Files
simstudioai--sim/apps/sim/tools/google_drive/share.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

181 lines
5.6 KiB
TypeScript

import type { GoogleDrivePermission, GoogleDriveToolParams } from '@/tools/google_drive/types'
import type { ToolConfig, ToolResponse } from '@/tools/types'
interface GoogleDriveShareParams extends GoogleDriveToolParams {
fileId: string
email?: string
domain?: string
type: 'user' | 'group' | 'domain' | 'anyone'
role: 'owner' | 'organizer' | 'fileOrganizer' | 'writer' | 'commenter' | 'reader'
transferOwnership?: boolean
moveToNewOwnersRoot?: boolean
sendNotification?: boolean
emailMessage?: string
}
interface GoogleDriveShareResponse extends ToolResponse {
output: {
permission: GoogleDrivePermission
}
}
export const shareTool: ToolConfig<GoogleDriveShareParams, GoogleDriveShareResponse> = {
id: 'google_drive_share',
name: 'Share Google Drive File',
description: 'Share a file with a user, group, domain, or make it public',
version: '1.0.0',
oauth: {
required: true,
provider: 'google-drive',
},
params: {
accessToken: {
type: 'string',
required: true,
visibility: 'hidden',
description: 'OAuth access token',
},
fileId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'The ID of the file to share',
},
type: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Type of grantee: user, group, domain, or anyone',
},
role: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description:
'Permission role: owner (transfer ownership), organizer (shared drive only), fileOrganizer (shared drive only), writer (edit), commenter (view and comment), reader (view only)',
},
email: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Email address of the user or group (required for type=user or type=group)',
},
domain: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Domain to share with (required for type=domain)',
},
transferOwnership: {
type: 'boolean',
required: false,
visibility: 'user-or-llm',
description: 'Required when role is owner. Transfers ownership to the specified user.',
},
moveToNewOwnersRoot: {
type: 'boolean',
required: false,
visibility: 'user-or-llm',
description:
"When transferring ownership, move the file to the new owner's My Drive root folder.",
},
sendNotification: {
type: 'boolean',
required: false,
visibility: 'user-or-llm',
description: 'Whether to send an email notification (default: true)',
},
emailMessage: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Custom message to include in the notification email',
},
},
request: {
url: (params) => {
const url = new URL(
`https://www.googleapis.com/drive/v3/files/${params.fileId?.trim()}/permissions`
)
url.searchParams.append('supportsAllDrives', 'true')
if (params.transferOwnership) {
url.searchParams.append('transferOwnership', 'true')
}
if (params.transferOwnership && params.moveToNewOwnersRoot) {
url.searchParams.append('moveToNewOwnersRoot', 'true')
}
if (params.transferOwnership) {
url.searchParams.append('sendNotificationEmail', 'true')
} else if (params.sendNotification !== undefined) {
url.searchParams.append('sendNotificationEmail', String(params.sendNotification))
}
if (params.emailMessage) {
url.searchParams.append('emailMessage', params.emailMessage)
}
return url.toString()
},
method: 'POST',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
'Content-Type': 'application/json',
}),
body: (params) => {
const body: Record<string, unknown> = {
type: params.type,
role: params.role,
}
if (params.email) {
body.emailAddress = params.email.trim()
}
if (params.domain) {
body.domain = params.domain.trim()
}
return body
},
},
transformResponse: async (response: Response) => {
const data = await response.json()
if (!response.ok) {
throw new Error(data.error?.message || 'Failed to share Google Drive file')
}
return {
success: true,
output: {
permission: {
id: data.id ?? null,
type: data.type ?? null,
role: data.role ?? null,
emailAddress: data.emailAddress ?? null,
displayName: data.displayName ?? null,
domain: data.domain ?? null,
expirationTime: data.expirationTime ?? null,
deleted: data.deleted ?? false,
},
},
}
},
outputs: {
permission: {
type: 'json',
description: 'The created permission details',
properties: {
id: { type: 'string', description: 'Permission ID' },
type: { type: 'string', description: 'Grantee type (user, group, domain, anyone)' },
role: { type: 'string', description: 'Permission role' },
emailAddress: { type: 'string', description: 'Email of the grantee', optional: true },
displayName: { type: 'string', description: 'Display name of the grantee', optional: true },
domain: { type: 'string', description: 'Domain of the grantee', optional: true },
expirationTime: { type: 'string', description: 'Expiration time', optional: true },
deleted: { type: 'boolean', description: 'Whether grantee is deleted' },
},
},
},
}