@friskai/frisk-js 0.2.8 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +1 -1
  2. package/dist/adapters/langchain/frisk-callback-handler.d.ts +1 -2
  3. package/dist/adapters/langchain/frisk-callback-handler.d.ts.map +1 -1
  4. package/dist/adapters/langchain/frisk-tool-middleware.d.ts.map +1 -1
  5. package/dist/adapters/langchain/index.js +1105 -1024
  6. package/dist/adapters/langchain/index.js.map +24 -25
  7. package/dist/adapters/langchain/langchain-framework-adapter/langchain-framework-adapter.d.ts +3 -3
  8. package/dist/adapters/langchain/langchain-framework-adapter/langchain-framework-adapter.d.ts.map +1 -1
  9. package/dist/core/extensions.d.ts +30 -0
  10. package/dist/core/extensions.d.ts.map +1 -0
  11. package/dist/core/frisk-session.d.ts +30 -4
  12. package/dist/core/frisk-session.d.ts.map +1 -1
  13. package/dist/core/frisk.d.ts +14 -24
  14. package/dist/core/frisk.d.ts.map +1 -1
  15. package/dist/core/tool-call-span.d.ts +1 -2
  16. package/dist/core/tool-call-span.d.ts.map +1 -1
  17. package/dist/core/types.d.ts +5 -0
  18. package/dist/core/types.d.ts.map +1 -1
  19. package/dist/errors/index.d.ts +6 -0
  20. package/dist/errors/index.d.ts.map +1 -1
  21. package/dist/framework-adapter/base-framework-adapter.d.ts +3 -3
  22. package/dist/framework-adapter/base-framework-adapter.d.ts.map +1 -1
  23. package/dist/framework-adapter/framework-adapter.d.ts +3 -3
  24. package/dist/framework-adapter/framework-adapter.d.ts.map +1 -1
  25. package/dist/framework-adapter/index.d.ts +2 -2
  26. package/dist/framework-adapter/index.d.ts.map +1 -1
  27. package/dist/generated/sdk-meta.d.ts +1 -1
  28. package/dist/index.d.ts +2 -2
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +298 -178
  31. package/dist/index.js.map +14 -15
  32. package/dist/telemetry/constants.d.ts +3 -1
  33. package/dist/telemetry/constants.d.ts.map +1 -1
  34. package/dist/utils/redact.d.ts +5 -5
  35. package/dist/utils/redact.d.ts.map +1 -1
  36. package/package.json +3 -27
  37. package/dist/adapters/claude/claude-framework-adapter/claude-framework-adapter.d.ts +0 -99
  38. package/dist/adapters/claude/claude-framework-adapter/claude-framework-adapter.d.ts.map +0 -1
  39. package/dist/adapters/claude/claude-framework-adapter/get-claude-agent-sdk-version.d.ts +0 -2
  40. package/dist/adapters/claude/claude-framework-adapter/get-claude-agent-sdk-version.d.ts.map +0 -1
  41. package/dist/adapters/claude/claude-framework-adapter/wrap-tool-with-llm-reasoning.d.ts +0 -4
  42. package/dist/adapters/claude/claude-framework-adapter/wrap-tool-with-llm-reasoning.d.ts.map +0 -1
  43. package/dist/adapters/claude/frisk-claude-session.d.ts +0 -29
  44. package/dist/adapters/claude/frisk-claude-session.d.ts.map +0 -1
  45. package/dist/adapters/claude/frisk-claude.d.ts +0 -71
  46. package/dist/adapters/claude/frisk-claude.d.ts.map +0 -1
  47. package/dist/adapters/claude/index.d.ts +0 -3
  48. package/dist/adapters/claude/index.d.ts.map +0 -1
  49. package/dist/adapters/claude/index.js +0 -65658
  50. package/dist/adapters/claude/index.js.map +0 -449
  51. package/dist/adapters/claude/resolve-claude-tool-name.d.ts +0 -2
  52. package/dist/adapters/claude/resolve-claude-tool-name.d.ts.map +0 -1
  53. package/dist/native-bindings/index.d.ts +0 -23
  54. package/dist/native-bindings/index.d.ts.map +0 -1
  55. package/native/README.md +0 -55
  56. package/native/frisk-js.darwin-arm64.node +0 -0
  57. package/native/frisk-js.darwin-x64.node +0 -0
  58. package/native/frisk-js.linux-arm64-gnu.node +0 -0
  59. package/native/frisk-js.linux-arm64-musl.node +0 -0
  60. package/native/frisk-js.linux-x64-gnu.node +0 -0
  61. package/native/frisk-js.linux-x64-musl.node +0 -0
  62. package/native/frisk-js.win32-arm64-msvc.node +0 -0
  63. package/native/frisk-js.win32-x64-msvc.node +0 -0
  64. package/native/index.cjs +0 -580
  65. package/native/index.d.ts +0 -73
package/dist/index.js CHANGED
@@ -1141,7 +1141,7 @@ var require_call_credentials = __commonJS((exports) => {
1141
1141
  if (isCurrentOauth2Client(googleCredentials)) {
1142
1142
  getHeaders = googleCredentials.getRequestHeaders(options.service_url);
1143
1143
  } else {
1144
- getHeaders = new Promise((resolve2, reject) => {
1144
+ getHeaders = new Promise((resolve, reject) => {
1145
1145
  googleCredentials.getRequestMetadata(options.service_url, (err, headers) => {
1146
1146
  if (err) {
1147
1147
  reject(err);
@@ -1151,7 +1151,7 @@ var require_call_credentials = __commonJS((exports) => {
1151
1151
  reject(new Error("Headers not set by metadata plugin"));
1152
1152
  return;
1153
1153
  }
1154
- resolve2(headers);
1154
+ resolve(headers);
1155
1155
  });
1156
1156
  });
1157
1157
  }
@@ -1206,10 +1206,10 @@ var require_call_credentials = __commonJS((exports) => {
1206
1206
  this.metadataGenerator = metadataGenerator;
1207
1207
  }
1208
1208
  generateMetadata(options) {
1209
- return new Promise((resolve2, reject) => {
1209
+ return new Promise((resolve, reject) => {
1210
1210
  this.metadataGenerator(options, (err, metadata) => {
1211
1211
  if (metadata !== undefined) {
1212
- resolve2(metadata);
1212
+ resolve(metadata);
1213
1213
  } else {
1214
1214
  reject(err);
1215
1215
  }
@@ -1531,14 +1531,14 @@ var require_channel_credentials = __commonJS((exports) => {
1531
1531
  }
1532
1532
  connect(socket) {
1533
1533
  const tlsConnectOptions = Object.assign({ socket }, this.connectionOptions);
1534
- return new Promise((resolve2, reject) => {
1534
+ return new Promise((resolve, reject) => {
1535
1535
  const tlsSocket = (0, tls_1.connect)(tlsConnectOptions, () => {
1536
1536
  var _a;
1537
1537
  if (((_a = this.connectionOptions.rejectUnauthorized) !== null && _a !== undefined ? _a : true) && !tlsSocket.authorized) {
1538
1538
  reject(tlsSocket.authorizationError);
1539
1539
  return;
1540
1540
  }
1541
- resolve2({
1541
+ resolve({
1542
1542
  socket: tlsSocket,
1543
1543
  secure: true
1544
1544
  });
@@ -1658,8 +1658,8 @@ var require_channel_credentials = __commonJS((exports) => {
1658
1658
  if (this.hasReceivedUpdates()) {
1659
1659
  return Promise.resolve(this.getLatestSecureContext());
1660
1660
  } else {
1661
- return new Promise((resolve2) => {
1662
- this.secureContextWatchers.push(resolve2);
1661
+ return new Promise((resolve) => {
1662
+ this.secureContextWatchers.push(resolve);
1663
1663
  });
1664
1664
  }
1665
1665
  }
@@ -1692,7 +1692,7 @@ var require_channel_credentials = __commonJS((exports) => {
1692
1692
  this.callCredentials = callCredentials;
1693
1693
  }
1694
1694
  connect(socket) {
1695
- return new Promise((resolve2, reject) => {
1695
+ return new Promise((resolve, reject) => {
1696
1696
  const secureContext = this.parent.getLatestSecureContext();
1697
1697
  if (!secureContext) {
1698
1698
  reject(new Error("Failed to load credentials"));
@@ -1717,7 +1717,7 @@ var require_channel_credentials = __commonJS((exports) => {
1717
1717
  reject(tlsSocket.authorizationError);
1718
1718
  return;
1719
1719
  }
1720
- resolve2({
1720
+ resolve({
1721
1721
  socket: tlsSocket,
1722
1722
  secure: true
1723
1723
  });
@@ -5245,7 +5245,7 @@ var require_aspromise = __commonJS((exports, module) => {
5245
5245
  var params = new Array(arguments.length - 1), offset = 0, index = 2, pending = true;
5246
5246
  while (index < arguments.length)
5247
5247
  params[offset++] = arguments[index++];
5248
- return new Promise(function executor(resolve2, reject) {
5248
+ return new Promise(function executor(resolve, reject) {
5249
5249
  params[offset] = function callback(err) {
5250
5250
  if (pending) {
5251
5251
  pending = false;
@@ -5255,7 +5255,7 @@ var require_aspromise = __commonJS((exports, module) => {
5255
5255
  var params2 = new Array(arguments.length - 1), offset2 = 0;
5256
5256
  while (offset2 < params2.length)
5257
5257
  params2[offset2++] = arguments[offset2];
5258
- resolve2.apply(null, params2);
5258
+ resolve.apply(null, params2);
5259
5259
  }
5260
5260
  }
5261
5261
  };
@@ -6643,7 +6643,7 @@ var require_path = __commonJS((exports) => {
6643
6643
  }
6644
6644
  return prefix + parts.join("/");
6645
6645
  };
6646
- path.resolve = function resolve2(originPath, includePath, alreadyNormalized) {
6646
+ path.resolve = function resolve(originPath, includePath, alreadyNormalized) {
6647
6647
  if (!alreadyNormalized)
6648
6648
  includePath = normalize(includePath);
6649
6649
  if (isAbsolute(includePath))
@@ -6956,7 +6956,7 @@ var require_mapfield = __commonJS((exports, module) => {
6956
6956
  keepComments ? this.comment : undefined
6957
6957
  ]);
6958
6958
  };
6959
- MapField.prototype.resolve = function resolve2() {
6959
+ MapField.prototype.resolve = function resolve() {
6960
6960
  if (this.resolved)
6961
6961
  return this;
6962
6962
  if (types.mapKey[this.keyType] === undefined)
@@ -7029,7 +7029,7 @@ var require_method = __commonJS((exports, module) => {
7029
7029
  this.parsedOptions
7030
7030
  ]);
7031
7031
  };
7032
- Method.prototype.resolve = function resolve2() {
7032
+ Method.prototype.resolve = function resolve() {
7033
7033
  if (this.resolved)
7034
7034
  return this;
7035
7035
  this.resolvedRequestType = this.parent.lookupType(this.requestType);
@@ -8429,7 +8429,7 @@ var require_field = __commonJS((exports, module) => {
8429
8429
  keepComments ? this.comment : undefined
8430
8430
  ]);
8431
8431
  };
8432
- Field.prototype.resolve = function resolve2() {
8432
+ Field.prototype.resolve = function resolve() {
8433
8433
  if (this.resolved)
8434
8434
  return this;
8435
8435
  if ((this.typeDefault = types.defaults[this.type]) === undefined) {
@@ -8683,7 +8683,7 @@ var require_object = __commonJS((exports, module) => {
8683
8683
  this.parent = null;
8684
8684
  this.resolved = false;
8685
8685
  };
8686
- ReflectionObject.prototype.resolve = function resolve2() {
8686
+ ReflectionObject.prototype.resolve = function resolve() {
8687
8687
  if (this.resolved)
8688
8688
  return this;
8689
8689
  if (this.root instanceof Root)
@@ -14234,18 +14234,18 @@ var require_compression_filter = __commonJS((exports) => {
14234
14234
  this.maxRecvMessageLength = maxRecvMessageLength;
14235
14235
  }
14236
14236
  compressMessage(message) {
14237
- return new Promise((resolve2, reject) => {
14237
+ return new Promise((resolve, reject) => {
14238
14238
  zlib.deflate(message, (err, output) => {
14239
14239
  if (err) {
14240
14240
  reject(err);
14241
14241
  } else {
14242
- resolve2(output);
14242
+ resolve(output);
14243
14243
  }
14244
14244
  });
14245
14245
  });
14246
14246
  }
14247
14247
  decompressMessage(message) {
14248
- return new Promise((resolve2, reject) => {
14248
+ return new Promise((resolve, reject) => {
14249
14249
  let totalLength = 0;
14250
14250
  const messageParts = [];
14251
14251
  const decompresser = zlib.createInflate();
@@ -14261,7 +14261,7 @@ var require_compression_filter = __commonJS((exports) => {
14261
14261
  }
14262
14262
  });
14263
14263
  decompresser.on("end", () => {
14264
- resolve2(Buffer.concat(messageParts));
14264
+ resolve(Buffer.concat(messageParts));
14265
14265
  });
14266
14266
  decompresser.write(message);
14267
14267
  decompresser.end();
@@ -14275,18 +14275,18 @@ var require_compression_filter = __commonJS((exports) => {
14275
14275
  this.maxRecvMessageLength = maxRecvMessageLength;
14276
14276
  }
14277
14277
  compressMessage(message) {
14278
- return new Promise((resolve2, reject) => {
14278
+ return new Promise((resolve, reject) => {
14279
14279
  zlib.gzip(message, (err, output) => {
14280
14280
  if (err) {
14281
14281
  reject(err);
14282
14282
  } else {
14283
- resolve2(output);
14283
+ resolve(output);
14284
14284
  }
14285
14285
  });
14286
14286
  });
14287
14287
  }
14288
14288
  decompressMessage(message) {
14289
- return new Promise((resolve2, reject) => {
14289
+ return new Promise((resolve, reject) => {
14290
14290
  let totalLength = 0;
14291
14291
  const messageParts = [];
14292
14292
  const decompresser = zlib.createGunzip();
@@ -14302,7 +14302,7 @@ var require_compression_filter = __commonJS((exports) => {
14302
14302
  }
14303
14303
  });
14304
14304
  decompresser.on("end", () => {
14305
- resolve2(Buffer.concat(messageParts));
14305
+ resolve(Buffer.concat(messageParts));
14306
14306
  });
14307
14307
  decompresser.write(message);
14308
14308
  decompresser.end();
@@ -15556,7 +15556,7 @@ var require_http_proxy = __commonJS((exports) => {
15556
15556
  options.headers = headers;
15557
15557
  const proxyAddressString = (0, subchannel_address_1.subchannelAddressToString)(address);
15558
15558
  trace("Using proxy " + proxyAddressString + " to connect to " + options.path);
15559
- return new Promise((resolve2, reject) => {
15559
+ return new Promise((resolve, reject) => {
15560
15560
  const request = http.request(options);
15561
15561
  request.once("connect", (res, socket, head) => {
15562
15562
  request.removeAllListeners();
@@ -15567,7 +15567,7 @@ var require_http_proxy = __commonJS((exports) => {
15567
15567
  socket.unshift(head);
15568
15568
  }
15569
15569
  trace("Successfully established a plaintext connection to " + options.path + " through proxy " + proxyAddressString);
15570
- resolve2(socket);
15570
+ resolve(socket);
15571
15571
  } else {
15572
15572
  (0, logging_1.log)(constants_1.LogVerbosity.ERROR, "Failed to connect to " + options.path + " through proxy " + proxyAddressString + " with status " + res.statusCode);
15573
15573
  reject();
@@ -16439,7 +16439,7 @@ var require_transport = __commonJS((exports) => {
16439
16439
  if (secureConnectResult.socket.closed) {
16440
16440
  return Promise.reject("Connection closed before starting HTTP/2 handshake");
16441
16441
  }
16442
- return new Promise((resolve2, reject) => {
16442
+ return new Promise((resolve, reject) => {
16443
16443
  var _a, _b, _c, _d, _e, _f, _g, _h;
16444
16444
  let remoteName = null;
16445
16445
  let realTarget = this.channelTarget;
@@ -16504,7 +16504,7 @@ var require_transport = __commonJS((exports) => {
16504
16504
  session.removeAllListeners();
16505
16505
  secureConnectResult.socket.removeListener("close", closeHandler);
16506
16506
  secureConnectResult.socket.removeListener("error", errorHandler);
16507
- resolve2(new Http2Transport(session, address, options, remoteName));
16507
+ resolve(new Http2Transport(session, address, options, remoteName));
16508
16508
  this.session = null;
16509
16509
  });
16510
16510
  session.once("close", closeHandler);
@@ -16518,7 +16518,7 @@ var require_transport = __commonJS((exports) => {
16518
16518
  if (proxiedSocket) {
16519
16519
  return proxiedSocket;
16520
16520
  } else {
16521
- return new Promise((resolve2, reject) => {
16521
+ return new Promise((resolve, reject) => {
16522
16522
  const closeCallback = () => {
16523
16523
  reject(new Error("Socket closed"));
16524
16524
  };
@@ -16528,7 +16528,7 @@ var require_transport = __commonJS((exports) => {
16528
16528
  const socket = net.connect(address, () => {
16529
16529
  socket.removeListener("close", closeCallback);
16530
16530
  socket.removeListener("error", errorCallback);
16531
- resolve2(socket);
16531
+ resolve(socket);
16532
16532
  });
16533
16533
  socket.once("close", closeCallback);
16534
16534
  socket.once("error", errorCallback);
@@ -19742,7 +19742,7 @@ var require_server_interceptors = __commonJS((exports) => {
19742
19742
  } else {
19743
19743
  decompresser = zlib.createGunzip();
19744
19744
  }
19745
- return new Promise((resolve2, reject) => {
19745
+ return new Promise((resolve, reject) => {
19746
19746
  let totalLength = 0;
19747
19747
  const messageParts = [];
19748
19748
  decompresser.on("data", (chunk) => {
@@ -19757,7 +19757,7 @@ var require_server_interceptors = __commonJS((exports) => {
19757
19757
  }
19758
19758
  });
19759
19759
  decompresser.on("end", () => {
19760
- resolve2(Buffer.concat(messageParts));
19760
+ resolve(Buffer.concat(messageParts));
19761
19761
  });
19762
19762
  decompresser.write(messageContents);
19763
19763
  decompresser.end();
@@ -20350,10 +20350,10 @@ var require_server = __commonJS((exports) => {
20350
20350
  bindOneAddress(address, boundPortObject) {
20351
20351
  this.trace("Attempting to bind " + (0, subchannel_address_1.subchannelAddressToString)(address));
20352
20352
  const http2Server = this.createHttp2Server(boundPortObject.credentials);
20353
- return new Promise((resolve2, reject) => {
20353
+ return new Promise((resolve, reject) => {
20354
20354
  const onError = (err) => {
20355
20355
  this.trace("Failed to bind " + (0, subchannel_address_1.subchannelAddressToString)(address) + " with error " + err.message);
20356
- resolve2({
20356
+ resolve({
20357
20357
  port: "port" in address ? address.port : 1,
20358
20358
  error: err.message
20359
20359
  });
@@ -20381,7 +20381,7 @@ var require_server = __commonJS((exports) => {
20381
20381
  });
20382
20382
  boundPortObject.listeningServers.add(http2Server);
20383
20383
  this.trace("Successfully bound " + (0, subchannel_address_1.subchannelAddressToString)(boundSubchannelAddress));
20384
- resolve2({
20384
+ resolve({
20385
20385
  port: "port" in boundSubchannelAddress ? boundSubchannelAddress.port : 1
20386
20386
  });
20387
20387
  http2Server.removeListener("error", onError);
@@ -20434,7 +20434,7 @@ var require_server = __commonJS((exports) => {
20434
20434
  }
20435
20435
  }
20436
20436
  resolvePort(port) {
20437
- return new Promise((resolve2, reject) => {
20437
+ return new Promise((resolve, reject) => {
20438
20438
  let seenResolution = false;
20439
20439
  const resolverListener = (endpointList, attributes, serviceConfig, resolutionNote) => {
20440
20440
  if (seenResolution) {
@@ -20450,7 +20450,7 @@ var require_server = __commonJS((exports) => {
20450
20450
  reject(new Error(`No addresses resolved for port ${port}`));
20451
20451
  return true;
20452
20452
  }
20453
- resolve2(addressList);
20453
+ resolve(addressList);
20454
20454
  return true;
20455
20455
  };
20456
20456
  const resolver = (0, resolver_1.createResolver)(port, resolverListener, this.options);
@@ -27564,8 +27564,8 @@ var require_promise = __commonJS((exports) => {
27564
27564
  _resolve;
27565
27565
  _reject;
27566
27566
  constructor() {
27567
- this._promise = new Promise((resolve2, reject) => {
27568
- this._resolve = resolve2;
27567
+ this._promise = new Promise((resolve, reject) => {
27568
+ this._resolve = resolve;
27569
27569
  this._reject = reject;
27570
27570
  });
27571
27571
  }
@@ -27653,9 +27653,9 @@ var require_exporter = __commonJS((exports) => {
27653
27653
  var api_1 = require_src4();
27654
27654
  var suppress_tracing_1 = require_suppress_tracing();
27655
27655
  function _export(exporter, arg) {
27656
- return new Promise((resolve2) => {
27656
+ return new Promise((resolve) => {
27657
27657
  api_1.context.with((0, suppress_tracing_1.suppressTracing)(api_1.context.active()), () => {
27658
- exporter.export(arg, resolve2);
27658
+ exporter.export(arg, resolve);
27659
27659
  });
27660
27660
  });
27661
27661
  }
@@ -28111,22 +28111,22 @@ var require_grpc_exporter_transport = __commonJS((exports) => {
28111
28111
  });
28112
28112
  }
28113
28113
  }
28114
- return new Promise((resolve2) => {
28114
+ return new Promise((resolve) => {
28115
28115
  const deadline = Date.now() + timeoutMillis;
28116
28116
  if (this._metadata == null) {
28117
- return resolve2({
28117
+ return resolve({
28118
28118
  error: new Error("metadata was null"),
28119
28119
  status: "failure"
28120
28120
  });
28121
28121
  }
28122
28122
  this._client.export(buffer, this._metadata, { deadline }, (err, response) => {
28123
28123
  if (err) {
28124
- resolve2({
28124
+ resolve({
28125
28125
  status: "failure",
28126
28126
  error: err
28127
28127
  });
28128
28128
  } else {
28129
- resolve2({
28129
+ resolve({
28130
28130
  data: response,
28131
28131
  status: "success"
28132
28132
  });
@@ -28469,9 +28469,9 @@ var require_http_exporter_transport = __commonJS((exports) => {
28469
28469
  async send(data, timeoutMillis) {
28470
28470
  const { agent, request } = await this._loadUtils();
28471
28471
  const headers = await this._parameters.headers();
28472
- return new Promise((resolve2) => {
28472
+ return new Promise((resolve) => {
28473
28473
  (0, http_transport_utils_1.sendWithHttp)(request, this._parameters.url, headers, this._parameters.compression, this._parameters.userAgent, agent, data, (result) => {
28474
- resolve2(result);
28474
+ resolve(result);
28475
28475
  }, timeoutMillis);
28476
28476
  });
28477
28477
  }
@@ -28520,9 +28520,9 @@ var require_retrying_transport = __commonJS((exports) => {
28520
28520
  this._transport = transport;
28521
28521
  }
28522
28522
  retry(data, timeoutMillis, inMillis) {
28523
- return new Promise((resolve2, reject) => {
28523
+ return new Promise((resolve, reject) => {
28524
28524
  setTimeout(() => {
28525
- this._transport.send(data, timeoutMillis).then(resolve2, reject);
28525
+ this._transport.send(data, timeoutMillis).then(resolve, reject);
28526
28526
  }, inMillis);
28527
28527
  });
28528
28528
  }
@@ -42765,14 +42765,14 @@ var require_BatchSpanProcessorBase = __commonJS((exports) => {
42765
42765
  this._maybeStartTimer();
42766
42766
  }
42767
42767
  _flushAll() {
42768
- return new Promise((resolve2, reject) => {
42768
+ return new Promise((resolve, reject) => {
42769
42769
  const promises = [];
42770
42770
  const count = Math.ceil(this._finishedSpans.length / this._maxExportBatchSize);
42771
42771
  for (let i = 0, j = count;i < j; i++) {
42772
42772
  promises.push(this._flushOneBatch());
42773
42773
  }
42774
42774
  Promise.all(promises).then(() => {
42775
- resolve2();
42775
+ resolve();
42776
42776
  }).catch(reject);
42777
42777
  });
42778
42778
  }
@@ -42781,7 +42781,7 @@ var require_BatchSpanProcessorBase = __commonJS((exports) => {
42781
42781
  if (this._finishedSpans.length === 0) {
42782
42782
  return Promise.resolve();
42783
42783
  }
42784
- return new Promise((resolve2, reject) => {
42784
+ return new Promise((resolve, reject) => {
42785
42785
  const timer = setTimeout(() => {
42786
42786
  reject(new Error("Timeout"));
42787
42787
  }, this._exportTimeoutMillis);
@@ -42796,7 +42796,7 @@ var require_BatchSpanProcessorBase = __commonJS((exports) => {
42796
42796
  const doExport = () => this._exporter.export(spans, (result) => {
42797
42797
  clearTimeout(timer);
42798
42798
  if (result.code === core_1.ExportResultCode.SUCCESS) {
42799
- resolve2();
42799
+ resolve();
42800
42800
  } else {
42801
42801
  reject(result.error ?? new Error("BatchSpanProcessor: span export failed"));
42802
42802
  }
@@ -43056,12 +43056,12 @@ var require_MultiSpanProcessor = __commonJS((exports) => {
43056
43056
  for (const spanProcessor of this._spanProcessors) {
43057
43057
  promises.push(spanProcessor.forceFlush());
43058
43058
  }
43059
- return new Promise((resolve2) => {
43059
+ return new Promise((resolve) => {
43060
43060
  Promise.all(promises).then(() => {
43061
- resolve2();
43061
+ resolve();
43062
43062
  }).catch((error) => {
43063
43063
  (0, core_1.globalErrorHandler)(error || new Error("MultiSpanProcessor: forceFlush failed"));
43064
- resolve2();
43064
+ resolve();
43065
43065
  });
43066
43066
  });
43067
43067
  }
@@ -43087,9 +43087,9 @@ var require_MultiSpanProcessor = __commonJS((exports) => {
43087
43087
  for (const spanProcessor of this._spanProcessors) {
43088
43088
  promises.push(spanProcessor.shutdown());
43089
43089
  }
43090
- return new Promise((resolve2, reject) => {
43090
+ return new Promise((resolve, reject) => {
43091
43091
  Promise.all(promises).then(() => {
43092
- resolve2();
43092
+ resolve();
43093
43093
  }, reject);
43094
43094
  });
43095
43095
  }
@@ -43142,32 +43142,32 @@ var require_BasicTracerProvider = __commonJS((exports) => {
43142
43142
  forceFlush() {
43143
43143
  const timeout = this._config.forceFlushTimeoutMillis;
43144
43144
  const promises = this._activeSpanProcessor["_spanProcessors"].map((spanProcessor) => {
43145
- return new Promise((resolve2) => {
43145
+ return new Promise((resolve) => {
43146
43146
  let state;
43147
43147
  const timeoutInterval = setTimeout(() => {
43148
- resolve2(new Error(`Span processor did not completed within timeout period of ${timeout} ms`));
43148
+ resolve(new Error(`Span processor did not completed within timeout period of ${timeout} ms`));
43149
43149
  state = ForceFlushState.timeout;
43150
43150
  }, timeout);
43151
43151
  spanProcessor.forceFlush().then(() => {
43152
43152
  clearTimeout(timeoutInterval);
43153
43153
  if (state !== ForceFlushState.timeout) {
43154
43154
  state = ForceFlushState.resolved;
43155
- resolve2(state);
43155
+ resolve(state);
43156
43156
  }
43157
43157
  }).catch((error) => {
43158
43158
  clearTimeout(timeoutInterval);
43159
43159
  state = ForceFlushState.error;
43160
- resolve2(error);
43160
+ resolve(error);
43161
43161
  });
43162
43162
  });
43163
43163
  });
43164
- return new Promise((resolve2, reject) => {
43164
+ return new Promise((resolve, reject) => {
43165
43165
  Promise.all(promises).then((results) => {
43166
43166
  const errors = results.filter((result) => result !== ForceFlushState.resolved);
43167
43167
  if (errors.length > 0) {
43168
43168
  reject(errors);
43169
43169
  } else {
43170
- resolve2();
43170
+ resolve();
43171
43171
  }
43172
43172
  }).catch((error) => reject([error]));
43173
43173
  });
@@ -43595,6 +43595,13 @@ class UnexpectedFriskServerResponseError extends Error {
43595
43595
  }
43596
43596
  }
43597
43597
 
43598
+ class MissingToolPoliciesExtensionError extends FriskError {
43599
+ constructor(options) {
43600
+ super("decide_tool_call requires the tool policies extension. Install and register the @friskai/frisk-js-tool-policies extension; calling frisk.connect() alone is not sufficient.", options);
43601
+ this.name = "MissingToolPoliciesExtensionError";
43602
+ }
43603
+ }
43604
+
43598
43605
  class ToolCallSpanNotInitializedError extends Error {
43599
43606
  constructor(message = "Tool call span has not been initialized. Call enter() first.") {
43600
43607
  super(message);
@@ -43940,23 +43947,6 @@ class AccessTokenProvider {
43940
43947
  return this.refreshIntervalId !== null;
43941
43948
  }
43942
43949
  }
43943
- // ../../node_modules/uuid/wrapper.mjs
43944
- var import_dist = __toESM(require_dist(), 1);
43945
- var v1 = import_dist.default.v1;
43946
- var v1ToV6 = import_dist.default.v1ToV6;
43947
- var v3 = import_dist.default.v3;
43948
- var v4 = import_dist.default.v4;
43949
- var v5 = import_dist.default.v5;
43950
- var v6 = import_dist.default.v6;
43951
- var v6ToV1 = import_dist.default.v6ToV1;
43952
- var v7 = import_dist.default.v7;
43953
- var NIL = import_dist.default.NIL;
43954
- var MAX = import_dist.default.MAX;
43955
- var version = import_dist.default.version;
43956
- var validate = import_dist.default.validate;
43957
- var stringify = import_dist.default.stringify;
43958
- var parse = import_dist.default.parse;
43959
-
43960
43950
  // src/env/index.ts
43961
43951
  var FRISK_API_KEY = "FRISK_API_KEY";
43962
43952
  var FRISK_BASE_URL = "FRISK_BASE_URL";
@@ -43993,27 +43983,70 @@ function combineRedactOptions(...options) {
43993
43983
  }
43994
43984
  return false;
43995
43985
  }
43996
- function redactDictionarySimple(data, redactOption) {
43986
+ function deleteDotPath(root, path) {
43987
+ const parts = path.split(".").filter((p) => p.length > 0);
43988
+ if (parts.length === 0)
43989
+ return false;
43990
+ let cur = root;
43991
+ for (const key of parts.slice(0, -1)) {
43992
+ if (cur === null || typeof cur !== "object" || Array.isArray(cur))
43993
+ return false;
43994
+ if (!(key in cur))
43995
+ return false;
43996
+ cur = cur[key];
43997
+ }
43998
+ if (cur === null || typeof cur !== "object" || Array.isArray(cur))
43999
+ return false;
44000
+ const last = parts[parts.length - 1];
44001
+ if (!(last in cur))
44002
+ return false;
44003
+ delete cur[last];
44004
+ return true;
44005
+ }
44006
+ function deepClone(obj) {
44007
+ return JSON.parse(JSON.stringify(obj));
44008
+ }
44009
+ function redactObject(data, redactOption) {
43997
44010
  if (redactOption === undefined || redactOption === false) {
43998
44011
  return { value: data, redactedPaths: [] };
43999
44012
  }
44000
- const redactedPaths = [];
44001
- const result = { ...data };
44002
44013
  if (redactOption === true) {
44003
- for (const key of Object.keys(result)) {
44004
- delete result[key];
44005
- redactedPaths.push(key);
44006
- }
44007
- } else if (Array.isArray(redactOption)) {
44008
- for (const path of redactOption) {
44009
- if (path in result) {
44010
- delete result[path];
44011
- redactedPaths.push(path);
44012
- }
44014
+ return { value: {}, redactedPaths: ["*"] };
44015
+ }
44016
+ if (!Array.isArray(redactOption) || redactOption.length === 0) {
44017
+ return { value: data, redactedPaths: [] };
44018
+ }
44019
+ const out = deepClone(data);
44020
+ const hits = [];
44021
+ const seen = new Set;
44022
+ for (const rawPath of redactOption) {
44023
+ const path = rawPath.trim();
44024
+ if (path.length === 0)
44025
+ continue;
44026
+ if (deleteDotPath(out, path) && !seen.has(path)) {
44027
+ seen.add(path);
44028
+ hits.push(path);
44013
44029
  }
44014
44030
  }
44015
- return { value: result, redactedPaths };
44031
+ return { value: out, redactedPaths: hits };
44016
44032
  }
44033
+ // ../../node_modules/uuid/wrapper.mjs
44034
+ var import_dist = __toESM(require_dist(), 1);
44035
+ var v1 = import_dist.default.v1;
44036
+ var v1ToV6 = import_dist.default.v1ToV6;
44037
+ var v3 = import_dist.default.v3;
44038
+ var v4 = import_dist.default.v4;
44039
+ var v5 = import_dist.default.v5;
44040
+ var v6 = import_dist.default.v6;
44041
+ var v6ToV1 = import_dist.default.v6ToV1;
44042
+ var v7 = import_dist.default.v7;
44043
+ var NIL = import_dist.default.NIL;
44044
+ var MAX = import_dist.default.MAX;
44045
+ var version = import_dist.default.version;
44046
+ var validate = import_dist.default.validate;
44047
+ var stringify = import_dist.default.stringify;
44048
+ var parse = import_dist.default.parse;
44049
+
44017
44050
  // src/framework-adapter/base-framework-adapter.ts
44018
44051
  class BaseFrameworkAdapter {
44019
44052
  agentFramework = "none";
@@ -44039,10 +44072,10 @@ class BaseFrameworkAdapter {
44039
44072
  };
44040
44073
  }
44041
44074
  toolArgsToDict(toolArgs, options) {
44042
- return redactDictionarySimple(toolArgs, options?.redact);
44075
+ return redactObject(toolArgs, options?.redact);
44043
44076
  }
44044
44077
  agentStateToDict(agentState, options) {
44045
- return redactDictionarySimple(agentState, options?.redact);
44078
+ return redactObject(agentState, options?.redact);
44046
44079
  }
44047
44080
  normalizeToolCall(toolCall) {
44048
44081
  return {
@@ -44064,22 +44097,6 @@ var DefaultWrapToolOptions = {
44064
44097
  captureReasoning: true
44065
44098
  };
44066
44099
 
44067
- // src/native-bindings/index.ts
44068
- import { createRequire as createRequire2 } from "module";
44069
- import { dirname, resolve } from "path";
44070
- var require2 = createRequire2(import.meta.url);
44071
- function resolveNativePath() {
44072
- const injected = process.env.FRISk_NATIVE_BINDINGS_PATH;
44073
- if (injected)
44074
- return injected;
44075
- const pkgJsonPath = require2.resolve("@friskai/frisk-js/package.json");
44076
- const pkgRoot = dirname(pkgJsonPath);
44077
- return resolve(pkgRoot, "native/index.cjs");
44078
- }
44079
- var nativeBindings = require2(resolveNativePath());
44080
- var FriskHandle = nativeBindings.FriskHandle;
44081
- var redactDictionary = nativeBindings.redactDictionary;
44082
-
44083
44100
  // src/telemetry/constants.ts
44084
44101
  var TRACER_NAME = "frisk_js_sdk";
44085
44102
  var TRACER_VERSION = "0.1.0";
@@ -44103,9 +44120,11 @@ var ATTRIBUTE_NAME_DECISION_OUTCOME = "frisk.decision.outcome";
44103
44120
  var ATTRIBUTE_NAME_DECISION_REASON = "frisk.decision.reason";
44104
44121
  var ATTRIBUTE_NAME_ERROR_TYPE = "error.type";
44105
44122
  var ATTRIBUTE_NAME_ERROR_MESSAGE = "error.message";
44106
- var ATTRIBUTE_NAME_LATENCY_NS = "latency_ns";
44107
44123
  var ATTRIBUTE_NAME_TOOL_CALL_IS_SUCCESS = "frisk.tool_call.is_success";
44108
44124
  var ATTRIBUTE_NAME_TOOL_CALL_IS_ERROR = "frisk.tool_call.is_error";
44125
+ var ATTRIBUTE_NAME_TOOL_CALL_COUNT = "frisk.tool_calls.count";
44126
+ var ATTRIBUTE_NAME_TOOL_CALL_ERROR_COUNT = "frisk.tool_calls.error_count";
44127
+ var ATTRIBUTE_NAME_TOOL_CALL_SEQUENCE_NUMBER = "frisk.tool_call.sequence_number";
44109
44128
  // src/telemetry/tracing-manager.ts
44110
44129
  var import_grpc_js = __toESM(require_src3(), 1);
44111
44130
  var import_exporter_trace_otlp_grpc = __toESM(require_src12(), 1);
@@ -44161,6 +44180,9 @@ class TracingManager {
44161
44180
  }
44162
44181
  }
44163
44182
 
44183
+ // src/core/frisk-session.ts
44184
+ var import_api2 = __toESM(require_src4(), 1);
44185
+
44164
44186
  // ../../node_modules/zod/v4/core/core.js
44165
44187
  var NEVER = Object.freeze({
44166
44188
  status: "aborted"
@@ -48510,7 +48532,6 @@ class ToolCallSpan {
48510
48532
  tracer;
48511
48533
  redaction;
48512
48534
  _span = null;
48513
- _startTimeNs = null;
48514
48535
  _traceContextCarrier = null;
48515
48536
  sessionId;
48516
48537
  friskToolVersionId;
@@ -48591,7 +48612,6 @@ class ToolCallSpan {
48591
48612
  }
48592
48613
  enter() {
48593
48614
  const parentContext = this.parent ? import_api.trace.setSpan(import_api.context.active(), this.parent) : import_api.context.active();
48594
- this._startTimeNs = process.hrtime.bigint();
48595
48615
  const redactedToolArgsResult = this.adapter.serializeToolArgs(removeLlmReasoningArg(this.toolCall.args), { redact: this.redaction.redactToolArgs });
48596
48616
  const redactedAgentStateResult = this.adapter.serializeAgentState(this.agentState, { redact: this.redaction.redactAgentState });
48597
48617
  this._span = this.tracer.startSpan(SPAN_NAME_DECIDE_TOOL_CALL, {
@@ -48617,11 +48637,6 @@ class ToolCallSpan {
48617
48637
  if (!this.span) {
48618
48638
  return;
48619
48639
  }
48620
- if (this._startTimeNs !== null) {
48621
- const endTimeNs = process.hrtime.bigint();
48622
- const latencyNs = endTimeNs - this._startTimeNs;
48623
- this.setAttribute(ATTRIBUTE_NAME_LATENCY_NS, Number(latencyNs));
48624
- }
48625
48640
  this.span.end();
48626
48641
  }
48627
48642
  }
@@ -48645,6 +48660,10 @@ class FriskSession {
48645
48660
  logger;
48646
48661
  _rootRunId = null;
48647
48662
  _isTracing = false;
48663
+ _agentState = null;
48664
+ toolCallSequenceNumber = 0;
48665
+ toolCallSequenceGenerator = this.createToolCallSequenceGenerator();
48666
+ toolCallErrorCount = 0;
48648
48667
  constructor({ frisk, redact, tracer, logging }) {
48649
48668
  const sessionId = this.constructor.generateSessionId();
48650
48669
  this.logger = deriveSdkLogger(logging, {
@@ -48667,6 +48686,71 @@ class FriskSession {
48667
48686
  get rootRunId() {
48668
48687
  return this._rootRunId;
48669
48688
  }
48689
+ async createToolCallSpan({
48690
+ name,
48691
+ args: toolArgsInput,
48692
+ agentState
48693
+ }) {
48694
+ const toolArgs = this.validateToolArgs(toolArgsInput);
48695
+ const redactedToolArgsResult = this.frisk.adapter?.serializeToolArgs(removeLlmReasoningArg(toolArgs), { redact: this.redaction.redactToolArgs }) ?? {
48696
+ value: "{}",
48697
+ redactedPaths: []
48698
+ };
48699
+ const agentStateToUse = agentState ?? this._agentState ?? {};
48700
+ const redactedAgentStateResult = this.frisk.adapter?.serializeAgentState(agentStateToUse, { redact: this.redaction.redactAgentState }) ?? {
48701
+ value: "{}",
48702
+ redactedPaths: []
48703
+ };
48704
+ const sessionSpan = this.rootSpan;
48705
+ const parentContext = sessionSpan ? import_api2.trace.setSpan(import_api2.context.active(), sessionSpan) : import_api2.context.active();
48706
+ const spanAttributes = {
48707
+ [ATTRIBUTE_NAME_SESSION_ID]: this.id,
48708
+ [ATTRIBUTE_NAME_TOOL_NAME]: name,
48709
+ [ATTRIBUTE_NAME_TOOL_ARGS_JSON]: redactedToolArgsResult.value,
48710
+ [ATTRIBUTE_NAME_TOOL_ARGS_REDACTED_PATHS_JSON]: JSON.stringify(redactedToolArgsResult.redactedPaths),
48711
+ [ATTRIBUTE_NAME_AGENT_STATE_JSON]: redactedAgentStateResult.value ?? "{}",
48712
+ [ATTRIBUTE_NAME_AGENT_STATE_REDACTED_PATHS_JSON]: JSON.stringify(redactedAgentStateResult.redactedPaths),
48713
+ [ATTRIBUTE_NAME_TOOL_CALL_SEQUENCE_NUMBER]: this.toolCallSequenceGenerator.next().value
48714
+ };
48715
+ await this.frisk.toolRegistrationComplete;
48716
+ const registeredTool = this.frisk.getRegisteredTool(name);
48717
+ if (registeredTool) {
48718
+ spanAttributes[ATTRIBUTE_NAME_FRISK_TOOL_ID] = registeredTool.id;
48719
+ spanAttributes[ATTRIBUTE_NAME_FRISK_TOOL_VERSION_ID] = registeredTool.versionId;
48720
+ }
48721
+ const span = this.getTracer().startSpan(SPAN_NAME_OBSERVE_TOOL_CALL, {
48722
+ attributes: spanAttributes
48723
+ }, parentContext);
48724
+ return span;
48725
+ }
48726
+ closeToolCallSpan({
48727
+ toolCallId,
48728
+ span,
48729
+ err,
48730
+ status
48731
+ }) {
48732
+ if (toolCallId) {
48733
+ span.setAttribute(ATTRIBUTE_NAME_TOOL_CALL_ID, toolCallId);
48734
+ }
48735
+ if (status === "error" /* Error */ || !!err) {
48736
+ this.incrementToolCallErrors();
48737
+ span.setAttribute(ATTRIBUTE_NAME_TOOL_CALL_IS_ERROR, true);
48738
+ span.setAttribute(ATTRIBUTE_NAME_TOOL_CALL_IS_SUCCESS, false);
48739
+ } else if (status === "success" /* Success */) {
48740
+ span.setAttribute(ATTRIBUTE_NAME_TOOL_CALL_IS_SUCCESS, true);
48741
+ span.setAttribute(ATTRIBUTE_NAME_TOOL_CALL_IS_ERROR, false);
48742
+ }
48743
+ if (err && err instanceof Error) {
48744
+ span.setAttribute(ATTRIBUTE_NAME_ERROR_MESSAGE, `${err}`);
48745
+ span.setAttribute(ATTRIBUTE_NAME_ERROR_TYPE, `${err.constructor.name}`);
48746
+ }
48747
+ span.end();
48748
+ }
48749
+ validateToolArgs(parsedToolArgs) {
48750
+ const isPlainObject2 = typeof parsedToolArgs === "object" && parsedToolArgs !== null && !Array.isArray(parsedToolArgs) && (Object.getPrototypeOf(parsedToolArgs) === Object.prototype || Object.getPrototypeOf(parsedToolArgs) === null);
48751
+ const toolArgs = isPlainObject2 ? parsedToolArgs : {};
48752
+ return toolArgs;
48753
+ }
48670
48754
  decideToolCall({
48671
48755
  toolCall,
48672
48756
  agentState
@@ -48723,13 +48807,28 @@ class FriskSession {
48723
48807
  }
48724
48808
  });
48725
48809
  }
48726
- initTracing({ runId, inputs }) {
48810
+ *createToolCallSequenceGenerator() {
48811
+ while (true) {
48812
+ yield this.toolCallSequenceNumber++;
48813
+ }
48814
+ }
48815
+ getToolCallCount() {
48816
+ return this.toolCallSequenceNumber;
48817
+ }
48818
+ incrementToolCallErrors() {
48819
+ this.toolCallErrorCount += 1;
48820
+ }
48821
+ getToolCallErrorCount() {
48822
+ return this.toolCallErrorCount;
48823
+ }
48824
+ initTracing({ runId, agentState }) {
48727
48825
  this._rootRunId = runId;
48728
48826
  this._isTracing = true;
48827
+ this._agentState = agentState;
48729
48828
  const span = this.tracer.startSpan(SPAN_NAME_FRISK_SESSION);
48730
48829
  span.setAttribute(ATTRIBUTE_NAME_SESSION_ID, this.id);
48731
48830
  span.setAttribute(ATTRIBUTE_NAME_REMOTE_SESSION_ID, runId);
48732
- const userPrompt = this.frisk.adapter.extractPrompt?.(inputs);
48831
+ const userPrompt = this.frisk.adapter.extractPrompt?.(agentState);
48733
48832
  if (userPrompt) {
48734
48833
  span.setAttribute(ATTRIBUTE_NAME_SESSION_PROMPT, userPrompt);
48735
48834
  }
@@ -48738,6 +48837,8 @@ class FriskSession {
48738
48837
  }
48739
48838
  endTracing() {
48740
48839
  if (this._rootSpan) {
48840
+ this._rootSpan.setAttribute(ATTRIBUTE_NAME_TOOL_CALL_COUNT, this.getToolCallCount());
48841
+ this._rootSpan.setAttribute(ATTRIBUTE_NAME_TOOL_CALL_ERROR_COUNT, this.getToolCallErrorCount());
48741
48842
  this._rootSpan.end();
48742
48843
  }
48743
48844
  this._isTracing = false;
@@ -48787,12 +48888,12 @@ function detectRuntime() {
48787
48888
 
48788
48889
  // src/core/sdk-attributes/read-sdk-meta.ts
48789
48890
  import { existsSync, readFileSync } from "node:fs";
48790
- import { dirname as dirname2, join } from "node:path";
48891
+ import { dirname, join } from "node:path";
48791
48892
  import { fileURLToPath } from "node:url";
48792
48893
 
48793
48894
  // src/generated/sdk-meta.ts
48794
48895
  var SDK_NAME = "@friskai/frisk-js";
48795
- var SDK_VERSION = "0.2.8";
48896
+ var SDK_VERSION = "0.3.0";
48796
48897
 
48797
48898
  // src/core/sdk-attributes/read-sdk-meta.ts
48798
48899
  function getSdkMeta() {
@@ -48826,7 +48927,7 @@ function findNearestPackageJson(startDir) {
48826
48927
  if (existsSync(candidate)) {
48827
48928
  return candidate;
48828
48929
  }
48829
- const parent = dirname2(dir);
48930
+ const parent = dirname(dir);
48830
48931
  if (parent === dir) {
48831
48932
  return null;
48832
48933
  }
@@ -48835,7 +48936,7 @@ function findNearestPackageJson(startDir) {
48835
48936
  }
48836
48937
  function tryReadPackageJson() {
48837
48938
  try {
48838
- const here = dirname2(fileURLToPath(import.meta.url));
48939
+ const here = dirname(fileURLToPath(import.meta.url));
48839
48940
  const pkgPath = findNearestPackageJson(here);
48840
48941
  if (!pkgPath)
48841
48942
  return null;
@@ -49203,6 +49304,9 @@ class ToolRegistry {
49203
49304
 
49204
49305
  // src/core/frisk.ts
49205
49306
  class Frisk {
49307
+ get toolPoliciesAvailable() {
49308
+ return this.toolPolicies?.available ?? false;
49309
+ }
49206
49310
  get redaction() {
49207
49311
  return this._redaction;
49208
49312
  }
@@ -49210,24 +49314,34 @@ class Frisk {
49210
49314
  apiBaseUrl;
49211
49315
  otlpEndpoint;
49212
49316
  accessTokenProvider;
49317
+ get adapter() {
49318
+ return this._adapter;
49319
+ }
49320
+ get logLevel() {
49321
+ return this._logLevel;
49322
+ }
49323
+ get tracingManager() {
49324
+ if (!this._tracingManager) {
49325
+ throw new FriskNotInitializedError;
49326
+ }
49327
+ return this._tracingManager;
49328
+ }
49213
49329
  initialized = false;
49214
49330
  rootLogger;
49215
49331
  logger;
49216
49332
  _logLevel;
49217
49333
  _adapter;
49218
- _friskHandle = null;
49219
49334
  _tracingManager = null;
49220
- _toolRegistry;
49335
+ toolRegistry;
49221
49336
  sdkAttributes;
49337
+ extensions = [];
49338
+ toolPolicies = null;
49222
49339
  wrapToolsCalled = false;
49223
49340
  get toolRegistrationComplete() {
49224
49341
  if (!this.wrapToolsCalled) {
49225
49342
  return Promise.resolve(true);
49226
49343
  }
49227
- return this._toolRegistry.initialized;
49228
- }
49229
- get logLevel() {
49230
- return this._logLevel;
49344
+ return this.toolRegistry.initialized;
49231
49345
  }
49232
49346
  static async connect(options) {
49233
49347
  const instance = new this(options);
@@ -49241,7 +49355,7 @@ class Frisk {
49241
49355
  this._logLevel = options?.logging?.logLevel;
49242
49356
  this.logger = deriveSdkLogger({
49243
49357
  logger: this.rootLogger,
49244
- logLevel: this._logLevel
49358
+ logLevel: this.logLevel
49245
49359
  }, {
49246
49360
  component: "FriskCore"
49247
49361
  });
@@ -49261,10 +49375,10 @@ class Frisk {
49261
49375
  baseUrl,
49262
49376
  logging: {
49263
49377
  logger: this.rootLogger,
49264
- logLevel: this._logLevel
49378
+ logLevel: this.logLevel
49265
49379
  }
49266
49380
  });
49267
- this._toolRegistry = new ToolRegistry({
49381
+ this.toolRegistry = new ToolRegistry({
49268
49382
  apiBaseUrl: baseUrl,
49269
49383
  getAccessToken: async () => this.accessTokenProvider.getAccessToken(),
49270
49384
  logger: this.logger
@@ -49275,21 +49389,20 @@ class Frisk {
49275
49389
  }
49276
49390
  this.otlpEndpoint = otlpEndpoint;
49277
49391
  this._redaction = resolveRedactionOptions(options?.redact);
49392
+ this.extensions = options?.extensions ?? [];
49393
+ this.mountExtensions();
49278
49394
  }
49279
- get friskHandle() {
49280
- if (!this._friskHandle) {
49281
- throw new FriskNotInitializedError;
49395
+ mountExtensions() {
49396
+ for (const ext of this.extensions) {
49397
+ if ("available" in ext && "decideToolCall" in ext) {
49398
+ this.toolPolicies = ext;
49399
+ }
49282
49400
  }
49283
- return this._friskHandle;
49284
- }
49285
- get adapter() {
49286
- return this._adapter;
49287
49401
  }
49288
- get tracingManager() {
49289
- if (!this._tracingManager) {
49290
- throw new FriskNotInitializedError;
49402
+ async initializeExtensions() {
49403
+ for (const ext of this.extensions) {
49404
+ await ext.initialize(this);
49291
49405
  }
49292
- return this._tracingManager;
49293
49406
  }
49294
49407
  async connect() {
49295
49408
  if (!this.initialized) {
@@ -49303,20 +49416,20 @@ class Frisk {
49303
49416
  tracerName: TRACER_NAME,
49304
49417
  tracerVersion: TRACER_VERSION
49305
49418
  });
49306
- this._friskHandle = new FriskHandle(currentToken, this.apiBaseUrl, this.otlpEndpoint);
49307
49419
  this.accessTokenProvider.addCallback((newToken) => this.updateAccessToken(newToken));
49308
49420
  this.accessTokenProvider.startBackgroundRefresh();
49309
49421
  this.initialized = true;
49422
+ await this.initializeExtensions();
49310
49423
  }
49311
49424
  }
49312
49425
  session(metadata) {
49313
49426
  const session = new FriskSession({
49314
49427
  frisk: this,
49315
- redact: this._redaction,
49428
+ redact: this.redaction,
49316
49429
  tracer: this.tracingManager.getTracer(),
49317
49430
  logging: {
49318
49431
  logger: this.rootLogger,
49319
- logLevel: this._logLevel
49432
+ logLevel: this.logLevel
49320
49433
  }
49321
49434
  });
49322
49435
  const registry2 = SessionRegistry.getInstance();
@@ -49324,20 +49437,20 @@ class Frisk {
49324
49437
  return session;
49325
49438
  }
49326
49439
  normalizeToolCall(toolCall) {
49327
- return this._adapter.normalizeToolCall(toolCall);
49440
+ return this.adapter.normalizeToolCall(toolCall);
49328
49441
  }
49329
49442
  wrapTools(tools, options = DefaultWrapToolOptions) {
49330
49443
  this.wrapToolsCalled = true;
49331
49444
  const toolList = [...tools];
49332
- const registerToolProperties = toolList.map((tool) => this._adapter.extractRegisterToolProperties?.(tool)).filter((properties) => properties !== null && properties !== undefined);
49445
+ const registerToolProperties = toolList.map((tool) => this.adapter.extractRegisterToolProperties?.(tool)).filter((properties) => properties !== null && properties !== undefined);
49333
49446
  if (registerToolProperties.length > 0) {
49334
- this._toolRegistry.registerTools({
49447
+ this.toolRegistry.registerTools({
49335
49448
  tools: registerToolProperties,
49336
49449
  sdkAttributes: this.sdkAttributes
49337
49450
  });
49338
49451
  }
49339
- if (this._adapter.wrapTools) {
49340
- return this._adapter.wrapTools(toolList, options);
49452
+ if (this.adapter.wrapTools) {
49453
+ return this.adapter.wrapTools(toolList, options);
49341
49454
  }
49342
49455
  return toolList;
49343
49456
  }
@@ -49349,8 +49462,8 @@ class Frisk {
49349
49462
  };
49350
49463
  }
49351
49464
  wrapTool(tool, options = DefaultWrapToolOptions) {
49352
- if (this._adapter.wrapTool) {
49353
- return this._adapter.wrapTool(tool, options);
49465
+ if (this.adapter.wrapTool) {
49466
+ return this.adapter.wrapTool(tool, options);
49354
49467
  }
49355
49468
  return tool;
49356
49469
  }
@@ -49359,30 +49472,38 @@ class Frisk {
49359
49472
  return registry2.get(sessionId);
49360
49473
  }
49361
49474
  updateAccessToken(authToken) {
49362
- this.friskHandle.updateAuthToken(authToken);
49475
+ this.toolPolicies?.updateAccessToken(authToken);
49363
49476
  this.tracingManager.updateAuthToken(authToken);
49364
49477
  }
49365
49478
  getRegisteredTool(toolName) {
49366
- return this._toolRegistry.getRegisteredTool(toolName);
49479
+ return this.toolRegistry.getRegisteredTool(toolName);
49367
49480
  }
49368
49481
  decideToolCall({
49369
49482
  toolCall,
49370
49483
  agentState,
49371
49484
  traceContextCarrier
49372
49485
  }) {
49373
- const id = toolCall.id ?? v4();
49374
- const argsJson = toolCall.args ? JSON.stringify(removeLlmReasoningArg(toolCall.args)) : null;
49375
- const stateJson = agentState ? JSON.stringify(agentState) : null;
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);
49378
- const outcome = coreResult.decision === "allow" ? "allow" /* ALLOW */ : coreResult.decision === "deny" ? "deny" /* DENY */ : coreResult.decision === "escalate" ? "escalate" /* ESCALATE */ : "error" /* ERROR */;
49379
- return {
49380
- outcome,
49381
- rulesMatchedCount: coreResult.rulesMatchedCount,
49382
- reason: coreResult.reason,
49383
- policyId: coreResult.policyId,
49384
- policyVersionId: coreResult.policyVersionId
49385
- };
49486
+ if (!this.toolPolicies) {
49487
+ throw new MissingToolPoliciesExtensionError;
49488
+ }
49489
+ const toolArgsJson = toolCall.args ? JSON.stringify(toolCall.args) : null;
49490
+ const agentStateJson = agentState ? JSON.stringify(agentState) : null;
49491
+ const redactedArgs = toolCall.args ? redactObject(toolCall.args, this.redaction.redactToolArgs) : { value: {}, redactedPaths: [] };
49492
+ const toolArgsRedactedJson = toolCall.args ? JSON.stringify(redactedArgs.value) : null;
49493
+ const toolArgsRedactedPathsJson = JSON.stringify(redactedArgs.redactedPaths);
49494
+ const redactedState = agentState ? redactObject(agentState, this.redaction.redactAgentState) : { value: {}, redactedPaths: [] };
49495
+ const agentStateRedactedJson = agentState ? JSON.stringify(redactedState.value) : null;
49496
+ const agentStateRedactedPathsJson = JSON.stringify(redactedState.redactedPaths);
49497
+ return this.toolPolicies.decideToolCall({
49498
+ toolCall,
49499
+ toolArgsJson,
49500
+ toolArgsRedactedJson,
49501
+ toolArgsRedactedPathsJson,
49502
+ agentStateJson,
49503
+ agentStateRedactedJson,
49504
+ agentStateRedactedPathsJson,
49505
+ traceContextCarrier
49506
+ });
49386
49507
  }
49387
49508
  async getOrCreateToolApprovalRequest({
49388
49509
  toolCallId,
@@ -49430,13 +49551,13 @@ class Frisk {
49430
49551
  if (this.tracingManager) {
49431
49552
  await this.tracingManager.shutdown();
49432
49553
  }
49433
- this.friskHandle.shutdown();
49554
+ for (const ext of this.extensions) {
49555
+ ext.shutdown();
49556
+ }
49434
49557
  }
49435
49558
  }
49436
49559
  export {
49437
49560
  requireEnv,
49438
- redactDictionarySimple,
49439
- redactDictionary,
49440
49561
  getEnv,
49441
49562
  combineRedactOptions,
49442
49563
  UnexpectedFriskServerResponseError,
@@ -49452,7 +49573,6 @@ export {
49452
49573
  InvalidAccessTokenError,
49453
49574
  FriskSession,
49454
49575
  FriskInvalidAPIKeyError,
49455
- FriskHandle,
49456
49576
  FriskError,
49457
49577
  FriskBaseURLNotFoundError,
49458
49578
  Frisk,
@@ -49466,5 +49586,5 @@ export {
49466
49586
  AccessTokenProvider
49467
49587
  };
49468
49588
 
49469
- //# debugId=59297CD6351BA8FC64756E2164756E21
49589
+ //# debugId=2B56BC442CE3397564756E2164756E21
49470
49590
  //# sourceMappingURL=index.js.map