@agentchatme/agent-core 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -37
- package/dist/{chunk-I4U4A7HO.js → chunk-KUZZ3MW2.js} +796 -161
- package/dist/chunk-KUZZ3MW2.js.map +1 -0
- package/dist/daemon-entry.d.ts +183 -139
- package/dist/daemon-entry.js +548 -442
- package/dist/daemon-entry.js.map +1 -1
- package/dist/index.d.ts +47 -221
- package/dist/index.js +215 -200
- package/dist/index.js.map +1 -1
- package/dist/prompts-BUfpwUT7.d.ts +630 -0
- package/package.json +3 -3
- package/dist/chunk-I4U4A7HO.js.map +0 -1
- package/dist/status-D8qOP4kM.d.ts +0 -260
package/dist/daemon-entry.d.ts
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
import { R as RunRunner,
|
|
2
|
-
export {
|
|
1
|
+
import { R as RunRunner, I as IntegrationClient, a as RunProfile, S as SocketState, M as ManualFetch, T as TextsStore, b as IntegrationStatus, c as RunPrompts, d as TimerHandle, e as IntegrationLastRun, f as RunOutcome } from './prompts-BUfpwUT7.js';
|
|
2
|
+
export { D as DEFAULT_WAKE_DEBOUNCE_MS, g as RunKind, h as RunOutcomeState, i as RunPreflight, j as RunRequest, W as WakeCoalescer, k as WakeCoalescerOptions } from './prompts-BUfpwUT7.js';
|
|
3
|
+
import { BlockedInfo, RealtimeState, AgentChatClient } from 'agentchatme';
|
|
3
4
|
import { EventEmitter } from 'node:events';
|
|
4
5
|
import 'zod';
|
|
5
6
|
|
|
6
|
-
interface
|
|
7
|
+
interface RunIntegrationOpts {
|
|
7
8
|
/** THE identity home for the agent this daemon serves. */
|
|
8
9
|
home: string;
|
|
9
10
|
/** How to start one headless run of this integration's coding agent. */
|
|
10
11
|
runner: RunRunner;
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
|
|
12
|
+
/** How this integration names itself to the server: the texts runtime and its own version. */
|
|
13
|
+
client: IntegrationClient;
|
|
14
|
+
/** The one pointer line a run prompt ends with: how THIS runtime reaches its copy of the manual (`manualPointer(...)`). */
|
|
15
|
+
manualPointer: string;
|
|
16
|
+
/**
|
|
17
|
+
* The skill file that follows the served manual (`<skills dir>/agentchat/SKILL.md`):
|
|
18
|
+
* whenever the texts in hand announce a version the file does not carry, the
|
|
19
|
+
* announced manual is downloaded, checked and written over it. Absent, the
|
|
20
|
+
* daemon leaves the manual to the CLI's install and `doctor --fix`.
|
|
21
|
+
*/
|
|
22
|
+
manualPath?: string;
|
|
23
|
+
/** Scratch dir for runs. The integration decides where; this package never derives one. */
|
|
24
|
+
workdir: string;
|
|
15
25
|
/** Defaults to `AGENTCHAT_RUN_PROFILE`, then `answer`. */
|
|
16
26
|
profile?: RunProfile;
|
|
17
27
|
/** Defaults to `AGENTCHAT_RUN_BUDGET_MS`, then 10 minutes. */
|
|
@@ -23,145 +33,165 @@ interface RunDoorbellOpts {
|
|
|
23
33
|
exit?: (code: number) => void;
|
|
24
34
|
}
|
|
25
35
|
/**
|
|
26
|
-
* Run the
|
|
36
|
+
* Run the integration daemon. Returns only on a condition that makes running
|
|
27
37
|
* pointless — another daemon already holding this home's lock — or when
|
|
28
38
|
* `signal` aborts (tests).
|
|
29
39
|
*/
|
|
30
|
-
declare function
|
|
40
|
+
declare function runIntegration(opts: RunIntegrationOpts): Promise<number>;
|
|
31
41
|
|
|
32
42
|
interface DaemonConfig {
|
|
33
43
|
apiKey: string;
|
|
34
44
|
handle: string;
|
|
35
45
|
apiBase: string;
|
|
36
|
-
|
|
46
|
+
/** `wss://api.agentchat.me` — the SDK's socket base; it appends `/v1/ws`. */
|
|
47
|
+
wsBase: string;
|
|
37
48
|
/** The identity home. Credentials, leader lock, and heartbeat all live here. */
|
|
38
49
|
home: string;
|
|
39
|
-
/** Scratch dir for the
|
|
50
|
+
/** Scratch dir for runs (the headless run's cwd). */
|
|
40
51
|
workdir: string;
|
|
41
52
|
}
|
|
42
|
-
/** `https://api.agentchat.me` → `wss://api.agentchat.me
|
|
53
|
+
/** `https://api.agentchat.me` → `wss://api.agentchat.me`. */
|
|
54
|
+
declare function wsBaseFor(apiBase: string): string;
|
|
55
|
+
/** `https://api.agentchat.me` → `wss://api.agentchat.me/v1/ws`, for logs and checks. */
|
|
43
56
|
declare function wsUrlFor(apiBase: string): string;
|
|
44
57
|
interface ResolveDaemonOpts {
|
|
45
58
|
/** THE identity home. Required — this module never derives one. */
|
|
46
59
|
home: string;
|
|
47
|
-
workdir
|
|
60
|
+
/** The run workdir. Required — this module never derives one either. */
|
|
61
|
+
workdir: string;
|
|
62
|
+
/** How to identify to the server when the handle has to be asked for. */
|
|
63
|
+
client: IntegrationClient;
|
|
48
64
|
}
|
|
49
65
|
/**
|
|
50
66
|
* Resolve the identity the daemon runs as.
|
|
51
67
|
*
|
|
52
68
|
* Async because the handle is load-bearing at runtime — it filters this agent's
|
|
53
|
-
* own outbound echoed back by server fan-out
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* blind and replying to ourselves.
|
|
69
|
+
* own outbound echoed back by server fan-out. An env-only identity
|
|
70
|
+
* (`AGENTCHAT_API_KEY`, no credentials file) has no handle on disk, so we ask
|
|
71
|
+
* the server rather than starting up blind and waking on ourselves.
|
|
57
72
|
*/
|
|
58
73
|
declare function resolveDaemonConfig(opts: ResolveDaemonOpts): Promise<DaemonConfig>;
|
|
59
74
|
|
|
60
|
-
interface
|
|
75
|
+
interface MessageWake {
|
|
61
76
|
readonly source: 'message';
|
|
62
77
|
readonly sender: string | null;
|
|
63
78
|
readonly conversationId: string | null;
|
|
64
79
|
readonly messageId: string | null;
|
|
65
80
|
}
|
|
66
|
-
|
|
67
|
-
interface
|
|
81
|
+
/** A `wake` frame: a deferred conversation's reminder came due. */
|
|
82
|
+
interface ReminderWake {
|
|
83
|
+
readonly source: 'reminder';
|
|
84
|
+
readonly conversationId: string;
|
|
85
|
+
readonly anchorMessageId: string;
|
|
86
|
+
readonly step: number;
|
|
87
|
+
}
|
|
88
|
+
type Wake = MessageWake | ReminderWake;
|
|
89
|
+
interface InviteWake {
|
|
68
90
|
readonly inviteId: string;
|
|
69
91
|
readonly groupId: string | null;
|
|
70
92
|
readonly groupName: string | null;
|
|
71
93
|
readonly inviterHandle: string | null;
|
|
72
94
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
*/
|
|
78
|
-
type TerminalReason = 'auth' | 'cap';
|
|
79
|
-
interface DoorbellSocketEvents {
|
|
80
|
-
knock: (knock: Knock) => void;
|
|
81
|
-
invite: (invite: InviteKnock) => void;
|
|
82
|
-
/** This agent's own outbound, echoed back by server fan-out. Not a knock. */
|
|
95
|
+
interface IntegrationConnectionEvents {
|
|
96
|
+
wake: (wake: Wake) => void;
|
|
97
|
+
invite: (invite: InviteWake) => void;
|
|
98
|
+
/** This agent's own outbound, echoed back by server fan-out. Not a wake. */
|
|
83
99
|
echo: () => void;
|
|
84
100
|
state: (state: SocketState, previous: SocketState) => void;
|
|
101
|
+
/** `hello.ok` arrived: the connection is live. Once per (re)connection, after `state` → `ready`. */
|
|
102
|
+
ready: () => void;
|
|
85
103
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
104
|
+
* The server refused the credential on the hello (the SDK is `blocked`,
|
|
105
|
+
* and so is `state`). Once per rejected attempt — the first one in a
|
|
106
|
+
* run and every 10–15 minutes after it, until a hello is accepted and
|
|
107
|
+
* `state` → `ready` lifts it. `detail` is the line `status` shows as the
|
|
108
|
+
* last error.
|
|
89
109
|
*/
|
|
90
|
-
|
|
91
|
-
/** The server answered the capability negotiation. */
|
|
92
|
-
ack: (negotiated: boolean) => void;
|
|
93
|
-
/** The socket gave up and stays stopped. The holder decides what happens next. */
|
|
94
|
-
terminal: (reason: TerminalReason, detail: string) => void;
|
|
110
|
+
blocked: (detail: string, info: BlockedInfo) => void;
|
|
95
111
|
}
|
|
96
|
-
interface
|
|
97
|
-
readonly url: string;
|
|
112
|
+
interface IntegrationConnectionOptions {
|
|
98
113
|
readonly apiKey: string;
|
|
114
|
+
/** `wss://api.agentchat.me` — the SDK appends `/v1/ws`. */
|
|
115
|
+
readonly wsBase: string;
|
|
99
116
|
/** This agent's handle, to recognise its own echo. Bare, any case. */
|
|
100
117
|
readonly selfHandle: string;
|
|
118
|
+
readonly client: IntegrationClient;
|
|
119
|
+
/** Test seams for the SDK's backoff; its defaults (500 ms → 30 s) otherwise. */
|
|
120
|
+
readonly reconnectIntervalMs?: number;
|
|
121
|
+
readonly maxReconnectIntervalMs?: number;
|
|
101
122
|
}
|
|
102
|
-
|
|
123
|
+
/**
|
|
124
|
+
* The SDK's connection state in the status file's vocabulary. Pure. `previous`
|
|
125
|
+
* is the status word in effect, which decides two things the SDK's state alone
|
|
126
|
+
* does not say: a `connecting` after a close is `reconnecting`, and the slow
|
|
127
|
+
* retry out of `blocked` (`connecting` again) stays `blocked` — only an
|
|
128
|
+
* accepted hello (`ready`) lifts it. `stopped` is `closed` from any state; a
|
|
129
|
+
* refusal stays visible as the last error, not as the socket word.
|
|
130
|
+
*/
|
|
131
|
+
declare function socketStateOf(next: RealtimeState, previous: SocketState): SocketState;
|
|
132
|
+
declare class IntegrationConnection extends EventEmitter {
|
|
103
133
|
private readonly options;
|
|
104
|
-
private
|
|
134
|
+
private rt;
|
|
105
135
|
private _state;
|
|
106
|
-
private attempt;
|
|
107
|
-
private reconnectTimer;
|
|
108
|
-
private livenessTimer;
|
|
109
136
|
private stopped;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
private helloOk;
|
|
137
|
+
/** Rejected hellos since the last accepted one: the first is an error line, the rest are info. */
|
|
138
|
+
private refusals;
|
|
113
139
|
private readonly selfHandle;
|
|
114
|
-
constructor(options:
|
|
140
|
+
constructor(options: IntegrationConnectionOptions);
|
|
115
141
|
get state(): SocketState;
|
|
116
142
|
/** True only while the socket is live — `hello.ok` received, not merely open. */
|
|
117
143
|
get connected(): boolean;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
on<E extends keyof DoorbellSocketEvents>(event: E, listener: DoorbellSocketEvents[E]): this;
|
|
144
|
+
on<E extends keyof IntegrationConnectionEvents>(event: E, listener: IntegrationConnectionEvents[E]): this;
|
|
145
|
+
/** Open the SDK's client. Once: it lives until `stop()`, reconnecting on its own. */
|
|
121
146
|
start(): void;
|
|
147
|
+
/** End the SDK's client. Final: a stopped connection is not restarted. */
|
|
122
148
|
stop(): void;
|
|
123
149
|
private setState;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
private onHelloOk;
|
|
150
|
+
/** The SDK is `blocked`: the server refused the credential on the hello. Fires per rejected attempt. */
|
|
151
|
+
private onBlocked;
|
|
127
152
|
/**
|
|
128
153
|
* A `message.new` frame. Only the sender (echo filter) and the ids (log
|
|
129
|
-
* line) are read. `content`, `metadata`, previews — never touched.
|
|
154
|
+
* line) are read. `content`, `metadata`, previews — never touched. The SDK
|
|
155
|
+
* acked it before this ran.
|
|
130
156
|
*/
|
|
131
157
|
private onMessageFrame;
|
|
158
|
+
/** A `wake` frame, validated by the SDK. No message, nothing to ack. */
|
|
159
|
+
private onWakeFrame;
|
|
132
160
|
private onInviteFrame;
|
|
133
|
-
/** Give up. The socket stays stopped; the holder decides what happens next. */
|
|
134
|
-
private enterTerminal;
|
|
135
|
-
private scheduleReconnect;
|
|
136
|
-
private armLiveness;
|
|
137
|
-
private clearTimers;
|
|
138
161
|
}
|
|
139
162
|
|
|
140
|
-
interface
|
|
163
|
+
interface IntegrationOptions {
|
|
141
164
|
readonly cfg: DaemonConfig;
|
|
142
165
|
readonly runner: RunRunner;
|
|
143
|
-
|
|
166
|
+
/** How this integration names itself to the server (texts runtime + its version). */
|
|
167
|
+
readonly client: IntegrationClient;
|
|
168
|
+
/** The one pointer line a run prompt ends with (`manualPointer(...)`). */
|
|
169
|
+
readonly manualPointer: string;
|
|
170
|
+
/** The skill file that follows the served manual (`<skills dir>/agentchat/SKILL.md`); absent, the daemon leaves the manual to the CLI. */
|
|
171
|
+
readonly manualPath?: string;
|
|
172
|
+
/** Injectable for tests; the manual download's `fetch`. */
|
|
173
|
+
readonly manualFetch?: ManualFetch;
|
|
144
174
|
readonly profile: RunProfile;
|
|
145
175
|
readonly budgetMs: number;
|
|
146
|
-
/** Injectable for tests; defaults to a real socket. */
|
|
147
|
-
readonly
|
|
148
|
-
/**
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
* class does not end the process.
|
|
153
|
-
*/
|
|
154
|
-
readonly onTerminal?: (reason: TerminalReason, detail: string) => void;
|
|
176
|
+
/** Injectable for tests; defaults to a real connection on the SDK socket. */
|
|
177
|
+
readonly connection?: IntegrationConnection;
|
|
178
|
+
/** Injectable for tests; defaults to an SDK client for `cfg`. */
|
|
179
|
+
readonly api?: AgentChatClient;
|
|
180
|
+
/** Injectable for tests; defaults to a store on `api` and the identity home. */
|
|
181
|
+
readonly texts?: TextsStore;
|
|
155
182
|
}
|
|
156
|
-
declare class
|
|
183
|
+
declare class Integration {
|
|
157
184
|
private readonly options;
|
|
158
|
-
private readonly
|
|
185
|
+
private readonly api;
|
|
186
|
+
private readonly connection;
|
|
187
|
+
private readonly texts;
|
|
188
|
+
private readonly manual;
|
|
159
189
|
private readonly invoker;
|
|
160
190
|
private heartbeatTimer;
|
|
161
191
|
private statusTimer;
|
|
162
192
|
private lastError;
|
|
163
193
|
private stopping;
|
|
164
|
-
constructor(options:
|
|
194
|
+
constructor(options: IntegrationOptions);
|
|
165
195
|
start(): Promise<void>;
|
|
166
196
|
/**
|
|
167
197
|
* Stop holding the socket and interrupt a run in flight (its process group
|
|
@@ -178,78 +208,70 @@ declare class Doorbell {
|
|
|
178
208
|
stopAndWait(graceMs: number): Promise<boolean>;
|
|
179
209
|
/** A run in flight finishes on its own; this resolves when it has. */
|
|
180
210
|
settled(): Promise<void>;
|
|
181
|
-
snapshot():
|
|
211
|
+
snapshot(): IntegrationStatus;
|
|
212
|
+
/**
|
|
213
|
+
* After every change in the texts in hand: the status file, and the skill
|
|
214
|
+
* file brought to the manual they announce. Exposed for an injected store's
|
|
215
|
+
* `onChange` (tests); the store this class builds calls it itself.
|
|
216
|
+
*/
|
|
217
|
+
textsChanged(): void;
|
|
218
|
+
/** The served texts plus the pointer line, or null while no text is in hand. */
|
|
219
|
+
private runPrompts;
|
|
182
220
|
/**
|
|
183
|
-
* The connect-time catch-up: one
|
|
221
|
+
* The connect-time catch-up: one wake (the invoker counts the tray before
|
|
184
222
|
* any run, so an empty tray costs a count, not a run) and the pending invites.
|
|
185
223
|
*/
|
|
186
224
|
private catchUp;
|
|
187
225
|
private writeStatus;
|
|
188
226
|
}
|
|
189
227
|
|
|
190
|
-
declare const
|
|
191
|
-
|
|
192
|
-
interface
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
|
|
197
|
-
readonly setTimeout?: (fn: () => void, ms: number) => TimerHandle;
|
|
198
|
-
readonly clearTimeout?: (handle: TimerHandle) => void;
|
|
228
|
+
declare const OFFERED_INVITES_FILE = "invites.offered.json";
|
|
229
|
+
/** The seam the invoker uses; `OfferedInvites` is the on-disk implementation. */
|
|
230
|
+
interface OfferedInviteStore {
|
|
231
|
+
has(inviteId: string): boolean;
|
|
232
|
+
add(inviteId: string): void;
|
|
233
|
+
/** Forget an offer: the run recorded at start turned out never to have got going. */
|
|
234
|
+
remove(inviteId: string): void;
|
|
199
235
|
}
|
|
200
|
-
declare
|
|
201
|
-
|
|
202
|
-
private readonly
|
|
236
|
+
declare function offeredInvitesPath(home: string): string;
|
|
237
|
+
declare class OfferedInvites implements OfferedInviteStore {
|
|
238
|
+
private readonly home;
|
|
203
239
|
private readonly now;
|
|
204
|
-
private readonly
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
get delayedPending(): boolean;
|
|
218
|
-
/** Epoch ms of the pending retry knock, or null. */
|
|
219
|
-
get delayedDue(): number | null;
|
|
220
|
-
/** A knock: arm the timer if none is armed; otherwise absorb. */
|
|
221
|
-
knock(): void;
|
|
222
|
-
/** A delayed knock (retry ladder). The sooner pending deadline is kept. */
|
|
223
|
-
knockAfter(delayMs: number): void;
|
|
224
|
-
/**
|
|
225
|
-
* Drop a pending retry knock, if there is one; returns whether there was.
|
|
226
|
-
* The debounce timer and later knocks are unaffected. For when nothing is
|
|
227
|
-
* owed any more — a run read the whole tray, or the tray was found empty —
|
|
228
|
-
* so the retry would only ring for a backlog that is already handled.
|
|
229
|
-
*/
|
|
230
|
-
cancelDelayed(): boolean;
|
|
231
|
-
/** Cancel everything; later knocks are ignored. */
|
|
232
|
-
stop(): void;
|
|
233
|
-
private fire;
|
|
240
|
+
private readonly entries;
|
|
241
|
+
/** `home === null` keeps the set in memory only (tests). */
|
|
242
|
+
constructor(home: string | null, entries?: Array<{
|
|
243
|
+
id: string;
|
|
244
|
+
at: string;
|
|
245
|
+
}>, now?: () => Date);
|
|
246
|
+
/** Read the set from the identity home; a missing or malformed file is an empty set. */
|
|
247
|
+
static load(home: string, now?: () => Date): OfferedInvites;
|
|
248
|
+
get size(): number;
|
|
249
|
+
has(inviteId: string): boolean;
|
|
250
|
+
add(inviteId: string): void;
|
|
251
|
+
remove(inviteId: string): void;
|
|
252
|
+
private persist;
|
|
234
253
|
}
|
|
235
254
|
|
|
236
255
|
declare const RETRY_LADDER_MS: readonly number[];
|
|
237
256
|
/** After the ladder is exhausted: how often the runtime is asked whether it is usable again. */
|
|
238
257
|
declare const PREFLIGHT_WATCH_MS: number;
|
|
239
|
-
interface
|
|
258
|
+
interface IntegrationInvokerOptions {
|
|
240
259
|
readonly runner: RunRunner;
|
|
241
|
-
|
|
260
|
+
/** The run prompts, resolved per run; null when the served texts are not available yet. */
|
|
261
|
+
readonly prompts: () => Promise<RunPrompts | null>;
|
|
242
262
|
/** A run is killed past this and counts as failed. */
|
|
243
263
|
readonly budgetMs: number;
|
|
244
264
|
readonly debounceMs?: number;
|
|
245
265
|
readonly retryLadderMs?: readonly number[];
|
|
246
266
|
readonly preflightWatchMs?: number;
|
|
247
267
|
/**
|
|
248
|
-
* Is anything waiting on the tray? Asked before every
|
|
268
|
+
* Is anything waiting on the tray? Asked before every wake run (never
|
|
249
269
|
* before an invite run). Resolves the answer; rejects when the count could
|
|
250
|
-
* not be read, and then the run starts anyway. Absent: every
|
|
270
|
+
* not be read, and then the run starts anyway. Absent: every wake runs.
|
|
251
271
|
*/
|
|
252
272
|
readonly trayHasWaiting?: () => Promise<boolean>;
|
|
273
|
+
/** Invites already offered to a run from this machine. Defaults to an in-memory set. */
|
|
274
|
+
readonly offeredInvites?: OfferedInviteStore;
|
|
253
275
|
/** Called after every state change (a status writer hangs off this). */
|
|
254
276
|
readonly onChange?: () => void;
|
|
255
277
|
readonly now?: () => number;
|
|
@@ -258,7 +280,7 @@ interface DoorbellInvokerOptions {
|
|
|
258
280
|
readonly runId?: () => string;
|
|
259
281
|
}
|
|
260
282
|
interface InvokerCounters {
|
|
261
|
-
readonly
|
|
283
|
+
readonly wakes: number;
|
|
262
284
|
readonly absorbed: number;
|
|
263
285
|
readonly invites: number;
|
|
264
286
|
readonly runsStarted: number;
|
|
@@ -266,14 +288,14 @@ interface InvokerCounters {
|
|
|
266
288
|
readonly runsFailed: number;
|
|
267
289
|
readonly runsTimedOut: number;
|
|
268
290
|
readonly runsNotStarted: number;
|
|
269
|
-
/**
|
|
291
|
+
/** Wake cycles that found the tray empty and started no run. */
|
|
270
292
|
readonly runsSkippedEmpty: number;
|
|
271
293
|
readonly retryRung: number;
|
|
272
294
|
readonly retryDueAt: number | null;
|
|
273
|
-
readonly lastRun:
|
|
295
|
+
readonly lastRun: IntegrationLastRun | null;
|
|
274
296
|
readonly running: boolean;
|
|
275
297
|
}
|
|
276
|
-
declare class
|
|
298
|
+
declare class IntegrationInvoker {
|
|
277
299
|
private readonly runner;
|
|
278
300
|
private readonly prompts;
|
|
279
301
|
private readonly budgetMs;
|
|
@@ -285,13 +307,23 @@ declare class DoorbellInvoker {
|
|
|
285
307
|
private readonly onChange;
|
|
286
308
|
private readonly newRunId;
|
|
287
309
|
private readonly trayHasWaiting;
|
|
310
|
+
private readonly offered;
|
|
288
311
|
private readonly coalescer;
|
|
289
312
|
private cycleDue;
|
|
290
313
|
private running;
|
|
291
314
|
private inFlight;
|
|
292
315
|
private stopped;
|
|
316
|
+
/** Invites queued for a run, in arrival order. */
|
|
293
317
|
private readonly invites;
|
|
294
|
-
|
|
318
|
+
/** Invites whose run did not start; offered again on the next wake. */
|
|
319
|
+
private readonly invitesAwaitingRetry;
|
|
320
|
+
/**
|
|
321
|
+
* Invite ids this process has taken, offered or not. The on-disk store says
|
|
322
|
+
* what was OFFERED; this says what is already in hand here — queued, in
|
|
323
|
+
* flight, or awaiting its retry — so the connect-time listing and a live
|
|
324
|
+
* frame for the same invite cannot queue it twice.
|
|
325
|
+
*/
|
|
326
|
+
private readonly taken;
|
|
295
327
|
private retryRung;
|
|
296
328
|
private preflightWatch;
|
|
297
329
|
private preflightWasDown;
|
|
@@ -303,14 +335,15 @@ declare class DoorbellInvoker {
|
|
|
303
335
|
private runsNotStarted;
|
|
304
336
|
private runsSkippedEmpty;
|
|
305
337
|
private lastRun;
|
|
306
|
-
constructor(options:
|
|
307
|
-
/** A
|
|
308
|
-
|
|
338
|
+
constructor(options: IntegrationInvokerOptions);
|
|
339
|
+
/** A wake from the socket (a frame), the connect-time catch-up, or any other source. Coalesced, then run. */
|
|
340
|
+
wake(source: string): void;
|
|
309
341
|
/**
|
|
310
|
-
* The second
|
|
311
|
-
*
|
|
342
|
+
* The second wake kind. Offered once per machine: an invite already offered
|
|
343
|
+
* to a run, already queued, or awaiting its retry is not queued again.
|
|
344
|
+
* Returns true when newly queued.
|
|
312
345
|
*/
|
|
313
|
-
invite(invite:
|
|
346
|
+
invite(invite: InviteWake): boolean;
|
|
314
347
|
/**
|
|
315
348
|
* Cancel timers and interrupt a run in flight (its signal aborts; the
|
|
316
349
|
* runner SIGTERMs the run's process group). `settled()` resolves when the
|
|
@@ -320,23 +353,32 @@ declare class DoorbellInvoker {
|
|
|
320
353
|
/** The promise of the work currently running, for tests and graceful stops. */
|
|
321
354
|
settled(): Promise<void>;
|
|
322
355
|
counters(): InvokerCounters;
|
|
323
|
-
private
|
|
356
|
+
private onWakeFired;
|
|
324
357
|
/** Run the worker if idle. One run at a time; work that lands mid-run runs afterwards. */
|
|
325
358
|
private schedule;
|
|
326
359
|
private drain;
|
|
327
360
|
/**
|
|
328
|
-
* The count before a
|
|
361
|
+
* The count before a wake run. True: start the run (something waits, or
|
|
329
362
|
* the count could not be read). False: the tray is empty — no run, nothing
|
|
330
363
|
* owed — or the invoker stopped while counting.
|
|
331
364
|
*/
|
|
332
365
|
private trayOwesRun;
|
|
333
366
|
/**
|
|
334
|
-
* Nothing is owed any more — a
|
|
335
|
-
* found it empty: back to the first rung, drop a pending re-
|
|
367
|
+
* Nothing is owed any more — a wake run read the whole tray, or a count
|
|
368
|
+
* found it empty: back to the first rung, drop a pending re-wake (it would
|
|
336
369
|
* only ring for a backlog that is already handled), end the preflight watch.
|
|
337
370
|
*/
|
|
338
371
|
private settleLadder;
|
|
339
372
|
private run;
|
|
373
|
+
/**
|
|
374
|
+
* An invite counts as offered once its run has started (recorded at
|
|
375
|
+
* `onStarted`; a runner that never signals it is recorded here, when the
|
|
376
|
+
* run ends): the agent had its chance, and the invite stays reachable
|
|
377
|
+
* through the hosted invite tools in any later run — including a run this
|
|
378
|
+
* integration interrupted. A run that never got going is no offer: the
|
|
379
|
+
* record is taken back and the invite is held for the next wake.
|
|
380
|
+
*/
|
|
381
|
+
private settleInvite;
|
|
340
382
|
private scheduleRetry;
|
|
341
383
|
private armPreflightWatch;
|
|
342
384
|
private clearPreflightWatch;
|
|
@@ -359,10 +401,12 @@ interface SpawnRunSpec {
|
|
|
359
401
|
* the outcome is `failed` with an "interrupted" detail.
|
|
360
402
|
*/
|
|
361
403
|
readonly signal?: AbortSignal;
|
|
404
|
+
/** Called once when the child process has been spawned (`RunRequest.onStarted`). */
|
|
405
|
+
readonly onStarted?: () => void;
|
|
362
406
|
}
|
|
363
407
|
/** Strip anything key-shaped or terminal-styled from a diagnostic, and bound it. */
|
|
364
408
|
declare function redactDiagnostic(value: string, max?: number): string;
|
|
365
409
|
/** Start the command, wait for it, classify. Never throws. */
|
|
366
410
|
declare function spawnRun(spec: SpawnRunSpec): Promise<RunOutcome>;
|
|
367
411
|
|
|
368
|
-
export {
|
|
412
|
+
export { type DaemonConfig, Integration, IntegrationConnection, type IntegrationConnectionEvents, type IntegrationConnectionOptions, IntegrationInvoker, type IntegrationInvokerOptions, type IntegrationOptions, type InviteWake, type InvokerCounters, type MessageWake, OFFERED_INVITES_FILE, type OfferedInviteStore, OfferedInvites, PREFLIGHT_WATCH_MS, RETRY_LADDER_MS, type ReminderWake, type ResolveDaemonOpts, type RunIntegrationOpts, RunOutcome, RunRunner, type SpawnRunSpec, type Wake, offeredInvitesPath, redactDiagnostic, resolveDaemonConfig, runIntegration, socketStateOf, spawnRun, wsBaseFor, wsUrlFor };
|