Files
simstudioai--sim/apps/sim/tools/google_calendar/unshare_calendar.ts
T
wehub-resource-sync d25d482dc2
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
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

123 lines
3.4 KiB
TypeScript

import {
CALENDAR_API_BASE,
type GoogleCalendarUnshareCalendarParams,
type GoogleCalendarUnshareCalendarResponse,
} from '@/tools/google_calendar/types'
import type { ToolConfig } from '@/tools/types'
const buildUnshareUrl = (params: GoogleCalendarUnshareCalendarParams) => {
const calendarId = params.calendarId?.trim() || 'primary'
return `${CALENDAR_API_BASE}/calendars/${encodeURIComponent(calendarId)}/acl/${encodeURIComponent(params.ruleId.trim())}`
}
export const unshareCalendarTool: ToolConfig<
GoogleCalendarUnshareCalendarParams,
GoogleCalendarUnshareCalendarResponse
> = {
id: 'google_calendar_unshare_calendar',
name: 'Google Calendar Remove Sharing',
description: 'Revoke an access control rule (sharing) from a calendar',
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 modify (e.g., primary or calendar@group.calendar.google.com)',
},
ruleId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'ACL rule ID to remove (e.g., user:person@example.com)',
},
},
request: {
url: buildUnshareUrl,
method: 'DELETE',
headers: (params: GoogleCalendarUnshareCalendarParams) => ({
Authorization: `Bearer ${params.accessToken}`,
'Content-Type': 'application/json',
}),
},
transformResponse: async (response: Response, params) => {
if (response.status === 204 || response.ok) {
return {
success: true,
output: {
content: 'Sharing rule successfully removed',
metadata: {
ruleId: params?.ruleId || '',
deleted: true,
},
},
}
}
const errorData = await response.json().catch(() => null)
throw new Error(errorData?.error?.message || 'Failed to remove sharing rule')
},
outputs: {
content: { type: 'string', description: 'Removal confirmation message' },
metadata: {
type: 'json',
description: 'Removal details including rule ID',
},
},
}
interface GoogleCalendarUnshareCalendarV2Response {
success: boolean
output: {
ruleId: string
deleted: boolean
}
}
export const unshareCalendarV2Tool: ToolConfig<
GoogleCalendarUnshareCalendarParams,
GoogleCalendarUnshareCalendarV2Response
> = {
id: 'google_calendar_unshare_calendar_v2',
name: 'Google Calendar Remove Sharing',
description:
'Revoke an access control rule (sharing) from a calendar. Returns API-aligned fields only.',
version: '2.0.0',
oauth: unshareCalendarTool.oauth,
params: unshareCalendarTool.params,
request: unshareCalendarTool.request,
transformResponse: async (response: Response, params) => {
if (response.status === 204 || response.ok) {
return {
success: true,
output: {
ruleId: params?.ruleId || '',
deleted: true,
},
}
}
const errorData = await response.json().catch(() => null)
throw new Error(errorData?.error?.message || 'Failed to remove sharing rule')
},
outputs: {
ruleId: { type: 'string', description: 'Removed ACL rule ID' },
deleted: { type: 'boolean', description: 'Whether removal was successful' },
},
}