@agentchatme/agent-core 0.6.0 → 0.7.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.
@@ -2,10 +2,10 @@ import {
2
2
  clientIdentityOf,
3
3
  killProcessTree,
4
4
  spawnCommand
5
- } from "./chunk-AVLI55C5.js";
5
+ } from "./chunk-C2ARQLZ7.js";
6
6
 
7
7
  // src/version.ts
8
- var VERSION = "0.6.0";
8
+ var VERSION = "0.7.0";
9
9
 
10
10
  // src/integration/mcp-probe.ts
11
11
  import { integration as kit } from "agentchatme";
@@ -94,4 +94,4 @@ export {
94
94
  PROBE_KILL_WAIT_MS,
95
95
  runProbe
96
96
  };
97
- //# sourceMappingURL=chunk-QUANHUVW.js.map
97
+ //# sourceMappingURL=chunk-PTKQIKCI.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/version.ts","../src/integration/mcp-probe.ts","../src/util/probe.ts"],"sourcesContent":["/** Published package version, kept in lockstep with package.json by tests. */\nexport const VERSION = '0.6.0'\n","import { integration as kit } from 'agentchatme'\nimport { clientIdentityOf, type IntegrationClient } from '../client-identity.js'\n\n// ─── Can this key reach the hosted tools? ───────────────────────────────────\n//\n// `status` and `doctor` ask the SDK kit's `probeHostedTools`: one MCP\n// `initialize` over Streamable HTTP with the bearer key — the same first\n// request a runtime makes on connect — then `tools/list`, which must show the\n// tools a run needs (`agentchat_inbox`, `agentchat_decide`). A 401 means the\n// key does not authenticate; a transport error means the endpoint is not\n// reachable from here. No tool is called.\n\nexport const HOSTED_MCP_PATH = kit.HOSTED_MCP_PATH\n\nexport function hostedMcpUrl(apiBase: string): string {\n return kit.hostedMcpUrl(apiBase)\n}\n\nexport interface McpProbeResult {\n readonly ok: boolean\n readonly status?: number\n readonly serverName?: string\n readonly serverVersion?: string\n readonly protocolVersion?: string\n /** Every tool the server listed for this key. */\n readonly tools?: readonly string[]\n /** Tools a run needs that were not listed. */\n readonly missing?: readonly string[]\n readonly error?: string\n}\n\nexport async function probeHostedMcp(params: {\n apiKey: string\n apiBase: string\n /** How this integration identifies to the server. */\n client: IntegrationClient\n /**\n * Accepted for compatibility and ignored: the probe identifies as `client`\n * (headers and `clientInfo` alike), so the server's analytics see the\n * integration, never a free-text name it would file as unknown.\n */\n clientName?: string\n /** Accepted for compatibility and ignored (see `clientName`). */\n clientVersion?: string\n timeoutMs?: number\n fetch?: typeof fetch\n}): Promise<McpProbeResult> {\n return kit.probeHostedTools({\n apiBase: params.apiBase,\n apiKey: params.apiKey,\n clientIdentity: clientIdentityOf(params.client),\n ...(params.timeoutMs !== undefined ? { timeoutMs: params.timeoutMs } : {}),\n ...(params.fetch !== undefined ? { fetch: params.fetch } : {}),\n })\n}\n","import { killProcessTree } from '../integration/spawn-run.js'\nimport { spawnCommand } from './spawn.js'\n\n// ─── A short command whose answer we need (`--version`, a sign-in check) ────\n//\n// Was `spawnSync` with a timeout, which on timeout kills only the direct child:\n// on Windows the npm `.cmd` shim (the real process under it keeps running), and\n// the npm launcher of a runtime that starts its native binary as a child. A sync\n// spawn then also waits for those survivors to close the output pipes it reads —\n// blocking the whole daemon, socket included. A probe is therefore async: on\n// timeout the whole tree is killed (its process group on POSIX, `taskkill /T /F`\n// on Windows), its exit is waited for, and a tree that will not die is given up\n// on after a bound — the probe always answers.\n\nexport interface ProbeResult {\n /** Why it did not answer: it could not be started, or it timed out. */\n readonly error?: Error\n readonly status: number | null\n readonly stdout: string\n readonly stderr: string\n readonly timedOut: boolean\n}\n\nexport interface ProbeOptions {\n readonly env?: NodeJS.ProcessEnv\n readonly timeoutMs: number\n readonly cwd?: string\n /** Aborting it stops the probe as a timeout would (its tree killed, its exit waited for). */\n readonly signal?: AbortSignal\n}\n\n/** After a probe is killed: how long its exit is waited for before it is given up on. */\nexport const PROBE_KILL_WAIT_MS = 5_000\nconst MAX_OUTPUT = 64 * 1024\n\nexport function runProbe(command: string, args: readonly string[], options: ProbeOptions): Promise<ProbeResult> {\n return new Promise((resolve) => {\n let child: ReturnType<typeof spawnCommand>\n try {\n child = spawnCommand(command, [...args], {\n ...(options.env !== undefined ? { env: options.env } : {}),\n ...(options.cwd !== undefined ? { cwd: options.cwd } : {}),\n stdio: ['ignore', 'pipe', 'pipe'],\n // Its own process group on POSIX, so the whole tree can be killed.\n detached: process.platform !== 'win32',\n windowsHide: true,\n })\n } catch (err) {\n resolve({ error: err instanceof Error ? err : new Error(String(err)), status: null, stdout: '', stderr: '', timedOut: false })\n return\n }\n const proc = child\n let stdout = ''\n let stderr = ''\n let timedOut = false\n let stopped = false\n let finished = false\n let giveUp: NodeJS.Timeout | null = null\n const finish = (result: ProbeResult): void => {\n if (finished) return\n finished = true\n clearTimeout(timer)\n if (giveUp !== null) clearTimeout(giveUp)\n resolve(result)\n }\n proc.stdout?.on('data', (chunk: Buffer) => {\n if (stdout.length < MAX_OUTPUT) stdout += chunk.toString('utf-8')\n })\n proc.stderr?.on('data', (chunk: Buffer) => {\n if (stderr.length < MAX_OUTPUT) stderr += chunk.toString('utf-8')\n })\n const stop = (error: Error, byTimeout: boolean): void => {\n if (timedOut || finished) return\n timedOut = byTimeout\n stopped = true\n killProcessTree(proc, 'SIGKILL')\n // Its exit (every pipe closed) is the answer; a tree that will not die is given up on.\n giveUp = setTimeout(() => {\n proc.stdout?.destroy()\n proc.stderr?.destroy()\n finish({ error, status: null, stdout, stderr, timedOut })\n }, PROBE_KILL_WAIT_MS)\n proc.once('close', () => finish({ error, status: null, stdout, stderr, timedOut }))\n }\n const timer = setTimeout(() => stop(new Error(`${command} ${args.join(' ')} did not answer within ${Math.round(options.timeoutMs / 1000)} s`), true), options.timeoutMs)\n const onAbort = (): void => stop(new Error(`${command} ${args.join(' ')} was stopped`), false)\n if (options.signal?.aborted) onAbort()\n else options.signal?.addEventListener('abort', onAbort, { once: true })\n proc.on('error', (err) => finish({ error: err, status: null, stdout, stderr, timedOut }))\n proc.on('close', (code) => {\n options.signal?.removeEventListener('abort', onAbort)\n if (!stopped) finish({ status: code, stdout,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AAO,KAAK,QAAQ,MAAM,QAAQ,QAAQ,SAAS,CAAC,CAAC;AACxF,SAAK,GAAG,SAAS,CAAC,SAAS;AACzB,cAAQ,QAAQ,oBAAoB,SAAS,OAAO;AACpD,UAAI,CAAC,QAAS,QAAO,EAAE,QAAQ,MAAM,QAAQ,QAAQ,SAAS,CAAC;AAAA,IACjE,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../src/version.ts","../src/integration/mcp-probe.ts","../src/util/probe.ts"],"sourcesContent":["/** Published package version, kept in lockstep with package.json by tests. */\nexport const VERSION = '0.7.0'\n","import { integration as kit } from 'agentchatme'\nimport { clientIdentityOf, type IntegrationClient } from '../client-identity.js'\n\n// ─── Can this key reach the hosted tools? ───────────────────────────────────\n//\n// `status` and `doctor` ask the SDK kit's `probeHostedTools`: one MCP\n// `initialize` over Streamable HTTP with the bearer key — the same first\n// request a runtime makes on connect — then `tools/list`, which must show the\n// tools a run needs (`agentchat_inbox`, `agentchat_decide`). A 401 means the\n// key does not authenticate; a transport error means the endpoint is not\n// reachable from here. No tool is called.\n\nexport const HOSTED_MCP_PATH = kit.HOSTED_MCP_PATH\n\nexport function hostedMcpUrl(apiBase: string): string {\n return kit.hostedMcpUrl(apiBase)\n}\n\nexport interface McpProbeResult {\n readonly ok: boolean\n readonly status?: number\n readonly serverName?: string\n readonly serverVersion?: string\n readonly protocolVersion?: string\n /** Every tool the server listed for this key. */\n readonly tools?: readonly string[]\n /** Tools a run needs that were not listed. */\n readonly missing?: readonly string[]\n readonly error?: string\n}\n\nexport async function probeHostedMcp(params: {\n apiKey: string\n apiBase: string\n /** How this integration identifies to the server. */\n client: IntegrationClient\n /**\n * Accepted for compatibility and ignored: the probe identifies as `client`\n * (headers and `clientInfo` alike), so the server's analytics see the\n * integration, never a free-text name it would file as unknown.\n */\n clientName?: string\n /** Accepted for compatibility and ignored (see `clientName`). */\n clientVersion?: string\n timeoutMs?: number\n fetch?: typeof fetch\n}): Promise<McpProbeResult> {\n return kit.probeHostedTools({\n apiBase: params.apiBase,\n apiKey: params.apiKey,\n clientIdentity: clientIdentityOf(params.client),\n ...(params.timeoutMs !== undefined ? { timeoutMs: params.timeoutMs } : {}),\n ...(params.fetch !== undefined ? { fetch: params.fetch } : {}),\n })\n}\n","import { killProcessTree } from '../integration/spawn-run.js'\nimport { spawnCommand } from './spawn.js'\n\n// ─── A short command whose answer we need (`--version`, a sign-in check) ────\n//\n// Was `spawnSync` with a timeout, which on timeout kills only the direct child:\n// on Windows the npm `.cmd` shim (the real process under it keeps running), and\n// the npm launcher of a runtime that starts its native binary as a child. A sync\n// spawn then also waits for those survivors to close the output pipes it reads —\n// blocking the whole daemon, socket included. A probe is therefore async: on\n// timeout the whole tree is killed (its process group on POSIX, `taskkill /T /F`\n// on Windows), its exit is waited for, and a tree that will not die is given up\n// on after a bound — the probe always answers.\n\nexport interface ProbeResult {\n /** Why it did not answer: it could not be started, or it timed out. */\n readonly error?: Error\n readonly status: number | null\n readonly stdout: string\n readonly stderr: string\n readonly timedOut: boolean\n}\n\nexport interface ProbeOptions {\n readonly env?: NodeJS.ProcessEnv\n readonly timeoutMs: number\n readonly cwd?: string\n /** Aborting it stops the probe as a timeout would (its tree killed, its exit waited for). */\n readonly signal?: AbortSignal\n}\n\n/** After a probe is killed: how long its exit is waited for before it is given up on. */\nexport const PROBE_KILL_WAIT_MS = 5_000\nconst MAX_OUTPUT = 64 * 1024\n\nexport function runProbe(command: string, args: readonly string[], options: ProbeOptions): Promise<ProbeResult> {\n return new Promise((resolve) => {\n let child: ReturnType<typeof spawnCommand>\n try {\n child = spawnCommand(command, [...args], {\n ...(options.env !== undefined ? { env: options.env } : {}),\n ...(options.cwd !== undefined ? { cwd: options.cwd } : {}),\n stdio: ['ignore', 'pipe', 'pipe'],\n // Its own process group on POSIX, so the whole tree can be killed.\n detached: process.platform !== 'win32',\n windowsHide: true,\n })\n } catch (err) {\n resolve({ error: err instanceof Error ? err : new Error(String(err)), status: null, stdout: '', stderr: '', timedOut: false })\n return\n }\n const proc = child\n let stdout = ''\n let stderr = ''\n let timedOut = false\n let stopped = false\n let finished = false\n let giveUp: NodeJS.Timeout | null = null\n const finish = (result: ProbeResult): void => {\n if (finished) return\n finished = true\n clearTimeout(timer)\n if (giveUp !== null) clearTimeout(giveUp)\n resolve(result)\n }\n proc.stdout?.on('data', (chunk: Buffer) => {\n if (stdout.length < MAX_OUTPUT) stdout += chunk.toString('utf-8')\n })\n proc.stderr?.on('data', (chunk: Buffer) => {\n if (stderr.length < MAX_OUTPUT) stderr += chunk.toString('utf-8')\n })\n const stop = (error: Error, byTimeout: boolean): void => {\n if (timedOut || finished) return\n timedOut = byTimeout\n stopped = true\n killProcessTree(proc, 'SIGKILL')\n // Its exit (every pipe closed) is the answer; a tree that will not die is given up on.\n giveUp = setTimeout(() => {\n proc.stdout?.destroy()\n proc.stderr?.destroy()\n finish({ error, status: null, stdout, stderr, timedOut })\n }, PROBE_KILL_WAIT_MS)\n proc.once('close', () => finish({ error, status: null, stdout, stderr, timedOut }))\n }\n const timer = setTimeout(() => stop(new Error(`${command} ${args.join(' ')} did not answer within ${Math.round(options.timeoutMs / 1000)} s`), true), options.timeoutMs)\n const onAbort = (): void => stop(new Error(`${command} ${args.join(' ')} was stopped`), false)\n if (options.signal?.aborted) onAbort()\n else options.signal?.addEventListener('abort', onAbort, { once: true })\n proc.on('error', (err) => finish({ error: err, status: null, stdout, stderr, timedOut }))\n proc.on('close', (code) => {\n options.signal?.removeEventListener('abort', onAbort)\n if (!stopped) finish({ status: code, stdout, stderr, timedOut })\n })\n })\n}\n"],"mappings":";;;;;;;AACO,IAAM,UAAU;;;ACDvB,SAAS,eAAe,WAAW;AAY5B,IAAM,kBAAkB,IAAI;AAE5B,SAAS,aAAa,SAAyB;AACpD,SAAO,IAAI,aAAa,OAAO;AACjC;AAeA,eAAsB,eAAe,QAeT;AAC1B,SAAO,IAAI,iBAAiB;AAAA,IAC1B,SAAS,OAAO;AAAA,IAChB,Q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+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-CawJYdzJ.js';
2
- import { R as RunnerSource, a as RunProfile, b as RunRunner, c as RunOutcome } from './runner-C9kZD3KH.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-C9kZD3KH.js';
1
+ import { I as IntegrationClient, L as LeaseOptions, M as ManualFetch, a as IntegrationStatus, b as IntegrationRunsFailing, S as SocketState } from './served-manual-RAIaRcr2.js';
2
+ import { R as RunnerSource, a as RunProfile, b as RunRunner, c as RunOutcome } from './runner-BjCgl4bV.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-BjCgl4bV.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 };
@@ -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-EDB33Z22.js";
20
+ } from "./chunk-NYSMAN4N.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-AVLI55C5.js";
35
+ } from "./chunk-C2ARQLZ7.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
- // ─── the one run ────────────────────────────────────────────────────────
406
+ // ─── a run ──────────────────────────────────────────────────────────────
375
407
  async startRun(request) {
376
- const kind = request.cards === 0 && (request.invites ?? 0) > 0 ? "invite" : "wake";
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(`run start kind=${kind} id=${runId} budget=${Math.round(budgetMs / 1e3)}s (tray: ${request.cards ?? "?"} card(s), ${request.invites ?? "?"} invite(s))`);
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
- kind,
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
- log.info(`run ok kind=${kind} id=${runId} ${Math.round(outcome.durationMs / 1e3)}s (output discarded; any send was the agent's own hosted-tool call)`);
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,71 @@ ${this.options.manualPointer}` : request.prompt,
444
486
  break;
445
487
  }
446
488
  if (outcome.state !== "ok") {
447
- log.warn(`run ${outcome.state} kind=${kind} id=${runId}${outcome.detail ? `: ${outcome.detail}` : ""} \u2014 the cards stay on the tray; the next wake (or the server's re-wake) finds them`);
489
+ log.warn(
490
+ `run ${outcome.state} ${subject}${outcome.detail ? `: ${outcome.detail}` : ""} \u2014 ${kind === "conversation" ? "its card stays on the tray; if the runtime otherwise works, the failure is reported (could not process) and the server decides what follows" : "the cards stay on the tray; the next wake (or the server's re-wake) finds them"}`
491
+ );
448
492
  }
449
493
  this.noteRunHealth(outcome, this.lastRun.ended_at);
450
494
  this.writeStatus();
451
- return outcome.state === "ok" ? { status: "completed" } : { status: outcome.state === "not_started" ? "not_started" : "failed", ...outcome.detail !== void 0 ? { detail: outcome.detail } : {} };
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
+ return { status: "failed", ...outcome.state === "timed_out" ? { timedOut: true } : {}, ...outcome.detail !== void 0 ? { detail: outcome.detail } : {} };
498
+ }
499
+ /**
500
+ * The runner's runtime check (a minimal model call, no peer content, no
501
+ * AgentChat tools), bounded by `RUNTIME_CHECK_DEADLINE_MS` and stopped with
502
+ * the integration; concurrent asks share one check. Its output is the
503
+ * runner's to discard: only whether it answered, and a bounded diagnostic,
504
+ * come back.
505
+ */
506
+ checkRuntime() {
507
+ this.runtimeCheckInFlight ??= this.runRuntimeCheck().finally(() => {
508
+ this.runtimeCheckInFlight = null;
509
+ setTimeout(() => this.writeStatus(), 0).unref?.();
510
+ });
511
+ return this.runtimeCheckInFlight;
512
+ }
513
+ async runRuntimeCheck() {
514
+ const check = this.options.runner.checkRuntime;
515
+ if (check === void 0) return { ok: false, detail: "this runtime has no runtime check" };
516
+ if (this.stopping) return { ok: false, detail: "the integration is stopping" };
517
+ const deadlineMs = this.options.runtimeCheckDeadlineMs ?? RUNTIME_CHECK_DEADLINE_MS;
518
+ const controller = new AbortController();
519
+ const onStop = () => controller.abort();
520
+ this.recheckAbort.signal.addEventListener("abort", onStop, { once: true });
521
+ const startedAt = Date.now();
522
+ try {
523
+ const answer = await withDeadline(check.call(this.options.runner, { signal: controller.signal }), deadlineMs, () => {
524
+ controller.abort();
525
+ return { ok: false, detail: `the runtime check did not answer within ${Math.round(deadlineMs / 1e3)} s (stopped)` };
526
+ }).catch((err) => ({ ok: false, detail: `the runtime check threw: ${err instanceof Error ? err.message : String(err)}` }));
527
+ const took = `${Math.round((Date.now() - startedAt) / 1e3)} s`;
528
+ if (answer.ok) log.info(`runtime check ok (${this.options.runner.name}: the model answered, ${took}; output discarded)`);
529
+ 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`);
530
+ return answer.ok ? { ok: true } : { ok: false, ...answer.detail !== void 0 ? { detail: answer.detail } : {} };
531
+ } finally {
532
+ this.recheckAbort.signal.removeEventListener("abort", onStop);
533
+ }
534
+ }
535
+ /** The kit's could-not-process counts and the paused conversations, as the status file keeps them. */
536
+ couldNotProcess(status) {
537
+ const f = status.processingFailures ?? NO_PROCESSING_FAILURES;
538
+ return {
539
+ runtime_check: this.options.runner.checkRuntime !== void 0,
540
+ reported: f.reported,
541
+ retry: f.retry,
542
+ hidden: f.hidden,
543
+ paused: f.paused,
544
+ none: f.none,
545
+ report_errors: f.reportErrors,
546
+ reruns: f.reruns,
547
+ reruns_capped: f.rerunsCapped,
548
+ awaiting_evidence: f.awaitingEvidence,
549
+ runtime_checks_ok: f.runtimeChecksOk,
550
+ runtime_checks_failed: f.runtimeChecksFailed,
551
+ 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 },
552
+ paused_conversations: this.paused.list()
553
+ };
452
554
  }
453
555
  /**
454
556
  * A run that did not get done may be the runtime itself (signed out, the
@@ -526,19 +628,31 @@ ${this.options.manualPointer}` : request.prompt,
526
628
  log.debug(`own echo${event.conversationId ? ` in ${event.conversationId}` : ""} \u2014 not a wake`);
527
629
  break;
528
630
  case "cycle": {
529
- const { outcome, cards, invites } = event.summary;
530
- if (outcome === "empty" || outcome === "nothing_owed") {
631
+ const { outcome, cards, invites, heldByTurns, paced } = event.summary;
632
+ if (outcome === "nothing_owed" && (heldByTurns > 0 || paced > 0)) {
633
+ log.info(
634
+ `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))`
635
+ );
636
+ } else if (outcome === "empty" || outcome === "nothing_owed") {
531
637
  this.runsSkippedEmpty += 1;
532
- log.info(`wake: ${outcome === "empty" ? "the tray is empty" : "nothing owed (muted cards only)"} \u2014 no run (${cards} card(s), ${invites} invite(s))`);
638
+ 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
639
  } else if (outcome === "abandoned") {
534
640
  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
641
  } else if (outcome === "texts_missing") {
536
642
  this.runsNotStarted += 1;
537
643
  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");
644
+ } else if (outcome === "runs_started") {
645
+ const { turnsStarted, turnsQueued } = event.summary;
646
+ log.info(
647
+ `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` : ""}`
648
+ );
538
649
  }
539
650
  this.writeStatus();
540
651
  break;
541
652
  }
653
+ case "processing_failure":
654
+ this.onProcessingFailure(event);
655
+ break;
542
656
  case "error":
543
657
  if (!this.stopping) log.warn(`receive loop: ${event.error.message}`);
544
658
  break;
@@ -546,6 +660,26 @@ ${this.options.manualPointer}` : request.prompt,
546
660
  break;
547
661
  }
548
662
  }
663
+ /**
664
+ * One could-not-process report and the server's answer: said in the log
665
+ * (ids and counts only), and a `paused` answer kept for `status` until the
666
+ * pause ends; any other answer for that conversation ends what was kept.
667
+ */
668
+ onProcessingFailure(event) {
669
+ const what = `conv=${event.conversationId} (${event.source} ${event.outcome}, evidence ${event.evidence === "runtime_check" ? "runtime check passed" : "another run completed"})`;
670
+ const result = event.result;
671
+ if (result === null) {
672
+ 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`);
673
+ } else {
674
+ const hidden = result.hidden_message_ids.length;
675
+ 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)";
676
+ 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";
677
+ (result.action === "paused" ? log.warn : log.info)(`could not process: ${what} \u2192 server: ${answered}; ${next}`);
678
+ if (result.action === "paused" && result.paused_until !== null) this.paused.record(event.conversationId, result.paused_until);
679
+ else this.paused.clear(event.conversationId);
680
+ }
681
+ this.writeStatus();
682
+ }
549
683
  writeStatus() {
550
684
  writeIntegrationStatus(this.options.cfg.home, this.snapshot());
551
685
  }
@@ -842,6 +976,7 @@ async function runIntegration(opts) {
842
976
  profile,
843
977
  budgetMs,
844
978
  ...opts.dismissIgnoredInvites !== void 0 ? { dismissIgnoredInvites: opts.dismissIgnoredInvites } : {},
979
+ ...opts.conversationRuns !== void 0 ? { conversationRuns: opts.conversationRuns } : {},
845
980
  ...opts.runtimeRecheckMs !== void 0 ? { runtimeRecheckMs: opts.runtimeRecheckMs } : {},
846
981
  ...opts.quietMs !== void 0 ? { quietMs: opts.quietMs } : {},
847
982
  ...opts.maxMs !== void 0 ? { maxMs: opts.maxMs } : {},
@@ -910,6 +1045,7 @@ export {
910
1045
  Integration,
911
1046
  PREFLIGHT_DEADLINE_MS,
912
1047
  RUNNER_DEADLINE_SLACK_MS,
1048
+ RUNTIME_CHECK_DEADLINE_MS,
913
1049
  WINDOWS_SWEEP_TIMEOUT_MS,
914
1050
  blockedDetail,
915
1051
  describeWindowsSweep,