@yielded/agent 0.1.0-beta.173 → 0.1.0-beta.174
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/{Admin-BX9ns28E.d.mts → Admin-BHmp2V9p.d.mts} +25 -16
- package/dist/{Agent-9aBoIi74.d.mts → Agent-B39jRnFv.d.mts} +2 -2
- package/dist/{Agent-0WvBWWbM.mjs → Agent-BiRbr73L.mjs} +7 -6
- package/dist/Agent-BiRbr73L.mjs.map +1 -0
- package/dist/{AgentRuntime-CQ-qcETl.mjs → AgentRuntime-B6qZlD3f.mjs} +199 -191
- package/dist/AgentRuntime-B6qZlD3f.mjs.map +1 -0
- package/dist/{AgentRuntime-BfP14534.d.mts → AgentRuntime-BD3ZHAMq.d.mts} +10 -10
- package/dist/{Digest-DCuPlhNk.mjs → Digest-EpeqWEdv.mjs} +41 -14
- package/dist/Digest-EpeqWEdv.mjs.map +1 -0
- package/dist/{DurableAgentRuntime-BAmSkWYr.mjs → DurableAgentRuntime-CBBjRNJN.mjs} +1447 -1424
- package/dist/DurableAgentRuntime-CBBjRNJN.mjs.map +1 -0
- package/dist/{EventSource-BwliwQz9.d.mts → EventSource-C9aaJaXT.d.mts} +2 -2
- package/dist/{MessageDelivery-B943ebI_.d.mts → MessageDelivery-BGDm-c46.d.mts} +42 -42
- package/dist/{Messaging-C_6OOg_s.d.mts → Messaging-SVu6rWV8.d.mts} +12 -6
- package/dist/{MessagingHost-B8oKM7AC.d.mts → MessagingHost-C6SOAcoG.d.mts} +2 -2
- package/dist/{Output-Dsx6k52t.d.mts → Output-CRamN1Fy.d.mts} +2 -2
- package/dist/{PreparedInputAdmission-CxSJSiTl.d.mts → PreparedInputAdmission-BvDqlgiP.d.mts} +3 -3
- package/dist/{RunContinuation-DHYNAQFi.mjs → RunContinuation-4ZATcVLB.mjs} +113 -56
- package/dist/RunContinuation-4ZATcVLB.mjs.map +1 -0
- package/dist/{RunContinuation-FHM7XPjq.d.mts → RunContinuation-CTJ1jGrO.d.mts} +6 -6
- package/dist/{RunJournal-kfKVxJj7.mjs → RunJournal-CNZqA3Ge.mjs} +33 -5
- package/dist/RunJournal-CNZqA3Ge.mjs.map +1 -0
- package/dist/{RunOptions-D8zxFIrZ.d.mts → RunOptions-Be77lKVZ.d.mts} +2 -2
- package/dist/{RunStorage-uqPxps09.mjs → RunStorage-BHjuuERI.mjs} +9 -6
- package/dist/RunStorage-BHjuuERI.mjs.map +1 -0
- package/dist/{Scheduling-CVyfXlBR.mjs → Scheduling-NG8slKdI.mjs} +11 -11
- package/dist/Scheduling-NG8slKdI.mjs.map +1 -0
- package/dist/{Subagent-vpffemql.mjs → Subagent-CTIpnzlB.mjs} +53 -40
- package/dist/Subagent-CTIpnzlB.mjs.map +1 -0
- package/dist/{Subagent-E6tvd7-k.d.mts → Subagent-DKhZA72u.d.mts} +19 -8
- package/dist/{SubagentHost-B6w2m-SI.d.mts → SubagentHost-D1xBgn9g.d.mts} +2 -2
- package/dist/{Subscription-DONig54Q.d.mts → Subscription-BNg9VCRl.d.mts} +2 -2
- package/dist/{SubscriptionInput-mJIRxWJM.d.mts → SubscriptionInput-BUoXv-_K.d.mts} +2 -2
- package/dist/{ThreadImport-DpHxjBrA.d.mts → ThreadImport-CMgzttvr.d.mts} +5 -5
- package/dist/{ThreadImport-DckUMEqJ.mjs → ThreadImport-CodYoJoa.mjs} +7 -7
- package/dist/ThreadImport-CodYoJoa.mjs.map +1 -0
- package/dist/{ThreadStore-CEekRa80.mjs → ThreadStore-59uDGXul.mjs} +163 -84
- package/dist/ThreadStore-59uDGXul.mjs.map +1 -0
- package/dist/{ThreadTransfer-B4gTQLIl.mjs → ThreadTransfer-3jigUl3g.mjs} +3 -3
- package/dist/{ThreadTransfer-B4gTQLIl.mjs.map → ThreadTransfer-3jigUl3g.mjs.map} +1 -1
- package/dist/{WorkerAdmission-DFVbbVh2.mjs → WorkerAdmission-DDYJdOsU.mjs} +4 -4
- package/dist/{WorkerAdmission-DFVbbVh2.mjs.map → WorkerAdmission-DDYJdOsU.mjs.map} +1 -1
- package/dist/{agent-registration-ByMZ_cK5.mjs → agent-registration-DRbyhAu-.mjs} +69 -56
- package/dist/agent-registration-DRbyhAu-.mjs.map +1 -0
- package/dist/capabilities/Approval.mjs +2 -2
- package/dist/capabilities/Approval.mjs.map +1 -1
- package/dist/capabilities/BrowserUse.d.mts +102 -1867
- package/dist/capabilities/BrowserUse.mjs +74 -798
- package/dist/capabilities/BrowserUse.mjs.map +1 -1
- package/dist/capabilities/Budget.mjs +3 -1
- package/dist/capabilities/Budget.mjs.map +1 -1
- package/dist/capabilities/CodeMode.d.mts +1 -1
- package/dist/capabilities/CodeMode.mjs +16 -9
- package/dist/capabilities/CodeMode.mjs.map +1 -1
- package/dist/capabilities/Commands.d.mts +1 -1
- package/dist/capabilities/McpClient.mjs +1 -1
- package/dist/capabilities/McpClient.mjs.map +1 -1
- package/dist/capabilities/Messaging.d.mts +1 -1
- package/dist/capabilities/Messaging.mjs +4 -4
- package/dist/capabilities/Messaging.mjs.map +1 -1
- package/dist/capabilities/ModelContext.mjs +7 -5
- package/dist/capabilities/ModelContext.mjs.map +1 -1
- package/dist/capabilities/Redaction.mjs +49 -19
- package/dist/capabilities/Redaction.mjs.map +1 -1
- package/dist/capabilities/RunHooks.d.mts +1 -1
- package/dist/capabilities/RunHooks.mjs +1 -1
- package/dist/capabilities/RunHooks.mjs.map +1 -1
- package/dist/capabilities/Subagent.d.mts +1 -1
- package/dist/capabilities/Subagent.mjs +1 -1
- package/dist/capabilities/SubagentReservations.mjs +3 -1
- package/dist/capabilities/SubagentReservations.mjs.map +1 -1
- package/dist/capabilities/WebCapture.mjs.map +1 -1
- package/dist/capabilities/WebSearch.mjs +7 -7
- package/dist/capabilities/WebSearch.mjs.map +1 -1
- package/dist/core/Agent.d.mts +1 -1
- package/dist/core/Agent.mjs +1 -1
- package/dist/core/AgentUpdates.mjs +8 -8
- package/dist/core/AgentUpdates.mjs.map +1 -1
- package/dist/core/Thread.mjs +1 -1
- package/dist/core/Thread.mjs.map +1 -1
- package/dist/core/Usage.mjs +2 -2
- package/dist/core/Usage.mjs.map +1 -1
- package/dist/durable/Admin.d.mts +1 -1
- package/dist/durable/AgentRegistration.d.mts +1 -1
- package/dist/durable/AgentRegistration.mjs +1 -1
- package/dist/durable/Certification.d.mts +1 -1
- package/dist/durable/CommittedActivity.d.mts +1 -1
- package/dist/durable/CommittedActivity.mjs +2 -2
- package/dist/durable/Digest.mjs +1 -1
- package/dist/durable/DurableAgentRuntime.d.mts +1 -1
- package/dist/durable/DurableAgentRuntime.mjs +2 -2
- package/dist/durable/EventSource.d.mts +1 -1
- package/dist/durable/EventSource.mjs +6 -6
- package/dist/durable/EventSource.mjs.map +1 -1
- package/dist/durable/GitHubWorkflowSource.d.mts +3 -3
- package/dist/durable/LifecyclePublication.d.mts +1 -1
- package/dist/durable/LifecyclePublication.mjs +1 -1
- package/dist/durable/MessageDelivery.d.mts +1 -1
- package/dist/durable/MessageDelivery.mjs +1 -1
- package/dist/durable/MessageDeliveryStoreConformance.d.mts +2 -2
- package/dist/durable/MessageDeliveryStoreConformance.mjs +1 -1
- package/dist/durable/PersistentHistory.d.mts +1 -1
- package/dist/durable/PersistentHistory.mjs +3 -3
- package/dist/durable/PreparedInputAdmission.d.mts +1 -1
- package/dist/durable/RecordFormat.mjs +2 -2
- package/dist/durable/RecordFormat.mjs.map +1 -1
- package/dist/durable/Recovery.d.mts +1 -1
- package/dist/durable/RunContinuation.d.mts +2 -2
- package/dist/durable/RunContinuation.mjs +2 -2
- package/dist/durable/RunJournal.d.mts +1 -1
- package/dist/durable/RunJournal.mjs +1 -1
- package/dist/durable/RunStorage.d.mts +1 -1
- package/dist/durable/RunStorage.mjs +1 -1
- package/dist/durable/Scheduling.d.mts +1 -1
- package/dist/durable/Scheduling.mjs +1 -1
- package/dist/durable/SettlementPublisher.d.mts +1 -1
- package/dist/durable/SettlementPublisher.mjs +2 -2
- package/dist/durable/SubmissionLedger.d.mts +1 -1
- package/dist/durable/SubmissionLedger.mjs +5 -1
- package/dist/durable/SubmissionLedger.mjs.map +1 -1
- package/dist/durable/SubmissionLedgerConformance.d.mts +1 -1
- package/dist/durable/SubmissionLedgerConformance.mjs +4 -4
- package/dist/durable/SubmissionStatus.d.mts +1 -1
- package/dist/durable/Subscription.d.mts +1 -1
- package/dist/durable/SubscriptionInput.d.mts +1 -1
- package/dist/durable/SubscriptionInput.mjs +3 -3
- package/dist/durable/SubscriptionInput.mjs.map +1 -1
- package/dist/durable/SubscriptionStoreConformance.d.mts +1 -1
- package/dist/durable/SubscriptionStoreConformance.mjs +2 -2
- package/dist/durable/SubscriptionStoreConformance.mjs.map +1 -1
- package/dist/durable/SubscriptionTools.d.mts +2 -2
- package/dist/durable/SubscriptionTransition.d.mts +1 -1
- package/dist/durable/Subscriptions.d.mts +5 -5
- package/dist/durable/Subscriptions.mjs +2 -2
- package/dist/durable/Subscriptions.mjs.map +1 -1
- package/dist/durable/ThreadArchiveRange.d.mts +1 -1
- package/dist/durable/ThreadContextHistory.d.mts +1 -1
- package/dist/durable/ThreadContextHistory.mjs +1 -1
- package/dist/durable/ThreadImport.d.mts +1 -1
- package/dist/durable/ThreadImport.mjs +1 -1
- package/dist/durable/ThreadInvariants.d.mts +3 -3
- package/dist/durable/ThreadInvariants.mjs +4 -4
- package/dist/durable/ThreadInvariants.mjs.map +1 -1
- package/dist/durable/ThreadProjectionMaintenance.d.mts +1 -1
- package/dist/durable/ThreadReader.d.mts +1 -1
- package/dist/durable/ThreadReader.mjs +1 -1
- package/dist/durable/ThreadStore.d.mts +1 -1
- package/dist/durable/ThreadStore.mjs +1 -1
- package/dist/durable/ThreadStoreConformance.d.mts +1 -1
- package/dist/durable/ThreadStoreConformance.mjs +3 -3
- package/dist/durable/ThreadTransfer.d.mts +1 -1
- package/dist/durable/ThreadTransfer.mjs +1 -1
- package/dist/durable/ThreadWork.d.mts +1 -1
- package/dist/durable/ThreadWork.mjs +4 -4
- package/dist/durable/ThreadWork.mjs.map +1 -1
- package/dist/durable/WorkerAdmission.d.mts +1 -1
- package/dist/durable/WorkerAdmission.mjs +1 -1
- package/dist/durable/WorkerHost.d.mts +2 -2
- package/dist/engine/AgentRuntime.d.mts +1 -1
- package/dist/engine/AgentRuntime.mjs +1 -1
- package/dist/engine/MessagingHost.d.mts +1 -1
- package/dist/engine/Output.d.mts +1 -1
- package/dist/engine/RunOptions.d.mts +1 -1
- package/dist/engine/SubagentHost.d.mts +1 -1
- package/dist/index.d.mts +19 -19
- package/dist/index.mjs +14 -14
- package/dist/{run-context-reader-OcsZr4bk.d.mts → run-context-reader-CC7ZD95F.d.mts} +2 -2
- package/package.json +1 -1
- package/src/capabilities/Approval.ts +58 -60
- package/src/capabilities/BrowserUse.ts +89 -944
- package/src/capabilities/Budget.ts +8 -1
- package/src/capabilities/CodeMode.ts +57 -33
- package/src/capabilities/McpClient.ts +2 -2
- package/src/capabilities/Messaging.ts +51 -55
- package/src/capabilities/ModelContext.ts +5 -2
- package/src/capabilities/Redaction.ts +64 -34
- package/src/capabilities/RunHooks.ts +52 -55
- package/src/capabilities/Subagent.ts +33 -33
- package/src/capabilities/SubagentReservations.ts +9 -1
- package/src/capabilities/WebCapture.ts +6 -0
- package/src/capabilities/WebSearch.ts +10 -7
- package/src/capabilities/internal/subagent-background.ts +202 -158
- package/src/core/Agent.ts +11 -6
- package/src/core/AgentUpdates.ts +8 -8
- package/src/core/Thread.ts +9 -10
- package/src/core/Usage.ts +7 -8
- package/src/core/internal/agent-updates.ts +1 -0
- package/src/durable/DurableAgentRuntime.ts +645 -625
- package/src/durable/EventSource.ts +15 -9
- package/src/durable/RecordFormat.ts +5 -3
- package/src/durable/RunContinuation.ts +233 -81
- package/src/durable/RunJournal.ts +10 -9
- package/src/durable/RunStorage.ts +122 -124
- package/src/durable/Scheduling.ts +639 -651
- package/src/durable/SubmissionLedger.ts +4 -0
- package/src/durable/SubscriptionInput.ts +5 -3
- package/src/durable/SubscriptionStoreConformance.ts +23 -23
- package/src/durable/Subscriptions.ts +18 -19
- package/src/durable/ThreadImport.ts +18 -19
- package/src/durable/ThreadInvariants.ts +2 -1
- package/src/durable/ThreadStore.ts +215 -111
- package/src/durable/ThreadWork.ts +1 -2
- package/src/durable/internal/StorageOwner.ts +10 -4
- package/src/durable/internal/agent-registration.ts +96 -89
- package/src/durable/internal/canonical-json.ts +61 -20
- package/src/durable/internal/prompt-history-cache.ts +13 -4
- package/src/durable/internal/record-encoding.ts +120 -64
- package/src/durable/internal/schedule-time.ts +6 -6
- package/src/durable/internal/usage-totals.ts +38 -0
- package/src/durable/internal/worker-host.ts +69 -74
- package/src/engine/internal/agent-runtime.ts +1067 -1018
- package/src/engine/internal/provisional-text.ts +12 -10
- package/src/engine/internal/tool-exposure.ts +22 -18
- package/src/engine/internal/tool-telemetry.ts +12 -7
- package/dist/Agent-0WvBWWbM.mjs.map +0 -1
- package/dist/AgentRuntime-CQ-qcETl.mjs.map +0 -1
- package/dist/Digest-DCuPlhNk.mjs.map +0 -1
- package/dist/DurableAgentRuntime-BAmSkWYr.mjs.map +0 -1
- package/dist/RunContinuation-DHYNAQFi.mjs.map +0 -1
- package/dist/RunJournal-kfKVxJj7.mjs.map +0 -1
- package/dist/RunStorage-uqPxps09.mjs.map +0 -1
- package/dist/Scheduling-CVyfXlBR.mjs.map +0 -1
- package/dist/Subagent-vpffemql.mjs.map +0 -1
- package/dist/ThreadImport-DckUMEqJ.mjs.map +0 -1
- package/dist/ThreadStore-CEekRa80.mjs.map +0 -1
- package/dist/agent-registration-ByMZ_cK5.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-registration-DRbyhAu-.mjs","names":["withProvisionalTextAttempt","run"],"sources":["../src/durable/internal/agent-registration.ts"],"sourcesContent":["import { Crypto, Option, Scope, Context, Effect, Layer, References, Schema, Tracer } from \"effect\";\nimport { Tool } from \"effect/ai\";\n\nimport type * as Agent from \"../../core/Agent.ts\";\nimport {\n type InputPromptSource,\n type InstructionSource,\n type ModelServices,\n type RunDispositionDeclaration,\n} from \"../../core/Agent.ts\";\nimport { type ThreadId, AgentId } from \"../../core/Identifiers.ts\";\nimport { getToolExecutionKind } from \"../../core/SubagentContract.ts\";\nimport {\n AdditionalToolCatalog,\n DiscoveryTool,\n IncludesCatalogDocumentation,\n PinnedTool,\n ToolNamespace,\n} from \"../../core/ToolExposure.ts\";\nimport { type RuntimeBinding } from \"../../engine/AgentRuntime.ts\";\nimport { ContextRolloverTool } from \"../../engine/ContextWindow.ts\";\nimport { getToolExecutionClass } from \"../../engine/DurableStep.ts\";\nimport { withAttempt as withProvisionalTextAttempt } from \"../../engine/internal/provisional-text.ts\";\nimport {\n BackgroundReporting,\n WorkerReportPreparationFailure,\n type WorkerReporting,\n} from \"../../engine/SubagentHost.ts\";\nimport { digestDefinitions, digestJson, DigestError } from \"../Digest.ts\";\nimport type { DurableWorkerFailure, DurableWorkerRequirements } from \"../DurableAgentRuntime.ts\";\nimport type { DefinitionDigestInput, Digest, PersistedJson } from \"../Records.ts\";\nimport { DefinitionDigests, ReplayContract } from \"../Records.ts\";\nimport type { Claim, Settlement, SubmissionSnapshot } from \"../SubmissionLedger.ts\";\n\n/** No unique current Binding can execute the stable Agent identity or decode its accepted input. */\nexport class BindingUnavailable extends Schema.TaggedError<BindingUnavailable>()(\n \"BindingUnavailable\",\n { agentId: AgentId, message: Schema.String },\n) {}\n\nexport type DurableBindingFailure = BindingUnavailable;\n\n/**\n * Submission execution/recovery routing for stable identities shared by current Definitions.\n * Worker declarations and peer-messaging endpoints still require unique Agent identities.\n */\nexport interface BindingSelection {\n /** Change when routing changes, so hosts can retry parked work without rewriting admission. */\n readonly key: string;\n /**\n * Select an exact registered Definition using the canonical Submission and authoritative host\n * state. Undefined retains unique-identity resolution. Never grant authority or mutate here;\n * input decoding, replay contracts and current Tool authorization still apply after selection.\n */\n readonly select: (\n submission: SubmissionSnapshot,\n ) => Effect.Effect<Agent.AnyDefinition | undefined, DurableWorkerFailure | BindingUnavailable>;\n}\n\n/** Captured at runtime construction; callers cannot replace routing during an Attempt. */\nexport const CurrentBindingSelection = Context.Reference<BindingSelection | undefined>(\n \"@effect-agent/thread/CurrentBindingSelection\",\n { defaultValue: () => undefined },\n);\n\n/** Exact immutable admission, lineage and delivery evidence; never an executable-code gate. */\nexport const definitionDigestsEqual = (\n left: DefinitionDigests,\n right: DefinitionDigests,\n): boolean =>\n left.agent === right.agent &&\n left.model === right.model &&\n left.tools === right.tools &&\n Schema.toEquivalence(Schema.UndefinedOr(ReplayContract))(left.replay, right.replay);\n\n/**\n * Explicit versions must cover every current Tool. Change a version when handler meaning,\n * durable Step names/codecs, external idempotency keys, authorization, completion projection,\n * or child/report protocols change. JSON Schema cannot detect handler or codec-transform changes.\n */\nexport interface ReplayVersions {\n readonly tools: Readonly<Record<string, PersistedJson>>;\n}\n\n// These are immutable declaration projections, never model or admission contexts.\nconst replaySchemaProjections = new WeakMap<Schema.Top, Schema.Json>();\n\ntype CachedFallbackContracts = {\n readonly tools: ReadonlyArray<Tool.Any>;\n readonly completionTool: string | undefined;\n readonly completionFromTools: ReadonlyArray<string>;\n readonly version: PersistedJson;\n readonly contracts: Record<string, Digest>;\n};\n\nconst fallbackContracts = new WeakMap<Crypto.Crypto, WeakMap<object, CachedFallbackContracts>>();\n\n/** Hash current operation contracts; no historical definitions or schemas are retained. */\nexport const toolReplayContracts = Effect.fnUntraced(function* (\n definition: Agent.AnyDefinition,\n versions?: ReplayVersions,\n fallbackVersion: PersistedJson = null,\n) {\n // Optional lookup preserves validation before a missing-service defect. A\n // different host Crypto service must never inherit another host's digest map.\n const crypto = Option.getOrUndefined(yield* Effect.serviceOption(Crypto.Crypto));\n\n const invalidContracts = () =>\n DigestError.make({\n message: \"Operation contracts require serializable codecs and a version for every Tool\",\n });\n\n const prepared = yield* Effect.try({\n try: () => {\n const tools = Object.values(definition.toolkit.tools);\n const completionTool = definition.completion?.tool;\n const completionFromTools = definition.completionFromTools?.map(({ tool }) => tool) ?? [];\n // Object-valued versions may be mutable caller data. Only primitive fallback\n // versions can reuse a result, and only one result is retained per toolkit.\n\n const cacheable =\n versions === undefined && (fallbackVersion === null || typeof fallbackVersion !== \"object\");\n\n const cached =\n cacheable && crypto !== undefined\n ? fallbackContracts.get(crypto)?.get(definition.toolkit.tools)\n : undefined;\n\n if (\n cached !== undefined &&\n cached.version === fallbackVersion &&\n cached.completionTool === completionTool &&\n cached.completionFromTools.length === completionFromTools.length &&\n cached.completionFromTools.every((tool, index) => tool === completionFromTools[index]) &&\n cached.tools.length === tools.length &&\n cached.tools.every((tool, index) => tool === tools[index])\n )\n return { _tag: \"Cached\" as const, contracts: { ...cached.contracts } };\n\n const jsonSchema = (schema: Schema.Top) => {\n const cached = replaySchemaProjections.get(schema);\n\n if (cached !== undefined) return cached;\n\n const projection = Schema.decodeUnknownSync(Schema.Json)(\n Tool.getJsonSchemaFromSchema(schema),\n );\n\n replaySchemaProjections.set(schema, projection);\n\n return projection;\n };\n\n return {\n _tag: \"Compile\" as const,\n jsonSchema,\n cacheable,\n tools,\n completionTool,\n completionFromTools,\n };\n },\n catch: () =>\n DigestError.make({\n message: \"Operation contracts require serializable codecs and a version for every Tool\",\n }),\n });\n\n if (prepared._tag === \"Cached\") return prepared.contracts;\n\n const declarations = yield* Effect.forEach(\n prepared.tools,\n Effect.fnUntraced(function* (tool) {\n const { version, present } = yield* Effect.try({\n try: () => ({\n version: versions === undefined ? fallbackVersion : versions.tools[tool.name],\n present: versions === undefined || Object.hasOwn(versions.tools, tool.name),\n }),\n catch: invalidContracts,\n });\n\n if (version === undefined || !present) return yield* invalidContracts();\n\n return yield* Effect.try({\n try: () => ({\n name: tool.name,\n contract: {\n version,\n ...(Tool.isProviderDefined(tool)\n ? {\n provider: {\n id: tool.id,\n providerName: tool.providerName,\n args: Schema.decodeUnknownSync(Schema.Json)(tool.args ?? null),\n requiresHandler: tool.requiresHandler,\n },\n readonly: Context.get(tool.annotations, Tool.Readonly),\n }\n : {}),\n parameters: prepared.jsonSchema(tool.parametersSchema),\n success: prepared.jsonSchema(tool.successSchema),\n failure: prepared.jsonSchema(tool.failureSchema),\n failureMode: tool.failureMode,\n needsApproval:\n typeof tool.needsApproval === \"function\" ? \"dynamic\" : (tool.needsApproval ?? false),\n executionClass: getToolExecutionClass(tool),\n executionKind: getToolExecutionKind(tool.annotations),\n contextRollover: Context.get(tool.annotations, ContextRolloverTool),\n completion: definition.completion?.tool === tool.name,\n completionFromTool:\n definition.completionFromTools?.some(\n (declaration) => declaration.tool === tool.name,\n ) ?? false,\n },\n }),\n catch: invalidContracts,\n });\n }),\n );\n\n const contracts = Object.fromEntries(\n yield* Effect.forEach(declarations, ({ name, contract }) =>\n digestJson(contract).pipe(Effect.map((digest) => [name, digest] as const)),\n ),\n );\n\n if (prepared.cacheable && crypto !== undefined) {\n const cache = fallbackContracts.get(crypto) ?? new WeakMap<object, CachedFallbackContracts>();\n\n cache.set(definition.toolkit.tools, {\n tools: prepared.tools,\n completionTool: prepared.completionTool,\n completionFromTools: prepared.completionFromTools,\n version: fallbackVersion,\n contracts: { ...contracts },\n });\n fallbackContracts.set(crypto, cache);\n }\n\n return contracts;\n});\n\n/** Compile current metadata without acquiring executable services. */\nexport const compileBindingContracts = Effect.fnUntraced(function* (\n definition: Agent.AnyDefinition,\n definitions: DefinitionDigestInput,\n versions?: ReplayVersions,\n): Effect.fn.Return<Pick<ResolvedBinding, \"digests\">, DigestError, Crypto.Crypto> {\n const digests = yield* digestDefinitions(definitions);\n const tools = yield* toolReplayContracts(definition, versions, definitions.tools);\n\n return {\n digests: DefinitionDigests.make({\n ...digests,\n replay: ReplayContract.make({ agent: digests.agent, tools }),\n }),\n };\n});\n\ntype ExecutableDefinition = Agent.AnyDefinition & {\n readonly instructions: InstructionSource<never, unknown, unknown>;\n readonly inputPrompt?: InputPromptSource<never, unknown, unknown> | undefined;\n};\n\n/** Executable model Binding accepted by durable registration descriptors. */\nexport type ExecutableAgentBinding = {\n readonly definition: ExecutableDefinition;\n readonly model: Layer.Layer<ModelServices, never, unknown>;\n};\n\n/**\n * Internal coordinator entry point for one fenced Attempt over an already-granted claim.\n * The generic signature matches `runAttempt` and is specialized for each captured Agent.\n */\ntype ResolvedAttemptDriver = <\n InputSchema extends Schema.Top,\n OutputSchema extends Schema.Top,\n Instructions,\n Tools extends Record<string, Tool.Any>,\n Provider,\n ModelProvides,\n ModelRequires,\n InstructionError,\n InstructionRequirements,\n RunDispositionValue extends\n | RunDispositionDeclaration<OutputSchema[\"Type\"], Schema.Top>\n | undefined,\n InputPromptValue extends InputPromptSource<InputSchema[\"Type\"], unknown, unknown> | undefined,\n UpdatesSchema extends Schema.Top | undefined,\n>(\n agent: RuntimeBinding<\n InputSchema,\n OutputSchema,\n Instructions,\n Tools,\n Provider,\n ModelProvides,\n ModelRequires,\n InstructionError,\n InstructionRequirements,\n RunDispositionValue,\n InputPromptValue,\n UpdatesSchema\n >,\n threadId: ThreadId,\n claim: Claim,\n) => Effect.Effect<\n Option.Option<Settlement>,\n DurableWorkerFailure | DurableBindingFailure,\n DurableWorkerRequirements<\n RuntimeBinding<\n InputSchema,\n OutputSchema,\n Instructions,\n Tools,\n Provider,\n ModelProvides,\n ModelRequires,\n InstructionError,\n InstructionRequirements,\n RunDispositionValue,\n InputPromptValue,\n UpdatesSchema\n >,\n InstructionRequirements\n >\n>;\n\ntype CapturedAttempt<A extends ExecutableAgentBinding> = (\n agent: A,\n threadId: ThreadId,\n claim: Claim,\n) => Effect.Effect<\n Option.Option<Settlement>,\n DurableWorkerFailure | DurableBindingFailure,\n DurableWorkerRequirements<A>\n>;\n\n/**\n * An Agent with its worker services captured, ready to drive a fenced Attempt.\n * Concrete Schema and model types stay inside this closure when registrations are collected.\n */\ninterface CapturedBinding {\n readonly agentId: AgentId;\n /** Exact immutable definition whose codecs and behavior the worker captured. */\n readonly definition: Agent.AnyDefinition;\n /** Captured independently from per-Attempt services: report preparation has no fenced Claim. */\n readonly reporting?: ReadonlyArray<WorkerReporting<WorkerReportPreparationFailure>>;\n readonly attempt: (\n driver: ResolvedAttemptDriver,\n threadId: ThreadId,\n claim: Claim,\n ) => Effect.Effect<Option.Option<Settlement>, DurableWorkerFailure | DurableBindingFailure>;\n}\n\n// Registrations outlive their construction span. Dependencies remain captured,\n// while every attempt/report inherits the invoking fiber's tracing state.\nconst omitTraceContext = Context.omit(\n Scope.Scope,\n Tracer.ParentSpan,\n Tracer.Tracer,\n Tracer.MinimumTraceLevel,\n Tracer.CurrentTraceLevel,\n References.TracerEnabled,\n References.TracerTimingEnabled,\n References.TracerSpanAnnotations,\n References.TracerSpanLinks,\n References.CurrentLoggers,\n References.CurrentLogLevel,\n References.MinimumLogLevel,\n References.CurrentStackFrame,\n References.CurrentLogAnnotations,\n References.CurrentLogSpans,\n);\n\n// R describes captured application services; ParentSpan is supplied by the\n// live invocation rather than stored as a registration dependency.\nconst withoutTraceContext = <R>(context: Context.Context<R>): Context.Context<R> =>\n omitTraceContext(context) as Context.Context<R>;\n\nconst captureReporting = <E, R>(reports: ReadonlyArray<WorkerReporting<E, R>>) =>\n Effect.map(\n Effect.context<Exclude<R, Scope.Scope>>().pipe(Effect.map(withoutTraceContext)),\n (context) =>\n reports.map((report): WorkerReporting<WorkerReportPreparationFailure> => ({\n ...report,\n prepare: (value) =>\n Effect.scoped(Effect.suspend(() => report.prepare(value))).pipe(\n Effect.provide(context),\n Effect.mapError((error) =>\n Schema.is(WorkerReportPreparationFailure)(error)\n ? error\n : WorkerReportPreparationFailure.make({ stage: \"preparation\" }),\n ),\n ),\n })),\n );\n\nconst backgroundReports = (definition: Agent.AnyDefinition) => [\n ...new Set(\n Object.values(definition.toolkit.tools).flatMap((tool) => {\n const report = Context.get(tool.annotations, BackgroundReporting);\n\n return report === undefined ? [] : [report];\n }),\n ),\n];\n\n/** One exact executable registration used by durable claim-time resolution. */\nexport interface ResolvedBinding extends CapturedBinding {\n readonly digests: DefinitionDigests;\n}\n\n/** Trusted claim identity for resolving per-Attempt application services. Not model input. */\nexport interface AgentAttemptContext {\n readonly threadId: ThreadId;\n readonly submissionId: Claim[\"submissionId\"];\n readonly attemptId: Claim[\"attemptId\"];\n}\n\nconst capture = <A extends ExecutableAgentBinding, Requires>(\n agent: A,\n prepare: (\n execute: ReturnType<CapturedAttempt<A>>,\n context: AgentAttemptContext,\n ) => Effect.Effect<\n Option.Option<Settlement>,\n DurableWorkerFailure | DurableBindingFailure,\n Requires\n >,\n): Effect.Effect<CapturedBinding, never, Requires> =>\n Effect.map(\n Effect.context<Requires>().pipe(Effect.map(withoutTraceContext)),\n (context): CapturedBinding => ({\n agentId: agent.definition.id,\n definition: agent.definition,\n attempt: (driver, threadId, claim) => {\n // Registration closes one concrete Binding before heterogeneous registrations are\n // collected. TypeScript cannot instantiate the higher-rank RuntimeBinding parameters\n // from the intentionally erased public shape, so specialize the driver back to A here.\n const run = driver as unknown as CapturedAttempt<A>;\n\n const execute = withProvisionalTextAttempt(\n run(agent, threadId, claim),\n threadId,\n claim.submissionId,\n claim.attemptId,\n );\n\n return prepare(execute, {\n threadId,\n submissionId: claim.submissionId,\n attemptId: claim.attemptId,\n }).pipe(Effect.provide(context));\n },\n }),\n );\n\nconst captureWithAttemptLayer = <A extends ExecutableAgentBinding, Provides, Requires>(\n agent: A,\n attemptLayer: (context: AgentAttemptContext) => Layer.Layer<Provides, never, Requires>,\n) =>\n capture(agent, (execute, context) =>\n execute.pipe(Effect.provide(Layer.fresh(attemptLayer(context)))),\n );\n\n/**\n * Build one exact worker registration from an executable Agent Binding and\n * its already-computed definition digests.\n *\n * `make(agent, digests)` captures the binding plus its worker-requirement\n * Context at Layer/effect construction time. Hosts that start from application\n * version declarations should use `compileRegistrations`; low-level fixtures\n * may supply a previously computed digest triple directly.\n */\nexport const DurableWorkerBinding = {\n make: <A extends ExecutableAgentBinding>(\n agent: A,\n digests: DefinitionDigests,\n ): Effect.Effect<ResolvedBinding, never, DurableWorkerRequirements<A>> =>\n Effect.gen(function* () {\n const binding = yield* capture(agent, (execute) => execute);\n const reporting = yield* captureReporting(backgroundReports(agent.definition));\n\n return { ...binding, digests, reporting };\n }),\n} as const;\n\n/** INTERNAL identity-only capture retained for the legacy direct worker path. */\nexport const makeLegacyWorkerBinding = <A extends ExecutableAgentBinding>(agent: A) =>\n capture(agent, (execute) => execute);\n\nexport const resolveWorkerBinding = Effect.fnUntraced(function* (\n bindings: ReadonlyArray<ResolvedBinding>,\n submission: SubmissionSnapshot,\n) {\n const selection = yield* CurrentBindingSelection;\n const definition = selection === undefined ? undefined : yield* selection.select(submission);\n\n const registered = bindings.filter(\n (binding) =>\n binding.agentId === submission.agentId &&\n (definition === undefined || Object.is(binding.definition, definition)),\n );\n\n const binding = registered[0];\n\n if (registered.length !== 1 || binding === undefined)\n return yield* BindingUnavailable.make({\n agentId: submission.agentId,\n message: \"Exactly one current Agent Binding must match the accepted Submission\",\n });\n\n return binding;\n});\n\n/** Resolve authoring-time admission through exact host registration, never by identity alone. */\nexport const resolveDefinitionBinding = (\n bindings: ReadonlyArray<ResolvedBinding>,\n definition: Pick<Agent.AnyDefinition, \"id\">,\n): Effect.Effect<ResolvedBinding, BindingUnavailable> => {\n const candidates = bindings.filter(\n (binding) => binding.agentId === definition.id && Object.is(binding.definition, definition),\n );\n\n const binding = candidates[0];\n\n return candidates.length === 1 && binding !== undefined\n ? Effect.succeed(binding)\n : Effect.fail(\n BindingUnavailable.make({\n agentId: definition.id,\n message:\n \"Registered admission requires exactly one registration of the exact Agent Definition\",\n }),\n );\n};\n\n/** Application versions and a model Layer, supplied directly or through an existing Binding. */\nexport type AgentRegistration<A extends ExecutableAgentBinding = ExecutableAgentBinding> = (\n | { readonly agent: A; readonly model?: never; readonly definitions: DefinitionDigestInput }\n | {\n readonly agent: A[\"definition\"];\n readonly model: A[\"model\"];\n readonly definitions: DefinitionDigestInput;\n }\n) & {\n /** Explicit operation versions let unchanged unfinished handlers survive toolbox changes. */\n readonly continuity?: {\n readonly versions: ReplayVersions;\n };\n /**\n * Build fresh services for exactly one fenced Attempt, across all its Tool/model turns.\n * Finalizes on completion, suspension, failure and interruption. Never reused after eviction.\n * Resolve invocation authority from the trusted claim identity, not captured caller state.\n * Keep fallible resource acquisition lazy in typed Tool operations; this Layer cannot fail.\n * Provide DurableApprovalSuspension here when resources need retention before approval waits.\n */\n readonly attemptLayer?: (context: AgentAttemptContext) => Layer.Layer<never, never, unknown>;\n};\n\ntype EntryWorkerRequirements<Entry> = Entry extends {\n readonly agent: infer A extends ExecutableAgentBinding;\n}\n ? DurableWorkerRequirements<A>\n : Entry extends {\n readonly agent: infer D extends ExecutableDefinition;\n readonly model: infer M extends ExecutableAgentBinding[\"model\"];\n }\n ? DurableWorkerRequirements<{ readonly definition: D; readonly model: M }>\n : never;\n\ntype AttemptLayerRequirements<Requirements, AttemptLayer> = AttemptLayer extends (\n context: AgentAttemptContext,\n) => Layer.Layer<infer Provides, never, infer Requires>\n ? Exclude<Requirements, Provides> | Requires\n : Requirements;\n\n// Conditional options retain every service they may consume. An absent attempt Layer\n// still needs the original worker services; only a definite Layer can remove them.\ntype EntryRequirements<Entry> = Entry extends unknown\n ? AttemptLayerRequirements<\n EntryWorkerRequirements<Entry>,\n \"attemptLayer\" extends keyof Entry ? Entry[\"attemptLayer\"] : undefined\n >\n : never;\n\ntype RegistrationRequirements<Entries extends ReadonlyArray<AgentRegistration>> = EntryRequirements<\n Entries[number]\n>;\n\nconst registrationDefinitions = (entry: AgentRegistration): DefinitionDigestInput => {\n const definition = entry.model === undefined ? entry.agent.definition : entry.agent;\n const automatic = backgroundReports(definition);\n\n const declaredDefinitions =\n definition.updates === undefined\n ? entry.definitions\n : {\n ...entry.definitions,\n agent: {\n declaration: entry.definitions.agent,\n updates: Schema.decodeUnknownSync(Schema.Json)(\n Tool.getJsonSchemaFromSchema(definition.updates),\n ),\n updateProtocol: { schemaVersion: 1, tool: \"emit_update\" },\n },\n };\n\n const definitions =\n automatic.length === 0\n ? declaredDefinitions\n : {\n ...declaredDefinitions,\n agent: {\n declaration: declaredDefinitions.agent,\n backgroundReporting: automatic.map((report) => ({\n delegationId: report.delegationId,\n targetAgentId: report.target.id,\n mode: \"standard\",\n // Preserve the fingerprint of existing standard registrations.\n destinationDelegationId: null,\n })),\n },\n };\n\n const exposure = definition.toolExposure;\n\n if (\n exposure === undefined &&\n !Object.values(definition.toolkit.tools).some(\n (tool) =>\n Context.get(tool.annotations, DiscoveryTool) || Context.get(tool.annotations, PinnedTool),\n )\n )\n return definitions;\n\n return {\n ...definitions,\n agent: {\n declaration: definitions.agent,\n toolExposure: {\n initialToolNames: exposure === undefined ? null : [...(exposure.initialToolNames ?? [])],\n maxTools: exposure?.maxTools ?? 64,\n maxSchemaBytes: exposure?.maxSchemaBytes ?? 262_144,\n requiredCompletion:\n definition.completion?.required === true ? definition.completion.tool : null,\n tools: Object.values(definition.toolkit.tools).map((tool) => ({\n name: tool.name,\n pinned: Context.get(tool.annotations, PinnedTool),\n discovery: Context.get(tool.annotations, DiscoveryTool),\n namespace: Context.get(tool.annotations, ToolNamespace) ?? null,\n includesCatalogDocumentation: Context.get(tool.annotations, IncludesCatalogDocumentation),\n additional: Context.get(tool.annotations, AdditionalToolCatalog).map((entry) => ({\n name: entry.tool.name,\n namespace: entry.namespace,\n method: entry.method,\n })),\n })),\n },\n },\n };\n};\n\n// The public signature distributes over descriptors, including optional attempt Layers.\n// The implementation consumes their erased union and captures the selected Layer's context.\nfunction compileRegistration<Entry extends AgentRegistration>(\n entry: Entry,\n): Effect.Effect<ResolvedBinding, DigestError, Crypto.Crypto | EntryRequirements<Entry>>;\nfunction compileRegistration(entry: AgentRegistration) {\n return Effect.flatMap(\n Effect.try({\n try: () => registrationDefinitions(entry),\n catch: () =>\n DigestError.make({ message: \"Agent update schema has no serializable wire contract\" }),\n }),\n (definitions) =>\n Effect.gen(function* () {\n const agent =\n // The heterogeneous descriptor erases model services; the overload retains EntryRequirements.\n // @effect-diagnostics-next-line anyUnknownInErrorContext:off\n entry.model === undefined ? entry.agent : { definition: entry.agent, model: entry.model };\n\n // Omitted attempt services need no Layer construction or provisioning scope.\n const binding = yield* entry.attemptLayer === undefined\n ? // Capture closes the erased requirements over the registration's actual Context.\n // @effect-diagnostics-next-line anyUnknownInErrorContext:off\n capture(agent, (execute) => execute)\n : // The selected Layer discharges its services before the remaining Context is captured.\n // @effect-diagnostics-next-line anyUnknownInErrorContext:off\n captureWithAttemptLayer(agent, entry.attemptLayer);\n\n const reporting = yield* captureReporting(backgroundReports(binding.definition));\n\n return {\n ...binding,\n ...(yield* compileBindingContracts(\n binding.definition,\n definitions,\n entry.continuity?.versions,\n )),\n reporting,\n };\n }),\n );\n}\n\n/** Compile heterogeneous Agent descriptors into exact, dependency-closed worker registrations. */\nexport const compileRegistrations = <const Entries extends ReadonlyArray<AgentRegistration>>(\n entries: Entries,\n): Effect.Effect<\n ReadonlyArray<ResolvedBinding>,\n DigestError,\n Crypto.Crypto | RegistrationRequirements<Entries>\n> => {\n return Effect.forEach(entries, compileRegistration<Entries[number]>);\n};\n"],"mappings":";;;;;;;;;;;;;AAmCA,IAAa,qBAAb,cAAwC,OAAO,YAAgC,CAAC,CAC9E,sBACA;CAAE,SAAS;CAAS,SAAS,OAAO;AAAO,CAC7C,CAAC,CAAC,CAAC;;AAsBH,MAAa,0BAA0B,QAAQ,UAC7C,gDACA,EAAE,oBAAoB,KAAA,EAAU,CAClC;;AAGA,MAAa,0BACX,MACA,UAEA,KAAK,UAAU,MAAM,SACrB,KAAK,UAAU,MAAM,SACrB,KAAK,UAAU,MAAM,SACrB,OAAO,cAAc,OAAO,YAAY,cAAc,CAAC,CAAC,CAAC,KAAK,QAAQ,MAAM,MAAM;AAYpF,MAAM,0CAA0B,IAAI,QAAiC;AAUrE,MAAM,oCAAoB,IAAI,QAAiE;;AAG/F,MAAa,sBAAsB,OAAO,WAAW,WACnD,YACA,UACA,kBAAiC,MACjC;CAGA,MAAM,SAAS,OAAO,eAAe,OAAO,OAAO,cAAc,OAAO,MAAM,C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AAQ,UAAU,CAAC;EAE/E,OAAO;GACL,GAAG;GACH,GAAI,OAAO,wBACT,QAAQ,YACR,aACA,MAAM,YAAY,QACpB;GACA;EACF;CACF,CAAC,CACL;AACF;;AAGA,MAAa,wBACX,YAKG;CACH,OAAO,OAAO,QAAQ,SAAS,mBAAoC;AACrE"}
|
|
@@ -102,7 +102,7 @@ const ApprovalAuditMemoryLive = Layer.effect(ApprovalAudit, Effect.gen(function*
|
|
|
102
102
|
pending: /* @__PURE__ */ new Set()
|
|
103
103
|
});
|
|
104
104
|
return ApprovalAudit.of({
|
|
105
|
-
recordRequest:
|
|
105
|
+
recordRequest: Effect.fnUntraced(function* (request) {
|
|
106
106
|
const recordedAt = DateTime.toUtc(DateTime.makeUnsafe(yield* Clock.currentTimeMillis));
|
|
107
107
|
const error = yield* Ref.modify(state, (current) => {
|
|
108
108
|
const reservedSize = current.events.length + current.pending.size + 2;
|
|
@@ -122,7 +122,7 @@ const ApprovalAuditMemoryLive = Layer.effect(ApprovalAudit, Effect.gen(function*
|
|
|
122
122
|
});
|
|
123
123
|
if (error !== void 0) return yield* error;
|
|
124
124
|
}),
|
|
125
|
-
recordDecision:
|
|
125
|
+
recordDecision: Effect.fnUntraced(function* (decision) {
|
|
126
126
|
const recordedAt = DateTime.toUtc(DateTime.makeUnsafe(yield* Clock.currentTimeMillis));
|
|
127
127
|
const error = yield* Ref.modify(state, (current) => {
|
|
128
128
|
if (!current.pending.has(decision.requestId)) return [ApprovalDecisionMismatch.make({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Approval.mjs","names":[],"sources":["../../src/capabilities/Approval.ts"],"sourcesContent":["import { Clock, Context, DateTime, Duration, Effect, Layer, Ref, Schema } from \"effect\";\n\nimport { ThreadId, RunId, ToolCallId } from \"../core/Identifiers.ts\";\nimport { utf8ByteLength } from \"../core/internal/utf8.ts\";\nimport { RedactedPreview, Redactor, type RedactionError } from \"./Redaction.ts\";\n\nconst MAX_APPROVAL_TARGETS = 32;\nconst MAX_APPROVAL_TARGET_BYTES = 64 * 1024;\nconst MAX_APPROVAL_AUDIT_EVENTS = 2_048;\n\nconst ApprovalTargets = Schema.Array(Schema.String.check(Schema.isMaxLength(2 * 1024)))\n .check(Schema.isMaxLength(MAX_APPROVAL_TARGETS))\n .pipe(\n Schema.refine(\n (targets): targets is ReadonlyArray<string> =>\n targets.reduce((total, target) => total + utf8ByteLength(target), 0) <=\n MAX_APPROVAL_TARGET_BYTES,\n { expected: `approval targets totaling at most ${MAX_APPROVAL_TARGET_BYTES} UTF-8 bytes` },\n ),\n );\n\nconst ApprovalRequestFields = {\n requestId: Schema.NonEmptyString,\n runId: RunId,\n threadId: ThreadId,\n toolCallId: ToolCallId,\n toolName: Schema.NonEmptyString,\n actionSummary: Schema.String.check(Schema.isMaxLength(2 * 1024)),\n resourceTargets: ApprovalTargets,\n risk: Schema.Literals([\"low\", \"medium\", \"high\", \"critical\"]),\n expiresAt: Schema.DateTimeUtcFromString,\n denial: Schema.Literals([\"terminal\", \"recoverable\"]),\n} as const;\n\n/** Decoded approval metadata before the Redactor owns Tool input preview creation. */\nexport class ApprovalRequestDraft extends Schema.Class<ApprovalRequestDraft>(\n \"@effect-agent/capabilities/ApprovalRequestDraft\",\n)(ApprovalRequestFields) {}\n\n/** Fully decoded, structurally redacted approval input. */\nexport class ApprovalRequest extends Schema.Class<ApprovalRequest>(\n \"@effect-agent/capabilities/ApprovalRequest\",\n)({\n ...ApprovalRequestFields,\n redactedInputPreview: RedactedPreview,\n}) {}\n\nexport class ApprovalApproved extends Schema.TaggedClass<ApprovalApproved>()(\"ApprovalApproved\", {\n requestId: Schema.NonEmptyString,\n decidedAt: Schema.DateTimeUtcFromString,\n resolver: Schema.NonEmptyString,\n}) {}\n\nexport class ApprovalDenied extends Schema.TaggedClass<ApprovalDenied>()(\"ApprovalDenied\", {\n requestId: Schema.NonEmptyString,\n decidedAt: Schema.DateTimeUtcFromString,\n resolver: Schema.NonEmptyString,\n reason: Schema.String.check(Schema.isMaxLength(2 * 1024)),\n timedOut: Schema.Boolean,\n}) {}\n\nexport const ApprovalDecision = Schema.Union([ApprovalApproved, ApprovalDenied]);\nexport type ApprovalDecision = typeof ApprovalDecision.Type;\n\n/** Resolver infrastructure failed before it could make a policy decision. */\nexport class ApprovalResolverError extends Schema.TaggedError<ApprovalResolverError>()(\n \"ApprovalResolverError\",\n { message: Schema.String },\n) {}\n\n/** The resolver explicitly observed its request deadline; callers turn this into a denial. */\nexport class ApprovalTimedOut extends Schema.TaggedError<ApprovalTimedOut>()(\"ApprovalTimedOut\", {\n requestId: Schema.NonEmptyString,\n}) {}\n\n/** First-class approval authority. Interactive, policy, and remote adapters implement this service. */\nexport class ApprovalResolver extends Context.Service<\n ApprovalResolver,\n {\n readonly request: (\n request: ApprovalRequest,\n ) => Effect.Effect<ApprovalDecision, ApprovalResolverError | ApprovalTimedOut>;\n }\n>()(\"@effect-agent/capabilities/ApprovalResolver\") {}\n\nexport class ApprovalRequestRecorded extends Schema.TaggedClass<ApprovalRequestRecorded>()(\n \"ApprovalRequestRecorded\",\n {\n sequence: Schema.Natural,\n recordedAt: Schema.DateTimeUtcFromString,\n request: ApprovalRequest,\n },\n) {}\n\nexport class ApprovalDecisionRecorded extends Schema.TaggedClass<ApprovalDecisionRecorded>()(\n \"ApprovalDecisionRecorded\",\n {\n sequence: Schema.Natural,\n recordedAt: Schema.DateTimeUtcFromString,\n decision: ApprovalDecision,\n },\n) {}\n\nexport const ApprovalAuditEvent = Schema.Union([ApprovalRequestRecorded, ApprovalDecisionRecorded]);\nexport type ApprovalAuditEvent = typeof ApprovalAuditEvent.Type;\n\nexport const ApprovalAuditEvents = Schema.Array(ApprovalAuditEvent).check(\n Schema.isMaxLength(MAX_APPROVAL_AUDIT_EVENTS),\n);\n\nexport class ApprovalAuditLimitExceeded extends Schema.TaggedError<ApprovalAuditLimitExceeded>()(\n \"ApprovalAuditLimitExceeded\",\n {\n limitValue: Schema.Natural,\n observedValue: Schema.Natural,\n },\n) {}\n\n/** A resolver or audit sink tried to associate a decision with another request. */\nexport class ApprovalDecisionMismatch extends Schema.TaggedError<ApprovalDecisionMismatch>()(\n \"ApprovalDecisionMismatch\",\n {\n expectedRequestId: Schema.NonEmptyString,\n observedRequestId: Schema.NonEmptyString,\n },\n) {}\n\n/** P2 semantic audit sink; durable runtimes replace this with canonical records. */\nexport class ApprovalAudit extends Context.Service<\n ApprovalAudit,\n {\n readonly recordRequest: (\n request: ApprovalRequest,\n ) => Effect.Effect<void, ApprovalAuditLimitExceeded>;\n readonly recordDecision: (\n decision: ApprovalDecision,\n ) => Effect.Effect<void, ApprovalAuditLimitExceeded | ApprovalDecisionMismatch>;\n readonly events: Effect.Effect<ReadonlyArray<ApprovalAuditEvent>>;\n }\n>()(\"@effect-agent/capabilities/ApprovalAudit\") {}\n\n/** Scoped in-memory audit projection with monotonic event order. */\nexport const ApprovalAuditMemoryLive = Layer.effect(\n ApprovalAudit,\n Effect.gen(function* () {\n interface AuditState {\n readonly events: ReadonlyArray<ApprovalAuditEvent>;\n readonly pending: ReadonlySet<string>;\n }\n const state = yield* Ref.make<AuditState>({ events: [], pending: new Set() });\n\n return ApprovalAudit.of({\n recordRequest: (request) =>\n Effect.gen(function* () {\n const recordedAt = DateTime.toUtc(DateTime.makeUnsafe(yield* Clock.currentTimeMillis));\n\n const error = yield* Ref.modify(state, (current) => {\n // Each accepted request atomically reserves room for its decision.\n const reservedSize = current.events.length + current.pending.size + 2;\n\n if (reservedSize > MAX_APPROVAL_AUDIT_EVENTS) {\n return [\n ApprovalAuditLimitExceeded.make({\n limitValue: MAX_APPROVAL_AUDIT_EVENTS,\n observedValue: reservedSize,\n }),\n current,\n ] as const;\n }\n\n const event = ApprovalRequestRecorded.make({\n sequence: current.events.length,\n recordedAt,\n request,\n });\n\n return [\n undefined,\n {\n events: [...current.events, event],\n pending: new Set(current.pending).add(request.requestId),\n },\n ] as const;\n });\n\n if (error !== undefined) return yield* error;\n }),\n recordDecision: (decision) =>\n Effect.gen(function* () {\n const recordedAt = DateTime.toUtc(DateTime.makeUnsafe(yield* Clock.currentTimeMillis));\n\n const error = yield* Ref.modify(state, (current) => {\n if (!current.pending.has(decision.requestId)) {\n return [\n ApprovalDecisionMismatch.make({\n expectedRequestId: [...current.pending][0] ?? \"no-pending-request\",\n observedRequestId: decision.requestId,\n }),\n current,\n ] as const;\n }\n const pending = new Set(current.pending);\n\n pending.delete(decision.requestId);\n\n const event = ApprovalDecisionRecorded.make({\n sequence: current.events.length,\n recordedAt,\n decision,\n });\n\n return [\n undefined,\n {\n events: [...current.events, event],\n pending,\n },\n ] as const;\n });\n\n if (error !== undefined) return yield* error;\n }),\n events: Ref.get(state).pipe(Effect.map((current) => current.events)),\n });\n }),\n);\n\n/** Construct an ApprovalRequest only after decoded input passes the configured Redactor. */\nexport const makeApprovalRequest = Effect.fnUntraced(function* (\n draft: ApprovalRequestDraft,\n decodedToolInput: unknown,\n): Effect.fn.Return<ApprovalRequest, RedactionError, Redactor> {\n const redactor = yield* Redactor;\n const redactedInputPreview = yield* redactor.redact(decodedToolInput);\n\n return ApprovalRequest.make({\n requestId: draft.requestId,\n runId: draft.runId,\n threadId: draft.threadId,\n toolCallId: draft.toolCallId,\n toolName: draft.toolName,\n actionSummary: draft.actionSummary,\n resourceTargets: draft.resourceTargets,\n risk: draft.risk,\n expiresAt: draft.expiresAt,\n denial: draft.denial,\n redactedInputPreview,\n });\n});\n\nconst timeoutDenial = (request: ApprovalRequest, decidedAt: DateTime.Utc): ApprovalDenied =>\n ApprovalDenied.make({\n requestId: request.requestId,\n decidedAt,\n resolver: \"effect-agent.timeout-deny\",\n reason: \"Approval request expired before a decision was available\",\n timedOut: true,\n });\n\n/**\n * Resolve with fail-closed deadline semantics and record request/decision audit\n * events around every successful, denied, timed-out, or resolver-failed\n * resolution. A resolver infrastructure failure records a synthetic denial so\n * the audit reservation is released before the typed error propagates.\n */\nexport const requestApproval = Effect.fnUntraced(function* (request: ApprovalRequest) {\n const audit = yield* ApprovalAudit;\n\n yield* audit.recordRequest(request);\n const nowMillis = yield* Clock.currentTimeMillis;\n const now = DateTime.toUtc(DateTime.makeUnsafe(nowMillis));\n const remainingMillis = DateTime.toEpochMillis(request.expiresAt) - nowMillis;\n\n let decision: ApprovalDecision;\n\n if (remainingMillis <= 0) {\n decision = timeoutDenial(request, now);\n } else {\n const resolver = yield* ApprovalResolver;\n\n decision = yield* resolver.request(request).pipe(\n Effect.timeoutOrElse({\n duration: Duration.millis(remainingMillis),\n orElse: () =>\n Clock.currentTimeMillis.pipe(\n Effect.map((millis) =>\n timeoutDenial(request, DateTime.toUtc(DateTime.makeUnsafe(millis))),\n ),\n ),\n }),\n Effect.catchTag(\"ApprovalTimedOut\", () =>\n Clock.currentTimeMillis.pipe(\n Effect.map((millis) =>\n timeoutDenial(request, DateTime.toUtc(DateTime.makeUnsafe(millis))),\n ),\n ),\n ),\n Effect.tapError(() =>\n Clock.currentTimeMillis.pipe(\n Effect.flatMap((millis) =>\n audit.recordDecision(\n ApprovalDenied.make({\n requestId: request.requestId,\n decidedAt: DateTime.toUtc(DateTime.makeUnsafe(millis)),\n resolver: \"effect-agent.resolver-error\",\n reason: \"Approval resolver failed before making a policy decision\",\n timedOut: false,\n }),\n ),\n ),\n ),\n ),\n );\n }\n if (decision.requestId !== request.requestId) {\n const mismatch = ApprovalDecisionMismatch.make({\n expectedRequestId: request.requestId,\n observedRequestId: decision.requestId,\n });\n\n const denied = ApprovalDenied.make({\n requestId: request.requestId,\n decidedAt: DateTime.toUtc(DateTime.makeUnsafe(yield* Clock.currentTimeMillis)),\n resolver: \"effect-agent.correlation-check\",\n reason: \"Approval resolver returned a decision for another request\",\n timedOut: false,\n });\n\n yield* audit.recordDecision(denied);\n\n return yield* mismatch;\n }\n yield* audit.recordDecision(decision);\n\n return decision;\n});\n\n/** Deterministic policy layer for tests and deny-by-default deployments. */\nexport const ApprovalDenyAll = Layer.succeed(ApprovalResolver)({\n request: (request) =>\n Clock.currentTimeMillis.pipe(\n Effect.map((millis) =>\n ApprovalDenied.make({\n requestId: request.requestId,\n decidedAt: DateTime.toUtc(DateTime.makeUnsafe(millis)),\n resolver: \"effect-agent.deny-all\",\n reason: \"No approving policy is configured\",\n timedOut: false,\n }),\n ),\n ),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,uBAAuB;AAC7B,MAAM,4BAA4B;AAClC,MAAM,4BAA4B;AAElC,MAAM,kBAAkB,OAAO,MAAM,OAAO,OAAO,MAAM,OAAO,YAAY,IAAQ,CAAC,CAAC,CAAC,CACpF,MAAM,OAAO,YAAY,oBAAoB,CAAC,CAAC,CAC/C,KACC,OAAO,QACJ,YACC,QAAQ,QAAQ,OAAO,WAAW,QAAQ,eAAe,MAAM,GAAG,CAAC,KACnE,2BACF,EAAE,UAAU,qCAAqC,0BAA0B,cAAc,CAC3F,CACF;AAEF,MAAM,wBAAwB;CAC5B,WAAW,OAAO;CAClB,OAAO;CACP,UAAU;CACV,YAAY;CACZ,UAAU,OAAO;CACjB,eAAe,OAAO,OAAO,MAAM,OAAO,YAAY,IAAQ,CAAC;CAC/D,iBAAiB;CACjB,MAAM,OAAO,SAAS;EAAC;EAAO;EAAU;EAAQ;CAAU,CAAC;CAC3D,WAAW,OAAO;CAClB,QAAQ,OAAO,SAAS,CAAC,YAAY,aAAa,CAAC;AACrD;;AAGA,IAAa,uBAAb,cAA0C,OAAO,MAC/C,iDACF,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC;;AAG1B,IAAa,kBAAb,cAAqC,OAAO,MAC1C,4CACF,CAAC,CAAC;CACA,GAAG;CACH,sBAAsB;AACxB,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAa,mBAAb,cAAsC,OAAO,YAA8B,CAAC,CAAC,oBAAoB;CAC/F,WAAW,OAAO;CAClB,WAAW,OAAO;CAClB,UAAU,OAAO;AACnB,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAa,iBAAb,cAAoC,OAAO,YAA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"],"sourcesContent":["import { Clock, Context, DateTime, Duration, Effect, Layer, Ref, Schema } from \"effect\";\n\nimport { ThreadId, RunId, ToolCallId } from \"../core/Identifiers.ts\";\nimport { utf8ByteLength } from \"../core/internal/utf8.ts\";\nimport { RedactedPreview, Redactor, type RedactionError } from \"./Redaction.ts\";\n\nconst MAX_APPROVAL_TARGETS = 32;\nconst MAX_APPROVAL_TARGET_BYTES = 64 * 1024;\nconst MAX_APPROVAL_AUDIT_EVENTS = 2_048;\n\nconst ApprovalTargets = Schema.Array(Schema.String.check(Schema.isMaxLength(2 * 1024)))\n .check(Schema.isMaxLength(MAX_APPROVAL_TARGETS))\n .pipe(\n Schema.refine(\n (targets): targets is ReadonlyArray<string> =>\n targets.reduce((total, target) => total + utf8ByteLength(target), 0) <=\n MAX_APPROVAL_TARGET_BYTES,\n { expected: `approval targets totaling at most ${MAX_APPROVAL_TARGET_BYTES} UTF-8 bytes` },\n ),\n );\n\nconst ApprovalRequestFields = {\n requestId: Schema.NonEmptyString,\n runId: RunId,\n threadId: ThreadId,\n toolCallId: ToolCallId,\n toolName: Schema.NonEmptyString,\n actionSummary: Schema.String.check(Schema.isMaxLength(2 * 1024)),\n resourceTargets: ApprovalTargets,\n risk: Schema.Literals([\"low\", \"medium\", \"high\", \"critical\"]),\n expiresAt: Schema.DateTimeUtcFromString,\n denial: Schema.Literals([\"terminal\", \"recoverable\"]),\n} as const;\n\n/** Decoded approval metadata before the Redactor owns Tool input preview creation. */\nexport class ApprovalRequestDraft extends Schema.Class<ApprovalRequestDraft>(\n \"@effect-agent/capabilities/ApprovalRequestDraft\",\n)(ApprovalRequestFields) {}\n\n/** Fully decoded, structurally redacted approval input. */\nexport class ApprovalRequest extends Schema.Class<ApprovalRequest>(\n \"@effect-agent/capabilities/ApprovalRequest\",\n)({\n ...ApprovalRequestFields,\n redactedInputPreview: RedactedPreview,\n}) {}\n\nexport class ApprovalApproved extends Schema.TaggedClass<ApprovalApproved>()(\"ApprovalApproved\", {\n requestId: Schema.NonEmptyString,\n decidedAt: Schema.DateTimeUtcFromString,\n resolver: Schema.NonEmptyString,\n}) {}\n\nexport class ApprovalDenied extends Schema.TaggedClass<ApprovalDenied>()(\"ApprovalDenied\", {\n requestId: Schema.NonEmptyString,\n decidedAt: Schema.DateTimeUtcFromString,\n resolver: Schema.NonEmptyString,\n reason: Schema.String.check(Schema.isMaxLength(2 * 1024)),\n timedOut: Schema.Boolean,\n}) {}\n\nexport const ApprovalDecision = Schema.Union([ApprovalApproved, ApprovalDenied]);\nexport type ApprovalDecision = typeof ApprovalDecision.Type;\n\n/** Resolver infrastructure failed before it could make a policy decision. */\nexport class ApprovalResolverError extends Schema.TaggedError<ApprovalResolverError>()(\n \"ApprovalResolverError\",\n { message: Schema.String },\n) {}\n\n/** The resolver explicitly observed its request deadline; callers turn this into a denial. */\nexport class ApprovalTimedOut extends Schema.TaggedError<ApprovalTimedOut>()(\"ApprovalTimedOut\", {\n requestId: Schema.NonEmptyString,\n}) {}\n\n/** First-class approval authority. Interactive, policy, and remote adapters implement this service. */\nexport class ApprovalResolver extends Context.Service<\n ApprovalResolver,\n {\n readonly request: (\n request: ApprovalRequest,\n ) => Effect.Effect<ApprovalDecision, ApprovalResolverError | ApprovalTimedOut>;\n }\n>()(\"@effect-agent/capabilities/ApprovalResolver\") {}\n\nexport class ApprovalRequestRecorded extends Schema.TaggedClass<ApprovalRequestRecorded>()(\n \"ApprovalRequestRecorded\",\n {\n sequence: Schema.Natural,\n recordedAt: Schema.DateTimeUtcFromString,\n request: ApprovalRequest,\n },\n) {}\n\nexport class ApprovalDecisionRecorded extends Schema.TaggedClass<ApprovalDecisionRecorded>()(\n \"ApprovalDecisionRecorded\",\n {\n sequence: Schema.Natural,\n recordedAt: Schema.DateTimeUtcFromString,\n decision: ApprovalDecision,\n },\n) {}\n\nexport const ApprovalAuditEvent = Schema.Union([ApprovalRequestRecorded, ApprovalDecisionRecorded]);\nexport type ApprovalAuditEvent = typeof ApprovalAuditEvent.Type;\n\nexport const ApprovalAuditEvents = Schema.Array(ApprovalAuditEvent).check(\n Schema.isMaxLength(MAX_APPROVAL_AUDIT_EVENTS),\n);\n\nexport class ApprovalAuditLimitExceeded extends Schema.TaggedError<ApprovalAuditLimitExceeded>()(\n \"ApprovalAuditLimitExceeded\",\n {\n limitValue: Schema.Natural,\n observedValue: Schema.Natural,\n },\n) {}\n\n/** A resolver or audit sink tried to associate a decision with another request. */\nexport class ApprovalDecisionMismatch extends Schema.TaggedError<ApprovalDecisionMismatch>()(\n \"ApprovalDecisionMismatch\",\n {\n expectedRequestId: Schema.NonEmptyString,\n observedRequestId: Schema.NonEmptyString,\n },\n) {}\n\n/** P2 semantic audit sink; durable runtimes replace this with canonical records. */\nexport class ApprovalAudit extends Context.Service<\n ApprovalAudit,\n {\n readonly recordRequest: (\n request: ApprovalRequest,\n ) => Effect.Effect<void, ApprovalAuditLimitExceeded>;\n readonly recordDecision: (\n decision: ApprovalDecision,\n ) => Effect.Effect<void, ApprovalAuditLimitExceeded | ApprovalDecisionMismatch>;\n readonly events: Effect.Effect<ReadonlyArray<ApprovalAuditEvent>>;\n }\n>()(\"@effect-agent/capabilities/ApprovalAudit\") {}\n\n/** Scoped in-memory audit projection with monotonic event order. */\nexport const ApprovalAuditMemoryLive = Layer.effect(\n ApprovalAudit,\n Effect.gen(function* () {\n interface AuditState {\n readonly events: ReadonlyArray<ApprovalAuditEvent>;\n readonly pending: ReadonlySet<string>;\n }\n const state = yield* Ref.make<AuditState>({ events: [], pending: new Set() });\n\n return ApprovalAudit.of({\n recordRequest: Effect.fnUntraced(function* (request) {\n const recordedAt = DateTime.toUtc(DateTime.makeUnsafe(yield* Clock.currentTimeMillis));\n\n const error = yield* Ref.modify(state, (current) => {\n // Each accepted request atomically reserves room for its decision.\n const reservedSize = current.events.length + current.pending.size + 2;\n\n if (reservedSize > MAX_APPROVAL_AUDIT_EVENTS) {\n return [\n ApprovalAuditLimitExceeded.make({\n limitValue: MAX_APPROVAL_AUDIT_EVENTS,\n observedValue: reservedSize,\n }),\n current,\n ] as const;\n }\n\n const event = ApprovalRequestRecorded.make({\n sequence: current.events.length,\n recordedAt,\n request,\n });\n\n return [\n undefined,\n {\n events: [...current.events, event],\n pending: new Set(current.pending).add(request.requestId),\n },\n ] as const;\n });\n\n if (error !== undefined) return yield* error;\n }),\n recordDecision: Effect.fnUntraced(function* (decision) {\n const recordedAt = DateTime.toUtc(DateTime.makeUnsafe(yield* Clock.currentTimeMillis));\n\n const error = yield* Ref.modify(state, (current) => {\n if (!current.pending.has(decision.requestId)) {\n return [\n ApprovalDecisionMismatch.make({\n expectedRequestId: [...current.pending][0] ?? \"no-pending-request\",\n observedRequestId: decision.requestId,\n }),\n current,\n ] as const;\n }\n const pending = new Set(current.pending);\n\n pending.delete(decision.requestId);\n\n const event = ApprovalDecisionRecorded.make({\n sequence: current.events.length,\n recordedAt,\n decision,\n });\n\n return [\n undefined,\n {\n events: [...current.events, event],\n pending,\n },\n ] as const;\n });\n\n if (error !== undefined) return yield* error;\n }),\n events: Ref.get(state).pipe(Effect.map((current) => current.events)),\n });\n }),\n);\n\n/** Construct an ApprovalRequest only after decoded input passes the configured Redactor. */\nexport const makeApprovalRequest = Effect.fnUntraced(function* (\n draft: ApprovalRequestDraft,\n decodedToolInput: unknown,\n): Effect.fn.Return<ApprovalRequest, RedactionError, Redactor> {\n const redactor = yield* Redactor;\n const redactedInputPreview = yield* redactor.redact(decodedToolInput);\n\n return ApprovalRequest.make({\n requestId: draft.requestId,\n runId: draft.runId,\n threadId: draft.threadId,\n toolCallId: draft.toolCallId,\n toolName: draft.toolName,\n actionSummary: draft.actionSummary,\n resourceTargets: draft.resourceTargets,\n risk: draft.risk,\n expiresAt: draft.expiresAt,\n denial: draft.denial,\n redactedInputPreview,\n });\n});\n\nconst timeoutDenial = (request: ApprovalRequest, decidedAt: DateTime.Utc): ApprovalDenied =>\n ApprovalDenied.make({\n requestId: request.requestId,\n decidedAt,\n resolver: \"effect-agent.timeout-deny\",\n reason: \"Approval request expired before a decision was available\",\n timedOut: true,\n });\n\n/**\n * Resolve with fail-closed deadline semantics and record request/decision audit\n * events around every successful, denied, timed-out, or resolver-failed\n * resolution. A resolver infrastructure failure records a synthetic denial so\n * the audit reservation is released before the typed error propagates.\n */\nexport const requestApproval = Effect.fnUntraced(function* (request: ApprovalRequest) {\n const audit = yield* ApprovalAudit;\n\n yield* audit.recordRequest(request);\n const nowMillis = yield* Clock.currentTimeMillis;\n const now = DateTime.toUtc(DateTime.makeUnsafe(nowMillis));\n const remainingMillis = DateTime.toEpochMillis(request.expiresAt) - nowMillis;\n\n let decision: ApprovalDecision;\n\n if (remainingMillis <= 0) {\n decision = timeoutDenial(request, now);\n } else {\n const resolver = yield* ApprovalResolver;\n\n decision = yield* resolver.request(request).pipe(\n Effect.timeoutOrElse({\n duration: Duration.millis(remainingMillis),\n orElse: () =>\n Clock.currentTimeMillis.pipe(\n Effect.map((millis) =>\n timeoutDenial(request, DateTime.toUtc(DateTime.makeUnsafe(millis))),\n ),\n ),\n }),\n Effect.catchTag(\"ApprovalTimedOut\", () =>\n Clock.currentTimeMillis.pipe(\n Effect.map((millis) =>\n timeoutDenial(request, DateTime.toUtc(DateTime.makeUnsafe(millis))),\n ),\n ),\n ),\n Effect.tapError(() =>\n Clock.currentTimeMillis.pipe(\n Effect.flatMap((millis) =>\n audit.recordDecision(\n ApprovalDenied.make({\n requestId: request.requestId,\n decidedAt: DateTime.toUtc(DateTime.makeUnsafe(millis)),\n resolver: \"effect-agent.resolver-error\",\n reason: \"Approval resolver failed before making a policy decision\",\n timedOut: false,\n }),\n ),\n ),\n ),\n ),\n );\n }\n if (decision.requestId !== request.requestId) {\n const mismatch = ApprovalDecisionMismatch.make({\n expectedRequestId: request.requestId,\n observedRequestId: decision.requestId,\n });\n\n const denied = ApprovalDenied.make({\n requestId: request.requestId,\n decidedAt: DateTime.toUtc(DateTime.makeUnsafe(yield* Clock.currentTimeMillis)),\n resolver: \"effect-agent.correlation-check\",\n reason: \"Approval resolver returned a decision for another request\",\n timedOut: false,\n });\n\n yield* audit.recordDecision(denied);\n\n return yield* mismatch;\n }\n yield* audit.recordDecision(decision);\n\n return decision;\n});\n\n/** Deterministic policy layer for tests and deny-by-default deployments. */\nexport const ApprovalDenyAll = Layer.succeed(ApprovalResolver)({\n request: (request) =>\n Clock.currentTimeMillis.pipe(\n Effect.map((millis) =>\n ApprovalDenied.make({\n requestId: request.requestId,\n decidedAt: DateTime.toUtc(DateTime.makeUnsafe(millis)),\n resolver: \"effect-agent.deny-all\",\n reason: \"No approving policy is configured\",\n timedOut: false,\n }),\n ),\n ),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,uBAAuB;AAC7B,MAAM,4BAA4B;AAClC,MAAM,4BAA4B;AAElC,MAAM,kBAAkB,OAAO,MAAM,OAAO,OAAO,MAAM,OAAO,YAAY,IAAQ,CAAC,CAAC,CAAC,CACpF,MAAM,OAAO,YAAY,oBAAoB,CAAC,CAAC,CAC/C,KACC,OAAO,QACJ,YACC,QAAQ,QAAQ,OAAO,WAAW,QAAQ,eAAe,MAAM,GAAG,CAAC,KACnE,2BACF,EAAE,UAAU,qCAAqC,0BAA0B,cAAc,CAC3F,CACF;AAEF,MAAM,wBAAwB;CAC5B,WAAW,OAAO;CAClB,OAAO;CACP,UAAU;CACV,YAAY;CACZ,UAAU,OAAO;CACjB,eAAe,OAAO,OAAO,MAAM,OAAO,YAAY,IAAQ,CAAC;CAC/D,iBAAiB;CACjB,MAAM,OAAO,SAAS;EAAC;EAAO;EAAU;EAAQ;CAAU,CAAC;CAC3D,WAAW,OAAO;CAClB,QAAQ,OAAO,SAAS,CAAC,YAAY,aAAa,CAAC;AACrD;;AAGA,IAAa,uBAAb,cAA0C,OAAO,MAC/C,iDACF,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC;;AAG1B,IAAa,kBAAb,cAAqC,OAAO,MAC1C,4CACF,CAAC,CAAC;CACA,GAAG;CACH,sBAA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