@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.cjs
CHANGED
|
@@ -1,7 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
//#region rolldown:runtime
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
const __ai_sdk_provider_utils = __toESM(require("@ai-sdk/provider-utils"));
|
|
26
|
+
const zod_v4 = __toESM(require("zod/v4"));
|
|
27
|
+
const node_crypto = __toESM(require("node:crypto"));
|
|
28
|
+
const __ai_sdk_provider = __toESM(require("@ai-sdk/provider"));
|
|
5
29
|
|
|
6
30
|
//#region src/chat-agent-language-model/chat-agent-schema.ts
|
|
7
31
|
const chatAgentToolCallSchema = zod_v4.z.object({
|
|
@@ -127,9 +151,10 @@ const convertLanguageModelV3PromptToChatAgentResponse = (prompt) => {
|
|
|
127
151
|
return messages;
|
|
128
152
|
};
|
|
129
153
|
const convertUserMessage$1 = (msg, messageIndex) => {
|
|
154
|
+
const text = (msg.content ?? []).filter((part) => part.type === "text").map((part) => part.text).join("\n");
|
|
130
155
|
return {
|
|
131
156
|
role: "user",
|
|
132
|
-
content:
|
|
157
|
+
content: text,
|
|
133
158
|
id: `user-${messageIndex}`
|
|
134
159
|
};
|
|
135
160
|
};
|
|
@@ -202,7 +227,10 @@ const convertToolResultOutput = (output) => {
|
|
|
202
227
|
function composeDatabricksStreamPartTransformers(...transformers) {
|
|
203
228
|
return (initialParts, last = null) => {
|
|
204
229
|
let currentParts = initialParts;
|
|
205
|
-
for (const fn of transformers)
|
|
230
|
+
for (const fn of transformers) {
|
|
231
|
+
const result = fn(currentParts, last);
|
|
232
|
+
currentParts = result.out;
|
|
233
|
+
}
|
|
206
234
|
return { out: currentParts };
|
|
207
235
|
};
|
|
208
236
|
}
|
|
@@ -219,7 +247,8 @@ const applyDeltaBoundaryTransform = (parts, last) => {
|
|
|
219
247
|
const incomingDeltaType = maybeGetDeltaType(incoming);
|
|
220
248
|
const incomingId = getPartId$1(incoming);
|
|
221
249
|
const lastId = getPartId$1(last);
|
|
222
|
-
|
|
250
|
+
const incomingMatchesLast = Boolean(isDeltaPart(last) && isDeltaPart(incoming)) && Boolean(lastDeltaType && incomingDeltaType) && Boolean(lastDeltaType === incomingDeltaType) && Boolean(incomingId && lastId && incomingId === lastId);
|
|
251
|
+
if (incomingMatchesLast) {
|
|
223
252
|
out.push(incoming);
|
|
224
253
|
continue;
|
|
225
254
|
}
|
|
@@ -235,6 +264,7 @@ const applyDeltaBoundaryTransform = (parts, last) => {
|
|
|
235
264
|
continue;
|
|
236
265
|
}
|
|
237
266
|
out.push(incoming);
|
|
267
|
+
continue;
|
|
238
268
|
}
|
|
239
269
|
return { out };
|
|
240
270
|
};
|
|
@@ -253,6 +283,7 @@ const getDeltaType = (part) => {
|
|
|
253
283
|
const isDeltaPart = (part) => part?.type === "text-delta" || part?.type === "reasoning-delta";
|
|
254
284
|
const getPartId$1 = (part) => {
|
|
255
285
|
if (part && "id" in part) return part.id;
|
|
286
|
+
return void 0;
|
|
256
287
|
};
|
|
257
288
|
|
|
258
289
|
//#endregion
|
|
@@ -265,10 +296,14 @@ const getPartId$1 = (part) => {
|
|
|
265
296
|
*/
|
|
266
297
|
const getDatabricksLanguageModelTransformStream = () => {
|
|
267
298
|
let lastChunk = null;
|
|
268
|
-
const deltaEndByTypeAndId =
|
|
299
|
+
const deltaEndByTypeAndId = new Set();
|
|
269
300
|
const transformerStreamParts = composeDatabricksStreamPartTransformers(applyDeltaBoundaryTransform);
|
|
270
301
|
return new TransformStream({
|
|
271
302
|
transform(chunk, controller) {
|
|
303
|
+
if (chunk.type === "raw") {
|
|
304
|
+
controller.enqueue(chunk);
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
272
307
|
const { out } = transformerStreamParts([chunk], lastChunk);
|
|
273
308
|
out.forEach((transformedChunk) => {
|
|
274
309
|
const group = getDeltaGroup(transformedChunk.type);
|
|
@@ -307,6 +342,7 @@ const getDeltaGroup = (type) => {
|
|
|
307
342
|
};
|
|
308
343
|
const getPartId = (part) => {
|
|
309
344
|
if ("id" in part) return part.id;
|
|
345
|
+
return void 0;
|
|
310
346
|
};
|
|
311
347
|
const makeEndKey = (id, group) => id && group ? `${group}:${id}` : null;
|
|
312
348
|
|
|
@@ -325,15 +361,16 @@ var DatabricksChatAgentLanguageModel = class {
|
|
|
325
361
|
}
|
|
326
362
|
supportedUrls = {};
|
|
327
363
|
async doGenerate(options) {
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
364
|
+
const networkArgs = this.getArgs({
|
|
365
|
+
config: this.config,
|
|
366
|
+
options,
|
|
367
|
+
stream: false,
|
|
368
|
+
modelId: this.modelId
|
|
369
|
+
});
|
|
370
|
+
const { value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
|
|
371
|
+
...networkArgs,
|
|
372
|
+
successfulResponseHandler: (0, __ai_sdk_provider_utils.createJsonResponseHandler)(chatAgentResponseSchema),
|
|
373
|
+
failedResponseHandler: (0, __ai_sdk_provider_utils.createJsonErrorResponseHandler)({
|
|
337
374
|
errorSchema: zod_v4.z.any(),
|
|
338
375
|
errorToMessage: (error) => JSON.stringify(error),
|
|
339
376
|
isRetryable: () => false
|
|
@@ -368,14 +405,14 @@ var DatabricksChatAgentLanguageModel = class {
|
|
|
368
405
|
stream: true,
|
|
369
406
|
modelId: this.modelId
|
|
370
407
|
});
|
|
371
|
-
const { responseHeaders, value: response } = await (0,
|
|
408
|
+
const { responseHeaders, value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
|
|
372
409
|
...networkArgs,
|
|
373
|
-
failedResponseHandler: (0,
|
|
410
|
+
failedResponseHandler: (0, __ai_sdk_provider_utils.createJsonErrorResponseHandler)({
|
|
374
411
|
errorSchema: zod_v4.z.any(),
|
|
375
412
|
errorToMessage: (error) => JSON.stringify(error),
|
|
376
413
|
isRetryable: () => false
|
|
377
414
|
}),
|
|
378
|
-
successfulResponseHandler: (0,
|
|
415
|
+
successfulResponseHandler: (0, __ai_sdk_provider_utils.createEventSourceResponseHandler)(chatAgentChunkSchema)
|
|
379
416
|
});
|
|
380
417
|
let finishReason = {
|
|
381
418
|
raw: void 0,
|
|
@@ -440,7 +477,7 @@ var DatabricksChatAgentLanguageModel = class {
|
|
|
440
477
|
messages: convertLanguageModelV3PromptToChatAgentResponse(options.prompt)
|
|
441
478
|
},
|
|
442
479
|
url: config.url({ path: "/completions" }),
|
|
443
|
-
headers: (0,
|
|
480
|
+
headers: (0, __ai_sdk_provider_utils.combineHeaders)(config.headers(), options.headers),
|
|
444
481
|
fetch: config.fetch,
|
|
445
482
|
abortSignal: options.abortSignal
|
|
446
483
|
};
|
|
@@ -466,7 +503,7 @@ const responsesAgentMessageSchema = zod_v4.z.object({
|
|
|
466
503
|
end_index: zod_v4.z.number(),
|
|
467
504
|
url: zod_v4.z.string(),
|
|
468
505
|
title: zod_v4.z.string()
|
|
469
|
-
})]))
|
|
506
|
+
})])).optional()
|
|
470
507
|
}))
|
|
471
508
|
});
|
|
472
509
|
const responsesAgentFunctionCallSchema = zod_v4.z.object({
|
|
@@ -527,7 +564,7 @@ const responsesAgentResponseSchema = zod_v4.z.object({
|
|
|
527
564
|
output_tokens: zod_v4.z.number(),
|
|
528
565
|
total_tokens: zod_v4.z.number()
|
|
529
566
|
}).optional()
|
|
530
|
-
});
|
|
567
|
+
}).passthrough();
|
|
531
568
|
/**
|
|
532
569
|
* Chunk schema
|
|
533
570
|
*/
|
|
@@ -550,9 +587,10 @@ const simpleErrorChunkSchema = zod_v4.z.object({
|
|
|
550
587
|
});
|
|
551
588
|
const responseOutputItemDoneSchema = zod_v4.z.object({
|
|
552
589
|
type: zod_v4.z.literal("response.output_item.done"),
|
|
553
|
-
output_index: zod_v4.z.number(),
|
|
554
|
-
item: responsesAgentOutputItem
|
|
555
|
-
|
|
590
|
+
output_index: zod_v4.z.number().optional(),
|
|
591
|
+
item: responsesAgentOutputItem,
|
|
592
|
+
id: zod_v4.z.string().optional()
|
|
593
|
+
}).passthrough();
|
|
556
594
|
const responseAnnotationAddedSchema = zod_v4.z.object({
|
|
557
595
|
type: zod_v4.z.literal("response.output_text.annotation.added"),
|
|
558
596
|
annotation: zod_v4.z.discriminatedUnion("type", [zod_v4.z.object({
|
|
@@ -754,17 +792,18 @@ const convertOutputItemDone = (item, options) => {
|
|
|
754
792
|
};
|
|
755
793
|
const convertResponsesAgentResponseToMessagePart = (response, options = { useRemoteToolCalling: false }) => {
|
|
756
794
|
const parts = [];
|
|
757
|
-
const toolNamesByCallId =
|
|
795
|
+
const toolNamesByCallId = new Map();
|
|
758
796
|
for (const output of response.output) if (output.type === "function_call") toolNamesByCallId.set(output.call_id, output.name);
|
|
759
797
|
else if (output.type === "mcp_approval_request") toolNamesByCallId.set(output.id, output.name);
|
|
760
798
|
for (const output of response.output) switch (output.type) {
|
|
761
|
-
case "message":
|
|
799
|
+
case "message": {
|
|
762
800
|
for (const content of output.content) if (content.type === "output_text") parts.push({
|
|
763
801
|
type: "text",
|
|
764
802
|
text: content.text,
|
|
765
803
|
providerMetadata: { databricks: { itemId: output.id } }
|
|
766
804
|
});
|
|
767
805
|
break;
|
|
806
|
+
}
|
|
768
807
|
case "function_call":
|
|
769
808
|
parts.push({
|
|
770
809
|
type: "tool-call",
|
|
@@ -832,14 +871,14 @@ const convertResponsesAgentResponseToMessagePart = (response, options = { useRem
|
|
|
832
871
|
async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
833
872
|
const input = [];
|
|
834
873
|
const warnings = [];
|
|
835
|
-
const processedApprovalIds =
|
|
836
|
-
const approvalIdsWithToolResult =
|
|
874
|
+
const processedApprovalIds = new Set();
|
|
875
|
+
const approvalIdsWithToolResult = new Set();
|
|
837
876
|
const toolCallResultsByToolCallId = prompt.filter((p) => p.role === "tool").flatMap((p) => p.content).reduce((reduction, toolCallResult) => {
|
|
838
877
|
if (toolCallResult.type === "tool-result") reduction[toolCallResult.toolCallId] = toolCallResult;
|
|
839
878
|
return reduction;
|
|
840
879
|
}, {});
|
|
841
880
|
for (const { role, content } of prompt) switch (role) {
|
|
842
|
-
case "system":
|
|
881
|
+
case "system": {
|
|
843
882
|
switch (systemMessageMode) {
|
|
844
883
|
case "system":
|
|
845
884
|
input.push({
|
|
@@ -865,6 +904,7 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
|
865
904
|
}
|
|
866
905
|
}
|
|
867
906
|
break;
|
|
907
|
+
}
|
|
868
908
|
case "user":
|
|
869
909
|
input.push({
|
|
870
910
|
role: "user",
|
|
@@ -874,21 +914,21 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
|
874
914
|
type: "input_text",
|
|
875
915
|
text: part.text
|
|
876
916
|
};
|
|
877
|
-
default: throw new
|
|
917
|
+
default: throw new __ai_sdk_provider.UnsupportedFunctionalityError({ functionality: `part ${JSON.stringify(part)}` });
|
|
878
918
|
}
|
|
879
919
|
})
|
|
880
920
|
});
|
|
881
921
|
break;
|
|
882
922
|
case "assistant":
|
|
883
923
|
for (const part of content) {
|
|
884
|
-
const providerOptions = await (0,
|
|
924
|
+
const providerOptions = await (0, __ai_sdk_provider_utils.parseProviderOptions)({
|
|
885
925
|
provider: "databricks",
|
|
886
926
|
providerOptions: part.providerOptions,
|
|
887
927
|
schema: ProviderOptionsSchema$1
|
|
888
928
|
});
|
|
889
929
|
const itemId = providerOptions?.itemId ?? void 0;
|
|
890
930
|
switch (part.type) {
|
|
891
|
-
case "text":
|
|
931
|
+
case "text": {
|
|
892
932
|
input.push({
|
|
893
933
|
role: "assistant",
|
|
894
934
|
content: [{
|
|
@@ -898,6 +938,7 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
|
898
938
|
id: itemId
|
|
899
939
|
});
|
|
900
940
|
break;
|
|
941
|
+
}
|
|
901
942
|
case "tool-call": {
|
|
902
943
|
const toolName = providerOptions?.toolName ?? part.toolName;
|
|
903
944
|
const approvalRequestId = providerOptions?.approvalRequestId;
|
|
@@ -927,7 +968,7 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
|
927
968
|
});
|
|
928
969
|
break;
|
|
929
970
|
}
|
|
930
|
-
case "tool-result":
|
|
971
|
+
case "tool-result": {
|
|
931
972
|
input.push({
|
|
932
973
|
type: "function_call_output",
|
|
933
974
|
call_id: part.toolCallId,
|
|
@@ -935,7 +976,8 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
|
935
976
|
});
|
|
936
977
|
approvalIdsWithToolResult.add(part.toolCallId);
|
|
937
978
|
break;
|
|
938
|
-
|
|
979
|
+
}
|
|
980
|
+
case "reasoning": {
|
|
939
981
|
if (!itemId) break;
|
|
940
982
|
input.push({
|
|
941
983
|
type: "reasoning",
|
|
@@ -946,6 +988,7 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
|
946
988
|
id: itemId
|
|
947
989
|
});
|
|
948
990
|
break;
|
|
991
|
+
}
|
|
949
992
|
}
|
|
950
993
|
}
|
|
951
994
|
break;
|
|
@@ -1016,13 +1059,14 @@ function prepareResponsesTools({ tools, toolChoice }) {
|
|
|
1016
1059
|
tools: void 0,
|
|
1017
1060
|
toolChoice: void 0
|
|
1018
1061
|
};
|
|
1062
|
+
const convertedToolChoice = convertResponsesToolChoice(toolChoice);
|
|
1019
1063
|
return {
|
|
1020
1064
|
tools: responsesTools,
|
|
1021
|
-
toolChoice:
|
|
1065
|
+
toolChoice: convertedToolChoice
|
|
1022
1066
|
};
|
|
1023
1067
|
}
|
|
1024
1068
|
function convertResponsesToolChoice(toolChoice) {
|
|
1025
|
-
if (!toolChoice) return;
|
|
1069
|
+
if (!toolChoice) return void 0;
|
|
1026
1070
|
switch (toolChoice.type) {
|
|
1027
1071
|
case "auto": return "auto";
|
|
1028
1072
|
case "none": return "none";
|
|
@@ -1031,7 +1075,7 @@ function convertResponsesToolChoice(toolChoice) {
|
|
|
1031
1075
|
type: "function",
|
|
1032
1076
|
name: toolChoice.toolName
|
|
1033
1077
|
};
|
|
1034
|
-
default: return;
|
|
1078
|
+
default: return void 0;
|
|
1035
1079
|
}
|
|
1036
1080
|
}
|
|
1037
1081
|
|
|
@@ -1098,6 +1142,7 @@ function callOptionsToResponsesArgs(options) {
|
|
|
1098
1142
|
if (databricksOptions?.parallelToolCalls != null) args.parallel_tool_calls = databricksOptions.parallelToolCalls;
|
|
1099
1143
|
if (databricksOptions?.metadata != null) args.metadata = databricksOptions.metadata;
|
|
1100
1144
|
if (databricksOptions?.reasoning != null) args.reasoning = databricksOptions.reasoning;
|
|
1145
|
+
if (databricksOptions?.includeTrace != null) args.databricks_options = { return_trace: databricksOptions.includeTrace };
|
|
1101
1146
|
return {
|
|
1102
1147
|
args,
|
|
1103
1148
|
warnings
|
|
@@ -1139,16 +1184,16 @@ var DatabricksResponsesAgentLanguageModel = class {
|
|
|
1139
1184
|
}
|
|
1140
1185
|
supportedUrls = {};
|
|
1141
1186
|
async doGenerate(options) {
|
|
1142
|
-
const { warnings
|
|
1187
|
+
const { warnings,...networkArgs } = await this.getArgs({
|
|
1143
1188
|
config: this.config,
|
|
1144
1189
|
options,
|
|
1145
1190
|
stream: false,
|
|
1146
1191
|
modelId: this.modelId
|
|
1147
1192
|
});
|
|
1148
|
-
const { value: response } = await (0,
|
|
1193
|
+
const { value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
|
|
1149
1194
|
...networkArgs,
|
|
1150
|
-
successfulResponseHandler: (0,
|
|
1151
|
-
failedResponseHandler: (0,
|
|
1195
|
+
successfulResponseHandler: (0, __ai_sdk_provider_utils.createJsonResponseHandler)(responsesAgentResponseSchema),
|
|
1196
|
+
failedResponseHandler: (0, __ai_sdk_provider_utils.createJsonErrorResponseHandler)({
|
|
1152
1197
|
errorSchema: zod_v4.z.any(),
|
|
1153
1198
|
errorToMessage: (error) => JSON.stringify(error),
|
|
1154
1199
|
isRetryable: () => false
|
|
@@ -1175,24 +1220,25 @@ var DatabricksResponsesAgentLanguageModel = class {
|
|
|
1175
1220
|
reasoning: 0
|
|
1176
1221
|
}
|
|
1177
1222
|
},
|
|
1178
|
-
warnings
|
|
1223
|
+
warnings,
|
|
1224
|
+
response: { body: response }
|
|
1179
1225
|
};
|
|
1180
1226
|
}
|
|
1181
1227
|
async doStream(options) {
|
|
1182
|
-
const { warnings
|
|
1228
|
+
const { warnings,...networkArgs } = await this.getArgs({
|
|
1183
1229
|
config: this.config,
|
|
1184
1230
|
options,
|
|
1185
1231
|
stream: true,
|
|
1186
1232
|
modelId: this.modelId
|
|
1187
1233
|
});
|
|
1188
|
-
const { responseHeaders, value: response } = await (0,
|
|
1234
|
+
const { responseHeaders, value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
|
|
1189
1235
|
...networkArgs,
|
|
1190
|
-
failedResponseHandler: (0,
|
|
1236
|
+
failedResponseHandler: (0, __ai_sdk_provider_utils.createJsonErrorResponseHandler)({
|
|
1191
1237
|
errorSchema: zod_v4.z.any(),
|
|
1192
1238
|
errorToMessage: (error) => JSON.stringify(error),
|
|
1193
1239
|
isRetryable: () => false
|
|
1194
1240
|
}),
|
|
1195
|
-
successfulResponseHandler: (0,
|
|
1241
|
+
successfulResponseHandler: (0, __ai_sdk_provider_utils.createEventSourceResponseHandler)(looseResponseAgentChunkSchema),
|
|
1196
1242
|
abortSignal: options.abortSignal
|
|
1197
1243
|
});
|
|
1198
1244
|
let finishReason = {
|
|
@@ -1214,7 +1260,7 @@ var DatabricksResponsesAgentLanguageModel = class {
|
|
|
1214
1260
|
};
|
|
1215
1261
|
const allParts = [];
|
|
1216
1262
|
const useRemoteToolCalling = this.config.useRemoteToolCalling ?? false;
|
|
1217
|
-
const toolNamesByCallId =
|
|
1263
|
+
const toolNamesByCallId = new Map();
|
|
1218
1264
|
return {
|
|
1219
1265
|
stream: response.pipeThrough(new TransformStream({
|
|
1220
1266
|
start(controller) {
|
|
@@ -1282,15 +1328,17 @@ var DatabricksResponsesAgentLanguageModel = class {
|
|
|
1282
1328
|
}
|
|
1283
1329
|
}
|
|
1284
1330
|
if (shouldDedupeOutputItemDone(parts, allParts.slice(0, -parts.length))) return;
|
|
1285
|
-
for (const part of parts) controller.enqueue(part);
|
|
1331
|
+
for (const part$1 of parts) controller.enqueue(part$1);
|
|
1286
1332
|
},
|
|
1287
1333
|
flush(controller) {
|
|
1288
1334
|
if (!useRemoteToolCalling) {
|
|
1289
1335
|
const toolCalls = allParts.filter((p) => p.type === "tool-call");
|
|
1290
1336
|
const toolResults = allParts.filter((p) => p.type === "tool-result");
|
|
1291
1337
|
for (const toolCall of toolCalls) {
|
|
1292
|
-
|
|
1293
|
-
if (
|
|
1338
|
+
const isMcpApprovalRequest = toolCall.providerMetadata?.databricks?.approvalRequestId != null;
|
|
1339
|
+
if (isMcpApprovalRequest) continue;
|
|
1340
|
+
const hasResult = toolResults.some((r) => r.toolCallId === toolCall.toolCallId);
|
|
1341
|
+
if (!hasResult) controller.enqueue({
|
|
1294
1342
|
...toolCall,
|
|
1295
1343
|
providerExecuted: true,
|
|
1296
1344
|
dynamic: true
|
|
@@ -1320,7 +1368,7 @@ var DatabricksResponsesAgentLanguageModel = class {
|
|
|
1320
1368
|
const { args: callArgs, warnings } = callOptionsToResponsesArgs(options);
|
|
1321
1369
|
return {
|
|
1322
1370
|
url: config.url({ path: "/responses" }),
|
|
1323
|
-
headers: (0,
|
|
1371
|
+
headers: (0, __ai_sdk_provider_utils.combineHeaders)(config.headers(), options.headers),
|
|
1324
1372
|
body: {
|
|
1325
1373
|
model: modelId,
|
|
1326
1374
|
input,
|
|
@@ -1349,7 +1397,8 @@ function shouldDedupeOutputItemDone(incomingParts, previousParts) {
|
|
|
1349
1397
|
* corresponds to a specific message and we should only compare against text streamed for that message.
|
|
1350
1398
|
*/
|
|
1351
1399
|
const lastDoneIndex = previousParts.findLastIndex((part) => part.type === "text-delta" && part.providerMetadata?.databricks?.itemType === "response.output_item.done");
|
|
1352
|
-
const
|
|
1400
|
+
const partsAfterLastDone = previousParts.slice(lastDoneIndex + 1);
|
|
1401
|
+
const { texts: reconstructuredTexts, current } = partsAfterLastDone.reduce((acc, part) => {
|
|
1353
1402
|
if (part.type === "text-delta") return {
|
|
1354
1403
|
...acc,
|
|
1355
1404
|
current: acc.current + part.delta
|
|
@@ -1365,7 +1414,7 @@ function shouldDedupeOutputItemDone(incomingParts, previousParts) {
|
|
|
1365
1414
|
});
|
|
1366
1415
|
if (current.length > 0) reconstructuredTexts.push(current);
|
|
1367
1416
|
if (reconstructuredTexts.length === 0) return false;
|
|
1368
|
-
|
|
1417
|
+
const allTextsFoundInOrder = reconstructuredTexts.reduce((acc, text) => {
|
|
1369
1418
|
if (!acc.found) return acc;
|
|
1370
1419
|
const index = doneTextDelta.delta.indexOf(text, acc.lastIndex);
|
|
1371
1420
|
if (index === -1) return {
|
|
@@ -1379,7 +1428,8 @@ function shouldDedupeOutputItemDone(incomingParts, previousParts) {
|
|
|
1379
1428
|
}, {
|
|
1380
1429
|
found: true,
|
|
1381
1430
|
lastIndex: 0
|
|
1382
|
-
})
|
|
1431
|
+
});
|
|
1432
|
+
return allTextsFoundInOrder.found;
|
|
1383
1433
|
}
|
|
1384
1434
|
|
|
1385
1435
|
//#endregion
|
|
@@ -1555,13 +1605,14 @@ const mapContentItemsToStreamParts = (items, id) => {
|
|
|
1555
1605
|
});
|
|
1556
1606
|
break;
|
|
1557
1607
|
case "image": break;
|
|
1558
|
-
case "reasoning":
|
|
1608
|
+
case "reasoning": {
|
|
1559
1609
|
for (const summary of item.summary.filter((s) => s.type === "summary_text")) parts.push({
|
|
1560
1610
|
type: "reasoning-delta",
|
|
1561
1611
|
id,
|
|
1562
1612
|
delta: summary.text
|
|
1563
1613
|
});
|
|
1564
1614
|
break;
|
|
1615
|
+
}
|
|
1565
1616
|
}
|
|
1566
1617
|
return parts;
|
|
1567
1618
|
};
|
|
@@ -1575,12 +1626,13 @@ const mapContentItemsToProviderContent = (items) => {
|
|
|
1575
1626
|
});
|
|
1576
1627
|
break;
|
|
1577
1628
|
case "image": break;
|
|
1578
|
-
case "reasoning":
|
|
1629
|
+
case "reasoning": {
|
|
1579
1630
|
for (const summary of item.summary.filter((s) => s.type === "summary_text")) parts.push({
|
|
1580
1631
|
type: "reasoning",
|
|
1581
1632
|
text: summary.text
|
|
1582
1633
|
});
|
|
1583
1634
|
break;
|
|
1635
|
+
}
|
|
1584
1636
|
}
|
|
1585
1637
|
return parts;
|
|
1586
1638
|
};
|
|
@@ -1716,11 +1768,12 @@ const convertToolResultOutputToContentValue = (output) => {
|
|
|
1716
1768
|
};
|
|
1717
1769
|
const ProviderOptionsSchema = zod_v4.z.object({ toolName: zod_v4.z.string().nullish() });
|
|
1718
1770
|
const getToolNameFromPart = async (part) => {
|
|
1719
|
-
|
|
1771
|
+
const providerOptions = await (0, __ai_sdk_provider_utils.parseProviderOptions)({
|
|
1720
1772
|
provider: "databricks",
|
|
1721
1773
|
providerOptions: part.providerOptions,
|
|
1722
1774
|
schema: ProviderOptionsSchema
|
|
1723
|
-
})
|
|
1775
|
+
});
|
|
1776
|
+
return providerOptions?.toolName ?? part.toolName;
|
|
1724
1777
|
};
|
|
1725
1778
|
|
|
1726
1779
|
//#endregion
|
|
@@ -1829,16 +1882,16 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1829
1882
|
}
|
|
1830
1883
|
supportedUrls = {};
|
|
1831
1884
|
async doGenerate(options) {
|
|
1832
|
-
const { warnings
|
|
1885
|
+
const { warnings,...networkArgs } = await this.getArgs({
|
|
1833
1886
|
config: this.config,
|
|
1834
1887
|
options,
|
|
1835
1888
|
stream: false,
|
|
1836
1889
|
modelId: this.modelId
|
|
1837
1890
|
});
|
|
1838
|
-
const { value: response } = await (0,
|
|
1891
|
+
const { value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
|
|
1839
1892
|
...networkArgs,
|
|
1840
|
-
successfulResponseHandler: (0,
|
|
1841
|
-
failedResponseHandler: (0,
|
|
1893
|
+
successfulResponseHandler: (0, __ai_sdk_provider_utils.createJsonResponseHandler)(fmapiResponseSchema),
|
|
1894
|
+
failedResponseHandler: (0, __ai_sdk_provider_utils.createJsonErrorResponseHandler)({
|
|
1842
1895
|
errorSchema: zod_v4.z.any(),
|
|
1843
1896
|
errorToMessage: (error) => JSON.stringify(error),
|
|
1844
1897
|
isRetryable: () => false
|
|
@@ -1846,8 +1899,9 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1846
1899
|
});
|
|
1847
1900
|
const choice = response.choices[0];
|
|
1848
1901
|
const finishReason = mapFmapiFinishReason(choice?.finish_reason);
|
|
1902
|
+
const useRemoteToolCalling = this.config.useRemoteToolCalling ?? false;
|
|
1849
1903
|
return {
|
|
1850
|
-
content: convertFmapiResponseToMessagePart(response, { useRemoteToolCalling
|
|
1904
|
+
content: convertFmapiResponseToMessagePart(response, { useRemoteToolCalling }),
|
|
1851
1905
|
finishReason,
|
|
1852
1906
|
usage: {
|
|
1853
1907
|
inputTokens: {
|
|
@@ -1866,20 +1920,20 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1866
1920
|
};
|
|
1867
1921
|
}
|
|
1868
1922
|
async doStream(options) {
|
|
1869
|
-
const { warnings
|
|
1923
|
+
const { warnings,...networkArgs } = await this.getArgs({
|
|
1870
1924
|
config: this.config,
|
|
1871
1925
|
options,
|
|
1872
1926
|
stream: true,
|
|
1873
1927
|
modelId: this.modelId
|
|
1874
1928
|
});
|
|
1875
|
-
const { responseHeaders, value: response } = await (0,
|
|
1929
|
+
const { responseHeaders, value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
|
|
1876
1930
|
...networkArgs,
|
|
1877
|
-
failedResponseHandler: (0,
|
|
1931
|
+
failedResponseHandler: (0, __ai_sdk_provider_utils.createJsonErrorResponseHandler)({
|
|
1878
1932
|
errorSchema: zod_v4.z.any(),
|
|
1879
1933
|
errorToMessage: (error) => JSON.stringify(error),
|
|
1880
1934
|
isRetryable: () => false
|
|
1881
1935
|
}),
|
|
1882
|
-
successfulResponseHandler: (0,
|
|
1936
|
+
successfulResponseHandler: (0, __ai_sdk_provider_utils.createEventSourceResponseHandler)(fmapiChunkSchema),
|
|
1883
1937
|
abortSignal: options.abortSignal
|
|
1884
1938
|
});
|
|
1885
1939
|
let finishReason = {
|
|
@@ -1899,9 +1953,9 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1899
1953
|
reasoning: 0
|
|
1900
1954
|
}
|
|
1901
1955
|
};
|
|
1902
|
-
const toolCallIdsByIndex =
|
|
1903
|
-
const toolCallNamesById =
|
|
1904
|
-
const toolCallInputsById =
|
|
1956
|
+
const toolCallIdsByIndex = new Map();
|
|
1957
|
+
const toolCallNamesById = new Map();
|
|
1958
|
+
const toolCallInputsById = new Map();
|
|
1905
1959
|
const useRemoteToolCalling = this.config.useRemoteToolCalling ?? false;
|
|
1906
1960
|
return {
|
|
1907
1961
|
stream: response.pipeThrough(new TransformStream({
|
|
@@ -1992,7 +2046,7 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1992
2046
|
const { args: callArgs, warnings } = callOptionsToFmapiArgs(options);
|
|
1993
2047
|
return {
|
|
1994
2048
|
url: config.url({ path: "/chat/completions" }),
|
|
1995
|
-
headers: (0,
|
|
2049
|
+
headers: (0, __ai_sdk_provider_utils.combineHeaders)(config.headers(), options.headers),
|
|
1996
2050
|
body: {
|
|
1997
2051
|
messages,
|
|
1998
2052
|
stream,
|
|
@@ -2010,7 +2064,7 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
2010
2064
|
* Convert AI SDK tool to OpenAI format
|
|
2011
2065
|
*/
|
|
2012
2066
|
function convertToolToOpenAIFormat(tool) {
|
|
2013
|
-
if (tool.type === "provider") return;
|
|
2067
|
+
if (tool.type === "provider") return void 0;
|
|
2014
2068
|
return {
|
|
2015
2069
|
type: "function",
|
|
2016
2070
|
function: {
|
|
@@ -2037,8 +2091,8 @@ function convertToolChoiceToOpenAIFormat(toolChoice) {
|
|
|
2037
2091
|
//#endregion
|
|
2038
2092
|
//#region src/databricks-provider.ts
|
|
2039
2093
|
const createDatabricksProvider = (settings) => {
|
|
2040
|
-
const baseUrl = (0,
|
|
2041
|
-
const getHeaders = () => (0,
|
|
2094
|
+
const baseUrl = (0, __ai_sdk_provider_utils.withoutTrailingSlash)(settings.baseURL);
|
|
2095
|
+
const getHeaders = () => (0, __ai_sdk_provider_utils.combineHeaders)(settings.headers);
|
|
2042
2096
|
const fetch = settings.fetch;
|
|
2043
2097
|
const provider = settings.provider ?? "databricks";
|
|
2044
2098
|
const formatUrl = ({ path }) => settings.formatUrl?.({
|
|
@@ -2083,5 +2137,5 @@ const createDatabricksProvider = (settings) => {
|
|
|
2083
2137
|
};
|
|
2084
2138
|
|
|
2085
2139
|
//#endregion
|
|
2086
|
-
exports.createDatabricksProvider = createDatabricksProvider
|
|
2140
|
+
exports.createDatabricksProvider = createDatabricksProvider
|
|
2087
2141
|
//# sourceMappingURL=index.cjs.map
|