rhachet-brains-openai 0.1.9 → 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.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "rhachet-brains-openai",
3
3
  "author": "ehmpathy",
4
4
  "description": "rhachet brain.atom and brain.repl adapter for openai",
5
- "version": "0.1.9",
5
+ "version": "0.2.1",
6
6
  "repository": "ehmpathy/rhachet-brains-openai",
7
7
  "homepage": "https://github.com/ehmpathy/rhachet-brains-openai",
8
8
  "keywords": [
@@ -54,12 +54,13 @@
54
54
  "preversion": "npm run prepush",
55
55
  "postversion": "git push origin HEAD --tags --no-verify",
56
56
  "prepare:husky": "husky install && chmod ug+x .husky/*",
57
- "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",
57
+ "prepare:rhachet": "rhachet init --hooks --roles behaver mechanic reviewer",
58
58
  "prepare": "if [ -e .git ] && [ -z $CI ]; then npm run prepare:husky && npm run prepare:rhachet; fi"
59
59
  },
60
60
  "dependencies": {
61
61
  "domain-objects": "0.31.9",
62
62
  "helpful-errors": "1.5.3",
63
+ "iso-price": "1.1.1",
63
64
  "openai": "5.8.2",
64
65
  "rhachet-artifact": "1.0.1",
65
66
  "rhachet-artifact-git": "1.1.5",
@@ -87,12 +88,14 @@
87
88
  "esbuild": "0.27.2",
88
89
  "esbuild-register": "3.6.0",
89
90
  "husky": "8.0.3",
91
+ "iso-time": "1.11.1",
90
92
  "jest": "30.2.0",
91
- "rhachet": "1.21.4",
92
- "rhachet-roles-bhrain": "0.5.9",
93
- "rhachet-roles-bhuild": "0.6.3",
94
- "rhachet-roles-ehmpathy": "1.17.15",
95
- "test-fns": "1.5.0",
93
+ "rhachet": "1.29.5",
94
+ "rhachet-brains-anthropic": "0.3.2",
95
+ "rhachet-roles-bhrain": "0.7.5",
96
+ "rhachet-roles-bhuild": "0.7.0",
97
+ "rhachet-roles-ehmpathy": "1.18.0",
98
+ "test-fns": "1.10.0",
96
99
  "tsc-alias": "1.8.10",
97
100
  "tsx": "4.20.6",
98
101
  "typescript": "5.4.5",
package/readme.md CHANGED
@@ -8,6 +8,8 @@ rhachet brain.atom and brain.repl adapter for openai
8
8
  npm install rhachet-brains-openai
9
9
  ```
10
10
 
11
+ note: this package bundles `@openai/codex-sdk` js for seamless cjs (e.g., jest) compatibility. vendor binaries come from the peer dep.
12
+
11
13
  ## usage
12
14
 
13
15
  ```ts
@@ -15,17 +17,17 @@ import { genBrainAtom, genBrainRepl } from 'rhachet-brains-openai';
15
17
  import { z } from 'zod';
16
18
 
17
19
  // create a brain atom for direct model inference
18
- const brainAtom = genBrainAtom({ slug: 'openai/gpt-4o-mini' });
20
+ const brainAtom = genBrainAtom({ slug: 'openai/gpt/4o-mini' });
19
21
 
20
22
  // simple string output
21
- const explanation = await brainAtom.ask({
23
+ const { output: explanation } = await brainAtom.ask({
22
24
  role: { briefs: [] },
23
25
  prompt: 'explain this code',
24
26
  schema: { output: z.string() },
25
27
  });
26
28
 
27
29
  // structured object output
28
- const { summary, issues } = await brainAtom.ask({
30
+ const { output: { summary, issues } } = await brainAtom.ask({
29
31
  role: { briefs: [] },
30
32
  prompt: 'analyze this code',
31
33
  schema: { output: z.object({ summary: z.string(), issues: z.array(z.string()) }) },
@@ -35,47 +37,125 @@ const { summary, issues } = await brainAtom.ask({
35
37
  const brainRepl = genBrainRepl({ slug: 'openai/codex' });
36
38
 
37
39
  // use ask() for read-only operations
38
- const { analysis } = await brainRepl.ask({
40
+ const { output: { analysis } } = await brainRepl.ask({
39
41
  role: { briefs: [] },
40
42
  prompt: 'analyze this codebase',
41
43
  schema: { output: z.object({ analysis: z.string() }) },
42
44
  });
43
45
 
44
46
  // use act() for read+write operations
45
- const { proposal } = await brainRepl.act({
47
+ const { output: { proposal } } = await brainRepl.act({
46
48
  role: { briefs: [] },
47
49
  prompt: 'refactor this module',
48
50
  schema: { output: z.object({ proposal: z.string() }) },
49
51
  });
50
52
  ```
51
53
 
54
+ ## continuation support
55
+
56
+ both atoms and repls support multi-turn conversations via episode continuation.
57
+
58
+ ### atoms
59
+
60
+ atoms support continuation via the openai responses api. pass the prior episode to continue the conversation:
61
+
62
+ ```ts
63
+ // first call establishes context
64
+ const resultFirst = await brainAtom.ask({
65
+ role: {},
66
+ prompt: 'remember the secret word "PINEAPPLE42"',
67
+ schema: { output: z.object({ content: z.string() }) },
68
+ });
69
+
70
+ // second call continues with prior context
71
+ const resultSecond = await brainAtom.ask({
72
+ on: { episode: resultFirst.episode },
73
+ role: {},
74
+ prompt: 'what is the secret word I told you?',
75
+ schema: { output: z.object({ content: z.string() }) },
76
+ });
77
+ // resultSecond.output.content contains "PINEAPPLE42"
78
+ ```
79
+
80
+ ### repls
81
+
82
+ repls support continuation via the codex-sdk `resumeThread()` api. the episode exid contains the thread id prefixed with `openai/codex/` for cross-supplier validation:
83
+
84
+ ```ts
85
+ // first call starts a new thread
86
+ const resultFirst = await brainRepl.ask({
87
+ role: {},
88
+ prompt: 'remember the secret word "MANGO99"',
89
+ schema: { output: z.object({ content: z.string() }) },
90
+ });
91
+ // resultFirst.episode.exid = "openai/codex/{threadId}"
92
+
93
+ // second call resumes the thread
94
+ const resultSecond = await brainRepl.ask({
95
+ on: { episode: resultFirst.episode },
96
+ role: {},
97
+ prompt: 'what is the secret word I told you?',
98
+ schema: { output: z.object({ content: z.string() }) },
99
+ });
100
+ // resultSecond.output.content contains "MANGO99"
101
+ ```
102
+
103
+ ### limitations
104
+
105
+ - **cross-supplier continuation is not supported**: episodes from other brain suppliers (e.g., anthropic) cannot be used to continue openai conversations. this throws a `BadRequestError`.
106
+ - **exid validation**: the episode exid must start with `openai/codex/` for repl continuation. this prevents accidental cross-supplier continuation attempts.
107
+
52
108
  ## available brains
53
109
 
54
110
  ### atoms (via genBrainAtom)
55
111
 
56
112
  stateless inference without tool use.
57
113
 
58
- | slug | model | description |
59
- | -------------------- | ----------- | --------------------------------------------- |
60
- | `openai/gpt-4o` | gpt-4o | multimodal model for reasoning and vision |
61
- | `openai/gpt-4o-mini` | gpt-4o-mini | fast and cost-effective multimodal model |
62
- | `openai/gpt-4-turbo` | gpt-4-turbo | high capability with vision support |
63
- | `openai/o1` | o1 | advanced reasoning model for complex problems |
64
- | `openai/o1-mini` | o1-mini | fast reasoning model for coding and math |
65
- | `openai/o1-preview` | o1-preview | preview of advanced reasoning capabilities |
114
+ | slug | model | context | cost (input) | cost (output) | cutoff |
115
+ | ------------------------------ | ------------------- | ------- | ------------ | ------------- | ------- |
116
+ | `openai/gpt/5.2-instant` | gpt-5.2-instant | 400K | $1.75/1M | $14/1M | 2025-08 |
117
+ | `openai/gpt/5.2-pro` | gpt-5.2-pro | 400K | $21/1M | $168/1M | 2025-08 |
118
+ | `openai/gpt/5.2-thoughtful` | gpt-5.2 | 400K | $1.75/1M | $14/1M | 2025-08 |
119
+ | `openai/gpt/codex/5.2` | gpt-5.2-codex | 400K | $10/1M | $40/1M | 2025-08 |
120
+ | `openai/gpt/5` | gpt-5 | 400K | $1.25/1M | $10/1M | 2024-09 |
121
+ | `openai/gpt/5-pro` | gpt-5-pro | 272K | $15/1M | $120/1M | 2024-09 |
122
+ | `openai/gpt/5-thoughtful` | gpt-5-thinking | 400K | $1.25/1M | $10/1M | 2024-09 |
123
+ | `openai/gpt/5-thoughtful-mini` | gpt-5-thinking-mini | 400K | $0.25/1M | $2/1M | 2024-09 |
124
+ | `openai/gpt/5.1-instant` | gpt-5.1-chat-latest | 400K | $1.25/1M | $10/1M | 2024-09 |
125
+ | `openai/gpt/5.1-thoughtful` | gpt-5.1 | 400K | $1.25/1M | $10/1M | 2024-09 |
126
+ | `openai/gpt/codex/5.1-max` | gpt-5.1-codex-max | 400K | $7.50/1M | $30/1M | 2024-09 |
127
+ | `openai/gpt/codex/5.1-mini` | gpt-5.1-codex-mini | 400K | $3/1M | $12/1M | 2024-09 |
128
+ | `openai/gpt/4.1` | gpt-4.1 | 1M | $2/1M | $8/1M | 2024-06 |
129
+ | `openai/gpt/4.1-mini` | gpt-4.1-mini | 128K | $0.40/1M | $1.60/1M | 2024-06 |
130
+ | `openai/gpt/4.1-nano` | gpt-4.1-nano | 1M | $0.10/1M | $0.40/1M | 2024-06 |
131
+ | `openai/o/3` | o3 | 200K | $0.40/1M | $1.60/1M | 2024-06 |
132
+ | `openai/o/3-mini` | o3-mini | 200K | $1.10/1M | $4.40/1M | 2024-06 |
133
+ | `openai/o/3-pro` | o3-pro | 200K | $20/1M | $80/1M | 2024-06 |
134
+ | `openai/o/4-mini` | o4-mini | 200K | $1.10/1M | $4.40/1M | 2024-06 |
135
+ | `openai/gpt/5-mini` | gpt-5-mini | 400K | $0.25/1M | $2/1M | 2024-05 |
136
+ | `openai/gpt/4-turbo` | gpt-4-turbo | 128K | $10/1M | $30/1M | 2023-12 |
137
+ | `openai/gpt/4o` | gpt-4o | 128K | $2.50/1M | $10/1M | 2023-10 |
138
+ | `openai/gpt/4o-mini` | gpt-4o-mini | 128K | $0.15/1M | $0.60/1M | 2023-10 |
139
+ | `openai/o/1` | o1 | 200K | $15/1M | $60/1M | 2023-10 |
140
+ | `openai/o/1-mini` | o1-mini | 128K | $3/1M | $12/1M | 2023-10 |
141
+ | `openai/o/1-preview` | o1-preview | 128K | $15/1M | $60/1M | 2023-10 |
66
142
 
67
143
  ### repls (via genBrainRepl)
68
144
 
69
- agentic coding assistant with tool use via codex-sdk.
145
+ agentic code assistant with tool use via codex-sdk.
70
146
 
71
- | slug | model | description |
72
- | ------------------- | ------------------ | ----------------------------------------- |
73
- | `openai/codex` | default | uses SDK default (gpt-5.1-codex-max) |
74
- | `openai/codex/max` | gpt-5.1-codex-max | optimized for long-horizon agentic coding |
75
- | `openai/codex/mini` | gpt-5.1-codex-mini | fast and cost-effective |
76
- | `openai/codex/5.2` | gpt-5.2-codex | most advanced agentic coding model |
147
+ | slug | model | context | cost (input) | cost (output) | cutoff |
148
+ | ------------------------ | ------------------ | ------- | ------------ | ------------- | ------- |
149
+ | `openai/codex` | gpt-5.1-codex-max | 400K | $7.50/1M | $30/1M | 2024-09 |
150
+ | `openai/codex/mini` | gpt-5.1-codex-mini | 400K | $3/1M | $12/1M | 2024-09 |
151
+ | `openai/codex/max` | gpt-5.1-codex-max | 400K | $7.50/1M | $30/1M | 2024-09 |
152
+ | `openai/codex/5.1` | gpt-5.1-codex-max | 400K | $7.50/1M | $30/1M | 2024-09 |
153
+ | `openai/codex/5.2` | gpt-5.2-codex | 400K | $10/1M | $40/1M | 2025-08 |
154
+ | `openai/codex/mini/5.1` | gpt-5.1-codex-mini | 400K | $3/1M | $12/1M | 2024-09 |
155
+ | `openai/codex/max/5.1` | gpt-5.1-codex-max | 400K | $7.50/1M | $30/1M | 2024-09 |
77
156
 
78
157
  ## sources
79
158
 
80
- - [Codex Models Documentation](https://developers.openai.com/codex/models/)
81
- - [Codex SDK Documentation](https://developers.openai.com/codex/sdk/)
159
+ - [openai api costs](https://openai.com/api/pricing/)
160
+ - [codex models documentation](https://developers.openai.com/codex/models/)
161
+ - [codex sdk documentation](https://developers.openai.com/codex/sdk/)