@openrouter/agent 0.7.2 → 0.9.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.
- package/README.md +728 -19
- package/esm/index.d.ts +24 -6
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +20 -5
- package/esm/index.js.map +1 -1
- package/esm/inner-loop/call-model.d.ts +8 -5
- package/esm/inner-loop/call-model.d.ts.map +1 -1
- package/esm/inner-loop/call-model.js +49 -40
- package/esm/inner-loop/call-model.js.map +1 -1
- package/esm/inner-loop/resume-tool-results.d.ts +128 -0
- package/esm/inner-loop/resume-tool-results.d.ts.map +1 -0
- package/esm/inner-loop/resume-tool-results.js +244 -0
- package/esm/inner-loop/resume-tool-results.js.map +1 -0
- package/esm/lib/agent-tool.d.ts +92 -0
- package/esm/lib/agent-tool.d.ts.map +1 -0
- package/esm/lib/agent-tool.js +211 -0
- package/esm/lib/agent-tool.js.map +1 -0
- package/esm/lib/async-params.d.ts +107 -6
- package/esm/lib/async-params.d.ts.map +1 -1
- package/esm/lib/async-params.js +8 -1
- package/esm/lib/async-params.js.map +1 -1
- package/esm/lib/async-tool-registry.d.ts +134 -0
- package/esm/lib/async-tool-registry.d.ts.map +1 -0
- package/esm/lib/async-tool-registry.js +352 -0
- package/esm/lib/async-tool-registry.js.map +1 -0
- package/esm/lib/async-tools.d.ts +23 -0
- package/esm/lib/async-tools.d.ts.map +1 -0
- package/esm/lib/async-tools.js +19 -0
- package/esm/lib/async-tools.js.map +1 -0
- package/esm/lib/conversation-state.d.ts +45 -1
- package/esm/lib/conversation-state.d.ts.map +1 -1
- package/esm/lib/conversation-state.js +119 -0
- package/esm/lib/conversation-state.js.map +1 -1
- package/esm/lib/doom-loop.d.ts +533 -0
- package/esm/lib/doom-loop.d.ts.map +1 -0
- package/esm/lib/doom-loop.js +1221 -0
- package/esm/lib/doom-loop.js.map +1 -0
- package/esm/lib/hooks-emit.d.ts +50 -0
- package/esm/lib/hooks-emit.d.ts.map +1 -0
- package/esm/lib/hooks-emit.js +307 -0
- package/esm/lib/hooks-emit.js.map +1 -0
- package/esm/lib/hooks-manager.d.ts +141 -0
- package/esm/lib/hooks-manager.d.ts.map +1 -0
- package/esm/lib/hooks-manager.js +282 -0
- package/esm/lib/hooks-manager.js.map +1 -0
- package/esm/lib/hooks-matchers.d.ts +12 -0
- package/esm/lib/hooks-matchers.d.ts.map +1 -0
- package/esm/lib/hooks-matchers.js +26 -0
- package/esm/lib/hooks-matchers.js.map +1 -0
- package/esm/lib/hooks-resolve.d.ts +17 -0
- package/esm/lib/hooks-resolve.d.ts.map +1 -0
- package/esm/lib/hooks-resolve.js +42 -0
- package/esm/lib/hooks-resolve.js.map +1 -0
- package/esm/lib/hooks-schemas.d.ts +221 -0
- package/esm/lib/hooks-schemas.d.ts.map +1 -0
- package/esm/lib/hooks-schemas.js +238 -0
- package/esm/lib/hooks-schemas.js.map +1 -0
- package/esm/lib/hooks-types.d.ts +178 -0
- package/esm/lib/hooks-types.d.ts.map +1 -0
- package/esm/lib/hooks-types.js +45 -0
- package/esm/lib/hooks-types.js.map +1 -0
- package/esm/lib/model-result.d.ts +848 -12
- package/esm/lib/model-result.d.ts.map +1 -1
- package/esm/lib/model-result.js +4055 -410
- package/esm/lib/model-result.js.map +1 -1
- package/esm/lib/reusable-stream.d.ts +15 -0
- package/esm/lib/reusable-stream.d.ts.map +1 -1
- package/esm/lib/reusable-stream.js +25 -0
- package/esm/lib/reusable-stream.js.map +1 -1
- package/esm/lib/stream-transformers.d.ts +20 -0
- package/esm/lib/stream-transformers.d.ts.map +1 -1
- package/esm/lib/stream-transformers.js +45 -0
- package/esm/lib/stream-transformers.js.map +1 -1
- package/esm/lib/tool-check.d.ts +76 -0
- package/esm/lib/tool-check.d.ts.map +1 -0
- package/esm/lib/tool-check.js +241 -0
- package/esm/lib/tool-check.js.map +1 -0
- package/esm/lib/tool-concurrency.d.ts +42 -0
- package/esm/lib/tool-concurrency.d.ts.map +1 -0
- package/esm/lib/tool-concurrency.js +80 -0
- package/esm/lib/tool-concurrency.js.map +1 -0
- package/esm/lib/tool-context.d.ts +45 -1
- package/esm/lib/tool-context.d.ts.map +1 -1
- package/esm/lib/tool-context.js +60 -1
- package/esm/lib/tool-context.js.map +1 -1
- package/esm/lib/tool-executor.d.ts +52 -9
- package/esm/lib/tool-executor.d.ts.map +1 -1
- package/esm/lib/tool-executor.js +263 -21
- package/esm/lib/tool-executor.js.map +1 -1
- package/esm/lib/tool-orchestrator.d.ts.map +1 -1
- package/esm/lib/tool-orchestrator.js +87 -47
- package/esm/lib/tool-orchestrator.js.map +1 -1
- package/esm/lib/tool-task.d.ts +157 -0
- package/esm/lib/tool-task.d.ts.map +1 -0
- package/esm/lib/tool-task.js +206 -0
- package/esm/lib/tool-task.js.map +1 -0
- package/esm/lib/tool-types.d.ts +609 -58
- package/esm/lib/tool-types.d.ts.map +1 -1
- package/esm/lib/tool-types.js +72 -10
- package/esm/lib/tool-types.js.map +1 -1
- package/esm/lib/tool.d.ts +217 -25
- package/esm/lib/tool.d.ts.map +1 -1
- package/esm/lib/tool.js +210 -1
- package/esm/lib/tool.js.map +1 -1
- package/package.json +35 -3
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { safeParse } from 'zod/v4/core';
|
|
2
|
+
import { executeHandlerChain } from './hooks-emit.js';
|
|
3
|
+
import { BUILT_IN_HOOK_NAMES, BUILT_IN_HOOKS } from './hooks-schemas.js';
|
|
4
|
+
//#endregion
|
|
5
|
+
/**
|
|
6
|
+
* Module-private key used by `resolveHooks` to call the internal
|
|
7
|
+
* untyped-registration path without exposing it as a public method on the
|
|
8
|
+
* class. See {@link getInternalRegistrar} below.
|
|
9
|
+
*/
|
|
10
|
+
const INTERNAL_REGISTRAR_KEY = Symbol('HooksManager.internalRegistrar');
|
|
11
|
+
/**
|
|
12
|
+
* Typed, extensible hook system for agent lifecycle events.
|
|
13
|
+
*
|
|
14
|
+
* Supports both built-in hooks (PreToolUse, PostToolUse, etc.) and
|
|
15
|
+
* user-defined custom hooks with full type safety.
|
|
16
|
+
*/
|
|
17
|
+
export class HooksManager {
|
|
18
|
+
constructor(customHooks, options) {
|
|
19
|
+
this.entries = new Map();
|
|
20
|
+
this.pendingAsync = new Set();
|
|
21
|
+
this.inflightControllers = new Set();
|
|
22
|
+
this.sessionId = '';
|
|
23
|
+
this.throwOnHandlerError = options?.throwOnHandlerError ?? false;
|
|
24
|
+
// Validate custom hook names: no empty names, no collisions with built-ins.
|
|
25
|
+
if (customHooks) {
|
|
26
|
+
for (const name of Object.keys(customHooks)) {
|
|
27
|
+
if (name === '') {
|
|
28
|
+
throw new Error('Custom hook names must be non-empty strings.');
|
|
29
|
+
}
|
|
30
|
+
if (BUILT_IN_HOOK_NAMES.has(name)) {
|
|
31
|
+
throw new Error(`Custom hook name "${name}" collides with a built-in hook. Choose a different name.`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
this.customHooks = {
|
|
35
|
+
...customHooks,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.customHooks = {};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Set the manager-level default session ID exposed as `context.sessionId`
|
|
44
|
+
* to handler invocations. Payloads deliberately do not carry session
|
|
45
|
+
* identity.
|
|
46
|
+
*
|
|
47
|
+
* This is a single mutable default on the manager instance: when one
|
|
48
|
+
* manager is shared by concurrent runs, callers MUST pass `sessionId` in
|
|
49
|
+
* the per-emit context instead (as the engine does), otherwise the last
|
|
50
|
+
* `setSessionId()` wins and concurrent emits observe the wrong id.
|
|
51
|
+
*/
|
|
52
|
+
setSessionId(sessionId) {
|
|
53
|
+
this.sessionId = sessionId;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Register a handler for a hook. Returns an unsubscribe function.
|
|
57
|
+
*/
|
|
58
|
+
on(hookName, entry) {
|
|
59
|
+
return this._register(hookName, entry);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Remove a specific handler function from a hook.
|
|
63
|
+
* Returns true if found and removed, false otherwise.
|
|
64
|
+
*/
|
|
65
|
+
off(hookName, handler) {
|
|
66
|
+
const list = this.entries.get(hookName);
|
|
67
|
+
if (!list) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const idx = list.findIndex((e) => e.handler === handler);
|
|
71
|
+
if (idx === -1) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
list.splice(idx, 1);
|
|
75
|
+
if (list.length === 0) {
|
|
76
|
+
this.entries.delete(hookName);
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Remove all handlers for a specific hook, or all handlers if no name given.
|
|
82
|
+
*/
|
|
83
|
+
removeAll(hookName) {
|
|
84
|
+
if (hookName) {
|
|
85
|
+
this.entries.delete(hookName);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this.entries.clear();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Validate the payload (and each handler's result) against the registered
|
|
93
|
+
* Zod schemas, invoke matching handlers, and return results.
|
|
94
|
+
*
|
|
95
|
+
* Payload validation failure is treated according to `throwOnHandlerError`:
|
|
96
|
+
* strict mode re-throws, default mode logs a warning and returns an empty
|
|
97
|
+
* result without invoking any handlers.
|
|
98
|
+
*/
|
|
99
|
+
async emit(hookName, payload, emitContext) {
|
|
100
|
+
// Snapshot the entries list so mutations (on()/off()/unsubscribe) triggered
|
|
101
|
+
// by a handler during the chain can't shift indices mid-iteration and
|
|
102
|
+
// silently skip the next handler, or splice in new handlers that were
|
|
103
|
+
// registered after this emit began.
|
|
104
|
+
const list = (this.entries.get(hookName) ?? []).slice();
|
|
105
|
+
// Validate the payload and, on success, feed the PARSED value into the
|
|
106
|
+
// chain. For schemas with .transform() / .default() / .coerce (or that
|
|
107
|
+
// strip unknown keys) the parsed output differs from the raw input: emit
|
|
108
|
+
// accepts the schema INPUT type (`payloadIn`) while handlers and
|
|
109
|
+
// finalPayload carry the schema OUTPUT (`payload`) -- so handlers must
|
|
110
|
+
// receive `parsed.data`, not the raw value, or the runtime shape silently
|
|
111
|
+
// diverges from the static types.
|
|
112
|
+
let chainPayload = payload;
|
|
113
|
+
const definition = this._definitionFor(hookName);
|
|
114
|
+
if (definition) {
|
|
115
|
+
const parsed = safeParse(definition.payload, payload);
|
|
116
|
+
if (!parsed.success) {
|
|
117
|
+
const err = new Error(`[HooksManager] Invalid payload for hook "${hookName}": ${parsed.error.message}`);
|
|
118
|
+
if (this.throwOnHandlerError) {
|
|
119
|
+
throw err;
|
|
120
|
+
}
|
|
121
|
+
console.warn(err.message);
|
|
122
|
+
return {
|
|
123
|
+
results: [],
|
|
124
|
+
pending: [],
|
|
125
|
+
finalPayload: chainPayload,
|
|
126
|
+
blocked: false,
|
|
127
|
+
mutated: false,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
chainPayload = parsed.data;
|
|
131
|
+
}
|
|
132
|
+
const controller = new AbortController();
|
|
133
|
+
this.inflightControllers.add(controller);
|
|
134
|
+
const context = {
|
|
135
|
+
signal: controller.signal,
|
|
136
|
+
hookName,
|
|
137
|
+
sessionId: emitContext?.sessionId ?? this.sessionId,
|
|
138
|
+
};
|
|
139
|
+
let hasDetachedWork = false;
|
|
140
|
+
try {
|
|
141
|
+
// Result validation is skipped for hooks whose result schema is void --
|
|
142
|
+
// decided by SCHEMA SHAPE, not by a hard-coded name list, so custom
|
|
143
|
+
// hooks registered with `result: z.void()` behave exactly like the
|
|
144
|
+
// built-in void hooks (handlers may return arbitrary values that are
|
|
145
|
+
// collected as opaque results without complaint).
|
|
146
|
+
const resultSchema = definition && !isVoidSchema(definition.result) ? definition.result : undefined;
|
|
147
|
+
const result = await executeHandlerChain(list, chainPayload, context, {
|
|
148
|
+
hookName,
|
|
149
|
+
throwOnHandlerError: this.throwOnHandlerError,
|
|
150
|
+
toolName: emitContext?.toolName,
|
|
151
|
+
resultSchema,
|
|
152
|
+
// When a handler's fire-and-forget work exceeds its asyncTimeout,
|
|
153
|
+
// abort this emit's signal so handlers observing context.signal can
|
|
154
|
+
// cancel the stale work cooperatively.
|
|
155
|
+
onAsyncTimeout: () => {
|
|
156
|
+
controller.abort(new Error('Hook async work timed out'));
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
// Track pending async work for drain(); each promise self-removes once
|
|
160
|
+
// it settles so the set can't grow unbounded across many emits.
|
|
161
|
+
hasDetachedWork = result.pending.length > 0;
|
|
162
|
+
if (hasDetachedWork) {
|
|
163
|
+
let remaining = result.pending.length;
|
|
164
|
+
for (const p of result.pending) {
|
|
165
|
+
this.pendingAsync.add(p);
|
|
166
|
+
p.finally(() => {
|
|
167
|
+
this.pendingAsync.delete(p);
|
|
168
|
+
// The emit's controller must stay registered until the detached
|
|
169
|
+
// work settles so abortInflight() can reach fire-and-forget
|
|
170
|
+
// handlers that outlive the emit call itself.
|
|
171
|
+
remaining--;
|
|
172
|
+
if (remaining === 0) {
|
|
173
|
+
this.inflightControllers.delete(controller);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
finally {
|
|
181
|
+
// With detached work in flight the controller lives until that work
|
|
182
|
+
// settles (see above); otherwise it can be dropped now.
|
|
183
|
+
if (!hasDetachedWork) {
|
|
184
|
+
this.inflightControllers.delete(controller);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Await all in-flight async handler work. Used for graceful shutdown.
|
|
190
|
+
*/
|
|
191
|
+
async drain() {
|
|
192
|
+
while (this.pendingAsync.size > 0) {
|
|
193
|
+
const snapshot = Array.from(this.pendingAsync);
|
|
194
|
+
await Promise.allSettled(snapshot);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Abort every in-flight `emit()` by firing their context `signal`s. Handlers
|
|
199
|
+
* that kick off async work should observe `context.signal` to honor this.
|
|
200
|
+
*
|
|
201
|
+
* Does not remove pending async work from `pendingAsync` — callers that want
|
|
202
|
+
* to wait for handlers to wind down should still call `drain()` afterward.
|
|
203
|
+
*/
|
|
204
|
+
abortInflight(reason) {
|
|
205
|
+
for (const controller of this.inflightControllers) {
|
|
206
|
+
controller.abort(reason);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Check if any handlers are registered for a given hook.
|
|
211
|
+
*/
|
|
212
|
+
hasHandlers(hookName) {
|
|
213
|
+
const list = this.entries.get(hookName);
|
|
214
|
+
return list !== undefined && list.length > 0;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Internal registration path used by `resolveHooks` to translate an
|
|
218
|
+
* InlineHookConfig object into this manager. User code should use `on()`.
|
|
219
|
+
*/
|
|
220
|
+
[INTERNAL_REGISTRAR_KEY](hookName, entry) {
|
|
221
|
+
return this._register(hookName, entry);
|
|
222
|
+
}
|
|
223
|
+
_register(hookName, entry) {
|
|
224
|
+
const list = this.entries.get(hookName) ?? [];
|
|
225
|
+
list.push(entry);
|
|
226
|
+
this.entries.set(hookName, list);
|
|
227
|
+
return () => {
|
|
228
|
+
const current = this.entries.get(hookName);
|
|
229
|
+
if (!current) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const idx = current.indexOf(entry);
|
|
233
|
+
if (idx !== -1) {
|
|
234
|
+
current.splice(idx, 1);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
_definitionFor(hookName) {
|
|
239
|
+
const builtIn = BUILT_IN_HOOKS[hookName];
|
|
240
|
+
if (builtIn) {
|
|
241
|
+
return builtIn;
|
|
242
|
+
}
|
|
243
|
+
const custom = this.customHooks[hookName];
|
|
244
|
+
if (custom) {
|
|
245
|
+
return custom;
|
|
246
|
+
}
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Internal: return the private registrar of a HooksManager instance. This
|
|
252
|
+
* lets `resolveHooks` register arbitrary hook names (including unknown ones
|
|
253
|
+
* from an inline config) without exposing a public bypass of the typed `on()`.
|
|
254
|
+
*
|
|
255
|
+
* NOT PART OF THE PUBLIC API.
|
|
256
|
+
*/
|
|
257
|
+
export function getInternalRegistrar(manager) {
|
|
258
|
+
return manager[INTERNAL_REGISTRAR_KEY].bind(manager);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Detect a `z.void()` schema (zod v4 core). Result validation is skipped for
|
|
262
|
+
* void-result hooks so side-effect-only handlers can return arbitrary values
|
|
263
|
+
* without tripping validation -- for built-ins and custom hooks alike.
|
|
264
|
+
*
|
|
265
|
+
* Implementation note: `schema._zod.def.type` is zod v4's designated
|
|
266
|
+
* introspection surface for library authors (every `$ZodType` carries a
|
|
267
|
+
* `_zod: $ZodTypeInternals` with a stable `def.type` discriminator). A string
|
|
268
|
+
* check is deliberately preferred over `instanceof $ZodVoid`, which breaks
|
|
269
|
+
* across duplicated zod module instances (dual-package hazard) and mixed
|
|
270
|
+
* zod/v4 vs zod/v4-mini usage. Behavior is pinned by tests in
|
|
271
|
+
* hooks-contract-fixes.test.ts ("void schema detection") so a zod upgrade
|
|
272
|
+
* that restructures the internals fails loudly instead of silently
|
|
273
|
+
* re-enabling result validation on void hooks.
|
|
274
|
+
*
|
|
275
|
+
* Exported for the pinning tests only; NOT re-exported from the package
|
|
276
|
+
* index and NOT part of the public API.
|
|
277
|
+
*/
|
|
278
|
+
export function isVoidSchema(schema) {
|
|
279
|
+
const def = schema._zod?.def;
|
|
280
|
+
return def?.type === 'void';
|
|
281
|
+
}
|
|
282
|
+
//# sourceMappingURL=hooks-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-manager.js","sourceRoot":"","sources":["../../src/lib/hooks-manager.ts"],"names":[],"mappings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,CAAC,CAAC;YAC3C,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,OAAO;YACT,CAAC;YACD,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACnC,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;gBACf,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YACzB,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;IAEO,cAAc,CAAC,QAAgB;QAMrC,MAAM,OAAO,GAAI,cAA6D,CAAC,QAAQ,CAAC,CAAC;QACzF,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC1C,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAqB;IACxD,OAAO,OAAO,CAAC,sBAAsB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,YAAY,CAAC,MAAgB;IAC3C,MAAM,GAAG,GACP,MAOD,CAAC,IAAI,EAAE,GAAG,CAAC;IACZ,OAAO,GAAG,EAAE,IAAI,KAAK,MAAM,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ToolMatcher } from './hooks-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Evaluate a ToolMatcher against a tool name.
|
|
4
|
+
*
|
|
5
|
+
* - `undefined` -> wildcard, matches all tools
|
|
6
|
+
* - `string` -> exact match
|
|
7
|
+
* - `RegExp` -> `.test(toolName)`
|
|
8
|
+
* - `function` -> arbitrary predicate (truthy/falsy returns are coerced to
|
|
9
|
+
* boolean so the declared `boolean` return type holds at runtime)
|
|
10
|
+
*/
|
|
11
|
+
export declare function matchesTool(matcher: ToolMatcher | undefined, toolName: string): boolean;
|
|
12
|
+
//# sourceMappingURL=hooks-matchers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-matchers.d.ts","sourceRoot":"","sources":["../../src/lib/hooks-matchers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAevF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evaluate a ToolMatcher against a tool name.
|
|
3
|
+
*
|
|
4
|
+
* - `undefined` -> wildcard, matches all tools
|
|
5
|
+
* - `string` -> exact match
|
|
6
|
+
* - `RegExp` -> `.test(toolName)`
|
|
7
|
+
* - `function` -> arbitrary predicate (truthy/falsy returns are coerced to
|
|
8
|
+
* boolean so the declared `boolean` return type holds at runtime)
|
|
9
|
+
*/
|
|
10
|
+
export function matchesTool(matcher, toolName) {
|
|
11
|
+
if (matcher === undefined) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
if (typeof matcher === 'string') {
|
|
15
|
+
return matcher === toolName;
|
|
16
|
+
}
|
|
17
|
+
if (matcher instanceof RegExp) {
|
|
18
|
+
// RegExps with the /g or /y flag advance `lastIndex` on every `.test()`,
|
|
19
|
+
// so successive emits with the same tool name alternate true/false.
|
|
20
|
+
// Reset so the matcher behaves statelessly regardless of flag.
|
|
21
|
+
matcher.lastIndex = 0;
|
|
22
|
+
return matcher.test(toolName);
|
|
23
|
+
}
|
|
24
|
+
return Boolean(matcher(toolName));
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=hooks-matchers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-matchers.js","sourceRoot":"","sources":["../../src/lib/hooks-matchers.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,OAAgC,EAAE,QAAgB;IAC5E,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,OAAO,KAAK,QAAQ,CAAC;IAC9B,CAAC;IACD,IAAI,OAAO,YAAY,MAAM,EAAE,CAAC;QAC9B,yEAAyE;QACzE,oEAAoE;QACpE,+DAA+D;QAC/D,OAAO,CAAC,SAAS,GAAG,CAAC,CAAC;QACtB,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HooksManager } from './hooks-manager.js';
|
|
2
|
+
import type { InlineHookConfig } from './hooks-types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Normalize a hooks option into a HooksManager instance.
|
|
5
|
+
*
|
|
6
|
+
* - `undefined` -> `undefined` (no hooks)
|
|
7
|
+
* - `HooksManager` -> passthrough
|
|
8
|
+
* - Plain object (InlineHookConfig) -> construct HooksManager, register all entries
|
|
9
|
+
*
|
|
10
|
+
* The inline config surface is typed to only accept built-in hook names, but
|
|
11
|
+
* a generic config coerced through `as` can smuggle typos past the compiler
|
|
12
|
+
* (e.g. `PretoolUse` vs `PreToolUse`) which would silently never fire. We log
|
|
13
|
+
* a warning for any non-built-in key and skip registration for it. Custom
|
|
14
|
+
* hooks must be registered through a `HooksManager` instance via `on()`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveHooks(hooks: InlineHookConfig | HooksManager | undefined): HooksManager | undefined;
|
|
17
|
+
//# sourceMappingURL=hooks-resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-resolve.d.ts","sourceRoot":"","sources":["../../src/lib/hooks-resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,KAAK,EAAa,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpE;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,gBAAgB,GAAG,YAAY,GAAG,SAAS,GACjD,YAAY,GAAG,SAAS,CA6B1B"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { getInternalRegistrar, HooksManager } from './hooks-manager.js';
|
|
2
|
+
import { BUILT_IN_HOOK_NAMES } from './hooks-schemas.js';
|
|
3
|
+
/**
|
|
4
|
+
* Normalize a hooks option into a HooksManager instance.
|
|
5
|
+
*
|
|
6
|
+
* - `undefined` -> `undefined` (no hooks)
|
|
7
|
+
* - `HooksManager` -> passthrough
|
|
8
|
+
* - Plain object (InlineHookConfig) -> construct HooksManager, register all entries
|
|
9
|
+
*
|
|
10
|
+
* The inline config surface is typed to only accept built-in hook names, but
|
|
11
|
+
* a generic config coerced through `as` can smuggle typos past the compiler
|
|
12
|
+
* (e.g. `PretoolUse` vs `PreToolUse`) which would silently never fire. We log
|
|
13
|
+
* a warning for any non-built-in key and skip registration for it. Custom
|
|
14
|
+
* hooks must be registered through a `HooksManager` instance via `on()`.
|
|
15
|
+
*/
|
|
16
|
+
export function resolveHooks(hooks) {
|
|
17
|
+
if (!hooks) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
if (hooks instanceof HooksManager) {
|
|
21
|
+
return hooks;
|
|
22
|
+
}
|
|
23
|
+
// Inline config -> HooksManager. We register through the internal registrar
|
|
24
|
+
// so we don't have to constrain `resolveHooks` to the typed `on()` surface
|
|
25
|
+
// and so user code can't reach this path.
|
|
26
|
+
const manager = new HooksManager();
|
|
27
|
+
const register = getInternalRegistrar(manager);
|
|
28
|
+
for (const [hookName, entries] of Object.entries(hooks)) {
|
|
29
|
+
if (!entries || !Array.isArray(entries)) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (!BUILT_IN_HOOK_NAMES.has(hookName)) {
|
|
33
|
+
console.warn(`[resolveHooks] Ignoring inline hook entry for unknown hook name "${hookName}". Inline config only supports built-in hooks; register custom hooks via a HooksManager instance.`);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
for (const entry of entries) {
|
|
37
|
+
register(hookName, entry);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return manager;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=hooks-resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-resolve.js","sourceRoot":"","sources":["../../src/lib/hooks-resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAGzD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAkD;IAElD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,4EAA4E;IAC5E,2EAA2E;IAC3E,0CAA0C;IAC1C,MAAM,OAAO,GAAG,IAAI,YAAY,EAAE,CAAC;IACnC,MAAM,QAAQ,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC/C,KAAK,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACxD,IAAI,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACxC,SAAS;QACX,CAAC;QACD,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvC,OAAO,CAAC,IAAI,CACV,oEAAoE,QAAQ,mGAAmG,CAChL,CAAC;YACF,SAAS;QACX,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC5B,QAAQ,CAAC,QAAQ,EAAE,KAAoC,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,221 @@
|
|
|
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
|
+
readonly DoomLoopDetected: "DoomLoopDetected";
|
|
14
|
+
};
|
|
15
|
+
export type HookName = (typeof HookName)[keyof typeof HookName];
|
|
16
|
+
/**
|
|
17
|
+
* A hook definition is a pair of Zod schemas: one for the payload and one for the result.
|
|
18
|
+
*/
|
|
19
|
+
export interface HookDefinition {
|
|
20
|
+
readonly payload: $ZodType;
|
|
21
|
+
readonly result: $ZodType;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A registry maps hook names to their definitions.
|
|
25
|
+
*/
|
|
26
|
+
export type HookRegistry = Record<string, HookDefinition>;
|
|
27
|
+
export declare const PreToolUsePayloadSchema: z4.ZodObject<{
|
|
28
|
+
toolName: z4.ZodString;
|
|
29
|
+
toolInput: z4.ZodRecord<z4.ZodString, z4.ZodUnknown>;
|
|
30
|
+
}, z4.z.core.$strip>;
|
|
31
|
+
export type PreToolUsePayload = Readonly<z4.infer<typeof PreToolUsePayloadSchema>>;
|
|
32
|
+
export declare const PostToolUsePayloadSchema: z4.ZodObject<{
|
|
33
|
+
toolName: z4.ZodString;
|
|
34
|
+
toolInput: z4.ZodRecord<z4.ZodString, z4.ZodUnknown>;
|
|
35
|
+
toolOutput: z4.ZodUnknown;
|
|
36
|
+
durationMs: z4.ZodNumber;
|
|
37
|
+
}, z4.z.core.$strip>;
|
|
38
|
+
export type PostToolUsePayload = Readonly<z4.infer<typeof PostToolUsePayloadSchema>>;
|
|
39
|
+
export declare const PostToolUseFailurePayloadSchema: z4.ZodObject<{
|
|
40
|
+
toolName: z4.ZodString;
|
|
41
|
+
toolInput: z4.ZodRecord<z4.ZodString, z4.ZodUnknown>;
|
|
42
|
+
error: z4.ZodUnknown;
|
|
43
|
+
}, z4.z.core.$strip>;
|
|
44
|
+
/**
|
|
45
|
+
* Fired when a tool EXECUTION throws or returns an error.
|
|
46
|
+
*
|
|
47
|
+
* Deliberately NOT fired when a tool never ran: a PermissionRequest 'deny',
|
|
48
|
+
* a user rejection on approval resume, or a PreToolUse block all synthesize
|
|
49
|
+
* a rejected result without execution, so no failure event is emitted.
|
|
50
|
+
* Observe those outcomes via the PermissionRequest / PreToolUse hooks
|
|
51
|
+
* themselves.
|
|
52
|
+
*/
|
|
53
|
+
export type PostToolUseFailurePayload = Readonly<z4.infer<typeof PostToolUseFailurePayloadSchema>>;
|
|
54
|
+
export declare const StopPayloadSchema: z4.ZodObject<{
|
|
55
|
+
reason: z4.ZodEnum<{
|
|
56
|
+
max_turns: "max_turns";
|
|
57
|
+
}>;
|
|
58
|
+
}, z4.z.core.$strip>;
|
|
59
|
+
export type StopPayload = Readonly<z4.infer<typeof StopPayloadSchema>>;
|
|
60
|
+
export declare const PermissionRequestPayloadSchema: z4.ZodObject<{
|
|
61
|
+
toolName: z4.ZodString;
|
|
62
|
+
toolInput: z4.ZodRecord<z4.ZodString, z4.ZodUnknown>;
|
|
63
|
+
riskLevel: z4.ZodEnum<{
|
|
64
|
+
low: "low";
|
|
65
|
+
high: "high";
|
|
66
|
+
medium: "medium";
|
|
67
|
+
}>;
|
|
68
|
+
}, z4.z.core.$strip>;
|
|
69
|
+
export type PermissionRequestPayload = Readonly<z4.infer<typeof PermissionRequestPayloadSchema>>;
|
|
70
|
+
export declare const UserPromptSubmitPayloadSchema: z4.ZodObject<{
|
|
71
|
+
prompt: z4.ZodString;
|
|
72
|
+
}, z4.z.core.$strip>;
|
|
73
|
+
export type UserPromptSubmitPayload = Readonly<z4.infer<typeof UserPromptSubmitPayloadSchema>>;
|
|
74
|
+
export declare const SessionStartPayloadSchema: z4.ZodObject<{
|
|
75
|
+
config: z4.ZodOptional<z4.ZodRecord<z4.ZodString, z4.ZodUnknown>>;
|
|
76
|
+
}, z4.z.core.$strip>;
|
|
77
|
+
declare const ModelCallUsageSchema: z4.ZodObject<{
|
|
78
|
+
inputTokens: z4.ZodNumber;
|
|
79
|
+
outputTokens: z4.ZodNumber;
|
|
80
|
+
totalTokens: z4.ZodNumber;
|
|
81
|
+
cachedTokens: z4.ZodNumber;
|
|
82
|
+
reasoningTokens: z4.ZodNumber;
|
|
83
|
+
cost: z4.ZodOptional<z4.ZodNumber>;
|
|
84
|
+
}, z4.z.core.$strip>;
|
|
85
|
+
export type ModelCallUsage = Readonly<z4.infer<typeof ModelCallUsageSchema>>;
|
|
86
|
+
export type SessionStartPayload = Readonly<z4.infer<typeof SessionStartPayloadSchema>>;
|
|
87
|
+
declare const SessionUsageTotalsSchema: z4.ZodObject<{
|
|
88
|
+
inputTokens: z4.ZodNumber;
|
|
89
|
+
outputTokens: z4.ZodNumber;
|
|
90
|
+
totalTokens: z4.ZodNumber;
|
|
91
|
+
cachedTokens: z4.ZodNumber;
|
|
92
|
+
reasoningTokens: z4.ZodNumber;
|
|
93
|
+
cost: z4.ZodOptional<z4.ZodNumber>;
|
|
94
|
+
modelCalls: z4.ZodNumber;
|
|
95
|
+
}, z4.z.core.$strip>;
|
|
96
|
+
export declare const SessionEndPayloadSchema: z4.ZodObject<{
|
|
97
|
+
reason: z4.ZodEnum<{
|
|
98
|
+
error: "error";
|
|
99
|
+
complete: "complete";
|
|
100
|
+
user: "user";
|
|
101
|
+
max_turns: "max_turns";
|
|
102
|
+
doom_loop: "doom_loop";
|
|
103
|
+
}>;
|
|
104
|
+
totalUsage: z4.ZodOptional<z4.ZodObject<{
|
|
105
|
+
inputTokens: z4.ZodNumber;
|
|
106
|
+
outputTokens: z4.ZodNumber;
|
|
107
|
+
totalTokens: z4.ZodNumber;
|
|
108
|
+
cachedTokens: z4.ZodNumber;
|
|
109
|
+
reasoningTokens: z4.ZodNumber;
|
|
110
|
+
cost: z4.ZodOptional<z4.ZodNumber>;
|
|
111
|
+
modelCalls: z4.ZodNumber;
|
|
112
|
+
}, z4.z.core.$strip>>;
|
|
113
|
+
}, z4.z.core.$strip>;
|
|
114
|
+
export declare const PostModelCallPayloadSchema: z4.ZodObject<{
|
|
115
|
+
sessionId: z4.ZodString;
|
|
116
|
+
responseId: z4.ZodString;
|
|
117
|
+
model: z4.ZodString;
|
|
118
|
+
durationMs: z4.ZodNumber;
|
|
119
|
+
turnType: z4.ZodEnum<{
|
|
120
|
+
initial: "initial";
|
|
121
|
+
resume: "resume";
|
|
122
|
+
tool_round: "tool_round";
|
|
123
|
+
final: "final";
|
|
124
|
+
retry: "retry";
|
|
125
|
+
}>;
|
|
126
|
+
turnNumber: z4.ZodNumber;
|
|
127
|
+
usage: z4.ZodOptional<z4.ZodObject<{
|
|
128
|
+
inputTokens: z4.ZodNumber;
|
|
129
|
+
outputTokens: z4.ZodNumber;
|
|
130
|
+
totalTokens: z4.ZodNumber;
|
|
131
|
+
cachedTokens: z4.ZodNumber;
|
|
132
|
+
reasoningTokens: z4.ZodNumber;
|
|
133
|
+
cost: z4.ZodOptional<z4.ZodNumber>;
|
|
134
|
+
}, z4.z.core.$strip>>;
|
|
135
|
+
}, z4.z.core.$strip>;
|
|
136
|
+
export declare const DoomLoopDetectedPayloadSchema: z4.ZodObject<{
|
|
137
|
+
detector: z4.ZodEnum<{
|
|
138
|
+
"tool-fingerprint": "tool-fingerprint";
|
|
139
|
+
"server-tool-fingerprint": "server-tool-fingerprint";
|
|
140
|
+
"text-repetition": "text-repetition";
|
|
141
|
+
"text-streak": "text-streak";
|
|
142
|
+
}>;
|
|
143
|
+
action: z4.ZodEnum<{
|
|
144
|
+
observe: "observe";
|
|
145
|
+
steer: "steer";
|
|
146
|
+
escalate: "escalate";
|
|
147
|
+
block: "block";
|
|
148
|
+
stop: "stop";
|
|
149
|
+
}>;
|
|
150
|
+
streak: z4.ZodNumber;
|
|
151
|
+
fingerprint: z4.ZodString;
|
|
152
|
+
toolName: z4.ZodOptional<z4.ZodString>;
|
|
153
|
+
toolInput: z4.ZodOptional<z4.ZodRecord<z4.ZodString, z4.ZodUnknown>>;
|
|
154
|
+
message: z4.ZodString;
|
|
155
|
+
}, z4.z.core.$strip>;
|
|
156
|
+
export type DoomLoopDetectedPayload = Readonly<z4.infer<typeof DoomLoopDetectedPayloadSchema>>;
|
|
157
|
+
export type SessionEndPayload = Readonly<z4.infer<typeof SessionEndPayloadSchema>>;
|
|
158
|
+
export type PostModelCallPayload = Readonly<z4.infer<typeof PostModelCallPayloadSchema>>;
|
|
159
|
+
export type SessionUsageTotals = Readonly<z4.infer<typeof SessionUsageTotalsSchema>>;
|
|
160
|
+
export declare const PreToolUseResultSchema: z4.ZodObject<{
|
|
161
|
+
mutatedInput: z4.ZodOptional<z4.ZodRecord<z4.ZodString, z4.ZodUnknown>>;
|
|
162
|
+
block: z4.ZodOptional<z4.ZodUnion<readonly [z4.ZodBoolean, z4.ZodString]>>;
|
|
163
|
+
}, z4.z.core.$strip>;
|
|
164
|
+
export type PreToolUseResult = Readonly<z4.infer<typeof PreToolUseResultSchema>>;
|
|
165
|
+
export declare const StopResultSchema: z4.ZodObject<{
|
|
166
|
+
forceResume: z4.ZodOptional<z4.ZodBoolean>;
|
|
167
|
+
appendPrompt: z4.ZodOptional<z4.ZodString>;
|
|
168
|
+
}, z4.z.core.$strip>;
|
|
169
|
+
/**
|
|
170
|
+
* Result of a Stop hook handler.
|
|
171
|
+
*
|
|
172
|
+
* `forceResume: true` alone does NOT change any state: the stop condition
|
|
173
|
+
* (e.g. `stepCountIs`) will typically fire again immediately on the next
|
|
174
|
+
* iteration, so a bare forceResume burns through the consecutive-override
|
|
175
|
+
* cap (3) in rapid succession and then stops. To make resumption useful,
|
|
176
|
+
* pair it with `appendPrompt` (which injects a user message, advancing the
|
|
177
|
+
* conversation) or use a stop condition whose predicate can change between
|
|
178
|
+
* iterations. This is by design: the engine caps rather than blocks bare
|
|
179
|
+
* forceResume so a handler that coordinates external state (e.g. waiting on
|
|
180
|
+
* an async gate that flips the stop condition) still has a few iterations
|
|
181
|
+
* to do so.
|
|
182
|
+
*
|
|
183
|
+
* `appendPrompt` is honored independently of `forceResume` — a handler can
|
|
184
|
+
* nudge the next turn without forcing a resume. Multiple handlers'
|
|
185
|
+
* appendPrompts are concatenated with newlines.
|
|
186
|
+
*
|
|
187
|
+
* The override counter resets when a tool round produces outputs or a fresh
|
|
188
|
+
* model response lands. Note that hook-blocked and rejected tool outputs
|
|
189
|
+
* count as progress: the model receives the block/denial feedback and can
|
|
190
|
+
* change course, which is observable forward motion even though no tool
|
|
191
|
+
* body executed.
|
|
192
|
+
*/
|
|
193
|
+
export type StopResult = Readonly<z4.infer<typeof StopResultSchema>>;
|
|
194
|
+
export declare const PermissionRequestResultSchema: z4.ZodObject<{
|
|
195
|
+
decision: z4.ZodEnum<{
|
|
196
|
+
allow: "allow";
|
|
197
|
+
deny: "deny";
|
|
198
|
+
ask_user: "ask_user";
|
|
199
|
+
}>;
|
|
200
|
+
reason: z4.ZodOptional<z4.ZodString>;
|
|
201
|
+
}, z4.z.core.$strip>;
|
|
202
|
+
export type PermissionRequestResult = Readonly<z4.infer<typeof PermissionRequestResultSchema>>;
|
|
203
|
+
export declare const UserPromptSubmitResultSchema: z4.ZodObject<{
|
|
204
|
+
mutatedPrompt: z4.ZodOptional<z4.ZodString>;
|
|
205
|
+
reject: z4.ZodOptional<z4.ZodUnion<readonly [z4.ZodBoolean, z4.ZodString]>>;
|
|
206
|
+
}, z4.z.core.$strip>;
|
|
207
|
+
export type UserPromptSubmitResult = Readonly<z4.infer<typeof UserPromptSubmitResultSchema>>;
|
|
208
|
+
export declare const DoomLoopDetectedResultSchema: z4.ZodObject<{
|
|
209
|
+
overrideAction: z4.ZodOptional<z4.ZodEnum<{
|
|
210
|
+
observe: "observe";
|
|
211
|
+
steer: "steer";
|
|
212
|
+
escalate: "escalate";
|
|
213
|
+
block: "block";
|
|
214
|
+
stop: "stop";
|
|
215
|
+
}>>;
|
|
216
|
+
}, z4.z.core.$strip>;
|
|
217
|
+
export type DoomLoopDetectedResult = Readonly<z4.infer<typeof DoomLoopDetectedResultSchema>>;
|
|
218
|
+
export declare const BUILT_IN_HOOKS: Record<HookName, HookDefinition>;
|
|
219
|
+
export declare const BUILT_IN_HOOK_NAMES: Set<string>;
|
|
220
|
+
export {};
|
|
221
|
+
//# 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;;;;;;;;;;;CAWX,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,cAA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