@ai-sdk/fireworks 3.0.0-beta.6 → 3.0.0-beta.60

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.
@@ -20,11 +20,17 @@ export type FireworksChatModelId =
20
20
  | 'accounts/fireworks/models/yi-large'
21
21
  | 'accounts/fireworks/models/kimi-k2-instruct'
22
22
  | 'accounts/fireworks/models/kimi-k2-thinking'
23
- | 'accounts/fireworks/models/kimi-k2p5'
23
+ | 'accounts/fireworks/models/kimi-k2p6'
24
24
  | 'accounts/fireworks/models/minimax-m2'
25
25
  | (string & {});
26
26
 
27
27
  export const fireworksLanguageModelOptions = z.object({
28
+ /**
29
+ * A stable key for routing requests with shared prompt prefixes to the same
30
+ * prompt cache.
31
+ */
32
+ promptCacheKey: z.string().optional(),
33
+
28
34
  thinking: z
29
35
  .object({
30
36
  type: z.enum(['enabled', 'disabled']).optional(),
@@ -1,4 +1,4 @@
1
- import { ImageModelV4, SharedV4Warning } from '@ai-sdk/provider';
1
+ import type { ImageModelV4, SharedV4Warning } from '@ai-sdk/provider';
2
2
  import {
3
3
  combineHeaders,
4
4
  convertImageModelFileToDataUri,
@@ -6,15 +6,19 @@ import {
6
6
  createJsonResponseHandler,
7
7
  createStatusCodeErrorResponseHandler,
8
8
  delay,
9
- FetchFunction,
10
9
  getFromApi,
10
+ isSameOrigin,
11
11
  postJsonToApi,
12
+ serializeModelOptions,
13
+ WORKFLOW_SERIALIZE,
14
+ WORKFLOW_DESERIALIZE,
15
+ type FetchFunction,
12
16
  } from '@ai-sdk/provider-utils';
13
17
  import {
14
18
  asyncPollResponseSchema,
15
19
  asyncSubmitResponseSchema,
16
20
  } from './fireworks-image-api';
17
- import { FireworksImageModelId } from './fireworks-image-options';
21
+ import type { FireworksImageModelId } from './fireworks-image-options';
18
22
 
19
23
  const DEFAULT_POLL_INTERVAL_MILLIS = 500;
20
24
  const DEFAULT_POLL_TIMEOUT_MILLIS = 120000; // 2 minutes for image generation
@@ -91,7 +95,7 @@ function getPollUrlForModel(
91
95
  interface FireworksImageModelConfig {
92
96
  provider: string;
93
97
  baseURL: string;
94
- headers: () => Record<string, string>;
98
+ headers?: () => Record<string, string>;
95
99
  fetch?: FetchFunction;
96
100
  /**
97
101
  * Poll interval in milliseconds between status checks for async models.
@@ -116,6 +120,20 @@ export class FireworksImageModel implements ImageModelV4 {
116
120
  return this.config.provider;
117
121
  }
118
122
 
123
+ static [WORKFLOW_SERIALIZE](model: FireworksImageModel) {
124
+ return serializeModelOptions({
125
+ modelId: model.modelId,
126
+ config: model.config,
127
+ });
128
+ }
129
+
130
+ static [WORKFLOW_DESERIALIZE](options: {
131
+ modelId: FireworksImageModelId;
132
+ config: FireworksImageModelConfig;
133
+ }) {
134
+ return new FireworksImageModel(options.modelId, options.config);
135
+ }
136
+
119
137
  constructor(
120
138
  readonly modelId: FireworksImageModelId,
121
139
  private config: FireworksImageModelConfig,
@@ -185,7 +203,7 @@ export class FireworksImageModel implements ImageModelV4 {
185
203
 
186
204
  const splitSize = size?.split('x');
187
205
  const currentDate = this.config._internal?.currentDate?.() ?? new Date();
188
- const combinedHeaders = combineHeaders(this.config.headers(), headers);
206
+ const combinedHeaders = combineHeaders(this.config.headers?.(), headers);
189
207
 
190
208
  const body = {
191
209
  prompt,
@@ -269,10 +287,15 @@ export class FireworksImageModel implements ImageModelV4 {
269
287
  abortSignal,
270
288
  });
271
289
 
272
- // Download the image from the URL
290
+ // Download the image from the URL. The URL comes from the provider
291
+ // response and typically points at a CDN, so only send credentials when it
292
+ // stays on the provider's own origin (never leak the API key to a CDN or an
293
+ // attacker-named host).
273
294
  const { value: imageBytes, responseHeaders } = await getFromApi({
274
295
  url: imageUrl,
275
- headers,
296
+ headers: isSameOrigin(imageUrl, this.config.baseURL)
297
+ ? headers
298
+ : undefined,
276
299
  abortSignal,
277
300
  failedResponseHandler: createStatusCodeErrorResponseHandler(),
278
301
  successfulResponseHandler: createBinaryResponseHandler(),
@@ -2,26 +2,26 @@ import {
2
2
  OpenAICompatibleChatLanguageModel,
3
3
  OpenAICompatibleCompletionLanguageModel,
4
4
  OpenAICompatibleEmbeddingModel,
5
- ProviderErrorStructure,
5
+ type ProviderErrorStructure,
6
6
  } from '@ai-sdk/openai-compatible';
7
- import {
7
+ import type {
8
8
  EmbeddingModelV4,
9
9
  ImageModelV4,
10
10
  LanguageModelV4,
11
11
  ProviderV4,
12
12
  } from '@ai-sdk/provider';
13
13
  import {
14
- FetchFunction,
15
14
  loadApiKey,
16
15
  withoutTrailingSlash,
17
16
  withUserAgentSuffix,
17
+ type FetchFunction,
18
18
  } from '@ai-sdk/provider-utils';
19
19
  import { z } from 'zod/v4';
20
- import { FireworksChatModelId } from './fireworks-chat-options';
21
- import { FireworksCompletionModelId } from './fireworks-completion-options';
22
- import { FireworksEmbeddingModelId } from './fireworks-embedding-options';
20
+ import type { FireworksChatModelId } from './fireworks-chat-options';
21
+ import type { FireworksCompletionModelId } from './fireworks-completion-options';
22
+ import type { FireworksEmbeddingModelId } from './fireworks-embedding-options';
23
23
  import { FireworksImageModel } from './fireworks-image-model';
24
- import { FireworksImageModelId } from './fireworks-image-options';
24
+ import type { FireworksImageModelId } from './fireworks-image-options';
25
25
  import { VERSION } from './version';
26
26
 
27
27
  export type FireworksErrorData = z.infer<typeof fireworksErrorSchema>;
@@ -134,17 +134,37 @@ export function createFireworks(
134
134
  const createChatModel = (modelId: FireworksChatModelId) => {
135
135
  return new OpenAICompatibleChatLanguageModel(modelId, {
136
136
  ...getCommonModelConfig('chat'),
137
+ includeUsage: true,
137
138
  errorStructure: fireworksErrorStructure,
138
139
  transformRequestBody: args => {
139
140
  const thinking = args.thinking as
140
141
  | { type?: string; budgetTokens?: number }
141
142
  | undefined;
142
143
  const reasoningHistory = args.reasoningHistory as string | undefined;
144
+ const promptCacheKey = args.promptCacheKey as string | undefined;
143
145
 
144
- const { thinking: _, reasoningHistory: __, ...rest } = args;
146
+ const {
147
+ thinking: _,
148
+ reasoningHistory: __,
149
+ promptCacheKey: ___,
150
+ reasoning_effort,
151
+ ...rest
152
+ } = args;
145
153
 
146
154
  return {
147
155
  ...rest,
156
+ ...(reasoning_effort != null && {
157
+ // Workaround since OpenAI spec allows for 5 reasoning levels, but Fireworks only supports 3 of them.
158
+ reasoning_effort:
159
+ reasoning_effort === 'minimal'
160
+ ? 'low'
161
+ : reasoning_effort === 'xhigh'
162
+ ? 'high'
163
+ : reasoning_effort,
164
+ }),
165
+ ...(promptCacheKey !== undefined && {
166
+ prompt_cache_key: promptCacheKey,
167
+ }),
148
168
  ...(thinking && {
149
169
  thinking: {
150
170
  type: thinking.type,
@@ -164,6 +184,7 @@ export function createFireworks(
164
184
  const createCompletionModel = (modelId: FireworksCompletionModelId) =>
165
185
  new OpenAICompatibleCompletionLanguageModel(modelId, {
166
186
  ...getCommonModelConfig('completion'),
187
+ includeUsage: true,
167
188
  errorStructure: fireworksErrorStructure,
168
189
  });
169
190
 
package/dist/index.d.mts DELETED
@@ -1,131 +0,0 @@
1
- import { z } from 'zod/v4';
2
- import { ImageModelV4, ProviderV4, LanguageModelV4, EmbeddingModelV4 } from '@ai-sdk/provider';
3
- import { FetchFunction } from '@ai-sdk/provider-utils';
4
-
5
- type FireworksChatModelId = 'accounts/fireworks/models/deepseek-v3' | 'accounts/fireworks/models/llama-v3p3-70b-instruct' | 'accounts/fireworks/models/llama-v3p2-3b-instruct' | 'accounts/fireworks/models/llama-v3p1-405b-instruct' | 'accounts/fireworks/models/llama-v3p1-8b-instruct' | 'accounts/fireworks/models/mixtral-8x7b-instruct' | 'accounts/fireworks/models/mixtral-8x22b-instruct' | 'accounts/fireworks/models/mixtral-8x7b-instruct-hf' | 'accounts/fireworks/models/qwen2p5-coder-32b-instruct' | 'accounts/fireworks/models/qwen2p5-72b-instruct' | 'accounts/fireworks/models/qwen-qwq-32b-preview' | 'accounts/fireworks/models/qwen2-vl-72b-instruct' | 'accounts/fireworks/models/llama-v3p2-11b-vision-instruct' | 'accounts/fireworks/models/qwq-32b' | 'accounts/fireworks/models/yi-large' | 'accounts/fireworks/models/kimi-k2-instruct' | 'accounts/fireworks/models/kimi-k2-thinking' | 'accounts/fireworks/models/kimi-k2p5' | 'accounts/fireworks/models/minimax-m2' | (string & {});
6
- declare const fireworksLanguageModelOptions: z.ZodObject<{
7
- thinking: z.ZodOptional<z.ZodObject<{
8
- type: z.ZodOptional<z.ZodEnum<{
9
- enabled: "enabled";
10
- disabled: "disabled";
11
- }>>;
12
- budgetTokens: z.ZodOptional<z.ZodNumber>;
13
- }, z.core.$strip>>;
14
- reasoningHistory: z.ZodOptional<z.ZodEnum<{
15
- disabled: "disabled";
16
- interleaved: "interleaved";
17
- preserved: "preserved";
18
- }>>;
19
- }, z.core.$strip>;
20
- type FireworksLanguageModelOptions = z.infer<typeof fireworksLanguageModelOptions>;
21
-
22
- type FireworksEmbeddingModelId = 'nomic-ai/nomic-embed-text-v1.5' | (string & {});
23
- declare const fireworksEmbeddingModelOptions: z.ZodObject<{}, z.core.$strip>;
24
- type FireworksEmbeddingModelOptions = z.infer<typeof fireworksEmbeddingModelOptions>;
25
-
26
- type FireworksImageModelId = 'accounts/fireworks/models/flux-1-dev-fp8' | 'accounts/fireworks/models/flux-1-schnell-fp8' | 'accounts/fireworks/models/flux-kontext-pro' | 'accounts/fireworks/models/flux-kontext-max' | 'accounts/fireworks/models/playground-v2-5-1024px-aesthetic' | 'accounts/fireworks/models/japanese-stable-diffusion-xl' | 'accounts/fireworks/models/playground-v2-1024px-aesthetic' | 'accounts/fireworks/models/SSD-1B' | 'accounts/fireworks/models/stable-diffusion-xl-1024-v1-0' | (string & {});
27
-
28
- interface FireworksImageModelConfig {
29
- provider: string;
30
- baseURL: string;
31
- headers: () => Record<string, string>;
32
- fetch?: FetchFunction;
33
- /**
34
- * Poll interval in milliseconds between status checks for async models.
35
- * Defaults to 500ms.
36
- */
37
- pollIntervalMillis?: number;
38
- /**
39
- * Overall timeout in milliseconds for polling before giving up.
40
- * Defaults to 120000ms (2 minutes).
41
- */
42
- pollTimeoutMillis?: number;
43
- _internal?: {
44
- currentDate?: () => Date;
45
- };
46
- }
47
- declare class FireworksImageModel implements ImageModelV4 {
48
- readonly modelId: FireworksImageModelId;
49
- private config;
50
- readonly specificationVersion = "v4";
51
- readonly maxImagesPerCall = 1;
52
- get provider(): string;
53
- constructor(modelId: FireworksImageModelId, config: FireworksImageModelConfig);
54
- doGenerate({ prompt, n, size, aspectRatio, seed, providerOptions, headers, abortSignal, files, mask, }: Parameters<ImageModelV4['doGenerate']>[0]): Promise<Awaited<ReturnType<ImageModelV4['doGenerate']>>>;
55
- /**
56
- * Handles async image generation for models like flux-kontext-* that return
57
- * a request_id and require polling for results.
58
- */
59
- private doGenerateAsync;
60
- /**
61
- * Polls the get_result endpoint until the image is ready.
62
- */
63
- private pollForImageUrl;
64
- }
65
-
66
- type FireworksCompletionModelId = 'accounts/fireworks/models/llama-v3-8b-instruct' | 'accounts/fireworks/models/llama-v2-34b-code' | (string & {});
67
-
68
- type FireworksErrorData = z.infer<typeof fireworksErrorSchema>;
69
- declare const fireworksErrorSchema: z.ZodObject<{
70
- error: z.ZodString;
71
- }, z.core.$strip>;
72
- interface FireworksProviderSettings {
73
- /**
74
- * Fireworks API key. Default value is taken from the `FIREWORKS_API_KEY`
75
- * environment variable.
76
- */
77
- apiKey?: string;
78
- /**
79
- * Base URL for the API calls.
80
- */
81
- baseURL?: string;
82
- /**
83
- * Custom headers to include in the requests.
84
- */
85
- headers?: Record<string, string>;
86
- /**
87
- * Custom fetch implementation. You can use it as a middleware to intercept requests,
88
- * or to provide a custom fetch implementation for e.g. testing.
89
- */
90
- fetch?: FetchFunction;
91
- }
92
- interface FireworksProvider extends ProviderV4 {
93
- /**
94
- * Creates a model for text generation.
95
- */
96
- (modelId: FireworksChatModelId): LanguageModelV4;
97
- /**
98
- * Creates a chat model for text generation.
99
- */
100
- chatModel(modelId: FireworksChatModelId): LanguageModelV4;
101
- /**
102
- * Creates a completion model for text generation.
103
- */
104
- completionModel(modelId: FireworksCompletionModelId): LanguageModelV4;
105
- /**
106
- * Creates a chat model for text generation.
107
- */
108
- languageModel(modelId: FireworksChatModelId): LanguageModelV4;
109
- /**
110
- * Creates a text embedding model for text generation.
111
- */
112
- embeddingModel(modelId: FireworksEmbeddingModelId): EmbeddingModelV4;
113
- /**
114
- * @deprecated Use `embeddingModel` instead.
115
- */
116
- textEmbeddingModel(modelId: FireworksEmbeddingModelId): EmbeddingModelV4;
117
- /**
118
- * Creates a model for image generation.
119
- */
120
- image(modelId: FireworksImageModelId): ImageModelV4;
121
- /**
122
- * Creates a model for image generation.
123
- */
124
- imageModel(modelId: FireworksImageModelId): ImageModelV4;
125
- }
126
- declare function createFireworks(options?: FireworksProviderSettings): FireworksProvider;
127
- declare const fireworks: FireworksProvider;
128
-
129
- declare const VERSION: string;
130
-
131
- export { type FireworksEmbeddingModelId, type FireworksEmbeddingModelOptions, type FireworksEmbeddingModelOptions as FireworksEmbeddingProviderOptions, type FireworksErrorData, FireworksImageModel, type FireworksImageModelId, type FireworksLanguageModelOptions, type FireworksProvider, type FireworksLanguageModelOptions as FireworksProviderOptions, type FireworksProviderSettings, VERSION, createFireworks, fireworks };
package/dist/index.mjs DELETED
@@ -1,382 +0,0 @@
1
- // src/fireworks-image-model.ts
2
- import {
3
- combineHeaders,
4
- convertImageModelFileToDataUri,
5
- createBinaryResponseHandler,
6
- createJsonResponseHandler,
7
- createStatusCodeErrorResponseHandler,
8
- delay,
9
- getFromApi,
10
- postJsonToApi
11
- } from "@ai-sdk/provider-utils";
12
-
13
- // src/fireworks-image-api.ts
14
- import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
15
- import { z } from "zod/v4";
16
- var asyncSubmitResponseSchema = lazySchema(
17
- () => zodSchema(
18
- z.object({
19
- request_id: z.string()
20
- })
21
- )
22
- );
23
- var asyncPollResponseSchema = lazySchema(
24
- () => zodSchema(
25
- z.object({
26
- id: z.string(),
27
- status: z.string(),
28
- result: z.object({
29
- sample: z.string().optional()
30
- }).nullable()
31
- })
32
- )
33
- );
34
-
35
- // src/fireworks-image-model.ts
36
- var DEFAULT_POLL_INTERVAL_MILLIS = 500;
37
- var DEFAULT_POLL_TIMEOUT_MILLIS = 12e4;
38
- var modelToBackendConfig = {
39
- "accounts/fireworks/models/flux-1-dev-fp8": {
40
- urlFormat: "workflows"
41
- },
42
- "accounts/fireworks/models/flux-1-schnell-fp8": {
43
- urlFormat: "workflows"
44
- },
45
- "accounts/fireworks/models/flux-kontext-pro": {
46
- urlFormat: "workflows_async",
47
- supportsEditing: true
48
- },
49
- "accounts/fireworks/models/flux-kontext-max": {
50
- urlFormat: "workflows_async",
51
- supportsEditing: true
52
- },
53
- "accounts/fireworks/models/playground-v2-5-1024px-aesthetic": {
54
- urlFormat: "image_generation",
55
- supportsSize: true
56
- },
57
- "accounts/fireworks/models/japanese-stable-diffusion-xl": {
58
- urlFormat: "image_generation",
59
- supportsSize: true
60
- },
61
- "accounts/fireworks/models/playground-v2-1024px-aesthetic": {
62
- urlFormat: "image_generation",
63
- supportsSize: true
64
- },
65
- "accounts/fireworks/models/stable-diffusion-xl-1024-v1-0": {
66
- urlFormat: "image_generation",
67
- supportsSize: true
68
- },
69
- "accounts/fireworks/models/SSD-1B": {
70
- urlFormat: "image_generation",
71
- supportsSize: true
72
- }
73
- };
74
- function getUrlForModel(baseUrl, modelId) {
75
- const config = modelToBackendConfig[modelId];
76
- switch (config == null ? void 0 : config.urlFormat) {
77
- case "image_generation":
78
- return `${baseUrl}/image_generation/${modelId}`;
79
- case "workflows_async":
80
- return `${baseUrl}/workflows/${modelId}`;
81
- case "workflows":
82
- default:
83
- return `${baseUrl}/workflows/${modelId}/text_to_image`;
84
- }
85
- }
86
- function getPollUrlForModel(baseUrl, modelId) {
87
- return `${baseUrl}/workflows/${modelId}/get_result`;
88
- }
89
- var FireworksImageModel = class {
90
- constructor(modelId, config) {
91
- this.modelId = modelId;
92
- this.config = config;
93
- this.specificationVersion = "v4";
94
- this.maxImagesPerCall = 1;
95
- }
96
- get provider() {
97
- return this.config.provider;
98
- }
99
- async doGenerate({
100
- prompt,
101
- n,
102
- size,
103
- aspectRatio,
104
- seed,
105
- providerOptions,
106
- headers,
107
- abortSignal,
108
- files,
109
- mask
110
- }) {
111
- var _a, _b, _c, _d;
112
- const warnings = [];
113
- const backendConfig = modelToBackendConfig[this.modelId];
114
- if (!(backendConfig == null ? void 0 : backendConfig.supportsSize) && size != null) {
115
- warnings.push({
116
- type: "unsupported",
117
- feature: "size",
118
- details: "This model does not support the `size` option. Use `aspectRatio` instead."
119
- });
120
- }
121
- if ((backendConfig == null ? void 0 : backendConfig.supportsSize) && aspectRatio != null) {
122
- warnings.push({
123
- type: "unsupported",
124
- feature: "aspectRatio",
125
- details: "This model does not support the `aspectRatio` option."
126
- });
127
- }
128
- const hasInputImage = files != null && files.length > 0;
129
- let inputImage;
130
- if (hasInputImage) {
131
- inputImage = convertImageModelFileToDataUri(files[0]);
132
- if (files.length > 1) {
133
- warnings.push({
134
- type: "other",
135
- message: "Fireworks only supports a single input image. Additional images are ignored."
136
- });
137
- }
138
- }
139
- if (mask != null) {
140
- warnings.push({
141
- type: "unsupported",
142
- feature: "mask",
143
- details: "Fireworks Kontext models do not support explicit masks. Use the prompt to describe the areas to edit."
144
- });
145
- }
146
- const splitSize = size == null ? void 0 : size.split("x");
147
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
148
- const combinedHeaders = combineHeaders(this.config.headers(), headers);
149
- const body = {
150
- prompt,
151
- aspect_ratio: aspectRatio,
152
- seed,
153
- samples: n,
154
- ...inputImage && { input_image: inputImage },
155
- ...splitSize && { width: splitSize[0], height: splitSize[1] },
156
- ...(_d = providerOptions.fireworks) != null ? _d : {}
157
- };
158
- if ((backendConfig == null ? void 0 : backendConfig.urlFormat) === "workflows_async") {
159
- return this.doGenerateAsync({
160
- body,
161
- headers: combinedHeaders,
162
- abortSignal,
163
- warnings,
164
- currentDate
165
- });
166
- }
167
- const { value: response, responseHeaders } = await postJsonToApi({
168
- url: getUrlForModel(this.config.baseURL, this.modelId),
169
- headers: combinedHeaders,
170
- body,
171
- failedResponseHandler: createStatusCodeErrorResponseHandler(),
172
- successfulResponseHandler: createBinaryResponseHandler(),
173
- abortSignal,
174
- fetch: this.config.fetch
175
- });
176
- return {
177
- images: [response],
178
- warnings,
179
- response: {
180
- timestamp: currentDate,
181
- modelId: this.modelId,
182
- headers: responseHeaders
183
- }
184
- };
185
- }
186
- /**
187
- * Handles async image generation for models like flux-kontext-* that return
188
- * a request_id and require polling for results.
189
- */
190
- async doGenerateAsync({
191
- body,
192
- headers,
193
- abortSignal,
194
- warnings,
195
- currentDate
196
- }) {
197
- const { value: submitResponse } = await postJsonToApi({
198
- url: getUrlForModel(this.config.baseURL, this.modelId),
199
- headers,
200
- body,
201
- failedResponseHandler: createStatusCodeErrorResponseHandler(),
202
- successfulResponseHandler: createJsonResponseHandler(
203
- asyncSubmitResponseSchema
204
- ),
205
- abortSignal,
206
- fetch: this.config.fetch
207
- });
208
- const requestId = submitResponse.request_id;
209
- const imageUrl = await this.pollForImageUrl({
210
- requestId,
211
- headers,
212
- abortSignal
213
- });
214
- const { value: imageBytes, responseHeaders } = await getFromApi({
215
- url: imageUrl,
216
- headers,
217
- abortSignal,
218
- failedResponseHandler: createStatusCodeErrorResponseHandler(),
219
- successfulResponseHandler: createBinaryResponseHandler(),
220
- fetch: this.config.fetch
221
- });
222
- return {
223
- images: [imageBytes],
224
- warnings,
225
- response: {
226
- timestamp: currentDate,
227
- modelId: this.modelId,
228
- headers: responseHeaders
229
- }
230
- };
231
- }
232
- /**
233
- * Polls the get_result endpoint until the image is ready.
234
- */
235
- async pollForImageUrl({
236
- requestId,
237
- headers,
238
- abortSignal
239
- }) {
240
- var _a, _b, _c;
241
- const pollIntervalMillis = (_a = this.config.pollIntervalMillis) != null ? _a : DEFAULT_POLL_INTERVAL_MILLIS;
242
- const pollTimeoutMillis = (_b = this.config.pollTimeoutMillis) != null ? _b : DEFAULT_POLL_TIMEOUT_MILLIS;
243
- const maxPollAttempts = Math.ceil(
244
- pollTimeoutMillis / Math.max(1, pollIntervalMillis)
245
- );
246
- const pollUrl = getPollUrlForModel(this.config.baseURL, this.modelId);
247
- for (let i = 0; i < maxPollAttempts; i++) {
248
- const { value: pollResponse } = await postJsonToApi({
249
- url: pollUrl,
250
- headers,
251
- body: { id: requestId },
252
- failedResponseHandler: createStatusCodeErrorResponseHandler(),
253
- successfulResponseHandler: createJsonResponseHandler(
254
- asyncPollResponseSchema
255
- ),
256
- abortSignal,
257
- fetch: this.config.fetch
258
- });
259
- const status = pollResponse.status;
260
- if (status === "Ready") {
261
- const imageUrl = (_c = pollResponse.result) == null ? void 0 : _c.sample;
262
- if (typeof imageUrl === "string") {
263
- return imageUrl;
264
- }
265
- throw new Error(
266
- "Fireworks poll response is Ready but missing result.sample"
267
- );
268
- }
269
- if (status === "Error" || status === "Failed") {
270
- throw new Error(
271
- `Fireworks image generation failed with status: ${status}`
272
- );
273
- }
274
- await delay(pollIntervalMillis);
275
- }
276
- throw new Error(
277
- `Fireworks image generation timed out after ${pollTimeoutMillis}ms`
278
- );
279
- }
280
- };
281
-
282
- // src/fireworks-provider.ts
283
- import {
284
- OpenAICompatibleChatLanguageModel,
285
- OpenAICompatibleCompletionLanguageModel,
286
- OpenAICompatibleEmbeddingModel
287
- } from "@ai-sdk/openai-compatible";
288
- import {
289
- loadApiKey,
290
- withoutTrailingSlash,
291
- withUserAgentSuffix
292
- } from "@ai-sdk/provider-utils";
293
- import { z as z2 } from "zod/v4";
294
-
295
- // src/version.ts
296
- var VERSION = true ? "3.0.0-beta.6" : "0.0.0-test";
297
-
298
- // src/fireworks-provider.ts
299
- var fireworksErrorSchema = z2.object({
300
- error: z2.string()
301
- });
302
- var fireworksErrorStructure = {
303
- errorSchema: fireworksErrorSchema,
304
- errorToMessage: (data) => data.error
305
- };
306
- var defaultBaseURL = "https://api.fireworks.ai/inference/v1";
307
- function createFireworks(options = {}) {
308
- var _a;
309
- const baseURL = withoutTrailingSlash((_a = options.baseURL) != null ? _a : defaultBaseURL);
310
- const getHeaders = () => withUserAgentSuffix(
311
- {
312
- Authorization: `Bearer ${loadApiKey({
313
- apiKey: options.apiKey,
314
- environmentVariableName: "FIREWORKS_API_KEY",
315
- description: "Fireworks API key"
316
- })}`,
317
- ...options.headers
318
- },
319
- `ai-sdk/fireworks/${VERSION}`
320
- );
321
- const getCommonModelConfig = (modelType) => ({
322
- provider: `fireworks.${modelType}`,
323
- url: ({ path }) => `${baseURL}${path}`,
324
- headers: getHeaders,
325
- fetch: options.fetch
326
- });
327
- const createChatModel = (modelId) => {
328
- return new OpenAICompatibleChatLanguageModel(modelId, {
329
- ...getCommonModelConfig("chat"),
330
- errorStructure: fireworksErrorStructure,
331
- transformRequestBody: (args) => {
332
- const thinking = args.thinking;
333
- const reasoningHistory = args.reasoningHistory;
334
- const { thinking: _, reasoningHistory: __, ...rest } = args;
335
- return {
336
- ...rest,
337
- ...thinking && {
338
- thinking: {
339
- type: thinking.type,
340
- ...thinking.budgetTokens !== void 0 && {
341
- budget_tokens: thinking.budgetTokens
342
- }
343
- }
344
- },
345
- ...reasoningHistory && {
346
- reasoning_history: reasoningHistory
347
- }
348
- };
349
- }
350
- });
351
- };
352
- const createCompletionModel = (modelId) => new OpenAICompatibleCompletionLanguageModel(modelId, {
353
- ...getCommonModelConfig("completion"),
354
- errorStructure: fireworksErrorStructure
355
- });
356
- const createEmbeddingModel = (modelId) => new OpenAICompatibleEmbeddingModel(modelId, {
357
- ...getCommonModelConfig("embedding"),
358
- errorStructure: fireworksErrorStructure
359
- });
360
- const createImageModel = (modelId) => new FireworksImageModel(modelId, {
361
- ...getCommonModelConfig("image"),
362
- baseURL: baseURL != null ? baseURL : defaultBaseURL
363
- });
364
- const provider = (modelId) => createChatModel(modelId);
365
- provider.specificationVersion = "v4";
366
- provider.completionModel = createCompletionModel;
367
- provider.chatModel = createChatModel;
368
- provider.languageModel = createChatModel;
369
- provider.embeddingModel = createEmbeddingModel;
370
- provider.textEmbeddingModel = createEmbeddingModel;
371
- provider.image = createImageModel;
372
- provider.imageModel = createImageModel;
373
- return provider;
374
- }
375
- var fireworks = createFireworks();
376
- export {
377
- FireworksImageModel,
378
- VERSION,
379
- createFireworks,
380
- fireworks
381
- };
382
- //# sourceMappingURL=index.mjs.map