@hazeljs/prompts 0.2.0-beta.64
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/LICENSE +192 -0
- package/dist/__tests__/registry.test.d.ts +2 -0
- package/dist/__tests__/registry.test.d.ts.map +1 -0
- package/dist/__tests__/registry.test.js +255 -0
- package/dist/__tests__/registry.test.js.map +1 -0
- package/dist/__tests__/stores/file.store.test.d.ts +2 -0
- package/dist/__tests__/stores/file.store.test.d.ts.map +1 -0
- package/dist/__tests__/stores/file.store.test.js +134 -0
- package/dist/__tests__/stores/file.store.test.js.map +1 -0
- package/dist/__tests__/stores/memory.store.test.d.ts +2 -0
- package/dist/__tests__/stores/memory.store.test.d.ts.map +1 -0
- package/dist/__tests__/stores/memory.store.test.js +74 -0
- package/dist/__tests__/stores/memory.store.test.js.map +1 -0
- package/dist/__tests__/stores/multi.store.test.d.ts +2 -0
- package/dist/__tests__/stores/multi.store.test.d.ts.map +1 -0
- package/dist/__tests__/stores/multi.store.test.js +81 -0
- package/dist/__tests__/stores/multi.store.test.js.map +1 -0
- package/dist/__tests__/template.test.d.ts +2 -0
- package/dist/__tests__/template.test.d.ts.map +1 -0
- package/dist/__tests__/template.test.js +60 -0
- package/dist/__tests__/template.test.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/registry.d.ts +153 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +288 -0
- package/dist/registry.js.map +1 -0
- package/dist/stores/database.store.d.ts +93 -0
- package/dist/stores/database.store.d.ts.map +1 -0
- package/dist/stores/database.store.js +46 -0
- package/dist/stores/database.store.js.map +1 -0
- package/dist/stores/file.store.d.ts +49 -0
- package/dist/stores/file.store.d.ts.map +1 -0
- package/dist/stores/file.store.js +105 -0
- package/dist/stores/file.store.js.map +1 -0
- package/dist/stores/index.d.ts +10 -0
- package/dist/stores/index.d.ts.map +1 -0
- package/dist/stores/index.js +14 -0
- package/dist/stores/index.js.map +1 -0
- package/dist/stores/memory.store.d.ts +21 -0
- package/dist/stores/memory.store.d.ts.map +1 -0
- package/dist/stores/memory.store.js +63 -0
- package/dist/stores/memory.store.js.map +1 -0
- package/dist/stores/multi.store.d.ts +44 -0
- package/dist/stores/multi.store.d.ts.map +1 -0
- package/dist/stores/multi.store.js +68 -0
- package/dist/stores/multi.store.js.map +1 -0
- package/dist/stores/redis.store.d.ts +65 -0
- package/dist/stores/redis.store.d.ts.map +1 -0
- package/dist/stores/redis.store.js +81 -0
- package/dist/stores/redis.store.js.map +1 -0
- package/dist/stores/store.interface.d.ts +62 -0
- package/dist/stores/store.interface.d.ts.map +1 -0
- package/dist/stores/store.interface.js +3 -0
- package/dist/stores/store.interface.js.map +1 -0
- package/dist/template.d.ts +38 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +46 -0
- package/dist/template.js.map +1 -0
- package/dist/types.d.ts +15 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +74 -0
package/dist/registry.js
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* PromptRegistry
|
|
4
|
+
*
|
|
5
|
+
* A global static store that maps string keys to PromptTemplate instances.
|
|
6
|
+
*
|
|
7
|
+
* ## Sync API (unchanged, zero-cost, works at module load time)
|
|
8
|
+
* Built-in prompt files self-register at import time via `register()`.
|
|
9
|
+
* Application code reads prompts synchronously via `get()`.
|
|
10
|
+
* End-users swap any prompt with `override()` at startup.
|
|
11
|
+
*
|
|
12
|
+
* ## Store backends (optional, async)
|
|
13
|
+
* One or more `PromptStore` implementations can be configured to
|
|
14
|
+
* persist/load prompts from the file system, Redis, a database, or any
|
|
15
|
+
* combination via `MultiStore`. The in-memory registry always acts as the
|
|
16
|
+
* runtime cache; stores are used for persistence and versioning.
|
|
17
|
+
*
|
|
18
|
+
* ## Versioning
|
|
19
|
+
* Every `PromptTemplate.metadata.version` is tracked in the version index.
|
|
20
|
+
* `get(key, version)` retrieves a specific cached version.
|
|
21
|
+
* `getAsync(key, version?)` falls back to configured stores when the version
|
|
22
|
+
* is not in the in-memory cache.
|
|
23
|
+
*
|
|
24
|
+
* Key naming convention: `package:scope:action`
|
|
25
|
+
* e.g. `rag:graph:entity-extraction`, `agent:supervisor:routing`
|
|
26
|
+
*
|
|
27
|
+
* @example Startup override
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { PromptRegistry, PromptTemplate } from '@hazeljs/prompts';
|
|
30
|
+
*
|
|
31
|
+
* PromptRegistry.override('rag:graph:entity-extraction', new PromptTemplate(
|
|
32
|
+
* 'Extract entities from: {text}',
|
|
33
|
+
* { name: 'Custom Extraction', version: '2.0.0' },
|
|
34
|
+
* ));
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example Multiple store backends
|
|
38
|
+
* ```typescript
|
|
39
|
+
* import { PromptRegistry, FileStore, RedisStore, MultiStore } from '@hazeljs/prompts';
|
|
40
|
+
*
|
|
41
|
+
* PromptRegistry.configure([
|
|
42
|
+
* new MultiStore([
|
|
43
|
+
* new FileStore({ filePath: './prompts/library.json' }),
|
|
44
|
+
* new RedisStore({ client: redisClient }),
|
|
45
|
+
* ]),
|
|
46
|
+
* ]);
|
|
47
|
+
*
|
|
48
|
+
* await PromptRegistry.saveAll(); // persist current registry to all stores
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
|
+
exports.PromptRegistry = void 0;
|
|
53
|
+
const template_1 = require("./template");
|
|
54
|
+
class PromptRegistry {
|
|
55
|
+
// ── Store configuration ───────────────────────────────────────────────────
|
|
56
|
+
/**
|
|
57
|
+
* Replace the configured store list.
|
|
58
|
+
* Called once at application startup before prompts are loaded.
|
|
59
|
+
*/
|
|
60
|
+
static configure(stores) {
|
|
61
|
+
this.stores = [...stores];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Append a single store to the list without replacing existing ones.
|
|
65
|
+
*/
|
|
66
|
+
static addStore(store) {
|
|
67
|
+
this.stores.push(store);
|
|
68
|
+
}
|
|
69
|
+
/** Returns the names of all configured stores (useful for diagnostics). */
|
|
70
|
+
static storeNames() {
|
|
71
|
+
return this.stores.map((s) => s.name);
|
|
72
|
+
}
|
|
73
|
+
// ── Sync API (fully backward-compatible) ──────────────────────────────────
|
|
74
|
+
/**
|
|
75
|
+
* Register a prompt only if the key has not already been registered.
|
|
76
|
+
* Built-in prompt files call this so they don't clobber user overrides
|
|
77
|
+
* set before the module is imported.
|
|
78
|
+
*/
|
|
79
|
+
static register(key, template) {
|
|
80
|
+
if (!this.latest.has(key)) {
|
|
81
|
+
this.setInMemory(key, template);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Override an existing (or register a new) prompt unconditionally.
|
|
86
|
+
* This is the entry point for end-user customisation.
|
|
87
|
+
*/
|
|
88
|
+
static override(key, template) {
|
|
89
|
+
this.setInMemory(key, template);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Retrieve a registered prompt by key.
|
|
93
|
+
*
|
|
94
|
+
* @param key - Registry key (e.g. `rag:graph:entity-extraction`).
|
|
95
|
+
* @param version - Optional specific version. Defaults to `'latest'`.
|
|
96
|
+
* @throws When the key (or requested version) is not found in the cache.
|
|
97
|
+
*/
|
|
98
|
+
static get(key, version) {
|
|
99
|
+
if (version) {
|
|
100
|
+
const verMap = this.versioned.get(key);
|
|
101
|
+
const tpl = verMap?.get(version);
|
|
102
|
+
if (!tpl) {
|
|
103
|
+
throw new Error(`[PromptRegistry] Version "${version}" of prompt "${key}" not found in cache. ` +
|
|
104
|
+
`Cached versions: ${[...(verMap?.keys() ?? [])].join(', ') || '(none)'}. ` +
|
|
105
|
+
`Use getAsync() to load from a store backend.`);
|
|
106
|
+
}
|
|
107
|
+
return tpl;
|
|
108
|
+
}
|
|
109
|
+
const template = this.latest.get(key);
|
|
110
|
+
if (!template) {
|
|
111
|
+
throw new Error(`[PromptRegistry] Prompt not found: "${key}". ` +
|
|
112
|
+
`Make sure the prompt file is imported before calling get(). ` +
|
|
113
|
+
`Registered keys: ${[...this.latest.keys()].join(', ') || '(none)'}`);
|
|
114
|
+
}
|
|
115
|
+
return template;
|
|
116
|
+
}
|
|
117
|
+
/** Returns `true` when a prompt is registered under the given key. */
|
|
118
|
+
static has(key, version) {
|
|
119
|
+
if (version)
|
|
120
|
+
return this.versioned.get(key)?.has(version) ?? false;
|
|
121
|
+
return this.latest.has(key);
|
|
122
|
+
}
|
|
123
|
+
/** Returns all registered prompt keys (latest versions) in insertion order. */
|
|
124
|
+
static list() {
|
|
125
|
+
return [...this.latest.keys()];
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Returns all cached version strings for a given key (excludes `'latest'`).
|
|
129
|
+
* Returns an empty array when the key is not registered.
|
|
130
|
+
*/
|
|
131
|
+
static versions(key) {
|
|
132
|
+
const verMap = this.versioned.get(key);
|
|
133
|
+
if (!verMap)
|
|
134
|
+
return [];
|
|
135
|
+
return [...verMap.keys()].filter((v) => v !== 'latest').sort();
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Remove a prompt from the cache.
|
|
139
|
+
* Primarily useful in tests to reset state between test cases.
|
|
140
|
+
* Pass `version` to remove only that version; omit to remove all versions.
|
|
141
|
+
*/
|
|
142
|
+
static unregister(key, version) {
|
|
143
|
+
if (version) {
|
|
144
|
+
this.versioned.get(key)?.delete(version);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
this.latest.delete(key);
|
|
148
|
+
this.versioned.delete(key);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Clear every registered prompt from the in-memory cache.
|
|
153
|
+
* Does NOT affect configured stores.
|
|
154
|
+
* Useful in tests; not recommended in production.
|
|
155
|
+
*/
|
|
156
|
+
static clear() {
|
|
157
|
+
this.latest.clear();
|
|
158
|
+
this.versioned.clear();
|
|
159
|
+
}
|
|
160
|
+
// ── Async store API ───────────────────────────────────────────────────────
|
|
161
|
+
/**
|
|
162
|
+
* Retrieve a prompt by key, checking the in-memory cache first.
|
|
163
|
+
* Falls back to configured stores when the version is not cached.
|
|
164
|
+
* The loaded template is added to the in-memory cache for subsequent calls.
|
|
165
|
+
*
|
|
166
|
+
* @param key - Registry key.
|
|
167
|
+
* @param version - Specific version string; defaults to `'latest'`.
|
|
168
|
+
* @throws When the key is not found in the cache or any configured store.
|
|
169
|
+
*/
|
|
170
|
+
static async getAsync(key, version) {
|
|
171
|
+
const cached = this.latest.get(key);
|
|
172
|
+
if (!version && cached)
|
|
173
|
+
return cached;
|
|
174
|
+
if (version && this.versioned.get(key)?.has(version)) {
|
|
175
|
+
return this.versioned.get(key).get(version);
|
|
176
|
+
}
|
|
177
|
+
// Try each store in order
|
|
178
|
+
for (const store of this.stores) {
|
|
179
|
+
const entry = await store.get(key, version);
|
|
180
|
+
if (entry) {
|
|
181
|
+
const tpl = this.entryToTemplate(entry);
|
|
182
|
+
this.setInMemory(key, tpl);
|
|
183
|
+
return tpl;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
throw new Error(`[PromptRegistry] Prompt "${key}"${version ? `@${version}` : ''} not found ` +
|
|
187
|
+
`in cache or any configured store (${this.stores.map((s) => s.name).join(', ') || 'none'}).`);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Persist the in-memory prompt for `key` to all configured stores.
|
|
191
|
+
* @param key - Registry key.
|
|
192
|
+
* @param version - Specific cached version to persist; defaults to `'latest'` (current).
|
|
193
|
+
*/
|
|
194
|
+
static async save(key, version) {
|
|
195
|
+
const tpl = this.get(key, version);
|
|
196
|
+
const entry = this.templateToEntry(key, tpl, version);
|
|
197
|
+
await Promise.all(this.stores.map((s) => s.set(entry)));
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Persist ALL in-memory prompts (latest version of each) to all configured stores.
|
|
201
|
+
*/
|
|
202
|
+
static async saveAll() {
|
|
203
|
+
const tasks = [];
|
|
204
|
+
for (const key of this.latest.keys()) {
|
|
205
|
+
tasks.push(this.save(key));
|
|
206
|
+
}
|
|
207
|
+
await Promise.all(tasks);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Load ALL prompts from the primary configured store into the in-memory cache.
|
|
211
|
+
* Existing in-memory registrations are NOT overwritten (same behaviour as `register()`).
|
|
212
|
+
* Use `override()` after `loadAll()` to force-replace specific keys.
|
|
213
|
+
*
|
|
214
|
+
* @param overwrite - When `true`, loaded entries overwrite existing cache entries.
|
|
215
|
+
* Default: `false`.
|
|
216
|
+
*/
|
|
217
|
+
static async loadAll(overwrite = false) {
|
|
218
|
+
if (this.stores.length === 0)
|
|
219
|
+
return;
|
|
220
|
+
const primaryStore = this.stores[0];
|
|
221
|
+
const keys = await primaryStore.keys();
|
|
222
|
+
await Promise.all(keys.map(async (key) => {
|
|
223
|
+
const entry = await primaryStore.get(key);
|
|
224
|
+
if (!entry)
|
|
225
|
+
return;
|
|
226
|
+
const tpl = this.entryToTemplate(entry);
|
|
227
|
+
if (overwrite) {
|
|
228
|
+
this.setInMemory(key, tpl);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
this.register(key, tpl);
|
|
232
|
+
}
|
|
233
|
+
}));
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Load a single prompt (optionally a specific version) from the first
|
|
237
|
+
* store that has it, cache it, and return it.
|
|
238
|
+
*
|
|
239
|
+
* @param key - Registry key.
|
|
240
|
+
* @param version - Specific version string; defaults to `'latest'`.
|
|
241
|
+
*/
|
|
242
|
+
static async load(key, version) {
|
|
243
|
+
for (const store of this.stores) {
|
|
244
|
+
const entry = await store.get(key, version);
|
|
245
|
+
if (entry) {
|
|
246
|
+
const tpl = this.entryToTemplate(entry);
|
|
247
|
+
this.setInMemory(key, tpl);
|
|
248
|
+
return tpl;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
// ── Private helpers ───────────────────────────────────────────────────────
|
|
254
|
+
static setInMemory(key, template) {
|
|
255
|
+
this.latest.set(key, template);
|
|
256
|
+
// Track versioned entry
|
|
257
|
+
const ver = template.metadata.version ?? 'latest';
|
|
258
|
+
if (!this.versioned.has(key)) {
|
|
259
|
+
this.versioned.set(key, new Map());
|
|
260
|
+
}
|
|
261
|
+
this.versioned.get(key).set(ver, template);
|
|
262
|
+
}
|
|
263
|
+
static templateToEntry(key, template, version) {
|
|
264
|
+
return {
|
|
265
|
+
key,
|
|
266
|
+
version: version ?? template.metadata.version ?? 'latest',
|
|
267
|
+
template: template.template,
|
|
268
|
+
metadata: template.metadata,
|
|
269
|
+
storedAt: new Date().toISOString(),
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
static entryToTemplate(entry) {
|
|
273
|
+
return new template_1.PromptTemplate(entry.template, entry.metadata);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
exports.PromptRegistry = PromptRegistry;
|
|
277
|
+
// ── In-memory runtime cache ───────────────────────────────────────────────
|
|
278
|
+
/** Latest version for each key. */
|
|
279
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
280
|
+
PromptRegistry.latest = new Map();
|
|
281
|
+
/**
|
|
282
|
+
* All cached versions per key.
|
|
283
|
+
* Shape: `{ [key]: { [version]: PromptTemplate } }`
|
|
284
|
+
*/
|
|
285
|
+
PromptRegistry.versioned = new Map();
|
|
286
|
+
// ── Store backends ────────────────────────────────────────────────────────
|
|
287
|
+
PromptRegistry.stores = [];
|
|
288
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;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3
|
+
* Minimal database adapter interface.
|
|
4
|
+
* Any ORM or raw database driver can implement this:
|
|
5
|
+
* Prisma, TypeORM, Knex, `pg`, `mysql2`, etc.
|
|
6
|
+
*
|
|
7
|
+
* Expected table / collection schema:
|
|
8
|
+
* ```sql
|
|
9
|
+
* CREATE TABLE prompt_entries (
|
|
10
|
+
* key TEXT NOT NULL,
|
|
11
|
+
* version TEXT NOT NULL DEFAULT 'latest',
|
|
12
|
+
* template TEXT NOT NULL,
|
|
13
|
+
* metadata JSONB NOT NULL,
|
|
14
|
+
* stored_at TEXT NOT NULL,
|
|
15
|
+
* PRIMARY KEY (key, version)
|
|
16
|
+
* );
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example Using Prisma:
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { PrismaClient } from '@prisma/client';
|
|
22
|
+
* const prisma = new PrismaClient();
|
|
23
|
+
*
|
|
24
|
+
* PromptRegistry.addStore(new DatabaseStore({
|
|
25
|
+
* adapter: {
|
|
26
|
+
* findOne: ({ key, version }) =>
|
|
27
|
+
* prisma.promptEntry.findUnique({ where: { key_version: { key, version } } }),
|
|
28
|
+
* upsert: (entry) =>
|
|
29
|
+
* prisma.promptEntry.upsert({
|
|
30
|
+
* where: { key_version: { key: entry.key, version: entry.version } },
|
|
31
|
+
* create: entry,
|
|
32
|
+
* update: entry,
|
|
33
|
+
* }),
|
|
34
|
+
* remove: ({ key, version }) =>
|
|
35
|
+
* version
|
|
36
|
+
* ? prisma.promptEntry.deleteMany({ where: { key, version } })
|
|
37
|
+
* : prisma.promptEntry.deleteMany({ where: { key } }),
|
|
38
|
+
* findKeys: () => prisma.promptEntry.findMany({ select: { key: true } }),
|
|
39
|
+
* findVersions: ({ key }) =>
|
|
40
|
+
* prisma.promptEntry.findMany({ where: { key, NOT: { version: 'latest' } }, select: { version: true } }),
|
|
41
|
+
* }
|
|
42
|
+
* }));
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export interface DatabaseAdapter {
|
|
46
|
+
/** Find one entry by key + version (defaults to `'latest'`). Returns null/undefined if not found. */
|
|
47
|
+
findOne(params: {
|
|
48
|
+
key: string;
|
|
49
|
+
version: string;
|
|
50
|
+
}): Promise<PromptEntry | null | undefined>;
|
|
51
|
+
/** Insert or update an entry. */
|
|
52
|
+
upsert(entry: PromptEntry): Promise<void>;
|
|
53
|
+
/** Delete entries. If `version` is absent, delete all versions of the key. */
|
|
54
|
+
remove(params: {
|
|
55
|
+
key: string;
|
|
56
|
+
version?: string;
|
|
57
|
+
}): Promise<void>;
|
|
58
|
+
/** Return all distinct keys. */
|
|
59
|
+
findKeys(): Promise<Array<{
|
|
60
|
+
key: string;
|
|
61
|
+
}>>;
|
|
62
|
+
/** Return all version strings for a given key (excluding `'latest'`). */
|
|
63
|
+
findVersions(params: {
|
|
64
|
+
key: string;
|
|
65
|
+
}): Promise<Array<{
|
|
66
|
+
version: string;
|
|
67
|
+
}>>;
|
|
68
|
+
}
|
|
69
|
+
export interface DatabaseStoreOptions {
|
|
70
|
+
/** Adapter that bridges the generic interface to your specific ORM/driver. */
|
|
71
|
+
adapter: DatabaseAdapter;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* DatabaseStore
|
|
75
|
+
*
|
|
76
|
+
* Persists prompt entries to any relational or document database via a thin
|
|
77
|
+
* `DatabaseAdapter` interface. No database driver is imported directly;
|
|
78
|
+
* you supply the adapter so the package stays dependency-free.
|
|
79
|
+
*
|
|
80
|
+
* @example See `DatabaseAdapter` JSDoc for a complete Prisma example.
|
|
81
|
+
*/
|
|
82
|
+
export declare class DatabaseStore implements PromptStore {
|
|
83
|
+
readonly name = "database";
|
|
84
|
+
private readonly adapter;
|
|
85
|
+
constructor(options: DatabaseStoreOptions);
|
|
86
|
+
get(key: string, version?: string): Promise<PromptEntry | undefined>;
|
|
87
|
+
set(entry: PromptEntry): Promise<void>;
|
|
88
|
+
delete(key: string, version?: string): Promise<void>;
|
|
89
|
+
has(key: string, version?: string): Promise<boolean>;
|
|
90
|
+
keys(): Promise<string[]>;
|
|
91
|
+
versions(key: string): Promise<string[]>;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=database.store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.store.d.ts","sourceRoot":"","sources":["../../src/stores/database.store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,WAAW,eAAe;IAC9B,qGAAqG;IACrG,OAAO,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IAE3F,iCAAiC;IACjC,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1C,8EAA8E;IAC9E,MAAM,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjE,gCAAgC;IAChC,QAAQ,IAAI,OAAO,CAAC,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;IAE5C,yEAAyE;IACzE,YAAY,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;CAC5E;AAED,MAAM,WAAW,oBAAoB;IACnC,8EAA8E;IAC9E,OAAO,EAAE,eAAe,CAAC;CAC1B;AAED;;;;;;;;GAQG;AACH,qBAAa,aAAc,YAAW,WAAW;IAC/C,QAAQ,CAAC,IAAI,cAAc;IAE3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;gBAE9B,OAAO,EAAE,oBAAoB;IAInC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,SAAW,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAKtE,GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAQtC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,SAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAKtD,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAKzB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAI/C"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseStore = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* DatabaseStore
|
|
6
|
+
*
|
|
7
|
+
* Persists prompt entries to any relational or document database via a thin
|
|
8
|
+
* `DatabaseAdapter` interface. No database driver is imported directly;
|
|
9
|
+
* you supply the adapter so the package stays dependency-free.
|
|
10
|
+
*
|
|
11
|
+
* @example See `DatabaseAdapter` JSDoc for a complete Prisma example.
|
|
12
|
+
*/
|
|
13
|
+
class DatabaseStore {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.name = 'database';
|
|
16
|
+
this.adapter = options.adapter;
|
|
17
|
+
}
|
|
18
|
+
async get(key, version = 'latest') {
|
|
19
|
+
const result = await this.adapter.findOne({ key, version });
|
|
20
|
+
return result ?? undefined;
|
|
21
|
+
}
|
|
22
|
+
async set(entry) {
|
|
23
|
+
const version = entry.version || 'latest';
|
|
24
|
+
await this.adapter.upsert({ ...entry, version });
|
|
25
|
+
if (version !== 'latest') {
|
|
26
|
+
await this.adapter.upsert({ ...entry, version: 'latest' });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async delete(key, version) {
|
|
30
|
+
await this.adapter.remove({ key, version });
|
|
31
|
+
}
|
|
32
|
+
async has(key, version = 'latest') {
|
|
33
|
+
const result = await this.adapter.findOne({ key, version });
|
|
34
|
+
return result != null;
|
|
35
|
+
}
|
|
36
|
+
async keys() {
|
|
37
|
+
const rows = await this.adapter.findKeys();
|
|
38
|
+
return [...new Set(rows.map((r) => r.key))];
|
|
39
|
+
}
|
|
40
|
+
async versions(key) {
|
|
41
|
+
const rows = await this.adapter.findVersions({ key });
|
|
42
|
+
return rows.map((r) => r.version).sort();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.DatabaseStore = DatabaseStore;
|
|
46
|
+
//# sourceMappingURL=database.store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.store.js","sourceRoot":"","sources":["../../src/stores/database.store.ts"],"names":[],"mappings":";;;AAmEA;;;;;;;;GAQG;AACH,MAAa,aAAa;IAKxB,YAAY,OAA6B;QAJhC,SAAI,GAAG,UAAU,CAAC;QAKzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,OAAO,GAAG,QAAQ;QACvC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5D,OAAO,MAAM,IAAI,SAAS,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,KAAkB;QAC1B,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,QAAQ,CAAC;QAC1C,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,EAAE,O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JSON file that stores all prompt entries.
|
|
5
|
+
* The file is created (with parent directories) if it does not exist.
|
|
6
|
+
* Default: `./prompts.json` relative to the current working directory.
|
|
7
|
+
*/
|
|
8
|
+
filePath?: string;
|
|
9
|
+
/**
|
|
10
|
+
* When `true`, the JSON file is pretty-printed with 2-space indentation.
|
|
11
|
+
* Useful for human-readable prompt files under version control.
|
|
12
|
+
* Default: `true`.
|
|
13
|
+
*/
|
|
14
|
+
pretty?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* FileStore
|
|
18
|
+
*
|
|
19
|
+
* Persists prompt entries to a single JSON file on disk.
|
|
20
|
+
* Entries are keyed by `"key@version"` in the JSON object.
|
|
21
|
+
* The file is read once on first access and written on every `set`/`delete`.
|
|
22
|
+
*
|
|
23
|
+
* Suitable for small-to-medium prompt libraries committed to a repository.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* PromptRegistry.addStore(new FileStore({ filePath: './prompts/library.json' }));
|
|
28
|
+
* await PromptRegistry.saveAll();
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class FileStore implements PromptStore {
|
|
32
|
+
readonly name = "file";
|
|
33
|
+
private readonly filePath;
|
|
34
|
+
private readonly pretty;
|
|
35
|
+
private cache;
|
|
36
|
+
constructor(options?: FileStoreOptions);
|
|
37
|
+
private compoundKey;
|
|
38
|
+
private read;
|
|
39
|
+
private write;
|
|
40
|
+
get(key: string, version?: string): Promise<PromptEntry | undefined>;
|
|
41
|
+
set(entry: PromptEntry): Promise<void>;
|
|
42
|
+
delete(key: string, version?: string): Promise<void>;
|
|
43
|
+
has(key: string, version?: string): Promise<boolean>;
|
|
44
|
+
keys(): Promise<string[]>;
|
|
45
|
+
versions(key: string): Promise<string[]>;
|
|
46
|
+
/** Invalidate the in-process file cache, forcing a re-read on next access. */
|
|
47
|
+
invalidate(): void;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=file.store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.store.d.ts","sourceRoot":"","sources":["../../src/stores/file.store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAElE,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAID;;;;;;;;;;;;;;GAcG;AACH,qBAAa,SAAU,YAAW,WAAW;IAC3C,QAAQ,CAAC,IAAI,UAAU;IAEvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IACjC,OAAO,CAAC,KAAK,CAAyB;gBAE1B,OAAO,GAAE,gBAAqB;IAO1C,OAAO,CAAC,WAAW;YAIL,IAAI;YAWJ,KAAK;IASb,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,SAAW,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAKtE,GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAUtC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYpD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,SAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAKtD,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IASzB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAU9C,8EAA8E;IAC9E,UAAU,IAAI,IAAI;CAGnB"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileStore = void 0;
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
/**
|
|
7
|
+
* FileStore
|
|
8
|
+
*
|
|
9
|
+
* Persists prompt entries to a single JSON file on disk.
|
|
10
|
+
* Entries are keyed by `"key@version"` in the JSON object.
|
|
11
|
+
* The file is read once on first access and written on every `set`/`delete`.
|
|
12
|
+
*
|
|
13
|
+
* Suitable for small-to-medium prompt libraries committed to a repository.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* PromptRegistry.addStore(new FileStore({ filePath: './prompts/library.json' }));
|
|
18
|
+
* await PromptRegistry.saveAll();
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
class FileStore {
|
|
22
|
+
constructor(options = {}) {
|
|
23
|
+
this.name = 'file';
|
|
24
|
+
this.cache = null;
|
|
25
|
+
this.filePath = options.filePath ?? (0, path_1.join)(process.cwd(), 'prompts.json');
|
|
26
|
+
this.pretty = options.pretty ?? true;
|
|
27
|
+
}
|
|
28
|
+
// ── Internal helpers ──────────────────────────────────────────────────────
|
|
29
|
+
compoundKey(key, version) {
|
|
30
|
+
return `${key}@${version}`;
|
|
31
|
+
}
|
|
32
|
+
async read() {
|
|
33
|
+
if (this.cache !== null)
|
|
34
|
+
return this.cache;
|
|
35
|
+
try {
|
|
36
|
+
const raw = await (0, promises_1.readFile)(this.filePath, 'utf8');
|
|
37
|
+
this.cache = JSON.parse(raw);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
this.cache = {};
|
|
41
|
+
}
|
|
42
|
+
return this.cache;
|
|
43
|
+
}
|
|
44
|
+
async write(data) {
|
|
45
|
+
this.cache = data;
|
|
46
|
+
await (0, promises_1.mkdir)((0, path_1.dirname)(this.filePath), { recursive: true });
|
|
47
|
+
const content = this.pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);
|
|
48
|
+
await (0, promises_1.writeFile)(this.filePath, content, 'utf8');
|
|
49
|
+
}
|
|
50
|
+
// ── PromptStore interface ─────────────────────────────────────────────────
|
|
51
|
+
async get(key, version = 'latest') {
|
|
52
|
+
const data = await this.read();
|
|
53
|
+
return data[this.compoundKey(key, version)];
|
|
54
|
+
}
|
|
55
|
+
async set(entry) {
|
|
56
|
+
const data = await this.read();
|
|
57
|
+
const version = entry.version || 'latest';
|
|
58
|
+
data[this.compoundKey(entry.key, version)] = { ...entry, version };
|
|
59
|
+
if (version !== 'latest') {
|
|
60
|
+
data[this.compoundKey(entry.key, 'latest')] = { ...entry, version: 'latest' };
|
|
61
|
+
}
|
|
62
|
+
await this.write(data);
|
|
63
|
+
}
|
|
64
|
+
async delete(key, version) {
|
|
65
|
+
const data = await this.read();
|
|
66
|
+
if (version) {
|
|
67
|
+
delete data[this.compoundKey(key, version)];
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
for (const k of Object.keys(data)) {
|
|
71
|
+
if (k.startsWith(`${key}@`))
|
|
72
|
+
delete data[k];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
await this.write(data);
|
|
76
|
+
}
|
|
77
|
+
async has(key, version = 'latest') {
|
|
78
|
+
const data = await this.read();
|
|
79
|
+
return this.compoundKey(key, version) in data;
|
|
80
|
+
}
|
|
81
|
+
async keys() {
|
|
82
|
+
const data = await this.read();
|
|
83
|
+
const seen = new Set();
|
|
84
|
+
for (const compKey of Object.keys(data)) {
|
|
85
|
+
seen.add(compKey.split('@')[0]);
|
|
86
|
+
}
|
|
87
|
+
return [...seen];
|
|
88
|
+
}
|
|
89
|
+
async versions(key) {
|
|
90
|
+
const data = await this.read();
|
|
91
|
+
const vers = [];
|
|
92
|
+
for (const compKey of Object.keys(data)) {
|
|
93
|
+
const [k, v] = compKey.split('@');
|
|
94
|
+
if (k === key && v !== 'latest')
|
|
95
|
+
vers.push(v);
|
|
96
|
+
}
|
|
97
|
+
return vers.sort();
|
|
98
|
+
}
|
|
99
|
+
/** Invalidate the in-process file cache, forcing a re-read on next access. */
|
|
100
|
+
invalidate() {
|
|
101
|
+
this.cache = null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.FileStore = FileStore;
|
|
105
|
+
//# sourceMappingURL=file.store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.store.js","sourceRoot":"","sources":["../../src/stores/file.store.ts"],"names":[],"mappings":";;;AAAA,0CAAyD;AACzD,+BAAqC;AAoBrC;;;;;;;;;;;;;;GAcG;AACH,MAAa,SAAS;IAOpB,YAAY,UAA4B,EAAE;QANjC,SAAI,GAAG,MAAM,CAAC;QAIf,UAAK,GAAoB,IAAI,CAAC;QAGpC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;QACxE,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC;IACvC,CAAC;IAED,6EAA6E;IAErE,WAAW,CAAC,GAAW,EAAE,OAAe;QAC9C,OAAO,GAAG,GAAG,IAAI,OAAO,EAAE,CAAC;IAC7B,CAAC;IAEO,KAAK,CAAC,IAAI;QAChB,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC;QAC3C,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAClD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAa,CAAC;QAC3C,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAClB,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAEO,KAAK,CAAC,KAAK,CAAC,IAAc;QAChC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC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I,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACxC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAClC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,QAAQ;gBAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;IACrB,CAAC;IAED,8EAA8E;IAC9E,UAAU;QACR,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;CACF;AA7FD,8BA6FC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { PromptEntry, PromptStore } from './store.interface';
|
|
2
|
+
export { MemoryStore } from './memory.store';
|
|
3
|
+
export { FileStore } from './file.store';
|
|
4
|
+
export type { FileStoreOptions } from './file.store';
|
|
5
|
+
export { RedisStore } from './redis.store';
|
|
6
|
+
export type { RedisAdapter, RedisStoreOptions } from './redis.store';
|
|
7
|
+
export { DatabaseStore } from './database.store';
|
|
8
|
+
export type { DatabaseAdapter, DatabaseStoreOptions } from './database.store';
|
|
9
|
+
export { MultiStore } from './multi.store';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stores/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MultiStore = exports.DatabaseStore = exports.RedisStore = exports.FileStore = exports.MemoryStore = void 0;
|
|
4
|
+
var memory_store_1 = require("./memory.store");
|
|
5
|
+
Object.defineProperty(exports, "MemoryStore", { enumerable: true, get: function () { return memory_store_1.MemoryStore; } });
|
|
6
|
+
var file_store_1 = require("./file.store");
|
|
7
|
+
Object.defineProperty(exports, "FileStore", { enumerable: true, get: function () { return file_store_1.FileStore; } });
|
|
8
|
+
var redis_store_1 = require("./redis.store");
|
|
9
|
+
Object.defineProperty(exports, "RedisStore", { enumerable: true, get: function () { return redis_store_1.RedisStore; } });
|
|
10
|
+
var database_store_1 = require("./database.store");
|
|
11
|
+
Object.defineProperty(exports, "DatabaseStore", { enumerable: true, get: function () { return database_store_1.DatabaseStore; } });
|
|
12
|
+
var multi_store_1 = require("./multi.store");
|
|
13
|
+
Object.defineProperty(exports, "MultiStore", { enumerable: true, get: function () { return multi_store_1.MultiStore; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stores/index.ts"],"names":[],"mappings":";;;AACA,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,2CAAyC;AAAhC,uGAAA,SAAS,OAAA;AAElB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AAEnB,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AAEtB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA"}
|