@wundr.io/prompt-templates 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ /**
3
+ * @wundr/prompt-templates - Jinja2-style dynamic prompt templating using Handlebars
4
+ *
5
+ * This package provides a powerful templating engine for creating dynamic AI prompts
6
+ * with support for variables, helpers, macros, and context-aware rendering.
7
+ *
8
+ * @example Basic usage
9
+ * ```typescript
10
+ * import { createEngine } from '@wundr.io/prompt-templates';
11
+ *
12
+ * const engine = createEngine();
13
+ *
14
+ * const result = engine.render(
15
+ * 'Hello, {{name}}! You are a {{role}}.',
16
+ * { variables: { name: 'Claude', role: 'helpful assistant' } }
17
+ * );
18
+ *
19
+ * console.log(result.output);
20
+ * // Output: "Hello, Claude! You are a helpful assistant."
21
+ * ```
22
+ *
23
+ * @example Using macros
24
+ * ```typescript
25
+ * import { createEngine } from '@wundr.io/prompt-templates';
26
+ *
27
+ * const engine = createEngine();
28
+ *
29
+ * const result = engine.render(
30
+ * '{{> systemRole role="a coding assistant" expertise="TypeScript" }}',
31
+ * { variables: {} }
32
+ * );
33
+ * ```
34
+ *
35
+ * @example Loading templates from files
36
+ * ```typescript
37
+ * import { createEngine } from '@wundr.io/prompt-templates';
38
+ *
39
+ * const engine = createEngine({}, '/path/to/templates');
40
+ * engine.loadTemplate('my-prompt');
41
+ *
42
+ * const result = engine.render('my-prompt', {
43
+ * variables: { user: 'John' }
44
+ * });
45
+ * ```
46
+ *
47
+ * @packageDocumentation
48
+ */
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.name = exports.version = exports.getMacroNames = exports.getMacroByName = exports.getBuiltinMacros = exports.personaMacro = exports.safetyGuardrailsMacro = exports.fewShotExamplesMacro = exports.chainOfThoughtMacro = exports.codeContextMacro = exports.toolsSectionMacro = exports.conversationHistoryMacro = exports.outputFormatMacro = exports.taskContextMacro = exports.systemRoleMacro = exports.getBuiltinHelpers = exports.numberedList = exports.bulletList = exports.wrap = exports.indent = exports.lowercase = exports.uppercase = exports.capitalize = exports.compare = exports.join = exports.truncate = exports.json = exports.formatDate = exports.repeat = exports.formatMemory = exports.codeBlock = exports.ifDefined = exports.formatTools = exports.createLoader = exports.TemplateLoader = exports.createEngine = exports.PromptTemplateEngine = exports.MacroDefinitionSchema = exports.ToolDefinitionSchema = exports.PromptTemplateConfigSchema = void 0;
51
+ // Zod schemas for validation
52
+ var types_js_1 = require("./types.js");
53
+ Object.defineProperty(exports, "PromptTemplateConfigSchema", { enumerable: true, get: function () { return types_js_1.PromptTemplateConfigSchema; } });
54
+ Object.defineProperty(exports, "ToolDefinitionSchema", { enumerable: true, get: function () { return types_js_1.ToolDefinitionSchema; } });
55
+ Object.defineProperty(exports, "MacroDefinitionSchema", { enumerable: true, get: function () { return types_js_1.MacroDefinitionSchema; } });
56
+ // Engine
57
+ var engine_js_1 = require("./engine.js");
58
+ Object.defineProperty(exports, "PromptTemplateEngine", { enumerable: true, get: function () { return engine_js_1.PromptTemplateEngine; } });
59
+ Object.defineProperty(exports, "createEngine", { enumerable: true, get: function () { return engine_js_1.createEngine; } });
60
+ // Loader
61
+ var loader_js_1 = require("./loader.js");
62
+ Object.defineProperty(exports, "TemplateLoader", { enumerable: true, get: function () { return loader_js_1.TemplateLoader; } });
63
+ Object.defineProperty(exports, "createLoader", { enumerable: true, get: function () { return loader_js_1.createLoader; } });
64
+ // Helpers
65
+ var helpers_js_1 = require("./helpers.js");
66
+ Object.defineProperty(exports, "formatTools", { enumerable: true, get: function () { return helpers_js_1.formatTools; } });
67
+ Object.defineProperty(exports, "ifDefined", { enumerable: true, get: function () { return helpers_js_1.ifDefined; } });
68
+ Object.defineProperty(exports, "codeBlock", { enumerable: true, get: function () { return helpers_js_1.codeBlock; } });
69
+ Object.defineProperty(exports, "formatMemory", { enumerable: true, get: function () { return helpers_js_1.formatMemory; } });
70
+ Object.defineProperty(exports, "repeat", { enumerable: true, get: function () { return helpers_js_1.repeat; } });
71
+ Object.defineProperty(exports, "formatDate", { enumerable: true, get: function () { return helpers_js_1.formatDate; } });
72
+ Object.defineProperty(exports, "json", { enumerable: true, get: function () { return helpers_js_1.json; } });
73
+ Object.defineProperty(exports, "truncate", { enumerable: true, get: function () { return helpers_js_1.truncate; } });
74
+ Object.defineProperty(exports, "join", { enumerable: true, get: function () { return helpers_js_1.join; } });
75
+ Object.defineProperty(exports, "compare", { enumerable: true, get: function () { return helpers_js_1.compare; } });
76
+ Object.defineProperty(exports, "capitalize", { enumerable: true, get: function () { return helpers_js_1.capitalize; } });
77
+ Object.defineProperty(exports, "uppercase", { enumerable: true, get: function () { return helpers_js_1.uppercase; } });
78
+ Object.defineProperty(exports, "lowercase", { enumerable: true, get: function () { return helpers_js_1.lowercase; } });
79
+ Object.defineProperty(exports, "indent", { enumerable: true, get: function () { return helpers_js_1.indent; } });
80
+ Object.defineProperty(exports, "wrap", { enumerable: true, get: function () { return helpers_js_1.wrap; } });
81
+ Object.defineProperty(exports, "bulletList", { enumerable: true, get: function () { return helpers_js_1.bulletList; } });
82
+ Object.defineProperty(exports, "numberedList", { enumerable: true, get: function () { return helpers_js_1.numberedList; } });
83
+ Object.defineProperty(exports, "getBuiltinHelpers", { enumerable: true, get: function () { return helpers_js_1.getBuiltinHelpers; } });
84
+ // Macros
85
+ var macros_js_1 = require("./macros.js");
86
+ Object.defineProperty(exports, "systemRoleMacro", { enumerable: true, get: function () { return macros_js_1.systemRoleMacro; } });
87
+ Object.defineProperty(exports, "taskContextMacro", { enumerable: true, get: function () { return macros_js_1.taskContextMacro; } });
88
+ Object.defineProperty(exports, "outputFormatMacro", { enumerable: true, get: function () { return macros_js_1.outputFormatMacro; } });
89
+ Object.defineProperty(exports, "conversationHistoryMacro", { enumerable: true, get: function () { return macros_js_1.conversationHistoryMacro; } });
90
+ Object.defineProperty(exports, "toolsSectionMacro", { enumerable: true, get: function () { return macros_js_1.toolsSectionMacro; } });
91
+ Object.defineProperty(exports, "codeContextMacro", { enumerable: true, get: function () { return macros_js_1.codeContextMacro; } });
92
+ Object.defineProperty(exports, "chainOfThoughtMacro", { enumerable: true, get: function () { return macros_js_1.chainOfThoughtMacro; } });
93
+ Object.defineProperty(exports, "fewShotExamplesMacro", { enumerable: true, get: function () { return macros_js_1.fewShotExamplesMacro; } });
94
+ Object.defineProperty(exports, "safetyGuardrailsMacro", { enumerable: true, get: function () { return macros_js_1.safetyGuardrailsMacro; } });
95
+ Object.defineProperty(exports, "personaMacro", { enumerable: true, get: function () { return macros_js_1.personaMacro; } });
96
+ Object.defineProperty(exports, "getBuiltinMacros", { enumerable: true, get: function () { return macros_js_1.getBuiltinMacros; } });
97
+ Object.defineProperty(exports, "getMacroByName", { enumerable: true, get: function () { return macros_js_1.getMacroByName; } });
98
+ Object.defineProperty(exports, "getMacroNames", { enumerable: true, get: function () { return macros_js_1.getMacroNames; } });
99
+ // Package info
100
+ exports.version = '1.0.3';
101
+ exports.name = '@wundr.io/prompt-templates';
102
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;;;AAqCH,6BAA6B;AAC7B,uCAIoB;AAHlB,sHAAA,0BAA0B,OAAA;AAC1B,gHAAA,oBAAoB,OAAA;AACpB,iHAAA,qBAAqB,OAAA;AAGvB,SAAS;AACT,yCAAiE;AAAxD,iHAAA,oBAAoB,OAAA;AAAE,yGAAA,YAAY,OAAA;AAE3C,SAAS;AACT,yCAA2D;AAAlD,2GAAA,cAAc,OAAA;AAAE,yGAAA,YAAY,OAAA;AAErC,UAAU;AACV,2CAmBsB;AAlBpB,yGAAA,WAAW,OAAA;AACX,uGAAA,SAAS,OAAA;AACT,uGAAA,SAAS,OAAA;AACT,0GAAA,YAAY,OAAA;AACZ,oGAAA,MAAM,OAAA;AACN,wGAAA,UAAU,OAAA;AACV,kGAAA,IAAI,OAAA;AACJ,sGAAA,QAAQ,OAAA;AACR,kGAAA,IAAI,OAAA;AACJ,qGAAA,OAAO,OAAA;AACP,wGAAA,UAAU,OAAA;AACV,uGAAA,SAAS,OAAA;AACT,uGAAA,SAAS,OAAA;AACT,oGAAA,MAAM,OAAA;AACN,kGAAA,IAAI,OAAA;AACJ,wGAAA,UAAU,OAAA;AACV,0GAAA,YAAY,OAAA;AACZ,+GAAA,iBAAiB,OAAA;AAGnB,SAAS;AACT,yCAcqB;AAbnB,4GAAA,eAAe,OAAA;AACf,6GAAA,gBAAgB,OAAA;AAChB,8GAAA,iBAAiB,OAAA;AACjB,qHAAA,wBAAwB,OAAA;AACxB,8GAAA,iBAAiB,OAAA;AACjB,6GAAA,gBAAgB,OAAA;AAChB,gHAAA,mBAAmB,OAAA;AACnB,iHAAA,oBAAoB,OAAA;AACpB,kHAAA,qBAAqB,OAAA;AACrB,yGAAA,YAAY,OAAA;AACZ,6GAAA,gBAAgB,OAAA;AAChB,2GAAA,cAAc,OAAA;AACd,0GAAA,aAAa,OAAA;AAGf,eAAe;AACF,QAAA,OAAO,GAAG,OAAO,CAAC;AAClB,QAAA,IAAI,GAAG,4BAA4B,CAAC"}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * @wundr/prompt-templates - Template file loader
3
+ */
4
+ import type { PromptTemplateConfig, LoaderOptions } from './types.js';
5
+ /**
6
+ * TemplateLoader handles loading templates from the filesystem
7
+ */
8
+ export declare class TemplateLoader {
9
+ private readonly options;
10
+ private readonly cache;
11
+ private readonly watchers;
12
+ /**
13
+ * Create a new TemplateLoader
14
+ *
15
+ * @param options - Loader configuration options
16
+ */
17
+ constructor(options?: LoaderOptions);
18
+ /**
19
+ * Load a template from a file
20
+ *
21
+ * @param templatePath - Path to the template file (relative or absolute)
22
+ * @returns Loaded template configuration
23
+ * @throws Error if template cannot be loaded or is invalid
24
+ */
25
+ loadTemplate(templatePath: string): PromptTemplateConfig;
26
+ /**
27
+ * Load a template asynchronously
28
+ *
29
+ * @param templatePath - Path to the template file
30
+ * @returns Promise resolving to loaded template configuration
31
+ */
32
+ loadTemplateAsync(templatePath: string): Promise<PromptTemplateConfig>;
33
+ /**
34
+ * Load all templates from a directory
35
+ *
36
+ * @param dirPath - Directory path to scan
37
+ * @param recursive - Whether to scan subdirectories
38
+ * @returns Array of loaded templates
39
+ */
40
+ loadTemplatesFromDirectory(dirPath?: string, recursive?: boolean): PromptTemplateConfig[];
41
+ /**
42
+ * Load raw template content from a file (without metadata parsing)
43
+ *
44
+ * @param templatePath - Path to the template file
45
+ * @returns Raw template string
46
+ */
47
+ loadRawTemplate(templatePath: string): string;
48
+ /**
49
+ * Load raw template content asynchronously
50
+ *
51
+ * @param templatePath - Path to the template file
52
+ * @returns Promise resolving to raw template string
53
+ */
54
+ loadRawTemplateAsync(templatePath: string): Promise<string>;
55
+ /**
56
+ * Check if a template exists
57
+ *
58
+ * @param templatePath - Path to the template file
59
+ * @returns True if template exists
60
+ */
61
+ templateExists(templatePath: string): boolean;
62
+ /**
63
+ * Clear the template cache
64
+ *
65
+ * @param templatePath - Optional specific template to clear, or all if not provided
66
+ */
67
+ clearCache(templatePath?: string): void;
68
+ /**
69
+ * Get cache statistics
70
+ *
71
+ * @returns Cache statistics object
72
+ */
73
+ getCacheStats(): {
74
+ size: number;
75
+ entries: string[];
76
+ };
77
+ /**
78
+ * Stop all file watchers
79
+ */
80
+ stopWatching(): void;
81
+ /**
82
+ * Resolve template path to absolute path
83
+ */
84
+ private resolveTemplatePath;
85
+ /**
86
+ * Ensure template path has the correct extension
87
+ */
88
+ private ensureExtension;
89
+ /**
90
+ * Load template configuration from file
91
+ */
92
+ private loadFromFile;
93
+ /**
94
+ * Load template configuration from file asynchronously
95
+ */
96
+ private loadFromFileAsync;
97
+ /**
98
+ * Parse template content with optional frontmatter
99
+ */
100
+ private parseTemplateContent;
101
+ /**
102
+ * Parse simple frontmatter format (key: value)
103
+ */
104
+ private parseSimpleFrontmatter;
105
+ /**
106
+ * Validate template configuration
107
+ */
108
+ private validateConfig;
109
+ /**
110
+ * Get all template files in a directory
111
+ */
112
+ private getTemplateFiles;
113
+ /**
114
+ * Set up file watcher for template changes
115
+ */
116
+ private setupWatcher;
117
+ /**
118
+ * Create a template error
119
+ */
120
+ private createError;
121
+ }
122
+ /**
123
+ * Create a template loader with default options
124
+ *
125
+ * @param options - Loader options
126
+ * @returns Configured template loader
127
+ */
128
+ export declare function createLoader(options?: LoaderOptions): TemplateLoader;
129
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EAEd,MAAM,YAAY,CAAC;AAqBpB;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0B;IAClD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyC;IAC/D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwC;IAEjE;;;;OAIG;gBACS,OAAO,GAAE,aAAkB;IAIvC;;;;;;OAMG;IACH,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,oBAAoB;IA+BxD;;;;;OAKG;IACG,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA+B5E;;;;;;OAMG;IACH,0BAA0B,CACxB,OAAO,CAAC,EAAE,MAAM,EAChB,SAAS,GAAE,OAAe,GACzB,oBAAoB,EAAE;IAuBzB;;;;;OAKG;IACH,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IAa7C;;;;;OAKG;IACG,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAejE;;;;;OAKG;IACH,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO;IAK7C;;;;OAIG;IACH,UAAU,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI;IASvC;;;;OAIG;IACH,aAAa,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE;IAOpD;;OAEG;IACH,YAAY,IAAI,IAAI;IAOpB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAU3B;;OAEG;IACH,OAAO,CAAC,eAAe;IAOvB;;OAEG;IACH,OAAO,CAAC,YAAY;IAYpB;;OAEG;YACW,iBAAiB;IAgB/B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IA2C5B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAoC9B;;OAEG;IACH,OAAO,CAAC,cAAc;IAgBtB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAyBxB;;OAEG;IACH,OAAO,CAAC,YAAY;IAWpB;;OAEG;IACH,OAAO,CAAC,WAAW;CAKpB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,cAAc,CAEpE"}
package/dist/loader.js ADDED
@@ -0,0 +1,415 @@
1
+ "use strict";
2
+ /**
3
+ * @wundr/prompt-templates - Template file loader
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.TemplateLoader = void 0;
40
+ exports.createLoader = createLoader;
41
+ const fs = __importStar(require("fs"));
42
+ const path = __importStar(require("path"));
43
+ const types_js_1 = require("./types.js");
44
+ /**
45
+ * Default loader options
46
+ */
47
+ const DEFAULT_LOADER_OPTIONS = {
48
+ baseDir: process.cwd(),
49
+ extension: '.hbs',
50
+ cache: true,
51
+ watch: false,
52
+ };
53
+ /**
54
+ * TemplateLoader handles loading templates from the filesystem
55
+ */
56
+ class TemplateLoader {
57
+ options;
58
+ cache = new Map();
59
+ watchers = new Map();
60
+ /**
61
+ * Create a new TemplateLoader
62
+ *
63
+ * @param options - Loader configuration options
64
+ */
65
+ constructor(options = {}) {
66
+ this.options = { ...DEFAULT_LOADER_OPTIONS, ...options };
67
+ }
68
+ /**
69
+ * Load a template from a file
70
+ *
71
+ * @param templatePath - Path to the template file (relative or absolute)
72
+ * @returns Loaded template configuration
73
+ * @throws Error if template cannot be loaded or is invalid
74
+ */
75
+ loadTemplate(templatePath) {
76
+ const absolutePath = this.resolveTemplatePath(templatePath);
77
+ // Check cache first
78
+ if (this.options.cache) {
79
+ const cached = this.cache.get(absolutePath);
80
+ if (cached) {
81
+ return cached.template;
82
+ }
83
+ }
84
+ // Load from filesystem
85
+ const template = this.loadFromFile(absolutePath);
86
+ // Cache the template
87
+ if (this.options.cache) {
88
+ this.cache.set(absolutePath, {
89
+ template,
90
+ loadedAt: new Date(),
91
+ filePath: absolutePath,
92
+ });
93
+ // Set up watcher if enabled
94
+ if (this.options.watch && !this.watchers.has(absolutePath)) {
95
+ this.setupWatcher(absolutePath);
96
+ }
97
+ }
98
+ return template;
99
+ }
100
+ /**
101
+ * Load a template asynchronously
102
+ *
103
+ * @param templatePath - Path to the template file
104
+ * @returns Promise resolving to loaded template configuration
105
+ */
106
+ async loadTemplateAsync(templatePath) {
107
+ const absolutePath = this.resolveTemplatePath(templatePath);
108
+ // Check cache first
109
+ if (this.options.cache) {
110
+ const cached = this.cache.get(absolutePath);
111
+ if (cached) {
112
+ return cached.template;
113
+ }
114
+ }
115
+ // Load from filesystem asynchronously
116
+ const template = await this.loadFromFileAsync(absolutePath);
117
+ // Cache the template
118
+ if (this.options.cache) {
119
+ this.cache.set(absolutePath, {
120
+ template,
121
+ loadedAt: new Date(),
122
+ filePath: absolutePath,
123
+ });
124
+ // Set up watcher if enabled
125
+ if (this.options.watch && !this.watchers.has(absolutePath)) {
126
+ this.setupWatcher(absolutePath);
127
+ }
128
+ }
129
+ return template;
130
+ }
131
+ /**
132
+ * Load all templates from a directory
133
+ *
134
+ * @param dirPath - Directory path to scan
135
+ * @param recursive - Whether to scan subdirectories
136
+ * @returns Array of loaded templates
137
+ */
138
+ loadTemplatesFromDirectory(dirPath, recursive = false) {
139
+ const absolutePath = dirPath
140
+ ? path.isAbsolute(dirPath)
141
+ ? dirPath
142
+ : path.join(this.options.baseDir, dirPath)
143
+ : this.options.baseDir;
144
+ const templates = [];
145
+ const files = this.getTemplateFiles(absolutePath, recursive);
146
+ for (const file of files) {
147
+ try {
148
+ const template = this.loadTemplate(file);
149
+ templates.push(template);
150
+ }
151
+ catch (error) {
152
+ // Log warning but continue loading other templates
153
+ console.warn(`Failed to load template ${file}:`, error);
154
+ }
155
+ }
156
+ return templates;
157
+ }
158
+ /**
159
+ * Load raw template content from a file (without metadata parsing)
160
+ *
161
+ * @param templatePath - Path to the template file
162
+ * @returns Raw template string
163
+ */
164
+ loadRawTemplate(templatePath) {
165
+ const absolutePath = this.resolveTemplatePath(templatePath);
166
+ if (!fs.existsSync(absolutePath)) {
167
+ throw this.createError('TEMPLATE_NOT_FOUND', `Template file not found: ${absolutePath}`);
168
+ }
169
+ return fs.readFileSync(absolutePath, 'utf-8');
170
+ }
171
+ /**
172
+ * Load raw template content asynchronously
173
+ *
174
+ * @param templatePath - Path to the template file
175
+ * @returns Promise resolving to raw template string
176
+ */
177
+ async loadRawTemplateAsync(templatePath) {
178
+ const absolutePath = this.resolveTemplatePath(templatePath);
179
+ try {
180
+ await fs.promises.access(absolutePath, fs.constants.R_OK);
181
+ }
182
+ catch {
183
+ throw this.createError('TEMPLATE_NOT_FOUND', `Template file not found: ${absolutePath}`);
184
+ }
185
+ return fs.promises.readFile(absolutePath, 'utf-8');
186
+ }
187
+ /**
188
+ * Check if a template exists
189
+ *
190
+ * @param templatePath - Path to the template file
191
+ * @returns True if template exists
192
+ */
193
+ templateExists(templatePath) {
194
+ const absolutePath = this.resolveTemplatePath(templatePath);
195
+ return fs.existsSync(absolutePath);
196
+ }
197
+ /**
198
+ * Clear the template cache
199
+ *
200
+ * @param templatePath - Optional specific template to clear, or all if not provided
201
+ */
202
+ clearCache(templatePath) {
203
+ if (templatePath) {
204
+ const absolutePath = this.resolveTemplatePath(templatePath);
205
+ this.cache.delete(absolutePath);
206
+ }
207
+ else {
208
+ this.cache.clear();
209
+ }
210
+ }
211
+ /**
212
+ * Get cache statistics
213
+ *
214
+ * @returns Cache statistics object
215
+ */
216
+ getCacheStats() {
217
+ return {
218
+ size: this.cache.size,
219
+ entries: Array.from(this.cache.keys()),
220
+ };
221
+ }
222
+ /**
223
+ * Stop all file watchers
224
+ */
225
+ stopWatching() {
226
+ for (const watcher of this.watchers.values()) {
227
+ watcher.close();
228
+ }
229
+ this.watchers.clear();
230
+ }
231
+ /**
232
+ * Resolve template path to absolute path
233
+ */
234
+ resolveTemplatePath(templatePath) {
235
+ // If already absolute, use as-is
236
+ if (path.isAbsolute(templatePath)) {
237
+ return this.ensureExtension(templatePath);
238
+ }
239
+ // Resolve relative to base directory
240
+ return this.ensureExtension(path.join(this.options.baseDir, templatePath));
241
+ }
242
+ /**
243
+ * Ensure template path has the correct extension
244
+ */
245
+ ensureExtension(filePath) {
246
+ if (!path.extname(filePath)) {
247
+ return filePath + this.options.extension;
248
+ }
249
+ return filePath;
250
+ }
251
+ /**
252
+ * Load template configuration from file
253
+ */
254
+ loadFromFile(filePath) {
255
+ if (!fs.existsSync(filePath)) {
256
+ throw this.createError('TEMPLATE_NOT_FOUND', `Template file not found: ${filePath}`);
257
+ }
258
+ const content = fs.readFileSync(filePath, 'utf-8');
259
+ return this.parseTemplateContent(content, filePath);
260
+ }
261
+ /**
262
+ * Load template configuration from file asynchronously
263
+ */
264
+ async loadFromFileAsync(filePath) {
265
+ try {
266
+ await fs.promises.access(filePath, fs.constants.R_OK);
267
+ }
268
+ catch {
269
+ throw this.createError('TEMPLATE_NOT_FOUND', `Template file not found: ${filePath}`);
270
+ }
271
+ const content = await fs.promises.readFile(filePath, 'utf-8');
272
+ return this.parseTemplateContent(content, filePath);
273
+ }
274
+ /**
275
+ * Parse template content with optional frontmatter
276
+ */
277
+ parseTemplateContent(content, filePath) {
278
+ const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
279
+ if (frontmatterMatch) {
280
+ // Has frontmatter - parse YAML/JSON metadata
281
+ const metadataStr = frontmatterMatch[1];
282
+ const templateStr = frontmatterMatch[2];
283
+ try {
284
+ const metadata = JSON.parse(metadataStr);
285
+ const config = {
286
+ ...metadata,
287
+ template: templateStr?.trim() || '',
288
+ id: metadata.id || path.basename(filePath, this.options.extension),
289
+ };
290
+ return this.validateConfig(config);
291
+ }
292
+ catch {
293
+ // If JSON parse fails, treat as simple key: value pairs
294
+ const metadata = this.parseSimpleFrontmatter(metadataStr);
295
+ const config = {
296
+ ...metadata,
297
+ template: templateStr?.trim() || '',
298
+ id: metadata.id || path.basename(filePath, this.options.extension),
299
+ };
300
+ return this.validateConfig(config);
301
+ }
302
+ }
303
+ // No frontmatter - create minimal config
304
+ const id = path.basename(filePath, this.options.extension);
305
+ return this.validateConfig({
306
+ id,
307
+ name: id,
308
+ version: '1.0.0',
309
+ template: content.trim(),
310
+ });
311
+ }
312
+ /**
313
+ * Parse simple frontmatter format (key: value)
314
+ */
315
+ parseSimpleFrontmatter(content) {
316
+ const result = {};
317
+ const lines = content.split('\n');
318
+ for (const line of lines) {
319
+ const match = line.match(/^(\w+):\s*(.*)$/);
320
+ if (match) {
321
+ const key = match[1];
322
+ let value = match[2]?.trim() || '';
323
+ // Try to parse as JSON for complex values
324
+ if (value && typeof value === 'string') {
325
+ if (value.startsWith('[') || value.startsWith('{')) {
326
+ try {
327
+ value = JSON.parse(value);
328
+ }
329
+ catch {
330
+ // Keep as string
331
+ }
332
+ }
333
+ else if (value === 'true') {
334
+ value = true;
335
+ }
336
+ else if (value === 'false') {
337
+ value = false;
338
+ }
339
+ else if (/^\d+$/.test(value)) {
340
+ value = parseInt(value, 10);
341
+ }
342
+ }
343
+ if (key) {
344
+ result[key] = value;
345
+ }
346
+ }
347
+ }
348
+ return result;
349
+ }
350
+ /**
351
+ * Validate template configuration
352
+ */
353
+ validateConfig(config) {
354
+ const result = types_js_1.PromptTemplateConfigSchema.safeParse(config);
355
+ if (!result.success) {
356
+ const errors = result.error.errors
357
+ .map(e => `${e.path.join('.')}: ${e.message}`)
358
+ .join(', ');
359
+ throw this.createError('INVALID_TEMPLATE_CONFIG', `Invalid template configuration: ${errors}`);
360
+ }
361
+ return result.data;
362
+ }
363
+ /**
364
+ * Get all template files in a directory
365
+ */
366
+ getTemplateFiles(dirPath, recursive) {
367
+ const files = [];
368
+ if (!fs.existsSync(dirPath)) {
369
+ return files;
370
+ }
371
+ const entries = fs.readdirSync(dirPath, { withFileTypes: true });
372
+ for (const entry of entries) {
373
+ const fullPath = path.join(dirPath, entry.name);
374
+ if (entry.isDirectory() && recursive) {
375
+ files.push(...this.getTemplateFiles(fullPath, recursive));
376
+ }
377
+ else if (entry.isFile() &&
378
+ entry.name.endsWith(this.options.extension)) {
379
+ files.push(fullPath);
380
+ }
381
+ }
382
+ return files;
383
+ }
384
+ /**
385
+ * Set up file watcher for template changes
386
+ */
387
+ setupWatcher(filePath) {
388
+ const watcher = fs.watch(filePath, eventType => {
389
+ if (eventType === 'change') {
390
+ // Invalidate cache on change
391
+ this.cache.delete(filePath);
392
+ }
393
+ });
394
+ this.watchers.set(filePath, watcher);
395
+ }
396
+ /**
397
+ * Create a template error
398
+ */
399
+ createError(code, message) {
400
+ const error = new Error(message);
401
+ error.code = code;
402
+ return error;
403
+ }
404
+ }
405
+ exports.TemplateLoader = TemplateLoader;
406
+ /**
407
+ * Create a template loader with default options
408
+ *
409
+ * @param options - Loader options
410
+ * @returns Configured template loader
411
+ */
412
+ function createLoader(options) {
413
+ return new TemplateLoader(options);
414
+ }
415
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+cH,oCAEC;AA/cD,uCAAyB;AACzB,2CAA6B;AAE7B,yCAAwD;AAQxD;;GAEG;AACH,MAAM,sBAAsB,GAA4B;IACtD,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE;IACtB,SAAS,EAAE,MAAM;IACjB,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,KAAK;CACb,CAAC;AAWF;;GAEG;AACH,MAAa,cAAc;IACR,OAAO,CAA0B;IACjC,KAAK,GAA+B,IAAI,GAAG,EAAE,CAAC;IAC9C,QAAQ,GAA8B,IAAI,GAAG,EAAE,CAAC;IAEjE;;;;OAIG;IACH,YAAY,UAAyB,EAAE;QACrC,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,sBAAsB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