From 77077dcd03b173f0f1ae37187af4ce21cc3ffc75 Mon Sep 17 00:00:00 2001 From: Nestor Qin Date: Fri, 11 Oct 2024 03:20:17 -0400 Subject: [PATCH] fix: keep .d.ts files in build output --- .../commands/run_view_events.ts | 8 +- src/page/googleCalendar/googleCalendar.ts | 150 +++++++++--------- .../googleCalendar/googleCalendar_base.ts | 2 +- webpack.config.cjs | 8 +- 4 files changed, 83 insertions(+), 85 deletions(-) diff --git a/src/page/googleCalendar/commands/run_view_events.ts b/src/page/googleCalendar/commands/run_view_events.ts index 6984338..1fdad2f 100644 --- a/src/page/googleCalendar/commands/run_view_events.ts +++ b/src/page/googleCalendar/commands/run_view_events.ts @@ -6,7 +6,7 @@ type RunViewEventParams = { calendarId: string; }; -const runViewEvents = async ( { auth, calendarId }: RunViewEventParams ) => { +const runViewEvents = async ({ auth, calendarId }: RunViewEventParams) => { const calendar = new calendar_v3.Calendar({}); try { @@ -31,18 +31,18 @@ const runViewEvents = async ( { auth, calendarId }: RunViewEventParams ) => { description, start, end, - }) + }), ) : []; return `Result for view events command: \n${JSON.stringify( curatedItems, null, - 2 + 2, )}`; } catch (error) { return `An error occurred: ${error}`; } }; -export { runViewEvents }; \ No newline at end of file +export { runViewEvents }; diff --git a/src/page/googleCalendar/googleCalendar.ts b/src/page/googleCalendar/googleCalendar.ts index 2deba03..fdbc903 100644 --- a/src/page/googleCalendar/googleCalendar.ts +++ b/src/page/googleCalendar/googleCalendar.ts @@ -4,96 +4,92 @@ import { GoogleCalendarParams } from "./googleCalendar_base"; import { runViewEvents } from "./commands/run_view_events"; export class PageHandler implements IPageHandler { - protected clientEmail: string; - protected privateKey: string; - protected scopes: string[]; + protected clientEmail: string; + protected privateKey: string; + protected scopes: string[]; - constructor(fields: GoogleCalendarParams) { - this.clientEmail = fields.credentials?.clientEmail || ""; - this.privateKey = fields.credentials?.privateKey || ""; - this.scopes = fields.scopes || [ - "https://www.googleapis.com/auth/calendar", - "https://www.googleapis.com/auth/calendar.events", - ]; - } + constructor(fields: GoogleCalendarParams) { + this.clientEmail = fields.credentials?.clientEmail || ""; + this.privateKey = fields.credentials?.privateKey || ""; + this.scopes = fields.scopes || [ + "https://www.googleapis.com/auth/calendar", + "https://www.googleapis.com/auth/calendar.events", + ]; + } - public getAuth = async () => { - const auth = new google.auth.JWT( - this.clientEmail, - undefined, - this.privateKey, - this.scopes - ); - return auth; - } + public getAuth = async () => { + const auth = new google.auth.JWT( + this.clientEmail, + undefined, + this.privateKey, + this.scopes, + ); + return auth; + }; - public googleCalendarGetIDsImpl = async () => { - const auth = await this.getAuth(); - const calendar = google.calendar({ version: "v3", auth }); - const calendarList = await calendar.calendarList.list(); - const calendarIds = calendarList.data.items?.map((item) => item.id); - return calendarIds; - } + public googleCalendarGetIDsImpl = async () => { + const auth = await this.getAuth(); + const calendar = google.calendar({ version: "v3", auth }); + const calendarList = await calendar.calendarList.list(); + const calendarIds = calendarList.data.items?.map((item) => item.id); + return calendarIds; + }; - public googleCalendarViewEventsImpl = async (calendarId : string) => { - const auth = await this.getAuth(); - return runViewEvents( - { - auth, - calendarId: calendarId, - } - ); - } + public googleCalendarViewEventsImpl = async (calendarId: string) => { + const auth = await this.getAuth(); + return runViewEvents({ + auth, + calendarId: calendarId, + }); + }; - public handleToolCall(toolName: string, params: any): any { - if (toolName in this.toolImplementations) { - const toolImplementation = this.toolImplementations[toolName as ToolName]; - return toolImplementation(params); - } else { - throw new Error(`Tool '${toolName}' not found in handler.`); - } + public handleToolCall(toolName: string, params: any): any { + if (toolName in this.toolImplementations) { + const toolImplementation = this.toolImplementations[toolName as ToolName]; + return toolImplementation(params); + } else { + throw new Error(`Tool '${toolName}' not found in handler.`); } + } - toolImplementations: Record any> = { - googleCalendarGetIDs: this.googleCalendarGetIDsImpl, - googleCalendarViewEvents: this.googleCalendarViewEventsImpl, - }; + toolImplementations: Record any> = { + googleCalendarGetIDs: this.googleCalendarGetIDsImpl, + googleCalendarViewEvents: this.googleCalendarViewEventsImpl, + }; } export const tools = { - googleCalendarGetIDs: { - displayName: "Google Calendar Get IDs", - description: - "A tool for retrieving Google Calendar IDs.", - schema: { - type: "function", - function: { - name: "googleCalendarGetIDs", - description: - "googleCalendarGetIDs() -> str - Get user's Google Calendar IDs, no parameter is needed.\\n\\n Returns:\\n calendar IDs", - parameters: { type: "object", properties: {}, required: [] }, - }, + googleCalendarGetIDs: { + displayName: "Google Calendar Get IDs", + description: "A tool for retrieving Google Calendar IDs.", + schema: { + type: "function", + function: { + name: "googleCalendarGetIDs", + description: + "googleCalendarGetIDs() -> str - Get user's Google Calendar IDs, no parameter is needed.\\n\\n Returns:\\n calendar IDs", + parameters: { type: "object", properties: {}, required: [] }, }, }, - googleCalendarViewEvents: { - displayName: "Google Calendar View Events", - description: - "A tool for retrieving Google Calendar events and meetings.", - schema: { - type: "function", - function: { - name: "googleCalendarViewEvents", - description: - "googleCalendarViewEvents() -> str - Get the user's Google Calendar events and meetings, parameter is the calendar ID.\\n\\n Args:\\n calendarId (str): The calendar ID.\\n\\n Returns:\\n title, start time, end time, attendees, description (if available)", - parameters: { - type: "object", - properties: { - calendarId: { type: "string" }, - }, - required: ["calendarId"], - }, + }, + googleCalendarViewEvents: { + displayName: "Google Calendar View Events", + description: "A tool for retrieving Google Calendar events and meetings.", + schema: { + type: "function", + function: { + name: "googleCalendarViewEvents", + description: + "googleCalendarViewEvents() -> str - Get the user's Google Calendar events and meetings, parameter is the calendar ID.\\n\\n Args:\\n calendarId (str): The calendar ID.\\n\\n Returns:\\n title, start time, end time, attendees, description (if available)", + parameters: { + type: "object", + properties: { + calendarId: { type: "string" }, + }, + required: ["calendarId"], }, }, }, + }, }; export type ToolName = keyof typeof tools; @@ -103,4 +99,4 @@ export function getToolInfo(): { name: ToolName; displayName: string }[] { name: name as ToolName, displayName: tool.displayName, })); -} \ No newline at end of file +} diff --git a/src/page/googleCalendar/googleCalendar_base.ts b/src/page/googleCalendar/googleCalendar_base.ts index d48b07c..bbf4f64 100644 --- a/src/page/googleCalendar/googleCalendar_base.ts +++ b/src/page/googleCalendar/googleCalendar_base.ts @@ -4,4 +4,4 @@ export interface GoogleCalendarParams { privateKey?: string; }; scopes?: string[]; -} \ No newline at end of file +} diff --git a/webpack.config.cjs b/webpack.config.cjs index 8e76573..d9a0d60 100644 --- a/webpack.config.cjs +++ b/webpack.config.cjs @@ -11,7 +11,9 @@ module.exports = { library: { type: "commonjs2", }, - clean: true, + clean: { + keep: "index.d.ts", + }, sourceMapFilename: "[file].map", }, target: "web", @@ -31,8 +33,8 @@ module.exports = { use: { loader: "babel-loader", options: { - presets: ["@babel/preset-env", "@babel/preset-typescript"] - } + presets: ["@babel/preset-env", "@babel/preset-typescript"], + }, }, }, {