promptopskit 0.3.0 → 0.3.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/README.md +49 -0
- package/SKILL.md +134 -71
- package/dist/{chunk-VYVEVJC3.js → chunk-R5PKK6Y7.js} +28 -24
- 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-PU3UPUND.js → chunk-U7IDX2P7.js} +9 -6
- package/dist/chunk-U7IDX2P7.js.map +1 -0
- package/dist/{chunk-5BI5FP5L.js → chunk-UJA7XBQZ.js} +24 -20
- package/dist/chunk-UJA7XBQZ.js.map +1 -0
- package/dist/chunk-VU3WKLFI.js +87 -0
- package/dist/chunk-VU3WKLFI.js.map +1 -0
- package/dist/cli/index.js +44 -20
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +325 -245
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +29 -195
- package/dist/index.js.map +1 -1
- package/dist/providers/anthropic.cjs +534 -21
- package/dist/providers/anthropic.cjs.map +1 -1
- package/dist/providers/anthropic.d.cts +2 -2
- package/dist/providers/anthropic.d.ts +2 -2
- package/dist/providers/anthropic.js +3 -2
- package/dist/providers/gemini.cjs +530 -17
- package/dist/providers/gemini.cjs.map +1 -1
- package/dist/providers/gemini.d.cts +2 -2
- package/dist/providers/gemini.d.ts +2 -2
- package/dist/providers/gemini.js +3 -2
- package/dist/providers/openai.cjs +535 -22
- package/dist/providers/openai.cjs.map +1 -1
- package/dist/providers/openai.d.cts +2 -2
- package/dist/providers/openai.d.ts +2 -2
- package/dist/providers/openai.js +3 -2
- package/dist/providers/openrouter.cjs +539 -26
- package/dist/providers/openrouter.cjs.map +1 -1
- package/dist/providers/openrouter.d.cts +2 -2
- package/dist/providers/openrouter.d.ts +2 -2
- package/dist/providers/openrouter.js +4 -3
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/types-CgA7_wNI.d.cts +68 -0
- package/dist/types-D_-336jx.d.ts +68 -0
- package/dist/usagetap/index.d.cts +2 -2
- package/dist/usagetap/index.d.ts +2 -2
- package/package.json +1 -1
- package/dist/chunk-5BI5FP5L.js.map +0 -1
- package/dist/chunk-6KGBPHSY.js +0 -56
- package/dist/chunk-6KGBPHSY.js.map +0 -1
- package/dist/chunk-PU3UPUND.js.map +0 -1
- package/dist/chunk-UYTUGV7Z.js +0 -83
- package/dist/chunk-UYTUGV7Z.js.map +0 -1
- package/dist/chunk-VYVEVJC3.js.map +0 -1
- package/dist/types-1zDDD-Ij.d.cts +0 -40
- package/dist/types-CQhlfAnR.d.ts +0 -40
- package/dist/{schema-DIOA4OiO.d.cts → schema-Dq0jKest.d.cts} +42 -42
- package/dist/{schema-DIOA4OiO.d.ts → schema-Dq0jKest.d.ts} +42 -42
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/providers/gemini.ts
|
|
@@ -65,25 +75,528 @@ function renderSections(asset, options = {}) {
|
|
|
65
75
|
return result;
|
|
66
76
|
}
|
|
67
77
|
|
|
78
|
+
// src/overrides/apply-overrides.ts
|
|
79
|
+
function applyOverrides(asset, options = {}) {
|
|
80
|
+
let result = { ...asset };
|
|
81
|
+
if (options.environment && result.environments?.[options.environment]) {
|
|
82
|
+
result = mergeOverride(result, result.environments[options.environment]);
|
|
83
|
+
}
|
|
84
|
+
if (options.tier && result.tiers?.[options.tier]) {
|
|
85
|
+
result = mergeOverride(result, result.tiers[options.tier]);
|
|
86
|
+
}
|
|
87
|
+
if (options.runtime) {
|
|
88
|
+
result = mergeOverride(result, options.runtime);
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
function mergeOverride(base, override) {
|
|
93
|
+
const result = { ...base };
|
|
94
|
+
if (override.model !== void 0) result.model = override.model;
|
|
95
|
+
if (override.fallback_models !== void 0) result.fallback_models = override.fallback_models;
|
|
96
|
+
if (override.tools !== void 0) result.tools = override.tools;
|
|
97
|
+
if (override.reasoning !== void 0) {
|
|
98
|
+
result.reasoning = { ...result.reasoning, ...override.reasoning };
|
|
99
|
+
}
|
|
100
|
+
if (override.sampling !== void 0) {
|
|
101
|
+
result.sampling = { ...result.sampling, ...override.sampling };
|
|
102
|
+
}
|
|
103
|
+
if (override.response !== void 0) {
|
|
104
|
+
result.response = { ...result.response, ...override.response };
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/providers/resolve-asset.ts
|
|
110
|
+
function resolveAssetForProvider(asset, runtime = {}) {
|
|
111
|
+
if (!runtime.environment && !runtime.tier && !runtime.runtime) {
|
|
112
|
+
return asset;
|
|
113
|
+
}
|
|
114
|
+
return applyOverrides(asset, {
|
|
115
|
+
environment: runtime.environment,
|
|
116
|
+
tier: runtime.tier,
|
|
117
|
+
runtime: runtime.runtime
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/prompt-resolution.ts
|
|
122
|
+
var import_promises3 = require("fs/promises");
|
|
123
|
+
var import_node_fs2 = require("fs");
|
|
124
|
+
var import_node_path3 = require("path");
|
|
125
|
+
|
|
126
|
+
// src/cache.ts
|
|
127
|
+
var import_node_fs = require("fs");
|
|
128
|
+
var PromptCache = class {
|
|
129
|
+
cache = /* @__PURE__ */ new Map();
|
|
130
|
+
maxSize;
|
|
131
|
+
constructor(maxSize = 100) {
|
|
132
|
+
this.maxSize = maxSize;
|
|
133
|
+
}
|
|
134
|
+
get(filePath) {
|
|
135
|
+
const entry = this.cache.get(filePath);
|
|
136
|
+
if (!entry) return void 0;
|
|
137
|
+
try {
|
|
138
|
+
const stat = (0, import_node_fs.statSync)(filePath);
|
|
139
|
+
if (stat.mtimeMs !== entry.mtime) {
|
|
140
|
+
this.cache.delete(filePath);
|
|
141
|
+
return void 0;
|
|
142
|
+
}
|
|
143
|
+
} catch {
|
|
144
|
+
this.cache.delete(filePath);
|
|
145
|
+
return void 0;
|
|
146
|
+
}
|
|
147
|
+
this.cache.delete(filePath);
|
|
148
|
+
this.cache.set(filePath, entry);
|
|
149
|
+
return entry.value;
|
|
150
|
+
}
|
|
151
|
+
set(filePath, value) {
|
|
152
|
+
try {
|
|
153
|
+
const stat = (0, import_node_fs.statSync)(filePath);
|
|
154
|
+
if (this.cache.has(filePath)) {
|
|
155
|
+
this.cache.delete(filePath);
|
|
156
|
+
} else if (this.cache.size >= this.maxSize) {
|
|
157
|
+
const oldest = this.cache.keys().next().value;
|
|
158
|
+
if (oldest) this.cache.delete(oldest);
|
|
159
|
+
}
|
|
160
|
+
this.cache.set(filePath, { value, mtime: stat.mtimeMs });
|
|
161
|
+
} catch {
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
clear() {
|
|
165
|
+
this.cache.clear();
|
|
166
|
+
}
|
|
167
|
+
get size() {
|
|
168
|
+
return this.cache.size;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// src/composition/resolve-includes.ts
|
|
173
|
+
var import_promises2 = require("fs/promises");
|
|
174
|
+
var import_node_path2 = require("path");
|
|
175
|
+
|
|
176
|
+
// src/parser/parser.ts
|
|
177
|
+
var import_gray_matter = __toESM(require("gray-matter"), 1);
|
|
178
|
+
|
|
179
|
+
// src/schema/schema.ts
|
|
180
|
+
var import_zod = require("zod");
|
|
181
|
+
var InlineToolDefSchema = import_zod.z.object({
|
|
182
|
+
name: import_zod.z.string(),
|
|
183
|
+
description: import_zod.z.string().optional(),
|
|
184
|
+
input_schema: import_zod.z.record(import_zod.z.unknown()).optional()
|
|
185
|
+
});
|
|
186
|
+
var ToolRefSchema = import_zod.z.union([import_zod.z.string(), InlineToolDefSchema]);
|
|
187
|
+
var MCPServerRefSchema = import_zod.z.union([
|
|
188
|
+
import_zod.z.string(),
|
|
189
|
+
import_zod.z.object({
|
|
190
|
+
name: import_zod.z.string(),
|
|
191
|
+
config: import_zod.z.record(import_zod.z.unknown()).optional()
|
|
192
|
+
})
|
|
193
|
+
]);
|
|
194
|
+
var ReasoningSchema = import_zod.z.object({
|
|
195
|
+
effort: import_zod.z.enum(["low", "medium", "high"]).optional(),
|
|
196
|
+
budget_tokens: import_zod.z.number().int().positive().optional()
|
|
197
|
+
});
|
|
198
|
+
var SamplingSchema = import_zod.z.object({
|
|
199
|
+
temperature: import_zod.z.number().min(0).max(2).optional(),
|
|
200
|
+
top_p: import_zod.z.number().min(0).max(1).optional(),
|
|
201
|
+
frequency_penalty: import_zod.z.number().optional(),
|
|
202
|
+
presence_penalty: import_zod.z.number().optional(),
|
|
203
|
+
stop: import_zod.z.array(import_zod.z.string()).optional(),
|
|
204
|
+
max_output_tokens: import_zod.z.number().int().positive().optional()
|
|
205
|
+
});
|
|
206
|
+
var ResponseSchema = import_zod.z.object({
|
|
207
|
+
format: import_zod.z.enum(["text", "json", "markdown"]).optional(),
|
|
208
|
+
stream: import_zod.z.boolean().optional()
|
|
209
|
+
});
|
|
210
|
+
var HistorySchema = import_zod.z.object({
|
|
211
|
+
max_items: import_zod.z.number().int().positive().optional()
|
|
212
|
+
});
|
|
213
|
+
var ContextInputDefinitionObjectSchema = import_zod.z.object({
|
|
214
|
+
name: import_zod.z.string(),
|
|
215
|
+
max_size: import_zod.z.number().int().positive().optional()
|
|
216
|
+
});
|
|
217
|
+
var ContextInputDefinitionSchema = import_zod.z.union([
|
|
218
|
+
import_zod.z.string(),
|
|
219
|
+
ContextInputDefinitionObjectSchema
|
|
220
|
+
]);
|
|
221
|
+
var ContextSchema = import_zod.z.object({
|
|
222
|
+
inputs: import_zod.z.array(ContextInputDefinitionSchema).optional(),
|
|
223
|
+
history: HistorySchema.optional()
|
|
224
|
+
});
|
|
225
|
+
var MetadataSchema = import_zod.z.object({
|
|
226
|
+
owner: import_zod.z.string().optional(),
|
|
227
|
+
tags: import_zod.z.array(import_zod.z.string()).optional(),
|
|
228
|
+
review_required: import_zod.z.boolean().optional(),
|
|
229
|
+
stable: import_zod.z.boolean().optional()
|
|
230
|
+
});
|
|
231
|
+
var MCPSchema = import_zod.z.object({
|
|
232
|
+
servers: import_zod.z.array(MCPServerRefSchema).optional()
|
|
233
|
+
});
|
|
234
|
+
var PromptAssetOverridesSchema = import_zod.z.object({
|
|
235
|
+
model: import_zod.z.string().optional(),
|
|
236
|
+
fallback_models: import_zod.z.array(import_zod.z.string()).optional(),
|
|
237
|
+
reasoning: ReasoningSchema.optional(),
|
|
238
|
+
sampling: SamplingSchema.optional(),
|
|
239
|
+
response: ResponseSchema.optional(),
|
|
240
|
+
tools: import_zod.z.array(ToolRefSchema).optional()
|
|
241
|
+
});
|
|
242
|
+
var SourceSchema = import_zod.z.object({
|
|
243
|
+
file_path: import_zod.z.string().optional(),
|
|
244
|
+
checksum: import_zod.z.string().optional()
|
|
245
|
+
});
|
|
246
|
+
var SectionsSchema = import_zod.z.object({
|
|
247
|
+
system_instructions: import_zod.z.string().optional(),
|
|
248
|
+
prompt_template: import_zod.z.string().optional(),
|
|
249
|
+
notes: import_zod.z.string().optional()
|
|
250
|
+
});
|
|
251
|
+
var PromptDefaultsSchema = import_zod.z.object({
|
|
252
|
+
provider: import_zod.z.enum(["openai", "anthropic", "google", "gemini", "openrouter", "any"]).optional(),
|
|
253
|
+
model: import_zod.z.string().optional(),
|
|
254
|
+
metadata: MetadataSchema.optional(),
|
|
255
|
+
sections: import_zod.z.object({
|
|
256
|
+
system_instructions: import_zod.z.string().optional()
|
|
257
|
+
}).optional()
|
|
258
|
+
});
|
|
259
|
+
var PromptAssetSchema = import_zod.z.object({
|
|
260
|
+
id: import_zod.z.string(),
|
|
261
|
+
schema_version: import_zod.z.number().int().positive().default(1),
|
|
262
|
+
description: import_zod.z.string().optional(),
|
|
263
|
+
provider: import_zod.z.enum(["openai", "anthropic", "google", "gemini", "openrouter", "any"]).optional(),
|
|
264
|
+
model: import_zod.z.string().optional(),
|
|
265
|
+
fallback_models: import_zod.z.array(import_zod.z.string()).optional(),
|
|
266
|
+
reasoning: ReasoningSchema.optional(),
|
|
267
|
+
sampling: SamplingSchema.optional(),
|
|
268
|
+
response: ResponseSchema.optional(),
|
|
269
|
+
tools: import_zod.z.array(ToolRefSchema).optional(),
|
|
270
|
+
mcp: MCPSchema.optional(),
|
|
271
|
+
context: ContextSchema.optional(),
|
|
272
|
+
includes: import_zod.z.array(import_zod.z.string()).optional(),
|
|
273
|
+
environments: import_zod.z.record(PromptAssetOverridesSchema).optional(),
|
|
274
|
+
tiers: import_zod.z.record(PromptAssetOverridesSchema).optional(),
|
|
275
|
+
metadata: MetadataSchema.optional(),
|
|
276
|
+
// Populated by parser, not authored in YAML
|
|
277
|
+
sections: SectionsSchema.optional(),
|
|
278
|
+
source: SourceSchema.optional()
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// src/parser/sections.ts
|
|
282
|
+
var SECTION_MAP = {
|
|
283
|
+
"system instructions": "system_instructions",
|
|
284
|
+
"prompt template": "prompt_template",
|
|
285
|
+
"notes": "notes"
|
|
286
|
+
};
|
|
287
|
+
function extractSections(body) {
|
|
288
|
+
const lines = body.split(/\r?\n/);
|
|
289
|
+
const sections = {};
|
|
290
|
+
let currentKey = null;
|
|
291
|
+
let currentLines = [];
|
|
292
|
+
let foundAnyH1 = false;
|
|
293
|
+
for (const line of lines) {
|
|
294
|
+
const h1Match = line.match(/^#\s+(.+)$/);
|
|
295
|
+
if (h1Match) {
|
|
296
|
+
if (currentKey) {
|
|
297
|
+
sections[currentKey] = currentLines.join("\n").trim();
|
|
298
|
+
}
|
|
299
|
+
foundAnyH1 = true;
|
|
300
|
+
const heading = h1Match[1].trim().toLowerCase();
|
|
301
|
+
currentKey = SECTION_MAP[heading] ?? null;
|
|
302
|
+
currentLines = [];
|
|
303
|
+
} else {
|
|
304
|
+
currentLines.push(line);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (currentKey) {
|
|
308
|
+
sections[currentKey] = currentLines.join("\n").trim();
|
|
309
|
+
}
|
|
310
|
+
if (!foundAnyH1) {
|
|
311
|
+
const trimmed = body.trim();
|
|
312
|
+
if (trimmed) {
|
|
313
|
+
sections.prompt_template = trimmed;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return sections;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// src/parser/parser.ts
|
|
320
|
+
function parsePrompt(content, filePath) {
|
|
321
|
+
const { data: frontMatter, content: body } = (0, import_gray_matter.default)(content);
|
|
322
|
+
const sections = extractSections(body);
|
|
323
|
+
const raw = {
|
|
324
|
+
...frontMatter,
|
|
325
|
+
sections,
|
|
326
|
+
source: filePath ? { file_path: filePath } : void 0
|
|
327
|
+
};
|
|
328
|
+
const asset = PromptAssetSchema.parse(raw);
|
|
329
|
+
return {
|
|
330
|
+
asset,
|
|
331
|
+
raw: {
|
|
332
|
+
frontMatter,
|
|
333
|
+
body
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// src/parser/loader.ts
|
|
339
|
+
var import_promises = require("fs/promises");
|
|
340
|
+
var import_node_path = require("path");
|
|
341
|
+
var import_gray_matter2 = __toESM(require("gray-matter"), 1);
|
|
342
|
+
var DEFAULTS_FILE_NAME = "defaults.md";
|
|
343
|
+
async function loadPromptFile(filePath, options = {}) {
|
|
344
|
+
const content = await (0, import_promises.readFile)(filePath, "utf-8");
|
|
345
|
+
const parsed = parsePrompt(content, filePath);
|
|
346
|
+
const root = options.defaultsRoot ?? (0, import_node_path.dirname)(filePath);
|
|
347
|
+
const defaults = await loadDefaultsForPath(filePath, root);
|
|
348
|
+
const asset = applyDefaults(parsed.asset, defaults);
|
|
349
|
+
return {
|
|
350
|
+
...parsed,
|
|
351
|
+
asset
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
async function loadDefaultsForPath(filePath, defaultsRoot) {
|
|
355
|
+
const directories = getDirectoriesToCheck(filePath, defaultsRoot);
|
|
356
|
+
let merged = {};
|
|
357
|
+
for (const dir of directories) {
|
|
358
|
+
const defaultsPath = (0, import_node_path.join)(dir, DEFAULTS_FILE_NAME);
|
|
359
|
+
try {
|
|
360
|
+
const defaultsContent = await (0, import_promises.readFile)(defaultsPath, "utf-8");
|
|
361
|
+
const defaults = parseDefaults(defaultsContent);
|
|
362
|
+
merged = mergeDefaults(merged, defaults);
|
|
363
|
+
} catch (error) {
|
|
364
|
+
if (error.code !== "ENOENT") {
|
|
365
|
+
throw error;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return merged;
|
|
370
|
+
}
|
|
371
|
+
function getDirectoriesToCheck(filePath, defaultsRoot) {
|
|
372
|
+
const dirs = [];
|
|
373
|
+
let current = (0, import_node_path.resolve)((0, import_node_path.dirname)(filePath));
|
|
374
|
+
const boundary = defaultsRoot ? (0, import_node_path.resolve)(defaultsRoot) : void 0;
|
|
375
|
+
while (true) {
|
|
376
|
+
dirs.unshift(current);
|
|
377
|
+
if (boundary && current === boundary || current === (0, import_node_path.dirname)(current)) {
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
current = (0, import_node_path.dirname)(current);
|
|
381
|
+
}
|
|
382
|
+
return dirs;
|
|
383
|
+
}
|
|
384
|
+
function parseDefaults(content) {
|
|
385
|
+
const { data: frontMatter, content: body } = (0, import_gray_matter2.default)(content);
|
|
386
|
+
const sections = extractSections(body);
|
|
387
|
+
return PromptDefaultsSchema.parse({
|
|
388
|
+
...frontMatter,
|
|
389
|
+
sections: {
|
|
390
|
+
system_instructions: sections.system_instructions
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
function mergeDefaults(base, local) {
|
|
395
|
+
return {
|
|
396
|
+
provider: local.provider ?? base.provider,
|
|
397
|
+
model: local.model ?? base.model,
|
|
398
|
+
metadata: {
|
|
399
|
+
...base.metadata ?? {},
|
|
400
|
+
...local.metadata ?? {}
|
|
401
|
+
},
|
|
402
|
+
sections: {
|
|
403
|
+
...base.sections ?? {},
|
|
404
|
+
...local.sections ?? {}
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
function applyDefaults(asset, defaults) {
|
|
409
|
+
const hasDefaultMetadata = defaults.metadata && Object.keys(defaults.metadata).length > 0;
|
|
410
|
+
const hasDefaultSystem = !!defaults.sections?.system_instructions;
|
|
411
|
+
const hasDefaultScalars = defaults.provider !== void 0 || defaults.model !== void 0;
|
|
412
|
+
if (!hasDefaultMetadata && !hasDefaultSystem && !hasDefaultScalars) {
|
|
413
|
+
return asset;
|
|
414
|
+
}
|
|
415
|
+
const mergedMetadata = {
|
|
416
|
+
...defaults.metadata ?? {},
|
|
417
|
+
...asset.metadata ?? {}
|
|
418
|
+
};
|
|
419
|
+
const metadata = Object.keys(mergedMetadata).length > 0 ? mergedMetadata : void 0;
|
|
420
|
+
const systemInstructions = asset.sections?.system_instructions ?? defaults.sections?.system_instructions;
|
|
421
|
+
const sections = asset.sections ? { ...asset.sections, system_instructions: systemInstructions } : systemInstructions ? { system_instructions: systemInstructions } : void 0;
|
|
422
|
+
return {
|
|
423
|
+
...asset,
|
|
424
|
+
provider: asset.provider ?? defaults.provider,
|
|
425
|
+
model: asset.model ?? defaults.model,
|
|
426
|
+
metadata,
|
|
427
|
+
sections
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// src/composition/resolve-includes.ts
|
|
432
|
+
async function resolveIncludes(asset, basePath, visited = /* @__PURE__ */ new Set()) {
|
|
433
|
+
if (!asset.includes || asset.includes.length === 0) {
|
|
434
|
+
return asset;
|
|
435
|
+
}
|
|
436
|
+
const baseDir = (0, import_node_path2.dirname)(basePath);
|
|
437
|
+
const resolvedPath = (0, import_node_path2.resolve)(basePath);
|
|
438
|
+
if (visited.has(resolvedPath)) {
|
|
439
|
+
throw new Error(`Circular include detected: ${resolvedPath}`);
|
|
440
|
+
}
|
|
441
|
+
visited.add(resolvedPath);
|
|
442
|
+
let mergedSystemInstructions = "";
|
|
443
|
+
for (const includePath of asset.includes) {
|
|
444
|
+
const fullPath = (0, import_node_path2.resolve)(baseDir, includePath);
|
|
445
|
+
if (visited.has(fullPath)) {
|
|
446
|
+
throw new Error(`Circular include detected: ${fullPath} (included from ${basePath})`);
|
|
447
|
+
}
|
|
448
|
+
const content = await (0, import_promises2.readFile)(fullPath, "utf-8");
|
|
449
|
+
const { asset: includedAsset } = parsePrompt(content, fullPath);
|
|
450
|
+
const resolved = await resolveIncludes(includedAsset, fullPath, new Set(visited));
|
|
451
|
+
if (resolved.sections?.system_instructions) {
|
|
452
|
+
mergedSystemInstructions += resolved.sections.system_instructions + "\n\n";
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
const localSystem = asset.sections?.system_instructions ?? "";
|
|
456
|
+
const combinedSystem = (mergedSystemInstructions + localSystem).trim() || void 0;
|
|
457
|
+
return {
|
|
458
|
+
...asset,
|
|
459
|
+
sections: {
|
|
460
|
+
...asset.sections,
|
|
461
|
+
system_instructions: combinedSystem
|
|
462
|
+
},
|
|
463
|
+
// Drop includes from the resolved asset — they've been inlined
|
|
464
|
+
includes: void 0
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// src/prompt-resolution.ts
|
|
469
|
+
var sharedPromptCache = new PromptCache();
|
|
470
|
+
async function loadPromptAsset(promptPath, config, promptCache = sharedPromptCache) {
|
|
471
|
+
const mode = config.mode ?? "auto";
|
|
472
|
+
if (mode !== "source-only" && config.compiledDir) {
|
|
473
|
+
const compiledFile = (0, import_node_path3.resolve)(config.compiledDir, promptPath + ".json");
|
|
474
|
+
if ((0, import_node_fs2.existsSync)(compiledFile)) {
|
|
475
|
+
if (mode === "auto") {
|
|
476
|
+
const sourceFile = (0, import_node_path3.resolve)(config.sourceDir, promptPath + ".md");
|
|
477
|
+
if ((0, import_node_fs2.existsSync)(sourceFile)) {
|
|
478
|
+
const compiledMtime = (0, import_node_fs2.statSync)(compiledFile).mtimeMs;
|
|
479
|
+
const sourceMtime = (0, import_node_fs2.statSync)(sourceFile).mtimeMs;
|
|
480
|
+
if (sourceMtime > compiledMtime) {
|
|
481
|
+
console.warn(
|
|
482
|
+
`[promptopskit] Warning: compiled artifact for "${promptPath}" is older than source .md file.
|
|
483
|
+
Run "promptopskit compile" or switch to source-only mode.`
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
const content = await (0, import_promises3.readFile)(compiledFile, "utf-8");
|
|
489
|
+
return JSON.parse(content);
|
|
490
|
+
}
|
|
491
|
+
if (mode === "compiled-only") {
|
|
492
|
+
throw new Error(
|
|
493
|
+
`Compiled artifact not found: ${compiledFile}
|
|
494
|
+
Run "promptopskit compile" to generate it.`
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
if (mode !== "compiled-only") {
|
|
499
|
+
const sourceFile = (0, import_node_path3.resolve)(config.sourceDir, promptPath + ".md");
|
|
500
|
+
if (config.cache !== false) {
|
|
501
|
+
const cached = promptCache.get(sourceFile);
|
|
502
|
+
if (cached) {
|
|
503
|
+
return cached;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
if (!(0, import_node_fs2.existsSync)(sourceFile)) {
|
|
507
|
+
const paths = [sourceFile];
|
|
508
|
+
if (config.compiledDir) {
|
|
509
|
+
paths.unshift((0, import_node_path3.resolve)(config.compiledDir, promptPath + ".json"));
|
|
510
|
+
}
|
|
511
|
+
throw new Error(
|
|
512
|
+
`Prompt not found: "${promptPath}"
|
|
513
|
+
Searched:
|
|
514
|
+
${paths.map((candidate) => ` - ${candidate}`).join("\n")}`
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
const { asset } = await loadPromptFile(sourceFile, { defaultsRoot: config.sourceDir });
|
|
518
|
+
if (config.cache !== false) {
|
|
519
|
+
promptCache.set(sourceFile, asset);
|
|
520
|
+
}
|
|
521
|
+
return asset;
|
|
522
|
+
}
|
|
523
|
+
throw new Error(`Prompt not found: "${promptPath}"`);
|
|
524
|
+
}
|
|
525
|
+
async function resolvePromptAsset(promptPath, config, options = {}, promptCache = sharedPromptCache) {
|
|
526
|
+
let asset = await loadPromptAsset(promptPath, config, promptCache);
|
|
527
|
+
const sourceFile = (0, import_node_path3.resolve)(config.sourceDir, promptPath + ".md");
|
|
528
|
+
if (asset.includes && asset.includes.length > 0 && (0, import_node_fs2.existsSync)(sourceFile)) {
|
|
529
|
+
asset = await resolveIncludes(asset, sourceFile);
|
|
530
|
+
}
|
|
531
|
+
asset = applyOverrides(asset, {
|
|
532
|
+
environment: options.environment,
|
|
533
|
+
tier: options.tier,
|
|
534
|
+
runtime: options.runtime
|
|
535
|
+
});
|
|
536
|
+
return asset;
|
|
537
|
+
}
|
|
538
|
+
function resolveInlinePromptSource(source, options = {}) {
|
|
539
|
+
const { asset } = parsePrompt(source);
|
|
540
|
+
return applyOverrides(asset, {
|
|
541
|
+
environment: options.environment,
|
|
542
|
+
tier: options.tier,
|
|
543
|
+
runtime: options.runtime
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// src/providers/prompt-input.ts
|
|
548
|
+
function isPromptLookup(input) {
|
|
549
|
+
return "path" in input && typeof input.path === "string" && "sourceDir" in input;
|
|
550
|
+
}
|
|
551
|
+
function isInlinePromptSource(input) {
|
|
552
|
+
return "source" in input && typeof input.source === "string";
|
|
553
|
+
}
|
|
554
|
+
async function resolveProviderPromptInput(input, runtime) {
|
|
555
|
+
if (isPromptLookup(input)) {
|
|
556
|
+
return resolvePromptAsset(input.path, input, runtime);
|
|
557
|
+
}
|
|
558
|
+
if (isInlinePromptSource(input)) {
|
|
559
|
+
return resolveInlinePromptSource(input.source, runtime);
|
|
560
|
+
}
|
|
561
|
+
return input;
|
|
562
|
+
}
|
|
563
|
+
function withPromptInputSupport(adapter) {
|
|
564
|
+
const validatePrompt = async (input, runtime) => {
|
|
565
|
+
const resolved = await resolveProviderPromptInput(input, runtime);
|
|
566
|
+
return adapter.validate(resolved, runtime);
|
|
567
|
+
};
|
|
568
|
+
const renderPrompt = async (input, runtime) => {
|
|
569
|
+
const resolved = await resolveProviderPromptInput(input, runtime);
|
|
570
|
+
return adapter.render(resolved, runtime);
|
|
571
|
+
};
|
|
572
|
+
return {
|
|
573
|
+
...adapter,
|
|
574
|
+
validatePrompt,
|
|
575
|
+
renderPrompt
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
|
|
68
579
|
// src/providers/gemini.ts
|
|
69
|
-
var geminiAdapter = {
|
|
580
|
+
var geminiAdapter = withPromptInputSupport({
|
|
70
581
|
name: "gemini",
|
|
71
|
-
validate(asset) {
|
|
582
|
+
validate(asset, runtime) {
|
|
583
|
+
const resolvedAsset = resolveAssetForProvider(asset, runtime);
|
|
72
584
|
const errors = [];
|
|
73
585
|
const warnings = [];
|
|
74
|
-
if (!
|
|
586
|
+
if (!resolvedAsset.model) {
|
|
75
587
|
errors.push("Gemini adapter requires a model to be specified.");
|
|
76
588
|
}
|
|
77
|
-
if (
|
|
589
|
+
if (resolvedAsset.sampling?.frequency_penalty !== void 0) {
|
|
78
590
|
warnings.push("Gemini does not support frequency_penalty. It will be ignored.");
|
|
79
591
|
}
|
|
80
|
-
if (
|
|
592
|
+
if (resolvedAsset.sampling?.presence_penalty !== void 0) {
|
|
81
593
|
warnings.push("Gemini does not support presence_penalty. It will be ignored.");
|
|
82
594
|
}
|
|
83
595
|
return { valid: errors.length === 0, errors, warnings };
|
|
84
596
|
},
|
|
85
597
|
render(asset, runtime) {
|
|
86
|
-
const
|
|
598
|
+
const resolvedAsset = resolveAssetForProvider(asset, runtime);
|
|
599
|
+
const sections = renderSections(resolvedAsset, {
|
|
87
600
|
variables: runtime.variables,
|
|
88
601
|
strict: runtime.strict
|
|
89
602
|
});
|
|
@@ -111,23 +624,23 @@ var geminiAdapter = {
|
|
|
111
624
|
};
|
|
112
625
|
}
|
|
113
626
|
const generationConfig = {};
|
|
114
|
-
if (
|
|
115
|
-
if (
|
|
116
|
-
if (
|
|
117
|
-
if (
|
|
118
|
-
if (
|
|
627
|
+
if (resolvedAsset.sampling?.temperature !== void 0) generationConfig.temperature = resolvedAsset.sampling.temperature;
|
|
628
|
+
if (resolvedAsset.sampling?.top_p !== void 0) generationConfig.topP = resolvedAsset.sampling.top_p;
|
|
629
|
+
if (resolvedAsset.sampling?.max_output_tokens !== void 0) generationConfig.maxOutputTokens = resolvedAsset.sampling.max_output_tokens;
|
|
630
|
+
if (resolvedAsset.sampling?.stop !== void 0) generationConfig.stopSequences = resolvedAsset.sampling.stop;
|
|
631
|
+
if (resolvedAsset.response?.format === "json") {
|
|
119
632
|
generationConfig.responseMimeType = "application/json";
|
|
120
633
|
}
|
|
121
|
-
if (
|
|
634
|
+
if (resolvedAsset.reasoning?.effort) {
|
|
122
635
|
body.thinkingConfig = {
|
|
123
|
-
thinkingBudget:
|
|
636
|
+
thinkingBudget: resolvedAsset.reasoning.effort === "high" ? 8192 : resolvedAsset.reasoning.effort === "medium" ? 4096 : 1024
|
|
124
637
|
};
|
|
125
638
|
}
|
|
126
639
|
if (Object.keys(generationConfig).length > 0) {
|
|
127
640
|
body.generationConfig = generationConfig;
|
|
128
641
|
}
|
|
129
|
-
if (
|
|
130
|
-
const functionDeclarations =
|
|
642
|
+
if (resolvedAsset.tools && resolvedAsset.tools.length > 0) {
|
|
643
|
+
const functionDeclarations = resolvedAsset.tools.map((tool) => {
|
|
131
644
|
if (typeof tool === "string") {
|
|
132
645
|
const def = runtime.toolRegistry?.[tool];
|
|
133
646
|
if (def) return def;
|
|
@@ -144,10 +657,10 @@ var geminiAdapter = {
|
|
|
144
657
|
return {
|
|
145
658
|
body,
|
|
146
659
|
provider: "gemini",
|
|
147
|
-
model:
|
|
660
|
+
model: resolvedAsset.model ?? "unknown"
|
|
148
661
|
};
|
|
149
662
|
}
|
|
150
|
-
};
|
|
663
|
+
});
|
|
151
664
|
// Annotate the CommonJS export names for ESM import in node:
|
|
152
665
|
0 && (module.exports = {
|
|
153
666
|
geminiAdapter
|