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
164 lines
4.5 KiB
TypeScript
164 lines
4.5 KiB
TypeScript
import type { NotionResponse } from '@/tools/notion/types'
|
|
import { DATABASE_OUTPUT_PROPERTIES } from '@/tools/notion/types'
|
|
import type { ToolConfig } from '@/tools/types'
|
|
|
|
export interface NotionReadDatabaseParams {
|
|
databaseId: string
|
|
accessToken: string
|
|
}
|
|
|
|
export const notionReadDatabaseTool: ToolConfig<NotionReadDatabaseParams, NotionResponse> = {
|
|
id: 'notion_read_database',
|
|
name: 'Read Notion Database',
|
|
description: 'Read database information and structure from Notion',
|
|
version: '1.0.0',
|
|
|
|
oauth: {
|
|
required: true,
|
|
provider: 'notion',
|
|
},
|
|
|
|
params: {
|
|
accessToken: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'hidden',
|
|
description: 'Notion OAuth access token',
|
|
},
|
|
databaseId: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-or-llm',
|
|
description: 'The UUID of the Notion database to read',
|
|
},
|
|
},
|
|
|
|
request: {
|
|
url: (params: NotionReadDatabaseParams) => {
|
|
return `https://api.notion.com/v1/databases/${params.databaseId.trim()}`
|
|
},
|
|
method: 'GET',
|
|
headers: (params: NotionReadDatabaseParams) => {
|
|
if (!params.accessToken) {
|
|
throw new Error('Access token is required')
|
|
}
|
|
|
|
return {
|
|
Authorization: `Bearer ${params.accessToken}`,
|
|
'Notion-Version': '2022-06-28',
|
|
'Content-Type': 'application/json',
|
|
}
|
|
},
|
|
},
|
|
|
|
transformResponse: async (response: Response) => {
|
|
const data = await response.json()
|
|
|
|
// Extract database title
|
|
const title = data.title?.map((t: any) => t.plain_text || '').join('') || 'Untitled Database'
|
|
|
|
// Extract properties for display
|
|
const properties = data.properties || {}
|
|
const propertyList = Object.entries(properties)
|
|
.map(([name, prop]: [string, any]) => ` ${name}: ${prop.type}`)
|
|
.join('\n')
|
|
|
|
const content = [
|
|
`Database: ${title}`,
|
|
'',
|
|
'Properties:',
|
|
propertyList,
|
|
'',
|
|
`Database ID: ${data.id}`,
|
|
`URL: ${data.url}`,
|
|
`Created: ${data.created_time ? new Date(data.created_time).toLocaleDateString() : 'Unknown'}`,
|
|
`Last edited: ${data.last_edited_time ? new Date(data.last_edited_time).toLocaleDateString() : 'Unknown'}`,
|
|
].join('\n')
|
|
|
|
return {
|
|
success: true,
|
|
output: {
|
|
content,
|
|
metadata: {
|
|
title,
|
|
url: data.url,
|
|
id: data.id,
|
|
createdTime: data.created_time,
|
|
lastEditedTime: data.last_edited_time,
|
|
properties: data.properties,
|
|
},
|
|
},
|
|
}
|
|
},
|
|
|
|
outputs: {
|
|
content: {
|
|
type: 'string',
|
|
description: 'Database information including title, properties schema, and metadata',
|
|
},
|
|
metadata: {
|
|
type: 'object',
|
|
description: 'Database metadata including title, ID, URL, timestamps, and properties schema',
|
|
properties: {
|
|
title: { type: 'string', description: 'Database title' },
|
|
url: DATABASE_OUTPUT_PROPERTIES.url,
|
|
id: DATABASE_OUTPUT_PROPERTIES.id,
|
|
createdTime: DATABASE_OUTPUT_PROPERTIES.created_time,
|
|
lastEditedTime: DATABASE_OUTPUT_PROPERTIES.last_edited_time,
|
|
properties: DATABASE_OUTPUT_PROPERTIES.properties,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
interface NotionReadDatabaseV2Response {
|
|
success: boolean
|
|
output: {
|
|
id: string
|
|
title: string
|
|
url: string
|
|
created_time: string
|
|
last_edited_time: string
|
|
properties: Record<string, any>
|
|
}
|
|
}
|
|
|
|
export const notionReadDatabaseV2Tool: ToolConfig<
|
|
NotionReadDatabaseParams,
|
|
NotionReadDatabaseV2Response
|
|
> = {
|
|
id: 'notion_read_database_v2',
|
|
name: 'Read Notion Database',
|
|
description: 'Read database information and structure from Notion',
|
|
version: '2.0.0',
|
|
oauth: notionReadDatabaseTool.oauth,
|
|
params: notionReadDatabaseTool.params,
|
|
request: notionReadDatabaseTool.request,
|
|
|
|
transformResponse: async (response: Response) => {
|
|
const data = await response.json()
|
|
const title = data.title?.map((t: any) => t.plain_text || '').join('') || 'Untitled Database'
|
|
|
|
return {
|
|
success: true,
|
|
output: {
|
|
id: data.id,
|
|
title,
|
|
url: data.url,
|
|
created_time: data.created_time,
|
|
last_edited_time: data.last_edited_time,
|
|
properties: data.properties || {},
|
|
},
|
|
}
|
|
},
|
|
|
|
outputs: {
|
|
id: DATABASE_OUTPUT_PROPERTIES.id,
|
|
title: { type: 'string', description: 'Database title' },
|
|
url: DATABASE_OUTPUT_PROPERTIES.url,
|
|
created_time: DATABASE_OUTPUT_PROPERTIES.created_time,
|
|
last_edited_time: DATABASE_OUTPUT_PROPERTIES.last_edited_time,
|
|
properties: DATABASE_OUTPUT_PROPERTIES.properties,
|
|
},
|
|
}
|