@friskai/frisk-js 0.2.4 → 0.2.8
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 +4 -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/frisk-claude.d.ts.map +1 -1
- package/dist/adapters/claude/index.js +694 -40
- package/dist/adapters/claude/index.js.map +18 -12
- package/dist/adapters/langchain/frisk-callback-handler.d.ts +21 -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/frisk-tool-middleware.d.ts.map +1 -1
- package/dist/adapters/langchain/index.js +24147 -23226
- package/dist/adapters/langchain/index.js.map +77 -68
- 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 +4 -0
- package/dist/adapters/langchain/langchain-framework-adapter/langchain-framework-adapter.d.ts.map +1 -1
- package/dist/adapters/langchain/langchain-framework-adapter/normalize-to-json-schema.d.ts +3 -0
- package/dist/adapters/langchain/langchain-framework-adapter/normalize-to-json-schema.d.ts.map +1 -0
- package/dist/core/frisk-session.d.ts +6 -3
- package/dist/core/frisk-session.d.ts.map +1 -1
- package/dist/core/frisk.d.ts +15 -4
- 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-approval-request.d.ts +5 -1
- package/dist/core/tool-approval-request.d.ts.map +1 -1
- package/dist/core/tool-call-span.d.ts +5 -1
- package/dist/core/tool-call-span.d.ts.map +1 -1
- package/dist/core/tool-registry.d.ts +35 -0
- package/dist/core/tool-registry.d.ts.map +1 -0
- package/dist/framework-adapter/base-framework-adapter.d.ts +4 -0
- package/dist/framework-adapter/base-framework-adapter.d.ts.map +1 -1
- package/dist/framework-adapter/framework-adapter.d.ts +9 -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 +651 -20
- package/dist/index.js.map +15 -10
- package/dist/telemetry/constants.d.ts +5 -0
- 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/native/index.d.ts +3 -1
- 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: [] };
|
|
@@ -44053,6 +44055,9 @@ class BaseFrameworkAdapter {
|
|
|
44053
44055
|
const prompt = agentState["prompt"];
|
|
44054
44056
|
return typeof prompt === "string" ? prompt : null;
|
|
44055
44057
|
}
|
|
44058
|
+
extractRegisterToolProperties(_tool) {
|
|
44059
|
+
return null;
|
|
44060
|
+
}
|
|
44056
44061
|
}
|
|
44057
44062
|
// src/framework-adapter/framework-adapter.ts
|
|
44058
44063
|
var DefaultWrapToolOptions = {
|
|
@@ -44079,12 +44084,15 @@ var redactDictionary = nativeBindings.redactDictionary;
|
|
|
44079
44084
|
var TRACER_NAME = "frisk_js_sdk";
|
|
44080
44085
|
var TRACER_VERSION = "0.1.0";
|
|
44081
44086
|
var SPAN_NAME_DECIDE_TOOL_CALL = "frisk.tool_call.decide";
|
|
44087
|
+
var SPAN_NAME_OBSERVE_TOOL_CALL = "frisk.tool_call.observation";
|
|
44082
44088
|
var SPAN_NAME_FRISK_SESSION = "frisk.session";
|
|
44083
44089
|
var ATTRIBUTE_NAME_SESSION_PROMPT = "frisk.session.prompt";
|
|
44084
44090
|
var ATTRIBUTE_NAME_SESSION_ID = "frisk.session.id";
|
|
44085
44091
|
var ATTRIBUTE_NAME_REMOTE_SESSION_ID = "frisk.session.remote_id";
|
|
44086
44092
|
var ATTRIBUTE_NAME_LLM_REASONING = "frisk.llm_reasoning";
|
|
44087
44093
|
var ATTRIBUTE_NAME_TOOL_NAME = "frisk.tool.name";
|
|
44094
|
+
var ATTRIBUTE_NAME_FRISK_TOOL_ID = "frisk.tool.id";
|
|
44095
|
+
var ATTRIBUTE_NAME_FRISK_TOOL_VERSION_ID = "frisk.tool.version_id";
|
|
44088
44096
|
var ATTRIBUTE_NAME_TOOL_CALL_ID = "frisk.tool_call.id";
|
|
44089
44097
|
var ATTRIBUTE_NAME_TOOL_ARGS_JSON = "frisk.tool.args.json";
|
|
44090
44098
|
var ATTRIBUTE_NAME_TOOL_ARGS_REDACTED_PATHS_JSON = "frisk.tool.args_redacted_paths.json";
|
|
@@ -44096,6 +44104,8 @@ var ATTRIBUTE_NAME_DECISION_REASON = "frisk.decision.reason";
|
|
|
44096
44104
|
var ATTRIBUTE_NAME_ERROR_TYPE = "error.type";
|
|
44097
44105
|
var ATTRIBUTE_NAME_ERROR_MESSAGE = "error.message";
|
|
44098
44106
|
var ATTRIBUTE_NAME_LATENCY_NS = "latency_ns";
|
|
44107
|
+
var ATTRIBUTE_NAME_TOOL_CALL_IS_SUCCESS = "frisk.tool_call.is_success";
|
|
44108
|
+
var ATTRIBUTE_NAME_TOOL_CALL_IS_ERROR = "frisk.tool_call.is_error";
|
|
44099
44109
|
// src/telemetry/tracing-manager.ts
|
|
44100
44110
|
var import_grpc_js = __toESM(require_src3(), 1);
|
|
44101
44111
|
var import_exporter_trace_otlp_grpc = __toESM(require_src12(), 1);
|
|
@@ -47317,10 +47327,92 @@ var stringProcessor = (schema, ctx, _json, _params) => {
|
|
|
47317
47327
|
}
|
|
47318
47328
|
}
|
|
47319
47329
|
};
|
|
47330
|
+
var numberProcessor = (schema, ctx, _json, _params) => {
|
|
47331
|
+
const json = _json;
|
|
47332
|
+
const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = schema._zod.bag;
|
|
47333
|
+
if (typeof format === "string" && format.includes("int"))
|
|
47334
|
+
json.type = "integer";
|
|
47335
|
+
else
|
|
47336
|
+
json.type = "number";
|
|
47337
|
+
if (typeof exclusiveMinimum === "number") {
|
|
47338
|
+
if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
|
|
47339
|
+
json.minimum = exclusiveMinimum;
|
|
47340
|
+
json.exclusiveMinimum = true;
|
|
47341
|
+
} else {
|
|
47342
|
+
json.exclusiveMinimum = exclusiveMinimum;
|
|
47343
|
+
}
|
|
47344
|
+
}
|
|
47345
|
+
if (typeof minimum === "number") {
|
|
47346
|
+
json.minimum = minimum;
|
|
47347
|
+
if (typeof exclusiveMinimum === "number" && ctx.target !== "draft-04") {
|
|
47348
|
+
if (exclusiveMinimum >= minimum)
|
|
47349
|
+
delete json.minimum;
|
|
47350
|
+
else
|
|
47351
|
+
delete json.exclusiveMinimum;
|
|
47352
|
+
}
|
|
47353
|
+
}
|
|
47354
|
+
if (typeof exclusiveMaximum === "number") {
|
|
47355
|
+
if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
|
|
47356
|
+
json.maximum = exclusiveMaximum;
|
|
47357
|
+
json.exclusiveMaximum = true;
|
|
47358
|
+
} else {
|
|
47359
|
+
json.exclusiveMaximum = exclusiveMaximum;
|
|
47360
|
+
}
|
|
47361
|
+
}
|
|
47362
|
+
if (typeof maximum === "number") {
|
|
47363
|
+
json.maximum = maximum;
|
|
47364
|
+
if (typeof exclusiveMaximum === "number" && ctx.target !== "draft-04") {
|
|
47365
|
+
if (exclusiveMaximum <= maximum)
|
|
47366
|
+
delete json.maximum;
|
|
47367
|
+
else
|
|
47368
|
+
delete json.exclusiveMaximum;
|
|
47369
|
+
}
|
|
47370
|
+
}
|
|
47371
|
+
if (typeof multipleOf === "number")
|
|
47372
|
+
json.multipleOf = multipleOf;
|
|
47373
|
+
};
|
|
47374
|
+
var booleanProcessor = (_schema, _ctx, json, _params) => {
|
|
47375
|
+
json.type = "boolean";
|
|
47376
|
+
};
|
|
47377
|
+
var bigintProcessor = (_schema, ctx, _json, _params) => {
|
|
47378
|
+
if (ctx.unrepresentable === "throw") {
|
|
47379
|
+
throw new Error("BigInt cannot be represented in JSON Schema");
|
|
47380
|
+
}
|
|
47381
|
+
};
|
|
47382
|
+
var symbolProcessor = (_schema, ctx, _json, _params) => {
|
|
47383
|
+
if (ctx.unrepresentable === "throw") {
|
|
47384
|
+
throw new Error("Symbols cannot be represented in JSON Schema");
|
|
47385
|
+
}
|
|
47386
|
+
};
|
|
47387
|
+
var nullProcessor = (_schema, ctx, json, _params) => {
|
|
47388
|
+
if (ctx.target === "openapi-3.0") {
|
|
47389
|
+
json.type = "string";
|
|
47390
|
+
json.nullable = true;
|
|
47391
|
+
json.enum = [null];
|
|
47392
|
+
} else {
|
|
47393
|
+
json.type = "null";
|
|
47394
|
+
}
|
|
47395
|
+
};
|
|
47396
|
+
var undefinedProcessor = (_schema, ctx, _json, _params) => {
|
|
47397
|
+
if (ctx.unrepresentable === "throw") {
|
|
47398
|
+
throw new Error("Undefined cannot be represented in JSON Schema");
|
|
47399
|
+
}
|
|
47400
|
+
};
|
|
47401
|
+
var voidProcessor = (_schema, ctx, _json, _params) => {
|
|
47402
|
+
if (ctx.unrepresentable === "throw") {
|
|
47403
|
+
throw new Error("Void cannot be represented in JSON Schema");
|
|
47404
|
+
}
|
|
47405
|
+
};
|
|
47320
47406
|
var neverProcessor = (_schema, _ctx, json, _params) => {
|
|
47321
47407
|
json.not = {};
|
|
47322
47408
|
};
|
|
47409
|
+
var anyProcessor = (_schema, _ctx, _json, _params) => {};
|
|
47323
47410
|
var unknownProcessor = (_schema, _ctx, _json, _params) => {};
|
|
47411
|
+
var dateProcessor = (_schema, ctx, _json, _params) => {
|
|
47412
|
+
if (ctx.unrepresentable === "throw") {
|
|
47413
|
+
throw new Error("Date cannot be represented in JSON Schema");
|
|
47414
|
+
}
|
|
47415
|
+
};
|
|
47324
47416
|
var enumProcessor = (schema, _ctx, json, _params) => {
|
|
47325
47417
|
const def = schema._zod.def;
|
|
47326
47418
|
const values = getEnumValues(def.entries);
|
|
@@ -47330,16 +47422,109 @@ var enumProcessor = (schema, _ctx, json, _params) => {
|
|
|
47330
47422
|
json.type = "string";
|
|
47331
47423
|
json.enum = values;
|
|
47332
47424
|
};
|
|
47425
|
+
var literalProcessor = (schema, ctx, json, _params) => {
|
|
47426
|
+
const def = schema._zod.def;
|
|
47427
|
+
const vals = [];
|
|
47428
|
+
for (const val of def.values) {
|
|
47429
|
+
if (val === undefined) {
|
|
47430
|
+
if (ctx.unrepresentable === "throw") {
|
|
47431
|
+
throw new Error("Literal `undefined` cannot be represented in JSON Schema");
|
|
47432
|
+
} else {}
|
|
47433
|
+
} else if (typeof val === "bigint") {
|
|
47434
|
+
if (ctx.unrepresentable === "throw") {
|
|
47435
|
+
throw new Error("BigInt literals cannot be represented in JSON Schema");
|
|
47436
|
+
} else {
|
|
47437
|
+
vals.push(Number(val));
|
|
47438
|
+
}
|
|
47439
|
+
} else {
|
|
47440
|
+
vals.push(val);
|
|
47441
|
+
}
|
|
47442
|
+
}
|
|
47443
|
+
if (vals.length === 0) {} else if (vals.length === 1) {
|
|
47444
|
+
const val = vals[0];
|
|
47445
|
+
json.type = val === null ? "null" : typeof val;
|
|
47446
|
+
if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
|
|
47447
|
+
json.enum = [val];
|
|
47448
|
+
} else {
|
|
47449
|
+
json.const = val;
|
|
47450
|
+
}
|
|
47451
|
+
} else {
|
|
47452
|
+
if (vals.every((v) => typeof v === "number"))
|
|
47453
|
+
json.type = "number";
|
|
47454
|
+
if (vals.every((v) => typeof v === "string"))
|
|
47455
|
+
json.type = "string";
|
|
47456
|
+
if (vals.every((v) => typeof v === "boolean"))
|
|
47457
|
+
json.type = "boolean";
|
|
47458
|
+
if (vals.every((v) => v === null))
|
|
47459
|
+
json.type = "null";
|
|
47460
|
+
json.enum = vals;
|
|
47461
|
+
}
|
|
47462
|
+
};
|
|
47463
|
+
var nanProcessor = (_schema, ctx, _json, _params) => {
|
|
47464
|
+
if (ctx.unrepresentable === "throw") {
|
|
47465
|
+
throw new Error("NaN cannot be represented in JSON Schema");
|
|
47466
|
+
}
|
|
47467
|
+
};
|
|
47468
|
+
var templateLiteralProcessor = (schema, _ctx, json, _params) => {
|
|
47469
|
+
const _json = json;
|
|
47470
|
+
const pattern = schema._zod.pattern;
|
|
47471
|
+
if (!pattern)
|
|
47472
|
+
throw new Error("Pattern not found in template literal");
|
|
47473
|
+
_json.type = "string";
|
|
47474
|
+
_json.pattern = pattern.source;
|
|
47475
|
+
};
|
|
47476
|
+
var fileProcessor = (schema, _ctx, json, _params) => {
|
|
47477
|
+
const _json = json;
|
|
47478
|
+
const file = {
|
|
47479
|
+
type: "string",
|
|
47480
|
+
format: "binary",
|
|
47481
|
+
contentEncoding: "binary"
|
|
47482
|
+
};
|
|
47483
|
+
const { minimum, maximum, mime } = schema._zod.bag;
|
|
47484
|
+
if (minimum !== undefined)
|
|
47485
|
+
file.minLength = minimum;
|
|
47486
|
+
if (maximum !== undefined)
|
|
47487
|
+
file.maxLength = maximum;
|
|
47488
|
+
if (mime) {
|
|
47489
|
+
if (mime.length === 1) {
|
|
47490
|
+
file.contentMediaType = mime[0];
|
|
47491
|
+
Object.assign(_json, file);
|
|
47492
|
+
} else {
|
|
47493
|
+
Object.assign(_json, file);
|
|
47494
|
+
_json.anyOf = mime.map((m) => ({ contentMediaType: m }));
|
|
47495
|
+
}
|
|
47496
|
+
} else {
|
|
47497
|
+
Object.assign(_json, file);
|
|
47498
|
+
}
|
|
47499
|
+
};
|
|
47500
|
+
var successProcessor = (_schema, _ctx, json, _params) => {
|
|
47501
|
+
json.type = "boolean";
|
|
47502
|
+
};
|
|
47333
47503
|
var customProcessor = (_schema, ctx, _json, _params) => {
|
|
47334
47504
|
if (ctx.unrepresentable === "throw") {
|
|
47335
47505
|
throw new Error("Custom types cannot be represented in JSON Schema");
|
|
47336
47506
|
}
|
|
47337
47507
|
};
|
|
47508
|
+
var functionProcessor = (_schema, ctx, _json, _params) => {
|
|
47509
|
+
if (ctx.unrepresentable === "throw") {
|
|
47510
|
+
throw new Error("Function types cannot be represented in JSON Schema");
|
|
47511
|
+
}
|
|
47512
|
+
};
|
|
47338
47513
|
var transformProcessor = (_schema, ctx, _json, _params) => {
|
|
47339
47514
|
if (ctx.unrepresentable === "throw") {
|
|
47340
47515
|
throw new Error("Transforms cannot be represented in JSON Schema");
|
|
47341
47516
|
}
|
|
47342
47517
|
};
|
|
47518
|
+
var mapProcessor = (_schema, ctx, _json, _params) => {
|
|
47519
|
+
if (ctx.unrepresentable === "throw") {
|
|
47520
|
+
throw new Error("Map cannot be represented in JSON Schema");
|
|
47521
|
+
}
|
|
47522
|
+
};
|
|
47523
|
+
var setProcessor = (_schema, ctx, _json, _params) => {
|
|
47524
|
+
if (ctx.unrepresentable === "throw") {
|
|
47525
|
+
throw new Error("Set cannot be represented in JSON Schema");
|
|
47526
|
+
}
|
|
47527
|
+
};
|
|
47343
47528
|
var arrayProcessor = (schema, ctx, _json, params) => {
|
|
47344
47529
|
const json = _json;
|
|
47345
47530
|
const def = schema._zod.def;
|
|
@@ -47417,6 +47602,84 @@ var intersectionProcessor = (schema, ctx, json, params) => {
|
|
|
47417
47602
|
];
|
|
47418
47603
|
json.allOf = allOf;
|
|
47419
47604
|
};
|
|
47605
|
+
var tupleProcessor = (schema, ctx, _json, params) => {
|
|
47606
|
+
const json = _json;
|
|
47607
|
+
const def = schema._zod.def;
|
|
47608
|
+
json.type = "array";
|
|
47609
|
+
const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
|
|
47610
|
+
const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
|
|
47611
|
+
const prefixItems = def.items.map((x, i) => process2(x, ctx, {
|
|
47612
|
+
...params,
|
|
47613
|
+
path: [...params.path, prefixPath, i]
|
|
47614
|
+
}));
|
|
47615
|
+
const rest = def.rest ? process2(def.rest, ctx, {
|
|
47616
|
+
...params,
|
|
47617
|
+
path: [...params.path, restPath, ...ctx.target === "openapi-3.0" ? [def.items.length] : []]
|
|
47618
|
+
}) : null;
|
|
47619
|
+
if (ctx.target === "draft-2020-12") {
|
|
47620
|
+
json.prefixItems = prefixItems;
|
|
47621
|
+
if (rest) {
|
|
47622
|
+
json.items = rest;
|
|
47623
|
+
}
|
|
47624
|
+
} else if (ctx.target === "openapi-3.0") {
|
|
47625
|
+
json.items = {
|
|
47626
|
+
anyOf: prefixItems
|
|
47627
|
+
};
|
|
47628
|
+
if (rest) {
|
|
47629
|
+
json.items.anyOf.push(rest);
|
|
47630
|
+
}
|
|
47631
|
+
json.minItems = prefixItems.length;
|
|
47632
|
+
if (!rest) {
|
|
47633
|
+
json.maxItems = prefixItems.length;
|
|
47634
|
+
}
|
|
47635
|
+
} else {
|
|
47636
|
+
json.items = prefixItems;
|
|
47637
|
+
if (rest) {
|
|
47638
|
+
json.additionalItems = rest;
|
|
47639
|
+
}
|
|
47640
|
+
}
|
|
47641
|
+
const { minimum, maximum } = schema._zod.bag;
|
|
47642
|
+
if (typeof minimum === "number")
|
|
47643
|
+
json.minItems = minimum;
|
|
47644
|
+
if (typeof maximum === "number")
|
|
47645
|
+
json.maxItems = maximum;
|
|
47646
|
+
};
|
|
47647
|
+
var recordProcessor = (schema, ctx, _json, params) => {
|
|
47648
|
+
const json = _json;
|
|
47649
|
+
const def = schema._zod.def;
|
|
47650
|
+
json.type = "object";
|
|
47651
|
+
const keyType = def.keyType;
|
|
47652
|
+
const keyBag = keyType._zod.bag;
|
|
47653
|
+
const patterns = keyBag?.patterns;
|
|
47654
|
+
if (def.mode === "loose" && patterns && patterns.size > 0) {
|
|
47655
|
+
const valueSchema = process2(def.valueType, ctx, {
|
|
47656
|
+
...params,
|
|
47657
|
+
path: [...params.path, "patternProperties", "*"]
|
|
47658
|
+
});
|
|
47659
|
+
json.patternProperties = {};
|
|
47660
|
+
for (const pattern of patterns) {
|
|
47661
|
+
json.patternProperties[pattern.source] = valueSchema;
|
|
47662
|
+
}
|
|
47663
|
+
} else {
|
|
47664
|
+
if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
|
|
47665
|
+
json.propertyNames = process2(def.keyType, ctx, {
|
|
47666
|
+
...params,
|
|
47667
|
+
path: [...params.path, "propertyNames"]
|
|
47668
|
+
});
|
|
47669
|
+
}
|
|
47670
|
+
json.additionalProperties = process2(def.valueType, ctx, {
|
|
47671
|
+
...params,
|
|
47672
|
+
path: [...params.path, "additionalProperties"]
|
|
47673
|
+
});
|
|
47674
|
+
}
|
|
47675
|
+
const keyValues = keyType._zod.values;
|
|
47676
|
+
if (keyValues) {
|
|
47677
|
+
const validKeyValues = [...keyValues].filter((v) => typeof v === "string" || typeof v === "number");
|
|
47678
|
+
if (validKeyValues.length > 0) {
|
|
47679
|
+
json.required = validKeyValues;
|
|
47680
|
+
}
|
|
47681
|
+
}
|
|
47682
|
+
};
|
|
47420
47683
|
var nullableProcessor = (schema, ctx, json, params) => {
|
|
47421
47684
|
const def = schema._zod.def;
|
|
47422
47685
|
const inner = process2(def.innerType, ctx, params);
|
|
@@ -47476,12 +47739,99 @@ var readonlyProcessor = (schema, ctx, json, params) => {
|
|
|
47476
47739
|
seen.ref = def.innerType;
|
|
47477
47740
|
json.readOnly = true;
|
|
47478
47741
|
};
|
|
47742
|
+
var promiseProcessor = (schema, ctx, _json, params) => {
|
|
47743
|
+
const def = schema._zod.def;
|
|
47744
|
+
process2(def.innerType, ctx, params);
|
|
47745
|
+
const seen = ctx.seen.get(schema);
|
|
47746
|
+
seen.ref = def.innerType;
|
|
47747
|
+
};
|
|
47479
47748
|
var optionalProcessor = (schema, ctx, _json, params) => {
|
|
47480
47749
|
const def = schema._zod.def;
|
|
47481
47750
|
process2(def.innerType, ctx, params);
|
|
47482
47751
|
const seen = ctx.seen.get(schema);
|
|
47483
47752
|
seen.ref = def.innerType;
|
|
47484
47753
|
};
|
|
47754
|
+
var lazyProcessor = (schema, ctx, _json, params) => {
|
|
47755
|
+
const innerType = schema._zod.innerType;
|
|
47756
|
+
process2(innerType, ctx, params);
|
|
47757
|
+
const seen = ctx.seen.get(schema);
|
|
47758
|
+
seen.ref = innerType;
|
|
47759
|
+
};
|
|
47760
|
+
var allProcessors = {
|
|
47761
|
+
string: stringProcessor,
|
|
47762
|
+
number: numberProcessor,
|
|
47763
|
+
boolean: booleanProcessor,
|
|
47764
|
+
bigint: bigintProcessor,
|
|
47765
|
+
symbol: symbolProcessor,
|
|
47766
|
+
null: nullProcessor,
|
|
47767
|
+
undefined: undefinedProcessor,
|
|
47768
|
+
void: voidProcessor,
|
|
47769
|
+
never: neverProcessor,
|
|
47770
|
+
any: anyProcessor,
|
|
47771
|
+
unknown: unknownProcessor,
|
|
47772
|
+
date: dateProcessor,
|
|
47773
|
+
enum: enumProcessor,
|
|
47774
|
+
literal: literalProcessor,
|
|
47775
|
+
nan: nanProcessor,
|
|
47776
|
+
template_literal: templateLiteralProcessor,
|
|
47777
|
+
file: fileProcessor,
|
|
47778
|
+
success: successProcessor,
|
|
47779
|
+
custom: customProcessor,
|
|
47780
|
+
function: functionProcessor,
|
|
47781
|
+
transform: transformProcessor,
|
|
47782
|
+
map: mapProcessor,
|
|
47783
|
+
set: setProcessor,
|
|
47784
|
+
array: arrayProcessor,
|
|
47785
|
+
object: objectProcessor,
|
|
47786
|
+
union: unionProcessor,
|
|
47787
|
+
intersection: intersectionProcessor,
|
|
47788
|
+
tuple: tupleProcessor,
|
|
47789
|
+
record: recordProcessor,
|
|
47790
|
+
nullable: nullableProcessor,
|
|
47791
|
+
nonoptional: nonoptionalProcessor,
|
|
47792
|
+
default: defaultProcessor,
|
|
47793
|
+
prefault: prefaultProcessor,
|
|
47794
|
+
catch: catchProcessor,
|
|
47795
|
+
pipe: pipeProcessor,
|
|
47796
|
+
readonly: readonlyProcessor,
|
|
47797
|
+
promise: promiseProcessor,
|
|
47798
|
+
optional: optionalProcessor,
|
|
47799
|
+
lazy: lazyProcessor
|
|
47800
|
+
};
|
|
47801
|
+
function toJSONSchema(input, params) {
|
|
47802
|
+
if ("_idmap" in input) {
|
|
47803
|
+
const registry2 = input;
|
|
47804
|
+
const ctx2 = initializeContext({ ...params, processors: allProcessors });
|
|
47805
|
+
const defs = {};
|
|
47806
|
+
for (const entry of registry2._idmap.entries()) {
|
|
47807
|
+
const [_, schema] = entry;
|
|
47808
|
+
process2(schema, ctx2);
|
|
47809
|
+
}
|
|
47810
|
+
const schemas = {};
|
|
47811
|
+
const external = {
|
|
47812
|
+
registry: registry2,
|
|
47813
|
+
uri: params?.uri,
|
|
47814
|
+
defs
|
|
47815
|
+
};
|
|
47816
|
+
ctx2.external = external;
|
|
47817
|
+
for (const entry of registry2._idmap.entries()) {
|
|
47818
|
+
const [key, schema] = entry;
|
|
47819
|
+
extractDefs(ctx2, schema);
|
|
47820
|
+
schemas[key] = finalize(ctx2, schema);
|
|
47821
|
+
}
|
|
47822
|
+
if (Object.keys(defs).length > 0) {
|
|
47823
|
+
const defsSegment = ctx2.target === "draft-2020-12" ? "$defs" : "definitions";
|
|
47824
|
+
schemas.__shared = {
|
|
47825
|
+
[defsSegment]: defs
|
|
47826
|
+
};
|
|
47827
|
+
}
|
|
47828
|
+
return { schemas };
|
|
47829
|
+
}
|
|
47830
|
+
const ctx = initializeContext({ ...params, processors: allProcessors });
|
|
47831
|
+
process2(input, ctx);
|
|
47832
|
+
extractDefs(ctx, input);
|
|
47833
|
+
return finalize(ctx, input);
|
|
47834
|
+
}
|
|
47485
47835
|
// ../../node_modules/zod/v4/classic/iso.js
|
|
47486
47836
|
var ZodISODateTime = /* @__PURE__ */ $constructor("ZodISODateTime", (inst, def) => {
|
|
47487
47837
|
$ZodISODateTime.init(inst, def);
|
|
@@ -48154,6 +48504,7 @@ function resolveRedactionOptions(options) {
|
|
|
48154
48504
|
class ToolCallSpan {
|
|
48155
48505
|
adapter;
|
|
48156
48506
|
toolCall;
|
|
48507
|
+
friskToolId;
|
|
48157
48508
|
agentState;
|
|
48158
48509
|
parent;
|
|
48159
48510
|
tracer;
|
|
@@ -48162,10 +48513,13 @@ class ToolCallSpan {
|
|
|
48162
48513
|
_startTimeNs = null;
|
|
48163
48514
|
_traceContextCarrier = null;
|
|
48164
48515
|
sessionId;
|
|
48516
|
+
friskToolVersionId;
|
|
48165
48517
|
constructor({
|
|
48166
48518
|
sessionId,
|
|
48167
48519
|
adapter,
|
|
48168
48520
|
toolCall,
|
|
48521
|
+
friskToolId,
|
|
48522
|
+
friskToolVersionId,
|
|
48169
48523
|
agentState,
|
|
48170
48524
|
parent,
|
|
48171
48525
|
tracer,
|
|
@@ -48174,6 +48528,8 @@ class ToolCallSpan {
|
|
|
48174
48528
|
this.sessionId = sessionId;
|
|
48175
48529
|
this.adapter = adapter;
|
|
48176
48530
|
this.toolCall = toolCall;
|
|
48531
|
+
this.friskToolId = friskToolId ?? null;
|
|
48532
|
+
this.friskToolVersionId = friskToolVersionId ?? null;
|
|
48177
48533
|
this.agentState = agentState;
|
|
48178
48534
|
this.parent = parent;
|
|
48179
48535
|
this.tracer = tracer;
|
|
@@ -48242,6 +48598,10 @@ class ToolCallSpan {
|
|
|
48242
48598
|
attributes: {
|
|
48243
48599
|
[ATTRIBUTE_NAME_SESSION_ID]: this.sessionId,
|
|
48244
48600
|
[ATTRIBUTE_NAME_TOOL_NAME]: this.toolCall.name,
|
|
48601
|
+
...this.friskToolId !== null ? { [ATTRIBUTE_NAME_FRISK_TOOL_ID]: this.friskToolId } : {},
|
|
48602
|
+
...this.friskToolVersionId !== null ? {
|
|
48603
|
+
[ATTRIBUTE_NAME_FRISK_TOOL_VERSION_ID]: this.friskToolVersionId
|
|
48604
|
+
} : {},
|
|
48245
48605
|
[ATTRIBUTE_NAME_TOOL_CALL_ID]: this.toolCall.id,
|
|
48246
48606
|
[ATTRIBUTE_NAME_TOOL_ARGS_JSON]: redactedToolArgsResult.value ?? "",
|
|
48247
48607
|
[ATTRIBUTE_NAME_TOOL_ARGS_REDACTED_PATHS_JSON]: JSON.stringify(redactedToolArgsResult.redactedPaths),
|
|
@@ -48279,7 +48639,7 @@ var DecisionOutcome;
|
|
|
48279
48639
|
class FriskSession {
|
|
48280
48640
|
frisk;
|
|
48281
48641
|
id;
|
|
48282
|
-
|
|
48642
|
+
_rootSpan = null;
|
|
48283
48643
|
redaction;
|
|
48284
48644
|
tracer;
|
|
48285
48645
|
logger;
|
|
@@ -48295,6 +48655,12 @@ class FriskSession {
|
|
|
48295
48655
|
this.redaction = redact;
|
|
48296
48656
|
this.tracer = tracer;
|
|
48297
48657
|
}
|
|
48658
|
+
get rootSpan() {
|
|
48659
|
+
return this._rootSpan;
|
|
48660
|
+
}
|
|
48661
|
+
getTracer() {
|
|
48662
|
+
return this.tracer;
|
|
48663
|
+
}
|
|
48298
48664
|
get isTracing() {
|
|
48299
48665
|
return this._isTracing;
|
|
48300
48666
|
}
|
|
@@ -48305,12 +48671,15 @@ class FriskSession {
|
|
|
48305
48671
|
toolCall,
|
|
48306
48672
|
agentState
|
|
48307
48673
|
}) {
|
|
48674
|
+
const registeredTool = this.frisk.getRegisteredTool(toolCall.name);
|
|
48308
48675
|
const toolCallSpan = new ToolCallSpan({
|
|
48309
48676
|
sessionId: this.id,
|
|
48310
48677
|
adapter: this.frisk.adapter,
|
|
48311
48678
|
toolCall,
|
|
48679
|
+
friskToolId: registeredTool?.id ?? null,
|
|
48680
|
+
friskToolVersionId: registeredTool?.versionId ?? null,
|
|
48312
48681
|
agentState,
|
|
48313
|
-
parent: this.
|
|
48682
|
+
parent: this._rootSpan,
|
|
48314
48683
|
tracer: this.tracer,
|
|
48315
48684
|
redact: this.redaction
|
|
48316
48685
|
});
|
|
@@ -48368,21 +48737,139 @@ class FriskSession {
|
|
|
48368
48737
|
return span;
|
|
48369
48738
|
}
|
|
48370
48739
|
endTracing() {
|
|
48371
|
-
if (this.
|
|
48372
|
-
this.
|
|
48740
|
+
if (this._rootSpan) {
|
|
48741
|
+
this._rootSpan.end();
|
|
48373
48742
|
}
|
|
48374
48743
|
this._isTracing = false;
|
|
48375
48744
|
const registry2 = SessionRegistry.getInstance();
|
|
48376
48745
|
registry2.unregister(this.id);
|
|
48377
48746
|
}
|
|
48378
48747
|
setRootSpan(span) {
|
|
48379
|
-
this.
|
|
48748
|
+
this._rootSpan = span;
|
|
48380
48749
|
}
|
|
48381
48750
|
static generateSessionId() {
|
|
48382
48751
|
return v4();
|
|
48383
48752
|
}
|
|
48384
48753
|
}
|
|
48385
48754
|
|
|
48755
|
+
// src/core/sdk-attributes/detect-runtime.ts
|
|
48756
|
+
function detectRuntime() {
|
|
48757
|
+
const g = globalThis;
|
|
48758
|
+
if (g.Bun) {
|
|
48759
|
+
return {
|
|
48760
|
+
runtime: "bun",
|
|
48761
|
+
runtimeVersion: g.Bun.version
|
|
48762
|
+
};
|
|
48763
|
+
}
|
|
48764
|
+
if (g.Deno) {
|
|
48765
|
+
return {
|
|
48766
|
+
runtime: "deno",
|
|
48767
|
+
runtimeVersion: g.Deno.version.deno
|
|
48768
|
+
};
|
|
48769
|
+
}
|
|
48770
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
48771
|
+
return {
|
|
48772
|
+
runtime: "node",
|
|
48773
|
+
runtimeVersion: process.versions.node
|
|
48774
|
+
};
|
|
48775
|
+
}
|
|
48776
|
+
if (typeof navigator !== "undefined") {
|
|
48777
|
+
return {
|
|
48778
|
+
runtime: "browser",
|
|
48779
|
+
runtimeVersion: navigator.userAgent
|
|
48780
|
+
};
|
|
48781
|
+
}
|
|
48782
|
+
return {
|
|
48783
|
+
runtime: "unknown",
|
|
48784
|
+
runtimeVersion: "unknown"
|
|
48785
|
+
};
|
|
48786
|
+
}
|
|
48787
|
+
|
|
48788
|
+
// src/core/sdk-attributes/read-sdk-meta.ts
|
|
48789
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
48790
|
+
import { dirname as dirname2, join } from "node:path";
|
|
48791
|
+
import { fileURLToPath } from "node:url";
|
|
48792
|
+
|
|
48793
|
+
// src/generated/sdk-meta.ts
|
|
48794
|
+
var SDK_NAME = "@friskai/frisk-js";
|
|
48795
|
+
var SDK_VERSION = "0.2.8";
|
|
48796
|
+
|
|
48797
|
+
// src/core/sdk-attributes/read-sdk-meta.ts
|
|
48798
|
+
function getSdkMeta() {
|
|
48799
|
+
if (isNonEmptyString(SDK_NAME) && isNonEmptyString(SDK_VERSION)) {
|
|
48800
|
+
return {
|
|
48801
|
+
sdkName: SDK_NAME,
|
|
48802
|
+
sdkVersion: SDK_VERSION,
|
|
48803
|
+
source: "injected"
|
|
48804
|
+
};
|
|
48805
|
+
}
|
|
48806
|
+
const fromPkg = tryReadPackageJson();
|
|
48807
|
+
if (fromPkg) {
|
|
48808
|
+
return {
|
|
48809
|
+
...fromPkg,
|
|
48810
|
+
source: "package.json"
|
|
48811
|
+
};
|
|
48812
|
+
}
|
|
48813
|
+
return {
|
|
48814
|
+
sdkName: "unknown",
|
|
48815
|
+
sdkVersion: "unknown",
|
|
48816
|
+
source: "unknown"
|
|
48817
|
+
};
|
|
48818
|
+
}
|
|
48819
|
+
function isNonEmptyString(value) {
|
|
48820
|
+
return typeof value === "string" && value.length > 0;
|
|
48821
|
+
}
|
|
48822
|
+
function findNearestPackageJson(startDir) {
|
|
48823
|
+
let dir = startDir;
|
|
48824
|
+
while (true) {
|
|
48825
|
+
const candidate = join(dir, "package.json");
|
|
48826
|
+
if (existsSync(candidate)) {
|
|
48827
|
+
return candidate;
|
|
48828
|
+
}
|
|
48829
|
+
const parent = dirname2(dir);
|
|
48830
|
+
if (parent === dir) {
|
|
48831
|
+
return null;
|
|
48832
|
+
}
|
|
48833
|
+
dir = parent;
|
|
48834
|
+
}
|
|
48835
|
+
}
|
|
48836
|
+
function tryReadPackageJson() {
|
|
48837
|
+
try {
|
|
48838
|
+
const here = dirname2(fileURLToPath(import.meta.url));
|
|
48839
|
+
const pkgPath = findNearestPackageJson(here);
|
|
48840
|
+
if (!pkgPath)
|
|
48841
|
+
return null;
|
|
48842
|
+
const raw = readFileSync(pkgPath, "utf8");
|
|
48843
|
+
const pkg = JSON.parse(raw);
|
|
48844
|
+
if (!isNonEmptyString(pkg.name) || !isNonEmptyString(pkg.version)) {
|
|
48845
|
+
return null;
|
|
48846
|
+
}
|
|
48847
|
+
return {
|
|
48848
|
+
sdkName: pkg.name,
|
|
48849
|
+
sdkVersion: pkg.version
|
|
48850
|
+
};
|
|
48851
|
+
} catch {
|
|
48852
|
+
return null;
|
|
48853
|
+
}
|
|
48854
|
+
}
|
|
48855
|
+
|
|
48856
|
+
// src/core/sdk-attributes/get-core-sdk-attributes.ts
|
|
48857
|
+
var coreSdkAttributes = null;
|
|
48858
|
+
function getCoreSdkAttributes() {
|
|
48859
|
+
if (!coreSdkAttributes) {
|
|
48860
|
+
const { sdkName, sdkVersion } = getSdkMeta();
|
|
48861
|
+
const { runtime, runtimeVersion } = detectRuntime();
|
|
48862
|
+
coreSdkAttributes = {
|
|
48863
|
+
version: sdkVersion,
|
|
48864
|
+
language: "js",
|
|
48865
|
+
name: sdkName,
|
|
48866
|
+
runtime,
|
|
48867
|
+
runtimeVersion
|
|
48868
|
+
};
|
|
48869
|
+
}
|
|
48870
|
+
return coreSdkAttributes;
|
|
48871
|
+
}
|
|
48872
|
+
|
|
48386
48873
|
// src/core/tool-approval-request.ts
|
|
48387
48874
|
var REQUEST_TIMEOUT_MS = 1e4;
|
|
48388
48875
|
var logger = deriveSdkLogger(undefined, {
|
|
@@ -48492,6 +48979,8 @@ async function safeReadErrorBody(response) {
|
|
|
48492
48979
|
async function getOrCreateToolApprovalRequest({
|
|
48493
48980
|
toolCallId,
|
|
48494
48981
|
toolName,
|
|
48982
|
+
toolId,
|
|
48983
|
+
toolVersionId,
|
|
48495
48984
|
policyId,
|
|
48496
48985
|
policyVersionId,
|
|
48497
48986
|
sessionId,
|
|
@@ -48504,7 +48993,9 @@ async function getOrCreateToolApprovalRequest({
|
|
|
48504
48993
|
policyId,
|
|
48505
48994
|
policyVersionId,
|
|
48506
48995
|
sessionId,
|
|
48507
|
-
toolName
|
|
48996
|
+
toolName,
|
|
48997
|
+
...toolId == null ? {} : { toolId },
|
|
48998
|
+
...toolVersionId == null ? {} : { toolVersionId }
|
|
48508
48999
|
};
|
|
48509
49000
|
try {
|
|
48510
49001
|
logger.debug?.(`Creating tool approval request for tool call ${toolCallId}`);
|
|
@@ -48537,7 +49028,9 @@ async function getOrCreateManyToolApprovalRequests({
|
|
|
48537
49028
|
toolCallId: input.toolCallId,
|
|
48538
49029
|
policyId: input.policyId,
|
|
48539
49030
|
policyVersionId: input.policyVersionId,
|
|
48540
|
-
toolName: input.toolName
|
|
49031
|
+
toolName: input.toolName,
|
|
49032
|
+
toolId: input.toolId ?? null,
|
|
49033
|
+
toolVersionId: input.toolVersionId ?? null
|
|
48541
49034
|
})),
|
|
48542
49035
|
agentId: "unknown",
|
|
48543
49036
|
organizationId: "unknown",
|
|
@@ -48615,19 +49108,127 @@ async function cancelManyToolApprovalRequests({
|
|
|
48615
49108
|
}
|
|
48616
49109
|
}
|
|
48617
49110
|
|
|
49111
|
+
// src/core/tool-registry.ts
|
|
49112
|
+
function buildRegisterToolsEndpoint(apiBaseUrl) {
|
|
49113
|
+
return new URL("/tool-registry/register-tools", apiBaseUrl).toString();
|
|
49114
|
+
}
|
|
49115
|
+
function parseRegisterToolsResponse(responseJson) {
|
|
49116
|
+
if (!Array.isArray(responseJson)) {
|
|
49117
|
+
throw new TypeError("registerTools response must be an array");
|
|
49118
|
+
}
|
|
49119
|
+
const toolNameToId = {};
|
|
49120
|
+
for (const [index, item] of responseJson.entries()) {
|
|
49121
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
49122
|
+
throw new TypeError(`registerTools response item at index ${index} must be an object`);
|
|
49123
|
+
}
|
|
49124
|
+
const { id: toolId, name: toolName } = item;
|
|
49125
|
+
if (typeof toolId !== "string" || toolId.length === 0) {
|
|
49126
|
+
throw new TypeError(`registerTools response item at index ${index} is missing a valid id`);
|
|
49127
|
+
}
|
|
49128
|
+
if (typeof toolName !== "string" || toolName.length === 0) {
|
|
49129
|
+
throw new TypeError(`registerTools response item at index ${index} is missing a valid name`);
|
|
49130
|
+
}
|
|
49131
|
+
toolNameToId[toolName] = item;
|
|
49132
|
+
}
|
|
49133
|
+
return toolNameToId;
|
|
49134
|
+
}
|
|
49135
|
+
|
|
49136
|
+
class ToolRegistry {
|
|
49137
|
+
initialized = Promise.resolve(true);
|
|
49138
|
+
apiBaseUrl;
|
|
49139
|
+
getAccessToken;
|
|
49140
|
+
logger;
|
|
49141
|
+
toolNameToId = new Map;
|
|
49142
|
+
constructor({ apiBaseUrl, getAccessToken, logger: logger2 }) {
|
|
49143
|
+
this.apiBaseUrl = apiBaseUrl;
|
|
49144
|
+
this.getAccessToken = getAccessToken;
|
|
49145
|
+
this.logger = logger2;
|
|
49146
|
+
}
|
|
49147
|
+
getRegisteredTool(toolName) {
|
|
49148
|
+
return this.toolNameToId.get(toolName) ?? null;
|
|
49149
|
+
}
|
|
49150
|
+
registerTools({
|
|
49151
|
+
tools,
|
|
49152
|
+
sdkAttributes
|
|
49153
|
+
}) {
|
|
49154
|
+
const toolsList = [...tools];
|
|
49155
|
+
if (toolsList.length === 0 && !sdkAttributes) {
|
|
49156
|
+
this.initialized = Promise.resolve(true);
|
|
49157
|
+
return;
|
|
49158
|
+
}
|
|
49159
|
+
this.initialized = this.executeRegisterTools({
|
|
49160
|
+
tools: toolsList,
|
|
49161
|
+
sdkAttributes
|
|
49162
|
+
});
|
|
49163
|
+
this.initialized;
|
|
49164
|
+
}
|
|
49165
|
+
async executeRegisterTools({
|
|
49166
|
+
tools,
|
|
49167
|
+
sdkAttributes
|
|
49168
|
+
}) {
|
|
49169
|
+
try {
|
|
49170
|
+
const accessToken = await this.getAccessToken();
|
|
49171
|
+
const response = await fetch(buildRegisterToolsEndpoint(this.apiBaseUrl), {
|
|
49172
|
+
method: "POST",
|
|
49173
|
+
headers: {
|
|
49174
|
+
Authorization: `Bearer ${accessToken}`,
|
|
49175
|
+
"Content-Type": "application/json"
|
|
49176
|
+
},
|
|
49177
|
+
body: JSON.stringify({
|
|
49178
|
+
properties: tools.map((property) => ({
|
|
49179
|
+
name: property.name,
|
|
49180
|
+
description: property.description,
|
|
49181
|
+
inputJsonSchema: property.inputJsonSchema,
|
|
49182
|
+
outputJsonSchema: property.outputJsonSchema,
|
|
49183
|
+
responseFormat: property.responseFormat
|
|
49184
|
+
})),
|
|
49185
|
+
sdk: sdkAttributes
|
|
49186
|
+
})
|
|
49187
|
+
});
|
|
49188
|
+
if (!response.ok) {
|
|
49189
|
+
this.logger?.error?.(`Failed to register tools: HTTP ${response.status} ${await response.text()}`);
|
|
49190
|
+
return true;
|
|
49191
|
+
}
|
|
49192
|
+
const responseJson = await response.json();
|
|
49193
|
+
const registerToolsResponse = parseRegisterToolsResponse(responseJson);
|
|
49194
|
+
for (const [toolName, tool] of Object.entries(registerToolsResponse)) {
|
|
49195
|
+
this.toolNameToId.set(toolName, tool);
|
|
49196
|
+
}
|
|
49197
|
+
} catch (error) {
|
|
49198
|
+
this.logger?.error?.(`Failed to register tools: ${error instanceof Error ? error.message : String(error)}`);
|
|
49199
|
+
}
|
|
49200
|
+
return true;
|
|
49201
|
+
}
|
|
49202
|
+
}
|
|
49203
|
+
|
|
48618
49204
|
// src/core/frisk.ts
|
|
48619
49205
|
class Frisk {
|
|
48620
|
-
redaction
|
|
49206
|
+
get redaction() {
|
|
49207
|
+
return this._redaction;
|
|
49208
|
+
}
|
|
49209
|
+
_redaction;
|
|
48621
49210
|
apiBaseUrl;
|
|
48622
49211
|
otlpEndpoint;
|
|
48623
49212
|
accessTokenProvider;
|
|
48624
49213
|
initialized = false;
|
|
48625
49214
|
rootLogger;
|
|
48626
49215
|
logger;
|
|
48627
|
-
|
|
49216
|
+
_logLevel;
|
|
48628
49217
|
_adapter;
|
|
48629
49218
|
_friskHandle = null;
|
|
48630
49219
|
_tracingManager = null;
|
|
49220
|
+
_toolRegistry;
|
|
49221
|
+
sdkAttributes;
|
|
49222
|
+
wrapToolsCalled = false;
|
|
49223
|
+
get toolRegistrationComplete() {
|
|
49224
|
+
if (!this.wrapToolsCalled) {
|
|
49225
|
+
return Promise.resolve(true);
|
|
49226
|
+
}
|
|
49227
|
+
return this._toolRegistry.initialized;
|
|
49228
|
+
}
|
|
49229
|
+
get logLevel() {
|
|
49230
|
+
return this._logLevel;
|
|
49231
|
+
}
|
|
48631
49232
|
static async connect(options) {
|
|
48632
49233
|
const instance = new this(options);
|
|
48633
49234
|
await instance.connect();
|
|
@@ -48637,13 +49238,15 @@ class Frisk {
|
|
|
48637
49238
|
this.rootLogger = deriveSdkLogger(options?.logging, {
|
|
48638
49239
|
sdk: "frisk"
|
|
48639
49240
|
});
|
|
48640
|
-
this.
|
|
49241
|
+
this._logLevel = options?.logging?.logLevel;
|
|
48641
49242
|
this.logger = deriveSdkLogger({
|
|
48642
49243
|
logger: this.rootLogger,
|
|
48643
|
-
logLevel: this.
|
|
49244
|
+
logLevel: this._logLevel
|
|
48644
49245
|
}, {
|
|
48645
49246
|
component: "FriskCore"
|
|
48646
49247
|
});
|
|
49248
|
+
this._adapter = options?.adapter ?? new BaseFrameworkAdapter;
|
|
49249
|
+
this.sdkAttributes = this.getSdkAttributes();
|
|
48647
49250
|
const apiKey = options?.apiKey ?? getEnv(FRISK_API_KEY);
|
|
48648
49251
|
if (!apiKey) {
|
|
48649
49252
|
throw new MissingAPIKeyError;
|
|
@@ -48658,16 +49261,20 @@ class Frisk {
|
|
|
48658
49261
|
baseUrl,
|
|
48659
49262
|
logging: {
|
|
48660
49263
|
logger: this.rootLogger,
|
|
48661
|
-
logLevel: this.
|
|
49264
|
+
logLevel: this._logLevel
|
|
48662
49265
|
}
|
|
48663
49266
|
});
|
|
49267
|
+
this._toolRegistry = new ToolRegistry({
|
|
49268
|
+
apiBaseUrl: baseUrl,
|
|
49269
|
+
getAccessToken: async () => this.accessTokenProvider.getAccessToken(),
|
|
49270
|
+
logger: this.logger
|
|
49271
|
+
});
|
|
48664
49272
|
const otlpEndpoint = options?.otlpEndpoint ?? getEnv(FRISK_TELEMETRY_ENDPOINT, FRISK_TELEMETRY_ENDPOINT_DEFAULT);
|
|
48665
49273
|
if (!otlpEndpoint) {
|
|
48666
49274
|
throw new MissingOtlpEndpointError;
|
|
48667
49275
|
}
|
|
48668
49276
|
this.otlpEndpoint = otlpEndpoint;
|
|
48669
|
-
this.
|
|
48670
|
-
this._adapter = options?.adapter ?? new BaseFrameworkAdapter;
|
|
49277
|
+
this._redaction = resolveRedactionOptions(options?.redact);
|
|
48671
49278
|
}
|
|
48672
49279
|
get friskHandle() {
|
|
48673
49280
|
if (!this._friskHandle) {
|
|
@@ -48705,11 +49312,11 @@ class Frisk {
|
|
|
48705
49312
|
session(metadata) {
|
|
48706
49313
|
const session = new FriskSession({
|
|
48707
49314
|
frisk: this,
|
|
48708
|
-
redact: this.
|
|
49315
|
+
redact: this._redaction,
|
|
48709
49316
|
tracer: this.tracingManager.getTracer(),
|
|
48710
49317
|
logging: {
|
|
48711
49318
|
logger: this.rootLogger,
|
|
48712
|
-
logLevel: this.
|
|
49319
|
+
logLevel: this._logLevel
|
|
48713
49320
|
}
|
|
48714
49321
|
});
|
|
48715
49322
|
const registry2 = SessionRegistry.getInstance();
|
|
@@ -48720,10 +49327,26 @@ class Frisk {
|
|
|
48720
49327
|
return this._adapter.normalizeToolCall(toolCall);
|
|
48721
49328
|
}
|
|
48722
49329
|
wrapTools(tools, options = DefaultWrapToolOptions) {
|
|
49330
|
+
this.wrapToolsCalled = true;
|
|
49331
|
+
const toolList = [...tools];
|
|
49332
|
+
const registerToolProperties = toolList.map((tool) => this._adapter.extractRegisterToolProperties?.(tool)).filter((properties) => properties !== null && properties !== undefined);
|
|
49333
|
+
if (registerToolProperties.length > 0) {
|
|
49334
|
+
this._toolRegistry.registerTools({
|
|
49335
|
+
tools: registerToolProperties,
|
|
49336
|
+
sdkAttributes: this.sdkAttributes
|
|
49337
|
+
});
|
|
49338
|
+
}
|
|
48723
49339
|
if (this._adapter.wrapTools) {
|
|
48724
|
-
return this._adapter.wrapTools(
|
|
49340
|
+
return this._adapter.wrapTools(toolList, options);
|
|
48725
49341
|
}
|
|
48726
|
-
return
|
|
49342
|
+
return toolList;
|
|
49343
|
+
}
|
|
49344
|
+
getSdkAttributes() {
|
|
49345
|
+
return {
|
|
49346
|
+
...getCoreSdkAttributes(),
|
|
49347
|
+
agentFramework: this.adapter.agentFramework ?? null,
|
|
49348
|
+
agentFrameworkVersion: this.adapter.agentFrameworkVersion ?? null
|
|
49349
|
+
};
|
|
48727
49350
|
}
|
|
48728
49351
|
wrapTool(tool, options = DefaultWrapToolOptions) {
|
|
48729
49352
|
if (this._adapter.wrapTool) {
|
|
@@ -48739,6 +49362,9 @@ class Frisk {
|
|
|
48739
49362
|
this.friskHandle.updateAuthToken(authToken);
|
|
48740
49363
|
this.tracingManager.updateAuthToken(authToken);
|
|
48741
49364
|
}
|
|
49365
|
+
getRegisteredTool(toolName) {
|
|
49366
|
+
return this._toolRegistry.getRegisteredTool(toolName);
|
|
49367
|
+
}
|
|
48742
49368
|
decideToolCall({
|
|
48743
49369
|
toolCall,
|
|
48744
49370
|
agentState,
|
|
@@ -48747,7 +49373,8 @@ class Frisk {
|
|
|
48747
49373
|
const id = toolCall.id ?? v4();
|
|
48748
49374
|
const argsJson = toolCall.args ? JSON.stringify(removeLlmReasoningArg(toolCall.args)) : null;
|
|
48749
49375
|
const stateJson = agentState ? JSON.stringify(agentState) : null;
|
|
48750
|
-
const
|
|
49376
|
+
const registeredTool = this.getRegisteredTool(toolCall.name);
|
|
49377
|
+
const coreResult = this.friskHandle.process(toolCall.name, registeredTool?.id ?? null, registeredTool?.versionId ?? null, argsJson, stateJson, id, this._redaction, traceContextCarrier);
|
|
48751
49378
|
const outcome = coreResult.decision === "allow" ? "allow" /* ALLOW */ : coreResult.decision === "deny" ? "deny" /* DENY */ : coreResult.decision === "escalate" ? "escalate" /* ESCALATE */ : "error" /* ERROR */;
|
|
48752
49379
|
return {
|
|
48753
49380
|
outcome,
|
|
@@ -48760,6 +49387,8 @@ class Frisk {
|
|
|
48760
49387
|
async getOrCreateToolApprovalRequest({
|
|
48761
49388
|
toolCallId,
|
|
48762
49389
|
toolName,
|
|
49390
|
+
toolId,
|
|
49391
|
+
toolVersionId,
|
|
48763
49392
|
policyId,
|
|
48764
49393
|
policyVersionId,
|
|
48765
49394
|
sessionId
|
|
@@ -48767,6 +49396,8 @@ class Frisk {
|
|
|
48767
49396
|
return getOrCreateToolApprovalRequest({
|
|
48768
49397
|
toolCallId,
|
|
48769
49398
|
toolName,
|
|
49399
|
+
toolId,
|
|
49400
|
+
toolVersionId,
|
|
48770
49401
|
policyId,
|
|
48771
49402
|
policyVersionId,
|
|
48772
49403
|
sessionId,
|
|
@@ -48835,5 +49466,5 @@ export {
|
|
|
48835
49466
|
AccessTokenProvider
|
|
48836
49467
|
};
|
|
48837
49468
|
|
|
48838
|
-
//# debugId=
|
|
49469
|
+
//# debugId=59297CD6351BA8FC64756E2164756E21
|
|
48839
49470
|
//# sourceMappingURL=index.js.map
|