chore: import upstream snapshot with attribution
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
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
This commit is contained in:
@@ -0,0 +1,205 @@
|
||||
import { toError } from '@sim/utils/errors'
|
||||
import type { NotionQueryDatabaseParams, NotionResponse } from '@/tools/notion/types'
|
||||
import { DATABASE_QUERY_RESULTS_OUTPUT, PAGINATION_OUTPUT_PROPERTIES } from '@/tools/notion/types'
|
||||
import { extractTitle, formatPropertyValue } from '@/tools/notion/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const notionQueryDatabaseTool: ToolConfig<NotionQueryDatabaseParams, NotionResponse> = {
|
||||
id: 'notion_query_database',
|
||||
name: 'Query Notion Database',
|
||||
description: 'Query and filter Notion database entries with advanced filtering',
|
||||
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 query',
|
||||
},
|
||||
filter: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Filter conditions as JSON (optional)',
|
||||
},
|
||||
sorts: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Sort criteria as JSON array (optional)',
|
||||
},
|
||||
pageSize: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Number of results to return (default: 100, max: 100)',
|
||||
},
|
||||
startCursor: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Pagination cursor returned by a previous request',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params: NotionQueryDatabaseParams) => {
|
||||
return `https://api.notion.com/v1/databases/${params.databaseId.trim()}/query`
|
||||
},
|
||||
method: 'POST',
|
||||
headers: (params: NotionQueryDatabaseParams) => {
|
||||
if (!params.accessToken) {
|
||||
throw new Error('Access token is required')
|
||||
}
|
||||
|
||||
return {
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
'Notion-Version': '2022-06-28',
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
},
|
||||
body: (params: NotionQueryDatabaseParams) => {
|
||||
const body: any = {}
|
||||
|
||||
// Add filter if provided
|
||||
if (params.filter) {
|
||||
try {
|
||||
body.filter = JSON.parse(params.filter)
|
||||
} catch (error) {
|
||||
throw new Error(`Invalid filter JSON: ${toError(error).message}`)
|
||||
}
|
||||
}
|
||||
|
||||
// Add sorts if provided
|
||||
if (params.sorts) {
|
||||
try {
|
||||
body.sorts = JSON.parse(params.sorts)
|
||||
} catch (error) {
|
||||
throw new Error(`Invalid sorts JSON: ${toError(error).message}`)
|
||||
}
|
||||
}
|
||||
|
||||
// Add page size if provided
|
||||
if (params.pageSize) {
|
||||
body.page_size = Math.min(Number(params.pageSize), 100)
|
||||
}
|
||||
|
||||
// Add pagination cursor if provided
|
||||
if (params.startCursor) {
|
||||
body.start_cursor = params.startCursor.trim()
|
||||
}
|
||||
|
||||
return body
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
const results = data.results || []
|
||||
|
||||
// Format the results into readable content
|
||||
const content = results
|
||||
.map((page: any, index: number) => {
|
||||
const properties = page.properties || {}
|
||||
const title = extractTitle(properties)
|
||||
const propertyValues = Object.entries(properties)
|
||||
.map(([key, value]: [string, any]) => {
|
||||
const formattedValue = formatPropertyValue(value)
|
||||
return ` ${key}: ${formattedValue}`
|
||||
})
|
||||
.join('\n')
|
||||
|
||||
return `Entry ${index + 1}${title ? ` - ${title}` : ''}:\n${propertyValues}`
|
||||
})
|
||||
.join('\n\n')
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
content: content || 'No results found',
|
||||
metadata: {
|
||||
totalResults: results.length,
|
||||
hasMore: data.has_more || false,
|
||||
nextCursor: data.next_cursor || null,
|
||||
results: results,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
content: {
|
||||
type: 'string',
|
||||
description: 'Formatted list of database entries with their properties',
|
||||
},
|
||||
metadata: {
|
||||
type: 'object',
|
||||
description:
|
||||
'Query metadata including total results count, pagination info, and raw results array',
|
||||
properties: {
|
||||
totalResults: { type: 'number', description: 'Number of results returned' },
|
||||
hasMore: PAGINATION_OUTPUT_PROPERTIES.has_more,
|
||||
nextCursor: PAGINATION_OUTPUT_PROPERTIES.next_cursor,
|
||||
results: DATABASE_QUERY_RESULTS_OUTPUT,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// V2 Tool with API-aligned outputs
|
||||
interface NotionQueryDatabaseV2Response {
|
||||
success: boolean
|
||||
output: {
|
||||
results: any[]
|
||||
has_more: boolean
|
||||
next_cursor: string | null
|
||||
total_results: number
|
||||
}
|
||||
}
|
||||
|
||||
export const notionQueryDatabaseV2Tool: ToolConfig<
|
||||
NotionQueryDatabaseParams,
|
||||
NotionQueryDatabaseV2Response
|
||||
> = {
|
||||
id: 'notion_query_database_v2',
|
||||
name: 'Query Notion Database',
|
||||
description: 'Query and filter Notion database entries with advanced filtering',
|
||||
version: '2.0.0',
|
||||
oauth: notionQueryDatabaseTool.oauth,
|
||||
params: notionQueryDatabaseTool.params,
|
||||
request: notionQueryDatabaseTool.request,
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
const results = data.results || []
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
results,
|
||||
has_more: data.has_more || false,
|
||||
next_cursor: data.next_cursor || null,
|
||||
total_results: results.length,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
results: DATABASE_QUERY_RESULTS_OUTPUT,
|
||||
has_more: PAGINATION_OUTPUT_PROPERTIES.has_more,
|
||||
next_cursor: PAGINATION_OUTPUT_PROPERTIES.next_cursor,
|
||||
total_results: { type: 'number', description: 'Number of results returned' },
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user