Files
simstudioai--sim/apps/sim/tools/google_calendar/update_calendar.ts
T
wehub-resource-sync d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

178 lines
5.0 KiB
TypeScript

import {
CALENDAR_API_BASE,
type GoogleCalendarApiCalendarResponse,
} from '@/tools/google_calendar/types'
import type { ToolConfig } from '@/tools/types'
export interface GoogleCalendarUpdateCalendarParams {
accessToken: string
calendarId?: string
summary?: string
description?: string
location?: string
timeZone?: string
}
export interface GoogleCalendarUpdateCalendarResponse {
success: boolean
output: {
content: string
metadata: {
id: string
summary: string
description?: string
location?: string
timeZone?: string
}
}
}
const buildUpdateCalendarUrl = (params: GoogleCalendarUpdateCalendarParams) => {
const calendarId = params.calendarId?.trim() || 'primary'
return `${CALENDAR_API_BASE}/calendars/${encodeURIComponent(calendarId)}`
}
const buildUpdateCalendarBody = (params: GoogleCalendarUpdateCalendarParams) => {
const body: Record<string, string> = {}
if (params.summary !== undefined) body.summary = params.summary
if (params.description !== undefined) body.description = params.description
if (params.location !== undefined) body.location = params.location
if (params.timeZone !== undefined) body.timeZone = params.timeZone
return body
}
export const updateCalendarTool: ToolConfig<
GoogleCalendarUpdateCalendarParams,
GoogleCalendarUpdateCalendarResponse
> = {
id: 'google_calendar_update_calendar',
name: 'Google Calendar Update Calendar',
description: "Update a secondary calendar's metadata (title, description, location, time zone)",
version: '1.0.0',
oauth: {
required: true,
provider: 'google-calendar',
},
params: {
accessToken: {
type: 'string',
required: true,
visibility: 'hidden',
description: 'Access token for Google Calendar API',
},
calendarId: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Calendar ID to update (e.g., primary or calendar@group.calendar.google.com)',
},
summary: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'New title for the calendar',
},
description: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'New description for the calendar',
},
location: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'New geographic location of the calendar as free-form text',
},
timeZone: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'New time zone of the calendar as an IANA name (e.g., America/Los_Angeles)',
},
},
request: {
url: buildUpdateCalendarUrl,
method: 'PATCH',
headers: (params: GoogleCalendarUpdateCalendarParams) => ({
Authorization: `Bearer ${params.accessToken}`,
'Content-Type': 'application/json',
}),
body: buildUpdateCalendarBody,
},
transformResponse: async (response: Response) => {
const data: GoogleCalendarApiCalendarResponse = await response.json()
return {
success: true,
output: {
content: `Calendar "${data.summary}" updated successfully`,
metadata: {
id: data.id,
summary: data.summary,
description: data.description,
location: data.location,
timeZone: data.timeZone,
},
},
}
},
outputs: {
content: { type: 'string', description: 'Calendar update confirmation message' },
metadata: {
type: 'json',
description: 'Updated calendar metadata (id, summary, description, location, timeZone)',
},
},
}
interface GoogleCalendarUpdateCalendarV2Response {
success: boolean
output: {
id: string
summary: string
description: string | null
location: string | null
timeZone: string | null
}
}
export const updateCalendarV2Tool: ToolConfig<
GoogleCalendarUpdateCalendarParams,
GoogleCalendarUpdateCalendarV2Response
> = {
id: 'google_calendar_update_calendar_v2',
name: 'Google Calendar Update Calendar',
description: "Update a secondary calendar's metadata. Returns API-aligned fields only.",
version: '2.0.0',
oauth: updateCalendarTool.oauth,
params: updateCalendarTool.params,
request: updateCalendarTool.request,
transformResponse: async (response: Response) => {
const data: GoogleCalendarApiCalendarResponse = await response.json()
return {
success: true,
output: {
id: data.id,
summary: data.summary,
description: data.description ?? null,
location: data.location ?? null,
timeZone: data.timeZone ?? null,
},
}
},
outputs: {
id: { type: 'string', description: 'Calendar ID' },
summary: { type: 'string', description: 'Calendar title' },
description: { type: 'string', description: 'Calendar description', optional: true },
location: { type: 'string', description: 'Calendar location', optional: true },
timeZone: { type: 'string', description: 'Calendar time zone', optional: true },
},
}