replicas-engine 0.1.666 → 0.1.669

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.
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ ENGINE_ENV,
4
+ IS_WARMING_MODE,
5
+ loadEngineEnv,
6
+ setAgentCredentialSnapshot
7
+ } from "./chunk-LO6ISJCF.js";
8
+ import "./chunk-6JWWD5NM.js";
9
+ export {
10
+ ENGINE_ENV,
11
+ IS_WARMING_MODE,
12
+ loadEngineEnv,
13
+ setAgentCredentialSnapshot
14
+ };
@@ -1,13 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- AGENT,
4
- AppServerProcess,
5
3
  buildCodexAgentEnv,
6
- getMemoryOutputSafetyViolation,
7
- headlessAgentRequestSchema,
8
4
  putPresignedFile,
9
5
  recoverCompletedTurn
10
- } from "./chunk-3EPGH6IZ.js";
6
+ } from "./chunk-XQW4B35Y.js";
7
+ import {
8
+ AGENT,
9
+ getMemoryOutputSafetyViolation,
10
+ headlessAgentRequestSchema
11
+ } from "./chunk-6JWWD5NM.js";
11
12
 
12
13
  // src/headless-agent.ts
13
14
  import { createHash } from "crypto";
@@ -171,38 +172,52 @@ function runCodexTurn(client, params, timeoutMs) {
171
172
  });
172
173
  }
173
174
  async function runCodex(request) {
174
- const appServer = new AppServerProcess({
175
- cwd: request.workingDirectory,
176
- env: buildCodexAgentEnv(),
177
- configOverrides: ["shell_environment_policy.inherit=none", "tools.web_search=false"]
178
- });
179
- try {
180
- const { client } = await appServer.start();
181
- client.on("serverRequest", (serverRequest) => {
182
- client.reject(serverRequest.id, -32601, "Headless agents do not accept server requests");
183
- });
184
- const thread = await client.request("thread/start", {
185
- model: request.model,
175
+ const [{ AppServerProcess }, { codexTokenManager }, { ENGINE_ENV }] = await Promise.all([
176
+ import("./app-server-process-GBLLP2RH.js"),
177
+ import("./codex-token-manager-KL7GDOF4.js"),
178
+ import("./engine-env-M3LJZ6ZJ.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({
186
184
  cwd: request.workingDirectory,
187
- approvalPolicy: "never",
188
- approvalsReviewer: "user",
189
- sandbox: request.mode === "filesystem" ? "workspace-write" : "read-only",
190
- ephemeral: true
185
+ env: buildCodexAgentEnv(),
186
+ configOverrides: ["shell_environment_policy.inherit=none", "tools.web_search=false"],
187
+ ...oauthOptions
191
188
  });
192
- const { turn, message } = await runCodexTurn(client, {
193
- threadId: thread.thread.id,
194
- input: [{ type: "text", text: request.prompt, text_elements: [] }],
195
- ...request.mode === "structured" ? { outputSchema: request.outputSchema } : {},
196
- approvalPolicy: "never",
197
- approvalsReviewer: "user"
198
- }, request.timeoutSeconds * 1e3);
199
- if (turn.status === "failed") throw new Error(turn.error?.message ?? "Codex ASP turn failed");
200
- if (!message) throw new Error("Codex ASP returned no final message");
201
- if (request.mode === "filesystem") return message;
202
- return JSON.parse(message);
203
- } finally {
204
- await appServer.stop();
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
+ }
205
219
  }
220
+ throw new Error("Codex ASP could not restart with fallback credentials");
206
221
  }
207
222
  async function main() {
208
223
  const [requestPath, outputPath] = process.argv.slice(2);