@vorim/sdk 4.2.0 → 4.4.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 +18 -0
  2. package/dist/{_commerce-core-BQbISpWe.d.cts → _commerce-core-B800cza0.d.cts} +1 -1
  3. package/dist/{_commerce-core-BIqTJ7Om.d.ts → _commerce-core-Bv_2hfKP.d.ts} +1 -1
  4. package/dist/index.cjs +21 -2
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.cts +13 -2
  7. package/dist/index.d.ts +13 -2
  8. package/dist/index.js +21 -2
  9. package/dist/index.js.map +1 -1
  10. package/dist/integrations/amazon.d.cts +2 -2
  11. package/dist/integrations/amazon.d.ts +2 -2
  12. package/dist/integrations/anthropic.d.cts +1 -1
  13. package/dist/integrations/anthropic.d.ts +1 -1
  14. package/dist/integrations/ap2.d.cts +1 -1
  15. package/dist/integrations/ap2.d.ts +1 -1
  16. package/dist/integrations/aws-iam.d.cts +1 -1
  17. package/dist/integrations/aws-iam.d.ts +1 -1
  18. package/dist/integrations/bank-rails.d.cts +1 -1
  19. package/dist/integrations/bank-rails.d.ts +1 -1
  20. package/dist/integrations/circle.d.cts +1 -1
  21. package/dist/integrations/circle.d.ts +1 -1
  22. package/dist/integrations/cloudflare.d.cts +1 -1
  23. package/dist/integrations/cloudflare.d.ts +1 -1
  24. package/dist/integrations/coinbase-cdp.d.cts +1 -1
  25. package/dist/integrations/coinbase-cdp.d.ts +1 -1
  26. package/dist/integrations/commerce-agents.d.cts +1 -1
  27. package/dist/integrations/commerce-agents.d.ts +1 -1
  28. package/dist/integrations/crewai.d.cts +1 -1
  29. package/dist/integrations/crewai.d.ts +1 -1
  30. package/dist/integrations/delivery.d.cts +2 -2
  31. package/dist/integrations/delivery.d.ts +2 -2
  32. package/dist/integrations/ebay.d.cts +2 -2
  33. package/dist/integrations/ebay.d.ts +2 -2
  34. package/dist/integrations/entra.d.cts +1 -1
  35. package/dist/integrations/entra.d.ts +1 -1
  36. package/dist/integrations/etsy.d.cts +2 -2
  37. package/dist/integrations/etsy.d.ts +2 -2
  38. package/dist/integrations/eu-providers.cjs +463 -0
  39. package/dist/integrations/eu-providers.cjs.map +1 -0
  40. package/dist/integrations/eu-providers.d.cts +123 -0
  41. package/dist/integrations/eu-providers.d.ts +123 -0
  42. package/dist/integrations/eu-providers.js +420 -0
  43. package/dist/integrations/eu-providers.js.map +1 -0
  44. package/dist/integrations/fhir.d.cts +1 -1
  45. package/dist/integrations/fhir.d.ts +1 -1
  46. package/dist/integrations/google-merchant.d.cts +2 -2
  47. package/dist/integrations/google-merchant.d.ts +2 -2
  48. package/dist/integrations/grok.cjs +9 -3
  49. package/dist/integrations/grok.cjs.map +1 -1
  50. package/dist/integrations/grok.d.cts +1 -1
  51. package/dist/integrations/grok.d.ts +1 -1
  52. package/dist/integrations/grok.js +9 -3
  53. package/dist/integrations/grok.js.map +1 -1
  54. package/dist/integrations/guidewire.d.cts +1 -1
  55. package/dist/integrations/guidewire.d.ts +1 -1
  56. package/dist/integrations/hermes.d.cts +1 -1
  57. package/dist/integrations/hermes.d.ts +1 -1
  58. package/dist/integrations/jira.d.cts +1 -1
  59. package/dist/integrations/jira.d.ts +1 -1
  60. package/dist/integrations/langchain.cjs +26 -7
  61. package/dist/integrations/langchain.cjs.map +1 -1
  62. package/dist/integrations/langchain.d.cts +1 -1
  63. package/dist/integrations/langchain.d.ts +1 -1
  64. package/dist/integrations/langchain.js +26 -7
  65. package/dist/integrations/langchain.js.map +1 -1
  66. package/dist/integrations/langgraph.d.cts +1 -1
  67. package/dist/integrations/langgraph.d.ts +1 -1
  68. package/dist/integrations/legal.d.cts +1 -1
  69. package/dist/integrations/legal.d.ts +1 -1
  70. package/dist/integrations/life-sciences.d.cts +1 -1
  71. package/dist/integrations/life-sciences.d.ts +1 -1
  72. package/dist/integrations/linear.d.cts +1 -1
  73. package/dist/integrations/linear.d.ts +1 -1
  74. package/dist/integrations/lithic.d.cts +1 -1
  75. package/dist/integrations/lithic.d.ts +1 -1
  76. package/dist/integrations/llamaindex.d.cts +1 -1
  77. package/dist/integrations/llamaindex.d.ts +1 -1
  78. package/dist/integrations/marqeta.d.cts +1 -1
  79. package/dist/integrations/marqeta.d.ts +1 -1
  80. package/dist/integrations/meta.d.cts +2 -2
  81. package/dist/integrations/meta.d.ts +2 -2
  82. package/dist/integrations/mistral.cjs +487 -0
  83. package/dist/integrations/mistral.cjs.map +1 -0
  84. package/dist/integrations/mistral.d.cts +133 -0
  85. package/dist/integrations/mistral.d.ts +133 -0
  86. package/dist/integrations/mistral.js +439 -0
  87. package/dist/integrations/mistral.js.map +1 -0
  88. package/dist/integrations/modern-treasury.d.cts +1 -1
  89. package/dist/integrations/modern-treasury.d.ts +1 -1
  90. package/dist/integrations/muse.cjs +9 -3
  91. package/dist/integrations/muse.cjs.map +1 -1
  92. package/dist/integrations/muse.d.cts +1 -1
  93. package/dist/integrations/muse.d.ts +1 -1
  94. package/dist/integrations/muse.js +9 -3
  95. package/dist/integrations/muse.js.map +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.cjs +9 -3
  101. package/dist/integrations/openai.cjs.map +1 -1
  102. package/dist/integrations/openai.d.cts +11 -1
  103. package/dist/integrations/openai.d.ts +11 -1
  104. package/dist/integrations/openai.js +9 -3
  105. package/dist/integrations/openai.js.map +1 -1
  106. package/dist/integrations/openrouter.cjs +9 -3
  107. package/dist/integrations/openrouter.cjs.map +1 -1
  108. package/dist/integrations/openrouter.d.cts +1 -1
  109. package/dist/integrations/openrouter.d.ts +1 -1
  110. package/dist/integrations/openrouter.js +9 -3
  111. package/dist/integrations/openrouter.js.map +1 -1
  112. package/dist/integrations/paypal-agent.d.cts +1 -1
  113. package/dist/integrations/paypal-agent.d.ts +1 -1
  114. package/dist/integrations/perplexity.cjs +9 -3
  115. package/dist/integrations/perplexity.cjs.map +1 -1
  116. package/dist/integrations/perplexity.d.cts +1 -1
  117. package/dist/integrations/perplexity.d.ts +1 -1
  118. package/dist/integrations/perplexity.js +9 -3
  119. package/dist/integrations/perplexity.js.map +1 -1
  120. package/dist/integrations/plaid.d.cts +1 -1
  121. package/dist/integrations/plaid.d.ts +1 -1
  122. package/dist/integrations/ramp.d.cts +1 -1
  123. package/dist/integrations/ramp.d.ts +1 -1
  124. package/dist/integrations/shopify.d.cts +1 -1
  125. package/dist/integrations/shopify.d.ts +1 -1
  126. package/dist/integrations/siem.d.cts +1 -1
  127. package/dist/integrations/siem.d.ts +1 -1
  128. package/dist/integrations/skyfire.d.cts +1 -1
  129. package/dist/integrations/skyfire.d.ts +1 -1
  130. package/dist/integrations/social-ads.d.cts +2 -2
  131. package/dist/integrations/social-ads.d.ts +2 -2
  132. package/dist/integrations/stripe-acp.d.cts +1 -1
  133. package/dist/integrations/stripe-acp.d.ts +1 -1
  134. package/dist/integrations/stripe-issuing.d.cts +1 -1
  135. package/dist/integrations/stripe-issuing.d.ts +1 -1
  136. package/dist/integrations/tiktok-shop.d.cts +2 -2
  137. package/dist/integrations/tiktok-shop.d.ts +2 -2
  138. package/dist/integrations/truanon.d.cts +1 -1
  139. package/dist/integrations/truanon.d.ts +1 -1
  140. package/dist/integrations/typesafe.d.cts +1 -1
  141. package/dist/integrations/typesafe.d.ts +1 -1
  142. package/dist/integrations/ucp.d.cts +1 -1
  143. package/dist/integrations/ucp.d.ts +1 -1
  144. package/dist/integrations/vercel-ai.d.cts +1 -1
  145. package/dist/integrations/vercel-ai.d.ts +1 -1
  146. package/dist/integrations/walmart.d.cts +2 -2
  147. package/dist/integrations/walmart.d.ts +2 -2
  148. package/dist/integrations/x402.d.cts +1 -1
  149. package/dist/integrations/x402.d.ts +1 -1
  150. package/dist/{types-DwPEBj7p.d.cts → types-BI7fk5gL.d.cts} +12 -1
  151. package/dist/{types-DwPEBj7p.d.ts → types-BI7fk5gL.d.ts} +12 -1
  152. package/package.json +21 -1
@@ -1,5 +1,5 @@
1
1
  import { VorimLangChainConfig } from './langchain.cjs';
2
- import '../types-DwPEBj7p.cjs';
2
+ import '../types-BI7fk5gL.cjs';
3
3
  import '../index.cjs';
4
4
  import '@vorim/shared-types';
5
5
  import '../httpSignatures.cjs';
@@ -1,5 +1,5 @@
1
1
  import { VorimLangChainConfig } from './langchain.js';
2
- import '../types-DwPEBj7p.js';
2
+ import '../types-BI7fk5gL.js';
3
3
  import '../index.js';
4
4
  import '@vorim/shared-types';
5
5
  import '../httpSignatures.js';
@@ -1,5 +1,5 @@
1
1
  import { VorimSDK } from '../index.cjs';
2
- import { P as PermissionScope } from '../types-DwPEBj7p.cjs';
2
+ import { P as PermissionScope } from '../types-BI7fk5gL.cjs';
3
3
  import '@vorim/shared-types';
4
4
  import '../httpSignatures.cjs';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { VorimSDK } from '../index.js';
2
- import { P as PermissionScope } from '../types-DwPEBj7p.js';
2
+ import { P as PermissionScope } from '../types-BI7fk5gL.js';
3
3
  import '@vorim/shared-types';
4
4
  import '../httpSignatures.js';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { VorimSDK } from '../index.cjs';
2
- import { P as PermissionScope } from '../types-DwPEBj7p.cjs';
2
+ import { P as PermissionScope } from '../types-BI7fk5gL.cjs';
3
3
  import '@vorim/shared-types';
4
4
  import '../httpSignatures.cjs';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { VorimSDK } from '../index.js';
2
- import { P as PermissionScope } from '../types-DwPEBj7p.js';
2
+ import { P as PermissionScope } from '../types-BI7fk5gL.js';
3
3
  import '@vorim/shared-types';
4
4
  import '../httpSignatures.js';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { VorimSDK } from '../index.cjs';
2
- import { P as PermissionScope } from '../types-DwPEBj7p.cjs';
2
+ import { P as PermissionScope } from '../types-BI7fk5gL.cjs';
3
3
  import '@vorim/shared-types';
4
4
  import '../httpSignatures.cjs';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { VorimSDK } from '../index.js';
2
- import { P as PermissionScope } from '../types-DwPEBj7p.js';
2
+ import { P as PermissionScope } from '../types-BI7fk5gL.js';
3
3
  import '@vorim/shared-types';
4
4
  import '../httpSignatures.js';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { VorimSDK } from '../index.cjs';
2
- import { P as PermissionScope } from '../types-DwPEBj7p.cjs';
2
+ import { P as PermissionScope } from '../types-BI7fk5gL.cjs';
3
3
  import '@vorim/shared-types';
4
4
  import '../httpSignatures.cjs';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { VorimSDK } from '../index.js';
2
- import { P as PermissionScope } from '../types-DwPEBj7p.js';
2
+ import { P as PermissionScope } from '../types-BI7fk5gL.js';
3
3
  import '@vorim/shared-types';
4
4
  import '../httpSignatures.js';
5
5
 
@@ -1,4 +1,4 @@
1
- import { P as PermissionScope, A as AgentRegistrationResult } from '../types-DwPEBj7p.cjs';
1
+ import { P as PermissionScope, A as AgentRegistrationResult } from '../types-BI7fk5gL.cjs';
2
2
  import { VorimSDK, ReplayInputs } from '../index.cjs';
3
3
  import { E as EscalationPolicy, T as TransportFailurePolicy } from '../_runtime-gate-DOJUKJBu.cjs';
4
4
  import '@vorim/shared-types';
@@ -1,4 +1,4 @@
1
- import { P as PermissionScope, A as AgentRegistrationResult } from '../types-DwPEBj7p.js';
1
+ import { P as PermissionScope, A as AgentRegistrationResult } from '../types-BI7fk5gL.js';
2
2
  import { VorimSDK, ReplayInputs } from '../index.js';
3
3
  import { E as EscalationPolicy, T as TransportFailurePolicy } from '../_runtime-gate-DOJUKJBu.js';
4
4
  import '@vorim/shared-types';
@@ -1,5 +1,5 @@
1
1
  import { VorimSDK } from '../index.cjs';
2
- import { P as PermissionScope } from '../types-DwPEBj7p.cjs';
2
+ import { P as PermissionScope } from '../types-BI7fk5gL.cjs';
3
3
  import '@vorim/shared-types';
4
4
  import '../httpSignatures.cjs';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { VorimSDK } from '../index.js';
2
- import { P as PermissionScope } from '../types-DwPEBj7p.js';
2
+ import { P as PermissionScope } from '../types-BI7fk5gL.js';
3
3
  import '@vorim/shared-types';
4
4
  import '../httpSignatures.js';
5
5
 
@@ -1,6 +1,6 @@
1
- import { C as CommerceProfile, a as CommerceGuardConfig, V as VorimCommerceGuard, b as CommerceReceipt } from '../_commerce-core-BQbISpWe.cjs';
1
+ import { C as CommerceProfile, a as CommerceGuardConfig, V as VorimCommerceGuard, b as CommerceReceipt } from '../_commerce-core-B800cza0.cjs';
2
2
  import { VorimSDK } from '../index.cjs';
3
- import '../types-DwPEBj7p.cjs';
3
+ import '../types-BI7fk5gL.cjs';
4
4
  import '../_runtime-gate-DOJUKJBu.cjs';
5
5
  import '@vorim/shared-types';
6
6
  import '../httpSignatures.cjs';
@@ -1,6 +1,6 @@
1
- import { C as CommerceProfile, a as CommerceGuardConfig, V as VorimCommerceGuard, b as CommerceReceipt } from '../_commerce-core-BIqTJ7Om.js';
1
+ import { C as CommerceProfile, a as CommerceGuardConfig, V as VorimCommerceGuard, b as CommerceReceipt } from '../_commerce-core-Bv_2hfKP.js';
2
2
  import { VorimSDK } from '../index.js';
3
- import '../types-DwPEBj7p.js';
3
+ import '../types-BI7fk5gL.js';
4
4
  import '../_runtime-gate-DOJUKJBu.js';
5
5
  import '@vorim/shared-types';
6
6
  import '../httpSignatures.js';
@@ -0,0 +1,487 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/integrations/mistral.ts
31
+ var mistral_exports = {};
32
+ __export(mistral_exports, {
33
+ DEFAULT_MISTRAL_MODEL: () => DEFAULT_MISTRAL_MODEL,
34
+ MISTRAL_BASE_URL: () => MISTRAL_BASE_URL,
35
+ MISTRAL_CODE_MODEL: () => MISTRAL_CODE_MODEL,
36
+ MISTRAL_EU_BASE_URL: () => MISTRAL_EU_BASE_URL,
37
+ MISTRAL_SMALL_MODEL: () => MISTRAL_SMALL_MODEL,
38
+ MISTRAL_US_BASE_URL: () => MISTRAL_US_BASE_URL,
39
+ VorimToolRegistry: () => VorimToolRegistry,
40
+ createMistralRegistry: () => createMistralRegistry,
41
+ decideMistralConfirmations: () => decideMistralConfirmations,
42
+ executeMistralFunctionCalls: () => executeMistralFunctionCalls,
43
+ normaliseMistralToolCalls: () => normaliseMistralToolCalls,
44
+ runMistralAgentLoop: () => runMistralAgentLoop
45
+ });
46
+ module.exports = __toCommonJS(mistral_exports);
47
+
48
+ // src/integrations/_runtime-gate.ts
49
+ function isAllowVerdict(decision) {
50
+ return decision === "allow" || decision === "modify";
51
+ }
52
+ async function runtimeGate(vorim, agentId, actionTarget, scope, payload, opts = {}) {
53
+ const onEscalation = opts.onEscalation ?? "wait";
54
+ const onTransportFailure = opts.onTransportFailure ?? "deny";
55
+ const d = await vorim.beforeAction(
56
+ { agentId, actionType: "tool_call", actionTarget, requiredScope: scope, payload },
57
+ { throwOnDeny: false }
58
+ );
59
+ if (d.isFallback || d.decision === "fallback") {
60
+ if (onTransportFailure === "allow") {
61
+ return { allowed: true, reason: d.reason ?? "control plane unreachable (fail-open)", decisionId: d.decisionId || void 0 };
62
+ }
63
+ return { allowed: false, reason: d.reason ?? "control plane unreachable (failed closed)", decisionId: d.decisionId || void 0 };
64
+ }
65
+ if (d.decision !== "escalate") {
66
+ return { allowed: isAllowVerdict(d.decision), reason: d.reason, decisionId: d.decisionId || void 0 };
67
+ }
68
+ if (onEscalation === "allow") {
69
+ return { allowed: true, reason: d.reason ?? "escalated (auto-allowed)", decisionId: d.decisionId || void 0 };
70
+ }
71
+ if (onEscalation === "deny") {
72
+ return { allowed: false, reason: d.reason ?? "escalated (auto-denied \u2014 awaiting human)", decisionId: d.decisionId || void 0 };
73
+ }
74
+ if (!d.decisionId) {
75
+ return { allowed: false, reason: "escalated but no decisionId to poll", decisionId: void 0 };
76
+ }
77
+ try {
78
+ const resolved = await vorim.waitForDecisionResolution(d.decisionId, { timeoutMs: opts.escalationTimeoutMs });
79
+ return { allowed: isAllowVerdict(resolved.decision), reason: resolved.reason, decisionId: resolved.decisionId || d.decisionId };
80
+ } catch {
81
+ return { allowed: false, reason: "escalation not resolved before timeout", decisionId: d.decisionId };
82
+ }
83
+ }
84
+
85
+ // src/replay.ts
86
+ function jcsCanonicalise(value) {
87
+ if (value === null) return "null";
88
+ if (value === true) return "true";
89
+ if (value === false) return "false";
90
+ if (typeof value === "number") {
91
+ if (!Number.isFinite(value)) {
92
+ throw new Error("jcsCanonicalise: NaN and Infinity are not JCS-valid");
93
+ }
94
+ const abs = Math.abs(value);
95
+ if (value !== 0 && (abs >= 1e21 || abs < 1e-4 || Number.isInteger(value) && abs > 2 ** 53)) {
96
+ throw new Error(
97
+ `jcsCanonicalise: numbers in the ranges where JS and Python formatting diverge (|x| >= 1e21, |x| < 1e-4, or integer |x| > 2^53) are not supported in signed metadata. Use a string instead of ${value}.`
98
+ );
99
+ }
100
+ return value.toString();
101
+ }
102
+ if (typeof value === "string") {
103
+ return JSON.stringify(value);
104
+ }
105
+ if (Array.isArray(value)) {
106
+ return "[" + value.map(jcsCanonicalise).join(",") + "]";
107
+ }
108
+ if (typeof value === "object") {
109
+ const obj = value;
110
+ const keys = Object.keys(obj).filter((k) => obj[k] !== void 0).sort();
111
+ const parts = keys.map((k) => JSON.stringify(k) + ":" + jcsCanonicalise(obj[k]));
112
+ return "{" + parts.join(",") + "}";
113
+ }
114
+ throw new Error(`jcsCanonicalise: unsupported value type: ${typeof value}`);
115
+ }
116
+ async function sha256Hex(input) {
117
+ const bytes = typeof input === "string" ? new TextEncoder().encode(input) : input;
118
+ const subtle = globalThis.crypto?.subtle;
119
+ if (subtle) {
120
+ const buf = await subtle.digest("SHA-256", bytes);
121
+ return Array.from(new Uint8Array(buf)).map((b) => b.toString(16).padStart(2, "0")).join("");
122
+ }
123
+ const nodeCrypto = await import("crypto");
124
+ return nodeCrypto.createHash("sha256").update(bytes).digest("hex");
125
+ }
126
+ async function hashTool(tool) {
127
+ const normalised = {
128
+ name: tool.name,
129
+ description: tool.description ?? "",
130
+ schema: tool.schema ?? {}
131
+ };
132
+ const hex = await sha256Hex(jcsCanonicalise(normalised));
133
+ return `sha256:${hex}`;
134
+ }
135
+ async function hashToolCatalogue(tools) {
136
+ if (tools.length === 0) {
137
+ return `sha256:${await sha256Hex("[]")}`;
138
+ }
139
+ const perTool = await Promise.all(tools.map(hashTool));
140
+ perTool.sort();
141
+ const hex = await sha256Hex(perTool.join(""));
142
+ return `sha256:${hex}`;
143
+ }
144
+ async function hashSystemPrompt(prompt) {
145
+ const hex = await sha256Hex(prompt);
146
+ return `sha256:${hex}`;
147
+ }
148
+ async function prepareReplayContext(inputs) {
149
+ const ctx = {};
150
+ if (inputs.modelVersion) ctx.model_version = inputs.modelVersion;
151
+ if (inputs.tools) ctx.tool_catalogue_hash = await hashToolCatalogue(inputs.tools);
152
+ if (inputs.systemPrompt) ctx.system_prompt_hash = await hashSystemPrompt(inputs.systemPrompt);
153
+ return ctx;
154
+ }
155
+
156
+ // src/integrations/openai.ts
157
+ var VorimToolRegistry = class {
158
+ vorim;
159
+ agentId;
160
+ defaultPermission;
161
+ asyncAudit;
162
+ useRuntimeControl;
163
+ onEscalation;
164
+ escalationTimeoutMs;
165
+ onTransportFailure;
166
+ tools = /* @__PURE__ */ new Map();
167
+ replayInputs;
168
+ replayCache = null;
169
+ framework;
170
+ constructor(config) {
171
+ this.framework = config.framework ?? "openai";
172
+ this.vorim = config.vorim;
173
+ this.agentId = config.agentId;
174
+ this.defaultPermission = config.defaultPermission ?? "agent:execute";
175
+ this.asyncAudit = config.asyncAudit ?? true;
176
+ this.useRuntimeControl = config.useRuntimeControl ?? false;
177
+ this.onEscalation = config.onEscalation;
178
+ this.escalationTimeoutMs = config.escalationTimeoutMs;
179
+ this.onTransportFailure = config.onTransportFailure;
180
+ this.replayInputs = config.replay;
181
+ }
182
+ /**
183
+ * Gate a tool call. When useRuntimeControl is on, run the full runtime
184
+ * decision (beforeAction) and surface its decisionId for audit linkage;
185
+ * otherwise use the lightweight permission check.
186
+ */
187
+ async gate(scope, actionTarget, payload) {
188
+ if (this.useRuntimeControl) {
189
+ try {
190
+ return await runtimeGate(this.vorim, this.agentId, actionTarget, scope, payload, {
191
+ onEscalation: this.onEscalation,
192
+ escalationTimeoutMs: this.escalationTimeoutMs,
193
+ onTransportFailure: this.onTransportFailure
194
+ });
195
+ } catch {
196
+ return { allowed: false, reason: "runtime gate unavailable (failed closed)" };
197
+ }
198
+ }
199
+ try {
200
+ const { allowed, reason } = await this.vorim.check(this.agentId, scope);
201
+ return { allowed, reason };
202
+ } catch {
203
+ return { allowed: false, reason: "permission check unavailable (failed closed)" };
204
+ }
205
+ }
206
+ async getReplayContext() {
207
+ if (!this.replayInputs) return {};
208
+ if (!this.replayCache) {
209
+ const inputs = {
210
+ ...this.replayInputs,
211
+ tools: this.replayInputs.tools ?? this.deriveCatalogue()
212
+ };
213
+ this.replayCache = prepareReplayContext(inputs);
214
+ }
215
+ return this.replayCache;
216
+ }
217
+ deriveCatalogue() {
218
+ return [...this.tools.values()].map((t) => ({
219
+ name: t.name,
220
+ description: t.description,
221
+ schema: t.parameters
222
+ }));
223
+ }
224
+ /** Register a tool. Invalidates the cached tool-catalogue hash. */
225
+ add(definition) {
226
+ this.tools.set(definition.name, definition);
227
+ this.replayCache = null;
228
+ return this;
229
+ }
230
+ /** Register multiple tools. */
231
+ /** Whether a tool with this name is registered. */
232
+ has(name) {
233
+ return this.tools.has(name);
234
+ }
235
+ addAll(definitions) {
236
+ for (const def of definitions) this.add(def);
237
+ return this;
238
+ }
239
+ /** Convert registered tools to OpenAI's ChatCompletionTool format. */
240
+ toOpenAITools() {
241
+ return [...this.tools.values()].map((t) => ({
242
+ type: "function",
243
+ function: {
244
+ name: t.name,
245
+ description: t.description,
246
+ parameters: t.parameters,
247
+ ...t.strict != null ? { strict: t.strict } : {}
248
+ }
249
+ }));
250
+ }
251
+ /**
252
+ * Execute tool calls from an OpenAI chat completion response.
253
+ * Each call is checked against Vorim permissions and audited.
254
+ * Returns an array of tool messages ready to append to the conversation.
255
+ */
256
+ async executeToolCalls(toolCalls) {
257
+ const results = await Promise.all(
258
+ toolCalls.map((tc) => this.executeSingleCall(tc))
259
+ );
260
+ return results;
261
+ }
262
+ async executeSingleCall(toolCall) {
263
+ const { id, function: fn } = toolCall;
264
+ const definition = this.tools.get(fn.name);
265
+ if (!definition) {
266
+ return {
267
+ role: "tool",
268
+ tool_call_id: id,
269
+ content: JSON.stringify({ error: `Unknown tool: ${fn.name}` })
270
+ };
271
+ }
272
+ const scope = definition.permission ?? this.defaultPermission;
273
+ let args;
274
+ try {
275
+ args = JSON.parse(fn.arguments);
276
+ } catch {
277
+ return {
278
+ role: "tool",
279
+ tool_call_id: id,
280
+ content: JSON.stringify({ error: `Invalid JSON arguments for ${fn.name}` })
281
+ };
282
+ }
283
+ const { allowed, reason, decisionId } = await this.gate(scope, fn.name, args);
284
+ const replayCtx = await this.getReplayContext();
285
+ if (!allowed) {
286
+ const event = {
287
+ agent_id: this.agentId,
288
+ event_type: "tool_call",
289
+ action: fn.name,
290
+ resource: truncate(fn.arguments, 500),
291
+ permission: scope,
292
+ result: "denied",
293
+ ...decisionId ? { decision_id: decisionId } : {},
294
+ metadata: { reason, framework: this.framework },
295
+ ...replayCtx
296
+ };
297
+ await this.emitAudit(event);
298
+ return {
299
+ role: "tool",
300
+ tool_call_id: id,
301
+ content: JSON.stringify({ error: `Permission denied: ${scope}${reason ? ` \u2014 ${reason}` : ""}` })
302
+ };
303
+ }
304
+ const start = Date.now();
305
+ try {
306
+ const result = await definition.execute(args);
307
+ const content = typeof result === "string" ? result : JSON.stringify(result);
308
+ const event = {
309
+ agent_id: this.agentId,
310
+ event_type: "tool_call",
311
+ action: fn.name,
312
+ resource: truncate(fn.arguments, 500),
313
+ permission: scope,
314
+ result: "success",
315
+ latency_ms: Date.now() - start,
316
+ ...decisionId ? { decision_id: decisionId } : {},
317
+ metadata: { framework: this.framework },
318
+ ...replayCtx
319
+ };
320
+ await this.emitAudit(event);
321
+ return { role: "tool", tool_call_id: id, content };
322
+ } catch (err) {
323
+ const errMsg = err instanceof Error ? err.message : String(err);
324
+ const event = {
325
+ agent_id: this.agentId,
326
+ event_type: "tool_call",
327
+ action: fn.name,
328
+ resource: truncate(fn.arguments, 500),
329
+ permission: scope,
330
+ result: "error",
331
+ latency_ms: Date.now() - start,
332
+ error_code: err instanceof Error ? err.name : "UNKNOWN",
333
+ ...decisionId ? { decision_id: decisionId } : {},
334
+ metadata: { error: errMsg, framework: this.framework },
335
+ ...replayCtx
336
+ };
337
+ await this.emitAudit(event);
338
+ return {
339
+ role: "tool",
340
+ tool_call_id: id,
341
+ content: JSON.stringify({ error: errMsg })
342
+ };
343
+ }
344
+ }
345
+ async emitAudit(event) {
346
+ if (this.asyncAudit) {
347
+ this.vorim.emit(event).catch(() => {
348
+ });
349
+ } else {
350
+ try {
351
+ await this.vorim.emit(event);
352
+ } catch {
353
+ }
354
+ }
355
+ }
356
+ };
357
+ function truncate(str, max) {
358
+ return str.length > max ? str.slice(0, max) + "\u2026" : str;
359
+ }
360
+
361
+ // src/integrations/mistral.ts
362
+ var MISTRAL_BASE_URL = "https://api.mistral.ai/v1";
363
+ var MISTRAL_EU_BASE_URL = "https://api.eu.mistral.ai/v1";
364
+ var MISTRAL_US_BASE_URL = "https://api.us.mistral.ai/v1";
365
+ var DEFAULT_MISTRAL_MODEL = "mistral-medium-latest";
366
+ var MISTRAL_SMALL_MODEL = "mistral-small-latest";
367
+ var MISTRAL_CODE_MODEL = "codestral-latest";
368
+ function createMistralRegistry(config) {
369
+ return new VorimToolRegistry({ ...config, framework: config.framework ?? "mistral" });
370
+ }
371
+ function normaliseMistralToolCalls(calls) {
372
+ return (calls ?? []).map((c, i) => ({
373
+ id: c.id && c.id !== "null" ? c.id : `mistral_call_${i}`,
374
+ type: "function",
375
+ function: {
376
+ name: c.function.name,
377
+ arguments: typeof c.function.arguments === "string" ? c.function.arguments : JSON.stringify(c.function.arguments ?? {})
378
+ }
379
+ }));
380
+ }
381
+ function isSdkClient(c) {
382
+ return typeof c?.chat?.complete === "function";
383
+ }
384
+ async function runMistralAgentLoop(config) {
385
+ const { mistral, registry, userMessage, systemPrompt, model = DEFAULT_MISTRAL_MODEL, maxIterations = 10 } = config;
386
+ const sdk = isSdkClient(mistral);
387
+ const messages = [];
388
+ if (systemPrompt) messages.push({ role: "system", content: systemPrompt });
389
+ messages.push({ role: "user", content: userMessage });
390
+ const tools = registry.toOpenAITools();
391
+ for (let i = 0; i < maxIterations; i++) {
392
+ const args = { model, messages, ...tools.length ? { tools } : {} };
393
+ if (config.parallelToolCalls != null) args[sdk ? "parallelToolCalls" : "parallel_tool_calls"] = config.parallelToolCalls;
394
+ const res = sdk ? await mistral.chat.complete(args) : await mistral.chat.completions.create(args);
395
+ const choice = res?.choices?.[0];
396
+ if (!choice) return "";
397
+ const msg = choice.message ?? {};
398
+ const rawCalls = sdk ? msg.toolCalls : msg.tool_calls;
399
+ const finish = sdk ? choice.finishReason : choice.finish_reason;
400
+ const calls = normaliseMistralToolCalls(rawCalls);
401
+ if (!calls.length || finish !== "tool_calls") {
402
+ return typeof msg.content === "string" ? msg.content : contentText(msg.content);
403
+ }
404
+ messages.push(sdk ? { role: "assistant", content: msg.content ?? "", toolCalls: calls } : { role: "assistant", content: msg.content ?? "", tool_calls: calls });
405
+ const results = await registry.executeToolCalls(calls);
406
+ for (const r of results) {
407
+ const name = calls.find((c) => c.id === r.tool_call_id)?.function.name;
408
+ messages.push(sdk ? { role: "tool", toolCallId: r.tool_call_id, name, content: r.content } : { role: "tool", tool_call_id: r.tool_call_id, name, content: r.content });
409
+ }
410
+ }
411
+ const last = messages[messages.length - 1];
412
+ return typeof last?.content === "string" ? last.content : "";
413
+ }
414
+ function contentText(content) {
415
+ if (!Array.isArray(content)) return "";
416
+ return content.map((c) => c?.type === "text" && typeof c.text === "string" ? c.text : "").join("");
417
+ }
418
+ var callId = (e, i) => e.tool_call_id ?? e.toolCallId ?? `mistral_call_${i}`;
419
+ var pending = (e) => (e.confirmation_status ?? e.confirmationStatus) === "pending";
420
+ async function executeMistralFunctionCalls(registry, outputs) {
421
+ const calls = (outputs ?? []).map((e, i) => ({ e, id: callId(e, i) })).filter(({ e }) => e.type === "function.call" && !pending(e) && registry.has(e.name));
422
+ if (!calls.length) return [];
423
+ const results = await registry.executeToolCalls(normaliseMistralToolCalls(
424
+ calls.map(({ e, id }) => ({ id, function: { name: e.name, arguments: e.arguments } }))
425
+ ));
426
+ return results.map((r) => ({ type: "function.result", tool_call_id: r.tool_call_id, result: r.content }));
427
+ }
428
+ async function decideMistralConfirmations(config, outputs) {
429
+ const out = [];
430
+ const entries = (outputs ?? []).map((e, i) => ({ e, id: callId(e, i) })).filter(({ e }) => e.type === "function.call" && pending(e));
431
+ for (const { e, id } of entries) {
432
+ const scope = config.scopes?.[e.name] ?? config.defaultPermission ?? "agent:execute";
433
+ const argsText = typeof e.arguments === "string" ? e.arguments : JSON.stringify(e.arguments ?? {});
434
+ let payload;
435
+ try {
436
+ payload = typeof e.arguments === "string" ? JSON.parse(e.arguments) : e.arguments;
437
+ } catch {
438
+ payload = void 0;
439
+ }
440
+ let allowed = false;
441
+ let reason;
442
+ let decisionId;
443
+ try {
444
+ if (config.useRuntimeControl) {
445
+ ({ allowed, reason, decisionId } = await runtimeGate(config.vorim, config.agentId, e.name, scope, payload, {
446
+ onEscalation: config.onEscalation,
447
+ escalationTimeoutMs: config.escalationTimeoutMs,
448
+ onTransportFailure: config.onTransportFailure
449
+ }));
450
+ } else {
451
+ ({ allowed, reason } = await config.vorim.check(config.agentId, scope));
452
+ }
453
+ } catch {
454
+ allowed = false;
455
+ reason = "Vorim unavailable (failed closed)";
456
+ }
457
+ out.push({ tool_call_id: id, confirmation: allowed ? "allow" : "deny" });
458
+ config.vorim.emit({
459
+ agent_id: config.agentId,
460
+ event_type: "tool_call",
461
+ action: e.name,
462
+ resource: argsText.slice(0, 500),
463
+ permission: scope,
464
+ result: allowed ? "success" : "denied",
465
+ ...decisionId ? { decision_id: decisionId } : {},
466
+ metadata: { framework: "mistral", stage: "confirmation", executed_by: "mistral", ...reason ? { reason } : {} }
467
+ }).catch(() => {
468
+ });
469
+ }
470
+ return out;
471
+ }
472
+ // Annotate the CommonJS export names for ESM import in node:
473
+ 0 && (module.exports = {
474
+ DEFAULT_MISTRAL_MODEL,
475
+ MISTRAL_BASE_URL,
476
+ MISTRAL_CODE_MODEL,
477
+ MISTRAL_EU_BASE_URL,
478
+ MISTRAL_SMALL_MODEL,
479
+ MISTRAL_US_BASE_URL,
480
+ VorimToolRegistry,
481
+ createMistralRegistry,
482
+ decideMistralConfirmations,
483
+ executeMistralFunctionCalls,
484
+ normaliseMistralToolCalls,
485
+ runMistralAgentLoop
486
+ });
487
+ //# sourceMappingURL=mistral.cjs.map