@agentchatme/agent-core 0.6.0 → 0.7.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/README.md +52 -6
- package/dist/{chunk-QUANHUVW.js → chunk-4PCDVXAR.js} +3 -3
- package/dist/{chunk-QUANHUVW.js.map → chunk-4PCDVXAR.js.map} +1 -1
- package/dist/{chunk-AVLI55C5.js → chunk-5KMQ23O6.js} +34 -8
- package/dist/chunk-5KMQ23O6.js.map +1 -0
- package/dist/{chunk-EDB33Z22.js → chunk-AQTRC7G4.js} +220 -49
- package/dist/chunk-AQTRC7G4.js.map +1 -0
- package/dist/daemon-entry.d.ts +55 -5
- package/dist/daemon-entry.js +149 -12
- package/dist/daemon-entry.js.map +1 -1
- package/dist/index.d.ts +45 -5
- package/dist/index.js +77 -3
- package/dist/index.js.map +1 -1
- package/dist/presets.d.ts +145 -2
- package/dist/presets.js +241 -18
- package/dist/presets.js.map +1 -1
- package/dist/{runner-C9kZD3KH.d.ts → runner-BLvFalN4.d.ts} +51 -7
- package/dist/{served-manual-CawJYdzJ.d.ts → served-manual-Bg-y_MEy.d.ts} +105 -2
- package/package.json +2 -2
- package/dist/chunk-AVLI55C5.js.map +0 -1
- package/dist/chunk-EDB33Z22.js.map +0 -1
package/dist/daemon-entry.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { I as IntegrationClient, L as LeaseOptions, M as ManualFetch, a as IntegrationStatus, b as IntegrationRunsFailing, S as SocketState } from './served-manual-
|
|
2
|
-
import { R as RunnerSource, a as RunProfile, b as RunRunner, c as RunOutcome } from './runner-
|
|
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-
|
|
1
|
+
import { I as IntegrationClient, L as LeaseOptions, M as ManualFetch, a as IntegrationStatus, b as IntegrationRunsFailing, S as SocketState } from './served-manual-Bg-y_MEy.js';
|
|
2
|
+
import { R as RunnerSource, a as RunProfile, b as RunRunner, c as RunOutcome } from './runner-BLvFalN4.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-BLvFalN4.js';
|
|
4
4
|
import { AgentChatClient, RealtimeClient, BlockedInfo, RealtimeState } from 'agentchatme';
|
|
5
5
|
import 'zod';
|
|
6
6
|
|
|
@@ -40,6 +40,8 @@ interface RunIntegrationOpts {
|
|
|
40
40
|
credentialsFromHomeOnly?: boolean;
|
|
41
41
|
/** See `IntegrationOptions.dismissIgnoredInvites` (default true). */
|
|
42
42
|
dismissIgnoredInvites?: boolean;
|
|
43
|
+
/** See `IntegrationOptions.conversationRuns` (default true: one run per conversation whenever the served texts allow it). */
|
|
44
|
+
conversationRuns?: boolean;
|
|
43
45
|
/** Test seam: while serving, how often to look again (5 s; the backoff after failed starts grows from it). */
|
|
44
46
|
pollMs?: number;
|
|
45
47
|
/** Test seam: the loop's own tick, how soon it notices a nudge (250 ms). */
|
|
@@ -110,6 +112,12 @@ declare function resolveDaemonConfig(opts: ResolveDaemonOpts): Promise<DaemonCon
|
|
|
110
112
|
declare const RUNNER_DEADLINE_SLACK_MS = 60000;
|
|
111
113
|
/** A runner's `preflight()` (a `--version`, an auth probe) past this counts as not ok. */
|
|
112
114
|
declare const PREFLIGHT_DEADLINE_MS = 60000;
|
|
115
|
+
/**
|
|
116
|
+
* A runner's `checkRuntime()` (a minimal model call) past this counts as not
|
|
117
|
+
* ok, and its probe is stopped (killed with its tree). The kit's own bound is
|
|
118
|
+
* the same 60 s.
|
|
119
|
+
*/
|
|
120
|
+
declare const RUNTIME_CHECK_DEADLINE_MS = 60000;
|
|
113
121
|
interface IntegrationOptions {
|
|
114
122
|
readonly cfg: DaemonConfig;
|
|
115
123
|
readonly runner: RunRunner;
|
|
@@ -152,6 +160,17 @@ interface IntegrationOptions {
|
|
|
152
160
|
* false, and no invite is ever dismissed on the agent's behalf.
|
|
153
161
|
*/
|
|
154
162
|
readonly dismissIgnoredInvites?: boolean;
|
|
163
|
+
/**
|
|
164
|
+
* Conversation runs (default true): whenever the served texts carry
|
|
165
|
+
* `conversation_run_template`, one run per conversation that owes a reply
|
|
166
|
+
* instead of one run for the whole tray. False keeps one run for the tray:
|
|
167
|
+
* right when a "run" does not start the agent on that one conversation (the
|
|
168
|
+
* `agentchat forward` mode hands each run to a receiver that reads the
|
|
169
|
+
* whole tray itself).
|
|
170
|
+
*/
|
|
171
|
+
readonly conversationRuns?: boolean;
|
|
172
|
+
/** Injectable for tests; `RUNTIME_CHECK_DEADLINE_MS`. */
|
|
173
|
+
readonly runtimeCheckDeadlineMs?: number;
|
|
155
174
|
}
|
|
156
175
|
declare class Integration {
|
|
157
176
|
private readonly options;
|
|
@@ -184,10 +203,16 @@ declare class Integration {
|
|
|
184
203
|
private runsNotStarted;
|
|
185
204
|
private runsSkippedEmpty;
|
|
186
205
|
private lastRun;
|
|
206
|
+
/** When the last run that got done ended (`last_ok_run_at`). */
|
|
207
|
+
private lastOkRunAt;
|
|
187
208
|
/** The newest wake since the last run started (for `RunRequest.wake`). */
|
|
188
209
|
private pendingWake;
|
|
189
210
|
/** The rung of the newest `unanswered` wake frame (the kit's wake event does not carry it). */
|
|
190
211
|
private lastUnansweredStep;
|
|
212
|
+
/** The conversations the server paused for this agent, as it answered (kept in the identity home). */
|
|
213
|
+
private readonly paused;
|
|
214
|
+
/** The runner's runtime check in flight: concurrent asks share it. */
|
|
215
|
+
private runtimeCheckInFlight;
|
|
191
216
|
constructor(options: IntegrationOptions);
|
|
192
217
|
start(): Promise<void>;
|
|
193
218
|
/**
|
|
@@ -204,6 +229,17 @@ declare class Integration {
|
|
|
204
229
|
wake(): void;
|
|
205
230
|
snapshot(): IntegrationStatus;
|
|
206
231
|
private startRun;
|
|
232
|
+
/**
|
|
233
|
+
* The runner's runtime check (a minimal model call, no peer content, no
|
|
234
|
+
* AgentChat tools), bounded by `RUNTIME_CHECK_DEADLINE_MS` and stopped with
|
|
235
|
+
* the integration; concurrent asks share one check. Its output is the
|
|
236
|
+
* runner's to discard: only whether it answered, and a bounded diagnostic,
|
|
237
|
+
* come back.
|
|
238
|
+
*/
|
|
239
|
+
private checkRuntime;
|
|
240
|
+
private runRuntimeCheck;
|
|
241
|
+
/** The kit's could-not-process counts and the paused conversations, as the status file keeps them. */
|
|
242
|
+
private couldNotProcess;
|
|
207
243
|
/**
|
|
208
244
|
* A run that did not get done may be the runtime itself (signed out, the
|
|
209
245
|
* binary gone, a flag an upgrade dropped): checked again, at most once per
|
|
@@ -228,6 +264,12 @@ declare class Integration {
|
|
|
228
264
|
/** Test seam: resolves when a runtime check started by a failed run has finished. */
|
|
229
265
|
runtimeCheckDone(): Promise<void>;
|
|
230
266
|
private onEvent;
|
|
267
|
+
/**
|
|
268
|
+
* One could-not-process report and the server's answer: said in the log
|
|
269
|
+
* (ids and counts only), and a `paused` answer kept for `status` until the
|
|
270
|
+
* pause ends; any other answer for that conversation ends what was kept.
|
|
271
|
+
*/
|
|
272
|
+
private onProcessingFailure;
|
|
231
273
|
private writeStatus;
|
|
232
274
|
}
|
|
233
275
|
|
|
@@ -271,6 +313,14 @@ interface SpawnRunSpec {
|
|
|
271
313
|
readonly signal?: AbortSignal;
|
|
272
314
|
/** Called once when the child process has been spawned (`RunRequest.onStarted`). */
|
|
273
315
|
readonly onStarted?: () => void;
|
|
316
|
+
/**
|
|
317
|
+
* An exit 0 with nothing on stdout is `failed`, not `ok`: for a probe whose
|
|
318
|
+
* answer must be there (a model call that printed nothing did not answer).
|
|
319
|
+
* Still counted, never kept.
|
|
320
|
+
*/
|
|
321
|
+
readonly requireStdout?: boolean;
|
|
322
|
+
/** Test seam: `NOT_STARTED_WITHIN_MS`. */
|
|
323
|
+
readonly notStartedWithinMs?: number;
|
|
274
324
|
}
|
|
275
325
|
/** Strip anything key-shaped or terminal-styled from a diagnostic, and bound it. */
|
|
276
326
|
declare function redactDiagnostic(value: string, max?: number): string;
|
|
@@ -307,7 +357,7 @@ declare function sweepWindowsDescendants(rootPid: number, aliveFromMs: number, a
|
|
|
307
357
|
}): Promise<WindowsSweep | null>;
|
|
308
358
|
/** One line for the log: what a sweep found and did. */
|
|
309
359
|
declare function describeWindowsSweep(sweep: WindowsSweep): string;
|
|
310
|
-
/** Start the command, wait for it, classify. Never throws, and always resolves. */
|
|
360
|
+
/** Start the command, wait for it, classify. Never throws, and always resolves. The output is counted, never kept. */
|
|
311
361
|
declare function spawnRun(spec: SpawnRunSpec): Promise<RunOutcome>;
|
|
312
362
|
|
|
313
|
-
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 };
|
|
363
|
+
export { type DaemonConfig, Integration, type IntegrationOptions, PREFLIGHT_DEADLINE_MS, RUNNER_DEADLINE_SLACK_MS, RUNTIME_CHECK_DEADLINE_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 };
|
package/dist/daemon-entry.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MANUAL,
|
|
3
|
+
PausedConversations,
|
|
3
4
|
acquireAgentLock,
|
|
4
5
|
acquireLeaderLock,
|
|
5
6
|
agentLockPath,
|
|
@@ -16,7 +17,7 @@ import {
|
|
|
16
17
|
standbyWaiting,
|
|
17
18
|
textsCachePath,
|
|
18
19
|
writeIntegrationStatus
|
|
19
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-AQTRC7G4.js";
|
|
20
21
|
import {
|
|
21
22
|
INTEGRATION_ENV,
|
|
22
23
|
INTEGRATION_ENV_LEGACY,
|
|
@@ -31,7 +32,7 @@ import {
|
|
|
31
32
|
resolveRunProfile,
|
|
32
33
|
spawnRun,
|
|
33
34
|
sweepWindowsDescendants
|
|
34
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-5KMQ23O6.js";
|
|
35
36
|
|
|
36
37
|
// src/integration/run.ts
|
|
37
38
|
import * as path2 from "path";
|
|
@@ -111,6 +112,21 @@ var HTTP_TIMEOUT_MS = 1e4;
|
|
|
111
112
|
var RUNNER_DEADLINE_SLACK_MS = 6e4;
|
|
112
113
|
var RUNTIME_RECHECK_MS = 5 * 6e4;
|
|
113
114
|
var PREFLIGHT_DEADLINE_MS = 6e4;
|
|
115
|
+
var RUNTIME_CHECK_DEADLINE_MS = 6e4;
|
|
116
|
+
var NO_PROCESSING_FAILURES = {
|
|
117
|
+
reported: 0,
|
|
118
|
+
retry: 0,
|
|
119
|
+
hidden: 0,
|
|
120
|
+
paused: 0,
|
|
121
|
+
none: 0,
|
|
122
|
+
reportErrors: 0,
|
|
123
|
+
reruns: 0,
|
|
124
|
+
rerunsCapped: 0,
|
|
125
|
+
awaitingEvidence: 0,
|
|
126
|
+
runtimeChecksOk: 0,
|
|
127
|
+
runtimeChecksFailed: 0,
|
|
128
|
+
lastRuntimeCheck: null
|
|
129
|
+
};
|
|
114
130
|
var CYCLE_FAILURE_CHARS = 240;
|
|
115
131
|
function reasonOf(source, frameReason) {
|
|
116
132
|
switch (source) {
|
|
@@ -158,6 +174,7 @@ var Integration = class {
|
|
|
158
174
|
this.options = options;
|
|
159
175
|
const { cfg, client } = options;
|
|
160
176
|
const identity = clientIdentityOf(client);
|
|
177
|
+
this.paused = new PausedConversations(cfg.home, cfg.handle);
|
|
161
178
|
this.api = options.api ?? new AgentChatClient2({ apiKey: cfg.apiKey, baseUrl: cfg.apiBase, clientIdentity: identity, timeoutMs: HTTP_TIMEOUT_MS, retry: { maxRetries: 0, baseDelayMs: 0, maxDelayMs: 0 } });
|
|
162
179
|
this.texts = new kit.TextsCache({
|
|
163
180
|
client: this.api,
|
|
@@ -215,6 +232,12 @@ var Integration = class {
|
|
|
215
232
|
client: this.api,
|
|
216
233
|
// The kit's own switch: off, no invite is dismissed on the agent's behalf.
|
|
217
234
|
...options.dismissIgnoredInvites === false ? { dismissIgnoredInvites: false } : {},
|
|
235
|
+
// One run per conversation whenever the served texts carry the template.
|
|
236
|
+
...options.conversationRuns === false ? { conversationRuns: false } : {},
|
|
237
|
+
// The evidence a could-not-process report needs when no other run has
|
|
238
|
+
// completed since: the runtime's own minimal model call. Without one, a
|
|
239
|
+
// failure waits for another run to complete.
|
|
240
|
+
...options.runner.checkRuntime !== void 0 ? { checkRuntime: () => this.checkRuntime() } : {},
|
|
218
241
|
texts: this.texts,
|
|
219
242
|
mode: "singleRun",
|
|
220
243
|
socket: this.realtime,
|
|
@@ -257,10 +280,16 @@ var Integration = class {
|
|
|
257
280
|
runsNotStarted = 0;
|
|
258
281
|
runsSkippedEmpty = 0;
|
|
259
282
|
lastRun = null;
|
|
283
|
+
/** When the last run that got done ended (`last_ok_run_at`). */
|
|
284
|
+
lastOkRunAt = null;
|
|
260
285
|
/** The newest wake since the last run started (for `RunRequest.wake`). */
|
|
261
286
|
pendingWake = null;
|
|
262
287
|
/** The rung of the newest `unanswered` wake frame (the kit's wake event does not carry it). */
|
|
263
288
|
lastUnansweredStep = null;
|
|
289
|
+
/** The conversations the server paused for this agent, as it answered (kept in the identity home). */
|
|
290
|
+
paused;
|
|
291
|
+
/** The runner's runtime check in flight: concurrent asks share it. */
|
|
292
|
+
runtimeCheckInFlight = null;
|
|
264
293
|
async start() {
|
|
265
294
|
const pre = await withDeadline(this.options.runner.preflight(), PREFLIGHT_DEADLINE_MS, () => ({
|
|
266
295
|
ok: false,
|
|
@@ -350,6 +379,9 @@ var Integration = class {
|
|
|
350
379
|
runs_not_started: this.runsNotStarted,
|
|
351
380
|
runs_skipped_empty: this.runsSkippedEmpty,
|
|
352
381
|
last_run: this.lastRun,
|
|
382
|
+
failed_runs_in_a_row: this.failingRuns,
|
|
383
|
+
last_ok_run_at: this.lastOkRunAt,
|
|
384
|
+
could_not_process: this.couldNotProcess(status),
|
|
353
385
|
// No local retry ladder (the server re-wakes, D3); kept for older readers.
|
|
354
386
|
retry_rung: 0,
|
|
355
387
|
retry_due_at: null,
|
|
@@ -371,18 +403,22 @@ var Integration = class {
|
|
|
371
403
|
}))
|
|
372
404
|
};
|
|
373
405
|
}
|
|
374
|
-
// ───
|
|
406
|
+
// ─── a run ──────────────────────────────────────────────────────────────
|
|
375
407
|
async startRun(request) {
|
|
376
|
-
const
|
|
408
|
+
const conversationId = request.kind === "conversation" && typeof request.conversationId === "string" && request.conversationId.length > 0 ? request.conversationId : void 0;
|
|
409
|
+
const kind = conversationId !== void 0 ? "conversation" : request.kind === "invite" ? "invite" : "wake";
|
|
377
410
|
const wake = this.pendingWake ?? { reason: kind === "invite" ? "invite" : "messages" };
|
|
378
411
|
this.pendingWake = null;
|
|
379
412
|
const runId = crypto.randomUUID();
|
|
380
413
|
const startedAt = Date.now();
|
|
381
414
|
const budgetMs = this.options.budgetMs;
|
|
382
415
|
const slackMs = this.options.runnerDeadlineSlackMs ?? RUNNER_DEADLINE_SLACK_MS;
|
|
416
|
+
const subject = `kind=${kind}${conversationId !== void 0 ? ` conv=${conversationId}` : ""} id=${runId}`;
|
|
383
417
|
this.runsStarted += 1;
|
|
384
418
|
this.writeStatus();
|
|
385
|
-
log.info(
|
|
419
|
+
log.info(
|
|
420
|
+
`run start ${subject} budget=${Math.round(budgetMs / 1e3)}s${kind === "conversation" ? "" : ` (tray: ${request.cards ?? "?"} card(s), ${request.invites ?? "?"} invite(s))`}`
|
|
421
|
+
);
|
|
386
422
|
const controller = new AbortController();
|
|
387
423
|
const onAbort = () => controller.abort();
|
|
388
424
|
if (request.signal.aborted) controller.abort();
|
|
@@ -393,6 +429,7 @@ var Integration = class {
|
|
|
393
429
|
outcome = await withDeadline(
|
|
394
430
|
this.options.runner.start({
|
|
395
431
|
kind,
|
|
432
|
+
...conversationId !== void 0 ? { conversationId } : {},
|
|
396
433
|
wake,
|
|
397
434
|
// No pointer, no trailing blank lines.
|
|
398
435
|
prompt: this.options.manualPointer.trim().length > 0 ? `${request.prompt}
|
|
@@ -420,7 +457,10 @@ ${this.options.manualPointer}` : request.prompt,
|
|
|
420
457
|
request.signal.removeEventListener("abort", onAbort);
|
|
421
458
|
}
|
|
422
459
|
this.lastRun = {
|
|
423
|
-
|
|
460
|
+
// Readers from before conversation runs know only `wake` and `invite`.
|
|
461
|
+
kind: kind === "invite" ? "invite" : "wake",
|
|
462
|
+
run_kind: kind,
|
|
463
|
+
conversation_id: conversationId ?? null,
|
|
424
464
|
started_at: new Date(startedAt).toISOString(),
|
|
425
465
|
ended_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
426
466
|
state: outcome.state,
|
|
@@ -431,7 +471,9 @@ ${this.options.manualPointer}` : request.prompt,
|
|
|
431
471
|
switch (outcome.state) {
|
|
432
472
|
case "ok":
|
|
433
473
|
this.runsOk += 1;
|
|
434
|
-
|
|
474
|
+
this.lastOkRunAt = this.lastRun.ended_at;
|
|
475
|
+
log.info(`run ok ${subject} ${Math.round(outcome.durationMs / 1e3)}s (output discarded; any send was the agent's own hosted-tool call)`);
|
|
476
|
+
if (conversationId !== void 0) this.paused.clear(conversationId);
|
|
435
477
|
break;
|
|
436
478
|
case "failed":
|
|
437
479
|
this.runsFailed += 1;
|
|
@@ -444,11 +486,72 @@ ${this.options.manualPointer}` : request.prompt,
|
|
|
444
486
|
break;
|
|
445
487
|
}
|
|
446
488
|
if (outcome.state !== "ok") {
|
|
447
|
-
log.warn(
|
|
489
|
+
log.warn(
|
|
490
|
+
`run ${outcome.state} ${subject}${outcome.detail ? `: ${outcome.detail}` : ""} \u2014 ${kind !== "conversation" ? "the cards stay on the tray; the next wake (or the server's re-wake) finds them" : outcome.state === "failed" && outcome.silent === true ? "its card stays on the tray; a silent failure counts as a timeout: it is reported (could not process) only once another conversation's run completes, and the server decides what follows" : "its card stays on the tray; if the runtime otherwise works, the failure is reported (could not process) and the server decides what follows"}`
|
|
491
|
+
);
|
|
448
492
|
}
|
|
449
493
|
this.noteRunHealth(outcome, this.lastRun.ended_at);
|
|
450
494
|
this.writeStatus();
|
|
451
|
-
|
|
495
|
+
if (outcome.state === "ok") return { status: "completed" };
|
|
496
|
+
if (outcome.state === "not_started") return { status: "not_started", ...outcome.detail !== void 0 ? { detail: outcome.detail } : {} };
|
|
497
|
+
const timedOut = outcome.state === "timed_out" || outcome.state === "failed" && outcome.silent === true;
|
|
498
|
+
return { status: "failed", ...timedOut ? { timedOut: true } : {}, ...outcome.detail !== void 0 ? { detail: outcome.detail } : {} };
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* The runner's runtime check (a minimal model call, no peer content, no
|
|
502
|
+
* AgentChat tools), bounded by `RUNTIME_CHECK_DEADLINE_MS` and stopped with
|
|
503
|
+
* the integration; concurrent asks share one check. Its output is the
|
|
504
|
+
* runner's to discard: only whether it answered, and a bounded diagnostic,
|
|
505
|
+
* come back.
|
|
506
|
+
*/
|
|
507
|
+
checkRuntime() {
|
|
508
|
+
this.runtimeCheckInFlight ??= this.runRuntimeCheck().finally(() => {
|
|
509
|
+
this.runtimeCheckInFlight = null;
|
|
510
|
+
setTimeout(() => this.writeStatus(), 0).unref?.();
|
|
511
|
+
});
|
|
512
|
+
return this.runtimeCheckInFlight;
|
|
513
|
+
}
|
|
514
|
+
async runRuntimeCheck() {
|
|
515
|
+
const check = this.options.runner.checkRuntime;
|
|
516
|
+
if (check === void 0) return { ok: false, detail: "this runtime has no runtime check" };
|
|
517
|
+
if (this.stopping) return { ok: false, detail: "the integration is stopping" };
|
|
518
|
+
const deadlineMs = this.options.runtimeCheckDeadlineMs ?? RUNTIME_CHECK_DEADLINE_MS;
|
|
519
|
+
const controller = new AbortController();
|
|
520
|
+
const onStop = () => controller.abort();
|
|
521
|
+
this.recheckAbort.signal.addEventListener("abort", onStop, { once: true });
|
|
522
|
+
const startedAt = Date.now();
|
|
523
|
+
try {
|
|
524
|
+
const answer = await withDeadline(check.call(this.options.runner, { signal: controller.signal }), deadlineMs, () => {
|
|
525
|
+
controller.abort();
|
|
526
|
+
return { ok: false, detail: `the runtime check did not answer within ${Math.round(deadlineMs / 1e3)} s (stopped)` };
|
|
527
|
+
}).catch((err) => ({ ok: false, detail: `the runtime check threw: ${err instanceof Error ? err.message : String(err)}` }));
|
|
528
|
+
const took = `${Math.round((Date.now() - startedAt) / 1e3)} s`;
|
|
529
|
+
if (answer.ok) log.info(`runtime check ok (${this.options.runner.name}: the model answered, ${took}; output discarded)`);
|
|
530
|
+
else if (!this.stopping) log.warn(`runtime check failed (${this.options.runner.name}, ${took}): ${answer.detail ?? "no detail"} \u2014 a failed run is not reported as this conversation's`);
|
|
531
|
+
return answer.ok ? { ok: true } : { ok: false, ...answer.detail !== void 0 ? { detail: answer.detail } : {} };
|
|
532
|
+
} finally {
|
|
533
|
+
this.recheckAbort.signal.removeEventListener("abort", onStop);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
/** The kit's could-not-process counts and the paused conversations, as the status file keeps them. */
|
|
537
|
+
couldNotProcess(status) {
|
|
538
|
+
const f = status.processingFailures ?? NO_PROCESSING_FAILURES;
|
|
539
|
+
return {
|
|
540
|
+
runtime_check: this.options.runner.checkRuntime !== void 0,
|
|
541
|
+
reported: f.reported,
|
|
542
|
+
retry: f.retry,
|
|
543
|
+
hidden: f.hidden,
|
|
544
|
+
paused: f.paused,
|
|
545
|
+
none: f.none,
|
|
546
|
+
report_errors: f.reportErrors,
|
|
547
|
+
reruns: f.reruns,
|
|
548
|
+
reruns_capped: f.rerunsCapped,
|
|
549
|
+
awaiting_evidence: f.awaitingEvidence,
|
|
550
|
+
runtime_checks_ok: f.runtimeChecksOk,
|
|
551
|
+
runtime_checks_failed: f.runtimeChecksFailed,
|
|
552
|
+
last_runtime_check: f.lastRuntimeCheck === null ? null : { at: f.lastRuntimeCheck.at, ok: f.lastRuntimeCheck.ok, detail: f.lastRuntimeCheck.detail?.slice(0, CYCLE_FAILURE_CHARS) ?? null },
|
|
553
|
+
paused_conversations: this.paused.list()
|
|
554
|
+
};
|
|
452
555
|
}
|
|
453
556
|
/**
|
|
454
557
|
* A run that did not get done may be the runtime itself (signed out, the
|
|
@@ -526,19 +629,31 @@ ${this.options.manualPointer}` : request.prompt,
|
|
|
526
629
|
log.debug(`own echo${event.conversationId ? ` in ${event.conversationId}` : ""} \u2014 not a wake`);
|
|
527
630
|
break;
|
|
528
631
|
case "cycle": {
|
|
529
|
-
const { outcome, cards, invites } = event.summary;
|
|
530
|
-
if (outcome === "
|
|
632
|
+
const { outcome, cards, invites, heldByTurns, paced } = event.summary;
|
|
633
|
+
if (outcome === "nothing_owed" && (heldByTurns > 0 || paced > 0)) {
|
|
634
|
+
log.info(
|
|
635
|
+
`wake: nothing new to start \u2014 ${heldByTurns} conversation(s) already running or waiting${paced > 0 ? `, ${paced} paced after a recent run` : ""} (${cards} card(s), ${invites} invite(s))`
|
|
636
|
+
);
|
|
637
|
+
} else if (outcome === "empty" || outcome === "nothing_owed") {
|
|
531
638
|
this.runsSkippedEmpty += 1;
|
|
532
|
-
log.info(`wake: ${outcome === "empty" ? "the tray is empty" : "nothing owed (muted
|
|
639
|
+
log.info(`wake: ${outcome === "empty" ? "the tray is empty" : "nothing owed (muted or notices-only cards)"} \u2014 no run (${cards} card(s), ${invites} invite(s))`);
|
|
533
640
|
} else if (outcome === "abandoned") {
|
|
534
641
|
log.warn(`wake cycle abandoned by the watchdog: ${event.summary.failure ?? "it ran past its deadline"} \u2014 the next wake starts a new one`);
|
|
535
642
|
} else if (outcome === "texts_missing") {
|
|
536
643
|
this.runsNotStarted += 1;
|
|
537
644
|
log.warn("no served texts in hand: GET /v1/texts has not answered yet and nothing is cached in the identity home \u2014 no run this time");
|
|
645
|
+
} else if (outcome === "runs_started") {
|
|
646
|
+
const { turnsStarted, turnsQueued } = event.summary;
|
|
647
|
+
log.info(
|
|
648
|
+
`wake: ${turnsStarted + turnsQueued} run(s) for ${cards} card(s), ${invites} invite(s) \u2014 ${turnsStarted} started, ${turnsQueued} queued (one at a time)${heldByTurns > 0 ? `; ${heldByTurns} conversation(s) already running or waiting` : ""}${paced > 0 ? `; ${paced} paced` : ""}`
|
|
649
|
+
);
|
|
538
650
|
}
|
|
539
651
|
this.writeStatus();
|
|
540
652
|
break;
|
|
541
653
|
}
|
|
654
|
+
case "processing_failure":
|
|
655
|
+
this.onProcessingFailure(event);
|
|
656
|
+
break;
|
|
542
657
|
case "error":
|
|
543
658
|
if (!this.stopping) log.warn(`receive loop: ${event.error.message}`);
|
|
544
659
|
break;
|
|
@@ -546,6 +661,26 @@ ${this.options.manualPointer}` : request.prompt,
|
|
|
546
661
|
break;
|
|
547
662
|
}
|
|
548
663
|
}
|
|
664
|
+
/**
|
|
665
|
+
* One could-not-process report and the server's answer: said in the log
|
|
666
|
+
* (ids and counts only), and a `paused` answer kept for `status` until the
|
|
667
|
+
* pause ends; any other answer for that conversation ends what was kept.
|
|
668
|
+
*/
|
|
669
|
+
onProcessingFailure(event) {
|
|
670
|
+
const what = `conv=${event.conversationId} (${event.source} ${event.outcome}, evidence ${event.evidence === "runtime_check" ? "runtime check passed" : "another run completed"})`;
|
|
671
|
+
const result = event.result;
|
|
672
|
+
if (result === null) {
|
|
673
|
+
log.warn(`could not process: ${what} \u2014 the report failed (${event.error ?? "no detail"}); nothing more is done for it now: its card stays on the tray and the server re-wakes it`);
|
|
674
|
+
} else {
|
|
675
|
+
const hidden = result.hidden_count ?? result.hidden_message_ids.length;
|
|
676
|
+
const answered = result.action === "retry" ? "retry (the first failure for these messages)" : result.action === "hidden" ? `hidden (${hidden} message(s) are now a note for this agent, still unread)` : result.action === "paused" ? `paused until ${result.paused_until ?? "?"}${hidden > 0 ? ` (${hidden} more message(s) hidden)` : ""} \u2014 no run starts there until then` : "none (nothing left to act on)";
|
|
677
|
+
const next = event.next === "rerun" ? "it runs again after the others" : event.next === "running" ? "its next run is under way already" : event.next === "rerun_capped" ? "not run again in this cycle (3 re-runs already); the server re-wakes it" : "nothing more for it";
|
|
678
|
+
(result.action === "paused" ? log.warn : log.info)(`could not process: ${what} \u2192 server: ${answered}; ${next}`);
|
|
679
|
+
if (result.action === "paused" && result.paused_until !== null) this.paused.record(event.conversationId, result.paused_until);
|
|
680
|
+
else this.paused.clear(event.conversationId);
|
|
681
|
+
}
|
|
682
|
+
this.writeStatus();
|
|
683
|
+
}
|
|
549
684
|
writeStatus() {
|
|
550
685
|
writeIntegrationStatus(this.options.cfg.home, this.snapshot());
|
|
551
686
|
}
|
|
@@ -842,6 +977,7 @@ async function runIntegration(opts) {
|
|
|
842
977
|
profile,
|
|
843
978
|
budgetMs,
|
|
844
979
|
...opts.dismissIgnoredInvites !== void 0 ? { dismissIgnoredInvites: opts.dismissIgnoredInvites } : {},
|
|
980
|
+
...opts.conversationRuns !== void 0 ? { conversationRuns: opts.conversationRuns } : {},
|
|
845
981
|
...opts.runtimeRecheckMs !== void 0 ? { runtimeRecheckMs: opts.runtimeRecheckMs } : {},
|
|
846
982
|
...opts.quietMs !== void 0 ? { quietMs: opts.quietMs } : {},
|
|
847
983
|
...opts.maxMs !== void 0 ? { maxMs: opts.maxMs } : {},
|
|
@@ -910,6 +1046,7 @@ export {
|
|
|
910
1046
|
Integration,
|
|
911
1047
|
PREFLIGHT_DEADLINE_MS,
|
|
912
1048
|
RUNNER_DEADLINE_SLACK_MS,
|
|
1049
|
+
RUNTIME_CHECK_DEADLINE_MS,
|
|
913
1050
|
WINDOWS_SWEEP_TIMEOUT_MS,
|
|
914
1051
|
blockedDetail,
|
|
915
1052
|
describeWindowsSweep,
|