@rivus/agent 0.13.2 → 0.14.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.
- package/README.md +20 -15
- package/dist/acp.d.ts +40 -40
- package/dist/acp.js +71 -31
- package/dist/bootstrap/pi-feishu.d.ts +20 -0
- package/dist/bootstrap/pi-feishu.js +594 -0
- package/dist/{agent-loop.d.ts → chunks/agent-loop.d.ts} +293 -44
- package/dist/chunks/agent-loop.js +1272 -0
- package/dist/chunks/api.d.ts +70 -0
- package/dist/chunks/api.js +471 -0
- package/dist/{rivus-plugin.d.ts → chunks/api2.d.ts} +271 -120
- package/dist/chunks/api2.js +1331 -0
- package/dist/chunks/api3.d.ts +402 -0
- package/dist/chunks/index.d.ts +3662 -0
- package/dist/chunks/module.js +267 -0
- package/dist/chunks/pi-skill-tool.js +460 -0
- package/dist/chunks/pi-tool-proxy.d.ts +188 -0
- package/dist/chunks/pi.js +329 -0
- package/dist/{rivus-daemon-cli.js → chunks/rivus-daemon-cli.js} +2197 -1526
- package/dist/{rivus-plugin-testkit.d.ts → chunks/rivus-plugin-testkit.d.ts} +1 -1
- package/dist/{rivus-plugin-testkit.js → chunks/rivus-plugin-testkit.js} +11 -3
- package/dist/chunks/sha256-digest.js +12 -0
- package/dist/chunks/spi.d.ts +1 -0
- package/dist/chunks/spi.js +2 -0
- package/dist/chunks/src.js +9897 -0
- package/dist/cli.js +602 -93
- package/dist/index.d.ts +8 -3645
- package/dist/index.js +9 -10483
- package/dist/mcp.d.ts +3 -38
- package/dist/mcp.js +4 -114
- package/dist/pi.d.ts +95 -9
- package/dist/pi.js +3 -146
- package/dist/testing/index.d.ts +1 -1
- package/dist/testing/index.js +1 -1
- package/examples/pi-feishu-deployment.bootstrap.ts +35 -46
- package/examples/pi-feishu.bootstrap.ts +35 -20
- package/examples/rivus-starter.plugin.mjs +3 -1
- package/package.json +8 -2
- package/dist/agent-loop.js +0 -121
- package/dist/agent-memory.d.ts +0 -100
- package/dist/agent-memory.js +0 -114
- package/dist/background-session-authority.js +0 -224
- package/dist/background-session-input.js +0 -45
- package/dist/background-session-service.d.ts +0 -291
- package/dist/pi-tool-proxy.d.ts +0 -197
- package/dist/rivus-plugin-registry.js +0 -215
- package/dist/tool-input-digest.js +0 -128
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { a as deepFreeze, c as validateRivusCatalogIdentifier, d as RIVUS_RUNTIME_TOOL_IDS, i as createRivusPluginCatalog, l as validateRivusMemoryScopes, o as uniqueRivusCatalogIds, p as InvalidRivusPlugin, s as uniqueRivusRuntimeToolIds } from "./api.js";
|
|
2
|
+
import { t as createSha256Digest } from "./sha256-digest.js";
|
|
3
|
+
import { q as createBackgroundSessionToolContracts } from "./api2.js";
|
|
4
|
+
//#region src/adapters/agent/memory/rivus-memory-tool-contract.ts
|
|
5
|
+
const RIVUS_MEMORY_TOOL_ID = "memory";
|
|
6
|
+
const RIVUS_MEMORY_TOOL_PLUGIN_ID = "rivus-core";
|
|
7
|
+
const RIVUS_MEMORY_TOOL_VERSION = "1.0.0";
|
|
8
|
+
function createRivusMemoryToolContract(scopes) {
|
|
9
|
+
return Object.freeze({
|
|
10
|
+
description: "Search and read Memory inside Host-bound scopes; propose or request forgetting only in writable private scopes.",
|
|
11
|
+
digest: "sha256:rivus-memory-v3",
|
|
12
|
+
id: RIVUS_MEMORY_TOOL_ID,
|
|
13
|
+
idempotency: "required",
|
|
14
|
+
inputSchema: Object.freeze({
|
|
15
|
+
additionalProperties: false,
|
|
16
|
+
properties: {
|
|
17
|
+
command: {
|
|
18
|
+
description: "One of search, read, propose, or forget_request.",
|
|
19
|
+
enum: [
|
|
20
|
+
"search",
|
|
21
|
+
"read",
|
|
22
|
+
"propose",
|
|
23
|
+
"forget_request"
|
|
24
|
+
],
|
|
25
|
+
type: "string"
|
|
26
|
+
},
|
|
27
|
+
id: {
|
|
28
|
+
description: "Required for read and forget_request.",
|
|
29
|
+
minLength: 1,
|
|
30
|
+
type: "string"
|
|
31
|
+
},
|
|
32
|
+
input: {
|
|
33
|
+
additionalProperties: false,
|
|
34
|
+
description: "Required for propose.",
|
|
35
|
+
properties: { content: {
|
|
36
|
+
minLength: 1,
|
|
37
|
+
type: "string"
|
|
38
|
+
} },
|
|
39
|
+
required: ["content"],
|
|
40
|
+
type: "object"
|
|
41
|
+
},
|
|
42
|
+
query: {
|
|
43
|
+
additionalProperties: false,
|
|
44
|
+
description: "Required for search.",
|
|
45
|
+
properties: { query: { type: "string" } },
|
|
46
|
+
required: ["query"],
|
|
47
|
+
type: "object"
|
|
48
|
+
},
|
|
49
|
+
reason: {
|
|
50
|
+
description: "Optional reason for forget_request.",
|
|
51
|
+
type: "string"
|
|
52
|
+
},
|
|
53
|
+
...scopes.length === 0 ? {} : { scope: {
|
|
54
|
+
description: "Optional Host-granted scope for search or propose. Confirmed Project and Shared User Profile Memory are read-only to the model.",
|
|
55
|
+
enum: [...scopes],
|
|
56
|
+
type: "string"
|
|
57
|
+
} }
|
|
58
|
+
},
|
|
59
|
+
required: ["command"],
|
|
60
|
+
type: "object"
|
|
61
|
+
}),
|
|
62
|
+
risk: "mutate",
|
|
63
|
+
version: RIVUS_MEMORY_TOOL_VERSION
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/adapters/agent/catalog/rivus-host-tool-descriptor-provider.ts
|
|
68
|
+
function createRivusHostToolDescriptorProvider(options) {
|
|
69
|
+
return Object.freeze({ provide: ({ deployment, memoryScopes }) => {
|
|
70
|
+
const contributions = [];
|
|
71
|
+
if (deployment.memory?.tool === true) contributions.push({
|
|
72
|
+
scope: "profile",
|
|
73
|
+
tool: Object.freeze({
|
|
74
|
+
...createRivusMemoryToolContract(memoryScopes),
|
|
75
|
+
pluginId: RIVUS_MEMORY_TOOL_PLUGIN_ID
|
|
76
|
+
})
|
|
77
|
+
});
|
|
78
|
+
if (options.backgroundSessions) contributions.push(...createBackgroundSessionToolContracts().map(toRuntimeContribution));
|
|
79
|
+
return Object.freeze(contributions);
|
|
80
|
+
} });
|
|
81
|
+
}
|
|
82
|
+
function toRuntimeContribution(tool) {
|
|
83
|
+
return Object.freeze({
|
|
84
|
+
scope: "runtime",
|
|
85
|
+
tool: Object.freeze({ ...tool })
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/modules/agent-catalog/application/resolution/rivus-agent-definition-resolver.ts
|
|
90
|
+
function createRivusAgentDefinitionResolver(providers) {
|
|
91
|
+
return Object.freeze({ resolve: (catalog, deployment) => resolveRivusAgentDefinition(catalog, deployment, providers) });
|
|
92
|
+
}
|
|
93
|
+
function resolveRivusAgentDefinition(catalog, deployment, providers) {
|
|
94
|
+
const snapshot = catalog.snapshot();
|
|
95
|
+
const plugin = snapshot.plugins.find((candidate) => candidate.id === deployment.pluginId);
|
|
96
|
+
if (!plugin) throw new InvalidRivusPlugin(`unknown deployment plugin: ${deployment.pluginId}`);
|
|
97
|
+
const profile = snapshot.profiles.find((candidate) => candidate.id === deployment.profileId && candidate.pluginId === deployment.pluginId);
|
|
98
|
+
if (!profile) throw new InvalidRivusPlugin(`unknown profile ${deployment.profileId} for plugin ${deployment.pluginId}`);
|
|
99
|
+
const memoryScopes = resolveMemoryScopes(profile, deployment);
|
|
100
|
+
const runtimeToolIds = resolveRuntimeTools(profile, deployment);
|
|
101
|
+
const memoryTool = deployment.memory?.tool === true;
|
|
102
|
+
if (memoryTool && memoryScopes.length === 0) throw new InvalidRivusPlugin(`deployment ${deployment.agentId} Memory Tool requires at least one granted scope`);
|
|
103
|
+
const contributions = providers.flatMap((provider) => provider.provide({
|
|
104
|
+
deployment,
|
|
105
|
+
memoryScopes,
|
|
106
|
+
profile
|
|
107
|
+
}));
|
|
108
|
+
const profileContributions = contributions.filter(({ scope }) => scope === "profile");
|
|
109
|
+
const runtimeContributions = contributions.filter(({ scope }) => scope === "runtime");
|
|
110
|
+
validateToolContributions(snapshot.tools, contributions);
|
|
111
|
+
if (memoryTool && !profileContributions.some(({ tool }) => tool.id === "memory")) throw new InvalidRivusPlugin(`deployment ${deployment.agentId} Memory Tool descriptor is unavailable`);
|
|
112
|
+
const pluginTools = resolvePluginTools(snapshot.tools, profile, deployment);
|
|
113
|
+
const profileToolsById = new Map(profileContributions.map(({ tool }) => [tool.id, deepFreeze({ ...tool })]));
|
|
114
|
+
const resolvedProfileToolIds = [...pluginTools.keys(), ...profileToolsById.keys()].sort();
|
|
115
|
+
const tools = resolvedProfileToolIds.map((id) => pluginTools.get(id) ?? profileToolsById.get(id));
|
|
116
|
+
const skills = resolveSkills(snapshot.skills, profile, deployment);
|
|
117
|
+
const skillIds = skills.map(({ id }) => id);
|
|
118
|
+
const profileRevision = digest({
|
|
119
|
+
memory: {
|
|
120
|
+
scopes: memoryScopes,
|
|
121
|
+
tool: memoryTool
|
|
122
|
+
},
|
|
123
|
+
model: profile.model,
|
|
124
|
+
plugin,
|
|
125
|
+
profileId: profile.id,
|
|
126
|
+
runtimeTools: runtimeToolIds,
|
|
127
|
+
skills: skills.map(({ content, digest: skillDigest, id, pluginId, title, version }) => ({
|
|
128
|
+
content,
|
|
129
|
+
digest: skillDigest,
|
|
130
|
+
id,
|
|
131
|
+
pluginId,
|
|
132
|
+
title,
|
|
133
|
+
version
|
|
134
|
+
})),
|
|
135
|
+
systemPrompt: profile.systemPrompt,
|
|
136
|
+
tools
|
|
137
|
+
});
|
|
138
|
+
const toolGrantSet = deepFreeze({
|
|
139
|
+
revision: digest({
|
|
140
|
+
profileRevision,
|
|
141
|
+
toolIds: resolvedProfileToolIds
|
|
142
|
+
}),
|
|
143
|
+
toolIds: resolvedProfileToolIds
|
|
144
|
+
});
|
|
145
|
+
const skillGrantSet = deepFreeze({
|
|
146
|
+
revision: digest({
|
|
147
|
+
profileRevision,
|
|
148
|
+
skillIds
|
|
149
|
+
}),
|
|
150
|
+
skillIds
|
|
151
|
+
});
|
|
152
|
+
const runtimeToolGrantSet = deepFreeze({
|
|
153
|
+
revision: digest({
|
|
154
|
+
profileRevision,
|
|
155
|
+
toolIds: runtimeToolIds
|
|
156
|
+
}),
|
|
157
|
+
toolIds: runtimeToolIds
|
|
158
|
+
});
|
|
159
|
+
return extendRuntimeTools(deepFreeze({
|
|
160
|
+
agentId: deployment.agentId,
|
|
161
|
+
endpointIds: [...deployment.endpointIds],
|
|
162
|
+
memory: {
|
|
163
|
+
scopes: memoryScopes,
|
|
164
|
+
tool: memoryTool
|
|
165
|
+
},
|
|
166
|
+
model: profile.model,
|
|
167
|
+
pluginId: deployment.pluginId,
|
|
168
|
+
profileId: deployment.profileId,
|
|
169
|
+
...deployment.projectSpaceId ? { projectSpaceId: deployment.projectSpaceId } : {},
|
|
170
|
+
profileRevision,
|
|
171
|
+
runtimeToolGrantSet,
|
|
172
|
+
skillGrantSet,
|
|
173
|
+
skills,
|
|
174
|
+
systemPrompt: profile.systemPrompt,
|
|
175
|
+
toolGrantSet,
|
|
176
|
+
tools
|
|
177
|
+
}), runtimeContributions);
|
|
178
|
+
}
|
|
179
|
+
function resolveRuntimeTools(profile, deployment) {
|
|
180
|
+
const profileToolIds = uniqueRivusRuntimeToolIds(profile.runtimeTools?.allow ?? [], `profile ${profile.id}`);
|
|
181
|
+
const requestedToolIds = uniqueRivusRuntimeToolIds(deployment.runtimeTools?.allow ?? [], `deployment ${deployment.agentId}`);
|
|
182
|
+
const profileToolIdSet = new Set(profileToolIds);
|
|
183
|
+
const requestedToolIdSet = new Set(requestedToolIds);
|
|
184
|
+
return RIVUS_RUNTIME_TOOL_IDS.filter((id) => profileToolIdSet.has(id) && requestedToolIdSet.has(id));
|
|
185
|
+
}
|
|
186
|
+
function resolveMemoryScopes(profile, deployment) {
|
|
187
|
+
const profileScopes = validateRivusMemoryScopes(profile.memory.scopes, `profile ${profile.id}`);
|
|
188
|
+
const requestedScopes = validateRivusMemoryScopes(deployment.memory?.scopes ?? [], `deployment ${deployment.agentId}`);
|
|
189
|
+
return profileScopes.filter((scope) => requestedScopes.includes(scope));
|
|
190
|
+
}
|
|
191
|
+
function resolvePluginTools(registeredTools, profile, deployment) {
|
|
192
|
+
const requestedTools = uniqueRivusCatalogIds(deployment.tools.allow, "deployment tool allowlist");
|
|
193
|
+
const catalogTools = new Map(registeredTools.map((tool) => [tool.id, tool]));
|
|
194
|
+
for (const id of requestedTools) if (!catalogTools.has(id)) throw new InvalidRivusPlugin(`unknown deployment tool: ${id}`);
|
|
195
|
+
const profileToolIds = uniqueRivusCatalogIds(profile.tools.allow, "profile tool allowlist");
|
|
196
|
+
for (const id of profileToolIds) if (!catalogTools.has(id)) throw new InvalidRivusPlugin(`profile ${profile.id} references unknown tool: ${id}`);
|
|
197
|
+
const grantedIds = profileToolIds.filter((id) => requestedTools.includes(id)).sort();
|
|
198
|
+
return new Map(grantedIds.map((id) => [id, toResolvedTool(catalogTools.get(id))]));
|
|
199
|
+
}
|
|
200
|
+
function resolveSkills(registeredSkills, profile, deployment) {
|
|
201
|
+
const requestedSkills = uniqueRivusCatalogIds(deployment.skills.allow, "deployment skill allowlist");
|
|
202
|
+
const catalogSkills = new Map(registeredSkills.map((skill) => [skill.id, skill]));
|
|
203
|
+
for (const id of requestedSkills) if (!catalogSkills.has(id)) throw new InvalidRivusPlugin(`unknown deployment skill: ${id}`);
|
|
204
|
+
return uniqueRivusCatalogIds(profile.skills.allow, "profile skill allowlist").filter((id) => requestedSkills.includes(id)).sort().map((id) => {
|
|
205
|
+
const skill = catalogSkills.get(id);
|
|
206
|
+
if (!skill) throw new InvalidRivusPlugin(`profile ${profile.id} references unknown skill: ${id}`);
|
|
207
|
+
return skill;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
function validateToolContributions(registeredTools, contributions) {
|
|
211
|
+
const knownIds = new Set(registeredTools.map(({ id }) => id));
|
|
212
|
+
for (const { tool } of contributions) {
|
|
213
|
+
validateRivusCatalogIdentifier(tool.id, "contributed tool");
|
|
214
|
+
validateRivusCatalogIdentifier(tool.pluginId, "contributed tool plugin");
|
|
215
|
+
if (knownIds.has(tool.id)) throw new InvalidRivusPlugin(`duplicate contributed tool id: ${tool.id}`);
|
|
216
|
+
if (tool.version.trim() === "" || tool.digest.trim() === "") throw new InvalidRivusPlugin(`contributed tool ${tool.id} requires a version and digest`);
|
|
217
|
+
knownIds.add(tool.id);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function extendRuntimeTools(definition, contributions) {
|
|
221
|
+
if (contributions.length === 0) return definition;
|
|
222
|
+
const additions = contributions.map(({ tool }) => deepFreeze({ ...tool }));
|
|
223
|
+
const additionIds = additions.map(({ id }) => id).sort();
|
|
224
|
+
return deepFreeze({
|
|
225
|
+
...definition,
|
|
226
|
+
toolGrantSet: {
|
|
227
|
+
revision: digest({
|
|
228
|
+
parentRevision: definition.toolGrantSet.revision,
|
|
229
|
+
toolIds: additionIds
|
|
230
|
+
}),
|
|
231
|
+
toolIds: [...definition.toolGrantSet.toolIds, ...additionIds].sort()
|
|
232
|
+
},
|
|
233
|
+
tools: [...definition.tools, ...additions]
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
function toResolvedTool(tool) {
|
|
237
|
+
const { createExecutor: _createExecutor, description, digest: toolDigest, id, idempotency, inputSchema, pluginId, risk, version } = tool;
|
|
238
|
+
return deepFreeze({
|
|
239
|
+
description,
|
|
240
|
+
digest: toolDigest,
|
|
241
|
+
id,
|
|
242
|
+
idempotency,
|
|
243
|
+
inputSchema,
|
|
244
|
+
pluginId,
|
|
245
|
+
risk,
|
|
246
|
+
version
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
function digest(value) {
|
|
250
|
+
return createSha256Digest(stableJson(value));
|
|
251
|
+
}
|
|
252
|
+
function stableJson(value) {
|
|
253
|
+
if (Array.isArray(value)) return `[${value.map(stableJson).join(",")}]`;
|
|
254
|
+
if (value !== null && typeof value === "object") return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, child]) => `${JSON.stringify(key)}:${stableJson(child)}`).join(",")}}`;
|
|
255
|
+
return JSON.stringify(value);
|
|
256
|
+
}
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region src/modules/agent-catalog/module.ts
|
|
259
|
+
function createRivusAgentCatalog(options = {}) {
|
|
260
|
+
const resolver = createRivusAgentDefinitionResolver(options.toolDescriptorProviders ?? []);
|
|
261
|
+
return Object.freeze({
|
|
262
|
+
createPluginCatalog: createRivusPluginCatalog,
|
|
263
|
+
resolve: (catalog, deployment) => resolver.resolve(catalog, deployment)
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
//#endregion
|
|
267
|
+
export { RIVUS_MEMORY_TOOL_VERSION as a, RIVUS_MEMORY_TOOL_PLUGIN_ID as i, createRivusHostToolDescriptorProvider as n, createRivusMemoryToolContract as o, RIVUS_MEMORY_TOOL_ID as r, createRivusAgentCatalog as t };
|