@meetopenbot/codex 1.2.1 → 1.2.3

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.
Files changed (2) hide show
  1. package/dist/index.js +102 -20
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -50,7 +50,8 @@ function resolveCodexConfig(config) {
50
50
  import {
51
51
  isCloudMode,
52
52
  llmAuthNotConfiguredMessage,
53
- resolveByokApiKey
53
+ resolveByokApiKey,
54
+ textReply as textReply2
54
55
  } from "@meetopenbot/plugin-sdk";
55
56
  import { Codex } from "@openai/codex-sdk";
56
57
 
@@ -90,8 +91,100 @@ function creditsErrorMessage(message) {
90
91
  import { threadSession } from "@meetopenbot/plugin-sdk";
91
92
  var codexSession = threadSession("codexThreadId");
92
93
 
94
+ // src/stream.ts
95
+ import {
96
+ createTextReplyBuffer,
97
+ textReply
98
+ } from "@meetopenbot/plugin-sdk";
99
+ var TOOL_ITEM_TYPES = /* @__PURE__ */ new Set([
100
+ "command_execution",
101
+ "mcp_tool_call",
102
+ "web_search",
103
+ "file_change"
104
+ ]);
105
+ var codexToolHint = (item, done) => {
106
+ if (!TOOL_ITEM_TYPES.has(item.type)) return void 0;
107
+ if (item.type === "command_execution") {
108
+ const hint = {
109
+ id: item.id,
110
+ name: "bash",
111
+ input: { command: item.command }
112
+ };
113
+ if (!done) return { type: "tool_call", ...hint };
114
+ return {
115
+ type: "tool_result",
116
+ ...hint,
117
+ output: item.aggregated_output,
118
+ error: item.status === "failed" || item.exit_code != null && item.exit_code !== 0
119
+ };
120
+ }
121
+ if (item.type === "mcp_tool_call") {
122
+ const hint = {
123
+ id: item.id,
124
+ name: item.server ? `${item.server}: ${item.tool}` : item.tool,
125
+ input: item.arguments
126
+ };
127
+ if (!done) return { type: "tool_call", ...hint };
128
+ return {
129
+ type: "tool_result",
130
+ ...hint,
131
+ output: item.error?.message ?? item.result,
132
+ error: item.status === "failed"
133
+ };
134
+ }
135
+ if (item.type === "web_search") {
136
+ const hint = { id: item.id, name: "web_search", input: { query: item.query } };
137
+ if (!done) return { type: "tool_call", ...hint };
138
+ return { type: "tool_result", ...hint, output: item.query };
139
+ }
140
+ if (item.type === "file_change") {
141
+ const hint = { id: item.id, name: "file_change", input: { changes: item.changes } };
142
+ if (!done) return { type: "tool_call", ...hint };
143
+ return {
144
+ type: "tool_result",
145
+ ...hint,
146
+ output: item.changes,
147
+ error: item.status === "failed"
148
+ };
149
+ }
150
+ return void 0;
151
+ };
152
+ var classifyCodexEvent = (chunk) => {
153
+ if (chunk.type === "item.started" || chunk.type === "item.completed") {
154
+ const tool = codexToolHint(chunk.item, chunk.type === "item.completed");
155
+ if (tool) return tool;
156
+ }
157
+ if (chunk.type === "item.completed" && chunk.item.type === "agent_message" && chunk.item.text.trim()) {
158
+ return { type: "text", text: chunk.item.text };
159
+ }
160
+ if (chunk.type === "turn.completed") return { type: "flush" };
161
+ return { type: "skip" };
162
+ };
163
+ async function* runCodexStream(args) {
164
+ const { events, state, storage } = args;
165
+ const replies = createTextReplyBuffer({ groupId: "codex:tools" });
166
+ for await (const chunk of events) {
167
+ if (chunk.type === "thread.started") {
168
+ await codexSession.write(state, storage, chunk.thread_id);
169
+ continue;
170
+ }
171
+ if (chunk.type === "turn.failed") {
172
+ yield* replies.end();
173
+ yield textReply(creditsErrorMessage(chunk.error.message) ?? chunk.error.message);
174
+ return;
175
+ }
176
+ if (chunk.type === "error") {
177
+ yield* replies.end();
178
+ yield textReply(creditsErrorMessage(chunk.message) ?? chunk.message);
179
+ return;
180
+ }
181
+ yield* replies.apply(classifyCodexEvent(chunk));
182
+ }
183
+ yield* replies.end();
184
+ }
185
+
93
186
  // src/runtime.ts
94
- async function runCodexTurn({
187
+ async function* runCodexTurn({
95
188
  prompt,
96
189
  handlerCtx,
97
190
  context
@@ -99,7 +192,8 @@ async function runCodexTurn({
99
192
  const byok = resolveByokApiKey("openai", ["CODEX_API_KEY"]);
100
193
  const credits = !byok && isCloudMode() ? resolveCreditsAuthConfig() : void 0;
101
194
  if (!byok && !credits) {
102
- return llmAuthNotConfiguredMessage("OPENAI_API_KEY");
195
+ yield textReply2(llmAuthNotConfiguredMessage("OPENAI_API_KEY"));
196
+ return;
103
197
  }
104
198
  const config = resolveCodexConfig(context.config);
105
199
  const client = new Codex({
@@ -120,23 +214,11 @@ async function runCodexTurn({
120
214
  const { events } = await thread.runStreamed(prompt, {
121
215
  signal: context.abortSignal
122
216
  });
123
- let text = "";
124
- for await (const chunk of events) {
125
- if (chunk.type === "thread.started") {
126
- await codexSession.write(handlerCtx.state, context.storage, chunk.thread_id);
127
- continue;
128
- }
129
- if (chunk.type === "turn.failed") {
130
- return creditsErrorMessage(chunk.error.message) ?? chunk.error.message;
131
- }
132
- if (chunk.type === "error") {
133
- return creditsErrorMessage(chunk.message) ?? chunk.message;
134
- }
135
- if (chunk.type === "item.completed" && chunk.item.type === "agent_message" && chunk.item.text.trim()) {
136
- text = chunk.item.text.trim();
137
- }
138
- }
139
- return text;
217
+ yield* runCodexStream({
218
+ events,
219
+ state: handlerCtx.state,
220
+ storage: context.storage
221
+ });
140
222
  }
141
223
 
142
224
  // src/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetopenbot/codex",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "type": "module",
5
5
  "description": "OpenAI Codex agent plugin for OpenBot",
6
6
  "main": "./dist/index.js",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "@openai/codex-sdk": "0.148.0",
22
- "@meetopenbot/plugin-sdk": "^0.3.0"
22
+ "@meetopenbot/plugin-sdk": "^0.5.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "^25.6.0",