@databricks/ai-sdk-provider 0.2.1 → 0.2.3

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
@@ -545,7 +545,7 @@ const responsesAgentResponseSchema = zod_v4.z.object({
545
545
  }).nullish(),
546
546
  model: zod_v4.z.string().optional(),
547
547
  output: zod_v4.z.array(responsesAgentOutputItem),
548
- incomplete_details: zod_v4.z.object({ reason: zod_v4.z.enum(["max_output_tokens", "content_filter"]).optional() }).nullish(),
548
+ incomplete_details: zod_v4.z.object({ reason: zod_v4.z.string().nullish().optional() }).nullish(),
549
549
  usage: zod_v4.z.object({
550
550
  input_tokens: zod_v4.z.number(),
551
551
  output_tokens: zod_v4.z.number(),
@@ -615,7 +615,7 @@ const responsesCompletedSchema = zod_v4.z.object({
615
615
  "queued",
616
616
  "incomplete"
617
617
  ]).optional(),
618
- incomplete_details: zod_v4.z.object({ reason: zod_v4.z.enum(["max_output_tokens", "content_filter"]).optional() }).nullish(),
618
+ incomplete_details: zod_v4.z.object({ reason: zod_v4.z.string().nullish().optional() }).nullish(),
619
619
  usage: zod_v4.z.object({
620
620
  input_tokens: zod_v4.z.number(),
621
621
  output_tokens: zod_v4.z.number(),
@@ -1189,6 +1189,75 @@ function convertResponsesToolChoice(toolChoice) {
1189
1189
  }
1190
1190
  }
1191
1191
 
1192
+ //#endregion
1193
+ //#region src/responses-agent-language-model/call-options-to-responses-args.ts
1194
+ /**
1195
+ * Converts AI SDK LanguageModelV2CallOptions to Databricks Responses API body parameters.
1196
+ *
1197
+ * Inspired by the getArgs method in:
1198
+ * https://github.com/vercel/ai/blob/main/packages/openai/src/responses/openai-responses-language-model.ts#L118
1199
+ *
1200
+ * Complies with the API described in:
1201
+ * https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/api-reference#responses-api-request
1202
+ */
1203
+ function callOptionsToResponsesArgs(options) {
1204
+ const warnings = [];
1205
+ const databricksOptions = options.providerOptions?.databricks;
1206
+ if (options.topK != null) warnings.push({
1207
+ type: "unsupported-setting",
1208
+ setting: "topK",
1209
+ details: "topK is not supported by the Databricks Responses API"
1210
+ });
1211
+ if (options.presencePenalty != null) warnings.push({
1212
+ type: "unsupported-setting",
1213
+ setting: "presencePenalty",
1214
+ details: "presencePenalty is not supported by the Databricks Responses API"
1215
+ });
1216
+ if (options.frequencyPenalty != null) warnings.push({
1217
+ type: "unsupported-setting",
1218
+ setting: "frequencyPenalty",
1219
+ details: "frequencyPenalty is not supported by the Databricks Responses API"
1220
+ });
1221
+ if (options.seed != null) warnings.push({
1222
+ type: "unsupported-setting",
1223
+ setting: "seed",
1224
+ details: "seed is not supported by the Databricks Responses API"
1225
+ });
1226
+ if (options.stopSequences != null && options.stopSequences.length > 0) warnings.push({
1227
+ type: "unsupported-setting",
1228
+ setting: "stopSequences",
1229
+ details: "stopSequences is not supported by the Databricks Responses API"
1230
+ });
1231
+ const args = {};
1232
+ if (options.maxOutputTokens != null) args.max_output_tokens = options.maxOutputTokens;
1233
+ if (options.temperature != null) args.temperature = options.temperature;
1234
+ if (options.topP != null) args.top_p = options.topP;
1235
+ if (options.responseFormat != null) switch (options.responseFormat.type) {
1236
+ case "text":
1237
+ args.text = { format: { type: "text" } };
1238
+ break;
1239
+ case "json":
1240
+ if (options.responseFormat.schema != null) args.text = { format: {
1241
+ type: "json_schema",
1242
+ json_schema: {
1243
+ name: options.responseFormat.name ?? "response",
1244
+ description: options.responseFormat.description,
1245
+ schema: options.responseFormat.schema,
1246
+ strict: true
1247
+ }
1248
+ } };
1249
+ else args.text = { format: { type: "json_object" } };
1250
+ break;
1251
+ }
1252
+ if (databricksOptions?.parallelToolCalls != null) args.parallel_tool_calls = databricksOptions.parallelToolCalls;
1253
+ if (databricksOptions?.metadata != null) args.metadata = databricksOptions.metadata;
1254
+ if (databricksOptions?.reasoning != null) args.reasoning = databricksOptions.reasoning;
1255
+ return {
1256
+ args,
1257
+ warnings
1258
+ };
1259
+ }
1260
+
1192
1261
  //#endregion
1193
1262
  //#region src/responses-agent-language-model/responses-agent-language-model.ts
1194
1263
  function mapResponsesFinishReason({ finishReason, hasToolCalls }) {
@@ -1213,7 +1282,7 @@ var DatabricksResponsesAgentLanguageModel = class {
1213
1282
  }
1214
1283
  supportedUrls = {};
1215
1284
  async doGenerate(options) {
1216
- const networkArgs = await this.getArgs({
1285
+ const { warnings,...networkArgs } = await this.getArgs({
1217
1286
  config: this.config,
1218
1287
  options,
1219
1288
  stream: false,
@@ -1241,11 +1310,11 @@ var DatabricksResponsesAgentLanguageModel = class {
1241
1310
  outputTokens: response.usage?.output_tokens ?? 0,
1242
1311
  totalTokens: response.usage?.total_tokens ?? 0
1243
1312
  },
1244
- warnings: []
1313
+ warnings
1245
1314
  };
1246
1315
  }
1247
1316
  async doStream(options) {
1248
- const networkArgs = await this.getArgs({
1317
+ const { warnings,...networkArgs } = await this.getArgs({
1249
1318
  config: this.config,
1250
1319
  options,
1251
1320
  stream: true,
@@ -1273,7 +1342,7 @@ var DatabricksResponsesAgentLanguageModel = class {
1273
1342
  start(controller) {
1274
1343
  controller.enqueue({
1275
1344
  type: "stream-start",
1276
- warnings: []
1345
+ warnings
1277
1346
  });
1278
1347
  },
1279
1348
  transform(chunk, controller) {
@@ -1348,6 +1417,7 @@ var DatabricksResponsesAgentLanguageModel = class {
1348
1417
  tools: options.tools,
1349
1418
  toolChoice: options.toolChoice
1350
1419
  });
1420
+ const { args: callArgs, warnings } = callOptionsToResponsesArgs(options);
1351
1421
  return {
1352
1422
  url: config.url({ path: "/responses" }),
1353
1423
  headers: (0, __ai_sdk_provider_utils.combineHeaders)(config.headers(), options.headers),
@@ -1356,8 +1426,10 @@ var DatabricksResponsesAgentLanguageModel = class {
1356
1426
  input,
1357
1427
  stream,
1358
1428
  ...tools ? { tools } : {},
1359
- ...toolChoice && tools ? { tool_choice: toolChoice } : {}
1429
+ ...toolChoice && tools ? { tool_choice: toolChoice } : {},
1430
+ ...callArgs
1360
1431
  },
1432
+ warnings,
1361
1433
  fetch: config.fetch
1362
1434
  };
1363
1435
  }
@@ -1479,11 +1551,7 @@ const fmapiChunkSchema = zod_v4.z.object({
1479
1551
  ]).optional(),
1480
1552
  tool_calls: zod_v4.z.array(toolCallDeltaSchema).optional()
1481
1553
  }),
1482
- finish_reason: zod_v4.z.union([
1483
- zod_v4.z.literal("stop"),
1484
- zod_v4.z.literal("tool_calls"),
1485
- zod_v4.z.null()
1486
- ]).optional()
1554
+ finish_reason: zod_v4.z.union([zod_v4.z.string(), zod_v4.z.null()]).optional()
1487
1555
  }))
1488
1556
  });
1489
1557
  const fmapiResponseSchema = zod_v4.z.object({
@@ -1509,11 +1577,7 @@ const fmapiResponseSchema = zod_v4.z.object({
1509
1577
  ]).optional(),
1510
1578
  tool_calls: zod_v4.z.array(toolCallSchema).optional()
1511
1579
  }),
1512
- finish_reason: zod_v4.z.union([
1513
- zod_v4.z.literal("stop"),
1514
- zod_v4.z.literal("tool_calls"),
1515
- zod_v4.z.null()
1516
- ]).optional()
1580
+ finish_reason: zod_v4.z.union([zod_v4.z.string(), zod_v4.z.null()]).optional()
1517
1581
  }))
1518
1582
  });
1519
1583
 
@@ -1761,6 +1825,82 @@ const getToolNameFromPart = async (part) => {
1761
1825
  return providerOptions?.toolName ?? part.toolName;
1762
1826
  };
1763
1827
 
1828
+ //#endregion
1829
+ //#region src/fmapi-language-model/fmapi-finish-reason.ts
1830
+ function mapFmapiFinishReason(finishReason) {
1831
+ switch (finishReason) {
1832
+ case "stop": return "stop";
1833
+ case "length": return "length";
1834
+ case "content_filter": return "content-filter";
1835
+ case "function_call":
1836
+ case "tool_calls": return "tool-calls";
1837
+ default: return "other";
1838
+ }
1839
+ }
1840
+
1841
+ //#endregion
1842
+ //#region src/fmapi-language-model/call-options-to-fmapi-args.ts
1843
+ /**
1844
+ * Converts AI SDK LanguageModelV2CallOptions to Databricks FMAPI body parameters.
1845
+ *
1846
+ * Inspired by the getArgs method in:
1847
+ * https://github.com/vercel/ai/blob/main/packages/openai/src/chat/openai-chat-language-model.ts#L71
1848
+ *
1849
+ * Complies with the API described in:
1850
+ * https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/api-reference#chat-request
1851
+ */
1852
+ function callOptionsToFmapiArgs(options) {
1853
+ const warnings = [];
1854
+ const databricksOptions = options.providerOptions?.databricks;
1855
+ if (options.presencePenalty != null) warnings.push({
1856
+ type: "unsupported-setting",
1857
+ setting: "presencePenalty",
1858
+ details: "presencePenalty is not supported by the Databricks FMAPI"
1859
+ });
1860
+ if (options.frequencyPenalty != null) warnings.push({
1861
+ type: "unsupported-setting",
1862
+ setting: "frequencyPenalty",
1863
+ details: "frequencyPenalty is not supported by the Databricks FMAPI"
1864
+ });
1865
+ if (options.seed != null) warnings.push({
1866
+ type: "unsupported-setting",
1867
+ setting: "seed",
1868
+ details: "seed is not supported by the Databricks FMAPI"
1869
+ });
1870
+ const args = {};
1871
+ if (options.maxOutputTokens != null) args.max_tokens = options.maxOutputTokens;
1872
+ if (options.temperature != null) args.temperature = options.temperature;
1873
+ if (options.topP != null) args.top_p = options.topP;
1874
+ if (options.topK != null) args.top_k = options.topK;
1875
+ if (options.stopSequences != null && options.stopSequences.length > 0) args.stop = options.stopSequences;
1876
+ if (options.responseFormat != null) switch (options.responseFormat.type) {
1877
+ case "text":
1878
+ args.response_format = { type: "text" };
1879
+ break;
1880
+ case "json":
1881
+ if (options.responseFormat.schema != null) args.response_format = {
1882
+ type: "json_schema",
1883
+ json_schema: {
1884
+ name: options.responseFormat.name ?? "response",
1885
+ description: options.responseFormat.description,
1886
+ schema: options.responseFormat.schema,
1887
+ strict: true
1888
+ }
1889
+ };
1890
+ else args.response_format = { type: "json_object" };
1891
+ break;
1892
+ }
1893
+ if (databricksOptions?.topK != null) args.top_k = databricksOptions.topK;
1894
+ if (databricksOptions?.n != null) args.n = databricksOptions.n;
1895
+ if (databricksOptions?.logprobs != null) args.logprobs = databricksOptions.logprobs;
1896
+ if (databricksOptions?.topLogprobs != null) args.top_logprobs = databricksOptions.topLogprobs;
1897
+ if (databricksOptions?.reasoningEffort != null) args.reasoning_effort = databricksOptions.reasoningEffort;
1898
+ return {
1899
+ args,
1900
+ warnings
1901
+ };
1902
+ }
1903
+
1764
1904
  //#endregion
1765
1905
  //#region src/fmapi-language-model/fmapi-language-model.ts
1766
1906
  var DatabricksFmapiLanguageModel = class {
@@ -1776,7 +1916,7 @@ var DatabricksFmapiLanguageModel = class {
1776
1916
  }
1777
1917
  supportedUrls = {};
1778
1918
  async doGenerate(options) {
1779
- const networkArgs = await this.getArgs({
1919
+ const { warnings,...networkArgs } = await this.getArgs({
1780
1920
  config: this.config,
1781
1921
  options,
1782
1922
  stream: false,
@@ -1792,8 +1932,7 @@ var DatabricksFmapiLanguageModel = class {
1792
1932
  })
1793
1933
  });
1794
1934
  const choice = response.choices[0];
1795
- let finishReason = "stop";
1796
- if (choice?.finish_reason === "tool_calls") finishReason = "tool-calls";
1935
+ const finishReason = mapFmapiFinishReason(choice?.finish_reason);
1797
1936
  return {
1798
1937
  content: convertFmapiResponseToMessagePart(response),
1799
1938
  finishReason,
@@ -1802,11 +1941,11 @@ var DatabricksFmapiLanguageModel = class {
1802
1941
  outputTokens: response.usage?.completion_tokens ?? 0,
1803
1942
  totalTokens: response.usage?.total_tokens ?? 0
1804
1943
  },
1805
- warnings: []
1944
+ warnings
1806
1945
  };
1807
1946
  }
1808
1947
  async doStream(options) {
1809
- const networkArgs = await this.getArgs({
1948
+ const { warnings,...networkArgs } = await this.getArgs({
1810
1949
  config: this.config,
1811
1950
  options,
1812
1951
  stream: true,
@@ -1836,7 +1975,7 @@ var DatabricksFmapiLanguageModel = class {
1836
1975
  start(controller) {
1837
1976
  controller.enqueue({
1838
1977
  type: "stream-start",
1839
- warnings: []
1978
+ warnings
1840
1979
  });
1841
1980
  },
1842
1981
  transform(chunk, controller) {
@@ -1853,8 +1992,7 @@ var DatabricksFmapiLanguageModel = class {
1853
1992
  return;
1854
1993
  }
1855
1994
  const choice = chunk.value.choices[0];
1856
- if (choice?.finish_reason === "stop") finishReason = "stop";
1857
- else if (choice?.finish_reason === "tool_calls") finishReason = "tool-calls";
1995
+ finishReason = mapFmapiFinishReason(choice?.finish_reason);
1858
1996
  if (chunk.value.usage) usage = {
1859
1997
  inputTokens: chunk.value.usage.prompt_tokens ?? 0,
1860
1998
  outputTokens: chunk.value.usage.completion_tokens ?? 0,
@@ -1904,6 +2042,7 @@ var DatabricksFmapiLanguageModel = class {
1904
2042
  const tools = options.tools?.map((tool) => convertToolToOpenAIFormat(tool)).filter((tool) => tool !== void 0);
1905
2043
  const toolChoice = options.toolChoice ? convertToolChoiceToOpenAIFormat(options.toolChoice) : void 0;
1906
2044
  const { messages } = await convertPromptToFmapiMessages(options.prompt);
2045
+ const { args: callArgs, warnings } = callOptionsToFmapiArgs(options);
1907
2046
  return {
1908
2047
  url: config.url({ path: "/chat/completions" }),
1909
2048
  headers: (0, __ai_sdk_provider_utils.combineHeaders)(config.headers(), options.headers),
@@ -1913,10 +2052,9 @@ var DatabricksFmapiLanguageModel = class {
1913
2052
  model: modelId,
1914
2053
  ...tools && tools.length > 0 ? { tools } : {},
1915
2054
  ...toolChoice && tools && tools.length > 0 ? { tool_choice: toolChoice } : {},
1916
- ...options.temperature !== void 0 ? { temperature: options.temperature } : {},
1917
- ...options.maxOutputTokens !== void 0 ? { max_tokens: options.maxOutputTokens } : {},
1918
- ...options.stopSequences && options.stopSequences.length > 0 ? { stop: options.stopSequences } : {}
2055
+ ...callArgs
1919
2056
  },
2057
+ warnings,
1920
2058
  fetch: config.fetch
1921
2059
  };
1922
2060
  }