@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
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
|
-
import { dirname, resolve } from "node:path";
|
|
4
|
-
import { pathToFileURL } from "node:url";
|
|
5
2
|
async function ensureBootstrap() {
|
|
6
3
|
try {
|
|
7
4
|
const { getDiRegistrars } = await import("@open-mercato/shared/lib/di/container");
|
|
@@ -10,14 +7,8 @@ async function ensureBootstrap() {
|
|
|
10
7
|
} catch {
|
|
11
8
|
}
|
|
12
9
|
try {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const bootstrapPath = resolve(__dirname, "../../../../../../apps/mercato/src/bootstrap.ts");
|
|
16
|
-
const bootstrapUrl = pathToFileURL(bootstrapPath).href;
|
|
17
|
-
const { bootstrap, isBootstrapped } = await import(bootstrapUrl);
|
|
18
|
-
if (!isBootstrapped()) {
|
|
19
|
-
bootstrap();
|
|
20
|
-
}
|
|
10
|
+
const { bootstrapFromAppRoot } = await import("@open-mercato/shared/lib/bootstrap/dynamicLoader");
|
|
11
|
+
await bootstrapFromAppRoot();
|
|
21
12
|
} catch (error) {
|
|
22
13
|
console.error("[MCP] Bootstrap failed:", error instanceof Error ? error.message : error);
|
|
23
14
|
}
|
|
@@ -211,7 +202,82 @@ const entityGraph = {
|
|
|
211
202
|
[Entity Graph] ${graph.nodes.length} entities, ${edges.length} relationships`);
|
|
212
203
|
}
|
|
213
204
|
};
|
|
214
|
-
|
|
205
|
+
const runPendingActionCleanup = {
|
|
206
|
+
command: "run-pending-action-cleanup",
|
|
207
|
+
async run() {
|
|
208
|
+
await ensureBootstrap();
|
|
209
|
+
const container = await createRequestContainer();
|
|
210
|
+
const { runPendingActionCleanup: runCleanup } = await import("./workers/ai-pending-action-cleanup.js");
|
|
211
|
+
const em = container.resolve("em");
|
|
212
|
+
const summary = await runCleanup({ em });
|
|
213
|
+
console.log("[ai-pending-action-cleanup] Sweep complete:", summary);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
const testTools = {
|
|
217
|
+
command: "test-tools",
|
|
218
|
+
async run(rest) {
|
|
219
|
+
const args = parseArgs(rest);
|
|
220
|
+
const json = args.json === true || args.json === "true";
|
|
221
|
+
const moduleFilter = typeof args.module === "string" && args.module.length > 0 ? args.module : null;
|
|
222
|
+
const includeMutations = args["no-mutations"] !== true && args["no-mutations"] !== "true";
|
|
223
|
+
const tenantId = typeof args.tenant === "string" && args.tenant.length > 0 ? args.tenant : null;
|
|
224
|
+
const organizationId = typeof args.org === "string" && args.org.length > 0 ? args.org : null;
|
|
225
|
+
await ensureBootstrap();
|
|
226
|
+
const { runToolTests } = await import("./lib/tool-test-runner.js");
|
|
227
|
+
const report = await runToolTests({
|
|
228
|
+
tenantId,
|
|
229
|
+
organizationId,
|
|
230
|
+
moduleFilter,
|
|
231
|
+
includeMutations
|
|
232
|
+
});
|
|
233
|
+
if (json) {
|
|
234
|
+
console.log("---TOOL_TEST_REPORT_BEGIN---");
|
|
235
|
+
console.log(JSON.stringify(report));
|
|
236
|
+
console.log("---TOOL_TEST_REPORT_END---");
|
|
237
|
+
} else {
|
|
238
|
+
console.log("");
|
|
239
|
+
console.log(
|
|
240
|
+
`AI tool test report \u2014 tenant=${report.tenantId ?? "<none>"} org=${report.organizationId ?? "<none>"}`
|
|
241
|
+
);
|
|
242
|
+
console.log(
|
|
243
|
+
`total=${report.total} pass=${report.passed} fail=${report.failed} skip=${report.skipped}`
|
|
244
|
+
);
|
|
245
|
+
const byModule = /* @__PURE__ */ new Map();
|
|
246
|
+
for (const record of report.records) {
|
|
247
|
+
const list = byModule.get(record.module) ?? [];
|
|
248
|
+
list.push(record);
|
|
249
|
+
byModule.set(record.module, list);
|
|
250
|
+
}
|
|
251
|
+
const sortedModules = Array.from(byModule.keys()).sort();
|
|
252
|
+
for (const moduleId of sortedModules) {
|
|
253
|
+
const list = byModule.get(moduleId);
|
|
254
|
+
console.log("");
|
|
255
|
+
console.log(`${moduleId} (${list.length}):`);
|
|
256
|
+
for (const record of list) {
|
|
257
|
+
const marker = record.status === "pass" ? "\u2713" : record.status === "fail" ? "\u2717" : "\xB7";
|
|
258
|
+
const reason = record.reason ? ` \u2014 ${record.reason}` : "";
|
|
259
|
+
const mutation = record.isMutation ? " [mutation]" : "";
|
|
260
|
+
console.log(
|
|
261
|
+
` ${marker} ${record.tool}${mutation} (${record.durationMs}ms)${reason}`
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
console.log("");
|
|
266
|
+
}
|
|
267
|
+
if (report.failed > 0) {
|
|
268
|
+
process.exitCode = 1;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
var cli_default = [
|
|
273
|
+
mcpServe,
|
|
274
|
+
mcpServeHttp,
|
|
275
|
+
mcpDev,
|
|
276
|
+
listTools,
|
|
277
|
+
entityGraph,
|
|
278
|
+
runPendingActionCleanup,
|
|
279
|
+
testTools
|
|
280
|
+
];
|
|
215
281
|
export {
|
|
216
282
|
cli_default as default
|
|
217
283
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/modules/ai_assistant/cli.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ModuleCli } from '@open-mercato/shared/modules/registry'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { fileURLToPath } from 'node:url'\nimport { dirname, resolve } from 'node:path'\nimport { pathToFileURL } from 'node:url'\n\n/**\n * Ensure app bootstrap is called before creating DI container.\n * Uses import.meta.url for runtime path resolution since @/ alias\n * doesn't work with dynamic imports (TypeScript path aliases are\n * compile-time only, not available to Node.js at runtime).\n */\nasync function ensureBootstrap(): Promise<void> {\n // First check if DI is already available\n try {\n const { getDiRegistrars } = await import('@open-mercato/shared/lib/di/container')\n getDiRegistrars()\n return // DI already available\n } catch {\n // DI not available, need to bootstrap\n }\n\n // Construct absolute path to bootstrap using import.meta.url\n try {\n const __filename = fileURLToPath(import.meta.url)\n const __dirname = dirname(__filename)\n // From packages/ai-assistant/src/modules/ai_assistant/cli.ts\n // to apps/mercato/src/bootstrap.ts:\n // ai_assistant \u2192 modules \u2192 src \u2192 ai-assistant \u2192 packages \u2192 root (6 levels)\n // then into apps/mercato/src/bootstrap.ts\n const bootstrapPath = resolve(__dirname, '../../../../../../apps/mercato/src/bootstrap.ts')\n\n // Dynamic import using file URL\n const bootstrapUrl = pathToFileURL(bootstrapPath).href\n const { bootstrap, isBootstrapped } = await import(bootstrapUrl)\n\n if (!isBootstrapped()) {\n bootstrap()\n }\n } catch (error) {\n console.error('[MCP] Bootstrap failed:', error instanceof Error ? error.message : error)\n // Continue - some contexts may not have bootstrap available\n }\n}\n\nfunction parseArgs(rest: string[]): Record<string, string | boolean> {\n const args: Record<string, string | boolean> = {}\n for (let i = 0; i < rest.length; i++) {\n const arg = rest[i]\n if (!arg?.startsWith('--')) continue\n\n const [key, value] = arg.replace(/^--/, '').split('=')\n if (value !== undefined) {\n args[key] = value\n } else if (rest[i + 1] && !rest[i + 1]!.startsWith('--')) {\n args[key] = rest[i + 1]!\n i++\n } else {\n args[key] = true\n }\n }\n return args\n}\n\nconst mcpServe: ModuleCli = {\n command: 'mcp:serve',\n async run(rest) {\n const args = parseArgs(rest)\n const apiKey = String(args['api-key'] ?? args.apiKey ?? '') || null\n const tenantId = String(args.tenant ?? args.tenantId ?? '') || null\n const organizationId = String(args.org ?? args.organizationId ?? '') || null\n const userId = String(args.user ?? args.userId ?? '') || null\n const debug = args.debug === true || args.debug === 'true'\n\n // Either API key or tenant is required\n if (!apiKey && !tenantId) {\n console.error('Usage: mercato ai_assistant mcp:serve [options]')\n console.error('')\n console.error('Authentication (choose one):')\n console.error(' --api-key <secret> API key secret for authentication (recommended)')\n console.error(' --tenant <id> Tenant ID (for manual context)')\n console.error('')\n console.error('Options (with --tenant):')\n console.error(' --org <id> Organization ID (optional)')\n console.error(' --user <id> User ID for ACL (optional, uses superadmin if not set)')\n console.error('')\n console.error('Common options:')\n console.error(' --debug Enable debug logging')\n console.error('')\n console.error('Examples:')\n console.error(' mercato ai_assistant mcp:serve --api-key omk_xxxx.yyyy...')\n console.error(' mercato ai_assistant mcp:serve --tenant 123e4567-e89b-12d3-a456-426614174000')\n return\n }\n\n await ensureBootstrap()\n const container = await createRequestContainer()\n\n const { runMcpServer } = await import('./lib/mcp-server')\n\n if (apiKey) {\n await runMcpServer({\n config: {\n name: 'open-mercato-mcp',\n version: '0.1.0',\n debug,\n },\n container,\n apiKeySecret: apiKey,\n })\n } else {\n await runMcpServer({\n config: {\n name: 'open-mercato-mcp',\n version: '0.1.0',\n debug,\n },\n container,\n context: {\n tenantId,\n organizationId,\n userId,\n },\n })\n }\n },\n}\n\nconst MCP_DEFAULT_PORT = 3001\n\nconst mcpServeHttp: ModuleCli = {\n command: 'mcp:serve-http',\n async run(rest) {\n const args = parseArgs(rest)\n const portArg = parseInt(String(args.port ?? ''), 10)\n const port = !portArg || isNaN(portArg) ? MCP_DEFAULT_PORT : portArg\n const debug = args.debug === true || args.debug === 'true'\n\n await ensureBootstrap()\n const container = await createRequestContainer()\n\n const { runMcpHttpServer } = await import('./lib/http-server')\n\n await runMcpHttpServer({\n config: {\n name: 'open-mercato-mcp',\n version: '0.1.0',\n debug,\n },\n container,\n port,\n })\n },\n}\n\nconst mcpDev: ModuleCli = {\n command: 'mcp:dev',\n async run() {\n await ensureBootstrap()\n const { runMcpDevServer } = await import('./lib/mcp-dev-server')\n await runMcpDevServer()\n },\n}\n\nconst listTools: ModuleCli = {\n command: 'mcp:list-tools',\n async run(rest) {\n const args = parseArgs(rest)\n const verbose = args.verbose === true || args.verbose === 'true'\n\n // Ensure bootstrap runs so modules are registered for API discovery\n await ensureBootstrap()\n\n const { loadAllModuleTools } = await import('./lib/tool-loader')\n await loadAllModuleTools()\n\n const { getToolRegistry } = await import('./lib/tool-registry')\n const registry = getToolRegistry()\n const toolNames = registry.listToolNames()\n\n if (toolNames.length === 0) {\n console.log('\\nNo MCP tools registered.')\n console.log('Tools can be registered by modules using registerMcpTool().\\n')\n return\n }\n\n console.log(`\\nRegistered MCP Tools (${toolNames.length}):\\n`)\n\n // Group tools by module\n const byModule = new Map<string, string[]>()\n for (const name of toolNames) {\n const [module] = name.split('.')\n const list = byModule.get(module) ?? []\n list.push(name)\n byModule.set(module, list)\n }\n\n // Sort modules alphabetically\n const sortedModules = Array.from(byModule.keys()).sort()\n\n for (const module of sortedModules) {\n const tools = byModule.get(module)!\n console.log(`${module} (${tools.length} tools):`)\n\n for (const name of tools.sort()) {\n const tool = registry.getTool(name)\n if (!tool) continue\n\n if (verbose) {\n console.log(` ${name}`)\n console.log(` ${tool.description}`)\n if (tool.requiredFeatures?.length) {\n console.log(` Requires: ${tool.requiredFeatures.join(', ')}`)\n }\n } else {\n console.log(` - ${name}`)\n }\n }\n console.log('')\n }\n },\n}\n\nconst entityGraph: ModuleCli = {\n command: 'entity-graph',\n async run(rest) {\n const args = parseArgs(rest)\n const format = String(args.format ?? 'triples') as 'json' | 'triples'\n const entity = args.entity ? String(args.entity) : undefined\n const module = args.module ? String(args.module) : undefined\n\n await ensureBootstrap()\n\n const { getOrm } = await import('@open-mercato/shared/lib/db/mikro')\n const { extractEntityGraph, formatGraphAsTriples, filterGraphByEntity, filterGraphByModule } = await import(\n './lib/entity-graph'\n )\n\n console.log('[Entity Graph] Extracting from MikroORM metadata...')\n\n const orm = await getOrm()\n const graph = await extractEntityGraph(orm)\n\n // Apply filters\n let edges = graph.edges\n\n if (entity) {\n edges = filterGraphByEntity(graph, entity)\n console.log(`[Entity Graph] Filtered by entity: ${entity}`)\n }\n\n if (module) {\n const filteredGraph = { ...graph, edges }\n edges = filterGraphByModule(filteredGraph, module)\n console.log(`[Entity Graph] Filtered by module: ${module}`)\n }\n\n const filteredGraph = { ...graph, edges }\n\n if (format === 'json') {\n console.log(JSON.stringify(filteredGraph, null, 2))\n } else {\n const triples = formatGraphAsTriples(filteredGraph)\n console.log('')\n for (const triple of triples) {\n console.log(triple)\n }\n }\n\n console.log(`\\n[Entity Graph] ${graph.nodes.length} entities, ${edges.length} relationships`)\n },\n}\n\nexport default [mcpServe, mcpServeHttp, mcpDev, listTools, entityGraph]\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,8BAA8B;
|
|
4
|
+
"sourcesContent": ["import type { ModuleCli } from '@open-mercato/shared/modules/registry'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\n/**\n * Ensure app bootstrap is called before creating DI container.\n * Uses the shared generated-bootstrap loader so the command works both from\n * the monorepo app and from standalone apps installed through npm packages.\n */\nasync function ensureBootstrap(): Promise<void> {\n // First check if DI is already available\n try {\n const { getDiRegistrars } = await import('@open-mercato/shared/lib/di/container')\n getDiRegistrars()\n return // DI already available\n } catch {\n // DI not available, need to bootstrap\n }\n\n try {\n const { bootstrapFromAppRoot } = await import('@open-mercato/shared/lib/bootstrap/dynamicLoader')\n await bootstrapFromAppRoot()\n } catch (error) {\n console.error('[MCP] Bootstrap failed:', error instanceof Error ? error.message : error)\n // Continue - some contexts may not have bootstrap available\n }\n}\n\nfunction parseArgs(rest: string[]): Record<string, string | boolean> {\n const args: Record<string, string | boolean> = {}\n for (let i = 0; i < rest.length; i++) {\n const arg = rest[i]\n if (!arg?.startsWith('--')) continue\n\n const [key, value] = arg.replace(/^--/, '').split('=')\n if (value !== undefined) {\n args[key] = value\n } else if (rest[i + 1] && !rest[i + 1]!.startsWith('--')) {\n args[key] = rest[i + 1]!\n i++\n } else {\n args[key] = true\n }\n }\n return args\n}\n\nconst mcpServe: ModuleCli = {\n command: 'mcp:serve',\n async run(rest) {\n const args = parseArgs(rest)\n const apiKey = String(args['api-key'] ?? args.apiKey ?? '') || null\n const tenantId = String(args.tenant ?? args.tenantId ?? '') || null\n const organizationId = String(args.org ?? args.organizationId ?? '') || null\n const userId = String(args.user ?? args.userId ?? '') || null\n const debug = args.debug === true || args.debug === 'true'\n\n // Either API key or tenant is required\n if (!apiKey && !tenantId) {\n console.error('Usage: mercato ai_assistant mcp:serve [options]')\n console.error('')\n console.error('Authentication (choose one):')\n console.error(' --api-key <secret> API key secret for authentication (recommended)')\n console.error(' --tenant <id> Tenant ID (for manual context)')\n console.error('')\n console.error('Options (with --tenant):')\n console.error(' --org <id> Organization ID (optional)')\n console.error(' --user <id> User ID for ACL (optional, uses superadmin if not set)')\n console.error('')\n console.error('Common options:')\n console.error(' --debug Enable debug logging')\n console.error('')\n console.error('Examples:')\n console.error(' mercato ai_assistant mcp:serve --api-key omk_xxxx.yyyy...')\n console.error(' mercato ai_assistant mcp:serve --tenant 123e4567-e89b-12d3-a456-426614174000')\n return\n }\n\n await ensureBootstrap()\n const container = await createRequestContainer()\n\n const { runMcpServer } = await import('./lib/mcp-server')\n\n if (apiKey) {\n await runMcpServer({\n config: {\n name: 'open-mercato-mcp',\n version: '0.1.0',\n debug,\n },\n container,\n apiKeySecret: apiKey,\n })\n } else {\n await runMcpServer({\n config: {\n name: 'open-mercato-mcp',\n version: '0.1.0',\n debug,\n },\n container,\n context: {\n tenantId,\n organizationId,\n userId,\n },\n })\n }\n },\n}\n\nconst MCP_DEFAULT_PORT = 3001\n\nconst mcpServeHttp: ModuleCli = {\n command: 'mcp:serve-http',\n async run(rest) {\n const args = parseArgs(rest)\n const portArg = parseInt(String(args.port ?? ''), 10)\n const port = !portArg || isNaN(portArg) ? MCP_DEFAULT_PORT : portArg\n const debug = args.debug === true || args.debug === 'true'\n\n await ensureBootstrap()\n const container = await createRequestContainer()\n\n const { runMcpHttpServer } = await import('./lib/http-server')\n\n await runMcpHttpServer({\n config: {\n name: 'open-mercato-mcp',\n version: '0.1.0',\n debug,\n },\n container,\n port,\n })\n },\n}\n\nconst mcpDev: ModuleCli = {\n command: 'mcp:dev',\n async run() {\n await ensureBootstrap()\n const { runMcpDevServer } = await import('./lib/mcp-dev-server')\n await runMcpDevServer()\n },\n}\n\nconst listTools: ModuleCli = {\n command: 'mcp:list-tools',\n async run(rest) {\n const args = parseArgs(rest)\n const verbose = args.verbose === true || args.verbose === 'true'\n\n // Ensure bootstrap runs so modules are registered for API discovery\n await ensureBootstrap()\n\n const { loadAllModuleTools } = await import('./lib/tool-loader')\n await loadAllModuleTools()\n\n const { getToolRegistry } = await import('./lib/tool-registry')\n const registry = getToolRegistry()\n const toolNames = registry.listToolNames()\n\n if (toolNames.length === 0) {\n console.log('\\nNo MCP tools registered.')\n console.log('Tools can be registered by modules using registerMcpTool().\\n')\n return\n }\n\n console.log(`\\nRegistered MCP Tools (${toolNames.length}):\\n`)\n\n // Group tools by module\n const byModule = new Map<string, string[]>()\n for (const name of toolNames) {\n const [module] = name.split('.')\n const list = byModule.get(module) ?? []\n list.push(name)\n byModule.set(module, list)\n }\n\n // Sort modules alphabetically\n const sortedModules = Array.from(byModule.keys()).sort()\n\n for (const module of sortedModules) {\n const tools = byModule.get(module)!\n console.log(`${module} (${tools.length} tools):`)\n\n for (const name of tools.sort()) {\n const tool = registry.getTool(name)\n if (!tool) continue\n\n if (verbose) {\n console.log(` ${name}`)\n console.log(` ${tool.description}`)\n if (tool.requiredFeatures?.length) {\n console.log(` Requires: ${tool.requiredFeatures.join(', ')}`)\n }\n } else {\n console.log(` - ${name}`)\n }\n }\n console.log('')\n }\n },\n}\n\nconst entityGraph: ModuleCli = {\n command: 'entity-graph',\n async run(rest) {\n const args = parseArgs(rest)\n const format = String(args.format ?? 'triples') as 'json' | 'triples'\n const entity = args.entity ? String(args.entity) : undefined\n const module = args.module ? String(args.module) : undefined\n\n await ensureBootstrap()\n\n const { getOrm } = await import('@open-mercato/shared/lib/db/mikro')\n const { extractEntityGraph, formatGraphAsTriples, filterGraphByEntity, filterGraphByModule } = await import(\n './lib/entity-graph'\n )\n\n console.log('[Entity Graph] Extracting from MikroORM metadata...')\n\n const orm = await getOrm()\n const graph = await extractEntityGraph(orm)\n\n // Apply filters\n let edges = graph.edges\n\n if (entity) {\n edges = filterGraphByEntity(graph, entity)\n console.log(`[Entity Graph] Filtered by entity: ${entity}`)\n }\n\n if (module) {\n const filteredGraph = { ...graph, edges }\n edges = filterGraphByModule(filteredGraph, module)\n console.log(`[Entity Graph] Filtered by module: ${module}`)\n }\n\n const filteredGraph = { ...graph, edges }\n\n if (format === 'json') {\n console.log(JSON.stringify(filteredGraph, null, 2))\n } else {\n const triples = formatGraphAsTriples(filteredGraph)\n console.log('')\n for (const triple of triples) {\n console.log(triple)\n }\n }\n\n console.log(`\\n[Entity Graph] ${graph.nodes.length} entities, ${edges.length} relationships`)\n },\n}\n\nconst runPendingActionCleanup: ModuleCli = {\n command: 'run-pending-action-cleanup',\n async run() {\n await ensureBootstrap()\n const container = await createRequestContainer()\n\n const { runPendingActionCleanup: runCleanup } = await import(\n './workers/ai-pending-action-cleanup'\n )\n\n const em = container.resolve<import('@mikro-orm/postgresql').EntityManager>('em')\n const summary = await runCleanup({ em })\n\n console.log('[ai-pending-action-cleanup] Sweep complete:', summary)\n },\n}\n\nconst testTools: ModuleCli = {\n command: 'test-tools',\n async run(rest) {\n const args = parseArgs(rest)\n const json = args.json === true || args.json === 'true'\n const moduleFilter =\n typeof args.module === 'string' && args.module.length > 0 ? args.module : null\n const includeMutations = args['no-mutations'] !== true && args['no-mutations'] !== 'true'\n const tenantId =\n typeof args.tenant === 'string' && args.tenant.length > 0 ? args.tenant : null\n const organizationId =\n typeof args.org === 'string' && args.org.length > 0 ? args.org : null\n\n await ensureBootstrap()\n const { runToolTests } = await import('./lib/tool-test-runner')\n const report = await runToolTests({\n tenantId,\n organizationId,\n moduleFilter,\n includeMutations,\n })\n\n if (json) {\n // Wrap in markers so a Playwright spec (or any caller) can extract the\n // JSON payload without being thrown off by bootstrap log lines emitted\n // to stdout by other modules during DI container creation.\n console.log('---TOOL_TEST_REPORT_BEGIN---')\n console.log(JSON.stringify(report))\n console.log('---TOOL_TEST_REPORT_END---')\n } else {\n console.log('')\n console.log(\n `AI tool test report \u2014 tenant=${report.tenantId ?? '<none>'} org=${\n report.organizationId ?? '<none>'\n }`,\n )\n console.log(\n `total=${report.total} pass=${report.passed} fail=${report.failed} skip=${report.skipped}`,\n )\n const byModule = new Map<string, typeof report.records>()\n for (const record of report.records) {\n const list = byModule.get(record.module) ?? []\n list.push(record)\n byModule.set(record.module, list)\n }\n const sortedModules = Array.from(byModule.keys()).sort()\n for (const moduleId of sortedModules) {\n const list = byModule.get(moduleId)!\n console.log('')\n console.log(`${moduleId} (${list.length}):`)\n for (const record of list) {\n const marker =\n record.status === 'pass' ? '\u2713' : record.status === 'fail' ? '\u2717' : '\u00B7'\n const reason = record.reason ? ` \u2014 ${record.reason}` : ''\n const mutation = record.isMutation ? ' [mutation]' : ''\n console.log(\n ` ${marker} ${record.tool}${mutation} (${record.durationMs}ms)${reason}`,\n )\n }\n }\n console.log('')\n }\n\n if (report.failed > 0) {\n process.exitCode = 1\n }\n },\n}\n\nexport default [\n mcpServe,\n mcpServeHttp,\n mcpDev,\n listTools,\n entityGraph,\n runPendingActionCleanup,\n testTools,\n]\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,8BAA8B;AAMvC,eAAe,kBAAiC;AAE9C,MAAI;AACF,UAAM,EAAE,gBAAgB,IAAI,MAAM,OAAO,uCAAuC;AAChF,oBAAgB;AAChB;AAAA,EACF,QAAQ;AAAA,EAER;AAEA,MAAI;AACF,UAAM,EAAE,qBAAqB,IAAI,MAAM,OAAO,kDAAkD;AAChG,UAAM,qBAAqB;AAAA,EAC7B,SAAS,OAAO;AACd,YAAQ,MAAM,2BAA2B,iBAAiB,QAAQ,MAAM,UAAU,KAAK;AAAA,EAEzF;AACF;AAEA,SAAS,UAAU,MAAkD;AACnE,QAAM,OAAyC,CAAC;AAChD,WAAS,IAA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
|
3
|
+
"sources": ["../../../../../src/modules/ai_assistant/data/entities/AiAgentMutationPolicyOverride.ts"],
|
|
4
|
+
"sourcesContent": ["// Canonical entity class lives in `../entities.ts` (single-file aggregate, same\n// pattern as `packages/core/src/modules/customers/data/entities.ts`). This\n// thin re-export exists so call sites that prefer the by-name import path\n// (`.../entities/AiAgentMutationPolicyOverride`) keep working.\n\nexport { AiAgentMutationPolicyOverride } from '../entities'\nexport type { AiAgentMutationPolicyOverride as default } from '../entities'\n"],
|
|
5
|
+
"mappings": "AAKA,SAAS,qCAAqC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/modules/ai_assistant/data/entities/AiAgentPromptOverride.ts"],
|
|
4
|
+
"sourcesContent": ["// Canonical entity class lives in `../entities.ts` (single-file aggregate, same\n// pattern as `packages/core/src/modules/customers/data/entities.ts`). This\n// thin re-export exists so call sites that prefer the by-name import path\n// (`.../entities/AiAgentPromptOverride`) keep working.\n\nexport { AiAgentPromptOverride } from '../entities'\nexport type { AiAgentPromptOverride as default } from '../entities'\n"],
|
|
5
|
+
"mappings": "AAKA,SAAS,6BAA6B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/modules/ai_assistant/data/entities/AiPendingAction.ts"],
|
|
4
|
+
"sourcesContent": ["// Canonical entity class lives in `../entities.ts` (single-file aggregate, same\n// pattern as `packages/core/src/modules/customers/data/entities.ts`). This\n// thin re-export exists so call sites that prefer the by-name import path\n// (`.../entities/AiPendingAction`) keep working.\n\nexport { AiPendingAction } from '../entities'\nexport type { AiPendingAction as default } from '../entities'\n"],
|
|
5
|
+
"mappings": "AAKA,SAAS,uBAAuB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
import { OptionalProps } from "@mikro-orm/core";
|
|
12
|
+
import {
|
|
13
|
+
Entity,
|
|
14
|
+
Index,
|
|
15
|
+
PrimaryKey,
|
|
16
|
+
Property
|
|
17
|
+
} from "@mikro-orm/decorators/legacy";
|
|
18
|
+
OptionalProps;
|
|
19
|
+
let AiAgentPromptOverride = class {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.createdAt = /* @__PURE__ */ new Date();
|
|
22
|
+
this.updatedAt = /* @__PURE__ */ new Date();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
__decorateClass([
|
|
26
|
+
PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
|
|
27
|
+
], AiAgentPromptOverride.prototype, "id", 2);
|
|
28
|
+
__decorateClass([
|
|
29
|
+
Property({ name: "tenant_id", type: "uuid" })
|
|
30
|
+
], AiAgentPromptOverride.prototype, "tenantId", 2);
|
|
31
|
+
__decorateClass([
|
|
32
|
+
Property({ name: "organization_id", type: "uuid", nullable: true })
|
|
33
|
+
], AiAgentPromptOverride.prototype, "organizationId", 2);
|
|
34
|
+
__decorateClass([
|
|
35
|
+
Property({ name: "agent_id", type: "text" })
|
|
36
|
+
], AiAgentPromptOverride.prototype, "agentId", 2);
|
|
37
|
+
__decorateClass([
|
|
38
|
+
Property({ name: "version", type: "int" })
|
|
39
|
+
], AiAgentPromptOverride.prototype, "version", 2);
|
|
40
|
+
__decorateClass([
|
|
41
|
+
Property({ name: "sections", type: "jsonb" })
|
|
42
|
+
], AiAgentPromptOverride.prototype, "sections", 2);
|
|
43
|
+
__decorateClass([
|
|
44
|
+
Property({ name: "notes", type: "text", nullable: true })
|
|
45
|
+
], AiAgentPromptOverride.prototype, "notes", 2);
|
|
46
|
+
__decorateClass([
|
|
47
|
+
Property({ name: "created_by_user_id", type: "uuid", nullable: true })
|
|
48
|
+
], AiAgentPromptOverride.prototype, "createdByUserId", 2);
|
|
49
|
+
__decorateClass([
|
|
50
|
+
Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
|
|
51
|
+
], AiAgentPromptOverride.prototype, "createdAt", 2);
|
|
52
|
+
__decorateClass([
|
|
53
|
+
Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
|
|
54
|
+
], AiAgentPromptOverride.prototype, "updatedAt", 2);
|
|
55
|
+
AiAgentPromptOverride = __decorateClass([
|
|
56
|
+
Entity({ tableName: "ai_agent_prompt_overrides" }),
|
|
57
|
+
Index({
|
|
58
|
+
name: "ai_agent_prompt_overrides_tenant_org_agent_version_uq",
|
|
59
|
+
expression: 'create unique index "ai_agent_prompt_overrides_tenant_org_agent_version_uq" on "ai_agent_prompt_overrides" ("tenant_id", "organization_id", "agent_id", "version") where "organization_id" is not null'
|
|
60
|
+
}),
|
|
61
|
+
Index({
|
|
62
|
+
name: "ai_agent_prompt_overrides_tenant_agent_version_null_org_uq",
|
|
63
|
+
expression: 'create unique index "ai_agent_prompt_overrides_tenant_agent_version_null_org_uq" on "ai_agent_prompt_overrides" ("tenant_id", "agent_id", "version") where "organization_id" is null'
|
|
64
|
+
}),
|
|
65
|
+
Index({
|
|
66
|
+
name: "ai_agent_prompt_overrides_tenant_agent_idx",
|
|
67
|
+
properties: ["tenantId", "agentId"]
|
|
68
|
+
}),
|
|
69
|
+
Index({
|
|
70
|
+
name: "ai_agent_prompt_overrides_tenant_org_agent_version_idx",
|
|
71
|
+
expression: 'create index "ai_agent_prompt_overrides_tenant_org_agent_version_idx" on "ai_agent_prompt_overrides" ("tenant_id", "organization_id", "agent_id", "version" desc)'
|
|
72
|
+
})
|
|
73
|
+
], AiAgentPromptOverride);
|
|
74
|
+
OptionalProps;
|
|
75
|
+
let AiPendingAction = class {
|
|
76
|
+
constructor() {
|
|
77
|
+
this.fieldDiff = [];
|
|
78
|
+
this.attachmentIds = [];
|
|
79
|
+
this.queueMode = "inline";
|
|
80
|
+
this.createdAt = /* @__PURE__ */ new Date();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
__decorateClass([
|
|
84
|
+
PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
|
|
85
|
+
], AiPendingAction.prototype, "id", 2);
|
|
86
|
+
__decorateClass([
|
|
87
|
+
Property({ name: "tenant_id", type: "uuid" })
|
|
88
|
+
], AiPendingAction.prototype, "tenantId", 2);
|
|
89
|
+
__decorateClass([
|
|
90
|
+
Property({ name: "organization_id", type: "uuid", nullable: true })
|
|
91
|
+
], AiPendingAction.prototype, "organizationId", 2);
|
|
92
|
+
__decorateClass([
|
|
93
|
+
Property({ name: "agent_id", type: "text" })
|
|
94
|
+
], AiPendingAction.prototype, "agentId", 2);
|
|
95
|
+
__decorateClass([
|
|
96
|
+
Property({ name: "tool_name", type: "text" })
|
|
97
|
+
], AiPendingAction.prototype, "toolName", 2);
|
|
98
|
+
__decorateClass([
|
|
99
|
+
Property({ name: "conversation_id", type: "text", nullable: true })
|
|
100
|
+
], AiPendingAction.prototype, "conversationId", 2);
|
|
101
|
+
__decorateClass([
|
|
102
|
+
Property({ name: "target_entity_type", type: "text", nullable: true })
|
|
103
|
+
], AiPendingAction.prototype, "targetEntityType", 2);
|
|
104
|
+
__decorateClass([
|
|
105
|
+
Property({ name: "target_record_id", type: "text", nullable: true })
|
|
106
|
+
], AiPendingAction.prototype, "targetRecordId", 2);
|
|
107
|
+
__decorateClass([
|
|
108
|
+
Property({ name: "normalized_input", type: "jsonb" })
|
|
109
|
+
], AiPendingAction.prototype, "normalizedInput", 2);
|
|
110
|
+
__decorateClass([
|
|
111
|
+
Property({ name: "field_diff", type: "jsonb", default: [] })
|
|
112
|
+
], AiPendingAction.prototype, "fieldDiff", 2);
|
|
113
|
+
__decorateClass([
|
|
114
|
+
Property({ name: "records", type: "jsonb", nullable: true })
|
|
115
|
+
], AiPendingAction.prototype, "records", 2);
|
|
116
|
+
__decorateClass([
|
|
117
|
+
Property({ name: "failed_records", type: "jsonb", nullable: true })
|
|
118
|
+
], AiPendingAction.prototype, "failedRecords", 2);
|
|
119
|
+
__decorateClass([
|
|
120
|
+
Property({ name: "side_effects_summary", type: "text", nullable: true })
|
|
121
|
+
], AiPendingAction.prototype, "sideEffectsSummary", 2);
|
|
122
|
+
__decorateClass([
|
|
123
|
+
Property({ name: "record_version", type: "text", nullable: true })
|
|
124
|
+
], AiPendingAction.prototype, "recordVersion", 2);
|
|
125
|
+
__decorateClass([
|
|
126
|
+
Property({ name: "attachment_ids", type: "jsonb", default: [] })
|
|
127
|
+
], AiPendingAction.prototype, "attachmentIds", 2);
|
|
128
|
+
__decorateClass([
|
|
129
|
+
Property({ name: "idempotency_key", type: "text" })
|
|
130
|
+
], AiPendingAction.prototype, "idempotencyKey", 2);
|
|
131
|
+
__decorateClass([
|
|
132
|
+
Property({ name: "created_by_user_id", type: "uuid" })
|
|
133
|
+
], AiPendingAction.prototype, "createdByUserId", 2);
|
|
134
|
+
__decorateClass([
|
|
135
|
+
Property({ name: "status", type: "text" })
|
|
136
|
+
], AiPendingAction.prototype, "status", 2);
|
|
137
|
+
__decorateClass([
|
|
138
|
+
Property({ name: "queue_mode", type: "text", default: "inline" })
|
|
139
|
+
], AiPendingAction.prototype, "queueMode", 2);
|
|
140
|
+
__decorateClass([
|
|
141
|
+
Property({ name: "execution_result", type: "jsonb", nullable: true })
|
|
142
|
+
], AiPendingAction.prototype, "executionResult", 2);
|
|
143
|
+
__decorateClass([
|
|
144
|
+
Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
|
|
145
|
+
], AiPendingAction.prototype, "createdAt", 2);
|
|
146
|
+
__decorateClass([
|
|
147
|
+
Property({ name: "expires_at", type: Date })
|
|
148
|
+
], AiPendingAction.prototype, "expiresAt", 2);
|
|
149
|
+
__decorateClass([
|
|
150
|
+
Property({ name: "resolved_at", type: Date, nullable: true })
|
|
151
|
+
], AiPendingAction.prototype, "resolvedAt", 2);
|
|
152
|
+
__decorateClass([
|
|
153
|
+
Property({ name: "resolved_by_user_id", type: "uuid", nullable: true })
|
|
154
|
+
], AiPendingAction.prototype, "resolvedByUserId", 2);
|
|
155
|
+
AiPendingAction = __decorateClass([
|
|
156
|
+
Entity({ tableName: "ai_pending_actions" }),
|
|
157
|
+
Index({
|
|
158
|
+
name: "ai_pending_actions_tenant_org_idempotency_uq",
|
|
159
|
+
expression: 'create unique index "ai_pending_actions_tenant_org_idempotency_uq" on "ai_pending_actions" ("tenant_id", "organization_id", "idempotency_key") where "organization_id" is not null'
|
|
160
|
+
}),
|
|
161
|
+
Index({
|
|
162
|
+
name: "ai_pending_actions_tenant_idem_null_org_uq",
|
|
163
|
+
expression: 'create unique index "ai_pending_actions_tenant_idem_null_org_uq" on "ai_pending_actions" ("tenant_id", "idempotency_key") where "organization_id" is null'
|
|
164
|
+
}),
|
|
165
|
+
Index({
|
|
166
|
+
name: "ai_pending_actions_tenant_org_status_expires_idx",
|
|
167
|
+
properties: ["tenantId", "organizationId", "status", "expiresAt"]
|
|
168
|
+
}),
|
|
169
|
+
Index({
|
|
170
|
+
name: "ai_pending_actions_tenant_org_agent_status_idx",
|
|
171
|
+
properties: ["tenantId", "organizationId", "agentId", "status"]
|
|
172
|
+
})
|
|
173
|
+
], AiPendingAction);
|
|
174
|
+
OptionalProps;
|
|
175
|
+
let AiAgentMutationPolicyOverride = class {
|
|
176
|
+
constructor() {
|
|
177
|
+
this.createdAt = /* @__PURE__ */ new Date();
|
|
178
|
+
this.updatedAt = /* @__PURE__ */ new Date();
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
__decorateClass([
|
|
182
|
+
PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
|
|
183
|
+
], AiAgentMutationPolicyOverride.prototype, "id", 2);
|
|
184
|
+
__decorateClass([
|
|
185
|
+
Property({ name: "tenant_id", type: "uuid" })
|
|
186
|
+
], AiAgentMutationPolicyOverride.prototype, "tenantId", 2);
|
|
187
|
+
__decorateClass([
|
|
188
|
+
Property({ name: "organization_id", type: "uuid", nullable: true })
|
|
189
|
+
], AiAgentMutationPolicyOverride.prototype, "organizationId", 2);
|
|
190
|
+
__decorateClass([
|
|
191
|
+
Property({ name: "agent_id", type: "text" })
|
|
192
|
+
], AiAgentMutationPolicyOverride.prototype, "agentId", 2);
|
|
193
|
+
__decorateClass([
|
|
194
|
+
Property({ name: "mutation_policy", type: "text" })
|
|
195
|
+
], AiAgentMutationPolicyOverride.prototype, "mutationPolicy", 2);
|
|
196
|
+
__decorateClass([
|
|
197
|
+
Property({ name: "notes", type: "text", nullable: true })
|
|
198
|
+
], AiAgentMutationPolicyOverride.prototype, "notes", 2);
|
|
199
|
+
__decorateClass([
|
|
200
|
+
Property({ name: "created_by_user_id", type: "uuid", nullable: true })
|
|
201
|
+
], AiAgentMutationPolicyOverride.prototype, "createdByUserId", 2);
|
|
202
|
+
__decorateClass([
|
|
203
|
+
Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
|
|
204
|
+
], AiAgentMutationPolicyOverride.prototype, "createdAt", 2);
|
|
205
|
+
__decorateClass([
|
|
206
|
+
Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
|
|
207
|
+
], AiAgentMutationPolicyOverride.prototype, "updatedAt", 2);
|
|
208
|
+
AiAgentMutationPolicyOverride = __decorateClass([
|
|
209
|
+
Entity({ tableName: "ai_agent_mutation_policy_overrides" }),
|
|
210
|
+
Index({
|
|
211
|
+
name: "ai_agent_mutation_policy_overrides_tenant_org_agent_uq",
|
|
212
|
+
expression: 'create unique index "ai_agent_mutation_policy_overrides_tenant_org_agent_uq" on "ai_agent_mutation_policy_overrides" ("tenant_id", "organization_id", "agent_id") where "organization_id" is not null'
|
|
213
|
+
}),
|
|
214
|
+
Index({
|
|
215
|
+
name: "ai_agent_mutation_policy_overrides_tenant_agent_null_org_uq",
|
|
216
|
+
expression: 'create unique index "ai_agent_mutation_policy_overrides_tenant_agent_null_org_uq" on "ai_agent_mutation_policy_overrides" ("tenant_id", "agent_id") where "organization_id" is null'
|
|
217
|
+
}),
|
|
218
|
+
Index({
|
|
219
|
+
name: "ai_agent_mutation_policy_overrides_tenant_agent_idx",
|
|
220
|
+
properties: ["tenantId", "agentId"]
|
|
221
|
+
})
|
|
222
|
+
], AiAgentMutationPolicyOverride);
|
|
223
|
+
export {
|
|
224
|
+
AiAgentMutationPolicyOverride,
|
|
225
|
+
AiAgentPromptOverride,
|
|
226
|
+
AiPendingAction
|
|
227
|
+
};
|
|
228
|
+
//# sourceMappingURL=entities.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/ai_assistant/data/entities.ts"],
|
|
4
|
+
"sourcesContent": ["import { OptionalProps } from '@mikro-orm/core'\nimport {\n Entity,\n Index,\n PrimaryKey,\n Property,\n} from '@mikro-orm/decorators/legacy'\nimport type {\n AiPendingActionExecutionResult,\n AiPendingActionFailedRecord,\n AiPendingActionFieldDiff,\n AiPendingActionQueueMode,\n AiPendingActionRecordDiff,\n AiPendingActionStatus,\n} from '../lib/pending-action-types'\n\n/**\n * Versioned additive prompt-override for a registered AI agent (Step 5.3).\n *\n * Each write creates a new row with `version = latest + 1`. Rows are never\n * updated in place \u2014 history is preserved so operators can roll back by\n * reading an earlier `version`. Column set is tenant/org-scoped per the\n * standard Open Mercato RBAC contract.\n *\n * `sections` holds additive text keyed by prompt section id. The runtime\n * composes the final `systemPrompt` via `composeSystemPromptWithOverride`\n * (see `lib/prompt-override-merge.ts`), which NEVER replaces a built-in\n * section \u2014 overrides are append-only by contract.\n */\n@Entity({ tableName: 'ai_agent_prompt_overrides' })\n@Index({\n name: 'ai_agent_prompt_overrides_tenant_org_agent_version_uq',\n expression:\n 'create unique index \"ai_agent_prompt_overrides_tenant_org_agent_version_uq\" on \"ai_agent_prompt_overrides\" (\"tenant_id\", \"organization_id\", \"agent_id\", \"version\") where \"organization_id\" is not null',\n})\n@Index({\n name: 'ai_agent_prompt_overrides_tenant_agent_version_null_org_uq',\n expression:\n 'create unique index \"ai_agent_prompt_overrides_tenant_agent_version_null_org_uq\" on \"ai_agent_prompt_overrides\" (\"tenant_id\", \"agent_id\", \"version\") where \"organization_id\" is null',\n})\n@Index({\n name: 'ai_agent_prompt_overrides_tenant_agent_idx',\n properties: ['tenantId', 'agentId'],\n})\n@Index({\n name: 'ai_agent_prompt_overrides_tenant_org_agent_version_idx',\n expression:\n 'create index \"ai_agent_prompt_overrides_tenant_org_agent_version_idx\" on \"ai_agent_prompt_overrides\" (\"tenant_id\", \"organization_id\", \"agent_id\", \"version\" desc)',\n})\nexport class AiAgentPromptOverride {\n [OptionalProps]?: 'createdAt' | 'updatedAt' | 'organizationId' | 'createdByUserId' | 'notes'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'organization_id', type: 'uuid', nullable: true })\n organizationId?: string | null\n\n @Property({ name: 'agent_id', type: 'text' })\n agentId!: string\n\n @Property({ name: 'version', type: 'int' })\n version!: number\n\n @Property({ name: 'sections', type: 'jsonb' })\n sections!: Record<string, string>\n\n @Property({ name: 'notes', type: 'text', nullable: true })\n notes?: string | null\n\n @Property({ name: 'created_by_user_id', type: 'uuid', nullable: true })\n createdByUserId?: string | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n}\n\n/**\n * Persistent mutation-approval gate row backing the Phase 3 WS-C contract\n * (spec \u00A78 `AiPendingAction` + \u00A79 confirm/cancel flow, Step 5.5).\n *\n * One row is created by `prepareMutation` (Step 5.6) whenever the runtime\n * intercepts an `isMutation: true` tool call from a non-read-only agent.\n * The row stores the normalized tool input, a precomputed `fieldDiff` (or\n * per-record batch diff in `records[]`), the target record version, an\n * `idempotencyKey` that dedupes double-submits within the TTL, and a\n * `status` that walks the state machine defined in\n * {@link AI_PENDING_ACTION_ALLOWED_TRANSITIONS}.\n *\n * The cleanup worker (Step 5.12) sweeps `status='pending' AND expiresAt < now`\n * rows and transitions them to `expired`. The confirm route (Step 5.8)\n * walks `pending \u2192 confirmed \u2192 executing \u2192 (failed | terminal success)`.\n * Reads always flow through `findOneWithDecryption` /\n * `findWithDecryption`, even though no column is GDPR-flagged today, so\n * future encrypted columns (e.g. `normalizedInput`) are handled.\n */\n@Entity({ tableName: 'ai_pending_actions' })\n@Index({\n name: 'ai_pending_actions_tenant_org_idempotency_uq',\n expression:\n 'create unique index \"ai_pending_actions_tenant_org_idempotency_uq\" on \"ai_pending_actions\" (\"tenant_id\", \"organization_id\", \"idempotency_key\") where \"organization_id\" is not null',\n})\n@Index({\n name: 'ai_pending_actions_tenant_idem_null_org_uq',\n expression:\n 'create unique index \"ai_pending_actions_tenant_idem_null_org_uq\" on \"ai_pending_actions\" (\"tenant_id\", \"idempotency_key\") where \"organization_id\" is null',\n})\n@Index({\n name: 'ai_pending_actions_tenant_org_status_expires_idx',\n properties: ['tenantId', 'organizationId', 'status', 'expiresAt'],\n})\n@Index({\n name: 'ai_pending_actions_tenant_org_agent_status_idx',\n properties: ['tenantId', 'organizationId', 'agentId', 'status'],\n})\nexport class AiPendingAction {\n [OptionalProps]?:\n | 'createdAt'\n | 'organizationId'\n | 'conversationId'\n | 'targetEntityType'\n | 'targetRecordId'\n | 'fieldDiff'\n | 'records'\n | 'failedRecords'\n | 'sideEffectsSummary'\n | 'recordVersion'\n | 'attachmentIds'\n | 'executionResult'\n | 'resolvedAt'\n | 'resolvedByUserId'\n | 'queueMode'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'organization_id', type: 'uuid', nullable: true })\n organizationId?: string | null\n\n @Property({ name: 'agent_id', type: 'text' })\n agentId!: string\n\n @Property({ name: 'tool_name', type: 'text' })\n toolName!: string\n\n @Property({ name: 'conversation_id', type: 'text', nullable: true })\n conversationId?: string | null\n\n @Property({ name: 'target_entity_type', type: 'text', nullable: true })\n targetEntityType?: string | null\n\n @Property({ name: 'target_record_id', type: 'text', nullable: true })\n targetRecordId?: string | null\n\n @Property({ name: 'normalized_input', type: 'jsonb' })\n normalizedInput!: Record<string, unknown>\n\n @Property({ name: 'field_diff', type: 'jsonb', default: [] })\n fieldDiff: AiPendingActionFieldDiff[] = []\n\n @Property({ name: 'records', type: 'jsonb', nullable: true })\n records?: AiPendingActionRecordDiff[] | null\n\n @Property({ name: 'failed_records', type: 'jsonb', nullable: true })\n failedRecords?: AiPendingActionFailedRecord[] | null\n\n @Property({ name: 'side_effects_summary', type: 'text', nullable: true })\n sideEffectsSummary?: string | null\n\n @Property({ name: 'record_version', type: 'text', nullable: true })\n recordVersion?: string | null\n\n @Property({ name: 'attachment_ids', type: 'jsonb', default: [] })\n attachmentIds: string[] = []\n\n @Property({ name: 'idempotency_key', type: 'text' })\n idempotencyKey!: string\n\n @Property({ name: 'created_by_user_id', type: 'uuid' })\n createdByUserId!: string\n\n @Property({ name: 'status', type: 'text' })\n status!: AiPendingActionStatus\n\n @Property({ name: 'queue_mode', type: 'text', default: 'inline' })\n queueMode: AiPendingActionQueueMode = 'inline'\n\n @Property({ name: 'execution_result', type: 'jsonb', nullable: true })\n executionResult?: AiPendingActionExecutionResult | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'expires_at', type: Date })\n expiresAt!: Date\n\n @Property({ name: 'resolved_at', type: Date, nullable: true })\n resolvedAt?: Date | null\n\n @Property({ name: 'resolved_by_user_id', type: 'uuid', nullable: true })\n resolvedByUserId?: string | null\n}\n\n/**\n * Tenant-scoped override of an agent's declared `mutationPolicy` (Step 5.4).\n *\n * Unlike {@link AiAgentPromptOverride}, this surface is NOT versioned \u2014 it is\n * a single-value policy switch per `(tenantId, organizationId, agentId)`. The\n * runtime enforces the override as a DOWNGRADE only: the effective policy\n * equals the MOST RESTRICTIVE of `{ code-declared, override }`. Escalation is\n * a code-level change and is rejected at the route layer.\n *\n * Hierarchy (most restrictive \u2192 least): `read-only` < `destructive-confirm-required`\n * < `confirm-required`. The route never allows an override to widen the\n * code-declared policy.\n */\n@Entity({ tableName: 'ai_agent_mutation_policy_overrides' })\n@Index({\n name: 'ai_agent_mutation_policy_overrides_tenant_org_agent_uq',\n expression:\n 'create unique index \"ai_agent_mutation_policy_overrides_tenant_org_agent_uq\" on \"ai_agent_mutation_policy_overrides\" (\"tenant_id\", \"organization_id\", \"agent_id\") where \"organization_id\" is not null',\n})\n@Index({\n name: 'ai_agent_mutation_policy_overrides_tenant_agent_null_org_uq',\n expression:\n 'create unique index \"ai_agent_mutation_policy_overrides_tenant_agent_null_org_uq\" on \"ai_agent_mutation_policy_overrides\" (\"tenant_id\", \"agent_id\") where \"organization_id\" is null',\n})\n@Index({\n name: 'ai_agent_mutation_policy_overrides_tenant_agent_idx',\n properties: ['tenantId', 'agentId'],\n})\nexport class AiAgentMutationPolicyOverride {\n [OptionalProps]?: 'createdAt' | 'updatedAt' | 'organizationId' | 'createdByUserId' | 'notes'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'organization_id', type: 'uuid', nullable: true })\n organizationId?: string | null\n\n @Property({ name: 'agent_id', type: 'text' })\n agentId!: string\n\n @Property({ name: 'mutation_policy', type: 'text' })\n mutationPolicy!: string\n\n @Property({ name: 'notes', type: 'text', nullable: true })\n notes?: string | null\n\n @Property({ name: 'created_by_user_id', type: 'uuid', nullable: true })\n createdByUserId?: string | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;AAAA,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA4CJ;AADI,IAAM,wBAAN,MAA4B;AAAA,EAA5B;AA4BL,qBAAkB,oBAAI,KAAK;AAG3B,qBAAkB,oBAAI,KAAK;AAAA;AAC7B;AA5BE;AAAA,EADC,WAAW,EAAE,MAAM,QAAQ,YAAY,oBAAoB,CAAC;AAAA,GAHlD,sBAIX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,aAAa,MAAM,OAAO,CAAC;AAAA,GANlC,sBAOX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,mBAAmB,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GATxD,sBAUX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,YAAY,MAAM,OAAO,CAAC;AAAA,GAZjC,sBAaX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,WAAW,MAAM,MAAM,CAAC;AAAA,GAf/B,sBAgBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,YAAY,MAAM,QAAQ,CAAC;AAAA,GAlBlC,sBAmBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,SAAS,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GArB9C,sBAsBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,sB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X;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,mBAAmB,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GATxD,8BAUX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,YAAY,MAAM,OAAO,CAAC;AAAA,GAZjC,8BAaX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,mBAAmB,MAAM,OAAO,CAAC;AAAA,GAfxC,8BAgBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,SAAS,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GAlB9C,8BAmBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,sBAAsB,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GArB3D,8BAsBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,cAAc,MAAM,MAAM,UAAU,MAAM,oBAAI,KAAK,EAAE,CAAC;AAAA,GAxB7D,8BAyBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,cAAc,MAAM,MAAM,UAAU,MAAM,oBAAI,KAAK,EAAE,CAAC;AAAA,GA3B7D,8BA4BX;AA5BW,gCAAN;AAAA,EAfN,OAAO,EAAE,WAAW,qCAAqC,CAAC;AAAA,EAC1D,MAAM;AAAA,IACL,MAAM;AAAA,IACN,YACE;AAAA,EACJ,CAAC;AAAA,EACA,MAAM;AAAA,IACL,MAAM;AAAA,IACN,YACE;AAAA,EACJ,CAAC;AAAA,EACA,MAAM;AAAA,IACL,MAAM;AAAA,IACN,YAAY,CAAC,YAAY,SAAS;AAAA,EACpC,CAAC;AAAA,GACY;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/modules/ai_assistant/data/repositories/AiAgentMutationPolicyOverrideRepository.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
findOneWithDecryption
|
|
3
|
+
} from "@open-mercato/shared/lib/encryption/find";
|
|
4
|
+
import { AiAgentMutationPolicyOverride } from "../entities.js";
|
|
5
|
+
class AiAgentMutationPolicyOverrideRepository {
|
|
6
|
+
constructor(em) {
|
|
7
|
+
this.em = em;
|
|
8
|
+
}
|
|
9
|
+
async get(agentId, ctx) {
|
|
10
|
+
if (!agentId || !ctx?.tenantId) return null;
|
|
11
|
+
const row = await findOneWithDecryption(
|
|
12
|
+
this.em,
|
|
13
|
+
AiAgentMutationPolicyOverride,
|
|
14
|
+
{
|
|
15
|
+
tenantId: ctx.tenantId,
|
|
16
|
+
organizationId: ctx.organizationId ?? null,
|
|
17
|
+
agentId
|
|
18
|
+
},
|
|
19
|
+
{},
|
|
20
|
+
{ tenantId: ctx.tenantId ?? null, organizationId: ctx.organizationId ?? null }
|
|
21
|
+
);
|
|
22
|
+
return row ?? null;
|
|
23
|
+
}
|
|
24
|
+
async set(input, ctx) {
|
|
25
|
+
if (!ctx?.tenantId) {
|
|
26
|
+
throw new Error("AiAgentMutationPolicyOverrideRepository.set requires tenantId");
|
|
27
|
+
}
|
|
28
|
+
if (!input?.agentId) {
|
|
29
|
+
throw new Error("AiAgentMutationPolicyOverrideRepository.set requires agentId");
|
|
30
|
+
}
|
|
31
|
+
const normalized = normalizeNotes(input.notes);
|
|
32
|
+
return this.em.transactional(async (tx) => {
|
|
33
|
+
const existing = await findOneWithDecryption(
|
|
34
|
+
tx,
|
|
35
|
+
AiAgentMutationPolicyOverride,
|
|
36
|
+
{
|
|
37
|
+
tenantId: ctx.tenantId,
|
|
38
|
+
organizationId: ctx.organizationId ?? null,
|
|
39
|
+
agentId: input.agentId
|
|
40
|
+
},
|
|
41
|
+
{},
|
|
42
|
+
{ tenantId: ctx.tenantId ?? null, organizationId: ctx.organizationId ?? null }
|
|
43
|
+
);
|
|
44
|
+
if (existing) {
|
|
45
|
+
existing.mutationPolicy = input.mutationPolicy;
|
|
46
|
+
existing.notes = normalized;
|
|
47
|
+
existing.createdByUserId = ctx.userId ?? existing.createdByUserId ?? null;
|
|
48
|
+
existing.updatedAt = /* @__PURE__ */ new Date();
|
|
49
|
+
await tx.persist(existing).flush();
|
|
50
|
+
return existing;
|
|
51
|
+
}
|
|
52
|
+
const row = tx.create(AiAgentMutationPolicyOverride, {
|
|
53
|
+
tenantId: ctx.tenantId,
|
|
54
|
+
organizationId: ctx.organizationId ?? null,
|
|
55
|
+
agentId: input.agentId,
|
|
56
|
+
mutationPolicy: input.mutationPolicy,
|
|
57
|
+
notes: normalized,
|
|
58
|
+
createdByUserId: ctx.userId ?? null
|
|
59
|
+
});
|
|
60
|
+
await tx.persist(row).flush();
|
|
61
|
+
return row;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async clear(agentId, ctx) {
|
|
65
|
+
if (!agentId || !ctx?.tenantId) return false;
|
|
66
|
+
return this.em.transactional(async (tx) => {
|
|
67
|
+
const existing = await findOneWithDecryption(
|
|
68
|
+
tx,
|
|
69
|
+
AiAgentMutationPolicyOverride,
|
|
70
|
+
{
|
|
71
|
+
tenantId: ctx.tenantId,
|
|
72
|
+
organizationId: ctx.organizationId ?? null,
|
|
73
|
+
agentId
|
|
74
|
+
},
|
|
75
|
+
{},
|
|
76
|
+
{ tenantId: ctx.tenantId ?? null, organizationId: ctx.organizationId ?? null }
|
|
77
|
+
);
|
|
78
|
+
if (!existing) return false;
|
|
79
|
+
await tx.remove(existing).flush();
|
|
80
|
+
return true;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function normalizeNotes(notes) {
|
|
85
|
+
if (typeof notes !== "string") return null;
|
|
86
|
+
const trimmed = notes.trim();
|
|
87
|
+
if (!trimmed) return null;
|
|
88
|
+
return notes;
|
|
89
|
+
}
|
|
90
|
+
var AiAgentMutationPolicyOverrideRepository_default = AiAgentMutationPolicyOverrideRepository;
|
|
91
|
+
export {
|
|
92
|
+
AiAgentMutationPolicyOverrideRepository,
|
|
93
|
+
AiAgentMutationPolicyOverrideRepository_default as default
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=AiAgentMutationPolicyOverrideRepository.js.map
|
package/dist/modules/ai_assistant/data/repositories/AiAgentMutationPolicyOverrideRepository.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/modules/ai_assistant/data/repositories/AiAgentMutationPolicyOverrideRepository.ts"],
|
|
4
|
+
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport {\n findOneWithDecryption,\n} from '@open-mercato/shared/lib/encryption/find'\nimport { AiAgentMutationPolicyOverride } from '../entities'\nimport type { AiAgentMutationPolicy } from '../../lib/ai-agent-definition'\n\nexport interface AiAgentMutationPolicyOverrideContext {\n tenantId: string\n organizationId?: string | null\n userId?: string | null\n}\n\nexport interface AiAgentMutationPolicyOverrideInput {\n agentId: string\n mutationPolicy: AiAgentMutationPolicy\n notes?: string | null\n}\n\n/**\n * Single-value mutation-policy override repository (Step 5.4).\n *\n * Unlike the versioned prompt override, there is ONE current mutation-policy\n * override per `(tenantId, organizationId, agentId)`. `set()` replaces the\n * existing row (or inserts a new one) inside a transaction so concurrent\n * writers cannot produce ghost rows. `clear()` deletes the row so the runtime\n * falls back to the code-declared policy.\n *\n * Reads always go through `findOneWithDecryption` to stay consistent with the\n * rest of the module even though `mutation_policy` isn't encrypted today.\n */\nexport class AiAgentMutationPolicyOverrideRepository {\n constructor(private readonly em: EntityManager) {}\n\n async get(\n agentId: string,\n ctx: AiAgentMutationPolicyOverrideContext,\n ): Promise<AiAgentMutationPolicyOverride | null> {\n if (!agentId || !ctx?.tenantId) return null\n const row = await findOneWithDecryption<AiAgentMutationPolicyOverride>(\n this.em,\n AiAgentMutationPolicyOverride,\n {\n tenantId: ctx.tenantId,\n organizationId: ctx.organizationId ?? null,\n agentId,\n } as any,\n {},\n { tenantId: ctx.tenantId ?? null, organizationId: ctx.organizationId ?? null },\n )\n return row ?? null\n }\n\n async set(\n input: AiAgentMutationPolicyOverrideInput,\n ctx: AiAgentMutationPolicyOverrideContext,\n ): Promise<AiAgentMutationPolicyOverride> {\n if (!ctx?.tenantId) {\n throw new Error('AiAgentMutationPolicyOverrideRepository.set requires tenantId')\n }\n if (!input?.agentId) {\n throw new Error('AiAgentMutationPolicyOverrideRepository.set requires agentId')\n }\n const normalized = normalizeNotes(input.notes)\n return this.em.transactional(async (tx) => {\n const existing = await findOneWithDecryption<AiAgentMutationPolicyOverride>(\n tx as unknown as EntityManager,\n AiAgentMutationPolicyOverride,\n {\n tenantId: ctx.tenantId,\n organizationId: ctx.organizationId ?? null,\n agentId: input.agentId,\n } as any,\n {},\n { tenantId: ctx.tenantId ?? null, organizationId: ctx.organizationId ?? null },\n )\n if (existing) {\n existing.mutationPolicy = input.mutationPolicy\n existing.notes = normalized\n existing.createdByUserId = ctx.userId ?? existing.createdByUserId ?? null\n existing.updatedAt = new Date()\n await tx.persist(existing).flush()\n return existing\n }\n const row = tx.create(AiAgentMutationPolicyOverride, {\n tenantId: ctx.tenantId,\n organizationId: ctx.organizationId ?? null,\n agentId: input.agentId,\n mutationPolicy: input.mutationPolicy,\n notes: normalized,\n createdByUserId: ctx.userId ?? null,\n } as unknown as AiAgentMutationPolicyOverride)\n await tx.persist(row).flush()\n return row\n })\n }\n\n async clear(\n agentId: string,\n ctx: AiAgentMutationPolicyOverrideContext,\n ): Promise<boolean> {\n if (!agentId || !ctx?.tenantId) return false\n return this.em.transactional(async (tx) => {\n const existing = await findOneWithDecryption<AiAgentMutationPolicyOverride>(\n tx as unknown as EntityManager,\n AiAgentMutationPolicyOverride,\n {\n tenantId: ctx.tenantId,\n organizationId: ctx.organizationId ?? null,\n agentId,\n } as any,\n {},\n { tenantId: ctx.tenantId ?? null, organizationId: ctx.organizationId ?? null },\n )\n if (!existing) return false\n await tx.remove(existing).flush()\n return true\n })\n }\n}\n\nfunction normalizeNotes(notes: string | null | undefined): string | null {\n if (typeof notes !== 'string') return null\n const trimmed = notes.trim()\n if (!trimmed) return null\n return notes\n}\n\nexport default AiAgentMutationPolicyOverrideRepository\n"],
|
|
5
|
+
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