@agentionai/agents 0.14.0 → 1.0.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 +22 -0
- package/dist/agents/AgentConfig.d.ts +10 -0
- package/dist/agents/AgentEvent.d.ts +2 -0
- package/dist/agents/AgentEvent.js +2 -0
- package/dist/agents/anthropic/ClaudeAgent.d.ts +54 -0
- package/dist/agents/anthropic/ClaudeAgent.js +235 -27
- package/dist/agents/google/GeminiAgent.js +2 -1
- package/dist/agents/openai/OpenAiAgent.d.ts +15 -0
- package/dist/agents/openai/OpenAiAgent.js +150 -0
- package/dist/agents/openai-compatible/OpenAICompatibleAgent.d.ts +27 -0
- package/dist/agents/openai-compatible/OpenAICompatibleAgent.js +191 -0
- package/dist/history/History.d.ts +2 -2
- package/dist/history/History.js +3 -1
- package/dist/history/index.d.ts +2 -2
- package/dist/history/index.js +3 -1
- package/dist/history/transformers.js +20 -1
- package/dist/history/types.d.ts +20 -1
- package/dist/history/types.js +11 -0
- package/dist/index.d.ts +1 -1
- package/dist/ingestion/IngestionPipeline.js +1 -1
- package/dist/llamacpp.d.ts +1 -1
- package/dist/team/Team.js +1 -10
- package/dist/vectorstore/LanceDBVectorStore.js +0 -1
- package/package.json +4 -7
package/README.md
CHANGED
|
@@ -75,6 +75,7 @@ import { ClaudeAgent, OpenAiAgent } from '@agentionai/agents';
|
|
|
75
75
|
## Features
|
|
76
76
|
|
|
77
77
|
- **Multi-Provider, No Lock-in** - Claude, OpenAI, Gemini, Mistral, plus local models via Ollama and llama.cpp—same interface. Switch models with one line.
|
|
78
|
+
- **Streaming** - `executeStream()` on Claude, OpenAI, and all OpenAI-compatible agents. Yields `{ type: "text" | "reasoning" }` chunks; tool calls handled transparently.
|
|
78
79
|
- **Built-In Tools** - Use provider-defined server-side tools (e.g. Anthropic's web search, bash, text editor) alongside your own.
|
|
79
80
|
- **Composable, Not Magical** - Agents are objects. Pipelines are arrays. No hidden state, no surprises.
|
|
80
81
|
- **Multimodal / Vision** - Send images alongside text with a unified `MessageContent[]` API across all providers.
|
|
@@ -186,6 +187,27 @@ const agent = new ClaudeAgent({
|
|
|
186
187
|
const response = await agent.execute('What happened in the news today?');
|
|
187
188
|
```
|
|
188
189
|
|
|
190
|
+
### Streaming
|
|
191
|
+
|
|
192
|
+
All three major providers support streaming via `executeStream()`, which returns an `AsyncGenerator<StreamChunk>`. Each chunk is `{ type: "text" | "reasoning"; content: string }` — text for visible output, reasoning for internal thinking tokens (DeepSeek R1, Claude extended thinking, OpenAI o-series).
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
import { ClaudeAgent } from '@agentionai/agents/claude';
|
|
196
|
+
|
|
197
|
+
const agent = new ClaudeAgent({
|
|
198
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
199
|
+
id: 'assistant',
|
|
200
|
+
name: 'Assistant',
|
|
201
|
+
description: 'You are a helpful assistant.',
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
for await (const chunk of agent.executeStream('Tell me a story')) {
|
|
205
|
+
if (chunk.type === 'text') process.stdout.write(chunk.content);
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Tool calls are handled transparently — the generator continues streaming after each round-trip. The same API works across `ClaudeAgent`, `OpenAiAgent`, and `LlamaCppAgent` / any `OpenAICompatibleAgent` subclass.
|
|
210
|
+
|
|
189
211
|
### Multi-Agent Pipeline
|
|
190
212
|
|
|
191
213
|
Chain agents together with different providers and models:
|
|
@@ -73,6 +73,16 @@ export interface ClaudeSpecificConfig {
|
|
|
73
73
|
* implementation detail that can change.
|
|
74
74
|
*/
|
|
75
75
|
authType?: "apiKey" | "oauth";
|
|
76
|
+
/**
|
|
77
|
+
* Enable extended thinking by setting a thinking token budget. When set (> 0), the
|
|
78
|
+
* agent requests `thinking: { type: "enabled", budget_tokens }` and surfaces thinking
|
|
79
|
+
* tokens as `"reasoning"` chunks from `executeStream()`.
|
|
80
|
+
*
|
|
81
|
+
* Constraints (enforced by Anthropic): `budget_tokens` must be ≥ 1024 and strictly less
|
|
82
|
+
* than `maxTokens`. When enabled, `temperature`/`topP`/`topK` are not sent (the API
|
|
83
|
+
* requires default sampling with thinking).
|
|
84
|
+
*/
|
|
85
|
+
thinkingBudgetTokens?: number;
|
|
76
86
|
}
|
|
77
87
|
/**
|
|
78
88
|
* Vendor-specific configuration for OpenAI
|
|
@@ -10,6 +10,8 @@ export declare class AgentEvent {
|
|
|
10
10
|
static MAX_RETRIES_EXCEEDED: string;
|
|
11
11
|
static MAX_TOKENS_EXCEEDED: string;
|
|
12
12
|
static TOOL_ERROR: string;
|
|
13
|
+
static CHUNK: string;
|
|
14
|
+
static REASONING_CHUNK: string;
|
|
13
15
|
private defaultPrevented;
|
|
14
16
|
constructor(target: BaseAgent<any>);
|
|
15
17
|
preventDefault(): void;
|
|
@@ -23,4 +23,6 @@ AgentEvent.RETRY = "retry";
|
|
|
23
23
|
AgentEvent.MAX_RETRIES_EXCEEDED = "max_retries_exceeded";
|
|
24
24
|
AgentEvent.MAX_TOKENS_EXCEEDED = "max_tokens_exceeded";
|
|
25
25
|
AgentEvent.TOOL_ERROR = "tool_error";
|
|
26
|
+
AgentEvent.CHUNK = "chunk";
|
|
27
|
+
AgentEvent.REASONING_CHUNK = "reasoning_chunk";
|
|
26
28
|
//# sourceMappingURL=AgentEvent.js.map
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { Anthropic } from "@anthropic-ai/sdk";
|
|
1
2
|
import { Message, ToolUnion, Usage } from "@anthropic-ai/sdk/resources";
|
|
2
3
|
import { type ToolDefinition } from "../../tools/Tool";
|
|
3
4
|
import { type BuiltInTool } from "../../tools/BuiltInTool";
|
|
4
5
|
import { BaseAgent, BaseAgentConfig, TokenUsage } from "../BaseAgent";
|
|
5
6
|
import { History, MessageContent } from "../../history/History";
|
|
7
|
+
import { StreamChunk } from "../openai-compatible/OpenAICompatibleAgent";
|
|
6
8
|
import { ClaudeModel } from "../model-types";
|
|
7
9
|
type AgentConfig = BaseAgentConfig & {
|
|
8
10
|
apiKey: string;
|
|
@@ -22,6 +24,12 @@ type AgentConfig = BaseAgentConfig & {
|
|
|
22
24
|
* @see lib/tools/BuiltInTool.ts
|
|
23
25
|
*/
|
|
24
26
|
builtInTools?: BuiltInTool[];
|
|
27
|
+
/**
|
|
28
|
+
* Enable extended thinking with this token budget (≥ 1024, and strictly less than
|
|
29
|
+
* `maxTokens`). When set, thinking tokens are streamed as `"reasoning"` chunks and
|
|
30
|
+
* `temperature`/`topP`/`topK` are omitted (required by the API when thinking is on).
|
|
31
|
+
*/
|
|
32
|
+
thinkingBudgetTokens?: number;
|
|
25
33
|
};
|
|
26
34
|
/**
|
|
27
35
|
* Agent for Anthropic models.
|
|
@@ -54,10 +62,56 @@ export declare class ClaudeAgent extends BaseAgent {
|
|
|
54
62
|
* (server-side) built-in tools, in the shape Anthropic's API expects.
|
|
55
63
|
*/
|
|
56
64
|
protected getAllToolDefinitions(): ToolUnion[];
|
|
65
|
+
/**
|
|
66
|
+
* Build the common `messages.create` params (shared by `execute()` and
|
|
67
|
+
* `executeStream()`), excluding `stream`. When extended thinking is enabled
|
|
68
|
+
* (`thinkingBudgetTokens > 0`) the API requires default sampling, so
|
|
69
|
+
* `temperature`/`top_p`/`top_k` are omitted in favour of the `thinking` block.
|
|
70
|
+
*/
|
|
71
|
+
protected buildMessageParams(): {
|
|
72
|
+
thinking: {
|
|
73
|
+
type: "enabled";
|
|
74
|
+
budget_tokens: number;
|
|
75
|
+
};
|
|
76
|
+
model: string & ClaudeModel;
|
|
77
|
+
system: string | undefined;
|
|
78
|
+
max_tokens: number;
|
|
79
|
+
messages: Anthropic.Messages.MessageParam[];
|
|
80
|
+
tools: Anthropic.Messages.ToolUnion[];
|
|
81
|
+
stop_sequences: string[] | undefined;
|
|
82
|
+
metadata: Record<string, string> | undefined;
|
|
83
|
+
} | {
|
|
84
|
+
temperature: number | undefined;
|
|
85
|
+
top_p: number | undefined;
|
|
86
|
+
top_k: number | undefined;
|
|
87
|
+
model: string & ClaudeModel;
|
|
88
|
+
system: string | undefined;
|
|
89
|
+
max_tokens: number;
|
|
90
|
+
messages: Anthropic.Messages.MessageParam[];
|
|
91
|
+
tools: Anthropic.Messages.ToolUnion[];
|
|
92
|
+
stop_sequences: string[] | undefined;
|
|
93
|
+
metadata: Record<string, string> | undefined;
|
|
94
|
+
};
|
|
57
95
|
protected process(_input: string): Promise<string>;
|
|
58
96
|
execute(input: string | MessageContent[]): Promise<string>;
|
|
59
97
|
protected handleResponse(response: Message): Promise<string>;
|
|
60
98
|
private handleToolUse;
|
|
99
|
+
/**
|
|
100
|
+
* Stream a response as an async generator of `StreamChunk` objects.
|
|
101
|
+
* Yields `{ type: "text" }` for visible output and `{ type: "reasoning" }` for
|
|
102
|
+
* extended thinking tokens (models with thinking enabled). Tool calls are handled
|
|
103
|
+
* transparently — the generator continues streaming after each round-trip.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* for await (const chunk of agent.executeStream("Explain recursion")) {
|
|
108
|
+
* if (chunk.type === "text") process.stdout.write(chunk.content);
|
|
109
|
+
* else process.stderr.write(`[thinking] ${chunk.content}`);
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
executeStream(input: string | MessageContent[]): AsyncGenerator<StreamChunk>;
|
|
114
|
+
private streamTurn;
|
|
61
115
|
protected parseUsage(input: Usage): TokenUsage;
|
|
62
116
|
}
|
|
63
117
|
export {};
|
|
@@ -38,6 +38,7 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
38
38
|
const metadata = config.metadata ?? vendorConfig.metadata;
|
|
39
39
|
const builtInTools = config.builtInTools ?? vendorConfig.builtInTools;
|
|
40
40
|
const authType = config.authType ?? vendorConfig.authType ?? "apiKey";
|
|
41
|
+
const thinkingBudgetTokens = config.thinkingBudgetTokens ?? vendorConfig.thinkingBudgetTokens;
|
|
41
42
|
this.client = new sdk_1.Anthropic(authType === "oauth"
|
|
42
43
|
? { authToken: config.apiKey }
|
|
43
44
|
: { apiKey: config.apiKey });
|
|
@@ -48,6 +49,7 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
48
49
|
metadata,
|
|
49
50
|
builtInTools,
|
|
50
51
|
authType,
|
|
52
|
+
thinkingBudgetTokens,
|
|
51
53
|
apiKey: config.apiKey,
|
|
52
54
|
temperature: config.temperature,
|
|
53
55
|
topP: config.topP,
|
|
@@ -70,6 +72,37 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
70
72
|
...(this.config.builtInTools ?? []),
|
|
71
73
|
];
|
|
72
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Build the common `messages.create` params (shared by `execute()` and
|
|
77
|
+
* `executeStream()`), excluding `stream`. When extended thinking is enabled
|
|
78
|
+
* (`thinkingBudgetTokens > 0`) the API requires default sampling, so
|
|
79
|
+
* `temperature`/`top_p`/`top_k` are omitted in favour of the `thinking` block.
|
|
80
|
+
*/
|
|
81
|
+
buildMessageParams() {
|
|
82
|
+
const messages = transformers_1.anthropicTransformer.toProvider(this.history.getEntries());
|
|
83
|
+
const thinkingEnabled = (this.config.thinkingBudgetTokens ?? 0) > 0;
|
|
84
|
+
return {
|
|
85
|
+
model: this.config.model,
|
|
86
|
+
system: this.history.getSystemMessage(),
|
|
87
|
+
max_tokens: this.config.maxTokens,
|
|
88
|
+
messages,
|
|
89
|
+
tools: this.getAllToolDefinitions(),
|
|
90
|
+
stop_sequences: this.config.stopSequences,
|
|
91
|
+
metadata: this.config.metadata,
|
|
92
|
+
...(thinkingEnabled
|
|
93
|
+
? {
|
|
94
|
+
thinking: {
|
|
95
|
+
type: "enabled",
|
|
96
|
+
budget_tokens: this.config.thinkingBudgetTokens,
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
: {
|
|
100
|
+
temperature: this.config.temperature,
|
|
101
|
+
top_p: this.config.topP,
|
|
102
|
+
top_k: this.config.topK,
|
|
103
|
+
}),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
73
106
|
async process(_input) {
|
|
74
107
|
return "";
|
|
75
108
|
}
|
|
@@ -102,20 +135,7 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
102
135
|
// mid-loop. endExecution() in the finally block enforces limits once.
|
|
103
136
|
this.history.beginExecution();
|
|
104
137
|
try {
|
|
105
|
-
const
|
|
106
|
-
const systemMessage = this.history.getSystemMessage();
|
|
107
|
-
const response = await this.client.messages.create({
|
|
108
|
-
model: this.config.model,
|
|
109
|
-
system: systemMessage,
|
|
110
|
-
max_tokens: this.config.maxTokens,
|
|
111
|
-
messages,
|
|
112
|
-
tools: this.getAllToolDefinitions(),
|
|
113
|
-
temperature: this.config.temperature,
|
|
114
|
-
top_p: this.config.topP,
|
|
115
|
-
top_k: this.config.topK,
|
|
116
|
-
stop_sequences: this.config.stopSequences,
|
|
117
|
-
metadata: this.config.metadata,
|
|
118
|
-
});
|
|
138
|
+
const response = (await this.client.messages.create(this.buildMessageParams()));
|
|
119
139
|
this.emit(AgentEvent_1.AgentEvent.AFTER_EXECUTE, response);
|
|
120
140
|
return await this.handleResponse(response);
|
|
121
141
|
}
|
|
@@ -212,19 +232,7 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
212
232
|
this.addMessageToHistory("user", toolResults);
|
|
213
233
|
// Continue conversation with tool results
|
|
214
234
|
try {
|
|
215
|
-
const
|
|
216
|
-
const newResponse = await this.client.messages.create({
|
|
217
|
-
model: this.config.model,
|
|
218
|
-
system: this.history.getSystemMessage(),
|
|
219
|
-
max_tokens: this.config.maxTokens,
|
|
220
|
-
messages,
|
|
221
|
-
tools: this.getAllToolDefinitions(),
|
|
222
|
-
temperature: this.config.temperature,
|
|
223
|
-
top_p: this.config.topP,
|
|
224
|
-
top_k: this.config.topK,
|
|
225
|
-
stop_sequences: this.config.stopSequences,
|
|
226
|
-
metadata: this.config.metadata,
|
|
227
|
-
});
|
|
235
|
+
const newResponse = (await this.client.messages.create(this.buildMessageParams()));
|
|
228
236
|
this.emit(AgentEvent_1.AgentEvent.AFTER_EXECUTE, newResponse);
|
|
229
237
|
return this.handleResponse(newResponse);
|
|
230
238
|
}
|
|
@@ -305,6 +313,206 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
305
313
|
}));
|
|
306
314
|
return results;
|
|
307
315
|
}
|
|
316
|
+
/**
|
|
317
|
+
* Stream a response as an async generator of `StreamChunk` objects.
|
|
318
|
+
* Yields `{ type: "text" }` for visible output and `{ type: "reasoning" }` for
|
|
319
|
+
* extended thinking tokens (models with thinking enabled). Tool calls are handled
|
|
320
|
+
* transparently — the generator continues streaming after each round-trip.
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```typescript
|
|
324
|
+
* for await (const chunk of agent.executeStream("Explain recursion")) {
|
|
325
|
+
* if (chunk.type === "text") process.stdout.write(chunk.content);
|
|
326
|
+
* else process.stderr.write(`[thinking] ${chunk.content}`);
|
|
327
|
+
* }
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
async *executeStream(input) {
|
|
331
|
+
this.emit(AgentEvent_1.AgentEvent.BEFORE_EXECUTE, input);
|
|
332
|
+
this.lastTokenUsage = undefined;
|
|
333
|
+
this.currentToolCallCount = 0;
|
|
334
|
+
const inputPreview = typeof input === "string" ? input : JSON.stringify(input);
|
|
335
|
+
if (VizConfig_1.vizConfig.isEnabled()) {
|
|
336
|
+
this.vizEventId = VizReporter_1.vizReporter.agentStart(this.id, this.name, this.config.model, "anthropic", inputPreview);
|
|
337
|
+
}
|
|
338
|
+
if (this.history.transient) {
|
|
339
|
+
this.history.clear();
|
|
340
|
+
this.addSystemMessage(this.getSystemMessage());
|
|
341
|
+
}
|
|
342
|
+
if (typeof input === "string") {
|
|
343
|
+
this.addTextToHistory("user", input);
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
this.addMessageToHistory("user", input);
|
|
347
|
+
}
|
|
348
|
+
this.history.setSessionAnchor();
|
|
349
|
+
this.history.beginExecution();
|
|
350
|
+
try {
|
|
351
|
+
yield* this.streamTurn();
|
|
352
|
+
}
|
|
353
|
+
catch (error) {
|
|
354
|
+
if (error instanceof sdk_1.APIError) {
|
|
355
|
+
const apiError = new AgentError_1.ApiError(`Anthropic API error: ${error.message}`, error.status, error);
|
|
356
|
+
this.emit(AgentEvent_1.AgentEvent.ERROR, apiError);
|
|
357
|
+
if (this.vizEventId) {
|
|
358
|
+
VizReporter_1.vizReporter.agentError(this.vizEventId, "ApiError", apiError.message, error.status === 429);
|
|
359
|
+
this.vizEventId = undefined;
|
|
360
|
+
}
|
|
361
|
+
throw apiError;
|
|
362
|
+
}
|
|
363
|
+
// Errors raised inside streamTurn() (e.g. MaxTokensExceededError) are
|
|
364
|
+
// already emitted and viz-reported at the throw site — preserve their
|
|
365
|
+
// type rather than re-wrapping them in a generic ExecutionError.
|
|
366
|
+
if (error instanceof AgentError_1.AgentError) {
|
|
367
|
+
throw error;
|
|
368
|
+
}
|
|
369
|
+
const executionError = new AgentError_1.ExecutionError(`Anthropic error: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
370
|
+
this.emit(AgentEvent_1.AgentEvent.ERROR, executionError);
|
|
371
|
+
if (this.vizEventId) {
|
|
372
|
+
VizReporter_1.vizReporter.agentError(this.vizEventId, "ExecutionError", executionError.message, false);
|
|
373
|
+
this.vizEventId = undefined;
|
|
374
|
+
}
|
|
375
|
+
throw executionError;
|
|
376
|
+
}
|
|
377
|
+
finally {
|
|
378
|
+
this.history.endExecution();
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
async *streamTurn() {
|
|
382
|
+
const stream = await this.client.messages.create({
|
|
383
|
+
...this.buildMessageParams(),
|
|
384
|
+
stream: true,
|
|
385
|
+
});
|
|
386
|
+
const blocks = new Map();
|
|
387
|
+
let textContent = "";
|
|
388
|
+
let stopReason = null;
|
|
389
|
+
let inputTokens = 0;
|
|
390
|
+
let outputTokens = 0;
|
|
391
|
+
for await (const event of stream) {
|
|
392
|
+
if (event.type === "message_start") {
|
|
393
|
+
const e = event;
|
|
394
|
+
inputTokens = e.message.usage.input_tokens;
|
|
395
|
+
outputTokens = e.message.usage.output_tokens;
|
|
396
|
+
}
|
|
397
|
+
if (event.type === "message_delta") {
|
|
398
|
+
const e = event;
|
|
399
|
+
stopReason = e.delta.stop_reason ?? stopReason;
|
|
400
|
+
outputTokens += e.usage?.output_tokens ?? 0;
|
|
401
|
+
}
|
|
402
|
+
if (event.type === "content_block_start") {
|
|
403
|
+
const e = event;
|
|
404
|
+
const block = e.content_block;
|
|
405
|
+
if (block.type === "tool_use") {
|
|
406
|
+
blocks.set(e.index, { kind: "tool_use", id: block.id, name: block.name, inputJson: "" });
|
|
407
|
+
}
|
|
408
|
+
else if (block.type === "text") {
|
|
409
|
+
blocks.set(e.index, { kind: "text", text: "" });
|
|
410
|
+
}
|
|
411
|
+
else if (block.type === "thinking") {
|
|
412
|
+
blocks.set(e.index, { kind: "thinking", thinking: "", signature: "" });
|
|
413
|
+
}
|
|
414
|
+
else if (block.type === "redacted_thinking") {
|
|
415
|
+
blocks.set(e.index, { kind: "redacted_thinking", data: block.data });
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
if (event.type === "content_block_delta") {
|
|
419
|
+
const e = event;
|
|
420
|
+
const delta = e.delta;
|
|
421
|
+
const acc = blocks.get(e.index);
|
|
422
|
+
if (delta.type === "text_delta") {
|
|
423
|
+
textContent += delta.text;
|
|
424
|
+
if (acc?.kind === "text")
|
|
425
|
+
acc.text += delta.text;
|
|
426
|
+
this.emit(AgentEvent_1.AgentEvent.CHUNK, delta.text);
|
|
427
|
+
yield { type: "text", content: delta.text };
|
|
428
|
+
}
|
|
429
|
+
else if (delta.type === "thinking_delta") {
|
|
430
|
+
if (acc?.kind === "thinking")
|
|
431
|
+
acc.thinking += delta.thinking;
|
|
432
|
+
this.emit(AgentEvent_1.AgentEvent.REASONING_CHUNK, delta.thinking);
|
|
433
|
+
yield { type: "reasoning", content: delta.thinking };
|
|
434
|
+
}
|
|
435
|
+
else if (delta.type === "signature_delta") {
|
|
436
|
+
if (acc?.kind === "thinking")
|
|
437
|
+
acc.signature += delta.signature;
|
|
438
|
+
}
|
|
439
|
+
else if (delta.type === "input_json_delta") {
|
|
440
|
+
if (acc?.kind === "tool_use")
|
|
441
|
+
acc.inputJson += delta.partial_json;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
const usage = {
|
|
446
|
+
input_tokens: inputTokens,
|
|
447
|
+
output_tokens: outputTokens,
|
|
448
|
+
total_tokens: inputTokens + outputTokens,
|
|
449
|
+
};
|
|
450
|
+
if (this.lastTokenUsage) {
|
|
451
|
+
this.lastTokenUsage.input_tokens += usage.input_tokens;
|
|
452
|
+
this.lastTokenUsage.output_tokens += usage.output_tokens;
|
|
453
|
+
this.lastTokenUsage.total_tokens += usage.total_tokens;
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
this.lastTokenUsage = { ...usage };
|
|
457
|
+
}
|
|
458
|
+
if (stopReason === "max_tokens") {
|
|
459
|
+
const error = new AgentError_1.MaxTokensExceededError("Response exceeded maximum token limit", this.config.maxTokens || 1024);
|
|
460
|
+
this.emit(AgentEvent_1.AgentEvent.MAX_TOKENS_EXCEEDED, error);
|
|
461
|
+
this.emit(AgentEvent_1.AgentEvent.ERROR, error);
|
|
462
|
+
if (this.vizEventId) {
|
|
463
|
+
VizReporter_1.vizReporter.agentError(this.vizEventId, "MaxTokensExceededError", error.message, false);
|
|
464
|
+
this.vizEventId = undefined;
|
|
465
|
+
}
|
|
466
|
+
throw error;
|
|
467
|
+
}
|
|
468
|
+
// Rebuild the assistant turn in stream order (thinking → text → tool_use).
|
|
469
|
+
const orderedBlocks = Array.from(blocks.entries())
|
|
470
|
+
.sort(([a], [b]) => a - b)
|
|
471
|
+
.map(([, b]) => {
|
|
472
|
+
switch (b.kind) {
|
|
473
|
+
case "thinking":
|
|
474
|
+
return { type: "thinking", thinking: b.thinking, signature: b.signature };
|
|
475
|
+
case "redacted_thinking":
|
|
476
|
+
return { type: "redacted_thinking", data: b.data };
|
|
477
|
+
case "tool_use":
|
|
478
|
+
return {
|
|
479
|
+
type: "tool_use",
|
|
480
|
+
id: b.id,
|
|
481
|
+
name: b.name,
|
|
482
|
+
input: JSON.parse(b.inputJson || "{}"),
|
|
483
|
+
};
|
|
484
|
+
case "text":
|
|
485
|
+
return { type: "text", text: b.text, citations: [] };
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
// Fallback: preserve streamed text even if no text block start was observed.
|
|
489
|
+
if (textContent && !orderedBlocks.some((b) => b.type === "text")) {
|
|
490
|
+
orderedBlocks.push({ type: "text", text: textContent, citations: [] });
|
|
491
|
+
}
|
|
492
|
+
const toolUseBlocks = orderedBlocks.filter((b) => b.type === "tool_use");
|
|
493
|
+
if (stopReason === "tool_use" && toolUseBlocks.length > 0) {
|
|
494
|
+
this.emit(AgentEvent_1.AgentEvent.TOOL_USE, orderedBlocks);
|
|
495
|
+
this.currentToolCallCount += toolUseBlocks.length;
|
|
496
|
+
const assistantEntry = transformers_1.anthropicTransformer.fromProviderContent("assistant", orderedBlocks);
|
|
497
|
+
this.addToHistory(assistantEntry);
|
|
498
|
+
const toolResults = await this.handleToolUse(orderedBlocks);
|
|
499
|
+
this.addMessageToHistory("user", toolResults);
|
|
500
|
+
yield* this.streamTurn();
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
const assistantEntry = transformers_1.anthropicTransformer.fromProviderContent("assistant", orderedBlocks);
|
|
504
|
+
this.addToHistory(assistantEntry);
|
|
505
|
+
this.emit(AgentEvent_1.AgentEvent.DONE, { content: textContent }, this.lastTokenUsage);
|
|
506
|
+
if (this.vizEventId) {
|
|
507
|
+
VizReporter_1.vizReporter.agentComplete(this.vizEventId, {
|
|
508
|
+
input: this.lastTokenUsage?.input_tokens || 0,
|
|
509
|
+
output: this.lastTokenUsage?.output_tokens || 0,
|
|
510
|
+
total: this.lastTokenUsage?.total_tokens || 0,
|
|
511
|
+
}, "end_turn", this.currentToolCallCount > 0, this.currentToolCallCount, textContent);
|
|
512
|
+
this.vizEventId = undefined;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
308
516
|
parseUsage(input) {
|
|
309
517
|
return {
|
|
310
518
|
input_tokens: input.input_tokens,
|
|
@@ -118,7 +118,7 @@ class GeminiAgent extends BaseAgent_1.BaseAgent {
|
|
|
118
118
|
items: this.convertPropertyToSchema(prop.items),
|
|
119
119
|
description,
|
|
120
120
|
};
|
|
121
|
-
case "object":
|
|
121
|
+
case "object": {
|
|
122
122
|
const objProps = {};
|
|
123
123
|
if (prop.properties) {
|
|
124
124
|
const subProps = prop.properties;
|
|
@@ -132,6 +132,7 @@ class GeminiAgent extends BaseAgent_1.BaseAgent {
|
|
|
132
132
|
description,
|
|
133
133
|
required: prop.required,
|
|
134
134
|
};
|
|
135
|
+
}
|
|
135
136
|
default:
|
|
136
137
|
return { type: generative_ai_1.SchemaType.STRING, description };
|
|
137
138
|
}
|
|
@@ -2,6 +2,7 @@ import { BaseAgent, BaseAgentConfig, TokenUsage } from "../BaseAgent";
|
|
|
2
2
|
import { History, MessageContent } from "../../history/History";
|
|
3
3
|
import { Tool, Response, ResponseUsage } from "openai/resources/responses/responses";
|
|
4
4
|
import { OpenAIModel } from "../model-types";
|
|
5
|
+
import { StreamChunk } from "../openai-compatible/OpenAICompatibleAgent";
|
|
5
6
|
type AgentConfig = BaseAgentConfig & {
|
|
6
7
|
apiKey: string;
|
|
7
8
|
model?: OpenAIModel;
|
|
@@ -42,6 +43,20 @@ export declare class OpenAiAgent extends BaseAgent {
|
|
|
42
43
|
execute(input: string | MessageContent[]): Promise<string>;
|
|
43
44
|
protected handleResponse(response: Response): Promise<string>;
|
|
44
45
|
private handleToolUse;
|
|
46
|
+
/**
|
|
47
|
+
* Stream a response as an async generator of `StreamChunk` objects.
|
|
48
|
+
* Yields `{ type: "text" }` for visible output and `{ type: "reasoning" }` for
|
|
49
|
+
* reasoning summary tokens (o-series models). Tool calls are handled transparently.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* for await (const chunk of agent.executeStream("Explain recursion")) {
|
|
54
|
+
* if (chunk.type === "text") process.stdout.write(chunk.content);
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
executeStream(input: string | MessageContent[]): AsyncGenerator<StreamChunk>;
|
|
59
|
+
private streamTurn;
|
|
45
60
|
protected parseUsage(input: ResponseUsage): TokenUsage;
|
|
46
61
|
}
|
|
47
62
|
export {};
|
|
@@ -341,6 +341,156 @@ class OpenAiAgent extends BaseAgent_1.BaseAgent {
|
|
|
341
341
|
}));
|
|
342
342
|
return toolResults;
|
|
343
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Stream a response as an async generator of `StreamChunk` objects.
|
|
346
|
+
* Yields `{ type: "text" }` for visible output and `{ type: "reasoning" }` for
|
|
347
|
+
* reasoning summary tokens (o-series models). Tool calls are handled transparently.
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```typescript
|
|
351
|
+
* for await (const chunk of agent.executeStream("Explain recursion")) {
|
|
352
|
+
* if (chunk.type === "text") process.stdout.write(chunk.content);
|
|
353
|
+
* }
|
|
354
|
+
* ```
|
|
355
|
+
*/
|
|
356
|
+
async *executeStream(input) {
|
|
357
|
+
this.emit(AgentEvent_1.AgentEvent.BEFORE_EXECUTE, input);
|
|
358
|
+
this.lastTokenUsage = undefined;
|
|
359
|
+
this.currentToolCallCount = 0;
|
|
360
|
+
const inputPreview = typeof input === "string" ? input : JSON.stringify(input);
|
|
361
|
+
if (VizConfig_1.vizConfig.isEnabled()) {
|
|
362
|
+
this.vizEventId = VizReporter_1.vizReporter.agentStart(this.id, this.name, this.config.model, "openai", inputPreview);
|
|
363
|
+
}
|
|
364
|
+
if (this.history.transient) {
|
|
365
|
+
this.history.clear();
|
|
366
|
+
this.addSystemMessage(this.getSystemMessage());
|
|
367
|
+
}
|
|
368
|
+
if (typeof input === "string") {
|
|
369
|
+
this.addTextToHistory("user", input);
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
this.addMessageToHistory("user", input);
|
|
373
|
+
}
|
|
374
|
+
this.history.setSessionAnchor();
|
|
375
|
+
this.history.beginExecution();
|
|
376
|
+
try {
|
|
377
|
+
yield* this.streamTurn();
|
|
378
|
+
}
|
|
379
|
+
catch (error) {
|
|
380
|
+
if (error instanceof AgentError_1.AgentError) {
|
|
381
|
+
this.emit(AgentEvent_1.AgentEvent.ERROR, error);
|
|
382
|
+
if (this.vizEventId) {
|
|
383
|
+
VizReporter_1.vizReporter.agentError(this.vizEventId, error.constructor.name, error.message, false);
|
|
384
|
+
this.vizEventId = undefined;
|
|
385
|
+
}
|
|
386
|
+
throw error;
|
|
387
|
+
}
|
|
388
|
+
if (error && typeof error === "object" && "error" in error) {
|
|
389
|
+
const openAIError = error;
|
|
390
|
+
const apiError = new AgentError_1.ApiError(`OpenAI API error: ${openAIError.error.message || "Unknown error"}`, openAIError.status, openAIError.error);
|
|
391
|
+
this.emit(AgentEvent_1.AgentEvent.ERROR, apiError);
|
|
392
|
+
if (this.vizEventId) {
|
|
393
|
+
VizReporter_1.vizReporter.agentError(this.vizEventId, "ApiError", apiError.message, openAIError.error.code === "rate_limit_exceeded");
|
|
394
|
+
this.vizEventId = undefined;
|
|
395
|
+
}
|
|
396
|
+
throw apiError;
|
|
397
|
+
}
|
|
398
|
+
const executionError = new AgentError_1.ExecutionError(`OpenAI error: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
399
|
+
this.emit(AgentEvent_1.AgentEvent.ERROR, executionError);
|
|
400
|
+
if (this.vizEventId) {
|
|
401
|
+
VizReporter_1.vizReporter.agentError(this.vizEventId, "ExecutionError", executionError.message, false);
|
|
402
|
+
this.vizEventId = undefined;
|
|
403
|
+
}
|
|
404
|
+
throw executionError;
|
|
405
|
+
}
|
|
406
|
+
finally {
|
|
407
|
+
this.history.endExecution();
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
async *streamTurn() {
|
|
411
|
+
const inputMessages = transformers_1.openAiTransformer.toProvider(this.history.getEntries());
|
|
412
|
+
const stream = await this.client.responses.create({
|
|
413
|
+
model: this.config.model,
|
|
414
|
+
max_output_tokens: this.config.maxTokens,
|
|
415
|
+
input: inputMessages,
|
|
416
|
+
tools: this.getToolDefinitions(),
|
|
417
|
+
store: false,
|
|
418
|
+
stream: true,
|
|
419
|
+
temperature: this.config.temperature,
|
|
420
|
+
top_p: this.config.topP,
|
|
421
|
+
user: this.config.user,
|
|
422
|
+
...(this.config.disableReasoning && { reasoning: { effort: null } }),
|
|
423
|
+
...(this.config.reasoningEffort && !this.config.disableReasoning && {
|
|
424
|
+
// `summary: "auto"` is required for the Responses API to stream
|
|
425
|
+
// `response.reasoning_summary_text.delta` events.
|
|
426
|
+
reasoning: { effort: this.config.reasoningEffort, summary: "auto" },
|
|
427
|
+
}),
|
|
428
|
+
});
|
|
429
|
+
let completedEvent = null;
|
|
430
|
+
for await (const event of stream) {
|
|
431
|
+
if (event.type === "response.output_text.delta") {
|
|
432
|
+
this.emit(AgentEvent_1.AgentEvent.CHUNK, event.delta);
|
|
433
|
+
yield { type: "text", content: event.delta };
|
|
434
|
+
}
|
|
435
|
+
if (event.type === "response.reasoning_summary_text.delta") {
|
|
436
|
+
this.emit(AgentEvent_1.AgentEvent.REASONING_CHUNK, event.delta);
|
|
437
|
+
yield { type: "reasoning", content: event.delta };
|
|
438
|
+
}
|
|
439
|
+
if (event.type === "response.completed") {
|
|
440
|
+
completedEvent = event;
|
|
441
|
+
if (event.response.usage) {
|
|
442
|
+
const usage = this.parseUsage(event.response.usage);
|
|
443
|
+
if (this.lastTokenUsage) {
|
|
444
|
+
this.lastTokenUsage.input_tokens += usage.input_tokens;
|
|
445
|
+
this.lastTokenUsage.output_tokens += usage.output_tokens;
|
|
446
|
+
this.lastTokenUsage.total_tokens += usage.total_tokens;
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
this.lastTokenUsage = { ...usage };
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
if (event.type === "response.incomplete") {
|
|
454
|
+
throw new AgentError_1.MaxTokensExceededError("Response incomplete: max tokens reached", this.config.maxTokens || 1024);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (!completedEvent) {
|
|
458
|
+
throw new AgentError_1.ExecutionError("OpenAI stream ended without a completed event");
|
|
459
|
+
}
|
|
460
|
+
const response = completedEvent.response;
|
|
461
|
+
const toolCalls = response.output.filter((o) => o.type === "function_call");
|
|
462
|
+
if (toolCalls.length > 0) {
|
|
463
|
+
this.emit(AgentEvent_1.AgentEvent.TOOL_USE, toolCalls);
|
|
464
|
+
this.currentToolCallCount += toolCalls.length;
|
|
465
|
+
const functionCalls = toolCalls.map((tc) => ({
|
|
466
|
+
id: tc.id || tc.call_id,
|
|
467
|
+
call_id: tc.call_id,
|
|
468
|
+
name: tc.name,
|
|
469
|
+
arguments: tc.arguments,
|
|
470
|
+
}));
|
|
471
|
+
const assistantEntry = transformers_1.openAiTransformer.fromProviderMessage("assistant", response.output_text || "", functionCalls);
|
|
472
|
+
this.addToHistory(assistantEntry);
|
|
473
|
+
const toolResults = await this.handleToolUse(toolCalls);
|
|
474
|
+
for (const result of toolResults) {
|
|
475
|
+
this.addToHistory(transformers_1.openAiTransformer.toolResultEntry(result.call_id, result.output, false));
|
|
476
|
+
}
|
|
477
|
+
yield* this.streamTurn();
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
const textContent = response.output_text || "";
|
|
481
|
+
const entry = transformers_1.openAiTransformer.fromProviderMessage("assistant", textContent);
|
|
482
|
+
this.addToHistory(entry);
|
|
483
|
+
this.emit(AgentEvent_1.AgentEvent.DONE, response, this.lastTokenUsage);
|
|
484
|
+
if (this.vizEventId) {
|
|
485
|
+
VizReporter_1.vizReporter.agentComplete(this.vizEventId, {
|
|
486
|
+
input: this.lastTokenUsage?.input_tokens || 0,
|
|
487
|
+
output: this.lastTokenUsage?.output_tokens || 0,
|
|
488
|
+
total: this.lastTokenUsage?.total_tokens || 0,
|
|
489
|
+
}, "end_turn", this.currentToolCallCount > 0, this.currentToolCallCount, textContent);
|
|
490
|
+
this.vizEventId = undefined;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
344
494
|
parseUsage(input) {
|
|
345
495
|
return {
|
|
346
496
|
input_tokens: input.input_tokens,
|
|
@@ -4,6 +4,15 @@ import { Model } from "openai/resources/models";
|
|
|
4
4
|
import { BaseAgent, BaseAgentConfig, TokenUsage } from "../BaseAgent";
|
|
5
5
|
import { AgentVendor } from "../AgentConfig";
|
|
6
6
|
import { History, MessageContent } from "../../history/History";
|
|
7
|
+
/**
|
|
8
|
+
* A single chunk yielded by `executeStream()`.
|
|
9
|
+
* - `"text"` — visible output token
|
|
10
|
+
* - `"reasoning"` — internal reasoning token (DeepSeek-style `reasoning_content`)
|
|
11
|
+
*/
|
|
12
|
+
export type StreamChunk = {
|
|
13
|
+
type: "text" | "reasoning";
|
|
14
|
+
content: string;
|
|
15
|
+
};
|
|
7
16
|
export type OpenAICompatibleConfig = BaseAgentConfig & {
|
|
8
17
|
/** Base URL of the OpenAI-compatible `/v1` endpoint (required) */
|
|
9
18
|
baseURL: string;
|
|
@@ -43,6 +52,24 @@ export declare abstract class OpenAICompatibleAgent extends BaseAgent {
|
|
|
43
52
|
private callProvider;
|
|
44
53
|
protected handleResponse(response: ChatCompletion): Promise<string>;
|
|
45
54
|
private handleToolCalls;
|
|
55
|
+
/**
|
|
56
|
+
* Stream a response as an async generator of `StreamChunk` objects.
|
|
57
|
+
*
|
|
58
|
+
* Yields `{ type: "text" }` for visible output and `{ type: "reasoning" }` for
|
|
59
|
+
* internal reasoning tokens (models that expose `reasoning_content`, e.g. DeepSeek R1).
|
|
60
|
+
* Tool calls are executed transparently — the generator continues streaming after
|
|
61
|
+
* each tool-call round-trip.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* for await (const chunk of agent.executeStream("Explain recursion")) {
|
|
66
|
+
* if (chunk.type === "text") process.stdout.write(chunk.content);
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
executeStream(input: string | MessageContent[]): AsyncGenerator<StreamChunk>;
|
|
71
|
+
private streamTurn;
|
|
72
|
+
private accumulateStreamUsage;
|
|
46
73
|
protected parseUsage(response: ChatCompletion): TokenUsage;
|
|
47
74
|
}
|
|
48
75
|
//# sourceMappingURL=OpenAICompatibleAgent.d.ts.map
|
|
@@ -236,6 +236,197 @@ class OpenAICompatibleAgent extends BaseAgent_1.BaseAgent {
|
|
|
236
236
|
}
|
|
237
237
|
}));
|
|
238
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Stream a response as an async generator of `StreamChunk` objects.
|
|
241
|
+
*
|
|
242
|
+
* Yields `{ type: "text" }` for visible output and `{ type: "reasoning" }` for
|
|
243
|
+
* internal reasoning tokens (models that expose `reasoning_content`, e.g. DeepSeek R1).
|
|
244
|
+
* Tool calls are executed transparently — the generator continues streaming after
|
|
245
|
+
* each tool-call round-trip.
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* for await (const chunk of agent.executeStream("Explain recursion")) {
|
|
250
|
+
* if (chunk.type === "text") process.stdout.write(chunk.content);
|
|
251
|
+
* }
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
async *executeStream(input) {
|
|
255
|
+
this.emit(AgentEvent_1.AgentEvent.BEFORE_EXECUTE, input);
|
|
256
|
+
this.lastTokenUsage = undefined;
|
|
257
|
+
this.currentToolCallCount = 0;
|
|
258
|
+
const inputPreview = typeof input === "string" ? input : JSON.stringify(input);
|
|
259
|
+
if (VizConfig_1.vizConfig.isEnabled()) {
|
|
260
|
+
this.vizEventId = VizReporter_1.vizReporter.agentStart(this.id, this.name, this.config.model, this.vendor, inputPreview);
|
|
261
|
+
}
|
|
262
|
+
if (this.history.transient) {
|
|
263
|
+
this.history.clear();
|
|
264
|
+
this.addSystemMessage(this.getSystemMessage());
|
|
265
|
+
}
|
|
266
|
+
if (typeof input === "string") {
|
|
267
|
+
this.addTextToHistory("user", input);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
this.addMessageToHistory("user", input);
|
|
271
|
+
}
|
|
272
|
+
this.history.setSessionAnchor();
|
|
273
|
+
this.history.beginExecution();
|
|
274
|
+
try {
|
|
275
|
+
yield* this.streamTurn();
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
if (error instanceof openai_1.default.APIError) {
|
|
279
|
+
const apiError = new AgentError_1.ApiError(`${this.getVendorName()} API error: ${error.message}`, error.status, error);
|
|
280
|
+
this.emit(AgentEvent_1.AgentEvent.ERROR, apiError);
|
|
281
|
+
if (this.vizEventId) {
|
|
282
|
+
VizReporter_1.vizReporter.agentError(this.vizEventId, "ApiError", apiError.message, error.status === 429);
|
|
283
|
+
this.vizEventId = undefined;
|
|
284
|
+
}
|
|
285
|
+
throw apiError;
|
|
286
|
+
}
|
|
287
|
+
if (error instanceof AgentError_1.AgentError) {
|
|
288
|
+
this.emit(AgentEvent_1.AgentEvent.ERROR, error);
|
|
289
|
+
if (this.vizEventId) {
|
|
290
|
+
VizReporter_1.vizReporter.agentError(this.vizEventId, error.constructor.name, error.message, false);
|
|
291
|
+
this.vizEventId = undefined;
|
|
292
|
+
}
|
|
293
|
+
throw error;
|
|
294
|
+
}
|
|
295
|
+
const executionError = new AgentError_1.ExecutionError(`${this.getVendorName()} error: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
296
|
+
this.emit(AgentEvent_1.AgentEvent.ERROR, executionError);
|
|
297
|
+
if (this.vizEventId) {
|
|
298
|
+
VizReporter_1.vizReporter.agentError(this.vizEventId, "ExecutionError", executionError.message, false);
|
|
299
|
+
this.vizEventId = undefined;
|
|
300
|
+
}
|
|
301
|
+
throw executionError;
|
|
302
|
+
}
|
|
303
|
+
finally {
|
|
304
|
+
this.history.endExecution();
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
async *streamTurn() {
|
|
308
|
+
const messages = transformers_1.chatCompletionsTransformer.toProvider(this.history.getEntries());
|
|
309
|
+
const tools = this.tools.size > 0 ? this.getToolDefinitions() : undefined;
|
|
310
|
+
const stream = await this.client.chat.completions.create({
|
|
311
|
+
model: this.config.model,
|
|
312
|
+
messages,
|
|
313
|
+
tools,
|
|
314
|
+
stream: true,
|
|
315
|
+
stream_options: { include_usage: true },
|
|
316
|
+
max_tokens: this.config.maxTokens,
|
|
317
|
+
temperature: this.config.temperature,
|
|
318
|
+
top_p: this.config.topP,
|
|
319
|
+
stop: this.config.stopSequences,
|
|
320
|
+
seed: this.config.seed,
|
|
321
|
+
presence_penalty: this.config.presencePenalty,
|
|
322
|
+
frequency_penalty: this.config.frequencyPenalty,
|
|
323
|
+
...this.buildExtraRequestParams(),
|
|
324
|
+
});
|
|
325
|
+
let textContent = "";
|
|
326
|
+
const toolCallAcc = new Map();
|
|
327
|
+
let finishReason = null;
|
|
328
|
+
for await (const chunk of stream) {
|
|
329
|
+
// Final chunk carrying usage (choices is empty)
|
|
330
|
+
if (chunk.choices.length === 0) {
|
|
331
|
+
if (chunk.usage)
|
|
332
|
+
this.accumulateStreamUsage(chunk.usage);
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
const choice = chunk.choices[0];
|
|
336
|
+
finishReason = choice.finish_reason ?? finishReason;
|
|
337
|
+
const delta = choice.delta;
|
|
338
|
+
if (delta.content) {
|
|
339
|
+
textContent += delta.content;
|
|
340
|
+
this.emit(AgentEvent_1.AgentEvent.CHUNK, delta.content);
|
|
341
|
+
yield { type: "text", content: delta.content };
|
|
342
|
+
}
|
|
343
|
+
// DeepSeek-style reasoning tokens (not in OpenAI SDK types — cast required)
|
|
344
|
+
const reasoningDelta = delta.reasoning_content;
|
|
345
|
+
if (reasoningDelta) {
|
|
346
|
+
this.emit(AgentEvent_1.AgentEvent.REASONING_CHUNK, reasoningDelta);
|
|
347
|
+
yield { type: "reasoning", content: reasoningDelta };
|
|
348
|
+
}
|
|
349
|
+
if (delta.tool_calls) {
|
|
350
|
+
for (const tc of delta.tool_calls) {
|
|
351
|
+
if (!toolCallAcc.has(tc.index)) {
|
|
352
|
+
toolCallAcc.set(tc.index, { id: "", name: "", arguments: "" });
|
|
353
|
+
}
|
|
354
|
+
const acc = toolCallAcc.get(tc.index);
|
|
355
|
+
if (tc.id)
|
|
356
|
+
acc.id = tc.id;
|
|
357
|
+
if (tc.function?.name)
|
|
358
|
+
acc.name += tc.function.name;
|
|
359
|
+
if (tc.function?.arguments)
|
|
360
|
+
acc.arguments += tc.function.arguments;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (finishReason === "length") {
|
|
365
|
+
const error = new AgentError_1.MaxTokensExceededError("Response exceeded maximum token limit", this.config.maxTokens || 1024);
|
|
366
|
+
this.emit(AgentEvent_1.AgentEvent.MAX_TOKENS_EXCEEDED, error);
|
|
367
|
+
this.emit(AgentEvent_1.AgentEvent.ERROR, error);
|
|
368
|
+
if (this.vizEventId) {
|
|
369
|
+
VizReporter_1.vizReporter.agentError(this.vizEventId, "MaxTokensExceededError", error.message, false);
|
|
370
|
+
this.vizEventId = undefined;
|
|
371
|
+
}
|
|
372
|
+
throw error;
|
|
373
|
+
}
|
|
374
|
+
if (finishReason === "tool_calls" && toolCallAcc.size > 0) {
|
|
375
|
+
const toolCalls = Array.from(toolCallAcc.entries())
|
|
376
|
+
.sort(([a], [b]) => a - b)
|
|
377
|
+
.map(([, tc]) => ({
|
|
378
|
+
id: tc.id,
|
|
379
|
+
type: "function",
|
|
380
|
+
function: { name: tc.name, arguments: tc.arguments },
|
|
381
|
+
}));
|
|
382
|
+
this.emit(AgentEvent_1.AgentEvent.TOOL_USE, toolCalls);
|
|
383
|
+
this.currentToolCallCount += toolCalls.length;
|
|
384
|
+
const assistantEntry = transformers_1.chatCompletionsTransformer.fromProviderMessage({
|
|
385
|
+
role: "assistant",
|
|
386
|
+
content: textContent || null,
|
|
387
|
+
tool_calls: toolCalls,
|
|
388
|
+
});
|
|
389
|
+
this.addToHistory(assistantEntry);
|
|
390
|
+
const toolResults = await this.handleToolCalls(toolCalls);
|
|
391
|
+
for (const result of toolResults) {
|
|
392
|
+
this.addToHistory(transformers_1.chatCompletionsTransformer.toolResultEntry(result.toolCallId, result.content));
|
|
393
|
+
}
|
|
394
|
+
yield* this.streamTurn();
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
const assistantEntry = transformers_1.chatCompletionsTransformer.fromProviderMessage({
|
|
398
|
+
role: "assistant",
|
|
399
|
+
content: textContent || null,
|
|
400
|
+
});
|
|
401
|
+
this.addToHistory(assistantEntry);
|
|
402
|
+
this.emit(AgentEvent_1.AgentEvent.DONE, { content: textContent }, this.lastTokenUsage);
|
|
403
|
+
if (this.vizEventId) {
|
|
404
|
+
VizReporter_1.vizReporter.agentComplete(this.vizEventId, {
|
|
405
|
+
input: this.lastTokenUsage?.input_tokens || 0,
|
|
406
|
+
output: this.lastTokenUsage?.output_tokens || 0,
|
|
407
|
+
total: this.lastTokenUsage?.total_tokens || 0,
|
|
408
|
+
}, "end_turn", this.currentToolCallCount > 0, this.currentToolCallCount, textContent);
|
|
409
|
+
this.vizEventId = undefined;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
accumulateStreamUsage(usage) {
|
|
414
|
+
if (!usage)
|
|
415
|
+
return;
|
|
416
|
+
const u = {
|
|
417
|
+
input_tokens: usage.prompt_tokens ?? 0,
|
|
418
|
+
output_tokens: usage.completion_tokens ?? 0,
|
|
419
|
+
total_tokens: usage.total_tokens ?? 0,
|
|
420
|
+
};
|
|
421
|
+
if (this.lastTokenUsage) {
|
|
422
|
+
this.lastTokenUsage.input_tokens += u.input_tokens;
|
|
423
|
+
this.lastTokenUsage.output_tokens += u.output_tokens;
|
|
424
|
+
this.lastTokenUsage.total_tokens += u.total_tokens;
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
this.lastTokenUsage = u;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
239
430
|
parseUsage(response) {
|
|
240
431
|
const usage = response.usage;
|
|
241
432
|
return {
|
|
@@ -3,8 +3,8 @@ import { HistoryEntry, MessageRole, MessageContent } from "./types";
|
|
|
3
3
|
import type { ReduceOptions } from "./types";
|
|
4
4
|
/** @internal — exposed for test teardown only */
|
|
5
5
|
export declare function resetTokenxCache(): void;
|
|
6
|
-
export type { HistoryEntry, MessageRole, MessageContent, ReduceOptions, ImageMimeType, ImageUrlContent, ImageBase64Content, } from "./types";
|
|
7
|
-
export { text, toolUse, toolResult, textMessage, imageUrl, imageBase64, isTextContent, isToolUseContent, isToolResultContent, isImageUrlContent, isImageBase64Content, isImageContent, } from "./types";
|
|
6
|
+
export type { HistoryEntry, MessageRole, MessageContent, ReduceOptions, ImageMimeType, ImageUrlContent, ImageBase64Content, ThinkingContent, } from "./types";
|
|
7
|
+
export { text, toolUse, toolResult, thinking, textMessage, imageUrl, imageBase64, isTextContent, isToolUseContent, isToolResultContent, isThinkingContent, isImageUrlContent, isImageBase64Content, isImageContent, } from "./types";
|
|
8
8
|
/**
|
|
9
9
|
* Metadata stored alongside each history entry.
|
|
10
10
|
* Extended with summary tracking fields for the compression plugin.
|
package/dist/history/History.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.History = exports.isImageContent = exports.isImageBase64Content = exports.isImageUrlContent = exports.isToolResultContent = exports.isToolUseContent = exports.isTextContent = exports.imageBase64 = exports.imageUrl = exports.textMessage = exports.toolResult = exports.toolUse = exports.text = void 0;
|
|
39
|
+
exports.History = exports.isImageContent = exports.isImageBase64Content = exports.isImageUrlContent = exports.isThinkingContent = exports.isToolResultContent = exports.isToolUseContent = exports.isTextContent = exports.imageBase64 = exports.imageUrl = exports.textMessage = exports.thinking = exports.toolResult = exports.toolUse = exports.text = void 0;
|
|
40
40
|
exports.resetTokenxCache = resetTokenxCache;
|
|
41
41
|
const events_1 = __importDefault(require("events"));
|
|
42
42
|
const types_1 = require("./types");
|
|
@@ -70,12 +70,14 @@ var types_2 = require("./types");
|
|
|
70
70
|
Object.defineProperty(exports, "text", { enumerable: true, get: function () { return types_2.text; } });
|
|
71
71
|
Object.defineProperty(exports, "toolUse", { enumerable: true, get: function () { return types_2.toolUse; } });
|
|
72
72
|
Object.defineProperty(exports, "toolResult", { enumerable: true, get: function () { return types_2.toolResult; } });
|
|
73
|
+
Object.defineProperty(exports, "thinking", { enumerable: true, get: function () { return types_2.thinking; } });
|
|
73
74
|
Object.defineProperty(exports, "textMessage", { enumerable: true, get: function () { return types_2.textMessage; } });
|
|
74
75
|
Object.defineProperty(exports, "imageUrl", { enumerable: true, get: function () { return types_2.imageUrl; } });
|
|
75
76
|
Object.defineProperty(exports, "imageBase64", { enumerable: true, get: function () { return types_2.imageBase64; } });
|
|
76
77
|
Object.defineProperty(exports, "isTextContent", { enumerable: true, get: function () { return types_2.isTextContent; } });
|
|
77
78
|
Object.defineProperty(exports, "isToolUseContent", { enumerable: true, get: function () { return types_2.isToolUseContent; } });
|
|
78
79
|
Object.defineProperty(exports, "isToolResultContent", { enumerable: true, get: function () { return types_2.isToolResultContent; } });
|
|
80
|
+
Object.defineProperty(exports, "isThinkingContent", { enumerable: true, get: function () { return types_2.isThinkingContent; } });
|
|
79
81
|
Object.defineProperty(exports, "isImageUrlContent", { enumerable: true, get: function () { return types_2.isImageUrlContent; } });
|
|
80
82
|
Object.defineProperty(exports, "isImageBase64Content", { enumerable: true, get: function () { return types_2.isImageBase64Content; } });
|
|
81
83
|
Object.defineProperty(exports, "isImageContent", { enumerable: true, get: function () { return types_2.isImageContent; } });
|
package/dist/history/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { History, resetTokenxCache, type EntryMetadata, type ReducibleEntry, type HistoryPlugin, } from "./History";
|
|
2
2
|
export { RedisHistory } from "./RedisHistory";
|
|
3
|
-
export type { HistoryEntry, MessageRole, MessageContent, TextContent, ToolUseContent, ToolResultContent, ProviderMeta, ReduceOptions, } from "./types";
|
|
4
|
-
export { text, toolUse, toolResult, textMessage, isTextContent, isToolUseContent, isToolResultContent, } from "./types";
|
|
3
|
+
export type { HistoryEntry, MessageRole, MessageContent, TextContent, ToolUseContent, ToolResultContent, ThinkingContent, ProviderMeta, ReduceOptions, } from "./types";
|
|
4
|
+
export { text, toolUse, toolResult, thinking, textMessage, isTextContent, isToolUseContent, isToolResultContent, isThinkingContent, } from "./types";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/history/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isToolResultContent = exports.isToolUseContent = exports.isTextContent = exports.textMessage = exports.toolResult = exports.toolUse = exports.text = exports.RedisHistory = exports.resetTokenxCache = exports.History = void 0;
|
|
3
|
+
exports.isThinkingContent = exports.isToolResultContent = exports.isToolUseContent = exports.isTextContent = exports.textMessage = exports.thinking = exports.toolResult = exports.toolUse = exports.text = exports.RedisHistory = exports.resetTokenxCache = exports.History = void 0;
|
|
4
4
|
var History_1 = require("./History");
|
|
5
5
|
Object.defineProperty(exports, "History", { enumerable: true, get: function () { return History_1.History; } });
|
|
6
6
|
Object.defineProperty(exports, "resetTokenxCache", { enumerable: true, get: function () { return History_1.resetTokenxCache; } });
|
|
@@ -10,8 +10,10 @@ var types_1 = require("./types");
|
|
|
10
10
|
Object.defineProperty(exports, "text", { enumerable: true, get: function () { return types_1.text; } });
|
|
11
11
|
Object.defineProperty(exports, "toolUse", { enumerable: true, get: function () { return types_1.toolUse; } });
|
|
12
12
|
Object.defineProperty(exports, "toolResult", { enumerable: true, get: function () { return types_1.toolResult; } });
|
|
13
|
+
Object.defineProperty(exports, "thinking", { enumerable: true, get: function () { return types_1.thinking; } });
|
|
13
14
|
Object.defineProperty(exports, "textMessage", { enumerable: true, get: function () { return types_1.textMessage; } });
|
|
14
15
|
Object.defineProperty(exports, "isTextContent", { enumerable: true, get: function () { return types_1.isTextContent; } });
|
|
15
16
|
Object.defineProperty(exports, "isToolUseContent", { enumerable: true, get: function () { return types_1.isToolUseContent; } });
|
|
16
17
|
Object.defineProperty(exports, "isToolResultContent", { enumerable: true, get: function () { return types_1.isToolResultContent; } });
|
|
18
|
+
Object.defineProperty(exports, "isThinkingContent", { enumerable: true, get: function () { return types_1.isThinkingContent; } });
|
|
17
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -40,6 +40,19 @@ exports.anthropicTransformer = {
|
|
|
40
40
|
is_error: block.is_error,
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
+
if ((0, types_1.isThinkingContent)(block)) {
|
|
44
|
+
if (block.redactedData !== undefined) {
|
|
45
|
+
return {
|
|
46
|
+
type: "redacted_thinking",
|
|
47
|
+
data: block.redactedData,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
type: "thinking",
|
|
52
|
+
thinking: block.thinking,
|
|
53
|
+
signature: block.signature ?? "",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
43
56
|
if ((0, types_1.isImageUrlContent)(block)) {
|
|
44
57
|
return {
|
|
45
58
|
type: "image",
|
|
@@ -72,7 +85,13 @@ exports.anthropicTransformer = {
|
|
|
72
85
|
if (block.type === "tool_use") {
|
|
73
86
|
return (0, types_1.toolUse)(block.id, block.name, block.input);
|
|
74
87
|
}
|
|
75
|
-
|
|
88
|
+
if (block.type === "thinking") {
|
|
89
|
+
return (0, types_1.thinking)(block.thinking, block.signature);
|
|
90
|
+
}
|
|
91
|
+
if (block.type === "redacted_thinking") {
|
|
92
|
+
return (0, types_1.thinking)("", undefined, block.data);
|
|
93
|
+
}
|
|
94
|
+
// Unknown / unsupported block — preserve a textual representation
|
|
76
95
|
return (0, types_1.text)(JSON.stringify(block));
|
|
77
96
|
});
|
|
78
97
|
return {
|
package/dist/history/types.d.ts
CHANGED
|
@@ -29,6 +29,20 @@ export type ToolResultContent = {
|
|
|
29
29
|
content: string;
|
|
30
30
|
is_error?: boolean;
|
|
31
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Extended-thinking / reasoning block produced by the assistant (Anthropic).
|
|
34
|
+
*
|
|
35
|
+
* These must be preserved verbatim — including `signature` — and echoed back on
|
|
36
|
+
* the following request when the assistant used a tool, or the provider rejects
|
|
37
|
+
* the turn. `redactedData` is set instead of `thinking` for redacted blocks,
|
|
38
|
+
* whose payload is opaque and must be returned unchanged.
|
|
39
|
+
*/
|
|
40
|
+
export type ThinkingContent = {
|
|
41
|
+
type: "thinking";
|
|
42
|
+
thinking: string;
|
|
43
|
+
signature?: string;
|
|
44
|
+
redactedData?: string;
|
|
45
|
+
};
|
|
32
46
|
/**
|
|
33
47
|
* Supported image MIME types across all providers
|
|
34
48
|
*/
|
|
@@ -56,7 +70,7 @@ export type ImageBase64Content = {
|
|
|
56
70
|
/**
|
|
57
71
|
* Union of all content types
|
|
58
72
|
*/
|
|
59
|
-
export type MessageContent = TextContent | ToolUseContent | ToolResultContent | ImageUrlContent | ImageBase64Content;
|
|
73
|
+
export type MessageContent = TextContent | ToolUseContent | ToolResultContent | ThinkingContent | ImageUrlContent | ImageBase64Content;
|
|
60
74
|
/**
|
|
61
75
|
* Anthropic-specific metadata
|
|
62
76
|
*/
|
|
@@ -149,6 +163,7 @@ export type HistoryEntry = {
|
|
|
149
163
|
export declare function isTextContent(content: MessageContent): content is TextContent;
|
|
150
164
|
export declare function isToolUseContent(content: MessageContent): content is ToolUseContent;
|
|
151
165
|
export declare function isToolResultContent(content: MessageContent): content is ToolResultContent;
|
|
166
|
+
export declare function isThinkingContent(content: MessageContent): content is ThinkingContent;
|
|
152
167
|
export declare function isImageUrlContent(content: MessageContent): content is ImageUrlContent;
|
|
153
168
|
export declare function isImageBase64Content(content: MessageContent): content is ImageBase64Content;
|
|
154
169
|
export declare function isImageContent(content: MessageContent): content is ImageUrlContent | ImageBase64Content;
|
|
@@ -160,6 +175,10 @@ export declare function text(value: string): TextContent;
|
|
|
160
175
|
* Create a tool use content block
|
|
161
176
|
*/
|
|
162
177
|
export declare function toolUse(id: string, name: string, input: Record<string, unknown>): ToolUseContent;
|
|
178
|
+
/**
|
|
179
|
+
* Create a thinking content block. Pass `redactedData` for redacted thinking.
|
|
180
|
+
*/
|
|
181
|
+
export declare function thinking(thinkingText: string, signature?: string, redactedData?: string): ThinkingContent;
|
|
163
182
|
/**
|
|
164
183
|
* Create a tool result content block
|
|
165
184
|
*/
|
package/dist/history/types.js
CHANGED
|
@@ -9,11 +9,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.isTextContent = isTextContent;
|
|
10
10
|
exports.isToolUseContent = isToolUseContent;
|
|
11
11
|
exports.isToolResultContent = isToolResultContent;
|
|
12
|
+
exports.isThinkingContent = isThinkingContent;
|
|
12
13
|
exports.isImageUrlContent = isImageUrlContent;
|
|
13
14
|
exports.isImageBase64Content = isImageBase64Content;
|
|
14
15
|
exports.isImageContent = isImageContent;
|
|
15
16
|
exports.text = text;
|
|
16
17
|
exports.toolUse = toolUse;
|
|
18
|
+
exports.thinking = thinking;
|
|
17
19
|
exports.toolResult = toolResult;
|
|
18
20
|
exports.textMessage = textMessage;
|
|
19
21
|
exports.imageUrl = imageUrl;
|
|
@@ -30,6 +32,9 @@ function isToolUseContent(content) {
|
|
|
30
32
|
function isToolResultContent(content) {
|
|
31
33
|
return content.type === "tool_result";
|
|
32
34
|
}
|
|
35
|
+
function isThinkingContent(content) {
|
|
36
|
+
return content.type === "thinking";
|
|
37
|
+
}
|
|
33
38
|
function isImageUrlContent(content) {
|
|
34
39
|
return content.type === "image_url";
|
|
35
40
|
}
|
|
@@ -54,6 +59,12 @@ function text(value) {
|
|
|
54
59
|
function toolUse(id, name, input) {
|
|
55
60
|
return { type: "tool_use", id, name, input };
|
|
56
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Create a thinking content block. Pass `redactedData` for redacted thinking.
|
|
64
|
+
*/
|
|
65
|
+
function thinking(thinkingText, signature, redactedData) {
|
|
66
|
+
return { type: "thinking", thinking: thinkingText, signature, redactedData };
|
|
67
|
+
}
|
|
57
68
|
/**
|
|
58
69
|
* Create a tool result content block
|
|
59
70
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { GeminiAgent } from "./agents/google/GeminiAgent";
|
|
|
6
6
|
export { OllamaAgent } from "./agents/ollama/OllamaAgent";
|
|
7
7
|
export { LlamaCppAgent } from "./agents/llamacpp/LlamaCppAgent";
|
|
8
8
|
export { OpenAICompatibleAgent } from "./agents/openai-compatible/OpenAICompatibleAgent";
|
|
9
|
-
export type { OpenAICompatibleConfig } from "./agents/openai-compatible/OpenAICompatibleAgent";
|
|
9
|
+
export type { OpenAICompatibleConfig, StreamChunk } from "./agents/openai-compatible/OpenAICompatibleAgent";
|
|
10
10
|
export * from "./agents/model-types";
|
|
11
11
|
export * from "./agents/AgentConfig";
|
|
12
12
|
export * from "./agents/AgentEvent";
|
|
@@ -187,7 +187,7 @@ class IngestionPipeline {
|
|
|
187
187
|
await this.store.addEmbeddedDocuments(embeddedDocs);
|
|
188
188
|
result.chunksStored += embeddedDocs.length;
|
|
189
189
|
}
|
|
190
|
-
catch
|
|
190
|
+
catch {
|
|
191
191
|
// Try storing one by one to identify problematic chunks
|
|
192
192
|
for (let i = 0; i < embeddedDocs.length; i++) {
|
|
193
193
|
try {
|
package/dist/llamacpp.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from "./core";
|
|
2
2
|
export { LlamaCppAgent } from "./agents/llamacpp/LlamaCppAgent";
|
|
3
3
|
export { OpenAICompatibleAgent } from "./agents/openai-compatible/OpenAICompatibleAgent";
|
|
4
|
-
export type { OpenAICompatibleConfig } from "./agents/openai-compatible/OpenAICompatibleAgent";
|
|
4
|
+
export type { OpenAICompatibleConfig, StreamChunk } from "./agents/openai-compatible/OpenAICompatibleAgent";
|
|
5
5
|
export { chatCompletionsTransformer } from "./history/transformers";
|
|
6
6
|
//# sourceMappingURL=llamacpp.d.ts.map
|
package/dist/team/Team.js
CHANGED
|
@@ -71,16 +71,7 @@ class Team extends node_events_1.default {
|
|
|
71
71
|
* @returns The result from the lead agent
|
|
72
72
|
*/
|
|
73
73
|
async execute(input) {
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
const result = await this.leadAgent.execute(input);
|
|
77
|
-
// this.emit("teamTaskCompleted", { input, result, teamName: this.name });
|
|
78
|
-
return result;
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
// this.emit("teamTaskError", { input, error, teamName: this.name });
|
|
82
|
-
throw error;
|
|
83
|
-
}
|
|
74
|
+
return this.leadAgent.execute(input);
|
|
84
75
|
}
|
|
85
76
|
/**
|
|
86
77
|
* Get the lead agent
|
|
@@ -53,7 +53,6 @@ const CHUNK_METADATA_KEYS = [
|
|
|
53
53
|
"start", "end", "source_id", "source_path",
|
|
54
54
|
"char_count", "token_count", "hash", "section", "page",
|
|
55
55
|
];
|
|
56
|
-
const CHUNK_METADATA_KEY_SET = new Set(CHUNK_METADATA_KEYS);
|
|
57
56
|
/**
|
|
58
57
|
* LanceDB implementation of the VectorStore interface.
|
|
59
58
|
*
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentionai/agents",
|
|
3
3
|
"author": "Laurent Zuijdwijk",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"description": "Agent Library",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -87,8 +87,8 @@
|
|
|
87
87
|
"test": "jest",
|
|
88
88
|
"test:watch": "jest --watch",
|
|
89
89
|
"lint": "eslint 'lib/**/*.{js,ts}'",
|
|
90
|
-
"lint:fix": "eslint '
|
|
91
|
-
"format": "prettier --write '
|
|
90
|
+
"lint:fix": "eslint 'lib/**/*.{js,ts}' --fix",
|
|
91
|
+
"format": "prettier --write 'lib/**/*.{js,ts,json,md}'",
|
|
92
92
|
"prepare": "npm run build",
|
|
93
93
|
"example": "tsx",
|
|
94
94
|
"example:watch": "nodemon --watch examples --watch src --ext ts --exec 'ts-node --project tsconfig.esm.json' examples/index.ts",
|
|
@@ -102,7 +102,6 @@
|
|
|
102
102
|
"publish:all": "npm run publish:npm && npm run publish:github"
|
|
103
103
|
},
|
|
104
104
|
"overrides": {
|
|
105
|
-
"ajv": "^8.17.1",
|
|
106
105
|
"whatwg-url": "^14.0.0"
|
|
107
106
|
},
|
|
108
107
|
"devDependencies": {
|
|
@@ -116,12 +115,10 @@
|
|
|
116
115
|
"@mistralai/mistralai": "^1.13.0",
|
|
117
116
|
"@types/jest": "^29.5.0",
|
|
118
117
|
"@types/node": "^18.15.11",
|
|
119
|
-
"@typescript-eslint/eslint-plugin": "^5.57.1",
|
|
120
|
-
"@typescript-eslint/parser": "^5.57.1",
|
|
121
118
|
"apache-arrow": "^18.1.0",
|
|
122
119
|
"babel-jest": "^29.7.0",
|
|
123
120
|
"docdash": "^2.0.2",
|
|
124
|
-
"eslint": "^
|
|
121
|
+
"eslint": "^9.23.0",
|
|
125
122
|
"eslint-config-prettier": "^8.8.0",
|
|
126
123
|
"eslint-plugin-prettier": "^4.2.1",
|
|
127
124
|
"globals": "^16.0.0",
|