@ai-sdk%2Fxai@3.0.82.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. diff --git a/dist/index.js b/dist/index.js
  2. index 135b95946139bbd1fc4b62239032931586189da0..7913520ad2f1c26b0f9621e7654f5fb570cba926 100644
  3. --- a/dist/index.js
  4. +++ b/dist/index.js
  5. @@ -1077,6 +1077,20 @@ async function convertToXaiResponsesInput({
  6. const mediaType = block.mediaType === "image/*" ? "image/jpeg" : block.mediaType;
  7. const imageUrl = block.data instanceof URL ? block.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils5.convertToBase64)(block.data)}`;
  8. contentParts.push({ type: "input_image", image_url: imageUrl });
  9. + } else if (block.mediaType === "application/pdf") {
  10. + if (block.data instanceof URL) {
  11. + contentParts.push({ type: "input_file", file_url: block.data.toString() });
  12. + } else {
  13. + contentParts.push({
  14. + type: "input_file",
  15. + ...(typeof block.data === "string" && block.data.startsWith("file-")
  16. + ? { file_id: block.data }
  17. + : {
  18. + filename: block.filename ?? "file",
  19. + file_data: `data:application/pdf;base64,${(0, import_provider_utils5.convertToBase64)(block.data)}`,
  20. + }),
  21. + });
  22. + }
  23. } else {
  24. throw new import_provider4.UnsupportedFunctionalityError({
  25. functionality: `file part media type ${block.mediaType}`
  26. diff --git a/dist/index.mjs b/dist/index.mjs
  27. index 61be60d452682b94dcdda39ffc47cb994eb8bfb1..d928f7f46e91057cd97fade9cc238db611345bcf 100644
  28. --- a/dist/index.mjs
  29. +++ b/dist/index.mjs
  30. @@ -1080,6 +1080,20 @@ async function convertToXaiResponsesInput({
  31. const mediaType = block.mediaType === "image/*" ? "image/jpeg" : block.mediaType;
  32. const imageUrl = block.data instanceof URL ? block.data.toString() : `data:${mediaType};base64,${convertToBase642(block.data)}`;
  33. contentParts.push({ type: "input_image", image_url: imageUrl });
  34. + } else if (block.mediaType === "application/pdf") {
  35. + if (block.data instanceof URL) {
  36. + contentParts.push({ type: "input_file", file_url: block.data.toString() });
  37. + } else {
  38. + contentParts.push({
  39. + type: "input_file",
  40. + ...(typeof block.data === "string" && block.data.startsWith("file-")
  41. + ? { file_id: block.data }
  42. + : {
  43. + filename: block.filename ?? "file",
  44. + file_data: `data:application/pdf;base64,${convertToBase642(block.data)}`,
  45. + }),
  46. + });
  47. + }
  48. } else {
  49. throw new UnsupportedFunctionalityError3({
  50. functionality: `file part media type ${block.mediaType}`
  51. diff --git a/src/responses/convert-to-xai-responses-input.ts b/src/responses/convert-to-xai-responses-input.ts
  52. index 19958d9fd90f7ce61bca70ad2d5f7b89a59fa63b..9329a1d56210af8aa33e5dbcb2916e24847070c1 100644
  53. --- a/src/responses/convert-to-xai-responses-input.ts
  54. +++ b/src/responses/convert-to-xai-responses-input.ts
  55. @@ -54,6 +54,24 @@ export async function convertToXaiResponsesInput({
  56. : `data:${mediaType};base64,${convertToBase64(block.data)}`;
  57. contentParts.push({ type: 'input_image', image_url: imageUrl });
  58. + } else if (block.mediaType === 'application/pdf') {
  59. + if (block.data instanceof URL) {
  60. + contentParts.push({
  61. + type: 'input_file',
  62. + file_url: block.data.toString(),
  63. + });
  64. + } else {
  65. + contentParts.push({
  66. + type: 'input_file',
  67. + ...(typeof block.data === 'string' &&
  68. + block.data.startsWith('file-')
  69. + ? { file_id: block.data }
  70. + : {
  71. + filename: block.filename ?? 'file',
  72. + file_data: `data:application/pdf;base64,${convertToBase64(block.data)}`,
  73. + }),
  74. + });
  75. + }
  76. } else {
  77. throw new UnsupportedFunctionalityError({
  78. functionality: `file part media type ${block.mediaType}`,
  79. diff --git a/src/responses/xai-responses-api.ts b/src/responses/xai-responses-api.ts
  80. index df24c42d29fe7fc1dd7649cc2c4712a68c3a536b..00195468a83d43c1bfb50854ea040b55ea352433 100644
  81. --- a/src/responses/xai-responses-api.ts
  82. +++ b/src/responses/xai-responses-api.ts
  83. @@ -26,7 +26,14 @@ export type XaiResponsesSystemMessage = {
  84. export type XaiResponsesUserMessageContentPart =
  85. | { type: 'input_text'; text: string }
  86. - | { type: 'input_image'; image_url: string };
  87. + | { type: 'input_image'; image_url: string }
  88. + | {
  89. + type: 'input_file';
  90. + file_url?: string;
  91. + file_id?: string;
  92. + file_data?: string;
  93. + filename?: string;
  94. + };
  95. export type XaiResponsesUserMessage = {
  96. role: 'user';