@databricks/ai-sdk-provider 0.2.2 → 0.3.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 CHANGED
@@ -1,31 +1,7 @@
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"));
1
+ let _ai_sdk_provider_utils = require("@ai-sdk/provider-utils");
2
+ let zod_v4 = require("zod/v4");
3
+ let node_crypto = require("node:crypto");
4
+ let _ai_sdk_provider = require("@ai-sdk/provider");
29
5
 
30
6
  //#region src/chat-agent-language-model/chat-agent-schema.ts
31
7
  const chatAgentToolCallSchema = zod_v4.z.object({
@@ -70,26 +46,6 @@ const chatAgentResponseSchema = zod_v4.z.object({
70
46
  messages: zod_v4.z.array(chatAgentMessageSchema)
71
47
  });
72
48
 
73
- //#endregion
74
- //#region src/tools.ts
75
- const DATABRICKS_TOOL_CALL_ID = "databricks-tool-call";
76
- /**
77
- * The AI-SDK requires that tools used by the model are defined ahead of time.
78
- *
79
- * Since tool calls can be orchestrated by Databricks' agents we don't know the name, input, or output schemas
80
- * of the tools until the model is called.
81
- *
82
- * In the DatabricksProvider we transform all tool calls to fit this definition, and keep the
83
- * original name as part of the metadata. This allows us to parse any tool orchestrated by Databricks' agents,
84
- * while still being able to render the tool call and result in the UI, and pass it back to the model with the correct name.
85
- */
86
- const DATABRICKS_TOOL_DEFINITION = {
87
- name: DATABRICKS_TOOL_CALL_ID,
88
- description: "Databricks tool call",
89
- inputSchema: zod_v4.z.any(),
90
- outputSchema: zod_v4.z.any()
91
- };
92
-
93
49
  //#endregion
94
50
  //#region src/chat-agent-language-model/chat-agent-convert-to-message-parts.ts
95
51
  const convertChatAgentChunkToMessagePart = (chunk) => {
@@ -105,14 +61,16 @@ const convertChatAgentChunkToMessagePart = (chunk) => {
105
61
  type: "tool-call",
106
62
  toolCallId: toolCall.id,
107
63
  input: toolCall.function.arguments,
108
- toolName: toolCall.function.name
64
+ toolName: toolCall.function.name,
65
+ dynamic: true,
66
+ providerExecuted: true
109
67
  });
110
68
  });
111
69
  } else if (chunk.delta.role === "tool") parts.push({
112
70
  type: "tool-result",
113
71
  toolCallId: chunk.delta.tool_call_id,
114
72
  result: chunk.delta.content,
115
- toolName: DATABRICKS_TOOL_CALL_ID
73
+ toolName: chunk.delta.name ?? "unknown"
116
74
  });
117
75
  return parts;
118
76
  };
@@ -127,20 +85,22 @@ const convertChatAgentResponseToMessagePart = (response) => {
127
85
  type: "tool-call",
128
86
  toolCallId: part.id,
129
87
  input: part.function.arguments,
130
- toolName: part.function.name
88
+ toolName: part.function.name,
89
+ dynamic: true,
90
+ providerExecuted: true
131
91
  });
132
92
  } else if (message.role === "tool") parts.push({
133
93
  type: "tool-result",
134
94
  toolCallId: message.tool_call_id,
135
95
  result: message.content,
136
- toolName: DATABRICKS_TOOL_CALL_ID
96
+ toolName: message.name ?? "unknown"
137
97
  });
138
98
  return parts;
139
99
  };
140
100
 
141
101
  //#endregion
142
102
  //#region src/chat-agent-language-model/chat-agent-convert-to-input.ts
143
- const convertLanguageModelV2PromptToChatAgentResponse = (prompt) => {
103
+ const convertLanguageModelV3PromptToChatAgentResponse = (prompt) => {
144
104
  const messages = [];
145
105
  let messageIndex = 0;
146
106
  for (const msg of prompt) switch (msg.role) {
@@ -167,10 +127,9 @@ const convertLanguageModelV2PromptToChatAgentResponse = (prompt) => {
167
127
  return messages;
168
128
  };
169
129
  const convertUserMessage$1 = (msg, messageIndex) => {
170
- const text = (msg.content ?? []).filter((part) => part.type === "text").map((part) => part.text).join("\n");
171
130
  return {
172
131
  role: "user",
173
- content: text,
132
+ content: (msg.content ?? []).filter((part) => part.type === "text").map((part) => part.text).join("\n"),
174
133
  id: `user-${messageIndex}`
175
134
  };
176
135
  };
@@ -243,10 +202,7 @@ const convertToolResultOutput = (output) => {
243
202
  function composeDatabricksStreamPartTransformers(...transformers) {
244
203
  return (initialParts, last = null) => {
245
204
  let currentParts = initialParts;
246
- for (const fn of transformers) {
247
- const result = fn(currentParts, last);
248
- currentParts = result.out;
249
- }
205
+ for (const fn of transformers) currentParts = fn(currentParts, last).out;
250
206
  return { out: currentParts };
251
207
  };
252
208
  }
@@ -263,8 +219,7 @@ const applyDeltaBoundaryTransform = (parts, last) => {
263
219
  const incomingDeltaType = maybeGetDeltaType(incoming);
264
220
  const incomingId = getPartId$1(incoming);
265
221
  const lastId = getPartId$1(last);
266
- const incomingMatchesLast = Boolean(isDeltaPart(last) && isDeltaPart(incoming)) && Boolean(lastDeltaType && incomingDeltaType) && Boolean(lastDeltaType === incomingDeltaType) && Boolean(incomingId && lastId && incomingId === lastId);
267
- if (incomingMatchesLast) {
222
+ if (Boolean(isDeltaPart(last) && isDeltaPart(incoming)) && Boolean(lastDeltaType && incomingDeltaType) && Boolean(lastDeltaType === incomingDeltaType) && Boolean(incomingId && lastId && incomingId === lastId)) {
268
223
  out.push(incoming);
269
224
  continue;
270
225
  }
@@ -280,7 +235,6 @@ const applyDeltaBoundaryTransform = (parts, last) => {
280
235
  continue;
281
236
  }
282
237
  out.push(incoming);
283
- continue;
284
238
  }
285
239
  return { out };
286
240
  };
@@ -299,7 +253,6 @@ const getDeltaType = (part) => {
299
253
  const isDeltaPart = (part) => part?.type === "text-delta" || part?.type === "reasoning-delta";
300
254
  const getPartId$1 = (part) => {
301
255
  if (part && "id" in part) return part.id;
302
- return void 0;
303
256
  };
304
257
 
305
258
  //#endregion
@@ -312,7 +265,7 @@ const getPartId$1 = (part) => {
312
265
  */
313
266
  const getDatabricksLanguageModelTransformStream = () => {
314
267
  let lastChunk = null;
315
- const deltaEndByTypeAndId = new Set();
268
+ const deltaEndByTypeAndId = /* @__PURE__ */ new Set();
316
269
  const transformerStreamParts = composeDatabricksStreamPartTransformers(applyDeltaBoundaryTransform);
317
270
  return new TransformStream({
318
271
  transform(chunk, controller) {
@@ -354,14 +307,13 @@ const getDeltaGroup = (type) => {
354
307
  };
355
308
  const getPartId = (part) => {
356
309
  if ("id" in part) return part.id;
357
- return void 0;
358
310
  };
359
311
  const makeEndKey = (id, group) => id && group ? `${group}:${id}` : null;
360
312
 
361
313
  //#endregion
362
314
  //#region src/chat-agent-language-model/chat-agent-language-model.ts
363
315
  var DatabricksChatAgentLanguageModel = class {
364
- specificationVersion = "v2";
316
+ specificationVersion = "v3";
365
317
  modelId;
366
318
  config;
367
319
  constructor(modelId, config) {
@@ -373,16 +325,15 @@ var DatabricksChatAgentLanguageModel = class {
373
325
  }
374
326
  supportedUrls = {};
375
327
  async doGenerate(options) {
376
- const networkArgs = this.getArgs({
377
- config: this.config,
378
- options,
379
- stream: false,
380
- modelId: this.modelId
381
- });
382
- const { value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
383
- ...networkArgs,
384
- successfulResponseHandler: (0, __ai_sdk_provider_utils.createJsonResponseHandler)(chatAgentResponseSchema),
385
- failedResponseHandler: (0, __ai_sdk_provider_utils.createJsonErrorResponseHandler)({
328
+ const { value: response } = await (0, _ai_sdk_provider_utils.postJsonToApi)({
329
+ ...this.getArgs({
330
+ config: this.config,
331
+ options,
332
+ stream: false,
333
+ modelId: this.modelId
334
+ }),
335
+ successfulResponseHandler: (0, _ai_sdk_provider_utils.createJsonResponseHandler)(chatAgentResponseSchema),
336
+ failedResponseHandler: (0, _ai_sdk_provider_utils.createJsonErrorResponseHandler)({
386
337
  errorSchema: zod_v4.z.any(),
387
338
  errorToMessage: (error) => JSON.stringify(error),
388
339
  isRetryable: () => false
@@ -390,11 +341,22 @@ var DatabricksChatAgentLanguageModel = class {
390
341
  });
391
342
  return {
392
343
  content: convertChatAgentResponseToMessagePart(response),
393
- finishReason: "stop",
344
+ finishReason: {
345
+ raw: void 0,
346
+ unified: "stop"
347
+ },
394
348
  usage: {
395
- inputTokens: 0,
396
- outputTokens: 0,
397
- totalTokens: 0
349
+ inputTokens: {
350
+ total: 0,
351
+ noCache: 0,
352
+ cacheRead: 0,
353
+ cacheWrite: 0
354
+ },
355
+ outputTokens: {
356
+ total: 0,
357
+ text: 0,
358
+ reasoning: 0
359
+ }
398
360
  },
399
361
  warnings: []
400
362
  };
@@ -406,16 +368,19 @@ var DatabricksChatAgentLanguageModel = class {
406
368
  stream: true,
407
369
  modelId: this.modelId
408
370
  });
409
- const { responseHeaders, value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
371
+ const { responseHeaders, value: response } = await (0, _ai_sdk_provider_utils.postJsonToApi)({
410
372
  ...networkArgs,
411
- failedResponseHandler: (0, __ai_sdk_provider_utils.createJsonErrorResponseHandler)({
373
+ failedResponseHandler: (0, _ai_sdk_provider_utils.createJsonErrorResponseHandler)({
412
374
  errorSchema: zod_v4.z.any(),
413
375
  errorToMessage: (error) => JSON.stringify(error),
414
376
  isRetryable: () => false
415
377
  }),
416
- successfulResponseHandler: (0, __ai_sdk_provider_utils.createEventSourceResponseHandler)(chatAgentChunkSchema)
378
+ successfulResponseHandler: (0, _ai_sdk_provider_utils.createEventSourceResponseHandler)(chatAgentChunkSchema)
417
379
  });
418
- let finishReason = "unknown";
380
+ let finishReason = {
381
+ raw: void 0,
382
+ unified: "other"
383
+ };
419
384
  return {
420
385
  stream: response.pipeThrough(new TransformStream({
421
386
  start(controller) {
@@ -430,7 +395,10 @@ var DatabricksChatAgentLanguageModel = class {
430
395
  rawValue: chunk.rawValue
431
396
  });
432
397
  if (!chunk.success) {
433
- finishReason = "error";
398
+ finishReason = {
399
+ raw: void 0,
400
+ unified: "error"
401
+ };
434
402
  controller.enqueue({
435
403
  type: "error",
436
404
  error: chunk.error
@@ -445,9 +413,17 @@ var DatabricksChatAgentLanguageModel = class {
445
413
  type: "finish",
446
414
  finishReason,
447
415
  usage: {
448
- inputTokens: 0,
449
- outputTokens: 0,
450
- totalTokens: 0
416
+ inputTokens: {
417
+ total: 0,
418
+ noCache: 0,
419
+ cacheRead: 0,
420
+ cacheWrite: 0
421
+ },
422
+ outputTokens: {
423
+ total: 0,
424
+ text: 0,
425
+ reasoning: 0
426
+ }
451
427
  }
452
428
  });
453
429
  }
@@ -461,10 +437,10 @@ var DatabricksChatAgentLanguageModel = class {
461
437
  body: {
462
438
  model: modelId,
463
439
  stream,
464
- messages: convertLanguageModelV2PromptToChatAgentResponse(options.prompt)
440
+ messages: convertLanguageModelV3PromptToChatAgentResponse(options.prompt)
465
441
  },
466
442
  url: config.url({ path: "/completions" }),
467
- headers: (0, __ai_sdk_provider_utils.combineHeaders)(config.headers(), options.headers),
443
+ headers: (0, _ai_sdk_provider_utils.combineHeaders)(config.headers(), options.headers),
468
444
  fetch: config.fetch,
469
445
  abortSignal: options.abortSignal
470
446
  };
@@ -692,7 +668,6 @@ function isMcpApprovalResponse(metadata) {
692
668
  */
693
669
  function extractDatabricksMetadata(part) {
694
670
  if ("callProviderMetadata" in part && part.callProviderMetadata?.databricks) return part.callProviderMetadata.databricks;
695
- return void 0;
696
671
  }
697
672
  /**
698
673
  * Extract the approval status boolean from an output object.
@@ -707,7 +682,6 @@ function extractDatabricksMetadata(part) {
707
682
  */
708
683
  function extractApprovalStatus(output) {
709
684
  if (isApprovalStatusOutput(output)) return output[MCP_APPROVAL_STATUS_KEY];
710
- return void 0;
711
685
  }
712
686
  /**
713
687
  * Extract approval status from a tool result's output value.
@@ -721,7 +695,6 @@ function extractApprovalStatusFromToolResult(output) {
721
695
  const value = output.value[MCP_APPROVAL_STATUS_KEY];
722
696
  if (typeof value === "boolean") return value;
723
697
  }
724
- return void 0;
725
698
  }
726
699
  /**
727
700
  * Create an approval status output object.
@@ -757,7 +730,7 @@ function getMcpApprovalState(output) {
757
730
 
758
731
  //#endregion
759
732
  //#region src/responses-agent-language-model/responses-convert-to-message-parts.ts
760
- const convertResponsesAgentChunkToMessagePart = (chunk) => {
733
+ const convertResponsesAgentChunkToMessagePart = (chunk, options = { useRemoteToolCalling: false }) => {
761
734
  const parts = [];
762
735
  if ("error" in chunk) {
763
736
  parts.push({
@@ -787,12 +760,12 @@ const convertResponsesAgentChunkToMessagePart = (chunk) => {
787
760
  parts.push({
788
761
  type: "tool-result",
789
762
  toolCallId: chunk.call_id,
790
- result: chunk.output,
791
- toolName: DATABRICKS_TOOL_CALL_ID
763
+ result: chunk.output != null ? chunk.output : {},
764
+ toolName: options.toolNamesByCallId?.get(chunk.call_id) ?? "unknown"
792
765
  });
793
766
  break;
794
767
  case "response.output_item.done":
795
- parts.push(...convertOutputItemDone(chunk.item));
768
+ parts.push(...convertOutputItemDone(chunk.item, options));
796
769
  break;
797
770
  case "response.output_text.annotation.added":
798
771
  parts.push({
@@ -813,7 +786,7 @@ const convertResponsesAgentChunkToMessagePart = (chunk) => {
813
786
  }
814
787
  return parts;
815
788
  };
816
- const convertOutputItemDone = (item) => {
789
+ const convertOutputItemDone = (item, options) => {
817
790
  switch (item.type) {
818
791
  case "message": {
819
792
  const firstContent = item.content[0];
@@ -831,18 +804,19 @@ const convertOutputItemDone = (item) => {
831
804
  case "function_call": return [{
832
805
  type: "tool-call",
833
806
  toolCallId: item.call_id,
834
- toolName: DATABRICKS_TOOL_CALL_ID,
807
+ toolName: item.name,
835
808
  input: item.arguments,
836
- providerMetadata: { databricks: {
837
- toolName: item.name,
838
- itemId: item.id
839
- } }
809
+ ...options.useRemoteToolCalling && {
810
+ dynamic: true,
811
+ providerExecuted: true
812
+ },
813
+ providerMetadata: { databricks: { itemId: item.id } }
840
814
  }];
841
815
  case "function_call_output": return [{
842
816
  type: "tool-result",
843
817
  toolCallId: item.call_id,
844
- result: item.output,
845
- toolName: DATABRICKS_TOOL_CALL_ID
818
+ result: item.output != null ? item.output : {},
819
+ toolName: options.toolNamesByCallId?.get(item.call_id) ?? "unknown"
846
820
  }];
847
821
  case "reasoning": {
848
822
  const firstSummary = item.summary[0];
@@ -867,11 +841,14 @@ const convertOutputItemDone = (item) => {
867
841
  case "mcp_approval_request": return [{
868
842
  type: "tool-call",
869
843
  toolCallId: item.id,
870
- toolName: DATABRICKS_TOOL_CALL_ID,
844
+ toolName: item.name,
871
845
  input: item.arguments,
846
+ ...options.useRemoteToolCalling && {
847
+ dynamic: true,
848
+ providerExecuted: true
849
+ },
872
850
  providerMetadata: { databricks: {
873
851
  type: MCP_APPROVAL_REQUEST_TYPE,
874
- toolName: item.name,
875
852
  itemId: item.id,
876
853
  serverLabel: item.server_label
877
854
  } }
@@ -879,7 +856,7 @@ const convertOutputItemDone = (item) => {
879
856
  case "mcp_approval_response": return [{
880
857
  type: "tool-result",
881
858
  toolCallId: item.approval_request_id,
882
- toolName: DATABRICKS_TOOL_CALL_ID,
859
+ toolName: options.toolNamesByCallId?.get(item.approval_request_id) ?? "mcp_approval",
883
860
  result: createApprovalStatusOutput(item.approve),
884
861
  providerMetadata: { databricks: {
885
862
  type: MCP_APPROVAL_RESPONSE_TYPE,
@@ -889,27 +866,30 @@ const convertOutputItemDone = (item) => {
889
866
  default: return [];
890
867
  }
891
868
  };
892
- const convertResponsesAgentResponseToMessagePart = (response) => {
869
+ const convertResponsesAgentResponseToMessagePart = (response, options = { useRemoteToolCalling: false }) => {
893
870
  const parts = [];
871
+ const toolNamesByCallId = /* @__PURE__ */ new Map();
872
+ for (const output of response.output) if (output.type === "function_call") toolNamesByCallId.set(output.call_id, output.name);
873
+ else if (output.type === "mcp_approval_request") toolNamesByCallId.set(output.id, output.name);
894
874
  for (const output of response.output) switch (output.type) {
895
- case "message": {
875
+ case "message":
896
876
  for (const content of output.content) if (content.type === "output_text") parts.push({
897
877
  type: "text",
898
878
  text: content.text,
899
879
  providerMetadata: { databricks: { itemId: output.id } }
900
880
  });
901
881
  break;
902
- }
903
882
  case "function_call":
904
883
  parts.push({
905
884
  type: "tool-call",
906
885
  toolCallId: output.call_id,
907
- toolName: DATABRICKS_TOOL_CALL_ID,
886
+ toolName: output.name,
908
887
  input: output.arguments,
909
- providerMetadata: { databricks: {
910
- toolName: output.name,
911
- itemId: output.id
912
- } }
888
+ ...options.useRemoteToolCalling && {
889
+ dynamic: true,
890
+ providerExecuted: true
891
+ },
892
+ providerMetadata: { databricks: { itemId: output.id } }
913
893
  });
914
894
  break;
915
895
  case "reasoning":
@@ -924,18 +904,17 @@ const convertResponsesAgentResponseToMessagePart = (response) => {
924
904
  type: "tool-result",
925
905
  result: output.output,
926
906
  toolCallId: output.call_id,
927
- toolName: DATABRICKS_TOOL_CALL_ID
907
+ toolName: toolNamesByCallId.get(output.call_id) ?? "unknown"
928
908
  });
929
909
  break;
930
910
  case "mcp_approval_request":
931
911
  parts.push({
932
912
  type: "tool-call",
933
913
  toolCallId: output.id,
934
- toolName: DATABRICKS_TOOL_CALL_ID,
914
+ toolName: output.name,
935
915
  input: output.arguments,
936
916
  providerMetadata: { databricks: {
937
917
  type: MCP_APPROVAL_REQUEST_TYPE,
938
- toolName: output.name,
939
918
  itemId: output.id,
940
919
  serverLabel: output.server_label
941
920
  } }
@@ -945,7 +924,7 @@ const convertResponsesAgentResponseToMessagePart = (response) => {
945
924
  parts.push({
946
925
  type: "tool-result",
947
926
  toolCallId: output.approval_request_id,
948
- toolName: DATABRICKS_TOOL_CALL_ID,
927
+ toolName: toolNamesByCallId.get(output.approval_request_id) ?? "mcp_approval",
949
928
  result: createApprovalStatusOutput(output.approve),
950
929
  providerMetadata: { databricks: {
951
930
  type: MCP_APPROVAL_RESPONSE_TYPE,
@@ -968,7 +947,7 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
968
947
  return reduction;
969
948
  }, {});
970
949
  for (const { role, content } of prompt) switch (role) {
971
- case "system": {
950
+ case "system":
972
951
  switch (systemMessageMode) {
973
952
  case "system":
974
953
  input.push({
@@ -994,7 +973,6 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
994
973
  }
995
974
  }
996
975
  break;
997
- }
998
976
  case "user":
999
977
  input.push({
1000
978
  role: "user",
@@ -1004,21 +982,21 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
1004
982
  type: "input_text",
1005
983
  text: part.text
1006
984
  };
1007
- default: throw new __ai_sdk_provider.UnsupportedFunctionalityError({ functionality: `part ${JSON.stringify(part)}` });
985
+ default: throw new _ai_sdk_provider.UnsupportedFunctionalityError({ functionality: `part ${JSON.stringify(part)}` });
1008
986
  }
1009
987
  })
1010
988
  });
1011
989
  break;
1012
990
  case "assistant":
1013
991
  for (const part of content) {
1014
- const providerOptions = await (0, __ai_sdk_provider_utils.parseProviderOptions)({
992
+ const providerOptions = await (0, _ai_sdk_provider_utils.parseProviderOptions)({
1015
993
  provider: "databricks",
1016
994
  providerOptions: part.providerOptions,
1017
995
  schema: ProviderOptionsSchema$1
1018
996
  });
1019
997
  const itemId = providerOptions?.itemId ?? void 0;
1020
998
  switch (part.type) {
1021
- case "text": {
999
+ case "text":
1022
1000
  input.push({
1023
1001
  role: "assistant",
1024
1002
  content: [{
@@ -1028,7 +1006,6 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
1028
1006
  id: itemId
1029
1007
  });
1030
1008
  break;
1031
- }
1032
1009
  case "tool-call": {
1033
1010
  const toolName = providerOptions?.toolName ?? part.toolName;
1034
1011
  if (providerOptions?.type === MCP_APPROVAL_REQUEST_TYPE) {
@@ -1079,7 +1056,7 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
1079
1056
  });
1080
1057
  break;
1081
1058
  }
1082
- case "tool-result": {
1059
+ case "tool-result":
1083
1060
  if (providerOptions?.type === MCP_APPROVAL_RESPONSE_TYPE) {
1084
1061
  const approvalRequestId = providerOptions?.approvalRequestId ?? part.toolCallId;
1085
1062
  const approve = providerOptions?.approve ?? false;
@@ -1099,8 +1076,7 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
1099
1076
  output: convertToolResultOutputToString(part.output)
1100
1077
  });
1101
1078
  break;
1102
- }
1103
- case "reasoning": {
1079
+ case "reasoning":
1104
1080
  if (!itemId) break;
1105
1081
  input.push({
1106
1082
  type: "reasoning",
@@ -1111,7 +1087,6 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
1111
1087
  id: itemId
1112
1088
  });
1113
1089
  break;
1114
- }
1115
1090
  }
1116
1091
  }
1117
1092
  break;
@@ -1139,7 +1114,10 @@ const convertToolResultOutputToString = (output) => {
1139
1114
  switch (output.type) {
1140
1115
  case "text":
1141
1116
  case "error-text": return output.value;
1142
- default: return JSON.stringify(output.value);
1117
+ case "execution-denied": return output.reason ?? "Execution denied";
1118
+ case "json":
1119
+ case "error-json":
1120
+ case "content": return JSON.stringify(output.value);
1143
1121
  }
1144
1122
  };
1145
1123
 
@@ -1157,7 +1135,7 @@ function prepareResponsesTools({ tools, toolChoice }) {
1157
1135
  };
1158
1136
  const responsesTools = [];
1159
1137
  for (const tool of tools) {
1160
- if (tool.type === "provider-defined" || tool.name === DATABRICKS_TOOL_CALL_ID) continue;
1138
+ if (tool.type === "provider") continue;
1161
1139
  responsesTools.push({
1162
1140
  type: "function",
1163
1141
  name: tool.name,
@@ -1169,14 +1147,13 @@ function prepareResponsesTools({ tools, toolChoice }) {
1169
1147
  tools: void 0,
1170
1148
  toolChoice: void 0
1171
1149
  };
1172
- const convertedToolChoice = convertResponsesToolChoice(toolChoice);
1173
1150
  return {
1174
1151
  tools: responsesTools,
1175
- toolChoice: convertedToolChoice
1152
+ toolChoice: convertResponsesToolChoice(toolChoice)
1176
1153
  };
1177
1154
  }
1178
1155
  function convertResponsesToolChoice(toolChoice) {
1179
- if (!toolChoice) return void 0;
1156
+ if (!toolChoice) return;
1180
1157
  switch (toolChoice.type) {
1181
1158
  case "auto": return "auto";
1182
1159
  case "none": return "none";
@@ -1185,23 +1162,103 @@ function convertResponsesToolChoice(toolChoice) {
1185
1162
  type: "function",
1186
1163
  name: toolChoice.toolName
1187
1164
  };
1188
- default: return void 0;
1165
+ default: return;
1166
+ }
1167
+ }
1168
+
1169
+ //#endregion
1170
+ //#region src/responses-agent-language-model/call-options-to-responses-args.ts
1171
+ /**
1172
+ * Converts AI SDK LanguageModelV3CallOptions to Databricks Responses API body parameters.
1173
+ *
1174
+ * Inspired by the getArgs method in:
1175
+ * https://github.com/vercel/ai/blob/main/packages/openai/src/responses/openai-responses-language-model.ts#L118
1176
+ *
1177
+ * Complies with the API described in:
1178
+ * https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/api-reference#responses-api-request
1179
+ */
1180
+ function callOptionsToResponsesArgs(options) {
1181
+ const warnings = [];
1182
+ const databricksOptions = options.providerOptions?.databricks;
1183
+ if (options.topK != null) warnings.push({
1184
+ type: "unsupported",
1185
+ feature: "topK",
1186
+ details: "topK is not supported by the Databricks Responses API"
1187
+ });
1188
+ if (options.presencePenalty != null) warnings.push({
1189
+ type: "unsupported",
1190
+ feature: "presencePenalty",
1191
+ details: "presencePenalty is not supported by the Databricks Responses API"
1192
+ });
1193
+ if (options.frequencyPenalty != null) warnings.push({
1194
+ type: "unsupported",
1195
+ feature: "frequencyPenalty",
1196
+ details: "frequencyPenalty is not supported by the Databricks Responses API"
1197
+ });
1198
+ if (options.seed != null) warnings.push({
1199
+ type: "unsupported",
1200
+ feature: "seed",
1201
+ details: "seed is not supported by the Databricks Responses API"
1202
+ });
1203
+ if (options.stopSequences != null && options.stopSequences.length > 0) warnings.push({
1204
+ type: "unsupported",
1205
+ feature: "stopSequences",
1206
+ details: "stopSequences is not supported by the Databricks Responses API"
1207
+ });
1208
+ const args = {};
1209
+ if (options.maxOutputTokens != null) args.max_output_tokens = options.maxOutputTokens;
1210
+ if (options.temperature != null) args.temperature = options.temperature;
1211
+ if (options.topP != null) args.top_p = options.topP;
1212
+ if (options.responseFormat != null) switch (options.responseFormat.type) {
1213
+ case "text":
1214
+ args.text = { format: { type: "text" } };
1215
+ break;
1216
+ case "json":
1217
+ if (options.responseFormat.schema != null) args.text = { format: {
1218
+ type: "json_schema",
1219
+ json_schema: {
1220
+ name: options.responseFormat.name ?? "response",
1221
+ description: options.responseFormat.description,
1222
+ schema: options.responseFormat.schema,
1223
+ strict: true
1224
+ }
1225
+ } };
1226
+ else args.text = { format: { type: "json_object" } };
1227
+ break;
1189
1228
  }
1229
+ if (databricksOptions?.parallelToolCalls != null) args.parallel_tool_calls = databricksOptions.parallelToolCalls;
1230
+ if (databricksOptions?.metadata != null) args.metadata = databricksOptions.metadata;
1231
+ if (databricksOptions?.reasoning != null) args.reasoning = databricksOptions.reasoning;
1232
+ return {
1233
+ args,
1234
+ warnings
1235
+ };
1190
1236
  }
1191
1237
 
1192
1238
  //#endregion
1193
1239
  //#region src/responses-agent-language-model/responses-agent-language-model.ts
1194
1240
  function mapResponsesFinishReason({ finishReason, hasToolCalls }) {
1241
+ let unified;
1195
1242
  switch (finishReason) {
1196
1243
  case void 0:
1197
- case null: return hasToolCalls ? "tool-calls" : "stop";
1198
- case "max_output_tokens": return "length";
1199
- case "content_filter": return "content-filter";
1200
- default: return hasToolCalls ? "tool-calls" : "other";
1244
+ case null:
1245
+ unified = hasToolCalls ? "tool-calls" : "stop";
1246
+ break;
1247
+ case "max_output_tokens":
1248
+ unified = "length";
1249
+ break;
1250
+ case "content_filter":
1251
+ unified = "content-filter";
1252
+ break;
1253
+ default: unified = hasToolCalls ? "tool-calls" : "other";
1201
1254
  }
1255
+ return {
1256
+ raw: finishReason ?? void 0,
1257
+ unified
1258
+ };
1202
1259
  }
1203
1260
  var DatabricksResponsesAgentLanguageModel = class {
1204
- specificationVersion = "v2";
1261
+ specificationVersion = "v3";
1205
1262
  modelId;
1206
1263
  config;
1207
1264
  constructor(modelId, config) {
@@ -1213,16 +1270,16 @@ var DatabricksResponsesAgentLanguageModel = class {
1213
1270
  }
1214
1271
  supportedUrls = {};
1215
1272
  async doGenerate(options) {
1216
- const networkArgs = await this.getArgs({
1273
+ const { warnings, ...networkArgs } = await this.getArgs({
1217
1274
  config: this.config,
1218
1275
  options,
1219
1276
  stream: false,
1220
1277
  modelId: this.modelId
1221
1278
  });
1222
- const { value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
1279
+ const { value: response } = await (0, _ai_sdk_provider_utils.postJsonToApi)({
1223
1280
  ...networkArgs,
1224
- successfulResponseHandler: (0, __ai_sdk_provider_utils.createJsonResponseHandler)(responsesAgentResponseSchema),
1225
- failedResponseHandler: (0, __ai_sdk_provider_utils.createJsonErrorResponseHandler)({
1281
+ successfulResponseHandler: (0, _ai_sdk_provider_utils.createJsonResponseHandler)(responsesAgentResponseSchema),
1282
+ failedResponseHandler: (0, _ai_sdk_provider_utils.createJsonErrorResponseHandler)({
1226
1283
  errorSchema: zod_v4.z.any(),
1227
1284
  errorToMessage: (error) => JSON.stringify(error),
1228
1285
  isRetryable: () => false
@@ -1237,43 +1294,64 @@ var DatabricksResponsesAgentLanguageModel = class {
1237
1294
  hasToolCalls
1238
1295
  }),
1239
1296
  usage: {
1240
- inputTokens: response.usage?.input_tokens ?? 0,
1241
- outputTokens: response.usage?.output_tokens ?? 0,
1242
- totalTokens: response.usage?.total_tokens ?? 0
1297
+ inputTokens: {
1298
+ total: response.usage?.input_tokens ?? 0,
1299
+ noCache: 0,
1300
+ cacheRead: 0,
1301
+ cacheWrite: 0
1302
+ },
1303
+ outputTokens: {
1304
+ total: response.usage?.output_tokens ?? 0,
1305
+ text: 0,
1306
+ reasoning: 0
1307
+ }
1243
1308
  },
1244
- warnings: []
1309
+ warnings
1245
1310
  };
1246
1311
  }
1247
1312
  async doStream(options) {
1248
- const networkArgs = await this.getArgs({
1313
+ const { warnings, ...networkArgs } = await this.getArgs({
1249
1314
  config: this.config,
1250
1315
  options,
1251
1316
  stream: true,
1252
1317
  modelId: this.modelId
1253
1318
  });
1254
- const { responseHeaders, value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
1319
+ const { responseHeaders, value: response } = await (0, _ai_sdk_provider_utils.postJsonToApi)({
1255
1320
  ...networkArgs,
1256
- failedResponseHandler: (0, __ai_sdk_provider_utils.createJsonErrorResponseHandler)({
1321
+ failedResponseHandler: (0, _ai_sdk_provider_utils.createJsonErrorResponseHandler)({
1257
1322
  errorSchema: zod_v4.z.any(),
1258
1323
  errorToMessage: (error) => JSON.stringify(error),
1259
1324
  isRetryable: () => false
1260
1325
  }),
1261
- successfulResponseHandler: (0, __ai_sdk_provider_utils.createEventSourceResponseHandler)(looseResponseAgentChunkSchema),
1326
+ successfulResponseHandler: (0, _ai_sdk_provider_utils.createEventSourceResponseHandler)(looseResponseAgentChunkSchema),
1262
1327
  abortSignal: options.abortSignal
1263
1328
  });
1264
- let finishReason = "unknown";
1329
+ let finishReason = {
1330
+ raw: void 0,
1331
+ unified: "stop"
1332
+ };
1265
1333
  const usage = {
1266
- inputTokens: 0,
1267
- outputTokens: 0,
1268
- totalTokens: 0
1334
+ inputTokens: {
1335
+ total: 0,
1336
+ noCache: 0,
1337
+ cacheRead: 0,
1338
+ cacheWrite: 0
1339
+ },
1340
+ outputTokens: {
1341
+ total: 0,
1342
+ text: 0,
1343
+ reasoning: 0
1344
+ }
1269
1345
  };
1270
1346
  const allParts = [];
1347
+ const useRemoteToolCalling = this.config.useRemoteToolCalling ?? false;
1348
+ const toolNamesByCallId = /* @__PURE__ */ new Map();
1271
1349
  return {
1272
1350
  stream: response.pipeThrough(new TransformStream({
1273
1351
  start(controller) {
1274
1352
  controller.enqueue({
1275
1353
  type: "stream-start",
1276
- warnings: []
1354
+ warnings
1277
1355
  });
1278
1356
  },
1279
1357
  transform(chunk, controller) {
@@ -1282,7 +1360,10 @@ var DatabricksResponsesAgentLanguageModel = class {
1282
1360
  rawValue: chunk.rawValue
1283
1361
  });
1284
1362
  if (!chunk.success) {
1285
- finishReason = "error";
1363
+ finishReason = {
1364
+ raw: void 0,
1365
+ unified: "error"
1366
+ };
1286
1367
  controller.enqueue({
1287
1368
  type: "error",
1288
1369
  error: chunk.error
@@ -1295,12 +1376,15 @@ var DatabricksResponsesAgentLanguageModel = class {
1295
1376
  finishReason: chunk.value.response.incomplete_details?.reason,
1296
1377
  hasToolCalls
1297
1378
  });
1298
- usage.inputTokens = chunk.value.response.usage.input_tokens;
1299
- usage.outputTokens = chunk.value.response.usage.output_tokens;
1300
- usage.totalTokens = chunk.value.response.usage.total_tokens;
1379
+ usage.inputTokens.total = chunk.value.response.usage.input_tokens;
1380
+ usage.outputTokens.total = chunk.value.response.usage.output_tokens;
1301
1381
  return;
1302
1382
  }
1303
- const parts = convertResponsesAgentChunkToMessagePart(chunk.value);
1383
+ if (chunk.value.type === "response.output_item.done" && chunk.value.item.type === "function_call") toolNamesByCallId.set(chunk.value.item.call_id, chunk.value.item.name);
1384
+ const parts = convertResponsesAgentChunkToMessagePart(chunk.value, {
1385
+ useRemoteToolCalling,
1386
+ toolNamesByCallId
1387
+ });
1304
1388
  allParts.push(...parts);
1305
1389
  /**
1306
1390
  * Check if the last chunk was a tool result without a tool call
@@ -1315,19 +1399,33 @@ var DatabricksResponsesAgentLanguageModel = class {
1315
1399
  if (!matchingToolCallInParts && !matchingToolCallInStream) {
1316
1400
  const toolCallFromPreviousMessages = options.prompt.flatMap((message) => {
1317
1401
  if (typeof message.content === "string") return [];
1318
- return message.content;
1319
- }).find((p) => p.type === "tool-call" && p.toolCallId === part.toolCallId);
1402
+ return message.content.filter((p) => p.type === "tool-call");
1403
+ }).find((p) => p.toolCallId === part.toolCallId);
1320
1404
  if (!toolCallFromPreviousMessages) throw new Error("No matching tool call found in previous message");
1321
- if (toolCallFromPreviousMessages.type === "tool-call") controller.enqueue({
1322
- ...toolCallFromPreviousMessages,
1405
+ controller.enqueue({
1406
+ type: "tool-call",
1407
+ toolCallId: toolCallFromPreviousMessages.toolCallId,
1408
+ toolName: toolCallFromPreviousMessages.toolName,
1323
1409
  input: JSON.stringify(toolCallFromPreviousMessages.input)
1324
1410
  });
1325
1411
  }
1326
1412
  }
1327
1413
  if (shouldDedupeOutputItemDone(parts, allParts.slice(0, -parts.length))) return;
1328
- for (const part$1 of parts) controller.enqueue(part$1);
1414
+ for (const part of parts) controller.enqueue(part);
1329
1415
  },
1330
1416
  flush(controller) {
1417
+ if (!useRemoteToolCalling) {
1418
+ const toolCalls = allParts.filter((p) => p.type === "tool-call");
1419
+ const toolResults = allParts.filter((p) => p.type === "tool-result");
1420
+ for (const toolCall of toolCalls) {
1421
+ if (toolCall.providerMetadata?.databricks?.type === MCP_APPROVAL_REQUEST_TYPE) continue;
1422
+ if (!toolResults.some((r) => r.toolCallId === toolCall.toolCallId)) controller.enqueue({
1423
+ ...toolCall,
1424
+ providerExecuted: true,
1425
+ dynamic: true
1426
+ });
1427
+ }
1428
+ }
1331
1429
  controller.enqueue({
1332
1430
  type: "finish",
1333
1431
  finishReason,
@@ -1348,16 +1446,19 @@ var DatabricksResponsesAgentLanguageModel = class {
1348
1446
  tools: options.tools,
1349
1447
  toolChoice: options.toolChoice
1350
1448
  });
1449
+ const { args: callArgs, warnings } = callOptionsToResponsesArgs(options);
1351
1450
  return {
1352
1451
  url: config.url({ path: "/responses" }),
1353
- headers: (0, __ai_sdk_provider_utils.combineHeaders)(config.headers(), options.headers),
1452
+ headers: (0, _ai_sdk_provider_utils.combineHeaders)(config.headers(), options.headers),
1354
1453
  body: {
1355
1454
  model: modelId,
1356
1455
  input,
1357
1456
  stream,
1358
1457
  ...tools ? { tools } : {},
1359
- ...toolChoice && tools ? { tool_choice: toolChoice } : {}
1458
+ ...toolChoice && tools ? { tool_choice: toolChoice } : {},
1459
+ ...callArgs
1360
1460
  },
1461
+ warnings,
1361
1462
  fetch: config.fetch
1362
1463
  };
1363
1464
  }
@@ -1377,8 +1478,7 @@ function shouldDedupeOutputItemDone(incomingParts, previousParts) {
1377
1478
  * corresponds to a specific message and we should only compare against text streamed for that message.
1378
1479
  */
1379
1480
  const lastDoneIndex = previousParts.findLastIndex((part) => part.type === "text-delta" && part.providerMetadata?.databricks?.itemType === "response.output_item.done");
1380
- const partsAfterLastDone = previousParts.slice(lastDoneIndex + 1);
1381
- const { texts: reconstructuredTexts, current } = partsAfterLastDone.reduce((acc, part) => {
1481
+ const { texts: reconstructuredTexts, current } = previousParts.slice(lastDoneIndex + 1).reduce((acc, part) => {
1382
1482
  if (part.type === "text-delta") return {
1383
1483
  ...acc,
1384
1484
  current: acc.current + part.delta
@@ -1392,9 +1492,9 @@ function shouldDedupeOutputItemDone(incomingParts, previousParts) {
1392
1492
  texts: [],
1393
1493
  current: ""
1394
1494
  });
1395
- reconstructuredTexts.push(current);
1495
+ if (current.length > 0) reconstructuredTexts.push(current);
1396
1496
  if (reconstructuredTexts.length === 0) return false;
1397
- const allTextsFoundInOrder = reconstructuredTexts.reduce((acc, text) => {
1497
+ return reconstructuredTexts.reduce((acc, text) => {
1398
1498
  if (!acc.found) return acc;
1399
1499
  const index = doneTextDelta.delta.indexOf(text, acc.lastIndex);
1400
1500
  if (index === -1) return {
@@ -1408,8 +1508,7 @@ function shouldDedupeOutputItemDone(incomingParts, previousParts) {
1408
1508
  }, {
1409
1509
  found: true,
1410
1510
  lastIndex: 0
1411
- });
1412
- return allTextsFoundInOrder.found;
1511
+ }).found;
1413
1512
  }
1414
1513
 
1415
1514
  //#endregion
@@ -1543,12 +1642,12 @@ const convertFmapiChunkToMessagePart = (chunk, toolCallIdsByIndex) => {
1543
1642
  } else if (Array.isArray(choice.delta.content)) parts.push(...mapContentItemsToStreamParts(choice.delta.content, chunk.id));
1544
1643
  return parts;
1545
1644
  };
1546
- const convertFmapiResponseToMessagePart = (response) => {
1645
+ const convertFmapiResponseToMessagePart = (response, options = { useRemoteToolCalling: false }) => {
1547
1646
  const parts = [];
1548
1647
  if (response.choices.length === 0) return parts;
1549
1648
  const choice = response.choices[0];
1550
1649
  if (choice.message.tool_calls && choice.message.tool_calls.length > 0) {
1551
- for (const toolCall of choice.message.tool_calls) parts.push(convertToolCallToContent(toolCall));
1650
+ for (const toolCall of choice.message.tool_calls) parts.push(convertToolCallToContent(toolCall, options));
1552
1651
  if (typeof choice.message.content === "string" && choice.message.content) parts.push({
1553
1652
  type: "text",
1554
1653
  text: choice.message.content
@@ -1562,13 +1661,16 @@ const convertFmapiResponseToMessagePart = (response) => {
1562
1661
  else parts.push(...mapContentItemsToProviderContent(choice.message.content ?? []));
1563
1662
  return parts;
1564
1663
  };
1565
- const convertToolCallToContent = (toolCall) => {
1664
+ const convertToolCallToContent = (toolCall, options) => {
1566
1665
  return {
1567
1666
  type: "tool-call",
1568
1667
  toolCallId: toolCall.id,
1569
- toolName: DATABRICKS_TOOL_CALL_ID,
1668
+ toolName: toolCall.function.name,
1570
1669
  input: toolCall.function.arguments,
1571
- providerMetadata: { databricks: { toolName: toolCall.function.name } }
1670
+ ...options.useRemoteToolCalling && {
1671
+ dynamic: true,
1672
+ providerExecuted: true
1673
+ }
1572
1674
  };
1573
1675
  };
1574
1676
  const mapContentItemsToStreamParts = (items, id) => {
@@ -1582,14 +1684,13 @@ const mapContentItemsToStreamParts = (items, id) => {
1582
1684
  });
1583
1685
  break;
1584
1686
  case "image": break;
1585
- case "reasoning": {
1687
+ case "reasoning":
1586
1688
  for (const summary of item.summary.filter((s) => s.type === "summary_text")) parts.push({
1587
1689
  type: "reasoning-delta",
1588
1690
  id,
1589
1691
  delta: summary.text
1590
1692
  });
1591
1693
  break;
1592
- }
1593
1694
  }
1594
1695
  return parts;
1595
1696
  };
@@ -1603,13 +1704,12 @@ const mapContentItemsToProviderContent = (items) => {
1603
1704
  });
1604
1705
  break;
1605
1706
  case "image": break;
1606
- case "reasoning": {
1707
+ case "reasoning":
1607
1708
  for (const summary of item.summary.filter((s) => s.type === "summary_text")) parts.push({
1608
1709
  type: "reasoning",
1609
1710
  text: summary.text
1610
1711
  });
1611
1712
  break;
1612
- }
1613
1713
  }
1614
1714
  return parts;
1615
1715
  };
@@ -1745,31 +1845,108 @@ const convertToolResultOutputToContentValue = (output) => {
1745
1845
  };
1746
1846
  const ProviderOptionsSchema = zod_v4.z.object({ toolName: zod_v4.z.string().nullish() });
1747
1847
  const getToolNameFromPart = async (part) => {
1748
- const providerOptions = await (0, __ai_sdk_provider_utils.parseProviderOptions)({
1848
+ return (await (0, _ai_sdk_provider_utils.parseProviderOptions)({
1749
1849
  provider: "databricks",
1750
1850
  providerOptions: part.providerOptions,
1751
1851
  schema: ProviderOptionsSchema
1752
- });
1753
- return providerOptions?.toolName ?? part.toolName;
1852
+ }))?.toolName ?? part.toolName;
1754
1853
  };
1755
1854
 
1756
1855
  //#endregion
1757
1856
  //#region src/fmapi-language-model/fmapi-finish-reason.ts
1758
1857
  function mapFmapiFinishReason(finishReason) {
1759
1858
  switch (finishReason) {
1760
- case "stop": return "stop";
1761
- case "length": return "length";
1762
- case "content_filter": return "content-filter";
1859
+ case "stop": return {
1860
+ raw: finishReason,
1861
+ unified: "stop"
1862
+ };
1863
+ case "length": return {
1864
+ raw: finishReason,
1865
+ unified: "length"
1866
+ };
1867
+ case "content_filter": return {
1868
+ raw: finishReason,
1869
+ unified: "content-filter"
1870
+ };
1763
1871
  case "function_call":
1764
- case "tool_calls": return "tool-calls";
1765
- default: return "other";
1872
+ case "tool_calls": return {
1873
+ raw: finishReason,
1874
+ unified: "tool-calls"
1875
+ };
1876
+ default: return {
1877
+ raw: finishReason ?? void 0,
1878
+ unified: "other"
1879
+ };
1880
+ }
1881
+ }
1882
+
1883
+ //#endregion
1884
+ //#region src/fmapi-language-model/call-options-to-fmapi-args.ts
1885
+ /**
1886
+ * Converts AI SDK LanguageModelV3CallOptions to Databricks FMAPI body parameters.
1887
+ *
1888
+ * Inspired by the getArgs method in:
1889
+ * https://github.com/vercel/ai/blob/main/packages/openai/src/chat/openai-chat-language-model.ts#L71
1890
+ *
1891
+ * Complies with the API described in:
1892
+ * https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/api-reference#chat-request
1893
+ */
1894
+ function callOptionsToFmapiArgs(options) {
1895
+ const warnings = [];
1896
+ const databricksOptions = options.providerOptions?.databricks;
1897
+ if (options.presencePenalty != null) warnings.push({
1898
+ type: "unsupported",
1899
+ feature: "presencePenalty",
1900
+ details: "presencePenalty is not supported by the Databricks FMAPI"
1901
+ });
1902
+ if (options.frequencyPenalty != null) warnings.push({
1903
+ type: "unsupported",
1904
+ feature: "frequencyPenalty",
1905
+ details: "frequencyPenalty is not supported by the Databricks FMAPI"
1906
+ });
1907
+ if (options.seed != null) warnings.push({
1908
+ type: "unsupported",
1909
+ feature: "seed",
1910
+ details: "seed is not supported by the Databricks FMAPI"
1911
+ });
1912
+ const args = {};
1913
+ if (options.maxOutputTokens != null) args.max_tokens = options.maxOutputTokens;
1914
+ if (options.temperature != null) args.temperature = options.temperature;
1915
+ if (options.topP != null) args.top_p = options.topP;
1916
+ if (options.topK != null) args.top_k = options.topK;
1917
+ if (options.stopSequences != null && options.stopSequences.length > 0) args.stop = options.stopSequences;
1918
+ if (options.responseFormat != null) switch (options.responseFormat.type) {
1919
+ case "text":
1920
+ args.response_format = { type: "text" };
1921
+ break;
1922
+ case "json":
1923
+ if (options.responseFormat.schema != null) args.response_format = {
1924
+ type: "json_schema",
1925
+ json_schema: {
1926
+ name: options.responseFormat.name ?? "response",
1927
+ description: options.responseFormat.description,
1928
+ schema: options.responseFormat.schema,
1929
+ strict: true
1930
+ }
1931
+ };
1932
+ else args.response_format = { type: "json_object" };
1933
+ break;
1766
1934
  }
1935
+ if (databricksOptions?.topK != null) args.top_k = databricksOptions.topK;
1936
+ if (databricksOptions?.n != null) args.n = databricksOptions.n;
1937
+ if (databricksOptions?.logprobs != null) args.logprobs = databricksOptions.logprobs;
1938
+ if (databricksOptions?.topLogprobs != null) args.top_logprobs = databricksOptions.topLogprobs;
1939
+ if (databricksOptions?.reasoningEffort != null) args.reasoning_effort = databricksOptions.reasoningEffort;
1940
+ return {
1941
+ args,
1942
+ warnings
1943
+ };
1767
1944
  }
1768
1945
 
1769
1946
  //#endregion
1770
1947
  //#region src/fmapi-language-model/fmapi-language-model.ts
1771
1948
  var DatabricksFmapiLanguageModel = class {
1772
- specificationVersion = "v2";
1949
+ specificationVersion = "v3";
1773
1950
  modelId;
1774
1951
  config;
1775
1952
  constructor(modelId, config) {
@@ -1781,16 +1958,16 @@ var DatabricksFmapiLanguageModel = class {
1781
1958
  }
1782
1959
  supportedUrls = {};
1783
1960
  async doGenerate(options) {
1784
- const networkArgs = await this.getArgs({
1961
+ const { warnings, ...networkArgs } = await this.getArgs({
1785
1962
  config: this.config,
1786
1963
  options,
1787
1964
  stream: false,
1788
1965
  modelId: this.modelId
1789
1966
  });
1790
- const { value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
1967
+ const { value: response } = await (0, _ai_sdk_provider_utils.postJsonToApi)({
1791
1968
  ...networkArgs,
1792
- successfulResponseHandler: (0, __ai_sdk_provider_utils.createJsonResponseHandler)(fmapiResponseSchema),
1793
- failedResponseHandler: (0, __ai_sdk_provider_utils.createJsonErrorResponseHandler)({
1969
+ successfulResponseHandler: (0, _ai_sdk_provider_utils.createJsonResponseHandler)(fmapiResponseSchema),
1970
+ failedResponseHandler: (0, _ai_sdk_provider_utils.createJsonErrorResponseHandler)({
1794
1971
  errorSchema: zod_v4.z.any(),
1795
1972
  errorToMessage: (error) => JSON.stringify(error),
1796
1973
  isRetryable: () => false
@@ -1799,48 +1976,68 @@ var DatabricksFmapiLanguageModel = class {
1799
1976
  const choice = response.choices[0];
1800
1977
  const finishReason = mapFmapiFinishReason(choice?.finish_reason);
1801
1978
  return {
1802
- content: convertFmapiResponseToMessagePart(response),
1979
+ content: convertFmapiResponseToMessagePart(response, { useRemoteToolCalling: this.config.useRemoteToolCalling ?? false }),
1803
1980
  finishReason,
1804
1981
  usage: {
1805
- inputTokens: response.usage?.prompt_tokens ?? 0,
1806
- outputTokens: response.usage?.completion_tokens ?? 0,
1807
- totalTokens: response.usage?.total_tokens ?? 0
1982
+ inputTokens: {
1983
+ total: response.usage?.prompt_tokens ?? 0,
1984
+ noCache: 0,
1985
+ cacheRead: 0,
1986
+ cacheWrite: 0
1987
+ },
1988
+ outputTokens: {
1989
+ total: response.usage?.completion_tokens ?? 0,
1990
+ text: 0,
1991
+ reasoning: 0
1992
+ }
1808
1993
  },
1809
- warnings: []
1994
+ warnings
1810
1995
  };
1811
1996
  }
1812
1997
  async doStream(options) {
1813
- const networkArgs = await this.getArgs({
1998
+ const { warnings, ...networkArgs } = await this.getArgs({
1814
1999
  config: this.config,
1815
2000
  options,
1816
2001
  stream: true,
1817
2002
  modelId: this.modelId
1818
2003
  });
1819
- const { responseHeaders, value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
2004
+ const { responseHeaders, value: response } = await (0, _ai_sdk_provider_utils.postJsonToApi)({
1820
2005
  ...networkArgs,
1821
- failedResponseHandler: (0, __ai_sdk_provider_utils.createJsonErrorResponseHandler)({
2006
+ failedResponseHandler: (0, _ai_sdk_provider_utils.createJsonErrorResponseHandler)({
1822
2007
  errorSchema: zod_v4.z.any(),
1823
2008
  errorToMessage: (error) => JSON.stringify(error),
1824
2009
  isRetryable: () => false
1825
2010
  }),
1826
- successfulResponseHandler: (0, __ai_sdk_provider_utils.createEventSourceResponseHandler)(fmapiChunkSchema),
2011
+ successfulResponseHandler: (0, _ai_sdk_provider_utils.createEventSourceResponseHandler)(fmapiChunkSchema),
1827
2012
  abortSignal: options.abortSignal
1828
2013
  });
1829
- let finishReason = "unknown";
2014
+ let finishReason = {
2015
+ raw: void 0,
2016
+ unified: "other"
2017
+ };
1830
2018
  let usage = {
1831
- inputTokens: 0,
1832
- outputTokens: 0,
1833
- totalTokens: 0
2019
+ inputTokens: {
2020
+ total: 0,
2021
+ noCache: 0,
2022
+ cacheRead: 0,
2023
+ cacheWrite: 0
2024
+ },
2025
+ outputTokens: {
2026
+ total: 0,
2027
+ text: 0,
2028
+ reasoning: 0
2029
+ }
1834
2030
  };
1835
- const toolCallIdsByIndex = new Map();
1836
- const toolCallNamesById = new Map();
1837
- const toolCallInputsById = new Map();
2031
+ const toolCallIdsByIndex = /* @__PURE__ */ new Map();
2032
+ const toolCallNamesById = /* @__PURE__ */ new Map();
2033
+ const toolCallInputsById = /* @__PURE__ */ new Map();
2034
+ const useRemoteToolCalling = this.config.useRemoteToolCalling ?? false;
1838
2035
  return {
1839
2036
  stream: response.pipeThrough(new TransformStream({
1840
2037
  start(controller) {
1841
2038
  controller.enqueue({
1842
2039
  type: "stream-start",
1843
- warnings: []
2040
+ warnings
1844
2041
  });
1845
2042
  },
1846
2043
  transform(chunk, controller) {
@@ -1849,7 +2046,10 @@ var DatabricksFmapiLanguageModel = class {
1849
2046
  rawValue: chunk.rawValue
1850
2047
  });
1851
2048
  if (!chunk.success) {
1852
- finishReason = "error";
2049
+ finishReason = {
2050
+ raw: void 0,
2051
+ unified: "error"
2052
+ };
1853
2053
  controller.enqueue({
1854
2054
  type: "error",
1855
2055
  error: chunk.error
@@ -1859,9 +2059,17 @@ var DatabricksFmapiLanguageModel = class {
1859
2059
  const choice = chunk.value.choices[0];
1860
2060
  finishReason = mapFmapiFinishReason(choice?.finish_reason);
1861
2061
  if (chunk.value.usage) usage = {
1862
- inputTokens: chunk.value.usage.prompt_tokens ?? 0,
1863
- outputTokens: chunk.value.usage.completion_tokens ?? 0,
1864
- totalTokens: chunk.value.usage.total_tokens ?? 0
2062
+ inputTokens: {
2063
+ total: chunk.value.usage.prompt_tokens ?? 0,
2064
+ noCache: 0,
2065
+ cacheRead: 0,
2066
+ cacheWrite: 0
2067
+ },
2068
+ outputTokens: {
2069
+ total: chunk.value.usage.completion_tokens ?? 0,
2070
+ text: 0,
2071
+ reasoning: 0
2072
+ }
1865
2073
  };
1866
2074
  const parts = convertFmapiChunkToMessagePart(chunk.value, toolCallIdsByIndex);
1867
2075
  for (const part of parts) {
@@ -1886,9 +2094,12 @@ var DatabricksFmapiLanguageModel = class {
1886
2094
  controller.enqueue({
1887
2095
  type: "tool-call",
1888
2096
  toolCallId,
1889
- toolName: DATABRICKS_TOOL_CALL_ID,
2097
+ toolName,
1890
2098
  input: inputText,
1891
- providerMetadata: { databricks: { toolName } }
2099
+ ...useRemoteToolCalling && {
2100
+ dynamic: true,
2101
+ providerExecuted: true
2102
+ }
1892
2103
  });
1893
2104
  }
1894
2105
  }
@@ -1907,19 +2118,19 @@ var DatabricksFmapiLanguageModel = class {
1907
2118
  const tools = options.tools?.map((tool) => convertToolToOpenAIFormat(tool)).filter((tool) => tool !== void 0);
1908
2119
  const toolChoice = options.toolChoice ? convertToolChoiceToOpenAIFormat(options.toolChoice) : void 0;
1909
2120
  const { messages } = await convertPromptToFmapiMessages(options.prompt);
2121
+ const { args: callArgs, warnings } = callOptionsToFmapiArgs(options);
1910
2122
  return {
1911
2123
  url: config.url({ path: "/chat/completions" }),
1912
- headers: (0, __ai_sdk_provider_utils.combineHeaders)(config.headers(), options.headers),
2124
+ headers: (0, _ai_sdk_provider_utils.combineHeaders)(config.headers(), options.headers),
1913
2125
  body: {
1914
2126
  messages,
1915
2127
  stream,
1916
2128
  model: modelId,
1917
2129
  ...tools && tools.length > 0 ? { tools } : {},
1918
2130
  ...toolChoice && tools && tools.length > 0 ? { tool_choice: toolChoice } : {},
1919
- ...options.temperature !== void 0 ? { temperature: options.temperature } : {},
1920
- ...options.maxOutputTokens !== void 0 ? { max_tokens: options.maxOutputTokens } : {},
1921
- ...options.stopSequences && options.stopSequences.length > 0 ? { stop: options.stopSequences } : {}
2131
+ ...callArgs
1922
2132
  },
2133
+ warnings,
1923
2134
  fetch: config.fetch
1924
2135
  };
1925
2136
  }
@@ -1928,7 +2139,7 @@ var DatabricksFmapiLanguageModel = class {
1928
2139
  * Convert AI SDK tool to OpenAI format
1929
2140
  */
1930
2141
  function convertToolToOpenAIFormat(tool) {
1931
- if (tool.type === "provider-defined" || tool.name === DATABRICKS_TOOL_CALL_ID) return void 0;
2142
+ if (tool.type === "provider") return;
1932
2143
  return {
1933
2144
  type: "function",
1934
2145
  function: {
@@ -1955,8 +2166,8 @@ function convertToolChoiceToOpenAIFormat(toolChoice) {
1955
2166
  //#endregion
1956
2167
  //#region src/databricks-provider.ts
1957
2168
  const createDatabricksProvider = (settings) => {
1958
- const baseUrl = (0, __ai_sdk_provider_utils.withoutTrailingSlash)(settings.baseURL);
1959
- const getHeaders = () => (0, __ai_sdk_provider_utils.combineHeaders)(settings.headers);
2169
+ const baseUrl = (0, _ai_sdk_provider_utils.withoutTrailingSlash)(settings.baseURL);
2170
+ const getHeaders = () => (0, _ai_sdk_provider_utils.combineHeaders)(settings.headers);
1960
2171
  const fetch = settings.fetch;
1961
2172
  const provider = settings.provider ?? "databricks";
1962
2173
  const formatUrl = ({ path }) => settings.formatUrl?.({
@@ -1973,13 +2184,15 @@ const createDatabricksProvider = (settings) => {
1973
2184
  url: formatUrl,
1974
2185
  headers: getHeaders,
1975
2186
  fetch,
1976
- provider
2187
+ provider,
2188
+ useRemoteToolCalling: settings.useRemoteToolCalling
1977
2189
  });
1978
2190
  const createFmapi = (modelId) => new DatabricksFmapiLanguageModel(modelId, {
1979
2191
  url: formatUrl,
1980
2192
  headers: getHeaders,
1981
2193
  fetch,
1982
- provider
2194
+ provider,
2195
+ useRemoteToolCalling: settings.useRemoteToolCalling
1983
2196
  });
1984
2197
  const notImplemented = (name) => {
1985
2198
  return () => {
@@ -1987,28 +2200,28 @@ const createDatabricksProvider = (settings) => {
1987
2200
  };
1988
2201
  };
1989
2202
  return {
2203
+ specificationVersion: "v3",
1990
2204
  responses: createResponsesAgent,
1991
2205
  chatCompletions: createFmapi,
1992
2206
  chatAgent: createChatAgent,
1993
2207
  imageModel: notImplemented("ImageModel"),
1994
2208
  textEmbeddingModel: notImplemented("TextEmbeddingModel"),
2209
+ embeddingModel: notImplemented("EmbeddingModel"),
1995
2210
  languageModel: notImplemented("LanguageModel")
1996
2211
  };
1997
2212
  };
1998
2213
 
1999
2214
  //#endregion
2000
- exports.DATABRICKS_TOOL_CALL_ID = DATABRICKS_TOOL_CALL_ID
2001
- exports.DATABRICKS_TOOL_DEFINITION = DATABRICKS_TOOL_DEFINITION
2002
- exports.MCP_APPROVAL_REQUEST_TYPE = MCP_APPROVAL_REQUEST_TYPE
2003
- exports.MCP_APPROVAL_RESPONSE_TYPE = MCP_APPROVAL_RESPONSE_TYPE
2004
- exports.MCP_APPROVAL_STATUS_KEY = MCP_APPROVAL_STATUS_KEY
2005
- exports.createApprovalStatusOutput = createApprovalStatusOutput
2006
- exports.createDatabricksProvider = createDatabricksProvider
2007
- exports.extractApprovalStatus = extractApprovalStatus
2008
- exports.extractApprovalStatusFromToolResult = extractApprovalStatusFromToolResult
2009
- exports.extractDatabricksMetadata = extractDatabricksMetadata
2010
- exports.getMcpApprovalState = getMcpApprovalState
2011
- exports.isApprovalStatusOutput = isApprovalStatusOutput
2012
- exports.isMcpApprovalRequest = isMcpApprovalRequest
2013
- exports.isMcpApprovalResponse = isMcpApprovalResponse
2215
+ exports.MCP_APPROVAL_REQUEST_TYPE = MCP_APPROVAL_REQUEST_TYPE;
2216
+ exports.MCP_APPROVAL_RESPONSE_TYPE = MCP_APPROVAL_RESPONSE_TYPE;
2217
+ exports.MCP_APPROVAL_STATUS_KEY = MCP_APPROVAL_STATUS_KEY;
2218
+ exports.createApprovalStatusOutput = createApprovalStatusOutput;
2219
+ exports.createDatabricksProvider = createDatabricksProvider;
2220
+ exports.extractApprovalStatus = extractApprovalStatus;
2221
+ exports.extractApprovalStatusFromToolResult = extractApprovalStatusFromToolResult;
2222
+ exports.extractDatabricksMetadata = extractDatabricksMetadata;
2223
+ exports.getMcpApprovalState = getMcpApprovalState;
2224
+ exports.isApprovalStatusOutput = isApprovalStatusOutput;
2225
+ exports.isMcpApprovalRequest = isMcpApprovalRequest;
2226
+ exports.isMcpApprovalResponse = isMcpApprovalResponse;
2014
2227
  //# sourceMappingURL=index.cjs.map