@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,235 @@
|
|
|
1
|
+
import type { AwilixContainer } from 'awilix'
|
|
2
|
+
import {
|
|
3
|
+
executePendingActionCancel,
|
|
4
|
+
PENDING_ACTION_CANCELLED_EVENT_ID,
|
|
5
|
+
PENDING_ACTION_EXPIRED_EVENT_ID,
|
|
6
|
+
} from '../pending-action-cancel'
|
|
7
|
+
import type {
|
|
8
|
+
AiActionCancelledPayload,
|
|
9
|
+
AiActionExpiredPayload,
|
|
10
|
+
} from '../../events'
|
|
11
|
+
import type { AiPendingAction } from '../../data/entities'
|
|
12
|
+
|
|
13
|
+
function makeAction(overrides: Partial<AiPendingAction> = {}): AiPendingAction {
|
|
14
|
+
return {
|
|
15
|
+
id: 'pa_1',
|
|
16
|
+
tenantId: 'tenant-1',
|
|
17
|
+
organizationId: 'org-1',
|
|
18
|
+
agentId: 'catalog.merchandising_assistant',
|
|
19
|
+
toolName: 'catalog.update_product',
|
|
20
|
+
status: 'pending',
|
|
21
|
+
fieldDiff: [],
|
|
22
|
+
records: null,
|
|
23
|
+
failedRecords: null,
|
|
24
|
+
sideEffectsSummary: null,
|
|
25
|
+
recordVersion: 'v-1',
|
|
26
|
+
attachmentIds: [],
|
|
27
|
+
normalizedInput: { productId: 'p-1', patch: { title: 'New' } },
|
|
28
|
+
queueMode: 'inline',
|
|
29
|
+
executionResult: null,
|
|
30
|
+
targetEntityType: 'product',
|
|
31
|
+
targetRecordId: 'p-1',
|
|
32
|
+
conversationId: null,
|
|
33
|
+
idempotencyKey: 'idem_1',
|
|
34
|
+
createdByUserId: 'user-1',
|
|
35
|
+
createdAt: new Date('2026-04-18T10:00:00.000Z'),
|
|
36
|
+
expiresAt: new Date('2026-04-18T11:00:00.000Z'),
|
|
37
|
+
resolvedAt: null,
|
|
38
|
+
resolvedByUserId: null,
|
|
39
|
+
...overrides,
|
|
40
|
+
} as unknown as AiPendingAction
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function makeRepoStub(initialRow: AiPendingAction) {
|
|
44
|
+
let row = { ...initialRow } as AiPendingAction & Record<string, unknown>
|
|
45
|
+
const setStatus = jest.fn(
|
|
46
|
+
async (_id: string, nextStatus: string, _scope: unknown, extra?: Record<string, unknown>) => {
|
|
47
|
+
row = {
|
|
48
|
+
...row,
|
|
49
|
+
status: nextStatus as never,
|
|
50
|
+
}
|
|
51
|
+
if (extra && 'executionResult' in extra) {
|
|
52
|
+
row.executionResult = (extra.executionResult ?? null) as never
|
|
53
|
+
}
|
|
54
|
+
if (extra && 'resolvedByUserId' in extra) {
|
|
55
|
+
row.resolvedByUserId = extra.resolvedByUserId as never
|
|
56
|
+
}
|
|
57
|
+
row.resolvedAt = ((extra?.now as Date | undefined) ?? new Date()) as never
|
|
58
|
+
return row as AiPendingAction
|
|
59
|
+
},
|
|
60
|
+
)
|
|
61
|
+
return {
|
|
62
|
+
setStatus,
|
|
63
|
+
get current() {
|
|
64
|
+
return row
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function makeCtx() {
|
|
70
|
+
return {
|
|
71
|
+
tenantId: 'tenant-1',
|
|
72
|
+
organizationId: 'org-1',
|
|
73
|
+
userId: 'user-1',
|
|
74
|
+
container: {
|
|
75
|
+
resolve: (name: string) => {
|
|
76
|
+
if (name === 'em') return {}
|
|
77
|
+
if (name === 'eventBus') return { emitEvent: async () => {} }
|
|
78
|
+
throw new Error(`unknown dep ${name}`)
|
|
79
|
+
},
|
|
80
|
+
} as unknown as AwilixContainer,
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
describe('executePendingActionCancel', () => {
|
|
85
|
+
it('atomically transitions pending → cancelled and emits typed ai.action.cancelled', async () => {
|
|
86
|
+
const repo = makeRepoStub(makeAction())
|
|
87
|
+
const emitEvent = jest.fn().mockResolvedValue(undefined)
|
|
88
|
+
const clock = new Date('2026-04-18T10:05:00.000Z')
|
|
89
|
+
|
|
90
|
+
const result = await executePendingActionCancel({
|
|
91
|
+
action: makeAction(),
|
|
92
|
+
ctx: makeCtx(),
|
|
93
|
+
reason: 'Customer asked to abort',
|
|
94
|
+
repo: repo as unknown as never,
|
|
95
|
+
emitEvent,
|
|
96
|
+
now: clock,
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
expect(result.status).toBe('cancelled')
|
|
100
|
+
expect(result.row.status).toBe('cancelled')
|
|
101
|
+
expect(repo.setStatus).toHaveBeenCalledTimes(1)
|
|
102
|
+
const [, nextStatus, , extra] = repo.setStatus.mock.calls[0]
|
|
103
|
+
expect(nextStatus).toBe('cancelled')
|
|
104
|
+
expect(extra).toMatchObject({
|
|
105
|
+
resolvedByUserId: 'user-1',
|
|
106
|
+
executionResult: {
|
|
107
|
+
error: { code: 'cancelled_by_user', message: 'Customer asked to abort' },
|
|
108
|
+
},
|
|
109
|
+
})
|
|
110
|
+
expect(emitEvent).toHaveBeenCalledTimes(1)
|
|
111
|
+
const [emittedId, emittedPayload] = emitEvent.mock.calls[0] as [
|
|
112
|
+
'ai.action.cancelled',
|
|
113
|
+
AiActionCancelledPayload,
|
|
114
|
+
]
|
|
115
|
+
expect(emittedId).toBe(PENDING_ACTION_CANCELLED_EVENT_ID)
|
|
116
|
+
expect(emittedPayload).toMatchObject({
|
|
117
|
+
pendingActionId: 'pa_1',
|
|
118
|
+
agentId: 'catalog.merchandising_assistant',
|
|
119
|
+
toolName: 'catalog.update_product',
|
|
120
|
+
status: 'cancelled',
|
|
121
|
+
tenantId: 'tenant-1',
|
|
122
|
+
organizationId: 'org-1',
|
|
123
|
+
userId: 'user-1',
|
|
124
|
+
resolvedByUserId: 'user-1',
|
|
125
|
+
reason: 'Customer asked to abort',
|
|
126
|
+
executionResult: {
|
|
127
|
+
error: { code: 'cancelled_by_user', message: 'Customer asked to abort' },
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
expect(typeof emittedPayload.resolvedAt).toBe('string')
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it('defaults to "Cancelled by user" message when no reason is supplied', async () => {
|
|
134
|
+
const repo = makeRepoStub(makeAction())
|
|
135
|
+
const emitEvent = jest.fn().mockResolvedValue(undefined)
|
|
136
|
+
const clock = new Date('2026-04-18T10:05:00.000Z')
|
|
137
|
+
|
|
138
|
+
const result = await executePendingActionCancel({
|
|
139
|
+
action: makeAction(),
|
|
140
|
+
ctx: makeCtx(),
|
|
141
|
+
repo: repo as unknown as never,
|
|
142
|
+
emitEvent,
|
|
143
|
+
now: clock,
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
expect(result.status).toBe('cancelled')
|
|
147
|
+
const [, , , extra] = repo.setStatus.mock.calls[0]
|
|
148
|
+
expect(extra).toMatchObject({
|
|
149
|
+
executionResult: {
|
|
150
|
+
error: { code: 'cancelled_by_user', message: 'Cancelled by user' },
|
|
151
|
+
},
|
|
152
|
+
})
|
|
153
|
+
const [, payload] = emitEvent.mock.calls[0] as [string, AiActionCancelledPayload]
|
|
154
|
+
expect(payload.reason).toBeUndefined()
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
it('idempotent: already-cancelled action returns row without calling setStatus or emitting', async () => {
|
|
158
|
+
const cancelledAction = makeAction({ status: 'cancelled' as never })
|
|
159
|
+
const repo = makeRepoStub(cancelledAction)
|
|
160
|
+
const emitEvent = jest.fn().mockResolvedValue(undefined)
|
|
161
|
+
|
|
162
|
+
const result = await executePendingActionCancel({
|
|
163
|
+
action: cancelledAction,
|
|
164
|
+
ctx: makeCtx(),
|
|
165
|
+
repo: repo as unknown as never,
|
|
166
|
+
emitEvent,
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
expect(result.status).toBe('cancelled')
|
|
170
|
+
expect(result.row).toBe(cancelledAction)
|
|
171
|
+
expect(repo.setStatus).not.toHaveBeenCalled()
|
|
172
|
+
expect(emitEvent).not.toHaveBeenCalled()
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it('expired short-circuit: flips to expired and emits typed ai.action.expired', async () => {
|
|
176
|
+
const expiredAction = makeAction({
|
|
177
|
+
expiresAt: new Date('2020-01-01T00:00:00.000Z'),
|
|
178
|
+
})
|
|
179
|
+
const repo = makeRepoStub(expiredAction)
|
|
180
|
+
const emitEvent = jest.fn().mockResolvedValue(undefined)
|
|
181
|
+
const clock = new Date('2026-04-18T10:05:00.000Z')
|
|
182
|
+
|
|
183
|
+
const result = await executePendingActionCancel({
|
|
184
|
+
action: expiredAction,
|
|
185
|
+
ctx: makeCtx(),
|
|
186
|
+
repo: repo as unknown as never,
|
|
187
|
+
emitEvent,
|
|
188
|
+
now: clock,
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
expect(result.status).toBe('expired')
|
|
192
|
+
expect(result.row.status).toBe('expired')
|
|
193
|
+
expect(repo.setStatus).toHaveBeenCalledTimes(1)
|
|
194
|
+
const [, nextStatus] = repo.setStatus.mock.calls[0]
|
|
195
|
+
expect(nextStatus).toBe('expired')
|
|
196
|
+
expect(emitEvent).toHaveBeenCalledTimes(1)
|
|
197
|
+
const [emittedId, emittedPayload] = emitEvent.mock.calls[0] as [
|
|
198
|
+
'ai.action.expired',
|
|
199
|
+
AiActionExpiredPayload,
|
|
200
|
+
]
|
|
201
|
+
expect(emittedId).toBe(PENDING_ACTION_EXPIRED_EVENT_ID)
|
|
202
|
+
expect(emittedPayload).toMatchObject({
|
|
203
|
+
pendingActionId: 'pa_1',
|
|
204
|
+
agentId: 'catalog.merchandising_assistant',
|
|
205
|
+
toolName: 'catalog.update_product',
|
|
206
|
+
status: 'expired',
|
|
207
|
+
tenantId: 'tenant-1',
|
|
208
|
+
organizationId: 'org-1',
|
|
209
|
+
userId: 'user-1',
|
|
210
|
+
resolvedByUserId: null,
|
|
211
|
+
})
|
|
212
|
+
expect(typeof emittedPayload.resolvedAt).toBe('string')
|
|
213
|
+
expect(typeof emittedPayload.expiresAt).toBe('string')
|
|
214
|
+
expect(typeof emittedPayload.expiredAt).toBe('string')
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
it('swallows emit-event errors without failing the cancel', async () => {
|
|
218
|
+
const repo = makeRepoStub(makeAction())
|
|
219
|
+
const emitEvent = jest.fn().mockRejectedValue(new Error('bus down'))
|
|
220
|
+
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {})
|
|
221
|
+
const clock = new Date('2026-04-18T10:05:00.000Z')
|
|
222
|
+
|
|
223
|
+
const result = await executePendingActionCancel({
|
|
224
|
+
action: makeAction(),
|
|
225
|
+
ctx: makeCtx(),
|
|
226
|
+
repo: repo as unknown as never,
|
|
227
|
+
emitEvent,
|
|
228
|
+
now: clock,
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
expect(result.status).toBe('cancelled')
|
|
232
|
+
expect(consoleWarnSpy).toHaveBeenCalled()
|
|
233
|
+
consoleWarnSpy.mockRestore()
|
|
234
|
+
})
|
|
235
|
+
})
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import {
|
|
2
|
+
serializePendingActionForClient,
|
|
3
|
+
type SerializablePendingActionRow,
|
|
4
|
+
type SerializedPendingAction,
|
|
5
|
+
} from '../pending-action-client'
|
|
6
|
+
|
|
7
|
+
function makeRow(
|
|
8
|
+
overrides: Partial<SerializablePendingActionRow> = {},
|
|
9
|
+
): SerializablePendingActionRow {
|
|
10
|
+
const base: SerializablePendingActionRow = {
|
|
11
|
+
id: 'pa_123',
|
|
12
|
+
agentId: 'catalog.merchandising_assistant',
|
|
13
|
+
toolName: 'catalog.update_product',
|
|
14
|
+
status: 'pending',
|
|
15
|
+
fieldDiff: [{ field: 'title', before: 'Old', after: 'New' }],
|
|
16
|
+
records: null,
|
|
17
|
+
failedRecords: null,
|
|
18
|
+
sideEffectsSummary: null,
|
|
19
|
+
attachmentIds: [],
|
|
20
|
+
targetEntityType: 'product',
|
|
21
|
+
targetRecordId: 'prod_1',
|
|
22
|
+
recordVersion: 'v1',
|
|
23
|
+
queueMode: 'inline',
|
|
24
|
+
executionResult: null,
|
|
25
|
+
createdAt: new Date('2026-04-18T10:00:00.000Z'),
|
|
26
|
+
expiresAt: new Date('2026-04-18T10:15:00.000Z'),
|
|
27
|
+
resolvedAt: null,
|
|
28
|
+
resolvedByUserId: null,
|
|
29
|
+
}
|
|
30
|
+
return { ...base, ...overrides }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('serializePendingActionForClient (Step 5.7)', () => {
|
|
34
|
+
it('produces the full whitelist in the documented shape', () => {
|
|
35
|
+
const row = makeRow()
|
|
36
|
+
const out = serializePendingActionForClient(row)
|
|
37
|
+
|
|
38
|
+
const expected: SerializedPendingAction = {
|
|
39
|
+
id: 'pa_123',
|
|
40
|
+
agentId: 'catalog.merchandising_assistant',
|
|
41
|
+
toolName: 'catalog.update_product',
|
|
42
|
+
status: 'pending',
|
|
43
|
+
fieldDiff: [{ field: 'title', before: 'Old', after: 'New' }],
|
|
44
|
+
records: null,
|
|
45
|
+
failedRecords: null,
|
|
46
|
+
sideEffectsSummary: null,
|
|
47
|
+
attachmentIds: [],
|
|
48
|
+
targetEntityType: 'product',
|
|
49
|
+
targetRecordId: 'prod_1',
|
|
50
|
+
recordVersion: 'v1',
|
|
51
|
+
queueMode: 'inline',
|
|
52
|
+
executionResult: null,
|
|
53
|
+
createdAt: '2026-04-18T10:00:00.000Z',
|
|
54
|
+
expiresAt: '2026-04-18T10:15:00.000Z',
|
|
55
|
+
resolvedAt: null,
|
|
56
|
+
resolvedByUserId: null,
|
|
57
|
+
}
|
|
58
|
+
expect(out).toEqual(expected)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('never exposes server-internal fields even when they exist on the row', () => {
|
|
62
|
+
const row = {
|
|
63
|
+
...makeRow(),
|
|
64
|
+
// Simulate the real MikroORM entity shape with internal fields present.
|
|
65
|
+
normalizedInput: { secret: 'do-not-leak' },
|
|
66
|
+
createdByUserId: 'user-1',
|
|
67
|
+
idempotencyKey: 'idem_abc123',
|
|
68
|
+
tenantId: 'tenant-1',
|
|
69
|
+
organizationId: 'org-1',
|
|
70
|
+
} as unknown as SerializablePendingActionRow
|
|
71
|
+
|
|
72
|
+
const out = serializePendingActionForClient(row)
|
|
73
|
+
|
|
74
|
+
expect(out).not.toHaveProperty('normalizedInput')
|
|
75
|
+
expect(out).not.toHaveProperty('createdByUserId')
|
|
76
|
+
expect(out).not.toHaveProperty('idempotencyKey')
|
|
77
|
+
expect(out).not.toHaveProperty('tenantId')
|
|
78
|
+
expect(out).not.toHaveProperty('organizationId')
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('keeps the exact whitelist of keys', () => {
|
|
82
|
+
const row = makeRow()
|
|
83
|
+
const out = serializePendingActionForClient(row)
|
|
84
|
+
const keys = Object.keys(out).sort()
|
|
85
|
+
expect(keys).toEqual(
|
|
86
|
+
[
|
|
87
|
+
'agentId',
|
|
88
|
+
'attachmentIds',
|
|
89
|
+
'createdAt',
|
|
90
|
+
'executionResult',
|
|
91
|
+
'expiresAt',
|
|
92
|
+
'failedRecords',
|
|
93
|
+
'fieldDiff',
|
|
94
|
+
'id',
|
|
95
|
+
'queueMode',
|
|
96
|
+
'recordVersion',
|
|
97
|
+
'records',
|
|
98
|
+
'resolvedAt',
|
|
99
|
+
'resolvedByUserId',
|
|
100
|
+
'sideEffectsSummary',
|
|
101
|
+
'status',
|
|
102
|
+
'targetEntityType',
|
|
103
|
+
'targetRecordId',
|
|
104
|
+
'toolName',
|
|
105
|
+
].sort(),
|
|
106
|
+
)
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
it('normalizes batch records + failedRecords and strips empty arrays', () => {
|
|
110
|
+
const out = serializePendingActionForClient(
|
|
111
|
+
makeRow({
|
|
112
|
+
records: [
|
|
113
|
+
{
|
|
114
|
+
recordId: 'p_1',
|
|
115
|
+
entityType: 'product',
|
|
116
|
+
label: 'SKU 1',
|
|
117
|
+
fieldDiff: [{ field: 'price', before: 10, after: 12 }],
|
|
118
|
+
recordVersion: 'v1',
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
failedRecords: [],
|
|
122
|
+
}),
|
|
123
|
+
)
|
|
124
|
+
expect(out.records).toHaveLength(1)
|
|
125
|
+
expect(out.records?.[0]?.recordId).toBe('p_1')
|
|
126
|
+
expect(out.failedRecords).toBeNull()
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('accepts ISO strings for Date fields (round-trip safety)', () => {
|
|
130
|
+
const out = serializePendingActionForClient(
|
|
131
|
+
makeRow({
|
|
132
|
+
createdAt: '2026-01-01T00:00:00.000Z',
|
|
133
|
+
expiresAt: '2026-01-01T00:10:00.000Z',
|
|
134
|
+
resolvedAt: '2026-01-01T00:05:00.000Z',
|
|
135
|
+
}),
|
|
136
|
+
)
|
|
137
|
+
expect(out.createdAt).toBe('2026-01-01T00:00:00.000Z')
|
|
138
|
+
expect(out.expiresAt).toBe('2026-01-01T00:10:00.000Z')
|
|
139
|
+
expect(out.resolvedAt).toBe('2026-01-01T00:05:00.000Z')
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('defaults queueMode to "inline" when absent', () => {
|
|
143
|
+
const out = serializePendingActionForClient(
|
|
144
|
+
makeRow({ queueMode: undefined as unknown as SerializablePendingActionRow['queueMode'] }),
|
|
145
|
+
)
|
|
146
|
+
expect(out.queueMode).toBe('inline')
|
|
147
|
+
})
|
|
148
|
+
})
|