rhachet-brains-fireworksai 0.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Uladzimir Kasacheuski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,7 @@
1
+ import type { BrainAtom } from 'rhachet';
2
+ /**
3
+ * .what = returns all brain atoms provided by fireworks ai
4
+ * .why = enables consumers to register fireworks ai atoms with genContextBrain
5
+ */
6
+ export declare const getBrainAtomsByFireworksAI: () => BrainAtom[];
7
+ export { genBrainAtom } from '../../domain.operations/atom/genBrainAtom';
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genBrainAtom = exports.getBrainAtomsByFireworksAI = void 0;
4
+ const genBrainAtom_1 = require("../../domain.operations/atom/genBrainAtom");
5
+ /**
6
+ * .what = returns all brain atoms provided by fireworks ai
7
+ * .why = enables consumers to register fireworks ai atoms with genContextBrain
8
+ */
9
+ const getBrainAtomsByFireworksAI = () => {
10
+ return [
11
+ (0, genBrainAtom_1.genBrainAtom)({ slug: 'fireworks/qwen3/coder-next' }),
12
+ (0, genBrainAtom_1.genBrainAtom)({ slug: 'fireworks/qwen3/coder-480b' }),
13
+ (0, genBrainAtom_1.genBrainAtom)({ slug: 'fireworks/qwen3/235b' }),
14
+ (0, genBrainAtom_1.genBrainAtom)({ slug: 'fireworks/deepseek/v3.1' }),
15
+ (0, genBrainAtom_1.genBrainAtom)({ slug: 'fireworks/deepseek/r1' }),
16
+ (0, genBrainAtom_1.genBrainAtom)({ slug: 'fireworks/kimi/k2' }),
17
+ (0, genBrainAtom_1.genBrainAtom)({ slug: 'fireworks/kimi/k2.5' }),
18
+ (0, genBrainAtom_1.genBrainAtom)({ slug: 'fireworks/llama4/maverick' }),
19
+ (0, genBrainAtom_1.genBrainAtom)({ slug: 'fireworks/llama3.3/70b' }),
20
+ (0, genBrainAtom_1.genBrainAtom)({ slug: 'fireworks/glm/4.7' }),
21
+ ];
22
+ };
23
+ exports.getBrainAtomsByFireworksAI = getBrainAtomsByFireworksAI;
24
+ // re-export factory for direct access
25
+ var genBrainAtom_2 = require("../../domain.operations/atom/genBrainAtom");
26
+ Object.defineProperty(exports, "genBrainAtom", { enumerable: true, get: function () { return genBrainAtom_2.genBrainAtom; } });
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/contract/sdk/index.ts"],"names":[],"mappings":";;;AAEA,4EAAyE;AAEzE;;;GAGG;AACI,MAAM,0BAA0B,GAAG,GAAgB,EAAE;IAC1D,OAAO;QACL,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,4BAA4B,EAAE,CAAC;QACpD,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,4BAA4B,EAAE,CAAC;QACpD,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC;QAC9C,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,yBAAyB,EAAE,CAAC;QACjD,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,uBAAuB,EAAE,CAAC;QAC/C,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC;QAC3C,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,CAAC;QAC7C,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,2BAA2B,EAAE,CAAC;QACnD,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC;QAChD,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC;KAC5C,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,0BAA0B,8BAarC;AAEF,sCAAsC;AACtC,0EAAyE;AAAhE,4GAAA,YAAY,OAAA"}
@@ -0,0 +1,25 @@
1
+ import { BrainSpec } from 'rhachet';
2
+ /**
3
+ * .what = atom config type
4
+ * .why = shared type for model configs
5
+ */
6
+ export type BrainAtomConfig = {
7
+ model: string;
8
+ description: string;
9
+ spec: BrainSpec;
10
+ };
11
+ /**
12
+ * .what = supported fireworks ai atom slugs
13
+ * .why = enables type-safe slug specification with model variants
14
+ */
15
+ export type FireworksBrainAtomSlug = 'fireworks/qwen3/coder-next' | 'fireworks/qwen3/coder-480b' | 'fireworks/qwen3/235b' | 'fireworks/deepseek/v3.1' | 'fireworks/deepseek/r1' | 'fireworks/kimi/k2' | 'fireworks/kimi/k2.5' | 'fireworks/llama4/maverick' | 'fireworks/llama3.3/70b' | 'fireworks/glm/4.7';
16
+ /**
17
+ * .what = model configuration by slug
18
+ * .why = maps slugs to api model names, descriptions, and specs
19
+ *
20
+ * .sources:
21
+ * - rates: https://fireworks.ai/pricing
22
+ * - models: https://docs.fireworks.ai/docs/serverless-models
23
+ * - api docs: https://docs.fireworks.ai/reference/chat-completions-1
24
+ */
25
+ export declare const CONFIG_BY_ATOM_SLUG: Record<FireworksBrainAtomSlug, BrainAtomConfig>;
@@ -0,0 +1,369 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CONFIG_BY_ATOM_SLUG = void 0;
4
+ const iso_price_1 = require("iso-price");
5
+ const rhachet_1 = require("rhachet");
6
+ /**
7
+ * .what = model configuration by slug
8
+ * .why = maps slugs to api model names, descriptions, and specs
9
+ *
10
+ * .sources:
11
+ * - rates: https://fireworks.ai/pricing
12
+ * - models: https://docs.fireworks.ai/docs/serverless-models
13
+ * - api docs: https://docs.fireworks.ai/reference/chat-completions-1
14
+ */
15
+ exports.CONFIG_BY_ATOM_SLUG = {
16
+ /**
17
+ * qwen3-coder-next
18
+ * .sources:
19
+ * - rates: https://fireworks.ai/pricing ($0.50/1M input, $1.20/1M output)
20
+ * - context: 262K
21
+ * - swe-bench: 74.2% verified
22
+ * - architecture: 80B total, 3B active (moe)
23
+ */
24
+ 'fireworks/qwen3/coder-next': {
25
+ model: 'Qwen/Qwen3-Coder-Next-FP8',
26
+ description: 'qwen3-coder-next - best cost/performance for code (262K)',
27
+ spec: new rhachet_1.BrainSpec({
28
+ cost: {
29
+ time: {
30
+ speed: { tokens: 150, per: { seconds: 1 } },
31
+ latency: { seconds: 0.5 },
32
+ },
33
+ cash: {
34
+ per: 'token',
35
+ cache: {
36
+ get: (0, iso_price_1.asIsoPrice)('$0'), // no cache rate on fireworks ai
37
+ set: (0, iso_price_1.asIsoPrice)('$0'),
38
+ },
39
+ input: (0, iso_price_1.dividePrice)({ of: '$0.50', by: 1000000 }), // $0.50/1M tokens
40
+ output: (0, iso_price_1.dividePrice)({ of: '$1.20', by: 1000000 }), // $1.20/1M tokens
41
+ },
42
+ },
43
+ gain: {
44
+ size: { context: { tokens: 262000 } }, // 262K context
45
+ grades: { swe: 74.2 }, // 74.2% swe-bench verified
46
+ cutoff: '2025-06-01',
47
+ domain: 'SOFTWARE',
48
+ skills: { tooluse: true },
49
+ },
50
+ }),
51
+ },
52
+ /**
53
+ * qwen3-coder-480b
54
+ * .sources:
55
+ * - rates: https://fireworks.ai/pricing ($2.00/1M input, $2.00/1M output)
56
+ * - context: 262K
57
+ * - swe-bench: 69.6% verified
58
+ * - architecture: 480B total, 35B active (moe)
59
+ */
60
+ 'fireworks/qwen3/coder-480b': {
61
+ model: 'Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8',
62
+ description: 'qwen3-coder-480b - large code model (262K)',
63
+ spec: new rhachet_1.BrainSpec({
64
+ cost: {
65
+ time: {
66
+ speed: { tokens: 80, per: { seconds: 1 } },
67
+ latency: { seconds: 1 },
68
+ },
69
+ cash: {
70
+ per: 'token',
71
+ cache: {
72
+ get: (0, iso_price_1.asIsoPrice)('$0'),
73
+ set: (0, iso_price_1.asIsoPrice)('$0'),
74
+ },
75
+ input: (0, iso_price_1.dividePrice)({ of: '$2.00', by: 1000000 }), // $2.00/1M tokens
76
+ output: (0, iso_price_1.dividePrice)({ of: '$2.00', by: 1000000 }), // $2.00/1M tokens
77
+ },
78
+ },
79
+ gain: {
80
+ size: { context: { tokens: 262000 } }, // 262K context
81
+ grades: { swe: 69.6 }, // 69.6% swe-bench verified
82
+ cutoff: '2025-06-01',
83
+ domain: 'SOFTWARE',
84
+ skills: { tooluse: true },
85
+ },
86
+ }),
87
+ },
88
+ /**
89
+ * qwen3-235b
90
+ * .sources:
91
+ * - rates: https://fireworks.ai/pricing ($0.20/1M input, $0.60/1M output)
92
+ * - context: 131K
93
+ * - architecture: 235B total, 22B active (moe)
94
+ */
95
+ 'fireworks/qwen3/235b': {
96
+ model: 'Qwen/Qwen3-235B-A22B-Instruct-2507-tput',
97
+ description: 'qwen3-235b - general purpose (131K)',
98
+ spec: new rhachet_1.BrainSpec({
99
+ cost: {
100
+ time: {
101
+ speed: { tokens: 120, per: { seconds: 1 } },
102
+ latency: { seconds: 0.5 },
103
+ },
104
+ cash: {
105
+ per: 'token',
106
+ cache: {
107
+ get: (0, iso_price_1.asIsoPrice)('$0'),
108
+ set: (0, iso_price_1.asIsoPrice)('$0'),
109
+ },
110
+ input: (0, iso_price_1.dividePrice)({ of: '$0.20', by: 1000000 }), // $0.20/1M tokens
111
+ output: (0, iso_price_1.dividePrice)({ of: '$0.60', by: 1000000 }), // $0.60/1M tokens
112
+ },
113
+ },
114
+ gain: {
115
+ size: { context: { tokens: 131000 } }, // 131K context
116
+ grades: {},
117
+ cutoff: '2025-07-01',
118
+ domain: 'ALL',
119
+ skills: { tooluse: true },
120
+ },
121
+ }),
122
+ },
123
+ /**
124
+ * deepseek-v3.1
125
+ * .sources:
126
+ * - rates: https://fireworks.ai/pricing ($1.25/1M input, $1.25/1M output)
127
+ * - context: 128K
128
+ * - architecture: 671B total, 37B active (moe)
129
+ */
130
+ 'fireworks/deepseek/v3.1': {
131
+ model: 'deepseek-ai/DeepSeek-V3.1',
132
+ description: 'deepseek-v3.1 - frontier open-source (128K)',
133
+ spec: new rhachet_1.BrainSpec({
134
+ cost: {
135
+ time: {
136
+ speed: { tokens: 100, per: { seconds: 1 } },
137
+ latency: { seconds: 1 },
138
+ },
139
+ cash: {
140
+ per: 'token',
141
+ cache: {
142
+ get: (0, iso_price_1.asIsoPrice)('$0'),
143
+ set: (0, iso_price_1.asIsoPrice)('$0'),
144
+ },
145
+ input: (0, iso_price_1.dividePrice)({ of: '$1.25', by: 1000000 }), // $1.25/1M tokens
146
+ output: (0, iso_price_1.dividePrice)({ of: '$1.25', by: 1000000 }), // $1.25/1M tokens
147
+ },
148
+ },
149
+ gain: {
150
+ size: { context: { tokens: 128000 } }, // 128K context
151
+ grades: {},
152
+ cutoff: '2025-03-01',
153
+ domain: 'ALL',
154
+ skills: { tooluse: true },
155
+ },
156
+ }),
157
+ },
158
+ /**
159
+ * deepseek-r1
160
+ * .sources:
161
+ * - rates: https://fireworks.ai/pricing ($3.00/1M input, $7.00/1M output)
162
+ * - context: 128K
163
+ * - architecture: 671B total, 37B active (moe), chain-of-thought
164
+ */
165
+ 'fireworks/deepseek/r1': {
166
+ model: 'deepseek-ai/DeepSeek-R1',
167
+ description: 'deepseek-r1 - chain-of-thought (128K)',
168
+ spec: new rhachet_1.BrainSpec({
169
+ cost: {
170
+ time: {
171
+ speed: { tokens: 60, per: { seconds: 1 } },
172
+ latency: { seconds: 1.5 },
173
+ },
174
+ cash: {
175
+ per: 'token',
176
+ cache: {
177
+ get: (0, iso_price_1.asIsoPrice)('$0'),
178
+ set: (0, iso_price_1.asIsoPrice)('$0'),
179
+ },
180
+ input: (0, iso_price_1.dividePrice)({ of: '$3.00', by: 1000000 }), // $3.00/1M tokens
181
+ output: (0, iso_price_1.dividePrice)({ of: '$7.00', by: 1000000 }), // $7.00/1M tokens
182
+ },
183
+ },
184
+ gain: {
185
+ size: { context: { tokens: 128000 } }, // 128K context
186
+ grades: {},
187
+ cutoff: '2025-03-01',
188
+ domain: 'ALL',
189
+ skills: { tooluse: true },
190
+ },
191
+ }),
192
+ },
193
+ /**
194
+ * kimi-k2
195
+ * .sources:
196
+ * - rates: https://fireworks.ai/pricing ($1.00/1M input, $3.00/1M output)
197
+ * - context: 128K
198
+ * - architecture: 1T total (moe)
199
+ */
200
+ 'fireworks/kimi/k2': {
201
+ model: 'moonshotai/Kimi-K2-Instruct',
202
+ description: 'kimi-k2 - large general purpose (128K)',
203
+ spec: new rhachet_1.BrainSpec({
204
+ cost: {
205
+ time: {
206
+ speed: { tokens: 80, per: { seconds: 1 } },
207
+ latency: { seconds: 1 },
208
+ },
209
+ cash: {
210
+ per: 'token',
211
+ cache: {
212
+ get: (0, iso_price_1.asIsoPrice)('$0'),
213
+ set: (0, iso_price_1.asIsoPrice)('$0'),
214
+ },
215
+ input: (0, iso_price_1.dividePrice)({ of: '$1.00', by: 1000000 }), // $1.00/1M tokens
216
+ output: (0, iso_price_1.dividePrice)({ of: '$3.00', by: 1000000 }), // $3.00/1M tokens
217
+ },
218
+ },
219
+ gain: {
220
+ size: { context: { tokens: 128000 } }, // 128K context
221
+ grades: {},
222
+ cutoff: '2025-06-01',
223
+ domain: 'ALL',
224
+ skills: { tooluse: true },
225
+ },
226
+ }),
227
+ },
228
+ /**
229
+ * kimi-k2.5
230
+ * .sources:
231
+ * - rates: https://fireworks.ai/pricing ($0.50/1M input, $2.80/1M output)
232
+ * - context: 128K
233
+ * - swe-bench: 76.8% verified
234
+ */
235
+ 'fireworks/kimi/k2.5': {
236
+ model: 'moonshotai/Kimi-K2.5',
237
+ description: 'kimi-k2.5 - best swe-bench on fireworks ai (128K)',
238
+ spec: new rhachet_1.BrainSpec({
239
+ cost: {
240
+ time: {
241
+ speed: { tokens: 100, per: { seconds: 1 } },
242
+ latency: { seconds: 0.8 },
243
+ },
244
+ cash: {
245
+ per: 'token',
246
+ cache: {
247
+ get: (0, iso_price_1.asIsoPrice)('$0'),
248
+ set: (0, iso_price_1.asIsoPrice)('$0'),
249
+ },
250
+ input: (0, iso_price_1.dividePrice)({ of: '$0.50', by: 1000000 }), // $0.50/1M tokens
251
+ output: (0, iso_price_1.dividePrice)({ of: '$2.80', by: 1000000 }), // $2.80/1M tokens
252
+ },
253
+ },
254
+ gain: {
255
+ size: { context: { tokens: 128000 } }, // 128K context
256
+ grades: { swe: 76.8 }, // 76.8% swe-bench verified
257
+ cutoff: '2025-07-01',
258
+ domain: 'ALL',
259
+ skills: { tooluse: true },
260
+ },
261
+ }),
262
+ },
263
+ /**
264
+ * llama-4-maverick
265
+ * .sources:
266
+ * - rates: https://fireworks.ai/pricing ($0.27/1M input, $0.85/1M output)
267
+ * - context: 1M
268
+ * - architecture: 17B active, 128 experts (moe)
269
+ */
270
+ 'fireworks/llama4/maverick': {
271
+ model: 'meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8',
272
+ description: 'llama-4-maverick - large context (1M)',
273
+ spec: new rhachet_1.BrainSpec({
274
+ cost: {
275
+ time: {
276
+ speed: { tokens: 120, per: { seconds: 1 } },
277
+ latency: { seconds: 0.5 },
278
+ },
279
+ cash: {
280
+ per: 'token',
281
+ cache: {
282
+ get: (0, iso_price_1.asIsoPrice)('$0'),
283
+ set: (0, iso_price_1.asIsoPrice)('$0'),
284
+ },
285
+ input: (0, iso_price_1.dividePrice)({ of: '$0.27', by: 1000000 }), // $0.27/1M tokens
286
+ output: (0, iso_price_1.dividePrice)({ of: '$0.85', by: 1000000 }), // $0.85/1M tokens
287
+ },
288
+ },
289
+ gain: {
290
+ size: { context: { tokens: 1000000 } }, // 1M context
291
+ grades: {},
292
+ cutoff: '2025-03-01',
293
+ domain: 'ALL',
294
+ skills: { tooluse: true },
295
+ },
296
+ }),
297
+ },
298
+ /**
299
+ * llama-3.3-70b
300
+ * .sources:
301
+ * - rates: https://fireworks.ai/pricing ($0.88/1M input, $0.88/1M output)
302
+ * - context: 128K
303
+ * - architecture: 70B dense
304
+ */
305
+ 'fireworks/llama3.3/70b': {
306
+ model: 'meta-llama/Llama-3.3-70B-Instruct-Turbo',
307
+ description: 'llama-3.3-70b - balanced dense model (128K)',
308
+ spec: new rhachet_1.BrainSpec({
309
+ cost: {
310
+ time: {
311
+ speed: { tokens: 150, per: { seconds: 1 } },
312
+ latency: { seconds: 0.4 },
313
+ },
314
+ cash: {
315
+ per: 'token',
316
+ cache: {
317
+ get: (0, iso_price_1.asIsoPrice)('$0'),
318
+ set: (0, iso_price_1.asIsoPrice)('$0'),
319
+ },
320
+ input: (0, iso_price_1.dividePrice)({ of: '$0.88', by: 1000000 }), // $0.88/1M tokens
321
+ output: (0, iso_price_1.dividePrice)({ of: '$0.88', by: 1000000 }), // $0.88/1M tokens
322
+ },
323
+ },
324
+ gain: {
325
+ size: { context: { tokens: 128000 } }, // 128K context
326
+ grades: {},
327
+ cutoff: '2024-12-01',
328
+ domain: 'ALL',
329
+ skills: { tooluse: true },
330
+ },
331
+ }),
332
+ },
333
+ /**
334
+ * glm-4.7
335
+ * .sources:
336
+ * - rates: https://fireworks.ai/pricing ($0.45/1M input, $2.00/1M output)
337
+ * - context: 128K
338
+ * - swe-bench: 73.8% verified
339
+ */
340
+ 'fireworks/glm/4.7': {
341
+ model: 'zai-org/GLM-4.7',
342
+ description: 'glm-4.7 - strong code + general (128K)',
343
+ spec: new rhachet_1.BrainSpec({
344
+ cost: {
345
+ time: {
346
+ speed: { tokens: 100, per: { seconds: 1 } },
347
+ latency: { seconds: 0.8 },
348
+ },
349
+ cash: {
350
+ per: 'token',
351
+ cache: {
352
+ get: (0, iso_price_1.asIsoPrice)('$0'),
353
+ set: (0, iso_price_1.asIsoPrice)('$0'),
354
+ },
355
+ input: (0, iso_price_1.dividePrice)({ of: '$0.45', by: 1000000 }), // $0.45/1M tokens
356
+ output: (0, iso_price_1.dividePrice)({ of: '$2.00', by: 1000000 }), // $2.00/1M tokens
357
+ },
358
+ },
359
+ gain: {
360
+ size: { context: { tokens: 128000 } }, // 128K context
361
+ grades: { swe: 73.8 }, // 73.8% swe-bench verified
362
+ cutoff: '2025-06-01',
363
+ domain: 'ALL',
364
+ skills: { tooluse: true },
365
+ },
366
+ }),
367
+ },
368
+ };
369
+ //# sourceMappingURL=BrainAtom.config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BrainAtom.config.js","sourceRoot":"","sources":["../../../src/domain.operations/atom/BrainAtom.config.ts"],"names":[],"mappings":";;;AAAA,yCAAoD;AACpD,qCAAoC;AA4BpC;;;;;;;;GAQG;AACU,QAAA,mBAAmB,GAG5B;IACF;;;;;;;OAOG;IACH,4BAA4B,EAAE;QAC5B,KAAK,EAAE,2BAA2B;QAClC,WAAW,EAAE,0DAA0D;QACvE,IAAI,EAAE,IAAI,mBAAS,CAAC;YAClB,IAAI,EAAE;gBACJ,IAAI,EAAE;oBACJ,KAAK,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE;oBAC3C,OAAO,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE;iB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mB,EAAE;QACnB,KAAK,EAAE,iBAAiB;QACxB,WAAW,EAAE,wCAAwC;QACrD,IAAI,EAAE,IAAI,mBAAS,CAAC;YAClB,IAAI,EAAE;gBACJ,IAAI,EAAE;oBACJ,KAAK,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE;oBAC3C,OAAO,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE;iBAC1B;gBACD,IAAI,EAAE;oBACJ,GAAG,EAAE,OAAO;oBACZ,KAAK,EAAE;wBACL,GAAG,EAAE,IAAA,sBAAU,EAAC,IAAI,CAAC;wBACrB,GAAG,EAAE,IAAA,sBAAU,EAAC,IAAI,CAAC;qBACtB;oBACD,KAAK,EAAE,IAAA,uBAAW,EAAC,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAS,EAAE,CAAC,EAAE,kBAAkB;oBACtE,MAAM,EAAE,IAAA,uBAAW,EAAC,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAS,EAAE,CAAC,EAAE,kBAAkB;iBACxE;aACF;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,MAAO,EAAE,EAAE,EAAE,eAAe;gBACvD,MAAM,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,2BAA2B;gBAClD,MAAM,EAAE,YAAY;gBACpB,MAAM,EAAE,KAAK;gBACb,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;aAC1B;SACF,CAAC;KACH;CACF,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { BrainAtom } from 'rhachet/brains';
2
+ import { type FireworksBrainAtomSlug } from './BrainAtom.config';
3
+ export type { FireworksBrainAtomSlug } from './BrainAtom.config';
4
+ /**
5
+ * .what = factory to generate fireworks ai brain atom instances
6
+ * .why = enables model variant selection via slug
7
+ *
8
+ * .note = fireworks ai api is openai-compatible with baseURL override
9
+ *
10
+ * .example
11
+ * genBrainAtom({ slug: 'fireworks/qwen3/coder-next' })
12
+ * genBrainAtom({ slug: 'fireworks/llama3.3/70b' }) // fast + cheap
13
+ * genBrainAtom({ slug: 'fireworks/kimi/k2.5' }) // best swe-bench
14
+ */
15
+ export declare const genBrainAtom: (input: {
16
+ slug: FireworksBrainAtomSlug;
17
+ }) => BrainAtom;
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.genBrainAtom = void 0;
7
+ const helpful_errors_1 = require("helpful-errors");
8
+ const openai_1 = __importDefault(require("openai"));
9
+ const brains_1 = require("rhachet/brains");
10
+ const zod_1 = require("zod");
11
+ const castContentToOutputSchema_1 = require("../../infra/cast/castContentToOutputSchema");
12
+ const castFromFireworksToolCall_1 = require("../../infra/cast/castFromFireworksToolCall");
13
+ const castIntoFireworksToolDef_1 = require("../../infra/cast/castIntoFireworksToolDef");
14
+ const castIntoFireworksToolMessages_1 = require("../../infra/cast/castIntoFireworksToolMessages");
15
+ const BrainAtom_config_1 = require("./BrainAtom.config");
16
+ /**
17
+ * .what = factory to generate fireworks ai brain atom instances
18
+ * .why = enables model variant selection via slug
19
+ *
20
+ * .note = fireworks ai api is openai-compatible with baseURL override
21
+ *
22
+ * .example
23
+ * genBrainAtom({ slug: 'fireworks/qwen3/coder-next' })
24
+ * genBrainAtom({ slug: 'fireworks/llama3.3/70b' }) // fast + cheap
25
+ * genBrainAtom({ slug: 'fireworks/kimi/k2.5' }) // best swe-bench
26
+ */
27
+ const genBrainAtom = (input) => {
28
+ const config = BrainAtom_config_1.CONFIG_BY_ATOM_SLUG[input.slug];
29
+ return new brains_1.BrainAtom({
30
+ repo: 'fireworks',
31
+ slug: input.slug,
32
+ description: config.description,
33
+ spec: config.spec,
34
+ /**
35
+ * .what = stateless inference with optional tool use
36
+ * .why = provides direct model access for tasks
37
+ *
38
+ * .note = supports continuation via `on.episode`
39
+ * .note = supports tool use via `plugs.tools`
40
+ */
41
+ ask: async (askInput, context) => {
42
+ // track start time for elapsed duration
43
+ const startedAt = Date.now();
44
+ // compose system prompt from briefs
45
+ const systemPrompt = askInput.role.briefs
46
+ ? await (0, brains_1.castBriefsToPrompt)({ briefs: askInput.role.briefs })
47
+ : undefined;
48
+ // get openai client from context or create new one with fireworks ai baseURL
49
+ const openai = context?.openai ??
50
+ new openai_1.default({
51
+ apiKey: process.env.FIREWORKS_API_KEY,
52
+ baseURL: 'https://api.fireworks.ai/inference/v1',
53
+ });
54
+ // build messages array with prior exchanges for continuation
55
+ const messages = [];
56
+ if (systemPrompt) {
57
+ messages.push({ role: 'system', content: systemPrompt });
58
+ }
59
+ if (askInput.on?.episode) {
60
+ for (const exchange of askInput.on.episode.exchanges) {
61
+ messages.push({ role: 'user', content: exchange.input });
62
+ messages.push({ role: 'assistant', content: exchange.output });
63
+ }
64
+ }
65
+ // handle prompt: string or BrainPlugToolExecution[]
66
+ const promptIsToolExecutions = Array.isArray(askInput.prompt);
67
+ if (promptIsToolExecutions) {
68
+ // tool continuation: add assistant message with tool_calls, then tool messages
69
+ const executions = askInput.prompt;
70
+ // reconstruct assistant message with tool_calls from prior exchange
71
+ // note: this is needed because fireworks ai expects the assistant message before tool messages
72
+ const toolCalls = executions.map((exec) => ({
73
+ id: exec.exid,
74
+ type: 'function',
75
+ function: {
76
+ name: exec.slug,
77
+ arguments: JSON.stringify(exec.input),
78
+ },
79
+ }));
80
+ messages.push({
81
+ role: 'assistant',
82
+ content: null,
83
+ tool_calls: toolCalls,
84
+ });
85
+ // add tool result messages
86
+ const toolMessages = (0, castIntoFireworksToolMessages_1.castIntoFireworksToolMessages)({ executions });
87
+ messages.push(...toolMessages);
88
+ }
89
+ else {
90
+ // regular prompt
91
+ messages.push({ role: 'user', content: askInput.prompt });
92
+ }
93
+ // convert zod schema to json schema for structured output
94
+ const jsonSchema = zod_1.z.toJSONSchema(askInput.schema.output);
95
+ // convert tools to fireworks ai format if plugged
96
+ const tools = askInput.plugs?.tools?.map((tool) => (0, castIntoFireworksToolDef_1.castIntoFireworksToolDef)({ tool }));
97
+ // determine if tools are present and whether this is a continuation
98
+ const hasTools = tools && tools.length > 0;
99
+ const isToolContinuation = promptIsToolExecutions;
100
+ // fail-fast: tools + structured output schema not supported by most models
101
+ // vllm constraint: "model must not generate both text and tool calls in same generation"
102
+ // when tools are plugged, output schema must be z.string() to allow plain text responses
103
+ if (hasTools && !isToolContinuation) {
104
+ const schemaType = jsonSchema.type;
105
+ if (schemaType !== 'string') {
106
+ throw new helpful_errors_1.BadRequestError(`when tools are plugged, output schema must be z.string() (found: ${schemaType}). most open-source models support either tool_calls or structured json, but not both. use z.string() and parse the response yourself if structure is needed.`, { schemaType, tools: askInput.plugs?.tools?.map((t) => t.slug) });
107
+ }
108
+ }
109
+ // include response_format only when we want structured output (not tool calls)
110
+ // vllm constraint: "model must not generate both text and tool calls in same generation"
111
+ // when response_format is present, model outputs json content, not tool_calls
112
+ // so we omit response_format on initial tool requests to enable tool call
113
+ const wantsToolCalls = hasTools && !isToolContinuation;
114
+ const wantStructuredOutput = !wantsToolCalls;
115
+ const response = await openai.chat.completions.create({
116
+ model: config.model,
117
+ messages,
118
+ ...(hasTools ? { tools, tool_choice: 'auto' } : {}),
119
+ ...(wantStructuredOutput
120
+ ? {
121
+ response_format: {
122
+ type: 'json_schema',
123
+ json_schema: {
124
+ name: 'response',
125
+ strict: true,
126
+ schema: jsonSchema,
127
+ },
128
+ },
129
+ }
130
+ : {}),
131
+ });
132
+ // extract response message
133
+ const message = response.choices[0]?.message;
134
+ const content = message?.content ?? '';
135
+ const toolCalls = message?.tool_calls;
136
+ // calculate elapsed time
137
+ const elapsedMs = Date.now() - startedAt;
138
+ // extract token usage from response
139
+ const tokensInput = response.usage?.prompt_tokens ?? 0;
140
+ const tokensOutput = response.usage?.completion_tokens ?? 0;
141
+ const tokensCached = response.usage?.prompt_tokens_details?.cached_tokens ?? 0;
142
+ // calculate character counts
143
+ const promptLength = promptIsToolExecutions
144
+ ? JSON.stringify(askInput.prompt).length
145
+ : askInput.prompt.length;
146
+ const charsInput = (systemPrompt?.length ?? 0) + promptLength;
147
+ const charsOutput = content.length;
148
+ // define size for metrics and cost calculation
149
+ const size = {
150
+ tokens: {
151
+ input: tokensInput,
152
+ output: tokensOutput,
153
+ cache: { get: tokensCached, set: 0 },
154
+ },
155
+ chars: {
156
+ input: charsInput,
157
+ output: charsOutput,
158
+ cache: { get: 0, set: 0 },
159
+ },
160
+ };
161
+ // calculate cash costs via rhachet utility
162
+ const { cash } = (0, brains_1.calcBrainOutputCost)({
163
+ for: { tokens: size.tokens },
164
+ with: { cost: { cash: config.spec.cost.cash } },
165
+ });
166
+ // build metrics
167
+ const metrics = new brains_1.BrainOutputMetrics({
168
+ size,
169
+ cost: {
170
+ time: { milliseconds: elapsedMs },
171
+ cash,
172
+ },
173
+ });
174
+ // handle tool calls if present
175
+ if (toolCalls && toolCalls.length > 0) {
176
+ // brain requested tool invocations
177
+ const invocations = toolCalls.map((toolCall) => (0, castFromFireworksToolCall_1.castFromFireworksToolCall)({ toolCall }));
178
+ // build continuables for tool call exchange
179
+ const { episode, series } = await (0, brains_1.genBrainContinuables)({
180
+ for: { grain: 'atom' },
181
+ on: { episode: askInput.on?.episode ?? null, series: null },
182
+ with: {
183
+ exchange: {
184
+ input: promptIsToolExecutions
185
+ ? JSON.stringify(askInput.prompt)
186
+ : askInput.prompt,
187
+ output: JSON.stringify(toolCalls),
188
+ exid: response.id ?? null,
189
+ },
190
+ episode: { exid: response.id ?? null },
191
+ },
192
+ });
193
+ // note: cast input because TypeScript can't verify conditional types at construction
194
+ return new brains_1.BrainOutput({
195
+ output: null,
196
+ calls: { tools: invocations },
197
+ metrics,
198
+ episode,
199
+ series,
200
+ });
201
+ }
202
+ // parse response content based on schema type
203
+ const output = (0, castContentToOutputSchema_1.castContentToOutputSchema)({
204
+ content,
205
+ schema: askInput.schema.output,
206
+ });
207
+ // build continuables (episode + series) for this invocation
208
+ const { episode, series } = await (0, brains_1.genBrainContinuables)({
209
+ for: { grain: 'atom' },
210
+ on: { episode: askInput.on?.episode ?? null, series: null },
211
+ with: {
212
+ exchange: {
213
+ input: promptIsToolExecutions
214
+ ? JSON.stringify(askInput.prompt)
215
+ : askInput.prompt,
216
+ output: content,
217
+ exid: response.id ?? null,
218
+ },
219
+ episode: { exid: response.id ?? null },
220
+ },
221
+ });
222
+ // note: cast input because TypeScript can't verify conditional types at construction
223
+ return new brains_1.BrainOutput({
224
+ output,
225
+ calls: null,
226
+ metrics,
227
+ episode,
228
+ series,
229
+ });
230
+ },
231
+ });
232
+ };
233
+ exports.genBrainAtom = genBrainAtom;
234
+ //# sourceMappingURL=genBrainAtom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"genBrainAtom.js","sourceRoot":"","sources":["../../../src/domain.operations/atom/genBrainAtom.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAiD;AACjD,oDAA4B;AAC5B,2CAWwB;AAIxB,6BAAwB;AAExB,0FAAuF;AACvF,0FAAuF;AACvF,wFAAqF;AACrF,kGAA+F;AAC/F,yDAG4B;AAK5B;;;;;;;;;;GAUG;AACI,MAAM,YAAY,GAAG,CAAC,KAE5B,EAAa,EAAE;IACd,MAAM,MAAM,GAAG,sCAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE/C,OAAO,IAAI,kBAAS,CAAC;QACnB,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,IAAI,EAAE,MAAM,CAAC,IAAI;QAEjB;;;;;;WAMG;QACH,GAAG,EAAE,KAAK,EACR,QAMC,EACD,OAAe,EACgC,EAAE;YACjD,wCAAwC;YACxC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAE7B,oCAA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,CAAC;YAED,8CAA8C;YAC9C,MAAM,MAAM,GAAG,IAAA,qDAAyB,EAAC;gBACvC,OAAO;gBACP,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM;aAC/B,CAAC,CAAC;YAEH,4DAA4D;YAC5D,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,IAAA,6BAAoB,EAAC;gBACrD,GAAG,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;gBACtB,EAAE,EAAE,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;gBAC3D,IAAI,EAAE;oBACJ,QAAQ,EAAE;wBACR,KAAK,EAAE,sBAAsB;4BAC3B,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;4BACjC,CAAC,CAAE,QAAQ,CAAC,MAAiB;wBAC/B,MAAM,EAAE,OAAO;wBACf,IAAI,EAAE,QAAQ,CAAC,EAAE,IAAI,IAAI;qBAC1B;oBACD,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,IAAI,IAAI,EAAE;iBACvC;aACF,CAAC,CAAC;YAEH,qFAAqF;YACrF,OAAO,IAAI,oBAAW,CAAC;gBACrB,MAAM;gBACN,KAAK,EAAE,IAAI;gBACX,OAAO;gBACP,OAAO;gBACP,MAAM;aAC4C,CAAC,CAAC;QACxD,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAhQW,QAAA,YAAY,gBAgQvB"}
@@ -0,0 +1 @@
1
+ export * from './contract/sdk';
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./contract/sdk"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B"}
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * .what = parses api response content based on schema type
4
+ * .why = object schemas need JSON.parse; string schemas take content directly
5
+ *
6
+ * .note = string schemas (plain or nullable) receive plain text from api
7
+ * because vllm constraint requires z.string() for tool use output
8
+ */
9
+ export declare const castContentToOutputSchema: <T>(input: {
10
+ content: string;
11
+ schema: z.Schema<T>;
12
+ }) => T;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.castContentToOutputSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * .what = parses api response content based on schema type
7
+ * .why = object schemas need JSON.parse; string schemas take content directly
8
+ *
9
+ * .note = string schemas (plain or nullable) receive plain text from api
10
+ * because vllm constraint requires z.string() for tool use output
11
+ */
12
+ const castContentToOutputSchema = (input) => {
13
+ const jsonSchema = zod_1.z.toJSONSchema(input.schema);
14
+ // detect string-like schemas: plain string or nullable string (anyOf with string + null)
15
+ const isStringSchema = (() => {
16
+ if (jsonSchema.type === 'string')
17
+ return true;
18
+ if (jsonSchema.anyOf) {
19
+ const types = jsonSchema.anyOf.map((s) => s.type).filter(Boolean);
20
+ // nullable string: anyOf with string and null only
21
+ return (types.length === 2 && types.includes('string') && types.includes('null'));
22
+ }
23
+ return false;
24
+ })();
25
+ // string schemas: parse content directly (no JSON.parse)
26
+ if (isStringSchema) {
27
+ return input.schema.parse(input.content);
28
+ }
29
+ // object/array schemas: JSON parse first
30
+ return input.schema.parse(JSON.parse(input.content));
31
+ };
32
+ exports.castContentToOutputSchema = castContentToOutputSchema;
33
+ //# sourceMappingURL=castContentToOutputSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"castContentToOutputSchema.js","sourceRoot":"","sources":["../../../src/infra/cast/castContentToOutputSchema.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB;;;;;;GAMG;AACI,MAAM,yBAAyB,GAAG,CAAI,KAG5C,EAAK,EAAE;IACN,MAAM,UAAU,GAAG,OAAC,CAAC,YAAY,CAAC,KAAK,CAAC,MAAM,CAG7C,CAAC;IAEF,yFAAyF;IACzF,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE;QAC3B,IAAI,UAAU,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QAC9C,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;YACrB,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAClE,mDAAmD;YACnD,OAAO,CACL,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CACzE,CAAC;QACJ,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,EAAE,CAAC;IAEL,yDAAyD;IACzD,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,yCAAyC;IACzC,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;AACvD,CAAC,CAAC;AA7BW,QAAA,yBAAyB,6BA6BpC"}
@@ -0,0 +1,14 @@
1
+ import type OpenAI from 'openai';
2
+ import type { BrainPlugToolInvocation } from 'rhachet/brains';
3
+ /**
4
+ * .what = converts a fireworks ai / openai tool call to rhachet invocation
5
+ * .why = enables callers to receive typed tool invocations from the brain
6
+ *
7
+ * .note = fireworks ai uses openai's tool_calls format:
8
+ * - id: string (maps to exid)
9
+ * - function.name: string (maps to slug)
10
+ * - function.arguments: JSON string (parsed to input)
11
+ */
12
+ export declare const castFromFireworksToolCall: (input: {
13
+ toolCall: OpenAI.ChatCompletionMessageToolCall;
14
+ }) => BrainPlugToolInvocation;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.castFromFireworksToolCall = void 0;
4
+ /**
5
+ * .what = converts a fireworks ai / openai tool call to rhachet invocation
6
+ * .why = enables callers to receive typed tool invocations from the brain
7
+ *
8
+ * .note = fireworks ai uses openai's tool_calls format:
9
+ * - id: string (maps to exid)
10
+ * - function.name: string (maps to slug)
11
+ * - function.arguments: JSON string (parsed to input)
12
+ */
13
+ const castFromFireworksToolCall = (input) => {
14
+ // parse arguments from JSON string
15
+ const parsedInput = JSON.parse(input.toolCall.function.arguments);
16
+ return {
17
+ exid: input.toolCall.id,
18
+ slug: input.toolCall.function.name,
19
+ input: parsedInput,
20
+ };
21
+ };
22
+ exports.castFromFireworksToolCall = castFromFireworksToolCall;
23
+ //# sourceMappingURL=castFromFireworksToolCall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"castFromFireworksToolCall.js","sourceRoot":"","sources":["../../../src/infra/cast/castFromFireworksToolCall.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;GAQG;AACI,MAAM,yBAAyB,GAAG,CAAC,KAEzC,EAA2B,EAAE;IAC5B,mCAAmC;IACnC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAElE,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE;QACvB,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI;QAClC,KAAK,EAAE,WAAW;KACnB,CAAC;AACJ,CAAC,CAAC;AAXW,QAAA,yBAAyB,6BAWpC"}
@@ -0,0 +1,13 @@
1
+ import type OpenAI from 'openai';
2
+ import type { BrainPlugToolDefinition } from 'rhachet/brains';
3
+ /**
4
+ * .what = converts a rhachet tool definition to fireworks ai / openai format
5
+ * .why = enables tool use via fireworks ai's openai-compatible api
6
+ *
7
+ * .note = fireworks ai uses openai's function call format:
8
+ * - type: 'function'
9
+ * - function: { name, description, parameters, strict }
10
+ */
11
+ export declare const castIntoFireworksToolDef: (input: {
12
+ tool: BrainPlugToolDefinition;
13
+ }) => OpenAI.ChatCompletionTool;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.castIntoFireworksToolDef = void 0;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * .what = converts a rhachet tool definition to fireworks ai / openai format
7
+ * .why = enables tool use via fireworks ai's openai-compatible api
8
+ *
9
+ * .note = fireworks ai uses openai's function call format:
10
+ * - type: 'function'
11
+ * - function: { name, description, parameters, strict }
12
+ */
13
+ const castIntoFireworksToolDef = (input) => {
14
+ // convert zod schema to json schema for function parameters
15
+ const parametersSchema = zod_1.z.toJSONSchema(input.tool.schema.input);
16
+ return {
17
+ type: 'function',
18
+ function: {
19
+ name: input.tool.slug,
20
+ description: input.tool.description,
21
+ parameters: parametersSchema,
22
+ strict: true,
23
+ },
24
+ };
25
+ };
26
+ exports.castIntoFireworksToolDef = castIntoFireworksToolDef;
27
+ //# sourceMappingURL=castIntoFireworksToolDef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"castIntoFireworksToolDef.js","sourceRoot":"","sources":["../../../src/infra/cast/castIntoFireworksToolDef.ts"],"names":[],"mappings":";;;AAEA,6BAAwB;AAExB;;;;;;;GAOG;AACI,MAAM,wBAAwB,GAAG,CAAC,KAExC,EAA6B,EAAE;IAC9B,4DAA4D;IAC5D,MAAM,gBAAgB,GAAG,OAAC,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAEjE,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE;YACR,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI;YACrB,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW;YACnC,UAAU,EAAE,gBAAgB;YAC5B,MAAM,EAAE,IAAI;SACb;KACF,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,wBAAwB,4BAenC"}
@@ -0,0 +1,14 @@
1
+ import type OpenAI from 'openai';
2
+ import type { BrainPlugToolExecution } from 'rhachet/brains';
3
+ /**
4
+ * .what = converts rhachet tool executions to fireworks ai / openai tool messages
5
+ * .why = enables tool result continuation in the brain conversation
6
+ *
7
+ * .note = fireworks ai uses openai's tool message format:
8
+ * - role: 'tool'
9
+ * - tool_call_id: string (from execution.exid)
10
+ * - content: string (JSON stringified output or error)
11
+ */
12
+ export declare const castIntoFireworksToolMessages: (input: {
13
+ executions: BrainPlugToolExecution[];
14
+ }) => OpenAI.ChatCompletionToolMessageParam[];
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.castIntoFireworksToolMessages = void 0;
4
+ /**
5
+ * .what = converts rhachet tool executions to fireworks ai / openai tool messages
6
+ * .why = enables tool result continuation in the brain conversation
7
+ *
8
+ * .note = fireworks ai uses openai's tool message format:
9
+ * - role: 'tool'
10
+ * - tool_call_id: string (from execution.exid)
11
+ * - content: string (JSON stringified output or error)
12
+ */
13
+ const castIntoFireworksToolMessages = (input) => {
14
+ return input.executions.map((execution) => {
15
+ // format content based on signal
16
+ const content = execution.signal === 'success'
17
+ ? JSON.stringify(execution.output)
18
+ : JSON.stringify({
19
+ error: execution.output.error.message,
20
+ signal: execution.signal,
21
+ });
22
+ return {
23
+ role: 'tool',
24
+ tool_call_id: execution.exid,
25
+ content,
26
+ };
27
+ });
28
+ };
29
+ exports.castIntoFireworksToolMessages = castIntoFireworksToolMessages;
30
+ //# sourceMappingURL=castIntoFireworksToolMessages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"castIntoFireworksToolMessages.js","sourceRoot":"","sources":["../../../src/infra/cast/castIntoFireworksToolMessages.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;GAQG;AACI,MAAM,6BAA6B,GAAG,CAAC,KAE7C,EAA2C,EAAE;IAC5C,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;QACxC,iCAAiC;QACjC,MAAM,OAAO,GACX,SAAS,CAAC,MAAM,KAAK,SAAS;YAC5B,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC;YAClC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;gBACb,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO;gBACrC,MAAM,EAAE,SAAS,CAAC,MAAM;aACzB,CAAC,CAAC;QAET,OAAO;YACL,IAAI,EAAE,MAAe;YACrB,YAAY,EAAE,SAAS,CAAC,IAAI;YAC5B,OAAO;SACR,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAnBW,QAAA,6BAA6B,iCAmBxC"}
package/license.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 ehmpathy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,110 @@
1
+ {
2
+ "name": "rhachet-brains-fireworksai",
3
+ "author": "ehmpathy",
4
+ "description": "rhachet brain.atom adapter for fireworks ai open-source models",
5
+ "version": "0.0.0",
6
+ "repository": "ehmpathy/rhachet-brains-fireworksai",
7
+ "homepage": "https://github.com/ehmpathy/rhachet-brains-fireworksai",
8
+ "keywords": [
9
+ "fireworks",
10
+ "fireworksai",
11
+ "qwen",
12
+ "deepseek",
13
+ "llama",
14
+ "open-source",
15
+ "rhachet",
16
+ "brain",
17
+ "llm",
18
+ "ai"
19
+ ],
20
+ "bugs": "https://github.com/ehmpathy/rhachet-brains-fireworksai/issues",
21
+ "license": "MIT",
22
+ "main": "dist/index.js",
23
+ "engines": {
24
+ "node": ">=8.0.0"
25
+ },
26
+ "files": [
27
+ "/dist"
28
+ ],
29
+ "dependencies": {
30
+ "domain-objects": "0.31.9",
31
+ "helpful-errors": "1.5.3",
32
+ "iso-price": "1.1.1",
33
+ "openai": "5.8.2",
34
+ "rhachet-artifact": "1.0.1",
35
+ "rhachet-artifact-git": "1.1.5",
36
+ "rhachet-roles-bhrain": "0.27.8",
37
+ "type-fns": "1.21.0",
38
+ "zod": "4.3.4"
39
+ },
40
+ "peerDependencies": {
41
+ "rhachet": ">=1.21.4"
42
+ },
43
+ "devDependencies": {
44
+ "@biomejs/biome": "2.3.8",
45
+ "@commitlint/cli": "19.5.0",
46
+ "@commitlint/config-conventional": "19.5.0",
47
+ "@swc/core": "1.15.3",
48
+ "@swc/jest": "0.2.39",
49
+ "@tsconfig/node20": "20.1.5",
50
+ "@tsconfig/strictest": "2.0.5",
51
+ "@types/jest": "30.0.0",
52
+ "@types/node": "22.15.21",
53
+ "cz-conventional-changelog": "3.3.0",
54
+ "declapract": "0.13.14",
55
+ "declapract-typescript-ehmpathy": "0.47.16",
56
+ "declastruct": "1.7.3",
57
+ "declastruct-github": "1.3.0",
58
+ "depcheck": "1.4.3",
59
+ "esbuild-register": "3.6.0",
60
+ "husky": "8.0.3",
61
+ "jest": "30.2.0",
62
+ "rhachet": "1.41.15",
63
+ "rhachet-brains-anthropic": "0.4.1",
64
+ "rhachet-roles-bhuild": "0.21.13",
65
+ "rhachet-roles-ehmpathy": "1.35.12",
66
+ "test-fns": "1.10.0",
67
+ "tsc-alias": "1.8.10",
68
+ "tsx": "4.20.6",
69
+ "typescript": "5.4.5",
70
+ "yalc": "1.0.0-pre.53"
71
+ },
72
+ "config": {
73
+ "commitizen": {
74
+ "path": "./node_modules/cz-conventional-changelog"
75
+ }
76
+ },
77
+ "scripts": {
78
+ "build:ts": "tsc -p ./tsconfig.build.json",
79
+ "commit:with-cli": "npx cz",
80
+ "fix:format:biome": "biome check --write",
81
+ "fix:format": "npm run fix:format:biome",
82
+ "fix:lint": "biome check --write",
83
+ "fix": "npm run fix:format && npm run fix:lint",
84
+ "build:clean:bun": "rm -f ./bin/*.bc",
85
+ "build:clean:tsc": "(chmod -R u+w dist 2>/dev/null || true) && rm -rf dist/",
86
+ "build:clean": "npm run build:clean:tsc && npm run build:clean:bun",
87
+ "build:compile:tsc": "tsc -p ./tsconfig.build.json && tsc-alias -p ./tsconfig.build.json",
88
+ "build:compile": "npm run build:compile:tsc && npm run build:compile:bun --if-present",
89
+ "build": "npm run build:clean && npm run build:compile && npm run build:complete --if-present",
90
+ "test:commits": "LAST_TAG=$(git describe --tags --abbrev=0 @^ 2> /dev/null || git rev-list --max-parents=0 HEAD) && npx commitlint --from $LAST_TAG --to HEAD --verbose",
91
+ "test:types": "tsc -p ./tsconfig.json --noEmit",
92
+ "test:format:biome": "biome format",
93
+ "test:format": "npm run test:format:biome",
94
+ "test:lint:deps": "npx depcheck -c ./.depcheckrc.yml",
95
+ "test:lint:biome": "biome check --diagnostic-level=error",
96
+ "test:lint:biome:all": "biome check",
97
+ "test:lint": "npm run test:lint:biome && npm run test:lint:deps",
98
+ "test:unit": "jest -c ./jest.unit.config.ts --forceExit --verbose --passWithNoTests $([ -z $THOROUGH ] && echo '--changedSince=main') $([ -n $RESNAP ] && echo '--updateSnapshot')",
99
+ "test:integration": "jest -c ./jest.integration.config.ts --forceExit --verbose --passWithNoTests $([ -z $THOROUGH ] && echo '--changedSince=main') $([ -n $RESNAP ] && echo '--updateSnapshot')",
100
+ "test:acceptance:locally": "npm run build && LOCALLY=true jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests $([ -n $RESNAP ] && echo '--updateSnapshot')",
101
+ "test": "npm run test:commits && npm run test:types && npm run test:format && npm run test:lint && npm run test:unit && npm run test:integration && npm run test:acceptance:locally",
102
+ "test:acceptance": "npm run build && jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests $([ -n $RESNAP ] && echo '--updateSnapshot')",
103
+ "prepush": "npm run test && npm run build",
104
+ "prepublish": "npm run build",
105
+ "preversion": "npm run prepush",
106
+ "postversion": "git push origin HEAD --tags --no-verify",
107
+ "prepare:husky": "husky install && chmod ug+x .husky/*",
108
+ "prepare:rhachet": "npm run build && rhachet init --hooks --roles mechanic behaver driver reviewer librarian ergonomist architect reflector dreamer"
109
+ }
110
+ }
package/readme.md ADDED
@@ -0,0 +1,85 @@
1
+ # rhachet-brains-fireworksai
2
+
3
+ rhachet brain.atom adapter for fireworks ai open-source models
4
+
5
+ ## install
6
+
7
+ ```sh
8
+ npm install rhachet-brains-fireworksai
9
+ ```
10
+
11
+ ## usage
12
+
13
+ ```ts
14
+ import { genBrainAtom } from 'rhachet-brains-fireworksai';
15
+ import { z } from 'zod';
16
+
17
+ // create a brain atom for direct model inference
18
+ const brainAtom = genBrainAtom({ slug: 'fireworks/qwen3/coder-next' });
19
+
20
+ // simple string output
21
+ const { output: explanation } = await brainAtom.ask({
22
+ role: { briefs: [] },
23
+ prompt: 'explain this code',
24
+ schema: { output: z.string() },
25
+ });
26
+
27
+ // structured object output
28
+ const { output: { summary, issues } } = await brainAtom.ask({
29
+ role: { briefs: [] },
30
+ prompt: 'analyze this code',
31
+ schema: { output: z.object({ summary: z.string(), issues: z.array(z.string()) }) },
32
+ });
33
+ ```
34
+
35
+ ## available brains
36
+
37
+ ### atoms (via genBrainAtom)
38
+
39
+ stateless inference without tool use.
40
+
41
+ | slug | model id | context | swe-bench | input | output |
42
+ | --- | --- | --- | --- | --- | --- |
43
+ | `fireworks/qwen3/coder-next` | Qwen/Qwen3-Coder-Next-FP8 | 262K | 74.2% | $0.50/1M | $1.20/1M |
44
+ | `fireworks/qwen3/coder-480b` | Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8 | 262K | 69.6% | $2.00/1M | $2.00/1M |
45
+ | `fireworks/qwen3/235b` | Qwen/Qwen3-235B-A22B-Instruct-2507-tput | 131K | — | $0.20/1M | $0.60/1M |
46
+ | `fireworks/deepseek/v3.1` | deepseek-ai/DeepSeek-V3.1 | 128K | — | $1.25/1M | $1.25/1M |
47
+ | `fireworks/deepseek/r1` | deepseek-ai/DeepSeek-R1 | 128K | — | $3.00/1M | $7.00/1M |
48
+ | `fireworks/kimi/k2` | moonshotai/Kimi-K2-Instruct | 128K | — | $1.00/1M | $3.00/1M |
49
+ | `fireworks/kimi/k2.5` | moonshotai/Kimi-K2.5 | 128K | 76.8% | $0.50/1M | $2.80/1M |
50
+ | `fireworks/llama4/maverick` | meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8 | 1M | — | $0.27/1M | $0.85/1M |
51
+ | `fireworks/llama3.3/70b` | meta-llama/Llama-3.3-70B-Instruct-Turbo | 128K | — | $0.88/1M | $0.88/1M |
52
+ | `fireworks/glm/4.7` | zai-org/GLM-4.7 | 128K | 73.8% | $0.45/1M | $2.00/1M |
53
+
54
+ ## why fireworks ai
55
+
56
+ fireworks ai rates include managed fine-tune access ($6-10/1M tokens) and high-throughput serverless infrastructure. some model authors offer cheaper direct apis for inference-only:
57
+
58
+ | model | fireworks ai (in/out) | author direct (in/out) | author api |
59
+ | --- | --- | --- | --- |
60
+ | deepseek v3 | $1.25/$1.25 | **$0.28/$0.42** (3-4x cheaper) | [api.deepseek.com](https://api-docs.deepseek.com/quick_start/pricing) |
61
+ | deepseek r1 | $3.00/$7.00 | **$0.28/$0.42** (10-17x cheaper) | [api.deepseek.com](https://api-docs.deepseek.com/quick_start/pricing) |
62
+ | kimi k2 | $1.00/$3.00 | **$0.60/$2.50** (~35% cheaper) | [platform.moonshot.ai](https://platform.moonshot.ai/docs/pricing/chat) |
63
+ | kimi k2.5 | $0.50/$2.80 | $0.60/$3.00 (at parity) | [platform.moonshot.ai](https://platform.moonshot.ai/docs/pricing/chat) |
64
+ | qwen3 coder-next | **$0.50/$1.20** | $1.00/$5.00 (fireworks ai cheaper) | [alibabacloud.com](https://www.alibabacloud.com/help/en/model-studio/model-pricing) |
65
+ | glm-4.7 | **$0.45/$2.00** | $0.60/$2.20 (fireworks ai cheaper) | [z.ai](https://docs.z.ai/guides/overview/pricing) |
66
+ | llama 4 maverick | $0.27/$0.85 | ~$0.27/$0.85 (at parity) | [llama.com](https://www.llama.com/products/llama-api/) |
67
+
68
+ **tldr:** deepseek's direct api is dramatically cheaper. kimi k2 is modestly cheaper via moonshot. the rest are at parity or more expensive than fireworks ai. fireworks ai's premium buys fine-tune access and unified multi-model infrastructure.
69
+
70
+ ## environment
71
+
72
+ requires `FIREWORKS_API_KEY` environment variable.
73
+
74
+ get your api key at https://api.fireworks.ai/inference/settings/api-keys
75
+
76
+ ## sources
77
+
78
+ - [fireworks ai api docs](https://docs.fireworks.ai/reference/chat-completions-1)
79
+ - [fireworks ai models](https://docs.fireworks.ai/docs/serverless-models)
80
+ - [fireworks ai rates](https://fireworks.ai/pricing)
81
+ - [deepseek rates](https://api-docs.deepseek.com/quick_start/pricing)
82
+ - [moonshot rates](https://platform.moonshot.ai/docs/pricing/chat)
83
+ - [alibaba model studio rates](https://www.alibabacloud.com/help/en/model-studio/model-pricing)
84
+ - [zhipu z.ai rates](https://docs.z.ai/guides/overview/pricing)
85
+ - [meta llama api](https://www.llama.com/products/llama-api/)