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
|
@@ -1,5 +1,20 @@
|
|
|
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
|
+
|
|
3
18
|
// ../shared/src/agent.ts
|
|
4
19
|
var AGENT = {
|
|
5
20
|
CLAUDE: "claude",
|
|
@@ -52,19 +67,113 @@ function codexReasoningEffortForThinkingLevel(thinkingLevel) {
|
|
|
52
67
|
return thinkingLevel ? CODEX_REASONING_EFFORT_BY_THINKING_LEVEL[thinkingLevel] : void 0;
|
|
53
68
|
}
|
|
54
69
|
|
|
55
|
-
// ../shared/src/
|
|
56
|
-
|
|
57
|
-
|
|
70
|
+
// ../shared/src/analytics/types.ts
|
|
71
|
+
import { z } from "zod";
|
|
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);
|
|
58
84
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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");
|
|
174
|
+
}
|
|
175
|
+
function isAgentChatMcpActivityRecord(value) {
|
|
176
|
+
return isNamedAgentChatActivityRecord(value, "mcpName");
|
|
68
177
|
}
|
|
69
178
|
|
|
70
179
|
// ../shared/src/sandbox.ts
|
|
@@ -231,47 +340,63 @@ function gitIdentityConfigCommands(identity, scope = "global") {
|
|
|
231
340
|
}
|
|
232
341
|
|
|
233
342
|
// ../shared/src/headless-agent.ts
|
|
234
|
-
import { z } from "zod";
|
|
235
|
-
var headlessAgentRequestBaseSchema =
|
|
236
|
-
agent:
|
|
343
|
+
import { z as z2 } from "zod";
|
|
344
|
+
var headlessAgentRequestBaseSchema = z2.object({
|
|
345
|
+
agent: z2.custom(
|
|
237
346
|
(value) => typeof value === "string" && isValidCodingAgentProvider(value)
|
|
238
347
|
),
|
|
239
|
-
model:
|
|
240
|
-
prompt:
|
|
241
|
-
workingDirectory:
|
|
242
|
-
timeoutSeconds:
|
|
348
|
+
model: z2.string().min(1),
|
|
349
|
+
prompt: z2.string(),
|
|
350
|
+
workingDirectory: z2.string().min(1),
|
|
351
|
+
timeoutSeconds: z2.number().int().min(1).max(1800).default(300)
|
|
243
352
|
});
|
|
244
|
-
var headlessAgentInputFileSchema =
|
|
245
|
-
path:
|
|
246
|
-
downloadUrl:
|
|
353
|
+
var headlessAgentInputFileSchema = z2.object({
|
|
354
|
+
path: z2.string().min(1),
|
|
355
|
+
downloadUrl: z2.url()
|
|
247
356
|
});
|
|
248
|
-
var headlessAgentOutputFileSchema =
|
|
249
|
-
path:
|
|
250
|
-
uploadUrl:
|
|
251
|
-
contentType:
|
|
252
|
-
minChars:
|
|
253
|
-
maxChars:
|
|
357
|
+
var headlessAgentOutputFileSchema = z2.object({
|
|
358
|
+
path: z2.string().min(1),
|
|
359
|
+
uploadUrl: z2.url(),
|
|
360
|
+
contentType: z2.string().min(1),
|
|
361
|
+
minChars: z2.number().int().positive().optional(),
|
|
362
|
+
maxChars: z2.number().int().positive().optional()
|
|
254
363
|
});
|
|
255
|
-
var headlessAgentRequestSchema =
|
|
364
|
+
var headlessAgentRequestSchema = z2.discriminatedUnion("mode", [
|
|
256
365
|
headlessAgentRequestBaseSchema.extend({
|
|
257
|
-
mode:
|
|
258
|
-
outputSchema:
|
|
366
|
+
mode: z2.literal("structured"),
|
|
367
|
+
outputSchema: z2.record(z2.string(), z2.json())
|
|
259
368
|
}),
|
|
260
369
|
headlessAgentRequestBaseSchema.extend({
|
|
261
|
-
mode:
|
|
262
|
-
inputFiles:
|
|
263
|
-
outputFiles:
|
|
264
|
-
sensitiveValues:
|
|
370
|
+
mode: z2.literal("filesystem"),
|
|
371
|
+
inputFiles: z2.array(headlessAgentInputFileSchema),
|
|
372
|
+
outputFiles: z2.array(headlessAgentOutputFileSchema),
|
|
373
|
+
sensitiveValues: z2.array(z2.string())
|
|
265
374
|
})
|
|
266
375
|
]);
|
|
267
|
-
var headlessFilesystemAgentResultSchema =
|
|
268
|
-
message:
|
|
269
|
-
files:
|
|
270
|
-
sha256:
|
|
271
|
-
sizeBytes:
|
|
376
|
+
var headlessFilesystemAgentResultSchema = z2.object({
|
|
377
|
+
message: z2.string(),
|
|
378
|
+
files: z2.record(z2.string(), z2.object({
|
|
379
|
+
sha256: z2.string().regex(/^[a-f0-9]{64}$/),
|
|
380
|
+
sizeBytes: z2.number().int().nonnegative()
|
|
272
381
|
}))
|
|
273
382
|
});
|
|
274
383
|
|
|
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
|
+
|
|
275
400
|
// ../shared/src/engine/environment.ts
|
|
276
401
|
var DESKTOP_STREAM_PORT = 6080;
|
|
277
402
|
|
|
@@ -292,11 +417,6 @@ var ASTER_MODEL_LABELS = {
|
|
|
292
417
|
"gpt-oss-120b": "GPT-OSS 120B"
|
|
293
418
|
};
|
|
294
419
|
|
|
295
|
-
// ../shared/src/type-guards.ts
|
|
296
|
-
function isRecord(value) {
|
|
297
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
420
|
// ../shared/src/engine/types.ts
|
|
301
421
|
var DEFAULT_CHAT_TITLES = {
|
|
302
422
|
claude: "Claude Code",
|
|
@@ -589,110 +709,6 @@ function paginateEngineLogContent(input) {
|
|
|
589
709
|
};
|
|
590
710
|
}
|
|
591
711
|
|
|
592
|
-
// ../shared/src/analytics/types.ts
|
|
593
|
-
import { z as z2 } from "zod";
|
|
594
|
-
|
|
595
|
-
// ../shared/src/credentials/types.ts
|
|
596
|
-
var CREDENTIAL_SCOPE = {
|
|
597
|
-
USER: "user",
|
|
598
|
-
ORG: "org"
|
|
599
|
-
};
|
|
600
|
-
var CREDENTIAL_SCOPES = Object.values(CREDENTIAL_SCOPE);
|
|
601
|
-
var CREDENTIAL_SCOPE_PRIORITY = [CREDENTIAL_SCOPE.USER, CREDENTIAL_SCOPE.ORG];
|
|
602
|
-
|
|
603
|
-
// ../shared/src/credentials/agents.ts
|
|
604
|
-
var CREDENTIAL_METHOD = {
|
|
605
|
-
OAUTH: "oauth",
|
|
606
|
-
API_KEY: "api_key",
|
|
607
|
-
FOUNDRY: "foundry",
|
|
608
|
-
BEDROCK: "bedrock",
|
|
609
|
-
OPENCODE_GO: "opencode-go",
|
|
610
|
-
ASTER: "aster",
|
|
611
|
-
OPENROUTER: "openrouter",
|
|
612
|
-
AI_GATEWAY: "ai-gateway"
|
|
613
|
-
};
|
|
614
|
-
var CREDENTIAL_TYPE = {
|
|
615
|
-
CLAUDE_OAUTH: "claude",
|
|
616
|
-
ANTHROPIC_API_KEY: "claude_anthropic_api_key",
|
|
617
|
-
CLAUDE_FOUNDRY: "claude_foundry",
|
|
618
|
-
CLAUDE_BEDROCK: "claude_bedrock",
|
|
619
|
-
CODEX_OAUTH: "codex",
|
|
620
|
-
OPENAI_API_KEY: "openai_api_key",
|
|
621
|
-
CODEX_FOUNDRY: "codex_foundry",
|
|
622
|
-
CURSOR_API_KEY: "cursor_api_key",
|
|
623
|
-
OPENCODE_GO_API_KEY: "opencode_go_api_key",
|
|
624
|
-
ASTER_API_KEY: "aster_api_key",
|
|
625
|
-
OPENROUTER_API_KEY: "openrouter_api_key",
|
|
626
|
-
AI_GATEWAY_API_KEY: "ai_gateway_api_key"
|
|
627
|
-
};
|
|
628
|
-
var AGENT_CREDENTIAL_METHODS_IN_ORDER = {
|
|
629
|
-
[AGENT.CLAUDE]: [
|
|
630
|
-
{ method: CREDENTIAL_METHOD.OAUTH, credentialType: CREDENTIAL_TYPE.CLAUDE_OAUTH },
|
|
631
|
-
{ method: CREDENTIAL_METHOD.API_KEY, credentialType: CREDENTIAL_TYPE.ANTHROPIC_API_KEY },
|
|
632
|
-
{ method: CREDENTIAL_METHOD.FOUNDRY, credentialType: CREDENTIAL_TYPE.CLAUDE_FOUNDRY },
|
|
633
|
-
{ method: CREDENTIAL_METHOD.BEDROCK, credentialType: CREDENTIAL_TYPE.CLAUDE_BEDROCK }
|
|
634
|
-
],
|
|
635
|
-
[AGENT.CODEX]: [
|
|
636
|
-
{ method: CREDENTIAL_METHOD.OAUTH, credentialType: CREDENTIAL_TYPE.CODEX_OAUTH },
|
|
637
|
-
{ method: CREDENTIAL_METHOD.API_KEY, credentialType: CREDENTIAL_TYPE.OPENAI_API_KEY },
|
|
638
|
-
{ method: CREDENTIAL_METHOD.FOUNDRY, credentialType: CREDENTIAL_TYPE.CODEX_FOUNDRY }
|
|
639
|
-
],
|
|
640
|
-
[AGENT.CURSOR]: [
|
|
641
|
-
{ method: CREDENTIAL_METHOD.API_KEY, credentialType: CREDENTIAL_TYPE.CURSOR_API_KEY }
|
|
642
|
-
],
|
|
643
|
-
[AGENT.DEEPSEEK]: [
|
|
644
|
-
{ method: CREDENTIAL_METHOD.OPENROUTER, credentialType: CREDENTIAL_TYPE.OPENROUTER_API_KEY }
|
|
645
|
-
],
|
|
646
|
-
[AGENT.FX]: [
|
|
647
|
-
{ method: CREDENTIAL_METHOD.AI_GATEWAY, credentialType: CREDENTIAL_TYPE.AI_GATEWAY_API_KEY }
|
|
648
|
-
],
|
|
649
|
-
[AGENT.KIMI]: [
|
|
650
|
-
{ method: CREDENTIAL_METHOD.AI_GATEWAY, credentialType: CREDENTIAL_TYPE.AI_GATEWAY_API_KEY }
|
|
651
|
-
],
|
|
652
|
-
[AGENT.OPENCODE]: [
|
|
653
|
-
{ method: CREDENTIAL_METHOD.OPENCODE_GO, credentialType: CREDENTIAL_TYPE.OPENCODE_GO_API_KEY },
|
|
654
|
-
{ method: CREDENTIAL_METHOD.ASTER, credentialType: CREDENTIAL_TYPE.ASTER_API_KEY },
|
|
655
|
-
{ method: CREDENTIAL_METHOD.OPENROUTER, credentialType: CREDENTIAL_TYPE.OPENROUTER_API_KEY }
|
|
656
|
-
],
|
|
657
|
-
[AGENT.PI]: [
|
|
658
|
-
{ method: CREDENTIAL_METHOD.ASTER, credentialType: CREDENTIAL_TYPE.ASTER_API_KEY },
|
|
659
|
-
{ method: CREDENTIAL_METHOD.OPENROUTER, credentialType: CREDENTIAL_TYPE.OPENROUTER_API_KEY }
|
|
660
|
-
]
|
|
661
|
-
};
|
|
662
|
-
|
|
663
|
-
// ../shared/src/analytics/types.ts
|
|
664
|
-
function isAgentChatActivityRecord(value) {
|
|
665
|
-
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";
|
|
666
|
-
}
|
|
667
|
-
var agentCredentialSnapshotSchema = z2.object({
|
|
668
|
-
method: z2.enum(CREDENTIAL_METHOD),
|
|
669
|
-
scope: z2.enum(CREDENTIAL_SCOPE),
|
|
670
|
-
revision: z2.string().optional()
|
|
671
|
-
});
|
|
672
|
-
function isAuthMethod(value) {
|
|
673
|
-
return typeof value === "string" && Object.values(CREDENTIAL_METHOD).some((method) => method === value);
|
|
674
|
-
}
|
|
675
|
-
function isCredentialScope(value) {
|
|
676
|
-
return typeof value === "string" && CREDENTIAL_SCOPES.some((scope) => scope === value);
|
|
677
|
-
}
|
|
678
|
-
function isAgentChatTurnActivityRecord(value) {
|
|
679
|
-
return isAgentChatActivityRecord(value) && typeof value.turnId === "string" && typeof value.seconds === "number" && Number.isFinite(value.seconds) && value.seconds >= 0;
|
|
680
|
-
}
|
|
681
|
-
function isAgentChatActivityCallRecord(value) {
|
|
682
|
-
return isAgentChatActivityRecord(value) && typeof value.callId === "string" && value.callId.length > 0;
|
|
683
|
-
}
|
|
684
|
-
function isNamedAgentChatActivityRecord(value, field) {
|
|
685
|
-
if (!isAgentChatActivityCallRecord(value)) return false;
|
|
686
|
-
const name = value[field];
|
|
687
|
-
return typeof name === "string" && name.length > 0;
|
|
688
|
-
}
|
|
689
|
-
function isAgentChatSkillActivityRecord(value) {
|
|
690
|
-
return isNamedAgentChatActivityRecord(value, "skillName");
|
|
691
|
-
}
|
|
692
|
-
function isAgentChatMcpActivityRecord(value) {
|
|
693
|
-
return isNamedAgentChatActivityRecord(value, "mcpName");
|
|
694
|
-
}
|
|
695
|
-
|
|
696
712
|
// ../shared/src/event.ts
|
|
697
713
|
var CLAUDE_PARTIAL_MESSAGE_EVENT_TYPE = "claude-partial-message";
|
|
698
714
|
function coerceClaudePartialMessagePayload(payload) {
|
|
@@ -719,6 +735,7 @@ var COMPACTION_STATUS_EVENT_TYPE = "compaction-status";
|
|
|
719
735
|
var CHAT_INTERRUPTED_EVENT_TYPE = "replicas-interrupted";
|
|
720
736
|
var CHAT_GOAL_EVENT_TYPE = "chat-goal";
|
|
721
737
|
var AUTH_RETRY_STATUS_EVENT_TYPE = "auth-retry-status";
|
|
738
|
+
var CURSOR_CONNECTION_STATUS_EVENT_TYPE = "cursor-connection-status";
|
|
722
739
|
var AUTH_FALLBACK_EVENT_TYPE = "auth-fallback";
|
|
723
740
|
function coerceAuthFallbackPayload(payload) {
|
|
724
741
|
const { provider, reason, exhaustedMethod, exhaustedScope, candidateMethod, candidateScope, status, detail } = payload;
|
|
@@ -986,6 +1003,37 @@ function paginateChatHistory(full, params) {
|
|
|
986
1003
|
};
|
|
987
1004
|
}
|
|
988
1005
|
|
|
1006
|
+
// ../shared/src/routes/codex.ts
|
|
1007
|
+
var CODEX_AUTH_ENV_KEYS = [
|
|
1008
|
+
"OPENAI_API_KEY",
|
|
1009
|
+
"AZURE_OPENAI_API_KEY",
|
|
1010
|
+
"CODEX_FOUNDRY_BASE_URL",
|
|
1011
|
+
"CODEX_FOUNDRY_MODEL",
|
|
1012
|
+
"REPLICAS_CODEX_AUTH_METHOD"
|
|
1013
|
+
];
|
|
1014
|
+
function codexAuthEnvFromResponse(response) {
|
|
1015
|
+
switch (response.type) {
|
|
1016
|
+
case "oauth":
|
|
1017
|
+
return { REPLICAS_CODEX_AUTH_METHOD: "oauth" };
|
|
1018
|
+
case "api_key":
|
|
1019
|
+
return { OPENAI_API_KEY: response.apiKey, REPLICAS_CODEX_AUTH_METHOD: "api_key" };
|
|
1020
|
+
case "foundry":
|
|
1021
|
+
return {
|
|
1022
|
+
AZURE_OPENAI_API_KEY: response.apiKey,
|
|
1023
|
+
CODEX_FOUNDRY_BASE_URL: response.baseUrl,
|
|
1024
|
+
CODEX_FOUNDRY_MODEL: response.model,
|
|
1025
|
+
REPLICAS_CODEX_AUTH_METHOD: "foundry"
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
var CODEX_AUTH_ENV_KEYS_BY_METHOD = {
|
|
1030
|
+
none: [],
|
|
1031
|
+
oauth: ["REPLICAS_CODEX_AUTH_METHOD"],
|
|
1032
|
+
api_key: ["OPENAI_API_KEY", "REPLICAS_CODEX_AUTH_METHOD"],
|
|
1033
|
+
bedrock: [],
|
|
1034
|
+
foundry: ["AZURE_OPENAI_API_KEY", "CODEX_FOUNDRY_BASE_URL", "CODEX_FOUNDRY_MODEL", "REPLICAS_CODEX_AUTH_METHOD"]
|
|
1035
|
+
};
|
|
1036
|
+
|
|
989
1037
|
// ../shared/src/memory-safety.ts
|
|
990
1038
|
var SECRET_PATTERNS = [
|
|
991
1039
|
/sk-[A-Za-z0-9_-]{10,}/g,
|
|
@@ -3350,58 +3398,11 @@ function isCodexAuthError(error) {
|
|
|
3350
3398
|
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");
|
|
3351
3399
|
}
|
|
3352
3400
|
|
|
3353
|
-
// ../shared/src/version.ts
|
|
3354
|
-
function compareVersions(v1, v2) {
|
|
3355
|
-
const parts1 = v1.split(".").map(Number);
|
|
3356
|
-
const parts2 = v2.split(".").map(Number);
|
|
3357
|
-
for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
|
|
3358
|
-
const num1 = parts1[i] || 0;
|
|
3359
|
-
const num2 = parts2[i] || 0;
|
|
3360
|
-
if (num1 > num2) return 1;
|
|
3361
|
-
if (num1 < num2) return -1;
|
|
3362
|
-
}
|
|
3363
|
-
return 0;
|
|
3364
|
-
}
|
|
3365
|
-
function isVersionBelow(version, minimum) {
|
|
3366
|
-
return compareVersions(version, minimum) < 0;
|
|
3367
|
-
}
|
|
3368
|
-
|
|
3369
3401
|
// ../shared/src/engine/chat-tabs.ts
|
|
3370
3402
|
function hasChatStarted(chat) {
|
|
3371
3403
|
return chat.processing || Boolean(chat.awaitingInput) || Boolean(chat.goal) || Boolean(chat.lastMessageText) || chat.updatedAt > chat.createdAt;
|
|
3372
3404
|
}
|
|
3373
3405
|
|
|
3374
|
-
// ../shared/src/routes/codex.ts
|
|
3375
|
-
var CODEX_AUTH_ENV_KEYS = [
|
|
3376
|
-
"OPENAI_API_KEY",
|
|
3377
|
-
"AZURE_OPENAI_API_KEY",
|
|
3378
|
-
"CODEX_FOUNDRY_BASE_URL",
|
|
3379
|
-
"CODEX_FOUNDRY_MODEL",
|
|
3380
|
-
"REPLICAS_CODEX_AUTH_METHOD"
|
|
3381
|
-
];
|
|
3382
|
-
function codexAuthEnvFromResponse(response) {
|
|
3383
|
-
switch (response.type) {
|
|
3384
|
-
case "oauth":
|
|
3385
|
-
return { REPLICAS_CODEX_AUTH_METHOD: "oauth" };
|
|
3386
|
-
case "api_key":
|
|
3387
|
-
return { OPENAI_API_KEY: response.apiKey, REPLICAS_CODEX_AUTH_METHOD: "api_key" };
|
|
3388
|
-
case "foundry":
|
|
3389
|
-
return {
|
|
3390
|
-
AZURE_OPENAI_API_KEY: response.apiKey,
|
|
3391
|
-
CODEX_FOUNDRY_BASE_URL: response.baseUrl,
|
|
3392
|
-
CODEX_FOUNDRY_MODEL: response.model,
|
|
3393
|
-
REPLICAS_CODEX_AUTH_METHOD: "foundry"
|
|
3394
|
-
};
|
|
3395
|
-
}
|
|
3396
|
-
}
|
|
3397
|
-
var CODEX_AUTH_ENV_KEYS_BY_METHOD = {
|
|
3398
|
-
none: [],
|
|
3399
|
-
oauth: ["REPLICAS_CODEX_AUTH_METHOD"],
|
|
3400
|
-
api_key: ["OPENAI_API_KEY", "REPLICAS_CODEX_AUTH_METHOD"],
|
|
3401
|
-
bedrock: [],
|
|
3402
|
-
foundry: ["AZURE_OPENAI_API_KEY", "CODEX_FOUNDRY_BASE_URL", "CODEX_FOUNDRY_MODEL", "REPLICAS_CODEX_AUTH_METHOD"]
|
|
3403
|
-
};
|
|
3404
|
-
|
|
3405
3406
|
// ../shared/src/routes/claude.ts
|
|
3406
3407
|
var CLAUDE_AUTH_ENV_KEYS = [
|
|
3407
3408
|
"ANTHROPIC_API_KEY",
|
|
@@ -6175,484 +6176,6 @@ function isSkillRegistryManifest(value) {
|
|
|
6175
6176
|
);
|
|
6176
6177
|
}
|
|
6177
6178
|
|
|
6178
|
-
// src/utils/presigned-upload.ts
|
|
6179
|
-
import { createReadStream } from "fs";
|
|
6180
|
-
import { request as httpRequest } from "http";
|
|
6181
|
-
import { request as httpsRequest } from "https";
|
|
6182
|
-
async function putPresignedFile(urlValue, filePath, size, contentType) {
|
|
6183
|
-
await new Promise((resolve, reject) => {
|
|
6184
|
-
const url = new URL(urlValue);
|
|
6185
|
-
const request = (url.protocol === "https:" ? httpsRequest : httpRequest)(url, {
|
|
6186
|
-
method: "PUT",
|
|
6187
|
-
headers: {
|
|
6188
|
-
"content-length": String(size),
|
|
6189
|
-
"content-type": contentType
|
|
6190
|
-
}
|
|
6191
|
-
}, (response) => {
|
|
6192
|
-
response.setEncoding("utf8");
|
|
6193
|
-
let body = "";
|
|
6194
|
-
response.on("data", (chunk) => {
|
|
6195
|
-
body += chunk;
|
|
6196
|
-
});
|
|
6197
|
-
response.on("end", () => {
|
|
6198
|
-
const status = response.statusCode ?? 0;
|
|
6199
|
-
if (status >= 200 && status < 300) resolve();
|
|
6200
|
-
else reject(new Error(`upload failed: ${status} ${body}`));
|
|
6201
|
-
});
|
|
6202
|
-
response.on("error", reject);
|
|
6203
|
-
});
|
|
6204
|
-
request.on("error", reject);
|
|
6205
|
-
const file = size > 0 ? createReadStream(filePath, { start: 0, end: size - 1 }) : createReadStream(filePath);
|
|
6206
|
-
file.on("error", (error) => request.destroy(error));
|
|
6207
|
-
file.pipe(request);
|
|
6208
|
-
});
|
|
6209
|
-
}
|
|
6210
|
-
|
|
6211
|
-
// src/utils/codex-agent-env.ts
|
|
6212
|
-
function buildCodexAgentEnv(source = process.env) {
|
|
6213
|
-
const env = Object.fromEntries(
|
|
6214
|
-
Object.entries(source).filter((entry) => typeof entry[1] === "string")
|
|
6215
|
-
);
|
|
6216
|
-
if (env.REPLICAS_CODEX_AUTH_METHOD === "oauth" || env.REPLICAS_CODEX_AUTH_METHOD === "foundry") {
|
|
6217
|
-
delete env.OPENAI_API_KEY;
|
|
6218
|
-
}
|
|
6219
|
-
delete env.GH_TOKEN;
|
|
6220
|
-
delete env.GITHUB_TOKEN;
|
|
6221
|
-
delete env.GH_CONFIG_DIR;
|
|
6222
|
-
return env;
|
|
6223
|
-
}
|
|
6224
|
-
|
|
6225
|
-
// src/utils/exec.ts
|
|
6226
|
-
import { exec, execFile } from "child_process";
|
|
6227
|
-
import { promisify } from "util";
|
|
6228
|
-
var execAsync = promisify(exec);
|
|
6229
|
-
var execFileAsync = promisify(execFile);
|
|
6230
|
-
var SUBPROCESS_MAX_BUFFER = HOOK_EXEC_MAX_BUFFER_BYTES;
|
|
6231
|
-
|
|
6232
|
-
// src/managers/codex-asp/app-server-process.ts
|
|
6233
|
-
import { spawn } from "child_process";
|
|
6234
|
-
import { EventEmitter as EventEmitter2 } from "events";
|
|
6235
|
-
|
|
6236
|
-
// src/managers/codex-asp/asp-client.ts
|
|
6237
|
-
import { EventEmitter } from "events";
|
|
6238
|
-
var DEFAULT_REQUEST_TIMEOUT_MS = 12e4;
|
|
6239
|
-
function hasOwn(record, key) {
|
|
6240
|
-
return Object.prototype.hasOwnProperty.call(record, key);
|
|
6241
|
-
}
|
|
6242
|
-
var AspClient = class {
|
|
6243
|
-
stdin;
|
|
6244
|
-
stdout;
|
|
6245
|
-
emitter = new EventEmitter();
|
|
6246
|
-
pending = /* @__PURE__ */ new Map();
|
|
6247
|
-
nextId = 1;
|
|
6248
|
-
lineBuffer = "";
|
|
6249
|
-
disposed = false;
|
|
6250
|
-
get isDisposed() {
|
|
6251
|
-
return this.disposed;
|
|
6252
|
-
}
|
|
6253
|
-
constructor(options) {
|
|
6254
|
-
this.stdin = options.stdin;
|
|
6255
|
-
this.stdout = options.stdout;
|
|
6256
|
-
this.stdout.setEncoding("utf8");
|
|
6257
|
-
this.stdout.on("data", this.handleStdoutData);
|
|
6258
|
-
this.stdin.on("error", this.handleStdinError);
|
|
6259
|
-
}
|
|
6260
|
-
on(event, listener) {
|
|
6261
|
-
this.emitter.on(event, listener);
|
|
6262
|
-
}
|
|
6263
|
-
off(event, listener) {
|
|
6264
|
-
this.emitter.off(event, listener);
|
|
6265
|
-
}
|
|
6266
|
-
async request(method, params, opts) {
|
|
6267
|
-
if (this.disposed) {
|
|
6268
|
-
throw new Error(`Cannot send ${method}: ASP client disposed`);
|
|
6269
|
-
}
|
|
6270
|
-
const id = this.nextId;
|
|
6271
|
-
this.nextId += 1;
|
|
6272
|
-
const promise = new Promise((resolve, reject) => {
|
|
6273
|
-
const timeoutMs = opts?.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
6274
|
-
const timer = timeoutMs > 0 ? setTimeout(() => {
|
|
6275
|
-
this.pending.delete(id);
|
|
6276
|
-
reject(new Error(`ASP request timed out for ${method}`));
|
|
6277
|
-
}, timeoutMs) : null;
|
|
6278
|
-
this.pending.set(id, { resolve, reject, method, timer });
|
|
6279
|
-
});
|
|
6280
|
-
this.write({ method, id, params });
|
|
6281
|
-
return promise;
|
|
6282
|
-
}
|
|
6283
|
-
notify(method, params) {
|
|
6284
|
-
if (this.disposed) {
|
|
6285
|
-
return;
|
|
6286
|
-
}
|
|
6287
|
-
try {
|
|
6288
|
-
this.write(params === void 0 ? { method } : { method, params });
|
|
6289
|
-
} catch (error) {
|
|
6290
|
-
console.warn(`[AspClient] Failed to send notification ${method}:`, error);
|
|
6291
|
-
}
|
|
6292
|
-
}
|
|
6293
|
-
respond(id, result) {
|
|
6294
|
-
if (this.disposed) {
|
|
6295
|
-
return;
|
|
6296
|
-
}
|
|
6297
|
-
try {
|
|
6298
|
-
this.write({ id, result });
|
|
6299
|
-
} catch (error) {
|
|
6300
|
-
console.warn(`[AspClient] Failed to send response ${String(id)}:`, error);
|
|
6301
|
-
}
|
|
6302
|
-
}
|
|
6303
|
-
reject(id, code, message, data) {
|
|
6304
|
-
if (this.disposed) {
|
|
6305
|
-
return;
|
|
6306
|
-
}
|
|
6307
|
-
try {
|
|
6308
|
-
this.write({
|
|
6309
|
-
id,
|
|
6310
|
-
error: {
|
|
6311
|
-
code,
|
|
6312
|
-
message,
|
|
6313
|
-
...data !== void 0 ? { data } : {}
|
|
6314
|
-
}
|
|
6315
|
-
});
|
|
6316
|
-
} catch (error) {
|
|
6317
|
-
console.warn(`[AspClient] Failed to send error response ${String(id)}:`, error);
|
|
6318
|
-
}
|
|
6319
|
-
}
|
|
6320
|
-
dispose(reason = new Error("ASP client disposed")) {
|
|
6321
|
-
if (this.disposed) {
|
|
6322
|
-
return;
|
|
6323
|
-
}
|
|
6324
|
-
this.disposed = true;
|
|
6325
|
-
this.stdout.off("data", this.handleStdoutData);
|
|
6326
|
-
this.stdin.removeListener("error", this.handleStdinError);
|
|
6327
|
-
for (const [id, pending] of this.pending) {
|
|
6328
|
-
if (pending.timer) {
|
|
6329
|
-
clearTimeout(pending.timer);
|
|
6330
|
-
}
|
|
6331
|
-
pending.reject(new Error(`${reason.message} while waiting for ${pending.method}`));
|
|
6332
|
-
this.pending.delete(id);
|
|
6333
|
-
}
|
|
6334
|
-
this.lineBuffer = "";
|
|
6335
|
-
this.emitter.emit("dispose", reason);
|
|
6336
|
-
this.emitter.removeAllListeners();
|
|
6337
|
-
}
|
|
6338
|
-
handleStdoutData = (chunk) => {
|
|
6339
|
-
this.lineBuffer += chunk.toString();
|
|
6340
|
-
let newlineIndex = this.lineBuffer.indexOf("\n");
|
|
6341
|
-
while (newlineIndex >= 0) {
|
|
6342
|
-
const line = this.lineBuffer.slice(0, newlineIndex).trim();
|
|
6343
|
-
this.lineBuffer = this.lineBuffer.slice(newlineIndex + 1);
|
|
6344
|
-
if (line.length > 0) {
|
|
6345
|
-
this.handleLine(line);
|
|
6346
|
-
}
|
|
6347
|
-
newlineIndex = this.lineBuffer.indexOf("\n");
|
|
6348
|
-
}
|
|
6349
|
-
};
|
|
6350
|
-
handleStdinError = (error) => {
|
|
6351
|
-
this.dispose(new Error(`ASP stdin error: ${error.message}`));
|
|
6352
|
-
};
|
|
6353
|
-
handleLine(line) {
|
|
6354
|
-
let parsed;
|
|
6355
|
-
try {
|
|
6356
|
-
parsed = JSON.parse(line);
|
|
6357
|
-
} catch (error) {
|
|
6358
|
-
console.warn("[AspClient] Failed to parse ASP JSON line:", error);
|
|
6359
|
-
return;
|
|
6360
|
-
}
|
|
6361
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
6362
|
-
console.warn("[AspClient] Ignoring non-object ASP message");
|
|
6363
|
-
return;
|
|
6364
|
-
}
|
|
6365
|
-
const message = parsed;
|
|
6366
|
-
const hasRequestId = typeof message.id === "number" || typeof message.id === "string";
|
|
6367
|
-
if (hasRequestId && (hasOwn(message, "result") || hasOwn(message, "error"))) {
|
|
6368
|
-
this.handleResponse(message);
|
|
6369
|
-
return;
|
|
6370
|
-
}
|
|
6371
|
-
if (hasRequestId && typeof message.method === "string") {
|
|
6372
|
-
this.emitter.emit("serverRequest", message);
|
|
6373
|
-
return;
|
|
6374
|
-
}
|
|
6375
|
-
if (!hasOwn(message, "id") && typeof message.method === "string") {
|
|
6376
|
-
this.emitter.emit("notification", message);
|
|
6377
|
-
}
|
|
6378
|
-
}
|
|
6379
|
-
handleResponse(message) {
|
|
6380
|
-
if (typeof message.id !== "number") {
|
|
6381
|
-
console.warn("[AspClient] Ignoring response with non-numeric request id");
|
|
6382
|
-
return;
|
|
6383
|
-
}
|
|
6384
|
-
const pending = this.pending.get(message.id);
|
|
6385
|
-
if (!pending) {
|
|
6386
|
-
console.warn(`[AspClient] Ignoring response for unknown request id ${message.id}`);
|
|
6387
|
-
return;
|
|
6388
|
-
}
|
|
6389
|
-
this.pending.delete(message.id);
|
|
6390
|
-
if (pending.timer) {
|
|
6391
|
-
clearTimeout(pending.timer);
|
|
6392
|
-
}
|
|
6393
|
-
if (hasOwn(message, "error")) {
|
|
6394
|
-
pending.reject(this.createRpcError(pending.method, message.error));
|
|
6395
|
-
return;
|
|
6396
|
-
}
|
|
6397
|
-
pending.resolve(message.result);
|
|
6398
|
-
}
|
|
6399
|
-
createRpcError(method, error) {
|
|
6400
|
-
if (typeof error !== "object" || error === null || Array.isArray(error)) {
|
|
6401
|
-
return new Error(`ASP request failed for ${method}`);
|
|
6402
|
-
}
|
|
6403
|
-
const rpcError = error;
|
|
6404
|
-
const code = typeof rpcError.code === "number" ? ` ${rpcError.code}` : "";
|
|
6405
|
-
const message = typeof rpcError.message === "string" ? rpcError.message : "Unknown ASP error";
|
|
6406
|
-
const data = hasOwn(rpcError, "data") ? ` data=${JSON.stringify(rpcError.data)}` : "";
|
|
6407
|
-
return new Error(`ASP request failed for ${method}:${code} ${message}${data}`);
|
|
6408
|
-
}
|
|
6409
|
-
write(message) {
|
|
6410
|
-
try {
|
|
6411
|
-
this.stdin.write(`${JSON.stringify(message)}
|
|
6412
|
-
`, (error) => {
|
|
6413
|
-
if (error) {
|
|
6414
|
-
this.dispose(new Error(`ASP write failed: ${error.message}`));
|
|
6415
|
-
}
|
|
6416
|
-
});
|
|
6417
|
-
} catch (error) {
|
|
6418
|
-
const writeError = error instanceof Error ? error : new Error("ASP write failed");
|
|
6419
|
-
this.dispose(writeError);
|
|
6420
|
-
throw writeError;
|
|
6421
|
-
}
|
|
6422
|
-
}
|
|
6423
|
-
};
|
|
6424
|
-
|
|
6425
|
-
// src/managers/codex-asp/app-server-process.ts
|
|
6426
|
-
var DEFAULT_CODEX_BINARY = "codex";
|
|
6427
|
-
var DEFAULT_CODEX_ARGS = [
|
|
6428
|
-
"app-server",
|
|
6429
|
-
"--listen",
|
|
6430
|
-
"stdio://",
|
|
6431
|
-
"-c",
|
|
6432
|
-
"features.memories=false",
|
|
6433
|
-
"-c",
|
|
6434
|
-
"memories.use_memories=false",
|
|
6435
|
-
"-c",
|
|
6436
|
-
"memories.generate_memories=false"
|
|
6437
|
-
];
|
|
6438
|
-
var MIN_CODEX_CLI_VERSION = "0.144.6";
|
|
6439
|
-
var CODEX_UPGRADE_TIMEOUT_MS = 12e4;
|
|
6440
|
-
var codexCliVersionEnsured = null;
|
|
6441
|
-
var ENGINE_PACKAGE_VERSION = "0.1.666";
|
|
6442
|
-
var INITIALIZE_METHOD = "initialize";
|
|
6443
|
-
var INITIALIZED_NOTIFICATION = "initialized";
|
|
6444
|
-
var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
|
|
6445
|
-
var AppServerProcess = class {
|
|
6446
|
-
binary;
|
|
6447
|
-
args;
|
|
6448
|
-
env;
|
|
6449
|
-
cwd;
|
|
6450
|
-
emitter = new EventEmitter2();
|
|
6451
|
-
child = null;
|
|
6452
|
-
client = null;
|
|
6453
|
-
shuttingDown = false;
|
|
6454
|
-
constructor(options) {
|
|
6455
|
-
this.binary = options.binary ?? DEFAULT_CODEX_BINARY;
|
|
6456
|
-
const baseArgs = options.args ?? (options.env.REPLICAS_CODEX_AUTH_METHOD === "foundry" ? [
|
|
6457
|
-
...DEFAULT_CODEX_ARGS,
|
|
6458
|
-
"-c",
|
|
6459
|
-
`model=${JSON.stringify(options.env.CODEX_FOUNDRY_MODEL)}`,
|
|
6460
|
-
"-c",
|
|
6461
|
-
'model_provider="azure"',
|
|
6462
|
-
"-c",
|
|
6463
|
-
'model_providers.azure.name="Azure OpenAI"',
|
|
6464
|
-
"-c",
|
|
6465
|
-
`model_providers.azure.base_url=${JSON.stringify(options.env.CODEX_FOUNDRY_BASE_URL)}`,
|
|
6466
|
-
"-c",
|
|
6467
|
-
'model_providers.azure.env_key="AZURE_OPENAI_API_KEY"',
|
|
6468
|
-
"-c",
|
|
6469
|
-
'model_providers.azure.wire_api="responses"'
|
|
6470
|
-
] : DEFAULT_CODEX_ARGS);
|
|
6471
|
-
this.args = [...baseArgs, ...(options.configOverrides ?? []).flatMap((override) => ["-c", override])];
|
|
6472
|
-
this.env = options.env;
|
|
6473
|
-
this.cwd = options.cwd;
|
|
6474
|
-
}
|
|
6475
|
-
on(event, listener) {
|
|
6476
|
-
this.emitter.on(event, listener);
|
|
6477
|
-
}
|
|
6478
|
-
async start() {
|
|
6479
|
-
if (this.child && this.client) {
|
|
6480
|
-
return { client: this.client };
|
|
6481
|
-
}
|
|
6482
|
-
this.shuttingDown = false;
|
|
6483
|
-
await this.ensureMinCodexCliVersion();
|
|
6484
|
-
const child = spawn(this.binary, this.args, {
|
|
6485
|
-
cwd: this.cwd,
|
|
6486
|
-
env: this.env,
|
|
6487
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
6488
|
-
});
|
|
6489
|
-
this.child = child;
|
|
6490
|
-
child.stderr.setEncoding("utf8");
|
|
6491
|
-
child.stderr.on("data", (chunk) => {
|
|
6492
|
-
for (const line of chunk.toString().split("\n")) {
|
|
6493
|
-
if (line.trim().length > 0) {
|
|
6494
|
-
console.error(`[codex-app-server] ${line}`);
|
|
6495
|
-
}
|
|
6496
|
-
}
|
|
6497
|
-
});
|
|
6498
|
-
child.on("exit", (code, signal) => {
|
|
6499
|
-
this.client?.dispose();
|
|
6500
|
-
this.client = null;
|
|
6501
|
-
this.child = null;
|
|
6502
|
-
if (!this.shuttingDown) {
|
|
6503
|
-
console.warn(`[AppServerProcess] codex app-server exited unexpectedly code=${code ?? "null"} signal=${signal ?? "null"}`);
|
|
6504
|
-
this.emitter.emit("exit", code, signal);
|
|
6505
|
-
}
|
|
6506
|
-
});
|
|
6507
|
-
const client = new AspClient({ stdin: child.stdin, stdout: child.stdout });
|
|
6508
|
-
this.client = client;
|
|
6509
|
-
let cleanupEarlyFailureHandlers = () => {
|
|
6510
|
-
};
|
|
6511
|
-
const earlyFailure = new Promise((_resolve, reject) => {
|
|
6512
|
-
const onError = (error) => {
|
|
6513
|
-
reject(error);
|
|
6514
|
-
};
|
|
6515
|
-
const onExit = (code, signal) => {
|
|
6516
|
-
reject(new Error(`codex app-server exited before initialize completed code=${code ?? "null"} signal=${signal ?? "null"}`));
|
|
6517
|
-
};
|
|
6518
|
-
child.once("error", onError);
|
|
6519
|
-
child.once("exit", onExit);
|
|
6520
|
-
cleanupEarlyFailureHandlers = () => {
|
|
6521
|
-
child.off("error", onError);
|
|
6522
|
-
child.off("exit", onExit);
|
|
6523
|
-
};
|
|
6524
|
-
});
|
|
6525
|
-
try {
|
|
6526
|
-
const initializeParams = {
|
|
6527
|
-
clientInfo: {
|
|
6528
|
-
name: "replicas_engine",
|
|
6529
|
-
title: "Replicas Engine",
|
|
6530
|
-
version: ENGINE_PACKAGE_VERSION
|
|
6531
|
-
},
|
|
6532
|
-
capabilities: {
|
|
6533
|
-
experimentalApi: true,
|
|
6534
|
-
requestAttestation: false,
|
|
6535
|
-
optOutNotificationMethods: null
|
|
6536
|
-
}
|
|
6537
|
-
};
|
|
6538
|
-
await Promise.race([
|
|
6539
|
-
client.request(INITIALIZE_METHOD, initializeParams),
|
|
6540
|
-
earlyFailure
|
|
6541
|
-
]);
|
|
6542
|
-
cleanupEarlyFailureHandlers();
|
|
6543
|
-
client.notify(INITIALIZED_NOTIFICATION);
|
|
6544
|
-
await this.loginWithConfiguredApiKey(client);
|
|
6545
|
-
return { client };
|
|
6546
|
-
} catch (error) {
|
|
6547
|
-
cleanupEarlyFailureHandlers();
|
|
6548
|
-
client.dispose();
|
|
6549
|
-
await this.killAfterFailedStart();
|
|
6550
|
-
throw error;
|
|
6551
|
-
}
|
|
6552
|
-
}
|
|
6553
|
-
async stop() {
|
|
6554
|
-
const child = this.child;
|
|
6555
|
-
this.shuttingDown = true;
|
|
6556
|
-
this.client?.dispose(new Error("ASP process stopped"));
|
|
6557
|
-
this.client = null;
|
|
6558
|
-
this.child = null;
|
|
6559
|
-
if (!child || child.killed) {
|
|
6560
|
-
return;
|
|
6561
|
-
}
|
|
6562
|
-
await new Promise((resolve) => {
|
|
6563
|
-
const timer = setTimeout(() => {
|
|
6564
|
-
child.kill("SIGKILL");
|
|
6565
|
-
}, 2e3);
|
|
6566
|
-
child.once("exit", () => {
|
|
6567
|
-
clearTimeout(timer);
|
|
6568
|
-
resolve();
|
|
6569
|
-
});
|
|
6570
|
-
child.kill("SIGTERM");
|
|
6571
|
-
});
|
|
6572
|
-
}
|
|
6573
|
-
ensureMinCodexCliVersion() {
|
|
6574
|
-
codexCliVersionEnsured ??= this.runEnsureMinCodexCliVersion().catch((error) => {
|
|
6575
|
-
codexCliVersionEnsured = null;
|
|
6576
|
-
console.warn("[AppServerProcess] Failed to ensure minimum codex CLI version, continuing with installed binary:", error);
|
|
6577
|
-
});
|
|
6578
|
-
return codexCliVersionEnsured;
|
|
6579
|
-
}
|
|
6580
|
-
async runEnsureMinCodexCliVersion() {
|
|
6581
|
-
const { stdout } = await execFileAsync(this.binary, ["--version"], { env: this.env });
|
|
6582
|
-
const version = stdout.match(/(\d+\.\d+\.\d+)/)?.[1];
|
|
6583
|
-
if (version && !isVersionBelow(version, MIN_CODEX_CLI_VERSION)) {
|
|
6584
|
-
return;
|
|
6585
|
-
}
|
|
6586
|
-
console.warn(`[AppServerProcess] codex CLI ${version ?? "unknown"} is below ${MIN_CODEX_CLI_VERSION}; upgrading @openai/codex`);
|
|
6587
|
-
await execFileAsync(
|
|
6588
|
-
"npm",
|
|
6589
|
-
["install", "-g", "--no-audit", "--no-fund", `@openai/codex@${MIN_CODEX_CLI_VERSION}`],
|
|
6590
|
-
{ env: this.env, timeout: CODEX_UPGRADE_TIMEOUT_MS }
|
|
6591
|
-
);
|
|
6592
|
-
console.warn(`[AppServerProcess] upgraded codex CLI to ${MIN_CODEX_CLI_VERSION}`);
|
|
6593
|
-
}
|
|
6594
|
-
async loginWithConfiguredApiKey(client) {
|
|
6595
|
-
if (this.env.REPLICAS_CODEX_AUTH_METHOD !== "api_key" || !this.env.OPENAI_API_KEY) {
|
|
6596
|
-
return;
|
|
6597
|
-
}
|
|
6598
|
-
const params = {
|
|
6599
|
-
type: "apiKey",
|
|
6600
|
-
apiKey: this.env.OPENAI_API_KEY
|
|
6601
|
-
};
|
|
6602
|
-
await client.request(ACCOUNT_LOGIN_START_METHOD, params);
|
|
6603
|
-
}
|
|
6604
|
-
async killAfterFailedStart() {
|
|
6605
|
-
const child = this.child;
|
|
6606
|
-
this.child = null;
|
|
6607
|
-
this.client = null;
|
|
6608
|
-
if (!child || child.killed) {
|
|
6609
|
-
return;
|
|
6610
|
-
}
|
|
6611
|
-
this.shuttingDown = true;
|
|
6612
|
-
child.kill("SIGKILL");
|
|
6613
|
-
await new Promise((resolve) => {
|
|
6614
|
-
child.once("exit", () => resolve());
|
|
6615
|
-
});
|
|
6616
|
-
}
|
|
6617
|
-
};
|
|
6618
|
-
|
|
6619
|
-
// src/managers/codex-asp/notification-dispatch.ts
|
|
6620
|
-
var TURN_STARTED_METHOD = "turn/started";
|
|
6621
|
-
var TURN_COMPLETED_METHOD = "turn/completed";
|
|
6622
|
-
var TURN_PLAN_UPDATED_METHOD = "turn/plan/updated";
|
|
6623
|
-
var THREAD_GOAL_UPDATED_METHOD = "thread/goal/updated";
|
|
6624
|
-
var THREAD_GOAL_CLEARED_METHOD = "thread/goal/cleared";
|
|
6625
|
-
var ITEM_STARTED_METHOD = "item/started";
|
|
6626
|
-
var ITEM_COMPLETED_METHOD = "item/completed";
|
|
6627
|
-
var AGENT_MESSAGE_DELTA_METHOD = "item/agentMessage/delta";
|
|
6628
|
-
var REASONING_SUMMARY_TEXT_DELTA_METHOD = "item/reasoning/summaryTextDelta";
|
|
6629
|
-
var REASONING_TEXT_DELTA_METHOD = "item/reasoning/textDelta";
|
|
6630
|
-
var REASONING_SUMMARY_PART_ADDED_METHOD = "item/reasoning/summaryPartAdded";
|
|
6631
|
-
var COMMAND_EXECUTION_OUTPUT_DELTA_METHOD = "item/commandExecution/outputDelta";
|
|
6632
|
-
var FILE_CHANGE_OUTPUT_DELTA_METHOD = "item/fileChange/outputDelta";
|
|
6633
|
-
var ACCOUNT_RATE_LIMITS_UPDATED_METHOD = "account/rateLimits/updated";
|
|
6634
|
-
var THREAD_TOKEN_USAGE_UPDATED_METHOD = "thread/tokenUsage/updated";
|
|
6635
|
-
var THREAD_COMPACTED_METHOD = "thread/compacted";
|
|
6636
|
-
function dispatchAspNotification(notification, handlers) {
|
|
6637
|
-
const handler = handlers[notification.method];
|
|
6638
|
-
if (!handler) return;
|
|
6639
|
-
handler(notification);
|
|
6640
|
-
}
|
|
6641
|
-
function recoverCompletedTurn(turn, completedItems, agentMessageDeltas) {
|
|
6642
|
-
const items = turn.items.length > 0 ? [...turn.items] : [];
|
|
6643
|
-
const itemIds = new Set(items.map((item) => item.id));
|
|
6644
|
-
for (const item of completedItems) {
|
|
6645
|
-
if (itemIds.has(item.id)) continue;
|
|
6646
|
-
items.push(item);
|
|
6647
|
-
itemIds.add(item.id);
|
|
6648
|
-
}
|
|
6649
|
-
for (const [itemId, text] of agentMessageDeltas) {
|
|
6650
|
-
if (itemIds.has(itemId)) continue;
|
|
6651
|
-
items.push({ type: "agentMessage", id: itemId, text, phase: null, memoryCitation: null });
|
|
6652
|
-
}
|
|
6653
|
-
return items.length > 0 ? { ...turn, items, itemsView: "full" } : turn;
|
|
6654
|
-
}
|
|
6655
|
-
|
|
6656
6179
|
export {
|
|
6657
6180
|
isRecord,
|
|
6658
6181
|
TIMEOUT,
|
|
@@ -6678,6 +6201,7 @@ export {
|
|
|
6678
6201
|
CHAT_INTERRUPTED_EVENT_TYPE,
|
|
6679
6202
|
CHAT_GOAL_EVENT_TYPE,
|
|
6680
6203
|
AUTH_RETRY_STATUS_EVENT_TYPE,
|
|
6204
|
+
CURSOR_CONNECTION_STATUS_EVENT_TYPE,
|
|
6681
6205
|
AUTH_FALLBACK_EVENT_TYPE,
|
|
6682
6206
|
CONTEXT_USAGE_EVENT_TYPE,
|
|
6683
6207
|
detectLanguageByPath,
|
|
@@ -6759,6 +6283,7 @@ export {
|
|
|
6759
6283
|
isTransientErrorText,
|
|
6760
6284
|
isClaudeAuthErrorText,
|
|
6761
6285
|
isCodexAuthError,
|
|
6286
|
+
isVersionBelow,
|
|
6762
6287
|
hasChatStarted,
|
|
6763
6288
|
DESKTOP_STREAM_PORT,
|
|
6764
6289
|
MERGED_MESSAGE_SEPARATOR,
|
|
@@ -6820,29 +6345,5 @@ export {
|
|
|
6820
6345
|
MEMORY_SUMMARY_FILENAME,
|
|
6821
6346
|
MEMORY_INDEX_FILENAME,
|
|
6822
6347
|
getMemoryOutputSafetyViolation,
|
|
6823
|
-
isSkillRegistryManifest
|
|
6824
|
-
putPresignedFile,
|
|
6825
|
-
buildCodexAgentEnv,
|
|
6826
|
-
execAsync,
|
|
6827
|
-
execFileAsync,
|
|
6828
|
-
SUBPROCESS_MAX_BUFFER,
|
|
6829
|
-
AppServerProcess,
|
|
6830
|
-
TURN_STARTED_METHOD,
|
|
6831
|
-
TURN_COMPLETED_METHOD,
|
|
6832
|
-
TURN_PLAN_UPDATED_METHOD,
|
|
6833
|
-
THREAD_GOAL_UPDATED_METHOD,
|
|
6834
|
-
THREAD_GOAL_CLEARED_METHOD,
|
|
6835
|
-
ITEM_STARTED_METHOD,
|
|
6836
|
-
ITEM_COMPLETED_METHOD,
|
|
6837
|
-
AGENT_MESSAGE_DELTA_METHOD,
|
|
6838
|
-
REASONING_SUMMARY_TEXT_DELTA_METHOD,
|
|
6839
|
-
REASONING_TEXT_DELTA_METHOD,
|
|
6840
|
-
REASONING_SUMMARY_PART_ADDED_METHOD,
|
|
6841
|
-
COMMAND_EXECUTION_OUTPUT_DELTA_METHOD,
|
|
6842
|
-
FILE_CHANGE_OUTPUT_DELTA_METHOD,
|
|
6843
|
-
ACCOUNT_RATE_LIMITS_UPDATED_METHOD,
|
|
6844
|
-
THREAD_TOKEN_USAGE_UPDATED_METHOD,
|
|
6845
|
-
THREAD_COMPACTED_METHOD,
|
|
6846
|
-
dispatchAspNotification,
|
|
6847
|
-
recoverCompletedTurn
|
|
6348
|
+
isSkillRegistryManifest
|
|
6848
6349
|
};
|