@rivus/agent 0.6.0 → 0.6.2
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/dist/agent-memory.js +114 -0
- package/dist/index.d.ts +29 -203
- package/dist/index.js +81 -259
- package/dist/pi-tool-proxy.d.ts +194 -0
- package/dist/pi.d.ts +10 -1
- package/dist/pi.js +111 -1
- package/dist/rivus-daemon-cli.js +35 -17
- package/dist/rivus-plugin-registry.js +2 -114
- package/dist/rivus-plugin-testkit.d.ts +2 -174
- package/dist/rivus-plugin-testkit.js +2 -1
- package/dist/rivus-plugin.d.ts +175 -0
- package/dist/tool-input-digest.js +126 -0
- package/examples/pi-feishu-deployment.bootstrap.ts +7 -4
- package/package.json +1 -1
|
@@ -1,177 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { h as RivusPlugin, l as RivusAgentDeployment } from "./rivus-plugin.js";
|
|
2
2
|
|
|
3
|
-
//#region src/domain/rivus-plugin.d.ts
|
|
4
|
-
declare const RIVUS_PLUGIN_API_VERSION = "1";
|
|
5
|
-
type RivusToolRisk = "observe" | "mutate" | "irreversible" | "host-control";
|
|
6
|
-
type RivusToolIdempotency = "none" | "supported" | "required";
|
|
7
|
-
declare function requiresToolApproval(risk: RivusToolRisk): boolean;
|
|
8
|
-
declare class RivusToolInputRejected extends Error {
|
|
9
|
-
readonly name: string;
|
|
10
|
-
}
|
|
11
|
-
interface RivusPluginManifest {
|
|
12
|
-
readonly apiVersion: string;
|
|
13
|
-
readonly id: string;
|
|
14
|
-
readonly version: string;
|
|
15
|
-
}
|
|
16
|
-
interface RivusToolExecutor {
|
|
17
|
-
execute(input: unknown, context: RivusToolExecutionContext): unknown;
|
|
18
|
-
}
|
|
19
|
-
interface RivusToolExecutionContext {
|
|
20
|
-
readonly agentId: string;
|
|
21
|
-
readonly instanceId: string;
|
|
22
|
-
readonly memory?: AgentMemoryAuthority;
|
|
23
|
-
readonly runId: string;
|
|
24
|
-
readonly callId: string;
|
|
25
|
-
readonly operationId?: string;
|
|
26
|
-
readonly policyEpoch: number;
|
|
27
|
-
readonly toolId: string;
|
|
28
|
-
readonly toolVersion: string;
|
|
29
|
-
readonly sessionKey: string;
|
|
30
|
-
}
|
|
31
|
-
interface RivusToolFactoryContext {
|
|
32
|
-
readonly toolId: string;
|
|
33
|
-
readonly toolVersion: string;
|
|
34
|
-
}
|
|
35
|
-
interface RivusToolDescriptor {
|
|
36
|
-
readonly id: string;
|
|
37
|
-
readonly version: string;
|
|
38
|
-
readonly digest: string;
|
|
39
|
-
readonly description: string;
|
|
40
|
-
readonly inputSchema: unknown;
|
|
41
|
-
readonly risk: RivusToolRisk;
|
|
42
|
-
readonly idempotency: RivusToolIdempotency;
|
|
43
|
-
readonly createExecutor: (context: RivusToolFactoryContext) => RivusToolExecutor;
|
|
44
|
-
}
|
|
45
|
-
interface RivusHostToolDescriptor extends RivusToolDescriptor {
|
|
46
|
-
readonly replayCompleted?: (input: unknown, completedResult: unknown, context: RivusToolExecutionContext) => unknown;
|
|
47
|
-
}
|
|
48
|
-
interface RivusSkillDescriptor {
|
|
49
|
-
readonly id: string;
|
|
50
|
-
readonly version: string;
|
|
51
|
-
readonly digest: string;
|
|
52
|
-
readonly title: string;
|
|
53
|
-
readonly content: string;
|
|
54
|
-
}
|
|
55
|
-
interface RivusAutomationTemplate {
|
|
56
|
-
readonly id: string;
|
|
57
|
-
readonly profileId: string;
|
|
58
|
-
readonly requestedSkillIds: ReadonlyArray<string>;
|
|
59
|
-
readonly requestedToolIds: ReadonlyArray<string>;
|
|
60
|
-
readonly createInput: (tick: RivusAutomationTickContext) => RivusAutomationInput;
|
|
61
|
-
}
|
|
62
|
-
interface RivusAutomationTickContext {
|
|
63
|
-
readonly occurrence: string;
|
|
64
|
-
}
|
|
65
|
-
interface RivusAutomationInput {
|
|
66
|
-
readonly text: string;
|
|
67
|
-
}
|
|
68
|
-
interface RivusAgentProfile {
|
|
69
|
-
readonly id: string;
|
|
70
|
-
readonly displayName: string;
|
|
71
|
-
readonly systemPrompt: string;
|
|
72
|
-
readonly model: Readonly<Record<string, unknown>>;
|
|
73
|
-
readonly tools: {
|
|
74
|
-
readonly allow: ReadonlyArray<string>;
|
|
75
|
-
};
|
|
76
|
-
readonly skills: {
|
|
77
|
-
readonly allow: ReadonlyArray<string>;
|
|
78
|
-
};
|
|
79
|
-
readonly memory: {
|
|
80
|
-
readonly scopes: ReadonlyArray<MemoryScope>;
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
interface RivusPluginRegistry {
|
|
84
|
-
registerAgentProfile(profile: RivusAgentProfile): void;
|
|
85
|
-
registerTool(tool: RivusToolDescriptor): void;
|
|
86
|
-
registerSkill(skill: RivusSkillDescriptor): void;
|
|
87
|
-
registerAutomation(template: RivusAutomationTemplate): void;
|
|
88
|
-
}
|
|
89
|
-
interface RivusPlugin {
|
|
90
|
-
readonly manifest: RivusPluginManifest;
|
|
91
|
-
register(registry: RivusPluginRegistry): void;
|
|
92
|
-
}
|
|
93
|
-
interface RegisteredRivusPlugin extends RivusPluginManifest {}
|
|
94
|
-
interface RegisteredRivusTool extends RivusToolDescriptor {
|
|
95
|
-
readonly pluginId: string;
|
|
96
|
-
}
|
|
97
|
-
interface RegisteredRivusSkill extends RivusSkillDescriptor {
|
|
98
|
-
readonly pluginId: string;
|
|
99
|
-
}
|
|
100
|
-
interface RegisteredRivusAutomation extends RivusAutomationTemplate {
|
|
101
|
-
readonly pluginId: string;
|
|
102
|
-
}
|
|
103
|
-
interface RegisteredRivusAgentProfile extends RivusAgentProfile {
|
|
104
|
-
readonly pluginId: string;
|
|
105
|
-
}
|
|
106
|
-
interface RivusPluginCatalogSnapshot {
|
|
107
|
-
readonly plugins: ReadonlyArray<RegisteredRivusPlugin>;
|
|
108
|
-
readonly profiles: ReadonlyArray<RegisteredRivusAgentProfile>;
|
|
109
|
-
readonly tools: ReadonlyArray<RegisteredRivusTool>;
|
|
110
|
-
readonly skills: ReadonlyArray<RegisteredRivusSkill>;
|
|
111
|
-
readonly automations: ReadonlyArray<RegisteredRivusAutomation>;
|
|
112
|
-
}
|
|
113
|
-
interface RivusPluginCatalog {
|
|
114
|
-
registerPlugin(plugin: RivusPlugin): void;
|
|
115
|
-
snapshot(): RivusPluginCatalogSnapshot;
|
|
116
|
-
}
|
|
117
|
-
interface RivusAgentDeployment {
|
|
118
|
-
readonly agentId: string;
|
|
119
|
-
readonly pluginId: string;
|
|
120
|
-
readonly profileId: string;
|
|
121
|
-
readonly projectSpaceId?: string;
|
|
122
|
-
readonly endpointIds: ReadonlyArray<string>;
|
|
123
|
-
readonly memory?: {
|
|
124
|
-
readonly scopes: ReadonlyArray<MemoryScope>;
|
|
125
|
-
readonly tool: boolean;
|
|
126
|
-
};
|
|
127
|
-
readonly skills: {
|
|
128
|
-
readonly allow: ReadonlyArray<string>;
|
|
129
|
-
};
|
|
130
|
-
readonly tools: {
|
|
131
|
-
readonly allow: ReadonlyArray<string>;
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
interface RivusResolvedToolDescriptor {
|
|
135
|
-
readonly id: string;
|
|
136
|
-
readonly version: string;
|
|
137
|
-
readonly digest: string;
|
|
138
|
-
readonly description: string;
|
|
139
|
-
readonly inputSchema: unknown;
|
|
140
|
-
readonly risk: RivusToolRisk;
|
|
141
|
-
readonly idempotency: RivusToolIdempotency;
|
|
142
|
-
readonly pluginId: string;
|
|
143
|
-
}
|
|
144
|
-
interface RivusToolGrantSet {
|
|
145
|
-
readonly toolIds: ReadonlyArray<string>;
|
|
146
|
-
readonly revision: string;
|
|
147
|
-
}
|
|
148
|
-
interface RivusSkillGrantSet {
|
|
149
|
-
readonly skillIds: ReadonlyArray<string>;
|
|
150
|
-
readonly revision: string;
|
|
151
|
-
}
|
|
152
|
-
interface ResolvedRivusAgentDefinition {
|
|
153
|
-
readonly agentId: string;
|
|
154
|
-
readonly pluginId: string;
|
|
155
|
-
readonly profileId: string;
|
|
156
|
-
readonly projectSpaceId?: string;
|
|
157
|
-
readonly projectSpaceRevision?: string;
|
|
158
|
-
readonly endpointIds: ReadonlyArray<string>;
|
|
159
|
-
readonly profileRevision: string;
|
|
160
|
-
readonly systemPrompt: string;
|
|
161
|
-
readonly model: Readonly<Record<string, unknown>>;
|
|
162
|
-
readonly memory: {
|
|
163
|
-
readonly scopes: ReadonlyArray<MemoryScope>;
|
|
164
|
-
readonly tool: boolean;
|
|
165
|
-
};
|
|
166
|
-
readonly skillGrantSet: RivusSkillGrantSet;
|
|
167
|
-
readonly skills: ReadonlyArray<RegisteredRivusSkill>;
|
|
168
|
-
readonly tools: ReadonlyArray<RivusResolvedToolDescriptor>;
|
|
169
|
-
readonly toolGrantSet: RivusToolGrantSet;
|
|
170
|
-
}
|
|
171
|
-
declare class InvalidRivusPlugin extends Error {
|
|
172
|
-
readonly name = "InvalidRivusPlugin";
|
|
173
|
-
}
|
|
174
|
-
//#endregion
|
|
175
3
|
//#region src/testing/rivus-plugin-testkit.d.ts
|
|
176
4
|
interface RivusPluginLifecycleProbe {
|
|
177
5
|
activate(): Promise<{
|
|
@@ -196,4 +24,4 @@ declare class RivusPluginConformanceError extends Error {
|
|
|
196
24
|
declare function assertRivusPluginConforms(input: RivusPluginConformanceInput): Promise<RivusPluginConformanceReport>;
|
|
197
25
|
declare function createFakeRivusPlugin(): RivusPlugin;
|
|
198
26
|
//#endregion
|
|
199
|
-
export {
|
|
27
|
+
export { assertRivusPluginConforms as a, RivusPluginLifecycleProbe as i, RivusPluginConformanceInput as n, createFakeRivusPlugin as o, RivusPluginConformanceReport as r, RivusPluginConformanceError as t };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as RIVUS_MEMORY_TOOL_ID } from "./agent-memory.js";
|
|
2
|
+
import { n as resolveRivusAgentDefinition, t as createRivusPluginCatalog } from "./rivus-plugin-registry.js";
|
|
2
3
|
//#region src/testing/rivus-plugin-testkit.ts
|
|
3
4
|
var RivusPluginConformanceError = class extends Error {
|
|
4
5
|
name = "RivusPluginConformanceError";
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { c as MemoryScope, t as AgentMemoryAuthority } from "./agent-memory.js";
|
|
2
|
+
|
|
3
|
+
//#region src/domain/rivus-plugin.d.ts
|
|
4
|
+
declare const RIVUS_PLUGIN_API_VERSION = "1";
|
|
5
|
+
type RivusToolRisk = "observe" | "mutate" | "irreversible" | "host-control";
|
|
6
|
+
type RivusToolIdempotency = "none" | "supported" | "required";
|
|
7
|
+
declare function requiresToolApproval(risk: RivusToolRisk): boolean;
|
|
8
|
+
declare class RivusToolInputRejected extends Error {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
}
|
|
11
|
+
interface RivusPluginManifest {
|
|
12
|
+
readonly apiVersion: string;
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly version: string;
|
|
15
|
+
}
|
|
16
|
+
interface RivusToolExecutor {
|
|
17
|
+
execute(input: unknown, context: RivusToolExecutionContext): unknown;
|
|
18
|
+
}
|
|
19
|
+
interface RivusToolExecutionContext {
|
|
20
|
+
readonly agentId: string;
|
|
21
|
+
readonly instanceId: string;
|
|
22
|
+
readonly memory?: AgentMemoryAuthority;
|
|
23
|
+
readonly runId: string;
|
|
24
|
+
readonly callId: string;
|
|
25
|
+
readonly operationId?: string;
|
|
26
|
+
readonly policyEpoch: number;
|
|
27
|
+
readonly toolId: string;
|
|
28
|
+
readonly toolVersion: string;
|
|
29
|
+
readonly sessionKey: string;
|
|
30
|
+
}
|
|
31
|
+
interface RivusToolFactoryContext {
|
|
32
|
+
readonly toolId: string;
|
|
33
|
+
readonly toolVersion: string;
|
|
34
|
+
}
|
|
35
|
+
interface RivusToolDescriptor {
|
|
36
|
+
readonly id: string;
|
|
37
|
+
readonly version: string;
|
|
38
|
+
readonly digest: string;
|
|
39
|
+
readonly description: string;
|
|
40
|
+
readonly inputSchema: unknown;
|
|
41
|
+
readonly risk: RivusToolRisk;
|
|
42
|
+
readonly idempotency: RivusToolIdempotency;
|
|
43
|
+
readonly createExecutor: (context: RivusToolFactoryContext) => RivusToolExecutor;
|
|
44
|
+
}
|
|
45
|
+
interface RivusHostToolDescriptor extends RivusToolDescriptor {
|
|
46
|
+
readonly replayCompleted?: (input: unknown, completedResult: unknown, context: RivusToolExecutionContext) => unknown;
|
|
47
|
+
}
|
|
48
|
+
interface RivusSkillDescriptor {
|
|
49
|
+
readonly id: string;
|
|
50
|
+
readonly version: string;
|
|
51
|
+
readonly digest: string;
|
|
52
|
+
readonly title: string;
|
|
53
|
+
readonly content: string;
|
|
54
|
+
}
|
|
55
|
+
interface RivusAutomationTemplate {
|
|
56
|
+
readonly id: string;
|
|
57
|
+
readonly profileId: string;
|
|
58
|
+
readonly requestedSkillIds: ReadonlyArray<string>;
|
|
59
|
+
readonly requestedToolIds: ReadonlyArray<string>;
|
|
60
|
+
readonly createInput: (tick: RivusAutomationTickContext) => RivusAutomationInput;
|
|
61
|
+
}
|
|
62
|
+
interface RivusAutomationTickContext {
|
|
63
|
+
readonly occurrence: string;
|
|
64
|
+
}
|
|
65
|
+
interface RivusAutomationInput {
|
|
66
|
+
readonly text: string;
|
|
67
|
+
}
|
|
68
|
+
interface RivusAgentProfile {
|
|
69
|
+
readonly id: string;
|
|
70
|
+
readonly displayName: string;
|
|
71
|
+
readonly systemPrompt: string;
|
|
72
|
+
readonly model: Readonly<Record<string, unknown>>;
|
|
73
|
+
readonly tools: {
|
|
74
|
+
readonly allow: ReadonlyArray<string>;
|
|
75
|
+
};
|
|
76
|
+
readonly skills: {
|
|
77
|
+
readonly allow: ReadonlyArray<string>;
|
|
78
|
+
};
|
|
79
|
+
readonly memory: {
|
|
80
|
+
readonly scopes: ReadonlyArray<MemoryScope>;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
interface RivusPluginRegistry {
|
|
84
|
+
registerAgentProfile(profile: RivusAgentProfile): void;
|
|
85
|
+
registerTool(tool: RivusToolDescriptor): void;
|
|
86
|
+
registerSkill(skill: RivusSkillDescriptor): void;
|
|
87
|
+
registerAutomation(template: RivusAutomationTemplate): void;
|
|
88
|
+
}
|
|
89
|
+
interface RivusPlugin {
|
|
90
|
+
readonly manifest: RivusPluginManifest;
|
|
91
|
+
register(registry: RivusPluginRegistry): void;
|
|
92
|
+
}
|
|
93
|
+
interface RegisteredRivusPlugin extends RivusPluginManifest {}
|
|
94
|
+
interface RegisteredRivusTool extends RivusToolDescriptor {
|
|
95
|
+
readonly pluginId: string;
|
|
96
|
+
}
|
|
97
|
+
interface RegisteredRivusSkill extends RivusSkillDescriptor {
|
|
98
|
+
readonly pluginId: string;
|
|
99
|
+
}
|
|
100
|
+
interface RegisteredRivusAutomation extends RivusAutomationTemplate {
|
|
101
|
+
readonly pluginId: string;
|
|
102
|
+
}
|
|
103
|
+
interface RegisteredRivusAgentProfile extends RivusAgentProfile {
|
|
104
|
+
readonly pluginId: string;
|
|
105
|
+
}
|
|
106
|
+
interface RivusPluginCatalogSnapshot {
|
|
107
|
+
readonly plugins: ReadonlyArray<RegisteredRivusPlugin>;
|
|
108
|
+
readonly profiles: ReadonlyArray<RegisteredRivusAgentProfile>;
|
|
109
|
+
readonly tools: ReadonlyArray<RegisteredRivusTool>;
|
|
110
|
+
readonly skills: ReadonlyArray<RegisteredRivusSkill>;
|
|
111
|
+
readonly automations: ReadonlyArray<RegisteredRivusAutomation>;
|
|
112
|
+
}
|
|
113
|
+
interface RivusPluginCatalog {
|
|
114
|
+
registerPlugin(plugin: RivusPlugin): void;
|
|
115
|
+
snapshot(): RivusPluginCatalogSnapshot;
|
|
116
|
+
}
|
|
117
|
+
interface RivusAgentDeployment {
|
|
118
|
+
readonly agentId: string;
|
|
119
|
+
readonly pluginId: string;
|
|
120
|
+
readonly profileId: string;
|
|
121
|
+
readonly projectSpaceId?: string;
|
|
122
|
+
readonly endpointIds: ReadonlyArray<string>;
|
|
123
|
+
readonly memory?: {
|
|
124
|
+
readonly scopes: ReadonlyArray<MemoryScope>;
|
|
125
|
+
readonly tool: boolean;
|
|
126
|
+
};
|
|
127
|
+
readonly skills: {
|
|
128
|
+
readonly allow: ReadonlyArray<string>;
|
|
129
|
+
};
|
|
130
|
+
readonly tools: {
|
|
131
|
+
readonly allow: ReadonlyArray<string>;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
interface RivusResolvedToolDescriptor {
|
|
135
|
+
readonly id: string;
|
|
136
|
+
readonly version: string;
|
|
137
|
+
readonly digest: string;
|
|
138
|
+
readonly description: string;
|
|
139
|
+
readonly inputSchema: unknown;
|
|
140
|
+
readonly risk: RivusToolRisk;
|
|
141
|
+
readonly idempotency: RivusToolIdempotency;
|
|
142
|
+
readonly pluginId: string;
|
|
143
|
+
}
|
|
144
|
+
interface RivusToolGrantSet {
|
|
145
|
+
readonly toolIds: ReadonlyArray<string>;
|
|
146
|
+
readonly revision: string;
|
|
147
|
+
}
|
|
148
|
+
interface RivusSkillGrantSet {
|
|
149
|
+
readonly skillIds: ReadonlyArray<string>;
|
|
150
|
+
readonly revision: string;
|
|
151
|
+
}
|
|
152
|
+
interface ResolvedRivusAgentDefinition {
|
|
153
|
+
readonly agentId: string;
|
|
154
|
+
readonly pluginId: string;
|
|
155
|
+
readonly profileId: string;
|
|
156
|
+
readonly projectSpaceId?: string;
|
|
157
|
+
readonly projectSpaceRevision?: string;
|
|
158
|
+
readonly endpointIds: ReadonlyArray<string>;
|
|
159
|
+
readonly profileRevision: string;
|
|
160
|
+
readonly systemPrompt: string;
|
|
161
|
+
readonly model: Readonly<Record<string, unknown>>;
|
|
162
|
+
readonly memory: {
|
|
163
|
+
readonly scopes: ReadonlyArray<MemoryScope>;
|
|
164
|
+
readonly tool: boolean;
|
|
165
|
+
};
|
|
166
|
+
readonly skillGrantSet: RivusSkillGrantSet;
|
|
167
|
+
readonly skills: ReadonlyArray<RegisteredRivusSkill>;
|
|
168
|
+
readonly tools: ReadonlyArray<RivusResolvedToolDescriptor>;
|
|
169
|
+
readonly toolGrantSet: RivusToolGrantSet;
|
|
170
|
+
}
|
|
171
|
+
declare class InvalidRivusPlugin extends Error {
|
|
172
|
+
readonly name = "InvalidRivusPlugin";
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
export { RivusToolRisk as A, RivusToolDescriptor as C, RivusToolGrantSet as D, RivusToolFactoryContext as E, RivusToolIdempotency as O, RivusSkillGrantSet as S, RivusToolExecutor as T, RivusPluginCatalogSnapshot as _, RegisteredRivusPlugin as a, RivusResolvedToolDescriptor as b, ResolvedRivusAgentDefinition as c, RivusAutomationInput as d, RivusAutomationTemplate as f, RivusPluginCatalog as g, RivusPlugin as h, RegisteredRivusAutomation as i, requiresToolApproval as j, RivusToolInputRejected as k, RivusAgentDeployment as l, RivusHostToolDescriptor as m, RIVUS_PLUGIN_API_VERSION as n, RegisteredRivusSkill as o, RivusAutomationTickContext as p, RegisteredRivusAgentProfile as r, RegisteredRivusTool as s, InvalidRivusPlugin as t, RivusAgentProfile as u, RivusPluginManifest as v, RivusToolExecutionContext as w, RivusSkillDescriptor as x, RivusPluginRegistry as y };
|
|
@@ -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 {
|
|
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({})),
|