@stratusagent/gateway 0.13.7 → 0.14.1
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/dist/event-intake.d.ts +159 -0
- package/dist/event-intake.d.ts.map +1 -0
- package/dist/event-intake.js +445 -0
- package/dist/event-intake.js.map +1 -0
- package/dist/events.d.ts +256 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +462 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +108 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +451 -24
- package/dist/index.js.map +1 -1
- package/dist/schedules.d.ts +84 -1
- package/dist/schedules.d.ts.map +1 -1
- package/dist/schedules.js +550 -49
- package/dist/schedules.js.map +1 -1
- package/dist/sessions.d.ts +15 -7
- package/dist/sessions.d.ts.map +1 -1
- package/dist/sessions.js +89 -19
- package/dist/sessions.js.map +1 -1
- package/package.json +7 -7
package/dist/schedules.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
2
|
+
import { type JsonObject, type Session, type SessionStatus, type SessionStoppedEarly, type TrustLevel } from '@stratusagent/core';
|
|
2
3
|
import { type ScheduleDestination, type ScheduleRecord, type SchedulerHandle } from '@stratusagent/agents';
|
|
4
|
+
import type { EventTrigger } from './event-intake.ts';
|
|
5
|
+
import type { SqliteEventStore } from './events.ts';
|
|
3
6
|
/**
|
|
4
7
|
* Durable schedules, in the same database sessions live in — a schedule
|
|
5
8
|
* survives a restart the way a parked approval does, and an operator has
|
|
@@ -27,6 +30,15 @@ export interface SqliteScheduleStoreOptions {
|
|
|
27
30
|
*/
|
|
28
31
|
stateHome?: string;
|
|
29
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Open `fleet.db` the way every store sharing it must: the derived-path
|
|
35
|
+
* check, an owner-only directory and file, WAL with a busy timeout, then
|
|
36
|
+
* `schema`, then the sidecars tightened. One implementation, because the
|
|
37
|
+
* schedule store and the event store (card 590) each hold their own
|
|
38
|
+
* connection to this file, and a second copy of this sequence is the one
|
|
39
|
+
* that drifts.
|
|
40
|
+
*/
|
|
41
|
+
export declare const openFleetDatabase: (filePath: string, options: SqliteScheduleStoreOptions, schema: string) => DatabaseSync;
|
|
30
42
|
export declare class SqliteScheduleStore {
|
|
31
43
|
private readonly db;
|
|
32
44
|
constructor(filePath: string, options?: SqliteScheduleStoreOptions);
|
|
@@ -66,6 +78,33 @@ export declare class SqliteScheduleStore {
|
|
|
66
78
|
export declare const SCHEDULE_SESSION_ID_PREFIX = "schedule:";
|
|
67
79
|
/** Whether a session id belongs to the reserved scheduled-firing namespace. */
|
|
68
80
|
export declare const isScheduleSessionId: (sessionId: string) => boolean;
|
|
81
|
+
/** The longest prefix of `text` that fits in `bytes` of UTF-8, never splitting a character. */
|
|
82
|
+
export declare const utf8Prefix: (text: string, bytes: number) => string;
|
|
83
|
+
/**
|
|
84
|
+
* What the next firing of a schedule reads from the one before it (card
|
|
85
|
+
* 858), from the gateway's session store: the status, the stopped-early
|
|
86
|
+
* marker, the latest reply and the label that reply carries. Never the
|
|
87
|
+
* transcript.
|
|
88
|
+
*/
|
|
89
|
+
export interface PreviousRun {
|
|
90
|
+
status: SessionStatus;
|
|
91
|
+
stoppedEarly?: SessionStoppedEarly;
|
|
92
|
+
/** The latest turn's text (`latestTurnReply`): for a stopped run, its wrap-up. */
|
|
93
|
+
reply?: string;
|
|
94
|
+
/** The label the run's own words carry (`sessionWriteTrust`). */
|
|
95
|
+
trust: TrustLevel;
|
|
96
|
+
}
|
|
97
|
+
/** A resumed firing carries at most this much of the stopped run's summary. */
|
|
98
|
+
export declare const RESUME_SUMMARY_MAX_BYTES = 4096;
|
|
99
|
+
/**
|
|
100
|
+
* What a firing that resumes sees after its schedule's prompt: when the
|
|
101
|
+
* stopped run ended and why, its own summary of what was done and left
|
|
102
|
+
* (capped), and, from the second stop in a row, that it's a repeat. The
|
|
103
|
+
* runtime posts nothing about a repeat: only the agent knows whether a
|
|
104
|
+
* person is waiting, so it's told it may post one line to the destination
|
|
105
|
+
* its schedule was approved with, when there is one.
|
|
106
|
+
*/
|
|
107
|
+
export declare const renderResumeBlock: (stoppedEarly: SessionStoppedEarly, reply: string | undefined, streak: number, reportsSomewhere: boolean) => string;
|
|
69
108
|
export interface SchedulerLimits {
|
|
70
109
|
/**
|
|
71
110
|
* The floor under a recurring cadence, milliseconds. Applied to intervals
|
|
@@ -109,7 +148,17 @@ export interface SchedulerRuntimeOptions {
|
|
|
109
148
|
agentId: string;
|
|
110
149
|
userMessage: string;
|
|
111
150
|
metadata: JsonObject;
|
|
151
|
+
/** An event firing's batch key: a repeat continues its turn rather than starting a second. */
|
|
152
|
+
idempotencyKey?: string;
|
|
112
153
|
}): Promise<unknown>;
|
|
154
|
+
/**
|
|
155
|
+
* Event triggers (card 590): the store their firings wait in, and the
|
|
156
|
+
* sources the operator configured. Without it, an `event` cadence is
|
|
157
|
+
* refused at creation: a trigger nothing can deliver to never fires.
|
|
158
|
+
*/
|
|
159
|
+
events?: SchedulerEventOptions;
|
|
160
|
+
/** The clock, for tests. Default `new Date()`. */
|
|
161
|
+
now?(): Date;
|
|
113
162
|
/**
|
|
114
163
|
* Prove a destination can be served, rejecting with a message fit for
|
|
115
164
|
* the person who named it. Called at creation — the whole point is
|
|
@@ -118,6 +167,14 @@ export interface SchedulerRuntimeOptions {
|
|
|
118
167
|
validateDestination(agentId: string, destination: ScheduleDestination): Promise<void>;
|
|
119
168
|
/** Status of a firing's session, for the spent-one-shot sweep. */
|
|
120
169
|
sessionStatus(sessionId: string): Promise<string | undefined>;
|
|
170
|
+
/**
|
|
171
|
+
* The session a schedule's previous firing ran in, or undefined when it
|
|
172
|
+
* doesn't exist (card 858). Read when the next firing of an `every` or
|
|
173
|
+
* `cron` schedule is claimed: a run that stopped early is that firing's
|
|
174
|
+
* checkpoint, and a run still going holds the slot back. Without it,
|
|
175
|
+
* every firing starts from its prompt alone, as before.
|
|
176
|
+
*/
|
|
177
|
+
previousRun?(sessionId: string): Promise<PreviousRun | undefined>;
|
|
121
178
|
/** The roster check: a schedule for an agent that does not exist is a refusal. */
|
|
122
179
|
hasAgent(agentId: string): boolean;
|
|
123
180
|
limits?: SchedulerLimits;
|
|
@@ -146,9 +203,35 @@ export interface SchedulerRuntimeOptions {
|
|
|
146
203
|
log(line: string): void;
|
|
147
204
|
warn(line: string): void;
|
|
148
205
|
}
|
|
206
|
+
export interface SchedulerEventOptions {
|
|
207
|
+
store: Pick<SqliteEventStore, 'open' | 'claim' | 'hold' | 'finish' | 'retire' | 'turnsStartedSince' | 'prune'>;
|
|
208
|
+
/** The configured source ids, read at each creation. */
|
|
209
|
+
sources(): readonly string[];
|
|
210
|
+
/**
|
|
211
|
+
* Event firings per agent at once, apart from timed schedules' cap: a
|
|
212
|
+
* Codex review must not wait behind a long work-loop firing, which is the
|
|
213
|
+
* polling this replaces. A firing over it waits, it is not dropped.
|
|
214
|
+
* Default 1.
|
|
215
|
+
*/
|
|
216
|
+
maxConcurrentPerAgent?: number;
|
|
217
|
+
}
|
|
149
218
|
export interface SchedulerRuntime {
|
|
150
219
|
/** The handle the `schedule.*` tools close over. */
|
|
151
220
|
handle: SchedulerHandle;
|
|
221
|
+
/** The event triggers on a source, for the intake's rule filter. */
|
|
222
|
+
eventTriggers(sourceId: string): EventTrigger[];
|
|
223
|
+
/**
|
|
224
|
+
* Run the hold-or-fire step for waiting event firings now, rather than at
|
|
225
|
+
* the next tick: the intake calls it after a delivery matched.
|
|
226
|
+
*/
|
|
227
|
+
kickEvents(): void;
|
|
228
|
+
/**
|
|
229
|
+
* Take event triggers on a host that had no source when it built this
|
|
230
|
+
* runtime: a plugin's source is known only once plugins load, after the
|
|
231
|
+
* gateway built its scheduler. Once, and with the same options
|
|
232
|
+
* `SchedulerRuntimeOptions.events` would have carried.
|
|
233
|
+
*/
|
|
234
|
+
attachEvents(events: SchedulerEventOptions): void;
|
|
152
235
|
/**
|
|
153
236
|
* The destination carve-out, shaped for the permission policy's
|
|
154
237
|
* `destinations` option: true exactly when this session is a firing of a
|
package/dist/schedules.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedules.d.ts","sourceRoot":"","sources":["../src/schedules.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schedules.d.ts","sourceRoot":"","sources":["../src/schedules.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,UAAU,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAQL,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,eAAe,EACrB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAkB,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpE;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAC5B,UAAU,MAAM,EAChB,SAAS,0BAA0B,EACnC,QAAQ,MAAM,KACb,YA4BF,CAAC;AAEF,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAe;gBAEtB,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B;IAYtE,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI;IAMpC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAO3C,gEAAgE;IAChE,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,cAAc,EAAE;IAOxC,6EAA6E;IAC7E,G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