Files
WeHub Mirror 6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (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 / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
WeHub snapshot of cb28d14c6f2c081de7a0d8729a8c816c9adef67a
2026-08-10 11:17:50 +08:00

183 lines
5.5 KiB
TypeScript

import { createLogger } from '@sim/logger'
import { toError } from '@sim/utils/errors'
import type {
SharepointCreateListResponse,
SharepointList,
SharepointToolParams,
} from '@/tools/sharepoint/types'
import { optionalTrim } from '@/tools/sharepoint/utils'
import type { ToolConfig } from '@/tools/types'
const logger = createLogger('SharePointCreateList')
export const createListTool: ToolConfig<SharepointToolParams, SharepointCreateListResponse> = {
id: 'sharepoint_create_list',
name: 'Create SharePoint List',
description: 'Create a new list in a SharePoint site',
version: '1.0.0',
oauth: {
required: true,
provider: 'sharepoint',
},
params: {
accessToken: {
type: 'string',
required: true,
visibility: 'hidden',
description: 'The access token for the SharePoint API',
},
siteId: {
type: 'string',
required: false,
visibility: 'hidden',
description: 'The ID of the SharePoint site (internal use)',
},
siteSelector: {
type: 'string',
required: false,
visibility: 'user-only',
description: 'Select the SharePoint site',
},
listDisplayName: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description:
'Display name of the list to create. Example: Project Tasks or Customer Contacts',
},
listDescription: {
type: 'string',
required: false,
visibility: 'user-only',
description: 'Description of the list',
},
listTemplate: {
type: 'string',
required: false,
visibility: 'user-only',
description: "List template name (e.g., 'genericList')",
},
pageContent: {
type: 'json',
required: false,
visibility: 'user-only',
description:
'Optional JSON of columns. Either a top-level array of column definitions or an object with { columns: [...] }.',
},
},
request: {
url: (params) => {
const siteId = optionalTrim(params.siteId) || optionalTrim(params.siteSelector) || 'root'
return `https://graph.microsoft.com/v1.0/sites/${encodeURIComponent(siteId)}/lists`
},
method: 'POST',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
'Content-Type': 'application/json',
Accept: 'application/json',
}),
body: (params) => {
const listDisplayName = optionalTrim(params.listDisplayName)
if (!listDisplayName) {
throw new Error('listDisplayName is required')
}
let columns: unknown[] | undefined
if (params.pageContent) {
if (typeof params.pageContent === 'string') {
try {
const parsed = JSON.parse(params.pageContent)
if (Array.isArray(parsed)) {
columns = parsed
} else if (
parsed &&
typeof parsed === 'object' &&
Array.isArray((parsed as { columns?: unknown[] }).columns)
) {
columns = (parsed as { columns: unknown[] }).columns
}
} catch (error) {
logger.warn('Invalid JSON in pageContent for create list; ignoring', {
error: toError(error).message,
})
}
} else if (typeof params.pageContent === 'object') {
const pageContent = params.pageContent as { columns?: unknown[] } | unknown[]
if (Array.isArray(pageContent)) {
columns = pageContent
} else if (pageContent && Array.isArray(pageContent.columns)) {
columns = pageContent.columns
}
}
}
const payload: {
displayName: string
description?: string
list: { template: string }
columns?: unknown[]
} = {
displayName: listDisplayName,
list: { template: optionalTrim(params.listTemplate) || 'genericList' },
}
const listDescription = optionalTrim(params.listDescription)
if (listDescription) payload.description = listDescription
if (columns && columns.length > 0) payload.columns = columns
logger.info('Creating SharePoint list', {
displayName: payload.displayName,
template: payload.list.template,
hasDescription: !!payload.description,
})
return payload
},
},
transformResponse: async (response: Response) => {
const data = await response.json()
const list: SharepointList = {
id: data.id,
displayName: data.displayName ?? data.name,
name: data.name,
webUrl: data.webUrl,
createdDateTime: data.createdDateTime,
lastModifiedDateTime: data.lastModifiedDateTime,
list: data.list,
}
logger.info('SharePoint list created successfully', {
listId: list.id,
displayName: list.displayName,
})
return {
success: true,
output: { list },
}
},
outputs: {
list: {
type: 'object',
description: 'Created SharePoint list information',
properties: {
id: { type: 'string', description: 'The unique ID of the list' },
displayName: { type: 'string', description: 'The display name of the list' },
name: { type: 'string', description: 'The internal name of the list' },
webUrl: { type: 'string', description: 'The web URL of the list' },
createdDateTime: { type: 'string', description: 'When the list was created' },
lastModifiedDateTime: {
type: 'string',
description: 'When the list was last modified',
},
list: { type: 'object', description: 'List properties (e.g., template)' },
},
},
},
}