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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. diff --git a/dist/index.d.mts b/dist/index.d.mts
  2. index 266c5ffdd9ee74ff95908ce90858ee4369d4e4ae..990ef4195bc67b6d25f249e1c81cf51710390f9a 100644
  3. --- a/dist/index.d.mts
  4. +++ b/dist/index.d.mts
  5. @@ -78,6 +78,7 @@ declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
  6. topLogprobs: z.ZodOptional<z.ZodNumber>;
  7. store: z.ZodOptional<z.ZodBoolean>;
  8. previousResponseId: z.ZodOptional<z.ZodString>;
  9. + promptCacheKey: z.ZodOptional<z.ZodString>;
  10. include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
  11. "file_search_call.results": "file_search_call.results";
  12. }>>>>;
  13. diff --git a/dist/index.d.ts b/dist/index.d.ts
  14. index 266c5ffdd9ee74ff95908ce90858ee4369d4e4ae..990ef4195bc67b6d25f249e1c81cf51710390f9a 100644
  15. --- a/dist/index.d.ts
  16. +++ b/dist/index.d.ts
  17. @@ -78,6 +78,7 @@ declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
  18. topLogprobs: z.ZodOptional<z.ZodNumber>;
  19. store: z.ZodOptional<z.ZodBoolean>;
  20. previousResponseId: z.ZodOptional<z.ZodString>;
  21. + promptCacheKey: z.ZodOptional<z.ZodString>;
  22. include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
  23. "file_search_call.results": "file_search_call.results";
  24. }>>>>;
  25. diff --git a/dist/index.js b/dist/index.js
  26. index 717b74538f5c8f0d6ab1475ebb2a84a47ccd3950..dd7dbeb3bc307e0d355f4bb4939d06cc8eae7528 100644
  27. --- a/dist/index.js
  28. +++ b/dist/index.js
  29. @@ -1119,6 +1119,14 @@ async function convertToXaiResponsesInput({
  30. type: "input_file",
  31. file_url: block.data.toString()
  32. });
  33. + } else if (block.mediaType === "application/pdf") {
  34. + contentParts.push({
  35. + type: "input_file",
  36. + ...typeof block.data === "string" && block.data.startsWith("file-") ? { file_id: block.data } : {
  37. + filename: block.filename ?? "file",
  38. + file_data: `data:application/pdf;base64,${(0, import_provider_utils5.convertToBase64)(block.data)}`
  39. + }
  40. + });
  41. } else {
  42. throw new import_provider4.UnsupportedFunctionalityError({
  43. functionality: `file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)`
  44. @@ -1760,6 +1768,10 @@ var xaiLanguageModelResponsesOptions = import_v47.z.object({
  45. * The ID of the previous response from the model.
  46. */
  47. previousResponseId: import_v47.z.string().optional(),
  48. + /**
  49. + * A stable key used by xAI to improve prompt cache routing.
  50. + */
  51. + promptCacheKey: import_v47.z.string().optional(),
  52. /**
  53. * Specify additional output data to include in the model response.
  54. * Example values: 'file_search_call.results'.
  55. @@ -2165,6 +2177,9 @@ var XaiResponsesLanguageModel = class {
  56. },
  57. ...options.previousResponseId != null && {
  58. previous_response_id: options.previousResponseId
  59. + },
  60. + ...options.promptCacheKey != null && {
  61. + prompt_cache_key: options.promptCacheKey
  62. }
  63. };
  64. if (xaiTools2 && xaiTools2.length > 0) {
  65. diff --git a/dist/index.mjs b/dist/index.mjs
  66. index a26af109585fc2bd3053b320142aa869c06d36f4..774adaf971b648544317a4fc65d0c56e488d4fc7 100644
  67. --- a/dist/index.mjs
  68. +++ b/dist/index.mjs
  69. @@ -1122,6 +1122,14 @@ async function convertToXaiResponsesInput({
  70. type: "input_file",
  71. file_url: block.data.toString()
  72. });
  73. + } else if (block.mediaType === "application/pdf") {
  74. + contentParts.push({
  75. + type: "input_file",
  76. + ...typeof block.data === "string" && block.data.startsWith("file-") ? { file_id: block.data } : {
  77. + filename: block.filename ?? "file",
  78. + file_data: `data:application/pdf;base64,${convertToBase642(block.data)}`
  79. + }
  80. + });
  81. } else {
  82. throw new UnsupportedFunctionalityError3({
  83. functionality: `file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)`
  84. @@ -1763,6 +1771,10 @@ var xaiLanguageModelResponsesOptions = z7.object({
  85. * The ID of the previous response from the model.
  86. */
  87. previousResponseId: z7.string().optional(),
  88. + /**
  89. + * A stable key used by xAI to improve prompt cache routing.
  90. + */
  91. + promptCacheKey: z7.string().optional(),
  92. /**
  93. * Specify additional output data to include in the model response.
  94. * Example values: 'file_search_call.results'.
  95. @@ -2186,6 +2198,9 @@ var XaiResponsesLanguageModel = class {
  96. },
  97. ...options.previousResponseId != null && {
  98. previous_response_id: options.previousResponseId
  99. + },
  100. + ...options.promptCacheKey != null && {
  101. + prompt_cache_key: options.promptCacheKey
  102. }
  103. };
  104. if (xaiTools2 && xaiTools2.length > 0) {
  105. diff --git a/src/responses/convert-to-xai-responses-input.ts b/src/responses/convert-to-xai-responses-input.ts
  106. index 9a3712990cf646a6f7ba757d3f2893a3c37c6ef9..b018a9b95eb21e6c12794e6bddb3d953f40441e5 100644
  107. --- a/src/responses/convert-to-xai-responses-input.ts
  108. +++ b/src/responses/convert-to-xai-responses-input.ts
  109. @@ -64,6 +64,17 @@ export async function convertToXaiResponsesInput({
  110. type: 'input_file',
  111. file_url: block.data.toString(),
  112. });
  113. + } else if (block.mediaType === 'application/pdf') {
  114. + contentParts.push({
  115. + type: 'input_file',
  116. + ...(typeof block.data === 'string' &&
  117. + block.data.startsWith('file-')
  118. + ? { file_id: block.data }
  119. + : {
  120. + filename: block.filename ?? 'file',
  121. + file_data: `data:application/pdf;base64,${convertToBase64(block.data)}`,
  122. + }),
  123. + });
  124. } else {
  125. throw new UnsupportedFunctionalityError({
  126. functionality: `file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)`,
  127. diff --git a/src/responses/xai-responses-api.ts b/src/responses/xai-responses-api.ts
  128. index 70483ea4f7c340b84c23766ac1d1df21e052842b..4b4d052860caa019556151e9e46dbfda8dfb18a9 100644
  129. --- a/src/responses/xai-responses-api.ts
  130. +++ b/src/responses/xai-responses-api.ts
  131. @@ -27,7 +27,13 @@ export type XaiResponsesSystemMessage = {
  132. export type XaiResponsesUserMessageContentPart =
  133. | { type: 'input_text'; text: string }
  134. | { type: 'input_image'; image_url: string }
  135. - | { type: 'input_file'; file_url: string };
  136. + | {
  137. + type: 'input_file';
  138. + file_url?: string;
  139. + file_id?: string;
  140. + file_data?: string;
  141. + filename?: string;
  142. + };
  143. export type XaiResponsesUserMessage = {
  144. role: 'user';
  145. diff --git a/src/responses/xai-responses-language-model.ts b/src/responses/xai-responses-language-model.ts
  146. index f90df62eb9a30154388b1390e9f3acc3ccc022bf..00e61cba6cf048ae0045be692f33cb7e1e6a1188 100644
  147. --- a/src/responses/xai-responses-language-model.ts
  148. +++ b/src/responses/xai-responses-language-model.ts
  149. @@ -182,6 +182,9 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
  150. ...(options.previousResponseId != null && {
  151. previous_response_id: options.previousResponseId,
  152. }),
  153. + ...(options.promptCacheKey != null && {
  154. + prompt_cache_key: options.promptCacheKey,
  155. + }),
  156. };
  157. if (xaiTools && xaiTools.length > 0) {
  158. diff --git a/src/responses/xai-responses-options.ts b/src/responses/xai-responses-options.ts
  159. index f8e96c061bf8793a402ababb8cad65bb2ad6aead..15c168892c1e8755453c61d3061e958cfd51ac71 100644
  160. --- a/src/responses/xai-responses-options.ts
  161. +++ b/src/responses/xai-responses-options.ts
  162. @@ -32,6 +32,10 @@ export const xaiLanguageModelResponsesOptions = z.object({
  163. * The ID of the previous response from the model.
  164. */
  165. previousResponseId: z.string().optional(),
  166. + /**
  167. + * A stable key used by xAI to improve prompt cache routing.
  168. + */
  169. + promptCacheKey: z.string().optional(),
  170. /**
  171. * Specify additional output data to include in the model response.
  172. * Example values: 'file_search_call.results'.