@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
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import type { AiAgentDefinition } from '../ai-agent-definition'
|
|
3
|
+
import type { AiToolDefinition } from '../types'
|
|
4
|
+
import {
|
|
5
|
+
checkAgentPolicy,
|
|
6
|
+
isMutationPolicyEscalation,
|
|
7
|
+
resolveEffectiveMutationPolicy,
|
|
8
|
+
} from '../agent-policy'
|
|
9
|
+
import { resetAgentRegistryForTests, seedAgentRegistryForTests } from '../agent-registry'
|
|
10
|
+
import { registerMcpTool, toolRegistry } from '../tool-registry'
|
|
11
|
+
|
|
12
|
+
function makeAgent(
|
|
13
|
+
overrides: Partial<AiAgentDefinition> & Pick<AiAgentDefinition, 'id' | 'moduleId'>,
|
|
14
|
+
): AiAgentDefinition {
|
|
15
|
+
return {
|
|
16
|
+
label: `${overrides.id} label`,
|
|
17
|
+
description: `${overrides.id} description`,
|
|
18
|
+
systemPrompt: 'You are a test agent.',
|
|
19
|
+
allowedTools: [],
|
|
20
|
+
...overrides,
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function makeTool(
|
|
25
|
+
overrides: Partial<AiToolDefinition> & Pick<AiToolDefinition, 'name'>,
|
|
26
|
+
): AiToolDefinition {
|
|
27
|
+
return {
|
|
28
|
+
description: `${overrides.name} description`,
|
|
29
|
+
inputSchema: z.object({}),
|
|
30
|
+
handler: async () => ({ ok: true }),
|
|
31
|
+
...overrides,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const baseAuth = { userFeatures: ['*'] as string[], isSuperAdmin: false }
|
|
36
|
+
|
|
37
|
+
describe('agent-policy mutation override (Step 5.4)', () => {
|
|
38
|
+
let warnSpy: jest.SpyInstance
|
|
39
|
+
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
resetAgentRegistryForTests()
|
|
42
|
+
toolRegistry.clear()
|
|
43
|
+
warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {})
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
afterEach(() => {
|
|
47
|
+
warnSpy.mockRestore()
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
afterAll(() => {
|
|
51
|
+
resetAgentRegistryForTests()
|
|
52
|
+
toolRegistry.clear()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
describe('resolveEffectiveMutationPolicy', () => {
|
|
56
|
+
it('returns the code-declared policy when no override is given', () => {
|
|
57
|
+
expect(resolveEffectiveMutationPolicy('confirm-required', undefined)).toBe(
|
|
58
|
+
'confirm-required',
|
|
59
|
+
)
|
|
60
|
+
expect(resolveEffectiveMutationPolicy('confirm-required', null)).toBe(
|
|
61
|
+
'confirm-required',
|
|
62
|
+
)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('defaults to read-only when the code-declared policy is missing', () => {
|
|
66
|
+
expect(resolveEffectiveMutationPolicy(undefined, undefined)).toBe('read-only')
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('picks the MOST RESTRICTIVE of { code, override }', () => {
|
|
70
|
+
expect(
|
|
71
|
+
resolveEffectiveMutationPolicy('confirm-required', 'read-only'),
|
|
72
|
+
).toBe('read-only')
|
|
73
|
+
expect(
|
|
74
|
+
resolveEffectiveMutationPolicy('confirm-required', 'destructive-confirm-required'),
|
|
75
|
+
).toBe('destructive-confirm-required')
|
|
76
|
+
expect(
|
|
77
|
+
resolveEffectiveMutationPolicy('destructive-confirm-required', 'read-only'),
|
|
78
|
+
).toBe('read-only')
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('never allows an override to ESCALATE the policy', () => {
|
|
82
|
+
// Override is more permissive than code — resolver keeps the code value.
|
|
83
|
+
expect(
|
|
84
|
+
resolveEffectiveMutationPolicy('read-only', 'confirm-required'),
|
|
85
|
+
).toBe('read-only')
|
|
86
|
+
expect(
|
|
87
|
+
resolveEffectiveMutationPolicy('destructive-confirm-required', 'confirm-required'),
|
|
88
|
+
).toBe('destructive-confirm-required')
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('falls back to the code-declared policy when the override value is unknown', () => {
|
|
92
|
+
const result = resolveEffectiveMutationPolicy(
|
|
93
|
+
'confirm-required',
|
|
94
|
+
'write-capable' as never,
|
|
95
|
+
'catalog.assistant',
|
|
96
|
+
)
|
|
97
|
+
expect(result).toBe('confirm-required')
|
|
98
|
+
expect(warnSpy).toHaveBeenCalled()
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
describe('isMutationPolicyEscalation', () => {
|
|
103
|
+
it('flags widenings as escalations', () => {
|
|
104
|
+
expect(isMutationPolicyEscalation('read-only', 'confirm-required')).toBe(true)
|
|
105
|
+
expect(
|
|
106
|
+
isMutationPolicyEscalation('read-only', 'destructive-confirm-required'),
|
|
107
|
+
).toBe(true)
|
|
108
|
+
expect(
|
|
109
|
+
isMutationPolicyEscalation('destructive-confirm-required', 'confirm-required'),
|
|
110
|
+
).toBe(true)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('does not flag same-level or downgrades', () => {
|
|
114
|
+
expect(isMutationPolicyEscalation('confirm-required', 'confirm-required')).toBe(false)
|
|
115
|
+
expect(isMutationPolicyEscalation('confirm-required', 'read-only')).toBe(false)
|
|
116
|
+
expect(
|
|
117
|
+
isMutationPolicyEscalation('confirm-required', 'destructive-confirm-required'),
|
|
118
|
+
).toBe(false)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it('treats a missing code-declared policy as read-only (strict)', () => {
|
|
122
|
+
expect(isMutationPolicyEscalation(undefined, 'confirm-required')).toBe(true)
|
|
123
|
+
expect(isMutationPolicyEscalation(undefined, 'read-only')).toBe(false)
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
describe('checkAgentPolicy uses the effective policy', () => {
|
|
128
|
+
it('blocks mutation when override downgrades a write-capable agent to read-only', () => {
|
|
129
|
+
registerMcpTool(makeTool({ name: 'customers_update', isMutation: true }), {
|
|
130
|
+
moduleId: 'customers',
|
|
131
|
+
})
|
|
132
|
+
seedAgentRegistryForTests([
|
|
133
|
+
makeAgent({
|
|
134
|
+
id: 'customers.assistant',
|
|
135
|
+
moduleId: 'customers',
|
|
136
|
+
allowedTools: ['customers_update'],
|
|
137
|
+
readOnly: false,
|
|
138
|
+
mutationPolicy: 'confirm-required',
|
|
139
|
+
}),
|
|
140
|
+
])
|
|
141
|
+
|
|
142
|
+
const decision = checkAgentPolicy({
|
|
143
|
+
agentId: 'customers.assistant',
|
|
144
|
+
authContext: baseAuth,
|
|
145
|
+
toolName: 'customers_update',
|
|
146
|
+
mutationPolicyOverride: 'read-only',
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
expect(decision.ok).toBe(false)
|
|
150
|
+
if (!decision.ok) {
|
|
151
|
+
expect(decision.code).toBe('mutation_blocked_by_policy')
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('keeps the code-declared policy when no override is supplied', () => {
|
|
156
|
+
registerMcpTool(makeTool({ name: 'customers_update', isMutation: true }), {
|
|
157
|
+
moduleId: 'customers',
|
|
158
|
+
})
|
|
159
|
+
seedAgentRegistryForTests([
|
|
160
|
+
makeAgent({
|
|
161
|
+
id: 'customers.assistant',
|
|
162
|
+
moduleId: 'customers',
|
|
163
|
+
allowedTools: ['customers_update'],
|
|
164
|
+
readOnly: false,
|
|
165
|
+
mutationPolicy: 'confirm-required',
|
|
166
|
+
}),
|
|
167
|
+
])
|
|
168
|
+
|
|
169
|
+
const decision = checkAgentPolicy({
|
|
170
|
+
agentId: 'customers.assistant',
|
|
171
|
+
authContext: baseAuth,
|
|
172
|
+
toolName: 'customers_update',
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
expect(decision.ok).toBe(true)
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
it('ignores a corrupt override value and falls back to the code-declared policy', () => {
|
|
179
|
+
registerMcpTool(makeTool({ name: 'customers_update', isMutation: true }), {
|
|
180
|
+
moduleId: 'customers',
|
|
181
|
+
})
|
|
182
|
+
seedAgentRegistryForTests([
|
|
183
|
+
makeAgent({
|
|
184
|
+
id: 'customers.assistant',
|
|
185
|
+
moduleId: 'customers',
|
|
186
|
+
allowedTools: ['customers_update'],
|
|
187
|
+
readOnly: false,
|
|
188
|
+
mutationPolicy: 'confirm-required',
|
|
189
|
+
}),
|
|
190
|
+
])
|
|
191
|
+
|
|
192
|
+
const decision = checkAgentPolicy({
|
|
193
|
+
agentId: 'customers.assistant',
|
|
194
|
+
authContext: baseAuth,
|
|
195
|
+
toolName: 'customers_update',
|
|
196
|
+
mutationPolicyOverride: 'write-capable' as never,
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
expect(decision.ok).toBe(true)
|
|
200
|
+
expect(warnSpy).toHaveBeenCalled()
|
|
201
|
+
})
|
|
202
|
+
})
|
|
203
|
+
})
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import type { AiAgentDefinition } from '../ai-agent-definition'
|
|
3
|
+
import type { AiToolDefinition } from '../types'
|
|
4
|
+
import { checkAgentPolicy } from '../agent-policy'
|
|
5
|
+
import { resetAgentRegistryForTests, seedAgentRegistryForTests } from '../agent-registry'
|
|
6
|
+
import { toolRegistry, registerMcpTool } from '../tool-registry'
|
|
7
|
+
|
|
8
|
+
function makeAgent(
|
|
9
|
+
overrides: Partial<AiAgentDefinition> & Pick<AiAgentDefinition, 'id' | 'moduleId'>
|
|
10
|
+
): AiAgentDefinition {
|
|
11
|
+
return {
|
|
12
|
+
label: `${overrides.id} label`,
|
|
13
|
+
description: `${overrides.id} description`,
|
|
14
|
+
systemPrompt: 'You are a test agent.',
|
|
15
|
+
allowedTools: [],
|
|
16
|
+
...overrides,
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function makeTool(
|
|
21
|
+
overrides: Partial<AiToolDefinition> & Pick<AiToolDefinition, 'name'>
|
|
22
|
+
): AiToolDefinition {
|
|
23
|
+
return {
|
|
24
|
+
description: `${overrides.name} description`,
|
|
25
|
+
inputSchema: z.object({}),
|
|
26
|
+
handler: async () => ({ ok: true }),
|
|
27
|
+
...overrides,
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const baseAuth = { userFeatures: [] as string[], isSuperAdmin: false }
|
|
32
|
+
|
|
33
|
+
describe('agent-policy', () => {
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
resetAgentRegistryForTests()
|
|
36
|
+
toolRegistry.clear()
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
afterAll(() => {
|
|
40
|
+
resetAgentRegistryForTests()
|
|
41
|
+
toolRegistry.clear()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('returns agent_unknown when the agent id does not resolve', () => {
|
|
45
|
+
const decision = checkAgentPolicy({
|
|
46
|
+
agentId: 'missing.agent',
|
|
47
|
+
authContext: { userFeatures: ['*'], isSuperAdmin: true },
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
expect(decision.ok).toBe(false)
|
|
51
|
+
if (!decision.ok) expect(decision.code).toBe('agent_unknown')
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('returns agent_features_denied when user lacks required features', () => {
|
|
55
|
+
seedAgentRegistryForTests([
|
|
56
|
+
makeAgent({
|
|
57
|
+
id: 'customers.assistant',
|
|
58
|
+
moduleId: 'customers',
|
|
59
|
+
requiredFeatures: ['customers.assistant.use'],
|
|
60
|
+
}),
|
|
61
|
+
])
|
|
62
|
+
|
|
63
|
+
const decision = checkAgentPolicy({
|
|
64
|
+
agentId: 'customers.assistant',
|
|
65
|
+
authContext: { userFeatures: ['catalog.view'], isSuperAdmin: false },
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
expect(decision.ok).toBe(false)
|
|
69
|
+
if (!decision.ok) expect(decision.code).toBe('agent_features_denied')
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('super-admin bypasses agent requiredFeatures', () => {
|
|
73
|
+
const agent = makeAgent({
|
|
74
|
+
id: 'customers.assistant',
|
|
75
|
+
moduleId: 'customers',
|
|
76
|
+
requiredFeatures: ['customers.assistant.use'],
|
|
77
|
+
})
|
|
78
|
+
seedAgentRegistryForTests([agent])
|
|
79
|
+
|
|
80
|
+
const decision = checkAgentPolicy({
|
|
81
|
+
agentId: 'customers.assistant',
|
|
82
|
+
authContext: { userFeatures: [], isSuperAdmin: true },
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
expect(decision.ok).toBe(true)
|
|
86
|
+
if (decision.ok) expect(decision.agent).toBe(agent)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('returns tool_not_whitelisted when toolName is not in allowedTools', () => {
|
|
90
|
+
seedAgentRegistryForTests([
|
|
91
|
+
makeAgent({
|
|
92
|
+
id: 'customers.assistant',
|
|
93
|
+
moduleId: 'customers',
|
|
94
|
+
allowedTools: ['customers_search'],
|
|
95
|
+
}),
|
|
96
|
+
])
|
|
97
|
+
|
|
98
|
+
const decision = checkAgentPolicy({
|
|
99
|
+
agentId: 'customers.assistant',
|
|
100
|
+
authContext: { userFeatures: ['*'], isSuperAdmin: false },
|
|
101
|
+
toolName: 'customers_delete',
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
expect(decision.ok).toBe(false)
|
|
105
|
+
if (!decision.ok) expect(decision.code).toBe('tool_not_whitelisted')
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('returns tool_unknown when tool is whitelisted but not registered', () => {
|
|
109
|
+
seedAgentRegistryForTests([
|
|
110
|
+
makeAgent({
|
|
111
|
+
id: 'customers.assistant',
|
|
112
|
+
moduleId: 'customers',
|
|
113
|
+
allowedTools: ['customers_search'],
|
|
114
|
+
}),
|
|
115
|
+
])
|
|
116
|
+
|
|
117
|
+
const decision = checkAgentPolicy({
|
|
118
|
+
agentId: 'customers.assistant',
|
|
119
|
+
authContext: { userFeatures: ['*'], isSuperAdmin: false },
|
|
120
|
+
toolName: 'customers_search',
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
expect(decision.ok).toBe(false)
|
|
124
|
+
if (!decision.ok) expect(decision.code).toBe('tool_unknown')
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('returns tool_features_denied when tool requiredFeatures are not satisfied', () => {
|
|
128
|
+
registerMcpTool(
|
|
129
|
+
makeTool({
|
|
130
|
+
name: 'customers_search',
|
|
131
|
+
requiredFeatures: ['customers.people.view'],
|
|
132
|
+
}),
|
|
133
|
+
{ moduleId: 'customers' }
|
|
134
|
+
)
|
|
135
|
+
seedAgentRegistryForTests([
|
|
136
|
+
makeAgent({
|
|
137
|
+
id: 'customers.assistant',
|
|
138
|
+
moduleId: 'customers',
|
|
139
|
+
allowedTools: ['customers_search'],
|
|
140
|
+
}),
|
|
141
|
+
])
|
|
142
|
+
|
|
143
|
+
const decision = checkAgentPolicy({
|
|
144
|
+
agentId: 'customers.assistant',
|
|
145
|
+
authContext: { userFeatures: ['catalog.view'], isSuperAdmin: false },
|
|
146
|
+
toolName: 'customers_search',
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
expect(decision.ok).toBe(false)
|
|
150
|
+
if (!decision.ok) expect(decision.code).toBe('tool_features_denied')
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('returns mutation_blocked_by_readonly for explicit readOnly: true + isMutation tool', () => {
|
|
154
|
+
registerMcpTool(
|
|
155
|
+
makeTool({ name: 'customers_update', isMutation: true }),
|
|
156
|
+
{ moduleId: 'customers' }
|
|
157
|
+
)
|
|
158
|
+
seedAgentRegistryForTests([
|
|
159
|
+
makeAgent({
|
|
160
|
+
id: 'customers.assistant',
|
|
161
|
+
moduleId: 'customers',
|
|
162
|
+
allowedTools: ['customers_update'],
|
|
163
|
+
readOnly: true,
|
|
164
|
+
}),
|
|
165
|
+
])
|
|
166
|
+
|
|
167
|
+
const decision = checkAgentPolicy({
|
|
168
|
+
agentId: 'customers.assistant',
|
|
169
|
+
authContext: { userFeatures: ['*'], isSuperAdmin: false },
|
|
170
|
+
toolName: 'customers_update',
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
expect(decision.ok).toBe(false)
|
|
174
|
+
if (!decision.ok) expect(decision.code).toBe('mutation_blocked_by_readonly')
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
it('defaults to read-only when readOnly is not declared (v1 default blocks mutation)', () => {
|
|
178
|
+
registerMcpTool(
|
|
179
|
+
makeTool({ name: 'customers_update', isMutation: true }),
|
|
180
|
+
{ moduleId: 'customers' }
|
|
181
|
+
)
|
|
182
|
+
seedAgentRegistryForTests([
|
|
183
|
+
makeAgent({
|
|
184
|
+
id: 'customers.assistant',
|
|
185
|
+
moduleId: 'customers',
|
|
186
|
+
allowedTools: ['customers_update'],
|
|
187
|
+
}),
|
|
188
|
+
])
|
|
189
|
+
|
|
190
|
+
const decision = checkAgentPolicy({
|
|
191
|
+
agentId: 'customers.assistant',
|
|
192
|
+
authContext: { userFeatures: ['*'], isSuperAdmin: false },
|
|
193
|
+
toolName: 'customers_update',
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
expect(decision.ok).toBe(false)
|
|
197
|
+
if (!decision.ok) expect(decision.code).toBe('mutation_blocked_by_readonly')
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
it('returns mutation_blocked_by_policy when readOnly=false but mutationPolicy=read-only', () => {
|
|
201
|
+
registerMcpTool(
|
|
202
|
+
makeTool({ name: 'customers_update', isMutation: true }),
|
|
203
|
+
{ moduleId: 'customers' }
|
|
204
|
+
)
|
|
205
|
+
seedAgentRegistryForTests([
|
|
206
|
+
makeAgent({
|
|
207
|
+
id: 'customers.assistant',
|
|
208
|
+
moduleId: 'customers',
|
|
209
|
+
allowedTools: ['customers_update'],
|
|
210
|
+
readOnly: false,
|
|
211
|
+
mutationPolicy: 'read-only',
|
|
212
|
+
}),
|
|
213
|
+
])
|
|
214
|
+
|
|
215
|
+
const decision = checkAgentPolicy({
|
|
216
|
+
agentId: 'customers.assistant',
|
|
217
|
+
authContext: { userFeatures: ['*'], isSuperAdmin: false },
|
|
218
|
+
toolName: 'customers_update',
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
expect(decision.ok).toBe(false)
|
|
222
|
+
if (!decision.ok) expect(decision.code).toBe('mutation_blocked_by_policy')
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
it('returns execution_mode_not_supported for object requested on chat agent with no output', () => {
|
|
226
|
+
seedAgentRegistryForTests([
|
|
227
|
+
makeAgent({
|
|
228
|
+
id: 'customers.assistant',
|
|
229
|
+
moduleId: 'customers',
|
|
230
|
+
executionMode: 'chat',
|
|
231
|
+
}),
|
|
232
|
+
])
|
|
233
|
+
|
|
234
|
+
const decision = checkAgentPolicy({
|
|
235
|
+
agentId: 'customers.assistant',
|
|
236
|
+
authContext: { userFeatures: ['*'], isSuperAdmin: false },
|
|
237
|
+
requestedExecutionMode: 'object',
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
expect(decision.ok).toBe(false)
|
|
241
|
+
if (!decision.ok) expect(decision.code).toBe('execution_mode_not_supported')
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
it('returns execution_mode_not_supported for chat requested on object-mode agent', () => {
|
|
245
|
+
seedAgentRegistryForTests([
|
|
246
|
+
makeAgent({
|
|
247
|
+
id: 'catalog.merchandiser',
|
|
248
|
+
moduleId: 'catalog',
|
|
249
|
+
executionMode: 'object',
|
|
250
|
+
output: {
|
|
251
|
+
schemaName: 'MerchandisingProposal',
|
|
252
|
+
schema: z.object({ proposals: z.array(z.any()) }),
|
|
253
|
+
},
|
|
254
|
+
}),
|
|
255
|
+
])
|
|
256
|
+
|
|
257
|
+
const decision = checkAgentPolicy({
|
|
258
|
+
agentId: 'catalog.merchandiser',
|
|
259
|
+
authContext: { userFeatures: ['*'], isSuperAdmin: false },
|
|
260
|
+
requestedExecutionMode: 'chat',
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
expect(decision.ok).toBe(false)
|
|
264
|
+
if (!decision.ok) expect(decision.code).toBe('execution_mode_not_supported')
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
it('allows object-mode on chat agent when output schema is declared', () => {
|
|
268
|
+
seedAgentRegistryForTests([
|
|
269
|
+
makeAgent({
|
|
270
|
+
id: 'catalog.merchandiser',
|
|
271
|
+
moduleId: 'catalog',
|
|
272
|
+
executionMode: 'chat',
|
|
273
|
+
output: {
|
|
274
|
+
schemaName: 'MerchandisingProposal',
|
|
275
|
+
schema: z.object({ proposals: z.array(z.any()) }),
|
|
276
|
+
},
|
|
277
|
+
}),
|
|
278
|
+
])
|
|
279
|
+
|
|
280
|
+
const decision = checkAgentPolicy({
|
|
281
|
+
agentId: 'catalog.merchandiser',
|
|
282
|
+
authContext: { userFeatures: ['*'], isSuperAdmin: false },
|
|
283
|
+
requestedExecutionMode: 'object',
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
expect(decision.ok).toBe(true)
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
it('returns attachment_type_not_accepted when agent has no acceptedMediaTypes but images are sent', () => {
|
|
290
|
+
seedAgentRegistryForTests([
|
|
291
|
+
makeAgent({
|
|
292
|
+
id: 'customers.assistant',
|
|
293
|
+
moduleId: 'customers',
|
|
294
|
+
}),
|
|
295
|
+
])
|
|
296
|
+
|
|
297
|
+
const decision = checkAgentPolicy({
|
|
298
|
+
agentId: 'customers.assistant',
|
|
299
|
+
authContext: { userFeatures: ['*'], isSuperAdmin: false },
|
|
300
|
+
attachmentMediaTypes: ['image/png'],
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
expect(decision.ok).toBe(false)
|
|
304
|
+
if (!decision.ok) expect(decision.code).toBe('attachment_type_not_accepted')
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
it('returns attachment_type_not_accepted when agent accepts [image] but a PDF is requested', () => {
|
|
308
|
+
seedAgentRegistryForTests([
|
|
309
|
+
makeAgent({
|
|
310
|
+
id: 'catalog.merchandiser',
|
|
311
|
+
moduleId: 'catalog',
|
|
312
|
+
acceptedMediaTypes: ['image'],
|
|
313
|
+
}),
|
|
314
|
+
])
|
|
315
|
+
|
|
316
|
+
const decision = checkAgentPolicy({
|
|
317
|
+
agentId: 'catalog.merchandiser',
|
|
318
|
+
authContext: { userFeatures: ['*'], isSuperAdmin: false },
|
|
319
|
+
attachmentMediaTypes: ['image/jpeg', 'application/pdf'],
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
expect(decision.ok).toBe(false)
|
|
323
|
+
if (!decision.ok) expect(decision.code).toBe('attachment_type_not_accepted')
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
it('allows attachments that match the declared acceptedMediaTypes', () => {
|
|
327
|
+
seedAgentRegistryForTests([
|
|
328
|
+
makeAgent({
|
|
329
|
+
id: 'catalog.merchandiser',
|
|
330
|
+
moduleId: 'catalog',
|
|
331
|
+
acceptedMediaTypes: ['image', 'pdf'],
|
|
332
|
+
}),
|
|
333
|
+
])
|
|
334
|
+
|
|
335
|
+
const decision = checkAgentPolicy({
|
|
336
|
+
agentId: 'catalog.merchandiser',
|
|
337
|
+
authContext: { userFeatures: ['*'], isSuperAdmin: false },
|
|
338
|
+
attachmentMediaTypes: ['image/png', 'application/pdf'],
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
expect(decision.ok).toBe(true)
|
|
342
|
+
})
|
|
343
|
+
|
|
344
|
+
it('success path returns the resolved agent and tool when toolName is provided', () => {
|
|
345
|
+
const tool = makeTool({ name: 'customers_search' })
|
|
346
|
+
registerMcpTool(tool, { moduleId: 'customers' })
|
|
347
|
+
const agent = makeAgent({
|
|
348
|
+
id: 'customers.assistant',
|
|
349
|
+
moduleId: 'customers',
|
|
350
|
+
allowedTools: ['customers_search'],
|
|
351
|
+
})
|
|
352
|
+
seedAgentRegistryForTests([agent])
|
|
353
|
+
|
|
354
|
+
const decision = checkAgentPolicy({
|
|
355
|
+
agentId: 'customers.assistant',
|
|
356
|
+
authContext: { userFeatures: ['*'], isSuperAdmin: false },
|
|
357
|
+
toolName: 'customers_search',
|
|
358
|
+
})
|
|
359
|
+
|
|
360
|
+
expect(decision.ok).toBe(true)
|
|
361
|
+
if (decision.ok) {
|
|
362
|
+
expect(decision.agent).toBe(agent)
|
|
363
|
+
expect(decision.tool?.name).toBe('customers_search')
|
|
364
|
+
}
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
it('success path when toolName is omitted (session-establish check)', () => {
|
|
368
|
+
const agent = makeAgent({
|
|
369
|
+
id: 'customers.assistant',
|
|
370
|
+
moduleId: 'customers',
|
|
371
|
+
})
|
|
372
|
+
seedAgentRegistryForTests([agent])
|
|
373
|
+
|
|
374
|
+
const decision = checkAgentPolicy({
|
|
375
|
+
agentId: 'customers.assistant',
|
|
376
|
+
authContext: { userFeatures: ['*'], isSuperAdmin: false },
|
|
377
|
+
})
|
|
378
|
+
|
|
379
|
+
expect(decision.ok).toBe(true)
|
|
380
|
+
if (decision.ok) {
|
|
381
|
+
expect(decision.agent).toBe(agent)
|
|
382
|
+
expect(decision.tool).toBeUndefined()
|
|
383
|
+
}
|
|
384
|
+
})
|
|
385
|
+
})
|