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
81 lines
2.5 KiB
TypeScript
81 lines
2.5 KiB
TypeScript
import { enrichTableToolSchema } from '@/tools/schema-enrichers'
|
|
import type { TableRowInsertParams, TableUpsertResponse } from '@/tools/table/types'
|
|
import type { ToolConfig } from '@/tools/types'
|
|
|
|
export const tableUpsertRowTool: ToolConfig<TableRowInsertParams, TableUpsertResponse> = {
|
|
id: 'table_upsert_row',
|
|
name: 'Upsert Row',
|
|
description:
|
|
'Insert or update a row based on unique column constraints. If a row with matching unique field exists, update it; otherwise insert a new row. IMPORTANT: You must use the "data" parameter (not "values", "row", "fields", or other variations) to specify the row contents.',
|
|
version: '1.0.0',
|
|
|
|
toolEnrichment: {
|
|
dependsOn: 'tableId',
|
|
enrichTool: (tableId, schema, desc) =>
|
|
enrichTableToolSchema(tableId, 'table_upsert_row', schema, desc),
|
|
},
|
|
|
|
params: {
|
|
tableId: {
|
|
type: 'string',
|
|
required: true,
|
|
description: 'Table ID',
|
|
visibility: 'user-only',
|
|
},
|
|
data: {
|
|
type: 'object',
|
|
required: true,
|
|
description: 'Row data to insert or update',
|
|
visibility: 'user-or-llm',
|
|
},
|
|
conflictTarget: {
|
|
type: 'string',
|
|
required: false,
|
|
description:
|
|
'Unique column to match on. Required only when the table has more than one unique column.',
|
|
visibility: 'user-only',
|
|
},
|
|
},
|
|
|
|
request: {
|
|
url: (params: TableRowInsertParams) => `/api/table/${params.tableId}/rows/upsert`,
|
|
method: 'POST',
|
|
headers: () => ({
|
|
'Content-Type': 'application/json',
|
|
}),
|
|
body: (params: TableRowInsertParams) => {
|
|
const workspaceId = params._context?.workspaceId
|
|
if (!workspaceId) {
|
|
throw new Error('Workspace ID is required in execution context')
|
|
}
|
|
|
|
return {
|
|
data: params.data,
|
|
workspaceId,
|
|
...(params.conflictTarget ? { conflictTarget: params.conflictTarget } : {}),
|
|
}
|
|
},
|
|
},
|
|
|
|
transformResponse: async (response): Promise<TableUpsertResponse> => {
|
|
const result = await response.json()
|
|
const data = result.data || result
|
|
|
|
return {
|
|
success: true,
|
|
output: {
|
|
row: data.row,
|
|
operation: data.operation,
|
|
message: data.message || 'Row upserted successfully',
|
|
},
|
|
}
|
|
},
|
|
|
|
outputs: {
|
|
success: { type: 'boolean', description: 'Whether row was upserted' },
|
|
row: { type: 'json', description: 'Upserted row data' },
|
|
operation: { type: 'string', description: 'Operation performed: insert or update' },
|
|
message: { type: 'string', description: 'Status message' },
|
|
},
|
|
}
|