@rivus/agent 0.16.2 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/LICENSE +669 -17
  2. package/README.md +25 -1080
  3. package/dist/cli.d.ts +1 -1
  4. package/dist/cli.js +12 -1234
  5. package/dist/index.d.ts +3 -7
  6. package/dist/index.js +3 -8
  7. package/dist/testing/index.d.ts +21 -50
  8. package/dist/testing/index.js +58 -89
  9. package/package.json +40 -104
  10. package/dist/acp.d.ts +0 -144
  11. package/dist/acp.js +0 -768
  12. package/dist/bootstrap/pi-feishu.d.ts +0 -20
  13. package/dist/bootstrap/pi-feishu.js +0 -4341
  14. package/dist/chunks/agent-loop.d.ts +0 -446
  15. package/dist/chunks/agent-loop.js +0 -158
  16. package/dist/chunks/background-session-authority.js +0 -230
  17. package/dist/chunks/background-session-control-input.js +0 -51
  18. package/dist/chunks/background-session-service.d.ts +0 -382
  19. package/dist/chunks/index.d.ts +0 -4448
  20. package/dist/chunks/pi-tool-proxy.d.ts +0 -120
  21. package/dist/chunks/pi.js +0 -406
  22. package/dist/chunks/rivus-agent-definition-resolver.js +0 -508
  23. package/dist/chunks/rivus-daemon-cli.js +0 -3839
  24. package/dist/chunks/rivus-model-management-wire.js +0 -344
  25. package/dist/chunks/rivus-plugin-testkit.d.ts +0 -214
  26. package/dist/chunks/rivus-plugin-testkit.js +0 -78
  27. package/dist/chunks/rivus-skill.d.ts +0 -95
  28. package/dist/chunks/rivus-tool.js +0 -158
  29. package/dist/chunks/sha256-digest.js +0 -7
  30. package/dist/chunks/src.js +0 -15313
  31. package/dist/mcp.d.ts +0 -92
  32. package/dist/mcp.js +0 -454
  33. package/dist/pi.d.ts +0 -129
  34. package/dist/pi.js +0 -3
  35. package/examples/a-share-briefing-analysis.mjs +0 -93
  36. package/examples/a-share-briefing-renderer.mjs +0 -257
  37. package/examples/a-share-index-evidence.mjs +0 -99
  38. package/examples/a-share-market-briefing.mjs +0 -83
  39. package/examples/a-share-market-date.mjs +0 -10
  40. package/examples/a-share-overseas-evidence.mjs +0 -86
  41. package/examples/a-share-policy-evidence.mjs +0 -145
  42. package/examples/a-share-provider-response.mjs +0 -21
  43. package/examples/a-share-sector-evidence.mjs +0 -70
  44. package/examples/acp-stdio-proxy.mjs +0 -58
  45. package/examples/current-weather.mjs +0 -117
  46. package/examples/html-drive-tools.mjs +0 -262
  47. package/examples/https-response-reader.mjs +0 -36
  48. package/examples/langfuse-drive-e2e.mjs +0 -175
  49. package/examples/pi-feishu-deployment.bootstrap.ts +0 -894
  50. package/examples/pi-feishu.bootstrap.ts +0 -242
  51. package/examples/rivus-agents.plugin.mjs +0 -290
  52. package/examples/rivus-langfuse-demo.config.json +0 -37
  53. package/examples/rivus-starter.plugin.mjs +0 -47
  54. package/examples/rivus.config.json +0 -114
  55. package/skills/runtime-management/SKILL.md +0 -65
package/dist/mcp.d.ts DELETED
@@ -1,92 +0,0 @@
1
- import { A as BackgroundSessionAuthority, r as BackgroundSessionService } from "./chunks/background-session-service.js";
2
- import { Readable, Writable } from "node:stream";
3
-
4
- //#region src/bootstrap/mcp/rivus-mcp-entrypoint.d.ts
5
- interface RunBackgroundSessionMcpServerEnv {
6
- readonly fetch?: typeof fetch;
7
- readonly input?: Readable;
8
- readonly output?: Writable;
9
- }
10
- declare function runBackgroundSessionMcpServer(options?: RunBackgroundSessionMcpServerEnv): Promise<void>;
11
- //#endregion
12
- //#region src/core/application/background-session/control/background-session-control.d.ts
13
- type BackgroundSessionControlCommand = "start" | "wait" | "list" | "status" | "send" | "stop";
14
- interface BackgroundSessionControlOrigin {
15
- readonly allowedActorOpenIds: ReadonlyArray<string>;
16
- readonly conversationId?: string;
17
- readonly endpointId: string;
18
- readonly tenantKey: string;
19
- }
20
- interface BackgroundSessionControlContext {
21
- readonly agentId: string;
22
- readonly authority: BackgroundSessionAuthority;
23
- readonly origin: BackgroundSessionControlOrigin;
24
- readonly policyEpoch: number;
25
- readonly runId: string;
26
- readonly sessionKey: string;
27
- readonly sourceMessageId: string;
28
- }
29
- interface BackgroundSessionControl {
30
- handle(command: BackgroundSessionControlCommand, context: BackgroundSessionControlContext, input: unknown): Promise<unknown>;
31
- }
32
- declare class BackgroundSessionControlError extends Error {
33
- readonly name = "BackgroundSessionControlError";
34
- }
35
- //#endregion
36
- //#region src/adapters/mcp/background-session/background-session-mcp-server.d.ts
37
- declare const BACKGROUND_SESSION_MCP_SERVER_NAME = "rivus-background-sessions";
38
- declare const BACKGROUND_SESSION_MCP_SERVER_VERSION = "1.0.0";
39
- interface BackgroundSessionMcpServerOptions {
40
- readonly capability: string;
41
- readonly controlUrl: string;
42
- readonly controlToken: string;
43
- readonly enabledTools?: ReadonlyArray<BackgroundSessionControlCommand>;
44
- readonly fetch?: typeof fetch;
45
- readonly input?: Readable;
46
- readonly output?: Writable;
47
- readonly serverName?: string;
48
- readonly serverVersion?: string;
49
- }
50
- interface BackgroundSessionMcpServer {
51
- run(): Promise<void>;
52
- }
53
- declare class BackgroundSessionMcpError extends Error {
54
- readonly name = "BackgroundSessionMcpError";
55
- }
56
- declare function createBackgroundSessionMcpServer(options: BackgroundSessionMcpServerOptions): BackgroundSessionMcpServer;
57
- //#endregion
58
- //#region src/adapters/compatibility/background-session/control.d.ts
59
- declare function createBackgroundSessionControl(options: {
60
- readonly service: BackgroundSessionService;
61
- }): BackgroundSessionControl;
62
- declare function toControlContext(input: {
63
- readonly agentId: string;
64
- readonly authority: BackgroundSessionAuthority;
65
- readonly origin: BackgroundSessionControlOrigin;
66
- readonly policyEpoch: number;
67
- readonly sessionKey: string;
68
- readonly sourceMessageId?: string;
69
- }): BackgroundSessionControlContext;
70
- //#endregion
71
- //#region src/adapters/http/background-session/background-session-control-http-server.d.ts
72
- interface BackgroundSessionControlHttpServerOptions {
73
- readonly control: BackgroundSessionControl;
74
- readonly host?: string;
75
- readonly port: number;
76
- readonly status?: () => unknown;
77
- readonly token: string;
78
- }
79
- interface BackgroundSessionControlHttpServer {
80
- port(): number;
81
- issueCapability(context: BackgroundSessionControlContext): string;
82
- close(): Promise<void>;
83
- start(): Promise<void>;
84
- }
85
- declare class BackgroundSessionControlHttpError extends Error {
86
- readonly statusCode: number;
87
- readonly name = "BackgroundSessionControlHttpError";
88
- constructor(statusCode: number, message: string);
89
- }
90
- declare function createBackgroundSessionControlHttpServer(options: BackgroundSessionControlHttpServerOptions): BackgroundSessionControlHttpServer;
91
- //#endregion
92
- export { BACKGROUND_SESSION_MCP_SERVER_NAME, BACKGROUND_SESSION_MCP_SERVER_VERSION, type BackgroundSessionControl, type BackgroundSessionControlCommand, type BackgroundSessionControlContext, BackgroundSessionControlError, BackgroundSessionControlHttpError, type BackgroundSessionControlHttpServer, type BackgroundSessionControlHttpServerOptions, type BackgroundSessionControlOrigin, BackgroundSessionMcpError, type BackgroundSessionMcpServer, type BackgroundSessionMcpServerOptions, createBackgroundSessionControl, createBackgroundSessionControlHttpServer, createBackgroundSessionMcpServer, runBackgroundSessionMcpServer, toControlContext };
package/dist/mcp.js DELETED
@@ -1,454 +0,0 @@
1
- import { a as readBackgroundSessionWaitInput, i as readBackgroundSessionString, n as readBackgroundSessionObject, o as createRandomId, r as readBackgroundSessionPhase, t as readBackgroundSessionInteger } from "./chunks/background-session-control-input.js";
2
- import { d as createBackgroundSessionKey, o as createBackgroundSessionToolContracts } from "./chunks/background-session-authority.js";
3
- import { randomUUID } from "node:crypto";
4
- import { pathToFileURL } from "node:url";
5
- import { createServer } from "node:http";
6
- //#region src/adapters/mcp/background-session/background-session-mcp-server.ts
7
- const BACKGROUND_SESSION_MCP_SERVER_NAME = "rivus-background-sessions";
8
- const BACKGROUND_SESSION_MCP_SERVER_VERSION = "1.0.0";
9
- var BackgroundSessionMcpError = class extends Error {
10
- name = "BackgroundSessionMcpError";
11
- };
12
- function createBackgroundSessionMcpServer(options) {
13
- const input = options.input ?? process.stdin;
14
- const output = options.output ?? process.stdout;
15
- const fetchImplementation = options.fetch ?? fetch;
16
- const enabledTools = new Set(options.enabledTools ?? [
17
- "start",
18
- "wait",
19
- "list",
20
- "status",
21
- "send",
22
- "stop"
23
- ]);
24
- const tools = createBackgroundSessionToolContracts().filter(({ id }) => enabledTools.has(id.slice(11))).map((contract) => ({
25
- description: contract.description,
26
- inputSchema: contract.inputSchema,
27
- name: contract.id
28
- }));
29
- const serverInfo = {
30
- name: options.serverName ?? "rivus-background-sessions",
31
- version: options.serverVersion ?? "1.0.0"
32
- };
33
- return { run: () => runMcpServer({
34
- capability: options.capability,
35
- controlToken: options.controlToken,
36
- controlUrl: options.controlUrl,
37
- fetchImplementation,
38
- input,
39
- output,
40
- serverInfo,
41
- tools
42
- }) };
43
- }
44
- async function runMcpServer(options) {
45
- const send = (message) => {
46
- const body = JSON.stringify(message);
47
- options.output.write(`${body}\n`);
48
- };
49
- for await (const message of readMcpMessages(options.input)) {
50
- if (!isRecord(message) || !isJsonRpcRequestId(message.id)) continue;
51
- const method = typeof message.method === "string" ? message.method : void 0;
52
- if (!method) continue;
53
- try {
54
- switch (method) {
55
- case "initialize":
56
- send({
57
- jsonrpc: "2.0",
58
- id: message.id,
59
- result: {
60
- capabilities: { tools: { listChanged: false } },
61
- protocolVersion: "2025-03-26",
62
- serverInfo: options.serverInfo
63
- }
64
- });
65
- break;
66
- case "ping":
67
- send({
68
- jsonrpc: "2.0",
69
- id: message.id,
70
- result: {}
71
- });
72
- break;
73
- case "tools/list":
74
- send({
75
- jsonrpc: "2.0",
76
- id: message.id,
77
- result: { tools: options.tools }
78
- });
79
- break;
80
- case "tools/call": {
81
- const params = isRecord(message.params) ? message.params : {};
82
- const name = typeof params.name === "string" ? params.name : "";
83
- const command = name.startsWith("background.") ? name.slice(11) : void 0;
84
- if (!command || !options.tools.some((tool) => tool.name === name)) {
85
- send({
86
- jsonrpc: "2.0",
87
- id: message.id,
88
- error: {
89
- code: -32602,
90
- message: `unknown tool: ${name}`
91
- }
92
- });
93
- break;
94
- }
95
- const response = await options.fetchImplementation(options.controlUrl, {
96
- body: JSON.stringify({
97
- capability: options.capability,
98
- command,
99
- input: params.arguments ?? {}
100
- }),
101
- headers: {
102
- authorization: `Bearer ${options.controlToken}`,
103
- "content-type": "application/json"
104
- },
105
- method: "POST"
106
- });
107
- const envelope = await response.json();
108
- if (!response.ok || envelope.error) {
109
- const messageText = envelope.error?.message ?? `background session control failed with ${response.status}`;
110
- send({
111
- jsonrpc: "2.0",
112
- id: message.id,
113
- error: {
114
- code: -32e3,
115
- message: messageText
116
- }
117
- });
118
- break;
119
- }
120
- send({
121
- jsonrpc: "2.0",
122
- id: message.id,
123
- result: {
124
- content: [{
125
- text: JSON.stringify(envelope.result ?? null),
126
- type: "text"
127
- }],
128
- isError: false
129
- }
130
- });
131
- break;
132
- }
133
- default: send({
134
- jsonrpc: "2.0",
135
- id: message.id,
136
- error: {
137
- code: -32601,
138
- message: `method not found: ${method}`
139
- }
140
- });
141
- }
142
- } catch (error) {
143
- send({
144
- jsonrpc: "2.0",
145
- id: message.id,
146
- error: {
147
- code: -32e3,
148
- message: error instanceof Error ? error.message : String(error)
149
- }
150
- });
151
- }
152
- }
153
- }
154
- async function* readMcpMessages(input) {
155
- let buffer = "";
156
- for await (const chunk of input) {
157
- buffer += chunk.toString("utf8");
158
- let newlineIndex = buffer.indexOf("\n");
159
- while (newlineIndex >= 0) {
160
- const line = buffer.slice(0, newlineIndex).replace(/\r$/, "");
161
- buffer = buffer.slice(newlineIndex + 1);
162
- if (line.trim() !== "") yield parseMcpMessage(line);
163
- newlineIndex = buffer.indexOf("\n");
164
- }
165
- }
166
- if (buffer.trim() !== "") yield parseMcpMessage(buffer.trim());
167
- }
168
- function parseMcpMessage(payload) {
169
- try {
170
- return JSON.parse(payload);
171
- } catch {
172
- throw new BackgroundSessionMcpError("invalid MCP JSON payload");
173
- }
174
- }
175
- function isJsonRpcRequestId(value) {
176
- return value === null || typeof value === "string" || typeof value === "number";
177
- }
178
- function isRecord(value) {
179
- return value !== null && typeof value === "object" && !Array.isArray(value);
180
- }
181
- //#endregion
182
- //#region src/bootstrap/mcp/rivus-mcp-entrypoint.ts
183
- async function runBackgroundSessionMcpServer(options = {}) {
184
- const controlUrl = requireEnv("RIVUS_MCP_CONTROL_URL");
185
- const controlToken = requireEnv("RIVUS_MCP_CONTROL_TOKEN");
186
- const capability = requireEnv("RIVUS_MCP_CAPABILITY");
187
- const enabledTools = optionalEnv("RIVUS_MCP_TOOLS")?.split(",").map((tool) => tool.trim()).filter(Boolean);
188
- await createBackgroundSessionMcpServer({
189
- capability,
190
- controlToken,
191
- controlUrl,
192
- ...enabledTools ? { enabledTools } : {},
193
- ...options.fetch ? { fetch: options.fetch } : {},
194
- ...options.input ? { input: options.input } : {},
195
- ...options.output ? { output: options.output } : {}
196
- }).run();
197
- }
198
- function requireEnv(name) {
199
- const value = process.env[name]?.trim();
200
- if (!value) throw new BackgroundSessionMcpError(`${name} is required`);
201
- return value;
202
- }
203
- function optionalEnv(name) {
204
- return process.env[name]?.trim() || void 0;
205
- }
206
- //#endregion
207
- //#region src/core/application/background-session/control/background-session-control.ts
208
- function createBackgroundSessionControl$1(options) {
209
- return { handle: async (command, context, input) => {
210
- const executionContext = {
211
- agentId: context.agentId,
212
- callId: `mcp-call:${options.createId()}`,
213
- instanceId: `mcp:${context.agentId}`,
214
- policyEpoch: context.policyEpoch,
215
- runId: context.runId,
216
- sessionKey: context.sessionKey,
217
- sourceMessageId: context.sourceMessageId,
218
- toolId: `background.${command}`,
219
- toolVersion: "1.0.0",
220
- origin: toToolOrigin(context.origin)
221
- };
222
- switch (command) {
223
- case "start": {
224
- const { displayName, prompt } = readObject(input, ["displayName", "prompt"]);
225
- if (typeof prompt !== "string" || prompt.trim() === "") throw new BackgroundSessionControlError("background.start requires a non-empty prompt");
226
- const sessionId = `bg-${options.createId()}`;
227
- return options.service.start({
228
- authority: {
229
- ...context.authority,
230
- sessionKey: createBackgroundSessionKey(sessionId)
231
- },
232
- context: executionContext,
233
- ...displayName === void 0 ? {} : { displayName: readString(displayName, "displayName") },
234
- prompt,
235
- sessionId
236
- });
237
- }
238
- case "wait": return options.service.wait({
239
- context: executionContext,
240
- ...readBackgroundSessionWaitInput(input, (message) => new BackgroundSessionControlError(message))
241
- });
242
- case "list": {
243
- const { limit, phase } = readObject(input, ["limit", "phase"]);
244
- return options.service.list({
245
- context: executionContext,
246
- ...limit === void 0 ? {} : { limit: readInteger(limit, "limit") },
247
- ...phase === void 0 ? {} : { phase: readPhase(phase) }
248
- });
249
- }
250
- case "status": {
251
- const { sessionId } = readObject(input, ["sessionId"]);
252
- return options.service.status({
253
- context: executionContext,
254
- sessionId: readString(sessionId, "sessionId")
255
- });
256
- }
257
- case "send": {
258
- const { message, sessionId } = readObject(input, ["message", "sessionId"]);
259
- return options.service.send({
260
- context: executionContext,
261
- message: readString(message, "message"),
262
- sessionId: readString(sessionId, "sessionId")
263
- });
264
- }
265
- case "stop": {
266
- const { reason, sessionId } = readObject(input, ["reason", "sessionId"]);
267
- return options.service.stop({
268
- context: executionContext,
269
- ...reason === void 0 ? {} : { reason: readString(reason, "reason") },
270
- sessionId: readString(sessionId, "sessionId")
271
- });
272
- }
273
- }
274
- } };
275
- }
276
- var BackgroundSessionControlError = class extends Error {
277
- name = "BackgroundSessionControlError";
278
- };
279
- function toControlContext$1(input) {
280
- return {
281
- agentId: input.agentId,
282
- authority: input.authority,
283
- origin: {
284
- allowedActorOpenIds: input.origin.allowedActorOpenIds,
285
- ...input.origin.conversationId === void 0 ? {} : { conversationId: input.origin.conversationId },
286
- endpointId: input.origin.endpointId,
287
- tenantKey: input.origin.tenantKey
288
- },
289
- policyEpoch: input.policyEpoch,
290
- runId: `mcp:${input.createId()}`,
291
- sessionKey: input.sessionKey,
292
- sourceMessageId: input.sourceMessageId ?? `mcp:${input.createId()}`
293
- };
294
- }
295
- function toToolOrigin(origin) {
296
- return {
297
- allowedActorOpenIds: origin.allowedActorOpenIds,
298
- endpointId: origin.endpointId,
299
- tenantKey: origin.tenantKey,
300
- ...origin.conversationId === void 0 ? {} : { conversationId: origin.conversationId }
301
- };
302
- }
303
- function readObject(input, allowed) {
304
- return readBackgroundSessionObject(input, allowed, (message) => new BackgroundSessionControlError(message));
305
- }
306
- function readString(value, name) {
307
- return readBackgroundSessionString(value, name, (message) => new BackgroundSessionControlError(message));
308
- }
309
- function readInteger(value, name) {
310
- return readBackgroundSessionInteger(value, name, (message) => new BackgroundSessionControlError(message));
311
- }
312
- function readPhase(value) {
313
- return readBackgroundSessionPhase(value, (message) => new BackgroundSessionControlError(message));
314
- }
315
- //#endregion
316
- //#region src/adapters/compatibility/background-session/control.ts
317
- function createBackgroundSessionControl(options) {
318
- return createBackgroundSessionControl$1({
319
- createId: createRandomId,
320
- service: options.service
321
- });
322
- }
323
- function toControlContext(input) {
324
- return toControlContext$1({
325
- ...input,
326
- createId: createRandomId
327
- });
328
- }
329
- //#endregion
330
- //#region src/adapters/http/background-session/background-session-control-http-server.ts
331
- var BackgroundSessionControlHttpError = class extends Error {
332
- statusCode;
333
- name = "BackgroundSessionControlHttpError";
334
- constructor(statusCode, message) {
335
- super(message);
336
- this.statusCode = statusCode;
337
- }
338
- };
339
- const COMMANDS = [
340
- "start",
341
- "wait",
342
- "list",
343
- "status",
344
- "send",
345
- "stop"
346
- ];
347
- function createBackgroundSessionControlHttpServer(options) {
348
- let server;
349
- let boundPort = options.port;
350
- const capabilities = /* @__PURE__ */ new Map();
351
- const capabilitiesBySessionKey = /* @__PURE__ */ new Map();
352
- const serverHandle = createServer((request, response) => {
353
- (async () => {
354
- try {
355
- if (request.method === "GET" && request.url === "/background-sessions/status") {
356
- if (request.headers.authorization !== `Bearer ${options.token}`) throw new BackgroundSessionControlHttpError(401, "unauthorized");
357
- respond(response, 200, {
358
- ok: true,
359
- result: options.status?.() ?? null
360
- });
361
- return;
362
- }
363
- if (request.method !== "POST" || request.url !== "/background-sessions") throw new BackgroundSessionControlHttpError(404, "not found");
364
- if (request.headers.authorization !== `Bearer ${options.token}`) throw new BackgroundSessionControlHttpError(401, "unauthorized");
365
- const envelope = parseEnvelope(await readBody(request, 64 * 1024));
366
- const context = capabilities.get(envelope.capability);
367
- if (!context) throw new BackgroundSessionControlHttpError(401, "unknown or expired capability");
368
- const command = envelope.command;
369
- if (!COMMANDS.includes(command)) throw new BackgroundSessionControlHttpError(400, `unsupported background session command: ${String(command)}`);
370
- respond(response, 200, {
371
- ok: true,
372
- result: await options.control.handle(command, context, envelope.input)
373
- });
374
- } catch (error) {
375
- respond(response, error instanceof BackgroundSessionControlHttpError ? error.statusCode : 500, {
376
- error: {
377
- message: error instanceof Error ? error.message : String(error),
378
- name: error instanceof Error ? error.name : "Error"
379
- },
380
- ok: false
381
- });
382
- }
383
- })();
384
- });
385
- serverHandle.on("error", () => void 0);
386
- return {
387
- port: () => boundPort,
388
- close: async () => {
389
- const active = server;
390
- server = void 0;
391
- capabilities.clear();
392
- capabilitiesBySessionKey.clear();
393
- if (active) await new Promise((resolve) => active.close(() => resolve()));
394
- },
395
- issueCapability: (context) => {
396
- const existing = capabilitiesBySessionKey.get(context.sessionKey);
397
- if (existing) return existing;
398
- const capability = randomUUID();
399
- capabilities.set(capability, context);
400
- capabilitiesBySessionKey.set(context.sessionKey, capability);
401
- return capability;
402
- },
403
- start: async () => {
404
- if (server) return;
405
- await new Promise((resolve, reject) => {
406
- server = serverHandle;
407
- serverHandle.listen(options.port, options.host ?? "127.0.0.1", () => {
408
- const address = serverHandle.address();
409
- if (address !== null && typeof address === "object") boundPort = address.port;
410
- resolve();
411
- });
412
- serverHandle.once("error", (error) => {
413
- server = void 0;
414
- reject(error);
415
- });
416
- });
417
- }
418
- };
419
- }
420
- function respond(response, statusCode, body) {
421
- response.writeHead(statusCode, { "content-type": "application/json" });
422
- response.end(JSON.stringify(body));
423
- }
424
- function parseEnvelope(body) {
425
- const parsed = JSON.parse(body);
426
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) throw new BackgroundSessionControlHttpError(400, "invalid background session control envelope");
427
- const record = parsed;
428
- if (typeof record.command !== "string" || typeof record.capability !== "string") throw new BackgroundSessionControlHttpError(400, "background session control envelope requires command and capability");
429
- return {
430
- capability: record.capability,
431
- command: record.command,
432
- input: record.input
433
- };
434
- }
435
- function readBody(request, maxBytes) {
436
- return new Promise((resolve, reject) => {
437
- const chunks = [];
438
- let total = 0;
439
- request.on("data", (chunk) => {
440
- total += chunk.length;
441
- if (total > maxBytes) {
442
- reject(new BackgroundSessionControlHttpError(413, "background session control request too large"));
443
- return;
444
- }
445
- chunks.push(chunk);
446
- });
447
- request.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
448
- });
449
- }
450
- //#endregion
451
- //#region src/mcp.ts
452
- if (pathToFileURL(process.argv[1] ?? "").href === import.meta.url) await runBackgroundSessionMcpServer();
453
- //#endregion
454
- export { BACKGROUND_SESSION_MCP_SERVER_NAME, BACKGROUND_SESSION_MCP_SERVER_VERSION, BackgroundSessionControlError, BackgroundSessionControlHttpError, BackgroundSessionMcpError, createBackgroundSessionControl, createBackgroundSessionControlHttpServer, createBackgroundSessionMcpServer, runBackgroundSessionMcpServer, toControlContext };
package/dist/pi.d.ts DELETED
@@ -1,129 +0,0 @@
1
- import { a as AgentLoopInput } from "./chunks/agent-loop.js";
2
- import { a as RivusRuntimeToolId, d as RivusResolvedToolDescriptor, g as RivusToolGrantSet, t as RegisteredRivusSkill, u as RivusMemoryScope } from "./chunks/rivus-skill.js";
3
- import { a as PiToolResult, c as ToolExecutionRequest, i as PiToolDefinition, n as PiToolApprovalRequest, r as PiToolContent, t as PiToolApprovalGateway } from "./chunks/pi-tool-proxy.js";
4
-
5
- //#region src/adapters/pi/skills/pi-skill-read-tool.d.ts
6
- declare class ProjectSkillReadDenied extends Error {
7
- readonly name = "ProjectSkillReadDenied";
8
- }
9
- declare function createPiSkillReadTool(options: {
10
- readonly cwd: string;
11
- readonly skillPaths: ReadonlyArray<string>;
12
- }): PiToolDefinition;
13
- declare const createPiProjectSkillReadTool: typeof createPiSkillReadTool;
14
- declare function createPiSkillReadTools(options: {
15
- readonly cwd: string;
16
- readonly runtimeToolIds: ReadonlyArray<RivusRuntimeToolId>;
17
- readonly skillPaths: ReadonlyArray<string>;
18
- }): PiToolDefinition[];
19
- //#endregion
20
- //#region src/adapters/pi/skills/pi-skill-tool.d.ts
21
- interface PiSkillReadDetails {
22
- readonly contentLength: number;
23
- readonly digest: string;
24
- readonly skillId: string;
25
- readonly title: string;
26
- readonly version: string;
27
- }
28
- interface PiSkillRuntime {
29
- readonly prompt: string;
30
- readonly tool?: PiToolDefinition<PiSkillReadDetails>;
31
- }
32
- declare function createPiSkillRuntime(skills: ReadonlyArray<RegisteredRivusSkill>): PiSkillRuntime;
33
- //#endregion
34
- //#region src/adapters/pi/skills/pi-skill-catalog.d.ts
35
- interface PiSkillCatalogEntry {
36
- readonly name: string;
37
- }
38
- interface PiSkillCatalogDiagnostic {
39
- readonly message: string;
40
- readonly path?: string;
41
- readonly type: "warning" | "error" | "collision";
42
- }
43
- declare class InvalidPiSkillCatalog extends Error {
44
- readonly name = "InvalidPiSkillCatalog";
45
- }
46
- declare function validatePiSkillCatalog(input: {
47
- readonly diagnostics: ReadonlyArray<PiSkillCatalogDiagnostic>;
48
- readonly skills: ReadonlyArray<PiSkillCatalogEntry>;
49
- }): ReadonlySet<string>;
50
- declare function validatePiSkillCommand(text: string, skillNames: ReadonlySet<string>): void;
51
- //#endregion
52
- //#region src/adapters/pi/skills/pi-skill-sources.d.ts
53
- declare class InvalidPiSkillSource extends Error {
54
- readonly name = "InvalidPiSkillSource";
55
- }
56
- interface ResolvePiSkillSourcesOptions {
57
- readonly agentDir: string;
58
- readonly homeDirectory: string;
59
- readonly projectSkillPaths?: ReadonlyArray<string>;
60
- }
61
- declare function resolvePiSkillSources(options: ResolvePiSkillSourcesOptions): Promise<ReadonlyArray<string>>;
62
- //#endregion
63
- //#region src/adapters/pi/tool-execution/pi-session-tools.d.ts
64
- interface PiNamedTool {
65
- readonly name: string;
66
- }
67
- declare function resolvePiSessionToolNames(runtimeToolIds: ReadonlyArray<RivusRuntimeToolId>, customTools: ReadonlyArray<PiNamedTool>): ReadonlyArray<string>;
68
- //#endregion
69
- //#region src/adapters/pi/tool-execution/pi-bash-tool-options.d.ts
70
- interface PiBashSpawnContext {
71
- command: string;
72
- cwd: string;
73
- env: Record<string, string | undefined>;
74
- }
75
- /** Rivus's Bash configuration boundary, independent of provider UI/model types. */
76
- interface PiBashToolOptions {
77
- commandPrefix?: string;
78
- shellPath?: string;
79
- spawnHook?: (context: PiBashSpawnContext) => PiBashSpawnContext;
80
- }
81
- //#endregion
82
- //#region src/adapters/pi/tool-execution/pi-bash-tool.d.ts
83
- /** Keep Pi's native execution, rendering and abort cleanup with a bounded default. */
84
- declare function createPiBashTool(cwd: string, options?: PiBashToolOptions): PiToolDefinition;
85
- //#endregion
86
- //#region src/adapters/pi/runtime/pi-session-resources.d.ts
87
- interface CreatePiSessionResourcesOptions {
88
- readonly agentDir: string;
89
- readonly appendSystemPromptOverride?: (base: string[]) => string[];
90
- readonly cwd: string;
91
- readonly homeDirectory: string;
92
- readonly projectSkillPaths?: ReadonlyArray<string>;
93
- readonly settingsOverrides?: Readonly<Record<string, unknown>>;
94
- readonly systemPromptOverride?: (base: string | undefined) => string | undefined;
95
- }
96
- interface PiSessionResources {
97
- readonly bashToolOptions?: {
98
- readonly commandPrefix?: string;
99
- readonly shellPath?: string;
100
- };
101
- readonly skillNames: ReadonlySet<string>;
102
- readonly skillPaths: ReadonlyArray<string>;
103
- readonly refresh: () => Promise<void>;
104
- readonly withSessionOptions: <Options extends object>(options: Options) => BoundPiSessionOptions<Options>;
105
- }
106
- type BoundPiSessionOptions<Options extends object> = Omit<Options, "agentDir" | "cwd" | "resourceLoader" | "settingsManager"> & {
107
- readonly agentDir: string;
108
- readonly cwd: string;
109
- };
110
- declare function createPiSessionResources(options: CreatePiSessionResourcesOptions): Promise<PiSessionResources>;
111
- //#endregion
112
- //#region src/adapters/compatibility/agent-execution/pi/pi-tool-proxy.d.ts
113
- interface ToolBroker {
114
- execute(request: ToolExecutionRequest): Promise<unknown>;
115
- }
116
- interface PiToolProxyOptions {
117
- readonly agentId: string;
118
- readonly instanceId: string;
119
- readonly tools: ReadonlyArray<RivusResolvedToolDescriptor>;
120
- readonly toolGrantSet: RivusToolGrantSet;
121
- readonly broker: ToolBroker;
122
- readonly approvals: PiToolApprovalGateway;
123
- readonly getActiveInput: () => AgentLoopInput | undefined;
124
- readonly memoryScopes?: ReadonlyArray<RivusMemoryScope>;
125
- }
126
- declare function createPiToolProxyDefinitions(options: PiToolProxyOptions): PiToolDefinition[];
127
- declare function createPiToolNameResolver(tools: ReadonlyArray<Pick<RivusResolvedToolDescriptor, "id">>): (toolName: string) => string;
128
- //#endregion
129
- export { type CreatePiSessionResourcesOptions, InvalidPiSkillCatalog, InvalidPiSkillSource, type PiBashToolOptions, type PiSessionResources, type PiSkillRuntime, type PiToolApprovalGateway, type PiToolApprovalRequest, type PiToolContent, type PiToolDefinition, type PiToolProxyOptions, type PiToolResult, ProjectSkillReadDenied, type ResolvePiSkillSourcesOptions, createPiBashTool, createPiProjectSkillReadTool, createPiSessionResources, createPiSkillReadTool, createPiSkillReadTools, createPiSkillRuntime, createPiToolNameResolver, createPiToolProxyDefinitions, resolvePiSessionToolNames, resolvePiSkillSources, validatePiSkillCatalog, validatePiSkillCommand };
package/dist/pi.js DELETED
@@ -1,3 +0,0 @@
1
- import { a as InvalidPiSkillSource, c as validatePiSkillCatalog, d as createPiProjectSkillReadTool, f as createPiSkillReadTool, i as resolvePiSessionToolNames, l as validatePiSkillCommand, m as createPiBashTool, n as createPiToolProxyDefinitions, o as resolvePiSkillSources, p as createPiSkillReadTools, r as createPiSessionResources, s as InvalidPiSkillCatalog, t as createPiToolNameResolver, u as ProjectSkillReadDenied } from "./chunks/pi.js";
2
- import { r as createPiSkillRuntime } from "./chunks/rivus-tool.js";
3
- export { InvalidPiSkillCatalog, InvalidPiSkillSource, ProjectSkillReadDenied, createPiBashTool, createPiProjectSkillReadTool, createPiSessionResources, createPiSkillReadTool, createPiSkillReadTools, createPiSkillRuntime, createPiToolNameResolver, createPiToolProxyDefinitions, resolvePiSessionToolNames, resolvePiSkillSources, validatePiSkillCatalog, validatePiSkillCommand };