@yourgpt/llm-sdk 2.1.6 → 2.1.7

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/dist/index.js CHANGED
@@ -2838,7 +2838,10 @@ var Runtime = class {
2838
2838
  }
2839
2839
  }
2840
2840
  if (resolvedThreadId) {
2841
- yield { type: "thread:created", threadId: resolvedThreadId };
2841
+ yield {
2842
+ type: "thread:created",
2843
+ threadId: resolvedThreadId
2844
+ };
2842
2845
  }
2843
2846
  if (resolvedThreadId && storageHealthy) {
2844
2847
  try {
package/dist/index.mjs CHANGED
@@ -2836,7 +2836,10 @@ var Runtime = class {
2836
2836
  }
2837
2837
  }
2838
2838
  if (resolvedThreadId) {
2839
- yield { type: "thread:created", threadId: resolvedThreadId };
2839
+ yield {
2840
+ type: "thread:created",
2841
+ threadId: resolvedThreadId
2842
+ };
2840
2843
  }
2841
2844
  if (resolvedThreadId && storageHealthy) {
2842
2845
  try {
@@ -0,0 +1,49 @@
1
+ import { L as LanguageModel } from '../../types-CR8mi9I0.mjs';
2
+ import 'zod';
3
+
4
+ /**
5
+ * Fireworks Provider
6
+ *
7
+ * Fireworks.ai is a high-performance inference platform for open-source models.
8
+ * It uses an OpenAI-compatible REST API.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { fireworks } from '@yourgpt/llm-sdk/fireworks';
13
+ * import { generateText } from '@yourgpt/llm-sdk';
14
+ *
15
+ * const result = await generateText({
16
+ * model: fireworks('accounts/fireworks/models/llama-v3p1-70b-instruct'),
17
+ * prompt: 'Hello!',
18
+ * });
19
+ * ```
20
+ */
21
+
22
+ interface FireworksProviderOptions {
23
+ /** API key (defaults to FIREWORKS_API_KEY env var) */
24
+ apiKey?: string;
25
+ /** Base URL for API (defaults to https://api.fireworks.ai/inference/v1) */
26
+ baseURL?: string;
27
+ }
28
+ /**
29
+ * Create a Fireworks language model.
30
+ *
31
+ * Model IDs follow the format `accounts/fireworks/models/{model-name}`.
32
+ *
33
+ * @param modelId - Full model ID or shorthand (e.g. 'accounts/fireworks/models/llama-v3p1-70b-instruct')
34
+ * @param options - Provider options
35
+ * @returns LanguageModel instance
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const model = fireworks('accounts/fireworks/models/llama-v3p1-70b-instruct');
40
+ *
41
+ * // With explicit API key
42
+ * const model = fireworks('accounts/fireworks/models/deepseek-v3', {
43
+ * apiKey: 'fw_...',
44
+ * });
45
+ * ```
46
+ */
47
+ declare function fireworks(modelId: string, options?: FireworksProviderOptions): LanguageModel;
48
+
49
+ export { type FireworksProviderOptions, fireworks as createFireworks, fireworks };
@@ -0,0 +1,49 @@
1
+ import { L as LanguageModel } from '../../types-CR8mi9I0.js';
2
+ import 'zod';
3
+
4
+ /**
5
+ * Fireworks Provider
6
+ *
7
+ * Fireworks.ai is a high-performance inference platform for open-source models.
8
+ * It uses an OpenAI-compatible REST API.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { fireworks } from '@yourgpt/llm-sdk/fireworks';
13
+ * import { generateText } from '@yourgpt/llm-sdk';
14
+ *
15
+ * const result = await generateText({
16
+ * model: fireworks('accounts/fireworks/models/llama-v3p1-70b-instruct'),
17
+ * prompt: 'Hello!',
18
+ * });
19
+ * ```
20
+ */
21
+
22
+ interface FireworksProviderOptions {
23
+ /** API key (defaults to FIREWORKS_API_KEY env var) */
24
+ apiKey?: string;
25
+ /** Base URL for API (defaults to https://api.fireworks.ai/inference/v1) */
26
+ baseURL?: string;
27
+ }
28
+ /**
29
+ * Create a Fireworks language model.
30
+ *
31
+ * Model IDs follow the format `accounts/fireworks/models/{model-name}`.
32
+ *
33
+ * @param modelId - Full model ID or shorthand (e.g. 'accounts/fireworks/models/llama-v3p1-70b-instruct')
34
+ * @param options - Provider options
35
+ * @returns LanguageModel instance
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const model = fireworks('accounts/fireworks/models/llama-v3p1-70b-instruct');
40
+ *
41
+ * // With explicit API key
42
+ * const model = fireworks('accounts/fireworks/models/deepseek-v3', {
43
+ * apiKey: 'fw_...',
44
+ * });
45
+ * ```
46
+ */
47
+ declare function fireworks(modelId: string, options?: FireworksProviderOptions): LanguageModel;
48
+
49
+ export { type FireworksProviderOptions, fireworks as createFireworks, fireworks };
@@ -0,0 +1,205 @@
1
+ 'use strict';
2
+
3
+ // src/providers/fireworks/provider.ts
4
+ function fireworks(modelId, options = {}) {
5
+ const apiKey = options.apiKey ?? process.env.FIREWORKS_API_KEY;
6
+ const baseURL = options.baseURL ?? "https://api.fireworks.ai/inference/v1";
7
+ let client = null;
8
+ async function getClient() {
9
+ if (!client) {
10
+ const { default: OpenAI } = await import('openai');
11
+ client = new OpenAI({ apiKey, baseURL });
12
+ }
13
+ return client;
14
+ }
15
+ return {
16
+ provider: "fireworks",
17
+ modelId,
18
+ capabilities: {
19
+ supportsVision: false,
20
+ supportsTools: true,
21
+ supportsStreaming: true,
22
+ supportsJsonMode: true,
23
+ supportsThinking: false,
24
+ supportsPDF: false,
25
+ maxTokens: 131072,
26
+ supportedImageTypes: []
27
+ },
28
+ async doGenerate(params) {
29
+ const client2 = await getClient();
30
+ const messages = formatMessages(params.messages);
31
+ const requestBody = {
32
+ model: modelId,
33
+ messages,
34
+ temperature: params.temperature,
35
+ max_tokens: params.maxTokens
36
+ };
37
+ if (params.tools) {
38
+ requestBody.tools = params.tools;
39
+ }
40
+ const response = await client2.chat.completions.create(requestBody);
41
+ const choice = response.choices[0];
42
+ const message = choice.message;
43
+ const toolCalls = (message.tool_calls ?? []).map(
44
+ (tc) => ({
45
+ id: tc.id,
46
+ name: tc.function.name,
47
+ args: JSON.parse(tc.function.arguments || "{}")
48
+ })
49
+ );
50
+ return {
51
+ text: message.content ?? "",
52
+ toolCalls,
53
+ finishReason: mapFinishReason(choice.finish_reason),
54
+ usage: {
55
+ promptTokens: response.usage?.prompt_tokens ?? 0,
56
+ completionTokens: response.usage?.completion_tokens ?? 0,
57
+ totalTokens: response.usage?.total_tokens ?? 0
58
+ },
59
+ rawResponse: response
60
+ };
61
+ },
62
+ async *doStream(params) {
63
+ const client2 = await getClient();
64
+ const messages = formatMessages(params.messages);
65
+ const requestBody = {
66
+ model: modelId,
67
+ messages,
68
+ temperature: params.temperature,
69
+ max_tokens: params.maxTokens,
70
+ stream: true
71
+ };
72
+ if (params.tools) {
73
+ requestBody.tools = params.tools;
74
+ }
75
+ const stream = await client2.chat.completions.create(requestBody);
76
+ const toolCallMap = /* @__PURE__ */ new Map();
77
+ let totalPromptTokens = 0;
78
+ let totalCompletionTokens = 0;
79
+ for await (const chunk of stream) {
80
+ if (params.signal?.aborted) {
81
+ yield { type: "error", error: new Error("Aborted") };
82
+ return;
83
+ }
84
+ const choice = chunk.choices[0];
85
+ const delta = choice?.delta;
86
+ if (delta?.content) {
87
+ yield { type: "text-delta", text: delta.content };
88
+ }
89
+ if (delta?.tool_calls) {
90
+ for (const tc of delta.tool_calls) {
91
+ const idx = tc.index ?? 0;
92
+ if (!toolCallMap.has(idx)) {
93
+ toolCallMap.set(idx, {
94
+ id: tc.id ?? "",
95
+ name: tc.function?.name ?? "",
96
+ arguments: tc.function?.arguments ?? ""
97
+ });
98
+ } else {
99
+ const existing = toolCallMap.get(idx);
100
+ if (tc.id && !existing.id) existing.id = tc.id;
101
+ if (tc.function?.name && !existing.name)
102
+ existing.name = tc.function.name;
103
+ if (tc.function?.arguments)
104
+ existing.arguments += tc.function.arguments;
105
+ }
106
+ }
107
+ }
108
+ if (choice?.finish_reason) {
109
+ for (const [, tc] of toolCallMap) {
110
+ yield {
111
+ type: "tool-call",
112
+ toolCall: {
113
+ id: tc.id,
114
+ name: tc.name,
115
+ args: JSON.parse(tc.arguments || "{}")
116
+ }
117
+ };
118
+ }
119
+ toolCallMap.clear();
120
+ if (chunk.usage) {
121
+ totalPromptTokens = chunk.usage.prompt_tokens;
122
+ totalCompletionTokens = chunk.usage.completion_tokens;
123
+ }
124
+ yield {
125
+ type: "finish",
126
+ finishReason: mapFinishReason(choice.finish_reason),
127
+ usage: {
128
+ promptTokens: totalPromptTokens,
129
+ completionTokens: totalCompletionTokens,
130
+ totalTokens: totalPromptTokens + totalCompletionTokens
131
+ }
132
+ };
133
+ }
134
+ }
135
+ }
136
+ };
137
+ }
138
+ function mapFinishReason(reason) {
139
+ switch (reason) {
140
+ case "stop":
141
+ return "stop";
142
+ case "length":
143
+ return "length";
144
+ case "tool_calls":
145
+ case "function_call":
146
+ return "tool-calls";
147
+ case "content_filter":
148
+ return "content-filter";
149
+ default:
150
+ return "unknown";
151
+ }
152
+ }
153
+ function formatMessages(messages) {
154
+ return messages.map((msg) => {
155
+ switch (msg.role) {
156
+ case "system":
157
+ return { role: "system", content: msg.content };
158
+ case "user":
159
+ if (typeof msg.content === "string") {
160
+ return { role: "user", content: msg.content };
161
+ }
162
+ return {
163
+ role: "user",
164
+ content: msg.content.map((part) => {
165
+ if (part.type === "text") {
166
+ return { type: "text", text: part.text };
167
+ }
168
+ if (part.type === "image") {
169
+ const imageData = typeof part.image === "string" ? part.image : Buffer.from(part.image).toString("base64");
170
+ const url = imageData.startsWith("data:") ? imageData : `data:${part.mimeType ?? "image/png"};base64,${imageData}`;
171
+ return { type: "image_url", image_url: { url, detail: "auto" } };
172
+ }
173
+ return { type: "text", text: "" };
174
+ })
175
+ };
176
+ case "assistant": {
177
+ const assistantMsg = { role: "assistant", content: msg.content };
178
+ if (msg.toolCalls && msg.toolCalls.length > 0) {
179
+ assistantMsg.tool_calls = msg.toolCalls.map((tc) => ({
180
+ id: tc.id,
181
+ type: "function",
182
+ function: {
183
+ name: tc.name,
184
+ arguments: JSON.stringify(tc.args)
185
+ }
186
+ }));
187
+ }
188
+ return assistantMsg;
189
+ }
190
+ case "tool":
191
+ return {
192
+ role: "tool",
193
+ tool_call_id: msg.toolCallId,
194
+ content: msg.content
195
+ };
196
+ default:
197
+ return msg;
198
+ }
199
+ });
200
+ }
201
+
202
+ exports.createFireworks = fireworks;
203
+ exports.fireworks = fireworks;
204
+ //# sourceMappingURL=index.js.map
205
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,202 @@
1
+ // src/providers/fireworks/provider.ts
2
+ function fireworks(modelId, options = {}) {
3
+ const apiKey = options.apiKey ?? process.env.FIREWORKS_API_KEY;
4
+ const baseURL = options.baseURL ?? "https://api.fireworks.ai/inference/v1";
5
+ let client = null;
6
+ async function getClient() {
7
+ if (!client) {
8
+ const { default: OpenAI } = await import('openai');
9
+ client = new OpenAI({ apiKey, baseURL });
10
+ }
11
+ return client;
12
+ }
13
+ return {
14
+ provider: "fireworks",
15
+ modelId,
16
+ capabilities: {
17
+ supportsVision: false,
18
+ supportsTools: true,
19
+ supportsStreaming: true,
20
+ supportsJsonMode: true,
21
+ supportsThinking: false,
22
+ supportsPDF: false,
23
+ maxTokens: 131072,
24
+ supportedImageTypes: []
25
+ },
26
+ async doGenerate(params) {
27
+ const client2 = await getClient();
28
+ const messages = formatMessages(params.messages);
29
+ const requestBody = {
30
+ model: modelId,
31
+ messages,
32
+ temperature: params.temperature,
33
+ max_tokens: params.maxTokens
34
+ };
35
+ if (params.tools) {
36
+ requestBody.tools = params.tools;
37
+ }
38
+ const response = await client2.chat.completions.create(requestBody);
39
+ const choice = response.choices[0];
40
+ const message = choice.message;
41
+ const toolCalls = (message.tool_calls ?? []).map(
42
+ (tc) => ({
43
+ id: tc.id,
44
+ name: tc.function.name,
45
+ args: JSON.parse(tc.function.arguments || "{}")
46
+ })
47
+ );
48
+ return {
49
+ text: message.content ?? "",
50
+ toolCalls,
51
+ finishReason: mapFinishReason(choice.finish_reason),
52
+ usage: {
53
+ promptTokens: response.usage?.prompt_tokens ?? 0,
54
+ completionTokens: response.usage?.completion_tokens ?? 0,
55
+ totalTokens: response.usage?.total_tokens ?? 0
56
+ },
57
+ rawResponse: response
58
+ };
59
+ },
60
+ async *doStream(params) {
61
+ const client2 = await getClient();
62
+ const messages = formatMessages(params.messages);
63
+ const requestBody = {
64
+ model: modelId,
65
+ messages,
66
+ temperature: params.temperature,
67
+ max_tokens: params.maxTokens,
68
+ stream: true
69
+ };
70
+ if (params.tools) {
71
+ requestBody.tools = params.tools;
72
+ }
73
+ const stream = await client2.chat.completions.create(requestBody);
74
+ const toolCallMap = /* @__PURE__ */ new Map();
75
+ let totalPromptTokens = 0;
76
+ let totalCompletionTokens = 0;
77
+ for await (const chunk of stream) {
78
+ if (params.signal?.aborted) {
79
+ yield { type: "error", error: new Error("Aborted") };
80
+ return;
81
+ }
82
+ const choice = chunk.choices[0];
83
+ const delta = choice?.delta;
84
+ if (delta?.content) {
85
+ yield { type: "text-delta", text: delta.content };
86
+ }
87
+ if (delta?.tool_calls) {
88
+ for (const tc of delta.tool_calls) {
89
+ const idx = tc.index ?? 0;
90
+ if (!toolCallMap.has(idx)) {
91
+ toolCallMap.set(idx, {
92
+ id: tc.id ?? "",
93
+ name: tc.function?.name ?? "",
94
+ arguments: tc.function?.arguments ?? ""
95
+ });
96
+ } else {
97
+ const existing = toolCallMap.get(idx);
98
+ if (tc.id && !existing.id) existing.id = tc.id;
99
+ if (tc.function?.name && !existing.name)
100
+ existing.name = tc.function.name;
101
+ if (tc.function?.arguments)
102
+ existing.arguments += tc.function.arguments;
103
+ }
104
+ }
105
+ }
106
+ if (choice?.finish_reason) {
107
+ for (const [, tc] of toolCallMap) {
108
+ yield {
109
+ type: "tool-call",
110
+ toolCall: {
111
+ id: tc.id,
112
+ name: tc.name,
113
+ args: JSON.parse(tc.arguments || "{}")
114
+ }
115
+ };
116
+ }
117
+ toolCallMap.clear();
118
+ if (chunk.usage) {
119
+ totalPromptTokens = chunk.usage.prompt_tokens;
120
+ totalCompletionTokens = chunk.usage.completion_tokens;
121
+ }
122
+ yield {
123
+ type: "finish",
124
+ finishReason: mapFinishReason(choice.finish_reason),
125
+ usage: {
126
+ promptTokens: totalPromptTokens,
127
+ completionTokens: totalCompletionTokens,
128
+ totalTokens: totalPromptTokens + totalCompletionTokens
129
+ }
130
+ };
131
+ }
132
+ }
133
+ }
134
+ };
135
+ }
136
+ function mapFinishReason(reason) {
137
+ switch (reason) {
138
+ case "stop":
139
+ return "stop";
140
+ case "length":
141
+ return "length";
142
+ case "tool_calls":
143
+ case "function_call":
144
+ return "tool-calls";
145
+ case "content_filter":
146
+ return "content-filter";
147
+ default:
148
+ return "unknown";
149
+ }
150
+ }
151
+ function formatMessages(messages) {
152
+ return messages.map((msg) => {
153
+ switch (msg.role) {
154
+ case "system":
155
+ return { role: "system", content: msg.content };
156
+ case "user":
157
+ if (typeof msg.content === "string") {
158
+ return { role: "user", content: msg.content };
159
+ }
160
+ return {
161
+ role: "user",
162
+ content: msg.content.map((part) => {
163
+ if (part.type === "text") {
164
+ return { type: "text", text: part.text };
165
+ }
166
+ if (part.type === "image") {
167
+ const imageData = typeof part.image === "string" ? part.image : Buffer.from(part.image).toString("base64");
168
+ const url = imageData.startsWith("data:") ? imageData : `data:${part.mimeType ?? "image/png"};base64,${imageData}`;
169
+ return { type: "image_url", image_url: { url, detail: "auto" } };
170
+ }
171
+ return { type: "text", text: "" };
172
+ })
173
+ };
174
+ case "assistant": {
175
+ const assistantMsg = { role: "assistant", content: msg.content };
176
+ if (msg.toolCalls && msg.toolCalls.length > 0) {
177
+ assistantMsg.tool_calls = msg.toolCalls.map((tc) => ({
178
+ id: tc.id,
179
+ type: "function",
180
+ function: {
181
+ name: tc.name,
182
+ arguments: JSON.stringify(tc.args)
183
+ }
184
+ }));
185
+ }
186
+ return assistantMsg;
187
+ }
188
+ case "tool":
189
+ return {
190
+ role: "tool",
191
+ tool_call_id: msg.toolCallId,
192
+ content: msg.content
193
+ };
194
+ default:
195
+ return msg;
196
+ }
197
+ });
198
+ }
199
+
200
+ export { fireworks as createFireworks, fireworks };
201
+ //# sourceMappingURL=index.mjs.map
202
+ //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yourgpt/llm-sdk",
3
- "version": "2.1.6",
3
+ "version": "2.1.7",
4
4
  "description": "AI SDK for building AI Agents with any LLM",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -46,6 +46,11 @@
46
46
  "import": "./dist/providers/openrouter/index.mjs",
47
47
  "require": "./dist/providers/openrouter/index.js"
48
48
  },
49
+ "./fireworks": {
50
+ "types": "./dist/providers/fireworks/index.d.mts",
51
+ "import": "./dist/providers/fireworks/index.mjs",
52
+ "require": "./dist/providers/fireworks/index.js"
53
+ },
49
54
  "./adapters": {
50
55
  "types": "./dist/adapters/index.d.ts",
51
56
  "import": "./dist/adapters/index.mjs",
@@ -113,6 +118,7 @@
113
118
  "grok",
114
119
  "ollama",
115
120
  "openrouter",
121
+ "fireworks",
116
122
  "multi-provider",
117
123
  "streaming"
118
124
  ],