@ai-sdk%2Fxai@3.0.102.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. diff --git a/dist/index.d.mts b/dist/index.d.mts
  2. index 266c5ffdd9ee74ff95908ce90858ee4369d4e4ae..6ac6e2873b7681ac632c903694aa38c7b09773fa 100644
  3. --- a/dist/index.d.mts
  4. +++ b/dist/index.d.mts
  5. @@ -5,12 +5,7 @@ import { FetchFunction } from '@ai-sdk/provider-utils';
  6. type XaiChatModelId = 'grok-4.3' | 'grok-4.20-0309-reasoning' | 'grok-4.20-0309-non-reasoning' | 'grok-4.20-multi-agent-0309' | 'grok-build-0.1' | (string & {});
  7. declare const xaiLanguageModelChatOptions: z.ZodObject<{
  8. - reasoningEffort: z.ZodOptional<z.ZodEnum<{
  9. - none: "none";
  10. - low: "low";
  11. - medium: "medium";
  12. - high: "high";
  13. - }>>;
  14. + reasoningEffort: z.ZodOptional<z.ZodString>;
  15. logprobs: z.ZodOptional<z.ZodBoolean>;
  16. topLogprobs: z.ZodOptional<z.ZodNumber>;
  17. parallel_function_calling: z.ZodOptional<z.ZodBoolean>;
  18. @@ -68,16 +63,12 @@ type XaiResponsesModelId = 'grok-4.3' | 'grok-4.20-0309-reasoning' | 'grok-4.20-
  19. * @see https://docs.x.ai/docs/api-reference#create-new-response
  20. */
  21. declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
  22. - reasoningEffort: z.ZodOptional<z.ZodEnum<{
  23. - none: "none";
  24. - low: "low";
  25. - medium: "medium";
  26. - high: "high";
  27. - }>>;
  28. + reasoningEffort: z.ZodOptional<z.ZodString>;
  29. logprobs: z.ZodOptional<z.ZodBoolean>;
  30. topLogprobs: z.ZodOptional<z.ZodNumber>;
  31. store: z.ZodOptional<z.ZodBoolean>;
  32. previousResponseId: z.ZodOptional<z.ZodString>;
  33. + promptCacheKey: z.ZodOptional<z.ZodString>;
  34. include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
  35. "file_search_call.results": "file_search_call.results";
  36. }>>>>;
  37. diff --git a/dist/index.d.ts b/dist/index.d.ts
  38. index 266c5ffdd9ee74ff95908ce90858ee4369d4e4ae..6ac6e2873b7681ac632c903694aa38c7b09773fa 100644
  39. --- a/dist/index.d.ts
  40. +++ b/dist/index.d.ts
  41. @@ -5,12 +5,7 @@ import { FetchFunction } from '@ai-sdk/provider-utils';
  42. type XaiChatModelId = 'grok-4.3' | 'grok-4.20-0309-reasoning' | 'grok-4.20-0309-non-reasoning' | 'grok-4.20-multi-agent-0309' | 'grok-build-0.1' | (string & {});
  43. declare const xaiLanguageModelChatOptions: z.ZodObject<{
  44. - reasoningEffort: z.ZodOptional<z.ZodEnum<{
  45. - none: "none";
  46. - low: "low";
  47. - medium: "medium";
  48. - high: "high";
  49. - }>>;
  50. + reasoningEffort: z.ZodOptional<z.ZodString>;
  51. logprobs: z.ZodOptional<z.ZodBoolean>;
  52. topLogprobs: z.ZodOptional<z.ZodNumber>;
  53. parallel_function_calling: z.ZodOptional<z.ZodBoolean>;
  54. @@ -68,16 +63,12 @@ type XaiResponsesModelId = 'grok-4.3' | 'grok-4.20-0309-reasoning' | 'grok-4.20-
  55. * @see https://docs.x.ai/docs/api-reference#create-new-response
  56. */
  57. declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
  58. - reasoningEffort: z.ZodOptional<z.ZodEnum<{
  59. - none: "none";
  60. - low: "low";
  61. - medium: "medium";
  62. - high: "high";
  63. - }>>;
  64. + reasoningEffort: z.ZodOptional<z.ZodString>;
  65. logprobs: z.ZodOptional<z.ZodBoolean>;
  66. topLogprobs: z.ZodOptional<z.ZodNumber>;
  67. store: z.ZodOptional<z.ZodBoolean>;
  68. previousResponseId: z.ZodOptional<z.ZodString>;
  69. + promptCacheKey: z.ZodOptional<z.ZodString>;
  70. include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
  71. "file_search_call.results": "file_search_call.results";
  72. }>>>>;
  73. diff --git a/dist/index.js b/dist/index.js
  74. index 717b74538f5c8f0d6ab1475ebb2a84a47ccd3950..0fd8f0d1cae951cd24401034a9c1dba762d9fd84 100644
  75. --- a/dist/index.js
  76. +++ b/dist/index.js
  77. @@ -246,7 +246,7 @@ var searchSourceSchema = import_v4.z.discriminatedUnion("type", [
  78. rssSourceSchema
  79. ]);
  80. var xaiLanguageModelChatOptions = import_v4.z.object({
  81. - reasoningEffort: import_v4.z.enum(["none", "low", "medium", "high"]).optional(),
  82. + reasoningEffort: import_v4.z.string().optional(),
  83. logprobs: import_v4.z.boolean().optional(),
  84. topLogprobs: import_v4.z.number().int().min(0).max(8).optional(),
  85. /**
  86. @@ -1119,6 +1119,14 @@ async function convertToXaiResponsesInput({
  87. type: "input_file",
  88. file_url: block.data.toString()
  89. });
  90. + } else if (block.mediaType === "application/pdf") {
  91. + contentParts.push({
  92. + type: "input_file",
  93. + ...typeof block.data === "string" && block.data.startsWith("file-") ? { file_id: block.data } : {
  94. + filename: block.filename ?? "file",
  95. + file_data: `data:application/pdf;base64,${(0, import_provider_utils5.convertToBase64)(block.data)}`
  96. + }
  97. + });
  98. } else {
  99. throw new import_provider4.UnsupportedFunctionalityError({
  100. functionality: `file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)`
  101. @@ -1746,7 +1754,7 @@ var xaiLanguageModelResponsesOptions = import_v47.z.object({
  102. * tokens), `medium` and `high` (uses more reasoning tokens). Not all models
  103. * support reasoning effort; see xAI's docs for the values each model accepts.
  104. */
  105. - reasoningEffort: import_v47.z.enum(["none", "low", "medium", "high"]).optional(),
  106. + reasoningEffort: import_v47.z.string().optional(),
  107. logprobs: import_v47.z.boolean().optional(),
  108. topLogprobs: import_v47.z.number().int().min(0).max(8).optional(),
  109. /**
  110. @@ -1760,6 +1768,10 @@ var xaiLanguageModelResponsesOptions = import_v47.z.object({
  111. * The ID of the previous response from the model.
  112. */
  113. previousResponseId: import_v47.z.string().optional(),
  114. + /**
  115. + * A stable key used by xAI to improve prompt cache routing.
  116. + */
  117. + promptCacheKey: import_v47.z.string().optional(),
  118. /**
  119. * Specify additional output data to include in the model response.
  120. * Example values: 'file_search_call.results'.
  121. @@ -2165,6 +2177,9 @@ var XaiResponsesLanguageModel = class {
  122. },
  123. ...options.previousResponseId != null && {
  124. previous_response_id: options.previousResponseId
  125. + },
  126. + ...options.promptCacheKey != null && {
  127. + prompt_cache_key: options.promptCacheKey
  128. }
  129. };
  130. if (xaiTools2 && xaiTools2.length > 0) {
  131. diff --git a/dist/index.mjs b/dist/index.mjs
  132. index a26af109585fc2bd3053b320142aa869c06d36f4..5faca56477b4e55a87f6f57850731c7d3e1721a5 100644
  133. --- a/dist/index.mjs
  134. +++ b/dist/index.mjs
  135. @@ -230,7 +230,7 @@ var searchSourceSchema = z.discriminatedUnion("type", [
  136. rssSourceSchema
  137. ]);
  138. var xaiLanguageModelChatOptions = z.object({
  139. - reasoningEffort: z.enum(["none", "low", "medium", "high"]).optional(),
  140. + reasoningEffort: z.string().optional(),
  141. logprobs: z.boolean().optional(),
  142. topLogprobs: z.number().int().min(0).max(8).optional(),
  143. /**
  144. @@ -1122,6 +1122,14 @@ async function convertToXaiResponsesInput({
  145. type: "input_file",
  146. file_url: block.data.toString()
  147. });
  148. + } else if (block.mediaType === "application/pdf") {
  149. + contentParts.push({
  150. + type: "input_file",
  151. + ...typeof block.data === "string" && block.data.startsWith("file-") ? { file_id: block.data } : {
  152. + filename: block.filename ?? "file",
  153. + file_data: `data:application/pdf;base64,${convertToBase642(block.data)}`
  154. + }
  155. + });
  156. } else {
  157. throw new UnsupportedFunctionalityError3({
  158. functionality: `file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)`
  159. @@ -1749,7 +1757,7 @@ var xaiLanguageModelResponsesOptions = z7.object({
  160. * tokens), `medium` and `high` (uses more reasoning tokens). Not all models
  161. * support reasoning effort; see xAI's docs for the values each model accepts.
  162. */
  163. - reasoningEffort: z7.enum(["none", "low", "medium", "high"]).optional(),
  164. + reasoningEffort: z7.string().optional(),
  165. logprobs: z7.boolean().optional(),
  166. topLogprobs: z7.number().int().min(0).max(8).optional(),
  167. /**
  168. @@ -1763,6 +1771,10 @@ var xaiLanguageModelResponsesOptions = z7.object({
  169. * The ID of the previous response from the model.
  170. */
  171. previousResponseId: z7.string().optional(),
  172. + /**
  173. + * A stable key used by xAI to improve prompt cache routing.
  174. + */
  175. + promptCacheKey: z7.string().optional(),
  176. /**
  177. * Specify additional output data to include in the model response.
  178. * Example values: 'file_search_call.results'.
  179. @@ -2186,6 +2198,9 @@ var XaiResponsesLanguageModel = class {
  180. },
  181. ...options.previousResponseId != null && {
  182. previous_response_id: options.previousResponseId
  183. + },
  184. + ...options.promptCacheKey != null && {
  185. + prompt_cache_key: options.promptCacheKey
  186. }
  187. };
  188. if (xaiTools2 && xaiTools2.length > 0) {
  189. diff --git a/src/responses/convert-to-xai-responses-input.ts b/src/responses/convert-to-xai-responses-input.ts
  190. index 9a3712990cf646a6f7ba757d3f2893a3c37c6ef9..b018a9b95eb21e6c12794e6bddb3d953f40441e5 100644
  191. --- a/src/responses/convert-to-xai-responses-input.ts
  192. +++ b/src/responses/convert-to-xai-responses-input.ts
  193. @@ -64,6 +64,17 @@ export async function convertToXaiResponsesInput({
  194. type: 'input_file',
  195. file_url: block.data.toString(),
  196. });
  197. + } else if (block.mediaType === 'application/pdf') {
  198. + contentParts.push({
  199. + type: 'input_file',
  200. + ...(typeof block.data === 'string' &&
  201. + block.data.startsWith('file-')
  202. + ? { file_id: block.data }
  203. + : {
  204. + filename: block.filename ?? 'file',
  205. + file_data: `data:application/pdf;base64,${convertToBase64(block.data)}`,
  206. + }),
  207. + });
  208. } else {
  209. throw new UnsupportedFunctionalityError({
  210. functionality: `file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)`,
  211. diff --git a/src/responses/xai-responses-api.ts b/src/responses/xai-responses-api.ts
  212. index 70483ea4f7c340b84c23766ac1d1df21e052842b..4b4d052860caa019556151e9e46dbfda8dfb18a9 100644
  213. --- a/src/responses/xai-responses-api.ts
  214. +++ b/src/responses/xai-responses-api.ts
  215. @@ -27,7 +27,13 @@ export type XaiResponsesSystemMessage = {
  216. export type XaiResponsesUserMessageContentPart =
  217. | { type: 'input_text'; text: string }
  218. | { type: 'input_image'; image_url: string }
  219. - | { type: 'input_file'; file_url: string };
  220. + | {
  221. + type: 'input_file';
  222. + file_url?: string;
  223. + file_id?: string;
  224. + file_data?: string;
  225. + filename?: string;
  226. + };
  227. export type XaiResponsesUserMessage = {
  228. role: 'user';
  229. diff --git a/src/responses/xai-responses-language-model.ts b/src/responses/xai-responses-language-model.ts
  230. index f90df62eb9a30154388b1390e9f3acc3ccc022bf..00e61cba6cf048ae0045be692f33cb7e1e6a1188 100644
  231. --- a/src/responses/xai-responses-language-model.ts
  232. +++ b/src/responses/xai-responses-language-model.ts
  233. @@ -182,6 +182,9 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
  234. ...(options.previousResponseId != null && {
  235. previous_response_id: options.previousResponseId,
  236. }),
  237. + ...(options.promptCacheKey != null && {
  238. + prompt_cache_key: options.promptCacheKey,
  239. + }),
  240. };
  241. if (xaiTools && xaiTools.length > 0) {
  242. diff --git a/src/responses/xai-responses-options.ts b/src/responses/xai-responses-options.ts
  243. index f8e96c061bf8793a402ababb8cad65bb2ad6aead..2a39a36221ab23ea0000bff1d7854c5bce3f9d74 100644
  244. --- a/src/responses/xai-responses-options.ts
  245. +++ b/src/responses/xai-responses-options.ts
  246. @@ -18,7 +18,7 @@ export const xaiLanguageModelResponsesOptions = z.object({
  247. * tokens), `medium` and `high` (uses more reasoning tokens). Not all models
  248. * support reasoning effort; see xAI's docs for the values each model accepts.
  249. */
  250. - reasoningEffort: z.enum(['none', 'low', 'medium', 'high']).optional(),
  251. + reasoningEffort: z.string().optional(),
  252. logprobs: z.boolean().optional(),
  253. topLogprobs: z.number().int().min(0).max(8).optional(),
  254. /**
  255. @@ -32,6 +32,10 @@ export const xaiLanguageModelResponsesOptions = z.object({
  256. * The ID of the previous response from the model.
  257. */
  258. previousResponseId: z.string().optional(),
  259. + /**
  260. + * A stable key used by xAI to improve prompt cache routing.
  261. + */
  262. + promptCacheKey: z.string().optional(),
  263. /**
  264. * Specify additional output data to include in the model response.
  265. * Example values: 'file_search_call.results'.
  266. diff --git a/src/xai-chat-options.ts b/src/xai-chat-options.ts
  267. index d70a72a9fa01da2c711c291da5ce949efbde60b5..fd6b1ae025388b614f08b620244be553199479ca 100644
  268. --- a/src/xai-chat-options.ts
  269. +++ b/src/xai-chat-options.ts
  270. @@ -51,7 +51,7 @@ const searchSourceSchema = z.discriminatedUnion('type', [
  271. // xai-specific provider options
  272. export const xaiLanguageModelChatOptions = z.object({
  273. - reasoningEffort: z.enum(['none', 'low', 'medium', 'high']).optional(),
  274. + reasoningEffort: z.string().optional(),
  275. logprobs: z.boolean().optional(),
  276. topLogprobs: z.number().int().min(0).max(8).optional(),