@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,62 @@
1
+ import type { PromptMetadata } from '../types';
2
+ /**
3
+ * A serializable snapshot of one version of a registered prompt.
4
+ * This is what gets persisted to / loaded from any store backend.
5
+ */
6
+ export interface PromptEntry {
7
+ /** Registry key (e.g. `rag:graph:entity-extraction`). */
8
+ key: string;
9
+ /**
10
+ * Semantic version string (e.g. `1.0.0`).
11
+ * Defaults to `'latest'` when `PromptMetadata.version` is not set.
12
+ */
13
+ version: string;
14
+ /** Raw template string with `{variable}` placeholders. */
15
+ template: string;
16
+ /** Human-readable metadata. */
17
+ metadata: PromptMetadata;
18
+ /** ISO-8601 timestamp of when the entry was written to the store. */
19
+ storedAt: string;
20
+ }
21
+ /**
22
+ * PromptStore
23
+ *
24
+ * Async storage contract implemented by every backend.
25
+ * All methods are async so implementations can use any I/O mechanism
26
+ * (file system, Redis, SQL/NoSQL, HTTP, etc.) without blocking the event loop.
27
+ *
28
+ * Versioning semantics:
29
+ * - Every entry is stored under a `(key, version)` pair.
30
+ * - `version` defaults to `'latest'` when not supplied.
31
+ * - `get(key)` returns the `'latest'` version.
32
+ * - `get(key, '1.2.0')` returns a specific historical version.
33
+ */
34
+ export interface PromptStore {
35
+ /** Human-readable identifier shown in error messages and logs. */
36
+ readonly name: string;
37
+ /**
38
+ * Retrieve the entry for `key` at `version` (defaults to `'latest'`).
39
+ * Returns `undefined` when the entry does not exist.
40
+ */
41
+ get(key: string, version?: string): Promise<PromptEntry | undefined>;
42
+ /**
43
+ * Persist `entry` to the store.
44
+ * If an entry with the same `(key, version)` already exists it is overwritten.
45
+ */
46
+ set(entry: PromptEntry): Promise<void>;
47
+ /**
48
+ * Remove the entry for `key` at `version`.
49
+ * If `version` is omitted, ALL versions of the key are removed.
50
+ */
51
+ delete(key: string, version?: string): Promise<void>;
52
+ /** Returns `true` when an entry for `key@version` exists. */
53
+ has(key: string, version?: string): Promise<boolean>;
54
+ /** Returns all distinct keys currently stored (deduplicated across versions). */
55
+ keys(): Promise<string[]>;
56
+ /**
57
+ * Returns all stored version strings for a given key in ascending semver order.
58
+ * Returns an empty array when the key does not exist.
59
+ */
60
+ versions(key: string): Promise<string[]>;
61
+ }
62
+ //# sourceMappingURL=store.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.interface.d.ts","sourceRoot":"","sources":["../../src/stores/store.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,yDAAyD;IACzD,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,0DAA0D;IAC1D,QAAQ,EAAE,MAAM,CAAC;IACjB,+BAA+B;IAC/B,QAAQ,EAAE,cAAc,CAAC;IACzB,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,WAAW;IAC1B,kEAAkE;IAClE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IAErE;;;OAGG;IACH,GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvC;;;OAGG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErD,6DAA6D;IAC7D,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAErD,iFAAiF;IACjF,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAE1B;;;OAGG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CAC1C"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=store.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.interface.js","sourceRoot":"","sources":["../../src/stores/store.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * PromptTemplate<TVariables>
3
+ *
4
+ * A typed, reusable prompt template that interpolates named `{variable}`
5
+ * placeholders with caller-supplied values.
6
+ *
7
+ * Usage:
8
+ * ```typescript
9
+ * const tpl = new PromptTemplate<{ query: string; context: string }>(
10
+ * 'Answer the question using the context.\nContext: {context}\nQuestion: {query}',
11
+ * { name: 'RAG Answer', version: '1.0.0' },
12
+ * );
13
+ *
14
+ * const rendered = tpl.render({ query: 'What is TypeScript?', context: '...' });
15
+ * ```
16
+ */
17
+ import type { PromptMetadata } from './types';
18
+ export declare class PromptTemplate<TVariables extends object = Record<string, unknown>> {
19
+ /** The raw template string containing `{variableName}` placeholders. */
20
+ readonly template: string;
21
+ /** Descriptive metadata — used for debugging and the registry. */
22
+ readonly metadata: PromptMetadata;
23
+ constructor(
24
+ /** The raw template string containing `{variableName}` placeholders. */
25
+ template: string,
26
+ /** Descriptive metadata — used for debugging and the registry. */
27
+ metadata: PromptMetadata);
28
+ /**
29
+ * Render the template by substituting all `{key}` placeholders with the
30
+ * corresponding values from `variables`.
31
+ *
32
+ * - If a placeholder key is present in `variables` its value is `String()`-cast.
33
+ * - If a placeholder key is NOT present it is left as-is (e.g. `{missing}`),
34
+ * making missing variables easy to spot.
35
+ */
36
+ render(variables: TVariables): string;
37
+ }
38
+ //# sourceMappingURL=template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,qBAAa,cAAc,CAAC,UAAU,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAE3E,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,EAAE,MAAM;IACzB,kEAAkE;IAClE,QAAQ,CAAC,QAAQ,EAAE,cAAc;;IAHjC,wEAAwE;IAC/D,QAAQ,EAAE,MAAM;IACzB,kEAAkE;IACzD,QAAQ,EAAE,cAAc;IAGnC;;;;;;;OAOG;IACH,MAAM,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM;CAOtC"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /**
3
+ * PromptTemplate<TVariables>
4
+ *
5
+ * A typed, reusable prompt template that interpolates named `{variable}`
6
+ * placeholders with caller-supplied values.
7
+ *
8
+ * Usage:
9
+ * ```typescript
10
+ * const tpl = new PromptTemplate<{ query: string; context: string }>(
11
+ * 'Answer the question using the context.\nContext: {context}\nQuestion: {query}',
12
+ * { name: 'RAG Answer', version: '1.0.0' },
13
+ * );
14
+ *
15
+ * const rendered = tpl.render({ query: 'What is TypeScript?', context: '...' });
16
+ * ```
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.PromptTemplate = void 0;
20
+ class PromptTemplate {
21
+ constructor(
22
+ /** The raw template string containing `{variableName}` placeholders. */
23
+ template,
24
+ /** Descriptive metadata — used for debugging and the registry. */
25
+ metadata) {
26
+ this.template = template;
27
+ this.metadata = metadata;
28
+ }
29
+ /**
30
+ * Render the template by substituting all `{key}` placeholders with the
31
+ * corresponding values from `variables`.
32
+ *
33
+ * - If a placeholder key is present in `variables` its value is `String()`-cast.
34
+ * - If a placeholder key is NOT present it is left as-is (e.g. `{missing}`),
35
+ * making missing variables easy to spot.
36
+ */
37
+ render(variables) {
38
+ const vars = variables;
39
+ return this.template.replace(/\{(\w+)\}/g, (match, key) => {
40
+ const value = vars[key];
41
+ return value !== undefined ? String(value) : match;
42
+ });
43
+ }
44
+ }
45
+ exports.PromptTemplate = PromptTemplate;
46
+ //# sourceMappingURL=template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template.js","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAIH,MAAa,cAAc;IACzB;IACE,wEAAwE;IAC/D,QAAgB;IACzB,kEAAkE;IACzD,QAAwB;QAFxB,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,aAAQ,GAAR,QAAQ,CAAgB;IAChC,CAAC;IAEJ;;;;;;;OAOG;IACH,MAAM,CAAC,SAAqB;QAC1B,MAAM,IAAI,GAAG,SAAoC,CAAC;QAClD,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,KAAK,EAAE,GAAW,EAAE,EAAE;YAChE,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;YACxB,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACrD,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAvBD,wCAuBC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Metadata attached to every PromptTemplate.
3
+ */
4
+ export interface PromptMetadata {
5
+ /** Unique human-readable name for this prompt. */
6
+ name: string;
7
+ /** Optional short description of what this prompt does. */
8
+ description?: string;
9
+ /**
10
+ * Semantic version string (e.g. '1.0.0').
11
+ * Bump when the prompt text changes meaningfully to aid debugging.
12
+ */
13
+ version?: string;
14
+ }
15
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@hazeljs/prompts",
3
+ "version": "0.2.0-alpha.1",
4
+ "description": "Typed, overridable prompt templates for HazelJS AI, RAG, and Agent packages",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc --skipLibCheck",
12
+ "test": "jest --coverage --passWithNoTests",
13
+ "lint": "eslint \"src/**/*.ts\"",
14
+ "lint:fix": "eslint \"src/**/*.ts\" --fix",
15
+ "clean": "rm -rf dist"
16
+ },
17
+ "devDependencies": {
18
+ "@types/jest": "^29.5.14",
19
+ "@types/node": "^20.17.50",
20
+ "@typescript-eslint/eslint-plugin": "^8.18.2",
21
+ "@typescript-eslint/parser": "^8.18.2",
22
+ "eslint": "^8.56.0",
23
+ "jest": "^29.7.0",
24
+ "ts-jest": "^29.1.2",
25
+ "typescript": "^5.3.3"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/hazeljs/hazeljs.git",
33
+ "directory": "packages/prompts"
34
+ },
35
+ "keywords": [
36
+ "hazeljs",
37
+ "prompts",
38
+ "prompt-template",
39
+ "llm",
40
+ "ai",
41
+ "rag",
42
+ "agent"
43
+ ],
44
+ "author": "Muhammad Arslan <muhammad.arslan@hazeljs.com>",
45
+ "license": "Apache-2.0",
46
+ "bugs": {
47
+ "url": "https://github.com/hazeljs/hazel-js/issues"
48
+ },
49
+ "homepage": "https://hazeljs.com",
50
+ "jest": {
51
+ "preset": "ts-jest",
52
+ "testEnvironment": "node",
53
+ "testMatch": [
54
+ "**/src/__tests__/**/*.test.ts"
55
+ ],
56
+ "collectCoverageFrom": [
57
+ "src/**/*.ts",
58
+ "!src/__tests__/**",
59
+ "!src/index.ts",
60
+ "!src/stores/index.ts",
61
+ "!src/stores/redis.store.ts",
62
+ "!src/stores/database.store.ts"
63
+ ],
64
+ "coverageThreshold": {
65
+ "global": {
66
+ "statements": 90,
67
+ "branches": 80,
68
+ "functions": 90,
69
+ "lines": 90
70
+ }
71
+ }
72
+ },
73
+ "gitHead": "cbc5ee2c12ced28fd0576faf13c5f078c1e8421e"
74
+ }