@mcp-abap-adt/llm-agent 8.1.1 → 8.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/dist/agents/anthropic-agent.d.ts +5 -8
- package/dist/agents/anthropic-agent.d.ts.map +1 -1
- package/dist/agents/anthropic-agent.js +97 -73
- package/dist/agents/anthropic-agent.js.map +1 -1
- package/dist/agents/base.d.ts +0 -11
- package/dist/agents/base.d.ts.map +1 -1
- package/dist/agents/base.js +0 -246
- package/dist/agents/base.js.map +1 -1
- package/dist/agents/deepseek-agent.d.ts +4 -8
- package/dist/agents/deepseek-agent.d.ts.map +1 -1
- package/dist/agents/deepseek-agent.js +80 -52
- package/dist/agents/deepseek-agent.js.map +1 -1
- package/dist/agents/openai-agent.d.ts +0 -4
- package/dist/agents/openai-agent.d.ts.map +1 -1
- package/dist/agents/openai-agent.js +72 -51
- package/dist/agents/openai-agent.js.map +1 -1
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/llm-providers/anthropic.d.ts +3 -3
- package/dist/llm-providers/anthropic.d.ts.map +1 -1
- package/dist/llm-providers/anthropic.js +108 -10
- package/dist/llm-providers/anthropic.js.map +1 -1
- package/dist/llm-providers/base.d.ts +5 -5
- package/dist/llm-providers/base.d.ts.map +1 -1
- package/dist/llm-providers/base.js.map +1 -1
- package/dist/llm-providers/deepseek.d.ts +3 -3
- package/dist/llm-providers/deepseek.d.ts.map +1 -1
- package/dist/llm-providers/deepseek.js +18 -8
- package/dist/llm-providers/deepseek.js.map +1 -1
- package/dist/llm-providers/openai.d.ts +9 -3
- package/dist/llm-providers/openai.d.ts.map +1 -1
- package/dist/llm-providers/openai.js +30 -8
- package/dist/llm-providers/openai.js.map +1 -1
- package/dist/smart-agent/check-models-cli.js +14 -0
- package/dist/smart-agent/check-models-cli.js.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -20,17 +20,14 @@ export declare class AnthropicAgent extends BaseAgent {
|
|
|
20
20
|
content: string;
|
|
21
21
|
raw?: unknown;
|
|
22
22
|
}>;
|
|
23
|
-
/**
|
|
24
|
-
* Convert MCP tools to Anthropic tool format
|
|
25
|
-
*/
|
|
26
|
-
private convertToolsToAnthropicTools;
|
|
27
|
-
/**
|
|
28
|
-
* Format messages for Anthropic API
|
|
29
|
-
*/
|
|
30
|
-
private formatMessagesForAnthropic;
|
|
31
23
|
/**
|
|
32
24
|
* Stream Anthropic response via real SSE streaming.
|
|
25
|
+
* Delegates to provider.streamChat() and parses raw chunks for tool calls.
|
|
33
26
|
*/
|
|
34
27
|
protected streamLLMWithTools(messages: Message[], tools: unknown[], options?: AgentCallOptions): AsyncGenerator<AgentStreamChunk, void, unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* Convert MCP tools to Anthropic tool format
|
|
30
|
+
*/
|
|
31
|
+
private convertToolsToAnthropicTools;
|
|
35
32
|
}
|
|
36
33
|
//# sourceMappingURL=anthropic-agent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-agent.d.ts","sourceRoot":"","sources":["../../src/agents/anthropic-agent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EACL,KAAK,gBAAgB,EACrB,SAAS,EACT,KAAK,eAAe,EACrB,MAAM,WAAW,CAAC;AAEnB,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,WAAW,EAAE,iBAAiB,CAAC;CAChC;AAED,qBAAa,cAAe,SAAQ,SAAS;IAC3C,OAAO,CAAC,WAAW,CAAoB;gBAE3B,MAAM,EAAE,oBAAoB;IAKxC;;OAEG;cACa,gBAAgB,CAC9B,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,OAAO,EAAE,EAChB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"anthropic-agent.d.ts","sourceRoot":"","sources":["../../src/agents/anthropic-agent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EACL,KAAK,gBAAgB,EACrB,SAAS,EACT,KAAK,eAAe,EACrB,MAAM,WAAW,CAAC;AAEnB,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,WAAW,EAAE,iBAAiB,CAAC;CAChC;AAED,qBAAa,cAAe,SAAQ,SAAS;IAC3C,OAAO,CAAC,WAAW,CAAoB;gBAE3B,MAAM,EAAE,oBAAoB;IAKxC;;OAEG;cACa,gBAAgB,CAC9B,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,OAAO,EAAE,EAChB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAgB9C;;;OAGG;cACc,kBAAkB,CACjC,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,OAAO,EAAE,EAChB,OAAO,CAAC,EAAE,gBAAgB,GACzB,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,OAAO,CAAC;IAsGlD;;OAEG;IACH,OAAO,CAAC,4BAA4B;CAmBrC"}
|
|
@@ -15,38 +15,108 @@ export class AnthropicAgent extends BaseAgent {
|
|
|
15
15
|
* Call Anthropic with tools using tools API
|
|
16
16
|
*/
|
|
17
17
|
async callLLMWithTools(messages, tools, options) {
|
|
18
|
-
// Convert MCP tools to Anthropic tool format
|
|
19
18
|
const anthropicTools = this.convertToolsToAnthropicTools(tools);
|
|
20
|
-
//
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// Call Anthropic API with tools
|
|
26
|
-
const requestBody = {
|
|
27
|
-
model: options?.model ?? model,
|
|
28
|
-
messages: formattedMessages,
|
|
29
|
-
max_tokens: config.maxTokens || 4096,
|
|
30
|
-
temperature: config.temperature || 0.7,
|
|
19
|
+
// Pass all messages (including system) — provider handles system message separation
|
|
20
|
+
const response = await this.llmProvider.chat(messages, anthropicTools.length > 0 ? anthropicTools : undefined, options);
|
|
21
|
+
return {
|
|
22
|
+
content: response.content,
|
|
23
|
+
raw: response.raw,
|
|
31
24
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Stream Anthropic response via real SSE streaming.
|
|
28
|
+
* Delegates to provider.streamChat() and parses raw chunks for tool calls.
|
|
29
|
+
*/
|
|
30
|
+
async *streamLLMWithTools(messages, tools, options) {
|
|
31
|
+
const anthropicTools = this.convertToolsToAnthropicTools(tools);
|
|
32
|
+
const toolCallMap = new Map();
|
|
33
|
+
let finishReason = 'stop';
|
|
34
|
+
let blockIndex = 0;
|
|
35
|
+
for await (const chunk of this.llmProvider.streamChat(messages, anthropicTools.length > 0 ? anthropicTools : undefined, options)) {
|
|
36
|
+
// Yield text deltas
|
|
37
|
+
if (chunk.content) {
|
|
38
|
+
yield { type: 'text', delta: chunk.content };
|
|
39
|
+
}
|
|
40
|
+
if (chunk.raw && typeof chunk.raw === 'object') {
|
|
41
|
+
const raw = chunk.raw;
|
|
42
|
+
// content_block_start — detect tool_use blocks
|
|
43
|
+
if (raw.type === 'content_block_start' && raw.content_block) {
|
|
44
|
+
const block = raw.content_block;
|
|
45
|
+
if (block.type === 'tool_use') {
|
|
46
|
+
toolCallMap.set(blockIndex, {
|
|
47
|
+
id: block.id ?? '',
|
|
48
|
+
name: block.name ?? '',
|
|
49
|
+
arguments: '',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
blockIndex++;
|
|
53
|
+
}
|
|
54
|
+
// content_block_delta — accumulate tool input JSON
|
|
55
|
+
if (raw.type === 'content_block_delta' && raw.delta) {
|
|
56
|
+
const delta = raw.delta;
|
|
57
|
+
if (delta.type === 'input_json_delta' && delta.partial_json) {
|
|
58
|
+
const current = toolCallMap.get(blockIndex - 1);
|
|
59
|
+
if (current)
|
|
60
|
+
current.arguments += delta.partial_json;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// message_delta — finish reason
|
|
64
|
+
if (raw.type === 'message_delta' && raw.delta) {
|
|
65
|
+
const delta = raw.delta;
|
|
66
|
+
const reason = delta.stop_reason;
|
|
67
|
+
if (reason === 'tool_use')
|
|
68
|
+
finishReason = 'tool_calls';
|
|
69
|
+
else if (reason === 'max_tokens')
|
|
70
|
+
finishReason = 'length';
|
|
71
|
+
else if (reason === 'end_turn' || reason === 'stop_sequence')
|
|
72
|
+
finishReason = 'stop';
|
|
73
|
+
}
|
|
74
|
+
// message_start — usage
|
|
75
|
+
if (raw.type === 'message_start' && raw.message) {
|
|
76
|
+
const msg = raw.message;
|
|
77
|
+
const usage = msg.usage;
|
|
78
|
+
if (usage) {
|
|
79
|
+
yield {
|
|
80
|
+
type: 'usage',
|
|
81
|
+
promptTokens: usage.input_tokens ?? 0,
|
|
82
|
+
completionTokens: usage.output_tokens ?? 0,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Track finish reason from provider
|
|
88
|
+
if (chunk.finishReason) {
|
|
89
|
+
if (chunk.finishReason === 'tool_use')
|
|
90
|
+
finishReason = 'tool_calls';
|
|
91
|
+
else if (chunk.finishReason === 'max_tokens')
|
|
92
|
+
finishReason = 'length';
|
|
93
|
+
else
|
|
94
|
+
finishReason = 'stop';
|
|
95
|
+
}
|
|
37
96
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
97
|
+
// Emit accumulated tool calls
|
|
98
|
+
if (toolCallMap.size > 0) {
|
|
99
|
+
const toolCalls = [...toolCallMap.entries()]
|
|
100
|
+
.sort(([a], [b]) => a - b)
|
|
101
|
+
.filter(([, tc]) => tc.name)
|
|
102
|
+
.map(([, tc]) => ({
|
|
103
|
+
id: tc.id,
|
|
104
|
+
name: tc.name,
|
|
105
|
+
arguments: (() => {
|
|
106
|
+
try {
|
|
107
|
+
return JSON.parse(tc.arguments);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return {};
|
|
111
|
+
}
|
|
112
|
+
})(),
|
|
113
|
+
}));
|
|
114
|
+
if (toolCalls.length > 0) {
|
|
115
|
+
yield { type: 'tool_calls', toolCalls };
|
|
116
|
+
finishReason = 'tool_calls';
|
|
44
117
|
}
|
|
45
118
|
}
|
|
46
|
-
|
|
47
|
-
content: textContent,
|
|
48
|
-
raw: response.data,
|
|
49
|
-
};
|
|
119
|
+
yield { type: 'done', finishReason };
|
|
50
120
|
}
|
|
51
121
|
/**
|
|
52
122
|
* Convert MCP tools to Anthropic tool format
|
|
@@ -64,51 +134,5 @@ export class AnthropicAgent extends BaseAgent {
|
|
|
64
134
|
};
|
|
65
135
|
});
|
|
66
136
|
}
|
|
67
|
-
/**
|
|
68
|
-
* Format messages for Anthropic API
|
|
69
|
-
*/
|
|
70
|
-
formatMessagesForAnthropic(messages) {
|
|
71
|
-
return messages.map((msg) => {
|
|
72
|
-
return {
|
|
73
|
-
role: msg.role === 'assistant' ? 'assistant' : 'user',
|
|
74
|
-
content: msg.content,
|
|
75
|
-
};
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Stream Anthropic response via real SSE streaming.
|
|
80
|
-
*/
|
|
81
|
-
async *streamLLMWithTools(messages, tools, options) {
|
|
82
|
-
const anthropicTools = this.convertToolsToAnthropicTools(tools);
|
|
83
|
-
const systemMessage = messages.find((m) => m.role === 'system');
|
|
84
|
-
const conversationMessages = messages.filter((m) => m.role !== 'system');
|
|
85
|
-
const formattedMessages = this.formatMessagesForAnthropic(conversationMessages);
|
|
86
|
-
const { model, config } = this.llmProvider;
|
|
87
|
-
const baseURL = config.baseURL || 'https://api.anthropic.com/v1';
|
|
88
|
-
const headers = {
|
|
89
|
-
'x-api-key': config.apiKey ?? '',
|
|
90
|
-
'anthropic-version': '2023-06-01',
|
|
91
|
-
};
|
|
92
|
-
const requestBody = {
|
|
93
|
-
model: options?.model ?? model,
|
|
94
|
-
messages: formattedMessages,
|
|
95
|
-
max_tokens: options?.maxTokens ?? config.maxTokens ?? 4096,
|
|
96
|
-
temperature: options?.temperature ?? config.temperature ?? 0.7,
|
|
97
|
-
stream: true,
|
|
98
|
-
};
|
|
99
|
-
if (systemMessage) {
|
|
100
|
-
requestBody.system = systemMessage.content;
|
|
101
|
-
}
|
|
102
|
-
if (anthropicTools.length > 0) {
|
|
103
|
-
requestBody.tools = anthropicTools;
|
|
104
|
-
}
|
|
105
|
-
if (options?.topP !== undefined) {
|
|
106
|
-
requestBody.top_p = options.topP;
|
|
107
|
-
}
|
|
108
|
-
if (options?.stop) {
|
|
109
|
-
requestBody.stop_sequences = options.stop;
|
|
110
|
-
}
|
|
111
|
-
yield* this.streamAnthropicSSE(`${baseURL}/messages`, headers, requestBody);
|
|
112
|
-
}
|
|
113
137
|
}
|
|
114
138
|
//# sourceMappingURL=anthropic-agent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-agent.js","sourceRoot":"","sources":["../../src/agents/anthropic-agent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAEL,SAAS,GAEV,MAAM,WAAW,CAAC;AAMnB,MAAM,OAAO,cAAe,SAAQ,SAAS;IACnC,WAAW,CAAoB;IAEvC,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,IAAI,CAAC,WAAW,IAAI;oBAChC,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE,EAAE;iBACf;aACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/dist/agents/base.d.ts
CHANGED
|
@@ -78,17 +78,6 @@ export declare abstract class BaseAgent implements BaseAgentLlmBridge {
|
|
|
78
78
|
* Public typed bridge for streaming adapter layer.
|
|
79
79
|
*/
|
|
80
80
|
streamWithTools(messages: Message[], tools: unknown[], options?: AgentCallOptions): AsyncGenerator<AgentStreamChunk, void, unknown>;
|
|
81
|
-
/**
|
|
82
|
-
* Shared SSE parser for OpenAI-compatible streaming endpoints.
|
|
83
|
-
* Handles text deltas, tool call accumulation, usage chunks, and done.
|
|
84
|
-
*/
|
|
85
|
-
protected streamOpenAICompatible(url: string, headers: Record<string, string>, body: Record<string, unknown>): AsyncGenerator<AgentStreamChunk, void, unknown>;
|
|
86
|
-
/**
|
|
87
|
-
* SSE parser for Anthropic streaming endpoints.
|
|
88
|
-
* Handles named events (message_start, content_block_delta, etc.),
|
|
89
|
-
* text deltas, tool input accumulation, usage, and done.
|
|
90
|
-
*/
|
|
91
|
-
protected streamAnthropicSSE(url: string, headers: Record<string, string>, body: Record<string, unknown>): AsyncGenerator<AgentStreamChunk, void, unknown>;
|
|
92
81
|
/**
|
|
93
82
|
* Clear conversation history
|
|
94
83
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/agents/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,KAAK,eAAe,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE5E,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B;;OAEG;IACH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aAAa,CACjB,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,OAAO,EAAE,EAChB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAI9C;;OAEG;IACH,eAAe,CACb,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,OAAO,EAAE,EAChB,OAAO,CAAC,EAAE,gBAAgB,GACzB,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,OAAO,CAAC;IAIlD;;OAEG;IACH,YAAY,IAAI,IAAI;IAIpB;;OAEG;IACH,UAAU,IAAI,OAAO,EAAE;CAGxB"}
|
package/dist/agents/base.js
CHANGED
|
@@ -91,252 +91,6 @@ export class BaseAgent {
|
|
|
91
91
|
streamWithTools(messages, tools, options) {
|
|
92
92
|
return this.streamLLMWithTools(messages, tools, options);
|
|
93
93
|
}
|
|
94
|
-
/**
|
|
95
|
-
* Shared SSE parser for OpenAI-compatible streaming endpoints.
|
|
96
|
-
* Handles text deltas, tool call accumulation, usage chunks, and done.
|
|
97
|
-
*/
|
|
98
|
-
async *streamOpenAICompatible(url, headers, body) {
|
|
99
|
-
const res = await fetch(url, {
|
|
100
|
-
method: 'POST',
|
|
101
|
-
headers: { 'Content-Type': 'application/json', ...headers },
|
|
102
|
-
body: JSON.stringify(body),
|
|
103
|
-
});
|
|
104
|
-
if (!res.ok) {
|
|
105
|
-
const text = await res.text();
|
|
106
|
-
throw new Error(`LLM streaming error: HTTP ${res.status} - ${text}`);
|
|
107
|
-
}
|
|
108
|
-
if (!res.body) {
|
|
109
|
-
throw new Error('LLM streaming error: no response body');
|
|
110
|
-
}
|
|
111
|
-
const toolCallMap = new Map();
|
|
112
|
-
let finishReason = 'stop';
|
|
113
|
-
const reader = res.body.getReader();
|
|
114
|
-
const decoder = new TextDecoder();
|
|
115
|
-
let buffer = '';
|
|
116
|
-
try {
|
|
117
|
-
while (true) {
|
|
118
|
-
const { done, value } = await reader.read();
|
|
119
|
-
if (done)
|
|
120
|
-
break;
|
|
121
|
-
buffer += decoder.decode(value, { stream: true });
|
|
122
|
-
const lines = buffer.split('\n');
|
|
123
|
-
buffer = lines.pop() ?? '';
|
|
124
|
-
for (const line of lines) {
|
|
125
|
-
const trimmed = line.trim();
|
|
126
|
-
if (!trimmed.startsWith('data: '))
|
|
127
|
-
continue;
|
|
128
|
-
const data = trimmed.slice(6);
|
|
129
|
-
if (data === '[DONE]')
|
|
130
|
-
continue;
|
|
131
|
-
let chunk;
|
|
132
|
-
try {
|
|
133
|
-
chunk = JSON.parse(data);
|
|
134
|
-
}
|
|
135
|
-
catch {
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
// Extract usage from any chunk that carries it (OpenAI sends it
|
|
139
|
-
// in a separate empty-choices chunk, DeepSeek may include it
|
|
140
|
-
// alongside the last choice).
|
|
141
|
-
const chunkUsage = chunk.usage;
|
|
142
|
-
if (chunkUsage) {
|
|
143
|
-
yield {
|
|
144
|
-
type: 'usage',
|
|
145
|
-
promptTokens: chunkUsage.prompt_tokens ?? 0,
|
|
146
|
-
completionTokens: chunkUsage.completion_tokens ?? 0,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
if (Array.isArray(chunk.choices) && chunk.choices.length === 0) {
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
const choice = chunk.choices?.[0];
|
|
153
|
-
if (!choice)
|
|
154
|
-
continue;
|
|
155
|
-
const delta = choice.delta ?? {};
|
|
156
|
-
if (typeof delta.content === 'string' && delta.content.length > 0) {
|
|
157
|
-
yield { type: 'text', delta: delta.content };
|
|
158
|
-
}
|
|
159
|
-
if (Array.isArray(delta.tool_calls)) {
|
|
160
|
-
for (const tc of delta.tool_calls) {
|
|
161
|
-
const index = tc.index;
|
|
162
|
-
if (!toolCallMap.has(index)) {
|
|
163
|
-
toolCallMap.set(index, {
|
|
164
|
-
id: tc.id ?? '',
|
|
165
|
-
name: tc.function?.name ?? '',
|
|
166
|
-
arguments: '',
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
if (tc.function?.arguments) {
|
|
170
|
-
const accumulated = toolCallMap.get(index);
|
|
171
|
-
if (accumulated) {
|
|
172
|
-
accumulated.arguments += tc.function.arguments;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (choice.finish_reason) {
|
|
178
|
-
finishReason =
|
|
179
|
-
choice.finish_reason === 'tool_calls'
|
|
180
|
-
? 'tool_calls'
|
|
181
|
-
: choice.finish_reason === 'length'
|
|
182
|
-
? 'length'
|
|
183
|
-
: choice.finish_reason === 'error'
|
|
184
|
-
? 'error'
|
|
185
|
-
: 'stop';
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
finally {
|
|
191
|
-
reader.releaseLock();
|
|
192
|
-
}
|
|
193
|
-
if (toolCallMap.size > 0) {
|
|
194
|
-
const toolCalls = [...toolCallMap.entries()]
|
|
195
|
-
.sort(([a], [b]) => a - b)
|
|
196
|
-
.map(([, tc]) => ({
|
|
197
|
-
id: tc.id,
|
|
198
|
-
name: tc.name,
|
|
199
|
-
arguments: (() => {
|
|
200
|
-
try {
|
|
201
|
-
return JSON.parse(tc.arguments);
|
|
202
|
-
}
|
|
203
|
-
catch {
|
|
204
|
-
return {};
|
|
205
|
-
}
|
|
206
|
-
})(),
|
|
207
|
-
}));
|
|
208
|
-
yield { type: 'tool_calls', toolCalls };
|
|
209
|
-
}
|
|
210
|
-
yield { type: 'done', finishReason };
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* SSE parser for Anthropic streaming endpoints.
|
|
214
|
-
* Handles named events (message_start, content_block_delta, etc.),
|
|
215
|
-
* text deltas, tool input accumulation, usage, and done.
|
|
216
|
-
*/
|
|
217
|
-
async *streamAnthropicSSE(url, headers, body) {
|
|
218
|
-
const res = await fetch(url, {
|
|
219
|
-
method: 'POST',
|
|
220
|
-
headers: { 'Content-Type': 'application/json', ...headers },
|
|
221
|
-
body: JSON.stringify(body),
|
|
222
|
-
});
|
|
223
|
-
if (!res.ok) {
|
|
224
|
-
const text = await res.text();
|
|
225
|
-
throw new Error(`LLM streaming error: HTTP ${res.status} - ${text}`);
|
|
226
|
-
}
|
|
227
|
-
if (!res.body) {
|
|
228
|
-
throw new Error('LLM streaming error: no response body');
|
|
229
|
-
}
|
|
230
|
-
const toolCallMap = new Map();
|
|
231
|
-
let promptTokens = 0;
|
|
232
|
-
let completionTokens = 0;
|
|
233
|
-
let finishReason = 'stop';
|
|
234
|
-
let currentEvent = '';
|
|
235
|
-
const reader = res.body.getReader();
|
|
236
|
-
const decoder = new TextDecoder();
|
|
237
|
-
let buffer = '';
|
|
238
|
-
try {
|
|
239
|
-
while (true) {
|
|
240
|
-
const { done, value } = await reader.read();
|
|
241
|
-
if (done)
|
|
242
|
-
break;
|
|
243
|
-
buffer += decoder.decode(value, { stream: true });
|
|
244
|
-
const lines = buffer.split('\n');
|
|
245
|
-
buffer = lines.pop() ?? '';
|
|
246
|
-
for (const line of lines) {
|
|
247
|
-
const trimmed = line.trim();
|
|
248
|
-
if (trimmed.startsWith('event: ')) {
|
|
249
|
-
currentEvent = trimmed.slice(7);
|
|
250
|
-
continue;
|
|
251
|
-
}
|
|
252
|
-
if (!trimmed.startsWith('data: '))
|
|
253
|
-
continue;
|
|
254
|
-
const data = trimmed.slice(6);
|
|
255
|
-
let parsed;
|
|
256
|
-
try {
|
|
257
|
-
parsed = JSON.parse(data);
|
|
258
|
-
}
|
|
259
|
-
catch {
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
switch (currentEvent) {
|
|
263
|
-
case 'message_start': {
|
|
264
|
-
const message = parsed.message;
|
|
265
|
-
promptTokens = message?.usage?.input_tokens ?? 0;
|
|
266
|
-
break;
|
|
267
|
-
}
|
|
268
|
-
case 'content_block_start': {
|
|
269
|
-
const contentBlock = parsed.content_block;
|
|
270
|
-
if (contentBlock?.type === 'tool_use') {
|
|
271
|
-
const index = parsed.index ?? 0;
|
|
272
|
-
toolCallMap.set(index, {
|
|
273
|
-
id: contentBlock.id ?? '',
|
|
274
|
-
name: contentBlock.name ?? '',
|
|
275
|
-
argumentsJson: '',
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
break;
|
|
279
|
-
}
|
|
280
|
-
case 'content_block_delta': {
|
|
281
|
-
const delta = parsed.delta;
|
|
282
|
-
if (delta?.type === 'text_delta' && delta.text) {
|
|
283
|
-
yield { type: 'text', delta: delta.text };
|
|
284
|
-
}
|
|
285
|
-
else if (delta?.type === 'input_json_delta') {
|
|
286
|
-
const index = parsed.index ?? 0;
|
|
287
|
-
const accumulated = toolCallMap.get(index);
|
|
288
|
-
if (accumulated && delta.partial_json) {
|
|
289
|
-
accumulated.argumentsJson += delta.partial_json;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
break;
|
|
293
|
-
}
|
|
294
|
-
case 'message_delta': {
|
|
295
|
-
const delta = parsed.delta;
|
|
296
|
-
const usage = parsed.usage;
|
|
297
|
-
completionTokens = usage?.output_tokens ?? 0;
|
|
298
|
-
if (delta?.stop_reason) {
|
|
299
|
-
finishReason =
|
|
300
|
-
delta.stop_reason === 'tool_use'
|
|
301
|
-
? 'tool_calls'
|
|
302
|
-
: delta.stop_reason === 'max_tokens'
|
|
303
|
-
? 'length'
|
|
304
|
-
: 'stop';
|
|
305
|
-
}
|
|
306
|
-
break;
|
|
307
|
-
}
|
|
308
|
-
case 'error': {
|
|
309
|
-
const error = parsed.error;
|
|
310
|
-
throw new Error(`Anthropic stream error: ${error?.message ?? 'unknown'}`);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
currentEvent = '';
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
finally {
|
|
318
|
-
reader.releaseLock();
|
|
319
|
-
}
|
|
320
|
-
yield { type: 'usage', promptTokens, completionTokens };
|
|
321
|
-
if (toolCallMap.size > 0) {
|
|
322
|
-
const toolCalls = [...toolCallMap.entries()]
|
|
323
|
-
.sort(([a], [b]) => a - b)
|
|
324
|
-
.map(([, tc]) => ({
|
|
325
|
-
id: tc.id,
|
|
326
|
-
name: tc.name,
|
|
327
|
-
arguments: (() => {
|
|
328
|
-
try {
|
|
329
|
-
return JSON.parse(tc.argumentsJson);
|
|
330
|
-
}
|
|
331
|
-
catch {
|
|
332
|
-
return {};
|
|
333
|
-
}
|
|
334
|
-
})(),
|
|
335
|
-
}));
|
|
336
|
-
yield { type: 'tool_calls', toolCalls };
|
|
337
|
-
}
|
|
338
|
-
yield { type: 'done', finishReason };
|
|
339
|
-
}
|
|
340
94
|
/**
|
|
341
95
|
* Clear conversation history
|
|
342
96
|
*/
|
package/dist/agents/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/agents/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAwB,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAoC1E;;GAEG;AACH,MAAM,OAAgB,SAAS;IACnB,SAAS,CAAmB;IAC5B,mBAAmB,GAAc,EAAE,CAAC;IACpC,KAAK,GAAc,EAAE,CAAC;IAEhC,YAAY,MAAuB;QACjC,wBAAwB;QACxB,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YACrB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QACpC,CAAC;aAAM,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YAC5B,IAAI,CAAC,SAAS,GAAG,IAAI,gBAAgB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC1D,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,C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,CAAC;IAC3D,CAAC;IAED;;OAEG;IACH,YAAY;QACV,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,CAAC,GAAG,IAAI,CAAC,mBAAmB,CAAC,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -19,17 +19,13 @@ export declare class DeepSeekAgent extends BaseAgent {
|
|
|
19
19
|
content: string;
|
|
20
20
|
raw?: unknown;
|
|
21
21
|
}>;
|
|
22
|
-
/**
|
|
23
|
-
* Convert MCP tools to DeepSeek function format
|
|
24
|
-
*/
|
|
25
|
-
private convertToolsToFunctions;
|
|
26
|
-
/**
|
|
27
|
-
* Format messages for DeepSeek API (same as OpenAI)
|
|
28
|
-
*/
|
|
29
|
-
private formatMessagesForDeepSeek;
|
|
30
22
|
/**
|
|
31
23
|
* Stream DeepSeek response
|
|
32
24
|
*/
|
|
33
25
|
protected streamLLMWithTools(messages: Message[], tools: unknown[], options?: AgentCallOptions): AsyncGenerator<AgentStreamChunk, void, unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* Convert MCP tools to DeepSeek function format
|
|
28
|
+
*/
|
|
29
|
+
private convertToolsToFunctions;
|
|
34
30
|
}
|
|
35
31
|
//# sourceMappingURL=deepseek-agent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deepseek-agent.d.ts","sourceRoot":"","sources":["../../src/agents/deepseek-agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EACL,KAAK,gBAAgB,EACrB,SAAS,EACT,KAAK,eAAe,EACrB,MAAM,WAAW,CAAC;AAEnB,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D,WAAW,EAAE,gBAAgB,CAAC;CAC/B;AAED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