@rivus/agent 0.6.0 → 0.6.1

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.
@@ -0,0 +1,126 @@
1
+ import { s as restrictMemoryScopesForAudience } from "./agent-memory.js";
2
+ import { createHash, randomUUID } from "node:crypto";
3
+ import { Unsafe } from "typebox";
4
+ //#region src/infrastructure/pi/pi-skill-tool.ts
5
+ const PI_SKILL_READER_TOOL_NAME = "rivus_read_skill";
6
+ function createPiSkillRuntime(skills) {
7
+ if (skills.length === 0) return Object.freeze({ prompt: "" });
8
+ const skillsById = new Map(skills.map((skill) => [skill.id, skill]));
9
+ const prompt = [
10
+ "Granted Skills are versioned instructions loaded on demand.",
11
+ `Before following a Skill, call ${PI_SKILL_READER_TOOL_NAME} with its exact ID and follow the returned content.`,
12
+ "Granted Skill catalog:",
13
+ ...skills.map((skill) => `- ${skill.id} | ${skill.title} | v${skill.version} | ${skill.digest}`)
14
+ ].join("\n");
15
+ const tool = {
16
+ description: "Read the full versioned instructions for one Skill granted to this Agent Runtime.",
17
+ execute: async (_callId, input) => {
18
+ const skillId = readSkillId(input);
19
+ const skill = skillsById.get(skillId);
20
+ if (!skill) throw new Error(`Skill is not granted: ${skillId}`);
21
+ const details = {
22
+ contentLength: skill.content.length,
23
+ digest: skill.digest,
24
+ skillId: skill.id,
25
+ title: skill.title,
26
+ version: skill.version
27
+ };
28
+ return {
29
+ content: [{
30
+ text: skill.content,
31
+ type: "text"
32
+ }],
33
+ details
34
+ };
35
+ },
36
+ executionMode: "sequential",
37
+ label: "Read granted Skill",
38
+ name: PI_SKILL_READER_TOOL_NAME,
39
+ parameters: Unsafe({
40
+ additionalProperties: false,
41
+ properties: { skillId: {
42
+ description: "Exact Skill ID from the granted Skill catalog.",
43
+ type: "string"
44
+ } },
45
+ required: ["skillId"],
46
+ type: "object"
47
+ }),
48
+ promptSnippet: `${PI_SKILL_READER_TOOL_NAME}: read one granted Skill by exact ID`
49
+ };
50
+ return Object.freeze({
51
+ prompt,
52
+ tool
53
+ });
54
+ }
55
+ function readSkillId(input) {
56
+ if (input === null || typeof input !== "object" || Array.isArray(input) || typeof input.skillId !== "string") throw new Error("Skill reader input requires a string skillId");
57
+ return input.skillId;
58
+ }
59
+ //#endregion
60
+ //#region src/application/delegation/tool-authority.ts
61
+ const authorities = /* @__PURE__ */ new WeakMap();
62
+ var InvalidInvocationAuthority = class extends Error {
63
+ name = "InvalidInvocationAuthority";
64
+ };
65
+ function createInvocationAuthority(authority) {
66
+ if (!authority.sourceMessageId.trim()) throw new InvalidInvocationAuthority("invocation authority requires a trusted source message id");
67
+ const reference = Object.freeze({ id: `authority:${randomUUID()}` });
68
+ const memory = authority.memory ? Object.freeze({
69
+ ...authority.memory,
70
+ scopes: Object.freeze(restrictMemoryScopesForAudience(authority.memory.scopes, authority.memory.audience))
71
+ }) : void 0;
72
+ authorities.set(reference, Object.freeze({
73
+ ...authority,
74
+ ...memory ? { memory } : {}
75
+ }));
76
+ return reference;
77
+ }
78
+ function resolveInvocationAuthority(reference) {
79
+ const authority = authorities.get(reference);
80
+ if (!authority) throw new InvalidInvocationAuthority("invocation authority was not issued by this host");
81
+ return authority;
82
+ }
83
+ //#endregion
84
+ //#region src/application/delegation/tool-input-digest.ts
85
+ var InvalidStableJson = class extends Error {
86
+ name = "InvalidStableJson";
87
+ };
88
+ var InvalidToolInput = class extends InvalidStableJson {
89
+ name = "InvalidToolInput";
90
+ };
91
+ function createToolInputDigest(input) {
92
+ let canonical;
93
+ try {
94
+ canonical = normalizeStableJson(input);
95
+ } catch (error) {
96
+ if (error instanceof InvalidStableJson) throw new InvalidToolInput(error.message);
97
+ throw error;
98
+ }
99
+ return `sha256:${createHash("sha256").update(JSON.stringify(canonical)).digest("hex")}`;
100
+ }
101
+ function normalizeStableJson(value) {
102
+ return canonicalize(value, /* @__PURE__ */ new Set());
103
+ }
104
+ function canonicalize(value, ancestors) {
105
+ if (value === null || typeof value === "string" || typeof value === "boolean") return value;
106
+ if (typeof value === "number") {
107
+ if (!Number.isFinite(value)) throw new InvalidStableJson("stable JSON numbers must be finite");
108
+ return Object.is(value, -0) ? 0 : value;
109
+ }
110
+ if (typeof value !== "object") throw new InvalidStableJson("value must contain only stable JSON values");
111
+ if (ancestors.has(value)) throw new InvalidStableJson("stable JSON must not contain cycles");
112
+ ancestors.add(value);
113
+ try {
114
+ if (Array.isArray(value)) return Array.from({ length: value.length }, (_, index) => {
115
+ if (!Object.hasOwn(value, index)) throw new InvalidStableJson("stable JSON arrays must not contain holes");
116
+ return canonicalize(value[index], ancestors);
117
+ });
118
+ const prototype = Object.getPrototypeOf(value);
119
+ if (prototype !== Object.prototype && prototype !== null) throw new InvalidStableJson("stable JSON objects must be plain objects");
120
+ return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(([key, entry]) => [key, canonicalize(entry, ancestors)]));
121
+ } finally {
122
+ ancestors.delete(value);
123
+ }
124
+ }
125
+ //#endregion
126
+ export { InvalidInvocationAuthority as a, PI_SKILL_READER_TOOL_NAME as c, normalizeStableJson as i, createPiSkillRuntime as l, InvalidToolInput as n, createInvocationAuthority as o, createToolInputDigest as r, resolveInvocationAuthority as s, InvalidStableJson as t };
@@ -36,9 +36,6 @@ import {
36
36
  createLazyFeishuWebSocketEventDispatcher,
37
37
  createPiAgentLoop,
38
38
  createProjectMemoryPromptPreparer,
39
- createPiSkillRuntime,
40
- createPiToolNameResolver,
41
- createPiToolProxyDefinitions,
42
39
  createPiSessionRegistry,
43
40
  createRoutedHumanInteractionToolApprovalService,
44
41
  createSessionScheduler,
@@ -66,7 +63,12 @@ import {
66
63
  type RivusDeploymentBootstrapContext,
67
64
  type RivusThinkingLevel
68
65
  } from "@rivus/agent";
69
- import { createPiProjectSkillReadTool } from "@rivus/agent/pi";
66
+ import {
67
+ createPiProjectSkillReadTool,
68
+ createPiSkillRuntime,
69
+ createPiToolNameResolver,
70
+ createPiToolProxyDefinitions
71
+ } from "@rivus/agent/pi";
70
72
 
71
73
  type PiSessionOptions = NonNullable<Parameters<typeof createAgentSession>[0]>;
72
74
 
@@ -233,6 +235,7 @@ export async function createRivusDeploymentAdapters(context: RivusDeploymentBoot
233
235
  agentId: input.agentId,
234
236
  botOpenId,
235
237
  cardRollover: cardRollover.transport,
238
+ finalizeRun: (runId) => cardRollover.rollover.releaseRun(runId),
236
239
  cancel: input.cancel,
237
240
  endpointId: input.endpointId,
238
241
  eventDispatcher: createLazyFeishuWebSocketEventDispatcher(() => new Lark.EventDispatcher({})),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivus/agent",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "A local agent daemon core built around a usable agent harness and domain events.",
5
5
  "type": "module",
6
6
  "license": "MIT",