@slopus/happy-providers 0.0.47 → 0.0.48
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/core/ProviderModelCompatibility.d.ts +2 -2
- package/dist/core/ProviderModelCompatibility.d.ts.map +1 -1
- package/dist/core/ProviderModelCompatibility.js +8 -2
- package/dist/core/ProviderModelCompatibility.js.map +1 -1
- package/dist/core/SessionProviderError.d.ts +12 -0
- package/dist/core/SessionProviderError.d.ts.map +1 -1
- package/dist/core/SessionProviderError.js +2 -0
- package/dist/core/SessionProviderError.js.map +1 -1
- package/dist/core/SessionRunRequest.d.ts +6 -0
- package/dist/core/SessionRunRequest.d.ts.map +1 -1
- package/dist/core/isNetworkFailure.d.ts +8 -0
- package/dist/core/isNetworkFailure.d.ts.map +1 -0
- package/dist/core/isNetworkFailure.js +45 -0
- package/dist/core/isNetworkFailure.js.map +1 -0
- package/dist/core/providerModelFamily.d.ts.map +1 -1
- package/dist/core/providerModelFamily.js +4 -0
- package/dist/core/providerModelFamily.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/protocol/acp/AcpConnection.d.ts +41 -0
- package/dist/protocol/acp/AcpConnection.d.ts.map +1 -0
- package/dist/protocol/acp/AcpConnection.js +2 -0
- package/dist/protocol/acp/AcpConnection.js.map +1 -0
- package/dist/protocol/acp/AcpProvider.d.ts +86 -0
- package/dist/protocol/acp/AcpProvider.d.ts.map +1 -0
- package/dist/protocol/acp/AcpProvider.js +27 -0
- package/dist/protocol/acp/AcpProvider.js.map +1 -0
- package/dist/protocol/acp/AcpSession.d.ts +26 -0
- package/dist/protocol/acp/AcpSession.d.ts.map +1 -0
- package/dist/protocol/acp/AcpSession.js +676 -0
- package/dist/protocol/acp/AcpSession.js.map +1 -0
- package/dist/protocol/acp/acpDiscoverModels.d.ts +10 -0
- package/dist/protocol/acp/acpDiscoverModels.d.ts.map +1 -0
- package/dist/protocol/acp/acpDiscoverModels.js +34 -0
- package/dist/protocol/acp/acpDiscoverModels.js.map +1 -0
- package/dist/protocol/acp/impl/AcpToolBridgeServer.d.ts +37 -0
- package/dist/protocol/acp/impl/AcpToolBridgeServer.d.ts.map +1 -0
- package/dist/protocol/acp/impl/AcpToolBridgeServer.js +136 -0
- package/dist/protocol/acp/impl/AcpToolBridgeServer.js.map +1 -0
- package/dist/protocol/acp/impl/AcpTurnQueue.d.ts +10 -0
- package/dist/protocol/acp/impl/AcpTurnQueue.d.ts.map +1 -0
- package/dist/protocol/acp/impl/AcpTurnQueue.js +26 -0
- package/dist/protocol/acp/impl/AcpTurnQueue.js.map +1 -0
- package/dist/protocol/acp/impl/acpCompactWithAgent.d.ts +10 -0
- package/dist/protocol/acp/impl/acpCompactWithAgent.d.ts.map +1 -0
- package/dist/protocol/acp/impl/acpCompactWithAgent.js +69 -0
- package/dist/protocol/acp/impl/acpCompactWithAgent.js.map +1 -0
- package/dist/protocol/acp/impl/acpConfigOptions.d.ts +22 -0
- package/dist/protocol/acp/impl/acpConfigOptions.d.ts.map +1 -0
- package/dist/protocol/acp/impl/acpConfigOptions.js +37 -0
- package/dist/protocol/acp/impl/acpConfigOptions.js.map +1 -0
- package/dist/protocol/acp/impl/acpConnectionSpawn.d.ts +9 -0
- package/dist/protocol/acp/impl/acpConnectionSpawn.d.ts.map +1 -0
- package/dist/protocol/acp/impl/acpConnectionSpawn.js +64 -0
- package/dist/protocol/acp/impl/acpConnectionSpawn.js.map +1 -0
- package/dist/protocol/acp/impl/acpPromptFromMessages.d.ts +22 -0
- package/dist/protocol/acp/impl/acpPromptFromMessages.d.ts.map +1 -0
- package/dist/protocol/acp/impl/acpPromptFromMessages.js +139 -0
- package/dist/protocol/acp/impl/acpPromptFromMessages.js.map +1 -0
- package/dist/protocol/acp/impl/acpResponseEvents.d.ts +20 -0
- package/dist/protocol/acp/impl/acpResponseEvents.d.ts.map +1 -0
- package/dist/protocol/acp/impl/acpResponseEvents.js +183 -0
- package/dist/protocol/acp/impl/acpResponseEvents.js.map +1 -0
- package/dist/protocol/acp/impl/acpSessionStore.d.ts +25 -0
- package/dist/protocol/acp/impl/acpSessionStore.d.ts.map +1 -0
- package/dist/protocol/acp/impl/acpSessionStore.js +50 -0
- package/dist/protocol/acp/impl/acpSessionStore.js.map +1 -0
- package/dist/protocol/acp/impl/processTree.d.ts +11 -0
- package/dist/protocol/acp/impl/processTree.d.ts.map +1 -0
- package/dist/protocol/acp/impl/processTree.js +80 -0
- package/dist/protocol/acp/impl/processTree.js.map +1 -0
- package/dist/vendors/bedrock/errors/anthropicBedrockErrors.d.ts.map +1 -1
- package/dist/vendors/bedrock/errors/anthropicBedrockErrors.js +6 -3
- package/dist/vendors/bedrock/errors/anthropicBedrockErrors.js.map +1 -1
- package/dist/vendors/claude/impl/auth.d.ts +3 -1
- package/dist/vendors/claude/impl/auth.d.ts.map +1 -1
- package/dist/vendors/claude/impl/auth.js +9 -6
- package/dist/vendors/claude/impl/auth.js.map +1 -1
- package/dist/vendors/claudeAgent/claudeAgentConnect.d.ts +10 -0
- package/dist/vendors/claudeAgent/claudeAgentConnect.d.ts.map +1 -0
- package/dist/vendors/claudeAgent/claudeAgentConnect.js +347 -0
- package/dist/vendors/claudeAgent/claudeAgentConnect.js.map +1 -0
- package/dist/vendors/claudeAgent/impl/AsyncInputQueue.d.ts +8 -0
- package/dist/vendors/claudeAgent/impl/AsyncInputQueue.d.ts.map +1 -0
- package/dist/vendors/claudeAgent/impl/AsyncInputQueue.js +37 -0
- package/dist/vendors/claudeAgent/impl/AsyncInputQueue.js.map +1 -0
- package/dist/vendors/claudeAgent/impl/claudeAgentUpdates.d.ts +12 -0
- package/dist/vendors/claudeAgent/impl/claudeAgentUpdates.d.ts.map +1 -0
- package/dist/vendors/claudeAgent/impl/claudeAgentUpdates.js +126 -0
- package/dist/vendors/claudeAgent/impl/claudeAgentUpdates.js.map +1 -0
- package/dist/vendors/codex/errors/codexErrors.d.ts.map +1 -1
- package/dist/vendors/codex/errors/codexErrors.js +8 -4
- package/dist/vendors/codex/errors/codexErrors.js.map +1 -1
- package/dist/vendors/codexAppServer/codexAppServerConnect.d.ts +11 -0
- package/dist/vendors/codexAppServer/codexAppServerConnect.d.ts.map +1 -0
- package/dist/vendors/codexAppServer/codexAppServerConnect.js +409 -0
- package/dist/vendors/codexAppServer/codexAppServerConnect.js.map +1 -0
- package/dist/vendors/codexAppServer/impl/codexItemUpdates.d.ts +10 -0
- package/dist/vendors/codexAppServer/impl/codexItemUpdates.d.ts.map +1 -0
- package/dist/vendors/codexAppServer/impl/codexItemUpdates.js +113 -0
- package/dist/vendors/codexAppServer/impl/codexItemUpdates.js.map +1 -0
- package/dist/vendors/codexAppServer/resolveCodexExecutable.d.ts +10 -0
- package/dist/vendors/codexAppServer/resolveCodexExecutable.d.ts.map +1 -0
- package/dist/vendors/codexAppServer/resolveCodexExecutable.js +61 -0
- package/dist/vendors/codexAppServer/resolveCodexExecutable.js.map +1 -0
- package/dist/vendors/foreignAgents/ForeignAgent.d.ts +74 -0
- package/dist/vendors/foreignAgents/ForeignAgent.d.ts.map +1 -0
- package/dist/vendors/foreignAgents/ForeignAgent.js +54 -0
- package/dist/vendors/foreignAgents/ForeignAgent.js.map +1 -0
- package/dist/vendors/foreignAgents/acpGenericAgent.d.ts +11 -0
- package/dist/vendors/foreignAgents/acpGenericAgent.d.ts.map +1 -0
- package/dist/vendors/foreignAgents/acpGenericAgent.js +33 -0
- package/dist/vendors/foreignAgents/acpGenericAgent.js.map +1 -0
- package/dist/vendors/foreignAgents/antigravityAgent.d.ts +11 -0
- package/dist/vendors/foreignAgents/antigravityAgent.d.ts.map +1 -0
- package/dist/vendors/foreignAgents/antigravityAgent.js +104 -0
- package/dist/vendors/foreignAgents/antigravityAgent.js.map +1 -0
- package/dist/vendors/foreignAgents/claudeCodeAgent.d.ts +8 -0
- package/dist/vendors/foreignAgents/claudeCodeAgent.d.ts.map +1 -0
- package/dist/vendors/foreignAgents/claudeCodeAgent.js +71 -0
- package/dist/vendors/foreignAgents/claudeCodeAgent.js.map +1 -0
- package/dist/vendors/foreignAgents/codexCliAgent.d.ts +10 -0
- package/dist/vendors/foreignAgents/codexCliAgent.d.ts.map +1 -0
- package/dist/vendors/foreignAgents/codexCliAgent.js +68 -0
- package/dist/vendors/foreignAgents/codexCliAgent.js.map +1 -0
- package/dist/vendors/foreignAgents/foreignAgents.d.ts +6 -0
- package/dist/vendors/foreignAgents/foreignAgents.d.ts.map +1 -0
- package/dist/vendors/foreignAgents/foreignAgents.js +17 -0
- package/dist/vendors/foreignAgents/foreignAgents.js.map +1 -0
- package/dist/vendors/foreignAgents/opencodeAgent.d.ts +8 -0
- package/dist/vendors/foreignAgents/opencodeAgent.d.ts.map +1 -0
- package/dist/vendors/foreignAgents/opencodeAgent.js +28 -0
- package/dist/vendors/foreignAgents/opencodeAgent.js.map +1 -0
- package/dist/vendors/grok/errors/grokErrors.d.ts.map +1 -1
- package/dist/vendors/grok/errors/grokErrors.js +6 -3
- package/dist/vendors/grok/errors/grokErrors.js.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acpPromptFromMessages.d.ts","sourceRoot":"","sources":["../../../../sources/protocol/acp/impl/acpPromptFromMessages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,KAAK,EAAE,cAAc,EAAsB,MAAM,0BAA0B,CAAC;AAEnF;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACjC,QAAQ,EAAE,SAAS,cAAc,EAAE,EACnC,MAAM,EAAE,OAAO,GAChB,YAAY,EAAE,CAkChB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC3B,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,SAAS,cAAc,EAAE,EAClC,OAAO,EAAE,SAAS,cAAc,EAAE,EAClC,MAAM,EAAE,OAAO,GAChB,YAAY,EAAE,CAchB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC5B,MAAM,EAAE,SAAS,cAAc,EAAE,EACjC,OAAO,EAAE,SAAS,cAAc,EAAE,EAClC,MAAM,EAAE,OAAO,GAChB,YAAY,EAAE,CAWhB"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The prompt that carries Happy messages into a foreign agent's next turn.
|
|
3
|
+
*
|
|
4
|
+
* ACP has exactly one input: a user prompt. Everything Happy adds to a conversation — the
|
|
5
|
+
* person's words, system notices, messages from other agents, results of tools the agent no
|
|
6
|
+
* longer has an open call for — is therefore rendered into that prompt, labelled so the foreign
|
|
7
|
+
* model can tell who said what.
|
|
8
|
+
*/
|
|
9
|
+
export function acpPromptFromMessages(messages, images) {
|
|
10
|
+
const blocks = [];
|
|
11
|
+
for (const message of messages) {
|
|
12
|
+
switch (message.role) {
|
|
13
|
+
case "user":
|
|
14
|
+
for (const block of message.content) {
|
|
15
|
+
if (block.type === "text")
|
|
16
|
+
blocks.push({ type: "text", text: block.text });
|
|
17
|
+
else if (block.type === "image")
|
|
18
|
+
pushImage(blocks, block, images);
|
|
19
|
+
}
|
|
20
|
+
break;
|
|
21
|
+
case "system":
|
|
22
|
+
blocks.push({
|
|
23
|
+
type: "text",
|
|
24
|
+
text: `<system-reminder>\n${textOf(message.content)}\n</system-reminder>`,
|
|
25
|
+
});
|
|
26
|
+
break;
|
|
27
|
+
case "agent":
|
|
28
|
+
blocks.push({
|
|
29
|
+
type: "text",
|
|
30
|
+
text: `<agent-message from="${message.author.id}" description="${message.author.description}">\n${textOf(message.content)}\n</agent-message>`,
|
|
31
|
+
});
|
|
32
|
+
break;
|
|
33
|
+
case "tool":
|
|
34
|
+
blocks.push({
|
|
35
|
+
type: "text",
|
|
36
|
+
text: `<happy-tool-result call="${message.callId}"${message.isError === true ? ' error="true"' : ""}>\n${textOf(message.content)}\n</happy-tool-result>`,
|
|
37
|
+
});
|
|
38
|
+
break;
|
|
39
|
+
case "assistant":
|
|
40
|
+
case "compaction":
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return mergeText(blocks);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A fresh foreign session that must continue a conversation it never saw: Happy's instructions
|
|
48
|
+
* and the transcript so far, then the new input.
|
|
49
|
+
*/
|
|
50
|
+
export function acpReplayPrompt(instructions, history, pending, images) {
|
|
51
|
+
const preamble = [];
|
|
52
|
+
if (instructions.trim().length > 0) {
|
|
53
|
+
preamble.push(`<happy-instructions>\n${instructions.trim()}\n</happy-instructions>`);
|
|
54
|
+
}
|
|
55
|
+
const transcript = history.map(transcriptLine).filter((line) => line.length > 0);
|
|
56
|
+
if (transcript.length > 0) {
|
|
57
|
+
preamble.push(`<conversation-so-far>\nThis conversation began before this session. Continue it.\n\n${transcript.join("\n\n")}\n</conversation-so-far>`);
|
|
58
|
+
}
|
|
59
|
+
const prompt = acpPromptFromMessages(pending, images);
|
|
60
|
+
if (preamble.length === 0)
|
|
61
|
+
return prompt;
|
|
62
|
+
return mergeText([{ type: "text", text: preamble.join("\n\n") }, ...prompt]);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A foreign session resuming after the conversation went on without it — another account,
|
|
66
|
+
* harness or model answered in between: what it missed as a transcript, then the new input.
|
|
67
|
+
*/
|
|
68
|
+
export function acpCatchUpPrompt(missed, pending, images) {
|
|
69
|
+
const transcript = missed.map(transcriptLine).filter((line) => line.length > 0);
|
|
70
|
+
const prompt = acpPromptFromMessages(pending, images);
|
|
71
|
+
if (transcript.length === 0)
|
|
72
|
+
return prompt;
|
|
73
|
+
return mergeText([
|
|
74
|
+
{
|
|
75
|
+
type: "text",
|
|
76
|
+
text: `<conversation-elsewhere>\nSince your last turn this conversation continued with another assistant. Continue from where it is now.\n\n${transcript.join("\n\n")}\n</conversation-elsewhere>`,
|
|
77
|
+
},
|
|
78
|
+
...prompt,
|
|
79
|
+
]);
|
|
80
|
+
}
|
|
81
|
+
function transcriptLine(message) {
|
|
82
|
+
switch (message.role) {
|
|
83
|
+
case "user":
|
|
84
|
+
return `User: ${textOf(message.content)}`;
|
|
85
|
+
case "system":
|
|
86
|
+
return `System: ${textOf(message.content)}`;
|
|
87
|
+
case "agent":
|
|
88
|
+
return `Agent ${message.author.id}: ${textOf(message.content)}`;
|
|
89
|
+
case "tool":
|
|
90
|
+
return `Tool result (${message.callId}): ${textOf(message.content)}`;
|
|
91
|
+
case "compaction":
|
|
92
|
+
return message.content === null ? "" : `Summary of earlier work: ${message.content}`;
|
|
93
|
+
case "assistant":
|
|
94
|
+
return `Assistant: ${message.content
|
|
95
|
+
.map((block) => {
|
|
96
|
+
if (block.type === "text")
|
|
97
|
+
return block.text;
|
|
98
|
+
if (block.type === "tool_call") {
|
|
99
|
+
return `[called ${block.name} ${block.arguments}]`;
|
|
100
|
+
}
|
|
101
|
+
if (block.type === "tool_result") {
|
|
102
|
+
return `[result ${textOf(block.content)}]`;
|
|
103
|
+
}
|
|
104
|
+
return "";
|
|
105
|
+
})
|
|
106
|
+
.filter((part) => part.length > 0)
|
|
107
|
+
.join("\n")}`;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function textOf(blocks) {
|
|
111
|
+
return blocks
|
|
112
|
+
.map((block) => block.type === "text" ? (block.text ?? "") : block.type === "image" ? "[image]" : "")
|
|
113
|
+
.filter((part) => part.length > 0)
|
|
114
|
+
.join("\n");
|
|
115
|
+
}
|
|
116
|
+
function pushImage(blocks, block, images) {
|
|
117
|
+
if (images)
|
|
118
|
+
blocks.push({ type: "image", data: block.data, mimeType: block.mimeType });
|
|
119
|
+
else
|
|
120
|
+
blocks.push({
|
|
121
|
+
type: "text",
|
|
122
|
+
text: "[An image was attached but this agent cannot see images.]",
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/** Adjacent text blocks become one, so the agent sees one coherent message. */
|
|
126
|
+
function mergeText(blocks) {
|
|
127
|
+
const merged = [];
|
|
128
|
+
for (const block of blocks) {
|
|
129
|
+
const last = merged[merged.length - 1];
|
|
130
|
+
if (block.type === "text" && last?.type === "text") {
|
|
131
|
+
merged[merged.length - 1] = { type: "text", text: `${last.text}\n\n${block.text}` };
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
merged.push(block);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return merged;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=acpPromptFromMessages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acpPromptFromMessages.js","sourceRoot":"","sources":["../../../../sources/protocol/acp/impl/acpPromptFromMessages.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CACjC,QAAmC,EACnC,MAAe;IAEf,MAAM,MAAM,GAAmB,EAAE,CAAC;IAClC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC7B,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;YACnB,KAAK,MAAM;gBACP,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;oBAClC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM;wBAAE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;yBACtE,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO;wBAAE,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;gBACtE,CAAC;gBACD,MAAM;YACV,KAAK,QAAQ;gBACT,MAAM,CAAC,IAAI,CAAC;oBACR,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,sBAAsB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,sBAAsB;iBAC5E,CAAC,CAAC;gBACH,MAAM;YACV,KAAK,OAAO;gBACR,MAAM,CAAC,I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,CAAC;SACjC,IAAI,CAAC,IAAI,CAAC,CAAC;AACpB,CAAC;AAED,SAAS,SAAS,CACd,MAAsB,EACtB,KAAqD,EACrD,MAAe;IAEf,IAAI,MAAM;QAAE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;;QAEnF,MAAM,CAAC,IAAI,CAAC;YACR,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,2DAA2D;SACpE,CAAC,CAAC;AACX,CAAC;AAED,+EAA+E;AAC/E,SAAS,SAAS,CAAC,MAAsB;IACrC,MAAM,MAAM,GAAmB,EAAE,CAAC;IAClC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACvC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,EAAE,IAAI,KAAK,MAAM,EAAE,CAAC;YACjD,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,IAAI,OAAO,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;QACxF,CAAC;aAAM,CAAC;YACJ,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type * as acp from "@agentclientprotocol/sdk";
|
|
2
|
+
import type { SessionEvent } from "../../../core/SessionEvent.js";
|
|
3
|
+
/** The MCP server name Happy's tools are served under inside the foreign agent. */
|
|
4
|
+
export declare const ACP_BRIDGE_NAME = "happy";
|
|
5
|
+
/**
|
|
6
|
+
* One Happy response being assembled from a foreign agent's updates.
|
|
7
|
+
*
|
|
8
|
+
* The foreign agent executes its own tools, so each of its calls becomes a provider-owned server
|
|
9
|
+
* call that is reported and settled inside the response. Happy never executes them.
|
|
10
|
+
*/
|
|
11
|
+
export declare class AcpResponseEvents {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(closed: Set<string>);
|
|
14
|
+
get outputCharacters(): number;
|
|
15
|
+
update(update: acp.SessionUpdate): Generator<SessionEvent>;
|
|
16
|
+
close(): Generator<SessionEvent>;
|
|
17
|
+
/** A response must not end with a foreign call it never settled. */
|
|
18
|
+
settleAll(): Generator<SessionEvent>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=acpResponseEvents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acpResponseEvents.d.ts","sourceRoot":"","sources":["../../../../sources/protocol/acp/impl/acpResponseEvents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,0BAA0B,CAAC;AAGrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D,mFAAmF;AACnF,eAAO,MAAM,eAAe,UAAU,CAAC;AAEvC;;;;;GAKG;AACH,qBAAa,iBAAiB;;IAO1B,YAAY,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,EAE9B;IAED,IAAI,gBAAgB,IAAI,MAAM,CAE7B;IAEA,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,aAAa,GAAG,SAAS,CAAC,YAAY,CAAC,CAqB1D;IAEA,KAAK,IAAI,SAAS,CAAC,YAAY,CAAC,CAIhC;IAED,oEAAoE;IACnE,SAAS,IAAI,SAAS,CAAC,YAAY,CAAC,CAcpC;CAqEJ"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/** The MCP server name Happy's tools are served under inside the foreign agent. */
|
|
2
|
+
export const ACP_BRIDGE_NAME = "happy";
|
|
3
|
+
/**
|
|
4
|
+
* One Happy response being assembled from a foreign agent's updates.
|
|
5
|
+
*
|
|
6
|
+
* The foreign agent executes its own tools, so each of its calls becomes a provider-owned server
|
|
7
|
+
* call that is reported and settled inside the response. Happy never executes them.
|
|
8
|
+
*/
|
|
9
|
+
export class AcpResponseEvents {
|
|
10
|
+
#open;
|
|
11
|
+
#outputCharacters = 0;
|
|
12
|
+
#calls = new Map();
|
|
13
|
+
/** Calls settled in any earlier response of this session; later updates are dropped. */
|
|
14
|
+
#closed;
|
|
15
|
+
constructor(closed) {
|
|
16
|
+
this.#closed = closed;
|
|
17
|
+
}
|
|
18
|
+
get outputCharacters() {
|
|
19
|
+
return this.#outputCharacters;
|
|
20
|
+
}
|
|
21
|
+
*update(update) {
|
|
22
|
+
switch (update.sessionUpdate) {
|
|
23
|
+
case "agent_message_chunk":
|
|
24
|
+
if (update.content.type !== "text")
|
|
25
|
+
return;
|
|
26
|
+
yield* this.#openBlock("text");
|
|
27
|
+
this.#outputCharacters += update.content.text.length;
|
|
28
|
+
yield { type: "text_delta", delta: update.content.text };
|
|
29
|
+
return;
|
|
30
|
+
case "agent_thought_chunk":
|
|
31
|
+
if (update.content.type !== "text")
|
|
32
|
+
return;
|
|
33
|
+
yield* this.#openBlock("reasoning");
|
|
34
|
+
this.#outputCharacters += update.content.text.length;
|
|
35
|
+
yield { type: "reasoning_delta", delta: update.content.text };
|
|
36
|
+
return;
|
|
37
|
+
case "tool_call":
|
|
38
|
+
case "tool_call_update":
|
|
39
|
+
yield* this.#toolCall(update);
|
|
40
|
+
return;
|
|
41
|
+
default:
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
*close() {
|
|
46
|
+
if (this.#open === "text")
|
|
47
|
+
yield { type: "text_end" };
|
|
48
|
+
if (this.#open === "reasoning")
|
|
49
|
+
yield { type: "reasoning_end" };
|
|
50
|
+
this.#open = undefined;
|
|
51
|
+
}
|
|
52
|
+
/** A response must not end with a foreign call it never settled. */
|
|
53
|
+
*settleAll() {
|
|
54
|
+
for (const [id, call] of this.#calls) {
|
|
55
|
+
if (call.settled)
|
|
56
|
+
continue;
|
|
57
|
+
yield* this.#settle(id, [
|
|
58
|
+
{
|
|
59
|
+
type: "text",
|
|
60
|
+
text: "The agent had not finished this step when the response ended.",
|
|
61
|
+
},
|
|
62
|
+
], false);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
*#openBlock(kind) {
|
|
66
|
+
if (this.#open === kind)
|
|
67
|
+
return;
|
|
68
|
+
yield* this.close();
|
|
69
|
+
this.#open = kind;
|
|
70
|
+
yield kind === "text" ? { type: "text_start" } : { type: "reasoning_start" };
|
|
71
|
+
}
|
|
72
|
+
*#toolCall(update) {
|
|
73
|
+
const id = update.toolCallId;
|
|
74
|
+
if (this.#closed.has(id))
|
|
75
|
+
return;
|
|
76
|
+
let call = this.#calls.get(id);
|
|
77
|
+
if (call === undefined) {
|
|
78
|
+
if (isBridgeToolCall(update)) {
|
|
79
|
+
// Already reported as a Happy tool call when the bridge received it.
|
|
80
|
+
this.#closed.add(id);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
yield* this.close();
|
|
84
|
+
call = { settled: false };
|
|
85
|
+
this.#calls.set(id, call);
|
|
86
|
+
yield {
|
|
87
|
+
type: "toolcall_start",
|
|
88
|
+
callId: id,
|
|
89
|
+
name: update.kind ?? "other",
|
|
90
|
+
server: true,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// Agents announce a call before its input is known and fill it in with later updates;
|
|
94
|
+
// the call is recorded with what was known when it settled.
|
|
95
|
+
if (update.title != null)
|
|
96
|
+
call.title = update.title;
|
|
97
|
+
if (update.rawInput !== undefined && !isEmptyObject(update.rawInput)) {
|
|
98
|
+
call.input = update.rawInput;
|
|
99
|
+
}
|
|
100
|
+
if (update.locations != null && update.locations.length > 0) {
|
|
101
|
+
call.paths = update.locations.map((location) => location.path);
|
|
102
|
+
}
|
|
103
|
+
if (update.status === "completed" || update.status === "failed") {
|
|
104
|
+
yield* this.#settle(id, toolResultContent(update), update.status === "failed");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
*#settle(id, content, isError) {
|
|
108
|
+
const call = this.#calls.get(id);
|
|
109
|
+
if (call === undefined || call.settled)
|
|
110
|
+
return;
|
|
111
|
+
call.settled = true;
|
|
112
|
+
this.#closed.add(id);
|
|
113
|
+
yield {
|
|
114
|
+
type: "toolcall_end",
|
|
115
|
+
callId: id,
|
|
116
|
+
arguments: JSON.stringify({
|
|
117
|
+
...(call.title === undefined ? {} : { title: call.title }),
|
|
118
|
+
...(call.input === undefined ? {} : { input: call.input }),
|
|
119
|
+
...(call.paths === undefined ? {} : { paths: call.paths }),
|
|
120
|
+
}),
|
|
121
|
+
};
|
|
122
|
+
yield { type: "toolcall_result_start", callId: id };
|
|
123
|
+
yield {
|
|
124
|
+
type: "toolcall_result_end",
|
|
125
|
+
callId: id,
|
|
126
|
+
content,
|
|
127
|
+
...(isError ? { isError: true } : {}),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function isEmptyObject(value) {
|
|
132
|
+
return (typeof value === "object" &&
|
|
133
|
+
value !== null &&
|
|
134
|
+
!Array.isArray(value) &&
|
|
135
|
+
Object.keys(value).length === 0);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Whether a foreign tool call is the agent's own record of calling Happy's bridge. Agents report
|
|
139
|
+
* MCP calls differently; Antigravity names the server in `rawInput.ServerName`, others use the
|
|
140
|
+
* `mcp__<server>__<tool>` convention in the title.
|
|
141
|
+
*/
|
|
142
|
+
function isBridgeToolCall(update) {
|
|
143
|
+
const raw = update.rawInput;
|
|
144
|
+
if (typeof raw === "object" && raw !== null) {
|
|
145
|
+
const record = raw;
|
|
146
|
+
for (const key of ["ServerName", "serverName", "server_name", "server"]) {
|
|
147
|
+
if (record[key] === ACP_BRIDGE_NAME)
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return update.title?.startsWith(`mcp__${ACP_BRIDGE_NAME}__`) === true;
|
|
152
|
+
}
|
|
153
|
+
function toolResultContent(update) {
|
|
154
|
+
const blocks = [];
|
|
155
|
+
for (const item of update.content ?? []) {
|
|
156
|
+
if (item.type === "content") {
|
|
157
|
+
if (item.content.type === "text")
|
|
158
|
+
blocks.push({ type: "text", text: item.content.text });
|
|
159
|
+
if (item.content.type === "image") {
|
|
160
|
+
blocks.push({
|
|
161
|
+
type: "image",
|
|
162
|
+
data: item.content.data,
|
|
163
|
+
mimeType: item.content.mimeType,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else if (item.type === "diff") {
|
|
168
|
+
blocks.push({ type: "text", text: `Edited ${item.path}\n${item.newText}` });
|
|
169
|
+
}
|
|
170
|
+
else if (item.type === "terminal") {
|
|
171
|
+
blocks.push({ type: "text", text: `Terminal ${item.terminalId}` });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (blocks.length > 0)
|
|
175
|
+
return blocks;
|
|
176
|
+
const raw = update.rawOutput;
|
|
177
|
+
if (typeof raw === "string")
|
|
178
|
+
return [{ type: "text", text: raw }];
|
|
179
|
+
if (raw !== undefined && raw !== null)
|
|
180
|
+
return [{ type: "text", text: JSON.stringify(raw) }];
|
|
181
|
+
return [{ type: "text", text: "Done." }];
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=acpResponseEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acpResponseEvents.js","sourceRoot":"","sources":["../../../../sources/protocol/acp/impl/acpResponseEvents.ts"],"names":[],"mappings":"AAKA,mFAAmF;AACnF,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IAC1B,KAAK,CAAmC;IACxC,iBAAiB,GAAG,CAAC,CAAC;IACb,MAAM,GAAG,IAAI,GAAG,EAAuB,CAAC;IACjD,wFAAwF;IAC/E,OAAO,CAAc;IA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,MAAM,EAAE,IAAI,EAAE,UAAU,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAChF,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAClC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QACvE,CAAC;IACL,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,MAAM,CAAC;IACrC,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC;IAC7B,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;IAClE,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC5F,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SessionMessage } from "../../../core/SessionContext.js";
|
|
2
|
+
/**
|
|
3
|
+
* Where one Happy conversation stands inside its foreign agent's own session.
|
|
4
|
+
*
|
|
5
|
+
* The foreign agent keeps its native context; Happy keeps the canonical transcript. This record
|
|
6
|
+
* is the join between them: which ACP session continues this conversation, and how much of the
|
|
7
|
+
* Happy transcript that session has already seen. `fingerprint` covers exactly that prefix, so a
|
|
8
|
+
* compaction, a provider switch, or an edited history is detected and answered with a fresh
|
|
9
|
+
* session and a replay instead of silently continuing a context that no longer matches.
|
|
10
|
+
*/
|
|
11
|
+
export interface AcpSessionRecord {
|
|
12
|
+
readonly acpSessionId: string;
|
|
13
|
+
readonly cwd: string;
|
|
14
|
+
readonly consumed: number;
|
|
15
|
+
readonly fingerprint: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function acpSessionRecordRead(directory: string, id: string): Promise<AcpSessionRecord | undefined>;
|
|
18
|
+
export declare function acpSessionRecordWrite(directory: string, id: string, record: AcpSessionRecord): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Identity of a transcript prefix as far as the foreign agent is concerned: what people and
|
|
21
|
+
* agents said. Assistant and tool records are deliberately left out — their canonical form is
|
|
22
|
+
* re-derived by Agent Base, while the words that entered the conversation never change.
|
|
23
|
+
*/
|
|
24
|
+
export declare function acpTranscriptFingerprint(messages: readonly SessionMessage[]): string;
|
|
25
|
+
//# sourceMappingURL=acpSessionStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acpSessionStore.d.ts","sourceRoot":"","sources":["../../../../sources/protocol/acp/impl/acpSessionStore.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE/D;;;;;;;;GAQG;AACH,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAChC;AAMD,wBAAsB,oBAAoB,CACtC,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,GACX,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAiBvC;AAED,wBAAsB,qBAAqB,CACvC,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,gBAAgB,GACzB,OAAO,CAAC,IAAI,CAAC,CAMf;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,CAWpF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
function recordPath(directory, id) {
|
|
5
|
+
return join(directory, "sessions", `${encodeURIComponent(id)}.json`);
|
|
6
|
+
}
|
|
7
|
+
export async function acpSessionRecordRead(directory, id) {
|
|
8
|
+
try {
|
|
9
|
+
const raw = JSON.parse(await readFile(recordPath(directory, id), "utf8"));
|
|
10
|
+
if (typeof raw === "object" &&
|
|
11
|
+
raw !== null &&
|
|
12
|
+
typeof raw.acpSessionId === "string" &&
|
|
13
|
+
typeof raw.cwd === "string" &&
|
|
14
|
+
typeof raw.consumed === "number" &&
|
|
15
|
+
typeof raw.fingerprint === "string") {
|
|
16
|
+
return raw;
|
|
17
|
+
}
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export async function acpSessionRecordWrite(directory, id, record) {
|
|
25
|
+
const path = recordPath(directory, id);
|
|
26
|
+
await mkdir(join(directory, "sessions"), { recursive: true, mode: 0o700 });
|
|
27
|
+
const temporary = `${path}.${process.pid}.tmp`;
|
|
28
|
+
await writeFile(temporary, JSON.stringify(record), { mode: 0o600 });
|
|
29
|
+
await rename(temporary, path);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Identity of a transcript prefix as far as the foreign agent is concerned: what people and
|
|
33
|
+
* agents said. Assistant and tool records are deliberately left out — their canonical form is
|
|
34
|
+
* re-derived by Agent Base, while the words that entered the conversation never change.
|
|
35
|
+
*/
|
|
36
|
+
export function acpTranscriptFingerprint(messages) {
|
|
37
|
+
const hash = createHash("sha256");
|
|
38
|
+
hash.update(String(messages.length));
|
|
39
|
+
for (const message of messages) {
|
|
40
|
+
hash.update(`\u0000${message.role}`);
|
|
41
|
+
if (message.role !== "user" && message.role !== "agent")
|
|
42
|
+
continue;
|
|
43
|
+
for (const block of message.content) {
|
|
44
|
+
if (block.type === "text")
|
|
45
|
+
hash.update(block.text);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return hash.digest("hex");
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=acpSessionStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acpSessionStore.js","sourceRoot":"","sources":["../../../../sources/protocol/acp/impl/acpSessionStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAoBjC,SAAS,UAAU,CAAC,SAAiB,EAAE,EAAU;IAC7C,OAAO,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,GAAG,kBAAkB,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACtC,SAAiB,EACjB,EAAU;IAEV,IAAI,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,UAAU,CAAC,SAAS,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,CAAY,CAAC;QACrF,IACI,OAAO,GAAG,KAAK,QAAQ;YACvB,GAAG,KAAK,IAAI;YACZ,OAAQ,GAAwB,CAAC,YAAY,KAAK,QAAQ;YAC1D,OAAQ,GAAwB,CAAC,GAAG,KAAK,QAAQ;YACjD,OAAQ,GAAwB,CAAC,QAAQ,KAAK,QAAQ;YACtD,OAAQ,GAAwB,CAAC,WAAW,KAAK,QAAQ,EAC3D,CAAC;YACC,OAAO,GAAuB,CAAC;QACnC,CAAC;QACD,O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AAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ChildProcess } from "node:child_process";
|
|
2
|
+
/**
|
|
3
|
+
* End a detached agent process and everything below it. Agents leave a running command alive
|
|
4
|
+
* when their turn is cancelled, and some start each command in a process group of its own, so
|
|
5
|
+
* every group in the tree is signalled, plus `groups` taken earlier for commands the agent may
|
|
6
|
+
* have orphaned since. Whatever is still running a moment later is killed outright.
|
|
7
|
+
*/
|
|
8
|
+
export declare function terminateProcessTree(child: Pick<ChildProcess, "pid" | "exitCode" | "signalCode" | "kill">, groups?: readonly number[]): void;
|
|
9
|
+
/** The process groups of `root` and every process below it, from one process table snapshot. */
|
|
10
|
+
export declare function processTreeGroups(root: number | undefined): number[];
|
|
11
|
+
//# sourceMappingURL=processTree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processTree.d.ts","sourceRoot":"","sources":["../../../../sources/protocol/acp/impl/processTree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAErE;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAChC,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,KAAK,GAAG,UAAU,GAAG,YAAY,GAAG,MAAM,CAAC,EACrE,MAAM,GAAE,SAAS,MAAM,EAAO,GAC/B,IAAI,CAoBN;AAeD,gGAAgG;AAChG,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,CA4BpE"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
/**
|
|
3
|
+
* End a detached agent process and everything below it. Agents leave a running command alive
|
|
4
|
+
* when their turn is cancelled, and some start each command in a process group of its own, so
|
|
5
|
+
* every group in the tree is signalled, plus `groups` taken earlier for commands the agent may
|
|
6
|
+
* have orphaned since. Whatever is still running a moment later is killed outright.
|
|
7
|
+
*/
|
|
8
|
+
export function terminateProcessTree(child, groups = []) {
|
|
9
|
+
if (process.platform === "win32") {
|
|
10
|
+
// Windows has no process groups; taskkill ends the whole tree below the agent.
|
|
11
|
+
if (child.pid !== undefined) {
|
|
12
|
+
try {
|
|
13
|
+
execFileSync("taskkill", ["/pid", String(child.pid), "/T", "/F"], {
|
|
14
|
+
stdio: "ignore",
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// Already gone.
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
22
|
+
child.kill();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const all = new Set([...groups, ...processTreeGroups(child.pid)]);
|
|
26
|
+
if (child.pid !== undefined)
|
|
27
|
+
all.add(child.pid);
|
|
28
|
+
signalGroups(all, "SIGTERM");
|
|
29
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
30
|
+
child.kill("SIGTERM");
|
|
31
|
+
setTimeout(() => signalGroups(all, "SIGKILL"), KILL_AFTER_MS).unref();
|
|
32
|
+
}
|
|
33
|
+
/** How long a terminated agent tree may take to exit on its own before it is killed. */
|
|
34
|
+
const KILL_AFTER_MS = 3_000;
|
|
35
|
+
function signalGroups(groups, signal) {
|
|
36
|
+
for (const group of groups) {
|
|
37
|
+
try {
|
|
38
|
+
process.kill(-group, signal);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// Already gone.
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** The process groups of `root` and every process below it, from one process table snapshot. */
|
|
46
|
+
export function processTreeGroups(root) {
|
|
47
|
+
if (root === undefined || process.platform === "win32")
|
|
48
|
+
return [];
|
|
49
|
+
let table;
|
|
50
|
+
try {
|
|
51
|
+
table = execFileSync("ps", ["-A", "-o", "pid=,ppid=,pgid="], { encoding: "utf8" });
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
const children = new Map();
|
|
57
|
+
const groupOf = new Map();
|
|
58
|
+
for (const line of table.split("\n")) {
|
|
59
|
+
const [pid, ppid, pgid] = line.trim().split(/\s+/).map(Number);
|
|
60
|
+
if (pid === undefined || ppid === undefined || pgid === undefined)
|
|
61
|
+
continue;
|
|
62
|
+
if (!Number.isFinite(pid) || !Number.isFinite(pgid))
|
|
63
|
+
continue;
|
|
64
|
+
children.set(ppid, [...(children.get(ppid) ?? []), pid]);
|
|
65
|
+
groupOf.set(pid, pgid);
|
|
66
|
+
}
|
|
67
|
+
const groups = new Set();
|
|
68
|
+
const pending = [root];
|
|
69
|
+
while (pending.length > 0) {
|
|
70
|
+
const pid = pending.pop();
|
|
71
|
+
const group = groupOf.get(pid);
|
|
72
|
+
if (group !== undefined)
|
|
73
|
+
groups.add(group);
|
|
74
|
+
pending.push(...(children.get(pid) ?? []));
|
|
75
|
+
}
|
|
76
|
+
// Never the daemon's own group, whatever a child did with its own.
|
|
77
|
+
groups.delete(groupOf.get(process.pid) ?? -1);
|
|
78
|
+
return [...groups];
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=processTree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processTree.js","sourceRoot":"","sources":["../../../../sources/protocol/acp/impl/processTree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAqB,MAAM,oBAAoB,CAAC;AAErE;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAChC,KAAqE,EACrE,MAAM,GAAsB,EAAE;IAE9B,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QAC/B,+EAA+E;QAC/E,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;YAC1B,IAAI,CAAC;gBACD,YAAY,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG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AG,EAAG,CAAC;QAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,KAAK,KAAK,SAAS;YAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC3C,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC;IACD,mEAAmE;IACnE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropicBedrockErrors.d.ts","sourceRoot":"","sources":["../../../../sources/vendors/bedrock/errors/anthropicBedrockErrors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"anthropicBedrockErrors.d.ts","sourceRoot":"","sources":["../../../../sources/vendors/bedrock/errors/anthropicBedrockErrors.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAQrF;;;;GAIG;AACH,wBAAgB,oCAAoC,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAa3E;AAED,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAsB9E;AAED,wBAAgB,qCAAqC,CACjD,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,MAAM,GACjB,oBAAoB,CAqCtB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { APIError } from "@anthropic-ai/sdk/error";
|
|
2
2
|
import { extractProviderErrorDiagnostics, extractProviderRetryResetAt, } from "../../../core/extractProviderErrorDiagnostics.js";
|
|
3
|
+
import { isNetworkFailure } from "../../../core/isNetworkFailure.js";
|
|
3
4
|
import { anthropicBedrockRuntimeExceptionDetails, anthropicBedrockStreamErrorDetails, isAnthropicBedrockConnectionFailure, resolveAnthropicBedrockErrorStatus, } from "../../../vendors/bedrock/impl/anthropicBedrockRetry.js";
|
|
4
5
|
/**
|
|
5
6
|
* Surfaced errors must read like a sentence. Raw transport failures such as undici's
|
|
@@ -61,9 +62,11 @@ export function classifyAnthropicBedrockProviderError(error, attempts) {
|
|
|
61
62
|
? "rate_limit"
|
|
62
63
|
: status === 503 || status === 529 || normalized.includes("overloaded")
|
|
63
64
|
? "server_overloaded"
|
|
64
|
-
:
|
|
65
|
-
? "
|
|
66
|
-
: "
|
|
65
|
+
: status === undefined && isNetworkFailure(error, message)
|
|
66
|
+
? "network"
|
|
67
|
+
: (status !== undefined && status >= 500) || kind === "internal_error"
|
|
68
|
+
? "internal_server_error"
|
|
69
|
+
: "unclassified";
|
|
67
70
|
if (type === "rate_limit" || type === "out_of_tokens") {
|
|
68
71
|
const resetAt = extractProviderRetryResetAt(error);
|
|
69
72
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropicBedrockErrors.js","sourceRoot":"","sources":["../../../../sources/vendors/bedrock/errors/anthropicBedrockErrors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAEnD,OAAO,EACH,+BAA+B,EAC/B,2BAA2B,GAC9B,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"anthropicBedrockErrors.js","sourceRoot":"","sources":["../../../../sources/vendors/bedrock/errors/anthropicBedrockErrors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAEnD,OAAO,EACH,+BAA+B,EAC/B,2BAA2B,GAC9B,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,EACH,uCAAuC,EACvC,kCAAkC,EACl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K,GAAG,IAAI,IAAI,KAAK,eAAe;YAC1C,CAAC,CAAC,eAAe;YACjB,CAAC,CAAC,MAAM,KAAK,GAAG;gBACd,CAAC,CAAC,YAAY;gBACd,CAAC,CAAC,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,QAAQ,CAAC,YAAY,CAAC;oBACrE,CAAC,CAAC,mBAAmB;oBACrB,CAAC,CAAC,MAAM,KAAK,SAAS,IAAI,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC;wBACxD,CAAC,CAAC,SAAS;wBACX,CAAC,CAAC,CAAC,MAAM,KAAK,SAAS,IAAI,MAAM,IAAI,GAAG,CAAC,IAAI,IAAI,KAAK,gBAAgB;4BACpE,CAAC,CAAC,uBAAuB;4BACzB,CAAC,CAAC,cAAc,CAAC;IACnC,IAAI,IAAI,KAAK,YAAY,IAAI,IAAI,KAAK,eAAe,EAAE,CAAC;QACpD,MAAM,OAAO,GAAG,2BAA2B,CAAC,KAAK,CAAC,CAAC;QACnD,OAAO;YACH,IAAI;YACJ,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC;YAC7C,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;SACxD,CAAC;IACN,CAAC;IACD,OAAO;QACH,IAAI;QACJ,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;KACxD,CAAC;AACN,CAAC"}
|
|
@@ -17,5 +17,7 @@ export declare function parseClaudeOAuthAccessToken(value: string): string | und
|
|
|
17
17
|
export declare function readClaudeCodeOAuthToken(options?: ReadClaudeCodeOAuthTokenOptions): Promise<string | undefined>;
|
|
18
18
|
/** Reads the native Claude Code token together with the kind of grant it came from. */
|
|
19
19
|
export declare function readClaudeCodeOAuthCredential(options?: ReadClaudeCodeOAuthTokenOptions): Promise<ClaudeCodeOAuthCredential | undefined>;
|
|
20
|
-
export declare function readTokenFromMacOsKeychain(configDirectory: string, env: NodeJS.ProcessEnv
|
|
20
|
+
export declare function readTokenFromMacOsKeychain(configDirectory: string, env: NodeJS.ProcessEnv,
|
|
21
|
+
/** How long one `security` child may run, launch included; tests not about the deadline lift it. */
|
|
22
|
+
attemptTimeoutMs?: number): Promise<string | undefined>;
|
|
21
23
|
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../../sources/vendors/claude/impl/auth.ts"],"names":[],"mappings":"AAoBA,6EAA6E;AAC7E,MAAM,WAAW,yBAAyB;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC;IAChC,wFAAwF;IACxF,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;CACzC;AAED,MAAM,WAAW,+BAA+B;IAC5C,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CAC3B;AAED,wBAAgB,kBAAkB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,CAE/E;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE7E;AAoBD,wBAAsB,wBAAwB,CAC1C,OAAO,GAAE,+BAAoC,GAC9C,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAE7B;AAED,uFAAuF;AACvF,wBAAsB,6BAA6B,CAC/C,OAAO,GAAE,+BAAoC,GAC9C,OAAO,CAAC,yBAAyB,GAAG,SAAS,CAAC,CA6BhD;AAED,wBAAsB,0BAA0B,CAC5C,eAAe,EAAE,MAAM,EACvB,GAAG,EAAE,MAAM,CAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"auth.d.ts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