Skip to content

Commit

Permalink
fix: keep .d.ts files in build output
Browse files Browse the repository at this point in the history
  • Loading branch information
Neet-Nestor committed Oct 11, 2024
1 parent 8a4144d commit 77077dc
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 85 deletions.
8 changes: 4 additions & 4 deletions src/page/googleCalendar/commands/run_view_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 };
export { runViewEvents };
150 changes: 73 additions & 77 deletions src/page/googleCalendar/googleCalendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ToolName, (...args: any[]) => any> = {
googleCalendarGetIDs: this.googleCalendarGetIDsImpl,
googleCalendarViewEvents: this.googleCalendarViewEventsImpl,
};
toolImplementations: Record<ToolName, (...args: any[]) => 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;
Expand All @@ -103,4 +99,4 @@ export function getToolInfo(): { name: ToolName; displayName: string }[] {
name: name as ToolName,
displayName: tool.displayName,
}));
}
}
2 changes: 1 addition & 1 deletion src/page/googleCalendar/googleCalendar_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export interface GoogleCalendarParams {
privateKey?: string;
};
scopes?: string[];
}
}
8 changes: 5 additions & 3 deletions webpack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ module.exports = {
library: {
type: "commonjs2",
},
clean: true,
clean: {
keep: "index.d.ts",
},
sourceMapFilename: "[file].map",
},
target: "web",
Expand All @@ -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"],
},
},
},
{
Expand Down

0 comments on commit 77077dc

Please sign in to comment.