@tangle-network/agent-app 0.44.26 → 0.44.27

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.
@@ -63,7 +63,7 @@ import {
63
63
  verifySandboxTerminalToken,
64
64
  verifyTerminalProxyToken,
65
65
  writeProfileFilesToBox
66
- } from "../chunk-Q74BS43G.js";
66
+ } from "../chunk-7775L5NN.js";
67
67
  import "../chunk-LWSJK546.js";
68
68
  import "../chunk-CQZSAR77.js";
69
69
  import "../chunk-ICOHEZK6.js";
@@ -32,6 +32,14 @@ interface DatabaseProviderOptions {
32
32
  * existing wording so callers see a familiar message. */
33
33
  notReadyMessage?: string;
34
34
  }
35
+ /** A database driver that can execute related SQLite statements as one batch.
36
+ * Cloudflare D1 and libsql expose this method; portable local drivers may not. */
37
+ interface SqliteBatchDatabase {
38
+ batch?: (statements: [unknown, ...unknown[]]) => Promise<unknown[]>;
39
+ }
40
+ /** Execute related SQLite statements in one transactional driver batch when
41
+ * supported, or sequentially in the same order for portable local drivers. */
42
+ declare function runSqliteStatements(db: SqliteBatchDatabase, statements: [unknown, ...unknown[]]): Promise<unknown[]>;
35
43
  /**
36
44
  * Create a swappable database provider. `DB` is the injected instance's type
37
45
  * (e.g. a drizzle `Database`); the proxy is typed as `DB` so callers keep full
@@ -77,4 +85,4 @@ interface KVStore {
77
85
  */
78
86
  declare function createInMemoryKV(initial?: Record<string, string>): KVStore;
79
87
 
80
- export { type DatabaseProvider, type DatabaseProviderOptions, type KVGetWithMetadataResult, type KVListResult, type KVPutOptions, type KVStore, createDatabaseProvider, createInMemoryKV };
88
+ export { type DatabaseProvider, type DatabaseProviderOptions, type KVGetWithMetadataResult, type KVListResult, type KVPutOptions, type KVStore, type SqliteBatchDatabase, createDatabaseProvider, createInMemoryKV, runSqliteStatements };
@@ -1,57 +1,11 @@
1
- // src/store/index.ts
2
- function createDatabaseProvider(options = {}) {
3
- const message = options.notReadyMessage ?? "Database not initialized \u2014 call setDatabase() first.";
4
- let current = null;
5
- const db = new Proxy({}, {
6
- get(_target, prop) {
7
- if (!current) throw new Error(message);
8
- const value = current[prop];
9
- return typeof value === "function" ? value.bind(current) : value;
10
- },
11
- has(_target, prop) {
12
- return current !== null && prop in current;
13
- }
14
- });
15
- return {
16
- db,
17
- setDatabase(database) {
18
- current = database;
19
- },
20
- isReady() {
21
- return current !== null;
22
- },
23
- reset() {
24
- current = null;
25
- }
26
- };
27
- }
28
- function createInMemoryKV(initial) {
29
- const store = new Map(
30
- initial ? Object.entries(initial).map(([k, v]) => [k, { value: v, metadata: null }]) : []
31
- );
32
- return {
33
- async get(key) {
34
- return store.get(key)?.value ?? null;
35
- },
36
- async getWithMetadata(key) {
37
- const entry = store.get(key);
38
- return { value: entry?.value ?? null, metadata: entry?.metadata ?? null };
39
- },
40
- async put(key, value, options) {
41
- store.set(key, { value, metadata: options?.metadata ?? null });
42
- },
43
- async delete(key) {
44
- store.delete(key);
45
- },
46
- async list(options) {
47
- const prefix = options?.prefix ?? "";
48
- const keys = [...store.keys()].filter((k) => k.startsWith(prefix)).sort().map((name) => ({ name }));
49
- return { keys, list_complete: true };
50
- }
51
- };
52
- }
1
+ import {
2
+ createDatabaseProvider,
3
+ createInMemoryKV,
4
+ runSqliteStatements
5
+ } from "../chunk-LRHVCVEW.js";
53
6
  export {
54
7
  createDatabaseProvider,
55
- createInMemoryKV
8
+ createInMemoryKV,
9
+ runSqliteStatements
56
10
  };
57
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/store/index.ts"],"sourcesContent":["/**\n * Swappable database provider — the seam that decouples the agent's persistence\n * from any one driver.\n *\n * The agent core (and the app's server modules) import a single `db` and use it\n * directly. That `db` is a lazy proxy: it forwards to whatever database instance\n * the runtime injects via {@link DatabaseProvider.setDatabase}. So the SAME core\n * runs on:\n * - Cloudflare D1 (`setDatabase(drizzle(d1, schema))`) — prod\n * - SQLite / miniflare (`setDatabase(drizzle(betterSqlite, schema))`) — eval / the portable inner shell\n * - libsql / Turso, Postgres (`setDatabase(drizzle(client, schema))`) — a future hosted DB\n *\n * Adding a new database is one adapter (a drizzle instance over a new driver) +\n * a `setDatabase` call. None of the modules importing `db` change. Substrate-\n * free and driver-agnostic: this module knows nothing about D1, drizzle, or any\n * schema — it only forwards property access to the injected instance.\n */\n\nexport interface DatabaseProvider<DB> {\n /** The injected database, as a lazy proxy. Throws (with `notReadyMessage`)\n * on any access before {@link setDatabase} is called. */\n readonly db: DB\n /** Inject the active database instance (any driver's client). */\n setDatabase(database: DB): void\n /** True once a database has been injected. */\n isReady(): boolean\n /** Clear the injected database (next access throws again). Mainly for tests. */\n reset(): void\n}\n\n/** Define options for configuring database provider behavior including error messaging */\nexport interface DatabaseProviderOptions {\n /** Error thrown when `db` is accessed before injection. Keep the product's\n * existing wording so callers see a familiar message. */\n notReadyMessage?: string\n}\n\n/**\n * Create a swappable database provider. `DB` is the injected instance's type\n * (e.g. a drizzle `Database`); the proxy is typed as `DB` so callers keep full\n * typing and their existing query syntax.\n */\nexport function createDatabaseProvider<DB extends object>(\n options: DatabaseProviderOptions = {},\n): DatabaseProvider<DB> {\n const message = options.notReadyMessage ?? 'Database not initialized — call setDatabase() first.'\n let current: DB | null = null\n\n const db = new Proxy({} as DB, {\n get(_target, prop) {\n if (!current) throw new Error(message)\n const value = (current as Record<string | symbol, unknown>)[prop]\n // Bind methods to the real instance so `this` resolves correctly through\n // the proxy (works for drizzle's query builders and class-based stores).\n return typeof value === 'function' ? (value as (...args: unknown[]) => unknown).bind(current) : value\n },\n has(_target, prop) {\n return current !== null && prop in (current as object)\n },\n })\n\n return {\n db,\n setDatabase(database: DB) {\n current = database\n },\n isReady() {\n return current !== null\n },\n reset() {\n current = null\n },\n }\n}\n\n// ── KV store port (the vault backend) ───────────────────────────────────────\n//\n// The vault (workspace files) is a key/value store. In production it's a\n// Cloudflare `KVNamespace`; the portable inner shell injects an in-memory (or\n// other) implementation. This is the subset of the KV API the vault uses —\n// `KVNamespace` satisfies it structurally, so prod passes the binding unchanged,\n// and `createInMemoryKV()` supplies the portable adapter for sandbox/eval.\n\n/** Describe the result of listing keys with completion status and optional pagination cursor */\nexport interface KVListResult {\n keys: { name: string }[]\n list_complete: boolean\n cursor?: string\n}\n\n/** Define options for storing a key-value pair with expiration and metadata settings */\nexport interface KVPutOptions {\n expiration?: number\n expirationTtl?: number\n metadata?: unknown\n}\n\n/** Resolve a key-value pair retrieval including its associated metadata and value */\nexport interface KVGetWithMetadataResult {\n value: string | null\n metadata: unknown | null\n}\n\n/** Define a key-value store interface for asynchronous data retrieval, storage, deletion, and listing */\nexport interface KVStore {\n get(key: string): Promise<string | null>\n /** Read a value with its stored metadata (e.g. the vault's encrypted/hasPII flags). */\n getWithMetadata(key: string): Promise<KVGetWithMetadataResult>\n put(key: string, value: string, options?: KVPutOptions): Promise<void>\n delete(key: string): Promise<void>\n list(options?: { prefix?: string; cursor?: string; limit?: number }): Promise<KVListResult>\n}\n\n/**\n * In-memory {@link KVStore} — the portable vault backend for sandbox/eval runs.\n * Backed by a Map; `list` returns all prefix-matched keys in one complete page\n * (no real pagination needed in-process). Seed with `initial` entries if useful.\n */\nexport function createInMemoryKV(initial?: Record<string, string>): KVStore {\n const store = new Map<string, { value: string; metadata: unknown }>(\n initial ? Object.entries(initial).map(([k, v]) => [k, { value: v, metadata: null }]) : [],\n )\n return {\n async get(key) {\n return store.get(key)?.value ?? null\n },\n async getWithMetadata(key) {\n const entry = store.get(key)\n return { value: entry?.value ?? null, metadata: entry?.metadata ?? null }\n },\n async put(key, value, options) {\n store.set(key, { value, metadata: options?.metadata ?? null })\n },\n async delete(key) {\n store.delete(key)\n },\n async list(options) {\n const prefix = options?.prefix ?? ''\n const keys = [...store.keys()]\n .filter((k) => k.startsWith(prefix))\n .sort()\n .map((name) => ({ name }))\n return { keys, list_complete: true }\n },\n }\n}\n"],"mappings":";AA0CO,SAAS,uBACd,UAAmC,CAAC,GACd;AACtB,QAAM,UAAU,QAAQ,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,CAAC,GAAG,MAAM,KAAK,CAAC,EAC1B,OAAO,CAAC,MAAM,EAAE,WAAW,MAAM,CAAC,EAClC,KAAK,EACL,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE;AAC3B,aAAO,EAAE,MAAM,eAAe,KAAK;AAAA,IACrC;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-app",
3
- "version": "0.44.26",
3
+ "version": "0.44.27",
4
4
  "packageManager": "pnpm@10.33.4",
5
5
  "description": "Application-shell framework for Tangle agent products: a bounded tool loop, the structured agent→app tool side channel, integration-hub client, per-workspace billing, and crypto — composed over the Tangle agent substrate through typed seams.",
6
6
  "keywords": [