@open-mercato/ai-assistant 0.10.1-develop.8278.1.f7f8e5ab1a → 0.10.1-develop.8287.1.7313a0fe67
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/.turbo/turbo-build.log +1 -1
- package/AGENTS.md +32 -44
- package/dist/index.js +59 -1
- package/dist/index.js.map +2 -2
- package/dist/modules/ai_assistant/__integration__/TC-AI-CITATIONS-020-citations.spec.js +257 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-CITATIONS-020-citations.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-AGENT-TOOL-012-agent-tools.spec.js +86 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-AGENT-TOOL-012-agent-tools.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-APPROVAL-015-approval-flow.spec.js +138 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-APPROVAL-015-approval-flow.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-APPROVAL-016-execute-refuses-mutation.spec.js +49 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-APPROVAL-016-execute-refuses-mutation.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-APPROVAL-017-visibility-and-revocation.spec.js +195 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-APPROVAL-017-visibility-and-revocation.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-AUDIT-014-tool-call-audit.spec.js +51 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-AUDIT-014-tool-call-audit.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-AUDIT-015-auditor-actor-scope.spec.js +51 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-AUDIT-015-auditor-actor-scope.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-AUDIT-016-auditor-org-and-tenant-isolation.spec.js +142 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-AUDIT-016-auditor-org-and-tenant-isolation.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-EXPOSURE-010-tools-list-acl.spec.js +86 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-EXPOSURE-010-tools-list-acl.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-MUTATION-013-deny-mode.spec.js +37 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-MUTATION-013-deny-mode.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-PARITY-011-agent-mcp-parity.spec.js +141 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-PARITY-011-agent-mcp-parity.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-RATE-LIMIT-018-agent-tool-rate-limit.spec.js +82 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-MCP-RATE-LIMIT-018-agent-tool-rate-limit.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-RUN-TRACE-015-conversation-runs.spec.js +191 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-RUN-TRACE-015-conversation-runs.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-RUN-TRACE-016-run-object-run-id.spec.js +136 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-RUN-TRACE-016-run-object-run-id.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-RUN-TRACE-017-run-access.spec.js +183 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-RUN-TRACE-017-run-access.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-RUN-TRACE-018-metadata-capture.spec.js +110 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-RUN-TRACE-018-metadata-capture.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-RUN-TRACE-020-run-list-filter-scope.spec.js +140 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-RUN-TRACE-020-run-list-filter-scope.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-RUN-UI-019-runs-pages.spec.js +141 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-RUN-UI-019-runs-pages.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/helpers/agentRunChat.js +58 -0
- package/dist/modules/ai_assistant/__integration__/helpers/agentRunChat.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/helpers/aiAssistantFixtures.js +135 -3
- package/dist/modules/ai_assistant/__integration__/helpers/aiAssistantFixtures.js.map +2 -2
- package/dist/modules/ai_assistant/__integration__/helpers/mcpFixtures.js +136 -0
- package/dist/modules/ai_assistant/__integration__/helpers/mcpFixtures.js.map +7 -0
- package/dist/modules/ai_assistant/acl.js +18 -0
- package/dist/modules/ai_assistant/acl.js.map +2 -2
- package/dist/modules/ai_assistant/ai-tools/meta-pack.js +45 -1
- package/dist/modules/ai_assistant/ai-tools/meta-pack.js.map +2 -2
- package/dist/modules/ai_assistant/ai-tools/search-pack.js +36 -3
- package/dist/modules/ai_assistant/ai-tools/search-pack.js.map +2 -2
- package/dist/modules/ai_assistant/api/ai/actions/[id]/cancel/route.js +20 -5
- 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 +36 -16
- 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 +17 -9
- package/dist/modules/ai_assistant/api/ai/actions/[id]/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/ai/actions/route.js +110 -0
- package/dist/modules/ai_assistant/api/ai/actions/route.js.map +7 -0
- package/dist/modules/ai_assistant/api/ai/chat/route.js +15 -2
- package/dist/modules/ai_assistant/api/ai/chat/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/ai/conversations/[conversationId]/runs/route.js +93 -0
- package/dist/modules/ai_assistant/api/ai/conversations/[conversationId]/runs/route.js.map +7 -0
- package/dist/modules/ai_assistant/api/ai/run-object/route.js +130 -9
- package/dist/modules/ai_assistant/api/ai/run-object/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/ai/runs/[id]/route.js +89 -0
- package/dist/modules/ai_assistant/api/ai/runs/[id]/route.js.map +7 -0
- package/dist/modules/ai_assistant/api/ai/runs/route.js +66 -0
- package/dist/modules/ai_assistant/api/ai/runs/route.js.map +7 -0
- package/dist/modules/ai_assistant/api/tools/execute/route.js +108 -4
- package/dist/modules/ai_assistant/api/tools/execute/route.js.map +2 -2
- package/dist/modules/ai_assistant/api/tools/route.js +85 -10
- package/dist/modules/ai_assistant/api/tools/route.js.map +2 -2
- package/dist/modules/ai_assistant/backend/config/ai-assistant/pending-actions/PendingActionsPageClient.js +218 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/pending-actions/PendingActionsPageClient.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/pending-actions/[id]/PendingActionDetailPageClient.js +326 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/pending-actions/[id]/PendingActionDetailPageClient.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/pending-actions/[id]/page.js +10 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/pending-actions/[id]/page.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/pending-actions/[id]/page.meta.js +22 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/pending-actions/[id]/page.meta.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/pending-actions/page.js +10 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/pending-actions/page.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/pending-actions/page.meta.js +25 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/pending-actions/page.meta.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/runs/AiRunsListPageClient.js +251 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/runs/AiRunsListPageClient.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/runs/[id]/AiRunDetailPageClient.js +260 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/runs/[id]/AiRunDetailPageClient.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/runs/[id]/page.js +10 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/runs/[id]/page.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/runs/[id]/page.meta.js +22 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/runs/[id]/page.meta.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/runs/page.js +10 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/runs/page.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/runs/page.meta.js +24 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/runs/page.meta.js.map +7 -0
- package/dist/modules/ai_assistant/cli.js +134 -6
- package/dist/modules/ai_assistant/cli.js.map +2 -2
- package/dist/modules/ai_assistant/components/AiAssistantSettingsPageClient.js +2 -0
- package/dist/modules/ai_assistant/components/AiAssistantSettingsPageClient.js.map +2 -2
- package/dist/modules/ai_assistant/components/McpExposureSection.js +136 -0
- package/dist/modules/ai_assistant/components/McpExposureSection.js.map +7 -0
- package/dist/modules/ai_assistant/components/agent-runs/agentRunsShared.js +84 -0
- package/dist/modules/ai_assistant/components/agent-runs/agentRunsShared.js.map +7 -0
- package/dist/modules/ai_assistant/components/pending-actions/RequesterLabel.js +23 -0
- package/dist/modules/ai_assistant/components/pending-actions/RequesterLabel.js.map +7 -0
- package/dist/modules/ai_assistant/components/pending-actions/pendingActionsNavBadge.js +37 -0
- package/dist/modules/ai_assistant/components/pending-actions/pendingActionsNavBadge.js.map +7 -0
- package/dist/modules/ai_assistant/components/pending-actions/pendingActionsShared.js +100 -0
- package/dist/modules/ai_assistant/components/pending-actions/pendingActionsShared.js.map +7 -0
- package/dist/modules/ai_assistant/components/pending-actions/useRequesterLabels.js +44 -0
- package/dist/modules/ai_assistant/components/pending-actions/useRequesterLabels.js.map +7 -0
- package/dist/modules/ai_assistant/data/entities.js +324 -1
- package/dist/modules/ai_assistant/data/entities.js.map +2 -2
- package/dist/modules/ai_assistant/data/repositories/AiChatConversationRepository.js +16 -1
- package/dist/modules/ai_assistant/data/repositories/AiChatConversationRepository.js.map +2 -2
- package/dist/modules/ai_assistant/data/repositories/AiPendingActionRepository.js +67 -2
- package/dist/modules/ai_assistant/data/repositories/AiPendingActionRepository.js.map +2 -2
- package/dist/modules/ai_assistant/data/validators.js +67 -1
- package/dist/modules/ai_assistant/data/validators.js.map +2 -2
- package/dist/modules/ai_assistant/di.js +5 -1
- package/dist/modules/ai_assistant/di.js.map +2 -2
- package/dist/modules/ai_assistant/encryption.js +24 -0
- package/dist/modules/ai_assistant/encryption.js.map +2 -2
- package/dist/modules/ai_assistant/events.js +7 -0
- package/dist/modules/ai_assistant/events.js.map +2 -2
- package/dist/modules/ai_assistant/i18n/de.json +177 -1
- package/dist/modules/ai_assistant/i18n/en.json +177 -1
- package/dist/modules/ai_assistant/i18n/es.json +177 -1
- package/dist/modules/ai_assistant/i18n/ko.json +177 -1
- package/dist/modules/ai_assistant/i18n/pl.json +177 -1
- package/dist/modules/ai_assistant/lib/agent-call-contract.js +78 -0
- package/dist/modules/ai_assistant/lib/agent-call-contract.js.map +7 -0
- package/dist/modules/ai_assistant/lib/agent-call-observer.js +360 -0
- package/dist/modules/ai_assistant/lib/agent-call-observer.js.map +7 -0
- package/dist/modules/ai_assistant/lib/agent-channel-policy.js +28 -0
- package/dist/modules/ai_assistant/lib/agent-channel-policy.js.map +7 -0
- package/dist/modules/ai_assistant/lib/agent-definition-hash.js +69 -0
- package/dist/modules/ai_assistant/lib/agent-definition-hash.js.map +7 -0
- package/dist/modules/ai_assistant/lib/agent-registry.js +70 -6
- package/dist/modules/ai_assistant/lib/agent-registry.js.map +2 -2
- package/dist/modules/ai_assistant/lib/agent-run-access.js +275 -0
- package/dist/modules/ai_assistant/lib/agent-run-access.js.map +7 -0
- package/dist/modules/ai_assistant/lib/agent-run-capture.js +213 -0
- package/dist/modules/ai_assistant/lib/agent-run-capture.js.map +7 -0
- package/dist/modules/ai_assistant/lib/agent-run-dispatcher.js +44 -0
- package/dist/modules/ai_assistant/lib/agent-run-dispatcher.js.map +7 -0
- package/dist/modules/ai_assistant/lib/agent-run-reader.js +66 -0
- package/dist/modules/ai_assistant/lib/agent-run-reader.js.map +7 -0
- package/dist/modules/ai_assistant/lib/agent-run-recorder.js +287 -0
- package/dist/modules/ai_assistant/lib/agent-run-recorder.js.map +7 -0
- package/dist/modules/ai_assistant/lib/agent-runtime.js +670 -218
- package/dist/modules/ai_assistant/lib/agent-runtime.js.map +3 -3
- package/dist/modules/ai_assistant/lib/agent-tool-error.js +19 -0
- package/dist/modules/ai_assistant/lib/agent-tool-error.js.map +7 -0
- package/dist/modules/ai_assistant/lib/agent-tool-rate-limit.js +45 -0
- package/dist/modules/ai_assistant/lib/agent-tool-rate-limit.js.map +7 -0
- package/dist/modules/ai_assistant/lib/agent-tool.js +227 -0
- package/dist/modules/ai_assistant/lib/agent-tool.js.map +7 -0
- package/dist/modules/ai_assistant/lib/agent-tools.js +134 -69
- package/dist/modules/ai_assistant/lib/agent-tools.js.map +2 -2
- package/dist/modules/ai_assistant/lib/ai-agent-definition.js.map +2 -2
- package/dist/modules/ai_assistant/lib/auth.js +2 -0
- package/dist/modules/ai_assistant/lib/auth.js.map +2 -2
- package/dist/modules/ai_assistant/lib/citations.js +129 -0
- package/dist/modules/ai_assistant/lib/citations.js.map +7 -0
- package/dist/modules/ai_assistant/lib/codemode-tools.js +1 -0
- package/dist/modules/ai_assistant/lib/codemode-tools.js.map +2 -2
- package/dist/modules/ai_assistant/lib/http-server.js +355 -140
- package/dist/modules/ai_assistant/lib/http-server.js.map +2 -2
- package/dist/modules/ai_assistant/lib/llm-adapters/tool-replay-context.js +156 -0
- package/dist/modules/ai_assistant/lib/llm-adapters/tool-replay-context.js.map +7 -0
- package/dist/modules/ai_assistant/lib/loop-step-extraction.js +141 -0
- package/dist/modules/ai_assistant/lib/loop-step-extraction.js.map +7 -0
- package/dist/modules/ai_assistant/lib/mcp-agent-tool-results.js +121 -0
- package/dist/modules/ai_assistant/lib/mcp-agent-tool-results.js.map +7 -0
- package/dist/modules/ai_assistant/lib/mcp-audit.js +155 -0
- package/dist/modules/ai_assistant/lib/mcp-audit.js.map +7 -0
- package/dist/modules/ai_assistant/lib/mcp-dev-server.js +151 -30
- package/dist/modules/ai_assistant/lib/mcp-dev-server.js.map +2 -2
- package/dist/modules/ai_assistant/lib/mcp-exposure.js +141 -0
- package/dist/modules/ai_assistant/lib/mcp-exposure.js.map +7 -0
- package/dist/modules/ai_assistant/lib/mcp-sdk-refusal-audit.js +77 -0
- package/dist/modules/ai_assistant/lib/mcp-sdk-refusal-audit.js.map +7 -0
- package/dist/modules/ai_assistant/lib/mcp-server.js +140 -31
- package/dist/modules/ai_assistant/lib/mcp-server.js.map +2 -2
- package/dist/modules/ai_assistant/lib/mcp-tool-execution-observer.js +54 -0
- package/dist/modules/ai_assistant/lib/mcp-tool-execution-observer.js.map +7 -0
- package/dist/modules/ai_assistant/lib/model-factory-context.js +23 -0
- package/dist/modules/ai_assistant/lib/model-factory-context.js.map +7 -0
- package/dist/modules/ai_assistant/lib/model-factory.js +11 -1
- package/dist/modules/ai_assistant/lib/model-factory.js.map +2 -2
- package/dist/modules/ai_assistant/lib/pending-action-cancel.js +13 -0
- package/dist/modules/ai_assistant/lib/pending-action-cancel.js.map +2 -2
- package/dist/modules/ai_assistant/lib/pending-action-client.js +12 -1
- package/dist/modules/ai_assistant/lib/pending-action-client.js.map +2 -2
- package/dist/modules/ai_assistant/lib/pending-action-executor.js +26 -6
- package/dist/modules/ai_assistant/lib/pending-action-executor.js.map +2 -2
- package/dist/modules/ai_assistant/lib/pending-action-notify.js +131 -0
- package/dist/modules/ai_assistant/lib/pending-action-notify.js.map +7 -0
- package/dist/modules/ai_assistant/lib/pending-action-recheck.js +112 -2
- package/dist/modules/ai_assistant/lib/pending-action-recheck.js.map +2 -2
- package/dist/modules/ai_assistant/lib/pending-action-types.js +25 -1
- package/dist/modules/ai_assistant/lib/pending-action-types.js.map +2 -2
- package/dist/modules/ai_assistant/lib/prepare-mutation.js +153 -38
- package/dist/modules/ai_assistant/lib/prepare-mutation.js.map +2 -2
- package/dist/modules/ai_assistant/lib/report-ai-assistant-error.js +16 -0
- package/dist/modules/ai_assistant/lib/report-ai-assistant-error.js.map +7 -0
- package/dist/modules/ai_assistant/lib/task-plan-stream.js +10 -0
- package/dist/modules/ai_assistant/lib/task-plan-stream.js.map +2 -2
- package/dist/modules/ai_assistant/lib/tool-executor.js +145 -2
- package/dist/modules/ai_assistant/lib/tool-executor.js.map +2 -2
- package/dist/modules/ai_assistant/lib/tool-loader.js +74 -0
- package/dist/modules/ai_assistant/lib/tool-loader.js.map +2 -2
- package/dist/modules/ai_assistant/lib/tool-ui-parts.js +38 -0
- package/dist/modules/ai_assistant/lib/tool-ui-parts.js.map +7 -0
- package/dist/modules/ai_assistant/lib/truncate.js +36 -1
- package/dist/modules/ai_assistant/lib/truncate.js.map +2 -2
- package/dist/modules/ai_assistant/migrations/Migration20261022130536_ai_assistant.js +15 -0
- package/dist/modules/ai_assistant/migrations/Migration20261022130536_ai_assistant.js.map +7 -0
- package/dist/modules/ai_assistant/migrations/Migration20261026192929_ai_assistant.js +40 -0
- package/dist/modules/ai_assistant/migrations/Migration20261026192929_ai_assistant.js.map +7 -0
- package/dist/modules/ai_assistant/notifications.client.js +21 -0
- package/dist/modules/ai_assistant/notifications.client.js.map +2 -2
- package/dist/modules/ai_assistant/notifications.js +20 -0
- package/dist/modules/ai_assistant/notifications.js.map +2 -2
- package/dist/modules/ai_assistant/setup.js +37 -2
- package/dist/modules/ai_assistant/setup.js.map +2 -2
- package/dist/modules/ai_assistant/widgets/injection/pending-actions-nav-badge/widget.client.js +31 -0
- package/dist/modules/ai_assistant/widgets/injection/pending-actions-nav-badge/widget.client.js.map +7 -0
- package/dist/modules/ai_assistant/widgets/injection/pending-actions-nav-badge/widget.js +17 -0
- package/dist/modules/ai_assistant/widgets/injection/pending-actions-nav-badge/widget.js.map +7 -0
- package/dist/modules/ai_assistant/widgets/injection-table.js +14 -0
- package/dist/modules/ai_assistant/widgets/injection-table.js.map +7 -0
- package/dist/modules/ai_assistant/widgets/notifications/PendingActionAwaitingApprovalRenderer.js +127 -0
- package/dist/modules/ai_assistant/widgets/notifications/PendingActionAwaitingApprovalRenderer.js.map +7 -0
- package/dist/modules/ai_assistant/workers/ai-agent-run-prune.js +72 -0
- package/dist/modules/ai_assistant/workers/ai-agent-run-prune.js.map +7 -0
- package/dist/modules/ai_assistant/workers/ai-pending-action-cleanup.js +17 -1
- package/dist/modules/ai_assistant/workers/ai-pending-action-cleanup.js.map +2 -2
- package/generated/entities/ai_agent_run/index.ts +46 -0
- package/generated/entities/ai_agent_run_step/index.ts +15 -0
- package/generated/entities/ai_agent_run_tool_call/index.ts +21 -0
- package/generated/entities/ai_pending_action/index.ts +3 -0
- package/generated/entities.ids.generated.ts +4 -1
- package/generated/entity-fields-registry.ts +92 -1
- package/jest.config.cjs +1 -0
- package/package.json +6 -6
- package/src/index.ts +75 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-CITATIONS-020-citations.spec.ts +289 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-MCP-AGENT-TOOL-012-agent-tools.spec.ts +135 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-MCP-APPROVAL-015-approval-flow.spec.ts +183 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-MCP-APPROVAL-016-execute-refuses-mutation.spec.ts +71 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-MCP-APPROVAL-017-visibility-and-revocation.spec.ts +258 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-MCP-AUDIT-014-tool-call-audit.spec.ts +77 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-MCP-AUDIT-015-auditor-actor-scope.spec.ts +83 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-MCP-AUDIT-016-auditor-org-and-tenant-isolation.spec.ts +184 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-MCP-EXPOSURE-010-tools-list-acl.spec.ts +121 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-MCP-MUTATION-013-deny-mode.spec.ts +63 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-MCP-PARITY-011-agent-mcp-parity.spec.ts +203 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-MCP-RATE-LIMIT-018-agent-tool-rate-limit.spec.ts +125 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-RUN-TRACE-015-conversation-runs.spec.ts +214 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-RUN-TRACE-016-run-object-run-id.spec.ts +163 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-RUN-TRACE-017-run-access.spec.ts +205 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-RUN-TRACE-018-metadata-capture.spec.ts +127 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-RUN-TRACE-020-run-list-filter-scope.spec.ts +157 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-RUN-UI-019-runs-pages.spec.ts +164 -0
- package/src/modules/ai_assistant/__integration__/helpers/agentRunChat.ts +115 -0
- package/src/modules/ai_assistant/__integration__/helpers/aiAssistantFixtures.ts +192 -2
- package/src/modules/ai_assistant/__integration__/helpers/mcpFixtures.ts +180 -0
- package/src/modules/ai_assistant/__tests__/cli-agent-run-prune.test.ts +15 -0
- package/src/modules/ai_assistant/__tests__/cli-mcp-exposure-flags.test.ts +265 -0
- package/src/modules/ai_assistant/__tests__/encryption-map.test.ts +22 -0
- package/src/modules/ai_assistant/__tests__/setup-schedules.test.ts +13 -3
- package/src/modules/ai_assistant/acl.ts +18 -0
- package/src/modules/ai_assistant/ai-tools/__tests__/get-pending-action.test.ts +177 -0
- package/src/modules/ai_assistant/ai-tools/__tests__/meta-pack.test.ts +6 -1
- package/src/modules/ai_assistant/ai-tools/__tests__/search-pack.test.ts +108 -0
- package/src/modules/ai_assistant/ai-tools/meta-pack.ts +48 -0
- package/src/modules/ai_assistant/ai-tools/search-pack.ts +46 -1
- package/src/modules/ai_assistant/api/ai/actions/[id]/__tests__/route.test.ts +103 -6
- package/src/modules/ai_assistant/api/ai/actions/[id]/cancel/__tests__/route.test.ts +69 -6
- package/src/modules/ai_assistant/api/ai/actions/[id]/cancel/route.ts +20 -5
- package/src/modules/ai_assistant/api/ai/actions/[id]/confirm/__tests__/route.test.ts +125 -6
- package/src/modules/ai_assistant/api/ai/actions/[id]/confirm/route.ts +38 -17
- package/src/modules/ai_assistant/api/ai/actions/[id]/route.ts +18 -9
- package/src/modules/ai_assistant/api/ai/actions/__tests__/route.test.ts +247 -0
- package/src/modules/ai_assistant/api/ai/actions/route.ts +145 -0
- package/src/modules/ai_assistant/api/ai/chat/__tests__/route.test.ts +44 -1
- package/src/modules/ai_assistant/api/ai/chat/route.ts +16 -0
- package/src/modules/ai_assistant/api/ai/conversations/[conversationId]/runs/route.ts +105 -0
- package/src/modules/ai_assistant/api/ai/run-object/__tests__/route.test.ts +431 -2
- package/src/modules/ai_assistant/api/ai/run-object/route.ts +160 -6
- package/src/modules/ai_assistant/api/ai/runs/[id]/route.ts +107 -0
- package/src/modules/ai_assistant/api/ai/runs/__tests__/route.test.ts +486 -0
- package/src/modules/ai_assistant/api/ai/runs/route.ts +74 -0
- package/src/modules/ai_assistant/api/tools/__tests__/route.test.ts +187 -0
- package/src/modules/ai_assistant/api/tools/execute/__tests__/route.approval-boundary.test.ts +169 -0
- package/src/modules/ai_assistant/api/tools/execute/__tests__/route.test.ts +247 -108
- package/src/modules/ai_assistant/api/tools/execute/route.ts +128 -4
- package/src/modules/ai_assistant/api/tools/route.ts +113 -13
- package/src/modules/ai_assistant/backend/config/ai-assistant/pending-actions/PendingActionsPageClient.tsx +257 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/pending-actions/[id]/PendingActionDetailPageClient.tsx +441 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/pending-actions/[id]/page.meta.ts +18 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/pending-actions/[id]/page.tsx +12 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/pending-actions/__tests__/PendingActionDetailPageClient.test.tsx +212 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/pending-actions/__tests__/PendingActionsPageClient.test.tsx +183 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/pending-actions/page.meta.ts +23 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/pending-actions/page.tsx +12 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/runs/AiRunsListPageClient.tsx +281 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/runs/[id]/AiRunDetailPageClient.tsx +406 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/runs/[id]/page.meta.ts +18 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/runs/[id]/page.tsx +12 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/runs/__tests__/AiRunDetailPageClient.test.tsx +230 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/runs/__tests__/AiRunsListPageClient.test.tsx +197 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/runs/page.meta.ts +22 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/runs/page.tsx +12 -0
- package/src/modules/ai_assistant/cli.ts +145 -3
- package/src/modules/ai_assistant/components/AiAssistantSettingsPageClient.tsx +3 -0
- package/src/modules/ai_assistant/components/McpExposureSection.tsx +198 -0
- package/src/modules/ai_assistant/components/__tests__/McpExposureSection.test.tsx +101 -0
- package/src/modules/ai_assistant/components/agent-runs/agentRunsShared.ts +116 -0
- package/src/modules/ai_assistant/components/pending-actions/RequesterLabel.tsx +45 -0
- package/src/modules/ai_assistant/components/pending-actions/pendingActionsNavBadge.ts +40 -0
- package/src/modules/ai_assistant/components/pending-actions/pendingActionsShared.ts +116 -0
- package/src/modules/ai_assistant/components/pending-actions/useRequesterLabels.ts +52 -0
- package/src/modules/ai_assistant/data/__tests__/run-validators.test.ts +63 -0
- package/src/modules/ai_assistant/data/entities.ts +340 -0
- package/src/modules/ai_assistant/data/repositories/AiChatConversationRepository.ts +17 -1
- package/src/modules/ai_assistant/data/repositories/AiPendingActionRepository.ts +128 -3
- package/src/modules/ai_assistant/data/repositories/__tests__/AiChatConversationRepository.test.ts +43 -0
- package/src/modules/ai_assistant/data/repositories/__tests__/AiPendingActionRepository.test.ts +286 -2
- package/src/modules/ai_assistant/data/validators.ts +101 -0
- package/src/modules/ai_assistant/di.ts +5 -0
- package/src/modules/ai_assistant/encryption.ts +24 -0
- package/src/modules/ai_assistant/events.ts +24 -0
- package/src/modules/ai_assistant/i18n/de.json +177 -1
- package/src/modules/ai_assistant/i18n/en.json +177 -1
- package/src/modules/ai_assistant/i18n/es.json +177 -1
- package/src/modules/ai_assistant/i18n/ko.json +177 -1
- package/src/modules/ai_assistant/i18n/pl.json +177 -1
- package/src/modules/ai_assistant/lib/__tests__/agent-call-contract.test.ts +180 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-call-observer.test.ts +367 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-channel-policy.test.ts +133 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-definition-hash.test.ts +191 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-registry.test.ts +98 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-run-capture.test.ts +166 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-run-completed-event.test.ts +143 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-run-dispatcher.test.ts +121 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-run-reader.test.ts +125 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-run-recorder.test.ts +504 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-runtime-object-channel.test.ts +195 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-runtime-object-steps.test.ts +72 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-runtime-object.test.ts +78 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-runtime.call-observer.test.ts +419 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-runtime.call-settings.test.ts +221 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-runtime.loop-trace.test.ts +237 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-runtime.prompt-resolved.test.ts +251 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-runtime.run-recording.test.ts +473 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-tool-decoupling.test.ts +163 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-tool.test.ts +380 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-tools.test.ts +297 -0
- package/src/modules/ai_assistant/lib/__tests__/ai-sdk-call-level-hooks.spike.test.ts +135 -0
- package/src/modules/ai_assistant/lib/__tests__/citations.test.ts +313 -0
- package/src/modules/ai_assistant/lib/__tests__/codemode-tool-annotations.test.ts +7 -0
- package/src/modules/ai_assistant/lib/__tests__/http-server.audit.test.ts +596 -0
- package/src/modules/ai_assistant/lib/__tests__/http-server.list-filter.test.ts +224 -0
- package/src/modules/ai_assistant/lib/__tests__/loop-step-extraction.test.ts +359 -0
- package/src/modules/ai_assistant/lib/__tests__/mcp-agent-tool-results.test.ts +248 -0
- package/src/modules/ai_assistant/lib/__tests__/mcp-audit.test.ts +231 -0
- package/src/modules/ai_assistant/lib/__tests__/mcp-dev-server.refusal-audit.test.ts +147 -0
- package/src/modules/ai_assistant/lib/__tests__/mcp-exposure.test.ts +357 -0
- package/src/modules/ai_assistant/lib/__tests__/mcp-sdk-refusal-audit.test.ts +104 -0
- package/src/modules/ai_assistant/lib/__tests__/mcp-servers.audit.test.ts +427 -0
- package/src/modules/ai_assistant/lib/__tests__/mcp-servers.exposure-filter.test.ts +164 -0
- package/src/modules/ai_assistant/lib/__tests__/mcp-tool-execution-observer.test.ts +83 -0
- package/src/modules/ai_assistant/lib/__tests__/model-factory-context.test.ts +40 -0
- package/src/modules/ai_assistant/lib/__tests__/pending-action-notify.test.ts +488 -0
- package/src/modules/ai_assistant/lib/__tests__/pending-action-recheck.channel.test.ts +402 -0
- package/src/modules/ai_assistant/lib/__tests__/prepare-mutation.test.ts +127 -1
- package/src/modules/ai_assistant/lib/__tests__/tool-executor.agent-tool-rate-limit.test.ts +198 -0
- package/src/modules/ai_assistant/lib/__tests__/tool-executor.agent-tool.test.ts +88 -0
- package/src/modules/ai_assistant/lib/__tests__/tool-executor.approval.test.ts +331 -0
- package/src/modules/ai_assistant/lib/__tests__/tool-executor.channel.test.ts +142 -0
- package/src/modules/ai_assistant/lib/__tests__/tool-loader-agent-tools.test.ts +243 -0
- package/src/modules/ai_assistant/lib/__tests__/tool-loader.test.ts +28 -0
- package/src/modules/ai_assistant/lib/__tests__/tool-replay-context.test.ts +543 -0
- package/src/modules/ai_assistant/lib/__tests__/truncate.test.ts +25 -1
- package/src/modules/ai_assistant/lib/agent-call-contract.ts +166 -0
- package/src/modules/ai_assistant/lib/agent-call-observer.ts +485 -0
- package/src/modules/ai_assistant/lib/agent-channel-policy.ts +70 -0
- package/src/modules/ai_assistant/lib/agent-definition-hash.ts +80 -0
- package/src/modules/ai_assistant/lib/agent-registry.ts +85 -6
- package/src/modules/ai_assistant/lib/agent-run-access.ts +382 -0
- package/src/modules/ai_assistant/lib/agent-run-capture.ts +294 -0
- package/src/modules/ai_assistant/lib/agent-run-dispatcher.ts +111 -0
- package/src/modules/ai_assistant/lib/agent-run-reader.ts +85 -0
- package/src/modules/ai_assistant/lib/agent-run-recorder.ts +453 -0
- package/src/modules/ai_assistant/lib/agent-runtime.ts +893 -275
- package/src/modules/ai_assistant/lib/agent-tool-error.ts +28 -0
- package/src/modules/ai_assistant/lib/agent-tool-rate-limit.ts +78 -0
- package/src/modules/ai_assistant/lib/agent-tool.ts +285 -0
- package/src/modules/ai_assistant/lib/agent-tools.ts +173 -75
- package/src/modules/ai_assistant/lib/ai-agent-definition.ts +39 -0
- package/src/modules/ai_assistant/lib/auth.ts +4 -0
- package/src/modules/ai_assistant/lib/citations.ts +148 -0
- package/src/modules/ai_assistant/lib/codemode-tools.ts +1 -0
- package/src/modules/ai_assistant/lib/http-server.ts +473 -165
- package/src/modules/ai_assistant/lib/llm-adapters/tool-replay-context.ts +283 -0
- package/src/modules/ai_assistant/lib/loop-step-extraction.ts +273 -0
- package/src/modules/ai_assistant/lib/mcp-agent-tool-results.ts +174 -0
- package/src/modules/ai_assistant/lib/mcp-audit.ts +238 -0
- package/src/modules/ai_assistant/lib/mcp-dev-server.ts +174 -33
- package/src/modules/ai_assistant/lib/mcp-exposure.ts +227 -0
- package/src/modules/ai_assistant/lib/mcp-sdk-refusal-audit.ts +113 -0
- package/src/modules/ai_assistant/lib/mcp-server.ts +152 -31
- package/src/modules/ai_assistant/lib/mcp-tool-execution-observer.ts +92 -0
- package/src/modules/ai_assistant/lib/model-factory-context.ts +31 -0
- package/src/modules/ai_assistant/lib/model-factory.ts +16 -1
- package/src/modules/ai_assistant/lib/pending-action-cancel.ts +17 -0
- package/src/modules/ai_assistant/lib/pending-action-client.ts +30 -0
- package/src/modules/ai_assistant/lib/pending-action-executor.ts +31 -6
- package/src/modules/ai_assistant/lib/pending-action-notify.ts +166 -0
- package/src/modules/ai_assistant/lib/pending-action-recheck.ts +166 -5
- package/src/modules/ai_assistant/lib/pending-action-types.ts +32 -0
- package/src/modules/ai_assistant/lib/prepare-mutation.ts +234 -49
- package/src/modules/ai_assistant/lib/report-ai-assistant-error.ts +17 -0
- package/src/modules/ai_assistant/lib/task-plan-stream.ts +11 -0
- package/src/modules/ai_assistant/lib/tool-executor.ts +197 -3
- package/src/modules/ai_assistant/lib/tool-loader.ts +92 -2
- package/src/modules/ai_assistant/lib/tool-ui-parts.ts +48 -0
- package/src/modules/ai_assistant/lib/truncate.ts +39 -0
- package/src/modules/ai_assistant/lib/types.ts +100 -1
- package/src/modules/ai_assistant/migrations/.snapshot-open-mercato.json +1616 -0
- package/src/modules/ai_assistant/migrations/Migration20261022130536_ai_assistant.ts +15 -0
- package/src/modules/ai_assistant/migrations/Migration20261026192929_ai_assistant.ts +42 -0
- package/src/modules/ai_assistant/notifications.client.ts +21 -0
- package/src/modules/ai_assistant/notifications.ts +20 -0
- package/src/modules/ai_assistant/setup.ts +49 -1
- package/src/modules/ai_assistant/widgets/injection/pending-actions-nav-badge/widget.client.tsx +39 -0
- package/src/modules/ai_assistant/widgets/injection/pending-actions-nav-badge/widget.ts +16 -0
- package/src/modules/ai_assistant/widgets/injection-table.ts +12 -0
- package/src/modules/ai_assistant/widgets/notifications/PendingActionAwaitingApprovalRenderer.tsx +132 -0
- package/src/modules/ai_assistant/workers/__tests__/ai-agent-run-prune.test.ts +104 -0
- package/src/modules/ai_assistant/workers/ai-agent-run-prune.ts +120 -0
- package/src/modules/ai_assistant/workers/ai-pending-action-cleanup.ts +30 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
[build:ai-assistant] found
|
|
1
|
+
[build:ai-assistant] found 326 entry points
|
|
2
2
|
[build:ai-assistant] built successfully
|
package/AGENTS.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
- Treat the public AI assistant docs linked below as the source of truth when they disagree with this file.
|
|
8
8
|
- Use `registerMcpTool`/`defineAiTool` with Zod schemas, `moduleId`, `requiredFeatures`, and serializable handler results.
|
|
9
9
|
- Run `yarn generate` after adding or changing agents, tools, API discovery metadata, or tool packs.
|
|
10
|
-
- Route model selection through `createModelFactory(container)`
|
|
10
|
+
- Route model selection through `createModelFactory(container)`; scoped overrides in `model-factory-context.ts` support eval replay before credentials. Recording can isolate tool inference; see `agent-eval-ci.mdx`.
|
|
11
11
|
- Route mutation-capable AI tools through the mutation approval path before execution.
|
|
12
12
|
- Bind MCP and session keys with `sessionUserId`; RBAC intersects their role grants with the owner's effective ACL. Unbound machine keys retain independent role grants.
|
|
13
13
|
- In delegated-key tests, check organization isolation on business records. The UserAcl API clears an empty feature list; retain an unrelated feature when testing revocation.
|
|
@@ -60,8 +60,6 @@ If a section in this AGENTS.md disagrees with one of those public docs, treat th
|
|
|
60
60
|
- Enable dynamic API discovery so the agent can call any endpoint without hardcoded tools
|
|
61
61
|
- Build the Raycast-style Command Palette UI (Cmd+K) for user interaction
|
|
62
62
|
|
|
63
|
-
Four core components to understand:
|
|
64
|
-
|
|
65
63
|
1. **OpenCode Agent** — AI backend that processes natural language and executes tools
|
|
66
64
|
2. **MCP HTTP Server** — Exposes tools to OpenCode via HTTP on port 3001
|
|
67
65
|
3. **Code Mode Tools** — 2 meta-tools (`search` + `execute`) where the AI writes JavaScript that runs in a `node:vm` sandbox
|
|
@@ -71,10 +69,7 @@ Four core components to understand:
|
|
|
71
69
|
|
|
72
70
|
### Add a New Tool
|
|
73
71
|
|
|
74
|
-
|
|
75
|
-
2. Define the tool with name, description, input schema, required features, and handler
|
|
76
|
-
3. Register it with a `moduleId`
|
|
77
|
-
4. Restart the MCP server
|
|
72
|
+
Define tools with `registerMcpTool` (name, description, schema, features, handler), register a `moduleId`, then restart MCP.
|
|
78
73
|
|
|
79
74
|
```typescript
|
|
80
75
|
import { registerMcpTool } from '@open-mercato/ai-assistant'
|
|
@@ -213,9 +208,10 @@ async handler(args, ctx) {
|
|
|
213
208
|
MUST rules for UI parts:
|
|
214
209
|
|
|
215
210
|
- MUST use a namespaced component id (`<module>:<kind>`). Reserved ids (`mutation-preview-card`, `field-diff-card`, `confirmation-card`, `mutation-result-card`) are FROZEN; never reuse.
|
|
216
|
-
- MUST keep props serializable (
|
|
211
|
+
- MUST keep props serializable (the SSE encoder drops functions, class instances, circular refs).
|
|
217
212
|
- MUST gate any privileged action inside the part behind the same ACL features as the originating tool.
|
|
218
|
-
- MUST keep prompt instructions in sync with the tool
|
|
213
|
+
- MUST keep prompt instructions in sync with the tool, or the model paraphrases instead of emitting the part.
|
|
214
|
+
- Cite sources via `emitCitations(ctx, [...])`: validates, drops unsafe hrefs, dedupes, caps 20/call and 50/run (`citations.mdx`).
|
|
219
215
|
|
|
220
216
|
Full reference: `apps/docs/docs/framework/ai-assistant/ui-parts.mdx`.
|
|
221
217
|
|
|
@@ -875,19 +871,30 @@ yarn mcp:serve
|
|
|
875
871
|
| `ai_assistant.tools.list` | MUST require for listing available MCP tools |
|
|
876
872
|
| `ai_assistant.mcp_servers.view` | MUST require for viewing external MCP server configs |
|
|
877
873
|
| `ai_assistant.mcp_servers.manage` | MUST require for creating/editing/deleting MCP server configs |
|
|
874
|
+
| `ai_assistant.pending_actions.approve` | Approve/reject MCP and `/tools/execute` pending actions of other users (Pending AI actions page); granted to `admin` |
|
|
878
875
|
|
|
879
876
|
## Workers
|
|
880
877
|
|
|
881
878
|
| Worker | Queue | Purpose |
|
|
882
879
|
|--------|-------|---------|
|
|
883
|
-
| `workers/ai-pending-action-cleanup` | `ai-pending-action-cleanup` |
|
|
880
|
+
| `workers/ai-pending-action-cleanup` | `ai-pending-action-cleanup` | Flips expired pending approvals (`status = 'pending'`, `expires_at < now`) to `expired` via the state-machine guard, emitting `ai.action.expired`; rows that concurrently transitioned are skipped. 5-minute system interval (`setup.ts`). Manual: `yarn mercato ai_assistant run-pending-action-cleanup`. Concurrency 1. |
|
|
881
|
+
| `workers/ai-agent-run-prune` | `ai-agent-run-prune` | Daily: deletes runs (with steps/tool calls) older than `AI_AGENT_RUNS_RETENTION_DAYS` (30) or soft-deleted. Manual: `yarn mercato ai_assistant run-agent-run-prune`. |
|
|
884
882
|
|
|
885
883
|
## Events
|
|
886
884
|
|
|
887
|
-
|
|
885
|
+
Pending-action events (`events.ts`, `emitAiAssistantEvent`) are FROZEN per `BACKWARD_COMPATIBILITY.md` §5; payloads additive-only, `category: 'system'`, `entity: 'ai_pending_action'`. `ai.action.confirmed` (`executePendingActionConfirm`) carries `{ pendingActionId, agentId, toolName, status, tenantId, organizationId, userId, resolvedByUserId, resolvedAt, executionResult, failedRecords? }`; `ai.action.cancelled` (`executePendingActionCancel`) the same plus `reason?`; `ai.action.expired` (TTL short-circuit and cleanup worker) has `resolvedByUserId: null` plus `expiresAt` / `expiredAt`.
|
|
888
886
|
|
|
889
887
|
`ai_assistant.moderation_flag.created` (`entity: 'ai_moderation_flag'`) fires best-effort from the input-moderation gate; payload carries flagged category names only, never prompt content.
|
|
890
888
|
|
|
889
|
+
`ai_assistant.agent_run.completed` fires after a run record commits; payload carries ids only.
|
|
890
|
+
|
|
891
|
+
## Run tracing
|
|
892
|
+
|
|
893
|
+
Guide: `agents.mdx` → "Model call settings and run tracing". Envs: `OM_AI_RUN_TRACE_CAPTURE` (`full`/`metadata`/`off`), `OM_AI_RUN_TRACE_CAPTURE_PROMPT`, `OM_AI_RUN_TRACE_MAX_PAYLOAD_BYTES`.
|
|
894
|
+
|
|
895
|
+
- The run recorder is best-effort and MUST NEVER throw into the turn.
|
|
896
|
+
- Runners that persist their own trace MUST pass `trace: { persist: false }`.
|
|
897
|
+
|
|
891
898
|
## Input moderation & safety identifiers
|
|
892
899
|
|
|
893
900
|
Guide: [`moderation.mdx`](../../apps/docs/docs/framework/ai-assistant/moderation.mdx) + spec `.ai/specs/2026-06-04-ai-input-moderation-and-safety-identifiers.md`. Envs: `OM_AI_INPUT_MODERATION`, `OM_AI_MODERATION_MODEL`.
|
|
@@ -1409,6 +1416,19 @@ if (tool.requiredFeatures?.length) {
|
|
|
1409
1416
|
}
|
|
1410
1417
|
```
|
|
1411
1418
|
|
|
1419
|
+
### Exposure, List Filtering, Audit and Approval Mode
|
|
1420
|
+
|
|
1421
|
+
Full reference: [`mcp.mdx`](../../apps/docs/docs/framework/ai-assistant/mcp.mdx) → "Exposure, audit and mutation modes".
|
|
1422
|
+
|
|
1423
|
+
- MUST resolve exposure through `resolveMcpExposureConfig` (CLI flag > `OM_MCP_*` env > default) and filter with `isToolExposed` / `filterToolsForCaller` (`lib/mcp-exposure.ts`) in all three servers — never re-implement allow/deny or feature filtering inline.
|
|
1424
|
+
- `mcp:serve-http` registers per request only tools passing exposure + the list principal's ACL (session user from `x-om-session-token`, else the API key's ACL), so `tools/list` == callable set; per-call ACL still runs.
|
|
1425
|
+
- MUST audit every `tools/call` and `/tools/execute` via `recordMcpToolCall` (`lib/mcp-audit.ts`, `access_logs` kind `ai_assistant.mcp_tool_call`): best-effort, bounded, argument names only (never values), correlation id from `x-correlation-id` echoed as `_meta.correlationId`.
|
|
1426
|
+
- MUST pass `channel` + `mutationMode` to `executeTool` from MCP/tools-api callers. `deny` hides and refuses mutations (`MUTATION_REQUIRES_APPROVAL`); `approval` queues an `ai_pending_actions` row (`channel` `mcp`/`tools-api`) and never runs the handler. Raw-tool rows are re-checked at confirm (`tool_not_exposed`, `approver_features_denied`, `requester_revoked`, `requester_features_denied`) and executed as the approver. Chat rows stay owner-only; MCP rows are owner-or-approver (`ai_assistant.pending_actions.approve`).
|
|
1427
|
+
|
|
1428
|
+
### Agent Tools
|
|
1429
|
+
|
|
1430
|
+
Guide: `mcp.mdx` → "Agent tools". Publish agents only via `defineAgentTool` or `mcpTool`; resolve the `aiAgentRunDispatcher` DI key soft-optionally (`resolveAiAgentRunDispatcher`), never import its implementer; stay read-only on `mcp`/`tools-api` unless the mutation mode is `approval`.
|
|
1431
|
+
|
|
1412
1432
|
### Return Standard Error Responses
|
|
1413
1433
|
|
|
1414
1434
|
| Code | Message | When returned |
|
|
@@ -1508,23 +1528,7 @@ Note: the guard is intentionally NOT added to `mcp-client.ts` `connectHttp`, whi
|
|
|
1508
1528
|
|
|
1509
1529
|
### 2026-05-13 - Remove dead `indexApiEndpoints` from MCP boot (#1876)
|
|
1510
1530
|
|
|
1511
|
-
|
|
1512
|
-
- MCP HTTP / stdio / dev entry points no longer call `indexApiEndpoints(searchService)` at startup. The Code Mode rewrite (2026-02-22) deleted the only readers (`find_api` / `call_api` / `discover_schema`), so the call was indexing into fulltext + tokens + vector indexes that nothing queried. On large specs (≳200 ops + remote embedding latency) the search-service fan-out also burned an `OpenAI` embedding storm + pgvector load on every boot — Code Mode reads the OpenAPI document directly via `getRawOpenApiSpec()` / `loadRichOpenApiSpec()`, in-memory.
|
|
1513
|
-
- Deleted `lib/api-discovery-tools.ts`, `lib/entity-graph-tools.ts`, `lib/api-endpoint-index-config.ts` — all dead since the 2026-02-22 rewrite, kept only by the boot-time indexing call we removed.
|
|
1514
|
-
- Pruned `lib/api-endpoint-index.ts`: removed `indexApiEndpoints`, `searchEndpoints`, `searchEndpointsFallback`, `buildSearchableContent`, `lastIndexChecksum`, and the `API_ENDPOINT_ENTITY` deprecated alias. Kept `parseApiEndpoints` (private), `getApiEndpoints`, `getEndpointByOperationId`, `getRawOpenApiSpec`, `loadRichOpenApiSpec`, `setRawSpecCache`, `clearRawSpecCache`, `clearEndpointCache`, `simplifyRequestBodySchema` — those still serve Code Mode.
|
|
1515
|
-
|
|
1516
|
-
**Files modified**:
|
|
1517
|
-
- `lib/http-server.ts`, `lib/mcp-server.ts`, `lib/mcp-dev-server.ts` — removed the `indexApiEndpoints` import + call
|
|
1518
|
-
- `lib/api-endpoint-index.ts` — pruned dead code
|
|
1519
|
-
|
|
1520
|
-
**Files deleted**:
|
|
1521
|
-
- `lib/api-discovery-tools.ts`
|
|
1522
|
-
- `lib/entity-graph-tools.ts`
|
|
1523
|
-
- `lib/api-endpoint-index-config.ts`
|
|
1524
|
-
|
|
1525
|
-
**Backward compatibility**: All removed symbols (`indexApiEndpoints`, `searchEndpoints`, `searchEndpointsFallback`, `endpointToIndexableRecord`, `API_ENDPOINT_ENTITY`, `API_ENDPOINT_SEARCH_CONFIG`, `apiEndpointEntityConfig`, `computeEndpointsChecksum`, `API_ENDPOINT_ENTITY_ID`, `GLOBAL_TENANT_ID` from `api-endpoint-index-config`) live inside the module's internal `lib/` path and are not part of the documented developer contract surface (see `BACKWARD_COMPATIBILITY.md`). They were already documented as legacy and unused.
|
|
1526
|
-
|
|
1527
|
-
**Operator cleanup (optional)**: If a deployment previously booted MCP and accumulated rows in fulltext/vector/tokens under `entityId: 'ai_assistant:api_endpoint'` / `tenantId: '00000000-0000-0000-0000-000000000000'`, they are orphaned but inert — no live workflow reads them. Manual purge is purely cosmetic.
|
|
1531
|
+
MCP HTTP / stdio / dev servers no longer index API endpoints into search at startup (no reader since the Code Mode rewrite; it caused an embedding storm on large specs). Deleted `lib/api-discovery-tools.ts`, `lib/entity-graph-tools.ts`, `lib/api-endpoint-index-config.ts` and pruned `lib/api-endpoint-index.ts` to the Code Mode helpers listed under "Rules for the API Endpoint Index". Removed symbols were internal `lib/` paths, not contract surface. Orphaned `ai_assistant:api_endpoint` search rows are inert; purging them is optional.
|
|
1528
1532
|
|
|
1529
1533
|
### 2026-05-08 - Phase 5 opt-in ToolLoopAgent backend (spec 2026-04-28-ai-agents-agentic-loop-controls)
|
|
1530
1534
|
|
|
@@ -1586,14 +1590,6 @@ Replaced the Vercel AI SDK with OpenCode: the chat API routes to OpenCode, sessi
|
|
|
1586
1590
|
|
|
1587
1591
|
**Lesson learned:** Exposing hundreds of individual tools overwhelms the AI context — use meta-tools the agent can search. Superseded by Code Mode (2026-02-22); the tools and files these entries described (`api_discover`, `api_schema`, `lib/api-discovery-tools.ts`, `lib/entity-graph-tools.ts`) were deleted in #1876. See git history for the detail.
|
|
1588
1592
|
|
|
1589
|
-
### Previous Changes
|
|
1590
|
-
|
|
1591
|
-
See git history for earlier changes including:
|
|
1592
|
-
- Zod 4 schema handling fixes
|
|
1593
|
-
- Debug panel addition
|
|
1594
|
-
- CLI tools fixes
|
|
1595
|
-
- Raycast-style command palette rewrite
|
|
1596
|
-
|
|
1597
1593
|
---
|
|
1598
1594
|
|
|
1599
1595
|
## Upgrading / Operator rollout notes
|
|
@@ -1676,11 +1672,3 @@ For a live end-to-end walkthrough against a real LLM:
|
|
|
1676
1672
|
6. Force a partial-success case (e.g., stale-version on one row) and confirm the result card renders the mixed outcome correctly.
|
|
1677
1673
|
|
|
1678
1674
|
---
|
|
1679
|
-
|
|
1680
|
-
## Future Development
|
|
1681
|
-
|
|
1682
|
-
Refer to git history and specs for planned features:
|
|
1683
|
-
- AI Agent Authorization & Impersonation
|
|
1684
|
-
- Actor + Subject model for audit trails
|
|
1685
|
-
- Permission tiers for rate limiting
|
|
1686
|
-
- Enhanced confirmation flow
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,34 @@ import {
|
|
|
3
3
|
defineAiAgent,
|
|
4
4
|
defineAiAgentExtension
|
|
5
5
|
} from "./modules/ai_assistant/lib/ai-agent-definition.js";
|
|
6
|
+
import {
|
|
7
|
+
mergeCallSettings,
|
|
8
|
+
aiAgentCallSettingsSchema
|
|
9
|
+
} from "./modules/ai_assistant/lib/agent-call-contract.js";
|
|
10
|
+
import {
|
|
11
|
+
AI_AGENT_RUN_DISPATCHER_DI_KEY,
|
|
12
|
+
AiAgentDispatchDeniedError,
|
|
13
|
+
isAiAgentDispatchDeniedError,
|
|
14
|
+
resolveAiAgentRunDispatcher,
|
|
15
|
+
resolveDispatchOwner
|
|
16
|
+
} from "./modules/ai_assistant/lib/agent-run-dispatcher.js";
|
|
6
17
|
import { defineAiTool } from "./modules/ai_assistant/lib/ai-tool-definition.js";
|
|
18
|
+
import {
|
|
19
|
+
emitCitations,
|
|
20
|
+
aiCitationSchema,
|
|
21
|
+
isSafeHref,
|
|
22
|
+
AI_CITATIONS_COMPONENT_ID,
|
|
23
|
+
AI_CITATIONS_MAX_PER_CALL
|
|
24
|
+
} from "./modules/ai_assistant/lib/citations.js";
|
|
25
|
+
import {
|
|
26
|
+
defineAgentTool,
|
|
27
|
+
AGENT_TOOL_DEFAULT_TIMEOUT_MS,
|
|
28
|
+
isAgentToolFeatureSuperset
|
|
29
|
+
} from "./modules/ai_assistant/lib/agent-tool.js";
|
|
30
|
+
import {
|
|
31
|
+
AgentToolError,
|
|
32
|
+
isAgentToolError
|
|
33
|
+
} from "./modules/ai_assistant/lib/agent-tool-error.js";
|
|
7
34
|
import {
|
|
8
35
|
definePromptTemplate
|
|
9
36
|
} from "./modules/ai_assistant/lib/prompt-composition-types.js";
|
|
@@ -16,6 +43,9 @@ import {
|
|
|
16
43
|
import { executeTool } from "./modules/ai_assistant/lib/tool-executor.js";
|
|
17
44
|
import { createMcpServer, runMcpServer } from "./modules/ai_assistant/lib/mcp-server.js";
|
|
18
45
|
import { runMcpHttpServer } from "./modules/ai_assistant/lib/http-server.js";
|
|
46
|
+
import {
|
|
47
|
+
MCP_TOOL_EXECUTION_OBSERVER_DI_KEY
|
|
48
|
+
} from "./modules/ai_assistant/lib/mcp-tool-execution-observer.js";
|
|
19
49
|
import {
|
|
20
50
|
authenticateMcpRequest,
|
|
21
51
|
extractApiKeyFromHeaders
|
|
@@ -42,6 +72,12 @@ import {
|
|
|
42
72
|
resolveAiAgentTools,
|
|
43
73
|
AgentPolicyError
|
|
44
74
|
} from "./modules/ai_assistant/lib/agent-tools.js";
|
|
75
|
+
import {
|
|
76
|
+
withToolReplayContext,
|
|
77
|
+
getToolReplayContext,
|
|
78
|
+
computeToolArgsKey,
|
|
79
|
+
ToolReplayError
|
|
80
|
+
} from "./modules/ai_assistant/lib/llm-adapters/tool-replay-context.js";
|
|
45
81
|
import {
|
|
46
82
|
createAiApiOperationRunner
|
|
47
83
|
} from "./modules/ai_assistant/lib/ai-api-operation-runner.js";
|
|
@@ -127,6 +163,10 @@ import {
|
|
|
127
163
|
} from "./modules/ai_assistant/lib/opencode-handlers.js";
|
|
128
164
|
import { metadata, features } from "./modules/ai_assistant/index.js";
|
|
129
165
|
export {
|
|
166
|
+
AGENT_TOOL_DEFAULT_TIMEOUT_MS,
|
|
167
|
+
AI_AGENT_RUN_DISPATCHER_DI_KEY,
|
|
168
|
+
AI_CITATIONS_COMPONENT_ID,
|
|
169
|
+
AI_CITATIONS_MAX_PER_CALL,
|
|
130
170
|
AI_PENDING_ACTION_ALLOWED_TRANSITIONS,
|
|
131
171
|
AI_PENDING_ACTION_DEFAULT_TTL_SECONDS,
|
|
132
172
|
AI_PENDING_ACTION_QUEUE_MODES,
|
|
@@ -134,9 +174,12 @@ export {
|
|
|
134
174
|
AI_PENDING_ACTION_TERMINAL_STATUSES,
|
|
135
175
|
AI_PENDING_ACTION_TTL_ENV_VAR,
|
|
136
176
|
AgentPolicyError,
|
|
177
|
+
AgentToolError,
|
|
178
|
+
AiAgentDispatchDeniedError,
|
|
137
179
|
AiModelFactoryError,
|
|
138
180
|
AiMutationPreparationError,
|
|
139
181
|
AiPendingActionStateError,
|
|
182
|
+
MCP_TOOL_EXECUTION_OBSERVER_DI_KEY,
|
|
140
183
|
MUTATION_PREVIEW_CARD_COMPONENT,
|
|
141
184
|
OpenCodeClient,
|
|
142
185
|
OpenCodeSessionOwnershipError,
|
|
@@ -144,6 +187,9 @@ export {
|
|
|
144
187
|
PENDING_ACTION_CONFIRMED_EVENT_ID,
|
|
145
188
|
PENDING_ACTION_EXPIRED_EVENT_ID,
|
|
146
189
|
PENDING_ACTION_RECHECK_CODES,
|
|
190
|
+
ToolReplayError,
|
|
191
|
+
aiAgentCallSettingsSchema,
|
|
192
|
+
aiCitationSchema,
|
|
147
193
|
applyAiAgentExtensions,
|
|
148
194
|
applyAiAgentOverrides,
|
|
149
195
|
applyAiOverridesFromEnabledModules,
|
|
@@ -159,16 +205,19 @@ export {
|
|
|
159
205
|
checkToolWhitelist,
|
|
160
206
|
composeSystemPrompt,
|
|
161
207
|
computeMutationIdempotencyKey,
|
|
208
|
+
computeToolArgsKey,
|
|
162
209
|
createAiAgentTransport,
|
|
163
210
|
createAiApiOperationRunner,
|
|
164
211
|
createMcpServer,
|
|
165
212
|
createModelFactory,
|
|
166
213
|
createOpenCodeClient,
|
|
214
|
+
defineAgentTool,
|
|
167
215
|
defineAiAgent,
|
|
168
216
|
defineAiAgentExtension,
|
|
169
217
|
defineAiTool,
|
|
170
218
|
defineApiBackedAiTool,
|
|
171
219
|
definePromptTemplate,
|
|
220
|
+
emitCitations,
|
|
172
221
|
executePendingActionCancel,
|
|
173
222
|
executePendingActionConfirm,
|
|
174
223
|
executeTool,
|
|
@@ -181,29 +230,37 @@ export {
|
|
|
181
230
|
getOwnedPendingQuestions,
|
|
182
231
|
getPendingQuestions,
|
|
183
232
|
getToolRegistry,
|
|
233
|
+
getToolReplayContext,
|
|
184
234
|
handleOpenCodeAnswer,
|
|
185
235
|
handleOpenCodeHealth,
|
|
186
236
|
handleOpenCodeMessage,
|
|
187
237
|
handleOpenCodeMessageStreaming,
|
|
188
238
|
indexToolsForSearch,
|
|
239
|
+
isAgentToolError,
|
|
240
|
+
isAgentToolFeatureSuperset,
|
|
241
|
+
isAiAgentDispatchDeniedError,
|
|
189
242
|
isAiPendingActionQueueMode,
|
|
190
243
|
isAiPendingActionStatus,
|
|
191
244
|
isAllowedAiPendingActionTransition,
|
|
192
245
|
isPendingActionRecheckCode,
|
|
246
|
+
isSafeHref,
|
|
193
247
|
isTerminalAiPendingActionStatus,
|
|
194
248
|
listAgents,
|
|
195
249
|
listAgentsByModule,
|
|
196
250
|
loadAgentRegistry,
|
|
197
251
|
loadAllModuleTools,
|
|
252
|
+
mergeCallSettings,
|
|
198
253
|
metadata,
|
|
199
254
|
prepareMutation,
|
|
200
255
|
registerMcpTool,
|
|
201
256
|
resetAgentRegistryForTests,
|
|
202
257
|
resetProgrammaticOverridesForTests,
|
|
258
|
+
resolveAiAgentRunDispatcher,
|
|
203
259
|
resolveAiAgentTools,
|
|
204
260
|
resolveAiPendingActionTtlSeconds,
|
|
205
261
|
resolveAttachmentParts,
|
|
206
262
|
resolveAttachmentPartsForAgent,
|
|
263
|
+
resolveDispatchOwner,
|
|
207
264
|
runAiAgentObject,
|
|
208
265
|
runAiAgentText,
|
|
209
266
|
runMcpHttpServer,
|
|
@@ -212,6 +269,7 @@ export {
|
|
|
212
269
|
serializePendingActionForClient,
|
|
213
270
|
summarizeAttachmentPartsForPrompt,
|
|
214
271
|
toolRegistry,
|
|
215
|
-
unregisterMcpTool
|
|
272
|
+
unregisterMcpTool,
|
|
273
|
+
withToolReplayContext
|
|
216
274
|
};
|
|
217
275
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @open-mercato/ai-assistant\n *\n * MCP (Model Context Protocol) server module for AI assistant integration.\n *\n * This module provides:\n * - MCP server with stdio transport for Claude Desktop integration\n * - Tool registry for modules to register AI-callable tools\n * - ACL-based permission filtering for tools\n * - Multi-tenant execution context\n *\n * @example\n * ```typescript\n * import { registerMcpTool } from '@open-mercato/ai-assistant/tools'\n * import { z } from 'zod'\n *\n * registerMcpTool({\n * name: 'customers.search',\n * description: 'Search for customers',\n * inputSchema: z.object({ query: z.string() }),\n * requiredFeatures: ['customers.people.view'],\n * handler: async (input, ctx) => {\n * // Implementation\n * }\n * }, { moduleId: 'customers' })\n * ```\n */\n\n// Re-export types\nexport * from './modules/ai_assistant/lib/types'\n\n// Focused-agent definition types + helper\nexport {\n defineAiAgent,\n defineAiAgentExtension,\n type AiAgentDefinition,\n type AiAgentExtension,\n type AiAgentSuggestion,\n type AiAgentExecutionMode,\n type AiAgentMutationPolicy,\n type AiAgentAcceptedMediaType,\n type AiAgentDataOperation,\n type AiAgentPageContextInput,\n type AiAgentStructuredOutput,\n type AiAgentDataCapabilities,\n} from './modules/ai_assistant/lib/ai-agent-definition'\n\n// Additive AI tool builder\nexport { defineAiTool } from './modules/ai_assistant/lib/ai-tool-definition'\n\n// Attachment-bridge contract types (spec Phase 0 \u00A78/\u00A710, implementation-ready for Phase 3 runtime)\nexport {\n type AttachmentSource,\n type AiResolvedAttachmentPart,\n type AiUiPart,\n type AiChatRequestContext,\n} from './modules/ai_assistant/lib/attachment-bridge-types'\n\n// Prompt-composition primitives (spec Phase 0 \u00A78, implementation-ready for Phase 3 prompt composer)\nexport {\n definePromptTemplate,\n type PromptSectionName,\n type PromptSection,\n type PromptTemplate,\n} from './modules/ai_assistant/lib/prompt-composition-types'\n\n// Tool registry\nexport {\n registerMcpTool,\n getToolRegistry,\n unregisterMcpTool,\n toolRegistry,\n} from './modules/ai_assistant/lib/tool-registry'\n\n// Tool executor\nexport { executeTool } from './modules/ai_assistant/lib/tool-executor'\n\n// MCP server (stdio)\nexport { createMcpServer, runMcpServer } from './modules/ai_assistant/lib/mcp-server'\n\n// MCP HTTP server\nexport { runMcpHttpServer, type McpHttpServerOptions } from './modules/ai_assistant/lib/http-server'\n\n// MCP auth\nexport {\n authenticateMcpRequest,\n extractApiKeyFromHeaders,\n type McpAuthResult,\n type McpAuthSuccess,\n type McpAuthFailure,\n} from './modules/ai_assistant/lib/auth'\n\n// Tool loader\nexport { loadAllModuleTools, indexToolsForSearch } from './modules/ai_assistant/lib/tool-loader'\n\n// AI Overrides \u2014 module-to-module + modules.ts + programmatic agent/tool replacement.\n// See `apps/docs/docs/framework/ai-assistant/overrides.mdx`.\nexport {\n applyAiAgentOverrides,\n applyAiAgentExtensions,\n applyAiToolOverrides,\n applyAiOverridesFromEnabledModules,\n resetProgrammaticOverridesForTests,\n type AiAgentOverride,\n type AiToolOverride,\n type AiAgentOverridesMap,\n type AiToolOverridesMap,\n type AiAgentOverrideConfigEntry,\n type AiAgentExtensionConfigEntry,\n type AiToolOverrideConfigEntry,\n type EnabledModuleAiOverrides,\n} from './modules/ai_assistant/lib/ai-overrides'\n\n// Agent registry (Phase 1 WS-A \u2014 read-side lookup API, no policy / dispatch)\nexport {\n loadAgentRegistry,\n getAgent,\n listAgents,\n listAgentsByModule,\n resetAgentRegistryForTests,\n} from './modules/ai_assistant/lib/agent-registry'\n\n// Agent runtime policy gate (Phase 1 WS-A \u2014 pure policy decisions, no HTTP or AI SDK wiring)\nexport {\n checkAgentPolicy,\n type AgentPolicyDenyCode,\n type AgentPolicyDecision,\n type AgentPolicyAuthContext,\n type AgentPolicyCheckInput,\n} from './modules/ai_assistant/lib/agent-policy'\n\n// AI SDK helpers (Phase 1 WS-B \u2014 chat-mode runtime + transport glue)\nexport {\n resolveAiAgentTools,\n AgentPolicyError,\n type ResolveAiAgentToolsInput,\n type ResolvedAgentTools,\n type AiUiPartQueue,\n} from './modules/ai_assistant/lib/agent-tools'\n\n// In-process API operation runner (Phase 1 of API-backed AI tool DRY refactor)\nexport {\n createAiApiOperationRunner,\n type AiApiOperationRequest,\n type AiApiOperationResponse,\n type AiApiOperationRunner,\n type AiApiOperationRunnerOptions,\n type AiApiHttpMethod,\n type AiToolExecutionContext,\n} from './modules/ai_assistant/lib/ai-api-operation-runner'\n\n// API-backed AI tool helper (Phase 2 of API-backed AI tool DRY refactor)\nexport {\n defineApiBackedAiTool,\n type ApiBackedAiToolConfig,\n} from './modules/ai_assistant/lib/api-backed-tool'\n\n// Mutation-preparation helper (Phase 3 WS-C \u2014 Step 5.6)\nexport {\n prepareMutation,\n computeMutationIdempotencyKey,\n AiMutationPreparationError,\n MUTATION_PREVIEW_CARD_COMPONENT,\n type PrepareMutationInput,\n type PrepareMutationContext,\n type PrepareMutationResult,\n} from './modules/ai_assistant/lib/prepare-mutation'\n\nexport {\n runAiAgentText,\n runAiAgentObject,\n composeSystemPrompt,\n type RunAiAgentTextInput,\n type RunAiAgentObjectInput,\n type RunAiAgentObjectOutputOverride,\n type RunAiAgentObjectResult,\n type RunAiAgentObjectGenerateResult,\n type RunAiAgentObjectStreamResult,\n type AgentRequestPageContext,\n} from './modules/ai_assistant/lib/agent-runtime'\n\nexport {\n createAiAgentTransport,\n type CreateAiAgentTransportInput,\n} from './modules/ai_assistant/lib/agent-transport'\n\n// Pending-action types / enums / state-machine guard (Phase 3 WS-C \u2014 Step 5.5)\nexport {\n AI_PENDING_ACTION_STATUSES,\n AI_PENDING_ACTION_QUEUE_MODES,\n AI_PENDING_ACTION_ALLOWED_TRANSITIONS,\n AI_PENDING_ACTION_TERMINAL_STATUSES,\n AI_PENDING_ACTION_DEFAULT_TTL_SECONDS,\n AI_PENDING_ACTION_TTL_ENV_VAR,\n AiPendingActionStateError,\n isAiPendingActionStatus,\n isAiPendingActionQueueMode,\n isTerminalAiPendingActionStatus,\n isAllowedAiPendingActionTransition,\n resolveAiPendingActionTtlSeconds,\n type AiPendingActionStatus,\n type AiPendingActionQueueMode,\n type AiPendingActionRecordDiff,\n type AiPendingActionFailedRecord,\n type AiPendingActionFieldDiff,\n type AiPendingActionExecutionResult,\n} from './modules/ai_assistant/lib/pending-action-types'\n\n// Client-facing pending-action serializer (Phase 3 WS-C \u2014 Step 5.7, reused by 5.8 / 5.9 / 5.10)\nexport {\n serializePendingActionForClient,\n type SerializedPendingAction,\n type SerializablePendingActionRow,\n} from './modules/ai_assistant/lib/pending-action-client'\n\n// Pending-action confirm re-check contract (Phase 3 WS-C \u2014 Step 5.8, reused by 5.9)\nexport {\n runPendingActionRechecks,\n checkStatusAndExpiry,\n checkAgentAndFeatures,\n checkToolWhitelist,\n checkToolFeatures,\n checkAttachmentScope,\n checkRecordVersion,\n PENDING_ACTION_RECHECK_CODES,\n isPendingActionRecheckCode,\n type PendingActionRecheckCode,\n type PendingActionRecheckResult,\n type PendingActionRecheckInput,\n type PendingActionAuthContext,\n} from './modules/ai_assistant/lib/pending-action-recheck'\n\n// Pending-action confirm executor (Phase 3 WS-C \u2014 Step 5.8)\nexport {\n executePendingActionConfirm,\n PENDING_ACTION_CONFIRMED_EVENT_ID,\n type PendingActionExecuteInput,\n type PendingActionExecuteContext,\n type PendingActionExecuteResult,\n type PendingActionExecuteOk,\n type PendingActionExecuteFail,\n} from './modules/ai_assistant/lib/pending-action-executor'\n\n// Pending-action cancel executor (Phase 3 WS-C \u2014 Step 5.9)\nexport {\n executePendingActionCancel,\n PENDING_ACTION_CANCELLED_EVENT_ID,\n PENDING_ACTION_EXPIRED_EVENT_ID,\n type PendingActionCancelInput,\n type PendingActionCancelContext,\n type PendingActionCancelResult,\n type PendingActionCancelStatus,\n} from './modules/ai_assistant/lib/pending-action-cancel'\n\n// Shared AI model factory (Phase 3 WS-A \u2014 Step 5.1)\nexport {\n createModelFactory,\n AiModelFactoryError,\n type AiModelFactory,\n type AiModelFactoryInput,\n type AiModelResolution,\n type AiModelFactoryErrorCode,\n type AiModelInstance,\n type CreateModelFactoryDependencies,\n} from './modules/ai_assistant/lib/model-factory'\n\n// Attachment-to-model bridge (Phase 1 WS-C \u2014 Step 3.7)\nexport {\n resolveAttachmentParts,\n resolveAttachmentPartsForAgent,\n attachmentPartsToUiFileParts,\n summarizeAttachmentPartsForPrompt,\n type ResolveAttachmentPartsInput,\n type AttachmentSigner,\n} from './modules/ai_assistant/lib/attachment-parts'\n\n// OpenCode client\nexport {\n OpenCodeClient,\n createOpenCodeClient,\n type OpenCodeClientConfig,\n type OpenCodeSession,\n type OpenCodeMessage,\n type OpenCodeHealth,\n type OpenCodeMcpStatus,\n} from './modules/ai_assistant/lib/opencode-client'\n\n// OpenCode route handlers\nexport {\n handleOpenCodeMessage,\n handleOpenCodeHealth,\n handleOpenCodeMessageStreaming,\n handleOpenCodeAnswer,\n getPendingQuestions,\n getOwnedPendingQuestions,\n OpenCodeSessionOwnershipError,\n extractTextFromResponse,\n extractAllPartsFromResponse,\n extractMetadataFromResponse,\n type OpenCodeTestRequest,\n type OpenCodeTestResponse,\n type OpenCodeHealthResponse,\n type OpenCodeResponsePart,\n type OpenCodeResponseMetadata,\n type OpenCodeStreamEvent,\n type OpenCodeQuestion,\n type OpenCodeAuthContext,\n type OpenCodeAnswerOwnershipOptions,\n} from './modules/ai_assistant/lib/opencode-handlers'\n\n// Module metadata\nexport { metadata, features } from './modules/ai_assistant'\n"],
|
|
5
|
-
"mappings": "AA6BA,cAAc;AAGd;AAAA,EACE;AAAA,EACA;AAAA,
|
|
4
|
+
"sourcesContent": ["/**\n * @open-mercato/ai-assistant\n *\n * MCP (Model Context Protocol) server module for AI assistant integration.\n *\n * This module provides:\n * - MCP server with stdio transport for Claude Desktop integration\n * - Tool registry for modules to register AI-callable tools\n * - ACL-based permission filtering for tools\n * - Multi-tenant execution context\n *\n * @example\n * ```typescript\n * import { registerMcpTool } from '@open-mercato/ai-assistant/tools'\n * import { z } from 'zod'\n *\n * registerMcpTool({\n * name: 'customers.search',\n * description: 'Search for customers',\n * inputSchema: z.object({ query: z.string() }),\n * requiredFeatures: ['customers.people.view'],\n * handler: async (input, ctx) => {\n * // Implementation\n * }\n * }, { moduleId: 'customers' })\n * ```\n */\n\n// Re-export types\nexport * from './modules/ai_assistant/lib/types'\n\n// Focused-agent definition types + helper\nexport {\n defineAiAgent,\n defineAiAgentExtension,\n type AiAgentDefinition,\n type AiAgentExtension,\n type AiAgentSuggestion,\n type AiAgentExecutionMode,\n type AiAgentMutationPolicy,\n type AiAgentAcceptedMediaType,\n type AiAgentDataOperation,\n type AiAgentPageContextInput,\n type AiAgentStructuredOutput,\n type AiAgentDataCapabilities,\n type AiAgentMcpToolConfig,\n} from './modules/ai_assistant/lib/ai-agent-definition'\n\nexport {\n mergeCallSettings,\n aiAgentCallSettingsSchema,\n type AiAgentCallSettings,\n type AiAgentRunChannel,\n type AiAgentRunTraceOptions,\n type AiAgentCallObserver,\n type AiAgentPromptResolvedEvent,\n type AiAgentModelCallStartEvent,\n type AiAgentModelCallEndEvent,\n type AiAgentModelCallUsage,\n} from './modules/ai_assistant/lib/agent-call-contract'\n\nexport {\n AI_AGENT_RUN_DISPATCHER_DI_KEY,\n AiAgentDispatchDeniedError,\n isAiAgentDispatchDeniedError,\n resolveAiAgentRunDispatcher,\n resolveDispatchOwner,\n type ResolveDispatchOwnerOptions,\n type AiAgentRunDispatcher,\n type AiAgentRunDispatchInput,\n type AiAgentRunDispatchResult,\n type AiAgentRunDispatchCaller,\n type AiAgentRunDispatchUsage,\n type AiAgentRunDispatchVia,\n type AiAgentDispatchDeniedCode,\n} from './modules/ai_assistant/lib/agent-run-dispatcher'\n\n// Additive AI tool builder\nexport { defineAiTool } from './modules/ai_assistant/lib/ai-tool-definition'\n\nexport {\n emitCitations,\n aiCitationSchema,\n isSafeHref,\n AI_CITATIONS_COMPONENT_ID,\n AI_CITATIONS_MAX_PER_CALL,\n type AiCitation,\n type AiCitationsPartPayload,\n type EmitCitationsOptions,\n} from './modules/ai_assistant/lib/citations'\n\n// Agent exposed as one tool (chat, MCP, /tools/execute)\nexport {\n defineAgentTool,\n AGENT_TOOL_DEFAULT_TIMEOUT_MS,\n isAgentToolFeatureSuperset,\n type AgentToolResult,\n type DefineAgentToolSpec,\n} from './modules/ai_assistant/lib/agent-tool'\nexport {\n AgentToolError,\n isAgentToolError,\n type AgentToolErrorCode,\n type AgentToolDenyCode,\n} from './modules/ai_assistant/lib/agent-tool-error'\n\n// Attachment-bridge contract types (spec Phase 0 \u00A78/\u00A710, implementation-ready for Phase 3 runtime)\nexport {\n type AttachmentSource,\n type AiResolvedAttachmentPart,\n type AiUiPart,\n type AiChatRequestContext,\n} from './modules/ai_assistant/lib/attachment-bridge-types'\n\n// Prompt-composition primitives (spec Phase 0 \u00A78, implementation-ready for Phase 3 prompt composer)\nexport {\n definePromptTemplate,\n type PromptSectionName,\n type PromptSection,\n type PromptTemplate,\n} from './modules/ai_assistant/lib/prompt-composition-types'\n\n// Tool registry\nexport {\n registerMcpTool,\n getToolRegistry,\n unregisterMcpTool,\n toolRegistry,\n} from './modules/ai_assistant/lib/tool-registry'\n\n// Tool executor\nexport { executeTool } from './modules/ai_assistant/lib/tool-executor'\n\n// MCP server (stdio)\nexport { createMcpServer, runMcpServer } from './modules/ai_assistant/lib/mcp-server'\n\n// MCP HTTP server\nexport { runMcpHttpServer, type McpHttpServerOptions } from './modules/ai_assistant/lib/http-server'\n\nexport {\n MCP_TOOL_EXECUTION_OBSERVER_DI_KEY,\n type McpToolExecutionObserver,\n type McpToolExecutionObserverContext,\n} from './modules/ai_assistant/lib/mcp-tool-execution-observer'\n\n// MCP auth\nexport {\n authenticateMcpRequest,\n extractApiKeyFromHeaders,\n type McpAuthResult,\n type McpAuthSuccess,\n type McpAuthFailure,\n} from './modules/ai_assistant/lib/auth'\n\n// Tool loader\nexport { loadAllModuleTools, indexToolsForSearch } from './modules/ai_assistant/lib/tool-loader'\n\n// AI Overrides \u2014 module-to-module + modules.ts + programmatic agent/tool replacement.\n// See `apps/docs/docs/framework/ai-assistant/overrides.mdx`.\nexport {\n applyAiAgentOverrides,\n applyAiAgentExtensions,\n applyAiToolOverrides,\n applyAiOverridesFromEnabledModules,\n resetProgrammaticOverridesForTests,\n type AiAgentOverride,\n type AiToolOverride,\n type AiAgentOverridesMap,\n type AiToolOverridesMap,\n type AiAgentOverrideConfigEntry,\n type AiAgentExtensionConfigEntry,\n type AiToolOverrideConfigEntry,\n type EnabledModuleAiOverrides,\n} from './modules/ai_assistant/lib/ai-overrides'\n\n// Agent registry (Phase 1 WS-A \u2014 read-side lookup API, no policy / dispatch)\nexport {\n loadAgentRegistry,\n getAgent,\n listAgents,\n listAgentsByModule,\n resetAgentRegistryForTests,\n} from './modules/ai_assistant/lib/agent-registry'\n\n// Agent runtime policy gate (Phase 1 WS-A \u2014 pure policy decisions, no HTTP or AI SDK wiring)\nexport {\n checkAgentPolicy,\n type AgentPolicyDenyCode,\n type AgentPolicyDecision,\n type AgentPolicyAuthContext,\n type AgentPolicyCheckInput,\n} from './modules/ai_assistant/lib/agent-policy'\n\n// AI SDK helpers (Phase 1 WS-B \u2014 chat-mode runtime + transport glue)\nexport {\n resolveAiAgentTools,\n AgentPolicyError,\n type ResolveAiAgentToolsInput,\n type ResolvedAgentTools,\n type AiUiPartQueue,\n} from './modules/ai_assistant/lib/agent-tools'\n\n// Tool record/replay seam for reproducible eval runs\nexport {\n withToolReplayContext,\n getToolReplayContext,\n computeToolArgsKey,\n ToolReplayError,\n type ToolReplayContext,\n type ToolReplayFixture,\n type ToolReplayMiss,\n type ToolReplayMissReason,\n type ToolReplayErrorCode,\n} from './modules/ai_assistant/lib/llm-adapters/tool-replay-context'\n\n// In-process API operation runner (Phase 1 of API-backed AI tool DRY refactor)\nexport {\n createAiApiOperationRunner,\n type AiApiOperationRequest,\n type AiApiOperationResponse,\n type AiApiOperationRunner,\n type AiApiOperationRunnerOptions,\n type AiApiHttpMethod,\n type AiToolExecutionContext,\n} from './modules/ai_assistant/lib/ai-api-operation-runner'\n\n// API-backed AI tool helper (Phase 2 of API-backed AI tool DRY refactor)\nexport {\n defineApiBackedAiTool,\n type ApiBackedAiToolConfig,\n} from './modules/ai_assistant/lib/api-backed-tool'\n\n// Mutation-preparation helper (Phase 3 WS-C \u2014 Step 5.6)\nexport {\n prepareMutation,\n computeMutationIdempotencyKey,\n AiMutationPreparationError,\n MUTATION_PREVIEW_CARD_COMPONENT,\n type PrepareMutationInput,\n type PrepareMutationContext,\n type PrepareMutationResult,\n} from './modules/ai_assistant/lib/prepare-mutation'\n\nexport {\n runAiAgentText,\n runAiAgentObject,\n composeSystemPrompt,\n type RunAiAgentTextInput,\n type RunAiAgentObjectInput,\n type RunAiAgentObjectOutputOverride,\n type RunAiAgentObjectResult,\n type RunAiAgentObjectGenerateResult,\n type RunAiAgentObjectStreamResult,\n type AgentRequestPageContext,\n} from './modules/ai_assistant/lib/agent-runtime'\n\nexport {\n createAiAgentTransport,\n type CreateAiAgentTransportInput,\n} from './modules/ai_assistant/lib/agent-transport'\n\n// Pending-action types / enums / state-machine guard (Phase 3 WS-C \u2014 Step 5.5)\nexport {\n AI_PENDING_ACTION_STATUSES,\n AI_PENDING_ACTION_QUEUE_MODES,\n AI_PENDING_ACTION_ALLOWED_TRANSITIONS,\n AI_PENDING_ACTION_TERMINAL_STATUSES,\n AI_PENDING_ACTION_DEFAULT_TTL_SECONDS,\n AI_PENDING_ACTION_TTL_ENV_VAR,\n AiPendingActionStateError,\n isAiPendingActionStatus,\n isAiPendingActionQueueMode,\n isTerminalAiPendingActionStatus,\n isAllowedAiPendingActionTransition,\n resolveAiPendingActionTtlSeconds,\n type AiPendingActionStatus,\n type AiPendingActionQueueMode,\n type AiPendingActionRecordDiff,\n type AiPendingActionFailedRecord,\n type AiPendingActionFieldDiff,\n type AiPendingActionExecutionResult,\n} from './modules/ai_assistant/lib/pending-action-types'\n\n// Client-facing pending-action serializer (Phase 3 WS-C \u2014 Step 5.7, reused by 5.8 / 5.9 / 5.10)\nexport {\n serializePendingActionForClient,\n type SerializedPendingAction,\n type SerializablePendingActionRow,\n} from './modules/ai_assistant/lib/pending-action-client'\n\n// Pending-action confirm re-check contract (Phase 3 WS-C \u2014 Step 5.8, reused by 5.9)\nexport {\n runPendingActionRechecks,\n checkStatusAndExpiry,\n checkAgentAndFeatures,\n checkToolWhitelist,\n checkToolFeatures,\n checkAttachmentScope,\n checkRecordVersion,\n PENDING_ACTION_RECHECK_CODES,\n isPendingActionRecheckCode,\n type PendingActionRecheckCode,\n type PendingActionRecheckResult,\n type PendingActionRecheckInput,\n type PendingActionAuthContext,\n} from './modules/ai_assistant/lib/pending-action-recheck'\n\n// Pending-action confirm executor (Phase 3 WS-C \u2014 Step 5.8)\nexport {\n executePendingActionConfirm,\n PENDING_ACTION_CONFIRMED_EVENT_ID,\n type PendingActionExecuteInput,\n type PendingActionExecuteContext,\n type PendingActionExecuteResult,\n type PendingActionExecuteOk,\n type PendingActionExecuteFail,\n} from './modules/ai_assistant/lib/pending-action-executor'\n\n// Pending-action cancel executor (Phase 3 WS-C \u2014 Step 5.9)\nexport {\n executePendingActionCancel,\n PENDING_ACTION_CANCELLED_EVENT_ID,\n PENDING_ACTION_EXPIRED_EVENT_ID,\n type PendingActionCancelInput,\n type PendingActionCancelContext,\n type PendingActionCancelResult,\n type PendingActionCancelStatus,\n} from './modules/ai_assistant/lib/pending-action-cancel'\n\n// Shared AI model factory (Phase 3 WS-A \u2014 Step 5.1)\nexport {\n createModelFactory,\n AiModelFactoryError,\n type AiModelFactory,\n type AiModelFactoryInput,\n type AiModelResolution,\n type AiModelFactoryErrorCode,\n type AiModelInstance,\n type CreateModelFactoryDependencies,\n} from './modules/ai_assistant/lib/model-factory'\n\n// Attachment-to-model bridge (Phase 1 WS-C \u2014 Step 3.7)\nexport {\n resolveAttachmentParts,\n resolveAttachmentPartsForAgent,\n attachmentPartsToUiFileParts,\n summarizeAttachmentPartsForPrompt,\n type ResolveAttachmentPartsInput,\n type AttachmentSigner,\n} from './modules/ai_assistant/lib/attachment-parts'\n\n// OpenCode client\nexport {\n OpenCodeClient,\n createOpenCodeClient,\n type OpenCodeClientConfig,\n type OpenCodeSession,\n type OpenCodeMessage,\n type OpenCodeHealth,\n type OpenCodeMcpStatus,\n} from './modules/ai_assistant/lib/opencode-client'\n\n// OpenCode route handlers\nexport {\n handleOpenCodeMessage,\n handleOpenCodeHealth,\n handleOpenCodeMessageStreaming,\n handleOpenCodeAnswer,\n getPendingQuestions,\n getOwnedPendingQuestions,\n OpenCodeSessionOwnershipError,\n extractTextFromResponse,\n extractAllPartsFromResponse,\n extractMetadataFromResponse,\n type OpenCodeTestRequest,\n type OpenCodeTestResponse,\n type OpenCodeHealthResponse,\n type OpenCodeResponsePart,\n type OpenCodeResponseMetadata,\n type OpenCodeStreamEvent,\n type OpenCodeQuestion,\n type OpenCodeAuthContext,\n type OpenCodeAnswerOwnershipOptions,\n} from './modules/ai_assistant/lib/opencode-handlers'\n\n// Module metadata\nexport { metadata, features } from './modules/ai_assistant'\n"],
|
|
5
|
+
"mappings": "AA6BA,cAAc;AAGd;AAAA,EACE;AAAA,EACA;AAAA,OAYK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,OASK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OASK;AAGP,SAAS,oBAAoB;AAE7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAWP;AAAA,EACE;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,mBAAmB;AAG5B,SAAS,iBAAiB,oBAAoB;AAG9C,SAAS,wBAAmD;AAE5D;AAAA,EACE;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAGP,SAAS,oBAAoB,2BAA2B;AAIxD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OASK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP;AAAA,EACE;AAAA,OAKK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AAGP;AAAA,EACE;AAAA,OAOK;AAGP;AAAA,EACE;AAAA,OAEK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAQK;AAEP;AAAA,EACE;AAAA,OAEK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAOK;AAGP;AAAA,EACE;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAMK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAOK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAMK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAUK;AAGP,SAAS,UAAU,gBAAgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { test, expect } from "@playwright/test";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { apiRequest, getAuthToken } from "@open-mercato/core/helpers/integration/api";
|
|
4
|
+
import { login } from "@open-mercato/core/helpers/integration/auth";
|
|
5
|
+
import { createCompanyFixture, deleteEntityIfExists } from "@open-mercato/core/helpers/integration/crmFixtures";
|
|
6
|
+
import { getTokenScope, readJsonSafe } from "@open-mercato/core/helpers/integration/generalFixtures";
|
|
7
|
+
import {
|
|
8
|
+
deleteAgentRunsInDb,
|
|
9
|
+
deleteConversationAgentRunsInDb,
|
|
10
|
+
deleteConversationCascadeInDb,
|
|
11
|
+
resolveIntegrationRunTraceCapture,
|
|
12
|
+
seedAgentRunInDb
|
|
13
|
+
} from "./helpers/aiAssistantFixtures.js";
|
|
14
|
+
import {
|
|
15
|
+
AGENT_RUNS_API,
|
|
16
|
+
CHAT_RUN_AGENT_ID,
|
|
17
|
+
createConversationFixture,
|
|
18
|
+
sendRealChatTurn,
|
|
19
|
+
waitForConversationRuns
|
|
20
|
+
} from "./helpers/agentRunChat.js";
|
|
21
|
+
const RUNS_PAGE = "/backend/config/ai-assistant/runs";
|
|
22
|
+
const CITATIONS_COMPONENT_ID = "ai_assistant:citations";
|
|
23
|
+
const CITATION_KIND = "it_source";
|
|
24
|
+
const LAUNCHER_AGENTS_STUB = {
|
|
25
|
+
agents: [
|
|
26
|
+
{
|
|
27
|
+
id: CHAT_RUN_AGENT_ID,
|
|
28
|
+
moduleId: "customers",
|
|
29
|
+
label: "Account assistant",
|
|
30
|
+
description: "Helps with customer accounts.",
|
|
31
|
+
executionMode: "chat",
|
|
32
|
+
mutationPolicy: "read-only",
|
|
33
|
+
allowedTools: [],
|
|
34
|
+
requiredFeatures: [],
|
|
35
|
+
acceptedMediaTypes: [],
|
|
36
|
+
hasOutputSchema: false
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
total: 1,
|
|
40
|
+
aiConfigured: true
|
|
41
|
+
};
|
|
42
|
+
function buildCitations(stamp) {
|
|
43
|
+
return [
|
|
44
|
+
{
|
|
45
|
+
kind: CITATION_KIND,
|
|
46
|
+
ref: `doc-external-${stamp}`,
|
|
47
|
+
label: `External handbook ${stamp}`,
|
|
48
|
+
href: "https://example.com/handbook",
|
|
49
|
+
quote: "Refunds are processed within five business days.",
|
|
50
|
+
locator: "p. 4"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
kind: CITATION_KIND,
|
|
54
|
+
ref: `doc-internal-${stamp}`,
|
|
55
|
+
label: `Internal record ${stamp}`,
|
|
56
|
+
href: "/backend/customers/companies"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
kind: CITATION_KIND,
|
|
60
|
+
ref: `doc-unsafe-${stamp}`,
|
|
61
|
+
label: `Unsafe source ${stamp}`,
|
|
62
|
+
href: "javascript:alert(1)"
|
|
63
|
+
}
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
async function expectRenderedCitations(page, scope, stamp) {
|
|
67
|
+
const section = page.locator(scope).locator("[data-ai-citations]");
|
|
68
|
+
await expect(section).toBeVisible({ timeout: 3e4 });
|
|
69
|
+
await expect(section.locator("li")).toHaveCount(3);
|
|
70
|
+
const external = section.getByRole("link", { name: new RegExp(`External handbook ${stamp}`) });
|
|
71
|
+
await expect(external).toHaveAttribute("href", "https://example.com/handbook");
|
|
72
|
+
await expect(external).toHaveAttribute("target", "_blank");
|
|
73
|
+
await expect(external).toHaveAttribute("rel", "noopener noreferrer");
|
|
74
|
+
await expect(section.getByText("p. 4")).toBeVisible();
|
|
75
|
+
await expect(section.getByText("Refunds are processed within five business days.")).toBeVisible();
|
|
76
|
+
const internal = section.getByRole("link", { name: `Internal record ${stamp}` });
|
|
77
|
+
await expect(internal).toHaveAttribute("href", "/backend/customers/companies");
|
|
78
|
+
await expect(internal).not.toHaveAttribute("target", "_blank");
|
|
79
|
+
await expect(section.getByText(`Unsafe source ${stamp}`)).toBeVisible();
|
|
80
|
+
await expect(section.getByRole("link", { name: new RegExp(`Unsafe source ${stamp}`) })).toHaveCount(0);
|
|
81
|
+
await expect(section.locator('a[href^="javascript:"]')).toHaveCount(0);
|
|
82
|
+
}
|
|
83
|
+
test.describe("TC-AI-CITATIONS-020: citations", () => {
|
|
84
|
+
test("the run detail API returns citations and the page renders them as Sources", async ({ page, request }) => {
|
|
85
|
+
test.slow();
|
|
86
|
+
const adminToken = await getAuthToken(request, "admin");
|
|
87
|
+
const { tenantId, organizationId, userId } = getTokenScope(adminToken);
|
|
88
|
+
const stamp = randomUUID().slice(0, 8);
|
|
89
|
+
const agentId = `it_citations.agent_${stamp}`;
|
|
90
|
+
const citations = buildCitations(stamp);
|
|
91
|
+
let runId = null;
|
|
92
|
+
try {
|
|
93
|
+
runId = await seedAgentRunInDb({ tenantId, organizationId, userId, agentId, citations });
|
|
94
|
+
const detailResponse = await apiRequest(request, "GET", `${AGENT_RUNS_API}/${runId}`, { token: adminToken });
|
|
95
|
+
expect(detailResponse.status()).toBe(200);
|
|
96
|
+
const detail = await readJsonSafe(detailResponse);
|
|
97
|
+
expect(detail?.run.citations).toEqual(citations);
|
|
98
|
+
const listResponse = await apiRequest(
|
|
99
|
+
request,
|
|
100
|
+
"GET",
|
|
101
|
+
`${AGENT_RUNS_API}?agentId=${encodeURIComponent(agentId)}`,
|
|
102
|
+
{ token: adminToken }
|
|
103
|
+
);
|
|
104
|
+
expect(listResponse.status()).toBe(200);
|
|
105
|
+
const list = await readJsonSafe(listResponse);
|
|
106
|
+
expect(list?.items).toHaveLength(1);
|
|
107
|
+
expect(list?.items[0]).not.toHaveProperty("citations");
|
|
108
|
+
await login(page, "admin");
|
|
109
|
+
await page.goto(`${RUNS_PAGE}/${runId}`, { waitUntil: "domcontentloaded" });
|
|
110
|
+
await expect(page.locator("[data-agent-run-detail]")).toBeVisible({ timeout: 3e4 });
|
|
111
|
+
await expect(page.locator("[data-agent-run-sources]").getByRole("heading", { name: "Sources" })).toBeVisible();
|
|
112
|
+
await expectRenderedCitations(page, "[data-agent-run-sources]", stamp);
|
|
113
|
+
} finally {
|
|
114
|
+
await deleteAgentRunsInDb([runId]).catch(() => void 0);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
test("a metadata-capture run shows no Sources", async ({ page, request }) => {
|
|
118
|
+
test.slow();
|
|
119
|
+
const adminToken = await getAuthToken(request, "admin");
|
|
120
|
+
const { tenantId, organizationId, userId } = getTokenScope(adminToken);
|
|
121
|
+
const stamp = randomUUID().slice(0, 8);
|
|
122
|
+
const agentId = `it_citations.metadata_${stamp}`;
|
|
123
|
+
let runId = null;
|
|
124
|
+
try {
|
|
125
|
+
runId = await seedAgentRunInDb({
|
|
126
|
+
tenantId,
|
|
127
|
+
organizationId,
|
|
128
|
+
userId,
|
|
129
|
+
agentId,
|
|
130
|
+
captureLevel: "metadata",
|
|
131
|
+
citations: buildCitations(stamp)
|
|
132
|
+
});
|
|
133
|
+
const detailResponse = await apiRequest(request, "GET", `${AGENT_RUNS_API}/${runId}`, { token: adminToken });
|
|
134
|
+
expect(detailResponse.status()).toBe(200);
|
|
135
|
+
const detail = await readJsonSafe(detailResponse);
|
|
136
|
+
expect(detail?.run.captureLevel).toBe("metadata");
|
|
137
|
+
expect(detail?.run.citations ?? null).toBeNull();
|
|
138
|
+
await login(page, "admin");
|
|
139
|
+
await page.route(`**${AGENT_RUNS_API}/${runId}`, async (route) => {
|
|
140
|
+
const response = await route.fetch();
|
|
141
|
+
const body = await response.json();
|
|
142
|
+
await route.fulfill({
|
|
143
|
+
response,
|
|
144
|
+
json: { ...body, run: { ...body.run, citations: buildCitations(stamp) } }
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
await page.goto(`${RUNS_PAGE}/${runId}`, { waitUntil: "domcontentloaded" });
|
|
148
|
+
await expect(page.locator("[data-agent-run-detail]")).toBeVisible({ timeout: 3e4 });
|
|
149
|
+
await expect(page.getByRole("heading", { name: agentId })).toBeVisible();
|
|
150
|
+
await expect(page.locator("[data-agent-run-sources]")).toHaveCount(0);
|
|
151
|
+
await expect(page.locator("[data-ai-citations]")).toHaveCount(0);
|
|
152
|
+
} finally {
|
|
153
|
+
await deleteAgentRunsInDb([runId]).catch(() => void 0);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
test("a reloaded conversation renders the persisted citations part", async ({ page, request }) => {
|
|
157
|
+
test.slow();
|
|
158
|
+
const adminToken = await getAuthToken(request, "admin");
|
|
159
|
+
const { tenantId } = getTokenScope(adminToken);
|
|
160
|
+
const stamp = randomUUID().slice(0, 8);
|
|
161
|
+
const conversationId = `it-citations-${randomUUID()}`;
|
|
162
|
+
try {
|
|
163
|
+
const importResponse = await apiRequest(request, "POST", "/api/ai_assistant/ai/conversations/import", {
|
|
164
|
+
token: adminToken,
|
|
165
|
+
data: {
|
|
166
|
+
conversation: { conversationId, agentId: CHAT_RUN_AGENT_ID, title: `Citations ${stamp}` },
|
|
167
|
+
messages: [
|
|
168
|
+
{ clientMessageId: `it-user-${stamp}`, role: "user", content: "How fast are refunds processed?" },
|
|
169
|
+
{
|
|
170
|
+
clientMessageId: `it-assistant-${stamp}`,
|
|
171
|
+
role: "assistant",
|
|
172
|
+
content: "Refunds take five business days [1].",
|
|
173
|
+
uiParts: [
|
|
174
|
+
{
|
|
175
|
+
componentId: CITATIONS_COMPONENT_ID,
|
|
176
|
+
payload: { citations: buildCitations(stamp), title: `Cited sources ${stamp}` }
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
expect(importResponse.status(), "POST /ai/conversations/import").toBe(200);
|
|
184
|
+
await login(page, "admin");
|
|
185
|
+
await page.route(
|
|
186
|
+
"**/api/ai_assistant/health",
|
|
187
|
+
(route) => route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify({ healthy: true }) })
|
|
188
|
+
);
|
|
189
|
+
await page.route(
|
|
190
|
+
"**/api/ai_assistant/ai/agents",
|
|
191
|
+
(route) => route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify(LAUNCHER_AGENTS_STUB) })
|
|
192
|
+
);
|
|
193
|
+
await page.goto(`/backend?openAiConversation=${encodeURIComponent(conversationId)}`, {
|
|
194
|
+
waitUntil: "domcontentloaded"
|
|
195
|
+
});
|
|
196
|
+
const sheet = page.locator("[data-ai-launcher-sheet]");
|
|
197
|
+
await expect(sheet).toBeVisible({ timeout: 3e4 });
|
|
198
|
+
await expect(sheet.getByText("Refunds take five business days [1].")).toBeVisible({ timeout: 3e4 });
|
|
199
|
+
await expect(sheet.getByRole("heading", { name: `Cited sources ${stamp}` })).toBeVisible();
|
|
200
|
+
await expectRenderedCitations(page, '[data-ai-launcher-sheet] [data-role="assistant"]', stamp);
|
|
201
|
+
} finally {
|
|
202
|
+
await deleteConversationCascadeInDb({ tenantId, conversationId }).catch(() => void 0);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
test("a real chat turn that searches persists record citations on its run", async ({ request }) => {
|
|
206
|
+
test.slow();
|
|
207
|
+
const adminToken = await getAuthToken(request, "admin");
|
|
208
|
+
const { tenantId } = getTokenScope(adminToken);
|
|
209
|
+
const stamp = randomUUID().slice(0, 8);
|
|
210
|
+
const companyName = `Citation Probe ${stamp}`;
|
|
211
|
+
const conversationId = `it-citations-live-${randomUUID()}`;
|
|
212
|
+
let companyId = null;
|
|
213
|
+
try {
|
|
214
|
+
companyId = await createCompanyFixture(request, adminToken, companyName);
|
|
215
|
+
await createConversationFixture(request, adminToken, {
|
|
216
|
+
agentId: CHAT_RUN_AGENT_ID,
|
|
217
|
+
conversationId,
|
|
218
|
+
title: `Citations live ${stamp}`
|
|
219
|
+
});
|
|
220
|
+
const turn = await sendRealChatTurn(request, adminToken, {
|
|
221
|
+
agentId: CHAT_RUN_AGENT_ID,
|
|
222
|
+
conversationId,
|
|
223
|
+
content: `Call search.hybrid_search with q "${companyName}" and tell me what you found.`
|
|
224
|
+
});
|
|
225
|
+
test.skip(turn.status !== 200, `No LLM provider configured (chat returned ${turn.status} ${turn.code ?? ""})`);
|
|
226
|
+
const runs = await waitForConversationRuns(request, adminToken, conversationId);
|
|
227
|
+
const detailResponse = await apiRequest(request, "GET", `${AGENT_RUNS_API}/${runs.items[0].id}`, {
|
|
228
|
+
token: adminToken
|
|
229
|
+
});
|
|
230
|
+
expect(detailResponse.status()).toBe(200);
|
|
231
|
+
const detail = await readJsonSafe(detailResponse);
|
|
232
|
+
const searchCalls = (detail?.toolCalls ?? []).filter((call) => call.toolName === "search.hybrid_search");
|
|
233
|
+
test.skip(searchCalls.length === 0, "The model did not call search.hybrid_search in this turn");
|
|
234
|
+
const hadHits = searchCalls.some((call) => {
|
|
235
|
+
const result = call.result;
|
|
236
|
+
return typeof result?.totalResults === "number" && result.totalResults > 0;
|
|
237
|
+
});
|
|
238
|
+
test.skip(!hadHits, "search.hybrid_search returned no hits (search index not ready)");
|
|
239
|
+
if (resolveIntegrationRunTraceCapture() !== "full") {
|
|
240
|
+
expect(detail?.run.citations ?? null).toBeNull();
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const citations = detail?.run.citations ?? [];
|
|
244
|
+
expect(citations.length).toBeGreaterThan(0);
|
|
245
|
+
expect(citations.length).toBeLessThanOrEqual(50);
|
|
246
|
+
for (const citation of citations) {
|
|
247
|
+
expect(citation.kind).toBe("record");
|
|
248
|
+
expect(String(citation.ref)).toContain(":");
|
|
249
|
+
}
|
|
250
|
+
} finally {
|
|
251
|
+
await deleteConversationAgentRunsInDb({ tenantId, conversationId }).catch(() => void 0);
|
|
252
|
+
await deleteConversationCascadeInDb({ tenantId, conversationId }).catch(() => void 0);
|
|
253
|
+
await deleteEntityIfExists(request, adminToken, "/api/customers/companies", companyId);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
//# sourceMappingURL=TC-AI-CITATIONS-020-citations.spec.js.map
|