@rivus/agent 0.14.2 → 0.14.4
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 +1 -1
- package/dist/acp.js +1 -2
- package/dist/bootstrap/pi-feishu.d.ts +1 -1
- package/dist/bootstrap/pi-feishu.js +4 -4
- package/dist/chunks/agent-loop.d.ts +55 -300
- package/dist/chunks/agent-loop.js +3 -1123
- package/dist/chunks/background-session-authority.js +230 -0
- package/dist/chunks/background-session-control-input.js +51 -0
- package/dist/chunks/background-session-service.d.ts +382 -0
- package/dist/chunks/index.d.ts +1201 -538
- package/dist/chunks/pi-tool-proxy.d.ts +22 -90
- package/dist/chunks/pi.js +5 -2
- package/dist/chunks/rivus-agent-definition-resolver.js +508 -0
- package/dist/chunks/rivus-daemon-cli.js +2776 -3244
- package/dist/chunks/rivus-plugin-testkit.d.ts +175 -2
- package/dist/chunks/rivus-plugin-testkit.js +11 -4
- package/dist/chunks/rivus-skill.d.ts +95 -0
- package/dist/chunks/sha256-digest.js +2 -7
- package/dist/chunks/src.js +11941 -7001
- package/dist/chunks/tool-input-digest.js +158 -0
- package/dist/cli.js +764 -712
- package/dist/index.d.ts +6 -7
- package/dist/index.js +7 -8
- package/dist/mcp.d.ts +48 -9
- package/dist/mcp.js +146 -20
- package/dist/pi.d.ts +3 -4
- package/dist/pi.js +1 -1
- package/package.json +5 -5
- package/dist/chunks/api.d.ts +0 -70
- package/dist/chunks/api.js +0 -471
- package/dist/chunks/api2.d.ts +0 -387
- package/dist/chunks/api2.js +0 -1331
- package/dist/chunks/api3.d.ts +0 -402
- package/dist/chunks/module.js +0 -267
- package/dist/chunks/pi-skill-tool.js +0 -460
- package/dist/chunks/spi.d.ts +0 -1
- package/dist/chunks/spi.js +0 -2
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { Unsafe } from "typebox";
|
|
2
|
+
//#region src/adapters/pi/skills/pi-skill-tool.ts
|
|
3
|
+
const PI_SKILL_READER_TOOL_NAME = "rivus_read_skill";
|
|
4
|
+
function createPiSkillRuntime(skills) {
|
|
5
|
+
if (skills.length === 0) return Object.freeze({ prompt: "" });
|
|
6
|
+
const skillsById = new Map(skills.map((skill) => [skill.id, skill]));
|
|
7
|
+
const prompt = [
|
|
8
|
+
"Granted Skills are versioned instructions loaded on demand.",
|
|
9
|
+
`Before following a Skill, call ${PI_SKILL_READER_TOOL_NAME} with its exact ID and follow the returned content.`,
|
|
10
|
+
"Granted Skill catalog:",
|
|
11
|
+
...skills.map((skill) => `- ${skill.id} | ${skill.title} | v${skill.version} | ${skill.digest}`)
|
|
12
|
+
].join("\n");
|
|
13
|
+
const tool = {
|
|
14
|
+
description: "Read the full versioned instructions for one Skill granted to this Agent Runtime.",
|
|
15
|
+
execute: async (_callId, input) => {
|
|
16
|
+
const skillId = readSkillId(input);
|
|
17
|
+
const skill = skillsById.get(skillId);
|
|
18
|
+
if (!skill) throw new Error(`Skill is not granted: ${skillId}`);
|
|
19
|
+
const details = {
|
|
20
|
+
contentLength: skill.content.length,
|
|
21
|
+
digest: skill.digest,
|
|
22
|
+
skillId: skill.id,
|
|
23
|
+
title: skill.title,
|
|
24
|
+
version: skill.version
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
content: [{
|
|
28
|
+
text: skill.content,
|
|
29
|
+
type: "text"
|
|
30
|
+
}],
|
|
31
|
+
details
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
executionMode: "sequential",
|
|
35
|
+
label: "Read granted Skill",
|
|
36
|
+
name: PI_SKILL_READER_TOOL_NAME,
|
|
37
|
+
parameters: Unsafe({
|
|
38
|
+
additionalProperties: false,
|
|
39
|
+
properties: { skillId: {
|
|
40
|
+
description: "Exact Skill ID from the granted Skill catalog.",
|
|
41
|
+
type: "string"
|
|
42
|
+
} },
|
|
43
|
+
required: ["skillId"],
|
|
44
|
+
type: "object"
|
|
45
|
+
}),
|
|
46
|
+
promptSnippet: `${PI_SKILL_READER_TOOL_NAME}: read one granted Skill by exact ID`
|
|
47
|
+
};
|
|
48
|
+
return Object.freeze({
|
|
49
|
+
prompt,
|
|
50
|
+
tool
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function readSkillId(input) {
|
|
54
|
+
if (input === null || typeof input !== "object" || Array.isArray(input) || typeof input.skillId !== "string") throw new Error("Skill reader input requires a string skillId");
|
|
55
|
+
return input.skillId;
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/core/application/agent-catalog/contracts/rivus-tool.ts
|
|
59
|
+
var RivusToolInputRejected = class extends Error {
|
|
60
|
+
name = "RivusToolInputRejected";
|
|
61
|
+
};
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/core/application/tool-execution/authority/invocation-authority-registry.ts
|
|
64
|
+
const authorities = /* @__PURE__ */ new WeakMap();
|
|
65
|
+
let localAuthoritySequence = 0;
|
|
66
|
+
var InvalidInvocationAuthority = class extends Error {
|
|
67
|
+
name = "InvalidInvocationAuthority";
|
|
68
|
+
};
|
|
69
|
+
function createInvocationAuthority(authority, identity = { next: () => String(++localAuthoritySequence) }) {
|
|
70
|
+
const reference = Object.freeze({ id: `authority:${identity.next()}` });
|
|
71
|
+
authorities.set(reference, normalizeInvocationAuthority(authority));
|
|
72
|
+
return reference;
|
|
73
|
+
}
|
|
74
|
+
function resolveInvocationAuthority(reference) {
|
|
75
|
+
const authority = authorities.get(reference);
|
|
76
|
+
if (!authority) throw new InvalidInvocationAuthority("invocation authority was not issued by this host");
|
|
77
|
+
return authority;
|
|
78
|
+
}
|
|
79
|
+
function normalizeInvocationAuthority(authority) {
|
|
80
|
+
if (!isRecord(authority) || typeof authority.sourceMessageId !== "string" || !authority.sourceMessageId.trim()) throw new InvalidInvocationAuthority("invocation authority requires a trusted source message id");
|
|
81
|
+
if (authority.endpointId !== void 0 && (!authority.endpointId || !authority.endpointId.trim())) throw new InvalidInvocationAuthority("invocation authority requires a trusted endpoint id");
|
|
82
|
+
return Object.freeze({
|
|
83
|
+
...authority,
|
|
84
|
+
...authority.allowedActorOpenIds === void 0 ? {} : { allowedActorOpenIds: Object.freeze([...authority.allowedActorOpenIds]) },
|
|
85
|
+
...authority.memory === void 0 ? {} : { memory: freezeMemoryAuthority(authority.memory) },
|
|
86
|
+
toolGrantSet: freezeGrantSet(authority.toolGrantSet)
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function freezeMemoryAuthority(value) {
|
|
90
|
+
const scopes = value.audience === "group" ? value.scopes.filter(isGroupMemoryScope) : [...value.scopes];
|
|
91
|
+
return Object.freeze({
|
|
92
|
+
...value,
|
|
93
|
+
scopes: Object.freeze(scopes)
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function freezeGrantSet(value) {
|
|
97
|
+
return Object.freeze({
|
|
98
|
+
revision: value.revision,
|
|
99
|
+
toolIds: Object.freeze([...value.toolIds])
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function isGroupMemoryScope(value) {
|
|
103
|
+
return value === "conversation" || value === "project";
|
|
104
|
+
}
|
|
105
|
+
function isRecord(value) {
|
|
106
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/core/application/tool-execution/authority/tool-risk-policy.ts
|
|
110
|
+
function requiresToolApproval(risk) {
|
|
111
|
+
return risk === "irreversible" || risk === "host-control";
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/core/application/tool-execution/brokerage/tool-input-digest.ts
|
|
115
|
+
var InvalidStableJson = class extends Error {
|
|
116
|
+
name = "InvalidStableJson";
|
|
117
|
+
};
|
|
118
|
+
var InvalidToolInput = class extends InvalidStableJson {
|
|
119
|
+
name = "InvalidToolInput";
|
|
120
|
+
};
|
|
121
|
+
function createToolInputDigest(input, digest) {
|
|
122
|
+
try {
|
|
123
|
+
return digest(serializeStableJson(input, /* @__PURE__ */ new Set()));
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (error instanceof InvalidStableJson) throw new InvalidToolInput(error.message);
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function normalizeStableJson(value) {
|
|
130
|
+
return JSON.parse(serializeStableJson(value, /* @__PURE__ */ new Set()));
|
|
131
|
+
}
|
|
132
|
+
function serializeStableJson(value, ancestors) {
|
|
133
|
+
if (value === null) return "null";
|
|
134
|
+
if (typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
|
|
135
|
+
if (typeof value === "number") {
|
|
136
|
+
if (!Number.isFinite(value)) throw new InvalidStableJson("stable JSON numbers must be finite");
|
|
137
|
+
return JSON.stringify(value);
|
|
138
|
+
}
|
|
139
|
+
if (typeof value !== "object" || value === null) throw new InvalidStableJson("value must contain only stable JSON values");
|
|
140
|
+
if (ancestors.has(value)) throw new InvalidStableJson("stable JSON must not contain cycles");
|
|
141
|
+
ancestors.add(value);
|
|
142
|
+
try {
|
|
143
|
+
if (Array.isArray(value)) {
|
|
144
|
+
const output = [];
|
|
145
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
146
|
+
if (!Object.hasOwn(value, index)) throw new InvalidStableJson("stable JSON arrays must not contain holes");
|
|
147
|
+
output.push(serializeStableJson(value[index], ancestors));
|
|
148
|
+
}
|
|
149
|
+
return `[${output.join(",")}]`;
|
|
150
|
+
}
|
|
151
|
+
if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new InvalidStableJson("stable JSON objects must be plain objects");
|
|
152
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${serializeStableJson(value[key], ancestors)}`).join(",")}}`;
|
|
153
|
+
} finally {
|
|
154
|
+
ancestors.delete(value);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
//#endregion
|
|
158
|
+
export { requiresToolApproval as a, resolveInvocationAuthority as c, createPiSkillRuntime as d, normalizeStableJson as i, RivusToolInputRejected as l, InvalidToolInput as n, InvalidInvocationAuthority as o, createToolInputDigest as r, createInvocationAuthority as s, InvalidStableJson as t, PI_SKILL_READER_TOOL_NAME as u };
|