@rivus/agent 0.14.3 → 0.15.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/README.md +1 -1
- package/dist/acp.js +1 -2
- package/dist/bootstrap/pi-feishu.d.ts +2 -2
- package/dist/bootstrap/pi-feishu.js +4119 -389
- 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 +1294 -515
- package/dist/chunks/pi-tool-proxy.d.ts +22 -90
- package/dist/chunks/pi.js +60 -20
- package/dist/chunks/rivus-agent-definition-resolver.js +508 -0
- package/dist/chunks/rivus-daemon-cli.js +3004 -3164
- package/dist/chunks/rivus-model-management-wire.js +344 -0
- 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/rivus-tool.js +158 -0
- package/dist/chunks/sha256-digest.js +2 -7
- package/dist/chunks/src.js +13402 -8264
- package/dist/cli.js +901 -698
- package/dist/index.d.ts +7 -8
- package/dist/index.js +8 -9
- package/dist/mcp.d.ts +46 -7
- package/dist/mcp.js +145 -19
- package/dist/pi.d.ts +5 -4
- package/dist/pi.js +1 -1
- package/examples/pi-feishu-deployment.bootstrap.ts +557 -462
- package/package.json +9 -7
- package/skills/runtime-management/SKILL.md +61 -0
- 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
package/dist/chunks/api3.d.ts
DELETED
|
@@ -1,402 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
|
|
3
|
-
//#region src/modules/background-session/domain/session/background-session-model.d.ts
|
|
4
|
-
type BackgroundSessionMemoryScope = "conversation" | "agent-private" | "project" | "shared-user-profile";
|
|
5
|
-
interface BackgroundSessionMemoryIdentity {
|
|
6
|
-
readonly audience: "group" | "private";
|
|
7
|
-
readonly conversationId?: string;
|
|
8
|
-
readonly projectId?: string;
|
|
9
|
-
readonly subjectId: string;
|
|
10
|
-
readonly tenantId: string;
|
|
11
|
-
}
|
|
12
|
-
type BackgroundSessionId = string;
|
|
13
|
-
type BackgroundSessionPhase = "queued" | "running" | "waiting" | "input-required" | "stopping" | "stopped" | "completed" | "failed" | "reconciliation-required";
|
|
14
|
-
declare function isBackgroundSessionTerminalPhase(phase: BackgroundSessionPhase): boolean;
|
|
15
|
-
interface BackgroundSessionLease {
|
|
16
|
-
readonly owner: string;
|
|
17
|
-
readonly epoch: number;
|
|
18
|
-
readonly expiresAt: string;
|
|
19
|
-
}
|
|
20
|
-
interface BackgroundSessionOrigin {
|
|
21
|
-
readonly endpointId: string;
|
|
22
|
-
readonly tenantKey: string;
|
|
23
|
-
readonly conversationId?: string;
|
|
24
|
-
readonly allowedActorOpenIds: ReadonlyArray<string>;
|
|
25
|
-
readonly memory?: BackgroundSessionMemoryIdentity;
|
|
26
|
-
}
|
|
27
|
-
interface BackgroundSessionAuthority {
|
|
28
|
-
readonly agentId: string;
|
|
29
|
-
readonly profileRevision: string;
|
|
30
|
-
readonly toolGrantRevision: string;
|
|
31
|
-
readonly policyEpoch: number;
|
|
32
|
-
readonly memoryScopes: ReadonlyArray<BackgroundSessionMemoryScope>;
|
|
33
|
-
readonly projectSpaceId?: string;
|
|
34
|
-
readonly sessionKey: string;
|
|
35
|
-
}
|
|
36
|
-
interface BackgroundSessionTerminalResult {
|
|
37
|
-
readonly text: string;
|
|
38
|
-
readonly stepRunId: string;
|
|
39
|
-
readonly completedAt: string;
|
|
40
|
-
}
|
|
41
|
-
interface BackgroundSessionCancellation {
|
|
42
|
-
readonly reason: string;
|
|
43
|
-
readonly requestedAt: string;
|
|
44
|
-
}
|
|
45
|
-
interface BackgroundSessionState {
|
|
46
|
-
readonly sessionId: BackgroundSessionId;
|
|
47
|
-
readonly displayName: string;
|
|
48
|
-
readonly phase: BackgroundSessionPhase;
|
|
49
|
-
readonly revision: number;
|
|
50
|
-
readonly parentRunId: string;
|
|
51
|
-
readonly sourceMessageId: string;
|
|
52
|
-
readonly origin: BackgroundSessionOrigin;
|
|
53
|
-
readonly authority: BackgroundSessionAuthority;
|
|
54
|
-
readonly prompt: string;
|
|
55
|
-
readonly stepCount: number;
|
|
56
|
-
readonly wakeCount: number;
|
|
57
|
-
readonly currentStepRunId?: string;
|
|
58
|
-
readonly lastWakeText?: string;
|
|
59
|
-
readonly pendingInput: ReadonlyArray<string>;
|
|
60
|
-
readonly wakeAt?: string;
|
|
61
|
-
readonly lease?: BackgroundSessionLease;
|
|
62
|
-
readonly cancellation?: BackgroundSessionCancellation;
|
|
63
|
-
readonly consecutiveFailures: number;
|
|
64
|
-
readonly result?: BackgroundSessionTerminalResult;
|
|
65
|
-
readonly errorMessage?: string;
|
|
66
|
-
readonly reconciliationNote?: string;
|
|
67
|
-
readonly createdAt: string;
|
|
68
|
-
readonly updatedAt: string;
|
|
69
|
-
}
|
|
70
|
-
declare class BackgroundSessionTransitionDenied extends Error {
|
|
71
|
-
readonly sessionId: BackgroundSessionId;
|
|
72
|
-
readonly name = "BackgroundSessionTransitionDenied";
|
|
73
|
-
constructor(sessionId: BackgroundSessionId, message: string);
|
|
74
|
-
}
|
|
75
|
-
//#endregion
|
|
76
|
-
//#region src/modules/background-session/application/authority/background-session-identity.d.ts
|
|
77
|
-
declare const BACKGROUND_SESSION_SESSION_KEY_PREFIX = "background";
|
|
78
|
-
declare function createBackgroundSessionKey(sessionId: string): string;
|
|
79
|
-
declare function createBackgroundSessionStepSourceMessageId(sessionId: string, stepCount: number): string;
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region src/modules/background-session/application/authority/background-session-authority.d.ts
|
|
82
|
-
declare const BACKGROUND_SESSION_TOOL_IDS: readonly ["background.start", "background.wait", "background.list", "background.status", "background.send", "background.stop"];
|
|
83
|
-
declare const BACKGROUND_SESSION_START_TOOL_ID = "background.start";
|
|
84
|
-
declare const BACKGROUND_SESSION_TOOL_PLUGIN_ID = "rivus-core";
|
|
85
|
-
declare const BACKGROUND_SESSION_TOOL_VERSION = "1.0.0";
|
|
86
|
-
interface BackgroundSessionToolContract {
|
|
87
|
-
readonly description: string;
|
|
88
|
-
readonly digest: string;
|
|
89
|
-
readonly id: string;
|
|
90
|
-
readonly idempotency: "none" | "supported" | "required";
|
|
91
|
-
readonly inputSchema: unknown;
|
|
92
|
-
readonly pluginId: string;
|
|
93
|
-
readonly risk: "observe" | "mutate" | "irreversible" | "host-control";
|
|
94
|
-
readonly version: string;
|
|
95
|
-
}
|
|
96
|
-
interface BackgroundSessionToolGrantSet {
|
|
97
|
-
readonly revision: string;
|
|
98
|
-
readonly toolIds: ReadonlyArray<string>;
|
|
99
|
-
}
|
|
100
|
-
interface BackgroundSessionAgentDefinition {
|
|
101
|
-
readonly agentId: string;
|
|
102
|
-
readonly endpointIds: ReadonlyArray<string>;
|
|
103
|
-
readonly memory: {
|
|
104
|
-
readonly scopes: ReadonlyArray<BackgroundSessionMemoryScope>;
|
|
105
|
-
};
|
|
106
|
-
readonly model: Readonly<Record<string, unknown>>;
|
|
107
|
-
readonly pluginId: string;
|
|
108
|
-
readonly profileId: string;
|
|
109
|
-
readonly profileRevision: string;
|
|
110
|
-
readonly projectSpaceId?: string;
|
|
111
|
-
readonly projectSpaceRevision?: string;
|
|
112
|
-
readonly skillGrantSet: {
|
|
113
|
-
readonly revision: string;
|
|
114
|
-
readonly skillIds: ReadonlyArray<string>;
|
|
115
|
-
};
|
|
116
|
-
readonly skills: ReadonlyArray<unknown>;
|
|
117
|
-
readonly systemPrompt: string;
|
|
118
|
-
readonly tools: ReadonlyArray<BackgroundSessionToolContract>;
|
|
119
|
-
readonly toolGrantSet: BackgroundSessionToolGrantSet;
|
|
120
|
-
}
|
|
121
|
-
type TransformedBackgroundSessionDefinition<T extends BackgroundSessionAgentDefinition> = Omit<T, "toolGrantSet" | "tools"> & {
|
|
122
|
-
readonly toolGrantSet: BackgroundSessionToolGrantSet;
|
|
123
|
-
readonly tools: ReadonlyArray<BackgroundSessionToolContract>;
|
|
124
|
-
};
|
|
125
|
-
declare function createBackgroundSessionToolContracts(): ReadonlyArray<BackgroundSessionToolContract>;
|
|
126
|
-
declare function backgroundSessionToolIds(): ReadonlyArray<string>;
|
|
127
|
-
declare function isBackgroundSessionToolId(toolId: string): boolean;
|
|
128
|
-
declare function extendBackgroundSessionDefinition<T extends BackgroundSessionAgentDefinition>(definition: T): TransformedBackgroundSessionDefinition<T>;
|
|
129
|
-
declare function narrowBackgroundSessionDefinition<T extends BackgroundSessionAgentDefinition>(definition: T): TransformedBackgroundSessionDefinition<T>;
|
|
130
|
-
//#endregion
|
|
131
|
-
//#region src/modules/background-session/application/session/background-session-delivery-store.d.ts
|
|
132
|
-
type BackgroundSessionDeliveryKind = "progress" | "final" | "stopped" | "failed" | "reconciliation";
|
|
133
|
-
interface BackgroundSessionDeliveryRecord {
|
|
134
|
-
readonly deliveryId: string;
|
|
135
|
-
readonly sessionId: string;
|
|
136
|
-
readonly kind: BackgroundSessionDeliveryKind;
|
|
137
|
-
readonly text: string;
|
|
138
|
-
readonly state: "pending" | "delivered";
|
|
139
|
-
readonly revision: number;
|
|
140
|
-
readonly providerMessageId?: string;
|
|
141
|
-
readonly createdAt: string;
|
|
142
|
-
}
|
|
143
|
-
interface BackgroundSessionDeliveryStore {
|
|
144
|
-
enqueue(input: {
|
|
145
|
-
readonly deliveryId: string;
|
|
146
|
-
readonly sessionId: string;
|
|
147
|
-
readonly kind: BackgroundSessionDeliveryKind;
|
|
148
|
-
readonly text: string;
|
|
149
|
-
readonly createdAt: string;
|
|
150
|
-
}): Promise<BackgroundSessionDeliveryRecord>;
|
|
151
|
-
pending(): Promise<ReadonlyArray<BackgroundSessionDeliveryRecord>>;
|
|
152
|
-
markDelivered(deliveryId: string, providerMessageId: string): Promise<BackgroundSessionDeliveryRecord | undefined>;
|
|
153
|
-
}
|
|
154
|
-
declare class BackgroundSessionDeliveryConflict extends Error {
|
|
155
|
-
readonly name = "BackgroundSessionDeliveryConflict";
|
|
156
|
-
constructor(deliveryId: string, message: string);
|
|
157
|
-
}
|
|
158
|
-
//#endregion
|
|
159
|
-
//#region src/modules/background-session/application/session/background-session-repository.d.ts
|
|
160
|
-
interface BackgroundSessionLeasePrecondition {
|
|
161
|
-
readonly kind: "absent";
|
|
162
|
-
}
|
|
163
|
-
interface BackgroundSessionLeaseRequirement {
|
|
164
|
-
readonly kind: "held";
|
|
165
|
-
readonly owner: string;
|
|
166
|
-
readonly epoch: number;
|
|
167
|
-
}
|
|
168
|
-
interface BackgroundSessionLeaseStaleOrAbsent {
|
|
169
|
-
readonly kind: "absent-or-stale";
|
|
170
|
-
}
|
|
171
|
-
interface BackgroundSessionRepository {
|
|
172
|
-
create(state: BackgroundSessionState): Promise<BackgroundSessionState>;
|
|
173
|
-
get(sessionId: string): Promise<BackgroundSessionState | undefined>;
|
|
174
|
-
list(options?: {
|
|
175
|
-
readonly phase?: BackgroundSessionPhase;
|
|
176
|
-
readonly limit?: number;
|
|
177
|
-
}): Promise<ReadonlyArray<BackgroundSessionState>>;
|
|
178
|
-
update(input: {
|
|
179
|
-
readonly sessionId: string;
|
|
180
|
-
readonly expectedRevision: number;
|
|
181
|
-
readonly expectedLease?: BackgroundSessionLeasePrecondition | BackgroundSessionLeaseRequirement | BackgroundSessionLeaseStaleOrAbsent;
|
|
182
|
-
readonly now?: string;
|
|
183
|
-
readonly build: (state: BackgroundSessionState) => BackgroundSessionState;
|
|
184
|
-
}): Promise<BackgroundSessionState | undefined>;
|
|
185
|
-
}
|
|
186
|
-
declare class BackgroundSessionRepositoryConflict extends Error {
|
|
187
|
-
readonly name = "BackgroundSessionRepositoryConflict";
|
|
188
|
-
constructor(sessionId: string, message: string);
|
|
189
|
-
}
|
|
190
|
-
declare class BackgroundSessionRepositoryCorrupted extends Error {
|
|
191
|
-
readonly name = "BackgroundSessionRepositoryCorrupted";
|
|
192
|
-
}
|
|
193
|
-
//#endregion
|
|
194
|
-
//#region src/modules/background-session/application/session/background-session-service.d.ts
|
|
195
|
-
interface BackgroundSessionExecutionOrigin {
|
|
196
|
-
readonly allowedActorOpenIds: ReadonlyArray<string>;
|
|
197
|
-
readonly conversationId?: string;
|
|
198
|
-
readonly endpointId: string;
|
|
199
|
-
readonly tenantKey: string;
|
|
200
|
-
}
|
|
201
|
-
interface BackgroundSessionExecutionContext {
|
|
202
|
-
readonly agentId: string;
|
|
203
|
-
readonly callId: string;
|
|
204
|
-
readonly instanceId: string;
|
|
205
|
-
readonly memory?: BackgroundSessionMemoryIdentity & {
|
|
206
|
-
readonly scopes: ReadonlyArray<BackgroundSessionMemoryScope>;
|
|
207
|
-
};
|
|
208
|
-
readonly operationId?: string;
|
|
209
|
-
readonly origin?: BackgroundSessionExecutionOrigin;
|
|
210
|
-
readonly policyEpoch: number;
|
|
211
|
-
readonly runId: string;
|
|
212
|
-
readonly sessionKey: string;
|
|
213
|
-
readonly sourceMessageId?: string;
|
|
214
|
-
readonly toolId: string;
|
|
215
|
-
readonly toolVersion: string;
|
|
216
|
-
}
|
|
217
|
-
interface BackgroundSessionSummary {
|
|
218
|
-
readonly sessionId: string;
|
|
219
|
-
readonly displayName: string;
|
|
220
|
-
readonly phase: BackgroundSessionPhase;
|
|
221
|
-
readonly stepCount: number;
|
|
222
|
-
readonly wakeAt?: string;
|
|
223
|
-
readonly createdAt: string;
|
|
224
|
-
readonly updatedAt: string;
|
|
225
|
-
}
|
|
226
|
-
interface BackgroundSessionDetail extends BackgroundSessionSummary {
|
|
227
|
-
readonly parentRunId: string;
|
|
228
|
-
readonly pendingInput: ReadonlyArray<string>;
|
|
229
|
-
readonly result?: BackgroundSessionState["result"];
|
|
230
|
-
readonly errorMessage?: string;
|
|
231
|
-
readonly cancellationReason?: string;
|
|
232
|
-
readonly reconciliationNote?: string;
|
|
233
|
-
}
|
|
234
|
-
declare class BackgroundSessionCallerDenied extends Error {
|
|
235
|
-
readonly name = "BackgroundSessionCallerDenied";
|
|
236
|
-
constructor(message: string);
|
|
237
|
-
}
|
|
238
|
-
interface BackgroundSessionServiceOptions {
|
|
239
|
-
readonly clock: {
|
|
240
|
-
now(): string;
|
|
241
|
-
};
|
|
242
|
-
readonly deliveries: BackgroundSessionDeliveryStore;
|
|
243
|
-
readonly repository: BackgroundSessionRepository;
|
|
244
|
-
}
|
|
245
|
-
interface BackgroundSessionService {
|
|
246
|
-
list(input: {
|
|
247
|
-
readonly context: BackgroundSessionExecutionContext;
|
|
248
|
-
readonly limit?: number;
|
|
249
|
-
readonly phase?: BackgroundSessionPhase;
|
|
250
|
-
}): Promise<ReadonlyArray<BackgroundSessionSummary>>;
|
|
251
|
-
resolveReconciliation(input: {
|
|
252
|
-
readonly outcome: "continue" | "stop";
|
|
253
|
-
readonly sessionId: string;
|
|
254
|
-
}): Promise<BackgroundSessionSummary>;
|
|
255
|
-
send(input: {
|
|
256
|
-
readonly context: BackgroundSessionExecutionContext;
|
|
257
|
-
readonly message: string;
|
|
258
|
-
readonly sessionId: string;
|
|
259
|
-
}): Promise<BackgroundSessionSummary>;
|
|
260
|
-
start(input: {
|
|
261
|
-
readonly authority: BackgroundSessionAuthority;
|
|
262
|
-
readonly context: BackgroundSessionExecutionContext;
|
|
263
|
-
readonly displayName?: string;
|
|
264
|
-
readonly prompt: string;
|
|
265
|
-
readonly sessionId: string;
|
|
266
|
-
}): Promise<BackgroundSessionSummary>;
|
|
267
|
-
status(input: {
|
|
268
|
-
readonly context: BackgroundSessionExecutionContext;
|
|
269
|
-
readonly sessionId: string;
|
|
270
|
-
}): Promise<BackgroundSessionDetail>;
|
|
271
|
-
stop(input: {
|
|
272
|
-
readonly context: BackgroundSessionExecutionContext;
|
|
273
|
-
readonly reason?: string;
|
|
274
|
-
readonly sessionId: string;
|
|
275
|
-
}): Promise<BackgroundSessionSummary>;
|
|
276
|
-
wait(input: {
|
|
277
|
-
readonly context: BackgroundSessionExecutionContext;
|
|
278
|
-
readonly delayMs?: number;
|
|
279
|
-
readonly reason?: string;
|
|
280
|
-
readonly until?: string;
|
|
281
|
-
}): Promise<BackgroundSessionSummary>;
|
|
282
|
-
}
|
|
283
|
-
declare function createBackgroundSessionService(options: BackgroundSessionServiceOptions): BackgroundSessionService;
|
|
284
|
-
declare function sessionIdFromSessionKey(sessionKey: string): string | undefined;
|
|
285
|
-
declare function terminalDeliveryId(sessionId: string, kind: BackgroundSessionDeliveryKind): string;
|
|
286
|
-
declare function progressDeliveryId(sessionId: string, stepCount: number): string;
|
|
287
|
-
//#endregion
|
|
288
|
-
//#region src/modules/background-session/application/control/background-session-control.d.ts
|
|
289
|
-
type BackgroundSessionControlCommand = "start" | "wait" | "list" | "status" | "send" | "stop";
|
|
290
|
-
interface BackgroundSessionControlOrigin {
|
|
291
|
-
readonly allowedActorOpenIds: ReadonlyArray<string>;
|
|
292
|
-
readonly conversationId?: string;
|
|
293
|
-
readonly endpointId: string;
|
|
294
|
-
readonly tenantKey: string;
|
|
295
|
-
}
|
|
296
|
-
interface BackgroundSessionControlContext {
|
|
297
|
-
readonly agentId: string;
|
|
298
|
-
readonly authority: BackgroundSessionAuthority;
|
|
299
|
-
readonly origin: BackgroundSessionControlOrigin;
|
|
300
|
-
readonly policyEpoch: number;
|
|
301
|
-
readonly runId: string;
|
|
302
|
-
readonly sessionKey: string;
|
|
303
|
-
readonly sourceMessageId: string;
|
|
304
|
-
}
|
|
305
|
-
interface BackgroundSessionControl {
|
|
306
|
-
handle(command: BackgroundSessionControlCommand, context: BackgroundSessionControlContext, input: unknown): Promise<unknown>;
|
|
307
|
-
}
|
|
308
|
-
declare function createBackgroundSessionControl(options: {
|
|
309
|
-
readonly service: BackgroundSessionService;
|
|
310
|
-
}): BackgroundSessionControl;
|
|
311
|
-
declare class BackgroundSessionControlError extends Error {
|
|
312
|
-
readonly name = "BackgroundSessionControlError";
|
|
313
|
-
}
|
|
314
|
-
declare function toControlContext(input: {
|
|
315
|
-
readonly agentId: string;
|
|
316
|
-
readonly authority: BackgroundSessionAuthority;
|
|
317
|
-
readonly origin: BackgroundSessionControlOrigin;
|
|
318
|
-
readonly policyEpoch: number;
|
|
319
|
-
readonly sessionKey: string;
|
|
320
|
-
readonly sourceMessageId?: string;
|
|
321
|
-
}): BackgroundSessionControlContext;
|
|
322
|
-
//#endregion
|
|
323
|
-
//#region src/modules/background-session/application/supervision/background-session-config.d.ts
|
|
324
|
-
declare const DEFAULT_BACKGROUND_SESSION_STEP_TIMEOUT_MS: number;
|
|
325
|
-
declare const DEFAULT_BACKGROUND_SESSION_MAX_CONCURRENT_SESSIONS = 4;
|
|
326
|
-
declare const DEFAULT_BACKGROUND_SESSION_LEASE_MS = 30000;
|
|
327
|
-
declare const DEFAULT_BACKGROUND_SESSION_LEASE_RENEWAL_INTERVAL_MS = 10000;
|
|
328
|
-
declare const DEFAULT_BACKGROUND_SESSION_MAX_CONSECUTIVE_FAILURES = 3;
|
|
329
|
-
declare const DEFAULT_BACKGROUND_SESSION_RETRY_BACKOFF_MS = 30000;
|
|
330
|
-
declare const DEFAULT_BACKGROUND_SESSION_LIFETIME_MS: number;
|
|
331
|
-
declare const DEFAULT_BACKGROUND_SESSION_SUPERVISOR_INTERVAL_MS = 1000;
|
|
332
|
-
declare function resolveBackgroundSessionSupervisorIntervalMs(leaseMs: number): number;
|
|
333
|
-
//#endregion
|
|
334
|
-
//#region src/modules/background-session/application/supervision/background-session-delivery-queue.d.ts
|
|
335
|
-
type BackgroundSessionDeliveryKindForSupervisor = "progress" | "final" | "stopped" | "failed" | "reconciliation";
|
|
336
|
-
type BackgroundSessionDeliverySink = (delivery: {
|
|
337
|
-
readonly deliveryId: string;
|
|
338
|
-
readonly kind: BackgroundSessionDeliveryKindForSupervisor;
|
|
339
|
-
readonly sessionId: string;
|
|
340
|
-
readonly text: string;
|
|
341
|
-
}) => Promise<{
|
|
342
|
-
readonly providerMessageId: string;
|
|
343
|
-
}>;
|
|
344
|
-
//#endregion
|
|
345
|
-
//#region src/modules/background-session/application/supervision/background-session-supervisor.d.ts
|
|
346
|
-
interface BackgroundSessionLimits {
|
|
347
|
-
readonly intervalMs: number;
|
|
348
|
-
readonly leaseMs: number;
|
|
349
|
-
readonly leaseRenewalIntervalMs: number;
|
|
350
|
-
readonly maxConcurrentSessions: number;
|
|
351
|
-
readonly maxConsecutiveFailures: number;
|
|
352
|
-
readonly retryBackoffMs: number;
|
|
353
|
-
readonly sessionLifetimeMs: number;
|
|
354
|
-
}
|
|
355
|
-
interface BackgroundSessionStepResult {
|
|
356
|
-
readonly finalText: string;
|
|
357
|
-
readonly runId: string;
|
|
358
|
-
}
|
|
359
|
-
interface BackgroundSessionSupervisorOptions {
|
|
360
|
-
readonly clock: {
|
|
361
|
-
now(): string;
|
|
362
|
-
};
|
|
363
|
-
readonly config: BackgroundSessionLimits;
|
|
364
|
-
readonly deliveries: BackgroundSessionDeliveryStore;
|
|
365
|
-
readonly deliver: BackgroundSessionDeliverySink;
|
|
366
|
-
readonly onError?: (error: unknown) => void;
|
|
367
|
-
readonly repository: BackgroundSessionRepository;
|
|
368
|
-
readonly runStep: (input: {
|
|
369
|
-
readonly session: BackgroundSessionState;
|
|
370
|
-
readonly signal: AbortSignal;
|
|
371
|
-
readonly wakeText: string;
|
|
372
|
-
}) => Promise<BackgroundSessionStepResult>;
|
|
373
|
-
readonly sleep: (ms: number) => Effect.Effect<void>;
|
|
374
|
-
}
|
|
375
|
-
interface BackgroundSessionSupervisorStatus {
|
|
376
|
-
readonly capacity: number;
|
|
377
|
-
readonly counters: {
|
|
378
|
-
readonly completed: number;
|
|
379
|
-
readonly deliveriesDelivered: number;
|
|
380
|
-
readonly failed: number;
|
|
381
|
-
readonly started: number;
|
|
382
|
-
readonly staleLeaseEventsDropped: number;
|
|
383
|
-
readonly stopped: number;
|
|
384
|
-
};
|
|
385
|
-
readonly inFlightSteps: number;
|
|
386
|
-
readonly oldestDueAt?: string;
|
|
387
|
-
readonly owner: string;
|
|
388
|
-
readonly phaseCounts: Readonly<Record<BackgroundSessionPhase, number>>;
|
|
389
|
-
readonly reconciliationCount: number;
|
|
390
|
-
readonly repositoryHealthy: boolean;
|
|
391
|
-
readonly running: boolean;
|
|
392
|
-
}
|
|
393
|
-
interface BackgroundSessionSupervisor {
|
|
394
|
-
recover(): Effect.Effect<void>;
|
|
395
|
-
start(): Effect.Effect<void>;
|
|
396
|
-
status(): BackgroundSessionSupervisorStatus;
|
|
397
|
-
stop(): Effect.Effect<void>;
|
|
398
|
-
tick(): Effect.Effect<void>;
|
|
399
|
-
}
|
|
400
|
-
declare function createBackgroundSessionSupervisor(options: BackgroundSessionSupervisorOptions): BackgroundSessionSupervisor;
|
|
401
|
-
//#endregion
|
|
402
|
-
export { BackgroundSessionPhase as $, BackgroundSessionRepository as A, backgroundSessionToolIds as B, BackgroundSessionDetail as C, progressDeliveryId as D, createBackgroundSessionService as E, BackgroundSessionDeliveryStore as F, BACKGROUND_SESSION_SESSION_KEY_PREFIX as G, extendBackgroundSessionDefinition as H, BACKGROUND_SESSION_START_TOOL_ID as I, BackgroundSessionAuthority as J, createBackgroundSessionKey as K, BACKGROUND_SESSION_TOOL_IDS as L, BackgroundSessionRepositoryCorrupted as M, BackgroundSessionDeliveryConflict as N, sessionIdFromSessionKey as O, BackgroundSessionDeliveryRecord as P, BackgroundSessionOrigin as Q, BACKGROUND_SESSION_TOOL_PLUGIN_ID as R, BackgroundSessionCallerDenied as S, BackgroundSessionSummary as T, isBackgroundSessionToolId as U, createBackgroundSessionToolContracts as V, narrowBackgroundSessionDefinition as W, BackgroundSessionId as X, BackgroundSessionCancellation as Y, BackgroundSessionLease as Z, BackgroundSessionControlContext as _, createBackgroundSessionSupervisor as a, createBackgroundSessionControl as b, DEFAULT_BACKGROUND_SESSION_LIFETIME_MS as c, DEFAULT_BACKGROUND_SESSION_RETRY_BACKOFF_MS as d, BackgroundSessionState as et, DEFAULT_BACKGROUND_SESSION_STEP_TIMEOUT_MS as f, BackgroundSessionControlCommand as g, BackgroundSessionControl as h, BackgroundSessionSupervisorStatus as i, BackgroundSessionRepositoryConflict as j, terminalDeliveryId as k, DEFAULT_BACKGROUND_SESSION_MAX_CONCURRENT_SESSIONS as l, resolveBackgroundSessionSupervisorIntervalMs as m, BackgroundSessionSupervisor as n, BackgroundSessionTransitionDenied as nt, DEFAULT_BACKGROUND_SESSION_LEASE_MS as o, DEFAULT_BACKGROUND_SESSION_SUPERVISOR_INTERVAL_MS as p, createBackgroundSessionStepSourceMessageId as q, BackgroundSessionSupervisorOptions as r, isBackgroundSessionTerminalPhase as rt, DEFAULT_BACKGROUND_SESSION_LEASE_RENEWAL_INTERVAL_MS as s, BackgroundSessionLimits as t, BackgroundSessionTerminalResult as tt, DEFAULT_BACKGROUND_SESSION_MAX_CONSECUTIVE_FAILURES as u, BackgroundSessionControlError as v, BackgroundSessionService as w, toControlContext as x, BackgroundSessionControlOrigin as y, BACKGROUND_SESSION_TOOL_VERSION as z };
|
package/dist/chunks/module.js
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import { a as deepFreeze, c as validateRivusCatalogIdentifier, d as RIVUS_RUNTIME_TOOL_IDS, i as createRivusPluginCatalog, l as validateRivusMemoryScopes, o as uniqueRivusCatalogIds, p as InvalidRivusPlugin, s as uniqueRivusRuntimeToolIds } from "./api.js";
|
|
2
|
-
import { t as createSha256Digest } from "./sha256-digest.js";
|
|
3
|
-
import { q as createBackgroundSessionToolContracts } from "./api2.js";
|
|
4
|
-
//#region src/adapters/agent/memory/rivus-memory-tool-contract.ts
|
|
5
|
-
const RIVUS_MEMORY_TOOL_ID = "memory";
|
|
6
|
-
const RIVUS_MEMORY_TOOL_PLUGIN_ID = "rivus-core";
|
|
7
|
-
const RIVUS_MEMORY_TOOL_VERSION = "1.0.0";
|
|
8
|
-
function createRivusMemoryToolContract(scopes) {
|
|
9
|
-
return Object.freeze({
|
|
10
|
-
description: "Search and read Memory inside Host-bound scopes; propose or request forgetting only in writable private scopes.",
|
|
11
|
-
digest: "sha256:rivus-memory-v3",
|
|
12
|
-
id: RIVUS_MEMORY_TOOL_ID,
|
|
13
|
-
idempotency: "required",
|
|
14
|
-
inputSchema: Object.freeze({
|
|
15
|
-
additionalProperties: false,
|
|
16
|
-
properties: {
|
|
17
|
-
command: {
|
|
18
|
-
description: "One of search, read, propose, or forget_request.",
|
|
19
|
-
enum: [
|
|
20
|
-
"search",
|
|
21
|
-
"read",
|
|
22
|
-
"propose",
|
|
23
|
-
"forget_request"
|
|
24
|
-
],
|
|
25
|
-
type: "string"
|
|
26
|
-
},
|
|
27
|
-
id: {
|
|
28
|
-
description: "Required for read and forget_request.",
|
|
29
|
-
minLength: 1,
|
|
30
|
-
type: "string"
|
|
31
|
-
},
|
|
32
|
-
input: {
|
|
33
|
-
additionalProperties: false,
|
|
34
|
-
description: "Required for propose.",
|
|
35
|
-
properties: { content: {
|
|
36
|
-
minLength: 1,
|
|
37
|
-
type: "string"
|
|
38
|
-
} },
|
|
39
|
-
required: ["content"],
|
|
40
|
-
type: "object"
|
|
41
|
-
},
|
|
42
|
-
query: {
|
|
43
|
-
additionalProperties: false,
|
|
44
|
-
description: "Required for search.",
|
|
45
|
-
properties: { query: { type: "string" } },
|
|
46
|
-
required: ["query"],
|
|
47
|
-
type: "object"
|
|
48
|
-
},
|
|
49
|
-
reason: {
|
|
50
|
-
description: "Optional reason for forget_request.",
|
|
51
|
-
type: "string"
|
|
52
|
-
},
|
|
53
|
-
...scopes.length === 0 ? {} : { scope: {
|
|
54
|
-
description: "Optional Host-granted scope for search or propose. Confirmed Project and Shared User Profile Memory are read-only to the model.",
|
|
55
|
-
enum: [...scopes],
|
|
56
|
-
type: "string"
|
|
57
|
-
} }
|
|
58
|
-
},
|
|
59
|
-
required: ["command"],
|
|
60
|
-
type: "object"
|
|
61
|
-
}),
|
|
62
|
-
risk: "mutate",
|
|
63
|
-
version: RIVUS_MEMORY_TOOL_VERSION
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
//#endregion
|
|
67
|
-
//#region src/adapters/agent/catalog/rivus-host-tool-descriptor-provider.ts
|
|
68
|
-
function createRivusHostToolDescriptorProvider(options) {
|
|
69
|
-
return Object.freeze({ provide: ({ deployment, memoryScopes }) => {
|
|
70
|
-
const contributions = [];
|
|
71
|
-
if (deployment.memory?.tool === true) contributions.push({
|
|
72
|
-
scope: "profile",
|
|
73
|
-
tool: Object.freeze({
|
|
74
|
-
...createRivusMemoryToolContract(memoryScopes),
|
|
75
|
-
pluginId: RIVUS_MEMORY_TOOL_PLUGIN_ID
|
|
76
|
-
})
|
|
77
|
-
});
|
|
78
|
-
if (options.backgroundSessions) contributions.push(...createBackgroundSessionToolContracts().map(toRuntimeContribution));
|
|
79
|
-
return Object.freeze(contributions);
|
|
80
|
-
} });
|
|
81
|
-
}
|
|
82
|
-
function toRuntimeContribution(tool) {
|
|
83
|
-
return Object.freeze({
|
|
84
|
-
scope: "runtime",
|
|
85
|
-
tool: Object.freeze({ ...tool })
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region src/modules/agent-catalog/application/resolution/rivus-agent-definition-resolver.ts
|
|
90
|
-
function createRivusAgentDefinitionResolver(providers) {
|
|
91
|
-
return Object.freeze({ resolve: (catalog, deployment) => resolveRivusAgentDefinition(catalog, deployment, providers) });
|
|
92
|
-
}
|
|
93
|
-
function resolveRivusAgentDefinition(catalog, deployment, providers) {
|
|
94
|
-
const snapshot = catalog.snapshot();
|
|
95
|
-
const plugin = snapshot.plugins.find((candidate) => candidate.id === deployment.pluginId);
|
|
96
|
-
if (!plugin) throw new InvalidRivusPlugin(`unknown deployment plugin: ${deployment.pluginId}`);
|
|
97
|
-
const profile = snapshot.profiles.find((candidate) => candidate.id === deployment.profileId && candidate.pluginId === deployment.pluginId);
|
|
98
|
-
if (!profile) throw new InvalidRivusPlugin(`unknown profile ${deployment.profileId} for plugin ${deployment.pluginId}`);
|
|
99
|
-
const memoryScopes = resolveMemoryScopes(profile, deployment);
|
|
100
|
-
const runtimeToolIds = resolveRuntimeTools(profile, deployment);
|
|
101
|
-
const memoryTool = deployment.memory?.tool === true;
|
|
102
|
-
if (memoryTool && memoryScopes.length === 0) throw new InvalidRivusPlugin(`deployment ${deployment.agentId} Memory Tool requires at least one granted scope`);
|
|
103
|
-
const contributions = providers.flatMap((provider) => provider.provide({
|
|
104
|
-
deployment,
|
|
105
|
-
memoryScopes,
|
|
106
|
-
profile
|
|
107
|
-
}));
|
|
108
|
-
const profileContributions = contributions.filter(({ scope }) => scope === "profile");
|
|
109
|
-
const runtimeContributions = contributions.filter(({ scope }) => scope === "runtime");
|
|
110
|
-
validateToolContributions(snapshot.tools, contributions);
|
|
111
|
-
if (memoryTool && !profileContributions.some(({ tool }) => tool.id === "memory")) throw new InvalidRivusPlugin(`deployment ${deployment.agentId} Memory Tool descriptor is unavailable`);
|
|
112
|
-
const pluginTools = resolvePluginTools(snapshot.tools, profile, deployment);
|
|
113
|
-
const profileToolsById = new Map(profileContributions.map(({ tool }) => [tool.id, deepFreeze({ ...tool })]));
|
|
114
|
-
const resolvedProfileToolIds = [...pluginTools.keys(), ...profileToolsById.keys()].sort();
|
|
115
|
-
const tools = resolvedProfileToolIds.map((id) => pluginTools.get(id) ?? profileToolsById.get(id));
|
|
116
|
-
const skills = resolveSkills(snapshot.skills, profile, deployment);
|
|
117
|
-
const skillIds = skills.map(({ id }) => id);
|
|
118
|
-
const profileRevision = digest({
|
|
119
|
-
memory: {
|
|
120
|
-
scopes: memoryScopes,
|
|
121
|
-
tool: memoryTool
|
|
122
|
-
},
|
|
123
|
-
model: profile.model,
|
|
124
|
-
plugin,
|
|
125
|
-
profileId: profile.id,
|
|
126
|
-
runtimeTools: runtimeToolIds,
|
|
127
|
-
skills: skills.map(({ content, digest: skillDigest, id, pluginId, title, version }) => ({
|
|
128
|
-
content,
|
|
129
|
-
digest: skillDigest,
|
|
130
|
-
id,
|
|
131
|
-
pluginId,
|
|
132
|
-
title,
|
|
133
|
-
version
|
|
134
|
-
})),
|
|
135
|
-
systemPrompt: profile.systemPrompt,
|
|
136
|
-
tools
|
|
137
|
-
});
|
|
138
|
-
const toolGrantSet = deepFreeze({
|
|
139
|
-
revision: digest({
|
|
140
|
-
profileRevision,
|
|
141
|
-
toolIds: resolvedProfileToolIds
|
|
142
|
-
}),
|
|
143
|
-
toolIds: resolvedProfileToolIds
|
|
144
|
-
});
|
|
145
|
-
const skillGrantSet = deepFreeze({
|
|
146
|
-
revision: digest({
|
|
147
|
-
profileRevision,
|
|
148
|
-
skillIds
|
|
149
|
-
}),
|
|
150
|
-
skillIds
|
|
151
|
-
});
|
|
152
|
-
const runtimeToolGrantSet = deepFreeze({
|
|
153
|
-
revision: digest({
|
|
154
|
-
profileRevision,
|
|
155
|
-
toolIds: runtimeToolIds
|
|
156
|
-
}),
|
|
157
|
-
toolIds: runtimeToolIds
|
|
158
|
-
});
|
|
159
|
-
return extendRuntimeTools(deepFreeze({
|
|
160
|
-
agentId: deployment.agentId,
|
|
161
|
-
endpointIds: [...deployment.endpointIds],
|
|
162
|
-
memory: {
|
|
163
|
-
scopes: memoryScopes,
|
|
164
|
-
tool: memoryTool
|
|
165
|
-
},
|
|
166
|
-
model: profile.model,
|
|
167
|
-
pluginId: deployment.pluginId,
|
|
168
|
-
profileId: deployment.profileId,
|
|
169
|
-
...deployment.projectSpaceId ? { projectSpaceId: deployment.projectSpaceId } : {},
|
|
170
|
-
profileRevision,
|
|
171
|
-
runtimeToolGrantSet,
|
|
172
|
-
skillGrantSet,
|
|
173
|
-
skills,
|
|
174
|
-
systemPrompt: profile.systemPrompt,
|
|
175
|
-
toolGrantSet,
|
|
176
|
-
tools
|
|
177
|
-
}), runtimeContributions);
|
|
178
|
-
}
|
|
179
|
-
function resolveRuntimeTools(profile, deployment) {
|
|
180
|
-
const profileToolIds = uniqueRivusRuntimeToolIds(profile.runtimeTools?.allow ?? [], `profile ${profile.id}`);
|
|
181
|
-
const requestedToolIds = uniqueRivusRuntimeToolIds(deployment.runtimeTools?.allow ?? [], `deployment ${deployment.agentId}`);
|
|
182
|
-
const profileToolIdSet = new Set(profileToolIds);
|
|
183
|
-
const requestedToolIdSet = new Set(requestedToolIds);
|
|
184
|
-
return RIVUS_RUNTIME_TOOL_IDS.filter((id) => profileToolIdSet.has(id) && requestedToolIdSet.has(id));
|
|
185
|
-
}
|
|
186
|
-
function resolveMemoryScopes(profile, deployment) {
|
|
187
|
-
const profileScopes = validateRivusMemoryScopes(profile.memory.scopes, `profile ${profile.id}`);
|
|
188
|
-
const requestedScopes = validateRivusMemoryScopes(deployment.memory?.scopes ?? [], `deployment ${deployment.agentId}`);
|
|
189
|
-
return profileScopes.filter((scope) => requestedScopes.includes(scope));
|
|
190
|
-
}
|
|
191
|
-
function resolvePluginTools(registeredTools, profile, deployment) {
|
|
192
|
-
const requestedTools = uniqueRivusCatalogIds(deployment.tools.allow, "deployment tool allowlist");
|
|
193
|
-
const catalogTools = new Map(registeredTools.map((tool) => [tool.id, tool]));
|
|
194
|
-
for (const id of requestedTools) if (!catalogTools.has(id)) throw new InvalidRivusPlugin(`unknown deployment tool: ${id}`);
|
|
195
|
-
const profileToolIds = uniqueRivusCatalogIds(profile.tools.allow, "profile tool allowlist");
|
|
196
|
-
for (const id of profileToolIds) if (!catalogTools.has(id)) throw new InvalidRivusPlugin(`profile ${profile.id} references unknown tool: ${id}`);
|
|
197
|
-
const grantedIds = profileToolIds.filter((id) => requestedTools.includes(id)).sort();
|
|
198
|
-
return new Map(grantedIds.map((id) => [id, toResolvedTool(catalogTools.get(id))]));
|
|
199
|
-
}
|
|
200
|
-
function resolveSkills(registeredSkills, profile, deployment) {
|
|
201
|
-
const requestedSkills = uniqueRivusCatalogIds(deployment.skills.allow, "deployment skill allowlist");
|
|
202
|
-
const catalogSkills = new Map(registeredSkills.map((skill) => [skill.id, skill]));
|
|
203
|
-
for (const id of requestedSkills) if (!catalogSkills.has(id)) throw new InvalidRivusPlugin(`unknown deployment skill: ${id}`);
|
|
204
|
-
return uniqueRivusCatalogIds(profile.skills.allow, "profile skill allowlist").filter((id) => requestedSkills.includes(id)).sort().map((id) => {
|
|
205
|
-
const skill = catalogSkills.get(id);
|
|
206
|
-
if (!skill) throw new InvalidRivusPlugin(`profile ${profile.id} references unknown skill: ${id}`);
|
|
207
|
-
return skill;
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
function validateToolContributions(registeredTools, contributions) {
|
|
211
|
-
const knownIds = new Set(registeredTools.map(({ id }) => id));
|
|
212
|
-
for (const { tool } of contributions) {
|
|
213
|
-
validateRivusCatalogIdentifier(tool.id, "contributed tool");
|
|
214
|
-
validateRivusCatalogIdentifier(tool.pluginId, "contributed tool plugin");
|
|
215
|
-
if (knownIds.has(tool.id)) throw new InvalidRivusPlugin(`duplicate contributed tool id: ${tool.id}`);
|
|
216
|
-
if (tool.version.trim() === "" || tool.digest.trim() === "") throw new InvalidRivusPlugin(`contributed tool ${tool.id} requires a version and digest`);
|
|
217
|
-
knownIds.add(tool.id);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
function extendRuntimeTools(definition, contributions) {
|
|
221
|
-
if (contributions.length === 0) return definition;
|
|
222
|
-
const additions = contributions.map(({ tool }) => deepFreeze({ ...tool }));
|
|
223
|
-
const additionIds = additions.map(({ id }) => id).sort();
|
|
224
|
-
return deepFreeze({
|
|
225
|
-
...definition,
|
|
226
|
-
toolGrantSet: {
|
|
227
|
-
revision: digest({
|
|
228
|
-
parentRevision: definition.toolGrantSet.revision,
|
|
229
|
-
toolIds: additionIds
|
|
230
|
-
}),
|
|
231
|
-
toolIds: [...definition.toolGrantSet.toolIds, ...additionIds].sort()
|
|
232
|
-
},
|
|
233
|
-
tools: [...definition.tools, ...additions]
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
function toResolvedTool(tool) {
|
|
237
|
-
const { createExecutor: _createExecutor, description, digest: toolDigest, id, idempotency, inputSchema, pluginId, risk, version } = tool;
|
|
238
|
-
return deepFreeze({
|
|
239
|
-
description,
|
|
240
|
-
digest: toolDigest,
|
|
241
|
-
id,
|
|
242
|
-
idempotency,
|
|
243
|
-
inputSchema,
|
|
244
|
-
pluginId,
|
|
245
|
-
risk,
|
|
246
|
-
version
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
function digest(value) {
|
|
250
|
-
return createSha256Digest(stableJson(value));
|
|
251
|
-
}
|
|
252
|
-
function stableJson(value) {
|
|
253
|
-
if (Array.isArray(value)) return `[${value.map(stableJson).join(",")}]`;
|
|
254
|
-
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(",")}}`;
|
|
255
|
-
return JSON.stringify(value);
|
|
256
|
-
}
|
|
257
|
-
//#endregion
|
|
258
|
-
//#region src/modules/agent-catalog/module.ts
|
|
259
|
-
function createRivusAgentCatalog(options = {}) {
|
|
260
|
-
const resolver = createRivusAgentDefinitionResolver(options.toolDescriptorProviders ?? []);
|
|
261
|
-
return Object.freeze({
|
|
262
|
-
createPluginCatalog: createRivusPluginCatalog,
|
|
263
|
-
resolve: (catalog, deployment) => resolver.resolve(catalog, deployment)
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
//#endregion
|
|
267
|
-
export { RIVUS_MEMORY_TOOL_VERSION as a, RIVUS_MEMORY_TOOL_PLUGIN_ID as i, createRivusHostToolDescriptorProvider as n, createRivusMemoryToolContract as o, RIVUS_MEMORY_TOOL_ID as r, createRivusAgentCatalog as t };
|