@alpic80/rivet-ai-sdk-provider 2.0.2 → 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 +24 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,12 +1762,12 @@ 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
|
-
|
|
1765
|
+
debugLog(`SSE event received:${printObject(data)}`);
|
|
1760
1766
|
return mapRivetEventToOpenAIChunk(data, id, model);
|
|
1761
1767
|
}));
|
|
1762
1768
|
}
|
|
1763
1769
|
function mapRivetEventToOpenAIChunk(eventData, id, model) {
|
|
1764
|
-
var _a15, _b, _c, _d, _e, _f, _g, _h;
|
|
1770
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1765
1771
|
const eventType = eventData.type;
|
|
1766
1772
|
switch (eventType) {
|
|
1767
1773
|
case "partialOutput":
|
|
@@ -1783,6 +1789,8 @@ function mapRivetEventToOpenAIChunk(eventData, id, model) {
|
|
|
1783
1789
|
usage: void 0
|
|
1784
1790
|
};
|
|
1785
1791
|
case "nodeFinish":
|
|
1792
|
+
const rawContent = (_g = (_f = (_c = (_b = eventData.outputs) == null ? void 0 : _b.response) == null ? void 0 : _c.value) != null ? _f : (_e = (_d = eventData.outputs) == null ? void 0 : _d.valueOutput) == null ? void 0 : _e.value) != null ? _g : void 0;
|
|
1793
|
+
const delta = typeof rawContent === "string" ? rawContent : rawContent !== void 0 ? JSON.stringify(rawContent) : void 0;
|
|
1786
1794
|
return {
|
|
1787
1795
|
id,
|
|
1788
1796
|
created: Math.floor(Date.now() / 1e3),
|
|
@@ -1791,14 +1799,14 @@ function mapRivetEventToOpenAIChunk(eventData, id, model) {
|
|
|
1791
1799
|
{
|
|
1792
1800
|
delta: {
|
|
1793
1801
|
role: "assistant",
|
|
1794
|
-
content:
|
|
1802
|
+
content: delta != null ? delta : "",
|
|
1795
1803
|
tool_calls: void 0
|
|
1796
1804
|
},
|
|
1797
1805
|
finish_reason: null,
|
|
1798
1806
|
index: 0
|
|
1799
1807
|
}
|
|
1800
1808
|
],
|
|
1801
|
-
usage: void 0
|
|
1809
|
+
usage: toOpenAIUsage((_k = (_j = (_i = (_h = eventData == null ? void 0 : eventData.output) == null ? void 0 : _h.usages) == null ? void 0 : _i.value) == null ? void 0 : _j[0]) == null ? void 0 : _k.value)
|
|
1802
1810
|
};
|
|
1803
1811
|
case "done":
|
|
1804
1812
|
return {
|
|
@@ -1809,16 +1817,17 @@ function mapRivetEventToOpenAIChunk(eventData, id, model) {
|
|
|
1809
1817
|
{
|
|
1810
1818
|
delta: {
|
|
1811
1819
|
role: "assistant",
|
|
1812
|
-
content: (
|
|
1820
|
+
content: (_n = (_m = (_l = eventData.graphOutput) == null ? void 0 : _l.response) == null ? void 0 : _m.value) != null ? _n : "",
|
|
1813
1821
|
tool_calls: void 0
|
|
1814
1822
|
},
|
|
1815
1823
|
finish_reason: "stop",
|
|
1816
1824
|
index: 0
|
|
1817
1825
|
}
|
|
1818
1826
|
],
|
|
1819
|
-
usage: toOpenAIUsage((
|
|
1827
|
+
usage: toOpenAIUsage((_q = (_p = (_o = eventData.graphOutput.usages) == null ? void 0 : _o.value) == null ? void 0 : _p[0]) == null ? void 0 : _q.value)
|
|
1820
1828
|
};
|
|
1821
1829
|
default:
|
|
1830
|
+
debugLog(`falling on default for type:${printObject(eventType)}`);
|
|
1822
1831
|
return {
|
|
1823
1832
|
id,
|
|
1824
1833
|
created: Math.floor(Date.now() / 1e3),
|
|
@@ -1839,7 +1848,7 @@ function mapRivetEventToOpenAIChunk(eventData, id, model) {
|
|
|
1839
1848
|
}
|
|
1840
1849
|
}
|
|
1841
1850
|
var toOpenAIUsage = (usage) => {
|
|
1842
|
-
|
|
1851
|
+
debugLog(`Usage to convert:${printObject(usage)}`);
|
|
1843
1852
|
return usage ? {
|
|
1844
1853
|
prompt_tokens: usage.prompt_tokens,
|
|
1845
1854
|
completion_tokens: usage.completion_tokens,
|