rhachet-brains-xai 0.1.3 → 0.2.1

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.
@@ -8,11 +8,14 @@ const genBrainAtom_1 = require("../../domain.operations/atom/genBrainAtom");
8
8
  */
9
9
  const getBrainAtomsByXAI = () => {
10
10
  return [
11
- (0, genBrainAtom_1.genBrainAtom)({ slug: 'xai/grok-code-fast-1' }),
12
- (0, genBrainAtom_1.genBrainAtom)({ slug: 'xai/grok-3' }),
13
- (0, genBrainAtom_1.genBrainAtom)({ slug: 'xai/grok-3-mini' }),
14
- (0, genBrainAtom_1.genBrainAtom)({ slug: 'xai/grok-4' }),
15
- (0, genBrainAtom_1.genBrainAtom)({ slug: 'xai/grok-4-fast' }),
11
+ (0, genBrainAtom_1.genBrainAtom)({ slug: 'xai/grok/code-fast-1' }),
12
+ (0, genBrainAtom_1.genBrainAtom)({ slug: 'xai/grok/3' }),
13
+ (0, genBrainAtom_1.genBrainAtom)({ slug: 'xai/grok/3-mini' }),
14
+ (0, genBrainAtom_1.genBrainAtom)({ slug: 'xai/grok/4' }),
15
+ (0, genBrainAtom_1.genBrainAtom)({ slug: 'xai/grok/4-fast-wout-reason' }),
16
+ (0, genBrainAtom_1.genBrainAtom)({ slug: 'xai/grok/4-fast-with-reason' }),
17
+ (0, genBrainAtom_1.genBrainAtom)({ slug: 'xai/grok/4.1-fast-wout-reason' }),
18
+ (0, genBrainAtom_1.genBrainAtom)({ slug: 'xai/grok/4.1-fast-with-reason' }),
16
19
  ];
17
20
  };
18
21
  exports.getBrainAtomsByXAI = getBrainAtomsByXAI;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/contract/sdk/index.ts"],"names":[],"mappings":";;;AAEA,4EAAyE;AAEzE;;;GAGG;AACI,MAAM,kBAAkB,GAAG,GAAgB,EAAE;IAClD,OAAO;QACL,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC;QAC9C,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;QACpC,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;QACzC,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;QACpC,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;KAC1C,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,kBAAkB,sBAQ7B;AAEF,sCAAsC;AACtC,0EAAyE;AAAhE,4GAAA,YAAY,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/contract/sdk/index.ts"],"names":[],"mappings":";;;AAEA,4EAAyE;AAEzE;;;GAGG;AACI,MAAM,kBAAkB,GAAG,GAAgB,EAAE;IAClD,OAAO;QACL,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC;QAC9C,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;QACpC,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;QACzC,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;QACpC,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,6BAA6B,EAAE,CAAC;QACrD,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,6BAA6B,EAAE,CAAC;QACrD,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,+BAA+B,EAAE,CAAC;QACvD,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,+BAA+B,EAAE,CAAC;KACxD,CAAC;AACJ,CAAC,CAAC;AAXW,QAAA,kBAAkB,sBAW7B;AAEF,sCAAsC;AACtC,0EAAyE;AAAhE,4GAAA,YAAY,OAAA"}
@@ -0,0 +1,26 @@
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 xai atom slugs
13
+ * .why = enables type-safe slug specification with model variants
14
+ */
15
+ export type XaiBrainAtomSlug = 'xai/grok/code-fast-1' | 'xai/grok/3' | 'xai/grok/3-mini' | 'xai/grok/4' | 'xai/grok/4-fast-wout-reason' | 'xai/grok/4-fast-with-reason' | 'xai/grok/4.1-fast-wout-reason' | 'xai/grok/4.1-fast-with-reason';
16
+ /**
17
+ * .what = model configuration by slug
18
+ * .why = maps slugs to api model names, descriptions, and specs
19
+ *
20
+ * .sources:
21
+ * - rates: https://docs.x.ai/docs/models
22
+ * - grok-code-fast-1: https://x.ai/news/grok-code-fast-1
23
+ * - grok-4 benchmarks: https://x.ai/news/grok-4
24
+ * - api docs: https://docs.x.ai/docs
25
+ */
26
+ export declare const CONFIG_BY_ATOM_SLUG: Record<XaiBrainAtomSlug, BrainAtomConfig>;
@@ -0,0 +1,305 @@
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://docs.x.ai/docs/models
12
+ * - grok-code-fast-1: https://x.ai/news/grok-code-fast-1
13
+ * - grok-4 benchmarks: https://x.ai/news/grok-4
14
+ * - api docs: https://docs.x.ai/docs
15
+ */
16
+ exports.CONFIG_BY_ATOM_SLUG = {
17
+ /**
18
+ * grok-code-fast-1
19
+ * .sources:
20
+ * - rates: https://x.ai/news/grok-code-fast-1 ($0.20/1M input, $1.50/1M output, $0.02/1M cached)
21
+ * - context: https://x.ai/news/grok-code-fast-1 (256K)
22
+ * - cutoff: https://x.ai/news/grok-code-fast-1 (march 2025)
23
+ * - swe-bench: https://x.ai/news/grok-code-fast-1 (70.8%)
24
+ */
25
+ 'xai/grok/code-fast-1': {
26
+ model: 'grok-code-fast-1',
27
+ description: 'grok-code-fast-1 - optimized for agentic code (256K)',
28
+ spec: new rhachet_1.BrainSpec({
29
+ cost: {
30
+ time: {
31
+ speed: { tokens: 200, per: { seconds: 1 } },
32
+ latency: { seconds: 0.5 },
33
+ },
34
+ cash: {
35
+ per: 'token',
36
+ cache: {
37
+ get: (0, iso_price_1.dividePrice)({ of: '$0.02', by: 1000000 }), // $0.02/1M cached
38
+ set: (0, iso_price_1.asIsoPrice)('$0'),
39
+ },
40
+ input: (0, iso_price_1.dividePrice)({ of: '$0.20', by: 1000000 }), // $0.20/1M tokens
41
+ output: (0, iso_price_1.dividePrice)({ of: '$1.50', by: 1000000 }), // $1.50/1M tokens
42
+ },
43
+ },
44
+ gain: {
45
+ size: { context: { tokens: 256000 } }, // 256K context
46
+ grades: { swe: 70.8 }, // 70.8% swe-bench verified
47
+ cutoff: '2025-03-01', // march 2025
48
+ domain: 'SOFTWARE',
49
+ skills: { tooluse: true },
50
+ },
51
+ }),
52
+ },
53
+ /**
54
+ * grok-3
55
+ * .sources:
56
+ * - rates: https://docs.x.ai/docs/models ($3/1M input, $15/1M output, $0.75/1M cached)
57
+ * - context: https://docs.x.ai/docs/models (131K)
58
+ * - cutoff: https://x.ai/news/grok-3 (november 2024)
59
+ */
60
+ 'xai/grok/3': {
61
+ model: 'grok-3-beta',
62
+ description: 'grok-3 - balanced (131K)',
63
+ spec: new rhachet_1.BrainSpec({
64
+ cost: {
65
+ time: {
66
+ speed: { tokens: 100, per: { seconds: 1 } },
67
+ latency: { seconds: 1 },
68
+ },
69
+ cash: {
70
+ per: 'token',
71
+ cache: {
72
+ get: (0, iso_price_1.dividePrice)({ of: '$0.75', by: 1000000 }), // $0.75/1M cached
73
+ set: (0, iso_price_1.asIsoPrice)('$0'),
74
+ },
75
+ input: (0, iso_price_1.dividePrice)({ of: '$3', by: 1000000 }), // $3/1M tokens
76
+ output: (0, iso_price_1.dividePrice)({ of: '$15', by: 1000000 }), // $15/1M tokens
77
+ },
78
+ },
79
+ gain: {
80
+ size: { context: { tokens: 131000 } }, // 131K context
81
+ grades: {},
82
+ cutoff: '2024-11-01', // november 2024
83
+ domain: 'ALL',
84
+ skills: { tooluse: true },
85
+ },
86
+ }),
87
+ },
88
+ /**
89
+ * grok-3-mini
90
+ * .sources:
91
+ * - rates: https://docs.x.ai/docs/models ($0.30/1M input, $0.50/1M output, $0.075/1M cached)
92
+ * - context: https://docs.x.ai/docs/models (131K)
93
+ * - cutoff: https://x.ai/news/grok-3 (november 2024)
94
+ */
95
+ 'xai/grok/3-mini': {
96
+ model: 'grok-3-mini-beta',
97
+ description: 'grok-3-mini - fast and cost-effective (131K)',
98
+ spec: new rhachet_1.BrainSpec({
99
+ cost: {
100
+ time: {
101
+ speed: { tokens: 150, per: { seconds: 1 } },
102
+ latency: { seconds: 0.5 },
103
+ },
104
+ cash: {
105
+ per: 'token',
106
+ cache: {
107
+ get: (0, iso_price_1.dividePrice)({ of: '$0.075', by: 1000000 }), // $0.075/1M cached
108
+ set: (0, iso_price_1.asIsoPrice)('$0'),
109
+ },
110
+ input: (0, iso_price_1.dividePrice)({ of: '$0.30', by: 1000000 }), // $0.30/1M tokens
111
+ output: (0, iso_price_1.dividePrice)({ of: '$0.50', by: 1000000 }), // $0.50/1M tokens
112
+ },
113
+ },
114
+ gain: {
115
+ size: { context: { tokens: 131000 } }, // 131K context
116
+ grades: {},
117
+ cutoff: '2024-11-01', // november 2024
118
+ domain: 'ALL',
119
+ skills: { tooluse: true },
120
+ },
121
+ }),
122
+ },
123
+ /**
124
+ * grok-4
125
+ * .sources:
126
+ * - rates: https://docs.x.ai/docs/models ($3/1M input, $15/1M output, $0.75/1M cached)
127
+ * - context: https://docs.x.ai/docs/models (256K)
128
+ * - benchmarks: https://x.ai/news/grok-4 (72-75% swe-bench, 86.6% mmlu, 88% gpqa diamond)
129
+ * - benchmarks: https://x.com/ArtificialAnlys/status/1943166841150644622 (94% aime 2024)
130
+ * - cutoff: https://x.ai/news/grok-4 (july 2025)
131
+ */
132
+ 'xai/grok/4': {
133
+ model: 'grok-4-07-09',
134
+ description: 'grok-4 - advanced (256K)',
135
+ spec: new rhachet_1.BrainSpec({
136
+ cost: {
137
+ time: {
138
+ speed: { tokens: 80, per: { seconds: 1 } },
139
+ latency: { seconds: 1.5 },
140
+ },
141
+ cash: {
142
+ per: 'token',
143
+ cache: {
144
+ get: (0, iso_price_1.dividePrice)({ of: '$0.75', by: 1000000 }), // $0.75/1M cached
145
+ set: (0, iso_price_1.asIsoPrice)('$0'),
146
+ },
147
+ input: (0, iso_price_1.dividePrice)({ of: '$3', by: 1000000 }), // $3/1M tokens
148
+ output: (0, iso_price_1.dividePrice)({ of: '$15', by: 1000000 }), // $15/1M tokens
149
+ },
150
+ },
151
+ gain: {
152
+ size: { context: { tokens: 256000 } }, // 256K context
153
+ grades: { swe: 75, mmlu: 86.6, gpqa: 88, aime: 94 }, // todo: remove as any next time you see this. the dep will already have been published.
154
+ cutoff: '2025-07-01', // july 2025
155
+ domain: 'ALL',
156
+ skills: { tooluse: true },
157
+ },
158
+ }),
159
+ },
160
+ /**
161
+ * grok-4-fast-wout-reason (non-reasoning)
162
+ * .sources:
163
+ * - rates: https://x.com/xai/status/1969183335797715149 ($0.20/1M input, $0.50/1M output, $0.05/1M cached)
164
+ * - context: https://x.ai/news/grok-4-fast (2M)
165
+ * - cutoff: https://x.ai/news/grok-4 (july 2025)
166
+ */
167
+ 'xai/grok/4-fast-wout-reason': {
168
+ model: 'grok-4-fast-non-reasoning',
169
+ description: 'grok-4-fast non-reasoning - fast responses (2M)',
170
+ spec: new rhachet_1.BrainSpec({
171
+ cost: {
172
+ time: {
173
+ speed: { tokens: 300, per: { seconds: 1 } },
174
+ latency: { seconds: 0.3 },
175
+ },
176
+ cash: {
177
+ per: 'token',
178
+ cache: {
179
+ get: (0, iso_price_1.dividePrice)({ of: '$0.05', by: 1000000 }), // $0.05/1M cached
180
+ set: (0, iso_price_1.asIsoPrice)('$0'),
181
+ },
182
+ input: (0, iso_price_1.dividePrice)({ of: '$0.20', by: 1000000 }), // $0.20/1M tokens
183
+ output: (0, iso_price_1.dividePrice)({ of: '$0.50', by: 1000000 }), // $0.50/1M tokens
184
+ },
185
+ },
186
+ gain: {
187
+ size: { context: { tokens: 2000000 } }, // 2M context
188
+ grades: {},
189
+ cutoff: '2025-07-01', // july 2025
190
+ domain: 'ALL',
191
+ skills: { tooluse: true },
192
+ },
193
+ }),
194
+ },
195
+ /**
196
+ * grok-4-fast-with-reason (reasoning)
197
+ * .sources:
198
+ * - rates: https://x.com/xai/status/1969183335797715149 ($0.20/1M input, $0.50/1M output, $0.05/1M cached)
199
+ * - context: https://x.ai/news/grok-4-fast (2M)
200
+ * - cutoff: https://x.ai/news/grok-4 (july 2025)
201
+ * - note: uses chain-of-thought, consumes more tokens but better for complex tasks
202
+ */
203
+ 'xai/grok/4-fast-with-reason': {
204
+ model: 'grok-4-fast-reasoning',
205
+ description: 'grok-4-fast reasoning - chain-of-thought (2M)',
206
+ spec: new rhachet_1.BrainSpec({
207
+ cost: {
208
+ time: {
209
+ speed: { tokens: 150, per: { seconds: 1 } },
210
+ latency: { seconds: 0.5 },
211
+ },
212
+ cash: {
213
+ per: 'token',
214
+ cache: {
215
+ get: (0, iso_price_1.dividePrice)({ of: '$0.05', by: 1000000 }), // $0.05/1M cached
216
+ set: (0, iso_price_1.asIsoPrice)('$0'),
217
+ },
218
+ input: (0, iso_price_1.dividePrice)({ of: '$0.20', by: 1000000 }), // $0.20/1M tokens
219
+ output: (0, iso_price_1.dividePrice)({ of: '$0.50', by: 1000000 }), // $0.50/1M tokens
220
+ },
221
+ },
222
+ gain: {
223
+ size: { context: { tokens: 2000000 } }, // 2M context
224
+ grades: {},
225
+ cutoff: '2025-07-01', // july 2025
226
+ domain: 'ALL',
227
+ skills: { tooluse: true },
228
+ },
229
+ }),
230
+ },
231
+ /**
232
+ * grok-4.1-fast-wout-reason (non-reasoning)
233
+ * .sources:
234
+ * - rates: https://blog.galaxy.ai/model/grok-4-1-fast ($0.20/1M input, $0.50/1M output, $0.05/1M cached)
235
+ * - context: https://x.ai/news/grok-4-1-fast (2M)
236
+ * - release: https://x.ai/news/grok-4-1-fast (november 2025)
237
+ * - note: successor to grok-4-fast, better tool call and lower hallucination
238
+ */
239
+ 'xai/grok/4.1-fast-wout-reason': {
240
+ model: 'grok-4-1-fast-non-reasoning',
241
+ description: 'grok-4.1-fast non-reasoning - best tool call (2M)',
242
+ spec: new rhachet_1.BrainSpec({
243
+ cost: {
244
+ time: {
245
+ speed: { tokens: 300, per: { seconds: 1 } },
246
+ latency: { seconds: 0.3 },
247
+ },
248
+ cash: {
249
+ per: 'token',
250
+ cache: {
251
+ get: (0, iso_price_1.dividePrice)({ of: '$0.05', by: 1000000 }), // $0.05/1M cached
252
+ set: (0, iso_price_1.asIsoPrice)('$0'),
253
+ },
254
+ input: (0, iso_price_1.dividePrice)({ of: '$0.20', by: 1000000 }), // $0.20/1M tokens
255
+ output: (0, iso_price_1.dividePrice)({ of: '$0.50', by: 1000000 }), // $0.50/1M tokens
256
+ },
257
+ },
258
+ gain: {
259
+ size: { context: { tokens: 2000000 } }, // 2M context
260
+ grades: {},
261
+ cutoff: '2025-11-01', // november 2025
262
+ domain: 'ALL',
263
+ skills: { tooluse: true },
264
+ },
265
+ }),
266
+ },
267
+ /**
268
+ * grok-4.1-fast-with-reason (reasoning)
269
+ * .sources:
270
+ * - rates: https://blog.galaxy.ai/model/grok-4-1-fast ($0.20/1M input, $0.50/1M output, $0.05/1M cached)
271
+ * - context: https://x.ai/news/grok-4-1-fast (2M)
272
+ * - release: https://x.ai/news/grok-4-1-fast (november 2025)
273
+ * - benchmark: https://llm-stats.com/models/grok-4-1-fast-reasoning (64 intelligence, ~79% swe-bench)
274
+ * - note: near grok-4 capability at 1/15th price
275
+ */
276
+ 'xai/grok/4.1-fast-with-reason': {
277
+ model: 'grok-4-1-fast-reasoning',
278
+ description: 'grok-4.1-fast reasoning - near grok-4 capability (2M)',
279
+ spec: new rhachet_1.BrainSpec({
280
+ cost: {
281
+ time: {
282
+ speed: { tokens: 150, per: { seconds: 1 } },
283
+ latency: { seconds: 0.5 },
284
+ },
285
+ cash: {
286
+ per: 'token',
287
+ cache: {
288
+ get: (0, iso_price_1.dividePrice)({ of: '$0.05', by: 1000000 }), // $0.05/1M cached
289
+ set: (0, iso_price_1.asIsoPrice)('$0'),
290
+ },
291
+ input: (0, iso_price_1.dividePrice)({ of: '$0.20', by: 1000000 }), // $0.20/1M tokens
292
+ output: (0, iso_price_1.dividePrice)({ of: '$0.50', by: 1000000 }), // $0.50/1M tokens
293
+ },
294
+ },
295
+ gain: {
296
+ size: { context: { tokens: 2000000 } }, // 2M context
297
+ grades: { swe: 79 }, // ~79% swe-bench
298
+ cutoff: '2025-11-01', // november 2025
299
+ domain: 'ALL',
300
+ skills: { tooluse: true },
301
+ },
302
+ }),
303
+ },
304
+ };
305
+ //# 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;AA0BpC;;;;;;;;;GASG;AACU,QAAA,mBAAmB,GAA8C;IAC5E;;;;;;;OAOG;IACH,sBAAsB,EAAE;QACtB,KAAK,EAAE,kBAAkB;QACzB,WAAW,EAAE,sDAAsD;QACnE,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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E,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,uBAAW,EAAC,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAS,EAAE,CAAC,EAAE,kBAAkB;wBACpE,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,OAAS,EAAE,EAAE,EAAE,aAAa;gBACvD,MAAM,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,iBAAiB;gBACtC,MAAM,EAAE,YAAY,EAAE,gBAAgB;gBACtC,MAAM,EAAE,KAAK;gBACb,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;aAC1B;SACF,CAAC;KACH;CACF,CAAC"}
@@ -1,9 +1,6 @@
1
- import { BrainAtom } from 'rhachet';
2
- /**
3
- * .what = supported xai atom slugs
4
- * .why = enables type-safe slug specification with model variants
5
- */
6
- export type XAIAtomSlug = 'xai/grok-code-fast-1' | 'xai/grok-3' | 'xai/grok-3-mini' | 'xai/grok-4' | 'xai/grok-4-fast';
1
+ import { BrainAtom } from 'rhachet/brains';
2
+ import { type XaiBrainAtomSlug } from './BrainAtom.config';
3
+ export type { XaiBrainAtomSlug } from './BrainAtom.config';
7
4
  /**
8
5
  * .what = factory to generate xai brain atom instances
9
6
  * .why = enables model variant selection via slug
@@ -11,10 +8,10 @@ export type XAIAtomSlug = 'xai/grok-code-fast-1' | 'xai/grok-3' | 'xai/grok-3-mi
11
8
  * .note = xai api is openai-compatible with baseURL override
12
9
  *
13
10
  * .example
14
- * genBrainAtom({ slug: 'xai/grok-code-fast-1' })
15
- * genBrainAtom({ slug: 'xai/grok-3-mini' }) // fast + cheap
16
- * genBrainAtom({ slug: 'xai/grok-4' }) // advanced reasoning
11
+ * genBrainAtom({ slug: 'xai/grok/code-fast-1' })
12
+ * genBrainAtom({ slug: 'xai/grok/3-mini' }) // fast + cheap
13
+ * genBrainAtom({ slug: 'xai/grok/4' }) // advanced
17
14
  */
18
15
  export declare const genBrainAtom: (input: {
19
- slug: XAIAtomSlug;
16
+ slug: XaiBrainAtomSlug;
20
17
  }) => BrainAtom;
@@ -5,39 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.genBrainAtom = void 0;
7
7
  const openai_1 = __importDefault(require("openai"));
8
- const rhachet_1 = require("rhachet");
8
+ const brains_1 = require("rhachet/brains");
9
9
  const zod_1 = require("zod");
10
- /**
11
- * .what = model configuration by slug
12
- * .why = maps slugs to API model names, descriptions, and context sizes
13
- */
14
- const CONFIG_BY_SLUG = {
15
- 'xai/grok-code-fast-1': {
16
- model: 'grok-code-fast-1',
17
- description: 'grok-code-fast-1 - optimized for agentic coding (256K)',
18
- context: 256000,
19
- },
20
- 'xai/grok-3': {
21
- model: 'grok-3-beta',
22
- description: 'grok-3 - balanced reasoning (131K)',
23
- context: 131000,
24
- },
25
- 'xai/grok-3-mini': {
26
- model: 'grok-3-mini-beta',
27
- description: 'grok-3-mini - fast and cost-effective (131K)',
28
- context: 131000,
29
- },
30
- 'xai/grok-4': {
31
- model: 'grok-4-07-09',
32
- description: 'grok-4 - advanced reasoning (256K)',
33
- context: 256000,
34
- },
35
- 'xai/grok-4-fast': {
36
- model: 'grok-4-fast-reasoning',
37
- description: 'grok-4-fast - frontier with reasoning (2M)',
38
- context: 2000000,
39
- },
40
- };
10
+ const BrainAtom_config_1 = require("./BrainAtom.config");
41
11
  /**
42
12
  * .what = factory to generate xai brain atom instances
43
13
  * .why = enables model variant selection via slug
@@ -45,24 +15,29 @@ const CONFIG_BY_SLUG = {
45
15
  * .note = xai api is openai-compatible with baseURL override
46
16
  *
47
17
  * .example
48
- * genBrainAtom({ slug: 'xai/grok-code-fast-1' })
49
- * genBrainAtom({ slug: 'xai/grok-3-mini' }) // fast + cheap
50
- * genBrainAtom({ slug: 'xai/grok-4' }) // advanced reasoning
18
+ * genBrainAtom({ slug: 'xai/grok/code-fast-1' })
19
+ * genBrainAtom({ slug: 'xai/grok/3-mini' }) // fast + cheap
20
+ * genBrainAtom({ slug: 'xai/grok/4' }) // advanced
51
21
  */
52
22
  const genBrainAtom = (input) => {
53
- const config = CONFIG_BY_SLUG[input.slug];
54
- return new rhachet_1.BrainAtom({
23
+ const config = BrainAtom_config_1.CONFIG_BY_ATOM_SLUG[input.slug];
24
+ return new brains_1.BrainAtom({
55
25
  repo: 'xai',
56
26
  slug: input.slug,
57
27
  description: config.description,
28
+ spec: config.spec,
58
29
  /**
59
30
  * .what = stateless inference (no tool use)
60
- * .why = provides direct model access for reasoning tasks
31
+ * .why = provides direct model access for tasks
32
+ *
33
+ * .note = supports continuation via `on.episode`
61
34
  */
62
35
  ask: async (askInput, context) => {
36
+ // track start time for elapsed duration
37
+ const startedAt = Date.now();
63
38
  // compose system prompt from briefs
64
39
  const systemPrompt = askInput.role.briefs
65
- ? await (0, rhachet_1.castBriefsToPrompt)({ briefs: askInput.role.briefs })
40
+ ? await (0, brains_1.castBriefsToPrompt)({ briefs: askInput.role.briefs })
66
41
  : undefined;
67
42
  // get openai client from context or create new one with xai baseURL
68
43
  const openai = context?.openai ??
@@ -70,11 +45,17 @@ const genBrainAtom = (input) => {
70
45
  apiKey: process.env.XAI_API_KEY,
71
46
  baseURL: 'https://api.x.ai/v1',
72
47
  });
73
- // build messages array
48
+ // build messages array with prior exchanges for continuation
74
49
  const messages = [];
75
50
  if (systemPrompt) {
76
51
  messages.push({ role: 'system', content: systemPrompt });
77
52
  }
53
+ if (askInput.on?.episode) {
54
+ for (const exchange of askInput.on.episode.exchanges) {
55
+ messages.push({ role: 'user', content: exchange.input });
56
+ messages.push({ role: 'assistant', content: exchange.output });
57
+ }
58
+ }
78
59
  messages.push({ role: 'user', content: askInput.prompt });
79
60
  // convert zod schema to json schema for structured output
80
61
  const jsonSchema = zod_1.z.toJSONSchema(askInput.schema.output);
@@ -95,7 +76,56 @@ const genBrainAtom = (input) => {
95
76
  const content = response.choices[0]?.message?.content ?? '';
96
77
  // parse JSON response and validate via schema
97
78
  const parsed = JSON.parse(content);
98
- return askInput.schema.output.parse(parsed);
79
+ const output = askInput.schema.output.parse(parsed);
80
+ // calculate elapsed time
81
+ const elapsedMs = Date.now() - startedAt;
82
+ // extract token usage from response
83
+ const tokensInput = response.usage?.prompt_tokens ?? 0;
84
+ const tokensOutput = response.usage?.completion_tokens ?? 0;
85
+ const tokensCached = response.usage?.prompt_tokens_details?.cached_tokens ?? 0;
86
+ // calculate character counts
87
+ const charsInput = (systemPrompt?.length ?? 0) + askInput.prompt.length;
88
+ const charsOutput = content.length;
89
+ // define size for metrics and cost calculation
90
+ const size = {
91
+ tokens: {
92
+ input: tokensInput,
93
+ output: tokensOutput,
94
+ cache: { get: tokensCached, set: 0 },
95
+ },
96
+ chars: {
97
+ input: charsInput,
98
+ output: charsOutput,
99
+ cache: { get: 0, set: 0 },
100
+ },
101
+ };
102
+ // calculate cash costs via rhachet utility
103
+ const { cash } = (0, brains_1.calcBrainOutputCost)({
104
+ for: { tokens: size.tokens },
105
+ with: { cost: { cash: config.spec.cost.cash } },
106
+ });
107
+ // build metrics
108
+ const metrics = new brains_1.BrainOutputMetrics({
109
+ size,
110
+ cost: {
111
+ time: { milliseconds: elapsedMs },
112
+ cash,
113
+ },
114
+ });
115
+ // build continuables (episode + series) for this invocation
116
+ const { episode, series } = await (0, brains_1.genBrainContinuables)({
117
+ for: { grain: 'atom' },
118
+ on: { episode: askInput.on?.episode ?? null, series: null },
119
+ with: {
120
+ exchange: {
121
+ input: askInput.prompt,
122
+ output: content,
123
+ exid: response.id ?? null,
124
+ },
125
+ episode: { exid: response.id ?? null },
126
+ },
127
+ });
128
+ return new brains_1.BrainOutput({ output, metrics, episode, series });
99
129
  },
100
130
  });
101
131
  };
@@ -1 +1 @@
1
- {"version":3,"file":"genBrainAtom.js","sourceRoot":"","sources":["../../../src/domain.operations/atom/genBrainAtom.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,qCAAwD;AAIxD,6BAAwB;AAaxB;;;GAGG;AACH,MAAM,cAAc,GAGhB;IACF,sBAAsB,EAAE;QACtB,KAAK,EAAE,kBAAkB;QACzB,WAAW,EAAE,wDAAwD;QACrE,OAAO,EAAE,MAAO;KACjB;IACD,YAAY,EAAE;QACZ,KAAK,EAAE,aAAa;QACpB,WAAW,EAAE,oCAAoC;QACjD,OAAO,EAAE,MAAO;KACjB;IACD,iBAAiB,EAAE;QACjB,KAAK,EAAE,kBAAkB;QACzB,WAAW,EAAE,8CAA8C;QAC3D,OAAO,EAAE,MAAO;KACjB;IACD,YAAY,EAAE;QACZ,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,oCAAoC;QACjD,OAAO,EAAE,MAAO;KACjB;IACD,iBAAiB,EAAE;QACjB,KAAK,EAAE,uBAAuB;QAC9B,WAAW,EAAE,4CAA4C;QACzD,OAAO,EAAE,OAAS;KACnB;CACF,CAAC;AAEF;;;;;;;;;;GAUG;AACI,MAAM,YAAY,GAAG,CAAC,KAA4B,EAAa,EAAE;IACtE,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE1C,OAAO,IAAI,mBAAS,CAAC;QACnB,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,WAAW,EAAE,MAA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EAAE,IAAI,CAAC,MAAM,EAAE;gBAC5B,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE;aAChD,CAAC,CAAC;YAEH,gBAAgB;YAChB,MAAM,OAAO,GAAG,IAAI,2BAAkB,CAAC;gBACrC,IAAI;gBACJ,IAAI,EAAE;oBACJ,IAAI,EAAE,EAAE,YAAY,EAAE,SAAS,EAAE;oBACjC,IAAI;iBACL;aACF,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,QAAQ,CAAC,MAAM;wBACtB,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,OAAO,IAAI,oBAAW,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QAC/D,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AA7IW,QAAA,YAAY,gBA6IvB"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "rhachet-brains-xai",
3
3
  "author": "ehmpathy",
4
4
  "description": "rhachet brain.atom adapter for xai grok models",
5
- "version": "0.1.3",
5
+ "version": "0.2.1",
6
6
  "repository": "ehmpathy/rhachet-brains-xai",
7
7
  "homepage": "https://github.com/ehmpathy/rhachet-brains-xai",
8
8
  "keywords": [
@@ -53,15 +53,17 @@
53
53
  "preversion": "npm run prepush",
54
54
  "postversion": "git push origin HEAD --tags --no-verify",
55
55
  "prepare:husky": "husky install && chmod ug+x .husky/*",
56
- "prepare:rhachet": "rhachet init --mode upsert && rhachet roles link --repo ehmpathy --role mechanic && rhachet roles link --repo bhuild --role behaver && rhachet roles link --repo bhrain --role reviewer && rhachet roles init --role mechanic && rhachet roles init --role behaver",
56
+ "prepare:rhachet": "rhachet init --roles behaver mechanic reviewer --hooks",
57
57
  "prepare": "if [ -e .git ] && [ -z $CI ]; then npm run prepare:husky && npm run prepare:rhachet; fi"
58
58
  },
59
59
  "dependencies": {
60
60
  "domain-objects": "0.31.9",
61
61
  "helpful-errors": "1.5.3",
62
+ "iso-price": "1.1.1",
62
63
  "openai": "5.8.2",
63
64
  "rhachet-artifact": "1.0.1",
64
65
  "rhachet-artifact-git": "1.1.5",
66
+ "rhachet-roles-bhrain": "0.7.5",
65
67
  "type-fns": "1.21.0",
66
68
  "zod": "4.3.4"
67
69
  },
@@ -87,11 +89,11 @@
87
89
  "esbuild-register": "3.6.0",
88
90
  "husky": "8.0.3",
89
91
  "jest": "30.2.0",
90
- "rhachet": "1.21.4",
91
- "rhachet-roles-bhrain": "0.5.9",
92
- "rhachet-roles-bhuild": "0.6.3",
93
- "rhachet-roles-ehmpathy": "1.17.15",
94
- "test-fns": "1.5.0",
92
+ "rhachet": "1.29.5",
93
+ "rhachet-brains-anthropic": "0.3.2",
94
+ "rhachet-roles-bhuild": "0.7.0",
95
+ "rhachet-roles-ehmpathy": "1.18.0",
96
+ "test-fns": "1.10.0",
95
97
  "tsc-alias": "1.8.10",
96
98
  "tsx": "4.20.6",
97
99
  "typescript": "5.4.5",
package/readme.md CHANGED
@@ -15,17 +15,17 @@ import { genBrainAtom } from 'rhachet-brains-xai';
15
15
  import { z } from 'zod';
16
16
 
17
17
  // create a brain atom for direct model inference
18
- const brainAtom = genBrainAtom({ slug: 'xai/grok-code-fast-1' });
18
+ const brainAtom = genBrainAtom({ slug: 'xai/grok/code-fast-1' });
19
19
 
20
20
  // simple string output
21
- const explanation = await brainAtom.ask({
21
+ const { output: explanation } = await brainAtom.ask({
22
22
  role: { briefs: [] },
23
23
  prompt: 'explain this code',
24
24
  schema: { output: z.string() },
25
25
  });
26
26
 
27
27
  // structured object output
28
- const { summary, issues } = await brainAtom.ask({
28
+ const { output: { summary, issues } } = await brainAtom.ask({
29
29
  role: { briefs: [] },
30
30
  prompt: 'analyze this code',
31
31
  schema: { output: z.object({ summary: z.string(), issues: z.array(z.string()) }) },
@@ -38,13 +38,16 @@ const { summary, issues } = await brainAtom.ask({
38
38
 
39
39
  stateless inference without tool use.
40
40
 
41
- | slug | model | context | description |
42
- | ---------------------- | ---------------------- | ------- | ---------------------------------- |
43
- | `xai/grok-code-fast-1` | grok-code-fast-1 | 256K | optimized for agentic code tasks |
44
- | `xai/grok-3` | grok-3-beta | 131K | balanced logic model |
45
- | `xai/grok-3-mini` | grok-3-mini-beta | 131K | fast and cost-effective |
46
- | `xai/grok-4` | grok-4-07-09 | 256K | advanced logic model |
47
- | `xai/grok-4-fast` | grok-4-fast-reasoning | 2M | frontier model with tool use |
41
+ | slug | model | context | cutoff | input | output | cache |
42
+ | ------------------------------- | --------------------------- | ------- | -------- | -------- | -------- | --------- |
43
+ | `xai/grok/code-fast-1` | grok-code-fast-1 | 256K | mar 2025 | $0.20/1M | $1.50/1M | $0.02/1M |
44
+ | `xai/grok/3` | grok-3-beta | 131K | nov 2024 | $3/1M | $15/1M | $0.75/1M |
45
+ | `xai/grok/3-mini` | grok-3-mini-beta | 131K | nov 2024 | $0.30/1M | $0.50/1M | $0.075/1M |
46
+ | `xai/grok/4` | grok-4-07-09 | 256K | jul 2025 | $3/1M | $15/1M | $0.75/1M |
47
+ | `xai/grok/4-fast-wout-reason` | grok-4-fast-non-reasoning | 2M | jul 2025 | $0.20/1M | $0.50/1M | $0.05/1M |
48
+ | `xai/grok/4-fast-with-reason` | grok-4-fast-reasoning | 2M | jul 2025 | $0.20/1M | $0.50/1M | $0.05/1M |
49
+ | `xai/grok/4.1-fast-wout-reason` | grok-4-1-fast-non-reasoning | 2M | nov 2025 | $0.20/1M | $0.50/1M | $0.05/1M |
50
+ | `xai/grok/4.1-fast-with-reason` | grok-4-1-fast-reasoning | 2M | nov 2025 | $0.20/1M | $0.50/1M | $0.05/1M |
48
51
 
49
52
  ## environment
50
53
 
@@ -55,3 +58,4 @@ requires `XAI_API_KEY` environment variable.
55
58
  - [xAI API Documentation](https://docs.x.ai/docs/overview)
56
59
  - [xAI Models](https://docs.x.ai/docs/models)
57
60
  - [Grok Code Fast 1](https://x.ai/news/grok-code-fast-1)
61
+ - [Grok 4](https://x.ai/news/grok-4)
@@ -1,13 +0,0 @@
1
- import { z } from 'zod';
2
- /**
3
- * .what = convert a zod schema to JSON schema for native SDK enforcement
4
- * .why = enables native structured output support in SDKs, reducing
5
- * token waste on validation retries
6
- *
7
- * .note = different SDKs require different conversion options:
8
- * - claude-agent-sdk: { $refStrategy: 'root' }
9
- * - codex-sdk: { target: 'openAi' }
10
- */
11
- export declare const asJsonSchema: (input: {
12
- schema: z.ZodSchema;
13
- }) => object;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.asJsonSchema = void 0;
4
- const zod_1 = require("zod");
5
- /**
6
- * .what = convert a zod schema to JSON schema for native SDK enforcement
7
- * .why = enables native structured output support in SDKs, reducing
8
- * token waste on validation retries
9
- *
10
- * .note = different SDKs require different conversion options:
11
- * - claude-agent-sdk: { $refStrategy: 'root' }
12
- * - codex-sdk: { target: 'openAi' }
13
- */
14
- const asJsonSchema = (input) => {
15
- return zod_1.z.toJSONSchema(input.schema, { target: 'openAi' });
16
- };
17
- exports.asJsonSchema = asJsonSchema;
18
- //# sourceMappingURL=asJsonSchema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"asJsonSchema.js","sourceRoot":"","sources":["../../../src/infra/schema/asJsonSchema.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB;;;;;;;;GAQG;AACI,MAAM,YAAY,GAAG,CAAC,KAA8B,EAAU,EAAE;IACrE,OAAO,OAAC,CAAC,YAAY,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC5D,CAAC,CAAC;AAFW,QAAA,YAAY,gBAEvB"}