zidane 4.0.2 → 4.1.3

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.
Files changed (77) hide show
  1. package/README.md +196 -614
  2. package/dist/agent-BoV5Twdl.d.ts +2347 -0
  3. package/dist/agent-BoV5Twdl.d.ts.map +1 -0
  4. package/dist/contexts-3Arvn7yR.js +321 -0
  5. package/dist/contexts-3Arvn7yR.js.map +1 -0
  6. package/dist/contexts.d.ts +2 -25
  7. package/dist/contexts.js +2 -10
  8. package/dist/errors-D1lhd6mX.js +118 -0
  9. package/dist/errors-D1lhd6mX.js.map +1 -0
  10. package/dist/index-28otmfLX.d.ts +400 -0
  11. package/dist/index-28otmfLX.d.ts.map +1 -0
  12. package/dist/index-BfSdALzk.d.ts +113 -0
  13. package/dist/index-BfSdALzk.d.ts.map +1 -0
  14. package/dist/index-DPsd0qwm.d.ts +254 -0
  15. package/dist/index-DPsd0qwm.d.ts.map +1 -0
  16. package/dist/index.d.ts +5 -95
  17. package/dist/index.js +141 -271
  18. package/dist/index.js.map +1 -0
  19. package/dist/interpolate-CukJwP2G.js +887 -0
  20. package/dist/interpolate-CukJwP2G.js.map +1 -0
  21. package/dist/mcp-8wClKY-3.js +771 -0
  22. package/dist/mcp-8wClKY-3.js.map +1 -0
  23. package/dist/mcp.d.ts +2 -4
  24. package/dist/mcp.js +2 -13
  25. package/dist/messages-z5Pq20p7.js +1020 -0
  26. package/dist/messages-z5Pq20p7.js.map +1 -0
  27. package/dist/presets-Cs7_CsMk.js +39 -0
  28. package/dist/presets-Cs7_CsMk.js.map +1 -0
  29. package/dist/presets.d.ts +2 -43
  30. package/dist/presets.js +2 -17
  31. package/dist/providers-CX-R-Oy-.js +969 -0
  32. package/dist/providers-CX-R-Oy-.js.map +1 -0
  33. package/dist/providers.d.ts +2 -4
  34. package/dist/providers.js +3 -23
  35. package/dist/session/sqlite.d.ts +7 -12
  36. package/dist/session/sqlite.d.ts.map +1 -0
  37. package/dist/session/sqlite.js +67 -79
  38. package/dist/session/sqlite.js.map +1 -0
  39. package/dist/session-Cn68UASv.js +440 -0
  40. package/dist/session-Cn68UASv.js.map +1 -0
  41. package/dist/session.d.ts +2 -4
  42. package/dist/session.js +3 -27
  43. package/dist/skills.d.ts +3 -322
  44. package/dist/skills.js +24 -47
  45. package/dist/skills.js.map +1 -0
  46. package/dist/stats-DoKUtF5T.js +58 -0
  47. package/dist/stats-DoKUtF5T.js.map +1 -0
  48. package/dist/tools-DpeWKzP1.js +3941 -0
  49. package/dist/tools-DpeWKzP1.js.map +1 -0
  50. package/dist/tools.d.ts +3 -95
  51. package/dist/tools.js +2 -40
  52. package/dist/tui.d.ts +533 -0
  53. package/dist/tui.d.ts.map +1 -0
  54. package/dist/tui.js +2004 -0
  55. package/dist/tui.js.map +1 -0
  56. package/dist/types-Bx_F8jet.js +39 -0
  57. package/dist/types-Bx_F8jet.js.map +1 -0
  58. package/dist/types.d.ts +4 -55
  59. package/dist/types.js +4 -28
  60. package/package.json +38 -4
  61. package/dist/agent-BAHrGtqu.d.ts +0 -2425
  62. package/dist/chunk-4ILGBQ23.js +0 -803
  63. package/dist/chunk-4LPBN547.js +0 -3540
  64. package/dist/chunk-64LLNY7F.js +0 -28
  65. package/dist/chunk-6STZTA4N.js +0 -830
  66. package/dist/chunk-7GQ7P6DM.js +0 -566
  67. package/dist/chunk-IC7FT4OD.js +0 -37
  68. package/dist/chunk-JCOB6IYO.js +0 -22
  69. package/dist/chunk-JH6IAAFA.js +0 -28
  70. package/dist/chunk-LNN5UTS2.js +0 -97
  71. package/dist/chunk-PMCQOMV4.js +0 -490
  72. package/dist/chunk-UD25QF3H.js +0 -304
  73. package/dist/chunk-W57VY6DJ.js +0 -834
  74. package/dist/sandbox-D7v6Wy62.d.ts +0 -28
  75. package/dist/skills-use-DwZrNmcw.d.ts +0 -80
  76. package/dist/types-Bai5rKpa.d.ts +0 -89
  77. package/dist/validation-Pm--dQEU.d.ts +0 -185
package/dist/index.js CHANGED
@@ -1,275 +1,145 @@
1
- import {
2
- defineSkill
3
- } from "./chunk-JCOB6IYO.js";
4
- import {
5
- anthropic,
6
- cerebras,
7
- openai,
8
- openrouter
9
- } from "./chunk-W57VY6DJ.js";
10
- import {
11
- basicTools,
12
- basic_default,
13
- definePreset
14
- } from "./chunk-64LLNY7F.js";
15
- import {
16
- createAgent,
17
- createInteractionTool,
18
- createSkillsReadTool,
19
- createSkillsRunScriptTool,
20
- createSkillsUseTool,
21
- createSpawnTool,
22
- edit,
23
- glob,
24
- grep,
25
- multiEdit,
26
- validateToolArgs
27
- } from "./chunk-4LPBN547.js";
28
- import {
29
- IMPLICITLY_ALLOWED_SKILL_TOOLS,
30
- buildCatalog,
31
- createSkillActivationState,
32
- discoverSkills,
33
- installAllowedToolsGate,
34
- interpolateShellCommands,
35
- isToolAllowedByUnion,
36
- matchesAllowedTool,
37
- parseAllowedToolPattern,
38
- parseSkillFile,
39
- resolveSkills,
40
- validateResourcePath,
41
- validateSkillForWrite,
42
- validateSkillName,
43
- writeSkillToDisk,
44
- writeSkillsToDisk
45
- } from "./chunk-6STZTA4N.js";
46
- import {
47
- flattenTurns,
48
- statsByModel
49
- } from "./chunk-IC7FT4OD.js";
50
- import {
51
- createDockerContext,
52
- createProcessContext,
53
- createSandboxContext
54
- } from "./chunk-UD25QF3H.js";
55
- import {
56
- connectMcpServers,
57
- normalizeMcpBlocks,
58
- normalizeMcpServers,
59
- resultToString
60
- } from "./chunk-7GQ7P6DM.js";
61
- import {
62
- toolOutputByteLength,
63
- toolResultToText
64
- } from "./chunk-JH6IAAFA.js";
65
- import {
66
- createFileMapStore,
67
- createMemoryStore,
68
- createRemoteStore,
69
- createSession,
70
- loadSession
71
- } from "./chunk-PMCQOMV4.js";
72
- import {
73
- OpenAICompatHttpError,
74
- autoDetectAndConvert,
75
- classifyOpenAICompatError,
76
- fromAnthropic,
77
- fromOpenAI,
78
- mapOAIFinishReason,
79
- openaiCompat,
80
- toAnthropic,
81
- toOpenAI
82
- } from "./chunk-4ILGBQ23.js";
83
- import {
84
- AgentAbortedError,
85
- AgentContextExceededError,
86
- AgentProviderError,
87
- AgentToolNotAllowedError,
88
- CONTEXT_EXCEEDED_MESSAGE_PATTERNS,
89
- matchesContextExceeded,
90
- toTypedError
91
- } from "./chunk-LNN5UTS2.js";
92
-
93
- // src/tracing.ts
1
+ import { a as multiEdit, c as grep, d as createAgent, g as validateToolArgs, h as createSkillsReadTool, l as glob, m as createSkillsRunScriptTool, n as createSpawnTool, p as createSkillsUseTool, s as createInteractionTool, u as edit } from "./tools-DpeWKzP1.js";
2
+ import { n as createProcessContext, r as createDockerContext, t as createSandboxContext } from "./contexts-3Arvn7yR.js";
3
+ import { a as CONTEXT_EXCEEDED_MESSAGE_PATTERNS, i as AgentToolNotAllowedError, n as AgentContextExceededError, o as matchesContextExceeded, r as AgentProviderError, s as toTypedError, t as AgentAbortedError } from "./errors-D1lhd6mX.js";
4
+ import { n as toolResultToText, t as toolOutputByteLength } from "./types-Bx_F8jet.js";
5
+ import { i as resultToString, n as normalizeMcpBlocks, r as normalizeMcpServers, t as connectMcpServers } from "./mcp-8wClKY-3.js";
6
+ import { _ as validateResourcePath, a as discoverSkills, b as createSkillActivationState, f as IMPLICITLY_ALLOWED_SKILL_TOOLS, g as parseAllowedToolPattern, h as matchesAllowedTool, i as writeSkillsToDisk, l as parseSkillFile, m as isToolAllowedByUnion, n as resolveSkills, p as installAllowedToolsGate, r as writeSkillToDisk, t as interpolateShellCommands, u as buildCatalog, v as validateSkillForWrite, y as validateSkillName } from "./interpolate-CukJwP2G.js";
7
+ import { n as statsByModel, t as flattenTurns } from "./stats-DoKUtF5T.js";
8
+ import { n as basicTools, r as basic_default, t as definePreset } from "./presets-Cs7_CsMk.js";
9
+ import { a as toOpenAI, c as classifyOpenAICompatError, i as toAnthropic, l as mapOAIFinishReason, n as fromAnthropic, o as OpenAICompatHttpError, r as fromOpenAI, t as autoDetectAndConvert, u as openaiCompat } from "./messages-z5Pq20p7.js";
10
+ import { i as anthropic, n as openai, r as cerebras, t as openrouter } from "./providers-CX-R-Oy-.js";
11
+ import { a as createFileMapStore, i as createMemoryStore, n as loadSession, r as createRemoteStore, t as createSession } from "./session-Cn68UASv.js";
12
+ import { defineSkill } from "./skills.js";
13
+ //#region src/tracing.ts
14
+ /**
15
+ * Build a set of tracing hook handlers that can be installed on an agent.
16
+ *
17
+ * @example Sentry
18
+ * ```ts
19
+ * const tracing = createTracingHooks({
20
+ * startSpan: (name, attrs) => Sentry.startInactiveSpan({ name, attributes: attrs }),
21
+ * })
22
+ * const uninstall = tracing.install(agent.hooks)
23
+ * try { await agent.run({ prompt }) }
24
+ * finally { uninstall() }
25
+ * ```
26
+ */
94
27
  function createTracingHooks(options) {
95
- const prefix = options.namespace ? `${options.namespace}/` : "";
96
- return {
97
- install(hooks) {
98
- const turnSpans = /* @__PURE__ */ new Map();
99
- const toolSpans = /* @__PURE__ */ new Map();
100
- const mcpSpans = /* @__PURE__ */ new Map();
101
- function endSpan(map, key) {
102
- const span = map.get(key);
103
- if (span) {
104
- try {
105
- span.end();
106
- } catch {
107
- }
108
- map.delete(key);
109
- }
110
- }
111
- function endAll(map) {
112
- for (const [, span] of map) {
113
- try {
114
- span.end();
115
- } catch {
116
- }
117
- }
118
- map.clear();
119
- }
120
- const unregisters = [];
121
- unregisters.push(hooks.hook("turn:before", (ctx) => {
122
- const span = options.startSpan(`${prefix}turn:${ctx.turn}`, { turnId: ctx.turnId });
123
- turnSpans.set(ctx.turnId, span);
124
- }));
125
- function safeSetAttrs(span, attrs) {
126
- if (!span)
127
- return;
128
- try {
129
- span.setAttributes?.(attrs);
130
- } catch {
131
- }
132
- }
133
- unregisters.push(hooks.hook("turn:after", (ctx) => {
134
- const span = turnSpans.get(ctx.turnId);
135
- safeSetAttrs(span, {
136
- inputTokens: ctx.usage.input,
137
- outputTokens: ctx.usage.output,
138
- ...ctx.usage.finishReason ? { finishReason: ctx.usage.finishReason } : {},
139
- ...ctx.usage.modelId ? { modelId: ctx.usage.modelId } : {}
140
- });
141
- endSpan(turnSpans, ctx.turnId);
142
- }));
143
- unregisters.push(hooks.hook("tool:before", (ctx) => {
144
- const span = options.startSpan(`${prefix}tool:${ctx.displayName}`, {
145
- toolName: ctx.name,
146
- displayName: ctx.displayName,
147
- turnId: ctx.turnId,
148
- callId: ctx.callId
149
- });
150
- toolSpans.set(ctx.callId, span);
151
- }));
152
- unregisters.push(hooks.hook("tool:after", (ctx) => {
153
- endSpan(toolSpans, ctx.callId);
154
- }));
155
- unregisters.push(hooks.hook("tool:error", (ctx) => {
156
- safeSetAttrs(toolSpans.get(ctx.callId), { error: ctx.error.message });
157
- endSpan(toolSpans, ctx.callId);
158
- }));
159
- unregisters.push(hooks.hook("mcp:tool:before", (ctx) => {
160
- const span = options.startSpan(`${prefix}mcp:${ctx.server}:${ctx.tool}`, {
161
- server: ctx.server,
162
- tool: ctx.tool,
163
- displayName: ctx.displayName,
164
- turnId: ctx.turnId,
165
- callId: ctx.callId
166
- });
167
- mcpSpans.set(ctx.callId, span);
168
- }));
169
- unregisters.push(hooks.hook("mcp:tool:after", (ctx) => {
170
- endSpan(mcpSpans, ctx.callId);
171
- }));
172
- unregisters.push(hooks.hook("mcp:tool:error", (ctx) => {
173
- safeSetAttrs(mcpSpans.get(ctx.callId), { error: ctx.error.message });
174
- endSpan(mcpSpans, ctx.callId);
175
- }));
176
- unregisters.push(hooks.hook("agent:done", () => {
177
- endAll(turnSpans);
178
- endAll(toolSpans);
179
- endAll(mcpSpans);
180
- }));
181
- let disposed = false;
182
- return function uninstall() {
183
- if (disposed)
184
- return;
185
- disposed = true;
186
- for (const un of unregisters) {
187
- try {
188
- un();
189
- } catch {
190
- }
191
- }
192
- endAll(turnSpans);
193
- endAll(toolSpans);
194
- endAll(mcpSpans);
195
- };
196
- }
197
- };
28
+ const prefix = options.namespace ? `${options.namespace}/` : "";
29
+ return { install(hooks) {
30
+ const turnSpans = /* @__PURE__ */ new Map();
31
+ const toolSpans = /* @__PURE__ */ new Map();
32
+ const mcpSpans = /* @__PURE__ */ new Map();
33
+ function endSpan(map, key) {
34
+ const span = map.get(key);
35
+ if (span) {
36
+ try {
37
+ span.end();
38
+ } catch {}
39
+ map.delete(key);
40
+ }
41
+ }
42
+ function endAll(map) {
43
+ for (const [, span] of map) try {
44
+ span.end();
45
+ } catch {}
46
+ map.clear();
47
+ }
48
+ const unregisters = [];
49
+ unregisters.push(hooks.hook("turn:before", (ctx) => {
50
+ const span = options.startSpan(`${prefix}turn:${ctx.turn}`, { turnId: ctx.turnId });
51
+ turnSpans.set(ctx.turnId, span);
52
+ }));
53
+ function safeSetAttrs(span, attrs) {
54
+ if (!span) return;
55
+ try {
56
+ span.setAttributes?.(attrs);
57
+ } catch {}
58
+ }
59
+ unregisters.push(hooks.hook("turn:after", (ctx) => {
60
+ safeSetAttrs(turnSpans.get(ctx.turnId), {
61
+ inputTokens: ctx.usage.input,
62
+ outputTokens: ctx.usage.output,
63
+ ...ctx.usage.finishReason ? { finishReason: ctx.usage.finishReason } : {},
64
+ ...ctx.usage.modelId ? { modelId: ctx.usage.modelId } : {}
65
+ });
66
+ endSpan(turnSpans, ctx.turnId);
67
+ }));
68
+ unregisters.push(hooks.hook("tool:before", (ctx) => {
69
+ const span = options.startSpan(`${prefix}tool:${ctx.displayName}`, {
70
+ toolName: ctx.name,
71
+ displayName: ctx.displayName,
72
+ turnId: ctx.turnId,
73
+ callId: ctx.callId
74
+ });
75
+ toolSpans.set(ctx.callId, span);
76
+ }));
77
+ unregisters.push(hooks.hook("tool:after", (ctx) => {
78
+ endSpan(toolSpans, ctx.callId);
79
+ }));
80
+ unregisters.push(hooks.hook("tool:error", (ctx) => {
81
+ safeSetAttrs(toolSpans.get(ctx.callId), { error: ctx.error.message });
82
+ endSpan(toolSpans, ctx.callId);
83
+ }));
84
+ unregisters.push(hooks.hook("mcp:tool:before", (ctx) => {
85
+ const span = options.startSpan(`${prefix}mcp:${ctx.server}:${ctx.tool}`, {
86
+ server: ctx.server,
87
+ tool: ctx.tool,
88
+ displayName: ctx.displayName,
89
+ turnId: ctx.turnId,
90
+ callId: ctx.callId
91
+ });
92
+ mcpSpans.set(ctx.callId, span);
93
+ }));
94
+ unregisters.push(hooks.hook("mcp:tool:after", (ctx) => {
95
+ endSpan(mcpSpans, ctx.callId);
96
+ }));
97
+ unregisters.push(hooks.hook("mcp:tool:error", (ctx) => {
98
+ safeSetAttrs(mcpSpans.get(ctx.callId), { error: ctx.error.message });
99
+ endSpan(mcpSpans, ctx.callId);
100
+ }));
101
+ unregisters.push(hooks.hook("agent:done", () => {
102
+ endAll(turnSpans);
103
+ endAll(toolSpans);
104
+ endAll(mcpSpans);
105
+ }));
106
+ let disposed = false;
107
+ return function uninstall() {
108
+ if (disposed) return;
109
+ disposed = true;
110
+ for (const un of unregisters) try {
111
+ un();
112
+ } catch {}
113
+ endAll(turnSpans);
114
+ endAll(toolSpans);
115
+ endAll(mcpSpans);
116
+ };
117
+ } };
198
118
  }
199
-
200
- // src/zod.ts
119
+ //#endregion
120
+ //#region src/zod.ts
121
+ /**
122
+ * Zod v4 integration helper.
123
+ *
124
+ * Normalizes the output of z.toJsonSchema() for use as ToolSpec.inputSchema.
125
+ * Zod is an optional peer dependency — consumers call z.toJsonSchema() themselves.
126
+ *
127
+ * Usage:
128
+ * import { z } from 'zod'
129
+ * import { zodToJsonSchema } from 'zidane'
130
+ * const schema = zodToJsonSchema(z.toJsonSchema(z.object({ name: z.string() })))
131
+ */
132
+ /**
133
+ * Normalize a JSON Schema (e.g. from zod v4's z.toJsonSchema()) for use
134
+ * as a ToolSpec.inputSchema.
135
+ *
136
+ * Strips the $schema key that some providers reject.
137
+ */
201
138
  function zodToJsonSchema(jsonSchema) {
202
- const { $schema, ...rest } = jsonSchema;
203
- return rest;
139
+ const { $schema, ...rest } = jsonSchema;
140
+ return rest;
204
141
  }
205
- export {
206
- AgentAbortedError,
207
- AgentContextExceededError,
208
- AgentProviderError,
209
- AgentToolNotAllowedError,
210
- CONTEXT_EXCEEDED_MESSAGE_PATTERNS,
211
- IMPLICITLY_ALLOWED_SKILL_TOOLS,
212
- OpenAICompatHttpError,
213
- anthropic,
214
- autoDetectAndConvert,
215
- basic_default as basic,
216
- basicTools,
217
- buildCatalog,
218
- cerebras,
219
- classifyOpenAICompatError,
220
- connectMcpServers,
221
- createAgent,
222
- createDockerContext,
223
- createFileMapStore,
224
- createInteractionTool,
225
- createMemoryStore,
226
- createProcessContext,
227
- createRemoteStore,
228
- createSandboxContext,
229
- createSession,
230
- createSkillActivationState,
231
- createSkillsReadTool,
232
- createSkillsRunScriptTool,
233
- createSkillsUseTool,
234
- createSpawnTool,
235
- createTracingHooks,
236
- definePreset,
237
- defineSkill,
238
- discoverSkills,
239
- edit,
240
- flattenTurns,
241
- fromAnthropic,
242
- fromOpenAI,
243
- glob,
244
- grep,
245
- installAllowedToolsGate,
246
- interpolateShellCommands,
247
- isToolAllowedByUnion,
248
- loadSession,
249
- mapOAIFinishReason,
250
- matchesAllowedTool,
251
- matchesContextExceeded,
252
- multiEdit,
253
- normalizeMcpBlocks,
254
- normalizeMcpServers,
255
- openai,
256
- openaiCompat,
257
- openrouter,
258
- parseAllowedToolPattern,
259
- parseSkillFile,
260
- resolveSkills,
261
- resultToString,
262
- statsByModel,
263
- toAnthropic,
264
- toOpenAI,
265
- toTypedError,
266
- toolOutputByteLength,
267
- toolResultToText,
268
- validateResourcePath,
269
- validateSkillForWrite,
270
- validateSkillName,
271
- validateToolArgs,
272
- writeSkillToDisk,
273
- writeSkillsToDisk,
274
- zodToJsonSchema
275
- };
142
+ //#endregion
143
+ export { AgentAbortedError, AgentContextExceededError, AgentProviderError, AgentToolNotAllowedError, CONTEXT_EXCEEDED_MESSAGE_PATTERNS, IMPLICITLY_ALLOWED_SKILL_TOOLS, OpenAICompatHttpError, anthropic, autoDetectAndConvert, basic_default as basic, basicTools, buildCatalog, cerebras, classifyOpenAICompatError, connectMcpServers, createAgent, createDockerContext, createFileMapStore, createInteractionTool, createMemoryStore, createProcessContext, createRemoteStore, createSandboxContext, createSession, createSkillActivationState, createSkillsReadTool, createSkillsRunScriptTool, createSkillsUseTool, createSpawnTool, createTracingHooks, definePreset, defineSkill, discoverSkills, edit, flattenTurns, fromAnthropic, fromOpenAI, glob, grep, installAllowedToolsGate, interpolateShellCommands, isToolAllowedByUnion, loadSession, mapOAIFinishReason, matchesAllowedTool, matchesContextExceeded, multiEdit, normalizeMcpBlocks, normalizeMcpServers, openai, openaiCompat, openrouter, parseAllowedToolPattern, parseSkillFile, resolveSkills, resultToString, statsByModel, toAnthropic, toOpenAI, toTypedError, toolOutputByteLength, toolResultToText, validateResourcePath, validateSkillForWrite, validateSkillName, validateToolArgs, writeSkillToDisk, writeSkillsToDisk, zodToJsonSchema };
144
+
145
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/tracing.ts","../src/zod.ts"],"sourcesContent":["/**\n * Tracing helper — wraps agent lifecycle hooks in caller-provided spans.\n *\n * Zidane is hooks-native; rather than introducing a plugin abstraction just for\n * observability, we ship a small helper that turns an arbitrary `startSpan`\n * function into a bundle of hook handlers. Works with Sentry, OpenTelemetry,\n * Datadog — any tracer that can hand back an object with an `end()` method.\n *\n * The helper:\n * - Starts a `turn:${n}` span on `turn:before`, ends it on `turn:after`.\n * - Starts a `tool:${name}` span on `tool:before`, ends it on `tool:after` / `tool:error`.\n * - Starts a `mcp:${server}:${tool}` span on `mcp:tool:before`, ends it on `mcp:tool:after` / `mcp:tool:error`.\n * - On `agent:done` closes any spans still open (defensive — normally all tool/turn\n * spans have matching end hooks, but an abort mid-execution can leave dangling ones).\n *\n * Returns an `install(hooks)` helper that registers every handler at once and\n * yields an `uninstall()` function for cleanup. Safe across multiple runs.\n */\n\nimport type { Hookable } from 'hookable'\nimport type { AgentHooks } from './agent'\n\n/** Minimal span shape — any tracer that provides these two methods is compatible. */\nexport interface Span {\n /** Close the span. Called exactly once per span. */\n end: () => void\n /** Optional: attach additional attributes after the span is started (ignored if unsupported). */\n setAttributes?: (attrs: Record<string, unknown>) => void\n}\n\n/** Function that opens a span. Caller-provided so we stay tracer-agnostic. */\nexport type StartSpan = (name: string, attrs?: Record<string, unknown>) => Span\n\nexport interface TracingHooksOptions {\n /** Tracer seam. Receives a span name + attributes; must return a `Span`. */\n startSpan: StartSpan\n /**\n * Optional attribute namespace. Prepended to every span name (e.g. `\"agent\"` →\n * span names like `agent/turn:0`, `agent/tool:Bash`).\n */\n namespace?: string\n}\n\n/** Value returned by {@link createTracingHooks} — install entrypoint. */\nexport interface TracingHookSet {\n /**\n * Attach every hook handler to the given agent hooks instance.\n *\n * @returns an `uninstall` function that detaches every handler and closes any\n * still-open spans. Safe to call multiple times.\n */\n install: (hooks: Hookable<AgentHooks>) => () => void\n}\n\n/**\n * Build a set of tracing hook handlers that can be installed on an agent.\n *\n * @example Sentry\n * ```ts\n * const tracing = createTracingHooks({\n * startSpan: (name, attrs) => Sentry.startInactiveSpan({ name, attributes: attrs }),\n * })\n * const uninstall = tracing.install(agent.hooks)\n * try { await agent.run({ prompt }) }\n * finally { uninstall() }\n * ```\n */\nexport function createTracingHooks(options: TracingHooksOptions): TracingHookSet {\n const prefix = options.namespace ? `${options.namespace}/` : ''\n\n return {\n install(hooks: Hookable<AgentHooks>): () => void {\n const turnSpans = new Map<string, Span>()\n const toolSpans = new Map<string, Span>()\n const mcpSpans = new Map<string, Span>()\n\n function endSpan(map: Map<string, Span>, key: string): void {\n const span = map.get(key)\n if (span) {\n try {\n span.end()\n }\n catch {\n // Tracer errors should not crash the run.\n }\n map.delete(key)\n }\n }\n\n function endAll(map: Map<string, Span>): void {\n for (const [, span] of map) {\n try {\n span.end()\n }\n catch {\n // ignore\n }\n }\n map.clear()\n }\n\n const unregisters: Array<() => void> = []\n\n unregisters.push(hooks.hook('turn:before', (ctx) => {\n const span = options.startSpan(`${prefix}turn:${ctx.turn}`, { turnId: ctx.turnId })\n turnSpans.set(ctx.turnId, span)\n }))\n\n function safeSetAttrs(span: Span | undefined, attrs: Record<string, unknown>): void {\n if (!span)\n return\n try {\n span.setAttributes?.(attrs)\n }\n catch {\n // Tracer errors should not crash the run.\n }\n }\n\n unregisters.push(hooks.hook('turn:after', (ctx) => {\n const span = turnSpans.get(ctx.turnId)\n safeSetAttrs(span, {\n inputTokens: ctx.usage.input,\n outputTokens: ctx.usage.output,\n ...(ctx.usage.finishReason ? { finishReason: ctx.usage.finishReason } : {}),\n ...(ctx.usage.modelId ? { modelId: ctx.usage.modelId } : {}),\n })\n endSpan(turnSpans, ctx.turnId)\n }))\n\n unregisters.push(hooks.hook('tool:before', (ctx) => {\n const span = options.startSpan(`${prefix}tool:${ctx.displayName}`, {\n toolName: ctx.name,\n displayName: ctx.displayName,\n turnId: ctx.turnId,\n callId: ctx.callId,\n })\n toolSpans.set(ctx.callId, span)\n }))\n\n unregisters.push(hooks.hook('tool:after', (ctx) => {\n endSpan(toolSpans, ctx.callId)\n }))\n\n unregisters.push(hooks.hook('tool:error', (ctx) => {\n safeSetAttrs(toolSpans.get(ctx.callId), { error: ctx.error.message })\n endSpan(toolSpans, ctx.callId)\n }))\n\n unregisters.push(hooks.hook('mcp:tool:before', (ctx) => {\n const span = options.startSpan(`${prefix}mcp:${ctx.server}:${ctx.tool}`, {\n server: ctx.server,\n tool: ctx.tool,\n displayName: ctx.displayName,\n turnId: ctx.turnId,\n callId: ctx.callId,\n })\n mcpSpans.set(ctx.callId, span)\n }))\n\n unregisters.push(hooks.hook('mcp:tool:after', (ctx) => {\n endSpan(mcpSpans, ctx.callId)\n }))\n\n unregisters.push(hooks.hook('mcp:tool:error', (ctx) => {\n safeSetAttrs(mcpSpans.get(ctx.callId), { error: ctx.error.message })\n endSpan(mcpSpans, ctx.callId)\n }))\n\n unregisters.push(hooks.hook('agent:done', () => {\n endAll(turnSpans)\n endAll(toolSpans)\n endAll(mcpSpans)\n }))\n\n let disposed = false\n return function uninstall() {\n if (disposed)\n return\n disposed = true\n for (const un of unregisters) {\n try {\n un()\n }\n catch {\n // ignore\n }\n }\n endAll(turnSpans)\n endAll(toolSpans)\n endAll(mcpSpans)\n }\n },\n }\n}\n","/**\n * Zod v4 integration helper.\n *\n * Normalizes the output of z.toJsonSchema() for use as ToolSpec.inputSchema.\n * Zod is an optional peer dependency — consumers call z.toJsonSchema() themselves.\n *\n * Usage:\n * import { z } from 'zod'\n * import { zodToJsonSchema } from 'zidane'\n * const schema = zodToJsonSchema(z.toJsonSchema(z.object({ name: z.string() })))\n */\n\n/**\n * Normalize a JSON Schema (e.g. from zod v4's z.toJsonSchema()) for use\n * as a ToolSpec.inputSchema.\n *\n * Strips the $schema key that some providers reject.\n */\nexport function zodToJsonSchema(jsonSchema: Record<string, unknown>): Record<string, unknown> {\n const { $schema, ...rest } = jsonSchema\n return rest\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,SAAgB,mBAAmB,SAA8C;CAC/E,MAAM,SAAS,QAAQ,YAAY,GAAG,QAAQ,UAAU,KAAK;CAE7D,OAAO,EACL,QAAQ,OAAyC;EAC/C,MAAM,4BAAY,IAAI,KAAmB;EACzC,MAAM,4BAAY,IAAI,KAAmB;EACzC,MAAM,2BAAW,IAAI,KAAmB;EAExC,SAAS,QAAQ,KAAwB,KAAmB;GAC1D,MAAM,OAAO,IAAI,IAAI,IAAI;GACzB,IAAI,MAAM;IACR,IAAI;KACF,KAAK,KAAK;YAEN;IAGN,IAAI,OAAO,IAAI;;;EAInB,SAAS,OAAO,KAA8B;GAC5C,KAAK,MAAM,GAAG,SAAS,KACrB,IAAI;IACF,KAAK,KAAK;WAEN;GAIR,IAAI,OAAO;;EAGb,MAAM,cAAiC,EAAE;EAEzC,YAAY,KAAK,MAAM,KAAK,gBAAgB,QAAQ;GAClD,MAAM,OAAO,QAAQ,UAAU,GAAG,OAAO,OAAO,IAAI,QAAQ,EAAE,QAAQ,IAAI,QAAQ,CAAC;GACnF,UAAU,IAAI,IAAI,QAAQ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