@laserdata/laser-sdk 0.0.1-rc.21 → 0.0.1-rc.22

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 (434) hide show
  1. package/README.md +1 -1
  2. package/dist/agent/agdx.d.ts +55 -0
  3. package/dist/agent/agdx.d.ts.map +1 -0
  4. package/dist/agent/agdx.js +447 -0
  5. package/dist/agent/agdx.js.map +1 -0
  6. package/dist/agent/assembler.d.ts +29 -0
  7. package/dist/agent/assembler.d.ts.map +1 -0
  8. package/dist/agent/assembler.js +69 -0
  9. package/dist/agent/assembler.js.map +1 -0
  10. package/dist/agent/builder.d.ts +114 -0
  11. package/dist/agent/builder.d.ts.map +1 -0
  12. package/dist/agent/builder.js +334 -0
  13. package/dist/agent/builder.js.map +1 -0
  14. package/dist/agent/context.d.ts +68 -0
  15. package/dist/agent/context.d.ts.map +1 -0
  16. package/dist/agent/context.js +212 -0
  17. package/dist/agent/context.js.map +1 -0
  18. package/dist/agent/contract.d.ts +70 -0
  19. package/dist/agent/contract.d.ts.map +1 -0
  20. package/dist/agent/contract.js +275 -0
  21. package/dist/agent/contract.js.map +1 -0
  22. package/dist/agent/registry.d.ts +76 -0
  23. package/dist/agent/registry.d.ts.map +1 -0
  24. package/dist/agent/registry.js +286 -0
  25. package/dist/agent/registry.js.map +1 -0
  26. package/dist/agent/reliable-consumer.d.ts +126 -0
  27. package/dist/agent/reliable-consumer.d.ts.map +1 -0
  28. package/dist/agent/reliable-consumer.js +551 -0
  29. package/dist/agent/reliable-consumer.js.map +1 -0
  30. package/dist/agent/replies.d.ts +28 -0
  31. package/dist/agent/replies.d.ts.map +1 -0
  32. package/dist/agent/replies.js +175 -0
  33. package/dist/agent/replies.js.map +1 -0
  34. package/dist/agent/router.d.ts +72 -0
  35. package/dist/agent/router.d.ts.map +1 -0
  36. package/dist/agent/router.js +172 -0
  37. package/dist/agent/router.js.map +1 -0
  38. package/dist/agent/scope.d.ts +16 -0
  39. package/dist/agent/scope.d.ts.map +1 -0
  40. package/dist/agent/scope.js +34 -0
  41. package/dist/agent/scope.js.map +1 -0
  42. package/dist/agent/workflow.d.ts +85 -0
  43. package/dist/agent/workflow.d.ts.map +1 -0
  44. package/dist/agent/workflow.js +416 -0
  45. package/dist/agent/workflow.js.map +1 -0
  46. package/dist/blob.d.ts +12 -0
  47. package/dist/blob.d.ts.map +1 -0
  48. package/dist/blob.js +34 -0
  49. package/dist/blob.js.map +1 -0
  50. package/dist/bridges/a2a.d.ts +89 -0
  51. package/dist/bridges/a2a.d.ts.map +1 -0
  52. package/dist/bridges/a2a.js +244 -0
  53. package/dist/bridges/a2a.js.map +1 -0
  54. package/dist/bridges/agui.d.ts +66 -0
  55. package/dist/bridges/agui.d.ts.map +1 -0
  56. package/dist/bridges/agui.js +335 -0
  57. package/dist/bridges/agui.js.map +1 -0
  58. package/dist/bridges/edge-auth.d.ts +16 -0
  59. package/dist/bridges/edge-auth.d.ts.map +1 -0
  60. package/dist/bridges/edge-auth.js +19 -0
  61. package/dist/bridges/edge-auth.js.map +1 -0
  62. package/dist/bridges/hops.d.ts +9 -0
  63. package/dist/bridges/hops.d.ts.map +1 -0
  64. package/dist/bridges/hops.js +16 -0
  65. package/dist/bridges/hops.js.map +1 -0
  66. package/dist/bridges/mcp.d.ts +79 -0
  67. package/dist/bridges/mcp.d.ts.map +1 -0
  68. package/dist/bridges/mcp.js +248 -0
  69. package/dist/bridges/mcp.js.map +1 -0
  70. package/dist/client/bytes.d.ts +3 -0
  71. package/dist/client/bytes.d.ts.map +1 -0
  72. package/dist/client/bytes.js +9 -0
  73. package/dist/client/bytes.js.map +1 -0
  74. package/dist/client/capabilities.d.ts +36 -0
  75. package/dist/client/capabilities.d.ts.map +1 -0
  76. package/dist/client/capabilities.js +91 -0
  77. package/dist/client/capabilities.js.map +1 -0
  78. package/dist/client/errors.d.ts +178 -0
  79. package/dist/client/errors.d.ts.map +1 -0
  80. package/dist/client/errors.js +192 -0
  81. package/dist/client/errors.js.map +1 -0
  82. package/dist/client/internals.d.ts +5 -0
  83. package/dist/client/internals.d.ts.map +1 -0
  84. package/dist/client/internals.js +5 -0
  85. package/dist/client/internals.js.map +1 -0
  86. package/dist/client/laser.d.ts +238 -0
  87. package/dist/client/laser.d.ts.map +1 -0
  88. package/dist/client/laser.js +831 -0
  89. package/dist/client/laser.js.map +1 -0
  90. package/dist/client/laserdata-ca.d.ts +2 -0
  91. package/dist/client/laserdata-ca.d.ts.map +1 -0
  92. package/dist/client/laserdata-ca.js +35 -0
  93. package/dist/client/laserdata-ca.js.map +1 -0
  94. package/dist/client/managed.d.ts +6 -0
  95. package/dist/client/managed.d.ts.map +1 -0
  96. package/dist/client/managed.js +19 -0
  97. package/dist/client/managed.js.map +1 -0
  98. package/dist/context-scope.d.ts +40 -0
  99. package/dist/context-scope.d.ts.map +1 -0
  100. package/dist/context-scope.js +73 -0
  101. package/dist/context-scope.js.map +1 -0
  102. package/dist/context.d.ts +64 -0
  103. package/dist/context.d.ts.map +1 -0
  104. package/dist/context.js +149 -0
  105. package/dist/context.js.map +1 -0
  106. package/dist/conversation-state.d.ts +24 -0
  107. package/dist/conversation-state.d.ts.map +1 -0
  108. package/dist/conversation-state.js +29 -0
  109. package/dist/conversation-state.js.map +1 -0
  110. package/dist/crash-context.d.ts +11 -0
  111. package/dist/crash-context.d.ts.map +1 -0
  112. package/dist/crash-context.js +62 -0
  113. package/dist/crash-context.js.map +1 -0
  114. package/dist/full.d.ts +3 -0
  115. package/dist/full.d.ts.map +1 -0
  116. package/dist/full.js +3 -0
  117. package/dist/full.js.map +1 -0
  118. package/dist/govern.d.ts +133 -0
  119. package/dist/govern.d.ts.map +1 -0
  120. package/dist/govern.js +347 -0
  121. package/dist/govern.js.map +1 -0
  122. package/dist/iggy/apache-iggy.d.ts +173 -0
  123. package/dist/iggy/apache-iggy.d.ts.map +1 -0
  124. package/dist/iggy/apache-iggy.js +634 -0
  125. package/dist/iggy/apache-iggy.js.map +1 -0
  126. package/dist/index.d.ts +121 -0
  127. package/dist/index.d.ts.map +1 -0
  128. package/dist/index.js +64 -0
  129. package/dist/index.js.map +1 -0
  130. package/dist/intent.d.ts +75 -0
  131. package/dist/intent.d.ts.map +1 -0
  132. package/dist/intent.js +195 -0
  133. package/dist/intent.js.map +1 -0
  134. package/dist/managed/batch.d.ts +5 -0
  135. package/dist/managed/batch.d.ts.map +1 -0
  136. package/dist/managed/batch.js +32 -0
  137. package/dist/managed/batch.js.map +1 -0
  138. package/dist/managed/forks.d.ts +72 -0
  139. package/dist/managed/forks.d.ts.map +1 -0
  140. package/dist/managed/forks.js +188 -0
  141. package/dist/managed/forks.js.map +1 -0
  142. package/dist/managed/graph.d.ts +58 -0
  143. package/dist/managed/graph.d.ts.map +1 -0
  144. package/dist/managed/graph.js +176 -0
  145. package/dist/managed/graph.js.map +1 -0
  146. package/dist/managed/kv.d.ts +144 -0
  147. package/dist/managed/kv.d.ts.map +1 -0
  148. package/dist/managed/kv.js +502 -0
  149. package/dist/managed/kv.js.map +1 -0
  150. package/dist/managed/projections.d.ts +61 -0
  151. package/dist/managed/projections.d.ts.map +1 -0
  152. package/dist/managed/projections.js +191 -0
  153. package/dist/managed/projections.js.map +1 -0
  154. package/dist/managed/query.d.ts +72 -0
  155. package/dist/managed/query.d.ts.map +1 -0
  156. package/dist/managed/query.js +287 -0
  157. package/dist/managed/query.js.map +1 -0
  158. package/dist/managed/rbac.d.ts +16 -0
  159. package/dist/managed/rbac.d.ts.map +1 -0
  160. package/dist/managed/rbac.js +82 -0
  161. package/dist/managed/rbac.js.map +1 -0
  162. package/dist/managed/runs.d.ts +40 -0
  163. package/dist/managed/runs.d.ts.map +1 -0
  164. package/dist/managed/runs.js +112 -0
  165. package/dist/managed/runs.js.map +1 -0
  166. package/dist/managed/watch.d.ts +21 -0
  167. package/dist/managed/watch.d.ts.map +1 -0
  168. package/dist/managed/watch.js +73 -0
  169. package/dist/managed/watch.js.map +1 -0
  170. package/dist/memory/handle.d.ts +77 -0
  171. package/dist/memory/handle.d.ts.map +1 -0
  172. package/dist/memory/handle.js +234 -0
  173. package/dist/memory/handle.js.map +1 -0
  174. package/dist/memory/log-memory.d.ts +38 -0
  175. package/dist/memory/log-memory.d.ts.map +1 -0
  176. package/dist/memory/log-memory.js +309 -0
  177. package/dist/memory/log-memory.js.map +1 -0
  178. package/dist/memory/topic.d.ts +22 -0
  179. package/dist/memory/topic.d.ts.map +1 -0
  180. package/dist/memory/topic.js +56 -0
  181. package/dist/memory/topic.js.map +1 -0
  182. package/dist/memory/types.d.ts +108 -0
  183. package/dist/memory/types.d.ts.map +1 -0
  184. package/dist/memory/types.js +127 -0
  185. package/dist/memory/types.js.map +1 -0
  186. package/dist/memory/vector-memory.d.ts +20 -0
  187. package/dist/memory/vector-memory.d.ts.map +1 -0
  188. package/dist/memory/vector-memory.js +193 -0
  189. package/dist/memory/vector-memory.js.map +1 -0
  190. package/dist/memory.d.ts +7 -0
  191. package/dist/memory.d.ts.map +1 -0
  192. package/dist/memory.js +6 -0
  193. package/dist/memory.js.map +1 -0
  194. package/dist/observe.d.ts +10 -0
  195. package/dist/observe.d.ts.map +1 -0
  196. package/dist/observe.js +5 -0
  197. package/dist/observe.js.map +1 -0
  198. package/dist/opentelemetry.d.ts +22 -0
  199. package/dist/opentelemetry.d.ts.map +1 -0
  200. package/dist/opentelemetry.js +38 -0
  201. package/dist/opentelemetry.js.map +1 -0
  202. package/dist/provenance/agent-topic.d.ts +14 -0
  203. package/dist/provenance/agent-topic.d.ts.map +1 -0
  204. package/dist/provenance/agent-topic.js +13 -0
  205. package/dist/provenance/agent-topic.js.map +1 -0
  206. package/dist/provenance/provenance.d.ts +24 -0
  207. package/dist/provenance/provenance.d.ts.map +1 -0
  208. package/dist/provenance/provenance.js +186 -0
  209. package/dist/provenance/provenance.js.map +1 -0
  210. package/dist/provenance/session-policy.d.ts +4 -0
  211. package/dist/provenance/session-policy.d.ts.map +1 -0
  212. package/dist/provenance/session-policy.js +5 -0
  213. package/dist/provenance/session-policy.js.map +1 -0
  214. package/dist/runtime/async-once.d.ts +6 -0
  215. package/dist/runtime/async-once.d.ts.map +1 -0
  216. package/dist/runtime/async-once.js +19 -0
  217. package/dist/runtime/async-once.js.map +1 -0
  218. package/dist/runtime/clock.d.ts +14 -0
  219. package/dist/runtime/clock.d.ts.map +1 -0
  220. package/dist/runtime/clock.js +21 -0
  221. package/dist/runtime/clock.js.map +1 -0
  222. package/dist/runtime/mutex.d.ts +5 -0
  223. package/dist/runtime/mutex.d.ts.map +1 -0
  224. package/dist/runtime/mutex.js +23 -0
  225. package/dist/runtime/mutex.js.map +1 -0
  226. package/dist/runtime/ulid.d.ts +7 -0
  227. package/dist/runtime/ulid.d.ts.map +1 -0
  228. package/dist/runtime/ulid.js +17 -0
  229. package/dist/runtime/ulid.js.map +1 -0
  230. package/dist/schema-codecs.d.ts +16 -0
  231. package/dist/schema-codecs.d.ts.map +1 -0
  232. package/dist/schema-codecs.js +174 -0
  233. package/dist/schema-codecs.js.map +1 -0
  234. package/dist/signing.d.ts +63 -0
  235. package/dist/signing.d.ts.map +1 -0
  236. package/dist/signing.js +288 -0
  237. package/dist/signing.js.map +1 -0
  238. package/dist/snapshot.d.ts +24 -0
  239. package/dist/snapshot.d.ts.map +1 -0
  240. package/dist/snapshot.js +80 -0
  241. package/dist/snapshot.js.map +1 -0
  242. package/dist/state-store.d.ts +20 -0
  243. package/dist/state-store.d.ts.map +1 -0
  244. package/dist/state-store.js +70 -0
  245. package/dist/state-store.js.map +1 -0
  246. package/dist/stream/codecs.d.ts +9 -0
  247. package/dist/stream/codecs.d.ts.map +1 -0
  248. package/dist/stream/codecs.js +83 -0
  249. package/dist/stream/codecs.js.map +1 -0
  250. package/dist/stream/consumer.d.ts +50 -0
  251. package/dist/stream/consumer.d.ts.map +1 -0
  252. package/dist/stream/consumer.js +145 -0
  253. package/dist/stream/consumer.js.map +1 -0
  254. package/dist/stream/cursor.d.ts +26 -0
  255. package/dist/stream/cursor.d.ts.map +1 -0
  256. package/dist/stream/cursor.js +83 -0
  257. package/dist/stream/cursor.js.map +1 -0
  258. package/dist/stream/header-value.d.ts +18 -0
  259. package/dist/stream/header-value.d.ts.map +1 -0
  260. package/dist/stream/header-value.js +70 -0
  261. package/dist/stream/header-value.js.map +1 -0
  262. package/dist/stream/polling-strategy.d.ts +14 -0
  263. package/dist/stream/polling-strategy.d.ts.map +1 -0
  264. package/dist/stream/polling-strategy.js +2 -0
  265. package/dist/stream/polling-strategy.js.map +1 -0
  266. package/dist/stream/producer.d.ts +44 -0
  267. package/dist/stream/producer.d.ts.map +1 -0
  268. package/dist/stream/producer.js +125 -0
  269. package/dist/stream/producer.js.map +1 -0
  270. package/dist/stream/publish.d.ts +83 -0
  271. package/dist/stream/publish.d.ts.map +1 -0
  272. package/dist/stream/publish.js +287 -0
  273. package/dist/stream/publish.js.map +1 -0
  274. package/dist/stream/record.d.ts +29 -0
  275. package/dist/stream/record.d.ts.map +1 -0
  276. package/dist/stream/record.js +152 -0
  277. package/dist/stream/record.js.map +1 -0
  278. package/dist/stream/routing.d.ts +10 -0
  279. package/dist/stream/routing.d.ts.map +1 -0
  280. package/dist/stream/routing.js +2 -0
  281. package/dist/stream/routing.js.map +1 -0
  282. package/dist/stream/stream.d.ts +14 -0
  283. package/dist/stream/stream.d.ts.map +1 -0
  284. package/dist/stream/stream.js +26 -0
  285. package/dist/stream/stream.js.map +1 -0
  286. package/dist/stream/topic.d.ts +52 -0
  287. package/dist/stream/topic.d.ts.map +1 -0
  288. package/dist/stream/topic.js +181 -0
  289. package/dist/stream/topic.js.map +1 -0
  290. package/dist/stream/typed-topic.d.ts +59 -0
  291. package/dist/stream/typed-topic.d.ts.map +1 -0
  292. package/dist/stream/typed-topic.js +119 -0
  293. package/dist/stream/typed-topic.js.map +1 -0
  294. package/dist/swarm.d.ts +16 -0
  295. package/dist/swarm.d.ts.map +1 -0
  296. package/dist/swarm.js +40 -0
  297. package/dist/swarm.js.map +1 -0
  298. package/dist/testing.d.ts +16 -0
  299. package/dist/testing.d.ts.map +1 -0
  300. package/dist/testing.js +19 -0
  301. package/dist/testing.js.map +1 -0
  302. package/dist/types/ids.d.ts +48 -0
  303. package/dist/types/ids.d.ts.map +1 -0
  304. package/dist/types/ids.js +161 -0
  305. package/dist/types/ids.js.map +1 -0
  306. package/dist/wire/agent-record.d.ts +24 -0
  307. package/dist/wire/agent-record.d.ts.map +1 -0
  308. package/dist/wire/agent-record.js +99 -0
  309. package/dist/wire/agent-record.js.map +1 -0
  310. package/dist/wire/agent-workflow.d.ts +118 -0
  311. package/dist/wire/agent-workflow.d.ts.map +1 -0
  312. package/dist/wire/agent-workflow.js +290 -0
  313. package/dist/wire/agent-workflow.js.map +1 -0
  314. package/dist/wire/agent.d.ts +255 -0
  315. package/dist/wire/agent.d.ts.map +1 -0
  316. package/dist/wire/agent.js +792 -0
  317. package/dist/wire/agent.js.map +1 -0
  318. package/dist/wire/authz.d.ts +186 -0
  319. package/dist/wire/authz.d.ts.map +1 -0
  320. package/dist/wire/authz.js +545 -0
  321. package/dist/wire/authz.js.map +1 -0
  322. package/dist/wire/batch.d.ts +17 -0
  323. package/dist/wire/batch.d.ts.map +1 -0
  324. package/dist/wire/batch.js +41 -0
  325. package/dist/wire/batch.js.map +1 -0
  326. package/dist/wire/browse.d.ts +96 -0
  327. package/dist/wire/browse.d.ts.map +1 -0
  328. package/dist/wire/browse.js +201 -0
  329. package/dist/wire/browse.js.map +1 -0
  330. package/dist/wire/cbor.d.ts +35 -0
  331. package/dist/wire/cbor.d.ts.map +1 -0
  332. package/dist/wire/cbor.js +231 -0
  333. package/dist/wire/cbor.js.map +1 -0
  334. package/dist/wire/change.d.ts +12 -0
  335. package/dist/wire/change.d.ts.map +1 -0
  336. package/dist/wire/change.js +22 -0
  337. package/dist/wire/change.js.map +1 -0
  338. package/dist/wire/clients.d.ts +27 -0
  339. package/dist/wire/clients.d.ts.map +1 -0
  340. package/dist/wire/clients.js +64 -0
  341. package/dist/wire/clients.js.map +1 -0
  342. package/dist/wire/codes.d.ts +67 -0
  343. package/dist/wire/codes.d.ts.map +1 -0
  344. package/dist/wire/codes.js +67 -0
  345. package/dist/wire/codes.js.map +1 -0
  346. package/dist/wire/commands.d.ts +68 -0
  347. package/dist/wire/commands.d.ts.map +1 -0
  348. package/dist/wire/commands.js +140 -0
  349. package/dist/wire/commands.js.map +1 -0
  350. package/dist/wire/content.d.ts +17 -0
  351. package/dist/wire/content.d.ts.map +1 -0
  352. package/dist/wire/content.js +47 -0
  353. package/dist/wire/content.js.map +1 -0
  354. package/dist/wire/control.d.ts +170 -0
  355. package/dist/wire/control.d.ts.map +1 -0
  356. package/dist/wire/control.js +453 -0
  357. package/dist/wire/control.js.map +1 -0
  358. package/dist/wire/fork.d.ts +112 -0
  359. package/dist/wire/fork.d.ts.map +1 -0
  360. package/dist/wire/fork.js +280 -0
  361. package/dist/wire/fork.js.map +1 -0
  362. package/dist/wire/forward.d.ts +23 -0
  363. package/dist/wire/forward.d.ts.map +1 -0
  364. package/dist/wire/forward.js +72 -0
  365. package/dist/wire/forward.js.map +1 -0
  366. package/dist/wire/graph.d.ts +181 -0
  367. package/dist/wire/graph.d.ts.map +1 -0
  368. package/dist/wire/graph.js +554 -0
  369. package/dist/wire/graph.js.map +1 -0
  370. package/dist/wire/hashing.d.ts +2 -0
  371. package/dist/wire/hashing.d.ts.map +1 -0
  372. package/dist/wire/hashing.js +21 -0
  373. package/dist/wire/hashing.js.map +1 -0
  374. package/dist/wire/headers.d.ts +32 -0
  375. package/dist/wire/headers.d.ts.map +1 -0
  376. package/dist/wire/headers.js +32 -0
  377. package/dist/wire/headers.js.map +1 -0
  378. package/dist/wire/hello.d.ts +50 -0
  379. package/dist/wire/hello.d.ts.map +1 -0
  380. package/dist/wire/hello.js +122 -0
  381. package/dist/wire/hello.js.map +1 -0
  382. package/dist/wire/http.d.ts +95 -0
  383. package/dist/wire/http.d.ts.map +1 -0
  384. package/dist/wire/http.js +282 -0
  385. package/dist/wire/http.js.map +1 -0
  386. package/dist/wire/ids.d.ts +50 -0
  387. package/dist/wire/ids.d.ts.map +1 -0
  388. package/dist/wire/ids.js +198 -0
  389. package/dist/wire/ids.js.map +1 -0
  390. package/dist/wire/index.d.ts +32 -0
  391. package/dist/wire/index.d.ts.map +1 -0
  392. package/dist/wire/index.js +32 -0
  393. package/dist/wire/index.js.map +1 -0
  394. package/dist/wire/kv.d.ts +260 -0
  395. package/dist/wire/kv.d.ts.map +1 -0
  396. package/dist/wire/kv.js +650 -0
  397. package/dist/wire/kv.js.map +1 -0
  398. package/dist/wire/limits.d.ts +36 -0
  399. package/dist/wire/limits.d.ts.map +1 -0
  400. package/dist/wire/limits.js +36 -0
  401. package/dist/wire/limits.js.map +1 -0
  402. package/dist/wire/memory.d.ts +17 -0
  403. package/dist/wire/memory.d.ts.map +1 -0
  404. package/dist/wire/memory.js +65 -0
  405. package/dist/wire/memory.js.map +1 -0
  406. package/dist/wire/mutation.d.ts +10 -0
  407. package/dist/wire/mutation.d.ts.map +1 -0
  408. package/dist/wire/mutation.js +18 -0
  409. package/dist/wire/mutation.js.map +1 -0
  410. package/dist/wire/query.d.ts +210 -0
  411. package/dist/wire/query.d.ts.map +1 -0
  412. package/dist/wire/query.js +594 -0
  413. package/dist/wire/query.js.map +1 -0
  414. package/dist/wire/result.d.ts +25 -0
  415. package/dist/wire/result.d.ts.map +1 -0
  416. package/dist/wire/result.js +52 -0
  417. package/dist/wire/result.js.map +1 -0
  418. package/dist/wire/snapshot.d.ts +11 -0
  419. package/dist/wire/snapshot.d.ts.map +1 -0
  420. package/dist/wire/snapshot.js +50 -0
  421. package/dist/wire/snapshot.js.map +1 -0
  422. package/dist/wire/topics.d.ts +5 -0
  423. package/dist/wire/topics.d.ts.map +1 -0
  424. package/dist/wire/topics.js +5 -0
  425. package/dist/wire/topics.js.map +1 -0
  426. package/dist/wire/topology.d.ts +24 -0
  427. package/dist/wire/topology.d.ts.map +1 -0
  428. package/dist/wire/topology.js +56 -0
  429. package/dist/wire/topology.js.map +1 -0
  430. package/dist/wire/value.d.ts +21 -0
  431. package/dist/wire/value.d.ts.map +1 -0
  432. package/dist/wire/value.js +40 -0
  433. package/dist/wire/value.js.map +1 -0
  434. package/package.json +2 -1
@@ -0,0 +1,792 @@
1
+ import { CodecError, InvalidError } from "../client/errors.js";
2
+ import { expectMap, field } from "./cbor.js";
3
+ import { ContentType } from "./content.js";
4
+ import { ChannelId, ConversationId, CorrelationId, RecordId } from "./ids.js";
5
+ import { logPositionFromBytes, logPositionToBytes } from "./ids.js";
6
+ import { MAX_AGENT_STRING_BYTES, MAX_BODY_REFERENCE_BYTES, MAX_CARD_CAPABILITIES, MAX_IDEMPOTENCY_KEY_BYTES, MAX_METADATA_ENTRIES, MAX_METADATA_KEY_BYTES, MAX_METADATA_TOTAL_BYTES, MAX_METADATA_VALUE_BYTES } from "./limits.js";
7
+ import { decodeValue, encodeValue } from "./value.js";
8
+ export const AgentKind = {
9
+ Command: "command",
10
+ Response: "response",
11
+ Event: "event",
12
+ Chunk: "chunk",
13
+ Status: "status",
14
+ Error: "error"
15
+ };
16
+ const AGENT_KINDS = new Set(Object.values(AgentKind));
17
+ export function parseAgentKind(value, context) {
18
+ if (!AGENT_KINDS.has(value)) {
19
+ throw new CodecError(`\`${value}\` is not a recognized agent envelope kind`, context, "kind");
20
+ }
21
+ return value;
22
+ }
23
+ const textEncoder = new TextEncoder();
24
+ function utf8Length(value) {
25
+ return textEncoder.encode(value).length;
26
+ }
27
+ export function parseIdempotencyKey(value) {
28
+ if (value.length === 0) {
29
+ throw new InvalidError("idempotency key must not be empty");
30
+ }
31
+ const bytes = utf8Length(value);
32
+ if (bytes > MAX_IDEMPOTENCY_KEY_BYTES) {
33
+ throw new InvalidError(`idempotency key is ${String(bytes)}B, exceeds cap ${String(MAX_IDEMPOTENCY_KEY_BYTES)}B`);
34
+ }
35
+ return value;
36
+ }
37
+ export function parseAgentId(value) {
38
+ if (value.length === 0) {
39
+ throw new InvalidError("agent id must not be empty");
40
+ }
41
+ const bytes = utf8Length(value);
42
+ if (bytes > MAX_AGENT_STRING_BYTES) {
43
+ throw new InvalidError(`agent id is ${String(bytes)}B, exceeds cap ${String(MAX_AGENT_STRING_BYTES)}B`);
44
+ }
45
+ for (const char of value) {
46
+ const code = char.charCodeAt(0);
47
+ if (code < 0x20 || code === 0x7f || (code >= 0x80 && code <= 0x9f)) {
48
+ throw new InvalidError(`agent id must not contain control characters (found ${char})`);
49
+ }
50
+ }
51
+ return value;
52
+ }
53
+ export const TaskStateName = {
54
+ Submitted: 1,
55
+ Working: 2,
56
+ InputRequired: 3,
57
+ Completed: 4,
58
+ Canceled: 5,
59
+ Failed: 6,
60
+ Rejected: 7,
61
+ AuthRequired: 8,
62
+ Unknown: 9
63
+ };
64
+ const TASK_STATE_DISPLAY = {
65
+ Submitted: "submitted",
66
+ Working: "working",
67
+ InputRequired: "input-required",
68
+ Completed: "completed",
69
+ Canceled: "canceled",
70
+ Failed: "failed",
71
+ Rejected: "rejected",
72
+ AuthRequired: "auth-required",
73
+ Unknown: "unknown"
74
+ };
75
+ const TASK_STATE_NAME_BY_CODE = new Map(Object.entries(TaskStateName).map(([name, code]) => [code, name]));
76
+ const TERMINAL_TASK_STATES = new Set([
77
+ "Completed",
78
+ "Canceled",
79
+ "Failed",
80
+ "Rejected"
81
+ ]);
82
+ export function taskStateFromCode(code) {
83
+ const name = TASK_STATE_NAME_BY_CODE.get(code);
84
+ return name === undefined ? { kind: "unrecognized", code } : { kind: "known", name };
85
+ }
86
+ export function taskStateCode(state) {
87
+ return state.kind === "known" ? TaskStateName[state.name] : state.code;
88
+ }
89
+ export function taskStateDisplay(state) {
90
+ return state.kind === "known"
91
+ ? TASK_STATE_DISPLAY[state.name]
92
+ : `unrecognized-${String(state.code)}`;
93
+ }
94
+ export function taskStateIsTerminal(state) {
95
+ return state.kind === "known" && TERMINAL_TASK_STATES.has(state.name);
96
+ }
97
+ export const AgentErrorCodeName = {
98
+ InvalidRequest: 1,
99
+ Unauthorized: 2,
100
+ Unsupported: 3,
101
+ DeadlineExceeded: 4,
102
+ Cancelled: 5,
103
+ ToolFailure: 6,
104
+ Internal: 7
105
+ };
106
+ const AGENT_ERROR_NAME_BY_CODE = new Map(Object.entries(AgentErrorCodeName).map(([name, code]) => [
107
+ code,
108
+ name
109
+ ]));
110
+ export function agentErrorCodeFromCode(code) {
111
+ const name = AGENT_ERROR_NAME_BY_CODE.get(code);
112
+ return name === undefined ? { kind: "unrecognized", code } : { kind: "known", name };
113
+ }
114
+ export function agentErrorCode(value) {
115
+ return value.kind === "known" ? AgentErrorCodeName[value.name] : value.code;
116
+ }
117
+ export const DeadLetterReasonName = {
118
+ RetryExhausted: 1,
119
+ Rejected: 2,
120
+ DecodeFailed: 3,
121
+ DeadlineExceeded: 4
122
+ };
123
+ const DEAD_LETTER_NAME_BY_CODE = new Map(Object.entries(DeadLetterReasonName).map(([name, code]) => [
124
+ code,
125
+ name
126
+ ]));
127
+ export function deadLetterReasonFromCode(code) {
128
+ const name = DEAD_LETTER_NAME_BY_CODE.get(code);
129
+ return name === undefined ? { kind: "unrecognized", code } : { kind: "known", name };
130
+ }
131
+ export function deadLetterReasonCode(value) {
132
+ return value.kind === "known" ? DeadLetterReasonName[value.name] : value.code;
133
+ }
134
+ export const HealthName = {
135
+ Healthy: 1,
136
+ Degraded: 2,
137
+ Unavailable: 3
138
+ };
139
+ const HEALTH_NAME_BY_CODE = new Map(Object.entries(HealthName).map(([name, code]) => [code, name]));
140
+ export function healthFromCode(code) {
141
+ const name = HEALTH_NAME_BY_CODE.get(code);
142
+ return name === undefined ? { kind: "unrecognized", code } : { kind: "known", name };
143
+ }
144
+ export function healthCode(value) {
145
+ return value.kind === "known" ? HealthName[value.name] : value.code;
146
+ }
147
+ export function encodeTokenUsage(usage) {
148
+ const map = new Map();
149
+ map.set("input_tokens", usage.inputTokens);
150
+ map.set("output_tokens", usage.outputTokens);
151
+ if (usage.reasoningOutputTokens !== undefined) {
152
+ map.set("reasoning_output_tokens", usage.reasoningOutputTokens);
153
+ }
154
+ if (usage.cacheReadInputTokens !== undefined) {
155
+ map.set("cache_read_input_tokens", usage.cacheReadInputTokens);
156
+ }
157
+ if (usage.cacheCreationInputTokens !== undefined) {
158
+ map.set("cache_creation_input_tokens", usage.cacheCreationInputTokens);
159
+ }
160
+ return map;
161
+ }
162
+ export function decodeTokenUsage(map, context) {
163
+ const reasoningOutputTokens = field.optionalU64(map, "reasoning_output_tokens", context);
164
+ const cacheReadInputTokens = field.optionalU64(map, "cache_read_input_tokens", context);
165
+ const cacheCreationInputTokens = field.optionalU64(map, "cache_creation_input_tokens", context);
166
+ return {
167
+ inputTokens: field.requiredU64(map, "input_tokens", context),
168
+ outputTokens: field.requiredU64(map, "output_tokens", context),
169
+ ...(reasoningOutputTokens !== undefined ? { reasoningOutputTokens } : {}),
170
+ ...(cacheReadInputTokens !== undefined ? { cacheReadInputTokens } : {}),
171
+ ...(cacheCreationInputTokens !== undefined ? { cacheCreationInputTokens } : {})
172
+ };
173
+ }
174
+ export function encodeAgentErrorBody(body) {
175
+ const map = new Map();
176
+ map.set("code", agentErrorCode(body.code));
177
+ if (body.message !== undefined)
178
+ map.set("message", body.message);
179
+ if (body.retryable)
180
+ map.set("retryable", body.retryable);
181
+ if (body.detail !== undefined)
182
+ map.set("detail", encodeValueMap(body.detail));
183
+ return map;
184
+ }
185
+ export function encodeValueMap(values) {
186
+ const map = new Map();
187
+ for (const [key, value] of values)
188
+ map.set(key, encodeValue(value));
189
+ return map;
190
+ }
191
+ export function decodeValueMap(map, context) {
192
+ const result = new Map();
193
+ for (const [key, value] of map) {
194
+ if (typeof key !== "string") {
195
+ throw new CodecError(`expected a string-keyed map in ${context}`, context, "map");
196
+ }
197
+ result.set(key, decodeValue(value, `${context}.${key}`));
198
+ }
199
+ return result;
200
+ }
201
+ export function decodeAgentErrorBody(map, context) {
202
+ const message = field.optionalString(map, "message", context);
203
+ const detailMap = field.optionalMap(map, "detail", context);
204
+ return {
205
+ code: agentErrorCodeFromCode(field.requiredU8(map, "code", context)),
206
+ ...(message !== undefined ? { message } : {}),
207
+ retryable: map.has("retryable") ? field.requiredBoolean(map, "retryable", context) : false,
208
+ ...(detailMap !== undefined ? { detail: decodeValueMap(detailMap, context) } : {})
209
+ };
210
+ }
211
+ export function encodeAgentDeadLetter(letter) {
212
+ const map = new Map();
213
+ map.set("source", logPositionToBytes(letter.source));
214
+ map.set("reason", deadLetterReasonCode(letter.reason));
215
+ map.set("attempts", letter.attempts);
216
+ if (letter.detail !== undefined)
217
+ map.set("detail", letter.detail);
218
+ map.set("payload", letter.payload);
219
+ return map;
220
+ }
221
+ export function decodeAgentDeadLetter(map, context) {
222
+ const detail = field.optionalString(map, "detail", context);
223
+ return {
224
+ source: logPositionFromBytes(field.requiredBytes(map, "source", context)),
225
+ reason: deadLetterReasonFromCode(field.requiredU8(map, "reason", context)),
226
+ attempts: field.requiredU32(map, "attempts", context),
227
+ ...(detail !== undefined ? { detail } : {}),
228
+ payload: field.requiredBytes(map, "payload", context)
229
+ };
230
+ }
231
+ function parseContentTypeName(value, context) {
232
+ if (Object.values(ContentType).includes(value)) {
233
+ return value;
234
+ }
235
+ throw new CodecError(`unknown content type name \`${value}\` in ${context}`, context, "content_type");
236
+ }
237
+ export function encodeContentRef(ref) {
238
+ const map = new Map();
239
+ if (ref.kind === "contentType") {
240
+ map.set("content_type", ref.value);
241
+ }
242
+ else {
243
+ map.set("schema_id", ref.value);
244
+ }
245
+ return map;
246
+ }
247
+ export function decodeContentRef(value, context) {
248
+ const map = expectMap(value, context);
249
+ if (map.has("content_type")) {
250
+ return {
251
+ kind: "contentType",
252
+ value: parseContentTypeName(field.requiredString(map, "content_type", context), context)
253
+ };
254
+ }
255
+ if (map.has("schema_id")) {
256
+ return { kind: "schemaId", value: field.requiredString(map, "schema_id", context) };
257
+ }
258
+ throw new CodecError(`content ref in ${context} must have \`content_type\` or \`schema_id\``, context, "content_ref");
259
+ }
260
+ function cappedString(value, field_, cap) {
261
+ if (value !== undefined) {
262
+ const bytes = utf8Length(value);
263
+ if (bytes > cap) {
264
+ throw new InvalidError(`${field_} is ${String(bytes)}B, exceeds cap ${String(cap)}B`, {
265
+ field: field_
266
+ });
267
+ }
268
+ }
269
+ }
270
+ export function encodeCapabilityDescriptor(capability) {
271
+ const map = new Map();
272
+ map.set("skill_id", capability.skillId);
273
+ if (capability.input !== undefined)
274
+ map.set("input", encodeContentRef(capability.input));
275
+ if (capability.output !== undefined)
276
+ map.set("output", encodeContentRef(capability.output));
277
+ if (capability.costClass !== undefined)
278
+ map.set("cost_class", capability.costClass);
279
+ if (capability.latencyClass !== undefined)
280
+ map.set("latency_class", capability.latencyClass);
281
+ if (capability.maxConcurrency !== undefined)
282
+ map.set("max_concurrency", capability.maxConcurrency);
283
+ if (capability.health !== undefined)
284
+ map.set("health", healthCode(capability.health));
285
+ if (capability.load !== undefined)
286
+ map.set("load", capability.load);
287
+ return map;
288
+ }
289
+ export function decodeCapabilityDescriptor(value, context) {
290
+ const map = expectMap(value, context);
291
+ const input = field.optionalMap(map, "input", context);
292
+ const output = field.optionalMap(map, "output", context);
293
+ const costClass = field.optionalU8(map, "cost_class", context);
294
+ const latencyClass = field.optionalU8(map, "latency_class", context);
295
+ const maxConcurrency = field.optionalU32(map, "max_concurrency", context);
296
+ const health = field.optionalU8(map, "health", context);
297
+ const load = field.optionalU16(map, "load", context);
298
+ return {
299
+ skillId: field.requiredString(map, "skill_id", context),
300
+ ...(input !== undefined ? { input: decodeContentRef(input, `${context}.input`) } : {}),
301
+ ...(output !== undefined ? { output: decodeContentRef(output, `${context}.output`) } : {}),
302
+ ...(costClass !== undefined ? { costClass } : {}),
303
+ ...(latencyClass !== undefined ? { latencyClass } : {}),
304
+ ...(maxConcurrency !== undefined ? { maxConcurrency } : {}),
305
+ ...(health !== undefined ? { health: healthFromCode(health) } : {}),
306
+ ...(load !== undefined ? { load } : {})
307
+ };
308
+ }
309
+ export function validateAgentCard(card) {
310
+ cappedString(card.name, "name", MAX_AGENT_STRING_BYTES);
311
+ cappedString(card.version, "version", MAX_AGENT_STRING_BYTES);
312
+ if (card.capabilities.length > MAX_CARD_CAPABILITIES) {
313
+ throw new InvalidError(`capabilities has ${String(card.capabilities.length)} entries, exceeds cap ${String(MAX_CARD_CAPABILITIES)}`, { field: "capabilities" });
314
+ }
315
+ for (const capability of card.capabilities) {
316
+ cappedString(capability.skillId, "capability skill_id", MAX_AGENT_STRING_BYTES);
317
+ }
318
+ }
319
+ export function encodeAgentCard(card) {
320
+ const map = new Map();
321
+ if (card.name !== undefined)
322
+ map.set("name", card.name);
323
+ if (card.version !== undefined)
324
+ map.set("version", card.version);
325
+ if (card.capabilities.length > 0) {
326
+ map.set("capabilities", card.capabilities.map(encodeCapabilityDescriptor));
327
+ }
328
+ if (card.ttlMicros !== undefined)
329
+ map.set("ttl_micros", card.ttlMicros);
330
+ return map;
331
+ }
332
+ export function decodeAgentCard(map, context) {
333
+ const name = field.optionalString(map, "name", context);
334
+ const version = field.optionalString(map, "version", context);
335
+ const ttlMicros = field.optionalU64(map, "ttl_micros", context);
336
+ return {
337
+ ...(name !== undefined ? { name } : {}),
338
+ ...(version !== undefined ? { version } : {}),
339
+ capabilities: field.optionalArray(map, "capabilities", context, (item) => decodeCapabilityDescriptor(item, `${context}.capabilities`)),
340
+ ...(ttlMicros !== undefined ? { ttlMicros } : {})
341
+ };
342
+ }
343
+ export function newAgentPresence(agent, inbox) {
344
+ return { v: 1, agent, ...(inbox !== undefined ? { inbox } : {}) };
345
+ }
346
+ export function validateAgentPresence(presence) {
347
+ cappedString(presence.inbox, "inbox", MAX_AGENT_STRING_BYTES);
348
+ }
349
+ export function encodeAgentPresence(presence) {
350
+ const map = new Map();
351
+ map.set("v", presence.v);
352
+ map.set("agent", presence.agent);
353
+ if (presence.inbox !== undefined)
354
+ map.set("inbox", presence.inbox);
355
+ return map;
356
+ }
357
+ export function decodeAgentPresence(map, context) {
358
+ const inbox = field.optionalString(map, "inbox", context);
359
+ return {
360
+ v: field.requiredU32(map, "v", context),
361
+ agent: parseAgentId(field.requiredString(map, "agent", context)),
362
+ ...(inbox !== undefined ? { inbox } : {})
363
+ };
364
+ }
365
+ const SHA256_BYTES = 32;
366
+ export function newBodyRef(reference, sizeBytes, sha256) {
367
+ return { reference, sizeBytes, sha256 };
368
+ }
369
+ export function validateBodyRef(ref) {
370
+ if (ref.reference.length === 0) {
371
+ throw new InvalidError("reference must not be empty", { field: "reference" });
372
+ }
373
+ const referenceBytes = utf8Length(ref.reference);
374
+ if (referenceBytes > MAX_BODY_REFERENCE_BYTES) {
375
+ throw new InvalidError(`reference is ${String(referenceBytes)}B, exceeds cap ${String(MAX_BODY_REFERENCE_BYTES)}B`, { field: "reference" });
376
+ }
377
+ if (ref.sha256.length !== SHA256_BYTES) {
378
+ throw new InvalidError(`digest must be ${String(SHA256_BYTES)} bytes, got ${String(ref.sha256.length)}`, { field: "sha256" });
379
+ }
380
+ }
381
+ export function encodeBodyRef(ref) {
382
+ const map = new Map();
383
+ map.set("reference", ref.reference);
384
+ map.set("size_bytes", ref.sizeBytes);
385
+ map.set("sha256", ref.sha256);
386
+ if (ref.encryption !== undefined)
387
+ map.set("encryption", ref.encryption);
388
+ return map;
389
+ }
390
+ export function decodeBodyRef(map, context) {
391
+ const encryption = field.optionalU8(map, "encryption", context);
392
+ return {
393
+ reference: field.requiredString(map, "reference", context),
394
+ sizeBytes: field.requiredU64(map, "size_bytes", context),
395
+ sha256: field.requiredBytes(map, "sha256", context),
396
+ ...(encryption !== undefined ? { encryption } : {})
397
+ };
398
+ }
399
+ export function encodeSignatureContext(context) {
400
+ const map = new Map();
401
+ if (context.contentType !== undefined)
402
+ map.set("content_type", context.contentType);
403
+ if (context.agentVersion !== undefined)
404
+ map.set("agent_version", context.agentVersion);
405
+ return map;
406
+ }
407
+ export function decodeSignatureContext(map, context) {
408
+ const contentType = field.optionalU8(map, "content_type", context);
409
+ const agentVersion = field.optionalU32(map, "agent_version", context);
410
+ return {
411
+ ...(contentType !== undefined ? { contentType } : {}),
412
+ ...(agentVersion !== undefined ? { agentVersion } : {})
413
+ };
414
+ }
415
+ export const SIGNATURE_SCHEME_ED25519 = 1;
416
+ export const SIGNATURE_DOMAIN = new TextEncoder().encode("agdx.signature.v1");
417
+ const ED25519_KEY_ID_BYTES = 8;
418
+ const ED25519_SIGNATURE_BYTES = 64;
419
+ export function validateSignature(signature) {
420
+ if (signature.scheme !== SIGNATURE_SCHEME_ED25519)
421
+ return;
422
+ if (signature.keyId.length !== ED25519_KEY_ID_BYTES) {
423
+ throw new InvalidError(`Ed25519 key id must be ${String(ED25519_KEY_ID_BYTES)} bytes, got ${String(signature.keyId.length)}`, { field: "key_id" });
424
+ }
425
+ if (signature.bytes.length !== ED25519_SIGNATURE_BYTES) {
426
+ throw new InvalidError(`Ed25519 signature must be ${String(ED25519_SIGNATURE_BYTES)} bytes, got ${String(signature.bytes.length)}`, { field: "bytes" });
427
+ }
428
+ }
429
+ export function encodeSignature(signature) {
430
+ const map = new Map();
431
+ map.set("scheme", signature.scheme);
432
+ map.set("key_id", signature.keyId);
433
+ map.set("bytes", signature.bytes);
434
+ if (signature.context !== undefined)
435
+ map.set("context", encodeSignatureContext(signature.context));
436
+ return map;
437
+ }
438
+ export function decodeSignature(map, context) {
439
+ const contextMap = field.optionalMap(map, "context", context);
440
+ return {
441
+ scheme: field.requiredU8(map, "scheme", context),
442
+ keyId: field.requiredBytes(map, "key_id", context),
443
+ bytes: field.requiredBytes(map, "bytes", context),
444
+ ...(contextMap !== undefined
445
+ ? { context: decodeSignatureContext(contextMap, `${context}.context`) }
446
+ : {})
447
+ };
448
+ }
449
+ export const features = {
450
+ NONE: 0n
451
+ };
452
+ export const OPERATION_TASK = "task";
453
+ export const OPERATION_CARD = "card";
454
+ export const OPERATION_PROGRESS = "progress";
455
+ export const OPERATION_QUARANTINE = "quarantine";
456
+ export const OPERATION_UNQUARANTINE = "unquarantine";
457
+ export const OPERATION_CHAT = "chat";
458
+ export const OPERATION_REASONING = "reasoning";
459
+ export const OPERATION_TOOL_ARGS = "tool_args";
460
+ export const OPERATION_STATE_SNAPSHOT = "state_snapshot";
461
+ export const OPERATION_STATE_DELTA = "state_delta";
462
+ export const METADATA_ROLE = "role";
463
+ export const METADATA_BRIDGE_HOPS = "bridge_hops";
464
+ export const METADATA_RUN = "run";
465
+ export const METADATA_DELEGATED_BY = "on_behalf_of";
466
+ export const METADATA_PURPOSE = "purpose";
467
+ export const METADATA_DATA_CLASSIFICATION = "data_classification";
468
+ export const METADATA_TASK_CONTEXT = "task_context";
469
+ export const METADATA_SESSION_INTENT = "session_intent";
470
+ function baseEnvelope(kind, conversation, source) {
471
+ return { kind, conversation, source, last: false, mustUnderstand: 0n, body: new Uint8Array(0) };
472
+ }
473
+ export function commandEnvelope(record, conversation, source, correlation, body) {
474
+ return { ...baseEnvelope(AgentKind.Command, conversation, source), record, correlation, body };
475
+ }
476
+ export function responseEnvelope(record, conversation, source, correlation, body) {
477
+ return { ...baseEnvelope(AgentKind.Response, conversation, source), record, correlation, body };
478
+ }
479
+ export function eventEnvelope(record, conversation, source, body) {
480
+ return { ...baseEnvelope(AgentKind.Event, conversation, source), record, body };
481
+ }
482
+ export function chunkEnvelope(conversation, source, correlation, channel, sequence, body) {
483
+ return {
484
+ ...baseEnvelope(AgentKind.Chunk, conversation, source),
485
+ correlation,
486
+ channel,
487
+ sequence,
488
+ body
489
+ };
490
+ }
491
+ export function statusEnvelope(record, conversation, source, operation) {
492
+ return { ...baseEnvelope(AgentKind.Status, conversation, source), record, operation };
493
+ }
494
+ export function errorEnvelope(record, conversation, source, correlation, body) {
495
+ return { ...baseEnvelope(AgentKind.Error, conversation, source), record, correlation, body };
496
+ }
497
+ export function withTarget(envelope, target) {
498
+ return { ...envelope, target };
499
+ }
500
+ export function withCause(envelope, cause, causeAt) {
501
+ return { ...envelope, cause, ...(causeAt !== undefined ? { causeAt } : {}) };
502
+ }
503
+ export function withCorrelation(envelope, correlation) {
504
+ return { ...envelope, correlation };
505
+ }
506
+ export function withIdempotencyKey(envelope, key) {
507
+ return { ...envelope, idempotencyKey: key };
508
+ }
509
+ export function withDeadlineMicros(envelope, deadlineMicros) {
510
+ return { ...envelope, deadlineMicros };
511
+ }
512
+ export function terminal(envelope, finishReason) {
513
+ return { ...envelope, last: true, finishReason };
514
+ }
515
+ export function withTaskState(envelope, state) {
516
+ return { ...envelope, taskState: state };
517
+ }
518
+ export function withOperation(envelope, operation) {
519
+ return { ...envelope, operation };
520
+ }
521
+ export function withTool(envelope, tool) {
522
+ return { ...envelope, tool };
523
+ }
524
+ export function withUsage(envelope, usage) {
525
+ return { ...envelope, usage };
526
+ }
527
+ export function withMetadata(envelope, key, value) {
528
+ const metadata = new Map(envelope.metadata ?? []);
529
+ metadata.set(key, value);
530
+ return { ...envelope, metadata };
531
+ }
532
+ export function withSignature(envelope, signature) {
533
+ return { ...envelope, signature };
534
+ }
535
+ export function requiring(envelope, bits) {
536
+ return { ...envelope, mustUnderstand: bits };
537
+ }
538
+ export function unmetRequirements(envelope, understood) {
539
+ return envelope.mustUnderstand & ~understood;
540
+ }
541
+ export function encodeAgentEnvelope(envelope) {
542
+ const map = new Map();
543
+ map.set("kind", envelope.kind);
544
+ if (envelope.record !== undefined)
545
+ map.set("record", envelope.record.toBytes());
546
+ map.set("conversation", envelope.conversation.toBytes());
547
+ map.set("source", envelope.source);
548
+ if (envelope.target !== undefined)
549
+ map.set("target", envelope.target);
550
+ if (envelope.cause !== undefined)
551
+ map.set("cause", envelope.cause.toBytes());
552
+ if (envelope.causeAt !== undefined)
553
+ map.set("cause_at", logPositionToBytes(envelope.causeAt));
554
+ if (envelope.correlation !== undefined)
555
+ map.set("correlation", envelope.correlation.toBytes());
556
+ if (envelope.channel !== undefined)
557
+ map.set("channel", envelope.channel.toBytes());
558
+ if (envelope.idempotencyKey !== undefined)
559
+ map.set("idempotency_key", envelope.idempotencyKey);
560
+ if (envelope.deadlineMicros !== undefined)
561
+ map.set("deadline_micros", envelope.deadlineMicros);
562
+ if (envelope.sequence !== undefined)
563
+ map.set("sequence", envelope.sequence);
564
+ if (envelope.last)
565
+ map.set("last", envelope.last);
566
+ if (envelope.finishReason !== undefined)
567
+ map.set("finish_reason", envelope.finishReason);
568
+ if (envelope.taskState !== undefined)
569
+ map.set("task_state", taskStateCode(envelope.taskState));
570
+ if (envelope.operation !== undefined)
571
+ map.set("operation", envelope.operation);
572
+ if (envelope.tool !== undefined)
573
+ map.set("tool", envelope.tool);
574
+ if (envelope.usage !== undefined)
575
+ map.set("usage", encodeTokenUsage(envelope.usage));
576
+ if (envelope.metadata !== undefined)
577
+ map.set("metadata", encodeValueMap(envelope.metadata));
578
+ if (envelope.mustUnderstand !== 0n)
579
+ map.set("must_understand", envelope.mustUnderstand);
580
+ if (envelope.body.length > 0)
581
+ map.set("body", envelope.body);
582
+ if (envelope.signature !== undefined)
583
+ map.set("signature", encodeSignature(envelope.signature));
584
+ return map;
585
+ }
586
+ export function decodeAgentEnvelope(map, context) {
587
+ const record = field.optionalBytes(map, "record", context);
588
+ const target = field.optionalString(map, "target", context);
589
+ const cause = field.optionalBytes(map, "cause", context);
590
+ const causeAt = field.optionalBytes(map, "cause_at", context);
591
+ const correlation = field.optionalBytes(map, "correlation", context);
592
+ const channel = field.optionalBytes(map, "channel", context);
593
+ const idempotencyKey = field.optionalString(map, "idempotency_key", context);
594
+ const deadlineMicros = field.optionalU64(map, "deadline_micros", context);
595
+ const sequence = field.optionalU64(map, "sequence", context);
596
+ const finishReason = field.optionalString(map, "finish_reason", context);
597
+ const taskState = field.optionalU8(map, "task_state", context);
598
+ const operation = field.optionalString(map, "operation", context);
599
+ const tool = field.optionalString(map, "tool", context);
600
+ const usageMap = field.optionalMap(map, "usage", context);
601
+ const metadataMap = field.optionalMap(map, "metadata", context);
602
+ const mustUnderstand = field.optionalU64(map, "must_understand", context);
603
+ const body = field.optionalBytes(map, "body", context);
604
+ const signatureMap = field.optionalMap(map, "signature", context);
605
+ return {
606
+ kind: parseAgentKind(field.requiredString(map, "kind", context), context),
607
+ ...(record !== undefined ? { record: RecordId.fromBytes(record) } : {}),
608
+ conversation: ConversationId.fromBytes(field.requiredBytes(map, "conversation", context)),
609
+ source: parseAgentId(field.requiredString(map, "source", context)),
610
+ ...(target !== undefined ? { target: parseAgentId(target) } : {}),
611
+ ...(cause !== undefined ? { cause: RecordId.fromBytes(cause) } : {}),
612
+ ...(causeAt !== undefined ? { causeAt: logPositionFromBytes(causeAt) } : {}),
613
+ ...(correlation !== undefined ? { correlation: CorrelationId.fromBytes(correlation) } : {}),
614
+ ...(channel !== undefined ? { channel: ChannelId.fromBytes(channel) } : {}),
615
+ ...(idempotencyKey !== undefined
616
+ ? { idempotencyKey: parseIdempotencyKey(idempotencyKey) }
617
+ : {}),
618
+ ...(deadlineMicros !== undefined ? { deadlineMicros } : {}),
619
+ ...(sequence !== undefined ? { sequence } : {}),
620
+ last: map.has("last") ? field.requiredBoolean(map, "last", context) : false,
621
+ ...(finishReason !== undefined ? { finishReason } : {}),
622
+ ...(taskState !== undefined ? { taskState: taskStateFromCode(taskState) } : {}),
623
+ ...(operation !== undefined ? { operation } : {}),
624
+ ...(tool !== undefined ? { tool } : {}),
625
+ ...(usageMap !== undefined ? { usage: decodeTokenUsage(usageMap, context) } : {}),
626
+ ...(metadataMap !== undefined ? { metadata: decodeValueMap(metadataMap, context) } : {}),
627
+ mustUnderstand: mustUnderstand ?? 0n,
628
+ body: body ?? new Uint8Array(0),
629
+ ...(signatureMap !== undefined ? { signature: decodeSignature(signatureMap, context) } : {})
630
+ };
631
+ }
632
+ const CHUNK_STREAM_OPERATIONS = new Set([
633
+ OPERATION_CHAT,
634
+ OPERATION_REASONING,
635
+ OPERATION_TOOL_ARGS
636
+ ]);
637
+ const STATUS_OPERATIONS = new Set([
638
+ OPERATION_TASK,
639
+ OPERATION_CARD,
640
+ OPERATION_PROGRESS,
641
+ OPERATION_QUARANTINE,
642
+ OPERATION_UNQUARANTINE
643
+ ]);
644
+ export function validateAgentEnvelope(envelope) {
645
+ const kind = envelope.kind;
646
+ const require = (present, fieldName) => {
647
+ if (!present)
648
+ throw new InvalidError(`${kind} requires \`${fieldName}\``, { kind, field: fieldName });
649
+ };
650
+ const forbid = (absent, fieldName) => {
651
+ if (!absent) {
652
+ throw new InvalidError(`\`${fieldName}\` is invalid on ${kind}`, { kind, field: fieldName });
653
+ }
654
+ };
655
+ const invalid = (fieldName, reason) => {
656
+ throw new InvalidError(`\`${fieldName}\`: ${reason}`, { field: fieldName });
657
+ };
658
+ if (kind !== AgentKind.Chunk) {
659
+ require(envelope.record !== undefined, "record");
660
+ }
661
+ switch (kind) {
662
+ case AgentKind.Command:
663
+ case AgentKind.Response:
664
+ case AgentKind.Chunk:
665
+ case AgentKind.Error:
666
+ require(envelope.correlation !== undefined, "correlation");
667
+ break;
668
+ case AgentKind.Status:
669
+ if (envelope.operation === OPERATION_TASK) {
670
+ require(envelope.correlation !== undefined, "correlation");
671
+ }
672
+ break;
673
+ case AgentKind.Event:
674
+ break;
675
+ }
676
+ if (kind === AgentKind.Chunk) {
677
+ require(envelope.channel !== undefined, "channel");
678
+ require(envelope.sequence !== undefined, "sequence");
679
+ }
680
+ else if (kind === AgentKind.Error) {
681
+ if (envelope.sequence !== undefined && envelope.channel === undefined) {
682
+ invalid("sequence", "sequence requires channel");
683
+ }
684
+ }
685
+ else {
686
+ forbid(envelope.channel === undefined, "channel");
687
+ forbid(envelope.sequence === undefined, "sequence");
688
+ }
689
+ if (envelope.last && kind !== AgentKind.Chunk && kind !== AgentKind.Status) {
690
+ throw new InvalidError(`\`last\` is invalid on ${kind}`, { kind, field: "last" });
691
+ }
692
+ if (kind === AgentKind.Chunk) {
693
+ if (envelope.finishReason !== undefined && !envelope.last) {
694
+ invalid("finish_reason", "finish_reason rides only the terminal chunk");
695
+ }
696
+ }
697
+ else if (kind !== AgentKind.Response) {
698
+ forbid(envelope.finishReason === undefined, "finish_reason");
699
+ }
700
+ if (kind === AgentKind.Chunk || kind === AgentKind.Status || kind === AgentKind.Error) {
701
+ forbid(envelope.idempotencyKey === undefined, "idempotency_key");
702
+ }
703
+ if (kind === AgentKind.Response ||
704
+ kind === AgentKind.Event ||
705
+ kind === AgentKind.Status ||
706
+ kind === AgentKind.Error) {
707
+ forbid(envelope.deadlineMicros === undefined, "deadline_micros");
708
+ }
709
+ if (kind === AgentKind.Chunk &&
710
+ envelope.deadlineMicros !== undefined &&
711
+ envelope.sequence !== 0n) {
712
+ invalid("deadline_micros", "the stream bound rides the opening chunk (sequence 0)");
713
+ }
714
+ if (kind === AgentKind.Status) {
715
+ if (envelope.operation === OPERATION_TASK) {
716
+ require(envelope.taskState !== undefined, "task_state");
717
+ }
718
+ }
719
+ else if (kind !== AgentKind.Response && kind !== AgentKind.Error) {
720
+ forbid(envelope.taskState === undefined, "task_state");
721
+ }
722
+ if (kind === AgentKind.Status) {
723
+ require(envelope.operation !== undefined, "operation");
724
+ if (envelope.operation !== undefined && !STATUS_OPERATIONS.has(envelope.operation)) {
725
+ invalid("operation", `status operation must be \`${OPERATION_TASK}\`, \`${OPERATION_CARD}\`, \`${OPERATION_PROGRESS}\`, \`${OPERATION_QUARANTINE}\`, or \`${OPERATION_UNQUARANTINE}\`, got \`${envelope.operation}\``);
726
+ }
727
+ }
728
+ else if (kind === AgentKind.Chunk) {
729
+ if (envelope.sequence === 0n) {
730
+ require(envelope.operation !== undefined, "operation");
731
+ }
732
+ if (envelope.operation !== undefined) {
733
+ if (envelope.sequence !== 0n) {
734
+ invalid("operation", "the stream purpose rides the opening chunk (sequence 0)");
735
+ }
736
+ if (!CHUNK_STREAM_OPERATIONS.has(envelope.operation)) {
737
+ invalid("operation", `chunk-stream purpose must be \`${OPERATION_CHAT}\`, \`${OPERATION_REASONING}\`, or \`${OPERATION_TOOL_ARGS}\`, got \`${envelope.operation}\``);
738
+ }
739
+ }
740
+ }
741
+ if (kind === AgentKind.Status) {
742
+ forbid(envelope.tool === undefined, "tool");
743
+ }
744
+ if (kind === AgentKind.Command) {
745
+ forbid(envelope.usage === undefined, "usage");
746
+ }
747
+ else if (kind === AgentKind.Chunk && envelope.usage !== undefined && !envelope.last) {
748
+ invalid("usage", "whole-stream accounting rides the terminal chunk");
749
+ }
750
+ if (kind === AgentKind.Chunk) {
751
+ if (envelope.body.length === 0 && !envelope.last) {
752
+ throw new InvalidError(`${kind} requires \`body\``, { kind, field: "body" });
753
+ }
754
+ }
755
+ else if (kind !== AgentKind.Status) {
756
+ require(envelope.body.length > 0, "body");
757
+ }
758
+ cappedString(envelope.operation, "operation", MAX_AGENT_STRING_BYTES);
759
+ cappedString(envelope.tool, "tool", MAX_AGENT_STRING_BYTES);
760
+ cappedString(envelope.finishReason, "finish_reason", MAX_AGENT_STRING_BYTES);
761
+ if (envelope.metadata !== undefined) {
762
+ if (envelope.metadata.size > MAX_METADATA_ENTRIES) {
763
+ throw new InvalidError(`\`metadata\` is ${String(envelope.metadata.size)} entries, exceeds cap ${String(MAX_METADATA_ENTRIES)}`, { field: "metadata" });
764
+ }
765
+ let total = 0;
766
+ for (const [key, value] of envelope.metadata) {
767
+ const keySize = utf8Length(key);
768
+ if (keySize > MAX_METADATA_KEY_BYTES) {
769
+ throw new InvalidError(`\`metadata key\` is ${String(keySize)}B, exceeds cap ${String(MAX_METADATA_KEY_BYTES)}B`, { field: "metadata key" });
770
+ }
771
+ const size = valueSize(value);
772
+ if (size > MAX_METADATA_VALUE_BYTES) {
773
+ throw new InvalidError(`\`metadata value\` is ${String(size)}B, exceeds cap ${String(MAX_METADATA_VALUE_BYTES)}B`, { field: "metadata value" });
774
+ }
775
+ total += keySize + size;
776
+ }
777
+ if (total > MAX_METADATA_TOTAL_BYTES) {
778
+ throw new InvalidError(`\`metadata\` is ${String(total)}B, exceeds cap ${String(MAX_METADATA_TOTAL_BYTES)}B`, { field: "metadata" });
779
+ }
780
+ }
781
+ if (envelope.signature !== undefined) {
782
+ validateSignature(envelope.signature);
783
+ }
784
+ }
785
+ function valueSize(value) {
786
+ if (value.kind === "string")
787
+ return utf8Length(value.value);
788
+ if (value.kind === "list")
789
+ return value.value.reduce((sum, item) => sum + 1 + valueSize(item), 0);
790
+ return 9;
791
+ }
792
+ //# sourceMappingURL=agent.js.map