@vorim/sdk 3.23.0 → 4.1.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 (152) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/_commerce-core-Dyr_dHVP.d.ts +156 -0
  3. package/dist/_commerce-core-wY2jC6rC.d.cts +156 -0
  4. package/dist/index.cjs +217 -14
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.cts +200 -16
  7. package/dist/index.d.ts +200 -16
  8. package/dist/index.js +216 -14
  9. package/dist/index.js.map +1 -1
  10. package/dist/integrations/amazon.cjs +357 -0
  11. package/dist/integrations/amazon.cjs.map +1 -0
  12. package/dist/integrations/amazon.d.cts +88 -0
  13. package/dist/integrations/amazon.d.ts +88 -0
  14. package/dist/integrations/amazon.js +328 -0
  15. package/dist/integrations/amazon.js.map +1 -0
  16. package/dist/integrations/anthropic.d.cts +1 -1
  17. package/dist/integrations/anthropic.d.ts +1 -1
  18. package/dist/integrations/ap2.d.cts +1 -1
  19. package/dist/integrations/ap2.d.ts +1 -1
  20. package/dist/integrations/aws-iam.d.cts +1 -1
  21. package/dist/integrations/aws-iam.d.ts +1 -1
  22. package/dist/integrations/bank-rails.d.cts +1 -1
  23. package/dist/integrations/bank-rails.d.ts +1 -1
  24. package/dist/integrations/circle.d.cts +1 -1
  25. package/dist/integrations/circle.d.ts +1 -1
  26. package/dist/integrations/cloudflare.d.cts +1 -1
  27. package/dist/integrations/cloudflare.d.ts +1 -1
  28. package/dist/integrations/coinbase-cdp.d.cts +1 -1
  29. package/dist/integrations/coinbase-cdp.d.ts +1 -1
  30. package/dist/integrations/commerce-agents.d.cts +1 -1
  31. package/dist/integrations/commerce-agents.d.ts +1 -1
  32. package/dist/integrations/crewai.d.cts +1 -1
  33. package/dist/integrations/crewai.d.ts +1 -1
  34. package/dist/integrations/delivery.cjs +327 -0
  35. package/dist/integrations/delivery.cjs.map +1 -0
  36. package/dist/integrations/delivery.d.cts +33 -0
  37. package/dist/integrations/delivery.d.ts +33 -0
  38. package/dist/integrations/delivery.js +296 -0
  39. package/dist/integrations/delivery.js.map +1 -0
  40. package/dist/integrations/ebay.cjs +350 -0
  41. package/dist/integrations/ebay.cjs.map +1 -0
  42. package/dist/integrations/ebay.d.cts +73 -0
  43. package/dist/integrations/ebay.d.ts +73 -0
  44. package/dist/integrations/ebay.js +321 -0
  45. package/dist/integrations/ebay.js.map +1 -0
  46. package/dist/integrations/entra.d.cts +1 -1
  47. package/dist/integrations/entra.d.ts +1 -1
  48. package/dist/integrations/etsy.cjs +330 -0
  49. package/dist/integrations/etsy.cjs.map +1 -0
  50. package/dist/integrations/etsy.d.cts +41 -0
  51. package/dist/integrations/etsy.d.ts +41 -0
  52. package/dist/integrations/etsy.js +301 -0
  53. package/dist/integrations/etsy.js.map +1 -0
  54. package/dist/integrations/fhir.d.cts +1 -1
  55. package/dist/integrations/fhir.d.ts +1 -1
  56. package/dist/integrations/google-merchant.cjs +332 -0
  57. package/dist/integrations/google-merchant.cjs.map +1 -0
  58. package/dist/integrations/google-merchant.d.cts +43 -0
  59. package/dist/integrations/google-merchant.d.ts +43 -0
  60. package/dist/integrations/google-merchant.js +303 -0
  61. package/dist/integrations/google-merchant.js.map +1 -0
  62. package/dist/integrations/grok.d.cts +1 -1
  63. package/dist/integrations/grok.d.ts +1 -1
  64. package/dist/integrations/guidewire.d.cts +1 -1
  65. package/dist/integrations/guidewire.d.ts +1 -1
  66. package/dist/integrations/hermes.d.cts +1 -1
  67. package/dist/integrations/hermes.d.ts +1 -1
  68. package/dist/integrations/jira.d.cts +1 -1
  69. package/dist/integrations/jira.d.ts +1 -1
  70. package/dist/integrations/langchain.d.cts +1 -1
  71. package/dist/integrations/langchain.d.ts +1 -1
  72. package/dist/integrations/langgraph.d.cts +1 -1
  73. package/dist/integrations/langgraph.d.ts +1 -1
  74. package/dist/integrations/legal.d.cts +1 -1
  75. package/dist/integrations/legal.d.ts +1 -1
  76. package/dist/integrations/life-sciences.d.cts +1 -1
  77. package/dist/integrations/life-sciences.d.ts +1 -1
  78. package/dist/integrations/linear.d.cts +1 -1
  79. package/dist/integrations/linear.d.ts +1 -1
  80. package/dist/integrations/lithic.d.cts +1 -1
  81. package/dist/integrations/lithic.d.ts +1 -1
  82. package/dist/integrations/llamaindex.d.cts +1 -1
  83. package/dist/integrations/llamaindex.d.ts +1 -1
  84. package/dist/integrations/marqeta.d.cts +1 -1
  85. package/dist/integrations/marqeta.d.ts +1 -1
  86. package/dist/integrations/meta.cjs +375 -0
  87. package/dist/integrations/meta.cjs.map +1 -0
  88. package/dist/integrations/meta.d.cts +83 -0
  89. package/dist/integrations/meta.d.ts +83 -0
  90. package/dist/integrations/meta.js +346 -0
  91. package/dist/integrations/meta.js.map +1 -0
  92. package/dist/integrations/modern-treasury.d.cts +1 -1
  93. package/dist/integrations/modern-treasury.d.ts +1 -1
  94. package/dist/integrations/muse.d.cts +1 -1
  95. package/dist/integrations/muse.d.ts +1 -1
  96. package/dist/integrations/nekuda.d.cts +1 -1
  97. package/dist/integrations/nekuda.d.ts +1 -1
  98. package/dist/integrations/okta.d.cts +1 -1
  99. package/dist/integrations/okta.d.ts +1 -1
  100. package/dist/integrations/openai.d.cts +1 -1
  101. package/dist/integrations/openai.d.ts +1 -1
  102. package/dist/integrations/openrouter.d.cts +1 -1
  103. package/dist/integrations/openrouter.d.ts +1 -1
  104. package/dist/integrations/paypal-agent.d.cts +1 -1
  105. package/dist/integrations/paypal-agent.d.ts +1 -1
  106. package/dist/integrations/perplexity.d.cts +1 -1
  107. package/dist/integrations/perplexity.d.ts +1 -1
  108. package/dist/integrations/plaid.d.cts +1 -1
  109. package/dist/integrations/plaid.d.ts +1 -1
  110. package/dist/integrations/ramp.d.cts +1 -1
  111. package/dist/integrations/ramp.d.ts +1 -1
  112. package/dist/integrations/shopify.d.cts +1 -1
  113. package/dist/integrations/shopify.d.ts +1 -1
  114. package/dist/integrations/siem.d.cts +1 -1
  115. package/dist/integrations/siem.d.ts +1 -1
  116. package/dist/integrations/skyfire.d.cts +1 -1
  117. package/dist/integrations/skyfire.d.ts +1 -1
  118. package/dist/integrations/social-ads.cjs +328 -0
  119. package/dist/integrations/social-ads.cjs.map +1 -0
  120. package/dist/integrations/social-ads.d.cts +36 -0
  121. package/dist/integrations/social-ads.d.ts +36 -0
  122. package/dist/integrations/social-ads.js +297 -0
  123. package/dist/integrations/social-ads.js.map +1 -0
  124. package/dist/integrations/stripe-acp.d.cts +1 -1
  125. package/dist/integrations/stripe-acp.d.ts +1 -1
  126. package/dist/integrations/stripe-issuing.d.cts +1 -1
  127. package/dist/integrations/stripe-issuing.d.ts +1 -1
  128. package/dist/integrations/tiktok-shop.cjs +334 -0
  129. package/dist/integrations/tiktok-shop.cjs.map +1 -0
  130. package/dist/integrations/tiktok-shop.d.cts +44 -0
  131. package/dist/integrations/tiktok-shop.d.ts +44 -0
  132. package/dist/integrations/tiktok-shop.js +305 -0
  133. package/dist/integrations/tiktok-shop.js.map +1 -0
  134. package/dist/integrations/truanon.d.cts +1 -1
  135. package/dist/integrations/truanon.d.ts +1 -1
  136. package/dist/integrations/typesafe.d.cts +1 -1
  137. package/dist/integrations/typesafe.d.ts +1 -1
  138. package/dist/integrations/ucp.d.cts +1 -1
  139. package/dist/integrations/ucp.d.ts +1 -1
  140. package/dist/integrations/vercel-ai.d.cts +1 -1
  141. package/dist/integrations/vercel-ai.d.ts +1 -1
  142. package/dist/integrations/walmart.cjs +344 -0
  143. package/dist/integrations/walmart.cjs.map +1 -0
  144. package/dist/integrations/walmart.d.cts +60 -0
  145. package/dist/integrations/walmart.d.ts +60 -0
  146. package/dist/integrations/walmart.js +315 -0
  147. package/dist/integrations/walmart.js.map +1 -0
  148. package/dist/integrations/x402.d.cts +1 -1
  149. package/dist/integrations/x402.d.ts +1 -1
  150. package/dist/{types-BrDQAJdl.d.cts → types-DphtTyIC.d.cts} +72 -3
  151. package/dist/{types-BrDQAJdl.d.ts → types-DphtTyIC.d.ts} +72 -3
  152. package/package.json +92 -2
package/dist/index.cjs CHANGED
@@ -45,6 +45,7 @@ __export(index_exports, {
45
45
  default: () => createVorim,
46
46
  deviceLogin: () => deviceLogin,
47
47
  eventDigest: () => eventDigest,
48
+ foldTraceparent: () => foldTraceparent,
48
49
  hashPayload: () => hashPayload,
49
50
  hashPreviousEvent: () => hashPreviousEvent,
50
51
  hashSystemPrompt: () => hashSystemPrompt,
@@ -930,7 +931,7 @@ async function verifyHttpRequest(request, options) {
930
931
  }
931
932
 
932
933
  // src/index.ts
933
- var SDK_VERSION = true ? "3.23.0" : "0.0.0";
934
+ var SDK_VERSION = true ? "4.1.0" : "0.0.0";
934
935
  var USER_AGENT = `vorim-sdk/${SDK_VERSION}`;
935
936
  function sleep(ms) {
936
937
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -973,6 +974,17 @@ function toApprovalAttestation(raw) {
973
974
  signature: raw.signature
974
975
  };
975
976
  }
977
+ function foldTraceparent(input) {
978
+ if (!input.traceparent) return input;
979
+ const { traceparent, ...rest } = input;
980
+ const m = /^[0-9a-f]{2}-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$/i.exec(traceparent.trim());
981
+ const out = { ...rest };
982
+ if (m) {
983
+ if (!out.trace_id) out.trace_id = m[1].toLowerCase();
984
+ if (!out.span_id) out.span_id = m[2].toLowerCase();
985
+ }
986
+ return out;
987
+ }
976
988
  var VorimSDK = class _VorimSDK {
977
989
  apiKey;
978
990
  baseUrl;
@@ -1028,7 +1040,7 @@ var VorimSDK = class _VorimSDK {
1028
1040
  }
1029
1041
  }
1030
1042
  this.chainEvents = config.chainEvents ?? false;
1031
- this.runtimeFailOpen = config.runtimeFailOpen ?? true;
1043
+ this.runtimeFailOpen = config.runtimeFailOpen ?? false;
1032
1044
  this.noPayload = config.noPayload !== void 0 && config.noPayload !== false;
1033
1045
  this.maxMetadataChars = typeof config.noPayload === "object" && typeof config.noPayload.maxMetadataChars === "number" ? config.noPayload.maxMetadataChars : 256;
1034
1046
  }
@@ -1131,11 +1143,26 @@ var VorimSDK = class _VorimSDK {
1131
1143
  return { agents: env.data ?? [], meta: env.meta ?? null };
1132
1144
  }
1133
1145
  /**
1134
- * Update an agent's metadata.
1146
+ * Update an agent's metadata or status.
1147
+ *
1148
+ * `status: 'suspended'` is the kill switch and, since 4.0.0, cascades to
1149
+ * every agent reachable through the agent's active identity delegations
1150
+ * unless `cascade: false`. Setting `status: 'active'` on a suspended agent
1151
+ * reverses exactly that cascade. The returned agent carries
1152
+ * `cascade.suspended` / `cascade.reactivated` with the agent ids touched.
1153
+ * See {@link suspendPreview} for the blast radius before acting.
1135
1154
  */
1136
1155
  async updateAgent(agentId, updates) {
1137
1156
  return this.patch(`/agents/${agentId}`, updates);
1138
1157
  }
1158
+ /**
1159
+ * What suspending (or revoking) this agent would touch: its delegation
1160
+ * subtree, how many of those agents are still active, open escalations
1161
+ * across the subtree, and live delegation links. Writes nothing.
1162
+ */
1163
+ async suspendPreview(agentId) {
1164
+ return this.get(`/agents/${agentId}/suspend-preview`);
1165
+ }
1139
1166
  /**
1140
1167
  * Revoke an agent (permanent deactivation).
1141
1168
  */
@@ -1495,9 +1522,9 @@ var VorimSDK = class _VorimSDK {
1495
1522
  * poll {@link waitForDecisionResolution} for the human decision.
1496
1523
  *
1497
1524
  * Transport failures (network/DNS/timeout/5xx) respect the constructor's
1498
- * `runtimeFailOpen` flag: when true (default) a synthetic `fallback`
1499
- * decision is returned so a control-plane blip does not block the agent;
1500
- * when false the underlying error is re-thrown.
1525
+ * `runtimeFailOpen` flag: when false (default) the underlying error is
1526
+ * re-thrown; when true a synthetic `fallback` decision is returned so a
1527
+ * control-plane blip does not block the agent.
1501
1528
  *
1502
1529
  * Always pass the public `agid_*` id as `agentId`.
1503
1530
  *
@@ -1522,7 +1549,10 @@ var VorimSDK = class _VorimSDK {
1522
1549
  required_scope: input.requiredScope,
1523
1550
  idempotency_key: input.idempotencyKey,
1524
1551
  workflow_id: input.workflowId,
1525
- estimated_tokens: input.estimatedTokens
1552
+ estimated_tokens: input.estimatedTokens,
1553
+ trace_id: input.traceId,
1554
+ span_id: input.spanId,
1555
+ traceparent: input.traceparent
1526
1556
  };
1527
1557
  let raw;
1528
1558
  try {
@@ -1542,6 +1572,7 @@ var VorimSDK = class _VorimSDK {
1542
1572
  latencyMs: 0,
1543
1573
  isFallback: true,
1544
1574
  policyVersion: 0,
1575
+ swarmId: null,
1545
1576
  escalationResolution: null,
1546
1577
  approval: null
1547
1578
  };
@@ -1560,12 +1591,18 @@ var VorimSDK = class _VorimSDK {
1560
1591
  // Enforcement runs inside beforeAction(): pass `workflowId` + `estimatedTokens`
1561
1592
  // on the action, and a `token_budget_gt` policy rule denies the action before
1562
1593
  // the spend if it would breach the budget. These methods manage the budgets
1563
- // and read live spend (dashboard-oriented; require a JWT-authed client or an
1564
- // owner/admin API key).
1594
+ // and read live spend. They need an API key holding the `runtime:manage`
1595
+ // scope (deliberately separate from `runtime:decide`, so an agent's own key
1596
+ // cannot raise its ceiling).
1565
1597
  /**
1566
1598
  * Create or update a token budget for an agent or workflow. One budget per
1567
1599
  * (scope, scope_ref) — calling this again for the same target updates it.
1568
1600
  *
1601
+ * A budget is a ceiling; a policy rule enforces it. Add a rule with
1602
+ * `match_conditions: { token_budget_gt: { scope } }` and a `deny` (or
1603
+ * `escalate`) decision, otherwise actions are still allowed once the budget
1604
+ * is used up.
1605
+ *
1569
1606
  * @example
1570
1607
  * await vorim.setBudget({
1571
1608
  * scope: 'workflow', scope_ref: 'nightly-summariser',
@@ -1656,19 +1693,20 @@ var VorimSDK = class _VorimSDK {
1656
1693
  * row's `decision` column off `'escalate'`. If we returned that verbatim,
1657
1694
  * a caller's obvious `if (d.decision === 'deny')` check would never fire
1658
1695
  * on a human DENIAL — a silent fail-open. So when a resolution is present
1659
- * we translate the verdict: approved → 'allow', denied → 'deny'. The raw
1660
- * resolution is also surfaced as `escalationResolution` for callers that
1661
- * want it explicitly.
1696
+ * we translate the verdict: approved → 'allow', denied → 'deny', and
1697
+ * timed_out (nobody answered within the org's escalation window) → 'deny'.
1698
+ * The raw resolution is also surfaced as `escalationResolution` for
1699
+ * callers that want it explicitly.
1662
1700
  *
1663
1701
  * A missing verdict (malformed/truncated response) fails CLOSED to 'deny'
1664
1702
  * rather than 'fallback', so the deny check fires on garbled input.
1665
1703
  */
1666
1704
  toRuntimeDecision(raw) {
1667
- const resolution = raw?.escalation_resolution === "approved" ? "approved" : raw?.escalation_resolution === "denied" ? "denied" : null;
1705
+ const resolution = raw?.escalation_resolution === "approved" ? "approved" : raw?.escalation_resolution === "denied" ? "denied" : raw?.escalation_resolution === "timed_out" ? "timed_out" : null;
1668
1706
  const hasVerdict = typeof raw?.decision === "string";
1669
1707
  let decision;
1670
1708
  if (raw?.decision === "escalate" && resolution === "approved") decision = "allow";
1671
- else if (raw?.decision === "escalate" && resolution === "denied") decision = "deny";
1709
+ else if (raw?.decision === "escalate" && (resolution === "denied" || resolution === "timed_out")) decision = "deny";
1672
1710
  else if (hasVerdict) decision = raw.decision;
1673
1711
  else decision = "deny";
1674
1712
  return {
@@ -1683,6 +1721,7 @@ var VorimSDK = class _VorimSDK {
1683
1721
  latencyMs: raw?.latency_ms ?? 0,
1684
1722
  isFallback: raw?.is_fallback ?? !hasVerdict,
1685
1723
  policyVersion: raw?.policy_version ?? 0,
1724
+ swarmId: typeof raw?.swarm_id === "string" ? raw.swarm_id : null,
1686
1725
  escalationResolution: resolution,
1687
1726
  approval: toApprovalAttestation(raw?.approval)
1688
1727
  };
@@ -1817,6 +1856,7 @@ var VorimSDK = class _VorimSDK {
1817
1856
  }
1818
1857
  async prepareEvent(event, signOverride) {
1819
1858
  this.assertNoPayload(event);
1859
+ event = foldTraceparent(event);
1820
1860
  const shouldSign = signOverride ?? this.autoSign;
1821
1861
  if (!shouldSign && !this.chainEvents) return event;
1822
1862
  if (this.chainEvents) {
@@ -1936,6 +1976,168 @@ var VorimSDK = class _VorimSDK {
1936
1976
  }
1937
1977
  return result;
1938
1978
  }
1979
+ /**
1980
+ * The server-minted swarm an agent belongs to and every member of it.
1981
+ * `{ swarm_id: null, members: [] }` for a standalone agent.
1982
+ */
1983
+ async getSwarm(agentId) {
1984
+ return this.get(`/agents/${agentId}/swarm`);
1985
+ }
1986
+ // ─── Many agents at once ─────────────────────────────────────────────
1987
+ /**
1988
+ * Register up to 50 agents in one call: an explicit list, or a template
1989
+ * repeated `count` times (names `<prefix>-1` .. `<prefix>-N`), optionally
1990
+ * grouped into a new swarm (`swarm: { name?, root? }`; the first created
1991
+ * agent roots it when `root` is absent). Each created agent's private key
1992
+ * is cached, like `register()`, so the SDK can sign for it at once. The
1993
+ * plan allowance is checked for the whole batch first; a single failure is
1994
+ * listed in `failed`, not thrown.
1995
+ */
1996
+ async registerMany(input) {
1997
+ const result = await this.post("/agents/bulk", input);
1998
+ for (const c of result?.created ?? []) {
1999
+ const id = c?.agent?.agent_id;
2000
+ if (id && c?.private_key) this.agentKeys.set(id, c.private_key);
2001
+ }
2002
+ return result;
2003
+ }
2004
+ // ─── Declarative swarm spec (vorim.swarm/v1) ─────────────────────────
2005
+ /**
2006
+ * Create or update a swarm from a spec: root, members and who they report
2007
+ * to, guardians, charter, budget and shares, breakers, tripwires. Pass the
2008
+ * YAML or JSON text, or the parsed object. `dryRun` returns the plan
2009
+ * without writing. Needs an org key with `runtime:manage`.
2010
+ */
2011
+ async applySwarmSpec(spec, opts = {}) {
2012
+ const body = typeof spec === "string" ? { spec } : spec;
2013
+ return this.post(`/swarms/apply?dry_run=${opts.dryRun ? "true" : "false"}`, body);
2014
+ }
2015
+ /**
2016
+ * Rehearse a swarm: every active member against a scenario set, through
2017
+ * the real decision pipeline with nothing written, signed with the roster,
2018
+ * charter, budget and policy version it ran under. `preset: 'hazards'`
2019
+ * (default) runs generic side tasks plus one main task; `'replay'` re-judges
2020
+ * the swarm's last 100 decisions; `scenarios` runs your own (each with
2021
+ * `expect: 'allow' | 'not_allow' | 'deny' | 'escalate'`). Verdict is pass,
2022
+ * pass_with_findings or fail. Needs `runtime:manage`.
2023
+ */
2024
+ async rehearseSwarm(swarmId, input = {}) {
2025
+ return this.post(`/swarms/${encodeURIComponent(swarmId)}/rehearse`, input);
2026
+ }
2027
+ /** Past rehearsals, newest first (summary only; fetch `/swarms/:id/rehearsals/:rid` for the signed payload). */
2028
+ async listSwarmRehearsals(swarmId) {
2029
+ return this.get(`/swarms/${encodeURIComponent(swarmId)}/rehearsals`);
2030
+ }
2031
+ /**
2032
+ * A swarm's trust: `min` (gate on it: the least trusted active member),
2033
+ * `weighted_mean` (display, weighted by recent activity), `trimmed_mean`
2034
+ * (for anything derived from peer reports), per member.
2035
+ */
2036
+ async getSwarmScore(swarmId) {
2037
+ return this.get(`/swarms/${encodeURIComponent(swarmId)}/score`);
2038
+ }
2039
+ /**
2040
+ * Issue a platform-signed attestation of the swarm as it is now: roster
2041
+ * and its hash, policy version and rules hash, charter, budget, kills,
2042
+ * latest rehearsal, receipt chain head and the three scores. Valid 24 h.
2043
+ * Hand it to a counterparty; they verify it against GET /trust/keys.
2044
+ */
2045
+ async attestSwarm(swarmId) {
2046
+ return this.post(`/swarms/${encodeURIComponent(swarmId)}/attest`, {});
2047
+ }
2048
+ /** Past attestations, newest first (fetch one by id for the signed payload). */
2049
+ async listSwarmAttestations(swarmId) {
2050
+ return this.get(`/swarms/${encodeURIComponent(swarmId)}/attestations`);
2051
+ }
2052
+ /** A swarm as it is now, as a spec: `{ spec, yaml }`. Keep the YAML in git and apply it again. */
2053
+ async getSwarmSpec(swarmId) {
2054
+ return this.get(`/swarms/${encodeURIComponent(swarmId)}/spec`);
2055
+ }
2056
+ /**
2057
+ * A swarm's attention picture: escalations in the last hour against its
2058
+ * budget, the rate to expect, median time to resolve, mean time between
2059
+ * interventions, and the fan-out estimate after Olsen and Goodrich (how
2060
+ * many swarms like this one person could supervise).
2061
+ */
2062
+ async getSwarmAttention(swarmId) {
2063
+ return this.get(`/swarms/${encodeURIComponent(swarmId)}/attention`);
2064
+ }
2065
+ /**
2066
+ * Set the swarm's attention budget: `perHour` escalations per rolling hour
2067
+ * a person may be asked to read (null = no budget). Past it `onExceed`
2068
+ * decides: 'deny' (the escalation is denied unread, the default) or
2069
+ * 'suspend' (the whole swarm stops). Returns the swarm detail.
2070
+ */
2071
+ async setSwarmAttention(swarmId, input) {
2072
+ const body = {};
2073
+ if (input.perHour !== void 0) body.attention_budget_per_hour = input.perHour;
2074
+ if (input.onExceed !== void 0) body.attention_exceeded_action = input.onExceed;
2075
+ return this.patch(`/swarms/${encodeURIComponent(swarmId)}`, body);
2076
+ }
2077
+ // ─── OpenTelemetry ───────────────────────────────────────────────────
2078
+ /**
2079
+ * Attributes for the agent's own spans: the OTel GenAI `gen_ai.agent.id`
2080
+ * plus Vorim's swarm and parent-agent ids (the conventions have no field
2081
+ * for either), so any OTel backend can group a swarm's spans. Cached for
2082
+ * 60 seconds per agent. Pass the active span's trace/span id back to
2083
+ * `beforeAction` / `emit` and Vorim's OTLP connector parents its spans
2084
+ * under yours.
2085
+ */
2086
+ async otelAttributes(agentId) {
2087
+ const cached = this.otelCache.get(agentId);
2088
+ if (cached && cached.expires > Date.now()) return cached.attrs;
2089
+ const attrs = { "gen_ai.agent.id": agentId, "vorim.agent.id": agentId };
2090
+ try {
2091
+ const swarm = await this.getSwarm(agentId);
2092
+ if (swarm?.swarm_id) {
2093
+ attrs["vorim.swarm.id"] = swarm.swarm_id;
2094
+ const me = swarm.members?.find((m) => m.agent_id === agentId);
2095
+ if (me?.parent_agent_id) attrs["vorim.parent_agent.id"] = me.parent_agent_id;
2096
+ }
2097
+ } catch {
2098
+ }
2099
+ this.otelCache.set(agentId, { attrs, expires: Date.now() + 6e4 });
2100
+ return attrs;
2101
+ }
2102
+ otelCache = /* @__PURE__ */ new Map();
2103
+ // ─── Guardian agents ─────────────────────────────────────────────────
2104
+ //
2105
+ // An agent with metadata.class = 'guardian' judges escalations that a rule
2106
+ // with approver_role 'guardian' assigned to its swarm. It reads the queue
2107
+ // from the server (never from a peer) and answers with a verdict signed by
2108
+ // its own key over one canonical line, so the approval is verifiable
2109
+ // offline against the agent's registered public key. An unanswered
2110
+ // escalation times out as denied: an absent guardian fails closed.
2111
+ /** Pending escalations this guardian may judge (empty for a non-guardian). */
2112
+ async listGuardianEscalations(agentId) {
2113
+ return this.get(`/runtime/guardian/escalations?agent_id=${encodeURIComponent(agentId)}`);
2114
+ }
2115
+ /**
2116
+ * Approve or veto an escalation as a guardian. Needs the agent's private
2117
+ * key (loaded by register(), registerEphemeral() or useAgentKey()). A
2118
+ * quorum rule returns `{ status: 'partial', approvals, required_approvals }`
2119
+ * until enough distinct approvals arrive; one veto denies at once.
2120
+ */
2121
+ async guardianResolve(agentId, decisionId, resolution) {
2122
+ const key = this.agentKeys.get(agentId);
2123
+ if (!key) {
2124
+ throw new VorimError(
2125
+ 400,
2126
+ "AGENT_KEY_NOT_LOADED",
2127
+ `No private key is cached for agent ${agentId}. Call register() or useAgentKey(agentId, privateKeyPem) first.`
2128
+ );
2129
+ }
2130
+ const signedAt = (/* @__PURE__ */ new Date()).toISOString();
2131
+ const line = `vorim-escalation-approval|v1|${decisionId}|${resolution}|agent:${agentId}|${signedAt}`;
2132
+ const signature = await this.sign(line, key);
2133
+ return this.post("/runtime/guardian/resolve", {
2134
+ agent_id: agentId,
2135
+ decision_id: decisionId,
2136
+ resolution,
2137
+ signed_at: signedAt,
2138
+ signature
2139
+ });
2140
+ }
1939
2141
  // ─── Credential Delegation ──────────────────────────────────────────
1940
2142
  /**
1941
2143
  * Register an OAuth provider for credential delegation.
@@ -2251,6 +2453,7 @@ async function deviceLogin(opts) {
2251
2453
  createSignatureBase,
2252
2454
  deviceLogin,
2253
2455
  eventDigest,
2456
+ foldTraceparent,
2254
2457
  hashPayload,
2255
2458
  hashPreviousEvent,
2256
2459
  hashSystemPrompt,