replicas-engine 0.1.673 → 0.1.676

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.
@@ -1,14 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
+ AGENT,
4
+ AppServerProcess,
3
5
  buildCodexAgentEnv,
6
+ getMemoryOutputSafetyViolation,
7
+ headlessAgentRequestSchema,
4
8
  putPresignedFile,
5
9
  recoverCompletedTurn
6
- } from "./chunk-XQW4B35Y.js";
7
- import {
8
- AGENT,
9
- getMemoryOutputSafetyViolation,
10
- headlessAgentRequestSchema
11
- } from "./chunk-5NBVP6A2.js";
10
+ } from "./chunk-OLZ7JWCU.js";
12
11
 
13
12
  // src/headless-agent.ts
14
13
  import { createHash } from "crypto";
@@ -172,52 +171,52 @@ function runCodexTurn(client, params, timeoutMs) {
172
171
  });
173
172
  }
174
173
  async function runCodex(request) {
175
- const [{ AppServerProcess }, { codexTokenManager }, { ENGINE_ENV }] = await Promise.all([
176
- import("./app-server-process-EVCFSBVG.js"),
177
- import("./codex-token-manager-VIZLBLS2.js"),
178
- import("./engine-env-3AQ2O2WZ.js")
179
- ]);
180
- for (let attempt = 0; attempt < 2; attempt++) {
181
- const authMethod = ENGINE_ENV.REPLICAS_CODEX_AUTH_METHOD;
182
- const oauthOptions = await codexTokenManager.prepareAspOauthOptions();
183
- const appServer = new AppServerProcess({
174
+ if (process.env.REPLICAS_CODEX_AUTH_METHOD === "oauth" && !request.codexOauthTokens) {
175
+ throw new Error("Codex OAuth credentials were not provided");
176
+ }
177
+ const appServer = new AppServerProcess({
178
+ cwd: request.workingDirectory,
179
+ env: buildCodexAgentEnv(),
180
+ configOverrides: ["shell_environment_policy.inherit=none", "tools.web_search=false"],
181
+ ...request.codexOauthTokens ? {
182
+ chatgptAuthTokens: {
183
+ accessToken: request.codexOauthTokens.accessToken,
184
+ chatgptAccountId: request.codexOauthTokens.accountId,
185
+ chatgptPlanType: null
186
+ },
187
+ refreshChatgptAuthTokens: async () => {
188
+ throw new Error("Failed to refresh token in standalone memory job");
189
+ }
190
+ } : {}
191
+ });
192
+ try {
193
+ const { client } = await appServer.start();
194
+ client.on("serverRequest", (serverRequest) => {
195
+ if (serverRequest.method === "account/chatgptAuthTokens/refresh") return;
196
+ client.reject(serverRequest.id, -32601, "Headless agents do not accept server requests");
197
+ });
198
+ const thread = await client.request("thread/start", {
199
+ model: request.model,
184
200
  cwd: request.workingDirectory,
185
- env: buildCodexAgentEnv(),
186
- configOverrides: ["shell_environment_policy.inherit=none", "tools.web_search=false"],
187
- ...oauthOptions
201
+ approvalPolicy: "never",
202
+ approvalsReviewer: "user",
203
+ sandbox: request.mode === "filesystem" ? "workspace-write" : "read-only",
204
+ ephemeral: true
188
205
  });
189
- try {
190
- const { client } = await appServer.start();
191
- client.on("serverRequest", (serverRequest) => {
192
- if (serverRequest.method === "account/chatgptAuthTokens/refresh") return;
193
- client.reject(serverRequest.id, -32601, "Headless agents do not accept server requests");
194
- });
195
- const thread = await client.request("thread/start", {
196
- model: request.model,
197
- cwd: request.workingDirectory,
198
- approvalPolicy: "never",
199
- approvalsReviewer: "user",
200
- sandbox: request.mode === "filesystem" ? "workspace-write" : "read-only",
201
- ephemeral: true
202
- });
203
- const { turn, message } = await runCodexTurn(client, {
204
- threadId: thread.thread.id,
205
- input: [{ type: "text", text: request.prompt, text_elements: [] }],
206
- ...request.mode === "structured" ? { outputSchema: request.outputSchema } : {},
207
- approvalPolicy: "never",
208
- approvalsReviewer: "user"
209
- }, request.timeoutSeconds * 1e3);
210
- if (turn.status === "failed") throw new Error(turn.error?.message ?? "Codex ASP turn failed");
211
- if (!message) throw new Error("Codex ASP returned no final message");
212
- if (request.mode === "filesystem") return message;
213
- return JSON.parse(message);
214
- } catch (error) {
215
- if (attempt > 0 || ENGINE_ENV.REPLICAS_CODEX_AUTH_METHOD === authMethod) throw error;
216
- } finally {
217
- await appServer.stop();
218
- }
206
+ const { turn, message } = await runCodexTurn(client, {
207
+ threadId: thread.thread.id,
208
+ input: [{ type: "text", text: request.prompt, text_elements: [] }],
209
+ ...request.mode === "structured" ? { outputSchema: request.outputSchema } : {},
210
+ approvalPolicy: "never",
211
+ approvalsReviewer: "user"
212
+ }, request.timeoutSeconds * 1e3);
213
+ if (turn.status === "failed") throw new Error(turn.error?.message ?? "Codex ASP turn failed");
214
+ if (!message) throw new Error("Codex ASP returned no final message");
215
+ if (request.mode === "filesystem") return message;
216
+ return JSON.parse(message);
217
+ } finally {
218
+ await appServer.stop();
219
219
  }
220
- throw new Error("Codex ASP could not restart with fallback credentials");
221
220
  }
222
221
  async function main() {
223
222
  const [requestPath, outputPath] = process.argv.slice(2);