promptopskit 0.3.1 → 0.3.4
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/README.md +28 -2
- package/SKILL.md +121 -107
- package/dist/{chunk-LRRSI4ON.js → chunk-R5PKK6Y7.js} +6 -5
- package/dist/chunk-R5PKK6Y7.js.map +1 -0
- package/dist/chunk-S5YHGHK5.js +311 -0
- package/dist/chunk-S5YHGHK5.js.map +1 -0
- package/dist/{chunk-DDXFDVA6.js → chunk-U7IDX2P7.js} +7 -4
- package/dist/chunk-U7IDX2P7.js.map +1 -0
- package/dist/{chunk-LNZS3TIJ.js → chunk-UJA7XBQZ.js} +6 -5
- package/dist/chunk-UJA7XBQZ.js.map +1 -0
- package/dist/{chunk-Y2YYEGOY.js → chunk-VU3WKLFI.js} +6 -5
- package/dist/chunk-VU3WKLFI.js.map +1 -0
- package/dist/cli/index.js +36 -16
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +258 -199
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +24 -163
- package/dist/index.js.map +1 -1
- package/dist/providers/anthropic.cjs +470 -2
- package/dist/providers/anthropic.cjs.map +1 -1
- package/dist/providers/anthropic.d.cts +1 -1
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +3 -2
- package/dist/providers/gemini.cjs +470 -2
- package/dist/providers/gemini.cjs.map +1 -1
- package/dist/providers/gemini.d.cts +1 -1
- package/dist/providers/gemini.d.ts +1 -1
- package/dist/providers/gemini.js +3 -2
- package/dist/providers/openai.cjs +470 -2
- package/dist/providers/openai.cjs.map +1 -1
- package/dist/providers/openai.d.cts +1 -1
- package/dist/providers/openai.d.ts +1 -1
- package/dist/providers/openai.js +3 -2
- package/dist/providers/openrouter.cjs +472 -4
- package/dist/providers/openrouter.cjs.map +1 -1
- package/dist/providers/openrouter.d.cts +1 -1
- package/dist/providers/openrouter.d.ts +1 -1
- package/dist/providers/openrouter.js +4 -3
- package/dist/types-CgA7_wNI.d.cts +68 -0
- package/dist/types-D_-336jx.d.ts +68 -0
- package/dist/usagetap/index.d.cts +1 -1
- package/dist/usagetap/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-DDXFDVA6.js.map +0 -1
- package/dist/chunk-DGFBS7YW.js +0 -101
- package/dist/chunk-DGFBS7YW.js.map +0 -1
- package/dist/chunk-LNZS3TIJ.js.map +0 -1
- package/dist/chunk-LRRSI4ON.js.map +0 -1
- package/dist/chunk-Y2YYEGOY.js.map +0 -1
- package/dist/types-BsYdPHTU.d.ts +0 -43
- package/dist/types-DC-jI6iV.d.cts +0 -43
package/dist/index.cjs
CHANGED
|
@@ -64,10 +64,156 @@ __export(src_exports, {
|
|
|
64
64
|
withUsageTapCall: () => withUsageTapCall
|
|
65
65
|
});
|
|
66
66
|
module.exports = __toCommonJS(src_exports);
|
|
67
|
+
var import_node_path4 = require("path");
|
|
68
|
+
|
|
69
|
+
// src/renderer/interpolate.ts
|
|
70
|
+
var VARIABLE_RE = /\{\{\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\}\}/g;
|
|
71
|
+
var ESCAPED_OPEN = /\\\{\\\{/g;
|
|
72
|
+
var ESCAPE_PLACEHOLDER = "\0ESCAPED_OPEN\0";
|
|
73
|
+
function interpolate(template, variables, options = {}) {
|
|
74
|
+
const { strict = false } = options;
|
|
75
|
+
let result = template.replace(ESCAPED_OPEN, ESCAPE_PLACEHOLDER);
|
|
76
|
+
result = result.replace(VARIABLE_RE, (match, name) => {
|
|
77
|
+
if (name in variables) {
|
|
78
|
+
return variables[name];
|
|
79
|
+
}
|
|
80
|
+
if (strict) {
|
|
81
|
+
throw new Error(`Missing required variable: "${name}"`);
|
|
82
|
+
}
|
|
83
|
+
return match;
|
|
84
|
+
});
|
|
85
|
+
result = result.replaceAll(ESCAPE_PLACEHOLDER, "{{");
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
function extractVariables(template) {
|
|
89
|
+
const vars = /* @__PURE__ */ new Set();
|
|
90
|
+
let match;
|
|
91
|
+
const re = new RegExp(VARIABLE_RE.source, "g");
|
|
92
|
+
while ((match = re.exec(template)) !== null) {
|
|
93
|
+
vars.add(match[1]);
|
|
94
|
+
}
|
|
95
|
+
return [...vars];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// src/renderer/renderer.ts
|
|
99
|
+
function renderSections(asset, options = {}) {
|
|
100
|
+
const { variables = {}, strict = false } = options;
|
|
101
|
+
const result = {};
|
|
102
|
+
if (asset.sections.system_instructions) {
|
|
103
|
+
result.system_instructions = interpolate(
|
|
104
|
+
asset.sections.system_instructions,
|
|
105
|
+
variables,
|
|
106
|
+
{ strict }
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
if (asset.sections.prompt_template) {
|
|
110
|
+
result.prompt_template = interpolate(
|
|
111
|
+
asset.sections.prompt_template,
|
|
112
|
+
variables,
|
|
113
|
+
{ strict }
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/overrides/apply-overrides.ts
|
|
120
|
+
function applyOverrides(asset, options = {}) {
|
|
121
|
+
let result = { ...asset };
|
|
122
|
+
if (options.environment && result.environments?.[options.environment]) {
|
|
123
|
+
result = mergeOverride(result, result.environments[options.environment]);
|
|
124
|
+
}
|
|
125
|
+
if (options.tier && result.tiers?.[options.tier]) {
|
|
126
|
+
result = mergeOverride(result, result.tiers[options.tier]);
|
|
127
|
+
}
|
|
128
|
+
if (options.runtime) {
|
|
129
|
+
result = mergeOverride(result, options.runtime);
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
function mergeOverride(base, override) {
|
|
134
|
+
const result = { ...base };
|
|
135
|
+
if (override.model !== void 0) result.model = override.model;
|
|
136
|
+
if (override.fallback_models !== void 0) result.fallback_models = override.fallback_models;
|
|
137
|
+
if (override.tools !== void 0) result.tools = override.tools;
|
|
138
|
+
if (override.reasoning !== void 0) {
|
|
139
|
+
result.reasoning = { ...result.reasoning, ...override.reasoning };
|
|
140
|
+
}
|
|
141
|
+
if (override.sampling !== void 0) {
|
|
142
|
+
result.sampling = { ...result.sampling, ...override.sampling };
|
|
143
|
+
}
|
|
144
|
+
if (override.response !== void 0) {
|
|
145
|
+
result.response = { ...result.response, ...override.response };
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// src/providers/resolve-asset.ts
|
|
151
|
+
function resolveAssetForProvider(asset, runtime = {}) {
|
|
152
|
+
if (!runtime.environment && !runtime.tier && !runtime.runtime) {
|
|
153
|
+
return asset;
|
|
154
|
+
}
|
|
155
|
+
return applyOverrides(asset, {
|
|
156
|
+
environment: runtime.environment,
|
|
157
|
+
tier: runtime.tier,
|
|
158
|
+
runtime: runtime.runtime
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/prompt-resolution.ts
|
|
67
163
|
var import_promises3 = require("fs/promises");
|
|
68
164
|
var import_node_fs2 = require("fs");
|
|
69
165
|
var import_node_path3 = require("path");
|
|
70
166
|
|
|
167
|
+
// src/cache.ts
|
|
168
|
+
var import_node_fs = require("fs");
|
|
169
|
+
var PromptCache = class {
|
|
170
|
+
cache = /* @__PURE__ */ new Map();
|
|
171
|
+
maxSize;
|
|
172
|
+
constructor(maxSize = 100) {
|
|
173
|
+
this.maxSize = maxSize;
|
|
174
|
+
}
|
|
175
|
+
get(filePath) {
|
|
176
|
+
const entry = this.cache.get(filePath);
|
|
177
|
+
if (!entry) return void 0;
|
|
178
|
+
try {
|
|
179
|
+
const stat = (0, import_node_fs.statSync)(filePath);
|
|
180
|
+
if (stat.mtimeMs !== entry.mtime) {
|
|
181
|
+
this.cache.delete(filePath);
|
|
182
|
+
return void 0;
|
|
183
|
+
}
|
|
184
|
+
} catch {
|
|
185
|
+
this.cache.delete(filePath);
|
|
186
|
+
return void 0;
|
|
187
|
+
}
|
|
188
|
+
this.cache.delete(filePath);
|
|
189
|
+
this.cache.set(filePath, entry);
|
|
190
|
+
return entry.value;
|
|
191
|
+
}
|
|
192
|
+
set(filePath, value) {
|
|
193
|
+
try {
|
|
194
|
+
const stat = (0, import_node_fs.statSync)(filePath);
|
|
195
|
+
if (this.cache.has(filePath)) {
|
|
196
|
+
this.cache.delete(filePath);
|
|
197
|
+
} else if (this.cache.size >= this.maxSize) {
|
|
198
|
+
const oldest = this.cache.keys().next().value;
|
|
199
|
+
if (oldest) this.cache.delete(oldest);
|
|
200
|
+
}
|
|
201
|
+
this.cache.set(filePath, { value, mtime: stat.mtimeMs });
|
|
202
|
+
} catch {
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
clear() {
|
|
206
|
+
this.cache.clear();
|
|
207
|
+
}
|
|
208
|
+
get size() {
|
|
209
|
+
return this.cache.size;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// src/composition/resolve-includes.ts
|
|
214
|
+
var import_promises2 = require("fs/promises");
|
|
215
|
+
var import_node_path2 = require("path");
|
|
216
|
+
|
|
71
217
|
// src/parser/parser.ts
|
|
72
218
|
var import_gray_matter = __toESM(require("gray-matter"), 1);
|
|
73
219
|
|
|
@@ -324,8 +470,6 @@ function applyDefaults(asset, defaults) {
|
|
|
324
470
|
}
|
|
325
471
|
|
|
326
472
|
// src/composition/resolve-includes.ts
|
|
327
|
-
var import_promises2 = require("fs/promises");
|
|
328
|
-
var import_node_path2 = require("path");
|
|
329
473
|
async function resolveIncludes(asset, basePath, visited = /* @__PURE__ */ new Set()) {
|
|
330
474
|
if (!asset.includes || asset.includes.length === 0) {
|
|
331
475
|
return asset;
|
|
@@ -362,101 +506,119 @@ async function resolveIncludes(asset, basePath, visited = /* @__PURE__ */ new Se
|
|
|
362
506
|
};
|
|
363
507
|
}
|
|
364
508
|
|
|
365
|
-
// src/
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
509
|
+
// src/prompt-resolution.ts
|
|
510
|
+
var sharedPromptCache = new PromptCache();
|
|
511
|
+
async function loadPromptAsset(promptPath, config, promptCache = sharedPromptCache) {
|
|
512
|
+
const mode = config.mode ?? "auto";
|
|
513
|
+
if (mode !== "source-only" && config.compiledDir) {
|
|
514
|
+
const compiledFile = (0, import_node_path3.resolve)(config.compiledDir, promptPath + ".json");
|
|
515
|
+
if ((0, import_node_fs2.existsSync)(compiledFile)) {
|
|
516
|
+
if (mode === "auto") {
|
|
517
|
+
const sourceFile = (0, import_node_path3.resolve)(config.sourceDir, promptPath + ".md");
|
|
518
|
+
if ((0, import_node_fs2.existsSync)(sourceFile)) {
|
|
519
|
+
const compiledMtime = (0, import_node_fs2.statSync)(compiledFile).mtimeMs;
|
|
520
|
+
const sourceMtime = (0, import_node_fs2.statSync)(sourceFile).mtimeMs;
|
|
521
|
+
if (sourceMtime > compiledMtime) {
|
|
522
|
+
console.warn(
|
|
523
|
+
`[promptopskit] Warning: compiled artifact for "${promptPath}" is older than source .md file.
|
|
524
|
+
Run "promptopskit compile" or switch to source-only mode.`
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
const content = await (0, import_promises3.readFile)(compiledFile, "utf-8");
|
|
530
|
+
return JSON.parse(content);
|
|
531
|
+
}
|
|
532
|
+
if (mode === "compiled-only") {
|
|
533
|
+
throw new Error(
|
|
534
|
+
`Compiled artifact not found: ${compiledFile}
|
|
535
|
+
Run "promptopskit compile" to generate it.`
|
|
536
|
+
);
|
|
537
|
+
}
|
|
392
538
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
function interpolate(template, variables, options = {}) {
|
|
401
|
-
const { strict = false } = options;
|
|
402
|
-
let result = template.replace(ESCAPED_OPEN, ESCAPE_PLACEHOLDER);
|
|
403
|
-
result = result.replace(VARIABLE_RE, (match, name) => {
|
|
404
|
-
if (name in variables) {
|
|
405
|
-
return variables[name];
|
|
539
|
+
if (mode !== "compiled-only") {
|
|
540
|
+
const sourceFile = (0, import_node_path3.resolve)(config.sourceDir, promptPath + ".md");
|
|
541
|
+
if (config.cache !== false) {
|
|
542
|
+
const cached = promptCache.get(sourceFile);
|
|
543
|
+
if (cached) {
|
|
544
|
+
return cached;
|
|
545
|
+
}
|
|
406
546
|
}
|
|
407
|
-
if (
|
|
408
|
-
|
|
547
|
+
if (!(0, import_node_fs2.existsSync)(sourceFile)) {
|
|
548
|
+
const paths = [sourceFile];
|
|
549
|
+
if (config.compiledDir) {
|
|
550
|
+
paths.unshift((0, import_node_path3.resolve)(config.compiledDir, promptPath + ".json"));
|
|
551
|
+
}
|
|
552
|
+
throw new Error(
|
|
553
|
+
`Prompt not found: "${promptPath}"
|
|
554
|
+
Searched:
|
|
555
|
+
${paths.map((candidate) => ` - ${candidate}`).join("\n")}`
|
|
556
|
+
);
|
|
409
557
|
}
|
|
410
|
-
|
|
558
|
+
const { asset } = await loadPromptFile(sourceFile, { defaultsRoot: config.sourceDir });
|
|
559
|
+
if (config.cache !== false) {
|
|
560
|
+
promptCache.set(sourceFile, asset);
|
|
561
|
+
}
|
|
562
|
+
return asset;
|
|
563
|
+
}
|
|
564
|
+
throw new Error(`Prompt not found: "${promptPath}"`);
|
|
565
|
+
}
|
|
566
|
+
async function resolvePromptAsset(promptPath, config, options = {}, promptCache = sharedPromptCache) {
|
|
567
|
+
let asset = await loadPromptAsset(promptPath, config, promptCache);
|
|
568
|
+
const sourceFile = (0, import_node_path3.resolve)(config.sourceDir, promptPath + ".md");
|
|
569
|
+
if (asset.includes && asset.includes.length > 0 && (0, import_node_fs2.existsSync)(sourceFile)) {
|
|
570
|
+
asset = await resolveIncludes(asset, sourceFile);
|
|
571
|
+
}
|
|
572
|
+
asset = applyOverrides(asset, {
|
|
573
|
+
environment: options.environment,
|
|
574
|
+
tier: options.tier,
|
|
575
|
+
runtime: options.runtime
|
|
411
576
|
});
|
|
412
|
-
|
|
413
|
-
return result;
|
|
577
|
+
return asset;
|
|
414
578
|
}
|
|
415
|
-
function
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
}
|
|
422
|
-
return [...vars];
|
|
579
|
+
function resolveInlinePromptSource(source, options = {}) {
|
|
580
|
+
const { asset } = parsePrompt(source);
|
|
581
|
+
return applyOverrides(asset, {
|
|
582
|
+
environment: options.environment,
|
|
583
|
+
tier: options.tier,
|
|
584
|
+
runtime: options.runtime
|
|
585
|
+
});
|
|
423
586
|
}
|
|
424
587
|
|
|
425
|
-
// src/
|
|
426
|
-
function
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
);
|
|
588
|
+
// src/providers/prompt-input.ts
|
|
589
|
+
function isPromptLookup(input) {
|
|
590
|
+
return "path" in input && typeof input.path === "string" && "sourceDir" in input;
|
|
591
|
+
}
|
|
592
|
+
function isInlinePromptSource(input) {
|
|
593
|
+
return "source" in input && typeof input.source === "string";
|
|
594
|
+
}
|
|
595
|
+
async function resolveProviderPromptInput(input, runtime) {
|
|
596
|
+
if (isPromptLookup(input)) {
|
|
597
|
+
return resolvePromptAsset(input.path, input, runtime);
|
|
435
598
|
}
|
|
436
|
-
if (
|
|
437
|
-
|
|
438
|
-
asset.sections.prompt_template,
|
|
439
|
-
variables,
|
|
440
|
-
{ strict }
|
|
441
|
-
);
|
|
599
|
+
if (isInlinePromptSource(input)) {
|
|
600
|
+
return resolveInlinePromptSource(input.source, runtime);
|
|
442
601
|
}
|
|
443
|
-
return
|
|
602
|
+
return input;
|
|
444
603
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
604
|
+
function withPromptInputSupport(adapter) {
|
|
605
|
+
const validatePrompt = async (input, runtime) => {
|
|
606
|
+
const resolved = await resolveProviderPromptInput(input, runtime);
|
|
607
|
+
return adapter.validate(resolved, runtime);
|
|
608
|
+
};
|
|
609
|
+
const renderPrompt2 = async (input, runtime) => {
|
|
610
|
+
const resolved = await resolveProviderPromptInput(input, runtime);
|
|
611
|
+
return adapter.render(resolved, runtime);
|
|
612
|
+
};
|
|
613
|
+
return {
|
|
614
|
+
...adapter,
|
|
615
|
+
validatePrompt,
|
|
616
|
+
renderPrompt: renderPrompt2
|
|
617
|
+
};
|
|
456
618
|
}
|
|
457
619
|
|
|
458
620
|
// src/providers/openai.ts
|
|
459
|
-
var openaiAdapter = {
|
|
621
|
+
var openaiAdapter = withPromptInputSupport({
|
|
460
622
|
name: "openai",
|
|
461
623
|
validate(asset, runtime) {
|
|
462
624
|
const resolvedAsset = resolveAssetForProvider(asset, runtime);
|
|
@@ -530,10 +692,10 @@ var openaiAdapter = {
|
|
|
530
692
|
model: resolvedAsset.model ?? "unknown"
|
|
531
693
|
};
|
|
532
694
|
}
|
|
533
|
-
};
|
|
695
|
+
});
|
|
534
696
|
|
|
535
697
|
// src/providers/anthropic.ts
|
|
536
|
-
var anthropicAdapter = {
|
|
698
|
+
var anthropicAdapter = withPromptInputSupport({
|
|
537
699
|
name: "anthropic",
|
|
538
700
|
validate(asset, runtime) {
|
|
539
701
|
const resolvedAsset = resolveAssetForProvider(asset, runtime);
|
|
@@ -612,10 +774,10 @@ var anthropicAdapter = {
|
|
|
612
774
|
model: resolvedAsset.model ?? "unknown"
|
|
613
775
|
};
|
|
614
776
|
}
|
|
615
|
-
};
|
|
777
|
+
});
|
|
616
778
|
|
|
617
779
|
// src/providers/gemini.ts
|
|
618
|
-
var geminiAdapter = {
|
|
780
|
+
var geminiAdapter = withPromptInputSupport({
|
|
619
781
|
name: "gemini",
|
|
620
782
|
validate(asset, runtime) {
|
|
621
783
|
const resolvedAsset = resolveAssetForProvider(asset, runtime);
|
|
@@ -698,10 +860,10 @@ var geminiAdapter = {
|
|
|
698
860
|
model: resolvedAsset.model ?? "unknown"
|
|
699
861
|
};
|
|
700
862
|
}
|
|
701
|
-
};
|
|
863
|
+
});
|
|
702
864
|
|
|
703
865
|
// src/providers/openrouter.ts
|
|
704
|
-
var openrouterAdapter = {
|
|
866
|
+
var openrouterAdapter = withPromptInputSupport({
|
|
705
867
|
name: "openrouter",
|
|
706
868
|
validate(asset, runtime) {
|
|
707
869
|
return openaiAdapter.validate(asset, runtime);
|
|
@@ -713,7 +875,7 @@ var openrouterAdapter = {
|
|
|
713
875
|
provider: "openrouter"
|
|
714
876
|
};
|
|
715
877
|
}
|
|
716
|
-
};
|
|
878
|
+
});
|
|
717
879
|
|
|
718
880
|
// src/providers/index.ts
|
|
719
881
|
var adapters = {
|
|
@@ -923,48 +1085,6 @@ function findClosestMatch(input, candidates) {
|
|
|
923
1085
|
return best;
|
|
924
1086
|
}
|
|
925
1087
|
|
|
926
|
-
// src/cache.ts
|
|
927
|
-
var import_node_fs = require("fs");
|
|
928
|
-
var PromptCache = class {
|
|
929
|
-
cache = /* @__PURE__ */ new Map();
|
|
930
|
-
maxSize;
|
|
931
|
-
constructor(maxSize = 100) {
|
|
932
|
-
this.maxSize = maxSize;
|
|
933
|
-
}
|
|
934
|
-
get(filePath) {
|
|
935
|
-
const entry = this.cache.get(filePath);
|
|
936
|
-
if (!entry) return void 0;
|
|
937
|
-
try {
|
|
938
|
-
const stat = (0, import_node_fs.statSync)(filePath);
|
|
939
|
-
if (stat.mtimeMs !== entry.mtime) {
|
|
940
|
-
this.cache.delete(filePath);
|
|
941
|
-
return void 0;
|
|
942
|
-
}
|
|
943
|
-
} catch {
|
|
944
|
-
this.cache.delete(filePath);
|
|
945
|
-
return void 0;
|
|
946
|
-
}
|
|
947
|
-
return entry.value;
|
|
948
|
-
}
|
|
949
|
-
set(filePath, value) {
|
|
950
|
-
if (this.cache.size >= this.maxSize) {
|
|
951
|
-
const oldest = this.cache.keys().next().value;
|
|
952
|
-
if (oldest) this.cache.delete(oldest);
|
|
953
|
-
}
|
|
954
|
-
try {
|
|
955
|
-
const stat = (0, import_node_fs.statSync)(filePath);
|
|
956
|
-
this.cache.set(filePath, { value, mtime: stat.mtimeMs });
|
|
957
|
-
} catch {
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
clear() {
|
|
961
|
-
this.cache.clear();
|
|
962
|
-
}
|
|
963
|
-
get size() {
|
|
964
|
-
return this.cache.size;
|
|
965
|
-
}
|
|
966
|
-
};
|
|
967
|
-
|
|
968
1088
|
// src/usagetap/client.ts
|
|
969
1089
|
var DEFAULT_BASE_URL = "https://api.usagetap.com";
|
|
970
1090
|
var ACCEPT_HEADER = "application/vnd.usagetap.v1+json";
|
|
@@ -1372,73 +1492,13 @@ var PromptOpsKit = class {
|
|
|
1372
1492
|
* Load a prompt asset from compiled or source, based on mode.
|
|
1373
1493
|
*/
|
|
1374
1494
|
async loadPrompt(promptPath) {
|
|
1375
|
-
|
|
1376
|
-
if (mode !== "source-only" && this.config.compiledDir) {
|
|
1377
|
-
const compiledFile = (0, import_node_path3.resolve)(this.config.compiledDir, promptPath + ".json");
|
|
1378
|
-
if ((0, import_node_fs2.existsSync)(compiledFile)) {
|
|
1379
|
-
if (mode === "auto") {
|
|
1380
|
-
const sourceFile = (0, import_node_path3.resolve)(this.config.sourceDir, promptPath + ".md");
|
|
1381
|
-
if ((0, import_node_fs2.existsSync)(sourceFile)) {
|
|
1382
|
-
const compiledMtime = (0, import_node_fs2.statSync)(compiledFile).mtimeMs;
|
|
1383
|
-
const sourceMtime = (0, import_node_fs2.statSync)(sourceFile).mtimeMs;
|
|
1384
|
-
if (sourceMtime > compiledMtime) {
|
|
1385
|
-
console.warn(
|
|
1386
|
-
`[promptopskit] Warning: compiled artifact for "${promptPath}" is older than source .md file.
|
|
1387
|
-
Run "promptopskit compile" or switch to source-only mode.`
|
|
1388
|
-
);
|
|
1389
|
-
}
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
|
-
const content = await (0, import_promises3.readFile)(compiledFile, "utf-8");
|
|
1393
|
-
return JSON.parse(content);
|
|
1394
|
-
}
|
|
1395
|
-
if (mode === "compiled-only") {
|
|
1396
|
-
throw new Error(
|
|
1397
|
-
`Compiled artifact not found: ${compiledFile}
|
|
1398
|
-
Run "promptopskit compile" to generate it.`
|
|
1399
|
-
);
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
if (mode !== "compiled-only") {
|
|
1403
|
-
const sourceFile = (0, import_node_path3.resolve)(this.config.sourceDir, promptPath + ".md");
|
|
1404
|
-
if (this.config.cache) {
|
|
1405
|
-
const cached = this.promptCache.get(sourceFile);
|
|
1406
|
-
if (cached) return cached;
|
|
1407
|
-
}
|
|
1408
|
-
if (!(0, import_node_fs2.existsSync)(sourceFile)) {
|
|
1409
|
-
const paths = [sourceFile];
|
|
1410
|
-
if (this.config.compiledDir) {
|
|
1411
|
-
paths.unshift((0, import_node_path3.resolve)(this.config.compiledDir, promptPath + ".json"));
|
|
1412
|
-
}
|
|
1413
|
-
throw new Error(
|
|
1414
|
-
`Prompt not found: "${promptPath}"
|
|
1415
|
-
Searched:
|
|
1416
|
-
${paths.map((p) => ` - ${p}`).join("\n")}`
|
|
1417
|
-
);
|
|
1418
|
-
}
|
|
1419
|
-
const { asset } = await loadPromptFile(sourceFile, { defaultsRoot: this.config.sourceDir });
|
|
1420
|
-
if (this.config.cache) {
|
|
1421
|
-
this.promptCache.set(sourceFile, asset);
|
|
1422
|
-
}
|
|
1423
|
-
return asset;
|
|
1424
|
-
}
|
|
1425
|
-
throw new Error(`Prompt not found: "${promptPath}"`);
|
|
1495
|
+
return loadPromptAsset(promptPath, this.config, this.promptCache);
|
|
1426
1496
|
}
|
|
1427
1497
|
/**
|
|
1428
1498
|
* Resolve a prompt: load, resolve includes, apply overrides.
|
|
1429
1499
|
*/
|
|
1430
1500
|
async resolvePrompt(promptPath, options = {}) {
|
|
1431
|
-
|
|
1432
|
-
const sourceFile = (0, import_node_path3.resolve)(this.config.sourceDir, promptPath + ".md");
|
|
1433
|
-
if (asset.includes && asset.includes.length > 0 && (0, import_node_fs2.existsSync)(sourceFile)) {
|
|
1434
|
-
asset = await resolveIncludes(asset, sourceFile);
|
|
1435
|
-
}
|
|
1436
|
-
asset = applyOverrides(asset, {
|
|
1437
|
-
environment: options.environment,
|
|
1438
|
-
tier: options.tier,
|
|
1439
|
-
runtime: options.runtime
|
|
1440
|
-
});
|
|
1441
|
-
return asset;
|
|
1501
|
+
return resolvePromptAsset(promptPath, this.config, options, this.promptCache);
|
|
1442
1502
|
}
|
|
1443
1503
|
/**
|
|
1444
1504
|
* Render a prompt for a specific provider.
|
|
@@ -1446,13 +1506,11 @@ ${paths.map((p) => ` - ${p}`).join("\n")}`
|
|
|
1446
1506
|
async renderPrompt(options) {
|
|
1447
1507
|
let resolved;
|
|
1448
1508
|
if (options.source) {
|
|
1449
|
-
|
|
1450
|
-
const overridden = applyOverrides(asset, {
|
|
1509
|
+
resolved = resolveInlinePromptSource(options.source, {
|
|
1451
1510
|
environment: options.environment,
|
|
1452
1511
|
tier: options.tier,
|
|
1453
1512
|
runtime: options.runtime
|
|
1454
1513
|
});
|
|
1455
|
-
resolved = overridden;
|
|
1456
1514
|
} else if (options.path) {
|
|
1457
1515
|
resolved = await this.resolvePrompt(options.path, {
|
|
1458
1516
|
environment: options.environment,
|
|
@@ -1496,7 +1554,8 @@ ${paths.map((p) => ` - ${p}`).join("\n")}`
|
|
|
1496
1554
|
*/
|
|
1497
1555
|
async validatePrompt(promptPath) {
|
|
1498
1556
|
const asset = await this.loadPrompt(promptPath);
|
|
1499
|
-
|
|
1557
|
+
const sourceFile = (0, import_node_path4.resolve)(this.config.sourceDir, promptPath + ".md");
|
|
1558
|
+
return validateAssetWithIncludes(asset, sourceFile);
|
|
1500
1559
|
}
|
|
1501
1560
|
/**
|
|
1502
1561
|
* Clear the internal cache.
|