trellis 3.1.3 → 3.1.7

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.
Files changed (60) hide show
  1. package/README.md +1 -0
  2. package/bin/trellis.mjs +68 -2
  3. package/dist/better-sqlite-backend-ahx5p0br.js +147 -0
  4. package/dist/cli/index.js +116 -45
  5. package/dist/client/index.js +5 -4
  6. package/dist/cms/client.d.ts +4 -3
  7. package/dist/cms/client.d.ts.map +1 -1
  8. package/dist/cms/formula.d.ts +10 -0
  9. package/dist/cms/formula.d.ts.map +1 -0
  10. package/dist/cms/index.d.ts +3 -2
  11. package/dist/cms/index.d.ts.map +1 -1
  12. package/dist/cms/index.js +156 -4
  13. package/dist/cms/types.d.ts +11 -0
  14. package/dist/cms/types.d.ts.map +1 -1
  15. package/dist/core/index.d.ts +4 -0
  16. package/dist/core/index.d.ts.map +1 -1
  17. package/dist/core/index.js +14 -4
  18. package/dist/core/persist/factory.d.ts +28 -0
  19. package/dist/core/persist/factory.d.ts.map +1 -0
  20. package/dist/core/persist/factory.js +8 -0
  21. package/dist/core/persist/sqlite-backend.d.ts.map +1 -1
  22. package/dist/core/persist/sqljs-backend.d.ts +60 -0
  23. package/dist/core/persist/sqljs-backend.d.ts.map +1 -0
  24. package/dist/core/persist/sqljs-backend.js +8 -0
  25. package/dist/db/index.js +11 -10
  26. package/dist/embeddings/index.js +1 -1
  27. package/dist/embeddings/store.d.ts.map +1 -1
  28. package/dist/{index-0zk3fx2s.js → index-4wxa8xz4.js} +4 -237
  29. package/dist/{index-6n5dcebj.js → index-53f3b8p8.js} +84 -30
  30. package/dist/{index-y3d71wzd.js → index-7pjz3tsy.js} +36 -6
  31. package/dist/{index-0q7wbasy.js → index-a2a394zz.js} +7 -3
  32. package/dist/index-h32txmxe.js +42 -0
  33. package/dist/index-h7zxhhhh.js +252 -0
  34. package/dist/index-h9e2efx4.js +251 -0
  35. package/dist/{index-2917tjd8.js → index-hr9qvv77.js} +15 -3
  36. package/dist/{index-hmdbnd4n.js → index-hy73j9z8.js} +1 -1
  37. package/dist/{index-q31hfjja.js → index-jgda3xyv.js} +1 -1
  38. package/dist/{index-7e27kvvj.js → index-wncptktd.js} +1 -1
  39. package/dist/index.js +8 -6
  40. package/dist/react/index.js +5 -4
  41. package/dist/{sdk-snn5gad3.js → sdk-bepky0xs.js} +5 -4
  42. package/dist/server/index.d.ts +2 -2
  43. package/dist/server/index.d.ts.map +1 -1
  44. package/dist/server/index.js +27 -24
  45. package/dist/server/node-adapter.d.ts +38 -0
  46. package/dist/server/node-adapter.d.ts.map +1 -0
  47. package/dist/server/node-adapter.js +108 -0
  48. package/dist/server/server-shared.d.ts +21 -0
  49. package/dist/server/server-shared.d.ts.map +1 -0
  50. package/dist/server/server.d.ts +19 -2
  51. package/dist/server/server.d.ts.map +1 -1
  52. package/dist/server/tenancy.d.ts +28 -2
  53. package/dist/server/tenancy.d.ts.map +1 -1
  54. package/dist/{server-mrctdwzr.js → server-szdjx0nt.js} +5 -3
  55. package/dist/sqlite-backend-0vsmc6qj.js +8 -0
  56. package/dist/{tenancy-7d1g4ayp.js → tenancy-pjm32b4v.js} +4 -3
  57. package/dist/vcs/blob-store.d.ts +2 -1
  58. package/dist/vcs/blob-store.d.ts.map +1 -1
  59. package/dist/vcs/index.js +2 -2
  60. package/package.json +16 -3
@@ -0,0 +1,252 @@
1
+ // @bun
2
+ import {
3
+ __require
4
+ } from "./index-a76rekgs.js";
5
+
6
+ // src/core/persist/sqlite-backend.ts
7
+ var _DatabaseCtor = null;
8
+ function loadDatabaseCtor() {
9
+ if (_DatabaseCtor)
10
+ return _DatabaseCtor;
11
+ try {
12
+ const { createRequire } = __require("module");
13
+ const requireCJS = createRequire(import.meta.url);
14
+ _DatabaseCtor = requireCJS("bun:sqlite").Database;
15
+ return _DatabaseCtor;
16
+ } catch {
17
+ throw new Error("SqliteKernelBackend requires the Bun runtime (built-in `bun:sqlite`). " + "In Node / WebContainer use `createKernelBackend()` from " + "`trellis/core` \u2014 it auto-selects better-sqlite3 or sql.js.");
18
+ }
19
+ }
20
+ var SCHEMA_SQL = `
21
+ CREATE TABLE IF NOT EXISTS ops (
22
+ hash TEXT PRIMARY KEY,
23
+ kind TEXT NOT NULL,
24
+ timestamp TEXT NOT NULL,
25
+ agent_id TEXT NOT NULL,
26
+ previous_hash TEXT,
27
+ payload TEXT NOT NULL
28
+ );
29
+
30
+ CREATE TABLE IF NOT EXISTS snapshots (
31
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
32
+ last_op_hash TEXT NOT NULL,
33
+ data TEXT NOT NULL,
34
+ created_at TEXT NOT NULL DEFAULT (datetime('now'))
35
+ );
36
+
37
+ CREATE TABLE IF NOT EXISTS blobs (
38
+ hash TEXT PRIMARY KEY,
39
+ content BLOB NOT NULL
40
+ );
41
+
42
+ CREATE INDEX IF NOT EXISTS idx_ops_kind ON ops(kind);
43
+ CREATE INDEX IF NOT EXISTS idx_ops_timestamp ON ops(timestamp);
44
+ CREATE INDEX IF NOT EXISTS idx_ops_agent ON ops(agent_id);
45
+ CREATE INDEX IF NOT EXISTS idx_ops_previous ON ops(previous_hash);
46
+ CREATE INDEX IF NOT EXISTS idx_snapshots_op ON snapshots(last_op_hash);
47
+ `;
48
+
49
+ class SqliteKernelBackend {
50
+ dbPath;
51
+ db;
52
+ _stmts = null;
53
+ constructor(dbPath) {
54
+ this.dbPath = dbPath;
55
+ const DatabaseCtor = loadDatabaseCtor();
56
+ this.db = new DatabaseCtor(dbPath);
57
+ }
58
+ init() {
59
+ this.db.exec("PRAGMA journal_mode=WAL;");
60
+ this.db.exec("PRAGMA foreign_keys=ON;");
61
+ this.db.exec("PRAGMA synchronous=NORMAL;");
62
+ this.db.exec(SCHEMA_SQL);
63
+ this._prepareStatements();
64
+ }
65
+ _prepareStatements() {
66
+ this._stmts = {
67
+ insert: this.db.prepare(`
68
+ INSERT OR IGNORE INTO ops (hash, kind, timestamp, agent_id, previous_hash, payload)
69
+ VALUES ($hash, $kind, $timestamp, $agentId, $previousHash, $payload)
70
+ `),
71
+ readAll: this.db.prepare(`
72
+ SELECT hash, kind, timestamp, agent_id, previous_hash, payload
73
+ FROM ops ORDER BY rowid ASC
74
+ `),
75
+ readUntil: this.db.prepare(`
76
+ SELECT hash, kind, timestamp, agent_id, previous_hash, payload
77
+ FROM ops WHERE rowid <= (SELECT rowid FROM ops WHERE hash = $hash)
78
+ ORDER BY rowid ASC
79
+ `),
80
+ readAfter: this.db.prepare(`
81
+ SELECT hash, kind, timestamp, agent_id, previous_hash, payload
82
+ FROM ops WHERE rowid > (SELECT rowid FROM ops WHERE hash = $hash)
83
+ ORDER BY rowid ASC
84
+ `),
85
+ getByHash: this.db.prepare(`
86
+ SELECT hash, kind, timestamp, agent_id, previous_hash, payload
87
+ FROM ops WHERE hash = $hash
88
+ `),
89
+ getLast: this.db.prepare(`
90
+ SELECT hash, kind, timestamp, agent_id, previous_hash, payload
91
+ FROM ops ORDER BY rowid DESC LIMIT 1
92
+ `),
93
+ count: this.db.prepare("SELECT COUNT(*) as cnt FROM ops"),
94
+ saveSnapshot: this.db.prepare(`
95
+ INSERT INTO snapshots (last_op_hash, data)
96
+ VALUES ($lastOpHash, $data)
97
+ `),
98
+ loadSnapshot: this.db.prepare(`
99
+ SELECT last_op_hash, data FROM snapshots
100
+ ORDER BY id DESC LIMIT 1
101
+ `),
102
+ putBlob: this.db.prepare(`
103
+ INSERT OR IGNORE INTO blobs (hash, content) VALUES ($hash, $content)
104
+ `),
105
+ getBlob: this.db.prepare(`
106
+ SELECT content FROM blobs WHERE hash = $hash
107
+ `),
108
+ hasBlob: this.db.prepare(`
109
+ SELECT 1 FROM blobs WHERE hash = $hash
110
+ `)
111
+ };
112
+ }
113
+ append(op) {
114
+ const payload = JSON.stringify({
115
+ facts: op.facts,
116
+ links: op.links,
117
+ ...op.deleteFacts?.length ? { deleteFacts: op.deleteFacts } : {},
118
+ ...op.deleteLinks?.length ? { deleteLinks: op.deleteLinks } : {},
119
+ ...op.vcs ? { vcs: op.vcs } : {},
120
+ ...op.signature ? { signature: op.signature } : {}
121
+ });
122
+ this._stmts.insert.run({
123
+ $hash: op.hash,
124
+ $kind: op.kind,
125
+ $timestamp: op.timestamp,
126
+ $agentId: op.agentId,
127
+ $previousHash: op.previousHash ?? null,
128
+ $payload: payload
129
+ });
130
+ }
131
+ appendBatch(ops) {
132
+ if (ops.length === 0)
133
+ return;
134
+ this.db.transaction(() => {
135
+ for (const op of ops) {
136
+ this.append(op);
137
+ }
138
+ })();
139
+ }
140
+ readAll() {
141
+ const rows = this._stmts.readAll.all();
142
+ return rows.map(rowToOp);
143
+ }
144
+ readUntil(hash) {
145
+ const rows = this._stmts.readUntil.all({ $hash: hash });
146
+ return rows.map(rowToOp);
147
+ }
148
+ readAfter(hash) {
149
+ const rows = this._stmts.readAfter.all({ $hash: hash });
150
+ return rows.map(rowToOp);
151
+ }
152
+ readUntilTimestamp(isoTimestamp) {
153
+ const rows = this.db.prepare(`SELECT hash, kind, timestamp, agent_id, previous_hash, payload
154
+ FROM ops WHERE timestamp <= $ts ORDER BY rowid ASC`).all({ $ts: isoTimestamp });
155
+ return rows.map(rowToOp);
156
+ }
157
+ getLastOp() {
158
+ const row = this._stmts.getLast.get();
159
+ return row ? rowToOp(row) : undefined;
160
+ }
161
+ getByHash(hash) {
162
+ return this.getOpByHash(hash);
163
+ }
164
+ getOpCount() {
165
+ return this.count();
166
+ }
167
+ getOpByHash(hash) {
168
+ const row = this._stmts.getByHash.get({ $hash: hash });
169
+ return row ? rowToOp(row) : undefined;
170
+ }
171
+ count() {
172
+ const row = this._stmts.count.get();
173
+ return row?.cnt ?? 0;
174
+ }
175
+ findCommonAncestor(hashA, hashB) {
176
+ const ancestorsA = new Set;
177
+ let cursor = hashA;
178
+ while (cursor) {
179
+ ancestorsA.add(cursor);
180
+ const op = this.getOpByHash(cursor);
181
+ cursor = op?.previousHash;
182
+ }
183
+ cursor = hashB;
184
+ while (cursor) {
185
+ if (ancestorsA.has(cursor)) {
186
+ return this.getOpByHash(cursor);
187
+ }
188
+ const op = this.getOpByHash(cursor);
189
+ cursor = op?.previousHash;
190
+ }
191
+ return;
192
+ }
193
+ saveSnapshot(lastOpHash, data) {
194
+ this._stmts.saveSnapshot.run({
195
+ $lastOpHash: lastOpHash,
196
+ $data: JSON.stringify(data)
197
+ });
198
+ }
199
+ loadLatestSnapshot() {
200
+ const row = this._stmts.loadSnapshot.get();
201
+ if (!row)
202
+ return;
203
+ return {
204
+ lastOpHash: row.last_op_hash,
205
+ data: JSON.parse(row.data)
206
+ };
207
+ }
208
+ putBlob(hash, content) {
209
+ this._stmts.putBlob.run({
210
+ $hash: hash,
211
+ $content: Buffer.from(content)
212
+ });
213
+ }
214
+ getBlob(hash) {
215
+ const row = this._stmts.getBlob.get({ $hash: hash });
216
+ if (!row)
217
+ return;
218
+ return new Uint8Array(row.content);
219
+ }
220
+ hasBlob(hash) {
221
+ return !!this._stmts.hasBlob.get({ $hash: hash });
222
+ }
223
+ close() {
224
+ this.db.close();
225
+ }
226
+ }
227
+ function rowToOp(row) {
228
+ const payload = JSON.parse(row.payload);
229
+ const op = {
230
+ hash: row.hash,
231
+ kind: row.kind,
232
+ timestamp: row.timestamp,
233
+ agentId: row.agent_id
234
+ };
235
+ if (row.previous_hash)
236
+ op.previousHash = row.previous_hash;
237
+ if (payload.facts)
238
+ op.facts = payload.facts;
239
+ if (payload.links)
240
+ op.links = payload.links;
241
+ if (payload.deleteFacts)
242
+ op.deleteFacts = payload.deleteFacts;
243
+ if (payload.deleteLinks)
244
+ op.deleteLinks = payload.deleteLinks;
245
+ if (payload.vcs)
246
+ op.vcs = payload.vcs;
247
+ if (payload.signature)
248
+ op.signature = payload.signature;
249
+ return op;
250
+ }
251
+
252
+ export { SqliteKernelBackend };
@@ -0,0 +1,251 @@
1
+ // @bun
2
+ import {
3
+ __require
4
+ } from "./index-a76rekgs.js";
5
+
6
+ // src/core/persist/sqljs-backend.ts
7
+ var SCHEMA_SQL = `
8
+ CREATE TABLE IF NOT EXISTS ops (
9
+ hash TEXT PRIMARY KEY,
10
+ kind TEXT NOT NULL,
11
+ timestamp TEXT NOT NULL,
12
+ agent_id TEXT NOT NULL,
13
+ previous_hash TEXT,
14
+ payload TEXT NOT NULL
15
+ );
16
+ CREATE TABLE IF NOT EXISTS snapshots (
17
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
18
+ last_op_hash TEXT NOT NULL,
19
+ data TEXT NOT NULL,
20
+ created_at TEXT NOT NULL DEFAULT (datetime('now'))
21
+ );
22
+ CREATE TABLE IF NOT EXISTS blobs (
23
+ hash TEXT PRIMARY KEY,
24
+ content BLOB NOT NULL
25
+ );
26
+ CREATE INDEX IF NOT EXISTS idx_ops_kind ON ops(kind);
27
+ CREATE INDEX IF NOT EXISTS idx_ops_timestamp ON ops(timestamp);
28
+ CREATE INDEX IF NOT EXISTS idx_ops_agent ON ops(agent_id);
29
+ CREATE INDEX IF NOT EXISTS idx_ops_previous ON ops(previous_hash);
30
+ CREATE INDEX IF NOT EXISTS idx_snapshots_op ON snapshots(last_op_hash);
31
+ `;
32
+
33
+ class SqlJsKernelBackend {
34
+ opts;
35
+ db;
36
+ stmts;
37
+ writes = 0;
38
+ flushEvery;
39
+ initialized = false;
40
+ constructor(opts) {
41
+ this.opts = opts;
42
+ this.flushEvery = opts.autoFlushEvery ?? 50;
43
+ }
44
+ static async create(opts) {
45
+ const backend = new SqlJsKernelBackend(opts);
46
+ await backend.bootstrap();
47
+ return backend;
48
+ }
49
+ async bootstrap() {
50
+ let initSqlJs;
51
+ try {
52
+ const mod = await import("sql.js");
53
+ initSqlJs = mod.default ?? mod;
54
+ } catch (e) {
55
+ throw new Error('SqlJsKernelBackend requires the optional dependency "sql.js". Install it: npm install sql.js');
56
+ }
57
+ let sqljsDistDir = null;
58
+ if (typeof window === "undefined") {
59
+ try {
60
+ const moduleMod = await import("module");
61
+ const pathMod = await import("path");
62
+ const req = moduleMod.createRequire(import.meta.url);
63
+ const sqlJsEntry = req.resolve("sql.js");
64
+ sqljsDistDir = pathMod.dirname(sqlJsEntry);
65
+ } catch {
66
+ sqljsDistDir = null;
67
+ }
68
+ }
69
+ const SQL = await initSqlJs({
70
+ locateFile: (file) => {
71
+ if (typeof window !== "undefined")
72
+ return `/sql-wasm/${file}`;
73
+ if (sqljsDistDir)
74
+ return `${sqljsDistDir}/${file}`;
75
+ return file;
76
+ }
77
+ });
78
+ const existing = this.loadFromDisk();
79
+ this.db = existing ? new SQL.Database(existing) : new SQL.Database;
80
+ }
81
+ loadFromDisk() {
82
+ if (this.opts.dbPath === ":memory:")
83
+ return null;
84
+ try {
85
+ const fs = __require("fs");
86
+ if (!fs.existsSync(this.opts.dbPath))
87
+ return null;
88
+ return new Uint8Array(fs.readFileSync(this.opts.dbPath));
89
+ } catch {
90
+ return null;
91
+ }
92
+ }
93
+ flushToDisk() {
94
+ if (this.opts.dbPath === ":memory:")
95
+ return;
96
+ try {
97
+ const fs = __require("fs");
98
+ const path = __require("path");
99
+ const data = this.db.export();
100
+ fs.mkdirSync(path.dirname(this.opts.dbPath), { recursive: true });
101
+ const tmp = `${this.opts.dbPath}.tmp`;
102
+ fs.writeFileSync(tmp, Buffer.from(data));
103
+ fs.renameSync(tmp, this.opts.dbPath);
104
+ } catch {}
105
+ }
106
+ init() {
107
+ if (this.initialized)
108
+ return;
109
+ this.db.exec(SCHEMA_SQL);
110
+ this.prepareStatements();
111
+ this.initialized = true;
112
+ }
113
+ prepareStatements() {
114
+ this.stmts = {
115
+ insert: this.db.prepare(`INSERT OR IGNORE INTO ops (hash, kind, timestamp, agent_id, previous_hash, payload)
116
+ VALUES ($hash, $kind, $timestamp, $agentId, $previousHash, $payload)`),
117
+ readAll: this.db.prepare(`SELECT hash, kind, timestamp, agent_id, previous_hash, payload
118
+ FROM ops ORDER BY rowid ASC`),
119
+ readUntil: this.db.prepare(`SELECT hash, kind, timestamp, agent_id, previous_hash, payload
120
+ FROM ops WHERE rowid <= (SELECT rowid FROM ops WHERE hash = $hash)
121
+ ORDER BY rowid ASC`),
122
+ readAfter: this.db.prepare(`SELECT hash, kind, timestamp, agent_id, previous_hash, payload
123
+ FROM ops WHERE rowid > (SELECT rowid FROM ops WHERE hash = $hash)
124
+ ORDER BY rowid ASC`),
125
+ getByHash: this.db.prepare(`SELECT hash, kind, timestamp, agent_id, previous_hash, payload
126
+ FROM ops WHERE hash = $hash`),
127
+ getLast: this.db.prepare(`SELECT hash, kind, timestamp, agent_id, previous_hash, payload
128
+ FROM ops ORDER BY rowid DESC LIMIT 1`),
129
+ count: this.db.prepare(`SELECT COUNT(*) AS cnt FROM ops`),
130
+ saveSnapshot: this.db.prepare(`INSERT INTO snapshots (last_op_hash, data) VALUES ($lastOpHash, $data)`),
131
+ loadSnapshot: this.db.prepare(`SELECT last_op_hash, data FROM snapshots ORDER BY id DESC LIMIT 1`)
132
+ };
133
+ }
134
+ append(op) {
135
+ const payload = JSON.stringify({
136
+ facts: op.facts,
137
+ links: op.links,
138
+ ...op.deleteFacts?.length ? { deleteFacts: op.deleteFacts } : {},
139
+ ...op.deleteLinks?.length ? { deleteLinks: op.deleteLinks } : {},
140
+ ...op.vcs ? { vcs: op.vcs } : {},
141
+ ...op.signature ? { signature: op.signature } : {}
142
+ });
143
+ this.stmts.insert.run({
144
+ $hash: op.hash,
145
+ $kind: op.kind,
146
+ $timestamp: op.timestamp,
147
+ $agentId: op.agentId,
148
+ $previousHash: op.previousHash ?? null,
149
+ $payload: payload
150
+ });
151
+ this.stmts.insert.reset();
152
+ this.tickFlush();
153
+ }
154
+ readAll() {
155
+ return this.runAll(this.stmts.readAll);
156
+ }
157
+ readUntil(hash) {
158
+ return this.runAll(this.stmts.readUntil, { $hash: hash });
159
+ }
160
+ readAfter(hash) {
161
+ return this.runAll(this.stmts.readAfter, { $hash: hash });
162
+ }
163
+ readUntilTimestamp(iso) {
164
+ const stmt = this.db.prepare(`SELECT hash, kind, timestamp, agent_id, previous_hash, payload
165
+ FROM ops WHERE timestamp <= $ts ORDER BY rowid ASC`);
166
+ const rows = this.runAll(stmt, { $ts: iso });
167
+ stmt.free();
168
+ return rows;
169
+ }
170
+ getByHash(hash) {
171
+ return this.runOne(this.stmts.getByHash, { $hash: hash });
172
+ }
173
+ getLastOp() {
174
+ return this.runOne(this.stmts.getLast);
175
+ }
176
+ getOpCount() {
177
+ this.stmts.count.bind({});
178
+ const has = this.stmts.count.step();
179
+ const row = has ? this.stmts.count.getAsObject() : { cnt: 0 };
180
+ this.stmts.count.reset();
181
+ return Number(row.cnt ?? 0);
182
+ }
183
+ saveSnapshot(lastOpHash, data) {
184
+ this.stmts.saveSnapshot.run({
185
+ $lastOpHash: lastOpHash,
186
+ $data: typeof data === "string" ? data : JSON.stringify(data)
187
+ });
188
+ this.stmts.saveSnapshot.reset();
189
+ this.tickFlush();
190
+ }
191
+ loadLatestSnapshot() {
192
+ this.stmts.loadSnapshot.bind({});
193
+ const has = this.stmts.loadSnapshot.step();
194
+ if (!has) {
195
+ this.stmts.loadSnapshot.reset();
196
+ return;
197
+ }
198
+ const row = this.stmts.loadSnapshot.getAsObject();
199
+ this.stmts.loadSnapshot.reset();
200
+ return { lastOpHash: row.last_op_hash, data: row.data };
201
+ }
202
+ close() {
203
+ try {
204
+ this.flushToDisk();
205
+ } finally {
206
+ for (const s of Object.values(this.stmts ?? {}))
207
+ s?.free?.();
208
+ this.db?.close?.();
209
+ }
210
+ }
211
+ flush() {
212
+ this.flushToDisk();
213
+ }
214
+ runAll(stmt, params = {}) {
215
+ stmt.bind(params);
216
+ const rows = [];
217
+ while (stmt.step())
218
+ rows.push(rowToOp(stmt.getAsObject()));
219
+ stmt.reset();
220
+ return rows;
221
+ }
222
+ runOne(stmt, params = {}) {
223
+ stmt.bind(params);
224
+ const has = stmt.step();
225
+ const row = has ? stmt.getAsObject() : undefined;
226
+ stmt.reset();
227
+ return row ? rowToOp(row) : undefined;
228
+ }
229
+ tickFlush() {
230
+ if (this.flushEvery === 0)
231
+ return;
232
+ if (++this.writes % this.flushEvery === 0)
233
+ this.flushToDisk();
234
+ }
235
+ }
236
+ function rowToOp(row) {
237
+ const payload = JSON.parse(row.payload);
238
+ return {
239
+ hash: row.hash,
240
+ kind: row.kind,
241
+ timestamp: row.timestamp,
242
+ agentId: row.agent_id,
243
+ previousHash: row.previous_hash ?? undefined,
244
+ facts: payload.facts,
245
+ links: payload.links,
246
+ deleteFacts: payload.deleteFacts,
247
+ deleteLinks: payload.deleteLinks
248
+ };
249
+ }
250
+
251
+ export { SqlJsKernelBackend };
@@ -72,12 +72,24 @@ var init_model = __esm(() => {
72
72
  });
73
73
 
74
74
  // src/embeddings/store.ts
75
- import { Database } from "bun:sqlite";
75
+ function loadDatabaseCtor() {
76
+ if (_DatabaseCtor)
77
+ return _DatabaseCtor;
78
+ try {
79
+ const { createRequire } = __require("module");
80
+ const requireCJS = createRequire(import.meta.url);
81
+ _DatabaseCtor = requireCJS("bun:sqlite").Database;
82
+ return _DatabaseCtor;
83
+ } catch {
84
+ throw new Error("EmbeddingStore requires the Bun runtime (built-in `bun:sqlite`). " + "It is not available under Node/WebContainer.");
85
+ }
86
+ }
76
87
 
77
88
  class VectorStore {
78
89
  db;
79
90
  constructor(dbPath) {
80
- this.db = new Database(dbPath);
91
+ const DatabaseCtor = loadDatabaseCtor();
92
+ this.db = new DatabaseCtor(dbPath);
81
93
  this.db.exec("PRAGMA journal_mode=WAL;");
82
94
  this.db.exec("PRAGMA foreign_keys=ON;");
83
95
  this.db.exec(SCHEMA_SQL);
@@ -251,7 +263,7 @@ function cosineSimilarity(a, b) {
251
263
  const denom = Math.sqrt(normA) * Math.sqrt(normB);
252
264
  return denom === 0 ? 0 : dot / denom;
253
265
  }
254
- var SCHEMA_SQL = `
266
+ var _DatabaseCtor = null, SCHEMA_SQL = `
255
267
  CREATE TABLE IF NOT EXISTS chunks (
256
268
  id TEXT PRIMARY KEY,
257
269
  entity_id TEXT NOT NULL,
@@ -9,7 +9,7 @@ import {
9
9
  init_issue,
10
10
  init_merge,
11
11
  init_milestone
12
- } from "./index-0q7wbasy.js";
12
+ } from "./index-a2a394zz.js";
13
13
  import {
14
14
  init_ops,
15
15
  init_types,
@@ -42,7 +42,7 @@ import {
42
42
  triageIssue,
43
43
  unblockIssue,
44
44
  updateIssue
45
- } from "./index-0q7wbasy.js";
45
+ } from "./index-a2a394zz.js";
46
46
  import {
47
47
  getDecision,
48
48
  getDecisionChain,
@@ -4,7 +4,7 @@ import {
4
4
  } from "./index-xzym9w0m.js";
5
5
  import {
6
6
  TenantPool
7
- } from "./index-y3d71wzd.js";
7
+ } from "./index-7pjz3tsy.js";
8
8
  import {
9
9
  __require
10
10
  } from "./index-a76rekgs.js";
package/dist/index.js CHANGED
@@ -11,10 +11,10 @@ import {
11
11
  loadProfile,
12
12
  saveProfile,
13
13
  writeAgentScaffold
14
- } from "./index-q31hfjja.js";
14
+ } from "./index-jgda3xyv.js";
15
15
  import {
16
16
  VcsMiddleware
17
- } from "./index-hmdbnd4n.js";
17
+ } from "./index-hy73j9z8.js";
18
18
  import {
19
19
  BlobStore,
20
20
  addCriterion,
@@ -53,7 +53,7 @@ import {
53
53
  triageIssue,
54
54
  unblockIssue,
55
55
  updateIssue
56
- } from "./index-0q7wbasy.js";
56
+ } from "./index-a2a394zz.js";
57
57
  import"./index-65z0xfjw.js";
58
58
  import {
59
59
  DEFAULT_CONFIG,
@@ -70,11 +70,13 @@ import {
70
70
  milestoneEntityId
71
71
  } from "./index-v9b4hqa7.js";
72
72
  import {
73
- SqliteKernelBackend,
74
73
  TrellisKernel
75
- } from "./index-0zk3fx2s.js";
76
- import"./index-yhwjgfvj.js";
74
+ } from "./index-4wxa8xz4.js";
77
75
  import"./index-yp88he8n.js";
76
+ import"./index-yhwjgfvj.js";
77
+ import {
78
+ SqliteKernelBackend
79
+ } from "./index-h7zxhhhh.js";
78
80
  import"./index-a76rekgs.js";
79
81
 
80
82
  // src/index.ts
@@ -1,12 +1,13 @@
1
1
  // @bun
2
2
  import {
3
3
  TrellisDb
4
- } from "../index-7e27kvvj.js";
4
+ } from "../index-wncptktd.js";
5
5
  import"../index-xzym9w0m.js";
6
- import"../index-y3d71wzd.js";
7
- import"../index-0zk3fx2s.js";
8
- import"../index-yhwjgfvj.js";
6
+ import"../index-7pjz3tsy.js";
7
+ import"../index-4wxa8xz4.js";
9
8
  import"../index-yp88he8n.js";
9
+ import"../index-yhwjgfvj.js";
10
+ import"../index-h7zxhhhh.js";
10
11
  import"../index-a76rekgs.js";
11
12
 
12
13
  // src/react/provider.tsx
@@ -2,12 +2,13 @@
2
2
  import {
3
3
  FetchError,
4
4
  TrellisDb
5
- } from "./index-7e27kvvj.js";
5
+ } from "./index-wncptktd.js";
6
6
  import"./index-xzym9w0m.js";
7
- import"./index-y3d71wzd.js";
8
- import"./index-0zk3fx2s.js";
9
- import"./index-yhwjgfvj.js";
7
+ import"./index-7pjz3tsy.js";
8
+ import"./index-4wxa8xz4.js";
10
9
  import"./index-yp88he8n.js";
10
+ import"./index-yhwjgfvj.js";
11
+ import"./index-h7zxhhhh.js";
11
12
  import"./index-a76rekgs.js";
12
13
  export {
13
14
  TrellisDb,
@@ -8,8 +8,8 @@
8
8
  *
9
9
  * @module trellis/server
10
10
  */
11
- export { startServer } from './server.js';
12
- export type { ServerConfig } from './server.js';
11
+ export { startServer, startServerCrossRuntime } from './server.js';
12
+ export type { ServerConfig, TrellisHttpServer } from './server.js';
13
13
  export { resolveAuth, signJwt, verifyJwt, buildOAuthUrl, exchangeOAuthCode, GOOGLE_PROVIDER, GITHUB_PROVIDER, ANONYMOUS, } from './auth.js';
14
14
  export type { AuthContext, AuthConfig, OAuthProvider } from './auth.js';
15
15
  export { PermissionRegistry, PermissionError, PUBLIC_READ, FULLY_PUBLIC, OWNER_ONLY, ADMIN_ONLY, } from './permissions.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,WAAW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