@agentchatme/agent-core 0.4.1 → 0.5.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 +83 -3
- package/dist/chunk-3ERPUP4M.js +97 -0
- package/dist/chunk-3ERPUP4M.js.map +1 -0
- package/dist/{chunk-AE4XHKHQ.js → chunk-AFDD53DD.js} +234 -10
- package/dist/chunk-AFDD53DD.js.map +1 -0
- package/dist/{chunk-7LAAAXUO.js → chunk-CDJASQ3X.js} +509 -104
- package/dist/chunk-CDJASQ3X.js.map +1 -0
- package/dist/daemon-entry.d.ts +58 -3
- package/dist/daemon-entry.js +287 -33
- package/dist/daemon-entry.js.map +1 -1
- package/dist/index.d.ts +94 -13
- package/dist/index.js +402 -354
- package/dist/index.js.map +1 -1
- package/dist/presets.d.ts +352 -21
- package/dist/presets.js +700 -105
- package/dist/presets.js.map +1 -1
- package/dist/{runner-B-ZZDAAm.d.ts → runner-DYVqz_9P.d.ts} +38 -2
- package/dist/{served-manual-99vEOjJS.d.ts → served-manual-Be_eUo0m.d.ts} +157 -26
- package/package.json +2 -2
- package/dist/chunk-7LAAAXUO.js.map +0 -1
- package/dist/chunk-AE4XHKHQ.js.map +0 -1
- package/dist/chunk-QDM4EFI7.js +0 -139
- package/dist/chunk-QDM4EFI7.js.map +0 -1
- package/dist/chunk-XDWBTX5J.js +0 -30
- package/dist/chunk-XDWBTX5J.js.map +0 -1
|
@@ -1,6 +1,91 @@
|
|
|
1
|
-
import { TextsRuntime, AgentChatClientIdentity, integration } from 'agentchatme';
|
|
1
|
+
import { TextsRuntime, AgentChatClientIdentity, SignupFlow, 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 {
|
|
@@ -163,31 +301,24 @@ declare function writeCredentials(home: string, creds: Credentials): void;
|
|
|
163
301
|
/** Delete the credential and any half-finished registration in `home`.
|
|
164
302
|
* Touches nothing outside `home` — that is the caller's whole agent. */
|
|
165
303
|
declare function clearCredentials(home: string): boolean;
|
|
166
|
-
|
|
167
|
-
kind:
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}, "strip", z.ZodTypeAny, {
|
|
174
|
-
created_at: string;
|
|
175
|
-
kind: "register" | "recover";
|
|
176
|
-
pending_id: string;
|
|
177
|
-
email: string;
|
|
178
|
-
handle?: string | undefined;
|
|
179
|
-
api_base?: string | undefined;
|
|
180
|
-
}, {
|
|
181
|
-
created_at: string;
|
|
182
|
-
pending_id: string;
|
|
304
|
+
interface PendingSignup {
|
|
305
|
+
kind: 'register' | 'recover';
|
|
306
|
+
/** The server's flow object, as its last answer gave it. */
|
|
307
|
+
flow: SignupFlow;
|
|
308
|
+
/** When that answer arrived (ISO-8601): `expires_in_s` and `resend_after_s` count from here. */
|
|
309
|
+
received_at: string;
|
|
310
|
+
/** What the start call sent. */
|
|
183
311
|
email: string;
|
|
184
|
-
handle?: string
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
312
|
+
handle?: string;
|
|
313
|
+
display_name?: string;
|
|
314
|
+
description?: string;
|
|
315
|
+
/** The API base the start call went to, when not the default. */
|
|
316
|
+
api_base?: string;
|
|
317
|
+
}
|
|
318
|
+
/** @deprecated Renamed to {@link PendingSignup}; kept so existing imports keep compiling. */
|
|
319
|
+
type PendingRegistration = PendingSignup;
|
|
320
|
+
declare function readPending(home: string): PendingSignup | null;
|
|
321
|
+
declare function writePending(home: string, pending: PendingSignup): void;
|
|
191
322
|
declare function clearPending(home: string): void;
|
|
192
323
|
|
|
193
324
|
type Verdict = 'PASS' | 'WARN' | 'FAIL';
|
|
@@ -377,4 +508,4 @@ interface CheckManualOptions {
|
|
|
377
508
|
/** Compare the skill file with the announced manual. Reads one file; no network. */
|
|
378
509
|
declare function checkManual(options: CheckManualOptions): ManualCheck;
|
|
379
510
|
|
|
380
|
-
export {
|
|
511
|
+
export { describeManualSync as $, SOCKET_STATES as A, type ServedManual as B, type CheckManualOptions as C, DEFAULT_API_BASE as D, type StatusContext as E, FAILED_CYCLE_OUTCOMES as F, type SyncManualOptions as G, type HostProfile as H, type IntegrationClient as I, acquireLease as J, anchorLabelOf as K, type LeaseOptions as L, type ManualFetch as M, bootedAt as N, checkManual as O, type PendingRegistration as P, clearCredentials as Q, REPEATED_FAILED_CYCLES as R, type SocketState as S, type TextsStatus as T, clearIntegrationStatus as U, type Verdict as V, clearPending as W, clientHeadersOf as X, clientIdentityOf as Y, clientNameOf as Z, credentialsPath as _, type IntegrationStatus as a, envApiKey as a0, failedCyclesInARow as a1, formatIntegrationStatus as a2, fromKitResult as a3, holderLive as a4, integrationStatusAge as a5, integrationStatusPath as a6, leaseHolder as a7, parseLease as a8, pendingPath as a9, pidAlive as aa, readCredentials as ab, readIntegrationStatus as ac, readManualVersion as ad, readPending as ae, resetLeaseObservations as af, resolveIdentity as ag, statePath as ah, syncManual as ai, writeCredentials as aj, writeIntegrationStatus as ak, writePending as al, 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 PendingSignup as x, type ResolveIdentityOptions as y, type ResolvedIdentity as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentchatme/agent-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
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",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"prepare": "pnpm run build"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"agentchatme": "^1.
|
|
45
|
+
"agentchatme": "^1.4.0",
|
|
46
46
|
"cross-spawn": "^7.0.6",
|
|
47
47
|
"ws": "^8.18.0",
|
|
48
48
|
"zod": "^3.23.0"
|