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.
@@ -0,0 +1,370 @@
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 { checkEnvelope } from './envelope.js';
56
+ import { UnreadableEnvelopeError } from './errors.js';
57
+ import { lazyRequire } from '../lib/lazyRequire.js';
58
+ // ─── The refusals ────────────────────────────────────────────────────
59
+ /**
60
+ * Raised when `node:sqlite` is not available in the running Node.
61
+ *
62
+ * Node 20 does not have the module at all; Node 22.5 through 22.12 have it
63
+ * behind `--experimental-sqlite`; Node 22.13+ and 23.4+ have it as-is (still
64
+ * marked experimental by Node, which is why it prints a warning on first use).
65
+ *
66
+ * The refusal names the version you are on and the three ways out, because
67
+ * "cannot find module 'node:sqlite'" out of a library's guts tells you what
68
+ * broke and nothing about what to do.
69
+ */
70
+ export class SqliteUnavailableError extends Error {
71
+ code = 'ERR_SQLITE_UNAVAILABLE';
72
+ /** The Node version this process is running. */
73
+ nodeVersion;
74
+ constructor(nodeVersion, reason) {
75
+ super(`[hosting] sqliteSessions() needs Node's built-in 'node:sqlite' module, and this ` +
76
+ `process (Node ${nodeVersion}) does not have it (${reason}). ` +
77
+ `That module ships with Node 22.5 and newer: on Node 22.13+ (and 23.4+) it is ` +
78
+ `available as-is, and on Node 22.5–22.12 it is behind --experimental-sqlite. ` +
79
+ `So: upgrade Node, add that flag, or use memorySessions() — which keeps ` +
80
+ `conversations in a Map and loses them on restart, and says so in its name. ` +
81
+ `This refuses rather than falling back to memory on your behalf: a store that ` +
82
+ `silently forgot every conversation on restart looks, from the outside, exactly ` +
83
+ `like a brand-new user.`);
84
+ this.name = 'SqliteUnavailableError';
85
+ this.nodeVersion = nodeVersion;
86
+ }
87
+ }
88
+ /**
89
+ * Raised when the file exists but this runtime cannot use it as a session
90
+ * store.
91
+ *
92
+ * The same law {@link UnreadableEnvelopeError} states for one stored value,
93
+ * one level up: **an unreadable store and an empty one are different facts, and
94
+ * only one of them is safe to answer with a fresh start.** A store that opened
95
+ * a corrupt file as an empty database would hand every returning user a blank
96
+ * slate and log nothing.
97
+ *
98
+ * `problem` is the fact to branch on — the three cases need different actions:
99
+ *
100
+ * - `'cannot-open'` — not a SQLite database, or not readable (permissions, a
101
+ * directory, a truncated file).
102
+ * - `'not-our-schema'` — a database whose `agent_sessions` table is somebody
103
+ * else's table of that name. Point the store at its own file.
104
+ * - `'newer-schema'` — written by a newer agentfootprint than this one. Same
105
+ * answer the envelope `format` field gives: refuse, never half-read.
106
+ */
107
+ export class UnreadableSessionFileError extends Error {
108
+ code = 'ERR_UNREADABLE_SESSION_FILE';
109
+ /** The file that was refused. */
110
+ file;
111
+ /** Which of the three cases this is. */
112
+ problem;
113
+ constructor(file, problem, detail) {
114
+ super(`[hosting] the session store at '${file}' cannot be used: ${detail} ` +
115
+ `An unreadable store and an empty one are different facts, and only one of them ` +
116
+ `is safe to answer with a fresh start — so this refuses rather than quietly ` +
117
+ `beginning every conversation again on top of a file that already exists. ` +
118
+ (problem === 'newer-schema'
119
+ ? `A store written by a newer agentfootprint needs a runtime that knows that ` +
120
+ `schema; roll forward, or point this one at its own file.`
121
+ : problem === 'not-our-schema'
122
+ ? `Give the store a file of its own rather than sharing one with tables of ` +
123
+ `the same name.`
124
+ : `Check the path and its permissions, or move the file aside to start a ` + `new one.`));
125
+ this.name = 'UnreadableSessionFileError';
126
+ this.file = file;
127
+ this.problem = problem;
128
+ }
129
+ }
130
+ // ─── The schema ──────────────────────────────────────────────────────
131
+ /**
132
+ * What this runtime writes. Bumped only for a change an older reader could not
133
+ * survive — and an older reader meeting a newer number refuses by name rather
134
+ * than reading what it half-understands, which is the same rule the envelope's
135
+ * `format` field follows.
136
+ */
137
+ const SCHEMA_VERSION = 1;
138
+ const SESSIONS_TABLE = 'agent_sessions';
139
+ const META_TABLE = 'agent_store_meta';
140
+ /**
141
+ * `format` and `saved_at` are COLUMNS as well as fields inside the JSON, and
142
+ * that redundancy is deliberate: it makes the file answer "which sessions are
143
+ * waiting on a person, and since when?" from the `sqlite3` command line during
144
+ * an incident, without a JSON parser and without this library. A store you
145
+ * cannot inspect with the tools already on the box is a store you debug by
146
+ * guessing.
147
+ */
148
+ const SESSIONS_COLUMNS = ['session_id', 'format', 'saved_at', 'envelope'];
149
+ // ─── The store ───────────────────────────────────────────────────────
150
+ /**
151
+ * A session store in one SQLite file — the battery-included place to keep a
152
+ * conversation, or a run that stopped to ask a person something, so that a
153
+ * restart does not lose it.
154
+ *
155
+ * @throws SqliteUnavailableError when the running Node has no `node:sqlite`.
156
+ * @throws UnreadableSessionFileError when the file exists but cannot be used —
157
+ * never answered with an empty store.
158
+ *
159
+ * @example A standing agent whose conversations survive a restart
160
+ * import { standingAgent, nodeHost, sqliteSessions } from 'agentfootprint/hosting';
161
+ *
162
+ * const handle = await standingAgent({
163
+ * agent,
164
+ * sessions: sqliteSessions({ file: './sessions.db' }),
165
+ * host: nodeHost({ port: 8080 }),
166
+ * });
167
+ *
168
+ * @example Keeping a paused run yourself, without the composer
169
+ * const sessions = sqliteSessions({ file: './sessions.db' });
170
+ * const out = await agent.run({ message });
171
+ * if (isPaused(out)) {
172
+ * await sessions.persist(sessionId, toPausedEnvelope({
173
+ * checkpoint: out.checkpoint,
174
+ * conversation: agent.checkpoint()!,
175
+ * pending: { pauseData: out.pauseData },
176
+ * }));
177
+ * }
178
+ * // …a deploy later, in a new process:
179
+ * const paused = readPausedRun(await sessions.hydrate(sessionId));
180
+ * const answer = await agent.resume(paused.checkpoint, decision);
181
+ */
182
+ export function sqliteSessions(options) {
183
+ const { file, busyTimeoutMs = 5000 } = options;
184
+ if (file === ':memory:' || file.trim() === '') {
185
+ throw new TypeError(`[hosting] sqliteSessions({ file: '${file}' }) is not a durable store. ` +
186
+ `':memory:' looks like a file and keeps nothing across a restart, which is the ` +
187
+ `one thing this adapter exists to do. Use memorySessions() when an in-process ` +
188
+ `store is what you want — it says so in its name — or give this one a real path.`);
189
+ }
190
+ const DatabaseSync = options._sqlite ?? loadSqlite();
191
+ ensureParentDirectory(file);
192
+ let db;
193
+ try {
194
+ db = new DatabaseSync(file);
195
+ }
196
+ catch (err) {
197
+ throw new UnreadableSessionFileError(file, 'cannot-open', `${describe(err)}.`);
198
+ }
199
+ let journalMode;
200
+ try {
201
+ journalMode = applyPragmas(db, busyTimeoutMs);
202
+ ensureSchema(db, file);
203
+ }
204
+ catch (err) {
205
+ db.close();
206
+ if (err instanceof UnreadableSessionFileError)
207
+ throw err;
208
+ throw new UnreadableSessionFileError(file, 'cannot-open', `${describe(err)}.`);
209
+ }
210
+ const insert = db.prepare(`INSERT INTO ${SESSIONS_TABLE} (session_id, format, saved_at, envelope) VALUES (?, ?, ?, ?) ` +
211
+ `ON CONFLICT(session_id) DO UPDATE SET format = excluded.format, ` +
212
+ `saved_at = excluded.saved_at, envelope = excluded.envelope`);
213
+ const select = db.prepare(`SELECT envelope FROM ${SESSIONS_TABLE} WHERE session_id = ?`);
214
+ const remove = db.prepare(`DELETE FROM ${SESSIONS_TABLE} WHERE session_id = ?`);
215
+ let closed = false;
216
+ const open = (verb) => {
217
+ if (closed) {
218
+ throw new Error(`[hosting] the sqliteSessions store at '${file}' is closed, so it cannot ${verb}. ` +
219
+ `close() is final by design — reopening the file behind you would hide a ` +
220
+ `shutdown-ordering bug rather than surface it. Build a new store if you need ` +
221
+ `one after closing this.`);
222
+ }
223
+ };
224
+ // The three port methods are `async` so that every refusal in them arrives
225
+ // as a REJECTION. A method that returns a promise on the happy path and
226
+ // throws synchronously on the sad one is a method whose callers need two
227
+ // error handlers, and the one they forget is the one that fires at 3am.
228
+ return {
229
+ journalMode,
230
+ // eslint-disable-next-line @typescript-eslint/require-await
231
+ async hydrate(sessionId) {
232
+ open('hydrate a session');
233
+ const row = select.get(sessionId);
234
+ if (row === undefined)
235
+ return undefined;
236
+ const stored = row.envelope;
237
+ if (typeof stored !== 'string') {
238
+ // A row exists and its payload is not even text. Present, unreadable —
239
+ // and specifically NOT `undefined`.
240
+ throw new UnreadableEnvelopeError(stored, sessionId);
241
+ }
242
+ let parsed;
243
+ try {
244
+ parsed = JSON.parse(stored);
245
+ }
246
+ catch {
247
+ // Bytes written by something that was not this store. Same fact, same
248
+ // refusal: a conversation EXISTS here and this runtime cannot see it.
249
+ throw new UnreadableEnvelopeError(stored, sessionId);
250
+ }
251
+ // Validate HERE as well as in the composer, so the refusal points at the
252
+ // store that produced the bytes rather than at whoever read them next.
253
+ return checkEnvelope(parsed, sessionId);
254
+ },
255
+ // eslint-disable-next-line @typescript-eslint/require-await
256
+ async persist(sessionId, envelope) {
257
+ open('persist a session');
258
+ // Checked on the way IN as well as out: a row this store could not read
259
+ // back is a row it has no business writing.
260
+ const checked = checkEnvelope(envelope, sessionId);
261
+ insert.run(sessionId, checked.format, checked.savedAt, JSON.stringify(checked));
262
+ },
263
+ // eslint-disable-next-line @typescript-eslint/require-await
264
+ async forget(sessionId) {
265
+ open('forget a session');
266
+ remove.run(sessionId);
267
+ },
268
+ close() {
269
+ if (closed)
270
+ return;
271
+ closed = true;
272
+ db.close();
273
+ },
274
+ };
275
+ }
276
+ // ─── Internals ───────────────────────────────────────────────────────
277
+ /**
278
+ * Load `node:sqlite`, or refuse by name.
279
+ *
280
+ * `lazyRequire` keeps the specifier away from bundler static analysis, so
281
+ * importing `agentfootprint/hosting` costs nothing for the consumers — the vast
282
+ * majority — who never construct one of these.
283
+ */
284
+ function loadSqlite() {
285
+ try {
286
+ const mod = lazyRequire('node:sqlite');
287
+ if (typeof mod?.DatabaseSync !== 'function') {
288
+ throw new Error('the module loaded but has no DatabaseSync');
289
+ }
290
+ return mod.DatabaseSync;
291
+ }
292
+ catch (err) {
293
+ throw new SqliteUnavailableError(nodeVersion(), describe(err));
294
+ }
295
+ }
296
+ /** The version string, without assuming `process` exists. */
297
+ function nodeVersion() {
298
+ return typeof process !== 'undefined' && typeof process.version === 'string'
299
+ ? process.version
300
+ : 'unknown';
301
+ }
302
+ /**
303
+ * Create the file's directory if it is missing — "no infrastructure" should not
304
+ * mean "except for one `mkdir`". A failure here is left to the open call, which
305
+ * reports it with the path in the same words as every other open failure.
306
+ */
307
+ function ensureParentDirectory(file) {
308
+ try {
309
+ const { mkdirSync } = lazyRequire('node:fs');
310
+ const { dirname } = lazyRequire('node:path');
311
+ mkdirSync(dirname(file), { recursive: true });
312
+ }
313
+ catch {
314
+ /* Reported by the open below, with the path and the real reason. */
315
+ }
316
+ }
317
+ /**
318
+ * Set the file up for concurrent use and report what it actually got.
319
+ *
320
+ * `journal_mode` is the first statement executed on purpose: it is the point at
321
+ * which SQLite reads the file header, so "this is not a database" surfaces here,
322
+ * at construction, where the caller can still do something about it — rather
323
+ * than on the first request of the night.
324
+ */
325
+ function applyPragmas(db, busyTimeoutMs) {
326
+ const row = db.prepare('PRAGMA journal_mode = WAL').get();
327
+ // A pragma takes a literal, not a bound parameter, so the number is coerced
328
+ // to one before it reaches the statement rather than trusted to be one.
329
+ const waitMs = Number.isFinite(busyTimeoutMs) ? Math.max(0, Math.floor(busyTimeoutMs)) : 5000;
330
+ db.exec(`PRAGMA busy_timeout = ${waitMs}`);
331
+ // NORMAL, not FULL: with WAL that is durable across a process crash — which
332
+ // is what this store promises — and it does not pay a disk sync per turn.
333
+ // A power cut can still cost the most recent commits; a fleet-grade store is
334
+ // the answer to that, not a pragma.
335
+ db.exec('PRAGMA synchronous = NORMAL');
336
+ return typeof row?.journal_mode === 'string' ? row.journal_mode : 'unknown';
337
+ }
338
+ /** Create the two tables if they are missing, and refuse a file that is not ours. */
339
+ function ensureSchema(db, file) {
340
+ db.exec(`CREATE TABLE IF NOT EXISTS ${SESSIONS_TABLE} (` +
341
+ `session_id TEXT PRIMARY KEY, format TEXT NOT NULL, ` +
342
+ `saved_at INTEGER NOT NULL, envelope TEXT NOT NULL) STRICT`);
343
+ db.exec(`CREATE TABLE IF NOT EXISTS ${META_TABLE} (key TEXT PRIMARY KEY, value TEXT NOT NULL) STRICT`);
344
+ // `CREATE TABLE IF NOT EXISTS` succeeds against somebody else's table of the
345
+ // same name, and the failure would otherwise arrive as a confusing constraint
346
+ // error on the first write.
347
+ const columns = db.prepare(`PRAGMA table_info('${SESSIONS_TABLE}')`).all().map((c) => String(c.name));
348
+ const missing = SESSIONS_COLUMNS.filter((name) => !columns.includes(name));
349
+ if (missing.length > 0) {
350
+ throw new UnreadableSessionFileError(file, 'not-our-schema', `it has a '${SESSIONS_TABLE}' table that is not this store's ` +
351
+ `(missing ${missing.join(', ')}; found ${columns.join(', ') || 'nothing'}).`);
352
+ }
353
+ const stored = db
354
+ .prepare(`SELECT value FROM ${META_TABLE} WHERE key = 'schema_version'`)
355
+ .get();
356
+ if (stored === undefined) {
357
+ db.prepare(`INSERT INTO ${META_TABLE} (key, value) VALUES ('schema_version', ?)`).run(String(SCHEMA_VERSION));
358
+ return;
359
+ }
360
+ const found = Number(stored.value);
361
+ if (!Number.isFinite(found) || found > SCHEMA_VERSION) {
362
+ throw new UnreadableSessionFileError(file, 'newer-schema', `it was written with schema version ${String(stored.value)} and this runtime ` +
363
+ `reads version ${SCHEMA_VERSION}.`);
364
+ }
365
+ }
366
+ /** One sentence about a thrown thing, for a message that has to stay readable. */
367
+ function describe(err) {
368
+ return err instanceof Error ? err.message : String(err);
369
+ }
370
+ //# sourceMappingURL=sqliteSessions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqliteSessions.js","sourceRoot":"","sources":["../../../src/hosting/sqliteSessions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AC,OAAO,CAAC,eAAe,UAAU,4CAA4C,CAAC,CAAC,GAAG,CACnF,MAAM,CAAC,cAAc,CAAC,CACvB,CAAC;QACF,OAAO;IACT,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACnC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,cAAc,EAAE,CAAC;QACtD,MAAM,IAAI,0BAA0B,CAClC,IAAI,EACJ,cAAc,EACd,sCAAsC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB;YAC5E,iBAAiB,cAAc,GAAG,CACrC,CAAC;IACJ,CAAC;AACH,CAAC;AAED,kFAAkF;AAClF,SAAS,QAAQ,CAAC,GAAY;IAC5B,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC"}
@@ -51,6 +51,13 @@
51
51
  * purpose: hiding a cap inside auto-chunking decides a protocol question
52
52
  * for every consumer at once.
53
53
  * • `memorySessions()` — conversations in a Map, for tests and local dev.
54
+ * • `sqliteSessions({ file })` — the same port, in a file, so a restart is not
55
+ * an amnesia event. Conversations AND runs paused waiting on a person, in
56
+ * one table, on Node's built-in `node:sqlite` — nothing to install and no
57
+ * peer dependency. One machine, one file, one writer at a time is the
58
+ * stated ceiling; it is not a distributed store. Refuses BY NAME on a Node
59
+ * without `node:sqlite` rather than falling back to memory, because a store
60
+ * that silently forgot everything looks exactly like a new user.
54
61
  * • `standingAgent({ agent, sessions, host, durability? })` — the composer.
55
62
  * • `toEnvelope` / `readEnvelope` — pack a conversation, and refuse by name to
56
63
  * unpack a format this runtime does not know.
@@ -75,7 +82,7 @@
75
82
  * process.on('SIGTERM', () => void handle.close());
76
83
  */
77
84
  Object.defineProperty(exports, "__esModule", { value: true });
78
- exports.FrameTooLargeError = exports.ConversationClosedError = exports.UnreadableEnvelopeError = exports.NoPendingAskError = exports.AwaitingDecisionError = exports.PauseNotCarriedError = exports.ConcurrentRunError = exports.HostClosedError = exports.requireCapability = exports.standingAgent = exports.checkEnvelope = exports.readPausedRun = exports.readEnvelope = exports.toPausedEnvelope = exports.toEnvelope = exports.memorySessions = exports.headerValue = exports.httpHost = exports.jsonWire = exports.nodeHost = void 0;
85
+ exports.FrameTooLargeError = exports.ConversationClosedError = exports.UnreadableEnvelopeError = exports.NoPendingAskError = exports.AwaitingDecisionError = exports.PauseNotCarriedError = exports.ConcurrentRunError = exports.HostClosedError = exports.requireCapability = exports.standingAgent = exports.checkEnvelope = exports.readPausedRun = exports.readEnvelope = exports.toPausedEnvelope = exports.toEnvelope = exports.UnreadableSessionFileError = exports.SqliteUnavailableError = exports.sqliteSessions = exports.memorySessions = exports.headerValue = exports.httpHost = exports.jsonWire = exports.nodeHost = void 0;
79
86
  var nodeHost_js_1 = require("./nodeHost.js");
80
87
  Object.defineProperty(exports, "nodeHost", { enumerable: true, get: function () { return nodeHost_js_1.nodeHost; } });
81
88
  Object.defineProperty(exports, "jsonWire", { enumerable: true, get: function () { return nodeHost_js_1.jsonWire; } });
@@ -84,6 +91,10 @@ Object.defineProperty(exports, "httpHost", { enumerable: true, get: function ()
84
91
  Object.defineProperty(exports, "headerValue", { enumerable: true, get: function () { return httpHost_js_1.headerValue; } });
85
92
  var memorySessions_js_1 = require("./memorySessions.js");
86
93
  Object.defineProperty(exports, "memorySessions", { enumerable: true, get: function () { return memorySessions_js_1.memorySessions; } });
94
+ var sqliteSessions_js_1 = require("./sqliteSessions.js");
95
+ Object.defineProperty(exports, "sqliteSessions", { enumerable: true, get: function () { return sqliteSessions_js_1.sqliteSessions; } });
96
+ Object.defineProperty(exports, "SqliteUnavailableError", { enumerable: true, get: function () { return sqliteSessions_js_1.SqliteUnavailableError; } });
97
+ Object.defineProperty(exports, "UnreadableSessionFileError", { enumerable: true, get: function () { return sqliteSessions_js_1.UnreadableSessionFileError; } });
87
98
  var envelope_js_1 = require("./envelope.js");
88
99
  Object.defineProperty(exports, "toEnvelope", { enumerable: true, get: function () { return envelope_js_1.toEnvelope; } });
89
100
  Object.defineProperty(exports, "toPausedEnvelope", { enumerable: true, get: function () { return envelope_js_1.toPausedEnvelope; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hosting/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;;;AAEH,6CAAmD;AAA1C,uGAAA,QAAQ,OAAA;AAAE,uGAAA,QAAQ,OAAA;AAG3B,6CAAsD;AAA7C,uGAAA,QAAQ,OAAA;AAAE,0GAAA,WAAW,OAAA;AAW9B,yDAAqD;AAA5C,mHAAA,cAAc,OAAA;AACvB,6CAMuB;AALrB,yGAAA,UAAU,OAAA;AACV,+GAAA,gBAAgB,OAAA;AAChB,2GAAA,YAAY,OAAA;AACZ,4GAAA,aAAa,OAAA;AACb,4GAAA,aAAa,OAAA;AAEf,uDAAmD;AAA1C,iHAAA,aAAa,OAAA;AAEtB,yCAUqB;AATnB,8GAAA,iBAAiB,OAAA;AACjB,4GAAA,eAAe,OAAA;AACf,+GAAA,kBAAkB,OAAA;AAClB,iHAAA,oBAAoB,OAAA;AACpB,kHAAA,qBAAqB,OAAA;AACrB,8GAAA,iBAAiB,OAAA;AACjB,oHAAA,uBAAuB,OAAA;AACvB,oHAAA,uBAAuB,OAAA;AACvB,+GAAA,kBAAkB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hosting/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiFG;;;AAEH,6CAAmD;AAA1C,uGAAA,QAAQ,OAAA;AAAE,uGAAA,QAAQ,OAAA;AAG3B,6CAAsD;AAA7C,uGAAA,QAAQ,OAAA;AAAE,0GAAA,WAAW,OAAA;AAW9B,yDAAqD;AAA5C,mHAAA,cAAc,OAAA;AACvB,yDAI6B;AAH3B,mHAAA,cAAc,OAAA;AACd,2HAAA,sBAAsB,OAAA;AACtB,+HAAA,0BAA0B,OAAA;AAM5B,6CAMuB;AALrB,yGAAA,UAAU,OAAA;AACV,+GAAA,gBAAgB,OAAA;AAChB,2GAAA,YAAY,OAAA;AACZ,4GAAA,aAAa,OAAA;AACb,4GAAA,aAAa,OAAA;AAEf,uDAAmD;AAA1C,iHAAA,aAAa,OAAA;AAEtB,yCAUqB;AATnB,8GAAA,iBAAiB,OAAA;AACjB,4GAAA,eAAe,OAAA;AACf,+GAAA,kBAAkB,OAAA;AAClB,iHAAA,oBAAoB,OAAA;AACpB,kHAAA,qBAAqB,OAAA;AACrB,8GAAA,iBAAiB,OAAA;AACjB,oHAAA,uBAAuB,OAAA;AACvB,oHAAA,uBAAuB,OAAA;AACvB,+GAAA,kBAAkB,OAAA"}
@@ -11,6 +11,9 @@
11
11
  * — which is also how the "a crashed process resumes the conversation" test is
12
12
  * written: keep the store, throw away everything else, and watch the
13
13
  * conversation come back through the envelope alone.
14
+ *
15
+ * The next step up ships beside this one: `sqliteSessions({ file })` is the same
16
+ * port in a file, with nothing to install.
14
17
  */
15
18
  Object.defineProperty(exports, "__esModule", { value: true });
16
19
  exports.memorySessions = void 0;
@@ -1 +1 @@
1
- {"version":3,"file":"memorySessions.js","sourceRoot":"","sources":["../../src/hosting/memorySessions.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAIH;;;;;;GAMG;AACH,SAAgB,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;AATD,wCASC"}
1
+ {"version":3,"file":"memorySessions.js","sourceRoot":"","sources":["../../src/hosting/memorySessions.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAIH;;;;;;GAMG;AACH,SAAgB,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;AATD,wCASC"}