agentfootprint 7.27.1 → 7.28.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 CHANGED
@@ -562,7 +562,7 @@ Same trick as the injection model: instead of N libraries for N patterns, we fou
562
562
 
563
563
  > 📖 Compare: [hand-rolled vs declarative](https://footprintjs.github.io/agentfootprint/docs/getting-started/why/) · [migration from LangChain / CrewAI / LangGraph](https://footprintjs.github.io/agentfootprint/docs/getting-started/vs/)
564
564
 
565
- ### Check in with the receipts — human consent for consequential actions
565
+ ### Check in with the receipts — human-in-the-loop consent for consequential actions
566
566
 
567
567
  OpenWorker-class agents check in; agentfootprint checks in **with the receipts.** A tool declares `checkIn: 'always'` (or a `(args) => boolean` predicate). When it trips, the run pauses **before** the tool executes and hands back an evidence pack: `willDo` (plain-words claim), `read` (context the run consumed), `drivers` (which context drove the choice, ranked, zero LLM calls), and a compact `trail`. A human answers `checkInApproved({ by })` / `checkInDeclined({ by, note })`; on approve the tool runs, on decline the model sees the note and adapts.
568
568
 
@@ -811,7 +811,7 @@ The flowchart, recorders, and tests don't change between dev and prod.
811
811
 
812
812
  **Operability**
813
813
  - Provider-agnostic prompt caching — declarative per-injection, per-iteration marker recomputation
814
- - Pause / resume — JSON-serializable checkpoints; resume hours later on a different server
814
+ - Human-in-the-loop pause / resume — a tool calls `pauseHere(...)` (or `askHuman(...)`); `isPaused(result)` hands you a JSON-serializable checkpoint, and `agent.resume(checkpoint, input)` continues hours later on a different server
815
815
  - Resilience primitives — `withRetry`, `withFallback`, `withCircuitBreaker`, `.outputFallback`, `agent.resumeOnError`
816
816
  - 60+ typed observability events — `agent` · `composition` · `context` · `stream` · `tools` · `skill` · `memory` · `cache` · `cost` · `permission` · `eval` · `embedding` · `pause` · `error` · `fallback` · `resilience` · `reliability` · `risk`
817
817
 
@@ -50,6 +50,13 @@
50
50
  * purpose: hiding a cap inside auto-chunking decides a protocol question
51
51
  * for every consumer at once.
52
52
  * â€Ē `memorySessions()` — conversations in a Map, for tests and local dev.
53
+ * â€Ē `sqliteSessions({ file })` — the same port, in a file, so a restart is not
54
+ * an amnesia event. Conversations AND runs paused waiting on a person, in
55
+ * one table, on Node's built-in `node:sqlite` — nothing to install and no
56
+ * peer dependency. One machine, one file, one writer at a time is the
57
+ * stated ceiling; it is not a distributed store. Refuses BY NAME on a Node
58
+ * without `node:sqlite` rather than falling back to memory, because a store
59
+ * that silently forgot everything looks exactly like a new user.
53
60
  * â€Ē `standingAgent({ agent, sessions, host, durability? })` — the composer.
54
61
  * â€Ē `toEnvelope` / `readEnvelope` — pack a conversation, and refuse by name to
55
62
  * unpack a format this runtime does not know.
@@ -78,6 +85,8 @@ export type { NodeHost, NodeHostHandle, NodeHostOptions } from './nodeHost.js';
78
85
  export { httpHost, headerValue } from './httpHost.js';
79
86
  export type { ConversationHandshake, HandshakeFacts, HttpHost, HttpHostHandle, HttpHostOptions, HttpRequestFacts, HttpWire, } from './httpHost.js';
80
87
  export { memorySessions } from './memorySessions.js';
88
+ export { sqliteSessions, SqliteUnavailableError, UnreadableSessionFileError, } from './sqliteSessions.js';
89
+ export type { SqliteSessions, SqliteSessionsOptions } from './sqliteSessions.js';
81
90
  export { toEnvelope, toPausedEnvelope, readEnvelope, readPausedRun, checkEnvelope, } from './envelope.js';
82
91
  export { standingAgent } from './standingAgent.js';
83
92
  export { requireCapability, HostClosedError, ConcurrentRunError, PauseNotCarriedError, AwaitingDecisionError, NoPendingAskError, UnreadableEnvelopeError, ConversationClosedError, FrameTooLargeError, } from './errors.js';
@@ -50,6 +50,13 @@
50
50
  * purpose: hiding a cap inside auto-chunking decides a protocol question
51
51
  * for every consumer at once.
52
52
  * â€Ē `memorySessions()` — conversations in a Map, for tests and local dev.
53
+ * â€Ē `sqliteSessions({ file })` — the same port, in a file, so a restart is not
54
+ * an amnesia event. Conversations AND runs paused waiting on a person, in
55
+ * one table, on Node's built-in `node:sqlite` — nothing to install and no
56
+ * peer dependency. One machine, one file, one writer at a time is the
57
+ * stated ceiling; it is not a distributed store. Refuses BY NAME on a Node
58
+ * without `node:sqlite` rather than falling back to memory, because a store
59
+ * that silently forgot everything looks exactly like a new user.
53
60
  * â€Ē `standingAgent({ agent, sessions, host, durability? })` — the composer.
54
61
  * â€Ē `toEnvelope` / `readEnvelope` — pack a conversation, and refuse by name to
55
62
  * unpack a format this runtime does not know.
@@ -76,6 +83,7 @@
76
83
  export { nodeHost, jsonWire } from './nodeHost.js';
77
84
  export { httpHost, headerValue } from './httpHost.js';
78
85
  export { memorySessions } from './memorySessions.js';
86
+ export { sqliteSessions, SqliteUnavailableError, UnreadableSessionFileError, } from './sqliteSessions.js';
79
87
  export { toEnvelope, toPausedEnvelope, readEnvelope, readPausedRun, checkEnvelope, } from './envelope.js';
80
88
  export { standingAgent } from './standingAgent.js';
81
89
  export { requireCapability, HostClosedError, ConcurrentRunError, PauseNotCarriedError, AwaitingDecisionError, NoPendingAskError, UnreadableEnvelopeError, ConversationClosedError, FrameTooLargeError, } from './errors.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hosting/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AAEH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAWtD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hosting/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiFG;AAEH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAWtD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAK7B,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,aAAa,CAAC"}
@@ -10,6 +10,9 @@
10
10
  * — which is also how the "a crashed process resumes the conversation" test is
11
11
  * written: keep the store, throw away everything else, and watch the
12
12
  * conversation come back through the envelope alone.
13
+ *
14
+ * The next step up ships beside this one: `sqliteSessions({ file })` is the same
15
+ * port in a file, with nothing to install.
13
16
  */
14
17
  import type { SessionLifecycle } from './types.js';
15
18
  /**
@@ -10,6 +10,9 @@
10
10
  * — which is also how the "a crashed process resumes the conversation" test is
11
11
  * written: keep the store, throw away everything else, and watch the
12
12
  * conversation come back through the envelope alone.
13
+ *
14
+ * The next step up ships beside this one: `sqliteSessions({ file })` is the same
15
+ * port in a file, with nothing to install.
13
16
  */
14
17
  /**
15
18
  * An in-process session store.
@@ -1 +1 @@
1
- {"version":3,"file":"memorySessions.js","sourceRoot":"","sources":["../../../src/hosting/memorySessions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH;;;;;;GAMG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,MAAM,GAAG,IAAI,GAAG,EAA8B,CAAC;IACrD,OAAO;QACL,OAAO,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC9D,OAAO,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE;YAC/B,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YAChC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"memorySessions.js","sourceRoot":"","sources":["../../../src/hosting/memorySessions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH;;;;;;GAMG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,MAAM,GAAG,IAAI,GAAG,EAA8B,CAAC;IACrD,OAAO;QACL,OAAO,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC9D,OAAO,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE;YAC/B,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YAChC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,211 @@
1
+ /**
2
+ * hosting/sqliteSessions — conversations in a file, so a restart is not an
3
+ * amnesia event.
4
+ *
5
+ * `memorySessions()` keeps conversations in a `Map` and says what that costs in
6
+ * its own docstring: restart the process and every conversation is gone. Until
7
+ * now the next step up was "bring a Redis", and the step between those two —
8
+ * *one machine, one file, nothing to install* — was a store every consumer had
9
+ * to write for themselves. This is that store.
10
+ *
11
+ * A paused run was in the same position from the other direction. `agent.run()`
12
+ * hands back a checkpoint that is documented as JSON you can keep anywhere, and
13
+ * "anywhere" was the whole of the offer: the library named a shape and left the
14
+ * keeping to you. Both halves land in the same table here, because
15
+ * {@link CheckpointEnvelope} was already a union of the two and a session store
16
+ * has no business caring which one it is holding.
17
+ *
18
+ * ── What this is, said plainly ──────────────────────────────────────────────
19
+ * **One process on one machine, writing one file.** That is the whole claim,
20
+ * and it is worth stating as a ceiling rather than leaving it to be discovered:
21
+ *
22
+ * â€Ē It survives a restart, a crash, a deploy — anything that ends the process
23
+ * and leaves the disk alone.
24
+ * â€Ē It is NOT a distributed store. Two machines do not share a session by
25
+ * both opening this file over a network filesystem, and nothing here tries
26
+ * to make that work.
27
+ * â€Ē WAL lets readers and one writer run at once, and **one writer at a time
28
+ * is the ceiling** — a second writer waits for the lock up to
29
+ * `busyTimeoutMs` and then fails loudly rather than queueing forever.
30
+ * Several processes on one box is fine at that scale; a fleet is not what
31
+ * this is.
32
+ *
33
+ * When you outgrow it you swap the one argument to `standingAgent`, which is
34
+ * the entire point of the port.
35
+ *
36
+ * ── Zero dependencies, and the version floor that buys ──────────────────────
37
+ * SQLite is *inside Node* — `node:sqlite`, no install, no native build, no
38
+ * peer dependency. The price is a version floor this package does not otherwise
39
+ * have: the module ships with Node 22.5 and newer. Rather than raise `engines`
40
+ * for one optional adapter and break every consumer on Node 20, the module is
41
+ * loaded when you actually construct a store, and its absence is refused by
42
+ * name with the version you are on and what to do about it — see
43
+ * {@link SqliteUnavailableError}. There is deliberately **no fallback to
44
+ * memory**: a store that silently forgot everything on restart is
45
+ * indistinguishable, from the outside, from a brand-new user.
46
+ *
47
+ * ── The two laws it inherits rather than re-implements ──────────────────────
48
+ * `checkEnvelope` is called on the way out AND on the way in, so an envelope
49
+ * whose `format` this runtime does not know is refused by name, and a stored
50
+ * session that is PRESENT but unreadable is refused by name too. Only a session
51
+ * that was never written hydrates as `undefined`. Validating on the way in as
52
+ * well is the cheap half of that promise: a row this store could not read back
53
+ * never gets written in the first place.
54
+ */
55
+ import type { SessionLifecycle } from './types.js';
56
+ /** One prepared statement, as this adapter calls it. */
57
+ export interface SqliteStatementLike {
58
+ run(...params: readonly unknown[]): unknown;
59
+ get(...params: readonly unknown[]): unknown;
60
+ all(...params: readonly unknown[]): unknown[];
61
+ }
62
+ /** One open database, as this adapter calls it. */
63
+ export interface SqliteDatabaseLike {
64
+ exec(sql: string): void;
65
+ prepare(sql: string): SqliteStatementLike;
66
+ close(): void;
67
+ }
68
+ /**
69
+ * The shape of `node:sqlite` this adapter needs — declared locally, the same
70
+ * way every other adapter here declares the slice of its backend it uses, so
71
+ * nothing takes a hard import on a module that does not exist on every
72
+ * supported Node.
73
+ */
74
+ export interface SqliteModuleLike {
75
+ new (path: string): SqliteDatabaseLike;
76
+ }
77
+ /** Options for {@link sqliteSessions}. */
78
+ export interface SqliteSessionsOptions {
79
+ /**
80
+ * The database file. Created if it does not exist, along with its parent
81
+ * directory — "no infrastructure" would be a thin promise if you still had to
82
+ * `mkdir` first.
83
+ *
84
+ * `':memory:'` is refused: it looks like a file, keeps nothing across a
85
+ * restart, and a store that quietly forgets is the exact failure this adapter
86
+ * exists to remove. Use `memorySessions()` when that is what you want — it
87
+ * says so in its name.
88
+ */
89
+ readonly file: string;
90
+ /**
91
+ * How long a write waits for another writer's lock before failing, in
92
+ * milliseconds. Default 5000.
93
+ *
94
+ * It fails rather than waits forever on purpose: a request hung on a lock
95
+ * looks exactly like a slow model, and the two need different fixes.
96
+ */
97
+ readonly busyTimeoutMs?: number;
98
+ /**
99
+ * @internal Test seam only — the `node:sqlite` module, injected. Lets the
100
+ * suite exercise the refusal path on a Node that HAS the module, and the
101
+ * failure paths without corrupting a real file. Not public API, not
102
+ * supported, and not a place to plug in another SQLite driver.
103
+ */
104
+ readonly _sqlite?: SqliteModuleLike;
105
+ }
106
+ /**
107
+ * A session store in a file.
108
+ *
109
+ * It is a {@link SessionLifecycle} plus the three things a real store owns
110
+ * beyond the port — closing, forgetting, and telling you what the file actually
111
+ * got — because the port deliberately asks for only two methods and leaves the
112
+ * rest to whoever implements it.
113
+ */
114
+ export interface SqliteSessions extends SessionLifecycle {
115
+ /**
116
+ * The journalling mode the file **actually has**, read back from SQLite
117
+ * rather than assumed from what was asked for.
118
+ *
119
+ * It is normally `'wal'`. It is something else when the file lives somewhere
120
+ * WAL cannot work — a network filesystem is the usual reason — and that is a
121
+ * fact worth being able to read: the store still works, with one writer *or*
122
+ * one reader at a time instead of both. A silent downgrade is the kind of
123
+ * thing that is only ever discovered under load.
124
+ */
125
+ readonly journalMode: string;
126
+ /** Forget one session. No-op if there is nothing stored for it. */
127
+ forget(sessionId: string): Promise<void>;
128
+ /**
129
+ * Close the file. Idempotent — a shutdown hook and an explicit close can
130
+ * coexist. Reading or writing afterwards refuses by name rather than
131
+ * reopening behind your back.
132
+ */
133
+ close(): void;
134
+ }
135
+ /**
136
+ * Raised when `node:sqlite` is not available in the running Node.
137
+ *
138
+ * Node 20 does not have the module at all; Node 22.5 through 22.12 have it
139
+ * behind `--experimental-sqlite`; Node 22.13+ and 23.4+ have it as-is (still
140
+ * marked experimental by Node, which is why it prints a warning on first use).
141
+ *
142
+ * The refusal names the version you are on and the three ways out, because
143
+ * "cannot find module 'node:sqlite'" out of a library's guts tells you what
144
+ * broke and nothing about what to do.
145
+ */
146
+ export declare class SqliteUnavailableError extends Error {
147
+ readonly code: "ERR_SQLITE_UNAVAILABLE";
148
+ /** The Node version this process is running. */
149
+ readonly nodeVersion: string;
150
+ constructor(nodeVersion: string, reason: string);
151
+ }
152
+ /**
153
+ * Raised when the file exists but this runtime cannot use it as a session
154
+ * store.
155
+ *
156
+ * The same law {@link UnreadableEnvelopeError} states for one stored value,
157
+ * one level up: **an unreadable store and an empty one are different facts, and
158
+ * only one of them is safe to answer with a fresh start.** A store that opened
159
+ * a corrupt file as an empty database would hand every returning user a blank
160
+ * slate and log nothing.
161
+ *
162
+ * `problem` is the fact to branch on — the three cases need different actions:
163
+ *
164
+ * - `'cannot-open'` — not a SQLite database, or not readable (permissions, a
165
+ * directory, a truncated file).
166
+ * - `'not-our-schema'` — a database whose `agent_sessions` table is somebody
167
+ * else's table of that name. Point the store at its own file.
168
+ * - `'newer-schema'` — written by a newer agentfootprint than this one. Same
169
+ * answer the envelope `format` field gives: refuse, never half-read.
170
+ */
171
+ export declare class UnreadableSessionFileError extends Error {
172
+ readonly code: "ERR_UNREADABLE_SESSION_FILE";
173
+ /** The file that was refused. */
174
+ readonly file: string;
175
+ /** Which of the three cases this is. */
176
+ readonly problem: 'cannot-open' | 'not-our-schema' | 'newer-schema';
177
+ constructor(file: string, problem: UnreadableSessionFileError['problem'], detail: string);
178
+ }
179
+ /**
180
+ * A session store in one SQLite file — the battery-included place to keep a
181
+ * conversation, or a run that stopped to ask a person something, so that a
182
+ * restart does not lose it.
183
+ *
184
+ * @throws SqliteUnavailableError when the running Node has no `node:sqlite`.
185
+ * @throws UnreadableSessionFileError when the file exists but cannot be used —
186
+ * never answered with an empty store.
187
+ *
188
+ * @example A standing agent whose conversations survive a restart
189
+ * import { standingAgent, nodeHost, sqliteSessions } from 'agentfootprint/hosting';
190
+ *
191
+ * const handle = await standingAgent({
192
+ * agent,
193
+ * sessions: sqliteSessions({ file: './sessions.db' }),
194
+ * host: nodeHost({ port: 8080 }),
195
+ * });
196
+ *
197
+ * @example Keeping a paused run yourself, without the composer
198
+ * const sessions = sqliteSessions({ file: './sessions.db' });
199
+ * const out = await agent.run({ message });
200
+ * if (isPaused(out)) {
201
+ * await sessions.persist(sessionId, toPausedEnvelope({
202
+ * checkpoint: out.checkpoint,
203
+ * conversation: agent.checkpoint()!,
204
+ * pending: { pauseData: out.pauseData },
205
+ * }));
206
+ * }
207
+ * // â€Ķa deploy later, in a new process:
208
+ * const paused = readPausedRun(await sessions.hydrate(sessionId));
209
+ * const answer = await agent.resume(paused.checkpoint, decision);
210
+ */
211
+ export declare function sqliteSessions(options: SqliteSessionsOptions): SqliteSessions;