rhachet-brains-openai 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,13 @@
1
+ import type { BrainAtom, BrainRepl } from 'rhachet';
2
+ /**
3
+ * .what = returns all brain atoms provided by openai
4
+ * .why = enables consumers to register openai atoms with genContextBrain
5
+ */
6
+ export declare const getBrainAtomsByOpenAI: () => BrainAtom[];
7
+ /**
8
+ * .what = returns all brain repls provided by openai
9
+ * .why = enables consumers to register openai repls with genContextBrain
10
+ */
11
+ export declare const getBrainReplsByOpenAI: () => BrainRepl[];
12
+ export { genBrainAtom } from '../../domain.operations/atoms/genBrainAtom';
13
+ export { genBrainRepl } from '../../domain.operations/repls/genBrainRepl';
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genBrainRepl = exports.genBrainAtom = exports.getBrainReplsByOpenAI = exports.getBrainAtomsByOpenAI = void 0;
4
+ const genBrainAtom_1 = require("../../domain.operations/atoms/genBrainAtom");
5
+ const genBrainRepl_1 = require("../../domain.operations/repls/genBrainRepl");
6
+ /**
7
+ * .what = returns all brain atoms provided by openai
8
+ * .why = enables consumers to register openai atoms with genContextBrain
9
+ */
10
+ const getBrainAtomsByOpenAI = () => {
11
+ return [(0, genBrainAtom_1.genBrainAtom)({ slug: 'openai/gpt-4o' })];
12
+ };
13
+ exports.getBrainAtomsByOpenAI = getBrainAtomsByOpenAI;
14
+ /**
15
+ * .what = returns all brain repls provided by openai
16
+ * .why = enables consumers to register openai repls with genContextBrain
17
+ */
18
+ const getBrainReplsByOpenAI = () => {
19
+ return [(0, genBrainRepl_1.genBrainRepl)({ slug: 'openai/codex' })];
20
+ };
21
+ exports.getBrainReplsByOpenAI = getBrainReplsByOpenAI;
22
+ // re-export factories for direct access
23
+ var genBrainAtom_2 = require("../../domain.operations/atoms/genBrainAtom");
24
+ Object.defineProperty(exports, "genBrainAtom", { enumerable: true, get: function () { return genBrainAtom_2.genBrainAtom; } });
25
+ var genBrainRepl_2 = require("../../domain.operations/repls/genBrainRepl");
26
+ Object.defineProperty(exports, "genBrainRepl", { enumerable: true, get: function () { return genBrainRepl_2.genBrainRepl; } });
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/contract/sdk/index.ts"],"names":[],"mappings":";;;AAEA,6EAA0E;AAC1E,6EAA0E;AAE1E;;;GAGG;AACI,MAAM,qBAAqB,GAAG,GAAgB,EAAE;IACrD,OAAO,CAAC,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC;AACnD,CAAC,CAAC;AAFW,QAAA,qBAAqB,yBAEhC;AAEF;;;GAGG;AACI,MAAM,qBAAqB,GAAG,GAAgB,EAAE;IACrD,OAAO,CAAC,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC;AAClD,CAAC,CAAC;AAFW,QAAA,qBAAqB,yBAEhC;AAEF,wCAAwC;AACxC,2EAA0E;AAAjE,4GAAA,YAAY,OAAA;AACrB,2EAA0E;AAAjE,4GAAA,YAAY,OAAA"}
@@ -0,0 +1,19 @@
1
+ import { type BrainAtom } from 'rhachet';
2
+ /**
3
+ * .what = supported openai atom slugs
4
+ * .why = enables type-safe slug specification with model variants
5
+ */
6
+ type OpenAIAtomSlug = 'openai/gpt-4o' | 'openai/gpt-4o-mini' | 'openai/gpt-4-turbo' | 'openai/o1' | 'openai/o1-mini' | 'openai/o1-preview';
7
+ /**
8
+ * .what = factory to generate openai brain atom instances
9
+ * .why = enables model variant selection via slug
10
+ *
11
+ * .example
12
+ * genBrainAtom({ slug: 'openai/gpt-4o' })
13
+ * genBrainAtom({ slug: 'openai/gpt-4o-mini' }) // fast + cheap
14
+ * genBrainAtom({ slug: 'openai/o1' }) // advanced reasoning
15
+ */
16
+ export declare const genBrainAtom: (input: {
17
+ slug: OpenAIAtomSlug;
18
+ }) => BrainAtom;
19
+ export {};
@@ -0,0 +1,97 @@
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 rhachet_1 = require("rhachet");
9
+ const zod_1 = require("zod");
10
+ /**
11
+ * .what = model configuration by slug
12
+ * .why = maps slugs to API model names and descriptions
13
+ */
14
+ const CONFIG_BY_SLUG = {
15
+ 'openai/gpt-4o': {
16
+ model: 'gpt-4o',
17
+ description: 'gpt-4o - multimodal model for reasoning and vision',
18
+ },
19
+ 'openai/gpt-4o-mini': {
20
+ model: 'gpt-4o-mini',
21
+ description: 'gpt-4o-mini - fast and cost-effective multimodal model',
22
+ },
23
+ 'openai/gpt-4-turbo': {
24
+ model: 'gpt-4-turbo',
25
+ description: 'gpt-4-turbo - high capability with vision support',
26
+ },
27
+ 'openai/o1': {
28
+ model: 'o1',
29
+ description: 'o1 - advanced reasoning model for complex problems',
30
+ },
31
+ 'openai/o1-mini': {
32
+ model: 'o1-mini',
33
+ description: 'o1-mini - fast reasoning model for coding and math',
34
+ },
35
+ 'openai/o1-preview': {
36
+ model: 'o1-preview',
37
+ description: 'o1-preview - preview of advanced reasoning capabilities',
38
+ },
39
+ };
40
+ /**
41
+ * .what = factory to generate openai brain atom instances
42
+ * .why = enables model variant selection via slug
43
+ *
44
+ * .example
45
+ * genBrainAtom({ slug: 'openai/gpt-4o' })
46
+ * genBrainAtom({ slug: 'openai/gpt-4o-mini' }) // fast + cheap
47
+ * genBrainAtom({ slug: 'openai/o1' }) // advanced reasoning
48
+ */
49
+ const genBrainAtom = (input) => {
50
+ const config = CONFIG_BY_SLUG[input.slug];
51
+ return {
52
+ repo: 'openai',
53
+ slug: input.slug,
54
+ description: config.description,
55
+ /**
56
+ * .what = stateless inference (no tool use)
57
+ * .why = provides direct model access for reasoning tasks
58
+ */
59
+ ask: async (askInput, context) => {
60
+ // compose system prompt from briefs
61
+ const systemPrompt = askInput.role.briefs
62
+ ? await (0, rhachet_1.castBriefsToPrompt)({ briefs: askInput.role.briefs })
63
+ : undefined;
64
+ // get openai client from context or create new one
65
+ const openai = context?.openai ??
66
+ new openai_1.default({ apiKey: process.env.OPENAI_API_KEY });
67
+ // build messages array
68
+ const messages = [];
69
+ if (systemPrompt) {
70
+ messages.push({ role: 'system', content: systemPrompt });
71
+ }
72
+ messages.push({ role: 'user', content: askInput.prompt });
73
+ // convert zod schema to json schema for structured output
74
+ const jsonSchema = zod_1.z.toJSONSchema(askInput.schema.output);
75
+ // call openai api with strict json_schema response format
76
+ const response = await openai.chat.completions.create({
77
+ model: config.model,
78
+ messages,
79
+ response_format: {
80
+ type: 'json_schema',
81
+ json_schema: {
82
+ name: 'response',
83
+ strict: true,
84
+ schema: jsonSchema,
85
+ },
86
+ },
87
+ });
88
+ // extract content from response
89
+ const content = response.choices[0]?.message?.content ?? '';
90
+ // parse JSON response and validate via schema
91
+ const parsed = JSON.parse(content);
92
+ return askInput.schema.output.parse(parsed);
93
+ },
94
+ };
95
+ };
96
+ exports.genBrainAtom = genBrainAtom;
97
+ //# sourceMappingURL=genBrainAtom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"genBrainAtom.js","sourceRoot":"","sources":["../../../src/domain.operations/atoms/genBrainAtom.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,qCAA6D;AAI7D,6BAAwB;AAcxB;;;GAGG;AACH,MAAM,cAAc,GAGhB;IACF,eAAe,EAAE;QACf,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,oDAAoD;KAClE;IACD,oBAAoB,EAAE;QACpB,KAAK,EAAE,aAAa;QACpB,WAAW,EAAE,wDAAwD;KACtE;IACD,oBAAoB,EAAE;QACpB,KAAK,EAAE,aAAa;QACpB,WAAW,EAAE,mDAAmD;KACjE;IACD,WAAW,EAAE;QACX,KAAK,EAAE,IAAI;QACX,WAAW,EAAE,oDAAoD;KAClE;IACD,gBAAgB,EAAE;QAChB,KAAK,EAAE,SAAS;QAChB,WAAW,EAAE,oDAAoD;KAClE;IACD,mBAAmB,EAAE;QACnB,KAAK,EAAE,YAAY;QACnB,WAAW,EAAE,yDAAyD;KACvE;CACF,CAAC;AAEF;;;;;;;;GAQG;AACI,MAAM,YAAY,GAAG,CAAC,KAA+B,EAAa,EAAE;IACzE,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE1C,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,WAAW,EAAE,MAAM,CA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AAC,CAAC,EAAE,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC;YAE5D,8CAA8C;YAC9C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACnC,OAAO,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC9C,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AA9DW,QAAA,YAAY,gBA8DvB"}
@@ -0,0 +1,19 @@
1
+ import { BrainRepl } from 'rhachet';
2
+ /**
3
+ * .what = supported openai codex repl slugs
4
+ * .why = enables type-safe slug specification with model variants
5
+ */
6
+ type CodexSlug = 'openai/codex' | 'openai/codex/max' | 'openai/codex/mini' | 'openai/codex/5.2';
7
+ /**
8
+ * .what = factory to generate openai codex brain repl instances
9
+ * .why = enables model variant selection via slug
10
+ *
11
+ * .example
12
+ * genBrainRepl({ slug: 'openai/codex' }) // default model
13
+ * genBrainRepl({ slug: 'openai/codex/mini' }) // fast + cheap
14
+ * genBrainRepl({ slug: 'openai/codex/5.2' }) // most advanced
15
+ */
16
+ export declare const genBrainRepl: (input: {
17
+ slug: CodexSlug;
18
+ }) => BrainRepl;
19
+ export {};
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genBrainRepl = void 0;
4
+ const codex_sdk_1 = require("@openai/codex-sdk");
5
+ const rhachet_1 = require("rhachet");
6
+ const wrapper_fns_1 = require("wrapper-fns");
7
+ const asJsonSchema_1 = require("../../infra/schema/asJsonSchema");
8
+ /**
9
+ * .what = model configuration by slug
10
+ * .why = maps slugs to API model names and descriptions
11
+ */
12
+ const CONFIG_BY_SLUG = {
13
+ 'openai/codex': {
14
+ model: undefined, // use SDK default (gpt-5.1-codex-max)
15
+ description: 'codex - agentic coding assistant (default model)',
16
+ },
17
+ 'openai/codex/max': {
18
+ model: 'gpt-5.1-codex-max',
19
+ description: 'codex max - optimized for long-horizon agentic coding',
20
+ },
21
+ 'openai/codex/mini': {
22
+ model: 'gpt-5.1-codex-mini',
23
+ description: 'codex mini - fast and cost-effective',
24
+ },
25
+ 'openai/codex/5.2': {
26
+ model: 'gpt-5.2-codex',
27
+ description: 'codex 5.2 - most advanced agentic coding model',
28
+ },
29
+ };
30
+ /**
31
+ * .what = composes full prompt with optional system context
32
+ * .why = codex-sdk ThreadOptions doesn't have systemPrompt, must prepend to user prompt
33
+ */
34
+ const composePromptWithSystem = (userPrompt, systemPrompt) => {
35
+ if (!systemPrompt)
36
+ return userPrompt;
37
+ return `${systemPrompt}\n\n---\n\n${userPrompt}`;
38
+ };
39
+ /**
40
+ * .what = invokes codex sdk with specified sandbox mode
41
+ * .why = dedupes shared logic between ask (read-only) and act (workspace-write)
42
+ */
43
+ const invokeCodex = async (input) => {
44
+ // compose system prompt from briefs
45
+ const systemPrompt = input.role.briefs
46
+ ? await (0, rhachet_1.castBriefsToPrompt)({ briefs: input.role.briefs })
47
+ : undefined;
48
+ // convert zod schema to json schema for native enforcement
49
+ const outputSchema = (0, asJsonSchema_1.asJsonSchema)({
50
+ schema: input.schema.output,
51
+ });
52
+ // create codex client
53
+ const codex = new codex_sdk_1.Codex({
54
+ apiKey: process.env.OPENAI_API_KEY,
55
+ });
56
+ // start thread with sandbox mode based on operation type
57
+ const sandboxMode = input.mode === 'ask' ? 'read-only' : 'workspace-write';
58
+ const thread = codex.startThread({
59
+ model: input.model,
60
+ sandboxMode,
61
+ });
62
+ // compose full prompt and run with timeout + retry for resilience
63
+ const fullPrompt = composePromptWithSystem(input.prompt, systemPrompt);
64
+ const response = await (0, wrapper_fns_1.withRetry)((0, wrapper_fns_1.withTimeout)(async () => thread.run(fullPrompt, { outputSchema }), {
65
+ threshold: { seconds: 60 },
66
+ }))();
67
+ // parse output via schema for runtime validation
68
+ return input.schema.output.parse(JSON.parse(response.finalResponse));
69
+ };
70
+ /**
71
+ * .what = factory to generate openai codex brain repl instances
72
+ * .why = enables model variant selection via slug
73
+ *
74
+ * .example
75
+ * genBrainRepl({ slug: 'openai/codex' }) // default model
76
+ * genBrainRepl({ slug: 'openai/codex/mini' }) // fast + cheap
77
+ * genBrainRepl({ slug: 'openai/codex/5.2' }) // most advanced
78
+ */
79
+ const genBrainRepl = (input) => {
80
+ const config = CONFIG_BY_SLUG[input.slug];
81
+ // extract model slug without the repo prefix (e.g., 'openai/codex' -> 'codex')
82
+ const modelSlug = input.slug.replace(/^openai\//, '');
83
+ return new rhachet_1.BrainRepl({
84
+ repo: 'openai',
85
+ slug: modelSlug,
86
+ description: config.description,
87
+ /**
88
+ * .what = readonly analysis (research, queries, code review)
89
+ * .why = provides safe, non-mutating agent interactions via read-only sandbox
90
+ */
91
+ ask: async (askInput, _context) => invokeCodex({ mode: 'ask', model: config.model, ...askInput }),
92
+ /**
93
+ * .what = read+write actions (code changes, file edits)
94
+ * .why = provides full agentic capabilities via workspace-write sandbox
95
+ */
96
+ act: async (actInput, _context) => invokeCodex({ mode: 'act', model: config.model, ...actInput }),
97
+ });
98
+ };
99
+ exports.genBrainRepl = genBrainRepl;
100
+ //# sourceMappingURL=genBrainRepl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"genBrainRepl.js","sourceRoot":"","sources":["../../../src/domain.operations/repls/genBrainRepl.ts"],"names":[],"mappings":";;;AAAA,iDAA0C;AAC1C,qCAAwD;AAIxD,6CAAqD;AAGrD,iEAA8D;AAY9D;;;GAGG;AACH,MAAM,cAAc,GAGhB;IACF,cAAc,EAAE;QACd,KAAK,EAAE,SAAS,EAAE,sCAAsC;QACxD,WAAW,EAAE,kDAAkD;KAChE;IACD,kBAAkB,EAAE;QAClB,KAAK,EAAE,mBAAmB;QAC1B,WAAW,EAAE,uDAAuD;KACrE;IACD,mBAAmB,EAAE;QACnB,KAAK,EAAE,oBAAoB;QAC3B,WAAW,EAAE,sCAAsC;KACpD;IACD,kBAAkB,EAAE;QAClB,KAAK,EAAE,eAAe;QACtB,WAAW,EAAE,gDAAgD;KAC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E,SAAS,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;KAC3B,CAAC,CACH,EAAE,CAAC;IAEJ,iDAAiD;IACjD,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;AACvE,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACI,MAAM,YAAY,GAAG,CAAC,KAA0B,EAAa,EAAE;IACpE,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE1C,+EAA+E;IAC/E,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAEtD,OAAO,IAAI,mBAAS,CAAC;QACnB,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,MAAM,CAAC,WAAW;QAE/B;;;WAGG;QACH,GAAG,EAAE,KAAK,EACR,QAIC,EACD,QAAgB,EACE,EAAE,CACpB,WAAW,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,GAAG,QAAQ,EAAE,CAAC;QAEhE;;;WAGG;QACH,GAAG,EAAE,KAAK,EACR,QAIC,EACD,QAAgB,EACE,EAAE,CACpB,WAAW,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,GAAG,QAAQ,EAAE,CAAC;KACjE,CAAC,CAAC;AACL,CAAC,CAAC;AAvCW,QAAA,YAAY,gBAuCvB"}
@@ -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,106 @@
1
+ {
2
+ "name": "rhachet-brains-openai",
3
+ "author": "ehmpathy",
4
+ "description": "rhachet BrainAtom & BrainRepl contracts for openai inference",
5
+ "version": "0.0.0",
6
+ "repository": "ehmpathy/rhachet-brains-openai",
7
+ "homepage": "https://github.com/ehmpathy/rhachet-brains-openai",
8
+ "keywords": [
9
+ "artifact",
10
+ "git",
11
+ "file",
12
+ "repo"
13
+ ],
14
+ "bugs": "https://github.com/ehmpathy/rhachet-brains-openai/issues",
15
+ "license": "MIT",
16
+ "main": "dist/index.js",
17
+ "engines": {
18
+ "node": ">=8.0.0"
19
+ },
20
+ "files": [
21
+ "/dist"
22
+ ],
23
+ "dependencies": {
24
+ "@ehmpathy/uni-time": "1.8.1",
25
+ "@openai/codex-sdk": "0.77.0",
26
+ "as-procedure": "1.1.7",
27
+ "domain-objects": "0.31.9",
28
+ "find-up": "5.0.0",
29
+ "hash-fns": "1.1.0",
30
+ "helpful-errors": "1.5.3",
31
+ "openai": "5.8.2",
32
+ "rhachet-artifact": "1.0.1",
33
+ "rhachet-artifact-git": "1.1.5",
34
+ "serde-fns": "1.3.0",
35
+ "type-fns": "1.21.0",
36
+ "wrapper-fns": "1.1.7",
37
+ "zod": "4.3.4"
38
+ },
39
+ "devDependencies": {
40
+ "@biomejs/biome": "2.3.8",
41
+ "@commitlint/cli": "19.5.0",
42
+ "@commitlint/config-conventional": "19.5.0",
43
+ "@swc/core": "1.15.3",
44
+ "@swc/jest": "0.2.39",
45
+ "@tsconfig/node20": "20.1.5",
46
+ "@tsconfig/strictest": "2.0.5",
47
+ "@types/jest": "30.0.0",
48
+ "@types/node": "22.15.21",
49
+ "cz-conventional-changelog": "3.3.0",
50
+ "declapract": "0.13.14",
51
+ "declapract-typescript-ehmpathy": "0.47.16",
52
+ "declastruct": "1.7.3",
53
+ "declastruct-github": "1.3.0",
54
+ "depcheck": "1.4.3",
55
+ "esbuild-register": "3.6.0",
56
+ "husky": "8.0.3",
57
+ "jest": "30.2.0",
58
+ "rhachet": "1.21.4",
59
+ "rhachet-roles-bhrain": "0.5.9",
60
+ "rhachet-roles-bhuild": "0.6.3",
61
+ "rhachet-roles-ehmpathy": "1.17.15",
62
+ "test-fns": "1.5.0",
63
+ "tsc-alias": "1.8.10",
64
+ "tsx": "4.20.6",
65
+ "typescript": "5.4.5",
66
+ "yalc": "1.0.0-pre.53"
67
+ },
68
+ "config": {
69
+ "commitizen": {
70
+ "path": "./node_modules/cz-conventional-changelog"
71
+ }
72
+ },
73
+ "scripts": {
74
+ "build:ts": "tsc -p ./tsconfig.build.json",
75
+ "commit:with-cli": "npx cz",
76
+ "fix:format:biome": "biome check --write",
77
+ "fix:format": "npm run fix:format:biome",
78
+ "fix:lint": "biome check --write",
79
+ "fix": "npm run fix:format && npm run fix:lint",
80
+ "build:clean:bun": "rm -f ./bin/*.bc",
81
+ "build:clean:tsc": "(chmod -R u+w dist 2>/dev/null || true) && rm -rf dist/",
82
+ "build:clean": "npm run build:clean:tsc && npm run build:clean:bun",
83
+ "build:compile:tsc": "tsc -p ./tsconfig.build.json && tsc-alias -p ./tsconfig.build.json",
84
+ "build:compile": "npm run build:compile:tsc && npm run build:compile:bun --if-present",
85
+ "build": "npm run build:clean && npm run build:compile && npm run build:complete --if-present",
86
+ "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",
87
+ "test:types": "tsc -p ./tsconfig.json --noEmit",
88
+ "test:format:biome": "biome format",
89
+ "test:format": "npm run test:format:biome",
90
+ "test:lint:deps": "npx depcheck -c ./.depcheckrc.yml",
91
+ "test:lint:biome": "biome check --diagnostic-level=error",
92
+ "test:lint:biome:all": "biome check",
93
+ "test:lint": "npm run test:lint:biome && npm run test:lint:deps",
94
+ "test:unit": "jest -c ./jest.unit.config.ts --forceExit --verbose --passWithNoTests $([ -z $THOROUGH ] && echo '--changedSince=main') $([ -n $RESNAP ] && echo '--updateSnapshot')",
95
+ "test:integration": "jest -c ./jest.integration.config.ts --forceExit --verbose --passWithNoTests $([ -z $THOROUGH ] && echo '--changedSince=main') $([ -n $RESNAP ] && echo '--updateSnapshot')",
96
+ "test:acceptance:locally": "npm run build && LOCALLY=true jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests $([ -n $RESNAP ] && echo '--updateSnapshot')",
97
+ "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",
98
+ "test:acceptance": "npm run build && jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests $([ -n $RESNAP ] && echo '--updateSnapshot')",
99
+ "prepush": "npm run test && npm run build",
100
+ "prepublish": "npm run build",
101
+ "preversion": "npm run prepush",
102
+ "postversion": "git push origin HEAD --tags --no-verify",
103
+ "prepare:husky": "husky install && chmod ug+x .husky/*",
104
+ "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"
105
+ }
106
+ }
package/readme.md ADDED
@@ -0,0 +1,80 @@
1
+ # rhachet-brains-openai
2
+
3
+ rhachet BrainAtom & BrainRepl contracts for openai inference
4
+
5
+ ## install
6
+
7
+ ```sh
8
+ npm install rhachet-brains-openai
9
+ ```
10
+
11
+ ## usage
12
+
13
+ ```ts
14
+ import { genBrainAtom, genBrainRepl } from 'rhachet-brains-openai';
15
+ import { z } from 'zod';
16
+
17
+ // create a brain atom for direct model inference
18
+ const brainAtom = genBrainAtom({ slug: 'openai/gpt-4o-mini' });
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
+ // create a brain repl for agentic tasks
35
+ const brainRepl = genBrainRepl({ slug: 'openai/codex' });
36
+
37
+ const result = await brainRepl.ask({
38
+ role: { briefs: [] },
39
+ prompt: 'analyze this codebase',
40
+ schema: { output: z.object({ content: z.string() }) },
41
+ });
42
+
43
+ // use act() for read+write operations
44
+ const result = await brainRepl.act({
45
+ role: { briefs: [] },
46
+ prompt: 'refactor this module',
47
+ schema: { output: z.object({ content: z.string() }) },
48
+ });
49
+ ```
50
+
51
+ ## available brains
52
+
53
+ ### atoms (via genBrainAtom)
54
+
55
+ stateless inference without tool use.
56
+
57
+ | slug | model | description |
58
+ | -------------------- | ----------- | --------------------------------------------- |
59
+ | `openai/gpt-4o` | gpt-4o | multimodal model for reasoning and vision |
60
+ | `openai/gpt-4o-mini` | gpt-4o-mini | fast and cost-effective multimodal model |
61
+ | `openai/gpt-4-turbo` | gpt-4-turbo | high capability with vision support |
62
+ | `openai/o1` | o1 | advanced reasoning model for complex problems |
63
+ | `openai/o1-mini` | o1-mini | fast reasoning model for coding and math |
64
+ | `openai/o1-preview` | o1-preview | preview of advanced reasoning capabilities |
65
+
66
+ ### repls (via genBrainRepl)
67
+
68
+ agentic coding assistant with tool use via codex-sdk.
69
+
70
+ | slug | model | description |
71
+ | ------------------- | ------------------ | ----------------------------------------- |
72
+ | `openai/codex` | default | uses SDK default (gpt-5.1-codex-max) |
73
+ | `openai/codex/max` | gpt-5.1-codex-max | optimized for long-horizon agentic coding |
74
+ | `openai/codex/mini` | gpt-5.1-codex-mini | fast and cost-effective |
75
+ | `openai/codex/5.2` | gpt-5.2-codex | most advanced agentic coding model |
76
+
77
+ ## sources
78
+
79
+ - [Codex Models Documentation](https://developers.openai.com/codex/models/)
80
+ - [Codex SDK Documentation](https://developers.openai.com/codex/sdk/)