@rivus/agent 0.16.1 → 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.
- package/LICENSE +0 -1
- package/README.md +3 -1079
- package/dist/acp.d.ts +1 -143
- package/dist/acp.js +1 -767
- package/dist/bootstrap/pi-feishu.d.ts +1 -19
- package/dist/bootstrap/pi-feishu.js +1 -4335
- package/dist/chunks/rivus-plugin-testkit.d.ts +2 -189
- package/dist/chunks/rivus-plugin-testkit.js +4 -19
- package/dist/cli.js +12 -1234
- package/dist/index.d.ts +12 -7
- package/dist/index.js +4 -7
- package/dist/mcp.d.ts +1 -91
- package/dist/mcp.js +2 -450
- package/dist/pi.d.ts +1 -128
- package/dist/pi.js +1 -2
- package/dist/testing/index.d.ts +1 -1
- package/examples/pi-feishu-deployment.bootstrap.ts +3 -888
- package/package.json +50 -87
- 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-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
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { y as RivusToolRisk } from "./rivus-skill.js";
|
|
2
|
-
import { Effect } from "effect";
|
|
3
|
-
import { TSchema } from "typebox";
|
|
4
|
-
|
|
5
|
-
//#region src/core/application/tool-execution/authority/invocation-authority-registry.d.ts
|
|
6
|
-
type InvocationMemoryScope = "conversation" | "agent-private" | "project" | "shared-user-profile";
|
|
7
|
-
interface InvocationMemoryAuthority {
|
|
8
|
-
readonly audience: "group" | "private";
|
|
9
|
-
readonly conversationId?: string;
|
|
10
|
-
readonly projectId?: string;
|
|
11
|
-
readonly scopes: ReadonlyArray<InvocationMemoryScope>;
|
|
12
|
-
readonly subjectId: string;
|
|
13
|
-
readonly tenantId: string;
|
|
14
|
-
}
|
|
15
|
-
interface InvocationToolGrantSet {
|
|
16
|
-
readonly revision: string;
|
|
17
|
-
readonly toolIds: ReadonlyArray<string>;
|
|
18
|
-
}
|
|
19
|
-
interface InvocationAuthorityRef {
|
|
20
|
-
readonly id: string;
|
|
21
|
-
}
|
|
22
|
-
interface InvocationAuthority {
|
|
23
|
-
readonly agentId: string;
|
|
24
|
-
readonly allowedActorOpenIds?: ReadonlyArray<string>;
|
|
25
|
-
readonly conversationId?: string;
|
|
26
|
-
readonly endpointId?: string;
|
|
27
|
-
readonly instanceId: string;
|
|
28
|
-
readonly memory?: InvocationMemoryAuthority;
|
|
29
|
-
readonly runId: string;
|
|
30
|
-
readonly sessionKey: string;
|
|
31
|
-
readonly sourceMessageId: string;
|
|
32
|
-
readonly tenantKey: string;
|
|
33
|
-
readonly toolGrantSet: InvocationToolGrantSet;
|
|
34
|
-
}
|
|
35
|
-
declare class InvalidInvocationAuthority extends Error {
|
|
36
|
-
readonly name = "InvalidInvocationAuthority";
|
|
37
|
-
}
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region src/core/application/tool-execution/authority/tool-risk-policy.d.ts
|
|
40
|
-
type ToolRisk = "observe" | "mutate" | "irreversible" | "host-control";
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region src/core/application/tool-execution/brokerage/tool-broker-ports.d.ts
|
|
43
|
-
interface AuthorizationPolicyState {
|
|
44
|
-
readonly epoch: number;
|
|
45
|
-
readonly revokedToolIds: ReadonlyArray<string>;
|
|
46
|
-
}
|
|
47
|
-
interface ToolApprovalRequest {
|
|
48
|
-
readonly approvalId: string;
|
|
49
|
-
readonly agentId: string;
|
|
50
|
-
readonly instanceId: string;
|
|
51
|
-
readonly inputDigest: string;
|
|
52
|
-
readonly operationId: string;
|
|
53
|
-
readonly runId: string;
|
|
54
|
-
readonly sessionKey: string;
|
|
55
|
-
readonly tenantKey: string;
|
|
56
|
-
readonly callId: string;
|
|
57
|
-
readonly toolId: string;
|
|
58
|
-
readonly toolVersion: string;
|
|
59
|
-
readonly risk: ToolRisk;
|
|
60
|
-
}
|
|
61
|
-
interface ToolExecutionRequest {
|
|
62
|
-
readonly approvalId?: string;
|
|
63
|
-
readonly authority: InvocationAuthorityRef;
|
|
64
|
-
readonly callId: string;
|
|
65
|
-
readonly input: unknown;
|
|
66
|
-
readonly operationId?: string;
|
|
67
|
-
readonly toolId: string;
|
|
68
|
-
readonly version: string;
|
|
69
|
-
}
|
|
70
|
-
//#endregion
|
|
71
|
-
//#region src/adapters/pi/tool-execution/pi-tool-definition.d.ts
|
|
72
|
-
type PiToolContent = {
|
|
73
|
-
readonly text: string;
|
|
74
|
-
readonly textSignature?: string;
|
|
75
|
-
readonly type: "text";
|
|
76
|
-
} | {
|
|
77
|
-
readonly data: string;
|
|
78
|
-
readonly mimeType: string;
|
|
79
|
-
readonly type: "image";
|
|
80
|
-
};
|
|
81
|
-
interface PiToolResult<TDetails = unknown> {
|
|
82
|
-
readonly content: PiToolContent[];
|
|
83
|
-
readonly details: TDetails;
|
|
84
|
-
readonly terminate?: boolean;
|
|
85
|
-
}
|
|
86
|
-
interface PiToolDefinition<TDetails = unknown> {
|
|
87
|
-
readonly description: string;
|
|
88
|
-
readonly execute: (toolCallId: string, params: unknown, signal?: AbortSignal, onUpdate?: (result: PiToolResult<TDetails>) => void, context?: unknown) => Promise<PiToolResult<TDetails>>;
|
|
89
|
-
readonly executionMode?: "parallel" | "sequential";
|
|
90
|
-
readonly label: string;
|
|
91
|
-
readonly name: string;
|
|
92
|
-
readonly parameters: TSchema;
|
|
93
|
-
readonly promptGuidelines?: string[];
|
|
94
|
-
readonly promptSnippet?: string;
|
|
95
|
-
}
|
|
96
|
-
//#endregion
|
|
97
|
-
//#region src/adapters/pi/tool-execution/pi-tool-proxy.d.ts
|
|
98
|
-
interface PiToolApprovalRequest {
|
|
99
|
-
readonly agentId: string;
|
|
100
|
-
readonly allowedActorOpenIds: ReadonlyArray<string>;
|
|
101
|
-
readonly approvalId: string;
|
|
102
|
-
readonly callId: string;
|
|
103
|
-
readonly endpointId: string;
|
|
104
|
-
readonly inputDigest: string;
|
|
105
|
-
readonly instanceId: string;
|
|
106
|
-
readonly operationId: string;
|
|
107
|
-
readonly risk: RivusToolRisk;
|
|
108
|
-
readonly runId: string;
|
|
109
|
-
readonly sessionKey: string;
|
|
110
|
-
readonly signal?: AbortSignal;
|
|
111
|
-
readonly sourceMessageId: string;
|
|
112
|
-
readonly tenantKey: string;
|
|
113
|
-
readonly toolId: string;
|
|
114
|
-
readonly toolVersion: string;
|
|
115
|
-
}
|
|
116
|
-
interface PiToolApprovalGateway {
|
|
117
|
-
requestApproval(request: PiToolApprovalRequest): Promise<void>;
|
|
118
|
-
}
|
|
119
|
-
//#endregion
|
|
120
|
-
export { PiToolResult as a, ToolExecutionRequest as c, InvocationAuthorityRef as d, PiToolDefinition as i, InvalidInvocationAuthority as l, PiToolApprovalRequest as n, AuthorizationPolicyState as o, PiToolContent as r, ToolApprovalRequest as s, PiToolApprovalGateway as t, InvocationAuthority as u };
|
package/dist/chunks/pi.js
DELETED
|
@@ -1,406 +0,0 @@
|
|
|
1
|
-
import { l as toEffectAgentLoopInput } from "./agent-loop.js";
|
|
2
|
-
import { i as requiresToolApproval, s as createToolInputDigest$1, u as createInvocationAuthority } from "./rivus-tool.js";
|
|
3
|
-
import { t as createSha256Digest } from "./sha256-digest.js";
|
|
4
|
-
import { createHash } from "node:crypto";
|
|
5
|
-
import { readFile, realpath, stat } from "node:fs/promises";
|
|
6
|
-
import { isAbsolute, join, relative } from "node:path";
|
|
7
|
-
import { DefaultResourceLoader, SettingsManager, createBashToolDefinition, createReadToolDefinition, defineTool } from "@earendil-works/pi-coding-agent";
|
|
8
|
-
import { Unsafe } from "typebox";
|
|
9
|
-
import { realpathSync, statSync } from "node:fs";
|
|
10
|
-
//#region src/adapters/pi/tool-execution/pi-bash-tool.ts
|
|
11
|
-
const DEFAULT_TIMEOUT_SECONDS = 120;
|
|
12
|
-
/** Keep Pi's native execution, rendering and abort cleanup with a bounded default. */
|
|
13
|
-
function createPiBashTool(cwd, options) {
|
|
14
|
-
const { commandPrefix, shellPath, spawnHook } = options ?? {};
|
|
15
|
-
const tool = createBashToolDefinition(cwd, {
|
|
16
|
-
...commandPrefix === void 0 ? {} : { commandPrefix },
|
|
17
|
-
...shellPath === void 0 ? {} : { shellPath },
|
|
18
|
-
...spawnHook === void 0 ? {} : { spawnHook }
|
|
19
|
-
});
|
|
20
|
-
return defineTool({
|
|
21
|
-
...tool,
|
|
22
|
-
description: `${tool.description} Defaults to ${DEFAULT_TIMEOUT_SECONDS} seconds when timeout is omitted; set an explicit positive timeout for longer commands.`,
|
|
23
|
-
parameters: {
|
|
24
|
-
...tool.parameters,
|
|
25
|
-
properties: {
|
|
26
|
-
...tool.parameters.properties,
|
|
27
|
-
timeout: {
|
|
28
|
-
...tool.parameters.properties.timeout,
|
|
29
|
-
description: `Timeout in seconds (optional, defaults to ${DEFAULT_TIMEOUT_SECONDS})`
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
execute: (id, args, signal, onUpdate, context) => tool.execute(id, {
|
|
34
|
-
...args,
|
|
35
|
-
timeout: args.timeout === void 0 ? DEFAULT_TIMEOUT_SECONDS : args.timeout
|
|
36
|
-
}, signal, onUpdate, context)
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
//#endregion
|
|
40
|
-
//#region src/adapters/pi/skills/pi-skill-read-tool.ts
|
|
41
|
-
var ProjectSkillReadDenied = class extends Error {
|
|
42
|
-
name = "ProjectSkillReadDenied";
|
|
43
|
-
};
|
|
44
|
-
function createPiSkillReadTool(options) {
|
|
45
|
-
if (options.skillPaths.length === 0) throw new ProjectSkillReadDenied("Pi Skill read requires a trusted Skill source");
|
|
46
|
-
const allowedSources = options.skillPaths.map((source) => {
|
|
47
|
-
const path = realpathSync(source);
|
|
48
|
-
return Object.freeze({
|
|
49
|
-
directory: statSync(path).isDirectory(),
|
|
50
|
-
path
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
return createReadToolDefinition(options.cwd, { operations: {
|
|
54
|
-
access: async (absolutePath) => {
|
|
55
|
-
await stat(await authorize(absolutePath, allowedSources));
|
|
56
|
-
},
|
|
57
|
-
readFile: async (absolutePath) => readFile(await authorize(absolutePath, allowedSources))
|
|
58
|
-
} });
|
|
59
|
-
}
|
|
60
|
-
const createPiProjectSkillReadTool = createPiSkillReadTool;
|
|
61
|
-
function createPiSkillReadTools(options) {
|
|
62
|
-
if (options.skillPaths.length === 0 || options.runtimeToolIds.includes("read")) return [];
|
|
63
|
-
return [createPiSkillReadTool(options)];
|
|
64
|
-
}
|
|
65
|
-
async function authorize(path, sources) {
|
|
66
|
-
const candidate = await realpath(path);
|
|
67
|
-
for (const source of sources) {
|
|
68
|
-
if (!source.directory) {
|
|
69
|
-
if (candidate === source.path) return candidate;
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
const relation = relative(source.path, candidate);
|
|
73
|
-
if (relation === "" || !relation.startsWith("..") && !isAbsolute(relation)) return candidate;
|
|
74
|
-
}
|
|
75
|
-
throw new ProjectSkillReadDenied("read is restricted to the bound Pi Skill sources");
|
|
76
|
-
}
|
|
77
|
-
//#endregion
|
|
78
|
-
//#region src/adapters/pi/skills/pi-skill-catalog.ts
|
|
79
|
-
var InvalidPiSkillCatalog = class extends Error {
|
|
80
|
-
name = "InvalidPiSkillCatalog";
|
|
81
|
-
};
|
|
82
|
-
function validatePiSkillCatalog(input) {
|
|
83
|
-
const fatal = input.diagnostics.find(({ type }) => type === "error" || type === "collision");
|
|
84
|
-
if (fatal) throw new InvalidPiSkillCatalog(`Pi Skill discovery failed: ${fatal.message}${fatal.path ? ` (${fatal.path})` : ""}`);
|
|
85
|
-
const names = /* @__PURE__ */ new Set();
|
|
86
|
-
for (const { name } of input.skills) {
|
|
87
|
-
validateSkillName(name);
|
|
88
|
-
if (names.has(name)) throw new InvalidPiSkillCatalog(`Pi Skill discovery contains duplicate name: ${name}`);
|
|
89
|
-
names.add(name);
|
|
90
|
-
}
|
|
91
|
-
return names;
|
|
92
|
-
}
|
|
93
|
-
function validateSkillName(name) {
|
|
94
|
-
if (typeof name !== "string" || name.length === 0 || name.length > 64 || !/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(name) || name.includes("--")) throw new InvalidPiSkillCatalog(`Pi Skill discovery contains unsafe name: ${String(name)}`);
|
|
95
|
-
}
|
|
96
|
-
function validatePiSkillCommand(text, skillNames) {
|
|
97
|
-
if (!text.startsWith("/skill:")) return;
|
|
98
|
-
const name = text.slice(7).split(/\s/, 1)[0];
|
|
99
|
-
if (!skillNames.has(name)) throw new InvalidPiSkillCatalog(`Unknown Pi Skill: ${name}`);
|
|
100
|
-
}
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region src/adapters/pi/skills/pi-skill-sources.ts
|
|
103
|
-
var InvalidPiSkillSource = class extends Error {
|
|
104
|
-
name = "InvalidPiSkillSource";
|
|
105
|
-
};
|
|
106
|
-
async function resolvePiSkillSources(options) {
|
|
107
|
-
const roots = [];
|
|
108
|
-
const seen = /* @__PURE__ */ new Set();
|
|
109
|
-
for (const path of [join(options.agentDir, "skills"), join(options.homeDirectory, ".agents", "skills")]) {
|
|
110
|
-
const canonical = await optionalDirectory(path);
|
|
111
|
-
if (canonical) appendUnique(roots, seen, canonical);
|
|
112
|
-
}
|
|
113
|
-
for (const path of options.projectSkillPaths ?? []) appendUnique(roots, seen, await requiredSkillSource(path));
|
|
114
|
-
return Object.freeze(roots);
|
|
115
|
-
}
|
|
116
|
-
async function optionalDirectory(path) {
|
|
117
|
-
let canonical;
|
|
118
|
-
try {
|
|
119
|
-
canonical = await realpath(path);
|
|
120
|
-
} catch (error) {
|
|
121
|
-
if (isMissingPath(error)) return void 0;
|
|
122
|
-
throw new InvalidPiSkillSource(`failed to resolve optional user Skill directory: ${path}`, { cause: error });
|
|
123
|
-
}
|
|
124
|
-
if (!(await stat(canonical)).isDirectory()) throw new InvalidPiSkillSource(`user Skill source must be a directory: ${path}`);
|
|
125
|
-
return canonical;
|
|
126
|
-
}
|
|
127
|
-
async function requiredSkillSource(path) {
|
|
128
|
-
try {
|
|
129
|
-
const canonical = await realpath(path);
|
|
130
|
-
const metadata = await stat(canonical);
|
|
131
|
-
if (!metadata.isDirectory() && !metadata.isFile()) throw new InvalidPiSkillSource(`Project Space Skill source must be a file or directory: ${path}`);
|
|
132
|
-
return canonical;
|
|
133
|
-
} catch (error) {
|
|
134
|
-
if (error instanceof InvalidPiSkillSource) throw error;
|
|
135
|
-
throw new InvalidPiSkillSource(`required Project Space Skill source is unavailable: ${path}`, { cause: error });
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
function appendUnique(roots, seen, path) {
|
|
139
|
-
if (seen.has(path)) return;
|
|
140
|
-
seen.add(path);
|
|
141
|
-
roots.push(path);
|
|
142
|
-
}
|
|
143
|
-
function isMissingPath(error) {
|
|
144
|
-
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
145
|
-
}
|
|
146
|
-
//#endregion
|
|
147
|
-
//#region src/adapters/pi/tool-execution/pi-session-tools.ts
|
|
148
|
-
function resolvePiSessionToolNames(runtimeToolIds, customTools) {
|
|
149
|
-
const names = [];
|
|
150
|
-
const seen = /* @__PURE__ */ new Set();
|
|
151
|
-
for (const name of [...runtimeToolIds, ...customTools.map(({ name }) => name)]) {
|
|
152
|
-
if (seen.has(name)) throw new Error(`Pi Session Tool name collision: ${name}`);
|
|
153
|
-
seen.add(name);
|
|
154
|
-
names.push(name);
|
|
155
|
-
}
|
|
156
|
-
return Object.freeze(names);
|
|
157
|
-
}
|
|
158
|
-
//#endregion
|
|
159
|
-
//#region src/adapters/pi/runtime/pi-session-resources.ts
|
|
160
|
-
const PI_BEHAVIOR_SETTING_KEYS = Object.freeze([
|
|
161
|
-
"lastChangelogVersion",
|
|
162
|
-
"defaultProvider",
|
|
163
|
-
"defaultModel",
|
|
164
|
-
"defaultThinkingLevel",
|
|
165
|
-
"transport",
|
|
166
|
-
"steeringMode",
|
|
167
|
-
"followUpMode",
|
|
168
|
-
"theme",
|
|
169
|
-
"compaction",
|
|
170
|
-
"branchSummary",
|
|
171
|
-
"retry",
|
|
172
|
-
"hideThinkingBlock",
|
|
173
|
-
"showCacheMissNotices",
|
|
174
|
-
"externalEditor",
|
|
175
|
-
"shellPath",
|
|
176
|
-
"quietStartup",
|
|
177
|
-
"shellCommandPrefix",
|
|
178
|
-
"collapseChangelog",
|
|
179
|
-
"enableSkillCommands",
|
|
180
|
-
"terminal",
|
|
181
|
-
"images",
|
|
182
|
-
"enabledModels",
|
|
183
|
-
"doubleEscapeAction",
|
|
184
|
-
"treeFilterMode",
|
|
185
|
-
"thinkingBudgets",
|
|
186
|
-
"editorPaddingX",
|
|
187
|
-
"outputPad",
|
|
188
|
-
"autocompleteMaxVisible",
|
|
189
|
-
"showHardwareCursor",
|
|
190
|
-
"markdown",
|
|
191
|
-
"warnings",
|
|
192
|
-
"httpProxy",
|
|
193
|
-
"httpIdleTimeoutMs",
|
|
194
|
-
"websocketConnectTimeoutMs"
|
|
195
|
-
]);
|
|
196
|
-
async function createPiSessionResources(options) {
|
|
197
|
-
const settingsManager = createSanitizedSettingsManager(options.cwd, options.agentDir, options.settingsOverrides);
|
|
198
|
-
const commandPrefix = settingsManager.getShellCommandPrefix();
|
|
199
|
-
const shellPath = settingsManager.getShellPath();
|
|
200
|
-
const bashToolOptions = commandPrefix === void 0 && shellPath === void 0 ? void 0 : Object.freeze({
|
|
201
|
-
...commandPrefix === void 0 ? {} : { commandPrefix },
|
|
202
|
-
...shellPath === void 0 ? {} : { shellPath }
|
|
203
|
-
});
|
|
204
|
-
let skillPaths = await resolveSkillPaths(options);
|
|
205
|
-
let currentResourceLoader = createResourceLoader(options, settingsManager, skillPaths);
|
|
206
|
-
await currentResourceLoader.reload();
|
|
207
|
-
let skillNames = validatePiSkillCatalog(currentResourceLoader.getSkills());
|
|
208
|
-
const resourceLoader = createResourceLoaderFacade(() => currentResourceLoader, settingsManager);
|
|
209
|
-
return {
|
|
210
|
-
...bashToolOptions === void 0 ? {} : { bashToolOptions },
|
|
211
|
-
get skillNames() {
|
|
212
|
-
return skillNames;
|
|
213
|
-
},
|
|
214
|
-
get skillPaths() {
|
|
215
|
-
return skillPaths;
|
|
216
|
-
},
|
|
217
|
-
refresh: async () => {
|
|
218
|
-
const nextSkillPaths = await resolveSkillPaths(options);
|
|
219
|
-
const nextResourceLoader = createResourceLoader(options, settingsManager, nextSkillPaths);
|
|
220
|
-
await nextResourceLoader.reload();
|
|
221
|
-
const nextSkillNames = validatePiSkillCatalog(nextResourceLoader.getSkills());
|
|
222
|
-
skillPaths = nextSkillPaths;
|
|
223
|
-
currentResourceLoader = nextResourceLoader;
|
|
224
|
-
skillNames = nextSkillNames;
|
|
225
|
-
},
|
|
226
|
-
withSessionOptions: (sessionOptions) => Object.freeze({
|
|
227
|
-
...sessionOptions,
|
|
228
|
-
agentDir: options.agentDir,
|
|
229
|
-
cwd: options.cwd,
|
|
230
|
-
resourceLoader,
|
|
231
|
-
settingsManager
|
|
232
|
-
})
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
function createResourceLoaderFacade(getCurrent, settingsManager) {
|
|
236
|
-
return {
|
|
237
|
-
extendResources: (paths) => getCurrent().extendResources(paths),
|
|
238
|
-
getAgentsFiles: () => getCurrent().getAgentsFiles(),
|
|
239
|
-
getAppendSystemPrompt: () => getCurrent().getAppendSystemPrompt(),
|
|
240
|
-
getAppendSystemPromptSources: () => getCurrent().getAppendSystemPromptSources(),
|
|
241
|
-
getExtensions: () => getCurrent().getExtensions(),
|
|
242
|
-
getPrompts: () => getCurrent().getPrompts(),
|
|
243
|
-
getSkills: () => getCurrent().getSkills(),
|
|
244
|
-
getSystemPrompt: () => getCurrent().getSystemPrompt(),
|
|
245
|
-
getSystemPromptSource: () => getCurrent().getSystemPromptSource(),
|
|
246
|
-
getThemes: () => getCurrent().getThemes(),
|
|
247
|
-
reload: (reloadOptions) => getCurrent().reload(reloadOptions),
|
|
248
|
-
settingsManager
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
async function resolveSkillPaths(options) {
|
|
252
|
-
return resolvePiSkillSources({
|
|
253
|
-
agentDir: options.agentDir,
|
|
254
|
-
homeDirectory: options.homeDirectory,
|
|
255
|
-
...options.projectSkillPaths ? { projectSkillPaths: options.projectSkillPaths } : {}
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
function createResourceLoader(options, settingsManager, skillPaths) {
|
|
259
|
-
return new DefaultResourceLoader({
|
|
260
|
-
agentDir: options.agentDir,
|
|
261
|
-
additionalSkillPaths: [...skillPaths],
|
|
262
|
-
...options.appendSystemPromptOverride ? { appendSystemPromptOverride: options.appendSystemPromptOverride } : {},
|
|
263
|
-
cwd: options.cwd,
|
|
264
|
-
noContextFiles: true,
|
|
265
|
-
noExtensions: true,
|
|
266
|
-
noPromptTemplates: true,
|
|
267
|
-
noSkills: true,
|
|
268
|
-
noThemes: true,
|
|
269
|
-
settingsManager,
|
|
270
|
-
...options.systemPromptOverride ? { systemPromptOverride: options.systemPromptOverride } : {}
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
function createSanitizedSettingsManager(cwd, agentDir, settingsOverrides) {
|
|
274
|
-
const fileSettings = SettingsManager.create(cwd, agentDir, { projectTrusted: false }).getGlobalSettings();
|
|
275
|
-
const behaviorSettings = Object.fromEntries(PI_BEHAVIOR_SETTING_KEYS.flatMap((key) => fileSettings[key] === void 0 ? [] : [[key, fileSettings[key]]]));
|
|
276
|
-
for (const key of PI_BEHAVIOR_SETTING_KEYS) if (settingsOverrides?.[key] !== void 0) behaviorSettings[key] = settingsOverrides[key];
|
|
277
|
-
return SettingsManager.inMemory(behaviorSettings, { projectTrusted: false });
|
|
278
|
-
}
|
|
279
|
-
//#endregion
|
|
280
|
-
//#region src/adapters/pi/tool-execution/pi-tool-proxy.ts
|
|
281
|
-
function createPiToolProxyDefinitions$1(options) {
|
|
282
|
-
const names = /* @__PURE__ */ new Set();
|
|
283
|
-
return options.tools.map((tool) => {
|
|
284
|
-
const name = toPiToolName(tool.id);
|
|
285
|
-
if (names.has(name)) throw new Error(`Pi tool name collision: ${name}`);
|
|
286
|
-
names.add(name);
|
|
287
|
-
return {
|
|
288
|
-
description: tool.description,
|
|
289
|
-
execute: async (callId, input, signal) => {
|
|
290
|
-
const activeInput = options.getActiveInput();
|
|
291
|
-
const invocation = activeInput?.invocation;
|
|
292
|
-
if (!activeInput || !invocation) throw new Error(`tool ${tool.id} requires an active agent run with a trusted invocation`);
|
|
293
|
-
if (!invocation.tenantKey) throw new Error(`tool ${tool.id} requires a trusted tenant identity`);
|
|
294
|
-
throwIfAborted(signal ?? activeInput.abortSignal);
|
|
295
|
-
const inputDigest = createToolInputDigest(input);
|
|
296
|
-
const operationId = createBoundId("operation", {
|
|
297
|
-
agentId: options.agentId,
|
|
298
|
-
inputDigest,
|
|
299
|
-
instanceId: options.instanceId,
|
|
300
|
-
sourceMessageId: invocation.sourceMessageId,
|
|
301
|
-
toolId: tool.id,
|
|
302
|
-
toolVersion: tool.version
|
|
303
|
-
});
|
|
304
|
-
const approvalId = createBoundId("approval", {
|
|
305
|
-
callId,
|
|
306
|
-
operationId,
|
|
307
|
-
runId: activeInput.runId
|
|
308
|
-
});
|
|
309
|
-
if (requiresToolApproval(tool.risk)) {
|
|
310
|
-
if (invocation.allowedActorOpenIds.length === 0) throw new Error(`tool ${tool.id} requires at least one trusted approval actor`);
|
|
311
|
-
await options.approvals.requestApproval({
|
|
312
|
-
agentId: options.agentId,
|
|
313
|
-
allowedActorOpenIds: invocation.allowedActorOpenIds,
|
|
314
|
-
approvalId,
|
|
315
|
-
callId,
|
|
316
|
-
endpointId: invocation.endpointId,
|
|
317
|
-
inputDigest,
|
|
318
|
-
instanceId: options.instanceId,
|
|
319
|
-
operationId,
|
|
320
|
-
risk: tool.risk,
|
|
321
|
-
runId: activeInput.runId,
|
|
322
|
-
sessionKey: activeInput.sessionKey,
|
|
323
|
-
signal: signal ?? activeInput.abortSignal,
|
|
324
|
-
sourceMessageId: invocation.sourceMessageId,
|
|
325
|
-
tenantKey: invocation.tenantKey,
|
|
326
|
-
toolId: tool.id,
|
|
327
|
-
toolVersion: tool.version
|
|
328
|
-
});
|
|
329
|
-
throwIfAborted(signal ?? activeInput.abortSignal);
|
|
330
|
-
}
|
|
331
|
-
const result = await options.broker.execute({
|
|
332
|
-
authority: createInvocationAuthority({
|
|
333
|
-
agentId: options.agentId,
|
|
334
|
-
allowedActorOpenIds: invocation.allowedActorOpenIds,
|
|
335
|
-
...invocation.kind === "background-session" ? invocation.conversationId ? { conversationId: invocation.conversationId } : {} : invocation.memory?.conversationId ? { conversationId: invocation.memory.conversationId } : {},
|
|
336
|
-
endpointId: invocation.endpointId,
|
|
337
|
-
instanceId: options.instanceId,
|
|
338
|
-
...invocation.memory ? { memory: {
|
|
339
|
-
...invocation.memory,
|
|
340
|
-
scopes: options.memoryScopes ?? []
|
|
341
|
-
} } : {},
|
|
342
|
-
runId: activeInput.runId,
|
|
343
|
-
sessionKey: activeInput.sessionKey,
|
|
344
|
-
sourceMessageId: invocation.sourceMessageId,
|
|
345
|
-
tenantKey: invocation.tenantKey,
|
|
346
|
-
toolGrantSet: options.toolGrantSet
|
|
347
|
-
}),
|
|
348
|
-
callId,
|
|
349
|
-
input,
|
|
350
|
-
operationId,
|
|
351
|
-
...requiresToolApproval(tool.risk) ? { approvalId } : {},
|
|
352
|
-
toolId: tool.id,
|
|
353
|
-
version: tool.version
|
|
354
|
-
});
|
|
355
|
-
return {
|
|
356
|
-
content: [{
|
|
357
|
-
text: stringifyToolResult(result),
|
|
358
|
-
type: "text"
|
|
359
|
-
}],
|
|
360
|
-
details: result
|
|
361
|
-
};
|
|
362
|
-
},
|
|
363
|
-
executionMode: "sequential",
|
|
364
|
-
label: tool.id,
|
|
365
|
-
name,
|
|
366
|
-
parameters: Unsafe(tool.inputSchema),
|
|
367
|
-
promptSnippet: `${name}: ${tool.description}`
|
|
368
|
-
};
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
function createToolInputDigest(input) {
|
|
372
|
-
return createToolInputDigest$1(input, createSha256Digest);
|
|
373
|
-
}
|
|
374
|
-
function createPiToolNameResolver$1(tools) {
|
|
375
|
-
const toolIdsByPiName = new Map(tools.map((tool) => [toPiToolName(tool.id), tool.id]));
|
|
376
|
-
return (toolName) => toolIdsByPiName.get(toolName) ?? toolName;
|
|
377
|
-
}
|
|
378
|
-
function toPiToolName(toolId) {
|
|
379
|
-
return `rivus_${toolId.replace(/[^a-zA-Z0-9_-]/g, "_")}`;
|
|
380
|
-
}
|
|
381
|
-
function createBoundId(kind, binding) {
|
|
382
|
-
return `${kind}:${createHash("sha256").update(JSON.stringify(binding)).digest("hex")}`;
|
|
383
|
-
}
|
|
384
|
-
function throwIfAborted(signal) {
|
|
385
|
-
if (signal.aborted) throw signal.reason ?? /* @__PURE__ */ new Error("tool execution was aborted");
|
|
386
|
-
}
|
|
387
|
-
function stringifyToolResult(result) {
|
|
388
|
-
if (typeof result === "string") return result;
|
|
389
|
-
return JSON.stringify(result ?? null);
|
|
390
|
-
}
|
|
391
|
-
//#endregion
|
|
392
|
-
//#region src/adapters/compatibility/agent-execution/pi/pi-tool-proxy.ts
|
|
393
|
-
function createPiToolProxyDefinitions(options) {
|
|
394
|
-
return createPiToolProxyDefinitions$1({
|
|
395
|
-
...options,
|
|
396
|
-
getActiveInput: () => {
|
|
397
|
-
const input = options.getActiveInput();
|
|
398
|
-
return input ? toEffectAgentLoopInput(input) : void 0;
|
|
399
|
-
}
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
function createPiToolNameResolver(tools) {
|
|
403
|
-
return createPiToolNameResolver$1(tools);
|
|
404
|
-
}
|
|
405
|
-
//#endregion
|
|
406
|
-
export { InvalidPiSkillSource as a, validatePiSkillCatalog as c, createPiProjectSkillReadTool as d, createPiSkillReadTool as f, resolvePiSessionToolNames as i, validatePiSkillCommand as l, createPiBashTool as m, createPiToolProxyDefinitions as n, resolvePiSkillSources as o, createPiSkillReadTools as p, createPiSessionResources as r, InvalidPiSkillCatalog as s, createPiToolNameResolver as t, ProjectSkillReadDenied as u };
|