@open-mercato/ai-assistant 0.11.1-develop.8305.1.6a9c271838 → 0.11.1-develop.8317.1.dde3d38b64
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/dist/modules/ai_assistant/lib/agent-policy.js.map +2 -2
- package/dist/modules/ai_assistant/lib/agent-runtime.js +7 -6
- package/dist/modules/ai_assistant/lib/agent-runtime.js.map +2 -2
- package/dist/modules/ai_assistant/lib/agent-tools.js +18 -5
- package/dist/modules/ai_assistant/lib/agent-tools.js.map +2 -2
- package/package.json +6 -6
- package/src/modules/ai_assistant/lib/__tests__/agent-runtime-object-channel.test.ts +51 -2
- package/src/modules/ai_assistant/lib/__tests__/agent-tool.test.ts +79 -1
- package/src/modules/ai_assistant/lib/__tests__/agent-tools.test.ts +99 -0
- package/src/modules/ai_assistant/lib/__tests__/direct-execution-approval-paths.test.ts +26 -0
- package/src/modules/ai_assistant/lib/agent-policy.ts +4 -2
- package/src/modules/ai_assistant/lib/agent-runtime.ts +8 -3
- package/src/modules/ai_assistant/lib/agent-tools.ts +27 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/ai_assistant/lib/agent-policy.ts"],
|
|
4
|
-
"sourcesContent": ["import { createLogger } from '@open-mercato/shared/lib/logger'\nimport { getAgent } from './agent-registry'\nimport { hasRequiredFeatures } from './auth'\nimport { toolRegistry } from './tool-registry'\nimport type {\n AiAgentAcceptedMediaType,\n AiAgentDefinition,\n AiAgentMutationPolicy,\n} from './ai-agent-definition'\nimport type { AiToolDefinition } from './types'\n\nconst logger = createLogger('ai_assistant')\n\nexport type AgentPolicyDenyCode =\n | 'agent_unknown'\n | 'agent_features_denied'\n | 'tool_not_whitelisted'\n | 'tool_unknown'\n | 'tool_features_denied'\n | 'mutation_blocked_by_readonly'\n | 'mutation_blocked_by_policy'\n | 'execution_mode_not_supported'\n | 'attachment_type_not_accepted'\n // Loop policy codes \u2014 Phase 0 of spec 2026-04-28-ai-agents-agentic-loop-controls\n /** Object-mode rejects loop primitives that the SDK ignores for generateObject. */\n | 'loop_unsupported_in_object_mode'\n /** User prepareStep returned a tools map with a raw (unwrapped) mutation handler. */\n | 'loop_violates_mutation_policy'\n /** loop.activeTools contained names outside agent.allowedTools (thrown for caller-supplied overrides; warning-only for agent-declared). */\n | 'loop_active_tools_outside_allowlist'\n /** agent.loop.allowRuntimeOverride is false and a per-call loop override was supplied. */\n | 'loop_runtime_override_disabled'\n\nexport type AgentPolicyDecision =\n | { ok: true; agent: AiAgentDefinition; tool?: AiToolDefinition }\n | { ok: false; code: AgentPolicyDenyCode; message: string }\n\nexport interface AgentPolicyAuthContext {\n userFeatures: string[]\n isSuperAdmin: boolean\n}\n\nexport interface AgentPolicyCheckInput {\n agentId: string\n authContext: AgentPolicyAuthContext\n toolName?: string\n attachmentMediaTypes?: string[]\n requestedExecutionMode?: 'chat' | 'object'\n /**\n * Optional tenant-scoped downgrade for the agent's code-declared\n * `mutationPolicy`. When supplied, the effective policy is the MOST\n * RESTRICTIVE of `{ code-declared, override }` \u2014 escalation is never\n * allowed through this channel (that is enforced at the route layer).\n * Callers that omit this field get the exact pre-Step-5.4 behavior.\n */\n mutationPolicyOverride?: AiAgentMutationPolicy | null\n}\n\n/**\n * Restrictiveness ranking of `AiAgentMutationPolicy` (most restrictive first).\n * `read-only` blocks all mutation tools. `destructive-confirm-required` forces\n * confirmation for every write (including non-destructive ones). `confirm-required`\n * is the least restrictive policy \u2014 writes go through a single confirmation.\n *\n * This ordering is load-bearing for both the runtime's effective-policy\n * computation AND the route-layer escalation guard. Changing the order is a\n * security-sensitive change.\n */\nconst POLICY_RESTRICTIVENESS: Record<AiAgentMutationPolicy, number> = {\n 'read-only': 0,\n 'destructive-confirm-required': 1,\n 'confirm-required': 2,\n}\n\nexport function isKnownMutationPolicy(value: unknown): value is AiAgentMutationPolicy {\n return (\n value === 'read-only' ||\n value === 'confirm-required' ||\n value === 'destructive-confirm-required'\n )\n}\n\n/**\n * Returns the effective mutation policy \u2014 the MOST RESTRICTIVE of\n * `{ codeDeclared, override }`. Missing override \u2192 `codeDeclared`. A corrupt\n * override value (unknown string from DB) is logged and falls back to\n * `codeDeclared` so the system fails SAFE when a schema drift leaks through.\n */\nexport function resolveEffectiveMutationPolicy(\n codeDeclared: AiAgentMutationPolicy | undefined,\n override: AiAgentMutationPolicy | null | undefined,\n agentId?: string,\n): AiAgentMutationPolicy {\n const base: AiAgentMutationPolicy =\n codeDeclared && isKnownMutationPolicy(codeDeclared) ? codeDeclared : 'read-only'\n if (override === undefined || override === null) return base\n if (!isKnownMutationPolicy(override)) {\n logger.warn('Ignoring corrupt mutationPolicy override; falling back to code-declared policy', {\n agentId: agentId ?? '<unknown>',\n override: String(override),\n base,\n })\n return base\n }\n const baseRank = POLICY_RESTRICTIVENESS[base]\n const overrideRank = POLICY_RESTRICTIVENESS[override]\n return overrideRank < baseRank ? override : base\n}\n\n/**\n * Returns `true` when `candidate` would WIDEN `codeDeclared` \u2014 i.e. would\n * grant the agent more mutation surface than its code declares. Used by the\n * mutation-policy override route to reject escalation attempts with 400.\n */\nexport function isMutationPolicyEscalation(\n codeDeclared: AiAgentMutationPolicy | undefined,\n candidate: AiAgentMutationPolicy,\n): boolean {\n const base: AiAgentMutationPolicy =\n codeDeclared && isKnownMutationPolicy(codeDeclared) ? codeDeclared : 'read-only'\n return POLICY_RESTRICTIVENESS[candidate] > POLICY_RESTRICTIVENESS[base]\n}\n\nfunction classifyMediaType(value: string): AiAgentAcceptedMediaType {\n const normalized = value.trim().toLowerCase()\n if (normalized.startsWith('image/')) return 'image'\n if (normalized === 'application/pdf') return 'pdf'\n return 'file'\n}\n\nfunction isAgentReadOnly(agent: AiAgentDefinition): boolean {\n if (typeof agent.readOnly === 'boolean') return agent.readOnly\n return true\n}\n\n/**\n * Returns the effective mutation policy for a policy-check invocation \u2014 the\n * most restrictive of `{ agent.mutationPolicy, input.mutationPolicyOverride }`.\n * Pure-lookup helper; no I/O. Callers that need to know the same value outside\n * of a policy check should use {@link resolveEffectiveMutationPolicy} directly.\n */\nfunction resolvePolicyCheckMutationPolicy(\n agent: AiAgentDefinition,\n override: AiAgentMutationPolicy | null | undefined,\n): AiAgentMutationPolicy {\n return resolveEffectiveMutationPolicy(agent.mutationPolicy, override, agent.id)\n}\n\nfunction hasAgentStructuredOutput(agent: AiAgentDefinition): boolean {\n return Boolean(agent.output)\n}\n\nfunction agentExecutionMode(agent: AiAgentDefinition): 'chat' | 'object' {\n return agent.executionMode ?? 'chat'\n}\n\nexport function checkAgentPolicy(input: AgentPolicyCheckInput): AgentPolicyDecision {\n const {\n agentId,\n authContext,\n toolName,\n attachmentMediaTypes,\n requestedExecutionMode,\n mutationPolicyOverride,\n } = input\n\n const agent = getAgent(agentId)\n if (!agent) {\n return {\n ok: false,\n code: 'agent_unknown',\n message: `Agent \"${agentId}\" is not registered.`,\n }\n }\n\n const agentFeatures = agent.requiredFeatures ?? []\n if (\n !hasRequiredFeatures(agentFeatures, authContext.userFeatures, authContext.isSuperAdmin)\n ) {\n return {\n ok: false,\n code: 'agent_features_denied',\n message: `Access to agent \"${agentId}\" requires features: ${agentFeatures.join(', ')}`,\n }\n }\n\n let resolvedTool: AiToolDefinition | undefined\n if (typeof toolName === 'string') {\n if (!agent.allowedTools.includes(toolName)) {\n return {\n ok: false,\n code: 'tool_not_whitelisted',\n message: `Tool \"${toolName}\" is not whitelisted for agent \"${agentId}\".`,\n }\n }\n\n const toolRecord = toolRegistry.getTool(toolName) as AiToolDefinition | undefined\n if (!toolRecord) {\n return {\n ok: false,\n code: 'tool_unknown',\n message: `Tool \"${toolName}\" is not registered in the tool registry.`,\n }\n }\n\n const toolFeatures = toolRecord.requiredFeatures ?? []\n if (\n !hasRequiredFeatures(toolFeatures, authContext.userFeatures, authContext.isSuperAdmin)\n ) {\n return {\n ok: false,\n code: 'tool_features_denied',\n message: `Access to tool \"${toolName}\" requires features: ${toolFeatures.join(', ')}`,\n }\n }\n\n if (toolRecord.isMutation === true) {\n if (isAgentReadOnly(agent)) {\n return {\n ok: false,\n code: 'mutation_blocked_by_readonly',\n message: `Mutation tool \"${toolName}\" cannot be executed by read-only agent \"${agentId}\".`,\n }\n }\n const effectivePolicy = resolvePolicyCheckMutationPolicy(agent, mutationPolicyOverride)\n if (effectivePolicy === 'read-only') {\n return {\n ok: false,\n code: 'mutation_blocked_by_policy',\n message: `Mutation tool \"${toolName}\" is blocked by agent \"${agentId}\" mutationPolicy=read-only.`,\n }\n }\n }\n\n resolvedTool = toolRecord\n }\n\n if (requestedExecutionMode) {\n const declaredMode = agentExecutionMode(agent)\n if (requestedExecutionMode === 'object') {\n if (declaredMode !== 'object' && !hasAgentStructuredOutput(agent)) {\n return {\n ok: false,\n code: 'execution_mode_not_supported',\n message: `Agent \"${agentId}\" does not support execution mode \"object\" (no output schema declared).`,\n }\n }\n } else if (requestedExecutionMode === 'chat') {\n if (declaredMode === 'object' && hasAgentStructuredOutput(agent)) {\n return {\n ok: false,\n code: 'execution_mode_not_supported',\n message: `Agent \"${agentId}\" is declared as object-mode and cannot run via chat transport.`,\n }\n }\n }\n }\n\n if (Array.isArray(attachmentMediaTypes) && attachmentMediaTypes.length > 0) {\n const accepted = agent.acceptedMediaTypes\n if (!accepted || accepted.length === 0) {\n return {\n ok: false,\n code: 'attachment_type_not_accepted',\n message: `Agent \"${agentId}\" does not accept attachments.`,\n }\n }\n const acceptedSet = new Set<AiAgentAcceptedMediaType>(accepted)\n for (const raw of attachmentMediaTypes) {\n const kind = classifyMediaType(raw)\n if (!acceptedSet.has(kind)) {\n return {\n ok: false,\n code: 'attachment_type_not_accepted',\n message: `Agent \"${agentId}\" does not accept media type \"${raw}\" (classified as \"${kind}\").`,\n }\n }\n }\n }\n\n return { ok: true, agent, tool: resolvedTool }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AACzB,SAAS,2BAA2B;AACpC,SAAS,oBAAoB;AAQ7B,MAAM,SAAS,aAAa,cAAc;
|
|
4
|
+
"sourcesContent": ["import { createLogger } from '@open-mercato/shared/lib/logger'\nimport { getAgent } from './agent-registry'\nimport { hasRequiredFeatures } from './auth'\nimport { toolRegistry } from './tool-registry'\nimport type {\n AiAgentAcceptedMediaType,\n AiAgentDefinition,\n AiAgentMutationPolicy,\n} from './ai-agent-definition'\nimport type { AiToolDefinition } from './types'\n\nconst logger = createLogger('ai_assistant')\n\nexport type AgentPolicyDenyCode =\n | 'agent_unknown'\n | 'agent_features_denied'\n | 'tool_not_whitelisted'\n | 'tool_unknown'\n | 'tool_features_denied'\n | 'mutation_blocked_by_readonly'\n | 'mutation_blocked_by_policy'\n | 'execution_mode_not_supported'\n | 'attachment_type_not_accepted'\n // Loop policy codes \u2014 Phase 0 of spec 2026-04-28-ai-agents-agentic-loop-controls\n /** Object-mode rejects loop primitives that the SDK ignores for generateObject. */\n | 'loop_unsupported_in_object_mode'\n /** User prepareStep returned a tools map with a raw (unwrapped) mutation handler. */\n | 'loop_violates_mutation_policy'\n /** loop.activeTools contained names outside agent.allowedTools (thrown for caller-supplied overrides; warning-only for agent-declared). */\n | 'loop_active_tools_outside_allowlist'\n /** agent.loop.allowRuntimeOverride is false and a per-call loop override was supplied. */\n | 'loop_runtime_override_disabled'\n\nexport type AgentPolicyDecision =\n | { ok: true; agent: AiAgentDefinition; tool?: AiToolDefinition }\n | { ok: false; code: AgentPolicyDenyCode; message: string }\n\nexport interface AgentPolicyAuthContext {\n userFeatures: string[]\n isSuperAdmin: boolean\n}\n\nexport interface AgentPolicyCheckInput {\n agentId: string\n authContext: AgentPolicyAuthContext\n toolName?: string\n attachmentMediaTypes?: string[]\n requestedExecutionMode?: 'chat' | 'object'\n /**\n * Optional tenant-scoped downgrade for the agent's code-declared\n * `mutationPolicy`. When supplied, the effective policy is the MOST\n * RESTRICTIVE of `{ code-declared, override }` \u2014 escalation is never\n * allowed through this channel (that is enforced at the route layer).\n * Callers that omit this field get the exact pre-Step-5.4 behavior.\n */\n mutationPolicyOverride?: AiAgentMutationPolicy | null\n}\n\n/**\n * Restrictiveness ranking of `AiAgentMutationPolicy` (most restrictive first).\n * `read-only` blocks all mutation tools. `destructive-confirm-required` forces\n * confirmation only for destructive writes; non-destructive writes run directly\n * on the in-process agent channel (on `mcp` / `tools-api` in approval mode every\n * write is still queued). `confirm-required` gates every write through a single\n * confirmation.\n *\n * This ordering is load-bearing for both the runtime's effective-policy\n * computation AND the route-layer escalation guard. Changing the order is a\n * security-sensitive change.\n */\nconst POLICY_RESTRICTIVENESS: Record<AiAgentMutationPolicy, number> = {\n 'read-only': 0,\n 'destructive-confirm-required': 1,\n 'confirm-required': 2,\n}\n\nexport function isKnownMutationPolicy(value: unknown): value is AiAgentMutationPolicy {\n return (\n value === 'read-only' ||\n value === 'confirm-required' ||\n value === 'destructive-confirm-required'\n )\n}\n\n/**\n * Returns the effective mutation policy \u2014 the MOST RESTRICTIVE of\n * `{ codeDeclared, override }`. Missing override \u2192 `codeDeclared`. A corrupt\n * override value (unknown string from DB) is logged and falls back to\n * `codeDeclared` so the system fails SAFE when a schema drift leaks through.\n */\nexport function resolveEffectiveMutationPolicy(\n codeDeclared: AiAgentMutationPolicy | undefined,\n override: AiAgentMutationPolicy | null | undefined,\n agentId?: string,\n): AiAgentMutationPolicy {\n const base: AiAgentMutationPolicy =\n codeDeclared && isKnownMutationPolicy(codeDeclared) ? codeDeclared : 'read-only'\n if (override === undefined || override === null) return base\n if (!isKnownMutationPolicy(override)) {\n logger.warn('Ignoring corrupt mutationPolicy override; falling back to code-declared policy', {\n agentId: agentId ?? '<unknown>',\n override: String(override),\n base,\n })\n return base\n }\n const baseRank = POLICY_RESTRICTIVENESS[base]\n const overrideRank = POLICY_RESTRICTIVENESS[override]\n return overrideRank < baseRank ? override : base\n}\n\n/**\n * Returns `true` when `candidate` would WIDEN `codeDeclared` \u2014 i.e. would\n * grant the agent more mutation surface than its code declares. Used by the\n * mutation-policy override route to reject escalation attempts with 400.\n */\nexport function isMutationPolicyEscalation(\n codeDeclared: AiAgentMutationPolicy | undefined,\n candidate: AiAgentMutationPolicy,\n): boolean {\n const base: AiAgentMutationPolicy =\n codeDeclared && isKnownMutationPolicy(codeDeclared) ? codeDeclared : 'read-only'\n return POLICY_RESTRICTIVENESS[candidate] > POLICY_RESTRICTIVENESS[base]\n}\n\nfunction classifyMediaType(value: string): AiAgentAcceptedMediaType {\n const normalized = value.trim().toLowerCase()\n if (normalized.startsWith('image/')) return 'image'\n if (normalized === 'application/pdf') return 'pdf'\n return 'file'\n}\n\nfunction isAgentReadOnly(agent: AiAgentDefinition): boolean {\n if (typeof agent.readOnly === 'boolean') return agent.readOnly\n return true\n}\n\n/**\n * Returns the effective mutation policy for a policy-check invocation \u2014 the\n * most restrictive of `{ agent.mutationPolicy, input.mutationPolicyOverride }`.\n * Pure-lookup helper; no I/O. Callers that need to know the same value outside\n * of a policy check should use {@link resolveEffectiveMutationPolicy} directly.\n */\nfunction resolvePolicyCheckMutationPolicy(\n agent: AiAgentDefinition,\n override: AiAgentMutationPolicy | null | undefined,\n): AiAgentMutationPolicy {\n return resolveEffectiveMutationPolicy(agent.mutationPolicy, override, agent.id)\n}\n\nfunction hasAgentStructuredOutput(agent: AiAgentDefinition): boolean {\n return Boolean(agent.output)\n}\n\nfunction agentExecutionMode(agent: AiAgentDefinition): 'chat' | 'object' {\n return agent.executionMode ?? 'chat'\n}\n\nexport function checkAgentPolicy(input: AgentPolicyCheckInput): AgentPolicyDecision {\n const {\n agentId,\n authContext,\n toolName,\n attachmentMediaTypes,\n requestedExecutionMode,\n mutationPolicyOverride,\n } = input\n\n const agent = getAgent(agentId)\n if (!agent) {\n return {\n ok: false,\n code: 'agent_unknown',\n message: `Agent \"${agentId}\" is not registered.`,\n }\n }\n\n const agentFeatures = agent.requiredFeatures ?? []\n if (\n !hasRequiredFeatures(agentFeatures, authContext.userFeatures, authContext.isSuperAdmin)\n ) {\n return {\n ok: false,\n code: 'agent_features_denied',\n message: `Access to agent \"${agentId}\" requires features: ${agentFeatures.join(', ')}`,\n }\n }\n\n let resolvedTool: AiToolDefinition | undefined\n if (typeof toolName === 'string') {\n if (!agent.allowedTools.includes(toolName)) {\n return {\n ok: false,\n code: 'tool_not_whitelisted',\n message: `Tool \"${toolName}\" is not whitelisted for agent \"${agentId}\".`,\n }\n }\n\n const toolRecord = toolRegistry.getTool(toolName) as AiToolDefinition | undefined\n if (!toolRecord) {\n return {\n ok: false,\n code: 'tool_unknown',\n message: `Tool \"${toolName}\" is not registered in the tool registry.`,\n }\n }\n\n const toolFeatures = toolRecord.requiredFeatures ?? []\n if (\n !hasRequiredFeatures(toolFeatures, authContext.userFeatures, authContext.isSuperAdmin)\n ) {\n return {\n ok: false,\n code: 'tool_features_denied',\n message: `Access to tool \"${toolName}\" requires features: ${toolFeatures.join(', ')}`,\n }\n }\n\n if (toolRecord.isMutation === true) {\n if (isAgentReadOnly(agent)) {\n return {\n ok: false,\n code: 'mutation_blocked_by_readonly',\n message: `Mutation tool \"${toolName}\" cannot be executed by read-only agent \"${agentId}\".`,\n }\n }\n const effectivePolicy = resolvePolicyCheckMutationPolicy(agent, mutationPolicyOverride)\n if (effectivePolicy === 'read-only') {\n return {\n ok: false,\n code: 'mutation_blocked_by_policy',\n message: `Mutation tool \"${toolName}\" is blocked by agent \"${agentId}\" mutationPolicy=read-only.`,\n }\n }\n }\n\n resolvedTool = toolRecord\n }\n\n if (requestedExecutionMode) {\n const declaredMode = agentExecutionMode(agent)\n if (requestedExecutionMode === 'object') {\n if (declaredMode !== 'object' && !hasAgentStructuredOutput(agent)) {\n return {\n ok: false,\n code: 'execution_mode_not_supported',\n message: `Agent \"${agentId}\" does not support execution mode \"object\" (no output schema declared).`,\n }\n }\n } else if (requestedExecutionMode === 'chat') {\n if (declaredMode === 'object' && hasAgentStructuredOutput(agent)) {\n return {\n ok: false,\n code: 'execution_mode_not_supported',\n message: `Agent \"${agentId}\" is declared as object-mode and cannot run via chat transport.`,\n }\n }\n }\n }\n\n if (Array.isArray(attachmentMediaTypes) && attachmentMediaTypes.length > 0) {\n const accepted = agent.acceptedMediaTypes\n if (!accepted || accepted.length === 0) {\n return {\n ok: false,\n code: 'attachment_type_not_accepted',\n message: `Agent \"${agentId}\" does not accept attachments.`,\n }\n }\n const acceptedSet = new Set<AiAgentAcceptedMediaType>(accepted)\n for (const raw of attachmentMediaTypes) {\n const kind = classifyMediaType(raw)\n if (!acceptedSet.has(kind)) {\n return {\n ok: false,\n code: 'attachment_type_not_accepted',\n message: `Agent \"${agentId}\" does not accept media type \"${raw}\" (classified as \"${kind}\").`,\n }\n }\n }\n }\n\n return { ok: true, agent, tool: resolvedTool }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AACzB,SAAS,2BAA2B;AACpC,SAAS,oBAAoB;AAQ7B,MAAM,SAAS,aAAa,cAAc;AA2D1C,MAAM,yBAAgE;AAAA,EACpE,aAAa;AAAA,EACb,gCAAgC;AAAA,EAChC,oBAAoB;AACtB;AAEO,SAAS,sBAAsB,OAAgD;AACpF,SACE,UAAU,eACV,UAAU,sBACV,UAAU;AAEd;AAQO,SAAS,+BACd,cACA,UACA,SACuB;AACvB,QAAM,OACJ,gBAAgB,sBAAsB,YAAY,IAAI,eAAe;AACvE,MAAI,aAAa,UAAa,aAAa,KAAM,QAAO;AACxD,MAAI,CAAC,sBAAsB,QAAQ,GAAG;AACpC,WAAO,KAAK,kFAAkF;AAAA,MAC5F,SAAS,WAAW;AAAA,MACpB,UAAU,OAAO,QAAQ;AAAA,MACzB;AAAA,IACF,CAAC;AACD,WAAO;AAAA,EACT;AACA,QAAM,WAAW,uBAAuB,IAAI;AAC5C,QAAM,eAAe,uBAAuB,QAAQ;AACpD,SAAO,eAAe,WAAW,WAAW;AAC9C;AAOO,SAAS,2BACd,cACA,WACS;AACT,QAAM,OACJ,gBAAgB,sBAAsB,YAAY,IA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,MACF;AAAA,IACF;AAAA,EACF;AAEA,MAAI,MAAM,QAAQ,oBAAoB,KAAK,qBAAqB,SAAS,GAAG;AAC1E,UAAM,WAAW,MAAM;AACvB,QAAI,CAAC,YAAY,SAAS,WAAW,GAAG;AACtC,aAAO;AAAA,QACL,IAAI;AAAA,QACJ,MAAM;AAAA,QACN,SAAS,UAAU,OAAO;AAAA,MAC5B;AAAA,IACF;AACA,UAAM,cAAc,IAAI,IAA8B,QAAQ;AAC9D,eAAW,OAAO,sBAAsB;AACtC,YAAM,OAAO,kBAAkB,GAAG;AAClC,UAAI,CAAC,YAAY,IAAI,IAAI,GAAG;AAC1B,eAAO;AAAA,UACL,IAAI;AAAA,UACJ,MAAM;AAAA,UACN,SAAS,UAAU,OAAO,iCAAiC,GAAG,qBAAqB,IAAI;AAAA,QACzF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,IAAI,MAAM,OAAO,MAAM,aAAa;AAC/C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -895,7 +895,7 @@ function appendAttachmentSummary(systemPrompt, parts) {
|
|
|
895
895
|
|
|
896
896
|
${summary}`;
|
|
897
897
|
}
|
|
898
|
-
function buildRuntimeMutationPolicySection(agent, mutationPolicyOverride) {
|
|
898
|
+
function buildRuntimeMutationPolicySection(agent, mutationPolicyOverride, channel = "agent") {
|
|
899
899
|
const effective = resolveEffectiveMutationPolicy(
|
|
900
900
|
agent.mutationPolicy ?? null,
|
|
901
901
|
mutationPolicyOverride ?? null,
|
|
@@ -919,7 +919,7 @@ function buildRuntimeMutationPolicySection(agent, mutationPolicyOverride) {
|
|
|
919
919
|
blocked.push(toolName);
|
|
920
920
|
continue;
|
|
921
921
|
}
|
|
922
|
-
if (effective === "confirm-required") {
|
|
922
|
+
if (effective === "confirm-required" || channel !== "agent") {
|
|
923
923
|
gated.push(toolName);
|
|
924
924
|
continue;
|
|
925
925
|
}
|
|
@@ -949,7 +949,7 @@ function buildRuntimeMutationPolicySection(agent, mutationPolicyOverride) {
|
|
|
949
949
|
`Tools that REQUIRE APPROVAL under the effective policy: ${gated.join(", ")}.`
|
|
950
950
|
);
|
|
951
951
|
lines.push(
|
|
952
|
-
'When you call any of these, the dispatcher returns an "awaiting confirmation" envelope and renders an inline approval card. Tell the operator the change is pending their confirmation; do NOT claim it has been applied.'
|
|
952
|
+
channel === "agent" ? 'When you call any of these, the dispatcher returns an "awaiting confirmation" envelope and renders an inline approval card. Tell the operator the change is pending their confirmation; do NOT claim it has been applied.' : 'When you call any of these, the change is queued as a pending action and the dispatcher returns an "awaiting confirmation" envelope. It will NOT run until it is approved on the Pending AI actions page. Report it as pending approval; do NOT claim it has been applied.'
|
|
953
953
|
);
|
|
954
954
|
}
|
|
955
955
|
if (conditional.length > 0) {
|
|
@@ -976,8 +976,8 @@ function buildRuntimeMutationPolicySection(agent, mutationPolicyOverride) {
|
|
|
976
976
|
);
|
|
977
977
|
return lines.join("\n");
|
|
978
978
|
}
|
|
979
|
-
function appendRuntimeMutationPolicy(systemPrompt, agent, mutationPolicyOverride) {
|
|
980
|
-
const block = buildRuntimeMutationPolicySection(agent, mutationPolicyOverride);
|
|
979
|
+
function appendRuntimeMutationPolicy(systemPrompt, agent, mutationPolicyOverride, channel) {
|
|
980
|
+
const block = buildRuntimeMutationPolicySection(agent, mutationPolicyOverride, channel);
|
|
981
981
|
if (!block) return systemPrompt;
|
|
982
982
|
return `${systemPrompt}
|
|
983
983
|
|
|
@@ -1434,7 +1434,8 @@ async function runAiAgentObject(input) {
|
|
|
1434
1434
|
const systemPrompt = appendRuntimeMutationPolicy(
|
|
1435
1435
|
appendRuntimeTaskPlanPrompt(appendAttachmentSummary(composedPrompt.prompt, resolvedAttachments), agent),
|
|
1436
1436
|
agent,
|
|
1437
|
-
runMutationPolicyOverride
|
|
1437
|
+
runMutationPolicyOverride,
|
|
1438
|
+
input.channel
|
|
1438
1439
|
);
|
|
1439
1440
|
const resolvedObjectModel = resolveAgentModel(
|
|
1440
1441
|
agent,
|