@vorim/sdk 3.7.5 → 3.7.6

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 (52) hide show
  1. package/README.md +1 -1
  2. package/dist/_runtime-gate-DOJUKJBu.d.cts +23 -0
  3. package/dist/_runtime-gate-DOJUKJBu.d.ts +23 -0
  4. package/dist/index.cjs +5 -3
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.js +5 -3
  7. package/dist/index.js.map +1 -1
  8. package/dist/integrations/anthropic.cjs +4 -1
  9. package/dist/integrations/anthropic.cjs.map +1 -1
  10. package/dist/integrations/anthropic.d.cts +8 -1
  11. package/dist/integrations/anthropic.d.ts +8 -1
  12. package/dist/integrations/anthropic.js +4 -1
  13. package/dist/integrations/anthropic.js.map +1 -1
  14. package/dist/integrations/crewai.cjs +56 -2
  15. package/dist/integrations/crewai.cjs.map +1 -1
  16. package/dist/integrations/crewai.d.cts +22 -2
  17. package/dist/integrations/crewai.d.ts +22 -2
  18. package/dist/integrations/crewai.js +54 -2
  19. package/dist/integrations/crewai.js.map +1 -1
  20. package/dist/integrations/langchain.cjs +99 -8
  21. package/dist/integrations/langchain.cjs.map +1 -1
  22. package/dist/integrations/langchain.d.cts +23 -0
  23. package/dist/integrations/langchain.d.ts +23 -0
  24. package/dist/integrations/langchain.js +99 -8
  25. package/dist/integrations/langchain.js.map +1 -1
  26. package/dist/integrations/langgraph.cjs +78 -6
  27. package/dist/integrations/langgraph.cjs.map +1 -1
  28. package/dist/integrations/langgraph.d.cts +1 -0
  29. package/dist/integrations/langgraph.d.ts +1 -0
  30. package/dist/integrations/langgraph.js +78 -6
  31. package/dist/integrations/langgraph.js.map +1 -1
  32. package/dist/integrations/llamaindex.cjs +96 -8
  33. package/dist/integrations/llamaindex.cjs.map +1 -1
  34. package/dist/integrations/llamaindex.d.cts +23 -0
  35. package/dist/integrations/llamaindex.d.ts +23 -0
  36. package/dist/integrations/llamaindex.js +96 -8
  37. package/dist/integrations/llamaindex.js.map +1 -1
  38. package/dist/integrations/openai.cjs +4 -1
  39. package/dist/integrations/openai.cjs.map +1 -1
  40. package/dist/integrations/openai.d.cts +8 -1
  41. package/dist/integrations/openai.d.ts +8 -1
  42. package/dist/integrations/openai.js +4 -1
  43. package/dist/integrations/openai.js.map +1 -1
  44. package/dist/integrations/vercel-ai.cjs +2 -1
  45. package/dist/integrations/vercel-ai.cjs.map +1 -1
  46. package/dist/integrations/vercel-ai.d.cts +7 -1
  47. package/dist/integrations/vercel-ai.d.ts +7 -1
  48. package/dist/integrations/vercel-ai.js +2 -1
  49. package/dist/integrations/vercel-ai.js.map +1 -1
  50. package/package.json +1 -1
  51. package/dist/_runtime-gate-DZQTkw4J.d.cts +0 -11
  52. package/dist/_runtime-gate-DZQTkw4J.d.ts +0 -11
@@ -1,5 +1,6 @@
1
1
  import { P as PermissionScope, A as AgentRegistrationResult } from '../types-B22WnXEW.cjs';
2
2
  import { VorimSDK, ReplayInputs } from '../index.cjs';
3
+ import { E as EscalationPolicy, T as TransportFailurePolicy } from '../_runtime-gate-DOJUKJBu.cjs';
3
4
 
4
5
  /** Minimal subset of @langchain/core Serialized */
5
6
  interface Serialized {
@@ -19,6 +20,28 @@ interface VorimLangChainConfig {
19
20
  defaultPermission?: PermissionScope;
20
21
  /** Whether to emit audit events asynchronously (fire-and-forget). @default true */
21
22
  asyncAudit?: boolean;
23
+ /**
24
+ * Use the full runtime-control decision API (`beforeAction`) instead of the
25
+ * lightweight permission check. When true, every tool call is evaluated
26
+ * against live policy rules (allow/deny/escalate) and the returned
27
+ * `decisionId` is linked onto each audit event's `decision_id`. Requires the
28
+ * runtime_control plan feature (Growth+). @default false
29
+ */
30
+ useRuntimeControl?: boolean;
31
+ /**
32
+ * What to do when a runtime decision returns `escalate`. Only applies when
33
+ * `useRuntimeControl` is true. `'wait'` (default) blocks and polls until a
34
+ * human approves/denies or the timeout elapses (→ deny); `'deny'` fails
35
+ * closed; `'allow'` proceeds (fail open — trusted use only). @default 'wait'
36
+ */
37
+ onEscalation?: EscalationPolicy;
38
+ /** Timeout (ms) for `onEscalation: 'wait'`. @default 300000 */
39
+ escalationTimeoutMs?: number;
40
+ /**
41
+ * Policy when the runtime gate can't reach the control plane. `'deny'` fails
42
+ * closed (secure default); `'allow'` fails open. @default 'deny'
43
+ */
44
+ onTransportFailure?: TransportFailurePolicy;
22
45
  /**
23
46
  * Framework name recorded on each audit event's metadata. Defaults to
24
47
  * 'langchain'. The LangGraph wrapper sets this to 'langgraph' so the audit
@@ -1,5 +1,6 @@
1
1
  import { P as PermissionScope, A as AgentRegistrationResult } from '../types-B22WnXEW.js';
2
2
  import { VorimSDK, ReplayInputs } from '../index.js';
3
+ import { E as EscalationPolicy, T as TransportFailurePolicy } from '../_runtime-gate-DOJUKJBu.js';
3
4
 
4
5
  /** Minimal subset of @langchain/core Serialized */
5
6
  interface Serialized {
@@ -19,6 +20,28 @@ interface VorimLangChainConfig {
19
20
  defaultPermission?: PermissionScope;
20
21
  /** Whether to emit audit events asynchronously (fire-and-forget). @default true */
21
22
  asyncAudit?: boolean;
23
+ /**
24
+ * Use the full runtime-control decision API (`beforeAction`) instead of the
25
+ * lightweight permission check. When true, every tool call is evaluated
26
+ * against live policy rules (allow/deny/escalate) and the returned
27
+ * `decisionId` is linked onto each audit event's `decision_id`. Requires the
28
+ * runtime_control plan feature (Growth+). @default false
29
+ */
30
+ useRuntimeControl?: boolean;
31
+ /**
32
+ * What to do when a runtime decision returns `escalate`. Only applies when
33
+ * `useRuntimeControl` is true. `'wait'` (default) blocks and polls until a
34
+ * human approves/denies or the timeout elapses (→ deny); `'deny'` fails
35
+ * closed; `'allow'` proceeds (fail open — trusted use only). @default 'wait'
36
+ */
37
+ onEscalation?: EscalationPolicy;
38
+ /** Timeout (ms) for `onEscalation: 'wait'`. @default 300000 */
39
+ escalationTimeoutMs?: number;
40
+ /**
41
+ * Policy when the runtime gate can't reach the control plane. `'deny'` fails
42
+ * closed (secure default); `'allow'` fails open. @default 'deny'
43
+ */
44
+ onTransportFailure?: TransportFailurePolicy;
22
45
  /**
23
46
  * Framework name recorded on each audit event's metadata. Defaults to
24
47
  * 'langchain'. The LangGraph wrapper sets this to 'langgraph' so the audit
@@ -5633,6 +5633,43 @@ var init_esm = __esm({
5633
5633
  }
5634
5634
  });
5635
5635
 
5636
+ // src/integrations/_runtime-gate.ts
5637
+ function isAllowVerdict(decision) {
5638
+ return decision === "allow" || decision === "modify";
5639
+ }
5640
+ async function runtimeGate(vorim, agentId, actionTarget, scope, payload, opts = {}) {
5641
+ const onEscalation = opts.onEscalation ?? "wait";
5642
+ const onTransportFailure = opts.onTransportFailure ?? "deny";
5643
+ const d = await vorim.beforeAction(
5644
+ { agentId, actionType: "tool_call", actionTarget, requiredScope: scope, payload },
5645
+ { throwOnDeny: false }
5646
+ );
5647
+ if (d.isFallback || d.decision === "fallback") {
5648
+ if (onTransportFailure === "allow") {
5649
+ return { allowed: true, reason: d.reason ?? "control plane unreachable (fail-open)", decisionId: d.decisionId || void 0 };
5650
+ }
5651
+ return { allowed: false, reason: d.reason ?? "control plane unreachable (failed closed)", decisionId: d.decisionId || void 0 };
5652
+ }
5653
+ if (d.decision !== "escalate") {
5654
+ return { allowed: isAllowVerdict(d.decision), reason: d.reason, decisionId: d.decisionId || void 0 };
5655
+ }
5656
+ if (onEscalation === "allow") {
5657
+ return { allowed: true, reason: d.reason ?? "escalated (auto-allowed)", decisionId: d.decisionId || void 0 };
5658
+ }
5659
+ if (onEscalation === "deny") {
5660
+ return { allowed: false, reason: d.reason ?? "escalated (auto-denied \u2014 awaiting human)", decisionId: d.decisionId || void 0 };
5661
+ }
5662
+ if (!d.decisionId) {
5663
+ return { allowed: false, reason: "escalated but no decisionId to poll", decisionId: void 0 };
5664
+ }
5665
+ try {
5666
+ const resolved = await vorim.waitForDecisionResolution(d.decisionId, { timeoutMs: opts.escalationTimeoutMs });
5667
+ return { allowed: isAllowVerdict(resolved.decision), reason: resolved.reason, decisionId: resolved.decisionId || d.decisionId };
5668
+ } catch {
5669
+ return { allowed: false, reason: "escalation not resolved before timeout", decisionId: d.decisionId };
5670
+ }
5671
+ }
5672
+
5636
5673
  // src/replay.ts
5637
5674
  function jcsCanonicalise(value) {
5638
5675
  if (value === null) return "null";
@@ -5706,18 +5743,50 @@ async function prepareReplayContext(inputs) {
5706
5743
 
5707
5744
  // src/integrations/langchain.ts
5708
5745
  function wrapTool(tool, config) {
5709
- const { vorim, agentId, permissionMap = {}, defaultPermission = "agent:execute", asyncAudit = true, replay, framework = "langchain" } = config;
5746
+ const {
5747
+ vorim,
5748
+ agentId,
5749
+ permissionMap = {},
5750
+ defaultPermission = "agent:execute",
5751
+ asyncAudit = true,
5752
+ replay,
5753
+ framework = "langchain",
5754
+ useRuntimeControl = false,
5755
+ onEscalation,
5756
+ escalationTimeoutMs,
5757
+ onTransportFailure
5758
+ } = config;
5710
5759
  const originalCall = tool._call.bind(tool);
5711
5760
  const getReplayCtx = makeReplayContextGetter(replay);
5712
5761
  tool._call = async function vorimGuardedCall(arg, runManager, parentConfig) {
5713
5762
  const scope = permissionMap[tool.name] ?? defaultPermission;
5714
5763
  let allowed;
5715
5764
  let reason;
5716
- try {
5717
- ({ allowed, reason } = await vorim.check(agentId, scope));
5718
- } catch {
5719
- allowed = false;
5720
- reason = "permission check unavailable (failed closed)";
5765
+ let decisionId;
5766
+ if (useRuntimeControl) {
5767
+ try {
5768
+ const gateRes = await runtimeGate(
5769
+ vorim,
5770
+ agentId,
5771
+ tool.name,
5772
+ scope,
5773
+ arg,
5774
+ { onEscalation, escalationTimeoutMs, onTransportFailure }
5775
+ );
5776
+ allowed = gateRes.allowed;
5777
+ reason = gateRes.reason;
5778
+ decisionId = gateRes.decisionId;
5779
+ } catch {
5780
+ allowed = false;
5781
+ reason = "runtime gate unavailable (failed closed)";
5782
+ }
5783
+ } else {
5784
+ try {
5785
+ ({ allowed, reason } = await vorim.check(agentId, scope));
5786
+ } catch {
5787
+ allowed = false;
5788
+ reason = "permission check unavailable (failed closed)";
5789
+ }
5721
5790
  }
5722
5791
  const replayCtx = await getReplayCtx();
5723
5792
  if (!allowed) {
@@ -5728,6 +5797,7 @@ function wrapTool(tool, config) {
5728
5797
  resource: truncate(JSON.stringify(arg), 500),
5729
5798
  permission: scope,
5730
5799
  result: "denied",
5800
+ ...decisionId ? { decision_id: decisionId } : {},
5731
5801
  metadata: { reason, framework },
5732
5802
  ...replayCtx
5733
5803
  };
@@ -5748,6 +5818,7 @@ function wrapTool(tool, config) {
5748
5818
  result: "error",
5749
5819
  latency_ms: Date.now() - start,
5750
5820
  error_code: err instanceof Error ? err.name : "UNKNOWN",
5821
+ ...decisionId ? { decision_id: decisionId } : {},
5751
5822
  metadata: { error: err instanceof Error ? err.message : String(err), framework },
5752
5823
  ...replayCtx
5753
5824
  };
@@ -5762,6 +5833,7 @@ function wrapTool(tool, config) {
5762
5833
  permission: scope,
5763
5834
  result: "success",
5764
5835
  latency_ms: Date.now() - start,
5836
+ ...decisionId ? { decision_id: decisionId } : {},
5765
5837
  metadata: { framework },
5766
5838
  ...replayCtx
5767
5839
  };
@@ -5863,7 +5935,22 @@ var VorimCallbackHandler = class _VorimCallbackHandler {
5863
5935
  }
5864
5936
  };
5865
5937
  async function createVorimAgent(config) {
5866
- const { vorim, name, capabilities, scopes, description, tools: rawTools, permissionMap, defaultPermission, asyncAudit, replay } = config;
5938
+ const {
5939
+ vorim,
5940
+ name,
5941
+ capabilities,
5942
+ scopes,
5943
+ description,
5944
+ tools: rawTools,
5945
+ permissionMap,
5946
+ defaultPermission,
5947
+ asyncAudit,
5948
+ replay,
5949
+ useRuntimeControl,
5950
+ onEscalation,
5951
+ escalationTimeoutMs,
5952
+ onTransportFailure
5953
+ } = config;
5867
5954
  const registration = await vorim.register({
5868
5955
  name,
5869
5956
  description,
@@ -5878,7 +5965,11 @@ async function createVorimAgent(config) {
5878
5965
  permissionMap,
5879
5966
  defaultPermission,
5880
5967
  asyncAudit,
5881
- replay: derivedReplay
5968
+ replay: derivedReplay,
5969
+ useRuntimeControl,
5970
+ onEscalation,
5971
+ escalationTimeoutMs,
5972
+ onTransportFailure
5882
5973
  };
5883
5974
  const tools = wrapTools(rawTools, agentConfig);
5884
5975
  const callbackHandler = new VorimCallbackHandler(vorim, agentId, derivedReplay);