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
130 lines
3.9 KiB
TypeScript
130 lines
3.9 KiB
TypeScript
import type {
|
|
MicrosoftGraphDriveItem,
|
|
OneDriveListResponse,
|
|
OneDriveToolParams,
|
|
} from '@/tools/onedrive/types'
|
|
import { escapeODataStringLiteral } from '@/tools/onedrive/utils'
|
|
import { assertGraphNextPageUrl, getGraphNextPageUrl } from '@/tools/sharepoint/utils'
|
|
import type { ToolConfig } from '@/tools/types'
|
|
|
|
export const listTool: ToolConfig<OneDriveToolParams, OneDriveListResponse> = {
|
|
id: 'onedrive_list',
|
|
name: 'List OneDrive Files',
|
|
description: 'List files and folders in OneDrive',
|
|
version: '1.0',
|
|
|
|
oauth: {
|
|
required: true,
|
|
provider: 'onedrive',
|
|
},
|
|
|
|
params: {
|
|
accessToken: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'hidden',
|
|
description: 'The access token for the OneDrive API',
|
|
},
|
|
folderId: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Folder ID to list files from (e.g., "01BYE5RZ6QN3ZWBTUFOFD3GSPGOHDJD36M")',
|
|
},
|
|
query: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Filter files by name prefix (e.g., "report", "invoice_2024")',
|
|
},
|
|
pageSize: {
|
|
type: 'number',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Maximum number of files to return (e.g., 10, 50, 100)',
|
|
},
|
|
pageToken: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description:
|
|
"Continuation URL from a previous response's nextPageToken, used to fetch the next page",
|
|
},
|
|
},
|
|
|
|
request: {
|
|
url: (params) => {
|
|
const pageToken = params.pageToken?.trim()
|
|
if (pageToken) {
|
|
return assertGraphNextPageUrl(pageToken)
|
|
}
|
|
|
|
// Use specific folder if provided, otherwise use root
|
|
const folderId = params.folderId?.trim()
|
|
const encodedFolderId = folderId ? encodeURIComponent(folderId) : ''
|
|
const baseUrl = encodedFolderId
|
|
? `https://graph.microsoft.com/v1.0/me/drive/items/${encodedFolderId}/children`
|
|
: 'https://graph.microsoft.com/v1.0/me/drive/root/children'
|
|
|
|
const url = new URL(baseUrl)
|
|
|
|
// Use Microsoft Graph $select parameter
|
|
url.searchParams.append(
|
|
'$select',
|
|
'id,name,file,folder,webUrl,size,createdDateTime,lastModifiedDateTime,parentReference,@microsoft.graph.downloadUrl'
|
|
)
|
|
|
|
// Add name filter if query provided
|
|
if (params.query) {
|
|
url.searchParams.append(
|
|
'$filter',
|
|
`startswith(name,'${escapeODataStringLiteral(params.query)}')`
|
|
)
|
|
}
|
|
|
|
// Add pagination
|
|
if (params.pageSize) {
|
|
url.searchParams.append('$top', Number(params.pageSize).toString())
|
|
}
|
|
|
|
return url.toString()
|
|
},
|
|
method: 'GET',
|
|
headers: (params) => ({
|
|
Authorization: `Bearer ${params.accessToken}`,
|
|
}),
|
|
},
|
|
|
|
transformResponse: async (response: Response) => {
|
|
const data = await response.json()
|
|
|
|
return {
|
|
success: true,
|
|
output: {
|
|
files: data.value.map((item: MicrosoftGraphDriveItem) => ({
|
|
id: item.id,
|
|
name: item.name,
|
|
mimeType: item.file?.mimeType || (item.folder ? 'application/folder' : 'unknown'),
|
|
webViewLink: item.webUrl,
|
|
webContentLink: item['@microsoft.graph.downloadUrl'],
|
|
size: item.size?.toString() || '0',
|
|
createdTime: item.createdDateTime,
|
|
modifiedTime: item.lastModifiedDateTime,
|
|
parents: item.parentReference ? [item.parentReference.id] : [],
|
|
})),
|
|
// Use the actual @odata.nextLink URL as the continuation token
|
|
nextPageToken: getGraphNextPageUrl(data),
|
|
},
|
|
}
|
|
},
|
|
|
|
outputs: {
|
|
success: { type: 'boolean', description: 'Whether files were listed successfully' },
|
|
files: { type: 'array', description: 'Array of file and folder objects with metadata' },
|
|
nextPageToken: {
|
|
type: 'string',
|
|
description: 'Token for retrieving the next page of results (optional)',
|
|
},
|
|
},
|
|
}
|