@hazeljs/prompts 0.2.0-alpha.1

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 (67) hide show
  1. package/LICENSE +192 -0
  2. package/README.md +461 -0
  3. package/dist/__tests__/registry.test.d.ts +2 -0
  4. package/dist/__tests__/registry.test.d.ts.map +1 -0
  5. package/dist/__tests__/registry.test.js +255 -0
  6. package/dist/__tests__/registry.test.js.map +1 -0
  7. package/dist/__tests__/stores/file.store.test.d.ts +2 -0
  8. package/dist/__tests__/stores/file.store.test.d.ts.map +1 -0
  9. package/dist/__tests__/stores/file.store.test.js +134 -0
  10. package/dist/__tests__/stores/file.store.test.js.map +1 -0
  11. package/dist/__tests__/stores/memory.store.test.d.ts +2 -0
  12. package/dist/__tests__/stores/memory.store.test.d.ts.map +1 -0
  13. package/dist/__tests__/stores/memory.store.test.js +74 -0
  14. package/dist/__tests__/stores/memory.store.test.js.map +1 -0
  15. package/dist/__tests__/stores/multi.store.test.d.ts +2 -0
  16. package/dist/__tests__/stores/multi.store.test.d.ts.map +1 -0
  17. package/dist/__tests__/stores/multi.store.test.js +81 -0
  18. package/dist/__tests__/stores/multi.store.test.js.map +1 -0
  19. package/dist/__tests__/template.test.d.ts +2 -0
  20. package/dist/__tests__/template.test.d.ts.map +1 -0
  21. package/dist/__tests__/template.test.js +60 -0
  22. package/dist/__tests__/template.test.js.map +1 -0
  23. package/dist/index.d.ts +13 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +18 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/registry.d.ts +153 -0
  28. package/dist/registry.d.ts.map +1 -0
  29. package/dist/registry.js +288 -0
  30. package/dist/registry.js.map +1 -0
  31. package/dist/stores/database.store.d.ts +93 -0
  32. package/dist/stores/database.store.d.ts.map +1 -0
  33. package/dist/stores/database.store.js +46 -0
  34. package/dist/stores/database.store.js.map +1 -0
  35. package/dist/stores/file.store.d.ts +49 -0
  36. package/dist/stores/file.store.d.ts.map +1 -0
  37. package/dist/stores/file.store.js +105 -0
  38. package/dist/stores/file.store.js.map +1 -0
  39. package/dist/stores/index.d.ts +10 -0
  40. package/dist/stores/index.d.ts.map +1 -0
  41. package/dist/stores/index.js +14 -0
  42. package/dist/stores/index.js.map +1 -0
  43. package/dist/stores/memory.store.d.ts +21 -0
  44. package/dist/stores/memory.store.d.ts.map +1 -0
  45. package/dist/stores/memory.store.js +63 -0
  46. package/dist/stores/memory.store.js.map +1 -0
  47. package/dist/stores/multi.store.d.ts +44 -0
  48. package/dist/stores/multi.store.d.ts.map +1 -0
  49. package/dist/stores/multi.store.js +68 -0
  50. package/dist/stores/multi.store.js.map +1 -0
  51. package/dist/stores/redis.store.d.ts +65 -0
  52. package/dist/stores/redis.store.d.ts.map +1 -0
  53. package/dist/stores/redis.store.js +81 -0
  54. package/dist/stores/redis.store.js.map +1 -0
  55. package/dist/stores/store.interface.d.ts +62 -0
  56. package/dist/stores/store.interface.d.ts.map +1 -0
  57. package/dist/stores/store.interface.js +3 -0
  58. package/dist/stores/store.interface.js.map +1 -0
  59. package/dist/template.d.ts +38 -0
  60. package/dist/template.d.ts.map +1 -0
  61. package/dist/template.js +46 -0
  62. package/dist/template.js.map +1 -0
  63. package/dist/types.d.ts +15 -0
  64. package/dist/types.d.ts.map +1 -0
  65. package/dist/types.js +3 -0
  66. package/dist/types.js.map +1 -0
  67. package/package.json +74 -0
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const template_1 = require("../template");
4
+ describe('PromptTemplate', () => {
5
+ describe('constructor', () => {
6
+ it('stores template string and metadata', () => {
7
+ const tpl = new template_1.PromptTemplate('Hello {name}', { name: 'Test', version: '1.0.0' });
8
+ expect(tpl.template).toBe('Hello {name}');
9
+ expect(tpl.metadata.name).toBe('Test');
10
+ expect(tpl.metadata.version).toBe('1.0.0');
11
+ });
12
+ });
13
+ describe('render()', () => {
14
+ it('substitutes a single variable', () => {
15
+ const tpl = new template_1.PromptTemplate('Hello {name}!', { name: 'Test' });
16
+ expect(tpl.render({ name: 'World' })).toBe('Hello World!');
17
+ });
18
+ it('substitutes multiple variables', () => {
19
+ const tpl = new template_1.PromptTemplate('Context: {context}\nQuestion: {query}', { name: 'QA' });
20
+ const rendered = tpl.render({ query: 'What?', context: 'Some context' });
21
+ expect(rendered).toBe('Context: Some context\nQuestion: What?');
22
+ });
23
+ it('leaves unrecognised placeholders intact', () => {
24
+ const tpl = new template_1.PromptTemplate('Hello {name} from {place}', {
25
+ name: 'Test',
26
+ });
27
+ expect(tpl.render({ name: 'Alice' })).toBe('Hello Alice from {place}');
28
+ });
29
+ it('converts non-string values to string', () => {
30
+ const tpl = new template_1.PromptTemplate('Count: {count}', { name: 'Counter' });
31
+ expect(tpl.render({ count: 42 })).toBe('Count: 42');
32
+ });
33
+ it('handles empty template', () => {
34
+ const tpl = new template_1.PromptTemplate('', { name: 'Empty' });
35
+ expect(tpl.render({})).toBe('');
36
+ });
37
+ it('handles template with no placeholders', () => {
38
+ const tpl = new template_1.PromptTemplate('Static text only.', {
39
+ name: 'Static',
40
+ });
41
+ expect(tpl.render({})).toBe('Static text only.');
42
+ });
43
+ it('substitutes the same placeholder multiple times', () => {
44
+ const tpl = new template_1.PromptTemplate('{word} and {word} again', { name: 'Rep' });
45
+ expect(tpl.render({ word: 'yes' })).toBe('yes and yes again');
46
+ });
47
+ it('handles multiline templates', () => {
48
+ const tpl = new template_1.PromptTemplate('Line 1: {a}\nLine 2: {b}\nDone.', {
49
+ name: 'ML',
50
+ });
51
+ const result = tpl.render({ a: 'foo', b: 'bar' });
52
+ expect(result).toBe('Line 1: foo\nLine 2: bar\nDone.');
53
+ });
54
+ it('handles undefined values by leaving placeholder', () => {
55
+ const tpl = new template_1.PromptTemplate('{defined} {optional}', { name: 'Partial' });
56
+ expect(tpl.render({ defined: 'hello' })).toBe('hello {optional}');
57
+ });
58
+ });
59
+ });
60
+ //# sourceMappingURL=template.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ACnD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;YACzD,MAAM,GAAG,GAAG,IAAI,yBAAc,CAAmB,yBAAyB,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;YAC7F,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;YACrC,MAAM,GAAG,GAAG,IAAI,yBAAc,CAA2B,iCAAiC,EAAE;gBAC1F,IAAI,EAAE,IAAI;aACX,CAAC,CAAC;YACH,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;YAClD,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;YACzD,MAAM,GAAG,GAAG,IAAI,yBAAc,CAC5B,sBAAsB,EACtB,EAAE,IAAI,EAAE,SAAS,EAAE,CACpB,CAAC;YACF,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACpE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ export type { PromptMetadata } from './types';
2
+ export { PromptTemplate } from './template';
3
+ export { PromptRegistry } from './registry';
4
+ export type { PromptEntry, PromptStore } from './stores/store.interface';
5
+ export { MemoryStore } from './stores/memory.store';
6
+ export { FileStore } from './stores/file.store';
7
+ export type { FileStoreOptions } from './stores/file.store';
8
+ export { RedisStore } from './stores/redis.store';
9
+ export type { RedisAdapter, RedisStoreOptions } from './stores/redis.store';
10
+ export { DatabaseStore } from './stores/database.store';
11
+ export type { DatabaseAdapter, DatabaseStoreOptions } from './stores/database.store';
12
+ export { MultiStore } from './stores/multi.store';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5C,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACrF,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MultiStore = exports.DatabaseStore = exports.RedisStore = exports.FileStore = exports.MemoryStore = exports.PromptRegistry = exports.PromptTemplate = void 0;
4
+ var template_1 = require("./template");
5
+ Object.defineProperty(exports, "PromptTemplate", { enumerable: true, get: function () { return template_1.PromptTemplate; } });
6
+ var registry_1 = require("./registry");
7
+ Object.defineProperty(exports, "PromptRegistry", { enumerable: true, get: function () { return registry_1.PromptRegistry; } });
8
+ var memory_store_1 = require("./stores/memory.store");
9
+ Object.defineProperty(exports, "MemoryStore", { enumerable: true, get: function () { return memory_store_1.MemoryStore; } });
10
+ var file_store_1 = require("./stores/file.store");
11
+ Object.defineProperty(exports, "FileStore", { enumerable: true, get: function () { return file_store_1.FileStore; } });
12
+ var redis_store_1 = require("./stores/redis.store");
13
+ Object.defineProperty(exports, "RedisStore", { enumerable: true, get: function () { return redis_store_1.RedisStore; } });
14
+ var database_store_1 = require("./stores/database.store");
15
+ Object.defineProperty(exports, "DatabaseStore", { enumerable: true, get: function () { return database_store_1.DatabaseStore; } });
16
+ var multi_store_1 = require("./stores/multi.store");
17
+ Object.defineProperty(exports, "MultiStore", { enumerable: true, get: function () { return multi_store_1.MultiStore; } });
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,uCAA4C;AAAnC,0GAAA,cAAc,OAAA;AACvB,uCAA4C;AAAnC,0GAAA,cAAc,OAAA;AAIvB,sDAAoD;AAA3C,2GAAA,WAAW,OAAA;AACpB,kDAAgD;AAAvC,uGAAA,SAAS,OAAA;AAElB,oDAAkD;AAAzC,yGAAA,UAAU,OAAA;AAEnB,0DAAwD;AAA/C,+GAAA,aAAa,OAAA;AAEtB,oDAAkD;AAAzC,yGAAA,UAAU,OAAA"}
@@ -0,0 +1,153 @@
1
+ /**
2
+ * PromptRegistry
3
+ *
4
+ * A global static store that maps string keys to PromptTemplate instances.
5
+ *
6
+ * ## Sync API (unchanged, zero-cost, works at module load time)
7
+ * Built-in prompt files self-register at import time via `register()`.
8
+ * Application code reads prompts synchronously via `get()`.
9
+ * End-users swap any prompt with `override()` at startup.
10
+ *
11
+ * ## Store backends (optional, async)
12
+ * One or more `PromptStore` implementations can be configured to
13
+ * persist/load prompts from the file system, Redis, a database, or any
14
+ * combination via `MultiStore`. The in-memory registry always acts as the
15
+ * runtime cache; stores are used for persistence and versioning.
16
+ *
17
+ * ## Versioning
18
+ * Every `PromptTemplate.metadata.version` is tracked in the version index.
19
+ * `get(key, version)` retrieves a specific cached version.
20
+ * `getAsync(key, version?)` falls back to configured stores when the version
21
+ * is not in the in-memory cache.
22
+ *
23
+ * Key naming convention: `package:scope:action`
24
+ * e.g. `rag:graph:entity-extraction`, `agent:supervisor:routing`
25
+ *
26
+ * @example Startup override
27
+ * ```typescript
28
+ * import { PromptRegistry, PromptTemplate } from '@hazeljs/prompts';
29
+ *
30
+ * PromptRegistry.override('rag:graph:entity-extraction', new PromptTemplate(
31
+ * 'Extract entities from: {text}',
32
+ * { name: 'Custom Extraction', version: '2.0.0' },
33
+ * ));
34
+ * ```
35
+ *
36
+ * @example Multiple store backends
37
+ * ```typescript
38
+ * import { PromptRegistry, FileStore, RedisStore, MultiStore } from '@hazeljs/prompts';
39
+ *
40
+ * PromptRegistry.configure([
41
+ * new MultiStore([
42
+ * new FileStore({ filePath: './prompts/library.json' }),
43
+ * new RedisStore({ client: redisClient }),
44
+ * ]),
45
+ * ]);
46
+ *
47
+ * await PromptRegistry.saveAll(); // persist current registry to all stores
48
+ * ```
49
+ */
50
+ import { PromptTemplate } from './template';
51
+ import type { PromptStore } from './stores/store.interface';
52
+ export declare class PromptRegistry {
53
+ /** Latest version for each key. */
54
+ private static readonly latest;
55
+ /**
56
+ * All cached versions per key.
57
+ * Shape: `{ [key]: { [version]: PromptTemplate } }`
58
+ */
59
+ private static readonly versioned;
60
+ private static stores;
61
+ /**
62
+ * Replace the configured store list.
63
+ * Called once at application startup before prompts are loaded.
64
+ */
65
+ static configure(stores: PromptStore[]): void;
66
+ /**
67
+ * Append a single store to the list without replacing existing ones.
68
+ */
69
+ static addStore(store: PromptStore): void;
70
+ /** Returns the names of all configured stores (useful for diagnostics). */
71
+ static storeNames(): string[];
72
+ /**
73
+ * Register a prompt only if the key has not already been registered.
74
+ * Built-in prompt files call this so they don't clobber user overrides
75
+ * set before the module is imported.
76
+ */
77
+ static register<T extends object>(key: string, template: PromptTemplate<T>): void;
78
+ /**
79
+ * Override an existing (or register a new) prompt unconditionally.
80
+ * This is the entry point for end-user customisation.
81
+ */
82
+ static override<T extends object>(key: string, template: PromptTemplate<T>): void;
83
+ /**
84
+ * Retrieve a registered prompt by key.
85
+ *
86
+ * @param key - Registry key (e.g. `rag:graph:entity-extraction`).
87
+ * @param version - Optional specific version. Defaults to `'latest'`.
88
+ * @throws When the key (or requested version) is not found in the cache.
89
+ */
90
+ static get<T extends object>(key: string, version?: string): PromptTemplate<T>;
91
+ /** Returns `true` when a prompt is registered under the given key. */
92
+ static has(key: string, version?: string): boolean;
93
+ /** Returns all registered prompt keys (latest versions) in insertion order. */
94
+ static list(): string[];
95
+ /**
96
+ * Returns all cached version strings for a given key (excludes `'latest'`).
97
+ * Returns an empty array when the key is not registered.
98
+ */
99
+ static versions(key: string): string[];
100
+ /**
101
+ * Remove a prompt from the cache.
102
+ * Primarily useful in tests to reset state between test cases.
103
+ * Pass `version` to remove only that version; omit to remove all versions.
104
+ */
105
+ static unregister(key: string, version?: string): void;
106
+ /**
107
+ * Clear every registered prompt from the in-memory cache.
108
+ * Does NOT affect configured stores.
109
+ * Useful in tests; not recommended in production.
110
+ */
111
+ static clear(): void;
112
+ /**
113
+ * Retrieve a prompt by key, checking the in-memory cache first.
114
+ * Falls back to configured stores when the version is not cached.
115
+ * The loaded template is added to the in-memory cache for subsequent calls.
116
+ *
117
+ * @param key - Registry key.
118
+ * @param version - Specific version string; defaults to `'latest'`.
119
+ * @throws When the key is not found in the cache or any configured store.
120
+ */
121
+ static getAsync<T extends object>(key: string, version?: string): Promise<PromptTemplate<T>>;
122
+ /**
123
+ * Persist the in-memory prompt for `key` to all configured stores.
124
+ * @param key - Registry key.
125
+ * @param version - Specific cached version to persist; defaults to `'latest'` (current).
126
+ */
127
+ static save(key: string, version?: string): Promise<void>;
128
+ /**
129
+ * Persist ALL in-memory prompts (latest version of each) to all configured stores.
130
+ */
131
+ static saveAll(): Promise<void>;
132
+ /**
133
+ * Load ALL prompts from the primary configured store into the in-memory cache.
134
+ * Existing in-memory registrations are NOT overwritten (same behaviour as `register()`).
135
+ * Use `override()` after `loadAll()` to force-replace specific keys.
136
+ *
137
+ * @param overwrite - When `true`, loaded entries overwrite existing cache entries.
138
+ * Default: `false`.
139
+ */
140
+ static loadAll(overwrite?: boolean): Promise<void>;
141
+ /**
142
+ * Load a single prompt (optionally a specific version) from the first
143
+ * store that has it, cache it, and return it.
144
+ *
145
+ * @param key - Registry key.
146
+ * @param version - Specific version string; defaults to `'latest'`.
147
+ */
148
+ static load(key: string, version?: string): Promise<PromptTemplate<object> | null>;
149
+ private static setInMemory;
150
+ private static templateToEntry;
151
+ private static entryToTemplate;
152
+ }
153
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAe,MAAM,0BAA0B,CAAC;AAEzE,qBAAa,cAAc;IAGzB,mCAAmC;IAEnC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAA0C;IAExE;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAI7B;IAIJ,OAAO,CAAC,MAAM,CAAC,MAAM,CAAqB;IAI1C;;;OAGG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI;IAI7C;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAIzC,2EAA2E;IAC3E,MAAM,CAAC,UAAU,IAAI,MAAM,EAAE;IAM7B;;;;OAIG;IACH,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tD;;;;;;OAMG;WACU,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IAcxF,OAAO,CAAC,MAAM,CAAC,WAAW;IAU1B,OAAO,CAAC,MAAM,CAAC,eAAe;IAc9B,OAAO,CAAC,MAAM,CAAC,eAAe;CAG/B"}
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;;;AAEH,yCAA4C;AAG5C,MAAa,cAAc;IAqBzB,6EAA6E;IAE7E;;;OAGG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,MAAM,GAAG,GAAG,QAAQ,CAAC,QAAQ,CAAC,OAAO,IAAI,QAAQ,CAAC;QAClD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QACrC,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC9C,CAAC;IAEO,MAAM,CAAC,eAAe,CAC5B,GAAW,EACX,QAAgC,EAChC,OAAgB;QAEhB,OAAO;YACL,GAAG;YACH,OAAO,EAAE,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,OAAO,IAAI,QAAQ;YACzD,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACnC,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,eAAe,CAAmB,KAAkB;QACjE,OAAO,IAAI,yBAAc,CAAI,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC/D,CAAC;;AAjRH,wCAkRC;AAjRC,6EAA6E;AAE7E,mCAAmC;AACnC,8DAA8D;AACtC,qBAAM,GAAG,IAAI,GAAG,EAA+B,CAAC;AAExE;;;GAGG;AACqB,wBAAS,GAAG,IAAI,GAAG,EAIxC,CAAC;AAEJ,6EAA6E;AAE9D,qBAAM,GAAkB,EAAE,CAAC"}
@@ -0,0 +1,93 @@
1
+ import type { PromptEntry, PromptStore } from './store.interface';
2
+ /**
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