@vorim/sdk 3.23.0 → 4.0.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 +23 -0
- package/dist/index.cjs +212 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +195 -16
- package/dist/index.d.ts +195 -16
- package/dist/index.js +211 -14
- package/dist/index.js.map +1 -1
- 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/entra.d.cts +1 -1
- package/dist/integrations/entra.d.ts +1 -1
- package/dist/integrations/fhir.d.cts +1 -1
- package/dist/integrations/fhir.d.ts +1 -1
- 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/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/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/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/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 +1 -1
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.0.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,8 +1527,9 @@ 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.
|
|
@@ -1593,19 +1624,20 @@ var VorimSDK = class _VorimSDK {
|
|
|
1593
1624
|
* row's `decision` column off `'escalate'`. If we returned that verbatim,
|
|
1594
1625
|
* a caller's obvious `if (d.decision === 'deny')` check would never fire
|
|
1595
1626
|
* 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
|
-
*
|
|
1627
|
+
* we translate the verdict: approved → 'allow', denied → 'deny', and
|
|
1628
|
+
* timed_out (nobody answered within the org's escalation window) → 'deny'.
|
|
1629
|
+
* The raw resolution is also surfaced as `escalationResolution` for
|
|
1630
|
+
* callers that want it explicitly.
|
|
1599
1631
|
*
|
|
1600
1632
|
* A missing verdict (malformed/truncated response) fails CLOSED to 'deny'
|
|
1601
1633
|
* rather than 'fallback', so the deny check fires on garbled input.
|
|
1602
1634
|
*/
|
|
1603
1635
|
toRuntimeDecision(raw) {
|
|
1604
|
-
const resolution = raw?.escalation_resolution === "approved" ? "approved" : raw?.escalation_resolution === "denied" ? "denied" : null;
|
|
1636
|
+
const resolution = raw?.escalation_resolution === "approved" ? "approved" : raw?.escalation_resolution === "denied" ? "denied" : raw?.escalation_resolution === "timed_out" ? "timed_out" : null;
|
|
1605
1637
|
const hasVerdict = typeof raw?.decision === "string";
|
|
1606
1638
|
let decision;
|
|
1607
1639
|
if (raw?.decision === "escalate" && resolution === "approved") decision = "allow";
|
|
1608
|
-
else if (raw?.decision === "escalate" && resolution === "denied") decision = "deny";
|
|
1640
|
+
else if (raw?.decision === "escalate" && (resolution === "denied" || resolution === "timed_out")) decision = "deny";
|
|
1609
1641
|
else if (hasVerdict) decision = raw.decision;
|
|
1610
1642
|
else decision = "deny";
|
|
1611
1643
|
return {
|
|
@@ -1620,6 +1652,7 @@ var VorimSDK = class _VorimSDK {
|
|
|
1620
1652
|
latencyMs: raw?.latency_ms ?? 0,
|
|
1621
1653
|
isFallback: raw?.is_fallback ?? !hasVerdict,
|
|
1622
1654
|
policyVersion: raw?.policy_version ?? 0,
|
|
1655
|
+
swarmId: typeof raw?.swarm_id === "string" ? raw.swarm_id : null,
|
|
1623
1656
|
escalationResolution: resolution,
|
|
1624
1657
|
approval: toApprovalAttestation(raw?.approval)
|
|
1625
1658
|
};
|
|
@@ -1754,6 +1787,7 @@ var VorimSDK = class _VorimSDK {
|
|
|
1754
1787
|
}
|
|
1755
1788
|
async prepareEvent(event, signOverride) {
|
|
1756
1789
|
this.assertNoPayload(event);
|
|
1790
|
+
event = foldTraceparent(event);
|
|
1757
1791
|
const shouldSign = signOverride ?? this.autoSign;
|
|
1758
1792
|
if (!shouldSign && !this.chainEvents) return event;
|
|
1759
1793
|
if (this.chainEvents) {
|
|
@@ -1873,6 +1907,168 @@ var VorimSDK = class _VorimSDK {
|
|
|
1873
1907
|
}
|
|
1874
1908
|
return result;
|
|
1875
1909
|
}
|
|
1910
|
+
/**
|
|
1911
|
+
* The server-minted swarm an agent belongs to and every member of it.
|
|
1912
|
+
* `{ swarm_id: null, members: [] }` for a standalone agent.
|
|
1913
|
+
*/
|
|
1914
|
+
async getSwarm(agentId) {
|
|
1915
|
+
return this.get(`/agents/${agentId}/swarm`);
|
|
1916
|
+
}
|
|
1917
|
+
// ─── Many agents at once ─────────────────────────────────────────────
|
|
1918
|
+
/**
|
|
1919
|
+
* Register up to 50 agents in one call: an explicit list, or a template
|
|
1920
|
+
* repeated `count` times (names `<prefix>-1` .. `<prefix>-N`), optionally
|
|
1921
|
+
* grouped into a new swarm (`swarm: { name?, root? }`; the first created
|
|
1922
|
+
* agent roots it when `root` is absent). Each created agent's private key
|
|
1923
|
+
* is cached, like `register()`, so the SDK can sign for it at once. The
|
|
1924
|
+
* plan allowance is checked for the whole batch first; a single failure is
|
|
1925
|
+
* listed in `failed`, not thrown.
|
|
1926
|
+
*/
|
|
1927
|
+
async registerMany(input) {
|
|
1928
|
+
const result = await this.post("/agents/bulk", input);
|
|
1929
|
+
for (const c of result?.created ?? []) {
|
|
1930
|
+
const id = c?.agent?.agent_id;
|
|
1931
|
+
if (id && c?.private_key) this.agentKeys.set(id, c.private_key);
|
|
1932
|
+
}
|
|
1933
|
+
return result;
|
|
1934
|
+
}
|
|
1935
|
+
// ─── Declarative swarm spec (vorim.swarm/v1) ─────────────────────────
|
|
1936
|
+
/**
|
|
1937
|
+
* Create or update a swarm from a spec: root, members and who they report
|
|
1938
|
+
* to, guardians, charter, budget and shares, breakers, tripwires. Pass the
|
|
1939
|
+
* YAML or JSON text, or the parsed object. `dryRun` returns the plan
|
|
1940
|
+
* without writing. Needs an org key with `runtime:manage`.
|
|
1941
|
+
*/
|
|
1942
|
+
async applySwarmSpec(spec, opts = {}) {
|
|
1943
|
+
const body = typeof spec === "string" ? { spec } : spec;
|
|
1944
|
+
return this.post(`/swarms/apply?dry_run=${opts.dryRun ? "true" : "false"}`, body);
|
|
1945
|
+
}
|
|
1946
|
+
/**
|
|
1947
|
+
* Rehearse a swarm: every active member against a scenario set, through
|
|
1948
|
+
* the real decision pipeline with nothing written, signed with the roster,
|
|
1949
|
+
* charter, budget and policy version it ran under. `preset: 'hazards'`
|
|
1950
|
+
* (default) runs generic side tasks plus one main task; `'replay'` re-judges
|
|
1951
|
+
* the swarm's last 100 decisions; `scenarios` runs your own (each with
|
|
1952
|
+
* `expect: 'allow' | 'not_allow' | 'deny' | 'escalate'`). Verdict is pass,
|
|
1953
|
+
* pass_with_findings or fail. Needs `runtime:manage`.
|
|
1954
|
+
*/
|
|
1955
|
+
async rehearseSwarm(swarmId, input = {}) {
|
|
1956
|
+
return this.post(`/swarms/${encodeURIComponent(swarmId)}/rehearse`, input);
|
|
1957
|
+
}
|
|
1958
|
+
/** Past rehearsals, newest first (summary only; fetch `/swarms/:id/rehearsals/:rid` for the signed payload). */
|
|
1959
|
+
async listSwarmRehearsals(swarmId) {
|
|
1960
|
+
return this.get(`/swarms/${encodeURIComponent(swarmId)}/rehearsals`);
|
|
1961
|
+
}
|
|
1962
|
+
/**
|
|
1963
|
+
* A swarm's trust: `min` (gate on it: the least trusted active member),
|
|
1964
|
+
* `weighted_mean` (display, weighted by recent activity), `trimmed_mean`
|
|
1965
|
+
* (for anything derived from peer reports), per member.
|
|
1966
|
+
*/
|
|
1967
|
+
async getSwarmScore(swarmId) {
|
|
1968
|
+
return this.get(`/swarms/${encodeURIComponent(swarmId)}/score`);
|
|
1969
|
+
}
|
|
1970
|
+
/**
|
|
1971
|
+
* Issue a platform-signed attestation of the swarm as it is now: roster
|
|
1972
|
+
* and its hash, policy version and rules hash, charter, budget, kills,
|
|
1973
|
+
* latest rehearsal, receipt chain head and the three scores. Valid 24 h.
|
|
1974
|
+
* Hand it to a counterparty; they verify it against GET /trust/keys.
|
|
1975
|
+
*/
|
|
1976
|
+
async attestSwarm(swarmId) {
|
|
1977
|
+
return this.post(`/swarms/${encodeURIComponent(swarmId)}/attest`, {});
|
|
1978
|
+
}
|
|
1979
|
+
/** Past attestations, newest first (fetch one by id for the signed payload). */
|
|
1980
|
+
async listSwarmAttestations(swarmId) {
|
|
1981
|
+
return this.get(`/swarms/${encodeURIComponent(swarmId)}/attestations`);
|
|
1982
|
+
}
|
|
1983
|
+
/** A swarm as it is now, as a spec: `{ spec, yaml }`. Keep the YAML in git and apply it again. */
|
|
1984
|
+
async getSwarmSpec(swarmId) {
|
|
1985
|
+
return this.get(`/swarms/${encodeURIComponent(swarmId)}/spec`);
|
|
1986
|
+
}
|
|
1987
|
+
/**
|
|
1988
|
+
* A swarm's attention picture: escalations in the last hour against its
|
|
1989
|
+
* budget, the rate to expect, median time to resolve, mean time between
|
|
1990
|
+
* interventions, and the fan-out estimate after Olsen and Goodrich (how
|
|
1991
|
+
* many swarms like this one person could supervise).
|
|
1992
|
+
*/
|
|
1993
|
+
async getSwarmAttention(swarmId) {
|
|
1994
|
+
return this.get(`/swarms/${encodeURIComponent(swarmId)}/attention`);
|
|
1995
|
+
}
|
|
1996
|
+
/**
|
|
1997
|
+
* Set the swarm's attention budget: `perHour` escalations per rolling hour
|
|
1998
|
+
* a person may be asked to read (null = no budget). Past it `onExceed`
|
|
1999
|
+
* decides: 'deny' (the escalation is denied unread, the default) or
|
|
2000
|
+
* 'suspend' (the whole swarm stops). Returns the swarm detail.
|
|
2001
|
+
*/
|
|
2002
|
+
async setSwarmAttention(swarmId, input) {
|
|
2003
|
+
const body = {};
|
|
2004
|
+
if (input.perHour !== void 0) body.attention_budget_per_hour = input.perHour;
|
|
2005
|
+
if (input.onExceed !== void 0) body.attention_exceeded_action = input.onExceed;
|
|
2006
|
+
return this.patch(`/swarms/${encodeURIComponent(swarmId)}`, body);
|
|
2007
|
+
}
|
|
2008
|
+
// ─── OpenTelemetry ───────────────────────────────────────────────────
|
|
2009
|
+
/**
|
|
2010
|
+
* Attributes for the agent's own spans: the OTel GenAI `gen_ai.agent.id`
|
|
2011
|
+
* plus Vorim's swarm and parent-agent ids (the conventions have no field
|
|
2012
|
+
* for either), so any OTel backend can group a swarm's spans. Cached for
|
|
2013
|
+
* 60 seconds per agent. Pass the active span's trace/span id back to
|
|
2014
|
+
* `beforeAction` / `emit` and Vorim's OTLP connector parents its spans
|
|
2015
|
+
* under yours.
|
|
2016
|
+
*/
|
|
2017
|
+
async otelAttributes(agentId) {
|
|
2018
|
+
const cached = this.otelCache.get(agentId);
|
|
2019
|
+
if (cached && cached.expires > Date.now()) return cached.attrs;
|
|
2020
|
+
const attrs = { "gen_ai.agent.id": agentId, "vorim.agent.id": agentId };
|
|
2021
|
+
try {
|
|
2022
|
+
const swarm = await this.getSwarm(agentId);
|
|
2023
|
+
if (swarm?.swarm_id) {
|
|
2024
|
+
attrs["vorim.swarm.id"] = swarm.swarm_id;
|
|
2025
|
+
const me = swarm.members?.find((m) => m.agent_id === agentId);
|
|
2026
|
+
if (me?.parent_agent_id) attrs["vorim.parent_agent.id"] = me.parent_agent_id;
|
|
2027
|
+
}
|
|
2028
|
+
} catch {
|
|
2029
|
+
}
|
|
2030
|
+
this.otelCache.set(agentId, { attrs, expires: Date.now() + 6e4 });
|
|
2031
|
+
return attrs;
|
|
2032
|
+
}
|
|
2033
|
+
otelCache = /* @__PURE__ */ new Map();
|
|
2034
|
+
// ─── Guardian agents ─────────────────────────────────────────────────
|
|
2035
|
+
//
|
|
2036
|
+
// An agent with metadata.class = 'guardian' judges escalations that a rule
|
|
2037
|
+
// with approver_role 'guardian' assigned to its swarm. It reads the queue
|
|
2038
|
+
// from the server (never from a peer) and answers with a verdict signed by
|
|
2039
|
+
// its own key over one canonical line, so the approval is verifiable
|
|
2040
|
+
// offline against the agent's registered public key. An unanswered
|
|
2041
|
+
// escalation times out as denied: an absent guardian fails closed.
|
|
2042
|
+
/** Pending escalations this guardian may judge (empty for a non-guardian). */
|
|
2043
|
+
async listGuardianEscalations(agentId) {
|
|
2044
|
+
return this.get(`/runtime/guardian/escalations?agent_id=${encodeURIComponent(agentId)}`);
|
|
2045
|
+
}
|
|
2046
|
+
/**
|
|
2047
|
+
* Approve or veto an escalation as a guardian. Needs the agent's private
|
|
2048
|
+
* key (loaded by register(), registerEphemeral() or useAgentKey()). A
|
|
2049
|
+
* quorum rule returns `{ status: 'partial', approvals, required_approvals }`
|
|
2050
|
+
* until enough distinct approvals arrive; one veto denies at once.
|
|
2051
|
+
*/
|
|
2052
|
+
async guardianResolve(agentId, decisionId, resolution) {
|
|
2053
|
+
const key = this.agentKeys.get(agentId);
|
|
2054
|
+
if (!key) {
|
|
2055
|
+
throw new VorimError(
|
|
2056
|
+
400,
|
|
2057
|
+
"AGENT_KEY_NOT_LOADED",
|
|
2058
|
+
`No private key is cached for agent ${agentId}. Call register() or useAgentKey(agentId, privateKeyPem) first.`
|
|
2059
|
+
);
|
|
2060
|
+
}
|
|
2061
|
+
const signedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2062
|
+
const line = `vorim-escalation-approval|v1|${decisionId}|${resolution}|agent:${agentId}|${signedAt}`;
|
|
2063
|
+
const signature = await this.sign(line, key);
|
|
2064
|
+
return this.post("/runtime/guardian/resolve", {
|
|
2065
|
+
agent_id: agentId,
|
|
2066
|
+
decision_id: decisionId,
|
|
2067
|
+
resolution,
|
|
2068
|
+
signed_at: signedAt,
|
|
2069
|
+
signature
|
|
2070
|
+
});
|
|
2071
|
+
}
|
|
1876
2072
|
// ─── Credential Delegation ──────────────────────────────────────────
|
|
1877
2073
|
/**
|
|
1878
2074
|
* Register an OAuth provider for credential delegation.
|
|
@@ -2188,6 +2384,7 @@ export {
|
|
|
2188
2384
|
createVorim as default,
|
|
2189
2385
|
deviceLogin,
|
|
2190
2386
|
eventDigest,
|
|
2387
|
+
foldTraceparent,
|
|
2191
2388
|
hashPayload,
|
|
2192
2389
|
hashPreviousEvent,
|
|
2193
2390
|
hashSystemPrompt,
|