@agentchatme/agent-core 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -8
- package/dist/{chunk-GXAX47O6.js → chunk-KUZZ3MW2.js} +421 -23
- package/dist/chunk-KUZZ3MW2.js.map +1 -0
- package/dist/daemon-entry.d.ts +21 -2
- package/dist/daemon-entry.js +16 -2
- package/dist/daemon-entry.js.map +1 -1
- package/dist/index.d.ts +17 -173
- package/dist/index.js +42 -29
- package/dist/index.js.map +1 -1
- package/dist/prompts-BUfpwUT7.d.ts +630 -0
- package/package.json +1 -1
- package/dist/chunk-GXAX47O6.js.map +0 -1
- package/dist/prompts-B0UL03Hu.d.ts +0 -336
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
import { TextsRuntime, AgentChatClientIdentity, AgentChatClient, Texts } from 'agentchatme';
|
|
2
|
-
|
|
3
|
-
interface IntegrationClient {
|
|
4
|
-
readonly runtime: TextsRuntime;
|
|
5
|
-
readonly version: string;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* The SDK's client identity for this integration. The SDK types client names
|
|
9
|
-
* as a closed union and the server normalises whatever arrives, so the
|
|
10
|
-
* runtime name is passed through as-is; the union widens on the SDK side.
|
|
11
|
-
*/
|
|
12
|
-
declare function clientIdentityOf(client: IntegrationClient): AgentChatClientIdentity;
|
|
13
|
-
/** The same identity as headers, for the one raw request this package still makes (the MCP probe). */
|
|
14
|
-
declare function clientHeadersOf(client: IntegrationClient): Record<string, string>;
|
|
15
|
-
|
|
16
|
-
declare const RUN_PROFILES: readonly ["answer", "work", "full"];
|
|
17
|
-
type RunProfile = (typeof RUN_PROFILES)[number];
|
|
18
|
-
declare const RUN_PROFILE_ENV = "AGENTCHAT_RUN_PROFILE";
|
|
19
|
-
declare const DEFAULT_RUN_PROFILE: RunProfile;
|
|
20
|
-
declare function isRunProfile(value: unknown): value is RunProfile;
|
|
21
|
-
/** `AGENTCHAT_RUN_PROFILE`, defaulting to `answer`; an unknown value is `answer` too. */
|
|
22
|
-
declare function resolveRunProfile(env?: NodeJS.ProcessEnv): RunProfile;
|
|
23
|
-
/** The one switch: `AGENTCHAT_INTEGRATION=off` holds no socket and starts no run. Tools and manual stay. */
|
|
24
|
-
declare const INTEGRATION_ENV = "AGENTCHAT_INTEGRATION";
|
|
25
|
-
/**
|
|
26
|
-
* The previous spelling of the switch. Honoured for one release: a service
|
|
27
|
-
* installed before the rename captured it into its unit file, and that unit
|
|
28
|
-
* must keep meaning what the operator set.
|
|
29
|
-
*/
|
|
30
|
-
declare const INTEGRATION_ENV_LEGACY = "AGENTCHAT_DOORBELL";
|
|
31
|
-
/** Which switch turned the integration off, or null when it is on. The new spelling wins when both are set. */
|
|
32
|
-
declare function integrationDisabledBy(env?: NodeJS.ProcessEnv): string | null;
|
|
33
|
-
declare function integrationDisabled(env?: NodeJS.ProcessEnv): boolean;
|
|
34
|
-
/** A run's time budget. Killed past it; that counts as a failed run. */
|
|
35
|
-
declare const RUN_BUDGET_ENV = "AGENTCHAT_RUN_BUDGET_MS";
|
|
36
|
-
declare const DEFAULT_RUN_BUDGET_MS: number;
|
|
37
|
-
declare function resolveRunBudgetMs(env?: NodeJS.ProcessEnv): number;
|
|
38
|
-
|
|
39
|
-
type RunKind = 'wake' | 'invite';
|
|
40
|
-
interface RunRequest {
|
|
41
|
-
readonly kind: RunKind;
|
|
42
|
-
/** The prompt for this kind of run: the served text, then the manual pointer (`buildRunPrompts`). */
|
|
43
|
-
readonly prompt: string;
|
|
44
|
-
/** Unique per run; for logs and for runtimes that want a session name. */
|
|
45
|
-
readonly runId: string;
|
|
46
|
-
/** The run is killed past this budget and counts as failed. */
|
|
47
|
-
readonly budgetMs: number;
|
|
48
|
-
/**
|
|
49
|
-
* Aborted when the integration is stopping (daemon shutdown, identity
|
|
50
|
-
* change). A runner passes it to `spawnRun`, which SIGTERMs the
|
|
51
|
-
* run's process group and SIGKILLs after a grace; the outcome is `failed`
|
|
52
|
-
* with an "interrupted" detail. Optional so a runner that cannot interrupt
|
|
53
|
-
* still satisfies the contract.
|
|
54
|
-
*/
|
|
55
|
-
readonly signal?: AbortSignal;
|
|
56
|
-
/**
|
|
57
|
-
* Called once, as soon as the runtime's process has been started. The
|
|
58
|
-
* invoker records a group invite as offered at this moment — not when the
|
|
59
|
-
* run ends — so a run cut short by a shutdown or a crash still counts as
|
|
60
|
-
* the invite's one offer from this machine. A runner built on `spawnRun`
|
|
61
|
-
* passes it through; a runner that cannot tell may leave it uncalled, and
|
|
62
|
-
* the invoker then records the offer when the run ends instead.
|
|
63
|
-
*/
|
|
64
|
-
readonly onStarted?: () => void;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* `not_started` — the runtime never got going: binary missing, or a non-zero
|
|
68
|
-
* exit with NOTHING ON STDOUT (an auth gate, a bad flag, a missing config —
|
|
69
|
-
* all of which print their complaint on stderr and quit; stderr does not
|
|
70
|
-
* count as output). `failed` — it produced output and exited non-zero, or was
|
|
71
|
-
* interrupted. `timed_out` — it ran past its budget and was killed. `ok` —
|
|
72
|
-
* exit 0. Anything but `ok` schedules the retry ladder.
|
|
73
|
-
*/
|
|
74
|
-
type RunOutcomeState = 'ok' | 'failed' | 'timed_out' | 'not_started';
|
|
75
|
-
interface RunOutcome {
|
|
76
|
-
readonly state: RunOutcomeState;
|
|
77
|
-
readonly exitCode: number | null;
|
|
78
|
-
readonly durationMs: number;
|
|
79
|
-
/** Bounded, credential-redacted diagnostic. Never message content. */
|
|
80
|
-
readonly detail?: string;
|
|
81
|
-
}
|
|
82
|
-
interface RunPreflight {
|
|
83
|
-
ok: boolean;
|
|
84
|
-
detail?: string;
|
|
85
|
-
}
|
|
86
|
-
interface RunRunner {
|
|
87
|
-
/** Short runtime name for logs and status, e.g. the CLI's binary name. */
|
|
88
|
-
readonly name: string;
|
|
89
|
-
/**
|
|
90
|
-
* Is the runtime usable right now (binary present, signed in)? Called
|
|
91
|
-
* before the socket is held, and — after the retry ladder is exhausted —
|
|
92
|
-
* periodically, so a runtime that comes back (the user signs in again)
|
|
93
|
-
* earns one re-wake without waiting for the next peer.
|
|
94
|
-
*/
|
|
95
|
-
preflight(): Promise<RunPreflight>;
|
|
96
|
-
/** Start one run and wait for it. Never throws — returns an outcome. */
|
|
97
|
-
start(request: RunRequest): Promise<RunOutcome>;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
declare const INTEGRATION_STATUS_FILE = "integration.status.json";
|
|
101
|
-
/** The file a daemon before the rename writes; read when the current one is absent. */
|
|
102
|
-
declare const LEGACY_STATUS_FILE = "doorbell.status.json";
|
|
103
|
-
/**
|
|
104
|
-
* The socket word. `blocked` is the SDK's own word for it (`RealtimeState`):
|
|
105
|
-
* the server refused the credential on the hello and a fresh hello is tried
|
|
106
|
-
* every 10–15 min until one is accepted — not an end state. Daemons before
|
|
107
|
-
* this release wrote `terminal` for it; readers map that on the way in.
|
|
108
|
-
*/
|
|
109
|
-
declare const SOCKET_STATES: readonly ["off", "idle", "connecting", "ready", "reconnecting", "blocked", "closed"];
|
|
110
|
-
type SocketState = (typeof SOCKET_STATES)[number];
|
|
111
|
-
type TextsSource$1 = 'server' | 'cache' | 'none';
|
|
112
|
-
interface TextsStatus {
|
|
113
|
-
/** Where the texts a run starts with came from. */
|
|
114
|
-
source: TextsSource$1;
|
|
115
|
-
fetched_at: string | null;
|
|
116
|
-
/** The served text set's version. */
|
|
117
|
-
version: string | null;
|
|
118
|
-
manual_version: string | null;
|
|
119
|
-
}
|
|
120
|
-
interface IntegrationLastRun {
|
|
121
|
-
kind: 'wake' | 'invite';
|
|
122
|
-
started_at: string;
|
|
123
|
-
ended_at: string;
|
|
124
|
-
state: 'ok' | 'failed' | 'timed_out' | 'not_started';
|
|
125
|
-
exit_code: number | null;
|
|
126
|
-
duration_ms: number;
|
|
127
|
-
detail: string | null;
|
|
128
|
-
}
|
|
129
|
-
interface IntegrationStatus {
|
|
130
|
-
version: 2;
|
|
131
|
-
updated_at: string;
|
|
132
|
-
pid: number;
|
|
133
|
-
runtime: string | null;
|
|
134
|
-
handle: string | null;
|
|
135
|
-
profile: string;
|
|
136
|
-
socket: SocketState;
|
|
137
|
-
wakes: number;
|
|
138
|
-
wakes_absorbed: number;
|
|
139
|
-
invites: number;
|
|
140
|
-
runs_started: number;
|
|
141
|
-
runs_ok: number;
|
|
142
|
-
runs_failed: number;
|
|
143
|
-
runs_timed_out: number;
|
|
144
|
-
runs_not_started: number;
|
|
145
|
-
/** Wakes whose tray count came back empty, so no run started. */
|
|
146
|
-
runs_skipped_empty: number;
|
|
147
|
-
last_run: IntegrationLastRun | null;
|
|
148
|
-
retry_rung: number;
|
|
149
|
-
retry_due_at: string | null;
|
|
150
|
-
last_error: string | null;
|
|
151
|
-
texts: TextsStatus | null;
|
|
152
|
-
}
|
|
153
|
-
declare function integrationStatusPath(home: string): string;
|
|
154
|
-
/** Best effort: the status file is diagnostics, never a dependency of waking. */
|
|
155
|
-
declare function writeIntegrationStatus(home: string, status: IntegrationStatus): void;
|
|
156
|
-
/** The current file, or — when a daemon from before the rename is the one running — the file it writes. */
|
|
157
|
-
declare function readIntegrationStatus(home: string): IntegrationStatus | null;
|
|
158
|
-
/** Remove both spellings: a stale legacy file must not outlive the daemon that wrote it. */
|
|
159
|
-
declare function clearIntegrationStatus(home: string): void;
|
|
160
|
-
/** Age of the status file, in ms, or null when absent. */
|
|
161
|
-
declare function integrationStatusAge(status: IntegrationStatus | null, now?: number): number | null;
|
|
162
|
-
/** Human lines for `status`. Pure. */
|
|
163
|
-
declare function formatIntegrationStatus(status: IntegrationStatus | null, now?: number): string[];
|
|
164
|
-
|
|
165
|
-
declare const DEFAULT_WAKE_DEBOUNCE_MS = 2000;
|
|
166
|
-
type TimerHandle = ReturnType<typeof setTimeout>;
|
|
167
|
-
interface WakeCoalescerOptions {
|
|
168
|
-
readonly onFire: () => void;
|
|
169
|
-
readonly debounceMs?: number;
|
|
170
|
-
/** Clock and timers are injectable so tests never wait on real time. */
|
|
171
|
-
readonly now?: () => number;
|
|
172
|
-
readonly setTimeout?: (fn: () => void, ms: number) => TimerHandle;
|
|
173
|
-
readonly clearTimeout?: (handle: TimerHandle) => void;
|
|
174
|
-
}
|
|
175
|
-
declare class WakeCoalescer {
|
|
176
|
-
private readonly onFire;
|
|
177
|
-
private readonly debounceMs;
|
|
178
|
-
private readonly now;
|
|
179
|
-
private readonly _setTimeout;
|
|
180
|
-
private readonly _clearTimeout;
|
|
181
|
-
private timer;
|
|
182
|
-
private delayed;
|
|
183
|
-
private delayedDeadline;
|
|
184
|
-
private stopped;
|
|
185
|
-
wakes: number;
|
|
186
|
-
absorbed: number;
|
|
187
|
-
fires: number;
|
|
188
|
-
constructor(options: WakeCoalescerOptions);
|
|
189
|
-
/** True while a debounce timer is armed. */
|
|
190
|
-
get armed(): boolean;
|
|
191
|
-
/** True while a retry wake is scheduled and has not fired. */
|
|
192
|
-
get delayedPending(): boolean;
|
|
193
|
-
/** Epoch ms of the pending retry wake, or null. */
|
|
194
|
-
get delayedDue(): number | null;
|
|
195
|
-
/** A wake: arm the timer if none is armed; otherwise absorb. */
|
|
196
|
-
wake(): void;
|
|
197
|
-
/** A delayed wake (retry ladder). The sooner pending deadline is kept. */
|
|
198
|
-
wakeAfter(delayMs: number): void;
|
|
199
|
-
/**
|
|
200
|
-
* Drop a pending retry wake, if there is one; returns whether there was.
|
|
201
|
-
* The debounce timer and later wakes are unaffected. For when nothing is
|
|
202
|
-
* owed any more — a run read the whole tray, or the tray was found empty —
|
|
203
|
-
* so the retry would only ring for a backlog that is already handled.
|
|
204
|
-
*/
|
|
205
|
-
cancelDelayed(): boolean;
|
|
206
|
-
/** Cancel everything; later wakes are ignored. */
|
|
207
|
-
stop(): void;
|
|
208
|
-
private fire;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
declare const TEXTS_CACHE_FILE = "texts.json";
|
|
212
|
-
declare const TEXTS_REFRESH_MS: number;
|
|
213
|
-
/** After a failed refresh: try again sooner than the daily timer. */
|
|
214
|
-
declare const TEXTS_RETRY_MS = 3600000;
|
|
215
|
-
type TextsSource = 'server' | 'cache' | 'none';
|
|
216
|
-
interface CachedTexts {
|
|
217
|
-
readonly fetched_at: string;
|
|
218
|
-
readonly runtime: string;
|
|
219
|
-
readonly texts: Texts;
|
|
220
|
-
}
|
|
221
|
-
declare function textsCachePath(home: string): string;
|
|
222
|
-
/** The last response cached for this runtime, or null. A cache for another runtime is not this one's. */
|
|
223
|
-
declare function readCachedTexts(home: string, runtime: TextsRuntime): CachedTexts | null;
|
|
224
|
-
/** Best effort: the cache is a convenience for an offline start, never a dependency of a fetch. */
|
|
225
|
-
declare function writeCachedTexts(home: string, runtime: TextsRuntime, texts: Texts, fetchedAt: Date): void;
|
|
226
|
-
type TextsClient = Pick<AgentChatClient, 'texts'>;
|
|
227
|
-
interface LoadedTexts {
|
|
228
|
-
readonly texts: Texts;
|
|
229
|
-
readonly source: 'server' | 'cache';
|
|
230
|
-
readonly fetched_at: string;
|
|
231
|
-
}
|
|
232
|
-
interface LoadTextsOptions {
|
|
233
|
-
readonly home: string;
|
|
234
|
-
readonly runtime: TextsRuntime;
|
|
235
|
-
readonly client: TextsClient;
|
|
236
|
-
readonly timeoutMs?: number;
|
|
237
|
-
readonly now?: () => Date;
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* One fetch with the cache as fallback — what a CLI command does before it
|
|
241
|
-
* places the identity line or checks it. Null only when the server could not
|
|
242
|
-
* be reached and nothing was ever cached for this runtime.
|
|
243
|
-
*/
|
|
244
|
-
declare function loadTexts(options: LoadTextsOptions): Promise<LoadedTexts | null>;
|
|
245
|
-
interface FetchIdentityLineOptions {
|
|
246
|
-
readonly home: string;
|
|
247
|
-
readonly apiKey: string;
|
|
248
|
-
readonly apiBase: string;
|
|
249
|
-
readonly client: IntegrationClient;
|
|
250
|
-
readonly timeoutMs?: number;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* The served identity line for this agent, for an integration's own install
|
|
254
|
-
* and placement paths: one fetch through an SDK client built here, the cache
|
|
255
|
-
* as fallback, null when neither answers. The identity commands do the same
|
|
256
|
-
* before `place`; this is the same read for callers that have no client.
|
|
257
|
-
*/
|
|
258
|
-
declare function fetchIdentityLine(options: FetchIdentityLineOptions): Promise<string | null>;
|
|
259
|
-
interface TextsStoreOptions {
|
|
260
|
-
readonly home: string;
|
|
261
|
-
readonly runtime: TextsRuntime;
|
|
262
|
-
readonly client: TextsClient;
|
|
263
|
-
readonly refreshMs?: number;
|
|
264
|
-
readonly retryMs?: number;
|
|
265
|
-
readonly timeoutMs?: number;
|
|
266
|
-
/** Called after every change in what `current()` or `source` answer (a status writer hangs off this). */
|
|
267
|
-
readonly onChange?: () => void;
|
|
268
|
-
readonly now?: () => Date;
|
|
269
|
-
readonly setTimeout?: (fn: () => void, ms: number) => TimerHandle;
|
|
270
|
-
readonly clearTimeout?: (handle: TimerHandle) => void;
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* The daemon's copy of the texts: fetched at start, refreshed on a timer, read
|
|
274
|
-
* from the identity-home cache when the server cannot be reached, and fetched
|
|
275
|
-
* on first use when the start fetch failed.
|
|
276
|
-
*/
|
|
277
|
-
declare class TextsStore {
|
|
278
|
-
readonly runtime: TextsRuntime;
|
|
279
|
-
private readonly home;
|
|
280
|
-
private readonly client;
|
|
281
|
-
private readonly refreshMs;
|
|
282
|
-
private readonly retryMs;
|
|
283
|
-
private readonly timeoutMs;
|
|
284
|
-
private readonly onChange;
|
|
285
|
-
private readonly now;
|
|
286
|
-
private readonly _setTimeout;
|
|
287
|
-
private readonly _clearTimeout;
|
|
288
|
-
private texts;
|
|
289
|
-
private _source;
|
|
290
|
-
private _fetchedAt;
|
|
291
|
-
private inFlight;
|
|
292
|
-
private timer;
|
|
293
|
-
private stopped;
|
|
294
|
-
private lastFailure;
|
|
295
|
-
private serverSeen;
|
|
296
|
-
constructor(options: TextsStoreOptions);
|
|
297
|
-
/** Where the current texts came from: the server (this process), the on-disk cache, or nowhere yet. */
|
|
298
|
-
get source(): TextsSource;
|
|
299
|
-
/** When the current texts were fetched from the server (by this process or the one that cached them). */
|
|
300
|
-
get fetchedAt(): string | null;
|
|
301
|
-
/** The texts in hand, without a network call. */
|
|
302
|
-
current(): Texts | null;
|
|
303
|
-
/**
|
|
304
|
-
* The start-time fetch, then the refresh timer. Returns once the first
|
|
305
|
-
* attempt has settled, so a run that starts right after `start()` has the
|
|
306
|
-
* freshest text available; a failure is logged once and does not throw —
|
|
307
|
-
* the daemon starts anyway, on the cache if there is one.
|
|
308
|
-
*/
|
|
309
|
-
start(): Promise<void>;
|
|
310
|
-
stop(): void;
|
|
311
|
-
/**
|
|
312
|
-
* Fetch now (coalescing a fetch already in flight), cache on success, arm
|
|
313
|
-
* the next refresh either way. Resolves whether the server answered.
|
|
314
|
-
*/
|
|
315
|
-
refresh(): Promise<boolean>;
|
|
316
|
-
/**
|
|
317
|
-
* The texts for a run: what is in hand, after one more fetch attempt if the
|
|
318
|
-
* server has not answered yet in this process. Null only when the server is
|
|
319
|
-
* unreachable and nothing was ever cached — the run then does not start and
|
|
320
|
-
* the wake retries on the ladder.
|
|
321
|
-
*/
|
|
322
|
-
ensure(): Promise<Texts | null>;
|
|
323
|
-
private fetchOnce;
|
|
324
|
-
private arm;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
interface RunPrompts {
|
|
328
|
-
/** What a wake run starts with. */
|
|
329
|
-
readonly wake: string;
|
|
330
|
-
/** What a group-invite run starts with. Invites are not on the tray and are never auto-accepted. */
|
|
331
|
-
readonly invite: string;
|
|
332
|
-
}
|
|
333
|
-
/** The served texts, then the one pointer line (`manualPointer(...)`). */
|
|
334
|
-
declare function buildRunPrompts(texts: Pick<Texts, 'wake_instruction' | 'invite_prompt'>, manualPointer: string): RunPrompts;
|
|
335
|
-
|
|
336
|
-
export { resolveRunProfile as $, type TextsSource as A, type TextsStatus as B, type CachedTexts as C, DEFAULT_WAKE_DEBOUNCE_MS as D, type TextsStoreOptions as E, type FetchIdentityLineOptions as F, buildRunPrompts as G, clearIntegrationStatus as H, type IntegrationClient as I, clientHeadersOf as J, clientIdentityOf as K, LEGACY_STATUS_FILE as L, fetchIdentityLine as M, formatIntegrationStatus as N, integrationDisabled as O, integrationDisabledBy as P, integrationStatusAge as Q, type RunRunner as R, type SocketState as S, TextsStore as T, integrationStatusPath as U, isRunProfile as V, WakeCoalescer as W, loadTexts as X, readCachedTexts as Y, readIntegrationStatus as Z, resolveRunBudgetMs as _, type RunProfile as a, textsCachePath as a0, writeCachedTexts as a1, writeIntegrationStatus as a2, type IntegrationStatus as b, type RunPrompts as c, type TimerHandle as d, type IntegrationLastRun as e, type RunOutcome as f, type RunKind as g, type RunOutcomeState as h, type RunPreflight as i, type RunRequest as j, type WakeCoalescerOptions as k, DEFAULT_RUN_BUDGET_MS as l, DEFAULT_RUN_PROFILE as m, INTEGRATION_ENV as n, INTEGRATION_ENV_LEGACY as o, INTEGRATION_STATUS_FILE as p, type LoadTextsOptions as q, type LoadedTexts as r, RUN_BUDGET_ENV as s, RUN_PROFILES as t, RUN_PROFILE_ENV as u, SOCKET_STATES as v, TEXTS_CACHE_FILE as w, TEXTS_REFRESH_MS as x, TEXTS_RETRY_MS as y, type TextsClient as z };
|