(args: QueryLogsArgs, context?: ServerToolContext)
| 113 | inputSchema: queryLogsArgsSchema, |
| 114 | outputSchema: z.unknown(), |
| 115 | async execute(args: QueryLogsArgs, context?: ServerToolContext): Promise<unknown> { |
| 116 | if (!context?.userId) { |
| 117 | throw new Error('Unauthorized access') |
| 118 | } |
| 119 | const userId = context.userId |
| 120 | const workspaceId = resolveWorkspaceId(args, context) |
| 121 | |
| 122 | if (args.view === 'list') { |
| 123 | const { view: _view, ...rest } = args |
| 124 | const params = { ...rest, workspaceId } as ListLogsParams |
| 125 | logger.info('query_logs list', { workspaceId, sortBy: params.sortBy }) |
| 126 | return listLogs(params, userId) |
| 127 | } |
| 128 | |
| 129 | // overview / full / grep — single execution by id |
| 130 | const detail = await fetchLogDetail({ |
| 131 | userId, |
| 132 | workspaceId, |
| 133 | lookupColumn: 'executionId', |
| 134 | lookupValue: args.executionId, |
| 135 | }) |
| 136 | if (!detail) { |
| 137 | return { ok: false, error: `Execution not found: ${args.executionId}` } |
| 138 | } |
| 139 | |
| 140 | const execData = detail.executionData as |
| 141 | | { traceSpans?: TraceSpan[]; totalDuration?: number | null } |
| 142 | | undefined |
| 143 | const traceSpans = (execData?.traceSpans ?? []) as TraceSpan[] |
| 144 | const viewCtx = buildLogViewContext(detail, workspaceId, userId) |
| 145 | |
| 146 | if (args.pattern) { |
| 147 | logger.info('query_logs grep', { workspaceId, executionId: args.executionId }) |
| 148 | const { matches, truncated } = await grepSpans(traceSpans, args.pattern, viewCtx) |
| 149 | return { |
| 150 | executionId: detail.executionId, |
| 151 | workflowId: detail.workflowId, |
| 152 | status: detail.status, |
| 153 | pattern: args.pattern, |
| 154 | matches, |
| 155 | truncated, |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | if (args.view === 'overview') { |
| 160 | return { |
| 161 | executionId: detail.executionId, |
| 162 | workflowId: detail.workflowId, |
| 163 | status: detail.status, |
| 164 | trigger: detail.trigger, |
| 165 | durationMs: execData?.totalDuration ?? null, |
| 166 | cost: detail.cost ?? null, |
| 167 | spans: toOverview(traceSpans), |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | // full |
| 172 | const spans = await toFull(traceSpans, viewCtx, { |
nothing calls this directly
no test coverage detected