(_toolCallId: string, params: unknown)
| 87 | description: tool.description, |
| 88 | parameters: convertJsonSchemaToParameters(tool.inputSchema) as any, |
| 89 | async execute(_toolCallId: string, params: unknown): Promise<AgentToolResult<unknown>> { |
| 90 | const toolParams = (params && typeof params === 'object' ? params : {}) as Record<string, unknown> |
| 91 | const ctx = getContext() |
| 92 | const execCtx: ToolExecutionContext = { |
| 93 | db: ctx.db, |
| 94 | dataProvider: new CoreDataProvider(ctx.db), |
| 95 | sessionId: ctx.sessionId, |
| 96 | locale: ctx.locale, |
| 97 | semanticIndexService: ctx.semanticIndexService, |
| 98 | preprocessConfig: ctx.preprocessConfig, |
| 99 | ownerPlatformId: ctx.ownerPlatformId, |
| 100 | timeFilter: ctx.timeFilter, |
| 101 | maxMessagesLimit: ctx.maxMessagesLimit, |
| 102 | maxToolResultTokens: tokenBudget, |
| 103 | segmentText: (texts, locale, options) => batchSegmentWithFrequency(texts, locale as any, options as any), |
| 104 | desensitizeMessages: (messages: RawMessage[]): RawMessage[] => |
| 105 | preprocessMessages( |
| 106 | messages as PreprocessableMessage[], |
| 107 | ctx.preprocessConfig as PreprocessConfig | undefined |
| 108 | ) as RawMessage[], |
| 109 | } |
| 110 | try { |
| 111 | const result = await tool.handler(toolParams, execCtx) |
| 112 | const chartDetails = |
| 113 | result.chart || result.charts |
| 114 | ? { |
| 115 | ...(result.chart ? { chart: result.chart } : {}), |
| 116 | ...(result.charts ? { charts: result.charts } : {}), |
| 117 | } |
| 118 | : {} |
| 119 | |
| 120 | if (result.rawMessages && result.rawMessages.length > 0) { |
| 121 | // tools may mirror rawMessages inside data; keep it out of extraDetails |
| 122 | // so the pipeline only renders scalar metadata (same as the desktop adapter) |
| 123 | const { rawMessages: _rawInData, ...extraDetails } = (result.data ?? {}) as Record<string, unknown> |
| 124 | const preprocessCfg = ctx.preprocessConfig as PreprocessConfig | undefined |
| 125 | const pipelineResult = applyPreprocessingPipeline({ |
| 126 | rawMessages: result.rawMessages as PreprocessableMessage[], |
| 127 | preprocessConfig: preprocessCfg, |
| 128 | anonymizeNames: preprocessCfg?.anonymizeNames ?? false, |
| 129 | ownerPlatformId: ctx.ownerPlatformId, |
| 130 | locale: ctx.locale, |
| 131 | maxToolResultTokens: tokenBudget, |
| 132 | truncationStrategy: TOOL_TRUNCATION_STRATEGY[tool.name] ?? 'keep_last', |
| 133 | extraDetails, |
| 134 | logger: getServerAiLogger() ?? undefined, |
| 135 | }) |
| 136 | return { |
| 137 | content: [{ type: 'text', text: pipelineResult.text }], |
| 138 | details: Object.keys(chartDetails).length > 0 ? chartDetails : null, |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | const baseDetails = |
| 143 | typeof result.data === 'object' && result.data !== null |
| 144 | ? (result.data as Record<string, unknown>) |
| 145 | : result.data === undefined |
| 146 | ? null |
nothing calls this directly
no test coverage detected