@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.
- package/README.md +316 -0
- package/dist/adapters/index.d.ts +7 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/langchain/frisk-callback-handler.d.ts +55 -0
- package/dist/adapters/langchain/frisk-callback-handler.d.ts.map +1 -0
- package/dist/adapters/langchain/frisk-langchain.d.ts +71 -0
- package/dist/adapters/langchain/frisk-langchain.d.ts.map +1 -0
- package/dist/adapters/langchain/frisk-tool-middleware.d.ts +68 -0
- package/dist/adapters/langchain/frisk-tool-middleware.d.ts.map +1 -0
- package/dist/adapters/langchain/index.d.ts +10 -0
- package/dist/adapters/langchain/index.d.ts.map +1 -0
- package/dist/adapters/langchain/langchain-framework-adapter/langchain-framework-adapter.d.ts +106 -0
- package/dist/adapters/langchain/langchain-framework-adapter/langchain-framework-adapter.d.ts.map +1 -0
- package/dist/adapters/langchain/langchain-framework-adapter/wrapToolWithLlmReasoning.d.ts +4 -0
- package/dist/adapters/langchain/langchain-framework-adapter/wrapToolWithLlmReasoning.d.ts.map +1 -0
- package/dist/adapters/langchain/langchain-framework-adapter.d.ts +105 -0
- package/dist/adapters/langchain/langchain-framework-adapter.d.ts.map +1 -0
- package/dist/adapters/langchain/types.d.ts +13 -0
- package/dist/adapters/langchain/types.d.ts.map +1 -0
- package/dist/adapters/langchain/wrapToolWithReasoning.d.ts +6 -0
- package/dist/adapters/langchain/wrapToolWithReasoning.d.ts.map +1 -0
- package/dist/core/frisk-options.d.ts +44 -0
- package/dist/core/frisk-options.d.ts.map +1 -0
- package/dist/core/frisk-session.d.ts +82 -0
- package/dist/core/frisk-session.d.ts.map +1 -0
- package/dist/core/frisk.d.ts +130 -0
- package/dist/core/frisk.d.ts.map +1 -0
- package/dist/core/install-graceful-shutdown.d.ts +67 -0
- package/dist/core/install-graceful-shutdown.d.ts.map +1 -0
- package/dist/core/llm-reasoning/constants.d.ts +2 -0
- package/dist/core/llm-reasoning/constants.d.ts.map +1 -0
- package/dist/core/llm-reasoning/removeLlmReasoningArg.d.ts +3 -0
- package/dist/core/llm-reasoning/removeLlmReasoningArg.d.ts.map +1 -0
- package/dist/core/session-registry.d.ts +50 -0
- package/dist/core/session-registry.d.ts.map +1 -0
- package/dist/core/token-manager.d.ts +155 -0
- package/dist/core/token-manager.d.ts.map +1 -0
- package/dist/core/tool-call-span.d.ts +89 -0
- package/dist/core/tool-call-span.d.ts.map +1 -0
- package/dist/core/types.d.ts +103 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/env/index.d.ts +26 -0
- package/dist/env/index.d.ts.map +1 -0
- package/dist/env/mocks/mockEnv.d.ts +11 -0
- package/dist/env/mocks/mockEnv.d.ts.map +1 -0
- package/dist/errors/capture-error.d.ts +3 -0
- package/dist/errors/capture-error.d.ts.map +1 -0
- package/dist/errors/index.d.ts +76 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/framework-adapter/base-framework-adapter.d.ts +68 -0
- package/dist/framework-adapter/base-framework-adapter.d.ts.map +1 -0
- package/dist/framework-adapter/framework-adapter.d.ts +105 -0
- package/dist/framework-adapter/framework-adapter.d.ts.map +1 -0
- package/dist/framework-adapter/index.d.ts +12 -0
- package/dist/framework-adapter/index.d.ts.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58377 -0
- package/dist/index.js.map +493 -0
- package/dist/logging/console-logger.d.ts +3 -0
- package/dist/logging/console-logger.d.ts.map +1 -0
- package/dist/logging/create-scoped-logger.d.ts +6 -0
- package/dist/logging/create-scoped-logger.d.ts.map +1 -0
- package/dist/logging/derive-sdk-logger.d.ts +6 -0
- package/dist/logging/derive-sdk-logger.d.ts.map +1 -0
- package/dist/logging/index.d.ts +4 -0
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/log-error.d.ts +3 -0
- package/dist/logging/log-error.d.ts.map +1 -0
- package/dist/logging/types.d.ts +14 -0
- package/dist/logging/types.d.ts.map +1 -0
- package/dist/native-bindings/index.d.ts +18 -0
- package/dist/native-bindings/index.d.ts.map +1 -0
- package/dist/telemetry/constants.d.ts +6 -0
- package/dist/telemetry/constants.d.ts.map +1 -0
- package/dist/telemetry/dynamic-auth-metadata.d.ts +50 -0
- package/dist/telemetry/dynamic-auth-metadata.d.ts.map +1 -0
- package/dist/telemetry/get-otel-sdk.d.ts +18 -0
- package/dist/telemetry/get-otel-sdk.d.ts.map +1 -0
- package/dist/telemetry/get-tracer.d.ts +15 -0
- package/dist/telemetry/get-tracer.d.ts.map +1 -0
- package/dist/telemetry/index.d.ts +7 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/mocks/index.d.ts +6 -0
- package/dist/telemetry/mocks/index.d.ts.map +1 -0
- package/dist/telemetry/mocks/mockTracer.d.ts +38 -0
- package/dist/telemetry/mocks/mockTracer.d.ts.map +1 -0
- package/dist/telemetry/mocks/mockTracerHandle.d.ts +56 -0
- package/dist/telemetry/mocks/mockTracerHandle.d.ts.map +1 -0
- package/dist/telemetry/tracer-handle.d.ts +18 -0
- package/dist/telemetry/tracer-handle.d.ts.map +1 -0
- package/dist/utils/redact.d.ts +57 -0
- package/dist/utils/redact.d.ts.map +1 -0
- package/native/.gitnore.bak +1 -0
- package/native/README.md +55 -0
- package/native/frisk-js.darwin-arm64.node +0 -0
- package/native/index.cjs +580 -0
- package/native/index.d.ts +69 -0
- package/package.json +99 -0
|
@@ -0,0 +1,105 @@
|
|
|
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 type { FrameworkAdapter, ToolCallInfo } from '../../framework-adapter/framework-adapter';
|
|
9
|
+
import type { RedactedDictionary, RedactedSerializedObject, RedactOption } from '../../utils/redact';
|
|
10
|
+
/**
|
|
11
|
+
* LangChain ToolCall type
|
|
12
|
+
* Represents a tool call from LangChain messages
|
|
13
|
+
*/
|
|
14
|
+
export interface LangChainToolCall {
|
|
15
|
+
id?: string;
|
|
16
|
+
name: string;
|
|
17
|
+
args: Record<string, unknown>;
|
|
18
|
+
type?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface LangchainTool {
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* LangChain framework adapter
|
|
24
|
+
*
|
|
25
|
+
* Provides LangChain-specific implementation of the FrameworkAdapter interface.
|
|
26
|
+
* Handles ToolCall objects, message serialization, and tool wrapping.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { LangchainFrameworkAdapter } from '@friskai/frisk-js';
|
|
31
|
+
*
|
|
32
|
+
* const adapter = new LangchainFrameworkAdapter();
|
|
33
|
+
*
|
|
34
|
+
* // Extract tool call info from a LangChain ToolCall
|
|
35
|
+
* const toolCallInfo = adapter.getToolCallInfo(toolCall);
|
|
36
|
+
*
|
|
37
|
+
* // Serialize agent state with redaction
|
|
38
|
+
* const serialized = adapter.serializeAgentState(state, {
|
|
39
|
+
* redact: ['password', 'api_key'],
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare class LangchainFrameworkAdapter implements FrameworkAdapter<LangChainToolCall, LangchainTool> {
|
|
44
|
+
/**
|
|
45
|
+
* Serialize tool arguments to JSON with optional redaction
|
|
46
|
+
*/
|
|
47
|
+
serializeToolArgs(toolArgs: Record<string, unknown> | null | undefined, options?: {
|
|
48
|
+
redact?: RedactOption;
|
|
49
|
+
}): RedactedSerializedObject;
|
|
50
|
+
/**
|
|
51
|
+
* Serialize agent state to JSON with optional redaction
|
|
52
|
+
*
|
|
53
|
+
* Automatically excludes the 'messages' key from serialization
|
|
54
|
+
* as it typically contains large message arrays.
|
|
55
|
+
*/
|
|
56
|
+
serializeAgentState(agentState: Record<string, unknown> | null | undefined, options?: {
|
|
57
|
+
redact?: RedactOption;
|
|
58
|
+
}): RedactedSerializedObject;
|
|
59
|
+
/**
|
|
60
|
+
* Convert tool arguments to dictionary with optional redaction
|
|
61
|
+
*/
|
|
62
|
+
toolArgsToDict(toolArgs: Record<string, unknown>, options?: {
|
|
63
|
+
redact?: RedactOption;
|
|
64
|
+
}): RedactedDictionary;
|
|
65
|
+
/**
|
|
66
|
+
* Convert agent state to dictionary with optional redaction
|
|
67
|
+
*
|
|
68
|
+
* Automatically combines the provided redact option with EXCLUDED_STATE_KEYS
|
|
69
|
+
*/
|
|
70
|
+
agentStateToDict(agentState: Record<string, unknown>, options?: {
|
|
71
|
+
redact?: RedactOption;
|
|
72
|
+
}): RedactedDictionary;
|
|
73
|
+
/**
|
|
74
|
+
* Extract tool call information from a LangChain ToolCall
|
|
75
|
+
*/
|
|
76
|
+
getToolCallInfo(toolCall: LangChainToolCall): ToolCallInfo;
|
|
77
|
+
/**
|
|
78
|
+
* Get the tool call ID or generate one if not present
|
|
79
|
+
*/
|
|
80
|
+
private getOrCreateToolCallId;
|
|
81
|
+
/**
|
|
82
|
+
* Get the tool name from a ToolCall
|
|
83
|
+
*/
|
|
84
|
+
private getToolName;
|
|
85
|
+
/**
|
|
86
|
+
* Extract the user query from agent state
|
|
87
|
+
*
|
|
88
|
+
* Looks for the last human message in the messages array
|
|
89
|
+
*/
|
|
90
|
+
getUserQuery(agentState: Record<string, unknown>): string | null;
|
|
91
|
+
/**
|
|
92
|
+
* Wrap tools with additional functionality
|
|
93
|
+
*
|
|
94
|
+
* Note: For Frisk policy enforcement, use FriskLangChain.wrapTools() instead.
|
|
95
|
+
* This method provides basic tool wrapping without policy checks.
|
|
96
|
+
*/
|
|
97
|
+
wrapTools(tools: Iterable<DynamicStructuredTool>): DynamicStructuredTool[];
|
|
98
|
+
/**
|
|
99
|
+
* Wrap a single tool
|
|
100
|
+
*
|
|
101
|
+
* This is a passthrough by default. Override in subclasses for custom wrapping.
|
|
102
|
+
*/
|
|
103
|
+
private wrapTool;
|
|
104
|
+
}
|
|
105
|
+
//# 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.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAE7D,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACb,MAAM,2CAA2C,CAAA;AAClD,OAAO,KAAK,EACV,kBAAkB,EAClB,wBAAwB,EACxB,YAAY,EACb,MAAM,oBAAoB,CAAA;AAO3B;;;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,CAAC,KAAK,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GAAG,qBAAqB,EAAE;IAI1E;;;;OAIG;IACH,OAAO,CAAC,QAAQ;CAMjB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Context key for the Frisk session ID in LangGraph runtime context
|
|
4
|
+
*/
|
|
5
|
+
export declare const FRISK_SESSION_ID_KEY = "frisk_session_id";
|
|
6
|
+
export type FriskContext = {
|
|
7
|
+
frisk_session_id: string | undefined;
|
|
8
|
+
};
|
|
9
|
+
export declare const RUNTIME_CONTEXT_KEY = "context";
|
|
10
|
+
export declare const FriskContextSchema: z.ZodObject<{
|
|
11
|
+
frisk_session_id: z.ZodOptional<z.ZodString>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapters/langchain/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;GAEG;AACH,eAAO,MAAM,oBAAoB,qBAAqB,CAAA;AACtD,MAAM,MAAM,YAAY,GAAG;IAAE,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAA;AAGnE,eAAO,MAAM,mBAAmB,YAAY,CAAA;AAE5C,eAAO,MAAM,kBAAkB;;iBAE7B,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
2
|
+
import { ZodObject } from 'zod/v4';
|
|
3
|
+
export declare const LLM_REASONING_ARG_NAME = "llmReasoning";
|
|
4
|
+
export declare function removeLlmReasoningArg<T extends object>(input: T): Omit<T, typeof LLM_REASONING_ARG_NAME>;
|
|
5
|
+
export declare function wrapToolWithReasoning(tool: DynamicStructuredTool<ZodObject>): any;
|
|
6
|
+
//# sourceMappingURL=wrapToolWithReasoning.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrapToolWithReasoning.d.ts","sourceRoot":"","sources":["../../../src/adapters/langchain/wrapToolWithReasoning.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,qBAAqB,EAItB,MAAM,uBAAuB,CAAA;AAO9B,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAQlC,eAAO,MAAM,sBAAsB,iBAAiB,CAAA;AAEpD,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,MAAM,EACpD,KAAK,EAAE,CAAC,GACP,IAAI,CAAC,CAAC,EAAE,OAAO,sBAAsB,CAAC,CASxC;AAED,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,qBAAqB,CAAC,SAAS,CAAC,GACrC,GAAG,CAuDL"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @friskai/frisk-js Options Utilities
|
|
3
|
+
*
|
|
4
|
+
* Helpers for normalizing and validating Frisk options.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Options for initializing the Frisk SDK
|
|
8
|
+
*/
|
|
9
|
+
export interface FriskOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Redaction configuration for tool arguments.
|
|
12
|
+
* - `true`: Redact all fields in tool arguments
|
|
13
|
+
* - `false`: Do not redact any fields
|
|
14
|
+
* - `string[]`: Array of field names to selectively redact
|
|
15
|
+
*/
|
|
16
|
+
redactToolArgs?: boolean | string[];
|
|
17
|
+
/**
|
|
18
|
+
* Redaction configuration for agent state.
|
|
19
|
+
* - `true`: Redact all fields in agent state
|
|
20
|
+
* - `false`: Do not redact any fields
|
|
21
|
+
* - `string[]`: Array of field names to selectively redact
|
|
22
|
+
*/
|
|
23
|
+
redactAgentState?: boolean | string[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Normalized Frisk options with defaults applied
|
|
27
|
+
*/
|
|
28
|
+
export interface NormalizedFriskOptions {
|
|
29
|
+
redactToolArgs: boolean | string[];
|
|
30
|
+
redactAgentState: boolean | string[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Normalize Frisk options with defaults
|
|
34
|
+
*/
|
|
35
|
+
export declare function normalizeFriskOptions(options?: FriskOptions): NormalizedFriskOptions;
|
|
36
|
+
/**
|
|
37
|
+
* Convert SDK options to core (Rust binding) format
|
|
38
|
+
* Note: The auto-generated types now use camelCase
|
|
39
|
+
*/
|
|
40
|
+
export declare function toCoreFriskOptions(options: NormalizedFriskOptions): {
|
|
41
|
+
redactToolArgs?: boolean | string[];
|
|
42
|
+
redactAgentState?: boolean | string[];
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=frisk-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frisk-options.d.ts","sourceRoot":"","sources":["../../src/core/frisk-options.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;IAEnC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,cAAc,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;IAClC,gBAAgB,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;CACrC;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,CAAC,EAAE,YAAY,GACrB,sBAAsB,CAKxB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,sBAAsB,GAAG;IACnE,cAAc,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;IACnC,gBAAgB,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;CACtC,CAKA"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @friskai/frisk-js Session
|
|
3
|
+
*
|
|
4
|
+
* FriskSession represents a single session for tracking tool calls and tracing.
|
|
5
|
+
*/
|
|
6
|
+
import type { Span, Tracer } from '@opentelemetry/api';
|
|
7
|
+
import { FriskSDKLogOptions } from '../logging';
|
|
8
|
+
import type { Frisk } from './frisk';
|
|
9
|
+
import { type NormalizedFriskOptions } from './frisk-options';
|
|
10
|
+
import { ProcessToolCallResult, ToolCallInfo } from './types';
|
|
11
|
+
interface FriskSessionInitParams {
|
|
12
|
+
frisk: Frisk;
|
|
13
|
+
sessionId: string;
|
|
14
|
+
options: NormalizedFriskOptions;
|
|
15
|
+
tracer: Tracer;
|
|
16
|
+
logging?: FriskSDKLogOptions;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A Frisk session for tracking a sequence of tool calls
|
|
20
|
+
*
|
|
21
|
+
* Sessions provide:
|
|
22
|
+
* - Tool call evaluation against policies
|
|
23
|
+
* - Tracing context for distributed tracing
|
|
24
|
+
* - State management for the session lifecycle
|
|
25
|
+
*/
|
|
26
|
+
export declare class FriskSession {
|
|
27
|
+
private _frisk;
|
|
28
|
+
private _sessionId;
|
|
29
|
+
private _options;
|
|
30
|
+
private _tracer;
|
|
31
|
+
private _rootSpan;
|
|
32
|
+
private _rootRunId;
|
|
33
|
+
private _isTracing;
|
|
34
|
+
private logger;
|
|
35
|
+
constructor({ frisk, sessionId, options, tracer, logging, }: FriskSessionInitParams);
|
|
36
|
+
/**
|
|
37
|
+
* Get the session ID
|
|
38
|
+
*/
|
|
39
|
+
get sessionId(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Get the root run ID for tracing
|
|
42
|
+
*/
|
|
43
|
+
get rootRunId(): string | null;
|
|
44
|
+
/**
|
|
45
|
+
* Check if tracing is active
|
|
46
|
+
*/
|
|
47
|
+
get isTracing(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Get the Frisk instance
|
|
50
|
+
*/
|
|
51
|
+
get frisk(): Frisk;
|
|
52
|
+
/**
|
|
53
|
+
* Get the OpenTelemetry tracer
|
|
54
|
+
*/
|
|
55
|
+
get tracer(): Tracer;
|
|
56
|
+
/**
|
|
57
|
+
* Get the root span for the session
|
|
58
|
+
*/
|
|
59
|
+
get rootSpan(): Span | null;
|
|
60
|
+
/**
|
|
61
|
+
* Set the root span for the session
|
|
62
|
+
*/
|
|
63
|
+
setRootSpan(span: Span): void;
|
|
64
|
+
/**
|
|
65
|
+
* Initialize tracing for this session
|
|
66
|
+
*/
|
|
67
|
+
initTracing(runId: string, inputs: Record<string, unknown>): Span;
|
|
68
|
+
/**
|
|
69
|
+
* End tracing for this session
|
|
70
|
+
*/
|
|
71
|
+
endTracing(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Evaluate a tool call against policies
|
|
74
|
+
*
|
|
75
|
+
* This method wraps the tool call evaluation in an OpenTelemetry span,
|
|
76
|
+
* handling redaction of sensitive data, latency recording, and trace
|
|
77
|
+
* context propagation.
|
|
78
|
+
*/
|
|
79
|
+
evaluateToolCall(toolCallInfo: ToolCallInfo, agentState: Record<string, unknown>): ProcessToolCallResult;
|
|
80
|
+
}
|
|
81
|
+
export {};
|
|
82
|
+
//# sourceMappingURL=frisk-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frisk-session.d.ts","sourceRoot":"","sources":["../../src/core/frisk-session.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAGtD,OAAO,EAAE,kBAAkB,EAAa,MAAM,YAAY,CAAA;AAM1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AAK7D,OAAO,EAEL,qBAAqB,EACrB,YAAY,EACb,MAAM,SAAS,CAAA;AAEhB,UAAU,sBAAsB;IAC9B,KAAK,EAAE,KAAK,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,sBAAsB,CAAA;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,kBAAkB,CAAA;CAC7B;AAED;;;;;;;GAOG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAO;IACrB,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,QAAQ,CAAwB;IACxC,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,UAAU,CAAiB;IACnC,OAAO,CAAC,MAAM,CAAW;gBAEb,EACV,KAAK,EACL,SAAS,EACT,OAAO,EACP,MAAM,EACN,OAAO,GACR,EAAE,sBAAsB;IAUzB;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,GAAG,IAAI,CAE7B;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,KAAK,CAEjB;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,IAAI,GAAG,IAAI,CAE1B;IAED;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAI7B;;OAEG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAgBjE;;OAEG;IACH,UAAU,IAAI,IAAI;IAWlB;;;;;;OAMG;IACH,gBAAgB,CACd,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,qBAAqB;CAuDzB"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @friskai/frisk-js Frisk SDK
|
|
3
|
+
*
|
|
4
|
+
* Main entry point for the Frisk SDK. Provides a high-level API for
|
|
5
|
+
* policy evaluation, session management, and tool wrapping.
|
|
6
|
+
*/
|
|
7
|
+
import { FrameworkAdapter } from '../framework-adapter';
|
|
8
|
+
import { LogLevel, SDKLogger } from '../logging';
|
|
9
|
+
import { type FriskHandleInstance } from '../native-bindings';
|
|
10
|
+
import { TracerHandle } from '../telemetry/tracer-handle';
|
|
11
|
+
import { FriskSession } from './frisk-session';
|
|
12
|
+
import type { FriskInitParams, ProcessToolCallResult, RedactionResult, ToolCallInfo, TraceContextCarrier } from './types';
|
|
13
|
+
/**
|
|
14
|
+
* Main Frisk SDK class
|
|
15
|
+
*
|
|
16
|
+
* Provides a high-level API for:
|
|
17
|
+
* - Policy evaluation for tool calls
|
|
18
|
+
* - Session management for tracking conversations
|
|
19
|
+
* - Redaction of sensitive data
|
|
20
|
+
* - Integration with LangChain and other frameworks
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { Frisk } from '@friskai/frisk-js';
|
|
25
|
+
*
|
|
26
|
+
* const frisk = new Frisk({
|
|
27
|
+
* apiKey: process.env.FRISK_API_KEY,
|
|
28
|
+
* baseUrl: 'https://api.frisk.ai',
|
|
29
|
+
* options: {
|
|
30
|
+
* redactToolArgs: ['password', 'api_key'],
|
|
31
|
+
* redactAgentState: true,
|
|
32
|
+
* },
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* // Create a session for tracking
|
|
36
|
+
* const sessionId = frisk.createSession();
|
|
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
|
+
* if (result.decision === ProcessToolCallDecision.ALLOW) {
|
|
46
|
+
* // Execute the tool
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare class Frisk<ToolCallT = unknown, ToolT = unknown> {
|
|
51
|
+
private options;
|
|
52
|
+
private baseUrl;
|
|
53
|
+
private telemetryEndpoint;
|
|
54
|
+
private tokenManager;
|
|
55
|
+
private initialized;
|
|
56
|
+
protected rootLogger: SDKLogger;
|
|
57
|
+
protected logger: SDKLogger;
|
|
58
|
+
protected logLevel?: LogLevel;
|
|
59
|
+
get frameworkAdapter(): FrameworkAdapter;
|
|
60
|
+
private _frameworkAdapter;
|
|
61
|
+
/**
|
|
62
|
+
* Get the native handle (for internal use)
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
get friskHandle(): FriskHandleInstance;
|
|
66
|
+
private _friskHandle;
|
|
67
|
+
/**
|
|
68
|
+
* Get the OpenTelemetry tracer handle
|
|
69
|
+
*/
|
|
70
|
+
get tracerHandle(): TracerHandle;
|
|
71
|
+
private _tracerHandle;
|
|
72
|
+
constructor(params?: FriskInitParams<ToolCallT, ToolT>);
|
|
73
|
+
init(): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Extract tool call information using the framework adapter
|
|
76
|
+
*/
|
|
77
|
+
getToolCallInfo(toolCall: ToolCallT): ToolCallInfo;
|
|
78
|
+
/**
|
|
79
|
+
* Wrap tools with LLM reasoning using the framework adapter
|
|
80
|
+
*/
|
|
81
|
+
wrapTools(tools: Iterable<ToolT>): ToolT[];
|
|
82
|
+
/**
|
|
83
|
+
* Wrap a single tool with LLM reasoning using the framework adapter
|
|
84
|
+
*/
|
|
85
|
+
wrapTool(tool: ToolT): ToolT;
|
|
86
|
+
/**
|
|
87
|
+
* Create a new session for tracking tool calls
|
|
88
|
+
*
|
|
89
|
+
* @returns The session ID
|
|
90
|
+
*/
|
|
91
|
+
createSession(): string;
|
|
92
|
+
/**
|
|
93
|
+
* Get a session by ID
|
|
94
|
+
*/
|
|
95
|
+
getSession(sessionId: string): FriskSession;
|
|
96
|
+
/**
|
|
97
|
+
* Update the authentication token
|
|
98
|
+
*
|
|
99
|
+
* This is used for token refresh when the current token expires.
|
|
100
|
+
*/
|
|
101
|
+
updateAuthToken(authToken: string): void;
|
|
102
|
+
/**
|
|
103
|
+
* Evaluate a tool call against policies
|
|
104
|
+
*
|
|
105
|
+
* @param toolName - Name of the tool being called
|
|
106
|
+
* @param toolArgs - Arguments passed to the tool
|
|
107
|
+
* @param agentState - Current state of the agent
|
|
108
|
+
* @param toolCallId - Optional unique identifier for the tool call
|
|
109
|
+
* @param traceContextCarrier - Optional trace context for distributed tracing
|
|
110
|
+
* @returns The policy evaluation result
|
|
111
|
+
*/
|
|
112
|
+
evaluateToolCall(toolName: string, toolArgs: Record<string, unknown> | null, agentState: Record<string, unknown> | null, toolCallId?: string, traceContextCarrier?: TraceContextCarrier): ProcessToolCallResult;
|
|
113
|
+
/**
|
|
114
|
+
* Redact sensitive fields from data
|
|
115
|
+
*
|
|
116
|
+
* @param data - Object or JSON string to redact
|
|
117
|
+
* @param redactOption - Redaction configuration
|
|
118
|
+
* @returns The redaction result
|
|
119
|
+
*/
|
|
120
|
+
redact(data: Record<string, unknown> | string, redactOption: boolean | string[]): RedactionResult;
|
|
121
|
+
/**
|
|
122
|
+
* Shutdown the Frisk SDK and flush telemetry
|
|
123
|
+
*
|
|
124
|
+
* This method flushes all pending spans to the telemetry backend
|
|
125
|
+
* before shutting down. Always call this before your process exits
|
|
126
|
+
* to ensure all telemetry data is exported.
|
|
127
|
+
*/
|
|
128
|
+
shutdown(): Promise<void>;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=frisk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frisk.d.ts","sourceRoot":"","sources":["../../src/core/frisk.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAiBH,OAAO,EAAwB,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEhD,OAAO,EAEL,KAAK,mBAAmB,EAEzB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAMzD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAI9C,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,mBAAmB,EACpB,MAAM,SAAS,CAAA;AAGhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,KAAK,CAAC,SAAS,GAAG,OAAO,EAAE,KAAK,GAAG,OAAO;IACrD,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,iBAAiB,CAAQ;IACjC,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,WAAW,CAAiB;IACpC,SAAS,CAAC,UAAU,EAAE,SAAS,CAAA;IAC/B,SAAS,CAAC,MAAM,EAAE,SAAS,CAAA;IAC3B,SAAS,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAA;IAE7B,IAAW,gBAAgB,IAAI,gBAAgB,CAE9C;IACD,OAAO,CAAC,iBAAiB,CAAoC;IAE7D;;;OAGG;IACH,IAAI,WAAW,IAAI,mBAAmB,CAKrC;IACD,OAAO,CAAC,YAAY,CAAmC;IAEvD;;OAEG;IACH,IAAI,YAAY,IAAI,YAAY,CAK/B;IACD,OAAO,CAAC,aAAa,CAA4B;gBAErC,MAAM,CAAC,EAAE,eAAe,CAAC,SAAS,EAAE,KAAK,CAAC;IA4DzC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAyBlC;;OAEG;IACH,eAAe,CAAC,QAAQ,EAAE,SAAS,GAAG,YAAY;IAIlD;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,KAAK,EAAE;IAO1C;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG,KAAK;IAO5B;;;;OAIG;IACH,aAAa,IAAI,MAAM;IAoBvB;;OAEG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY;IAK3C;;;;OAIG;IACH,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAKxC;;;;;;;;;OASG;IACH,gBAAgB,CACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EACxC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EAC1C,UAAU,CAAC,EAAE,MAAM,EACnB,mBAAmB,CAAC,EAAE,mBAAmB,GACxC,qBAAqB;IA6BxB;;;;;;OAMG;IACH,MAAM,CACJ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EACtC,YAAY,EAAE,OAAO,GAAG,MAAM,EAAE,GAC/B,eAAe;IAUlB;;;;;;OAMG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAShC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export type ShutdownReason = {
|
|
2
|
+
kind: 'signal';
|
|
3
|
+
signal: NodeJS.Signals;
|
|
4
|
+
} | {
|
|
5
|
+
kind: 'beforeExit';
|
|
6
|
+
code: number;
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'manual';
|
|
9
|
+
};
|
|
10
|
+
export type InstallGracefulShutdownOptions = {
|
|
11
|
+
/**
|
|
12
|
+
* Signals you consider "graceful shutdown" triggers.
|
|
13
|
+
* In servers, SIGTERM is the big one (k8s/docker/systemd).
|
|
14
|
+
*/
|
|
15
|
+
signals?: readonly NodeJS.Signals[];
|
|
16
|
+
/**
|
|
17
|
+
* If true, hook process.beforeExit to catch "normal" program completion.
|
|
18
|
+
* For long-running servers, this is usually false.
|
|
19
|
+
*
|
|
20
|
+
* NOTE: beforeExit can fire multiple times if you schedule work in it.
|
|
21
|
+
* This helper is idempotent to prevent loops.
|
|
22
|
+
*/
|
|
23
|
+
hookBeforeExit?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* If provided, start a timer once shutdown begins. When reached:
|
|
26
|
+
* - sets process.exitCode to non-zero (cooperative)
|
|
27
|
+
* - optionally force exits (NOT recommended for SDKs)
|
|
28
|
+
*/
|
|
29
|
+
hardTimeoutMs?: number;
|
|
30
|
+
/**
|
|
31
|
+
* If true, when hard timeout is reached, call process.exit(1).
|
|
32
|
+
* Default false (SDK-friendly; avoids cutting off other libraries).
|
|
33
|
+
*/
|
|
34
|
+
forceExitOnHardTimeout?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Exit code to use if hard timeout is reached.
|
|
37
|
+
* Default 1.
|
|
38
|
+
*/
|
|
39
|
+
hardTimeoutExitCode?: number;
|
|
40
|
+
/**
|
|
41
|
+
* If true (default), once shutdown completes due to a signal,
|
|
42
|
+
* we re-send the signal to ourselves (after removing our listener)
|
|
43
|
+
* so the process exits with conventional semantics.
|
|
44
|
+
*
|
|
45
|
+
* If your host app manages exit itself, you can set this to false.
|
|
46
|
+
*/
|
|
47
|
+
reRaiseSignalAfterShutdown?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* If true (default), if another signal arrives while shutdown is already running,
|
|
50
|
+
* immediately re-raise that signal to exit ASAP (common "second Ctrl+C kills now").
|
|
51
|
+
*/
|
|
52
|
+
fastExitOnSecondSignal?: boolean;
|
|
53
|
+
};
|
|
54
|
+
export type GracefulShutdownHandle = {
|
|
55
|
+
/** Manually trigger shutdown (useful in tests or explicit server stop flows). */
|
|
56
|
+
shutdown: (reason?: ShutdownReason) => Promise<void>;
|
|
57
|
+
/** Remove installed listeners (useful if your library can be started/stopped). */
|
|
58
|
+
uninstall: () => void;
|
|
59
|
+
/** Returns the in-flight shutdown promise if running, else null. */
|
|
60
|
+
getShutdownPromise: () => Promise<void> | null;
|
|
61
|
+
};
|
|
62
|
+
export declare const ShutdownOptionDefaults: {
|
|
63
|
+
Server: InstallGracefulShutdownOptions;
|
|
64
|
+
Script: InstallGracefulShutdownOptions;
|
|
65
|
+
};
|
|
66
|
+
export declare function installGracefulShutdown(shutdownFn: (reason: ShutdownReason) => Promise<void>, opts?: InstallGracefulShutdownOptions): GracefulShutdownHandle;
|
|
67
|
+
//# sourceMappingURL=install-graceful-shutdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install-graceful-shutdown.d.ts","sourceRoot":"","sources":["../../src/core/install-graceful-shutdown.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAA;AAEtB,MAAM,MAAM,8BAA8B,GAAG;IAC3C;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,MAAM,CAAC,OAAO,EAAE,CAAA;IAEnC;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IAExB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;IAEtB;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAEhC;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAE5B;;;;;;OAMG;IACH,0BAA0B,CAAC,EAAE,OAAO,CAAA;IAEpC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,iFAAiF;IACjF,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACpD,kFAAkF;IAClF,SAAS,EAAE,MAAM,IAAI,CAAA;IACrB,oEAAoE;IACpE,kBAAkB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;CAC/C,CAAA;AAED,eAAO,MAAM,sBAAsB;YAS5B,8BAA8B;YAS9B,8BAA8B;CACpC,CAAA;AAED,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,EACrD,IAAI,GAAE,8BAA8D,GACnE,sBAAsB,CAsIxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/core/llm-reasoning/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,iBAAiB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeLlmReasoningArg.d.ts","sourceRoot":"","sources":["../../../src/core/llm-reasoning/removeLlmReasoningArg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEpD,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,MAAM,EACpD,KAAK,EAAE,CAAC,GACP,IAAI,CAAC,CAAC,EAAE,OAAO,sBAAsB,CAAC,CAQxC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @friskai/frisk-js Session Registry
|
|
3
|
+
*
|
|
4
|
+
* Global registry for tracking Frisk sessions.
|
|
5
|
+
*/
|
|
6
|
+
import type { FriskSession } from './frisk-session';
|
|
7
|
+
/**
|
|
8
|
+
* Global registry for Frisk sessions
|
|
9
|
+
*
|
|
10
|
+
* This singleton registry maintains a mapping of session IDs to FriskSession instances.
|
|
11
|
+
* It allows callbacks and middleware to retrieve session context without direct references.
|
|
12
|
+
*/
|
|
13
|
+
export declare class SessionRegistry {
|
|
14
|
+
private static instance;
|
|
15
|
+
private sessions;
|
|
16
|
+
/**
|
|
17
|
+
* Get the singleton SessionRegistry instance
|
|
18
|
+
*/
|
|
19
|
+
static getInstance(): SessionRegistry;
|
|
20
|
+
/**
|
|
21
|
+
* Private constructor to enforce singleton pattern
|
|
22
|
+
*/
|
|
23
|
+
private constructor();
|
|
24
|
+
/**
|
|
25
|
+
* Register a session in the registry
|
|
26
|
+
*/
|
|
27
|
+
register(sessionId: string, session: FriskSession): void;
|
|
28
|
+
/**
|
|
29
|
+
* Get a session by ID
|
|
30
|
+
* @throws {SessionNotFoundError} if session is not found
|
|
31
|
+
*/
|
|
32
|
+
get(sessionId: string): FriskSession;
|
|
33
|
+
/**
|
|
34
|
+
* Check if a session exists
|
|
35
|
+
*/
|
|
36
|
+
has(sessionId: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Remove a session from the registry
|
|
39
|
+
*/
|
|
40
|
+
unregister(sessionId: string): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Clear all sessions (useful for testing)
|
|
43
|
+
*/
|
|
44
|
+
clear(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Get the number of registered sessions
|
|
47
|
+
*/
|
|
48
|
+
get size(): number;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=session-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-registry.d.ts","sourceRoot":"","sources":["../../src/core/session-registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAEnD;;;;;GAKG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA+B;IACtD,OAAO,CAAC,QAAQ,CAAuC;IAEvD;;OAEG;IACH,MAAM,CAAC,WAAW,IAAI,eAAe;IAOrC;;OAEG;IACH,OAAO;IAEP;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAIxD;;;OAGG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY;IAQpC;;OAEG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAI/B;;OAEG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAItC;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
|