@agentionai/agents 0.14.0 → 1.0.1
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 +73 -13
- 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 +195 -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
|
@@ -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 (`reasoning` on OpenRouter, `reasoning_content` on DeepSeek/llama.cpp)
|
|
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,201 @@ 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
|
+
// Reasoning tokens (not in OpenAI SDK types — cast required). Servers
|
|
344
|
+
// disagree on the field name: OpenRouter sends `delta.reasoning`, while
|
|
345
|
+
// DeepSeek/llama.cpp send `delta.reasoning_content`. Prefer `reasoning`;
|
|
346
|
+
// never concatenate — that would duplicate the text if both were sent.
|
|
347
|
+
const deltaExtras = delta;
|
|
348
|
+
const reasoningDelta = (deltaExtras.reasoning ?? deltaExtras.reasoning_content);
|
|
349
|
+
if (reasoningDelta) {
|
|
350
|
+
this.emit(AgentEvent_1.AgentEvent.REASONING_CHUNK, reasoningDelta);
|
|
351
|
+
yield { type: "reasoning", content: reasoningDelta };
|
|
352
|
+
}
|
|
353
|
+
if (delta.tool_calls) {
|
|
354
|
+
for (const tc of delta.tool_calls) {
|
|
355
|
+
if (!toolCallAcc.has(tc.index)) {
|
|
356
|
+
toolCallAcc.set(tc.index, { id: "", name: "", arguments: "" });
|
|
357
|
+
}
|
|
358
|
+
const acc = toolCallAcc.get(tc.index);
|
|
359
|
+
if (tc.id)
|
|
360
|
+
acc.id = tc.id;
|
|
361
|
+
if (tc.function?.name)
|
|
362
|
+
acc.name += tc.function.name;
|
|
363
|
+
if (tc.function?.arguments)
|
|
364
|
+
acc.arguments += tc.function.arguments;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (finishReason === "length") {
|
|
369
|
+
const error = new AgentError_1.MaxTokensExceededError("Response exceeded maximum token limit", this.config.maxTokens || 1024);
|
|
370
|
+
this.emit(AgentEvent_1.AgentEvent.MAX_TOKENS_EXCEEDED, error);
|
|
371
|
+
this.emit(AgentEvent_1.AgentEvent.ERROR, error);
|
|
372
|
+
if (this.vizEventId) {
|
|
373
|
+
VizReporter_1.vizReporter.agentError(this.vizEventId, "MaxTokensExceededError", error.message, false);
|
|
374
|
+
this.vizEventId = undefined;
|
|
375
|
+
}
|
|
376
|
+
throw error;
|
|
377
|
+
}
|
|
378
|
+
if (finishReason === "tool_calls" && toolCallAcc.size > 0) {
|
|
379
|
+
const toolCalls = Array.from(toolCallAcc.entries())
|
|
380
|
+
.sort(([a], [b]) => a - b)
|
|
381
|
+
.map(([, tc]) => ({
|
|
382
|
+
id: tc.id,
|
|
383
|
+
type: "function",
|
|
384
|
+
function: { name: tc.name, arguments: tc.arguments },
|
|
385
|
+
}));
|
|
386
|
+
this.emit(AgentEvent_1.AgentEvent.TOOL_USE, toolCalls);
|
|
387
|
+
this.currentToolCallCount += toolCalls.length;
|
|
388
|
+
const assistantEntry = transformers_1.chatCompletionsTransformer.fromProviderMessage({
|
|
389
|
+
role: "assistant",
|
|
390
|
+
content: textContent || null,
|
|
391
|
+
tool_calls: toolCalls,
|
|
392
|
+
});
|
|
393
|
+
this.addToHistory(assistantEntry);
|
|
394
|
+
const toolResults = await this.handleToolCalls(toolCalls);
|
|
395
|
+
for (const result of toolResults) {
|
|
396
|
+
this.addToHistory(transformers_1.chatCompletionsTransformer.toolResultEntry(result.toolCallId, result.content));
|
|
397
|
+
}
|
|
398
|
+
yield* this.streamTurn();
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
const assistantEntry = transformers_1.chatCompletionsTransformer.fromProviderMessage({
|
|
402
|
+
role: "assistant",
|
|
403
|
+
content: textContent || null,
|
|
404
|
+
});
|
|
405
|
+
this.addToHistory(assistantEntry);
|
|
406
|
+
this.emit(AgentEvent_1.AgentEvent.DONE, { content: textContent }, this.lastTokenUsage);
|
|
407
|
+
if (this.vizEventId) {
|
|
408
|
+
VizReporter_1.vizReporter.agentComplete(this.vizEventId, {
|
|
409
|
+
input: this.lastTokenUsage?.input_tokens || 0,
|
|
410
|
+
output: this.lastTokenUsage?.output_tokens || 0,
|
|
411
|
+
total: this.lastTokenUsage?.total_tokens || 0,
|
|
412
|
+
}, "end_turn", this.currentToolCallCount > 0, this.currentToolCallCount, textContent);
|
|
413
|
+
this.vizEventId = undefined;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
accumulateStreamUsage(usage) {
|
|
418
|
+
if (!usage)
|
|
419
|
+
return;
|
|
420
|
+
const u = {
|
|
421
|
+
input_tokens: usage.prompt_tokens ?? 0,
|
|
422
|
+
output_tokens: usage.completion_tokens ?? 0,
|
|
423
|
+
total_tokens: usage.total_tokens ?? 0,
|
|
424
|
+
};
|
|
425
|
+
if (this.lastTokenUsage) {
|
|
426
|
+
this.lastTokenUsage.input_tokens += u.input_tokens;
|
|
427
|
+
this.lastTokenUsage.output_tokens += u.output_tokens;
|
|
428
|
+
this.lastTokenUsage.total_tokens += u.total_tokens;
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
this.lastTokenUsage = u;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
239
434
|
parseUsage(response) {
|
|
240
435
|
const usage = response.usage;
|
|
241
436
|
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
|
*
|