@powerhousedao/clint 0.0.0-stage → 6.2.3-dev.57
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/LICENSE +661 -0
- package/dist/build-skills-C1Vr_kQh.mjs +293 -0
- package/dist/build-skills-C1Vr_kQh.mjs.map +1 -0
- package/dist/dist-CUltriBW.mjs +1628 -0
- package/dist/dist-CUltriBW.mjs.map +1 -0
- package/dist/drive-CNCPoCNs.mjs +82 -0
- package/dist/drive-CNCPoCNs.mjs.map +1 -0
- package/dist/esm-C1DOsF1a.mjs +13140 -0
- package/dist/esm-C1DOsF1a.mjs.map +1 -0
- package/dist/events-DkzJFZeW.mjs +237 -0
- package/dist/events-DkzJFZeW.mjs.map +1 -0
- package/dist/folders-mLL9D5Ck.mjs +254 -0
- package/dist/folders-mLL9D5Ck.mjs.map +1 -0
- package/dist/index.d.mts +1005 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +6 -0
- package/dist/local-signer-EFzJV3bn.mjs +128 -0
- package/dist/local-signer-EFzJV3bn.mjs.map +1 -0
- package/dist/markdown-C1TFXoB6.mjs +275 -0
- package/dist/markdown-C1TFXoB6.mjs.map +1 -0
- package/dist/reactor-C9VIUX1H.mjs +51 -0
- package/dist/reactor-C9VIUX1H.mjs.map +1 -0
- package/dist/rolldown-runtime-8H4AJuhK.mjs +14 -0
- package/dist/runners/clint-runner.d.mts +109 -0
- package/dist/runners/clint-runner.d.mts.map +1 -0
- package/dist/runners/clint-runner.mjs +202 -0
- package/dist/runners/clint-runner.mjs.map +1 -0
- package/dist/runners/mastra-runner.d.mts +100 -0
- package/dist/runners/mastra-runner.d.mts.map +1 -0
- package/dist/runners/mastra-runner.mjs +309 -0
- package/dist/runners/mastra-runner.mjs.map +1 -0
- package/dist/services-BvLvP5Qh.mjs +1210 -0
- package/dist/services-BvLvP5Qh.mjs.map +1 -0
- package/dist/src-DRDGtXYJ.mjs +5061 -0
- package/dist/src-DRDGtXYJ.mjs.map +1 -0
- package/dist/start-CKRhuB1Y.mjs +1526 -0
- package/dist/start-CKRhuB1Y.mjs.map +1 -0
- package/dist/stdin-BjAO9gPK.mjs +17 -0
- package/dist/stdin-BjAO9gPK.mjs.map +1 -0
- package/dist/stream-DVuufwIj.mjs +148 -0
- package/dist/stream-DVuufwIj.mjs.map +1 -0
- package/dist/subscriptions-CfiflAsI.mjs +38 -0
- package/dist/subscriptions-CfiflAsI.mjs.map +1 -0
- package/dist/switchboard-DAS-5x53.mjs +48 -0
- package/dist/switchboard-DAS-5x53.mjs.map +1 -0
- package/dist/types-DrLfp2dR.d.mts +1766 -0
- package/dist/types-DrLfp2dR.d.mts.map +1 -0
- package/package.json +101 -3
- package/README.md +0 -3
|
@@ -0,0 +1,1766 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AttachmentHash, AttachmentRef, AttachmentRef as AttachmentRef$1, DocumentChangeEvent, IReactorClient, JobInfo, PagedResults, PagingOptions, SearchFilter, ViewFilter } from "@powerhousedao/reactor";
|
|
3
|
+
import "@powerhousedao/shared/document-model";
|
|
4
|
+
import { Action, DocumentModelModule, PHBaseState, PHDocument } from "document-model";
|
|
5
|
+
//#region src/core/proxy-routes.d.ts
|
|
6
|
+
interface ProxyRoute {
|
|
7
|
+
/** URL path prefix matched against incoming requests (e.g. '/switchboard/graphql'). */
|
|
8
|
+
prefix: string;
|
|
9
|
+
/**
|
|
10
|
+
* Upstream target URL (e.g. new URL('http://localhost:4001/graphql')).
|
|
11
|
+
* Optional only for pure redirect routes (`redirectTo` set).
|
|
12
|
+
*/
|
|
13
|
+
upstream?: URL;
|
|
14
|
+
/** Whether WebSocket upgrade should be forwarded on this route. */
|
|
15
|
+
ws: boolean;
|
|
16
|
+
/** Origin label for route management (e.g. 'switchboard', 'service:my-svc'). */
|
|
17
|
+
source: string;
|
|
18
|
+
/**
|
|
19
|
+
* When set, matching requests get a 302 to this location instead of being
|
|
20
|
+
* proxied. No upstream connection is made.
|
|
21
|
+
*/
|
|
22
|
+
redirectTo?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Match the prefix exactly rather than as a `startsWith` prefix. Exact
|
|
25
|
+
* routes are matched before prefix routes so a `'/'` redirect can coexist
|
|
26
|
+
* with a `'/'` catch-all without shadowing longer prefixes.
|
|
27
|
+
*/
|
|
28
|
+
exact?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Endpoint types that imply WebSocket transport. Websites need upgrades
|
|
32
|
+
* forwarded for dev-server HMR sockets (Vite connects on the page's own
|
|
33
|
+
* origin/path).
|
|
34
|
+
*/
|
|
35
|
+
declare function isWsEndpointType(type: EndpointType): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Relative-prefix route specs for a Powerhouse Switchboard, usable as
|
|
38
|
+
* `ServiceDefinition.proxyRoutes` specs (mounted under `/{serviceId}/`).
|
|
39
|
+
* The MCP route is included only when `mcpUrl` is provided.
|
|
40
|
+
*/
|
|
41
|
+
declare function buildSwitchboardRouteSpecs(switchboardUrl: string, mcpUrl?: string, basePrefix?: string): Array<ServiceProxyRouteSpec & {
|
|
42
|
+
upstream: URL;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Absolute proxy routes for the embedded Switchboard, mounted under
|
|
46
|
+
* `/switchboard` with source `'switchboard'`. The MCP route is included
|
|
47
|
+
* only when `mcpUrl` is provided.
|
|
48
|
+
*/
|
|
49
|
+
declare function buildSwitchboardRoutes(switchboardUrl: string, mcpUrl?: string): Array<ProxyRoute & {
|
|
50
|
+
upstream: URL;
|
|
51
|
+
}>;
|
|
52
|
+
/** A (serviceId, captureName) pair identifying the proxy-root website. */
|
|
53
|
+
interface ProxyRootCapture {
|
|
54
|
+
serviceId: string;
|
|
55
|
+
captureName: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Proxy mount prefix for a service route: `/{serviceId}/{name}`. Single
|
|
59
|
+
* owner of the convention used for capture routes and for mounting
|
|
60
|
+
* `ServiceDefinition.proxyRoutes` specs.
|
|
61
|
+
*/
|
|
62
|
+
declare function captureRoutePrefix(serviceId: string, captureName: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* Build proxy routes from a service definition's readiness captures and its
|
|
65
|
+
* `proxyRoutes` hook. Only captures with announceable endpoint types produce
|
|
66
|
+
* routes; hook specs are mounted under `/{serviceId}/`.
|
|
67
|
+
*/
|
|
68
|
+
declare function buildServiceRoutes(def: ServiceDefinition, instance: ServiceInstanceStatus, implicitRoot?: ProxyRootCapture, log?: {
|
|
69
|
+
warn(msg: string): void;
|
|
70
|
+
}): ProxyRoute[];
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/core/project-scanner.d.ts
|
|
73
|
+
/**
|
|
74
|
+
* Common project indicator files/dirs. When any of these exist in a folder
|
|
75
|
+
* that isn't matched by the scanner, the folder is treated as a foreign
|
|
76
|
+
* project and its subtree is pruned from the search.
|
|
77
|
+
*/
|
|
78
|
+
declare const PROJECT_INDICATORS: readonly [".git", "package.json", "node_modules", "pyproject.toml", "setup.py", "Cargo.toml", "go.mod", "pom.xml", "build.gradle", "build.gradle.kts", ".sln", "Gemfile", "composer.json"];
|
|
79
|
+
/**
|
|
80
|
+
* Breadth-first search for project folders starting from `rootDir`.
|
|
81
|
+
*
|
|
82
|
+
* - If root itself matches, returns it immediately.
|
|
83
|
+
* - Otherwise searches subfolders breadth-first:
|
|
84
|
+
* - Match → added to results, subtree pruned
|
|
85
|
+
* - Mismatch (foreign project) → subtree pruned
|
|
86
|
+
* - Non-project → subfolders enqueued for further search
|
|
87
|
+
*
|
|
88
|
+
* Uses `scanner.getProjectName` for the result name (default: `path.basename`),
|
|
89
|
+
* and `scanner.getProjectConfig` when provided.
|
|
90
|
+
*/
|
|
91
|
+
declare function scanProjects(rootDir: string, scanner: ProjectScanner): ProjectScanResult[];
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/core/skills.d.ts
|
|
94
|
+
/**
|
|
95
|
+
* Metadata extracted from a SKILL.md frontmatter.
|
|
96
|
+
*/
|
|
97
|
+
interface SkillInfo {
|
|
98
|
+
name: string;
|
|
99
|
+
description: string;
|
|
100
|
+
/** Absolute path to the SKILL.md file. */
|
|
101
|
+
skillMdPath: string;
|
|
102
|
+
/** Absolute path to the .cli-docs.md file, if present. */
|
|
103
|
+
cliDocsPath?: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Read skill metadata from artifact directories.
|
|
107
|
+
*
|
|
108
|
+
* Scans each artifact directory for `{skillName}/SKILL.md` files, parses
|
|
109
|
+
* frontmatter, and returns a deduplicated sorted list. First directory wins
|
|
110
|
+
* on name collisions. When a name appears in more than one root, `onWarn` is
|
|
111
|
+
* invoked once per collision so the caller can surface the conflict.
|
|
112
|
+
*
|
|
113
|
+
* Convention: codegen orders artifacts as `[skills-tpl/, skills-ext/]`, so
|
|
114
|
+
* tpl always wins over ext. The warning message names both roots verbatim.
|
|
115
|
+
*/
|
|
116
|
+
declare function readSkills(artifacts: string[], onWarn?: (message: string) => void): SkillInfo[];
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/core/types.d.ts
|
|
119
|
+
/**
|
|
120
|
+
* Utility type: infer the TypeScript type from a Zod config schema.
|
|
121
|
+
* Use in implementation projects for type-strict config access:
|
|
122
|
+
*
|
|
123
|
+
* ```ts
|
|
124
|
+
* const configSchema = z.object({ port: z.number().default(3000) });
|
|
125
|
+
* type MyConfig = InferConfig<typeof configSchema>;
|
|
126
|
+
* // MyConfig = { port: number }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
type InferConfig<T extends z.ZodType> = z.infer<T>;
|
|
130
|
+
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
131
|
+
interface Logger {
|
|
132
|
+
debug(msg: string, ...args: unknown[]): void;
|
|
133
|
+
info(msg: string, ...args: unknown[]): void;
|
|
134
|
+
warn(msg: string, ...args: unknown[]): void;
|
|
135
|
+
error(msg: string, ...args: unknown[]): void;
|
|
136
|
+
level: LogLevel;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* A key-value store for CLI-managed state.
|
|
140
|
+
* Backed by `{workdir}/.ph/{cli-name}/` on disk, or in-memory for testing.
|
|
141
|
+
*/
|
|
142
|
+
interface WorkdirStore {
|
|
143
|
+
/** Resolved absolute working directory. */
|
|
144
|
+
getWorkdir(): string;
|
|
145
|
+
/** Path to the local config file: `{workdir}/.ph/{cliName}.config.local.json`. */
|
|
146
|
+
getLocalConfigPath(): string;
|
|
147
|
+
/** Absolute path to `{workdir}/.ph/{cliName}/{path}`. When path is omitted, returns the store root. */
|
|
148
|
+
getStoreFolder(path?: string): string;
|
|
149
|
+
/** Load a JSON file from the store. Throws if filename doesn't end with `.json`. */
|
|
150
|
+
loadJsonObject<T>(filename: string, fallback: T): Promise<T>;
|
|
151
|
+
/** Write a JSON file to the store (atomic write with temp file). */
|
|
152
|
+
storeJsonObject(filename: string, value: unknown): Promise<void>;
|
|
153
|
+
/** Shorthand for loadJsonObject on the local config file. */
|
|
154
|
+
loadLocalConfig<T>(fallback: T): Promise<T>;
|
|
155
|
+
/** Shorthand for storeJsonObject on the local config file. */
|
|
156
|
+
storeLocalConfig(value: unknown): Promise<void>;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Payload map for framework-emitted events. Registry generic narrows
|
|
160
|
+
* `powerhouse:*` payloads to registered document types.
|
|
161
|
+
*
|
|
162
|
+
* User code registered via declaration merging can extend this interface
|
|
163
|
+
* (or just emit/on with arbitrary string keys; those fall through to the
|
|
164
|
+
* `unknown` overload).
|
|
165
|
+
*/
|
|
166
|
+
interface PhClintEvents<R extends DocumentRegistry = AnyRegistry> {
|
|
167
|
+
"powerhouse:ready": {
|
|
168
|
+
driveId: string;
|
|
169
|
+
};
|
|
170
|
+
"powerhouse:document:changed": {
|
|
171
|
+
changeType: "updated";
|
|
172
|
+
documents: Array<R[keyof R & string]["document"]>;
|
|
173
|
+
};
|
|
174
|
+
"powerhouse:document:created": {
|
|
175
|
+
documentId: string;
|
|
176
|
+
documentType: keyof R & string;
|
|
177
|
+
};
|
|
178
|
+
"powerhouse:document:deleted": {
|
|
179
|
+
documentId: string;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Overloaded emit function: typed for framework-emitted events, fallback
|
|
184
|
+
* `unknown` payload for any other event string.
|
|
185
|
+
*/
|
|
186
|
+
type EmitFn<R extends DocumentRegistry = AnyRegistry> = {
|
|
187
|
+
<K extends keyof PhClintEvents<R>>(event: K, data: PhClintEvents<R>[K]): void;
|
|
188
|
+
(event: string, data?: unknown): void;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Overloaded listener registration: typed handler for framework events,
|
|
192
|
+
* fallback `unknown` payload for any other event string.
|
|
193
|
+
*/
|
|
194
|
+
type OnFn<R extends DocumentRegistry = AnyRegistry> = {
|
|
195
|
+
<K extends keyof PhClintEvents<R>>(event: K, handler: (data: PhClintEvents<R>[K]) => void): void;
|
|
196
|
+
(event: string, handler: (data?: unknown) => void): void;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Context passed to command execute functions.
|
|
200
|
+
* Provides access to workdir, workspace, resolved config, and optional runtime services.
|
|
201
|
+
*/
|
|
202
|
+
interface CommandContext<TConfig = Record<string, unknown>, R extends DocumentRegistry = AnyRegistry> {
|
|
203
|
+
/** The resolved working directory — where the user/agent collaborate on data. */
|
|
204
|
+
workdir: string;
|
|
205
|
+
/** Key-value store for CLI-managed state at {workdir}/.ph/{cli-name}/. */
|
|
206
|
+
workspace: WorkdirStore;
|
|
207
|
+
config: TConfig;
|
|
208
|
+
/** Write progressive output during command execution (raw — no trailing newline added). */
|
|
209
|
+
stdout: (text: string) => void;
|
|
210
|
+
/** Structured logger — level controlled by --verbose flag or RunOptions.logLevel. */
|
|
211
|
+
log?: Logger;
|
|
212
|
+
routine?: Routine;
|
|
213
|
+
processes?: ProcessManager;
|
|
214
|
+
services?: ServiceManager;
|
|
215
|
+
/** Embedded reverse proxy, when `proxyEnabled`. */
|
|
216
|
+
proxy?: {
|
|
217
|
+
/** Public base URL of the proxy (e.g. 'http://localhost:8090'). */
|
|
218
|
+
url: string;
|
|
219
|
+
port: number;
|
|
220
|
+
/** Current route table snapshot. */
|
|
221
|
+
routes(): ReadonlyArray<{
|
|
222
|
+
prefix: string;
|
|
223
|
+
upstream?: string;
|
|
224
|
+
ws: boolean;
|
|
225
|
+
source: string;
|
|
226
|
+
redirectTo?: string;
|
|
227
|
+
exact?: boolean;
|
|
228
|
+
}>;
|
|
229
|
+
/**
|
|
230
|
+
* Register a proxy route at runtime — used by embedding CLIs to add
|
|
231
|
+
* redirects or announce extra endpoints once a service is ready.
|
|
232
|
+
*/
|
|
233
|
+
addRoute(route: ProxyRoute): void;
|
|
234
|
+
};
|
|
235
|
+
emit?: EmitFn<R>;
|
|
236
|
+
on?: OnFn<R>;
|
|
237
|
+
/** Folder operations on the agent's personal drive. Available when a personal drive is configured. */
|
|
238
|
+
folders?: FolderOperations;
|
|
239
|
+
/** Lazy reactor accessor — returns the ReactorContext or undefined if not configured. */
|
|
240
|
+
reactor?: () => Promise<ReactorContext<R> | undefined>;
|
|
241
|
+
/** Lazy agent accessor — returns the AgentProvider or undefined if not configured. */
|
|
242
|
+
agent?: () => Promise<AgentProvider | undefined>;
|
|
243
|
+
/**
|
|
244
|
+
* Run a bounded subprocess, routing each output line through `stdout()`.
|
|
245
|
+
* Convenience wrapper around `processes.run()` with auto-wired `onOutput`.
|
|
246
|
+
*/
|
|
247
|
+
runProcess: (command: string, opts?: Omit<ProcessRunOptions, "onOutput">) => Promise<{
|
|
248
|
+
success: boolean;
|
|
249
|
+
output: string;
|
|
250
|
+
}>;
|
|
251
|
+
/** @internal Hook for interactive mode to capture progressive tool output. */
|
|
252
|
+
_onToolOutput?: (toolName: string, text: string) => void;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* CommandContext without the reactor/agent accessors.
|
|
256
|
+
* Used as TriggerContext.context to avoid duplicate access paths.
|
|
257
|
+
*/
|
|
258
|
+
type CoreContext<TConfig = Record<string, unknown>, R extends DocumentRegistry = AnyRegistry> = Omit<CommandContext<TConfig, R>, "reactor" | "agent">;
|
|
259
|
+
/**
|
|
260
|
+
* Interactive parameter prompting configuration for a command.
|
|
261
|
+
* Used by the REPL to prompt for missing/optional parameters.
|
|
262
|
+
*/
|
|
263
|
+
interface PromptConfig {
|
|
264
|
+
promptForDefaults?: boolean;
|
|
265
|
+
promptOptional?: string[];
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Interactive mode (REPL) configuration.
|
|
269
|
+
* When used in CliOptions, `welcome` may be a Resolvable<string>.
|
|
270
|
+
* After resolution (in `Cli.interactive`), it is always a plain string.
|
|
271
|
+
* TConfig is inferred from the CLI's configSchema.
|
|
272
|
+
*/
|
|
273
|
+
interface InteractiveConfig<TConfig = Record<string, unknown>> {
|
|
274
|
+
welcome: Resolvable<string, TConfig>;
|
|
275
|
+
/** Number of trailing lines to show in the output window for tool results. Default: 6. */
|
|
276
|
+
outputWindow?: number;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Resolved interactive config — all Resolvable values have been resolved.
|
|
280
|
+
*/
|
|
281
|
+
interface ResolvedInteractiveConfig {
|
|
282
|
+
welcome: string;
|
|
283
|
+
/** Number of trailing lines to show in the output window for tool results. Default: 6. */
|
|
284
|
+
outputWindow: number;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* A command definition — the atomic unit of ph-clint.
|
|
288
|
+
* Compatible with Mastra createTool() shape.
|
|
289
|
+
*/
|
|
290
|
+
interface Command<TInput extends z.ZodType = z.ZodType, TOutput = unknown, TConfig = Record<string, unknown>, R extends DocumentRegistry = any> {
|
|
291
|
+
id: string;
|
|
292
|
+
description: string;
|
|
293
|
+
inputSchema: TInput;
|
|
294
|
+
outputSchema?: z.ZodType<TOutput>;
|
|
295
|
+
prompt?: PromptConfig;
|
|
296
|
+
/**
|
|
297
|
+
* Field keys from `inputSchema` to be parsed as positional arguments, in order.
|
|
298
|
+
* Positional fields are NOT registered as `--flag` options. A required positional
|
|
299
|
+
* field may not follow an optional one.
|
|
300
|
+
*
|
|
301
|
+
* Example:
|
|
302
|
+
* inputSchema: z.object({ title: z.string(), priority: z.number().default(1) }),
|
|
303
|
+
* positional: ['title', 'priority'],
|
|
304
|
+
* // usage: cli add "Buy milk" 2
|
|
305
|
+
*/
|
|
306
|
+
positional?: readonly string[];
|
|
307
|
+
execute: (input: z.output<TInput>, context: CommandContext<TConfig, R>) => Promise<TOutput>;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Typed chunks for streaming command/agent output.
|
|
311
|
+
* Framework-agnostic — the Mastra integration maps its fullStream chunks
|
|
312
|
+
* to these types, and the REPL/CLI renders them.
|
|
313
|
+
*/
|
|
314
|
+
interface TextDeltaChunk {
|
|
315
|
+
type: "text-delta";
|
|
316
|
+
text: string;
|
|
317
|
+
}
|
|
318
|
+
interface ToolCallChunk {
|
|
319
|
+
type: "tool-call";
|
|
320
|
+
toolCallId?: string;
|
|
321
|
+
toolName: string;
|
|
322
|
+
args: unknown;
|
|
323
|
+
}
|
|
324
|
+
interface ToolResultChunk {
|
|
325
|
+
type: "tool-result";
|
|
326
|
+
toolCallId?: string;
|
|
327
|
+
toolName: string;
|
|
328
|
+
result: unknown;
|
|
329
|
+
isError: boolean;
|
|
330
|
+
}
|
|
331
|
+
interface ToolOutputChunk {
|
|
332
|
+
type: "tool-output";
|
|
333
|
+
toolCallId?: string;
|
|
334
|
+
toolName: string;
|
|
335
|
+
text: string;
|
|
336
|
+
}
|
|
337
|
+
interface ErrorChunk {
|
|
338
|
+
type: "error";
|
|
339
|
+
error: string;
|
|
340
|
+
/** Transient failure worth re-attempting (provider 429/5xx, dropped connection). */
|
|
341
|
+
retryable?: boolean;
|
|
342
|
+
statusCode?: number;
|
|
343
|
+
/** Suggested wait before retry, ms (from `retry-after`). */
|
|
344
|
+
retryAfterMs?: number;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Token usage reported by the model at the end of a step (one LLM turn)
|
|
348
|
+
* or at the end of the full stream. Field names mirror the AI SDK's
|
|
349
|
+
* `LanguageModelUsage` so callers can pass through provider-specific
|
|
350
|
+
* details (cache reads/writes, reasoning tokens) without re-mapping.
|
|
351
|
+
*/
|
|
352
|
+
interface StreamUsage {
|
|
353
|
+
inputTokens?: number;
|
|
354
|
+
outputTokens?: number;
|
|
355
|
+
totalTokens?: number;
|
|
356
|
+
cachedInputTokens?: number;
|
|
357
|
+
cacheCreationInputTokens?: number;
|
|
358
|
+
reasoningTokens?: number;
|
|
359
|
+
}
|
|
360
|
+
interface StepFinishChunk {
|
|
361
|
+
type: "step-finish";
|
|
362
|
+
usage?: StreamUsage;
|
|
363
|
+
finishReason?: string;
|
|
364
|
+
}
|
|
365
|
+
interface FinishChunk {
|
|
366
|
+
type: "finish";
|
|
367
|
+
usage?: StreamUsage;
|
|
368
|
+
finishReason?: string;
|
|
369
|
+
}
|
|
370
|
+
type StreamChunk = TextDeltaChunk | ToolCallChunk | ToolOutputChunk | ToolResultChunk | ErrorChunk | StepFinishChunk | FinishChunk;
|
|
371
|
+
/**
|
|
372
|
+
* A content part in a multimodal prompt. Mirrors the AI SDK's
|
|
373
|
+
* `TextPart | ImagePart` without importing the SDK types directly.
|
|
374
|
+
*/
|
|
375
|
+
type AgentContentPart = {
|
|
376
|
+
type: "text";
|
|
377
|
+
text: string;
|
|
378
|
+
} | {
|
|
379
|
+
type: "image";
|
|
380
|
+
image: string | Uint8Array | ArrayBuffer | URL;
|
|
381
|
+
mediaType?: string;
|
|
382
|
+
};
|
|
383
|
+
/**
|
|
384
|
+
* Input to `AgentProvider.stream()`. Either a plain text string
|
|
385
|
+
* or an array of content parts (text + images).
|
|
386
|
+
*/
|
|
387
|
+
type AgentPromptInput = string | AgentContentPart[];
|
|
388
|
+
/**
|
|
389
|
+
* Options for streaming an agent prompt.
|
|
390
|
+
*/
|
|
391
|
+
interface AgentStreamOptions {
|
|
392
|
+
threadId?: string;
|
|
393
|
+
tools?: Map<string, Command>;
|
|
394
|
+
/** Signal to abort the current stream. When aborted, the underlying LLM request is cancelled. */
|
|
395
|
+
abortSignal?: AbortSignal;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Abstract agent provider — the boundary between the core and
|
|
399
|
+
* agent integrations (Mastra, etc.). Core code never imports
|
|
400
|
+
* agent framework modules directly.
|
|
401
|
+
*/
|
|
402
|
+
interface AgentProvider {
|
|
403
|
+
id: string;
|
|
404
|
+
/** Human-readable display name. */
|
|
405
|
+
name?: string;
|
|
406
|
+
/** Short description of the agent's capabilities. */
|
|
407
|
+
description?: string;
|
|
408
|
+
/** Agent avatar image (data URI or URL). */
|
|
409
|
+
image?: string;
|
|
410
|
+
/** The underlying Mastra Agent instance, if one was used to create this provider. */
|
|
411
|
+
mastraAgent?: unknown;
|
|
412
|
+
stream(prompt: AgentPromptInput, opts?: AgentStreamOptions): AsyncGenerator<StreamChunk>;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* A work item produced by a trigger for the routine loop to execute.
|
|
416
|
+
*/
|
|
417
|
+
interface WorkItem {
|
|
418
|
+
type: "command" | "function";
|
|
419
|
+
params: Record<string, unknown>;
|
|
420
|
+
callbacks?: {
|
|
421
|
+
onSuccess?: (result: unknown) => void | Promise<void>;
|
|
422
|
+
onFailure?: (error: Error) => void | Promise<void>;
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Context passed to trigger setup() and poll() functions.
|
|
427
|
+
* Provides core infrastructure via `context`, per-trigger state,
|
|
428
|
+
* and lazy accessors for reactor and agent capabilities.
|
|
429
|
+
*/
|
|
430
|
+
interface TriggerContext<TState = Record<string, unknown>, TConfig = Record<string, unknown>, R extends DocumentRegistry = AnyRegistry> {
|
|
431
|
+
/** Live reference to the core context (workdir, config, emit, services, etc.). */
|
|
432
|
+
context: CoreContext<TConfig, R>;
|
|
433
|
+
/** Full CommandContext assembled from core context + capability accessors. */
|
|
434
|
+
commandContext: CommandContext<TConfig, R>;
|
|
435
|
+
state: TState;
|
|
436
|
+
/** Lazy reactor accessor — returns the ReactorContext or undefined if not configured. */
|
|
437
|
+
reactor: () => Promise<ReactorContext<R> | undefined>;
|
|
438
|
+
/** Lazy agent accessor — returns the AgentProvider or undefined if not configured. */
|
|
439
|
+
agent: () => Promise<AgentProvider | undefined>;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Options for defineTrigger().
|
|
443
|
+
*/
|
|
444
|
+
interface TriggerOptions<TState = Record<string, unknown>, TConfig = Record<string, unknown>, R extends DocumentRegistry = AnyRegistry> {
|
|
445
|
+
id: string;
|
|
446
|
+
type: "condition";
|
|
447
|
+
/** Optional initializer called once per trigger instance before setup()/poll(). */
|
|
448
|
+
state?: () => TState;
|
|
449
|
+
setup?: (context: TriggerContext<TState, TConfig, R>) => Promise<void>;
|
|
450
|
+
teardown?: (context: TriggerContext<TState, TConfig, R>) => Promise<void>;
|
|
451
|
+
poll: (context: TriggerContext<TState, TConfig, R>) => Promise<WorkItem | null>;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* A trigger instance — produces work items for the routine loop.
|
|
455
|
+
*/
|
|
456
|
+
interface Trigger<TState = Record<string, unknown>, TConfig = Record<string, unknown>, R extends DocumentRegistry = AnyRegistry> {
|
|
457
|
+
id: string;
|
|
458
|
+
type: string;
|
|
459
|
+
/** Optional initializer called once per trigger instance before setup()/poll(). */
|
|
460
|
+
state?: () => TState;
|
|
461
|
+
setup?: (context: TriggerContext<TState, TConfig, R>) => Promise<void>;
|
|
462
|
+
teardown?: (context: TriggerContext<TState, TConfig, R>) => Promise<void>;
|
|
463
|
+
poll: (context: TriggerContext<TState, TConfig, R>) => Promise<WorkItem | null>;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* State machine states for the routine loop.
|
|
467
|
+
*/
|
|
468
|
+
type RoutineStatus = "init" | "ready" | "running" | "stopping";
|
|
469
|
+
/**
|
|
470
|
+
* A routine — a tick-based execution loop with pluggable triggers.
|
|
471
|
+
*/
|
|
472
|
+
interface Routine {
|
|
473
|
+
readonly status: RoutineStatus;
|
|
474
|
+
readonly triggerIds: string[];
|
|
475
|
+
readonly queueLength: number;
|
|
476
|
+
start(): void;
|
|
477
|
+
stop(): Promise<void>;
|
|
478
|
+
/** Optional callback for work item output. Set before start() to capture results. */
|
|
479
|
+
onOutput?: (text: string) => void;
|
|
480
|
+
/** Optional callback for structured stream chunks (tool-call, tool-output, tool-result). */
|
|
481
|
+
onChunk?: (chunk: StreamChunk) => void;
|
|
482
|
+
/** Update the context used for command execution within the routine. */
|
|
483
|
+
setContext(context: CommandContext): void;
|
|
484
|
+
/** Set lazy capability accessors (reactor, agent) and the wrap registry for trigger contexts. */
|
|
485
|
+
setCapabilities<R extends DocumentRegistry = AnyRegistry>(caps: {
|
|
486
|
+
getReactor?: () => Promise<ReactorContext<R> | undefined>;
|
|
487
|
+
getAgent?: () => Promise<AgentProvider | undefined>;
|
|
488
|
+
/** Composed wrap registry from lifecycle hooks. Defaults to IDENTITY_WRAPS when absent. */
|
|
489
|
+
wraps?: WrapRegistry;
|
|
490
|
+
}): void;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* A handle to a running or completed process.
|
|
494
|
+
*/
|
|
495
|
+
interface ProcessHandle {
|
|
496
|
+
label: string;
|
|
497
|
+
status: "running" | "succeeded" | "failed";
|
|
498
|
+
kill(): void;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Options for running a bounded shell command.
|
|
502
|
+
*/
|
|
503
|
+
interface ProcessRunOptions {
|
|
504
|
+
label?: string;
|
|
505
|
+
timeout?: number;
|
|
506
|
+
cwd?: string;
|
|
507
|
+
env?: Record<string, string>;
|
|
508
|
+
/** Called for each line of output (stdout + stderr combined) as it arrives. */
|
|
509
|
+
onOutput?: (line: string) => void;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Manages bounded shell command execution.
|
|
513
|
+
*/
|
|
514
|
+
interface ProcessManager {
|
|
515
|
+
run(command: string, opts?: ProcessRunOptions): Promise<{
|
|
516
|
+
success: boolean;
|
|
517
|
+
output: string;
|
|
518
|
+
}>;
|
|
519
|
+
list(): ProcessHandle[];
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Endpoint type classification for captured service endpoints.
|
|
523
|
+
* Used by integrations (e.g. Mastra) to auto-discover service capabilities.
|
|
524
|
+
*/
|
|
525
|
+
type EndpointType = "other" | "api-mcp" | "api-rest" | "api-graphql" | "website";
|
|
526
|
+
/**
|
|
527
|
+
* A capture definition with a group index and optional endpoint type.
|
|
528
|
+
* When only an index is needed, a plain `number` can be used instead.
|
|
529
|
+
*/
|
|
530
|
+
interface CaptureDefinition {
|
|
531
|
+
group: number;
|
|
532
|
+
type?: EndpointType;
|
|
533
|
+
/**
|
|
534
|
+
* Claim the proxy's `/` catch-all for this website endpoint. Only honored
|
|
535
|
+
* on `website`-type captures. Exactly one capture across all services
|
|
536
|
+
* should set this — the primary SPA whose root-relative asset requests
|
|
537
|
+
* must resolve at the proxy root. Other `website` captures are routed
|
|
538
|
+
* under `/{serviceId}/{captureName}` and must serve themselves under that
|
|
539
|
+
* base path.
|
|
540
|
+
*/
|
|
541
|
+
proxyRoot?: boolean;
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* A named readiness pattern for multi-pattern readiness detection.
|
|
545
|
+
* The service becomes ready when ALL patterns have matched.
|
|
546
|
+
*
|
|
547
|
+
* Captures map endpoint names to either a plain group index (`number`)
|
|
548
|
+
* or a `CaptureDefinition` with an optional endpoint type.
|
|
549
|
+
*/
|
|
550
|
+
interface ReadinessPattern {
|
|
551
|
+
name: string;
|
|
552
|
+
pattern: RegExp;
|
|
553
|
+
captures?: Record<string, number | CaptureDefinition>;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Readiness configuration for a service.
|
|
557
|
+
*
|
|
558
|
+
* Supports two forms:
|
|
559
|
+
* - Single pattern: `{ pattern, captures?, timeout, wait? }`
|
|
560
|
+
* - Multiple patterns: `{ patterns, timeout, wait? }` — ready when ALL match
|
|
561
|
+
*/
|
|
562
|
+
interface ReadinessConfig {
|
|
563
|
+
/** Single readiness pattern (mutually exclusive with `patterns`). */
|
|
564
|
+
pattern?: RegExp;
|
|
565
|
+
/** Captures for the single pattern. Maps endpoint name → group index or CaptureDefinition. */
|
|
566
|
+
captures?: Record<string, number | CaptureDefinition>;
|
|
567
|
+
/** Multiple named readiness patterns — service is ready when ALL have matched. */
|
|
568
|
+
patterns?: ReadinessPattern[];
|
|
569
|
+
/** Max time (ms) to wait for all patterns to match before marking failed. */
|
|
570
|
+
timeout: number;
|
|
571
|
+
/** Block until ready (default true). When false, mark ready immediately after spawn. */
|
|
572
|
+
wait?: boolean;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Pluggable project detection for a service.
|
|
576
|
+
* When attached to a ServiceDefinition, enables auto-discovery of projects
|
|
577
|
+
* and generation of a `{id}-ls` command.
|
|
578
|
+
*/
|
|
579
|
+
interface ProjectScanner {
|
|
580
|
+
isProjectFolder(folderPath: string): boolean;
|
|
581
|
+
getProjectName?(folderPath: string): string;
|
|
582
|
+
getProjectConfig?(folderPath: string): Record<string, unknown>;
|
|
583
|
+
/** Read document linkage from the project's spec/config file. */
|
|
584
|
+
getDocumentLink?(folderPath: string): {
|
|
585
|
+
documentId: string;
|
|
586
|
+
documentType: string;
|
|
587
|
+
} | undefined;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Result of scanning for projects in a directory tree.
|
|
591
|
+
*/
|
|
592
|
+
interface ProjectScanResult {
|
|
593
|
+
name: string;
|
|
594
|
+
path: string;
|
|
595
|
+
config?: Record<string, unknown>;
|
|
596
|
+
/** Document ID linked to this project (from getDocumentLink). */
|
|
597
|
+
documentId?: string;
|
|
598
|
+
/** Document type linked to this project. */
|
|
599
|
+
documentType?: string;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Result of a preflight check.
|
|
603
|
+
* Return `{ ok: true }` if the check passes.
|
|
604
|
+
* Return `{ ok: false, message, hint? }` if it fails.
|
|
605
|
+
*/
|
|
606
|
+
type PreflightResult = {
|
|
607
|
+
ok: true;
|
|
608
|
+
} | {
|
|
609
|
+
ok: false;
|
|
610
|
+
message: string;
|
|
611
|
+
hint?: string;
|
|
612
|
+
};
|
|
613
|
+
/**
|
|
614
|
+
* Context passed to a preflight check before spawning.
|
|
615
|
+
*/
|
|
616
|
+
interface PreflightContext<TConfig = Record<string, unknown>> {
|
|
617
|
+
/** Resolved working directory where the process will spawn. */
|
|
618
|
+
cwd: string;
|
|
619
|
+
/** CLI config. */
|
|
620
|
+
config: TConfig;
|
|
621
|
+
/** Start params (from paramsSchema). */
|
|
622
|
+
params?: Record<string, unknown>;
|
|
623
|
+
/** Resolved command string that would be spawned. */
|
|
624
|
+
command: string;
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* A preflight check receives the resolved start context and returns pass/fail.
|
|
628
|
+
*/
|
|
629
|
+
type PreflightCheck<TConfig = Record<string, unknown>> = (ctx: PreflightContext<TConfig>) => PreflightResult | Promise<PreflightResult>;
|
|
630
|
+
/**
|
|
631
|
+
* Context passed to `ServiceDefinition.command` / `env` builders.
|
|
632
|
+
*/
|
|
633
|
+
interface ServiceBuildContext<TConfig = Record<string, unknown>> {
|
|
634
|
+
/** Start params (from paramsSchema). */
|
|
635
|
+
params?: Record<string, unknown>;
|
|
636
|
+
/** Resolved CLI config. */
|
|
637
|
+
config: TConfig;
|
|
638
|
+
/** Embedded-proxy mount info derived from `config.proxyPublicUrl`. */
|
|
639
|
+
proxy: {
|
|
640
|
+
/** Validated public URL, trailing slashes stripped. Undefined when unset/invalid. */
|
|
641
|
+
publicUrl?: string;
|
|
642
|
+
/** Mount base path: '' at root, else leading-slash no-trailing-slash ('/myagent'). */
|
|
643
|
+
basePath: string;
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* A proxy route declared by a service, relative to its mount. The framework
|
|
648
|
+
* mounts `prefix` under `/{serviceId}/` and manages the route's lifecycle
|
|
649
|
+
* alongside capture-derived routes (added on ready, removed on stop/failure,
|
|
650
|
+
* re-wired for instances adopted at boot).
|
|
651
|
+
*/
|
|
652
|
+
interface ServiceProxyRouteSpec {
|
|
653
|
+
/** Path prefix relative to the service mount (leading '/' ignored). */
|
|
654
|
+
prefix: string;
|
|
655
|
+
upstream: string | URL;
|
|
656
|
+
ws?: boolean;
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Definition for a long-running background service.
|
|
660
|
+
* Services are spawned as detached processes that survive CLI exit.
|
|
661
|
+
*/
|
|
662
|
+
interface ServiceDefinition<TConfig = Record<string, unknown>> {
|
|
663
|
+
id: string;
|
|
664
|
+
/** Display name for this service. Defaults to slugToTitle(id) when omitted. */
|
|
665
|
+
name?: string;
|
|
666
|
+
/** Human-readable description of the service. */
|
|
667
|
+
description?: string;
|
|
668
|
+
command: string | ((ctx: ServiceBuildContext<TConfig>) => string);
|
|
669
|
+
env?: (ctx: ServiceBuildContext<TConfig>) => Record<string, string>;
|
|
670
|
+
/**
|
|
671
|
+
* Proxy routes derived from a ready instance's endpoints, mounted under
|
|
672
|
+
* `/{serviceId}/`. Invalid specs (bad upstream URL) are skipped.
|
|
673
|
+
*/
|
|
674
|
+
proxyRoutes?: (instance: ServiceInstanceStatus) => ServiceProxyRouteSpec[];
|
|
675
|
+
/** Zod schema for typed start parameters (merged into start command flags). */
|
|
676
|
+
paramsSchema?: import("zod").ZodType;
|
|
677
|
+
/** Maximum concurrent instances (default 1). */
|
|
678
|
+
maxInstances?: number;
|
|
679
|
+
/**
|
|
680
|
+
* Checks to run before spawning the process.
|
|
681
|
+
* All checks run in order. First failure aborts the start.
|
|
682
|
+
* Use for fast, cheap validations (file existence, port checks, version checks).
|
|
683
|
+
*/
|
|
684
|
+
preflight?: PreflightCheck<TConfig>[];
|
|
685
|
+
readiness?: ReadinessConfig;
|
|
686
|
+
shutdown?: {
|
|
687
|
+
signal: NodeJS.Signals;
|
|
688
|
+
timeout: number;
|
|
689
|
+
};
|
|
690
|
+
restart?: {
|
|
691
|
+
enabled: boolean;
|
|
692
|
+
maxRetries: number;
|
|
693
|
+
delay: number;
|
|
694
|
+
};
|
|
695
|
+
/** Project scanner for auto-discovery. Enables `{id}-ls` command and panel integration. */
|
|
696
|
+
projectScanner?: ProjectScanner;
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Options for starting a service instance.
|
|
700
|
+
*/
|
|
701
|
+
interface ServiceStartOptions {
|
|
702
|
+
/** Working directory for instance identity (affects instance ID via hash). */
|
|
703
|
+
workdir?: string;
|
|
704
|
+
/** Spawn cwd — where the process actually runs. Defaults to process.cwd(). */
|
|
705
|
+
cwd?: string;
|
|
706
|
+
params?: Record<string, unknown>;
|
|
707
|
+
name?: string;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Runtime status of a service instance.
|
|
711
|
+
*/
|
|
712
|
+
interface ServiceInstanceStatus {
|
|
713
|
+
serviceId: string;
|
|
714
|
+
instanceId: string;
|
|
715
|
+
name: string;
|
|
716
|
+
status: "idle" | "starting" | "ready" | "failed" | "stopping" | "stopped";
|
|
717
|
+
pid?: number;
|
|
718
|
+
endpoints?: Record<string, string>;
|
|
719
|
+
endpointTypes?: Record<string, EndpointType>;
|
|
720
|
+
error?: string;
|
|
721
|
+
restartAttempt?: number;
|
|
722
|
+
workdir?: string;
|
|
723
|
+
params?: Record<string, unknown>;
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Runtime status of a service (legacy single-instance view).
|
|
727
|
+
*/
|
|
728
|
+
interface ServiceStatus {
|
|
729
|
+
id: string;
|
|
730
|
+
name: string;
|
|
731
|
+
status: "idle" | "starting" | "ready" | "failed" | "stopping" | "stopped";
|
|
732
|
+
pid?: number;
|
|
733
|
+
endpoints?: Record<string, string>;
|
|
734
|
+
error?: string;
|
|
735
|
+
restartAttempt?: number;
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Manager for long-running background services.
|
|
739
|
+
*/
|
|
740
|
+
interface ServiceManager {
|
|
741
|
+
start(id: string, opts?: ServiceStartOptions): Promise<string>;
|
|
742
|
+
stop(id: string, instanceId?: string): Promise<void>;
|
|
743
|
+
list(serviceId?: string): ServiceInstanceStatus[];
|
|
744
|
+
/** Get the static definition for a service. */
|
|
745
|
+
getDefinition(id: string): ServiceDefinition | undefined;
|
|
746
|
+
logs(id: string, instanceId?: string, lines?: number): string;
|
|
747
|
+
/** Watch a service's log file for new lines. Returns cleanup function. */
|
|
748
|
+
watchLogs(id: string, instanceId: string, onLine: (line: string) => void): () => void;
|
|
749
|
+
/** Watch a service for structured stream chunks. Returns cleanup function. */
|
|
750
|
+
watchChunks(id: string, instanceId: string, onChunk: (chunk: StreamChunk) => void): () => void;
|
|
751
|
+
/** Scan for projects using the service's projectScanner. */
|
|
752
|
+
scanProjects(id: string, rootDir: string): ProjectScanResult[];
|
|
753
|
+
/** Remove all stopped instance state files (and their log files) for a service. */
|
|
754
|
+
purgeStoppedInstances(id: string): void;
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* A central event bus for decoupled communication. Typed for framework
|
|
758
|
+
* events via PhClintEvents<R>; arbitrary string events fall through to
|
|
759
|
+
* the `unknown` payload overload.
|
|
760
|
+
*/
|
|
761
|
+
interface EventBus<R extends DocumentRegistry = AnyRegistry> {
|
|
762
|
+
emit: EmitFn<R>;
|
|
763
|
+
on: OnFn<R>;
|
|
764
|
+
off: OnFn<R>;
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Configuration for the routine loop.
|
|
768
|
+
*/
|
|
769
|
+
interface RoutineConfig {
|
|
770
|
+
/** Service identity — when set, auto-injects service commands for the routine. */
|
|
771
|
+
id?: string;
|
|
772
|
+
/** Display name for auto-injected service commands. Defaults to slugToTitle(id) when omitted. */
|
|
773
|
+
name?: string;
|
|
774
|
+
tickInterval?: number;
|
|
775
|
+
idleInterval?: number;
|
|
776
|
+
/** Project scanner for auto-discovery. Enables `{id}-ls` command when `id` is set. */
|
|
777
|
+
projectScanner?: ProjectScanner;
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* A value that can be provided directly or resolved lazily from context.
|
|
781
|
+
* Used for settings that may depend on runtime state (workdir, config).
|
|
782
|
+
* TConfig is inferred from the CLI's configSchema when used inside defineCli().
|
|
783
|
+
*/
|
|
784
|
+
type Resolvable<T, TConfig = Record<string, unknown>> = T | ((ctx: {
|
|
785
|
+
workdir: string;
|
|
786
|
+
config: TConfig;
|
|
787
|
+
}) => T);
|
|
788
|
+
/**
|
|
789
|
+
* Context passed to agent factory callbacks.
|
|
790
|
+
* Provides everything the factory needs to construct an agent.
|
|
791
|
+
* TConfig is inferred from the CLI's configSchema.
|
|
792
|
+
*/
|
|
793
|
+
interface AgentSetupContext<TConfig = Record<string, unknown>> {
|
|
794
|
+
workdir: string;
|
|
795
|
+
config: TConfig;
|
|
796
|
+
cliName: string;
|
|
797
|
+
cliVersion: string;
|
|
798
|
+
context: CommandContext;
|
|
799
|
+
commands: Command<any, any, any>[];
|
|
800
|
+
/** Skill metadata from PromptsConfig, filtered by agent assignment if configured. */
|
|
801
|
+
skills: SkillInfo[];
|
|
802
|
+
/** Full prompts configuration — agent profiles, skill configs, artifact paths. */
|
|
803
|
+
prompts?: PromptsConfig;
|
|
804
|
+
/**
|
|
805
|
+
* The composed wrap registry from registered lifecycle hooks. Always present;
|
|
806
|
+
* identity wraps when no hook contributes. Mastra uses `wraps.tool` and
|
|
807
|
+
* `wraps.agentStream` to instrument tools and the stream generator.
|
|
808
|
+
*/
|
|
809
|
+
wraps: WrapRegistry;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* A loader that dynamically imports and constructs the agent.
|
|
813
|
+
* Receives the full AgentSetupContext (including auto-injected commands)
|
|
814
|
+
* and should return a configured AgentProvider.
|
|
815
|
+
*/
|
|
816
|
+
type AgentLoader<TConfig = Record<string, unknown>> = (ctx: AgentSetupContext<TConfig>) => Promise<AgentProvider>;
|
|
817
|
+
/**
|
|
818
|
+
* Bootstrap-phase timestamps captured before plugin onInit runs. Plugins use
|
|
819
|
+
* these to emit retroactive spans covering the pre-config window.
|
|
820
|
+
*/
|
|
821
|
+
interface BootTimings {
|
|
822
|
+
/** ms since epoch — set on the first line of bootstrap()/runImpl(). */
|
|
823
|
+
bootStartedAt: number;
|
|
824
|
+
/** ms since epoch — set immediately after resolveConfig() completes. */
|
|
825
|
+
configResolvedAt: number;
|
|
826
|
+
/** ms since epoch — set just before initLifecycle() is invoked. */
|
|
827
|
+
lifecycleInitStartedAt: number;
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Context passed to LifecycleHook.onInit. Fully-resolved config (including
|
|
831
|
+
* plugin schema fragments) plus framework identity and process state.
|
|
832
|
+
*/
|
|
833
|
+
interface LifecycleInitContext {
|
|
834
|
+
/** Fully resolved config (the user's schema + every plugin's contributed fields). */
|
|
835
|
+
config: Record<string, unknown>;
|
|
836
|
+
cliName: string;
|
|
837
|
+
cliVersion: string;
|
|
838
|
+
log: Logger;
|
|
839
|
+
eventBus: EventBus<AnyRegistry>;
|
|
840
|
+
/** Path to ~/.ph/<cliname>/ — plugins persist their own state here. */
|
|
841
|
+
userStoreFolder: string;
|
|
842
|
+
/** True when stdin is a TTY — plugins use this to decide whether to prompt. */
|
|
843
|
+
isInteractive: boolean;
|
|
844
|
+
bootTimings: BootTimings;
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* The four named wrap points the framework exposes for plugins to instrument.
|
|
848
|
+
* Identity wraps are the default; composition is middleware-style.
|
|
849
|
+
*
|
|
850
|
+
* Important: `agentStream` must return `inner` directly when not wrapping —
|
|
851
|
+
* any passthrough `async function*` adds a generator frame per yield.
|
|
852
|
+
*/
|
|
853
|
+
interface WrapRegistry {
|
|
854
|
+
/** Wraps each CLI/agent command execution. */
|
|
855
|
+
command<R>(id: string, inner: () => Promise<R>): Promise<R>;
|
|
856
|
+
/** Wraps the agent stream generator. Return `inner` directly for identity. */
|
|
857
|
+
agentStream<P, O, T>(inner: (prompt: P, opts?: O) => AsyncGenerator<T>, attrs: {
|
|
858
|
+
agentId: string;
|
|
859
|
+
}): (prompt: P, opts?: O) => AsyncGenerator<T>;
|
|
860
|
+
/**
|
|
861
|
+
* Wraps each agent tool's execute function. Implementations must forward
|
|
862
|
+
* every invocation argument — Mastra invokes `execute(args, toolContext)`.
|
|
863
|
+
*/
|
|
864
|
+
tool<T extends {
|
|
865
|
+
execute: (...args: unknown[]) => unknown;
|
|
866
|
+
}>(name: string, tool: T): T;
|
|
867
|
+
/** Wraps a routine iteration body. */
|
|
868
|
+
routineIteration<R>(attrs: {
|
|
869
|
+
index: number;
|
|
870
|
+
}, inner: () => Promise<R>): Promise<R>;
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Returned by LifecycleHook.onInit. Contributes wrap implementations and an
|
|
874
|
+
* optional shutdown function. Empty (no contribute, no shutdown) composes to
|
|
875
|
+
* identity — the plugin had nothing to do this run.
|
|
876
|
+
*/
|
|
877
|
+
interface LifecycleHandle {
|
|
878
|
+
contribute?: Partial<WrapRegistry>;
|
|
879
|
+
shutdown?: () => Promise<void>;
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* A lifecycle hook is a declarative plugin contract:
|
|
883
|
+
* - declares an optional config schema fragment (merged at defineCli time)
|
|
884
|
+
* - declares an `onInit` invoked after config resolves but before any
|
|
885
|
+
* command/stream/iteration runs (mirrors the AgentLoader timing pattern)
|
|
886
|
+
*
|
|
887
|
+
* Hooks register via `defineCli({ lifecycle: [...] })`. They contribute
|
|
888
|
+
* `WrapRegistry` fragments which the framework composes into a single
|
|
889
|
+
* registry. If `lifecycle` is omitted, the framework uses `IDENTITY_WRAPS`
|
|
890
|
+
* — there is no "telemetry off" branch in core, only "no contributions".
|
|
891
|
+
*/
|
|
892
|
+
interface LifecycleHook {
|
|
893
|
+
name: string;
|
|
894
|
+
/** Zod fragment merged into the effective config schema (auto-derives env vars, surfaces in `cli config`). */
|
|
895
|
+
configSchema?: z.ZodObject<any>;
|
|
896
|
+
onInit(ctx: LifecycleInitContext): Promise<LifecycleHandle> | LifecycleHandle;
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Agent profile definition for build-time instruction generation.
|
|
900
|
+
*/
|
|
901
|
+
interface AgentProfileConfig {
|
|
902
|
+
/** Export name prefix in generated TS (e.g. 'RupertDevAgent' → rupertDevAgentInstructions). */
|
|
903
|
+
name: string;
|
|
904
|
+
/** Template filenames within the profiles directory, concatenated in order. */
|
|
905
|
+
sections: string[];
|
|
906
|
+
/** Skill IDs assigned to this agent. */
|
|
907
|
+
skills: string[];
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* Configuration for an individual skill.
|
|
911
|
+
*/
|
|
912
|
+
interface SkillConfig {
|
|
913
|
+
description: string;
|
|
914
|
+
/** Zod schema for additional input fields beyond the base `prompt` field. */
|
|
915
|
+
inputSchema?: import("zod").ZodType;
|
|
916
|
+
/** Handlebars instruction template. Receives { skillId, description, prompt, ...extraInputFields }. */
|
|
917
|
+
instructionTemplate?: string;
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Configuration for agent prompts, profiles, and skills.
|
|
921
|
+
*/
|
|
922
|
+
interface PromptsConfig {
|
|
923
|
+
/** Candidate directories containing pre-built prompt artifacts (skills, agent profiles). First existing wins. */
|
|
924
|
+
artifacts: string[];
|
|
925
|
+
/** Agent profiles: build-time instruction sections + runtime skill assignments. Key = agent ID. */
|
|
926
|
+
agents?: Record<string, AgentProfileConfig>;
|
|
927
|
+
/** Skill configs: description + optional inputSchema + instructionTemplate. Key = skill folder name.
|
|
928
|
+
* A plain string is accepted as shorthand for `{ description: string }`. */
|
|
929
|
+
skills?: Record<string, string | SkillConfig>;
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Static, JSON-serializable metadata about a CLI instance.
|
|
933
|
+
* Returned by `Cli.getMetadata()` for use in build-time template contexts.
|
|
934
|
+
*/
|
|
935
|
+
/** Field metadata for config/command/service parameters in CLI metadata output. */
|
|
936
|
+
interface MetadataField {
|
|
937
|
+
id: string;
|
|
938
|
+
description: string | undefined;
|
|
939
|
+
optional: boolean;
|
|
940
|
+
default?: unknown;
|
|
941
|
+
type: string;
|
|
942
|
+
sensitive: boolean;
|
|
943
|
+
}
|
|
944
|
+
/** Config field metadata — includes env var name. */
|
|
945
|
+
type ConfigMetadataField = MetadataField & {
|
|
946
|
+
env: string;
|
|
947
|
+
};
|
|
948
|
+
interface CliMetadata {
|
|
949
|
+
name: string;
|
|
950
|
+
version: string;
|
|
951
|
+
description: string;
|
|
952
|
+
hasInteractive: boolean;
|
|
953
|
+
hasAgent: boolean;
|
|
954
|
+
/** Whether a Powerhouse reactor integration is configured. */
|
|
955
|
+
hasReactor: boolean;
|
|
956
|
+
config: Record<string, ConfigMetadataField> | null;
|
|
957
|
+
commands: Record<string, {
|
|
958
|
+
id: string;
|
|
959
|
+
description: string;
|
|
960
|
+
params: Record<string, MetadataField>;
|
|
961
|
+
}>;
|
|
962
|
+
services: Record<string, {
|
|
963
|
+
id: string;
|
|
964
|
+
name: string;
|
|
965
|
+
description?: string;
|
|
966
|
+
maxInstances?: number;
|
|
967
|
+
params: Record<string, MetadataField>;
|
|
968
|
+
shutdown?: {
|
|
969
|
+
signal: string;
|
|
970
|
+
timeout: number;
|
|
971
|
+
};
|
|
972
|
+
restart?: {
|
|
973
|
+
enabled: boolean;
|
|
974
|
+
maxRetries: number;
|
|
975
|
+
delay: number;
|
|
976
|
+
};
|
|
977
|
+
readinessTimeout?: number;
|
|
978
|
+
/** MCP tool prefix(es) derived from readiness captures with type 'api-mcp'.
|
|
979
|
+
* undefined = no MCP, string = single MCP endpoint, Record = multiple (keyed by capture name). */
|
|
980
|
+
mcpPrefix?: string | Record<string, string>;
|
|
981
|
+
}> | null;
|
|
982
|
+
prompts: {
|
|
983
|
+
artifacts: string[];
|
|
984
|
+
agents: Record<string, {
|
|
985
|
+
name: string;
|
|
986
|
+
sections: string[];
|
|
987
|
+
skills: string[];
|
|
988
|
+
}>;
|
|
989
|
+
skills: Record<string, string | SkillConfig>;
|
|
990
|
+
resolved: Record<string, {
|
|
991
|
+
id: string;
|
|
992
|
+
description: string;
|
|
993
|
+
}>;
|
|
994
|
+
} | null;
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* Options for defineCli().
|
|
998
|
+
*
|
|
999
|
+
* Generic over TSchema — inferred from `configSchema`. This propagates the
|
|
1000
|
+
* resolved config type into `Resolvable` callbacks, `AgentContext`, and
|
|
1001
|
+
* `InteractiveConfig`, so `ctx.config` is fully typed without casts.
|
|
1002
|
+
*/
|
|
1003
|
+
interface CliOptions<TSchema extends z.ZodType = z.ZodType<Record<string, unknown>>, TSecrets extends z.ZodType = z.ZodType<Record<string, unknown>>> {
|
|
1004
|
+
name: string;
|
|
1005
|
+
version: string;
|
|
1006
|
+
/**
|
|
1007
|
+
* Absolute path to the CLI package root (the directory containing package.json).
|
|
1008
|
+
* Used by the framework to resolve sibling packages (e.g. the `-app` Reactor Package)
|
|
1009
|
+
* and auto-detect Connect assets. Typically set to `CLI_ROOT` from config.ts.
|
|
1010
|
+
*/
|
|
1011
|
+
root?: string;
|
|
1012
|
+
description: Resolvable<string, z.infer<TSchema> & z.infer<TSecrets>>;
|
|
1013
|
+
commands: Command<any, any, any>[];
|
|
1014
|
+
configSchema?: TSchema;
|
|
1015
|
+
/** Schema for sensitive config values. Merged into configSchema internally; values are censored in output. */
|
|
1016
|
+
secretsSchema?: TSecrets;
|
|
1017
|
+
interactive?: InteractiveConfig<z.infer<TSchema> & z.infer<TSecrets>>;
|
|
1018
|
+
/**
|
|
1019
|
+
* Builds the bearer-token handler for the embedded switchboard's HTTP
|
|
1020
|
+
* attachment routes (`/attachments/*`). Called once after config resolves,
|
|
1021
|
+
* with the workdir + resolved config; the returned handler mints a token per
|
|
1022
|
+
* call (or undefined when none is available). The framework has no identity
|
|
1023
|
+
* of its own, so the host CLI supplies this — without it, attachment
|
|
1024
|
+
* reservations against an auth-enabled switchboard are unauthenticated and
|
|
1025
|
+
* rejected (401).
|
|
1026
|
+
*/
|
|
1027
|
+
attachmentJwtHandler?: (ctx: {
|
|
1028
|
+
workdir: string;
|
|
1029
|
+
config: z.infer<TSchema> & z.infer<TSecrets>;
|
|
1030
|
+
}) => ((url: string) => Promise<string | undefined>) | undefined;
|
|
1031
|
+
triggers?: Trigger<any, any, any>[];
|
|
1032
|
+
routine?: RoutineConfig;
|
|
1033
|
+
/** Service definitions for the ServiceManager. */
|
|
1034
|
+
services?: ServiceDefinition<z.infer<TSchema> & z.infer<TSecrets>>[];
|
|
1035
|
+
/** Event handlers registered on the event bus. Receives event data and a logger for display output. */
|
|
1036
|
+
events?: Record<string, (data: any, log: Logger) => void>;
|
|
1037
|
+
/**
|
|
1038
|
+
* Implementation-level workdir override. When set, the --workdir/-w CLI flag
|
|
1039
|
+
* is hidden — the implementation owns the decision of where the workspace is.
|
|
1040
|
+
* When omitted, the user can set it via --workdir or it defaults to cwd.
|
|
1041
|
+
*/
|
|
1042
|
+
workdir?: string;
|
|
1043
|
+
/**
|
|
1044
|
+
* Implementation-level config defaults. These form layer 5 of the 6-layer
|
|
1045
|
+
* config resolution (above hardcoded schema defaults, below user/local config).
|
|
1046
|
+
*/
|
|
1047
|
+
configDefaults?: Record<string, unknown>;
|
|
1048
|
+
/**
|
|
1049
|
+
* Prompts configuration: agent profiles, skill descriptions, and skill sources.
|
|
1050
|
+
* When set, skills are available as CLI commands and auto-installed on first run.
|
|
1051
|
+
*/
|
|
1052
|
+
prompts?: PromptsConfig;
|
|
1053
|
+
/**
|
|
1054
|
+
* When true, an embedded reverse proxy is started that exposes all service
|
|
1055
|
+
* endpoints through a single port. Config fields `proxyPort` and `proxyHost`
|
|
1056
|
+
* are auto-injected into the config schema.
|
|
1057
|
+
*/
|
|
1058
|
+
proxyEnabled?: boolean;
|
|
1059
|
+
/**
|
|
1060
|
+
* Extra proxy routes registered at startup, alongside the service-derived
|
|
1061
|
+
* ones. For in-process HTTP servers on fixed ports (e.g. a trigger-owned
|
|
1062
|
+
* API) that the ServiceManager doesn't know about. Requires `proxyEnabled`.
|
|
1063
|
+
*/
|
|
1064
|
+
proxyRoutes?: Array<{
|
|
1065
|
+
/** URL path prefix matched against incoming requests (e.g. '/preview'). */
|
|
1066
|
+
prefix: string;
|
|
1067
|
+
/** Upstream target URL (e.g. 'http://127.0.0.1:5180'). */
|
|
1068
|
+
upstream: string;
|
|
1069
|
+
/** Forward WebSocket upgrades on this route. */
|
|
1070
|
+
ws?: boolean;
|
|
1071
|
+
}>;
|
|
1072
|
+
/**
|
|
1073
|
+
* Lifecycle hooks registered with this CLI. Each hook may contribute a
|
|
1074
|
+
* config schema fragment (merged into the effective schema, so its fields
|
|
1075
|
+
* flow through the 6-layer resolver and `cli config`) and an `onInit`
|
|
1076
|
+
* callback invoked after config resolves with the resulting `WrapRegistry`
|
|
1077
|
+
* contributions composed into the framework.
|
|
1078
|
+
*
|
|
1079
|
+
* Identity wraps are the default — omit or pass `[]` for no instrumentation.
|
|
1080
|
+
*/
|
|
1081
|
+
lifecycle?: LifecycleHook[];
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* Output handlers for run(). Defaults to process.exit/console.log/process.stderr.
|
|
1085
|
+
*
|
|
1086
|
+
* For interactive mode testing, `interactiveInput` provides a headless REPL
|
|
1087
|
+
* that reads from the iterable instead of rendering Ink.
|
|
1088
|
+
*/
|
|
1089
|
+
interface RunOptions {
|
|
1090
|
+
exit?: (code: number) => void;
|
|
1091
|
+
stdout?: (message: string) => void;
|
|
1092
|
+
stderr?: (message: string) => void;
|
|
1093
|
+
/** Headless interactive mode: lines are read from this iterable instead of Ink. */
|
|
1094
|
+
interactiveInput?: AsyncIterable<string>;
|
|
1095
|
+
/** Resume a previous agent conversation by thread ID. */
|
|
1096
|
+
resume?: string;
|
|
1097
|
+
/** Override workdir for testing (replaces cwd fallback). */
|
|
1098
|
+
workdir?: string;
|
|
1099
|
+
/** Path to a config file (--config flag value), relative to cwd. */
|
|
1100
|
+
configFile?: string;
|
|
1101
|
+
/** Override log verbosity. Default: 'info'. */
|
|
1102
|
+
logLevel?: LogLevel;
|
|
1103
|
+
}
|
|
1104
|
+
/**
|
|
1105
|
+
* Environment variable mapping for a config field.
|
|
1106
|
+
*/
|
|
1107
|
+
interface ConfigEnvVar {
|
|
1108
|
+
name: string;
|
|
1109
|
+
field: string;
|
|
1110
|
+
description: string;
|
|
1111
|
+
}
|
|
1112
|
+
/**
|
|
1113
|
+
* A CLI instance returned by defineCli().
|
|
1114
|
+
*/
|
|
1115
|
+
interface Cli {
|
|
1116
|
+
name: string;
|
|
1117
|
+
version: string;
|
|
1118
|
+
description: string;
|
|
1119
|
+
configSchema?: z.ZodType;
|
|
1120
|
+
interactive?: InteractiveConfig<any> | ResolvedInteractiveConfig;
|
|
1121
|
+
/** True when an agent loader has been set. */
|
|
1122
|
+
hasAgent: boolean;
|
|
1123
|
+
/** True when a reactor configuration has been set. */
|
|
1124
|
+
hasReactor: boolean;
|
|
1125
|
+
/** Configure the agent factory — called lazily when the agent is first needed. */
|
|
1126
|
+
configureAgent(loader: AgentLoader<any>): void;
|
|
1127
|
+
/** Configure the reactor capability — lazy-loaded on first reactor() access. */
|
|
1128
|
+
configureReactor<R extends DocumentRegistry = AnyRegistry>(config: ReactorConfiguration<R>): void;
|
|
1129
|
+
getCommand(id: string): Command | undefined;
|
|
1130
|
+
listCommands(): Command[];
|
|
1131
|
+
execute(commandId: string, args: Record<string, unknown>, context?: CommandContext): Promise<unknown>;
|
|
1132
|
+
parseArgs(commandId: string, argv: string[]): Record<string, unknown>;
|
|
1133
|
+
generateHelp(): string;
|
|
1134
|
+
generateCommandHelp(commandId: string): string;
|
|
1135
|
+
generateCompletion(shell: string): string;
|
|
1136
|
+
configEnvVars(): ConfigEnvVar[];
|
|
1137
|
+
/** Return static, JSON-serializable metadata about this CLI. */
|
|
1138
|
+
getMetadata(): CliMetadata;
|
|
1139
|
+
/**
|
|
1140
|
+
* Initialize the CLI runtime (workdir, config, context, lazy agent) without
|
|
1141
|
+
* entering the command/REPL dispatch loop. Useful for programmatic access
|
|
1142
|
+
* to the configured agent — e.g. in a generated `mastra/index.ts`.
|
|
1143
|
+
*/
|
|
1144
|
+
bootstrap(opts?: BootstrapOptions): Promise<BootstrapResult>;
|
|
1145
|
+
run(argv: string[], options?: RunOptions): Promise<void>;
|
|
1146
|
+
stopRoutine?(): Promise<void>;
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* Options for `Cli.bootstrap()` — lightweight runtime init without dispatch.
|
|
1150
|
+
*/
|
|
1151
|
+
interface BootstrapOptions {
|
|
1152
|
+
/** Explicit workdir (skips resolveWorkdir flag/cwd logic). */
|
|
1153
|
+
workdir?: string;
|
|
1154
|
+
/** Config file override (equivalent to --config flag). */
|
|
1155
|
+
configFile?: string;
|
|
1156
|
+
/** Log level — default 'info'. */
|
|
1157
|
+
logLevel?: LogLevel;
|
|
1158
|
+
/** Custom stdout sink — default console.log. */
|
|
1159
|
+
stdout?: (text: string) => void;
|
|
1160
|
+
/** Custom stderr sink — default console.error. */
|
|
1161
|
+
stderr?: (text: string) => void;
|
|
1162
|
+
}
|
|
1163
|
+
/**
|
|
1164
|
+
* Result of `Cli.bootstrap()` — provides access to the initialized runtime.
|
|
1165
|
+
*/
|
|
1166
|
+
interface BootstrapResult {
|
|
1167
|
+
workdir: string;
|
|
1168
|
+
config: Record<string, unknown>;
|
|
1169
|
+
context: CommandContext;
|
|
1170
|
+
/** Lazy-load the AgentProvider (calls the agent factory on first access). */
|
|
1171
|
+
getAgent(): Promise<AgentProvider | undefined>;
|
|
1172
|
+
/** The raw Mastra Agent from the provider, if available. Lazy-loads the agent. */
|
|
1173
|
+
get mastraAgent(): Promise<unknown>;
|
|
1174
|
+
}
|
|
1175
|
+
//#endregion
|
|
1176
|
+
//#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/kysely.d.ts
|
|
1177
|
+
declare global {
|
|
1178
|
+
interface AsyncDisposable {}
|
|
1179
|
+
interface SymbolConstructor {
|
|
1180
|
+
readonly asyncDispose: unique symbol;
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
//#endregion
|
|
1184
|
+
//#region ../reactor-attachments/dist/interfaces-C4GRlKeB.d.ts
|
|
1185
|
+
/**
|
|
1186
|
+
* Status of attachment data in the local store.
|
|
1187
|
+
* 'pending' is a virtual status synthesized at query time from live,
|
|
1188
|
+
* hash-bearing reservations -- it never appears in the attachment table.
|
|
1189
|
+
*/
|
|
1190
|
+
type AttachmentStatus = "available" | "evicted" | "pending";
|
|
1191
|
+
/**
|
|
1192
|
+
* Metadata about an attachment. For committed attachments (available/evicted),
|
|
1193
|
+
* expiresAtUtc is null. For pending attachments synthesized from a live
|
|
1194
|
+
* reservation, expiresAtUtc carries the reservation expiry so callers can
|
|
1195
|
+
* emit Retry-After or bound polling loops.
|
|
1196
|
+
*/
|
|
1197
|
+
type AttachmentHeader = {
|
|
1198
|
+
hash: AttachmentHash;
|
|
1199
|
+
mimeType: string;
|
|
1200
|
+
fileName: string;
|
|
1201
|
+
sizeBytes: number;
|
|
1202
|
+
extension: string | null;
|
|
1203
|
+
status: AttachmentStatus;
|
|
1204
|
+
source: "local" | "sync";
|
|
1205
|
+
createdAtUtc: string;
|
|
1206
|
+
lastAccessedAtUtc: string;
|
|
1207
|
+
expiresAtUtc: string | null;
|
|
1208
|
+
};
|
|
1209
|
+
/**
|
|
1210
|
+
* Upload-first reservation. clientHash and sizeBytes are absent;
|
|
1211
|
+
* the ref is only known after send() completes.
|
|
1212
|
+
*/
|
|
1213
|
+
type UploadFirstReserveAttachmentOptions = {
|
|
1214
|
+
mimeType: string;
|
|
1215
|
+
fileName: string;
|
|
1216
|
+
extension?: string | null;
|
|
1217
|
+
clientHash?: undefined;
|
|
1218
|
+
sizeBytes?: undefined;
|
|
1219
|
+
};
|
|
1220
|
+
/**
|
|
1221
|
+
* Hash-first reservation. clientHash is present and sizeBytes is required.
|
|
1222
|
+
* The ref is known at reservation time; send() verifies the uploaded bytes
|
|
1223
|
+
* against the claimed hash and declared size. The explicit "?: undefined"
|
|
1224
|
+
* on UploadFirstReserveAttachmentOptions makes clientHash a narrowing discriminant:
|
|
1225
|
+
* checking options.clientHash !== undefined narrows sizeBytes to number.
|
|
1226
|
+
*/
|
|
1227
|
+
type HashFirstReserveAttachmentOptions = {
|
|
1228
|
+
mimeType: string;
|
|
1229
|
+
fileName: string;
|
|
1230
|
+
extension?: string | null;
|
|
1231
|
+
/**
|
|
1232
|
+
* Content hash claimed by the client (lowercase SHA-256 hex).
|
|
1233
|
+
*/
|
|
1234
|
+
clientHash: AttachmentHash;
|
|
1235
|
+
/**
|
|
1236
|
+
* Declared size in bytes. Required when clientHash is present.
|
|
1237
|
+
* Reported by stat() during the pending window and enforced on
|
|
1238
|
+
* ingest: an upload whose actual byte count differs is rejected.
|
|
1239
|
+
*/
|
|
1240
|
+
sizeBytes: number;
|
|
1241
|
+
};
|
|
1242
|
+
/**
|
|
1243
|
+
* Options provided when reserving an attachment slot.
|
|
1244
|
+
*
|
|
1245
|
+
* Use HashFirstReserveAttachmentOptions when clientHash is known up front;
|
|
1246
|
+
* the service then operates in hash-first mode: reserve() rejects if the
|
|
1247
|
+
* content is already available, and send() verifies the uploaded bytes.
|
|
1248
|
+
*
|
|
1249
|
+
* Use UploadFirstReserveAttachmentOptions (or omit clientHash) for the
|
|
1250
|
+
* upload-first flow where the ref is only known after send() completes.
|
|
1251
|
+
*/
|
|
1252
|
+
type ReserveAttachmentOptions = UploadFirstReserveAttachmentOptions | HashFirstReserveAttachmentOptions;
|
|
1253
|
+
/**
|
|
1254
|
+
* Result of uploading attachment data through a handle.
|
|
1255
|
+
*/
|
|
1256
|
+
type AttachmentUploadResult = {
|
|
1257
|
+
hash: AttachmentHash;
|
|
1258
|
+
ref: AttachmentRef;
|
|
1259
|
+
header: AttachmentHeader;
|
|
1260
|
+
};
|
|
1261
|
+
/**
|
|
1262
|
+
* Options for one byte transfer through an upload handle.
|
|
1263
|
+
*
|
|
1264
|
+
* `onProgress` is best-effort: a transport that cannot observe its own
|
|
1265
|
+
* upload bytes (notably `fetch`, which exposes no upload-side progress)
|
|
1266
|
+
* simply never calls it. Absence is the signal — there is no capability
|
|
1267
|
+
* negotiation.
|
|
1268
|
+
*/
|
|
1269
|
+
type AttachmentSendOptions = {
|
|
1270
|
+
onProgress?: (loaded: number, total?: number) => void;
|
|
1271
|
+
signal?: AbortSignal;
|
|
1272
|
+
};
|
|
1273
|
+
/**
|
|
1274
|
+
* Options form of IAttachmentService.get. `documentId` anchors the download
|
|
1275
|
+
* authorization for remote readers; it never becomes part of the ref or any
|
|
1276
|
+
* global configuration.
|
|
1277
|
+
*/
|
|
1278
|
+
type AttachmentDownloadOptions = {
|
|
1279
|
+
documentId?: string;
|
|
1280
|
+
signal?: AbortSignal;
|
|
1281
|
+
};
|
|
1282
|
+
/** Options form of IAttachmentService.stat. */
|
|
1283
|
+
type AttachmentStatOptions = {
|
|
1284
|
+
documentId?: string;
|
|
1285
|
+
};
|
|
1286
|
+
/**
|
|
1287
|
+
* Options for minting a raw download target without transferring bytes
|
|
1288
|
+
* (previews, share links). `documentId` is required: targets are always
|
|
1289
|
+
* document-authorized. `expiresIn` (seconds) requests a caller-chosen
|
|
1290
|
+
* target lifetime; the server clamps it to its configured maximum.
|
|
1291
|
+
*/
|
|
1292
|
+
type AttachmentDownloadTargetOptions = {
|
|
1293
|
+
documentId: string;
|
|
1294
|
+
expiresIn?: number;
|
|
1295
|
+
signal?: AbortSignal;
|
|
1296
|
+
};
|
|
1297
|
+
/** Exact HTTP headers that must be sent with an attachment transfer target. */
|
|
1298
|
+
type AttachmentTargetHeaders = Readonly<Record<string, string>>;
|
|
1299
|
+
type SwitchboardAttachmentUploadTarget = {
|
|
1300
|
+
kind: "switchboard";
|
|
1301
|
+
method: "PUT";
|
|
1302
|
+
url: string;
|
|
1303
|
+
headers: AttachmentTargetHeaders;
|
|
1304
|
+
expiresAtUtc?: string;
|
|
1305
|
+
};
|
|
1306
|
+
type PresignedPutAttachmentUploadTarget = {
|
|
1307
|
+
kind: "presigned-put";
|
|
1308
|
+
method: "PUT";
|
|
1309
|
+
url: string;
|
|
1310
|
+
headers: AttachmentTargetHeaders;
|
|
1311
|
+
expiresAtUtc: string;
|
|
1312
|
+
};
|
|
1313
|
+
/** Provider-neutral target returned to a client that needs to upload bytes. */
|
|
1314
|
+
type AttachmentUploadTarget = SwitchboardAttachmentUploadTarget | PresignedPutAttachmentUploadTarget;
|
|
1315
|
+
type SwitchboardAttachmentDownloadTarget = {
|
|
1316
|
+
kind: "switchboard";
|
|
1317
|
+
method: "GET";
|
|
1318
|
+
url: string;
|
|
1319
|
+
headers: AttachmentTargetHeaders;
|
|
1320
|
+
expiresAtUtc?: string;
|
|
1321
|
+
};
|
|
1322
|
+
type PresignedGetAttachmentDownloadTarget = {
|
|
1323
|
+
kind: "presigned-get";
|
|
1324
|
+
method: "GET";
|
|
1325
|
+
url: string;
|
|
1326
|
+
headers: AttachmentTargetHeaders;
|
|
1327
|
+
expiresAtUtc: string;
|
|
1328
|
+
};
|
|
1329
|
+
/** Provider-neutral target returned to a client that needs to download bytes. */
|
|
1330
|
+
type AttachmentDownloadTarget = SwitchboardAttachmentDownloadTarget | PresignedGetAttachmentDownloadTarget;
|
|
1331
|
+
/**
|
|
1332
|
+
* Response when retrieving attachment data from the local store.
|
|
1333
|
+
*/
|
|
1334
|
+
type AttachmentResponse = {
|
|
1335
|
+
header: AttachmentHeader;
|
|
1336
|
+
body: ReadableStream<Uint8Array>;
|
|
1337
|
+
};
|
|
1338
|
+
//#endregion
|
|
1339
|
+
//#region src/interfaces.d.ts
|
|
1340
|
+
/**
|
|
1341
|
+
* Client-facing interface for uploading, querying, and retrieving attachments.
|
|
1342
|
+
* This is what applications (editors, Connect, CLI tools) interact with.
|
|
1343
|
+
*/
|
|
1344
|
+
interface IAttachmentService {
|
|
1345
|
+
/**
|
|
1346
|
+
* Reserve a new attachment slot and return an upload handle.
|
|
1347
|
+
*
|
|
1348
|
+
* When options.clientHash is provided (hash-first mode):
|
|
1349
|
+
* - @throws AttachmentAlreadyExists if data for that hash is currently
|
|
1350
|
+
* available. The error carries the canonical ref; the caller uses it
|
|
1351
|
+
* directly and uploads nothing (dedup fast path).
|
|
1352
|
+
* - If the hash is evicted, the reservation is created: the client holds
|
|
1353
|
+
* the bytes and the upload restores them.
|
|
1354
|
+
* - If the hash is pending (another in-flight reservation), the
|
|
1355
|
+
* reservation is created: concurrent reservations are deliberately
|
|
1356
|
+
* permitted (see design doc -- no uniqueness race).
|
|
1357
|
+
* - The returned handle's ref field is set immediately to the computed ref.
|
|
1358
|
+
*
|
|
1359
|
+
* When options.clientHash is absent (upload-first mode):
|
|
1360
|
+
* - No pre-check against the store.
|
|
1361
|
+
* - The returned handle's ref field is null until send() completes.
|
|
1362
|
+
*/
|
|
1363
|
+
reserve(options: ReserveAttachmentOptions): Promise<IAttachmentUpload>;
|
|
1364
|
+
/**
|
|
1365
|
+
* Get attachment metadata by ref.
|
|
1366
|
+
*
|
|
1367
|
+
* @throws AttachmentNotFound if the ref is unknown.
|
|
1368
|
+
* Returns an AttachmentHeader with status='pending' and expiresAtUtc set if
|
|
1369
|
+
* the hash has an active reservation but no committed bytes. Callers must
|
|
1370
|
+
* check header.status to distinguish pending from available.
|
|
1371
|
+
*
|
|
1372
|
+
* `documentId` names the document that authorizes the read. Remote readers
|
|
1373
|
+
* require it; local/direct readers ignore it.
|
|
1374
|
+
*/
|
|
1375
|
+
stat(ref: AttachmentRef, options?: AttachmentStatOptions): Promise<AttachmentHeader>;
|
|
1376
|
+
/**
|
|
1377
|
+
* Retrieve attachment data.
|
|
1378
|
+
*
|
|
1379
|
+
* Always succeeds for any known, available ref. The underlying store
|
|
1380
|
+
* handles re-fetching evicted data from the transport transparently.
|
|
1381
|
+
*
|
|
1382
|
+
* @throws AttachmentPending if the hash is reserved but bytes not yet
|
|
1383
|
+
* available. There is no store-level wait; polling across the
|
|
1384
|
+
* pending window is the caller's loop, bounded by the error's
|
|
1385
|
+
* expiresAtUtc. A wait inside get() would hold request handlers
|
|
1386
|
+
* open across multi-second windows and hide retry policy where
|
|
1387
|
+
* callers cannot tune it.
|
|
1388
|
+
*
|
|
1389
|
+
* The options form carries the document id that authorizes a remote
|
|
1390
|
+
* download. Remote readers require it; local/direct readers ignore it.
|
|
1391
|
+
*/
|
|
1392
|
+
get(ref: AttachmentRef, options?: AbortSignal | AttachmentDownloadOptions): Promise<AttachmentResponse>;
|
|
1393
|
+
/**
|
|
1394
|
+
* Obtain the raw, document-authorized download target for a ref without
|
|
1395
|
+
* transferring any bytes. Used to mint direct URLs (previews, share
|
|
1396
|
+
* links): a presigned target URL is a self-contained public capability
|
|
1397
|
+
* until its expiry. `expiresIn` (seconds) requests a caller-chosen
|
|
1398
|
+
* lifetime; the server clamps it to its configured maximum.
|
|
1399
|
+
*
|
|
1400
|
+
* @throws when the underlying store cannot produce download targets
|
|
1401
|
+
* (local/direct stores serve bytes, not URLs).
|
|
1402
|
+
*/
|
|
1403
|
+
getDownloadTarget(ref: AttachmentRef, options: AttachmentDownloadTargetOptions): Promise<AttachmentDownloadTarget>;
|
|
1404
|
+
}
|
|
1405
|
+
/**
|
|
1406
|
+
* Upload handle returned by reserve(). Encapsulates all transport-specific
|
|
1407
|
+
* concerns (URLs, credentials, streaming protocols) behind a single send() method.
|
|
1408
|
+
*/
|
|
1409
|
+
interface IAttachmentUpload {
|
|
1410
|
+
/**
|
|
1411
|
+
* Unique identifier for this reservation.
|
|
1412
|
+
*/
|
|
1413
|
+
reservationId: string;
|
|
1414
|
+
/**
|
|
1415
|
+
* The ref this upload will produce. Set immediately when the
|
|
1416
|
+
* reservation carries a client hash (hash-first mode); null in the
|
|
1417
|
+
* upload-first flow, where the ref is only known after send() completes.
|
|
1418
|
+
*/
|
|
1419
|
+
ref: AttachmentRef | null;
|
|
1420
|
+
/**
|
|
1421
|
+
* Reservation TTL contract, from the server in remote mode.
|
|
1422
|
+
* ISO 8601 UTC string indicating when the reservation expires.
|
|
1423
|
+
* Clients use this to bound retry windows and populate the pending-upload queue.
|
|
1424
|
+
*/
|
|
1425
|
+
readonly expiresAtUtc: string;
|
|
1426
|
+
/** Direct transfer target returned by target-capable server backends. */
|
|
1427
|
+
readonly uploadTarget?: AttachmentUploadTarget;
|
|
1428
|
+
/**
|
|
1429
|
+
* Stream attachment data through this handle.
|
|
1430
|
+
*
|
|
1431
|
+
* `data` may be a Blob: a remote handle sends it as the request body
|
|
1432
|
+
* as-is, which a browser streams from disk instead of buffering.
|
|
1433
|
+
*
|
|
1434
|
+
* The handle manages the full upload lifecycle internally:
|
|
1435
|
+
* writing bytes to the backing store, computing or verifying
|
|
1436
|
+
* the content hash, creating the attachment record, and
|
|
1437
|
+
* cleaning up the reservation.
|
|
1438
|
+
*
|
|
1439
|
+
* Dedup: if an attachment with the same content hash already
|
|
1440
|
+
* exists, send() returns the existing ref. Content-addressed
|
|
1441
|
+
* storage means identical uploads converge on the same hash.
|
|
1442
|
+
*
|
|
1443
|
+
* When the reservation carries a client hash, the handle verifies
|
|
1444
|
+
* the received bytes against the claims:
|
|
1445
|
+
* - @throws SizeMismatch if the byte count differs from the declared
|
|
1446
|
+
* sizeBytes. The handle may reject mid-stream as soon as the count
|
|
1447
|
+
* exceeds the declaration, without consuming the rest.
|
|
1448
|
+
* - @throws HashMismatch if the server-computed hash differs from the
|
|
1449
|
+
* claimed hash. Nothing is committed; the reservation is retained
|
|
1450
|
+
* so the client can retry with the correct bytes.
|
|
1451
|
+
*
|
|
1452
|
+
* @returns The content hash, ref, and header for the uploaded attachment.
|
|
1453
|
+
*
|
|
1454
|
+
* `options.onProgress` reports bytes handed to the transport, when the
|
|
1455
|
+
* transport can observe them at all -- some cannot, so it may never fire,
|
|
1456
|
+
* and an implementation is free to ignore it.
|
|
1457
|
+
*
|
|
1458
|
+
* `options.signal` aborts the transfer in flight, and any implementation
|
|
1459
|
+
* that moves bytes must honour it: reject with an `AbortError` and commit
|
|
1460
|
+
* nothing. `useAttachmentUpload().cancel()` promises exactly that, so an
|
|
1461
|
+
* implementation that quietly ran to completion would report a cancelled
|
|
1462
|
+
* upload as done. A handle that transfers nothing itself (the S3 handle,
|
|
1463
|
+
* which requires its presigned target) has nothing to abort.
|
|
1464
|
+
*/
|
|
1465
|
+
send(data: ReadableStream<Uint8Array> | Blob, options?: AttachmentSendOptions): Promise<AttachmentUploadResult>;
|
|
1466
|
+
}
|
|
1467
|
+
//#endregion
|
|
1468
|
+
//#region src/integrations/powerhouse/types.d.ts
|
|
1469
|
+
/**
|
|
1470
|
+
* Options for creating an empty document. Mirrors the internal
|
|
1471
|
+
* `CreateDocumentOptions` type in @powerhousedao/reactor (not exported there).
|
|
1472
|
+
*/
|
|
1473
|
+
interface CreateDocumentOptions {
|
|
1474
|
+
parentIdentifier?: string;
|
|
1475
|
+
documentModelVersion?: number;
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1478
|
+
* One entry in a DocumentRegistry. Carries enough to narrow every
|
|
1479
|
+
* IReactorClient method that touches a PHDocument or Action.
|
|
1480
|
+
*
|
|
1481
|
+
* - `document` — the concrete PHDocument shape returned by `get`, `create`, etc.
|
|
1482
|
+
* - `actions` — union of Action types accepted by `execute` / `executeAsync`.
|
|
1483
|
+
* - `state` — the global state shape, used by `DocumentModelModule<S>` introspection.
|
|
1484
|
+
*/
|
|
1485
|
+
interface RegistryEntry<S extends PHBaseState = PHBaseState, A extends Action = Action> {
|
|
1486
|
+
document: PHDocument<S>;
|
|
1487
|
+
actions: A;
|
|
1488
|
+
state: S;
|
|
1489
|
+
}
|
|
1490
|
+
/**
|
|
1491
|
+
* Maps a documentType string → RegistryEntry. Impls build one with
|
|
1492
|
+
* `defineRegistry([Module1, Module2] as const)`; see registry.ts.
|
|
1493
|
+
*/
|
|
1494
|
+
type DocumentRegistry = Record<string, RegistryEntry>;
|
|
1495
|
+
/**
|
|
1496
|
+
* Fallback registry used when a CLI doesn't declare one.
|
|
1497
|
+
* Every slot resolves to the base PHDocument / Action shapes.
|
|
1498
|
+
* `R = AnyRegistry` is the default for ReactorContext, CoreContext, etc.
|
|
1499
|
+
*/
|
|
1500
|
+
type AnyRegistry = Record<string, RegistryEntry>;
|
|
1501
|
+
/**
|
|
1502
|
+
* Typed view over IReactorClient. Every method that takes a documentType
|
|
1503
|
+
* string, returns a PHDocument, or accepts an Action is re-declared with
|
|
1504
|
+
* registry-derived types. All other methods are inherited via `Omit<…>`.
|
|
1505
|
+
*
|
|
1506
|
+
* Runtime: the underlying object IS an IReactorClient — we only cast at the
|
|
1507
|
+
* ReactorContext boundary. No runtime wrapping, no perf cost.
|
|
1508
|
+
*/
|
|
1509
|
+
interface TypedReactorClient<R extends DocumentRegistry> extends Omit<IReactorClient, "get" | "getOutgoingRelationships" | "getIncomingRelationships" | "find" | "getDocumentModelModule" | "create" | "createEmpty" | "createDocumentInDrive" | "execute" | "executeAsync" | "rename" | "addRelationship" | "removeRelationship" | "moveRelationship" | "subscribe"> {
|
|
1510
|
+
get<T extends keyof R & string = keyof R & string>(identifier: string, view?: ViewFilter, signal?: AbortSignal): Promise<R[T]["document"]>;
|
|
1511
|
+
getOutgoingRelationships<T extends keyof R & string = keyof R & string>(sourceIdentifier: string, relationshipType: string, view?: ViewFilter, paging?: PagingOptions, signal?: AbortSignal): Promise<PagedResults<R[T]["document"]>>;
|
|
1512
|
+
getIncomingRelationships<T extends keyof R & string = keyof R & string>(targetIdentifier: string, relationshipType: string, view?: ViewFilter, paging?: PagingOptions, signal?: AbortSignal): Promise<PagedResults<R[T]["document"]>>;
|
|
1513
|
+
find<T extends keyof R & string = keyof R & string>(search: Omit<SearchFilter, "documentTypes"> & {
|
|
1514
|
+
documentTypes?: T[];
|
|
1515
|
+
}, view?: ViewFilter, paging?: PagingOptions, signal?: AbortSignal): Promise<PagedResults<R[T]["document"]>>;
|
|
1516
|
+
getDocumentModelModule<T extends keyof R & string>(documentType: T): Promise<DocumentModelModule<R[T]["state"]>>;
|
|
1517
|
+
create<T extends keyof R & string = keyof R & string>(document: R[T]["document"], parentIdentifier?: string, signal?: AbortSignal): Promise<R[T]["document"]>;
|
|
1518
|
+
createEmpty<T extends keyof R & string>(documentModelType: T, options?: CreateDocumentOptions, signal?: AbortSignal): Promise<R[T]["document"]>;
|
|
1519
|
+
createDocumentInDrive<T extends keyof R & string = keyof R & string>(driveId: string, document: R[T]["document"], parentFolder?: string, signal?: AbortSignal): Promise<R[T]["document"]>;
|
|
1520
|
+
execute<T extends keyof R & string = keyof R & string>(documentIdentifier: string, branch: string, actions: Array<R[T]["actions"]>, signal?: AbortSignal): Promise<R[T]["document"]>;
|
|
1521
|
+
executeAsync<T extends keyof R & string = keyof R & string>(documentIdentifier: string, branch: string, actions: Array<R[T]["actions"]>, signal?: AbortSignal): Promise<JobInfo>;
|
|
1522
|
+
rename<T extends keyof R & string = keyof R & string>(documentIdentifier: string, name: string, branch?: string, signal?: AbortSignal): Promise<R[T]["document"]>;
|
|
1523
|
+
addRelationship<T extends keyof R & string = keyof R & string>(sourceIdentifier: string, targetIdentifier: string, relationshipType: string, branch?: string, signal?: AbortSignal): Promise<R[T]["document"]>;
|
|
1524
|
+
removeRelationship<T extends keyof R & string = keyof R & string>(sourceIdentifier: string, targetIdentifier: string, relationshipType: string, branch?: string, signal?: AbortSignal): Promise<R[T]["document"]>;
|
|
1525
|
+
moveRelationship<T extends keyof R & string = keyof R & string>(sourceParentIdentifier: string, targetParentIdentifier: string, targetIdentifier: string, relationshipType: string, branch?: string, signal?: AbortSignal): Promise<{
|
|
1526
|
+
source: R[T]["document"];
|
|
1527
|
+
target: R[T]["document"];
|
|
1528
|
+
}>;
|
|
1529
|
+
subscribe<T extends keyof R & string = keyof R & string>(search: Omit<SearchFilter, "documentTypes"> & {
|
|
1530
|
+
documentTypes?: T[];
|
|
1531
|
+
}, callback: (event: TypedDocumentChangeEvent<R, T>) => void, view?: ViewFilter): () => void;
|
|
1532
|
+
}
|
|
1533
|
+
/** Narrowed DocumentChangeEvent carrying registry-typed documents. */
|
|
1534
|
+
interface TypedDocumentChangeEvent<R extends DocumentRegistry, T extends keyof R & string = keyof R & string> extends Omit<DocumentChangeEvent, "documents"> {
|
|
1535
|
+
documents: Array<R[T]["document"]>;
|
|
1536
|
+
}
|
|
1537
|
+
/**
|
|
1538
|
+
* Structural type for the ReactorClientModule returned by
|
|
1539
|
+
* @powerhousedao/reactor's ReactorClientBuilder.buildModule().
|
|
1540
|
+
*
|
|
1541
|
+
* Used as the boundary type between buildReactor() and its consumers
|
|
1542
|
+
* (ensureDrive, startSwitchboard, buildDefaultReactor). The actual module
|
|
1543
|
+
* has additional properties; this captures the subset ph-clint uses.
|
|
1544
|
+
*
|
|
1545
|
+
* Imported via `import type` — zero runtime coupling.
|
|
1546
|
+
*/
|
|
1547
|
+
interface ReactorClientModule {
|
|
1548
|
+
client: IReactorClient;
|
|
1549
|
+
reactor: {
|
|
1550
|
+
kill(): {
|
|
1551
|
+
completed: Promise<void>;
|
|
1552
|
+
};
|
|
1553
|
+
findByType(documentType: string): Promise<{
|
|
1554
|
+
results?: Array<{
|
|
1555
|
+
header: {
|
|
1556
|
+
id: string;
|
|
1557
|
+
};
|
|
1558
|
+
}>;
|
|
1559
|
+
} | undefined>;
|
|
1560
|
+
};
|
|
1561
|
+
}
|
|
1562
|
+
/**
|
|
1563
|
+
* A drive managed by the reactor. Each drive has a role:
|
|
1564
|
+
* - `personal` — the agent's own workspace drive
|
|
1565
|
+
* - `watched` — an observed drive (local or remote)
|
|
1566
|
+
*/
|
|
1567
|
+
interface DriveEntry {
|
|
1568
|
+
/** Drive document ID. */
|
|
1569
|
+
id: string;
|
|
1570
|
+
/** Display name. */
|
|
1571
|
+
name: string;
|
|
1572
|
+
/** Role: 'personal' = agent's own workspace, 'watched' = observed from elsewhere. */
|
|
1573
|
+
role: "personal" | "watched";
|
|
1574
|
+
/** For watched remote drives: the Switchboard URL to sync from. */
|
|
1575
|
+
remoteUrl?: string;
|
|
1576
|
+
}
|
|
1577
|
+
/**
|
|
1578
|
+
* An entry in a drive folder listing — either a folder node or a document node.
|
|
1579
|
+
*/
|
|
1580
|
+
interface FolderEntry {
|
|
1581
|
+
/** Document ID of the folder or document node. */
|
|
1582
|
+
id: string;
|
|
1583
|
+
/** Display name. */
|
|
1584
|
+
name: string;
|
|
1585
|
+
/** Whether this is a folder node or a document node. */
|
|
1586
|
+
type: "folder" | "document";
|
|
1587
|
+
/** Document type (only for type: 'document'). */
|
|
1588
|
+
documentType?: string;
|
|
1589
|
+
/** Full path from drive root, e.g. "specs/my-project". */
|
|
1590
|
+
path: string;
|
|
1591
|
+
}
|
|
1592
|
+
/**
|
|
1593
|
+
* Programmatic API for managing documents in the agent's personal drive
|
|
1594
|
+
* using the reactor's native folder hierarchy.
|
|
1595
|
+
*/
|
|
1596
|
+
interface FolderOperations {
|
|
1597
|
+
/** Add/link a document to the personal drive at the given folder path. Creates folders as needed. */
|
|
1598
|
+
addDocument(documentId: string, folderPath: string, name?: string): Promise<void>;
|
|
1599
|
+
/** Create a new document bound to the personal drive at the given folder path. */
|
|
1600
|
+
createDocument(documentType: string, folderPath: string, name?: string): Promise<{
|
|
1601
|
+
documentId: string;
|
|
1602
|
+
}>;
|
|
1603
|
+
/** Remove a document from the personal drive (unlink, not delete the document itself). */
|
|
1604
|
+
removeDocument(documentId: string, folderPath?: string): Promise<void>;
|
|
1605
|
+
/** Get a document by ID from the personal drive. */
|
|
1606
|
+
getDocument(documentId: string): Promise<unknown>;
|
|
1607
|
+
/** List contents of a folder in the personal drive. Root when folderPath is omitted. */
|
|
1608
|
+
listFolder(folderPath?: string): Promise<FolderEntry[]>;
|
|
1609
|
+
/** Ensure a folder path exists, creating intermediate folders as needed. Returns leaf folder ID. */
|
|
1610
|
+
ensureFolder(folderPath: string): Promise<string>;
|
|
1611
|
+
/** Find documents in the personal drive by document type. */
|
|
1612
|
+
findByType(documentType: string): Promise<FolderEntry[]>;
|
|
1613
|
+
}
|
|
1614
|
+
/**
|
|
1615
|
+
* Context for the Powerhouse reactor capability.
|
|
1616
|
+
* Returned by the reactor factory and accessible via `context.reactor()`.
|
|
1617
|
+
*/
|
|
1618
|
+
interface ReactorContext<R extends DocumentRegistry = AnyRegistry> {
|
|
1619
|
+
/** The Reactor client — typed CRUD + subscription API. */
|
|
1620
|
+
client: TypedReactorClient<R>;
|
|
1621
|
+
/** The default drive ID. Aliases personalDriveId when multi-drive is configured. */
|
|
1622
|
+
driveId: string;
|
|
1623
|
+
/** All managed drives, ordered as configured. */
|
|
1624
|
+
drives?: DriveEntry[];
|
|
1625
|
+
/** The personal drive ID (first drive with role 'personal'). */
|
|
1626
|
+
personalDriveId?: string;
|
|
1627
|
+
/** Phase 2: Switchboard GraphQL URL (e.g. http://localhost:4001/graphql). */
|
|
1628
|
+
switchboardUrl?: string;
|
|
1629
|
+
/** Phase 2: Switchboard drive URL (e.g. http://localhost:4001/d/{driveId}). */
|
|
1630
|
+
driveUrl?: string;
|
|
1631
|
+
/** Phase 2: Switchboard MCP URL (e.g. http://localhost:4001/mcp). */
|
|
1632
|
+
mcpUrl?: string;
|
|
1633
|
+
/** Phase 3: Connect web UI URL (e.g. http://localhost:3000). */
|
|
1634
|
+
connectUrl?: string;
|
|
1635
|
+
/**
|
|
1636
|
+
* Switchboard-provided attachment service. Constructed externally
|
|
1637
|
+
* (switchboard owns createRemoteAttachmentService) and passed in via
|
|
1638
|
+
* ReactorSetupContext.attachments. Upload and read sites reach it here.
|
|
1639
|
+
* Undefined when no attachment service is wired.
|
|
1640
|
+
*/
|
|
1641
|
+
attachments?: IAttachmentService;
|
|
1642
|
+
/** Internal: the ReactorClientModule, passed to startSwitchboard(). */
|
|
1643
|
+
_module?: ReactorClientModule;
|
|
1644
|
+
/** Teardown — called by the framework on CLI exit. */
|
|
1645
|
+
shutdown(): Promise<void>;
|
|
1646
|
+
}
|
|
1647
|
+
/**
|
|
1648
|
+
* Drive configuration for the Powerhouse integration.
|
|
1649
|
+
*/
|
|
1650
|
+
interface DriveConfig {
|
|
1651
|
+
/** Drive display name. */
|
|
1652
|
+
name: string;
|
|
1653
|
+
/** Optional icon URL for the drive. */
|
|
1654
|
+
icon?: string;
|
|
1655
|
+
/** Deterministic drive ID. When set, the drive is created with this ID
|
|
1656
|
+
* instead of a random UUID. Used for stable cross-session identity. */
|
|
1657
|
+
id?: string;
|
|
1658
|
+
/** Editor id (from a Connect-loaded package) that Connect should open this
|
|
1659
|
+
* drive in. Stored on `header.meta.preferredEditor` at creation time. Has
|
|
1660
|
+
* no effect on drives that already exist. */
|
|
1661
|
+
preferredEditor?: string;
|
|
1662
|
+
}
|
|
1663
|
+
/**
|
|
1664
|
+
* Subscription configuration — filters which document changes
|
|
1665
|
+
* are bridged to the event bus.
|
|
1666
|
+
*/
|
|
1667
|
+
interface SubscriptionConfig<R extends DocumentRegistry = AnyRegistry> {
|
|
1668
|
+
/** Filter by document type(s). */
|
|
1669
|
+
documentTypes?: Array<keyof R & string>;
|
|
1670
|
+
}
|
|
1671
|
+
/**
|
|
1672
|
+
* Switchboard (Phase 2) configuration.
|
|
1673
|
+
*/
|
|
1674
|
+
interface SwitchboardConfig {
|
|
1675
|
+
/** Enable Switchboard. Default: false. */
|
|
1676
|
+
enabled: boolean;
|
|
1677
|
+
/** Hostname/IP to bind to. Default: 'localhost'. */
|
|
1678
|
+
host?: string;
|
|
1679
|
+
/** HTTP port. Default: derived from CLI name via hash. */
|
|
1680
|
+
port?: number;
|
|
1681
|
+
/** Number of ports to scan starting from `port`. Default: 1. */
|
|
1682
|
+
portRange?: number;
|
|
1683
|
+
/** Service label for preflight messages. Default: '{cliName}-api'. */
|
|
1684
|
+
name?: string;
|
|
1685
|
+
/**
|
|
1686
|
+
* Registry URL forwarded to the switchboard's `HttpPackageLoader`. When
|
|
1687
|
+
* set, the `Packages` GraphQL subgraph is registered (install/uninstall
|
|
1688
|
+
* mutations) and dynamic package resolution is enabled.
|
|
1689
|
+
*/
|
|
1690
|
+
registryUrl?: string;
|
|
1691
|
+
}
|
|
1692
|
+
/**
|
|
1693
|
+
* Connect UI (Phase 3) configuration.
|
|
1694
|
+
*/
|
|
1695
|
+
interface ConnectConfig {
|
|
1696
|
+
/** Enable Connect. Default: false. */
|
|
1697
|
+
enabled: boolean;
|
|
1698
|
+
/** HTTP port. Default: derived from CLI name via hash. */
|
|
1699
|
+
port?: number;
|
|
1700
|
+
/** Number of ports to scan starting from `port`. Default: 1. */
|
|
1701
|
+
portRange?: number;
|
|
1702
|
+
/** Working directory for `ph connect` (must be a Reactor Package project). */
|
|
1703
|
+
workdir?: string;
|
|
1704
|
+
/** Service ID for ServiceManager. Default: '{cliName}-studio'. */
|
|
1705
|
+
name?: string;
|
|
1706
|
+
/** Path to pre-built Connect static assets. When set, serves via static file server instead of Vite dev server. */
|
|
1707
|
+
assetsDir?: string;
|
|
1708
|
+
precompress?: boolean;
|
|
1709
|
+
/**
|
|
1710
|
+
* Package registry URL forwarded to Connect via
|
|
1711
|
+
* `PH_CONNECT_PACKAGES_REGISTRY`. The vite config reads this to resolve
|
|
1712
|
+
* Powerhouse packages for in-browser dynamic imports.
|
|
1713
|
+
*/
|
|
1714
|
+
registryUrl?: string;
|
|
1715
|
+
}
|
|
1716
|
+
/**
|
|
1717
|
+
* Context passed to the reactor factory in configureReactor().
|
|
1718
|
+
* Provides core infrastructure the factory needs to build the reactor.
|
|
1719
|
+
*
|
|
1720
|
+
* **Important:** `workspace` must be rooted at `workdir`. In normal framework
|
|
1721
|
+
* usage the CLI assembles both from a single workdir value, so they always
|
|
1722
|
+
* agree. When constructing this context manually (e.g. in tests or custom
|
|
1723
|
+
* reactor factories), ensure `workspace` was created with the same directory
|
|
1724
|
+
* as `workdir` — otherwise storage paths (reactor database, config) will
|
|
1725
|
+
* land in unexpected locations.
|
|
1726
|
+
*/
|
|
1727
|
+
interface ReactorSetupContext<R extends DocumentRegistry = AnyRegistry> {
|
|
1728
|
+
workdir: string;
|
|
1729
|
+
config: Record<string, unknown>;
|
|
1730
|
+
workspace: WorkdirStore;
|
|
1731
|
+
emit?: EmitFn<R>;
|
|
1732
|
+
on?: OnFn<R>;
|
|
1733
|
+
/** Switchboard config — passed by the framework so create() can set enableSync. */
|
|
1734
|
+
switchboard?: SwitchboardConfig;
|
|
1735
|
+
/**
|
|
1736
|
+
* Switchboard-provided attachment service to thread through to ReactorContext.
|
|
1737
|
+
* The service is constructed externally (switchboard owns createRemoteAttachmentService)
|
|
1738
|
+
* and relayed here so the create() factory can place it on the returned context.
|
|
1739
|
+
*/
|
|
1740
|
+
attachments?: IAttachmentService;
|
|
1741
|
+
}
|
|
1742
|
+
/**
|
|
1743
|
+
* Configuration for configureReactor().
|
|
1744
|
+
* The `create` factory is called lazily on first reactor() access.
|
|
1745
|
+
*/
|
|
1746
|
+
interface ReactorConfiguration<R extends DocumentRegistry = AnyRegistry> {
|
|
1747
|
+
/** Factory that builds and returns a ReactorContext. */
|
|
1748
|
+
create: (ctx: ReactorSetupContext<R>) => Promise<ReactorContext<R>>;
|
|
1749
|
+
/** Connect web UI service configuration — commands injected immediately. */
|
|
1750
|
+
connect?: ConnectConfig;
|
|
1751
|
+
/** Switchboard service configuration. */
|
|
1752
|
+
switchboard?: SwitchboardConfig;
|
|
1753
|
+
}
|
|
1754
|
+
/**
|
|
1755
|
+
* Internal handle for the Switchboard instance.
|
|
1756
|
+
*/
|
|
1757
|
+
interface SwitchboardInstance {
|
|
1758
|
+
switchboardUrl: string;
|
|
1759
|
+
driveUrl: string;
|
|
1760
|
+
mcpUrl: string;
|
|
1761
|
+
shutdown(): Promise<void>;
|
|
1762
|
+
}
|
|
1763
|
+
//#endregion
|
|
1764
|
+
export { OnFn as $, AgentStreamOptions as A, ToolOutputChunk as At, ConfigEnvVar as B, PROJECT_INDICATORS as Bt, ReserveAttachmentOptions as C, ServiceProxyRouteSpec as Ct, AgentPromptInput as D, StreamChunk as Dt, AgentProfileConfig as E, SkillConfig as Et, Cli as F, WorkItem as Ft, EventBus as G, buildSwitchboardRoutes as Gt, EmitFn as H, ProxyRoute as Ht, CliMetadata as I, WorkdirStore as It, LifecycleHandle as J, InferConfig as K, captureRoutePrefix as Kt, CliOptions as L, WrapRegistry as Lt, BootstrapOptions as M, Trigger as Mt, BootstrapResult as N, TriggerContext as Nt, AgentProvider as O, TextDeltaChunk as Ot, CaptureDefinition as P, TriggerOptions as Pt, Logger as Q, Command as R, SkillInfo as Rt, IAttachmentService as S, ServiceManager as St, AgentLoader as T, ServiceStatus as Tt, EndpointType as U, buildServiceRoutes as Ut, CoreContext as V, scanProjects as Vt, ErrorChunk as W, buildSwitchboardRouteSpecs as Wt, LifecycleInitContext as X, LifecycleHook as Y, LogLevel as Z, TypedDocumentChangeEvent as _, RoutineStatus as _t, DriveConfig as a, ProcessManager as at, AttachmentResponse as b, ServiceDefinition as bt, FolderOperations as c, ProjectScanner as ct, ReactorContext as d, ReadinessConfig as dt, PhClintEvents as et, ReactorSetupContext as f, ReadinessPattern as ft, SwitchboardInstance as g, RoutineConfig as gt, SwitchboardConfig as h, Routine as ht, DocumentRegistry as i, ProcessHandle as it, BootTimings as j, ToolResultChunk as jt, AgentSetupContext as k, ToolCallChunk as kt, ReactorClientModule as l, PromptConfig as lt, SubscriptionConfig as m, ResolvedInteractiveConfig as mt, AttachmentRef$1 as n, PreflightContext as nt, DriveEntry as o, ProcessRunOptions as ot, RegistryEntry as p, Resolvable as pt, InteractiveConfig as q, isWsEndpointType as qt, ConnectConfig as r, PreflightResult as rt, FolderEntry as s, ProjectScanResult as st, AnyRegistry as t, PreflightCheck as tt, ReactorConfiguration as u, PromptsConfig as ut, TypedReactorClient as v, RunOptions as vt, AgentContentPart as w, ServiceStartOptions as wt, AttachmentUploadResult as x, ServiceInstanceStatus as xt, AttachmentHeader as y, ServiceBuildContext as yt, CommandContext as z, readSkills as zt };
|
|
1765
|
+
export {};
|
|
1766
|
+
//# sourceMappingURL=types-DrLfp2dR.d.mts.map
|