Skip to content

Commit

Permalink
feat(remove): auto generate thread title
Browse files Browse the repository at this point in the history
  • Loading branch information
pnd280 committed Oct 11, 2024
1 parent 61a4e26 commit 3f612d6
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 141 deletions.
8 changes: 8 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ Consider giving a star ⭐ on [Github](https://github.com/pnd280/complexity).

💖 Support the development via [Ko-fi](https://ko-fi.com/pnd280) or [Paypal](https://paypal.me/pnd280).

## v0.0.3.13

_Release date: 11th Oct, 2024_

- **FIX**: Adapt to new query box dynamic placeholders - fixed a bug where selectors are not showing.
- **REMOVE**: **Temporarily** removed **Auto-generate thread title** setting.


## v0.0.3.11

_Release date: 8th Oct, 2024_
Expand Down
1 change: 0 additions & 1 deletion src/content-script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ function initTrafficInterceptors() {
WebpageMessageInterceptor.alterQueries();
WebpageMessageInterceptor.blockTelemetry();
WebpageMessageInterceptor.removeComplexityIdentifier();
WebpageMessageInterceptor.autoRenameThread();
}

function initConsoleMessage() {
Expand Down
131 changes: 1 addition & 130 deletions src/content-script/main-world/WebpageMessageInterceptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ import {
isWebSocketEventData,
WsParsedMessage,
} from "@/types/ws.types";
import { DomHelperSelectors, DomSelectors } from "@/utils/DomSelectors";
import { queryClient } from "@/utils/ts-query-query-client";
import UiUtils from "@/utils/UiUtils";
import { jsonUtils, waitForElement, whereAmI } from "@/utils/utils";
import { jsonUtils } from "@/utils/utils";
import WsMessageParser from "@/utils/WsMessageParser";

export default class WebpageMessageInterceptor {
Expand Down Expand Up @@ -271,133 +269,6 @@ export default class WebpageMessageInterceptor {
});
}

static autoRenameThread() {
const prompt = `
# IDENTITY and PURPOSE
You are an expert content summarizer. Your task is to generate a concise, one-line title that captures the essence of the provided text.
## STEPS
- Synthesize your understanding of the text into a single title consisting of 3-10 words, optionally starting with an emoji.
- Ensure the title is straightforward and easy to comprehend.
- The title should reflect the main topic, task, or purpose of the text.
## OUTPUT INSTRUCTIONS
- Provide the title in plain text without any special characters or Markdown formatting.
- Respond strictly with the title; do not include any additional text or context.
- The title must be in the same language as the original text.
## THE TEXT:
`;

if (
!CplxUserSettings.get().generalSettings.qolTweaks.autoGenerateThreadTitle
)
return;

webpageMessenger.addInterceptor({
matchCondition: (messageData: MessageData<unknown>) => {
if (!isWebSocketEventData(messageData)) return { match: false };

if (messageData.payload.isInternal) {
return { match: false };
}

const parsedPayload = parseStructuredMessage(messageData);

if (!parsedPayload) return { match: false };

if (parsedPayload.data[0]?.length < 1) return { match: false };

const { status, query_str, privacy_state } = parsedPayload.data[0];

if (status !== "completed" || privacy_state === "INCOGNITO")
return { match: false };

if (query_str == null) return { match: false };

return {
match: true,
args: [
{
queryStr: query_str,
},
],
};
},
callback: async (messageData, args) => {
if (whereAmI() !== "thread") return messageData;

if ($(DomHelperSelectors.THREAD.MESSAGE.BLOCK).length > 1)
return messageData;

const queryStr = args[0].queryStr;

webpageMessenger.sendMessage({
event: "sendWebSocketMessage",
payload: WsMessageParser.stringify({
messageCode: 420,
event: "perplexity_ask",
data: [
prompt + queryStr,
{
version: "2.12",
source: "default",
language: "en-US",
search_focus: "writing",
mode: "concise",
model_preference: "turbo" as LanguageModel["code"],
is_incognito: true,
ignore_interceptor: true,
},
],
}),
timeout: 10000,
});

const title =
await WebpageMessageInterceptor.waitForThreadNameGeneration({
queryStr: prompt + queryStr,
});

if (!title) return messageData;

const div = await waitForElement({
selector: DomSelectors.SICKY_NAVBAR_CHILD.THREAD_TITLE,
timeout: 1000,
});

if (div == null) return messageData;

$(DomSelectors.SICKY_NAVBAR_CHILD.THREAD_TITLE_WRAPPER).css({
opacity: 0,
});

(div as HTMLElement).click();

const input = await waitForElement({
selector: DomSelectors.SICKY_NAVBAR_CHILD.THREAD_TITLE_INPUT,
timeout: 1000,
});

if (input == null) return messageData;

UiUtils.setReactInputValue(input as HTMLInputElement, title);

$(input).trigger("blur");

$(DomSelectors.SICKY_NAVBAR_CHILD.THREAD_TITLE_WRAPPER).css({
opacity: 100,
});

return messageData;
},
stopCondition: () => false,
});
}

static waitForUpsertThreadCollection() {
const matchCondition = (messageData: MessageData<any>) => {
const parsedPayload = parseStructuredMessage(messageData);
Expand Down
1 change: 0 additions & 1 deletion src/cplx-user-settings/CplxUserSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default class CplxUserSettings {
blockTelemetry: false,
noFileCreationOnPaste: false,
fileDropableThreadWrapper: false,
autoGenerateThreadTitle: false,
},
visualTweaks: {
collapseEmptyThreadVisualColumns: false,
Expand Down
8 changes: 0 additions & 8 deletions src/cplx-user-settings/GeneralSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,6 @@ export default class GeneralSettings {
"Automatically reload the page when Cloudflare session expires.",
versionRelease: "0.0.0.12",
},
{
id: "auto-generate-thread-title",
label: "Auto-generate thread title",
settingKey: "autoGenerateThreadTitle",
experimental: true,
description: "Auto-generate a 3-10 word title for your thread.",
versionRelease: "0.0.4.0",
},
{
id: "no-file-creation-on-paste",
label: "No file creation on long text paste",
Expand Down
1 change: 0 additions & 1 deletion src/cplx-user-settings/types/cplx-user-settings.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export const cplxUserSettingsSchema = z.object({
blockTelemetry: z.boolean(),
noFileCreationOnPaste: z.boolean(),
fileDropableThreadWrapper: z.boolean(),
autoGenerateThreadTitle: z.boolean(),
}),
visualTweaks: z.object({
collapseEmptyThreadVisualColumns: z.boolean(),
Expand Down

0 comments on commit 3f612d6

Please sign in to comment.