@databricks/ai-sdk-provider 0.4.1 → 0.5.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.
- package/dist/index.cjs +131 -77
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +77 -47
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -52,7 +52,8 @@ interface DatabricksProviderSettings {
|
|
|
52
52
|
*/
|
|
53
53
|
useRemoteToolCalling?: boolean;
|
|
54
54
|
}
|
|
55
|
-
declare const createDatabricksProvider: (settings: DatabricksProviderSettings) => DatabricksProvider;
|
|
56
|
-
|
|
55
|
+
declare const createDatabricksProvider: (settings: DatabricksProviderSettings) => DatabricksProvider; //#endregion
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=databricks-provider.d.ts.map
|
|
57
58
|
export { DatabricksLanguageModelConfig, DatabricksProvider, DatabricksProviderSettings, createDatabricksProvider };
|
|
58
59
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/databricks-provider.ts"],"mappings":";;;;KAMY,6BAAA
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/databricks-provider.ts"],"sourcesContent":null,"mappings":";;;;KAMY,6BAAA;;EAAA,OAAA,EAAA,GAAA,GAEK,MAFL,CAAA,MAAA,EAAA,MAA6B,GAAA,SAAA,CAAA;EAAA,GAAA,EAAA,CAAA,OAAA,EAAA;IAExB,IAAA,EAAA,MAAA;EAAM,CAAA,EAEb,GAAA,MAAA;EAAa,KAAA,CAAA,EAAb,aAAa;EASN;;;;;EAMkC,oBANP,CAAA,EAAA,OAAA;AAAU,CAAA;AAarC,UAbA,kBAAA,SAA2B,UAaD,CAAA;EAAA;EAAA,SAI/B,CAAA,OAAA,EAAA,MAAA,CAAA,EAfkB,eAelB;EAAM,SAQR,CAAA,OAAA,EAAA,MAAA,CAAA,EAtBoB,eAsBpB;EAAa;EAeV,eAAA,CAAA,OAAA,EAAA,MAqDZ,CAAA,EAvFmC,eAuFnC;EAAA;EAAA,kBApDW,CAAA,OAAA,EAAA,MAAA,CAAA,EAAA,KAAA;EAA0B,aACnC,CAAA,OAAA,EAAA,MAAA,CAAA,EAAA,KAAA;AAmDF;UAhFgB,0BAAA;;;;YAIL;;;;;;;UAQF;;;;;;;;;;;;;;;cAeG,qCACD,+BACT"}
|
package/dist/index.d.mts
CHANGED
|
@@ -52,7 +52,8 @@ interface DatabricksProviderSettings {
|
|
|
52
52
|
*/
|
|
53
53
|
useRemoteToolCalling?: boolean;
|
|
54
54
|
}
|
|
55
|
-
declare const createDatabricksProvider: (settings: DatabricksProviderSettings) => DatabricksProvider;
|
|
56
|
-
|
|
55
|
+
declare const createDatabricksProvider: (settings: DatabricksProviderSettings) => DatabricksProvider; //#endregion
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=databricks-provider.d.ts.map
|
|
57
58
|
export { DatabricksLanguageModelConfig, DatabricksProvider, DatabricksProviderSettings, createDatabricksProvider };
|
|
58
59
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/databricks-provider.ts"],"mappings":";;;;KAMY,6BAAA
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/databricks-provider.ts"],"sourcesContent":null,"mappings":";;;;KAMY,6BAAA;;EAAA,OAAA,EAAA,GAAA,GAEK,MAFL,CAAA,MAAA,EAAA,MAA6B,GAAA,SAAA,CAAA;EAAA,GAAA,EAAA,CAAA,OAAA,EAAA;IAExB,IAAA,EAAA,MAAA;EAAM,CAAA,EAEb,GAAA,MAAA;EAAa,KAAA,CAAA,EAAb,aAAa;EASN;;;;;EAMkC,oBANP,CAAA,EAAA,OAAA;AAAU,CAAA;AAarC,UAbA,kBAAA,SAA2B,UAaD,CAAA;EAAA;EAAA,SAI/B,CAAA,OAAA,EAAA,MAAA,CAAA,EAfkB,eAelB;EAAM,SAQR,CAAA,OAAA,EAAA,MAAA,CAAA,EAtBoB,eAsBpB;EAAa;EAeV,eAAA,CAAA,OAAA,EAAA,MAqDZ,CAAA,EAvFmC,eAuFnC;EAAA;EAAA,kBApDW,CAAA,OAAA,EAAA,MAAA,CAAA,EAAA,KAAA;EAA0B,aACnC,CAAA,OAAA,EAAA,MAAA,CAAA,EAAA,KAAA;AAmDF;UAhFgB,0BAAA;;;;YAIL;;;;;;;UAQF;;;;;;;;;;;;;;;cAeG,qCACD,+BACT"}
|
package/dist/index.mjs
CHANGED
|
@@ -127,9 +127,10 @@ const convertLanguageModelV3PromptToChatAgentResponse = (prompt) => {
|
|
|
127
127
|
return messages;
|
|
128
128
|
};
|
|
129
129
|
const convertUserMessage$1 = (msg, messageIndex) => {
|
|
130
|
+
const text = (msg.content ?? []).filter((part) => part.type === "text").map((part) => part.text).join("\n");
|
|
130
131
|
return {
|
|
131
132
|
role: "user",
|
|
132
|
-
content:
|
|
133
|
+
content: text,
|
|
133
134
|
id: `user-${messageIndex}`
|
|
134
135
|
};
|
|
135
136
|
};
|
|
@@ -202,7 +203,10 @@ const convertToolResultOutput = (output) => {
|
|
|
202
203
|
function composeDatabricksStreamPartTransformers(...transformers) {
|
|
203
204
|
return (initialParts, last = null) => {
|
|
204
205
|
let currentParts = initialParts;
|
|
205
|
-
for (const fn of transformers)
|
|
206
|
+
for (const fn of transformers) {
|
|
207
|
+
const result = fn(currentParts, last);
|
|
208
|
+
currentParts = result.out;
|
|
209
|
+
}
|
|
206
210
|
return { out: currentParts };
|
|
207
211
|
};
|
|
208
212
|
}
|
|
@@ -219,7 +223,8 @@ const applyDeltaBoundaryTransform = (parts, last) => {
|
|
|
219
223
|
const incomingDeltaType = maybeGetDeltaType(incoming);
|
|
220
224
|
const incomingId = getPartId$1(incoming);
|
|
221
225
|
const lastId = getPartId$1(last);
|
|
222
|
-
|
|
226
|
+
const incomingMatchesLast = Boolean(isDeltaPart(last) && isDeltaPart(incoming)) && Boolean(lastDeltaType && incomingDeltaType) && Boolean(lastDeltaType === incomingDeltaType) && Boolean(incomingId && lastId && incomingId === lastId);
|
|
227
|
+
if (incomingMatchesLast) {
|
|
223
228
|
out.push(incoming);
|
|
224
229
|
continue;
|
|
225
230
|
}
|
|
@@ -235,6 +240,7 @@ const applyDeltaBoundaryTransform = (parts, last) => {
|
|
|
235
240
|
continue;
|
|
236
241
|
}
|
|
237
242
|
out.push(incoming);
|
|
243
|
+
continue;
|
|
238
244
|
}
|
|
239
245
|
return { out };
|
|
240
246
|
};
|
|
@@ -253,6 +259,7 @@ const getDeltaType = (part) => {
|
|
|
253
259
|
const isDeltaPart = (part) => part?.type === "text-delta" || part?.type === "reasoning-delta";
|
|
254
260
|
const getPartId$1 = (part) => {
|
|
255
261
|
if (part && "id" in part) return part.id;
|
|
262
|
+
return void 0;
|
|
256
263
|
};
|
|
257
264
|
|
|
258
265
|
//#endregion
|
|
@@ -265,10 +272,14 @@ const getPartId$1 = (part) => {
|
|
|
265
272
|
*/
|
|
266
273
|
const getDatabricksLanguageModelTransformStream = () => {
|
|
267
274
|
let lastChunk = null;
|
|
268
|
-
const deltaEndByTypeAndId =
|
|
275
|
+
const deltaEndByTypeAndId = new Set();
|
|
269
276
|
const transformerStreamParts = composeDatabricksStreamPartTransformers(applyDeltaBoundaryTransform);
|
|
270
277
|
return new TransformStream({
|
|
271
278
|
transform(chunk, controller) {
|
|
279
|
+
if (chunk.type === "raw") {
|
|
280
|
+
controller.enqueue(chunk);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
272
283
|
const { out } = transformerStreamParts([chunk], lastChunk);
|
|
273
284
|
out.forEach((transformedChunk) => {
|
|
274
285
|
const group = getDeltaGroup(transformedChunk.type);
|
|
@@ -307,6 +318,7 @@ const getDeltaGroup = (type) => {
|
|
|
307
318
|
};
|
|
308
319
|
const getPartId = (part) => {
|
|
309
320
|
if ("id" in part) return part.id;
|
|
321
|
+
return void 0;
|
|
310
322
|
};
|
|
311
323
|
const makeEndKey = (id, group) => id && group ? `${group}:${id}` : null;
|
|
312
324
|
|
|
@@ -325,13 +337,14 @@ var DatabricksChatAgentLanguageModel = class {
|
|
|
325
337
|
}
|
|
326
338
|
supportedUrls = {};
|
|
327
339
|
async doGenerate(options) {
|
|
340
|
+
const networkArgs = this.getArgs({
|
|
341
|
+
config: this.config,
|
|
342
|
+
options,
|
|
343
|
+
stream: false,
|
|
344
|
+
modelId: this.modelId
|
|
345
|
+
});
|
|
328
346
|
const { value: response } = await postJsonToApi({
|
|
329
|
-
...
|
|
330
|
-
config: this.config,
|
|
331
|
-
options,
|
|
332
|
-
stream: false,
|
|
333
|
-
modelId: this.modelId
|
|
334
|
-
}),
|
|
347
|
+
...networkArgs,
|
|
335
348
|
successfulResponseHandler: createJsonResponseHandler(chatAgentResponseSchema),
|
|
336
349
|
failedResponseHandler: createJsonErrorResponseHandler({
|
|
337
350
|
errorSchema: z.any(),
|
|
@@ -466,7 +479,7 @@ const responsesAgentMessageSchema = z.object({
|
|
|
466
479
|
end_index: z.number(),
|
|
467
480
|
url: z.string(),
|
|
468
481
|
title: z.string()
|
|
469
|
-
})]))
|
|
482
|
+
})])).optional()
|
|
470
483
|
}))
|
|
471
484
|
});
|
|
472
485
|
const responsesAgentFunctionCallSchema = z.object({
|
|
@@ -527,7 +540,7 @@ const responsesAgentResponseSchema = z.object({
|
|
|
527
540
|
output_tokens: z.number(),
|
|
528
541
|
total_tokens: z.number()
|
|
529
542
|
}).optional()
|
|
530
|
-
});
|
|
543
|
+
}).passthrough();
|
|
531
544
|
/**
|
|
532
545
|
* Chunk schema
|
|
533
546
|
*/
|
|
@@ -550,9 +563,10 @@ const simpleErrorChunkSchema = z.object({
|
|
|
550
563
|
});
|
|
551
564
|
const responseOutputItemDoneSchema = z.object({
|
|
552
565
|
type: z.literal("response.output_item.done"),
|
|
553
|
-
output_index: z.number(),
|
|
554
|
-
item: responsesAgentOutputItem
|
|
555
|
-
|
|
566
|
+
output_index: z.number().optional(),
|
|
567
|
+
item: responsesAgentOutputItem,
|
|
568
|
+
id: z.string().optional()
|
|
569
|
+
}).passthrough();
|
|
556
570
|
const responseAnnotationAddedSchema = z.object({
|
|
557
571
|
type: z.literal("response.output_text.annotation.added"),
|
|
558
572
|
annotation: z.discriminatedUnion("type", [z.object({
|
|
@@ -754,17 +768,18 @@ const convertOutputItemDone = (item, options) => {
|
|
|
754
768
|
};
|
|
755
769
|
const convertResponsesAgentResponseToMessagePart = (response, options = { useRemoteToolCalling: false }) => {
|
|
756
770
|
const parts = [];
|
|
757
|
-
const toolNamesByCallId =
|
|
771
|
+
const toolNamesByCallId = new Map();
|
|
758
772
|
for (const output of response.output) if (output.type === "function_call") toolNamesByCallId.set(output.call_id, output.name);
|
|
759
773
|
else if (output.type === "mcp_approval_request") toolNamesByCallId.set(output.id, output.name);
|
|
760
774
|
for (const output of response.output) switch (output.type) {
|
|
761
|
-
case "message":
|
|
775
|
+
case "message": {
|
|
762
776
|
for (const content of output.content) if (content.type === "output_text") parts.push({
|
|
763
777
|
type: "text",
|
|
764
778
|
text: content.text,
|
|
765
779
|
providerMetadata: { databricks: { itemId: output.id } }
|
|
766
780
|
});
|
|
767
781
|
break;
|
|
782
|
+
}
|
|
768
783
|
case "function_call":
|
|
769
784
|
parts.push({
|
|
770
785
|
type: "tool-call",
|
|
@@ -832,14 +847,14 @@ const convertResponsesAgentResponseToMessagePart = (response, options = { useRem
|
|
|
832
847
|
async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
833
848
|
const input = [];
|
|
834
849
|
const warnings = [];
|
|
835
|
-
const processedApprovalIds =
|
|
836
|
-
const approvalIdsWithToolResult =
|
|
850
|
+
const processedApprovalIds = new Set();
|
|
851
|
+
const approvalIdsWithToolResult = new Set();
|
|
837
852
|
const toolCallResultsByToolCallId = prompt.filter((p) => p.role === "tool").flatMap((p) => p.content).reduce((reduction, toolCallResult) => {
|
|
838
853
|
if (toolCallResult.type === "tool-result") reduction[toolCallResult.toolCallId] = toolCallResult;
|
|
839
854
|
return reduction;
|
|
840
855
|
}, {});
|
|
841
856
|
for (const { role, content } of prompt) switch (role) {
|
|
842
|
-
case "system":
|
|
857
|
+
case "system": {
|
|
843
858
|
switch (systemMessageMode) {
|
|
844
859
|
case "system":
|
|
845
860
|
input.push({
|
|
@@ -865,6 +880,7 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
|
865
880
|
}
|
|
866
881
|
}
|
|
867
882
|
break;
|
|
883
|
+
}
|
|
868
884
|
case "user":
|
|
869
885
|
input.push({
|
|
870
886
|
role: "user",
|
|
@@ -888,7 +904,7 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
|
888
904
|
});
|
|
889
905
|
const itemId = providerOptions?.itemId ?? void 0;
|
|
890
906
|
switch (part.type) {
|
|
891
|
-
case "text":
|
|
907
|
+
case "text": {
|
|
892
908
|
input.push({
|
|
893
909
|
role: "assistant",
|
|
894
910
|
content: [{
|
|
@@ -898,6 +914,7 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
|
898
914
|
id: itemId
|
|
899
915
|
});
|
|
900
916
|
break;
|
|
917
|
+
}
|
|
901
918
|
case "tool-call": {
|
|
902
919
|
const toolName = providerOptions?.toolName ?? part.toolName;
|
|
903
920
|
const approvalRequestId = providerOptions?.approvalRequestId;
|
|
@@ -927,7 +944,7 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
|
927
944
|
});
|
|
928
945
|
break;
|
|
929
946
|
}
|
|
930
|
-
case "tool-result":
|
|
947
|
+
case "tool-result": {
|
|
931
948
|
input.push({
|
|
932
949
|
type: "function_call_output",
|
|
933
950
|
call_id: part.toolCallId,
|
|
@@ -935,7 +952,8 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
|
935
952
|
});
|
|
936
953
|
approvalIdsWithToolResult.add(part.toolCallId);
|
|
937
954
|
break;
|
|
938
|
-
|
|
955
|
+
}
|
|
956
|
+
case "reasoning": {
|
|
939
957
|
if (!itemId) break;
|
|
940
958
|
input.push({
|
|
941
959
|
type: "reasoning",
|
|
@@ -946,6 +964,7 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
|
946
964
|
id: itemId
|
|
947
965
|
});
|
|
948
966
|
break;
|
|
967
|
+
}
|
|
949
968
|
}
|
|
950
969
|
}
|
|
951
970
|
break;
|
|
@@ -1016,13 +1035,14 @@ function prepareResponsesTools({ tools, toolChoice }) {
|
|
|
1016
1035
|
tools: void 0,
|
|
1017
1036
|
toolChoice: void 0
|
|
1018
1037
|
};
|
|
1038
|
+
const convertedToolChoice = convertResponsesToolChoice(toolChoice);
|
|
1019
1039
|
return {
|
|
1020
1040
|
tools: responsesTools,
|
|
1021
|
-
toolChoice:
|
|
1041
|
+
toolChoice: convertedToolChoice
|
|
1022
1042
|
};
|
|
1023
1043
|
}
|
|
1024
1044
|
function convertResponsesToolChoice(toolChoice) {
|
|
1025
|
-
if (!toolChoice) return;
|
|
1045
|
+
if (!toolChoice) return void 0;
|
|
1026
1046
|
switch (toolChoice.type) {
|
|
1027
1047
|
case "auto": return "auto";
|
|
1028
1048
|
case "none": return "none";
|
|
@@ -1031,7 +1051,7 @@ function convertResponsesToolChoice(toolChoice) {
|
|
|
1031
1051
|
type: "function",
|
|
1032
1052
|
name: toolChoice.toolName
|
|
1033
1053
|
};
|
|
1034
|
-
default: return;
|
|
1054
|
+
default: return void 0;
|
|
1035
1055
|
}
|
|
1036
1056
|
}
|
|
1037
1057
|
|
|
@@ -1098,6 +1118,7 @@ function callOptionsToResponsesArgs(options) {
|
|
|
1098
1118
|
if (databricksOptions?.parallelToolCalls != null) args.parallel_tool_calls = databricksOptions.parallelToolCalls;
|
|
1099
1119
|
if (databricksOptions?.metadata != null) args.metadata = databricksOptions.metadata;
|
|
1100
1120
|
if (databricksOptions?.reasoning != null) args.reasoning = databricksOptions.reasoning;
|
|
1121
|
+
if (databricksOptions?.includeTrace != null) args.databricks_options = { return_trace: databricksOptions.includeTrace };
|
|
1101
1122
|
return {
|
|
1102
1123
|
args,
|
|
1103
1124
|
warnings
|
|
@@ -1139,7 +1160,7 @@ var DatabricksResponsesAgentLanguageModel = class {
|
|
|
1139
1160
|
}
|
|
1140
1161
|
supportedUrls = {};
|
|
1141
1162
|
async doGenerate(options) {
|
|
1142
|
-
const { warnings
|
|
1163
|
+
const { warnings,...networkArgs } = await this.getArgs({
|
|
1143
1164
|
config: this.config,
|
|
1144
1165
|
options,
|
|
1145
1166
|
stream: false,
|
|
@@ -1175,11 +1196,12 @@ var DatabricksResponsesAgentLanguageModel = class {
|
|
|
1175
1196
|
reasoning: 0
|
|
1176
1197
|
}
|
|
1177
1198
|
},
|
|
1178
|
-
warnings
|
|
1199
|
+
warnings,
|
|
1200
|
+
response: { body: response }
|
|
1179
1201
|
};
|
|
1180
1202
|
}
|
|
1181
1203
|
async doStream(options) {
|
|
1182
|
-
const { warnings
|
|
1204
|
+
const { warnings,...networkArgs } = await this.getArgs({
|
|
1183
1205
|
config: this.config,
|
|
1184
1206
|
options,
|
|
1185
1207
|
stream: true,
|
|
@@ -1214,7 +1236,7 @@ var DatabricksResponsesAgentLanguageModel = class {
|
|
|
1214
1236
|
};
|
|
1215
1237
|
const allParts = [];
|
|
1216
1238
|
const useRemoteToolCalling = this.config.useRemoteToolCalling ?? false;
|
|
1217
|
-
const toolNamesByCallId =
|
|
1239
|
+
const toolNamesByCallId = new Map();
|
|
1218
1240
|
return {
|
|
1219
1241
|
stream: response.pipeThrough(new TransformStream({
|
|
1220
1242
|
start(controller) {
|
|
@@ -1282,15 +1304,17 @@ var DatabricksResponsesAgentLanguageModel = class {
|
|
|
1282
1304
|
}
|
|
1283
1305
|
}
|
|
1284
1306
|
if (shouldDedupeOutputItemDone(parts, allParts.slice(0, -parts.length))) return;
|
|
1285
|
-
for (const part of parts) controller.enqueue(part);
|
|
1307
|
+
for (const part$1 of parts) controller.enqueue(part$1);
|
|
1286
1308
|
},
|
|
1287
1309
|
flush(controller) {
|
|
1288
1310
|
if (!useRemoteToolCalling) {
|
|
1289
1311
|
const toolCalls = allParts.filter((p) => p.type === "tool-call");
|
|
1290
1312
|
const toolResults = allParts.filter((p) => p.type === "tool-result");
|
|
1291
1313
|
for (const toolCall of toolCalls) {
|
|
1292
|
-
|
|
1293
|
-
if (
|
|
1314
|
+
const isMcpApprovalRequest = toolCall.providerMetadata?.databricks?.approvalRequestId != null;
|
|
1315
|
+
if (isMcpApprovalRequest) continue;
|
|
1316
|
+
const hasResult = toolResults.some((r) => r.toolCallId === toolCall.toolCallId);
|
|
1317
|
+
if (!hasResult) controller.enqueue({
|
|
1294
1318
|
...toolCall,
|
|
1295
1319
|
providerExecuted: true,
|
|
1296
1320
|
dynamic: true
|
|
@@ -1349,7 +1373,8 @@ function shouldDedupeOutputItemDone(incomingParts, previousParts) {
|
|
|
1349
1373
|
* corresponds to a specific message and we should only compare against text streamed for that message.
|
|
1350
1374
|
*/
|
|
1351
1375
|
const lastDoneIndex = previousParts.findLastIndex((part) => part.type === "text-delta" && part.providerMetadata?.databricks?.itemType === "response.output_item.done");
|
|
1352
|
-
const
|
|
1376
|
+
const partsAfterLastDone = previousParts.slice(lastDoneIndex + 1);
|
|
1377
|
+
const { texts: reconstructuredTexts, current } = partsAfterLastDone.reduce((acc, part) => {
|
|
1353
1378
|
if (part.type === "text-delta") return {
|
|
1354
1379
|
...acc,
|
|
1355
1380
|
current: acc.current + part.delta
|
|
@@ -1365,7 +1390,7 @@ function shouldDedupeOutputItemDone(incomingParts, previousParts) {
|
|
|
1365
1390
|
});
|
|
1366
1391
|
if (current.length > 0) reconstructuredTexts.push(current);
|
|
1367
1392
|
if (reconstructuredTexts.length === 0) return false;
|
|
1368
|
-
|
|
1393
|
+
const allTextsFoundInOrder = reconstructuredTexts.reduce((acc, text) => {
|
|
1369
1394
|
if (!acc.found) return acc;
|
|
1370
1395
|
const index = doneTextDelta.delta.indexOf(text, acc.lastIndex);
|
|
1371
1396
|
if (index === -1) return {
|
|
@@ -1379,7 +1404,8 @@ function shouldDedupeOutputItemDone(incomingParts, previousParts) {
|
|
|
1379
1404
|
}, {
|
|
1380
1405
|
found: true,
|
|
1381
1406
|
lastIndex: 0
|
|
1382
|
-
})
|
|
1407
|
+
});
|
|
1408
|
+
return allTextsFoundInOrder.found;
|
|
1383
1409
|
}
|
|
1384
1410
|
|
|
1385
1411
|
//#endregion
|
|
@@ -1555,13 +1581,14 @@ const mapContentItemsToStreamParts = (items, id) => {
|
|
|
1555
1581
|
});
|
|
1556
1582
|
break;
|
|
1557
1583
|
case "image": break;
|
|
1558
|
-
case "reasoning":
|
|
1584
|
+
case "reasoning": {
|
|
1559
1585
|
for (const summary of item.summary.filter((s) => s.type === "summary_text")) parts.push({
|
|
1560
1586
|
type: "reasoning-delta",
|
|
1561
1587
|
id,
|
|
1562
1588
|
delta: summary.text
|
|
1563
1589
|
});
|
|
1564
1590
|
break;
|
|
1591
|
+
}
|
|
1565
1592
|
}
|
|
1566
1593
|
return parts;
|
|
1567
1594
|
};
|
|
@@ -1575,12 +1602,13 @@ const mapContentItemsToProviderContent = (items) => {
|
|
|
1575
1602
|
});
|
|
1576
1603
|
break;
|
|
1577
1604
|
case "image": break;
|
|
1578
|
-
case "reasoning":
|
|
1605
|
+
case "reasoning": {
|
|
1579
1606
|
for (const summary of item.summary.filter((s) => s.type === "summary_text")) parts.push({
|
|
1580
1607
|
type: "reasoning",
|
|
1581
1608
|
text: summary.text
|
|
1582
1609
|
});
|
|
1583
1610
|
break;
|
|
1611
|
+
}
|
|
1584
1612
|
}
|
|
1585
1613
|
return parts;
|
|
1586
1614
|
};
|
|
@@ -1716,11 +1744,12 @@ const convertToolResultOutputToContentValue = (output) => {
|
|
|
1716
1744
|
};
|
|
1717
1745
|
const ProviderOptionsSchema = z.object({ toolName: z.string().nullish() });
|
|
1718
1746
|
const getToolNameFromPart = async (part) => {
|
|
1719
|
-
|
|
1747
|
+
const providerOptions = await parseProviderOptions({
|
|
1720
1748
|
provider: "databricks",
|
|
1721
1749
|
providerOptions: part.providerOptions,
|
|
1722
1750
|
schema: ProviderOptionsSchema
|
|
1723
|
-
})
|
|
1751
|
+
});
|
|
1752
|
+
return providerOptions?.toolName ?? part.toolName;
|
|
1724
1753
|
};
|
|
1725
1754
|
|
|
1726
1755
|
//#endregion
|
|
@@ -1829,7 +1858,7 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1829
1858
|
}
|
|
1830
1859
|
supportedUrls = {};
|
|
1831
1860
|
async doGenerate(options) {
|
|
1832
|
-
const { warnings
|
|
1861
|
+
const { warnings,...networkArgs } = await this.getArgs({
|
|
1833
1862
|
config: this.config,
|
|
1834
1863
|
options,
|
|
1835
1864
|
stream: false,
|
|
@@ -1846,8 +1875,9 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1846
1875
|
});
|
|
1847
1876
|
const choice = response.choices[0];
|
|
1848
1877
|
const finishReason = mapFmapiFinishReason(choice?.finish_reason);
|
|
1878
|
+
const useRemoteToolCalling = this.config.useRemoteToolCalling ?? false;
|
|
1849
1879
|
return {
|
|
1850
|
-
content: convertFmapiResponseToMessagePart(response, { useRemoteToolCalling
|
|
1880
|
+
content: convertFmapiResponseToMessagePart(response, { useRemoteToolCalling }),
|
|
1851
1881
|
finishReason,
|
|
1852
1882
|
usage: {
|
|
1853
1883
|
inputTokens: {
|
|
@@ -1866,7 +1896,7 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1866
1896
|
};
|
|
1867
1897
|
}
|
|
1868
1898
|
async doStream(options) {
|
|
1869
|
-
const { warnings
|
|
1899
|
+
const { warnings,...networkArgs } = await this.getArgs({
|
|
1870
1900
|
config: this.config,
|
|
1871
1901
|
options,
|
|
1872
1902
|
stream: true,
|
|
@@ -1899,9 +1929,9 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1899
1929
|
reasoning: 0
|
|
1900
1930
|
}
|
|
1901
1931
|
};
|
|
1902
|
-
const toolCallIdsByIndex =
|
|
1903
|
-
const toolCallNamesById =
|
|
1904
|
-
const toolCallInputsById =
|
|
1932
|
+
const toolCallIdsByIndex = new Map();
|
|
1933
|
+
const toolCallNamesById = new Map();
|
|
1934
|
+
const toolCallInputsById = new Map();
|
|
1905
1935
|
const useRemoteToolCalling = this.config.useRemoteToolCalling ?? false;
|
|
1906
1936
|
return {
|
|
1907
1937
|
stream: response.pipeThrough(new TransformStream({
|
|
@@ -2010,7 +2040,7 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
2010
2040
|
* Convert AI SDK tool to OpenAI format
|
|
2011
2041
|
*/
|
|
2012
2042
|
function convertToolToOpenAIFormat(tool) {
|
|
2013
|
-
if (tool.type === "provider") return;
|
|
2043
|
+
if (tool.type === "provider") return void 0;
|
|
2014
2044
|
return {
|
|
2015
2045
|
type: "function",
|
|
2016
2046
|
function: {
|