zidane 1.6.7 → 1.6.9
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 +20 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -225,36 +225,37 @@ agent.hooks.hook('stream:thinking', (ctx) => {
|
|
|
225
225
|
|
|
226
226
|
### Tool execution
|
|
227
227
|
|
|
228
|
-
|
|
229
|
-
agent.hooks.hook('tool:before', (ctx) => { /* ctx.name, ctx.input */ })
|
|
230
|
-
agent.hooks.hook('tool:after', (ctx) => { /* ctx.name, ctx.input, ctx.result */ })
|
|
231
|
-
agent.hooks.hook('tool:error', (ctx) => { /* ctx.name, ctx.input, ctx.error */ })
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
### Tool gate
|
|
235
|
-
|
|
236
|
-
Block a tool from running:
|
|
228
|
+
All tool hooks include `turnId` and `callId` for correlation. Typed via `ToolHookContext`.
|
|
237
229
|
|
|
238
230
|
```ts
|
|
239
231
|
agent.hooks.hook('tool:gate', (ctx) => {
|
|
232
|
+
// ctx.turnId, ctx.callId, ctx.name, ctx.input
|
|
240
233
|
if (ctx.name === 'shell' && String(ctx.input.command).includes('rm -rf')) {
|
|
241
234
|
ctx.block = true
|
|
242
235
|
ctx.reason = 'dangerous command'
|
|
243
236
|
}
|
|
244
237
|
})
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
### Tool transform
|
|
248
|
-
|
|
249
|
-
Modify tool output before it's sent back to the model:
|
|
250
238
|
|
|
251
|
-
|
|
239
|
+
agent.hooks.hook('tool:before', (ctx) => { /* ctx.turnId, ctx.callId, ctx.name, ctx.input */ })
|
|
240
|
+
agent.hooks.hook('tool:after', (ctx) => { /* + ctx.result */ })
|
|
241
|
+
agent.hooks.hook('tool:error', (ctx) => { /* + ctx.error */ })
|
|
252
242
|
agent.hooks.hook('tool:transform', (ctx) => {
|
|
243
|
+
// + ctx.result, ctx.isError — mutate to modify output
|
|
253
244
|
if (ctx.result.length > 5000)
|
|
254
245
|
ctx.result = ctx.result.slice(0, 5000) + '\n... (truncated)'
|
|
255
246
|
})
|
|
256
247
|
```
|
|
257
248
|
|
|
249
|
+
MCP tool hooks mirror the same pattern with `server` and `tool` fields. Typed via `McpToolHookContext`.
|
|
250
|
+
|
|
251
|
+
```ts
|
|
252
|
+
agent.hooks.hook('mcp:tool:gate', (ctx) => { /* ctx.turnId, ctx.callId, ctx.server, ctx.tool, ctx.input, ctx.block, ctx.reason */ })
|
|
253
|
+
agent.hooks.hook('mcp:tool:before', (ctx) => { /* ctx.turnId, ctx.callId, ctx.server, ctx.tool, ctx.input */ })
|
|
254
|
+
agent.hooks.hook('mcp:tool:after', (ctx) => { /* + ctx.result */ })
|
|
255
|
+
agent.hooks.hook('mcp:tool:transform', (ctx) => { /* + ctx.result — mutate to modify */ })
|
|
256
|
+
agent.hooks.hook('mcp:tool:error', (ctx) => { /* + ctx.error */ })
|
|
257
|
+
```
|
|
258
|
+
|
|
258
259
|
### Context transform
|
|
259
260
|
|
|
260
261
|
Prune messages before each LLM call:
|
|
@@ -581,6 +582,9 @@ All types are available from `zidane/types`:
|
|
|
581
582
|
|
|
582
583
|
```ts
|
|
583
584
|
import type { Agent, SessionTurn, TurnUsage, Provider, ToolDef } from 'zidane/types'
|
|
585
|
+
|
|
586
|
+
// Hook context types for typed event handlers
|
|
587
|
+
import type { ToolHookContext, McpToolHookContext, SessionHookContext, StreamHookContext } from 'zidane/types'
|
|
584
588
|
```
|
|
585
589
|
|
|
586
590
|
## Testing
|
|
@@ -589,7 +593,7 @@ import type { Agent, SessionTurn, TurnUsage, Provider, ToolDef } from 'zidane/ty
|
|
|
589
593
|
bun test
|
|
590
594
|
```
|
|
591
595
|
|
|
592
|
-
|
|
596
|
+
489+ tests with mock provider and execution context. No API keys or Docker needed.
|
|
593
597
|
|
|
594
598
|
## License
|
|
595
599
|
|