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.
- package/README.md +4 -4
- package/dist/src/app-server-process-GBLLP2RH.js +10 -0
- package/dist/src/{chunk-3EPGH6IZ.js → chunk-6JWWD5NM.js} +200 -699
- package/dist/src/chunk-CBZ5YQAS.js +448 -0
- package/dist/src/chunk-IRM6KMN5.js +407 -0
- package/dist/src/chunk-LO6ISJCF.js +162 -0
- package/dist/src/chunk-XQW4B35Y.js +108 -0
- package/dist/src/codex-token-manager-KL7GDOF4.js +13 -0
- package/dist/src/engine-env-M3LJZ6ZJ.js +14 -0
- package/dist/src/headless-agent.js +49 -34
- package/dist/src/index.js +428 -803
- package/package.json +1 -1
|
@@ -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-
|
|
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
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
ephemeral: true
|
|
185
|
+
env: buildCodexAgentEnv(),
|
|
186
|
+
configOverrides: ["shell_environment_policy.inherit=none", "tools.web_search=false"],
|
|
187
|
+
...oauthOptions
|
|
191
188
|
});
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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);
|