@alpic80/rivet-ai-sdk-provider 2.0.3 → 2.0.4

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/index.js CHANGED
@@ -1019,6 +1019,7 @@ var rivetFailedResponseHandler = createJsonErrorResponseHandler({
1019
1019
  });
1020
1020
 
1021
1021
  // src/utils.ts
1022
+ var isDebug = process.env.RIVET_AI_PROVIDER_DEBUG === "true";
1022
1023
  function printObject(obj) {
1023
1024
  const seen = /* @__PURE__ */ new WeakSet();
1024
1025
  return JSON.stringify(
@@ -1039,6 +1040,11 @@ function printObject(obj) {
1039
1040
  // Indentation level for pretty-printing
1040
1041
  );
1041
1042
  }
1043
+ var debugLog = (...args) => {
1044
+ if (isDebug) {
1045
+ console.log(...args);
1046
+ }
1047
+ };
1042
1048
 
1043
1049
  // src/rivet-prepare-tools.ts
1044
1050
  async function prepareTools({
@@ -1051,7 +1057,7 @@ async function prepareTools({
1051
1057
  if (tools == null) {
1052
1058
  return { tools: void 0, toolSchemas: void 0, toolChoice: void 0, toolWarnings };
1053
1059
  }
1054
- console.log(`
1060
+ debugLog(`
1055
1061
 
1056
1062
  prepare tools input:${printObject(tools)}`);
1057
1063
  const rivetTools = [];
@@ -1081,7 +1087,7 @@ prepare tools input:${printObject(tools)}`);
1081
1087
  }
1082
1088
  }
1083
1089
  }
1084
- console.log(`rivetSchemas:${printObject(rivetSchemas)}`);
1090
+ debugLog(`rivetSchemas:${printObject(rivetSchemas)}`);
1085
1091
  if (toolChoice == null) {
1086
1092
  return { tools: rivetTools, toolSchemas: rivetSchemas, toolChoice: void 0, toolWarnings };
1087
1093
  }
@@ -1109,7 +1115,7 @@ prepare tools input:${printObject(tools)}`);
1109
1115
  }
1110
1116
 
1111
1117
  // src/version.ts
1112
- var VERSION = true ? "2.0.3" : "0.0.0-test";
1118
+ var VERSION = true ? "2.0.4" : "0.0.0-test";
1113
1119
 
1114
1120
  // src/post-to-api.ts
1115
1121
  var getOriginalFetch = () => globalThis.fetch;
@@ -1258,7 +1264,7 @@ function parseJsonEventStream({
1258
1264
  return stream.pipeThrough(new TransformStream({
1259
1265
  transform(chunk, controller) {
1260
1266
  const decoded = new TextDecoder().decode(chunk);
1261
- console.log(`Decoded:${printObject(decoded)}`);
1267
+ debugLog(`Decoded:${printObject(decoded)}`);
1262
1268
  controller.enqueue(decoded);
1263
1269
  }
1264
1270
  })).pipeThrough(new EventSourceParserStream()).pipeThrough(
@@ -1267,7 +1273,7 @@ function parseJsonEventStream({
1267
1273
  if (data === "[DONE]") {
1268
1274
  return;
1269
1275
  }
1270
- console.log(`Data to schema:${printObject(data)}`);
1276
+ debugLog(`Data to schema:${printObject(data)}`);
1271
1277
  controller.enqueue(await safeParseJSON({ text: data, schema }));
1272
1278
  }
1273
1279
  })
@@ -1323,13 +1329,13 @@ var RivetChatLanguageModel = class {
1323
1329
  runParams: {},
1324
1330
  chatConfig: {}
1325
1331
  };
1326
- console.log(`providerOptions:${printObject(providerOptions)}`);
1332
+ debugLog(`providerOptions:${printObject(providerOptions)}`);
1327
1333
  const options = (_a15 = await parseProviderOptions({
1328
1334
  provider: "rivet",
1329
1335
  providerOptions,
1330
1336
  schema: rivetLanguageModelOptions
1331
1337
  })) != null ? _a15 : emptyOptions;
1332
- console.log(`options:${printObject(options)}`);
1338
+ debugLog(`options:${printObject(options)}`);
1333
1339
  const {
1334
1340
  tools: rivetTools,
1335
1341
  toolSchemas: rivetSchemas,
@@ -1454,7 +1460,7 @@ var RivetChatLanguageModel = class {
1454
1460
  var _a15;
1455
1461
  const { args, warnings } = await this.getArgs(options);
1456
1462
  const body = args;
1457
- console.log(`body:${printObject(body)}`);
1463
+ debugLog(`body:${printObject(body)}`);
1458
1464
  const headers = combineHeaders(this.config.headers(), options.headers);
1459
1465
  let responseId = (_a15 = headers["X-Completion-Id"]) != null ? _a15 : this.generateId();
1460
1466
  const model = this.modelId;
@@ -1756,7 +1762,7 @@ var rivetChatChunkSchema = import_v43.z.object({
1756
1762
  });
1757
1763
  function createRivetEventSourceResponseHandler(id, model) {
1758
1764
  return createEventSourceResponseHandler(import_v43.z.any().transform((data) => {
1759
- console.log(`SSE event received:${printObject(data)}`);
1765
+ debugLog(`SSE event received:${printObject(data)}`);
1760
1766
  return mapRivetEventToOpenAIChunk(data, id, model);
1761
1767
  }));
1762
1768
  }
@@ -1821,7 +1827,7 @@ function mapRivetEventToOpenAIChunk(eventData, id, model) {
1821
1827
  usage: toOpenAIUsage((_q = (_p = (_o = eventData.graphOutput.usages) == null ? void 0 : _o.value) == null ? void 0 : _p[0]) == null ? void 0 : _q.value)
1822
1828
  };
1823
1829
  default:
1824
- console.log(`failling on default for type:${printObject(eventType)}`);
1830
+ debugLog(`falling on default for type:${printObject(eventType)}`);
1825
1831
  return {
1826
1832
  id,
1827
1833
  created: Math.floor(Date.now() / 1e3),
@@ -1842,7 +1848,7 @@ function mapRivetEventToOpenAIChunk(eventData, id, model) {
1842
1848
  }
1843
1849
  }
1844
1850
  var toOpenAIUsage = (usage) => {
1845
- console.log(`Usage to convert:${printObject(usage)}`);
1851
+ debugLog(`Usage to convert:${printObject(usage)}`);
1846
1852
  return usage ? {
1847
1853
  prompt_tokens: usage.prompt_tokens,
1848
1854
  completion_tokens: usage.completion_tokens,