@powerhousedao/clint 6.2.3-dev.70 → 6.2.3-dev.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/runners/clint-runner.d.mts +362 -119
- package/dist/runners/clint-runner.d.mts.map +1 -1
- package/dist/runners/clint-runner.mjs +328 -86
- package/dist/runners/clint-runner.mjs.map +1 -1
- package/dist/runners/mastra-runner.d.mts +261 -109
- package/dist/runners/mastra-runner.d.mts.map +1 -1
- package/dist/runners/mastra-runner.mjs +110 -50
- package/dist/runners/mastra-runner.mjs.map +1 -1
- package/package.json +16 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clint-runner.mjs","names":[],"sources":["../../src/runners/proxy-plugin.ts","../../src/runners/clint-runner.ts"],"sourcesContent":["import type { HostPlugin } from \"@powerhousedao/host-core\";\n\n/**\n * R5 — the clint proxy as a COMPOUND plugin (rewire plan: appliesTo\n * \"compound\", the member-set branch of the hierarchy). One front port routes\n * to the scheduled members, WebSocket-aware; member references resolve\n * through each child's runner.{host,port} (the agents-manager convention).\n * Declarative veneer over the clint package's createProxyServer; the route\n * table assembly is pure (buildProxyRouteTable) and unit-tested without\n * sockets.\n */\n\nexport interface ProxyPluginConfig {\n port: number;\n host?: string;\n publicUrl?: string;\n /** Route prefix -> target: a member reference (resolved to the child's\n * host:port) or an explicit upstream URL; optional path + ws. */\n routes: Record<\n string,\n {\n member?: string;\n upstream?: string;\n path?: string;\n ws?: boolean;\n }\n >;\n}\n\nexport interface ResolvedProxyRoute {\n prefix: string;\n upstream: string;\n ws: boolean;\n source: string;\n}\n\n/** Member endpoints the compound runner knows at onMemberReady: name ->\n * { host, port }. */\nexport type MemberEndpoints = Record<string, { host: string; port: number }>;\n\n/**\n * Pure route-table assembly: member refs become loopback upstreams via the\n * member's host:port (+ optional path); explicit upstreams pass through.\n * A member ref with no known endpoint throws naming the member — a routing\n * declaration that cannot resolve must fail loudly, not silently drop.\n */\nexport function buildProxyRouteTable(\n config: ProxyPluginConfig,\n members: MemberEndpoints,\n): ResolvedProxyRoute[] {\n const table: ResolvedProxyRoute[] = [];\n for (const [prefix, route] of Object.entries(config.routes)) {\n if (route.upstream) {\n table.push({\n prefix,\n upstream: `${route.upstream.replace(/\\/+$/, \"\")}${route.path ?? \"\"}`,\n ws: route.ws ?? false,\n source: `upstream:${route.upstream}`,\n });\n continue;\n }\n if (!route.member) {\n throw new Error(\n `proxy route \"${prefix}\" names neither a member nor an upstream.`,\n );\n }\n const endpoint = members[route.member];\n if (!endpoint) {\n throw new Error(\n `proxy route \"${prefix}\" references member \"${route.member}\", which has no resolved endpoint (known: ${Object.keys(members).join(\", \") || \"none\"}).`,\n );\n }\n const host = endpoint.host === \"0.0.0.0\" ? \"127.0.0.1\" : endpoint.host;\n table.push({\n prefix,\n upstream: `http://${host}:${endpoint.port}${route.path ?? \"\"}`,\n ws: route.ws ?? false,\n source: `member:${route.member}`,\n });\n }\n return table;\n}\n\nexport interface ClintCompoundContext {\n memberEndpoints: MemberEndpoints;\n proxyRoutes?: ResolvedProxyRoute[];\n proxyStop?: () => Promise<void>;\n logger?: { info: (m: string) => void };\n}\n\nexport function createProxyPlugin(config: ProxyPluginConfig): HostPlugin<{\n onMembersReady: (ctx: ClintCompoundContext) => Promise<void>;\n onShutdown: (ctx: ClintCompoundContext) => Promise<void>;\n}> {\n return {\n name: \"clint-proxy\",\n appliesTo: \"compound\",\n hooks: {\n onMembersReady: async (ctx) => {\n const table = buildProxyRouteTable(config, ctx.memberEndpoints);\n ctx.proxyRoutes = table;\n const { createProxyServer } = await import(\"../core/proxy.js\");\n const instance = await createProxyServer({\n port: config.port,\n host: config.host ?? \"0.0.0.0\",\n publicUrl: config.publicUrl,\n logger: (ctx.logger ?? console) as never,\n });\n for (const route of table) {\n instance.addRoute({\n prefix: route.prefix,\n upstream: new URL(route.upstream),\n ws: route.ws,\n source: route.source,\n } as never);\n }\n ctx.proxyStop = () => instance.stop();\n ctx.logger?.info(\n `[clint-proxy] listening on ${instance.url} — ${table.length} route(s)`,\n );\n },\n onShutdown: async (ctx) => {\n await ctx.proxyStop?.();\n },\n },\n };\n}\n\nexport default createProxyPlugin;\n","import { createInterface } from \"node:readline\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport {\n compoundHostSchema,\n defaultUserDataDir,\n loadHost,\n probeRun,\n resolveUserDataPlaceholders,\n runObserveHook,\n runObserveHookSequential,\n resolveHostPlugins,\n type HostDefinition,\n type RunnerContext,\n} from \"@powerhousedao/host-core\";\nimport {\n createProxyPlugin,\n type ClintCompoundContext,\n type MemberEndpoints,\n} from \"./proxy-plugin.js\";\nimport fs from \"node:fs\";\nimport { createEventBus } from \"../core/events.js\";\nimport { isPortFree } from \"../core/preflight.js\";\nimport {\n createServiceManager,\n defineService,\n resolveServiceName,\n} from \"../core/services.js\";\nimport { formatStatus } from \"../core/service-command.js\";\nimport type { ServiceDefinition, ServiceManager } from \"../core/types.js\";\n\n/**\n * clint-runner (P5.4): the clint framework shell as a compound-kind runner.\n * Children declared in hosts/cli/host.js are SCHEDULED as clint services —\n * each member runs as `ph-cli run <member>` in its own (hidden) process with\n * state files, logs, readiness patterns and restart policies from the ported\n * services manager; `lifecycle: \"detached\"` (the default, clint's own\n * posture) leaves children running when the shell exits and re-attaches on\n * the next run, `\"attached\"` tears them down vetra-style.\n *\n * The agents manager (config.agents) maps names to OpenAI-compatible\n * endpoints — a sibling host reference resolves through that host's\n * runner.port (the mastra-runner serves /v1 there). `dev` adds a line chat\n * loop against the first agent; the full ink REPL remains the library path\n * (defineCli) for implementation projects, as scaffolded clint CLIs use it\n * natively — noted in the phase-5 WBS.\n */\n\nexport const kind = \"compound\";\n\nexport const hostSchema = compoundHostSchema;\n\ninterface ChildWrapper {\n host: string;\n runner?: { port?: number } & Record<string, unknown>;\n config?: { readiness?: { pattern?: string; timeout?: number } } & Record<\n string,\n unknown\n >;\n}\n\ninterface AgentRef {\n host?: string;\n url?: string;\n}\n\ninterface CliHostConfig {\n agents?: Record<string, AgentRef>;\n startOrder?: string[];\n}\n\n// A URL in stdout is the universal \"I am serving\" signal across member kinds\n// (switchboard prints \"MCP server available at http://…\", preview \"Local:\",\n// the agent \"agent API … http://…\").\nconst DEFAULT_READINESS = \"https?://|listening|ready\";\n\n/** Resolve the project's ph-cli entry the same way host-core resolves runner\n * modules: from the PROJECT's dependency tree. */\nfunction resolvePhCliEntry(projectRoot: string): string {\n const require_ = createRequire(\n pathToFileURL(path.join(projectRoot, \"package.json\")).href,\n );\n const pkgPath = require_.resolve(\"@powerhousedao/ph-cli/package.json\");\n return path.join(path.dirname(pkgPath), \"dist\", \"cli.mjs\");\n}\n\nfunction childServices(\n host: HostDefinition,\n ctx: RunnerContext,\n phCliEntry: string,\n): ServiceDefinition<Record<string, unknown>>[] {\n const children = (host.children ?? {}) as Record<string, ChildWrapper>;\n return Object.entries(children).map(([name, wrapper]) =>\n defineService({\n id: name,\n name,\n command: () => `node \"${phCliEntry}\" run ${wrapper.host}`,\n env: () => ({\n FEATURE_UNIFORM_RUNNERS_ENABLED: \"1\",\n PH_USER_DATA_DIR: defaultUserDataDir(ctx.projectRoot, ctx.env),\n }),\n readiness: {\n patterns: [\n {\n name: \"up\",\n pattern: new RegExp(\n wrapper.config?.readiness?.pattern ?? DEFAULT_READINESS,\n \"i\",\n ),\n },\n ],\n timeout: wrapper.config?.readiness?.timeout ?? 180_000,\n },\n }),\n );\n}\n\nasync function resolveAgentEndpoint(\n ref: AgentRef,\n ctx: RunnerContext,\n): Promise<string> {\n if (ref.url) return ref.url.replace(/\\/$/, \"\");\n if (ref.host) {\n const sibling = await loadHost(ctx.projectRoot, ref.host);\n const port = sibling.host.runner.port ?? 4910;\n return `http://127.0.0.1:${String(port)}/v1`;\n }\n throw new Error(\"agents entries need { host } or { url }\");\n}\n\nfunction readProjectName(projectRoot: string, fallback: string): string {\n try {\n return (\n (\n JSON.parse(\n fs.readFileSync(path.join(projectRoot, \"package.json\"), \"utf8\"),\n ) as { name?: string }\n ).name ?? fallback\n );\n } catch {\n return fallback;\n }\n}\n\nexport interface CliRunHandle {\n services: ServiceManager;\n agents: Record<string, string>;\n shutdown: () => Promise<void>;\n}\n\nasync function startShell(\n host: HostDefinition,\n ctx: RunnerContext,\n): Promise<CliRunHandle> {\n const userData = defaultUserDataDir(ctx.projectRoot, ctx.env);\n const resolved = resolveUserDataPlaceholders(host, userData);\n const config = (resolved.config ?? {}) as CliHostConfig;\n const lifecycle =\n (resolved.runner.lifecycle as string | undefined) ?? \"detached\";\n\n const phCliEntry = resolvePhCliEntry(ctx.projectRoot);\n const children = (resolved.children ?? {}) as Record<string, ChildWrapper>;\n const projectName = readProjectName(ctx.projectRoot, resolved.name);\n const definitions = childServices(resolved, ctx, phCliEntry);\n const eventBus = createEventBus();\n // R5: compound plugins (appliesTo \"compound\" — e.g. the proxy) run over the\n // member set. Built-ins resolve from a declared `runner.plugins`; the proxy\n // is registered when a `runner.proxy` block is present (ergonomic alias).\n const memberEndpoints: MemberEndpoints = {};\n const servicesDir = path.join(ctx.projectRoot, \".ph\", \"services\");\n const services = createServiceManager(definitions, {\n config: {},\n servicesDir,\n eventBus,\n });\n\n // Start order: config.startOrder first, then declaration order.\n const names = definitions.map((d) => d.id);\n const ordered = [\n ...(config.startOrder ?? []).filter((n) => names.includes(n)),\n ...names.filter((n) => !(config.startOrder ?? []).includes(n)),\n ];\n for (const id of ordered) {\n // Re-attach checks, strongest first. (1) The member's OWN run record —\n // written with the member process's real pid (mastra-runner, the generic\n // compound). (2) Port occupancy for record-less bridge members. (3) The\n // service state file — weakest on Windows, where it records the cmd shim\n // pid, which dies on console teardown while the node grandchild survives.\n const wrapper = children[id];\n const member = await loadHost(ctx.projectRoot, wrapper.host);\n const record = probeRun(ctx.projectRoot, member.host.name, projectName);\n if (record.status === \"live\") {\n console.log(\n `[${resolved.name}] ${id}: already running (pid ${record.record.pid}) — re-attached`,\n );\n continue;\n }\n const memberPort =\n typeof wrapper.runner?.port === \"number\"\n ? wrapper.runner.port\n : typeof member.host.runner.port === \"number\"\n ? member.host.runner.port\n : undefined;\n if (memberPort !== undefined) {\n const memberHost =\n (typeof wrapper.runner?.host === \"string\" && wrapper.runner.host) ||\n (typeof member.host.runner.host === \"string\" &&\n member.host.runner.host) ||\n \"127.0.0.1\";\n memberEndpoints[id] = { host: memberHost, port: memberPort };\n }\n if (memberPort !== undefined && !(await isPortFree(memberPort))) {\n console.log(\n `[${resolved.name}] ${id}: port ${memberPort} already serving — re-attached`,\n );\n continue;\n }\n const already = services\n .list(id)\n .some((s) => s.status === \"ready\" || s.status === \"starting\");\n if (already) {\n console.log(`[${resolved.name}] ${id}: already running — re-attached`);\n continue;\n }\n console.log(`[${resolved.name}] starting ${id}…`);\n await services.start(id, {\n workdir: ctx.projectRoot,\n cwd: ctx.projectRoot,\n });\n const status = services.list(id).find((s) => s.serviceId === id);\n if (status) console.log(` ${formatStatus(status)}`);\n }\n\n // Compound-plugin pipeline (CompoundCore): resolve entries + the proxy\n // ergonomic alias, then fire onMembersReady now that endpoints are known.\n const pluginEntries = (resolved.runner as { plugins?: unknown }).plugins as\n | Parameters<typeof resolveHostPlugins>[3]\n | undefined;\n const resolvedPlugins = pluginEntries\n ? (\n await resolveHostPlugins(\n ctx.projectRoot,\n \"compound\",\n ctx.verb ?? \"run\",\n pluginEntries,\n `hosts/${host.name}/host.js`,\n )\n ).map((r) => r.plugin)\n : [];\n const proxyBlock = (resolved.runner as { proxy?: unknown }).proxy;\n if (proxyBlock && typeof proxyBlock === \"object\") {\n resolvedPlugins.push(createProxyPlugin(proxyBlock as never) as never);\n }\n const compoundCtx: ClintCompoundContext = {\n memberEndpoints,\n logger: { info: (m: string) => console.log(m) },\n };\n if (resolvedPlugins.length > 0) {\n await runObserveHook(\"onMembersReady\", resolvedPlugins, compoundCtx);\n }\n\n const agents: Record<string, string> = {};\n for (const [name, ref] of Object.entries(config.agents ?? {})) {\n agents[name] = await resolveAgentEndpoint(ref, ctx);\n }\n if (Object.keys(agents).length > 0) {\n console.log(\n `[${resolved.name}] agents: ${Object.entries(agents)\n .map(([n, u]) => `${n} → ${u}`)\n .join(\", \")}`,\n );\n }\n\n const shutdown = async () => {\n if (resolvedPlugins.length > 0) {\n await runObserveHookSequential(\n \"onShutdown\",\n resolvedPlugins,\n compoundCtx,\n );\n }\n if (lifecycle === \"attached\") {\n for (const id of names) {\n try {\n await services.stop(id);\n } catch {\n // already stopped\n }\n }\n } else {\n console.log(\n `[${resolved.name}] detached lifecycle: children keep running ` +\n `(stop them with the ${resolved.name} service commands or taskkill).`,\n );\n }\n };\n\n if (lifecycle === \"attached\") {\n const onSignal = () => {\n void shutdown().finally(() => process.exit(130));\n };\n process.once(\"SIGINT\", onSignal);\n process.once(\"SIGTERM\", onSignal);\n }\n\n return { services, agents, shutdown };\n}\n\n/** Minimal line chat against an agent's OpenAI-compatible endpoint. */\nasync function chatLoop(agents: Record<string, string>): Promise<void> {\n const [agentName, endpoint] = Object.entries(agents)[0] ?? [];\n if (!agentName || !endpoint) {\n console.log(\"No agents configured (config.agents) — chat unavailable.\");\n return;\n }\n console.log(`Chatting with ${agentName} (${endpoint}). /exit to quit.`);\n const rl = createInterface({ input: process.stdin, output: process.stdout });\n const ask = (q: string) =>\n new Promise<string>((resolve) => rl.question(q, resolve));\n for (;;) {\n const line = (await ask(\"> \")).trim();\n if (line === \"/exit\" || line === \"exit\") break;\n if (!line) continue;\n try {\n const res = await fetch(`${endpoint}/chat/completions`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n messages: [{ role: \"user\", content: line }],\n }),\n });\n const body = (await res.json()) as {\n choices?: { message?: { content?: string } }[];\n error?: { message?: string };\n };\n console.log(\n body.choices?.[0]?.message?.content ??\n `[error] ${body.error?.message ?? res.status}`,\n );\n } catch (error) {\n console.log(`[transport error] ${String(error)}`);\n }\n }\n rl.close();\n}\n\nexport async function run(\n host: HostDefinition,\n ctx: RunnerContext,\n): Promise<CliRunHandle> {\n const handle = await startShell(host, ctx);\n console.log(\n `[${host.name}] services up. ` +\n `(ph run ${host.name} dev for the chat shell; Ctrl+C ${\n (host.runner.lifecycle as string | undefined) === \"attached\"\n ? \"stops the children\"\n : \"leaves children running\"\n }.)`,\n );\n return handle;\n}\n\nexport const serve = run;\n\n/** dev = services up + the line chat shell (blocks until /exit). */\nexport async function dev(\n host: HostDefinition,\n ctx: RunnerContext,\n): Promise<void> {\n const handle = await startShell(host, ctx);\n await chatLoop(handle.agents);\n await handle.shutdown();\n}\n\n/** build = forward build to each member host that exports it (fail loud on\n * members that do not — a silent skip would report success on an unbuilt\n * set), same posture as the generic compound. */\nexport async function build(\n host: HostDefinition,\n ctx: RunnerContext,\n): Promise<void> {\n const { getVerb, resolveRunnerModule, validateHost } =\n await import(\"@powerhousedao/host-core\");\n const children = (host.children ?? {}) as Record<string, ChildWrapper>;\n for (const [name, wrapper] of Object.entries(children)) {\n const member = await loadHost(ctx.projectRoot, wrapper.host);\n const specifier = member.host.runner.module;\n const runner = await resolveRunnerModule(ctx.projectRoot, specifier);\n validateHost(\n runner,\n specifier,\n member.host,\n `hosts/${wrapper.host}/host.js`,\n );\n const fn = getVerb(runner, specifier, \"build\");\n console.log(`[${host.name}] build → ${name} (${wrapper.host})`);\n await fn(member.host, { ...ctx, verb: \"build\" });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA8CA,SAAgB,qBACd,QACA,SACsB;CACtB,MAAM,QAA8B,CAAC;CACrC,KAAK,MAAM,CAAC,QAAQ,UAAU,OAAO,QAAQ,OAAO,MAAM,GAAG;EAC3D,IAAI,MAAM,UAAU;GAClB,MAAM,KAAK;IACT;IACA,UAAU,GAAG,MAAM,SAAS,QAAQ,QAAQ,EAAE,IAAI,MAAM,QAAQ;IAChE,IAAI,MAAM,MAAM;IAChB,QAAQ,YAAY,MAAM;GAC5B,CAAC;GACD;EACF;EACA,IAAI,CAAC,MAAM,QACT,MAAM,IAAI,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AK,MAAM;EAAQ,CAAC;CACjD;AACF"}
|
|
1
|
+
{"version":3,"file":"clint-runner.mjs","names":[],"sources":["../../src/runners/removed-forms.ts","../../src/runners/proxy-plugin.ts","../../src/runners/member-records.ts","../../src/runners/clint-runner.ts"],"sourcesContent":["import type { z } from \"zod\";\n\n/**\n * Output tokens (typed-host-configs T3) replaced the sibling-host reference\n * forms the clint runners used to resolve themselves. A removed key is not\n * just \"unrecognized\": its error names the token form that replaces it.\n * Pass the result as a strict object's `error` option.\n */\nexport function removedKeyError(\n key: string,\n hint: (input: Record<string, unknown>) => string,\n): z.core.$ZodErrorMap {\n return (issue) => {\n if (issue.code !== \"unrecognized_keys\" || !issue.keys.includes(key)) {\n return undefined;\n }\n const input =\n typeof issue.input === \"object\" && issue.input !== null\n ? (issue.input as Record<string, unknown>)\n : {};\n return `\\`${key}\\` was removed; ${hint(input)}`;\n };\n}\n\n/** A quoted host name from a removed reference, or a placeholder. */\nexport function quotedHost(value: unknown, placeholder: string): string {\n return typeof value === \"string\" && value.length > 0\n ? JSON.stringify(value)\n : placeholder;\n}\n","import type { HostPlugin } from \"@powerhousedao/host-core\";\nimport { ref } from \"@powerhousedao/host-core/schema\";\nimport { z } from \"zod\";\nimport { removedKeyError } from \"./removed-forms.js\";\n\n/**\n * R5 — the clint proxy as a COMPOUND plugin (rewire plan: appliesTo\n * \"compound\", the member-set branch of the hierarchy). One front port routes\n * to upstream URLs, WebSocket-aware. A route to a member names that member\n * host's own output (e.g. `{ $output: { host: \"assistant\", path: [\"origin\"] } }`),\n * resolved before the runner sees the config — the proxy never derives an\n * address from a declared port. Declarative veneer over the clint package's\n * createProxyServer; the route table assembly is pure\n * (buildProxyRouteTable) and unit-tested without sockets.\n */\n\n/** The token form that replaced a route's `member` reference. */\nfunction memberHint(input: Record<string, unknown>): string {\n const member =\n typeof input.member === \"string\" && input.member.length > 0\n ? `, member: ${JSON.stringify(input.member)}`\n : \"\";\n return `point \\`upstream\\` at the member host's output: upstream: <host>.origin from ../<host>/outputs.js, or { $output: { host: \"<member's host>\"${member}, path: [\"origin\"] } }.`;\n}\n\n/** The proxy config, built once per form: `url` is the upstream field —\n * `ref(z.url())` when declared, `z.url()` when resolved. */\nfunction buildProxyPluginConfigSchema<U extends z.ZodType>(url: U) {\n /** One route: an upstream URL (literal or output token) plus optional\n * path + ws. */\n const proxyRouteSchema = z.strictObject(\n {\n upstream: url,\n path: z.string().optional(),\n ws: z.boolean().optional(),\n },\n { error: removedKeyError(\"member\", memberHint) },\n );\n return z.strictObject({\n /** Front port (0 = any free port). */\n port: z.number().int().min(0),\n /** Bind address (default \"0.0.0.0\"). */\n host: z.string().min(1).optional(),\n publicUrl: z.url().optional(),\n /** Route prefix -> target. */\n routes: z.record(z.string(), proxyRouteSchema),\n });\n}\n\n/** `runner.proxy` on a clint-runner host, resolved (what the runner reads). */\nexport const proxyPluginConfigSchema = buildProxyPluginConfigSchema(z.url());\n\n/** `runner.proxy` as declared: upstreams may be output tokens. */\nexport const declaredProxyPluginConfigSchema = buildProxyPluginConfigSchema(\n ref(z.url()),\n);\n\nexport type ProxyPluginConfig = z.output<typeof proxyPluginConfigSchema>;\nexport type ProxyPluginConfigInput = z.input<\n typeof declaredProxyPluginConfigSchema\n>;\n\nexport interface ResolvedProxyRoute {\n prefix: string;\n upstream: string;\n ws: boolean;\n source: string;\n}\n\n/** Pure route-table assembly: each upstream (+ optional path). */\nexport function buildProxyRouteTable(\n config: ProxyPluginConfig,\n): ResolvedProxyRoute[] {\n return Object.entries(config.routes).map(([prefix, route]) => ({\n prefix,\n upstream: `${route.upstream.replace(/\\/+$/, \"\")}${route.path ?? \"\"}`,\n ws: route.ws ?? false,\n source: `upstream:${route.upstream}`,\n }));\n}\n\nexport interface ClintCompoundContext {\n proxyRoutes?: ResolvedProxyRoute[];\n /** The proxy's listening URL, set at onMembersReady. */\n proxyUrl?: string;\n proxyStop?: () => Promise<void>;\n logger?: { info: (m: string) => void };\n}\n\nexport function createProxyPlugin(config: ProxyPluginConfig): HostPlugin<{\n onMembersReady: (ctx: ClintCompoundContext) => Promise<void>;\n onShutdown: (ctx: ClintCompoundContext) => Promise<void>;\n}> {\n return {\n name: \"clint-proxy\",\n appliesTo: \"compound\",\n hooks: {\n onMembersReady: async (ctx) => {\n const table = buildProxyRouteTable(config);\n ctx.proxyRoutes = table;\n const { createProxyServer } = await import(\"../core/proxy.js\");\n const instance = await createProxyServer({\n port: config.port,\n host: config.host ?? \"0.0.0.0\",\n publicUrl: config.publicUrl,\n logger: (ctx.logger ?? console) as never,\n });\n for (const route of table) {\n instance.addRoute({\n prefix: route.prefix,\n upstream: new URL(route.upstream),\n ws: route.ws,\n source: route.source,\n });\n }\n ctx.proxyUrl = instance.url;\n ctx.proxyStop = () => instance.stop();\n ctx.logger?.info(\n `[clint-proxy] listening on ${instance.url} — ${table.length} route(s)`,\n );\n },\n onShutdown: async (ctx) => {\n await ctx.proxyStop?.();\n },\n },\n };\n}\n\nexport default createProxyPlugin;\n","import { probeRun } from \"@powerhousedao/host-core\";\n\n/* Kept out of clint-runner.ts: a runner module exports only its verb\n * functions (plus schemas and constants). */\n\n/** How often {@link awaitRunRecord} re-reads a member's run record. */\nconst RECORD_POLL_MS = 100;\n\n/** A member whose outputs something reads, and what it waits for. */\nexport interface RecordWait {\n /** The child key (`children.<id>`). */\n id: string;\n /** The member host's `name` (its record is `.ph/run/<host>.json`). */\n host: string;\n /** How long to wait, in ms (the member's readiness timeout). */\n timeout: number;\n /** Who reads the member's outputs, for the error. */\n readers: string[];\n /** The member's service state, when clint started it: a `failed` or\n * `stopped` member will never publish, so the wait ends early. */\n status?: () => string | undefined;\n}\n\n/**\n * Waits for a started member's LIVE run record. A member counts as up when\n * its stdout matches the readiness pattern, but `ph run` writes the member's\n * run record only after the runner's `ready` resolves, so a reader that\n * looks right after the readiness line can find none. Polls until the\n * record is live, the member's service fails or stops, or `timeout` passes;\n * then throws naming the member, its record, the timeout and its readers.\n * An earlier run's stale record does not count: it is waited past.\n */\nexport async function awaitRunRecord(\n projectRoot: string,\n projectName: string,\n consumer: string,\n wait: RecordWait,\n pollMs = RECORD_POLL_MS,\n): Promise<void> {\n const deadline = Date.now() + wait.timeout;\n for (;;) {\n if (probeRun(projectRoot, wait.host, projectName).status === \"live\") {\n return;\n }\n const status = wait.status?.();\n const gone = status === \"failed\" || status === \"stopped\";\n if (gone || Date.now() >= deadline) {\n const why = gone\n ? `${status} before publishing its live run record`\n : `published no live run record within ${wait.timeout} ms (children.${wait.id}.config.readiness.timeout)`;\n throw new Error(\n `hosts/${consumer}/host.js: member \"${wait.id}\" is up (its readiness line matched) but ${why} (.ph/run/${wait.host}.json); ${wait.readers.join(\", \")} read its outputs.`,\n );\n }\n await new Promise((resolve) =>\n setTimeout(resolve, Math.min(pollMs, Math.max(0, deadline - Date.now()))),\n );\n }\n}\n","import { createInterface } from \"node:readline\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport {\n compoundOutputSource,\n defaultUserDataDir,\n loadHost,\n loadProducers,\n outputRefsOf,\n outputSitesOf,\n planCompound,\n probeRun,\n processResolveEnv,\n refineStartOrder,\n resolveHostOutputs,\n runObserveHook,\n runObserveHookSequential,\n resolveHostPlugins,\n runRecordOutputSource,\n type DeferredResolution,\n type LoadedHost,\n type RunnerContext,\n type RunnerHandle,\n} from \"@powerhousedao/host-core\";\nimport { defineHostSchemas, ref } from \"@powerhousedao/host-core/schema\";\nimport { z } from \"zod\";\nimport {\n createProxyPlugin,\n declaredProxyPluginConfigSchema,\n proxyPluginConfigSchema,\n type ClintCompoundContext,\n} from \"./proxy-plugin.js\";\nimport { awaitRunRecord } from \"./member-records.js\";\nimport { quotedHost, removedKeyError } from \"./removed-forms.js\";\nimport fs from \"node:fs\";\nimport { createEventBus } from \"../core/events.js\";\nimport { isPortFree } from \"../core/preflight.js\";\nimport { createServiceManager, defineService } from \"../core/services.js\";\nimport { formatStatus } from \"../core/service-command.js\";\nimport type { ServiceDefinition, ServiceManager } from \"../core/types.js\";\n\n/**\n * clint-runner (P5.4): the clint shell as a compound runner. Each member\n * runs as `ph-cli run <member>` in its own process, scheduled by the ported\n * services manager; `lifecycle: \"detached\"` (default) leaves members running\n * and re-attaches next run, `\"attached\"` tears them down. `config.agents`\n * maps names to OpenAI-compatible endpoints (a literal, or a member's\n * `endpoints.openai` token resolved once it is up). `dev` adds a line chat\n * loop against the first agent; the ink REPL stays the library path.\n */\n\nexport const kind = \"compound\";\n\n/** The token form that replaced an agent's sibling `host` reference. */\nfunction agentHostHint(input: Record<string, unknown>): string {\n const host = quotedHost(input.host, '\"<agent host>\"');\n return `use url: <host>.endpoints.openai from ../<host>/outputs.js, or { url: { $output: { host: ${host}, path: [\"endpoints\", \"openai\"] } } }.`;\n}\n\n/** An agent the shell can chat with: the OpenAI-compatible base URL of an\n * agent API (an agent host's `endpoints.openai` output, or external). */\nfunction agentRefSchema<U extends z.ZodType>(url: U) {\n return z.strictObject(\n { url },\n { error: removedKeyError(\"host\", agentHostHint) },\n );\n}\n\n/**\n * The clint compound host, from one definition in two forms: DECLARED (what\n * host.js authors write) and RESOLVED (what `validateHost` checks).\n *\n * `config.agents.*.url` and `runner.proxy.routes.*.upstream` are DEFERRED\n * self fields: they typically name outputs of this compound's own members,\n * which exist only once clint has started them inside the verb. They take\n * tokens in BOTH forms (`ref`, not `s.tokenable`), and the runner resolves\n * them after its members are up, then parses them with `ownFieldsSchema`.\n */\nconst schemas = defineHostSchemas((base) => {\n /** clint-runner's own `runner` options, on top of the common base. */\n const clintRunnerOptionsSchema = base.runnerBaseSchema\n .extend({\n /** \"detached\" (default): children outlive the shell and are\n * re-attached on the next run. \"attached\": the shell tears them down\n * on exit. */\n lifecycle: z.enum([\"attached\", \"detached\"]).optional(),\n /** One front port routing to upstreams (the clint proxy plugin). */\n proxy: declaredProxyPluginConfigSchema.optional(),\n })\n .strict();\n\n /** A member's scheduling knobs. Members run as their own `ph-cli run\n * <host>` process, so the wrapper's `config` is read by clint (not passed\n * to the member) and holds only these. */\n const clintMemberConfigSchema = z.strictObject({\n /** When the member counts as up: a stdout pattern (regex source, case\n * insensitive) and a timeout in ms. */\n readiness: z\n .strictObject({\n pattern: z.string().min(1).optional(),\n timeout: z.number().int().positive().optional(),\n })\n .optional(),\n });\n\n const cliHostConfigSchema = z.strictObject({\n agents: z.record(z.string(), agentRefSchema(ref(z.url()))).optional(),\n /** Member start order; must name declared children. Unnamed members\n * start after the named ones, in declaration order. */\n startOrder: z.array(z.string().min(1)).optional(),\n });\n\n // Extend the unrefined base, refine last (zod refuses to extend a refined\n // object).\n return base.compoundHostSchema\n .extend({\n runner: clintRunnerOptionsSchema,\n children: z.record(\n z.string(),\n base.childWrapperSchema.extend({\n config: clintMemberConfigSchema.optional(),\n }),\n ),\n config: cliHostConfigSchema.optional(),\n })\n .superRefine(refineStartOrder);\n});\n\n/** Declared form: what a host file may contain before resolution. */\nexport const declaredHostSchema = schemas.declaredHostSchema;\n/** Resolved form: what `validateHost` checks and the verbs receive (the\n * deferred self fields may still carry tokens; see above). */\nexport const hostSchema = schemas.hostSchema;\n\n/** The deferred self fields once resolved (after member start). */\nconst ownFieldsSchema = z.strictObject({\n agents: z.record(z.string(), agentRefSchema(z.url())).optional(),\n proxy: proxyPluginConfigSchema.optional(),\n});\n\n/** What a clint host.js author writes. */\nexport type ClintHostInput = z.input<typeof declaredHostSchema>;\n/** What the verbs receive. */\nexport type ClintHost = z.output<typeof hostSchema>;\ntype OwnFields = z.output<typeof ownFieldsSchema>;\n\n/** The verbs this runner exports (the rest of its exports are not verbs). */\nexport const verbs = [\"run\", \"serve\", \"dev\", \"build\"] as const;\n\n/** Live outputs of the compound's members, keyed by child name\n * (`outputs` undefined when the member published no live run record). */\nexport type LiveMemberOutputs = Record<\n string,\n { host: string; outputs: unknown }\n>;\n\n/**\n * Resolve the shell's own tokens before any member starts: `$env`, the\n * built-ins and other hosts' outputs now (an unset variable or a producer\n * that is not running fails with nothing started); tokens naming its own\n * members' outputs are deferred until those members are up (`finish`).\n * `children` stay as declared: each member resolves its own.\n */\nasync function resolveOwnTokens(\n host: ClintHost,\n ctx: RunnerContext,\n projectName: string,\n): Promise<DeferredResolution<ClintHost>> {\n const members = Object.entries(host.children).map(([key, wrapper]) => ({\n key,\n host: wrapper.host,\n }));\n const foreign = outputRefsOf({ ...host, children: {} }).filter(\n (ref) => !members.some((member) => member.host === ref.host),\n );\n return resolveHostOutputs(\n host,\n {\n outputs: runRecordOutputSource(ctx.projectRoot, {\n consumer: host.name,\n producers: await loadProducers(ctx.projectRoot, foreign),\n projectName,\n }),\n ...processResolveEnv(ctx.projectRoot, ctx.env),\n where: `hosts/${host.name}/host.js`,\n },\n { deferSelf: { members } },\n );\n}\n\n/** Finish the deferred self tokens from the members' live run records. */\nfunction finishOwnTokens(\n pending: DeferredResolution<ClintHost>,\n live: LiveMemberOutputs,\n name: string,\n): ClintHost {\n const started = new Map<string, unknown>();\n for (const [key, member] of Object.entries(live)) {\n if (member.outputs !== undefined) started.set(key, member.outputs);\n }\n const silent = pending.needs.filter((key) => !started.has(key));\n if (silent.length > 0) {\n const paths = pending.deferred\n .filter((d) => d.members.some((key) => silent.includes(key)))\n .map((d) => d.path);\n throw new Error(\n `hosts/${name}/host.js: ${paths.join(\", \")} read the outputs of member ${silent.map((key) => `\"${key}\"`).join(\", \")}, which is up but published no live run record (.ph/run/<host>.json) to read them from.`,\n );\n }\n const members = Object.entries(pending.host.children).map(\n ([key, wrapper]) => ({ key, host: wrapper.host }),\n );\n return pending.finish(compoundOutputSource(members, started, name));\n}\n\n/** Started members' outputs, read from their own run records (members run\n * as separate `ph-cli run` processes, which publish their outputs there). */\nfunction liveMemberOutputs(\n projectRoot: string,\n projectName: string,\n memberHosts: Record<string, string>,\n): LiveMemberOutputs {\n const members: LiveMemberOutputs = {};\n for (const [id, hostName] of Object.entries(memberHosts)) {\n const probe = probeRun(projectRoot, hostName, projectName);\n members[id] = {\n host: hostName,\n outputs: probe.status === \"live\" ? probe.record.outputs : undefined,\n };\n }\n return members;\n}\n\n/** What starting the shell produces: the resolved agent endpoints and, when\n * `runner.proxy` is set, the proxy's URL. Member outputs belong to the\n * members. */\nexport const outputsSchema = z.strictObject({\n agents: z.record(z.string(), z.url()),\n proxy: z.strictObject({ url: z.url() }).optional(),\n});\n\nexport type ClintOutputs = z.infer<typeof outputsSchema>;\n\ndeclare global {\n interface PHHostRunners {\n \"@powerhousedao/clint/clint-runner\": {\n host: ClintHostInput;\n outputs: ClintOutputs;\n };\n }\n}\n\n// A URL in stdout is the universal \"I am serving\" signal across member kinds\n// (switchboard prints \"MCP server available at http://…\", preview \"Local:\",\n// the agent \"agent API … http://…\").\nconst DEFAULT_READINESS = \"https?://|listening|ready\";\n/** How long a member may take to print its readiness line, in ms; also how\n * long clint then waits for its run record when something reads it. */\nconst READINESS_TIMEOUT = 180_000;\n\n/** Resolve the project's ph-cli entry the same way host-core resolves runner\n * modules: from the PROJECT's dependency tree. */\nfunction resolvePhCliEntry(projectRoot: string): string {\n const require_ = createRequire(\n pathToFileURL(path.join(projectRoot, \"package.json\")).href,\n );\n const pkgPath = require_.resolve(\"@powerhousedao/ph-cli/package.json\");\n return path.join(path.dirname(pkgPath), \"dist\", \"cli.mjs\");\n}\n\nfunction childServices(\n host: ClintHost,\n ctx: RunnerContext,\n phCliEntry: string,\n): ServiceDefinition<Record<string, unknown>>[] {\n return Object.entries(host.children).map(([name, wrapper]) =>\n defineService({\n id: name,\n name,\n command: () => `node \"${phCliEntry}\" run ${wrapper.host}`,\n env: () => ({\n FEATURE_UNIFORM_RUNNERS_ENABLED: \"1\",\n PH_USER_DATA_DIR: defaultUserDataDir(ctx.projectRoot, ctx.env),\n }),\n readiness: {\n patterns: [\n {\n name: \"up\",\n pattern: new RegExp(\n wrapper.config?.readiness?.pattern ?? DEFAULT_READINESS,\n \"i\",\n ),\n },\n ],\n timeout: wrapper.config?.readiness?.timeout ?? READINESS_TIMEOUT,\n },\n }),\n );\n}\n\nfunction readProjectName(projectRoot: string, fallback: string): string {\n try {\n return (\n (\n JSON.parse(\n fs.readFileSync(path.join(projectRoot, \"package.json\"), \"utf8\"),\n ) as { name?: string }\n ).name ?? fallback\n );\n } catch {\n return fallback;\n }\n}\n\nasync function stopAll(\n services: ServiceManager,\n names: string[],\n): Promise<void> {\n for (const id of names) {\n try {\n await services.stop(id);\n } catch {\n // already stopped\n }\n }\n}\n\n/** The shell's handle: the runner contract plus the services manager. */\nexport interface CliRunHandle extends RunnerHandle<ClintOutputs> {\n services: ServiceManager;\n}\n\nasync function startShell(\n host: ClintHost,\n ctx: RunnerContext,\n): Promise<CliRunHandle> {\n const projectName = readProjectName(ctx.projectRoot, host.name);\n // resolveOwnTokens also substitutes the \"${userData}\"/\"${projectRoot}\"\n // sugar (processResolveEnv's built-ins); member wrappers stay as declared.\n const pending = await resolveOwnTokens(host, ctx, projectName);\n const resolved = pending.host;\n const config = resolved.config ?? {};\n const lifecycle = resolved.runner.lifecycle ?? \"detached\";\n\n const phCliEntry = resolvePhCliEntry(ctx.projectRoot);\n const children = resolved.children;\n const definitions = childServices(resolved, ctx, phCliEntry);\n const eventBus = createEventBus();\n // R5: compound plugins (appliesTo \"compound\" — e.g. the proxy) run over the\n // member set. Built-ins resolve from a declared `runner.plugins`; the proxy\n // is registered when a `runner.proxy` block is present (ergonomic alias).\n const servicesDir = path.join(ctx.projectRoot, \".ph\", \"services\");\n const services = createServiceManager(definitions, {\n config: {},\n servicesDir,\n eventBus,\n });\n\n // Each member's own host.js: its `$output` tokens on sibling members\n // decide the start order (each member resolves them from its producers'\n // run records as it starts).\n const names = definitions.map((d) => d.id);\n const loaded = new Map<string, LoadedHost>();\n for (const id of names) {\n loaded.set(id, await loadHost(ctx.projectRoot, children[id].host));\n }\n // Start order: the same dependency plan the generic compound uses —\n // producers before consumers (ties keep declaration order); a\n // config.startOrder must agree with the tokens. Tokens on hosts outside\n // the compound read standalone producers and do not order members.\n const memberRefs = names.map((key) => ({ key, host: children[key].host }));\n const plan = planCompound(\n names.map((key) => ({\n key,\n host: children[key].host,\n refs: outputSitesOf(loaded.get(key)?.host)\n .filter(({ ref }) => memberRefs.some((m) => m.host === ref.host))\n .map(({ ref, path }) => ({ ref, path })),\n })),\n config.startOrder,\n );\n const ordered = plan.order;\n // Whose outputs are read, and by whom: the shell's deferred self fields,\n // and the members that consume a sibling.\n const readers = new Map<string, string[]>();\n const addReader = (id: string, reader: string) =>\n readers.set(id, [...(readers.get(id) ?? []), reader]);\n for (const deferred of pending.deferred) {\n for (const id of deferred.members) addReader(id, deferred.path);\n }\n for (const edge of plan.edges) {\n addReader(edge.producer, `member \"${edge.consumer}\"`);\n }\n /** Wait for a member's live run record when something reads it. With\n * `managed` (clint's own service state describes it), a failed or stopped\n * service ends the wait early; a member found serving on its port is not\n * clint's to watch, so it gets the full timeout. */\n const waitForRecord = async (\n id: string,\n memberHost: string,\n managed = true,\n ) => {\n const read = readers.get(id);\n if (!read) return;\n try {\n await awaitRunRecord(ctx.projectRoot, projectName, host.name, {\n id,\n host: memberHost,\n timeout: children[id].config?.readiness?.timeout ?? READINESS_TIMEOUT,\n readers: read,\n ...(managed\n ? {\n status: () =>\n services.list(id).find((s) => s.serviceId === id)?.status,\n }\n : {}),\n });\n } catch (error) {\n if (lifecycle === \"attached\") await stopAll(services, names);\n throw error;\n }\n };\n\n const memberHosts: Record<string, string> = {};\n for (const id of ordered) {\n // Re-attach checks, strongest first. (1) The member's OWN run record —\n // written with the member process's real pid (mastra-runner, the generic\n // compound). (2) Port occupancy for record-less bridge members. (3) The\n // service state file — weakest on Windows, where it records the cmd shim\n // pid, which dies on console teardown while the node grandchild survives.\n const wrapper = children[id];\n const member =\n loaded.get(id) ?? (await loadHost(ctx.projectRoot, wrapper.host));\n memberHosts[id] = member.host.name;\n const record = probeRun(ctx.projectRoot, member.host.name, projectName);\n if (record.status === \"live\") {\n console.log(\n `[${resolved.name}] ${id}: already running (pid ${record.record.pid}) — re-attached`,\n );\n continue;\n }\n const memberPort =\n typeof wrapper.runner?.port === \"number\"\n ? wrapper.runner.port\n : typeof member.host.runner.port === \"number\"\n ? member.host.runner.port\n : undefined;\n if (memberPort !== undefined && !(await isPortFree(memberPort))) {\n console.log(\n `[${resolved.name}] ${id}: port ${memberPort} already serving — re-attached`,\n );\n // It may still be booting (an earlier detached run, or started by\n // hand): its readers need its record, as after a fresh start.\n await waitForRecord(id, member.host.name, false);\n continue;\n }\n const already = services\n .list(id)\n .some((s) => s.status === \"ready\" || s.status === \"starting\");\n if (already) {\n console.log(`[${resolved.name}] ${id}: already running — re-attached`);\n await waitForRecord(id, member.host.name);\n continue;\n }\n console.log(`[${resolved.name}] starting ${id}…`);\n await services.start(id, {\n workdir: ctx.projectRoot,\n cwd: ctx.projectRoot,\n });\n const status = services.list(id).find((s) => s.serviceId === id);\n if (status) console.log(` ${formatStatus(status)}`);\n // Before anything reads its outputs (the next member, or the shell's\n // own deferred fields below).\n await waitForRecord(id, member.host.name);\n }\n\n // The deferred self fields (agent urls, proxy upstreams) name the\n // members' outputs, which exist now.\n let own: OwnFields;\n try {\n const finished = finishOwnTokens(\n pending,\n liveMemberOutputs(ctx.projectRoot, projectName, memberHosts),\n host.name,\n );\n const parsedOwn = ownFieldsSchema.safeParse({\n agents: finished.config?.agents,\n proxy: finished.runner.proxy,\n });\n if (!parsedOwn.success) {\n throw new Error(\n `hosts/${host.name}: agents/proxy resolved to invalid values:\\n${z.prettifyError(parsedOwn.error)}`,\n );\n }\n own = parsedOwn.data;\n } catch (error) {\n if (lifecycle === \"attached\") await stopAll(services, names);\n throw error;\n }\n\n // Compound-plugin pipeline (CompoundCore): resolve entries + the proxy\n // ergonomic alias, then fire onMembersReady now that endpoints are known.\n const pluginEntries = resolved.runner.plugins;\n const resolvedPlugins = pluginEntries\n ? (\n await resolveHostPlugins(\n ctx.projectRoot,\n \"compound\",\n ctx.verb,\n pluginEntries,\n `hosts/${host.name}/host.js`,\n )\n ).map((r) => r.plugin)\n : [];\n const proxyBlock = own.proxy;\n if (proxyBlock) {\n resolvedPlugins.push(createProxyPlugin(proxyBlock));\n }\n const compoundCtx: ClintCompoundContext = {\n logger: { info: (m: string) => console.log(m) },\n };\n if (resolvedPlugins.length > 0) {\n await runObserveHook(\"onMembersReady\", resolvedPlugins, compoundCtx);\n }\n\n const agents: Record<string, string> = {};\n for (const [name, agent] of Object.entries(own.agents ?? {})) {\n agents[name] = agent.url.replace(/\\/$/, \"\");\n }\n if (Object.keys(agents).length > 0) {\n console.log(\n `[${resolved.name}] agents: ${Object.entries(agents)\n .map(([n, u]) => `${n} → ${u}`)\n .join(\", \")}`,\n );\n }\n\n const shutdown = async () => {\n if (resolvedPlugins.length > 0) {\n await runObserveHookSequential(\n \"onShutdown\",\n resolvedPlugins,\n compoundCtx,\n );\n }\n if (lifecycle === \"attached\") {\n await stopAll(services, names);\n } else {\n console.log(\n `[${resolved.name}] detached lifecycle: children keep running ` +\n `(stop them with the ${resolved.name} service commands or taskkill).`,\n );\n }\n };\n\n // Validated before the stack is handed out: an invalid output (e.g. a proxy\n // bound to a bare IPv6 host, which does not form a URL) tears down what\n // was started instead of leaving it half-up.\n const parsedOutputs = outputsSchema.safeParse({\n agents,\n ...(compoundCtx.proxyUrl ? { proxy: { url: compoundCtx.proxyUrl } } : {}),\n });\n if (!parsedOutputs.success) {\n await shutdown();\n throw new Error(\n `hosts/${host.name}: the shell produced invalid outputs:\\n${z.prettifyError(parsedOutputs.error)}`,\n );\n }\n const outputs = parsedOutputs.data;\n\n if (lifecycle === \"attached\") {\n const onSignal = () => {\n void shutdown().finally(() => process.exit(130));\n };\n process.once(\"SIGINT\", onSignal);\n process.once(\"SIGTERM\", onSignal);\n }\n\n // Members were started (and awaited to readiness) above.\n return { outputs, ready: Promise.resolve(), services, shutdown };\n}\n\n/** Minimal line chat against an agent's OpenAI-compatible endpoint. */\nasync function chatLoop(agents: Record<string, string>): Promise<void> {\n const [agentName, endpoint] = Object.entries(agents)[0] ?? [];\n if (!agentName || !endpoint) {\n console.log(\"No agents configured (config.agents) — chat unavailable.\");\n return;\n }\n console.log(`Chatting with ${agentName} (${endpoint}). /exit to quit.`);\n const rl = createInterface({ input: process.stdin, output: process.stdout });\n const ask = (q: string) =>\n new Promise<string>((resolve) => rl.question(q, resolve));\n for (;;) {\n const line = (await ask(\"> \")).trim();\n if (line === \"/exit\" || line === \"exit\") break;\n if (!line) continue;\n try {\n const res = await fetch(`${endpoint}/chat/completions`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n messages: [{ role: \"user\", content: line }],\n }),\n });\n const body = (await res.json()) as {\n choices?: { message?: { content?: string } }[];\n error?: { message?: string };\n };\n console.log(\n body.choices?.[0]?.message?.content ??\n `[error] ${body.error?.message ?? res.status}`,\n );\n } catch (error) {\n console.log(`[transport error] ${String(error)}`);\n }\n }\n rl.close();\n}\n\nexport async function run(\n host: ClintHost,\n ctx: RunnerContext,\n): Promise<CliRunHandle> {\n const handle = await startShell(host, ctx);\n console.log(\n `[${host.name}] services up. ` +\n `(ph run ${host.name} dev for the chat shell; Ctrl+C ${\n host.runner.lifecycle === \"attached\"\n ? \"stops the children\"\n : \"leaves children running\"\n }.)`,\n );\n return handle;\n}\n\nexport const serve = run;\n\n/** dev = services up + the line chat shell (blocks until /exit). */\nexport async function dev(host: ClintHost, ctx: RunnerContext): Promise<void> {\n const handle = await startShell(host, ctx);\n await chatLoop(handle.outputs.agents);\n await handle.shutdown();\n}\n\n/** build = forward build to each member host that exports it (fail loud on\n * members that do not — a silent skip would report success on an unbuilt\n * set), same posture as the generic compound. */\nexport async function build(\n host: ClintHost,\n ctx: RunnerContext,\n): Promise<void> {\n const { getVerb, resolveRunnerModule, validateHost } =\n await import(\"@powerhousedao/host-core\");\n for (const [name, wrapper] of Object.entries(host.children)) {\n const member = await loadHost(ctx.projectRoot, wrapper.host);\n const specifier = member.host.runner.module;\n const runner = await resolveRunnerModule(ctx.projectRoot, specifier);\n const validated = validateHost(\n runner,\n specifier,\n member.host,\n `hosts/${wrapper.host}/host.js`,\n );\n const fn = getVerb(runner, specifier, \"build\");\n console.log(`[${host.name}] build → ${name} (${wrapper.host})`);\n await fn(validated, {\n ...ctx,\n verb: \"build\",\n parent: { host: host.name, verb: ctx.verb },\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAQA,SAAgB,gBACd,KACA,MACqB;CACrB,QAAQ,UAAU;EAChB,IAAI,MAAM,SAAS,uBAAuB,CAAC,MAAM,KAAK,SAAS,GAAG,GAChE;EAMF,OAAO,KAAK,IAAI,kBAAkB,KAHhC,OAAO,MAAM,UAAU,YAAY,MAAM,UAAU,OAC9C,MAAM,QACP,CAAC,CACqC;CAC9C;AACF;;AAGA,SAAgB,WAAW,OAAgB,aAA6B;CACtE,OAAO,OAAO,UAAU,YAAY,MAAM,SAAS,IAC/C,KAAK,UAAU,KAAK,IACpB;AACN;;;;;;;;;;;;;;ACZA,SAAS,WAAW,OAAwC;CAK1D,OAAO,6IAHL,OAAO,MAAM,WAAW,YAAY,MAAM,OAAO,SAAS,IACtD,aAAa,KAAK,UAAU,MAAM,MAAM,MACxC,GACqJ;AAC7J;;;AAIA,SAAS,6BAAkD,KAAQ;;;CAGjE,MAAM,mBAAmB,EAAE,aACzB;EACE,UAAU;EACV,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS;EAC1B,IAAI,EAAE,QAAQ,CAAC,CAAC,SAAS;CAC3B,GACA,EAAE,OAAO,gBAAgB,UAAU,UAAU,EAAE,CACjD;CACA,OAAO,EAAE,aAAa;;EAEpB,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;;EAE5B,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;EACjC,WAAW,EAAE,IAAI,CAAC,CAAC,SAAS;;EAE5B,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,gBAAgB;CAC/C,CAAC;AACH;;AAGA,MAAa,0BAA0B,6BAA6B,EAAE,IAAI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EAC3D,MAAM,SAAS,MAAM,SAAS,IAAI,aAAa,QAAQ,IAAI;EAC3D,MAAM,YAAY,OAAO,KAAK,OAAO;EACrC,MAAM,SAAS,MAAM,oBAAoB,IAAI,aAAa,SAAS;EACnE,MAAM,YAAY,aAChB,QACA,WACA,OAAO,MACP,SAAS,QAAQ,KAAK,SACxB;EACA,MAAM,KAAK,QAAQ,QAAQ,WAAW,OAAO;EAC7C,QAAQ,IAAI,IAAI,KAAK,KAAK,YAAY,KAAK,IAAI,QAAQ,KAAK,EAAE;EAC9D,MAAM,GAAG,WAAW;GAClB,GAAG;GACH,MAAM;GACN,QAAQ;IAAE,MAAM,KAAK;IAAM,MAAM,IAAI;GAAK;EAC5C,CAAC;CACH;AACF"}
|
|
@@ -1,128 +1,285 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { RunnerContext, RunnerHandle } from "@powerhousedao/host-core";
|
|
2
3
|
//#region src/runners/mastra-runner.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* mastra-runner (P5.6): the headless agent host. Its reactor is a REMOTE
|
|
5
|
-
* attach — a lone `remote` backend
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
6
|
+
* attach — a lone `remote` backend whose `remote.url` is the running
|
|
7
|
+
* switchboard's GraphQL endpoint (typically the output token
|
|
8
|
+
* `switchboard.endpoints.graphql`, resolved before the verb runs); it depends
|
|
9
|
+
* on that switchboard and never starts one. `run`/`serve` expose an
|
|
10
|
+
* OpenAI-compatible chat-completions endpoint (streaming SSE +
|
|
11
|
+
* non-streaming, stateless baseline — the caller owns session state);
|
|
12
|
+
* without a configured model it answers as the DEMO agent. `build` compiles
|
|
13
|
+
* skills and agent profiles (ph-clint-dev's pipeline, ported).
|
|
12
14
|
*/
|
|
13
15
|
export declare const kind = "reactor";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
config: import("zod").ZodOptional<import("zod").ZodObject<{}, import("zod/v4/core").$loose>>;
|
|
29
|
-
profile: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
30
|
-
appId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
31
|
-
name: import("zod").ZodOptional<import("zod").ZodString>;
|
|
32
|
-
description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
33
|
-
icon: import("zod").ZodOptional<import("zod").ZodString>;
|
|
34
|
-
}, import("zod/v4/core").$strict>>;
|
|
35
|
-
reactor: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
36
|
-
backends: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodObject<{
|
|
37
|
-
kind: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
16
|
+
/** The verbs this runner exports (`promptFromMessages` is a helper). */
|
|
17
|
+
export declare const verbs: readonly ["run", "serve", "build"];
|
|
18
|
+
/** Declared form: what a host file may contain before resolution. */
|
|
19
|
+
export declare const declaredHostSchema: z.ZodObject<{
|
|
20
|
+
name: z.ZodString;
|
|
21
|
+
profile: z.ZodOptional<z.ZodObject<{
|
|
22
|
+
appId: z.ZodOptional<z.ZodString>;
|
|
23
|
+
name: z.ZodOptional<z.ZodString>;
|
|
24
|
+
description: z.ZodOptional<z.ZodString>;
|
|
25
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
26
|
+
}, z.core.$strict>>;
|
|
27
|
+
reactor: z.ZodOptional<z.ZodObject<{
|
|
28
|
+
backends: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
29
|
+
kind: z.ZodEnum<{
|
|
38
30
|
"in-process": "in-process";
|
|
39
31
|
remote: "remote";
|
|
40
32
|
worker: "worker";
|
|
33
|
+
}>;
|
|
34
|
+
storage: z.ZodOptional<z.ZodObject<{
|
|
35
|
+
kind: z.ZodEnum<{
|
|
36
|
+
idb: "idb";
|
|
37
|
+
memory: "memory";
|
|
38
|
+
path: "path";
|
|
39
|
+
postgres: "postgres";
|
|
40
|
+
}>;
|
|
41
|
+
dataDir: z.ZodOptional<import("@powerhousedao/host-core").TokenableSchema<z.ZodString, import("@powerhousedao/host-core").EnvToken>>;
|
|
42
|
+
url: z.ZodOptional<z.ZodString>;
|
|
43
|
+
}, z.core.$strict>>;
|
|
44
|
+
readModel: z.ZodOptional<z.ZodObject<{
|
|
45
|
+
url: z.ZodOptional<z.ZodString>;
|
|
46
|
+
}, z.core.$strict>>;
|
|
47
|
+
packages: z.ZodOptional<z.ZodObject<{
|
|
48
|
+
cdnUrl: z.ZodOptional<z.ZodString>;
|
|
49
|
+
specs: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
50
|
+
dynamic: z.ZodOptional<z.ZodBoolean>;
|
|
51
|
+
}, z.core.$strict>>;
|
|
52
|
+
remote: z.ZodOptional<z.ZodObject<{
|
|
53
|
+
url: import("@powerhousedao/host-core").TokenableSchema<z.ZodURL>;
|
|
54
|
+
}, z.core.$strict>>;
|
|
55
|
+
projection: z.ZodOptional<z.ZodObject<{
|
|
56
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
57
|
+
dbPoolSize: z.ZodOptional<z.ZodNumber>;
|
|
58
|
+
}, z.core.$strict>>;
|
|
59
|
+
executors: z.ZodOptional<z.ZodObject<{
|
|
60
|
+
numWorkers: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"auto">]>>;
|
|
61
|
+
}, z.core.$strict>>;
|
|
62
|
+
}, z.core.$strict>>>;
|
|
63
|
+
placement: z.ZodOptional<z.ZodObject<{
|
|
64
|
+
primary: z.ZodOptional<z.ZodString>;
|
|
65
|
+
default: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
66
|
+
}, z.core.$strict>>;
|
|
67
|
+
protocol: z.ZodOptional<z.ZodObject<{
|
|
68
|
+
featureFlags: z.ZodOptional<z.ZodObject<{
|
|
69
|
+
documentDecisions: z.ZodOptional<z.ZodBoolean>;
|
|
70
|
+
authEnforcement: z.ZodOptional<z.ZodBoolean>;
|
|
71
|
+
authGroups: z.ZodOptional<z.ZodBoolean>;
|
|
72
|
+
authConditions: z.ZodOptional<z.ZodBoolean>;
|
|
73
|
+
}, z.core.$strict>>;
|
|
74
|
+
createSignaturePolicy: z.ZodOptional<z.ZodEnum<{
|
|
75
|
+
legacy: "legacy";
|
|
76
|
+
"v2-required": "v2-required";
|
|
77
|
+
}>>;
|
|
78
|
+
unsupportedStoredDocuments: z.ZodOptional<z.ZodEnum<{
|
|
79
|
+
"read-only": "read-only";
|
|
80
|
+
refuse: "refuse";
|
|
41
81
|
}>>;
|
|
42
|
-
|
|
43
|
-
|
|
82
|
+
}, z.core.$strict>>;
|
|
83
|
+
workflows: z.ZodOptional<z.ZodBoolean>;
|
|
84
|
+
renown: z.ZodOptional<z.ZodObject<{
|
|
85
|
+
url: z.ZodOptional<z.ZodString>;
|
|
86
|
+
networkId: z.ZodOptional<z.ZodString>;
|
|
87
|
+
chainId: z.ZodOptional<z.ZodNumber>;
|
|
88
|
+
}, z.core.$strict>>;
|
|
89
|
+
packages: z.ZodOptional<z.ZodObject<{
|
|
90
|
+
registryUrl: z.ZodOptional<z.ZodString>;
|
|
91
|
+
}, z.core.$strict>>;
|
|
92
|
+
namespace: z.ZodOptional<z.ZodString>;
|
|
93
|
+
auth: z.ZodOptional<z.ZodObject<{
|
|
94
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
95
|
+
admins: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
96
|
+
renown: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
97
|
+
}, z.core.$strict>>;
|
|
98
|
+
drives: z.ZodOptional<import("@powerhousedao/host-core").TokenableSchema<z.ZodArray<z.ZodObject<{
|
|
99
|
+
slug: z.ZodString;
|
|
100
|
+
id: z.ZodOptional<z.ZodString>;
|
|
101
|
+
projectHash: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"id">]>>;
|
|
102
|
+
name: z.ZodOptional<z.ZodString>;
|
|
103
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
104
|
+
preferredEditor: z.ZodOptional<z.ZodString>;
|
|
105
|
+
sharingType: z.ZodOptional<z.ZodEnum<{
|
|
106
|
+
private: "private";
|
|
107
|
+
public: "public";
|
|
108
|
+
shared: "shared";
|
|
109
|
+
}>>;
|
|
110
|
+
availableOffline: z.ZodOptional<z.ZodBoolean>;
|
|
111
|
+
remote: z.ZodOptional<z.ZodObject<{
|
|
112
|
+
url: import("@powerhousedao/host-core").TokenableSchema<z.ZodString>;
|
|
113
|
+
}, z.core.$strict>>;
|
|
114
|
+
}, z.core.$strict>>>>;
|
|
115
|
+
}, z.core.$strict>>;
|
|
116
|
+
runner: z.ZodObject<{
|
|
117
|
+
module: z.ZodString;
|
|
118
|
+
defaultVerb: z.ZodOptional<z.ZodString>;
|
|
119
|
+
port: z.ZodOptional<z.ZodNumber>;
|
|
120
|
+
host: z.ZodOptional<z.ZodString>;
|
|
121
|
+
plugins: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
122
|
+
module: z.ZodString;
|
|
123
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
124
|
+
verbs: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"*">, z.ZodArray<z.ZodString>]>>;
|
|
125
|
+
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
126
|
+
}, z.core.$strict>]>>>;
|
|
127
|
+
}, z.core.$strict>;
|
|
128
|
+
config: z.ZodOptional<z.ZodObject<{
|
|
129
|
+
model: z.ZodOptional<z.ZodString>;
|
|
130
|
+
apiKey: z.ZodOptional<import("@powerhousedao/host-core").TokenableSchema<z.ZodString>>;
|
|
131
|
+
instructions: z.ZodOptional<z.ZodString>;
|
|
132
|
+
prompts: z.ZodOptional<z.ZodObject<{
|
|
133
|
+
skillsDir: z.ZodOptional<z.ZodString>;
|
|
134
|
+
agentsDir: z.ZodOptional<z.ZodString>;
|
|
135
|
+
outDir: z.ZodOptional<z.ZodString>;
|
|
136
|
+
}, z.core.$strict>>;
|
|
137
|
+
}, z.core.$strict>>;
|
|
138
|
+
}, z.core.$strict>;
|
|
139
|
+
/** Resolved form: what the verbs receive (and `validateHost` checks). */
|
|
140
|
+
export declare const hostSchema: z.ZodObject<{
|
|
141
|
+
name: z.ZodString;
|
|
142
|
+
profile: z.ZodOptional<z.ZodObject<{
|
|
143
|
+
appId: z.ZodOptional<z.ZodString>;
|
|
144
|
+
name: z.ZodOptional<z.ZodString>;
|
|
145
|
+
description: z.ZodOptional<z.ZodString>;
|
|
146
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
147
|
+
}, z.core.$strict>>;
|
|
148
|
+
reactor: z.ZodOptional<z.ZodObject<{
|
|
149
|
+
backends: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
150
|
+
kind: z.ZodEnum<{
|
|
151
|
+
"in-process": "in-process";
|
|
152
|
+
remote: "remote";
|
|
153
|
+
worker: "worker";
|
|
154
|
+
}>;
|
|
155
|
+
storage: z.ZodOptional<z.ZodObject<{
|
|
156
|
+
kind: z.ZodEnum<{
|
|
44
157
|
idb: "idb";
|
|
45
158
|
memory: "memory";
|
|
46
159
|
path: "path";
|
|
47
160
|
postgres: "postgres";
|
|
48
161
|
}>;
|
|
49
|
-
dataDir: import("
|
|
50
|
-
url:
|
|
51
|
-
},
|
|
52
|
-
readModel:
|
|
53
|
-
url:
|
|
54
|
-
},
|
|
55
|
-
packages:
|
|
56
|
-
cdnUrl:
|
|
57
|
-
specs:
|
|
58
|
-
dynamic:
|
|
59
|
-
},
|
|
60
|
-
remote:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
createSignaturePolicy: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
162
|
+
dataDir: z.ZodOptional<import("@powerhousedao/host-core").TokenableSchema<z.ZodString, import("@powerhousedao/host-core").EnvToken>>;
|
|
163
|
+
url: z.ZodOptional<z.ZodString>;
|
|
164
|
+
}, z.core.$strict>>;
|
|
165
|
+
readModel: z.ZodOptional<z.ZodObject<{
|
|
166
|
+
url: z.ZodOptional<z.ZodString>;
|
|
167
|
+
}, z.core.$strict>>;
|
|
168
|
+
packages: z.ZodOptional<z.ZodObject<{
|
|
169
|
+
cdnUrl: z.ZodOptional<z.ZodString>;
|
|
170
|
+
specs: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
171
|
+
dynamic: z.ZodOptional<z.ZodBoolean>;
|
|
172
|
+
}, z.core.$strict>>;
|
|
173
|
+
remote: z.ZodOptional<z.ZodObject<{
|
|
174
|
+
url: import("@powerhousedao/host-core").TokenableSchema<z.ZodURL>;
|
|
175
|
+
}, z.core.$strict>>;
|
|
176
|
+
projection: z.ZodOptional<z.ZodObject<{
|
|
177
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
178
|
+
dbPoolSize: z.ZodOptional<z.ZodNumber>;
|
|
179
|
+
}, z.core.$strict>>;
|
|
180
|
+
executors: z.ZodOptional<z.ZodObject<{
|
|
181
|
+
numWorkers: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"auto">]>>;
|
|
182
|
+
}, z.core.$strict>>;
|
|
183
|
+
}, z.core.$strict>>>;
|
|
184
|
+
placement: z.ZodOptional<z.ZodObject<{
|
|
185
|
+
primary: z.ZodOptional<z.ZodString>;
|
|
186
|
+
default: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
187
|
+
}, z.core.$strict>>;
|
|
188
|
+
protocol: z.ZodOptional<z.ZodObject<{
|
|
189
|
+
featureFlags: z.ZodOptional<z.ZodObject<{
|
|
190
|
+
documentDecisions: z.ZodOptional<z.ZodBoolean>;
|
|
191
|
+
authEnforcement: z.ZodOptional<z.ZodBoolean>;
|
|
192
|
+
authGroups: z.ZodOptional<z.ZodBoolean>;
|
|
193
|
+
authConditions: z.ZodOptional<z.ZodBoolean>;
|
|
194
|
+
}, z.core.$strict>>;
|
|
195
|
+
createSignaturePolicy: z.ZodOptional<z.ZodEnum<{
|
|
84
196
|
legacy: "legacy";
|
|
85
197
|
"v2-required": "v2-required";
|
|
86
198
|
}>>;
|
|
87
|
-
unsupportedStoredDocuments:
|
|
199
|
+
unsupportedStoredDocuments: z.ZodOptional<z.ZodEnum<{
|
|
88
200
|
"read-only": "read-only";
|
|
89
201
|
refuse: "refuse";
|
|
90
202
|
}>>;
|
|
91
|
-
},
|
|
92
|
-
workflows:
|
|
93
|
-
renown:
|
|
94
|
-
url:
|
|
95
|
-
networkId:
|
|
96
|
-
chainId:
|
|
97
|
-
},
|
|
98
|
-
packages:
|
|
99
|
-
registryUrl:
|
|
100
|
-
},
|
|
101
|
-
namespace:
|
|
102
|
-
auth:
|
|
103
|
-
enabled:
|
|
104
|
-
admins:
|
|
105
|
-
renown:
|
|
106
|
-
},
|
|
107
|
-
drives:
|
|
108
|
-
slug:
|
|
109
|
-
id:
|
|
110
|
-
projectHash:
|
|
111
|
-
name:
|
|
112
|
-
icon:
|
|
113
|
-
preferredEditor:
|
|
114
|
-
sharingType:
|
|
203
|
+
}, z.core.$strict>>;
|
|
204
|
+
workflows: z.ZodOptional<z.ZodBoolean>;
|
|
205
|
+
renown: z.ZodOptional<z.ZodObject<{
|
|
206
|
+
url: z.ZodOptional<z.ZodString>;
|
|
207
|
+
networkId: z.ZodOptional<z.ZodString>;
|
|
208
|
+
chainId: z.ZodOptional<z.ZodNumber>;
|
|
209
|
+
}, z.core.$strict>>;
|
|
210
|
+
packages: z.ZodOptional<z.ZodObject<{
|
|
211
|
+
registryUrl: z.ZodOptional<z.ZodString>;
|
|
212
|
+
}, z.core.$strict>>;
|
|
213
|
+
namespace: z.ZodOptional<z.ZodString>;
|
|
214
|
+
auth: z.ZodOptional<z.ZodObject<{
|
|
215
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
216
|
+
admins: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
217
|
+
renown: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
218
|
+
}, z.core.$strict>>;
|
|
219
|
+
drives: z.ZodOptional<import("@powerhousedao/host-core").TokenableSchema<z.ZodArray<z.ZodObject<{
|
|
220
|
+
slug: z.ZodString;
|
|
221
|
+
id: z.ZodOptional<z.ZodString>;
|
|
222
|
+
projectHash: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"id">]>>;
|
|
223
|
+
name: z.ZodOptional<z.ZodString>;
|
|
224
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
225
|
+
preferredEditor: z.ZodOptional<z.ZodString>;
|
|
226
|
+
sharingType: z.ZodOptional<z.ZodEnum<{
|
|
115
227
|
private: "private";
|
|
116
228
|
public: "public";
|
|
117
229
|
shared: "shared";
|
|
118
230
|
}>>;
|
|
119
|
-
availableOffline:
|
|
120
|
-
remote:
|
|
121
|
-
url: import("
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
|
|
231
|
+
availableOffline: z.ZodOptional<z.ZodBoolean>;
|
|
232
|
+
remote: z.ZodOptional<z.ZodObject<{
|
|
233
|
+
url: import("@powerhousedao/host-core").TokenableSchema<z.ZodString>;
|
|
234
|
+
}, z.core.$strict>>;
|
|
235
|
+
}, z.core.$strict>>>>;
|
|
236
|
+
}, z.core.$strict>>;
|
|
237
|
+
runner: z.ZodObject<{
|
|
238
|
+
module: z.ZodString;
|
|
239
|
+
defaultVerb: z.ZodOptional<z.ZodString>;
|
|
240
|
+
port: z.ZodOptional<z.ZodNumber>;
|
|
241
|
+
host: z.ZodOptional<z.ZodString>;
|
|
242
|
+
plugins: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
243
|
+
module: z.ZodString;
|
|
244
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
245
|
+
verbs: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"*">, z.ZodArray<z.ZodString>]>>;
|
|
246
|
+
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
247
|
+
}, z.core.$strict>]>>>;
|
|
248
|
+
}, z.core.$strict>;
|
|
249
|
+
config: z.ZodOptional<z.ZodObject<{
|
|
250
|
+
model: z.ZodOptional<z.ZodString>;
|
|
251
|
+
apiKey: z.ZodOptional<import("@powerhousedao/host-core").TokenableSchema<z.ZodString>>;
|
|
252
|
+
instructions: z.ZodOptional<z.ZodString>;
|
|
253
|
+
prompts: z.ZodOptional<z.ZodObject<{
|
|
254
|
+
skillsDir: z.ZodOptional<z.ZodString>;
|
|
255
|
+
agentsDir: z.ZodOptional<z.ZodString>;
|
|
256
|
+
outDir: z.ZodOptional<z.ZodString>;
|
|
257
|
+
}, z.core.$strict>>;
|
|
258
|
+
}, z.core.$strict>>;
|
|
259
|
+
}, z.core.$strict>;
|
|
260
|
+
/** What an agent host.js author writes. */
|
|
261
|
+
export type MastraHostInput = z.input<typeof declaredHostSchema>;
|
|
262
|
+
/** What the verbs receive. */
|
|
263
|
+
export type MastraHost = z.output<typeof hostSchema>;
|
|
264
|
+
export type AgentHostConfig = NonNullable<MastraHostInput["config"]>;
|
|
265
|
+
/** What serving the agent produces: where its OpenAI-compatible API is
|
|
266
|
+
* actually bound. */
|
|
267
|
+
export declare const outputsSchema: z.ZodObject<{
|
|
268
|
+
origin: z.ZodURL;
|
|
269
|
+
endpoints: z.ZodObject<{
|
|
270
|
+
openai: z.ZodURL;
|
|
271
|
+
ready: z.ZodURL;
|
|
272
|
+
}, z.core.$strict>;
|
|
273
|
+
}, z.core.$strict>;
|
|
274
|
+
export type MastraOutputs = z.infer<typeof outputsSchema>;
|
|
275
|
+
declare global {
|
|
276
|
+
interface PHHostRunners {
|
|
277
|
+
"@powerhousedao/clint/mastra-runner": {
|
|
278
|
+
host: MastraHostInput;
|
|
279
|
+
outputs: MastraOutputs;
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
}
|
|
126
283
|
type ChatMessage = {
|
|
127
284
|
role: string;
|
|
128
285
|
content: unknown;
|
|
@@ -130,16 +287,11 @@ type ChatMessage = {
|
|
|
130
287
|
/** Baseline stateless mapping: the last user message is the prompt (string
|
|
131
288
|
* or OpenAI content-part arrays flattened to their text parts). */
|
|
132
289
|
export declare function promptFromMessages(messages: ChatMessage[]): string;
|
|
133
|
-
export
|
|
134
|
-
|
|
135
|
-
endpoints: Record<string, string>;
|
|
136
|
-
ready: Promise<void>;
|
|
137
|
-
shutdown: () => Promise<void>;
|
|
138
|
-
}
|
|
139
|
-
export declare function run(host: HostDefinition, ctx: RunnerContext): Promise<AgentServeHandle>;
|
|
290
|
+
export type AgentServeHandle = RunnerHandle<MastraOutputs>;
|
|
291
|
+
export declare function run(host: MastraHost, ctx: RunnerContext): Promise<AgentServeHandle>;
|
|
140
292
|
export declare const serve: typeof run;
|
|
141
293
|
/** `build` — skill + agent-profile compilation (ph-clint-dev's pipeline). */
|
|
142
|
-
export declare function build(host:
|
|
294
|
+
export declare function build(host: MastraHost, ctx: RunnerContext): Promise<void>;
|
|
143
295
|
//#endregion
|
|
144
296
|
export {};
|
|
145
297
|
//# sourceMappingURL=mastra-runner.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mastra-runner.d.mts","names":[],"sources":["../../src/runners/mastra-runner.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"mastra-runner.d.mts","names":[],"sources":["../../src/runners/mastra-runner.ts"],"mappings":";;;;;;;;;;;;;;qBAkCa;;qBAGA;;qBA8CA,oBAAkB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAA6B,EAAA,KAAA;;qBAE/C,YAAU,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAAqB,EAAA,KAAA;;YAGhC,kBAAkB,EAAE,aAAa;;YAEjC,aAAa,EAAE,cAAc;YAC7B,kBAAkB,YAAY;;;qBAI7B,eAAa,EAAA;;;;;;GASxB,EAAA,KAAA;YAEU,gBAAgB,EAAE,aAAa;QAEnC;YACI;IACR;MACE,MAAM;MACN,SAAS;;;;KA8BV;EAAgB;EAAc;;;;wBAInB,mBAAmB,UAAU;YAqCjC,mBAAmB,aAAa;wBA0MtB,IACpB,MAAM,YACN,KAAK,gBACJ,QAAQ;qBAIE,cAAK;;wBAGI,MACpB,MAAM,YACN,KAAK,gBACJ"}
|