@meetopenbot/codex 1.0.10 → 1.0.11
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 +132 -535
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,543 +1,140 @@
|
|
|
1
|
-
//
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
async *runStreamedInternal(input, turnOptions = {}) {
|
|
57
|
-
const { schemaPath, cleanup } = await createOutputSchemaFile(turnOptions.outputSchema);
|
|
58
|
-
const options = this._threadOptions;
|
|
59
|
-
const { prompt, images } = normalizeInput(input);
|
|
60
|
-
const generator = this._exec.run({
|
|
61
|
-
input: prompt,
|
|
62
|
-
baseUrl: this._options.baseUrl,
|
|
63
|
-
apiKey: this._options.apiKey,
|
|
64
|
-
threadId: this._id,
|
|
65
|
-
images,
|
|
66
|
-
model: options?.model,
|
|
67
|
-
sandboxMode: options?.sandboxMode,
|
|
68
|
-
workingDirectory: options?.workingDirectory,
|
|
69
|
-
skipGitRepoCheck: options?.skipGitRepoCheck,
|
|
70
|
-
outputSchemaFile: schemaPath,
|
|
71
|
-
modelReasoningEffort: options?.modelReasoningEffort,
|
|
72
|
-
signal: turnOptions.signal,
|
|
73
|
-
networkAccessEnabled: options?.networkAccessEnabled,
|
|
74
|
-
webSearchMode: options?.webSearchMode,
|
|
75
|
-
webSearchEnabled: options?.webSearchEnabled,
|
|
76
|
-
approvalPolicy: options?.approvalPolicy,
|
|
77
|
-
additionalDirectories: options?.additionalDirectories
|
|
78
|
-
});
|
|
79
|
-
try {
|
|
80
|
-
for await (const item of generator) {
|
|
81
|
-
let parsed;
|
|
82
|
-
try {
|
|
83
|
-
parsed = JSON.parse(item);
|
|
84
|
-
} catch (error) {
|
|
85
|
-
throw new Error(`Failed to parse item: ${item}`, { cause: error });
|
|
86
|
-
}
|
|
87
|
-
if (parsed.type === "thread.started") {
|
|
88
|
-
this._id = parsed.thread_id;
|
|
89
|
-
}
|
|
90
|
-
yield parsed;
|
|
91
|
-
}
|
|
92
|
-
} finally {
|
|
93
|
-
await cleanup();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/** Provides the input to the agent and returns the completed turn. */
|
|
97
|
-
async run(input, turnOptions = {}) {
|
|
98
|
-
const generator = this.runStreamedInternal(input, turnOptions);
|
|
99
|
-
const items = [];
|
|
100
|
-
let finalResponse = "";
|
|
101
|
-
let usage = null;
|
|
102
|
-
let turnFailure = null;
|
|
103
|
-
for await (const event of generator) {
|
|
104
|
-
if (event.type === "item.completed") {
|
|
105
|
-
if (event.item.type === "agent_message") {
|
|
106
|
-
finalResponse = event.item.text;
|
|
107
|
-
}
|
|
108
|
-
items.push(event.item);
|
|
109
|
-
} else if (event.type === "turn.completed") {
|
|
110
|
-
usage = event.usage;
|
|
111
|
-
} else if (event.type === "turn.failed") {
|
|
112
|
-
turnFailure = event.error;
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
if (turnFailure) {
|
|
117
|
-
throw new Error(turnFailure.message);
|
|
118
|
-
}
|
|
119
|
-
return { items, finalResponse, usage };
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
function normalizeInput(input) {
|
|
123
|
-
if (typeof input === "string") {
|
|
124
|
-
return { prompt: input, images: [] };
|
|
125
|
-
}
|
|
126
|
-
const promptParts = [];
|
|
127
|
-
const images = [];
|
|
128
|
-
for (const item of input) {
|
|
129
|
-
if (item.type === "text") {
|
|
130
|
-
promptParts.push(item.text);
|
|
131
|
-
} else if (item.type === "local_image") {
|
|
132
|
-
images.push(item.path);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return { prompt: promptParts.join("\n\n"), images };
|
|
136
|
-
}
|
|
137
|
-
var INTERNAL_ORIGINATOR_ENV = "CODEX_INTERNAL_ORIGINATOR_OVERRIDE";
|
|
138
|
-
var TYPESCRIPT_SDK_ORIGINATOR = "codex_sdk_ts";
|
|
139
|
-
var CODEX_NPM_NAME = "@openai/codex";
|
|
140
|
-
var PLATFORM_PACKAGE_BY_TARGET = {
|
|
141
|
-
"x86_64-unknown-linux-musl": "@openai/codex-linux-x64",
|
|
142
|
-
"aarch64-unknown-linux-musl": "@openai/codex-linux-arm64",
|
|
143
|
-
"x86_64-apple-darwin": "@openai/codex-darwin-x64",
|
|
144
|
-
"aarch64-apple-darwin": "@openai/codex-darwin-arm64",
|
|
145
|
-
"x86_64-pc-windows-msvc": "@openai/codex-win32-x64",
|
|
146
|
-
"aarch64-pc-windows-msvc": "@openai/codex-win32-arm64"
|
|
147
|
-
};
|
|
148
|
-
var moduleRequire = createRequire(import.meta.url);
|
|
149
|
-
var CodexExec = class {
|
|
150
|
-
executablePath;
|
|
151
|
-
envOverride;
|
|
152
|
-
configOverrides;
|
|
153
|
-
constructor(executablePath = null, env, configOverrides) {
|
|
154
|
-
this.executablePath = executablePath || findCodexPath();
|
|
155
|
-
this.envOverride = env;
|
|
156
|
-
this.configOverrides = configOverrides;
|
|
157
|
-
}
|
|
158
|
-
async *run(args) {
|
|
159
|
-
const commandArgs = ["exec", "--experimental-json"];
|
|
160
|
-
if (this.configOverrides) {
|
|
161
|
-
for (const override of serializeConfigOverrides(this.configOverrides)) {
|
|
162
|
-
commandArgs.push("--config", override);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (args.model) {
|
|
166
|
-
commandArgs.push("--model", args.model);
|
|
167
|
-
}
|
|
168
|
-
if (args.sandboxMode) {
|
|
169
|
-
commandArgs.push("--sandbox", args.sandboxMode);
|
|
170
|
-
}
|
|
171
|
-
if (args.workingDirectory) {
|
|
172
|
-
commandArgs.push("--cd", args.workingDirectory);
|
|
173
|
-
}
|
|
174
|
-
if (args.additionalDirectories?.length) {
|
|
175
|
-
for (const dir of args.additionalDirectories) {
|
|
176
|
-
commandArgs.push("--add-dir", dir);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (args.skipGitRepoCheck) {
|
|
180
|
-
commandArgs.push("--skip-git-repo-check");
|
|
181
|
-
}
|
|
182
|
-
if (args.outputSchemaFile) {
|
|
183
|
-
commandArgs.push("--output-schema", args.outputSchemaFile);
|
|
184
|
-
}
|
|
185
|
-
if (args.modelReasoningEffort) {
|
|
186
|
-
commandArgs.push("--config", `model_reasoning_effort="${args.modelReasoningEffort}"`);
|
|
187
|
-
}
|
|
188
|
-
if (args.networkAccessEnabled !== void 0) {
|
|
189
|
-
commandArgs.push(
|
|
190
|
-
"--config",
|
|
191
|
-
`sandbox_workspace_write.network_access=${args.networkAccessEnabled}`
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
if (args.webSearchMode) {
|
|
195
|
-
commandArgs.push("--config", `web_search="${args.webSearchMode}"`);
|
|
196
|
-
} else if (args.webSearchEnabled === true) {
|
|
197
|
-
commandArgs.push("--config", `web_search="live"`);
|
|
198
|
-
} else if (args.webSearchEnabled === false) {
|
|
199
|
-
commandArgs.push("--config", `web_search="disabled"`);
|
|
200
|
-
}
|
|
201
|
-
if (args.approvalPolicy) {
|
|
202
|
-
commandArgs.push("--config", `approval_policy="${args.approvalPolicy}"`);
|
|
203
|
-
}
|
|
204
|
-
if (args.threadId) {
|
|
205
|
-
commandArgs.push("resume", args.threadId);
|
|
206
|
-
}
|
|
207
|
-
if (args.images?.length) {
|
|
208
|
-
for (const image of args.images) {
|
|
209
|
-
commandArgs.push("--image", image);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
const env = {};
|
|
213
|
-
if (this.envOverride) {
|
|
214
|
-
Object.assign(env, this.envOverride);
|
|
215
|
-
} else {
|
|
216
|
-
for (const [key, value] of Object.entries(process.env)) {
|
|
217
|
-
if (value !== void 0) {
|
|
218
|
-
env[key] = value;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
if (!env[INTERNAL_ORIGINATOR_ENV]) {
|
|
223
|
-
env[INTERNAL_ORIGINATOR_ENV] = TYPESCRIPT_SDK_ORIGINATOR;
|
|
224
|
-
}
|
|
225
|
-
if (args.baseUrl) {
|
|
226
|
-
env.OPENAI_BASE_URL = args.baseUrl;
|
|
227
|
-
}
|
|
228
|
-
if (args.apiKey) {
|
|
229
|
-
env.CODEX_API_KEY = args.apiKey;
|
|
230
|
-
}
|
|
231
|
-
const child = spawn(this.executablePath, commandArgs, {
|
|
232
|
-
env,
|
|
233
|
-
signal: args.signal
|
|
234
|
-
});
|
|
235
|
-
let spawnError = null;
|
|
236
|
-
child.once("error", (err) => spawnError = err);
|
|
237
|
-
if (!child.stdin) {
|
|
238
|
-
child.kill();
|
|
239
|
-
throw new Error("Child process has no stdin");
|
|
240
|
-
}
|
|
241
|
-
child.stdin.write(args.input);
|
|
242
|
-
child.stdin.end();
|
|
243
|
-
if (!child.stdout) {
|
|
244
|
-
child.kill();
|
|
245
|
-
throw new Error("Child process has no stdout");
|
|
246
|
-
}
|
|
247
|
-
const stderrChunks = [];
|
|
248
|
-
if (child.stderr) {
|
|
249
|
-
child.stderr.on("data", (data) => {
|
|
250
|
-
stderrChunks.push(data);
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
const exitPromise = new Promise(
|
|
254
|
-
(resolve) => {
|
|
255
|
-
child.once("exit", (code, signal) => {
|
|
256
|
-
resolve({ code, signal });
|
|
1
|
+
// index.ts
|
|
2
|
+
import {
|
|
3
|
+
definePlugin,
|
|
4
|
+
shouldHandleInvoke,
|
|
5
|
+
agentOutput
|
|
6
|
+
} from "@meetopenbot/plugin-sdk";
|
|
7
|
+
import {
|
|
8
|
+
Codex
|
|
9
|
+
} from "@openai/codex-sdk";
|
|
10
|
+
var codex_default = definePlugin({
|
|
11
|
+
id: "codex",
|
|
12
|
+
name: "Codex",
|
|
13
|
+
description: "Codex integration tools for OpenBot",
|
|
14
|
+
configSchema: {
|
|
15
|
+
type: "object",
|
|
16
|
+
properties: {
|
|
17
|
+
apiKey: { type: "string", description: "Codex API Key", format: "password" },
|
|
18
|
+
baseURL: { type: "string", description: "Custom OpenAI-compatible endpoint" },
|
|
19
|
+
codexPathOverride: { type: "string", description: "Path to codex CLI" },
|
|
20
|
+
model: { type: "string", description: "Model to use", default: "gpt-5-codex" },
|
|
21
|
+
workingDirectory: { type: "string", description: "Working directory for Codex" },
|
|
22
|
+
skipGitRepoCheck: { type: "boolean", description: "Skip git repo check", default: true },
|
|
23
|
+
sandboxMode: {
|
|
24
|
+
type: "string",
|
|
25
|
+
enum: ["workspace-read", "workspace-write", "full-read", "full-write"],
|
|
26
|
+
description: "Sandbox mode",
|
|
27
|
+
default: "workspace-write"
|
|
28
|
+
},
|
|
29
|
+
approvalPolicy: {
|
|
30
|
+
type: "string",
|
|
31
|
+
enum: ["always", "never", "automatic"],
|
|
32
|
+
description: "Approval policy",
|
|
33
|
+
default: "never"
|
|
34
|
+
},
|
|
35
|
+
networkAccessEnabled: { type: "boolean", description: "Enable network access" },
|
|
36
|
+
webSearchMode: {
|
|
37
|
+
type: "string",
|
|
38
|
+
enum: ["always", "never", "automatic"],
|
|
39
|
+
description: "Web search mode"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
factory: (context) => {
|
|
44
|
+
const config = context.config;
|
|
45
|
+
const env = globalThis?.process?.env || {};
|
|
46
|
+
const apiKey = config.apiKey ?? env.CODEX_API_KEY ?? env.OPENAI_API_KEY;
|
|
47
|
+
const codexPathOverride = config.codexPathOverride ?? env.CODEX_PATH ?? env.CODEX_CLI_PATH;
|
|
48
|
+
const model = config.model?.split("/").pop() || "gpt-5-codex";
|
|
49
|
+
let client;
|
|
50
|
+
const getClient = () => {
|
|
51
|
+
if (!client) {
|
|
52
|
+
client = new Codex({
|
|
53
|
+
apiKey,
|
|
54
|
+
...codexPathOverride && { codexPathOverride },
|
|
55
|
+
...config.baseURL && { baseUrl: config.baseURL }
|
|
257
56
|
});
|
|
258
57
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
function serializeConfigOverrides(configOverrides) {
|
|
286
|
-
const overrides = [];
|
|
287
|
-
flattenConfigOverrides(configOverrides, "", overrides);
|
|
288
|
-
return overrides;
|
|
289
|
-
}
|
|
290
|
-
function flattenConfigOverrides(value, prefix, overrides) {
|
|
291
|
-
if (!isPlainObject(value)) {
|
|
292
|
-
if (prefix) {
|
|
293
|
-
overrides.push(`${prefix}=${toTomlValue(value, prefix)}`);
|
|
294
|
-
return;
|
|
295
|
-
} else {
|
|
296
|
-
throw new Error("Codex config overrides must be a plain object");
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
const entries = Object.entries(value);
|
|
300
|
-
if (!prefix && entries.length === 0) {
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
if (prefix && entries.length === 0) {
|
|
304
|
-
overrides.push(`${prefix}={}`);
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
for (const [key, child] of entries) {
|
|
308
|
-
if (!key) {
|
|
309
|
-
throw new Error("Codex config override keys must be non-empty strings");
|
|
310
|
-
}
|
|
311
|
-
if (child === void 0) {
|
|
312
|
-
continue;
|
|
313
|
-
}
|
|
314
|
-
const path3 = prefix ? `${prefix}.${key}` : key;
|
|
315
|
-
if (isPlainObject(child)) {
|
|
316
|
-
flattenConfigOverrides(child, path3, overrides);
|
|
317
|
-
} else {
|
|
318
|
-
overrides.push(`${path3}=${toTomlValue(child, path3)}`);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
function toTomlValue(value, path3) {
|
|
323
|
-
if (typeof value === "string") {
|
|
324
|
-
return JSON.stringify(value);
|
|
325
|
-
} else if (typeof value === "number") {
|
|
326
|
-
if (!Number.isFinite(value)) {
|
|
327
|
-
throw new Error(`Codex config override at ${path3} must be a finite number`);
|
|
328
|
-
}
|
|
329
|
-
return `${value}`;
|
|
330
|
-
} else if (typeof value === "boolean") {
|
|
331
|
-
return value ? "true" : "false";
|
|
332
|
-
} else if (Array.isArray(value)) {
|
|
333
|
-
const rendered = value.map((item, index) => toTomlValue(item, `${path3}[${index}]`));
|
|
334
|
-
return `[${rendered.join(", ")}]`;
|
|
335
|
-
} else if (isPlainObject(value)) {
|
|
336
|
-
const parts = [];
|
|
337
|
-
for (const [key, child] of Object.entries(value)) {
|
|
338
|
-
if (!key) {
|
|
339
|
-
throw new Error("Codex config override keys must be non-empty strings");
|
|
340
|
-
}
|
|
341
|
-
if (child === void 0) {
|
|
342
|
-
continue;
|
|
343
|
-
}
|
|
344
|
-
parts.push(`${formatTomlKey(key)} = ${toTomlValue(child, `${path3}.${key}`)}`);
|
|
345
|
-
}
|
|
346
|
-
return `{${parts.join(", ")}}`;
|
|
347
|
-
} else if (value === null) {
|
|
348
|
-
throw new Error(`Codex config override at ${path3} cannot be null`);
|
|
349
|
-
} else {
|
|
350
|
-
const typeName = typeof value;
|
|
351
|
-
throw new Error(`Unsupported Codex config override value at ${path3}: ${typeName}`);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
var TOML_BARE_KEY = /^[A-Za-z0-9_-]+$/;
|
|
355
|
-
function formatTomlKey(key) {
|
|
356
|
-
return TOML_BARE_KEY.test(key) ? key : JSON.stringify(key);
|
|
357
|
-
}
|
|
358
|
-
function isPlainObject(value) {
|
|
359
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
360
|
-
}
|
|
361
|
-
function findCodexPath() {
|
|
362
|
-
const { platform, arch } = process;
|
|
363
|
-
let targetTriple = null;
|
|
364
|
-
switch (platform) {
|
|
365
|
-
case "linux":
|
|
366
|
-
case "android":
|
|
367
|
-
switch (arch) {
|
|
368
|
-
case "x64":
|
|
369
|
-
targetTriple = "x86_64-unknown-linux-musl";
|
|
370
|
-
break;
|
|
371
|
-
case "arm64":
|
|
372
|
-
targetTriple = "aarch64-unknown-linux-musl";
|
|
373
|
-
break;
|
|
374
|
-
default:
|
|
375
|
-
break;
|
|
376
|
-
}
|
|
377
|
-
break;
|
|
378
|
-
case "darwin":
|
|
379
|
-
switch (arch) {
|
|
380
|
-
case "x64":
|
|
381
|
-
targetTriple = "x86_64-apple-darwin";
|
|
382
|
-
break;
|
|
383
|
-
case "arm64":
|
|
384
|
-
targetTriple = "aarch64-apple-darwin";
|
|
385
|
-
break;
|
|
386
|
-
default:
|
|
387
|
-
break;
|
|
388
|
-
}
|
|
389
|
-
break;
|
|
390
|
-
case "win32":
|
|
391
|
-
switch (arch) {
|
|
392
|
-
case "x64":
|
|
393
|
-
targetTriple = "x86_64-pc-windows-msvc";
|
|
394
|
-
break;
|
|
395
|
-
case "arm64":
|
|
396
|
-
targetTriple = "aarch64-pc-windows-msvc";
|
|
397
|
-
break;
|
|
398
|
-
default:
|
|
399
|
-
break;
|
|
58
|
+
return client;
|
|
59
|
+
};
|
|
60
|
+
let thread = null;
|
|
61
|
+
const getThread = (state, meta) => {
|
|
62
|
+
if (thread) return thread;
|
|
63
|
+
const workingDirectory = config.workingDirectory || state?.channelDetails?.cwd || globalThis?.process?.cwd() || "/tmp";
|
|
64
|
+
const threadOptions = {
|
|
65
|
+
model,
|
|
66
|
+
workingDirectory,
|
|
67
|
+
skipGitRepoCheck: config.skipGitRepoCheck ?? true,
|
|
68
|
+
sandboxMode: config.sandboxMode ?? "workspace-write",
|
|
69
|
+
approvalPolicy: config.approvalPolicy ?? "never",
|
|
70
|
+
...typeof config.networkAccessEnabled === "boolean" && {
|
|
71
|
+
networkAccessEnabled: config.networkAccessEnabled
|
|
72
|
+
},
|
|
73
|
+
...config.webSearchMode && {
|
|
74
|
+
webSearchMode: config.webSearchMode
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const threadId = state?.threadId || meta?.threadId;
|
|
78
|
+
thread = threadId ? getClient().resumeThread(threadId, threadOptions) : getClient().startThread(threadOptions);
|
|
79
|
+
if (!threadId && state) {
|
|
80
|
+
state.threadId = thread.id;
|
|
400
81
|
}
|
|
401
|
-
|
|
402
|
-
default:
|
|
403
|
-
break;
|
|
404
|
-
}
|
|
405
|
-
if (!targetTriple) {
|
|
406
|
-
throw new Error(`Unsupported platform: ${platform} (${arch})`);
|
|
407
|
-
}
|
|
408
|
-
const platformPackage = PLATFORM_PACKAGE_BY_TARGET[targetTriple];
|
|
409
|
-
if (!platformPackage) {
|
|
410
|
-
throw new Error(`Unsupported target triple: ${targetTriple}`);
|
|
411
|
-
}
|
|
412
|
-
let vendorRoot;
|
|
413
|
-
try {
|
|
414
|
-
const codexPackageJsonPath = moduleRequire.resolve(`${CODEX_NPM_NAME}/package.json`);
|
|
415
|
-
const codexRequire = createRequire(codexPackageJsonPath);
|
|
416
|
-
const platformPackageJsonPath = codexRequire.resolve(`${platformPackage}/package.json`);
|
|
417
|
-
vendorRoot = path2.join(path2.dirname(platformPackageJsonPath), "vendor");
|
|
418
|
-
} catch {
|
|
419
|
-
throw new Error(
|
|
420
|
-
`Unable to locate Codex CLI binaries. Ensure ${CODEX_NPM_NAME} is installed with optional dependencies.`
|
|
421
|
-
);
|
|
422
|
-
}
|
|
423
|
-
const archRoot = path2.join(vendorRoot, targetTriple);
|
|
424
|
-
const codexBinaryName = process.platform === "win32" ? "codex.exe" : "codex";
|
|
425
|
-
const binaryPath = path2.join(archRoot, "codex", codexBinaryName);
|
|
426
|
-
return binaryPath;
|
|
427
|
-
}
|
|
428
|
-
var Codex = class {
|
|
429
|
-
exec;
|
|
430
|
-
options;
|
|
431
|
-
constructor(options = {}) {
|
|
432
|
-
const { codexPathOverride, env, config } = options;
|
|
433
|
-
this.exec = new CodexExec(codexPathOverride, env, config);
|
|
434
|
-
this.options = options;
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* Starts a new conversation with an agent.
|
|
438
|
-
* @returns A new thread instance.
|
|
439
|
-
*/
|
|
440
|
-
startThread(options = {}) {
|
|
441
|
-
return new Thread(this.exec, this.options, options);
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* Resumes a conversation with an agent based on the thread id.
|
|
445
|
-
* Threads are persisted in ~/.codex/sessions.
|
|
446
|
-
*
|
|
447
|
-
* @param id The id of the thread to resume.
|
|
448
|
-
* @returns A new thread instance.
|
|
449
|
-
*/
|
|
450
|
-
resumeThread(id, options = {}) {
|
|
451
|
-
return new Thread(this.exec, this.options, options, id);
|
|
452
|
-
}
|
|
453
|
-
};
|
|
454
|
-
|
|
455
|
-
// index.ts
|
|
456
|
-
var codexPlugin = (options = { model: "gpt-5-codex" }) => (builder) => {
|
|
457
|
-
const env = globalThis?.process?.env || {};
|
|
458
|
-
const apiKey = options.apiKey ?? env.CODEX_API_KEY ?? env.OPENAI_API_KEY;
|
|
459
|
-
const codexPathOverride = options.codexPathOverride ?? env.CODEX_PATH ?? env.CODEX_CLI_PATH;
|
|
460
|
-
const model = options.model?.split("/").pop() || "gpt-5-codex";
|
|
461
|
-
let client;
|
|
462
|
-
const getClient = () => {
|
|
463
|
-
if (!client) {
|
|
464
|
-
client = new Codex({
|
|
465
|
-
apiKey,
|
|
466
|
-
...codexPathOverride && { codexPathOverride },
|
|
467
|
-
...options.baseURL && { baseUrl: options.baseURL }
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
return client;
|
|
471
|
-
};
|
|
472
|
-
let thread = null;
|
|
473
|
-
const getThread = (state) => {
|
|
474
|
-
if (thread) return thread;
|
|
475
|
-
const workingDirectory = options.workingDirectory || state?.channelDetails?.cwd || globalThis?.process?.cwd() || "/tmp";
|
|
476
|
-
const threadOptions = {
|
|
477
|
-
model,
|
|
478
|
-
workingDirectory,
|
|
479
|
-
skipGitRepoCheck: options.skipGitRepoCheck ?? false,
|
|
480
|
-
sandboxMode: options.sandboxMode ?? "workspace-write",
|
|
481
|
-
...options.approvalPolicy && { approvalPolicy: options.approvalPolicy },
|
|
482
|
-
...typeof options.networkAccessEnabled === "boolean" && { networkAccessEnabled: options.networkAccessEnabled },
|
|
483
|
-
...options.webSearchMode && { webSearchMode: options.webSearchMode }
|
|
82
|
+
return thread;
|
|
484
83
|
};
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
84
|
+
return (builder) => {
|
|
85
|
+
builder.on("agent:invoke", async function* (event, ctx) {
|
|
86
|
+
if (!shouldHandleInvoke(event, context.agentId)) return;
|
|
87
|
+
const { content } = event.data || {};
|
|
88
|
+
if (!content) {
|
|
89
|
+
yield agentOutput({
|
|
90
|
+
agentId: context.agentId,
|
|
91
|
+
content: "No content provided.",
|
|
92
|
+
threadId: event.meta?.threadId
|
|
93
|
+
});
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const turn = await getThread(ctx?.state, event.meta).runStreamed(content);
|
|
98
|
+
for await (const chunk of turn.events) {
|
|
99
|
+
if (chunk.type === "item.completed") {
|
|
100
|
+
let outputContent = "";
|
|
101
|
+
if (chunk.item.type === "agent_message") {
|
|
102
|
+
outputContent = chunk.item.text;
|
|
103
|
+
} else if (chunk.item.type === "reasoning") {
|
|
104
|
+
outputContent = chunk.item.text;
|
|
105
|
+
} else if (chunk.item.type === "command_execution") {
|
|
106
|
+
outputContent = `Executing: ${chunk.item.command}`;
|
|
107
|
+
} else if (chunk.item.type === "file_change") {
|
|
108
|
+
outputContent = chunk.item.changes.map((change) => `${change.path}: ${change.action}`).join("\n");
|
|
109
|
+
} else if (chunk.item.type === "error") {
|
|
110
|
+
outputContent = `Error: ${chunk.item.message}`;
|
|
111
|
+
} else if (chunk.item.type === "todo_list") {
|
|
112
|
+
outputContent = chunk.item.items.map(
|
|
113
|
+
(item) => `- ${item.text} (${item.completed ? "completed" : "pending"})`
|
|
114
|
+
).join("\n");
|
|
115
|
+
} else if (chunk.item.type === "web_search") {
|
|
116
|
+
outputContent = `Searching: ${chunk.item.query}`;
|
|
117
|
+
}
|
|
118
|
+
if (outputContent) {
|
|
119
|
+
yield agentOutput({
|
|
120
|
+
agentId: context.agentId,
|
|
121
|
+
content: outputContent,
|
|
122
|
+
threadId: event.meta?.threadId
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
522
126
|
}
|
|
127
|
+
} catch (error) {
|
|
128
|
+
yield agentOutput({
|
|
129
|
+
agentId: context.agentId,
|
|
130
|
+
content: `Error: ${error?.message || "Codex request failed."}`,
|
|
131
|
+
threadId: event.meta?.threadId
|
|
132
|
+
});
|
|
523
133
|
}
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
data: { content: `Error: ${error?.message || "Codex request failed."}` }
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
});
|
|
532
|
-
};
|
|
533
|
-
var plugin = {
|
|
534
|
-
id: "codex",
|
|
535
|
-
name: "Codex",
|
|
536
|
-
description: "Codex integration tools for OpenBot",
|
|
537
|
-
kind: "runtime",
|
|
538
|
-
factory: (options) => codexPlugin(options)
|
|
539
|
-
};
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
});
|
|
540
138
|
export {
|
|
541
|
-
|
|
542
|
-
plugin
|
|
139
|
+
codex_default as default
|
|
543
140
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meetopenbot/codex",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Codex tools plugin for OpenBot",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -15,16 +15,16 @@
|
|
|
15
15
|
"assets"
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
|
-
"build": "esbuild index.ts --bundle --platform=node --format=esm --outfile=dist/index.js --external
|
|
18
|
+
"build": "esbuild index.ts --bundle --platform=node --format=esm --outfile=dist/index.js --external:@meetopenbot/plugin-sdk --external:@openai/codex-sdk --external:zod",
|
|
19
19
|
"prepublishOnly": "npm run build"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@
|
|
23
|
-
"
|
|
22
|
+
"@meetopenbot/plugin-sdk": "^0.1.2",
|
|
23
|
+
"@openai/codex-sdk": "^0.138.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/node": "^25.6.0",
|
|
27
27
|
"esbuild": "^0.21.0",
|
|
28
|
-
"zod": "^
|
|
28
|
+
"zod": "^4.4.3"
|
|
29
29
|
}
|
|
30
|
-
}
|
|
30
|
+
}
|