@agentchatme/agent-core 0.4.1 → 0.5.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.
@@ -1,6 +1,91 @@
1
1
  import { TextsRuntime, AgentChatClientIdentity, integration } from 'agentchatme';
2
2
  import { z } from 'zod';
3
3
 
4
+ declare const LEASE_RENEW_MS = 10000;
5
+ declare const LEASE_STALE_MS = 45000;
6
+ /** Who holds a lease, as its file says. */
7
+ interface LeaseHolder {
8
+ readonly pid: number;
9
+ /** Null in a lock written before leases (a bare pid). */
10
+ readonly token: string | null;
11
+ readonly host: string | null;
12
+ readonly home?: string;
13
+ readonly label?: string;
14
+ readonly acquired_at?: string;
15
+ /** The holder's wall clock at its last renewal (informational: staleness is observed, not computed from it); null before leases. */
16
+ readonly renewed_at: number | null;
17
+ }
18
+ interface Lease {
19
+ readonly path: string;
20
+ /** True once the lease is no longer this process's (replaced, removed, unrenewable, or released). */
21
+ readonly lost: boolean;
22
+ /** Renewals that failed (an error writing or reading the file), and the last one's message. */
23
+ readonly renewErrors: number;
24
+ readonly lastRenewError: string | null;
25
+ /** Called once, when the lease is no longer this process's (not on `release`). */
26
+ onLost(listener: (why: string) => void): void;
27
+ /** Give the lease up (stop renewing; remove the file if it is still ours). Idempotent; never throws. */
28
+ release(): void;
29
+ }
30
+ type LeaseAttempt = {
31
+ readonly ok: true;
32
+ readonly lease: Lease;
33
+ } | {
34
+ readonly ok: false;
35
+ readonly path: string;
36
+ readonly holder: LeaseHolder | null;
37
+ };
38
+ interface LeaseOptions {
39
+ readonly renewMs?: number;
40
+ readonly staleMs?: number;
41
+ /** Test seam: the wall clock (for `renewed_at` and file ages). */
42
+ readonly now?: () => number;
43
+ /** Test seam: the monotonic clock (ms) staleness is observed on. Defaults to `performance.now()` (on macOS it runs on through sleep; hence the second look). */
44
+ readonly monotonic?: () => number;
45
+ /** Test seam: when this machine booted (epoch ms). */
46
+ readonly bootedAt?: () => number;
47
+ /**
48
+ * Keep observing a held lease for up to this long before refusing (default
49
+ * 0: one look). A holder seen renewing in that time is there: refused at once.
50
+ */
51
+ readonly observeMs?: number;
52
+ /** Stops the waits (observing, confirming): the attempt is refused. */
53
+ readonly signal?: AbortSignal;
54
+ }
55
+ /** When this machine booted (epoch ms): now minus its uptime. */
56
+ declare function bootedAt(now?: number): number;
57
+ /** Whether a pid names a live process (signal 0; EPERM means it exists under another user). */
58
+ declare function pidAlive(pid: number): boolean;
59
+ /** A lease file's holder: `<pid>\n{json}`, or a bare pid (a lock from before leases); null when it says neither. */
60
+ declare function parseLease(raw: string): LeaseHolder | null;
61
+ /**
62
+ * A one-look judgement (no history): for naming a holder and for the service
63
+ * reinstall, which stops the daemon a lock names only when it is really there.
64
+ * A dead pid on this host is gone; a lock from before leases is judged by its
65
+ * pid and the boot; a lease by a renewal within `staleMs` of this wall clock.
66
+ * Taking a lease over uses the observed rule (`acquireLease`), never this.
67
+ */
68
+ declare function holderLive(holder: LeaseHolder, at?: {
69
+ now?: number;
70
+ staleMs?: number;
71
+ mtimeMs?: number | null;
72
+ bootedAt?: number;
73
+ }): boolean;
74
+ /**
75
+ * Acquire the lease at `file`. Refused (naming the holder) while a holder is
76
+ * there; a stale one — by the observed rule, confirmed by a second look — is
77
+ * taken over under the guard. With `observeMs`, a held lease is watched that
78
+ * long before refusing. Async: it waits without blocking this process.
79
+ */
80
+ declare function acquireLease(file: string, info?: {
81
+ home?: string;
82
+ label?: string;
83
+ }, options?: LeaseOptions): Promise<LeaseAttempt>;
84
+ /** The holder of the lease at `file` by a one-look judgement (`holderLive`), or null. */
85
+ declare function leaseHolder(file: string, staleMs?: number): LeaseHolder | null;
86
+ /** Test seam: forget what this process has observed of leases. */
87
+ declare function resetLeaseObservations(): void;
88
+
4
89
  interface IntegrationClient {
5
90
  readonly runtime: TextsRuntime;
6
91
  readonly version: string;
@@ -58,6 +143,8 @@ interface IntegrationStatus {
58
143
  runtime: string | null;
59
144
  handle: string | null;
60
145
  profile: string;
146
+ /** The run workdir the daemon was given (absent in a file an older daemon wrote). */
147
+ workdir?: string;
61
148
  socket: SocketState;
62
149
  wakes: number;
63
150
  wakes_absorbed: number;
@@ -80,6 +167,57 @@ interface IntegrationStatus {
80
167
  recent_cycles?: IntegrationCycle[] | null;
81
168
  /** The socket's backpressure: true while it refuses new messages because handlers are behind (the kit's `intakePaused`); null from an older daemon. */
82
169
  intake_paused?: boolean | null;
170
+ /**
171
+ * Another daemon serves this agent (one agent, one listener): its identity
172
+ * home and pid. This one holds no socket and starts no run until it stops.
173
+ * Null or absent when this one serves it (or an older daemon wrote the file).
174
+ */
175
+ standby?: IntegrationStandby | null;
176
+ /**
177
+ * Runs keep failing and the runtime's own check says why (signed out, binary
178
+ * gone, a flag the installed version rejects): the check's words, since when,
179
+ * how many runs did not get done, when it was last checked. Cleared when a
180
+ * run succeeds. Null or absent when runs are fine (or an older daemon wrote the file).
181
+ */
182
+ runs_failing?: IntegrationRunsFailing | null;
183
+ /**
184
+ * This home gave its agent up because it cannot serve it — the server
185
+ * refuses its key, or its runs fail for a runtime reason while a healthy
186
+ * listener for the agent waits — and holds no socket until a recheck passes.
187
+ * Null or absent when it serves (or stands by for another).
188
+ */
189
+ unservable?: IntegrationUnservable | null;
190
+ /** Lock renewals that failed (the lock folder gone, a full disk, permissions), and the last message; null or absent when none did. */
191
+ lease_errors?: {
192
+ readonly count: number;
193
+ readonly last: string | null;
194
+ } | null;
195
+ }
196
+ interface IntegrationUnservable {
197
+ /** `key_refused`: the server refuses this home's key. `runs_failing`: the runtime's own check fails. */
198
+ readonly reason: 'key_refused' | 'runs_failing';
199
+ /** What was said: the refusal, or the runtime check's words. */
200
+ readonly detail: string;
201
+ /** When this home gave the agent up. */
202
+ readonly since: string;
203
+ /** When it checks again (the runtime first, for `runs_failing`). */
204
+ readonly retry_at: string;
205
+ }
206
+ interface IntegrationStandby {
207
+ /** The identity home of the daemon that serves the agent, as its lock says. */
208
+ readonly home: string | null;
209
+ readonly pid: number | null;
210
+ readonly since: string | null;
211
+ }
212
+ interface IntegrationRunsFailing {
213
+ /** The runtime's own check (preflight), in its words. */
214
+ readonly reason: string;
215
+ /** When the first of the failing runs ended. */
216
+ readonly since: string;
217
+ /** Runs that did not get done since then (each one a wake cycle that started a run). */
218
+ readonly runs_missed: number;
219
+ /** When the runtime was last checked. */
220
+ readonly checked_at: string;
83
221
  }
84
222
  /** One wake cycle as the status file keeps it: what it found and how it ended. Counts and outcomes only. */
85
223
  interface IntegrationCycle {
@@ -377,4 +515,4 @@ interface CheckManualOptions {
377
515
  /** Compare the skill file with the announced manual. Reads one file; no network. */
378
516
  declare function checkManual(options: CheckManualOptions): ManualCheck;
379
517
 
380
- export { resolveIdentity as $, clientIdentityOf as A, clientNameOf as B, type CheckManualOptions as C, DEFAULT_API_BASE as D, credentialsPath as E, FAILED_CYCLE_OUTCOMES as F, describeManualSync as G, type HostProfile as H, type IntegrationClient as I, envApiKey as J, failedCyclesInARow as K, LEGACY_STATUS_FILE as L, type ManualFetch as M, formatIntegrationStatus as N, fromKitResult as O, type PendingRegistration as P, integrationStatusAge as Q, REPEATED_FAILED_CYCLES as R, type SocketState as S, type TextsStatus as T, integrationStatusPath as U, type Verdict as V, pendingPath as W, readCredentials as X, readIntegrationStatus as Y, readManualVersion as Z, readPending as _, type IntegrationStatus as a, statePath as a0, syncManual as a1, writeCredentials as a2, writeIntegrationStatus as a3, writePending as a4, type Credentials as b, type DoctorCheck as c, type DoctorContext as d, INTEGRATION_STATUS_FILE as e, type IntegrationCycle as f, type IntegrationLastRun as g, MANUAL_FETCH_TIMEOUT_MS as h, MANUAL_MAX_BYTES as i, MANUAL_MAX_REDIRECTS as j, type ManualCheck as k, type ManualCheckState as l, type ManualSyncResult as m, type ManualSyncState as n, type ResolveIdentityOptions as o, type ResolvedIdentity as p, SOCKET_STATES as q, type ServedManual as r, type StatusContext as s, type SyncManualOptions as t, anchorLabelOf as u, checkManual as v, clearCredentials as w, clearIntegrationStatus as x, clearPending as y, clientHeadersOf as z };
518
+ export { envApiKey as $, type ServedManual as A, type StatusContext as B, type CheckManualOptions as C, DEFAULT_API_BASE as D, type SyncManualOptions as E, FAILED_CYCLE_OUTCOMES as F, acquireLease as G, type HostProfile as H, type IntegrationClient as I, anchorLabelOf as J, bootedAt as K, type LeaseOptions as L, type ManualFetch as M, checkManual as N, clearCredentials as O, type PendingRegistration as P, clearIntegrationStatus as Q, REPEATED_FAILED_CYCLES as R, type SocketState as S, type TextsStatus as T, clearPending as U, type Verdict as V, clientHeadersOf as W, clientIdentityOf as X, clientNameOf as Y, credentialsPath as Z, describeManualSync as _, type IntegrationStatus as a, failedCyclesInARow as a0, formatIntegrationStatus as a1, fromKitResult as a2, holderLive as a3, integrationStatusAge as a4, integrationStatusPath as a5, leaseHolder as a6, parseLease as a7, pendingPath as a8, pidAlive as a9, readCredentials as aa, readIntegrationStatus as ab, readManualVersion as ac, readPending as ad, resetLeaseObservations as ae, resolveIdentity as af, statePath as ag, syncManual as ah, writeCredentials as ai, writeIntegrationStatus as aj, writePending as ak, type IntegrationRunsFailing as b, type Lease as c, type LeaseAttempt as d, type LeaseHolder as e, type Credentials as f, type DoctorCheck as g, type DoctorContext as h, INTEGRATION_STATUS_FILE as i, type IntegrationCycle as j, type IntegrationLastRun as k, type IntegrationStandby as l, type IntegrationUnservable as m, LEASE_RENEW_MS as n, LEASE_STALE_MS as o, LEGACY_STATUS_FILE as p, MANUAL_FETCH_TIMEOUT_MS as q, MANUAL_MAX_BYTES as r, MANUAL_MAX_REDIRECTS as s, type ManualCheck as t, type ManualCheckState as u, type ManualSyncResult as v, type ManualSyncState as w, type ResolveIdentityOptions as x, type ResolvedIdentity as y, SOCKET_STATES as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentchatme/agent-core",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Shared host-agnostic engine for AgentChat integrations — the resident supervisor on the AgentChat SDK's integration kit (single-run mode: the socket acking on receipt, wakes, the tray before every run), the runner seam and spawnRun, the presets for known coding agents' headless runs, identity storage and flows, service plumbing. Runtime code only; every function takes an identity home, none resolves one.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",