@friskai/frisk-js 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +316 -0
  2. package/dist/adapters/index.d.ts +7 -0
  3. package/dist/adapters/index.d.ts.map +1 -0
  4. package/dist/adapters/langchain/frisk-callback-handler.d.ts +55 -0
  5. package/dist/adapters/langchain/frisk-callback-handler.d.ts.map +1 -0
  6. package/dist/adapters/langchain/frisk-langchain.d.ts +71 -0
  7. package/dist/adapters/langchain/frisk-langchain.d.ts.map +1 -0
  8. package/dist/adapters/langchain/frisk-tool-middleware.d.ts +68 -0
  9. package/dist/adapters/langchain/frisk-tool-middleware.d.ts.map +1 -0
  10. package/dist/adapters/langchain/index.d.ts +10 -0
  11. package/dist/adapters/langchain/index.d.ts.map +1 -0
  12. package/dist/adapters/langchain/langchain-framework-adapter/langchain-framework-adapter.d.ts +106 -0
  13. package/dist/adapters/langchain/langchain-framework-adapter/langchain-framework-adapter.d.ts.map +1 -0
  14. package/dist/adapters/langchain/langchain-framework-adapter/wrapToolWithLlmReasoning.d.ts +4 -0
  15. package/dist/adapters/langchain/langchain-framework-adapter/wrapToolWithLlmReasoning.d.ts.map +1 -0
  16. package/dist/adapters/langchain/langchain-framework-adapter.d.ts +105 -0
  17. package/dist/adapters/langchain/langchain-framework-adapter.d.ts.map +1 -0
  18. package/dist/adapters/langchain/types.d.ts +13 -0
  19. package/dist/adapters/langchain/types.d.ts.map +1 -0
  20. package/dist/adapters/langchain/wrapToolWithReasoning.d.ts +6 -0
  21. package/dist/adapters/langchain/wrapToolWithReasoning.d.ts.map +1 -0
  22. package/dist/core/frisk-options.d.ts +44 -0
  23. package/dist/core/frisk-options.d.ts.map +1 -0
  24. package/dist/core/frisk-session.d.ts +82 -0
  25. package/dist/core/frisk-session.d.ts.map +1 -0
  26. package/dist/core/frisk.d.ts +130 -0
  27. package/dist/core/frisk.d.ts.map +1 -0
  28. package/dist/core/install-graceful-shutdown.d.ts +67 -0
  29. package/dist/core/install-graceful-shutdown.d.ts.map +1 -0
  30. package/dist/core/llm-reasoning/constants.d.ts +2 -0
  31. package/dist/core/llm-reasoning/constants.d.ts.map +1 -0
  32. package/dist/core/llm-reasoning/removeLlmReasoningArg.d.ts +3 -0
  33. package/dist/core/llm-reasoning/removeLlmReasoningArg.d.ts.map +1 -0
  34. package/dist/core/session-registry.d.ts +50 -0
  35. package/dist/core/session-registry.d.ts.map +1 -0
  36. package/dist/core/token-manager.d.ts +155 -0
  37. package/dist/core/token-manager.d.ts.map +1 -0
  38. package/dist/core/tool-call-span.d.ts +89 -0
  39. package/dist/core/tool-call-span.d.ts.map +1 -0
  40. package/dist/core/types.d.ts +103 -0
  41. package/dist/core/types.d.ts.map +1 -0
  42. package/dist/env/index.d.ts +26 -0
  43. package/dist/env/index.d.ts.map +1 -0
  44. package/dist/env/mocks/mockEnv.d.ts +11 -0
  45. package/dist/env/mocks/mockEnv.d.ts.map +1 -0
  46. package/dist/errors/capture-error.d.ts +3 -0
  47. package/dist/errors/capture-error.d.ts.map +1 -0
  48. package/dist/errors/index.d.ts +76 -0
  49. package/dist/errors/index.d.ts.map +1 -0
  50. package/dist/framework-adapter/base-framework-adapter.d.ts +68 -0
  51. package/dist/framework-adapter/base-framework-adapter.d.ts.map +1 -0
  52. package/dist/framework-adapter/framework-adapter.d.ts +105 -0
  53. package/dist/framework-adapter/framework-adapter.d.ts.map +1 -0
  54. package/dist/framework-adapter/index.d.ts +12 -0
  55. package/dist/framework-adapter/index.d.ts.map +1 -0
  56. package/dist/index.d.ts +45 -0
  57. package/dist/index.d.ts.map +1 -0
  58. package/dist/index.js +58377 -0
  59. package/dist/index.js.map +493 -0
  60. package/dist/logging/console-logger.d.ts +3 -0
  61. package/dist/logging/console-logger.d.ts.map +1 -0
  62. package/dist/logging/create-scoped-logger.d.ts +6 -0
  63. package/dist/logging/create-scoped-logger.d.ts.map +1 -0
  64. package/dist/logging/derive-sdk-logger.d.ts +6 -0
  65. package/dist/logging/derive-sdk-logger.d.ts.map +1 -0
  66. package/dist/logging/index.d.ts +4 -0
  67. package/dist/logging/index.d.ts.map +1 -0
  68. package/dist/logging/log-error.d.ts +3 -0
  69. package/dist/logging/log-error.d.ts.map +1 -0
  70. package/dist/logging/types.d.ts +14 -0
  71. package/dist/logging/types.d.ts.map +1 -0
  72. package/dist/native-bindings/index.d.ts +18 -0
  73. package/dist/native-bindings/index.d.ts.map +1 -0
  74. package/dist/telemetry/constants.d.ts +6 -0
  75. package/dist/telemetry/constants.d.ts.map +1 -0
  76. package/dist/telemetry/dynamic-auth-metadata.d.ts +50 -0
  77. package/dist/telemetry/dynamic-auth-metadata.d.ts.map +1 -0
  78. package/dist/telemetry/get-otel-sdk.d.ts +18 -0
  79. package/dist/telemetry/get-otel-sdk.d.ts.map +1 -0
  80. package/dist/telemetry/get-tracer.d.ts +15 -0
  81. package/dist/telemetry/get-tracer.d.ts.map +1 -0
  82. package/dist/telemetry/index.d.ts +7 -0
  83. package/dist/telemetry/index.d.ts.map +1 -0
  84. package/dist/telemetry/mocks/index.d.ts +6 -0
  85. package/dist/telemetry/mocks/index.d.ts.map +1 -0
  86. package/dist/telemetry/mocks/mockTracer.d.ts +38 -0
  87. package/dist/telemetry/mocks/mockTracer.d.ts.map +1 -0
  88. package/dist/telemetry/mocks/mockTracerHandle.d.ts +56 -0
  89. package/dist/telemetry/mocks/mockTracerHandle.d.ts.map +1 -0
  90. package/dist/telemetry/tracer-handle.d.ts +18 -0
  91. package/dist/telemetry/tracer-handle.d.ts.map +1 -0
  92. package/dist/utils/redact.d.ts +57 -0
  93. package/dist/utils/redact.d.ts.map +1 -0
  94. package/native/.gitnore.bak +1 -0
  95. package/native/README.md +55 -0
  96. package/native/frisk-js.darwin-arm64.node +0 -0
  97. package/native/index.cjs +580 -0
  98. package/native/index.d.ts +69 -0
  99. package/package.json +99 -0
package/README.md ADDED
@@ -0,0 +1,316 @@
1
+ # frisk_js - JavaScript/TypeScript Bindings for FriskAI Policy Engine
2
+
3
+ JavaScript and TypeScript bindings for the FriskAI policy engine, available in two flavors:
4
+
5
+ 1. **Node-native N-API bindings** (recommended for Node.js) - Full-featured with OpenTelemetry and PolicyManager
6
+ 2. **WebAssembly bindings** - Lightweight for browser environments
7
+
8
+ ## Features
9
+
10
+ ### N-API Bindings (Node.js)
11
+ - 🚀 **Native Performance**: Compiled to native code via Rust N-API
12
+ - 🔄 **Full Feature Parity**: Matches Python SDK functionality
13
+ - 📊 **OpenTelemetry Integration**: Built-in observability
14
+ - 🔄 **Auto Policy Refresh**: Automatic policy synchronization
15
+ - 🔒 **Singleton Pattern**: Process-wide handle management
16
+ - 🛡️ **Field Redaction**: Privacy-preserving data handling
17
+ - 📘 **TypeScript Support**: Full type definitions with JSDoc documentation
18
+
19
+ ### WASM Bindings (Browser/Universal)
20
+ - 🌐 **Universal**: Works in browser and Node.js environments
21
+ - 🔒 **Deterministic**: Consistent policy evaluation across all platforms
22
+ - 📦 **Zero Dependencies**: No external runtime dependencies
23
+
24
+ ## Installation
25
+
26
+ ### N-API (Node.js)
27
+
28
+ ```bash
29
+ # Build from source
30
+ cd crates/frisk_js
31
+ napi build --no-default-features --features napi --platform
32
+
33
+ # The .node file will be created in the current directory
34
+ ```
35
+
36
+ ### WASM (Browser)
37
+
38
+ ```bash
39
+ cd crates/frisk_js
40
+ wasm-pack build --target bundler --out-dir pkg
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ ### N-API (Node.js) - JavaScript
46
+
47
+ ```javascript
48
+ const { FriskHandle, redactDictionary } = require('./frisk-js.linux-x64-gnu.node');
49
+
50
+ // Create singleton handle (automatically starts policy refresh)
51
+ const handle = new FriskHandle(
52
+ process.env.FRISK_TOKEN,
53
+ 'https://api.frisk.ai',
54
+ 'http://otel-collector:4317'
55
+ );
56
+
57
+ // Process a tool call
58
+ const result = handle.process(
59
+ 'tool_name',
60
+ JSON.stringify({ action: 'allowed' }), // tool args
61
+ JSON.stringify({ user: 'john' }), // agent state
62
+ 'call-id-123', // tool call ID
63
+ { // options
64
+ redact_tool_args: true,
65
+ redact_agent_state: ['password', 'token']
66
+ },
67
+ { // OpenTelemetry trace context
68
+ traceparent: '00-...'
69
+ }
70
+ );
71
+
72
+ console.log(result);
73
+ // { decision: 'allow', rules_matched_count: 1, reason: '...' }
74
+
75
+ // Update token if needed
76
+ handle.updateAuthToken(newToken);
77
+
78
+ // Redact sensitive data
79
+ const redacted = redactDictionary(
80
+ JSON.stringify({ secret: "value", public: "data" }),
81
+ ['secret'] // or true for all fields
82
+ );
83
+ console.log(redacted.redacted);
84
+ console.log(redacted.matched_paths);
85
+ ```
86
+
87
+ ### N-API (Node.js) - TypeScript
88
+
89
+ Full TypeScript support with comprehensive type definitions:
90
+
91
+ ```typescript
92
+ import {
93
+ FriskHandle,
94
+ redactDictionary,
95
+ ProcessToolCallResult,
96
+ ProcessToolCallOptions,
97
+ TraceContextCarrier
98
+ } from '@friskai/frisk-js';
99
+
100
+ // Create handle with full type checking
101
+ const handle = new FriskHandle(
102
+ process.env.FRISK_TOKEN!,
103
+ 'https://api.frisk.ai',
104
+ 'http://otel-collector:4317'
105
+ );
106
+
107
+ // Process with typed options
108
+ const options: ProcessToolCallOptions = {
109
+ redact_tool_args: ['password', 'api_key'],
110
+ redact_agent_state: true
111
+ };
112
+
113
+ const traceContext: TraceContextCarrier = {
114
+ traceparent: '00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01'
115
+ };
116
+
117
+ const result: ProcessToolCallResult = handle.process(
118
+ 'send_email',
119
+ JSON.stringify({ recipient: 'user@example.com' }),
120
+ JSON.stringify({ user_id: 123 }),
121
+ 'call-abc-123',
122
+ options,
123
+ traceContext
124
+ );
125
+
126
+ // TypeScript knows the exact shape of result
127
+ if (result.decision === 'allow') {
128
+ console.log(`Allowed: ${result.reason}`);
129
+ } else {
130
+ console.log(`Denied: ${result.reason}`);
131
+ }
132
+ ```
133
+
134
+ **TypeScript Features:**
135
+ - ✅ Full IntelliSense support in your IDE
136
+ - ✅ Compile-time type checking
137
+ - ✅ Comprehensive JSDoc documentation
138
+ - ✅ Type-safe APIs for all methods
139
+ - ✅ Example code in `examples/typescript/`
140
+
141
+ See [examples/typescript/README.md](./examples/typescript/README.md) for a complete TypeScript example.
142
+
143
+ ### WASM (Browser)
144
+
145
+ ```javascript
146
+ import { JsPolicyEngine } from '@frisk/policy-engine';
147
+
148
+ // Define your policies
149
+ const policies = [
150
+ {
151
+ id: "policy-1",
152
+ current_version_id: "v1",
153
+ status: "ACTIVE",
154
+ policy: {
155
+ tool_name: "send_email",
156
+ rule: {
157
+ action: "allow",
158
+ when: {
159
+ source: "args",
160
+ matches: {
161
+ key: "recipient",
162
+ op: "eq",
163
+ value: "admin@example.com"
164
+ }
165
+ }
166
+ }
167
+ }
168
+ }
169
+ ];
170
+
171
+ // Create engine instance
172
+ const engine = new JsPolicyEngine(policies);
173
+
174
+ // Evaluate a tool call
175
+ const result = engine.evaluateToolCall(
176
+ "send_email",
177
+ { recipient: "admin@example.com", subject: "Test" },
178
+ { user: "john" },
179
+ "company-123"
180
+ );
181
+
182
+ console.log(result);
183
+ // Output: { decision: "allow", rules_matched_count: 1, reason: "..." }
184
+ ```
185
+
186
+ ### TypeScript Example
187
+
188
+ ```typescript
189
+ import { JsPolicyEngine } from '@frisk/policy-engine';
190
+
191
+ interface EvaluationResult {
192
+ decision: 'allow' | 'deny';
193
+ rules_matched_count: number;
194
+ reason: string;
195
+ }
196
+
197
+ const engine = new JsPolicyEngine(policies);
198
+ const result: EvaluationResult = engine.evaluateToolCall(
199
+ "send_email",
200
+ { recipient: "user@example.com" },
201
+ {},
202
+ "company-123"
203
+ );
204
+ ```
205
+
206
+ ## API Reference
207
+
208
+ ### `JsPolicyEngine`
209
+
210
+ #### Constructor
211
+
212
+ ```typescript
213
+ new JsPolicyEngine(policies_json: object | string)
214
+ ```
215
+
216
+ Creates a new policy engine instance with the given policies.
217
+
218
+ **Parameters:**
219
+ - `policies_json`: Policy definitions as an object or JSON string
220
+
221
+ **Throws:**
222
+ - Error if policies JSON is invalid
223
+ - Error if policies cannot be deserialized
224
+
225
+ #### `evaluateToolCall`
226
+
227
+ ```typescript
228
+ evaluateToolCall(
229
+ tool_name: string,
230
+ tool_args: object,
231
+ agent_state: object,
232
+ company_id: string
233
+ ): EvaluationResult
234
+ ```
235
+
236
+ Evaluates a tool call against the loaded policies.
237
+
238
+ **Parameters:**
239
+ - `tool_name`: Name of the tool being called
240
+ - `tool_args`: Arguments passed to the tool (as JSON object or string)
241
+ - `agent_state`: Current agent state (as JSON object or string)
242
+ - `company_id`: Company identifier
243
+
244
+ **Returns:**
245
+ - `EvaluationResult` object containing:
246
+ - `decision`: "allow" or "deny"
247
+ - `rules_matched_count`: Number of rules that matched
248
+ - `reason`: Human-readable reason for the decision
249
+
250
+ **Throws:**
251
+ - Error if arguments cannot be parsed as JSON
252
+ - Error if result cannot be serialized
253
+
254
+ ## Policy Format
255
+
256
+ Policies should follow this structure:
257
+
258
+ ```json
259
+ {
260
+ "id": "unique-policy-id",
261
+ "current_version_id": "version-id",
262
+ "status": "ACTIVE",
263
+ "policy": {
264
+ "tool_name": "tool_name_to_match",
265
+ "rule": {
266
+ "action": "allow" | "deny" | "modify",
267
+ "when": {
268
+ "source": "args" | "state",
269
+ "matches": {
270
+ "key": "field_name",
271
+ "op": "eq" | "ne" | "gt" | "lt" | "gte" | "lte" | "in" | "contains" | "regex",
272
+ "value": "expected_value"
273
+ }
274
+ }
275
+ }
276
+ }
277
+ }
278
+ ```
279
+
280
+ ## Browser Support
281
+
282
+ Modern browsers with WebAssembly support:
283
+ - Chrome/Edge 57+
284
+ - Firefox 52+
285
+ - Safari 11+
286
+
287
+ ## Node.js Support
288
+
289
+ Node.js 12+ with WebAssembly support
290
+
291
+ ## Building from Source
292
+
293
+ ```bash
294
+ # Install wasm-pack
295
+ cargo install wasm-pack
296
+
297
+ # Build the package
298
+ cd crates/frisk_js
299
+ wasm-pack build --target bundler --out-dir pkg
300
+
301
+ # The generated package will be in the pkg/ directory
302
+ ```
303
+
304
+ ## Bundle Size
305
+
306
+ - Uncompressed: ~1.5 MB
307
+ - Gzipped: ~500 KB
308
+ - Brotli: ~450 KB (estimated)
309
+
310
+ ## License
311
+
312
+ See the root repository LICENSE file.
313
+
314
+ ## Contributing
315
+
316
+ Contributions are welcome! Please see the main repository for contribution guidelines.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @friskai/frisk-js Adapters
3
+ *
4
+ * Framework adapters for integrating Frisk with popular AI/LLM frameworks.
5
+ */
6
+ export { FRISK_SESSION_ID_KEY, FriskCallbackHandler, FriskLangchain, type FriskLangchainInitParams, FriskToolMiddleware, type FriskToolMiddlewareOptions, } from './langchain';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,EACd,KAAK,wBAAwB,EAC7B,mBAAmB,EACnB,KAAK,0BAA0B,GAChC,MAAM,aAAa,CAAA"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @friskai/frisk-js FriskCallbackHandler
3
+ *
4
+ * LangChain callback handler for Frisk session tracing.
5
+ * Handles chain lifecycle events to manage tracing spans.
6
+ */
7
+ import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
8
+ import type { Serialized } from '@langchain/core/load/serializable';
9
+ import type { ChainValues } from '@langchain/core/utils/types';
10
+ import type { FriskLangchain } from './frisk-langchain';
11
+ /**
12
+ * FriskCallbackHandler - LangChain callback handler for Frisk tracing
13
+ *
14
+ * This handler integrates with LangChain's callback system to automatically
15
+ * manage tracing spans for Frisk sessions. It initializes tracing when a
16
+ * root chain starts and ends tracing when the root chain completes.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { FriskLangchain } from '@friskai/frisk-js';
21
+ *
22
+ * const frisk = new FriskLangchain({ apiKey: process.env.FRISK_API_KEY });
23
+ * await frisk.init();
24
+ *
25
+ * const sessionId = frisk.createSession();
26
+ * const callbackHandler = frisk.callbackHandler(sessionId);
27
+ *
28
+ * // Use with LangChain
29
+ * const result = await agent.invoke(
30
+ * { input: 'Hello' },
31
+ * { callbacks: [callbackHandler] }
32
+ * );
33
+ * ```
34
+ */
35
+ export declare class FriskCallbackHandler extends BaseCallbackHandler {
36
+ name: string;
37
+ private _frisk;
38
+ private _sessionId;
39
+ private _friskSession;
40
+ constructor(frisk: FriskLangchain, sessionId: string);
41
+ /**
42
+ * Called at the start of a Chain run.
43
+ * Initializes tracing for root chains (those without a parent).
44
+ *
45
+ * NOTE: The official documentation and source code types state that `parentRunId` is the 8th argument to this method, but this isn't true.
46
+ * In practice, `parentRunId` is the 4th argument. This may be a documentation bug or an issue with the types, but we need to use the correct argument position to get the parent run ID.
47
+ */
48
+ handleChainStart(_chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string): void;
49
+ /**
50
+ * Called at the end of a Chain run.
51
+ * Ends tracing when the root chain completes.
52
+ */
53
+ handleChainEnd(_outputs: ChainValues, runId: string): void;
54
+ }
55
+ //# sourceMappingURL=frisk-callback-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frisk-callback-handler.d.ts","sourceRoot":"","sources":["../../../src/adapters/langchain/frisk-callback-handler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAA;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAI9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,oBAAqB,SAAQ,mBAAmB;IAC3D,IAAI,SAAyB;IAE7B,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,aAAa,CAAc;gBAEvB,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM;IAmBpD;;;;;;OAMG;IACH,gBAAgB,CACd,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM,GACnB,IAAI;IAOP;;;OAGG;IACH,cAAc,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;CAM3D"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @friskai/frisk-js LangChain Integration
3
+ *
4
+ * FriskLangchain class that extends Frisk with LangChain-specific functionality.
5
+ */
6
+ import { StateSchema } from '@langchain/langgraph';
7
+ import { Frisk } from '../../core/frisk';
8
+ import type { FriskInitParams } from '../../core/types';
9
+ import { type LangChainToolCall } from '../../framework-adapter';
10
+ import { FriskCallbackHandler } from './frisk-callback-handler';
11
+ import type { LangchainTool } from './langchain-framework-adapter/langchain-framework-adapter';
12
+ /**
13
+ * LangChain-specific Frisk init params (without frameworkAdapter since it's preset)
14
+ */
15
+ export type FriskLangchainInitParams = Omit<FriskInitParams<LangChainToolCall, LangchainTool>, 'frameworkAdapter'>;
16
+ /**
17
+ * FriskLangchain - Frisk SDK configured for LangChain integration
18
+ *
19
+ * Extends the base Frisk class with LangChain-specific functionality.
20
+ * Automatically configures the LangchainFrameworkAdapter.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * import { FriskLangchain } from '@friskai/frisk-js';
25
+ *
26
+ * const frisk = new FriskLangchain({
27
+ * apiKey: process.env.FRISK_API_KEY,
28
+ * options: {
29
+ * redactToolArgs: ['password'],
30
+ * },
31
+ * });
32
+ *
33
+ * await frisk.init();
34
+ *
35
+ * // Wrap tools with policy enforcement
36
+ * const wrappedTools = frisk.wrapTools(myTools);
37
+ *
38
+ * // Evaluate a tool call
39
+ * const result = frisk.evaluateToolCall(
40
+ * 'send_email',
41
+ * { recipient: 'user@example.com' },
42
+ * { userId: 123 }
43
+ * );
44
+ * ```
45
+ */
46
+ export declare class FriskLangchain extends Frisk<LangChainToolCall, LangchainTool> {
47
+ constructor(params?: FriskLangchainInitParams);
48
+ /**
49
+ * Create a callback handler for a session
50
+ *
51
+ * The callback handler integrates with LangChain's callback system to
52
+ * automatically manage tracing spans for the session.
53
+ *
54
+ * @param sessionId - The session ID to create a callback handler for
55
+ * @returns A FriskCallbackHandler instance
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const sessionId = frisk.createSession();
60
+ * const callbackHandler = frisk.callbackHandler(sessionId);
61
+ *
62
+ * const result = await agent.invoke(
63
+ * { input: 'Hello' },
64
+ * { callbacks: [callbackHandler] }
65
+ * );
66
+ * ```
67
+ */
68
+ callbackHandler(sessionId: string): FriskCallbackHandler;
69
+ toolMiddleware(agentStateSchema: StateSchema<any>): import("langchain").AgentMiddleware<any, any, unknown, readonly (import("@langchain/core/tools").ClientTool | import("@langchain/core/tools").ServerTool)[]>;
70
+ }
71
+ //# sourceMappingURL=frisk-langchain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frisk-langchain.d.ts","sourceRoot":"","sources":["../../../src/adapters/langchain/frisk-langchain.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAElD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EACL,KAAK,iBAAiB,EAEvB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAE/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2DAA2D,CAAA;AAE9F;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,IAAI,CACzC,eAAe,CAAC,iBAAiB,EAAE,aAAa,CAAC,EACjD,kBAAkB,CACnB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,cAAe,SAAQ,KAAK,CAAC,iBAAiB,EAAE,aAAa,CAAC;gBAC7D,MAAM,CAAC,EAAE,wBAAwB;IAO7C;;;;;;;;;;;;;;;;;;;OAmBG;IACI,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,oBAAoB;IAIxD,cAAc,CAAC,gBAAgB,EAAE,WAAW,CAAC,GAAG,CAAC;CAqBzD"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @friskai/frisk-js FriskToolMiddleware
3
+ *
4
+ * Middleware for intercepting and evaluating LangChain tool calls
5
+ * against Frisk policies before execution.
6
+ */
7
+ import { Command } from '@langchain/langgraph';
8
+ import { ToolCallHandler, ToolCallRequest, ToolMessage } from 'langchain';
9
+ import { FriskSDKLogOptions } from '../../logging';
10
+ import { FriskLangchain } from './frisk-langchain';
11
+ import { FriskContext } from './types';
12
+ /**
13
+ * Options for creating a Frisk tool middleware
14
+ */
15
+ export interface FriskToolMiddlewareOptions {
16
+ logging?: FriskSDKLogOptions;
17
+ }
18
+ /**
19
+ * FriskToolMiddleware - Middleware for LangChain tool call interception
20
+ *
21
+ * This middleware wraps LangChain tools with policy enforcement.
22
+ * When a tool is called, it first evaluates the call against Frisk policies.
23
+ * If the policy denies the call, a denial message is returned instead of
24
+ * executing the tool.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * import { FriskLangchain } from '@friskai/frisk-js';
29
+ *
30
+ * const frisk = new FriskLangchain({ apiKey: process.env.FRISK_API_KEY });
31
+ * await frisk.init();
32
+ *
33
+ * const session = frisk.createSession();
34
+ * const middleware = session.toolMiddleware();
35
+ *
36
+ * // Wrap tools with policy enforcement
37
+ * const wrappedTools = middleware.wrapTools(tools);
38
+ *
39
+ * // Use wrapped tools with LangGraph agent
40
+ * const agent = createReactAgent({
41
+ * llm,
42
+ * tools: wrappedTools,
43
+ * });
44
+ *
45
+ * // Invoke with the session ID in configurable
46
+ * await agent.invoke(
47
+ * { messages: [new HumanMessage("Hello")] },
48
+ * { configurable: { frisk_session_id: session.sessionId } }
49
+ * );
50
+ * ```
51
+ */
52
+ export declare class FriskToolMiddleware<TState extends Record<string, unknown> = Record<string, unknown>, TContext extends FriskContext = FriskContext> {
53
+ private _frisk;
54
+ private logger;
55
+ name: string;
56
+ constructor(frisk: FriskLangchain, options?: FriskToolMiddlewareOptions);
57
+ /**
58
+ * Get the Frisk instance
59
+ */
60
+ get frisk(): FriskLangchain;
61
+ wrapToolCall(request: ToolCallRequest<TState, TContext>, handler: ToolCallHandler<TState, TContext>): Promise<ToolMessage | Command>;
62
+ /**
63
+ * Get the Frisk session from the RunnableConfig
64
+ */
65
+ private getFriskSessionFromRuntime;
66
+ private blockOrExecuteToolCall;
67
+ }
68
+ //# sourceMappingURL=frisk-tool-middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frisk-tool-middleware.d.ts","sourceRoot":"","sources":["../../../src/adapters/langchain/frisk-tool-middleware.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAUzE,OAAO,EAAE,kBAAkB,EAAa,MAAM,eAAe,CAAA;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAEL,YAAY,EAEb,MAAM,SAAS,CAAA;AAEhB;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,OAAO,CAAC,EAAE,kBAAkB,CAAA;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,mBAAmB,CAC9B,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,QAAQ,SAAS,YAAY,GAAG,YAAY;IAG5C,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAW;IAElB,IAAI,SAAwB;gBACvB,KAAK,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,0BAA0B;IAOvE;;OAEG;IACH,IAAI,KAAK,IAAI,cAAc,CAE1B;IAEY,YAAY,CACvB,OAAO,EAAE,eAAe,CAAC,MAAM,EAAE,QAAQ,CAAC,EAC1C,OAAO,EAAE,eAAe,CAAC,MAAM,EAAE,QAAQ,CAAC,GACzC,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC;IAiCjC;;OAEG;IACH,OAAO,CAAC,0BAA0B;YAyBpB,sBAAsB;CAgBrC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @friskai/frisk-js LangChain Adapter
3
+ *
4
+ * Exports for LangChain integration.
5
+ */
6
+ export { FriskCallbackHandler } from './frisk-callback-handler';
7
+ export { FriskLangchain, type FriskLangchainInitParams, } from './frisk-langchain';
8
+ export { FriskToolMiddleware, type FriskToolMiddlewareOptions, } from './frisk-tool-middleware';
9
+ export { FRISK_SESSION_ID_KEY } from './types';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/langchain/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,EACL,cAAc,EACd,KAAK,wBAAwB,GAC9B,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,mBAAmB,EACnB,KAAK,0BAA0B,GAChC,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * @friskai/frisk-js LangChain Framework Adapter
3
+ *
4
+ * Framework adapter for LangChain integration.
5
+ * Handles LangChain-specific tool calls, serialization, and tool wrapping.
6
+ */
7
+ import { DynamicStructuredTool } from '@langchain/core/tools';
8
+ import { ZodObject } from 'zod/v4';
9
+ import type { FrameworkAdapter, ToolCallInfo } from '../../../framework-adapter/framework-adapter';
10
+ import type { RedactedDictionary, RedactedSerializedObject, RedactOption } from '../../../utils/redact';
11
+ /**
12
+ * LangChain ToolCall type
13
+ * Represents a tool call from LangChain messages
14
+ */
15
+ export interface LangChainToolCall {
16
+ id?: string;
17
+ name: string;
18
+ args: Record<string, unknown>;
19
+ type?: string;
20
+ }
21
+ export interface LangchainTool {
22
+ }
23
+ /**
24
+ * LangChain framework adapter
25
+ *
26
+ * Provides LangChain-specific implementation of the FrameworkAdapter interface.
27
+ * Handles ToolCall objects, message serialization, and tool wrapping.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * import { LangchainFrameworkAdapter } from '@friskai/frisk-js';
32
+ *
33
+ * const adapter = new LangchainFrameworkAdapter();
34
+ *
35
+ * // Extract tool call info from a LangChain ToolCall
36
+ * const toolCallInfo = adapter.getToolCallInfo(toolCall);
37
+ *
38
+ * // Serialize agent state with redaction
39
+ * const serialized = adapter.serializeAgentState(state, {
40
+ * redact: ['password', 'api_key'],
41
+ * });
42
+ * ```
43
+ */
44
+ export declare class LangchainFrameworkAdapter implements FrameworkAdapter<LangChainToolCall, LangchainTool> {
45
+ /**
46
+ * Serialize tool arguments to JSON with optional redaction
47
+ */
48
+ serializeToolArgs(toolArgs: Record<string, unknown> | null | undefined, options?: {
49
+ redact?: RedactOption;
50
+ }): RedactedSerializedObject;
51
+ /**
52
+ * Serialize agent state to JSON with optional redaction
53
+ *
54
+ * Automatically excludes the 'messages' key from serialization
55
+ * as it typically contains large message arrays.
56
+ */
57
+ serializeAgentState(agentState: Record<string, unknown> | null | undefined, options?: {
58
+ redact?: RedactOption;
59
+ }): RedactedSerializedObject;
60
+ /**
61
+ * Convert tool arguments to dictionary with optional redaction
62
+ */
63
+ toolArgsToDict(toolArgs: Record<string, unknown>, options?: {
64
+ redact?: RedactOption;
65
+ }): RedactedDictionary;
66
+ /**
67
+ * Convert agent state to dictionary with optional redaction
68
+ *
69
+ * Automatically combines the provided redact option with EXCLUDED_STATE_KEYS
70
+ */
71
+ agentStateToDict(agentState: Record<string, unknown>, options?: {
72
+ redact?: RedactOption;
73
+ }): RedactedDictionary;
74
+ /**
75
+ * Extract tool call information from a LangChain ToolCall
76
+ */
77
+ getToolCallInfo(toolCall: LangChainToolCall): ToolCallInfo;
78
+ /**
79
+ * Get the tool call ID or generate one if not present
80
+ */
81
+ private getOrCreateToolCallId;
82
+ /**
83
+ * Get the tool name from a ToolCall
84
+ */
85
+ private getToolName;
86
+ /**
87
+ * Extract the user query from agent state
88
+ *
89
+ * Looks for the last human message in the messages array
90
+ */
91
+ getUserQuery(agentState: Record<string, unknown>): string | null;
92
+ /**
93
+ * Wrap tools with additional functionality
94
+ *
95
+ * Note: For Frisk policy enforcement, use FriskLangChain.wrapTools() instead.
96
+ * This method provides basic tool wrapping without policy checks.
97
+ */
98
+ wrapTools(tools: Iterable<DynamicStructuredTool<ZodObject>>): DynamicStructuredTool[];
99
+ /**
100
+ * Wrap a single tool
101
+ *
102
+ * This is a passthrough by default. Override in subclasses for custom wrapping.
103
+ */
104
+ wrapTool(originalTool: DynamicStructuredTool<ZodObject>): DynamicStructuredTool;
105
+ }
106
+ //# sourceMappingURL=langchain-framework-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"langchain-framework-adapter.d.ts","sourceRoot":"","sources":["../../../../src/adapters/langchain/langchain-framework-adapter/langchain-framework-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAE7D,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAClC,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACb,MAAM,8CAA8C,CAAA;AACrD,OAAO,KAAK,EACV,kBAAkB,EAClB,wBAAwB,EACxB,YAAY,EACb,MAAM,uBAAuB,CAAA;AAO9B;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,aAAa;CAE7B;AAQD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,yBACX,YAAW,gBAAgB,CAAC,iBAAiB,EAAE,aAAa,CAAC;IAE7D;;OAEG;IACH,iBAAiB,CACf,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,EACpD,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,YAAY,CAAA;KAAE,GAClC,wBAAwB;IAY3B;;;;;OAKG;IACH,mBAAmB,CACjB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,EACtD,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,YAAY,CAAA;KAAE,GAClC,wBAAwB;IAY3B;;OAEG;IACH,cAAc,CACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,YAAY,CAAA;KAAE,GAClC,kBAAkB;IAIrB;;;;OAIG;IACH,gBAAgB,CACd,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,YAAY,CAAA;KAAE,GAClC,kBAAkB;IAQrB;;OAEG;IACH,eAAe,CAAC,QAAQ,EAAE,iBAAiB,GAAG,YAAY;IAQ1D;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAU7B;;OAEG;IACH,OAAO,CAAC,WAAW;IASnB;;;;OAIG;IACH,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI;IA6BhE;;;;;OAKG;IACH,SAAS,CACP,KAAK,EAAE,QAAQ,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC,GAChD,qBAAqB,EAAE;IAI1B;;;;OAIG;IACI,QAAQ,CACb,YAAY,EAAE,qBAAqB,CAAC,SAAS,CAAC,GAC7C,qBAAqB;CAKzB"}
@@ -0,0 +1,4 @@
1
+ import { DynamicStructuredTool } from '@langchain/core/tools';
2
+ import { ZodObject } from 'zod/v4';
3
+ export declare function wrapToolWithLlmReasoning(tool: DynamicStructuredTool<ZodObject>): any;
4
+ //# sourceMappingURL=wrapToolWithLlmReasoning.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapToolWithLlmReasoning.d.ts","sourceRoot":"","sources":["../../../../src/adapters/langchain/langchain-framework-adapter/wrapToolWithLlmReasoning.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAG7D,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAKlC,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,qBAAqB,CAAC,SAAS,CAAC,GACrC,GAAG,CAsCL"}