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.
- package/dist/src/{chunk-5NBVP6A2.js → chunk-OLZ7JWCU.js} +741 -199
- package/dist/src/headless-agent.js +48 -49
- package/dist/src/index.js +757 -244
- package/package.json +1 -1
- package/dist/src/app-server-process-EVCFSBVG.js +0 -10
- package/dist/src/chunk-2CFOJHNH.js +0 -162
- package/dist/src/chunk-A2ZICXOK.js +0 -407
- package/dist/src/chunk-CKJJIOSE.js +0 -448
- package/dist/src/chunk-XQW4B35Y.js +0 -108
- package/dist/src/codex-token-manager-VIZLBLS2.js +0 -13
- package/dist/src/engine-env-3AQ2O2WZ.js +0 -14
|
@@ -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-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
-
|
|
186
|
-
|
|
187
|
-
|
|
201
|
+
approvalPolicy: "never",
|
|
202
|
+
approvalsReviewer: "user",
|
|
203
|
+
sandbox: request.mode === "filesystem" ? "workspace-write" : "read-only",
|
|
204
|
+
ephemeral: true
|
|
188
205
|
});
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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);
|