@rivus/agent 0.14.3 → 0.15.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 (40) hide show
  1. package/README.md +1 -1
  2. package/dist/acp.js +1 -2
  3. package/dist/bootstrap/pi-feishu.d.ts +2 -2
  4. package/dist/bootstrap/pi-feishu.js +4119 -389
  5. package/dist/chunks/agent-loop.d.ts +55 -300
  6. package/dist/chunks/agent-loop.js +3 -1123
  7. package/dist/chunks/background-session-authority.js +230 -0
  8. package/dist/chunks/background-session-control-input.js +51 -0
  9. package/dist/chunks/background-session-service.d.ts +382 -0
  10. package/dist/chunks/index.d.ts +1294 -515
  11. package/dist/chunks/pi-tool-proxy.d.ts +22 -90
  12. package/dist/chunks/pi.js +60 -20
  13. package/dist/chunks/rivus-agent-definition-resolver.js +508 -0
  14. package/dist/chunks/rivus-daemon-cli.js +3004 -3164
  15. package/dist/chunks/rivus-model-management-wire.js +344 -0
  16. package/dist/chunks/rivus-plugin-testkit.d.ts +175 -2
  17. package/dist/chunks/rivus-plugin-testkit.js +11 -4
  18. package/dist/chunks/rivus-skill.d.ts +95 -0
  19. package/dist/chunks/rivus-tool.js +158 -0
  20. package/dist/chunks/sha256-digest.js +2 -7
  21. package/dist/chunks/src.js +13402 -8264
  22. package/dist/cli.js +901 -698
  23. package/dist/index.d.ts +7 -8
  24. package/dist/index.js +8 -9
  25. package/dist/mcp.d.ts +46 -7
  26. package/dist/mcp.js +145 -19
  27. package/dist/pi.d.ts +5 -4
  28. package/dist/pi.js +1 -1
  29. package/examples/pi-feishu-deployment.bootstrap.ts +557 -462
  30. package/package.json +9 -7
  31. package/skills/runtime-management/SKILL.md +61 -0
  32. package/dist/chunks/api.d.ts +0 -70
  33. package/dist/chunks/api.js +0 -471
  34. package/dist/chunks/api2.d.ts +0 -387
  35. package/dist/chunks/api2.js +0 -1331
  36. package/dist/chunks/api3.d.ts +0 -402
  37. package/dist/chunks/module.js +0 -267
  38. package/dist/chunks/pi-skill-tool.js +0 -460
  39. package/dist/chunks/spi.d.ts +0 -1
  40. package/dist/chunks/spi.js +0 -2
package/dist/mcp.js CHANGED
@@ -1,7 +1,8 @@
1
- import { F as createBackgroundSessionControl, I as toControlContext, P as BackgroundSessionControlError, q as createBackgroundSessionToolContracts } from "./chunks/api2.js";
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";
2
3
  import { randomUUID } from "node:crypto";
3
- import { createServer } from "node:http";
4
4
  import { pathToFileURL } from "node:url";
5
+ import { createServer } from "node:http";
5
6
  //#region src/adapters/mcp/background-session/background-session-mcp-server.ts
6
7
  const BACKGROUND_SESSION_MCP_SERVER_NAME = "rivus-background-sessions";
7
8
  const BACKGROUND_SESSION_MCP_SERVER_VERSION = "1.0.0";
@@ -40,21 +41,6 @@ function createBackgroundSessionMcpServer(options) {
40
41
  tools
41
42
  }) };
42
43
  }
43
- async function runBackgroundSessionMcpServer(options = {}) {
44
- const controlUrl = requireEnv("RIVUS_MCP_CONTROL_URL");
45
- const controlToken = requireEnv("RIVUS_MCP_CONTROL_TOKEN");
46
- const capability = requireEnv("RIVUS_MCP_CAPABILITY");
47
- const enabledTools = optionalEnv("RIVUS_MCP_TOOLS")?.split(",").map((tool) => tool.trim()).filter(Boolean);
48
- await createBackgroundSessionMcpServer({
49
- capability,
50
- controlToken,
51
- controlUrl,
52
- ...enabledTools ? { enabledTools } : {},
53
- ...options.fetch ? { fetch: options.fetch } : {},
54
- ...options.input ? { input: options.input } : {},
55
- ...options.output ? { output: options.output } : {}
56
- }).run();
57
- }
58
44
  async function runMcpServer(options) {
59
45
  const send = (message) => {
60
46
  const body = JSON.stringify(message);
@@ -189,6 +175,26 @@ function parseMcpMessage(payload) {
189
175
  function isJsonRpcRequestId(value) {
190
176
  return value === null || typeof value === "string" || typeof value === "number";
191
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
+ }
192
198
  function requireEnv(name) {
193
199
  const value = process.env[name]?.trim();
194
200
  if (!value) throw new BackgroundSessionMcpError(`${name} is required`);
@@ -197,8 +203,128 @@ function requireEnv(name) {
197
203
  function optionalEnv(name) {
198
204
  return process.env[name]?.trim() || void 0;
199
205
  }
200
- function isRecord(value) {
201
- return value !== null && typeof value === "object" && !Array.isArray(value);
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
+ });
202
328
  }
203
329
  //#endregion
204
330
  //#region src/adapters/http/background-session/background-session-control-http-server.ts
package/dist/pi.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { a as AgentLoopInput } from "./chunks/agent-loop.js";
2
- import { d as MemoryScope } from "./chunks/api.js";
3
- import { Q as RivusResolvedToolDescriptor, ft as RivusRuntimeToolId, rt as RivusToolGrantSet, st as RegisteredRivusSkill } from "./chunks/api2.js";
4
- import { a as PiToolResult, i as PiToolDefinition, n as PiToolApprovalRequest, r as PiToolContent, t as PiToolApprovalGateway, u as ToolExecutionRequest } from "./chunks/pi-tool-proxy.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";
5
4
 
6
5
  //#region src/adapters/pi/skills/pi-skill-read-tool.d.ts
7
6
  declare class ProjectSkillReadDenied extends Error {
@@ -74,11 +73,13 @@ interface CreatePiSessionResourcesOptions {
74
73
  readonly cwd: string;
75
74
  readonly homeDirectory: string;
76
75
  readonly projectSkillPaths?: ReadonlyArray<string>;
76
+ readonly settingsOverrides?: Readonly<Record<string, unknown>>;
77
77
  readonly systemPromptOverride?: (base: string | undefined) => string | undefined;
78
78
  }
79
79
  interface PiSessionResources {
80
80
  readonly skillNames: ReadonlySet<string>;
81
81
  readonly skillPaths: ReadonlyArray<string>;
82
+ readonly refresh: () => Promise<void>;
82
83
  readonly withSessionOptions: <Options extends object>(options: Options) => BoundPiSessionOptions<Options>;
83
84
  }
84
85
  type BoundPiSessionOptions<Options extends object> = Omit<Options, "agentDir" | "cwd" | "resourceLoader" | "settingsManager"> & {
@@ -99,7 +100,7 @@ interface PiToolProxyOptions {
99
100
  readonly broker: ToolBroker;
100
101
  readonly approvals: PiToolApprovalGateway;
101
102
  readonly getActiveInput: () => AgentLoopInput | undefined;
102
- readonly memoryScopes?: ReadonlyArray<MemoryScope>;
103
+ readonly memoryScopes?: ReadonlyArray<RivusMemoryScope>;
103
104
  }
104
105
  declare function createPiToolProxyDefinitions(options: PiToolProxyOptions): PiToolDefinition[];
105
106
  declare function createPiToolNameResolver(tools: ReadonlyArray<Pick<RivusResolvedToolDescriptor, "id">>): (toolName: string) => string;
package/dist/pi.js CHANGED
@@ -1,3 +1,3 @@
1
- import { n as createPiSkillRuntime } from "./chunks/pi-skill-tool.js";
1
+ import { r as createPiSkillRuntime } from "./chunks/rivus-tool.js";
2
2
  import { a as InvalidPiSkillSource, c as validatePiSkillCatalog, d as createPiProjectSkillReadTool, f as createPiSkillReadTool, i as resolvePiSessionToolNames, l as validatePiSkillCommand, 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";
3
3
  export { InvalidPiSkillCatalog, InvalidPiSkillSource, ProjectSkillReadDenied, createPiProjectSkillReadTool, createPiSessionResources, createPiSkillReadTool, createPiSkillReadTools, createPiSkillRuntime, createPiToolNameResolver, createPiToolProxyDefinitions, resolvePiSessionToolNames, resolvePiSkillSources, validatePiSkillCatalog, validatePiSkillCommand };