@rivus/runtime 0.16.6 → 0.18.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 +674 -21
- package/README.md +21 -0
- package/dist/acp.d.ts +7 -92
- package/dist/acp.js +298 -249
- package/dist/chunks/agent-loop.d.ts +143 -95
- package/dist/chunks/agent-user-input.js +109 -0
- package/dist/chunks/rivus-runtime-tool.d.ts +104 -4
- package/dist/chunks/{tool-input-digest.js → tool-risk-policy.js} +7 -14
- package/dist/chunks/user-input-xml.js +224 -0
- package/dist/index.d.ts +107 -823
- package/dist/index.js +242 -705
- package/dist/pi.d.ts +62 -332
- package/dist/pi.js +547 -546
- package/package.json +12 -11
- package/dist/chunks/agent-loop.js +0 -164
|
@@ -1,5 +1,128 @@
|
|
|
1
1
|
import { Effect, Stream } from "effect";
|
|
2
|
-
|
|
2
|
+
//#region src/core/application/agent-execution/contracts/agent-user-input.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The structured input accepted by an Agent Run. It is deliberately a data
|
|
5
|
+
* object: paths, credentials and provider specific handles are kept in the
|
|
6
|
+
* AttachmentAccess binding that accompanies a run.
|
|
7
|
+
*/
|
|
8
|
+
interface UserInput {
|
|
9
|
+
readonly version: 1;
|
|
10
|
+
readonly deliveryId: string;
|
|
11
|
+
readonly message: InputMessage;
|
|
12
|
+
}
|
|
13
|
+
interface InputMessage {
|
|
14
|
+
readonly id: string;
|
|
15
|
+
readonly source: "direct" | "quoted";
|
|
16
|
+
readonly author?: InputAuthor;
|
|
17
|
+
readonly sentAt?: string;
|
|
18
|
+
readonly parts: ReadonlyArray<InputPart>;
|
|
19
|
+
}
|
|
20
|
+
interface InputAuthor {
|
|
21
|
+
readonly id?: string;
|
|
22
|
+
readonly name?: string;
|
|
23
|
+
}
|
|
24
|
+
type InputNoticeReason = "permission_denied" | "expired" | "unsupported" | "limit_exceeded" | "invalid_content" | "unavailable";
|
|
25
|
+
type InputPart = InputTextPart | InputImagePart | InputAttachmentPart | InputQuotePart | InputNoticePart;
|
|
26
|
+
interface InputTextPart {
|
|
27
|
+
readonly type: "text";
|
|
28
|
+
readonly text: string;
|
|
29
|
+
/** Origin metadata is optional for compatibility with old structured callers. */
|
|
30
|
+
readonly source?: "direct" | "quoted";
|
|
31
|
+
readonly controlEligible?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** An image part references bytes that were prepared by the channel adapter. */
|
|
34
|
+
interface InputImagePart {
|
|
35
|
+
readonly type: "image";
|
|
36
|
+
readonly attachmentId: string;
|
|
37
|
+
readonly mimeType: string;
|
|
38
|
+
readonly size?: number;
|
|
39
|
+
}
|
|
40
|
+
interface InputAttachmentPart {
|
|
41
|
+
readonly type: "attachment";
|
|
42
|
+
readonly attachmentId: string;
|
|
43
|
+
readonly mediaKind: "file" | "audio" | "video";
|
|
44
|
+
readonly durationMs?: number;
|
|
45
|
+
readonly fileName?: string;
|
|
46
|
+
readonly mimeType: string;
|
|
47
|
+
readonly size: number;
|
|
48
|
+
}
|
|
49
|
+
interface InputQuotePart {
|
|
50
|
+
readonly type: "quote";
|
|
51
|
+
readonly kind: "forward" | "reply";
|
|
52
|
+
readonly messages: ReadonlyArray<InputMessage>;
|
|
53
|
+
}
|
|
54
|
+
/** Reserved Bash action handled by the Run binding; never an OS executable. */
|
|
55
|
+
declare const ATTACHMENT_RECOVERY_COMMAND = "rivus-attachment-recover";
|
|
56
|
+
interface InputRecovery {
|
|
57
|
+
readonly toolName: string;
|
|
58
|
+
readonly arguments: Readonly<Record<string, string | number>>;
|
|
59
|
+
}
|
|
60
|
+
interface InputNoticePart {
|
|
61
|
+
readonly type: "notice";
|
|
62
|
+
readonly reason: InputNoticeReason;
|
|
63
|
+
readonly text: string;
|
|
64
|
+
/** Present only when the channel adapter has installed a trusted action. */
|
|
65
|
+
readonly recovery?: InputRecovery;
|
|
66
|
+
}
|
|
67
|
+
interface MaterializedAttachment {
|
|
68
|
+
readonly attachmentId: string;
|
|
69
|
+
readonly path: string;
|
|
70
|
+
readonly mimeType: string;
|
|
71
|
+
readonly size: number;
|
|
72
|
+
readonly mediaKind: "file" | "audio" | "video";
|
|
73
|
+
readonly fileName?: string;
|
|
74
|
+
readonly durationMs?: number;
|
|
75
|
+
}
|
|
76
|
+
/** Runtime identity used to bind an adapter grant to one active Run. */
|
|
77
|
+
interface AttachmentAccessBinding {
|
|
78
|
+
readonly generationId?: string;
|
|
79
|
+
readonly runId: AgentRunId;
|
|
80
|
+
readonly sessionKey: SessionKey;
|
|
81
|
+
readonly signal: AbortSignal;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Run-scoped access to bytes and files prepared by an inbound adapter.
|
|
85
|
+
* Implementations must validate the tenant, endpoint, session generation and
|
|
86
|
+
* run before serving a request. A path returned by materialize is a handle,
|
|
87
|
+
* never an authority by itself.
|
|
88
|
+
*/
|
|
89
|
+
interface AttachmentAccess {
|
|
90
|
+
/** Create a Run-bound view. The returned view must reject after revoke. */
|
|
91
|
+
readonly bind?: (binding: AttachmentAccessBinding) => AttachmentAccess;
|
|
92
|
+
/** Revoke this view and any adapter grant it wraps. */
|
|
93
|
+
readonly revoke?: () => void;
|
|
94
|
+
readonly readBytes: (attachmentId: string) => Effect.Effect<Uint8Array, unknown>;
|
|
95
|
+
readonly materialize: (attachmentId: string) => Effect.Effect<MaterializedAttachment, unknown>;
|
|
96
|
+
/** Whether a deployed tool can consume the given media kind. */
|
|
97
|
+
readonly canUnderstand?: (input: {
|
|
98
|
+
readonly mediaKind: "file" | "audio" | "video";
|
|
99
|
+
readonly mimeType: string;
|
|
100
|
+
}) => boolean;
|
|
101
|
+
/** Enforces the provider's native image count/size/vision budget. */
|
|
102
|
+
readonly canProvideImage?: (input: {
|
|
103
|
+
readonly mimeType: string;
|
|
104
|
+
readonly size: number;
|
|
105
|
+
readonly index: number;
|
|
106
|
+
}) => boolean;
|
|
107
|
+
/** Returns a recovery action only for an adapter-authenticated failure. */
|
|
108
|
+
readonly trustedRecovery?: (notice: InputNoticePart) => InputRecovery | undefined;
|
|
109
|
+
/** Executes an adapter-authorized recovery through the existing tool boundary. */
|
|
110
|
+
readonly executeRecovery?: (input: {
|
|
111
|
+
readonly toolName: string;
|
|
112
|
+
readonly arguments: Readonly<Record<string, string | number>>;
|
|
113
|
+
readonly signal?: AbortSignal;
|
|
114
|
+
}) => Effect.Effect<{
|
|
115
|
+
readonly outputPath: string;
|
|
116
|
+
readonly mimeType: string;
|
|
117
|
+
readonly sizeBytes: number;
|
|
118
|
+
} | undefined, unknown>;
|
|
119
|
+
}
|
|
120
|
+
interface AgentSteeringRequest {
|
|
121
|
+
readonly attachmentAccess?: AttachmentAccess;
|
|
122
|
+
readonly userInput: UserInput;
|
|
123
|
+
}
|
|
124
|
+
type AgentSteeringInput = string | UserInput | AgentSteeringRequest;
|
|
125
|
+
//#endregion
|
|
3
126
|
//#region src/core/application/agent-execution/contracts/agent-domain-events.d.ts
|
|
4
127
|
type AgentRunId = string;
|
|
5
128
|
type SessionKey = string;
|
|
@@ -8,6 +131,8 @@ interface AgentRunAccepted {
|
|
|
8
131
|
readonly runId: AgentRunId;
|
|
9
132
|
readonly sessionKey: SessionKey;
|
|
10
133
|
readonly prompt: string;
|
|
134
|
+
/** Structured input is retained for replay; `prompt` remains the legacy view. */
|
|
135
|
+
readonly userInput?: UserInput;
|
|
11
136
|
readonly occurredAt: Date;
|
|
12
137
|
}
|
|
13
138
|
interface AgentTurnStarted {
|
|
@@ -138,13 +263,6 @@ interface AgentRunCancelled {
|
|
|
138
263
|
readonly occurredAt: Date;
|
|
139
264
|
}
|
|
140
265
|
type AgentDomainEvent = AgentRunAccepted | AgentTurnStarted | AssistantTextDelta | AssistantThinkingDelta | AgentModelExecutionStarted | AgentModelExecutionEnded | AgentSkillExecutionStarted | AgentSkillExecutionEnded | AgentToolExecutionStarted | AgentToolExecutionUpdated | AgentToolExecutionEnded | AgentTurnCompleted | AgentRunCompleted | AgentRunFailed | AgentRunCancelled;
|
|
141
|
-
type AgentToolExecutionEvent = AgentToolExecutionStarted | AgentToolExecutionUpdated | AgentToolExecutionEnded;
|
|
142
|
-
type AgentModelExecutionEvent = AgentModelExecutionStarted | AgentModelExecutionEnded;
|
|
143
|
-
type TerminalAgentDomainEvent = AgentRunCompleted | AgentRunFailed | AgentRunCancelled;
|
|
144
|
-
declare function isAssistantTextDeltaEvent(event: AgentDomainEvent): event is AssistantTextDelta;
|
|
145
|
-
declare function isAssistantThinkingDeltaEvent(event: AgentDomainEvent): event is AssistantThinkingDelta;
|
|
146
|
-
declare function isAgentToolExecutionEvent(event: AgentDomainEvent): event is AgentToolExecutionEvent;
|
|
147
|
-
declare function isTerminalAgentDomainEvent(event: AgentDomainEvent): event is TerminalAgentDomainEvent;
|
|
148
266
|
//#endregion
|
|
149
267
|
//#region src/core/application/agent-execution/contracts/agent-run-state.d.ts
|
|
150
268
|
type AgentRunPhase = "idle" | "accepted" | "running" | "completed" | "failed" | "cancelled";
|
|
@@ -153,6 +271,7 @@ interface AgentRunState {
|
|
|
153
271
|
readonly runId?: AgentRunId;
|
|
154
272
|
readonly sessionKey?: SessionKey;
|
|
155
273
|
readonly prompt?: string;
|
|
274
|
+
readonly userInput?: UserInput;
|
|
156
275
|
readonly finalText: string;
|
|
157
276
|
readonly errorMessage?: string;
|
|
158
277
|
readonly cancellationReason?: string;
|
|
@@ -194,6 +313,7 @@ interface AgentRunSummary {
|
|
|
194
313
|
readonly finalText: string;
|
|
195
314
|
readonly phase: AgentRunPhase;
|
|
196
315
|
readonly prompt?: string;
|
|
316
|
+
readonly userInput?: UserInput;
|
|
197
317
|
readonly runId: AgentRunId;
|
|
198
318
|
readonly sessionKey?: SessionKey;
|
|
199
319
|
readonly startedAt?: Date;
|
|
@@ -222,7 +342,6 @@ interface AgentHistory {
|
|
|
222
342
|
readonly sessions: ReadonlyArray<AgentSessionSummary>;
|
|
223
343
|
readonly totalEvents: number;
|
|
224
344
|
}
|
|
225
|
-
declare function replayAgentHistory(events: ReadonlyArray<AgentDomainEvent>): AgentHistory;
|
|
226
345
|
//#endregion
|
|
227
346
|
//#region src/core/application/agent-execution/transcript/agent-transcript.d.ts
|
|
228
347
|
interface AgentTranscript {
|
|
@@ -247,22 +366,14 @@ interface AgentTranscriptTurn {
|
|
|
247
366
|
readonly toolExecutionCount: number;
|
|
248
367
|
readonly updatedAt: Date;
|
|
249
368
|
readonly userText: string;
|
|
369
|
+
readonly userInput?: UserInput;
|
|
250
370
|
}
|
|
251
371
|
type AgentTranscriptMessageRole = "assistant" | "user";
|
|
252
372
|
interface AgentTranscriptMessage {
|
|
253
373
|
readonly content: string;
|
|
254
374
|
readonly role: AgentTranscriptMessageRole;
|
|
375
|
+
readonly userInput?: UserInput;
|
|
255
376
|
}
|
|
256
|
-
interface AgentConversationMessagesOptions {
|
|
257
|
-
readonly text: string;
|
|
258
|
-
readonly transcript?: AgentTranscript;
|
|
259
|
-
}
|
|
260
|
-
declare function replayAgentTranscript(events: ReadonlyArray<AgentDomainEvent>, sessionKey: SessionKey): AgentTranscript;
|
|
261
|
-
declare function createAgentTranscriptTurn(summary: AgentRunSummary & {
|
|
262
|
-
readonly sessionKey: SessionKey;
|
|
263
|
-
}): AgentTranscriptTurn;
|
|
264
|
-
declare function createAgentTranscriptMessages(transcript: AgentTranscript): ReadonlyArray<AgentTranscriptMessage>;
|
|
265
|
-
declare function createAgentConversationMessages(options: AgentConversationMessagesOptions): ReadonlyArray<AgentTranscriptMessage>;
|
|
266
377
|
//#endregion
|
|
267
378
|
//#region src/core/application/agent-execution/invocation/agent-invocation.d.ts
|
|
268
379
|
interface AgentMemoryInvocationIdentity {
|
|
@@ -311,25 +422,30 @@ interface BackgroundSessionAgentInvocationOrigin {
|
|
|
311
422
|
type AgentInvocationOrigin = FeishuAgentInvocationOrigin | LocalCliAgentInvocationOrigin | AutomationAgentInvocationOrigin | BackgroundSessionAgentInvocationOrigin;
|
|
312
423
|
//#endregion
|
|
313
424
|
//#region src/core/application/agent-execution/loop/agent-loop.d.ts
|
|
314
|
-
interface AgentLoopInput
|
|
425
|
+
interface AgentLoopInput {
|
|
315
426
|
readonly abortSignal: AbortSignal;
|
|
427
|
+
readonly attachmentAccess?: AttachmentAccess;
|
|
316
428
|
readonly invocation?: AgentInvocationOrigin;
|
|
317
429
|
readonly messages?: ReadonlyArray<AgentTranscriptMessage>;
|
|
318
430
|
readonly runId: AgentRunId;
|
|
319
431
|
readonly sessionKey: SessionKey;
|
|
320
432
|
/** Optional mailbox for user steering while the run is active. */
|
|
321
|
-
readonly steering?: AgentSteeringChannel
|
|
433
|
+
readonly steering?: AgentSteeringChannel;
|
|
322
434
|
readonly text: string;
|
|
435
|
+
readonly userInput?: UserInput;
|
|
323
436
|
readonly previousSessionState?: AgentRunState;
|
|
324
437
|
readonly previousSessionTranscript?: AgentTranscript;
|
|
325
438
|
}
|
|
326
|
-
interface AgentSteeringChannel
|
|
439
|
+
interface AgentSteeringChannel {
|
|
440
|
+
/** Legacy text mailbox. Kept unchanged for existing provider adapters. */
|
|
327
441
|
next(): Effect.Effect<string>;
|
|
328
442
|
/** Seal admission at provider completion and return accepted messages still waiting. */
|
|
329
443
|
close?(): Effect.Effect<readonly string[]>;
|
|
444
|
+
/** Structured mailbox used by adapters that advertise structured steering. */
|
|
445
|
+
nextInput?(): Effect.Effect<AgentSteeringInput>;
|
|
446
|
+
closeInput?(): Effect.Effect<readonly AgentSteeringInput[]>;
|
|
330
447
|
}
|
|
331
448
|
type AgentLoopEvent = AgentLoopTurnStart | AgentLoopTextDelta | AgentLoopThinkingDelta | AgentLoopModelExecutionStart | AgentLoopModelExecutionEnd | AgentLoopSkillExecutionStart | AgentLoopSkillExecutionEnd | AgentLoopToolExecutionStart | AgentLoopToolExecutionUpdate | AgentLoopToolExecutionEnd;
|
|
332
|
-
type AgentLoopEventLike = AgentLoopEvent | string;
|
|
333
449
|
interface AgentLoopTextDelta {
|
|
334
450
|
readonly type: "assistant_text_delta";
|
|
335
451
|
readonly delta: string;
|
|
@@ -401,81 +517,13 @@ interface AgentLoopToolExecutionEnd {
|
|
|
401
517
|
readonly result: unknown;
|
|
402
518
|
readonly isError: boolean;
|
|
403
519
|
}
|
|
404
|
-
interface AgentLoop$1 {
|
|
405
|
-
run(input: AgentLoopInput$1): Stream.Stream<AgentLoopEvent, unknown>;
|
|
406
|
-
/** Provider adapters opt in only when they can consume steering safely. */
|
|
407
|
-
readonly supportsSteering?: boolean;
|
|
408
|
-
}
|
|
409
|
-
interface TextAgentLoopOptions$1 {
|
|
410
|
-
readonly generate: (input: AgentLoopInput$1) => Effect.Effect<string, unknown>;
|
|
411
|
-
}
|
|
412
|
-
type AgentLoopToolExecutionStartOptions = Omit<AgentLoopToolExecutionStart, "type">;
|
|
413
|
-
type AgentLoopToolExecutionUpdateOptions = Omit<AgentLoopToolExecutionUpdate, "type">;
|
|
414
|
-
type AgentLoopToolExecutionEndOptions = Omit<AgentLoopToolExecutionEnd, "type">;
|
|
415
|
-
type AgentLoopModelExecutionStartOptions = Omit<AgentLoopModelExecutionStart, "type">;
|
|
416
|
-
type AgentLoopModelExecutionEndOptions = Omit<AgentLoopModelExecutionEnd, "type">;
|
|
417
|
-
type AgentLoopSkillExecutionStartOptions = Omit<AgentLoopSkillExecutionStart, "type">;
|
|
418
|
-
type AgentLoopSkillExecutionEndOptions = Omit<AgentLoopSkillExecutionSucceeded, "type"> | Omit<AgentLoopSkillExecutionFailed, "type">;
|
|
419
|
-
declare function createAgentLoopTextDelta(delta: string): AgentLoopTextDelta;
|
|
420
|
-
declare function createAgentLoopTurnStart(): AgentLoopTurnStart;
|
|
421
|
-
declare function normalizeAgentLoopEvent(event: AgentLoopEventLike): AgentLoopEvent;
|
|
422
|
-
declare function createAgentLoopThinkingDelta(delta: string): AgentLoopThinkingDelta;
|
|
423
|
-
declare function createAgentLoopModelExecutionStart(options: AgentLoopModelExecutionStartOptions): AgentLoopModelExecutionStart;
|
|
424
|
-
declare function createAgentLoopModelExecutionEnd(options: AgentLoopModelExecutionEndOptions): AgentLoopModelExecutionEnd;
|
|
425
|
-
declare function createAgentLoopSkillExecutionStart(options: AgentLoopSkillExecutionStartOptions): AgentLoopSkillExecutionStart;
|
|
426
|
-
declare function createAgentLoopSkillExecutionEnd(options: AgentLoopSkillExecutionEndOptions): AgentLoopSkillExecutionEnd;
|
|
427
|
-
declare function createAgentLoopToolExecutionStart(options: AgentLoopToolExecutionStartOptions): AgentLoopToolExecutionStart;
|
|
428
|
-
declare function createAgentLoopToolExecutionUpdate(options: AgentLoopToolExecutionUpdateOptions): AgentLoopToolExecutionUpdate;
|
|
429
|
-
declare function createAgentLoopToolExecutionEnd(options: AgentLoopToolExecutionEndOptions): AgentLoopToolExecutionEnd;
|
|
430
|
-
interface EventAgentLoopOptions$1 {
|
|
431
|
-
readonly events: ReadonlyArray<AgentLoopEventLike> | ((input: AgentLoopInput$1) => ReadonlyArray<AgentLoopEventLike> | Promise<ReadonlyArray<AgentLoopEventLike>>);
|
|
432
|
-
}
|
|
433
|
-
declare function createEventAgentLoop$1(options: EventAgentLoopOptions$1): AgentLoop$1;
|
|
434
|
-
declare function createTextAgentLoop$1(options: TextAgentLoopOptions$1): AgentLoop$1;
|
|
435
|
-
//#endregion
|
|
436
|
-
//#region src/adapters/compatibility/agent-execution/loop/agent-loop.d.ts
|
|
437
|
-
interface AgentLoopInput {
|
|
438
|
-
readonly runId: AgentRunId;
|
|
439
|
-
readonly sessionKey: SessionKey;
|
|
440
|
-
readonly text: string;
|
|
441
|
-
readonly abortSignal: AbortSignal;
|
|
442
|
-
readonly previousSessionState?: AgentRunState;
|
|
443
|
-
readonly previousSessionTranscript?: AgentTranscript;
|
|
444
|
-
readonly messages?: ReadonlyArray<AgentTranscriptMessage>;
|
|
445
|
-
readonly invocation?: AgentInvocationOrigin;
|
|
446
|
-
/** Optional mailbox for user steering while the run is active. */
|
|
447
|
-
readonly steering?: AgentSteeringChannel;
|
|
448
|
-
}
|
|
449
|
-
interface AgentSteeringChannel {
|
|
450
|
-
next(signal?: AbortSignal): Promise<string>;
|
|
451
|
-
close?(): Promise<readonly string[]>;
|
|
452
|
-
}
|
|
453
520
|
interface AgentLoop {
|
|
454
521
|
run(input: AgentLoopInput): Stream.Stream<AgentLoopEvent, unknown>;
|
|
455
522
|
/** Provider adapters opt in only when they can consume steering safely. */
|
|
456
523
|
readonly supportsSteering?: boolean;
|
|
524
|
+
/** Structured steering is a separate capability from the legacy text mailbox. */
|
|
525
|
+
readonly supportsStructuredSteering?: boolean;
|
|
457
526
|
}
|
|
458
|
-
type AgentLoopCallbackOutput = Iterable<AgentLoopEventLike> | AsyncIterable<AgentLoopEventLike> | Stream.Stream<AgentLoopEventLike, unknown>;
|
|
459
|
-
type AgentLoopCallbackResult = AgentLoopCallbackOutput | PromiseLike<AgentLoopCallbackOutput> | Effect.Effect<AgentLoopCallbackOutput, unknown>;
|
|
460
|
-
type AgentLoopCallback = (input: AgentLoopInput) => AgentLoopCallbackResult;
|
|
461
|
-
interface AsyncIterableAgentLoopOptions {
|
|
462
|
-
readonly run: (input: AgentLoopInput) => AsyncIterable<AgentLoopEventLike>;
|
|
463
|
-
}
|
|
464
|
-
interface EventAgentLoopOptions {
|
|
465
|
-
readonly events: ReadonlyArray<AgentLoopEventLike> | ((input: AgentLoopInput) => ReadonlyArray<AgentLoopEventLike> | Promise<ReadonlyArray<AgentLoopEventLike>>);
|
|
466
|
-
}
|
|
467
|
-
type TextAgentLoopCallback = (input: AgentLoopInput) => string | Promise<string>;
|
|
468
|
-
interface TextAgentLoopOptions {
|
|
469
|
-
readonly generate: (input: AgentLoopInput) => Effect.Effect<string, unknown>;
|
|
470
|
-
}
|
|
471
|
-
declare function createEventAgentLoop(options: EventAgentLoopOptions): AgentLoop;
|
|
472
|
-
declare function createAsyncIterableAgentLoop(options: AsyncIterableAgentLoopOptions): AgentLoop;
|
|
473
|
-
declare function createAgentLoopFromCallback(run: AgentLoopCallback): AgentLoop;
|
|
474
|
-
declare function createTextAgentLoop(options: TextAgentLoopOptions): AgentLoop;
|
|
475
|
-
declare function createTextAgentLoopFromCallback(generate: TextAgentLoopCallback): AgentLoop;
|
|
476
|
-
declare function toEffectAgentLoop(loop: AgentLoop): AgentLoop$1;
|
|
477
|
-
declare function fromEffectAgentLoop(loop: AgentLoop$1): AgentLoop;
|
|
478
|
-
declare function toEffectAgentLoopInput(input: AgentLoopInput): AgentLoopInput$1;
|
|
479
|
-
declare function toCompatibilityAgentLoopInput(input: AgentLoopInput$1): AgentLoopInput;
|
|
480
527
|
//#endregion
|
|
481
|
-
export {
|
|
528
|
+
export { UserInput as C, MaterializedAttachment as S, AttachmentAccessBinding as _, AgentTranscript as a, InputPart as b, AgentRunSummary as c, AgentDomainEvent as d, AgentRunId as f, AttachmentAccess as g, AgentSteeringInput as h, AgentMemoryInvocationIdentity as i, AgentSessionSummary as l, ATTACHMENT_RECOVERY_COMMAND as m, AgentLoopInput as n, AgentTranscriptTurn as o, SessionKey as p, AgentInvocationOrigin as r, AgentHistory as s, AgentLoop as t, AgentRunState as u, InputMessage as v, InputRecovery as x, InputNoticePart as y };
|
|
529
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
//#region src/core/application/agent-execution/contracts/agent-user-input.ts
|
|
2
|
+
/** Reserved Bash action handled by the Run binding; never an OS executable. */
|
|
3
|
+
const ATTACHMENT_RECOVERY_COMMAND = "rivus-attachment-recover";
|
|
4
|
+
function isAgentSteeringRequest(value) {
|
|
5
|
+
return typeof value === "object" && value !== null && "userInput" in value;
|
|
6
|
+
}
|
|
7
|
+
/** Detach caller-owned nested arrays before an input enters a Run or mailbox. */
|
|
8
|
+
function cloneUserInput(input) {
|
|
9
|
+
return structuredClone(input);
|
|
10
|
+
}
|
|
11
|
+
function cloneAgentSteeringInput(input) {
|
|
12
|
+
if (typeof input === "string") return input;
|
|
13
|
+
if (isAgentSteeringRequest(input)) return {
|
|
14
|
+
...input.attachmentAccess ? { attachmentAccess: input.attachmentAccess } : {},
|
|
15
|
+
userInput: cloneUserInput(input.userInput)
|
|
16
|
+
};
|
|
17
|
+
return cloneUserInput(input);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Validate data crossing a persistence or adapter boundary before any access
|
|
21
|
+
* binding is consulted. The structural check deliberately does not validate
|
|
22
|
+
* or grant a notice recovery action; only AttachmentAccess can do that.
|
|
23
|
+
*/
|
|
24
|
+
function isValidUserInput(value, limits = {}) {
|
|
25
|
+
const maxDepth = limits.maxDepth ?? 4;
|
|
26
|
+
const maxMessages = limits.maxMessages ?? 100;
|
|
27
|
+
const maxPartsPerMessage = limits.maxPartsPerMessage ?? 256;
|
|
28
|
+
const maxTextCharacters = limits.maxTextCharacters ?? 1e5;
|
|
29
|
+
const seen = /* @__PURE__ */ new Set();
|
|
30
|
+
let messageCount = 0;
|
|
31
|
+
let textCharacters = 0;
|
|
32
|
+
if (!isRecord(value) || value.version !== 1 || !isNonEmptyString(value.deliveryId, 512)) return false;
|
|
33
|
+
return validateMessage(value.message, "direct", 0);
|
|
34
|
+
function validateMessage(value, expectedSource, depth) {
|
|
35
|
+
if (depth > maxDepth || !isRecord(value) || seen.has(value)) return false;
|
|
36
|
+
seen.add(value);
|
|
37
|
+
if (++messageCount > maxMessages || value.source !== expectedSource || !isNonEmptyString(value.id, 512)) return false;
|
|
38
|
+
if (value.author !== void 0 && (!isRecord(value.author) || !optionalString(value.author.id, 512) || !optionalString(value.author.name, 512))) return false;
|
|
39
|
+
if (value.sentAt !== void 0 && !isNonEmptyString(value.sentAt, 128)) return false;
|
|
40
|
+
if (!Array.isArray(value.parts) || value.parts.length > maxPartsPerMessage) return false;
|
|
41
|
+
for (const part of value.parts) if (!validatePart(part, expectedSource, depth)) return false;
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
function validatePart(value, messageSource, depth) {
|
|
45
|
+
if (!isRecord(value) || typeof value.type !== "string") return false;
|
|
46
|
+
if (value.type === "text") {
|
|
47
|
+
if (typeof value.text !== "string" || value.source !== void 0 && value.source !== messageSource) return false;
|
|
48
|
+
if (value.controlEligible !== void 0 && typeof value.controlEligible !== "boolean") return false;
|
|
49
|
+
textCharacters += value.text.length;
|
|
50
|
+
return textCharacters <= maxTextCharacters;
|
|
51
|
+
}
|
|
52
|
+
if (value.type === "image") return isNonEmptyString(value.attachmentId, 512) && isNonEmptyString(value.mimeType, 256) && optionalNonNegativeInteger(value.size);
|
|
53
|
+
if (value.type === "attachment") return isNonEmptyString(value.attachmentId, 512) && isNonEmptyString(value.mimeType, 256) && (value.mediaKind === "file" || value.mediaKind === "audio" || value.mediaKind === "video") && nonNegativeInteger(value.size) && optionalString(value.fileName, 512) && optionalNonNegativeInteger(value.durationMs);
|
|
54
|
+
if (value.type === "quote") {
|
|
55
|
+
if (value.kind !== "forward" && value.kind !== "reply" || !Array.isArray(value.messages)) return false;
|
|
56
|
+
return value.messages.every((message) => validateMessage(message, "quoted", depth + 1));
|
|
57
|
+
}
|
|
58
|
+
if (value.type === "notice") {
|
|
59
|
+
if (!noticeReason(value.reason) || typeof value.text !== "string") return false;
|
|
60
|
+
textCharacters += value.text.length;
|
|
61
|
+
if (textCharacters > maxTextCharacters) return false;
|
|
62
|
+
if (value.recovery !== void 0) {
|
|
63
|
+
if (!isRecord(value.recovery) || !isNonEmptyString(value.recovery.toolName, 256) || !isRecord(value.recovery.arguments)) return false;
|
|
64
|
+
for (const [key, argument] of Object.entries(value.recovery.arguments)) {
|
|
65
|
+
if (typeof argument === "string") textCharacters += argument.length;
|
|
66
|
+
if (textCharacters > maxTextCharacters || !isNonEmptyString(key, 256) || !(typeof argument === "string" || typeof argument === "number" && Number.isFinite(argument))) return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function isRecord(value) {
|
|
75
|
+
return typeof value === "object" && value !== null;
|
|
76
|
+
}
|
|
77
|
+
function isNonEmptyString(value, maxLength) {
|
|
78
|
+
return typeof value === "string" && value.length > 0 && value.length <= maxLength;
|
|
79
|
+
}
|
|
80
|
+
function optionalString(value, maxLength) {
|
|
81
|
+
return value === void 0 || typeof value === "string" && value.length <= maxLength;
|
|
82
|
+
}
|
|
83
|
+
function nonNegativeInteger(value) {
|
|
84
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
85
|
+
}
|
|
86
|
+
function optionalNonNegativeInteger(value) {
|
|
87
|
+
return value === void 0 || nonNegativeInteger(value);
|
|
88
|
+
}
|
|
89
|
+
function noticeReason(value) {
|
|
90
|
+
return value === "permission_denied" || value === "expired" || value === "unsupported" || value === "limit_exceeded" || value === "invalid_content" || value === "unavailable";
|
|
91
|
+
}
|
|
92
|
+
/** A stable textual compatibility projection for old prompt/history APIs. */
|
|
93
|
+
function projectUserInputText(input) {
|
|
94
|
+
return projectMessageText(input.message);
|
|
95
|
+
}
|
|
96
|
+
function projectMessageText(message) {
|
|
97
|
+
return message.parts.flatMap((part) => {
|
|
98
|
+
switch (part.type) {
|
|
99
|
+
case "text": return [part.text];
|
|
100
|
+
case "image": return [`[图片 ${part.attachmentId}]`];
|
|
101
|
+
case "attachment": return [`[${part.mediaKind === "audio" ? "音频" : part.mediaKind === "video" ? "视频" : "文件"}${part.fileName ? ` ${part.fileName}` : ""}]`];
|
|
102
|
+
case "notice": return [part.text];
|
|
103
|
+
case "quote": return part.messages.flatMap(projectMessageText);
|
|
104
|
+
}
|
|
105
|
+
}).filter((text) => text.length > 0).join("\n");
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
export { isValidUserInput as a, isAgentSteeringRequest as i, cloneAgentSteeringInput as n, projectUserInputText as o, cloneUserInput as r, ATTACHMENT_RECOVERY_COMMAND as t };
|
|
109
|
+
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as AgentRunId, i as AgentMemoryInvocationIdentity, r as AgentInvocationOrigin } from "./agent-loop.js";
|
|
2
2
|
import { Effect } from "effect";
|
|
3
|
-
|
|
4
3
|
//#region src/core/application/agent-execution/contracts/model-runtime.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Runtime-owned model contracts. These describe the actual model binding and
|
|
@@ -237,6 +236,69 @@ interface AgentModelContentObserver {
|
|
|
237
236
|
observeOutput(observation: AgentModelOutputObservation): void;
|
|
238
237
|
}
|
|
239
238
|
//#endregion
|
|
239
|
+
//#region src/core/domain/tool-operation/value-objects/binding.d.ts
|
|
240
|
+
interface ToolOperationBinding {
|
|
241
|
+
readonly agentId: string;
|
|
242
|
+
readonly inputDigest: string;
|
|
243
|
+
readonly instanceId: string;
|
|
244
|
+
readonly sourceMessageId: string;
|
|
245
|
+
readonly toolId: string;
|
|
246
|
+
readonly toolVersion: string;
|
|
247
|
+
}
|
|
248
|
+
//#endregion
|
|
249
|
+
//#region src/core/domain/tool-operation/aggregate/snapshot.d.ts
|
|
250
|
+
type ToolOperationState = {
|
|
251
|
+
readonly status: "pending";
|
|
252
|
+
} | {
|
|
253
|
+
readonly result: unknown;
|
|
254
|
+
readonly status: "completed";
|
|
255
|
+
} | {
|
|
256
|
+
readonly reason: string;
|
|
257
|
+
readonly status: "reconciliation-required";
|
|
258
|
+
} | {
|
|
259
|
+
readonly status: "aborted";
|
|
260
|
+
};
|
|
261
|
+
interface ToolOperationReconciliationAction {
|
|
262
|
+
readonly actorId: string;
|
|
263
|
+
readonly at: string;
|
|
264
|
+
readonly note: string;
|
|
265
|
+
}
|
|
266
|
+
interface ToolOperationReconciliation extends ToolOperationReconciliationAction {
|
|
267
|
+
readonly outcome: "applied" | "not-applied";
|
|
268
|
+
}
|
|
269
|
+
interface ToolOperationSnapshot {
|
|
270
|
+
readonly binding: ToolOperationBinding;
|
|
271
|
+
readonly operationId: string;
|
|
272
|
+
readonly reconciliation?: ToolOperationReconciliation;
|
|
273
|
+
readonly revision: number;
|
|
274
|
+
readonly state: ToolOperationState;
|
|
275
|
+
}
|
|
276
|
+
type ToolOperationRecord = ToolOperationSnapshot;
|
|
277
|
+
type ToolOperationReconciliationOutcome = {
|
|
278
|
+
readonly result: unknown;
|
|
279
|
+
readonly status: "applied";
|
|
280
|
+
} | {
|
|
281
|
+
readonly status: "not-applied";
|
|
282
|
+
};
|
|
283
|
+
type ToolOperationBeginResult = {
|
|
284
|
+
readonly status: "acquired";
|
|
285
|
+
} | {
|
|
286
|
+
readonly result: unknown;
|
|
287
|
+
readonly status: "completed";
|
|
288
|
+
} | {
|
|
289
|
+
readonly status: "blocked";
|
|
290
|
+
readonly reason: string;
|
|
291
|
+
};
|
|
292
|
+
type ToolOperationInspectResult = {
|
|
293
|
+
readonly status: "missing";
|
|
294
|
+
} | {
|
|
295
|
+
readonly result: unknown;
|
|
296
|
+
readonly status: "completed";
|
|
297
|
+
} | {
|
|
298
|
+
readonly status: "blocked";
|
|
299
|
+
readonly reason: string;
|
|
300
|
+
};
|
|
301
|
+
//#endregion
|
|
240
302
|
//#region src/core/application/agent-execution/invocation/agent-invocation-identity.d.ts
|
|
241
303
|
interface NormalizedAgentInvocation {
|
|
242
304
|
readonly allowedActorOpenIds: ReadonlyArray<string>;
|
|
@@ -292,10 +354,30 @@ interface InvocationAuthorityIdentity {
|
|
|
292
354
|
declare function createInvocationAuthority(authority: InvocationAuthority, identity?: InvocationAuthorityIdentity): InvocationAuthorityRef;
|
|
293
355
|
declare function resolveInvocationAuthority(reference: InvocationAuthorityRef): InvocationAuthority;
|
|
294
356
|
//#endregion
|
|
357
|
+
//#region src/core/application/tool-execution/brokerage/tool-input-digest.d.ts
|
|
358
|
+
type ToolInputDigest = (canonicalJson: string) => string;
|
|
359
|
+
declare function createToolInputDigest(input: unknown, digest: ToolInputDigest): string;
|
|
360
|
+
//#endregion
|
|
361
|
+
//#region src/core/application/tool-execution/operation/tool-operation-ledger.d.ts
|
|
362
|
+
interface ToolOperationLedger {
|
|
363
|
+
abort(operationId: string, binding: ToolOperationBinding): Effect.Effect<void, unknown>;
|
|
364
|
+
begin(operationId: string, binding: ToolOperationBinding): Effect.Effect<ToolOperationBeginResult, unknown>;
|
|
365
|
+
complete(operationId: string, binding: ToolOperationBinding, result: unknown): Effect.Effect<void, unknown>;
|
|
366
|
+
inspect(operationId: string, binding: ToolOperationBinding): Effect.Effect<ToolOperationInspectResult, unknown>;
|
|
367
|
+
reconciliationRequired(): ReadonlyArray<ToolOperationRecord>;
|
|
368
|
+
reconcile(input: {
|
|
369
|
+
readonly action: ToolOperationReconciliationAction;
|
|
370
|
+
readonly expectedRevision: number;
|
|
371
|
+
readonly operationId: string;
|
|
372
|
+
readonly outcome: ToolOperationReconciliationOutcome;
|
|
373
|
+
}): Effect.Effect<ToolOperationRecord, unknown>;
|
|
374
|
+
requireReconciliation(operationId: string, binding: ToolOperationBinding, reason: string): Effect.Effect<void, unknown>;
|
|
375
|
+
unresolvedForSource(sourceMessageId: string): ReadonlyArray<ToolOperationRecord>;
|
|
376
|
+
}
|
|
377
|
+
//#endregion
|
|
295
378
|
//#region src/core/application/tool-execution/authority/tool-risk-policy.d.ts
|
|
296
379
|
type ToolRisk = "observe" | "mutate" | "irreversible" | "host-control";
|
|
297
380
|
type ToolIdempotency = "none" | "supported" | "required";
|
|
298
|
-
declare function requiresToolApproval(risk: ToolRisk): boolean;
|
|
299
381
|
//#endregion
|
|
300
382
|
//#region src/core/application/tool-execution/brokerage/tool-broker-ports.d.ts
|
|
301
383
|
interface AuthorizationPolicyState {
|
|
@@ -374,6 +456,23 @@ declare class ToolExecutorInputRejected extends Error {
|
|
|
374
456
|
readonly name = "ToolExecutorInputRejected";
|
|
375
457
|
}
|
|
376
458
|
//#endregion
|
|
459
|
+
//#region src/core/application/tool-execution/brokerage/tool-broker.d.ts
|
|
460
|
+
interface ToolBrokerOptions {
|
|
461
|
+
readonly approvals: ToolApprovalService;
|
|
462
|
+
readonly catalog: ToolCatalog;
|
|
463
|
+
readonly digest: ToolInputDigest;
|
|
464
|
+
readonly hostTools?: ReadonlyArray<ToolDescriptor>;
|
|
465
|
+
readonly operations?: ToolOperationLedger;
|
|
466
|
+
readonly policy: AuthorizationPolicyProvider;
|
|
467
|
+
}
|
|
468
|
+
interface ToolBroker {
|
|
469
|
+
execute(request: ToolExecutionRequest): Effect.Effect<unknown, unknown>;
|
|
470
|
+
}
|
|
471
|
+
declare class ToolInvocationDenied extends Error {
|
|
472
|
+
readonly name = "ToolInvocationDenied";
|
|
473
|
+
}
|
|
474
|
+
declare function createToolBroker(options: ToolBrokerOptions): ToolBroker;
|
|
475
|
+
//#endregion
|
|
377
476
|
//#region src/core/application/tool-execution/contracts/rivus-runtime-tool.d.ts
|
|
378
477
|
declare const RIVUS_RUNTIME_TOOL_IDS: readonly ["read", "bash", "edit", "write", "grep", "find", "ls"];
|
|
379
478
|
type RivusRuntimeToolId = (typeof RIVUS_RUNTIME_TOOL_IDS)[number];
|
|
@@ -383,4 +482,5 @@ interface RivusRuntimeToolGrantSet {
|
|
|
383
482
|
}
|
|
384
483
|
declare function isRivusRuntimeToolId(value: string): value is RivusRuntimeToolId;
|
|
385
484
|
//#endregion
|
|
386
|
-
export {
|
|
485
|
+
export { RivusMemoryScope as A, RivusToolRisk as B, NormalizedAgentInvocation as C, AgentModelContentObserver as D, ToolOperationRecord as E, RivusToolFactoryContext as F, RunAdmissionOptions as G, ModelChangeClock as H, RivusToolGrantSet as I, RivusSkillGrantSet as J, RegisteredRivusSkill as K, RivusToolGrantSetOperations as L, RivusToolDescriptor as M, RivusToolExecutionContext as N, RegisteredRivusTool as O, RivusToolExecutor as P, ModelReference as Q, RivusToolIdempotency as R, resolveInvocationAuthority as S, ToolOperationReconciliationAction as T, RunAdmission as U, ModelChangeBoundaryDeadlineError as V, RunAdmissionLease as W, ModelChangePaidCallKind as X, ModelBinding as Y, ModelChangeRuntimePort as Z, createToolInputDigest as _, ToolBroker as a, InvocationToolGrantSet as b, createToolBroker as c, ToolDescriptor as d, ToolExecutionContext as f, ToolInputDigest as g, ToolOperationLedger as h, isRivusRuntimeToolId as i, RivusResolvedToolDescriptor as j, RivusHostToolDescriptor as k, AuthorizationPolicyState as l, ToolExecutorInputRejected as m, RivusRuntimeToolGrantSet as n, ToolBrokerOptions as o, ToolExecutionRequest as p, RivusSkillDescriptor as q, RivusRuntimeToolId as r, ToolInvocationDenied as s, RIVUS_RUNTIME_TOOL_IDS as t, ToolApprovalRequest as u, InvalidInvocationAuthority as v, normalizeAgentInvocation as w, createInvocationAuthority as x, InvocationAuthorityRef as y, RivusToolInputRejected as z };
|
|
486
|
+
export {};
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
//#region src/core/application/tool-execution/contracts/rivus-tool.ts
|
|
2
|
-
var RivusToolInputRejected = class extends Error {
|
|
3
|
-
name = "RivusToolInputRejected";
|
|
4
|
-
};
|
|
5
|
-
//#endregion
|
|
6
1
|
//#region src/core/application/agent-execution/invocation/agent-invocation-identity.ts
|
|
7
2
|
/**
|
|
8
3
|
* Background-session conversationId is captured only from the explicit origin
|
|
@@ -67,11 +62,6 @@ function isRecord(value) {
|
|
|
67
62
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
68
63
|
}
|
|
69
64
|
//#endregion
|
|
70
|
-
//#region src/core/application/tool-execution/authority/tool-risk-policy.ts
|
|
71
|
-
function requiresToolApproval(risk) {
|
|
72
|
-
return risk === "irreversible" || risk === "host-control";
|
|
73
|
-
}
|
|
74
|
-
//#endregion
|
|
75
65
|
//#region src/core/application/tool-execution/brokerage/tool-input-digest.ts
|
|
76
66
|
var InvalidStableJson = class extends Error {
|
|
77
67
|
name = "InvalidStableJson";
|
|
@@ -87,9 +77,6 @@ function createToolInputDigest(input, digest) {
|
|
|
87
77
|
throw error;
|
|
88
78
|
}
|
|
89
79
|
}
|
|
90
|
-
function normalizeStableJson(value) {
|
|
91
|
-
return JSON.parse(serializeStableJson(value, /* @__PURE__ */ new Set()));
|
|
92
|
-
}
|
|
93
80
|
function serializeStableJson(value, ancestors) {
|
|
94
81
|
if (value === null) return "null";
|
|
95
82
|
if (typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
|
|
@@ -116,4 +103,10 @@ function serializeStableJson(value, ancestors) {
|
|
|
116
103
|
}
|
|
117
104
|
}
|
|
118
105
|
//#endregion
|
|
119
|
-
|
|
106
|
+
//#region src/core/application/tool-execution/authority/tool-risk-policy.ts
|
|
107
|
+
function requiresToolApproval(risk) {
|
|
108
|
+
return risk === "irreversible" || risk === "host-control";
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
export { createInvocationAuthority as a, InvalidInvocationAuthority as i, InvalidToolInput as n, resolveInvocationAuthority as o, createToolInputDigest as r, normalizeAgentInvocation as s, requiresToolApproval as t };
|
|
112
|
+
|