@friskai/frisk-js 0.3.0 → 0.3.2
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/dist/adapters/langchain/frisk-callback-handler.d.ts +80 -3
- package/dist/adapters/langchain/frisk-callback-handler.d.ts.map +1 -1
- package/dist/adapters/langchain/index.js +564 -238
- package/dist/adapters/langchain/index.js.map +1 -453
- package/dist/core/frisk-session.d.ts +43 -10
- package/dist/core/frisk-session.d.ts.map +1 -1
- package/dist/core/llm-reasoning/extractLlmReasoning.d.ts +8 -0
- package/dist/core/llm-reasoning/extractLlmReasoning.d.ts.map +1 -0
- package/dist/core/spans/frisk-span.d.ts +38 -0
- package/dist/core/spans/frisk-span.d.ts.map +1 -0
- package/dist/core/spans/index.d.ts +7 -0
- package/dist/core/spans/index.d.ts.map +1 -0
- package/dist/core/spans/llm-call-span.d.ts +23 -0
- package/dist/core/spans/llm-call-span.d.ts.map +1 -0
- package/dist/core/spans/operation-span.d.ts +13 -0
- package/dist/core/spans/operation-span.d.ts.map +1 -0
- package/dist/core/spans/session-span.d.ts +20 -0
- package/dist/core/spans/session-span.d.ts.map +1 -0
- package/dist/core/spans/tool-call-decision-span.d.ts +27 -0
- package/dist/core/spans/tool-call-decision-span.d.ts.map +1 -0
- package/dist/core/spans/tool-call-observation-span.d.ts +28 -0
- package/dist/core/spans/tool-call-observation-span.d.ts.map +1 -0
- package/dist/generated/sdk-meta.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +318 -171
- package/dist/index.js.map +1 -439
- package/dist/telemetry/constants.d.ts +24 -0
- package/dist/telemetry/constants.d.ts.map +1 -1
- package/package.json +2 -1
- package/dist/core/tool-call-span.d.ts +0 -102
- package/dist/core/tool-call-span.d.ts.map +0 -1
|
@@ -5,8 +5,32 @@ export declare const TRACER_VERSION = "0.1.0";
|
|
|
5
5
|
/** Span name used for policy evaluation around a single tool call. */
|
|
6
6
|
export declare const SPAN_NAME_DECIDE_TOOL_CALL = "frisk.tool_call.decide";
|
|
7
7
|
export declare const SPAN_NAME_OBSERVE_TOOL_CALL = "frisk.tool_call.observation";
|
|
8
|
+
/** Span name used for a single LLM invocation within a session. */
|
|
9
|
+
export declare const SPAN_NAME_LLM_CALL = "frisk.llm_call";
|
|
10
|
+
/** Span name used for a single operation (e.g. a LangChain run) within a session. */
|
|
11
|
+
export declare const SPAN_NAME_OPERATION = "frisk.operation";
|
|
8
12
|
/** Span name used for the parent Frisk session lifecycle span. */
|
|
9
13
|
export declare const SPAN_NAME_FRISK_SESSION = "frisk.session";
|
|
14
|
+
/** Tool-call span attribute linking back to the LLM call that announced it. */
|
|
15
|
+
export declare const ATTRIBUTE_NAME_LLM_CALL_SPAN_ID = "frisk.tool_call.llm_call_span_id";
|
|
16
|
+
/** LLM call span attribute holding the single prompt string. */
|
|
17
|
+
export declare const ATTRIBUTE_NAME_LLM_CALL_PROMPT = "frisk.llm_call.prompt";
|
|
18
|
+
/** LLM call span attribute holding the JSON-stringified prompt messages. */
|
|
19
|
+
export declare const ATTRIBUTE_NAME_LLM_CALL_PROMPTS_JSON = "frisk.llm_call.prompts.json";
|
|
20
|
+
/** LLM call span attribute holding the JSON-stringified responses. */
|
|
21
|
+
export declare const ATTRIBUTE_NAME_LLM_CALL_RESPONSES_JSON = "frisk.llm_call.responses.json";
|
|
22
|
+
/** LLM call span attribute holding the JSON-stringified requested tool calls. */
|
|
23
|
+
export declare const ATTRIBUTE_NAME_LLM_CALL_TOOL_CALLS_JSON = "frisk.llm_call.tool_calls.json";
|
|
24
|
+
/** LLM call span attribute for the model name. */
|
|
25
|
+
export declare const ATTRIBUTE_NAME_MODEL_NAME = "frisk.model.name";
|
|
26
|
+
/** LLM call span attribute for the model provider. */
|
|
27
|
+
export declare const ATTRIBUTE_NAME_MODEL_PROVIDER = "frisk.model.provider";
|
|
28
|
+
/** LLM call span attribute for input (prompt) token count. */
|
|
29
|
+
export declare const ATTRIBUTE_NAME_TOKEN_USAGE_INPUT_TOKENS = "frisk.token_usage.input_tokens";
|
|
30
|
+
/** LLM call span attribute for output (completion) token count. */
|
|
31
|
+
export declare const ATTRIBUTE_NAME_TOKEN_USAGE_OUTPUT_TOKENS = "frisk.token_usage.output_tokens";
|
|
32
|
+
/** LLM call span attribute for total token count. */
|
|
33
|
+
export declare const ATTRIBUTE_NAME_TOKEN_USAGE_TOTAL_TOKENS = "frisk.token_usage.total_tokens";
|
|
10
34
|
export declare const ATTRIBUTE_NAME_SESSION_PROMPT = "frisk.session.prompt";
|
|
11
35
|
export declare const ATTRIBUTE_NAME_SESSION_ID = "frisk.session.id";
|
|
12
36
|
export declare const ATTRIBUTE_NAME_REMOTE_SESSION_ID = "frisk.session.remote_id";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/telemetry/constants.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,eAAO,MAAM,WAAW,iBAAiB,CAAA;AACzC,mCAAmC;AACnC,eAAO,MAAM,cAAc,UAAU,CAAA;AACrC,sEAAsE;AACtE,eAAO,MAAM,0BAA0B,2BAA2B,CAAA;AAElE,eAAO,MAAM,2BAA2B,gCAAgC,CAAA;AAExE,kEAAkE;AAClE,eAAO,MAAM,uBAAuB,kBAAkB,CAAA;AAEtD,eAAO,MAAM,6BAA6B,yBAAyB,CAAA;AACnE,eAAO,MAAM,yBAAyB,qBAAqB,CAAA;AAC3D,eAAO,MAAM,gCAAgC,4BAA4B,CAAA;AAEzE,8DAA8D;AAC9D,eAAO,MAAM,4BAA4B,wBAAwB,CAAA;AACjE,eAAO,MAAM,wBAAwB,oBAAoB,CAAA;AACzD,eAAO,MAAM,4BAA4B,kBAAkB,CAAA;AAC3D,eAAO,MAAM,oCAAoC,0BAA0B,CAAA;AAC3E,eAAO,MAAM,2BAA2B,uBAAuB,CAAA;AAC/D,eAAO,MAAM,6BAA6B,yBAAyB,CAAA;AACnE,e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 -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friskai/frisk-js",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "FriskAI TypeScript SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"build": "bash ./build.sh",
|
|
32
32
|
"build:ts": "bash ./build-ts.sh",
|
|
33
33
|
"dev": "bun build ./src/index.ts --outdir ./dist --target node --format esm --sourcemap=linked --watch --external @langchain/core --external @langchain/langgraph --external langchain",
|
|
34
|
+
"dev:watch": "node ./scripts/dev-watch.mjs",
|
|
34
35
|
"clean": "rm -rf dist",
|
|
35
36
|
"clean:all": "rm -rf dist native/*.node",
|
|
36
37
|
"prepublishOnly": "bun run build",
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @friskai/frisk-js Tool Call Span
|
|
3
|
-
*
|
|
4
|
-
* Context manager wrapping an OpenTelemetry span for a single tool call.
|
|
5
|
-
* Handles span lifecycle, attribute setting, and latency recording.
|
|
6
|
-
*/
|
|
7
|
-
import { Attributes, AttributeValue, type Span, type Tracer } from '@opentelemetry/api';
|
|
8
|
-
import type { FrameworkAdapter } from '../framework-adapter';
|
|
9
|
-
import { RedactionOptions } from './redaction-options';
|
|
10
|
-
import type { NormalizedToolCall, ToolCallDecision, TraceContextCarrier } from './types';
|
|
11
|
-
interface ToolCallSpanOptions {
|
|
12
|
-
sessionId: string;
|
|
13
|
-
adapter: FrameworkAdapter;
|
|
14
|
-
toolCall: NormalizedToolCall;
|
|
15
|
-
friskToolId?: string | null;
|
|
16
|
-
friskToolVersionId?: string | null;
|
|
17
|
-
agentState: Record<string, unknown>;
|
|
18
|
-
parent: Span | null;
|
|
19
|
-
tracer: Tracer;
|
|
20
|
-
redact: RedactionOptions;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Context manager for wrapping a tool call in an OpenTelemetry span.
|
|
24
|
-
*
|
|
25
|
-
* Provides:
|
|
26
|
-
* - Automatic span creation with parent context
|
|
27
|
-
* - Tool call attributes (name, id, args, state)
|
|
28
|
-
* - Redaction of sensitive fields
|
|
29
|
-
* - Latency recording
|
|
30
|
-
* - Result/error attribute setting
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* const span = new ToolCallSpan({adapter, toolCall, agentState, parent, tracer, redact});
|
|
35
|
-
* span.enter();
|
|
36
|
-
* try {
|
|
37
|
-
* const result = await processToolCall();
|
|
38
|
-
* span.saveResult(result);
|
|
39
|
-
* } catch (error) {
|
|
40
|
-
* span.saveError(error);
|
|
41
|
-
* throw error;
|
|
42
|
-
* } finally {
|
|
43
|
-
* span.exit();
|
|
44
|
-
* }
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export declare class ToolCallSpan {
|
|
48
|
-
private adapter;
|
|
49
|
-
private toolCall;
|
|
50
|
-
private friskToolId;
|
|
51
|
-
private agentState;
|
|
52
|
-
private parent;
|
|
53
|
-
private tracer;
|
|
54
|
-
private redaction;
|
|
55
|
-
private _span;
|
|
56
|
-
private _traceContextCarrier;
|
|
57
|
-
private sessionId;
|
|
58
|
-
private friskToolVersionId;
|
|
59
|
-
constructor({ sessionId, adapter, toolCall, friskToolId, friskToolVersionId, agentState, parent, tracer, redact, }: ToolCallSpanOptions);
|
|
60
|
-
/**
|
|
61
|
-
* Get the current span (null if not entered)
|
|
62
|
-
*/
|
|
63
|
-
private get span();
|
|
64
|
-
/**
|
|
65
|
-
* Get the trace context carrier for propagation
|
|
66
|
-
*/
|
|
67
|
-
get traceContextCarrier(): TraceContextCarrier | null;
|
|
68
|
-
/**
|
|
69
|
-
* Execute an async callback within the span context
|
|
70
|
-
*
|
|
71
|
-
* @param callback - Async function to execute within the span
|
|
72
|
-
* @returns Promise resolving to the result of the callback
|
|
73
|
-
*/
|
|
74
|
-
run<T>(callback: (span: ToolCallSpan) => T): T;
|
|
75
|
-
/**
|
|
76
|
-
* Execute an async callback within the span context
|
|
77
|
-
*
|
|
78
|
-
* @param callback - Async function to execute within the span
|
|
79
|
-
* @returns Promise resolving to the result of the callback
|
|
80
|
-
*/
|
|
81
|
-
runAsync<T>(callback: (span: ToolCallSpan) => Promise<T>): Promise<T>;
|
|
82
|
-
setAttribute(key: string, value: AttributeValue): void;
|
|
83
|
-
setAttributes(attributes: Attributes): void;
|
|
84
|
-
/**
|
|
85
|
-
* Save the result of the tool call to the span
|
|
86
|
-
*/
|
|
87
|
-
saveResult(decision: ToolCallDecision): void;
|
|
88
|
-
/**
|
|
89
|
-
* Save an error to the span
|
|
90
|
-
*/
|
|
91
|
-
saveError(error: unknown): void;
|
|
92
|
-
/**
|
|
93
|
-
* Enter the span context - starts the span and sets initial attributes
|
|
94
|
-
*/
|
|
95
|
-
private enter;
|
|
96
|
-
/**
|
|
97
|
-
* Exit the span context
|
|
98
|
-
*/
|
|
99
|
-
private exit;
|
|
100
|
-
}
|
|
101
|
-
export {};
|
|
102
|
-
//# sourceMappingURL=tool-call-span.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool-call-span.d.ts","sourceRoot":"","sources":["../../src/core/tool-call-span.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,UAAU,EACV,cAAc,EAGd,KAAK,IAAI,EACT,KAAK,MAAM,EAEZ,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAmB5D,OAAO,EACL,gBAAgB,EAGjB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EACV,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,SAAS,CAAA;AAEhB,UAAU,mBAAmB;IAC3B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,gBAAgB,CAAA;IACzB,QAAQ,EA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