agentfootprint 9.24.0 → 9.26.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 (289) hide show
  1. package/AGENTS.md +1 -1
  2. package/CLAUDE.md +7 -1
  3. package/README.md +3 -1
  4. package/ai-instructions/claude-code/SKILL.md +1 -1
  5. package/dist/adapters/code/local.js +102 -2
  6. package/dist/adapters/code/local.js.map +1 -1
  7. package/dist/adapters/hosting/agentcore.js +11 -0
  8. package/dist/adapters/hosting/agentcore.js.map +1 -1
  9. package/dist/adapters/identity/jwks.js +277 -0
  10. package/dist/adapters/identity/jwks.js.map +1 -0
  11. package/dist/adapters/types.js +18 -1
  12. package/dist/adapters/types.js.map +1 -1
  13. package/dist/artifacts/fileArtifacts.js +144 -17
  14. package/dist/artifacts/fileArtifacts.js.map +1 -1
  15. package/dist/artifacts/gcsArtifacts.js +398 -0
  16. package/dist/artifacts/gcsArtifacts.js.map +1 -0
  17. package/dist/artifacts/index.js +17 -1
  18. package/dist/artifacts/index.js.map +1 -1
  19. package/dist/artifacts/objectStore.js +264 -0
  20. package/dist/artifacts/objectStore.js.map +1 -0
  21. package/dist/artifacts/payload.js +41 -2
  22. package/dist/artifacts/payload.js.map +1 -1
  23. package/dist/artifacts/recordingArtifact.js +88 -0
  24. package/dist/artifacts/recordingArtifact.js.map +1 -0
  25. package/dist/artifacts/s3Artifacts.js +542 -0
  26. package/dist/artifacts/s3Artifacts.js.map +1 -0
  27. package/dist/artifacts/scopePath.js +87 -0
  28. package/dist/artifacts/scopePath.js.map +1 -0
  29. package/dist/artifacts/streaming.js +132 -0
  30. package/dist/artifacts/streaming.js.map +1 -0
  31. package/dist/artifacts/types.js +10 -2
  32. package/dist/artifacts/types.js.map +1 -1
  33. package/dist/core/Agent.js +176 -0
  34. package/dist/core/Agent.js.map +1 -1
  35. package/dist/core/agent/AgentBuilder.js +20 -0
  36. package/dist/core/agent/AgentBuilder.js.map +1 -1
  37. package/dist/core/agent/repeatedCall.js +190 -0
  38. package/dist/core/agent/repeatedCall.js.map +1 -0
  39. package/dist/core/agent/stages/toolCalls.js +50 -0
  40. package/dist/core/agent/stages/toolCalls.js.map +1 -1
  41. package/dist/core/codeRunnerTool.js +149 -12
  42. package/dist/core/codeRunnerTool.js.map +1 -1
  43. package/dist/esm/adapters/code/local.d.ts +16 -0
  44. package/dist/esm/adapters/code/local.js +102 -2
  45. package/dist/esm/adapters/code/local.js.map +1 -1
  46. package/dist/esm/adapters/hosting/agentcore.js +11 -0
  47. package/dist/esm/adapters/hosting/agentcore.js.map +1 -1
  48. package/dist/esm/adapters/identity/jwks.d.ts +124 -0
  49. package/dist/esm/adapters/identity/jwks.js +249 -0
  50. package/dist/esm/adapters/identity/jwks.js.map +1 -0
  51. package/dist/esm/adapters/types.d.ts +86 -0
  52. package/dist/esm/adapters/types.js +16 -0
  53. package/dist/esm/adapters/types.js.map +1 -1
  54. package/dist/esm/artifacts/fileArtifacts.d.ts +13 -1
  55. package/dist/esm/artifacts/fileArtifacts.js +145 -18
  56. package/dist/esm/artifacts/fileArtifacts.js.map +1 -1
  57. package/dist/esm/artifacts/gcsArtifacts.d.ts +142 -0
  58. package/dist/esm/artifacts/gcsArtifacts.js +394 -0
  59. package/dist/esm/artifacts/gcsArtifacts.js.map +1 -0
  60. package/dist/esm/artifacts/index.d.ts +5 -1
  61. package/dist/esm/artifacts/index.js +4 -0
  62. package/dist/esm/artifacts/index.js.map +1 -1
  63. package/dist/esm/artifacts/objectStore.d.ts +166 -0
  64. package/dist/esm/artifacts/objectStore.js +252 -0
  65. package/dist/esm/artifacts/objectStore.js.map +1 -0
  66. package/dist/esm/artifacts/payload.d.ts +36 -4
  67. package/dist/esm/artifacts/payload.js +38 -1
  68. package/dist/esm/artifacts/payload.js.map +1 -1
  69. package/dist/esm/artifacts/recordingArtifact.d.ts +76 -0
  70. package/dist/esm/artifacts/recordingArtifact.js +83 -0
  71. package/dist/esm/artifacts/recordingArtifact.js.map +1 -0
  72. package/dist/esm/artifacts/s3Artifacts.d.ts +149 -0
  73. package/dist/esm/artifacts/s3Artifacts.js +538 -0
  74. package/dist/esm/artifacts/s3Artifacts.js.map +1 -0
  75. package/dist/esm/artifacts/scopePath.d.ts +50 -0
  76. package/dist/esm/artifacts/scopePath.js +80 -0
  77. package/dist/esm/artifacts/scopePath.js.map +1 -0
  78. package/dist/esm/artifacts/streaming.d.ts +82 -0
  79. package/dist/esm/artifacts/streaming.js +123 -0
  80. package/dist/esm/artifacts/streaming.js.map +1 -0
  81. package/dist/esm/artifacts/types.d.ts +71 -5
  82. package/dist/esm/artifacts/types.js +10 -2
  83. package/dist/esm/artifacts/types.js.map +1 -1
  84. package/dist/esm/core/Agent.d.ts +66 -2
  85. package/dist/esm/core/Agent.js +176 -0
  86. package/dist/esm/core/Agent.js.map +1 -1
  87. package/dist/esm/core/agent/AgentBuilder.js +20 -0
  88. package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
  89. package/dist/esm/core/agent/repeatedCall.d.ts +150 -0
  90. package/dist/esm/core/agent/repeatedCall.js +184 -0
  91. package/dist/esm/core/agent/repeatedCall.js.map +1 -0
  92. package/dist/esm/core/agent/stages/toolCalls.d.ts +12 -0
  93. package/dist/esm/core/agent/stages/toolCalls.js +50 -0
  94. package/dist/esm/core/agent/stages/toolCalls.js.map +1 -1
  95. package/dist/esm/core/agent/types.d.ts +82 -0
  96. package/dist/esm/core/codeRunnerTool.d.ts +31 -0
  97. package/dist/esm/core/codeRunnerTool.js +149 -12
  98. package/dist/esm/core/codeRunnerTool.js.map +1 -1
  99. package/dist/esm/events/payloads.d.ts +22 -0
  100. package/dist/esm/events/registry.d.ts +3 -1
  101. package/dist/esm/events/registry.js +2 -0
  102. package/dist/esm/events/registry.js.map +1 -1
  103. package/dist/esm/hosting/admission.d.ts +180 -0
  104. package/dist/esm/hosting/admission.js +188 -0
  105. package/dist/esm/hosting/admission.js.map +1 -0
  106. package/dist/esm/hosting/artifactWire.d.ts +8 -5
  107. package/dist/esm/hosting/artifactWire.js +14 -9
  108. package/dist/esm/hosting/artifactWire.js.map +1 -1
  109. package/dist/esm/hosting/envelope.d.ts +34 -0
  110. package/dist/esm/hosting/envelope.js +81 -0
  111. package/dist/esm/hosting/envelope.js.map +1 -1
  112. package/dist/esm/hosting/errors.d.ts +131 -0
  113. package/dist/esm/hosting/errors.js +195 -0
  114. package/dist/esm/hosting/errors.js.map +1 -1
  115. package/dist/esm/hosting/httpHost.d.ts +21 -0
  116. package/dist/esm/hosting/httpHost.js +44 -2
  117. package/dist/esm/hosting/httpHost.js.map +1 -1
  118. package/dist/esm/hosting/identityVerification.d.ts +154 -0
  119. package/dist/esm/hosting/identityVerification.js +135 -0
  120. package/dist/esm/hosting/identityVerification.js.map +1 -0
  121. package/dist/esm/hosting/index.d.ts +12 -3
  122. package/dist/esm/hosting/index.js +16 -2
  123. package/dist/esm/hosting/index.js.map +1 -1
  124. package/dist/esm/hosting/memorySessions.d.ts +9 -0
  125. package/dist/esm/hosting/memorySessions.js +86 -0
  126. package/dist/esm/hosting/memorySessions.js.map +1 -1
  127. package/dist/esm/hosting/nodeHost.js +8 -0
  128. package/dist/esm/hosting/nodeHost.js.map +1 -1
  129. package/dist/esm/hosting/sessionWire.d.ts +126 -0
  130. package/dist/esm/hosting/sessionWire.js +95 -0
  131. package/dist/esm/hosting/sessionWire.js.map +1 -0
  132. package/dist/esm/hosting/sqliteSessions.js +122 -5
  133. package/dist/esm/hosting/sqliteSessions.js.map +1 -1
  134. package/dist/esm/hosting/standingAgent.js +299 -8
  135. package/dist/esm/hosting/standingAgent.js.map +1 -1
  136. package/dist/esm/hosting/types.d.ts +166 -6
  137. package/dist/esm/hosting/types.js.map +1 -1
  138. package/dist/esm/hosting/wireOps.d.ts +52 -0
  139. package/dist/esm/hosting/wireOps.js +60 -0
  140. package/dist/esm/hosting/wireOps.js.map +1 -0
  141. package/dist/esm/identity.d.ts +1 -0
  142. package/dist/esm/identity.js +6 -0
  143. package/dist/esm/identity.js.map +1 -1
  144. package/dist/esm/index.d.ts +3 -2
  145. package/dist/esm/index.js +10 -1
  146. package/dist/esm/index.js.map +1 -1
  147. package/dist/esm/lib/injection-engine/factories/defineSkill.d.ts +27 -0
  148. package/dist/esm/lib/injection-engine/factories/defineSkill.js +13 -0
  149. package/dist/esm/lib/injection-engine/factories/defineSkill.js.map +1 -1
  150. package/dist/esm/lib/injection-engine/index.d.ts +1 -0
  151. package/dist/esm/lib/injection-engine/index.js +7 -0
  152. package/dist/esm/lib/injection-engine/index.js.map +1 -1
  153. package/dist/esm/lib/injection-engine/skillGraph.js +9 -1
  154. package/dist/esm/lib/injection-engine/skillGraph.js.map +1 -1
  155. package/dist/esm/lib/injection-engine/skillGraphCheckup.d.ts +1 -1
  156. package/dist/esm/lib/injection-engine/skillGraphCheckup.js.map +1 -1
  157. package/dist/esm/lib/injection-engine/skillSteps.d.ts +16 -0
  158. package/dist/esm/lib/injection-engine/skillSteps.js +5 -0
  159. package/dist/esm/lib/injection-engine/skillSteps.js.map +1 -1
  160. package/dist/esm/lib/injection-engine/skillVocabulary.d.ts +83 -0
  161. package/dist/esm/lib/injection-engine/skillVocabulary.js +218 -0
  162. package/dist/esm/lib/injection-engine/skillVocabulary.js.map +1 -0
  163. package/dist/events/registry.js +2 -0
  164. package/dist/events/registry.js.map +1 -1
  165. package/dist/hosting/admission.js +194 -0
  166. package/dist/hosting/admission.js.map +1 -0
  167. package/dist/hosting/artifactWire.js +14 -9
  168. package/dist/hosting/artifactWire.js.map +1 -1
  169. package/dist/hosting/envelope.js +84 -1
  170. package/dist/hosting/envelope.js.map +1 -1
  171. package/dist/hosting/errors.js +203 -1
  172. package/dist/hosting/errors.js.map +1 -1
  173. package/dist/hosting/httpHost.js +43 -1
  174. package/dist/hosting/httpHost.js.map +1 -1
  175. package/dist/hosting/identityVerification.js +140 -0
  176. package/dist/hosting/identityVerification.js.map +1 -0
  177. package/dist/hosting/index.js +38 -1
  178. package/dist/hosting/index.js.map +1 -1
  179. package/dist/hosting/memorySessions.js +86 -0
  180. package/dist/hosting/memorySessions.js.map +1 -1
  181. package/dist/hosting/nodeHost.js +8 -0
  182. package/dist/hosting/nodeHost.js.map +1 -1
  183. package/dist/hosting/sessionWire.js +100 -0
  184. package/dist/hosting/sessionWire.js.map +1 -0
  185. package/dist/hosting/sqliteSessions.js +121 -4
  186. package/dist/hosting/sqliteSessions.js.map +1 -1
  187. package/dist/hosting/standingAgent.js +297 -6
  188. package/dist/hosting/standingAgent.js.map +1 -1
  189. package/dist/hosting/types.js.map +1 -1
  190. package/dist/hosting/wireOps.js +65 -0
  191. package/dist/hosting/wireOps.js.map +1 -0
  192. package/dist/identity.js +9 -1
  193. package/dist/identity.js.map +1 -1
  194. package/dist/index.js +30 -13
  195. package/dist/index.js.map +1 -1
  196. package/dist/lib/injection-engine/factories/defineSkill.js +13 -0
  197. package/dist/lib/injection-engine/factories/defineSkill.js.map +1 -1
  198. package/dist/lib/injection-engine/index.js +10 -1
  199. package/dist/lib/injection-engine/index.js.map +1 -1
  200. package/dist/lib/injection-engine/skillGraph.js +9 -1
  201. package/dist/lib/injection-engine/skillGraph.js.map +1 -1
  202. package/dist/lib/injection-engine/skillGraphCheckup.js.map +1 -1
  203. package/dist/lib/injection-engine/skillSteps.js +5 -0
  204. package/dist/lib/injection-engine/skillSteps.js.map +1 -1
  205. package/dist/lib/injection-engine/skillVocabulary.js +224 -0
  206. package/dist/lib/injection-engine/skillVocabulary.js.map +1 -0
  207. package/dist/types/adapters/code/local.d.ts +16 -0
  208. package/dist/types/adapters/code/local.d.ts.map +1 -1
  209. package/dist/types/adapters/hosting/agentcore.d.ts.map +1 -1
  210. package/dist/types/adapters/identity/jwks.d.ts +125 -0
  211. package/dist/types/adapters/identity/jwks.d.ts.map +1 -0
  212. package/dist/types/adapters/types.d.ts +86 -0
  213. package/dist/types/adapters/types.d.ts.map +1 -1
  214. package/dist/types/artifacts/fileArtifacts.d.ts +13 -1
  215. package/dist/types/artifacts/fileArtifacts.d.ts.map +1 -1
  216. package/dist/types/artifacts/gcsArtifacts.d.ts +143 -0
  217. package/dist/types/artifacts/gcsArtifacts.d.ts.map +1 -0
  218. package/dist/types/artifacts/index.d.ts +5 -1
  219. package/dist/types/artifacts/index.d.ts.map +1 -1
  220. package/dist/types/artifacts/objectStore.d.ts +167 -0
  221. package/dist/types/artifacts/objectStore.d.ts.map +1 -0
  222. package/dist/types/artifacts/payload.d.ts +36 -4
  223. package/dist/types/artifacts/payload.d.ts.map +1 -1
  224. package/dist/types/artifacts/recordingArtifact.d.ts +77 -0
  225. package/dist/types/artifacts/recordingArtifact.d.ts.map +1 -0
  226. package/dist/types/artifacts/s3Artifacts.d.ts +150 -0
  227. package/dist/types/artifacts/s3Artifacts.d.ts.map +1 -0
  228. package/dist/types/artifacts/scopePath.d.ts +51 -0
  229. package/dist/types/artifacts/scopePath.d.ts.map +1 -0
  230. package/dist/types/artifacts/streaming.d.ts +83 -0
  231. package/dist/types/artifacts/streaming.d.ts.map +1 -0
  232. package/dist/types/artifacts/types.d.ts +71 -5
  233. package/dist/types/artifacts/types.d.ts.map +1 -1
  234. package/dist/types/core/Agent.d.ts +66 -2
  235. package/dist/types/core/Agent.d.ts.map +1 -1
  236. package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
  237. package/dist/types/core/agent/repeatedCall.d.ts +151 -0
  238. package/dist/types/core/agent/repeatedCall.d.ts.map +1 -0
  239. package/dist/types/core/agent/stages/toolCalls.d.ts +12 -0
  240. package/dist/types/core/agent/stages/toolCalls.d.ts.map +1 -1
  241. package/dist/types/core/agent/types.d.ts +82 -0
  242. package/dist/types/core/agent/types.d.ts.map +1 -1
  243. package/dist/types/core/codeRunnerTool.d.ts +31 -0
  244. package/dist/types/core/codeRunnerTool.d.ts.map +1 -1
  245. package/dist/types/events/payloads.d.ts +22 -0
  246. package/dist/types/events/payloads.d.ts.map +1 -1
  247. package/dist/types/events/registry.d.ts +3 -1
  248. package/dist/types/events/registry.d.ts.map +1 -1
  249. package/dist/types/hosting/admission.d.ts +181 -0
  250. package/dist/types/hosting/admission.d.ts.map +1 -0
  251. package/dist/types/hosting/artifactWire.d.ts +8 -5
  252. package/dist/types/hosting/artifactWire.d.ts.map +1 -1
  253. package/dist/types/hosting/envelope.d.ts +34 -0
  254. package/dist/types/hosting/envelope.d.ts.map +1 -1
  255. package/dist/types/hosting/errors.d.ts +131 -0
  256. package/dist/types/hosting/errors.d.ts.map +1 -1
  257. package/dist/types/hosting/httpHost.d.ts +21 -0
  258. package/dist/types/hosting/httpHost.d.ts.map +1 -1
  259. package/dist/types/hosting/identityVerification.d.ts +155 -0
  260. package/dist/types/hosting/identityVerification.d.ts.map +1 -0
  261. package/dist/types/hosting/index.d.ts +12 -3
  262. package/dist/types/hosting/index.d.ts.map +1 -1
  263. package/dist/types/hosting/memorySessions.d.ts +9 -0
  264. package/dist/types/hosting/memorySessions.d.ts.map +1 -1
  265. package/dist/types/hosting/nodeHost.d.ts.map +1 -1
  266. package/dist/types/hosting/sessionWire.d.ts +127 -0
  267. package/dist/types/hosting/sessionWire.d.ts.map +1 -0
  268. package/dist/types/hosting/sqliteSessions.d.ts.map +1 -1
  269. package/dist/types/hosting/standingAgent.d.ts.map +1 -1
  270. package/dist/types/hosting/types.d.ts +166 -6
  271. package/dist/types/hosting/types.d.ts.map +1 -1
  272. package/dist/types/hosting/wireOps.d.ts +53 -0
  273. package/dist/types/hosting/wireOps.d.ts.map +1 -0
  274. package/dist/types/identity.d.ts +1 -0
  275. package/dist/types/identity.d.ts.map +1 -1
  276. package/dist/types/index.d.ts +3 -2
  277. package/dist/types/index.d.ts.map +1 -1
  278. package/dist/types/lib/injection-engine/factories/defineSkill.d.ts +27 -0
  279. package/dist/types/lib/injection-engine/factories/defineSkill.d.ts.map +1 -1
  280. package/dist/types/lib/injection-engine/index.d.ts +1 -0
  281. package/dist/types/lib/injection-engine/index.d.ts.map +1 -1
  282. package/dist/types/lib/injection-engine/skillGraph.d.ts.map +1 -1
  283. package/dist/types/lib/injection-engine/skillGraphCheckup.d.ts +1 -1
  284. package/dist/types/lib/injection-engine/skillGraphCheckup.d.ts.map +1 -1
  285. package/dist/types/lib/injection-engine/skillSteps.d.ts +16 -0
  286. package/dist/types/lib/injection-engine/skillSteps.d.ts.map +1 -1
  287. package/dist/types/lib/injection-engine/skillVocabulary.d.ts +84 -0
  288. package/dist/types/lib/injection-engine/skillVocabulary.d.ts.map +1 -0
  289. package/package.json +15 -1
@@ -0,0 +1,264 @@
1
+ "use strict";
2
+ /**
3
+ * artifacts/objectStore — the half every REMOTE OBJECT adapter shares.
4
+ *
5
+ * Two adapters put artifacts in somebody else's bucket. They speak different
6
+ * SDKs and dispatch different operations, and that is exactly where a vendor
7
+ * belongs — but the laws they follow must not fork, so the laws live here:
8
+ *
9
+ * 1. **The payload is the object body, and it is the CANONICAL BYTES** —
10
+ * the same bytes `meta.bytes` counts and a digest covers. Not a JSON
11
+ * envelope wrapping base64: a stored report should be downloadable with
12
+ * the vendor's own console and be the report. That choice is also what
13
+ * makes `getStream` possible at all — a body you have to parse is a body
14
+ * you cannot stream.
15
+ * 2. **The meta rides as ONE object-metadata entry** ({@link ARTIFACT_META_KEY}),
16
+ * an ASCII-safe JSON envelope. One key, one truth: a "helpful" second
17
+ * copy of `kind` in a sibling field is a second thing that can disagree.
18
+ * ASCII because user metadata travels as an HTTP header on at least one
19
+ * of these services — a label with an em-dash in it must not be
20
+ * mangled at the transport — and JSON-with-escapes rather than base64
21
+ * because an operator reading the console should be able to SEE what the
22
+ * ticket says.
23
+ * 3. **The metadata budget is checked at put and REFUSED by name.** Both
24
+ * services cap user metadata (the caps differ; each adapter states its
25
+ * own). A refusal that names the field to shorten beats a vendor's
26
+ * "MetadataTooLarge" at document 400, and beats silent truncation
27
+ * always.
28
+ * 4. **Missing means null; unreadable means an error.** A 404 is the
29
+ * port's deliberate "no data" ambiguity — but only when the call ASKED
30
+ * ABOUT ONE OBJECT. A write and a listing do not ask that question, so a
31
+ * 404 from one of them is the service saying something else entirely (the
32
+ * bucket does not exist, the endpoint is wrong); nobody downstream turns
33
+ * it into `null`, so letting it past the sanitizer hands the caller the
34
+ * SDK's own text — which contains the object key. That is what
35
+ * {@link NotFoundMeaning} makes each call site declare, and why the
36
+ * default is the safe one. Anything else — denied, throttled, a network
37
+ * failure — is NOT "no data" either, and answering `null` for it would
38
+ * report an empty scope over objects that exist. Each adapter maps its
39
+ * own SDK's missing-object shape; everything else raises through
40
+ * {@link objectSdkFailure}.
41
+ * 5. **Listings order by the SERVICE's own creation time**, which comes back
42
+ * free on a listing, and page by offset over that sorted list. The port
43
+ * promises newest-first ACROSS pages; a bucket's key order is
44
+ * lexicographic, so a cursor that was the service's own continuation
45
+ * token would page in the wrong order and call it paging.
46
+ *
47
+ * Nothing in this file imports an SDK, names a vendor, or knows a wire
48
+ * format. It is the part of an object adapter that can be unit-tested with
49
+ * nothing but strings.
50
+ */
51
+ Object.defineProperty(exports, "__esModule", { value: true });
52
+ exports.assertBucketOption = exports.decodeOffsetCursor = exports.pageObjectListing = exports.objectFailurePolicy = exports.objectSdkFailure = exports.isExpiredMeta = exports.readMetadataEntry = exports.decodeArtifactMetaValue = exports.encodeArtifactMetaValue = exports.ARTIFACT_META_KEY = void 0;
53
+ const naming_js_1 = require("./naming.js");
54
+ const types_js_1 = require("./types.js");
55
+ /** The single object-metadata key that carries the ticket. */
56
+ exports.ARTIFACT_META_KEY = 'af-artifact';
57
+ /** Envelope version. Bumped only for a change an older reader could not
58
+ * survive; a newer number is refused, never half-read. */
59
+ const META_FORMAT = 1;
60
+ /**
61
+ * Every non-ASCII character as a `\uXXXX` escape, so the JSON is pure ASCII
62
+ * and survives a transport that only promises US-ASCII. `JSON.parse` reverses
63
+ * it exactly — the escape is part of JSON, not a private encoding.
64
+ */
65
+ function asciiJson(value) {
66
+ return JSON.stringify(value).replace(/[\u007f-\uffff]/g, (char) => {
67
+ const code = char.charCodeAt(0).toString(16).padStart(4, '0');
68
+ return `\\u${code}`;
69
+ });
70
+ }
71
+ /**
72
+ * Encode a ticket for the object's metadata, refusing one that will not fit.
73
+ *
74
+ * @param meta the minted ticket.
75
+ * @param shape how the payload must be rebuilt from the body's bytes.
76
+ * @param budget the service's user-metadata cap, in bytes.
77
+ * @param adapter the factory name, for the refusal.
78
+ * @throws InvalidArtifactError when the encoded ticket exceeds the budget —
79
+ * naming the fields that are big enough to be the reason.
80
+ */
81
+ function encodeArtifactMetaValue(meta, shape, budget, adapter) {
82
+ const envelope = { v: META_FORMAT, shape, meta };
83
+ const value = asciiJson(envelope);
84
+ // The key travels with the value; both count against the service's cap.
85
+ const size = exports.ARTIFACT_META_KEY.length + value.length;
86
+ if (size > budget) {
87
+ const suspects = [];
88
+ if (meta.label !== undefined && meta.label.length > 64) {
89
+ suspects.push(`label (${meta.label.length} chars)`);
90
+ }
91
+ if (meta.parentRefs !== undefined && meta.parentRefs.length > 4) {
92
+ suspects.push(`parentRefs (${meta.parentRefs.length} refs)`);
93
+ }
94
+ if (meta.kind.length > 64)
95
+ suspects.push(`kind (${meta.kind.length} chars)`);
96
+ throw new types_js_1.InvalidArtifactError(`${adapter}: the ticket does not fit this service's object-metadata budget ` +
97
+ `(${size} bytes encoded, budget ${budget}). The ticket travels AS object metadata, so ` +
98
+ `the payload size is irrelevant here — the description is what is too long` +
99
+ (suspects.length > 0 ? `; the length is in ${suspects.join(' and ')}` : '') +
100
+ `. Shorten the label, carry fewer parentRefs, or move the long prose into the payload ` +
101
+ `where size is what this store is for.`);
102
+ }
103
+ return value;
104
+ }
105
+ exports.encodeArtifactMetaValue = encodeArtifactMetaValue;
106
+ /**
107
+ * Read a ticket back off an object's metadata.
108
+ *
109
+ * `undefined` for anything this runtime must not interpret: no entry (not
110
+ * ours — a foreign object in a shared bucket is left alone), unparseable, a
111
+ * newer envelope version, or a ref that is not a minted ref. Refusing to
112
+ * interpret is the point: a half-read ticket would be a confident description
113
+ * of the wrong thing.
114
+ */
115
+ function decodeArtifactMetaValue(value) {
116
+ if (typeof value !== 'string' || value === '')
117
+ return undefined;
118
+ let parsed;
119
+ try {
120
+ parsed = JSON.parse(value);
121
+ }
122
+ catch {
123
+ return undefined;
124
+ }
125
+ const envelope = parsed;
126
+ if (envelope === null || typeof envelope !== 'object')
127
+ return undefined;
128
+ if (typeof envelope.v !== 'number' || envelope.v > META_FORMAT)
129
+ return undefined;
130
+ const meta = envelope.meta;
131
+ if (meta === undefined || !(0, naming_js_1.isArtifactRef)(meta.ref))
132
+ return undefined;
133
+ const shape = envelope.shape;
134
+ if (shape !== 'text' && shape !== 'binary' && shape !== 'json')
135
+ return undefined;
136
+ return { meta: meta, shape };
137
+ }
138
+ exports.decodeArtifactMetaValue = decodeArtifactMetaValue;
139
+ /** Case-insensitive lookup in a metadata bag. At least one of these services
140
+ * lower-cases user-metadata keys in transit, so the key written and the key
141
+ * read back are not guaranteed to be the same string. */
142
+ function readMetadataEntry(bag, key) {
143
+ if (bag === undefined || bag === null)
144
+ return undefined;
145
+ const direct = bag[key];
146
+ if (direct !== undefined)
147
+ return direct;
148
+ const wanted = key.toLowerCase();
149
+ for (const [name, value] of Object.entries(bag)) {
150
+ if (name.toLowerCase() === wanted)
151
+ return value;
152
+ }
153
+ return undefined;
154
+ }
155
+ exports.readMetadataEntry = readMetadataEntry;
156
+ /** Has the calendar passed this ticket? The one expiry predicate both object
157
+ * adapters use, so "expired" cannot mean two things. */
158
+ function isExpiredMeta(meta, now) {
159
+ return meta.expiresAt !== undefined && meta.expiresAt <= now;
160
+ }
161
+ exports.isExpiredMeta = isExpiredMeta;
162
+ /**
163
+ * Re-raise a failed SDK call WITHOUT its text (the `sdkFailure` law, applied
164
+ * to object storage).
165
+ *
166
+ * A cloud SDK reports transport and validation failures by echoing request
167
+ * detail into the message: the bucket, the KEY — which here contains the
168
+ * tenant, the principal and the conversation id — and sometimes a signed URL
169
+ * or a header the request carried. This library then hands that string to the
170
+ * LLM as a tool result, puts it on the commit log, and ships it to every sink
171
+ * attached. One echo and the scope tuple is in the conversation.
172
+ *
173
+ * So the text does not come through. What does is the part that is both safe
174
+ * and actionable: which operation failed, the exception's NAME, and the HTTP
175
+ * status. The original is deliberately NOT attached as `cause` — a cause
176
+ * travels into every serializer that walks own properties, which would undo
177
+ * all of this in one `JSON.stringify`.
178
+ */
179
+ function objectSdkFailure(adapter, operation, err) {
180
+ const e = err;
181
+ const name = typeof e?.name === 'string' && e.name.length > 0 ? e.name : 'an unnamed failure';
182
+ const status = typeof e?.$metadata?.httpStatusCode === 'number'
183
+ ? e.$metadata.httpStatusCode
184
+ : typeof e?.code === 'number'
185
+ ? e.code
186
+ : undefined;
187
+ return new Error(`[artifacts] ${adapter}: ${operation} failed — ${name}` +
188
+ (status !== undefined ? ` (HTTP ${status})` : '') +
189
+ `.\n The SDK's own message is withheld: object-storage errors echo the bucket and the ` +
190
+ `object KEY, and the key carries this run's tenant/principal/conversation. Check the ` +
191
+ `service's own logs for the full exception. This is not "no data" — a missing object ` +
192
+ `answers null; this call did not get an answer at all.`);
193
+ }
194
+ exports.objectSdkFailure = objectSdkFailure;
195
+ /**
196
+ * The one gate every object adapter runs its SDK failures through.
197
+ *
198
+ * Returns what to throw — the sanitized error for anything the caller is not
199
+ * standing by to interpret, the original ONLY for a genuine missing object at
200
+ * a call site that declared it asks about one, and our own refusals verbatim
201
+ * (an {@link InvalidArtifactError} is this library's sentence, already written
202
+ * for a human, and re-wrapping it would replace a teaching refusal with a
203
+ * transport complaint).
204
+ *
205
+ * Built once per adapter so the vendor's not-found detection is bound in one
206
+ * place: two call sites in the same adapter cannot end up disagreeing about
207
+ * what "missing" looks like.
208
+ *
209
+ * @param adapter the factory name, for the message.
210
+ * @param isMissingObject the adapter's own reading of its SDK's
211
+ * "no such object" — the one genuinely per-vendor part.
212
+ */
213
+ function objectFailurePolicy(adapter, isMissingObject) {
214
+ return (operation, err, meaning) => {
215
+ if (err instanceof types_js_1.InvalidArtifactError)
216
+ return err;
217
+ if (meaning === 'missing-object' && isMissingObject(err))
218
+ return err;
219
+ return objectSdkFailure(adapter, operation, err);
220
+ };
221
+ }
222
+ exports.objectFailurePolicy = objectFailurePolicy;
223
+ /**
224
+ * The port's paging law over a scope's rows: newest first, offset cursor.
225
+ *
226
+ * Sorted by the SERVICE's creation time (falling back to the ticket's own
227
+ * `createdAt` when a listing did not carry one), ties broken by ref so two
228
+ * objects written in the same millisecond still page deterministically.
229
+ */
230
+ function pageObjectListing(rows, options) {
231
+ const sorted = [...rows].sort((a, b) => b.serviceCreatedAt - a.serviceCreatedAt || (a.meta.ref < b.meta.ref ? -1 : 1));
232
+ const offset = decodeOffsetCursor(options?.cursor);
233
+ const limit = Math.max(1, Math.floor(options?.limit ?? 50));
234
+ const page = sorted.slice(offset, offset + limit);
235
+ const nextOffset = offset + page.length;
236
+ return {
237
+ artifacts: page.map((row) => row.meta),
238
+ ...(nextOffset < sorted.length && { cursor: String(nextOffset) }),
239
+ };
240
+ }
241
+ exports.pageObjectListing = pageObjectListing;
242
+ /** The offset a cursor names. Total: a cursor this store did not mint reads
243
+ * as "start at the beginning" rather than as an error — a caller cannot
244
+ * learn anything about another scope by guessing one. */
245
+ function decodeOffsetCursor(cursor) {
246
+ if (cursor === undefined)
247
+ return 0;
248
+ const parsed = Number(cursor);
249
+ return Number.isFinite(parsed) && parsed >= 0 ? Math.floor(parsed) : 0;
250
+ }
251
+ exports.decodeOffsetCursor = decodeOffsetCursor;
252
+ /** Validate a bucket name option at construction — the same shape of refusal
253
+ * every adapter here gives for a missing required option. */
254
+ function assertBucketOption(adapter, option, value) {
255
+ if (typeof value !== 'string' || value.trim() === '') {
256
+ throw new TypeError(`[artifacts] ${adapter}({ ${option}: ${JSON.stringify(value)} }) names no bucket. ` +
257
+ `Give it the name of a bucket that already exists — this library never creates one: ` +
258
+ `a bucket carries region, lifecycle, encryption and access decisions that belong to ` +
259
+ `your infrastructure, not to a call in an agent.`);
260
+ }
261
+ return value;
262
+ }
263
+ exports.assertBucketOption = assertBucketOption;
264
+ //# sourceMappingURL=objectStore.js.map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AC9D,SAAgB,kBAAkB,CAAC,OAAe,EAAE,MAAc,EAAE,KAAc;IAChF,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACrD,MAAM,IAAI,SAAS,CACjB,eAAe,OAAO,MAAM,MAAM,KAAK,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,uBAAuB;YACjF,qFAAqF;YACrF,qFAAqF;YACrF,iDAAiD,CACpD,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAVD,gDAUC"}
@@ -23,7 +23,7 @@
23
23
  * a claim check exists to prevent.
24
24
  */
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.decodeArtifactData = exports.encodeArtifactData = exports.computeArtifactDigest = exports.measureArtifactBytes = exports.canonicalPayloadBytes = void 0;
26
+ exports.decodeArtifactData = exports.encodeArtifactData = exports.computeArtifactDigest = exports.decodeCanonicalPayload = exports.payloadShapeOf = exports.measureArtifactBytes = exports.canonicalPayloadBytes = void 0;
27
27
  const types_js_1 = require("./types.js");
28
28
  const textEncoder = new TextEncoder();
29
29
  const textDecoder = new TextDecoder();
@@ -59,6 +59,38 @@ function measureArtifactBytes(data) {
59
59
  return canonicalPayloadBytes(data).byteLength;
60
60
  }
61
61
  exports.measureArtifactBytes = measureArtifactBytes;
62
+ /** The shape a payload will be stored under. Total: everything that is not a
63
+ * string or a `Uint8Array` rides as JSON (and is refused at measure/encode if
64
+ * JSON cannot carry it). */
65
+ function payloadShapeOf(data) {
66
+ if (data instanceof Uint8Array)
67
+ return 'binary';
68
+ if (typeof data === 'string')
69
+ return 'text';
70
+ return 'json';
71
+ }
72
+ exports.payloadShapeOf = payloadShapeOf;
73
+ /**
74
+ * Rebuild a payload from its CANONICAL BYTES and its shape — the read half of
75
+ * `canonicalPayloadBytes`, for stores that hold the bytes themselves (an
76
+ * object body, a stream) rather than the text envelope.
77
+ *
78
+ * Round-trip law: `decodeCanonicalPayload(payloadShapeOf(x),
79
+ * canonicalPayloadBytes(x))` equals `x` for every payload this library
80
+ * accepts — which is what lets `bytes`, the digest, and the stored object all
81
+ * be the same bytes in every adapter.
82
+ */
83
+ function decodeCanonicalPayload(shape, bytes) {
84
+ switch (shape) {
85
+ case 'text':
86
+ return textDecoder.decode(bytes);
87
+ case 'binary':
88
+ return bytes;
89
+ case 'json':
90
+ return JSON.parse(textDecoder.decode(bytes));
91
+ }
92
+ }
93
+ exports.decodeCanonicalPayload = decodeCanonicalPayload;
62
94
  /** `sha-256:<hex>` over the canonical bytes. */
63
95
  async function computeArtifactDigest(data) {
64
96
  const bytes = canonicalPayloadBytes(data);
@@ -82,7 +114,10 @@ function encodeArtifactData(data) {
82
114
  return { shape: 'json', value: textDecoder.decode(canonicalPayloadBytes(data)) };
83
115
  }
84
116
  exports.encodeArtifactData = encodeArtifactData;
85
- /** Decode what {@link encodeArtifactData} wrote. Total over its own output. */
117
+ /** Decode what {@link encodeArtifactData} wrote. Total over its own output;
118
+ * an `'external'` envelope is the one thing it refuses, by name — the bytes
119
+ * live beside the envelope and only the adapter that wrote them can reach
120
+ * them. */
86
121
  function decodeArtifactData(encoded) {
87
122
  switch (encoded.shape) {
88
123
  case 'text':
@@ -91,6 +126,10 @@ function decodeArtifactData(encoded) {
91
126
  return fromBase64(encoded.value);
92
127
  case 'json':
93
128
  return JSON.parse(encoded.value);
129
+ case 'external':
130
+ throw new types_js_1.InvalidArtifactError(`the payload was streamed and lives beside the envelope ('${encoded.value}'), not in ` +
131
+ `it. Only the store that wrote it can read it back — read this artifact through ` +
132
+ `that store's get()/getStream(), never by decoding the envelope alone.`);
94
133
  }
95
134
  }
96
135
  exports.decodeArtifactData = decodeArtifactData;
@@ -1 +1 @@
1
- {"version":3,"file":"payload.js","sourceRoot":"","sources":["../../src/artifacts/payload.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH,yCAAkD;AAElD,MAAM,WAA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AO,CAAC,KAAK,aAAa;gBACpF,iFAAiF;gBACjF,uEAAuE,CAC1E,CAAC;IACN,CAAC;AACH,CAAC;AAfD,gDAeC;AAED,wEAAwE;AACxE,SAAS,QAAQ,CAAC,KAAiB;IACjC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,MAAM,KAAK,GAAG,MAAM,CAAC;IACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC;QAC7C,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;AACtB,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3B,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACxE,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ /**
3
+ * artifacts/recordingArtifact — a finished run, checked into the store like any
4
+ * other payload.
5
+ *
6
+ * `recordRun` has produced `{ snapshot, events, structure }` since 8.x and the
7
+ * lens family has consumed exactly that shape since. What nobody shipped was
8
+ * the boring half in between: WHERE a completed run's recording goes so a
9
+ * screen can ask for it later. Every deployment that wanted the Lens over the
10
+ * wire wrote the same twenty lines — record the run, serialize it, put it
11
+ * somewhere with a key, hand the key to the frontend — and each one wrote a
12
+ * slightly different, slightly wrong version of retention and scoping.
13
+ *
14
+ * All four of those problems already have an answer in this package: the
15
+ * artifact store IS a keyed payload store with scope isolation, retention and
16
+ * a read-only wire. So a recording is simply an artifact of kind
17
+ * `'recording/run'`, and the wire ops that already redeem claim tickets serve
18
+ * it with **zero new operations** — `{ op: 'artifact-get', ref }` returns the
19
+ * recording, and the frontend does what it always did with the bytes.
20
+ *
21
+ * ── Why the payload is TEXT and not an object ───────────────────────────────
22
+ * The recording is minted as its JSON text — the same bytes
23
+ * `JSON.stringify(recorder.toRecording())` produces, which is precisely what
24
+ * `observeRecording(JSON.parse(text))` consumes on the viewer side. Two
25
+ * reasons, and both are about not lying:
26
+ *
27
+ * • `recordRun` states that `snapshot` and `structure` are the runner's OWN
28
+ * objects, held by reference. An in-process store handed those would keep
29
+ * a live view into a finished run's state — the artifact would silently
30
+ * change if anything touched it. Serializing detaches it, once, here.
31
+ * • A recording that cannot be serialized cannot be delivered over any wire
32
+ * either, so failing at the mint is failing at the honest moment rather
33
+ * than at whatever reads it next.
34
+ */
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.recordingPutInput = exports.UnserializableRecordingError = exports.RECORDING_MEDIA_TYPE = exports.RECORDING_ARTIFACT_KIND = void 0;
37
+ /** The consumer vocabulary a run recording is stored under. One kind, exact
38
+ * match — the same rule every `wants` declaration is judged by. */
39
+ exports.RECORDING_ARTIFACT_KIND = 'recording/run';
40
+ /** The media type a recording is minted with. */
41
+ exports.RECORDING_MEDIA_TYPE = 'application/json';
42
+ /**
43
+ * Raised when a recording could not be turned into bytes.
44
+ *
45
+ * Its own class because the CALLER's answer differs from every other mint
46
+ * failure: a full store is retryable and a cyclic snapshot is not.
47
+ */
48
+ class UnserializableRecordingError extends Error {
49
+ code = 'ERR_UNSERIALIZABLE_RECORDING';
50
+ constructor(detail) {
51
+ super(`[artifacts] the run recording could not be serialized (${detail}), so it was not ` +
52
+ `stored. A recording that JSON cannot carry could not be delivered over any wire ` +
53
+ `either — this fails at the mint rather than at whatever tried to read it. The run ` +
54
+ `itself is unaffected: its answer was already composed before this was attempted.`);
55
+ this.name = 'UnserializableRecordingError';
56
+ }
57
+ }
58
+ exports.UnserializableRecordingError = UnserializableRecordingError;
59
+ /**
60
+ * Turn one finished recording into the `put` input that stores it.
61
+ *
62
+ * Pure: no store, no events, no agent. The caller owns WHEN this happens (after
63
+ * the answer is composed) and what to do when it fails.
64
+ *
65
+ * @throws UnserializableRecordingError when the recording cannot be
66
+ * JSON-serialized — a cyclic object in a snapshot, most likely.
67
+ */
68
+ function recordingPutInput(recording, facts = {}) {
69
+ let text;
70
+ try {
71
+ text = JSON.stringify(recording) ?? '';
72
+ }
73
+ catch (err) {
74
+ throw new UnserializableRecordingError(err instanceof Error ? err.message : String(err));
75
+ }
76
+ if (text === '') {
77
+ throw new UnserializableRecordingError('it serializes to nothing');
78
+ }
79
+ return {
80
+ kind: exports.RECORDING_ARTIFACT_KIND,
81
+ mediaType: exports.RECORDING_MEDIA_TYPE,
82
+ data: text,
83
+ label: facts.label ?? (facts.runId !== undefined ? `run ${facts.runId}` : 'run recording'),
84
+ ...(facts.runId !== undefined && { origin: { runId: facts.runId } }),
85
+ };
86
+ }
87
+ exports.recordingPutInput = recordingPutInput;
88
+ //# sourceMappingURL=recordingArtifact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recordingArtifact.js","sourceRoot":"","sources":["../../src/artifacts/recordingArtifact.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;;;AAIH;oEACoE;AACvD,QAAA,uBAAuB,GAAG,eAAe,CAAC;AAEvD,iDAAiD;AACpC,QAAA,oBAAoB,GAAG,kBAAkB,CAAC;AAoBvD;;;;;GAKG;AACH,MAAa,4BAA6B,SAAQ,KAAK;IAC5C,IAAI,GAAG,8BAAuC,CAAC;IAExD,YAAY,MAAc;QACxB,KAAK,CACH,0DAA0D,MAAM,mBAAmB;YACjF,kFAAkF;YAClF,oFAAoF;YACpF,kFAAkF,CACrF,CA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