@wrongstack/core 0.1.9 → 0.2.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/dist/agent-bridge-DmBiCipY.d.ts +33 -0
- package/dist/compactor-DSl2FK7a.d.ts +17 -0
- package/dist/config-DXrqb41m.d.ts +193 -0
- package/dist/{provider-txgB0Oq9.d.ts → context-u0bryklF.d.ts} +540 -472
- package/dist/coordination/index.d.ts +892 -0
- package/dist/coordination/index.js +2869 -0
- package/dist/coordination/index.js.map +1 -0
- package/dist/defaults/index.d.ts +34 -2309
- package/dist/defaults/index.js +5610 -4608
- package/dist/defaults/index.js.map +1 -1
- package/dist/events-B6Q03pTu.d.ts +290 -0
- package/dist/execution/index.d.ts +260 -0
- package/dist/execution/index.js +1625 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/index.d.ts +81 -11
- package/dist/index.js +7727 -6174
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/index.d.ts +10 -0
- package/dist/infrastructure/index.js +575 -0
- package/dist/infrastructure/index.js.map +1 -0
- package/dist/input-reader-E-ffP2ee.d.ts +12 -0
- package/dist/kernel/index.d.ts +15 -4
- package/dist/kernel/index.js.map +1 -1
- package/dist/logger-BH6AE0W9.d.ts +24 -0
- package/dist/logger-BMQgxvdy.d.ts +12 -0
- package/dist/mcp-servers-BA1Ofmfj.d.ts +100 -0
- package/dist/memory-CEXuo7sz.d.ts +16 -0
- package/dist/mode-CV077NjV.d.ts +27 -0
- package/dist/models/index.d.ts +60 -0
- package/dist/models/index.js +621 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models-registry-DqzwpBQy.d.ts +46 -0
- package/dist/models-registry-Y2xbog0E.d.ts +95 -0
- package/dist/multi-agent-BDfkxL5C.d.ts +351 -0
- package/dist/observability/index.d.ts +353 -0
- package/dist/observability/index.js +691 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability-BhnVLBLS.d.ts +67 -0
- package/dist/path-resolver-CPRj4bFY.d.ts +10 -0
- package/dist/path-resolver-Crkt8wTQ.d.ts +54 -0
- package/dist/plugin-CoYYZKdn.d.ts +447 -0
- package/dist/renderer-0A2ZEtca.d.ts +158 -0
- package/dist/sdd/index.d.ts +206 -0
- package/dist/sdd/index.js +864 -0
- package/dist/sdd/index.js.map +1 -0
- package/dist/secret-scrubber-3TLUkiCV.d.ts +31 -0
- package/dist/secret-scrubber-CwYliRWd.d.ts +54 -0
- package/dist/secret-vault-DoISxaKO.d.ts +19 -0
- package/dist/security/index.d.ts +46 -0
- package/dist/security/index.js +536 -0
- package/dist/security/index.js.map +1 -0
- package/dist/selector-BRqzvugb.d.ts +51 -0
- package/dist/session-reader-C3x96CDR.d.ts +150 -0
- package/dist/skill-Bx8jxznf.d.ts +72 -0
- package/dist/storage/index.d.ts +540 -0
- package/dist/storage/index.js +1802 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/{system-prompt-vAB0F54-.d.ts → system-prompt-CG9jU5-5.d.ts} +9 -1
- package/dist/task-graph-BITvWt4t.d.ts +160 -0
- package/dist/tool-executor-CYdZdtno.d.ts +97 -0
- package/dist/types/index.d.ts +26 -4
- package/dist/types/index.js +1787 -4
- package/dist/types/index.js.map +1 -1
- package/dist/utils/index.d.ts +49 -2
- package/dist/utils/index.js +100 -2
- package/dist/utils/index.js.map +1 -1
- package/package.json +34 -2
- package/dist/mode-Pjt5vMS6.d.ts +0 -815
- package/dist/session-reader-9sOTgmeC.d.ts +0 -1087
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
import { u as Tool, z as ToolResultBlock, g as Provider, R as Request, j as Response, D as ToolUseBlock, a0 as Context, b as ContentBlock, T as TextBlock, a7 as RunOptions, W as WrongStackError, J as JSONSchema } from './context-u0bryklF.js';
|
|
2
|
+
import { T as Tracer } from './observability-BhnVLBLS.js';
|
|
3
|
+
import { E as EventBus, a as EventName, L as Listener } from './events-B6Q03pTu.js';
|
|
4
|
+
import { R as Renderer, C as Container, P as Pipeline, c as ReadonlyPipeline } from './renderer-0A2ZEtca.js';
|
|
5
|
+
import { a as PermissionPolicy, S as SecretScrubber } from './secret-scrubber-3TLUkiCV.js';
|
|
6
|
+
import { e as ProviderConfig, C as Config } from './config-DXrqb41m.js';
|
|
7
|
+
import { W as WireFamily } from './models-registry-Y2xbog0E.js';
|
|
8
|
+
import { L as Logger } from './logger-BMQgxvdy.js';
|
|
9
|
+
|
|
10
|
+
declare class ToolRegistry {
|
|
11
|
+
private readonly tools;
|
|
12
|
+
register(tool: Tool, owner?: string): void;
|
|
13
|
+
/**
|
|
14
|
+
* Attempt to register a tool. Returns true if successful, false if a tool
|
|
15
|
+
* with the same name is already registered. Useful in multi-agent or plugin
|
|
16
|
+
* scenarios where duplicate registration may be intentional.
|
|
17
|
+
*/
|
|
18
|
+
tryRegister(tool: Tool, owner?: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Register a tool as a default. If the tool name is already registered,
|
|
21
|
+
* this is a no-op — the existing registration (from core or another
|
|
22
|
+
* plugin) takes precedence. Use `override` to intentionally replace.
|
|
23
|
+
*/
|
|
24
|
+
registerDefault(tool: Tool, owner?: string): void;
|
|
25
|
+
unregister(name: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Override an existing tool. Throws if the tool is not already registered.
|
|
28
|
+
* Plugins use this to replace built-in tools with custom implementations.
|
|
29
|
+
*/
|
|
30
|
+
override(name: string, tool: Tool, owner?: string): void;
|
|
31
|
+
get(name: string): Tool | undefined;
|
|
32
|
+
ownerOf(name: string): string | undefined;
|
|
33
|
+
list(): Tool[];
|
|
34
|
+
listWithOwner(): {
|
|
35
|
+
tool: Tool;
|
|
36
|
+
owner: string;
|
|
37
|
+
}[];
|
|
38
|
+
clear(): void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Output from a single tool execution.
|
|
43
|
+
*/
|
|
44
|
+
interface ToolExecutionOutput {
|
|
45
|
+
result: ToolResultBlock | ToolConfirmPendingResult;
|
|
46
|
+
tool?: Tool;
|
|
47
|
+
durationMs: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Result of running a batch of tools for a single agent iteration.
|
|
51
|
+
*/
|
|
52
|
+
interface ToolBatchResult {
|
|
53
|
+
outputs: ToolExecutionOutput[];
|
|
54
|
+
remainingBudget: number;
|
|
55
|
+
}
|
|
56
|
+
type ConfirmAwaiter = (tool: Tool, input: unknown, toolUseId: string, suggestedPattern: string) => Promise<'yes' | 'no' | 'always' | 'deny'>;
|
|
57
|
+
interface ToolExecutorOptions {
|
|
58
|
+
permissionPolicy: PermissionPolicy;
|
|
59
|
+
secretScrubber: SecretScrubber;
|
|
60
|
+
renderer?: Renderer | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Optional event bus. When provided, the executor emits `tool.started`
|
|
63
|
+
* before invoking each tool's `execute()`. Closes the observability gap
|
|
64
|
+
* between "model decided to call tool" and "tool finished".
|
|
65
|
+
*/
|
|
66
|
+
events?: EventBus | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Optional tracer. When provided, every tool execution opens a
|
|
69
|
+
* `tool.<name>` span with attributes for tool name, permission decision,
|
|
70
|
+
* input size, output size, and outcome. Spans are no-op by default.
|
|
71
|
+
*/
|
|
72
|
+
tracer?: Tracer | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Async callback invoked when a tool needs user confirmation.
|
|
75
|
+
* When omitted and confirmation is required, the executor returns a
|
|
76
|
+
* failure result immediately (TUI path). When provided (CLI path),
|
|
77
|
+
* the callback handles the interactive prompt and returns a decision.
|
|
78
|
+
*/
|
|
79
|
+
confirmAwaiter?: ConfirmAwaiter | undefined;
|
|
80
|
+
iterationTimeoutMs?: number;
|
|
81
|
+
perIterationOutputCapBytes?: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Result returned by executeBatch when a tool needs confirmation and
|
|
85
|
+
* no confirmAwaiter is available. The TUI catches this and surfaces a
|
|
86
|
+
* confirmation dialog; once resolved the tool is re-executed.
|
|
87
|
+
* The string tag identifies it as a "pending confirm" result so callers
|
|
88
|
+
* can distinguish it from an error without inspecting content strings.
|
|
89
|
+
*/
|
|
90
|
+
interface ToolConfirmPendingResult {
|
|
91
|
+
type: 'tool_confirm_pending';
|
|
92
|
+
toolUseId: string;
|
|
93
|
+
toolName: string;
|
|
94
|
+
input: unknown;
|
|
95
|
+
suggestedPattern: string;
|
|
96
|
+
}
|
|
97
|
+
type ToolExecutorStrategy = 'parallel' | 'sequential' | 'smart';
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Factory for constructing a Provider instance. The `family` field
|
|
101
|
+
* declares the wire protocol so callers can route without inspecting
|
|
102
|
+
* the returned instance. The `type` is the registry key (e.g. a
|
|
103
|
+
* provider's models.dev id or a user-chosen alias).
|
|
104
|
+
*/
|
|
105
|
+
interface ProviderFactory$1 {
|
|
106
|
+
/**
|
|
107
|
+
* Unique identifier used as the registry key. When registered via
|
|
108
|
+
* a plugin, this becomes `cfg.type` in `ProviderRegistry.create(cfg)`.
|
|
109
|
+
*/
|
|
110
|
+
type: string;
|
|
111
|
+
/**
|
|
112
|
+
* Declares the wire protocol family so consumers can route based on
|
|
113
|
+
* capability (e.g. which tool-format converter to use) without
|
|
114
|
+
* instantiating the provider.
|
|
115
|
+
*/
|
|
116
|
+
family: WireFamily;
|
|
117
|
+
create(cfg: ProviderConfig): Provider;
|
|
118
|
+
}
|
|
119
|
+
declare class ProviderRegistry {
|
|
120
|
+
private readonly factories;
|
|
121
|
+
/**
|
|
122
|
+
* Register a provider factory. If a factory with the same type already
|
|
123
|
+
* exists, it is replaced. Use this for both initial registration and
|
|
124
|
+
* runtime overrides (e.g. from plugins or CLI flags).
|
|
125
|
+
*/
|
|
126
|
+
register(f: ProviderFactory$1): void;
|
|
127
|
+
/**
|
|
128
|
+
* Override an existing factory. Throws if no factory is registered
|
|
129
|
+
* for the given type. Use this to safely replace a provider at runtime
|
|
130
|
+
* (e.g. in tests or when a plugin provides a custom implementation).
|
|
131
|
+
*/
|
|
132
|
+
override(type: string, f: ProviderFactory$1): void;
|
|
133
|
+
has(type: string): boolean;
|
|
134
|
+
create(cfg: ProviderConfig): Provider;
|
|
135
|
+
list(): string[];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Default iteration cap. Use 0 or Infinity via config to disable. */
|
|
139
|
+
declare const DEFAULT_MAX_ITERATIONS = 100;
|
|
140
|
+
interface RunResult {
|
|
141
|
+
status: 'done' | 'failed' | 'max_iterations' | 'aborted';
|
|
142
|
+
/**
|
|
143
|
+
* Set when `status === 'failed'` (always) or `'aborted'` (when the abort
|
|
144
|
+
* carried an error context). Always a `WrongStackError` so callers can
|
|
145
|
+
* branch on `code`, `severity`, and `recoverable` without parsing strings.
|
|
146
|
+
* Raw throws are wrapped into an `AgentError` with code `AGENT_RUN_FAILED`
|
|
147
|
+
* by `Agent.run` before they reach this field.
|
|
148
|
+
*/
|
|
149
|
+
error?: WrongStackError;
|
|
150
|
+
finalText?: string;
|
|
151
|
+
iterations: number;
|
|
152
|
+
}
|
|
153
|
+
interface AgentInit {
|
|
154
|
+
container: Container;
|
|
155
|
+
tools: ToolRegistry;
|
|
156
|
+
providers: ProviderRegistry;
|
|
157
|
+
events: EventBus;
|
|
158
|
+
pipelines: AgentPipelines;
|
|
159
|
+
context: Context;
|
|
160
|
+
maxIterations?: number;
|
|
161
|
+
iterationTimeoutMs?: number;
|
|
162
|
+
executionStrategy?: 'parallel' | 'sequential' | 'smart';
|
|
163
|
+
perIterationOutputCapBytes?: number;
|
|
164
|
+
/**
|
|
165
|
+
* When true (default), the agent automatically extends its iteration
|
|
166
|
+
* limit by 100 when hit, without asking the user. Set to false to
|
|
167
|
+
* emit `iteration.limit_reached` and wait for a listener to grant/deny.
|
|
168
|
+
*/
|
|
169
|
+
autoExtendLimit?: boolean;
|
|
170
|
+
/**
|
|
171
|
+
* Optional confirm handler. When set, the executor calls it synchronously
|
|
172
|
+
* when a tool needs user confirmation (CLI path). When omitted, the
|
|
173
|
+
* executor returns a `ToolConfirmPendingResult` and the agent emits
|
|
174
|
+
* `tool.confirm_needed` for the TUI to resolve.
|
|
175
|
+
*/
|
|
176
|
+
confirmAwaiter?: ConfirmAwaiter | undefined;
|
|
177
|
+
/**
|
|
178
|
+
* Override the PermissionPolicy resolved from the container. Subagents
|
|
179
|
+
* use this to force auto-approval — they cannot respond to interactive
|
|
180
|
+
* permission prompts, so inheriting the leader's non-YOLO policy would
|
|
181
|
+
* silently hang the entire delegated run on the first tool call.
|
|
182
|
+
*/
|
|
183
|
+
permissionPolicy?: PermissionPolicy;
|
|
184
|
+
/**
|
|
185
|
+
* Optional tracer. When provided, `Agent.run` opens an `agent.run` span,
|
|
186
|
+
* per-iteration `agent.iteration` spans, and `provider.complete` spans
|
|
187
|
+
* inside the retry loop. Tool spans are opened by the ToolExecutor.
|
|
188
|
+
* Default is `NoopTracer` (zero overhead).
|
|
189
|
+
*/
|
|
190
|
+
tracer?: Tracer | undefined;
|
|
191
|
+
}
|
|
192
|
+
interface AgentPipelines {
|
|
193
|
+
request: Pipeline<Request>;
|
|
194
|
+
response: Pipeline<Response>;
|
|
195
|
+
toolCall: Pipeline<ToolCallPipelinePayload>;
|
|
196
|
+
userInput: Pipeline<UserInputPayload>;
|
|
197
|
+
assistantOutput: Pipeline<TextBlock>;
|
|
198
|
+
contextWindow: Pipeline<Context>;
|
|
199
|
+
}
|
|
200
|
+
interface UserInputPayload {
|
|
201
|
+
content: ContentBlock[];
|
|
202
|
+
/** Concatenation of text blocks — convenience for middleware that only cares about text. */
|
|
203
|
+
text: string;
|
|
204
|
+
ctx: Context;
|
|
205
|
+
}
|
|
206
|
+
type AgentInput = string | ContentBlock[];
|
|
207
|
+
interface ToolCallPipelinePayload {
|
|
208
|
+
toolUse: ToolUseBlock;
|
|
209
|
+
result: ToolResultBlock;
|
|
210
|
+
ctx: Context;
|
|
211
|
+
/** Undefined when the model invoked a tool name we don't know. */
|
|
212
|
+
tool?: Tool;
|
|
213
|
+
}
|
|
214
|
+
declare function createDefaultPipelines(): AgentPipelines;
|
|
215
|
+
declare class Agent {
|
|
216
|
+
readonly container: Container;
|
|
217
|
+
readonly tools: ToolRegistry;
|
|
218
|
+
readonly providers: ProviderRegistry;
|
|
219
|
+
readonly events: EventBus;
|
|
220
|
+
readonly pipelines: AgentPipelines;
|
|
221
|
+
readonly ctx: Context;
|
|
222
|
+
private readonly maxIterations;
|
|
223
|
+
private readonly iterationTimeoutMs;
|
|
224
|
+
private readonly executionStrategy;
|
|
225
|
+
private readonly perIterationOutputCapBytes;
|
|
226
|
+
private readonly plugins;
|
|
227
|
+
private readonly toolExecutor;
|
|
228
|
+
private readonly autoExtendLimit;
|
|
229
|
+
private readonly tracer;
|
|
230
|
+
constructor(init: AgentInit);
|
|
231
|
+
private get logger();
|
|
232
|
+
private get retry();
|
|
233
|
+
private get errorHandler();
|
|
234
|
+
private get permission();
|
|
235
|
+
private get scrubber();
|
|
236
|
+
private get renderer();
|
|
237
|
+
register(tool: Tool): void;
|
|
238
|
+
use(plugin: Plugin, api: PluginAPI): Promise<void>;
|
|
239
|
+
run(userInput: AgentInput, opts?: RunOptions): Promise<RunResult>;
|
|
240
|
+
private runInner;
|
|
241
|
+
/**
|
|
242
|
+
* Normalize user input and emit through userInput pipeline + session append.
|
|
243
|
+
*/
|
|
244
|
+
private normalizeAndEmitUserInput;
|
|
245
|
+
/**
|
|
246
|
+
* Check if iteration limit has been reached and request extension if needed.
|
|
247
|
+
* Returns the new effective limit (possibly extended) and a RunResult if
|
|
248
|
+
* the loop should exit. Returns `{ limit }` with no result when the
|
|
249
|
+
* iteration may proceed.
|
|
250
|
+
*/
|
|
251
|
+
private checkIterationLimit;
|
|
252
|
+
/**
|
|
253
|
+
* Build request and run through request pipeline.
|
|
254
|
+
*/
|
|
255
|
+
private buildAndRunRequestPipeline;
|
|
256
|
+
/**
|
|
257
|
+
* Process the provider response: run response pipeline, emit events,
|
|
258
|
+
* update session, render text, handle abort.
|
|
259
|
+
*/
|
|
260
|
+
private processResponse;
|
|
261
|
+
/**
|
|
262
|
+
* Execute tools and append tool results to context.
|
|
263
|
+
* When a tool returns `tool_confirm_pending` (no confirmAwaiter set),
|
|
264
|
+
* we pause and emit `tool.confirm_needed`. The run is blocked until
|
|
265
|
+
* the event listener resolves the confirmation, then we re-run the
|
|
266
|
+
* single tool.
|
|
267
|
+
*/
|
|
268
|
+
private executeTools;
|
|
269
|
+
private waitForConfirm;
|
|
270
|
+
private executeSingleWithDecision;
|
|
271
|
+
/**
|
|
272
|
+
* Run context window pipeline. The pipeline may be empty, or it may contain
|
|
273
|
+
* middleware with its own injected dependencies.
|
|
274
|
+
*/
|
|
275
|
+
private compactContextIfNeeded;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* A slash command registered with the CLI or available to plugins.
|
|
280
|
+
* Plugins receive a view of the registry via PluginAPI.slashCommands.
|
|
281
|
+
*
|
|
282
|
+
* Commands registered by plugins use a namespaced name: `pluginName:commandName`.
|
|
283
|
+
* This prevents collisions with built-in commands and other plugins.
|
|
284
|
+
*/
|
|
285
|
+
interface SlashCommand {
|
|
286
|
+
/** Unique command name. For plugins: `pluginName:commandName`. */
|
|
287
|
+
name: string;
|
|
288
|
+
/** Short aliases — also prefixed automatically: `pluginName:alias`. */
|
|
289
|
+
aliases?: string[];
|
|
290
|
+
description: string;
|
|
291
|
+
/**
|
|
292
|
+
* Optional detailed help shown by `/help <name>`. Use this for usage,
|
|
293
|
+
* arguments, examples, side-effects — anything that doesn't fit in
|
|
294
|
+
* `description`. Renders verbatim, so format with line breaks.
|
|
295
|
+
* If absent, `/help <name>` falls back to `description`.
|
|
296
|
+
*/
|
|
297
|
+
help?: string;
|
|
298
|
+
/**
|
|
299
|
+
* Execute the command.
|
|
300
|
+
* @param args Everything after the command name (trimmed by dispatch).
|
|
301
|
+
* @param ctx The current agent context.
|
|
302
|
+
* @returns `{ exit: true }` to quit the REPL. `{ message }` to print and
|
|
303
|
+
* continue. `{ runText }` to send a follow-up user-role message to the
|
|
304
|
+
* model immediately (e.g. `/steer <text>` builds a STEERING preamble
|
|
305
|
+
* here and asks the TUI to run it as the next turn). The TUI prints
|
|
306
|
+
* `message` first (if any) so the user sees the slash result before
|
|
307
|
+
* the model's response starts streaming.
|
|
308
|
+
*/
|
|
309
|
+
run(args: string, ctx: Context): Promise<{
|
|
310
|
+
exit?: boolean;
|
|
311
|
+
message?: string;
|
|
312
|
+
runText?: string;
|
|
313
|
+
} | void>;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
interface ToolRegistryView {
|
|
317
|
+
register(t: Tool): void;
|
|
318
|
+
unregister(name: string): void;
|
|
319
|
+
get(name: string): Tool | undefined;
|
|
320
|
+
list(): Tool[];
|
|
321
|
+
}
|
|
322
|
+
interface ProviderFactory {
|
|
323
|
+
type: string;
|
|
324
|
+
family: WireFamily;
|
|
325
|
+
create(cfg: unknown): Provider;
|
|
326
|
+
}
|
|
327
|
+
interface ProviderRegistryView {
|
|
328
|
+
register(f: ProviderFactory): void;
|
|
329
|
+
create(cfg: {
|
|
330
|
+
type: string;
|
|
331
|
+
} & Record<string, unknown>): Provider;
|
|
332
|
+
list(): string[];
|
|
333
|
+
}
|
|
334
|
+
interface MCPRegistryView {
|
|
335
|
+
start(cfg: unknown): Promise<void>;
|
|
336
|
+
stop(name: string): Promise<void>;
|
|
337
|
+
restart(name: string): Promise<void>;
|
|
338
|
+
list(): {
|
|
339
|
+
name: string;
|
|
340
|
+
state: string;
|
|
341
|
+
toolCount: number;
|
|
342
|
+
}[];
|
|
343
|
+
}
|
|
344
|
+
interface SlashCommandRegistryView {
|
|
345
|
+
register(cmd: SlashCommand): void;
|
|
346
|
+
unregister(name: string): boolean;
|
|
347
|
+
get(name: string): SlashCommand | undefined;
|
|
348
|
+
list(): SlashCommand[];
|
|
349
|
+
}
|
|
350
|
+
interface PluginPipelines {
|
|
351
|
+
request: ReadonlyPipeline<Request>;
|
|
352
|
+
response: ReadonlyPipeline<Response>;
|
|
353
|
+
toolCall: ReadonlyPipeline<ToolCallPipelinePayload>;
|
|
354
|
+
userInput: ReadonlyPipeline<{
|
|
355
|
+
content: ContentBlock[];
|
|
356
|
+
text: string;
|
|
357
|
+
ctx: Context;
|
|
358
|
+
}>;
|
|
359
|
+
assistantOutput: ReadonlyPipeline<TextBlock>;
|
|
360
|
+
contextWindow: ReadonlyPipeline<Context>;
|
|
361
|
+
[k: string]: ReadonlyPipeline<any>;
|
|
362
|
+
}
|
|
363
|
+
interface PluginAPI {
|
|
364
|
+
container: Container;
|
|
365
|
+
pipelines: PluginPipelines;
|
|
366
|
+
events: EventBus;
|
|
367
|
+
tools: ToolRegistryView;
|
|
368
|
+
providers: ProviderRegistryView;
|
|
369
|
+
mcp: MCPRegistryView;
|
|
370
|
+
slashCommands: SlashCommandRegistryView;
|
|
371
|
+
config: Config;
|
|
372
|
+
log: Logger;
|
|
373
|
+
/**
|
|
374
|
+
* Register a one-time event listener. The handler is automatically removed
|
|
375
|
+
* after the first emission, or when the plugin is uninstalled — whichever
|
|
376
|
+
* comes first.
|
|
377
|
+
*/
|
|
378
|
+
onEvent<K extends EventName>(event: K, handler: Listener<K>): () => void;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Capability declaration — informs the host which subsystems a plugin
|
|
382
|
+
* intends to touch. Used for diagnostics and per-plugin enable/disable UX
|
|
383
|
+
* (e.g. "this plugin registers tools — disable to remove them"). Not
|
|
384
|
+
* enforced at runtime: a plugin that declares `tools: false` can still
|
|
385
|
+
* call `api.tools.register()`, but the host can flag the discrepancy.
|
|
386
|
+
*/
|
|
387
|
+
interface PluginCapabilities {
|
|
388
|
+
/** Will register tools via `api.tools.register()`. */
|
|
389
|
+
tools?: boolean;
|
|
390
|
+
/** Will register provider factories via `api.providers.register()`. */
|
|
391
|
+
providers?: boolean;
|
|
392
|
+
/**
|
|
393
|
+
* Pipelines the plugin hooks into. Use the standard names
|
|
394
|
+
* (`request | response | toolCall | userInput | assistantOutput | contextWindow`)
|
|
395
|
+
* or custom pipeline names exposed by other plugins.
|
|
396
|
+
*/
|
|
397
|
+
pipelines?: string[];
|
|
398
|
+
/** Will register slash commands via `api.slashCommands.register()`. */
|
|
399
|
+
slashCommands?: boolean;
|
|
400
|
+
/** Will start MCP servers via `api.mcp.start()`. */
|
|
401
|
+
mcp?: boolean;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Structured dependency declaration. The string form (`dependsOn: ['foo']`)
|
|
405
|
+
* is shorthand for `[{ name: 'foo' }]` — both work. Use the structured form
|
|
406
|
+
* when you need a version constraint:
|
|
407
|
+
*
|
|
408
|
+
* dependsOn: [{ name: 'wstack-auth', version: '^1.2.0' }]
|
|
409
|
+
*/
|
|
410
|
+
interface PluginDependency {
|
|
411
|
+
name: string;
|
|
412
|
+
/** npm-style semver range. Supports `^`, `~`, exact, and unprefixed. */
|
|
413
|
+
version?: string;
|
|
414
|
+
}
|
|
415
|
+
interface Plugin {
|
|
416
|
+
name: string;
|
|
417
|
+
version?: string;
|
|
418
|
+
/** One-line summary for `wstack plugins list` and error messages. */
|
|
419
|
+
description?: string;
|
|
420
|
+
/** Semver range against the kernel API version (KERNEL_API_VERSION). */
|
|
421
|
+
apiVersion: string;
|
|
422
|
+
/**
|
|
423
|
+
* Capability hints — what subsystems the plugin will register against.
|
|
424
|
+
* Optional; provided for diagnostics and UX. The loader does not enforce
|
|
425
|
+
* these, but mismatch is surfaced via logger at warn level.
|
|
426
|
+
*/
|
|
427
|
+
capabilities?: PluginCapabilities;
|
|
428
|
+
/**
|
|
429
|
+
* JSON Schema for the options under `Config.plugins[<name>].options`.
|
|
430
|
+
* When present, the loader validates that section before calling `setup`
|
|
431
|
+
* and rejects the plugin with a clear error path on failure.
|
|
432
|
+
*/
|
|
433
|
+
configSchema?: JSONSchema;
|
|
434
|
+
/**
|
|
435
|
+
* Mandatory plugin dependencies — loading fails if any are absent or
|
|
436
|
+
* version-incompatible. Accepts both the legacy string-array form and
|
|
437
|
+
* the structured form with version constraints.
|
|
438
|
+
*/
|
|
439
|
+
dependsOn?: (string | PluginDependency)[];
|
|
440
|
+
/** Optional plugin dependencies — silently skipped if absent. */
|
|
441
|
+
optionalDeps?: (string | PluginDependency)[];
|
|
442
|
+
conflictsWith?: string[];
|
|
443
|
+
setup(api: PluginAPI): void | Promise<void>;
|
|
444
|
+
teardown?(api: PluginAPI): void | Promise<void>;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export { Agent as A, DEFAULT_MAX_ITERATIONS as D, type MCPRegistryView as M, type Plugin as P, type RunResult as R, type SlashCommand as S, type ToolRegistryView as T, type UserInputPayload as U, type PluginAPI as a, type PluginCapabilities as b, type PluginDependency as c, type PluginPipelines as d, type ProviderFactory as e, type ProviderRegistryView as f, type SlashCommandRegistryView as g, type ToolExecutorOptions as h, type ToolExecutorStrategy as i, type ToolBatchResult as j, ToolRegistry as k, ProviderRegistry as l, type AgentInit as m, type AgentInput as n, type AgentPipelines as o, type ProviderFactory$1 as p, createDefaultPipelines as q };
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { T as TextBlock, b as ContentBlock } from './context-u0bryklF.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Container — dependency injection with explicit bind / override / decorate.
|
|
5
|
+
*
|
|
6
|
+
* Invariants:
|
|
7
|
+
* bind() — throws if token already bound
|
|
8
|
+
* override() — throws if nothing to replace
|
|
9
|
+
* decorate() — stacks; cached value cleared on register
|
|
10
|
+
*/
|
|
11
|
+
type Token<T> = symbol & {
|
|
12
|
+
readonly __type?: T;
|
|
13
|
+
};
|
|
14
|
+
type Factory<T> = (c: Container) => T;
|
|
15
|
+
type Decorator<T> = (inner: T, c: Container) => T;
|
|
16
|
+
interface BindOptions {
|
|
17
|
+
singleton?: boolean;
|
|
18
|
+
owner?: string;
|
|
19
|
+
}
|
|
20
|
+
declare class Container {
|
|
21
|
+
private readonly entries;
|
|
22
|
+
bind<T>(token: Token<T>, factory: Factory<T>, opts?: BindOptions): void;
|
|
23
|
+
override<T>(token: Token<T>, factory: Factory<T>, opts?: BindOptions): void;
|
|
24
|
+
decorate<T>(token: Token<T>, decorator: Decorator<T>, owner?: string): void;
|
|
25
|
+
resolve<T>(token: Token<T>): T;
|
|
26
|
+
has<T>(token: Token<T>): boolean;
|
|
27
|
+
ownerOf<T>(token: Token<T>): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Remove a token's binding (along with any decorators stacked on it).
|
|
30
|
+
* Returns true if the token existed. Use this to withdraw temporary
|
|
31
|
+
* bindings installed by a short-lived run or plugin — without it, the
|
|
32
|
+
* entry persists in the map forever.
|
|
33
|
+
*/
|
|
34
|
+
unbind<T>(token: Token<T>): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Drop every binding. Intended for tests and short-lived CLI invocations
|
|
37
|
+
* that rebuild the container from scratch. Production code should prefer
|
|
38
|
+
* `unbind` on the specific tokens it owns.
|
|
39
|
+
*/
|
|
40
|
+
clear(): void;
|
|
41
|
+
list(): Array<{
|
|
42
|
+
token: symbol;
|
|
43
|
+
owner: string;
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Inspect a binding's full shape, including decorator count and whether
|
|
47
|
+
* a singleton value is cached. Returns null if the token is unbound.
|
|
48
|
+
* Decorator and factory function references are not exposed — only counts
|
|
49
|
+
* and metadata, to keep internal state hidden.
|
|
50
|
+
*/
|
|
51
|
+
inspect<T>(token: Token<T>): {
|
|
52
|
+
owner: string;
|
|
53
|
+
singleton: boolean;
|
|
54
|
+
decoratorCount: number;
|
|
55
|
+
cached: boolean;
|
|
56
|
+
} | null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Pipeline — Koa-style middleware chain with named middleware
|
|
61
|
+
* and position-aware insertion. Generic over input type T.
|
|
62
|
+
*/
|
|
63
|
+
type NextFn<T> = (value: T) => Promise<T>;
|
|
64
|
+
type MiddlewareHandler<T> = (value: T, next: NextFn<T>) => Promise<T>;
|
|
65
|
+
/**
|
|
66
|
+
* Called when a middleware crashes (throws or rejects). Used by the
|
|
67
|
+
* Pipeline's error boundary to log the offender without aborting the run.
|
|
68
|
+
*
|
|
69
|
+
* Return `'rethrow'` to propagate the error (default for core middleware),
|
|
70
|
+
* or `'swallow'` to skip past the crashing middleware and continue with the
|
|
71
|
+
* value the previous one produced. Plugin middleware should usually be
|
|
72
|
+
* swallowed so one bad plugin can't kill an agent run.
|
|
73
|
+
*/
|
|
74
|
+
type PipelineErrorPolicy = 'rethrow' | 'swallow';
|
|
75
|
+
interface PipelineErrorEvent {
|
|
76
|
+
middleware: string;
|
|
77
|
+
owner?: string;
|
|
78
|
+
err: unknown;
|
|
79
|
+
}
|
|
80
|
+
type PipelineErrorHandler = (ev: PipelineErrorEvent) => PipelineErrorPolicy | Promise<PipelineErrorPolicy>;
|
|
81
|
+
interface Middleware<T> {
|
|
82
|
+
name: string;
|
|
83
|
+
handler: MiddlewareHandler<T>;
|
|
84
|
+
owner?: string;
|
|
85
|
+
}
|
|
86
|
+
interface PipelineOptions {
|
|
87
|
+
/** When true and the target middleware is not found, operations silently no-op instead of throwing. */
|
|
88
|
+
optional?: boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Read-only view of a pipeline. Returned to consumers (plugins, hooks)
|
|
92
|
+
* so they can inspect but not mutate the chain.
|
|
93
|
+
*/
|
|
94
|
+
interface ReadonlyPipeline<T> {
|
|
95
|
+
readonly size: number;
|
|
96
|
+
list(): readonly string[];
|
|
97
|
+
run(input: T): Promise<T>;
|
|
98
|
+
}
|
|
99
|
+
declare class Pipeline<T> {
|
|
100
|
+
private readonly chain;
|
|
101
|
+
private errorHandler?;
|
|
102
|
+
/**
|
|
103
|
+
* Install an error boundary. When a middleware throws or rejects, the
|
|
104
|
+
* handler is called and decides whether to swallow (continue with the
|
|
105
|
+
* pre-handler value) or rethrow. Without a handler, errors propagate.
|
|
106
|
+
*
|
|
107
|
+
* Wire one per pipeline at boot — the host CLI typically installs a
|
|
108
|
+
* single boundary that logs to the operational log and emits a
|
|
109
|
+
* `pipeline.error` event for /diag.
|
|
110
|
+
*/
|
|
111
|
+
setErrorHandler(handler: PipelineErrorHandler | undefined): this;
|
|
112
|
+
use(mw: Middleware<T> | Middleware<unknown>): this;
|
|
113
|
+
prepend(mw: Middleware<T>): this;
|
|
114
|
+
/**
|
|
115
|
+
* Insert middleware at an explicit index. Out-of-range indices are clamped.
|
|
116
|
+
* Use this when insertBefore/insertAfter are insufficient (e.g. to place
|
|
117
|
+
* a middleware at a known position regardless of named targets).
|
|
118
|
+
*/
|
|
119
|
+
insertAt(index: number, mw: Middleware<T>): this;
|
|
120
|
+
/**
|
|
121
|
+
* Insert mw immediately before the first occurrence of target.
|
|
122
|
+
* If called multiple times with the same target, each call inserts
|
|
123
|
+
* before the target's current position — so after insertBefore('B', X)
|
|
124
|
+
* then insertBefore('B', Y), the order is Y → X → B.
|
|
125
|
+
*/
|
|
126
|
+
insertBefore(target: string, mw: Middleware<T>, opts?: PipelineOptions): this;
|
|
127
|
+
/**
|
|
128
|
+
* Insert mw immediately after the first occurrence of target.
|
|
129
|
+
* If called multiple times with the same target, each call inserts
|
|
130
|
+
* after the target's current position — so after insertAfter('B', X)
|
|
131
|
+
* then insertAfter('B', Y), the order is B → X → Y.
|
|
132
|
+
*/
|
|
133
|
+
insertAfter(target: string, mw: Middleware<T>, opts?: PipelineOptions): this;
|
|
134
|
+
replace(target: string, mw: Middleware<T>, opts?: PipelineOptions): this;
|
|
135
|
+
remove(name: string, opts?: PipelineOptions): this;
|
|
136
|
+
list(): readonly string[];
|
|
137
|
+
size(): number;
|
|
138
|
+
/** Return a read-only view suitable for passing to plugins. */
|
|
139
|
+
asReadonly(): ReadonlyPipeline<T>;
|
|
140
|
+
run(input: T): Promise<T>;
|
|
141
|
+
private indexOf;
|
|
142
|
+
private ensureUnique;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
interface Renderer {
|
|
146
|
+
write(text: string | TextBlock): void;
|
|
147
|
+
writeLine(text?: string): void;
|
|
148
|
+
writeBlock(block: ContentBlock): void;
|
|
149
|
+
writeToolCall(name: string, input: unknown): void;
|
|
150
|
+
writeToolResult(name: string, content: unknown, isError: boolean): void;
|
|
151
|
+
writeDiff(unifiedDiff: string): void;
|
|
152
|
+
writeWarning(text: string): void;
|
|
153
|
+
writeError(text: string): void;
|
|
154
|
+
writeInfo(text: string): void;
|
|
155
|
+
clear(): void;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export { type BindOptions as B, Container as C, type Decorator as D, type Factory as F, type Middleware as M, type NextFn as N, Pipeline as P, type Renderer as R, type Token as T, type MiddlewareHandler as a, type PipelineOptions as b, type ReadonlyPipeline as c };
|