@rivus/gateway 0.18.2 → 0.20.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.
@@ -1,285 +0,0 @@
1
- import { A as RivusDeploymentRuntimePort, C as FeishuReceiveMessagePayload, D as CreateRivusDeploymentRuntimePortInput, E as CreateRivusDeploymentEndpointPortInput, O as RivusDeploymentBackgroundSessionPort, S as FeishuCardActionTriggerPayload, T as CreateRivusDeploymentBackgroundSessionPortInput, U as AutomationScheduler, W as RecoveryControl, _ as DurableQueue, a as RivusDeploymentBootstrapContext, b as FeishuAgentRunPreparation, c as RivusDaemonProcess, d as FeishuReceiveMessageReplayResult, f as FeishuReceiveRuntimeStatus, g as DurableQueueWorkerDrainResult, h as DurableQueueWorker, i as RivusDaemonPromptRunner, k as RivusDeploymentEndpointPort, l as RivusDaemonTransport, m as FeishuMessageAcceptResult, p as FeishuInboundDeliveryMetadata, r as RivusDaemonFeishuReplayRunner, t as RivusDaemonBootstrapContext, u as FeishuReceiveMessageReplayOptions, v as DurableQueueDrainResult, w as CreateRivusDeploymentAutomationPortInput, x as FeishuStreamAction, y as FeishuAgentDaemonHandleResult } from "../chunks/rivus-daemon-cli.js";
2
- import { AgentEventLog, AgentHarness, AgentHistory, AgentRunId, AgentRunState, PromptCommand } from "@rivus/runtime";
3
- import { Effect } from "effect";
4
- import { PeriodicEffectLoop } from "@rivus/platform/concurrency";
5
- //#region src/adapters/feishu/protocol/feishu-card-protocol.d.ts
6
- /** Shared raw-card schema used by Feishu protocol adapters. */
7
- interface FeishuRawCardJson {
8
- readonly body: {
9
- readonly direction?: "horizontal" | "vertical";
10
- readonly elements: ReadonlyArray<unknown>;
11
- readonly padding?: string;
12
- readonly vertical_spacing?: string;
13
- };
14
- readonly config: {
15
- readonly streaming_mode?: boolean;
16
- readonly update_multi: true;
17
- };
18
- readonly header: {
19
- readonly padding?: string;
20
- readonly template: "blue" | "green" | "grey" | "orange" | "red";
21
- readonly title: {
22
- readonly content: string;
23
- readonly tag: "plain_text";
24
- };
25
- };
26
- readonly schema: "2.0";
27
- }
28
- //#endregion
29
- //#region src/adapters/feishu/runtime/card-action-response.d.ts
30
- interface FeishuCardActionCallbackResponse {
31
- readonly card?: {
32
- readonly data: FeishuRawCardJson;
33
- readonly type: "raw";
34
- };
35
- readonly toast: FeishuCardActionToast;
36
- }
37
- interface FeishuCardActionToast {
38
- readonly type: "success" | "info" | "warning" | "error";
39
- readonly content: string;
40
- readonly i18n?: {
41
- readonly en_us?: string;
42
- readonly zh_cn?: string;
43
- };
44
- }
45
- //#endregion
46
- //#region src/adapters/feishu/runtime/event-handlers.d.ts
47
- interface FeishuSdkReceiveMessagePayload {
48
- readonly message: FeishuReceiveMessagePayload["event"]["message"];
49
- readonly sender?: FeishuReceiveMessagePayload["event"]["sender"];
50
- readonly tenant_key?: string;
51
- }
52
- type FeishuReceiveMessageHandlerPayload = FeishuReceiveMessagePayload | FeishuSdkReceiveMessagePayload;
53
- interface FeishuEventHandlers {
54
- readonly "card.action.trigger"?: (payload: FeishuCardActionTriggerPayload) => Promise<FeishuCardActionCallbackResponse>;
55
- readonly "im.message.receive_v1": (payload: FeishuReceiveMessageHandlerPayload) => Promise<FeishuMessageAcceptResult>;
56
- }
57
- //#endregion
58
- //#region src/bootstrap/feishu/agent-runtime.d.ts
59
- interface FeishuAgentRuntime {
60
- readonly handlers: FeishuEventHandlers;
61
- readonly harness: AgentHarness;
62
- readonly queue: DurableQueue<FeishuReceiveMessagePayload, FeishuInboundDeliveryMetadata, FeishuAgentDaemonHandleResult>;
63
- readonly worker: DurableQueueWorker<FeishuAgentDaemonHandleResult>;
64
- drainAvailable(): Effect.Effect<DurableQueueWorkerDrainResult<FeishuAgentDaemonHandleResult>, unknown>;
65
- drainOne(): Effect.Effect<DurableQueueDrainResult<FeishuAgentDaemonHandleResult>, unknown>;
66
- pending(): number;
67
- receiveStatus(): FeishuReceiveRuntimeStatus;
68
- replayReceiveMessage(payload: FeishuReceiveMessagePayload, options?: FeishuReceiveMessageReplayOptions): Effect.Effect<FeishuReceiveMessageReplayResult, unknown>;
69
- }
70
- //#endregion
71
- //#region src/platform/daemon/status/daemon-status-reporter.d.ts
72
- interface DaemonStatusSnapshot<History, RunState, CardStatus, ReceiveStatus> {
73
- readonly agentId: string;
74
- readonly cards?: CardStatus;
75
- readonly harness: {
76
- readonly activeRunId?: string;
77
- readonly activeRunState?: RunState;
78
- readonly activeSessionKey?: string;
79
- readonly busy: boolean;
80
- };
81
- readonly history: History;
82
- readonly process: {
83
- readonly running: boolean;
84
- };
85
- readonly queue: {
86
- readonly pending: number;
87
- };
88
- readonly receive?: ReceiveStatus;
89
- readonly transport: {
90
- readonly running: boolean;
91
- };
92
- readonly workerLoop: {
93
- readonly running: boolean;
94
- };
95
- }
96
- interface DaemonStatusReporter<History, RunState, CardStatus, ReceiveStatus> {
97
- status(): Effect.Effect<DaemonStatusSnapshot<History, RunState, CardStatus, ReceiveStatus>, unknown>;
98
- }
99
- //#endregion
100
- //#region src/adapters/feishu/runtime/websocket-daemon.d.ts
101
- interface FeishuWebSocketDaemon {
102
- running(): boolean;
103
- start(): Promise<void>;
104
- stop(): Promise<void>;
105
- }
106
- //#endregion
107
- //#region src/core/application/card-presentation/projection/card-presentation.d.ts
108
- type CardPresentationStatus = "streaming" | "handoff-pending" | "active" | "closed" | "terminal";
109
- interface CardPresentation {
110
- readonly runId: string;
111
- readonly presentationId: string;
112
- readonly generation: number;
113
- readonly cardId: string;
114
- readonly elementId?: string;
115
- readonly sourceMessageId: string;
116
- readonly status: CardPresentationStatus;
117
- readonly createdAt: string;
118
- readonly leaseDeadlineAt: string;
119
- readonly handoffAt?: string;
120
- readonly handoffFailedAt?: string;
121
- readonly predecessorPresentationId?: string;
122
- readonly successorPresentationId?: string;
123
- readonly terminalReceiptId?: string;
124
- }
125
- interface CardPresentationChain {
126
- readonly runId: string;
127
- readonly activeGeneration: number;
128
- readonly activePresentationId: string;
129
- readonly presentations: ReadonlyArray<CardPresentation>;
130
- readonly revision: number;
131
- }
132
- interface CardPresentationBinding {
133
- readonly cardId: string;
134
- readonly createdAt: string;
135
- readonly elementId?: string;
136
- readonly leaseDeadlineAt: string;
137
- readonly presentationId: string;
138
- readonly runId: string;
139
- readonly sourceMessageId: string;
140
- }
141
- interface CardPresentationSuccessor {
142
- readonly cardId: string;
143
- readonly createdAt: string;
144
- readonly elementId?: string;
145
- readonly leaseDeadlineAt: string;
146
- readonly presentationId: string;
147
- }
148
- //#endregion
149
- //#region src/core/application/card-presentation/projection/card-presentation-service.d.ts
150
- interface CardPresentationHandoffStart {
151
- readonly presentation: CardPresentation;
152
- readonly started: boolean;
153
- }
154
- interface BeginCardPresentationHandoffInput {
155
- readonly handoffAt: string;
156
- readonly runId: string;
157
- }
158
- interface CompleteCardPresentationHandoffInput {
159
- readonly runId: string;
160
- readonly successor: CardPresentationSuccessor;
161
- }
162
- interface FailCardPresentationHandoffInput {
163
- readonly failedAt: string;
164
- readonly runId: string;
165
- }
166
- interface MarkCardPresentationTerminalInput {
167
- readonly runId: string;
168
- readonly terminalReceiptId: string;
169
- }
170
- interface CardPresentationService {
171
- chain(runId: string): CardPresentationChain | undefined;
172
- chains(): ReadonlyArray<CardPresentationChain>;
173
- size(): number;
174
- bind(binding: CardPresentationBinding): Effect.Effect<CardPresentation, unknown>;
175
- beginHandoff(input: BeginCardPresentationHandoffInput): Effect.Effect<CardPresentationHandoffStart, unknown>;
176
- compensateInterruptedHandoffs(compensatedAt: string): Effect.Effect<ReadonlyArray<CardPresentationChain>, unknown>;
177
- completeHandoff(input: CompleteCardPresentationHandoffInput): Effect.Effect<CardPresentation, unknown>;
178
- failHandoff(input: FailCardPresentationHandoffInput): Effect.Effect<void, unknown>;
179
- markTerminal(input: MarkCardPresentationTerminalInput): Effect.Effect<void, unknown>;
180
- release(runId: string): Effect.Effect<void, unknown>;
181
- }
182
- //#endregion
183
- //#region src/adapters/feishu/card-presentation/delivery/feishu-cardkit-publisher.d.ts
184
- interface FeishuCardTarget {
185
- readonly cardId: string;
186
- readonly elementId: string;
187
- readonly progressElementId?: string;
188
- }
189
- //#endregion
190
- //#region src/adapters/feishu/card-presentation/target/feishu-card-target-registry.d.ts
191
- interface FeishuCardTargetRegistry extends CardPresentationService {
192
- resolveTarget(runId: AgentRunId): Effect.Effect<FeishuCardTarget, unknown>;
193
- }
194
- //#endregion
195
- //#region src/adapters/feishu/card-presentation/rollover/feishu-card-rollover.d.ts
196
- interface FeishuCardRolloverTarget {
197
- readonly cardId: string;
198
- readonly elementId?: string;
199
- }
200
- interface FeishuCardRolloverStreamPublisher {
201
- flush(runId?: string): Effect.Effect<void, unknown>;
202
- publish(action: FeishuStreamAction): Effect.Effect<void, unknown>;
203
- }
204
- type FeishuCardRolloverEventType = "handoff_started" | "handoff_succeeded" | "handoff_failed" | "handoff_notice_failed" | "presentation_write_failed" | "stale_update_dropped" | "stream_closed" | "terminal_delivery_failed";
205
- type FeishuCardRolloverCounters = Readonly<Record<FeishuCardRolloverEventType, number>>;
206
- interface FeishuCardRolloverStatus {
207
- readonly counters: FeishuCardRolloverCounters;
208
- readonly leaseMs: number;
209
- readonly live: ReadonlyArray<CardPresentation>;
210
- }
211
- type FeishuCardRolloverHandoffResult = {
212
- readonly presentation: CardPresentation;
213
- readonly status: "rolled-over";
214
- } | {
215
- readonly reason: "already-pending" | "not-due" | "not-live" | "not-streaming";
216
- readonly status: "skipped";
217
- } | {
218
- readonly error: unknown;
219
- readonly status: "failed";
220
- };
221
- interface FeishuCardRollover extends FeishuCardRolloverStreamPublisher {
222
- bindRun(run: FeishuAgentRunPreparation, target: FeishuCardRolloverTarget): Effect.Effect<CardPresentation, unknown>;
223
- dueRunIds(now: Date): ReadonlyArray<string>;
224
- handoff(runId: string): Effect.Effect<FeishuCardRolloverHandoffResult, unknown>;
225
- observeStreamClosed(cardId: string): void;
226
- recover(): Effect.Effect<{
227
- readonly compensated: number;
228
- }, unknown>;
229
- releaseRun(runId: string): Effect.Effect<void>;
230
- status(): FeishuCardRolloverStatus;
231
- }
232
- //#endregion
233
- //#region src/adapters/feishu/card-presentation/rollover/feishu-card-rollover-supervisor.d.ts
234
- interface FeishuCardRolloverSupervisorTickResult {
235
- readonly results: ReadonlyArray<FeishuCardRolloverHandoffResult>;
236
- }
237
- interface FeishuCardRolloverSupervisor {
238
- recover(): Effect.Effect<void, unknown>;
239
- running(): boolean;
240
- start(): void;
241
- stop(): Promise<void>;
242
- tick(): Effect.Effect<FeishuCardRolloverSupervisorTickResult, unknown>;
243
- }
244
- //#endregion
245
- //#region src/bootstrap/feishu/card-rollover-runtime.d.ts
246
- interface ConfiguredFeishuCardRolloverRuntime {
247
- readonly rollover: FeishuCardRollover;
248
- readonly supervisor: FeishuCardRolloverSupervisor;
249
- readonly transport: RivusDaemonTransport;
250
- prepareRun(run: FeishuAgentRunPreparation): Effect.Effect<void, unknown>;
251
- }
252
- //#endregion
253
- //#region src/bootstrap/feishu/rivus-daemon-bootstrap.d.ts
254
- type ConfiguredRivusDaemonStatus = DaemonStatusSnapshot<AgentHistory, AgentRunState, FeishuCardRolloverStatus, FeishuReceiveRuntimeStatus>;
255
- type ConfiguredRivusDaemonStatusReporter = DaemonStatusReporter<AgentHistory, AgentRunState, FeishuCardRolloverStatus, FeishuReceiveRuntimeStatus>;
256
- interface ConfiguredRivusDaemonBootstrap {
257
- readonly cardRollover: ConfiguredFeishuCardRolloverRuntime;
258
- readonly cardTargets: FeishuCardTargetRegistry;
259
- readonly eventLog: AgentEventLog;
260
- readonly process: RivusDaemonProcess;
261
- readonly publisher: FeishuCardRollover;
262
- readonly runtime: FeishuAgentRuntime;
263
- readonly statusReporter: ConfiguredRivusDaemonStatusReporter;
264
- readonly transport: RivusDaemonTransport;
265
- readonly websocketTransport: FeishuWebSocketDaemon;
266
- readonly workerLoop: PeriodicEffectLoop;
267
- promptText(command: PromptCommand): Effect.Effect<string, unknown>;
268
- restoreHistory(): Effect.Effect<AgentHistory, unknown>;
269
- status(): Effect.Effect<ConfiguredRivusDaemonStatus, unknown>;
270
- }
271
- //#endregion
272
- //#region src/bootstrap/feishu/pi-feishu-daemon-bootstrap.d.ts
273
- export declare function createRivusDaemonProcess(context: RivusDaemonBootstrapContext): Promise<RivusDaemonProcess & RivusDaemonPromptRunner & RivusDaemonFeishuReplayRunner & Pick<ConfiguredRivusDaemonBootstrap, "status">>;
274
- //#endregion
275
- //#region src/bootstrap/pi-feishu.d.ts
276
- export declare function createRivusDeploymentAdapters(context: RivusDeploymentBootstrapContext): Promise<{
277
- dispose: () => Promise<void>;
278
- createRecoveryControl: () => Effect.Effect<RecoveryControl, unknown, never>;
279
- createBackgroundSession: ((input: CreateRivusDeploymentBackgroundSessionPortInput) => Effect.Effect<RivusDeploymentBackgroundSessionPort, unknown, never>) | undefined;
280
- createAutomation: (input: CreateRivusDeploymentAutomationPortInput) => Effect.Effect<AutomationScheduler, unknown, never>;
281
- createEndpoint: (input: CreateRivusDeploymentEndpointPortInput) => Effect.Effect<RivusDeploymentEndpointPort, unknown, never>;
282
- createRuntime: (input: CreateRivusDeploymentRuntimePortInput) => Effect.Effect<RivusDeploymentRuntimePort, unknown>;
283
- }>;
284
- //#endregion
285
- export {};
@@ -1,194 +0,0 @@
1
- //#region src/core/application/background-session/authority/background-session-authority.ts
2
- const BACKGROUND_SESSION_START_TOOL_ID = "background.start";
3
- const BACKGROUND_SESSION_TOOL_PLUGIN_ID = "rivus-core";
4
- const BACKGROUND_SESSION_TOOL_VERSION = "1.0.0";
5
- const BACKGROUND_SESSION_TOOL_DIGESTS = {
6
- "background.list": "sha256:c935847595e406d55ca889875b38db66bb1d4d7a34d7b0fb2b85aecf9478c149",
7
- "background.send": "sha256:b7ed492e45c794dc286f7f66aca8d046082d11dfdc8787eaf5604765b68a7735",
8
- "background.start": "sha256:773690e47f6eef1f1b289216e94cf98e548382d6cffb7b2f034c3ed0635dfcbb",
9
- "background.status": "sha256:6aaa328d6cd97d8755a63abbe97286f1061fd2f238f68b1e576ed9a1d2b7e6b1",
10
- "background.stop": "sha256:aa0bfdf0c9394058bfcbd8662e7bedd59055f9ddad51c2a1bb61666bd67ebfcb",
11
- "background.wait": "sha256:4a0dc80e933ad3c99b6d58421ac9ef733157e39e0ac9b6ad87ac6e65ceaedaab"
12
- };
13
- function createBackgroundSessionToolContracts() {
14
- return [
15
- Object.freeze({
16
- description: "Start a background agent session. Use when the request must wait for external changes, observe over time, or continue working after the foreground run ends. Returns a stable session id immediately; the foreground response can finish here. The detached session continues with the granted Skills, CLI, Tools, Project Space, and Memory of this agent.",
17
- digest: BACKGROUND_SESSION_TOOL_DIGESTS["background.start"],
18
- id: "background.start",
19
- idempotency: "supported",
20
- inputSchema: Object.freeze({
21
- additionalProperties: false,
22
- properties: Object.freeze({
23
- displayName: {
24
- type: "string",
25
- maxLength: 200
26
- },
27
- prompt: {
28
- type: "string",
29
- minLength: 1,
30
- maxLength: 2e4
31
- }
32
- }),
33
- required: ["prompt"],
34
- type: "object"
35
- }),
36
- pluginId: BACKGROUND_SESSION_TOOL_PLUGIN_ID,
37
- risk: "mutate",
38
- version: BACKGROUND_SESSION_TOOL_VERSION
39
- }),
40
- Object.freeze({
41
- description: "Pause the current background session durably and end the current step. Call with delayMs to resume after a delay, with until to resume at an absolute ISO time, or with neither to wait for user input. After this call no further tool calls are accepted in this step.",
42
- digest: BACKGROUND_SESSION_TOOL_DIGESTS["background.wait"],
43
- id: "background.wait",
44
- idempotency: "supported",
45
- inputSchema: Object.freeze({
46
- additionalProperties: false,
47
- properties: Object.freeze({
48
- delayMs: {
49
- type: "integer",
50
- minimum: 1e3,
51
- maximum: 864e5
52
- },
53
- reason: {
54
- type: "string",
55
- maxLength: 500
56
- },
57
- until: {
58
- type: "string",
59
- maxLength: 64
60
- }
61
- }),
62
- type: "object"
63
- }),
64
- pluginId: BACKGROUND_SESSION_TOOL_PLUGIN_ID,
65
- risk: "mutate",
66
- version: BACKGROUND_SESSION_TOOL_VERSION
67
- }),
68
- Object.freeze({
69
- description: "List background sessions owned by this conversation, newest first. Optionally filter by phase and limit the number of results.",
70
- digest: BACKGROUND_SESSION_TOOL_DIGESTS["background.list"],
71
- id: "background.list",
72
- idempotency: "supported",
73
- inputSchema: Object.freeze({
74
- additionalProperties: false,
75
- properties: Object.freeze({
76
- limit: {
77
- type: "integer",
78
- minimum: 1,
79
- maximum: 50
80
- },
81
- phase: {
82
- enum: [
83
- "queued",
84
- "running",
85
- "waiting",
86
- "input-required",
87
- "stopping",
88
- "stopped",
89
- "completed",
90
- "failed",
91
- "reconciliation-required"
92
- ],
93
- type: "string"
94
- }
95
- }),
96
- type: "object"
97
- }),
98
- pluginId: BACKGROUND_SESSION_TOOL_PLUGIN_ID,
99
- risk: "observe",
100
- version: BACKGROUND_SESSION_TOOL_VERSION
101
- }),
102
- Object.freeze({
103
- description: "Return the current phase, step counts, wake time, and result of one background session owned by this conversation.",
104
- digest: BACKGROUND_SESSION_TOOL_DIGESTS["background.status"],
105
- id: "background.status",
106
- idempotency: "supported",
107
- inputSchema: Object.freeze({
108
- additionalProperties: false,
109
- properties: Object.freeze({ sessionId: {
110
- type: "string",
111
- minLength: 1,
112
- maxLength: 200
113
- } }),
114
- required: ["sessionId"],
115
- type: "object"
116
- }),
117
- pluginId: BACKGROUND_SESSION_TOOL_PLUGIN_ID,
118
- risk: "observe",
119
- version: BACKGROUND_SESSION_TOOL_VERSION
120
- }),
121
- Object.freeze({
122
- description: "Send new user instruction text to a background session owned by this conversation and wake it. The input is delivered exactly once in the next step.",
123
- digest: BACKGROUND_SESSION_TOOL_DIGESTS["background.send"],
124
- id: "background.send",
125
- idempotency: "supported",
126
- inputSchema: Object.freeze({
127
- additionalProperties: false,
128
- properties: Object.freeze({
129
- message: {
130
- type: "string",
131
- minLength: 1,
132
- maxLength: 2e4
133
- },
134
- sessionId: {
135
- type: "string",
136
- minLength: 1,
137
- maxLength: 200
138
- }
139
- }),
140
- required: ["message", "sessionId"],
141
- type: "object"
142
- }),
143
- pluginId: BACKGROUND_SESSION_TOOL_PLUGIN_ID,
144
- risk: "mutate",
145
- version: BACKGROUND_SESSION_TOOL_VERSION
146
- }),
147
- Object.freeze({
148
- description: "Stop a background session owned by this conversation. Persists the cancellation, aborts the active step and its owned process, and delivers a terminal notice.",
149
- digest: BACKGROUND_SESSION_TOOL_DIGESTS["background.stop"],
150
- id: "background.stop",
151
- idempotency: "supported",
152
- inputSchema: Object.freeze({
153
- additionalProperties: false,
154
- properties: Object.freeze({
155
- reason: {
156
- type: "string",
157
- maxLength: 500
158
- },
159
- sessionId: {
160
- type: "string",
161
- minLength: 1,
162
- maxLength: 200
163
- }
164
- }),
165
- required: ["sessionId"],
166
- type: "object"
167
- }),
168
- pluginId: BACKGROUND_SESSION_TOOL_PLUGIN_ID,
169
- risk: "mutate",
170
- version: BACKGROUND_SESSION_TOOL_VERSION
171
- })
172
- ];
173
- }
174
- function narrowBackgroundSessionDefinition(definition, digest) {
175
- const childToolIds = definition.toolGrantSet.toolIds.filter((id) => id !== BACKGROUND_SESSION_START_TOOL_ID);
176
- const toolGrantSet = Object.freeze({
177
- revision: grantRevision(digest, definition.toolGrantSet.revision, childToolIds),
178
- toolIds: Object.freeze(childToolIds)
179
- });
180
- return Object.freeze({
181
- ...definition,
182
- tools: Object.freeze(definition.tools.filter(({ id }) => id !== BACKGROUND_SESSION_START_TOOL_ID)),
183
- toolGrantSet
184
- });
185
- }
186
- function grantRevision(digest, parentRevision, toolIds) {
187
- return digest(JSON.stringify({
188
- parentRevision,
189
- toolIds: [...toolIds].sort()
190
- }));
191
- }
192
- //#endregion
193
- export { narrowBackgroundSessionDefinition as n, createBackgroundSessionToolContracts as t };
194
-
@@ -1 +0,0 @@
1
- export { createRivusDaemonProcess } from "@rivus/gateway/bootstrap/pi-feishu";