6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (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 / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
138 lines
3.9 KiB
TypeScript
138 lines
3.9 KiB
TypeScript
import type {
|
|
LogfireQueryApiResponse,
|
|
LogfireQueryParams,
|
|
LogfireQueryResponse,
|
|
} from '@/tools/logfire/types'
|
|
import {
|
|
buildLogfireQueryBody,
|
|
extractLogfireColumns,
|
|
extractLogfireRows,
|
|
LOGFIRE_QUERY_PATH,
|
|
logfireHeaders,
|
|
logfireUrl,
|
|
parseLogfireResponse,
|
|
} from '@/tools/logfire/utils'
|
|
import type { ToolConfig } from '@/tools/types'
|
|
|
|
export const logfireQueryTool: ToolConfig<LogfireQueryParams, LogfireQueryResponse> = {
|
|
id: 'logfire_query',
|
|
name: 'Logfire Query',
|
|
description:
|
|
'Run a read-only SQL query against Logfire traces, logs, and metrics. Reads the records and metrics tables using PostgreSQL-compatible syntax.',
|
|
version: '1.0.0',
|
|
|
|
params: {
|
|
apiKey: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-only',
|
|
description: 'Logfire read token',
|
|
},
|
|
region: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-only',
|
|
description: 'Logfire data region: auto, us, or eu. Auto reads the region from the token.',
|
|
},
|
|
host: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-only',
|
|
description:
|
|
'Base URL of a self-hosted Logfire instance, e.g. https://logfire.example.com. Overrides region. Leave blank for Logfire Cloud.',
|
|
},
|
|
sql: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-or-llm',
|
|
description: 'SQL SELECT query to run against the records or metrics table',
|
|
},
|
|
minTimestamp: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description:
|
|
'ISO 8601 lower bound on start_timestamp. Defaults to 2020-01-01T00:00:00Z when omitted.',
|
|
},
|
|
maxTimestamp: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'ISO 8601 upper bound on start_timestamp',
|
|
},
|
|
limit: {
|
|
type: 'number',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Maximum rows to return. Logfire defaults to 100 and caps at 10000.',
|
|
},
|
|
timezone: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'IANA timezone used to evaluate the query, for example Europe/Paris',
|
|
},
|
|
environment: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Restrict results to a single deployment environment',
|
|
},
|
|
},
|
|
|
|
request: {
|
|
url: (params) => logfireUrl(params, LOGFIRE_QUERY_PATH),
|
|
method: 'POST',
|
|
headers: (params) => logfireHeaders(params.apiKey),
|
|
body: (params) =>
|
|
buildLogfireQueryBody({
|
|
sql: params.sql,
|
|
minTimestamp: params.minTimestamp,
|
|
maxTimestamp: params.maxTimestamp,
|
|
limit: params.limit,
|
|
timezone: params.timezone,
|
|
environment: params.environment,
|
|
}),
|
|
},
|
|
|
|
transformResponse: async (response) => {
|
|
const results = await parseLogfireResponse<LogfireQueryApiResponse>(response)
|
|
const rows = extractLogfireRows(results)
|
|
|
|
return {
|
|
success: true,
|
|
output: {
|
|
rows,
|
|
columns: extractLogfireColumns(results),
|
|
rowCount: rows.length,
|
|
},
|
|
}
|
|
},
|
|
|
|
outputs: {
|
|
rows: {
|
|
type: 'array',
|
|
description: 'Result rows. Row fields depend on the query projection.',
|
|
items: { type: 'object', description: 'A single result row' },
|
|
},
|
|
columns: {
|
|
type: 'array',
|
|
description: 'Column metadata for the result set',
|
|
items: {
|
|
type: 'object',
|
|
description: 'Column metadata',
|
|
properties: {
|
|
name: { type: 'string', description: 'Column name', nullable: true },
|
|
datatype: { type: 'json', description: 'Arrow datatype of the column' },
|
|
nullable: {
|
|
type: 'boolean',
|
|
description: 'Whether the column is nullable',
|
|
nullable: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
rowCount: { type: 'number', description: 'Number of rows returned' },
|
|
},
|
|
}
|