@agentchatme/agent-core 0.3.0 → 0.4.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 +34 -26
- package/dist/chunk-HOY2FERJ.js +26 -0
- package/dist/chunk-HOY2FERJ.js.map +1 -0
- package/dist/chunk-NCSF3CCV.js +139 -0
- package/dist/chunk-NCSF3CCV.js.map +1 -0
- package/dist/chunk-TH6XOVA3.js +283 -0
- package/dist/chunk-TH6XOVA3.js.map +1 -0
- package/dist/{chunk-KUZZ3MW2.js → chunk-W3LYBKIV.js} +391 -888
- package/dist/chunk-W3LYBKIV.js.map +1 -0
- package/dist/daemon-entry.d.ts +127 -282
- package/dist/daemon-entry.js +308 -951
- package/dist/daemon-entry.js.map +1 -1
- package/dist/index.d.ts +63 -14
- package/dist/index.js +98 -137
- package/dist/index.js.map +1 -1
- package/dist/presets.d.ts +262 -0
- package/dist/presets.js +538 -0
- package/dist/presets.js.map +1 -0
- package/dist/runner-BzgsiS3V.d.ts +122 -0
- package/dist/served-manual-DZmEak4_.d.ts +368 -0
- package/package.json +8 -3
- package/dist/chunk-KUZZ3MW2.js.map +0 -1
- package/dist/prompts-BUfpwUT7.d.ts +0 -630
package/dist/daemon-entry.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
1
|
+
import { I as IntegrationClient, M as ManualFetch, a as IntegrationStatus, S as SocketState } from './served-manual-DZmEak4_.js';
|
|
2
|
+
import { R as RunnerSource, a as RunProfile, b as RunRunner, c as RunOutcome } from './runner-BzgsiS3V.js';
|
|
3
|
+
export { d as RunKind, e as RunOutcomeState, f as RunPreflight, g as RunRequest, h as RunWake, i as RunnerFactory, j as RunnerIdentity } from './runner-BzgsiS3V.js';
|
|
4
|
+
import { AgentChatClient, RealtimeClient, BlockedInfo, RealtimeState } from 'agentchatme';
|
|
5
5
|
import 'zod';
|
|
6
6
|
|
|
7
7
|
interface RunIntegrationOpts {
|
|
8
8
|
/** THE identity home for the agent this daemon serves. */
|
|
9
9
|
home: string;
|
|
10
|
-
/** How to start one headless run
|
|
11
|
-
runner:
|
|
10
|
+
/** How to start one headless run: a runner, or a factory that builds one per identity (`RunnerFactory`). */
|
|
11
|
+
runner: RunnerSource;
|
|
12
12
|
/** How this integration names itself to the server: the texts runtime and its own version. */
|
|
13
13
|
client: IntegrationClient;
|
|
14
14
|
/** The one pointer line a run prompt ends with: how THIS runtime reaches its copy of the manual (`manualPointer(...)`). */
|
|
@@ -31,6 +31,14 @@ interface RunIntegrationOpts {
|
|
|
31
31
|
env?: NodeJS.ProcessEnv;
|
|
32
32
|
/** Test seam: what a signal-initiated shutdown calls last. Defaults to `process.exit`. */
|
|
33
33
|
exit?: (code: number) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Serve only the agent the home's `credentials` hold: `AGENTCHAT_API_KEY`
|
|
36
|
+
* in the environment is ignored (default false: it overrides, as for every
|
|
37
|
+
* integration). The `agentchat` listener sets it.
|
|
38
|
+
*/
|
|
39
|
+
credentialsFromHomeOnly?: boolean;
|
|
40
|
+
/** See `IntegrationOptions.dismissIgnoredInvites` (default true). */
|
|
41
|
+
dismissIgnoredInvites?: boolean;
|
|
34
42
|
}
|
|
35
43
|
/**
|
|
36
44
|
* Run the integration daemon. Returns only on a condition that makes running
|
|
@@ -61,6 +69,8 @@ interface ResolveDaemonOpts {
|
|
|
61
69
|
workdir: string;
|
|
62
70
|
/** How to identify to the server when the handle has to be asked for. */
|
|
63
71
|
client: IntegrationClient;
|
|
72
|
+
/** Whether `AGENTCHAT_API_KEY` may override the home's credentials (default true; see `resolveIdentity`). */
|
|
73
|
+
envKey?: boolean;
|
|
64
74
|
}
|
|
65
75
|
/**
|
|
66
76
|
* Resolve the identity the daemon runs as.
|
|
@@ -72,94 +82,15 @@ interface ResolveDaemonOpts {
|
|
|
72
82
|
*/
|
|
73
83
|
declare function resolveDaemonConfig(opts: ResolveDaemonOpts): Promise<DaemonConfig>;
|
|
74
84
|
|
|
75
|
-
interface MessageWake {
|
|
76
|
-
readonly source: 'message';
|
|
77
|
-
readonly sender: string | null;
|
|
78
|
-
readonly conversationId: string | null;
|
|
79
|
-
readonly messageId: string | null;
|
|
80
|
-
}
|
|
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 {
|
|
90
|
-
readonly inviteId: string;
|
|
91
|
-
readonly groupId: string | null;
|
|
92
|
-
readonly groupName: string | null;
|
|
93
|
-
readonly inviterHandle: string | null;
|
|
94
|
-
}
|
|
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. */
|
|
99
|
-
echo: () => void;
|
|
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;
|
|
103
|
-
/**
|
|
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.
|
|
109
|
-
*/
|
|
110
|
-
blocked: (detail: string, info: BlockedInfo) => void;
|
|
111
|
-
}
|
|
112
|
-
interface IntegrationConnectionOptions {
|
|
113
|
-
readonly apiKey: string;
|
|
114
|
-
/** `wss://api.agentchat.me` — the SDK appends `/v1/ws`. */
|
|
115
|
-
readonly wsBase: string;
|
|
116
|
-
/** This agent's handle, to recognise its own echo. Bare, any case. */
|
|
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;
|
|
122
|
-
}
|
|
123
85
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
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.
|
|
86
|
+
* How long past its budget a runner may take to return before the loop stops
|
|
87
|
+
* waiting for it. `spawnRun` always returns well inside this (grace, drain and
|
|
88
|
+
* abandon are seconds); the deadline is for a runner that does not keep the
|
|
89
|
+
* "never hangs" promise — the loop must outlive every runner.
|
|
130
90
|
*/
|
|
131
|
-
declare
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
private rt;
|
|
135
|
-
private _state;
|
|
136
|
-
private stopped;
|
|
137
|
-
/** Rejected hellos since the last accepted one: the first is an error line, the rest are info. */
|
|
138
|
-
private refusals;
|
|
139
|
-
private readonly selfHandle;
|
|
140
|
-
constructor(options: IntegrationConnectionOptions);
|
|
141
|
-
get state(): SocketState;
|
|
142
|
-
/** True only while the socket is live — `hello.ok` received, not merely open. */
|
|
143
|
-
get connected(): boolean;
|
|
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. */
|
|
146
|
-
start(): void;
|
|
147
|
-
/** End the SDK's client. Final: a stopped connection is not restarted. */
|
|
148
|
-
stop(): void;
|
|
149
|
-
private setState;
|
|
150
|
-
/** The SDK is `blocked`: the server refused the credential on the hello. Fires per rejected attempt. */
|
|
151
|
-
private onBlocked;
|
|
152
|
-
/**
|
|
153
|
-
* A `message.new` frame. Only the sender (echo filter) and the ids (log
|
|
154
|
-
* line) are read. `content`, `metadata`, previews — never touched. The SDK
|
|
155
|
-
* acked it before this ran.
|
|
156
|
-
*/
|
|
157
|
-
private onMessageFrame;
|
|
158
|
-
/** A `wake` frame, validated by the SDK. No message, nothing to ack. */
|
|
159
|
-
private onWakeFrame;
|
|
160
|
-
private onInviteFrame;
|
|
161
|
-
}
|
|
162
|
-
|
|
91
|
+
declare const RUNNER_DEADLINE_SLACK_MS = 60000;
|
|
92
|
+
/** A runner's `preflight()` (a `--version`, an auth probe) past this counts as not ok. */
|
|
93
|
+
declare const PREFLIGHT_DEADLINE_MS = 60000;
|
|
163
94
|
interface IntegrationOptions {
|
|
164
95
|
readonly cfg: DaemonConfig;
|
|
165
96
|
readonly runner: RunRunner;
|
|
@@ -167,167 +98,52 @@ interface IntegrationOptions {
|
|
|
167
98
|
readonly client: IntegrationClient;
|
|
168
99
|
/** The one pointer line a run prompt ends with (`manualPointer(...)`). */
|
|
169
100
|
readonly manualPointer: string;
|
|
170
|
-
/** The skill file that follows the served manual (`<skills dir>/agentchat/SKILL.md`); absent, the
|
|
101
|
+
/** The skill file that follows the served manual (`<skills dir>/agentchat/SKILL.md`); absent, the manual is left to the CLI. */
|
|
171
102
|
readonly manualPath?: string;
|
|
172
103
|
/** Injectable for tests; the manual download's `fetch`. */
|
|
173
104
|
readonly manualFetch?: ManualFetch;
|
|
174
105
|
readonly profile: RunProfile;
|
|
175
106
|
readonly budgetMs: number;
|
|
176
|
-
/** Injectable for tests;
|
|
177
|
-
readonly
|
|
107
|
+
/** Injectable for tests; past `budgetMs` plus this a runner that has not returned is abandoned. */
|
|
108
|
+
readonly runnerDeadlineSlackMs?: number;
|
|
178
109
|
/** Injectable for tests; defaults to an SDK client for `cfg`. */
|
|
179
110
|
readonly api?: AgentChatClient;
|
|
180
|
-
/** Injectable for tests
|
|
181
|
-
readonly
|
|
111
|
+
/** Injectable for tests: the socket (built with `ackOnReceipt` and the v1 capabilities otherwise). */
|
|
112
|
+
readonly realtime?: RealtimeClient;
|
|
113
|
+
/** Injectable for tests: the coalescing window. */
|
|
114
|
+
readonly quietMs?: number;
|
|
115
|
+
readonly maxMs?: number;
|
|
116
|
+
/** Injectable for tests: the kit's cycle watchdog (default 10 min, not counting runs). */
|
|
117
|
+
readonly cycleTimeoutMs?: number;
|
|
118
|
+
/**
|
|
119
|
+
* Injectable for tests: the kit's pacing window (default 60 s) — a second
|
|
120
|
+
* completed run that leaves an invite pending counts toward dismissing it
|
|
121
|
+
* only this long after the first.
|
|
122
|
+
*/
|
|
123
|
+
readonly paceMs?: number;
|
|
124
|
+
/**
|
|
125
|
+
* The kit's single-run rule dismisses an invite two completed runs left
|
|
126
|
+
* pending, so an ignored invite does not cost a run on every wake. Right
|
|
127
|
+
* when a run is the agent itself; wrong when "completed" only means a
|
|
128
|
+
* receiver accepted a POST (the `agentchat forward` mode): there it is
|
|
129
|
+
* false, and no invite is ever dismissed on the agent's behalf.
|
|
130
|
+
*/
|
|
131
|
+
readonly dismissIgnoredInvites?: boolean;
|
|
182
132
|
}
|
|
183
133
|
declare class Integration {
|
|
184
134
|
private readonly options;
|
|
185
135
|
private readonly api;
|
|
186
|
-
private readonly
|
|
136
|
+
private readonly realtime;
|
|
187
137
|
private readonly texts;
|
|
188
138
|
private readonly manual;
|
|
189
|
-
private readonly
|
|
139
|
+
private readonly loop;
|
|
190
140
|
private heartbeatTimer;
|
|
191
141
|
private statusTimer;
|
|
142
|
+
private socket;
|
|
192
143
|
private lastError;
|
|
193
144
|
private stopping;
|
|
194
|
-
constructor(options: IntegrationOptions);
|
|
195
|
-
start(): Promise<void>;
|
|
196
|
-
/**
|
|
197
|
-
* Stop holding the socket and interrupt a run in flight (its process group
|
|
198
|
-
* is SIGTERMed by the runner). Synchronous; `settled()` or `stopAndWait()`
|
|
199
|
-
* tell when the run has actually ended.
|
|
200
|
-
*/
|
|
201
|
-
stop(): void;
|
|
202
|
-
/**
|
|
203
|
-
* `stop()`, then wait up to `graceMs` for the interrupted run to end. What a
|
|
204
|
-
* shutdown awaits before the process exits, so a launchd/systemd stop
|
|
205
|
-
* reaches the child and the restarted daemon does not find a run still
|
|
206
|
-
* going. Resolves true when nothing is running any more.
|
|
207
|
-
*/
|
|
208
|
-
stopAndWait(graceMs: number): Promise<boolean>;
|
|
209
|
-
/** A run in flight finishes on its own; this resolves when it has. */
|
|
210
|
-
settled(): Promise<void>;
|
|
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;
|
|
220
|
-
/**
|
|
221
|
-
* The connect-time catch-up: one wake (the invoker counts the tray before
|
|
222
|
-
* any run, so an empty tray costs a count, not a run) and the pending invites.
|
|
223
|
-
*/
|
|
224
|
-
private catchUp;
|
|
225
|
-
private writeStatus;
|
|
226
|
-
}
|
|
227
|
-
|
|
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;
|
|
235
|
-
}
|
|
236
|
-
declare function offeredInvitesPath(home: string): string;
|
|
237
|
-
declare class OfferedInvites implements OfferedInviteStore {
|
|
238
|
-
private readonly home;
|
|
239
|
-
private readonly now;
|
|
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;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
declare const RETRY_LADDER_MS: readonly number[];
|
|
256
|
-
/** After the ladder is exhausted: how often the runtime is asked whether it is usable again. */
|
|
257
|
-
declare const PREFLIGHT_WATCH_MS: number;
|
|
258
|
-
interface IntegrationInvokerOptions {
|
|
259
|
-
readonly runner: RunRunner;
|
|
260
|
-
/** The run prompts, resolved per run; null when the served texts are not available yet. */
|
|
261
|
-
readonly prompts: () => Promise<RunPrompts | null>;
|
|
262
|
-
/** A run is killed past this and counts as failed. */
|
|
263
|
-
readonly budgetMs: number;
|
|
264
|
-
readonly debounceMs?: number;
|
|
265
|
-
readonly retryLadderMs?: readonly number[];
|
|
266
|
-
readonly preflightWatchMs?: number;
|
|
267
|
-
/**
|
|
268
|
-
* Is anything waiting on the tray? Asked before every wake run (never
|
|
269
|
-
* before an invite run). Resolves the answer; rejects when the count could
|
|
270
|
-
* not be read, and then the run starts anyway. Absent: every wake runs.
|
|
271
|
-
*/
|
|
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;
|
|
275
|
-
/** Called after every state change (a status writer hangs off this). */
|
|
276
|
-
readonly onChange?: () => void;
|
|
277
|
-
readonly now?: () => number;
|
|
278
|
-
readonly setTimeout?: (fn: () => void, ms: number) => TimerHandle;
|
|
279
|
-
readonly clearTimeout?: (handle: TimerHandle) => void;
|
|
280
|
-
readonly runId?: () => string;
|
|
281
|
-
}
|
|
282
|
-
interface InvokerCounters {
|
|
283
|
-
readonly wakes: number;
|
|
284
|
-
readonly absorbed: number;
|
|
285
|
-
readonly invites: number;
|
|
286
|
-
readonly runsStarted: number;
|
|
287
|
-
readonly runsOk: number;
|
|
288
|
-
readonly runsFailed: number;
|
|
289
|
-
readonly runsTimedOut: number;
|
|
290
|
-
readonly runsNotStarted: number;
|
|
291
|
-
/** Wake cycles that found the tray empty and started no run. */
|
|
292
|
-
readonly runsSkippedEmpty: number;
|
|
293
|
-
readonly retryRung: number;
|
|
294
|
-
readonly retryDueAt: number | null;
|
|
295
|
-
readonly lastRun: IntegrationLastRun | null;
|
|
296
|
-
readonly running: boolean;
|
|
297
|
-
}
|
|
298
|
-
declare class IntegrationInvoker {
|
|
299
|
-
private readonly runner;
|
|
300
|
-
private readonly prompts;
|
|
301
|
-
private readonly budgetMs;
|
|
302
|
-
private readonly ladder;
|
|
303
|
-
private readonly preflightWatchMs;
|
|
304
|
-
private readonly now;
|
|
305
|
-
private readonly _setTimeout;
|
|
306
|
-
private readonly _clearTimeout;
|
|
307
|
-
private readonly onChange;
|
|
308
|
-
private readonly newRunId;
|
|
309
|
-
private readonly trayHasWaiting;
|
|
310
|
-
private readonly offered;
|
|
311
|
-
private readonly coalescer;
|
|
312
|
-
private cycleDue;
|
|
313
|
-
private running;
|
|
314
|
-
private inFlight;
|
|
315
145
|
private stopped;
|
|
316
|
-
|
|
317
|
-
private readonly invites;
|
|
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;
|
|
327
|
-
private retryRung;
|
|
328
|
-
private preflightWatch;
|
|
329
|
-
private preflightWasDown;
|
|
330
|
-
private invitesSeen;
|
|
146
|
+
private invites;
|
|
331
147
|
private runsStarted;
|
|
332
148
|
private runsOk;
|
|
333
149
|
private runsFailed;
|
|
@@ -335,67 +151,63 @@ declare class IntegrationInvoker {
|
|
|
335
151
|
private runsNotStarted;
|
|
336
152
|
private runsSkippedEmpty;
|
|
337
153
|
private lastRun;
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
wake(
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
* Returns true when newly queued.
|
|
345
|
-
*/
|
|
346
|
-
invite(invite: InviteWake): boolean;
|
|
154
|
+
/** The newest wake since the last run started (for `RunRequest.wake`). */
|
|
155
|
+
private pendingWake;
|
|
156
|
+
/** The rung of the newest `unanswered` wake frame (the kit's wake event does not carry it). */
|
|
157
|
+
private lastUnansweredStep;
|
|
158
|
+
constructor(options: IntegrationOptions);
|
|
159
|
+
start(): Promise<void>;
|
|
347
160
|
/**
|
|
348
|
-
*
|
|
349
|
-
* runner SIGTERMs
|
|
350
|
-
*
|
|
161
|
+
* Stop holding the socket and interrupt a run in flight (its signal aborts;
|
|
162
|
+
* the runner SIGTERMs its process group). `idle()` / `stopAndWait()`
|
|
163
|
+
* tell when the run has actually ended.
|
|
351
164
|
*/
|
|
352
165
|
stop(): void;
|
|
353
|
-
/**
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
* owed — or the invoker stopped while counting.
|
|
364
|
-
*/
|
|
365
|
-
private trayOwesRun;
|
|
366
|
-
/**
|
|
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
|
|
369
|
-
* only ring for a backlog that is already handled), end the preflight watch.
|
|
370
|
-
*/
|
|
371
|
-
private settleLadder;
|
|
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;
|
|
382
|
-
private scheduleRetry;
|
|
383
|
-
private armPreflightWatch;
|
|
384
|
-
private clearPreflightWatch;
|
|
385
|
-
private probePreflight;
|
|
166
|
+
/** `stop()`, then wait up to `graceMs` for the interrupted run to end. Resolves true when nothing runs any more. */
|
|
167
|
+
stopAndWait(graceMs: number): Promise<boolean>;
|
|
168
|
+
/** Resolves when no cycle (and so no run) is running: the kit's `ReceiveLoop.idle()`. */
|
|
169
|
+
idle(): Promise<void>;
|
|
170
|
+
/** A wake heard outside the socket (a test, a webhook the integration received). */
|
|
171
|
+
wake(): void;
|
|
172
|
+
snapshot(): IntegrationStatus;
|
|
173
|
+
private startRun;
|
|
174
|
+
private onEvent;
|
|
175
|
+
private writeStatus;
|
|
386
176
|
}
|
|
387
177
|
|
|
178
|
+
/**
|
|
179
|
+
* The SDK's connection state in the status file's vocabulary. Pure. `previous`
|
|
180
|
+
* is the status word in effect, which decides two things the SDK's state alone
|
|
181
|
+
* does not say: a `connecting` after a close is `reconnecting`, and the slow
|
|
182
|
+
* retry out of `blocked` (`connecting` again) stays `blocked` — only an
|
|
183
|
+
* accepted hello (`ready`) lifts it. `stopped` is `closed` from any state; a
|
|
184
|
+
* refusal stays visible as the last error, not as the socket word.
|
|
185
|
+
*/
|
|
186
|
+
declare function socketStateOf(next: RealtimeState, previous: SocketState): SocketState;
|
|
187
|
+
/** The `last error` line for a refused credential: the server's close, what to do, and that the SDK keeps trying. */
|
|
188
|
+
declare function blockedDetail(info: BlockedInfo): string;
|
|
189
|
+
|
|
388
190
|
interface SpawnRunSpec {
|
|
389
191
|
readonly command: string;
|
|
390
192
|
readonly args: readonly string[];
|
|
391
193
|
readonly cwd: string;
|
|
392
194
|
readonly env: NodeJS.ProcessEnv;
|
|
195
|
+
/**
|
|
196
|
+
* Run `command` through the platform shell (`/bin/sh -c`, `cmd.exe /d /s /c`)
|
|
197
|
+
* with no `args`: for a command line the OWNER configured. Nothing derived
|
|
198
|
+
* from a wake or a message is ever part of it.
|
|
199
|
+
*/
|
|
200
|
+
readonly shell?: boolean;
|
|
393
201
|
/** Written to the child's stdin and closed; `null` closes stdin at once. */
|
|
394
202
|
readonly stdin: string | null;
|
|
395
203
|
/** Kill past this. */
|
|
396
204
|
readonly budgetMs: number;
|
|
397
205
|
/** SIGTERM first; SIGKILL this long after. */
|
|
398
206
|
readonly graceMs?: number;
|
|
207
|
+
/** After the process exited, how long its pipes may stay open before the run is detached from them. */
|
|
208
|
+
readonly drainMs?: number;
|
|
209
|
+
/** After the SIGKILL, how long before a run that has still not ended is abandoned. */
|
|
210
|
+
readonly abandonMs?: number;
|
|
399
211
|
/**
|
|
400
212
|
* Aborting it SIGTERMs the run's process group (SIGKILL after `graceMs`);
|
|
401
213
|
* the outcome is `failed` with an "interrupted" detail.
|
|
@@ -406,7 +218,40 @@ interface SpawnRunSpec {
|
|
|
406
218
|
}
|
|
407
219
|
/** Strip anything key-shaped or terminal-styled from a diagnostic, and bound it. */
|
|
408
220
|
declare function redactDiagnostic(value: string, max?: number): string;
|
|
409
|
-
/**
|
|
221
|
+
/** What one Windows sweep saw and did, for the log line and for tests. */
|
|
222
|
+
interface WindowsSweep {
|
|
223
|
+
/** PowerShell's exit code; null when it was killed past its deadline or could not start. */
|
|
224
|
+
readonly exitCode: number | null;
|
|
225
|
+
readonly timedOut: boolean;
|
|
226
|
+
/** Every child of the root the sweep saw, as `<pid> <created ISO>`, in or out of the window. */
|
|
227
|
+
readonly candidates: string[];
|
|
228
|
+
/** Pids it ran `taskkill /T /F` on, with taskkill's exit code. */
|
|
229
|
+
readonly killed: Array<{
|
|
230
|
+
pid: number;
|
|
231
|
+
code: number;
|
|
232
|
+
}>;
|
|
233
|
+
/** The window it used, ISO. */
|
|
234
|
+
readonly window: string | null;
|
|
235
|
+
/** stderr, bounded. */
|
|
236
|
+
readonly stderr: string;
|
|
237
|
+
}
|
|
238
|
+
/** A cold PowerShell on a busy runner takes seconds to start (seen: ~30 s on windows-latest the first time); past this the sweep is given up. */
|
|
239
|
+
declare const WINDOWS_SWEEP_TIMEOUT_MS = 60000;
|
|
240
|
+
/**
|
|
241
|
+
* Windows: kill the processes an exited run left behind — its direct
|
|
242
|
+
* children, which keep the dead run's pid as their `ParentProcessId` (Windows
|
|
243
|
+
* does not reparent), created while the run was alive (so a reused pid cannot
|
|
244
|
+
* pick up a stranger's children), each with its own tree. Best effort, and
|
|
245
|
+
* never waited for by the run: `spawnRun` only logs the result. A
|
|
246
|
+
* `powershell -EncodedCommand` (no quoting to get wrong), bounded by
|
|
247
|
+
* `timeoutMs`. Resolves null off Windows.
|
|
248
|
+
*/
|
|
249
|
+
declare function sweepWindowsDescendants(rootPid: number, aliveFromMs: number, aliveUntilMs: number, options?: {
|
|
250
|
+
timeoutMs?: number;
|
|
251
|
+
}): Promise<WindowsSweep | null>;
|
|
252
|
+
/** One line for the log: what a sweep found and did. */
|
|
253
|
+
declare function describeWindowsSweep(sweep: WindowsSweep): string;
|
|
254
|
+
/** Start the command, wait for it, classify. Never throws, and always resolves. */
|
|
410
255
|
declare function spawnRun(spec: SpawnRunSpec): Promise<RunOutcome>;
|
|
411
256
|
|
|
412
|
-
export { type DaemonConfig, Integration,
|
|
257
|
+
export { type DaemonConfig, Integration, type IntegrationOptions, PREFLIGHT_DEADLINE_MS, RUNNER_DEADLINE_SLACK_MS, type ResolveDaemonOpts, type RunIntegrationOpts, RunOutcome, RunRunner, RunnerSource, type SpawnRunSpec, WINDOWS_SWEEP_TIMEOUT_MS, type WindowsSweep, blockedDetail, describeWindowsSweep, redactDiagnostic, resolveDaemonConfig, runIntegration, socketStateOf, spawnRun, sweepWindowsDescendants, wsBaseFor, wsUrlFor };
|