@letta-ai/letta-code 0.34.70 → 0.34.72
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/app-server-client.cjs.map +2 -2
- package/dist/app-server-client.js.map +2 -2
- package/dist/mcp-client.js +2 -2
- package/dist/mcp-client.js.map +1 -1
- package/dist/mcp-oauth.js +2 -2
- package/dist/mcp-oauth.js.map +1 -1
- package/dist/types/agent/subagent-state.d.ts +4 -1
- package/dist/types/agent/subagent-state.d.ts.map +1 -1
- package/dist/types/agent/subagents/background-link.d.ts +1 -1
- package/dist/types/agent/subagents/background-link.d.ts.map +1 -1
- package/dist/types/agent/subagents/child-send-tracking.d.ts +5 -0
- package/dist/types/agent/subagents/child-send-tracking.d.ts.map +1 -1
- package/dist/types/agent/subagents/ephemeral-subagent.d.ts +1 -0
- package/dist/types/agent/subagents/ephemeral-subagent.d.ts.map +1 -1
- package/dist/types/agent/subagents/index.d.ts.map +1 -1
- package/dist/types/agent/subagents/manager.d.ts.map +1 -1
- package/dist/types/agent/subagents/subagent-launcher.d.ts +1 -0
- package/dist/types/agent/subagents/subagent-launcher.d.ts.map +1 -1
- package/dist/types/agent/turn-recovery-policy.d.ts +1 -0
- package/dist/types/agent/turn-recovery-policy.d.ts.map +1 -1
- package/dist/types/backend/api/environments.d.ts +9 -2
- package/dist/types/backend/api/environments.d.ts.map +1 -1
- package/dist/types/backend/api/ephemeral-conversations.d.ts +1 -0
- package/dist/types/backend/api/ephemeral-conversations.d.ts.map +1 -1
- package/dist/types/backend/api/subagents.d.ts +48 -0
- package/dist/types/backend/api/subagents.d.ts.map +1 -0
- package/dist/types/backend/dev/pi-stream-adapter.d.ts +4 -10
- package/dist/types/backend/dev/pi-stream-adapter.d.ts.map +1 -1
- package/dist/types/backend/local/local-backend.d.ts +2 -0
- package/dist/types/backend/local/local-backend.d.ts.map +1 -1
- package/dist/types/backend/local/local-executor-factory.d.ts +2 -7
- package/dist/types/backend/local/local-executor-factory.d.ts.map +1 -1
- package/dist/types/permissions/checker.d.ts.map +1 -1
- package/dist/types/telemetry/error-reporting.d.ts +1 -0
- package/dist/types/telemetry/error-reporting.d.ts.map +1 -1
- package/dist/types/tools/impl/antigravity-session.d.ts +29 -0
- package/dist/types/tools/impl/antigravity-session.d.ts.map +1 -0
- package/dist/types/tools/impl/codex-app-server.d.ts.map +1 -1
- package/dist/types/tools/impl/external-coding-agent-task.d.ts.map +1 -1
- package/dist/types/tools/impl/external-coding-agent.d.ts +1 -1
- package/dist/types/tools/impl/external-coding-agent.d.ts.map +1 -1
- package/dist/types/tools/impl/external-llm-trace-launch.d.ts +1 -4
- package/dist/types/tools/impl/external-llm-trace-launch.d.ts.map +1 -1
- package/dist/types/tools/impl/external-llm-trace-payload.d.ts +1 -1
- package/dist/types/tools/impl/external-llm-trace-payload.d.ts.map +1 -1
- package/dist/types/tools/impl/external-llm-trace-proxy.d.ts +1 -0
- package/dist/types/tools/impl/external-llm-trace-proxy.d.ts.map +1 -1
- package/dist/types/tools/impl/external-llm-trace-session.d.ts.map +1 -1
- package/dist/types/tools/impl/list-agents.d.ts +35 -0
- package/dist/types/tools/impl/list-agents.d.ts.map +1 -0
- package/dist/types/tools/impl/native-session-owner.d.ts +3 -1
- package/dist/types/tools/impl/native-session-owner.d.ts.map +1 -1
- package/dist/types/tools/impl/remote-external-coding-agent.d.ts.map +1 -1
- package/dist/types/tools/impl/remote-external-worker-computer.d.ts.map +1 -1
- package/dist/types/tools/impl/send-agent-message.d.ts.map +1 -1
- package/dist/types/tools/impl/subagent-persistence.d.ts +10 -0
- package/dist/types/tools/impl/subagent-persistence.d.ts.map +1 -0
- package/dist/types/tools/impl/task-agent-selection.d.ts +1 -1
- package/dist/types/tools/impl/task-agent-selection.d.ts.map +1 -1
- package/dist/types/tools/impl/task-stop.d.ts.map +1 -1
- package/dist/types/tools/impl/task.d.ts +2 -1
- package/dist/types/tools/impl/task.d.ts.map +1 -1
- package/dist/types/tools/tool-definitions.d.ts +87 -0
- package/dist/types/tools/tool-definitions.d.ts.map +1 -1
- package/dist/types/tools/toolset-catalog.d.ts +1 -1
- package/dist/types/tools/toolset-catalog.d.ts.map +1 -1
- package/dist/types/types/app-server-info.d.ts +1 -0
- package/dist/types/types/app-server-info.d.ts.map +1 -1
- package/dist/types/types/external-tool-protocol.d.ts +1 -0
- package/dist/types/types/external-tool-protocol.d.ts.map +1 -1
- package/dist/types/utils/subagent-launch-marker.d.ts +1 -0
- package/dist/types/utils/subagent-launch-marker.d.ts.map +1 -1
- package/dist/types/websocket/listener/image-policy.d.ts +2 -0
- package/dist/types/websocket/listener/image-policy.d.ts.map +1 -1
- package/dist/types/websocket/listener/queue.d.ts +3 -1
- package/dist/types/websocket/listener/queue.d.ts.map +1 -1
- package/letta.js +1166 -361
- package/npm-shrinkwrap.json +129 -129
- package/package.json +2 -2
- package/skills/image-generation/SKILL.md +24 -11
package/letta.js
CHANGED
|
@@ -3472,14 +3472,14 @@ function trackEndTurnNoAssistant(params) {
|
|
|
3472
3472
|
});
|
|
3473
3473
|
}
|
|
3474
3474
|
function extractHttpStatus(message) {
|
|
3475
|
-
const match = /(?:^|:\s
|
|
3475
|
+
const match = /(?:^|:\s*|API error \()(?:HTTP\s+)?([45]\d{2})\b/.exec(message);
|
|
3476
3476
|
return match ? Number(match[1]) : undefined;
|
|
3477
3477
|
}
|
|
3478
3478
|
function reportExternalWorkerLaunchFailure(options) {
|
|
3479
3479
|
try {
|
|
3480
3480
|
const safe = (value, pattern) => value && pattern.test(value) ? value : undefined;
|
|
3481
3481
|
const safeId = (id) => safe(id, /^[a-zA-Z0-9_-]{1,128}$/);
|
|
3482
|
-
const httpStatus = extractHttpStatus(formatTelemetryErrorMessage(options.error));
|
|
3482
|
+
const httpStatus = options.httpStatus === undefined ? extractHttpStatus(formatTelemetryErrorMessage(options.error)) : options.httpStatus ?? undefined;
|
|
3483
3483
|
telemetry.trackError("external_worker_launch_failed", "External worker launch failed", JSON.stringify({
|
|
3484
3484
|
stage: options.stage,
|
|
3485
3485
|
harness: safe(options.harness, /^[a-z-]{1,32}$/),
|
|
@@ -4629,6 +4629,7 @@ var init_toolset_catalog = __esm(() => {
|
|
|
4629
4629
|
"SetWorkingDirectory",
|
|
4630
4630
|
"Task",
|
|
4631
4631
|
"SendAgentMessage",
|
|
4632
|
+
"ListAgents",
|
|
4632
4633
|
"Monitor",
|
|
4633
4634
|
"WatchPR",
|
|
4634
4635
|
"Wake",
|
|
@@ -4675,6 +4676,7 @@ var init_toolset_catalog = __esm(() => {
|
|
|
4675
4676
|
"Workflow",
|
|
4676
4677
|
"Task",
|
|
4677
4678
|
"SendAgentMessage",
|
|
4679
|
+
"ListAgents",
|
|
4678
4680
|
"TaskCreate",
|
|
4679
4681
|
"TaskGet",
|
|
4680
4682
|
"TaskList",
|
|
@@ -4693,6 +4695,7 @@ var init_toolset_catalog = __esm(() => {
|
|
|
4693
4695
|
"SetWorkingDirectory",
|
|
4694
4696
|
"Task",
|
|
4695
4697
|
"SendAgentMessage",
|
|
4698
|
+
"ListAgents",
|
|
4696
4699
|
"Monitor",
|
|
4697
4700
|
"WatchPR",
|
|
4698
4701
|
"Wake",
|
|
@@ -6139,7 +6142,7 @@ var package_default;
|
|
|
6139
6142
|
var init_package = __esm(() => {
|
|
6140
6143
|
package_default = {
|
|
6141
6144
|
name: "@letta-ai/letta-code",
|
|
6142
|
-
version: "0.34.
|
|
6145
|
+
version: "0.34.72",
|
|
6143
6146
|
lettaStartupLogProtocol: 1,
|
|
6144
6147
|
lettaConfigDirProtocol: 1,
|
|
6145
6148
|
description: "Letta Code is a CLI tool for interacting with stateful Letta agents from the terminal.",
|
|
@@ -6426,7 +6429,7 @@ var init_package = __esm(() => {
|
|
|
6426
6429
|
},
|
|
6427
6430
|
lettaLifecycleProtocol: 1,
|
|
6428
6431
|
lettaRuntimeGraphProtocol: 1,
|
|
6429
|
-
lettaRuntimeGraphSha512: "sha512-
|
|
6432
|
+
lettaRuntimeGraphSha512: "sha512-SoUJCWzp2p3N/h/S39QON/TRiQKI3RO2K2BTagcHNuJynxAOL9HR9gTA1JyBv5ENq+/4US4KrCaGcA35peIbjA==",
|
|
6430
6433
|
patchedDependencies: {
|
|
6431
6434
|
"@earendil-works/pi-ai@1.5.2": "patches/@earendil-works%2Fpi-ai@1.5.2.patch"
|
|
6432
6435
|
}
|
|
@@ -6463,7 +6466,7 @@ function maybeMapKnownApiError(status, responseText) {
|
|
|
6463
6466
|
try {
|
|
6464
6467
|
const errorData = JSON.parse(responseText);
|
|
6465
6468
|
if (typeof errorData.error === "string" && errorData.error.includes("only available for pro or enterprise")) {
|
|
6466
|
-
return new Error("PLAN_UPGRADE_REQUIRED");
|
|
6469
|
+
return Object.assign(new Error("PLAN_UPGRADE_REQUIRED"), { status });
|
|
6467
6470
|
}
|
|
6468
6471
|
} catch {}
|
|
6469
6472
|
return null;
|
|
@@ -94370,7 +94373,7 @@ function consumeSubagentLaunch(env4) {
|
|
|
94370
94373
|
delete env4[SUBAGENT_LAUNCH_ENV];
|
|
94371
94374
|
return isLaunch;
|
|
94372
94375
|
}
|
|
94373
|
-
var SUBAGENT_LAUNCH_ENV = "LETTA_SUBAGENT_LAUNCH", SUBAGENT_LAUNCH_PROFILE_ENV = "LETTA_SUBAGENT_LAUNCH_PROFILE", SUBAGENT_NAME_ENV = "LETTA_SUBAGENT_NAME", LISTENER_CONNECTION_ENV = "LETTA_RUNTIME_LISTENER_CONNECTION_ID";
|
|
94376
|
+
var SUBAGENT_LAUNCH_ENV = "LETTA_SUBAGENT_LAUNCH", SUBAGENT_LAUNCH_PROFILE_ENV = "LETTA_SUBAGENT_LAUNCH_PROFILE", SUBAGENT_SUMMARY_ENV = "LETTA_SUBAGENT_SUMMARY", SUBAGENT_NAME_ENV = "LETTA_SUBAGENT_NAME", LISTENER_CONNECTION_ENV = "LETTA_RUNTIME_LISTENER_CONNECTION_ID";
|
|
94374
94377
|
|
|
94375
94378
|
// src/constants.ts
|
|
94376
94379
|
var DEFAULT_TITLE_SUMMARIZATION_MODEL = "openai/gpt-6-luna", DEFAULT_AGENT_NAME = "Letta Code", INTERRUPTED_BY_USER = "Interrupted by user", TURN_DID_NOT_COMPLETE = "Turn did not complete", SYSTEM_REMINDER_TAG = "system-reminder", SYSTEM_REMINDER_OPEN, SYSTEM_REMINDER_CLOSE, SYSTEM_ALERT_TAG = "system-alert", SYSTEM_ALERT_OPEN, SYSTEM_ALERT_CLOSE, COMPACTION_SUMMARY_HEADER = "(Earlier messages in this conversation have been compacted to free up context, summarized below)", TOKEN_DISPLAY_THRESHOLD = 100, ELAPSED_DISPLAY_THRESHOLD_MS;
|
|
@@ -94743,7 +94746,9 @@ function resolveEphemeralSubagentLink(env4 = process.env) {
|
|
|
94743
94746
|
const parentAgentId = env4.LETTA_PARENT_AGENT_ID?.trim();
|
|
94744
94747
|
if (!parentAgentId)
|
|
94745
94748
|
return null;
|
|
94749
|
+
const summary = env4[SUBAGENT_SUMMARY_ENV]?.trim();
|
|
94746
94750
|
return {
|
|
94751
|
+
...summary ? { summary } : {},
|
|
94747
94752
|
parent_agent_id: parentAgentId,
|
|
94748
94753
|
is_subagent: true,
|
|
94749
94754
|
name: resolveCreatedAgentName(undefined, true, env4[SUBAGENT_NAME_ENV]?.trim() || undefined)
|
|
@@ -98724,6 +98729,7 @@ var init_subagents2 = __esm(() => {
|
|
|
98724
98729
|
MEMFS_V2_BUILTIN_SOURCES = [init_v2_default, reflection_v2_default];
|
|
98725
98730
|
GLOBAL_AGENTS_DIR = getGlobalAgentsDir();
|
|
98726
98731
|
RESERVED_EXTERNAL_SUBAGENT_NAMES = new Set([
|
|
98732
|
+
"antigravity",
|
|
98727
98733
|
"letta",
|
|
98728
98734
|
"claude-code",
|
|
98729
98735
|
"codex",
|
|
@@ -104932,6 +104938,9 @@ function isEmptyResponseError(detail) {
|
|
|
104932
104938
|
return false;
|
|
104933
104939
|
return detail.toLowerCase().includes(EMPTY_RESPONSE_DETAIL_FRAGMENT);
|
|
104934
104940
|
}
|
|
104941
|
+
function isProviderStreamTimeoutDetail(detail) {
|
|
104942
|
+
return typeof detail === "string" && /\bstream sent no output within|\bstream(?:ing)? (?:timed out|timeout)\b/i.test(detail);
|
|
104943
|
+
}
|
|
104935
104944
|
function isRetryableProviderErrorDetail(detail) {
|
|
104936
104945
|
if (isCloudflareEdge52xDetail(detail))
|
|
104937
104946
|
return true;
|
|
@@ -104954,7 +104963,7 @@ function shouldRetryRunMetadataError(errorType, detail) {
|
|
|
104954
104963
|
const nonRetryableErrorType = isNonRetryableRunErrorType(errorType);
|
|
104955
104964
|
const nonRetryableQuotaDetail = hasNonRetryableQuotaDetail(detail);
|
|
104956
104965
|
const retryable429Detail = typeof detail === "string" && RETRYABLE_429_PATTERN.test(detail);
|
|
104957
|
-
const retryableDetail = isRetryableProviderErrorDetail(detail);
|
|
104966
|
+
const retryableDetail = isRetryableProviderErrorDetail(detail) || isProviderStreamTimeoutDetail(detail);
|
|
104958
104967
|
const nonRetryableDetail = isNonRetryableProviderErrorDetail(detail);
|
|
104959
104968
|
if (nonRetryableErrorType)
|
|
104960
104969
|
return false;
|
|
@@ -109348,6 +109357,13 @@ var exports_pi_stream_adapter = {};
|
|
|
109348
109357
|
__export(exports_pi_stream_adapter, {
|
|
109349
109358
|
PiStreamAdapter: () => PiStreamAdapter
|
|
109350
109359
|
});
|
|
109360
|
+
function inputAfterCompaction(input, compaction) {
|
|
109361
|
+
return {
|
|
109362
|
+
...input,
|
|
109363
|
+
uiMessages: compaction.uiMessages,
|
|
109364
|
+
systemPrompt: compaction.systemPrompt ?? input.systemPrompt
|
|
109365
|
+
};
|
|
109366
|
+
}
|
|
109351
109367
|
async function sleepWithAbort(delayMs, abortSignal) {
|
|
109352
109368
|
if (delayMs <= 0)
|
|
109353
109369
|
return;
|
|
@@ -109556,12 +109572,7 @@ class PiStreamAdapter {
|
|
|
109556
109572
|
if (!shouldCompactForContextPressure({ contextTokens, contextWindow })) {
|
|
109557
109573
|
return null;
|
|
109558
109574
|
}
|
|
109559
|
-
return this.onContextPressure(input, {
|
|
109560
|
-
contextTokens,
|
|
109561
|
-
contextWindow,
|
|
109562
|
-
phase: "preflight",
|
|
109563
|
-
source: "estimate"
|
|
109564
|
-
});
|
|
109575
|
+
return this.onContextPressure(input, { contextTokens, contextWindow });
|
|
109565
109576
|
}
|
|
109566
109577
|
async* streamOnce(input) {
|
|
109567
109578
|
const tools = toPiTools(input.clientTools);
|
|
@@ -109659,7 +109670,6 @@ class PiStreamAdapter {
|
|
|
109659
109670
|
const result = this.runStream(resolved.model, context3, options);
|
|
109660
109671
|
let streamError;
|
|
109661
109672
|
let finalMessage;
|
|
109662
|
-
let finalLocalMessage;
|
|
109663
109673
|
for await (const part of result) {
|
|
109664
109674
|
if (part.type === "error") {
|
|
109665
109675
|
const error3 = new PiProviderError(part.error);
|
|
@@ -109673,8 +109683,7 @@ class PiStreamAdapter {
|
|
|
109673
109683
|
}
|
|
109674
109684
|
if (part.type === "done") {
|
|
109675
109685
|
finalMessage = part.message;
|
|
109676
|
-
|
|
109677
|
-
yield providerLocalMessage(finalLocalMessage);
|
|
109686
|
+
yield providerLocalMessage(toLocalAssistantMessage(part.message, input));
|
|
109678
109687
|
}
|
|
109679
109688
|
yield providerStreamPart(part, resolved.model);
|
|
109680
109689
|
}
|
|
@@ -109694,26 +109703,6 @@ class PiStreamAdapter {
|
|
|
109694
109703
|
if (finalMessage.stopReason === "error" || finalMessage.stopReason === "aborted") {
|
|
109695
109704
|
throw new PiProviderError(finalMessage);
|
|
109696
109705
|
}
|
|
109697
|
-
if (this.onContextPressure) {
|
|
109698
|
-
const usageContextTokens = contextTokensFromUsage(finalMessage.usage);
|
|
109699
|
-
const contextTokens = usageContextTokens ?? estimateProviderContextTokens({
|
|
109700
|
-
...input,
|
|
109701
|
-
uiMessages: [
|
|
109702
|
-
...input.uiMessages,
|
|
109703
|
-
finalLocalMessage ?? toLocalAssistantMessage(finalMessage, input)
|
|
109704
|
-
]
|
|
109705
|
-
});
|
|
109706
|
-
const contextWindow = resolved.model.contextWindow;
|
|
109707
|
-
const compaction = shouldCompactForContextPressure({ contextTokens, contextWindow }) && contextTokens !== undefined ? await this.onContextPressure(input, {
|
|
109708
|
-
contextTokens,
|
|
109709
|
-
contextWindow,
|
|
109710
|
-
phase: "post_turn",
|
|
109711
|
-
source: usageContextTokens === undefined ? "estimate" : "usage"
|
|
109712
|
-
}) : null;
|
|
109713
|
-
if (compaction) {
|
|
109714
|
-
yield* this.emitCompactionChunks(compaction, "context_window_limit");
|
|
109715
|
-
}
|
|
109716
|
-
}
|
|
109717
109706
|
} catch (error3) {
|
|
109718
109707
|
if (!llmEnded) {
|
|
109719
109708
|
const endError = llmEndErrorFromError(error3);
|
|
@@ -109738,7 +109727,7 @@ class PiStreamAdapter {
|
|
|
109738
109727
|
preflightCompactionChecked = true;
|
|
109739
109728
|
const compaction = await this.compactBeforeProviderCall(activeInput);
|
|
109740
109729
|
if (compaction) {
|
|
109741
|
-
activeInput =
|
|
109730
|
+
activeInput = inputAfterCompaction(activeInput, compaction);
|
|
109742
109731
|
yield* this.emitCompactionChunks(compaction, "context_window_limit");
|
|
109743
109732
|
continue;
|
|
109744
109733
|
}
|
|
@@ -109763,7 +109752,7 @@ class PiStreamAdapter {
|
|
|
109763
109752
|
if (!compaction)
|
|
109764
109753
|
throw error3;
|
|
109765
109754
|
contextOverflowCompactions += 1;
|
|
109766
|
-
activeInput =
|
|
109755
|
+
activeInput = inputAfterCompaction(activeInput, compaction);
|
|
109767
109756
|
yield* this.emitCompactionChunks(compaction, "context_window_overflow");
|
|
109768
109757
|
continue;
|
|
109769
109758
|
}
|
|
@@ -109784,7 +109773,7 @@ class PiStreamAdapter {
|
|
|
109784
109773
|
}
|
|
109785
109774
|
if (compaction) {
|
|
109786
109775
|
contextOverflowCompactions += 1;
|
|
109787
|
-
activeInput =
|
|
109776
|
+
activeInput = inputAfterCompaction(activeInput, compaction);
|
|
109788
109777
|
yield* this.emitCompactionChunks(compaction, "context_window_overflow");
|
|
109789
109778
|
continue;
|
|
109790
109779
|
}
|
|
@@ -110439,11 +110428,7 @@ var init_local_backend = __esm(() => {
|
|
|
110439
110428
|
}
|
|
110440
110429
|
async compactAfterContextOverflow(input, _error) {
|
|
110441
110430
|
const result = await this.compactLocalConversation(input.conversationId, input.agentId, "context_window_overflow", undefined, input);
|
|
110442
|
-
return
|
|
110443
|
-
uiMessages: this.store.listLocalMessages(input.conversationId, input.agentId),
|
|
110444
|
-
summary: result.summary,
|
|
110445
|
-
stats: result.stats
|
|
110446
|
-
};
|
|
110431
|
+
return this.turnCompaction(input, result);
|
|
110447
110432
|
}
|
|
110448
110433
|
async compactForContextPressure(input, pressure) {
|
|
110449
110434
|
const messageTokens = estimateLocalMessageTokens2(this.store.listLocalMessages(input.conversationId, input.agentId));
|
|
@@ -110451,10 +110436,16 @@ var init_local_backend = __esm(() => {
|
|
|
110451
110436
|
const result = await runLocalPressureCompaction(() => this.compactLocalConversation(input.conversationId, input.agentId, "context_window_limit", undefined, input, (contextCompactionThreshold(pressure.contextWindow) ?? 0) - fixedTokens));
|
|
110452
110437
|
if (!result)
|
|
110453
110438
|
return null;
|
|
110439
|
+
return this.turnCompaction(input, result);
|
|
110440
|
+
}
|
|
110441
|
+
turnCompaction(input, result) {
|
|
110454
110442
|
return {
|
|
110455
110443
|
uiMessages: this.store.listLocalMessages(input.conversationId, input.agentId),
|
|
110456
110444
|
summary: result.summary,
|
|
110457
|
-
stats: result.stats
|
|
110445
|
+
stats: result.stats,
|
|
110446
|
+
...result.systemPrompt !== undefined ? {
|
|
110447
|
+
systemPrompt: appendAvailableSkillsBlock(result.systemPrompt, input.clientSkills)
|
|
110448
|
+
} : {}
|
|
110458
110449
|
};
|
|
110459
110450
|
}
|
|
110460
110451
|
effectiveContextWindow(conversationId, agentId) {
|
|
@@ -110491,8 +110482,16 @@ var init_local_backend = __esm(() => {
|
|
|
110491
110482
|
async compactLocalConversation(conversationId, agentId, trigger, body, turn, maxMessageTokens) {
|
|
110492
110483
|
await this.emitCompactStart(conversationId, agentId, trigger);
|
|
110493
110484
|
const result = await this.compactLocalConversationInner(conversationId, agentId, trigger, body, turn, maxMessageTokens);
|
|
110485
|
+
const systemPrompt = await this.recompileMemoryAfterCompaction(conversationId, agentId);
|
|
110494
110486
|
await this.emitCompactEnd(conversationId, agentId, trigger, result.stats);
|
|
110495
|
-
return result;
|
|
110487
|
+
return systemPrompt === undefined ? result : { ...result, systemPrompt };
|
|
110488
|
+
}
|
|
110489
|
+
async recompileMemoryAfterCompaction(conversationId, agentId) {
|
|
110490
|
+
if (this.store.isAgentFreeConversation(conversationId) || !this.isMemfsEnabledForAgent(agentId)) {
|
|
110491
|
+
return;
|
|
110492
|
+
}
|
|
110493
|
+
const compiled = await this.compileAndMaybePersistSystemPrompt(conversationId, agentId, { dryRun: false });
|
|
110494
|
+
return compiled.content;
|
|
110496
110495
|
}
|
|
110497
110496
|
async compactLocalConversationInner(conversationId, agentId, trigger, body, turn, maxMessageTokens) {
|
|
110498
110497
|
const agent = this.effectiveAgentForConversation(conversationId, agentId);
|
|
@@ -110503,27 +110502,20 @@ var init_local_backend = __esm(() => {
|
|
|
110503
110502
|
const self2 = isLocalSelfCompactionMode(settings.mode) ? await this.selfCompactionContext(conversationId, agentId, turn) : undefined;
|
|
110504
110503
|
if (isLocalSlidingWindowMode(settings.mode)) {
|
|
110505
110504
|
try {
|
|
110506
|
-
const
|
|
110507
|
-
if (
|
|
110508
|
-
|
|
110509
|
-
dryRun: false
|
|
110510
|
-
});
|
|
110511
|
-
return result2;
|
|
110505
|
+
const result = await this.compactLocalConversationPass(conversationId, agentId, agent, trigger, settings, self2);
|
|
110506
|
+
if (result.stats.context_window === undefined || result.stats.context_tokens_after === undefined || result.stats.context_tokens_after < result.stats.context_window) {
|
|
110507
|
+
return result;
|
|
110512
110508
|
}
|
|
110513
110509
|
} catch (error3) {
|
|
110514
110510
|
if (!isLocalSlidingWindowCompactionPlanningError(error3))
|
|
110515
110511
|
throw error3;
|
|
110516
110512
|
}
|
|
110517
110513
|
}
|
|
110518
|
-
|
|
110514
|
+
return this.compactLocalConversationPass(conversationId, agentId, agent, trigger, {
|
|
110519
110515
|
...settings,
|
|
110520
110516
|
mode: self2 ? "self_compact_all" : "all",
|
|
110521
110517
|
prompt: settings.prompt
|
|
110522
110518
|
}, self2);
|
|
110523
|
-
await this.compileAndMaybePersistSystemPrompt(conversationId, agentId, {
|
|
110524
|
-
dryRun: false
|
|
110525
|
-
});
|
|
110526
|
-
return result;
|
|
110527
110519
|
}
|
|
110528
110520
|
async compactLocalConversationPass(conversationId, agentId, agent, trigger, settings, self2) {
|
|
110529
110521
|
const slidingWindow = isLocalSlidingWindowMode(settings.mode);
|
|
@@ -203477,7 +203469,7 @@ var init_mcp_client = __esm(() => {
|
|
|
203477
203469
|
init_streamableHttp();
|
|
203478
203470
|
DEFAULT_CLIENT_INFO = {
|
|
203479
203471
|
name: "letta-code",
|
|
203480
|
-
version: "0.34.
|
|
203472
|
+
version: "0.34.72"
|
|
203481
203473
|
};
|
|
203482
203474
|
});
|
|
203483
203475
|
|
|
@@ -207825,6 +207817,11 @@ A powerful search tool built on ripgrep
|
|
|
207825
207817
|
`;
|
|
207826
207818
|
var init_Grep = () => {};
|
|
207827
207819
|
|
|
207820
|
+
// src/tools/descriptions/ListAgents.md
|
|
207821
|
+
var ListAgents_default = `List unarchived subagents launched by the current conversation, most recently updated first. Each entry includes timestamps, status, and the address for SendAgentMessage. Returns up to 20 entries by default. Filter by running, completed, failed, or stopped. When has_more is true, pass next_cursor as cursor to get the next page with the same status filter.
|
|
207822
|
+
`;
|
|
207823
|
+
var init_ListAgents = () => {};
|
|
207824
|
+
|
|
207828
207825
|
// src/tools/descriptions/LS.md
|
|
207829
207826
|
var LS_default = `# LS
|
|
207830
207827
|
|
|
@@ -215839,6 +215836,37 @@ function excerptProgressText(value, max2) {
|
|
|
215839
215836
|
const line = value.replace(/\s+/g, " ").trim();
|
|
215840
215837
|
return line.length > max2 ? `${line.slice(0, max2)}…` : line;
|
|
215841
215838
|
}
|
|
215839
|
+
function observeSubagentState(id, observer) {
|
|
215840
|
+
const state2 = store2.agents.get(id);
|
|
215841
|
+
if (state2)
|
|
215842
|
+
stateObservers.set(state2, observer);
|
|
215843
|
+
}
|
|
215844
|
+
function captureSubagentStop(id) {
|
|
215845
|
+
const state2 = store2.agents.get(id);
|
|
215846
|
+
const observer = state2 && stateObservers.get(state2);
|
|
215847
|
+
return () => {
|
|
215848
|
+
if (!state2 || !observer)
|
|
215849
|
+
return;
|
|
215850
|
+
const current = store2.agents.get(id) ?? state2;
|
|
215851
|
+
observer({
|
|
215852
|
+
...current,
|
|
215853
|
+
stopOutcome: { attempt: current.stopAttempts ?? 0, kind: "stopped" }
|
|
215854
|
+
});
|
|
215855
|
+
};
|
|
215856
|
+
}
|
|
215857
|
+
function observeStateChange(previous, next, resultIdentity) {
|
|
215858
|
+
const observer = stateObservers.get(previous);
|
|
215859
|
+
if (!observer)
|
|
215860
|
+
return;
|
|
215861
|
+
stateObservers.set(next, observer);
|
|
215862
|
+
if (resultIdentity || previous.status !== next.status || previous.agentId !== next.agentId || previous.conversationId !== next.conversationId || previous.cancelPending !== next.cancelPending || previous.stopOutcome?.kind !== next.stopOutcome?.kind) {
|
|
215863
|
+
observer(resultIdentity ? {
|
|
215864
|
+
...next,
|
|
215865
|
+
agentId: next.agentId || resultIdentity.agentId,
|
|
215866
|
+
conversationId: resultIdentity.conversationId || next.conversationId
|
|
215867
|
+
} : next);
|
|
215868
|
+
}
|
|
215869
|
+
}
|
|
215842
215870
|
function updateSnapshot() {
|
|
215843
215871
|
const agents = Array.from(store2.agents.values());
|
|
215844
215872
|
const now2 = Date.now();
|
|
@@ -215949,8 +215977,14 @@ function updateSubagent(id, updates) {
|
|
|
215949
215977
|
const isNoop = keys2.every((k3) => agent[k3] === updates[k3]) && nextMax === agent.maxToolCallsSeen;
|
|
215950
215978
|
if (isNoop)
|
|
215951
215979
|
return;
|
|
215952
|
-
const updatedAgent = {
|
|
215980
|
+
const updatedAgent = {
|
|
215981
|
+
...agent,
|
|
215982
|
+
...updates,
|
|
215983
|
+
maxToolCallsSeen: nextMax,
|
|
215984
|
+
updatedAt: Date.now()
|
|
215985
|
+
};
|
|
215953
215986
|
store2.agents.set(id, updatedAgent);
|
|
215987
|
+
observeStateChange(agent, updatedAgent);
|
|
215954
215988
|
if (updatedAgent.status === "completed" || updatedAgent.status === "error") {
|
|
215955
215989
|
scheduleCompletedSubagentCleanup(id);
|
|
215956
215990
|
} else {
|
|
@@ -215973,6 +216007,7 @@ function addToolCall(subagentId, toolCallId, toolName2, toolArgs) {
|
|
|
215973
216007
|
maxToolCallsSeen: Math.max(agent.maxToolCallsSeen, agent.toolCalls.length + 1)
|
|
215974
216008
|
};
|
|
215975
216009
|
store2.agents.set(subagentId, updatedAgent);
|
|
216010
|
+
observeStateChange(agent, updatedAgent);
|
|
215976
216011
|
notifyListeners();
|
|
215977
216012
|
}
|
|
215978
216013
|
function addProgressText(subagentId, text2, now2 = () => new Date) {
|
|
@@ -215984,23 +216019,26 @@ function addProgressText(subagentId, text2, now2 = () => new Date) {
|
|
|
215984
216019
|
if (!excerpt || previous?.text === excerpt)
|
|
215985
216020
|
return;
|
|
215986
216021
|
const count = (agent.progressTextCount ?? 0) + 1;
|
|
215987
|
-
|
|
216022
|
+
const updatedAgent = {
|
|
215988
216023
|
...agent,
|
|
215989
216024
|
progressTexts: [
|
|
215990
216025
|
...agent.progressTexts ?? [],
|
|
215991
216026
|
{ id: `text-${count}`, at: now2().toISOString(), text: excerpt }
|
|
215992
216027
|
].slice(-MAX_PROGRESS_TEXTS),
|
|
215993
216028
|
progressTextCount: count
|
|
215994
|
-
}
|
|
216029
|
+
};
|
|
216030
|
+
store2.agents.set(subagentId, updatedAgent);
|
|
216031
|
+
observeStateChange(agent, updatedAgent);
|
|
215995
216032
|
notifyListeners();
|
|
215996
216033
|
}
|
|
215997
|
-
function completeSubagent(id, result2) {
|
|
216034
|
+
function completeSubagent(id, result2, resultIdentity) {
|
|
215998
216035
|
const agent = store2.agents.get(id);
|
|
215999
216036
|
if (!agent)
|
|
216000
216037
|
return;
|
|
216001
216038
|
const updatedAgent = {
|
|
216002
216039
|
...agent,
|
|
216003
216040
|
status: result2.success ? "completed" : "error",
|
|
216041
|
+
updatedAt: Date.now(),
|
|
216004
216042
|
error: result2.error,
|
|
216005
216043
|
stopFailed: undefined,
|
|
216006
216044
|
...result2.result !== undefined ? { result: result2.result } : {},
|
|
@@ -216010,6 +216048,7 @@ function completeSubagent(id, result2) {
|
|
|
216010
216048
|
maxToolCallsSeen: Math.max(agent.maxToolCallsSeen, agent.toolCalls.length)
|
|
216011
216049
|
};
|
|
216012
216050
|
store2.agents.set(id, updatedAgent);
|
|
216051
|
+
observeStateChange(agent, updatedAgent, resultIdentity);
|
|
216013
216052
|
scheduleCompletedSubagentCleanup(id);
|
|
216014
216053
|
notifyListeners();
|
|
216015
216054
|
}
|
|
@@ -216115,12 +216154,14 @@ function interruptActiveSubagents(errorMessage3, scope) {
|
|
|
216115
216154
|
const updatedAgent = {
|
|
216116
216155
|
...agent,
|
|
216117
216156
|
status: "error",
|
|
216157
|
+
updatedAt: Date.now(),
|
|
216118
216158
|
error: errorMessage3,
|
|
216119
216159
|
durationMs: Date.now() - agent.startTime,
|
|
216120
216160
|
...hook ? { cancelPending: true, stopAttempts: (agent.stopAttempts ?? 0) + 1 } : {},
|
|
216121
216161
|
stopFailed: undefined
|
|
216122
216162
|
};
|
|
216123
216163
|
store2.agents.set(id, updatedAgent);
|
|
216164
|
+
observeStateChange(agent, updatedAgent);
|
|
216124
216165
|
scheduleCompletedSubagentCleanup(id);
|
|
216125
216166
|
anyInterrupted = true;
|
|
216126
216167
|
}
|
|
@@ -216150,6 +216191,7 @@ function interruptStopFailedSubagents(errorMessage3, scope) {
|
|
|
216150
216191
|
stopFailed: undefined
|
|
216151
216192
|
};
|
|
216152
216193
|
store2.agents.set(id, updatedAgent);
|
|
216194
|
+
observeStateChange(agent, updatedAgent);
|
|
216153
216195
|
scheduleCompletedSubagentCleanup(id);
|
|
216154
216196
|
interrupted.push(id);
|
|
216155
216197
|
}
|
|
@@ -216193,7 +216235,7 @@ function emitStreamEvent(subagentId, event) {
|
|
|
216193
216235
|
listener(subagentId, event);
|
|
216194
216236
|
}
|
|
216195
216237
|
}
|
|
216196
|
-
var PROGRESS_TEXT_CHARS = 300, MAX_PROGRESS_TEXTS = 20, store2, cachedSnapshot, cachedLifecycleItems, DEFAULT_COMPLETED_SUBAGENT_RETENTION_MS = 30000, completedSubagentRetentionMs, DEFAULT_PUBLISHED_RESULT_RETENTION_MS, publishedResultRetentionMs, completedSubagentCleanupTimers, subagentCounter = 0, subagentAbortHooks, streamEventListeners;
|
|
216238
|
+
var PROGRESS_TEXT_CHARS = 300, MAX_PROGRESS_TEXTS = 20, store2, stateObservers, cachedSnapshot, cachedLifecycleItems, DEFAULT_COMPLETED_SUBAGENT_RETENTION_MS = 30000, completedSubagentRetentionMs, DEFAULT_PUBLISHED_RESULT_RETENTION_MS, publishedResultRetentionMs, completedSubagentCleanupTimers, subagentCounter = 0, subagentAbortHooks, streamEventListeners;
|
|
216197
216239
|
var init_subagent_state = __esm(() => {
|
|
216198
216240
|
init_subagent_events();
|
|
216199
216241
|
store2 = {
|
|
@@ -216201,6 +216243,7 @@ var init_subagent_state = __esm(() => {
|
|
|
216201
216243
|
expanded: false,
|
|
216202
216244
|
listeners: new Set
|
|
216203
216245
|
};
|
|
216246
|
+
stateObservers = new WeakMap;
|
|
216204
216247
|
cachedSnapshot = {
|
|
216205
216248
|
agents: [],
|
|
216206
216249
|
expanded: false
|
|
@@ -221357,6 +221400,7 @@ function getDefaultDecision(toolName2, toolArgs, modTools = getAvailableModTools
|
|
|
221357
221400
|
"TaskGet",
|
|
221358
221401
|
"TaskList",
|
|
221359
221402
|
"TaskUpdate",
|
|
221403
|
+
"ListAgents",
|
|
221360
221404
|
"read_artifact_file",
|
|
221361
221405
|
"write_artifact_file",
|
|
221362
221406
|
"Wake",
|
|
@@ -232527,6 +232571,257 @@ var init_grep = __esm(() => {
|
|
|
232527
232571
|
execFileAsync10 = promisify14(execFile14);
|
|
232528
232572
|
});
|
|
232529
232573
|
|
|
232574
|
+
// src/backend/api/subagents.ts
|
|
232575
|
+
function usesCloudSubagents() {
|
|
232576
|
+
return resolveBackendMode() === "api" && isCloudServerUrl();
|
|
232577
|
+
}
|
|
232578
|
+
function listCloudSubagentsPage(conversationId, actingUserId, options) {
|
|
232579
|
+
return apiRequest("GET", "/v1/subagents", undefined, {
|
|
232580
|
+
actingUserId,
|
|
232581
|
+
signal: AbortSignal.timeout(15000),
|
|
232582
|
+
query: {
|
|
232583
|
+
parent_conversation_id: conversationId,
|
|
232584
|
+
archived: options.archived ?? false,
|
|
232585
|
+
after: options.after,
|
|
232586
|
+
limit: options.limit,
|
|
232587
|
+
status: options.status
|
|
232588
|
+
}
|
|
232589
|
+
});
|
|
232590
|
+
}
|
|
232591
|
+
async function listCloudSubagents(conversationId, actingUserId, archived = false) {
|
|
232592
|
+
const records = [];
|
|
232593
|
+
let after2;
|
|
232594
|
+
while (true) {
|
|
232595
|
+
const page = await listCloudSubagentsPage(conversationId, actingUserId, {
|
|
232596
|
+
archived,
|
|
232597
|
+
after: after2,
|
|
232598
|
+
limit: 200
|
|
232599
|
+
});
|
|
232600
|
+
records.push(...page);
|
|
232601
|
+
if (page.length < 200)
|
|
232602
|
+
return records;
|
|
232603
|
+
after2 = page.at(-1)?.subagent_id;
|
|
232604
|
+
}
|
|
232605
|
+
}
|
|
232606
|
+
function queueSubagentUpdates(record4, update2) {
|
|
232607
|
+
let pending2 = record4.catch(() => {
|
|
232608
|
+
debugLog("subagents", "Could not resolve the persisted subagent");
|
|
232609
|
+
return;
|
|
232610
|
+
});
|
|
232611
|
+
return (change) => {
|
|
232612
|
+
pending2 = pending2.then(async (id) => {
|
|
232613
|
+
if (id) {
|
|
232614
|
+
try {
|
|
232615
|
+
await update2(id, change);
|
|
232616
|
+
} catch {
|
|
232617
|
+
debugLog("subagents", "Could not update the persisted subagent");
|
|
232618
|
+
}
|
|
232619
|
+
}
|
|
232620
|
+
return id;
|
|
232621
|
+
});
|
|
232622
|
+
};
|
|
232623
|
+
}
|
|
232624
|
+
function createSubagentWriter(input, actingUserId) {
|
|
232625
|
+
const record4 = apiRequest("POST", "/v1/subagents", { ...input }, {
|
|
232626
|
+
actingUserId,
|
|
232627
|
+
signal: AbortSignal.timeout(15000)
|
|
232628
|
+
}).then((row) => row.subagent_id);
|
|
232629
|
+
return subagentWriter(record4, actingUserId);
|
|
232630
|
+
}
|
|
232631
|
+
function subagentWriter(record4, actingUserId) {
|
|
232632
|
+
return queueSubagentUpdates(record4, (id, change) => apiRequest("PATCH", `/v1/subagents/${encodeURIComponent(id)}`, { ...change }, {
|
|
232633
|
+
actingUserId,
|
|
232634
|
+
signal: AbortSignal.timeout(15000)
|
|
232635
|
+
}));
|
|
232636
|
+
}
|
|
232637
|
+
function resumeSubagentWriter(conversationId, target, actingUserId) {
|
|
232638
|
+
if (!usesCloudSubagents() || conversationId === "default" || !target.conversation_id && !target.worker_session_id)
|
|
232639
|
+
return;
|
|
232640
|
+
const matches3 = (record5) => target.worker_session_id ? record5.worker_session_id === target.worker_session_id : record5.conversation_id === target.conversation_id;
|
|
232641
|
+
const record4 = (async () => {
|
|
232642
|
+
for (const archived of [false, true]) {
|
|
232643
|
+
const records = await listCloudSubagents(conversationId, actingUserId, archived);
|
|
232644
|
+
const match3 = records.filter(matches3).sort((a2, b3) => b3.updated_at.localeCompare(a2.updated_at))[0];
|
|
232645
|
+
if (match3)
|
|
232646
|
+
return match3.subagent_id;
|
|
232647
|
+
}
|
|
232648
|
+
return;
|
|
232649
|
+
})();
|
|
232650
|
+
const update2 = subagentWriter(record4, actingUserId);
|
|
232651
|
+
update2({ status: "running", archived: false });
|
|
232652
|
+
return { update: update2, found: record4.then(Boolean, () => false) };
|
|
232653
|
+
}
|
|
232654
|
+
var init_subagents3 = __esm(() => {
|
|
232655
|
+
init_backend_mode();
|
|
232656
|
+
init_debug();
|
|
232657
|
+
init_request();
|
|
232658
|
+
init_server_url();
|
|
232659
|
+
});
|
|
232660
|
+
|
|
232661
|
+
// src/tools/schemas/ListAgents.json
|
|
232662
|
+
var ListAgents_default2;
|
|
232663
|
+
var init_ListAgents2 = __esm(() => {
|
|
232664
|
+
ListAgents_default2 = {
|
|
232665
|
+
type: "object",
|
|
232666
|
+
properties: {
|
|
232667
|
+
limit: {
|
|
232668
|
+
type: "integer",
|
|
232669
|
+
minimum: 1,
|
|
232670
|
+
maximum: 100,
|
|
232671
|
+
default: 20,
|
|
232672
|
+
description: "Maximum number of subagents to return."
|
|
232673
|
+
},
|
|
232674
|
+
cursor: {
|
|
232675
|
+
type: "string",
|
|
232676
|
+
minLength: 1,
|
|
232677
|
+
description: "The next_cursor from the previous page. Keep the same status filter."
|
|
232678
|
+
},
|
|
232679
|
+
status: {
|
|
232680
|
+
type: "string",
|
|
232681
|
+
enum: ["running", "completed", "failed", "stopped"],
|
|
232682
|
+
description: "Only return subagents with this status."
|
|
232683
|
+
}
|
|
232684
|
+
},
|
|
232685
|
+
additionalProperties: false
|
|
232686
|
+
};
|
|
232687
|
+
});
|
|
232688
|
+
|
|
232689
|
+
// src/tools/impl/subagent-persistence.ts
|
|
232690
|
+
function createLaunchSubagentObserver(scope, args, description, prompt, harness, forkContext, computer, cloud) {
|
|
232691
|
+
if (!scope || scope.conversationId === "default" || !usesCloudSubagents())
|
|
232692
|
+
return;
|
|
232693
|
+
const actingUserId = getRuntimeActingUserAttribution();
|
|
232694
|
+
const input = {
|
|
232695
|
+
parent_agent_id: scope.agentId,
|
|
232696
|
+
parent_conversation_id: scope.conversationId,
|
|
232697
|
+
description,
|
|
232698
|
+
prompt,
|
|
232699
|
+
harness,
|
|
232700
|
+
subagent_type: args.subagent_type ?? null,
|
|
232701
|
+
fork_context: forkContext,
|
|
232702
|
+
model_config: args.model ? { model: args.model } : null,
|
|
232703
|
+
agent_id: args.agent_id ?? null,
|
|
232704
|
+
conversation_id: args.conversation_id === "default" ? null : args.conversation_id ?? null,
|
|
232705
|
+
computer: computer ?? null,
|
|
232706
|
+
repositories: cloud?.githubRepositories?.map(({ owner, repo, commit }) => `${owner}/${repo}${commit ? `@${commit}` : ""}`) ?? null,
|
|
232707
|
+
sandbox_size: cloud?.sandboxSize ?? null,
|
|
232708
|
+
mcp_config: args.mcp ?? null,
|
|
232709
|
+
worker_session_id: null,
|
|
232710
|
+
status: "running"
|
|
232711
|
+
};
|
|
232712
|
+
return () => {
|
|
232713
|
+
const write = createSubagentWriter(input, actingUserId);
|
|
232714
|
+
let previous;
|
|
232715
|
+
let stopped = false;
|
|
232716
|
+
let resolvedLinks = {};
|
|
232717
|
+
return (state2) => {
|
|
232718
|
+
const links2 = harness === "letta" ? {
|
|
232719
|
+
...state2.agentId ? { agent_id: state2.agentId } : {},
|
|
232720
|
+
...state2.conversationId && state2.conversationId !== "default" ? { conversation_id: state2.conversationId } : {}
|
|
232721
|
+
} : state2.agentId ? { worker_session_id: state2.agentId } : {};
|
|
232722
|
+
const status = stopped ? "stopped" : persistedSubagentStatus(state2);
|
|
232723
|
+
stopped = status === "stopped";
|
|
232724
|
+
resolvedLinks = { ...resolvedLinks, ...links2 };
|
|
232725
|
+
const change = { ...resolvedLinks, status };
|
|
232726
|
+
const serialized = JSON.stringify(change);
|
|
232727
|
+
if (serialized === previous)
|
|
232728
|
+
return;
|
|
232729
|
+
previous = serialized;
|
|
232730
|
+
write(change);
|
|
232731
|
+
};
|
|
232732
|
+
};
|
|
232733
|
+
}
|
|
232734
|
+
function persistedSubagentStatus(state2) {
|
|
232735
|
+
if (state2.stopOutcome?.kind === "stopped")
|
|
232736
|
+
return "stopped";
|
|
232737
|
+
if (state2.status === "error" && !state2.cancelPending)
|
|
232738
|
+
return "failed";
|
|
232739
|
+
if (state2.status === "completed")
|
|
232740
|
+
return "completed";
|
|
232741
|
+
return "running";
|
|
232742
|
+
}
|
|
232743
|
+
var init_subagent_persistence = __esm(() => {
|
|
232744
|
+
init_subagents3();
|
|
232745
|
+
init_runtime_context();
|
|
232746
|
+
});
|
|
232747
|
+
|
|
232748
|
+
// src/tools/impl/list-agents.ts
|
|
232749
|
+
function formatPage(rows, limit4) {
|
|
232750
|
+
const agents = rows.slice(0, limit4);
|
|
232751
|
+
const has_more = rows.length > limit4;
|
|
232752
|
+
return {
|
|
232753
|
+
agents,
|
|
232754
|
+
has_more,
|
|
232755
|
+
next_cursor: has_more ? agents.at(-1)?.subagent_id ?? null : null
|
|
232756
|
+
};
|
|
232757
|
+
}
|
|
232758
|
+
async function list_agents({
|
|
232759
|
+
limit: limit4 = 20,
|
|
232760
|
+
cursor,
|
|
232761
|
+
status
|
|
232762
|
+
} = {}) {
|
|
232763
|
+
if (!Number.isInteger(limit4) || limit4 < 1 || limit4 > 100) {
|
|
232764
|
+
throw new Error("ListAgents limit must be an integer between 1 and 100.");
|
|
232765
|
+
}
|
|
232766
|
+
if (status !== undefined && !ListAgents_default2.properties.status.enum.includes(status)) {
|
|
232767
|
+
throw new Error("ListAgents status must be running, completed, failed, or stopped.");
|
|
232768
|
+
}
|
|
232769
|
+
const scope = resolveNotificationScope();
|
|
232770
|
+
if (!scope)
|
|
232771
|
+
throw new Error("ListAgents requires a calling conversation.");
|
|
232772
|
+
if (usesCloudSubagents()) {
|
|
232773
|
+
if (scope.conversationId === "default")
|
|
232774
|
+
return formatPage([], limit4);
|
|
232775
|
+
const rows2 = await listCloudSubagentsPage(scope.conversationId, getRuntimeActingUserAttribution(), { after: cursor, limit: limit4 + 1, status });
|
|
232776
|
+
return formatPage(rows2.map(({
|
|
232777
|
+
subagent_id,
|
|
232778
|
+
description,
|
|
232779
|
+
harness,
|
|
232780
|
+
subagent_type,
|
|
232781
|
+
status: status2,
|
|
232782
|
+
agent_id,
|
|
232783
|
+
conversation_id,
|
|
232784
|
+
worker_session_id,
|
|
232785
|
+
created_at,
|
|
232786
|
+
updated_at
|
|
232787
|
+
}) => ({
|
|
232788
|
+
subagent_id,
|
|
232789
|
+
description,
|
|
232790
|
+
harness,
|
|
232791
|
+
subagent_type,
|
|
232792
|
+
status: status2,
|
|
232793
|
+
agent_id: worker_session_id ?? agent_id,
|
|
232794
|
+
conversation_id,
|
|
232795
|
+
worker_session_id,
|
|
232796
|
+
created_at,
|
|
232797
|
+
updated_at
|
|
232798
|
+
})), limit4);
|
|
232799
|
+
}
|
|
232800
|
+
const rows = getSubagents().filter((agent) => agent.parentAgentId === scope.agentId && agent.parentConversationId === scope.conversationId).map((agent) => ({
|
|
232801
|
+
subagent_id: agent.id,
|
|
232802
|
+
description: agent.description,
|
|
232803
|
+
subagent_type: agent.type,
|
|
232804
|
+
status: persistedSubagentStatus(agent),
|
|
232805
|
+
agent_id: agent.agentId ?? null,
|
|
232806
|
+
conversation_id: agent.conversationId ?? null,
|
|
232807
|
+
created_at: new Date(agent.startTime).toISOString(),
|
|
232808
|
+
updated_at: new Date(agent.updatedAt ?? agent.startTime).toISOString()
|
|
232809
|
+
})).sort((a2, b3) => b3.updated_at.localeCompare(a2.updated_at) || b3.subagent_id.localeCompare(a2.subagent_id));
|
|
232810
|
+
const cursorIndex = cursor ? rows.findIndex((row) => row.subagent_id === cursor) : -1;
|
|
232811
|
+
if (cursor && cursorIndex === -1)
|
|
232812
|
+
return formatPage([], limit4);
|
|
232813
|
+
const page = rows.slice(cursorIndex + 1).filter((row) => !status || row.status === status);
|
|
232814
|
+
return formatPage(page, limit4);
|
|
232815
|
+
}
|
|
232816
|
+
var init_list_agents = __esm(() => {
|
|
232817
|
+
init_subagent_state();
|
|
232818
|
+
init_subagents3();
|
|
232819
|
+
init_runtime_context();
|
|
232820
|
+
init_ListAgents2();
|
|
232821
|
+
init_task_notifications();
|
|
232822
|
+
init_subagent_persistence();
|
|
232823
|
+
});
|
|
232824
|
+
|
|
232530
232825
|
// node_modules/picomatch/lib/constants.js
|
|
232531
232826
|
var require_constants2 = __commonJS((exports, module) => {
|
|
232532
232827
|
var path28 = __require("path");
|
|
@@ -234079,6 +234374,7 @@ __export(exports_environments3, {
|
|
|
234079
234374
|
environmentMatchesSelector: () => environmentMatchesSelector,
|
|
234080
234375
|
describeEnvironment: () => describeEnvironment,
|
|
234081
234376
|
createAgentSandbox: () => createAgentSandbox,
|
|
234377
|
+
WorkerSandboxExpiredError: () => WorkerSandboxExpiredError,
|
|
234082
234378
|
SUBAGENT_CLOUD_OPTIONS_ENV: () => SUBAGENT_CLOUD_OPTIONS_ENV,
|
|
234083
234379
|
ComputerResolutionError: () => ComputerResolutionError
|
|
234084
234380
|
});
|
|
@@ -234098,17 +234394,39 @@ async function sendEnvironmentMessage(connectionId, body3) {
|
|
|
234098
234394
|
async function getEnvironmentConnection(deviceId) {
|
|
234099
234395
|
return apiRequest("GET", `/v1/environments/${encodeURIComponent(deviceId)}`);
|
|
234100
234396
|
}
|
|
234397
|
+
function isSandboxExpiredResponse(error4) {
|
|
234398
|
+
if (!(error4 instanceof ApiRequestError))
|
|
234399
|
+
return false;
|
|
234400
|
+
if (error4.status === 410)
|
|
234401
|
+
return true;
|
|
234402
|
+
try {
|
|
234403
|
+
return JSON.parse(error4.responseText)?.code === "SANDBOX_EXPIRED";
|
|
234404
|
+
} catch {
|
|
234405
|
+
return false;
|
|
234406
|
+
}
|
|
234407
|
+
}
|
|
234101
234408
|
async function createAgentSandbox(agentId, options = {}, request3 = apiRequest) {
|
|
234102
234409
|
const conversationId = options.conversationId === "default" ? undefined : options.conversationId;
|
|
234103
|
-
|
|
234104
|
-
|
|
234105
|
-
|
|
234106
|
-
|
|
234107
|
-
|
|
234108
|
-
|
|
234109
|
-
|
|
234110
|
-
|
|
234111
|
-
|
|
234410
|
+
let sandbox;
|
|
234411
|
+
try {
|
|
234412
|
+
sandbox = await request3("POST", `/v1/agents/${encodeURIComponent(agentId)}/sandboxes`, {
|
|
234413
|
+
...conversationId && { conversationId },
|
|
234414
|
+
...options.resumeOnly && { resumeOnly: true },
|
|
234415
|
+
...options.githubRepositories !== undefined && {
|
|
234416
|
+
githubRepositories: options.githubRepositories
|
|
234417
|
+
},
|
|
234418
|
+
...options.sandboxSize !== undefined && {
|
|
234419
|
+
sandboxSize: options.sandboxSize
|
|
234420
|
+
}
|
|
234421
|
+
});
|
|
234422
|
+
} catch (error4) {
|
|
234423
|
+
if (options.resumeOnly && isSandboxExpiredResponse(error4))
|
|
234424
|
+
throw new WorkerSandboxExpiredError;
|
|
234425
|
+
throw error4;
|
|
234426
|
+
}
|
|
234427
|
+
if (options.resumeOnly && sandbox.resumed === false)
|
|
234428
|
+
throw new WorkerSandboxExpiredError;
|
|
234429
|
+
return sandbox;
|
|
234112
234430
|
}
|
|
234113
234431
|
function isEnvironmentOnline(environment) {
|
|
234114
234432
|
return typeof environment.connectionId === "string" && environment.connectionId.length > 0 && typeof environment.lastHeartbeat === "number" && Date.now() - environment.lastHeartbeat < 120000;
|
|
@@ -234165,8 +234483,17 @@ async function resolveEnvironmentConnectionId(selector, list = listEnvironments)
|
|
|
234165
234483
|
async function resolveAgentSandboxConnectionId(agentId, options = {}) {
|
|
234166
234484
|
const timeoutMs = options.timeoutMs ?? 3 * 60000;
|
|
234167
234485
|
const pollIntervalMs = options.pollIntervalMs ?? 2000;
|
|
234168
|
-
|
|
234169
|
-
|
|
234486
|
+
let deviceId;
|
|
234487
|
+
let connectionName;
|
|
234488
|
+
try {
|
|
234489
|
+
const sandbox = await createAgentSandbox(agentId, options);
|
|
234490
|
+
deviceId = sandbox.deviceId || `sandbox-${agentId}`;
|
|
234491
|
+
connectionName = sandbox.connectionName;
|
|
234492
|
+
} catch (error4) {
|
|
234493
|
+
if (error4 instanceof WorkerSandboxExpiredError)
|
|
234494
|
+
throw error4;
|
|
234495
|
+
throw new ComputerResolutionError("cloud_sandbox_create_failed", error4 instanceof Error ? error4.message : String(error4), error4);
|
|
234496
|
+
}
|
|
234170
234497
|
const deadline = Date.now() + timeoutMs;
|
|
234171
234498
|
let lastEnvironment = null;
|
|
234172
234499
|
let lastError = null;
|
|
@@ -234183,9 +234510,9 @@ async function resolveAgentSandboxConnectionId(agentId, options = {}) {
|
|
|
234183
234510
|
await new Promise((resolve33) => setTimeout(resolve33, pollIntervalMs));
|
|
234184
234511
|
}
|
|
234185
234512
|
if (lastEnvironment) {
|
|
234186
|
-
throw new
|
|
234513
|
+
throw new ComputerResolutionError("cloud_sandbox_online_timeout", `Timed out waiting for cloud sandbox ${connectionName} to come online. Last status: ${describeEnvironment(lastEnvironment)}`, lastError);
|
|
234187
234514
|
}
|
|
234188
|
-
throw new
|
|
234515
|
+
throw new ComputerResolutionError("cloud_sandbox_register_timeout", `Timed out waiting for cloud sandbox ${connectionName} to register${lastError instanceof Error ? `: ${lastError.message}` : ""}`, lastError);
|
|
234189
234516
|
}
|
|
234190
234517
|
function getTeleportStatus(agentId, conversationId, teleportId, request3 = apiRequest) {
|
|
234191
234518
|
return request3("GET", `/v1/environments/runtimes/${encodeURIComponent(agentId)}/${encodeURIComponent(conversationId)}/teleports/${encodeURIComponent(teleportId)}`, undefined, { signal: AbortSignal.timeout(5000) });
|
|
@@ -234196,15 +234523,27 @@ async function teleportToEnvironment(agentId, conversationId, targetConnectionId
|
|
|
234196
234523
|
idempotencyKey: randomUUID37()
|
|
234197
234524
|
});
|
|
234198
234525
|
}
|
|
234199
|
-
var SUBAGENT_CLOUD_OPTIONS_ENV = "LETTA_SUBAGENT_CLOUD_OPTIONS", ComputerResolutionError;
|
|
234526
|
+
var SUBAGENT_CLOUD_OPTIONS_ENV = "LETTA_SUBAGENT_CLOUD_OPTIONS", WorkerSandboxExpiredError, ComputerResolutionError;
|
|
234200
234527
|
var init_environments3 = __esm(() => {
|
|
234201
234528
|
init_request();
|
|
234529
|
+
WorkerSandboxExpiredError = class WorkerSandboxExpiredError extends Error {
|
|
234530
|
+
constructor() {
|
|
234531
|
+
super("The worker's cloud sandbox expired and was deleted. Launch a new worker with Agent.");
|
|
234532
|
+
}
|
|
234533
|
+
};
|
|
234202
234534
|
ComputerResolutionError = class ComputerResolutionError extends Error {
|
|
234203
234535
|
code;
|
|
234204
|
-
|
|
234205
|
-
|
|
234536
|
+
httpStatus;
|
|
234537
|
+
constructor(code, message, cause) {
|
|
234538
|
+
super(message, { cause });
|
|
234206
234539
|
this.code = code;
|
|
234207
234540
|
this.name = "ComputerResolutionError";
|
|
234541
|
+
if (cause && typeof cause === "object" && "status" in cause) {
|
|
234542
|
+
const status = cause.status;
|
|
234543
|
+
if (typeof status === "number" && Number.isInteger(status) && status >= 400 && status <= 599) {
|
|
234544
|
+
this.httpStatus = status;
|
|
234545
|
+
}
|
|
234546
|
+
}
|
|
234208
234547
|
}
|
|
234209
234548
|
};
|
|
234210
234549
|
});
|
|
@@ -239102,6 +239441,20 @@ function waitForChildRun(receipt, signal, onIdle) {
|
|
|
239102
239441
|
onIdle
|
|
239103
239442
|
});
|
|
239104
239443
|
}
|
|
239444
|
+
function trackPersistedChildSend(receipt, writer) {
|
|
239445
|
+
writer.found.then(async (found) => {
|
|
239446
|
+
if (!found)
|
|
239447
|
+
return;
|
|
239448
|
+
try {
|
|
239449
|
+
await waitForChildRun(receipt, new AbortController().signal, () => {
|
|
239450
|
+
return;
|
|
239451
|
+
});
|
|
239452
|
+
writer.update({ status: "completed" });
|
|
239453
|
+
} catch {
|
|
239454
|
+
writer.update({ status: "failed" });
|
|
239455
|
+
}
|
|
239456
|
+
});
|
|
239457
|
+
}
|
|
239105
239458
|
function trackChildSend(input) {
|
|
239106
239459
|
const { receipt, child, parentScope } = input;
|
|
239107
239460
|
const subagentId = generateSubagentId();
|
|
@@ -239115,10 +239468,16 @@ function trackChildSend(input) {
|
|
|
239115
239468
|
})
|
|
239116
239469
|
});
|
|
239117
239470
|
const onIdle = createRemoteIdleNotifier(subagentId, parentScope);
|
|
239118
|
-
(input.waitForRun ?? ((receipt2, signal) => waitForChildRun(receipt2, signal, onIdle)))(receipt, input.signal ?? new AbortController().signal).then(() =>
|
|
239119
|
-
|
|
239120
|
-
|
|
239121
|
-
})
|
|
239471
|
+
(input.waitForRun ?? ((receipt2, signal) => waitForChildRun(receipt2, signal, onIdle)))(receipt, input.signal ?? new AbortController().signal).then(() => {
|
|
239472
|
+
input.persistRun?.({ status: "completed" });
|
|
239473
|
+
completeSubagent(subagentId, { success: true });
|
|
239474
|
+
}, (error4) => {
|
|
239475
|
+
input.persistRun?.({ status: "failed" });
|
|
239476
|
+
completeSubagent(subagentId, {
|
|
239477
|
+
success: false,
|
|
239478
|
+
error: getErrorMessage2(error4)
|
|
239479
|
+
});
|
|
239480
|
+
});
|
|
239122
239481
|
return subagentId;
|
|
239123
239482
|
}
|
|
239124
239483
|
var init_child_send_tracking = __esm(() => {
|
|
@@ -239330,6 +239689,7 @@ function composeSubagentChildEnv(options) {
|
|
|
239330
239689
|
},
|
|
239331
239690
|
LETTA_PARENT_AGENT_ID: parentAgentId,
|
|
239332
239691
|
LETTA_PARENT_CONVERSATION_ID: options.parentConversationId,
|
|
239692
|
+
[SUBAGENT_SUMMARY_ENV]: options.subagentSummary,
|
|
239333
239693
|
[SUBAGENT_DEPTH_ENV]: String(readSubagentDepth(parentProcessEnv) + 1),
|
|
239334
239694
|
...transcriptPath && { TRANSCRIPT_PATH: transcriptPath }
|
|
239335
239695
|
};
|
|
@@ -239606,6 +239966,250 @@ var init_subagent_process = __esm(() => {
|
|
|
239606
239966
|
init_package_manager_spawn();
|
|
239607
239967
|
});
|
|
239608
239968
|
|
|
239969
|
+
// src/tools/impl/native-session-owner.ts
|
|
239970
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
239971
|
+
import { mkdirSync as mkdirSync38, readFileSync as readFileSync41, rmSync as rmSync16, writeFileSync as writeFileSync33 } from "node:fs";
|
|
239972
|
+
import { join as join68 } from "node:path";
|
|
239973
|
+
function ownerPath(source, sessionId) {
|
|
239974
|
+
const id = createHash11("sha256").update(`${source}:${sessionId}`).digest("hex");
|
|
239975
|
+
return join68(resolveGlobalConfigDir(), "native-session-owners", `${id}.json`);
|
|
239976
|
+
}
|
|
239977
|
+
function readNativeSessionOwner(source, sessionId) {
|
|
239978
|
+
try {
|
|
239979
|
+
const owner = JSON.parse(readFileSync41(ownerPath(source, sessionId), "utf8"));
|
|
239980
|
+
if (typeof owner.agentId === "string" && typeof owner.conversationId === "string" && (owner.cloudSkillRepositories === undefined || isCloudRepositoryNames(owner.cloudSkillRepositories)))
|
|
239981
|
+
return owner;
|
|
239982
|
+
throw new Error("Invalid native session owner record");
|
|
239983
|
+
} catch (error4) {
|
|
239984
|
+
if (error4.code !== "ENOENT")
|
|
239985
|
+
throw error4;
|
|
239986
|
+
}
|
|
239987
|
+
return;
|
|
239988
|
+
}
|
|
239989
|
+
function persistNativeSessionOwner(source, sessionId, scope) {
|
|
239990
|
+
const path30 = ownerPath(source, sessionId);
|
|
239991
|
+
mkdirSync38(join68(path30, ".."), { recursive: true, mode: 448 });
|
|
239992
|
+
try {
|
|
239993
|
+
writeFileSync33(path30, JSON.stringify(scope), { flag: "wx", mode: 384 });
|
|
239994
|
+
} catch (error4) {
|
|
239995
|
+
if (error4.code !== "EEXIST")
|
|
239996
|
+
throw error4;
|
|
239997
|
+
}
|
|
239998
|
+
}
|
|
239999
|
+
var init_native_session_owner = __esm(() => {
|
|
240000
|
+
init_cloud_repository_roots();
|
|
240001
|
+
init_settings_path();
|
|
240002
|
+
});
|
|
240003
|
+
|
|
240004
|
+
// src/tools/impl/antigravity-session.ts
|
|
240005
|
+
import { createInterface as createInterface8 } from "node:readline";
|
|
240006
|
+
async function runAntigravityTurn(options, env6, secrets2) {
|
|
240007
|
+
const start = Date.now();
|
|
240008
|
+
if (env6.GEMINI_API_KEY)
|
|
240009
|
+
secrets2 = { ...secrets2, GEMINI_API_KEY: env6.GEMINI_API_KEY };
|
|
240010
|
+
let sessionId = options.resumeSessionId;
|
|
240011
|
+
const state2 = { queue: [], closing: false };
|
|
240012
|
+
const controller = new AbortController;
|
|
240013
|
+
const signal = options.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
240014
|
+
const base2 = {
|
|
240015
|
+
model: options.model,
|
|
240016
|
+
report: "",
|
|
240017
|
+
agentId: options.parentAgentId
|
|
240018
|
+
};
|
|
240019
|
+
try {
|
|
240020
|
+
signal.throwIfAborted();
|
|
240021
|
+
const args = [
|
|
240022
|
+
"--mode",
|
|
240023
|
+
"accept-edits",
|
|
240024
|
+
"--input-format",
|
|
240025
|
+
"stream-json",
|
|
240026
|
+
"--output-format",
|
|
240027
|
+
"stream-json",
|
|
240028
|
+
"--disable-slash-commands"
|
|
240029
|
+
];
|
|
240030
|
+
if (env6.GEMINI_API_KEY)
|
|
240031
|
+
args.push("--settings", '{"modelProvider":"gemini"}');
|
|
240032
|
+
if (sessionId) {
|
|
240033
|
+
const owner = readNativeSessionOwner("antigravity", sessionId);
|
|
240034
|
+
if (!sessionPattern.test(sessionId) || owner?.agentId !== options.parentAgentId)
|
|
240035
|
+
throw new Error("Antigravity session does not belong to this agent");
|
|
240036
|
+
if (sessions.has(sessionId))
|
|
240037
|
+
throw new Error("Antigravity session is already running");
|
|
240038
|
+
sessions.set(sessionId, state2);
|
|
240039
|
+
args.push("--conversation", sessionId);
|
|
240040
|
+
options = {
|
|
240041
|
+
...options,
|
|
240042
|
+
cwd: owner.cwd ?? options.cwd,
|
|
240043
|
+
model: options.model ?? owner.model
|
|
240044
|
+
};
|
|
240045
|
+
}
|
|
240046
|
+
if (options.model)
|
|
240047
|
+
args.push("--model", options.model);
|
|
240048
|
+
const running = spawnManagedWorkloadProcess("agy", args, {
|
|
240049
|
+
cwd: options.cwd,
|
|
240050
|
+
env: env6,
|
|
240051
|
+
signal
|
|
240052
|
+
});
|
|
240053
|
+
const child = running.process;
|
|
240054
|
+
let diagnostic = "";
|
|
240055
|
+
let spawnError;
|
|
240056
|
+
child.once("error", (error5) => {
|
|
240057
|
+
spawnError = error5;
|
|
240058
|
+
});
|
|
240059
|
+
child.stderr.on("data", (chunk2) => {
|
|
240060
|
+
diagnostic = (diagnostic + chunk2).slice(-2048);
|
|
240061
|
+
});
|
|
240062
|
+
child.stdin.on("error", () => {});
|
|
240063
|
+
const lines = createInterface8({ input: child.stdout });
|
|
240064
|
+
const send = (content) => child.stdin.write(`${JSON.stringify({ event: "user", message: { content } })}
|
|
240065
|
+
`);
|
|
240066
|
+
send([options.mcpReminder, options.prompt].filter(Boolean).join(`
|
|
240067
|
+
|
|
240068
|
+
`));
|
|
240069
|
+
let report;
|
|
240070
|
+
let error4;
|
|
240071
|
+
let initialized = false;
|
|
240072
|
+
const text2 = createSecretStreamScrubber(secrets2);
|
|
240073
|
+
const tools = new Set;
|
|
240074
|
+
try {
|
|
240075
|
+
for await (const line of lines) {
|
|
240076
|
+
if (!line.trim())
|
|
240077
|
+
continue;
|
|
240078
|
+
const event = JSON.parse(line);
|
|
240079
|
+
if (!isRecord2(event))
|
|
240080
|
+
throw new Error("Invalid Antigravity event");
|
|
240081
|
+
if (event.event === "init") {
|
|
240082
|
+
const id = event.conversation_id;
|
|
240083
|
+
if (initialized || typeof id !== "string" || !sessionPattern.test(id) || sessionId && id !== sessionId || !sessionId && sessions.has(id))
|
|
240084
|
+
throw new Error("Invalid Antigravity conversation ID");
|
|
240085
|
+
sessionId = id;
|
|
240086
|
+
if (!options.resumeSessionId)
|
|
240087
|
+
persistNativeSessionOwner("antigravity", id, {
|
|
240088
|
+
agentId: options.parentAgentId,
|
|
240089
|
+
conversationId: options.parentConversationId ?? "default",
|
|
240090
|
+
cwd: options.cwd,
|
|
240091
|
+
model: options.model
|
|
240092
|
+
});
|
|
240093
|
+
if (readNativeSessionOwner("antigravity", id)?.agentId !== options.parentAgentId)
|
|
240094
|
+
throw new Error("Antigravity session owner mismatch");
|
|
240095
|
+
sessions.set(id, state2);
|
|
240096
|
+
initialized = true;
|
|
240097
|
+
options.onStarted?.(`antigravity_${id}`);
|
|
240098
|
+
} else if (event.event === "step_update" && isRecord2(event.step_update)) {
|
|
240099
|
+
const step = event.step_update;
|
|
240100
|
+
if (!initialized || step.conversation_id !== sessionId)
|
|
240101
|
+
throw new Error("Unexpected Antigravity step conversation");
|
|
240102
|
+
if (step.step_type === "agent_response" && typeof step.text_delta === "string") {
|
|
240103
|
+
const delta = text2.push(step.text_delta);
|
|
240104
|
+
if (delta)
|
|
240105
|
+
emitProgress(options.onText, delta);
|
|
240106
|
+
}
|
|
240107
|
+
if (step.step_type === "tool" && typeof step.step_index === "number" && typeof step.tool_name === "string") {
|
|
240108
|
+
const info = isRecord2(step.tool_info) ? step.tool_info : {};
|
|
240109
|
+
const id = `step-${step.step_index}`;
|
|
240110
|
+
if (!tools.has(step.step_index)) {
|
|
240111
|
+
tools.add(step.step_index);
|
|
240112
|
+
emitProgress(options.onToolCall, {
|
|
240113
|
+
id,
|
|
240114
|
+
name: step.tool_name,
|
|
240115
|
+
args: formatExternalToolCallArgs(info.parameters)
|
|
240116
|
+
});
|
|
240117
|
+
}
|
|
240118
|
+
if (step.state === "DONE")
|
|
240119
|
+
emitProgress(options.onToolResult, {
|
|
240120
|
+
id,
|
|
240121
|
+
name: step.tool_name,
|
|
240122
|
+
isError: !!info.error,
|
|
240123
|
+
output: toolOutputText(info.error ?? info.output)
|
|
240124
|
+
});
|
|
240125
|
+
}
|
|
240126
|
+
} else if (event.event === "result" && isRecord2(event.result)) {
|
|
240127
|
+
const result3 = event.result;
|
|
240128
|
+
const tail2 = text2.flush();
|
|
240129
|
+
if (tail2)
|
|
240130
|
+
emitProgress(options.onText, tail2);
|
|
240131
|
+
if (result3.status !== "SUCCESS")
|
|
240132
|
+
error4 = typeof result3.error === "string" ? result3.error : "Antigravity turn failed";
|
|
240133
|
+
else if (!initialized || result3.conversation_id !== sessionId || typeof result3.response !== "string" || state2.closing)
|
|
240134
|
+
throw new Error("Invalid Antigravity result");
|
|
240135
|
+
const next = !error4 && state2.queue.shift();
|
|
240136
|
+
if (next) {
|
|
240137
|
+
tools.clear();
|
|
240138
|
+
send(next);
|
|
240139
|
+
} else {
|
|
240140
|
+
state2.closing = true;
|
|
240141
|
+
report = typeof result3.response === "string" ? result3.response : undefined;
|
|
240142
|
+
child.stdin.end();
|
|
240143
|
+
}
|
|
240144
|
+
}
|
|
240145
|
+
}
|
|
240146
|
+
const { exitCode } = await running.completion;
|
|
240147
|
+
signal.throwIfAborted();
|
|
240148
|
+
if (spawnError?.code === "ENOENT")
|
|
240149
|
+
throw new Error("Required executable 'agy' was not found on PATH");
|
|
240150
|
+
if (!initialized && /authentication required|authentication failed/i.test(`${diagnostic}
|
|
240151
|
+
${error4}`))
|
|
240152
|
+
throw new Error("Antigravity is not signed in: run agy to authenticate");
|
|
240153
|
+
if (spawnError || error4 || exitCode !== 0 || report === undefined || !sessionId)
|
|
240154
|
+
throw spawnError ?? new Error(error4 || diagnostic.trim() || "Antigravity exited without a result");
|
|
240155
|
+
return {
|
|
240156
|
+
...base2,
|
|
240157
|
+
agentId: `antigravity_${sessionId}`,
|
|
240158
|
+
runtimeSessionId: sessionId,
|
|
240159
|
+
report: scrubSecretsFromString(report, secrets2),
|
|
240160
|
+
success: true,
|
|
240161
|
+
durationMs: Date.now() - start
|
|
240162
|
+
};
|
|
240163
|
+
} finally {
|
|
240164
|
+
lines.close();
|
|
240165
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
240166
|
+
controller.abort();
|
|
240167
|
+
await running.completion;
|
|
240168
|
+
}
|
|
240169
|
+
} catch (error4) {
|
|
240170
|
+
return {
|
|
240171
|
+
...base2,
|
|
240172
|
+
success: false,
|
|
240173
|
+
error: scrubSecretsFromString(error4 instanceof Error ? error4.message : String(error4), secrets2),
|
|
240174
|
+
durationMs: Date.now() - start
|
|
240175
|
+
};
|
|
240176
|
+
} finally {
|
|
240177
|
+
if (sessionId && sessions.get(sessionId) === state2)
|
|
240178
|
+
sessions.delete(sessionId);
|
|
240179
|
+
}
|
|
240180
|
+
}
|
|
240181
|
+
function sendAntigravityMessage(options, env6, secrets2) {
|
|
240182
|
+
const id = options.resumeSessionId;
|
|
240183
|
+
if (readNativeSessionOwner("antigravity", id)?.agentId !== options.parentAgentId)
|
|
240184
|
+
throw new Error("Antigravity session does not belong to this agent");
|
|
240185
|
+
const active = sessions.get(id);
|
|
240186
|
+
if (active) {
|
|
240187
|
+
if (active.closing)
|
|
240188
|
+
throw new Error("Antigravity session is finishing; retry after completion");
|
|
240189
|
+
active.queue.push(options.prompt);
|
|
240190
|
+
return { mode: "steered", queued: true };
|
|
240191
|
+
}
|
|
240192
|
+
const controller = new AbortController;
|
|
240193
|
+
const signal = options.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
240194
|
+
const completion = runAntigravityTurn({ ...options, signal }, env6, secrets2);
|
|
240195
|
+
return {
|
|
240196
|
+
mode: "resumed",
|
|
240197
|
+
completion,
|
|
240198
|
+
interrupt: async () => {
|
|
240199
|
+
controller.abort();
|
|
240200
|
+
await completion;
|
|
240201
|
+
}
|
|
240202
|
+
};
|
|
240203
|
+
}
|
|
240204
|
+
var sessions, sessionPattern;
|
|
240205
|
+
var init_antigravity_session = __esm(() => {
|
|
240206
|
+
init_subagent_process();
|
|
240207
|
+
init_secret_substitution();
|
|
240208
|
+
init_native_session_owner();
|
|
240209
|
+
sessions = new Map;
|
|
240210
|
+
sessionPattern = /^[a-f\d]{8}(?:-[a-f\d]{4}){3}-[a-f\d]{12}$/i;
|
|
240211
|
+
});
|
|
240212
|
+
|
|
239609
240213
|
// src/utils/confirm-process-exit.ts
|
|
239610
240214
|
async function confirmProcessExit(exit, name) {
|
|
239611
240215
|
let timer;
|
|
@@ -239623,11 +240227,11 @@ async function confirmProcessExit(exit, name) {
|
|
|
239623
240227
|
|
|
239624
240228
|
// src/utils/native-cli-env.ts
|
|
239625
240229
|
import { homedir as homedir19 } from "node:os";
|
|
239626
|
-
import { join as
|
|
240230
|
+
import { join as join69 } from "node:path";
|
|
239627
240231
|
function withNativeCliPath(env6, platform7 = process.platform) {
|
|
239628
240232
|
if (platform7 === "win32")
|
|
239629
240233
|
return { ...env6 };
|
|
239630
|
-
const nativeBin =
|
|
240234
|
+
const nativeBin = join69(env6.HOME || homedir19(), ".local", "bin");
|
|
239631
240235
|
const paths = (env6.PATH ?? "/usr/bin:/bin").split(":");
|
|
239632
240236
|
if (!paths.includes(nativeBin))
|
|
239633
240237
|
paths.push(nativeBin);
|
|
@@ -239638,7 +240242,7 @@ var init_native_cli_env = () => {};
|
|
|
239638
240242
|
// src/tools/impl/claude-repository-skills.ts
|
|
239639
240243
|
import { mkdir as mkdir11, mkdtemp as mkdtemp4, rm as rm8, stat as stat10, symlink as symlink3 } from "node:fs/promises";
|
|
239640
240244
|
import { tmpdir as tmpdir13 } from "node:os";
|
|
239641
|
-
import { basename as basename22, join as
|
|
240245
|
+
import { basename as basename22, join as join70 } from "node:path";
|
|
239642
240246
|
async function stageClaudeRepositorySkills(repositoryRoots) {
|
|
239643
240247
|
const directories = [];
|
|
239644
240248
|
let stagingRoot;
|
|
@@ -239649,7 +240253,7 @@ async function stageClaudeRepositorySkills(repositoryRoots) {
|
|
|
239649
240253
|
try {
|
|
239650
240254
|
for (const repo of repositoryRoots) {
|
|
239651
240255
|
for (const source of [".claude", ".agents"]) {
|
|
239652
|
-
const skills =
|
|
240256
|
+
const skills = join70(repo, source, "skills");
|
|
239653
240257
|
const info = await stat10(skills).catch((error4) => {
|
|
239654
240258
|
if (error4.code === "ENOENT" || error4.code === "ENOTDIR")
|
|
239655
240259
|
return;
|
|
@@ -239657,11 +240261,11 @@ async function stageClaudeRepositorySkills(repositoryRoots) {
|
|
|
239657
240261
|
});
|
|
239658
240262
|
if (!info?.isDirectory())
|
|
239659
240263
|
continue;
|
|
239660
|
-
stagingRoot ??= await mkdtemp4(
|
|
239661
|
-
const directory =
|
|
239662
|
-
const claudeDir =
|
|
240264
|
+
stagingRoot ??= await mkdtemp4(join70(tmpdir13(), "letta-claude-skills-"));
|
|
240265
|
+
const directory = join70(stagingRoot, source, basename22(repo));
|
|
240266
|
+
const claudeDir = join70(directory, ".claude");
|
|
239663
240267
|
await mkdir11(claudeDir, { recursive: true });
|
|
239664
|
-
await symlink3(skills,
|
|
240268
|
+
await symlink3(skills, join70(claudeDir, "skills"), "dir");
|
|
239665
240269
|
directories.push(directory);
|
|
239666
240270
|
}
|
|
239667
240271
|
}
|
|
@@ -239800,11 +240404,17 @@ function traceJsonFits(bytes, encodedBytes) {
|
|
|
239800
240404
|
function tracePayloadFits(json2) {
|
|
239801
240405
|
return traceJsonFits(Buffer.byteLength(json2), Buffer.byteLength(JSON.stringify(json2)));
|
|
239802
240406
|
}
|
|
239803
|
-
function
|
|
240407
|
+
function isInlineImage(value) {
|
|
240408
|
+
if (value.type === "image")
|
|
240409
|
+
return value.source?.type === "base64" && typeof value.source.data === "string";
|
|
240410
|
+
const url2 = typeof value.image_url === "string" ? value.image_url : value.image_url?.url;
|
|
240411
|
+
return (value.type === "input_image" || value.type === "image_url") && typeof url2 === "string" && /^data:image\/[^;,]+;base64,/i.test(url2);
|
|
240412
|
+
}
|
|
240413
|
+
function compactTracePayload(json2, mode = "full") {
|
|
239804
240414
|
const payload = JSON.parse(json2);
|
|
239805
240415
|
if (!payload || typeof payload !== "object")
|
|
239806
240416
|
return TRUNCATED_TRACE_JSON;
|
|
239807
|
-
if (!Array.isArray(payload)) {
|
|
240417
|
+
if (mode === "full" && !Array.isArray(payload)) {
|
|
239808
240418
|
const object4 = payload;
|
|
239809
240419
|
delete object4.system;
|
|
239810
240420
|
delete object4.tools;
|
|
@@ -239816,36 +240426,47 @@ function compactTracePayload(json2) {
|
|
|
239816
240426
|
let encodedBytes = Buffer.byteLength(JSON.stringify(initial2));
|
|
239817
240427
|
if (traceJsonFits(bytes, encodedBytes))
|
|
239818
240428
|
return initial2;
|
|
239819
|
-
|
|
239820
|
-
|
|
239821
|
-
|
|
239822
|
-
|
|
239823
|
-
|
|
239824
|
-
|
|
239825
|
-
|
|
239826
|
-
|
|
239827
|
-
|
|
239828
|
-
|
|
239829
|
-
|
|
239830
|
-
|
|
239831
|
-
|
|
239832
|
-
|
|
239833
|
-
|
|
239834
|
-
|
|
239835
|
-
|
|
239836
|
-
|
|
240429
|
+
function shrink(imagesOnly) {
|
|
240430
|
+
const candidates = [];
|
|
240431
|
+
function collect(container) {
|
|
240432
|
+
for (const [key2, value] of Object.entries(container)) {
|
|
240433
|
+
const isObject5 = value !== null && typeof value === "object";
|
|
240434
|
+
if (imagesOnly && (!isObject5 || !isInlineImage(value))) {
|
|
240435
|
+
if (isObject5)
|
|
240436
|
+
collect(value);
|
|
240437
|
+
continue;
|
|
240438
|
+
}
|
|
240439
|
+
if (!imagesOnly && (Array.isArray(value) || key2 === "response" && isObject5)) {
|
|
240440
|
+
collect(value);
|
|
240441
|
+
continue;
|
|
240442
|
+
}
|
|
240443
|
+
const serialized = JSON.stringify(value);
|
|
240444
|
+
const bytes2 = Buffer.byteLength(serialized) - Buffer.byteLength(TRUNCATED_TRACE_JSON);
|
|
240445
|
+
const encodedBytes2 = Buffer.byteLength(JSON.stringify(serialized)) - Buffer.byteLength(JSON.stringify(TRUNCATED_TRACE_JSON));
|
|
240446
|
+
if (bytes2 > 0 && encodedBytes2 > 0) {
|
|
240447
|
+
candidates.push({
|
|
240448
|
+
bytes: bytes2,
|
|
240449
|
+
encodedBytes: encodedBytes2,
|
|
240450
|
+
replace: () => {
|
|
240451
|
+
container[key2] = truncated;
|
|
240452
|
+
}
|
|
240453
|
+
});
|
|
240454
|
+
}
|
|
239837
240455
|
}
|
|
239838
240456
|
}
|
|
240457
|
+
collect(payload);
|
|
240458
|
+
candidates.sort((a2, b3) => b3.bytes - a2.bytes);
|
|
240459
|
+
for (const candidate of candidates) {
|
|
240460
|
+
if (traceJsonFits(bytes, encodedBytes))
|
|
240461
|
+
break;
|
|
240462
|
+
candidate.replace();
|
|
240463
|
+
bytes -= candidate.bytes;
|
|
240464
|
+
encodedBytes -= candidate.encodedBytes;
|
|
240465
|
+
}
|
|
239839
240466
|
}
|
|
239840
|
-
|
|
239841
|
-
|
|
239842
|
-
|
|
239843
|
-
if (traceJsonFits(bytes, encodedBytes))
|
|
239844
|
-
break;
|
|
239845
|
-
candidate.replace();
|
|
239846
|
-
bytes -= candidate.bytes;
|
|
239847
|
-
encodedBytes -= candidate.encodedBytes;
|
|
239848
|
-
}
|
|
240467
|
+
shrink(true);
|
|
240468
|
+
if (mode === "full" && !traceJsonFits(bytes, encodedBytes))
|
|
240469
|
+
shrink(false);
|
|
239849
240470
|
return traceJsonFits(bytes, encodedBytes) ? marked() : TRUNCATED_TRACE_JSON;
|
|
239850
240471
|
}
|
|
239851
240472
|
var MAX_TRACE_PAYLOAD_BYTES, SENSITIVE, MAX_TRACE_BUFFER_BYTES, MAX_ENCODED_PAYLOAD_BYTES, truncated, TRUNCATED_TRACE_JSON;
|
|
@@ -239865,12 +240486,24 @@ import { createServer as createServer6, request as httpRequest3 } from "node:htt
|
|
|
239865
240486
|
import { request as httpsRequest2 } from "node:https";
|
|
239866
240487
|
import { isDeepStrictEqual } from "node:util";
|
|
239867
240488
|
import { brotliDecompressSync, gunzipSync, inflateSync } from "node:zlib";
|
|
240489
|
+
function withoutCacheBreakpoints(item) {
|
|
240490
|
+
if (!item || typeof item !== "object" || Array.isArray(item))
|
|
240491
|
+
return item;
|
|
240492
|
+
const block = { ...item };
|
|
240493
|
+
const cacheControl = block.cache_control;
|
|
240494
|
+
if (cacheControl && typeof cacheControl === "object" && "type" in cacheControl && cacheControl.type === "ephemeral")
|
|
240495
|
+
delete block.cache_control;
|
|
240496
|
+
if (Array.isArray(block.content))
|
|
240497
|
+
block.content = block.content.map(withoutCacheBreakpoints);
|
|
240498
|
+
return block;
|
|
240499
|
+
}
|
|
239868
240500
|
async function startTraceProxy(options) {
|
|
239869
240501
|
const upstream = new URL(options.upstream);
|
|
239870
240502
|
if (!["http:", "https:"].includes(upstream.protocol) || upstream.username || upstream.password)
|
|
239871
240503
|
throw new Error("Unsupported trace upstream");
|
|
239872
240504
|
const prefix = `/${randomUUID39()}`;
|
|
239873
240505
|
const historyKey = options.harness === "claude_code" ? "messages" : "input";
|
|
240506
|
+
const comparable = (item) => options.harness === "claude_code" ? withoutCacheBreakpoints(item) : item;
|
|
239874
240507
|
let previous;
|
|
239875
240508
|
let activeCaptures = 0;
|
|
239876
240509
|
const pending2 = new Set;
|
|
@@ -239948,21 +240581,26 @@ async function startTraceProxy(options) {
|
|
|
239948
240581
|
requestJson = fallbackJson;
|
|
239949
240582
|
if (previous?.sessionId === scope.worker_session_id && Array.isArray(items)) {
|
|
239950
240583
|
const prefixItems = previous.items.length;
|
|
239951
|
-
if (prefixItems > 0 && items.length > prefixItems && previous.items.every((item, index) => isDeepStrictEqual(item, items[index]))) {
|
|
239952
|
-
const
|
|
240584
|
+
if (prefixItems > 0 && items.length > prefixItems && previous.items.every((item, index) => isDeepStrictEqual(item, comparable(items[index])))) {
|
|
240585
|
+
const rawDelta = JSON.stringify({
|
|
239953
240586
|
...request3,
|
|
239954
240587
|
[historyKey]: items.slice(prefixItems),
|
|
239955
240588
|
base_trace_id: previous.id,
|
|
239956
240589
|
prefix_items: prefixItems
|
|
239957
240590
|
});
|
|
239958
|
-
|
|
240591
|
+
const deltaJson = tracePayloadFits(rawDelta) ? rawDelta : compactTracePayload(rawDelta, "images");
|
|
240592
|
+
if (deltaJson !== TRUNCATED_TRACE_JSON) {
|
|
239959
240593
|
requestJson = deltaJson;
|
|
239960
240594
|
delta = { baseId: previous.id, fallbackJson };
|
|
239961
240595
|
}
|
|
239962
240596
|
}
|
|
239963
240597
|
}
|
|
239964
240598
|
}
|
|
239965
|
-
previous = Array.isArray(items) && (!requestTruncated || delta) ? {
|
|
240599
|
+
previous = Array.isArray(items) && (!requestTruncated || delta) ? {
|
|
240600
|
+
id,
|
|
240601
|
+
sessionId: scope.worker_session_id,
|
|
240602
|
+
items: items.map(comparable)
|
|
240603
|
+
} : undefined;
|
|
239966
240604
|
const response = assembled.response;
|
|
239967
240605
|
const usage = response.usage ?? {};
|
|
239968
240606
|
const token2 = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? Math.min(Math.trunc(value), 4294967295) : null;
|
|
@@ -239975,6 +240613,7 @@ async function startTraceProxy(options) {
|
|
|
239975
240613
|
const error4 = transportError || status >= 400 || Boolean(response.error) || response.status === "failed";
|
|
239976
240614
|
options.emit({
|
|
239977
240615
|
...scope,
|
|
240616
|
+
task_description: scope.task_description === undefined ? undefined : JSON.parse(sanitizeTraceJson(JSON.stringify(scope.task_description), credentials)),
|
|
239978
240617
|
id,
|
|
239979
240618
|
harness: options.harness,
|
|
239980
240619
|
model: JSON.parse(sanitizeTraceJson(JSON.stringify(String(response.model ?? request3?.model ?? "")), credentials)).slice(0, 255),
|
|
@@ -240026,6 +240665,7 @@ async function startTraceProxy(options) {
|
|
|
240026
240665
|
reply.on("end", () => finish());
|
|
240027
240666
|
reply.on("error", () => {
|
|
240028
240667
|
finish(true);
|
|
240668
|
+
res.socket?.destroy();
|
|
240029
240669
|
res.destroy();
|
|
240030
240670
|
});
|
|
240031
240671
|
reply.pipe(res);
|
|
@@ -240057,6 +240697,15 @@ async function startTraceProxy(options) {
|
|
|
240057
240697
|
});
|
|
240058
240698
|
req.pipe(target);
|
|
240059
240699
|
});
|
|
240700
|
+
if (options.harness === "codex") {
|
|
240701
|
+
server2.on("upgrade", (_request, socket) => {
|
|
240702
|
+
socket.end(`HTTP/1.1 404 Not Found\r
|
|
240703
|
+
Connection: close\r
|
|
240704
|
+
Content-Length: 0\r
|
|
240705
|
+
\r
|
|
240706
|
+
`);
|
|
240707
|
+
});
|
|
240708
|
+
}
|
|
240060
240709
|
await new Promise((resolve34, reject2) => {
|
|
240061
240710
|
server2.once("error", reject2);
|
|
240062
240711
|
server2.listen(0, "127.0.0.1", resolve34);
|
|
@@ -240083,8 +240732,10 @@ var init_external_llm_trace_proxy = __esm(() => {
|
|
|
240083
240732
|
// src/tools/impl/external-llm-trace-session.ts
|
|
240084
240733
|
function updateExternalTraceTask(sessionId, context3) {
|
|
240085
240734
|
const scope = sessionScopes.get(sessionId);
|
|
240086
|
-
if (scope && context3 && scope.parent_agent_id === context3.parent_agent_id && scope.parent_conversation_id === context3.parent_conversation_id)
|
|
240735
|
+
if (scope && context3 && scope.parent_agent_id === context3.parent_agent_id && scope.parent_conversation_id === context3.parent_conversation_id) {
|
|
240087
240736
|
scope.task_id = context3.task_id;
|
|
240737
|
+
scope.task_description = context3.task_description;
|
|
240738
|
+
}
|
|
240088
240739
|
}
|
|
240089
240740
|
function describeUploadError(error4, secrets2) {
|
|
240090
240741
|
if (!(error4 instanceof Error))
|
|
@@ -240280,12 +240931,21 @@ async function traceClaudeLaunch(context3, env6, sessionId) {
|
|
|
240280
240931
|
function record4(value) {
|
|
240281
240932
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
240282
240933
|
}
|
|
240283
|
-
async function traceCodexLaunch(context3, env6, client, createTrace2 = createTraceSession) {
|
|
240934
|
+
async function traceCodexLaunch(context3, env6, client, resumeThreadId, createTrace2 = createTraceSession) {
|
|
240284
240935
|
if (!context3 || env6.LETTA_CODE_TELEM === "0" || env6.LETTA_CODE_TELEM === "false" || env6.DO_NOT_TRACK === "1")
|
|
240285
240936
|
return;
|
|
240286
240937
|
try {
|
|
240287
240938
|
const configuration = record4((await client.request("config/read", { includeLayers: false })).config);
|
|
240288
|
-
const
|
|
240939
|
+
const resumed = resumeThreadId ? await client.request("thread/read", {
|
|
240940
|
+
threadId: resumeThreadId,
|
|
240941
|
+
includeTurns: false
|
|
240942
|
+
}).catch(() => {
|
|
240943
|
+
return;
|
|
240944
|
+
}) : undefined;
|
|
240945
|
+
const persistedProvider = record4(resumed?.thread).modelProvider;
|
|
240946
|
+
const configuredProvider = configuration.model_provider;
|
|
240947
|
+
const sourceProvider = typeof persistedProvider === "string" && persistedProvider ? persistedProvider : configuredProvider;
|
|
240948
|
+
const providerId2 = typeof sourceProvider === "string" && sourceProvider !== "letta_trace" ? sourceProvider : "openai";
|
|
240289
240949
|
const provider2 = record4(record4(configuration.model_providers)[providerId2]);
|
|
240290
240950
|
const account = record4((await client.request("account/read", { refreshToken: false })).account);
|
|
240291
240951
|
const configuredUrl = provider2.base_url ?? (providerId2 === "openai" ? configuration.openai_base_url ?? env6.OPENAI_BASE_URL : undefined);
|
|
@@ -240302,6 +240962,8 @@ async function traceCodexLaunch(context3, env6, client, createTrace2 = createTra
|
|
|
240302
240962
|
[`model_providers.${selected}.supports_websockets`]: false
|
|
240303
240963
|
};
|
|
240304
240964
|
if (providerId2 === "openai") {
|
|
240965
|
+
if (resumeThreadId)
|
|
240966
|
+
overrides.openai_base_url = trace.url;
|
|
240305
240967
|
overrides[`model_providers.${selected}.name`] = "OpenAI trace";
|
|
240306
240968
|
overrides[`model_providers.${selected}.requires_openai_auth`] = true;
|
|
240307
240969
|
overrides[`model_providers.${selected}.wire_api`] = "responses";
|
|
@@ -240311,8 +240973,7 @@ async function traceCodexLaunch(context3, env6, client, createTrace2 = createTra
|
|
|
240311
240973
|
args: Object.entries(overrides).flatMap(([key2, value]) => [
|
|
240312
240974
|
"-c",
|
|
240313
240975
|
`${key2}=${JSON.stringify(value)}`
|
|
240314
|
-
])
|
|
240315
|
-
params: { modelProvider: selected }
|
|
240976
|
+
])
|
|
240316
240977
|
};
|
|
240317
240978
|
} catch {
|
|
240318
240979
|
return;
|
|
@@ -240324,7 +240985,7 @@ var init_external_llm_trace_launch = __esm(() => {
|
|
|
240324
240985
|
|
|
240325
240986
|
// src/tools/impl/claude-stream-session.ts
|
|
240326
240987
|
import { randomUUID as randomUUID40 } from "node:crypto";
|
|
240327
|
-
import { createInterface as
|
|
240988
|
+
import { createInterface as createInterface9 } from "node:readline";
|
|
240328
240989
|
function errorMessage3(error4) {
|
|
240329
240990
|
return error4 instanceof Error ? error4.message : String(error4);
|
|
240330
240991
|
}
|
|
@@ -240730,12 +241391,12 @@ async function launchSession(options, deps) {
|
|
|
240730
241391
|
onReasoning: options.onReasoning,
|
|
240731
241392
|
toolNames: new Map
|
|
240732
241393
|
};
|
|
240733
|
-
|
|
241394
|
+
sessions2.set(sessionId, session3);
|
|
240734
241395
|
transport3.process.stderr.setEncoding("utf8");
|
|
240735
241396
|
transport3.process.stderr.on("data", (chunk2) => {
|
|
240736
241397
|
session3.stderr += chunk2;
|
|
240737
241398
|
});
|
|
240738
|
-
const stdout =
|
|
241399
|
+
const stdout = createInterface9({ input: transport3.process.stdout });
|
|
240739
241400
|
stdout.on("line", (line) => {
|
|
240740
241401
|
if (!line.trim())
|
|
240741
241402
|
return;
|
|
@@ -240784,8 +241445,8 @@ async function launchSession(options, deps) {
|
|
|
240784
241445
|
}).finally(() => {
|
|
240785
241446
|
session3.exited = true;
|
|
240786
241447
|
removeUpstreamAbort();
|
|
240787
|
-
if (
|
|
240788
|
-
|
|
241448
|
+
if (sessions2.get(sessionId) === session3)
|
|
241449
|
+
sessions2.delete(sessionId);
|
|
240789
241450
|
resolveExit();
|
|
240790
241451
|
});
|
|
240791
241452
|
try {
|
|
@@ -240839,7 +241500,7 @@ async function startSession(options, deps) {
|
|
|
240839
241500
|
const key2 = options.resumeSessionId ?? options.sessionId;
|
|
240840
241501
|
if (key2) {
|
|
240841
241502
|
for (;; ) {
|
|
240842
|
-
const existing =
|
|
241503
|
+
const existing = sessions2.get(key2);
|
|
240843
241504
|
if (!existing)
|
|
240844
241505
|
break;
|
|
240845
241506
|
if (!existing.settled)
|
|
@@ -240871,14 +241532,14 @@ async function steerSession(session3, prompt, signal) {
|
|
|
240871
241532
|
signal?.throwIfAborted();
|
|
240872
241533
|
await waitForTurnStart(session3, signal);
|
|
240873
241534
|
if (session3.idleOnBackgroundTasks) {
|
|
240874
|
-
if (session3.settled ||
|
|
241535
|
+
if (session3.settled || sessions2.get(session3.sessionId) !== session3) {
|
|
240875
241536
|
throw new Error("Claude Code session is no longer active");
|
|
240876
241537
|
}
|
|
240877
241538
|
session3.idleOnBackgroundTasks = false;
|
|
240878
241539
|
await writeInput(session3, prompt);
|
|
240879
241540
|
return "steered";
|
|
240880
241541
|
}
|
|
240881
|
-
if (session3.settled ||
|
|
241542
|
+
if (session3.settled || sessions2.get(session3.sessionId) !== session3) {
|
|
240882
241543
|
throw new Error("Claude Code session is no longer active");
|
|
240883
241544
|
}
|
|
240884
241545
|
const requestId = randomUUID40();
|
|
@@ -240911,7 +241572,7 @@ async function steerSession(session3, prompt, signal) {
|
|
|
240911
241572
|
session3.suppressedResult = undefined;
|
|
240912
241573
|
return "steered";
|
|
240913
241574
|
} catch (error4) {
|
|
240914
|
-
if (ackTimedOut && !signal?.aborted && !session3.settled &&
|
|
241575
|
+
if (ackTimedOut && !signal?.aborted && !session3.settled && sessions2.get(session3.sessionId) === session3 && await queueSteerPrompt(session3, prompt))
|
|
240915
241576
|
return "queued";
|
|
240916
241577
|
session3.pendingSteers = Math.max(0, session3.pendingSteers - 1);
|
|
240917
241578
|
if (interruptAcknowledged) {
|
|
@@ -240923,7 +241584,7 @@ async function steerSession(session3, prompt, signal) {
|
|
|
240923
241584
|
const suppressed = session3.suppressedResult;
|
|
240924
241585
|
session3.suppressedResult = undefined;
|
|
240925
241586
|
finishResult(session3, suppressed);
|
|
240926
|
-
} else if (session3.resultCount === resultCount && !session3.settled &&
|
|
241587
|
+
} else if (session3.resultCount === resultCount && !session3.settled && sessions2.get(session3.sessionId) === session3) {
|
|
240927
241588
|
markTurnStarted(session3);
|
|
240928
241589
|
}
|
|
240929
241590
|
throw error4;
|
|
@@ -240953,7 +241614,7 @@ async function deliverClaudeMessage(options, deps, launch) {
|
|
|
240953
241614
|
await pending3;
|
|
240954
241615
|
continue;
|
|
240955
241616
|
}
|
|
240956
|
-
const existing =
|
|
241617
|
+
const existing = sessions2.get(options.sessionId);
|
|
240957
241618
|
if (!existing)
|
|
240958
241619
|
break;
|
|
240959
241620
|
if (existing.settled) {
|
|
@@ -240968,7 +241629,7 @@ async function deliverClaudeMessage(options, deps, launch) {
|
|
|
240968
241629
|
session: existing
|
|
240969
241630
|
};
|
|
240970
241631
|
} catch (error4) {
|
|
240971
|
-
if (
|
|
241632
|
+
if (sessions2.get(options.sessionId) === existing && !existing.settled)
|
|
240972
241633
|
throw error4;
|
|
240973
241634
|
}
|
|
240974
241635
|
}
|
|
@@ -241010,14 +241671,14 @@ async function sendClaudeMessage(options, deps = {}) {
|
|
|
241010
241671
|
return trackedReceipt(delivered.session);
|
|
241011
241672
|
}
|
|
241012
241673
|
async function stopClaudeSession(sessionId) {
|
|
241013
|
-
const session3 =
|
|
241674
|
+
const session3 = sessions2.get(sessionId);
|
|
241014
241675
|
if (!session3)
|
|
241015
241676
|
return false;
|
|
241016
241677
|
session3.abortController.abort(new Error("Stopped by parent"));
|
|
241017
241678
|
await confirmProcessExit(session3.exit, "Claude Code");
|
|
241018
241679
|
return true;
|
|
241019
241680
|
}
|
|
241020
|
-
var
|
|
241681
|
+
var sessions2, pendingResumes, BACKGROUND_TASK_WAIT_CAP_MS, SETTLED_EXIT_GRACE_MS = 1e4;
|
|
241021
241682
|
var init_claude_stream_session = __esm(() => {
|
|
241022
241683
|
init_subagent_process();
|
|
241023
241684
|
init_cloud_repository_roots();
|
|
@@ -241025,7 +241686,7 @@ var init_claude_stream_session = __esm(() => {
|
|
|
241025
241686
|
init_claude_repository_skills();
|
|
241026
241687
|
init_claude_steer_timeouts();
|
|
241027
241688
|
init_external_llm_trace_launch();
|
|
241028
|
-
|
|
241689
|
+
sessions2 = new Map;
|
|
241029
241690
|
pendingResumes = new Map;
|
|
241030
241691
|
BACKGROUND_TASK_WAIT_CAP_MS = 35 * 60000;
|
|
241031
241692
|
});
|
|
@@ -241199,8 +241860,8 @@ var init_codex_steer_receipt = __esm(() => {
|
|
|
241199
241860
|
});
|
|
241200
241861
|
|
|
241201
241862
|
// src/tools/impl/codex-app-server.ts
|
|
241202
|
-
import { join as
|
|
241203
|
-
import { createInterface as
|
|
241863
|
+
import { join as join71 } from "node:path";
|
|
241864
|
+
import { createInterface as createInterface10 } from "node:readline";
|
|
241204
241865
|
import { setTimeout as sleep12 } from "node:timers/promises";
|
|
241205
241866
|
async function listCodexModels(cwd2, env6) {
|
|
241206
241867
|
const controller = new AbortController;
|
|
@@ -241284,7 +241945,7 @@ class CodexAppServerClient {
|
|
|
241284
241945
|
this.transport = transport3;
|
|
241285
241946
|
this.onNotification = onNotification;
|
|
241286
241947
|
this.onClose = onClose;
|
|
241287
|
-
const stdout =
|
|
241948
|
+
const stdout = createInterface10({ input: transport3.stdout });
|
|
241288
241949
|
stdout.once("error", () => void this.close());
|
|
241289
241950
|
stdout.on("line", (line) => {
|
|
241290
241951
|
if (!line.trim())
|
|
@@ -241322,7 +241983,7 @@ class CodexAppServerClient {
|
|
|
241322
241983
|
await this.request("initialize", {
|
|
241323
241984
|
clientInfo: {
|
|
241324
241985
|
name: "letta-code",
|
|
241325
|
-
version: "0.34.
|
|
241986
|
+
version: "0.34.72"
|
|
241326
241987
|
},
|
|
241327
241988
|
capabilities: null
|
|
241328
241989
|
});
|
|
@@ -241382,8 +242043,8 @@ class CodexAppServerClient {
|
|
|
241382
242043
|
}
|
|
241383
242044
|
function failSession(session3, error4) {
|
|
241384
242045
|
clearIdleSessionCleanup(session3);
|
|
241385
|
-
if (
|
|
241386
|
-
|
|
242046
|
+
if (sessions3.get(session3.threadId) === session3)
|
|
242047
|
+
sessions3.delete(session3.threadId);
|
|
241387
242048
|
const waiter = session3.activeWaiter;
|
|
241388
242049
|
session3.activeTurnId = undefined;
|
|
241389
242050
|
session3.activeWaiter = undefined;
|
|
@@ -241526,8 +242187,8 @@ function clearIdleSessionCleanup(session3) {
|
|
|
241526
242187
|
}
|
|
241527
242188
|
function disposeSession(session3) {
|
|
241528
242189
|
clearIdleSessionCleanup(session3);
|
|
241529
|
-
if (
|
|
241530
|
-
|
|
242190
|
+
if (sessions3.get(session3.threadId) === session3)
|
|
242191
|
+
sessions3.delete(session3.threadId);
|
|
241531
242192
|
session3.client.dispose();
|
|
241532
242193
|
}
|
|
241533
242194
|
function scheduleIdleSessionCleanup(session3) {
|
|
@@ -241583,7 +242244,7 @@ async function createSession(options, deps) {
|
|
|
241583
242244
|
try {
|
|
241584
242245
|
await client.initialize();
|
|
241585
242246
|
await assertCodexSignedIn(client);
|
|
241586
|
-
trace = deps.createTransport ? undefined : await traceCodexLaunch(options.traceContext, env6, client);
|
|
242247
|
+
trace = deps.createTransport ? undefined : await traceCodexLaunch(options.traceContext, env6, client, options.resumeThreadId);
|
|
241587
242248
|
if (trace) {
|
|
241588
242249
|
client.dispose();
|
|
241589
242250
|
transport3 = spawnTransport({
|
|
@@ -241600,12 +242261,13 @@ async function createSession(options, deps) {
|
|
|
241600
242261
|
});
|
|
241601
242262
|
if (options.cloudSkillRepositories?.length) {
|
|
241602
242263
|
await client.request("skills/extraRoots/set", {
|
|
241603
|
-
extraRoots: cloudRepositoryRoots(options.cloudSkillRepositories).map((root2) =>
|
|
242264
|
+
extraRoots: cloudRepositoryRoots(options.cloudSkillRepositories).map((root2) => join71(root2, PROJECT_SKILLS_DIR))
|
|
241604
242265
|
});
|
|
241605
242266
|
}
|
|
241606
242267
|
const method2 = options.resumeThreadId ? "thread/resume" : "thread/start";
|
|
241607
242268
|
const params = options.resumeThreadId ? {
|
|
241608
242269
|
threadId: options.resumeThreadId,
|
|
242270
|
+
model: options.model,
|
|
241609
242271
|
...options.mcpReminder ? { developerInstructions: options.mcpReminder } : {}
|
|
241610
242272
|
} : {
|
|
241611
242273
|
cwd: options.cwd,
|
|
@@ -241614,7 +242276,7 @@ async function createSession(options, deps) {
|
|
|
241614
242276
|
sandbox: "danger-full-access",
|
|
241615
242277
|
developerInstructions: options.mcpReminder
|
|
241616
242278
|
};
|
|
241617
|
-
response = await client.request(method2,
|
|
242279
|
+
response = await client.request(method2, params);
|
|
241618
242280
|
} catch (error4) {
|
|
241619
242281
|
trace?.close();
|
|
241620
242282
|
client.dispose();
|
|
@@ -241636,13 +242298,13 @@ async function createSession(options, deps) {
|
|
|
241636
242298
|
client,
|
|
241637
242299
|
cwd: readString3(thread, "cwd") ?? options.cwd,
|
|
241638
242300
|
parentAgentId: options.parentAgentId,
|
|
241639
|
-
model: options.model,
|
|
242301
|
+
model: readString3(response, "model") ?? options.model,
|
|
241640
242302
|
startLock: Promise.resolve(),
|
|
241641
242303
|
pendingNotifications,
|
|
241642
242304
|
idleTimeoutMs: deps.idleTimeoutMs ?? DEFAULT_IDLE_TIMEOUT_MS,
|
|
241643
242305
|
sleep: deps.sleep ?? sleep12
|
|
241644
242306
|
};
|
|
241645
|
-
|
|
242307
|
+
sessions3.set(threadId, session3);
|
|
241646
242308
|
return session3;
|
|
241647
242309
|
}
|
|
241648
242310
|
async function startTurnAttempt(session3, prompt, startedAt, listeners6) {
|
|
@@ -241654,7 +242316,6 @@ async function startTurnAttempt(session3, prompt, startedAt, listeners6) {
|
|
|
241654
242316
|
threadId: session3.threadId,
|
|
241655
242317
|
input: textInput(prompt),
|
|
241656
242318
|
cwd: session3.cwd,
|
|
241657
|
-
model: session3.model,
|
|
241658
242319
|
approvalPolicy: "never",
|
|
241659
242320
|
sandboxPolicy: { type: "dangerFullAccess" }
|
|
241660
242321
|
});
|
|
@@ -241763,7 +242424,7 @@ async function startCodexTurn(options, deps = {}) {
|
|
|
241763
242424
|
}
|
|
241764
242425
|
}
|
|
241765
242426
|
async function resumeSession(threadId, options, deps) {
|
|
241766
|
-
const loaded =
|
|
242427
|
+
const loaded = sessions3.get(threadId);
|
|
241767
242428
|
if (loaded) {
|
|
241768
242429
|
clearIdleSessionCleanup(loaded);
|
|
241769
242430
|
return loaded;
|
|
@@ -241823,7 +242484,7 @@ async function sendCodexMessage(options, deps = {}) {
|
|
|
241823
242484
|
};
|
|
241824
242485
|
}));
|
|
241825
242486
|
} catch (error4) {
|
|
241826
|
-
if (!session3.activeTurnId &&
|
|
242487
|
+
if (!session3.activeTurnId && sessions3.get(session3.threadId) === session3) {
|
|
241827
242488
|
scheduleIdleSessionCleanup(session3);
|
|
241828
242489
|
}
|
|
241829
242490
|
throw error4;
|
|
@@ -241844,15 +242505,15 @@ async function runCodexTurn(options, deps = {}) {
|
|
|
241844
242505
|
}
|
|
241845
242506
|
}
|
|
241846
242507
|
async function stopCodexSession(threadId) {
|
|
241847
|
-
const session3 =
|
|
242508
|
+
const session3 = sessions3.get(threadId);
|
|
241848
242509
|
if (!session3)
|
|
241849
242510
|
return false;
|
|
241850
242511
|
await session3.client.stop();
|
|
241851
|
-
if (
|
|
241852
|
-
|
|
242512
|
+
if (sessions3.get(threadId) === session3)
|
|
242513
|
+
sessions3.delete(threadId);
|
|
241853
242514
|
return true;
|
|
241854
242515
|
}
|
|
241855
|
-
var
|
|
242516
|
+
var sessions3, sessionCreations, DEFAULT_IDLE_TIMEOUT_MS, CODEX_NOT_SIGNED_IN_ERROR = "Codex is not signed in. Run `codex login` on this computer.";
|
|
241856
242517
|
var init_codex_app_server = __esm(() => {
|
|
241857
242518
|
init_skills5();
|
|
241858
242519
|
init_subagent_process();
|
|
@@ -241862,7 +242523,7 @@ var init_codex_app_server = __esm(() => {
|
|
|
241862
242523
|
init_codex_steer_receipt();
|
|
241863
242524
|
init_external_llm_trace_launch();
|
|
241864
242525
|
init_external_llm_trace_session();
|
|
241865
|
-
|
|
242526
|
+
sessions3 = new Map;
|
|
241866
242527
|
sessionCreations = new Map;
|
|
241867
242528
|
DEFAULT_IDLE_TIMEOUT_MS = 5 * 60000;
|
|
241868
242529
|
});
|
|
@@ -241870,8 +242531,8 @@ var init_codex_app_server = __esm(() => {
|
|
|
241870
242531
|
// src/tools/impl/cursor-session.ts
|
|
241871
242532
|
import { randomUUID as randomUUID41 } from "node:crypto";
|
|
241872
242533
|
import { existsSync as existsSync47 } from "node:fs";
|
|
241873
|
-
import { join as
|
|
241874
|
-
import { createInterface as
|
|
242534
|
+
import { join as join72 } from "node:path";
|
|
242535
|
+
import { createInterface as createInterface11 } from "node:readline";
|
|
241875
242536
|
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
241876
242537
|
function key2(options, id) {
|
|
241877
242538
|
if (!UUID.test(id) || !/^[\w-]+$/.test(options.parentAgentId))
|
|
@@ -241904,7 +242565,7 @@ async function runCursorTurn(options, env6 = process.env, secrets2 = {}) {
|
|
|
241904
242565
|
try {
|
|
241905
242566
|
options.signal?.throwIfAborted();
|
|
241906
242567
|
sessionKey = key2(options, id);
|
|
241907
|
-
if (
|
|
242568
|
+
if (sessions4.has(sessionKey))
|
|
241908
242569
|
throw new Error("Cursor session already has an active turn");
|
|
241909
242570
|
if (!env6.CURSOR_API_KEY)
|
|
241910
242571
|
throw new Error("Cursor is not signed in: add CURSOR_API_KEY to the agent's secrets or the selected computer's environment.");
|
|
@@ -241937,7 +242598,7 @@ async function runCursorTurn(options, env6 = process.env, secrets2 = {}) {
|
|
|
241937
242598
|
let stderr = "";
|
|
241938
242599
|
let requestId = 0;
|
|
241939
242600
|
const pending2 = new Map;
|
|
241940
|
-
const output =
|
|
242601
|
+
const output = createInterface11({ input: running.process.stdout });
|
|
241941
242602
|
running.process.stderr.on("data", (chunk2) => {
|
|
241942
242603
|
stderr = (stderr + chunk2).slice(-8192);
|
|
241943
242604
|
});
|
|
@@ -242021,12 +242682,12 @@ async function runCursorTurn(options, env6 = process.env, secrets2 = {}) {
|
|
|
242021
242682
|
await completion;
|
|
242022
242683
|
}
|
|
242023
242684
|
};
|
|
242024
|
-
|
|
242685
|
+
sessions4.set(sessionKey, active);
|
|
242025
242686
|
const command = {
|
|
242026
242687
|
type: "start",
|
|
242027
242688
|
sessionId: id,
|
|
242028
242689
|
resume: !!options.resumeSessionId,
|
|
242029
|
-
stateDir:
|
|
242690
|
+
stateDir: join72(resolveGlobalConfigDir(), "cursor-sessions", sessionKey),
|
|
242030
242691
|
cwd: options.cwd,
|
|
242031
242692
|
model: options.model,
|
|
242032
242693
|
reminder: options.mcpReminder,
|
|
@@ -242045,8 +242706,8 @@ async function runCursorTurn(options, env6 = process.env, secrets2 = {}) {
|
|
|
242045
242706
|
durationMs: Date.now() - startedAt
|
|
242046
242707
|
};
|
|
242047
242708
|
} finally {
|
|
242048
|
-
if (sessionKey && active &&
|
|
242049
|
-
|
|
242709
|
+
if (sessionKey && active && sessions4.get(sessionKey) === active)
|
|
242710
|
+
sessions4.delete(sessionKey);
|
|
242050
242711
|
}
|
|
242051
242712
|
}
|
|
242052
242713
|
async function sendCursorMessage(options, env6 = process.env, secrets2 = {}) {
|
|
@@ -242056,7 +242717,7 @@ async function sendCursorMessage(options, env6 = process.env, secrets2 = {}) {
|
|
|
242056
242717
|
return;
|
|
242057
242718
|
}).then(async () => {
|
|
242058
242719
|
options.signal?.throwIfAborted();
|
|
242059
|
-
const active =
|
|
242720
|
+
const active = sessions4.get(sessionKey);
|
|
242060
242721
|
const tail2 = queued.get(sessionKey);
|
|
242061
242722
|
if ((!tail2 || tail2.started) && active && await active.steer(options.prompt))
|
|
242062
242723
|
return { mode: "steered" };
|
|
@@ -242115,7 +242776,7 @@ async function listCursorModels(cwd2, env6, timeoutMs = 30000) {
|
|
|
242115
242776
|
const running = spawnManagedWorkloadProcess(process.execPath, [resolveCursorWorkerPath()], { cwd: cwd2, env: env6, signal: controller.signal });
|
|
242116
242777
|
let event;
|
|
242117
242778
|
let stderr = "";
|
|
242118
|
-
const output =
|
|
242779
|
+
const output = createInterface11({ input: running.process.stdout });
|
|
242119
242780
|
output.on("line", (line) => {
|
|
242120
242781
|
if (line.startsWith("letta-cursor:"))
|
|
242121
242782
|
event = JSON.parse(line.slice("letta-cursor:".length));
|
|
@@ -242142,14 +242803,14 @@ async function listCursorModels(cwd2, env6, timeoutMs = 30000) {
|
|
|
242142
242803
|
}
|
|
242143
242804
|
throw new Error(controller.signal.aborted ? "Cursor model discovery timed out" : event?.type === "error" ? event.error : `Cursor exited without a model catalog: ${stderr}`);
|
|
242144
242805
|
}
|
|
242145
|
-
var
|
|
242806
|
+
var sessions4, queued, followupControllers, locks, UUID;
|
|
242146
242807
|
var init_cursor_session = __esm(() => {
|
|
242147
242808
|
init_subagent_depth();
|
|
242148
242809
|
init_subagent_process();
|
|
242149
242810
|
init_runtime_context();
|
|
242150
242811
|
init_secret_substitution();
|
|
242151
242812
|
init_settings_path();
|
|
242152
|
-
|
|
242813
|
+
sessions4 = new Map;
|
|
242153
242814
|
queued = new Map;
|
|
242154
242815
|
followupControllers = new Set;
|
|
242155
242816
|
locks = new Map;
|
|
@@ -243125,41 +243786,6 @@ var init_engine = __esm(() => {
|
|
|
243125
243786
|
assertSharedReminderCoverage();
|
|
243126
243787
|
});
|
|
243127
243788
|
|
|
243128
|
-
// src/tools/impl/native-session-owner.ts
|
|
243129
|
-
import { createHash as createHash11 } from "node:crypto";
|
|
243130
|
-
import { mkdirSync as mkdirSync38, readFileSync as readFileSync41, rmSync as rmSync16, writeFileSync as writeFileSync33 } from "node:fs";
|
|
243131
|
-
import { join as join72 } from "node:path";
|
|
243132
|
-
function ownerPath(source, sessionId) {
|
|
243133
|
-
const id = createHash11("sha256").update(`${source}:${sessionId}`).digest("hex");
|
|
243134
|
-
return join72(resolveGlobalConfigDir(), "native-session-owners", `${id}.json`);
|
|
243135
|
-
}
|
|
243136
|
-
function readNativeSessionOwner(source, sessionId) {
|
|
243137
|
-
try {
|
|
243138
|
-
const owner = JSON.parse(readFileSync41(ownerPath(source, sessionId), "utf8"));
|
|
243139
|
-
if (typeof owner.agentId === "string" && typeof owner.conversationId === "string" && (owner.cloudSkillRepositories === undefined || isCloudRepositoryNames(owner.cloudSkillRepositories)))
|
|
243140
|
-
return owner;
|
|
243141
|
-
throw new Error("Invalid native session owner record");
|
|
243142
|
-
} catch (error4) {
|
|
243143
|
-
if (error4.code !== "ENOENT")
|
|
243144
|
-
throw error4;
|
|
243145
|
-
}
|
|
243146
|
-
return;
|
|
243147
|
-
}
|
|
243148
|
-
function persistNativeSessionOwner(source, sessionId, scope) {
|
|
243149
|
-
const path30 = ownerPath(source, sessionId);
|
|
243150
|
-
mkdirSync38(join72(path30, ".."), { recursive: true, mode: 448 });
|
|
243151
|
-
try {
|
|
243152
|
-
writeFileSync33(path30, JSON.stringify(scope), { flag: "wx", mode: 384 });
|
|
243153
|
-
} catch (error4) {
|
|
243154
|
-
if (error4.code !== "EEXIST")
|
|
243155
|
-
throw error4;
|
|
243156
|
-
}
|
|
243157
|
-
}
|
|
243158
|
-
var init_native_session_owner = __esm(() => {
|
|
243159
|
-
init_cloud_repository_roots();
|
|
243160
|
-
init_settings_path();
|
|
243161
|
-
});
|
|
243162
|
-
|
|
243163
243789
|
// src/tools/impl/native-session-capture.ts
|
|
243164
243790
|
import { createHash as createHash12, randomUUID as randomUUID42 } from "node:crypto";
|
|
243165
243791
|
import { readdirSync as readdirSync18, rmSync as rmSync17 } from "node:fs";
|
|
@@ -243949,8 +244575,8 @@ function dispose(session3, error4) {
|
|
|
243949
244575
|
if (session3.stopping)
|
|
243950
244576
|
return session3.stopping;
|
|
243951
244577
|
clearTimeout(session3.idleTimer);
|
|
243952
|
-
if (
|
|
243953
|
-
|
|
244578
|
+
if (sessions5.get(session3.id) === session3)
|
|
244579
|
+
sessions5.delete(session3.id);
|
|
243954
244580
|
session3.stopping = session3.server.close().then(() => {
|
|
243955
244581
|
if (session3.active)
|
|
243956
244582
|
finish(session3, session3.active, {
|
|
@@ -244033,7 +244659,7 @@ async function createSession2(options, env6) {
|
|
|
244033
244659
|
lock: Promise.resolve()
|
|
244034
244660
|
};
|
|
244035
244661
|
const stream11 = await server2.events((event) => onEvent(session3, event));
|
|
244036
|
-
|
|
244662
|
+
sessions5.set(session3.id, session3);
|
|
244037
244663
|
stream11.completion.catch((error4) => dispose(session3, message(error4)));
|
|
244038
244664
|
return session3;
|
|
244039
244665
|
} catch (error4) {
|
|
@@ -244047,7 +244673,7 @@ async function getSession(options, env6) {
|
|
|
244047
244673
|
const id = options.resumeSessionId;
|
|
244048
244674
|
if (!id)
|
|
244049
244675
|
return createSession2(options, env6);
|
|
244050
|
-
const loaded =
|
|
244676
|
+
const loaded = sessions5.get(id);
|
|
244051
244677
|
if (loaded)
|
|
244052
244678
|
return loaded;
|
|
244053
244679
|
const pending2 = creations.get(id);
|
|
@@ -244166,11 +244792,11 @@ async function sendOpenCodeMessage(options, env6 = process.env) {
|
|
|
244166
244792
|
};
|
|
244167
244793
|
});
|
|
244168
244794
|
}
|
|
244169
|
-
var
|
|
244795
|
+
var sessions5, creations;
|
|
244170
244796
|
var init_opencode_session = __esm(() => {
|
|
244171
244797
|
init_subagent_depth();
|
|
244172
244798
|
init_opencode_server();
|
|
244173
|
-
|
|
244799
|
+
sessions5 = new Map;
|
|
244174
244800
|
creations = new Map;
|
|
244175
244801
|
});
|
|
244176
244802
|
|
|
@@ -244345,7 +244971,7 @@ async function defaultRunPreflight(executable, args, env6, signal) {
|
|
|
244345
244971
|
function classifyExternalCodingAgentStartupError(error4) {
|
|
244346
244972
|
if (error4.startsWith(MISSING_EXECUTABLE_PREFIX) || error4.startsWith(CODEX_NOT_READY_PREFIX))
|
|
244347
244973
|
return "not_installed";
|
|
244348
|
-
if (error4.startsWith(CLAUDE_NOT_SIGNED_IN_PREFIX) || error4.startsWith(CODEX_NOT_SIGNED_IN_ERROR) || error4.startsWith("Cursor is not signed in:"))
|
|
244974
|
+
if (error4.startsWith(CLAUDE_NOT_SIGNED_IN_PREFIX) || error4.startsWith(CODEX_NOT_SIGNED_IN_ERROR) || error4.startsWith("Cursor is not signed in:") || error4.startsWith("Antigravity is not signed in:"))
|
|
244349
244975
|
return "not_signed_in";
|
|
244350
244976
|
return;
|
|
244351
244977
|
}
|
|
@@ -244473,12 +245099,16 @@ function scrubWorkerListeners(listeners6, secretEnv) {
|
|
|
244473
245099
|
async function runExternalCodingAgent(options, deps = {}) {
|
|
244474
245100
|
const startedAt = Date.now();
|
|
244475
245101
|
const { env: env6, secretEnv, mcpReminder } = await buildExternalWorkerLaunchEnv(options, deps);
|
|
245102
|
+
if (options.type === "antigravity" && env6.GEMINI_API_KEY)
|
|
245103
|
+
secretEnv.GEMINI_API_KEY = env6.GEMINI_API_KEY;
|
|
244476
245104
|
options = {
|
|
244477
245105
|
...options,
|
|
244478
245106
|
...scrubWorkerListeners(options, secretEnv),
|
|
244479
245107
|
mcpReminder
|
|
244480
245108
|
};
|
|
244481
245109
|
const cwd2 = options.cwd ?? getCurrentWorkingDirectory();
|
|
245110
|
+
if (options.type === "antigravity")
|
|
245111
|
+
return runAntigravityTurn({ ...options, cwd: cwd2 }, env6, secretEnv);
|
|
244482
245112
|
const captureActingUserId = options.actingUserId !== undefined ? options.actingUserId : getRuntimeActingUserAttribution();
|
|
244483
245113
|
const scope = options.parentConversationId ? {
|
|
244484
245114
|
agentId: options.parentAgentId,
|
|
@@ -244553,7 +245183,8 @@ async function runExternalCodingAgent(options, deps = {}) {
|
|
|
244553
245183
|
secretValues: Object.values(secretEnv),
|
|
244554
245184
|
parent_agent_id: scope.agentId,
|
|
244555
245185
|
parent_conversation_id: scope.conversationId,
|
|
244556
|
-
task_id: options.taskId ?? randomUUID44()
|
|
245186
|
+
task_id: options.taskId ?? randomUUID44(),
|
|
245187
|
+
task_description: options.description
|
|
244557
245188
|
} : undefined,
|
|
244558
245189
|
prompt: options.prompt,
|
|
244559
245190
|
parentAgentId: options.parentAgentId,
|
|
@@ -244607,7 +245238,8 @@ async function runExternalCodingAgent(options, deps = {}) {
|
|
|
244607
245238
|
secretValues: Object.values(secretEnv),
|
|
244608
245239
|
parent_agent_id: scope.agentId,
|
|
244609
245240
|
parent_conversation_id: scope.conversationId,
|
|
244610
|
-
task_id: options.taskId ?? randomUUID44()
|
|
245241
|
+
task_id: options.taskId ?? randomUUID44(),
|
|
245242
|
+
task_description: options.description
|
|
244611
245243
|
} : undefined,
|
|
244612
245244
|
prompt: options.prompt,
|
|
244613
245245
|
parentAgentId: options.parentAgentId,
|
|
@@ -244668,18 +245300,21 @@ var init_external_coding_agent = __esm(() => {
|
|
|
244668
245300
|
init_secret_substitution();
|
|
244669
245301
|
init_debug();
|
|
244670
245302
|
init_native_cli_env();
|
|
245303
|
+
init_antigravity_session();
|
|
244671
245304
|
init_claude_stream_session();
|
|
244672
245305
|
init_codex_app_server();
|
|
244673
245306
|
init_cursor_session();
|
|
244674
245307
|
init_native_session_capture();
|
|
244675
245308
|
init_opencode_session();
|
|
244676
245309
|
EXTERNAL_CODING_AGENT_TYPES = [
|
|
245310
|
+
"antigravity",
|
|
244677
245311
|
"claude-code",
|
|
244678
245312
|
"codex",
|
|
244679
245313
|
"opencode",
|
|
244680
245314
|
"cursor"
|
|
244681
245315
|
];
|
|
244682
245316
|
EXTERNAL_AGENT_ID_PREFIXES = {
|
|
245317
|
+
antigravity: "antigravity_",
|
|
244683
245318
|
"claude-code": "claude_",
|
|
244684
245319
|
codex: "codex_",
|
|
244685
245320
|
opencode: "opencode_",
|
|
@@ -244695,15 +245330,8 @@ function deadlineFor(timeoutMs) {
|
|
|
244695
245330
|
function deadlineReached(deadline) {
|
|
244696
245331
|
return deadline !== null && Date.now() >= deadline;
|
|
244697
245332
|
}
|
|
244698
|
-
|
|
244699
|
-
|
|
244700
|
-
while (!signal?.aborted) {
|
|
244701
|
-
const agent = getSnapshot2().agents.find((entry) => entry.id === subagentId);
|
|
244702
|
-
if (!agent || agent.agentURL || agent.conversationId || agent.status === "error" || agent.status === "completed" || deadlineReached(deadline)) {
|
|
244703
|
-
return;
|
|
244704
|
-
}
|
|
244705
|
-
await sleep9(BACKGROUND_STARTUP_POLL_MS);
|
|
244706
|
-
}
|
|
245333
|
+
function waitForBackgroundSubagentLink(subagentId, timeoutMs = null, signal) {
|
|
245334
|
+
return waitForBackgroundSubagentConversationId(subagentId, timeoutMs, signal);
|
|
244707
245335
|
}
|
|
244708
245336
|
async function waitForBackgroundSubagentAgentId(subagentId, timeoutMs = null, signal) {
|
|
244709
245337
|
const deadline = deadlineFor(timeoutMs);
|
|
@@ -245564,6 +246192,7 @@ async function executeSubagent(type, config2, model2, userPrompt, subagentId, is
|
|
|
245564
246192
|
actingUserId: actingUserIdOverride,
|
|
245565
246193
|
transcriptPath,
|
|
245566
246194
|
subagentId,
|
|
246195
|
+
subagentSummary: existingAgentId || existingConversationId ? undefined : getSubagents().find((agent) => agent.id === subagentId)?.description,
|
|
245567
246196
|
subagentName: existingAgentId || existingConversationId ? undefined : allocateSubagentName(parentAgentName)
|
|
245568
246197
|
});
|
|
245569
246198
|
delete childEnv[SUBAGENT_CLOUD_OPTIONS_ENV];
|
|
@@ -246664,23 +247293,29 @@ var init_remote_connect_retry = __esm(() => {
|
|
|
246664
247293
|
async function resolveExternalWorkerComputer(computer, scope, cloudOptions) {
|
|
246665
247294
|
if (!isCloudEnvironmentSelector(computer))
|
|
246666
247295
|
return resolveEnvironmentConnectionId(computer);
|
|
246667
|
-
const client = await getClient();
|
|
246668
247296
|
const parentConversationId = scope.conversationId && scope.conversationId !== "default" ? scope.conversationId : undefined;
|
|
246669
247297
|
const createParams = {
|
|
246670
247298
|
agent_id: scope.agentId,
|
|
246671
247299
|
hidden: true,
|
|
246672
247300
|
...parentConversationId ? { parent_conversation_id: parentConversationId } : {}
|
|
246673
247301
|
};
|
|
246674
|
-
|
|
246675
|
-
|
|
246676
|
-
|
|
246677
|
-
|
|
246678
|
-
|
|
246679
|
-
|
|
246680
|
-
|
|
247302
|
+
let conversationId;
|
|
247303
|
+
try {
|
|
247304
|
+
const client = await getClient();
|
|
247305
|
+
const conversation = await client.conversations.create(createParams).catch((error4) => {
|
|
247306
|
+
if (!parentConversationId || !error4 || typeof error4 !== "object" || !("status" in error4) || error4.status !== 403) {
|
|
247307
|
+
throw error4;
|
|
247308
|
+
}
|
|
247309
|
+
const fallbackParams = { agent_id: scope.agentId, hidden: true };
|
|
247310
|
+
return client.conversations.create(fallbackParams);
|
|
247311
|
+
});
|
|
247312
|
+
conversationId = conversation.id;
|
|
247313
|
+
} catch (error4) {
|
|
247314
|
+
throw new ComputerResolutionError("cloud_conversation_create_failed", error4 instanceof Error ? error4.message : String(error4), error4);
|
|
247315
|
+
}
|
|
246681
247316
|
return resolveAgentSandboxConnectionId(scope.agentId, {
|
|
246682
247317
|
...cloudOptions,
|
|
246683
|
-
conversationId
|
|
247318
|
+
conversationId
|
|
246684
247319
|
});
|
|
246685
247320
|
}
|
|
246686
247321
|
var init_remote_external_worker_computer = __esm(() => {
|
|
@@ -246813,32 +247448,35 @@ async function defaultConnect(connectionId, scope) {
|
|
|
246813
247448
|
throw error4;
|
|
246814
247449
|
}
|
|
246815
247450
|
}
|
|
246816
|
-
async function resolveQualifiedComputer(deviceId, scope) {
|
|
247451
|
+
async function resolveQualifiedComputer(deviceId, scope, resumeOnly = false) {
|
|
247452
|
+
const prefix = `sandbox-${scope.agentId}-`;
|
|
247453
|
+
const suffix = deviceId.startsWith(prefix) ? deviceId.slice(prefix.length).match(/^(conv-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})-linux-vm$/i) : null;
|
|
246817
247454
|
let environment;
|
|
246818
247455
|
try {
|
|
246819
247456
|
environment = await getEnvironmentConnection(deviceId);
|
|
246820
|
-
} catch {
|
|
246821
|
-
|
|
246822
|
-
|
|
246823
|
-
|
|
246824
|
-
|
|
246825
|
-
|
|
246826
|
-
|
|
246827
|
-
|
|
246828
|
-
|
|
246829
|
-
|
|
246830
|
-
|
|
246831
|
-
|
|
246832
|
-
|
|
246833
|
-
|
|
246834
|
-
throw new Error(`Computer "${deviceId}" is offline`);
|
|
247457
|
+
} catch (error4) {
|
|
247458
|
+
if (!(resumeOnly && suffix && error4 instanceof ApiRequestError && error4.status === 404))
|
|
247459
|
+
return resolveEnvironmentConnectionId(deviceId);
|
|
247460
|
+
}
|
|
247461
|
+
if (environment && isEnvironmentOnline(environment) && environment.connectionId)
|
|
247462
|
+
return { connectionId: environment.connectionId, environment };
|
|
247463
|
+
if (suffix && (!environment || environment.deviceId === deviceId)) {
|
|
247464
|
+
const resolved = await resolveAgentSandboxConnectionId(scope.agentId, {
|
|
247465
|
+
conversationId: suffix[1],
|
|
247466
|
+
resumeOnly
|
|
247467
|
+
});
|
|
247468
|
+
if (resolved.environment.deviceId !== deviceId)
|
|
247469
|
+
throw new Error("Cloud sandbox device changed while waking worker");
|
|
247470
|
+
return resolved;
|
|
246835
247471
|
}
|
|
246836
|
-
|
|
247472
|
+
throw new Error(`Computer "${deviceId}" is offline`);
|
|
246837
247473
|
}
|
|
246838
247474
|
function errorMessage5(error4) {
|
|
246839
247475
|
return error4 instanceof Error ? error4.message : String(error4);
|
|
246840
247476
|
}
|
|
246841
247477
|
function classifyRemoteExternalWorkerControlError(error4) {
|
|
247478
|
+
if (error4 instanceof WorkerSandboxExpiredError)
|
|
247479
|
+
return "sandbox_expired";
|
|
246842
247480
|
if (error4 instanceof ComputerResolutionError) {
|
|
246843
247481
|
return error4.code === "computer_offline" || error4.code === "computer_not_found" ? error4.code : "other";
|
|
246844
247482
|
}
|
|
@@ -247042,13 +247680,14 @@ class RemoteSubagentFollower {
|
|
|
247042
247680
|
}
|
|
247043
247681
|
async function launchRemoteExternalCodingAgent(params, deps) {
|
|
247044
247682
|
const { type, computer, parentScope } = params;
|
|
247045
|
-
const fail2 = (stage, error4, errorCode) => {
|
|
247683
|
+
const fail2 = (stage, error4, errorCode, httpStatus) => {
|
|
247046
247684
|
reportExternalWorkerLaunchFailure({
|
|
247047
247685
|
stage,
|
|
247048
247686
|
harness: type,
|
|
247049
247687
|
computer: stage === "resolve_computer" ? undefined : computer,
|
|
247050
247688
|
error: error4,
|
|
247051
247689
|
errorCode,
|
|
247690
|
+
httpStatus,
|
|
247052
247691
|
agentId: parentScope.agentId,
|
|
247053
247692
|
conversationId: parentScope.conversationId,
|
|
247054
247693
|
toolCallId: params.toolCallId
|
|
@@ -247077,7 +247716,8 @@ async function launchRemoteExternalCodingAgent(params, deps) {
|
|
|
247077
247716
|
if (outdated)
|
|
247078
247717
|
return fail2("outdated_computer", outdated);
|
|
247079
247718
|
} catch (error4) {
|
|
247080
|
-
|
|
247719
|
+
const resolutionError = error4 instanceof ComputerResolutionError ? error4 : undefined;
|
|
247720
|
+
return fail2("resolve_computer", errorMessage5(error4), resolutionError?.code, resolutionError ? resolutionError.httpStatus ?? null : undefined);
|
|
247081
247721
|
}
|
|
247082
247722
|
params.signal?.throwIfAborted();
|
|
247083
247723
|
const connect = () => (deps.connect ?? defaultConnect)(connectionId, parentScope);
|
|
@@ -247211,17 +247851,17 @@ async function launchRemoteExternalCodingAgent(params, deps) {
|
|
|
247211
247851
|
conversation_id: null
|
|
247212
247852
|
};
|
|
247213
247853
|
}
|
|
247214
|
-
async function connectQualifiedTarget(agentId, parentScope, deps) {
|
|
247854
|
+
async function connectQualifiedTarget(agentId, parentScope, deps, resumeOnly = false) {
|
|
247215
247855
|
const target = parseExternalCodingAgentId(agentId);
|
|
247216
247856
|
if (!target?.computer || target.type === "opencode")
|
|
247217
247857
|
throw new Error(`Invalid remote external coding agent ID: ${agentId}`);
|
|
247218
|
-
const resolved = await (deps.resolveComputer ?? resolveQualifiedComputer)(target.computer, parentScope);
|
|
247858
|
+
const resolved = await (deps.resolveComputer ?? resolveQualifiedComputer)(target.computer, parentScope, resumeOnly);
|
|
247219
247859
|
if (resolved.environment.metadata?.subagent_message !== true)
|
|
247220
247860
|
throw new Error(formatOutdatedSteeringError(target.computer));
|
|
247221
247861
|
return {
|
|
247222
247862
|
target,
|
|
247223
247863
|
lettaCodeVersion: resolved.environment.metadata?.lettaCodeVersion,
|
|
247224
|
-
client: await (deps.connect ?? defaultConnect)(resolved.connectionId, parentScope)
|
|
247864
|
+
client: await connectRemoteWorkerWithRetry(() => (deps.connect ?? defaultConnect)(resolved.connectionId, parentScope))
|
|
247225
247865
|
};
|
|
247226
247866
|
}
|
|
247227
247867
|
async function stopRemoteExternalCodingAgent(params, deps = {}) {
|
|
@@ -247250,6 +247890,8 @@ async function sendRemoteExternalCodingAgentMessage(params, deps = {}) {
|
|
|
247250
247890
|
try {
|
|
247251
247891
|
return await deliverRemoteExternalCodingAgentMessage(params, deps);
|
|
247252
247892
|
} catch (error4) {
|
|
247893
|
+
if (error4 instanceof WorkerSandboxExpiredError)
|
|
247894
|
+
throw error4;
|
|
247253
247895
|
const target = parseExternalCodingAgentId(params.agentId);
|
|
247254
247896
|
reportExternalWorkerLaunchFailure({
|
|
247255
247897
|
stage: error4 instanceof OutdatedRemoteWorkerError ? "outdated_computer" : "follow_up",
|
|
@@ -247266,10 +247908,10 @@ async function sendRemoteExternalCodingAgentMessage(params, deps = {}) {
|
|
|
247266
247908
|
}
|
|
247267
247909
|
async function deliverRemoteExternalCodingAgentMessage(params, deps) {
|
|
247268
247910
|
const requestId = `subagent-message-${randomUUID47()}`;
|
|
247269
|
-
const { target, client, lettaCodeVersion } = await connectQualifiedTarget(params.agentId, params.parentScope, deps);
|
|
247911
|
+
const { target, client, lettaCodeVersion } = await connectQualifiedTarget(params.agentId, params.parentScope, deps, true);
|
|
247270
247912
|
const toolCallId = params.toolCallId ?? `remote-followup-${randomUUID47()}`;
|
|
247271
247913
|
const connect = async () => {
|
|
247272
|
-
const resolved = await (deps.resolveComputer ?? resolveQualifiedComputer)(target.computer, params.parentScope);
|
|
247914
|
+
const resolved = await (deps.resolveComputer ?? resolveQualifiedComputer)(target.computer, params.parentScope, true);
|
|
247273
247915
|
return (deps.connect ?? defaultConnect)(resolved.connectionId, params.parentScope);
|
|
247274
247916
|
};
|
|
247275
247917
|
const follower = new RemoteSubagentFollower(params.parentScope, toolCallId, connect, 2000);
|
|
@@ -247378,6 +248020,7 @@ var init_remote_external_coding_agent = __esm(() => {
|
|
|
247378
248020
|
init_remote_subagent_events();
|
|
247379
248021
|
REMOTE_EXTERNAL_WORKER_STOPPED = Symbol("remote external worker stopped");
|
|
247380
248022
|
DISPLAY_NAMES = {
|
|
248023
|
+
antigravity: "Antigravity",
|
|
247381
248024
|
"claude-code": "Claude Code",
|
|
247382
248025
|
codex: "Codex",
|
|
247383
248026
|
opencode: "OpenCode",
|
|
@@ -247575,6 +248218,7 @@ async function task_stop(args, deps = {}) {
|
|
|
247575
248218
|
return finishPendingWakeCancellation(task);
|
|
247576
248219
|
if (task.status === "running" && task.abortController) {
|
|
247577
248220
|
const initialStop = task.stop;
|
|
248221
|
+
const markStopped = captureSubagentStop(task.subagentId);
|
|
247578
248222
|
const child = getSubagents().find((agent) => agent.id === task.subagentId);
|
|
247579
248223
|
const external3 = parseExternalCodingAgentId(child?.agentId ?? undefined);
|
|
247580
248224
|
let remote;
|
|
@@ -247642,6 +248286,7 @@ async function task_stop(args, deps = {}) {
|
|
|
247642
248286
|
if (!remoteExternalStopped)
|
|
247643
248287
|
throw new Error("Subagent process exit was not confirmed");
|
|
247644
248288
|
task.status = "failed";
|
|
248289
|
+
markStopped();
|
|
247645
248290
|
scheduleBackgroundTaskCleanup(task_id);
|
|
247646
248291
|
return {
|
|
247647
248292
|
killed: true,
|
|
@@ -247671,6 +248316,7 @@ async function task_stop(args, deps = {}) {
|
|
|
247671
248316
|
}
|
|
247672
248317
|
task.status = "failed";
|
|
247673
248318
|
scheduleBackgroundTaskCleanup(task_id);
|
|
248319
|
+
markStopped();
|
|
247674
248320
|
task.cancelPendingWakes = () => runWithRuntimeContext({
|
|
247675
248321
|
...scope,
|
|
247676
248322
|
actingUserId: task.actingUserId ?? undefined,
|
|
@@ -247683,6 +248329,7 @@ async function task_stop(args, deps = {}) {
|
|
|
247683
248329
|
}
|
|
247684
248330
|
task.status = "failed";
|
|
247685
248331
|
scheduleBackgroundTaskCleanup(task_id);
|
|
248332
|
+
markStopped();
|
|
247686
248333
|
return remote ?? { killed: true };
|
|
247687
248334
|
}
|
|
247688
248335
|
return { killed: false };
|
|
@@ -247881,7 +248528,14 @@ var init_Task2 = __esm(() => {
|
|
|
247881
248528
|
},
|
|
247882
248529
|
harness: {
|
|
247883
248530
|
type: "string",
|
|
247884
|
-
enum: [
|
|
248531
|
+
enum: [
|
|
248532
|
+
"letta",
|
|
248533
|
+
"claude-code",
|
|
248534
|
+
"codex",
|
|
248535
|
+
"cursor",
|
|
248536
|
+
"opencode",
|
|
248537
|
+
"antigravity"
|
|
248538
|
+
],
|
|
247885
248539
|
description: "The harness that executes the task. Defaults to letta (a Letta subagent). Set to override the harness that runs the subagent worker (requires the harness to be installed on the computer)."
|
|
247886
248540
|
},
|
|
247887
248541
|
subagent_type: {
|
|
@@ -248118,6 +248772,8 @@ function spawnBackgroundSubagentTask(args) {
|
|
|
248118
248772
|
openTaskProgressLog(subagentId, outputFile, resolvedParentScope?.agentId);
|
|
248119
248773
|
if (publishResult)
|
|
248120
248774
|
serveTaskEvents(subagentId);
|
|
248775
|
+
if (args.observePersistedState)
|
|
248776
|
+
observeSubagentState(subagentId, args.observePersistedState());
|
|
248121
248777
|
const parentAgentIdForSpawn = resolvedParentScope?.agentId;
|
|
248122
248778
|
const workerMemoryDir = subagentType === "memory" && resolvedParentScope ? memoryScope?.primaryRoot ?? getScopedMemoryFilesystemRoot(resolvedParentScope.agentId) : undefined;
|
|
248123
248779
|
const effectiveMemoryScope = memoryScope ?? (workerMemoryDir ? { primaryRoot: workerMemoryDir, writableRoots: [workerMemoryDir] } : undefined);
|
|
@@ -248158,7 +248814,10 @@ function spawnBackgroundSubagentTask(args) {
|
|
|
248158
248814
|
...publishResult && result3.success ? {
|
|
248159
248815
|
result: truncateByChars(result3.report || "", LIMITS.TASK_OUTPUT_CHARS, "Task", { workingDirectory: getCurrentWorkingDirectory() }).content
|
|
248160
248816
|
} : {}
|
|
248161
|
-
}
|
|
248817
|
+
}, args.observePersistedState ? {
|
|
248818
|
+
agentId: result3.agentId || existingAgentId,
|
|
248819
|
+
conversationId: result3.conversationId || existingConversationId
|
|
248820
|
+
} : undefined);
|
|
248162
248821
|
try {
|
|
248163
248822
|
await onComplete?.({
|
|
248164
248823
|
success: result3.success,
|
|
@@ -248352,9 +249011,10 @@ async function launchSubagent(args, cloudSkillRepositories) {
|
|
|
248352
249011
|
if (resolvedComputer.error) {
|
|
248353
249012
|
return { success: false, error: resolvedComputer.error };
|
|
248354
249013
|
}
|
|
248355
|
-
const cloud = parseTaskCloudOptions(
|
|
249014
|
+
const cloud = parseTaskCloudOptions(resolvedComputer.computer, args.cloud);
|
|
248356
249015
|
if ("error" in cloud)
|
|
248357
249016
|
return { success: false, error: cloud.error };
|
|
249017
|
+
const observePersistedState = args.notifyCaller ? undefined : createLaunchSubagentObserver(resolvedParentScope, args, description, inputPrompt, externalCodingAgentType ?? "letta", Boolean(config2.fork), resolvedComputer.computer, cloud.options);
|
|
248358
249018
|
let effectiveAgentId = args.agent_id;
|
|
248359
249019
|
let effectiveConversationId = args.conversation_id;
|
|
248360
249020
|
const callerNotification = args.notifyCaller ? {
|
|
@@ -248387,7 +249047,9 @@ async function launchSubagent(args, cloudSkillRepositories) {
|
|
|
248387
249047
|
agentId: parentAgentId
|
|
248388
249048
|
},
|
|
248389
249049
|
signal
|
|
248390
|
-
}, {
|
|
249050
|
+
}, {
|
|
249051
|
+
spawn: (task) => spawnBackgroundSubagentTask({ ...task, observePersistedState })
|
|
249052
|
+
});
|
|
248391
249053
|
}
|
|
248392
249054
|
const worker = await prepareExternalWorkerPrompt({
|
|
248393
249055
|
prompt: inputPrompt,
|
|
@@ -248410,6 +249072,7 @@ async function launchSubagent(args, cloudSkillRepositories) {
|
|
|
248410
249072
|
const { taskId: taskId2, outputFile: outputFile2, subagentId: subagentId2 } = spawnBackgroundSubagentTask({
|
|
248411
249073
|
subagentType: configName,
|
|
248412
249074
|
config: config2,
|
|
249075
|
+
observePersistedState,
|
|
248413
249076
|
prompt: worker.prompt,
|
|
248414
249077
|
description,
|
|
248415
249078
|
model: model2,
|
|
@@ -248512,6 +249175,7 @@ async function launchSubagent(args, cloudSkillRepositories) {
|
|
|
248512
249175
|
description,
|
|
248513
249176
|
model: model2,
|
|
248514
249177
|
toolCallId,
|
|
249178
|
+
observePersistedState,
|
|
248515
249179
|
existingAgentId: effectiveAgentId,
|
|
248516
249180
|
existingConversationId: effectiveConversationId,
|
|
248517
249181
|
maxTurns: args.max_turns,
|
|
@@ -248524,10 +249188,11 @@ async function launchSubagent(args, cloudSkillRepositories) {
|
|
|
248524
249188
|
});
|
|
248525
249189
|
const abortStartup = () => backgroundTasks.get(taskId)?.abortController?.abort(signal?.reason);
|
|
248526
249190
|
signal?.addEventListener("abort", abortStartup, { once: true });
|
|
249191
|
+
let linkedConversationId;
|
|
248527
249192
|
try {
|
|
248528
249193
|
if (signal?.aborted)
|
|
248529
249194
|
abortStartup();
|
|
248530
|
-
await waitForBackgroundSubagentLink(subagentId, null, signal);
|
|
249195
|
+
linkedConversationId = await waitForBackgroundSubagentLink(subagentId, null, signal);
|
|
248531
249196
|
signal?.throwIfAborted();
|
|
248532
249197
|
} finally {
|
|
248533
249198
|
signal?.removeEventListener("abort", abortStartup);
|
|
@@ -248539,7 +249204,7 @@ async function launchSubagent(args, cloudSkillRepositories) {
|
|
|
248539
249204
|
error: backgroundTasks.get(taskId)?.error ?? "Subagent launch failed"
|
|
248540
249205
|
};
|
|
248541
249206
|
}
|
|
248542
|
-
const conversationId = linkedAgent?.conversationId ?? effectiveConversationId ?? null;
|
|
249207
|
+
const conversationId = linkedConversationId ?? linkedAgent?.conversationId ?? effectiveConversationId ?? null;
|
|
248543
249208
|
if (!isDeployingExisting)
|
|
248544
249209
|
recordTaskSummary(conversationId, description);
|
|
248545
249210
|
return {
|
|
@@ -248596,6 +249261,7 @@ var init_task = __esm(() => {
|
|
|
248596
249261
|
init_process_manager();
|
|
248597
249262
|
init_remote_external_coding_agent();
|
|
248598
249263
|
init_subagent_computer();
|
|
249264
|
+
init_subagent_persistence();
|
|
248599
249265
|
init_task_abort_hook();
|
|
248600
249266
|
init_task_agent_selection();
|
|
248601
249267
|
init_task_cloud_options();
|
|
@@ -248608,6 +249274,15 @@ var init_task = __esm(() => {
|
|
|
248608
249274
|
// src/tools/impl/external-coding-agent-task.ts
|
|
248609
249275
|
function trackExternalFollowupCompletion(args) {
|
|
248610
249276
|
return spawnBackgroundSubagentTask({
|
|
249277
|
+
observePersistedState: args.publishResult ? undefined : () => {
|
|
249278
|
+
const writer = resumeSubagentWriter(args.parentScope.conversationId, { worker_session_id: args.agentId }, args.parentScope.actingUserId === undefined ? getRuntimeActingUserAttribution() : args.parentScope.actingUserId);
|
|
249279
|
+
let stopped = false;
|
|
249280
|
+
return (state2) => {
|
|
249281
|
+
const status = stopped ? "stopped" : persistedSubagentStatus(state2);
|
|
249282
|
+
stopped = status === "stopped";
|
|
249283
|
+
writer?.update({ status, worker_session_id: args.agentId });
|
|
249284
|
+
};
|
|
249285
|
+
},
|
|
248611
249286
|
taskId: args.taskId,
|
|
248612
249287
|
subagentType: args.type,
|
|
248613
249288
|
config: createExternalCodingAgentConfig(args.type),
|
|
@@ -248662,10 +249337,12 @@ function trackExternalFollowupCompletion(args) {
|
|
|
248662
249337
|
});
|
|
248663
249338
|
}
|
|
248664
249339
|
var init_external_coding_agent_task = __esm(() => {
|
|
249340
|
+
init_subagents3();
|
|
248665
249341
|
init_runtime_context();
|
|
248666
249342
|
init_external_coding_agent();
|
|
248667
249343
|
init_native_session_capture();
|
|
248668
249344
|
init_process_manager();
|
|
249345
|
+
init_subagent_persistence();
|
|
248669
249346
|
init_task();
|
|
248670
249347
|
init_task_transcript();
|
|
248671
249348
|
});
|
|
@@ -248754,6 +249431,8 @@ async function send_agent_message(args, deps = {}) {
|
|
|
248754
249431
|
}
|
|
248755
249432
|
args.signal?.throwIfAborted();
|
|
248756
249433
|
const parentScope = sender;
|
|
249434
|
+
const steerActingUserId = getRuntimeActingUserAttribution();
|
|
249435
|
+
const recordSteer = () => resumeSubagentWriter(parentScope.conversationId, { worker_session_id: args.agent_id }, steerActingUserId);
|
|
248757
249436
|
if (externalTarget.computer) {
|
|
248758
249437
|
const receipt3 = await (deps.sendRemoteExternalMessage ?? sendRemoteExternalCodingAgentMessage)({
|
|
248759
249438
|
agentId: args.agent_id,
|
|
@@ -248765,6 +249444,8 @@ async function send_agent_message(args, deps = {}) {
|
|
|
248765
249444
|
}, {
|
|
248766
249445
|
track: deps.trackExternalFollowup ?? trackExternalFollowupCompletion
|
|
248767
249446
|
});
|
|
249447
|
+
if (receipt3.delivery !== "resumed")
|
|
249448
|
+
recordSteer();
|
|
248768
249449
|
return {
|
|
248769
249450
|
content: JSON.stringify({
|
|
248770
249451
|
status: "accepted",
|
|
@@ -248777,7 +249458,7 @@ async function send_agent_message(args, deps = {}) {
|
|
|
248777
249458
|
status: "success"
|
|
248778
249459
|
};
|
|
248779
249460
|
}
|
|
248780
|
-
if (externalTarget.type === "opencode" || externalTarget.type === "cursor") {
|
|
249461
|
+
if (externalTarget.type === "antigravity" || externalTarget.type === "opencode" || externalTarget.type === "cursor") {
|
|
248781
249462
|
const messageOptions = {
|
|
248782
249463
|
sessionId: externalTarget.sessionId,
|
|
248783
249464
|
prompt: args.message,
|
|
@@ -248786,13 +249467,22 @@ async function send_agent_message(args, deps = {}) {
|
|
|
248786
249467
|
signal: args.signal
|
|
248787
249468
|
};
|
|
248788
249469
|
const secrets2 = externalTarget.type === "cursor" ? await resolveExternalCodingAgentSecretEnv(parentScope.agentId) : {};
|
|
248789
|
-
const
|
|
249470
|
+
const worker2 = externalTarget.type === "antigravity" ? await buildExternalWorkerResumeEnv({
|
|
249471
|
+
parentAgentId: parentScope.agentId,
|
|
249472
|
+
actingUserId: getRuntimeActingUserAttribution()
|
|
249473
|
+
}, deps.workerEnv) : undefined;
|
|
249474
|
+
const receipt3 = worker2 ? sendAntigravityMessage({
|
|
249475
|
+
...messageOptions,
|
|
249476
|
+
resumeSessionId: externalTarget.sessionId,
|
|
249477
|
+
mcpReminder: worker2.mcpReminder
|
|
249478
|
+
}, worker2.env, worker2.secretEnv) : externalTarget.type === "cursor" ? await sendCursorMessage(messageOptions, { ...process.env, ...secrets2 }, secrets2) : await sendOpenCodeMessage(messageOptions);
|
|
248790
249479
|
if (receipt3.mode === "steered") {
|
|
249480
|
+
recordSteer();
|
|
248791
249481
|
return {
|
|
248792
249482
|
content: JSON.stringify({
|
|
248793
249483
|
status: "accepted",
|
|
248794
249484
|
agent_id: args.agent_id,
|
|
248795
|
-
delivery: externalTarget.type === "cursor" ? "run/steer" : "session/abort+prompt"
|
|
249485
|
+
delivery: externalTarget.type === "antigravity" ? "queued" : externalTarget.type === "cursor" ? "run/steer" : "session/abort+prompt"
|
|
248796
249486
|
}),
|
|
248797
249487
|
status: "success"
|
|
248798
249488
|
};
|
|
@@ -248861,6 +249551,7 @@ async function send_agent_message(args, deps = {}) {
|
|
|
248861
249551
|
throw error4;
|
|
248862
249552
|
}
|
|
248863
249553
|
if (receipt3.mode === "steered") {
|
|
249554
|
+
recordSteer();
|
|
248864
249555
|
return {
|
|
248865
249556
|
content: JSON.stringify({
|
|
248866
249557
|
status: "accepted",
|
|
@@ -248932,6 +249623,7 @@ async function send_agent_message(args, deps = {}) {
|
|
|
248932
249623
|
throw error4;
|
|
248933
249624
|
}
|
|
248934
249625
|
if (receipt2.mode === "steered") {
|
|
249626
|
+
recordSteer();
|
|
248935
249627
|
return {
|
|
248936
249628
|
content: JSON.stringify({
|
|
248937
249629
|
status: "accepted",
|
|
@@ -249025,16 +249717,20 @@ async function send_agent_message(args, deps = {}) {
|
|
|
249025
249717
|
actingUserId
|
|
249026
249718
|
}, signal);
|
|
249027
249719
|
const child = receipt.agent_id ? await resolveChildSubagent(backend3, receipt.agent_id, sender.agentId) : null;
|
|
249720
|
+
const persistRun = resumeSubagentWriter(sender.conversationId, { conversation_id: receipt.conversation_id }, actingUserId);
|
|
249028
249721
|
if (child) {
|
|
249029
249722
|
(deps.trackChildSend ?? trackChildSend)({
|
|
249030
249723
|
receipt,
|
|
249031
249724
|
child,
|
|
249725
|
+
...persistRun && { persistRun: persistRun.update },
|
|
249032
249726
|
prompt: args.message,
|
|
249033
249727
|
parentScope: {
|
|
249034
249728
|
agentId: sender.agentId,
|
|
249035
249729
|
conversationId: sender.conversationId
|
|
249036
249730
|
}
|
|
249037
249731
|
});
|
|
249732
|
+
} else if (persistRun) {
|
|
249733
|
+
trackPersistedChildSend(receipt, persistRun);
|
|
249038
249734
|
}
|
|
249039
249735
|
return {
|
|
249040
249736
|
content: JSON.stringify({
|
|
@@ -249074,9 +249770,11 @@ var init_send_agent_message = __esm(() => {
|
|
|
249074
249770
|
init_agent_message();
|
|
249075
249771
|
init_conversation_enqueue();
|
|
249076
249772
|
init_request();
|
|
249773
|
+
init_subagents3();
|
|
249077
249774
|
init_runtime_context();
|
|
249078
249775
|
init_runtime_execution_settings();
|
|
249079
249776
|
init_debug();
|
|
249777
|
+
init_antigravity_session();
|
|
249080
249778
|
init_claude_stream_session();
|
|
249081
249779
|
init_codex_app_server();
|
|
249082
249780
|
init_cursor_session();
|
|
@@ -253475,6 +254173,27 @@ function buildBashDescriptionForPlatform(platform9 = process.platform) {
|
|
|
253475
254173
|
|
|
253476
254174
|
${WINDOWS_BASH_EXECUTION_GUIDANCE}` : baseDescription;
|
|
253477
254175
|
}
|
|
254176
|
+
function buildTaskSchema(env6 = process.env) {
|
|
254177
|
+
const { computer } = resolveSubagentComputer({
|
|
254178
|
+
requested: undefined,
|
|
254179
|
+
subagentType: "general-purpose",
|
|
254180
|
+
config: { fork: false, launchProfile: "default" },
|
|
254181
|
+
env: env6
|
|
254182
|
+
});
|
|
254183
|
+
if (!computer)
|
|
254184
|
+
return Task_default2;
|
|
254185
|
+
const destination = computer.toLowerCase() === "cloud" ? "a fresh Cloud sandbox, where this machine's files are unavailable" : `the connected computer ${JSON.stringify(computer)}; unless that is this machine, this machine's files are unavailable there`;
|
|
254186
|
+
return {
|
|
254187
|
+
...Task_default2,
|
|
254188
|
+
properties: {
|
|
254189
|
+
...Task_default2.properties,
|
|
254190
|
+
computer: {
|
|
254191
|
+
...Task_default2.properties.computer,
|
|
254192
|
+
description: `Omitting computer sends subagents to ${destination}. memory and recall subagents always stay on this machine. Pass "local" to stay on this machine, "cloud" for a fresh Cloud sandbox, or a connected computer ID or name. Prefer a stable device ID or computer name; ephemeral connection IDs are also supported to pin a specific listener. Fails fast if the device is offline or does not support routing.`
|
|
254193
|
+
}
|
|
254194
|
+
}
|
|
254195
|
+
};
|
|
254196
|
+
}
|
|
253478
254197
|
function execCommandDescription() {
|
|
253479
254198
|
const baseDescription = applyCommitTrailer(ExecCommand_default.trim());
|
|
253480
254199
|
return process.platform === "win32" ? `${baseDescription}
|
|
@@ -253497,6 +254216,7 @@ var init_tool_definitions = __esm(() => {
|
|
|
253497
254216
|
init_ExitWorktree();
|
|
253498
254217
|
init_Glob();
|
|
253499
254218
|
init_Grep();
|
|
254219
|
+
init_ListAgents();
|
|
253500
254220
|
init_LS();
|
|
253501
254221
|
init_Memory();
|
|
253502
254222
|
init_Monitor();
|
|
@@ -253531,6 +254251,7 @@ var init_tool_definitions = __esm(() => {
|
|
|
253531
254251
|
init_exit_worktree();
|
|
253532
254252
|
init_glob();
|
|
253533
254253
|
init_grep();
|
|
254254
|
+
init_list_agents();
|
|
253534
254255
|
init_ls();
|
|
253535
254256
|
init_memory4();
|
|
253536
254257
|
init_monitor();
|
|
@@ -253540,6 +254261,7 @@ var init_tool_definitions = __esm(() => {
|
|
|
253540
254261
|
init_send_agent_message();
|
|
253541
254262
|
init_set_working_directory();
|
|
253542
254263
|
init_skill();
|
|
254264
|
+
init_subagent_computer();
|
|
253543
254265
|
init_task();
|
|
253544
254266
|
init_task_create();
|
|
253545
254267
|
init_task_get();
|
|
@@ -253561,6 +254283,7 @@ var init_tool_definitions = __esm(() => {
|
|
|
253561
254283
|
init_ExitWorktree2();
|
|
253562
254284
|
init_Glob2();
|
|
253563
254285
|
init_Grep2();
|
|
254286
|
+
init_ListAgents2();
|
|
253564
254287
|
init_LS2();
|
|
253565
254288
|
init_Memory2();
|
|
253566
254289
|
init_Monitor2();
|
|
@@ -253670,6 +254393,11 @@ ${WINDOWS_UNIFIED_EXEC_GUIDANCE}`;
|
|
|
253670
254393
|
description: ReadLSP_default.trim(),
|
|
253671
254394
|
impl: read_lsp
|
|
253672
254395
|
}),
|
|
254396
|
+
ListAgents: defineTool({
|
|
254397
|
+
schema: ListAgents_default2,
|
|
254398
|
+
description: ListAgents_default.trim(),
|
|
254399
|
+
impl: list_agents
|
|
254400
|
+
}),
|
|
253673
254401
|
SendAgentMessage: defineTool({
|
|
253674
254402
|
schema: SendAgentMessage_default2,
|
|
253675
254403
|
description: SendAgentMessage_default.trim(),
|
|
@@ -253691,7 +254419,7 @@ ${WINDOWS_UNIFIED_EXEC_GUIDANCE}`;
|
|
|
253691
254419
|
impl: skill
|
|
253692
254420
|
}),
|
|
253693
254421
|
Task: defineTool({
|
|
253694
|
-
schema:
|
|
254422
|
+
schema: buildTaskSchema(),
|
|
253695
254423
|
description: Task_default.trim(),
|
|
253696
254424
|
impl: task
|
|
253697
254425
|
}),
|
|
@@ -258575,11 +259303,14 @@ function getListenerBlockedReason(lifecycle, pendingApprovalsLen) {
|
|
|
258575
259303
|
}
|
|
258576
259304
|
|
|
258577
259305
|
// src/websocket/listener/image-policy.ts
|
|
259306
|
+
function hasImageContent(content) {
|
|
259307
|
+
return Array.isArray(content) && content.some((part) => part.type === "image");
|
|
259308
|
+
}
|
|
258578
259309
|
function getInboundImageFailureMode(incoming) {
|
|
258579
259310
|
return incoming?.imageFailureMode ?? "strict";
|
|
258580
259311
|
}
|
|
258581
259312
|
function getInboundImageFailureModes(incoming) {
|
|
258582
|
-
return getInboundImageFailureMode(incoming) === "drop" ? buildImageFailureModesByMessageOtid(incoming.messages, "drop") : undefined;
|
|
259313
|
+
return getInboundImageFailureMode(incoming) === "drop" ? buildImageFailureModesByMessageOtid(incoming.messages.filter((message2) => ("content" in message2) && hasImageContent(message2.content)), "drop") : undefined;
|
|
258583
259314
|
}
|
|
258584
259315
|
var init_image_policy = __esm(() => {
|
|
258585
259316
|
init_message_image_normalization();
|
|
@@ -258618,7 +259349,7 @@ function getBatchActingUserId(items) {
|
|
|
258618
259349
|
}
|
|
258619
259350
|
return actingUserId;
|
|
258620
259351
|
}
|
|
258621
|
-
function buildQueuedTurnMessage(runtime, batch) {
|
|
259352
|
+
function buildQueuedTurnMessage(runtime, batch, imageFailureMode) {
|
|
258622
259353
|
let template2;
|
|
258623
259354
|
const messages = [];
|
|
258624
259355
|
const durableInputIdentities = [];
|
|
@@ -258672,6 +259403,7 @@ function buildQueuedTurnMessage(runtime, batch) {
|
|
|
258672
259403
|
agentId: scopeItem?.agentId ?? runtime.agentId ?? undefined,
|
|
258673
259404
|
conversationId: scopeItem?.conversationId ?? runtime.conversationId,
|
|
258674
259405
|
...template2,
|
|
259406
|
+
imageFailureMode,
|
|
258675
259407
|
mcpOriginatorSuperRunId,
|
|
258676
259408
|
...processOwnedTurn ? { processOwnedTurn: true } : {},
|
|
258677
259409
|
actingUserId: batchActingUserId ?? undefined,
|
|
@@ -258700,7 +259432,7 @@ function getDequeuedClientMessageIds(runtime, batch) {
|
|
|
258700
259432
|
function shouldQueueInboundMessage(parsed) {
|
|
258701
259433
|
return parsed.messages.some((payload) => ("content" in payload));
|
|
258702
259434
|
}
|
|
258703
|
-
function consumeQueuedTurn(runtime) {
|
|
259435
|
+
function consumeQueuedTurn(runtime, options) {
|
|
258704
259436
|
const queuedItems = runtime.queueRuntime.peekReady();
|
|
258705
259437
|
const firstQueuedItem = queuedItems[0];
|
|
258706
259438
|
if (!firstQueuedItem) {
|
|
@@ -258715,6 +259447,9 @@ function consumeQueuedTurn(runtime) {
|
|
|
258715
259447
|
let batchImageFailureMode = null;
|
|
258716
259448
|
let batchPreferences = JSON.stringify(getStoredClientPreferences(runtime.agentId, runtime.conversationId));
|
|
258717
259449
|
const isNoCoalesce = (candidate) => candidate.kind === "message" && candidate.noCoalesce === true;
|
|
259450
|
+
if (options?.continuation && isNoCoalesce(firstQueuedItem)) {
|
|
259451
|
+
return null;
|
|
259452
|
+
}
|
|
258718
259453
|
for (const item of queuedItems) {
|
|
258719
259454
|
if (!hasSameQueueScope(firstQueuedItem, item)) {
|
|
258720
259455
|
break;
|
|
@@ -258735,11 +259470,14 @@ function consumeQueuedTurn(runtime) {
|
|
|
258735
259470
|
break;
|
|
258736
259471
|
}
|
|
258737
259472
|
batchConnectionId ??= itemConnectionId;
|
|
258738
|
-
const
|
|
258739
|
-
if (
|
|
258740
|
-
|
|
259473
|
+
const hasImages = incoming ? incoming.messages.some((message2) => ("content" in message2) && hasImageContent(message2.content)) : hasImageContent(item.content);
|
|
259474
|
+
if (hasImages) {
|
|
259475
|
+
const itemImageFailureMode = getInboundImageFailureMode(incoming);
|
|
259476
|
+
if (batchImageFailureMode !== null && itemImageFailureMode !== batchImageFailureMode) {
|
|
259477
|
+
break;
|
|
259478
|
+
}
|
|
259479
|
+
batchImageFailureMode = itemImageFailureMode;
|
|
258741
259480
|
}
|
|
258742
|
-
batchImageFailureMode = itemImageFailureMode;
|
|
258743
259481
|
}
|
|
258744
259482
|
queueLen += 1;
|
|
258745
259483
|
if (item.kind === "message") {
|
|
@@ -258782,7 +259520,7 @@ function consumeQueuedTurn(runtime) {
|
|
|
258782
259520
|
}
|
|
258783
259521
|
}
|
|
258784
259522
|
const clientMessageIds = getDequeuedClientMessageIds(runtime, dequeuedBatch);
|
|
258785
|
-
const queuedTurn = buildQueuedTurnMessage(runtime, dequeuedBatch);
|
|
259523
|
+
const queuedTurn = buildQueuedTurnMessage(runtime, dequeuedBatch, batchImageFailureMode ?? undefined);
|
|
258786
259524
|
if (!queuedTurn) {
|
|
258787
259525
|
return null;
|
|
258788
259526
|
}
|
|
@@ -264321,7 +265059,8 @@ function toExternalToolDefinition(listener, tool, connectionId, runtimeScope) {
|
|
|
264321
265059
|
}
|
|
264322
265060
|
};
|
|
264323
265061
|
return enableListenerExternalToolBackground(toolDefinition, {
|
|
264324
|
-
createNotificationGuard: () => captureExternalToolNotificationGuard(listener, runtimeScope)
|
|
265062
|
+
createNotificationGuard: () => captureExternalToolNotificationGuard(listener, runtimeScope),
|
|
265063
|
+
...tool.foreground_yield_ms !== undefined ? { yieldMs: clampForegroundYieldMs(tool.foreground_yield_ms) } : {}
|
|
264325
265064
|
});
|
|
264326
265065
|
}
|
|
264327
265066
|
function installExternalToolBridge(runtime, options) {
|
|
@@ -264607,6 +265346,7 @@ function rejectPendingExternalToolCalls(runtime, reason) {
|
|
|
264607
265346
|
var EXTERNAL_TOOL_CALL_TIMEOUT_MS, registeredToolsByRuntime, lastSubmittingConnectionByRuntime, nextRegistrationSequence = 0, connectionIdByRegistrationKey;
|
|
264608
265347
|
var init_external_tools = __esm(() => {
|
|
264609
265348
|
init_external_tool_background_eligibility();
|
|
265349
|
+
init_foreground_yield();
|
|
264610
265350
|
init_manager2();
|
|
264611
265351
|
init_debug();
|
|
264612
265352
|
init_connection();
|
|
@@ -452812,26 +453552,29 @@ var init_turn_observers = __esm(() => {
|
|
|
452812
453552
|
async function startTurnInput(params) {
|
|
452813
453553
|
const sendParams = {
|
|
452814
453554
|
...params,
|
|
452815
|
-
buildSendOptions: () =>
|
|
452816
|
-
|
|
452817
|
-
|
|
452818
|
-
|
|
452819
|
-
|
|
452820
|
-
|
|
452821
|
-
|
|
452822
|
-
|
|
452823
|
-
|
|
452824
|
-
|
|
452825
|
-
|
|
452826
|
-
|
|
452827
|
-
|
|
452828
|
-
|
|
452829
|
-
|
|
452830
|
-
|
|
452831
|
-
|
|
452832
|
-
|
|
452833
|
-
|
|
452834
|
-
|
|
453555
|
+
buildSendOptions: () => {
|
|
453556
|
+
const actingUserId = params.getActingUserId();
|
|
453557
|
+
return {
|
|
453558
|
+
...params.agentId ? { agentId: params.agentId } : {},
|
|
453559
|
+
streamTokens: true,
|
|
453560
|
+
background: true,
|
|
453561
|
+
workingDirectory: params.workingDirectory,
|
|
453562
|
+
permissionModeState: params.permissionModeState,
|
|
453563
|
+
...params.runtime.skillSources !== undefined ? { skillSources: params.runtime.skillSources } : {},
|
|
453564
|
+
preparedToolContext: params.preparedToolContext,
|
|
453565
|
+
...params.getInput().imageFailureModesByMessageOtid ? {
|
|
453566
|
+
imageFailureModesByMessageOtid: params.getInput().imageFailureModesByMessageOtid
|
|
453567
|
+
} : {},
|
|
453568
|
+
...params.overrideModel ? { overrideModel: params.overrideModel } : {},
|
|
453569
|
+
...params.responseFormat ? { responseFormat: params.responseFormat } : {},
|
|
453570
|
+
...actingUserId !== undefined ? { actingUserId } : {},
|
|
453571
|
+
...params.getInterruptedToolCallIds().length > 0 ? {
|
|
453572
|
+
approvalNormalization: {
|
|
453573
|
+
interruptedToolCallIds: params.getInterruptedToolCallIds()
|
|
453574
|
+
}
|
|
453575
|
+
} : {}
|
|
453576
|
+
};
|
|
453577
|
+
}
|
|
452835
453578
|
};
|
|
452836
453579
|
const sender = createTurnInputSender(sendParams);
|
|
452837
453580
|
const input = params.getInput();
|
|
@@ -452844,7 +453587,11 @@ async function startTurnInput(params) {
|
|
|
452844
453587
|
stream: sender.accept(result3)
|
|
452845
453588
|
};
|
|
452846
453589
|
}
|
|
453590
|
+
function getProviderRetryLimit(errorDetail3) {
|
|
453591
|
+
return isProviderStreamTimeoutDetail(errorDetail3) ? 1 : LLM_API_ERROR_MAX_RETRIES;
|
|
453592
|
+
}
|
|
452847
453593
|
async function prepareProviderRetryInput(params) {
|
|
453594
|
+
const maxAttempts = getProviderRetryLimit(params.errorDetail);
|
|
452848
453595
|
const delayMs = getRetryDelayMs2({
|
|
452849
453596
|
category: "transient_provider",
|
|
452850
453597
|
attempt: params.attempt,
|
|
@@ -452852,10 +453599,10 @@ async function prepareProviderRetryInput(params) {
|
|
|
452852
453599
|
});
|
|
452853
453600
|
emitRecoverableRetryNotice(params.socket, params.runtime, {
|
|
452854
453601
|
kind: "transient_provider_retry",
|
|
452855
|
-
message: getRetryStatusMessage(params.errorDetail) || `LLM API error encountered, retrying (attempt ${params.attempt}/${
|
|
453602
|
+
message: getRetryStatusMessage(params.errorDetail) || `LLM API error encountered, retrying (attempt ${params.attempt}/${maxAttempts})...`,
|
|
452856
453603
|
reason: "llm_api_error",
|
|
452857
453604
|
attempt: params.attempt,
|
|
452858
|
-
maxAttempts
|
|
453605
|
+
maxAttempts,
|
|
452859
453606
|
delayMs,
|
|
452860
453607
|
runId: params.runId ?? undefined,
|
|
452861
453608
|
agentId: params.agentId,
|
|
@@ -452867,11 +453614,37 @@ async function prepareProviderRetryInput(params) {
|
|
|
452867
453614
|
}
|
|
452868
453615
|
return refreshTurnInputOtidsForNewRequest(params.input);
|
|
452869
453616
|
}
|
|
453617
|
+
async function sendPostStopRetry(params) {
|
|
453618
|
+
const { agentId, conversationId, runtime, runId, socket, turnLease } = params;
|
|
453619
|
+
let input = params.deploymentInterrupted ? createDeploymentRecoveryTurnInput() : await prepareProviderRetryInput(params);
|
|
453620
|
+
if (params.finishIfInterrupted(runId))
|
|
453621
|
+
return { kind: "interrupted" };
|
|
453622
|
+
const consumed = params.deploymentInterrupted || params.noCoalesce ? null : consumeQueuedTurn(runtime, { continuation: true });
|
|
453623
|
+
if (consumed) {
|
|
453624
|
+
const { dequeuedBatch, queuedTurn } = consumed;
|
|
453625
|
+
queuedTurn.messages = ensureTurnInputMessageOtids(queuedTurn.messages);
|
|
453626
|
+
await params.onConsumeQueuedTurn(queuedTurn);
|
|
453627
|
+
if (params.finishIfInterrupted(runId))
|
|
453628
|
+
return { kind: "interrupted" };
|
|
453629
|
+
params.turnCorrelation.appendDequeuedBatch(dequeuedBatch.batchId);
|
|
453630
|
+
params.onDequeued(dequeuedBatch.batchId, queuedTurn.actingUserId ?? null);
|
|
453631
|
+
input = appendQueuedTurnToInput(input, queuedTurn);
|
|
453632
|
+
emitDequeuedUserMessage(socket, runtime, queuedTurn, dequeuedBatch);
|
|
453633
|
+
}
|
|
453634
|
+
setTurnLoopStatus(runtime, turnLease, "SENDING_API_REQUEST", {
|
|
453635
|
+
agent_id: agentId,
|
|
453636
|
+
conversation_id: conversationId
|
|
453637
|
+
});
|
|
453638
|
+
const messages = params.deploymentInterrupted ? input.messages : injectQueuedSkillContent(input.messages, params);
|
|
453639
|
+
params.setInput(updateTurnInputMessagesPreservingOtids(input, messages));
|
|
453640
|
+
const result3 = await params.sender.send(messages);
|
|
453641
|
+
return params.finishIfInterrupted(runId) ? { kind: "interrupted" } : { kind: "sent", result: result3 };
|
|
453642
|
+
}
|
|
452870
453643
|
async function shouldRetryPostStopTurn(params) {
|
|
452871
453644
|
if (params.deploymentInterrupted) {
|
|
452872
453645
|
return params.deploymentAttempts < CLOUD_API_DEPLOYMENT_RECOVERY_MAX_ATTEMPTS;
|
|
452873
453646
|
}
|
|
452874
|
-
if (params.providerAttempts >=
|
|
453647
|
+
if (params.providerAttempts >= getProviderRetryLimit(params.errorDetail))
|
|
452875
453648
|
return false;
|
|
452876
453649
|
return isRetriablePostStopError(params.stopReason, params.runId, params.errorDetail);
|
|
452877
453650
|
}
|
|
@@ -452904,11 +453677,15 @@ var init_turn_send = __esm(() => {
|
|
|
452904
453677
|
init_turn_recovery_policy();
|
|
452905
453678
|
init_error_formatter();
|
|
452906
453679
|
init_constants3();
|
|
453680
|
+
init_continuation_input();
|
|
453681
|
+
init_protocol_outbound();
|
|
453682
|
+
init_queue();
|
|
452907
453683
|
init_recoverable_notices();
|
|
452908
453684
|
init_recovery();
|
|
452909
453685
|
init_send();
|
|
452910
453686
|
init_skill_injection();
|
|
452911
453687
|
init_turn_input_state();
|
|
453688
|
+
init_turn_status();
|
|
452912
453689
|
});
|
|
452913
453690
|
|
|
452914
453691
|
// src/reminders/listen-context.ts
|
|
@@ -453587,24 +454364,17 @@ async function handleIncomingMessageInner(msg, socket, runtime, onStatusChange,
|
|
|
453587
454364
|
connectionId,
|
|
453588
454365
|
resolveClientMessageIds: () => turnCorrelation.clientMessageIds
|
|
453589
454366
|
});
|
|
453590
|
-
if (setup.kind === "interrupted") {
|
|
453591
|
-
finishTurn({
|
|
453592
|
-
stopReason: "cancelled",
|
|
453593
|
-
socket,
|
|
453594
|
-
agentId,
|
|
453595
|
-
conversationId
|
|
453596
|
-
});
|
|
453597
|
-
return;
|
|
453598
|
-
}
|
|
453599
|
-
if (setup.kind === "cancelled") {
|
|
454367
|
+
if (setup.kind === "interrupted" || setup.kind === "cancelled") {
|
|
453600
454368
|
finishTurn({
|
|
453601
454369
|
stopReason: "cancelled",
|
|
453602
454370
|
agentId: agentId || null,
|
|
453603
454371
|
conversationId,
|
|
453604
|
-
|
|
453605
|
-
|
|
453606
|
-
|
|
453607
|
-
|
|
454372
|
+
...setup.kind === "interrupted" ? { socket } : {
|
|
454373
|
+
errorNotice: {
|
|
454374
|
+
message: setup.reason,
|
|
454375
|
+
cancelRequested: turnAbortSignal.aborted,
|
|
454376
|
+
abortSignal: turnAbortSignal
|
|
454377
|
+
}
|
|
453608
454378
|
}
|
|
453609
454379
|
});
|
|
453610
454380
|
return;
|
|
@@ -453613,6 +454383,7 @@ async function handleIncomingMessageInner(msg, socket, runtime, onStatusChange,
|
|
|
453613
454383
|
const inboundUserTranscriptLines = setup.inboundUserTranscriptLines;
|
|
453614
454384
|
const overrideModel = setup.overrideModel;
|
|
453615
454385
|
let pendingNormalizationInterruptedToolCallIds = setup.pendingNormalizationInterruptedToolCallIds;
|
|
454386
|
+
let actingUserId = msg.suppressActingUserFallback ? null : msg.actingUserId;
|
|
453616
454387
|
const initial2 = await startTurnInput({
|
|
453617
454388
|
conversationId,
|
|
453618
454389
|
agentId,
|
|
@@ -453624,7 +454395,7 @@ async function handleIncomingMessageInner(msg, socket, runtime, onStatusChange,
|
|
|
453624
454395
|
preparedToolContext: setup.preparedToolContext.preparedToolContext,
|
|
453625
454396
|
overrideModel,
|
|
453626
454397
|
responseFormat: msg.responseFormat,
|
|
453627
|
-
|
|
454398
|
+
getActingUserId: () => actingUserId,
|
|
453628
454399
|
getInput: () => turnInput,
|
|
453629
454400
|
getInterruptedToolCallIds: () => pendingNormalizationInterruptedToolCallIds,
|
|
453630
454401
|
onTerminal: noteFinalization,
|
|
@@ -453752,6 +454523,12 @@ async function handleIncomingMessageInner(msg, socket, runtime, onStatusChange,
|
|
|
453752
454523
|
}
|
|
453753
454524
|
const latestErrorInfo = result3.errorInfo;
|
|
453754
454525
|
const errorDetail3 = getApprovalToolCallDesyncErrorText(latestErrorInfo ?? {}) || latestErrorInfo?.detail || latestErrorInfo?.message || runErrorInfo2?.detail || runErrorInfo2?.message || fallbackError || null;
|
|
454526
|
+
const retryErrorDetail = [
|
|
454527
|
+
latestErrorInfo?.detail,
|
|
454528
|
+
latestErrorInfo?.message,
|
|
454529
|
+
runErrorInfo2?.detail,
|
|
454530
|
+
runErrorInfo2?.message
|
|
454531
|
+
].find(isProviderStreamTimeoutDetail) ?? errorDetail3;
|
|
453755
454532
|
const quotaError = latestErrorInfo ?? runErrorInfo2 ?? errorDetail3;
|
|
453756
454533
|
const deploymentInterrupted = isCloudApiDeploymentInterrupted(latestErrorInfo) || isCloudApiDeploymentInterrupted(runErrorInfo2);
|
|
453757
454534
|
if (!deploymentInterrupted && shouldAttemptPostStopApprovalRecovery({
|
|
@@ -453909,42 +454686,51 @@ async function handleIncomingMessageInner(msg, socket, runtime, onStatusChange,
|
|
|
453909
454686
|
providerAttempts: llmApiErrorRetries,
|
|
453910
454687
|
stopReason: stopReason || "error",
|
|
453911
454688
|
runId: lastRunId,
|
|
453912
|
-
errorDetail:
|
|
454689
|
+
errorDetail: retryErrorDetail
|
|
453913
454690
|
});
|
|
453914
454691
|
if (finishIfInterrupted(lastRunId || runtime.activeRunId)) {
|
|
453915
454692
|
break;
|
|
453916
454693
|
}
|
|
453917
454694
|
if (shouldRetry) {
|
|
453918
|
-
if (deploymentInterrupted)
|
|
454695
|
+
if (deploymentInterrupted)
|
|
453919
454696
|
deploymentRecoveryAttempts += 1;
|
|
453920
|
-
|
|
453921
|
-
} else {
|
|
454697
|
+
else
|
|
453922
454698
|
llmApiErrorRetries += 1;
|
|
453923
|
-
|
|
453924
|
-
|
|
453925
|
-
|
|
453926
|
-
|
|
453927
|
-
|
|
453928
|
-
runtime,
|
|
453929
|
-
turnLease,
|
|
453930
|
-
agentId,
|
|
453931
|
-
conversationId,
|
|
453932
|
-
runId: lastRunId
|
|
453933
|
-
});
|
|
453934
|
-
}
|
|
453935
|
-
setTurnLoopStatus(runtime, turnLease, "SENDING_API_REQUEST", {
|
|
453936
|
-
agent_id: agentId,
|
|
453937
|
-
conversation_id: conversationId
|
|
453938
|
-
});
|
|
453939
|
-
const retryInputWithSkillContent = deploymentInterrupted ? turnInput.messages : injectQueuedSkillContent(turnInput.messages, {
|
|
454699
|
+
const retry3 = await sendPostStopRetry({
|
|
454700
|
+
deploymentInterrupted,
|
|
454701
|
+
input: turnInput,
|
|
454702
|
+
errorDetail: retryErrorDetail,
|
|
454703
|
+
attempt: llmApiErrorRetries,
|
|
453940
454704
|
socket,
|
|
453941
454705
|
runtime,
|
|
454706
|
+
turnLease,
|
|
453942
454707
|
agentId,
|
|
453943
|
-
conversationId
|
|
454708
|
+
conversationId,
|
|
454709
|
+
runId: lastRunId,
|
|
454710
|
+
sender: turnInputSender,
|
|
454711
|
+
setInput: (input) => {
|
|
454712
|
+
turnInput = input;
|
|
454713
|
+
},
|
|
454714
|
+
finishIfInterrupted,
|
|
454715
|
+
turnCorrelation,
|
|
454716
|
+
noCoalesce: msg.noCoalesce,
|
|
454717
|
+
onConsumeQueuedTurn: createQueuedTurnConsumer({
|
|
454718
|
+
parkedInput: msg,
|
|
454719
|
+
turnToolContextId,
|
|
454720
|
+
runtime,
|
|
454721
|
+
ownership: durabilityOwnership,
|
|
454722
|
+
interruptedRevisionRef,
|
|
454723
|
+
recoveryLineageId,
|
|
454724
|
+
recoveryEvidenceWriter
|
|
454725
|
+
}).onConsumeQueuedTurn,
|
|
454726
|
+
onDequeued: (batchId, queuedActingUserId) => {
|
|
454727
|
+
activeDequeuedBatchId = batchId;
|
|
454728
|
+
actingUserId = queuedActingUserId;
|
|
454729
|
+
}
|
|
453944
454730
|
});
|
|
453945
|
-
|
|
453946
|
-
|
|
453947
|
-
const retryStream = turnInputSender.accept(
|
|
454731
|
+
if (retry3.kind === "interrupted")
|
|
454732
|
+
break;
|
|
454733
|
+
const retryStream = turnInputSender.accept(retry3.result);
|
|
453948
454734
|
if (!retryStream) {
|
|
453949
454735
|
return;
|
|
453950
454736
|
}
|
|
@@ -456064,7 +456850,7 @@ function isRuntimeScope2(value) {
|
|
|
456064
456850
|
function isExternalToolDefinitionPayload(value) {
|
|
456065
456851
|
if (!isRecord18(value))
|
|
456066
456852
|
return false;
|
|
456067
|
-
return typeof value.name === "string" && (value.label === undefined || typeof value.label === "string") && typeof value.description === "string" && isRecord18(value.parameters) && (value.auto_background === undefined || typeof value.auto_background === "boolean") && (value.timeout_ms === undefined || typeof value.timeout_ms === "number" && Number.isSafeInteger(value.timeout_ms) && value.timeout_ms >= 1000 && value.timeout_ms <= 300000);
|
|
456853
|
+
return typeof value.name === "string" && (value.label === undefined || typeof value.label === "string") && typeof value.description === "string" && isRecord18(value.parameters) && (value.auto_background === undefined || typeof value.auto_background === "boolean") && (value.foreground_yield_ms === undefined || typeof value.foreground_yield_ms === "number" && Number.isFinite(value.foreground_yield_ms) && value.foreground_yield_ms > 0) && (value.timeout_ms === undefined || typeof value.timeout_ms === "number" && Number.isSafeInteger(value.timeout_ms) && value.timeout_ms >= 1000 && value.timeout_ms <= 300000);
|
|
456068
456854
|
}
|
|
456069
456855
|
function isStringList(value) {
|
|
456070
456856
|
return Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
@@ -456276,6 +457062,7 @@ var init_subagent_protocol_inbound = __esm(() => {
|
|
|
456276
457062
|
"mcp"
|
|
456277
457063
|
]);
|
|
456278
457064
|
LEGACY_EXTERNAL_SUBAGENT_TYPES = new Set([
|
|
457065
|
+
"antigravity",
|
|
456279
457066
|
"claude-code",
|
|
456280
457067
|
"codex",
|
|
456281
457068
|
"cursor",
|
|
@@ -459690,6 +460477,7 @@ function buildAppServerInfoResponse(command, options) {
|
|
|
459690
460477
|
runtime_external_tools_update: true,
|
|
459691
460478
|
runtime_tool_policy: true,
|
|
459692
460479
|
runtime_tool_policy_foreground_yield: true,
|
|
460480
|
+
external_tool_foreground_yield: true,
|
|
459693
460481
|
structured_outputs: options.backend === "api",
|
|
459694
460482
|
write_file_base64: true,
|
|
459695
460483
|
split_channels: false
|
|
@@ -462815,6 +463603,7 @@ async function applyRuntimeStartState(parsed, context3, scope, scopedRuntime) {
|
|
|
462815
463603
|
if (!mode) {
|
|
462816
463604
|
throw new Error(`Unsupported permission mode: ${parsed.mode}`);
|
|
462817
463605
|
}
|
|
463606
|
+
const hadPermissionMode = context3.runtime.permissionModeByConversation.has(getPermissionModeScopeKey(scope.agent_id, scope.conversation_id));
|
|
462818
463607
|
const state2 = getOrCreateConversationPermissionModeStateRef(context3.runtime, scope.agent_id, scope.conversation_id);
|
|
462819
463608
|
if (!(parsed.mode_is_default && state2.explicit)) {
|
|
462820
463609
|
const previousMode = state2.mode;
|
|
@@ -462822,7 +463611,7 @@ async function applyRuntimeStartState(parsed, context3, scope, scopedRuntime) {
|
|
|
462822
463611
|
if (!parsed.mode_is_default)
|
|
462823
463612
|
state2.explicit = true;
|
|
462824
463613
|
persistPermissionModeMapForRuntime(context3.runtime);
|
|
462825
|
-
if (previousMode !== mode) {
|
|
463614
|
+
if (hadPermissionMode && previousMode !== mode) {
|
|
462826
463615
|
telemetry.trackPermissionModeChanged({
|
|
462827
463616
|
agent_id: scope.agent_id,
|
|
462828
463617
|
conversation_id: scope.conversation_id,
|
|
@@ -464275,6 +465064,8 @@ function nativeSessionOwner(agentId) {
|
|
|
464275
465064
|
const target = parseExternalCodingAgentId(agentId);
|
|
464276
465065
|
if (!target || target.computer)
|
|
464277
465066
|
return;
|
|
465067
|
+
if (target.type === "antigravity")
|
|
465068
|
+
return readNativeSessionOwner(target.type, target.sessionId);
|
|
464278
465069
|
if (target.type !== "claude-code" && target.type !== "codex")
|
|
464279
465070
|
return;
|
|
464280
465071
|
return getNativeSessionOwner(target.type === "claude-code" ? "claude_code" : "codex", target.sessionId);
|
|
@@ -464344,6 +465135,14 @@ async function handleSubagentMessageCommand(command, parent, deps = {}) {
|
|
|
464344
465135
|
parentAgentId: command.runtime.agent_id,
|
|
464345
465136
|
actingUserId: command.runtime.acting_user_id
|
|
464346
465137
|
}, deps.workerEnv);
|
|
465138
|
+
if (target.type === "antigravity" && worker)
|
|
465139
|
+
return sendAntigravityMessage({
|
|
465140
|
+
resumeSessionId: sessionId,
|
|
465141
|
+
prompt: command.message,
|
|
465142
|
+
parentAgentId: command.runtime.agent_id,
|
|
465143
|
+
cwd: getCurrentWorkingDirectory(),
|
|
465144
|
+
mcpReminder: worker.mcpReminder
|
|
465145
|
+
}, worker.env, worker.secretEnv);
|
|
464347
465146
|
return target.type === "cursor" ? sendCursorMessage({
|
|
464348
465147
|
sessionId,
|
|
464349
465148
|
prompt: command.message,
|
|
@@ -464505,6 +465304,7 @@ var DEDUPE_TTL_MS = 30000, responses;
|
|
|
464505
465304
|
var init_subagent_control = __esm(() => {
|
|
464506
465305
|
init_subagent_state();
|
|
464507
465306
|
init_runtime_context();
|
|
465307
|
+
init_antigravity_session();
|
|
464508
465308
|
init_claude_steer_timeouts();
|
|
464509
465309
|
init_claude_stream_session();
|
|
464510
465310
|
init_codex_app_server();
|
|
@@ -464512,6 +465312,7 @@ var init_subagent_control = __esm(() => {
|
|
|
464512
465312
|
init_external_coding_agent();
|
|
464513
465313
|
init_external_coding_agent_task();
|
|
464514
465314
|
init_native_session_capture();
|
|
465315
|
+
init_native_session_owner();
|
|
464515
465316
|
init_process_manager();
|
|
464516
465317
|
init_task_stop();
|
|
464517
465318
|
init_cwd();
|
|
@@ -464610,7 +465411,7 @@ async function handleLaunchSubagentCommand(command, parent, connectionId, launch
|
|
|
464610
465411
|
signal.removeEventListener("abort", onAbort);
|
|
464611
465412
|
}
|
|
464612
465413
|
}
|
|
464613
|
-
var
|
|
465414
|
+
var init_subagents4 = __esm(() => {
|
|
464614
465415
|
init_runtime_context();
|
|
464615
465416
|
init_task();
|
|
464616
465417
|
init_cwd();
|
|
@@ -464670,7 +465471,7 @@ var init_task_control = __esm(() => {
|
|
|
464670
465471
|
init_stop_conversation();
|
|
464671
465472
|
init_subagent_control();
|
|
464672
465473
|
init_subagent_events2();
|
|
464673
|
-
|
|
465474
|
+
init_subagents4();
|
|
464674
465475
|
});
|
|
464675
465476
|
|
|
464676
465477
|
// src/websocket/listener/message-router.ts
|
|
@@ -472361,7 +473162,7 @@ var exports_external_worker_models = {};
|
|
|
472361
473162
|
__export(exports_external_worker_models, {
|
|
472362
473163
|
listExternalWorkerModels: () => listExternalWorkerModels
|
|
472363
473164
|
});
|
|
472364
|
-
import { createInterface as
|
|
473165
|
+
import { createInterface as createInterface12 } from "node:readline";
|
|
472365
473166
|
async function listClaudeModels(cwd2, env6) {
|
|
472366
473167
|
const controller = new AbortController;
|
|
472367
473168
|
const running = spawnManagedWorkloadProcess("claude", [
|
|
@@ -472379,7 +473180,7 @@ async function listClaudeModels(cwd2, env6) {
|
|
|
472379
473180
|
'{"disableAllHooks":true}'
|
|
472380
473181
|
], { cwd: cwd2, env: env6, signal: controller.signal });
|
|
472381
473182
|
const timer = setTimeout(() => controller.abort(), 30000);
|
|
472382
|
-
const lines =
|
|
473183
|
+
const lines = createInterface12({ input: running.process.stdout });
|
|
472383
473184
|
let stderr = "";
|
|
472384
473185
|
running.process.once("error", (error4) => {
|
|
472385
473186
|
stderr = error4.message;
|
|
@@ -478495,10 +479296,10 @@ async function openReadOnlyDatabase(path49) {
|
|
|
478495
479296
|
async function exportHermesSession(storePath, sessionId) {
|
|
478496
479297
|
const database = await openReadOnlyDatabase(storePath);
|
|
478497
479298
|
try {
|
|
478498
|
-
const
|
|
479299
|
+
const sessions6 = database.all("SELECT * FROM sessions WHERE id = ?", sessionId);
|
|
478499
479300
|
const messages = database.all("SELECT * FROM messages WHERE session_id = ? ORDER BY id", sessionId);
|
|
478500
479301
|
return JSON.stringify({
|
|
478501
|
-
session:
|
|
479302
|
+
session: sessions6[0] ?? { id: sessionId },
|
|
478502
479303
|
messages
|
|
478503
479304
|
});
|
|
478504
479305
|
} finally {
|
|
@@ -478742,8 +479543,8 @@ async function readManifest(dir) {
|
|
|
478742
479543
|
}
|
|
478743
479544
|
return JSON.parse(raw2);
|
|
478744
479545
|
}
|
|
478745
|
-
function filterSessions(
|
|
478746
|
-
return
|
|
479546
|
+
function filterSessions(sessions6, filter3) {
|
|
479547
|
+
return sessions6.filter((session3) => (!filter3.source || session3.source === filter3.source) && (!filter3.project || (session3.project ?? "").startsWith(filter3.project)));
|
|
478747
479548
|
}
|
|
478748
479549
|
async function resolveSessionFile(dir, target) {
|
|
478749
479550
|
if (target.endsWith(".json")) {
|
|
@@ -478918,19 +479719,19 @@ async function runDetect(asJson) {
|
|
|
478918
479719
|
}
|
|
478919
479720
|
async function runList4(flags) {
|
|
478920
479721
|
const manifest2 = await readManifest(flags.dir);
|
|
478921
|
-
const
|
|
479722
|
+
const sessions6 = filterSessions(manifest2.sessions, flags);
|
|
478922
479723
|
if (flags.asJson) {
|
|
478923
|
-
console.log(JSON.stringify({ sessions:
|
|
479724
|
+
console.log(JSON.stringify({ sessions: sessions6 }, null, 2));
|
|
478924
479725
|
return 0;
|
|
478925
479726
|
}
|
|
478926
|
-
for (const session3 of
|
|
479727
|
+
for (const session3 of sessions6) {
|
|
478927
479728
|
console.log(`${(session3.startedAt ?? "unknown").slice(0, 19)} ${session3.source} msgs:${session3.userMessages} ${session3.file}`);
|
|
478928
479729
|
if (session3.firstUserPrompt) {
|
|
478929
479730
|
console.log(` ${session3.firstUserPrompt.replace(/\s+/g, " ").slice(0, 90)}`);
|
|
478930
479731
|
}
|
|
478931
479732
|
}
|
|
478932
479733
|
console.log(`
|
|
478933
|
-
Total: ${
|
|
479734
|
+
Total: ${sessions6.length} session(s); errors: ${manifest2.errors.length}; sources: ${Object.keys(manifest2.sources).join(", ")}`);
|
|
478934
479735
|
return 0;
|
|
478935
479736
|
}
|
|
478936
479737
|
async function runView(flags, target, options) {
|
|
@@ -484323,13 +485124,16 @@ async function createSubagentConversation(cloudBackend, parentConversationId, ag
|
|
|
484323
485124
|
if (!cloudBackend || !parentConversationId || parentConversationId === "default") {
|
|
484324
485125
|
return "default";
|
|
484325
485126
|
}
|
|
485127
|
+
const summary = process.env[SUBAGENT_SUMMARY_ENV]?.trim();
|
|
484326
485128
|
const body3 = {
|
|
484327
485129
|
agent_id: agentId,
|
|
484328
485130
|
parent_conversation_id: parentConversationId,
|
|
484329
|
-
is_subagent: true
|
|
485131
|
+
is_subagent: true,
|
|
485132
|
+
...summary ? { summary } : {}
|
|
484330
485133
|
};
|
|
484331
485134
|
return (await create4(body3)).id;
|
|
484332
485135
|
}
|
|
485136
|
+
var init_subagent_conversation = () => {};
|
|
484333
485137
|
|
|
484334
485138
|
// src/stream-json-writer.ts
|
|
484335
485139
|
function stampWireMessage(msg) {
|
|
@@ -488605,6 +489409,7 @@ var LLM_API_ERROR_MAX_RETRIES2 = 3, EMPTY_RESPONSE_MAX_RETRIES2 = 2, HEADLESS_ST
|
|
|
488605
489409
|
var init_headless = __esm(() => {
|
|
488606
489410
|
init_error();
|
|
488607
489411
|
init_preloaded_skills();
|
|
489412
|
+
init_subagent_conversation();
|
|
488608
489413
|
init_subagent_launcher();
|
|
488609
489414
|
init_paths();
|
|
488610
489415
|
init_constants2();
|
|
@@ -538523,4 +539328,4 @@ function registerBunOAuthFlows() {
|
|
|
538523
539328
|
registerBunOAuthFlows();
|
|
538524
539329
|
await init_src5().then(() => exports_src2);
|
|
538525
539330
|
|
|
538526
|
-
//# debugId=
|
|
539331
|
+
//# debugId=B171A817D173726764756E2164756E21
|