mcp-agent-foundry 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -3
- package/dist/config/validator.d.ts +2 -2
- package/dist/config/validator.d.ts.map +1 -1
- package/dist/config/validator.js +2 -2
- package/dist/config/validator.js.map +1 -1
- package/dist/failover/orchestrator.d.ts.map +1 -1
- package/dist/failover/orchestrator.js +12 -2
- package/dist/failover/orchestrator.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mcp/tools/critique-plan.d.ts.map +1 -1
- package/dist/mcp/tools/critique-plan.js +57 -4
- package/dist/mcp/tools/critique-plan.js.map +1 -1
- package/dist/mcp/tools/design-feedback.d.ts.map +1 -1
- package/dist/mcp/tools/design-feedback.js +58 -4
- package/dist/mcp/tools/design-feedback.js.map +1 -1
- package/dist/mcp/tools/invoke-agent.d.ts.map +1 -1
- package/dist/mcp/tools/invoke-agent.js +64 -1
- package/dist/mcp/tools/invoke-agent.js.map +1 -1
- package/dist/mcp/tools/review-code.d.ts.map +1 -1
- package/dist/mcp/tools/review-code.js +57 -4
- package/dist/mcp/tools/review-code.js.map +1 -1
- package/dist/mcp/tools/tasks/execute-task.d.ts.map +1 -1
- package/dist/mcp/tools/tasks/execute-task.js +74 -5
- package/dist/mcp/tools/tasks/execute-task.js.map +1 -1
- package/dist/providers/anthropic.d.ts +40 -6
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +120 -8
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/base.d.ts +6 -3
- package/dist/providers/base.d.ts.map +1 -1
- package/dist/providers/base.js.map +1 -1
- package/dist/router/engine.d.ts +3 -3
- package/dist/router/engine.d.ts.map +1 -1
- package/dist/router/engine.js +32 -4
- package/dist/router/engine.js.map +1 -1
- package/dist/router/pattern-executor.d.ts.map +1 -1
- package/dist/router/pattern-executor.js +38 -7
- package/dist/router/pattern-executor.js.map +1 -1
- package/dist/types.d.ts +39 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Available roles: coder, critic, designer, researcher, reviewer
|
|
6
6
|
*/
|
|
7
7
|
import { z } from "zod";
|
|
8
|
+
import { isSessionDelegation } from "../../types.js";
|
|
8
9
|
// ============================================================================
|
|
9
10
|
// Constants
|
|
10
11
|
// ============================================================================
|
|
@@ -15,7 +16,13 @@ const AGENT_ROLES = ["coder", "critic", "designer", "orchestrator", "researcher"
|
|
|
15
16
|
/**
|
|
16
17
|
* Tool description for invoke_agent
|
|
17
18
|
*/
|
|
18
|
-
const TOOL_DESCRIPTION =
|
|
19
|
+
const TOOL_DESCRIPTION = `Invoke a specialized AI agent for a specific task.
|
|
20
|
+
|
|
21
|
+
When configured with session mode (for Claude Code users), this tool returns
|
|
22
|
+
delegation instructions instead of making an API call. The current session
|
|
23
|
+
should follow the instructions to complete the task.
|
|
24
|
+
|
|
25
|
+
Available roles: coder (code generation), critic (plan review, assumption challenging), designer (UI/UX feedback), orchestrator (task synthesis, document improvement), researcher (fact-finding), reviewer (code review).`;
|
|
19
26
|
// ============================================================================
|
|
20
27
|
// Input Schema
|
|
21
28
|
// ============================================================================
|
|
@@ -51,6 +58,44 @@ function formatAgentResponse(response) {
|
|
|
51
58
|
.join("\n");
|
|
52
59
|
return header + meta + content;
|
|
53
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Format a session delegation response for MCP output.
|
|
63
|
+
* This instructs the current Claude session to handle the request.
|
|
64
|
+
*
|
|
65
|
+
* @param delegation - The session delegation response from the provider
|
|
66
|
+
* @returns Formatted string with delegation instructions
|
|
67
|
+
*/
|
|
68
|
+
function formatDelegationResponse(delegation) {
|
|
69
|
+
const contextSection = delegation.context
|
|
70
|
+
? `### Additional Context\n\n${delegation.context}\n\n`
|
|
71
|
+
: "";
|
|
72
|
+
return `## Session Delegation
|
|
73
|
+
|
|
74
|
+
This request is being delegated to the current Claude session.
|
|
75
|
+
|
|
76
|
+
**Role**: ${delegation.role}
|
|
77
|
+
**Model Requested**: ${delegation.model || "default"}
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
### Instructions
|
|
82
|
+
|
|
83
|
+
${delegation.instructions}
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
### System Prompt to Apply
|
|
88
|
+
|
|
89
|
+
\`\`\`
|
|
90
|
+
${delegation.system_prompt}
|
|
91
|
+
\`\`\`
|
|
92
|
+
|
|
93
|
+
### Task to Execute
|
|
94
|
+
|
|
95
|
+
${delegation.task}
|
|
96
|
+
|
|
97
|
+
${contextSection}`.trim();
|
|
98
|
+
}
|
|
54
99
|
// ============================================================================
|
|
55
100
|
// Tool Registration
|
|
56
101
|
// ============================================================================
|
|
@@ -93,6 +138,24 @@ export function registerInvokeAgentTool(server, router, logger) {
|
|
|
93
138
|
const invokeInput = context !== undefined ? { role, task, context } : { role, task };
|
|
94
139
|
const response = await router.invokeAgent(invokeInput);
|
|
95
140
|
const durationMs = Date.now() - startTime;
|
|
141
|
+
// Handle session delegation responses
|
|
142
|
+
if (isSessionDelegation(response)) {
|
|
143
|
+
logger.info("invoke_agent delegated to session", {
|
|
144
|
+
role,
|
|
145
|
+
model: response.model,
|
|
146
|
+
durationMs,
|
|
147
|
+
});
|
|
148
|
+
return {
|
|
149
|
+
content: [
|
|
150
|
+
{
|
|
151
|
+
type: "text",
|
|
152
|
+
text: formatDelegationResponse(response),
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
isError: false,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
// Handle normal completion responses
|
|
96
159
|
logger.info("invoke_agent completed", {
|
|
97
160
|
role,
|
|
98
161
|
provider: response.provider,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invoke-agent.js","sourceRoot":"","sources":["../../../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,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAE5E,sDAAsD;YACtD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;gBAC3B,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE;oBAClC,IAAI;oBACJ,KAAK;oBACL,YAAY;iBACb,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE;oBAClC,IAAI;oBACJ,YAAY;iBACb,CAAC,CAAC;YACL,CAAC;YAED,qDAAqD;YACrD,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,qBAAqB,IAAI,CAAC,WAAW,EAAE,aAAa,YAAY,EAAE;qBACzE;iBACF;aACF,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,8BAA8B,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"review-code.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/review-code.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"review-code.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/review-code.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AA+I3D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,GACb,IAAI,CAwGN"}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* This is a shorthand for invoking the 'reviewer' role with code-specific formatting.
|
|
6
6
|
*/
|
|
7
7
|
import { z } from "zod";
|
|
8
|
+
import { isSessionDelegation } from "../../types.js";
|
|
8
9
|
// ============================================================================
|
|
9
10
|
// Constants
|
|
10
11
|
// ============================================================================
|
|
@@ -49,6 +50,39 @@ function formatCodeReviewResponse(response) {
|
|
|
49
50
|
.join("\n");
|
|
50
51
|
return header + meta + content;
|
|
51
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Format a session delegation response for MCP output.
|
|
55
|
+
*
|
|
56
|
+
* @param delegation - The session delegation response from the provider
|
|
57
|
+
* @returns Formatted string with delegation instructions
|
|
58
|
+
*/
|
|
59
|
+
function formatDelegationResponse(delegation) {
|
|
60
|
+
return `## Session Delegation
|
|
61
|
+
|
|
62
|
+
This request is being delegated to the current Claude session.
|
|
63
|
+
|
|
64
|
+
**Role**: ${delegation.role}
|
|
65
|
+
**Model Requested**: ${delegation.model || "default"}
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
### Instructions
|
|
70
|
+
|
|
71
|
+
${delegation.instructions}
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
### System Prompt to Apply
|
|
76
|
+
|
|
77
|
+
\`\`\`
|
|
78
|
+
${delegation.system_prompt}
|
|
79
|
+
\`\`\`
|
|
80
|
+
|
|
81
|
+
### Task to Execute
|
|
82
|
+
|
|
83
|
+
${delegation.task}
|
|
84
|
+
`.trim();
|
|
85
|
+
}
|
|
52
86
|
// ============================================================================
|
|
53
87
|
// Task Builder
|
|
54
88
|
// ============================================================================
|
|
@@ -125,17 +159,36 @@ export function registerReviewCodeTool(server, router, logger) {
|
|
|
125
159
|
task: taskString,
|
|
126
160
|
});
|
|
127
161
|
const durationMs = Date.now() - startTime;
|
|
162
|
+
// Handle session delegation responses
|
|
163
|
+
if (isSessionDelegation(response)) {
|
|
164
|
+
logger.info("review_code delegated to session", {
|
|
165
|
+
model: response.model,
|
|
166
|
+
durationMs,
|
|
167
|
+
});
|
|
168
|
+
return {
|
|
169
|
+
content: [
|
|
170
|
+
{
|
|
171
|
+
type: "text",
|
|
172
|
+
text: formatDelegationResponse(response),
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
isError: false,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
// After session delegation check, response is AgentResponse
|
|
179
|
+
const agentResponse = response;
|
|
180
|
+
// Handle normal completion responses
|
|
128
181
|
logger.info("review_code completed", {
|
|
129
|
-
provider:
|
|
130
|
-
model:
|
|
182
|
+
provider: agentResponse.provider,
|
|
183
|
+
model: agentResponse.model,
|
|
131
184
|
durationMs,
|
|
132
|
-
traceId:
|
|
185
|
+
traceId: agentResponse.metadata.traceId,
|
|
133
186
|
});
|
|
134
187
|
return {
|
|
135
188
|
content: [
|
|
136
189
|
{
|
|
137
190
|
type: "text",
|
|
138
|
-
text: formatCodeReviewResponse(
|
|
191
|
+
text: formatCodeReviewResponse(agentResponse),
|
|
139
192
|
},
|
|
140
193
|
],
|
|
141
194
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"review-code.js","sourceRoot":"","sources":["../../../src/mcp/tools/review-code.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"review-code.js","sourceRoot":"","sources":["../../../src/mcp/tools/review-code.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,CAAC,EAAE,M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],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"execute-task.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/tasks/execute-task.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAyNrE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,YAAY,EACpB,WAAW,EAAE,eAAe,EAC5B,MAAM,EAAE,MAAM,EACd,eAAe,CAAC,EAAE,eAAe,GAChC,IAAI,CA8NN"}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
import { roleNeedsWorktree } from "../../../config/worktree-defaults.js";
|
|
10
|
+
import { isSessionDelegation } from "../../../types.js";
|
|
10
11
|
import { injectWorktreeContext } from "../../../worktrees/instructions.js";
|
|
11
12
|
// ============================================================================
|
|
12
13
|
// Constants
|
|
@@ -86,6 +87,53 @@ function formatTaskExecutionResponse(taskId, role, response, durationMs, autoCom
|
|
|
86
87
|
const agentResponse = `### Agent Response\n${content}`;
|
|
87
88
|
return header + meta + instructions + agentResponse;
|
|
88
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Format a session delegation response for MCP output.
|
|
92
|
+
*
|
|
93
|
+
* @param taskId - The Claude Code task ID
|
|
94
|
+
* @param role - The agent role used
|
|
95
|
+
* @param delegation - The session delegation response from the provider
|
|
96
|
+
* @param durationMs - Execution duration in milliseconds
|
|
97
|
+
* @param worktreeInfo - Optional worktree information if one was allocated
|
|
98
|
+
* @returns Formatted string with delegation instructions
|
|
99
|
+
*/
|
|
100
|
+
function formatDelegationResponse(taskId, role, delegation, durationMs, worktreeInfo) {
|
|
101
|
+
let header = `## Session Delegation
|
|
102
|
+
|
|
103
|
+
This request is being delegated to the current Claude session.
|
|
104
|
+
|
|
105
|
+
**Task ID:** ${taskId}
|
|
106
|
+
**Role**: ${role}
|
|
107
|
+
**Model Requested**: ${delegation.model || "default"}
|
|
108
|
+
**Duration:** ${String(durationMs)}ms
|
|
109
|
+
`;
|
|
110
|
+
// Add worktree info if allocated
|
|
111
|
+
if (worktreeInfo?.allocated) {
|
|
112
|
+
header +=
|
|
113
|
+
`\n### Worktree Allocated\n` +
|
|
114
|
+
`**Path:** \`${worktreeInfo.path}\`\n` +
|
|
115
|
+
`**Branch:** \`${worktreeInfo.branch}\`\n`;
|
|
116
|
+
}
|
|
117
|
+
return `${header}
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
### Instructions
|
|
121
|
+
|
|
122
|
+
${delegation.instructions}
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
### System Prompt to Apply
|
|
127
|
+
|
|
128
|
+
\`\`\`
|
|
129
|
+
${delegation.system_prompt}
|
|
130
|
+
\`\`\`
|
|
131
|
+
|
|
132
|
+
### Task to Execute
|
|
133
|
+
|
|
134
|
+
${delegation.task}
|
|
135
|
+
`.trim();
|
|
136
|
+
}
|
|
89
137
|
/**
|
|
90
138
|
* Formats an error response for task execution failure
|
|
91
139
|
*
|
|
@@ -222,22 +270,43 @@ export function registerExecuteTaskTool(server, router, coordinator, logger, wor
|
|
|
222
270
|
// Invoke the agent through the router
|
|
223
271
|
const response = await router.invokeAgent(invokeInput);
|
|
224
272
|
const durationMs = Date.now() - startTime;
|
|
273
|
+
// Handle session delegation responses
|
|
274
|
+
if (isSessionDelegation(response)) {
|
|
275
|
+
logger.info("execute_task delegated to session", {
|
|
276
|
+
taskId,
|
|
277
|
+
role,
|
|
278
|
+
model: response.model,
|
|
279
|
+
durationMs,
|
|
280
|
+
worktreeAllocated: !!allocatedWorktree,
|
|
281
|
+
});
|
|
282
|
+
return {
|
|
283
|
+
content: [
|
|
284
|
+
{
|
|
285
|
+
type: "text",
|
|
286
|
+
text: formatDelegationResponse(taskId, role, response, durationMs, worktreeInfo),
|
|
287
|
+
},
|
|
288
|
+
],
|
|
289
|
+
isError: false,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
// After session delegation check, response is AgentResponse
|
|
293
|
+
const agentResponse = response;
|
|
225
294
|
// Mark execution complete
|
|
226
|
-
coordinator.completeExecution(taskId,
|
|
295
|
+
coordinator.completeExecution(taskId, agentResponse);
|
|
227
296
|
logger.info("execute_task completed", {
|
|
228
297
|
taskId,
|
|
229
298
|
role,
|
|
230
|
-
provider:
|
|
231
|
-
model:
|
|
299
|
+
provider: agentResponse.provider,
|
|
300
|
+
model: agentResponse.model,
|
|
232
301
|
durationMs,
|
|
233
|
-
traceId:
|
|
302
|
+
traceId: agentResponse.metadata.traceId,
|
|
234
303
|
worktreeAllocated: !!allocatedWorktree,
|
|
235
304
|
});
|
|
236
305
|
return {
|
|
237
306
|
content: [
|
|
238
307
|
{
|
|
239
308
|
type: "text",
|
|
240
|
-
text: formatTaskExecutionResponse(taskId, role,
|
|
309
|
+
text: formatTaskExecutionResponse(taskId, role, agentResponse, durationMs, autoComplete, worktreeInfo),
|
|
241
310
|
},
|
|
242
311
|
],
|
|
243
312
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute-task.js","sourceRoot":"","sources":["../../../../src/mcp/tools/tasks/execute-task.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"execute-task.js","sourceRoot":"","sources":["../../../../src/mcp/tools/tasks/execute-task.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAKzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAE3E,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E;;GAEG;AACH,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,CAAU,CAAC;AAEvF;;GAEG;AACH,MAAM,gBAAgB,GACpB,qIAAqI;IACrI,kIAAkI;IAClI,uFAAuF,CAAC;AAE1F;;GAEG;AACH,MAAM,mBAAmB,GAAG,cAAc,CAAC;AAE3C,+EAA+E;AAC/E,eAAe;AACf,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,2BAA2B,GAAG;IAClC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,oCAAoC,CAAC;IACxE,IAAI,EAAE,CAAC;SACJ,IAAI,CAAC,WAAW,CAAC;SACjB,QAAQ,EAAE;SACV,QAAQ,CACP,6EAA6E,CAC9E;IACH,OAAO,EAAE,CAAC;SACP,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CAAC,2CAA2C,CAAC;IACxD,YAAY,EAAE,CAAC;SACZ,OAAO,EAAE;SACT,OAAO,CAAC,IAAI,CAAC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5
5
|
* Handles message formatting, streaming, and tool use for Claude models.
|
|
6
6
|
*
|
|
7
|
-
* Supports
|
|
7
|
+
* Supports three access modes:
|
|
8
8
|
* - 'api': Direct HTTP calls to Anthropic API (requires API key)
|
|
9
|
+
* - 'session': Delegates to the current Claude Code session (zero-cost, in-process)
|
|
9
10
|
* - 'subscription': Uses Claude Agent SDK (requires CLAUDE_CODE_OAUTH_TOKEN)
|
|
11
|
+
* - 'auto': Automatically selects the best available mode (session > api > subscription)
|
|
10
12
|
*/
|
|
11
13
|
import { BaseProvider } from './base.js';
|
|
12
|
-
import type { CompletionRequest, CompletionResponse, StreamChunk } from '../types.js';
|
|
14
|
+
import type { CompletionRequest, CompletionResponse, SessionDelegationResponse, StreamChunk } from '../types.js';
|
|
13
15
|
/**
|
|
14
16
|
* Anthropic Claude API provider adapter.
|
|
15
17
|
*
|
|
@@ -36,14 +38,41 @@ export declare class AnthropicProvider extends BaseProvider {
|
|
|
36
38
|
/**
|
|
37
39
|
* Execute a completion request and return the full response.
|
|
38
40
|
*
|
|
39
|
-
* Supports
|
|
41
|
+
* Supports three modes:
|
|
40
42
|
* - API mode (access_mode: 'api'): Direct HTTP calls to Anthropic API
|
|
43
|
+
* - Session mode (access_mode: 'session'): Delegates to current Claude Code session
|
|
41
44
|
* - Subscription mode (access_mode: 'subscription'): Uses Claude Agent SDK
|
|
45
|
+
* - Auto mode (access_mode: 'auto'): Selects best available (session > api > subscription)
|
|
42
46
|
*
|
|
43
47
|
* @param request - The completion request
|
|
44
|
-
* @returns Promise resolving to the normalized completion response
|
|
48
|
+
* @returns Promise resolving to the normalized completion response or session delegation
|
|
49
|
+
*/
|
|
50
|
+
complete(request: CompletionRequest): Promise<CompletionResponse | SessionDelegationResponse>;
|
|
51
|
+
/**
|
|
52
|
+
* Resolve the effective access mode based on config and environment.
|
|
53
|
+
*
|
|
54
|
+
* Priority for 'auto' mode:
|
|
55
|
+
* 1. session - if running inside Claude Code session
|
|
56
|
+
* 2. api - if API key is configured
|
|
57
|
+
* 3. subscription - if OAuth token is available
|
|
58
|
+
*
|
|
59
|
+
* @returns The resolved access mode to use
|
|
60
|
+
* @throws Error if no valid access mode is available
|
|
45
61
|
*/
|
|
46
|
-
|
|
62
|
+
private resolveAccessMode;
|
|
63
|
+
/**
|
|
64
|
+
* Return a session delegation response instead of making an API call.
|
|
65
|
+
* The current Claude session will handle the request directly.
|
|
66
|
+
*
|
|
67
|
+
* This is the most efficient mode when running inside Claude Code:
|
|
68
|
+
* - Zero additional API costs (uses current session's quota)
|
|
69
|
+
* - No subprocess spawning overhead
|
|
70
|
+
* - Direct integration with the calling Claude instance
|
|
71
|
+
*
|
|
72
|
+
* @param request - The completion request
|
|
73
|
+
* @returns SessionDelegationResponse for the caller to handle
|
|
74
|
+
*/
|
|
75
|
+
private completeViaSession;
|
|
47
76
|
/**
|
|
48
77
|
* Execute a completion using Claude Agent SDK (subscription mode).
|
|
49
78
|
* Uses CLAUDE_CODE_OAUTH_TOKEN for authentication.
|
|
@@ -71,7 +100,12 @@ export declare class AnthropicProvider extends BaseProvider {
|
|
|
71
100
|
/**
|
|
72
101
|
* Check if the Anthropic API is available and credentials are valid.
|
|
73
102
|
*
|
|
74
|
-
*
|
|
103
|
+
* For each access mode:
|
|
104
|
+
* - session: Checks if running in Claude Code context
|
|
105
|
+
* - subscription: Checks if OAuth token exists
|
|
106
|
+
* - api: Makes a minimal API request to verify credentials
|
|
107
|
+
*
|
|
108
|
+
* @throws Error if the health check fails
|
|
75
109
|
*/
|
|
76
110
|
healthCheck(): Promise<void>;
|
|
77
111
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAA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C,wBAAwB;IAiChC;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAiBtB;;;;;OAKG;YACY,cAAc;IAkD7B;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;IAkC5B;;;;;OAKG;IACH,OAAO,CAAC,+BAA+B;CAuBxC"}
|
|
@@ -4,13 +4,28 @@
|
|
|
4
4
|
* Provider adapter for the Anthropic Claude API.
|
|
5
5
|
* Handles message formatting, streaming, and tool use for Claude models.
|
|
6
6
|
*
|
|
7
|
-
* Supports
|
|
7
|
+
* Supports three access modes:
|
|
8
8
|
* - 'api': Direct HTTP calls to Anthropic API (requires API key)
|
|
9
|
+
* - 'session': Delegates to the current Claude Code session (zero-cost, in-process)
|
|
9
10
|
* - 'subscription': Uses Claude Agent SDK (requires CLAUDE_CODE_OAUTH_TOKEN)
|
|
11
|
+
* - 'auto': Automatically selects the best available mode (session > api > subscription)
|
|
10
12
|
*/
|
|
11
13
|
import { BaseProvider } from './base.js';
|
|
12
14
|
import { query } from '@anthropic-ai/claude-agent-sdk';
|
|
13
15
|
// ============================================================================
|
|
16
|
+
// Session Detection
|
|
17
|
+
// ============================================================================
|
|
18
|
+
/**
|
|
19
|
+
* Check if running inside a Claude Code session.
|
|
20
|
+
* When true, we can use session delegation instead of subprocess/API.
|
|
21
|
+
*
|
|
22
|
+
* @returns true if running in a Claude Code MCP context
|
|
23
|
+
*/
|
|
24
|
+
function isRunningInClaudeSession() {
|
|
25
|
+
return process.env.CLAUDE_CODE_ENTRY === 'mcp' ||
|
|
26
|
+
process.env.CLAUDE_CODE_SESSION === 'true';
|
|
27
|
+
}
|
|
28
|
+
// ============================================================================
|
|
14
29
|
// Anthropic Provider
|
|
15
30
|
// ============================================================================
|
|
16
31
|
/**
|
|
@@ -53,16 +68,21 @@ export class AnthropicProvider extends BaseProvider {
|
|
|
53
68
|
/**
|
|
54
69
|
* Execute a completion request and return the full response.
|
|
55
70
|
*
|
|
56
|
-
* Supports
|
|
71
|
+
* Supports three modes:
|
|
57
72
|
* - API mode (access_mode: 'api'): Direct HTTP calls to Anthropic API
|
|
73
|
+
* - Session mode (access_mode: 'session'): Delegates to current Claude Code session
|
|
58
74
|
* - Subscription mode (access_mode: 'subscription'): Uses Claude Agent SDK
|
|
75
|
+
* - Auto mode (access_mode: 'auto'): Selects best available (session > api > subscription)
|
|
59
76
|
*
|
|
60
77
|
* @param request - The completion request
|
|
61
|
-
* @returns Promise resolving to the normalized completion response
|
|
78
|
+
* @returns Promise resolving to the normalized completion response or session delegation
|
|
62
79
|
*/
|
|
63
80
|
async complete(request) {
|
|
64
|
-
|
|
65
|
-
if (
|
|
81
|
+
const accessMode = this.resolveAccessMode();
|
|
82
|
+
if (accessMode === 'session') {
|
|
83
|
+
return this.completeViaSession(request);
|
|
84
|
+
}
|
|
85
|
+
if (accessMode === 'subscription') {
|
|
66
86
|
return this.completeViaSubscription(request);
|
|
67
87
|
}
|
|
68
88
|
// Default: API mode with direct HTTP calls
|
|
@@ -77,6 +97,75 @@ export class AnthropicProvider extends BaseProvider {
|
|
|
77
97
|
});
|
|
78
98
|
return this.translateResponse(response);
|
|
79
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Resolve the effective access mode based on config and environment.
|
|
102
|
+
*
|
|
103
|
+
* Priority for 'auto' mode:
|
|
104
|
+
* 1. session - if running inside Claude Code session
|
|
105
|
+
* 2. api - if API key is configured
|
|
106
|
+
* 3. subscription - if OAuth token is available
|
|
107
|
+
*
|
|
108
|
+
* @returns The resolved access mode to use
|
|
109
|
+
* @throws Error if no valid access mode is available
|
|
110
|
+
*/
|
|
111
|
+
resolveAccessMode() {
|
|
112
|
+
const configMode = this.config.access_mode;
|
|
113
|
+
if (configMode === 'auto') {
|
|
114
|
+
// Priority: session > api > subscription
|
|
115
|
+
if (isRunningInClaudeSession()) {
|
|
116
|
+
return 'session';
|
|
117
|
+
}
|
|
118
|
+
if (this.config.api_key) {
|
|
119
|
+
return 'api';
|
|
120
|
+
}
|
|
121
|
+
if (process.env['CLAUDE_CODE_OAUTH_TOKEN']) {
|
|
122
|
+
return 'subscription';
|
|
123
|
+
}
|
|
124
|
+
throw new Error('No valid access mode available. Set ANTHROPIC_API_KEY or run inside Claude Code.');
|
|
125
|
+
}
|
|
126
|
+
// Handle explicit session mode
|
|
127
|
+
if (configMode === 'session') {
|
|
128
|
+
return 'session';
|
|
129
|
+
}
|
|
130
|
+
// Handle explicit subscription mode
|
|
131
|
+
if (configMode === 'subscription') {
|
|
132
|
+
return 'subscription';
|
|
133
|
+
}
|
|
134
|
+
// Default to API mode
|
|
135
|
+
return configMode || 'api';
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Return a session delegation response instead of making an API call.
|
|
139
|
+
* The current Claude session will handle the request directly.
|
|
140
|
+
*
|
|
141
|
+
* This is the most efficient mode when running inside Claude Code:
|
|
142
|
+
* - Zero additional API costs (uses current session's quota)
|
|
143
|
+
* - No subprocess spawning overhead
|
|
144
|
+
* - Direct integration with the calling Claude instance
|
|
145
|
+
*
|
|
146
|
+
* @param request - The completion request
|
|
147
|
+
* @returns SessionDelegationResponse for the caller to handle
|
|
148
|
+
*/
|
|
149
|
+
completeViaSession(request) {
|
|
150
|
+
// Extract the task from messages (last user message)
|
|
151
|
+
const lastUserMessage = [...request.messages].reverse().find(m => m.role === 'user');
|
|
152
|
+
const task = typeof lastUserMessage?.content === 'string'
|
|
153
|
+
? lastUserMessage.content
|
|
154
|
+
: lastUserMessage?.content?.map(b => b.type === 'text' ? b.text : '').join('') || '';
|
|
155
|
+
// Get system prompt from config (system messages are not part of Message type,
|
|
156
|
+
// they're passed through config.system_prompt by the role resolver)
|
|
157
|
+
const systemPrompt = this.config.system_prompt || '';
|
|
158
|
+
// Get role name from config
|
|
159
|
+
const role = this.config.role_name || 'assistant';
|
|
160
|
+
return {
|
|
161
|
+
delegation: true,
|
|
162
|
+
role,
|
|
163
|
+
system_prompt: systemPrompt,
|
|
164
|
+
task,
|
|
165
|
+
model: request.model,
|
|
166
|
+
instructions: `You are now acting as the '${role}' agent. Apply the following system prompt as your persona and execute the task.\n\n---\nSYSTEM PROMPT:\n${systemPrompt}\n---\n\nTASK:\n${task}`,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
80
169
|
/**
|
|
81
170
|
* Execute a completion using Claude Agent SDK (subscription mode).
|
|
82
171
|
* Uses CLAUDE_CODE_OAUTH_TOKEN for authentication.
|
|
@@ -175,12 +264,25 @@ export class AnthropicProvider extends BaseProvider {
|
|
|
175
264
|
/**
|
|
176
265
|
* Check if the Anthropic API is available and credentials are valid.
|
|
177
266
|
*
|
|
178
|
-
*
|
|
267
|
+
* For each access mode:
|
|
268
|
+
* - session: Checks if running in Claude Code context
|
|
269
|
+
* - subscription: Checks if OAuth token exists
|
|
270
|
+
* - api: Makes a minimal API request to verify credentials
|
|
271
|
+
*
|
|
272
|
+
* @throws Error if the health check fails
|
|
179
273
|
*/
|
|
180
274
|
async healthCheck() {
|
|
275
|
+
const accessMode = this.resolveAccessMode();
|
|
276
|
+
// For session mode, verify we're in a Claude Code context
|
|
277
|
+
if (accessMode === 'session') {
|
|
278
|
+
if (!isRunningInClaudeSession()) {
|
|
279
|
+
throw new Error('Session mode requires running inside a Claude Code session');
|
|
280
|
+
}
|
|
281
|
+
return; // In session context, assume healthy
|
|
282
|
+
}
|
|
181
283
|
// For subscription mode, we can't easily verify without spawning SDK
|
|
182
284
|
// Just check if the OAuth token exists
|
|
183
|
-
if (
|
|
285
|
+
if (accessMode === 'subscription') {
|
|
184
286
|
if (!process.env['CLAUDE_CODE_OAUTH_TOKEN']) {
|
|
185
287
|
throw new Error('Subscription mode requires CLAUDE_CODE_OAUTH_TOKEN environment variable');
|
|
186
288
|
}
|
|
@@ -193,7 +295,17 @@ export class AnthropicProvider extends BaseProvider {
|
|
|
193
295
|
max_tokens: 1,
|
|
194
296
|
};
|
|
195
297
|
// If this throws, the health check failed
|
|
196
|
-
|
|
298
|
+
// Note: This will recursively call complete(), but with api mode
|
|
299
|
+
// since we've already resolved the mode
|
|
300
|
+
const url = `${this.getBaseUrl(this.DEFAULT_BASE_URL)}/v1/messages`;
|
|
301
|
+
const anthropicRequest = this.translateRequest(request);
|
|
302
|
+
await this.makeRequest({
|
|
303
|
+
method: 'POST',
|
|
304
|
+
url,
|
|
305
|
+
headers: this.buildHeaders(),
|
|
306
|
+
body: anthropicRequest,
|
|
307
|
+
timeoutMs: request.timeout_ms ?? this.defaultTimeoutMs,
|
|
308
|
+
});
|
|
197
309
|
}
|
|
198
310
|
/**
|
|
199
311
|
* Translate our normalized request format to Anthropic's format.
|