@alpic80/rivet-ai-sdk-provider 2.0.3 → 2.0.5
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.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +43 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -5
package/dist/index.d.mts
CHANGED
|
@@ -53,6 +53,10 @@ declare const rivetLanguageModelOptions: z.ZodObject<{
|
|
|
53
53
|
pcm16: "pcm16";
|
|
54
54
|
}>>;
|
|
55
55
|
}, z.core.$strip>;
|
|
56
|
+
rivetInputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
57
|
+
type: z.ZodString;
|
|
58
|
+
value: z.ZodUnknown;
|
|
59
|
+
}, z.core.$strip>>>;
|
|
56
60
|
}, z.core.$strip>;
|
|
57
61
|
type RivetLanguageModelOptions = z.infer<typeof rivetLanguageModelOptions>;
|
|
58
62
|
|
package/dist/index.d.ts
CHANGED
|
@@ -53,6 +53,10 @@ declare const rivetLanguageModelOptions: z.ZodObject<{
|
|
|
53
53
|
pcm16: "pcm16";
|
|
54
54
|
}>>;
|
|
55
55
|
}, z.core.$strip>;
|
|
56
|
+
rivetInputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
57
|
+
type: z.ZodString;
|
|
58
|
+
value: z.ZodUnknown;
|
|
59
|
+
}, z.core.$strip>>>;
|
|
56
60
|
}, z.core.$strip>;
|
|
57
61
|
type RivetLanguageModelOptions = z.infer<typeof rivetLanguageModelOptions>;
|
|
58
62
|
|
package/dist/index.js
CHANGED
|
@@ -942,6 +942,14 @@ var rivetRunParamsSchema = import_v4.z.object({
|
|
|
942
942
|
streamNode: import_v4.z.string().optional(),
|
|
943
943
|
events: import_v4.z.string().optional()
|
|
944
944
|
});
|
|
945
|
+
var graphInputSchema = import_v4.z.record(
|
|
946
|
+
import_v4.z.string(),
|
|
947
|
+
// key type
|
|
948
|
+
import_v4.z.object({
|
|
949
|
+
type: import_v4.z.string(),
|
|
950
|
+
value: import_v4.z.unknown()
|
|
951
|
+
})
|
|
952
|
+
).optional();
|
|
945
953
|
var standardChatConfigSchema = import_v4.z.object({
|
|
946
954
|
temperature: import_v4.z.number().optional(),
|
|
947
955
|
top_p: import_v4.z.number().optional(),
|
|
@@ -989,7 +997,8 @@ var rivetCustomChatConfigSchema = import_v4.z.object({
|
|
|
989
997
|
});
|
|
990
998
|
var rivetLanguageModelOptions = import_v4.z.object({
|
|
991
999
|
runParams: rivetRunParamsSchema,
|
|
992
|
-
chatConfig: rivetCustomChatConfigSchema
|
|
1000
|
+
chatConfig: rivetCustomChatConfigSchema,
|
|
1001
|
+
rivetInputs: graphInputSchema
|
|
993
1002
|
});
|
|
994
1003
|
var rivetChatConfigSchema = standardChatConfigSchema.merge(rivetCustomChatConfigSchema);
|
|
995
1004
|
var rivetToolOptions = import_v4.z.record(
|
|
@@ -1019,6 +1028,7 @@ var rivetFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
1019
1028
|
});
|
|
1020
1029
|
|
|
1021
1030
|
// src/utils.ts
|
|
1031
|
+
var isDebug = process.env.RIVET_AI_PROVIDER_DEBUG === "true";
|
|
1022
1032
|
function printObject(obj) {
|
|
1023
1033
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
1024
1034
|
return JSON.stringify(
|
|
@@ -1039,6 +1049,11 @@ function printObject(obj) {
|
|
|
1039
1049
|
// Indentation level for pretty-printing
|
|
1040
1050
|
);
|
|
1041
1051
|
}
|
|
1052
|
+
var debugLog = (...args) => {
|
|
1053
|
+
if (isDebug) {
|
|
1054
|
+
console.log(...args);
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1042
1057
|
|
|
1043
1058
|
// src/rivet-prepare-tools.ts
|
|
1044
1059
|
async function prepareTools({
|
|
@@ -1051,7 +1066,7 @@ async function prepareTools({
|
|
|
1051
1066
|
if (tools == null) {
|
|
1052
1067
|
return { tools: void 0, toolSchemas: void 0, toolChoice: void 0, toolWarnings };
|
|
1053
1068
|
}
|
|
1054
|
-
|
|
1069
|
+
debugLog(`
|
|
1055
1070
|
|
|
1056
1071
|
prepare tools input:${printObject(tools)}`);
|
|
1057
1072
|
const rivetTools = [];
|
|
@@ -1081,7 +1096,7 @@ prepare tools input:${printObject(tools)}`);
|
|
|
1081
1096
|
}
|
|
1082
1097
|
}
|
|
1083
1098
|
}
|
|
1084
|
-
|
|
1099
|
+
debugLog(`rivetSchemas:${printObject(rivetSchemas)}`);
|
|
1085
1100
|
if (toolChoice == null) {
|
|
1086
1101
|
return { tools: rivetTools, toolSchemas: rivetSchemas, toolChoice: void 0, toolWarnings };
|
|
1087
1102
|
}
|
|
@@ -1109,7 +1124,7 @@ prepare tools input:${printObject(tools)}`);
|
|
|
1109
1124
|
}
|
|
1110
1125
|
|
|
1111
1126
|
// src/version.ts
|
|
1112
|
-
var VERSION = true ? "2.0.
|
|
1127
|
+
var VERSION = true ? "2.0.5" : "0.0.0-test";
|
|
1113
1128
|
|
|
1114
1129
|
// src/post-to-api.ts
|
|
1115
1130
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -1258,7 +1273,7 @@ function parseJsonEventStream({
|
|
|
1258
1273
|
return stream.pipeThrough(new TransformStream({
|
|
1259
1274
|
transform(chunk, controller) {
|
|
1260
1275
|
const decoded = new TextDecoder().decode(chunk);
|
|
1261
|
-
|
|
1276
|
+
debugLog(`Decoded:${printObject(decoded)}`);
|
|
1262
1277
|
controller.enqueue(decoded);
|
|
1263
1278
|
}
|
|
1264
1279
|
})).pipeThrough(new EventSourceParserStream()).pipeThrough(
|
|
@@ -1267,7 +1282,7 @@ function parseJsonEventStream({
|
|
|
1267
1282
|
if (data === "[DONE]") {
|
|
1268
1283
|
return;
|
|
1269
1284
|
}
|
|
1270
|
-
|
|
1285
|
+
debugLog(`Data to schema:${printObject(data)}`);
|
|
1271
1286
|
controller.enqueue(await safeParseJSON({ text: data, schema }));
|
|
1272
1287
|
}
|
|
1273
1288
|
})
|
|
@@ -1317,19 +1332,20 @@ var RivetChatLanguageModel = class {
|
|
|
1317
1332
|
toolChoice
|
|
1318
1333
|
//in Rivet tool section
|
|
1319
1334
|
}) {
|
|
1320
|
-
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1335
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1321
1336
|
const warnings = [];
|
|
1322
1337
|
const emptyOptions = {
|
|
1323
1338
|
runParams: {},
|
|
1324
|
-
chatConfig: {}
|
|
1339
|
+
chatConfig: {},
|
|
1340
|
+
rivetInputs: {}
|
|
1325
1341
|
};
|
|
1326
|
-
|
|
1342
|
+
debugLog(`providerOptions:${printObject(providerOptions)}`);
|
|
1327
1343
|
const options = (_a15 = await parseProviderOptions({
|
|
1328
1344
|
provider: "rivet",
|
|
1329
1345
|
providerOptions,
|
|
1330
1346
|
schema: rivetLanguageModelOptions
|
|
1331
1347
|
})) != null ? _a15 : emptyOptions;
|
|
1332
|
-
|
|
1348
|
+
debugLog(`options:${printObject(options)}`);
|
|
1333
1349
|
const {
|
|
1334
1350
|
tools: rivetTools,
|
|
1335
1351
|
toolSchemas: rivetSchemas,
|
|
@@ -1338,15 +1354,16 @@ var RivetChatLanguageModel = class {
|
|
|
1338
1354
|
} = await prepareTools({ tools, toolChoice });
|
|
1339
1355
|
options.runParams = (_b = options.runParams) != null ? _b : {};
|
|
1340
1356
|
options.chatConfig = (_c = options.chatConfig) != null ? _c : {};
|
|
1357
|
+
options.rivetInputs = (_d = options.rivetInputs) != null ? _d : {};
|
|
1341
1358
|
const chatConfig = __spreadValues({}, options.chatConfig);
|
|
1342
|
-
chatConfig.maxTokens = (
|
|
1343
|
-
chatConfig.temperature = (
|
|
1344
|
-
chatConfig.top_p = (
|
|
1345
|
-
chatConfig.top_k = (
|
|
1346
|
-
chatConfig.stop_sequences = (
|
|
1347
|
-
chatConfig.frequencyPenalty = (
|
|
1348
|
-
chatConfig.presencePenalty = (
|
|
1349
|
-
chatConfig.seed = (
|
|
1359
|
+
chatConfig.maxTokens = (_e = chatConfig.maxTokens) != null ? _e : maxOutputTokens;
|
|
1360
|
+
chatConfig.temperature = (_f = chatConfig.temperature) != null ? _f : temperature;
|
|
1361
|
+
chatConfig.top_p = (_g = chatConfig.top_p) != null ? _g : topP;
|
|
1362
|
+
chatConfig.top_k = (_h = chatConfig.top_k) != null ? _h : topK;
|
|
1363
|
+
chatConfig.stop_sequences = (_i = chatConfig.stop_sequences) != null ? _i : stopSequences;
|
|
1364
|
+
chatConfig.frequencyPenalty = (_j = chatConfig.frequencyPenalty) != null ? _j : frequencyPenalty;
|
|
1365
|
+
chatConfig.presencePenalty = (_k = chatConfig.presencePenalty) != null ? _k : presencePenalty;
|
|
1366
|
+
chatConfig.seed = (_l = chatConfig.seed) != null ? _l : seed;
|
|
1350
1367
|
if (responseFormat) {
|
|
1351
1368
|
const isJson = (responseFormat == null ? void 0 : responseFormat.type) === "json";
|
|
1352
1369
|
const hasSchema = isJson && !!(responseFormat == null ? void 0 : responseFormat.schema);
|
|
@@ -1359,7 +1376,7 @@ var RivetChatLanguageModel = class {
|
|
|
1359
1376
|
}
|
|
1360
1377
|
const messages = convertToRivetChatMessages(prompt);
|
|
1361
1378
|
return {
|
|
1362
|
-
args: {
|
|
1379
|
+
args: __spreadValues({
|
|
1363
1380
|
chatConfig: {
|
|
1364
1381
|
type: "object",
|
|
1365
1382
|
value: chatConfig
|
|
@@ -1378,7 +1395,7 @@ var RivetChatLanguageModel = class {
|
|
|
1378
1395
|
value: rivetSchemas
|
|
1379
1396
|
},
|
|
1380
1397
|
runParams: __spreadValues({}, options.runParams)
|
|
1381
|
-
},
|
|
1398
|
+
}, (_m = options.rivetInputs) != null ? _m : {}),
|
|
1382
1399
|
warnings: [...warnings, ...toolWarnings]
|
|
1383
1400
|
};
|
|
1384
1401
|
}
|
|
@@ -1454,7 +1471,7 @@ var RivetChatLanguageModel = class {
|
|
|
1454
1471
|
var _a15;
|
|
1455
1472
|
const { args, warnings } = await this.getArgs(options);
|
|
1456
1473
|
const body = args;
|
|
1457
|
-
|
|
1474
|
+
debugLog(`body:${printObject(body)}`);
|
|
1458
1475
|
const headers = combineHeaders(this.config.headers(), options.headers);
|
|
1459
1476
|
let responseId = (_a15 = headers["X-Completion-Id"]) != null ? _a15 : this.generateId();
|
|
1460
1477
|
const model = this.modelId;
|
|
@@ -1698,8 +1715,8 @@ var rivetChatResponseSchema = import_v43.z.object({
|
|
|
1698
1715
|
usage: rivetUsageSchema
|
|
1699
1716
|
});
|
|
1700
1717
|
var rivetChatResponseHandler = (id, model) => async ({
|
|
1701
|
-
url,
|
|
1702
|
-
requestBodyValues,
|
|
1718
|
+
url: _url,
|
|
1719
|
+
requestBodyValues: _requestBodyValues,
|
|
1703
1720
|
response
|
|
1704
1721
|
}) => {
|
|
1705
1722
|
const raw = await response.json();
|
|
@@ -1756,7 +1773,7 @@ var rivetChatChunkSchema = import_v43.z.object({
|
|
|
1756
1773
|
});
|
|
1757
1774
|
function createRivetEventSourceResponseHandler(id, model) {
|
|
1758
1775
|
return createEventSourceResponseHandler(import_v43.z.any().transform((data) => {
|
|
1759
|
-
|
|
1776
|
+
debugLog(`SSE event received:${printObject(data)}`);
|
|
1760
1777
|
return mapRivetEventToOpenAIChunk(data, id, model);
|
|
1761
1778
|
}));
|
|
1762
1779
|
}
|
|
@@ -1821,7 +1838,7 @@ function mapRivetEventToOpenAIChunk(eventData, id, model) {
|
|
|
1821
1838
|
usage: toOpenAIUsage((_q = (_p = (_o = eventData.graphOutput.usages) == null ? void 0 : _o.value) == null ? void 0 : _p[0]) == null ? void 0 : _q.value)
|
|
1822
1839
|
};
|
|
1823
1840
|
default:
|
|
1824
|
-
|
|
1841
|
+
debugLog(`falling on default for type:${printObject(eventType)}`);
|
|
1825
1842
|
return {
|
|
1826
1843
|
id,
|
|
1827
1844
|
created: Math.floor(Date.now() / 1e3),
|
|
@@ -1842,7 +1859,7 @@ function mapRivetEventToOpenAIChunk(eventData, id, model) {
|
|
|
1842
1859
|
}
|
|
1843
1860
|
}
|
|
1844
1861
|
var toOpenAIUsage = (usage) => {
|
|
1845
|
-
|
|
1862
|
+
debugLog(`Usage to convert:${printObject(usage)}`);
|
|
1846
1863
|
return usage ? {
|
|
1847
1864
|
prompt_tokens: usage.prompt_tokens,
|
|
1848
1865
|
completion_tokens: usage.completion_tokens,
|