@rivus/agent 0.13.2 → 0.14.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.
- package/README.md +17 -18
- 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 +596 -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 +604 -95
- 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 +45 -54
- package/examples/pi-feishu.bootstrap.ts +53 -37
- package/examples/rivus-starter.plugin.mjs +3 -1
- package/package.json +12 -14
- 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
package/dist/pi-tool-proxy.d.ts
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { s as AgentLoopInput } from "./agent-loop.js";
|
|
2
|
-
import { c as MemoryScope, t as AgentMemoryAuthority } from "./agent-memory.js";
|
|
3
|
-
import { O as RivusToolGrantSet, _ as RivusPluginCatalog, h as RivusHostToolDescriptor, j as RivusToolRisk, x as RivusResolvedToolDescriptor } from "./rivus-plugin.js";
|
|
4
|
-
import { ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
5
|
-
|
|
6
|
-
//#region src/domain/recovery-action.d.ts
|
|
7
|
-
interface RecoveryAction {
|
|
8
|
-
readonly actorId: string;
|
|
9
|
-
readonly at: string;
|
|
10
|
-
readonly note: string;
|
|
11
|
-
}
|
|
12
|
-
declare class InvalidRecoveryAction extends Error {
|
|
13
|
-
readonly name = "InvalidRecoveryAction";
|
|
14
|
-
}
|
|
15
|
-
declare function createRecoveryAction(input: RecoveryAction): RecoveryAction;
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region src/application/delegation/tool-operation-ledger.d.ts
|
|
18
|
-
interface ToolOperationBinding {
|
|
19
|
-
readonly agentId: string;
|
|
20
|
-
readonly inputDigest: string;
|
|
21
|
-
readonly instanceId: string;
|
|
22
|
-
readonly sourceMessageId: string;
|
|
23
|
-
readonly toolId: string;
|
|
24
|
-
readonly toolVersion: string;
|
|
25
|
-
}
|
|
26
|
-
type ToolOperationState = {
|
|
27
|
-
readonly status: "pending";
|
|
28
|
-
} | {
|
|
29
|
-
readonly result: unknown;
|
|
30
|
-
readonly status: "completed";
|
|
31
|
-
} | {
|
|
32
|
-
readonly reason: string;
|
|
33
|
-
readonly status: "reconciliation-required";
|
|
34
|
-
} | {
|
|
35
|
-
readonly status: "aborted";
|
|
36
|
-
};
|
|
37
|
-
interface ToolOperationRecord {
|
|
38
|
-
readonly binding: ToolOperationBinding;
|
|
39
|
-
readonly operationId: string;
|
|
40
|
-
readonly reconciliation?: ToolOperationReconciliation;
|
|
41
|
-
readonly revision: number;
|
|
42
|
-
readonly state: ToolOperationState;
|
|
43
|
-
}
|
|
44
|
-
interface ToolOperationReconciliation extends RecoveryAction {
|
|
45
|
-
readonly outcome: "applied" | "not-applied";
|
|
46
|
-
}
|
|
47
|
-
type ToolOperationReconciliationOutcome = {
|
|
48
|
-
readonly result: unknown;
|
|
49
|
-
readonly status: "applied";
|
|
50
|
-
} | {
|
|
51
|
-
readonly status: "not-applied";
|
|
52
|
-
};
|
|
53
|
-
type ToolOperationBeginResult = {
|
|
54
|
-
readonly status: "acquired";
|
|
55
|
-
} | {
|
|
56
|
-
readonly result: unknown;
|
|
57
|
-
readonly status: "completed";
|
|
58
|
-
} | {
|
|
59
|
-
readonly status: "blocked";
|
|
60
|
-
readonly reason: string;
|
|
61
|
-
};
|
|
62
|
-
type ToolOperationInspectResult = {
|
|
63
|
-
readonly status: "missing";
|
|
64
|
-
} | {
|
|
65
|
-
readonly result: unknown;
|
|
66
|
-
readonly status: "completed";
|
|
67
|
-
} | {
|
|
68
|
-
readonly status: "blocked";
|
|
69
|
-
readonly reason: string;
|
|
70
|
-
};
|
|
71
|
-
interface ToolOperationLedger {
|
|
72
|
-
abort(operationId: string, binding: ToolOperationBinding): Promise<void>;
|
|
73
|
-
begin(operationId: string, binding: ToolOperationBinding): Promise<ToolOperationBeginResult>;
|
|
74
|
-
complete(operationId: string, binding: ToolOperationBinding, result: unknown): Promise<void>;
|
|
75
|
-
inspect(operationId: string, binding: ToolOperationBinding): Promise<ToolOperationInspectResult>;
|
|
76
|
-
reconciliationRequired(): ReadonlyArray<ToolOperationRecord>;
|
|
77
|
-
reconcile(input: {
|
|
78
|
-
readonly action: RecoveryAction;
|
|
79
|
-
readonly expectedRevision: number;
|
|
80
|
-
readonly operationId: string;
|
|
81
|
-
readonly outcome: ToolOperationReconciliationOutcome;
|
|
82
|
-
}): Promise<ToolOperationRecord>;
|
|
83
|
-
requireReconciliation(operationId: string, binding: ToolOperationBinding, reason: string): Promise<void>;
|
|
84
|
-
unresolvedForSource(sourceMessageId: string): ReadonlyArray<ToolOperationRecord>;
|
|
85
|
-
}
|
|
86
|
-
declare function createToolOperationLedger(options?: {
|
|
87
|
-
readonly initial?: ReadonlyArray<ToolOperationRecord>;
|
|
88
|
-
readonly persist?: (record: ToolOperationRecord) => Promise<void>;
|
|
89
|
-
}): ToolOperationLedger;
|
|
90
|
-
//#endregion
|
|
91
|
-
//#region src/application/delegation/tool-authority.d.ts
|
|
92
|
-
interface InvocationAuthorityRef {
|
|
93
|
-
readonly id: string;
|
|
94
|
-
}
|
|
95
|
-
interface InvocationAuthority {
|
|
96
|
-
readonly agentId: string;
|
|
97
|
-
readonly allowedActorOpenIds?: ReadonlyArray<string>;
|
|
98
|
-
readonly conversationId?: string;
|
|
99
|
-
readonly endpointId?: string;
|
|
100
|
-
readonly instanceId: string;
|
|
101
|
-
readonly memory?: AgentMemoryAuthority;
|
|
102
|
-
readonly runId: string;
|
|
103
|
-
readonly sessionKey: string;
|
|
104
|
-
readonly sourceMessageId: string;
|
|
105
|
-
readonly tenantKey: string;
|
|
106
|
-
readonly toolGrantSet: RivusToolGrantSet;
|
|
107
|
-
}
|
|
108
|
-
declare class InvalidInvocationAuthority extends Error {
|
|
109
|
-
readonly name = "InvalidInvocationAuthority";
|
|
110
|
-
}
|
|
111
|
-
declare function createInvocationAuthority(authority: InvocationAuthority): InvocationAuthorityRef;
|
|
112
|
-
//#endregion
|
|
113
|
-
//#region src/application/delegation/tool-broker.d.ts
|
|
114
|
-
interface AuthorizationPolicyState {
|
|
115
|
-
readonly epoch: number;
|
|
116
|
-
readonly revokedToolIds: ReadonlyArray<string>;
|
|
117
|
-
}
|
|
118
|
-
interface AuthorizationPolicyProvider {
|
|
119
|
-
current(): Promise<AuthorizationPolicyState>;
|
|
120
|
-
}
|
|
121
|
-
interface ToolApprovalRequest {
|
|
122
|
-
readonly approvalId: string;
|
|
123
|
-
readonly agentId: string;
|
|
124
|
-
readonly instanceId: string;
|
|
125
|
-
readonly inputDigest: string;
|
|
126
|
-
readonly operationId: string;
|
|
127
|
-
readonly runId: string;
|
|
128
|
-
readonly sessionKey: string;
|
|
129
|
-
readonly tenantKey: string;
|
|
130
|
-
readonly callId: string;
|
|
131
|
-
readonly toolId: string;
|
|
132
|
-
readonly toolVersion: string;
|
|
133
|
-
readonly risk: RivusToolRisk;
|
|
134
|
-
}
|
|
135
|
-
interface ToolApprovalService {
|
|
136
|
-
consume(request: ToolApprovalRequest): Promise<boolean>;
|
|
137
|
-
}
|
|
138
|
-
interface ToolBrokerOptions {
|
|
139
|
-
readonly approvals: ToolApprovalService;
|
|
140
|
-
readonly catalog: RivusPluginCatalog;
|
|
141
|
-
readonly hostTools?: ReadonlyArray<RivusHostToolDescriptor>;
|
|
142
|
-
readonly policy: AuthorizationPolicyProvider;
|
|
143
|
-
readonly operations?: ToolOperationLedger;
|
|
144
|
-
}
|
|
145
|
-
interface ToolExecutionRequest {
|
|
146
|
-
readonly authority: InvocationAuthorityRef;
|
|
147
|
-
readonly callId: string;
|
|
148
|
-
readonly toolId: string;
|
|
149
|
-
readonly version: string;
|
|
150
|
-
readonly input: unknown;
|
|
151
|
-
readonly operationId?: string;
|
|
152
|
-
readonly approvalId?: string;
|
|
153
|
-
}
|
|
154
|
-
interface ToolBroker {
|
|
155
|
-
execute(request: ToolExecutionRequest): Promise<unknown>;
|
|
156
|
-
}
|
|
157
|
-
declare class ToolInvocationDenied extends Error {
|
|
158
|
-
readonly name = "ToolInvocationDenied";
|
|
159
|
-
}
|
|
160
|
-
declare function createToolBroker(options: ToolBrokerOptions): ToolBroker;
|
|
161
|
-
//#endregion
|
|
162
|
-
//#region src/infrastructure/pi/pi-tool-proxy.d.ts
|
|
163
|
-
interface PiToolApprovalRequest {
|
|
164
|
-
readonly agentId: string;
|
|
165
|
-
readonly allowedActorOpenIds: ReadonlyArray<string>;
|
|
166
|
-
readonly approvalId: string;
|
|
167
|
-
readonly callId: string;
|
|
168
|
-
readonly endpointId: string;
|
|
169
|
-
readonly inputDigest: string;
|
|
170
|
-
readonly instanceId: string;
|
|
171
|
-
readonly operationId: string;
|
|
172
|
-
readonly risk: RivusToolRisk;
|
|
173
|
-
readonly runId: string;
|
|
174
|
-
readonly sessionKey: string;
|
|
175
|
-
readonly signal?: AbortSignal;
|
|
176
|
-
readonly sourceMessageId: string;
|
|
177
|
-
readonly tenantKey: string;
|
|
178
|
-
readonly toolId: string;
|
|
179
|
-
readonly toolVersion: string;
|
|
180
|
-
}
|
|
181
|
-
interface PiToolApprovalGateway {
|
|
182
|
-
requestApproval(request: PiToolApprovalRequest): Promise<void>;
|
|
183
|
-
}
|
|
184
|
-
interface PiToolProxyOptions {
|
|
185
|
-
readonly agentId: string;
|
|
186
|
-
readonly approvals: PiToolApprovalGateway;
|
|
187
|
-
readonly broker: ToolBroker;
|
|
188
|
-
readonly getActiveInput: () => AgentLoopInput | undefined;
|
|
189
|
-
readonly instanceId: string;
|
|
190
|
-
readonly memoryScopes?: ReadonlyArray<MemoryScope>;
|
|
191
|
-
readonly toolGrantSet: RivusToolGrantSet;
|
|
192
|
-
readonly tools: ReadonlyArray<RivusResolvedToolDescriptor>;
|
|
193
|
-
}
|
|
194
|
-
declare function createPiToolProxyDefinitions(options: PiToolProxyOptions): ToolDefinition[];
|
|
195
|
-
declare function createPiToolNameResolver(tools: ReadonlyArray<Pick<RivusResolvedToolDescriptor, "id">>): (toolName: string) => string;
|
|
196
|
-
//#endregion
|
|
197
|
-
export { createRecoveryAction as A, ToolOperationReconciliation as C, createToolOperationLedger as D, ToolOperationState as E, InvalidRecoveryAction as O, ToolOperationLedger as S, ToolOperationRecord as T, InvocationAuthorityRef as _, createPiToolProxyDefinitions as a, ToolOperationBinding as b, ToolApprovalRequest as c, ToolBrokerOptions as d, ToolExecutionRequest as f, InvocationAuthority as g, InvalidInvocationAuthority as h, createPiToolNameResolver as i, RecoveryAction as k, ToolApprovalService as l, createToolBroker as m, PiToolApprovalRequest as n, AuthorizationPolicyProvider as o, ToolInvocationDenied as p, PiToolProxyOptions as r, AuthorizationPolicyState as s, PiToolApprovalGateway as t, ToolBroker as u, createInvocationAuthority as v, ToolOperationReconciliationOutcome as w, ToolOperationInspectResult as x, ToolOperationBeginResult as y };
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import { c as InvalidRivusPlugin, o as createRivusMemoryToolContract, r as RIVUS_MEMORY_TOOL_PLUGIN_ID, t as MEMORY_SCOPES } from "./agent-memory.js";
|
|
2
|
-
import { u as extendBackgroundSessionDefinition } from "./background-session-authority.js";
|
|
3
|
-
import { createHash } from "node:crypto";
|
|
4
|
-
//#region src/application/plugin/deep-freeze.ts
|
|
5
|
-
function deepFreeze(value) {
|
|
6
|
-
if (value !== null && typeof value === "object" && !Object.isFrozen(value)) {
|
|
7
|
-
Object.freeze(value);
|
|
8
|
-
for (const child of Object.values(value)) deepFreeze(child);
|
|
9
|
-
}
|
|
10
|
-
return value;
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/application/plugin/rivus-plugin-registry.ts
|
|
14
|
-
function createRivusPluginCatalog() {
|
|
15
|
-
const plugins = /* @__PURE__ */ new Map();
|
|
16
|
-
const profiles = /* @__PURE__ */ new Map();
|
|
17
|
-
const tools = /* @__PURE__ */ new Map();
|
|
18
|
-
const skills = /* @__PURE__ */ new Map();
|
|
19
|
-
const automations = /* @__PURE__ */ new Map();
|
|
20
|
-
return {
|
|
21
|
-
registerPlugin: (plugin) => {
|
|
22
|
-
validateManifest(plugin.manifest);
|
|
23
|
-
rejectDuplicate(plugins, plugin.manifest.id, "plugin");
|
|
24
|
-
const pendingProfiles = [];
|
|
25
|
-
const pendingTools = [];
|
|
26
|
-
const pendingSkills = [];
|
|
27
|
-
const pendingAutomations = [];
|
|
28
|
-
const pendingIds = /* @__PURE__ */ new Set();
|
|
29
|
-
const register = (kind, definition, catalog, destination, namespaced) => {
|
|
30
|
-
validateIdentifier(definition.id, kind);
|
|
31
|
-
if (namespaced && !definition.id.startsWith(`${plugin.manifest.id}/`)) throw new InvalidRivusPlugin(`${kind} id ${definition.id} must use plugin namespace ${plugin.manifest.id}/`);
|
|
32
|
-
const key = `${kind}:${definition.id}`;
|
|
33
|
-
if (pendingIds.has(key) || catalog.has(definition.id)) throw new InvalidRivusPlugin(`duplicate ${kind} id: ${definition.id}`);
|
|
34
|
-
pendingIds.add(key);
|
|
35
|
-
destination.push(deepFreeze({
|
|
36
|
-
...definition,
|
|
37
|
-
pluginId: plugin.manifest.id
|
|
38
|
-
}));
|
|
39
|
-
};
|
|
40
|
-
plugin.register({
|
|
41
|
-
registerAgentProfile: (profile) => register("profile", profile, profiles, pendingProfiles, false),
|
|
42
|
-
registerAutomation: (automation) => register("automation", automation, automations, pendingAutomations, true),
|
|
43
|
-
registerSkill: (skill) => register("skill", skill, skills, pendingSkills, true),
|
|
44
|
-
registerTool: (tool) => register("tool", tool, tools, pendingTools, true)
|
|
45
|
-
});
|
|
46
|
-
const availableToolIds = /* @__PURE__ */ new Set([...tools.keys(), ...pendingTools.map(({ id }) => id)]);
|
|
47
|
-
const availableSkillIds = /* @__PURE__ */ new Set([...skills.keys(), ...pendingSkills.map(({ id }) => id)]);
|
|
48
|
-
const availableProfileIds = /* @__PURE__ */ new Set([...profiles.keys(), ...pendingProfiles.map(({ id }) => id)]);
|
|
49
|
-
for (const profile of pendingProfiles) {
|
|
50
|
-
validateMemoryScopes(profile.memory.scopes, `profile ${profile.id}`);
|
|
51
|
-
validateReferences(profile.tools.allow, availableToolIds, `profile ${profile.id}`, "tool");
|
|
52
|
-
validateReferences(profile.skills.allow, availableSkillIds, `profile ${profile.id}`, "skill");
|
|
53
|
-
}
|
|
54
|
-
for (const automation of pendingAutomations) {
|
|
55
|
-
if (!availableProfileIds.has(automation.profileId)) throw new InvalidRivusPlugin(`automation ${automation.id} references unknown profile: ${automation.profileId}`);
|
|
56
|
-
validateReferences(automation.requestedToolIds, availableToolIds, `automation ${automation.id}`, "tool");
|
|
57
|
-
validateReferences(automation.requestedSkillIds, availableSkillIds, `automation ${automation.id}`, "skill");
|
|
58
|
-
}
|
|
59
|
-
plugins.set(plugin.manifest.id, deepFreeze({ ...plugin.manifest }));
|
|
60
|
-
for (const profile of pendingProfiles) profiles.set(profile.id, profile);
|
|
61
|
-
for (const tool of pendingTools) tools.set(tool.id, tool);
|
|
62
|
-
for (const skill of pendingSkills) skills.set(skill.id, skill);
|
|
63
|
-
for (const automation of pendingAutomations) automations.set(automation.id, automation);
|
|
64
|
-
},
|
|
65
|
-
snapshot: () => deepFreeze({
|
|
66
|
-
automations: [...automations.values()],
|
|
67
|
-
plugins: [...plugins.values()],
|
|
68
|
-
profiles: [...profiles.values()],
|
|
69
|
-
skills: [...skills.values()],
|
|
70
|
-
tools: [...tools.values()]
|
|
71
|
-
})
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
function resolveRivusAgentDefinition(catalog, deployment, options = {}) {
|
|
75
|
-
const snapshot = catalog.snapshot();
|
|
76
|
-
const plugin = snapshot.plugins.find((candidate) => candidate.id === deployment.pluginId);
|
|
77
|
-
if (!plugin) throw new InvalidRivusPlugin(`unknown deployment plugin: ${deployment.pluginId}`);
|
|
78
|
-
const profile = snapshot.profiles.find((candidate) => candidate.id === deployment.profileId && candidate.pluginId === deployment.pluginId);
|
|
79
|
-
if (!profile) throw new InvalidRivusPlugin(`unknown profile ${deployment.profileId} for plugin ${deployment.pluginId}`);
|
|
80
|
-
const requestedTools = uniqueExactIds(deployment.tools.allow, "deployment tool allowlist");
|
|
81
|
-
const catalogTools = new Map(snapshot.tools.map((tool) => [tool.id, tool]));
|
|
82
|
-
for (const id of requestedTools) if (!catalogTools.has(id)) throw new InvalidRivusPlugin(`unknown deployment tool: ${id}`);
|
|
83
|
-
const profileToolIds = uniqueExactIds(profile.tools.allow, "profile tool allowlist");
|
|
84
|
-
for (const id of profileToolIds) if (!catalogTools.has(id)) throw new InvalidRivusPlugin(`profile ${profile.id} references unknown tool: ${id}`);
|
|
85
|
-
const toolIds = profileToolIds.filter((id) => requestedTools.includes(id)).sort();
|
|
86
|
-
const profileMemoryScopes = validateMemoryScopes(profile.memory.scopes, `profile ${profile.id}`);
|
|
87
|
-
const requestedMemoryScopes = validateMemoryScopes(deployment.memory?.scopes ?? [], `deployment ${deployment.agentId}`);
|
|
88
|
-
const memoryScopes = profileMemoryScopes.filter((scope) => requestedMemoryScopes.includes(scope));
|
|
89
|
-
const memoryTool = deployment.memory?.tool === true;
|
|
90
|
-
if (memoryTool && memoryScopes.length === 0) throw new InvalidRivusPlugin(`deployment ${deployment.agentId} Memory Tool requires at least one granted scope`);
|
|
91
|
-
const memoryToolContract = createRivusMemoryToolContract(memoryScopes);
|
|
92
|
-
const resolvedToolIds = [...toolIds, ...memoryTool ? [memoryToolContract.id] : []].sort();
|
|
93
|
-
const tools = resolvedToolIds.map((id) => id === memoryToolContract.id ? {
|
|
94
|
-
...memoryToolContract,
|
|
95
|
-
pluginId: RIVUS_MEMORY_TOOL_PLUGIN_ID
|
|
96
|
-
} : toResolvedTool(catalogTools.get(id)));
|
|
97
|
-
const requestedSkills = uniqueExactIds(deployment.skills.allow, "deployment skill allowlist");
|
|
98
|
-
const catalogSkills = new Map(snapshot.skills.map((skill) => [skill.id, skill]));
|
|
99
|
-
for (const id of requestedSkills) if (!catalogSkills.has(id)) throw new InvalidRivusPlugin(`unknown deployment skill: ${id}`);
|
|
100
|
-
const skillIds = uniqueExactIds(profile.skills.allow, "profile skill allowlist").filter((id) => requestedSkills.includes(id)).sort();
|
|
101
|
-
const skills = skillIds.map((id) => {
|
|
102
|
-
const skill = catalogSkills.get(id);
|
|
103
|
-
if (!skill) throw new InvalidRivusPlugin(`profile ${profile.id} references unknown skill: ${id}`);
|
|
104
|
-
return skill;
|
|
105
|
-
});
|
|
106
|
-
const profileRevision = digest({
|
|
107
|
-
memory: {
|
|
108
|
-
scopes: memoryScopes,
|
|
109
|
-
tool: memoryTool
|
|
110
|
-
},
|
|
111
|
-
model: profile.model,
|
|
112
|
-
plugin,
|
|
113
|
-
profileId: profile.id,
|
|
114
|
-
skills: skills.map(({ content, digest: skillDigest, id, pluginId, title, version }) => ({
|
|
115
|
-
content,
|
|
116
|
-
digest: skillDigest,
|
|
117
|
-
id,
|
|
118
|
-
pluginId,
|
|
119
|
-
title,
|
|
120
|
-
version
|
|
121
|
-
})),
|
|
122
|
-
systemPrompt: profile.systemPrompt,
|
|
123
|
-
tools
|
|
124
|
-
});
|
|
125
|
-
const toolGrantSet = deepFreeze({
|
|
126
|
-
revision: digest({
|
|
127
|
-
profileRevision,
|
|
128
|
-
toolIds: resolvedToolIds
|
|
129
|
-
}),
|
|
130
|
-
toolIds: resolvedToolIds
|
|
131
|
-
});
|
|
132
|
-
const skillGrantSet = deepFreeze({
|
|
133
|
-
revision: digest({
|
|
134
|
-
profileRevision,
|
|
135
|
-
skillIds
|
|
136
|
-
}),
|
|
137
|
-
skillIds
|
|
138
|
-
});
|
|
139
|
-
const definition = deepFreeze({
|
|
140
|
-
agentId: deployment.agentId,
|
|
141
|
-
endpointIds: [...deployment.endpointIds],
|
|
142
|
-
memory: {
|
|
143
|
-
scopes: memoryScopes,
|
|
144
|
-
tool: memoryTool
|
|
145
|
-
},
|
|
146
|
-
model: profile.model,
|
|
147
|
-
pluginId: deployment.pluginId,
|
|
148
|
-
profileId: deployment.profileId,
|
|
149
|
-
...deployment.projectSpaceId ? { projectSpaceId: deployment.projectSpaceId } : {},
|
|
150
|
-
profileRevision,
|
|
151
|
-
skillGrantSet,
|
|
152
|
-
skills,
|
|
153
|
-
systemPrompt: profile.systemPrompt,
|
|
154
|
-
toolGrantSet,
|
|
155
|
-
tools
|
|
156
|
-
});
|
|
157
|
-
if (options.backgroundSessions === true) return extendBackgroundSessionDefinition(definition);
|
|
158
|
-
return definition;
|
|
159
|
-
}
|
|
160
|
-
function validateMemoryScopes(scopes, owner) {
|
|
161
|
-
const result = /* @__PURE__ */ new Set();
|
|
162
|
-
for (const scope of scopes) {
|
|
163
|
-
if (!MEMORY_SCOPES.includes(scope)) throw new InvalidRivusPlugin(`${owner} references unsupported Memory scope: ${String(scope)}`);
|
|
164
|
-
if (result.has(scope)) throw new InvalidRivusPlugin(`${owner} contains duplicate Memory scope: ${scope}`);
|
|
165
|
-
result.add(scope);
|
|
166
|
-
}
|
|
167
|
-
return [...result];
|
|
168
|
-
}
|
|
169
|
-
function validateManifest(manifest) {
|
|
170
|
-
validateIdentifier(manifest.id, "plugin");
|
|
171
|
-
if (manifest.apiVersion !== "1") throw new InvalidRivusPlugin(`unsupported plugin API version ${manifest.apiVersion}; expected 1`);
|
|
172
|
-
if (manifest.version.trim() === "") throw new InvalidRivusPlugin("plugin version must not be empty");
|
|
173
|
-
}
|
|
174
|
-
function validateIdentifier(id, kind) {
|
|
175
|
-
if (!/^[a-z0-9][a-z0-9._/-]*$/.test(id) || id.includes("*") || id.includes("//")) throw new InvalidRivusPlugin(`invalid ${kind} id: ${id}`);
|
|
176
|
-
}
|
|
177
|
-
function rejectDuplicate(map, id, kind) {
|
|
178
|
-
if (map.has(id)) throw new InvalidRivusPlugin(`duplicate ${kind} id: ${id}`);
|
|
179
|
-
}
|
|
180
|
-
function uniqueExactIds(ids, label) {
|
|
181
|
-
const result = /* @__PURE__ */ new Set();
|
|
182
|
-
for (const id of ids) {
|
|
183
|
-
if (id.includes("*")) throw new InvalidRivusPlugin(`${label} does not support wildcard id: ${id}`);
|
|
184
|
-
validateIdentifier(id, label);
|
|
185
|
-
if (result.has(id)) throw new InvalidRivusPlugin(`duplicate id in ${label}: ${id}`);
|
|
186
|
-
result.add(id);
|
|
187
|
-
}
|
|
188
|
-
return [...result];
|
|
189
|
-
}
|
|
190
|
-
function validateReferences(ids, available, owner, kind) {
|
|
191
|
-
for (const id of uniqueExactIds(ids, `${owner} ${kind} references`)) if (!available.has(id)) throw new InvalidRivusPlugin(`${owner} references unknown ${kind}: ${id}`);
|
|
192
|
-
}
|
|
193
|
-
function toResolvedTool(tool) {
|
|
194
|
-
const { createExecutor: _createExecutor, description, digest: toolDigest, id, idempotency, inputSchema, pluginId, risk, version } = tool;
|
|
195
|
-
return deepFreeze({
|
|
196
|
-
description,
|
|
197
|
-
digest: toolDigest,
|
|
198
|
-
id,
|
|
199
|
-
idempotency,
|
|
200
|
-
inputSchema,
|
|
201
|
-
pluginId,
|
|
202
|
-
risk,
|
|
203
|
-
version
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
function digest(value) {
|
|
207
|
-
return `sha256:${createHash("sha256").update(stableJson(value)).digest("hex")}`;
|
|
208
|
-
}
|
|
209
|
-
function stableJson(value) {
|
|
210
|
-
if (Array.isArray(value)) return `[${value.map(stableJson).join(",")}]`;
|
|
211
|
-
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(",")}}`;
|
|
212
|
-
return JSON.stringify(value);
|
|
213
|
-
}
|
|
214
|
-
//#endregion
|
|
215
|
-
export { resolveRivusAgentDefinition as n, deepFreeze as r, createRivusPluginCatalog as t };
|
|
@@ -1,128 +0,0 @@
|
|
|
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
|
-
if (authority.endpointId !== void 0 && !authority.endpointId.trim()) throw new InvalidInvocationAuthority("invocation authority requires a trusted endpoint id");
|
|
68
|
-
const reference = Object.freeze({ id: `authority:${randomUUID()}` });
|
|
69
|
-
const memory = authority.memory ? Object.freeze({
|
|
70
|
-
...authority.memory,
|
|
71
|
-
scopes: Object.freeze(restrictMemoryScopesForAudience(authority.memory.scopes, authority.memory.audience))
|
|
72
|
-
}) : void 0;
|
|
73
|
-
authorities.set(reference, Object.freeze({
|
|
74
|
-
...authority,
|
|
75
|
-
...authority.allowedActorOpenIds ? { allowedActorOpenIds: Object.freeze([...authority.allowedActorOpenIds]) } : {},
|
|
76
|
-
...memory ? { memory } : {}
|
|
77
|
-
}));
|
|
78
|
-
return reference;
|
|
79
|
-
}
|
|
80
|
-
function resolveInvocationAuthority(reference) {
|
|
81
|
-
const authority = authorities.get(reference);
|
|
82
|
-
if (!authority) throw new InvalidInvocationAuthority("invocation authority was not issued by this host");
|
|
83
|
-
return authority;
|
|
84
|
-
}
|
|
85
|
-
//#endregion
|
|
86
|
-
//#region src/application/delegation/tool-input-digest.ts
|
|
87
|
-
var InvalidStableJson = class extends Error {
|
|
88
|
-
name = "InvalidStableJson";
|
|
89
|
-
};
|
|
90
|
-
var InvalidToolInput = class extends InvalidStableJson {
|
|
91
|
-
name = "InvalidToolInput";
|
|
92
|
-
};
|
|
93
|
-
function createToolInputDigest(input) {
|
|
94
|
-
let canonical;
|
|
95
|
-
try {
|
|
96
|
-
canonical = normalizeStableJson(input);
|
|
97
|
-
} catch (error) {
|
|
98
|
-
if (error instanceof InvalidStableJson) throw new InvalidToolInput(error.message);
|
|
99
|
-
throw error;
|
|
100
|
-
}
|
|
101
|
-
return `sha256:${createHash("sha256").update(JSON.stringify(canonical)).digest("hex")}`;
|
|
102
|
-
}
|
|
103
|
-
function normalizeStableJson(value) {
|
|
104
|
-
return canonicalize(value, /* @__PURE__ */ new Set());
|
|
105
|
-
}
|
|
106
|
-
function canonicalize(value, ancestors) {
|
|
107
|
-
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
108
|
-
if (typeof value === "number") {
|
|
109
|
-
if (!Number.isFinite(value)) throw new InvalidStableJson("stable JSON numbers must be finite");
|
|
110
|
-
return Object.is(value, -0) ? 0 : value;
|
|
111
|
-
}
|
|
112
|
-
if (typeof value !== "object") throw new InvalidStableJson("value must contain only stable JSON values");
|
|
113
|
-
if (ancestors.has(value)) throw new InvalidStableJson("stable JSON must not contain cycles");
|
|
114
|
-
ancestors.add(value);
|
|
115
|
-
try {
|
|
116
|
-
if (Array.isArray(value)) return Array.from({ length: value.length }, (_, index) => {
|
|
117
|
-
if (!Object.hasOwn(value, index)) throw new InvalidStableJson("stable JSON arrays must not contain holes");
|
|
118
|
-
return canonicalize(value[index], ancestors);
|
|
119
|
-
});
|
|
120
|
-
const prototype = Object.getPrototypeOf(value);
|
|
121
|
-
if (prototype !== Object.prototype && prototype !== null) throw new InvalidStableJson("stable JSON objects must be plain objects");
|
|
122
|
-
return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(([key, entry]) => [key, canonicalize(entry, ancestors)]));
|
|
123
|
-
} finally {
|
|
124
|
-
ancestors.delete(value);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
//#endregion
|
|
128
|
-
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 };
|