@ai-sdk/fireworks 3.0.0-beta.5 → 3.0.0-beta.58
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/CHANGELOG.md +488 -8
- package/README.md +2 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +89 -78
- package/dist/index.js.map +1 -1
- package/docs/26-fireworks.mdx +0 -2
- package/package.json +15 -15
- package/src/fireworks-image-model.ts +30 -7
- package/src/fireworks-provider.ts +24 -8
- package/dist/index.d.mts +0 -131
- package/dist/index.mjs +0 -382
- package/dist/index.mjs.map +0 -1
|
@@ -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,6 +134,7 @@ 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
|
|
@@ -141,10 +142,24 @@ export function createFireworks(
|
|
|
141
142
|
| undefined;
|
|
142
143
|
const reasoningHistory = args.reasoningHistory as string | undefined;
|
|
143
144
|
|
|
144
|
-
const {
|
|
145
|
+
const {
|
|
146
|
+
thinking: _,
|
|
147
|
+
reasoningHistory: __,
|
|
148
|
+
reasoning_effort,
|
|
149
|
+
...rest
|
|
150
|
+
} = args;
|
|
145
151
|
|
|
146
152
|
return {
|
|
147
153
|
...rest,
|
|
154
|
+
...(reasoning_effort != null && {
|
|
155
|
+
// Workaround since OpenAI spec allows for 5 reasoning levels, but Fireworks only supports 3 of them.
|
|
156
|
+
reasoning_effort:
|
|
157
|
+
reasoning_effort === 'minimal'
|
|
158
|
+
? 'low'
|
|
159
|
+
: reasoning_effort === 'xhigh'
|
|
160
|
+
? 'high'
|
|
161
|
+
: reasoning_effort,
|
|
162
|
+
}),
|
|
148
163
|
...(thinking && {
|
|
149
164
|
thinking: {
|
|
150
165
|
type: thinking.type,
|
|
@@ -164,6 +179,7 @@ export function createFireworks(
|
|
|
164
179
|
const createCompletionModel = (modelId: FireworksCompletionModelId) =>
|
|
165
180
|
new OpenAICompatibleCompletionLanguageModel(modelId, {
|
|
166
181
|
...getCommonModelConfig('completion'),
|
|
182
|
+
includeUsage: true,
|
|
167
183
|
errorStructure: fireworksErrorStructure,
|
|
168
184
|
});
|
|
169
185
|
|
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.5" : "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
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/fireworks-image-model.ts","../src/fireworks-image-api.ts","../src/fireworks-provider.ts","../src/version.ts"],"sourcesContent":["import { ImageModelV4, SharedV4Warning } from '@ai-sdk/provider';\nimport {\n combineHeaders,\n convertImageModelFileToDataUri,\n createBinaryResponseHandler,\n createJsonResponseHandler,\n createStatusCodeErrorResponseHandler,\n delay,\n FetchFunction,\n getFromApi,\n postJsonToApi,\n} from '@ai-sdk/provider-utils';\nimport {\n asyncPollResponseSchema,\n asyncSubmitResponseSchema,\n} from './fireworks-image-api';\nimport { FireworksImageModelId } from './fireworks-image-options';\n\nconst DEFAULT_POLL_INTERVAL_MILLIS = 500;\nconst DEFAULT_POLL_TIMEOUT_MILLIS = 120000; // 2 minutes for image generation\n\ninterface FireworksImageModelBackendConfig {\n urlFormat: 'workflows' | 'workflows_async' | 'image_generation';\n supportsSize?: boolean;\n supportsEditing?: boolean;\n}\n\nconst modelToBackendConfig: Partial<\n Record<FireworksImageModelId, FireworksImageModelBackendConfig>\n> = {\n 'accounts/fireworks/models/flux-1-dev-fp8': {\n urlFormat: 'workflows',\n },\n 'accounts/fireworks/models/flux-1-schnell-fp8': {\n urlFormat: 'workflows',\n },\n 'accounts/fireworks/models/flux-kontext-pro': {\n urlFormat: 'workflows_async',\n supportsEditing: true,\n },\n 'accounts/fireworks/models/flux-kontext-max': {\n urlFormat: 'workflows_async',\n supportsEditing: true,\n },\n 'accounts/fireworks/models/playground-v2-5-1024px-aesthetic': {\n urlFormat: 'image_generation',\n supportsSize: true,\n },\n 'accounts/fireworks/models/japanese-stable-diffusion-xl': {\n urlFormat: 'image_generation',\n supportsSize: true,\n },\n 'accounts/fireworks/models/playground-v2-1024px-aesthetic': {\n urlFormat: 'image_generation',\n supportsSize: true,\n },\n 'accounts/fireworks/models/stable-diffusion-xl-1024-v1-0': {\n urlFormat: 'image_generation',\n supportsSize: true,\n },\n 'accounts/fireworks/models/SSD-1B': {\n urlFormat: 'image_generation',\n supportsSize: true,\n },\n};\n\nfunction getUrlForModel(\n baseUrl: string,\n modelId: FireworksImageModelId,\n): string {\n const config = modelToBackendConfig[modelId];\n\n switch (config?.urlFormat) {\n case 'image_generation':\n return `${baseUrl}/image_generation/${modelId}`;\n case 'workflows_async':\n return `${baseUrl}/workflows/${modelId}`;\n case 'workflows':\n default:\n return `${baseUrl}/workflows/${modelId}/text_to_image`;\n }\n}\n\nfunction getPollUrlForModel(\n baseUrl: string,\n modelId: FireworksImageModelId,\n): string {\n return `${baseUrl}/workflows/${modelId}/get_result`;\n}\n\ninterface FireworksImageModelConfig {\n provider: string;\n baseURL: string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n /**\n * Poll interval in milliseconds between status checks for async models.\n * Defaults to 500ms.\n */\n pollIntervalMillis?: number;\n /**\n * Overall timeout in milliseconds for polling before giving up.\n * Defaults to 120000ms (2 minutes).\n */\n pollTimeoutMillis?: number;\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class FireworksImageModel implements ImageModelV4 {\n readonly specificationVersion = 'v4';\n readonly maxImagesPerCall = 1;\n\n get provider(): string {\n return this.config.provider;\n }\n\n constructor(\n readonly modelId: FireworksImageModelId,\n private config: FireworksImageModelConfig,\n ) {}\n\n async doGenerate({\n prompt,\n n,\n size,\n aspectRatio,\n seed,\n providerOptions,\n headers,\n abortSignal,\n files,\n mask,\n }: Parameters<ImageModelV4['doGenerate']>[0]): Promise<\n Awaited<ReturnType<ImageModelV4['doGenerate']>>\n > {\n const warnings: Array<SharedV4Warning> = [];\n\n const backendConfig = modelToBackendConfig[this.modelId];\n if (!backendConfig?.supportsSize && size != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'size',\n details:\n 'This model does not support the `size` option. Use `aspectRatio` instead.',\n });\n }\n\n // Use supportsSize as a proxy for whether the model does not support\n // aspectRatio. This invariant holds for the current set of models.\n if (backendConfig?.supportsSize && aspectRatio != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'aspectRatio',\n details: 'This model does not support the `aspectRatio` option.',\n });\n }\n\n // Handle files for image editing\n const hasInputImage = files != null && files.length > 0;\n let inputImage: string | undefined;\n\n if (hasInputImage) {\n inputImage = convertImageModelFileToDataUri(files[0]);\n\n if (files.length > 1) {\n warnings.push({\n type: 'other',\n message:\n 'Fireworks only supports a single input image. Additional images are ignored.',\n });\n }\n }\n\n // Warn about mask - Fireworks Kontext models don't support explicit masks\n if (mask != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'mask',\n details:\n 'Fireworks Kontext models do not support explicit masks. Use the prompt to describe the areas to edit.',\n });\n }\n\n const splitSize = size?.split('x');\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const combinedHeaders = combineHeaders(this.config.headers(), headers);\n\n const body = {\n prompt,\n aspect_ratio: aspectRatio,\n seed,\n samples: n,\n ...(inputImage && { input_image: inputImage }),\n ...(splitSize && { width: splitSize[0], height: splitSize[1] }),\n ...(providerOptions.fireworks ?? {}),\n };\n\n // Handle async models that require polling (e.g., flux-kontext-*)\n if (backendConfig?.urlFormat === 'workflows_async') {\n return this.doGenerateAsync({\n body,\n headers: combinedHeaders,\n abortSignal,\n warnings,\n currentDate,\n });\n }\n\n // Handle sync models that return binary directly\n const { value: response, responseHeaders } = await postJsonToApi({\n url: getUrlForModel(this.config.baseURL, this.modelId),\n headers: combinedHeaders,\n body,\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createBinaryResponseHandler(),\n abortSignal,\n fetch: this.config.fetch,\n });\n\n return {\n images: [response],\n warnings,\n response: {\n timestamp: currentDate,\n modelId: this.modelId,\n headers: responseHeaders,\n },\n };\n }\n\n /**\n * Handles async image generation for models like flux-kontext-* that return\n * a request_id and require polling for results.\n */\n private async doGenerateAsync({\n body,\n headers,\n abortSignal,\n warnings,\n currentDate,\n }: {\n body: Record<string, unknown>;\n headers: Record<string, string | undefined>;\n abortSignal: AbortSignal | undefined;\n warnings: Array<SharedV4Warning>;\n currentDate: Date;\n }): Promise<Awaited<ReturnType<ImageModelV4['doGenerate']>>> {\n // Submit the generation request\n const { value: submitResponse } = await postJsonToApi({\n url: getUrlForModel(this.config.baseURL, this.modelId),\n headers,\n body,\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n asyncSubmitResponseSchema,\n ),\n abortSignal,\n fetch: this.config.fetch,\n });\n\n const requestId = submitResponse.request_id;\n\n // Poll for the result\n const imageUrl = await this.pollForImageUrl({\n requestId,\n headers,\n abortSignal,\n });\n\n // Download the image from the URL\n const { value: imageBytes, responseHeaders } = await getFromApi({\n url: imageUrl,\n headers,\n abortSignal,\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createBinaryResponseHandler(),\n fetch: this.config.fetch,\n });\n\n return {\n images: [imageBytes],\n warnings,\n response: {\n timestamp: currentDate,\n modelId: this.modelId,\n headers: responseHeaders,\n },\n };\n }\n\n /**\n * Polls the get_result endpoint until the image is ready.\n */\n private async pollForImageUrl({\n requestId,\n headers,\n abortSignal,\n }: {\n requestId: string;\n headers: Record<string, string | undefined>;\n abortSignal: AbortSignal | undefined;\n }): Promise<string> {\n const pollIntervalMillis =\n this.config.pollIntervalMillis ?? DEFAULT_POLL_INTERVAL_MILLIS;\n const pollTimeoutMillis =\n this.config.pollTimeoutMillis ?? DEFAULT_POLL_TIMEOUT_MILLIS;\n const maxPollAttempts = Math.ceil(\n pollTimeoutMillis / Math.max(1, pollIntervalMillis),\n );\n\n const pollUrl = getPollUrlForModel(this.config.baseURL, this.modelId);\n\n for (let i = 0; i < maxPollAttempts; i++) {\n const { value: pollResponse } = await postJsonToApi({\n url: pollUrl,\n headers,\n body: { id: requestId },\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n asyncPollResponseSchema,\n ),\n abortSignal,\n fetch: this.config.fetch,\n });\n\n const status = pollResponse.status;\n\n if (status === 'Ready') {\n const imageUrl = pollResponse.result?.sample;\n if (typeof imageUrl === 'string') {\n return imageUrl;\n }\n throw new Error(\n 'Fireworks poll response is Ready but missing result.sample',\n );\n }\n\n if (status === 'Error' || status === 'Failed') {\n throw new Error(\n `Fireworks image generation failed with status: ${status}`,\n );\n }\n\n // Wait before next poll attempt\n await delay(pollIntervalMillis);\n }\n\n throw new Error(\n `Fireworks image generation timed out after ${pollTimeoutMillis}ms`,\n );\n }\n}\n","import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\n\n// Schema for async submit response\nexport const asyncSubmitResponseSchema = lazySchema(() =>\n zodSchema(\n z.object({\n request_id: z.string(),\n }),\n ),\n);\n\n// Schema for async poll response\nexport const asyncPollResponseSchema = lazySchema(() =>\n zodSchema(\n z.object({\n id: z.string(),\n status: z.string(),\n result: z\n .object({\n sample: z.string().optional(),\n })\n .nullable(),\n }),\n ),\n);\n","import {\n OpenAICompatibleChatLanguageModel,\n OpenAICompatibleCompletionLanguageModel,\n OpenAICompatibleEmbeddingModel,\n ProviderErrorStructure,\n} from '@ai-sdk/openai-compatible';\nimport {\n EmbeddingModelV4,\n ImageModelV4,\n LanguageModelV4,\n ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\nimport { FireworksChatModelId } from './fireworks-chat-options';\nimport { FireworksCompletionModelId } from './fireworks-completion-options';\nimport { FireworksEmbeddingModelId } from './fireworks-embedding-options';\nimport { FireworksImageModel } from './fireworks-image-model';\nimport { FireworksImageModelId } from './fireworks-image-options';\nimport { VERSION } from './version';\n\nexport type FireworksErrorData = z.infer<typeof fireworksErrorSchema>;\n\nconst fireworksErrorSchema = z.object({\n error: z.string(),\n});\n\nconst fireworksErrorStructure: ProviderErrorStructure<FireworksErrorData> = {\n errorSchema: fireworksErrorSchema,\n errorToMessage: data => data.error,\n};\n\nexport interface FireworksProviderSettings {\n /**\n * Fireworks API key. Default value is taken from the `FIREWORKS_API_KEY`\n * environment variable.\n */\n apiKey?: string;\n /**\n * Base URL for the API calls.\n */\n baseURL?: string;\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface FireworksProvider extends ProviderV4 {\n /**\n * Creates a model for text generation.\n */\n (modelId: FireworksChatModelId): LanguageModelV4;\n\n /**\n * Creates a chat model for text generation.\n */\n chatModel(modelId: FireworksChatModelId): LanguageModelV4;\n\n /**\n * Creates a completion model for text generation.\n */\n completionModel(modelId: FireworksCompletionModelId): LanguageModelV4;\n\n /**\n * Creates a chat model for text generation.\n */\n languageModel(modelId: FireworksChatModelId): LanguageModelV4;\n\n /**\n * Creates a text embedding model for text generation.\n */\n embeddingModel(modelId: FireworksEmbeddingModelId): EmbeddingModelV4;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: FireworksEmbeddingModelId): EmbeddingModelV4;\n\n /**\n * Creates a model for image generation.\n */\n image(modelId: FireworksImageModelId): ImageModelV4;\n\n /**\n * Creates a model for image generation.\n */\n imageModel(modelId: FireworksImageModelId): ImageModelV4;\n}\n\nconst defaultBaseURL = 'https://api.fireworks.ai/inference/v1';\n\nexport function createFireworks(\n options: FireworksProviderSettings = {},\n): FireworksProvider {\n const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'FIREWORKS_API_KEY',\n description: 'Fireworks API key',\n })}`,\n ...options.headers,\n },\n `ai-sdk/fireworks/${VERSION}`,\n );\n\n interface CommonModelConfig {\n provider: string;\n url: ({ path }: { path: string }) => string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n }\n\n const getCommonModelConfig = (modelType: string): CommonModelConfig => ({\n provider: `fireworks.${modelType}`,\n url: ({ path }) => `${baseURL}${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const createChatModel = (modelId: FireworksChatModelId) => {\n return new OpenAICompatibleChatLanguageModel(modelId, {\n ...getCommonModelConfig('chat'),\n errorStructure: fireworksErrorStructure,\n transformRequestBody: args => {\n const thinking = args.thinking as\n | { type?: string; budgetTokens?: number }\n | undefined;\n const reasoningHistory = args.reasoningHistory as string | undefined;\n\n const { thinking: _, reasoningHistory: __, ...rest } = args;\n\n return {\n ...rest,\n ...(thinking && {\n thinking: {\n type: thinking.type,\n ...(thinking.budgetTokens !== undefined && {\n budget_tokens: thinking.budgetTokens,\n }),\n },\n }),\n ...(reasoningHistory && {\n reasoning_history: reasoningHistory,\n }),\n };\n },\n });\n };\n\n const createCompletionModel = (modelId: FireworksCompletionModelId) =>\n new OpenAICompatibleCompletionLanguageModel(modelId, {\n ...getCommonModelConfig('completion'),\n errorStructure: fireworksErrorStructure,\n });\n\n const createEmbeddingModel = (modelId: FireworksEmbeddingModelId) =>\n new OpenAICompatibleEmbeddingModel(modelId, {\n ...getCommonModelConfig('embedding'),\n errorStructure: fireworksErrorStructure,\n });\n\n const createImageModel = (modelId: FireworksImageModelId) =>\n new FireworksImageModel(modelId, {\n ...getCommonModelConfig('image'),\n baseURL: baseURL ?? defaultBaseURL,\n });\n\n const provider = (modelId: FireworksChatModelId) => createChatModel(modelId);\n\n provider.specificationVersion = 'v4' as const;\n provider.completionModel = createCompletionModel;\n provider.chatModel = createChatModel;\n provider.languageModel = createChatModel;\n provider.embeddingModel = createEmbeddingModel;\n provider.textEmbeddingModel = createEmbeddingModel;\n provider.image = createImageModel;\n provider.imageModel = createImageModel;\n return provider;\n}\n\nexport const fireworks = createFireworks();\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;;;ACXP,SAAS,YAAY,iBAAiB;AACtC,SAAS,SAAS;AAGX,IAAM,4BAA4B;AAAA,EAAW,MAClD;AAAA,IACE,EAAE,OAAO;AAAA,MACP,YAAY,EAAE,OAAO;AAAA,IACvB,CAAC;AAAA,EACH;AACF;AAGO,IAAM,0BAA0B;AAAA,EAAW,MAChD;AAAA,IACE,EAAE,OAAO;AAAA,MACP,IAAI,EAAE,OAAO;AAAA,MACb,QAAQ,EAAE,OAAO;AAAA,MACjB,QAAQ,EACL,OAAO;AAAA,QACN,QAAQ,EAAE,OAAO,EAAE,SAAS;AAAA,MAC9B,CAAC,EACA,SAAS;AAAA,IACd,CAAC;AAAA,EACH;AACF;;;ADPA,IAAM,+BAA+B;AACrC,IAAM,8BAA8B;AAQpC,IAAM,uBAEF;AAAA,EACF,4CAA4C;AAAA,IAC1C,WAAW;AAAA,EACb;AAAA,EACA,gDAAgD;AAAA,IAC9C,WAAW;AAAA,EACb;AAAA,EACA,8CAA8C;AAAA,IAC5C,WAAW;AAAA,IACX,iBAAiB;AAAA,EACnB;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