replicas-engine 0.1.740 → 0.1.741
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/asp-host-KDEJGDMP.js +15 -0
- package/dist/src/chunk-25CMFABL.js +73 -0
- package/dist/src/{chunk-7SUFESKA.js → chunk-6O6BPV7Q.js} +1 -1
- package/dist/src/{chunk-ZZRN6VSK.js → chunk-ESGIWRVV.js} +35 -110
- package/dist/src/{chunk-YPAI4W4G.js → chunk-Q6F7J5DH.js} +29 -17
- package/dist/src/{chunk-3Z7CQNGC.js → chunk-TRGZSX4W.js} +4 -66
- package/dist/src/chunk-UUKFVYYJ.js +419 -0
- package/dist/src/chunk-Z6P6S5HL.js +95 -0
- package/dist/src/command-protection-hook.js +3 -2
- package/dist/src/deepseek-command-protection-plugin.js +4 -3
- package/dist/src/headless-agent.js +6 -4
- package/dist/src/index.js +84 -451
- package/dist/src/post-tool-pr-hook.js +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
ENGINE_ENV,
|
|
4
|
+
monolithRequest,
|
|
5
|
+
setAgentCredentialSnapshot
|
|
6
|
+
} from "./chunk-TRGZSX4W.js";
|
|
7
|
+
import {
|
|
8
|
+
AppServerProcess,
|
|
9
|
+
buildCodexAgentEnv
|
|
10
|
+
} from "./chunk-ESGIWRVV.js";
|
|
11
|
+
import {
|
|
12
|
+
CODEX_AUTH_ENV_KEYS,
|
|
13
|
+
CODEX_AUTH_ENV_KEYS_BY_METHOD,
|
|
14
|
+
codexAuthEnvFromResponse,
|
|
15
|
+
createErrorResult,
|
|
16
|
+
createSuccessResult
|
|
17
|
+
} from "./chunk-Q6F7J5DH.js";
|
|
18
|
+
|
|
19
|
+
// src/managers/codex-token-manager.ts
|
|
20
|
+
import { promises as fs } from "fs";
|
|
21
|
+
import path from "path";
|
|
22
|
+
|
|
23
|
+
// src/managers/auth-env-transition.ts
|
|
24
|
+
function applyAuthEnvTransition(params) {
|
|
25
|
+
const newOwned = new Set(params.authKeysByMethod[params.newMethod]);
|
|
26
|
+
const prevOwned = new Set(params.authKeysByMethod[params.prevMethod]);
|
|
27
|
+
for (const key of params.authKeys) {
|
|
28
|
+
const value = params.newEnvVars[key];
|
|
29
|
+
if (value !== void 0) {
|
|
30
|
+
for (const env of params.envs) {
|
|
31
|
+
env[key] = value;
|
|
32
|
+
}
|
|
33
|
+
} else if (prevOwned.has(key) && !newOwned.has(key)) {
|
|
34
|
+
for (const env of params.envs) {
|
|
35
|
+
delete env[key];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/services/credential-fallbacks.ts
|
|
42
|
+
var fallbacksByAgent = /* @__PURE__ */ new Map();
|
|
43
|
+
var exhaustedByAgent = /* @__PURE__ */ new Map();
|
|
44
|
+
function recordCredentialFallback(notice) {
|
|
45
|
+
fallbacksByAgent.set(notice.provider, notice);
|
|
46
|
+
}
|
|
47
|
+
function listCredentialFallbacks() {
|
|
48
|
+
return [...fallbacksByAgent.values()].filter((notice) => {
|
|
49
|
+
const live = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS[notice.provider];
|
|
50
|
+
if (!live) return false;
|
|
51
|
+
return notice.status === "switched" ? live.method === notice.candidateMethod && live.scope === notice.candidateScope : live.method === notice.exhaustedMethod && live.scope === notice.exhaustedScope;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function listExhaustedCredentials(provider) {
|
|
55
|
+
return [...exhaustedByAgent.get(provider)?.values() ?? []];
|
|
56
|
+
}
|
|
57
|
+
function recordExhaustedCredential(provider, credential) {
|
|
58
|
+
const spent = exhaustedByAgent.get(provider) ?? /* @__PURE__ */ new Map();
|
|
59
|
+
spent.set(`${credential.method}|${credential.scope}`, credential);
|
|
60
|
+
exhaustedByAgent.set(provider, spent);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/managers/base-refresh-manager.ts
|
|
64
|
+
var BaseRefreshManager = class {
|
|
65
|
+
constructor(managerName, intervalMs = 15 * 60 * 1e3) {
|
|
66
|
+
this.managerName = managerName;
|
|
67
|
+
this.intervalMs = intervalMs;
|
|
68
|
+
this.health = {
|
|
69
|
+
isRunning: false,
|
|
70
|
+
intervalMs: this.intervalMs,
|
|
71
|
+
lastAttemptAt: null,
|
|
72
|
+
lastSuccessAt: null,
|
|
73
|
+
lastErrorAt: null,
|
|
74
|
+
lastErrorMessage: null
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
managerName;
|
|
78
|
+
intervalMs;
|
|
79
|
+
intervalHandle = null;
|
|
80
|
+
health;
|
|
81
|
+
async start() {
|
|
82
|
+
if (this.intervalHandle) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const skipReason = this.getSkipReason();
|
|
86
|
+
if (skipReason) {
|
|
87
|
+
console.log(`[${this.managerName}] Skipping: ${skipReason}`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
console.log(`[${this.managerName}] Starting token refresh service`);
|
|
91
|
+
this.health.isRunning = true;
|
|
92
|
+
const config = this.getRuntimeConfig();
|
|
93
|
+
if (config) {
|
|
94
|
+
this.health.lastAttemptAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
95
|
+
for (let attempt = 1; attempt <= 3; attempt++) {
|
|
96
|
+
try {
|
|
97
|
+
await this.doRefresh(config);
|
|
98
|
+
this.health.lastSuccessAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
99
|
+
this.health.lastErrorAt = null;
|
|
100
|
+
this.health.lastErrorMessage = null;
|
|
101
|
+
break;
|
|
102
|
+
} catch (error) {
|
|
103
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
104
|
+
this.health.lastErrorAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
105
|
+
this.health.lastErrorMessage = message;
|
|
106
|
+
if (attempt < 3) {
|
|
107
|
+
console.warn(`[${this.managerName}] Initial refresh attempt ${attempt} failed, retrying in 2s...`);
|
|
108
|
+
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
109
|
+
} else {
|
|
110
|
+
console.error(`[${this.managerName}] Initial refresh failed after 3 attempts:`, error);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
this.scheduleNextRefresh();
|
|
116
|
+
}
|
|
117
|
+
async swapCredentials(params) {
|
|
118
|
+
if (!this.getRuntimeConfig()) {
|
|
119
|
+
return createErrorResult({ message: `${this.managerName} has no runtime config`, code: "not_configured" });
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
console.log(`[${this.managerName}] Fetching fresh credentials from monolith (${params.failureKind})...`);
|
|
123
|
+
const excludeCredentials = listExhaustedCredentials(params.provider);
|
|
124
|
+
await params.refresh({
|
|
125
|
+
...excludeCredentials.length > 0 ? { excludeCredentials } : {},
|
|
126
|
+
...params.allowedMethods ? { allowedMethods: [...params.allowedMethods] } : {}
|
|
127
|
+
});
|
|
128
|
+
if (params.isOauthNow()) {
|
|
129
|
+
this.start().catch((error) => {
|
|
130
|
+
console.error(`[${this.managerName}] Failed to restart OAuth refresh service after fallback:`, error);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return createSuccessResult();
|
|
134
|
+
} catch (error) {
|
|
135
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
136
|
+
console.error(`[${this.managerName}] Failed to fetch fresh credentials:`, error);
|
|
137
|
+
return createErrorResult({
|
|
138
|
+
message,
|
|
139
|
+
code: message.includes('"code":"no_credentials"') ? "no_credentials" : "refresh_failed"
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
stop() {
|
|
144
|
+
if (!this.intervalHandle) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
clearTimeout(this.intervalHandle);
|
|
148
|
+
this.intervalHandle = null;
|
|
149
|
+
this.health.isRunning = false;
|
|
150
|
+
console.log(`[${this.managerName}] Stopped`);
|
|
151
|
+
}
|
|
152
|
+
getHealthStatus() {
|
|
153
|
+
return { ...this.health };
|
|
154
|
+
}
|
|
155
|
+
getSkipReason() {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
getNextRefreshDelayMs() {
|
|
159
|
+
return this.intervalMs;
|
|
160
|
+
}
|
|
161
|
+
getRuntimeConfig() {
|
|
162
|
+
if (!ENGINE_ENV.REPLICAS_WORKSPACE_ID) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
monolithUrl: ENGINE_ENV.REPLICAS_MONOLITH_URL,
|
|
167
|
+
workspaceId: ENGINE_ENV.REPLICAS_WORKSPACE_ID,
|
|
168
|
+
engineSecret: ENGINE_ENV.REPLICAS_ENGINE_SECRET
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
scheduleNextRefresh() {
|
|
172
|
+
const delayMs = this.getNextRefreshDelayMs();
|
|
173
|
+
this.health.intervalMs = delayMs;
|
|
174
|
+
this.intervalHandle = setTimeout(async () => {
|
|
175
|
+
await this.refreshOnce();
|
|
176
|
+
if (this.intervalHandle) this.scheduleNextRefresh();
|
|
177
|
+
}, delayMs);
|
|
178
|
+
console.log(`[${this.managerName}] Token refresh scheduled in ${Math.round(delayMs / 1e3)} seconds`);
|
|
179
|
+
}
|
|
180
|
+
async refreshOnce(force = false) {
|
|
181
|
+
if (!force && this.getSkipReason()) {
|
|
182
|
+
return createSuccessResult();
|
|
183
|
+
}
|
|
184
|
+
const config = this.getRuntimeConfig();
|
|
185
|
+
if (!config) return createSuccessResult();
|
|
186
|
+
this.health.lastAttemptAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
187
|
+
try {
|
|
188
|
+
await this.doRefresh(config);
|
|
189
|
+
this.health.lastSuccessAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
190
|
+
this.health.lastErrorAt = null;
|
|
191
|
+
this.health.lastErrorMessage = null;
|
|
192
|
+
return createSuccessResult();
|
|
193
|
+
} catch (error) {
|
|
194
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
195
|
+
this.health.lastErrorAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
196
|
+
this.health.lastErrorMessage = message;
|
|
197
|
+
console.error(`[${this.managerName}] Failed to refresh credentials:`, error);
|
|
198
|
+
return createErrorResult({ message });
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// src/managers/codex-token-manager.ts
|
|
204
|
+
var CodexAspAuthMethodChangedError = class extends Error {
|
|
205
|
+
name = "CodexAspAuthMethodChangedError";
|
|
206
|
+
};
|
|
207
|
+
var CodexTokenManager = class extends BaseRefreshManager {
|
|
208
|
+
constructor() {
|
|
209
|
+
super("CodexTokenManager");
|
|
210
|
+
}
|
|
211
|
+
getSkipReason() {
|
|
212
|
+
if (!ENGINE_ENV.REPLICAS_CODEX_AUTH_METHOD && ENGINE_ENV.OPENAI_API_KEY) {
|
|
213
|
+
return "OPENAI_API_KEY is set";
|
|
214
|
+
}
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
async doRefresh(_config) {
|
|
218
|
+
await this.refreshWithRequest(void 0, true);
|
|
219
|
+
}
|
|
220
|
+
async refreshWithRequest(request, restartOnChange = false) {
|
|
221
|
+
const previousEnv = CODEX_AUTH_ENV_KEYS.map((key) => process.env[key]);
|
|
222
|
+
console.log("[CodexTokenManager] Refreshing Codex credentials...");
|
|
223
|
+
const response = await monolithRequest("/v1/engine/codex/refresh-credentials", {
|
|
224
|
+
body: request
|
|
225
|
+
});
|
|
226
|
+
if (!response.ok) {
|
|
227
|
+
const errorText = await response.text();
|
|
228
|
+
throw new Error(`Credentials refresh failed: ${response.status} ${errorText}`);
|
|
229
|
+
}
|
|
230
|
+
const data = await response.json();
|
|
231
|
+
await this.applyCredentialsResponse(data);
|
|
232
|
+
if (restartOnChange && CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index])) {
|
|
233
|
+
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-KDEJGDMP.js");
|
|
234
|
+
await restartCodexAspHostIfRunning2();
|
|
235
|
+
}
|
|
236
|
+
if (data.scope) {
|
|
237
|
+
setAgentCredentialSnapshot("codex", {
|
|
238
|
+
method: data.type,
|
|
239
|
+
scope: data.scope,
|
|
240
|
+
...data.revision ? { revision: data.revision } : {}
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
console.log(`[CodexTokenManager] Credentials refreshed (method=${data.type})`);
|
|
244
|
+
return data;
|
|
245
|
+
}
|
|
246
|
+
async prepareAspOauthOptions() {
|
|
247
|
+
if (ENGINE_ENV.REPLICAS_CODEX_AUTH_METHOD !== "oauth") return {};
|
|
248
|
+
const response = await this.refreshWithRequest();
|
|
249
|
+
if (response.type !== "oauth") return {};
|
|
250
|
+
const login = this.buildAspOauthLogin(response);
|
|
251
|
+
let credential = login.credential;
|
|
252
|
+
return {
|
|
253
|
+
chatgptAuthTokens: login.tokens,
|
|
254
|
+
refreshChatgptAuthTokens: async (params) => {
|
|
255
|
+
const refreshed = await this.refreshAspOauthCredentials(
|
|
256
|
+
credential,
|
|
257
|
+
`Codex ASP requested an external token refresh (${params.reason})`
|
|
258
|
+
);
|
|
259
|
+
if (!refreshed.ok) {
|
|
260
|
+
if (refreshed.error.code === "method_changed") {
|
|
261
|
+
throw new CodexAspAuthMethodChangedError(refreshed.error.message);
|
|
262
|
+
}
|
|
263
|
+
throw new Error(refreshed.error.message);
|
|
264
|
+
}
|
|
265
|
+
credential = refreshed.data.credential;
|
|
266
|
+
return refreshed.data.tokens;
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
async refreshAspOauthCredentials(failedCredential, failureReason) {
|
|
271
|
+
try {
|
|
272
|
+
const response = await this.refreshWithRequest({
|
|
273
|
+
failedMethod: "oauth",
|
|
274
|
+
...failedCredential?.method === "oauth" ? { failedCredential } : {},
|
|
275
|
+
failureKind: "rejected",
|
|
276
|
+
failureReason
|
|
277
|
+
});
|
|
278
|
+
if (response.type !== "oauth") {
|
|
279
|
+
return createErrorResult({
|
|
280
|
+
message: `${failureReason}; credentials changed to ${response.type}, so the app server must restart`,
|
|
281
|
+
code: "method_changed"
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
return createSuccessResult(this.buildAspOauthLogin(response));
|
|
285
|
+
} catch (error) {
|
|
286
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
287
|
+
return createErrorResult({
|
|
288
|
+
message,
|
|
289
|
+
code: message.includes('"code":"no_credentials"') ? "no_credentials" : "refresh_failed"
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
async fetchFreshCredentials(failureReason, failureKind = "rejected", failedCredential = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.codex, allowedMethods) {
|
|
294
|
+
const failedMethod = failedCredential?.method === "oauth" || failedCredential?.method === "api_key" || failedCredential?.method === "foundry" ? failedCredential.method : ENGINE_ENV.REPLICAS_CODEX_AUTH_METHOD;
|
|
295
|
+
return this.swapCredentials({
|
|
296
|
+
provider: "codex",
|
|
297
|
+
failureKind,
|
|
298
|
+
allowedMethods,
|
|
299
|
+
refresh: async (exclusions) => {
|
|
300
|
+
await this.refreshWithRequest(
|
|
301
|
+
failedMethod === "oauth" || failedMethod === "api_key" || failedMethod === "foundry" ? {
|
|
302
|
+
failedMethod,
|
|
303
|
+
...failedCredential?.method === failedMethod ? { failedCredential } : {},
|
|
304
|
+
failureReason,
|
|
305
|
+
failureKind,
|
|
306
|
+
...exclusions
|
|
307
|
+
} : exclusions
|
|
308
|
+
);
|
|
309
|
+
},
|
|
310
|
+
isOauthNow: () => ENGINE_ENV.REPLICAS_CODEX_AUTH_METHOD === "oauth"
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
async applyCredentialsResponse(response) {
|
|
314
|
+
await this.removeOauthCredentialsFile();
|
|
315
|
+
const envVars = codexAuthEnvFromResponse(response);
|
|
316
|
+
applyAuthEnvTransition({
|
|
317
|
+
prevMethod: ENGINE_ENV.REPLICAS_CODEX_AUTH_METHOD ?? "none",
|
|
318
|
+
newMethod: envVars.REPLICAS_CODEX_AUTH_METHOD ?? "none",
|
|
319
|
+
authKeys: CODEX_AUTH_ENV_KEYS,
|
|
320
|
+
authKeysByMethod: CODEX_AUTH_ENV_KEYS_BY_METHOD,
|
|
321
|
+
newEnvVars: envVars,
|
|
322
|
+
envs: [ENGINE_ENV, process.env]
|
|
323
|
+
});
|
|
324
|
+
if (response.type === "api_key") {
|
|
325
|
+
for (const key of CODEX_AUTH_ENV_KEYS_BY_METHOD.api_key) {
|
|
326
|
+
if (envVars[key] !== void 0) continue;
|
|
327
|
+
delete ENGINE_ENV[key];
|
|
328
|
+
delete process.env[key];
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
buildAspOauthLogin(response) {
|
|
333
|
+
const credential = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.codex;
|
|
334
|
+
return {
|
|
335
|
+
tokens: {
|
|
336
|
+
accessToken: response.accessToken,
|
|
337
|
+
chatgptAccountId: response.accountId,
|
|
338
|
+
chatgptPlanType: null
|
|
339
|
+
},
|
|
340
|
+
...credential?.method === "oauth" ? { credential } : {}
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
async removeOauthCredentialsFile() {
|
|
344
|
+
const authPath = path.join(ENGINE_ENV.HOME_DIR, ".codex", "auth.json");
|
|
345
|
+
try {
|
|
346
|
+
await fs.unlink(authPath);
|
|
347
|
+
} catch (error) {
|
|
348
|
+
if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) throw error;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
var codexTokenManager = new CodexTokenManager();
|
|
353
|
+
|
|
354
|
+
// src/managers/codex-asp/asp-host.ts
|
|
355
|
+
var hostPromise = null;
|
|
356
|
+
var activeProcess = null;
|
|
357
|
+
var restartPromise = null;
|
|
358
|
+
async function getCodexAspHost() {
|
|
359
|
+
if (restartPromise) {
|
|
360
|
+
await restartPromise;
|
|
361
|
+
}
|
|
362
|
+
hostPromise ??= (async () => {
|
|
363
|
+
try {
|
|
364
|
+
const oauthOptions = await codexTokenManager.prepareAspOauthOptions();
|
|
365
|
+
const process2 = new AppServerProcess({
|
|
366
|
+
cwd: ENGINE_ENV.WORKSPACE_ROOT,
|
|
367
|
+
env: buildCodexAgentEnv(),
|
|
368
|
+
...oauthOptions
|
|
369
|
+
});
|
|
370
|
+
const { client } = await process2.start();
|
|
371
|
+
activeProcess = process2;
|
|
372
|
+
process2.on("exit", () => {
|
|
373
|
+
if (activeProcess === process2) {
|
|
374
|
+
activeProcess = null;
|
|
375
|
+
}
|
|
376
|
+
hostPromise = null;
|
|
377
|
+
});
|
|
378
|
+
return { client };
|
|
379
|
+
} catch (error) {
|
|
380
|
+
hostPromise = null;
|
|
381
|
+
throw error;
|
|
382
|
+
}
|
|
383
|
+
})();
|
|
384
|
+
return hostPromise;
|
|
385
|
+
}
|
|
386
|
+
async function restartCodexAspHost() {
|
|
387
|
+
if (restartPromise) {
|
|
388
|
+
return restartPromise;
|
|
389
|
+
}
|
|
390
|
+
restartPromise = (async () => {
|
|
391
|
+
const process2 = activeProcess;
|
|
392
|
+
hostPromise = null;
|
|
393
|
+
activeProcess = null;
|
|
394
|
+
if (process2) {
|
|
395
|
+
await process2.stop();
|
|
396
|
+
}
|
|
397
|
+
})();
|
|
398
|
+
try {
|
|
399
|
+
await restartPromise;
|
|
400
|
+
} finally {
|
|
401
|
+
restartPromise = null;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
async function restartCodexAspHostIfRunning() {
|
|
405
|
+
if (activeProcess) await restartCodexAspHost();
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export {
|
|
409
|
+
recordCredentialFallback,
|
|
410
|
+
listCredentialFallbacks,
|
|
411
|
+
recordExhaustedCredential,
|
|
412
|
+
BaseRefreshManager,
|
|
413
|
+
applyAuthEnvTransition,
|
|
414
|
+
getCodexAspHost,
|
|
415
|
+
restartCodexAspHost,
|
|
416
|
+
restartCodexAspHostIfRunning,
|
|
417
|
+
CodexAspAuthMethodChangedError,
|
|
418
|
+
codexTokenManager
|
|
419
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/utils/presigned-upload.ts
|
|
4
|
+
import { createReadStream } from "fs";
|
|
5
|
+
import { request as httpRequest } from "http";
|
|
6
|
+
import { request as httpsRequest } from "https";
|
|
7
|
+
async function putPresignedFile(urlValue, filePath, size, contentType) {
|
|
8
|
+
await new Promise((resolve, reject) => {
|
|
9
|
+
const url = new URL(urlValue);
|
|
10
|
+
const request = (url.protocol === "https:" ? httpsRequest : httpRequest)(url, {
|
|
11
|
+
method: "PUT",
|
|
12
|
+
headers: {
|
|
13
|
+
"content-length": String(size),
|
|
14
|
+
"content-type": contentType
|
|
15
|
+
}
|
|
16
|
+
}, (response) => {
|
|
17
|
+
response.setEncoding("utf8");
|
|
18
|
+
let body = "";
|
|
19
|
+
response.on("data", (chunk) => {
|
|
20
|
+
body += chunk;
|
|
21
|
+
});
|
|
22
|
+
response.on("end", () => {
|
|
23
|
+
const status = response.statusCode ?? 0;
|
|
24
|
+
if (status >= 200 && status < 300) resolve();
|
|
25
|
+
else reject(new Error(`upload failed: ${status} ${body}`));
|
|
26
|
+
});
|
|
27
|
+
response.on("error", reject);
|
|
28
|
+
});
|
|
29
|
+
request.on("error", reject);
|
|
30
|
+
const file = size > 0 ? createReadStream(filePath, { start: 0, end: size - 1 }) : createReadStream(filePath);
|
|
31
|
+
file.on("error", (error) => request.destroy(error));
|
|
32
|
+
file.pipe(request);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/managers/codex-asp/notification-dispatch.ts
|
|
37
|
+
var TURN_STARTED_METHOD = "turn/started";
|
|
38
|
+
var TURN_COMPLETED_METHOD = "turn/completed";
|
|
39
|
+
var TURN_PLAN_UPDATED_METHOD = "turn/plan/updated";
|
|
40
|
+
var THREAD_GOAL_UPDATED_METHOD = "thread/goal/updated";
|
|
41
|
+
var THREAD_GOAL_CLEARED_METHOD = "thread/goal/cleared";
|
|
42
|
+
var ITEM_STARTED_METHOD = "item/started";
|
|
43
|
+
var ITEM_COMPLETED_METHOD = "item/completed";
|
|
44
|
+
var AGENT_MESSAGE_DELTA_METHOD = "item/agentMessage/delta";
|
|
45
|
+
var REASONING_SUMMARY_TEXT_DELTA_METHOD = "item/reasoning/summaryTextDelta";
|
|
46
|
+
var REASONING_TEXT_DELTA_METHOD = "item/reasoning/textDelta";
|
|
47
|
+
var REASONING_SUMMARY_PART_ADDED_METHOD = "item/reasoning/summaryPartAdded";
|
|
48
|
+
var COMMAND_EXECUTION_OUTPUT_DELTA_METHOD = "item/commandExecution/outputDelta";
|
|
49
|
+
var FILE_CHANGE_OUTPUT_DELTA_METHOD = "item/fileChange/outputDelta";
|
|
50
|
+
var ACCOUNT_RATE_LIMITS_UPDATED_METHOD = "account/rateLimits/updated";
|
|
51
|
+
var THREAD_TOKEN_USAGE_UPDATED_METHOD = "thread/tokenUsage/updated";
|
|
52
|
+
var THREAD_COMPACTED_METHOD = "thread/compacted";
|
|
53
|
+
var MODEL_REROUTED_METHOD = "model/rerouted";
|
|
54
|
+
function dispatchAspNotification(notification, handlers) {
|
|
55
|
+
const handler = handlers[notification.method];
|
|
56
|
+
if (!handler) return;
|
|
57
|
+
handler(notification);
|
|
58
|
+
}
|
|
59
|
+
function recoverCompletedTurn(turn, completedItems, agentMessageDeltas) {
|
|
60
|
+
const items = turn.items.length > 0 ? [...turn.items] : [];
|
|
61
|
+
const itemIds = new Set(items.map((item) => item.id));
|
|
62
|
+
for (const item of completedItems) {
|
|
63
|
+
if (itemIds.has(item.id)) continue;
|
|
64
|
+
items.push(item);
|
|
65
|
+
itemIds.add(item.id);
|
|
66
|
+
}
|
|
67
|
+
for (const [itemId, text] of agentMessageDeltas) {
|
|
68
|
+
if (itemIds.has(itemId)) continue;
|
|
69
|
+
items.push({ type: "agentMessage", id: itemId, text, phase: null, memoryCitation: null });
|
|
70
|
+
}
|
|
71
|
+
return items.length > 0 ? { ...turn, items, itemsView: "full" } : turn;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export {
|
|
75
|
+
putPresignedFile,
|
|
76
|
+
TURN_STARTED_METHOD,
|
|
77
|
+
TURN_COMPLETED_METHOD,
|
|
78
|
+
TURN_PLAN_UPDATED_METHOD,
|
|
79
|
+
THREAD_GOAL_UPDATED_METHOD,
|
|
80
|
+
THREAD_GOAL_CLEARED_METHOD,
|
|
81
|
+
ITEM_STARTED_METHOD,
|
|
82
|
+
ITEM_COMPLETED_METHOD,
|
|
83
|
+
AGENT_MESSAGE_DELTA_METHOD,
|
|
84
|
+
REASONING_SUMMARY_TEXT_DELTA_METHOD,
|
|
85
|
+
REASONING_TEXT_DELTA_METHOD,
|
|
86
|
+
REASONING_SUMMARY_PART_ADDED_METHOD,
|
|
87
|
+
COMMAND_EXECUTION_OUTPUT_DELTA_METHOD,
|
|
88
|
+
FILE_CHANGE_OUTPUT_DELTA_METHOD,
|
|
89
|
+
ACCOUNT_RATE_LIMITS_UPDATED_METHOD,
|
|
90
|
+
THREAD_TOKEN_USAGE_UPDATED_METHOD,
|
|
91
|
+
THREAD_COMPACTED_METHOD,
|
|
92
|
+
MODEL_REROUTED_METHOD,
|
|
93
|
+
dispatchAspNotification,
|
|
94
|
+
recoverCompletedTurn
|
|
95
|
+
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
evaluateCommandProtection
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-25CMFABL.js";
|
|
5
|
+
import "./chunk-TRGZSX4W.js";
|
|
5
6
|
import {
|
|
6
7
|
isRecord
|
|
7
8
|
} from "./chunk-2RB7SIP3.js";
|
|
8
|
-
import "./chunk-
|
|
9
|
+
import "./chunk-Q6F7J5DH.js";
|
|
9
10
|
|
|
10
11
|
// src/command-protection-hook.ts
|
|
11
12
|
var provider = process.argv[2];
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
evaluateCommandProtection
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-25CMFABL.js";
|
|
5
5
|
import {
|
|
6
6
|
notifyPostToolUse
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-6O6BPV7Q.js";
|
|
8
|
+
import "./chunk-TRGZSX4W.js";
|
|
8
9
|
import "./chunk-2RB7SIP3.js";
|
|
9
|
-
import "./chunk-
|
|
10
|
+
import "./chunk-Q6F7J5DH.js";
|
|
10
11
|
|
|
11
12
|
// src/deepseek-command-protection-plugin.ts
|
|
12
13
|
function replicasCommandProtection(context) {
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
AppServerProcess,
|
|
4
|
-
buildCodexAgentEnv,
|
|
5
3
|
putPresignedFile,
|
|
6
4
|
recoverCompletedTurn
|
|
7
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-Z6P6S5HL.js";
|
|
6
|
+
import {
|
|
7
|
+
AppServerProcess,
|
|
8
|
+
buildCodexAgentEnv
|
|
9
|
+
} from "./chunk-ESGIWRVV.js";
|
|
8
10
|
import {
|
|
9
11
|
AGENT,
|
|
10
12
|
getMemoryOutputSafetyViolation,
|
|
11
13
|
headlessAgentRequestSchema
|
|
12
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-Q6F7J5DH.js";
|
|
13
15
|
|
|
14
16
|
// src/headless-agent.ts
|
|
15
17
|
import { createHash } from "crypto";
|