@open-mercato/ai-assistant 0.5.1-develop.3036.f02c281f23 → 0.5.1-develop.3045.b4b3320cc2
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 +361 -0
- package/README.md +5 -0
- package/dist/index.js +154 -0
- package/dist/index.js.map +2 -2
- package/dist/modules/ai_assistant/__integration__/TC-AI-002-agent-policy.spec.js +73 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-002-agent-policy.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-AGENT-SETTINGS-005-settings-page.spec.js +484 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-AGENT-SETTINGS-005-settings-page.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-PLAYGROUND-004-playground.spec.js +251 -0
- package/dist/modules/ai_assistant/__integration__/TC-AI-PLAYGROUND-004-playground.spec.js.map +7 -0
- package/dist/modules/ai_assistant/__integration__/TC-INT-AI-TOOLS.spec.js +91 -0
- package/dist/modules/ai_assistant/__integration__/TC-INT-AI-TOOLS.spec.js.map +7 -0
- package/dist/modules/ai_assistant/ai-tools/attachments-pack.js +202 -0
- package/dist/modules/ai_assistant/ai-tools/attachments-pack.js.map +7 -0
- package/dist/modules/ai_assistant/ai-tools/meta-pack.js +121 -0
- package/dist/modules/ai_assistant/ai-tools/meta-pack.js.map +7 -0
- package/dist/modules/ai_assistant/ai-tools/search-pack.js +94 -0
- package/dist/modules/ai_assistant/ai-tools/search-pack.js.map +7 -0
- package/dist/modules/ai_assistant/ai-tools.js +14 -0
- package/dist/modules/ai_assistant/ai-tools.js.map +7 -0
- package/dist/modules/ai_assistant/api/ai/actions/[id]/cancel/route.js +175 -0
- package/dist/modules/ai_assistant/api/ai/actions/[id]/cancel/route.js.map +7 -0
- package/dist/modules/ai_assistant/api/ai/actions/[id]/confirm/route.js +174 -0
- package/dist/modules/ai_assistant/api/ai/actions/[id]/confirm/route.js.map +7 -0
- package/dist/modules/ai_assistant/api/ai/actions/[id]/route.js +101 -0
- package/dist/modules/ai_assistant/api/ai/actions/[id]/route.js.map +7 -0
- package/dist/modules/ai_assistant/api/ai/agents/[agentId]/mutation-policy/route.js +311 -0
- package/dist/modules/ai_assistant/api/ai/agents/[agentId]/mutation-policy/route.js.map +7 -0
- package/dist/modules/ai_assistant/api/ai/agents/[agentId]/prompt-override/route.js +246 -0
- package/dist/modules/ai_assistant/api/ai/agents/[agentId]/prompt-override/route.js.map +7 -0
- package/dist/modules/ai_assistant/api/ai/agents/route.js +94 -0
- package/dist/modules/ai_assistant/api/ai/agents/route.js.map +7 -0
- package/dist/modules/ai_assistant/api/ai/chat/route.js +173 -0
- package/dist/modules/ai_assistant/api/ai/chat/route.js.map +7 -0
- package/dist/modules/ai_assistant/api/ai/run-object/route.js +167 -0
- package/dist/modules/ai_assistant/api/ai/run-object/route.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/agents/AiAgentSettingsPageClient.js +1111 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/agents/AiAgentSettingsPageClient.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/agents/page.js +10 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/agents/page.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/agents/page.meta.js +28 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/agents/page.meta.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/legacy/page.js +10 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/legacy/page.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/legacy/page.meta.js +30 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/legacy/page.meta.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/page.js +4 -6
- package/dist/modules/ai_assistant/backend/config/ai-assistant/page.js.map +2 -2
- package/dist/modules/ai_assistant/backend/config/ai-assistant/page.meta.js +1 -21
- package/dist/modules/ai_assistant/backend/config/ai-assistant/page.meta.js.map +2 -2
- package/dist/modules/ai_assistant/backend/config/ai-assistant/playground/AiPlaygroundPageClient.js +462 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/playground/AiPlaygroundPageClient.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/playground/page.js +10 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/playground/page.js.map +7 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/playground/page.meta.js +28 -0
- package/dist/modules/ai_assistant/backend/config/ai-assistant/playground/page.meta.js.map +7 -0
- package/dist/modules/ai_assistant/cli.js +78 -12
- package/dist/modules/ai_assistant/cli.js.map +2 -2
- package/dist/modules/ai_assistant/data/entities/AiAgentMutationPolicyOverride.js +5 -0
- package/dist/modules/ai_assistant/data/entities/AiAgentMutationPolicyOverride.js.map +7 -0
- package/dist/modules/ai_assistant/data/entities/AiAgentPromptOverride.js +5 -0
- package/dist/modules/ai_assistant/data/entities/AiAgentPromptOverride.js.map +7 -0
- package/dist/modules/ai_assistant/data/entities/AiPendingAction.js +5 -0
- package/dist/modules/ai_assistant/data/entities/AiPendingAction.js.map +7 -0
- package/dist/modules/ai_assistant/data/entities.js +228 -0
- package/dist/modules/ai_assistant/data/entities.js.map +7 -0
- package/dist/modules/ai_assistant/data/repositories/AiAgentMutationPolicyOverrideRepository.js +95 -0
- package/dist/modules/ai_assistant/data/repositories/AiAgentMutationPolicyOverrideRepository.js.map +7 -0
- package/dist/modules/ai_assistant/data/repositories/AiAgentPromptOverrideRepository.js +95 -0
- package/dist/modules/ai_assistant/data/repositories/AiAgentPromptOverrideRepository.js.map +7 -0
- package/dist/modules/ai_assistant/data/repositories/AiPendingActionRepository.js +223 -0
- package/dist/modules/ai_assistant/data/repositories/AiPendingActionRepository.js.map +7 -0
- package/dist/modules/ai_assistant/events.js +33 -0
- package/dist/modules/ai_assistant/events.js.map +7 -0
- package/dist/modules/ai_assistant/i18n/de.json +252 -0
- package/dist/modules/ai_assistant/i18n/en.json +252 -0
- package/dist/modules/ai_assistant/i18n/es.json +252 -0
- package/dist/modules/ai_assistant/i18n/pl.json +252 -0
- package/dist/modules/ai_assistant/lib/agent-policy.js +168 -0
- package/dist/modules/ai_assistant/lib/agent-policy.js.map +7 -0
- package/dist/modules/ai_assistant/lib/agent-registry.js +195 -0
- package/dist/modules/ai_assistant/lib/agent-registry.js.map +7 -0
- package/dist/modules/ai_assistant/lib/agent-runtime.js +451 -0
- package/dist/modules/ai_assistant/lib/agent-runtime.js.map +7 -0
- package/dist/modules/ai_assistant/lib/agent-tools.js +223 -0
- package/dist/modules/ai_assistant/lib/agent-tools.js.map +7 -0
- package/dist/modules/ai_assistant/lib/agent-transport.js +25 -0
- package/dist/modules/ai_assistant/lib/agent-transport.js.map +7 -0
- package/dist/modules/ai_assistant/lib/ai-agent-definition.js +11 -0
- package/dist/modules/ai_assistant/lib/ai-agent-definition.js.map +7 -0
- package/dist/modules/ai_assistant/lib/ai-agents-generated.d.js +1 -0
- package/dist/modules/ai_assistant/lib/ai-agents-generated.d.js.map +7 -0
- package/dist/modules/ai_assistant/lib/ai-api-operation-runner.js +239 -0
- package/dist/modules/ai_assistant/lib/ai-api-operation-runner.js.map +7 -0
- package/dist/modules/ai_assistant/lib/ai-overrides.js +189 -0
- package/dist/modules/ai_assistant/lib/ai-overrides.js.map +7 -0
- package/dist/modules/ai_assistant/lib/ai-tool-definition.js +7 -0
- package/dist/modules/ai_assistant/lib/ai-tool-definition.js.map +7 -0
- package/dist/modules/ai_assistant/lib/ai-tools-generated.d.js +1 -0
- package/dist/modules/ai_assistant/lib/ai-tools-generated.d.js.map +7 -0
- package/dist/modules/ai_assistant/lib/api-backed-tool.js +48 -0
- package/dist/modules/ai_assistant/lib/api-backed-tool.js.map +7 -0
- package/dist/modules/ai_assistant/lib/attachment-bridge-types.js +1 -0
- package/dist/modules/ai_assistant/lib/attachment-bridge-types.js.map +7 -0
- package/dist/modules/ai_assistant/lib/attachment-parts.js +276 -0
- package/dist/modules/ai_assistant/lib/attachment-parts.js.map +7 -0
- package/dist/modules/ai_assistant/lib/model-factory.js +68 -0
- package/dist/modules/ai_assistant/lib/model-factory.js.map +7 -0
- package/dist/modules/ai_assistant/lib/pending-action-cancel.js +86 -0
- package/dist/modules/ai_assistant/lib/pending-action-cancel.js.map +7 -0
- package/dist/modules/ai_assistant/lib/pending-action-client.js +35 -0
- package/dist/modules/ai_assistant/lib/pending-action-client.js.map +7 -0
- package/dist/modules/ai_assistant/lib/pending-action-executor.js +243 -0
- package/dist/modules/ai_assistant/lib/pending-action-executor.js.map +7 -0
- package/dist/modules/ai_assistant/lib/pending-action-recheck.js +246 -0
- package/dist/modules/ai_assistant/lib/pending-action-recheck.js.map +7 -0
- package/dist/modules/ai_assistant/lib/pending-action-types.js +70 -0
- package/dist/modules/ai_assistant/lib/pending-action-types.js.map +7 -0
- package/dist/modules/ai_assistant/lib/prepare-mutation.js +315 -0
- package/dist/modules/ai_assistant/lib/prepare-mutation.js.map +7 -0
- package/dist/modules/ai_assistant/lib/prompt-composition-types.js +7 -0
- package/dist/modules/ai_assistant/lib/prompt-composition-types.js.map +7 -0
- package/dist/modules/ai_assistant/lib/prompt-override-merge.js +175 -0
- package/dist/modules/ai_assistant/lib/prompt-override-merge.js.map +7 -0
- package/dist/modules/ai_assistant/lib/schema-utils.js +5 -1
- package/dist/modules/ai_assistant/lib/schema-utils.js.map +2 -2
- package/dist/modules/ai_assistant/lib/tool-executor.js +13 -2
- package/dist/modules/ai_assistant/lib/tool-executor.js.map +2 -2
- package/dist/modules/ai_assistant/lib/tool-loader.js +86 -11
- package/dist/modules/ai_assistant/lib/tool-loader.js.map +2 -2
- package/dist/modules/ai_assistant/lib/tool-test-fixtures.js +120 -0
- package/dist/modules/ai_assistant/lib/tool-test-fixtures.js.map +7 -0
- package/dist/modules/ai_assistant/lib/tool-test-runner.js +418 -0
- package/dist/modules/ai_assistant/lib/tool-test-runner.js.map +7 -0
- package/dist/modules/ai_assistant/migrations/Migration20260419100521.js +17 -0
- package/dist/modules/ai_assistant/migrations/Migration20260419100521.js.map +7 -0
- package/dist/modules/ai_assistant/migrations/Migration20260419132948.js +16 -0
- package/dist/modules/ai_assistant/migrations/Migration20260419132948.js.map +7 -0
- package/dist/modules/ai_assistant/migrations/Migration20260419134235.js +17 -0
- package/dist/modules/ai_assistant/migrations/Migration20260419134235.js.map +7 -0
- package/dist/modules/ai_assistant/setup.js +36 -0
- package/dist/modules/ai_assistant/setup.js.map +2 -2
- package/dist/modules/ai_assistant/workers/ai-pending-action-cleanup.js +161 -0
- package/dist/modules/ai_assistant/workers/ai-pending-action-cleanup.js.map +7 -0
- package/generated/entities/ai_agent_mutation_policy_override/index.ts +9 -0
- package/generated/entities/ai_agent_prompt_override/index.ts +10 -0
- package/generated/entities/ai_pending_action/index.ts +24 -0
- package/generated/entities.ids.generated.ts +13 -0
- package/generated/entity-fields-registry.ts +57 -0
- package/jest.config.cjs +7 -0
- package/package.json +4 -4
- package/src/index.ts +215 -0
- package/src/modules/ai_assistant/__integration__/README.md +5 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-002-agent-policy.spec.ts +115 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-AGENT-SETTINGS-005-settings-page.spec.ts +574 -0
- package/src/modules/ai_assistant/__integration__/TC-AI-PLAYGROUND-004-playground.spec.ts +333 -0
- package/src/modules/ai_assistant/__integration__/TC-INT-AI-TOOLS.spec.ts +135 -0
- package/src/modules/ai_assistant/__tests__/events.test.ts +145 -0
- package/src/modules/ai_assistant/__tests__/integration/pending-action-contract.test.ts +1015 -0
- package/src/modules/ai_assistant/__tests__/integration/ws-c-attachment-bridge.test.ts +235 -0
- package/src/modules/ai_assistant/__tests__/integration/ws-c-policy-and-tools.test.ts +330 -0
- package/src/modules/ai_assistant/__tests__/integration/ws-c-tool-pack-coverage.test.ts +285 -0
- package/src/modules/ai_assistant/ai-tools/__tests__/attachments-pack.test.ts +322 -0
- package/src/modules/ai_assistant/ai-tools/__tests__/meta-pack.test.ts +218 -0
- package/src/modules/ai_assistant/ai-tools/__tests__/search-pack.test.ts +192 -0
- package/src/modules/ai_assistant/ai-tools/attachments-pack.ts +269 -0
- package/src/modules/ai_assistant/ai-tools/meta-pack.ts +140 -0
- package/src/modules/ai_assistant/ai-tools/search-pack.ts +122 -0
- package/src/modules/ai_assistant/ai-tools.ts +21 -0
- package/src/modules/ai_assistant/api/ai/actions/[id]/__tests__/route.test.ts +222 -0
- package/src/modules/ai_assistant/api/ai/actions/[id]/cancel/__tests__/route.test.ts +286 -0
- package/src/modules/ai_assistant/api/ai/actions/[id]/cancel/route.ts +237 -0
- package/src/modules/ai_assistant/api/ai/actions/[id]/confirm/__tests__/route.test.ts +339 -0
- package/src/modules/ai_assistant/api/ai/actions/[id]/confirm/route.ts +229 -0
- package/src/modules/ai_assistant/api/ai/actions/[id]/route.ts +142 -0
- package/src/modules/ai_assistant/api/ai/agents/[agentId]/mutation-policy/__tests__/route.test.ts +367 -0
- package/src/modules/ai_assistant/api/ai/agents/[agentId]/mutation-policy/route.ts +380 -0
- package/src/modules/ai_assistant/api/ai/agents/[agentId]/prompt-override/__tests__/route.test.ts +333 -0
- package/src/modules/ai_assistant/api/ai/agents/[agentId]/prompt-override/route.ts +307 -0
- package/src/modules/ai_assistant/api/ai/agents/route.ts +107 -0
- package/src/modules/ai_assistant/api/ai/chat/__tests__/route.test.ts +282 -0
- package/src/modules/ai_assistant/api/ai/chat/route.ts +207 -0
- package/src/modules/ai_assistant/api/ai/run-object/__tests__/route.test.ts +282 -0
- package/src/modules/ai_assistant/api/ai/run-object/route.ts +204 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/agents/AiAgentSettingsPageClient.tsx +1419 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/agents/page.meta.ts +26 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/agents/page.tsx +12 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/legacy/page.meta.ts +28 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/legacy/page.tsx +12 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/page.meta.ts +8 -23
- package/src/modules/ai_assistant/backend/config/ai-assistant/page.tsx +15 -10
- package/src/modules/ai_assistant/backend/config/ai-assistant/playground/AiPlaygroundPageClient.tsx +604 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/playground/page.meta.ts +26 -0
- package/src/modules/ai_assistant/backend/config/ai-assistant/playground/page.tsx +12 -0
- package/src/modules/ai_assistant/cli.ts +99 -24
- package/src/modules/ai_assistant/data/__tests__/schema-unique-indexes.test.ts +69 -0
- package/src/modules/ai_assistant/data/entities/AiAgentMutationPolicyOverride.ts +7 -0
- package/src/modules/ai_assistant/data/entities/AiAgentPromptOverride.ts +7 -0
- package/src/modules/ai_assistant/data/entities/AiPendingAction.ts +7 -0
- package/src/modules/ai_assistant/data/entities.ts +270 -0
- package/src/modules/ai_assistant/data/repositories/AiAgentMutationPolicyOverrideRepository.ts +129 -0
- package/src/modules/ai_assistant/data/repositories/AiAgentPromptOverrideRepository.ts +132 -0
- package/src/modules/ai_assistant/data/repositories/AiPendingActionRepository.ts +334 -0
- package/src/modules/ai_assistant/data/repositories/__tests__/AiAgentMutationPolicyOverrideRepository.test.ts +195 -0
- package/src/modules/ai_assistant/data/repositories/__tests__/AiAgentPromptOverrideRepository.test.ts +197 -0
- package/src/modules/ai_assistant/data/repositories/__tests__/AiPendingActionRepository.test.ts +357 -0
- package/src/modules/ai_assistant/events.ts +112 -0
- package/src/modules/ai_assistant/i18n/de.json +252 -0
- package/src/modules/ai_assistant/i18n/en.json +252 -0
- package/src/modules/ai_assistant/i18n/es.json +252 -0
- package/src/modules/ai_assistant/i18n/pl.json +252 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-policy.mutation-override.test.ts +203 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-policy.test.ts +385 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-registry.test.ts +217 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-runtime-object.test.ts +329 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-runtime-parity.test.ts +573 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-runtime.test.ts +291 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-tools.test.ts +172 -0
- package/src/modules/ai_assistant/lib/__tests__/agent-transport.test.ts +41 -0
- package/src/modules/ai_assistant/lib/__tests__/ai-agent-definition.test.ts +183 -0
- package/src/modules/ai_assistant/lib/__tests__/ai-api-operation-runner.test.ts +432 -0
- package/src/modules/ai_assistant/lib/__tests__/ai-overrides.test.ts +308 -0
- package/src/modules/ai_assistant/lib/__tests__/api-backed-tool.test.ts +302 -0
- package/src/modules/ai_assistant/lib/__tests__/attachment-bridge-and-prompt-types.test.ts +188 -0
- package/src/modules/ai_assistant/lib/__tests__/attachment-parts.test.ts +531 -0
- package/src/modules/ai_assistant/lib/__tests__/max-steps-budget.integration.test.ts +263 -0
- package/src/modules/ai_assistant/lib/__tests__/model-factory.integration.test.ts +183 -0
- package/src/modules/ai_assistant/lib/__tests__/model-factory.test.ts +168 -0
- package/src/modules/ai_assistant/lib/__tests__/pending-action-cancel.test.ts +235 -0
- package/src/modules/ai_assistant/lib/__tests__/pending-action-client.test.ts +148 -0
- package/src/modules/ai_assistant/lib/__tests__/pending-action-executor.test.ts +348 -0
- package/src/modules/ai_assistant/lib/__tests__/pending-action-recheck.test.ts +378 -0
- package/src/modules/ai_assistant/lib/__tests__/phase-0-additive-contract.test.ts +299 -0
- package/src/modules/ai_assistant/lib/__tests__/prepare-mutation.test.ts +610 -0
- package/src/modules/ai_assistant/lib/__tests__/prompt-override-merge.test.ts +136 -0
- package/src/modules/ai_assistant/lib/__tests__/tool-loader.test.ts +125 -0
- package/src/modules/ai_assistant/lib/agent-policy.ts +270 -0
- package/src/modules/ai_assistant/lib/agent-registry.ts +277 -0
- package/src/modules/ai_assistant/lib/agent-runtime.ts +751 -0
- package/src/modules/ai_assistant/lib/agent-tools.ts +396 -0
- package/src/modules/ai_assistant/lib/agent-transport.ts +51 -0
- package/src/modules/ai_assistant/lib/ai-agent-definition.ts +86 -0
- package/src/modules/ai_assistant/lib/ai-agents-generated.d.ts +18 -0
- package/src/modules/ai_assistant/lib/ai-api-operation-runner.ts +333 -0
- package/src/modules/ai_assistant/lib/ai-overrides.ts +389 -0
- package/src/modules/ai_assistant/lib/ai-tool-definition.ts +7 -0
- package/src/modules/ai_assistant/lib/ai-tools-generated.d.ts +7 -0
- package/src/modules/ai_assistant/lib/api-backed-tool.ts +85 -0
- package/src/modules/ai_assistant/lib/attachment-bridge-types.ts +24 -0
- package/src/modules/ai_assistant/lib/attachment-parts.ts +433 -0
- package/src/modules/ai_assistant/lib/model-factory.ts +212 -0
- package/src/modules/ai_assistant/lib/pending-action-cancel.ts +179 -0
- package/src/modules/ai_assistant/lib/pending-action-client.ts +126 -0
- package/src/modules/ai_assistant/lib/pending-action-executor.ts +424 -0
- package/src/modules/ai_assistant/lib/pending-action-recheck.ts +410 -0
- package/src/modules/ai_assistant/lib/pending-action-types.ts +194 -0
- package/src/modules/ai_assistant/lib/prepare-mutation.ts +448 -0
- package/src/modules/ai_assistant/lib/prompt-composition-types.ts +24 -0
- package/src/modules/ai_assistant/lib/prompt-override-merge.ts +253 -0
- package/src/modules/ai_assistant/lib/schema-utils.ts +14 -2
- package/src/modules/ai_assistant/lib/tool-executor.ts +25 -3
- package/src/modules/ai_assistant/lib/tool-loader.ts +159 -13
- package/src/modules/ai_assistant/lib/tool-test-fixtures.ts +160 -0
- package/src/modules/ai_assistant/lib/tool-test-runner.ts +596 -0
- package/src/modules/ai_assistant/lib/types.ts +105 -2
- package/src/modules/ai_assistant/migrations/.snapshot-open-mercato.json +871 -0
- package/src/modules/ai_assistant/migrations/Migration20260419100521.ts +17 -0
- package/src/modules/ai_assistant/migrations/Migration20260419132948.ts +16 -0
- package/src/modules/ai_assistant/migrations/Migration20260419134235.ts +17 -0
- package/src/modules/ai_assistant/setup.ts +53 -0
- package/src/modules/ai_assistant/workers/__tests__/ai-pending-action-cleanup.test.ts +333 -0
- package/src/modules/ai_assistant/workers/ai-pending-action-cleanup.ts +269 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
[build:ai-assistant] found
|
|
1
|
+
[build:ai-assistant] found 151 entry points
|
|
2
2
|
[build:ai-assistant] built successfully
|
package/AGENTS.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
> **IMPORTANT**: Update this file with every major change to this module. When implementing new features, modifying architecture, or changing key interfaces, update the relevant sections to keep guidance accurate for future agents.
|
|
4
4
|
|
|
5
|
+
## Where to look first
|
|
6
|
+
|
|
7
|
+
Before editing this module — and especially before writing or reviewing a new agent — read the public framework docs. They are the source of truth and stay in sync with this AGENTS.md by review:
|
|
8
|
+
|
|
9
|
+
| Topic | Public doc | This file |
|
|
10
|
+
|-------|------------|-----------|
|
|
11
|
+
| System map, request flow, persistence | [`apps/docs/docs/framework/ai-assistant/architecture.mdx`](../../apps/docs/docs/framework/ai-assistant/architecture.mdx) | "Architecture Constraints" below |
|
|
12
|
+
| End-to-end "add a new agent" walkthrough | [`apps/docs/docs/framework/ai-assistant/developer-guide.mdx`](../../apps/docs/docs/framework/ai-assistant/developer-guide.mdx) + [`.ai/skills/create-ai-agent/SKILL.md`](../../.ai/skills/create-ai-agent/SKILL.md) | "How to Add a New AI Agent" below |
|
|
13
|
+
| Agent contract reference | [`apps/docs/docs/framework/ai-assistant/agents.mdx`](../../apps/docs/docs/framework/ai-assistant/agents.mdx) | "How to Add an AI Tool Pack" below |
|
|
14
|
+
| Record cards + custom inline UI parts | [`apps/docs/docs/framework/ai-assistant/ui-parts.mdx`](../../apps/docs/docs/framework/ai-assistant/ui-parts.mdx) | "Adding UI Parts" below |
|
|
15
|
+
| File upload contract | [`apps/docs/docs/framework/ai-assistant/attachments.mdx`](../../apps/docs/docs/framework/ai-assistant/attachments.mdx) | — |
|
|
16
|
+
| Mutation approval lifecycle | [`apps/docs/docs/framework/ai-assistant/mutation-approvals.mdx`](../../apps/docs/docs/framework/ai-assistant/mutation-approvals.mdx) | "Workers" / "Events" below |
|
|
17
|
+
| Topbar launcher + Cmd/Ctrl+L | [`apps/docs/docs/framework/ai-assistant/launcher.mdx`](../../apps/docs/docs/framework/ai-assistant/launcher.mdx) | — |
|
|
18
|
+
| Overrides/extensions — replace, disable, append, or delete tools/prompts/suggestions across modules | [`apps/docs/docs/framework/ai-assistant/overrides.mdx`](../../apps/docs/docs/framework/ai-assistant/overrides.mdx) | "How to Override or Extend Another Module's Agent or Tool" below |
|
|
19
|
+
| Tenant prompt + policy overrides | [`apps/docs/docs/framework/ai-assistant/settings.mdx`](../../apps/docs/docs/framework/ai-assistant/settings.mdx) | — |
|
|
20
|
+
| Operator-facing user guide | [`apps/docs/docs/user-guide/ai-assistant.mdx`](../../apps/docs/docs/user-guide/ai-assistant.mdx) | — |
|
|
21
|
+
|
|
22
|
+
If a section in this AGENTS.md disagrees with one of those public docs, treat the public doc as authoritative and open a follow-up to update this file.
|
|
23
|
+
|
|
5
24
|
## Use This Module To...
|
|
6
25
|
|
|
7
26
|
- Add AI-powered assistance capabilities to Open Mercato
|
|
@@ -77,6 +96,229 @@ APIs are automatically available via the Code Mode `search` tool (reads the Open
|
|
|
77
96
|
5. Send: "find his related companies"
|
|
78
97
|
6. Verify: `willContinue: true` and the AI references Taylor correctly
|
|
79
98
|
|
|
99
|
+
### How to Add a New AI Agent
|
|
100
|
+
|
|
101
|
+
> **Use the [`create-ai-agent` skill](../../.ai/skills/create-ai-agent/SKILL.md)** for the full step-by-step procedure (file layout, tool pack registration, mutation approval wiring, ACL/setup, generator + cache refresh, `<AiChat>` embedding, standalone vs monorepo differences, and a verification checklist). The summary below stays here for quick reference.
|
|
102
|
+
|
|
103
|
+
Typed AI agents live in each module's root `ai-agents.ts`. The generator auto-discovers the file and aggregates it into `apps/mercato/.mercato/generated/ai-agents.generated.ts`. Reference implementations: `packages/core/src/modules/customers/ai-agents.ts` and `packages/core/src/modules/catalog/ai-agents.ts`.
|
|
104
|
+
|
|
105
|
+
1. Create `<module>/ai-agents.ts` and export `aiAgents: AiAgentDefinition[]` (default export optional).
|
|
106
|
+
2. Declare the agent with `defineAiAgent({ ... })` from `@open-mercato/ai-assistant`. Required fields: `id`, `moduleId`, `label`, `description`, `systemPrompt`, `allowedTools`. Useful optional fields: `executionMode` (`'chat'` — default — or `'object'`), `defaultModel`, `acceptedMediaTypes`, `requiredFeatures`, `uiParts`, `readOnly`, `mutationPolicy` (`'read-only'` | `'confirm-required'` | `'destructive-confirm-required'`), `maxSteps`, `output` (Zod schema for `'object'` mode), `resolvePageContext`, `keywords`, `suggestions`, `domain`, `dataCapabilities`.
|
|
107
|
+
3. Add the feature(s) you list in `requiredFeatures` to the module's `acl.ts` and grant them in `setup.ts` `defaultRoleFeatures`.
|
|
108
|
+
4. Put the agent's tool allowlist behind the narrowest set possible. Start from the general-purpose packs (`search.hybrid_search`, `search.get_record_context`, `attachments.list_record_attachments`, `attachments.read_attachment`, `meta.describe_agent`) and add your module's own `defineAiTool`-registered tools.
|
|
109
|
+
5. For mutation-capable agents, keep `readOnly: true` + `mutationPolicy: 'read-only'` on the agent and light up writes only via the per-tenant mutation-policy override table (spec Phase 3 WS-C §5.4). The runtime filters out any `isMutation: true` tool when the override is still read-only.
|
|
110
|
+
6. Run `yarn generate` so the agent shows up in the registry. Smoke-test via `/backend/config/ai-assistant/playground` (see `/framework/ai-assistant/playground`), then embed `<AiChat agent="<module>.<agent>" />` in the page where you want the operator UI.
|
|
111
|
+
|
|
112
|
+
### How to Add an AI Tool Pack
|
|
113
|
+
|
|
114
|
+
Typed tools live under `<module>/ai-tools/` and register via `defineAiTool`. Tool packs are exposed to agents through the agent's `allowedTools` array.
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { defineAiTool } from '@open-mercato/ai-assistant'
|
|
118
|
+
import { z } from 'zod'
|
|
119
|
+
|
|
120
|
+
const listPeopleTool = defineAiTool({
|
|
121
|
+
name: 'customers.list_people',
|
|
122
|
+
description: 'Search customer people records by name, email, or tag.',
|
|
123
|
+
inputSchema: z.object({
|
|
124
|
+
query: z.string().optional(),
|
|
125
|
+
limit: z.number().int().min(1).max(100).default(20),
|
|
126
|
+
}),
|
|
127
|
+
requiredFeatures: ['customers.people.view'],
|
|
128
|
+
isMutation: false,
|
|
129
|
+
async handler(input, ctx) {
|
|
130
|
+
// ctx.container, ctx.tenantId, ctx.organizationId, ctx.userId, ctx.userFeatures, ctx.isSuperAdmin
|
|
131
|
+
return { records: [] }
|
|
132
|
+
},
|
|
133
|
+
})
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
MUST rules:
|
|
137
|
+
- MUST set `requiredFeatures` for any tool that reads or writes tenant data. The wildcard-aware ACL matcher is applied before the handler runs.
|
|
138
|
+
- MUST use Zod for `inputSchema` — never raw JSON Schema.
|
|
139
|
+
- MUST set `isMutation: true` on write tools. The policy gate strips these from read-only agents and from read-only tenant overrides.
|
|
140
|
+
- MUST route every mutation tool through `prepareMutation(...)` (see the Mutation Approvals guide at `/framework/ai-assistant/mutation-approvals`). Writing directly inside the handler bypasses the approval gate — the runtime fails closed and refuses to return a result to the operator.
|
|
141
|
+
- MUST expose tools to an agent by listing the tool name in the agent's `allowedTools`. Tools not on the whitelist never reach the model.
|
|
142
|
+
|
|
143
|
+
Run `yarn generate` after adding/changing tool definitions so the typed tool registry picks them up.
|
|
144
|
+
|
|
145
|
+
### How to Add a UI Part (record cards / custom inline widgets)
|
|
146
|
+
|
|
147
|
+
UI parts are typed inline widgets the agent streams into the chat. Two paths — pick the cheapest one that fits.
|
|
148
|
+
|
|
149
|
+
**Path A — record cards (no registration).** Five kinds ship out of the box: `product`, `deal`, `person`, `company`, `activity`. Add a `responseStyle` rule to the agent's prompt teaching the model to emit a fenced Markdown block whose info string is `open-mercato:<kind>` and whose body is one JSON object. The chat composer auto-parses the fence into a typed component. Reference: `packages/core/src/modules/customers/ai-agents.ts` (CRM cards) and `packages/core/src/modules/catalog/ai-agents.ts` (product cards). Card payload shapes live in `packages/ui/src/ai/records/types.ts`.
|
|
150
|
+
|
|
151
|
+
To add a brand-new record-card kind:
|
|
152
|
+
|
|
153
|
+
1. Add the payload type + the `RecordCardKind` union in `packages/ui/src/ai/records/types.ts`.
|
|
154
|
+
2. Implement the component (copy `ProductCard.tsx` or `PersonCard.tsx`; reuse `RecordCardShell` for header/leading/meta consistency).
|
|
155
|
+
3. Wire it into `packages/ui/src/ai/records/registry.tsx` so `RecordCard` resolves the kind.
|
|
156
|
+
4. Update the consuming agent's prompt with a fenced example.
|
|
157
|
+
5. Add an integration spec asserting `<AiMessageContent>` renders the new kind from a fenced sample.
|
|
158
|
+
|
|
159
|
+
**Path B — custom server-emitted parts.** For widgets that need server-only state (one-time signed URLs, action handlers, computed snapshots), register a stable namespaced component id and have the tool handler enqueue the part:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
// 1. component
|
|
163
|
+
'use client'
|
|
164
|
+
import { registerAiUiPart } from '@open-mercato/ui/ai'
|
|
165
|
+
registerAiUiPart('<module>:<kind>', YourComponent)
|
|
166
|
+
|
|
167
|
+
// 2. push from a tool's handler
|
|
168
|
+
async handler(args, ctx) {
|
|
169
|
+
ctx.uiParts?.enqueue({ componentId: '<module>:<kind>', props: { /* serializable */ } })
|
|
170
|
+
return { ok: true }
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
MUST rules for UI parts:
|
|
175
|
+
|
|
176
|
+
- 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.
|
|
177
|
+
- MUST keep props serializable (no functions, no class instances, no circular refs — the SSE encoder drops them).
|
|
178
|
+
- MUST gate any privileged action inside the part behind the same ACL features as the originating tool.
|
|
179
|
+
- MUST keep prompt instructions in sync with the tool — without a prompt rule the model will paraphrase instead of emitting the part.
|
|
180
|
+
|
|
181
|
+
Full reference: `apps/docs/docs/framework/ai-assistant/ui-parts.mdx`.
|
|
182
|
+
|
|
183
|
+
### How to Override or Extend Another Module's Agent or Tool
|
|
184
|
+
|
|
185
|
+
Modules can replace/disable any AI agent or AI tool that another module registered, or patch an existing agent by appending, deleting, or replacing allowed tools, system-prompt text, and starter suggestions. Use full overrides when you need to swap the whole behavior; use `aiAgentExtensions` when a downstream module only wants to adjust a shipped agent, such as adding "show catalog stats" while removing an irrelevant starter prompt. See spec `.ai/specs/2026-04-30-ai-overrides-and-module-disable.md` and `apps/docs/docs/framework/ai-assistant/overrides.mdx`.
|
|
186
|
+
|
|
187
|
+
There are three paths.
|
|
188
|
+
|
|
189
|
+
**Path A — extra exports on `<module>/ai-agents.ts` / `<module>/ai-tools.ts` (per-module file).** No separate `<module>/ai-overrides.ts` file. The generator already scans the existing `ai-agents.ts` / `ai-tools.ts` files; it now also picks up the optional `aiAgentOverrides` / `aiToolOverrides` exports and emits them as sibling `aiAgentOverrideEntries` / `aiToolOverrideEntries` arrays inside the same generated files.
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
// src/modules/<my-module>/ai-agents.ts
|
|
193
|
+
import type {
|
|
194
|
+
AiAgentDefinition,
|
|
195
|
+
AiAgentOverridesMap,
|
|
196
|
+
} from '@open-mercato/ai-assistant'
|
|
197
|
+
import myCustomMerchandisingAgent from './agents/my-merchandising-agent'
|
|
198
|
+
|
|
199
|
+
export const aiAgents: AiAgentDefinition[] = [
|
|
200
|
+
// ...your module's own agents
|
|
201
|
+
]
|
|
202
|
+
|
|
203
|
+
export const aiAgentOverrides: AiAgentOverridesMap = {
|
|
204
|
+
// Replace the default merchandising assistant with my variant.
|
|
205
|
+
'catalog.merchandising_assistant': myCustomMerchandisingAgent,
|
|
206
|
+
// Disable the default catalog explorer entirely.
|
|
207
|
+
'catalog.catalog_assistant': null,
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Agent extension patch:
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
import { defineAiAgentExtension } from '@open-mercato/ai-assistant'
|
|
215
|
+
|
|
216
|
+
export const aiAgentExtensions = [
|
|
217
|
+
defineAiAgentExtension({
|
|
218
|
+
targetAgentId: 'catalog.catalog_assistant',
|
|
219
|
+
deleteAllowedTools: ['catalog.old_stats'],
|
|
220
|
+
appendAllowedTools: ['example.catalog_stats'],
|
|
221
|
+
appendSystemPrompt: 'Use example.catalog_stats when the operator asks for catalog metrics.',
|
|
222
|
+
deleteSuggestions: ['Old catalog stats'],
|
|
223
|
+
appendSuggestions: [
|
|
224
|
+
{ label: 'Show catalog stats', prompt: 'Show catalog stats' },
|
|
225
|
+
],
|
|
226
|
+
}),
|
|
227
|
+
]
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Extension fields apply in deterministic order: `replace*` first, `delete*` second, `append*` last. Supported fields are `replaceAllowedTools` / `deleteAllowedTools` / `appendAllowedTools`, `replaceSystemPrompt` / `appendSystemPrompt`, and `replaceSuggestions` / `deleteSuggestions` / `appendSuggestions`. The legacy `suggestions` field is still accepted as an append alias.
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
// src/modules/<my-module>/ai-tools.ts
|
|
234
|
+
import { defineAiTool, type AiToolOverridesMap } from '@open-mercato/ai-assistant'
|
|
235
|
+
|
|
236
|
+
export const aiTools = [/* ...your module's own tools */]
|
|
237
|
+
|
|
238
|
+
export const aiToolOverrides: AiToolOverridesMap = {
|
|
239
|
+
'inbox_ops_accept_action': null,
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
**Path B — `modules.ts` inline (app-level static, unified `entry.overrides`).** Declare overrides under the umbrella `overrides.ai` key on a `ModuleEntry` inside `apps/<app>/src/modules.ts`. Other contracts a module presents (routes, events, workers, widgets, …) reuse the same `entry.overrides` shape per spec `.ai/specs/2026-05-04-modules-ts-unified-overrides.md` (AI is Phase 1; other domains roll out as separate PRs). The app's `bootstrap.ts` calls `applyModuleOverridesFromEnabledModules(enabledModules)` from `@open-mercato/shared/modules/overrides` once at boot — both `apps/mercato` and the `create-mercato-app` template ship that wiring.
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
// apps/<app>/src/modules.ts
|
|
247
|
+
{
|
|
248
|
+
id: 'example',
|
|
249
|
+
from: '@app',
|
|
250
|
+
overrides: {
|
|
251
|
+
ai: {
|
|
252
|
+
agents: { 'catalog.catalog_assistant': null },
|
|
253
|
+
tools: { 'inbox_ops_accept_action': null },
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
**Path C — programmatic API (boot-time / dynamic).** Call from `src/bootstrap.ts` or any boot-time entry point. Programmatic overrides supersede both `modules.ts` and file-based overrides for the same id and persist for the process lifetime.
|
|
260
|
+
|
|
261
|
+
```ts
|
|
262
|
+
import {
|
|
263
|
+
applyAiAgentOverrides,
|
|
264
|
+
applyAiToolOverrides,
|
|
265
|
+
} from '@open-mercato/ai-assistant'
|
|
266
|
+
|
|
267
|
+
applyAiAgentOverrides({
|
|
268
|
+
'catalog.catalog_assistant': null, // disable
|
|
269
|
+
})
|
|
270
|
+
applyAiToolOverrides({
|
|
271
|
+
'inbox_ops_accept_action': null, // disable a default tool
|
|
272
|
+
})
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
MUST rules:
|
|
276
|
+
|
|
277
|
+
- MUST keep override exports inside the existing `<module>/ai-agents.ts` / `<module>/ai-tools.ts` files (no separate `ai-overrides.ts` file is generated or scanned).
|
|
278
|
+
- MUST keep override values consistent with their map key — the value's `id` (agent) or `name` (tool) MUST equal the key. Mismatches log a warning and are skipped.
|
|
279
|
+
- MUST NOT use overrides to patch your own module's agent / tool — author the canonical definition in the same `ai-agents.ts` / `ai-tools.ts` `aiAgents` / `aiTools` array instead. The convention is for **cross-module** replacement.
|
|
280
|
+
- MUST run `yarn generate` after editing any `aiAgentOverrides` / `aiToolOverrides` export so the generated registry picks the change up.
|
|
281
|
+
- MUST run `yarn mercato configs cache structural --all-tenants` after disabling an agent so existing tenants flush stale nav/agent caches.
|
|
282
|
+
- MUST call `applyModuleOverridesFromEnabledModules(enabledModules)` from the app's `bootstrap.ts` if you use Path B (already wired in `apps/mercato` and the `create-mercato-app` template). Importing `@open-mercato/ai-assistant` also runs the side-effect that registers the AI domain applier with the dispatcher.
|
|
283
|
+
|
|
284
|
+
Resolution order (highest precedence first):
|
|
285
|
+
|
|
286
|
+
1. Programmatic `applyAiAgentOverrides` / `applyAiToolOverrides` calls (last call per id wins).
|
|
287
|
+
2. `modules.ts` inline (`aiAgentOverrides` / `aiToolOverrides` on `ModuleEntry`; last entry per id wins).
|
|
288
|
+
3. File-based `<module>/ai-agents.ts` / `<module>/ai-tools.ts` overrides (last module load order wins).
|
|
289
|
+
4. The base `<module>/ai-agents.ts` / `<module>/ai-tools.ts` registrations.
|
|
290
|
+
|
|
291
|
+
`null` always means "disable" — applies to all three paths.
|
|
292
|
+
|
|
293
|
+
### How to Embed the Global Launcher
|
|
294
|
+
|
|
295
|
+
The topbar AI launcher is mounted in `packages/ui/src/backend/AppShell.tsx`:
|
|
296
|
+
|
|
297
|
+
```tsx
|
|
298
|
+
import { AiAssistantLauncher } from '@open-mercato/ui/ai'
|
|
299
|
+
<AiAssistantLauncher variant="topbar" />
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
It self-fetches `/api/ai_assistant/health` and `/api/ai_assistant/ai/agents` and renders nothing when AI is not configured or the caller has access to no agents. It also binds the global **Cmd/Ctrl+L** keyboard shortcut (preventDefault'd against the browser address-bar binding). Standalone apps with custom chrome should mount the same component to expose the global launcher.
|
|
303
|
+
|
|
304
|
+
Full reference: `apps/docs/docs/framework/ai-assistant/launcher.mdx`.
|
|
305
|
+
|
|
306
|
+
### How to Configure AI Providers
|
|
307
|
+
|
|
308
|
+
The unified AI runtime picks the first configured provider from `llmProviderRegistry`. Configure providers via env variables:
|
|
309
|
+
|
|
310
|
+
| Variable | Provider | Default model |
|
|
311
|
+
|----------|----------|---------------|
|
|
312
|
+
| `ANTHROPIC_API_KEY` | Anthropic (Claude) | `claude-sonnet-4-20250514` |
|
|
313
|
+
| `OPENAI_API_KEY` | OpenAI | `gpt-4o-mini` |
|
|
314
|
+
| `GOOGLE_GENERATIVE_AI_API_KEY` | Google | `gemini-1.5-pro-latest` |
|
|
315
|
+
|
|
316
|
+
At least one MUST be set or the runtime throws `AiModelFactoryError` with `code: 'no_provider_configured'` on first invocation. See `/framework/ai-assistant/overview` for the full matrix.
|
|
317
|
+
|
|
318
|
+
Per-module model overrides use `<MODULE>_AI_MODEL` (uppercased from the agent's `moduleId`): for example, `CATALOG_AI_MODEL=claude-opus-4-20250514`, `INBOX_OPS_AI_MODEL=gpt-4o`.
|
|
319
|
+
|
|
320
|
+
All new callers MUST use `createModelFactory(container)` from `@open-mercato/ai-assistant/modules/ai_assistant/lib/model-factory` — never inline provider SDK calls (`createAnthropic`, `createOpenAI`, `createGoogleGenerativeAI`). The factory enforces the resolution order (caller override → `<MODULE>_AI_MODEL` → `agentDefaultModel` → provider default) and throws the documented `AiModelFactoryError` codes when misconfigured. See **Model Resolution** below.
|
|
321
|
+
|
|
80
322
|
## Architecture Constraints
|
|
81
323
|
|
|
82
324
|
When modifying this stack, follow these constraints:
|
|
@@ -247,6 +489,34 @@ Use 2 meta-tools instead of individual endpoint/schema tools. The AI writes Java
|
|
|
247
489
|
|
|
248
490
|
**When modifying Code Mode tools**: Edit `lib/codemode-tools.ts` for tool definitions, `lib/sandbox.ts` for the sandbox engine, `lib/truncate.ts` for response size limiting.
|
|
249
491
|
|
|
492
|
+
## Model Resolution
|
|
493
|
+
|
|
494
|
+
Use `createModelFactory(container)` from
|
|
495
|
+
`@open-mercato/ai-assistant/modules/ai_assistant/lib/model-factory` whenever a
|
|
496
|
+
runtime needs to materialize an AI SDK `LanguageModel` instance. The factory
|
|
497
|
+
consolidates what was previously duplicated across `inbox_ops/lib/llmProvider.ts`
|
|
498
|
+
and the agent-runtime's inline `resolveAgentModel`. Do NOT reintroduce ad-hoc
|
|
499
|
+
`createAnthropic` / `createOpenAI` / `createGoogleGenerativeAI` lookups in new
|
|
500
|
+
modules — route them through the factory instead.
|
|
501
|
+
|
|
502
|
+
Resolution order (highest precedence first):
|
|
503
|
+
|
|
504
|
+
1. `callerOverride` (non-empty string) — typically `runAiAgentText({ modelOverride })`.
|
|
505
|
+
2. `<MODULE>_AI_MODEL` env variable (uppercased from `moduleId`) —
|
|
506
|
+
e.g. `INBOX_OPS_AI_MODEL`, `CATALOG_AI_MODEL`. Internal convention;
|
|
507
|
+
no need to enumerate each one in `.env.example`.
|
|
508
|
+
3. `agentDefaultModel` (typically `AiAgentDefinition.defaultModel`).
|
|
509
|
+
4. The configured provider's own default (`llmProvider.defaultModel`).
|
|
510
|
+
|
|
511
|
+
The factory throws `AiModelFactoryError` with `code: 'no_provider_configured'`
|
|
512
|
+
when the registry has no configured provider and `code: 'api_key_missing'`
|
|
513
|
+
when the picked provider returns an empty key — every current call site
|
|
514
|
+
already relies on the throw bubbling up, do not swallow it.
|
|
515
|
+
|
|
516
|
+
The `agent-runtime.ts` inline `resolveAgentModel` will migrate to
|
|
517
|
+
`createModelFactory` in a follow-up Step (5.2+). New agents should accept
|
|
518
|
+
the factory-backed path from day one.
|
|
519
|
+
|
|
250
520
|
## MANDATORY: Use AskUserQuestion for Confirmations
|
|
251
521
|
|
|
252
522
|
> **This is the MOST IMPORTANT rule. NEVER skip this.**
|
|
@@ -484,6 +754,16 @@ yarn mcp:serve
|
|
|
484
754
|
| `ai_assistant.mcp_servers.view` | MUST require for viewing external MCP server configs |
|
|
485
755
|
| `ai_assistant.mcp_servers.manage` | MUST require for creating/editing/deleting MCP server configs |
|
|
486
756
|
|
|
757
|
+
## Workers
|
|
758
|
+
|
|
759
|
+
| Worker | Queue | Purpose |
|
|
760
|
+
|--------|-------|---------|
|
|
761
|
+
| `workers/ai-pending-action-cleanup` | `ai-pending-action-cleanup` | Scans every tenant for expired pending mutation approvals (`status = 'pending'` AND `expires_at < now`) and flips them to `expired` via the state-machine guard, emitting `ai.action.expired` per row. Race-safe: rows that concurrently transitioned (e.g., a confirm beat us) throw `AiPendingActionStateError` from the repo and are skipped without emitting. Runs on a 5-minute system-scope interval (registered by `setup.ts`). Manually invoked via `yarn mercato ai_assistant run-pending-action-cleanup`. Concurrency: 1. |
|
|
762
|
+
|
|
763
|
+
## Events
|
|
764
|
+
|
|
765
|
+
Typed pending-action lifecycle events live in `src/modules/ai_assistant/events.ts` and are emitted via the shared `emitAiAssistantEvent` helper (`createModuleEvents`). The three ids are FROZEN per `BACKWARD_COMPATIBILITY.md` §5 and MUST NOT be renamed; payload fields are additive-only. `ai.action.confirmed` fires from `executePendingActionConfirm` with `{ pendingActionId, agentId, toolName, status, tenantId, organizationId, userId, resolvedByUserId, resolvedAt, executionResult, failedRecords? }`; `ai.action.cancelled` fires from `executePendingActionCancel` with the same shape plus an optional `reason`; `ai.action.expired` fires from the cancel helper's TTL short-circuit (and the Step 5.12 cleanup worker) with `resolvedByUserId: null` and additional `expiresAt` / `expiredAt` timestamps. All three use `category: 'system'` and `entity: 'ai_pending_action'`.
|
|
766
|
+
|
|
487
767
|
## Rules for the OpenCode Client
|
|
488
768
|
|
|
489
769
|
Located in `lib/opencode-client.ts`. Use these methods when interacting with OpenCode:
|
|
@@ -1156,6 +1436,87 @@ See git history for earlier changes including:
|
|
|
1156
1436
|
|
|
1157
1437
|
---
|
|
1158
1438
|
|
|
1439
|
+
## Upgrading / Operator rollout notes
|
|
1440
|
+
|
|
1441
|
+
This section captures what existing deployments need to know when picking up the **AI Framework Unification** release (#1593, spec [`2026-04-11-unified-ai-tooling-and-subagents`](../../.ai/specs/implemented/2026-04-11-unified-ai-tooling-and-subagents.md)). All changes are additive; no runtime contract was renamed or removed.
|
|
1442
|
+
|
|
1443
|
+
### New environment variables
|
|
1444
|
+
|
|
1445
|
+
| Variable | Default | Purpose |
|
|
1446
|
+
|----------|---------|---------|
|
|
1447
|
+
| `AI_PENDING_ACTION_TTL_SECONDS` | `900` (15 minutes) | Expiry window for pending mutation approvals. After this window the cleanup worker flips `status = 'pending'` rows whose `expires_at < now` to `expired` and emits `ai.action.expired`. |
|
|
1448
|
+
| `<MODULE>_AI_MODEL` | unset | Per-module model override, uppercased from the module id. Examples: `INBOX_OPS_AI_MODEL`, `CATALOG_AI_MODEL`. Internal convention — no need to enumerate each one in `.env.example`. Resolution order: caller override → this env var → `agentDefaultModel` → configured provider's default. |
|
|
1449
|
+
|
|
1450
|
+
### New database table
|
|
1451
|
+
|
|
1452
|
+
- Migration `Migration20260419134235_ai_assistant` lands automatically on `yarn db:migrate`. It adds the additive `ai_pending_actions` table that backs the mutation approval gate.
|
|
1453
|
+
- No data migration is needed. Existing rows in other tables are untouched.
|
|
1454
|
+
- The runtime gracefully falls back if the table is absent (the mutation gate fails closed rather than blocking the app build).
|
|
1455
|
+
|
|
1456
|
+
### New cleanup worker registration
|
|
1457
|
+
|
|
1458
|
+
- Worker id: `ai_assistant:pending-action-cleanup` (queue: `ai-pending-action-cleanup`, concurrency: `1`, interval: 5 minutes system-scope).
|
|
1459
|
+
- Auto-registered via the module's `setup.ts` `seedDefaults`. For existing tenants the worker activates once structural cache is refreshed:
|
|
1460
|
+
|
|
1461
|
+
```bash
|
|
1462
|
+
yarn mercato configs cache structural --all-tenants
|
|
1463
|
+
```
|
|
1464
|
+
|
|
1465
|
+
- Manual invocation (useful when debugging or running outside the scheduler):
|
|
1466
|
+
|
|
1467
|
+
```bash
|
|
1468
|
+
yarn mercato ai_assistant run-pending-action-cleanup
|
|
1469
|
+
```
|
|
1470
|
+
|
|
1471
|
+
- See the **Workers** section above for the full description.
|
|
1472
|
+
|
|
1473
|
+
### New prompt-override + mutation-policy-override tables
|
|
1474
|
+
|
|
1475
|
+
- Additive tables: `ai_agent_prompt_overrides`, `ai_agent_mutation_policy_overrides`.
|
|
1476
|
+
- Both are feature-gated behind `ai_assistant.settings.manage` (standard ACL feature). Operators who don't want the settings UI exposed can remove that feature from role grants — the UI hides itself and the runtime falls back to agent defaults.
|
|
1477
|
+
- Prompt overrides are versioned with safe additive merge rules (see Step 5.3 of the spec).
|
|
1478
|
+
- Mutation-policy overrides can NEVER escalate an agent's `mutationPolicy` above what the agent definition declares — the runtime re-checks on every confirm call and refuses at the pending-action gate.
|
|
1479
|
+
|
|
1480
|
+
### Backward-compatibility posture
|
|
1481
|
+
|
|
1482
|
+
- `packages/core/src/modules/inbox_ops/lib/llmProvider.ts` keeps its public API. The implementation now delegates to `createModelFactory(container)` (see **Model Resolution** above), so callers don't change.
|
|
1483
|
+
- No existing event IDs, API routes, widget injection spot IDs, DI service names, ACL feature IDs, notification type IDs, CLI commands, or generated file contracts were renamed or removed.
|
|
1484
|
+
- New routes are namespaced under `/api/ai_assistant/ai/...` and `/api/ai/actions/:id/...`; they do not collide with the existing OpenCode Code Mode routes.
|
|
1485
|
+
|
|
1486
|
+
### Coexistence with OpenCode Code Mode
|
|
1487
|
+
|
|
1488
|
+
The AI framework unification **does not replace OpenCode Code Mode.** Both stacks run side-by-side and can be enabled independently per tenant and per agent.
|
|
1489
|
+
|
|
1490
|
+
| Surface | OpenCode Code Mode (unchanged) | New AI Framework |
|
|
1491
|
+
|---------|--------------------------------|------------------|
|
|
1492
|
+
| Chat entrypoint | `POST /api/chat` (SSE, OpenCode in Docker) | `POST /api/ai_assistant/ai/chat?agent=<module>.<agent>` (typed agent dispatcher) |
|
|
1493
|
+
| Tool discovery | `/api/tools`, `/api/tools/execute` (2 meta-tools: `search` + `execute`) | Typed tool packs (`search.*`, `attachments.*`, `meta.*`, customers, catalog) registered via `defineAiTool()` |
|
|
1494
|
+
| CLI | `mcp:serve`, `mcp:serve-http`, `mcp:dev` | (none — the dispatcher is an HTTP route, not an MCP process) |
|
|
1495
|
+
| UI | Raycast-style Command Palette (`Cmd+K`) | `<AiChat>` component, playground page, agent settings page |
|
|
1496
|
+
| Mutation approvals | N/A (tool call → tool result) | `ai_pending_actions` + approval cards (`mutation-preview-card` / `field-diff-card` / `confirmation-card` / `mutation-result-card`) |
|
|
1497
|
+
| Demo | General-purpose chat | D18 `catalog.merchandising_assistant` on `/backend/catalog/catalog/products` |
|
|
1498
|
+
|
|
1499
|
+
Operators who don't want the new surfaces can:
|
|
1500
|
+
|
|
1501
|
+
- remove `ai_assistant.settings.manage` from role grants to hide the settings UI, **or**
|
|
1502
|
+
- omit individual agents from a tenant via the mutation-policy override table (see Step 5.4), **or**
|
|
1503
|
+
- simply not mount `<AiChat>` anywhere in custom UIs — the runtime does not activate until an agent is invoked.
|
|
1504
|
+
|
|
1505
|
+
Tenants who want both keep OpenCode Code Mode for ad-hoc chat and Code-Mode-style exploration, and use the new framework for focused, mutation-capable agents (e.g., `customers.account_assistant`, `catalog.merchandising_assistant`) with the D16 pending-action contract.
|
|
1506
|
+
|
|
1507
|
+
### Operator QA checklist (D18 demo)
|
|
1508
|
+
|
|
1509
|
+
For a live end-to-end walkthrough against a real LLM:
|
|
1510
|
+
|
|
1511
|
+
1. Set `AI_PENDING_ACTION_TTL_SECONDS=900`, your chosen provider env vars (e.g., `ANTHROPIC_API_KEY`), and optional `CATALOG_AI_MODEL`.
|
|
1512
|
+
2. Run `yarn db:migrate` to pick up `Migration20260419134235_ai_assistant`.
|
|
1513
|
+
3. Run `yarn mercato configs cache structural --all-tenants` to register the cleanup worker on existing tenants.
|
|
1514
|
+
4. Open `/backend/catalog/catalog/products`, pick a handful of rows, open the `<AiChat>` sheet, and walk through each of the four named use cases (description drafting, attribute extraction, title variants, price adjustment suggestion).
|
|
1515
|
+
5. Confirm the proposal card shows a single `[Confirm All]` approval and that after confirmation the DataTable refreshes via the DOM event bridge as `catalog.product.updated` events arrive per record.
|
|
1516
|
+
6. Force a partial-success case (e.g., stale-version on one row) and confirm the result card renders the mixed outcome correctly.
|
|
1517
|
+
|
|
1518
|
+
---
|
|
1519
|
+
|
|
1159
1520
|
## Future Development
|
|
1160
1521
|
|
|
1161
1522
|
Refer to git history and specs for planned features:
|
package/README.md
CHANGED
|
@@ -8,6 +8,11 @@ AI-powered chat and tool execution for Open Mercato, using MCP (Model Context Pr
|
|
|
8
8
|
- **MCP Server**: Exposes platform tools to AI agents via Model Context Protocol
|
|
9
9
|
- **API Discovery**: Meta-tools (`api_discover`, `api_execute`, `api_schema`) for dynamic API access
|
|
10
10
|
- **OpenCode Integration**: Go-based AI backend for processing requests and executing tools
|
|
11
|
+
- **Typed Agent Framework** *(new — 2026-04-18)*: `AiAgentDefinition` + `defineAiTool()`, generated `ai-agents.generated.ts` discovery, dispatcher route `POST /api/ai_assistant/ai/chat?agent=<module>.<agent>`, AI SDK helpers (`createAiAgentTransport`, `runAiAgentText`, `runAiAgentObject`), attachment bridge, and tool packs for customers + catalog — see the spec at [`.ai/specs/implemented/2026-04-11-unified-ai-tooling-and-subagents.md`](../../.ai/specs/implemented/2026-04-11-unified-ai-tooling-and-subagents.md)
|
|
12
|
+
- **Mutation Approval Gate (D16)** *(new — 2026-04-18)*: additive `ai_pending_actions` table, `prepareMutation` runtime wrapper, three pending-action routes (`GET` / `confirm` / `cancel`), four new UI parts (`mutation-preview-card`, `field-diff-card`, `confirmation-card`, `mutation-result-card`), typed `ai.action.{confirmed,cancelled,expired}` events, and a cleanup worker for expired approvals — see the **Upgrading / Operator rollout notes** section in [`AGENTS.md`](./AGENTS.md)
|
|
13
|
+
- **Playground + Settings**: `/backend/config/ai-assistant/playground` (agent picker + debug + object-mode) and `/backend/config/ai-assistant/agents` (versioned prompt overrides + feature-gated `mutationPolicy`)
|
|
14
|
+
|
|
15
|
+
Both stacks coexist: OpenCode Code Mode keeps powering the Command Palette and `/api/chat` unchanged; the new typed framework adds focused, mutation-capable agents alongside it.
|
|
11
16
|
|
|
12
17
|
## Quick Start
|
|
13
18
|
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
export * from "./modules/ai_assistant/lib/types.js";
|
|
2
|
+
import {
|
|
3
|
+
defineAiAgent,
|
|
4
|
+
defineAiAgentExtension
|
|
5
|
+
} from "./modules/ai_assistant/lib/ai-agent-definition.js";
|
|
6
|
+
import { defineAiTool } from "./modules/ai_assistant/lib/ai-tool-definition.js";
|
|
7
|
+
import {
|
|
8
|
+
definePromptTemplate
|
|
9
|
+
} from "./modules/ai_assistant/lib/prompt-composition-types.js";
|
|
2
10
|
import {
|
|
3
11
|
registerMcpTool,
|
|
4
12
|
getToolRegistry,
|
|
@@ -13,6 +21,93 @@ import {
|
|
|
13
21
|
extractApiKeyFromHeaders
|
|
14
22
|
} from "./modules/ai_assistant/lib/auth.js";
|
|
15
23
|
import { loadAllModuleTools, indexToolsForSearch } from "./modules/ai_assistant/lib/tool-loader.js";
|
|
24
|
+
import {
|
|
25
|
+
applyAiAgentOverrides,
|
|
26
|
+
applyAiAgentExtensions,
|
|
27
|
+
applyAiToolOverrides,
|
|
28
|
+
applyAiOverridesFromEnabledModules,
|
|
29
|
+
resetProgrammaticOverridesForTests
|
|
30
|
+
} from "./modules/ai_assistant/lib/ai-overrides.js";
|
|
31
|
+
import {
|
|
32
|
+
loadAgentRegistry,
|
|
33
|
+
getAgent,
|
|
34
|
+
listAgents,
|
|
35
|
+
listAgentsByModule,
|
|
36
|
+
resetAgentRegistryForTests
|
|
37
|
+
} from "./modules/ai_assistant/lib/agent-registry.js";
|
|
38
|
+
import {
|
|
39
|
+
checkAgentPolicy
|
|
40
|
+
} from "./modules/ai_assistant/lib/agent-policy.js";
|
|
41
|
+
import {
|
|
42
|
+
resolveAiAgentTools,
|
|
43
|
+
AgentPolicyError
|
|
44
|
+
} from "./modules/ai_assistant/lib/agent-tools.js";
|
|
45
|
+
import {
|
|
46
|
+
createAiApiOperationRunner
|
|
47
|
+
} from "./modules/ai_assistant/lib/ai-api-operation-runner.js";
|
|
48
|
+
import {
|
|
49
|
+
defineApiBackedAiTool
|
|
50
|
+
} from "./modules/ai_assistant/lib/api-backed-tool.js";
|
|
51
|
+
import {
|
|
52
|
+
prepareMutation,
|
|
53
|
+
computeMutationIdempotencyKey,
|
|
54
|
+
AiMutationPreparationError,
|
|
55
|
+
MUTATION_PREVIEW_CARD_COMPONENT
|
|
56
|
+
} from "./modules/ai_assistant/lib/prepare-mutation.js";
|
|
57
|
+
import {
|
|
58
|
+
runAiAgentText,
|
|
59
|
+
runAiAgentObject,
|
|
60
|
+
composeSystemPrompt
|
|
61
|
+
} from "./modules/ai_assistant/lib/agent-runtime.js";
|
|
62
|
+
import {
|
|
63
|
+
createAiAgentTransport
|
|
64
|
+
} from "./modules/ai_assistant/lib/agent-transport.js";
|
|
65
|
+
import {
|
|
66
|
+
AI_PENDING_ACTION_STATUSES,
|
|
67
|
+
AI_PENDING_ACTION_QUEUE_MODES,
|
|
68
|
+
AI_PENDING_ACTION_ALLOWED_TRANSITIONS,
|
|
69
|
+
AI_PENDING_ACTION_TERMINAL_STATUSES,
|
|
70
|
+
AI_PENDING_ACTION_DEFAULT_TTL_SECONDS,
|
|
71
|
+
AI_PENDING_ACTION_TTL_ENV_VAR,
|
|
72
|
+
AiPendingActionStateError,
|
|
73
|
+
isAiPendingActionStatus,
|
|
74
|
+
isAiPendingActionQueueMode,
|
|
75
|
+
isTerminalAiPendingActionStatus,
|
|
76
|
+
isAllowedAiPendingActionTransition,
|
|
77
|
+
resolveAiPendingActionTtlSeconds
|
|
78
|
+
} from "./modules/ai_assistant/lib/pending-action-types.js";
|
|
79
|
+
import {
|
|
80
|
+
serializePendingActionForClient
|
|
81
|
+
} from "./modules/ai_assistant/lib/pending-action-client.js";
|
|
82
|
+
import {
|
|
83
|
+
runPendingActionRechecks,
|
|
84
|
+
checkStatusAndExpiry,
|
|
85
|
+
checkAgentAndFeatures,
|
|
86
|
+
checkToolWhitelist,
|
|
87
|
+
checkAttachmentScope,
|
|
88
|
+
checkRecordVersion,
|
|
89
|
+
PENDING_ACTION_RECHECK_CODES,
|
|
90
|
+
isPendingActionRecheckCode
|
|
91
|
+
} from "./modules/ai_assistant/lib/pending-action-recheck.js";
|
|
92
|
+
import {
|
|
93
|
+
executePendingActionConfirm,
|
|
94
|
+
PENDING_ACTION_CONFIRMED_EVENT_ID
|
|
95
|
+
} from "./modules/ai_assistant/lib/pending-action-executor.js";
|
|
96
|
+
import {
|
|
97
|
+
executePendingActionCancel,
|
|
98
|
+
PENDING_ACTION_CANCELLED_EVENT_ID,
|
|
99
|
+
PENDING_ACTION_EXPIRED_EVENT_ID
|
|
100
|
+
} from "./modules/ai_assistant/lib/pending-action-cancel.js";
|
|
101
|
+
import {
|
|
102
|
+
createModelFactory,
|
|
103
|
+
AiModelFactoryError
|
|
104
|
+
} from "./modules/ai_assistant/lib/model-factory.js";
|
|
105
|
+
import {
|
|
106
|
+
resolveAttachmentParts,
|
|
107
|
+
resolveAttachmentPartsForAgent,
|
|
108
|
+
attachmentPartsToUiFileParts,
|
|
109
|
+
summarizeAttachmentPartsForPrompt
|
|
110
|
+
} from "./modules/ai_assistant/lib/attachment-parts.js";
|
|
16
111
|
import {
|
|
17
112
|
OpenCodeClient,
|
|
18
113
|
createOpenCodeClient
|
|
@@ -29,16 +124,55 @@ import {
|
|
|
29
124
|
} from "./modules/ai_assistant/lib/opencode-handlers.js";
|
|
30
125
|
import { metadata, features } from "./modules/ai_assistant/index.js";
|
|
31
126
|
export {
|
|
127
|
+
AI_PENDING_ACTION_ALLOWED_TRANSITIONS,
|
|
128
|
+
AI_PENDING_ACTION_DEFAULT_TTL_SECONDS,
|
|
129
|
+
AI_PENDING_ACTION_QUEUE_MODES,
|
|
130
|
+
AI_PENDING_ACTION_STATUSES,
|
|
131
|
+
AI_PENDING_ACTION_TERMINAL_STATUSES,
|
|
132
|
+
AI_PENDING_ACTION_TTL_ENV_VAR,
|
|
133
|
+
AgentPolicyError,
|
|
134
|
+
AiModelFactoryError,
|
|
135
|
+
AiMutationPreparationError,
|
|
136
|
+
AiPendingActionStateError,
|
|
137
|
+
MUTATION_PREVIEW_CARD_COMPONENT,
|
|
32
138
|
OpenCodeClient,
|
|
139
|
+
PENDING_ACTION_CANCELLED_EVENT_ID,
|
|
140
|
+
PENDING_ACTION_CONFIRMED_EVENT_ID,
|
|
141
|
+
PENDING_ACTION_EXPIRED_EVENT_ID,
|
|
142
|
+
PENDING_ACTION_RECHECK_CODES,
|
|
143
|
+
applyAiAgentExtensions,
|
|
144
|
+
applyAiAgentOverrides,
|
|
145
|
+
applyAiOverridesFromEnabledModules,
|
|
146
|
+
applyAiToolOverrides,
|
|
147
|
+
attachmentPartsToUiFileParts,
|
|
33
148
|
authenticateMcpRequest,
|
|
149
|
+
checkAgentAndFeatures,
|
|
150
|
+
checkAgentPolicy,
|
|
151
|
+
checkAttachmentScope,
|
|
152
|
+
checkRecordVersion,
|
|
153
|
+
checkStatusAndExpiry,
|
|
154
|
+
checkToolWhitelist,
|
|
155
|
+
composeSystemPrompt,
|
|
156
|
+
computeMutationIdempotencyKey,
|
|
157
|
+
createAiAgentTransport,
|
|
158
|
+
createAiApiOperationRunner,
|
|
34
159
|
createMcpServer,
|
|
160
|
+
createModelFactory,
|
|
35
161
|
createOpenCodeClient,
|
|
162
|
+
defineAiAgent,
|
|
163
|
+
defineAiAgentExtension,
|
|
164
|
+
defineAiTool,
|
|
165
|
+
defineApiBackedAiTool,
|
|
166
|
+
definePromptTemplate,
|
|
167
|
+
executePendingActionCancel,
|
|
168
|
+
executePendingActionConfirm,
|
|
36
169
|
executeTool,
|
|
37
170
|
extractAllPartsFromResponse,
|
|
38
171
|
extractApiKeyFromHeaders,
|
|
39
172
|
extractMetadataFromResponse,
|
|
40
173
|
extractTextFromResponse,
|
|
41
174
|
features,
|
|
175
|
+
getAgent,
|
|
42
176
|
getPendingQuestions,
|
|
43
177
|
getToolRegistry,
|
|
44
178
|
handleOpenCodeAnswer,
|
|
@@ -46,11 +180,31 @@ export {
|
|
|
46
180
|
handleOpenCodeMessage,
|
|
47
181
|
handleOpenCodeMessageStreaming,
|
|
48
182
|
indexToolsForSearch,
|
|
183
|
+
isAiPendingActionQueueMode,
|
|
184
|
+
isAiPendingActionStatus,
|
|
185
|
+
isAllowedAiPendingActionTransition,
|
|
186
|
+
isPendingActionRecheckCode,
|
|
187
|
+
isTerminalAiPendingActionStatus,
|
|
188
|
+
listAgents,
|
|
189
|
+
listAgentsByModule,
|
|
190
|
+
loadAgentRegistry,
|
|
49
191
|
loadAllModuleTools,
|
|
50
192
|
metadata,
|
|
193
|
+
prepareMutation,
|
|
51
194
|
registerMcpTool,
|
|
195
|
+
resetAgentRegistryForTests,
|
|
196
|
+
resetProgrammaticOverridesForTests,
|
|
197
|
+
resolveAiAgentTools,
|
|
198
|
+
resolveAiPendingActionTtlSeconds,
|
|
199
|
+
resolveAttachmentParts,
|
|
200
|
+
resolveAttachmentPartsForAgent,
|
|
201
|
+
runAiAgentObject,
|
|
202
|
+
runAiAgentText,
|
|
52
203
|
runMcpHttpServer,
|
|
53
204
|
runMcpServer,
|
|
205
|
+
runPendingActionRechecks,
|
|
206
|
+
serializePendingActionForClient,
|
|
207
|
+
summarizeAttachmentPartsForPrompt,
|
|
54
208
|
toolRegistry,
|
|
55
209
|
unregisterMcpTool
|
|
56
210
|
};
|
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// 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// 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 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} 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,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,mBAAmB;AAG5B,SAAS,iBAAiB,oBAAoB;AAG9C,SAAS,wBAAmD;AAG5D;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAGP,SAAS,oBAAoB,2BAA2B;
|
|
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 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 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} 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,OAWK;AAGP,SAAS,oBAAoB;AAW7B;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;AAG5D;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,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,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,OAQK;AAGP,SAAS,UAAU,gBAAgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|