rhachet-brains-xai 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 xai
4
+ * .why = enables consumers to register xai atoms with genContextBrain
5
+ */
6
+ export declare const getBrainAtomsByXAI: () => BrainAtom[];
7
+ export { genBrainAtom } from '../../domain.operations/atom/genBrainAtom';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genBrainAtom = exports.getBrainAtomsByXAI = void 0;
4
+ const genBrainAtom_1 = require("../../domain.operations/atom/genBrainAtom");
5
+ /**
6
+ * .what = returns all brain atoms provided by xai
7
+ * .why = enables consumers to register xai atoms with genContextBrain
8
+ */
9
+ const getBrainAtomsByXAI = () => {
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' }),
16
+ ];
17
+ };
18
+ exports.getBrainAtomsByXAI = getBrainAtomsByXAI;
19
+ // re-export factory for direct access
20
+ var genBrainAtom_2 = require("../../domain.operations/atom/genBrainAtom");
21
+ Object.defineProperty(exports, "genBrainAtom", { enumerable: true, get: function () { return genBrainAtom_2.genBrainAtom; } });
22
+ //# 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,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"}
@@ -0,0 +1,20 @@
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';
7
+ /**
8
+ * .what = factory to generate xai brain atom instances
9
+ * .why = enables model variant selection via slug
10
+ *
11
+ * .note = xai api is openai-compatible with baseURL override
12
+ *
13
+ * .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
17
+ */
18
+ export declare const genBrainAtom: (input: {
19
+ slug: XAIAtomSlug;
20
+ }) => BrainAtom;
@@ -0,0 +1,103 @@
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 openai_1 = __importDefault(require("openai"));
8
+ const zod_1 = require("zod");
9
+ const rhachet_1 = require("rhachet");
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
+ };
41
+ /**
42
+ * .what = factory to generate xai brain atom instances
43
+ * .why = enables model variant selection via slug
44
+ *
45
+ * .note = xai api is openai-compatible with baseURL override
46
+ *
47
+ * .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
51
+ */
52
+ const genBrainAtom = (input) => {
53
+ const config = CONFIG_BY_SLUG[input.slug];
54
+ return new rhachet_1.BrainAtom({
55
+ repo: 'xai',
56
+ slug: input.slug,
57
+ description: config.description,
58
+ /**
59
+ * .what = stateless inference (no tool use)
60
+ * .why = provides direct model access for reasoning tasks
61
+ */
62
+ ask: async (askInput, context) => {
63
+ // compose system prompt from briefs
64
+ const systemPrompt = askInput.role.briefs
65
+ ? await (0, rhachet_1.castBriefsToPrompt)({ briefs: askInput.role.briefs })
66
+ : undefined;
67
+ // get openai client from context or create new one with xai baseURL
68
+ const openai = context?.openai ??
69
+ new openai_1.default({
70
+ apiKey: process.env.XAI_API_KEY,
71
+ baseURL: 'https://api.x.ai/v1',
72
+ });
73
+ // build messages array
74
+ const messages = [];
75
+ if (systemPrompt) {
76
+ messages.push({ role: 'system', content: systemPrompt });
77
+ }
78
+ messages.push({ role: 'user', content: askInput.prompt });
79
+ // convert zod schema to json schema for structured output
80
+ const jsonSchema = zod_1.z.toJSONSchema(askInput.schema.output);
81
+ // call xai api with strict json_schema response format
82
+ const response = await openai.chat.completions.create({
83
+ model: config.model,
84
+ messages,
85
+ response_format: {
86
+ type: 'json_schema',
87
+ json_schema: {
88
+ name: 'response',
89
+ strict: true,
90
+ schema: jsonSchema,
91
+ },
92
+ },
93
+ });
94
+ // extract content from response
95
+ const content = response.choices[0]?.message?.content ?? '';
96
+ // parse JSON response and validate via schema
97
+ const parsed = JSON.parse(content);
98
+ return askInput.schema.output.parse(parsed);
99
+ },
100
+ });
101
+ };
102
+ exports.genBrainAtom = genBrainAtom;
103
+ //# sourceMappingURL=genBrainAtom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"genBrainAtom.js","sourceRoot":"","sources":["../../../src/domain.operations/atom/genBrainAtom.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,13 @@
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;
@@ -0,0 +1,18 @@
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
@@ -0,0 +1 @@
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"}
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,103 @@
1
+ {
2
+ "name": "rhachet-brains-xai",
3
+ "author": "ehmpathy",
4
+ "description": "rhachet brain.atom adapter for xai grok models",
5
+ "version": "0.0.0",
6
+ "repository": "ehmpathy/rhachet-brains-xai",
7
+ "homepage": "https://github.com/ehmpathy/rhachet-brains-xai",
8
+ "keywords": [
9
+ "rhachet",
10
+ "brain",
11
+ "xai",
12
+ "grok",
13
+ "llm",
14
+ "ai"
15
+ ],
16
+ "bugs": "https://github.com/ehmpathy/rhachet-brains-xai/issues",
17
+ "license": "MIT",
18
+ "main": "dist/index.js",
19
+ "engines": {
20
+ "node": ">=8.0.0"
21
+ },
22
+ "files": [
23
+ "/dist"
24
+ ],
25
+ "dependencies": {
26
+ "@openai/codex-sdk": "0.77.0",
27
+ "domain-objects": "0.31.9",
28
+ "helpful-errors": "1.5.3",
29
+ "openai": "5.8.2",
30
+ "rhachet-artifact": "1.0.1",
31
+ "rhachet-artifact-git": "1.1.5",
32
+ "type-fns": "1.21.0",
33
+ "wrapper-fns": "1.1.7",
34
+ "zod": "4.3.4"
35
+ },
36
+ "devDependencies": {
37
+ "@biomejs/biome": "2.3.8",
38
+ "@commitlint/cli": "19.5.0",
39
+ "@commitlint/config-conventional": "19.5.0",
40
+ "@swc/core": "1.15.3",
41
+ "@swc/jest": "0.2.39",
42
+ "@tsconfig/node20": "20.1.5",
43
+ "@tsconfig/strictest": "2.0.5",
44
+ "@types/jest": "30.0.0",
45
+ "@types/node": "22.15.21",
46
+ "cz-conventional-changelog": "3.3.0",
47
+ "declapract": "0.13.14",
48
+ "declapract-typescript-ehmpathy": "0.47.16",
49
+ "declastruct": "1.7.3",
50
+ "declastruct-github": "1.3.0",
51
+ "depcheck": "1.4.3",
52
+ "esbuild-register": "3.6.0",
53
+ "husky": "8.0.3",
54
+ "jest": "30.2.0",
55
+ "rhachet": "1.21.4",
56
+ "rhachet-roles-bhrain": "0.5.9",
57
+ "rhachet-roles-bhuild": "0.6.3",
58
+ "rhachet-roles-ehmpathy": "1.17.15",
59
+ "test-fns": "1.5.0",
60
+ "tsc-alias": "1.8.10",
61
+ "tsx": "4.20.6",
62
+ "typescript": "5.4.5",
63
+ "yalc": "1.0.0-pre.53"
64
+ },
65
+ "config": {
66
+ "commitizen": {
67
+ "path": "./node_modules/cz-conventional-changelog"
68
+ }
69
+ },
70
+ "scripts": {
71
+ "build:ts": "tsc -p ./tsconfig.build.json",
72
+ "commit:with-cli": "npx cz",
73
+ "fix:format:biome": "biome check --write",
74
+ "fix:format": "npm run fix:format:biome",
75
+ "fix:lint": "biome check --write",
76
+ "fix": "npm run fix:format && npm run fix:lint",
77
+ "build:clean:bun": "rm -f ./bin/*.bc",
78
+ "build:clean:tsc": "(chmod -R u+w dist 2>/dev/null || true) && rm -rf dist/",
79
+ "build:clean": "npm run build:clean:tsc && npm run build:clean:bun",
80
+ "build:compile:tsc": "tsc -p ./tsconfig.build.json && tsc-alias -p ./tsconfig.build.json",
81
+ "build:compile": "npm run build:compile:tsc && npm run build:compile:bun --if-present",
82
+ "build": "npm run build:clean && npm run build:compile && npm run build:complete --if-present",
83
+ "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",
84
+ "test:types": "tsc -p ./tsconfig.json --noEmit",
85
+ "test:format:biome": "biome format",
86
+ "test:format": "npm run test:format:biome",
87
+ "test:lint:deps": "npx depcheck -c ./.depcheckrc.yml",
88
+ "test:lint:biome": "biome check --diagnostic-level=error",
89
+ "test:lint:biome:all": "biome check",
90
+ "test:lint": "npm run test:lint:biome && npm run test:lint:deps",
91
+ "test:unit": "jest -c ./jest.unit.config.ts --forceExit --verbose --passWithNoTests $([ -z $THOROUGH ] && echo '--changedSince=main') $([ -n $RESNAP ] && echo '--updateSnapshot')",
92
+ "test:integration": "jest -c ./jest.integration.config.ts --forceExit --verbose --passWithNoTests $([ -z $THOROUGH ] && echo '--changedSince=main') $([ -n $RESNAP ] && echo '--updateSnapshot')",
93
+ "test:acceptance:locally": "npm run build && LOCALLY=true jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests $([ -n $RESNAP ] && echo '--updateSnapshot')",
94
+ "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",
95
+ "test:acceptance": "npm run build && jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests $([ -n $RESNAP ] && echo '--updateSnapshot')",
96
+ "prepush": "npm run test && npm run build",
97
+ "prepublish": "npm run build",
98
+ "preversion": "npm run prepush",
99
+ "postversion": "git push origin HEAD --tags --no-verify",
100
+ "prepare:husky": "husky install && chmod ug+x .husky/*",
101
+ "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"
102
+ }
103
+ }
package/readme.md ADDED
@@ -0,0 +1,57 @@
1
+ # rhachet-brains-xai
2
+
3
+ rhachet brain.atom adapter for xai grok models
4
+
5
+ ## install
6
+
7
+ ```sh
8
+ npm install rhachet-brains-xai
9
+ ```
10
+
11
+ ## usage
12
+
13
+ ```ts
14
+ import { genBrainAtom } from 'rhachet-brains-xai';
15
+ import { z } from 'zod';
16
+
17
+ // create a brain atom for direct model inference
18
+ const brainAtom = genBrainAtom({ slug: 'xai/grok-code-fast-1' });
19
+
20
+ // simple string output
21
+ const response = await brainAtom.ask({
22
+ role: { briefs: [] },
23
+ prompt: 'explain this code',
24
+ schema: { output: z.string() },
25
+ });
26
+
27
+ // structured object output
28
+ const result = 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 | 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 |
48
+
49
+ ## environment
50
+
51
+ requires `XAI_API_KEY` environment variable.
52
+
53
+ ## sources
54
+
55
+ - [xAI API Documentation](https://docs.x.ai/docs/overview)
56
+ - [xAI Models](https://docs.x.ai/docs/models)
57
+ - [Grok Code Fast 1](https://x.ai/news/grok-code-fast-1)