@tangle-network/agent-app 0.1.11 → 0.1.12
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/dist/store/index.d.ts +24 -1
- package/dist/store/index.js +21 -1
- package/dist/store/index.js.map +1 -1
- package/package.json +1 -1
package/dist/store/index.d.ts
CHANGED
|
@@ -37,5 +37,28 @@ interface DatabaseProviderOptions {
|
|
|
37
37
|
* typing and their existing query syntax.
|
|
38
38
|
*/
|
|
39
39
|
declare function createDatabaseProvider<DB extends object>(options?: DatabaseProviderOptions): DatabaseProvider<DB>;
|
|
40
|
+
interface KVListResult {
|
|
41
|
+
keys: {
|
|
42
|
+
name: string;
|
|
43
|
+
}[];
|
|
44
|
+
list_complete: boolean;
|
|
45
|
+
cursor?: string;
|
|
46
|
+
}
|
|
47
|
+
interface KVStore {
|
|
48
|
+
get(key: string): Promise<string | null>;
|
|
49
|
+
put(key: string, value: string): Promise<void>;
|
|
50
|
+
delete(key: string): Promise<void>;
|
|
51
|
+
list(options?: {
|
|
52
|
+
prefix?: string;
|
|
53
|
+
cursor?: string;
|
|
54
|
+
limit?: number;
|
|
55
|
+
}): Promise<KVListResult>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* In-memory {@link KVStore} — the portable vault backend for sandbox/eval runs.
|
|
59
|
+
* Backed by a Map; `list` returns all prefix-matched keys in one complete page
|
|
60
|
+
* (no real pagination needed in-process). Seed with `initial` entries if useful.
|
|
61
|
+
*/
|
|
62
|
+
declare function createInMemoryKV(initial?: Record<string, string>): KVStore;
|
|
40
63
|
|
|
41
|
-
export { type DatabaseProvider, type DatabaseProviderOptions, createDatabaseProvider };
|
|
64
|
+
export { type DatabaseProvider, type DatabaseProviderOptions, type KVListResult, type KVStore, createDatabaseProvider, createInMemoryKV };
|
package/dist/store/index.js
CHANGED
|
@@ -25,7 +25,27 @@ function createDatabaseProvider(options = {}) {
|
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
+
function createInMemoryKV(initial) {
|
|
29
|
+
const store = new Map(initial ? Object.entries(initial) : []);
|
|
30
|
+
return {
|
|
31
|
+
async get(key) {
|
|
32
|
+
return store.has(key) ? store.get(key) : null;
|
|
33
|
+
},
|
|
34
|
+
async put(key, value) {
|
|
35
|
+
store.set(key, value);
|
|
36
|
+
},
|
|
37
|
+
async delete(key) {
|
|
38
|
+
store.delete(key);
|
|
39
|
+
},
|
|
40
|
+
async list(options) {
|
|
41
|
+
const prefix = options?.prefix ?? "";
|
|
42
|
+
const keys = [...store.keys()].filter((k) => k.startsWith(prefix)).sort().map((name) => ({ name }));
|
|
43
|
+
return { keys, list_complete: true };
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
28
47
|
export {
|
|
29
|
-
createDatabaseProvider
|
|
48
|
+
createDatabaseProvider,
|
|
49
|
+
createInMemoryKV
|
|
30
50
|
};
|
|
31
51
|
//# sourceMappingURL=index.js.map
|
package/dist/store/index.js.map
CHANGED
|
@@ -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\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"],"mappings":";AAyCO,SAAS,uBACd,UAAmC,CAAC,GACd;AACtB,QAAM,UAAU,QAAQ,mBAAmB;AAC3C,MAAI,UAAqB;AAEzB,QAAM,KAAK,IAAI,MAAM,CAAC,GAAS;AAAA,IAC7B,IAAI,SAAS,MAAM;AACjB,UAAI,CAAC,QAAS,OAAM,IAAI,MAAM,OAAO;AACrC,YAAM,QAAS,QAA6C,IAAI;AAGhE,aAAO,OAAO,UAAU,aAAc,MAA0C,KAAK,OAAO,IAAI;AAAA,IAClG;AAAA,IACA,IAAI,SAAS,MAAM;AACjB,aAAO,YAAY,QAAQ,QAAS;AAAA,IACtC;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA,YAAY,UAAc;AACxB,gBAAU;AAAA,IACZ;AAAA,IACA,UAAU;AACR,aAAO,YAAY;AAAA,IACrB;AAAA,IACA,QAAQ;AACN,gBAAU;AAAA,IACZ;AAAA,EACF;AACF;","names":[]}
|
|
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\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\nexport interface KVListResult {\n keys: { name: string }[]\n list_complete: boolean\n cursor?: string\n}\n\nexport interface KVStore {\n get(key: string): Promise<string | null>\n put(key: string, value: string): 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, string>(initial ? Object.entries(initial) : [])\n return {\n async get(key) {\n return store.has(key) ? (store.get(key) as string) : null\n },\n async put(key, value) {\n store.set(key, value)\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":";AAyCO,SAAS,uBACd,UAAmC,CAAC,GACd;AACtB,QAAM,UAAU,QAAQ,mBAAmB;AAC3C,MAAI,UAAqB;AAEzB,QAAM,KAAK,IAAI,MAAM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",
|
|
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": [
|