@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.
- package/CHANGELOG.md +30 -0
- package/dist/_commerce-core-Dyr_dHVP.d.ts +156 -0
- package/dist/_commerce-core-wY2jC6rC.d.cts +156 -0
- package/dist/index.cjs +217 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +200 -16
- package/dist/index.d.ts +200 -16
- package/dist/index.js +216 -14
- package/dist/index.js.map +1 -1
- package/dist/integrations/amazon.cjs +357 -0
- package/dist/integrations/amazon.cjs.map +1 -0
- package/dist/integrations/amazon.d.cts +88 -0
- package/dist/integrations/amazon.d.ts +88 -0
- package/dist/integrations/amazon.js +328 -0
- package/dist/integrations/amazon.js.map +1 -0
- package/dist/integrations/anthropic.d.cts +1 -1
- package/dist/integrations/anthropic.d.ts +1 -1
- package/dist/integrations/ap2.d.cts +1 -1
- package/dist/integrations/ap2.d.ts +1 -1
- package/dist/integrations/aws-iam.d.cts +1 -1
- package/dist/integrations/aws-iam.d.ts +1 -1
- package/dist/integrations/bank-rails.d.cts +1 -1
- package/dist/integrations/bank-rails.d.ts +1 -1
- package/dist/integrations/circle.d.cts +1 -1
- package/dist/integrations/circle.d.ts +1 -1
- package/dist/integrations/cloudflare.d.cts +1 -1
- package/dist/integrations/cloudflare.d.ts +1 -1
- package/dist/integrations/coinbase-cdp.d.cts +1 -1
- package/dist/integrations/coinbase-cdp.d.ts +1 -1
- package/dist/integrations/commerce-agents.d.cts +1 -1
- package/dist/integrations/commerce-agents.d.ts +1 -1
- package/dist/integrations/crewai.d.cts +1 -1
- package/dist/integrations/crewai.d.ts +1 -1
- package/dist/integrations/delivery.cjs +327 -0
- package/dist/integrations/delivery.cjs.map +1 -0
- package/dist/integrations/delivery.d.cts +33 -0
- package/dist/integrations/delivery.d.ts +33 -0
- package/dist/integrations/delivery.js +296 -0
- package/dist/integrations/delivery.js.map +1 -0
- package/dist/integrations/ebay.cjs +350 -0
- package/dist/integrations/ebay.cjs.map +1 -0
- package/dist/integrations/ebay.d.cts +73 -0
- package/dist/integrations/ebay.d.ts +73 -0
- package/dist/integrations/ebay.js +321 -0
- package/dist/integrations/ebay.js.map +1 -0
- package/dist/integrations/entra.d.cts +1 -1
- package/dist/integrations/entra.d.ts +1 -1
- package/dist/integrations/etsy.cjs +330 -0
- package/dist/integrations/etsy.cjs.map +1 -0
- package/dist/integrations/etsy.d.cts +41 -0
- package/dist/integrations/etsy.d.ts +41 -0
- package/dist/integrations/etsy.js +301 -0
- package/dist/integrations/etsy.js.map +1 -0
- package/dist/integrations/fhir.d.cts +1 -1
- package/dist/integrations/fhir.d.ts +1 -1
- package/dist/integrations/google-merchant.cjs +332 -0
- package/dist/integrations/google-merchant.cjs.map +1 -0
- package/dist/integrations/google-merchant.d.cts +43 -0
- package/dist/integrations/google-merchant.d.ts +43 -0
- package/dist/integrations/google-merchant.js +303 -0
- package/dist/integrations/google-merchant.js.map +1 -0
- package/dist/integrations/grok.d.cts +1 -1
- package/dist/integrations/grok.d.ts +1 -1
- package/dist/integrations/guidewire.d.cts +1 -1
- package/dist/integrations/guidewire.d.ts +1 -1
- package/dist/integrations/hermes.d.cts +1 -1
- package/dist/integrations/hermes.d.ts +1 -1
- package/dist/integrations/jira.d.cts +1 -1
- package/dist/integrations/jira.d.ts +1 -1
- package/dist/integrations/langchain.d.cts +1 -1
- package/dist/integrations/langchain.d.ts +1 -1
- package/dist/integrations/langgraph.d.cts +1 -1
- package/dist/integrations/langgraph.d.ts +1 -1
- package/dist/integrations/legal.d.cts +1 -1
- package/dist/integrations/legal.d.ts +1 -1
- package/dist/integrations/life-sciences.d.cts +1 -1
- package/dist/integrations/life-sciences.d.ts +1 -1
- package/dist/integrations/linear.d.cts +1 -1
- package/dist/integrations/linear.d.ts +1 -1
- package/dist/integrations/lithic.d.cts +1 -1
- package/dist/integrations/lithic.d.ts +1 -1
- package/dist/integrations/llamaindex.d.cts +1 -1
- package/dist/integrations/llamaindex.d.ts +1 -1
- package/dist/integrations/marqeta.d.cts +1 -1
- package/dist/integrations/marqeta.d.ts +1 -1
- package/dist/integrations/meta.cjs +375 -0
- package/dist/integrations/meta.cjs.map +1 -0
- package/dist/integrations/meta.d.cts +83 -0
- package/dist/integrations/meta.d.ts +83 -0
- package/dist/integrations/meta.js +346 -0
- package/dist/integrations/meta.js.map +1 -0
- package/dist/integrations/modern-treasury.d.cts +1 -1
- package/dist/integrations/modern-treasury.d.ts +1 -1
- package/dist/integrations/muse.d.cts +1 -1
- package/dist/integrations/muse.d.ts +1 -1
- package/dist/integrations/nekuda.d.cts +1 -1
- package/dist/integrations/nekuda.d.ts +1 -1
- package/dist/integrations/okta.d.cts +1 -1
- package/dist/integrations/okta.d.ts +1 -1
- package/dist/integrations/openai.d.cts +1 -1
- package/dist/integrations/openai.d.ts +1 -1
- package/dist/integrations/openrouter.d.cts +1 -1
- package/dist/integrations/openrouter.d.ts +1 -1
- package/dist/integrations/paypal-agent.d.cts +1 -1
- package/dist/integrations/paypal-agent.d.ts +1 -1
- package/dist/integrations/perplexity.d.cts +1 -1
- package/dist/integrations/perplexity.d.ts +1 -1
- package/dist/integrations/plaid.d.cts +1 -1
- package/dist/integrations/plaid.d.ts +1 -1
- package/dist/integrations/ramp.d.cts +1 -1
- package/dist/integrations/ramp.d.ts +1 -1
- package/dist/integrations/shopify.d.cts +1 -1
- package/dist/integrations/shopify.d.ts +1 -1
- package/dist/integrations/siem.d.cts +1 -1
- package/dist/integrations/siem.d.ts +1 -1
- package/dist/integrations/skyfire.d.cts +1 -1
- package/dist/integrations/skyfire.d.ts +1 -1
- package/dist/integrations/social-ads.cjs +328 -0
- package/dist/integrations/social-ads.cjs.map +1 -0
- package/dist/integrations/social-ads.d.cts +36 -0
- package/dist/integrations/social-ads.d.ts +36 -0
- package/dist/integrations/social-ads.js +297 -0
- package/dist/integrations/social-ads.js.map +1 -0
- package/dist/integrations/stripe-acp.d.cts +1 -1
- package/dist/integrations/stripe-acp.d.ts +1 -1
- package/dist/integrations/stripe-issuing.d.cts +1 -1
- package/dist/integrations/stripe-issuing.d.ts +1 -1
- package/dist/integrations/tiktok-shop.cjs +334 -0
- package/dist/integrations/tiktok-shop.cjs.map +1 -0
- package/dist/integrations/tiktok-shop.d.cts +44 -0
- package/dist/integrations/tiktok-shop.d.ts +44 -0
- package/dist/integrations/tiktok-shop.js +305 -0
- package/dist/integrations/tiktok-shop.js.map +1 -0
- package/dist/integrations/truanon.d.cts +1 -1
- package/dist/integrations/truanon.d.ts +1 -1
- package/dist/integrations/typesafe.d.cts +1 -1
- package/dist/integrations/typesafe.d.ts +1 -1
- package/dist/integrations/ucp.d.cts +1 -1
- package/dist/integrations/ucp.d.ts +1 -1
- package/dist/integrations/vercel-ai.d.cts +1 -1
- package/dist/integrations/vercel-ai.d.ts +1 -1
- package/dist/integrations/walmart.cjs +344 -0
- package/dist/integrations/walmart.cjs.map +1 -0
- package/dist/integrations/walmart.d.cts +60 -0
- package/dist/integrations/walmart.d.ts +60 -0
- package/dist/integrations/walmart.js +315 -0
- package/dist/integrations/walmart.js.map +1 -0
- package/dist/integrations/x402.d.cts +1 -1
- package/dist/integrations/x402.d.ts +1 -1
- package/dist/{types-BrDQAJdl.d.cts → types-DphtTyIC.d.cts} +72 -3
- package/dist/{types-BrDQAJdl.d.ts → types-DphtTyIC.d.ts} +72 -3
- package/package.json +92 -2
package/dist/index.js
CHANGED
|
@@ -867,7 +867,7 @@ async function verifyHttpRequest(request, options) {
|
|
|
867
867
|
}
|
|
868
868
|
|
|
869
869
|
// src/index.ts
|
|
870
|
-
var SDK_VERSION = true ? "
|
|
870
|
+
var SDK_VERSION = true ? "4.1.0" : "0.0.0";
|
|
871
871
|
var USER_AGENT = `vorim-sdk/${SDK_VERSION}`;
|
|
872
872
|
function sleep(ms) {
|
|
873
873
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -910,6 +910,17 @@ function toApprovalAttestation(raw) {
|
|
|
910
910
|
signature: raw.signature
|
|
911
911
|
};
|
|
912
912
|
}
|
|
913
|
+
function foldTraceparent(input) {
|
|
914
|
+
if (!input.traceparent) return input;
|
|
915
|
+
const { traceparent, ...rest } = input;
|
|
916
|
+
const m = /^[0-9a-f]{2}-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$/i.exec(traceparent.trim());
|
|
917
|
+
const out = { ...rest };
|
|
918
|
+
if (m) {
|
|
919
|
+
if (!out.trace_id) out.trace_id = m[1].toLowerCase();
|
|
920
|
+
if (!out.span_id) out.span_id = m[2].toLowerCase();
|
|
921
|
+
}
|
|
922
|
+
return out;
|
|
923
|
+
}
|
|
913
924
|
var VorimSDK = class _VorimSDK {
|
|
914
925
|
apiKey;
|
|
915
926
|
baseUrl;
|
|
@@ -965,7 +976,7 @@ var VorimSDK = class _VorimSDK {
|
|
|
965
976
|
}
|
|
966
977
|
}
|
|
967
978
|
this.chainEvents = config.chainEvents ?? false;
|
|
968
|
-
this.runtimeFailOpen = config.runtimeFailOpen ??
|
|
979
|
+
this.runtimeFailOpen = config.runtimeFailOpen ?? false;
|
|
969
980
|
this.noPayload = config.noPayload !== void 0 && config.noPayload !== false;
|
|
970
981
|
this.maxMetadataChars = typeof config.noPayload === "object" && typeof config.noPayload.maxMetadataChars === "number" ? config.noPayload.maxMetadataChars : 256;
|
|
971
982
|
}
|
|
@@ -1068,11 +1079,26 @@ var VorimSDK = class _VorimSDK {
|
|
|
1068
1079
|
return { agents: env.data ?? [], meta: env.meta ?? null };
|
|
1069
1080
|
}
|
|
1070
1081
|
/**
|
|
1071
|
-
* Update an agent's metadata.
|
|
1082
|
+
* Update an agent's metadata or status.
|
|
1083
|
+
*
|
|
1084
|
+
* `status: 'suspended'` is the kill switch and, since 4.0.0, cascades to
|
|
1085
|
+
* every agent reachable through the agent's active identity delegations
|
|
1086
|
+
* unless `cascade: false`. Setting `status: 'active'` on a suspended agent
|
|
1087
|
+
* reverses exactly that cascade. The returned agent carries
|
|
1088
|
+
* `cascade.suspended` / `cascade.reactivated` with the agent ids touched.
|
|
1089
|
+
* See {@link suspendPreview} for the blast radius before acting.
|
|
1072
1090
|
*/
|
|
1073
1091
|
async updateAgent(agentId, updates) {
|
|
1074
1092
|
return this.patch(`/agents/${agentId}`, updates);
|
|
1075
1093
|
}
|
|
1094
|
+
/**
|
|
1095
|
+
* What suspending (or revoking) this agent would touch: its delegation
|
|
1096
|
+
* subtree, how many of those agents are still active, open escalations
|
|
1097
|
+
* across the subtree, and live delegation links. Writes nothing.
|
|
1098
|
+
*/
|
|
1099
|
+
async suspendPreview(agentId) {
|
|
1100
|
+
return this.get(`/agents/${agentId}/suspend-preview`);
|
|
1101
|
+
}
|
|
1076
1102
|
/**
|
|
1077
1103
|
* Revoke an agent (permanent deactivation).
|
|
1078
1104
|
*/
|
|
@@ -1432,9 +1458,9 @@ var VorimSDK = class _VorimSDK {
|
|
|
1432
1458
|
* poll {@link waitForDecisionResolution} for the human decision.
|
|
1433
1459
|
*
|
|
1434
1460
|
* Transport failures (network/DNS/timeout/5xx) respect the constructor's
|
|
1435
|
-
* `runtimeFailOpen` flag: when
|
|
1436
|
-
*
|
|
1437
|
-
*
|
|
1461
|
+
* `runtimeFailOpen` flag: when false (default) the underlying error is
|
|
1462
|
+
* re-thrown; when true a synthetic `fallback` decision is returned so a
|
|
1463
|
+
* control-plane blip does not block the agent.
|
|
1438
1464
|
*
|
|
1439
1465
|
* Always pass the public `agid_*` id as `agentId`.
|
|
1440
1466
|
*
|
|
@@ -1459,7 +1485,10 @@ var VorimSDK = class _VorimSDK {
|
|
|
1459
1485
|
required_scope: input.requiredScope,
|
|
1460
1486
|
idempotency_key: input.idempotencyKey,
|
|
1461
1487
|
workflow_id: input.workflowId,
|
|
1462
|
-
estimated_tokens: input.estimatedTokens
|
|
1488
|
+
estimated_tokens: input.estimatedTokens,
|
|
1489
|
+
trace_id: input.traceId,
|
|
1490
|
+
span_id: input.spanId,
|
|
1491
|
+
traceparent: input.traceparent
|
|
1463
1492
|
};
|
|
1464
1493
|
let raw;
|
|
1465
1494
|
try {
|
|
@@ -1479,6 +1508,7 @@ var VorimSDK = class _VorimSDK {
|
|
|
1479
1508
|
latencyMs: 0,
|
|
1480
1509
|
isFallback: true,
|
|
1481
1510
|
policyVersion: 0,
|
|
1511
|
+
swarmId: null,
|
|
1482
1512
|
escalationResolution: null,
|
|
1483
1513
|
approval: null
|
|
1484
1514
|
};
|
|
@@ -1497,12 +1527,18 @@ var VorimSDK = class _VorimSDK {
|
|
|
1497
1527
|
// Enforcement runs inside beforeAction(): pass `workflowId` + `estimatedTokens`
|
|
1498
1528
|
// on the action, and a `token_budget_gt` policy rule denies the action before
|
|
1499
1529
|
// the spend if it would breach the budget. These methods manage the budgets
|
|
1500
|
-
// and read live spend
|
|
1501
|
-
//
|
|
1530
|
+
// and read live spend. They need an API key holding the `runtime:manage`
|
|
1531
|
+
// scope (deliberately separate from `runtime:decide`, so an agent's own key
|
|
1532
|
+
// cannot raise its ceiling).
|
|
1502
1533
|
/**
|
|
1503
1534
|
* Create or update a token budget for an agent or workflow. One budget per
|
|
1504
1535
|
* (scope, scope_ref) — calling this again for the same target updates it.
|
|
1505
1536
|
*
|
|
1537
|
+
* A budget is a ceiling; a policy rule enforces it. Add a rule with
|
|
1538
|
+
* `match_conditions: { token_budget_gt: { scope } }` and a `deny` (or
|
|
1539
|
+
* `escalate`) decision, otherwise actions are still allowed once the budget
|
|
1540
|
+
* is used up.
|
|
1541
|
+
*
|
|
1506
1542
|
* @example
|
|
1507
1543
|
* await vorim.setBudget({
|
|
1508
1544
|
* scope: 'workflow', scope_ref: 'nightly-summariser',
|
|
@@ -1593,19 +1629,20 @@ var VorimSDK = class _VorimSDK {
|
|
|
1593
1629
|
* row's `decision` column off `'escalate'`. If we returned that verbatim,
|
|
1594
1630
|
* a caller's obvious `if (d.decision === 'deny')` check would never fire
|
|
1595
1631
|
* on a human DENIAL — a silent fail-open. So when a resolution is present
|
|
1596
|
-
* we translate the verdict: approved → 'allow', denied → 'deny'
|
|
1597
|
-
*
|
|
1598
|
-
*
|
|
1632
|
+
* we translate the verdict: approved → 'allow', denied → 'deny', and
|
|
1633
|
+
* timed_out (nobody answered within the org's escalation window) → 'deny'.
|
|
1634
|
+
* The raw resolution is also surfaced as `escalationResolution` for
|
|
1635
|
+
* callers that want it explicitly.
|
|
1599
1636
|
*
|
|
1600
1637
|
* A missing verdict (malformed/truncated response) fails CLOSED to 'deny'
|
|
1601
1638
|
* rather than 'fallback', so the deny check fires on garbled input.
|
|
1602
1639
|
*/
|
|
1603
1640
|
toRuntimeDecision(raw) {
|
|
1604
|
-
const resolution = raw?.escalation_resolution === "approved" ? "approved" : raw?.escalation_resolution === "denied" ? "denied" : null;
|
|
1641
|
+
const resolution = raw?.escalation_resolution === "approved" ? "approved" : raw?.escalation_resolution === "denied" ? "denied" : raw?.escalation_resolution === "timed_out" ? "timed_out" : null;
|
|
1605
1642
|
const hasVerdict = typeof raw?.decision === "string";
|
|
1606
1643
|
let decision;
|
|
1607
1644
|
if (raw?.decision === "escalate" && resolution === "approved") decision = "allow";
|
|
1608
|
-
else if (raw?.decision === "escalate" && resolution === "denied") decision = "deny";
|
|
1645
|
+
else if (raw?.decision === "escalate" && (resolution === "denied" || resolution === "timed_out")) decision = "deny";
|
|
1609
1646
|
else if (hasVerdict) decision = raw.decision;
|
|
1610
1647
|
else decision = "deny";
|
|
1611
1648
|
return {
|
|
@@ -1620,6 +1657,7 @@ var VorimSDK = class _VorimSDK {
|
|
|
1620
1657
|
latencyMs: raw?.latency_ms ?? 0,
|
|
1621
1658
|
isFallback: raw?.is_fallback ?? !hasVerdict,
|
|
1622
1659
|
policyVersion: raw?.policy_version ?? 0,
|
|
1660
|
+
swarmId: typeof raw?.swarm_id === "string" ? raw.swarm_id : null,
|
|
1623
1661
|
escalationResolution: resolution,
|
|
1624
1662
|
approval: toApprovalAttestation(raw?.approval)
|
|
1625
1663
|
};
|
|
@@ -1754,6 +1792,7 @@ var VorimSDK = class _VorimSDK {
|
|
|
1754
1792
|
}
|
|
1755
1793
|
async prepareEvent(event, signOverride) {
|
|
1756
1794
|
this.assertNoPayload(event);
|
|
1795
|
+
event = foldTraceparent(event);
|
|
1757
1796
|
const shouldSign = signOverride ?? this.autoSign;
|
|
1758
1797
|
if (!shouldSign && !this.chainEvents) return event;
|
|
1759
1798
|
if (this.chainEvents) {
|
|
@@ -1873,6 +1912,168 @@ var VorimSDK = class _VorimSDK {
|
|
|
1873
1912
|
}
|
|
1874
1913
|
return result;
|
|
1875
1914
|
}
|
|
1915
|
+
/**
|
|
1916
|
+
* The server-minted swarm an agent belongs to and every member of it.
|
|
1917
|
+
* `{ swarm_id: null, members: [] }` for a standalone agent.
|
|
1918
|
+
*/
|
|
1919
|
+
async getSwarm(agentId) {
|
|
1920
|
+
return this.get(`/agents/${agentId}/swarm`);
|
|
1921
|
+
}
|
|
1922
|
+
// ─── Many agents at once ─────────────────────────────────────────────
|
|
1923
|
+
/**
|
|
1924
|
+
* Register up to 50 agents in one call: an explicit list, or a template
|
|
1925
|
+
* repeated `count` times (names `<prefix>-1` .. `<prefix>-N`), optionally
|
|
1926
|
+
* grouped into a new swarm (`swarm: { name?, root? }`; the first created
|
|
1927
|
+
* agent roots it when `root` is absent). Each created agent's private key
|
|
1928
|
+
* is cached, like `register()`, so the SDK can sign for it at once. The
|
|
1929
|
+
* plan allowance is checked for the whole batch first; a single failure is
|
|
1930
|
+
* listed in `failed`, not thrown.
|
|
1931
|
+
*/
|
|
1932
|
+
async registerMany(input) {
|
|
1933
|
+
const result = await this.post("/agents/bulk", input);
|
|
1934
|
+
for (const c of result?.created ?? []) {
|
|
1935
|
+
const id = c?.agent?.agent_id;
|
|
1936
|
+
if (id && c?.private_key) this.agentKeys.set(id, c.private_key);
|
|
1937
|
+
}
|
|
1938
|
+
return result;
|
|
1939
|
+
}
|
|
1940
|
+
// ─── Declarative swarm spec (vorim.swarm/v1) ─────────────────────────
|
|
1941
|
+
/**
|
|
1942
|
+
* Create or update a swarm from a spec: root, members and who they report
|
|
1943
|
+
* to, guardians, charter, budget and shares, breakers, tripwires. Pass the
|
|
1944
|
+
* YAML or JSON text, or the parsed object. `dryRun` returns the plan
|
|
1945
|
+
* without writing. Needs an org key with `runtime:manage`.
|
|
1946
|
+
*/
|
|
1947
|
+
async applySwarmSpec(spec, opts = {}) {
|
|
1948
|
+
const body = typeof spec === "string" ? { spec } : spec;
|
|
1949
|
+
return this.post(`/swarms/apply?dry_run=${opts.dryRun ? "true" : "false"}`, body);
|
|
1950
|
+
}
|
|
1951
|
+
/**
|
|
1952
|
+
* Rehearse a swarm: every active member against a scenario set, through
|
|
1953
|
+
* the real decision pipeline with nothing written, signed with the roster,
|
|
1954
|
+
* charter, budget and policy version it ran under. `preset: 'hazards'`
|
|
1955
|
+
* (default) runs generic side tasks plus one main task; `'replay'` re-judges
|
|
1956
|
+
* the swarm's last 100 decisions; `scenarios` runs your own (each with
|
|
1957
|
+
* `expect: 'allow' | 'not_allow' | 'deny' | 'escalate'`). Verdict is pass,
|
|
1958
|
+
* pass_with_findings or fail. Needs `runtime:manage`.
|
|
1959
|
+
*/
|
|
1960
|
+
async rehearseSwarm(swarmId, input = {}) {
|
|
1961
|
+
return this.post(`/swarms/${encodeURIComponent(swarmId)}/rehearse`, input);
|
|
1962
|
+
}
|
|
1963
|
+
/** Past rehearsals, newest first (summary only; fetch `/swarms/:id/rehearsals/:rid` for the signed payload). */
|
|
1964
|
+
async listSwarmRehearsals(swarmId) {
|
|
1965
|
+
return this.get(`/swarms/${encodeURIComponent(swarmId)}/rehearsals`);
|
|
1966
|
+
}
|
|
1967
|
+
/**
|
|
1968
|
+
* A swarm's trust: `min` (gate on it: the least trusted active member),
|
|
1969
|
+
* `weighted_mean` (display, weighted by recent activity), `trimmed_mean`
|
|
1970
|
+
* (for anything derived from peer reports), per member.
|
|
1971
|
+
*/
|
|
1972
|
+
async getSwarmScore(swarmId) {
|
|
1973
|
+
return this.get(`/swarms/${encodeURIComponent(swarmId)}/score`);
|
|
1974
|
+
}
|
|
1975
|
+
/**
|
|
1976
|
+
* Issue a platform-signed attestation of the swarm as it is now: roster
|
|
1977
|
+
* and its hash, policy version and rules hash, charter, budget, kills,
|
|
1978
|
+
* latest rehearsal, receipt chain head and the three scores. Valid 24 h.
|
|
1979
|
+
* Hand it to a counterparty; they verify it against GET /trust/keys.
|
|
1980
|
+
*/
|
|
1981
|
+
async attestSwarm(swarmId) {
|
|
1982
|
+
return this.post(`/swarms/${encodeURIComponent(swarmId)}/attest`, {});
|
|
1983
|
+
}
|
|
1984
|
+
/** Past attestations, newest first (fetch one by id for the signed payload). */
|
|
1985
|
+
async listSwarmAttestations(swarmId) {
|
|
1986
|
+
return this.get(`/swarms/${encodeURIComponent(swarmId)}/attestations`);
|
|
1987
|
+
}
|
|
1988
|
+
/** A swarm as it is now, as a spec: `{ spec, yaml }`. Keep the YAML in git and apply it again. */
|
|
1989
|
+
async getSwarmSpec(swarmId) {
|
|
1990
|
+
return this.get(`/swarms/${encodeURIComponent(swarmId)}/spec`);
|
|
1991
|
+
}
|
|
1992
|
+
/**
|
|
1993
|
+
* A swarm's attention picture: escalations in the last hour against its
|
|
1994
|
+
* budget, the rate to expect, median time to resolve, mean time between
|
|
1995
|
+
* interventions, and the fan-out estimate after Olsen and Goodrich (how
|
|
1996
|
+
* many swarms like this one person could supervise).
|
|
1997
|
+
*/
|
|
1998
|
+
async getSwarmAttention(swarmId) {
|
|
1999
|
+
return this.get(`/swarms/${encodeURIComponent(swarmId)}/attention`);
|
|
2000
|
+
}
|
|
2001
|
+
/**
|
|
2002
|
+
* Set the swarm's attention budget: `perHour` escalations per rolling hour
|
|
2003
|
+
* a person may be asked to read (null = no budget). Past it `onExceed`
|
|
2004
|
+
* decides: 'deny' (the escalation is denied unread, the default) or
|
|
2005
|
+
* 'suspend' (the whole swarm stops). Returns the swarm detail.
|
|
2006
|
+
*/
|
|
2007
|
+
async setSwarmAttention(swarmId, input) {
|
|
2008
|
+
const body = {};
|
|
2009
|
+
if (input.perHour !== void 0) body.attention_budget_per_hour = input.perHour;
|
|
2010
|
+
if (input.onExceed !== void 0) body.attention_exceeded_action = input.onExceed;
|
|
2011
|
+
return this.patch(`/swarms/${encodeURIComponent(swarmId)}`, body);
|
|
2012
|
+
}
|
|
2013
|
+
// ─── OpenTelemetry ───────────────────────────────────────────────────
|
|
2014
|
+
/**
|
|
2015
|
+
* Attributes for the agent's own spans: the OTel GenAI `gen_ai.agent.id`
|
|
2016
|
+
* plus Vorim's swarm and parent-agent ids (the conventions have no field
|
|
2017
|
+
* for either), so any OTel backend can group a swarm's spans. Cached for
|
|
2018
|
+
* 60 seconds per agent. Pass the active span's trace/span id back to
|
|
2019
|
+
* `beforeAction` / `emit` and Vorim's OTLP connector parents its spans
|
|
2020
|
+
* under yours.
|
|
2021
|
+
*/
|
|
2022
|
+
async otelAttributes(agentId) {
|
|
2023
|
+
const cached = this.otelCache.get(agentId);
|
|
2024
|
+
if (cached && cached.expires > Date.now()) return cached.attrs;
|
|
2025
|
+
const attrs = { "gen_ai.agent.id": agentId, "vorim.agent.id": agentId };
|
|
2026
|
+
try {
|
|
2027
|
+
const swarm = await this.getSwarm(agentId);
|
|
2028
|
+
if (swarm?.swarm_id) {
|
|
2029
|
+
attrs["vorim.swarm.id"] = swarm.swarm_id;
|
|
2030
|
+
const me = swarm.members?.find((m) => m.agent_id === agentId);
|
|
2031
|
+
if (me?.parent_agent_id) attrs["vorim.parent_agent.id"] = me.parent_agent_id;
|
|
2032
|
+
}
|
|
2033
|
+
} catch {
|
|
2034
|
+
}
|
|
2035
|
+
this.otelCache.set(agentId, { attrs, expires: Date.now() + 6e4 });
|
|
2036
|
+
return attrs;
|
|
2037
|
+
}
|
|
2038
|
+
otelCache = /* @__PURE__ */ new Map();
|
|
2039
|
+
// ─── Guardian agents ─────────────────────────────────────────────────
|
|
2040
|
+
//
|
|
2041
|
+
// An agent with metadata.class = 'guardian' judges escalations that a rule
|
|
2042
|
+
// with approver_role 'guardian' assigned to its swarm. It reads the queue
|
|
2043
|
+
// from the server (never from a peer) and answers with a verdict signed by
|
|
2044
|
+
// its own key over one canonical line, so the approval is verifiable
|
|
2045
|
+
// offline against the agent's registered public key. An unanswered
|
|
2046
|
+
// escalation times out as denied: an absent guardian fails closed.
|
|
2047
|
+
/** Pending escalations this guardian may judge (empty for a non-guardian). */
|
|
2048
|
+
async listGuardianEscalations(agentId) {
|
|
2049
|
+
return this.get(`/runtime/guardian/escalations?agent_id=${encodeURIComponent(agentId)}`);
|
|
2050
|
+
}
|
|
2051
|
+
/**
|
|
2052
|
+
* Approve or veto an escalation as a guardian. Needs the agent's private
|
|
2053
|
+
* key (loaded by register(), registerEphemeral() or useAgentKey()). A
|
|
2054
|
+
* quorum rule returns `{ status: 'partial', approvals, required_approvals }`
|
|
2055
|
+
* until enough distinct approvals arrive; one veto denies at once.
|
|
2056
|
+
*/
|
|
2057
|
+
async guardianResolve(agentId, decisionId, resolution) {
|
|
2058
|
+
const key = this.agentKeys.get(agentId);
|
|
2059
|
+
if (!key) {
|
|
2060
|
+
throw new VorimError(
|
|
2061
|
+
400,
|
|
2062
|
+
"AGENT_KEY_NOT_LOADED",
|
|
2063
|
+
`No private key is cached for agent ${agentId}. Call register() or useAgentKey(agentId, privateKeyPem) first.`
|
|
2064
|
+
);
|
|
2065
|
+
}
|
|
2066
|
+
const signedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2067
|
+
const line = `vorim-escalation-approval|v1|${decisionId}|${resolution}|agent:${agentId}|${signedAt}`;
|
|
2068
|
+
const signature = await this.sign(line, key);
|
|
2069
|
+
return this.post("/runtime/guardian/resolve", {
|
|
2070
|
+
agent_id: agentId,
|
|
2071
|
+
decision_id: decisionId,
|
|
2072
|
+
resolution,
|
|
2073
|
+
signed_at: signedAt,
|
|
2074
|
+
signature
|
|
2075
|
+
});
|
|
2076
|
+
}
|
|
1876
2077
|
// ─── Credential Delegation ──────────────────────────────────────────
|
|
1877
2078
|
/**
|
|
1878
2079
|
* Register an OAuth provider for credential delegation.
|
|
@@ -2188,6 +2389,7 @@ export {
|
|
|
2188
2389
|
createVorim as default,
|
|
2189
2390
|
deviceLogin,
|
|
2190
2391
|
eventDigest,
|
|
2392
|
+
foldTraceparent,
|
|
2191
2393
|
hashPayload,
|
|
2192
2394
|
hashPreviousEvent,
|
|
2193
2395
|
hashSystemPrompt,
|