@friskai/frisk-js 0.2.6 → 0.2.10
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/claude/claude-framework-adapter/claude-framework-adapter.d.ts +2 -0
- package/dist/adapters/claude/claude-framework-adapter/claude-framework-adapter.d.ts.map +1 -1
- package/dist/adapters/claude/claude-framework-adapter/get-claude-agent-sdk-version.d.ts +2 -0
- package/dist/adapters/claude/claude-framework-adapter/get-claude-agent-sdk-version.d.ts.map +1 -0
- package/dist/adapters/claude/index.js +304 -53
- package/dist/adapters/claude/index.js.map +16 -11
- package/dist/adapters/langchain/frisk-callback-handler.d.ts +20 -16
- package/dist/adapters/langchain/frisk-callback-handler.d.ts.map +1 -1
- package/dist/adapters/langchain/frisk-langchain-session.d.ts.map +1 -1
- package/dist/adapters/langchain/index.js +23791 -23455
- package/dist/adapters/langchain/index.js.map +77 -72
- package/dist/adapters/langchain/langchain-framework-adapter/get-langchain-version.d.ts +2 -0
- package/dist/adapters/langchain/langchain-framework-adapter/get-langchain-version.d.ts.map +1 -0
- package/dist/adapters/langchain/langchain-framework-adapter/langchain-framework-adapter.d.ts +2 -0
- package/dist/adapters/langchain/langchain-framework-adapter/langchain-framework-adapter.d.ts.map +1 -1
- package/dist/core/frisk-session.d.ts +27 -2
- package/dist/core/frisk-session.d.ts.map +1 -1
- package/dist/core/frisk.d.ts +6 -2
- package/dist/core/frisk.d.ts.map +1 -1
- package/dist/core/sdk-attributes/detect-runtime.d.ts +5 -0
- package/dist/core/sdk-attributes/detect-runtime.d.ts.map +1 -0
- package/dist/core/sdk-attributes/get-core-sdk-attributes.d.ts +12 -0
- package/dist/core/sdk-attributes/get-core-sdk-attributes.d.ts.map +1 -0
- package/dist/core/sdk-attributes/read-sdk-meta.d.ts +7 -0
- package/dist/core/sdk-attributes/read-sdk-meta.d.ts.map +1 -0
- package/dist/core/tool-call-span.d.ts +1 -2
- package/dist/core/tool-call-span.d.ts.map +1 -1
- package/dist/core/tool-registry.d.ts +5 -1
- package/dist/core/tool-registry.d.ts.map +1 -1
- package/dist/framework-adapter/base-framework-adapter.d.ts +2 -0
- package/dist/framework-adapter/base-framework-adapter.d.ts.map +1 -1
- package/dist/framework-adapter/framework-adapter.d.ts +2 -0
- package/dist/framework-adapter/framework-adapter.d.ts.map +1 -1
- package/dist/generated/sdk-meta.d.ts +3 -0
- package/dist/generated/sdk-meta.d.ts.map +1 -0
- package/dist/index.js +263 -32
- package/dist/index.js.map +14 -10
- package/dist/telemetry/constants.d.ts +6 -1
- package/dist/telemetry/constants.d.ts.map +1 -1
- package/native/frisk-js.darwin-arm64.node +0 -0
- package/native/frisk-js.darwin-x64.node +0 -0
- package/native/frisk-js.linux-arm64-gnu.node +0 -0
- package/native/frisk-js.linux-arm64-musl.node +0 -0
- package/native/frisk-js.linux-x64-gnu.node +0 -0
- package/native/frisk-js.linux-x64-musl.node +0 -0
- package/native/frisk-js.win32-arm64-msvc.node +0 -0
- package/native/frisk-js.win32-x64-msvc.node +0 -0
- package/native/index.cjs +52 -52
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -44016,6 +44016,8 @@ function redactDictionarySimple(data, redactOption) {
|
|
|
44016
44016
|
}
|
|
44017
44017
|
// src/framework-adapter/base-framework-adapter.ts
|
|
44018
44018
|
class BaseFrameworkAdapter {
|
|
44019
|
+
agentFramework = "none";
|
|
44020
|
+
agentFrameworkVersion = null;
|
|
44019
44021
|
serializeToolArgs(toolArgs, options) {
|
|
44020
44022
|
if (toolArgs == null) {
|
|
44021
44023
|
return { value: null, redactedPaths: [] };
|
|
@@ -44082,6 +44084,7 @@ var redactDictionary = nativeBindings.redactDictionary;
|
|
|
44082
44084
|
var TRACER_NAME = "frisk_js_sdk";
|
|
44083
44085
|
var TRACER_VERSION = "0.1.0";
|
|
44084
44086
|
var SPAN_NAME_DECIDE_TOOL_CALL = "frisk.tool_call.decide";
|
|
44087
|
+
var SPAN_NAME_OBSERVE_TOOL_CALL = "frisk.tool_call.observation";
|
|
44085
44088
|
var SPAN_NAME_FRISK_SESSION = "frisk.session";
|
|
44086
44089
|
var ATTRIBUTE_NAME_SESSION_PROMPT = "frisk.session.prompt";
|
|
44087
44090
|
var ATTRIBUTE_NAME_SESSION_ID = "frisk.session.id";
|
|
@@ -44100,7 +44103,11 @@ var ATTRIBUTE_NAME_DECISION_OUTCOME = "frisk.decision.outcome";
|
|
|
44100
44103
|
var ATTRIBUTE_NAME_DECISION_REASON = "frisk.decision.reason";
|
|
44101
44104
|
var ATTRIBUTE_NAME_ERROR_TYPE = "error.type";
|
|
44102
44105
|
var ATTRIBUTE_NAME_ERROR_MESSAGE = "error.message";
|
|
44103
|
-
var
|
|
44106
|
+
var ATTRIBUTE_NAME_TOOL_CALL_IS_SUCCESS = "frisk.tool_call.is_success";
|
|
44107
|
+
var ATTRIBUTE_NAME_TOOL_CALL_IS_ERROR = "frisk.tool_call.is_error";
|
|
44108
|
+
var ATTRIBUTE_NAME_TOOL_CALL_COUNT = "frisk.tool_calls.count";
|
|
44109
|
+
var ATTRIBUTE_NAME_TOOL_CALL_ERROR_COUNT = "frisk.tool_calls.error_count";
|
|
44110
|
+
var ATTRIBUTE_NAME_TOOL_CALL_SEQUENCE_NUMBER = "frisk.tool_call.sequence_number";
|
|
44104
44111
|
// src/telemetry/tracing-manager.ts
|
|
44105
44112
|
var import_grpc_js = __toESM(require_src3(), 1);
|
|
44106
44113
|
var import_exporter_trace_otlp_grpc = __toESM(require_src12(), 1);
|
|
@@ -44156,6 +44163,9 @@ class TracingManager {
|
|
|
44156
44163
|
}
|
|
44157
44164
|
}
|
|
44158
44165
|
|
|
44166
|
+
// src/core/frisk-session.ts
|
|
44167
|
+
var import_api2 = __toESM(require_src4(), 1);
|
|
44168
|
+
|
|
44159
44169
|
// ../../node_modules/zod/v4/core/core.js
|
|
44160
44170
|
var NEVER = Object.freeze({
|
|
44161
44171
|
status: "aborted"
|
|
@@ -48505,7 +48515,6 @@ class ToolCallSpan {
|
|
|
48505
48515
|
tracer;
|
|
48506
48516
|
redaction;
|
|
48507
48517
|
_span = null;
|
|
48508
|
-
_startTimeNs = null;
|
|
48509
48518
|
_traceContextCarrier = null;
|
|
48510
48519
|
sessionId;
|
|
48511
48520
|
friskToolVersionId;
|
|
@@ -48586,7 +48595,6 @@ class ToolCallSpan {
|
|
|
48586
48595
|
}
|
|
48587
48596
|
enter() {
|
|
48588
48597
|
const parentContext = this.parent ? import_api.trace.setSpan(import_api.context.active(), this.parent) : import_api.context.active();
|
|
48589
|
-
this._startTimeNs = process.hrtime.bigint();
|
|
48590
48598
|
const redactedToolArgsResult = this.adapter.serializeToolArgs(removeLlmReasoningArg(this.toolCall.args), { redact: this.redaction.redactToolArgs });
|
|
48591
48599
|
const redactedAgentStateResult = this.adapter.serializeAgentState(this.agentState, { redact: this.redaction.redactAgentState });
|
|
48592
48600
|
this._span = this.tracer.startSpan(SPAN_NAME_DECIDE_TOOL_CALL, {
|
|
@@ -48612,11 +48620,6 @@ class ToolCallSpan {
|
|
|
48612
48620
|
if (!this.span) {
|
|
48613
48621
|
return;
|
|
48614
48622
|
}
|
|
48615
|
-
if (this._startTimeNs !== null) {
|
|
48616
|
-
const endTimeNs = process.hrtime.bigint();
|
|
48617
|
-
const latencyNs = endTimeNs - this._startTimeNs;
|
|
48618
|
-
this.setAttribute(ATTRIBUTE_NAME_LATENCY_NS, Number(latencyNs));
|
|
48619
|
-
}
|
|
48620
48623
|
this.span.end();
|
|
48621
48624
|
}
|
|
48622
48625
|
}
|
|
@@ -48634,12 +48637,15 @@ var DecisionOutcome;
|
|
|
48634
48637
|
class FriskSession {
|
|
48635
48638
|
frisk;
|
|
48636
48639
|
id;
|
|
48637
|
-
|
|
48640
|
+
_rootSpan = null;
|
|
48638
48641
|
redaction;
|
|
48639
48642
|
tracer;
|
|
48640
48643
|
logger;
|
|
48641
48644
|
_rootRunId = null;
|
|
48642
48645
|
_isTracing = false;
|
|
48646
|
+
toolCallSequenceNumber = 0;
|
|
48647
|
+
toolCallSequenceGenerator = this.createToolCallSequenceGenerator();
|
|
48648
|
+
toolCallErrorCount = 0;
|
|
48643
48649
|
constructor({ frisk, redact, tracer, logging }) {
|
|
48644
48650
|
const sessionId = this.constructor.generateSessionId();
|
|
48645
48651
|
this.logger = deriveSdkLogger(logging, {
|
|
@@ -48650,12 +48656,75 @@ class FriskSession {
|
|
|
48650
48656
|
this.redaction = redact;
|
|
48651
48657
|
this.tracer = tracer;
|
|
48652
48658
|
}
|
|
48659
|
+
get rootSpan() {
|
|
48660
|
+
return this._rootSpan;
|
|
48661
|
+
}
|
|
48662
|
+
getTracer() {
|
|
48663
|
+
return this.tracer;
|
|
48664
|
+
}
|
|
48653
48665
|
get isTracing() {
|
|
48654
48666
|
return this._isTracing;
|
|
48655
48667
|
}
|
|
48656
48668
|
get rootRunId() {
|
|
48657
48669
|
return this._rootRunId;
|
|
48658
48670
|
}
|
|
48671
|
+
async createToolCallSpan({
|
|
48672
|
+
name,
|
|
48673
|
+
args: toolArgsInput
|
|
48674
|
+
}) {
|
|
48675
|
+
const toolArgs = this.validateToolArgs(toolArgsInput);
|
|
48676
|
+
const redactedToolArgsResult = this.frisk.adapter?.serializeToolArgs(removeLlmReasoningArg(toolArgs), { redact: this.redaction.redactToolArgs }) ?? {
|
|
48677
|
+
value: "{}",
|
|
48678
|
+
redactedPaths: []
|
|
48679
|
+
};
|
|
48680
|
+
const sessionSpan = this.rootSpan;
|
|
48681
|
+
const parentContext = sessionSpan ? import_api2.trace.setSpan(import_api2.context.active(), sessionSpan) : import_api2.context.active();
|
|
48682
|
+
const spanAttributes = {
|
|
48683
|
+
[ATTRIBUTE_NAME_SESSION_ID]: this.id,
|
|
48684
|
+
[ATTRIBUTE_NAME_TOOL_NAME]: name,
|
|
48685
|
+
[ATTRIBUTE_NAME_TOOL_ARGS_JSON]: redactedToolArgsResult.value,
|
|
48686
|
+
[ATTRIBUTE_NAME_TOOL_ARGS_REDACTED_PATHS_JSON]: JSON.stringify(redactedToolArgsResult.redactedPaths),
|
|
48687
|
+
[ATTRIBUTE_NAME_TOOL_CALL_SEQUENCE_NUMBER]: this.toolCallSequenceGenerator.next().value
|
|
48688
|
+
};
|
|
48689
|
+
await this.frisk.toolRegistrationComplete;
|
|
48690
|
+
const registeredTool = this.frisk.getRegisteredTool(name);
|
|
48691
|
+
if (registeredTool) {
|
|
48692
|
+
spanAttributes[ATTRIBUTE_NAME_FRISK_TOOL_ID] = registeredTool.id;
|
|
48693
|
+
spanAttributes[ATTRIBUTE_NAME_FRISK_TOOL_VERSION_ID] = registeredTool.versionId;
|
|
48694
|
+
}
|
|
48695
|
+
const span = this.getTracer().startSpan(SPAN_NAME_OBSERVE_TOOL_CALL, {
|
|
48696
|
+
attributes: spanAttributes
|
|
48697
|
+
}, parentContext);
|
|
48698
|
+
return span;
|
|
48699
|
+
}
|
|
48700
|
+
closeToolCallSpan({
|
|
48701
|
+
toolCallId,
|
|
48702
|
+
span,
|
|
48703
|
+
err,
|
|
48704
|
+
status
|
|
48705
|
+
}) {
|
|
48706
|
+
if (toolCallId) {
|
|
48707
|
+
span.setAttribute(ATTRIBUTE_NAME_TOOL_CALL_ID, toolCallId);
|
|
48708
|
+
}
|
|
48709
|
+
if (status === "error" /* Error */ || !!err) {
|
|
48710
|
+
this.incrementToolCallErrors();
|
|
48711
|
+
span.setAttribute(ATTRIBUTE_NAME_TOOL_CALL_IS_ERROR, true);
|
|
48712
|
+
span.setAttribute(ATTRIBUTE_NAME_TOOL_CALL_IS_SUCCESS, false);
|
|
48713
|
+
} else if (status === "success" /* Success */) {
|
|
48714
|
+
span.setAttribute(ATTRIBUTE_NAME_TOOL_CALL_IS_SUCCESS, true);
|
|
48715
|
+
span.setAttribute(ATTRIBUTE_NAME_TOOL_CALL_IS_ERROR, false);
|
|
48716
|
+
}
|
|
48717
|
+
if (err && err instanceof Error) {
|
|
48718
|
+
span.setAttribute(ATTRIBUTE_NAME_ERROR_MESSAGE, `${err}`);
|
|
48719
|
+
span.setAttribute(ATTRIBUTE_NAME_ERROR_TYPE, `${err.constructor.name}`);
|
|
48720
|
+
}
|
|
48721
|
+
span.end();
|
|
48722
|
+
}
|
|
48723
|
+
validateToolArgs(parsedToolArgs) {
|
|
48724
|
+
const isPlainObject2 = typeof parsedToolArgs === "object" && parsedToolArgs !== null && !Array.isArray(parsedToolArgs) && (Object.getPrototypeOf(parsedToolArgs) === Object.prototype || Object.getPrototypeOf(parsedToolArgs) === null);
|
|
48725
|
+
const toolArgs = isPlainObject2 ? parsedToolArgs : {};
|
|
48726
|
+
return toolArgs;
|
|
48727
|
+
}
|
|
48659
48728
|
decideToolCall({
|
|
48660
48729
|
toolCall,
|
|
48661
48730
|
agentState
|
|
@@ -48668,7 +48737,7 @@ class FriskSession {
|
|
|
48668
48737
|
friskToolId: registeredTool?.id ?? null,
|
|
48669
48738
|
friskToolVersionId: registeredTool?.versionId ?? null,
|
|
48670
48739
|
agentState,
|
|
48671
|
-
parent: this.
|
|
48740
|
+
parent: this._rootSpan,
|
|
48672
48741
|
tracer: this.tracer,
|
|
48673
48742
|
redact: this.redaction
|
|
48674
48743
|
});
|
|
@@ -48712,6 +48781,20 @@ class FriskSession {
|
|
|
48712
48781
|
}
|
|
48713
48782
|
});
|
|
48714
48783
|
}
|
|
48784
|
+
*createToolCallSequenceGenerator() {
|
|
48785
|
+
while (true) {
|
|
48786
|
+
yield this.toolCallSequenceNumber++;
|
|
48787
|
+
}
|
|
48788
|
+
}
|
|
48789
|
+
getToolCallCount() {
|
|
48790
|
+
return this.toolCallSequenceNumber;
|
|
48791
|
+
}
|
|
48792
|
+
incrementToolCallErrors() {
|
|
48793
|
+
this.toolCallErrorCount += 1;
|
|
48794
|
+
}
|
|
48795
|
+
getToolCallErrorCount() {
|
|
48796
|
+
return this.toolCallErrorCount;
|
|
48797
|
+
}
|
|
48715
48798
|
initTracing({ runId, inputs }) {
|
|
48716
48799
|
this._rootRunId = runId;
|
|
48717
48800
|
this._isTracing = true;
|
|
@@ -48726,21 +48809,141 @@ class FriskSession {
|
|
|
48726
48809
|
return span;
|
|
48727
48810
|
}
|
|
48728
48811
|
endTracing() {
|
|
48729
|
-
if (this.
|
|
48730
|
-
this.
|
|
48812
|
+
if (this._rootSpan) {
|
|
48813
|
+
this._rootSpan.setAttribute(ATTRIBUTE_NAME_TOOL_CALL_COUNT, this.getToolCallCount());
|
|
48814
|
+
this._rootSpan.setAttribute(ATTRIBUTE_NAME_TOOL_CALL_ERROR_COUNT, this.getToolCallErrorCount());
|
|
48815
|
+
this._rootSpan.end();
|
|
48731
48816
|
}
|
|
48732
48817
|
this._isTracing = false;
|
|
48733
48818
|
const registry2 = SessionRegistry.getInstance();
|
|
48734
48819
|
registry2.unregister(this.id);
|
|
48735
48820
|
}
|
|
48736
48821
|
setRootSpan(span) {
|
|
48737
|
-
this.
|
|
48822
|
+
this._rootSpan = span;
|
|
48738
48823
|
}
|
|
48739
48824
|
static generateSessionId() {
|
|
48740
48825
|
return v4();
|
|
48741
48826
|
}
|
|
48742
48827
|
}
|
|
48743
48828
|
|
|
48829
|
+
// src/core/sdk-attributes/detect-runtime.ts
|
|
48830
|
+
function detectRuntime() {
|
|
48831
|
+
const g = globalThis;
|
|
48832
|
+
if (g.Bun) {
|
|
48833
|
+
return {
|
|
48834
|
+
runtime: "bun",
|
|
48835
|
+
runtimeVersion: g.Bun.version
|
|
48836
|
+
};
|
|
48837
|
+
}
|
|
48838
|
+
if (g.Deno) {
|
|
48839
|
+
return {
|
|
48840
|
+
runtime: "deno",
|
|
48841
|
+
runtimeVersion: g.Deno.version.deno
|
|
48842
|
+
};
|
|
48843
|
+
}
|
|
48844
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
48845
|
+
return {
|
|
48846
|
+
runtime: "node",
|
|
48847
|
+
runtimeVersion: process.versions.node
|
|
48848
|
+
};
|
|
48849
|
+
}
|
|
48850
|
+
if (typeof navigator !== "undefined") {
|
|
48851
|
+
return {
|
|
48852
|
+
runtime: "browser",
|
|
48853
|
+
runtimeVersion: navigator.userAgent
|
|
48854
|
+
};
|
|
48855
|
+
}
|
|
48856
|
+
return {
|
|
48857
|
+
runtime: "unknown",
|
|
48858
|
+
runtimeVersion: "unknown"
|
|
48859
|
+
};
|
|
48860
|
+
}
|
|
48861
|
+
|
|
48862
|
+
// src/core/sdk-attributes/read-sdk-meta.ts
|
|
48863
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
48864
|
+
import { dirname as dirname2, join } from "node:path";
|
|
48865
|
+
import { fileURLToPath } from "node:url";
|
|
48866
|
+
|
|
48867
|
+
// src/generated/sdk-meta.ts
|
|
48868
|
+
var SDK_NAME = "@friskai/frisk-js";
|
|
48869
|
+
var SDK_VERSION = "0.2.10";
|
|
48870
|
+
|
|
48871
|
+
// src/core/sdk-attributes/read-sdk-meta.ts
|
|
48872
|
+
function getSdkMeta() {
|
|
48873
|
+
if (isNonEmptyString(SDK_NAME) && isNonEmptyString(SDK_VERSION)) {
|
|
48874
|
+
return {
|
|
48875
|
+
sdkName: SDK_NAME,
|
|
48876
|
+
sdkVersion: SDK_VERSION,
|
|
48877
|
+
source: "injected"
|
|
48878
|
+
};
|
|
48879
|
+
}
|
|
48880
|
+
const fromPkg = tryReadPackageJson();
|
|
48881
|
+
if (fromPkg) {
|
|
48882
|
+
return {
|
|
48883
|
+
...fromPkg,
|
|
48884
|
+
source: "package.json"
|
|
48885
|
+
};
|
|
48886
|
+
}
|
|
48887
|
+
return {
|
|
48888
|
+
sdkName: "unknown",
|
|
48889
|
+
sdkVersion: "unknown",
|
|
48890
|
+
source: "unknown"
|
|
48891
|
+
};
|
|
48892
|
+
}
|
|
48893
|
+
function isNonEmptyString(value) {
|
|
48894
|
+
return typeof value === "string" && value.length > 0;
|
|
48895
|
+
}
|
|
48896
|
+
function findNearestPackageJson(startDir) {
|
|
48897
|
+
let dir = startDir;
|
|
48898
|
+
while (true) {
|
|
48899
|
+
const candidate = join(dir, "package.json");
|
|
48900
|
+
if (existsSync(candidate)) {
|
|
48901
|
+
return candidate;
|
|
48902
|
+
}
|
|
48903
|
+
const parent = dirname2(dir);
|
|
48904
|
+
if (parent === dir) {
|
|
48905
|
+
return null;
|
|
48906
|
+
}
|
|
48907
|
+
dir = parent;
|
|
48908
|
+
}
|
|
48909
|
+
}
|
|
48910
|
+
function tryReadPackageJson() {
|
|
48911
|
+
try {
|
|
48912
|
+
const here = dirname2(fileURLToPath(import.meta.url));
|
|
48913
|
+
const pkgPath = findNearestPackageJson(here);
|
|
48914
|
+
if (!pkgPath)
|
|
48915
|
+
return null;
|
|
48916
|
+
const raw = readFileSync(pkgPath, "utf8");
|
|
48917
|
+
const pkg = JSON.parse(raw);
|
|
48918
|
+
if (!isNonEmptyString(pkg.name) || !isNonEmptyString(pkg.version)) {
|
|
48919
|
+
return null;
|
|
48920
|
+
}
|
|
48921
|
+
return {
|
|
48922
|
+
sdkName: pkg.name,
|
|
48923
|
+
sdkVersion: pkg.version
|
|
48924
|
+
};
|
|
48925
|
+
} catch {
|
|
48926
|
+
return null;
|
|
48927
|
+
}
|
|
48928
|
+
}
|
|
48929
|
+
|
|
48930
|
+
// src/core/sdk-attributes/get-core-sdk-attributes.ts
|
|
48931
|
+
var coreSdkAttributes = null;
|
|
48932
|
+
function getCoreSdkAttributes() {
|
|
48933
|
+
if (!coreSdkAttributes) {
|
|
48934
|
+
const { sdkName, sdkVersion } = getSdkMeta();
|
|
48935
|
+
const { runtime, runtimeVersion } = detectRuntime();
|
|
48936
|
+
coreSdkAttributes = {
|
|
48937
|
+
version: sdkVersion,
|
|
48938
|
+
language: "js",
|
|
48939
|
+
name: sdkName,
|
|
48940
|
+
runtime,
|
|
48941
|
+
runtimeVersion
|
|
48942
|
+
};
|
|
48943
|
+
}
|
|
48944
|
+
return coreSdkAttributes;
|
|
48945
|
+
}
|
|
48946
|
+
|
|
48744
48947
|
// src/core/tool-approval-request.ts
|
|
48745
48948
|
var REQUEST_TIMEOUT_MS = 1e4;
|
|
48746
48949
|
var logger = deriveSdkLogger(undefined, {
|
|
@@ -49018,16 +49221,25 @@ class ToolRegistry {
|
|
|
49018
49221
|
getRegisteredTool(toolName) {
|
|
49019
49222
|
return this.toolNameToId.get(toolName) ?? null;
|
|
49020
49223
|
}
|
|
49021
|
-
registerTools(
|
|
49022
|
-
|
|
49023
|
-
|
|
49224
|
+
registerTools({
|
|
49225
|
+
tools,
|
|
49226
|
+
sdkAttributes
|
|
49227
|
+
}) {
|
|
49228
|
+
const toolsList = [...tools];
|
|
49229
|
+
if (toolsList.length === 0 && !sdkAttributes) {
|
|
49024
49230
|
this.initialized = Promise.resolve(true);
|
|
49025
49231
|
return;
|
|
49026
49232
|
}
|
|
49027
|
-
this.initialized = this.executeRegisterTools(
|
|
49233
|
+
this.initialized = this.executeRegisterTools({
|
|
49234
|
+
tools: toolsList,
|
|
49235
|
+
sdkAttributes
|
|
49236
|
+
});
|
|
49028
49237
|
this.initialized;
|
|
49029
49238
|
}
|
|
49030
|
-
async executeRegisterTools(
|
|
49239
|
+
async executeRegisterTools({
|
|
49240
|
+
tools,
|
|
49241
|
+
sdkAttributes
|
|
49242
|
+
}) {
|
|
49031
49243
|
try {
|
|
49032
49244
|
const accessToken = await this.getAccessToken();
|
|
49033
49245
|
const response = await fetch(buildRegisterToolsEndpoint(this.apiBaseUrl), {
|
|
@@ -49037,13 +49249,14 @@ class ToolRegistry {
|
|
|
49037
49249
|
"Content-Type": "application/json"
|
|
49038
49250
|
},
|
|
49039
49251
|
body: JSON.stringify({
|
|
49040
|
-
properties:
|
|
49252
|
+
properties: tools.map((property) => ({
|
|
49041
49253
|
name: property.name,
|
|
49042
49254
|
description: property.description,
|
|
49043
49255
|
inputJsonSchema: property.inputJsonSchema,
|
|
49044
49256
|
outputJsonSchema: property.outputJsonSchema,
|
|
49045
49257
|
responseFormat: property.responseFormat
|
|
49046
|
-
}))
|
|
49258
|
+
})),
|
|
49259
|
+
sdk: sdkAttributes
|
|
49047
49260
|
})
|
|
49048
49261
|
});
|
|
49049
49262
|
if (!response.ok) {
|
|
@@ -49064,18 +49277,22 @@ class ToolRegistry {
|
|
|
49064
49277
|
|
|
49065
49278
|
// src/core/frisk.ts
|
|
49066
49279
|
class Frisk {
|
|
49067
|
-
redaction
|
|
49280
|
+
get redaction() {
|
|
49281
|
+
return this._redaction;
|
|
49282
|
+
}
|
|
49283
|
+
_redaction;
|
|
49068
49284
|
apiBaseUrl;
|
|
49069
49285
|
otlpEndpoint;
|
|
49070
49286
|
accessTokenProvider;
|
|
49071
49287
|
initialized = false;
|
|
49072
49288
|
rootLogger;
|
|
49073
49289
|
logger;
|
|
49074
|
-
|
|
49290
|
+
_logLevel;
|
|
49075
49291
|
_adapter;
|
|
49076
49292
|
_friskHandle = null;
|
|
49077
49293
|
_tracingManager = null;
|
|
49078
49294
|
_toolRegistry;
|
|
49295
|
+
sdkAttributes;
|
|
49079
49296
|
wrapToolsCalled = false;
|
|
49080
49297
|
get toolRegistrationComplete() {
|
|
49081
49298
|
if (!this.wrapToolsCalled) {
|
|
@@ -49083,6 +49300,9 @@ class Frisk {
|
|
|
49083
49300
|
}
|
|
49084
49301
|
return this._toolRegistry.initialized;
|
|
49085
49302
|
}
|
|
49303
|
+
get logLevel() {
|
|
49304
|
+
return this._logLevel;
|
|
49305
|
+
}
|
|
49086
49306
|
static async connect(options) {
|
|
49087
49307
|
const instance = new this(options);
|
|
49088
49308
|
await instance.connect();
|
|
@@ -49092,13 +49312,15 @@ class Frisk {
|
|
|
49092
49312
|
this.rootLogger = deriveSdkLogger(options?.logging, {
|
|
49093
49313
|
sdk: "frisk"
|
|
49094
49314
|
});
|
|
49095
|
-
this.
|
|
49315
|
+
this._logLevel = options?.logging?.logLevel;
|
|
49096
49316
|
this.logger = deriveSdkLogger({
|
|
49097
49317
|
logger: this.rootLogger,
|
|
49098
|
-
logLevel: this.
|
|
49318
|
+
logLevel: this._logLevel
|
|
49099
49319
|
}, {
|
|
49100
49320
|
component: "FriskCore"
|
|
49101
49321
|
});
|
|
49322
|
+
this._adapter = options?.adapter ?? new BaseFrameworkAdapter;
|
|
49323
|
+
this.sdkAttributes = this.getSdkAttributes();
|
|
49102
49324
|
const apiKey = options?.apiKey ?? getEnv(FRISK_API_KEY);
|
|
49103
49325
|
if (!apiKey) {
|
|
49104
49326
|
throw new MissingAPIKeyError;
|
|
@@ -49113,7 +49335,7 @@ class Frisk {
|
|
|
49113
49335
|
baseUrl,
|
|
49114
49336
|
logging: {
|
|
49115
49337
|
logger: this.rootLogger,
|
|
49116
|
-
logLevel: this.
|
|
49338
|
+
logLevel: this._logLevel
|
|
49117
49339
|
}
|
|
49118
49340
|
});
|
|
49119
49341
|
this._toolRegistry = new ToolRegistry({
|
|
@@ -49126,8 +49348,7 @@ class Frisk {
|
|
|
49126
49348
|
throw new MissingOtlpEndpointError;
|
|
49127
49349
|
}
|
|
49128
49350
|
this.otlpEndpoint = otlpEndpoint;
|
|
49129
|
-
this.
|
|
49130
|
-
this._adapter = options?.adapter ?? new BaseFrameworkAdapter;
|
|
49351
|
+
this._redaction = resolveRedactionOptions(options?.redact);
|
|
49131
49352
|
}
|
|
49132
49353
|
get friskHandle() {
|
|
49133
49354
|
if (!this._friskHandle) {
|
|
@@ -49165,11 +49386,11 @@ class Frisk {
|
|
|
49165
49386
|
session(metadata) {
|
|
49166
49387
|
const session = new FriskSession({
|
|
49167
49388
|
frisk: this,
|
|
49168
|
-
redact: this.
|
|
49389
|
+
redact: this._redaction,
|
|
49169
49390
|
tracer: this.tracingManager.getTracer(),
|
|
49170
49391
|
logging: {
|
|
49171
49392
|
logger: this.rootLogger,
|
|
49172
|
-
logLevel: this.
|
|
49393
|
+
logLevel: this._logLevel
|
|
49173
49394
|
}
|
|
49174
49395
|
});
|
|
49175
49396
|
const registry2 = SessionRegistry.getInstance();
|
|
@@ -49184,13 +49405,23 @@ class Frisk {
|
|
|
49184
49405
|
const toolList = [...tools];
|
|
49185
49406
|
const registerToolProperties = toolList.map((tool) => this._adapter.extractRegisterToolProperties?.(tool)).filter((properties) => properties !== null && properties !== undefined);
|
|
49186
49407
|
if (registerToolProperties.length > 0) {
|
|
49187
|
-
this._toolRegistry.registerTools(
|
|
49408
|
+
this._toolRegistry.registerTools({
|
|
49409
|
+
tools: registerToolProperties,
|
|
49410
|
+
sdkAttributes: this.sdkAttributes
|
|
49411
|
+
});
|
|
49188
49412
|
}
|
|
49189
49413
|
if (this._adapter.wrapTools) {
|
|
49190
49414
|
return this._adapter.wrapTools(toolList, options);
|
|
49191
49415
|
}
|
|
49192
49416
|
return toolList;
|
|
49193
49417
|
}
|
|
49418
|
+
getSdkAttributes() {
|
|
49419
|
+
return {
|
|
49420
|
+
...getCoreSdkAttributes(),
|
|
49421
|
+
agentFramework: this.adapter.agentFramework ?? null,
|
|
49422
|
+
agentFrameworkVersion: this.adapter.agentFrameworkVersion ?? null
|
|
49423
|
+
};
|
|
49424
|
+
}
|
|
49194
49425
|
wrapTool(tool, options = DefaultWrapToolOptions) {
|
|
49195
49426
|
if (this._adapter.wrapTool) {
|
|
49196
49427
|
return this._adapter.wrapTool(tool, options);
|
|
@@ -49217,7 +49448,7 @@ class Frisk {
|
|
|
49217
49448
|
const argsJson = toolCall.args ? JSON.stringify(removeLlmReasoningArg(toolCall.args)) : null;
|
|
49218
49449
|
const stateJson = agentState ? JSON.stringify(agentState) : null;
|
|
49219
49450
|
const registeredTool = this.getRegisteredTool(toolCall.name);
|
|
49220
|
-
const coreResult = this.friskHandle.process(toolCall.name, registeredTool?.id ?? null, registeredTool?.versionId ?? null, argsJson, stateJson, id, this.
|
|
49451
|
+
const coreResult = this.friskHandle.process(toolCall.name, registeredTool?.id ?? null, registeredTool?.versionId ?? null, argsJson, stateJson, id, this._redaction, traceContextCarrier);
|
|
49221
49452
|
const outcome = coreResult.decision === "allow" ? "allow" /* ALLOW */ : coreResult.decision === "deny" ? "deny" /* DENY */ : coreResult.decision === "escalate" ? "escalate" /* ESCALATE */ : "error" /* ERROR */;
|
|
49222
49453
|
return {
|
|
49223
49454
|
outcome,
|
|
@@ -49309,5 +49540,5 @@ export {
|
|
|
49309
49540
|
AccessTokenProvider
|
|
49310
49541
|
};
|
|
49311
49542
|
|
|
49312
|
-
//# debugId=
|
|
49543
|
+
//# debugId=40ACC90B60961E6C64756E2164756E21
|
|
49313
49544
|
//# sourceMappingURL=index.js.map
|