@hazeljs/prompts 0.7.9 → 0.8.0

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 (2) hide show
  1. package/README.md +51 -44
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -50,7 +50,7 @@ Context: {context}
50
50
  Question: {question}
51
51
 
52
52
  Answer:`,
53
- { name: 'RAG Answer', version: '1.0.0' },
53
+ { name: 'RAG Answer', version: '1.0.0' }
54
54
  );
55
55
 
56
56
  // Register under a namespaced key — safe to call at module load time
@@ -82,8 +82,8 @@ PromptRegistry.override(
82
82
  'myapp:rag:answer',
83
83
  new PromptTemplate<{ context: string; question: string }>(
84
84
  `You are a helpful assistant. Use the context to answer.\nContext: {context}\nQ: {question}\nA:`,
85
- { name: 'Custom Answer', version: '2.0.0' },
86
- ),
85
+ { name: 'Custom Answer', version: '2.0.0' }
86
+ )
87
87
  );
88
88
  ```
89
89
 
@@ -99,7 +99,7 @@ import { PromptTemplate } from '@hazeljs/prompts';
99
99
  // Typed — TypeScript enforces the variable shape
100
100
  const tpl = new PromptTemplate<{ name: string; tier: string }>(
101
101
  'Hello {name}, you are on the {tier} plan.',
102
- { name: 'Welcome Message', version: '1.0.0' },
102
+ { name: 'Welcome Message', version: '1.0.0' }
103
103
  );
104
104
 
105
105
  const text = tpl.render({ name: 'Alice', tier: 'pro' });
@@ -107,6 +107,7 @@ const text = tpl.render({ name: 'Alice', tier: 'pro' });
107
107
  ```
108
108
 
109
109
  **Placeholder rules:**
110
+
110
111
  - Syntax: `{variableName}` (alphanumeric + underscore)
111
112
  - Missing variable → placeholder left as-is (`{missing}` stays `{missing}`)
112
113
  - Extra variables in `.render()` are silently ignored
@@ -115,9 +116,9 @@ const text = tpl.render({ name: 'Alice', tier: 'pro' });
115
116
 
116
117
  ```typescript
117
118
  interface PromptMetadata {
118
- name: string; // Human-readable display name
119
- version?: string; // Semver string — enables get(key, version)
120
- description?: string; // Optional description
119
+ name: string; // Human-readable display name
120
+ version?: string; // Semver string — enables get(key, version)
121
+ description?: string; // Optional description
121
122
  }
122
123
  ```
123
124
 
@@ -155,7 +156,7 @@ const tpl = PromptRegistry.get('myapp:qa:answer');
155
156
  const v1 = PromptRegistry.get('myapp:qa:answer', '1.0.0');
156
157
 
157
158
  // Check existence
158
- PromptRegistry.has('myapp:qa:answer'); // → boolean
159
+ PromptRegistry.has('myapp:qa:answer'); // → boolean
159
160
  PromptRegistry.has('myapp:qa:answer', '1.0.0'); // → boolean for version
160
161
 
161
162
  // List all registered keys
@@ -188,8 +189,8 @@ await PromptRegistry.save('myapp:qa:answer');
188
189
  await PromptRegistry.saveAll();
189
190
 
190
191
  // Load all prompts from the primary store into the cache
191
- await PromptRegistry.loadAll(); // does not overwrite existing cache entries
192
- await PromptRegistry.loadAll(true); // overwrite = true
192
+ await PromptRegistry.loadAll(); // does not overwrite existing cache entries
193
+ await PromptRegistry.loadAll(true); // overwrite = true
193
194
  ```
194
195
 
195
196
  ---
@@ -215,8 +216,8 @@ import { FileStore, PromptRegistry } from '@hazeljs/prompts';
215
216
 
216
217
  PromptRegistry.configure([new FileStore({ filePath: './prompts/library.json' })]);
217
218
 
218
- await PromptRegistry.saveAll(); // write to disk
219
- await PromptRegistry.loadAll(); // read from disk on startup
219
+ await PromptRegistry.saveAll(); // write to disk
220
+ await PromptRegistry.loadAll(); // read from disk on startup
220
221
  ```
221
222
 
222
223
  ### RedisStore
@@ -229,9 +230,7 @@ import { RedisStore, PromptRegistry } from '@hazeljs/prompts';
229
230
 
230
231
  const redis = new Redis({ host: 'localhost', port: 6379 });
231
232
 
232
- PromptRegistry.configure([
233
- new RedisStore({ client: redis, keyPrefix: 'hazel:prompts:' }),
234
- ]);
233
+ PromptRegistry.configure([new RedisStore({ client: redis, keyPrefix: 'hazel:prompts:' })]);
235
234
 
236
235
  // Load on startup
237
236
  await PromptRegistry.loadAll();
@@ -262,14 +261,22 @@ class PrismaPromptAdapter implements DatabaseAdapter {
262
261
  async set(entry: PromptEntry): Promise<void> {
263
262
  await this.prisma.prompt.upsert({
264
263
  where: { key: entry.key },
265
- create: { key: entry.key, template: entry.template, metadata: JSON.stringify(entry.metadata) },
264
+ create: {
265
+ key: entry.key,
266
+ template: entry.template,
267
+ metadata: JSON.stringify(entry.metadata),
268
+ },
266
269
  update: { template: entry.template, metadata: JSON.stringify(entry.metadata) },
267
270
  });
268
271
  }
269
272
 
270
273
  async getAll(): Promise<PromptEntry[]> {
271
274
  const rows = await this.prisma.prompt.findMany();
272
- return rows.map(r => ({ key: r.key, template: r.template, metadata: JSON.parse(r.metadata) }));
275
+ return rows.map((r) => ({
276
+ key: r.key,
277
+ template: r.template,
278
+ metadata: JSON.parse(r.metadata),
279
+ }));
273
280
  }
274
281
  }
275
282
 
@@ -326,8 +333,8 @@ PromptRegistry.override(
326
333
  Return JSON: { entities: [...], relationships: [...] }
327
334
 
328
335
  Text: {text}`,
329
- { name: 'Legal Entity Extraction', version: '1.0.0' },
330
- ),
336
+ { name: 'Legal Entity Extraction', version: '1.0.0' }
337
+ )
331
338
  );
332
339
 
333
340
  // Customise the supervisor routing prompt used by SupervisorAgent
@@ -338,8 +345,8 @@ PromptRegistry.override(
338
345
  Workers: {workers}
339
346
  Task: {task}
340
347
  Respond with JSON: [{ "worker": "...", "subtask": "..." }]`,
341
- { name: 'Custom Supervisor', version: '2.0.0' },
342
- ),
348
+ { name: 'Custom Supervisor', version: '2.0.0' }
349
+ )
343
350
  );
344
351
  ```
345
352
 
@@ -405,32 +412,32 @@ createMcpServer({ registry }).listenStdio();
405
412
 
406
413
  ### `PromptTemplate<TVariables>`
407
414
 
408
- | Method / Property | Description |
409
- |---|---|
410
- | `new PromptTemplate(template, metadata)` | Create a new template |
411
- | `.template` | Raw template string (read-only) |
412
- | `.metadata` | `PromptMetadata` object (read-only) |
413
- | `.render(variables: TVariables)` | Interpolate placeholders and return the rendered string |
415
+ | Method / Property | Description |
416
+ | ---------------------------------------- | ------------------------------------------------------- |
417
+ | `new PromptTemplate(template, metadata)` | Create a new template |
418
+ | `.template` | Raw template string (read-only) |
419
+ | `.metadata` | `PromptMetadata` object (read-only) |
420
+ | `.render(variables: TVariables)` | Interpolate placeholders and return the rendered string |
414
421
 
415
422
  ### `PromptRegistry` (static)
416
423
 
417
- | Method | Description |
418
- |---|---|
419
- | `register(key, template)` | Register if key not already set |
420
- | `override(key, template)` | Always register (overwrites existing) |
421
- | `get(key, version?)` | Sync get — throws if not found |
422
- | `has(key, version?)` | Returns `boolean` |
423
- | `list()` | Returns all registered keys |
424
- | `versions(key)` | Returns all cached version strings for a key |
425
- | `unregister(key, version?)` | Remove from cache |
426
- | `clear()` | Remove all from cache |
427
- | `configure(stores)` | Replace store list |
428
- | `addStore(store)` | Append a store |
429
- | `storeNames()` | Names of configured stores |
430
- | `getAsync(key, version?)` | Async get — falls back to stores |
431
- | `save(key, version?)` | Persist one prompt to all stores |
432
- | `saveAll()` | Persist all prompts to all stores |
433
- | `loadAll(overwrite?)` | Load all from primary store into cache |
424
+ | Method | Description |
425
+ | --------------------------- | -------------------------------------------- |
426
+ | `register(key, template)` | Register if key not already set |
427
+ | `override(key, template)` | Always register (overwrites existing) |
428
+ | `get(key, version?)` | Sync get — throws if not found |
429
+ | `has(key, version?)` | Returns `boolean` |
430
+ | `list()` | Returns all registered keys |
431
+ | `versions(key)` | Returns all cached version strings for a key |
432
+ | `unregister(key, version?)` | Remove from cache |
433
+ | `clear()` | Remove all from cache |
434
+ | `configure(stores)` | Replace store list |
435
+ | `addStore(store)` | Append a store |
436
+ | `storeNames()` | Names of configured stores |
437
+ | `getAsync(key, version?)` | Async get — falls back to stores |
438
+ | `save(key, version?)` | Persist one prompt to all stores |
439
+ | `saveAll()` | Persist all prompts to all stores |
440
+ | `loadAll(overwrite?)` | Load all from primary store into cache |
434
441
 
435
442
  ### `PromptStore` interface
436
443
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hazeljs/prompts",
3
- "version": "0.7.9",
3
+ "version": "0.8.0",
4
4
  "description": "Typed, overridable prompt templates for HazelJS AI, RAG, and Agent packages",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -70,5 +70,5 @@
70
70
  }
71
71
  }
72
72
  },
73
- "gitHead": "28c21c509aeca3bf2d0878fbee737d906b654c67"
73
+ "gitHead": "e0ed98ca074dd4f7472816d3c32ef576900dcca6"
74
74
  }