@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,309 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { createServer } from "node:http";
|
|
4
|
+
import { clearRunRecord, defaultUserDataDir, loadHost, probeRun, reactorHostSchema, resolveUserDataPlaceholders, writeRunRecord } from "@powerhousedao/host-core";
|
|
5
|
+
//#region src/integrations/powerhouse/remote-reactor.ts
|
|
6
|
+
/** Derive the GraphQL endpoint from the accepted url spellings. */
|
|
7
|
+
function deriveGraphqlEndpoint(url) {
|
|
8
|
+
const parsed = new URL(url);
|
|
9
|
+
if (parsed.pathname.includes("/d/")) return `${parsed.origin}/graphql`;
|
|
10
|
+
if (parsed.pathname.replace(/\/$/, "").endsWith("/graphql")) return `${parsed.origin}${parsed.pathname.replace(/\/$/, "")}`;
|
|
11
|
+
const base = parsed.pathname.replace(/\/$/, "");
|
|
12
|
+
return `${parsed.origin}${base}/graphql`;
|
|
13
|
+
}
|
|
14
|
+
async function probeEndpoint(endpoint, timeoutMs) {
|
|
15
|
+
try {
|
|
16
|
+
await fetch(endpoint, {
|
|
17
|
+
method: "POST",
|
|
18
|
+
headers: { "content-type": "application/json" },
|
|
19
|
+
body: JSON.stringify({ query: "{ __typename }" }),
|
|
20
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
21
|
+
});
|
|
22
|
+
} catch (cause) {
|
|
23
|
+
throw new Error(`Cannot attach to the reactor at ${endpoint}: the switchboard is not answering. The agent depends on a RUNNING switchboard and never starts one — start it first (e.g. \`ph run switchboard\`, \`ph vetra\`, or the compound that members both) and retry.`, { cause });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Read the inspection subgraph's info when it answers (dev switchboards
|
|
27
|
+
* under the OPEN policy serve it); absence is not an attach failure. */
|
|
28
|
+
async function readRemoteInfo(endpoint, token, timeoutMs) {
|
|
29
|
+
try {
|
|
30
|
+
const res = await fetch(`${endpoint}/inspection`, {
|
|
31
|
+
method: "POST",
|
|
32
|
+
headers: {
|
|
33
|
+
"content-type": "application/json",
|
|
34
|
+
...token ? { authorization: `Bearer ${token}` } : {}
|
|
35
|
+
},
|
|
36
|
+
body: JSON.stringify({ query: "query ReactorInspectionInfo { inspection { info } }" }),
|
|
37
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
38
|
+
});
|
|
39
|
+
if (!res.ok) return void 0;
|
|
40
|
+
return (await res.json()).data?.inspection?.info;
|
|
41
|
+
} catch {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function attachRemoteReactor(options) {
|
|
46
|
+
const timeoutMs = options.timeoutMs ?? 1e4;
|
|
47
|
+
const endpoint = deriveGraphqlEndpoint(options.url);
|
|
48
|
+
await probeEndpoint(endpoint, timeoutMs);
|
|
49
|
+
const remoteInfo = await readRemoteInfo(endpoint, options.token, timeoutMs);
|
|
50
|
+
const { GraphQLReactorClient } = await import("@powerhousedao/reactor-browser/graphql-client");
|
|
51
|
+
return {
|
|
52
|
+
endpoint,
|
|
53
|
+
client: new GraphQLReactorClient({
|
|
54
|
+
url: endpoint,
|
|
55
|
+
documentModels: options.documentModels,
|
|
56
|
+
...options.token ? { tokenProvider: () => Promise.resolve(options.token) } : {}
|
|
57
|
+
}),
|
|
58
|
+
remoteInfo
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/runners/agent-provider.ts
|
|
63
|
+
function createDemoProvider(agentName) {
|
|
64
|
+
return {
|
|
65
|
+
modelId: "demo",
|
|
66
|
+
async *stream(prompt) {
|
|
67
|
+
yield {
|
|
68
|
+
type: "text-delta",
|
|
69
|
+
text: `You said: ${JSON.stringify(prompt.slice(0, 2e3))}. I'm the ${agentName} demo agent — configure a model (host config \`model\`, provider API key in the environment) for real responses.`
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
async function createMastraProvider(options) {
|
|
75
|
+
const { Agent } = await import("@mastra/core/agent");
|
|
76
|
+
const { mapMastraStream } = await import("../stream-DVuufwIj.mjs");
|
|
77
|
+
const agent = new Agent({
|
|
78
|
+
id: options.agentName,
|
|
79
|
+
name: options.agentName,
|
|
80
|
+
instructions: options.instructions,
|
|
81
|
+
model: options.model
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
modelId: options.model,
|
|
85
|
+
async *stream(prompt, streamOptions) {
|
|
86
|
+
const result = await agent.stream(prompt, {
|
|
87
|
+
memory: void 0,
|
|
88
|
+
threadId: streamOptions.threadId
|
|
89
|
+
});
|
|
90
|
+
yield* mapMastraStream(result.fullStream);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/runners/mastra-runner.ts
|
|
96
|
+
/**
|
|
97
|
+
* mastra-runner (P5.6): the headless agent host. Its reactor is a REMOTE
|
|
98
|
+
* attach — a lone `remote` backend naming a running switchboard (by sibling
|
|
99
|
+
* host reference or URL); it depends on that switchboard and never starts
|
|
100
|
+
* one. `run`/`serve` expose an OpenAI-compatible chat-completions endpoint
|
|
101
|
+
* (streaming SSE + non-streaming, stateless baseline — the caller owns
|
|
102
|
+
* session state); without a configured model it answers as the DEMO agent.
|
|
103
|
+
* `build` compiles skills and agent profiles (ph-clint-dev's pipeline,
|
|
104
|
+
* ported).
|
|
105
|
+
*/
|
|
106
|
+
const kind = "reactor";
|
|
107
|
+
const hostSchema = reactorHostSchema;
|
|
108
|
+
const DEFAULT_AGENT_PORT = 4910;
|
|
109
|
+
/** Resolve the remote backend's switchboard url: `remote.url` as given, or a
|
|
110
|
+
* sibling host reference (`remote.host`) whose runner.port names the port. */
|
|
111
|
+
async function resolveRemoteUrl(host, ctx) {
|
|
112
|
+
const reactor = host.reactor;
|
|
113
|
+
const remote = Object.entries(reactor?.backends ?? {}).find(([, b]) => b.kind === "remote")?.[1];
|
|
114
|
+
if (!remote) throw new Error(`hosts/${host.name}: an agent host attaches to a RUNNING switchboard — declare a remote backend, e.g. reactor.backends.switchboard = { kind: "remote", remote: { host: "switchboard" } }.`);
|
|
115
|
+
const ref = remote.remote;
|
|
116
|
+
if (ref?.url) return ref.url;
|
|
117
|
+
if (ref?.host) {
|
|
118
|
+
const port = (await loadHost(ctx.projectRoot, ref.host)).host.runner.port;
|
|
119
|
+
if (typeof port !== "number") throw new Error(`hosts/${host.name}: sibling host "${ref.host}" declares no runner.port to derive the switchboard endpoint from — set one, or use remote.url.`);
|
|
120
|
+
return `http://localhost:${port}/graphql`;
|
|
121
|
+
}
|
|
122
|
+
throw new Error(`hosts/${host.name}: the remote backend needs remote.url or a sibling remote.host reference.`);
|
|
123
|
+
}
|
|
124
|
+
/** Baseline stateless mapping: the last user message is the prompt (string
|
|
125
|
+
* or OpenAI content-part arrays flattened to their text parts). */
|
|
126
|
+
function promptFromMessages(messages) {
|
|
127
|
+
const content = [...messages].reverse().find((m) => m.role === "user")?.content;
|
|
128
|
+
if (typeof content === "string") return content;
|
|
129
|
+
if (Array.isArray(content)) return content.map((part) => part.type === "text" ? part.text ?? "" : "").join("");
|
|
130
|
+
return "";
|
|
131
|
+
}
|
|
132
|
+
async function readBody(req) {
|
|
133
|
+
const chunks = [];
|
|
134
|
+
for await (const chunk of req) chunks.push(chunk);
|
|
135
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
136
|
+
}
|
|
137
|
+
function completionChunk(id, model, delta, finish) {
|
|
138
|
+
return `data: ${JSON.stringify({
|
|
139
|
+
id,
|
|
140
|
+
object: "chat.completion.chunk",
|
|
141
|
+
created: Math.floor(Date.now() / 1e3),
|
|
142
|
+
model,
|
|
143
|
+
choices: [{
|
|
144
|
+
index: 0,
|
|
145
|
+
delta,
|
|
146
|
+
finish_reason: finish
|
|
147
|
+
}]
|
|
148
|
+
})}\n\n`;
|
|
149
|
+
}
|
|
150
|
+
async function serveAgent(host, ctx) {
|
|
151
|
+
const userData = defaultUserDataDir(ctx.projectRoot, ctx.env);
|
|
152
|
+
const resolved = resolveUserDataPlaceholders(host, userData);
|
|
153
|
+
const config = resolved.config ?? {};
|
|
154
|
+
const port = typeof resolved.runner.port === "number" ? resolved.runner.port : DEFAULT_AGENT_PORT;
|
|
155
|
+
const projectName = (() => {
|
|
156
|
+
try {
|
|
157
|
+
return JSON.parse(fs.readFileSync(`${ctx.projectRoot}/package.json`, "utf8")).name ?? host.name;
|
|
158
|
+
} catch {
|
|
159
|
+
return host.name;
|
|
160
|
+
}
|
|
161
|
+
})();
|
|
162
|
+
const probe = probeRun(ctx.projectRoot, resolved.name, projectName);
|
|
163
|
+
if (probe.status === "live") throw new Error(`${resolved.name} is already running (pid ${probe.record.pid}).`);
|
|
164
|
+
const attachment = await attachRemoteReactor({
|
|
165
|
+
url: await resolveRemoteUrl(resolved, ctx),
|
|
166
|
+
documentModels: []
|
|
167
|
+
});
|
|
168
|
+
console.log(`[${resolved.name}] reactor attached: ${attachment.endpoint}`);
|
|
169
|
+
let provider;
|
|
170
|
+
if (config.model) provider = await createMastraProvider({
|
|
171
|
+
agentName: resolved.name,
|
|
172
|
+
instructions: config.instructions ?? `You are ${resolved.name}, a Powerhouse project agent.`,
|
|
173
|
+
model: config.model
|
|
174
|
+
});
|
|
175
|
+
else provider = createDemoProvider(resolved.name);
|
|
176
|
+
const server = createServer((req, res) => {
|
|
177
|
+
(async () => {
|
|
178
|
+
const url = (req.url ?? "/").split("?")[0];
|
|
179
|
+
if (req.method === "GET" && url === "/ready") {
|
|
180
|
+
res.writeHead(200, { "content-type": "application/json" });
|
|
181
|
+
res.end(JSON.stringify({
|
|
182
|
+
ok: true,
|
|
183
|
+
agent: resolved.name
|
|
184
|
+
}));
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (req.method === "GET" && url === "/v1/models") {
|
|
188
|
+
res.writeHead(200, { "content-type": "application/json" });
|
|
189
|
+
res.end(JSON.stringify({
|
|
190
|
+
object: "list",
|
|
191
|
+
data: [{
|
|
192
|
+
id: provider.modelId,
|
|
193
|
+
object: "model",
|
|
194
|
+
owned_by: "clint"
|
|
195
|
+
}]
|
|
196
|
+
}));
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (req.method === "POST" && url === "/v1/chat/completions") {
|
|
200
|
+
let body;
|
|
201
|
+
try {
|
|
202
|
+
body = JSON.parse(await readBody(req));
|
|
203
|
+
} catch {
|
|
204
|
+
res.writeHead(400, { "content-type": "application/json" });
|
|
205
|
+
res.end(JSON.stringify({ error: { message: "invalid JSON body" } }));
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const prompt = promptFromMessages(body.messages ?? []);
|
|
209
|
+
const id = `chatcmpl-${randomUUID()}`;
|
|
210
|
+
const threadId = randomUUID();
|
|
211
|
+
if (body.stream) {
|
|
212
|
+
res.writeHead(200, {
|
|
213
|
+
"content-type": "text/event-stream",
|
|
214
|
+
"cache-control": "no-store",
|
|
215
|
+
connection: "keep-alive"
|
|
216
|
+
});
|
|
217
|
+
res.write(completionChunk(id, provider.modelId, { role: "assistant" }, null));
|
|
218
|
+
try {
|
|
219
|
+
for await (const chunk of provider.stream(prompt, { threadId })) if (chunk.type === "text-delta" && chunk.text) res.write(completionChunk(id, provider.modelId, { content: chunk.text }, null));
|
|
220
|
+
else if (chunk.type === "error") res.write(completionChunk(id, provider.modelId, { content: `\n[agent error] ${String(chunk.message ?? "unknown")}` }, null));
|
|
221
|
+
res.write(completionChunk(id, provider.modelId, {}, "stop"));
|
|
222
|
+
res.write("data: [DONE]\n\n");
|
|
223
|
+
} finally {
|
|
224
|
+
res.end();
|
|
225
|
+
}
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
let text = "";
|
|
229
|
+
for await (const chunk of provider.stream(prompt, { threadId })) if (chunk.type === "text-delta" && chunk.text) text += chunk.text;
|
|
230
|
+
res.writeHead(200, { "content-type": "application/json" });
|
|
231
|
+
res.end(JSON.stringify({
|
|
232
|
+
id,
|
|
233
|
+
object: "chat.completion",
|
|
234
|
+
created: Math.floor(Date.now() / 1e3),
|
|
235
|
+
model: provider.modelId,
|
|
236
|
+
choices: [{
|
|
237
|
+
index: 0,
|
|
238
|
+
message: {
|
|
239
|
+
role: "assistant",
|
|
240
|
+
content: text
|
|
241
|
+
},
|
|
242
|
+
finish_reason: "stop"
|
|
243
|
+
}]
|
|
244
|
+
}));
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
res.writeHead(404, { "content-type": "application/json" });
|
|
248
|
+
res.end(JSON.stringify({ error: { message: `no route: ${url}` } }));
|
|
249
|
+
})().catch((error) => {
|
|
250
|
+
if (!res.headersSent) res.writeHead(500);
|
|
251
|
+
res.end(JSON.stringify({ error: { message: String(error) } }));
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
const ready = new Promise((resolve, reject) => {
|
|
255
|
+
server.once("error", reject);
|
|
256
|
+
server.listen(port, "127.0.0.1", () => resolve());
|
|
257
|
+
});
|
|
258
|
+
await ready;
|
|
259
|
+
const boundPort = server.address().port;
|
|
260
|
+
console.log(`[${resolved.name}] agent API (OpenAI-compatible): http://127.0.0.1:${boundPort}/v1 (model: ${provider.modelId})`);
|
|
261
|
+
writeRunRecord(ctx.projectRoot, {
|
|
262
|
+
pid: process.pid,
|
|
263
|
+
hostName: resolved.name,
|
|
264
|
+
projectName,
|
|
265
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
266
|
+
members: { [resolved.name]: {
|
|
267
|
+
port: boundPort,
|
|
268
|
+
url: `http://127.0.0.1:${boundPort}/v1`
|
|
269
|
+
} },
|
|
270
|
+
extra: {
|
|
271
|
+
reactor: attachment.endpoint,
|
|
272
|
+
model: provider.modelId
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
const cleanup = () => clearRunRecord(ctx.projectRoot, resolved.name);
|
|
276
|
+
process.once("exit", cleanup);
|
|
277
|
+
return {
|
|
278
|
+
port: boundPort,
|
|
279
|
+
endpoints: {
|
|
280
|
+
openai: `http://127.0.0.1:${boundPort}/v1`,
|
|
281
|
+
ready: `http://127.0.0.1:${boundPort}/ready`
|
|
282
|
+
},
|
|
283
|
+
ready,
|
|
284
|
+
shutdown: async () => {
|
|
285
|
+
cleanup();
|
|
286
|
+
await new Promise((resolve) => server.close(resolve));
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
async function run(host, ctx) {
|
|
291
|
+
return serveAgent(host, ctx);
|
|
292
|
+
}
|
|
293
|
+
const serve = run;
|
|
294
|
+
/** `build` — skill + agent-profile compilation (ph-clint-dev's pipeline). */
|
|
295
|
+
async function build(host, ctx) {
|
|
296
|
+
const config = host.config ?? {};
|
|
297
|
+
const { buildSkills } = await import("../build-skills-C1Vr_kQh.mjs");
|
|
298
|
+
const result = await buildSkills({
|
|
299
|
+
rootDir: ctx.projectRoot,
|
|
300
|
+
skillsDir: config.prompts?.skillsDir,
|
|
301
|
+
agentsDir: config.prompts?.agentsDir,
|
|
302
|
+
outDir: config.prompts?.outDir
|
|
303
|
+
});
|
|
304
|
+
console.log(`[${host.name}] compiled ${result.skills} skill(s), ${result.profiles} profile(s) → ${result.outDir}`);
|
|
305
|
+
}
|
|
306
|
+
//#endregion
|
|
307
|
+
export { build, hostSchema, kind, promptFromMessages, run, serve };
|
|
308
|
+
|
|
309
|
+
//# sourceMappingURL=mastra-runner.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mastra-runner.mjs","names":[],"sources":["../../src/integrations/powerhouse/remote-reactor.ts","../../src/runners/agent-provider.ts","../../src/runners/mastra-runner.ts"],"sourcesContent":["import type { DocumentModelModule } from \"@powerhousedao/shared/document-model\";\nimport type { ReactorProtocol } from \"@powerhousedao/host-core\";\n\n/**\n * P5.5 — the agent host's reactor is a REMOTE attach: a running switchboard,\n * reached over GraphQL, instead of the embedded PGlite reactor glued to the\n * CLI's lifetime. N agents attach to ONE reactor as clients; the switchboard\n * outlives agent sessions. The agent DEPENDS on the switchboard — an\n * unreachable remote fails the attach loudly with the start hint, it never\n * auto-starts one.\n */\n\nexport interface AttachRemoteReactorOptions {\n /**\n * Where the switchboard lives: its GraphQL endpoint\n * (`http://localhost:4001/graphql`), a drive url (`…/d/<drive>`), or a bare\n * origin — the endpoint is derived.\n */\n url: string;\n /** Document models the client signs/reduces with. */\n documentModels: DocumentModelModule[];\n /**\n * What this agent expects of the fleet it joins (the host file's\n * reactor.protocol). Reachability and inspection facts are checked at\n * attach; flag-level comparison engages once the inspection subgraph\n * exposes the enforcement flags (upstream note in the phase-5 WBS) — until\n * then the expectation is carried for the error message and future use.\n */\n expectedProtocol?: ReactorProtocol;\n /** Bearer for authenticated switchboards; omitted = unauthenticated. */\n token?: string;\n /** Reachability probe budget. */\n timeoutMs?: number;\n}\n\nexport interface RemoteReactorAttachment {\n /** The derived GraphQL endpoint actually dialed. */\n endpoint: string;\n /** IReactorClient-compatible GraphQL client (reactor-browser). */\n client: unknown;\n /** Remote facts from the inspection subgraph, when it answers. */\n remoteInfo?: Record<string, unknown>;\n}\n\n/** Derive the GraphQL endpoint from the accepted url spellings. */\nexport function deriveGraphqlEndpoint(url: string): string {\n const parsed = new URL(url);\n if (parsed.pathname.includes(\"/d/\")) {\n return `${parsed.origin}/graphql`;\n }\n if (parsed.pathname.replace(/\\/$/, \"\").endsWith(\"/graphql\")) {\n return `${parsed.origin}${parsed.pathname.replace(/\\/$/, \"\")}`;\n }\n const base = parsed.pathname.replace(/\\/$/, \"\");\n return `${parsed.origin}${base}/graphql`;\n}\n\nasync function probeEndpoint(\n endpoint: string,\n timeoutMs: number,\n): Promise<void> {\n try {\n // A GraphQL endpoint answers POST; any HTTP response (even 400) proves\n // the server is listening. Only transport failure means unreachable.\n await fetch(endpoint, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ query: \"{ __typename }\" }),\n signal: AbortSignal.timeout(timeoutMs),\n });\n } catch (cause) {\n throw new Error(\n `Cannot attach to the reactor at ${endpoint}: the switchboard is not ` +\n `answering. The agent depends on a RUNNING switchboard and never ` +\n `starts one — start it first (e.g. \\`ph run switchboard\\`, ` +\n `\\`ph vetra\\`, or the compound that members both) and retry.`,\n { cause },\n );\n }\n}\n\n/** Read the inspection subgraph's info when it answers (dev switchboards\n * under the OPEN policy serve it); absence is not an attach failure. */\nasync function readRemoteInfo(\n endpoint: string,\n token: string | undefined,\n timeoutMs: number,\n): Promise<Record<string, unknown> | undefined> {\n try {\n const res = await fetch(`${endpoint}/inspection`, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n ...(token ? { authorization: `Bearer ${token}` } : {}),\n },\n body: JSON.stringify({\n query: \"query ReactorInspectionInfo { inspection { info } }\",\n }),\n signal: AbortSignal.timeout(timeoutMs),\n });\n if (!res.ok) return undefined;\n const body = (await res.json()) as {\n data?: { inspection?: { info?: Record<string, unknown> } };\n };\n return body.data?.inspection?.info;\n } catch {\n return undefined;\n }\n}\n\nexport async function attachRemoteReactor(\n options: AttachRemoteReactorOptions,\n): Promise<RemoteReactorAttachment> {\n const timeoutMs = options.timeoutMs ?? 10_000;\n const endpoint = deriveGraphqlEndpoint(options.url);\n\n await probeEndpoint(endpoint, timeoutMs);\n const remoteInfo = await readRemoteInfo(endpoint, options.token, timeoutMs);\n\n const { GraphQLReactorClient } =\n await import(\"@powerhousedao/reactor-browser/graphql-client\");\n const client = new GraphQLReactorClient({\n url: endpoint,\n documentModels: options.documentModels,\n ...(options.token\n ? { tokenProvider: () => Promise.resolve(options.token) }\n : {}),\n } as never);\n\n return { endpoint, client, remoteInfo };\n}\n","import type { StreamChunk } from \"../core/types.js\";\n\n/**\n * The mastra-runner's provider seam: a real Mastra agent when a model is\n * configured, and a DEMO provider otherwise — same posture as the ph-rupert\n * example: the host answers without an API key, loudly saying it is the demo.\n */\nexport interface AgentStreamProvider {\n readonly modelId: string;\n stream(\n prompt: string,\n options: { threadId: string },\n ): AsyncIterable<StreamChunk>;\n}\n\nexport function createDemoProvider(agentName: string): AgentStreamProvider {\n return {\n modelId: \"demo\",\n // eslint-disable-next-line require-yield -- single-chunk generator below\n async *stream(prompt: string) {\n const text =\n `You said: ${JSON.stringify(prompt.slice(0, 2000))}. ` +\n `I'm the ${agentName} demo agent — configure a model (host config ` +\n `\\`model\\`, provider API key in the environment) for real responses.`;\n yield { type: \"text-delta\", text } as StreamChunk;\n },\n };\n}\n\nexport interface MastraProviderOptions {\n agentName: string;\n instructions: string;\n /** Mastra model-router string, e.g. `anthropic/claude-sonnet-4-5`. */\n model: string;\n}\n\nexport async function createMastraProvider(\n options: MastraProviderOptions,\n): Promise<AgentStreamProvider> {\n const { Agent } = await import(\"@mastra/core/agent\");\n const { mapMastraStream } = await import(\"../integrations/mastra/stream.js\");\n const agent = new Agent({\n id: options.agentName,\n name: options.agentName,\n instructions: options.instructions,\n // Mastra's model router resolves provider/key from the environment.\n model: options.model as never,\n });\n return {\n modelId: options.model,\n async *stream(prompt: string, streamOptions: { threadId: string }) {\n const result = await agent.stream(prompt, {\n memory: undefined,\n threadId: streamOptions.threadId,\n } as never);\n yield* mapMastraStream(\n (result as { fullStream: AsyncIterable<unknown> }).fullStream as never,\n );\n },\n };\n}\n","import { randomUUID } from \"node:crypto\";\nimport fs from \"node:fs\";\nimport { createServer, type Server } from \"node:http\";\nimport {\n defaultUserDataDir,\n loadHost,\n probeRun,\n reactorHostSchema,\n resolveUserDataPlaceholders,\n writeRunRecord,\n clearRunRecord,\n type HostDefinition,\n type ReactorConfig,\n type RunnerContext,\n} from \"@powerhousedao/host-core\";\nimport {\n attachRemoteReactor,\n type RemoteReactorAttachment,\n} from \"../integrations/powerhouse/remote-reactor.js\";\nimport {\n createDemoProvider,\n createMastraProvider,\n type AgentStreamProvider,\n} from \"./agent-provider.js\";\n\n/**\n * mastra-runner (P5.6): the headless agent host. Its reactor is a REMOTE\n * attach — a lone `remote` backend naming a running switchboard (by sibling\n * host reference or URL); it depends on that switchboard and never starts\n * one. `run`/`serve` expose an OpenAI-compatible chat-completions endpoint\n * (streaming SSE + non-streaming, stateless baseline — the caller owns\n * session state); without a configured model it answers as the DEMO agent.\n * `build` compiles skills and agent profiles (ph-clint-dev's pipeline,\n * ported).\n */\n\nexport const kind = \"reactor\";\n\nexport const hostSchema = reactorHostSchema;\n\ninterface AgentHostConfig {\n model?: string;\n instructions?: string;\n prompts?: {\n skillsDir?: string;\n agentsDir?: string;\n outDir?: string;\n };\n}\n\nconst DEFAULT_AGENT_PORT = 4910;\n\n/** Resolve the remote backend's switchboard url: `remote.url` as given, or a\n * sibling host reference (`remote.host`) whose runner.port names the port. */\nasync function resolveRemoteUrl(\n host: HostDefinition,\n ctx: RunnerContext,\n): Promise<string> {\n const reactor = host.reactor as ReactorConfig | undefined;\n const backends = Object.entries(reactor?.backends ?? {});\n const remote = backends.find(([, b]) => b.kind === \"remote\")?.[1];\n if (!remote) {\n throw new Error(\n `hosts/${host.name}: an agent host attaches to a RUNNING switchboard — ` +\n `declare a remote backend, e.g. reactor.backends.switchboard = ` +\n `{ kind: \"remote\", remote: { host: \"switchboard\" } }.`,\n );\n }\n const ref = remote.remote as { url?: string; host?: string } | undefined;\n if (ref?.url) return ref.url;\n if (ref?.host) {\n const sibling = await loadHost(ctx.projectRoot, ref.host);\n const port = sibling.host.runner.port;\n if (typeof port !== \"number\") {\n throw new Error(\n `hosts/${host.name}: sibling host \"${ref.host}\" declares no ` +\n `runner.port to derive the switchboard endpoint from — set one, or ` +\n `use remote.url.`,\n );\n }\n return `http://localhost:${port}/graphql`;\n }\n throw new Error(\n `hosts/${host.name}: the remote backend needs remote.url or a sibling ` +\n `remote.host reference.`,\n );\n}\n\ntype ChatMessage = { role: string; content: unknown };\n\n/** Baseline stateless mapping: the last user message is the prompt (string\n * or OpenAI content-part arrays flattened to their text parts). */\nexport function promptFromMessages(messages: ChatMessage[]): string {\n const lastUser = [...messages].reverse().find((m) => m.role === \"user\");\n const content = lastUser?.content;\n if (typeof content === \"string\") return content;\n if (Array.isArray(content)) {\n return content\n .map((part: { type?: string; text?: string }) =>\n part.type === \"text\" ? (part.text ?? \"\") : \"\",\n )\n .join(\"\");\n }\n return \"\";\n}\n\nasync function readBody(\n req: import(\"node:http\").IncomingMessage,\n): Promise<string> {\n const chunks: Buffer[] = [];\n for await (const chunk of req) chunks.push(chunk as Buffer);\n return Buffer.concat(chunks).toString(\"utf8\");\n}\n\nfunction completionChunk(\n id: string,\n model: string,\n delta: Record<string, unknown>,\n finish: string | null,\n): string {\n return `data: ${JSON.stringify({\n id,\n object: \"chat.completion.chunk\",\n created: Math.floor(Date.now() / 1000),\n model,\n choices: [{ index: 0, delta, finish_reason: finish }],\n })}\\n\\n`;\n}\n\nexport interface AgentServeHandle {\n port: number;\n endpoints: Record<string, string>;\n ready: Promise<void>;\n shutdown: () => Promise<void>;\n}\n\nasync function serveAgent(\n host: HostDefinition,\n ctx: RunnerContext,\n): Promise<AgentServeHandle> {\n const userData = defaultUserDataDir(ctx.projectRoot, ctx.env);\n const resolved = resolveUserDataPlaceholders(host, userData);\n const config = (resolved.config ?? {}) as AgentHostConfig;\n const port =\n typeof resolved.runner.port === \"number\"\n ? resolved.runner.port\n : DEFAULT_AGENT_PORT;\n\n // Single-instance lock, standalone-run parity with the compound.\n const projectName = (() => {\n try {\n return (\n (\n JSON.parse(\n fs.readFileSync(`${ctx.projectRoot}/package.json`, \"utf8\"),\n ) as { name?: string }\n ).name ?? host.name\n );\n } catch {\n return host.name;\n }\n })();\n const probe = probeRun(ctx.projectRoot, resolved.name, projectName);\n if (probe.status === \"live\") {\n throw new Error(\n `${resolved.name} is already running (pid ${probe.record.pid}).`,\n );\n }\n\n // The reactor: attach, loudly, before serving anything.\n const remoteUrl = await resolveRemoteUrl(resolved, ctx);\n const attachment: RemoteReactorAttachment = await attachRemoteReactor({\n url: remoteUrl,\n documentModels: [],\n });\n console.log(`[${resolved.name}] reactor attached: ${attachment.endpoint}`);\n\n // The agent: real Mastra when a model is configured, demo otherwise.\n let provider: AgentStreamProvider;\n if (config.model) {\n provider = await createMastraProvider({\n agentName: resolved.name,\n instructions:\n config.instructions ??\n `You are ${resolved.name}, a Powerhouse project agent.`,\n model: config.model,\n });\n } else {\n provider = createDemoProvider(resolved.name);\n }\n\n const server: Server = createServer((req, res) => {\n void (async () => {\n const url = (req.url ?? \"/\").split(\"?\")[0];\n if (req.method === \"GET\" && url === \"/ready\") {\n res.writeHead(200, { \"content-type\": \"application/json\" });\n res.end(JSON.stringify({ ok: true, agent: resolved.name }));\n return;\n }\n if (req.method === \"GET\" && url === \"/v1/models\") {\n res.writeHead(200, { \"content-type\": \"application/json\" });\n res.end(\n JSON.stringify({\n object: \"list\",\n data: [\n { id: provider.modelId, object: \"model\", owned_by: \"clint\" },\n ],\n }),\n );\n return;\n }\n if (req.method === \"POST\" && url === \"/v1/chat/completions\") {\n let body: { messages?: ChatMessage[]; stream?: boolean };\n try {\n body = JSON.parse(await readBody(req)) as typeof body;\n } catch {\n res.writeHead(400, { \"content-type\": \"application/json\" });\n res.end(JSON.stringify({ error: { message: \"invalid JSON body\" } }));\n return;\n }\n const prompt = promptFromMessages(body.messages ?? []);\n const id = `chatcmpl-${randomUUID()}`;\n const threadId = randomUUID(); // stateless baseline: the caller owns sessions\n\n if (body.stream) {\n res.writeHead(200, {\n \"content-type\": \"text/event-stream\",\n \"cache-control\": \"no-store\",\n connection: \"keep-alive\",\n });\n res.write(\n completionChunk(id, provider.modelId, { role: \"assistant\" }, null),\n );\n try {\n for await (const chunk of provider.stream(prompt, { threadId })) {\n if (chunk.type === \"text-delta\" && chunk.text) {\n res.write(\n completionChunk(\n id,\n provider.modelId,\n { content: chunk.text },\n null,\n ),\n );\n } else if (chunk.type === \"error\") {\n res.write(\n completionChunk(\n id,\n provider.modelId,\n {\n content: `\\n[agent error] ${String((chunk as { message?: unknown }).message ?? \"unknown\")}`,\n },\n null,\n ),\n );\n }\n }\n res.write(completionChunk(id, provider.modelId, {}, \"stop\"));\n res.write(\"data: [DONE]\\n\\n\");\n } finally {\n res.end();\n }\n return;\n }\n\n let text = \"\";\n for await (const chunk of provider.stream(prompt, { threadId })) {\n if (chunk.type === \"text-delta\" && chunk.text) text += chunk.text;\n }\n res.writeHead(200, { \"content-type\": \"application/json\" });\n res.end(\n JSON.stringify({\n id,\n object: \"chat.completion\",\n created: Math.floor(Date.now() / 1000),\n model: provider.modelId,\n choices: [\n {\n index: 0,\n message: { role: \"assistant\", content: text },\n finish_reason: \"stop\",\n },\n ],\n }),\n );\n return;\n }\n res.writeHead(404, { \"content-type\": \"application/json\" });\n res.end(JSON.stringify({ error: { message: `no route: ${url}` } }));\n })().catch((error: unknown) => {\n if (!res.headersSent) res.writeHead(500);\n res.end(JSON.stringify({ error: { message: String(error) } }));\n });\n });\n\n const ready = new Promise<void>((resolve, reject) => {\n server.once(\"error\", reject);\n server.listen(port, \"127.0.0.1\", () => resolve());\n });\n await ready;\n // The actual bound port (a requested 0 means \"any free port\").\n const boundPort = (server.address() as { port: number }).port;\n console.log(\n `[${resolved.name}] agent API (OpenAI-compatible): http://127.0.0.1:${boundPort}/v1 (model: ${provider.modelId})`,\n );\n\n writeRunRecord(ctx.projectRoot, {\n pid: process.pid,\n hostName: resolved.name,\n projectName,\n startedAt: new Date().toISOString(),\n members: {\n [resolved.name]: {\n port: boundPort,\n url: `http://127.0.0.1:${boundPort}/v1`,\n },\n },\n extra: { reactor: attachment.endpoint, model: provider.modelId },\n });\n const cleanup = () => clearRunRecord(ctx.projectRoot, resolved.name);\n process.once(\"exit\", cleanup);\n\n return {\n port: boundPort,\n endpoints: {\n openai: `http://127.0.0.1:${boundPort}/v1`,\n ready: `http://127.0.0.1:${boundPort}/ready`,\n },\n ready,\n shutdown: async () => {\n cleanup();\n await new Promise((resolve) => server.close(resolve));\n },\n };\n}\n\nexport async function run(\n host: HostDefinition,\n ctx: RunnerContext,\n): Promise<AgentServeHandle> {\n return serveAgent(host, ctx);\n}\n\nexport const serve = run;\n\n/** `build` — skill + agent-profile compilation (ph-clint-dev's pipeline). */\nexport async function build(\n host: HostDefinition,\n ctx: RunnerContext,\n): Promise<void> {\n const config = (host.config ?? {}) as AgentHostConfig;\n const { buildSkills } = await import(\"../dev/build-skills.js\");\n const result = await buildSkills({\n rootDir: ctx.projectRoot,\n skillsDir: config.prompts?.skillsDir,\n agentsDir: config.prompts?.agentsDir,\n outDir: config.prompts?.outDir,\n });\n console.log(\n `[${host.name}] compiled ${result.skills} skill(s), ${result.profiles} profile(s) → ${result.outDir}`,\n );\n}\n"],"mappings":";;;;;;AA6CA,SAAgB,sBAAsB,KAAqB;CACzD,MAAM,SAAS,IAAI,IAAI,GAAG;CAC1B,IAAI,OAAO,SAAS,SAAS,KAAK,GAChC,OAAO,GAAG,OAAO,OAAO;CAE1B,IAAI,OAAO,SAAS,QAAQ,OAAO,EAAE,CAAC,CAAC,SAAS,UAAU,GACxD,OAAO,GAAG,OAAO,SAAS,OAAO,SAAS,QAAQ,OAAO,EAAE;CAE7D,MAAM,OAAO,OAAO,SAAS,QAAQ,OAAO,EAAE;CAC9C,OAAO,GAAG,OAAO,SAAS,KAAK;AACjC;AAEA,eAAe,cACb,UACA,WACe;CACf,IAAI;EAGF,MAAM,MAAM,UAAU;GACpB,QAAQ;GACR,SAAS,EAAE,gBAAgB,mBAAmB;GAC9C,MAAM,KAAK,UAAU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