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,20 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
// ../shared/src/result.ts
|
|
4
|
-
function createSuccessResult(data) {
|
|
5
|
-
return { ok: true, data };
|
|
6
|
-
}
|
|
7
|
-
function createErrorResult(error) {
|
|
8
|
-
return {
|
|
9
|
-
ok: false,
|
|
10
|
-
error: {
|
|
11
|
-
message: error.message,
|
|
12
|
-
code: error.code,
|
|
13
|
-
details: error.details
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
3
|
// ../shared/src/agent.ts
|
|
19
4
|
var AGENT = {
|
|
20
5
|
CLAUDE: "claude",
|
|
@@ -67,113 +52,19 @@ function codexReasoningEffortForThinkingLevel(thinkingLevel) {
|
|
|
67
52
|
return thinkingLevel ? CODEX_REASONING_EFFORT_BY_THINKING_LEVEL[thinkingLevel] : void 0;
|
|
68
53
|
}
|
|
69
54
|
|
|
70
|
-
// ../shared/src/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// ../shared/src/credentials/types.ts
|
|
74
|
-
var CREDENTIAL_SCOPE = {
|
|
75
|
-
USER: "user",
|
|
76
|
-
ORG: "org"
|
|
77
|
-
};
|
|
78
|
-
var CREDENTIAL_SCOPES = Object.values(CREDENTIAL_SCOPE);
|
|
79
|
-
var CREDENTIAL_SCOPE_PRIORITY = [CREDENTIAL_SCOPE.USER, CREDENTIAL_SCOPE.ORG];
|
|
80
|
-
|
|
81
|
-
// ../shared/src/type-guards.ts
|
|
82
|
-
function isRecord(value) {
|
|
83
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// ../shared/src/credentials/agents.ts
|
|
87
|
-
var CREDENTIAL_METHOD = {
|
|
88
|
-
OAUTH: "oauth",
|
|
89
|
-
API_KEY: "api_key",
|
|
90
|
-
FOUNDRY: "foundry",
|
|
91
|
-
BEDROCK: "bedrock",
|
|
92
|
-
OPENCODE_GO: "opencode-go",
|
|
93
|
-
ASTER: "aster",
|
|
94
|
-
OPENROUTER: "openrouter",
|
|
95
|
-
AI_GATEWAY: "ai-gateway"
|
|
96
|
-
};
|
|
97
|
-
var CREDENTIAL_TYPE = {
|
|
98
|
-
CLAUDE_OAUTH: "claude",
|
|
99
|
-
ANTHROPIC_API_KEY: "claude_anthropic_api_key",
|
|
100
|
-
CLAUDE_FOUNDRY: "claude_foundry",
|
|
101
|
-
CLAUDE_BEDROCK: "claude_bedrock",
|
|
102
|
-
CODEX_OAUTH: "codex",
|
|
103
|
-
OPENAI_API_KEY: "openai_api_key",
|
|
104
|
-
CODEX_FOUNDRY: "codex_foundry",
|
|
105
|
-
CURSOR_API_KEY: "cursor_api_key",
|
|
106
|
-
OPENCODE_GO_API_KEY: "opencode_go_api_key",
|
|
107
|
-
ASTER_API_KEY: "aster_api_key",
|
|
108
|
-
OPENROUTER_API_KEY: "openrouter_api_key",
|
|
109
|
-
AI_GATEWAY_API_KEY: "ai_gateway_api_key"
|
|
110
|
-
};
|
|
111
|
-
var AGENT_CREDENTIAL_METHODS_IN_ORDER = {
|
|
112
|
-
[AGENT.CLAUDE]: [
|
|
113
|
-
{ method: CREDENTIAL_METHOD.OAUTH, credentialType: CREDENTIAL_TYPE.CLAUDE_OAUTH },
|
|
114
|
-
{ method: CREDENTIAL_METHOD.API_KEY, credentialType: CREDENTIAL_TYPE.ANTHROPIC_API_KEY },
|
|
115
|
-
{ method: CREDENTIAL_METHOD.FOUNDRY, credentialType: CREDENTIAL_TYPE.CLAUDE_FOUNDRY },
|
|
116
|
-
{ method: CREDENTIAL_METHOD.BEDROCK, credentialType: CREDENTIAL_TYPE.CLAUDE_BEDROCK }
|
|
117
|
-
],
|
|
118
|
-
[AGENT.CODEX]: [
|
|
119
|
-
{ method: CREDENTIAL_METHOD.OAUTH, credentialType: CREDENTIAL_TYPE.CODEX_OAUTH },
|
|
120
|
-
{ method: CREDENTIAL_METHOD.API_KEY, credentialType: CREDENTIAL_TYPE.OPENAI_API_KEY },
|
|
121
|
-
{ method: CREDENTIAL_METHOD.FOUNDRY, credentialType: CREDENTIAL_TYPE.CODEX_FOUNDRY }
|
|
122
|
-
],
|
|
123
|
-
[AGENT.CURSOR]: [
|
|
124
|
-
{ method: CREDENTIAL_METHOD.API_KEY, credentialType: CREDENTIAL_TYPE.CURSOR_API_KEY }
|
|
125
|
-
],
|
|
126
|
-
[AGENT.DEEPSEEK]: [
|
|
127
|
-
{ method: CREDENTIAL_METHOD.OPENROUTER, credentialType: CREDENTIAL_TYPE.OPENROUTER_API_KEY }
|
|
128
|
-
],
|
|
129
|
-
[AGENT.FX]: [
|
|
130
|
-
{ method: CREDENTIAL_METHOD.AI_GATEWAY, credentialType: CREDENTIAL_TYPE.AI_GATEWAY_API_KEY }
|
|
131
|
-
],
|
|
132
|
-
[AGENT.KIMI]: [
|
|
133
|
-
{ method: CREDENTIAL_METHOD.AI_GATEWAY, credentialType: CREDENTIAL_TYPE.AI_GATEWAY_API_KEY }
|
|
134
|
-
],
|
|
135
|
-
[AGENT.OPENCODE]: [
|
|
136
|
-
{ method: CREDENTIAL_METHOD.OPENCODE_GO, credentialType: CREDENTIAL_TYPE.OPENCODE_GO_API_KEY },
|
|
137
|
-
{ method: CREDENTIAL_METHOD.ASTER, credentialType: CREDENTIAL_TYPE.ASTER_API_KEY },
|
|
138
|
-
{ method: CREDENTIAL_METHOD.OPENROUTER, credentialType: CREDENTIAL_TYPE.OPENROUTER_API_KEY }
|
|
139
|
-
],
|
|
140
|
-
[AGENT.PI]: [
|
|
141
|
-
{ method: CREDENTIAL_METHOD.ASTER, credentialType: CREDENTIAL_TYPE.ASTER_API_KEY },
|
|
142
|
-
{ method: CREDENTIAL_METHOD.OPENROUTER, credentialType: CREDENTIAL_TYPE.OPENROUTER_API_KEY }
|
|
143
|
-
]
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
// ../shared/src/analytics/types.ts
|
|
147
|
-
function isAgentChatActivityRecord(value) {
|
|
148
|
-
return isRecord(value) && typeof value.chatId === "string" && typeof value.provider === "string" && isValidAgentProvider(value.provider) && typeof value.model === "string" && (value.credentialMethod === void 0 || isAuthMethod(value.credentialMethod)) && (value.credentialScope === void 0 || isCredentialScope(value.credentialScope)) && value.credentialMethod === void 0 === (value.credentialScope === void 0) && (value.senderUserId === void 0 || typeof value.senderUserId === "string") && typeof value.occurredAt === "string";
|
|
149
|
-
}
|
|
150
|
-
var agentCredentialSnapshotSchema = z.object({
|
|
151
|
-
method: z.enum(CREDENTIAL_METHOD),
|
|
152
|
-
scope: z.enum(CREDENTIAL_SCOPE),
|
|
153
|
-
revision: z.string().optional()
|
|
154
|
-
});
|
|
155
|
-
function isAuthMethod(value) {
|
|
156
|
-
return typeof value === "string" && Object.values(CREDENTIAL_METHOD).some((method) => method === value);
|
|
157
|
-
}
|
|
158
|
-
function isCredentialScope(value) {
|
|
159
|
-
return typeof value === "string" && CREDENTIAL_SCOPES.some((scope) => scope === value);
|
|
160
|
-
}
|
|
161
|
-
function isAgentChatTurnActivityRecord(value) {
|
|
162
|
-
return isAgentChatActivityRecord(value) && typeof value.turnId === "string" && typeof value.seconds === "number" && Number.isFinite(value.seconds) && value.seconds >= 0;
|
|
163
|
-
}
|
|
164
|
-
function isAgentChatActivityCallRecord(value) {
|
|
165
|
-
return isAgentChatActivityRecord(value) && typeof value.callId === "string" && value.callId.length > 0;
|
|
166
|
-
}
|
|
167
|
-
function isNamedAgentChatActivityRecord(value, field) {
|
|
168
|
-
if (!isAgentChatActivityCallRecord(value)) return false;
|
|
169
|
-
const name = value[field];
|
|
170
|
-
return typeof name === "string" && name.length > 0;
|
|
171
|
-
}
|
|
172
|
-
function isAgentChatSkillActivityRecord(value) {
|
|
173
|
-
return isNamedAgentChatActivityRecord(value, "skillName");
|
|
55
|
+
// ../shared/src/result.ts
|
|
56
|
+
function createSuccessResult(data) {
|
|
57
|
+
return { ok: true, data };
|
|
174
58
|
}
|
|
175
|
-
function
|
|
176
|
-
return
|
|
59
|
+
function createErrorResult(error) {
|
|
60
|
+
return {
|
|
61
|
+
ok: false,
|
|
62
|
+
error: {
|
|
63
|
+
message: error.message,
|
|
64
|
+
code: error.code,
|
|
65
|
+
details: error.details
|
|
66
|
+
}
|
|
67
|
+
};
|
|
177
68
|
}
|
|
178
69
|
|
|
179
70
|
// ../shared/src/sandbox.ts
|
|
@@ -340,63 +231,48 @@ function gitIdentityConfigCommands(identity, scope = "global") {
|
|
|
340
231
|
}
|
|
341
232
|
|
|
342
233
|
// ../shared/src/headless-agent.ts
|
|
343
|
-
import { z
|
|
344
|
-
var headlessAgentRequestBaseSchema =
|
|
345
|
-
agent:
|
|
234
|
+
import { z } from "zod";
|
|
235
|
+
var headlessAgentRequestBaseSchema = z.object({
|
|
236
|
+
agent: z.custom(
|
|
346
237
|
(value) => typeof value === "string" && isValidCodingAgentProvider(value)
|
|
347
238
|
),
|
|
348
|
-
model:
|
|
349
|
-
prompt:
|
|
350
|
-
workingDirectory:
|
|
351
|
-
timeoutSeconds:
|
|
239
|
+
model: z.string().min(1),
|
|
240
|
+
prompt: z.string(),
|
|
241
|
+
workingDirectory: z.string().min(1),
|
|
242
|
+
timeoutSeconds: z.number().int().min(1).max(1800).default(300),
|
|
243
|
+
codexOauthTokens: z.object({ accessToken: z.string(), accountId: z.string() }).optional()
|
|
352
244
|
});
|
|
353
|
-
var headlessAgentInputFileSchema =
|
|
354
|
-
path:
|
|
355
|
-
downloadUrl:
|
|
245
|
+
var headlessAgentInputFileSchema = z.object({
|
|
246
|
+
path: z.string().min(1),
|
|
247
|
+
downloadUrl: z.url()
|
|
356
248
|
});
|
|
357
|
-
var headlessAgentOutputFileSchema =
|
|
358
|
-
path:
|
|
359
|
-
uploadUrl:
|
|
360
|
-
contentType:
|
|
361
|
-
minChars:
|
|
362
|
-
maxChars:
|
|
249
|
+
var headlessAgentOutputFileSchema = z.object({
|
|
250
|
+
path: z.string().min(1),
|
|
251
|
+
uploadUrl: z.url(),
|
|
252
|
+
contentType: z.string().min(1),
|
|
253
|
+
minChars: z.number().int().positive().optional(),
|
|
254
|
+
maxChars: z.number().int().positive().optional()
|
|
363
255
|
});
|
|
364
|
-
var headlessAgentRequestSchema =
|
|
256
|
+
var headlessAgentRequestSchema = z.discriminatedUnion("mode", [
|
|
365
257
|
headlessAgentRequestBaseSchema.extend({
|
|
366
|
-
mode:
|
|
367
|
-
outputSchema:
|
|
258
|
+
mode: z.literal("structured"),
|
|
259
|
+
outputSchema: z.record(z.string(), z.json())
|
|
368
260
|
}),
|
|
369
261
|
headlessAgentRequestBaseSchema.extend({
|
|
370
|
-
mode:
|
|
371
|
-
inputFiles:
|
|
372
|
-
outputFiles:
|
|
373
|
-
sensitiveValues:
|
|
262
|
+
mode: z.literal("filesystem"),
|
|
263
|
+
inputFiles: z.array(headlessAgentInputFileSchema),
|
|
264
|
+
outputFiles: z.array(headlessAgentOutputFileSchema),
|
|
265
|
+
sensitiveValues: z.array(z.string())
|
|
374
266
|
})
|
|
375
267
|
]);
|
|
376
|
-
var headlessFilesystemAgentResultSchema =
|
|
377
|
-
message:
|
|
378
|
-
files:
|
|
379
|
-
sha256:
|
|
380
|
-
sizeBytes:
|
|
268
|
+
var headlessFilesystemAgentResultSchema = z.object({
|
|
269
|
+
message: z.string(),
|
|
270
|
+
files: z.record(z.string(), z.object({
|
|
271
|
+
sha256: z.string().regex(/^[a-f0-9]{64}$/),
|
|
272
|
+
sizeBytes: z.number().int().nonnegative()
|
|
381
273
|
}))
|
|
382
274
|
});
|
|
383
275
|
|
|
384
|
-
// ../shared/src/version.ts
|
|
385
|
-
function compareVersions(v1, v2) {
|
|
386
|
-
const parts1 = v1.split(".").map(Number);
|
|
387
|
-
const parts2 = v2.split(".").map(Number);
|
|
388
|
-
for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
|
|
389
|
-
const num1 = parts1[i] || 0;
|
|
390
|
-
const num2 = parts2[i] || 0;
|
|
391
|
-
if (num1 > num2) return 1;
|
|
392
|
-
if (num1 < num2) return -1;
|
|
393
|
-
}
|
|
394
|
-
return 0;
|
|
395
|
-
}
|
|
396
|
-
function isVersionBelow(version, minimum) {
|
|
397
|
-
return compareVersions(version, minimum) < 0;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
276
|
// ../shared/src/engine/environment.ts
|
|
401
277
|
var DESKTOP_STREAM_PORT = 6080;
|
|
402
278
|
|
|
@@ -417,6 +293,11 @@ var ASTER_MODEL_LABELS = {
|
|
|
417
293
|
"gpt-oss-120b": "GPT-OSS 120B"
|
|
418
294
|
};
|
|
419
295
|
|
|
296
|
+
// ../shared/src/type-guards.ts
|
|
297
|
+
function isRecord(value) {
|
|
298
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
299
|
+
}
|
|
300
|
+
|
|
420
301
|
// ../shared/src/engine/types.ts
|
|
421
302
|
var DEFAULT_CHAT_TITLES = {
|
|
422
303
|
claude: "Claude Code",
|
|
@@ -712,6 +593,110 @@ function paginateEngineLogContent(input) {
|
|
|
712
593
|
};
|
|
713
594
|
}
|
|
714
595
|
|
|
596
|
+
// ../shared/src/analytics/types.ts
|
|
597
|
+
import { z as z2 } from "zod";
|
|
598
|
+
|
|
599
|
+
// ../shared/src/credentials/types.ts
|
|
600
|
+
var CREDENTIAL_SCOPE = {
|
|
601
|
+
USER: "user",
|
|
602
|
+
ORG: "org"
|
|
603
|
+
};
|
|
604
|
+
var CREDENTIAL_SCOPES = Object.values(CREDENTIAL_SCOPE);
|
|
605
|
+
var CREDENTIAL_SCOPE_PRIORITY = [CREDENTIAL_SCOPE.USER, CREDENTIAL_SCOPE.ORG];
|
|
606
|
+
|
|
607
|
+
// ../shared/src/credentials/agents.ts
|
|
608
|
+
var CREDENTIAL_METHOD = {
|
|
609
|
+
OAUTH: "oauth",
|
|
610
|
+
API_KEY: "api_key",
|
|
611
|
+
FOUNDRY: "foundry",
|
|
612
|
+
BEDROCK: "bedrock",
|
|
613
|
+
OPENCODE_GO: "opencode-go",
|
|
614
|
+
ASTER: "aster",
|
|
615
|
+
OPENROUTER: "openrouter",
|
|
616
|
+
AI_GATEWAY: "ai-gateway"
|
|
617
|
+
};
|
|
618
|
+
var CREDENTIAL_TYPE = {
|
|
619
|
+
CLAUDE_OAUTH: "claude",
|
|
620
|
+
ANTHROPIC_API_KEY: "claude_anthropic_api_key",
|
|
621
|
+
CLAUDE_FOUNDRY: "claude_foundry",
|
|
622
|
+
CLAUDE_BEDROCK: "claude_bedrock",
|
|
623
|
+
CODEX_OAUTH: "codex",
|
|
624
|
+
OPENAI_API_KEY: "openai_api_key",
|
|
625
|
+
CODEX_FOUNDRY: "codex_foundry",
|
|
626
|
+
CURSOR_API_KEY: "cursor_api_key",
|
|
627
|
+
OPENCODE_GO_API_KEY: "opencode_go_api_key",
|
|
628
|
+
ASTER_API_KEY: "aster_api_key",
|
|
629
|
+
OPENROUTER_API_KEY: "openrouter_api_key",
|
|
630
|
+
AI_GATEWAY_API_KEY: "ai_gateway_api_key"
|
|
631
|
+
};
|
|
632
|
+
var AGENT_CREDENTIAL_METHODS_IN_ORDER = {
|
|
633
|
+
[AGENT.CLAUDE]: [
|
|
634
|
+
{ method: CREDENTIAL_METHOD.OAUTH, credentialType: CREDENTIAL_TYPE.CLAUDE_OAUTH },
|
|
635
|
+
{ method: CREDENTIAL_METHOD.API_KEY, credentialType: CREDENTIAL_TYPE.ANTHROPIC_API_KEY },
|
|
636
|
+
{ method: CREDENTIAL_METHOD.FOUNDRY, credentialType: CREDENTIAL_TYPE.CLAUDE_FOUNDRY },
|
|
637
|
+
{ method: CREDENTIAL_METHOD.BEDROCK, credentialType: CREDENTIAL_TYPE.CLAUDE_BEDROCK }
|
|
638
|
+
],
|
|
639
|
+
[AGENT.CODEX]: [
|
|
640
|
+
{ method: CREDENTIAL_METHOD.OAUTH, credentialType: CREDENTIAL_TYPE.CODEX_OAUTH },
|
|
641
|
+
{ method: CREDENTIAL_METHOD.API_KEY, credentialType: CREDENTIAL_TYPE.OPENAI_API_KEY },
|
|
642
|
+
{ method: CREDENTIAL_METHOD.FOUNDRY, credentialType: CREDENTIAL_TYPE.CODEX_FOUNDRY }
|
|
643
|
+
],
|
|
644
|
+
[AGENT.CURSOR]: [
|
|
645
|
+
{ method: CREDENTIAL_METHOD.API_KEY, credentialType: CREDENTIAL_TYPE.CURSOR_API_KEY }
|
|
646
|
+
],
|
|
647
|
+
[AGENT.DEEPSEEK]: [
|
|
648
|
+
{ method: CREDENTIAL_METHOD.OPENROUTER, credentialType: CREDENTIAL_TYPE.OPENROUTER_API_KEY }
|
|
649
|
+
],
|
|
650
|
+
[AGENT.FX]: [
|
|
651
|
+
{ method: CREDENTIAL_METHOD.AI_GATEWAY, credentialType: CREDENTIAL_TYPE.AI_GATEWAY_API_KEY }
|
|
652
|
+
],
|
|
653
|
+
[AGENT.KIMI]: [
|
|
654
|
+
{ method: CREDENTIAL_METHOD.AI_GATEWAY, credentialType: CREDENTIAL_TYPE.AI_GATEWAY_API_KEY }
|
|
655
|
+
],
|
|
656
|
+
[AGENT.OPENCODE]: [
|
|
657
|
+
{ method: CREDENTIAL_METHOD.OPENCODE_GO, credentialType: CREDENTIAL_TYPE.OPENCODE_GO_API_KEY },
|
|
658
|
+
{ method: CREDENTIAL_METHOD.ASTER, credentialType: CREDENTIAL_TYPE.ASTER_API_KEY },
|
|
659
|
+
{ method: CREDENTIAL_METHOD.OPENROUTER, credentialType: CREDENTIAL_TYPE.OPENROUTER_API_KEY }
|
|
660
|
+
],
|
|
661
|
+
[AGENT.PI]: [
|
|
662
|
+
{ method: CREDENTIAL_METHOD.ASTER, credentialType: CREDENTIAL_TYPE.ASTER_API_KEY },
|
|
663
|
+
{ method: CREDENTIAL_METHOD.OPENROUTER, credentialType: CREDENTIAL_TYPE.OPENROUTER_API_KEY }
|
|
664
|
+
]
|
|
665
|
+
};
|
|
666
|
+
|
|
667
|
+
// ../shared/src/analytics/types.ts
|
|
668
|
+
function isAgentChatActivityRecord(value) {
|
|
669
|
+
return isRecord(value) && typeof value.chatId === "string" && typeof value.provider === "string" && isValidAgentProvider(value.provider) && typeof value.model === "string" && (value.credentialMethod === void 0 || isAuthMethod(value.credentialMethod)) && (value.credentialScope === void 0 || isCredentialScope(value.credentialScope)) && value.credentialMethod === void 0 === (value.credentialScope === void 0) && (value.senderUserId === void 0 || typeof value.senderUserId === "string") && typeof value.occurredAt === "string";
|
|
670
|
+
}
|
|
671
|
+
var agentCredentialSnapshotSchema = z2.object({
|
|
672
|
+
method: z2.enum(CREDENTIAL_METHOD),
|
|
673
|
+
scope: z2.enum(CREDENTIAL_SCOPE),
|
|
674
|
+
revision: z2.string().optional()
|
|
675
|
+
});
|
|
676
|
+
function isAuthMethod(value) {
|
|
677
|
+
return typeof value === "string" && Object.values(CREDENTIAL_METHOD).some((method) => method === value);
|
|
678
|
+
}
|
|
679
|
+
function isCredentialScope(value) {
|
|
680
|
+
return typeof value === "string" && CREDENTIAL_SCOPES.some((scope) => scope === value);
|
|
681
|
+
}
|
|
682
|
+
function isAgentChatTurnActivityRecord(value) {
|
|
683
|
+
return isAgentChatActivityRecord(value) && typeof value.turnId === "string" && typeof value.seconds === "number" && Number.isFinite(value.seconds) && value.seconds >= 0;
|
|
684
|
+
}
|
|
685
|
+
function isAgentChatActivityCallRecord(value) {
|
|
686
|
+
return isAgentChatActivityRecord(value) && typeof value.callId === "string" && value.callId.length > 0;
|
|
687
|
+
}
|
|
688
|
+
function isNamedAgentChatActivityRecord(value, field) {
|
|
689
|
+
if (!isAgentChatActivityCallRecord(value)) return false;
|
|
690
|
+
const name = value[field];
|
|
691
|
+
return typeof name === "string" && name.length > 0;
|
|
692
|
+
}
|
|
693
|
+
function isAgentChatSkillActivityRecord(value) {
|
|
694
|
+
return isNamedAgentChatActivityRecord(value, "skillName");
|
|
695
|
+
}
|
|
696
|
+
function isAgentChatMcpActivityRecord(value) {
|
|
697
|
+
return isNamedAgentChatActivityRecord(value, "mcpName");
|
|
698
|
+
}
|
|
699
|
+
|
|
715
700
|
// ../shared/src/event.ts
|
|
716
701
|
var CLAUDE_PARTIAL_MESSAGE_EVENT_TYPE = "claude-partial-message";
|
|
717
702
|
function coerceClaudePartialMessagePayload(payload) {
|
|
@@ -1006,37 +991,6 @@ function paginateChatHistory(full, params) {
|
|
|
1006
991
|
};
|
|
1007
992
|
}
|
|
1008
993
|
|
|
1009
|
-
// ../shared/src/routes/codex.ts
|
|
1010
|
-
var CODEX_AUTH_ENV_KEYS = [
|
|
1011
|
-
"OPENAI_API_KEY",
|
|
1012
|
-
"AZURE_OPENAI_API_KEY",
|
|
1013
|
-
"CODEX_FOUNDRY_BASE_URL",
|
|
1014
|
-
"CODEX_FOUNDRY_MODEL",
|
|
1015
|
-
"REPLICAS_CODEX_AUTH_METHOD"
|
|
1016
|
-
];
|
|
1017
|
-
function codexAuthEnvFromResponse(response) {
|
|
1018
|
-
switch (response.type) {
|
|
1019
|
-
case "oauth":
|
|
1020
|
-
return { REPLICAS_CODEX_AUTH_METHOD: "oauth" };
|
|
1021
|
-
case "api_key":
|
|
1022
|
-
return { OPENAI_API_KEY: response.apiKey, REPLICAS_CODEX_AUTH_METHOD: "api_key" };
|
|
1023
|
-
case "foundry":
|
|
1024
|
-
return {
|
|
1025
|
-
AZURE_OPENAI_API_KEY: response.apiKey,
|
|
1026
|
-
CODEX_FOUNDRY_BASE_URL: response.baseUrl,
|
|
1027
|
-
CODEX_FOUNDRY_MODEL: response.model,
|
|
1028
|
-
REPLICAS_CODEX_AUTH_METHOD: "foundry"
|
|
1029
|
-
};
|
|
1030
|
-
}
|
|
1031
|
-
}
|
|
1032
|
-
var CODEX_AUTH_ENV_KEYS_BY_METHOD = {
|
|
1033
|
-
none: [],
|
|
1034
|
-
oauth: ["REPLICAS_CODEX_AUTH_METHOD"],
|
|
1035
|
-
api_key: ["OPENAI_API_KEY", "REPLICAS_CODEX_AUTH_METHOD"],
|
|
1036
|
-
bedrock: [],
|
|
1037
|
-
foundry: ["AZURE_OPENAI_API_KEY", "CODEX_FOUNDRY_BASE_URL", "CODEX_FOUNDRY_MODEL", "REPLICAS_CODEX_AUTH_METHOD"]
|
|
1038
|
-
};
|
|
1039
|
-
|
|
1040
994
|
// ../shared/src/memory-safety.ts
|
|
1041
995
|
var SECRET_PATTERNS = [
|
|
1042
996
|
/sk-[A-Za-z0-9_-]{10,}/g,
|
|
@@ -1501,6 +1455,7 @@ var WEB_APP_PATHS = {
|
|
|
1501
1455
|
"audit-logs": `${DASHBOARD_PATH}/audit-logs`,
|
|
1502
1456
|
accountAgents: `${DASHBOARD_PATH}/account/agents`,
|
|
1503
1457
|
accountProfile: `${DASHBOARD_PATH}/account/profile`,
|
|
1458
|
+
accountConnections: `${DASHBOARD_PATH}/account/connections`,
|
|
1504
1459
|
accountIntegrations: `${DASHBOARD_PATH}/account/integrations`,
|
|
1505
1460
|
accountApiKeys: `${DASHBOARD_PATH}/account/api-keys`,
|
|
1506
1461
|
accountPreferences: `${DASHBOARD_PATH}/account/preferences`,
|
|
@@ -2587,7 +2542,7 @@ const plugins = await replicas.plugins.list();
|
|
|
2587
2542
|
const installed = plugins.filter((plugin) => plugin.connected);
|
|
2588
2543
|
\`\`\`
|
|
2589
2544
|
|
|
2590
|
-
If a plugin is not connected, ask the user to
|
|
2545
|
+
If a plugin is not connected, ask the user to connect it under personal Connections or the relevant environment's Plugins tab. A connection on Global reaches every workspace unless a more specific environment overrides it.
|
|
2591
2546
|
|
|
2592
2547
|
## Search, inspect, execute
|
|
2593
2548
|
|
|
@@ -3354,11 +3309,58 @@ function isCodexAuthError(error) {
|
|
|
3354
3309
|
return lower.includes("unauthorized") || lower.includes("authentication") || lower.includes("invalid api key") || lower.includes("incorrect api key") || lower.includes("api key") && lower.includes("invalid") || lower.includes("401") || lower.includes('codexerrorinfo="unauthorized"') || lower.includes("codexerrorinfo=unauthorized") || lower.includes("failed to refresh token") || lower.includes("your session has ended");
|
|
3355
3310
|
}
|
|
3356
3311
|
|
|
3312
|
+
// ../shared/src/version.ts
|
|
3313
|
+
function compareVersions(v1, v2) {
|
|
3314
|
+
const parts1 = v1.split(".").map(Number);
|
|
3315
|
+
const parts2 = v2.split(".").map(Number);
|
|
3316
|
+
for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
|
|
3317
|
+
const num1 = parts1[i] || 0;
|
|
3318
|
+
const num2 = parts2[i] || 0;
|
|
3319
|
+
if (num1 > num2) return 1;
|
|
3320
|
+
if (num1 < num2) return -1;
|
|
3321
|
+
}
|
|
3322
|
+
return 0;
|
|
3323
|
+
}
|
|
3324
|
+
function isVersionBelow(version, minimum) {
|
|
3325
|
+
return compareVersions(version, minimum) < 0;
|
|
3326
|
+
}
|
|
3327
|
+
|
|
3357
3328
|
// ../shared/src/engine/chat-tabs.ts
|
|
3358
3329
|
function hasChatStarted(chat) {
|
|
3359
3330
|
return chat.processing || Boolean(chat.awaitingInput) || Boolean(chat.goal) || Boolean(chat.lastMessageText) || chat.updatedAt > chat.createdAt;
|
|
3360
3331
|
}
|
|
3361
3332
|
|
|
3333
|
+
// ../shared/src/routes/codex.ts
|
|
3334
|
+
var CODEX_AUTH_ENV_KEYS = [
|
|
3335
|
+
"OPENAI_API_KEY",
|
|
3336
|
+
"AZURE_OPENAI_API_KEY",
|
|
3337
|
+
"CODEX_FOUNDRY_BASE_URL",
|
|
3338
|
+
"CODEX_FOUNDRY_MODEL",
|
|
3339
|
+
"REPLICAS_CODEX_AUTH_METHOD"
|
|
3340
|
+
];
|
|
3341
|
+
function codexAuthEnvFromResponse(response) {
|
|
3342
|
+
switch (response.type) {
|
|
3343
|
+
case "oauth":
|
|
3344
|
+
return { REPLICAS_CODEX_AUTH_METHOD: "oauth" };
|
|
3345
|
+
case "api_key":
|
|
3346
|
+
return { OPENAI_API_KEY: response.apiKey, REPLICAS_CODEX_AUTH_METHOD: "api_key" };
|
|
3347
|
+
case "foundry":
|
|
3348
|
+
return {
|
|
3349
|
+
AZURE_OPENAI_API_KEY: response.apiKey,
|
|
3350
|
+
CODEX_FOUNDRY_BASE_URL: response.baseUrl,
|
|
3351
|
+
CODEX_FOUNDRY_MODEL: response.model,
|
|
3352
|
+
REPLICAS_CODEX_AUTH_METHOD: "foundry"
|
|
3353
|
+
};
|
|
3354
|
+
}
|
|
3355
|
+
}
|
|
3356
|
+
var CODEX_AUTH_ENV_KEYS_BY_METHOD = {
|
|
3357
|
+
none: [],
|
|
3358
|
+
oauth: ["REPLICAS_CODEX_AUTH_METHOD"],
|
|
3359
|
+
api_key: ["OPENAI_API_KEY", "REPLICAS_CODEX_AUTH_METHOD"],
|
|
3360
|
+
bedrock: [],
|
|
3361
|
+
foundry: ["AZURE_OPENAI_API_KEY", "CODEX_FOUNDRY_BASE_URL", "CODEX_FOUNDRY_MODEL", "REPLICAS_CODEX_AUTH_METHOD"]
|
|
3362
|
+
};
|
|
3363
|
+
|
|
3362
3364
|
// ../shared/src/routes/claude.ts
|
|
3363
3365
|
var CLAUDE_AUTH_ENV_KEYS = [
|
|
3364
3366
|
"ANTHROPIC_API_KEY",
|
|
@@ -6132,6 +6134,523 @@ function isSkillRegistryManifest(value) {
|
|
|
6132
6134
|
);
|
|
6133
6135
|
}
|
|
6134
6136
|
|
|
6137
|
+
// src/utils/presigned-upload.ts
|
|
6138
|
+
import { createReadStream } from "fs";
|
|
6139
|
+
import { request as httpRequest } from "http";
|
|
6140
|
+
import { request as httpsRequest } from "https";
|
|
6141
|
+
async function putPresignedFile(urlValue, filePath, size, contentType) {
|
|
6142
|
+
await new Promise((resolve, reject) => {
|
|
6143
|
+
const url = new URL(urlValue);
|
|
6144
|
+
const request = (url.protocol === "https:" ? httpsRequest : httpRequest)(url, {
|
|
6145
|
+
method: "PUT",
|
|
6146
|
+
headers: {
|
|
6147
|
+
"content-length": String(size),
|
|
6148
|
+
"content-type": contentType
|
|
6149
|
+
}
|
|
6150
|
+
}, (response) => {
|
|
6151
|
+
response.setEncoding("utf8");
|
|
6152
|
+
let body = "";
|
|
6153
|
+
response.on("data", (chunk) => {
|
|
6154
|
+
body += chunk;
|
|
6155
|
+
});
|
|
6156
|
+
response.on("end", () => {
|
|
6157
|
+
const status = response.statusCode ?? 0;
|
|
6158
|
+
if (status >= 200 && status < 300) resolve();
|
|
6159
|
+
else reject(new Error(`upload failed: ${status} ${body}`));
|
|
6160
|
+
});
|
|
6161
|
+
response.on("error", reject);
|
|
6162
|
+
});
|
|
6163
|
+
request.on("error", reject);
|
|
6164
|
+
const file = size > 0 ? createReadStream(filePath, { start: 0, end: size - 1 }) : createReadStream(filePath);
|
|
6165
|
+
file.on("error", (error) => request.destroy(error));
|
|
6166
|
+
file.pipe(request);
|
|
6167
|
+
});
|
|
6168
|
+
}
|
|
6169
|
+
|
|
6170
|
+
// src/utils/codex-agent-env.ts
|
|
6171
|
+
function buildCodexAgentEnv(source = process.env) {
|
|
6172
|
+
const env = Object.fromEntries(
|
|
6173
|
+
Object.entries(source).filter((entry) => typeof entry[1] === "string")
|
|
6174
|
+
);
|
|
6175
|
+
if (env.REPLICAS_CODEX_AUTH_METHOD === "oauth" || env.REPLICAS_CODEX_AUTH_METHOD === "foundry") {
|
|
6176
|
+
delete env.OPENAI_API_KEY;
|
|
6177
|
+
}
|
|
6178
|
+
delete env.GH_TOKEN;
|
|
6179
|
+
delete env.GITHUB_TOKEN;
|
|
6180
|
+
delete env.GH_CONFIG_DIR;
|
|
6181
|
+
return env;
|
|
6182
|
+
}
|
|
6183
|
+
|
|
6184
|
+
// src/utils/exec.ts
|
|
6185
|
+
import { exec, execFile } from "child_process";
|
|
6186
|
+
import { promisify } from "util";
|
|
6187
|
+
var execAsync = promisify(exec);
|
|
6188
|
+
var execFileAsync = promisify(execFile);
|
|
6189
|
+
var SUBPROCESS_MAX_BUFFER = HOOK_EXEC_MAX_BUFFER_BYTES;
|
|
6190
|
+
|
|
6191
|
+
// src/managers/codex-asp/app-server-process.ts
|
|
6192
|
+
import { spawn } from "child_process";
|
|
6193
|
+
import { EventEmitter as EventEmitter2 } from "events";
|
|
6194
|
+
|
|
6195
|
+
// src/managers/codex-asp/asp-client.ts
|
|
6196
|
+
import { EventEmitter } from "events";
|
|
6197
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 12e4;
|
|
6198
|
+
function hasOwn(record, key) {
|
|
6199
|
+
return Object.prototype.hasOwnProperty.call(record, key);
|
|
6200
|
+
}
|
|
6201
|
+
var AspClient = class {
|
|
6202
|
+
stdin;
|
|
6203
|
+
stdout;
|
|
6204
|
+
emitter = new EventEmitter();
|
|
6205
|
+
pending = /* @__PURE__ */ new Map();
|
|
6206
|
+
nextId = 1;
|
|
6207
|
+
lineBuffer = "";
|
|
6208
|
+
disposed = false;
|
|
6209
|
+
get isDisposed() {
|
|
6210
|
+
return this.disposed;
|
|
6211
|
+
}
|
|
6212
|
+
constructor(options) {
|
|
6213
|
+
this.stdin = options.stdin;
|
|
6214
|
+
this.stdout = options.stdout;
|
|
6215
|
+
this.stdout.setEncoding("utf8");
|
|
6216
|
+
this.stdout.on("data", this.handleStdoutData);
|
|
6217
|
+
this.stdin.on("error", this.handleStdinError);
|
|
6218
|
+
}
|
|
6219
|
+
on(event, listener) {
|
|
6220
|
+
this.emitter.on(event, listener);
|
|
6221
|
+
}
|
|
6222
|
+
off(event, listener) {
|
|
6223
|
+
this.emitter.off(event, listener);
|
|
6224
|
+
}
|
|
6225
|
+
async request(method, params, opts) {
|
|
6226
|
+
if (this.disposed) {
|
|
6227
|
+
throw new Error(`Cannot send ${method}: ASP client disposed`);
|
|
6228
|
+
}
|
|
6229
|
+
const id = this.nextId;
|
|
6230
|
+
this.nextId += 1;
|
|
6231
|
+
const promise = new Promise((resolve, reject) => {
|
|
6232
|
+
const timeoutMs = opts?.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
6233
|
+
const timer = timeoutMs > 0 ? setTimeout(() => {
|
|
6234
|
+
this.pending.delete(id);
|
|
6235
|
+
reject(new Error(`ASP request timed out for ${method}`));
|
|
6236
|
+
}, timeoutMs) : null;
|
|
6237
|
+
this.pending.set(id, { resolve, reject, method, timer });
|
|
6238
|
+
});
|
|
6239
|
+
this.write({ method, id, params });
|
|
6240
|
+
return promise;
|
|
6241
|
+
}
|
|
6242
|
+
notify(method, params) {
|
|
6243
|
+
if (this.disposed) {
|
|
6244
|
+
return;
|
|
6245
|
+
}
|
|
6246
|
+
try {
|
|
6247
|
+
this.write(params === void 0 ? { method } : { method, params });
|
|
6248
|
+
} catch (error) {
|
|
6249
|
+
console.warn(`[AspClient] Failed to send notification ${method}:`, error);
|
|
6250
|
+
}
|
|
6251
|
+
}
|
|
6252
|
+
respond(id, result) {
|
|
6253
|
+
if (this.disposed) {
|
|
6254
|
+
return;
|
|
6255
|
+
}
|
|
6256
|
+
try {
|
|
6257
|
+
this.write({ id, result });
|
|
6258
|
+
} catch (error) {
|
|
6259
|
+
console.warn(`[AspClient] Failed to send response ${String(id)}:`, error);
|
|
6260
|
+
}
|
|
6261
|
+
}
|
|
6262
|
+
reject(id, code, message, data) {
|
|
6263
|
+
if (this.disposed) {
|
|
6264
|
+
return;
|
|
6265
|
+
}
|
|
6266
|
+
try {
|
|
6267
|
+
this.write({
|
|
6268
|
+
id,
|
|
6269
|
+
error: {
|
|
6270
|
+
code,
|
|
6271
|
+
message,
|
|
6272
|
+
...data !== void 0 ? { data } : {}
|
|
6273
|
+
}
|
|
6274
|
+
});
|
|
6275
|
+
} catch (error) {
|
|
6276
|
+
console.warn(`[AspClient] Failed to send error response ${String(id)}:`, error);
|
|
6277
|
+
}
|
|
6278
|
+
}
|
|
6279
|
+
dispose(reason = new Error("ASP client disposed")) {
|
|
6280
|
+
if (this.disposed) {
|
|
6281
|
+
return;
|
|
6282
|
+
}
|
|
6283
|
+
this.disposed = true;
|
|
6284
|
+
this.stdout.off("data", this.handleStdoutData);
|
|
6285
|
+
this.stdin.removeListener("error", this.handleStdinError);
|
|
6286
|
+
for (const [id, pending] of this.pending) {
|
|
6287
|
+
if (pending.timer) {
|
|
6288
|
+
clearTimeout(pending.timer);
|
|
6289
|
+
}
|
|
6290
|
+
pending.reject(new Error(`${reason.message} while waiting for ${pending.method}`));
|
|
6291
|
+
this.pending.delete(id);
|
|
6292
|
+
}
|
|
6293
|
+
this.lineBuffer = "";
|
|
6294
|
+
this.emitter.emit("dispose", reason);
|
|
6295
|
+
this.emitter.removeAllListeners();
|
|
6296
|
+
}
|
|
6297
|
+
handleStdoutData = (chunk) => {
|
|
6298
|
+
this.lineBuffer += chunk.toString();
|
|
6299
|
+
let newlineIndex = this.lineBuffer.indexOf("\n");
|
|
6300
|
+
while (newlineIndex >= 0) {
|
|
6301
|
+
const line = this.lineBuffer.slice(0, newlineIndex).trim();
|
|
6302
|
+
this.lineBuffer = this.lineBuffer.slice(newlineIndex + 1);
|
|
6303
|
+
if (line.length > 0) {
|
|
6304
|
+
this.handleLine(line);
|
|
6305
|
+
}
|
|
6306
|
+
newlineIndex = this.lineBuffer.indexOf("\n");
|
|
6307
|
+
}
|
|
6308
|
+
};
|
|
6309
|
+
handleStdinError = (error) => {
|
|
6310
|
+
this.dispose(new Error(`ASP stdin error: ${error.message}`));
|
|
6311
|
+
};
|
|
6312
|
+
handleLine(line) {
|
|
6313
|
+
let parsed;
|
|
6314
|
+
try {
|
|
6315
|
+
parsed = JSON.parse(line);
|
|
6316
|
+
} catch (error) {
|
|
6317
|
+
console.warn("[AspClient] Failed to parse ASP JSON line:", error);
|
|
6318
|
+
return;
|
|
6319
|
+
}
|
|
6320
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
6321
|
+
console.warn("[AspClient] Ignoring non-object ASP message");
|
|
6322
|
+
return;
|
|
6323
|
+
}
|
|
6324
|
+
const message = parsed;
|
|
6325
|
+
const hasRequestId = typeof message.id === "number" || typeof message.id === "string";
|
|
6326
|
+
if (hasRequestId && (hasOwn(message, "result") || hasOwn(message, "error"))) {
|
|
6327
|
+
this.handleResponse(message);
|
|
6328
|
+
return;
|
|
6329
|
+
}
|
|
6330
|
+
if (hasRequestId && typeof message.method === "string") {
|
|
6331
|
+
this.emitter.emit("serverRequest", message);
|
|
6332
|
+
return;
|
|
6333
|
+
}
|
|
6334
|
+
if (!hasOwn(message, "id") && typeof message.method === "string") {
|
|
6335
|
+
this.emitter.emit("notification", message);
|
|
6336
|
+
}
|
|
6337
|
+
}
|
|
6338
|
+
handleResponse(message) {
|
|
6339
|
+
if (typeof message.id !== "number") {
|
|
6340
|
+
console.warn("[AspClient] Ignoring response with non-numeric request id");
|
|
6341
|
+
return;
|
|
6342
|
+
}
|
|
6343
|
+
const pending = this.pending.get(message.id);
|
|
6344
|
+
if (!pending) {
|
|
6345
|
+
console.warn(`[AspClient] Ignoring response for unknown request id ${message.id}`);
|
|
6346
|
+
return;
|
|
6347
|
+
}
|
|
6348
|
+
this.pending.delete(message.id);
|
|
6349
|
+
if (pending.timer) {
|
|
6350
|
+
clearTimeout(pending.timer);
|
|
6351
|
+
}
|
|
6352
|
+
if (hasOwn(message, "error")) {
|
|
6353
|
+
pending.reject(this.createRpcError(pending.method, message.error));
|
|
6354
|
+
return;
|
|
6355
|
+
}
|
|
6356
|
+
pending.resolve(message.result);
|
|
6357
|
+
}
|
|
6358
|
+
createRpcError(method, error) {
|
|
6359
|
+
if (typeof error !== "object" || error === null || Array.isArray(error)) {
|
|
6360
|
+
return new Error(`ASP request failed for ${method}`);
|
|
6361
|
+
}
|
|
6362
|
+
const rpcError = error;
|
|
6363
|
+
const code = typeof rpcError.code === "number" ? ` ${rpcError.code}` : "";
|
|
6364
|
+
const message = typeof rpcError.message === "string" ? rpcError.message : "Unknown ASP error";
|
|
6365
|
+
const data = hasOwn(rpcError, "data") ? ` data=${JSON.stringify(rpcError.data)}` : "";
|
|
6366
|
+
return new Error(`ASP request failed for ${method}:${code} ${message}${data}`);
|
|
6367
|
+
}
|
|
6368
|
+
write(message) {
|
|
6369
|
+
try {
|
|
6370
|
+
this.stdin.write(`${JSON.stringify(message)}
|
|
6371
|
+
`, (error) => {
|
|
6372
|
+
if (error) {
|
|
6373
|
+
this.dispose(new Error(`ASP write failed: ${error.message}`));
|
|
6374
|
+
}
|
|
6375
|
+
});
|
|
6376
|
+
} catch (error) {
|
|
6377
|
+
const writeError = error instanceof Error ? error : new Error("ASP write failed");
|
|
6378
|
+
this.dispose(writeError);
|
|
6379
|
+
throw writeError;
|
|
6380
|
+
}
|
|
6381
|
+
}
|
|
6382
|
+
};
|
|
6383
|
+
|
|
6384
|
+
// src/managers/codex-asp/app-server-process.ts
|
|
6385
|
+
var DEFAULT_CODEX_BINARY = "codex";
|
|
6386
|
+
var DEFAULT_CODEX_ARGS = [
|
|
6387
|
+
"app-server",
|
|
6388
|
+
"--listen",
|
|
6389
|
+
"stdio://",
|
|
6390
|
+
"-c",
|
|
6391
|
+
"features.memories=false",
|
|
6392
|
+
"-c",
|
|
6393
|
+
"memories.use_memories=false",
|
|
6394
|
+
"-c",
|
|
6395
|
+
"memories.generate_memories=false"
|
|
6396
|
+
];
|
|
6397
|
+
var MIN_CODEX_CLI_VERSION = "0.144.6";
|
|
6398
|
+
var CODEX_UPGRADE_TIMEOUT_MS = 12e4;
|
|
6399
|
+
var codexCliVersionEnsured = null;
|
|
6400
|
+
var ENGINE_PACKAGE_VERSION = "0.1.676";
|
|
6401
|
+
var INITIALIZE_METHOD = "initialize";
|
|
6402
|
+
var INITIALIZED_NOTIFICATION = "initialized";
|
|
6403
|
+
var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
|
|
6404
|
+
var AppServerProcess = class {
|
|
6405
|
+
binary;
|
|
6406
|
+
args;
|
|
6407
|
+
env;
|
|
6408
|
+
cwd;
|
|
6409
|
+
chatgptAuthTokens;
|
|
6410
|
+
refreshChatgptAuthTokens;
|
|
6411
|
+
emitter = new EventEmitter2();
|
|
6412
|
+
child = null;
|
|
6413
|
+
client = null;
|
|
6414
|
+
shuttingDown = false;
|
|
6415
|
+
invalidating = false;
|
|
6416
|
+
constructor(options) {
|
|
6417
|
+
this.binary = options.binary ?? DEFAULT_CODEX_BINARY;
|
|
6418
|
+
const baseArgs = options.args ?? (options.env.REPLICAS_CODEX_AUTH_METHOD === "foundry" ? [
|
|
6419
|
+
...DEFAULT_CODEX_ARGS,
|
|
6420
|
+
"-c",
|
|
6421
|
+
`model=${JSON.stringify(options.env.CODEX_FOUNDRY_MODEL)}`,
|
|
6422
|
+
"-c",
|
|
6423
|
+
'model_provider="azure"',
|
|
6424
|
+
"-c",
|
|
6425
|
+
'model_providers.azure.name="Azure OpenAI"',
|
|
6426
|
+
"-c",
|
|
6427
|
+
`model_providers.azure.base_url=${JSON.stringify(options.env.CODEX_FOUNDRY_BASE_URL)}`,
|
|
6428
|
+
"-c",
|
|
6429
|
+
'model_providers.azure.env_key="AZURE_OPENAI_API_KEY"',
|
|
6430
|
+
"-c",
|
|
6431
|
+
'model_providers.azure.wire_api="responses"'
|
|
6432
|
+
] : DEFAULT_CODEX_ARGS);
|
|
6433
|
+
this.args = [...baseArgs, ...(options.configOverrides ?? []).flatMap((override) => ["-c", override])];
|
|
6434
|
+
this.env = options.env;
|
|
6435
|
+
this.cwd = options.cwd;
|
|
6436
|
+
this.chatgptAuthTokens = options.chatgptAuthTokens;
|
|
6437
|
+
this.refreshChatgptAuthTokens = options.refreshChatgptAuthTokens;
|
|
6438
|
+
}
|
|
6439
|
+
on(event, listener) {
|
|
6440
|
+
this.emitter.on(event, listener);
|
|
6441
|
+
}
|
|
6442
|
+
async start() {
|
|
6443
|
+
if (this.child && this.client) {
|
|
6444
|
+
return { client: this.client };
|
|
6445
|
+
}
|
|
6446
|
+
this.shuttingDown = false;
|
|
6447
|
+
this.invalidating = false;
|
|
6448
|
+
await this.ensureMinCodexCliVersion();
|
|
6449
|
+
const child = spawn(this.binary, this.args, {
|
|
6450
|
+
cwd: this.cwd,
|
|
6451
|
+
env: this.env,
|
|
6452
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
6453
|
+
});
|
|
6454
|
+
this.child = child;
|
|
6455
|
+
child.stderr.setEncoding("utf8");
|
|
6456
|
+
child.stderr.on("data", (chunk) => {
|
|
6457
|
+
for (const line of chunk.toString().split("\n")) {
|
|
6458
|
+
if (line.trim().length > 0) {
|
|
6459
|
+
console.error(`[codex-app-server] ${line}`);
|
|
6460
|
+
}
|
|
6461
|
+
}
|
|
6462
|
+
});
|
|
6463
|
+
child.on("exit", (code, signal) => {
|
|
6464
|
+
this.client?.dispose();
|
|
6465
|
+
this.client = null;
|
|
6466
|
+
this.child = null;
|
|
6467
|
+
if (!this.shuttingDown) {
|
|
6468
|
+
if (!this.invalidating) {
|
|
6469
|
+
console.warn(`[AppServerProcess] codex app-server exited unexpectedly code=${code ?? "null"} signal=${signal ?? "null"}`);
|
|
6470
|
+
}
|
|
6471
|
+
this.emitter.emit("exit", code, signal);
|
|
6472
|
+
}
|
|
6473
|
+
});
|
|
6474
|
+
const client = new AspClient({ stdin: child.stdin, stdout: child.stdout });
|
|
6475
|
+
this.client = client;
|
|
6476
|
+
client.on("serverRequest", (serverRequest) => {
|
|
6477
|
+
if (serverRequest.method !== "account/chatgptAuthTokens/refresh") return;
|
|
6478
|
+
if (!this.refreshChatgptAuthTokens) {
|
|
6479
|
+
client.reject(serverRequest.id, -32603, "Codex OAuth refresh is not configured");
|
|
6480
|
+
return;
|
|
6481
|
+
}
|
|
6482
|
+
void this.refreshChatgptAuthTokens(serverRequest.params).then((tokens) => {
|
|
6483
|
+
client.respond(serverRequest.id, tokens);
|
|
6484
|
+
}).catch((error) => {
|
|
6485
|
+
if (error instanceof Error && error.name === "CodexAspAuthMethodChangedError") {
|
|
6486
|
+
this.invalidating = true;
|
|
6487
|
+
client.dispose(error);
|
|
6488
|
+
if (!child.killed) child.kill("SIGTERM");
|
|
6489
|
+
return;
|
|
6490
|
+
}
|
|
6491
|
+
client.reject(
|
|
6492
|
+
serverRequest.id,
|
|
6493
|
+
-32603,
|
|
6494
|
+
error instanceof Error ? error.message : "Failed to refresh Codex OAuth credentials"
|
|
6495
|
+
);
|
|
6496
|
+
});
|
|
6497
|
+
});
|
|
6498
|
+
let cleanupEarlyFailureHandlers = () => {
|
|
6499
|
+
};
|
|
6500
|
+
const earlyFailure = new Promise((_resolve, reject) => {
|
|
6501
|
+
const onError = (error) => {
|
|
6502
|
+
reject(error);
|
|
6503
|
+
};
|
|
6504
|
+
const onExit = (code, signal) => {
|
|
6505
|
+
reject(new Error(`codex app-server exited before initialize completed code=${code ?? "null"} signal=${signal ?? "null"}`));
|
|
6506
|
+
};
|
|
6507
|
+
child.once("error", onError);
|
|
6508
|
+
child.once("exit", onExit);
|
|
6509
|
+
cleanupEarlyFailureHandlers = () => {
|
|
6510
|
+
child.off("error", onError);
|
|
6511
|
+
child.off("exit", onExit);
|
|
6512
|
+
};
|
|
6513
|
+
});
|
|
6514
|
+
try {
|
|
6515
|
+
const initializeParams = {
|
|
6516
|
+
clientInfo: {
|
|
6517
|
+
name: "replicas_engine",
|
|
6518
|
+
title: "Replicas Engine",
|
|
6519
|
+
version: ENGINE_PACKAGE_VERSION
|
|
6520
|
+
},
|
|
6521
|
+
capabilities: {
|
|
6522
|
+
experimentalApi: true,
|
|
6523
|
+
requestAttestation: false,
|
|
6524
|
+
optOutNotificationMethods: null
|
|
6525
|
+
}
|
|
6526
|
+
};
|
|
6527
|
+
await Promise.race([
|
|
6528
|
+
client.request(INITIALIZE_METHOD, initializeParams),
|
|
6529
|
+
earlyFailure
|
|
6530
|
+
]);
|
|
6531
|
+
cleanupEarlyFailureHandlers();
|
|
6532
|
+
client.notify(INITIALIZED_NOTIFICATION);
|
|
6533
|
+
await this.loginWithConfiguredCredentials(client);
|
|
6534
|
+
return { client };
|
|
6535
|
+
} catch (error) {
|
|
6536
|
+
cleanupEarlyFailureHandlers();
|
|
6537
|
+
client.dispose();
|
|
6538
|
+
await this.killAfterFailedStart();
|
|
6539
|
+
throw error;
|
|
6540
|
+
}
|
|
6541
|
+
}
|
|
6542
|
+
async stop() {
|
|
6543
|
+
const child = this.child;
|
|
6544
|
+
this.shuttingDown = true;
|
|
6545
|
+
this.client?.dispose(new Error("ASP process stopped"));
|
|
6546
|
+
this.client = null;
|
|
6547
|
+
this.child = null;
|
|
6548
|
+
if (!child || child.killed) {
|
|
6549
|
+
return;
|
|
6550
|
+
}
|
|
6551
|
+
await new Promise((resolve) => {
|
|
6552
|
+
const timer = setTimeout(() => {
|
|
6553
|
+
child.kill("SIGKILL");
|
|
6554
|
+
}, 2e3);
|
|
6555
|
+
child.once("exit", () => {
|
|
6556
|
+
clearTimeout(timer);
|
|
6557
|
+
resolve();
|
|
6558
|
+
});
|
|
6559
|
+
child.kill("SIGTERM");
|
|
6560
|
+
});
|
|
6561
|
+
}
|
|
6562
|
+
ensureMinCodexCliVersion() {
|
|
6563
|
+
codexCliVersionEnsured ??= this.runEnsureMinCodexCliVersion().catch((error) => {
|
|
6564
|
+
codexCliVersionEnsured = null;
|
|
6565
|
+
console.warn("[AppServerProcess] Failed to ensure minimum codex CLI version, continuing with installed binary:", error);
|
|
6566
|
+
});
|
|
6567
|
+
return codexCliVersionEnsured;
|
|
6568
|
+
}
|
|
6569
|
+
async runEnsureMinCodexCliVersion() {
|
|
6570
|
+
const { stdout } = await execFileAsync(this.binary, ["--version"], { env: this.env });
|
|
6571
|
+
const version = stdout.match(/(\d+\.\d+\.\d+)/)?.[1];
|
|
6572
|
+
if (version && !isVersionBelow(version, MIN_CODEX_CLI_VERSION)) {
|
|
6573
|
+
return;
|
|
6574
|
+
}
|
|
6575
|
+
console.warn(`[AppServerProcess] codex CLI ${version ?? "unknown"} is below ${MIN_CODEX_CLI_VERSION}; upgrading @openai/codex`);
|
|
6576
|
+
await execFileAsync(
|
|
6577
|
+
"npm",
|
|
6578
|
+
["install", "-g", "--no-audit", "--no-fund", `@openai/codex@${MIN_CODEX_CLI_VERSION}`],
|
|
6579
|
+
{ env: this.env, timeout: CODEX_UPGRADE_TIMEOUT_MS }
|
|
6580
|
+
);
|
|
6581
|
+
console.warn(`[AppServerProcess] upgraded codex CLI to ${MIN_CODEX_CLI_VERSION}`);
|
|
6582
|
+
}
|
|
6583
|
+
async loginWithConfiguredCredentials(client) {
|
|
6584
|
+
if (this.env.REPLICAS_CODEX_AUTH_METHOD === "oauth") {
|
|
6585
|
+
if (!this.chatgptAuthTokens) {
|
|
6586
|
+
throw new Error("Codex OAuth credentials were not prepared before app-server startup");
|
|
6587
|
+
}
|
|
6588
|
+
const params2 = {
|
|
6589
|
+
type: "chatgptAuthTokens",
|
|
6590
|
+
...this.chatgptAuthTokens
|
|
6591
|
+
};
|
|
6592
|
+
await client.request(ACCOUNT_LOGIN_START_METHOD, params2);
|
|
6593
|
+
return;
|
|
6594
|
+
}
|
|
6595
|
+
if (this.env.REPLICAS_CODEX_AUTH_METHOD !== "api_key" || !this.env.OPENAI_API_KEY) return;
|
|
6596
|
+
const params = {
|
|
6597
|
+
type: "apiKey",
|
|
6598
|
+
apiKey: this.env.OPENAI_API_KEY
|
|
6599
|
+
};
|
|
6600
|
+
await client.request(ACCOUNT_LOGIN_START_METHOD, params);
|
|
6601
|
+
}
|
|
6602
|
+
async killAfterFailedStart() {
|
|
6603
|
+
const child = this.child;
|
|
6604
|
+
this.child = null;
|
|
6605
|
+
this.client = null;
|
|
6606
|
+
if (!child || child.killed) {
|
|
6607
|
+
return;
|
|
6608
|
+
}
|
|
6609
|
+
this.shuttingDown = true;
|
|
6610
|
+
child.kill("SIGKILL");
|
|
6611
|
+
await new Promise((resolve) => {
|
|
6612
|
+
child.once("exit", () => resolve());
|
|
6613
|
+
});
|
|
6614
|
+
}
|
|
6615
|
+
};
|
|
6616
|
+
|
|
6617
|
+
// src/managers/codex-asp/notification-dispatch.ts
|
|
6618
|
+
var TURN_STARTED_METHOD = "turn/started";
|
|
6619
|
+
var TURN_COMPLETED_METHOD = "turn/completed";
|
|
6620
|
+
var TURN_PLAN_UPDATED_METHOD = "turn/plan/updated";
|
|
6621
|
+
var THREAD_GOAL_UPDATED_METHOD = "thread/goal/updated";
|
|
6622
|
+
var THREAD_GOAL_CLEARED_METHOD = "thread/goal/cleared";
|
|
6623
|
+
var ITEM_STARTED_METHOD = "item/started";
|
|
6624
|
+
var ITEM_COMPLETED_METHOD = "item/completed";
|
|
6625
|
+
var AGENT_MESSAGE_DELTA_METHOD = "item/agentMessage/delta";
|
|
6626
|
+
var REASONING_SUMMARY_TEXT_DELTA_METHOD = "item/reasoning/summaryTextDelta";
|
|
6627
|
+
var REASONING_TEXT_DELTA_METHOD = "item/reasoning/textDelta";
|
|
6628
|
+
var REASONING_SUMMARY_PART_ADDED_METHOD = "item/reasoning/summaryPartAdded";
|
|
6629
|
+
var COMMAND_EXECUTION_OUTPUT_DELTA_METHOD = "item/commandExecution/outputDelta";
|
|
6630
|
+
var FILE_CHANGE_OUTPUT_DELTA_METHOD = "item/fileChange/outputDelta";
|
|
6631
|
+
var ACCOUNT_RATE_LIMITS_UPDATED_METHOD = "account/rateLimits/updated";
|
|
6632
|
+
var THREAD_TOKEN_USAGE_UPDATED_METHOD = "thread/tokenUsage/updated";
|
|
6633
|
+
var THREAD_COMPACTED_METHOD = "thread/compacted";
|
|
6634
|
+
function dispatchAspNotification(notification, handlers) {
|
|
6635
|
+
const handler = handlers[notification.method];
|
|
6636
|
+
if (!handler) return;
|
|
6637
|
+
handler(notification);
|
|
6638
|
+
}
|
|
6639
|
+
function recoverCompletedTurn(turn, completedItems, agentMessageDeltas) {
|
|
6640
|
+
const items = turn.items.length > 0 ? [...turn.items] : [];
|
|
6641
|
+
const itemIds = new Set(items.map((item) => item.id));
|
|
6642
|
+
for (const item of completedItems) {
|
|
6643
|
+
if (itemIds.has(item.id)) continue;
|
|
6644
|
+
items.push(item);
|
|
6645
|
+
itemIds.add(item.id);
|
|
6646
|
+
}
|
|
6647
|
+
for (const [itemId, text] of agentMessageDeltas) {
|
|
6648
|
+
if (itemIds.has(itemId)) continue;
|
|
6649
|
+
items.push({ type: "agentMessage", id: itemId, text, phase: null, memoryCitation: null });
|
|
6650
|
+
}
|
|
6651
|
+
return items.length > 0 ? { ...turn, items, itemsView: "full" } : turn;
|
|
6652
|
+
}
|
|
6653
|
+
|
|
6135
6654
|
export {
|
|
6136
6655
|
isRecord,
|
|
6137
6656
|
TIMEOUT,
|
|
@@ -6238,7 +6757,6 @@ export {
|
|
|
6238
6757
|
isTransientErrorText,
|
|
6239
6758
|
isClaudeAuthErrorText,
|
|
6240
6759
|
isCodexAuthError,
|
|
6241
|
-
isVersionBelow,
|
|
6242
6760
|
hasChatStarted,
|
|
6243
6761
|
DESKTOP_STREAM_PORT,
|
|
6244
6762
|
MERGED_MESSAGE_SEPARATOR,
|
|
@@ -6300,5 +6818,29 @@ export {
|
|
|
6300
6818
|
MEMORY_SUMMARY_FILENAME,
|
|
6301
6819
|
MEMORY_INDEX_FILENAME,
|
|
6302
6820
|
getMemoryOutputSafetyViolation,
|
|
6303
|
-
isSkillRegistryManifest
|
|
6821
|
+
isSkillRegistryManifest,
|
|
6822
|
+
putPresignedFile,
|
|
6823
|
+
buildCodexAgentEnv,
|
|
6824
|
+
execAsync,
|
|
6825
|
+
execFileAsync,
|
|
6826
|
+
SUBPROCESS_MAX_BUFFER,
|
|
6827
|
+
AppServerProcess,
|
|
6828
|
+
TURN_STARTED_METHOD,
|
|
6829
|
+
TURN_COMPLETED_METHOD,
|
|
6830
|
+
TURN_PLAN_UPDATED_METHOD,
|
|
6831
|
+
THREAD_GOAL_UPDATED_METHOD,
|
|
6832
|
+
THREAD_GOAL_CLEARED_METHOD,
|
|
6833
|
+
ITEM_STARTED_METHOD,
|
|
6834
|
+
ITEM_COMPLETED_METHOD,
|
|
6835
|
+
AGENT_MESSAGE_DELTA_METHOD,
|
|
6836
|
+
REASONING_SUMMARY_TEXT_DELTA_METHOD,
|
|
6837
|
+
REASONING_TEXT_DELTA_METHOD,
|
|
6838
|
+
REASONING_SUMMARY_PART_ADDED_METHOD,
|
|
6839
|
+
COMMAND_EXECUTION_OUTPUT_DELTA_METHOD,
|
|
6840
|
+
FILE_CHANGE_OUTPUT_DELTA_METHOD,
|
|
6841
|
+
ACCOUNT_RATE_LIMITS_UPDATED_METHOD,
|
|
6842
|
+
THREAD_TOKEN_USAGE_UPDATED_METHOD,
|
|
6843
|
+
THREAD_COMPACTED_METHOD,
|
|
6844
|
+
dispatchAspNotification,
|
|
6845
|
+
recoverCompletedTurn
|
|
6304
6846
|
};
|