@rivus/agent 0.16.2 → 0.16.6

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.
@@ -1,508 +0,0 @@
1
- import { o as createBackgroundSessionToolContracts } from "./background-session-authority.js";
2
- //#region src/platform/values/deep-freeze.ts
3
- function deepFreeze(value) {
4
- if (value !== null && typeof value === "object" && !Object.isFrozen(value)) {
5
- Object.freeze(value);
6
- for (const child of Object.values(value)) deepFreeze(child);
7
- }
8
- return value;
9
- }
10
- //#endregion
11
- //#region src/core/application/agent-catalog/contracts/rivus-runtime-tool.ts
12
- const RIVUS_RUNTIME_TOOL_IDS = Object.freeze([
13
- "read",
14
- "bash",
15
- "edit",
16
- "write",
17
- "grep",
18
- "find",
19
- "ls"
20
- ]);
21
- function isRivusRuntimeToolId(value) {
22
- return RIVUS_RUNTIME_TOOL_IDS.includes(value);
23
- }
24
- //#endregion
25
- //#region src/adapters/agent/memory/rivus-memory-tool-contract.ts
26
- const RIVUS_MEMORY_TOOL_ID = "memory";
27
- const RIVUS_MEMORY_TOOL_PLUGIN_ID = "rivus-core";
28
- const RIVUS_MEMORY_TOOL_VERSION = "1.0.0";
29
- function createRivusMemoryToolContract(scopes) {
30
- return Object.freeze({
31
- description: "Search and read Memory inside Host-bound scopes; propose or request forgetting only in writable private scopes.",
32
- digest: "sha256:rivus-memory-v3",
33
- id: RIVUS_MEMORY_TOOL_ID,
34
- idempotency: "required",
35
- inputSchema: Object.freeze({
36
- additionalProperties: false,
37
- properties: {
38
- command: {
39
- description: "One of search, read, propose, or forget_request.",
40
- enum: [
41
- "search",
42
- "read",
43
- "propose",
44
- "forget_request"
45
- ],
46
- type: "string"
47
- },
48
- id: {
49
- description: "Required for read and forget_request.",
50
- minLength: 1,
51
- type: "string"
52
- },
53
- input: {
54
- additionalProperties: false,
55
- description: "Required for propose.",
56
- properties: { content: {
57
- minLength: 1,
58
- type: "string"
59
- } },
60
- required: ["content"],
61
- type: "object"
62
- },
63
- query: {
64
- additionalProperties: false,
65
- description: "Required for search.",
66
- properties: { query: { type: "string" } },
67
- required: ["query"],
68
- type: "object"
69
- },
70
- reason: {
71
- description: "Optional reason for forget_request.",
72
- type: "string"
73
- },
74
- ...scopes.length === 0 ? {} : { scope: {
75
- description: "Optional Host-granted scope for search or propose. Confirmed Project and Shared User Profile Memory are read-only to the model.",
76
- enum: [...scopes],
77
- type: "string"
78
- } }
79
- },
80
- required: ["command"],
81
- type: "object"
82
- }),
83
- risk: "mutate",
84
- version: RIVUS_MEMORY_TOOL_VERSION
85
- });
86
- }
87
- //#endregion
88
- //#region src/adapters/agent/catalog/rivus-host-tool-descriptor-provider.ts
89
- function createRivusHostToolDescriptorProvider(options) {
90
- return Object.freeze({ provide: ({ deployment, memoryScopes }) => {
91
- const contributions = [];
92
- if (deployment.memory?.tool === true) contributions.push({
93
- scope: "profile",
94
- tool: Object.freeze({
95
- ...createRivusMemoryToolContract(memoryScopes),
96
- pluginId: RIVUS_MEMORY_TOOL_PLUGIN_ID
97
- })
98
- });
99
- if (options.backgroundSessions) contributions.push(...createBackgroundSessionToolContracts().map(toRuntimeContribution));
100
- return Object.freeze(contributions);
101
- } });
102
- }
103
- function toRuntimeContribution(tool) {
104
- return Object.freeze({
105
- scope: "runtime",
106
- tool: Object.freeze({ ...tool })
107
- });
108
- }
109
- //#endregion
110
- //#region src/core/application/agent-catalog/contracts/rivus-plugin.ts
111
- const RIVUS_PLUGIN_API_VERSION = "1";
112
- var InvalidRivusPlugin = class extends Error {
113
- name = "InvalidRivusPlugin";
114
- };
115
- //#endregion
116
- //#region src/core/application/agent-catalog/catalog/rivus-catalog-validation.ts
117
- const MEMORY_SCOPES = [
118
- "conversation",
119
- "agent-private",
120
- "project",
121
- "shared-user-profile"
122
- ];
123
- function validateRivusPluginManifest(manifest) {
124
- validateRivusCatalogIdentifier(manifest.id, "plugin");
125
- if (manifest.apiVersion !== "1") throw new InvalidRivusPlugin(`unsupported plugin API version ${manifest.apiVersion}; expected 1`);
126
- if (manifest.version.trim() === "") throw new InvalidRivusPlugin("plugin version must not be empty");
127
- }
128
- function validateRivusCatalogRegistration(item, existing, pending) {
129
- validateRivusCatalogIdentifier(item.id, item.kind);
130
- if (item.namespaced && !item.id.startsWith(`${item.pluginId}/`)) throw new InvalidRivusPlugin(`${item.kind} id ${item.id} must use plugin namespace ${item.pluginId}/`);
131
- const key = `${item.kind}:${item.id}`;
132
- if (pending.has(key) || existing.has(item.id)) throw new InvalidRivusPlugin(`duplicate ${item.kind} id: ${item.id}`);
133
- }
134
- function validateRivusCatalogIdentifier(id, kind) {
135
- if (!/^[a-z0-9][a-z0-9._/-]*$/.test(id) || id.includes("*") || id.includes("//")) throw new InvalidRivusPlugin(`invalid ${kind} id: ${id}`);
136
- }
137
- function uniqueRivusCatalogIds(ids, label) {
138
- const result = /* @__PURE__ */ new Set();
139
- for (const id of ids) {
140
- if (id.includes("*")) throw new InvalidRivusPlugin(`${label} does not support wildcard id: ${id}`);
141
- validateRivusCatalogIdentifier(id, label);
142
- if (result.has(id)) throw new InvalidRivusPlugin(`duplicate id in ${label}: ${id}`);
143
- result.add(id);
144
- }
145
- return [...result];
146
- }
147
- function validateRivusCatalogReferences(ids, available, owner, kind) {
148
- for (const id of uniqueRivusCatalogIds(ids, `${owner} ${kind} references`)) validateRivusCatalogReference(id, available, owner, kind);
149
- }
150
- function validateRivusCatalogReference(id, available, owner, kind) {
151
- if (!available.has(id)) throw new InvalidRivusPlugin(`${owner} references unknown ${kind}: ${id}`);
152
- }
153
- function validateRivusMemoryScopes(scopes, owner) {
154
- const result = /* @__PURE__ */ new Set();
155
- for (const scope of scopes) {
156
- if (!MEMORY_SCOPES.includes(scope)) throw new InvalidRivusPlugin(`${owner} references unsupported Memory scope: ${String(scope)}`);
157
- if (result.has(scope)) throw new InvalidRivusPlugin(`${owner} contains duplicate Memory scope: ${scope}`);
158
- result.add(scope);
159
- }
160
- return [...result];
161
- }
162
- function uniqueRivusRuntimeToolIds(ids, owner) {
163
- const result = /* @__PURE__ */ new Set();
164
- for (const id of ids) {
165
- if (typeof id === "string" && id.includes("*")) throw new InvalidRivusPlugin(`${owner} does not support wildcard Runtime Tool: ${id}`);
166
- if (typeof id !== "string" || !isRivusRuntimeToolId(id)) throw new InvalidRivusPlugin(`${owner} references unknown Runtime Tool: ${String(id)}`);
167
- if (result.has(id)) throw new InvalidRivusPlugin(`${owner} contains duplicate Runtime Tool: ${id}`);
168
- result.add(id);
169
- }
170
- return [...result];
171
- }
172
- //#endregion
173
- //#region src/core/application/agent-catalog/catalog/rivus-plugin-catalog.ts
174
- function createRivusPluginCatalog(runtime) {
175
- const plugins = /* @__PURE__ */ new Map();
176
- const profiles = /* @__PURE__ */ new Map();
177
- const tools = /* @__PURE__ */ new Map();
178
- const skills = /* @__PURE__ */ new Map();
179
- const automations = /* @__PURE__ */ new Map();
180
- return {
181
- registerPlugin: (plugin) => {
182
- validateRivusPluginManifest(plugin.manifest);
183
- if (plugins.has(plugin.manifest.id)) throw new InvalidRivusPlugin(`duplicate plugin id: ${plugin.manifest.id}`);
184
- const pendingProfiles = [];
185
- const pendingTools = [];
186
- const pendingSkills = [];
187
- const pendingAutomations = [];
188
- const pendingIds = /* @__PURE__ */ new Set();
189
- const register = (kind, definition, catalog, destination, namespaced) => {
190
- validateRivusCatalogRegistration({
191
- id: definition.id,
192
- kind,
193
- namespaced,
194
- pluginId: plugin.manifest.id
195
- }, catalog, pendingIds);
196
- const key = `${kind}:${definition.id}`;
197
- pendingIds.add(key);
198
- destination.push(runtime.deepFreeze({
199
- ...definition,
200
- pluginId: plugin.manifest.id
201
- }));
202
- };
203
- plugin.register({
204
- registerAgentProfile: (profile) => register("profile", profile, profiles, pendingProfiles, false),
205
- registerAutomation: (automation) => register("automation", automation, automations, pendingAutomations, true),
206
- registerSkill: (skill) => register("skill", skill, skills, pendingSkills, true),
207
- registerTool: (tool) => register("tool", tool, tools, pendingTools, true)
208
- });
209
- const availableToolIds = /* @__PURE__ */ new Set([...tools.keys(), ...pendingTools.map(({ id }) => id)]);
210
- const availableSkillIds = /* @__PURE__ */ new Set([...skills.keys(), ...pendingSkills.map(({ id }) => id)]);
211
- const availableProfileIds = /* @__PURE__ */ new Set([...profiles.keys(), ...pendingProfiles.map(({ id }) => id)]);
212
- for (const profile of pendingProfiles) {
213
- validateRivusMemoryScopes(profile.memory.scopes, `profile ${profile.id}`);
214
- uniqueRivusRuntimeToolIds(profile.runtimeTools?.allow ?? [], `profile ${profile.id}`);
215
- validateRivusCatalogReferences(profile.tools.allow, availableToolIds, `profile ${profile.id}`, "tool");
216
- validateRivusCatalogReferences(profile.skills.allow, availableSkillIds, `profile ${profile.id}`, "skill");
217
- }
218
- for (const automation of pendingAutomations) {
219
- validateRivusCatalogReference(automation.profileId, availableProfileIds, `automation ${automation.id}`, "profile");
220
- validateRivusCatalogReferences(automation.requestedToolIds, availableToolIds, `automation ${automation.id}`, "tool");
221
- validateRivusCatalogReferences(automation.requestedSkillIds, availableSkillIds, `automation ${automation.id}`, "skill");
222
- }
223
- plugins.set(plugin.manifest.id, runtime.deepFreeze({ ...plugin.manifest }));
224
- for (const profile of pendingProfiles) profiles.set(profile.id, profile);
225
- for (const tool of pendingTools) tools.set(tool.id, tool);
226
- for (const skill of pendingSkills) skills.set(skill.id, skill);
227
- for (const automation of pendingAutomations) automations.set(automation.id, automation);
228
- },
229
- snapshot: () => runtime.deepFreeze({
230
- automations: [...automations.values()],
231
- plugins: [...plugins.values()],
232
- profiles: [...profiles.values()],
233
- skills: [...skills.values()],
234
- tools: [...tools.values()]
235
- })
236
- };
237
- }
238
- //#endregion
239
- //#region src/core/application/agent-catalog/resolution/rivus-tool-grant-set.ts
240
- function narrowRivusToolGrantSet(parent, restrictions, runtime) {
241
- const toolIds = intersectToolIds([parent.toolIds, ...restrictions]);
242
- return runtime.deepFreeze({
243
- revision: runtime.digest(JSON.stringify({
244
- parentRevision: parent.revision,
245
- toolIds
246
- })),
247
- toolIds
248
- });
249
- }
250
- function intersectRivusToolIds(sets, runtime) {
251
- const toolIds = intersectToolIds(sets);
252
- return runtime.deepFreeze({
253
- revision: runtime.digest(JSON.stringify(toolIds)),
254
- toolIds
255
- });
256
- }
257
- function createRivusToolGrantSetOperations(runtime) {
258
- return Object.freeze({
259
- intersect: (sets) => intersectRivusToolIds(sets, runtime),
260
- narrow: (parent, restrictions) => narrowRivusToolGrantSet(parent, restrictions, runtime)
261
- });
262
- }
263
- function intersectToolIds(sets) {
264
- const [first = [], ...rest] = sets;
265
- return [...new Set(first)].filter((id) => rest.every((set) => set.includes(id))).sort();
266
- }
267
- //#endregion
268
- //#region src/core/application/agent-catalog/resolution/rivus-agent-grant-restriction.ts
269
- function restrictRivusAgentDefinitionGrants(definition, restriction, runtime) {
270
- const toolIds = uniqueIds(restriction.toolIds);
271
- const skillIds = uniqueIds(restriction.skillIds);
272
- const runtimeToolIds = uniqueRuntimeToolIds(restriction.runtimeToolIds);
273
- const memoryScopes = uniqueScopes(restriction.memory.scopes);
274
- const toolsById = new Map(definition.tools.map((tool) => [tool.id, tool]));
275
- const skillsById = new Map(definition.skills.map((skill) => [skill.id, skill]));
276
- const tools = toolIds.map((toolId) => {
277
- const tool = toolsById.get(toolId);
278
- if (!tool) throw new Error(`Agent grant restriction requests ungranted Tool: ${toolId}`);
279
- return tool;
280
- });
281
- const skills = skillIds.map((skillId) => {
282
- const skill = skillsById.get(skillId);
283
- if (!skill) throw new Error(`Agent grant restriction requests ungranted Skill: ${skillId}`);
284
- return skill;
285
- });
286
- for (const scope of memoryScopes) if (!definition.memory.scopes.includes(scope)) throw new Error(`Agent grant restriction requests ungranted Memory scope: ${scope}`);
287
- for (const runtimeToolId of runtimeToolIds) if (!definition.runtimeToolGrantSet.toolIds.includes(runtimeToolId)) throw new Error(`Agent grant restriction requests ungranted Runtime Tool: ${runtimeToolId}`);
288
- if (restriction.memory.tool && !definition.memory.tool) throw new Error("Agent grant restriction cannot enable an ungranted Memory Tool");
289
- const skillGrantSet = runtime.deepFreeze({
290
- revision: runtime.digest(JSON.stringify({
291
- parentRevision: definition.skillGrantSet.revision,
292
- skillIds
293
- })),
294
- skillIds
295
- });
296
- const runtimeToolGrantSet = runtime.deepFreeze({
297
- revision: runtime.digest(JSON.stringify({
298
- parentRevision: definition.runtimeToolGrantSet.revision,
299
- toolIds: runtimeToolIds
300
- })),
301
- toolIds: runtimeToolIds
302
- });
303
- return runtime.deepFreeze({
304
- ...definition,
305
- memory: {
306
- scopes: memoryScopes,
307
- tool: restriction.memory.tool
308
- },
309
- runtimeToolGrantSet,
310
- skillGrantSet,
311
- skills,
312
- toolGrantSet: narrowRivusToolGrantSet(definition.toolGrantSet, [toolIds], runtime),
313
- tools
314
- });
315
- }
316
- function uniqueRuntimeToolIds(ids) {
317
- const requested = /* @__PURE__ */ new Set();
318
- for (const id of ids) {
319
- if (!isRivusRuntimeToolId(id)) throw new Error(`Agent grant restriction requests unknown Runtime Tool: ${id}`);
320
- requested.add(id);
321
- }
322
- return RIVUS_RUNTIME_TOOL_IDS.filter((id) => requested.has(id));
323
- }
324
- function uniqueIds(ids) {
325
- return [...new Set(ids)].sort();
326
- }
327
- function uniqueScopes(scopes) {
328
- return [...new Set(scopes)].sort();
329
- }
330
- //#endregion
331
- //#region src/core/application/agent-catalog/resolution/rivus-agent-definition-resolver.ts
332
- function createRivusAgentDefinitionResolver(providers, runtime) {
333
- return Object.freeze({ resolve: (catalog, deployment) => resolveRivusAgentDefinition(catalog, deployment, providers, runtime) });
334
- }
335
- function createRivusAgentCatalog(providers, runtime) {
336
- const resolver = createRivusAgentDefinitionResolver(providers, runtime);
337
- return Object.freeze({
338
- createPluginCatalog: () => createRivusPluginCatalog(runtime),
339
- resolve: (catalog, deployment) => resolver.resolve(catalog, deployment),
340
- restrictGrants: (definition, restriction) => restrictRivusAgentDefinitionGrants(definition, restriction, runtime)
341
- });
342
- }
343
- function resolveRivusAgentDefinition(catalog, deployment, providers, runtime) {
344
- const snapshot = catalog.snapshot();
345
- const plugin = snapshot.plugins.find((candidate) => candidate.id === deployment.pluginId);
346
- if (!plugin) throw new InvalidRivusPlugin(`unknown deployment plugin: ${deployment.pluginId}`);
347
- const profile = snapshot.profiles.find((candidate) => candidate.id === deployment.profileId && candidate.pluginId === deployment.pluginId);
348
- if (!profile) throw new InvalidRivusPlugin(`unknown profile ${deployment.profileId} for plugin ${deployment.pluginId}`);
349
- const memoryScopes = resolveMemoryScopes(profile, deployment);
350
- const runtimeToolIds = resolveRuntimeTools(profile, deployment);
351
- const memoryTool = deployment.memory?.tool === true;
352
- if (memoryTool && memoryScopes.length === 0) throw new InvalidRivusPlugin(`deployment ${deployment.agentId} Memory Tool requires at least one granted scope`);
353
- const contributions = providers.flatMap((provider) => provider.provide({
354
- deployment,
355
- memoryScopes,
356
- profile
357
- }));
358
- const profileContributions = contributions.filter(({ scope }) => scope === "profile");
359
- const runtimeContributions = contributions.filter(({ scope }) => scope === "runtime");
360
- validateToolContributions(snapshot.tools, contributions);
361
- if (memoryTool && !profileContributions.some(({ tool }) => tool.id === "memory")) throw new InvalidRivusPlugin(`deployment ${deployment.agentId} Memory Tool descriptor is unavailable`);
362
- const pluginTools = resolvePluginTools(snapshot.tools, profile, deployment);
363
- const profileToolsById = new Map(profileContributions.map(({ tool }) => [tool.id, runtime.deepFreeze({ ...tool })]));
364
- const resolvedProfileToolIds = [...pluginTools.keys(), ...profileToolsById.keys()].sort();
365
- const tools = resolvedProfileToolIds.map((id) => pluginTools.get(id) ?? profileToolsById.get(id));
366
- const skills = resolveSkills(snapshot.skills, profile, deployment);
367
- const skillIds = skills.map(({ id }) => id);
368
- const profileRevision = digest(runtime, {
369
- memory: {
370
- scopes: memoryScopes,
371
- tool: memoryTool
372
- },
373
- model: profile.model,
374
- plugin,
375
- profileId: profile.id,
376
- runtimeTools: runtimeToolIds,
377
- skills: skills.map(({ content, digest: skillDigest, id, pluginId, title, version }) => ({
378
- content,
379
- digest: skillDigest,
380
- id,
381
- pluginId,
382
- title,
383
- version
384
- })),
385
- systemPrompt: profile.systemPrompt,
386
- tools
387
- });
388
- const toolGrantSet = runtime.deepFreeze({
389
- revision: digest(runtime, {
390
- profileRevision,
391
- toolIds: resolvedProfileToolIds
392
- }),
393
- toolIds: resolvedProfileToolIds
394
- });
395
- const skillGrantSet = runtime.deepFreeze({
396
- revision: digest(runtime, {
397
- profileRevision,
398
- skillIds
399
- }),
400
- skillIds
401
- });
402
- const runtimeToolGrantSet = runtime.deepFreeze({
403
- revision: digest(runtime, {
404
- profileRevision,
405
- toolIds: runtimeToolIds
406
- }),
407
- toolIds: runtimeToolIds
408
- });
409
- return extendRuntimeTools(runtime.deepFreeze({
410
- agentId: deployment.agentId,
411
- endpointIds: [...deployment.endpointIds],
412
- memory: {
413
- scopes: memoryScopes,
414
- tool: memoryTool
415
- },
416
- model: profile.model,
417
- pluginId: deployment.pluginId,
418
- profileId: deployment.profileId,
419
- ...deployment.projectSpaceId ? { projectSpaceId: deployment.projectSpaceId } : {},
420
- profileRevision,
421
- runtimeToolGrantSet,
422
- skillGrantSet,
423
- skills,
424
- systemPrompt: profile.systemPrompt,
425
- toolGrantSet,
426
- tools
427
- }), runtimeContributions, runtime);
428
- }
429
- function resolveRuntimeTools(profile, deployment) {
430
- const profileToolIds = uniqueRivusRuntimeToolIds(profile.runtimeTools?.allow ?? [], `profile ${profile.id}`);
431
- const requestedToolIds = uniqueRivusRuntimeToolIds(deployment.runtimeTools?.allow ?? [], `deployment ${deployment.agentId}`);
432
- const profileToolIdSet = new Set(profileToolIds);
433
- const requestedToolIdSet = new Set(requestedToolIds);
434
- return RIVUS_RUNTIME_TOOL_IDS.filter((id) => profileToolIdSet.has(id) && requestedToolIdSet.has(id));
435
- }
436
- function resolveMemoryScopes(profile, deployment) {
437
- const profileScopes = validateRivusMemoryScopes(profile.memory.scopes, `profile ${profile.id}`);
438
- const requestedScopes = validateRivusMemoryScopes(deployment.memory?.scopes ?? [], `deployment ${deployment.agentId}`);
439
- return profileScopes.filter((scope) => requestedScopes.includes(scope));
440
- }
441
- function resolvePluginTools(registeredTools, profile, deployment) {
442
- const requestedTools = uniqueRivusCatalogIds(deployment.tools.allow, "deployment tool allowlist");
443
- const catalogTools = new Map(registeredTools.map((tool) => [tool.id, tool]));
444
- for (const id of requestedTools) if (!catalogTools.has(id)) throw new InvalidRivusPlugin(`unknown deployment tool: ${id}`);
445
- const profileToolIds = uniqueRivusCatalogIds(profile.tools.allow, "profile tool allowlist");
446
- for (const id of profileToolIds) if (!catalogTools.has(id)) throw new InvalidRivusPlugin(`profile ${profile.id} references unknown tool: ${id}`);
447
- const grantedIds = profileToolIds.filter((id) => requestedTools.includes(id)).sort();
448
- return new Map(grantedIds.map((id) => [id, toResolvedTool(catalogTools.get(id))]));
449
- }
450
- function resolveSkills(registeredSkills, profile, deployment) {
451
- const requestedSkills = uniqueRivusCatalogIds(deployment.skills.allow, "deployment skill allowlist");
452
- const catalogSkills = new Map(registeredSkills.map((skill) => [skill.id, skill]));
453
- for (const id of requestedSkills) if (!catalogSkills.has(id)) throw new InvalidRivusPlugin(`unknown deployment skill: ${id}`);
454
- return uniqueRivusCatalogIds(profile.skills.allow, "profile skill allowlist").filter((id) => requestedSkills.includes(id)).sort().map((id) => {
455
- const skill = catalogSkills.get(id);
456
- if (!skill) throw new InvalidRivusPlugin(`profile ${profile.id} references unknown skill: ${id}`);
457
- return skill;
458
- });
459
- }
460
- function validateToolContributions(registeredTools, contributions) {
461
- const knownIds = new Set(registeredTools.map(({ id }) => id));
462
- for (const { tool } of contributions) {
463
- validateRivusCatalogIdentifier(tool.id, "contributed tool");
464
- validateRivusCatalogIdentifier(tool.pluginId, "contributed tool plugin");
465
- if (knownIds.has(tool.id)) throw new InvalidRivusPlugin(`duplicate contributed tool id: ${tool.id}`);
466
- if (tool.version.trim() === "" || tool.digest.trim() === "") throw new InvalidRivusPlugin(`contributed tool ${tool.id} requires a version and digest`);
467
- knownIds.add(tool.id);
468
- }
469
- }
470
- function extendRuntimeTools(definition, contributions, runtime) {
471
- if (contributions.length === 0) return definition;
472
- const additions = contributions.map(({ tool }) => runtime.deepFreeze({ ...tool }));
473
- const additionIds = additions.map(({ id }) => id).sort();
474
- return runtime.deepFreeze({
475
- ...definition,
476
- toolGrantSet: {
477
- revision: digest(runtime, {
478
- parentRevision: definition.toolGrantSet.revision,
479
- toolIds: additionIds
480
- }),
481
- toolIds: [...definition.toolGrantSet.toolIds, ...additionIds].sort()
482
- },
483
- tools: [...definition.tools, ...additions]
484
- });
485
- }
486
- function toResolvedTool(tool) {
487
- const { createExecutor: _createExecutor, description, digest: toolDigest, id, idempotency, inputSchema, pluginId, risk, version } = tool;
488
- return {
489
- description,
490
- digest: toolDigest,
491
- id,
492
- idempotency,
493
- inputSchema,
494
- pluginId,
495
- risk,
496
- version
497
- };
498
- }
499
- function digest(runtime, value) {
500
- return runtime.digest(stableJson(value));
501
- }
502
- function stableJson(value) {
503
- if (Array.isArray(value)) return `[${value.map(stableJson).join(",")}]`;
504
- 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(",")}}`;
505
- return JSON.stringify(value);
506
- }
507
- //#endregion
508
- export { RIVUS_PLUGIN_API_VERSION as a, RIVUS_MEMORY_TOOL_PLUGIN_ID as c, RIVUS_RUNTIME_TOOL_IDS as d, isRivusRuntimeToolId as f, InvalidRivusPlugin as i, RIVUS_MEMORY_TOOL_VERSION as l, createRivusToolGrantSetOperations as n, createRivusHostToolDescriptorProvider as o, deepFreeze as p, createRivusPluginCatalog as r, RIVUS_MEMORY_TOOL_ID as s, createRivusAgentCatalog as t, createRivusMemoryToolContract as u };