Files
simstudioai--sim/apps/sim/tools/langsmith/update_run.ts
T
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

146 lines
3.9 KiB
TypeScript

import { filterUndefined } from '@sim/utils/object'
import type { LangsmithUpdateRunParams, LangsmithUpdateRunResponse } from '@/tools/langsmith/types'
import type { ToolConfig } from '@/tools/types'
export const langsmithUpdateRunTool: ToolConfig<
LangsmithUpdateRunParams,
LangsmithUpdateRunResponse
> = {
id: 'langsmith_update_run',
name: 'LangSmith Update Run',
description: 'Patch an existing LangSmith run with outputs, status, or timing once it completes.',
version: '1.0.0',
params: {
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'LangSmith API key',
},
runId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'ID of the run to update',
},
name: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Corrected run name',
},
end_time: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Run end time in ISO-8601 format',
},
outputs: {
type: 'json',
required: false,
visibility: 'user-or-llm',
description: 'Outputs payload',
},
extra: {
type: 'json',
required: false,
visibility: 'user-or-llm',
description: 'Additional metadata (extra)',
},
tags: {
type: 'json',
required: false,
visibility: 'user-or-llm',
description: 'Array of tag strings',
},
status: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Run status',
},
error: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Error details',
},
events: {
type: 'json',
required: false,
visibility: 'user-or-llm',
description: 'Structured events array',
},
},
request: {
url: (params) => `https://api.smith.langchain.com/runs/${params.runId.trim()}`,
method: 'PATCH',
headers: (params) => ({
'X-Api-Key': params.apiKey,
'Content-Type': 'application/json',
}),
body: (params) => {
const emptyToUndefined = (value?: string) => (value === '' ? undefined : value)
const payload: Record<string, unknown> = {
name: emptyToUndefined(params.name),
end_time: emptyToUndefined(params.end_time),
outputs: params.outputs,
extra: params.extra,
tags: params.tags,
status: emptyToUndefined(params.status),
error: emptyToUndefined(params.error),
events: params.events,
}
const filtered = filterUndefined(payload)
if (Object.keys(filtered).length === 0) {
throw new Error('Provide at least one field to update')
}
return filtered
},
},
transformResponse: async (response, params) => {
if (!response.ok) {
const errorText = await response.text()
throw new Error(`LangSmith update run failed (${response.status}): ${errorText}`)
}
const responseText = await response.text()
let message: string | null = null
if (responseText) {
try {
const data = JSON.parse(responseText) as Record<string, unknown>
message = typeof data.message === 'string' ? data.message : null
} catch {
// Response body isn't JSON (e.g. empty object or plain text) — no message to surface
}
}
return {
success: true,
output: {
accepted: true,
runId: params?.runId.trim() ?? '',
message,
},
}
},
outputs: {
accepted: {
type: 'boolean',
description: 'Whether the run update was accepted',
},
runId: {
type: 'string',
description: 'ID of the run that was updated',
},
message: {
type: 'string',
description: 'Response message from LangSmith, if provided',
optional: true,
},
},
}