@meetopenbot/codex 1.2.1 → 1.2.2
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/dist/index.js +45 -20
- 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,43 @@ 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 classifyCodexEvent = (chunk) => {
|
|
100
|
+
if (chunk.type === "item.completed" && chunk.item.type === "agent_message" && chunk.item.text.trim()) {
|
|
101
|
+
return { type: "text", text: chunk.item.text };
|
|
102
|
+
}
|
|
103
|
+
if (chunk.type === "turn.completed") return { type: "flush" };
|
|
104
|
+
return { type: "skip" };
|
|
105
|
+
};
|
|
106
|
+
async function* runCodexStream(args) {
|
|
107
|
+
const { events, state, storage } = args;
|
|
108
|
+
const replies = createTextReplyBuffer();
|
|
109
|
+
for await (const chunk of events) {
|
|
110
|
+
if (chunk.type === "thread.started") {
|
|
111
|
+
await codexSession.write(state, storage, chunk.thread_id);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (chunk.type === "turn.failed") {
|
|
115
|
+
yield* replies.end();
|
|
116
|
+
yield textReply(creditsErrorMessage(chunk.error.message) ?? chunk.error.message);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (chunk.type === "error") {
|
|
120
|
+
yield* replies.end();
|
|
121
|
+
yield textReply(creditsErrorMessage(chunk.message) ?? chunk.message);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
yield* replies.apply(classifyCodexEvent(chunk));
|
|
125
|
+
}
|
|
126
|
+
yield* replies.end();
|
|
127
|
+
}
|
|
128
|
+
|
|
93
129
|
// src/runtime.ts
|
|
94
|
-
async function runCodexTurn({
|
|
130
|
+
async function* runCodexTurn({
|
|
95
131
|
prompt,
|
|
96
132
|
handlerCtx,
|
|
97
133
|
context
|
|
@@ -99,7 +135,8 @@ async function runCodexTurn({
|
|
|
99
135
|
const byok = resolveByokApiKey("openai", ["CODEX_API_KEY"]);
|
|
100
136
|
const credits = !byok && isCloudMode() ? resolveCreditsAuthConfig() : void 0;
|
|
101
137
|
if (!byok && !credits) {
|
|
102
|
-
|
|
138
|
+
yield textReply2(llmAuthNotConfiguredMessage("OPENAI_API_KEY"));
|
|
139
|
+
return;
|
|
103
140
|
}
|
|
104
141
|
const config = resolveCodexConfig(context.config);
|
|
105
142
|
const client = new Codex({
|
|
@@ -120,23 +157,11 @@ async function runCodexTurn({
|
|
|
120
157
|
const { events } = await thread.runStreamed(prompt, {
|
|
121
158
|
signal: context.abortSignal
|
|
122
159
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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;
|
|
160
|
+
yield* runCodexStream({
|
|
161
|
+
events,
|
|
162
|
+
state: handlerCtx.state,
|
|
163
|
+
storage: context.storage
|
|
164
|
+
});
|
|
140
165
|
}
|
|
141
166
|
|
|
142
167
|
// src/index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meetopenbot/codex",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
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.
|
|
22
|
+
"@meetopenbot/plugin-sdk": "^0.4.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^25.6.0",
|