agentfootprint 9.31.0 → 9.32.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.
Files changed (130) hide show
  1. package/AGENTS.md +1 -1
  2. package/CLAUDE.md +4 -1
  3. package/ai-instructions/claude-code/SKILL.md +1 -1
  4. package/dist/adapters/identity/jwks.js +18 -0
  5. package/dist/adapters/identity/jwks.js.map +1 -1
  6. package/dist/adapters/types.js.map +1 -1
  7. package/dist/artifacts/gcsArtifacts.js +20 -0
  8. package/dist/artifacts/gcsArtifacts.js.map +1 -1
  9. package/dist/esm/adapters/identity/jwks.d.ts +18 -0
  10. package/dist/esm/adapters/identity/jwks.js +18 -0
  11. package/dist/esm/adapters/identity/jwks.js.map +1 -1
  12. package/dist/esm/adapters/types.d.ts +30 -2
  13. package/dist/esm/adapters/types.js.map +1 -1
  14. package/dist/esm/artifacts/gcsArtifacts.d.ts +20 -0
  15. package/dist/esm/artifacts/gcsArtifacts.js +20 -0
  16. package/dist/esm/artifacts/gcsArtifacts.js.map +1 -1
  17. package/dist/esm/events/payloads.d.ts +36 -0
  18. package/dist/esm/events/registry.d.ts +3 -1
  19. package/dist/esm/events/registry.js +2 -0
  20. package/dist/esm/events/registry.js.map +1 -1
  21. package/dist/esm/hosting/admission.d.ts +25 -0
  22. package/dist/esm/hosting/admission.js +25 -0
  23. package/dist/esm/hosting/admission.js.map +1 -1
  24. package/dist/esm/hosting/envelope.d.ts +10 -0
  25. package/dist/esm/hosting/envelope.js +10 -0
  26. package/dist/esm/hosting/envelope.js.map +1 -1
  27. package/dist/esm/hosting/index.d.ts +1 -0
  28. package/dist/esm/hosting/index.js.map +1 -1
  29. package/dist/esm/hosting/ingressRecord.d.ts +177 -0
  30. package/dist/esm/hosting/ingressRecord.js +246 -0
  31. package/dist/esm/hosting/ingressRecord.js.map +1 -0
  32. package/dist/esm/hosting/standingAgent.js +50 -1
  33. package/dist/esm/hosting/standingAgent.js.map +1 -1
  34. package/dist/esm/hosting/types.d.ts +31 -0
  35. package/dist/esm/hosting/types.js.map +1 -1
  36. package/dist/esm/lib/mcp/gatewayTransport.d.ts +52 -0
  37. package/dist/esm/lib/mcp/gatewayTransport.js +1 -0
  38. package/dist/esm/lib/mcp/gatewayTransport.js.map +1 -1
  39. package/dist/esm/lib/mcp/mcpClient.js +8 -1
  40. package/dist/esm/lib/mcp/mcpClient.js.map +1 -1
  41. package/dist/esm/lib/mcp/types.d.ts +10 -0
  42. package/dist/esm/observe.js +2 -1
  43. package/dist/esm/observe.js.map +1 -1
  44. package/dist/esm/recorders/core/ResilienceRecorder.d.ts +8 -7
  45. package/dist/esm/recorders/core/ResilienceRecorder.js +9 -7
  46. package/dist/esm/recorders/core/ResilienceRecorder.js.map +1 -1
  47. package/dist/esm/recorders/core/resilienceHooks.d.ts +1 -0
  48. package/dist/esm/recorders/core/resilienceHooks.js +13 -0
  49. package/dist/esm/recorders/core/resilienceHooks.js.map +1 -1
  50. package/dist/esm/resilience/withCircuitBreaker.d.ts +27 -7
  51. package/dist/esm/resilience/withCircuitBreaker.js +53 -19
  52. package/dist/esm/resilience/withCircuitBreaker.js.map +1 -1
  53. package/dist/esm/resilience/withFallback.d.ts +11 -0
  54. package/dist/esm/resilience/withFallback.js +11 -0
  55. package/dist/esm/resilience/withFallback.js.map +1 -1
  56. package/dist/esm/resilience/withRetry.d.ts +12 -0
  57. package/dist/esm/resilience/withRetry.js +12 -0
  58. package/dist/esm/resilience/withRetry.js.map +1 -1
  59. package/dist/esm/security/PermissionPolicy.d.ts +22 -0
  60. package/dist/esm/security/PermissionPolicy.js +22 -0
  61. package/dist/esm/security/PermissionPolicy.js.map +1 -1
  62. package/dist/events/registry.js +2 -0
  63. package/dist/events/registry.js.map +1 -1
  64. package/dist/hosting/admission.js +25 -0
  65. package/dist/hosting/admission.js.map +1 -1
  66. package/dist/hosting/envelope.js +10 -0
  67. package/dist/hosting/envelope.js.map +1 -1
  68. package/dist/hosting/index.js.map +1 -1
  69. package/dist/hosting/ingressRecord.js +250 -0
  70. package/dist/hosting/ingressRecord.js.map +1 -0
  71. package/dist/hosting/standingAgent.js +50 -1
  72. package/dist/hosting/standingAgent.js.map +1 -1
  73. package/dist/hosting/types.js.map +1 -1
  74. package/dist/lib/mcp/gatewayTransport.js +1 -0
  75. package/dist/lib/mcp/gatewayTransport.js.map +1 -1
  76. package/dist/lib/mcp/mcpClient.js +8 -1
  77. package/dist/lib/mcp/mcpClient.js.map +1 -1
  78. package/dist/observe.js +2 -1
  79. package/dist/observe.js.map +1 -1
  80. package/dist/recorders/core/ResilienceRecorder.js +9 -7
  81. package/dist/recorders/core/ResilienceRecorder.js.map +1 -1
  82. package/dist/recorders/core/resilienceHooks.js +13 -0
  83. package/dist/recorders/core/resilienceHooks.js.map +1 -1
  84. package/dist/resilience/withCircuitBreaker.js +53 -19
  85. package/dist/resilience/withCircuitBreaker.js.map +1 -1
  86. package/dist/resilience/withFallback.js +11 -0
  87. package/dist/resilience/withFallback.js.map +1 -1
  88. package/dist/resilience/withRetry.js +12 -0
  89. package/dist/resilience/withRetry.js.map +1 -1
  90. package/dist/security/PermissionPolicy.js +22 -0
  91. package/dist/security/PermissionPolicy.js.map +1 -1
  92. package/dist/types/adapters/identity/jwks.d.ts +18 -0
  93. package/dist/types/adapters/identity/jwks.d.ts.map +1 -1
  94. package/dist/types/adapters/types.d.ts +30 -2
  95. package/dist/types/adapters/types.d.ts.map +1 -1
  96. package/dist/types/artifacts/gcsArtifacts.d.ts +20 -0
  97. package/dist/types/artifacts/gcsArtifacts.d.ts.map +1 -1
  98. package/dist/types/events/payloads.d.ts +36 -0
  99. package/dist/types/events/payloads.d.ts.map +1 -1
  100. package/dist/types/events/registry.d.ts +3 -1
  101. package/dist/types/events/registry.d.ts.map +1 -1
  102. package/dist/types/hosting/admission.d.ts +25 -0
  103. package/dist/types/hosting/admission.d.ts.map +1 -1
  104. package/dist/types/hosting/envelope.d.ts +10 -0
  105. package/dist/types/hosting/envelope.d.ts.map +1 -1
  106. package/dist/types/hosting/index.d.ts +1 -0
  107. package/dist/types/hosting/index.d.ts.map +1 -1
  108. package/dist/types/hosting/ingressRecord.d.ts +178 -0
  109. package/dist/types/hosting/ingressRecord.d.ts.map +1 -0
  110. package/dist/types/hosting/standingAgent.d.ts.map +1 -1
  111. package/dist/types/hosting/types.d.ts +31 -0
  112. package/dist/types/hosting/types.d.ts.map +1 -1
  113. package/dist/types/lib/mcp/gatewayTransport.d.ts +52 -0
  114. package/dist/types/lib/mcp/gatewayTransport.d.ts.map +1 -1
  115. package/dist/types/lib/mcp/types.d.ts +10 -0
  116. package/dist/types/lib/mcp/types.d.ts.map +1 -1
  117. package/dist/types/observe.d.ts.map +1 -1
  118. package/dist/types/recorders/core/ResilienceRecorder.d.ts +8 -7
  119. package/dist/types/recorders/core/ResilienceRecorder.d.ts.map +1 -1
  120. package/dist/types/recorders/core/resilienceHooks.d.ts +1 -0
  121. package/dist/types/recorders/core/resilienceHooks.d.ts.map +1 -1
  122. package/dist/types/resilience/withCircuitBreaker.d.ts +27 -7
  123. package/dist/types/resilience/withCircuitBreaker.d.ts.map +1 -1
  124. package/dist/types/resilience/withFallback.d.ts +11 -0
  125. package/dist/types/resilience/withFallback.d.ts.map +1 -1
  126. package/dist/types/resilience/withRetry.d.ts +12 -0
  127. package/dist/types/resilience/withRetry.d.ts.map +1 -1
  128. package/dist/types/security/PermissionPolicy.d.ts +22 -0
  129. package/dist/types/security/PermissionPolicy.d.ts.map +1 -1
  130. package/package.json +1 -1
@@ -12,6 +12,31 @@
12
12
  * and cost events every run already emits). This module is the join, plus the
13
13
  * seam where an operator's own rule goes.
14
14
  *
15
+ * **Status, split rather than averaged, because the two halves were not earned
16
+ * equally:**
17
+ *
18
+ * • **The `admission: { decide }` seam is field-validated — an independent
19
+ * field trial, 2026-08-13.** Running against a real hosted door (a live
20
+ * `nodeHost` in a live Google Cloud project, sessions in a real Firestore),
21
+ * the trial had one caller's first two turns run and the third answer **429
22
+ * before the provider or the session store was invoked** — the
23
+ * cheapest-refusal claim, measured rather than asserted.
24
+ *
25
+ * • **`turnsPerHour` itself is contract-shaped and tested.** The finding
26
+ * records the refusal and restates this helper's per-process bound; it does
27
+ * not record the shipped helper as the policy under test, and a run of a few
28
+ * minutes cannot have crossed an HOUR boundary in any case. So the window's
29
+ * own arithmetic — the roll-off, the reset a caller is told about — is
30
+ * proven here by tests and not by a field run.
31
+ *
32
+ * The honest bound the trial restated is the one already on {@link RecentSpend}:
33
+ * `turnsPerHour` is an in-process reference policy, its counters are not shared
34
+ * across instances and do not survive a restart, so a fleet-wide or billing
35
+ * control needs a `decide` that reads a transactional store of your own.
36
+ *
37
+ * The refusal itself is invisible to `auditExport()` — it happens before a run
38
+ * exists. `standingAgent({ onIngressDecision })` is where it lands instead.
39
+ *
15
40
  * ── One decision, three answers, no fourth ───────────────────────────────────
16
41
  * `'allow'` · `{ queue: true }` · `{ refuse: '<sentence>' }`. Deliberately not
17
42
  * "delay by N ms" (a sleep is a thread the caller is paying for), not "degrade
@@ -12,6 +12,31 @@
12
12
  * and cost events every run already emits). This module is the join, plus the
13
13
  * seam where an operator's own rule goes.
14
14
  *
15
+ * **Status, split rather than averaged, because the two halves were not earned
16
+ * equally:**
17
+ *
18
+ * • **The `admission: { decide }` seam is field-validated — an independent
19
+ * field trial, 2026-08-13.** Running against a real hosted door (a live
20
+ * `nodeHost` in a live Google Cloud project, sessions in a real Firestore),
21
+ * the trial had one caller's first two turns run and the third answer **429
22
+ * before the provider or the session store was invoked** — the
23
+ * cheapest-refusal claim, measured rather than asserted.
24
+ *
25
+ * • **`turnsPerHour` itself is contract-shaped and tested.** The finding
26
+ * records the refusal and restates this helper's per-process bound; it does
27
+ * not record the shipped helper as the policy under test, and a run of a few
28
+ * minutes cannot have crossed an HOUR boundary in any case. So the window's
29
+ * own arithmetic — the roll-off, the reset a caller is told about — is
30
+ * proven here by tests and not by a field run.
31
+ *
32
+ * The honest bound the trial restated is the one already on {@link RecentSpend}:
33
+ * `turnsPerHour` is an in-process reference policy, its counters are not shared
34
+ * across instances and do not survive a restart, so a fleet-wide or billing
35
+ * control needs a `decide` that reads a transactional store of your own.
36
+ *
37
+ * The refusal itself is invisible to `auditExport()` — it happens before a run
38
+ * exists. `standingAgent({ onIngressDecision })` is where it lands instead.
39
+ *
15
40
  * ── One decision, three answers, no fourth ───────────────────────────────────
16
41
  * `'allow'` · `{ queue: true }` · `{ refuse: '<sentence>' }`. Deliberately not
17
42
  * "delay by N ms" (a sleep is a thread the caller is paying for), not "degrade
@@ -1 +1 @@
1
- {"version":3,"file":"admission.js","sourceRoot":"","sources":["../../../src/hosting/admission.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AA0FH,gEAAgE;AAChE,MAAM,OAAO,GAAG,SAAS,CAAC;AAE1B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,YAAY,CAAC,OAA4B;IACvD,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAC1B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,SAAS,CACjB,mCAAmC,MAAM,CAAC,KAAK,CAAC,uCAAuC;YACrF,uFAAuF;YACvF,gFAAgF,CACnF,CAAC;IACJ,CAAC;IACD,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,KAAK,CAAC;IACvD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,cAAc,GAAG,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,SAAS,CACjB,4CAA4C,MAAM,CAAC,cAAc,CAAC,wBAAwB;YACxF,gFAAgF;YAChF,oDAAoD,CACvD,CAAC;IACJ,CAAC;IACD,OAAO;QACL,MAAM,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAoB;YAChD,MAAM,OAAO,GAAG,QAAQ,KAAK,SAAS,CAAC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YACD,OAAO;gBACL,KAAK,EAAE,OAAO,CAAC,MAAM;gBACrB,WAAW;gBACX,YAAY;gBACZ,uEAAuE;gBACvE,GAAG,CAAC,MAAM,IAAI,EAAE,GAAG,EAAE,CAAC;gBACtB,QAAQ;gBACR,QAAQ,EAAE,EAAE,GAAG,SAAS,IAAI,QAAQ;aACrC,CAAC;QACJ,CAAC;QACD,IAAI,IAAI;YACN,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,QAAsC;IAChE,OAAO,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,QAAQ,CAAC,MAAM,EAAE,CAAC;AAC3E,CAAC"}
@@ -138,6 +138,16 @@ export declare function checkEnvelope(envelope: unknown, sessionId?: string): Ch
138
138
  * session nobody signed for is a session nobody can list, and inventing an
139
139
  * owner would be inventing an entitlement.
140
140
  *
141
+ * **Status: the CONTRACT is field-validated — an independent field trial,
142
+ * 2026-08-13.** A live multi-user run against a real Firestore: an owner
143
+ * written once and never moved, a cross-user transcript answering the same
144
+ * not-found a missing session gets, one caller's own two sessions listed over
145
+ * two pages, `listByUser` / `ownerOf` feature detection, and `mayOpenSession`
146
+ * refusing an ordinary turn on somebody else's conversation. The store
147
+ * underneath was **the trial's own Firestore `SessionLifecycle`**, not one this
148
+ * package ships — so the rung belongs to this derivation and the rules above
149
+ * it, and no shipped Google adapter may borrow the credit.
150
+ *
141
151
  * Reads both formats, so a session that is mid-question is owned exactly as
142
152
  * firmly as one that is finished. Returns `undefined` rather than throwing on
143
153
  * a shape it cannot read — an index is a convenience, and refusing to WRITE a
@@ -165,6 +165,16 @@ export function checkEnvelope(envelope, sessionId) {
165
165
  * session nobody signed for is a session nobody can list, and inventing an
166
166
  * owner would be inventing an entitlement.
167
167
  *
168
+ * **Status: the CONTRACT is field-validated — an independent field trial,
169
+ * 2026-08-13.** A live multi-user run against a real Firestore: an owner
170
+ * written once and never moved, a cross-user transcript answering the same
171
+ * not-found a missing session gets, one caller's own two sessions listed over
172
+ * two pages, `listByUser` / `ownerOf` feature detection, and `mayOpenSession`
173
+ * refusing an ordinary turn on somebody else's conversation. The store
174
+ * underneath was **the trial's own Firestore `SessionLifecycle`**, not one this
175
+ * package ships — so the rung belongs to this derivation and the rules above
176
+ * it, and no shipped Google adapter may borrow the credit.
177
+ *
168
178
  * Reads both formats, so a session that is mid-question is owned exactly as
169
179
  * firmly as one that is finished. Returns `undefined` rather than throwing on
170
180
  * a shape it cannot read — an index is a convenience, and refusing to WRITE a
@@ -1 +1 @@
1
- {"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../../src/hosting/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAA2B,MAAM,0BAA0B,CAAC;AASvF,+DAA+D;AAC/D,MAAM,aAAa,GAAsB,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,UAA8B;IACvD,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;AAC9E,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAiB;IAChD,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;AACvE,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,YAAY,CAAC,QAAiB;IAC5C,IAAI,UAAU,CAAC,QAAQ,CAAC,KAAK,cAAc,E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AAO,CAAC,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,SAAS,CACjB,2EAA2E,CAC5E,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QACpD,MAAM,IAAI,SAAS,CACjB,+EAA+E;YAC7E,yEAAyE,CAC5E,CAAC;IACJ,CAAC;IACD,kBAAkB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IACrC,OAAO,GAAgB,CAAC;AAC1B,CAAC"}
@@ -101,6 +101,7 @@ export { bearerToken, verifyRequestIdentity } from './identityVerification.js';
101
101
  export type { IdentityVerificationOptions, IdentityVerifier, VerifiedIdentity, } from './identityVerification.js';
102
102
  export { spendKeyFor, spendLedger, turnsPerHour } from './admission.js';
103
103
  export type { AdmissionContext, AdmissionPolicy, AdmissionVerdict, RecentSpend, SpendLedger, SpendLedgerOptions, TurnsPerHourOptions, } from './admission.js';
104
+ export type { IngressAdmissionVerdict, IngressDoor, IngressOutcome, IngressRecord, IngressSink, } from './ingressRecord.js';
104
105
  export { readSessionWireOp, sessionWireBody, SESSION_LIST_OP, SESSION_TRANSCRIPT_OP, } from './sessionWire.js';
105
106
  export type { SessionSummary, SessionWireRequest, SessionWireResult, TranscriptMessage, } from './sessionWire.js';
106
107
  export { ALL_WIRE_OPS, isWireOp, refuseUnknownWireOp, WIRE_OPS } from './wireOps.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hosting/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsFG;AAEH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEzF,6EAA6E;AAC7E,2EAA2E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uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,qBAAqB,EACrB,2BAA2B,EAC3B,4BAA4B,EAC5B,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AAGrB,2EAA2E;AAC3E,iEAAiE;AACjE,8EAA8E;AAC9E,yDAAyD;AACzD,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAO/E,+EAA+E;AAC/E,uEAAuE;AACvE,2DAA2D;AAC3D,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAuBxE,+EAA+E;AAC/E,yEAAyE;AACzE,qBAAqB;AACrB,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAO1B,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGrF,8EAA8E;AAC9E,6EAA6E;AAC7E,yEAAyE;AACzE,0EAA0E;AAC1E,2EAA2E;AAC3E,2BAA2B;AAC3B,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,GAChB,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,177 @@
1
+ /**
2
+ * hosting/ingressRecord — what the door decided, for the requests that never
3
+ * became a run.
4
+ *
5
+ * await standingAgent({
6
+ * agent, sessions, host,
7
+ * identity: { verify },
8
+ * admission: turnsPerHour({ limit: 60 }),
9
+ * onIngressDecision: (record) => myAuditSink.write(record),
10
+ * });
11
+ *
12
+ * ── The gap this closes, named exactly ───────────────────────────────────────
13
+ * `auditExport()` is a record of RUNS. A 401 out of `identity.verify` and a 429
14
+ * out of `admission.decide` both happen before a run exists — no agent has been
15
+ * built, no observer is attached, no typed event is emitted — so neither is in
16
+ * the bundle. Two independent review rounds wrote that down as the same finding,
17
+ * and the honest consequence is the sharp one: **an empty bundle is not evidence
18
+ * that nobody was turned away.** It is evidence that nobody ran.
19
+ *
20
+ * This is the seam where the turned-away go. One record per request the composer
21
+ * decided, handed to a sink you own, at the moment the reply reaches its
22
+ * terminal.
23
+ *
24
+ * ── What it is NOT, said before anything else ────────────────────────────────
25
+ * **It does not join the audit hash chain.** Nothing here is hashed, chained,
26
+ * sequenced against `auditExport()`'s records, or verifiable by
27
+ * `verifyAuditBundle`. It is a STREAM you chain into your own sink. Saying
28
+ * otherwise would make this fix the exact failure it exists to close — a
29
+ * mechanism that looks like evidence and is not. If you need ingress decisions
30
+ * inside a tamper-evident chain, write them into the same store your audit
31
+ * bundle lands in and chain them there, where the sequence is yours to define.
32
+ *
33
+ * ── Secrets never travel ─────────────────────────────────────────────────────
34
+ * A record carries the CLASS of what happened and the identifiers the caller
35
+ * already knew. Never the bearer token, never a header, never a claim set,
36
+ * never an error's message — the `sdkFailure` law, applied to the front door.
37
+ * `errorName` and `errorCode` are this package's own vocabulary; a message may
38
+ * carry an SDK's text, an operator's sentence or a store's detail, so no message
39
+ * is copied. The one identity field is `userId`, and it is the id the token
40
+ * PROVED — never one a request merely claimed.
41
+ *
42
+ * ── What the composer can decide, and what it never sees ─────────────────────
43
+ * Every ingress exit of `standingAgent` funnels through one reply terminal, so
44
+ * all of these land here — including the ones a consumer's own `verify` and
45
+ * `decide` never observe:
46
+ *
47
+ * - a request with no `Authorization: Bearer …` at all (`verify` is never
48
+ * called, so nothing you wrote could have logged it);
49
+ * - a verifier that could not answer (503) as distinct from a bad credential;
50
+ * - an admission refusal, and also an admission ALLOW — the census is what
51
+ * makes an absence readable;
52
+ * - a turn or a transcript naming somebody else's session (the 404 that is
53
+ * deliberately indistinguishable from "no such session");
54
+ * - a session op at a door with no verifier, a store with no owner index, a
55
+ * concurrent-run refusal, an artifact ref that did not resolve;
56
+ * - and a request that was SERVED.
57
+ *
58
+ * What it does not carry, stated rather than implied: a body the TRANSPORT
59
+ * refused before the composer ever saw it — unparseable JSON, or an `op` this
60
+ * host's wire grammar does not speak (`InvalidWireOpError`, answered 400 by
61
+ * `httpHost` inside its own request reader). That is a malformed request rather
62
+ * than a decision about a caller, and the composer does not claim it. Your HTTP
63
+ * access log has it.
64
+ *
65
+ * Pattern: Observer at a composition boundary. Zero-cost when unset — with no
66
+ * sink configured nothing is built, nothing is wrapped, and the reply object the
67
+ * handler uses is the host's own, to the byte.
68
+ */
69
+ import { type VerifiedIdentity } from './identityVerification.js';
70
+ import { type IdentityFailureClass } from './errors.js';
71
+ import type { HostReply, HostRequest } from './types.js';
72
+ /** Which of the composer's three doors this request knocked at. */
73
+ export type IngressDoor = 'turn' | 'session-op' | 'artifact';
74
+ /**
75
+ * How the door answered — coarse on purpose, because this is the field a
76
+ * dashboard groups by. `errorCode` carries the precision beside it.
77
+ *
78
+ * - `'served'` — the reply reached a DELIVERING terminal: an answer, a
79
+ * question a person must answer, a transcript, a listing, an artifact.
80
+ *
81
+ * Read it as **delivered**, not as *admitted*. The record is filed at the
82
+ * terminal the reply actually reached, and a failure is not a delivery — so
83
+ * a request the door admitted whose RUN, store or provider then broke ends
84
+ * at `reply.fail` and is filed `'failed'` (or `'refused'`, when the error
85
+ * names itself with an `ERR_…` code), carrying that error's class. It is
86
+ * NOT `'served'`. To count what the door let through, count everything that
87
+ * is not one of the door's own refusals — `'identity-refused'`,
88
+ * `'verifier-unavailable'`, `'admission-refused'`, `'session-refused'` — or
89
+ * read `admission`, which is the verdict a policy actually returned and is
90
+ * present on a refused record and a broken one alike.
91
+ * - `'identity-refused'` — 401. The credential did not identify anybody, or
92
+ * none arrived at a door that insists.
93
+ * - `'verifier-unavailable'` — 503. The verifier could not do its job; the
94
+ * caller's token was never judged and this is not their fault.
95
+ * - `'admission-refused'` — 429. A policy said no before any work started.
96
+ * - `'session-refused'` — the one indistinguishable not-found: a session that
97
+ * does not exist, belongs to somebody else, or names no owner.
98
+ * - `'refused'` — every other refusal the door made by name (a session op with
99
+ * no verifier configured, a store with no owner index, a concurrent run, an
100
+ * artifact ref that did not resolve, a pause the wire could not carry).
101
+ * - `'failed'` — the request ended in an error that is not one of the door's
102
+ * own refusals. Usually the run, the store or the provider — which is why
103
+ * an admitted request that then broke lands HERE and not in `'served'`.
104
+ */
105
+ export type IngressOutcome = 'served' | 'identity-refused' | 'verifier-unavailable' | 'admission-refused' | 'session-refused' | 'refused' | 'failed';
106
+ /** What an admission policy answered, when one was consulted. */
107
+ export type IngressAdmissionVerdict = 'allow' | 'queue' | 'refuse';
108
+ /**
109
+ * One decision the door made, as plain data.
110
+ *
111
+ * Every field is either a class of what happened or an identifier the caller
112
+ * already had. Nothing here is a secret, and nothing here is a message.
113
+ */
114
+ export interface IngressRecord {
115
+ /** When the request left the door, `Date.now()`. */
116
+ readonly at: number;
117
+ /** Which door it knocked at. */
118
+ readonly door: IngressDoor;
119
+ /** The wire op it named, in the spelling a body uses. Absent for a turn. */
120
+ readonly op?: string;
121
+ /** How the door answered. */
122
+ readonly outcome: IngressOutcome;
123
+ /** The refusal's own `code` (`'ERR_IDENTITY_NOT_VERIFIED'`, …). Never a message. */
124
+ readonly errorCode?: string;
125
+ /** The error's class name, for a failure this package did not author. */
126
+ readonly errorName?: string;
127
+ /** WHICH token check failed — the whole vocabulary a refusal may say about a
128
+ * credential, and never one character of the credential. */
129
+ readonly identityFailure?: IdentityFailureClass;
130
+ /** `true` when the refused request also NAMED a user it could not prove —
131
+ * the impersonation shape, kept separate so a sink can count it. */
132
+ readonly claimedUser?: boolean;
133
+ /** The id the token PROVED, when one was proven. Never a claimed one. */
134
+ readonly userId?: string;
135
+ /** The conversation this request named, when it named one. */
136
+ readonly sessionId?: string;
137
+ /** Whether a bearer credential was PRESENT. Never its value. */
138
+ readonly bearerPresent: boolean;
139
+ /** What the admission policy answered, when one was consulted. */
140
+ readonly admission?: IngressAdmissionVerdict;
141
+ }
142
+ /**
143
+ * Where records go — {@link StandingAgentBaseOptions.onIngressDecision}.
144
+ *
145
+ * Called once per request, synchronously, at the moment the reply reaches its
146
+ * terminal. A sink that throws is contained (a broken log must not turn a served
147
+ * request into a failed one) and reported once on `console.warn`, because a
148
+ * silently-dropped security record is the failure this whole seam exists to
149
+ * close. Do the slow part yourself: buffer, batch, and never `await` the network
150
+ * inside it.
151
+ */
152
+ export type IngressSink = (record: IngressRecord) => void;
153
+ /**
154
+ * The per-request bookkeeping: the facts known at the door, the facts learned
155
+ * on the way in, and the ONE record that leaves.
156
+ *
157
+ * Built only when a sink is configured. `settle` is idempotent — the first
158
+ * terminal wins, and a reply that somehow reaches two of them (a host that
159
+ * completes and then fails) still produces exactly one record, because two
160
+ * records for one request would be a census that over-counts.
161
+ */
162
+ export interface IngressNote {
163
+ /** Wrap the host's reply so its first terminal files the record. */
164
+ watch(reply: HostReply): HostReply;
165
+ /** The verifier proved somebody — record the proven id, never a claimed one. */
166
+ identified(verified: VerifiedIdentity | undefined): void;
167
+ /** An admission policy answered. */
168
+ admitted(verdict: IngressAdmissionVerdict): void;
169
+ /** File the record for a request that left without any terminal at all. */
170
+ settle(): void;
171
+ }
172
+ /**
173
+ * Begin one request's ingress record.
174
+ *
175
+ * @internal — the option is public, this bookkeeping is not.
176
+ */
177
+ export declare function beginIngress(request: HostRequest, sink: IngressSink): IngressNote;
@@ -0,0 +1,246 @@
1
+ /**
2
+ * hosting/ingressRecord — what the door decided, for the requests that never
3
+ * became a run.
4
+ *
5
+ * await standingAgent({
6
+ * agent, sessions, host,
7
+ * identity: { verify },
8
+ * admission: turnsPerHour({ limit: 60 }),
9
+ * onIngressDecision: (record) => myAuditSink.write(record),
10
+ * });
11
+ *
12
+ * ── The gap this closes, named exactly ───────────────────────────────────────
13
+ * `auditExport()` is a record of RUNS. A 401 out of `identity.verify` and a 429
14
+ * out of `admission.decide` both happen before a run exists — no agent has been
15
+ * built, no observer is attached, no typed event is emitted — so neither is in
16
+ * the bundle. Two independent review rounds wrote that down as the same finding,
17
+ * and the honest consequence is the sharp one: **an empty bundle is not evidence
18
+ * that nobody was turned away.** It is evidence that nobody ran.
19
+ *
20
+ * This is the seam where the turned-away go. One record per request the composer
21
+ * decided, handed to a sink you own, at the moment the reply reaches its
22
+ * terminal.
23
+ *
24
+ * ── What it is NOT, said before anything else ────────────────────────────────
25
+ * **It does not join the audit hash chain.** Nothing here is hashed, chained,
26
+ * sequenced against `auditExport()`'s records, or verifiable by
27
+ * `verifyAuditBundle`. It is a STREAM you chain into your own sink. Saying
28
+ * otherwise would make this fix the exact failure it exists to close — a
29
+ * mechanism that looks like evidence and is not. If you need ingress decisions
30
+ * inside a tamper-evident chain, write them into the same store your audit
31
+ * bundle lands in and chain them there, where the sequence is yours to define.
32
+ *
33
+ * ── Secrets never travel ─────────────────────────────────────────────────────
34
+ * A record carries the CLASS of what happened and the identifiers the caller
35
+ * already knew. Never the bearer token, never a header, never a claim set,
36
+ * never an error's message — the `sdkFailure` law, applied to the front door.
37
+ * `errorName` and `errorCode` are this package's own vocabulary; a message may
38
+ * carry an SDK's text, an operator's sentence or a store's detail, so no message
39
+ * is copied. The one identity field is `userId`, and it is the id the token
40
+ * PROVED — never one a request merely claimed.
41
+ *
42
+ * ── What the composer can decide, and what it never sees ─────────────────────
43
+ * Every ingress exit of `standingAgent` funnels through one reply terminal, so
44
+ * all of these land here — including the ones a consumer's own `verify` and
45
+ * `decide` never observe:
46
+ *
47
+ * - a request with no `Authorization: Bearer …` at all (`verify` is never
48
+ * called, so nothing you wrote could have logged it);
49
+ * - a verifier that could not answer (503) as distinct from a bad credential;
50
+ * - an admission refusal, and also an admission ALLOW — the census is what
51
+ * makes an absence readable;
52
+ * - a turn or a transcript naming somebody else's session (the 404 that is
53
+ * deliberately indistinguishable from "no such session");
54
+ * - a session op at a door with no verifier, a store with no owner index, a
55
+ * concurrent-run refusal, an artifact ref that did not resolve;
56
+ * - and a request that was SERVED.
57
+ *
58
+ * What it does not carry, stated rather than implied: a body the TRANSPORT
59
+ * refused before the composer ever saw it — unparseable JSON, or an `op` this
60
+ * host's wire grammar does not speak (`InvalidWireOpError`, answered 400 by
61
+ * `httpHost` inside its own request reader). That is a malformed request rather
62
+ * than a decision about a caller, and the composer does not claim it. Your HTTP
63
+ * access log has it.
64
+ *
65
+ * Pattern: Observer at a composition boundary. Zero-cost when unset — with no
66
+ * sink configured nothing is built, nothing is wrapped, and the reply object the
67
+ * handler uses is the host's own, to the byte.
68
+ */
69
+ import { bearerToken } from './identityVerification.js';
70
+ import { AdmissionRefusedError, IdentityNotVerifiedError, SessionNotFoundError, VerifierUnavailableError, } from './errors.js';
71
+ import { ARTIFACT_GET_OP, ARTIFACT_HEAD_OP } from './artifactWire.js';
72
+ import { SESSION_LIST_OP, SESSION_TRANSCRIPT_OP } from './sessionWire.js';
73
+ /**
74
+ * Classify one refusal into the record's vocabulary.
75
+ *
76
+ * The order is deliberate: the classes this package authored are matched by
77
+ * `instanceof` first, so a door refusal never reads as a generic failure, and
78
+ * anything else keeps only its class NAME. No message is read, from any error,
79
+ * ever.
80
+ */
81
+ function classify(err) {
82
+ if (err instanceof IdentityNotVerifiedError) {
83
+ return {
84
+ outcome: 'identity-refused',
85
+ errorCode: err.code,
86
+ errorName: err.name,
87
+ identityFailure: err.failure,
88
+ claimedUser: err.claimedUser,
89
+ };
90
+ }
91
+ if (err instanceof VerifierUnavailableError) {
92
+ return { outcome: 'verifier-unavailable', errorCode: err.code, errorName: err.name };
93
+ }
94
+ if (err instanceof AdmissionRefusedError) {
95
+ return { outcome: 'admission-refused', errorCode: err.code, errorName: err.name };
96
+ }
97
+ if (err instanceof SessionNotFoundError) {
98
+ return { outcome: 'session-refused', errorCode: err.code, errorName: err.name };
99
+ }
100
+ const code = err?.code;
101
+ const name = err?.name;
102
+ // A hosting refusal names itself with an `ERR_…` code. Anything else is a
103
+ // failure rather than a decision — and either way only the class travels.
104
+ const hasHostingCode = typeof code === 'string' && code.startsWith('ERR_');
105
+ return {
106
+ outcome: hasHostingCode ? 'refused' : 'failed',
107
+ ...(typeof code === 'string' && { errorCode: code }),
108
+ ...(typeof name === 'string' && { errorName: name }),
109
+ };
110
+ }
111
+ /** Which op name a request named, in the spelling a body uses. */
112
+ function opOf(request) {
113
+ if (request.session !== undefined) {
114
+ return request.session.op === 'list' ? SESSION_LIST_OP : SESSION_TRANSCRIPT_OP;
115
+ }
116
+ if (request.artifact !== undefined) {
117
+ return request.artifact.op === 'head' ? ARTIFACT_HEAD_OP : ARTIFACT_GET_OP;
118
+ }
119
+ return undefined;
120
+ }
121
+ /** Which door a request knocked at — the same discriminants the handler uses. */
122
+ function doorOf(request) {
123
+ if (request.session !== undefined)
124
+ return 'session-op';
125
+ if (request.artifact !== undefined)
126
+ return 'artifact';
127
+ return 'turn';
128
+ }
129
+ /**
130
+ * Which conversation this request named. A `session-transcript` names it inside
131
+ * the op rather than beside it, and a record that missed that would be blind to
132
+ * exactly the refusal the ownership rule produces.
133
+ */
134
+ function sessionOf(request) {
135
+ if (request.session !== undefined && request.session.op === 'transcript') {
136
+ return request.session.sessionId;
137
+ }
138
+ return request.sessionId;
139
+ }
140
+ let warnedOnce = false;
141
+ /** Report a throwing sink once. A broken record is a fault worth naming; a
142
+ * fault reported on every request is a second outage. */
143
+ function warnSink(err) {
144
+ if (warnedOnce)
145
+ return;
146
+ warnedOnce = true;
147
+ // eslint-disable-next-line no-console
148
+ console.warn(`[hosting] the onIngressDecision sink threw and the record was dropped. The request was ` +
149
+ `unaffected — a broken log must not turn a served request into a failed one — but this ` +
150
+ `door's ingress decisions are not being recorded. Reported once per process. Cause: ` +
151
+ `${err?.name ?? 'unknown'}`);
152
+ }
153
+ /**
154
+ * Begin one request's ingress record.
155
+ *
156
+ * @internal — the option is public, this bookkeeping is not.
157
+ */
158
+ export function beginIngress(request, sink) {
159
+ const door = doorOf(request);
160
+ const op = opOf(request);
161
+ const sessionId = sessionOf(request);
162
+ // Presence, never the value: the whole point of the class vocabulary above is
163
+ // that an operator can act without a single character of the credential.
164
+ const bearerPresent = bearerToken(request.headers) !== undefined;
165
+ let userId;
166
+ let admission;
167
+ let filed = false;
168
+ function file(outcome, err) {
169
+ if (filed)
170
+ return;
171
+ filed = true;
172
+ const detail = err === undefined ? undefined : classify(err);
173
+ const record = {
174
+ at: Date.now(),
175
+ door,
176
+ ...(op !== undefined && { op }),
177
+ outcome: detail?.outcome ?? outcome,
178
+ ...(detail?.errorCode !== undefined && { errorCode: detail.errorCode }),
179
+ ...(detail?.errorName !== undefined && { errorName: detail.errorName }),
180
+ ...(detail?.identityFailure !== undefined && { identityFailure: detail.identityFailure }),
181
+ ...(detail?.claimedUser !== undefined && { claimedUser: detail.claimedUser }),
182
+ ...(userId !== undefined && { userId }),
183
+ ...(sessionId !== undefined && { sessionId }),
184
+ bearerPresent,
185
+ ...(admission !== undefined && { admission }),
186
+ };
187
+ try {
188
+ sink(record);
189
+ }
190
+ catch (sinkErr) {
191
+ warnSink(sinkErr);
192
+ }
193
+ }
194
+ return {
195
+ watch(reply) {
196
+ // Every optional terminal is forwarded ONLY when the host has it: the
197
+ // composer feature-detects `awaiting`/`artifact`/`sessions`, so a wrapper
198
+ // that defined them unconditionally would tell it the host can describe a
199
+ // pause it cannot, and the named refusal for that case would never fire.
200
+ return {
201
+ complete(output) {
202
+ file('served');
203
+ reply.complete(output);
204
+ },
205
+ fail(error) {
206
+ file('failed', error);
207
+ reply.fail(error);
208
+ },
209
+ ...(reply.awaiting && {
210
+ awaiting: (pending) => {
211
+ file('served');
212
+ reply.awaiting?.(pending);
213
+ },
214
+ }),
215
+ ...(reply.artifact && {
216
+ artifact: (result) => {
217
+ file('served');
218
+ reply.artifact?.(result);
219
+ },
220
+ }),
221
+ ...(reply.sessions && {
222
+ sessions: (result) => {
223
+ file('served');
224
+ reply.sessions?.(result);
225
+ },
226
+ }),
227
+ // Not a terminal: a chunk is part of an answer still being written.
228
+ ...(reply.emit && { emit: (chunk) => reply.emit?.(chunk) }),
229
+ };
230
+ },
231
+ identified(verified) {
232
+ if (verified !== undefined)
233
+ userId = verified.userId;
234
+ },
235
+ admitted(verdict) {
236
+ admission = verdict;
237
+ },
238
+ settle() {
239
+ // Only reachable if a request left the door without ending its reply,
240
+ // which the composer never does. Recorded as a failure rather than
241
+ // silently dropped: a census with holes is the thing this replaces.
242
+ file('failed');
243
+ },
244
+ };
245
+ }
246
+ //# sourceMappingURL=ingressRecord.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingressRecord.js","sourceRoot":"","sources":["../../../src/hosting/ingressRecord.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AAEH,OAAO,EAAE,WAAW,EAAyB,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,GAEzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAgG1E;;;;;;;GAOG;AACH,SAAS,QAAQ,CAAC,GAAY;IAO5B,IAAI,GAAG,YAAY,wBAAwB,EAAE,CAAC;QAC5C,OAAO;YACL,OAAO,EAAE,kBAAkB;YAC3B,SAAS,EAAE,GAAG,CAAC,IAAI;YACnB,SAAS,EAAE,GAAG,CAAC,IAAI;YACnB,eAAe,EAAE,GAAG,CAAC,OAAO;YAC5B,WAAW,EAAE,GAAG,CAAC,WAAW;SAC7B,CAAC;IACJ,CAAC;IACD,IAAI,GAAG,YAAY,wBAAwB,EAAE,CAAC;QAC5C,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,GAAG,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;IACvF,CAAC;IACD,IAAI,GAAG,YAAY,qBAAqB,EAAE,CAAC;QACzC,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,GAAG,CAAC,IAAI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