@databricks/ai-sdk-provider 0.4.0 → 0.5.0-rc.1
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 +132 -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 +78 -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;
|
|
@@ -956,6 +999,7 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
|
956
999
|
if (approvalIdsWithToolResult.has(part.approvalId)) continue;
|
|
957
1000
|
input.push({
|
|
958
1001
|
type: "mcp_approval_response",
|
|
1002
|
+
id: part.approvalId,
|
|
959
1003
|
approval_request_id: part.approvalId,
|
|
960
1004
|
approve: part.approved,
|
|
961
1005
|
...part.reason && { reason: part.reason }
|
|
@@ -1015,13 +1059,14 @@ function prepareResponsesTools({ tools, toolChoice }) {
|
|
|
1015
1059
|
tools: void 0,
|
|
1016
1060
|
toolChoice: void 0
|
|
1017
1061
|
};
|
|
1062
|
+
const convertedToolChoice = convertResponsesToolChoice(toolChoice);
|
|
1018
1063
|
return {
|
|
1019
1064
|
tools: responsesTools,
|
|
1020
|
-
toolChoice:
|
|
1065
|
+
toolChoice: convertedToolChoice
|
|
1021
1066
|
};
|
|
1022
1067
|
}
|
|
1023
1068
|
function convertResponsesToolChoice(toolChoice) {
|
|
1024
|
-
if (!toolChoice) return;
|
|
1069
|
+
if (!toolChoice) return void 0;
|
|
1025
1070
|
switch (toolChoice.type) {
|
|
1026
1071
|
case "auto": return "auto";
|
|
1027
1072
|
case "none": return "none";
|
|
@@ -1030,7 +1075,7 @@ function convertResponsesToolChoice(toolChoice) {
|
|
|
1030
1075
|
type: "function",
|
|
1031
1076
|
name: toolChoice.toolName
|
|
1032
1077
|
};
|
|
1033
|
-
default: return;
|
|
1078
|
+
default: return void 0;
|
|
1034
1079
|
}
|
|
1035
1080
|
}
|
|
1036
1081
|
|
|
@@ -1097,6 +1142,7 @@ function callOptionsToResponsesArgs(options) {
|
|
|
1097
1142
|
if (databricksOptions?.parallelToolCalls != null) args.parallel_tool_calls = databricksOptions.parallelToolCalls;
|
|
1098
1143
|
if (databricksOptions?.metadata != null) args.metadata = databricksOptions.metadata;
|
|
1099
1144
|
if (databricksOptions?.reasoning != null) args.reasoning = databricksOptions.reasoning;
|
|
1145
|
+
if (databricksOptions?.includeTrace != null) args.databricks_options = { return_trace: databricksOptions.includeTrace };
|
|
1100
1146
|
return {
|
|
1101
1147
|
args,
|
|
1102
1148
|
warnings
|
|
@@ -1138,16 +1184,16 @@ var DatabricksResponsesAgentLanguageModel = class {
|
|
|
1138
1184
|
}
|
|
1139
1185
|
supportedUrls = {};
|
|
1140
1186
|
async doGenerate(options) {
|
|
1141
|
-
const { warnings
|
|
1187
|
+
const { warnings,...networkArgs } = await this.getArgs({
|
|
1142
1188
|
config: this.config,
|
|
1143
1189
|
options,
|
|
1144
1190
|
stream: false,
|
|
1145
1191
|
modelId: this.modelId
|
|
1146
1192
|
});
|
|
1147
|
-
const { value: response } = await (0,
|
|
1193
|
+
const { value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
|
|
1148
1194
|
...networkArgs,
|
|
1149
|
-
successfulResponseHandler: (0,
|
|
1150
|
-
failedResponseHandler: (0,
|
|
1195
|
+
successfulResponseHandler: (0, __ai_sdk_provider_utils.createJsonResponseHandler)(responsesAgentResponseSchema),
|
|
1196
|
+
failedResponseHandler: (0, __ai_sdk_provider_utils.createJsonErrorResponseHandler)({
|
|
1151
1197
|
errorSchema: zod_v4.z.any(),
|
|
1152
1198
|
errorToMessage: (error) => JSON.stringify(error),
|
|
1153
1199
|
isRetryable: () => false
|
|
@@ -1174,24 +1220,25 @@ var DatabricksResponsesAgentLanguageModel = class {
|
|
|
1174
1220
|
reasoning: 0
|
|
1175
1221
|
}
|
|
1176
1222
|
},
|
|
1177
|
-
warnings
|
|
1223
|
+
warnings,
|
|
1224
|
+
response: { body: response }
|
|
1178
1225
|
};
|
|
1179
1226
|
}
|
|
1180
1227
|
async doStream(options) {
|
|
1181
|
-
const { warnings
|
|
1228
|
+
const { warnings,...networkArgs } = await this.getArgs({
|
|
1182
1229
|
config: this.config,
|
|
1183
1230
|
options,
|
|
1184
1231
|
stream: true,
|
|
1185
1232
|
modelId: this.modelId
|
|
1186
1233
|
});
|
|
1187
|
-
const { responseHeaders, value: response } = await (0,
|
|
1234
|
+
const { responseHeaders, value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
|
|
1188
1235
|
...networkArgs,
|
|
1189
|
-
failedResponseHandler: (0,
|
|
1236
|
+
failedResponseHandler: (0, __ai_sdk_provider_utils.createJsonErrorResponseHandler)({
|
|
1190
1237
|
errorSchema: zod_v4.z.any(),
|
|
1191
1238
|
errorToMessage: (error) => JSON.stringify(error),
|
|
1192
1239
|
isRetryable: () => false
|
|
1193
1240
|
}),
|
|
1194
|
-
successfulResponseHandler: (0,
|
|
1241
|
+
successfulResponseHandler: (0, __ai_sdk_provider_utils.createEventSourceResponseHandler)(looseResponseAgentChunkSchema),
|
|
1195
1242
|
abortSignal: options.abortSignal
|
|
1196
1243
|
});
|
|
1197
1244
|
let finishReason = {
|
|
@@ -1213,7 +1260,7 @@ var DatabricksResponsesAgentLanguageModel = class {
|
|
|
1213
1260
|
};
|
|
1214
1261
|
const allParts = [];
|
|
1215
1262
|
const useRemoteToolCalling = this.config.useRemoteToolCalling ?? false;
|
|
1216
|
-
const toolNamesByCallId =
|
|
1263
|
+
const toolNamesByCallId = new Map();
|
|
1217
1264
|
return {
|
|
1218
1265
|
stream: response.pipeThrough(new TransformStream({
|
|
1219
1266
|
start(controller) {
|
|
@@ -1281,15 +1328,17 @@ var DatabricksResponsesAgentLanguageModel = class {
|
|
|
1281
1328
|
}
|
|
1282
1329
|
}
|
|
1283
1330
|
if (shouldDedupeOutputItemDone(parts, allParts.slice(0, -parts.length))) return;
|
|
1284
|
-
for (const part of parts) controller.enqueue(part);
|
|
1331
|
+
for (const part$1 of parts) controller.enqueue(part$1);
|
|
1285
1332
|
},
|
|
1286
1333
|
flush(controller) {
|
|
1287
1334
|
if (!useRemoteToolCalling) {
|
|
1288
1335
|
const toolCalls = allParts.filter((p) => p.type === "tool-call");
|
|
1289
1336
|
const toolResults = allParts.filter((p) => p.type === "tool-result");
|
|
1290
1337
|
for (const toolCall of toolCalls) {
|
|
1291
|
-
|
|
1292
|
-
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({
|
|
1293
1342
|
...toolCall,
|
|
1294
1343
|
providerExecuted: true,
|
|
1295
1344
|
dynamic: true
|
|
@@ -1319,7 +1368,7 @@ var DatabricksResponsesAgentLanguageModel = class {
|
|
|
1319
1368
|
const { args: callArgs, warnings } = callOptionsToResponsesArgs(options);
|
|
1320
1369
|
return {
|
|
1321
1370
|
url: config.url({ path: "/responses" }),
|
|
1322
|
-
headers: (0,
|
|
1371
|
+
headers: (0, __ai_sdk_provider_utils.combineHeaders)(config.headers(), options.headers),
|
|
1323
1372
|
body: {
|
|
1324
1373
|
model: modelId,
|
|
1325
1374
|
input,
|
|
@@ -1348,7 +1397,8 @@ function shouldDedupeOutputItemDone(incomingParts, previousParts) {
|
|
|
1348
1397
|
* corresponds to a specific message and we should only compare against text streamed for that message.
|
|
1349
1398
|
*/
|
|
1350
1399
|
const lastDoneIndex = previousParts.findLastIndex((part) => part.type === "text-delta" && part.providerMetadata?.databricks?.itemType === "response.output_item.done");
|
|
1351
|
-
const
|
|
1400
|
+
const partsAfterLastDone = previousParts.slice(lastDoneIndex + 1);
|
|
1401
|
+
const { texts: reconstructuredTexts, current } = partsAfterLastDone.reduce((acc, part) => {
|
|
1352
1402
|
if (part.type === "text-delta") return {
|
|
1353
1403
|
...acc,
|
|
1354
1404
|
current: acc.current + part.delta
|
|
@@ -1364,7 +1414,7 @@ function shouldDedupeOutputItemDone(incomingParts, previousParts) {
|
|
|
1364
1414
|
});
|
|
1365
1415
|
if (current.length > 0) reconstructuredTexts.push(current);
|
|
1366
1416
|
if (reconstructuredTexts.length === 0) return false;
|
|
1367
|
-
|
|
1417
|
+
const allTextsFoundInOrder = reconstructuredTexts.reduce((acc, text) => {
|
|
1368
1418
|
if (!acc.found) return acc;
|
|
1369
1419
|
const index = doneTextDelta.delta.indexOf(text, acc.lastIndex);
|
|
1370
1420
|
if (index === -1) return {
|
|
@@ -1378,7 +1428,8 @@ function shouldDedupeOutputItemDone(incomingParts, previousParts) {
|
|
|
1378
1428
|
}, {
|
|
1379
1429
|
found: true,
|
|
1380
1430
|
lastIndex: 0
|
|
1381
|
-
})
|
|
1431
|
+
});
|
|
1432
|
+
return allTextsFoundInOrder.found;
|
|
1382
1433
|
}
|
|
1383
1434
|
|
|
1384
1435
|
//#endregion
|
|
@@ -1554,13 +1605,14 @@ const mapContentItemsToStreamParts = (items, id) => {
|
|
|
1554
1605
|
});
|
|
1555
1606
|
break;
|
|
1556
1607
|
case "image": break;
|
|
1557
|
-
case "reasoning":
|
|
1608
|
+
case "reasoning": {
|
|
1558
1609
|
for (const summary of item.summary.filter((s) => s.type === "summary_text")) parts.push({
|
|
1559
1610
|
type: "reasoning-delta",
|
|
1560
1611
|
id,
|
|
1561
1612
|
delta: summary.text
|
|
1562
1613
|
});
|
|
1563
1614
|
break;
|
|
1615
|
+
}
|
|
1564
1616
|
}
|
|
1565
1617
|
return parts;
|
|
1566
1618
|
};
|
|
@@ -1574,12 +1626,13 @@ const mapContentItemsToProviderContent = (items) => {
|
|
|
1574
1626
|
});
|
|
1575
1627
|
break;
|
|
1576
1628
|
case "image": break;
|
|
1577
|
-
case "reasoning":
|
|
1629
|
+
case "reasoning": {
|
|
1578
1630
|
for (const summary of item.summary.filter((s) => s.type === "summary_text")) parts.push({
|
|
1579
1631
|
type: "reasoning",
|
|
1580
1632
|
text: summary.text
|
|
1581
1633
|
});
|
|
1582
1634
|
break;
|
|
1635
|
+
}
|
|
1583
1636
|
}
|
|
1584
1637
|
return parts;
|
|
1585
1638
|
};
|
|
@@ -1715,11 +1768,12 @@ const convertToolResultOutputToContentValue = (output) => {
|
|
|
1715
1768
|
};
|
|
1716
1769
|
const ProviderOptionsSchema = zod_v4.z.object({ toolName: zod_v4.z.string().nullish() });
|
|
1717
1770
|
const getToolNameFromPart = async (part) => {
|
|
1718
|
-
|
|
1771
|
+
const providerOptions = await (0, __ai_sdk_provider_utils.parseProviderOptions)({
|
|
1719
1772
|
provider: "databricks",
|
|
1720
1773
|
providerOptions: part.providerOptions,
|
|
1721
1774
|
schema: ProviderOptionsSchema
|
|
1722
|
-
})
|
|
1775
|
+
});
|
|
1776
|
+
return providerOptions?.toolName ?? part.toolName;
|
|
1723
1777
|
};
|
|
1724
1778
|
|
|
1725
1779
|
//#endregion
|
|
@@ -1828,16 +1882,16 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1828
1882
|
}
|
|
1829
1883
|
supportedUrls = {};
|
|
1830
1884
|
async doGenerate(options) {
|
|
1831
|
-
const { warnings
|
|
1885
|
+
const { warnings,...networkArgs } = await this.getArgs({
|
|
1832
1886
|
config: this.config,
|
|
1833
1887
|
options,
|
|
1834
1888
|
stream: false,
|
|
1835
1889
|
modelId: this.modelId
|
|
1836
1890
|
});
|
|
1837
|
-
const { value: response } = await (0,
|
|
1891
|
+
const { value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
|
|
1838
1892
|
...networkArgs,
|
|
1839
|
-
successfulResponseHandler: (0,
|
|
1840
|
-
failedResponseHandler: (0,
|
|
1893
|
+
successfulResponseHandler: (0, __ai_sdk_provider_utils.createJsonResponseHandler)(fmapiResponseSchema),
|
|
1894
|
+
failedResponseHandler: (0, __ai_sdk_provider_utils.createJsonErrorResponseHandler)({
|
|
1841
1895
|
errorSchema: zod_v4.z.any(),
|
|
1842
1896
|
errorToMessage: (error) => JSON.stringify(error),
|
|
1843
1897
|
isRetryable: () => false
|
|
@@ -1845,8 +1899,9 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1845
1899
|
});
|
|
1846
1900
|
const choice = response.choices[0];
|
|
1847
1901
|
const finishReason = mapFmapiFinishReason(choice?.finish_reason);
|
|
1902
|
+
const useRemoteToolCalling = this.config.useRemoteToolCalling ?? false;
|
|
1848
1903
|
return {
|
|
1849
|
-
content: convertFmapiResponseToMessagePart(response, { useRemoteToolCalling
|
|
1904
|
+
content: convertFmapiResponseToMessagePart(response, { useRemoteToolCalling }),
|
|
1850
1905
|
finishReason,
|
|
1851
1906
|
usage: {
|
|
1852
1907
|
inputTokens: {
|
|
@@ -1865,20 +1920,20 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1865
1920
|
};
|
|
1866
1921
|
}
|
|
1867
1922
|
async doStream(options) {
|
|
1868
|
-
const { warnings
|
|
1923
|
+
const { warnings,...networkArgs } = await this.getArgs({
|
|
1869
1924
|
config: this.config,
|
|
1870
1925
|
options,
|
|
1871
1926
|
stream: true,
|
|
1872
1927
|
modelId: this.modelId
|
|
1873
1928
|
});
|
|
1874
|
-
const { responseHeaders, value: response } = await (0,
|
|
1929
|
+
const { responseHeaders, value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
|
|
1875
1930
|
...networkArgs,
|
|
1876
|
-
failedResponseHandler: (0,
|
|
1931
|
+
failedResponseHandler: (0, __ai_sdk_provider_utils.createJsonErrorResponseHandler)({
|
|
1877
1932
|
errorSchema: zod_v4.z.any(),
|
|
1878
1933
|
errorToMessage: (error) => JSON.stringify(error),
|
|
1879
1934
|
isRetryable: () => false
|
|
1880
1935
|
}),
|
|
1881
|
-
successfulResponseHandler: (0,
|
|
1936
|
+
successfulResponseHandler: (0, __ai_sdk_provider_utils.createEventSourceResponseHandler)(fmapiChunkSchema),
|
|
1882
1937
|
abortSignal: options.abortSignal
|
|
1883
1938
|
});
|
|
1884
1939
|
let finishReason = {
|
|
@@ -1898,9 +1953,9 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1898
1953
|
reasoning: 0
|
|
1899
1954
|
}
|
|
1900
1955
|
};
|
|
1901
|
-
const toolCallIdsByIndex =
|
|
1902
|
-
const toolCallNamesById =
|
|
1903
|
-
const toolCallInputsById =
|
|
1956
|
+
const toolCallIdsByIndex = new Map();
|
|
1957
|
+
const toolCallNamesById = new Map();
|
|
1958
|
+
const toolCallInputsById = new Map();
|
|
1904
1959
|
const useRemoteToolCalling = this.config.useRemoteToolCalling ?? false;
|
|
1905
1960
|
return {
|
|
1906
1961
|
stream: response.pipeThrough(new TransformStream({
|
|
@@ -1991,7 +2046,7 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1991
2046
|
const { args: callArgs, warnings } = callOptionsToFmapiArgs(options);
|
|
1992
2047
|
return {
|
|
1993
2048
|
url: config.url({ path: "/chat/completions" }),
|
|
1994
|
-
headers: (0,
|
|
2049
|
+
headers: (0, __ai_sdk_provider_utils.combineHeaders)(config.headers(), options.headers),
|
|
1995
2050
|
body: {
|
|
1996
2051
|
messages,
|
|
1997
2052
|
stream,
|
|
@@ -2009,7 +2064,7 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
2009
2064
|
* Convert AI SDK tool to OpenAI format
|
|
2010
2065
|
*/
|
|
2011
2066
|
function convertToolToOpenAIFormat(tool) {
|
|
2012
|
-
if (tool.type === "provider") return;
|
|
2067
|
+
if (tool.type === "provider") return void 0;
|
|
2013
2068
|
return {
|
|
2014
2069
|
type: "function",
|
|
2015
2070
|
function: {
|
|
@@ -2036,8 +2091,8 @@ function convertToolChoiceToOpenAIFormat(toolChoice) {
|
|
|
2036
2091
|
//#endregion
|
|
2037
2092
|
//#region src/databricks-provider.ts
|
|
2038
2093
|
const createDatabricksProvider = (settings) => {
|
|
2039
|
-
const baseUrl = (0,
|
|
2040
|
-
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);
|
|
2041
2096
|
const fetch = settings.fetch;
|
|
2042
2097
|
const provider = settings.provider ?? "databricks";
|
|
2043
2098
|
const formatUrl = ({ path }) => settings.formatUrl?.({
|
|
@@ -2082,5 +2137,5 @@ const createDatabricksProvider = (settings) => {
|
|
|
2082
2137
|
};
|
|
2083
2138
|
|
|
2084
2139
|
//#endregion
|
|
2085
|
-
exports.createDatabricksProvider = createDatabricksProvider
|
|
2140
|
+
exports.createDatabricksProvider = createDatabricksProvider
|
|
2086
2141
|
//# sourceMappingURL=index.cjs.map
|