@openrouter/agent 0.7.2 → 0.8.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.
Files changed (64) hide show
  1. package/README.md +248 -17
  2. package/esm/index.d.ts +8 -5
  3. package/esm/index.d.ts.map +1 -1
  4. package/esm/index.js +12 -4
  5. package/esm/index.js.map +1 -1
  6. package/esm/inner-loop/call-model.d.ts +8 -5
  7. package/esm/inner-loop/call-model.d.ts.map +1 -1
  8. package/esm/inner-loop/call-model.js +16 -6
  9. package/esm/inner-loop/call-model.js.map +1 -1
  10. package/esm/lib/async-params.d.ts +25 -6
  11. package/esm/lib/async-params.d.ts.map +1 -1
  12. package/esm/lib/async-params.js +3 -1
  13. package/esm/lib/async-params.js.map +1 -1
  14. package/esm/lib/conversation-state.d.ts +44 -1
  15. package/esm/lib/conversation-state.d.ts.map +1 -1
  16. package/esm/lib/conversation-state.js +111 -0
  17. package/esm/lib/conversation-state.js.map +1 -1
  18. package/esm/lib/hooks-emit.d.ts +50 -0
  19. package/esm/lib/hooks-emit.d.ts.map +1 -0
  20. package/esm/lib/hooks-emit.js +307 -0
  21. package/esm/lib/hooks-emit.js.map +1 -0
  22. package/esm/lib/hooks-manager.d.ts +141 -0
  23. package/esm/lib/hooks-manager.d.ts.map +1 -0
  24. package/esm/lib/hooks-manager.js +282 -0
  25. package/esm/lib/hooks-manager.js.map +1 -0
  26. package/esm/lib/hooks-matchers.d.ts +12 -0
  27. package/esm/lib/hooks-matchers.d.ts.map +1 -0
  28. package/esm/lib/hooks-matchers.js +26 -0
  29. package/esm/lib/hooks-matchers.js.map +1 -0
  30. package/esm/lib/hooks-resolve.d.ts +17 -0
  31. package/esm/lib/hooks-resolve.d.ts.map +1 -0
  32. package/esm/lib/hooks-resolve.js +42 -0
  33. package/esm/lib/hooks-resolve.js.map +1 -0
  34. package/esm/lib/hooks-schemas.d.ts +188 -0
  35. package/esm/lib/hooks-schemas.d.ts.map +1 -0
  36. package/esm/lib/hooks-schemas.js +184 -0
  37. package/esm/lib/hooks-schemas.js.map +1 -0
  38. package/esm/lib/hooks-types.d.ts +174 -0
  39. package/esm/lib/hooks-types.d.ts.map +1 -0
  40. package/esm/lib/hooks-types.js +45 -0
  41. package/esm/lib/hooks-types.js.map +1 -0
  42. package/esm/lib/model-result.d.ts +209 -9
  43. package/esm/lib/model-result.d.ts.map +1 -1
  44. package/esm/lib/model-result.js +1397 -348
  45. package/esm/lib/model-result.js.map +1 -1
  46. package/esm/lib/reusable-stream.d.ts +6 -0
  47. package/esm/lib/reusable-stream.d.ts.map +1 -1
  48. package/esm/lib/reusable-stream.js +8 -0
  49. package/esm/lib/reusable-stream.js.map +1 -1
  50. package/esm/lib/tool-executor.d.ts.map +1 -1
  51. package/esm/lib/tool-executor.js +11 -1
  52. package/esm/lib/tool-executor.js.map +1 -1
  53. package/esm/lib/tool-orchestrator.d.ts.map +1 -1
  54. package/esm/lib/tool-orchestrator.js +4 -1
  55. package/esm/lib/tool-orchestrator.js.map +1 -1
  56. package/esm/lib/tool-types.d.ts +137 -45
  57. package/esm/lib/tool-types.d.ts.map +1 -1
  58. package/esm/lib/tool-types.js +13 -0
  59. package/esm/lib/tool-types.js.map +1 -1
  60. package/esm/lib/tool.d.ts +35 -25
  61. package/esm/lib/tool.d.ts.map +1 -1
  62. package/esm/lib/tool.js +19 -0
  63. package/esm/lib/tool.js.map +1 -1
  64. package/package.json +6 -2
@@ -0,0 +1,188 @@
1
+ import * as z4 from 'zod/v4';
2
+ import type { $ZodType } from 'zod/v4/core';
3
+ export declare const HookName: {
4
+ readonly PreToolUse: "PreToolUse";
5
+ readonly PostToolUse: "PostToolUse";
6
+ readonly PostToolUseFailure: "PostToolUseFailure";
7
+ readonly UserPromptSubmit: "UserPromptSubmit";
8
+ readonly Stop: "Stop";
9
+ readonly PermissionRequest: "PermissionRequest";
10
+ readonly SessionStart: "SessionStart";
11
+ readonly SessionEnd: "SessionEnd";
12
+ readonly PostModelCall: "PostModelCall";
13
+ };
14
+ export type HookName = (typeof HookName)[keyof typeof HookName];
15
+ /**
16
+ * A hook definition is a pair of Zod schemas: one for the payload and one for the result.
17
+ */
18
+ export interface HookDefinition {
19
+ readonly payload: $ZodType;
20
+ readonly result: $ZodType;
21
+ }
22
+ /**
23
+ * A registry maps hook names to their definitions.
24
+ */
25
+ export type HookRegistry = Record<string, HookDefinition>;
26
+ export declare const PreToolUsePayloadSchema: z4.ZodObject<{
27
+ toolName: z4.ZodString;
28
+ toolInput: z4.ZodRecord<z4.ZodString, z4.ZodUnknown>;
29
+ }, z4.z.core.$strip>;
30
+ export type PreToolUsePayload = Readonly<z4.infer<typeof PreToolUsePayloadSchema>>;
31
+ export declare const PostToolUsePayloadSchema: z4.ZodObject<{
32
+ toolName: z4.ZodString;
33
+ toolInput: z4.ZodRecord<z4.ZodString, z4.ZodUnknown>;
34
+ toolOutput: z4.ZodUnknown;
35
+ durationMs: z4.ZodNumber;
36
+ }, z4.z.core.$strip>;
37
+ export type PostToolUsePayload = Readonly<z4.infer<typeof PostToolUsePayloadSchema>>;
38
+ export declare const PostToolUseFailurePayloadSchema: z4.ZodObject<{
39
+ toolName: z4.ZodString;
40
+ toolInput: z4.ZodRecord<z4.ZodString, z4.ZodUnknown>;
41
+ error: z4.ZodUnknown;
42
+ }, z4.z.core.$strip>;
43
+ /**
44
+ * Fired when a tool EXECUTION throws or returns an error.
45
+ *
46
+ * Deliberately NOT fired when a tool never ran: a PermissionRequest 'deny',
47
+ * a user rejection on approval resume, or a PreToolUse block all synthesize
48
+ * a rejected result without execution, so no failure event is emitted.
49
+ * Observe those outcomes via the PermissionRequest / PreToolUse hooks
50
+ * themselves.
51
+ */
52
+ export type PostToolUseFailurePayload = Readonly<z4.infer<typeof PostToolUseFailurePayloadSchema>>;
53
+ export declare const StopPayloadSchema: z4.ZodObject<{
54
+ reason: z4.ZodEnum<{
55
+ max_turns: "max_turns";
56
+ }>;
57
+ }, z4.z.core.$strip>;
58
+ export type StopPayload = Readonly<z4.infer<typeof StopPayloadSchema>>;
59
+ export declare const PermissionRequestPayloadSchema: z4.ZodObject<{
60
+ toolName: z4.ZodString;
61
+ toolInput: z4.ZodRecord<z4.ZodString, z4.ZodUnknown>;
62
+ riskLevel: z4.ZodEnum<{
63
+ low: "low";
64
+ high: "high";
65
+ medium: "medium";
66
+ }>;
67
+ }, z4.z.core.$strip>;
68
+ export type PermissionRequestPayload = Readonly<z4.infer<typeof PermissionRequestPayloadSchema>>;
69
+ export declare const UserPromptSubmitPayloadSchema: z4.ZodObject<{
70
+ prompt: z4.ZodString;
71
+ }, z4.z.core.$strip>;
72
+ export type UserPromptSubmitPayload = Readonly<z4.infer<typeof UserPromptSubmitPayloadSchema>>;
73
+ export declare const SessionStartPayloadSchema: z4.ZodObject<{
74
+ config: z4.ZodOptional<z4.ZodRecord<z4.ZodString, z4.ZodUnknown>>;
75
+ }, z4.z.core.$strip>;
76
+ declare const ModelCallUsageSchema: z4.ZodObject<{
77
+ inputTokens: z4.ZodNumber;
78
+ outputTokens: z4.ZodNumber;
79
+ totalTokens: z4.ZodNumber;
80
+ cachedTokens: z4.ZodNumber;
81
+ reasoningTokens: z4.ZodNumber;
82
+ cost: z4.ZodOptional<z4.ZodNumber>;
83
+ }, z4.z.core.$strip>;
84
+ export type ModelCallUsage = Readonly<z4.infer<typeof ModelCallUsageSchema>>;
85
+ export type SessionStartPayload = Readonly<z4.infer<typeof SessionStartPayloadSchema>>;
86
+ declare const SessionUsageTotalsSchema: z4.ZodObject<{
87
+ inputTokens: z4.ZodNumber;
88
+ outputTokens: z4.ZodNumber;
89
+ totalTokens: z4.ZodNumber;
90
+ cachedTokens: z4.ZodNumber;
91
+ reasoningTokens: z4.ZodNumber;
92
+ cost: z4.ZodOptional<z4.ZodNumber>;
93
+ modelCalls: z4.ZodNumber;
94
+ }, z4.z.core.$strip>;
95
+ export declare const SessionEndPayloadSchema: z4.ZodObject<{
96
+ reason: z4.ZodEnum<{
97
+ error: "error";
98
+ complete: "complete";
99
+ user: "user";
100
+ max_turns: "max_turns";
101
+ }>;
102
+ totalUsage: z4.ZodOptional<z4.ZodObject<{
103
+ inputTokens: z4.ZodNumber;
104
+ outputTokens: z4.ZodNumber;
105
+ totalTokens: z4.ZodNumber;
106
+ cachedTokens: z4.ZodNumber;
107
+ reasoningTokens: z4.ZodNumber;
108
+ cost: z4.ZodOptional<z4.ZodNumber>;
109
+ modelCalls: z4.ZodNumber;
110
+ }, z4.z.core.$strip>>;
111
+ }, z4.z.core.$strip>;
112
+ export declare const PostModelCallPayloadSchema: z4.ZodObject<{
113
+ sessionId: z4.ZodString;
114
+ responseId: z4.ZodString;
115
+ model: z4.ZodString;
116
+ durationMs: z4.ZodNumber;
117
+ turnType: z4.ZodEnum<{
118
+ initial: "initial";
119
+ resume: "resume";
120
+ tool_round: "tool_round";
121
+ final: "final";
122
+ retry: "retry";
123
+ }>;
124
+ turnNumber: z4.ZodNumber;
125
+ usage: z4.ZodOptional<z4.ZodObject<{
126
+ inputTokens: z4.ZodNumber;
127
+ outputTokens: z4.ZodNumber;
128
+ totalTokens: z4.ZodNumber;
129
+ cachedTokens: z4.ZodNumber;
130
+ reasoningTokens: z4.ZodNumber;
131
+ cost: z4.ZodOptional<z4.ZodNumber>;
132
+ }, z4.z.core.$strip>>;
133
+ }, z4.z.core.$strip>;
134
+ export type SessionEndPayload = Readonly<z4.infer<typeof SessionEndPayloadSchema>>;
135
+ export type PostModelCallPayload = Readonly<z4.infer<typeof PostModelCallPayloadSchema>>;
136
+ export type SessionUsageTotals = Readonly<z4.infer<typeof SessionUsageTotalsSchema>>;
137
+ export declare const PreToolUseResultSchema: z4.ZodObject<{
138
+ mutatedInput: z4.ZodOptional<z4.ZodRecord<z4.ZodString, z4.ZodUnknown>>;
139
+ block: z4.ZodOptional<z4.ZodUnion<readonly [z4.ZodBoolean, z4.ZodString]>>;
140
+ }, z4.z.core.$strip>;
141
+ export type PreToolUseResult = Readonly<z4.infer<typeof PreToolUseResultSchema>>;
142
+ export declare const StopResultSchema: z4.ZodObject<{
143
+ forceResume: z4.ZodOptional<z4.ZodBoolean>;
144
+ appendPrompt: z4.ZodOptional<z4.ZodString>;
145
+ }, z4.z.core.$strip>;
146
+ /**
147
+ * Result of a Stop hook handler.
148
+ *
149
+ * `forceResume: true` alone does NOT change any state: the stop condition
150
+ * (e.g. `stepCountIs`) will typically fire again immediately on the next
151
+ * iteration, so a bare forceResume burns through the consecutive-override
152
+ * cap (3) in rapid succession and then stops. To make resumption useful,
153
+ * pair it with `appendPrompt` (which injects a user message, advancing the
154
+ * conversation) or use a stop condition whose predicate can change between
155
+ * iterations. This is by design: the engine caps rather than blocks bare
156
+ * forceResume so a handler that coordinates external state (e.g. waiting on
157
+ * an async gate that flips the stop condition) still has a few iterations
158
+ * to do so.
159
+ *
160
+ * `appendPrompt` is honored independently of `forceResume` — a handler can
161
+ * nudge the next turn without forcing a resume. Multiple handlers'
162
+ * appendPrompts are concatenated with newlines.
163
+ *
164
+ * The override counter resets when a tool round produces outputs or a fresh
165
+ * model response lands. Note that hook-blocked and rejected tool outputs
166
+ * count as progress: the model receives the block/denial feedback and can
167
+ * change course, which is observable forward motion even though no tool
168
+ * body executed.
169
+ */
170
+ export type StopResult = Readonly<z4.infer<typeof StopResultSchema>>;
171
+ export declare const PermissionRequestResultSchema: z4.ZodObject<{
172
+ decision: z4.ZodEnum<{
173
+ allow: "allow";
174
+ deny: "deny";
175
+ ask_user: "ask_user";
176
+ }>;
177
+ reason: z4.ZodOptional<z4.ZodString>;
178
+ }, z4.z.core.$strip>;
179
+ export type PermissionRequestResult = Readonly<z4.infer<typeof PermissionRequestResultSchema>>;
180
+ export declare const UserPromptSubmitResultSchema: z4.ZodObject<{
181
+ mutatedPrompt: z4.ZodOptional<z4.ZodString>;
182
+ reject: z4.ZodOptional<z4.ZodUnion<readonly [z4.ZodBoolean, z4.ZodString]>>;
183
+ }, z4.z.core.$strip>;
184
+ export type UserPromptSubmitResult = Readonly<z4.infer<typeof UserPromptSubmitResultSchema>>;
185
+ export declare const BUILT_IN_HOOKS: Record<HookName, HookDefinition>;
186
+ export declare const BUILT_IN_HOOK_NAMES: Set<string>;
187
+ export {};
188
+ //# sourceMappingURL=hooks-schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks-schemas.d.ts","sourceRoot":"","sources":["../../src/lib/hooks-schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAU5C,eAAO,MAAM,QAAQ;;;;;;;;;;CAUX,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAiB1D,eAAO,MAAM,uBAAuB;;;oBAGlC,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC,CAAC;AAEnF,eAAO,MAAM,wBAAwB;;;;;oBAKnC,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC,CAAC;AAErF,eAAO,MAAM,+BAA+B;;;;oBAI1C,CAAC;AAEH;;;;;;;;GAQG;AACH,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC,CAAC;AAEnG,eAAO,MAAM,iBAAiB;;;;oBAI5B,CAAC;AAEH,MAAM,MA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G,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC,CAAC;AAEjF,eAAO,MAAM,gBAAgB;;;oBAG3B,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC;AAErE,eAAO,MAAM,6BAA6B;;;;;;;oBAOxC,CAAC;AAEH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAC,CAAC;AAE/F,eAAO,MAAM,4BAA4B;;;oBAQvC,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC,CAAC;AAW7F,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,QAAQ,EAAE,cAAc,CAqC3D,CAAC;AAEF,eAAO,MAAM,mBAAmB,aAAuC,CAAC"}
@@ -0,0 +1,184 @@
1
+ import * as z4 from 'zod/v4';
2
+ //#region Hook Names & Definition Shape
3
+ //
4
+ // HookName, HookDefinition, and HookRegistry live HERE (with the schemas
5
+ // they key/describe) rather than in hooks-types.ts, so the dependency
6
+ // between the two modules stays one-directional (hooks-types -> hooks-
7
+ // schemas) and no import cycle exists. hooks-types re-exports them, so the
8
+ // public import surface is unchanged.
9
+ export const HookName = {
10
+ PreToolUse: 'PreToolUse',
11
+ PostToolUse: 'PostToolUse',
12
+ PostToolUseFailure: 'PostToolUseFailure',
13
+ UserPromptSubmit: 'UserPromptSubmit',
14
+ Stop: 'Stop',
15
+ PermissionRequest: 'PermissionRequest',
16
+ SessionStart: 'SessionStart',
17
+ SessionEnd: 'SessionEnd',
18
+ PostModelCall: 'PostModelCall',
19
+ };
20
+ //#endregion
21
+ //#region Payload Schemas + Derived Types
22
+ //
23
+ // Each payload/result type is DERIVED from its Zod schema (single source of
24
+ // truth) so the static types can never drift from what the runtime actually
25
+ // validates -- the same discipline custom hooks get via `zodInfer` in
26
+ // hooks-manager.ts. `Readonly<...>` matches the immutability contract
27
+ // handlers are given (top-level, like the previous hand-written interfaces).
28
+ //
29
+ // Note: payloads deliberately do NOT carry `sessionId`. The session id is
30
+ // ambient context, not event data -- handlers read it from
31
+ // `context.sessionId` (LifecycleHookContext), which the manager populates
32
+ // via `setSessionId()`.
33
+ export const PreToolUsePayloadSchema = z4.object({
34
+ toolName: z4.string(),
35
+ toolInput: z4.record(z4.string(), z4.unknown()),
36
+ });
37
+ export const PostToolUsePayloadSchema = z4.object({
38
+ toolName: z4.string(),
39
+ toolInput: z4.record(z4.string(), z4.unknown()),
40
+ toolOutput: z4.unknown(),
41
+ durationMs: z4.number(),
42
+ });
43
+ export const PostToolUseFailurePayloadSchema = z4.object({
44
+ toolName: z4.string(),
45
+ toolInput: z4.record(z4.string(), z4.unknown()),
46
+ error: z4.unknown(),
47
+ });
48
+ export const StopPayloadSchema = z4.object({
49
+ reason: z4.enum([
50
+ 'max_turns',
51
+ ]),
52
+ });
53
+ export const PermissionRequestPayloadSchema = z4.object({
54
+ toolName: z4.string(),
55
+ toolInput: z4.record(z4.string(), z4.unknown()),
56
+ riskLevel: z4.enum([
57
+ 'low',
58
+ 'medium',
59
+ 'high',
60
+ ]),
61
+ });
62
+ export const UserPromptSubmitPayloadSchema = z4.object({
63
+ prompt: z4.string(),
64
+ });
65
+ export const SessionStartPayloadSchema = z4.object({
66
+ config: z4.record(z4.string(), z4.unknown()).optional(),
67
+ });
68
+ const ModelCallUsageSchema = z4.object({
69
+ inputTokens: z4.number(),
70
+ outputTokens: z4.number(),
71
+ totalTokens: z4.number(),
72
+ cachedTokens: z4.number(),
73
+ reasoningTokens: z4.number(),
74
+ cost: z4.number().optional(),
75
+ });
76
+ const SessionUsageTotalsSchema = ModelCallUsageSchema.extend({
77
+ modelCalls: z4.number(),
78
+ });
79
+ export const SessionEndPayloadSchema = z4.object({
80
+ reason: z4.enum([
81
+ 'user',
82
+ 'error',
83
+ 'max_turns',
84
+ 'complete',
85
+ ]),
86
+ totalUsage: SessionUsageTotalsSchema.optional(),
87
+ });
88
+ export const PostModelCallPayloadSchema = z4.object({
89
+ sessionId: z4.string(),
90
+ responseId: z4.string(),
91
+ model: z4.string(),
92
+ durationMs: z4.number(),
93
+ turnType: z4.enum([
94
+ 'initial',
95
+ 'resume',
96
+ 'tool_round',
97
+ 'final',
98
+ 'retry',
99
+ ]),
100
+ turnNumber: z4.number(),
101
+ usage: ModelCallUsageSchema.optional(),
102
+ });
103
+ //#endregion
104
+ //#region Result Schemas + Derived Types
105
+ export const PreToolUseResultSchema = z4.object({
106
+ mutatedInput: z4.record(z4.string(), z4.unknown()).optional(),
107
+ block: z4
108
+ .union([
109
+ z4.boolean(),
110
+ z4.string(),
111
+ ])
112
+ .optional(),
113
+ });
114
+ export const StopResultSchema = z4.object({
115
+ forceResume: z4.boolean().optional(),
116
+ appendPrompt: z4.string().optional(),
117
+ });
118
+ export const PermissionRequestResultSchema = z4.object({
119
+ decision: z4.enum([
120
+ 'allow',
121
+ 'deny',
122
+ 'ask_user',
123
+ ]),
124
+ reason: z4.string().optional(),
125
+ });
126
+ export const UserPromptSubmitResultSchema = z4.object({
127
+ mutatedPrompt: z4.string().optional(),
128
+ reject: z4
129
+ .union([
130
+ z4.boolean(),
131
+ z4.string(),
132
+ ])
133
+ .optional(),
134
+ });
135
+ const VoidResultSchema = z4.void();
136
+ //#endregion
137
+ //#region Built-in Hook Registry
138
+ // Keyed by the HookName enum object (not string literals) and typed as
139
+ // Record<HookName, ...> so adding a name to HookName without registering
140
+ // schemas here is a compile error.
141
+ export const BUILT_IN_HOOKS = {
142
+ [HookName.PreToolUse]: {
143
+ payload: PreToolUsePayloadSchema,
144
+ result: PreToolUseResultSchema,
145
+ },
146
+ [HookName.PostToolUse]: {
147
+ payload: PostToolUsePayloadSchema,
148
+ result: VoidResultSchema,
149
+ },
150
+ [HookName.PostToolUseFailure]: {
151
+ payload: PostToolUseFailurePayloadSchema,
152
+ result: VoidResultSchema,
153
+ },
154
+ [HookName.UserPromptSubmit]: {
155
+ payload: UserPromptSubmitPayloadSchema,
156
+ result: UserPromptSubmitResultSchema,
157
+ },
158
+ [HookName.Stop]: {
159
+ payload: StopPayloadSchema,
160
+ result: StopResultSchema,
161
+ },
162
+ [HookName.PermissionRequest]: {
163
+ payload: PermissionRequestPayloadSchema,
164
+ result: PermissionRequestResultSchema,
165
+ },
166
+ [HookName.SessionStart]: {
167
+ payload: SessionStartPayloadSchema,
168
+ result: VoidResultSchema,
169
+ },
170
+ [HookName.SessionEnd]: {
171
+ payload: SessionEndPayloadSchema,
172
+ result: VoidResultSchema,
173
+ },
174
+ PostModelCall: {
175
+ payload: PostModelCallPayloadSchema,
176
+ result: VoidResultSchema,
177
+ },
178
+ };
179
+ export const BUILT_IN_HOOK_NAMES = new Set(Object.keys(BUILT_IN_HOOKS));
180
+ // NOTE: void-result hooks are detected by schema shape (`isVoidSchema` in
181
+ // hooks-manager.ts), not by a name list, so custom hooks with `result:
182
+ // z.void()` behave identically to the built-in void hooks.
183
+ //#endregion
184
+ //# sourceMappingURL=hooks-schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks-schemas.js","sourceRoot":"","sources":["../../src/lib/hooks-schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,QAAQ,CAAC;AAG7B,uCAAuC;AACvC,EAAE;AACF,yEAAyE;AACzE,sEAAsE;AACtE,uEAAuE;AACvE,2EAA2E;AAC3E,sCAAsC;AAEtC,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,UAAU,EAAE,YAAY;IACxB,WAAW,EAAE,aAAa;IAC1B,kBAAkB,EAAE,oBAAoB;IACxC,gBAAgB,EAAE,kBAAkB;IACpC,IAAI,EAAE,MAAM;IACZ,iBAAiB,EAAE,mBAAmB;IACtC,YAAY,EAAE,cAA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,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;QACrB,OAAO,EAAE,uBAAuB;QAChC,MAAM,EAAE,gBAAgB;KACzB;IACD,aAAa,EAAE;QACb,OAAO,EAAE,0BAA0B;QACnC,MAAM,EAAE,gBAAgB;KACzB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;AACxE,0EAA0E;AAC1E,uEAAuE;AACvE,2DAA2D;AAE3D,YAAY"}
@@ -0,0 +1,174 @@
1
+ import type { PermissionRequestPayload, PermissionRequestResult, PostModelCallPayload, PostToolUseFailurePayload, PostToolUsePayload, PreToolUsePayload, PreToolUseResult, SessionEndPayload, SessionStartPayload, StopPayload, StopResult, UserPromptSubmitPayload, UserPromptSubmitResult } from './hooks-schemas.js';
2
+ import { HookName } from './hooks-schemas.js';
3
+ export type { HookDefinition, HookRegistry } from './hooks-schemas.js';
4
+ export { HookName } from './hooks-schemas.js';
5
+ /**
6
+ * Context provided to every lifecycle-hook handler invocation.
7
+ *
8
+ * - `signal` is aborted if the manager's `abortInflight()` is called while the
9
+ * emit is still running. Handlers that kick off background work via
10
+ * {@link AsyncOutput} should observe the signal for cancellation.
11
+ */
12
+ export interface LifecycleHookContext {
13
+ readonly signal: AbortSignal;
14
+ readonly hookName: string;
15
+ /**
16
+ * The current session id. This is the single source for session identity in
17
+ * handlers -- payloads deliberately do not repeat it. The engine threads it
18
+ * per emit (safe for a manager shared across concurrent runs); direct
19
+ * `emit()` callers get the manager-level default from `setSessionId()`
20
+ * unless they pass a per-emit override.
21
+ */
22
+ readonly sessionId: string;
23
+ }
24
+ /**
25
+ * Returned by a handler to signal fire-and-forget mode.
26
+ *
27
+ * The chain proceeds immediately without waiting for completion. Any background
28
+ * work the handler has kicked off should be attached as `work` so the manager
29
+ * can track it for `drain()` and enforce the `asyncTimeout`.
30
+ *
31
+ * The handler is expected to construct and return this object synchronously (or
32
+ * resolve to it quickly). The `work` promise is the detached work to track.
33
+ */
34
+ export interface AsyncOutput {
35
+ readonly async: true;
36
+ /**
37
+ * Background work the manager should track for `drain()` and time out after
38
+ * `asyncTimeout` ms. Omit if there is no work to track.
39
+ */
40
+ readonly work?: Promise<unknown>;
41
+ /** Milliseconds before the async handler is aborted. Default: 30000 */
42
+ readonly asyncTimeout?: number;
43
+ }
44
+ declare const DEFAULT_ASYNC_TIMEOUT = 30000;
45
+ export { DEFAULT_ASYNC_TIMEOUT };
46
+ /**
47
+ * A handler may return a sync result, an async signal, or void.
48
+ */
49
+ export type HookReturn<R> = R | AsyncOutput | void;
50
+ /**
51
+ * A hook handler receives the validated payload and context.
52
+ */
53
+ export type HookHandler<P, R> = (payload: P, context: LifecycleHookContext) => HookReturn<R> | Promise<HookReturn<R>>;
54
+ /**
55
+ * Matcher for tool-scoped hooks. Filters handler invocation by tool name.
56
+ */
57
+ export type ToolMatcher = string | RegExp | ((toolName: string) => boolean);
58
+ /**
59
+ * An entry registered for a specific hook.
60
+ */
61
+ export interface HookEntry<P, R> {
62
+ readonly handler: HookHandler<P, R>;
63
+ readonly matcher?: ToolMatcher;
64
+ readonly filter?: (payload: P) => boolean;
65
+ }
66
+ /**
67
+ * Result of emitting a hook through the handler chain.
68
+ */
69
+ export interface EmitResult<R, P> {
70
+ /**
71
+ * Sync results from handlers that returned a hook-specific value.
72
+ *
73
+ * INVARIANT: every entry passed the hook's result schema (invalid results
74
+ * are skipped or thrown per the error policy, never collected), so
75
+ * consumers can rely on the static type `R` without re-narrowing. For
76
+ * void-result hooks (no schema) entries are opaque and `R` is `undefined`
77
+ * -- treat them accordingly.
78
+ */
79
+ readonly results: R[];
80
+ /** Handles to detached async handler work. */
81
+ readonly pending: Promise<void>[];
82
+ /** The payload after all mutation piping has been applied. */
83
+ readonly finalPayload: P;
84
+ /** True if any handler triggered a block/reject short-circuit. */
85
+ readonly blocked: boolean;
86
+ /**
87
+ * True if any handler's result actually piped a mutation into the payload
88
+ * (e.g. PreToolUse `mutatedInput`, UserPromptSubmit `mutatedPrompt`).
89
+ * Callers should use this rather than comparing `finalPayload` references,
90
+ * since payload validation may clone the object even when no handler
91
+ * mutated it.
92
+ */
93
+ readonly mutated: boolean;
94
+ }
95
+ export interface HooksManagerOptions {
96
+ /**
97
+ * If true, a throwing handler or a schema-validation failure stops the chain
98
+ * and propagates the error. If false (default), the error is logged as a
99
+ * warning and execution continues.
100
+ */
101
+ readonly throwOnHandlerError?: boolean;
102
+ }
103
+ export type { ModelCallUsage, PermissionRequestPayload, PermissionRequestResult, PostModelCallPayload, PostToolUseFailurePayload, PostToolUsePayload, PreToolUsePayload, PreToolUseResult, SessionEndPayload, SessionStartPayload, SessionUsageTotals, StopPayload, StopResult, UserPromptSubmitPayload, UserPromptSubmitResult, } from './hooks-schemas.js';
104
+ export interface BuiltInHookDefinitions {
105
+ PreToolUse: {
106
+ payload: PreToolUsePayload;
107
+ result: PreToolUseResult;
108
+ };
109
+ PostToolUse: {
110
+ payload: PostToolUsePayload;
111
+ /** Observation-only hook: handlers have no meaningful result. */
112
+ result: undefined;
113
+ };
114
+ PostToolUseFailure: {
115
+ payload: PostToolUseFailurePayload;
116
+ /** Observation-only hook: handlers have no meaningful result. */
117
+ result: undefined;
118
+ };
119
+ UserPromptSubmit: {
120
+ payload: UserPromptSubmitPayload;
121
+ result: UserPromptSubmitResult;
122
+ };
123
+ Stop: {
124
+ payload: StopPayload;
125
+ result: StopResult;
126
+ };
127
+ PermissionRequest: {
128
+ payload: PermissionRequestPayload;
129
+ result: PermissionRequestResult;
130
+ };
131
+ SessionStart: {
132
+ payload: SessionStartPayload;
133
+ /** Observation-only hook: handlers have no meaningful result. */
134
+ result: undefined;
135
+ };
136
+ SessionEnd: {
137
+ payload: SessionEndPayload;
138
+ /** Observation-only hook: handlers have no meaningful result. */
139
+ result: undefined;
140
+ };
141
+ PostModelCall: {
142
+ payload: PostModelCallPayload;
143
+ /** Observation-only hook: handlers have no meaningful result. */
144
+ result: undefined;
145
+ };
146
+ }
147
+ /**
148
+ * Inline hook config passed directly to callModel.
149
+ * Only supports built-in hooks. For custom hooks, use a HooksManager instance.
150
+ */
151
+ export type InlineHookConfig = {
152
+ [K in keyof BuiltInHookDefinitions]?: HookEntry<BuiltInHookDefinitions[K]['payload'], BuiltInHookDefinitions[K]['result']>[];
153
+ };
154
+ /**
155
+ * Checks if a value is an AsyncOutput signal (see {@link AsyncOutputSchema}).
156
+ */
157
+ export declare function isAsyncOutput(value: unknown): value is AsyncOutput;
158
+ /**
159
+ * Per-hook chain behavior: which result fields pipe mutations back into the
160
+ * payload, and which result field short-circuits the chain.
161
+ *
162
+ * Keyed by {@link HookName} so a typo'd hook name is a compile error rather
163
+ * than a silent no-behavior lookup. Hooks absent from this table are
164
+ * observation-only: their handlers' results are collected but never alter
165
+ * the payload or stop the chain. Custom hooks never participate.
166
+ */
167
+ export interface HookBehavior {
168
+ /** result field name -> payload field it replaces (mutation piping) */
169
+ readonly mutations?: Readonly<Record<string, string>>;
170
+ /** result field that short-circuits the chain when `true` or a non-empty string */
171
+ readonly blockField?: string;
172
+ }
173
+ export declare const HOOK_BEHAVIOR: Readonly<Partial<Record<HookName, HookBehavior>>>;
174
+ //# sourceMappingURL=hooks-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks-types.d.ts","sourceRoot":"","sources":["../../src/lib/hooks-types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,wBAAwB,EACxB,uBAAuB,EACvB,oBAAoB,EACpB,yBAAyB,EACzB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,UAAU,EACV,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAI9C,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAKvE,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W,CAAC;QACrB,MAAM,EAAE,UAAU,CAAC;KACpB,CAAC;IACF,iBAAiB,EAAE;QACjB,OAAO,EAAE,wBAAwB,CAAC;QAClC,MAAM,EAAE,uBAAuB,CAAC;KACjC,CAAC;IACF,YAAY,EAAE;QACZ,OAAO,EAAE,mBAAmB,CAAC;QAC7B,iEAAiE;QACjE,MAAM,EAAE,SAAS,CAAC;KACnB,CAAC;IACF,UAAU,EAAE;QACV,OAAO,EAAE,iBAAiB,CAAC;QAC3B,iEAAiE;QACjE,MAAM,EAAE,SAAS,CAAC;KACnB,CAAC;IACF,aAAa,EAAE;QACb,OAAO,EAAE,oBAAoB,CAAC;QAC9B,iEAAiE;QACjE,MAAM,EAAE,SAAS,CAAC;KACnB,CAAC;CACH;AAMD;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;KAC5B,CAAC,IAAI,MAAM,sBAAsB,CAAC,CAAC,EAAE,SAAS,CAC7C,sBAAsB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EACpC,sBAAsB,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CACpC,EAAE;CACJ,CAAC;AAmBF;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,YAAY;IAC3B,uEAAuE;IACvE,QAAQ,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACtD,mFAAmF;IACnF,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAa1E,CAAC"}
@@ -0,0 +1,45 @@
1
+ import * as z4 from 'zod/v4';
2
+ import { HookName } from './hooks-schemas.js';
3
+ // HookName / HookDefinition / HookRegistry are declared in hooks-schemas.ts
4
+ // next to the schemas they describe; re-exported here so the public import
5
+ // surface is unchanged and the module dependency stays one-directional
6
+ // (hooks-types -> hooks-schemas, no cycle).
7
+ export { HookName } from './hooks-schemas.js';
8
+ const DEFAULT_ASYNC_TIMEOUT = 30000;
9
+ export { DEFAULT_ASYNC_TIMEOUT };
10
+ //#endregion
11
+ //#region Helper Types
12
+ /**
13
+ * Strict schema for an {@link AsyncOutput} signal: `async` must be literally
14
+ * `true`, `work`/`asyncTimeout` must match their declared types, and any
15
+ * foreign key fails the parse. A handler that accidentally returns
16
+ * `{ async: true, mutatedInput: {...} }` is therefore treated as a result
17
+ * (so the mutation is not silently discarded), not as fire-and-forget.
18
+ */
19
+ const AsyncOutputSchema = z4.strictObject({
20
+ async: z4.literal(true),
21
+ work: z4.instanceof(Promise).optional(),
22
+ asyncTimeout: z4.number().optional(),
23
+ });
24
+ /**
25
+ * Checks if a value is an AsyncOutput signal (see {@link AsyncOutputSchema}).
26
+ */
27
+ export function isAsyncOutput(value) {
28
+ return AsyncOutputSchema.safeParse(value).success;
29
+ }
30
+ export const HOOK_BEHAVIOR = Object.freeze({
31
+ [HookName.PreToolUse]: Object.freeze({
32
+ mutations: Object.freeze({
33
+ mutatedInput: 'toolInput',
34
+ }),
35
+ blockField: 'block',
36
+ }),
37
+ [HookName.UserPromptSubmit]: Object.freeze({
38
+ mutations: Object.freeze({
39
+ mutatedPrompt: 'prompt',
40
+ }),
41
+ blockField: 'reject',
42
+ }),
43
+ });
44
+ //#endregion
45
+ //# sourceMappingURL=hooks-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks-types.js","sourceRoot":"","sources":["../../src/lib/hooks-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,QAAQ,CAAC;AAgB7B,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAK9C,4EAA4E;AAC5E,2EAA2E;AAC3E,uEAAuE;AACvE,4CAA4C;AAC5C,OAAO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