agentfootprint 9.114.2 → 9.115.0
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/AGENTS.md +1 -1
- package/CAPABILITIES.md +3 -0
- package/ai-instructions/claude-code/SKILL.md +1 -1
- package/dist/adapters/hosting/agentCoreA2A.js +5 -0
- package/dist/adapters/hosting/agentCoreA2A.js.map +1 -1
- package/dist/adapters/hosting/agentcore.js +5 -0
- package/dist/adapters/hosting/agentcore.js.map +1 -1
- package/dist/adapters/hosting/foundryResponses.js +5 -0
- package/dist/adapters/hosting/foundryResponses.js.map +1 -1
- package/dist/adapters/observability/agentcore.js +18 -5
- package/dist/adapters/observability/agentcore.js.map +1 -1
- package/dist/adapters/observability/audit.js +17 -4
- package/dist/adapters/observability/audit.js.map +1 -1
- package/dist/adapters/observability/otel.js +890 -33
- package/dist/adapters/observability/otel.js.map +1 -1
- package/dist/artifacts/capability.js +9 -3
- package/dist/artifacts/capability.js.map +1 -1
- package/dist/bridge/eventMeta.js +40 -1
- package/dist/bridge/eventMeta.js.map +1 -1
- package/dist/core/Agent.js +40 -6
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/RunnerBase.js +32 -1
- package/dist/core/RunnerBase.js.map +1 -1
- package/dist/core/agent/AgentBuilder.js +13 -1
- package/dist/core/agent/AgentBuilder.js.map +1 -1
- package/dist/core/agent/stages/toolCalls.js +64 -7
- package/dist/core/agent/stages/toolCalls.js.map +1 -1
- package/dist/core/flowchartAsTool.js +8 -2
- package/dist/core/flowchartAsTool.js.map +1 -1
- package/dist/core/runbook/runbookAsTool.js +7 -2
- package/dist/core/runbook/runbookAsTool.js.map +1 -1
- package/dist/core/toolShownArgs.js +55 -0
- package/dist/core/toolShownArgs.js.map +1 -0
- package/dist/esm/adapters/hosting/agentCoreA2A.d.ts +14 -1
- package/dist/esm/adapters/hosting/agentCoreA2A.js +5 -0
- package/dist/esm/adapters/hosting/agentCoreA2A.js.map +1 -1
- package/dist/esm/adapters/hosting/agentcore.d.ts +18 -2
- package/dist/esm/adapters/hosting/agentcore.js +5 -0
- package/dist/esm/adapters/hosting/agentcore.js.map +1 -1
- package/dist/esm/adapters/hosting/foundryResponses.d.ts +15 -1
- package/dist/esm/adapters/hosting/foundryResponses.js +5 -0
- package/dist/esm/adapters/hosting/foundryResponses.js.map +1 -1
- package/dist/esm/adapters/observability/agentcore.d.ts +17 -5
- package/dist/esm/adapters/observability/agentcore.js +18 -5
- package/dist/esm/adapters/observability/agentcore.js.map +1 -1
- package/dist/esm/adapters/observability/audit.d.ts +6 -2
- package/dist/esm/adapters/observability/audit.js +17 -4
- package/dist/esm/adapters/observability/audit.js.map +1 -1
- package/dist/esm/adapters/observability/otel.d.ts +240 -11
- package/dist/esm/adapters/observability/otel.js +890 -33
- package/dist/esm/adapters/observability/otel.js.map +1 -1
- package/dist/esm/artifacts/capability.d.ts +3 -1
- package/dist/esm/artifacts/capability.js +9 -3
- package/dist/esm/artifacts/capability.js.map +1 -1
- package/dist/esm/bridge/eventMeta.d.ts +32 -0
- package/dist/esm/bridge/eventMeta.js +38 -0
- package/dist/esm/bridge/eventMeta.js.map +1 -1
- package/dist/esm/core/Agent.d.ts +18 -5
- package/dist/esm/core/Agent.js +42 -8
- package/dist/esm/core/Agent.js.map +1 -1
- package/dist/esm/core/RunnerBase.d.ts +20 -0
- package/dist/esm/core/RunnerBase.js +32 -1
- package/dist/esm/core/RunnerBase.js.map +1 -1
- package/dist/esm/core/agent/AgentBuilder.js +13 -1
- package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
- package/dist/esm/core/agent/stages/toolCalls.d.ts +11 -0
- package/dist/esm/core/agent/stages/toolCalls.js +64 -7
- package/dist/esm/core/agent/stages/toolCalls.js.map +1 -1
- package/dist/esm/core/flowchartAsTool.js +8 -2
- package/dist/esm/core/flowchartAsTool.js.map +1 -1
- package/dist/esm/core/runbook/runbookAsTool.js +7 -2
- package/dist/esm/core/runbook/runbookAsTool.js.map +1 -1
- package/dist/esm/core/toolShownArgs.d.ts +62 -0
- package/dist/esm/core/toolShownArgs.js +49 -0
- package/dist/esm/core/toolShownArgs.js.map +1 -0
- package/dist/esm/events/payloads.d.ts +122 -6
- package/dist/esm/events/registry.d.ts +3 -1
- package/dist/esm/events/registry.js +2 -0
- package/dist/esm/events/registry.js.map +1 -1
- package/dist/esm/events/types.d.ts +7 -0
- package/dist/esm/hosting/artifactWire.d.ts +10 -2
- package/dist/esm/hosting/artifactWire.js +20 -2
- package/dist/esm/hosting/artifactWire.js.map +1 -1
- package/dist/esm/hosting/doorGuard.d.ts +280 -0
- package/dist/esm/hosting/doorGuard.js +499 -0
- package/dist/esm/hosting/doorGuard.js.map +1 -0
- package/dist/esm/hosting/errors.d.ts +113 -0
- package/dist/esm/hosting/errors.js +177 -0
- package/dist/esm/hosting/errors.js.map +1 -1
- package/dist/esm/hosting/httpHost.d.ts +32 -3
- package/dist/esm/hosting/httpHost.js +218 -4
- package/dist/esm/hosting/httpHost.js.map +1 -1
- package/dist/esm/hosting/index.d.ts +7 -5
- package/dist/esm/hosting/index.js +10 -3
- package/dist/esm/hosting/index.js.map +1 -1
- package/dist/esm/hosting/ingressRecord.d.ts +64 -10
- package/dist/esm/hosting/ingressRecord.js +65 -6
- package/dist/esm/hosting/ingressRecord.js.map +1 -1
- package/dist/esm/hosting/nodeHost.d.ts +32 -2
- package/dist/esm/hosting/nodeHost.js +10 -0
- package/dist/esm/hosting/nodeHost.js.map +1 -1
- package/dist/esm/hosting/standingAgent.js +362 -51
- package/dist/esm/hosting/standingAgent.js.map +1 -1
- package/dist/esm/hosting/turnArtifacts.d.ts +93 -0
- package/dist/esm/hosting/turnArtifacts.js +126 -0
- package/dist/esm/hosting/turnArtifacts.js.map +1 -0
- package/dist/esm/hosting/types.d.ts +196 -3
- package/dist/esm/hosting/types.js +10 -0
- package/dist/esm/hosting/types.js.map +1 -1
- package/dist/esm/hosting/webSocketConversation.d.ts +15 -1
- package/dist/esm/hosting/webSocketConversation.js +54 -2
- package/dist/esm/hosting/webSocketConversation.js.map +1 -1
- package/dist/esm/integrity/disposition/ledger.d.ts +8 -0
- package/dist/esm/integrity/disposition/ledger.js +0 -0
- package/dist/esm/integrity/disposition/ledger.js.map +1 -1
- package/dist/esm/lib/mcp/mcpServe.js +39 -2
- package/dist/esm/lib/mcp/mcpServe.js.map +1 -1
- package/dist/esm/lib/mcp/types.d.ts +30 -0
- package/dist/esm/recorders/observability/commentary/artifactPhrases.d.ts +4 -0
- package/dist/esm/recorders/observability/commentary/artifactPhrases.js +9 -0
- package/dist/esm/recorders/observability/commentary/artifactPhrases.js.map +1 -1
- package/dist/esm/recorders/observability/commentary/commentaryTemplates.js +30 -3
- package/dist/esm/recorders/observability/commentary/commentaryTemplates.js.map +1 -1
- package/dist/esm/recorders/observability/recordRun.d.ts +12 -0
- package/dist/esm/recorders/observability/recordRun.js +17 -1
- package/dist/esm/recorders/observability/recordRun.js.map +1 -1
- package/dist/esm/strategies/attach.js +87 -1
- package/dist/esm/strategies/attach.js.map +1 -1
- package/dist/events/registry.js +2 -0
- package/dist/events/registry.js.map +1 -1
- package/dist/hosting/artifactWire.js +21 -3
- package/dist/hosting/artifactWire.js.map +1 -1
- package/dist/hosting/doorGuard.js +509 -0
- package/dist/hosting/doorGuard.js.map +1 -0
- package/dist/hosting/errors.js +183 -1
- package/dist/hosting/errors.js.map +1 -1
- package/dist/hosting/httpHost.js +218 -4
- package/dist/hosting/httpHost.js.map +1 -1
- package/dist/hosting/index.js +19 -2
- package/dist/hosting/index.js.map +1 -1
- package/dist/hosting/ingressRecord.js +66 -6
- package/dist/hosting/ingressRecord.js.map +1 -1
- package/dist/hosting/nodeHost.js +11 -1
- package/dist/hosting/nodeHost.js.map +1 -1
- package/dist/hosting/standingAgent.js +359 -48
- package/dist/hosting/standingAgent.js.map +1 -1
- package/dist/hosting/turnArtifacts.js +130 -0
- package/dist/hosting/turnArtifacts.js.map +1 -0
- package/dist/hosting/types.js +11 -1
- package/dist/hosting/types.js.map +1 -1
- package/dist/hosting/webSocketConversation.js +54 -2
- package/dist/hosting/webSocketConversation.js.map +1 -1
- package/dist/integrity/disposition/ledger.js +0 -0
- package/dist/integrity/disposition/ledger.js.map +1 -1
- package/dist/lib/mcp/mcpServe.js +39 -2
- package/dist/lib/mcp/mcpServe.js.map +1 -1
- package/dist/recorders/observability/commentary/artifactPhrases.js +10 -1
- package/dist/recorders/observability/commentary/artifactPhrases.js.map +1 -1
- package/dist/recorders/observability/commentary/commentaryTemplates.js +29 -2
- package/dist/recorders/observability/commentary/commentaryTemplates.js.map +1 -1
- package/dist/recorders/observability/recordRun.js +20 -3
- package/dist/recorders/observability/recordRun.js.map +1 -1
- package/dist/strategies/attach.js +87 -1
- package/dist/strategies/attach.js.map +1 -1
- package/dist/types/adapters/hosting/agentCoreA2A.d.ts +14 -1
- package/dist/types/adapters/hosting/agentCoreA2A.d.ts.map +1 -1
- package/dist/types/adapters/hosting/agentcore.d.ts +18 -2
- package/dist/types/adapters/hosting/agentcore.d.ts.map +1 -1
- package/dist/types/adapters/hosting/foundryResponses.d.ts +15 -1
- package/dist/types/adapters/hosting/foundryResponses.d.ts.map +1 -1
- package/dist/types/adapters/observability/agentcore.d.ts +17 -5
- package/dist/types/adapters/observability/agentcore.d.ts.map +1 -1
- package/dist/types/adapters/observability/audit.d.ts +6 -2
- package/dist/types/adapters/observability/audit.d.ts.map +1 -1
- package/dist/types/adapters/observability/otel.d.ts +240 -11
- package/dist/types/adapters/observability/otel.d.ts.map +1 -1
- package/dist/types/artifacts/capability.d.ts +3 -1
- package/dist/types/artifacts/capability.d.ts.map +1 -1
- package/dist/types/bridge/eventMeta.d.ts +32 -0
- package/dist/types/bridge/eventMeta.d.ts.map +1 -1
- package/dist/types/core/Agent.d.ts +18 -5
- package/dist/types/core/Agent.d.ts.map +1 -1
- package/dist/types/core/RunnerBase.d.ts +20 -0
- package/dist/types/core/RunnerBase.d.ts.map +1 -1
- package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
- package/dist/types/core/agent/stages/toolCalls.d.ts +11 -0
- package/dist/types/core/agent/stages/toolCalls.d.ts.map +1 -1
- package/dist/types/core/flowchartAsTool.d.ts.map +1 -1
- package/dist/types/core/runbook/runbookAsTool.d.ts.map +1 -1
- package/dist/types/core/toolShownArgs.d.ts +63 -0
- package/dist/types/core/toolShownArgs.d.ts.map +1 -0
- package/dist/types/events/payloads.d.ts +122 -6
- package/dist/types/events/payloads.d.ts.map +1 -1
- package/dist/types/events/registry.d.ts +3 -1
- package/dist/types/events/registry.d.ts.map +1 -1
- package/dist/types/events/types.d.ts +7 -0
- package/dist/types/events/types.d.ts.map +1 -1
- package/dist/types/hosting/artifactWire.d.ts +10 -2
- package/dist/types/hosting/artifactWire.d.ts.map +1 -1
- package/dist/types/hosting/doorGuard.d.ts +281 -0
- package/dist/types/hosting/doorGuard.d.ts.map +1 -0
- package/dist/types/hosting/errors.d.ts +113 -0
- package/dist/types/hosting/errors.d.ts.map +1 -1
- package/dist/types/hosting/httpHost.d.ts +32 -3
- package/dist/types/hosting/httpHost.d.ts.map +1 -1
- package/dist/types/hosting/index.d.ts +7 -5
- package/dist/types/hosting/index.d.ts.map +1 -1
- package/dist/types/hosting/ingressRecord.d.ts +64 -10
- package/dist/types/hosting/ingressRecord.d.ts.map +1 -1
- package/dist/types/hosting/nodeHost.d.ts +32 -2
- package/dist/types/hosting/nodeHost.d.ts.map +1 -1
- package/dist/types/hosting/standingAgent.d.ts.map +1 -1
- package/dist/types/hosting/turnArtifacts.d.ts +94 -0
- package/dist/types/hosting/turnArtifacts.d.ts.map +1 -0
- package/dist/types/hosting/types.d.ts +196 -3
- package/dist/types/hosting/types.d.ts.map +1 -1
- package/dist/types/hosting/webSocketConversation.d.ts +15 -1
- package/dist/types/hosting/webSocketConversation.d.ts.map +1 -1
- package/dist/types/integrity/disposition/ledger.d.ts +8 -0
- package/dist/types/integrity/disposition/ledger.d.ts.map +1 -1
- package/dist/types/lib/mcp/mcpServe.d.ts.map +1 -1
- package/dist/types/lib/mcp/types.d.ts +30 -0
- package/dist/types/lib/mcp/types.d.ts.map +1 -1
- package/dist/types/recorders/observability/commentary/artifactPhrases.d.ts +4 -0
- package/dist/types/recorders/observability/commentary/artifactPhrases.d.ts.map +1 -1
- package/dist/types/recorders/observability/commentary/commentaryTemplates.d.ts.map +1 -1
- package/dist/types/recorders/observability/recordRun.d.ts +12 -0
- package/dist/types/recorders/observability/recordRun.d.ts.map +1 -1
- package/dist/types/strategies/attach.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -97,18 +97,22 @@
|
|
|
97
97
|
* Pattern: Composition root. It owns wiring and ordering; it invents no
|
|
98
98
|
* mechanism of its own.
|
|
99
99
|
*/
|
|
100
|
+
import { isDevMode } from 'footprintjs';
|
|
100
101
|
import { bindArtifacts } from '../artifacts/capability.js';
|
|
101
102
|
import { readAskComponent } from '../core/askComponent.js';
|
|
102
103
|
import { applyInputResponse, readAwaitingInput } from '../core/inputRequest.js';
|
|
103
104
|
import { isPaused, pauseDemandsDecision } from '../core/pause.js';
|
|
105
|
+
import { NOT_A_REF } from './artifactWire.js';
|
|
106
|
+
import { isArtifactRef } from '../artifacts/naming.js';
|
|
104
107
|
import { durableWriter } from './durability.js';
|
|
105
108
|
import { envelopeOwner, envelopeTranscript, readEnvelope, readPausedRun, toEnvelope, toPausedEnvelope, } from './envelope.js';
|
|
106
|
-
import { AdmissionRefusedError, ArtifactNotCarriedError, ArtifactNotFoundError, ArtifactSessionRequiredError, AwaitingDecisionError, ConcurrentRunError, NoArtifactStoreError, NoPendingAskError, PauseNotCarriedError, SessionIndexUnavailableError, SessionNotFoundError, SessionOpNeedsIdentityError, SessionsNotCarriedError, UnreadableEnvelopeError, } from './errors.js';
|
|
109
|
+
import { AdmissionRefusedError, ArtifactNotCarriedError, ArtifactNotFoundError, ArtifactSessionRequiredError, AwaitingDecisionError, ConcurrentRunError, InvalidWireOpError, NoArtifactStoreError, NoPendingAskError, PauseNotCarriedError, SessionIndexUnavailableError, SessionNotFoundError, SessionOpNeedsIdentityError, SessionsNotCarriedError, UnreadableEnvelopeError, } from './errors.js';
|
|
107
110
|
import { verifyRequestIdentity } from './identityVerification.js';
|
|
108
111
|
import { spendKeyFor, spendLedger } from './admission.js';
|
|
109
|
-
import { beginIngress } from './ingressRecord.js';
|
|
112
|
+
import { beginIngress, recordHostRefusal } from './ingressRecord.js';
|
|
113
|
+
import { openTurnArtifacts } from './turnArtifacts.js';
|
|
110
114
|
import { SESSION_LIST_OP, SESSION_TRANSCRIPT_OP } from './sessionWire.js';
|
|
111
|
-
import { DEFAULT_MAX_ACTIVE_SESSIONS } from './types.js';
|
|
115
|
+
import { DEFAULT_MAX_ACTIVE_SESSIONS, TURN_ARTIFACTS_TIMEOUT_MS } from './types.js';
|
|
112
116
|
/**
|
|
113
117
|
* The pool key the anonymous fallback instance is held under, and the session
|
|
114
118
|
* key it can never collide with: a real session id from a transport is a
|
|
@@ -218,6 +222,16 @@ export async function standingAgent(options) {
|
|
|
218
222
|
`uses the one instance you passed. Drop it, or switch to 'agentFactory' to get ` +
|
|
219
223
|
`the per-session pool it describes.`);
|
|
220
224
|
}
|
|
225
|
+
// A bound on the artifact hand-over that could never fire is not a bound —
|
|
226
|
+
// and a hand-over that may hold a lane forever is the outage it exists to
|
|
227
|
+
// prevent. Refused here, before a socket exists.
|
|
228
|
+
const turnArtifactsTimeoutMs = options.turnArtifactsTimeoutMs ?? TURN_ARTIFACTS_TIMEOUT_MS;
|
|
229
|
+
if (!Number.isFinite(turnArtifactsTimeoutMs) || turnArtifactsTimeoutMs <= 0) {
|
|
230
|
+
throw new Error(`[hosting] standingAgent was given turnArtifactsTimeoutMs: ${String(options.turnArtifactsTimeoutMs)}. It is how long a turn's artifact hand-over (reply.turnArtifacts) may hold the ` +
|
|
231
|
+
`reply, so it has to be a positive, finite number of milliseconds — a bound that ` +
|
|
232
|
+
`can never fire would let one host's hung store hold every other session. Drop it ` +
|
|
233
|
+
`for the default (${TURN_ARTIFACTS_TIMEOUT_MS} ms).`);
|
|
234
|
+
}
|
|
221
235
|
const maxActiveSessions = options.maxActiveSessions ?? DEFAULT_MAX_ACTIVE_SESSIONS;
|
|
222
236
|
if (factory !== undefined && (!Number.isInteger(maxActiveSessions) || maxActiveSessions < 1)) {
|
|
223
237
|
throw new Error(`[hosting] standingAgent was given maxActiveSessions: ${String(options.maxActiveSessions)}. ` +
|
|
@@ -524,7 +538,7 @@ export async function standingAgent(options) {
|
|
|
524
538
|
// "concurrent run", and must not make the turn wait either.
|
|
525
539
|
if (identified.artifact !== undefined) {
|
|
526
540
|
try {
|
|
527
|
-
await answerArtifact(identified.artifact, identified, reply);
|
|
541
|
+
await answerArtifact(identified.artifact, identified, verified, reply);
|
|
528
542
|
}
|
|
529
543
|
catch (err) {
|
|
530
544
|
reply.fail(err instanceof Error ? err : new Error(String(err)));
|
|
@@ -575,7 +589,7 @@ export async function standingAgent(options) {
|
|
|
575
589
|
ledger.admit(spendKey);
|
|
576
590
|
}
|
|
577
591
|
const lane = laneFor(sessionId);
|
|
578
|
-
await serialize(lane, sessionKey, () => answerOne(lane, sessions, identified, reply, sessionId, verified, spendKey), queueAnyway);
|
|
592
|
+
await serialize(lane, sessionKey, () => answerOne(lane, sessions, identified, reply, sessionId, verified, spendKey, note), queueAnyway);
|
|
579
593
|
}
|
|
580
594
|
catch (err) {
|
|
581
595
|
reply.fail(err instanceof Error ? err : new Error(String(err)));
|
|
@@ -697,13 +711,17 @@ export async function standingAgent(options) {
|
|
|
697
711
|
*
|
|
698
712
|
* ── The scope is the run's own, re-composed — one isolation rule ────────
|
|
699
713
|
* A ref is redeemed under EXACTLY the scope the run's tools minted it in:
|
|
700
|
-
* `
|
|
701
|
-
*
|
|
702
|
-
*
|
|
703
|
-
*
|
|
704
|
-
*
|
|
705
|
-
*
|
|
706
|
-
*
|
|
714
|
+
* `sessionArtifactScope(userId, sessionId, storedIdentity)` — the same
|
|
715
|
+
* function a turn's hand-over (`reply.turnArtifacts`) is bound with, so a
|
|
716
|
+
* host's filing and this redemption compose one tuple from the same inputs
|
|
717
|
+
* for the same caller. It is `identityForRequest` when the request names a
|
|
718
|
+
* user — the same call, on the same inputs, that composed the run's
|
|
719
|
+
* identity — else the session rung
|
|
720
|
+
* `{ conversationId: sessionId }` (what seed derives for an identity-less
|
|
721
|
+
* served run). No new spelling exists to drift. The stored identity is read
|
|
722
|
+
* only when a `userId` arrived (it is the only rung that needs the stored
|
|
723
|
+
* tenant/conversation tuple), through the same wake → hydrate →
|
|
724
|
+
* refuse-unreadable steps a turn takes.
|
|
707
725
|
*
|
|
708
726
|
* A ref from another session — or a right session presented with the wrong
|
|
709
727
|
* identity — composes a different tuple, and the store answers a wrong
|
|
@@ -719,10 +737,29 @@ export async function standingAgent(options) {
|
|
|
719
737
|
* hosting door, and a phantom tool name would be an actor that does not
|
|
720
738
|
* exist.
|
|
721
739
|
*
|
|
740
|
+
* ── Nothing a stranger chose reaches the record ──────────────────────────
|
|
741
|
+
* Every fact this door emits is stamped with the session the request NAMED
|
|
742
|
+
* (`emitArtifactFact`), and that stamp decides which run's recording keeps
|
|
743
|
+
* it (`eventBelongsToRun`). So the door checks, before it emits anything or
|
|
744
|
+
* builds a lane:
|
|
745
|
+
*
|
|
746
|
+
* 1. **The ref's shape** (`isArtifactRef`) — free text posing as a ref would
|
|
747
|
+
* be text written into a live recording (the wire readers refuse it too;
|
|
748
|
+
* this covers a host that builds `HostRequest.artifact` itself).
|
|
749
|
+
* 2. **At a verifying door, ownership** — the turn door's own rule
|
|
750
|
+
* (`mayOpenSession`) for a stored conversation; for one whose FIRST turn
|
|
751
|
+
* is still in flight (nothing stored yet), only the caller that turn is
|
|
752
|
+
* serving. Anyone else gets the ONE not-found, and nothing is emitted —
|
|
753
|
+
* a stranger can neither write into another person's recording nor flood
|
|
754
|
+
* it until its own events are evicted.
|
|
755
|
+
*
|
|
756
|
+
* At a door with no verifier the session id IS the key, by law: whoever
|
|
757
|
+
* presents it may redeem under it, and its facts are that session's.
|
|
758
|
+
*
|
|
722
759
|
* Zero-cost when unused: an agent without a store answers with the teaching
|
|
723
760
|
* refusal naming the attach, and nothing else in the composer changes.
|
|
724
761
|
*/
|
|
725
|
-
async function answerArtifact(op, request, reply) {
|
|
762
|
+
async function answerArtifact(op, request, verified, reply) {
|
|
726
763
|
const sessionId = request.sessionId;
|
|
727
764
|
if (sessionId === undefined) {
|
|
728
765
|
// An anonymous run scopes its artifacts to its own runId — a name no
|
|
@@ -732,6 +769,18 @@ export async function standingAgent(options) {
|
|
|
732
769
|
reply.fail(new ArtifactSessionRequiredError(op.op));
|
|
733
770
|
return;
|
|
734
771
|
}
|
|
772
|
+
if (!isArtifactRef(op.ref)) {
|
|
773
|
+
reply.fail(new InvalidWireOpError(`'artifact-${op.op}' ${NOT_A_REF}`));
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
// Read the stored conversation once: its OWNER (a verifying door) and its
|
|
777
|
+
// identity tuple (any request naming a user) both come from it.
|
|
778
|
+
const needsStored = identityOptions !== undefined || request.userId !== undefined;
|
|
779
|
+
const envelope = needsStored ? await storedFor(sessionId) : undefined;
|
|
780
|
+
if (identityOptions !== undefined && !mayRedeemFrom(sessionId, envelope, verified)) {
|
|
781
|
+
reply.fail(new ArtifactNotFoundError(op.ref));
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
735
784
|
const lane = laneFor(sessionId);
|
|
736
785
|
// Admitted for the duration: a lane with work is never evicted, and a
|
|
737
786
|
// resolution mid-flight is work — retiring the instance under it would
|
|
@@ -743,26 +792,17 @@ export async function standingAgent(options) {
|
|
|
743
792
|
// The fail-closed law at the wire: the refusal lands on the record
|
|
744
793
|
// (`no-store`, the same reason `ctx.artifacts` teaches with) and the
|
|
745
794
|
// reply names the attach.
|
|
746
|
-
emitArtifactFact(lane.agent, {
|
|
747
|
-
type: 'refused',
|
|
748
|
-
op: op.op,
|
|
749
|
-
reason: 'no-store',
|
|
750
|
-
ref: op.ref,
|
|
751
|
-
});
|
|
795
|
+
emitArtifactFact(lane.agent, { type: 'refused', op: op.op, reason: 'no-store', ref: op.ref }, { sessionId });
|
|
752
796
|
reply.fail(new NoArtifactStoreError(op.op));
|
|
753
797
|
return;
|
|
754
798
|
}
|
|
755
799
|
let stored;
|
|
756
|
-
if (request.userId !== undefined) {
|
|
757
|
-
await sessions.onWake?.(sessionId, 'artifact');
|
|
800
|
+
if (request.userId !== undefined && envelope !== undefined) {
|
|
758
801
|
try {
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
envelope.
|
|
763
|
-
? readPausedRun(envelope).conversation.identity
|
|
764
|
-
: readEnvelope(envelope).identity;
|
|
765
|
-
}
|
|
802
|
+
stored =
|
|
803
|
+
envelope.format === 'flowchart-v1'
|
|
804
|
+
? readPausedRun(envelope).conversation.identity
|
|
805
|
+
: readEnvelope(envelope).identity;
|
|
766
806
|
}
|
|
767
807
|
catch (err) {
|
|
768
808
|
// The same law as a turn: an unreadable stored conversation is a
|
|
@@ -771,11 +811,9 @@ export async function standingAgent(options) {
|
|
|
771
811
|
throw err instanceof UnreadableEnvelopeError ? err.withSession(sessionId) : err;
|
|
772
812
|
}
|
|
773
813
|
}
|
|
774
|
-
const scope =
|
|
775
|
-
conversationId: sessionId,
|
|
776
|
-
};
|
|
814
|
+
const scope = sessionArtifactScope(request.userId, sessionId, stored);
|
|
777
815
|
const bound = bindArtifacts(store, scope, {
|
|
778
|
-
onEvent: (fact) => emitArtifactFact(lane.agent, fact),
|
|
816
|
+
onEvent: (fact) => emitArtifactFact(lane.agent, fact, { sessionId }),
|
|
779
817
|
});
|
|
780
818
|
if (op.op === 'head') {
|
|
781
819
|
const meta = await bound.head(op.ref);
|
|
@@ -802,6 +840,34 @@ export async function standingAgent(options) {
|
|
|
802
840
|
lane.lastUsedMs = Date.now();
|
|
803
841
|
}
|
|
804
842
|
}
|
|
843
|
+
/** The stored conversation for a redemption — woken and hydrated the way a
|
|
844
|
+
* turn does it, the unreadable-envelope law included. */
|
|
845
|
+
async function storedFor(sessionId) {
|
|
846
|
+
await sessions.onWake?.(sessionId, 'artifact');
|
|
847
|
+
try {
|
|
848
|
+
return await sessions.hydrate(sessionId);
|
|
849
|
+
}
|
|
850
|
+
catch (err) {
|
|
851
|
+
throw err instanceof UnreadableEnvelopeError ? err.withSession(sessionId) : err;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* May this caller redeem under `sessionId` at a VERIFYING door?
|
|
856
|
+
*
|
|
857
|
+
* A stored conversation answers with the turn door's own rule
|
|
858
|
+
* (`mayOpenSession`) — asked leniently, before any strict reader, for the
|
|
859
|
+
* same reason the turn door asks it first. With nothing stored yet the only
|
|
860
|
+
* conversation that can hold artifacts is one whose FIRST turn is in flight
|
|
861
|
+
* right now (a chart presented mid-turn), and then only the caller that turn
|
|
862
|
+
* is serving may redeem. Read from the lane WITHOUT building one: a refused
|
|
863
|
+
* caller never makes the pool grow or evict.
|
|
864
|
+
*/
|
|
865
|
+
function mayRedeemFrom(sessionId, envelope, verified) {
|
|
866
|
+
if (envelope !== undefined)
|
|
867
|
+
return mayOpenSession(envelope, verified);
|
|
868
|
+
const serving = shared ?? pool.get(sessionId);
|
|
869
|
+
return serving?.activeSessionId === sessionId && serving.activeOwner === verified?.userId;
|
|
870
|
+
}
|
|
805
871
|
/**
|
|
806
872
|
* Whose conversation is this — and may THIS caller open it? (9.26.0)
|
|
807
873
|
*
|
|
@@ -862,12 +928,13 @@ export async function standingAgent(options) {
|
|
|
862
928
|
return true;
|
|
863
929
|
return envelopeOwner(stored) === verified?.userId;
|
|
864
930
|
}
|
|
865
|
-
async function answerOne(lane, store, request, reply, sessionId, verified, spendKey) {
|
|
931
|
+
async function answerOne(lane, store, request, reply, sessionId, verified, spendKey, note) {
|
|
866
932
|
const runner = lane.agent;
|
|
867
933
|
lane.activeReply = reply;
|
|
868
934
|
// The writer only ever writes for the run it is inside; an anonymous
|
|
869
935
|
// request has nowhere to write to and gets nothing.
|
|
870
936
|
lane.activeSessionId = sessionId;
|
|
937
|
+
lane.activeOwner = verified?.userId;
|
|
871
938
|
// Whose usage this lane's next token and cost events belong to. Set only
|
|
872
939
|
// with an admission policy; the subscriptions that read it do not exist
|
|
873
940
|
// otherwise.
|
|
@@ -940,6 +1007,24 @@ export async function standingAgent(options) {
|
|
|
940
1007
|
// produces `undefined` here and every earlier release's behaviour is
|
|
941
1008
|
// unchanged.
|
|
942
1009
|
const identity = identityForRequest(request.userId, sessionId, prior?.identity ?? paused?.conversation.identity);
|
|
1010
|
+
// What this turn offers a host that files its own artifacts
|
|
1011
|
+
// (`reply.turnArtifacts`): WHERE its claim tickets are redeemed — the one
|
|
1012
|
+
// composition the artifact door re-composes for the same caller, built
|
|
1013
|
+
// only if a host asks — and where a hook failure is recorded. No session,
|
|
1014
|
+
// no scope: nothing a later request presents could ever redeem an
|
|
1015
|
+
// anonymous run's artifacts, so there is nothing to bind.
|
|
1016
|
+
const stored = prior?.identity ?? paused?.conversation.identity;
|
|
1017
|
+
const offer = {
|
|
1018
|
+
...(sessionId !== undefined && {
|
|
1019
|
+
session: {
|
|
1020
|
+
id: sessionId,
|
|
1021
|
+
scope: () => sessionArtifactScope(request.userId, sessionId, stored),
|
|
1022
|
+
},
|
|
1023
|
+
}),
|
|
1024
|
+
timeoutMs: turnArtifactsTimeoutMs,
|
|
1025
|
+
...(request.signal !== undefined && { signal: request.signal }),
|
|
1026
|
+
note,
|
|
1027
|
+
};
|
|
943
1028
|
const runOptions = request.signal !== undefined || sessionId !== undefined || identity !== undefined
|
|
944
1029
|
? {
|
|
945
1030
|
...(request.signal !== undefined && { env: { signal: request.signal } }),
|
|
@@ -995,11 +1080,14 @@ export async function standingAgent(options) {
|
|
|
995
1080
|
runner.abandonPause();
|
|
996
1081
|
if (sessionId !== undefined)
|
|
997
1082
|
await runner.closeToolSessions({ scope: 'run', sessionId });
|
|
1083
|
+
// A turn that ends, so the host is offered its binding like any
|
|
1084
|
+
// other — but no run happened, so there is no run id to stamp.
|
|
1085
|
+
await offerTurnArtifacts(runner, reply, offer, () => undefined);
|
|
998
1086
|
reply.complete(output);
|
|
999
1087
|
return;
|
|
1000
1088
|
}
|
|
1001
1089
|
}
|
|
1002
|
-
await deliver(lane, await runner.resume(paused.checkpoint, request.decision, runOptions), store, reply, sessionId, paused);
|
|
1090
|
+
await deliver(lane, await runner.resume(paused.checkpoint, request.decision, runOptions), store, reply, sessionId, offer, paused);
|
|
1003
1091
|
return;
|
|
1004
1092
|
}
|
|
1005
1093
|
if (paused && sessionId !== undefined) {
|
|
@@ -1011,7 +1099,7 @@ export async function standingAgent(options) {
|
|
|
1011
1099
|
const output = prior
|
|
1012
1100
|
? await runner.run({ message: request.input, continueFrom: prior }, runOptions)
|
|
1013
1101
|
: await runner.run({ message: request.input }, runOptions);
|
|
1014
|
-
await deliver(lane, output, store, reply, sessionId);
|
|
1102
|
+
await deliver(lane, output, store, reply, sessionId, offer);
|
|
1015
1103
|
}
|
|
1016
1104
|
catch (err) {
|
|
1017
1105
|
// A run that threw still has to drain. A write left in flight would race
|
|
@@ -1025,11 +1113,12 @@ export async function standingAgent(options) {
|
|
|
1025
1113
|
finally {
|
|
1026
1114
|
lane.activeReply = undefined;
|
|
1027
1115
|
lane.activeSessionId = undefined;
|
|
1116
|
+
lane.activeOwner = undefined;
|
|
1028
1117
|
lane.activeSpendKey = undefined;
|
|
1029
1118
|
}
|
|
1030
1119
|
}
|
|
1031
1120
|
/** Store what the run left behind, then end the reply with the right terminal. */
|
|
1032
|
-
async function deliver(lane, output, store, reply, sessionId, priorPause) {
|
|
1121
|
+
async function deliver(lane, output, store, reply, sessionId, offer, priorPause) {
|
|
1033
1122
|
const runner = lane.agent;
|
|
1034
1123
|
// Mid-run writes settle FIRST. Ordering, not tidiness: an 'async' write
|
|
1035
1124
|
// still in flight would otherwise land after the terminal envelope and
|
|
@@ -1050,6 +1139,13 @@ export async function standingAgent(options) {
|
|
|
1050
1139
|
if (sessionId !== undefined && conversation) {
|
|
1051
1140
|
await store.persist(sessionId, toPausedEnvelope({ checkpoint: output.checkpoint, conversation, pending }));
|
|
1052
1141
|
if (reply.awaiting) {
|
|
1142
|
+
// The run id for `origin` comes from the conversation just
|
|
1143
|
+
// snapshotted. When that is the PRIOR pause's — re-used because
|
|
1144
|
+
// the same question is still open, which is what a partial answer
|
|
1145
|
+
// does WITHOUT running anything — no origin is stamped: this
|
|
1146
|
+
// request ran nothing, and the instance's last run may be another
|
|
1147
|
+
// session's. Absent is never wrong; a borrowed run id would be.
|
|
1148
|
+
await offerTurnArtifacts(runner, reply, offer, () => conversation === priorPause?.conversation ? undefined : conversation?.runId);
|
|
1053
1149
|
reply.awaiting(pending);
|
|
1054
1150
|
return;
|
|
1055
1151
|
}
|
|
@@ -1084,17 +1180,37 @@ export async function standingAgent(options) {
|
|
|
1084
1180
|
runner.abandonPause();
|
|
1085
1181
|
}
|
|
1086
1182
|
}
|
|
1183
|
+
let conversation;
|
|
1087
1184
|
if (sessionId !== undefined) {
|
|
1088
|
-
|
|
1185
|
+
conversation = runner.checkpoint();
|
|
1089
1186
|
// Persist BEFORE answering: the caller learns the answer only once the
|
|
1090
1187
|
// conversation that produced it is durable, so a queued next turn can
|
|
1091
1188
|
// never read state older than the answer already given.
|
|
1092
1189
|
if (conversation)
|
|
1093
1190
|
await store.persist(sessionId, toEnvelope(conversation));
|
|
1094
1191
|
}
|
|
1192
|
+
// The snapshot just persisted names the run that answered — the same id
|
|
1193
|
+
// the run's own recording carries on its `origin` — so stamping a host's
|
|
1194
|
+
// filing costs no second snapshot.
|
|
1195
|
+
await offerTurnArtifacts(runner, reply, offer, () => conversation?.runId);
|
|
1095
1196
|
reply.complete(typeof output === 'string' ? output : String(output));
|
|
1096
1197
|
}
|
|
1097
|
-
|
|
1198
|
+
// The HOST's own refusals — a forged request its door guard turned away, a
|
|
1199
|
+
// session id over the bound — never reach `handler`, so they would never
|
|
1200
|
+
// reach the record either. Subscribed only when a sink is set (the zero-delta
|
|
1201
|
+
// path stays zero), and only on a host that reports them (feature-detected).
|
|
1202
|
+
// Before `serve`, so a refusal in the first instant of serving is not lost.
|
|
1203
|
+
const stopHostRefusals = ingressSink !== undefined && typeof host.onRefusal === 'function'
|
|
1204
|
+
? host.onRefusal((refusal) => recordHostRefusal(refusal, ingressSink))
|
|
1205
|
+
: undefined;
|
|
1206
|
+
let handle;
|
|
1207
|
+
try {
|
|
1208
|
+
handle = await host.serve(handler);
|
|
1209
|
+
}
|
|
1210
|
+
catch (err) {
|
|
1211
|
+
stopHostRefusals?.();
|
|
1212
|
+
throw err;
|
|
1213
|
+
}
|
|
1098
1214
|
// ── Shutdown ────────────────────────────────────────────────────────
|
|
1099
1215
|
//
|
|
1100
1216
|
// Telemetry drains on close, because a batching exporter that loses its
|
|
@@ -1121,6 +1237,7 @@ export async function standingAgent(options) {
|
|
|
1121
1237
|
function closeOnce() {
|
|
1122
1238
|
closing ??= (async () => {
|
|
1123
1239
|
await handle.close();
|
|
1240
|
+
stopHostRefusals?.();
|
|
1124
1241
|
if (shared !== undefined) {
|
|
1125
1242
|
shared.detach();
|
|
1126
1243
|
if (shutdownMode !== 'none') {
|
|
@@ -1216,6 +1333,165 @@ function identityForRequest(userId, sessionId, stored) {
|
|
|
1216
1333
|
principal: userId,
|
|
1217
1334
|
};
|
|
1218
1335
|
}
|
|
1336
|
+
/**
|
|
1337
|
+
* The scope a SESSION's claim tickets live in, for the request being served —
|
|
1338
|
+
* the ONE composition of that tuple, shared by the two doors that need it.
|
|
1339
|
+
*
|
|
1340
|
+
* `answerArtifact` redeems under it, and a turn hands its host a store bound
|
|
1341
|
+
* to it (`reply.turnArtifacts`). One function rather than two call sites that
|
|
1342
|
+
* agree today: the field bug this exists for was a host that composed its own
|
|
1343
|
+
* tuple, got the session rung right and the signed-in rung wrong, and filed
|
|
1344
|
+
* every ticket where redemption would never look. Deliberately NOT exported —
|
|
1345
|
+
* a function a host can call with a user id is a function a host can call
|
|
1346
|
+
* with SOMEBODY ELSE's user id.
|
|
1347
|
+
*
|
|
1348
|
+
* `identityForRequest` when the request names a user, else the session rung
|
|
1349
|
+
* `{ conversationId: sessionId }` — what seed derives for an identity-less
|
|
1350
|
+
* served run.
|
|
1351
|
+
*/
|
|
1352
|
+
function sessionArtifactScope(userId, sessionId, stored) {
|
|
1353
|
+
return identityForRequest(userId, sessionId, stored) ?? { conversationId: sessionId };
|
|
1354
|
+
}
|
|
1355
|
+
/**
|
|
1356
|
+
* Hand this turn's binding to a host that asked for it — AWAITED while the
|
|
1357
|
+
* session's lane is still held, BOUNDED, immediately before the turn's
|
|
1358
|
+
* terminal.
|
|
1359
|
+
*
|
|
1360
|
+
* Four guarantees, each one a finding an earlier cut of this seam failed:
|
|
1361
|
+
*
|
|
1362
|
+
* - **Inside the turn.** The composer awaits the hook here, so a host files
|
|
1363
|
+
* while no other run can be in flight on this instance.
|
|
1364
|
+
* - **Bounded.** The hook and every operation it started race ONE deadline
|
|
1365
|
+
* (`turnArtifactsTimeoutMs`) and the request's signal. Whichever ends the
|
|
1366
|
+
* wait, the binding is revoked, nothing in flight is cancelled (it may
|
|
1367
|
+
* still land — its facts name their own session and run, so they cannot
|
|
1368
|
+
* enter anyone else's record), the cause is reported and the terminal is
|
|
1369
|
+
* delivered — so one host's hung store or hook can hold neither every other
|
|
1370
|
+
* session (the shared shape), nor a pooled lane, nor `close()`.
|
|
1371
|
+
* - **Never the terminal's decision, never silent.** A hook that throws, an
|
|
1372
|
+
* operation that fails, the bound, the abort and a call after the turn are
|
|
1373
|
+
* reported (`turnArtifactsFailed`) and the terminal is delivered anyway.
|
|
1374
|
+
* - **Revoked when the turn ends.** A verb called later is refused by name
|
|
1375
|
+
* (`TurnArtifactsExpiredError`), already handled, and reported.
|
|
1376
|
+
*
|
|
1377
|
+
* A host without the hook gets nothing built: no binding, no scope, no store
|
|
1378
|
+
* lookup, no run-id read, no timer.
|
|
1379
|
+
*/
|
|
1380
|
+
async function offerTurnArtifacts(agent, reply, offer, runIdOf) {
|
|
1381
|
+
if (reply.turnArtifacts === undefined)
|
|
1382
|
+
return;
|
|
1383
|
+
const session = offer.session;
|
|
1384
|
+
// WHOSE facts these are, captured NOW — the binding owns "whose run", never
|
|
1385
|
+
// the agent's mutable current-run state when a late fact lands.
|
|
1386
|
+
const runId = session !== undefined ? runIdOf() : undefined;
|
|
1387
|
+
const attribution = session === undefined
|
|
1388
|
+
? undefined
|
|
1389
|
+
: { sessionId: session.id, ...(runId !== undefined && { runId }) };
|
|
1390
|
+
const failed = (failure) => turnArtifactsFailed(agent, attribution, offer.note, failure);
|
|
1391
|
+
const opened = openTurnArtifacts({
|
|
1392
|
+
store: agent.getArtifactStore(),
|
|
1393
|
+
scope: session?.scope(),
|
|
1394
|
+
runId,
|
|
1395
|
+
onEvent: (fact) => {
|
|
1396
|
+
// Only a bound hand-over reports facts, and only a session binds.
|
|
1397
|
+
if (attribution !== undefined)
|
|
1398
|
+
emitArtifactFact(agent, fact, attribution);
|
|
1399
|
+
},
|
|
1400
|
+
onFailure: (failure) => failed({
|
|
1401
|
+
cause: failure.cause,
|
|
1402
|
+
op: failure.op,
|
|
1403
|
+
...(failure.cause === 'operation' && errorClassOf(failure.error)),
|
|
1404
|
+
}),
|
|
1405
|
+
});
|
|
1406
|
+
const handOver = (async () => {
|
|
1407
|
+
try {
|
|
1408
|
+
await reply.turnArtifacts?.(opened.turn);
|
|
1409
|
+
}
|
|
1410
|
+
catch (err) {
|
|
1411
|
+
// A hook that merely re-threw an operation's failure was already counted.
|
|
1412
|
+
if (!opened.reported(err))
|
|
1413
|
+
failed({ cause: 'hook', ...errorClassOf(err) });
|
|
1414
|
+
}
|
|
1415
|
+
await opened.drain();
|
|
1416
|
+
})();
|
|
1417
|
+
try {
|
|
1418
|
+
const ended = await withinBound(handOver, offer.timeoutMs, offer.signal);
|
|
1419
|
+
if (ended !== 'settled')
|
|
1420
|
+
failed({ cause: ended });
|
|
1421
|
+
}
|
|
1422
|
+
finally {
|
|
1423
|
+
opened.revoke();
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
/**
|
|
1427
|
+
* Wait for `work`, but no longer than `timeoutMs` and no longer than `signal`
|
|
1428
|
+
* allows. `work` is NOT cancelled when the wait ends — there is nothing to
|
|
1429
|
+
* cancel a store's in-flight write with, and pretending otherwise would be
|
|
1430
|
+
* worse than saying we stopped waiting (the `toolSessions.ts · withTimeout`
|
|
1431
|
+
* law). The timer is unref'd, so a pending hand-over can never be the reason a
|
|
1432
|
+
* process stays up.
|
|
1433
|
+
*/
|
|
1434
|
+
async function withinBound(work, timeoutMs, signal) {
|
|
1435
|
+
if (signal?.aborted === true)
|
|
1436
|
+
return 'abort';
|
|
1437
|
+
let timer;
|
|
1438
|
+
let onAbort;
|
|
1439
|
+
try {
|
|
1440
|
+
return await Promise.race([
|
|
1441
|
+
work.then(() => 'settled'),
|
|
1442
|
+
new Promise((resolve) => {
|
|
1443
|
+
timer = setTimeout(() => resolve('timeout'), timeoutMs);
|
|
1444
|
+
timer.unref?.();
|
|
1445
|
+
}),
|
|
1446
|
+
new Promise((resolve) => {
|
|
1447
|
+
if (signal === undefined)
|
|
1448
|
+
return;
|
|
1449
|
+
onAbort = () => resolve('abort');
|
|
1450
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
1451
|
+
}),
|
|
1452
|
+
]);
|
|
1453
|
+
}
|
|
1454
|
+
finally {
|
|
1455
|
+
if (timer !== undefined)
|
|
1456
|
+
clearTimeout(timer);
|
|
1457
|
+
if (onAbort !== undefined)
|
|
1458
|
+
signal?.removeEventListener('abort', onAbort);
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
/** The routable half of a failure — class and code, never the message. */
|
|
1462
|
+
function errorClassOf(err) {
|
|
1463
|
+
const code = err?.code;
|
|
1464
|
+
return {
|
|
1465
|
+
...(err instanceof Error && { errorClass: err.constructor?.name ?? err.name }),
|
|
1466
|
+
...(typeof code === 'string' && { errorCode: code }),
|
|
1467
|
+
};
|
|
1468
|
+
}
|
|
1469
|
+
/**
|
|
1470
|
+
* Record one failure of a turn's artifact hand-over — on the serving agent's
|
|
1471
|
+
* stream as `agentfootprint.artifacts.hand_over_failed`, stamped with the
|
|
1472
|
+
* session and run it was FOR; the first one on the ingress record's census
|
|
1473
|
+
* (`IngressRecord.turnArtifactsFailure`); and on the console in dev mode. The
|
|
1474
|
+
* swallow is the library's decision, so the visibility is its duty: the
|
|
1475
|
+
* default deployment keeps no ingress sink, and a missing story must not be
|
|
1476
|
+
* silent there (the `toolSessions.ts` law 5, "never throws into the run — but
|
|
1477
|
+
* never silent either"). It never reaches the reply.
|
|
1478
|
+
*/
|
|
1479
|
+
function turnArtifactsFailed(agent, attribution, note, failure) {
|
|
1480
|
+
const payload = {
|
|
1481
|
+
cause: failure.cause,
|
|
1482
|
+
...(failure.op !== undefined && { op: failure.op }),
|
|
1483
|
+
...(failure.errorClass !== undefined && { errorClass: failure.errorClass }),
|
|
1484
|
+
...(failure.errorCode !== undefined && { errorCode: failure.errorCode }),
|
|
1485
|
+
};
|
|
1486
|
+
note?.turnArtifactsFailed(payload);
|
|
1487
|
+
if (attribution !== undefined) {
|
|
1488
|
+
agent.emitAttributed('agentfootprint.artifacts.hand_over_failed', { ...payload }, attribution);
|
|
1489
|
+
}
|
|
1490
|
+
if (isDevMode()) {
|
|
1491
|
+
// eslint-disable-next-line no-console
|
|
1492
|
+
console.error('[hosting] reply.turnArtifacts hand-over failed; the reply was delivered anyway:', payload);
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1219
1495
|
/**
|
|
1220
1496
|
* End the reply with a resolved artifact — through the terminal built for it
|
|
1221
1497
|
* when the host has one, and through the named refusal when it does not.
|
|
@@ -1248,34 +1524,69 @@ function deliverSessions(reply, op, result) {
|
|
|
1248
1524
|
reply.fail(new SessionsNotCarriedError(op));
|
|
1249
1525
|
}
|
|
1250
1526
|
/**
|
|
1251
|
-
* Put one capability fact on the serving agent's typed record — the
|
|
1252
|
-
* door's adapter onto the SAME `artifacts
|
|
1253
|
-
*
|
|
1254
|
-
*
|
|
1527
|
+
* Put one capability fact on the serving agent's typed record — the hosting
|
|
1528
|
+
* door's adapter onto the SAME `artifacts.*` events every tool's use of
|
|
1529
|
+
* `ctx.artifacts` rides, minus the `tool` field (the actor was the hosting
|
|
1530
|
+
* door or the host's own code, and payloads never carry an actor that does not
|
|
1255
1531
|
* exist).
|
|
1256
1532
|
*
|
|
1257
|
-
*
|
|
1258
|
-
*
|
|
1259
|
-
*
|
|
1260
|
-
*
|
|
1533
|
+
* Two bindings feed it. The wire's redemption (`artifact-head` /
|
|
1534
|
+
* `artifact-get`) is read-only and only ever produces `resolved` / `refused`
|
|
1535
|
+
* — the wire deliberately has no put. The turn's hand-over
|
|
1536
|
+
* (`reply.turnArtifacts`) is the host's own code filing for its turn, so its
|
|
1537
|
+
* `put` produces `minted` and, when retention made room, `expired` —
|
|
1538
|
+
* tool-less, like the run's own recording mint, and carrying every meta field
|
|
1539
|
+
* a tool's mint carries.
|
|
1540
|
+
*
|
|
1541
|
+
* Every fact is stamped with the SESSION it was produced for
|
|
1542
|
+
* (`RunnerBase.emitAttributed`). The door answers outside any run and — for a
|
|
1543
|
+
* redemption — outside the lane, so on an instance shared by several sessions
|
|
1544
|
+
* a fact can be delivered while ANOTHER session's run is in flight; the stamp
|
|
1545
|
+
* is what keeps it out of that run's recording and self-explain evidence
|
|
1546
|
+
* (`bridge/eventMeta.ts · eventBelongsToRun`). Delivery to listeners is
|
|
1547
|
+
* unchanged. Dropped when nobody listens (the dispatcher's own fast path), so
|
|
1548
|
+
* an unobserved agent pays one listener check per fact and nothing more.
|
|
1261
1549
|
*/
|
|
1262
|
-
function emitArtifactFact(agent, fact) {
|
|
1550
|
+
function emitArtifactFact(agent, fact, attribution) {
|
|
1263
1551
|
switch (fact.type) {
|
|
1552
|
+
case 'minted': {
|
|
1553
|
+
const meta = fact.meta;
|
|
1554
|
+
agent.emitAttributed('agentfootprint.artifacts.minted', {
|
|
1555
|
+
ref: meta.ref,
|
|
1556
|
+
kind: meta.kind,
|
|
1557
|
+
mediaType: meta.mediaType,
|
|
1558
|
+
bytes: meta.bytes,
|
|
1559
|
+
...(meta.label !== undefined && { label: meta.label }),
|
|
1560
|
+
...(meta.digest !== undefined && { digest: meta.digest }),
|
|
1561
|
+
...(meta.expiresAt !== undefined && { expiresAt: meta.expiresAt }),
|
|
1562
|
+
...(meta.origin !== undefined && { origin: meta.origin }),
|
|
1563
|
+
...(meta.parentRefs !== undefined && { parentRefs: meta.parentRefs }),
|
|
1564
|
+
}, attribution);
|
|
1565
|
+
return;
|
|
1566
|
+
}
|
|
1567
|
+
case 'expired':
|
|
1568
|
+
agent.emitAttributed('agentfootprint.artifacts.expired', {
|
|
1569
|
+
ref: fact.swept.ref,
|
|
1570
|
+
reason: fact.swept.reason,
|
|
1571
|
+
kind: fact.swept.kind,
|
|
1572
|
+
bytes: fact.swept.bytes,
|
|
1573
|
+
}, attribution);
|
|
1574
|
+
return;
|
|
1264
1575
|
case 'resolved':
|
|
1265
|
-
agent.
|
|
1576
|
+
agent.emitAttributed('agentfootprint.artifacts.resolved', {
|
|
1266
1577
|
ref: fact.ref,
|
|
1267
1578
|
via: fact.via,
|
|
1268
1579
|
kind: fact.kind,
|
|
1269
1580
|
bytes: fact.bytes,
|
|
1270
|
-
});
|
|
1581
|
+
}, attribution);
|
|
1271
1582
|
return;
|
|
1272
1583
|
case 'refused':
|
|
1273
|
-
agent.
|
|
1584
|
+
agent.emitAttributed('agentfootprint.artifacts.refused', {
|
|
1274
1585
|
op: fact.op,
|
|
1275
1586
|
reason: fact.reason,
|
|
1276
1587
|
...(fact.ref !== undefined && { ref: fact.ref }),
|
|
1277
1588
|
...(fact.detail !== undefined && { detail: fact.detail }),
|
|
1278
|
-
});
|
|
1589
|
+
}, attribution);
|
|
1279
1590
|
return;
|
|
1280
1591
|
default:
|
|
1281
1592
|
return;
|