@vorim/sdk 3.19.0 → 3.22.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 +49 -0
- package/README.md +73 -1
- package/dist/index.cjs +261 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +140 -3
- package/dist/index.d.ts +140 -3
- package/dist/index.js +253 -9
- package/dist/index.js.map +1 -1
- package/dist/integrations/anthropic.d.cts +2 -1
- package/dist/integrations/anthropic.d.ts +2 -1
- package/dist/integrations/ap2.d.cts +2 -1
- package/dist/integrations/ap2.d.ts +2 -1
- package/dist/integrations/aws-iam.d.cts +2 -1
- package/dist/integrations/aws-iam.d.ts +2 -1
- package/dist/integrations/bank-rails.d.cts +2 -1
- package/dist/integrations/bank-rails.d.ts +2 -1
- package/dist/integrations/circle.d.cts +2 -1
- package/dist/integrations/circle.d.ts +2 -1
- package/dist/integrations/cloudflare.d.cts +2 -1
- package/dist/integrations/cloudflare.d.ts +2 -1
- package/dist/integrations/coinbase-cdp.d.cts +2 -1
- package/dist/integrations/coinbase-cdp.d.ts +2 -1
- package/dist/integrations/commerce-agents.cjs +467 -0
- package/dist/integrations/commerce-agents.cjs.map +1 -0
- package/dist/integrations/commerce-agents.d.cts +200 -0
- package/dist/integrations/commerce-agents.d.ts +200 -0
- package/dist/integrations/commerce-agents.js +429 -0
- package/dist/integrations/commerce-agents.js.map +1 -0
- package/dist/integrations/crewai.d.cts +2 -1
- package/dist/integrations/crewai.d.ts +2 -1
- package/dist/integrations/entra.d.cts +2 -1
- package/dist/integrations/entra.d.ts +2 -1
- package/dist/integrations/fhir.d.cts +2 -1
- package/dist/integrations/fhir.d.ts +2 -1
- package/dist/integrations/grok.d.cts +2 -1
- package/dist/integrations/grok.d.ts +2 -1
- package/dist/integrations/guidewire.d.cts +2 -1
- package/dist/integrations/guidewire.d.ts +2 -1
- package/dist/integrations/hermes.d.cts +2 -1
- package/dist/integrations/hermes.d.ts +2 -1
- package/dist/integrations/jira.d.cts +2 -1
- package/dist/integrations/jira.d.ts +2 -1
- package/dist/integrations/langchain.d.cts +2 -1
- package/dist/integrations/langchain.d.ts +2 -1
- package/dist/integrations/langgraph.d.cts +2 -1
- package/dist/integrations/langgraph.d.ts +2 -1
- package/dist/integrations/legal.d.cts +2 -1
- package/dist/integrations/legal.d.ts +2 -1
- package/dist/integrations/life-sciences.d.cts +2 -1
- package/dist/integrations/life-sciences.d.ts +2 -1
- package/dist/integrations/linear.d.cts +2 -1
- package/dist/integrations/linear.d.ts +2 -1
- package/dist/integrations/lithic.d.cts +2 -1
- package/dist/integrations/lithic.d.ts +2 -1
- package/dist/integrations/llamaindex.d.cts +2 -1
- package/dist/integrations/llamaindex.d.ts +2 -1
- package/dist/integrations/marqeta.d.cts +2 -1
- package/dist/integrations/marqeta.d.ts +2 -1
- package/dist/integrations/modern-treasury.d.cts +2 -1
- package/dist/integrations/modern-treasury.d.ts +2 -1
- package/dist/integrations/muse.cjs +437 -0
- package/dist/integrations/muse.cjs.map +1 -0
- package/dist/integrations/muse.d.cts +72 -0
- package/dist/integrations/muse.d.ts +72 -0
- package/dist/integrations/muse.js +394 -0
- package/dist/integrations/muse.js.map +1 -0
- package/dist/integrations/nekuda.d.cts +2 -1
- package/dist/integrations/nekuda.d.ts +2 -1
- package/dist/integrations/okta.d.cts +2 -1
- package/dist/integrations/okta.d.ts +2 -1
- package/dist/integrations/openai.d.cts +2 -1
- package/dist/integrations/openai.d.ts +2 -1
- package/dist/integrations/openrouter.d.cts +2 -1
- package/dist/integrations/openrouter.d.ts +2 -1
- package/dist/integrations/paypal-agent.d.cts +2 -1
- package/dist/integrations/paypal-agent.d.ts +2 -1
- package/dist/integrations/perplexity.d.cts +2 -1
- package/dist/integrations/perplexity.d.ts +2 -1
- package/dist/integrations/plaid.d.cts +2 -1
- package/dist/integrations/plaid.d.ts +2 -1
- package/dist/integrations/ramp.d.cts +2 -1
- package/dist/integrations/ramp.d.ts +2 -1
- package/dist/integrations/shopify.d.cts +2 -1
- package/dist/integrations/shopify.d.ts +2 -1
- package/dist/integrations/siem.d.cts +1 -1
- package/dist/integrations/siem.d.ts +1 -1
- package/dist/integrations/skyfire.d.cts +2 -1
- package/dist/integrations/skyfire.d.ts +2 -1
- package/dist/integrations/stripe-acp.d.cts +2 -1
- package/dist/integrations/stripe-acp.d.ts +2 -1
- package/dist/integrations/stripe-issuing.d.cts +2 -1
- package/dist/integrations/stripe-issuing.d.ts +2 -1
- package/dist/integrations/truanon.d.cts +2 -1
- package/dist/integrations/truanon.d.ts +2 -1
- package/dist/integrations/typesafe.cjs +268 -0
- package/dist/integrations/typesafe.cjs.map +1 -0
- package/dist/integrations/typesafe.d.cts +145 -0
- package/dist/integrations/typesafe.d.ts +145 -0
- package/dist/integrations/typesafe.js +221 -0
- package/dist/integrations/typesafe.js.map +1 -0
- package/dist/integrations/ucp.d.cts +2 -1
- package/dist/integrations/ucp.d.ts +2 -1
- package/dist/integrations/vercel-ai.d.cts +2 -1
- package/dist/integrations/vercel-ai.d.ts +2 -1
- package/dist/integrations/x402.d.cts +2 -1
- package/dist/integrations/x402.d.ts +2 -1
- package/dist/{types-BmeluKHI.d.cts → types-BrDQAJdl.d.cts} +36 -1
- package/dist/{types-BmeluKHI.d.ts → types-BrDQAJdl.d.ts} +36 -1
- package/package.json +31 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { VorimSDK } from '../index.js';
|
|
2
|
-
import { P as PermissionScope } from '../types-
|
|
2
|
+
import { P as PermissionScope } from '../types-BrDQAJdl.js';
|
|
3
|
+
import '@vorim/shared-types';
|
|
3
4
|
|
|
4
5
|
/** The Jira REST operations this guard knows how to classify. Any other label
|
|
5
6
|
* is accepted too; it just defaults to the 'write' risk tier. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { P as PermissionScope, A as AgentRegistrationResult } from '../types-
|
|
1
|
+
import { P as PermissionScope, A as AgentRegistrationResult } from '../types-BrDQAJdl.cjs';
|
|
2
2
|
import { VorimSDK, ReplayInputs } from '../index.cjs';
|
|
3
3
|
import { E as EscalationPolicy, T as TransportFailurePolicy } from '../_runtime-gate-DOJUKJBu.cjs';
|
|
4
|
+
import '@vorim/shared-types';
|
|
4
5
|
|
|
5
6
|
/** Minimal subset of @langchain/core Serialized */
|
|
6
7
|
interface Serialized {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { P as PermissionScope, A as AgentRegistrationResult } from '../types-
|
|
1
|
+
import { P as PermissionScope, A as AgentRegistrationResult } from '../types-BrDQAJdl.js';
|
|
2
2
|
import { VorimSDK, ReplayInputs } from '../index.js';
|
|
3
3
|
import { E as EscalationPolicy, T as TransportFailurePolicy } from '../_runtime-gate-DOJUKJBu.js';
|
|
4
|
+
import '@vorim/shared-types';
|
|
4
5
|
|
|
5
6
|
/** Minimal subset of @langchain/core Serialized */
|
|
6
7
|
interface Serialized {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { VorimLangChainConfig } from './langchain.cjs';
|
|
2
|
-
import '../types-
|
|
2
|
+
import '../types-BrDQAJdl.cjs';
|
|
3
3
|
import '../index.cjs';
|
|
4
|
+
import '@vorim/shared-types';
|
|
4
5
|
import '../_runtime-gate-DOJUKJBu.cjs';
|
|
5
6
|
|
|
6
7
|
/** Config for the LangGraph wrappers (same shape as the LangChain config). */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { VorimLangChainConfig } from './langchain.js';
|
|
2
|
-
import '../types-
|
|
2
|
+
import '../types-BrDQAJdl.js';
|
|
3
3
|
import '../index.js';
|
|
4
|
+
import '@vorim/shared-types';
|
|
4
5
|
import '../_runtime-gate-DOJUKJBu.js';
|
|
5
6
|
|
|
6
7
|
/** Config for the LangGraph wrappers (same shape as the LangChain config). */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { VorimSDK } from '../index.cjs';
|
|
2
|
-
import { P as PermissionScope } from '../types-
|
|
2
|
+
import { P as PermissionScope } from '../types-BrDQAJdl.cjs';
|
|
3
|
+
import '@vorim/shared-types';
|
|
3
4
|
|
|
4
5
|
/** Which DMS this guard fronts. Configuration, not separate code paths. */
|
|
5
6
|
type LegalDms = 'imanage' | 'netdocuments';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { VorimSDK } from '../index.js';
|
|
2
|
-
import { P as PermissionScope } from '../types-
|
|
2
|
+
import { P as PermissionScope } from '../types-BrDQAJdl.js';
|
|
3
|
+
import '@vorim/shared-types';
|
|
3
4
|
|
|
4
5
|
/** Which DMS this guard fronts. Configuration, not separate code paths. */
|
|
5
6
|
type LegalDms = 'imanage' | 'netdocuments';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { VorimSDK } from '../index.cjs';
|
|
2
|
-
import { P as PermissionScope } from '../types-
|
|
2
|
+
import { P as PermissionScope } from '../types-BrDQAJdl.cjs';
|
|
3
|
+
import '@vorim/shared-types';
|
|
3
4
|
|
|
4
5
|
/** Which validated system this guard fronts. Configuration, not separate code
|
|
5
6
|
* paths. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { VorimSDK } from '../index.js';
|
|
2
|
-
import { P as PermissionScope } from '../types-
|
|
2
|
+
import { P as PermissionScope } from '../types-BrDQAJdl.js';
|
|
3
|
+
import '@vorim/shared-types';
|
|
3
4
|
|
|
4
5
|
/** Which validated system this guard fronts. Configuration, not separate code
|
|
5
6
|
* paths. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { VorimSDK } from '../index.cjs';
|
|
2
|
-
import { P as PermissionScope } from '../types-
|
|
2
|
+
import { P as PermissionScope } from '../types-BrDQAJdl.cjs';
|
|
3
|
+
import '@vorim/shared-types';
|
|
3
4
|
|
|
4
5
|
/** The Linear GraphQL mutations this guard knows how to classify. Any other
|
|
5
6
|
* label is accepted too; it just defaults to the 'write' risk tier. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { VorimSDK } from '../index.js';
|
|
2
|
-
import { P as PermissionScope } from '../types-
|
|
2
|
+
import { P as PermissionScope } from '../types-BrDQAJdl.js';
|
|
3
|
+
import '@vorim/shared-types';
|
|
3
4
|
|
|
4
5
|
/** The Linear GraphQL mutations this guard knows how to classify. Any other
|
|
5
6
|
* label is accepted too; it just defaults to the 'write' risk tier. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { VorimSDK } from '../index.cjs';
|
|
2
|
-
import { P as PermissionScope } from '../types-
|
|
2
|
+
import { P as PermissionScope } from '../types-BrDQAJdl.cjs';
|
|
3
|
+
import '@vorim/shared-types';
|
|
3
4
|
|
|
4
5
|
/** Lithic card types. SINGLE_USE and MERCHANT_LOCKED are the agent-friendly
|
|
5
6
|
* ones (one-shot / merchant-pinned delegated spend). */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { VorimSDK } from '../index.js';
|
|
2
|
-
import { P as PermissionScope } from '../types-
|
|
2
|
+
import { P as PermissionScope } from '../types-BrDQAJdl.js';
|
|
3
|
+
import '@vorim/shared-types';
|
|
3
4
|
|
|
4
5
|
/** Lithic card types. SINGLE_USE and MERCHANT_LOCKED are the agent-friendly
|
|
5
6
|
* ones (one-shot / merchant-pinned delegated spend). */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { P as PermissionScope, A as AgentRegistrationResult } from '../types-
|
|
1
|
+
import { P as PermissionScope, A as AgentRegistrationResult } from '../types-BrDQAJdl.cjs';
|
|
2
2
|
import { VorimSDK, ReplayInputs } from '../index.cjs';
|
|
3
3
|
import { E as EscalationPolicy, T as TransportFailurePolicy } from '../_runtime-gate-DOJUKJBu.cjs';
|
|
4
|
+
import '@vorim/shared-types';
|
|
4
5
|
|
|
5
6
|
/** Matches @llamaindex/core ToolMetadata */
|
|
6
7
|
interface ToolMetadata<P extends Record<string, unknown> = Record<string, unknown>> {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { P as PermissionScope, A as AgentRegistrationResult } from '../types-
|
|
1
|
+
import { P as PermissionScope, A as AgentRegistrationResult } from '../types-BrDQAJdl.js';
|
|
2
2
|
import { VorimSDK, ReplayInputs } from '../index.js';
|
|
3
3
|
import { E as EscalationPolicy, T as TransportFailurePolicy } from '../_runtime-gate-DOJUKJBu.js';
|
|
4
|
+
import '@vorim/shared-types';
|
|
4
5
|
|
|
5
6
|
/** Matches @llamaindex/core ToolMetadata */
|
|
6
7
|
interface ToolMetadata<P extends Record<string, unknown> = Record<string, unknown>> {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { VorimSDK } from '../index.cjs';
|
|
2
|
-
import { P as PermissionScope } from '../types-
|
|
2
|
+
import { P as PermissionScope } from '../types-BrDQAJdl.cjs';
|
|
3
|
+
import '@vorim/shared-types';
|
|
3
4
|
|
|
4
5
|
type MarqetaOperation = 'createCard' | 'velocityControl' | 'jitFunding' | 'suspendCard';
|
|
5
6
|
interface MarqetaConfig {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { VorimSDK } from '../index.js';
|
|
2
|
-
import { P as PermissionScope } from '../types-
|
|
2
|
+
import { P as PermissionScope } from '../types-BrDQAJdl.js';
|
|
3
|
+
import '@vorim/shared-types';
|
|
3
4
|
|
|
4
5
|
type MarqetaOperation = 'createCard' | 'velocityControl' | 'jitFunding' | 'suspendCard';
|
|
5
6
|
interface MarqetaConfig {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { VorimSDK } from '../index.cjs';
|
|
2
|
-
import '../types-
|
|
2
|
+
import '../types-BrDQAJdl.cjs';
|
|
3
|
+
import '@vorim/shared-types';
|
|
3
4
|
|
|
4
5
|
type MTEnvironment = 'sandbox' | 'production';
|
|
5
6
|
type MTPaymentType = 'ach' | 'wire' | 'rtp' | 'book' | 'check' | 'card' | 'stablecoin';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { VorimSDK } from '../index.js';
|
|
2
|
-
import '../types-
|
|
2
|
+
import '../types-BrDQAJdl.js';
|
|
3
|
+
import '@vorim/shared-types';
|
|
3
4
|
|
|
4
5
|
type MTEnvironment = 'sandbox' | 'production';
|
|
5
6
|
type MTPaymentType = 'ach' | 'wire' | 'rtp' | 'book' | 'check' | 'card' | 'stablecoin';
|
|
@@ -0,0 +1,437 @@
|
|
|
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/muse.ts
|
|
31
|
+
var muse_exports = {};
|
|
32
|
+
__export(muse_exports, {
|
|
33
|
+
DEFAULT_MUSE_MODEL: () => DEFAULT_MUSE_MODEL,
|
|
34
|
+
MUSE_API_KEY_ENV: () => MUSE_API_KEY_ENV,
|
|
35
|
+
MUSE_BASE_URL: () => MUSE_BASE_URL,
|
|
36
|
+
VorimToolRegistry: () => VorimToolRegistry,
|
|
37
|
+
createVorimMuseAgent: () => createVorimOpenAIAgent,
|
|
38
|
+
runAgentLoop: () => runAgentLoop,
|
|
39
|
+
runMuseAgentLoop: () => runMuseAgentLoop
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(muse_exports);
|
|
42
|
+
|
|
43
|
+
// src/integrations/_runtime-gate.ts
|
|
44
|
+
function isAllowVerdict(decision) {
|
|
45
|
+
return decision === "allow" || decision === "modify";
|
|
46
|
+
}
|
|
47
|
+
async function runtimeGate(vorim, agentId, actionTarget, scope, payload, opts = {}) {
|
|
48
|
+
const onEscalation = opts.onEscalation ?? "wait";
|
|
49
|
+
const onTransportFailure = opts.onTransportFailure ?? "deny";
|
|
50
|
+
const d = await vorim.beforeAction(
|
|
51
|
+
{ agentId, actionType: "tool_call", actionTarget, requiredScope: scope, payload },
|
|
52
|
+
{ throwOnDeny: false }
|
|
53
|
+
);
|
|
54
|
+
if (d.isFallback || d.decision === "fallback") {
|
|
55
|
+
if (onTransportFailure === "allow") {
|
|
56
|
+
return { allowed: true, reason: d.reason ?? "control plane unreachable (fail-open)", decisionId: d.decisionId || void 0 };
|
|
57
|
+
}
|
|
58
|
+
return { allowed: false, reason: d.reason ?? "control plane unreachable (failed closed)", decisionId: d.decisionId || void 0 };
|
|
59
|
+
}
|
|
60
|
+
if (d.decision !== "escalate") {
|
|
61
|
+
return { allowed: isAllowVerdict(d.decision), reason: d.reason, decisionId: d.decisionId || void 0 };
|
|
62
|
+
}
|
|
63
|
+
if (onEscalation === "allow") {
|
|
64
|
+
return { allowed: true, reason: d.reason ?? "escalated (auto-allowed)", decisionId: d.decisionId || void 0 };
|
|
65
|
+
}
|
|
66
|
+
if (onEscalation === "deny") {
|
|
67
|
+
return { allowed: false, reason: d.reason ?? "escalated (auto-denied \u2014 awaiting human)", decisionId: d.decisionId || void 0 };
|
|
68
|
+
}
|
|
69
|
+
if (!d.decisionId) {
|
|
70
|
+
return { allowed: false, reason: "escalated but no decisionId to poll", decisionId: void 0 };
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const resolved = await vorim.waitForDecisionResolution(d.decisionId, { timeoutMs: opts.escalationTimeoutMs });
|
|
74
|
+
return { allowed: isAllowVerdict(resolved.decision), reason: resolved.reason, decisionId: resolved.decisionId || d.decisionId };
|
|
75
|
+
} catch {
|
|
76
|
+
return { allowed: false, reason: "escalation not resolved before timeout", decisionId: d.decisionId };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/replay.ts
|
|
81
|
+
function jcsCanonicalise(value) {
|
|
82
|
+
if (value === null) return "null";
|
|
83
|
+
if (value === true) return "true";
|
|
84
|
+
if (value === false) return "false";
|
|
85
|
+
if (typeof value === "number") {
|
|
86
|
+
if (!Number.isFinite(value)) {
|
|
87
|
+
throw new Error("jcsCanonicalise: NaN and Infinity are not JCS-valid");
|
|
88
|
+
}
|
|
89
|
+
const abs = Math.abs(value);
|
|
90
|
+
if (value !== 0 && (abs >= 1e21 || abs < 1e-4 || Number.isInteger(value) && abs > 2 ** 53)) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`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}.`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
return value.toString();
|
|
96
|
+
}
|
|
97
|
+
if (typeof value === "string") {
|
|
98
|
+
return JSON.stringify(value);
|
|
99
|
+
}
|
|
100
|
+
if (Array.isArray(value)) {
|
|
101
|
+
return "[" + value.map(jcsCanonicalise).join(",") + "]";
|
|
102
|
+
}
|
|
103
|
+
if (typeof value === "object") {
|
|
104
|
+
const obj = value;
|
|
105
|
+
const keys = Object.keys(obj).filter((k) => obj[k] !== void 0).sort();
|
|
106
|
+
const parts = keys.map((k) => JSON.stringify(k) + ":" + jcsCanonicalise(obj[k]));
|
|
107
|
+
return "{" + parts.join(",") + "}";
|
|
108
|
+
}
|
|
109
|
+
throw new Error(`jcsCanonicalise: unsupported value type: ${typeof value}`);
|
|
110
|
+
}
|
|
111
|
+
async function sha256Hex(input) {
|
|
112
|
+
const bytes = typeof input === "string" ? new TextEncoder().encode(input) : input;
|
|
113
|
+
const subtle = globalThis.crypto?.subtle;
|
|
114
|
+
if (subtle) {
|
|
115
|
+
const buf = await subtle.digest("SHA-256", bytes);
|
|
116
|
+
return Array.from(new Uint8Array(buf)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
117
|
+
}
|
|
118
|
+
const nodeCrypto = await import("crypto");
|
|
119
|
+
return nodeCrypto.createHash("sha256").update(bytes).digest("hex");
|
|
120
|
+
}
|
|
121
|
+
async function hashTool(tool) {
|
|
122
|
+
const normalised = {
|
|
123
|
+
name: tool.name,
|
|
124
|
+
description: tool.description ?? "",
|
|
125
|
+
schema: tool.schema ?? {}
|
|
126
|
+
};
|
|
127
|
+
const hex = await sha256Hex(jcsCanonicalise(normalised));
|
|
128
|
+
return `sha256:${hex}`;
|
|
129
|
+
}
|
|
130
|
+
async function hashToolCatalogue(tools) {
|
|
131
|
+
if (tools.length === 0) {
|
|
132
|
+
return `sha256:${await sha256Hex("[]")}`;
|
|
133
|
+
}
|
|
134
|
+
const perTool = await Promise.all(tools.map(hashTool));
|
|
135
|
+
perTool.sort();
|
|
136
|
+
const hex = await sha256Hex(perTool.join(""));
|
|
137
|
+
return `sha256:${hex}`;
|
|
138
|
+
}
|
|
139
|
+
async function hashSystemPrompt(prompt) {
|
|
140
|
+
const hex = await sha256Hex(prompt);
|
|
141
|
+
return `sha256:${hex}`;
|
|
142
|
+
}
|
|
143
|
+
async function prepareReplayContext(inputs) {
|
|
144
|
+
const ctx = {};
|
|
145
|
+
if (inputs.modelVersion) ctx.model_version = inputs.modelVersion;
|
|
146
|
+
if (inputs.tools) ctx.tool_catalogue_hash = await hashToolCatalogue(inputs.tools);
|
|
147
|
+
if (inputs.systemPrompt) ctx.system_prompt_hash = await hashSystemPrompt(inputs.systemPrompt);
|
|
148
|
+
return ctx;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// src/integrations/openai.ts
|
|
152
|
+
var VorimToolRegistry = class {
|
|
153
|
+
vorim;
|
|
154
|
+
agentId;
|
|
155
|
+
defaultPermission;
|
|
156
|
+
asyncAudit;
|
|
157
|
+
useRuntimeControl;
|
|
158
|
+
onEscalation;
|
|
159
|
+
escalationTimeoutMs;
|
|
160
|
+
onTransportFailure;
|
|
161
|
+
tools = /* @__PURE__ */ new Map();
|
|
162
|
+
replayInputs;
|
|
163
|
+
replayCache = null;
|
|
164
|
+
constructor(config) {
|
|
165
|
+
this.vorim = config.vorim;
|
|
166
|
+
this.agentId = config.agentId;
|
|
167
|
+
this.defaultPermission = config.defaultPermission ?? "agent:execute";
|
|
168
|
+
this.asyncAudit = config.asyncAudit ?? true;
|
|
169
|
+
this.useRuntimeControl = config.useRuntimeControl ?? false;
|
|
170
|
+
this.onEscalation = config.onEscalation;
|
|
171
|
+
this.escalationTimeoutMs = config.escalationTimeoutMs;
|
|
172
|
+
this.onTransportFailure = config.onTransportFailure;
|
|
173
|
+
this.replayInputs = config.replay;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Gate a tool call. When useRuntimeControl is on, run the full runtime
|
|
177
|
+
* decision (beforeAction) and surface its decisionId for audit linkage;
|
|
178
|
+
* otherwise use the lightweight permission check.
|
|
179
|
+
*/
|
|
180
|
+
async gate(scope, actionTarget, payload) {
|
|
181
|
+
if (this.useRuntimeControl) {
|
|
182
|
+
try {
|
|
183
|
+
return await runtimeGate(this.vorim, this.agentId, actionTarget, scope, payload, {
|
|
184
|
+
onEscalation: this.onEscalation,
|
|
185
|
+
escalationTimeoutMs: this.escalationTimeoutMs,
|
|
186
|
+
onTransportFailure: this.onTransportFailure
|
|
187
|
+
});
|
|
188
|
+
} catch {
|
|
189
|
+
return { allowed: false, reason: "runtime gate unavailable (failed closed)" };
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
const { allowed, reason } = await this.vorim.check(this.agentId, scope);
|
|
194
|
+
return { allowed, reason };
|
|
195
|
+
} catch {
|
|
196
|
+
return { allowed: false, reason: "permission check unavailable (failed closed)" };
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
async getReplayContext() {
|
|
200
|
+
if (!this.replayInputs) return {};
|
|
201
|
+
if (!this.replayCache) {
|
|
202
|
+
const inputs = {
|
|
203
|
+
...this.replayInputs,
|
|
204
|
+
tools: this.replayInputs.tools ?? this.deriveCatalogue()
|
|
205
|
+
};
|
|
206
|
+
this.replayCache = prepareReplayContext(inputs);
|
|
207
|
+
}
|
|
208
|
+
return this.replayCache;
|
|
209
|
+
}
|
|
210
|
+
deriveCatalogue() {
|
|
211
|
+
return [...this.tools.values()].map((t) => ({
|
|
212
|
+
name: t.name,
|
|
213
|
+
description: t.description,
|
|
214
|
+
schema: t.parameters
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
/** Register a tool. Invalidates the cached tool-catalogue hash. */
|
|
218
|
+
add(definition) {
|
|
219
|
+
this.tools.set(definition.name, definition);
|
|
220
|
+
this.replayCache = null;
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
/** Register multiple tools. */
|
|
224
|
+
addAll(definitions) {
|
|
225
|
+
for (const def of definitions) this.add(def);
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
/** Convert registered tools to OpenAI's ChatCompletionTool format. */
|
|
229
|
+
toOpenAITools() {
|
|
230
|
+
return [...this.tools.values()].map((t) => ({
|
|
231
|
+
type: "function",
|
|
232
|
+
function: {
|
|
233
|
+
name: t.name,
|
|
234
|
+
description: t.description,
|
|
235
|
+
parameters: t.parameters,
|
|
236
|
+
...t.strict != null ? { strict: t.strict } : {}
|
|
237
|
+
}
|
|
238
|
+
}));
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Execute tool calls from an OpenAI chat completion response.
|
|
242
|
+
* Each call is checked against Vorim permissions and audited.
|
|
243
|
+
* Returns an array of tool messages ready to append to the conversation.
|
|
244
|
+
*/
|
|
245
|
+
async executeToolCalls(toolCalls) {
|
|
246
|
+
const results = await Promise.all(
|
|
247
|
+
toolCalls.map((tc) => this.executeSingleCall(tc))
|
|
248
|
+
);
|
|
249
|
+
return results;
|
|
250
|
+
}
|
|
251
|
+
async executeSingleCall(toolCall) {
|
|
252
|
+
const { id, function: fn } = toolCall;
|
|
253
|
+
const definition = this.tools.get(fn.name);
|
|
254
|
+
if (!definition) {
|
|
255
|
+
return {
|
|
256
|
+
role: "tool",
|
|
257
|
+
tool_call_id: id,
|
|
258
|
+
content: JSON.stringify({ error: `Unknown tool: ${fn.name}` })
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
const scope = definition.permission ?? this.defaultPermission;
|
|
262
|
+
let args;
|
|
263
|
+
try {
|
|
264
|
+
args = JSON.parse(fn.arguments);
|
|
265
|
+
} catch {
|
|
266
|
+
return {
|
|
267
|
+
role: "tool",
|
|
268
|
+
tool_call_id: id,
|
|
269
|
+
content: JSON.stringify({ error: `Invalid JSON arguments for ${fn.name}` })
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
const { allowed, reason, decisionId } = await this.gate(scope, fn.name, args);
|
|
273
|
+
const replayCtx = await this.getReplayContext();
|
|
274
|
+
if (!allowed) {
|
|
275
|
+
const event = {
|
|
276
|
+
agent_id: this.agentId,
|
|
277
|
+
event_type: "tool_call",
|
|
278
|
+
action: fn.name,
|
|
279
|
+
resource: truncate(fn.arguments, 500),
|
|
280
|
+
permission: scope,
|
|
281
|
+
result: "denied",
|
|
282
|
+
...decisionId ? { decision_id: decisionId } : {},
|
|
283
|
+
metadata: { reason, framework: "openai" },
|
|
284
|
+
...replayCtx
|
|
285
|
+
};
|
|
286
|
+
await this.emitAudit(event);
|
|
287
|
+
return {
|
|
288
|
+
role: "tool",
|
|
289
|
+
tool_call_id: id,
|
|
290
|
+
content: JSON.stringify({ error: `Permission denied: ${scope}${reason ? ` \u2014 ${reason}` : ""}` })
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
const start = Date.now();
|
|
294
|
+
try {
|
|
295
|
+
const result = await definition.execute(args);
|
|
296
|
+
const content = typeof result === "string" ? result : JSON.stringify(result);
|
|
297
|
+
const event = {
|
|
298
|
+
agent_id: this.agentId,
|
|
299
|
+
event_type: "tool_call",
|
|
300
|
+
action: fn.name,
|
|
301
|
+
resource: truncate(fn.arguments, 500),
|
|
302
|
+
permission: scope,
|
|
303
|
+
result: "success",
|
|
304
|
+
latency_ms: Date.now() - start,
|
|
305
|
+
...decisionId ? { decision_id: decisionId } : {},
|
|
306
|
+
metadata: { framework: "openai" },
|
|
307
|
+
...replayCtx
|
|
308
|
+
};
|
|
309
|
+
await this.emitAudit(event);
|
|
310
|
+
return { role: "tool", tool_call_id: id, content };
|
|
311
|
+
} catch (err) {
|
|
312
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
313
|
+
const event = {
|
|
314
|
+
agent_id: this.agentId,
|
|
315
|
+
event_type: "tool_call",
|
|
316
|
+
action: fn.name,
|
|
317
|
+
resource: truncate(fn.arguments, 500),
|
|
318
|
+
permission: scope,
|
|
319
|
+
result: "error",
|
|
320
|
+
latency_ms: Date.now() - start,
|
|
321
|
+
error_code: err instanceof Error ? err.name : "UNKNOWN",
|
|
322
|
+
...decisionId ? { decision_id: decisionId } : {},
|
|
323
|
+
metadata: { error: errMsg, framework: "openai" },
|
|
324
|
+
...replayCtx
|
|
325
|
+
};
|
|
326
|
+
await this.emitAudit(event);
|
|
327
|
+
return {
|
|
328
|
+
role: "tool",
|
|
329
|
+
tool_call_id: id,
|
|
330
|
+
content: JSON.stringify({ error: errMsg })
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
async emitAudit(event) {
|
|
335
|
+
if (this.asyncAudit) {
|
|
336
|
+
this.vorim.emit(event).catch(() => {
|
|
337
|
+
});
|
|
338
|
+
} else {
|
|
339
|
+
try {
|
|
340
|
+
await this.vorim.emit(event);
|
|
341
|
+
} catch {
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
async function runAgentLoop(config) {
|
|
347
|
+
const { openai, model = "gpt-4o", systemPrompt, maxIterations = 10, registry, userMessage } = config;
|
|
348
|
+
const messages = [];
|
|
349
|
+
if (systemPrompt) messages.push({ role: "system", content: systemPrompt });
|
|
350
|
+
messages.push({ role: "user", content: userMessage });
|
|
351
|
+
const tools = registry.toOpenAITools();
|
|
352
|
+
for (let i = 0; i < maxIterations; i++) {
|
|
353
|
+
const response = await openai.chat.completions.create({
|
|
354
|
+
model,
|
|
355
|
+
messages,
|
|
356
|
+
...tools.length > 0 ? { tools } : {}
|
|
357
|
+
});
|
|
358
|
+
const choice = response.choices[0];
|
|
359
|
+
messages.push(choice.message);
|
|
360
|
+
if (choice.finish_reason === "stop" || !choice.message.tool_calls?.length) {
|
|
361
|
+
return choice.message.content ?? "";
|
|
362
|
+
}
|
|
363
|
+
const toolMessages = await registry.executeToolCalls(choice.message.tool_calls);
|
|
364
|
+
messages.push(...toolMessages);
|
|
365
|
+
}
|
|
366
|
+
return messages[messages.length - 1]?.content ?? "";
|
|
367
|
+
}
|
|
368
|
+
async function createVorimOpenAIAgent(config) {
|
|
369
|
+
const { vorim, name, description, capabilities, scopes, tools } = config;
|
|
370
|
+
const registration = await vorim.register({
|
|
371
|
+
name,
|
|
372
|
+
description,
|
|
373
|
+
capabilities,
|
|
374
|
+
scopes
|
|
375
|
+
});
|
|
376
|
+
const agentId = registration.agent.agent_id;
|
|
377
|
+
const registry = new VorimToolRegistry({ vorim, agentId });
|
|
378
|
+
registry.addAll(tools);
|
|
379
|
+
return {
|
|
380
|
+
agentId,
|
|
381
|
+
registration,
|
|
382
|
+
registry,
|
|
383
|
+
privateKey: registration.private_key
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function truncate(str, max) {
|
|
387
|
+
return str.length > max ? str.slice(0, max) + "\u2026" : str;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// src/integrations/muse.ts
|
|
391
|
+
var MUSE_BASE_URL = "https://api.meta.ai/v1";
|
|
392
|
+
var MUSE_API_KEY_ENV = "MODEL_API_KEY";
|
|
393
|
+
var DEFAULT_MUSE_MODEL = "muse-spark-1.3";
|
|
394
|
+
async function runMuseAgentLoop(config) {
|
|
395
|
+
const {
|
|
396
|
+
muse,
|
|
397
|
+
model = DEFAULT_MUSE_MODEL,
|
|
398
|
+
parallelToolCalls,
|
|
399
|
+
systemPrompt,
|
|
400
|
+
maxIterations = 10,
|
|
401
|
+
registry,
|
|
402
|
+
userMessage
|
|
403
|
+
} = config;
|
|
404
|
+
const messages = [];
|
|
405
|
+
if (systemPrompt) messages.push({ role: "system", content: systemPrompt });
|
|
406
|
+
messages.push({ role: "user", content: userMessage });
|
|
407
|
+
const tools = registry.toOpenAITools();
|
|
408
|
+
for (let i = 0; i < maxIterations; i++) {
|
|
409
|
+
const response = await muse.chat.completions.create({
|
|
410
|
+
model,
|
|
411
|
+
messages,
|
|
412
|
+
...tools.length > 0 ? { tools } : {},
|
|
413
|
+
// Meta-specific: forward parallel_tool_calls only when the caller set it.
|
|
414
|
+
...parallelToolCalls !== void 0 ? { parallel_tool_calls: parallelToolCalls } : {}
|
|
415
|
+
// Deliberately no tool_choice: Meta returns 400 for anything but "auto".
|
|
416
|
+
});
|
|
417
|
+
const choice = response.choices[0];
|
|
418
|
+
messages.push(choice.message);
|
|
419
|
+
if (choice.finish_reason === "stop" || !choice.message.tool_calls?.length) {
|
|
420
|
+
return choice.message.content ?? "";
|
|
421
|
+
}
|
|
422
|
+
const toolMessages = await registry.executeToolCalls(choice.message.tool_calls);
|
|
423
|
+
messages.push(...toolMessages);
|
|
424
|
+
}
|
|
425
|
+
return messages[messages.length - 1]?.content ?? "";
|
|
426
|
+
}
|
|
427
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
428
|
+
0 && (module.exports = {
|
|
429
|
+
DEFAULT_MUSE_MODEL,
|
|
430
|
+
MUSE_API_KEY_ENV,
|
|
431
|
+
MUSE_BASE_URL,
|
|
432
|
+
VorimToolRegistry,
|
|
433
|
+
createVorimMuseAgent,
|
|
434
|
+
runAgentLoop,
|
|
435
|
+
runMuseAgentLoop
|
|
436
|
+
});
|
|
437
|
+
//# sourceMappingURL=muse.cjs.map
|