@agentionai/agents 1.2.0 → 1.3.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.
@@ -56,6 +56,14 @@ export type TokenUsage = {
56
56
  * Generation throughput: `output_tokens` over `generationMs`. Falls back to
57
57
  * `totalMs` when the first-token time is unknown (an unstreamed call), in
58
58
  * which case it is an end-to-end rate rather than a pure generation rate.
59
+ *
60
+ * Accurate wherever thinking is streamed, because the first thinking chunk
61
+ * starts the generation window — verified on Anthropic extended thinking and
62
+ * on DeepSeek via OpenRouter. It over-reports on OpenAI's Responses API,
63
+ * which does not stream raw reasoning: there the thinking finishes before the
64
+ * first visible token, so it lands inside `timeToFirstTokenMs` while its
65
+ * tokens still count toward `output_tokens`. For the visible-output rate on
66
+ * that path, divide `output_tokens - reasoning_tokens` by `generationMs`.
59
67
  */
60
68
  outputTokensPerSecond?: number;
61
69
  };
@@ -43,7 +43,7 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
43
43
  ? { authToken: config.apiKey }
44
44
  : { apiKey: config.apiKey });
45
45
  this.config = {
46
- model: config.model || "claude-3-5-haiku-latest",
46
+ model: config.model || "claude-haiku-4-5",
47
47
  maxTokens: config.maxTokens || 1024,
48
48
  disableParallelToolUse,
49
49
  metadata,
@@ -35,7 +35,7 @@ class GeminiAgent extends BaseAgent_1.BaseAgent {
35
35
  const responseMimeType = config.responseMimeType ?? vendorConfig.responseMimeType;
36
36
  const responseSchema = config.responseSchema ?? vendorConfig.responseSchema;
37
37
  this.config = {
38
- model: config.model || "gemini-2.0-flash",
38
+ model: config.model || "gemini-flash-latest",
39
39
  maxTokens: config.maxTokens || 1024,
40
40
  apiKey: config.apiKey,
41
41
  temperature: config.temperature,
@@ -8,19 +8,19 @@
8
8
  * You can also provide any custom string for newer models not yet listed.
9
9
  * @see https://docs.anthropic.com/en/docs/about-claude/models
10
10
  */
11
- export type ClaudeModel = "claude-opus-4-7" | "claude-opus-4-6" | "claude-sonnet-4-6" | "claude-opus-4-5" | "claude-sonnet-4-5" | "claude-haiku-4-5" | "claude-haiku-4-5-20251001" | (string & Record<never, never>);
11
+ export type ClaudeModel = "claude-opus-5" | "claude-sonnet-5" | "claude-fable-5" | "claude-opus-4-8" | "claude-opus-4-7" | "claude-opus-4-6" | "claude-sonnet-4-6" | "claude-opus-4-5" | "claude-opus-4-5-20251101" | "claude-sonnet-4-5" | "claude-sonnet-4-5-20250929" | "claude-haiku-4-5" | "claude-haiku-4-5-20251001" | (string & Record<never, never>);
12
12
  /**
13
13
  * Supported Google Gemini models.
14
14
  * You can also provide any custom string for newer models not yet listed.
15
15
  * @see https://ai.google.dev/gemini-api/docs/models/gemini
16
16
  */
17
- export type GeminiModel = "gemini-flash-latest" | "gemini-flash-lite-latest" | "gemini-3.0-pro" | "gemini-3.0-flash" | "gemini-2.5-flash-lite" | "gemini-2.0-flash-exp" | "gemini-2.0-flash" | "gemini-2.0-flash-lite" | (string & {});
17
+ export type GeminiModel = "gemini-pro-latest" | "gemini-flash-latest" | "gemini-flash-lite-latest" | "gemini-3.6-flash" | "gemini-3.5-flash" | "gemini-3.5-flash-lite" | "gemini-3.1-pro-preview" | "gemini-3.1-flash-lite" | "gemini-3.1-flash-lite-preview" | "gemini-3-pro-preview" | "gemini-3-flash-preview" | "gemini-2.5-pro" | "gemini-2.5-flash" | "gemini-2.5-flash-lite" | "gemini-2.0-flash" | "gemini-2.0-flash-001" | "gemini-2.0-flash-lite" | "gemini-2.0-flash-lite-001" | (string & {});
18
18
  /**
19
19
  * Supported Mistral models.
20
20
  * You can also provide any custom string for newer models not yet listed.
21
21
  * @see https://docs.mistral.ai/getting-started/models/
22
22
  */
23
- export type MistralModel = "mistral-large-latest" | "mistral-small-latest" | "ministral-8b-latest" | "ministral-8b-2410" | "ministral-3b-latest" | "ministral-3b-2410" | "codestral-latest" | "codestral-2405" | "mistral-embed" | "mistral-moderation-latest" | "mistral-moderation-2411" | (string & {});
23
+ export type MistralModel = "mistral-large-latest" | "mistral-large-2512" | "mistral-medium-latest" | "mistral-medium-3.5" | "mistral-small-latest" | "mistral-small-2603" | "magistral-small-latest" | "ministral-14b-latest" | "ministral-8b-latest" | "ministral-8b-2512" | "ministral-3b-latest" | "ministral-3b-2512" | "codestral-latest" | "codestral-2508" | "devstral-latest" | "devstral-medium-latest" | "mistral-embed" | "codestral-embed" | "mistral-moderation-latest" | "mistral-moderation-2603" | "mistral-ocr-latest" | (string & {});
24
24
  /**
25
25
  * Popular Ollama models (locally hosted).
26
26
  * You can also provide any custom string for models you have pulled.
@@ -320,13 +320,17 @@ class OpenAICompatibleAgent extends BaseAgent_1.BaseAgent {
320
320
  let reasoningContent = "";
321
321
  const toolCallAcc = new Map();
322
322
  let finishReason = null;
323
+ let streamUsage;
323
324
  for await (const chunk of stream) {
324
- // Final chunk carrying usage (choices is empty)
325
- if (chunk.choices.length === 0) {
326
- if (chunk.usage)
327
- this.accumulateStreamUsage(chunk.usage);
325
+ // Usage can ride on any chunk: OpenAI sends it on a final choice-less
326
+ // chunk, OpenRouter attaches it to the last content chunk (the one
327
+ // carrying finish_reason). Keep the most recent and fold it in once the
328
+ // stream ends — it is a running total for the turn, not a delta, so
329
+ // taking the last one covers both layouts without double-counting.
330
+ if (chunk.usage)
331
+ streamUsage = chunk.usage;
332
+ if (chunk.choices.length === 0)
328
333
  continue;
329
- }
330
334
  const choice = chunk.choices[0];
331
335
  finishReason = choice.finish_reason ?? finishReason;
332
336
  const delta = choice.delta;
@@ -366,6 +370,10 @@ class OpenAICompatibleAgent extends BaseAgent_1.BaseAgent {
366
370
  }
367
371
  }
368
372
  }
373
+ // Before any early return below, so a turn that hits the token limit or
374
+ // continues into a tool call still reports what it spent.
375
+ if (streamUsage)
376
+ this.accumulateStreamUsage(streamUsage);
369
377
  if (finishReason === "length") {
370
378
  const error = new AgentError_1.MaxTokensExceededError("Response exceeded maximum token limit", this.config.maxTokens || 1024);
371
379
  this.emit(AgentEvent_1.AgentEvent.MAX_TOKENS_EXCEEDED, error);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agentionai/agents",
3
3
  "author": "Laurent Zuijdwijk",
4
- "version": "1.2.0",
4
+ "version": "1.3.0",
5
5
  "description": "Agent Library",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",