@open-mercato/ai-assistant 0.6.6-develop.6465.1.019f0fb26f → 0.6.6-develop.6471.1.9ab5bdd79a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/frontend/hooks/useCommandPalette.js +16 -14
- package/dist/frontend/hooks/useCommandPalette.js.map +2 -2
- package/dist/modules/ai_assistant/api/ai/actions/[id]/cancel/route.js +3 -1
- package/dist/modules/ai_assistant/api/ai/actions/[id]/cancel/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/ai/actions/[id]/confirm/route.js +3 -1
- package/dist/modules/ai_assistant/api/ai/actions/[id]/confirm/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/ai/actions/[id]/route.js +3 -1
- package/dist/modules/ai_assistant/api/ai/actions/[id]/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/ai/agents/[agentId]/loop-override/route.js +5 -3
- package/dist/modules/ai_assistant/api/ai/agents/[agentId]/loop-override/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/ai/agents/[agentId]/models/route.js +4 -2
- package/dist/modules/ai_assistant/api/ai/agents/[agentId]/models/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/ai/agents/[agentId]/mutation-policy/route.js +5 -3
- package/dist/modules/ai_assistant/api/ai/agents/[agentId]/mutation-policy/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/ai/agents/[agentId]/prompt-override/route.js +4 -2
- package/dist/modules/ai_assistant/api/ai/agents/[agentId]/prompt-override/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/ai/agents/route.js +3 -1
- package/dist/modules/ai_assistant/api/ai/agents/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/ai/chat/route.js +6 -7
- package/dist/modules/ai_assistant/api/ai/chat/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/ai/conversations/[conversationId]/route.js +5 -3
- package/dist/modules/ai_assistant/api/ai/conversations/[conversationId]/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/ai/conversations/import/route.js +3 -1
- package/dist/modules/ai_assistant/api/ai/conversations/import/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/ai/conversations/route.js +4 -2
- package/dist/modules/ai_assistant/api/ai/conversations/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/ai/run-object/route.js +3 -1
- package/dist/modules/ai_assistant/api/ai/run-object/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/chat/route.js +23 -14
- package/dist/modules/ai_assistant/api/chat/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/health/route.js +3 -1
- package/dist/modules/ai_assistant/api/health/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/mcp-key/route.js +3 -1
- package/dist/modules/ai_assistant/api/mcp-key/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/route/route.js +11 -9
- package/dist/modules/ai_assistant/api/route/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/session-key/route.js +3 -1
- package/dist/modules/ai_assistant/api/session-key/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/settings/allowlist/route.js +4 -2
- package/dist/modules/ai_assistant/api/settings/allowlist/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/settings/route.js +6 -4
- package/dist/modules/ai_assistant/api/settings/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/tools/execute/route.js +3 -1
- package/dist/modules/ai_assistant/api/tools/execute/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/tools/route.js +3 -1
- package/dist/modules/ai_assistant/api/tools/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/usage/daily/route.js +3 -1
- package/dist/modules/ai_assistant/api/usage/daily/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/usage/sessions/[sessionId]/route.js +3 -1
- package/dist/modules/ai_assistant/api/usage/sessions/[sessionId]/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/usage/sessions/route.js +3 -1
- package/dist/modules/ai_assistant/api/usage/sessions/route.js.map +2 -2
- package/dist/modules/ai_assistant/cli.js +3 -0
- package/dist/modules/ai_assistant/cli.js.map +2 -2
- package/dist/modules/ai_assistant/lib/agent-policy.js +7 -5
- package/dist/modules/ai_assistant/lib/agent-policy.js.map +2 -2
- package/dist/modules/ai_assistant/lib/agent-registry.js +11 -13
- package/dist/modules/ai_assistant/lib/agent-registry.js.map +2 -2
- package/dist/modules/ai_assistant/lib/agent-runtime.js +21 -44
- package/dist/modules/ai_assistant/lib/agent-runtime.js.map +2 -2
- package/dist/modules/ai_assistant/lib/agent-tools.js +5 -10
- package/dist/modules/ai_assistant/lib/agent-tools.js.map +2 -2
- package/dist/modules/ai_assistant/lib/ai-overrides.js +5 -9
- package/dist/modules/ai_assistant/lib/ai-overrides.js.map +2 -2
- package/dist/modules/ai_assistant/lib/api-endpoint-index.js +22 -22
- package/dist/modules/ai_assistant/lib/api-endpoint-index.js.map +2 -2
- package/dist/modules/ai_assistant/lib/attachment-parts.js +10 -26
- package/dist/modules/ai_assistant/lib/attachment-parts.js.map +2 -2
- package/dist/modules/ai_assistant/lib/auth.js +3 -1
- package/dist/modules/ai_assistant/lib/auth.js.map +2 -2
- package/dist/modules/ai_assistant/lib/codemode-tools.js +15 -17
- package/dist/modules/ai_assistant/lib/codemode-tools.js.map +2 -2
- package/dist/modules/ai_assistant/lib/entity-index.js +7 -5
- package/dist/modules/ai_assistant/lib/entity-index.js.map +2 -2
- package/dist/modules/ai_assistant/lib/generated-registry-loader.js +3 -4
- package/dist/modules/ai_assistant/lib/generated-registry-loader.js.map +2 -2
- package/dist/modules/ai_assistant/lib/http-server.js +45 -48
- package/dist/modules/ai_assistant/lib/http-server.js.map +2 -2
- package/dist/modules/ai_assistant/lib/llm-bootstrap.js +5 -12
- package/dist/modules/ai_assistant/lib/llm-bootstrap.js.map +2 -2
- package/dist/modules/ai_assistant/lib/mcp-client.js +3 -1
- package/dist/modules/ai_assistant/lib/mcp-client.js.map +2 -2
- package/dist/modules/ai_assistant/lib/mcp-dev-key-resolution.js +3 -1
- package/dist/modules/ai_assistant/lib/mcp-dev-key-resolution.js.map +2 -2
- package/dist/modules/ai_assistant/lib/mcp-dev-server.js +3 -1
- package/dist/modules/ai_assistant/lib/mcp-dev-server.js.map +2 -2
- package/dist/modules/ai_assistant/lib/mcp-server.js +24 -19
- package/dist/modules/ai_assistant/lib/mcp-server.js.map +2 -2
- package/dist/modules/ai_assistant/lib/mcp-tool-adapter.js +3 -1
- package/dist/modules/ai_assistant/lib/mcp-tool-adapter.js.map +2 -2
- package/dist/modules/ai_assistant/lib/model-factory.js +4 -2
- package/dist/modules/ai_assistant/lib/model-factory.js.map +2 -2
- package/dist/modules/ai_assistant/lib/opencode-client.js +5 -3
- package/dist/modules/ai_assistant/lib/opencode-client.js.map +2 -2
- package/dist/modules/ai_assistant/lib/opencode-handlers.js +30 -12
- package/dist/modules/ai_assistant/lib/opencode-handlers.js.map +2 -2
- package/dist/modules/ai_assistant/lib/pending-action-cancel.js +3 -1
- package/dist/modules/ai_assistant/lib/pending-action-cancel.js.map +2 -2
- package/dist/modules/ai_assistant/lib/pending-action-executor.js +3 -1
- package/dist/modules/ai_assistant/lib/pending-action-executor.js.map +2 -2
- package/dist/modules/ai_assistant/lib/prepare-mutation.js +4 -6
- package/dist/modules/ai_assistant/lib/prepare-mutation.js.map +2 -2
- package/dist/modules/ai_assistant/lib/schema-utils.js +3 -1
- package/dist/modules/ai_assistant/lib/schema-utils.js.map +2 -2
- package/dist/modules/ai_assistant/lib/token-usage-recorder.js +4 -8
- package/dist/modules/ai_assistant/lib/token-usage-recorder.js.map +2 -2
- package/dist/modules/ai_assistant/lib/tool-executor.js +3 -1
- package/dist/modules/ai_assistant/lib/tool-executor.js.map +2 -2
- package/dist/modules/ai_assistant/lib/tool-loader.js +18 -25
- package/dist/modules/ai_assistant/lib/tool-loader.js.map +2 -2
- package/dist/modules/ai_assistant/lib/tool-registry.js +3 -1
- package/dist/modules/ai_assistant/lib/tool-registry.js.map +2 -2
- package/dist/modules/ai_assistant/lib/tool-test-runner.js +3 -1
- package/dist/modules/ai_assistant/lib/tool-test-runner.js.map +2 -2
- package/dist/modules/ai_assistant/setup.js +4 -8
- package/dist/modules/ai_assistant/setup.js.map +2 -2
- package/dist/modules/ai_assistant/subscribers/conversation-shared-notify.js +3 -1
- package/dist/modules/ai_assistant/subscribers/conversation-shared-notify.js.map +2 -2
- package/dist/modules/ai_assistant/workers/ai-pending-action-cleanup.js +7 -19
- package/dist/modules/ai_assistant/workers/ai-pending-action-cleanup.js.map +2 -2
- package/dist/modules/ai_assistant/workers/ai-token-usage-prune.js +5 -11
- package/dist/modules/ai_assistant/workers/ai-token-usage-prune.js.map +2 -2
- package/package.json +6 -6
- package/src/frontend/hooks/useCommandPalette.ts +17 -16
- package/src/modules/ai_assistant/__tests__/events.test.ts +23 -5
- package/src/modules/ai_assistant/__tests__/integration/ws-c-attachment-bridge.test.ts +21 -3
- package/src/modules/ai_assistant/__tests__/integration/ws-c-policy-and-tools.test.ts +22 -3
- package/src/modules/ai_assistant/__tests__/token-usage-recorder.test.ts +26 -5
- package/src/modules/ai_assistant/api/ai/actions/[id]/cancel/route.ts +4 -1
- package/src/modules/ai_assistant/api/ai/actions/[id]/confirm/route.ts +4 -1
- package/src/modules/ai_assistant/api/ai/actions/[id]/route.ts +4 -1
- package/src/modules/ai_assistant/api/ai/agents/[agentId]/loop-override/route.ts +6 -3
- package/src/modules/ai_assistant/api/ai/agents/[agentId]/models/route.ts +5 -2
- package/src/modules/ai_assistant/api/ai/agents/[agentId]/mutation-policy/route.ts +6 -3
- package/src/modules/ai_assistant/api/ai/agents/[agentId]/prompt-override/route.ts +5 -2
- package/src/modules/ai_assistant/api/ai/agents/route.ts +4 -1
- package/src/modules/ai_assistant/api/ai/chat/route.ts +7 -7
- package/src/modules/ai_assistant/api/ai/conversations/[conversationId]/route.ts +6 -3
- package/src/modules/ai_assistant/api/ai/conversations/import/route.ts +4 -1
- package/src/modules/ai_assistant/api/ai/conversations/route.ts +5 -2
- package/src/modules/ai_assistant/api/ai/run-object/route.ts +4 -1
- package/src/modules/ai_assistant/api/chat/route.ts +24 -15
- package/src/modules/ai_assistant/api/health/route.ts +4 -1
- package/src/modules/ai_assistant/api/mcp-key/route.ts +4 -1
- package/src/modules/ai_assistant/api/route/route.ts +12 -9
- package/src/modules/ai_assistant/api/session-key/route.ts +4 -1
- package/src/modules/ai_assistant/api/settings/allowlist/route.ts +5 -2
- package/src/modules/ai_assistant/api/settings/route.ts +7 -4
- package/src/modules/ai_assistant/api/tools/execute/route.ts +4 -1
- package/src/modules/ai_assistant/api/tools/route.ts +4 -1
- package/src/modules/ai_assistant/api/usage/daily/route.ts +4 -1
- package/src/modules/ai_assistant/api/usage/sessions/[sessionId]/route.ts +4 -1
- package/src/modules/ai_assistant/api/usage/sessions/route.ts +4 -1
- package/src/modules/ai_assistant/cli.ts +5 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-policy.mutation-override.test.ts +20 -2
- package/src/modules/ai_assistant/lib/__tests__/agent-registry.test.ts +25 -5
- package/src/modules/ai_assistant/lib/__tests__/agent-runtime-loop-phase0.test.ts +21 -2
- package/src/modules/ai_assistant/lib/__tests__/agent-runtime-parity.test.ts +23 -3
- package/src/modules/ai_assistant/lib/__tests__/agent-runtime-phase4a.test.ts +20 -2
- package/src/modules/ai_assistant/lib/__tests__/agent-tools.test.ts +22 -3
- package/src/modules/ai_assistant/lib/__tests__/ai-overrides.test.ts +23 -3
- package/src/modules/ai_assistant/lib/__tests__/attachment-parts.test.ts +25 -7
- package/src/modules/ai_assistant/lib/__tests__/model-factory.test.ts +25 -5
- package/src/modules/ai_assistant/lib/__tests__/pending-action-cancel.test.ts +19 -1
- package/src/modules/ai_assistant/lib/__tests__/prepare-mutation.test.ts +22 -3
- package/src/modules/ai_assistant/lib/agent-policy.ts +8 -5
- package/src/modules/ai_assistant/lib/agent-registry.ts +12 -15
- package/src/modules/ai_assistant/lib/agent-runtime.ts +23 -46
- package/src/modules/ai_assistant/lib/agent-tools.ts +7 -11
- package/src/modules/ai_assistant/lib/ai-overrides.ts +6 -9
- package/src/modules/ai_assistant/lib/api-endpoint-index.ts +23 -22
- package/src/modules/ai_assistant/lib/attachment-parts.ts +14 -29
- package/src/modules/ai_assistant/lib/auth.ts +4 -1
- package/src/modules/ai_assistant/lib/codemode-tools.ts +17 -17
- package/src/modules/ai_assistant/lib/entity-index.ts +8 -5
- package/src/modules/ai_assistant/lib/generated-registry-loader.ts +4 -4
- package/src/modules/ai_assistant/lib/http-server.ts +46 -48
- package/src/modules/ai_assistant/lib/llm-bootstrap.ts +7 -13
- package/src/modules/ai_assistant/lib/mcp-client.ts +4 -1
- package/src/modules/ai_assistant/lib/mcp-dev-key-resolution.ts +4 -1
- package/src/modules/ai_assistant/lib/mcp-dev-server.ts +4 -1
- package/src/modules/ai_assistant/lib/mcp-server.ts +27 -19
- package/src/modules/ai_assistant/lib/mcp-tool-adapter.ts +4 -1
- package/src/modules/ai_assistant/lib/model-factory.ts +6 -3
- package/src/modules/ai_assistant/lib/opencode-client.ts +6 -3
- package/src/modules/ai_assistant/lib/opencode-handlers.ts +32 -12
- package/src/modules/ai_assistant/lib/pending-action-cancel.ts +4 -1
- package/src/modules/ai_assistant/lib/pending-action-executor.ts +4 -1
- package/src/modules/ai_assistant/lib/prepare-mutation.ts +5 -6
- package/src/modules/ai_assistant/lib/schema-utils.ts +4 -1
- package/src/modules/ai_assistant/lib/token-usage-recorder.ts +5 -8
- package/src/modules/ai_assistant/lib/tool-executor.ts +4 -1
- package/src/modules/ai_assistant/lib/tool-loader.ts +19 -25
- package/src/modules/ai_assistant/lib/tool-registry.ts +4 -1
- package/src/modules/ai_assistant/lib/tool-test-runner.ts +4 -1
- package/src/modules/ai_assistant/setup.ts +5 -8
- package/src/modules/ai_assistant/subscribers/conversation-shared-notify.ts +4 -1
- package/src/modules/ai_assistant/workers/ai-pending-action-cleanup.ts +8 -19
- package/src/modules/ai_assistant/workers/ai-token-usage-prune.ts +6 -11
|
@@ -13,6 +13,14 @@ import type { McpServerOptions, McpToolContext } from './types'
|
|
|
13
13
|
import type { SearchService } from '@open-mercato/search/service'
|
|
14
14
|
import type { RbacService } from '@open-mercato/core/modules/auth/services/rbacService'
|
|
15
15
|
|
|
16
|
+
|
|
17
|
+
const formatStderrError = (error: unknown): string =>
|
|
18
|
+
error instanceof Error ? error.stack ?? error.message : String(error)
|
|
19
|
+
|
|
20
|
+
const writeStderrLine = (line: string): void => {
|
|
21
|
+
process.stderr.write(`${line}\n`)
|
|
22
|
+
}
|
|
23
|
+
|
|
16
24
|
/**
|
|
17
25
|
* Create and configure an MCP server instance.
|
|
18
26
|
*/
|
|
@@ -43,7 +51,7 @@ export async function createMcpServer(options: McpServerOptions): Promise<Server
|
|
|
43
51
|
userId = authResult.userId
|
|
44
52
|
userFeatures = authResult.features
|
|
45
53
|
isSuperAdmin = authResult.isSuperAdmin
|
|
46
|
-
|
|
54
|
+
writeStderrLine(`[MCP Server] Authenticated via API key: ${authResult.keyName}`)
|
|
47
55
|
} else if (context && context.userId) {
|
|
48
56
|
// Manual context with a real user — load that user's ACL.
|
|
49
57
|
tenantId = context.tenantId
|
|
@@ -67,7 +75,7 @@ export async function createMcpServer(options: McpServerOptions): Promise<Server
|
|
|
67
75
|
userFeatures = acl.features
|
|
68
76
|
isSuperAdmin = acl.isSuperAdmin
|
|
69
77
|
} catch (error) {
|
|
70
|
-
|
|
78
|
+
writeStderrLine(`[MCP Server] Failed to load user ACL: ${formatStderrError(error)}`)
|
|
71
79
|
}
|
|
72
80
|
} else if (allowUnauthenticatedSuperadmin) {
|
|
73
81
|
// Explicit, loud dev/testing opt-in. Without a user there is no ACL to load,
|
|
@@ -78,7 +86,7 @@ export async function createMcpServer(options: McpServerOptions): Promise<Server
|
|
|
78
86
|
organizationId = context.organizationId
|
|
79
87
|
}
|
|
80
88
|
isSuperAdmin = true
|
|
81
|
-
|
|
89
|
+
writeStderrLine(
|
|
82
90
|
'[MCP Server] WARNING: allowUnauthenticatedSuperadmin is enabled — running with UNAUTHENTICATED SUPERADMIN access and no per-user ACL. Do not use this outside local development/testing.'
|
|
83
91
|
)
|
|
84
92
|
} else {
|
|
@@ -115,7 +123,7 @@ export async function createMcpServer(options: McpServerOptions): Promise<Server
|
|
|
115
123
|
)
|
|
116
124
|
|
|
117
125
|
if (config.debug) {
|
|
118
|
-
|
|
126
|
+
writeStderrLine(
|
|
119
127
|
`[MCP Server] Listing ${accessibleTools.length}/${tools.length} tools (filtered by ACL)`
|
|
120
128
|
)
|
|
121
129
|
}
|
|
@@ -135,7 +143,7 @@ export async function createMcpServer(options: McpServerOptions): Promise<Server
|
|
|
135
143
|
const { name, arguments: args } = request.params
|
|
136
144
|
|
|
137
145
|
if (config.debug) {
|
|
138
|
-
|
|
146
|
+
writeStderrLine(`[MCP Server] Calling tool: ${name} argKeys=${Object.keys(args ?? {}).join(',')}`)
|
|
139
147
|
}
|
|
140
148
|
|
|
141
149
|
const result = await executeTool(name, args ?? {}, toolContext)
|
|
@@ -181,18 +189,18 @@ export async function runMcpServer(options: McpServerOptions): Promise<void> {
|
|
|
181
189
|
const orm = await getOrm()
|
|
182
190
|
const graph = await extractEntityGraph(orm)
|
|
183
191
|
cacheEntityGraph(graph)
|
|
184
|
-
|
|
192
|
+
writeStderrLine(`[MCP Server] Entity graph: ${graph.nodes.length} entities`)
|
|
185
193
|
} catch (error) {
|
|
186
|
-
|
|
194
|
+
writeStderrLine(`[MCP Server] Entity graph skipped: ${error instanceof Error ? error.message : String(error)}`)
|
|
187
195
|
}
|
|
188
196
|
|
|
189
197
|
// Pre-cache raw OpenAPI spec for Code Mode search tool
|
|
190
198
|
try {
|
|
191
199
|
const { getRawOpenApiSpec } = await import('./api-endpoint-index')
|
|
192
200
|
await getRawOpenApiSpec()
|
|
193
|
-
|
|
201
|
+
writeStderrLine('[MCP Server] Raw OpenAPI spec cached for Code Mode')
|
|
194
202
|
} catch (error) {
|
|
195
|
-
|
|
203
|
+
writeStderrLine(`[MCP Server] Raw OpenAPI spec caching skipped: ${error instanceof Error ? error.message : String(error)}`)
|
|
196
204
|
}
|
|
197
205
|
|
|
198
206
|
// Load tools from all modules before starting
|
|
@@ -204,7 +212,7 @@ export async function runMcpServer(options: McpServerOptions): Promise<void> {
|
|
|
204
212
|
await indexToolsForSearch(searchService)
|
|
205
213
|
} catch (error) {
|
|
206
214
|
// Search service might not be configured - discovery will use fallback
|
|
207
|
-
|
|
215
|
+
writeStderrLine('[MCP Server] Search indexing skipped (search service not available)')
|
|
208
216
|
}
|
|
209
217
|
|
|
210
218
|
const server = await createMcpServer(options)
|
|
@@ -212,27 +220,27 @@ export async function runMcpServer(options: McpServerOptions): Promise<void> {
|
|
|
212
220
|
|
|
213
221
|
const toolCount = getToolRegistry().listToolNames().length
|
|
214
222
|
|
|
215
|
-
|
|
223
|
+
writeStderrLine(`[MCP Server] Starting ${options.config.name} v${options.config.version}`)
|
|
216
224
|
|
|
217
225
|
if (options.apiKeySecret && options.apiKeySecret.trim().length > 0) {
|
|
218
|
-
|
|
226
|
+
writeStderrLine(`[MCP Server] Authentication: API key`)
|
|
219
227
|
} else if (options.context && options.context.userId) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
228
|
+
writeStderrLine(`[MCP Server] Tenant: ${options.context.tenantId ?? '(none)'}`)
|
|
229
|
+
writeStderrLine(`[MCP Server] Organization: ${options.context.organizationId ?? '(none)'}`)
|
|
230
|
+
writeStderrLine(`[MCP Server] User: ${options.context.userId}`)
|
|
223
231
|
} else {
|
|
224
|
-
|
|
232
|
+
writeStderrLine(`[MCP Server] Authentication: none (unauthenticated superadmin opt-in)`)
|
|
225
233
|
}
|
|
226
234
|
|
|
227
|
-
|
|
235
|
+
writeStderrLine(`[MCP Server] Tools registered: ${toolCount}`)
|
|
228
236
|
|
|
229
237
|
await server.connect(transport)
|
|
230
238
|
|
|
231
|
-
|
|
239
|
+
writeStderrLine('[MCP Server] Connected and ready for requests')
|
|
232
240
|
|
|
233
241
|
// Handle shutdown gracefully
|
|
234
242
|
const shutdown = async () => {
|
|
235
|
-
|
|
243
|
+
writeStderrLine('[MCP Server] Shutting down...')
|
|
236
244
|
await server.close()
|
|
237
245
|
process.exit(0)
|
|
238
246
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { createLogger } from '@open-mercato/shared/lib/logger'
|
|
1
2
|
import { dynamicTool, type Tool } from 'ai'
|
|
2
3
|
import type { InProcessMcpClient, ToolInfoWithSchema } from './in-process-client'
|
|
3
4
|
import { toSafeZodSchema } from './schema-utils'
|
|
4
5
|
|
|
6
|
+
const logger = createLogger('ai_assistant')
|
|
7
|
+
|
|
5
8
|
/**
|
|
6
9
|
* Convert MCP tools to Vercel AI SDK format.
|
|
7
10
|
*
|
|
@@ -43,7 +46,7 @@ export function convertMcpToolsToAiSdk(
|
|
|
43
46
|
},
|
|
44
47
|
})
|
|
45
48
|
} catch (error) {
|
|
46
|
-
|
|
49
|
+
logger.error('Error converting tool', { toolName: mcpTool.name, err: error })
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
52
|
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
* @see packages/core/src/modules/inbox_ops/lib/llmProvider.ts
|
|
62
62
|
*/
|
|
63
63
|
|
|
64
|
+
import { createLogger } from '@open-mercato/shared/lib/logger'
|
|
64
65
|
import type { AwilixContainer } from 'awilix'
|
|
65
66
|
import type { EnvLookup, LlmProvider } from '@open-mercato/shared/lib/ai/llm-provider'
|
|
66
67
|
import { llmProviderRegistry } from '@open-mercato/shared/lib/ai/llm-provider-registry'
|
|
@@ -74,6 +75,8 @@ import {
|
|
|
74
75
|
type TenantAllowlistSnapshot,
|
|
75
76
|
} from './model-allowlist'
|
|
76
77
|
|
|
78
|
+
const logger = createLogger('ai_assistant')
|
|
79
|
+
|
|
77
80
|
/**
|
|
78
81
|
* Minimal AI SDK LanguageModel shape — the factory exposes the protocol-
|
|
79
82
|
* agnostic `unknown`-typed return from {@link LlmProvider.createModel} under a
|
|
@@ -775,7 +778,7 @@ interface EnforceAllowlistResult {
|
|
|
775
778
|
* 2. The provider's `defaultModel` (if allowed).
|
|
776
779
|
* 3. The first model from the effective allowlist for that provider.
|
|
777
780
|
*
|
|
778
|
-
* Both fall-back paths emit a
|
|
781
|
+
* Both fall-back paths emit a logger warning so the operator can see why the
|
|
779
782
|
* runtime did not honor the requested combination. The function never throws.
|
|
780
783
|
*/
|
|
781
784
|
function enforceAllowlist(input: EnforceAllowlistInput): EnforceAllowlistResult {
|
|
@@ -795,7 +798,7 @@ function enforceAllowlist(input: EnforceAllowlistInput): EnforceAllowlistResult
|
|
|
795
798
|
? 'the effective allowlist (env ∩ tenant)'
|
|
796
799
|
: 'OM_AI_AVAILABLE_PROVIDERS'
|
|
797
800
|
fallback = `Provider "${provider.id}" is not in ${source}; using "${replacement.id}" instead.`
|
|
798
|
-
|
|
801
|
+
logger.warn('Allowlist provider fallback', { reason: fallback })
|
|
799
802
|
provider = replacement
|
|
800
803
|
modelId = pickAllowedModel({
|
|
801
804
|
provider,
|
|
@@ -819,7 +822,7 @@ function enforceAllowlist(input: EnforceAllowlistInput): EnforceAllowlistResult
|
|
|
819
822
|
? `the effective allowlist (env ∩ tenant) for "${provider.id}"`
|
|
820
823
|
: `OM_AI_AVAILABLE_MODELS_${provider.id.toUpperCase()}`
|
|
821
824
|
const reason = `Model "${modelId}" is not in ${source}; using "${replacementModel}" instead.`
|
|
822
|
-
|
|
825
|
+
logger.warn('Allowlist model fallback', { reason })
|
|
823
826
|
fallback = fallback ? `${fallback} ${reason}` : reason
|
|
824
827
|
modelId = replacementModel
|
|
825
828
|
}
|
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
* Client for communicating with OpenCode server running in headless mode.
|
|
5
5
|
* OpenCode is used as an AI agent that can execute MCP tools.
|
|
6
6
|
*/
|
|
7
|
+
import { createLogger } from '@open-mercato/shared/lib/logger'
|
|
7
8
|
import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
|
|
8
9
|
import { fetchWithTimeout, resolveTimeoutMs } from '@open-mercato/shared/lib/http/fetchWithTimeout'
|
|
9
10
|
|
|
11
|
+
const logger = createLogger('ai_assistant')
|
|
12
|
+
|
|
10
13
|
const DEFAULT_OPENCODE_REQUEST_TIMEOUT_MS = 30_000
|
|
11
14
|
const DEFAULT_OPENCODE_SSE_CONNECT_TIMEOUT_MS = 15_000
|
|
12
15
|
|
|
@@ -411,7 +414,7 @@ export class OpenCodeClient {
|
|
|
411
414
|
|
|
412
415
|
const body = { answers }
|
|
413
416
|
|
|
414
|
-
|
|
417
|
+
logger.debug('Answering question', { questionId, answersCount: answers.length })
|
|
415
418
|
|
|
416
419
|
const res = await fetchWithTimeout(`${this.baseUrl}/question/${questionId}/reply`, {
|
|
417
420
|
method: 'POST',
|
|
@@ -421,7 +424,7 @@ export class OpenCodeClient {
|
|
|
421
424
|
})
|
|
422
425
|
|
|
423
426
|
const responseText = await res.text()
|
|
424
|
-
|
|
427
|
+
logger.debug('Answer response received', { status: res.status, bytes: responseText.length })
|
|
425
428
|
|
|
426
429
|
if (!res.ok) {
|
|
427
430
|
throw new Error(`Failed to answer question: ${res.status} - ${responseText}`)
|
|
@@ -432,7 +435,7 @@ export class OpenCodeClient {
|
|
|
432
435
|
* Reject a pending question.
|
|
433
436
|
*/
|
|
434
437
|
async rejectQuestion(questionId: string): Promise<void> {
|
|
435
|
-
|
|
438
|
+
logger.info('OpenCode Client — Rejecting question', { questionId: questionId })
|
|
436
439
|
|
|
437
440
|
const res = await fetchWithTimeout(`${this.baseUrl}/question/${questionId}/reject`, {
|
|
438
441
|
method: 'POST',
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createLogger } from '@open-mercato/shared/lib/logger'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* OpenCode API Route Handlers
|
|
3
5
|
*
|
|
@@ -12,6 +14,8 @@ import {
|
|
|
12
14
|
type OpenCodeQuestion,
|
|
13
15
|
} from './opencode-client'
|
|
14
16
|
|
|
17
|
+
const logger = createLogger('ai_assistant').child({ component: 'opencode' })
|
|
18
|
+
|
|
15
19
|
let clientInstance: OpenCodeClient | null = null
|
|
16
20
|
|
|
17
21
|
function getClient(): OpenCodeClient {
|
|
@@ -445,11 +449,19 @@ export async function handleOpenCodeMessageStreaming(
|
|
|
445
449
|
// Session is explicitly idle and no questions - complete
|
|
446
450
|
resolved = true
|
|
447
451
|
const durationMs = Date.now() - startTime
|
|
448
|
-
|
|
452
|
+
logger.info('Session complete (heartbeat)', {
|
|
453
|
+
sessionId: targetSessionId.slice(0, 16),
|
|
454
|
+
durationMs,
|
|
455
|
+
inputTokens: usageStats.totalInputTokens,
|
|
456
|
+
outputTokens: usageStats.totalOutputTokens,
|
|
457
|
+
toolCalls: usageStats.toolCalls,
|
|
458
|
+
tools: usageStats.toolNames.join(','),
|
|
459
|
+
messages: usageStats.messageCount,
|
|
460
|
+
})
|
|
449
461
|
try {
|
|
450
462
|
await onEvent({ type: 'done', sessionId: targetSessionId })
|
|
451
463
|
} catch (err) {
|
|
452
|
-
|
|
464
|
+
logger.error('Heartbeat: failed to emit done event', { err })
|
|
453
465
|
}
|
|
454
466
|
cleanup()
|
|
455
467
|
clearTimeout(timeout)
|
|
@@ -458,7 +470,7 @@ export async function handleOpenCodeMessageStreaming(
|
|
|
458
470
|
}
|
|
459
471
|
// Status is 'unknown' or something else - wait for SSE events
|
|
460
472
|
} catch (err) {
|
|
461
|
-
|
|
473
|
+
logger.error('Heartbeat error', { err })
|
|
462
474
|
}
|
|
463
475
|
}
|
|
464
476
|
}, 1000)
|
|
@@ -572,7 +584,15 @@ export async function handleOpenCodeMessageStreaming(
|
|
|
572
584
|
// Truly idle - complete the stream
|
|
573
585
|
resolved = true
|
|
574
586
|
const durationMs = Date.now() - startTime
|
|
575
|
-
|
|
587
|
+
logger.info('Session complete', {
|
|
588
|
+
sessionId: targetSessionId.slice(0, 16),
|
|
589
|
+
durationMs,
|
|
590
|
+
inputTokens: usageStats.totalInputTokens,
|
|
591
|
+
outputTokens: usageStats.totalOutputTokens,
|
|
592
|
+
toolCalls: usageStats.toolCalls,
|
|
593
|
+
tools: usageStats.toolNames.join(','),
|
|
594
|
+
messages: usageStats.messageCount,
|
|
595
|
+
})
|
|
576
596
|
await onEvent({ type: 'done', sessionId: targetSessionId })
|
|
577
597
|
cleanup()
|
|
578
598
|
clearTimeout(timeout)
|
|
@@ -580,14 +600,14 @@ export async function handleOpenCodeMessageStreaming(
|
|
|
580
600
|
resolve()
|
|
581
601
|
}
|
|
582
602
|
} catch (err) {
|
|
583
|
-
|
|
603
|
+
logger.error('Error in timeout callback', { err })
|
|
584
604
|
// Still try to complete even if there was an error
|
|
585
605
|
if (!resolved) {
|
|
586
606
|
resolved = true
|
|
587
607
|
try {
|
|
588
608
|
await onEvent({ type: 'done', sessionId: targetSessionId })
|
|
589
609
|
} catch (e2) {
|
|
590
|
-
|
|
610
|
+
logger.error('Failed to emit done event', { err: e2 })
|
|
591
611
|
}
|
|
592
612
|
cleanup()
|
|
593
613
|
clearTimeout(timeout)
|
|
@@ -639,7 +659,7 @@ export async function handleOpenCodeMessageStreaming(
|
|
|
639
659
|
if (info.tokens) {
|
|
640
660
|
usageStats.totalInputTokens += info.tokens.input || 0
|
|
641
661
|
usageStats.totalOutputTokens += info.tokens.output || 0
|
|
642
|
-
|
|
662
|
+
logger.debug('Token usage for message', { message: usageStats.messageCount, inputTokens: info.tokens.input, outputTokens: info.tokens.output, model: info.modelID || 'unknown' })
|
|
643
663
|
}
|
|
644
664
|
|
|
645
665
|
// Emit intermediate metadata for visibility
|
|
@@ -675,14 +695,14 @@ export async function handleOpenCodeMessageStreaming(
|
|
|
675
695
|
break
|
|
676
696
|
case 'thinking':
|
|
677
697
|
// Extended thinking blocks — route to debug panel only, never to chat
|
|
678
|
-
|
|
698
|
+
logger.debug('Thinking block received', { chars: (delta || part.text || '').length })
|
|
679
699
|
await onEvent({ type: 'debug', partType: 'thinking', data: { text: delta || part.text } })
|
|
680
700
|
break
|
|
681
701
|
case 'tool_use':
|
|
682
702
|
if (part.name) {
|
|
683
703
|
usageStats.toolCalls++
|
|
684
704
|
usageStats.toolNames.push(part.name)
|
|
685
|
-
|
|
705
|
+
logger.debug('Tool call observed', { toolCallNumber: usageStats.toolCalls, toolName: part.name })
|
|
686
706
|
await onEvent({
|
|
687
707
|
type: 'tool-call',
|
|
688
708
|
id: part.id,
|
|
@@ -717,7 +737,7 @@ export async function handleOpenCodeMessageStreaming(
|
|
|
717
737
|
}
|
|
718
738
|
}
|
|
719
739
|
} catch (err) {
|
|
720
|
-
|
|
740
|
+
logger.error('Error processing SSE event', { err })
|
|
721
741
|
}
|
|
722
742
|
},
|
|
723
743
|
(error) => {
|
|
@@ -731,7 +751,7 @@ export async function handleOpenCodeMessageStreaming(
|
|
|
731
751
|
// We only catch errors here - successful completion is signaled via SSE session.status: idle
|
|
732
752
|
client.sendMessage(session.id, message, { model }).catch((err) => {
|
|
733
753
|
// Log send errors - SSE should also receive an error event
|
|
734
|
-
|
|
754
|
+
logger.error('Send error (SSE should handle)', { err })
|
|
735
755
|
})
|
|
736
756
|
|
|
737
757
|
// Wait for SSE to indicate completion (session.status: idle or error)
|
|
@@ -863,7 +883,7 @@ export async function handleOpenCodeAnswer(
|
|
|
863
883
|
// Timeout - assume complete
|
|
864
884
|
await onEvent({ type: 'done', sessionId })
|
|
865
885
|
} catch (error) {
|
|
866
|
-
|
|
886
|
+
logger.error('Answer question failed', { err: error })
|
|
867
887
|
await onEvent({
|
|
868
888
|
type: 'error',
|
|
869
889
|
error: error instanceof Error ? error.message : 'Failed to answer question',
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* BEFORE invoking this helper so the event is emitted exactly once per
|
|
19
19
|
* cancellation.
|
|
20
20
|
*/
|
|
21
|
+
import { createLogger } from '@open-mercato/shared/lib/logger'
|
|
21
22
|
import { AiPendingActionRepository } from '../data/repositories/AiPendingActionRepository'
|
|
22
23
|
import type { AiPendingAction } from '../data/entities'
|
|
23
24
|
import { emitAiAssistantEvent } from '../events'
|
|
@@ -28,6 +29,8 @@ import type {
|
|
|
28
29
|
} from '../events'
|
|
29
30
|
import type { AiPendingActionExecutionResult } from './pending-action-types'
|
|
30
31
|
|
|
32
|
+
const logger = createLogger('ai_assistant')
|
|
33
|
+
|
|
31
34
|
export interface PendingActionCancelContext {
|
|
32
35
|
tenantId: string
|
|
33
36
|
organizationId: string | null
|
|
@@ -78,7 +81,7 @@ async function emitEventSafe(
|
|
|
78
81
|
try {
|
|
79
82
|
await emitter(eventId, payload)
|
|
80
83
|
} catch (error) {
|
|
81
|
-
|
|
84
|
+
logger.warn('Failed to emit pending-action event', { eventId, err: error })
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
87
|
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* The handler's own transaction boundary (typically a command) is the
|
|
19
19
|
* unit of atomicity for the underlying data change.
|
|
20
20
|
*/
|
|
21
|
+
import { createLogger } from '@open-mercato/shared/lib/logger'
|
|
21
22
|
import { AiPendingActionRepository } from '../data/repositories/AiPendingActionRepository'
|
|
22
23
|
import type { AiPendingAction } from '../data/entities'
|
|
23
24
|
import { emitAiAssistantEvent } from '../events'
|
|
@@ -29,6 +30,8 @@ import type {
|
|
|
29
30
|
AiPendingActionFailedRecord,
|
|
30
31
|
} from './pending-action-types'
|
|
31
32
|
|
|
33
|
+
const logger = createLogger('ai_assistant')
|
|
34
|
+
|
|
32
35
|
export interface PendingActionExecuteContext {
|
|
33
36
|
tenantId: string
|
|
34
37
|
organizationId: string | null
|
|
@@ -95,7 +98,7 @@ async function emitConfirmed(
|
|
|
95
98
|
try {
|
|
96
99
|
await emitter(CONFIRMED_EVENT_ID, payload)
|
|
97
100
|
} catch (error) {
|
|
98
|
-
|
|
101
|
+
logger.warn('Failed to emit pending-action event', { eventId: CONFIRMED_EVENT_ID, err: error })
|
|
99
102
|
}
|
|
100
103
|
}
|
|
101
104
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createLogger } from '@open-mercato/shared/lib/logger'
|
|
1
2
|
import { createHash } from 'node:crypto'
|
|
2
3
|
import type { AwilixContainer } from 'awilix'
|
|
3
4
|
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
@@ -18,6 +19,8 @@ import type {
|
|
|
18
19
|
AiPendingActionRecordDiff,
|
|
19
20
|
} from './pending-action-types'
|
|
20
21
|
|
|
22
|
+
const logger = createLogger('ai_assistant')
|
|
23
|
+
|
|
21
24
|
/**
|
|
22
25
|
* Structured error raised by {@link prepareMutation}. Callers (today the
|
|
23
26
|
* agent-runtime tool wrapper installed by `resolveAiAgentTools`) turn this
|
|
@@ -263,9 +266,7 @@ async function buildSingleRecordDiff(
|
|
|
263
266
|
}> {
|
|
264
267
|
const resolver = tool.loadBeforeRecord
|
|
265
268
|
if (!resolver) {
|
|
266
|
-
|
|
267
|
-
`[AI Agents] prepareMutation: tool "${tool.name}" declared isMutation=true but no loadBeforeRecord resolver; shipping empty fieldDiff.`,
|
|
268
|
-
)
|
|
269
|
+
logger.warn('prepareMutation: tool declared isMutation=true but no loadBeforeRecord resolver; shipping empty fieldDiff', { toolName: tool.name })
|
|
269
270
|
return {
|
|
270
271
|
fieldDiff: [],
|
|
271
272
|
targetEntityType: null,
|
|
@@ -310,9 +311,7 @@ async function buildBatchRecords(
|
|
|
310
311
|
}> {
|
|
311
312
|
const resolver = tool.loadBeforeRecords
|
|
312
313
|
if (!resolver) {
|
|
313
|
-
|
|
314
|
-
`[AI Agents] prepareMutation: bulk tool "${tool.name}" declared isMutation=true but no loadBeforeRecords resolver; shipping empty records[].`,
|
|
315
|
-
)
|
|
314
|
+
logger.warn('prepareMutation: bulk tool declared isMutation=true but no loadBeforeRecords resolver; shipping empty records[]', { toolName: tool.name })
|
|
316
315
|
return {
|
|
317
316
|
records: null,
|
|
318
317
|
targetEntityType: null,
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { createLogger } from '@open-mercato/shared/lib/logger'
|
|
1
2
|
import { z, type ZodType } from 'zod'
|
|
2
3
|
|
|
4
|
+
const logger = createLogger('ai_assistant')
|
|
5
|
+
|
|
3
6
|
/**
|
|
4
7
|
* Cache for converted safe schemas to avoid repeated conversions per request.
|
|
5
8
|
*/
|
|
@@ -169,7 +172,7 @@ export function toSafeZodSchema(schema: ZodType): ZodType {
|
|
|
169
172
|
|
|
170
173
|
return safeSchema
|
|
171
174
|
} catch (error) {
|
|
172
|
-
|
|
175
|
+
logger.error('Schema Utils — Error converting schema', { err: error })
|
|
173
176
|
// Fallback to the original schema if conversion fails
|
|
174
177
|
return schema
|
|
175
178
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { createLogger } from '@open-mercato/shared/lib/logger'
|
|
1
2
|
import type { AwilixContainer } from 'awilix'
|
|
2
3
|
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
3
4
|
import type { AiChatRequestContext } from './attachment-bridge-types'
|
|
4
5
|
import { AiTokenUsageRepository } from '../data/repositories/AiTokenUsageRepository'
|
|
5
6
|
import { emitAiAssistantEvent } from '../events'
|
|
6
7
|
|
|
8
|
+
const logger = createLogger('ai_assistant')
|
|
9
|
+
|
|
7
10
|
export interface RecordTokenUsageInput {
|
|
8
11
|
authContext: AiChatRequestContext
|
|
9
12
|
agentId: string
|
|
@@ -89,10 +92,7 @@ export async function recordTokenUsage(
|
|
|
89
92
|
reasoningTokens,
|
|
90
93
|
})
|
|
91
94
|
} catch (error) {
|
|
92
|
-
|
|
93
|
-
'[AI token-usage] recordTokenUsage failed (turn continues unaffected):',
|
|
94
|
-
error instanceof Error ? error.message : error,
|
|
95
|
-
)
|
|
95
|
+
logger.warn('recordTokenUsage failed (turn continues unaffected)', { err: error })
|
|
96
96
|
return
|
|
97
97
|
}
|
|
98
98
|
|
|
@@ -114,9 +114,6 @@ export async function recordTokenUsage(
|
|
|
114
114
|
{ persistent: false },
|
|
115
115
|
)
|
|
116
116
|
} catch (emitError) {
|
|
117
|
-
|
|
118
|
-
'[AI token-usage] Event emit failed (non-fatal):',
|
|
119
|
-
emitError instanceof Error ? emitError.message : emitError,
|
|
120
|
-
)
|
|
117
|
+
logger.warn('Token-usage event emit failed (non-fatal)', { err: emitError })
|
|
121
118
|
}
|
|
122
119
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { createLogger } from '@open-mercato/shared/lib/logger'
|
|
1
2
|
import type { McpToolContext, ToolExecutionResult } from './types'
|
|
2
3
|
import { getToolRegistry } from './tool-registry'
|
|
3
4
|
import { hasRequiredFeatures } from './auth'
|
|
4
5
|
import type { RbacService } from '@open-mercato/core/modules/auth/services/rbacService'
|
|
5
6
|
|
|
7
|
+
const logger = createLogger('ai_assistant')
|
|
8
|
+
|
|
6
9
|
/**
|
|
7
10
|
* Strip empty strings from object values so LLM-generated `""` for optional
|
|
8
11
|
* fields becomes `undefined` (passes `.optional()` Zod validators).
|
|
@@ -86,7 +89,7 @@ export async function executeTool(
|
|
|
86
89
|
return { success: true, result }
|
|
87
90
|
} catch (error) {
|
|
88
91
|
const message = error instanceof Error ? error.message : String(error)
|
|
89
|
-
|
|
92
|
+
logger.error('Error executing tool', { toolName, err: error })
|
|
90
93
|
return {
|
|
91
94
|
success: false,
|
|
92
95
|
error: message,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createLogger } from '@open-mercato/shared/lib/logger'
|
|
1
2
|
import { z } from 'zod'
|
|
2
3
|
import type { SearchService } from '@open-mercato/search/service'
|
|
3
4
|
import { registerMcpTool, getToolRegistry, toolRegistry, unregisterMcpTool } from './tool-registry'
|
|
@@ -14,6 +15,8 @@ import {
|
|
|
14
15
|
ensureApiRouteManifestsRegistered,
|
|
15
16
|
} from './generated-registry-loader'
|
|
16
17
|
|
|
18
|
+
const logger = createLogger('ai_assistant').child({ component: 'tools' })
|
|
19
|
+
|
|
17
20
|
/**
|
|
18
21
|
* Module tool definition as exported from ai-tools.ts files.
|
|
19
22
|
*/
|
|
@@ -102,9 +105,7 @@ export function registerGeneratedAiToolEntries(entries: AiToolConfigEntry[]): nu
|
|
|
102
105
|
if (!Array.isArray(entry.tools) || entry.tools.length === 0) continue
|
|
103
106
|
for (const candidate of entry.tools) {
|
|
104
107
|
if (!isModuleAiTool(candidate)) {
|
|
105
|
-
|
|
106
|
-
`[MCP Tools] Skipping malformed AI tool in module "${entry.moduleId}"`
|
|
107
|
-
)
|
|
108
|
+
logger.warn('Skipping malformed AI tool', { moduleId: entry.moduleId })
|
|
108
109
|
continue
|
|
109
110
|
}
|
|
110
111
|
// Register the full typed tool — see comment on `loadModuleTools`.
|
|
@@ -137,14 +138,14 @@ export function applyAiToolOverrideEntries(
|
|
|
137
138
|
for (const [name, value] of Object.entries(overrideMap)) {
|
|
138
139
|
if (value === null) {
|
|
139
140
|
unregisterMcpTool(name)
|
|
140
|
-
|
|
141
|
+
logger.info('Tool disabled by override', { toolName: name })
|
|
141
142
|
continue
|
|
142
143
|
}
|
|
143
144
|
const next = overridden.get(name)
|
|
144
145
|
if (!next) continue
|
|
145
146
|
// Re-register through the public path so moduleMap stays consistent.
|
|
146
147
|
registerMcpTool(next as McpToolDefinition, { moduleId: 'ai_overrides' })
|
|
147
|
-
|
|
148
|
+
logger.info('Tool replaced by override', { toolName: name })
|
|
148
149
|
}
|
|
149
150
|
}
|
|
150
151
|
|
|
@@ -221,14 +222,11 @@ export async function loadGeneratedModuleAiTools(): Promise<number> {
|
|
|
221
222
|
try {
|
|
222
223
|
await loadGeneratedAiToolOverrides()
|
|
223
224
|
} catch (error) {
|
|
224
|
-
|
|
225
|
+
logger.error('Failed to apply tool overrides', { err: error })
|
|
225
226
|
}
|
|
226
227
|
return count
|
|
227
228
|
} catch (error) {
|
|
228
|
-
|
|
229
|
-
'[MCP Tools] Could not load ai-tools.generated.ts (module tools unavailable):',
|
|
230
|
-
error
|
|
231
|
-
)
|
|
229
|
+
logger.error('Could not load ai-tools.generated.ts (module tools unavailable)', { err: error })
|
|
232
230
|
return 0
|
|
233
231
|
}
|
|
234
232
|
}
|
|
@@ -240,7 +238,7 @@ export async function loadGeneratedModuleAiTools(): Promise<number> {
|
|
|
240
238
|
export async function loadAllModuleTools(): Promise<void> {
|
|
241
239
|
// 1. Register built-in tools
|
|
242
240
|
registerMcpTool(contextWhoamiTool, { moduleId: 'context' })
|
|
243
|
-
|
|
241
|
+
logger.debug('Registered built-in context_whoami tool')
|
|
244
242
|
|
|
245
243
|
// 2. Register Code Mode tools (search + execute)
|
|
246
244
|
// These two tools replace the previous api_discover, call_api, discover_schema,
|
|
@@ -249,9 +247,9 @@ export async function loadAllModuleTools(): Promise<void> {
|
|
|
249
247
|
try {
|
|
250
248
|
const { loadCodeModeTools } = await import('./codemode-tools')
|
|
251
249
|
const toolCount = await loadCodeModeTools()
|
|
252
|
-
|
|
250
|
+
logger.info('Registered Code Mode tools', { toolCount })
|
|
253
251
|
} catch (error) {
|
|
254
|
-
|
|
252
|
+
logger.error('Could not load Code Mode tools', { err: error })
|
|
255
253
|
}
|
|
256
254
|
|
|
257
255
|
// 3. Register module-contributed tools from ai-tools.generated.ts.
|
|
@@ -259,11 +257,9 @@ export async function loadAllModuleTools(): Promise<void> {
|
|
|
259
257
|
// generated file is not fatal (pre-generate builds, tests).
|
|
260
258
|
try {
|
|
261
259
|
const moduleToolCount = await loadGeneratedModuleAiTools()
|
|
262
|
-
|
|
263
|
-
`[MCP Tools] Registered ${moduleToolCount} module-contributed AI tools from ai-tools.generated.ts`
|
|
264
|
-
)
|
|
260
|
+
logger.info('Registered module-contributed AI tools', { toolCount: moduleToolCount })
|
|
265
261
|
} catch (error) {
|
|
266
|
-
|
|
262
|
+
logger.error('Could not load module AI tools', { err: error })
|
|
267
263
|
}
|
|
268
264
|
|
|
269
265
|
// 4. Register the API route manifest so API-backed module tools can run.
|
|
@@ -272,12 +268,10 @@ export async function loadAllModuleTools(): Promise<void> {
|
|
|
272
268
|
try {
|
|
273
269
|
const routeCount = await ensureApiRouteManifestsRegistered()
|
|
274
270
|
if (routeCount > 0) {
|
|
275
|
-
|
|
276
|
-
`[MCP Tools] Registered ${routeCount} API route manifests for API-backed tools`
|
|
277
|
-
)
|
|
271
|
+
logger.info('Registered API route manifests for API-backed tools', { routeCount })
|
|
278
272
|
}
|
|
279
273
|
} catch (error) {
|
|
280
|
-
|
|
274
|
+
logger.error('Could not register API route manifests', { err: error })
|
|
281
275
|
}
|
|
282
276
|
}
|
|
283
277
|
|
|
@@ -304,16 +298,16 @@ export async function indexToolsForSearch(
|
|
|
304
298
|
try {
|
|
305
299
|
const result = await toolSearchService.indexTools(force)
|
|
306
300
|
|
|
307
|
-
|
|
308
|
-
|
|
301
|
+
logger.info('Indexed tools for search', { indexed: result.indexed })
|
|
302
|
+
logger.debug('Search strategies available', { strategies: result.strategies.join(',') })
|
|
309
303
|
|
|
310
304
|
if (result.skipped > 0) {
|
|
311
|
-
|
|
305
|
+
logger.debug('Skipped unchanged tools', { skipped: result.skipped })
|
|
312
306
|
}
|
|
313
307
|
|
|
314
308
|
return result
|
|
315
309
|
} catch (error) {
|
|
316
|
-
|
|
310
|
+
logger.error('Failed to index tools for search', { err: error })
|
|
317
311
|
throw error
|
|
318
312
|
}
|
|
319
313
|
}
|