@vorim/sdk 3.5.0 → 3.6.1
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 +35 -0
- package/dist/_runtime-gate-DZQTkw4J.d.cts +11 -0
- package/dist/_runtime-gate-DZQTkw4J.d.ts +11 -0
- package/dist/index.cjs +13 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -233
- package/dist/index.d.ts +6 -233
- package/dist/index.js +13 -8
- package/dist/index.js.map +1 -1
- package/dist/integrations/anthropic.cjs +54 -5
- package/dist/integrations/anthropic.cjs.map +1 -1
- package/dist/integrations/anthropic.d.cts +30 -1
- package/dist/integrations/anthropic.d.ts +30 -1
- package/dist/integrations/anthropic.js +54 -5
- package/dist/integrations/anthropic.js.map +1 -1
- package/dist/integrations/crewai.d.cts +2 -1
- package/dist/integrations/crewai.d.ts +2 -1
- package/dist/integrations/langchain.cjs +12 -14
- package/dist/integrations/langchain.cjs.map +1 -1
- package/dist/integrations/langchain.d.cts +9 -1
- package/dist/integrations/langchain.d.ts +9 -1
- package/dist/integrations/langchain.js +12 -14
- package/dist/integrations/langchain.js.map +1 -1
- package/dist/integrations/langgraph.cjs +200 -0
- package/dist/integrations/langgraph.cjs.map +1 -0
- package/dist/integrations/langgraph.d.cts +20 -0
- package/dist/integrations/langgraph.d.ts +20 -0
- package/dist/integrations/langgraph.js +162 -0
- package/dist/integrations/langgraph.js.map +1 -0
- package/dist/integrations/llamaindex.cjs +3 -4
- package/dist/integrations/llamaindex.cjs.map +1 -1
- package/dist/integrations/llamaindex.d.cts +2 -1
- package/dist/integrations/llamaindex.d.ts +2 -1
- package/dist/integrations/llamaindex.js +3 -4
- package/dist/integrations/llamaindex.js.map +1 -1
- package/dist/integrations/openai.cjs +66 -11
- package/dist/integrations/openai.cjs.map +1 -1
- package/dist/integrations/openai.d.cts +37 -1
- package/dist/integrations/openai.d.ts +37 -1
- package/dist/integrations/openai.js +66 -11
- package/dist/integrations/openai.js.map +1 -1
- package/dist/integrations/siem.cjs +128 -0
- package/dist/integrations/siem.cjs.map +1 -0
- package/dist/integrations/siem.d.cts +57 -0
- package/dist/integrations/siem.d.ts +57 -0
- package/dist/integrations/siem.js +102 -0
- package/dist/integrations/siem.js.map +1 -0
- package/dist/integrations/stripe-acp.cjs +179 -0
- package/dist/integrations/stripe-acp.cjs.map +1 -0
- package/dist/integrations/stripe-acp.d.cts +69 -0
- package/dist/integrations/stripe-acp.d.ts +69 -0
- package/dist/integrations/stripe-acp.js +153 -0
- package/dist/integrations/stripe-acp.js.map +1 -0
- package/dist/integrations/vercel-ai.cjs +252 -0
- package/dist/integrations/vercel-ai.cjs.map +1 -0
- package/dist/integrations/vercel-ai.d.cts +67 -0
- package/dist/integrations/vercel-ai.d.ts +67 -0
- package/dist/integrations/vercel-ai.js +214 -0
- package/dist/integrations/vercel-ai.js.map +1 -0
- package/dist/types-B22WnXEW.d.cts +234 -0
- package/dist/types-B22WnXEW.d.ts +234 -0
- package/package.json +41 -1
|
@@ -0,0 +1,200 @@
|
|
|
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/langgraph.ts
|
|
31
|
+
var langgraph_exports = {};
|
|
32
|
+
__export(langgraph_exports, {
|
|
33
|
+
wrapGraphTool: () => wrapGraphTool,
|
|
34
|
+
wrapGraphTools: () => wrapGraphTools
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(langgraph_exports);
|
|
37
|
+
|
|
38
|
+
// src/replay.ts
|
|
39
|
+
function jcsCanonicalise(value) {
|
|
40
|
+
if (value === null) return "null";
|
|
41
|
+
if (value === true) return "true";
|
|
42
|
+
if (value === false) return "false";
|
|
43
|
+
if (typeof value === "number") {
|
|
44
|
+
if (!Number.isFinite(value)) {
|
|
45
|
+
throw new Error("jcsCanonicalise: NaN and Infinity are not JCS-valid");
|
|
46
|
+
}
|
|
47
|
+
return value.toString();
|
|
48
|
+
}
|
|
49
|
+
if (typeof value === "string") {
|
|
50
|
+
return JSON.stringify(value);
|
|
51
|
+
}
|
|
52
|
+
if (Array.isArray(value)) {
|
|
53
|
+
return "[" + value.map(jcsCanonicalise).join(",") + "]";
|
|
54
|
+
}
|
|
55
|
+
if (typeof value === "object") {
|
|
56
|
+
const obj = value;
|
|
57
|
+
const keys = Object.keys(obj).filter((k) => obj[k] !== void 0).sort();
|
|
58
|
+
const parts = keys.map((k) => JSON.stringify(k) + ":" + jcsCanonicalise(obj[k]));
|
|
59
|
+
return "{" + parts.join(",") + "}";
|
|
60
|
+
}
|
|
61
|
+
throw new Error(`jcsCanonicalise: unsupported value type: ${typeof value}`);
|
|
62
|
+
}
|
|
63
|
+
async function sha256Hex(input) {
|
|
64
|
+
const bytes = typeof input === "string" ? new TextEncoder().encode(input) : input;
|
|
65
|
+
const subtle = globalThis.crypto?.subtle;
|
|
66
|
+
if (subtle) {
|
|
67
|
+
const buf = await subtle.digest("SHA-256", bytes);
|
|
68
|
+
return Array.from(new Uint8Array(buf)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
69
|
+
}
|
|
70
|
+
const nodeCrypto = await import("crypto");
|
|
71
|
+
return nodeCrypto.createHash("sha256").update(bytes).digest("hex");
|
|
72
|
+
}
|
|
73
|
+
async function hashTool(tool) {
|
|
74
|
+
const normalised = {
|
|
75
|
+
name: tool.name,
|
|
76
|
+
description: tool.description ?? "",
|
|
77
|
+
schema: tool.schema ?? {}
|
|
78
|
+
};
|
|
79
|
+
const hex = await sha256Hex(jcsCanonicalise(normalised));
|
|
80
|
+
return `sha256:${hex}`;
|
|
81
|
+
}
|
|
82
|
+
async function hashToolCatalogue(tools) {
|
|
83
|
+
if (tools.length === 0) {
|
|
84
|
+
return `sha256:${await sha256Hex("[]")}`;
|
|
85
|
+
}
|
|
86
|
+
const perTool = await Promise.all(tools.map(hashTool));
|
|
87
|
+
perTool.sort();
|
|
88
|
+
const hex = await sha256Hex(perTool.join(""));
|
|
89
|
+
return `sha256:${hex}`;
|
|
90
|
+
}
|
|
91
|
+
async function hashSystemPrompt(prompt) {
|
|
92
|
+
const hex = await sha256Hex(prompt);
|
|
93
|
+
return `sha256:${hex}`;
|
|
94
|
+
}
|
|
95
|
+
async function prepareReplayContext(inputs) {
|
|
96
|
+
const ctx = {};
|
|
97
|
+
if (inputs.modelVersion) ctx.model_version = inputs.modelVersion;
|
|
98
|
+
if (inputs.tools) ctx.tool_catalogue_hash = await hashToolCatalogue(inputs.tools);
|
|
99
|
+
if (inputs.systemPrompt) ctx.system_prompt_hash = await hashSystemPrompt(inputs.systemPrompt);
|
|
100
|
+
return ctx;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/integrations/langchain.ts
|
|
104
|
+
function wrapTool(tool, config) {
|
|
105
|
+
const { vorim, agentId, permissionMap = {}, defaultPermission = "agent:execute", asyncAudit = true, replay, framework = "langchain" } = config;
|
|
106
|
+
const originalCall = tool._call.bind(tool);
|
|
107
|
+
const getReplayCtx = makeReplayContextGetter(replay);
|
|
108
|
+
tool._call = async function vorimGuardedCall(arg, runManager, parentConfig) {
|
|
109
|
+
const scope = permissionMap[tool.name] ?? defaultPermission;
|
|
110
|
+
const { allowed, reason } = await vorim.check(agentId, scope);
|
|
111
|
+
const replayCtx = await getReplayCtx();
|
|
112
|
+
if (!allowed) {
|
|
113
|
+
const event2 = {
|
|
114
|
+
agent_id: agentId,
|
|
115
|
+
event_type: "tool_call",
|
|
116
|
+
action: tool.name,
|
|
117
|
+
resource: truncate(JSON.stringify(arg), 500),
|
|
118
|
+
permission: scope,
|
|
119
|
+
result: "denied",
|
|
120
|
+
metadata: { reason, framework },
|
|
121
|
+
...replayCtx
|
|
122
|
+
};
|
|
123
|
+
await emitAudit(vorim, event2, asyncAudit);
|
|
124
|
+
throw new Error(`Vorim: permission denied for "${tool.name}" \u2014 scope "${scope}"${reason ? `: ${reason}` : ""}`);
|
|
125
|
+
}
|
|
126
|
+
const start = Date.now();
|
|
127
|
+
let result;
|
|
128
|
+
try {
|
|
129
|
+
result = await originalCall(arg, runManager, parentConfig);
|
|
130
|
+
} catch (err) {
|
|
131
|
+
const event2 = {
|
|
132
|
+
agent_id: agentId,
|
|
133
|
+
event_type: "tool_call",
|
|
134
|
+
action: tool.name,
|
|
135
|
+
resource: truncate(JSON.stringify(arg), 500),
|
|
136
|
+
permission: scope,
|
|
137
|
+
result: "error",
|
|
138
|
+
latency_ms: Date.now() - start,
|
|
139
|
+
error_code: err instanceof Error ? err.name : "UNKNOWN",
|
|
140
|
+
metadata: { error: err instanceof Error ? err.message : String(err), framework },
|
|
141
|
+
...replayCtx
|
|
142
|
+
};
|
|
143
|
+
await emitAudit(vorim, event2, asyncAudit);
|
|
144
|
+
throw err;
|
|
145
|
+
}
|
|
146
|
+
const event = {
|
|
147
|
+
agent_id: agentId,
|
|
148
|
+
event_type: "tool_call",
|
|
149
|
+
action: tool.name,
|
|
150
|
+
resource: truncate(JSON.stringify(arg), 500),
|
|
151
|
+
permission: scope,
|
|
152
|
+
result: "success",
|
|
153
|
+
latency_ms: Date.now() - start,
|
|
154
|
+
metadata: { framework },
|
|
155
|
+
...replayCtx
|
|
156
|
+
};
|
|
157
|
+
await emitAudit(vorim, event, asyncAudit);
|
|
158
|
+
return result;
|
|
159
|
+
};
|
|
160
|
+
return tool;
|
|
161
|
+
}
|
|
162
|
+
function makeReplayContextGetter(replay) {
|
|
163
|
+
if (!replay) return async () => ({});
|
|
164
|
+
let cached = null;
|
|
165
|
+
return () => {
|
|
166
|
+
if (!cached) cached = prepareReplayContext(replay);
|
|
167
|
+
return cached;
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function wrapTools(tools, config) {
|
|
171
|
+
return tools.map((t) => wrapTool(t, config));
|
|
172
|
+
}
|
|
173
|
+
function truncate(str, max) {
|
|
174
|
+
return str.length > max ? str.slice(0, max) + "\u2026" : str;
|
|
175
|
+
}
|
|
176
|
+
function emitAudit(vorim, event, async) {
|
|
177
|
+
if (async) {
|
|
178
|
+
vorim.emit(event).catch(() => {
|
|
179
|
+
});
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
return vorim.emit(event).then(() => void 0).catch(() => void 0);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// src/integrations/langgraph.ts
|
|
186
|
+
function wrapGraphTool(tool, config) {
|
|
187
|
+
return wrapTool(tool, withFramework(config));
|
|
188
|
+
}
|
|
189
|
+
function wrapGraphTools(tools, config) {
|
|
190
|
+
return wrapTools(tools, withFramework(config));
|
|
191
|
+
}
|
|
192
|
+
function withFramework(config) {
|
|
193
|
+
return { ...config, framework: config.framework ?? "langgraph" };
|
|
194
|
+
}
|
|
195
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
196
|
+
0 && (module.exports = {
|
|
197
|
+
wrapGraphTool,
|
|
198
|
+
wrapGraphTools
|
|
199
|
+
});
|
|
200
|
+
//# sourceMappingURL=langgraph.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/langgraph.ts","../../src/replay.ts","../../src/integrations/langchain.ts"],"sourcesContent":["// ============================================================================\n// VORIM SDK — LangGraph Integration\n// LangGraph builds stateful agent graphs out of LangChain tools. The right\n// place to enforce identity, permissions, and audit is the tool boundary —\n// every time a node executes a tool, it passes through a Vorim gate and emits\n// a signed audit event. This module reuses the LangChain tool wrappers (a\n// LangGraph tool IS a LangChain tool) and tags events with framework\n// \"langgraph\" so your audit trail names the graph correctly.\n//\n// Peer dependency: @langchain/core >=0.3.0 (and @langchain/langgraph to build\n// the graph itself — Vorim does not need it directly).\n//\n// Usage:\n// import { ToolNode } from '@langchain/langgraph/prebuilt';\n// import createVorim from '@vorim/sdk';\n// import { wrapGraphTools } from '@vorim/sdk/integrations/langgraph';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_live_...' });\n// const guarded = wrapGraphTools([searchTool, writeTool], {\n// vorim, agentId: 'agid_acme_a1b2c3d4',\n// permissionMap: { writeTool: 'agent:write' },\n// });\n// const toolNode = new ToolNode(guarded); // drop into your StateGraph\n// ============================================================================\n\nimport { wrapTool, wrapTools, type VorimLangChainConfig } from './langchain.js';\n\n/** Config for the LangGraph wrappers (same shape as the LangChain config). */\nexport type VorimLangGraphConfig = VorimLangChainConfig;\n\n/**\n * Wrap a single tool used inside a LangGraph node. Each execution is gated by\n * a Vorim permission (or runtime-control) check and recorded in the signed\n * audit trail under framework \"langgraph\". A denied call throws so the graph\n * records the tool error.\n */\nexport function wrapGraphTool<T>(tool: T, config: VorimLangGraphConfig): T {\n return wrapTool(tool as any, withFramework(config)) as T;\n}\n\n/**\n * Wrap the array of tools you hand to a ToolNode / prebuilt ReAct agent.\n * Returns the same tools, each guarded.\n */\nexport function wrapGraphTools<T>(tools: T[], config: VorimLangGraphConfig): T[] {\n return wrapTools(tools as any[], withFramework(config)) as T[];\n}\n\n// Tag audit events as \"langgraph\" (the shared wrapper defaults to\n// 'langchain') so the audit trail names graph runs correctly, without\n// mutating the caller's config object.\nfunction withFramework(config: VorimLangGraphConfig): VorimLangGraphConfig {\n return { ...config, framework: config.framework ?? 'langgraph' };\n}\n","/**\n * Replayable agent decision evidence helpers.\n *\n * Canonical-form hashing for the VAIP -02 schema fields that the SDK\n * attaches to audit events. The hashes recorded in audit_events.tool_catalogue_hash\n * and audit_events.system_prompt_hash use these functions, so the bytes\n * an auditor or counterparty reconstructs must match what the SDK produced.\n *\n * These helpers are intentionally separate from the signing path. The\n * v0 canonical signature form (event_type|action|resource|input_hash|\n * output_hash|result) does NOT cover model_version, tool_catalogue_hash,\n * or system_prompt_hash. They will enter the canonical bytes in v1\n * (RFC 8785 JCS) in a follow-up release.\n *\n * Stable across SDK versions: the canonical-form version is documented\n * in CANONICAL_TOOL_CATALOGUE_VERSION. Future changes get a v2 etc;\n * never edit the existing v1 logic, or already-recorded hashes lose\n * their meaning.\n */\n\n// ─── Versioning ───────────────────────────────────────────────────────────\n\n/**\n * Canonical-form version for tool catalogue hashes produced by this SDK.\n * Recorded in tool_catalogue_canon_version on the event metadata (when\n * the metadata field is used) so verifiers know which hash recipe to\n * reproduce. Increment ONLY if the algorithm changes in a way that\n * would change the hash for the same logical catalogue.\n */\nexport const CANONICAL_TOOL_CATALOGUE_VERSION = 'v1' as const;\n\n// ─── Types ────────────────────────────────────────────────────────────────\n\n/**\n * Minimum shape a tool needs for catalogue hashing. The framework\n * integrations adapt their native tool objects to this shape before\n * calling hashToolCatalogue.\n */\nexport interface CatalogueTool {\n /** The name the model sees and calls. Required. */\n name: string;\n /** Human-readable description shown to the model. Optional; absent ↔ empty string. */\n description?: string;\n /**\n * JSON Schema describing the tool's input parameters. Optional;\n * absent ↔ empty object `{}`. The schema gets RFC 8785 JCS-canonicalised\n * before hashing so semantically-equivalent variations (key order,\n * whitespace) produce the same hash.\n */\n schema?: Record<string, unknown> | null;\n}\n\n// ─── RFC 8785 JCS subset ──────────────────────────────────────────────────\n\n/**\n * RFC 8785 JSON Canonicalization Scheme, sufficient subset for tool\n * catalogue values.\n *\n * Rules:\n * - Object keys sorted lexicographically by UTF-16 code units (which\n * is what JS string comparison does naturally).\n * - No whitespace between tokens.\n * - Numbers: integers as integers, finite floats per ECMAScript\n * Number.prototype.toString. JCS forbids NaN and Infinity.\n * - Strings: JSON-escape using minimal set per RFC 8259 § 7.\n * - null, true, false, arrays: as JSON.stringify produces them, since\n * JSON.stringify already produces the canonical form for these.\n *\n * Not vendoring a full library because tool schemas don't carry\n * non-integer numbers in practice and the JS spec for Number.toString\n * happens to coincide with JCS § 3.2.2.2 for the integer case.\n */\nexport function jcsCanonicalise(value: unknown): string {\n if (value === null) return 'null';\n if (value === true) return 'true';\n if (value === false) return 'false';\n\n if (typeof value === 'number') {\n if (!Number.isFinite(value)) {\n throw new Error('jcsCanonicalise: NaN and Infinity are not JCS-valid');\n }\n // For integers in safe range, .toString() matches JCS. For\n // non-integer floats, .toString() also matches in modern JS\n // engines (V8, JavaScriptCore, SpiderMonkey all use the shortest\n // round-trip representation, which is what JCS § 3.2.2.2 requires).\n return value.toString();\n }\n\n if (typeof value === 'string') {\n return JSON.stringify(value);\n }\n\n if (Array.isArray(value)) {\n return '[' + value.map(jcsCanonicalise).join(',') + ']';\n }\n\n if (typeof value === 'object') {\n const obj = value as Record<string, unknown>;\n // Filter undefined-valued fields, matching @vorim/verify and\n // @vorim/shared-types. Without this the SDK throws on { a: 1, b: undefined }\n // while the verifier silently drops b — a cross-module canonical-form\n // divergence that would break signature verification on such events.\n const keys = Object.keys(obj).filter(k => obj[k] !== undefined).sort();\n const parts = keys.map(k => JSON.stringify(k) + ':' + jcsCanonicalise(obj[k]));\n return '{' + parts.join(',') + '}';\n }\n\n // undefined, function, symbol, bigint — not JSON-representable\n throw new Error(`jcsCanonicalise: unsupported value type: ${typeof value}`);\n}\n\n// ─── SHA-256 ──────────────────────────────────────────────────────────────\n\nasync function sha256Hex(input: string | Uint8Array): Promise<string> {\n const bytes = typeof input === 'string' ? new TextEncoder().encode(input) : input;\n\n // Node.js Web Crypto (Node 18+) supports digest. Browser Web Crypto does too.\n // Fall back to node:crypto if Web Crypto is unavailable.\n const subtle = (globalThis as any).crypto?.subtle;\n if (subtle) {\n const buf = await subtle.digest('SHA-256', bytes);\n return Array.from(new Uint8Array(buf))\n .map(b => b.toString(16).padStart(2, '0'))\n .join('');\n }\n\n // Node fallback\n const nodeCrypto = await import('node:crypto');\n return nodeCrypto.createHash('sha256').update(bytes).digest('hex');\n}\n\n// ─── Public API ───────────────────────────────────────────────────────────\n\n/**\n * Hash a single tool definition. Returns `sha256:<hex>`.\n *\n * Canonical form (v1):\n * JCS-canonicalised JSON of `{name, description, schema}` where\n * absent fields substitute `description: \"\"` and `schema: {}`.\n */\nexport async function hashTool(tool: CatalogueTool): Promise<string> {\n const normalised = {\n name: tool.name,\n description: tool.description ?? '',\n schema: tool.schema ?? {},\n };\n const hex = await sha256Hex(jcsCanonicalise(normalised));\n return `sha256:${hex}`;\n}\n\n/**\n * Hash an entire tool catalogue. Returns `sha256:<hex>`.\n *\n * Reordering tools does NOT change the hash (tool hashes sorted\n * lexicographically before concatenation). Adding, removing, or\n * modifying a tool DOES change the hash.\n *\n * Per-tool hashing first means a verifier comparing two catalogue\n * hashes that differ can also be given the per-tool hashes to\n * identify which specific tool changed.\n */\nexport async function hashToolCatalogue(tools: CatalogueTool[]): Promise<string> {\n if (tools.length === 0) {\n // Empty catalogue has a deterministic, stable hash distinct from \"no field\"\n return `sha256:${await sha256Hex('[]')}`;\n }\n const perTool = await Promise.all(tools.map(hashTool));\n perTool.sort();\n const hex = await sha256Hex(perTool.join(''));\n return `sha256:${hex}`;\n}\n\n/**\n * Hash a system prompt. Returns `sha256:<hex>`.\n *\n * The prompt is UTF-8 encoded and hashed verbatim — no normalisation.\n * If a caller wants to ignore whitespace or comment differences, they\n * should normalise before calling. The intent here is deterministic\n * reproducibility, not semantic equivalence.\n */\nexport async function hashSystemPrompt(prompt: string): Promise<string> {\n const hex = await sha256Hex(prompt);\n return `sha256:${hex}`;\n}\n\n/**\n * Convenience: hash the previous event's canonical bytes for use in\n * the prev_event_hash field of hash-chained ingest. Caller provides\n * the canonical bytes (use canonicalPayloadV0 from the main module).\n */\nexport async function hashPreviousEvent(canonicalBytes: string): Promise<string> {\n const hex = await sha256Hex(canonicalBytes);\n return `sha256:${hex}`;\n}\n\n// ─── Replay context — framework integration helper ────────────────────────\n\n/**\n * Raw inputs the integration captures from the framework. Set by the\n * integration's config; turned into hashes by {@link prepareReplayContext}.\n */\nexport interface ReplayInputs {\n /** Stable identifier for the model. E.g. `\"anthropic:claude-opus-4-8\"`. */\n modelVersion?: string;\n /** Tools available to the agent at call time. Hashed via {@link hashToolCatalogue}. */\n tools?: CatalogueTool[];\n /** System prompt active at call time. Hashed via {@link hashSystemPrompt}. */\n systemPrompt?: string;\n}\n\n/**\n * Pre-computed hashes ready to attach to audit events. The three keys\n * match the audit_events column names.\n */\nexport interface ReplayContext {\n model_version?: string;\n tool_catalogue_hash?: string;\n system_prompt_hash?: string;\n}\n\n/**\n * Compute replay context once from raw inputs. Use at integration\n * setup time so each emit can attach the hashes without re-hashing.\n *\n * Returns an object suitable for spreading into an AuditEventInput:\n * `await vorim.emit({ ...event, ...replayContext })`\n *\n * If a field is absent in the inputs, it is absent in the result\n * (not the empty string). That keeps the event lean.\n */\nexport async function prepareReplayContext(\n inputs: ReplayInputs,\n): Promise<ReplayContext> {\n const ctx: ReplayContext = {};\n if (inputs.modelVersion) ctx.model_version = inputs.modelVersion;\n if (inputs.tools) ctx.tool_catalogue_hash = await hashToolCatalogue(inputs.tools);\n if (inputs.systemPrompt) ctx.system_prompt_hash = await hashSystemPrompt(inputs.systemPrompt);\n return ctx;\n}\n","// ============================================================================\n// VORIM SDK — LangChain / LangGraph JS Integration\n// Provides tool wrapping with permission checks + audit trail,\n// a callback handler for observability, and a factory for creating\n// Vorim-secured LangGraph ReAct agents.\n//\n// Peer dependencies:\n// @langchain/core >=0.3.0\n// @langchain/langgraph >=0.2.0\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\nimport type { PermissionScope, AuditEventInput } from '../types.js';\nimport {\n prepareReplayContext,\n type ReplayInputs,\n type ReplayContext,\n type CatalogueTool,\n} from '../replay.js';\n\n// ─── Re-declared LangChain types (peer dependency — not bundled) ──────────\n// These mirror the actual types from @langchain/core so consumers don't\n// need to import them separately for basic usage.\n\n/** Minimal subset of @langchain/core Serialized */\ninterface Serialized {\n lc: number;\n type: string;\n id: string[];\n kwargs?: Record<string, unknown>;\n}\n\n// ─── Configuration ────────────────────────────────────────────────────────\n\nexport interface VorimLangChainConfig {\n /** Vorim SDK instance. */\n vorim: VorimSDK;\n /** The Vorim agent_id to associate with this LangChain agent. */\n agentId: string;\n /** Map tool names → Vorim permission scopes. Unmapped tools default to 'agent:execute'. */\n permissionMap?: Record<string, PermissionScope>;\n /** Default permission scope for tools not in permissionMap. @default 'agent:execute' */\n defaultPermission?: PermissionScope;\n /** Whether to emit audit events asynchronously (fire-and-forget). @default true */\n asyncAudit?: boolean;\n /**\n * Framework name recorded on each audit event's metadata. Defaults to\n * 'langchain'. The LangGraph wrapper sets this to 'langgraph' so the audit\n * trail names the graph correctly while reusing this tool-wrapping logic.\n * @default 'langchain'\n */\n framework?: string;\n /**\n * Replayable agent decision evidence (VAIP -02). When provided, the\n * hashes of the model version, tool catalogue, and system prompt are\n * attached to every emitted audit event so an auditor can later\n * reproduce the agent's decision context.\n *\n * Hashes are computed once on first emit and cached for subsequent\n * emits in this config's lifetime.\n *\n * These fields are NOT covered by the v0 canonical signature form;\n * advisory only until v1 (RFC 8785 JCS) lands.\n */\n replay?: ReplayInputs;\n}\n\n// ─── Tool Wrapper ─────────────────────────────────────────────────────────\n\n/**\n * Wraps a LangChain `StructuredTool` (or `DynamicStructuredTool`) with\n * Vorim permission checks before execution and audit event emission after.\n *\n * Works with any tool that has `name`, `description`, `schema`, and `_call`.\n *\n * @example\n * ```ts\n * import { DynamicStructuredTool } from \"@langchain/core/tools\";\n * import { wrapTool } from \"@vorim/sdk/integrations/langchain\";\n *\n * const guarded = wrapTool(myTool, {\n * vorim, agentId: \"agid_acme_a1b2c3d4\",\n * permissionMap: { search_docs: \"agent:read\" },\n * });\n * ```\n */\nexport function wrapTool<T extends LangChainTool>(\n tool: T,\n config: VorimLangChainConfig,\n): T {\n const { vorim, agentId, permissionMap = {}, defaultPermission = 'agent:execute', asyncAudit = true, replay, framework = 'langchain' } = config;\n\n const originalCall = tool._call.bind(tool);\n const getReplayCtx = makeReplayContextGetter(replay);\n\n // Override _call to inject permission check + audit\n (tool as any)._call = async function vorimGuardedCall(\n arg: unknown,\n runManager?: unknown,\n parentConfig?: unknown,\n ): Promise<unknown> {\n const scope = permissionMap[tool.name] ?? defaultPermission;\n\n // 1. Permission check\n const { allowed, reason } = await vorim.check(agentId, scope);\n const replayCtx = await getReplayCtx();\n\n if (!allowed) {\n const event: AuditEventInput = {\n agent_id: agentId,\n event_type: 'tool_call',\n action: tool.name,\n resource: truncate(JSON.stringify(arg), 500),\n permission: scope,\n result: 'denied',\n metadata: { reason, framework },\n ...replayCtx,\n };\n await emitAudit(vorim, event, asyncAudit);\n throw new Error(`Vorim: permission denied for \"${tool.name}\" — scope \"${scope}\"${reason ? `: ${reason}` : ''}`);\n }\n\n // 2. Execute the original tool\n const start = Date.now();\n let result: unknown;\n try {\n result = await originalCall(arg, runManager, parentConfig);\n } catch (err) {\n const event: AuditEventInput = {\n agent_id: agentId,\n event_type: 'tool_call',\n action: tool.name,\n resource: truncate(JSON.stringify(arg), 500),\n permission: scope,\n result: 'error',\n latency_ms: Date.now() - start,\n error_code: err instanceof Error ? err.name : 'UNKNOWN',\n metadata: { error: err instanceof Error ? err.message : String(err), framework },\n ...replayCtx,\n };\n await emitAudit(vorim, event, asyncAudit);\n throw err;\n }\n\n // 3. Audit success\n const event: AuditEventInput = {\n agent_id: agentId,\n event_type: 'tool_call',\n action: tool.name,\n resource: truncate(JSON.stringify(arg), 500),\n permission: scope,\n result: 'success',\n latency_ms: Date.now() - start,\n metadata: { framework },\n ...replayCtx,\n };\n await emitAudit(vorim, event, asyncAudit);\n\n return result;\n };\n\n return tool;\n}\n\n/**\n * Lazy-cached replay context getter. The hashes are computed once on\n * first call and reused for subsequent calls in this closure's lifetime.\n * Returns an empty object when no `replay` config was provided so the\n * spread is a no-op.\n */\nfunction makeReplayContextGetter(replay: ReplayInputs | undefined): () => Promise<ReplayContext> {\n if (!replay) return async () => ({});\n let cached: Promise<ReplayContext> | null = null;\n return () => {\n if (!cached) cached = prepareReplayContext(replay);\n return cached;\n };\n}\n\n/**\n * Wraps an array of LangChain tools with Vorim permission + audit.\n */\nexport function wrapTools<T extends LangChainTool>(\n tools: T[],\n config: VorimLangChainConfig,\n): T[] {\n return tools.map(t => wrapTool(t, config));\n}\n\n// ─── Callback Handler ─────────────────────────────────────────────────────\n\n/**\n * LangChain callback handler that emits Vorim audit events for every\n * tool invocation. This is a **non-intrusive** observability layer —\n * it does not block or modify tool execution.\n *\n * Attach it to any LangChain invoke/stream call:\n * ```ts\n * const handler = new VorimCallbackHandler(vorim, \"agid_acme_a1b2c3d4\");\n * await agent.invoke({ messages }, { callbacks: [handler] });\n * ```\n */\nexport class VorimCallbackHandler {\n name = 'VorimCallbackHandler';\n private vorim: VorimSDK;\n private agentId: string;\n private runMap = new Map<string, { tool: string; input: string; startTime: number }>();\n private getReplayCtx: () => Promise<ReplayContext>;\n\n // Flags to satisfy BaseCallbackHandler interface\n ignoreLLM = true;\n ignoreChain = true;\n ignoreAgent = true;\n ignoreRetriever = true;\n ignoreCustomEvent = true;\n lc_serializable = false;\n\n get lc_id(): string[] { return ['vorim', 'callbacks', 'VorimCallbackHandler']; }\n get lc_namespace(): string[] { return ['vorim', 'callbacks']; }\n\n /**\n * @param vorim Vorim SDK instance.\n * @param agentId The Vorim agent_id whose actions this callback audits.\n * @param replay Optional replayable-evidence inputs. Same shape as\n * {@link VorimLangChainConfig.replay}; hashes are\n * computed once and attached to every audit event.\n */\n constructor(vorim: VorimSDK, agentId: string, replay?: ReplayInputs) {\n this.vorim = vorim;\n this.agentId = agentId;\n this.getReplayCtx = makeReplayContextGetter(replay);\n }\n\n async handleToolStart(\n tool: Serialized,\n input: string,\n runId: string,\n _parentRunId?: string,\n _tags?: string[],\n _metadata?: Record<string, unknown>,\n runName?: string,\n ): Promise<void> {\n const toolName = runName ?? tool.id?.[tool.id.length - 1] ?? 'unknown';\n this.runMap.set(runId, { tool: toolName, input, startTime: Date.now() });\n }\n\n async handleToolEnd(\n _output: unknown,\n runId: string,\n ): Promise<void> {\n const run = this.runMap.get(runId);\n if (!run) return;\n this.runMap.delete(runId);\n const replayCtx = await this.getReplayCtx();\n\n await this.vorim.emit({\n agent_id: this.agentId,\n event_type: 'tool_call',\n action: run.tool,\n resource: truncate(run.input, 500),\n result: 'success',\n latency_ms: Date.now() - run.startTime,\n metadata: { framework: 'langchain' },\n ...replayCtx,\n }).catch(() => {}); // never throw from callback\n }\n\n async handleToolError(\n err: Error,\n runId: string,\n ): Promise<void> {\n const run = this.runMap.get(runId);\n if (!run) return;\n this.runMap.delete(runId);\n const replayCtx = await this.getReplayCtx();\n\n await this.vorim.emit({\n agent_id: this.agentId,\n event_type: 'tool_call',\n action: run.tool,\n resource: truncate(run.input, 500),\n result: 'error',\n latency_ms: Date.now() - run.startTime,\n error_code: err.name,\n metadata: { error: err.message, framework: 'langchain' },\n ...replayCtx,\n }).catch(() => {});\n }\n\n // Required by BaseCallbackHandler — no-op for events we don't need\n copy(): VorimCallbackHandler {\n return new VorimCallbackHandler(this.vorim, this.agentId);\n }\n\n toJSON() {\n return { lc: 1, type: 'not_implemented', id: this.lc_id };\n }\n\n toJSONNotImplemented() {\n return this.toJSON();\n }\n}\n\n// ─── Agent Factory ────────────────────────────────────────────────────────\n\nexport interface CreateVorimAgentConfig extends VorimLangChainConfig {\n /** Display name for the agent when registering with Vorim. */\n name: string;\n /** Agent capabilities (e.g. [\"web_search\", \"code_execution\"]). */\n capabilities: string[];\n /** Initial permission scopes to grant. */\n scopes: PermissionScope[];\n /** Optional description. */\n description?: string;\n}\n\n/**\n * Registers a new agent with Vorim and returns wrapped tools + callback handler\n * ready to use with `createReactAgent` or any LangChain agent.\n *\n * @example\n * ```ts\n * import { createReactAgent } from \"@langchain/langgraph/prebuilt\";\n * import { ChatOpenAI } from \"@langchain/openai\";\n * import { createVorimAgent } from \"@vorim/sdk/integrations/langchain\";\n *\n * const { agentId, tools, callbackHandler } = await createVorimAgent({\n * vorim,\n * name: \"research-agent\",\n * capabilities: [\"web_search\"],\n * scopes: [\"agent:read\", \"agent:execute\"],\n * tools: [searchTool, analysisTool],\n * });\n *\n * const agent = createReactAgent({\n * llm: new ChatOpenAI({ model: \"gpt-4o\" }),\n * tools,\n * });\n *\n * const result = await agent.invoke(\n * { messages: [{ role: \"user\", content: \"Research AI trends\" }] },\n * { callbacks: [callbackHandler] },\n * );\n * ```\n */\nexport async function createVorimAgent<T extends LangChainTool>(config: CreateVorimAgentConfig & { tools: T[] }) {\n const { vorim, name, capabilities, scopes, description, tools: rawTools, permissionMap, defaultPermission, asyncAudit, replay } = config;\n\n // Register agent with Vorim\n const registration = await vorim.register({\n name,\n description,\n capabilities,\n scopes,\n });\n\n const agentId = registration.agent.agent_id;\n\n // If the caller passed `replay.tools`, use those. Otherwise derive a\n // tool catalogue from the rawTools we're about to wrap so the\n // replayable-evidence story works automatically.\n const derivedReplay: ReplayInputs | undefined = replay\n ? { ...replay, tools: replay.tools ?? deriveCatalogueFromLangChainTools(rawTools) }\n : { tools: deriveCatalogueFromLangChainTools(rawTools) };\n\n const agentConfig: VorimLangChainConfig = {\n vorim, agentId, permissionMap, defaultPermission, asyncAudit, replay: derivedReplay,\n };\n\n // Wrap tools with permission checks\n const tools = wrapTools(rawTools, agentConfig);\n\n // Create callback handler for audit trail\n const callbackHandler = new VorimCallbackHandler(vorim, agentId, derivedReplay);\n\n return {\n /** The Vorim agent_id. */\n agentId,\n /** The full agent registration result. */\n registration,\n /** Tools wrapped with Vorim permission checks + audit. */\n tools,\n /** Callback handler for audit trail observability. */\n callbackHandler,\n /** The private key (store securely — shown once). */\n privateKey: registration.private_key,\n };\n}\n\n// ─── Internal helpers ─────────────────────────────────────────────────────\n\n/** Minimal interface matching any LangChain StructuredTool / DynamicStructuredTool. */\ninterface LangChainTool {\n name: string;\n description: string;\n schema: unknown;\n _call(arg: any, runManager?: any, parentConfig?: any): Promise<any>;\n}\n\nfunction truncate(str: string, max: number): string {\n return str.length > max ? str.slice(0, max) + '…' : str;\n}\n\nfunction emitAudit(vorim: VorimSDK, event: AuditEventInput, async: boolean): Promise<void> | void {\n if (async) {\n vorim.emit(event).catch(() => {});\n return;\n }\n // asyncAudit=false: return the awaitable so callers can ensure the audit\n // event is persisted before the process exits.\n return vorim.emit(event).then(() => undefined).catch(() => undefined);\n}\n\n/**\n * Convert LangChain tools to the catalogue shape used by hashToolCatalogue.\n * Best-effort: LangChain tool schemas can be Zod or plain JSON Schema.\n * If we can't get a serialisable shape, we fall back to `null` schema\n * which the hashing treats as `{}`.\n */\nfunction deriveCatalogueFromLangChainTools(tools: LangChainTool[]): CatalogueTool[] {\n return tools.map(t => {\n let schema: Record<string, unknown> | null = null;\n const raw = t.schema as unknown;\n if (raw && typeof raw === 'object') {\n // If it's already plain JSON-serialisable, use it. Otherwise null.\n try {\n schema = JSON.parse(JSON.stringify(raw));\n } catch {\n schema = null;\n }\n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.cjs';
|
|
4
|
+
|
|
5
|
+
/** Config for the LangGraph wrappers (same shape as the LangChain config). */
|
|
6
|
+
type VorimLangGraphConfig = VorimLangChainConfig;
|
|
7
|
+
/**
|
|
8
|
+
* Wrap a single tool used inside a LangGraph node. Each execution is gated by
|
|
9
|
+
* a Vorim permission (or runtime-control) check and recorded in the signed
|
|
10
|
+
* audit trail under framework "langgraph". A denied call throws so the graph
|
|
11
|
+
* records the tool error.
|
|
12
|
+
*/
|
|
13
|
+
declare function wrapGraphTool<T>(tool: T, config: VorimLangGraphConfig): T;
|
|
14
|
+
/**
|
|
15
|
+
* Wrap the array of tools you hand to a ToolNode / prebuilt ReAct agent.
|
|
16
|
+
* Returns the same tools, each guarded.
|
|
17
|
+
*/
|
|
18
|
+
declare function wrapGraphTools<T>(tools: T[], config: VorimLangGraphConfig): T[];
|
|
19
|
+
|
|
20
|
+
export { type VorimLangGraphConfig, wrapGraphTool, wrapGraphTools };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { VorimLangChainConfig } from './langchain.js';
|
|
2
|
+
import '../types-B22WnXEW.js';
|
|
3
|
+
import '../index.js';
|
|
4
|
+
|
|
5
|
+
/** Config for the LangGraph wrappers (same shape as the LangChain config). */
|
|
6
|
+
type VorimLangGraphConfig = VorimLangChainConfig;
|
|
7
|
+
/**
|
|
8
|
+
* Wrap a single tool used inside a LangGraph node. Each execution is gated by
|
|
9
|
+
* a Vorim permission (or runtime-control) check and recorded in the signed
|
|
10
|
+
* audit trail under framework "langgraph". A denied call throws so the graph
|
|
11
|
+
* records the tool error.
|
|
12
|
+
*/
|
|
13
|
+
declare function wrapGraphTool<T>(tool: T, config: VorimLangGraphConfig): T;
|
|
14
|
+
/**
|
|
15
|
+
* Wrap the array of tools you hand to a ToolNode / prebuilt ReAct agent.
|
|
16
|
+
* Returns the same tools, each guarded.
|
|
17
|
+
*/
|
|
18
|
+
declare function wrapGraphTools<T>(tools: T[], config: VorimLangGraphConfig): T[];
|
|
19
|
+
|
|
20
|
+
export { type VorimLangGraphConfig, wrapGraphTool, wrapGraphTools };
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// src/replay.ts
|
|
2
|
+
function jcsCanonicalise(value) {
|
|
3
|
+
if (value === null) return "null";
|
|
4
|
+
if (value === true) return "true";
|
|
5
|
+
if (value === false) return "false";
|
|
6
|
+
if (typeof value === "number") {
|
|
7
|
+
if (!Number.isFinite(value)) {
|
|
8
|
+
throw new Error("jcsCanonicalise: NaN and Infinity are not JCS-valid");
|
|
9
|
+
}
|
|
10
|
+
return value.toString();
|
|
11
|
+
}
|
|
12
|
+
if (typeof value === "string") {
|
|
13
|
+
return JSON.stringify(value);
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
return "[" + value.map(jcsCanonicalise).join(",") + "]";
|
|
17
|
+
}
|
|
18
|
+
if (typeof value === "object") {
|
|
19
|
+
const obj = value;
|
|
20
|
+
const keys = Object.keys(obj).filter((k) => obj[k] !== void 0).sort();
|
|
21
|
+
const parts = keys.map((k) => JSON.stringify(k) + ":" + jcsCanonicalise(obj[k]));
|
|
22
|
+
return "{" + parts.join(",") + "}";
|
|
23
|
+
}
|
|
24
|
+
throw new Error(`jcsCanonicalise: unsupported value type: ${typeof value}`);
|
|
25
|
+
}
|
|
26
|
+
async function sha256Hex(input) {
|
|
27
|
+
const bytes = typeof input === "string" ? new TextEncoder().encode(input) : input;
|
|
28
|
+
const subtle = globalThis.crypto?.subtle;
|
|
29
|
+
if (subtle) {
|
|
30
|
+
const buf = await subtle.digest("SHA-256", bytes);
|
|
31
|
+
return Array.from(new Uint8Array(buf)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
32
|
+
}
|
|
33
|
+
const nodeCrypto = await import("crypto");
|
|
34
|
+
return nodeCrypto.createHash("sha256").update(bytes).digest("hex");
|
|
35
|
+
}
|
|
36
|
+
async function hashTool(tool) {
|
|
37
|
+
const normalised = {
|
|
38
|
+
name: tool.name,
|
|
39
|
+
description: tool.description ?? "",
|
|
40
|
+
schema: tool.schema ?? {}
|
|
41
|
+
};
|
|
42
|
+
const hex = await sha256Hex(jcsCanonicalise(normalised));
|
|
43
|
+
return `sha256:${hex}`;
|
|
44
|
+
}
|
|
45
|
+
async function hashToolCatalogue(tools) {
|
|
46
|
+
if (tools.length === 0) {
|
|
47
|
+
return `sha256:${await sha256Hex("[]")}`;
|
|
48
|
+
}
|
|
49
|
+
const perTool = await Promise.all(tools.map(hashTool));
|
|
50
|
+
perTool.sort();
|
|
51
|
+
const hex = await sha256Hex(perTool.join(""));
|
|
52
|
+
return `sha256:${hex}`;
|
|
53
|
+
}
|
|
54
|
+
async function hashSystemPrompt(prompt) {
|
|
55
|
+
const hex = await sha256Hex(prompt);
|
|
56
|
+
return `sha256:${hex}`;
|
|
57
|
+
}
|
|
58
|
+
async function prepareReplayContext(inputs) {
|
|
59
|
+
const ctx = {};
|
|
60
|
+
if (inputs.modelVersion) ctx.model_version = inputs.modelVersion;
|
|
61
|
+
if (inputs.tools) ctx.tool_catalogue_hash = await hashToolCatalogue(inputs.tools);
|
|
62
|
+
if (inputs.systemPrompt) ctx.system_prompt_hash = await hashSystemPrompt(inputs.systemPrompt);
|
|
63
|
+
return ctx;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/integrations/langchain.ts
|
|
67
|
+
function wrapTool(tool, config) {
|
|
68
|
+
const { vorim, agentId, permissionMap = {}, defaultPermission = "agent:execute", asyncAudit = true, replay, framework = "langchain" } = config;
|
|
69
|
+
const originalCall = tool._call.bind(tool);
|
|
70
|
+
const getReplayCtx = makeReplayContextGetter(replay);
|
|
71
|
+
tool._call = async function vorimGuardedCall(arg, runManager, parentConfig) {
|
|
72
|
+
const scope = permissionMap[tool.name] ?? defaultPermission;
|
|
73
|
+
const { allowed, reason } = await vorim.check(agentId, scope);
|
|
74
|
+
const replayCtx = await getReplayCtx();
|
|
75
|
+
if (!allowed) {
|
|
76
|
+
const event2 = {
|
|
77
|
+
agent_id: agentId,
|
|
78
|
+
event_type: "tool_call",
|
|
79
|
+
action: tool.name,
|
|
80
|
+
resource: truncate(JSON.stringify(arg), 500),
|
|
81
|
+
permission: scope,
|
|
82
|
+
result: "denied",
|
|
83
|
+
metadata: { reason, framework },
|
|
84
|
+
...replayCtx
|
|
85
|
+
};
|
|
86
|
+
await emitAudit(vorim, event2, asyncAudit);
|
|
87
|
+
throw new Error(`Vorim: permission denied for "${tool.name}" \u2014 scope "${scope}"${reason ? `: ${reason}` : ""}`);
|
|
88
|
+
}
|
|
89
|
+
const start = Date.now();
|
|
90
|
+
let result;
|
|
91
|
+
try {
|
|
92
|
+
result = await originalCall(arg, runManager, parentConfig);
|
|
93
|
+
} catch (err) {
|
|
94
|
+
const event2 = {
|
|
95
|
+
agent_id: agentId,
|
|
96
|
+
event_type: "tool_call",
|
|
97
|
+
action: tool.name,
|
|
98
|
+
resource: truncate(JSON.stringify(arg), 500),
|
|
99
|
+
permission: scope,
|
|
100
|
+
result: "error",
|
|
101
|
+
latency_ms: Date.now() - start,
|
|
102
|
+
error_code: err instanceof Error ? err.name : "UNKNOWN",
|
|
103
|
+
metadata: { error: err instanceof Error ? err.message : String(err), framework },
|
|
104
|
+
...replayCtx
|
|
105
|
+
};
|
|
106
|
+
await emitAudit(vorim, event2, asyncAudit);
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
const event = {
|
|
110
|
+
agent_id: agentId,
|
|
111
|
+
event_type: "tool_call",
|
|
112
|
+
action: tool.name,
|
|
113
|
+
resource: truncate(JSON.stringify(arg), 500),
|
|
114
|
+
permission: scope,
|
|
115
|
+
result: "success",
|
|
116
|
+
latency_ms: Date.now() - start,
|
|
117
|
+
metadata: { framework },
|
|
118
|
+
...replayCtx
|
|
119
|
+
};
|
|
120
|
+
await emitAudit(vorim, event, asyncAudit);
|
|
121
|
+
return result;
|
|
122
|
+
};
|
|
123
|
+
return tool;
|
|
124
|
+
}
|
|
125
|
+
function makeReplayContextGetter(replay) {
|
|
126
|
+
if (!replay) return async () => ({});
|
|
127
|
+
let cached = null;
|
|
128
|
+
return () => {
|
|
129
|
+
if (!cached) cached = prepareReplayContext(replay);
|
|
130
|
+
return cached;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function wrapTools(tools, config) {
|
|
134
|
+
return tools.map((t) => wrapTool(t, config));
|
|
135
|
+
}
|
|
136
|
+
function truncate(str, max) {
|
|
137
|
+
return str.length > max ? str.slice(0, max) + "\u2026" : str;
|
|
138
|
+
}
|
|
139
|
+
function emitAudit(vorim, event, async) {
|
|
140
|
+
if (async) {
|
|
141
|
+
vorim.emit(event).catch(() => {
|
|
142
|
+
});
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
return vorim.emit(event).then(() => void 0).catch(() => void 0);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/integrations/langgraph.ts
|
|
149
|
+
function wrapGraphTool(tool, config) {
|
|
150
|
+
return wrapTool(tool, withFramework(config));
|
|
151
|
+
}
|
|
152
|
+
function wrapGraphTools(tools, config) {
|
|
153
|
+
return wrapTools(tools, withFramework(config));
|
|
154
|
+
}
|
|
155
|
+
function withFramework(config) {
|
|
156
|
+
return { ...config, framework: config.framework ?? "langgraph" };
|
|
157
|
+
}
|
|
158
|
+
export {
|
|
159
|
+
wrapGraphTool,
|
|
160
|
+
wrapGraphTools
|
|
161
|
+
};
|
|
162
|
+
//# sourceMappingURL=langgraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/replay.ts","../../src/integrations/langchain.ts","../../src/integrations/langgraph.ts"],"sourcesContent":["/**\n * Replayable agent decision evidence helpers.\n *\n * Canonical-form hashing for the VAIP -02 schema fields that the SDK\n * attaches to audit events. The hashes recorded in audit_events.tool_catalogue_hash\n * and audit_events.system_prompt_hash use these functions, so the bytes\n * an auditor or counterparty reconstructs must match what the SDK produced.\n *\n * These helpers are intentionally separate from the signing path. The\n * v0 canonical signature form (event_type|action|resource|input_hash|\n * output_hash|result) does NOT cover model_version, tool_catalogue_hash,\n * or system_prompt_hash. They will enter the canonical bytes in v1\n * (RFC 8785 JCS) in a follow-up release.\n *\n * Stable across SDK versions: the canonical-form version is documented\n * in CANONICAL_TOOL_CATALOGUE_VERSION. Future changes get a v2 etc;\n * never edit the existing v1 logic, or already-recorded hashes lose\n * their meaning.\n */\n\n// ─── Versioning ───────────────────────────────────────────────────────────\n\n/**\n * Canonical-form version for tool catalogue hashes produced by this SDK.\n * Recorded in tool_catalogue_canon_version on the event metadata (when\n * the metadata field is used) so verifiers know which hash recipe to\n * reproduce. Increment ONLY if the algorithm changes in a way that\n * would change the hash for the same logical catalogue.\n */\nexport const CANONICAL_TOOL_CATALOGUE_VERSION = 'v1' as const;\n\n// ─── Types ────────────────────────────────────────────────────────────────\n\n/**\n * Minimum shape a tool needs for catalogue hashing. The framework\n * integrations adapt their native tool objects to this shape before\n * calling hashToolCatalogue.\n */\nexport interface CatalogueTool {\n /** The name the model sees and calls. Required. */\n name: string;\n /** Human-readable description shown to the model. Optional; absent ↔ empty string. */\n description?: string;\n /**\n * JSON Schema describing the tool's input parameters. Optional;\n * absent ↔ empty object `{}`. The schema gets RFC 8785 JCS-canonicalised\n * before hashing so semantically-equivalent variations (key order,\n * whitespace) produce the same hash.\n */\n schema?: Record<string, unknown> | null;\n}\n\n// ─── RFC 8785 JCS subset ──────────────────────────────────────────────────\n\n/**\n * RFC 8785 JSON Canonicalization Scheme, sufficient subset for tool\n * catalogue values.\n *\n * Rules:\n * - Object keys sorted lexicographically by UTF-16 code units (which\n * is what JS string comparison does naturally).\n * - No whitespace between tokens.\n * - Numbers: integers as integers, finite floats per ECMAScript\n * Number.prototype.toString. JCS forbids NaN and Infinity.\n * - Strings: JSON-escape using minimal set per RFC 8259 § 7.\n * - null, true, false, arrays: as JSON.stringify produces them, since\n * JSON.stringify already produces the canonical form for these.\n *\n * Not vendoring a full library because tool schemas don't carry\n * non-integer numbers in practice and the JS spec for Number.toString\n * happens to coincide with JCS § 3.2.2.2 for the integer case.\n */\nexport function jcsCanonicalise(value: unknown): string {\n if (value === null) return 'null';\n if (value === true) return 'true';\n if (value === false) return 'false';\n\n if (typeof value === 'number') {\n if (!Number.isFinite(value)) {\n throw new Error('jcsCanonicalise: NaN and Infinity are not JCS-valid');\n }\n // For integers in safe range, .toString() matches JCS. For\n // non-integer floats, .toString() also matches in modern JS\n // engines (V8, JavaScriptCore, SpiderMonkey all use the shortest\n // round-trip representation, which is what JCS § 3.2.2.2 requires).\n return value.toString();\n }\n\n if (typeof value === 'string') {\n return JSON.stringify(value);\n }\n\n if (Array.isArray(value)) {\n return '[' + value.map(jcsCanonicalise).join(',') + ']';\n }\n\n if (typeof value === 'object') {\n const obj = value as Record<string, unknown>;\n // Filter undefined-valued fields, matching @vorim/verify and\n // @vorim/shared-types. Without this the SDK throws on { a: 1, b: undefined }\n // while the verifier silently drops b — a cross-module canonical-form\n // divergence that would break signature verification on such events.\n const keys = Object.keys(obj).filter(k => obj[k] !== undefined).sort();\n const parts = keys.map(k => JSON.stringify(k) + ':' + jcsCanonicalise(obj[k]));\n return '{' + parts.join(',') + '}';\n }\n\n // undefined, function, symbol, bigint — not JSON-representable\n throw new Error(`jcsCanonicalise: unsupported value type: ${typeof value}`);\n}\n\n// ─── SHA-256 ──────────────────────────────────────────────────────────────\n\nasync function sha256Hex(input: string | Uint8Array): Promise<string> {\n const bytes = typeof input === 'string' ? new TextEncoder().encode(input) : input;\n\n // Node.js Web Crypto (Node 18+) supports digest. Browser Web Crypto does too.\n // Fall back to node:crypto if Web Crypto is unavailable.\n const subtle = (globalThis as any).crypto?.subtle;\n if (subtle) {\n const buf = await subtle.digest('SHA-256', bytes);\n return Array.from(new Uint8Array(buf))\n .map(b => b.toString(16).padStart(2, '0'))\n .join('');\n }\n\n // Node fallback\n const nodeCrypto = await import('node:crypto');\n return nodeCrypto.createHash('sha256').update(bytes).digest('hex');\n}\n\n// ─── Public API ───────────────────────────────────────────────────────────\n\n/**\n * Hash a single tool definition. Returns `sha256:<hex>`.\n *\n * Canonical form (v1):\n * JCS-canonicalised JSON of `{name, description, schema}` where\n * absent fields substitute `description: \"\"` and `schema: {}`.\n */\nexport async function hashTool(tool: CatalogueTool): Promise<string> {\n const normalised = {\n name: tool.name,\n description: tool.description ?? '',\n schema: tool.schema ?? {},\n };\n const hex = await sha256Hex(jcsCanonicalise(normalised));\n return `sha256:${hex}`;\n}\n\n/**\n * Hash an entire tool catalogue. Returns `sha256:<hex>`.\n *\n * Reordering tools does NOT change the hash (tool hashes sorted\n * lexicographically before concatenation). Adding, removing, or\n * modifying a tool DOES change the hash.\n *\n * Per-tool hashing first means a verifier comparing two catalogue\n * hashes that differ can also be given the per-tool hashes to\n * identify which specific tool changed.\n */\nexport async function hashToolCatalogue(tools: CatalogueTool[]): Promise<string> {\n if (tools.length === 0) {\n // Empty catalogue has a deterministic, stable hash distinct from \"no field\"\n return `sha256:${await sha256Hex('[]')}`;\n }\n const perTool = await Promise.all(tools.map(hashTool));\n perTool.sort();\n const hex = await sha256Hex(perTool.join(''));\n return `sha256:${hex}`;\n}\n\n/**\n * Hash a system prompt. Returns `sha256:<hex>`.\n *\n * The prompt is UTF-8 encoded and hashed verbatim — no normalisation.\n * If a caller wants to ignore whitespace or comment differences, they\n * should normalise before calling. The intent here is deterministic\n * reproducibility, not semantic equivalence.\n */\nexport async function hashSystemPrompt(prompt: string): Promise<string> {\n const hex = await sha256Hex(prompt);\n return `sha256:${hex}`;\n}\n\n/**\n * Convenience: hash the previous event's canonical bytes for use in\n * the prev_event_hash field of hash-chained ingest. Caller provides\n * the canonical bytes (use canonicalPayloadV0 from the main module).\n */\nexport async function hashPreviousEvent(canonicalBytes: string): Promise<string> {\n const hex = await sha256Hex(canonicalBytes);\n return `sha256:${hex}`;\n}\n\n// ─── Replay context — framework integration helper ────────────────────────\n\n/**\n * Raw inputs the integration captures from the framework. Set by the\n * integration's config; turned into hashes by {@link prepareReplayContext}.\n */\nexport interface ReplayInputs {\n /** Stable identifier for the model. E.g. `\"anthropic:claude-opus-4-8\"`. */\n modelVersion?: string;\n /** Tools available to the agent at call time. Hashed via {@link hashToolCatalogue}. */\n tools?: CatalogueTool[];\n /** System prompt active at call time. Hashed via {@link hashSystemPrompt}. */\n systemPrompt?: string;\n}\n\n/**\n * Pre-computed hashes ready to attach to audit events. The three keys\n * match the audit_events column names.\n */\nexport interface ReplayContext {\n model_version?: string;\n tool_catalogue_hash?: string;\n system_prompt_hash?: string;\n}\n\n/**\n * Compute replay context once from raw inputs. Use at integration\n * setup time so each emit can attach the hashes without re-hashing.\n *\n * Returns an object suitable for spreading into an AuditEventInput:\n * `await vorim.emit({ ...event, ...replayContext })`\n *\n * If a field is absent in the inputs, it is absent in the result\n * (not the empty string). That keeps the event lean.\n */\nexport async function prepareReplayContext(\n inputs: ReplayInputs,\n): Promise<ReplayContext> {\n const ctx: ReplayContext = {};\n if (inputs.modelVersion) ctx.model_version = inputs.modelVersion;\n if (inputs.tools) ctx.tool_catalogue_hash = await hashToolCatalogue(inputs.tools);\n if (inputs.systemPrompt) ctx.system_prompt_hash = await hashSystemPrompt(inputs.systemPrompt);\n return ctx;\n}\n","// ============================================================================\n// VORIM SDK — LangChain / LangGraph JS Integration\n// Provides tool wrapping with permission checks + audit trail,\n// a callback handler for observability, and a factory for creating\n// Vorim-secured LangGraph ReAct agents.\n//\n// Peer dependencies:\n// @langchain/core >=0.3.0\n// @langchain/langgraph >=0.2.0\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\nimport type { PermissionScope, AuditEventInput } from '../types.js';\nimport {\n prepareReplayContext,\n type ReplayInputs,\n type ReplayContext,\n type CatalogueTool,\n} from '../replay.js';\n\n// ─── Re-declared LangChain types (peer dependency — not bundled) ──────────\n// These mirror the actual types from @langchain/core so consumers don't\n// need to import them separately for basic usage.\n\n/** Minimal subset of @langchain/core Serialized */\ninterface Serialized {\n lc: number;\n type: string;\n id: string[];\n kwargs?: Record<string, unknown>;\n}\n\n// ─── Configuration ────────────────────────────────────────────────────────\n\nexport interface VorimLangChainConfig {\n /** Vorim SDK instance. */\n vorim: VorimSDK;\n /** The Vorim agent_id to associate with this LangChain agent. */\n agentId: string;\n /** Map tool names → Vorim permission scopes. Unmapped tools default to 'agent:execute'. */\n permissionMap?: Record<string, PermissionScope>;\n /** Default permission scope for tools not in permissionMap. @default 'agent:execute' */\n defaultPermission?: PermissionScope;\n /** Whether to emit audit events asynchronously (fire-and-forget). @default true */\n asyncAudit?: boolean;\n /**\n * Framework name recorded on each audit event's metadata. Defaults to\n * 'langchain'. The LangGraph wrapper sets this to 'langgraph' so the audit\n * trail names the graph correctly while reusing this tool-wrapping logic.\n * @default 'langchain'\n */\n framework?: string;\n /**\n * Replayable agent decision evidence (VAIP -02). When provided, the\n * hashes of the model version, tool catalogue, and system prompt are\n * attached to every emitted audit event so an auditor can later\n * reproduce the agent's decision context.\n *\n * Hashes are computed once on first emit and cached for subsequent\n * emits in this config's lifetime.\n *\n * These fields are NOT covered by the v0 canonical signature form;\n * advisory only until v1 (RFC 8785 JCS) lands.\n */\n replay?: ReplayInputs;\n}\n\n// ─── Tool Wrapper ─────────────────────────────────────────────────────────\n\n/**\n * Wraps a LangChain `StructuredTool` (or `DynamicStructuredTool`) with\n * Vorim permission checks before execution and audit event emission after.\n *\n * Works with any tool that has `name`, `description`, `schema`, and `_call`.\n *\n * @example\n * ```ts\n * import { DynamicStructuredTool } from \"@langchain/core/tools\";\n * import { wrapTool } from \"@vorim/sdk/integrations/langchain\";\n *\n * const guarded = wrapTool(myTool, {\n * vorim, agentId: \"agid_acme_a1b2c3d4\",\n * permissionMap: { search_docs: \"agent:read\" },\n * });\n * ```\n */\nexport function wrapTool<T extends LangChainTool>(\n tool: T,\n config: VorimLangChainConfig,\n): T {\n const { vorim, agentId, permissionMap = {}, defaultPermission = 'agent:execute', asyncAudit = true, replay, framework = 'langchain' } = config;\n\n const originalCall = tool._call.bind(tool);\n const getReplayCtx = makeReplayContextGetter(replay);\n\n // Override _call to inject permission check + audit\n (tool as any)._call = async function vorimGuardedCall(\n arg: unknown,\n runManager?: unknown,\n parentConfig?: unknown,\n ): Promise<unknown> {\n const scope = permissionMap[tool.name] ?? defaultPermission;\n\n // 1. Permission check\n const { allowed, reason } = await vorim.check(agentId, scope);\n const replayCtx = await getReplayCtx();\n\n if (!allowed) {\n const event: AuditEventInput = {\n agent_id: agentId,\n event_type: 'tool_call',\n action: tool.name,\n resource: truncate(JSON.stringify(arg), 500),\n permission: scope,\n result: 'denied',\n metadata: { reason, framework },\n ...replayCtx,\n };\n await emitAudit(vorim, event, asyncAudit);\n throw new Error(`Vorim: permission denied for \"${tool.name}\" — scope \"${scope}\"${reason ? `: ${reason}` : ''}`);\n }\n\n // 2. Execute the original tool\n const start = Date.now();\n let result: unknown;\n try {\n result = await originalCall(arg, runManager, parentConfig);\n } catch (err) {\n const event: AuditEventInput = {\n agent_id: agentId,\n event_type: 'tool_call',\n action: tool.name,\n resource: truncate(JSON.stringify(arg), 500),\n permission: scope,\n result: 'error',\n latency_ms: Date.now() - start,\n error_code: err instanceof Error ? err.name : 'UNKNOWN',\n metadata: { error: err instanceof Error ? err.message : String(err), framework },\n ...replayCtx,\n };\n await emitAudit(vorim, event, asyncAudit);\n throw err;\n }\n\n // 3. Audit success\n const event: AuditEventInput = {\n agent_id: agentId,\n event_type: 'tool_call',\n action: tool.name,\n resource: truncate(JSON.stringify(arg), 500),\n permission: scope,\n result: 'success',\n latency_ms: Date.now() - start,\n metadata: { framework },\n ...replayCtx,\n };\n await emitAudit(vorim, event, asyncAudit);\n\n return result;\n };\n\n return tool;\n}\n\n/**\n * Lazy-cached replay context getter. The hashes are computed once on\n * first call and reused for subsequent calls in this closure's lifetime.\n * Returns an empty object when no `replay` config was provided so the\n * spread is a no-op.\n */\nfunction makeReplayContextGetter(replay: ReplayInputs | undefined): () => Promise<ReplayContext> {\n if (!replay) return async () => ({});\n let cached: Promise<ReplayContext> | null = null;\n return () => {\n if (!cached) cached = prepareReplayContext(replay);\n return cached;\n };\n}\n\n/**\n * Wraps an array of LangChain tools with Vorim permission + audit.\n */\nexport function wrapTools<T extends LangChainTool>(\n tools: T[],\n config: VorimLangChainConfig,\n): T[] {\n return tools.map(t => wrapTool(t, config));\n}\n\n// ─── Callback Handler ─────────────────────────────────────────────────────\n\n/**\n * LangChain callback handler that emits Vorim audit events for every\n * tool invocation. This is a **non-intrusive** observability layer —\n * it does not block or modify tool execution.\n *\n * Attach it to any LangChain invoke/stream call:\n * ```ts\n * const handler = new VorimCallbackHandler(vorim, \"agid_acme_a1b2c3d4\");\n * await agent.invoke({ messages }, { callbacks: [handler] });\n * ```\n */\nexport class VorimCallbackHandler {\n name = 'VorimCallbackHandler';\n private vorim: VorimSDK;\n private agentId: string;\n private runMap = new Map<string, { tool: string; input: string; startTime: number }>();\n private getReplayCtx: () => Promise<ReplayContext>;\n\n // Flags to satisfy BaseCallbackHandler interface\n ignoreLLM = true;\n ignoreChain = true;\n ignoreAgent = true;\n ignoreRetriever = true;\n ignoreCustomEvent = true;\n lc_serializable = false;\n\n get lc_id(): string[] { return ['vorim', 'callbacks', 'VorimCallbackHandler']; }\n get lc_namespace(): string[] { return ['vorim', 'callbacks']; }\n\n /**\n * @param vorim Vorim SDK instance.\n * @param agentId The Vorim agent_id whose actions this callback audits.\n * @param replay Optional replayable-evidence inputs. Same shape as\n * {@link VorimLangChainConfig.replay}; hashes are\n * computed once and attached to every audit event.\n */\n constructor(vorim: VorimSDK, agentId: string, replay?: ReplayInputs) {\n this.vorim = vorim;\n this.agentId = agentId;\n this.getReplayCtx = makeReplayContextGetter(replay);\n }\n\n async handleToolStart(\n tool: Serialized,\n input: string,\n runId: string,\n _parentRunId?: string,\n _tags?: string[],\n _metadata?: Record<string, unknown>,\n runName?: string,\n ): Promise<void> {\n const toolName = runName ?? tool.id?.[tool.id.length - 1] ?? 'unknown';\n this.runMap.set(runId, { tool: toolName, input, startTime: Date.now() });\n }\n\n async handleToolEnd(\n _output: unknown,\n runId: string,\n ): Promise<void> {\n const run = this.runMap.get(runId);\n if (!run) return;\n this.runMap.delete(runId);\n const replayCtx = await this.getReplayCtx();\n\n await this.vorim.emit({\n agent_id: this.agentId,\n event_type: 'tool_call',\n action: run.tool,\n resource: truncate(run.input, 500),\n result: 'success',\n latency_ms: Date.now() - run.startTime,\n metadata: { framework: 'langchain' },\n ...replayCtx,\n }).catch(() => {}); // never throw from callback\n }\n\n async handleToolError(\n err: Error,\n runId: string,\n ): Promise<void> {\n const run = this.runMap.get(runId);\n if (!run) return;\n this.runMap.delete(runId);\n const replayCtx = await this.getReplayCtx();\n\n await this.vorim.emit({\n agent_id: this.agentId,\n event_type: 'tool_call',\n action: run.tool,\n resource: truncate(run.input, 500),\n result: 'error',\n latency_ms: Date.now() - run.startTime,\n error_code: err.name,\n metadata: { error: err.message, framework: 'langchain' },\n ...replayCtx,\n }).catch(() => {});\n }\n\n // Required by BaseCallbackHandler — no-op for events we don't need\n copy(): VorimCallbackHandler {\n return new VorimCallbackHandler(this.vorim, this.agentId);\n }\n\n toJSON() {\n return { lc: 1, type: 'not_implemented', id: this.lc_id };\n }\n\n toJSONNotImplemented() {\n return this.toJSON();\n }\n}\n\n// ─── Agent Factory ────────────────────────────────────────────────────────\n\nexport interface CreateVorimAgentConfig extends VorimLangChainConfig {\n /** Display name for the agent when registering with Vorim. */\n name: string;\n /** Agent capabilities (e.g. [\"web_search\", \"code_execution\"]). */\n capabilities: string[];\n /** Initial permission scopes to grant. */\n scopes: PermissionScope[];\n /** Optional description. */\n description?: string;\n}\n\n/**\n * Registers a new agent with Vorim and returns wrapped tools + callback handler\n * ready to use with `createReactAgent` or any LangChain agent.\n *\n * @example\n * ```ts\n * import { createReactAgent } from \"@langchain/langgraph/prebuilt\";\n * import { ChatOpenAI } from \"@langchain/openai\";\n * import { createVorimAgent } from \"@vorim/sdk/integrations/langchain\";\n *\n * const { agentId, tools, callbackHandler } = await createVorimAgent({\n * vorim,\n * name: \"research-agent\",\n * capabilities: [\"web_search\"],\n * scopes: [\"agent:read\", \"agent:execute\"],\n * tools: [searchTool, analysisTool],\n * });\n *\n * const agent = createReactAgent({\n * llm: new ChatOpenAI({ model: \"gpt-4o\" }),\n * tools,\n * });\n *\n * const result = await agent.invoke(\n * { messages: [{ role: \"user\", content: \"Research AI trends\" }] },\n * { callbacks: [callbackHandler] },\n * );\n * ```\n */\nexport async function createVorimAgent<T extends LangChainTool>(config: CreateVorimAgentConfig & { tools: T[] }) {\n const { vorim, name, capabilities, scopes, description, tools: rawTools, permissionMap, defaultPermission, asyncAudit, replay } = config;\n\n // Register agent with Vorim\n const registration = await vorim.register({\n name,\n description,\n capabilities,\n scopes,\n });\n\n const agentId = registration.agent.agent_id;\n\n // If the caller passed `replay.tools`, use those. Otherwise derive a\n // tool catalogue from the rawTools we're about to wrap so the\n // replayable-evidence story works automatically.\n const derivedReplay: ReplayInputs | undefined = replay\n ? { ...replay, tools: replay.tools ?? deriveCatalogueFromLangChainTools(rawTools) }\n : { tools: deriveCatalogueFromLangChainTools(rawTools) };\n\n const agentConfig: VorimLangChainConfig = {\n vorim, agentId, permissionMap, defaultPermission, asyncAudit, replay: derivedReplay,\n };\n\n // Wrap tools with permission checks\n const tools = wrapTools(rawTools, agentConfig);\n\n // Create callback handler for audit trail\n const callbackHandler = new VorimCallbackHandler(vorim, agentId, derivedReplay);\n\n return {\n /** The Vorim agent_id. */\n agentId,\n /** The full agent registration result. */\n registration,\n /** Tools wrapped with Vorim permission checks + audit. */\n tools,\n /** Callback handler for audit trail observability. */\n callbackHandler,\n /** The private key (store securely — shown once). */\n privateKey: registration.private_key,\n };\n}\n\n// ─── Internal helpers ─────────────────────────────────────────────────────\n\n/** Minimal interface matching any LangChain StructuredTool / DynamicStructuredTool. */\ninterface LangChainTool {\n name: string;\n description: string;\n schema: unknown;\n _call(arg: any, runManager?: any, parentConfig?: any): Promise<any>;\n}\n\nfunction truncate(str: string, max: number): string {\n return str.length > max ? str.slice(0, max) + '…' : str;\n}\n\nfunction emitAudit(vorim: VorimSDK, event: AuditEventInput, async: boolean): Promise<void> | void {\n if (async) {\n vorim.emit(event).catch(() => {});\n return;\n }\n // asyncAudit=false: return the awaitable so callers can ensure the audit\n // event is persisted before the process exits.\n return vorim.emit(event).then(() => undefined).catch(() => undefined);\n}\n\n/**\n * Convert LangChain tools to the catalogue shape used by hashToolCatalogue.\n * Best-effort: LangChain tool schemas can be Zod or plain JSON Schema.\n * If we can't get a serialisable shape, we fall back to `null` schema\n * which the hashing treats as `{}`.\n */\nfunction deriveCatalogueFromLangChainTools(tools: LangChainTool[]): CatalogueTool[] {\n return tools.map(t => {\n let schema: Record<string, unknown> | null = null;\n const raw = t.schema as unknown;\n if (raw && typeof raw === 'object') {\n // If it's already plain JSON-serialisable, use it. Otherwise null.\n try {\n schema = JSON.parse(JSON.stringify(raw));\n } catch {\n schema = null;\n }\n }\n return {\n name: t.name,\n description: t.description ?? '',\n schema,\n };\n });\n}\n","// ============================================================================\n// VORIM SDK — LangGraph Integration\n// LangGraph builds stateful agent graphs out of LangChain tools. The right\n// place to enforce identity, permissions, and audit is the tool boundary —\n// every time a node executes a tool, it passes through a Vorim gate and emits\n// a signed audit event. This module reuses the LangChain tool wrappers (a\n// LangGraph tool IS a LangChain tool) and tags events with framework\n// \"langgraph\" so your audit trail names the graph correctly.\n//\n// Peer dependency: @langchain/core >=0.3.0 (and @langchain/langgraph to build\n// the graph itself — Vorim does not need it directly).\n//\n// Usage:\n// import { ToolNode } from '@langchain/langgraph/prebuilt';\n// import createVorim from '@vorim/sdk';\n// import { wrapGraphTools } from '@vorim/sdk/integrations/langgraph';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_live_...' });\n// const guarded = wrapGraphTools([searchTool, writeTool], {\n// vorim, agentId: 'agid_acme_a1b2c3d4',\n// permissionMap: { writeTool: 'agent:write' },\n// });\n// const toolNode = new ToolNode(guarded); // drop into your StateGraph\n// ============================================================================\n\nimport { wrapTool, wrapTools, type VorimLangChainConfig } from './langchain.js';\n\n/** Config for the LangGraph wrappers (same shape as the LangChain config). */\nexport type VorimLangGraphConfig = VorimLangChainConfig;\n\n/**\n * Wrap a single tool used inside a LangGraph node. Each execution is gated by\n * a Vorim permission (or runtime-control) check and recorded in the signed\n * audit trail under framework \"langgraph\". A denied call throws so the graph\n * records the tool error.\n */\nexport function wrapGraphTool<T>(tool: T, config: VorimLangGraphConfig): T {\n return wrapTool(tool as any, withFramework(config)) as T;\n}\n\n/**\n * Wrap the array of tools you hand to a ToolNode / prebuilt ReAct agent.\n * Returns the same tools, each guarded.\n */\nexport function wrapGraphTools<T>(tools: T[], config: VorimLangGraphConfig): T[] {\n return wrapTools(tools as any[], withFramework(config)) as T[];\n}\n\n// Tag audit events as \"langgraph\" (the shared wrapper defaults to\n// 'langchain') so the audit trail names graph runs correctly, without\n// mutating the caller's config object.\nfunction withFramework(config: VorimLangGraphConfig): VorimLangGraphConfig {\n return { ...config, framework: config.framework ?? 'langgraph' };\n}\n"],"mappings":";AAwEO,SAAS,gBAAgB,OAAwB;AACtD,MAAI,UAAU,KAAM,QAAO;AAC3B,MAAI,UAAU,KAAM,QAAO;AAC3B,MAAI,UAAU,MAAO,QAAO;AAE5B,MAAI,OAAO,UAAU,UAAU;AAC7B,QAAI,CAAC,OAAO,SAAS,KAAK,GAAG;AAC3B,YAAM,IAAI,MAAM,qDAAqD;AAAA,IACvE;AAKA,WAAO,MAAM,SAAS;AAAA,EACxB;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,KAAK,UAAU,KAAK;AAAA,EAC7B;AAEA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,MAAM,MAAM,IAAI,eAAe,EAAE,KAAK,GAAG,IAAI;AAAA,EACtD;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,UAAM,MAAM;AAKZ,UAAM,OAAO,OAAO,KAAK,GAAG,EAAE,OAAO,OAAK,IAAI,CAAC,MAAM,MAAS,EAAE,KAAK;AACrE,UAAM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C;AAChC;AAAA,EACF;AAGA,SAAO,MAAM,KAAK,KAAK,EAAE,KAAK,MAAM,MAAS,EAAE,MAAM,MAAM,MAAS;AACtE;;;ACvXO,SAAS,cAAiB,MAAS,QAAiC;AACzE,SAAO,SAAS,MAAa,cAAc,MAAM,CAAC;AACpD;AAMO,SAAS,eAAkB,OAAY,QAAmC;AAC/E,SAAO,UAAU,OAAgB,cAAc,MAAM,CAAC;AACxD;AAKA,SAAS,cAAc,QAAoD;AACzE,SAAO,EAAE,GAAG,QAAQ,WAAW,OAAO,aAAa,YAAY;AACjE;","names":["event"]}
|
|
@@ -55,10 +55,9 @@ function jcsCanonicalise(value) {
|
|
|
55
55
|
return "[" + value.map(jcsCanonicalise).join(",") + "]";
|
|
56
56
|
}
|
|
57
57
|
if (typeof value === "object") {
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
});
|
|
58
|
+
const obj = value;
|
|
59
|
+
const keys = Object.keys(obj).filter((k) => obj[k] !== void 0).sort();
|
|
60
|
+
const parts = keys.map((k) => JSON.stringify(k) + ":" + jcsCanonicalise(obj[k]));
|
|
62
61
|
return "{" + parts.join(",") + "}";
|
|
63
62
|
}
|
|
64
63
|
throw new Error(`jcsCanonicalise: unsupported value type: ${typeof value}`);
|