@rivus/agent 0.14.2 → 0.14.4

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.
Files changed (37) hide show
  1. package/README.md +1 -1
  2. package/dist/acp.js +1 -2
  3. package/dist/bootstrap/pi-feishu.d.ts +1 -1
  4. package/dist/bootstrap/pi-feishu.js +4 -4
  5. package/dist/chunks/agent-loop.d.ts +55 -300
  6. package/dist/chunks/agent-loop.js +3 -1123
  7. package/dist/chunks/background-session-authority.js +230 -0
  8. package/dist/chunks/background-session-control-input.js +51 -0
  9. package/dist/chunks/background-session-service.d.ts +382 -0
  10. package/dist/chunks/index.d.ts +1201 -538
  11. package/dist/chunks/pi-tool-proxy.d.ts +22 -90
  12. package/dist/chunks/pi.js +5 -2
  13. package/dist/chunks/rivus-agent-definition-resolver.js +508 -0
  14. package/dist/chunks/rivus-daemon-cli.js +2776 -3244
  15. package/dist/chunks/rivus-plugin-testkit.d.ts +175 -2
  16. package/dist/chunks/rivus-plugin-testkit.js +11 -4
  17. package/dist/chunks/rivus-skill.d.ts +95 -0
  18. package/dist/chunks/sha256-digest.js +2 -7
  19. package/dist/chunks/src.js +11941 -7001
  20. package/dist/chunks/tool-input-digest.js +158 -0
  21. package/dist/cli.js +764 -712
  22. package/dist/index.d.ts +6 -7
  23. package/dist/index.js +7 -8
  24. package/dist/mcp.d.ts +48 -9
  25. package/dist/mcp.js +146 -20
  26. package/dist/pi.d.ts +3 -4
  27. package/dist/pi.js +1 -1
  28. package/package.json +5 -5
  29. package/dist/chunks/api.d.ts +0 -70
  30. package/dist/chunks/api.js +0 -471
  31. package/dist/chunks/api2.d.ts +0 -387
  32. package/dist/chunks/api2.js +0 -1331
  33. package/dist/chunks/api3.d.ts +0 -402
  34. package/dist/chunks/module.js +0 -267
  35. package/dist/chunks/pi-skill-tool.js +0 -460
  36. package/dist/chunks/spi.d.ts +0 -1
  37. package/dist/chunks/spi.js +0 -2
@@ -0,0 +1,230 @@
1
+ //#region src/core/application/background-session/authority/background-session-identity.ts
2
+ const BACKGROUND_SESSION_SESSION_KEY_PREFIX = "background";
3
+ function createBackgroundSessionKey(sessionId) {
4
+ return `${BACKGROUND_SESSION_SESSION_KEY_PREFIX}:${sessionId}`;
5
+ }
6
+ function createBackgroundSessionStepSourceMessageId(sessionId, stepCount) {
7
+ return `bg:${sessionId}:step:${stepCount}`;
8
+ }
9
+ //#endregion
10
+ //#region src/core/application/background-session/authority/background-session-authority.ts
11
+ const BACKGROUND_SESSION_TOOL_IDS = [
12
+ "background.start",
13
+ "background.wait",
14
+ "background.list",
15
+ "background.status",
16
+ "background.send",
17
+ "background.stop"
18
+ ];
19
+ const BACKGROUND_SESSION_START_TOOL_ID = "background.start";
20
+ const BACKGROUND_SESSION_TOOL_PLUGIN_ID = "rivus-core";
21
+ const BACKGROUND_SESSION_TOOL_VERSION = "1.0.0";
22
+ const BACKGROUND_SESSION_TOOL_DIGESTS = {
23
+ "background.list": "sha256:c935847595e406d55ca889875b38db66bb1d4d7a34d7b0fb2b85aecf9478c149",
24
+ "background.send": "sha256:b7ed492e45c794dc286f7f66aca8d046082d11dfdc8787eaf5604765b68a7735",
25
+ "background.start": "sha256:773690e47f6eef1f1b289216e94cf98e548382d6cffb7b2f034c3ed0635dfcbb",
26
+ "background.status": "sha256:6aaa328d6cd97d8755a63abbe97286f1061fd2f238f68b1e576ed9a1d2b7e6b1",
27
+ "background.stop": "sha256:aa0bfdf0c9394058bfcbd8662e7bedd59055f9ddad51c2a1bb61666bd67ebfcb",
28
+ "background.wait": "sha256:4a0dc80e933ad3c99b6d58421ac9ef733157e39e0ac9b6ad87ac6e65ceaedaab"
29
+ };
30
+ function createBackgroundSessionToolContracts() {
31
+ return [
32
+ Object.freeze({
33
+ 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.",
34
+ digest: BACKGROUND_SESSION_TOOL_DIGESTS["background.start"],
35
+ id: "background.start",
36
+ idempotency: "supported",
37
+ inputSchema: Object.freeze({
38
+ additionalProperties: false,
39
+ properties: Object.freeze({
40
+ displayName: {
41
+ type: "string",
42
+ maxLength: 200
43
+ },
44
+ prompt: {
45
+ type: "string",
46
+ minLength: 1,
47
+ maxLength: 2e4
48
+ }
49
+ }),
50
+ required: ["prompt"],
51
+ type: "object"
52
+ }),
53
+ pluginId: BACKGROUND_SESSION_TOOL_PLUGIN_ID,
54
+ risk: "mutate",
55
+ version: BACKGROUND_SESSION_TOOL_VERSION
56
+ }),
57
+ Object.freeze({
58
+ 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.",
59
+ digest: BACKGROUND_SESSION_TOOL_DIGESTS["background.wait"],
60
+ id: "background.wait",
61
+ idempotency: "supported",
62
+ inputSchema: Object.freeze({
63
+ additionalProperties: false,
64
+ properties: Object.freeze({
65
+ delayMs: {
66
+ type: "integer",
67
+ minimum: 1e3,
68
+ maximum: 864e5
69
+ },
70
+ reason: {
71
+ type: "string",
72
+ maxLength: 500
73
+ },
74
+ until: {
75
+ type: "string",
76
+ maxLength: 64
77
+ }
78
+ }),
79
+ type: "object"
80
+ }),
81
+ pluginId: BACKGROUND_SESSION_TOOL_PLUGIN_ID,
82
+ risk: "mutate",
83
+ version: BACKGROUND_SESSION_TOOL_VERSION
84
+ }),
85
+ Object.freeze({
86
+ description: "List background sessions owned by this conversation, newest first. Optionally filter by phase and limit the number of results.",
87
+ digest: BACKGROUND_SESSION_TOOL_DIGESTS["background.list"],
88
+ id: "background.list",
89
+ idempotency: "supported",
90
+ inputSchema: Object.freeze({
91
+ additionalProperties: false,
92
+ properties: Object.freeze({
93
+ limit: {
94
+ type: "integer",
95
+ minimum: 1,
96
+ maximum: 50
97
+ },
98
+ phase: {
99
+ enum: [
100
+ "queued",
101
+ "running",
102
+ "waiting",
103
+ "input-required",
104
+ "stopping",
105
+ "stopped",
106
+ "completed",
107
+ "failed",
108
+ "reconciliation-required"
109
+ ],
110
+ type: "string"
111
+ }
112
+ }),
113
+ type: "object"
114
+ }),
115
+ pluginId: BACKGROUND_SESSION_TOOL_PLUGIN_ID,
116
+ risk: "observe",
117
+ version: BACKGROUND_SESSION_TOOL_VERSION
118
+ }),
119
+ Object.freeze({
120
+ description: "Return the current phase, step counts, wake time, and result of one background session owned by this conversation.",
121
+ digest: BACKGROUND_SESSION_TOOL_DIGESTS["background.status"],
122
+ id: "background.status",
123
+ idempotency: "supported",
124
+ inputSchema: Object.freeze({
125
+ additionalProperties: false,
126
+ properties: Object.freeze({ sessionId: {
127
+ type: "string",
128
+ minLength: 1,
129
+ maxLength: 200
130
+ } }),
131
+ required: ["sessionId"],
132
+ type: "object"
133
+ }),
134
+ pluginId: BACKGROUND_SESSION_TOOL_PLUGIN_ID,
135
+ risk: "observe",
136
+ version: BACKGROUND_SESSION_TOOL_VERSION
137
+ }),
138
+ Object.freeze({
139
+ 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.",
140
+ digest: BACKGROUND_SESSION_TOOL_DIGESTS["background.send"],
141
+ id: "background.send",
142
+ idempotency: "supported",
143
+ inputSchema: Object.freeze({
144
+ additionalProperties: false,
145
+ properties: Object.freeze({
146
+ message: {
147
+ type: "string",
148
+ minLength: 1,
149
+ maxLength: 2e4
150
+ },
151
+ sessionId: {
152
+ type: "string",
153
+ minLength: 1,
154
+ maxLength: 200
155
+ }
156
+ }),
157
+ required: ["message", "sessionId"],
158
+ type: "object"
159
+ }),
160
+ pluginId: BACKGROUND_SESSION_TOOL_PLUGIN_ID,
161
+ risk: "mutate",
162
+ version: BACKGROUND_SESSION_TOOL_VERSION
163
+ }),
164
+ Object.freeze({
165
+ 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.",
166
+ digest: BACKGROUND_SESSION_TOOL_DIGESTS["background.stop"],
167
+ id: "background.stop",
168
+ idempotency: "supported",
169
+ inputSchema: Object.freeze({
170
+ additionalProperties: false,
171
+ properties: Object.freeze({
172
+ reason: {
173
+ type: "string",
174
+ maxLength: 500
175
+ },
176
+ sessionId: {
177
+ type: "string",
178
+ minLength: 1,
179
+ maxLength: 200
180
+ }
181
+ }),
182
+ required: ["sessionId"],
183
+ type: "object"
184
+ }),
185
+ pluginId: BACKGROUND_SESSION_TOOL_PLUGIN_ID,
186
+ risk: "mutate",
187
+ version: BACKGROUND_SESSION_TOOL_VERSION
188
+ })
189
+ ];
190
+ }
191
+ function backgroundSessionToolIds() {
192
+ return [...BACKGROUND_SESSION_TOOL_IDS];
193
+ }
194
+ function isBackgroundSessionToolId(toolId) {
195
+ return BACKGROUND_SESSION_TOOL_IDS.includes(toolId);
196
+ }
197
+ function extendBackgroundSessionDefinition(definition, digest) {
198
+ const contracts = createBackgroundSessionToolContracts();
199
+ const existingIds = new Set(definition.tools.map(({ id }) => id));
200
+ const additions = contracts.filter((contract) => !existingIds.has(contract.id));
201
+ const toolGrantSet = Object.freeze({
202
+ revision: grantRevision(digest, definition.toolGrantSet.revision, additions.map(({ id }) => id)),
203
+ toolIds: Object.freeze([...definition.toolGrantSet.toolIds, ...additions.map(({ id }) => id)].sort())
204
+ });
205
+ return Object.freeze({
206
+ ...definition,
207
+ tools: Object.freeze([...definition.tools, ...additions]),
208
+ toolGrantSet
209
+ });
210
+ }
211
+ function narrowBackgroundSessionDefinition(definition, digest) {
212
+ const childToolIds = definition.toolGrantSet.toolIds.filter((id) => id !== BACKGROUND_SESSION_START_TOOL_ID);
213
+ const toolGrantSet = Object.freeze({
214
+ revision: grantRevision(digest, definition.toolGrantSet.revision, childToolIds),
215
+ toolIds: Object.freeze(childToolIds)
216
+ });
217
+ return Object.freeze({
218
+ ...definition,
219
+ tools: Object.freeze(definition.tools.filter(({ id }) => id !== BACKGROUND_SESSION_START_TOOL_ID)),
220
+ toolGrantSet
221
+ });
222
+ }
223
+ function grantRevision(digest, parentRevision, toolIds) {
224
+ return digest(JSON.stringify({
225
+ parentRevision,
226
+ toolIds: [...toolIds].sort()
227
+ }));
228
+ }
229
+ //#endregion
230
+ export { backgroundSessionToolIds as a, isBackgroundSessionToolId as c, createBackgroundSessionKey as d, createBackgroundSessionStepSourceMessageId as f, BACKGROUND_SESSION_TOOL_VERSION as i, narrowBackgroundSessionDefinition as l, BACKGROUND_SESSION_TOOL_IDS as n, createBackgroundSessionToolContracts as o, BACKGROUND_SESSION_TOOL_PLUGIN_ID as r, extendBackgroundSessionDefinition as s, BACKGROUND_SESSION_START_TOOL_ID as t, BACKGROUND_SESSION_SESSION_KEY_PREFIX as u };
@@ -0,0 +1,51 @@
1
+ import { randomUUID } from "node:crypto";
2
+ //#region src/platform/identity/random-id.ts
3
+ function createRandomId() {
4
+ return randomUUID();
5
+ }
6
+ //#endregion
7
+ //#region src/core/application/background-session/control/background-session-control-input.ts
8
+ function readBackgroundSessionObject(input, allowed, error) {
9
+ if (input === null || typeof input !== "object" || Array.isArray(input)) throw error("background tool input must be an object");
10
+ const record = input;
11
+ const unknown = Object.keys(record).find((key) => !allowed.includes(key));
12
+ if (unknown) throw error(`field is not allowed: ${unknown}`);
13
+ return record;
14
+ }
15
+ function readBackgroundSessionString(value, name, error) {
16
+ if (typeof value !== "string" || value.trim() === "") throw error(`${name} must be a non-empty string`);
17
+ return value;
18
+ }
19
+ function readBackgroundSessionInteger(value, name, error) {
20
+ if (!Number.isSafeInteger(value) || value < 1) throw error(`${name} must be a positive integer`);
21
+ return value;
22
+ }
23
+ function readBackgroundSessionPhase(value, error) {
24
+ const phases = [
25
+ "queued",
26
+ "running",
27
+ "waiting",
28
+ "input-required",
29
+ "stopping",
30
+ "stopped",
31
+ "completed",
32
+ "failed",
33
+ "reconciliation-required"
34
+ ];
35
+ if (typeof value !== "string" || !phases.includes(value)) throw error(`phase must be one of ${phases.join(", ")}`);
36
+ return value;
37
+ }
38
+ function readBackgroundSessionWaitInput(input, error) {
39
+ const { delayMs, reason, until } = readBackgroundSessionObject(input, [
40
+ "delayMs",
41
+ "reason",
42
+ "until"
43
+ ], error);
44
+ const args = {};
45
+ if (delayMs !== void 0) args.delayMs = readBackgroundSessionInteger(delayMs, "delayMs", error);
46
+ if (reason !== void 0) args.reason = readBackgroundSessionString(reason, "reason", error);
47
+ if (until !== void 0) args.until = readBackgroundSessionString(until, "until", error);
48
+ return args;
49
+ }
50
+ //#endregion
51
+ export { readBackgroundSessionWaitInput as a, readBackgroundSessionString as i, readBackgroundSessionObject as n, createRandomId as o, readBackgroundSessionPhase as r, readBackgroundSessionInteger as t };
@@ -0,0 +1,382 @@
1
+ //#region src/core/domain/background-session/value-objects/background-session-id.d.ts
2
+ type BackgroundSessionId = string;
3
+ //#endregion
4
+ //#region src/core/domain/background-session/events/background-session-events.d.ts
5
+ type AggregateTransition<TState, TEvent> = Readonly<{
6
+ events: ReadonlyArray<TEvent>;
7
+ state: TState;
8
+ }>;
9
+ type BackgroundSessionCompleted = Readonly<{
10
+ displayName: string;
11
+ revision: number;
12
+ sessionId: BackgroundSessionId;
13
+ text: string;
14
+ type: "BackgroundSessionCompleted";
15
+ }>;
16
+ type BackgroundSessionFailed = Readonly<{
17
+ displayName: string;
18
+ errorMessage: string;
19
+ revision: number;
20
+ sessionId: BackgroundSessionId;
21
+ type: "BackgroundSessionFailed";
22
+ }>;
23
+ type BackgroundSessionStopped = Readonly<{
24
+ displayName: string;
25
+ reason?: string;
26
+ revision: number;
27
+ sessionId: BackgroundSessionId;
28
+ type: "BackgroundSessionStopped";
29
+ }>;
30
+ type BackgroundSessionReconciliationRequired = Readonly<{
31
+ displayName: string;
32
+ note: string;
33
+ revision: number;
34
+ sessionId: BackgroundSessionId;
35
+ type: "BackgroundSessionReconciliationRequired";
36
+ }>;
37
+ type BackgroundSessionEvent = BackgroundSessionCompleted | BackgroundSessionFailed | BackgroundSessionStopped | BackgroundSessionReconciliationRequired;
38
+ //#endregion
39
+ //#region src/core/domain/background-session/value-objects/memory.d.ts
40
+ declare const BACKGROUND_SESSION_MEMORY_SCOPES: readonly ["conversation", "agent-private", "project", "shared-user-profile"];
41
+ type BackgroundSessionMemoryScope = (typeof BACKGROUND_SESSION_MEMORY_SCOPES)[number];
42
+ declare const BACKGROUND_SESSION_MEMORY_AUDIENCES: readonly ["group", "private"];
43
+ type BackgroundSessionMemoryAudience = (typeof BACKGROUND_SESSION_MEMORY_AUDIENCES)[number];
44
+ interface BackgroundSessionMemoryIdentity {
45
+ readonly audience: BackgroundSessionMemoryAudience;
46
+ readonly conversationId?: string;
47
+ readonly projectId?: string;
48
+ readonly subjectId: string;
49
+ readonly tenantId: string;
50
+ }
51
+ //#endregion
52
+ //#region src/core/domain/background-session/value-objects/authority.d.ts
53
+ type BackgroundSessionAuthority = Readonly<{
54
+ agentId: string;
55
+ profileRevision: string;
56
+ toolGrantRevision: string;
57
+ policyEpoch: number;
58
+ memoryScopes: ReadonlyArray<BackgroundSessionMemoryScope>;
59
+ projectSpaceId?: string;
60
+ sessionKey: string;
61
+ }>;
62
+ //#endregion
63
+ //#region src/core/domain/background-session/value-objects/cancellation.d.ts
64
+ type BackgroundSessionCancellation = Readonly<{
65
+ reason: string;
66
+ requestedAt: string;
67
+ }>;
68
+ //#endregion
69
+ //#region src/core/domain/background-session/value-objects/lease.d.ts
70
+ type BackgroundSessionLease = Readonly<{
71
+ owner: string;
72
+ epoch: number;
73
+ expiresAt: string;
74
+ }>;
75
+ //#endregion
76
+ //#region src/core/domain/background-session/value-objects/origin.d.ts
77
+ type BackgroundSessionOrigin = Readonly<{
78
+ endpointId: string;
79
+ tenantKey: string;
80
+ conversationId?: string;
81
+ allowedActorOpenIds: ReadonlyArray<string>;
82
+ memory?: BackgroundSessionMemoryIdentity;
83
+ }>;
84
+ //#endregion
85
+ //#region src/core/domain/background-session/value-objects/phase.d.ts
86
+ type BackgroundSessionPhase = "queued" | "running" | "waiting" | "input-required" | "stopping" | "stopped" | "completed" | "failed" | "reconciliation-required";
87
+ //#endregion
88
+ //#region src/core/domain/background-session/value-objects/terminal-result.d.ts
89
+ type BackgroundSessionTerminalResult = Readonly<{
90
+ text: string;
91
+ stepRunId: string;
92
+ completedAt: string;
93
+ }>;
94
+ //#endregion
95
+ //#region src/core/domain/background-session/aggregate/snapshot.d.ts
96
+ type BackgroundSessionSnapshot = Readonly<{
97
+ sessionId: BackgroundSessionId;
98
+ displayName: string;
99
+ phase: BackgroundSessionPhase;
100
+ revision: number;
101
+ parentRunId: string;
102
+ sourceMessageId: string;
103
+ origin: BackgroundSessionOrigin;
104
+ authority: BackgroundSessionAuthority;
105
+ prompt: string;
106
+ stepCount: number;
107
+ wakeCount: number;
108
+ currentStepRunId?: string;
109
+ lastWakeText?: string;
110
+ pendingInput: ReadonlyArray<string>;
111
+ wakeAt?: string;
112
+ lease?: BackgroundSessionLease;
113
+ cancellation?: BackgroundSessionCancellation;
114
+ consecutiveFailures: number;
115
+ result?: BackgroundSessionTerminalResult;
116
+ errorMessage?: string;
117
+ reconciliationNote?: string;
118
+ createdAt: string;
119
+ updatedAt: string;
120
+ }>;
121
+ //#endregion
122
+ //#region src/core/domain/background-session/aggregate/background-session.d.ts
123
+ type BackgroundSessionTransition = AggregateTransition<BackgroundSession, BackgroundSessionEvent>;
124
+ interface CreateBackgroundSessionInput {
125
+ readonly sessionId: BackgroundSessionId;
126
+ readonly displayName: string;
127
+ readonly prompt: string;
128
+ readonly parentRunId: string;
129
+ readonly sourceMessageId: string;
130
+ readonly origin: BackgroundSessionOrigin;
131
+ readonly authority: BackgroundSessionAuthority;
132
+ readonly now: string;
133
+ }
134
+ interface ClaimBackgroundSessionInput {
135
+ readonly lease: BackgroundSessionLease;
136
+ readonly stepRunId: string;
137
+ readonly wakeText: string;
138
+ readonly now: string;
139
+ }
140
+ interface SuspendBackgroundSessionInput {
141
+ readonly wakeAt?: string;
142
+ readonly reason?: string;
143
+ readonly now: string;
144
+ }
145
+ declare class BackgroundSession implements BackgroundSessionSnapshot {
146
+ readonly sessionId: BackgroundSessionId;
147
+ readonly displayName: string;
148
+ readonly phase: BackgroundSessionPhase;
149
+ readonly revision: number;
150
+ readonly parentRunId: string;
151
+ readonly sourceMessageId: string;
152
+ readonly origin: BackgroundSessionOrigin;
153
+ readonly authority: BackgroundSessionAuthority;
154
+ readonly prompt: string;
155
+ readonly stepCount: number;
156
+ readonly wakeCount: number;
157
+ readonly currentStepRunId?: string;
158
+ readonly lastWakeText?: string;
159
+ readonly pendingInput: ReadonlyArray<string>;
160
+ readonly wakeAt?: string;
161
+ readonly lease?: BackgroundSessionLease;
162
+ readonly cancellation?: BackgroundSessionCancellation;
163
+ readonly consecutiveFailures: number;
164
+ readonly result?: BackgroundSessionTerminalResult;
165
+ readonly errorMessage?: string;
166
+ readonly reconciliationNote?: string;
167
+ readonly createdAt: string;
168
+ readonly updatedAt: string;
169
+ private constructor();
170
+ static create(input: CreateBackgroundSessionInput): BackgroundSession;
171
+ static restore(snapshot: unknown): BackgroundSession;
172
+ claim(input: ClaimBackgroundSessionInput): BackgroundSessionTransition;
173
+ renewLease(lease: BackgroundSessionLease): BackgroundSessionTransition;
174
+ releaseLease(): BackgroundSessionTransition;
175
+ suspend(input: SuspendBackgroundSessionInput): BackgroundSessionTransition;
176
+ completeStep(input: {
177
+ readonly text: string;
178
+ readonly stepRunId: string;
179
+ readonly now: string;
180
+ }): BackgroundSessionTransition;
181
+ failStep(input: {
182
+ readonly errorMessage: string;
183
+ readonly now: string;
184
+ readonly retryable: boolean;
185
+ readonly wakeAt?: string;
186
+ }): BackgroundSessionTransition;
187
+ requestStop(input: {
188
+ readonly reason: string;
189
+ readonly now: string;
190
+ }): BackgroundSessionTransition;
191
+ completeStop(input: {
192
+ readonly now: string;
193
+ }): BackgroundSessionTransition;
194
+ parkForReconciliation(input: {
195
+ readonly reason: string;
196
+ readonly now: string;
197
+ }): BackgroundSessionTransition;
198
+ resolveReconciliation(input: {
199
+ readonly outcome: "continue" | "stop";
200
+ readonly now: string;
201
+ }): BackgroundSessionTransition;
202
+ appendInput(input: {
203
+ readonly message: string;
204
+ readonly now: string;
205
+ }): BackgroundSessionTransition;
206
+ requeueInterruptedStep(input: {
207
+ readonly wakeText: string;
208
+ readonly now: string;
209
+ }): BackgroundSessionTransition;
210
+ isLeaseExpired(now: string): boolean;
211
+ isDue(now: string): boolean;
212
+ isTerminal(): boolean;
213
+ toSnapshot(): BackgroundSessionSnapshot;
214
+ validateTransitionTo(next: BackgroundSession): string | undefined;
215
+ private snapshotFields;
216
+ private next;
217
+ private unchanged;
218
+ private stopped;
219
+ }
220
+ //#endregion
221
+ //#region src/core/application/background-session/ports/background-session-delivery-store.d.ts
222
+ type BackgroundSessionDeliveryKind = "progress" | "final" | "stopped" | "failed" | "reconciliation";
223
+ interface BackgroundSessionDeliveryRecord {
224
+ readonly deliveryId: string;
225
+ readonly sessionId: string;
226
+ readonly kind: BackgroundSessionDeliveryKind;
227
+ readonly text: string;
228
+ readonly state: "pending" | "delivered";
229
+ readonly revision: number;
230
+ readonly providerMessageId?: string;
231
+ readonly createdAt: string;
232
+ }
233
+ interface BackgroundSessionDeliveryStore {
234
+ enqueue(input: {
235
+ readonly deliveryId: string;
236
+ readonly sessionId: string;
237
+ readonly kind: BackgroundSessionDeliveryKind;
238
+ readonly text: string;
239
+ readonly createdAt: string;
240
+ }): Promise<BackgroundSessionDeliveryRecord>;
241
+ pending(): Promise<ReadonlyArray<BackgroundSessionDeliveryRecord>>;
242
+ markDelivered(deliveryId: string, providerMessageId: string): Promise<BackgroundSessionDeliveryRecord | undefined>;
243
+ }
244
+ declare class BackgroundSessionDeliveryConflict extends Error {
245
+ readonly name = "BackgroundSessionDeliveryConflict";
246
+ constructor(deliveryId: string, message: string);
247
+ }
248
+ //#endregion
249
+ //#region src/core/application/background-session/ports/background-session-repository.d.ts
250
+ interface BackgroundSessionLeasePrecondition {
251
+ readonly kind: "absent";
252
+ }
253
+ interface BackgroundSessionLeaseRequirement {
254
+ readonly kind: "held";
255
+ readonly owner: string;
256
+ readonly epoch: number;
257
+ }
258
+ interface BackgroundSessionLeaseStaleOrAbsent {
259
+ readonly kind: "absent-or-stale";
260
+ }
261
+ interface BackgroundSessionRepository {
262
+ create(session: BackgroundSession): Promise<BackgroundSession>;
263
+ get(sessionId: string): Promise<BackgroundSession | undefined>;
264
+ list(options?: {
265
+ readonly phase?: BackgroundSessionPhase;
266
+ readonly limit?: number;
267
+ }): Promise<ReadonlyArray<BackgroundSession>>;
268
+ update(input: {
269
+ readonly sessionId: string;
270
+ readonly expectedRevision: number;
271
+ readonly expectedLease?: BackgroundSessionLeasePrecondition | BackgroundSessionLeaseRequirement | BackgroundSessionLeaseStaleOrAbsent;
272
+ readonly now?: string;
273
+ readonly build: (session: BackgroundSession) => BackgroundSession;
274
+ }): Promise<BackgroundSession | undefined>;
275
+ }
276
+ declare class BackgroundSessionRepositoryConflict extends Error {
277
+ readonly name = "BackgroundSessionRepositoryConflict";
278
+ constructor(sessionId: string, message: string);
279
+ }
280
+ declare class BackgroundSessionRepositoryCorrupted extends Error {
281
+ readonly name = "BackgroundSessionRepositoryCorrupted";
282
+ }
283
+ //#endregion
284
+ //#region src/core/application/background-session/authority/background-session-identity.d.ts
285
+ declare const BACKGROUND_SESSION_SESSION_KEY_PREFIX = "background";
286
+ declare function createBackgroundSessionKey(sessionId: string): string;
287
+ declare function createBackgroundSessionStepSourceMessageId(sessionId: string, stepCount: number): string;
288
+ //#endregion
289
+ //#region src/core/application/background-session/commands/background-session-ids.d.ts
290
+ declare function sessionIdFromSessionKey(sessionKey: string): string | undefined;
291
+ declare function terminalDeliveryId(sessionId: string, kind: BackgroundSessionDeliveryKind): string;
292
+ declare function progressDeliveryId(sessionId: string, stepCount: number): string;
293
+ //#endregion
294
+ //#region src/core/application/background-session/commands/background-session-service.d.ts
295
+ interface BackgroundSessionExecutionOrigin {
296
+ readonly allowedActorOpenIds: ReadonlyArray<string>;
297
+ readonly conversationId?: string;
298
+ readonly endpointId: string;
299
+ readonly tenantKey: string;
300
+ }
301
+ interface BackgroundSessionExecutionContext {
302
+ readonly agentId: string;
303
+ readonly callId: string;
304
+ readonly instanceId: string;
305
+ readonly memory?: BackgroundSessionMemoryIdentity & {
306
+ readonly scopes: ReadonlyArray<BackgroundSessionMemoryScope>;
307
+ };
308
+ readonly operationId?: string;
309
+ readonly origin?: BackgroundSessionExecutionOrigin;
310
+ readonly policyEpoch: number;
311
+ readonly runId: string;
312
+ readonly sessionKey: string;
313
+ readonly sourceMessageId?: string;
314
+ readonly toolId: string;
315
+ readonly toolVersion: string;
316
+ }
317
+ interface BackgroundSessionSummary {
318
+ readonly sessionId: string;
319
+ readonly displayName: string;
320
+ readonly phase: BackgroundSessionPhase;
321
+ readonly stepCount: number;
322
+ readonly wakeAt?: string;
323
+ readonly createdAt: string;
324
+ readonly updatedAt: string;
325
+ }
326
+ interface BackgroundSessionDetailResult {
327
+ readonly completedAt: string;
328
+ readonly stepRunId: string;
329
+ readonly text: string;
330
+ }
331
+ interface BackgroundSessionDetail extends BackgroundSessionSummary {
332
+ readonly parentRunId: string;
333
+ readonly pendingInput: ReadonlyArray<string>;
334
+ readonly result?: BackgroundSessionDetailResult;
335
+ readonly errorMessage?: string;
336
+ readonly cancellationReason?: string;
337
+ readonly reconciliationNote?: string;
338
+ }
339
+ declare class BackgroundSessionCallerDenied extends Error {
340
+ readonly name = "BackgroundSessionCallerDenied";
341
+ constructor(message: string);
342
+ }
343
+ interface BackgroundSessionService {
344
+ list(input: {
345
+ readonly context: BackgroundSessionExecutionContext;
346
+ readonly limit?: number;
347
+ readonly phase?: BackgroundSessionPhase;
348
+ }): Promise<ReadonlyArray<BackgroundSessionSummary>>;
349
+ resolveReconciliation(input: {
350
+ readonly outcome: "continue" | "stop";
351
+ readonly sessionId: string;
352
+ }): Promise<BackgroundSessionSummary>;
353
+ send(input: {
354
+ readonly context: BackgroundSessionExecutionContext;
355
+ readonly message: string;
356
+ readonly sessionId: string;
357
+ }): Promise<BackgroundSessionSummary>;
358
+ start(input: {
359
+ readonly authority: BackgroundSessionAuthority;
360
+ readonly context: BackgroundSessionExecutionContext;
361
+ readonly displayName?: string;
362
+ readonly prompt: string;
363
+ readonly sessionId: string;
364
+ }): Promise<BackgroundSessionSummary>;
365
+ status(input: {
366
+ readonly context: BackgroundSessionExecutionContext;
367
+ readonly sessionId: string;
368
+ }): Promise<BackgroundSessionDetail>;
369
+ stop(input: {
370
+ readonly context: BackgroundSessionExecutionContext;
371
+ readonly reason?: string;
372
+ readonly sessionId: string;
373
+ }): Promise<BackgroundSessionSummary>;
374
+ wait(input: {
375
+ readonly context: BackgroundSessionExecutionContext;
376
+ readonly delayMs?: number;
377
+ readonly reason?: string;
378
+ readonly until?: string;
379
+ }): Promise<BackgroundSessionSummary>;
380
+ }
381
+ //#endregion
382
+ export { BackgroundSessionAuthority as A, SuspendBackgroundSessionInput as C, BackgroundSessionOrigin as D, BackgroundSessionPhase as E, BackgroundSessionId as M, BackgroundSessionLease as O, CreateBackgroundSessionInput as S, BackgroundSessionTerminalResult as T, BackgroundSessionDeliveryConflict as _, progressDeliveryId as a, BackgroundSession as b, BACKGROUND_SESSION_SESSION_KEY_PREFIX as c, BackgroundSessionLeasePrecondition as d, BackgroundSessionLeaseRequirement as f, BackgroundSessionRepositoryCorrupted as g, BackgroundSessionRepositoryConflict as h, BackgroundSessionSummary as i, BackgroundSessionMemoryScope as j, BackgroundSessionCancellation as k, createBackgroundSessionKey as l, BackgroundSessionRepository as m, BackgroundSessionDetail as n, sessionIdFromSessionKey as o, BackgroundSessionLeaseStaleOrAbsent as p, BackgroundSessionService as r, terminalDeliveryId as s, BackgroundSessionCallerDenied as t, createBackgroundSessionStepSourceMessageId as u, BackgroundSessionDeliveryRecord as v, BackgroundSessionSnapshot as w, ClaimBackgroundSessionInput as x, BackgroundSessionDeliveryStore as y };