Skip to content

Commit

Permalink
feat: add tool getPageTextContent
Browse files Browse the repository at this point in the history
  • Loading branch information
Neet-Nestor committed Oct 23, 2024
1 parent 723e8d5 commit ea06237
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Tool } from "./tool";

export const replaceSelectedText = (
state: State,
parameters: { newText: string | string[] }
parameters: { newText: string | string[] },
): void => {
const { newText } = parameters;
const selection = state.currentSelection;
Expand All @@ -17,7 +17,7 @@ export const replaceSelectedText = (
if (Array.isArray(newText)) {
const fragment = document.createDocumentFragment();
newText.forEach((text) =>
fragment.appendChild(document.createTextNode(text))
fragment.appendChild(document.createTextNode(text)),
);
range.insertNode(fragment);
} else {
Expand All @@ -29,7 +29,7 @@ export const replaceSelectedText = (

export const appendTextToDocument = (
state: State,
parameters: { text: string }
parameters: { text: string },
): void => {
if (window.location.hostname.includes("overleaf.com")) {
const { text } = parameters;
Expand Down Expand Up @@ -59,7 +59,7 @@ export async function createGoogleCalendarEvent(
startDateTime: string;
endDateTime: string;
timeZone?: string;
}
},
) {
let { token } = parameters;

Expand All @@ -74,7 +74,7 @@ export async function createGoogleCalendarEvent(
} catch (e) {
throw new Error(
"createGoogleCalendarEvent: `token` must be specified in parameters or `identity` permission must be added to the extension manifest.\n" +
e
e,
);
}
}
Expand Down Expand Up @@ -108,7 +108,7 @@ export async function createGoogleCalendarEvent(
"Content-Type": "application/json",
},
body: JSON.stringify(event),
}
},
);

if (!response.ok) {
Expand Down
27 changes: 26 additions & 1 deletion src/retriever.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ export const getSelectedText = (state: State, parameters: {}): string => {
return state.currentSelection.toString();
};

export const getPageTextContent = (): string => {
if (document) {
return document.body.innerText || "";
}
return "";
};

export async function getCalendarEvents(
state: State,
parameters: { token?: string },
Expand All @@ -26,7 +33,7 @@ export async function getCalendarEvents(
} catch (e) {
throw new Error(
"getCalendarEvents: `token` must be specified in parameters or `identity` permission must be added to the extension manifest.\n" +
e
e,
);
}
}
Expand Down Expand Up @@ -87,6 +94,24 @@ export const retrievers: Record<string, Tool> = {
caller: CallerType.Any,
implementation: getSelectedText,
},
getPageTextContent: {
name: "getPageTextContent",
displayName: "Get Page Content",
description: "Fetch the entire text content of the current webpage.",
schema: {
type: "function",
function: {
name: "getPageTextContent",
description:
"getPageTextContent() -> str - Fetches the entire text content of the current webpage.\n\n Returns:\n str: The entire text content of the webpage.",
parameters: { type: "object", properties: {}, required: [] },
},
},
type: ToolType.Retriever,
scope: Scope.Any,
caller: CallerType.ContentScript,
implementation: getPageTextContent,
},
getCalendarEvents: {
name: "getGoogleCalendarEvents",
displayName: "Get Google Calendar Events",
Expand Down

0 comments on commit ea06237

Please sign in to comment.