zidane 1.4.0 → 1.5.2

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.
@@ -1,7 +1,7 @@
1
1
  import { Hookable } from 'hookable';
2
2
  import { E as ExecutionContext, c as ExecutionHandle, f as SkillsConfig, d as SkillConfig } from './types-D8fzooXc.js';
3
3
  import Anthropic from '@anthropic-ai/sdk';
4
- import { M as McpServerConfig, e as TurnUsage, b as SessionMessage, C as ChildRunStats, a as AgentStats, A as AgentRunOptions, c as SessionTurn, d as ToolExecutionMode } from './types-CLRMCak3.js';
4
+ import { M as McpServerConfig, e as TurnUsage, b as SessionMessage, C as ChildRunStats, a as AgentStats, A as AgentRunOptions, c as SessionTurn, d as ToolExecutionMode } from './types-CskNDruh.js';
5
5
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
6
6
  import { Provider, StreamOptions } from './providers.js';
7
7
  import { Session } from './session.js';
@@ -240,6 +240,12 @@ interface AgentOptions {
240
240
  session?: Session;
241
241
  /** Skills configuration (merged with harness-level skills, agent takes precedence) */
242
242
  skills?: SkillsConfig;
243
+ /** Default max agent loop iterations (default: 50). Can be overridden per-run. */
244
+ maxTurns?: number;
245
+ /** Default max tokens per LLM response (default: 16384). Can be overridden per-run. */
246
+ maxTokens?: number;
247
+ /** Default thinking token budget — overrides the level-based default when set. Can be overridden per-run. */
248
+ thinkingBudget?: number;
243
249
  /** @internal */
244
250
  _mcpConnector?: (configs: McpServerConfig[]) => Promise<McpConnection>;
245
251
  }
@@ -260,6 +266,6 @@ interface Agent {
260
266
  readonly session: Session | null;
261
267
  meta: Record<string, unknown>;
262
268
  }
263
- declare function createAgent({ harness: harnessOption, provider, toolExecution, enableTools, execution, mcpServers, session, skills: agentSkills, _mcpConnector }: AgentOptions): Agent;
269
+ declare function createAgent({ harness: harnessOption, provider, toolExecution, enableTools, execution, mcpServers, session, skills: agentSkills, maxTurns: agentMaxTurns, maxTokens: agentMaxTokens, thinkingBudget: agentThinkingBudget, _mcpConnector }: AgentOptions): Agent;
264
270
 
265
271
  export { type Agent as A, type Harness as H, type McpConnection as M, type ToolContext as T, _default as _, type AgentHooks as a, type AgentOptions as b, type HarnessConfig as c, type ToolDef as d, type ToolMap as e, connectMcpServers as f, createAgent as g, defineHarness as h, basicTools as i, noTools as n, resultToString as r };
@@ -438,7 +438,7 @@ async function runLoop(ctx) {
438
438
  let totalOut = 0;
439
439
  const turnUsages = [];
440
440
  const startTime = Date.now();
441
- const maxTurns = 50;
441
+ const maxTurns = ctx.maxTurns ?? 50;
442
442
  for (let turn = 0; turn < maxTurns; turn++) {
443
443
  if (ctx.signal.aborted) {
444
444
  await ctx.hooks.callHook("agent:abort", {});
@@ -477,7 +477,9 @@ async function runLoop(ctx) {
477
477
  });
478
478
  continue;
479
479
  }
480
- return { totalIn, totalOut, turns: turn + 1, elapsed: Date.now() - startTime, turnUsage: turnUsages };
480
+ const stats2 = { totalIn, totalOut, turns: turn + 1, elapsed: Date.now() - startTime, turnUsage: turnUsages };
481
+ await ctx.hooks.callHook("agent:done", stats2);
482
+ return stats2;
481
483
  }
482
484
  }
483
485
  const stats = { totalIn, totalOut, turns: maxTurns, elapsed: Date.now() - startTime, turnUsage: turnUsages };
@@ -492,23 +494,30 @@ async function executeTurn(ctx, turn) {
492
494
  system: ctx.system,
493
495
  tools: ctx.formattedTools,
494
496
  messages,
495
- maxTokens: 16384,
497
+ maxTokens: ctx.maxTokens ?? 16384,
496
498
  thinking: ctx.thinking,
499
+ thinkingBudget: ctx.thinkingBudget,
497
500
  signal: ctx.signal
498
501
  };
499
502
  await ctx.hooks.callHook("context:transform", { messages });
500
503
  await ctx.hooks.callHook("turn:before", { turn, turnId, options: streamOptions });
501
504
  let currentText = "";
502
505
  let blockIndex = 0;
503
- const result = await ctx.provider.stream(
504
- streamOptions,
505
- {
506
- onText(delta) {
507
- currentText += delta;
508
- ctx.hooks.callHook("stream:text", { delta, text: currentText, turnId, blockIndex });
506
+ let result;
507
+ try {
508
+ result = await ctx.provider.stream(
509
+ streamOptions,
510
+ {
511
+ onText(delta) {
512
+ currentText += delta;
513
+ ctx.hooks.callHook("stream:text", { delta, text: currentText, turnId, blockIndex });
514
+ }
509
515
  }
510
- }
511
- );
516
+ );
517
+ } catch (err) {
518
+ await ctx.hooks.callHook("turn:after", { turn, turnId, usage: { input: 0, output: 0 } });
519
+ throw err;
520
+ }
512
521
  if (currentText) {
513
522
  await ctx.hooks.callHook("stream:end", { text: currentText, turnId, blockIndex });
514
523
  blockIndex++;
@@ -628,7 +637,7 @@ var init_loop = __esm({
628
637
 
629
638
  // src/agent.ts
630
639
  import { createHooks } from "hookable";
631
- function createAgent({ harness: harnessOption, provider, toolExecution = "sequential", enableTools = true, execution, mcpServers, session, skills: agentSkills, _mcpConnector }) {
640
+ function createAgent({ harness: harnessOption, provider, toolExecution = "sequential", enableTools = true, execution, mcpServers, session, skills: agentSkills, maxTurns: agentMaxTurns, maxTokens: agentMaxTokens, thinkingBudget: agentThinkingBudget, _mcpConnector }) {
632
641
  const hooks = createHooks();
633
642
  const harness = harnessOption ?? noTools;
634
643
  const executionContext = execution ?? createProcessContext();
@@ -720,6 +729,9 @@ function createAgent({ harness: harnessOption, provider, toolExecution = "sequen
720
729
  }
721
730
  const thinking = options.thinking ?? "off";
722
731
  const model = options.model ?? provider.meta.defaultModel;
732
+ const maxTurns = options.maxTurns ?? agentMaxTurns;
733
+ const maxTokens = options.maxTokens ?? agentMaxTokens;
734
+ const thinkingBudget = options.thinkingBudget ?? agentThinkingBudget;
723
735
  let system = options.system || harness.system || "You are a helpful assistant.";
724
736
  if (skillsCatalog) {
725
737
  system = `${system}
@@ -796,7 +808,10 @@ ${skillsCatalog}`;
796
808
  steeringQueue,
797
809
  followUpQueue,
798
810
  turns,
799
- generateTurnId: () => session?.generateTurnId() ?? crypto.randomUUID()
811
+ generateTurnId: () => session?.generateTurnId() ?? crypto.randomUUID(),
812
+ maxTurns,
813
+ maxTokens,
814
+ thinkingBudget
800
815
  });
801
816
  const finalStats = {
802
817
  ...stats,
@@ -814,7 +829,7 @@ ${skillsCatalog}`;
814
829
  await hooks.callHook("agent:done", finalStats);
815
830
  return finalStats;
816
831
  }
817
- const totalCost = finalStats.turnUsage?.reduce((sum, t) => sum + (t.cost ?? 0), 0) || void 0;
832
+ const totalCost = finalStats.turnUsage?.reduce((sum, t) => sum + (t.cost ?? 0), 0);
818
833
  if (totalCost)
819
834
  finalStats.cost = totalCost;
820
835
  const finalNewTurns = turns.slice(lastPersistedTurnCount);
@@ -322,13 +322,20 @@ async function createSession(options = {}) {
322
322
  run.tokensOut = stats.tokensOut;
323
323
  if (stats.turnUsage) {
324
324
  run.turnUsage = stats.turnUsage;
325
- run.totalUsage = stats.turnUsage.reduce((acc, t) => ({
325
+ const total = stats.turnUsage.reduce((acc, t) => ({
326
326
  input: acc.input + t.input,
327
327
  output: acc.output + t.output,
328
- cacheCreation: (acc.cacheCreation ?? 0) + (t.cacheCreation ?? 0) || void 0,
329
- cacheRead: (acc.cacheRead ?? 0) + (t.cacheRead ?? 0) || void 0,
330
- thinking: (acc.thinking ?? 0) + (t.thinking ?? 0) || void 0
331
- }), { input: 0, output: 0 });
328
+ cacheCreation: (acc.cacheCreation ?? 0) + (t.cacheCreation ?? 0),
329
+ cacheRead: (acc.cacheRead ?? 0) + (t.cacheRead ?? 0),
330
+ thinking: (acc.thinking ?? 0) + (t.thinking ?? 0)
331
+ }), { input: 0, output: 0, cacheCreation: 0, cacheRead: 0, thinking: 0 });
332
+ run.totalUsage = {
333
+ input: total.input,
334
+ output: total.output,
335
+ ...total.cacheCreation ? { cacheCreation: total.cacheCreation } : {},
336
+ ...total.cacheRead ? { cacheRead: total.cacheRead } : {},
337
+ ...total.thinking ? { thinking: total.thinking } : {}
338
+ };
332
339
  }
333
340
  if (stats.cost !== void 0)
334
341
  run.cost = stats.cost;
@@ -1,8 +1,8 @@
1
1
  import '@anthropic-ai/sdk';
2
2
  import 'hookable';
3
- export { H as Harness, c as HarnessConfig, T as ToolContext, d as ToolDef, e as ToolMap, _ as basic, i as basicTools, h as defineHarness, n as noTools } from './agent-B4wguzkU.js';
3
+ export { H as Harness, c as HarnessConfig, T as ToolContext, d as ToolDef, e as ToolMap, _ as basic, i as basicTools, h as defineHarness, n as noTools } from './agent-DZDheE1c.js';
4
4
  import './types-D8fzooXc.js';
5
5
  import './providers.js';
6
- import './types-CLRMCak3.js';
6
+ import './types-CskNDruh.js';
7
7
  import '@modelcontextprotocol/sdk/client/index.js';
8
8
  import './session.js';
package/dist/harnesses.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  defineHarness,
5
5
  init_harnesses,
6
6
  noTools
7
- } from "./chunk-YCH7G7YC.js";
7
+ } from "./chunk-XMFQK35S.js";
8
8
  import "./chunk-26LIQARN.js";
9
9
  import "./chunk-PRNQ7DXE.js";
10
10
  import "./chunk-PNKVD2UK.js";
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- export { A as Agent, a as AgentHooks, b as AgentOptions, H as Harness, c as HarnessConfig, M as McpConnection, T as ToolContext, d as ToolDef, e as ToolMap, f as connectMcpServers, g as createAgent, h as defineHarness, n as noTools } from './agent-B4wguzkU.js';
1
+ export { A as Agent, a as AgentHooks, b as AgentOptions, H as Harness, c as HarnessConfig, M as McpConnection, T as ToolContext, d as ToolDef, e as ToolMap, f as connectMcpServers, g as createAgent, h as defineHarness, n as noTools } from './agent-DZDheE1c.js';
2
2
  import { S as SpawnConfig, E as ExecutionContext, a as ExecResult } from './types-D8fzooXc.js';
3
3
  export { C as ContextCapabilities, b as ContextType, c as ExecutionHandle, d as SkillConfig, e as SkillResource, f as SkillsConfig } from './types-D8fzooXc.js';
4
4
  export { CreateSessionOptions, RemoteStoreOptions, Session, SessionData, SessionRun, SessionStore, SqliteStoreOptions, autoDetectAndConvert, createMemoryStore, createRemoteStore, createSession, createSqliteStore, fromAnthropic, fromOpenAI, loadSession, toAnthropic, toOpenAI } from './session.js';
5
5
  export { buildCatalog, defineSkill, discoverSkills, interpolateShellCommands, mergeSkillsConfig, parseSkillFile, resolveSkills, validateSkillName, writeSkillToDisk, writeSkillsToDisk } from './skills.js';
6
- export { C as ChildAgent, S as SpawnToolOptions, a as SpawnToolState, c as createSpawnTool, s as spawn } from './spawn-vZAQfDkd.js';
7
- export { A as AgentRunOptions, a as AgentStats, I as ImageContent, M as McpServerConfig, S as SessionContentBlock, b as SessionMessage, c as SessionTurn, T as ThinkingLevel, d as ToolExecutionMode, e as TurnUsage } from './types-CLRMCak3.js';
6
+ export { C as ChildAgent, S as SpawnToolOptions, a as SpawnToolState, c as createSpawnTool, s as spawn } from './spawn-MUlKj85h.js';
7
+ export { A as AgentRunOptions, a as AgentStats, I as ImageContent, M as McpServerConfig, S as SessionContentBlock, b as SessionMessage, c as SessionTurn, T as ThinkingLevel, d as ToolExecutionMode, e as TurnUsage } from './types-CskNDruh.js';
8
8
  import 'hookable';
9
9
  import '@anthropic-ai/sdk';
10
10
  import '@modelcontextprotocol/sdk/client/index.js';
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  init_tools,
12
12
  noTools,
13
13
  spawn
14
- } from "./chunk-YCH7G7YC.js";
14
+ } from "./chunk-XMFQK35S.js";
15
15
  import {
16
16
  connectMcpServers,
17
17
  init_mcp
@@ -22,7 +22,7 @@ import {
22
22
  createSession,
23
23
  createSqliteStore,
24
24
  loadSession
25
- } from "./chunk-IC2WAUBZ.js";
25
+ } from "./chunk-ZH2KFHLB.js";
26
26
  import {
27
27
  autoDetectAndConvert,
28
28
  fromAnthropic,
package/dist/mcp.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import 'hookable';
2
- export { M as McpConnection, f as connectMcpServers, r as resultToString } from './agent-B4wguzkU.js';
3
- export { M as McpServerConfig } from './types-CLRMCak3.js';
2
+ export { M as McpConnection, f as connectMcpServers, r as resultToString } from './agent-DZDheE1c.js';
3
+ export { M as McpServerConfig } from './types-CskNDruh.js';
4
4
  import '@modelcontextprotocol/sdk/client/index.js';
5
5
  import './types-D8fzooXc.js';
6
6
  import '@anthropic-ai/sdk';
@@ -1,4 +1,4 @@
1
- import { b as SessionMessage, T as ThinkingLevel, I as ImageContent, e as TurnUsage } from './types-CLRMCak3.js';
1
+ import { b as SessionMessage, T as ThinkingLevel, I as ImageContent, e as TurnUsage } from './types-CskNDruh.js';
2
2
 
3
3
  interface AnthropicParams {
4
4
  apiKey?: string;
@@ -57,6 +57,8 @@ interface StreamOptions {
57
57
  maxTokens: number;
58
58
  /** Thinking/reasoning level (optional, default: off) */
59
59
  thinking?: ThinkingLevel;
60
+ /** Exact thinking token budget — overrides the level-based default when set */
61
+ thinkingBudget?: number;
60
62
  /** Abort signal for cancellation */
61
63
  signal?: AbortSignal;
62
64
  }
package/dist/providers.js CHANGED
@@ -98,14 +98,14 @@ function anthropic(anthropicParams) {
98
98
  const thinking = options.thinking ?? "off";
99
99
  const params = {
100
100
  model: options.model,
101
- max_tokens: options.maxTokens ?? 16384,
101
+ max_tokens: options.maxTokens,
102
102
  system,
103
103
  tools: options.tools,
104
104
  messages: messages.map((m) => toAnthropic(m)),
105
105
  stream: true
106
106
  };
107
107
  if (thinking !== "off") {
108
- const budgetTokens = THINKING_BUDGETS[thinking];
108
+ const budgetTokens = options.thinkingBudget ?? THINKING_BUDGETS[thinking];
109
109
  params.thinking = {
110
110
  type: "enabled",
111
111
  budget_tokens: budgetTokens
package/dist/session.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { b as SessionMessage, c as SessionTurn, e as TurnUsage } from './types-CLRMCak3.js';
2
- export { S as SessionContentBlock } from './types-CLRMCak3.js';
1
+ import { b as SessionMessage, c as SessionTurn, e as TurnUsage } from './types-CskNDruh.js';
2
+ export { S as SessionContentBlock } from './types-CskNDruh.js';
3
3
 
4
4
  /**
5
5
  * In-memory session store.
package/dist/session.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  createSession,
5
5
  createSqliteStore,
6
6
  loadSession
7
- } from "./chunk-IC2WAUBZ.js";
7
+ } from "./chunk-ZH2KFHLB.js";
8
8
  import {
9
9
  autoDetectAndConvert,
10
10
  fromAnthropic,
@@ -1,5 +1,5 @@
1
- import { c as HarnessConfig, d as ToolDef } from './agent-B4wguzkU.js';
2
- import { a as AgentStats } from './types-CLRMCak3.js';
1
+ import { c as HarnessConfig, d as ToolDef } from './agent-DZDheE1c.js';
2
+ import { a as AgentStats } from './types-CskNDruh.js';
3
3
 
4
4
  /**
5
5
  * Spawn tool — create sub-agents from a parent agent.
package/dist/tools.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { d as ToolDef } from './agent-B4wguzkU.js';
2
- export { C as ChildAgent, S as SpawnToolOptions, a as SpawnToolState, c as createSpawnTool, s as spawn } from './spawn-vZAQfDkd.js';
1
+ import { d as ToolDef } from './agent-DZDheE1c.js';
2
+ export { C as ChildAgent, S as SpawnToolOptions, a as SpawnToolState, c as createSpawnTool, s as spawn } from './spawn-MUlKj85h.js';
3
3
  import 'hookable';
4
4
  import './types-D8fzooXc.js';
5
5
  import '@anthropic-ai/sdk';
6
- import './types-CLRMCak3.js';
6
+ import './types-CskNDruh.js';
7
7
  import '@modelcontextprotocol/sdk/client/index.js';
8
8
  import './providers.js';
9
9
  import './session.js';
package/dist/tools.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  spawn,
8
8
  validateToolArgs,
9
9
  writeFile
10
- } from "./chunk-YCH7G7YC.js";
10
+ } from "./chunk-XMFQK35S.js";
11
11
  import "./chunk-26LIQARN.js";
12
12
  import "./chunk-PRNQ7DXE.js";
13
13
  import "./chunk-PNKVD2UK.js";
@@ -70,6 +70,12 @@ interface AgentRunOptions {
70
70
  images?: ImageContent[];
71
71
  /** Abort signal — when triggered, the agent stops after the current turn */
72
72
  signal?: AbortSignal;
73
+ /** Maximum agent loop iterations for this run (overrides agent-level default, default: 50) */
74
+ maxTurns?: number;
75
+ /** Maximum tokens per LLM response for this run (overrides agent-level default, default: 16384) */
76
+ maxTokens?: number;
77
+ /** Exact thinking token budget — overrides the level-based default when set */
78
+ thinkingBudget?: number;
73
79
  }
74
80
  interface TurnUsage {
75
81
  input: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zidane",
3
- "version": "1.4.0",
3
+ "version": "1.5.2",
4
4
  "description": "an agent that goes straight to the goal",
5
5
  "type": "module",
6
6
  "private": false,