@rivus/agent 0.16.2 → 0.17.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/LICENSE +669 -17
- package/README.md +25 -1080
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +12 -1234
- package/dist/index.d.ts +3 -7
- package/dist/index.js +3 -8
- package/dist/testing/index.d.ts +21 -50
- package/dist/testing/index.js +58 -89
- package/package.json +40 -104
- package/dist/acp.d.ts +0 -144
- package/dist/acp.js +0 -768
- package/dist/bootstrap/pi-feishu.d.ts +0 -20
- package/dist/bootstrap/pi-feishu.js +0 -4341
- package/dist/chunks/agent-loop.d.ts +0 -446
- package/dist/chunks/agent-loop.js +0 -158
- package/dist/chunks/background-session-authority.js +0 -230
- package/dist/chunks/background-session-control-input.js +0 -51
- package/dist/chunks/background-session-service.d.ts +0 -382
- package/dist/chunks/index.d.ts +0 -4448
- package/dist/chunks/pi-tool-proxy.d.ts +0 -120
- package/dist/chunks/pi.js +0 -406
- package/dist/chunks/rivus-agent-definition-resolver.js +0 -508
- package/dist/chunks/rivus-daemon-cli.js +0 -3839
- package/dist/chunks/rivus-model-management-wire.js +0 -344
- package/dist/chunks/rivus-plugin-testkit.d.ts +0 -214
- package/dist/chunks/rivus-plugin-testkit.js +0 -78
- package/dist/chunks/rivus-skill.d.ts +0 -95
- package/dist/chunks/rivus-tool.js +0 -158
- package/dist/chunks/sha256-digest.js +0 -7
- package/dist/chunks/src.js +0 -15313
- package/dist/mcp.d.ts +0 -92
- package/dist/mcp.js +0 -454
- package/dist/pi.d.ts +0 -129
- package/dist/pi.js +0 -3
- package/examples/a-share-briefing-analysis.mjs +0 -93
- package/examples/a-share-briefing-renderer.mjs +0 -257
- package/examples/a-share-index-evidence.mjs +0 -99
- package/examples/a-share-market-briefing.mjs +0 -83
- package/examples/a-share-market-date.mjs +0 -10
- package/examples/a-share-overseas-evidence.mjs +0 -86
- package/examples/a-share-policy-evidence.mjs +0 -145
- package/examples/a-share-provider-response.mjs +0 -21
- package/examples/a-share-sector-evidence.mjs +0 -70
- package/examples/acp-stdio-proxy.mjs +0 -58
- package/examples/current-weather.mjs +0 -117
- package/examples/html-drive-tools.mjs +0 -262
- package/examples/https-response-reader.mjs +0 -36
- package/examples/langfuse-drive-e2e.mjs +0 -175
- package/examples/pi-feishu-deployment.bootstrap.ts +0 -894
- package/examples/pi-feishu.bootstrap.ts +0 -242
- package/examples/rivus-agents.plugin.mjs +0 -290
- package/examples/rivus-langfuse-demo.config.json +0 -37
- package/examples/rivus-starter.plugin.mjs +0 -47
- package/examples/rivus.config.json +0 -114
- package/skills/runtime-management/SKILL.md +0 -65
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
//#region src/core/application/agent-catalog/contracts/rivus-tool.d.ts
|
|
2
|
-
type RivusMemoryScope = "conversation" | "agent-private" | "project" | "shared-user-profile";
|
|
3
|
-
type RivusToolRisk = "observe" | "mutate" | "irreversible" | "host-control";
|
|
4
|
-
type RivusToolIdempotency = "none" | "supported" | "required";
|
|
5
|
-
declare class RivusToolInputRejected extends Error {
|
|
6
|
-
readonly name: string;
|
|
7
|
-
}
|
|
8
|
-
interface RivusToolExecutor {
|
|
9
|
-
execute(input: unknown, context: RivusToolExecutionContext): unknown;
|
|
10
|
-
}
|
|
11
|
-
interface RivusToolExecutionOrigin {
|
|
12
|
-
readonly endpointId: string;
|
|
13
|
-
readonly tenantKey: string;
|
|
14
|
-
readonly conversationId?: string;
|
|
15
|
-
readonly allowedActorOpenIds: ReadonlyArray<string>;
|
|
16
|
-
}
|
|
17
|
-
interface RivusToolExecutionContext {
|
|
18
|
-
readonly agentId: string;
|
|
19
|
-
readonly instanceId: string;
|
|
20
|
-
readonly memory?: RivusMemoryAuthority;
|
|
21
|
-
readonly runId: string;
|
|
22
|
-
readonly callId: string;
|
|
23
|
-
readonly operationId?: string;
|
|
24
|
-
readonly policyEpoch: number;
|
|
25
|
-
readonly toolId: string;
|
|
26
|
-
readonly toolVersion: string;
|
|
27
|
-
readonly sessionKey: string;
|
|
28
|
-
readonly origin?: RivusToolExecutionOrigin;
|
|
29
|
-
readonly sourceMessageId?: string;
|
|
30
|
-
}
|
|
31
|
-
interface RivusMemoryAuthority {
|
|
32
|
-
readonly audience: "group" | "private";
|
|
33
|
-
readonly conversationId?: string;
|
|
34
|
-
readonly projectId?: string;
|
|
35
|
-
readonly scopes: ReadonlyArray<RivusMemoryScope>;
|
|
36
|
-
readonly subjectId: string;
|
|
37
|
-
readonly tenantId: string;
|
|
38
|
-
}
|
|
39
|
-
interface RivusToolFactoryContext {
|
|
40
|
-
readonly toolId: string;
|
|
41
|
-
readonly toolVersion: string;
|
|
42
|
-
}
|
|
43
|
-
interface RivusToolDescriptor {
|
|
44
|
-
readonly id: string;
|
|
45
|
-
readonly version: string;
|
|
46
|
-
readonly digest: string;
|
|
47
|
-
readonly description: string;
|
|
48
|
-
readonly inputSchema: unknown;
|
|
49
|
-
readonly risk: RivusToolRisk;
|
|
50
|
-
readonly idempotency: RivusToolIdempotency;
|
|
51
|
-
readonly createExecutor: (context: RivusToolFactoryContext) => RivusToolExecutor;
|
|
52
|
-
}
|
|
53
|
-
interface RivusHostToolDescriptor extends RivusToolDescriptor {
|
|
54
|
-
readonly replayCompleted?: (input: unknown, completedResult: unknown, context: RivusToolExecutionContext) => unknown;
|
|
55
|
-
}
|
|
56
|
-
interface RegisteredRivusTool extends RivusToolDescriptor {
|
|
57
|
-
readonly pluginId: string;
|
|
58
|
-
}
|
|
59
|
-
interface RivusResolvedToolDescriptor {
|
|
60
|
-
readonly id: string;
|
|
61
|
-
readonly version: string;
|
|
62
|
-
readonly digest: string;
|
|
63
|
-
readonly description: string;
|
|
64
|
-
readonly inputSchema: unknown;
|
|
65
|
-
readonly risk: RivusToolRisk;
|
|
66
|
-
readonly idempotency: RivusToolIdempotency;
|
|
67
|
-
readonly pluginId: string;
|
|
68
|
-
}
|
|
69
|
-
interface RivusToolGrantSet {
|
|
70
|
-
readonly toolIds: ReadonlyArray<string>;
|
|
71
|
-
readonly revision: string;
|
|
72
|
-
}
|
|
73
|
-
//#endregion
|
|
74
|
-
//#region src/core/application/agent-catalog/contracts/rivus-runtime-tool.d.ts
|
|
75
|
-
declare const RIVUS_RUNTIME_TOOL_IDS: readonly ["read", "bash", "edit", "write", "grep", "find", "ls"];
|
|
76
|
-
type RivusRuntimeToolId = (typeof RIVUS_RUNTIME_TOOL_IDS)[number];
|
|
77
|
-
declare function isRivusRuntimeToolId(value: string): value is RivusRuntimeToolId;
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/core/application/agent-catalog/contracts/rivus-skill.d.ts
|
|
80
|
-
interface RivusSkillDescriptor {
|
|
81
|
-
readonly id: string;
|
|
82
|
-
readonly version: string;
|
|
83
|
-
readonly digest: string;
|
|
84
|
-
readonly title: string;
|
|
85
|
-
readonly content: string;
|
|
86
|
-
}
|
|
87
|
-
interface RegisteredRivusSkill extends RivusSkillDescriptor {
|
|
88
|
-
readonly pluginId: string;
|
|
89
|
-
}
|
|
90
|
-
interface RivusSkillGrantSet {
|
|
91
|
-
readonly skillIds: ReadonlyArray<string>;
|
|
92
|
-
readonly revision: string;
|
|
93
|
-
}
|
|
94
|
-
//#endregion
|
|
95
|
-
export { RivusToolIdempotency as _, RivusRuntimeToolId as a, RivusHostToolDescriptor as c, RivusResolvedToolDescriptor as d, RivusToolDescriptor as f, RivusToolGrantSet as g, RivusToolFactoryContext as h, RIVUS_RUNTIME_TOOL_IDS as i, RivusMemoryAuthority as l, RivusToolExecutor as m, RivusSkillDescriptor as n, isRivusRuntimeToolId as o, RivusToolExecutionContext as p, RivusSkillGrantSet as r, RegisteredRivusTool as s, RegisteredRivusSkill as t, RivusMemoryScope as u, RivusToolInputRejected as v, RivusToolRisk as y };
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { Unsafe } from "typebox";
|
|
2
|
-
//#region src/core/application/tool-execution/authority/invocation-authority-registry.ts
|
|
3
|
-
const authorities = /* @__PURE__ */ new WeakMap();
|
|
4
|
-
let localAuthoritySequence = 0;
|
|
5
|
-
var InvalidInvocationAuthority = class extends Error {
|
|
6
|
-
name = "InvalidInvocationAuthority";
|
|
7
|
-
};
|
|
8
|
-
function createInvocationAuthority(authority, identity = { next: () => String(++localAuthoritySequence) }) {
|
|
9
|
-
const reference = Object.freeze({ id: `authority:${identity.next()}` });
|
|
10
|
-
authorities.set(reference, normalizeInvocationAuthority(authority));
|
|
11
|
-
return reference;
|
|
12
|
-
}
|
|
13
|
-
function resolveInvocationAuthority(reference) {
|
|
14
|
-
const authority = authorities.get(reference);
|
|
15
|
-
if (!authority) throw new InvalidInvocationAuthority("invocation authority was not issued by this host");
|
|
16
|
-
return authority;
|
|
17
|
-
}
|
|
18
|
-
function normalizeInvocationAuthority(authority) {
|
|
19
|
-
if (!isRecord(authority) || typeof authority.sourceMessageId !== "string" || !authority.sourceMessageId.trim()) throw new InvalidInvocationAuthority("invocation authority requires a trusted source message id");
|
|
20
|
-
if (authority.endpointId !== void 0 && (!authority.endpointId || !authority.endpointId.trim())) throw new InvalidInvocationAuthority("invocation authority requires a trusted endpoint id");
|
|
21
|
-
return Object.freeze({
|
|
22
|
-
...authority,
|
|
23
|
-
...authority.allowedActorOpenIds === void 0 ? {} : { allowedActorOpenIds: Object.freeze([...authority.allowedActorOpenIds]) },
|
|
24
|
-
...authority.memory === void 0 ? {} : { memory: freezeMemoryAuthority(authority.memory) },
|
|
25
|
-
toolGrantSet: freezeGrantSet(authority.toolGrantSet)
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
function freezeMemoryAuthority(value) {
|
|
29
|
-
const scopes = value.audience === "group" ? value.scopes.filter(isGroupMemoryScope) : [...value.scopes];
|
|
30
|
-
return Object.freeze({
|
|
31
|
-
...value,
|
|
32
|
-
scopes: Object.freeze(scopes)
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function freezeGrantSet(value) {
|
|
36
|
-
return Object.freeze({
|
|
37
|
-
revision: value.revision,
|
|
38
|
-
toolIds: Object.freeze([...value.toolIds])
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function isGroupMemoryScope(value) {
|
|
42
|
-
return value === "conversation" || value === "project";
|
|
43
|
-
}
|
|
44
|
-
function isRecord(value) {
|
|
45
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
46
|
-
}
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region src/core/application/tool-execution/brokerage/tool-input-digest.ts
|
|
49
|
-
var InvalidStableJson = class extends Error {
|
|
50
|
-
name = "InvalidStableJson";
|
|
51
|
-
};
|
|
52
|
-
var InvalidToolInput = class extends InvalidStableJson {
|
|
53
|
-
name = "InvalidToolInput";
|
|
54
|
-
};
|
|
55
|
-
function createToolInputDigest(input, digest) {
|
|
56
|
-
try {
|
|
57
|
-
return digest(serializeStableJson(input, /* @__PURE__ */ new Set()));
|
|
58
|
-
} catch (error) {
|
|
59
|
-
if (error instanceof InvalidStableJson) throw new InvalidToolInput(error.message);
|
|
60
|
-
throw error;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function normalizeStableJson(value) {
|
|
64
|
-
return JSON.parse(serializeStableJson(value, /* @__PURE__ */ new Set()));
|
|
65
|
-
}
|
|
66
|
-
function serializeStableJson(value, ancestors) {
|
|
67
|
-
if (value === null) return "null";
|
|
68
|
-
if (typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
|
|
69
|
-
if (typeof value === "number") {
|
|
70
|
-
if (!Number.isFinite(value)) throw new InvalidStableJson("stable JSON numbers must be finite");
|
|
71
|
-
return JSON.stringify(value);
|
|
72
|
-
}
|
|
73
|
-
if (typeof value !== "object" || value === null) throw new InvalidStableJson("value must contain only stable JSON values");
|
|
74
|
-
if (ancestors.has(value)) throw new InvalidStableJson("stable JSON must not contain cycles");
|
|
75
|
-
ancestors.add(value);
|
|
76
|
-
try {
|
|
77
|
-
if (Array.isArray(value)) {
|
|
78
|
-
const output = [];
|
|
79
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
80
|
-
if (!Object.hasOwn(value, index)) throw new InvalidStableJson("stable JSON arrays must not contain holes");
|
|
81
|
-
output.push(serializeStableJson(value[index], ancestors));
|
|
82
|
-
}
|
|
83
|
-
return `[${output.join(",")}]`;
|
|
84
|
-
}
|
|
85
|
-
if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new InvalidStableJson("stable JSON objects must be plain objects");
|
|
86
|
-
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${serializeStableJson(value[key], ancestors)}`).join(",")}}`;
|
|
87
|
-
} finally {
|
|
88
|
-
ancestors.delete(value);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
//#endregion
|
|
92
|
-
//#region src/core/application/tool-execution/authority/tool-risk-policy.ts
|
|
93
|
-
function requiresToolApproval(risk) {
|
|
94
|
-
return risk === "irreversible" || risk === "host-control";
|
|
95
|
-
}
|
|
96
|
-
//#endregion
|
|
97
|
-
//#region src/adapters/pi/skills/pi-skill-tool.ts
|
|
98
|
-
const PI_SKILL_READER_TOOL_NAME = "rivus_read_skill";
|
|
99
|
-
function createPiSkillRuntime(skills) {
|
|
100
|
-
if (skills.length === 0) return Object.freeze({ prompt: "" });
|
|
101
|
-
const skillsById = new Map(skills.map((skill) => [skill.id, skill]));
|
|
102
|
-
const prompt = [
|
|
103
|
-
"Granted Skills are versioned instructions loaded on demand.",
|
|
104
|
-
`Before following a Skill, call ${PI_SKILL_READER_TOOL_NAME} with its exact ID and follow the returned content.`,
|
|
105
|
-
"Granted Skill catalog:",
|
|
106
|
-
...skills.map((skill) => `- ${skill.id} | ${skill.title} | v${skill.version} | ${skill.digest}`)
|
|
107
|
-
].join("\n");
|
|
108
|
-
const tool = {
|
|
109
|
-
description: "Read the full versioned instructions for one Skill granted to this Agent Runtime.",
|
|
110
|
-
execute: async (_callId, input) => {
|
|
111
|
-
const skillId = readSkillId(input);
|
|
112
|
-
const skill = skillsById.get(skillId);
|
|
113
|
-
if (!skill) throw new Error(`Skill is not granted: ${skillId}`);
|
|
114
|
-
const details = {
|
|
115
|
-
contentLength: skill.content.length,
|
|
116
|
-
digest: skill.digest,
|
|
117
|
-
skillId: skill.id,
|
|
118
|
-
title: skill.title,
|
|
119
|
-
version: skill.version
|
|
120
|
-
};
|
|
121
|
-
return {
|
|
122
|
-
content: [{
|
|
123
|
-
text: skill.content,
|
|
124
|
-
type: "text"
|
|
125
|
-
}],
|
|
126
|
-
details
|
|
127
|
-
};
|
|
128
|
-
},
|
|
129
|
-
executionMode: "sequential",
|
|
130
|
-
label: "Read granted Skill",
|
|
131
|
-
name: PI_SKILL_READER_TOOL_NAME,
|
|
132
|
-
parameters: Unsafe({
|
|
133
|
-
additionalProperties: false,
|
|
134
|
-
properties: { skillId: {
|
|
135
|
-
description: "Exact Skill ID from the granted Skill catalog.",
|
|
136
|
-
type: "string"
|
|
137
|
-
} },
|
|
138
|
-
required: ["skillId"],
|
|
139
|
-
type: "object"
|
|
140
|
-
}),
|
|
141
|
-
promptSnippet: `${PI_SKILL_READER_TOOL_NAME}: read one granted Skill by exact ID`
|
|
142
|
-
};
|
|
143
|
-
return Object.freeze({
|
|
144
|
-
prompt,
|
|
145
|
-
tool
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
function readSkillId(input) {
|
|
149
|
-
if (input === null || typeof input !== "object" || Array.isArray(input) || typeof input.skillId !== "string") throw new Error("Skill reader input requires a string skillId");
|
|
150
|
-
return input.skillId;
|
|
151
|
-
}
|
|
152
|
-
//#endregion
|
|
153
|
-
//#region src/core/application/agent-catalog/contracts/rivus-tool.ts
|
|
154
|
-
var RivusToolInputRejected = class extends Error {
|
|
155
|
-
name = "RivusToolInputRejected";
|
|
156
|
-
};
|
|
157
|
-
//#endregion
|
|
158
|
-
export { InvalidStableJson as a, normalizeStableJson as c, resolveInvocationAuthority as d, requiresToolApproval as i, InvalidInvocationAuthority as l, PI_SKILL_READER_TOOL_NAME as n, InvalidToolInput as o, createPiSkillRuntime as r, createToolInputDigest as s, RivusToolInputRejected as t, createInvocationAuthority as u };
|