@providerprotocol/ai 0.0.18 → 0.0.20
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/README.md +364 -111
- package/dist/anthropic/index.d.ts +1 -1
- package/dist/anthropic/index.js +6 -6
- package/dist/chunk-P5IRTEM5.js +120 -0
- package/dist/chunk-P5IRTEM5.js.map +1 -0
- package/dist/{chunk-5FEAOEXV.js → chunk-U3FZWV4U.js} +53 -102
- package/dist/chunk-U3FZWV4U.js.map +1 -0
- package/dist/chunk-WAKD3OO5.js +224 -0
- package/dist/chunk-WAKD3OO5.js.map +1 -0
- package/dist/content-DEl3z_W2.d.ts +276 -0
- package/dist/google/index.d.ts +3 -1
- package/dist/google/index.js +123 -7
- package/dist/google/index.js.map +1 -1
- package/dist/http/index.d.ts +2 -2
- package/dist/http/index.js +4 -3
- package/dist/image-Dhq-Yuq4.d.ts +456 -0
- package/dist/index.d.ts +55 -163
- package/dist/index.js +81 -213
- package/dist/index.js.map +1 -1
- package/dist/ollama/index.d.ts +1 -1
- package/dist/ollama/index.js +6 -6
- package/dist/openai/index.d.ts +47 -20
- package/dist/openai/index.js +310 -7
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +1 -1
- package/dist/openrouter/index.js +6 -6
- package/dist/{provider-D5MO3-pS.d.ts → provider-BBMBZuGn.d.ts} +11 -11
- package/dist/proxy/index.d.ts +310 -86
- package/dist/proxy/index.js +33 -59
- package/dist/proxy/index.js.map +1 -1
- package/dist/{retry-DZ4Sqmxp.d.ts → retry-DR7YRJDz.d.ts} +1 -1
- package/dist/{stream-BjyVzBxV.d.ts → stream-DRHy6q1a.d.ts} +2 -275
- package/dist/xai/index.d.ts +29 -1
- package/dist/xai/index.js +119 -7
- package/dist/xai/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-5FEAOEXV.js.map +0 -1
- package/dist/chunk-DZQHVGNV.js +0 -71
- package/dist/chunk-DZQHVGNV.js.map +0 -1
|
@@ -1,277 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* @fileoverview Content block types for multimodal messages.
|
|
3
|
-
*
|
|
4
|
-
* Defines the various content block types that can be included in
|
|
5
|
-
* user and assistant messages, supporting text, images, audio, video,
|
|
6
|
-
* and arbitrary binary data.
|
|
7
|
-
*
|
|
8
|
-
* @module types/content
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Image source variants for ImageBlock.
|
|
12
|
-
*
|
|
13
|
-
* Images can be provided as base64-encoded strings, URLs, or raw bytes.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* // Base64 encoded image
|
|
18
|
-
* const base64Source: ImageSource = {
|
|
19
|
-
* type: 'base64',
|
|
20
|
-
* data: 'iVBORw0KGgo...'
|
|
21
|
-
* };
|
|
22
|
-
*
|
|
23
|
-
* // URL reference
|
|
24
|
-
* const urlSource: ImageSource = {
|
|
25
|
-
* type: 'url',
|
|
26
|
-
* url: 'https://example.com/image.png'
|
|
27
|
-
* };
|
|
28
|
-
*
|
|
29
|
-
* // Raw bytes
|
|
30
|
-
* const bytesSource: ImageSource = {
|
|
31
|
-
* type: 'bytes',
|
|
32
|
-
* data: new Uint8Array([...])
|
|
33
|
-
* };
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
type ImageSource = {
|
|
37
|
-
type: 'base64';
|
|
38
|
-
data: string;
|
|
39
|
-
} | {
|
|
40
|
-
type: 'url';
|
|
41
|
-
url: string;
|
|
42
|
-
} | {
|
|
43
|
-
type: 'bytes';
|
|
44
|
-
data: Uint8Array;
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Text content block.
|
|
48
|
-
*
|
|
49
|
-
* The most common content block type, containing plain text content.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* const textBlock: TextBlock = {
|
|
54
|
-
* type: 'text',
|
|
55
|
-
* text: 'Hello, world!'
|
|
56
|
-
* };
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
interface TextBlock {
|
|
60
|
-
/** Discriminator for text blocks */
|
|
61
|
-
type: 'text';
|
|
62
|
-
/** The text content */
|
|
63
|
-
text: string;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Image content block.
|
|
67
|
-
*
|
|
68
|
-
* Contains an image with its source data and metadata.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* const imageBlock: ImageBlock = {
|
|
73
|
-
* type: 'image',
|
|
74
|
-
* source: { type: 'url', url: 'https://example.com/photo.jpg' },
|
|
75
|
-
* mimeType: 'image/jpeg',
|
|
76
|
-
* width: 1920,
|
|
77
|
-
* height: 1080
|
|
78
|
-
* };
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
interface ImageBlock {
|
|
82
|
-
/** Discriminator for image blocks */
|
|
83
|
-
type: 'image';
|
|
84
|
-
/** The image data source */
|
|
85
|
-
source: ImageSource;
|
|
86
|
-
/** MIME type of the image (e.g., 'image/png', 'image/jpeg') */
|
|
87
|
-
mimeType: string;
|
|
88
|
-
/** Image width in pixels */
|
|
89
|
-
width?: number;
|
|
90
|
-
/** Image height in pixels */
|
|
91
|
-
height?: number;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Audio content block.
|
|
95
|
-
*
|
|
96
|
-
* Contains audio data with its metadata.
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```typescript
|
|
100
|
-
* const audioBlock: AudioBlock = {
|
|
101
|
-
* type: 'audio',
|
|
102
|
-
* data: audioBytes,
|
|
103
|
-
* mimeType: 'audio/mp3',
|
|
104
|
-
* duration: 120.5
|
|
105
|
-
* };
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
interface AudioBlock {
|
|
109
|
-
/** Discriminator for audio blocks */
|
|
110
|
-
type: 'audio';
|
|
111
|
-
/** Raw audio data */
|
|
112
|
-
data: Uint8Array;
|
|
113
|
-
/** MIME type of the audio (e.g., 'audio/mp3', 'audio/wav') */
|
|
114
|
-
mimeType: string;
|
|
115
|
-
/** Duration in seconds */
|
|
116
|
-
duration?: number;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Video content block.
|
|
120
|
-
*
|
|
121
|
-
* Contains video data with its metadata.
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* ```typescript
|
|
125
|
-
* const videoBlock: VideoBlock = {
|
|
126
|
-
* type: 'video',
|
|
127
|
-
* data: videoBytes,
|
|
128
|
-
* mimeType: 'video/mp4',
|
|
129
|
-
* duration: 30,
|
|
130
|
-
* width: 1920,
|
|
131
|
-
* height: 1080
|
|
132
|
-
* };
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
interface VideoBlock {
|
|
136
|
-
/** Discriminator for video blocks */
|
|
137
|
-
type: 'video';
|
|
138
|
-
/** Raw video data */
|
|
139
|
-
data: Uint8Array;
|
|
140
|
-
/** MIME type of the video (e.g., 'video/mp4', 'video/webm') */
|
|
141
|
-
mimeType: string;
|
|
142
|
-
/** Duration in seconds */
|
|
143
|
-
duration?: number;
|
|
144
|
-
/** Video width in pixels */
|
|
145
|
-
width?: number;
|
|
146
|
-
/** Video height in pixels */
|
|
147
|
-
height?: number;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Binary content block for arbitrary data.
|
|
151
|
-
*
|
|
152
|
-
* A generic block type for data that doesn't fit other categories.
|
|
153
|
-
*
|
|
154
|
-
* @example
|
|
155
|
-
* ```typescript
|
|
156
|
-
* const binaryBlock: BinaryBlock = {
|
|
157
|
-
* type: 'binary',
|
|
158
|
-
* data: pdfBytes,
|
|
159
|
-
* mimeType: 'application/pdf',
|
|
160
|
-
* metadata: { filename: 'document.pdf', pages: 10 }
|
|
161
|
-
* };
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
interface BinaryBlock {
|
|
165
|
-
/** Discriminator for binary blocks */
|
|
166
|
-
type: 'binary';
|
|
167
|
-
/** Raw binary data */
|
|
168
|
-
data: Uint8Array;
|
|
169
|
-
/** MIME type of the data */
|
|
170
|
-
mimeType: string;
|
|
171
|
-
/** Additional metadata about the binary content */
|
|
172
|
-
metadata?: Record<string, unknown>;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Union of all content block types.
|
|
176
|
-
*
|
|
177
|
-
* Used when a function or property can accept any type of content block.
|
|
178
|
-
*/
|
|
179
|
-
type ContentBlock = TextBlock | ImageBlock | AudioBlock | VideoBlock | BinaryBlock;
|
|
180
|
-
/**
|
|
181
|
-
* Content types allowed in user messages.
|
|
182
|
-
*
|
|
183
|
-
* Users can send any type of content block including binary data.
|
|
184
|
-
*/
|
|
185
|
-
type UserContent = TextBlock | ImageBlock | AudioBlock | VideoBlock | BinaryBlock;
|
|
186
|
-
/**
|
|
187
|
-
* Content types allowed in assistant messages.
|
|
188
|
-
*
|
|
189
|
-
* Assistants can generate text and media but not arbitrary binary data.
|
|
190
|
-
*/
|
|
191
|
-
type AssistantContent = TextBlock | ImageBlock | AudioBlock | VideoBlock;
|
|
192
|
-
/**
|
|
193
|
-
* Creates a text content block from a string.
|
|
194
|
-
*
|
|
195
|
-
* @param content - The text content
|
|
196
|
-
* @returns A TextBlock containing the provided text
|
|
197
|
-
*
|
|
198
|
-
* @example
|
|
199
|
-
* ```typescript
|
|
200
|
-
* const block = text('Hello, world!');
|
|
201
|
-
* // { type: 'text', text: 'Hello, world!' }
|
|
202
|
-
* ```
|
|
203
|
-
*/
|
|
204
|
-
declare function text(content: string): TextBlock;
|
|
205
|
-
/**
|
|
206
|
-
* Type guard for TextBlock.
|
|
207
|
-
*
|
|
208
|
-
* @param block - The content block to check
|
|
209
|
-
* @returns True if the block is a TextBlock
|
|
210
|
-
*
|
|
211
|
-
* @example
|
|
212
|
-
* ```typescript
|
|
213
|
-
* if (isTextBlock(block)) {
|
|
214
|
-
* console.log(block.text);
|
|
215
|
-
* }
|
|
216
|
-
* ```
|
|
217
|
-
*/
|
|
218
|
-
declare function isTextBlock(block: ContentBlock): block is TextBlock;
|
|
219
|
-
/**
|
|
220
|
-
* Type guard for ImageBlock.
|
|
221
|
-
*
|
|
222
|
-
* @param block - The content block to check
|
|
223
|
-
* @returns True if the block is an ImageBlock
|
|
224
|
-
*
|
|
225
|
-
* @example
|
|
226
|
-
* ```typescript
|
|
227
|
-
* if (isImageBlock(block)) {
|
|
228
|
-
* console.log(block.mimeType, block.width, block.height);
|
|
229
|
-
* }
|
|
230
|
-
* ```
|
|
231
|
-
*/
|
|
232
|
-
declare function isImageBlock(block: ContentBlock): block is ImageBlock;
|
|
233
|
-
/**
|
|
234
|
-
* Type guard for AudioBlock.
|
|
235
|
-
*
|
|
236
|
-
* @param block - The content block to check
|
|
237
|
-
* @returns True if the block is an AudioBlock
|
|
238
|
-
*
|
|
239
|
-
* @example
|
|
240
|
-
* ```typescript
|
|
241
|
-
* if (isAudioBlock(block)) {
|
|
242
|
-
* console.log(block.mimeType, block.duration);
|
|
243
|
-
* }
|
|
244
|
-
* ```
|
|
245
|
-
*/
|
|
246
|
-
declare function isAudioBlock(block: ContentBlock): block is AudioBlock;
|
|
247
|
-
/**
|
|
248
|
-
* Type guard for VideoBlock.
|
|
249
|
-
*
|
|
250
|
-
* @param block - The content block to check
|
|
251
|
-
* @returns True if the block is a VideoBlock
|
|
252
|
-
*
|
|
253
|
-
* @example
|
|
254
|
-
* ```typescript
|
|
255
|
-
* if (isVideoBlock(block)) {
|
|
256
|
-
* console.log(block.mimeType, block.duration);
|
|
257
|
-
* }
|
|
258
|
-
* ```
|
|
259
|
-
*/
|
|
260
|
-
declare function isVideoBlock(block: ContentBlock): block is VideoBlock;
|
|
261
|
-
/**
|
|
262
|
-
* Type guard for BinaryBlock.
|
|
263
|
-
*
|
|
264
|
-
* @param block - The content block to check
|
|
265
|
-
* @returns True if the block is a BinaryBlock
|
|
266
|
-
*
|
|
267
|
-
* @example
|
|
268
|
-
* ```typescript
|
|
269
|
-
* if (isBinaryBlock(block)) {
|
|
270
|
-
* console.log(block.mimeType, block.metadata);
|
|
271
|
-
* }
|
|
272
|
-
* ```
|
|
273
|
-
*/
|
|
274
|
-
declare function isBinaryBlock(block: ContentBlock): block is BinaryBlock;
|
|
1
|
+
import { C as ContentBlock, I as ImageBlock, a as AudioBlock, V as VideoBlock, A as AssistantContent, U as UserContent } from './content-DEl3z_W2.js';
|
|
275
2
|
|
|
276
3
|
/**
|
|
277
4
|
* @fileoverview JSON Schema types for tool parameters and structured outputs.
|
|
@@ -1283,4 +1010,4 @@ declare function contentBlockStart(index: number): StreamEvent;
|
|
|
1283
1010
|
*/
|
|
1284
1011
|
declare function contentBlockStop(index: number): StreamEvent;
|
|
1285
1012
|
|
|
1286
|
-
export {
|
|
1013
|
+
export { AssistantMessage as A, type BeforeCallResult as B, messageStart as C, messageStop as D, type EventDelta as E, contentBlockStart as F, contentBlockStop as G, type TurnJSON as H, type JSONSchema as J, Message as M, type StreamResult as S, type Turn as T, UserMessage as U, type MessageType as a, type MessageJSON as b, type Tool as c, type ToolUseStrategy as d, type TokenUsage as e, type StreamEvent as f, type JSONSchemaProperty as g, type JSONSchemaPropertyType as h, type ToolCall as i, type ToolResult as j, type ToolMetadata as k, type AfterCallResult as l, type ToolExecution as m, ToolResultMessage as n, isUserMessage as o, isAssistantMessage as p, isToolResultMessage as q, type MessageMetadata as r, type MessageOptions as s, createTurn as t, emptyUsage as u, aggregateUsage as v, type StreamEventType as w, createStreamResult as x, textDelta as y, toolCallDelta as z };
|
package/dist/xai/index.d.ts
CHANGED
|
@@ -1,4 +1,31 @@
|
|
|
1
|
-
import { d as Provider, f as ModelReference, b as LLMHandler } from '../provider-
|
|
1
|
+
import { d as Provider, f as ModelReference, b as LLMHandler } from '../provider-BBMBZuGn.js';
|
|
2
|
+
import { n as ImageHandler } from '../image-Dhq-Yuq4.js';
|
|
3
|
+
import '../content-DEl3z_W2.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview xAI Image Generation API Handler
|
|
7
|
+
*
|
|
8
|
+
* This module implements the image handler for xAI's Image Generation API (Aurora).
|
|
9
|
+
* Supports the grok-2-image-1212 model.
|
|
10
|
+
*
|
|
11
|
+
* @see {@link https://docs.x.ai/docs/image-generation xAI Image Generation Reference}
|
|
12
|
+
* @module providers/xai/image
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* xAI image generation parameters.
|
|
17
|
+
* Passed through unchanged to the API.
|
|
18
|
+
*
|
|
19
|
+
* Note: xAI does NOT support negative_prompt or seed parameters.
|
|
20
|
+
*/
|
|
21
|
+
interface XAIImageParams {
|
|
22
|
+
/** Number of images to generate (1-10) */
|
|
23
|
+
n?: number;
|
|
24
|
+
/** Response format */
|
|
25
|
+
response_format?: 'url' | 'b64_json';
|
|
26
|
+
/** User identifier */
|
|
27
|
+
user?: string;
|
|
28
|
+
}
|
|
2
29
|
|
|
3
30
|
/**
|
|
4
31
|
* xAI Chat Completions API parameters (OpenAI-compatible).
|
|
@@ -660,6 +687,7 @@ interface XAIProvider extends Provider<XAIProviderOptions> {
|
|
|
660
687
|
/** Supported modalities */
|
|
661
688
|
readonly modalities: {
|
|
662
689
|
llm: LLMHandler<XAILLMParamsUnion>;
|
|
690
|
+
image: ImageHandler<XAIImageParams>;
|
|
663
691
|
};
|
|
664
692
|
}
|
|
665
693
|
/**
|
package/dist/xai/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Image
|
|
3
|
+
} from "../chunk-WAKD3OO5.js";
|
|
1
4
|
import {
|
|
2
5
|
AssistantMessage,
|
|
3
6
|
isAssistantMessage,
|
|
@@ -8,14 +11,14 @@ import {
|
|
|
8
11
|
parseSSEStream
|
|
9
12
|
} from "../chunk-Z7RBRCRN.js";
|
|
10
13
|
import {
|
|
11
|
-
doFetch,
|
|
12
|
-
doStreamFetch,
|
|
13
|
-
normalizeHttpError,
|
|
14
14
|
resolveApiKey
|
|
15
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-P5IRTEM5.js";
|
|
16
16
|
import {
|
|
17
|
-
UPPError
|
|
18
|
-
|
|
17
|
+
UPPError,
|
|
18
|
+
doFetch,
|
|
19
|
+
doStreamFetch,
|
|
20
|
+
normalizeHttpError
|
|
21
|
+
} from "../chunk-U3FZWV4U.js";
|
|
19
22
|
|
|
20
23
|
// src/providers/xai/transform.completions.ts
|
|
21
24
|
function transformRequest(request, modelId) {
|
|
@@ -1728,6 +1731,112 @@ function createMessagesLLMHandler() {
|
|
|
1728
1731
|
};
|
|
1729
1732
|
}
|
|
1730
1733
|
|
|
1734
|
+
// src/providers/xai/image.ts
|
|
1735
|
+
var XAI_IMAGES_API_URL = "https://api.x.ai/v1/images/generations";
|
|
1736
|
+
function getCapabilities(modelId) {
|
|
1737
|
+
return {
|
|
1738
|
+
generate: true,
|
|
1739
|
+
streaming: false,
|
|
1740
|
+
edit: false,
|
|
1741
|
+
maxImages: 10
|
|
1742
|
+
};
|
|
1743
|
+
}
|
|
1744
|
+
function createImageHandler() {
|
|
1745
|
+
let providerRef = null;
|
|
1746
|
+
return {
|
|
1747
|
+
_setProvider(provider) {
|
|
1748
|
+
providerRef = provider;
|
|
1749
|
+
},
|
|
1750
|
+
bind(modelId) {
|
|
1751
|
+
if (!providerRef) {
|
|
1752
|
+
throw new UPPError(
|
|
1753
|
+
"Provider reference not set. Handler must be used with createProvider().",
|
|
1754
|
+
"INVALID_REQUEST",
|
|
1755
|
+
"xai",
|
|
1756
|
+
"image"
|
|
1757
|
+
);
|
|
1758
|
+
}
|
|
1759
|
+
const capabilities = getCapabilities(modelId);
|
|
1760
|
+
const model = {
|
|
1761
|
+
modelId,
|
|
1762
|
+
capabilities,
|
|
1763
|
+
get provider() {
|
|
1764
|
+
return providerRef;
|
|
1765
|
+
},
|
|
1766
|
+
async generate(request) {
|
|
1767
|
+
return executeGenerate(modelId, request);
|
|
1768
|
+
}
|
|
1769
|
+
};
|
|
1770
|
+
return model;
|
|
1771
|
+
}
|
|
1772
|
+
};
|
|
1773
|
+
}
|
|
1774
|
+
async function executeGenerate(modelId, request) {
|
|
1775
|
+
const apiKey = await resolveApiKey(
|
|
1776
|
+
request.config,
|
|
1777
|
+
"XAI_API_KEY",
|
|
1778
|
+
"xai",
|
|
1779
|
+
"image"
|
|
1780
|
+
);
|
|
1781
|
+
const baseUrl = request.config.baseUrl ? `${request.config.baseUrl.replace(/\/$/, "")}/v1/images/generations` : XAI_IMAGES_API_URL;
|
|
1782
|
+
const body = {
|
|
1783
|
+
model: modelId,
|
|
1784
|
+
prompt: request.prompt
|
|
1785
|
+
};
|
|
1786
|
+
if (request.params) {
|
|
1787
|
+
const { n, response_format, user } = request.params;
|
|
1788
|
+
if (n !== void 0) body.n = n;
|
|
1789
|
+
if (response_format !== void 0) body.response_format = response_format;
|
|
1790
|
+
if (user !== void 0) body.user = user;
|
|
1791
|
+
}
|
|
1792
|
+
const headers = {
|
|
1793
|
+
"Content-Type": "application/json",
|
|
1794
|
+
Authorization: `Bearer ${apiKey}`
|
|
1795
|
+
};
|
|
1796
|
+
if (request.config.headers) {
|
|
1797
|
+
for (const [key, value] of Object.entries(request.config.headers)) {
|
|
1798
|
+
if (value !== void 0) {
|
|
1799
|
+
headers[key] = value;
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
const response = await doFetch(baseUrl, {
|
|
1804
|
+
method: "POST",
|
|
1805
|
+
headers,
|
|
1806
|
+
body: JSON.stringify(body),
|
|
1807
|
+
signal: request.signal
|
|
1808
|
+
}, request.config, "xai", "image");
|
|
1809
|
+
const data = await response.json();
|
|
1810
|
+
return transformResponse4(data);
|
|
1811
|
+
}
|
|
1812
|
+
function transformResponse4(data) {
|
|
1813
|
+
const images = data.data.map((item) => {
|
|
1814
|
+
let image;
|
|
1815
|
+
if (item.b64_json) {
|
|
1816
|
+
image = Image.fromBase64(item.b64_json, "image/jpeg");
|
|
1817
|
+
} else if (item.url) {
|
|
1818
|
+
image = Image.fromUrl(item.url, "image/jpeg");
|
|
1819
|
+
} else {
|
|
1820
|
+
throw new UPPError(
|
|
1821
|
+
"No image data in response",
|
|
1822
|
+
"PROVIDER_ERROR",
|
|
1823
|
+
"xai",
|
|
1824
|
+
"image"
|
|
1825
|
+
);
|
|
1826
|
+
}
|
|
1827
|
+
return {
|
|
1828
|
+
image,
|
|
1829
|
+
metadata: item.revised_prompt ? { revised_prompt: item.revised_prompt } : void 0
|
|
1830
|
+
};
|
|
1831
|
+
});
|
|
1832
|
+
return {
|
|
1833
|
+
images,
|
|
1834
|
+
usage: {
|
|
1835
|
+
imagesGenerated: images.length
|
|
1836
|
+
}
|
|
1837
|
+
};
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1731
1840
|
// src/providers/xai/types.ts
|
|
1732
1841
|
function webSearchTool(options) {
|
|
1733
1842
|
return {
|
|
@@ -1780,6 +1889,7 @@ function createXAIProvider() {
|
|
|
1780
1889
|
const completionsHandler = createCompletionsLLMHandler();
|
|
1781
1890
|
const responsesHandler = createResponsesLLMHandler();
|
|
1782
1891
|
const messagesHandler = createMessagesLLMHandler();
|
|
1892
|
+
const imageHandler = createImageHandler();
|
|
1783
1893
|
const fn = function(modelId, options) {
|
|
1784
1894
|
const apiMode = options?.api ?? "completions";
|
|
1785
1895
|
currentApiMode = apiMode;
|
|
@@ -1796,7 +1906,8 @@ function createXAIProvider() {
|
|
|
1796
1906
|
default:
|
|
1797
1907
|
return completionsHandler;
|
|
1798
1908
|
}
|
|
1799
|
-
}
|
|
1909
|
+
},
|
|
1910
|
+
image: imageHandler
|
|
1800
1911
|
};
|
|
1801
1912
|
Object.defineProperties(fn, {
|
|
1802
1913
|
name: {
|
|
@@ -1819,6 +1930,7 @@ function createXAIProvider() {
|
|
|
1819
1930
|
completionsHandler._setProvider?.(provider);
|
|
1820
1931
|
responsesHandler._setProvider?.(provider);
|
|
1821
1932
|
messagesHandler._setProvider?.(provider);
|
|
1933
|
+
imageHandler._setProvider?.(provider);
|
|
1822
1934
|
return provider;
|
|
1823
1935
|
}
|
|
1824
1936
|
var xai = createXAIProvider();
|