Skip to content

Commit

Permalink
feat(language-model-selector): persist reasoning models
Browse files Browse the repository at this point in the history
  • Loading branch information
pnd280 committed Jan 30, 2025
1 parent 3738a64 commit 6d2c4ec
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 23 deletions.
4 changes: 2 additions & 2 deletions e2e/utils/pplx-api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Page } from "@playwright/test";

import { ENDPOINTS } from "@/services/pplx-api/endpoints";
import { UserSettingsApiResponseSchema } from "@/services/pplx-api/pplx-api.types";
import { PplxUserSettingsApiResponseSchema } from "@/services/pplx-api/pplx-api.types";

export type AuthSession = {
user: {
Expand All @@ -24,5 +24,5 @@ export async function fetchPplxAuthSession(page: Page) {

export async function fetchPplxUserSettings(page: Page) {
const resp = await page.request.get(ENDPOINTS.USER_SETTINGS);
return UserSettingsApiResponseSchema.parse(await resp.json());
return PplxUserSettingsApiResponseSchema.parse(await resp.json());
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "complexity",
"displayName": "Complexity - Perplexity AI Supercharged",
"version": "1.4.2.0",
"version": "1.4.3.0",
"author": "pnd280",
"description": "Supercharge your Perplexity AI",
"type": "module",
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/usePplxUserSettings.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { useQuery, UseQueryResult } from "@tanstack/react-query";

import usePplxAuth from "@/hooks/usePplxAuth";
import { UserSettingsApiResponse } from "@/services/pplx-api/pplx-api.types";
import { PplxUserSettingsApiResponse } from "@/services/pplx-api/pplx-api.types";
import { pplxApiQueries } from "@/services/pplx-api/query-keys";
import { ControlledQueryOptions } from "@/types/tanstack-query.types";

export default function usePplxUserSettings({
...props
}: ControlledQueryOptions<
UserSettingsApiResponse,
PplxUserSettingsApiResponse,
typeof pplxApiQueries.userSettings.queryKey,
"enabled"
> = {}): UseQueryResult<UserSettingsApiResponse> {
> = {}): UseQueryResult<PplxUserSettingsApiResponse> {
const { isLoggedIn } = usePplxAuth();

const query = useQuery({
Expand Down
6 changes: 1 addition & 5 deletions src/plugins/block-analytic-events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ csLoaderRegistry.register({
return skip();
}

const firstPayloadItem = payload[0];
const shouldBlockAnalyticEvents =
firstPayloadItem === "analytics_event";

if (shouldBlockAnalyticEvents) {
if (payload[0] === "analytics_event") {
stopPropagation("");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { produce } from "immer";

import { pluginGuardsStore } from "@/components/plugins-guard/store";
import { networkInterceptMiddlewareManager } from "@/plugins/_api/network-intercept-middleware-manager/middleware-manager";
import {
Expand Down Expand Up @@ -76,6 +78,33 @@ csLoaderRegistry.register({
});
},
});

networkInterceptMiddlewareManager.updateMiddleware({
id: "persist-reasoning-model",
middlewareFn({ data, skip }) {
if (
data.type !== "network-intercept:fetchEvent" ||
data.event !== "request"
) {
return skip();
}

const isSaveSettingsRequest = data.payload.url.includes(
"/rest/user/save-settings",
);

if (!isSaveSettingsRequest) return skip();

const parsedPayload = JSON.parse(data.payload.data);

const newPayload = produce(parsedPayload, (draft: any) => {
draft.updated_settings.default_model =
sharedQueryBoxStore.getState().selectedLanguageModel;
});

return JSON.stringify(newPayload);
},
});
});
},
});
12 changes: 6 additions & 6 deletions src/services/pplx-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { LanguageModel } from "@/data/plugins/query-box/language-model-sele
import { InternalWebSocketManager } from "@/plugins/_api/web-socket/internal-web-socket-manager";
import { ENDPOINTS } from "@/services/pplx-api/endpoints";
import {
OrgSettingsApiResponseSchema,
PplxOrgSettingsApiResponseSchema,
Space,
SpaceFileDownloadUrlApiResponse,
SpaceFileDownloadUrlApiResponseSchema,
Expand All @@ -19,8 +19,8 @@ import {
ThreadMessageApiResponseSchema,
ThreadsSearchApiResponse,
ThreadsSearchApiResponseSchema,
UserSettingsApiResponse,
UserSettingsApiResponseSchema,
PplxUserSettingsApiResponse,
PplxUserSettingsApiResponseSchema,
} from "@/services/pplx-api/pplx-api.types";
import {
saveSettingViaFetch,
Expand All @@ -43,7 +43,7 @@ export class PplxApiService {
return data;
}

static async fetchUserSettings(): Promise<UserSettingsApiResponse> {
static async fetchUserSettings(): Promise<PplxUserSettingsApiResponse> {
const resp = await fetch(ENDPOINTS.USER_SETTINGS);

const respText = await resp.text();
Expand All @@ -52,7 +52,7 @@ export class PplxApiService {
throw new Error("Cloudflare timeout");
}

const parsedJson = UserSettingsApiResponseSchema.parse(
const parsedJson = PplxUserSettingsApiResponseSchema.parse(
jsonUtils.safeParse(respText),
);

Expand All @@ -62,7 +62,7 @@ export class PplxApiService {
static async fetchOrgSettings() {
const resp = await fetchResource(ENDPOINTS.ORG_SETTINGS);

const data = OrgSettingsApiResponseSchema.parse(jsonUtils.safeParse(resp));
const data = PplxOrgSettingsApiResponseSchema.parse(jsonUtils.safeParse(resp));

return data;
}
Expand Down
12 changes: 6 additions & 6 deletions src/services/pplx-api/pplx-api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FocusMode } from "@/data/plugins/better-focus-selector/focus-modes";
import { FocusWebRecency } from "@/data/plugins/better-focus-selector/focus-web-recency";
import { LanguageModel } from "@/data/plugins/query-box/language-model-selector/language-models.types";

export const UserSettingsApiResponseSchema = z.object({
export const PplxUserSettingsApiResponseSchema = z.object({
has_ai_profile: z.boolean(),
default_copilot: z.boolean().nullable(),
default_model: z.string(),
Expand All @@ -18,16 +18,16 @@ export const UserSettingsApiResponseSchema = z.object({
query_count: z.number(),
});

export type UserSettingsApiResponse = z.infer<
typeof UserSettingsApiResponseSchema
export type PplxUserSettingsApiResponse = z.infer<
typeof PplxUserSettingsApiResponseSchema
>;

export const OrgSettingsApiResponseSchema = z.object({
export const PplxOrgSettingsApiResponseSchema = z.object({
is_in_organization: z.boolean(),
});

export type OrgSettingsApiResponse = z.infer<
typeof OrgSettingsApiResponseSchema
export type PplxOrgSettingsApiResponse = z.infer<
typeof PplxOrgSettingsApiResponseSchema
>;

export const ThreadMessageApiResponseSchema = z.object({
Expand Down

0 comments on commit 6d2c4ec

Please sign in to comment.