prompts.chat 0.0.1 → 0.0.2
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 +877 -0
- package/dist/builder/index.d.mts +1067 -0
- package/dist/builder/index.d.ts +1067 -0
- package/dist/builder/index.js +2471 -0
- package/dist/builder/index.js.map +1 -0
- package/dist/builder/index.mjs +2432 -0
- package/dist/builder/index.mjs.map +1 -0
- package/dist/index-BEIO8LCd.d.mts +61 -0
- package/dist/index-BEIO8LCd.d.ts +61 -0
- package/dist/index-CSHEKYfQ.d.mts +64 -0
- package/dist/index-CSHEKYfQ.d.ts +64 -0
- package/dist/index-D41E6D9X.d.mts +77 -0
- package/dist/index-D41E6D9X.d.ts +77 -0
- package/dist/index-DOz8zcA0.d.mts +68 -0
- package/dist/index-DOz8zcA0.d.ts +68 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3335 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3276 -0
- package/dist/index.mjs.map +1 -0
- package/dist/parser/index.d.mts +1 -0
- package/dist/parser/index.d.ts +1 -0
- package/dist/parser/index.js +288 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/index.mjs +259 -0
- package/dist/parser/index.mjs.map +1 -0
- package/dist/quality/index.d.mts +1 -0
- package/dist/quality/index.d.ts +1 -0
- package/dist/quality/index.js +212 -0
- package/dist/quality/index.js.map +1 -0
- package/dist/quality/index.mjs +184 -0
- package/dist/quality/index.mjs.map +1 -0
- package/dist/similarity/index.d.mts +1 -0
- package/dist/similarity/index.d.ts +1 -0
- package/dist/similarity/index.js +123 -0
- package/dist/similarity/index.js.map +1 -0
- package/dist/similarity/index.mjs +91 -0
- package/dist/similarity/index.mjs.map +1 -0
- package/dist/variables/index.d.mts +1 -0
- package/dist/variables/index.d.ts +1 -0
- package/dist/variables/index.js +306 -0
- package/dist/variables/index.js.map +1 -0
- package/dist/variables/index.mjs +274 -0
- package/dist/variables/index.mjs.map +1 -0
- package/package.json +77 -6
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/parser/index.ts
|
|
21
|
+
var parser_exports = {};
|
|
22
|
+
__export(parser_exports, {
|
|
23
|
+
getSystemPrompt: () => getSystemPrompt,
|
|
24
|
+
interpolate: () => interpolate,
|
|
25
|
+
parse: () => parse,
|
|
26
|
+
toJson: () => toJson,
|
|
27
|
+
toYaml: () => toYaml
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(parser_exports);
|
|
30
|
+
function parseSimpleYaml(content) {
|
|
31
|
+
const result = {};
|
|
32
|
+
const lines = content.split("\n");
|
|
33
|
+
let currentKey = null;
|
|
34
|
+
let currentValue = null;
|
|
35
|
+
let inArray = false;
|
|
36
|
+
let inMultiline = false;
|
|
37
|
+
let multilineContent = "";
|
|
38
|
+
let arrayItems = [];
|
|
39
|
+
let indent = 0;
|
|
40
|
+
for (let i = 0; i < lines.length; i++) {
|
|
41
|
+
const line = lines[i];
|
|
42
|
+
const trimmed = line.trim();
|
|
43
|
+
if (!trimmed || trimmed.startsWith("#")) {
|
|
44
|
+
if (inMultiline) {
|
|
45
|
+
multilineContent += "\n";
|
|
46
|
+
}
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (inMultiline) {
|
|
50
|
+
const lineIndent = line.search(/\S/);
|
|
51
|
+
if (lineIndent > indent) {
|
|
52
|
+
multilineContent += (multilineContent ? "\n" : "") + line.slice(indent + 2);
|
|
53
|
+
continue;
|
|
54
|
+
} else {
|
|
55
|
+
if (inArray && currentKey) {
|
|
56
|
+
const lastItem = arrayItems[arrayItems.length - 1];
|
|
57
|
+
if (lastItem && typeof lastItem === "object") {
|
|
58
|
+
const keys = Object.keys(lastItem);
|
|
59
|
+
const lastKey = keys[keys.length - 1];
|
|
60
|
+
lastItem[lastKey] = multilineContent.trim();
|
|
61
|
+
}
|
|
62
|
+
} else if (currentKey) {
|
|
63
|
+
result[currentKey] = multilineContent.trim();
|
|
64
|
+
}
|
|
65
|
+
inMultiline = false;
|
|
66
|
+
multilineContent = "";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (trimmed.startsWith("- ")) {
|
|
70
|
+
if (!inArray && currentKey) {
|
|
71
|
+
inArray = true;
|
|
72
|
+
arrayItems = [];
|
|
73
|
+
}
|
|
74
|
+
const itemContent = trimmed.slice(2);
|
|
75
|
+
const kvMatch = itemContent.match(/^(\w+):\s*(.*)$/);
|
|
76
|
+
if (kvMatch) {
|
|
77
|
+
const obj = {};
|
|
78
|
+
obj[kvMatch[1]] = kvMatch[2] === "|" ? "" : kvMatch[2] || "";
|
|
79
|
+
if (kvMatch[2] === "|") {
|
|
80
|
+
inMultiline = true;
|
|
81
|
+
indent = line.search(/\S/);
|
|
82
|
+
multilineContent = "";
|
|
83
|
+
}
|
|
84
|
+
arrayItems.push(obj);
|
|
85
|
+
} else {
|
|
86
|
+
arrayItems.push(itemContent);
|
|
87
|
+
}
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (inArray && line.startsWith(" ")) {
|
|
91
|
+
const propMatch = trimmed.match(/^(\w+):\s*(.*)$/);
|
|
92
|
+
if (propMatch && arrayItems.length > 0) {
|
|
93
|
+
const lastItem = arrayItems[arrayItems.length - 1];
|
|
94
|
+
if (typeof lastItem === "object" && lastItem !== null) {
|
|
95
|
+
lastItem[propMatch[1]] = propMatch[2] === "|" ? "" : propMatch[2] || "";
|
|
96
|
+
if (propMatch[2] === "|") {
|
|
97
|
+
inMultiline = true;
|
|
98
|
+
indent = line.search(/\S/);
|
|
99
|
+
multilineContent = "";
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (inArray && !line.startsWith(" ") && !line.startsWith(" ")) {
|
|
106
|
+
if (currentKey) {
|
|
107
|
+
result[currentKey] = arrayItems;
|
|
108
|
+
}
|
|
109
|
+
inArray = false;
|
|
110
|
+
arrayItems = [];
|
|
111
|
+
}
|
|
112
|
+
const match = trimmed.match(/^(\w+):\s*(.*)$/);
|
|
113
|
+
if (match) {
|
|
114
|
+
currentKey = match[1];
|
|
115
|
+
const value = match[2];
|
|
116
|
+
if (value === "" || value === "|" || value === ">") {
|
|
117
|
+
if (value === "|" || value === ">") {
|
|
118
|
+
inMultiline = true;
|
|
119
|
+
indent = line.search(/\S/);
|
|
120
|
+
multilineContent = "";
|
|
121
|
+
}
|
|
122
|
+
} else if (value.startsWith('"') && value.endsWith('"')) {
|
|
123
|
+
result[currentKey] = value.slice(1, -1);
|
|
124
|
+
} else if (value.startsWith("'") && value.endsWith("'")) {
|
|
125
|
+
result[currentKey] = value.slice(1, -1);
|
|
126
|
+
} else if (value === "true") {
|
|
127
|
+
result[currentKey] = true;
|
|
128
|
+
} else if (value === "false") {
|
|
129
|
+
result[currentKey] = false;
|
|
130
|
+
} else if (!isNaN(Number(value))) {
|
|
131
|
+
result[currentKey] = Number(value);
|
|
132
|
+
} else {
|
|
133
|
+
result[currentKey] = value;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (inArray && currentKey) {
|
|
138
|
+
result[currentKey] = arrayItems;
|
|
139
|
+
}
|
|
140
|
+
if (inMultiline && currentKey) {
|
|
141
|
+
result[currentKey] = multilineContent.trim();
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
function parseJson(content) {
|
|
146
|
+
return JSON.parse(content);
|
|
147
|
+
}
|
|
148
|
+
function parseMarkdown(content) {
|
|
149
|
+
const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
|
|
150
|
+
if (frontmatterMatch) {
|
|
151
|
+
const frontmatter = parseSimpleYaml(frontmatterMatch[1]);
|
|
152
|
+
const body = frontmatterMatch[2].trim();
|
|
153
|
+
return {
|
|
154
|
+
...frontmatter,
|
|
155
|
+
messages: [{ role: "system", content: body }]
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
messages: [{ role: "system", content: content.trim() }]
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function normalize(data) {
|
|
163
|
+
const messages = [];
|
|
164
|
+
if (Array.isArray(data.messages)) {
|
|
165
|
+
for (const msg of data.messages) {
|
|
166
|
+
if (typeof msg === "object" && msg !== null) {
|
|
167
|
+
const m = msg;
|
|
168
|
+
messages.push({
|
|
169
|
+
role: m.role || "user",
|
|
170
|
+
content: String(m.content || "")
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (messages.length === 0 && typeof data.content === "string") {
|
|
176
|
+
messages.push({ role: "system", content: data.content });
|
|
177
|
+
}
|
|
178
|
+
if (messages.length === 0 && typeof data.prompt === "string") {
|
|
179
|
+
messages.push({ role: "system", content: data.prompt });
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
name: data.name,
|
|
183
|
+
description: data.description,
|
|
184
|
+
model: data.model,
|
|
185
|
+
modelParameters: data.modelParameters,
|
|
186
|
+
messages,
|
|
187
|
+
variables: data.variables,
|
|
188
|
+
metadata: data.metadata
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function parse(content, format) {
|
|
192
|
+
const trimmed = content.trim();
|
|
193
|
+
if (!format) {
|
|
194
|
+
if (trimmed.startsWith("{")) {
|
|
195
|
+
format = "json";
|
|
196
|
+
} else if (trimmed.startsWith("---")) {
|
|
197
|
+
format = "markdown";
|
|
198
|
+
} else if (trimmed.includes(":") && (trimmed.includes("\n ") || trimmed.includes("\n-"))) {
|
|
199
|
+
format = "yaml";
|
|
200
|
+
} else {
|
|
201
|
+
format = "text";
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
let data;
|
|
205
|
+
switch (format) {
|
|
206
|
+
case "json":
|
|
207
|
+
data = parseJson(trimmed);
|
|
208
|
+
break;
|
|
209
|
+
case "yaml":
|
|
210
|
+
data = parseSimpleYaml(trimmed);
|
|
211
|
+
break;
|
|
212
|
+
case "markdown":
|
|
213
|
+
data = parseMarkdown(trimmed);
|
|
214
|
+
break;
|
|
215
|
+
case "text":
|
|
216
|
+
default:
|
|
217
|
+
data = { messages: [{ role: "system", content: trimmed }] };
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
return normalize(data);
|
|
221
|
+
}
|
|
222
|
+
function toYaml(prompt) {
|
|
223
|
+
const lines = [];
|
|
224
|
+
if (prompt.name) {
|
|
225
|
+
lines.push(`name: ${prompt.name}`);
|
|
226
|
+
}
|
|
227
|
+
if (prompt.description) {
|
|
228
|
+
lines.push(`description: ${prompt.description}`);
|
|
229
|
+
}
|
|
230
|
+
if (prompt.model) {
|
|
231
|
+
lines.push(`model: ${prompt.model}`);
|
|
232
|
+
}
|
|
233
|
+
if (prompt.modelParameters) {
|
|
234
|
+
lines.push("modelParameters:");
|
|
235
|
+
for (const [key, value] of Object.entries(prompt.modelParameters)) {
|
|
236
|
+
if (value !== void 0) {
|
|
237
|
+
lines.push(` ${key}: ${value}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (prompt.messages.length > 0) {
|
|
242
|
+
lines.push("messages:");
|
|
243
|
+
for (const msg of prompt.messages) {
|
|
244
|
+
lines.push(` - role: ${msg.role}`);
|
|
245
|
+
if (msg.content.includes("\n")) {
|
|
246
|
+
lines.push(" content: |");
|
|
247
|
+
for (const line of msg.content.split("\n")) {
|
|
248
|
+
lines.push(` ${line}`);
|
|
249
|
+
}
|
|
250
|
+
} else {
|
|
251
|
+
lines.push(` content: "${msg.content.replace(/"/g, '\\"')}"`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return lines.join("\n");
|
|
256
|
+
}
|
|
257
|
+
function toJson(prompt, pretty = true) {
|
|
258
|
+
return JSON.stringify(prompt, null, pretty ? 2 : 0);
|
|
259
|
+
}
|
|
260
|
+
function getSystemPrompt(prompt) {
|
|
261
|
+
const systemMessage = prompt.messages.find((m) => m.role === "system");
|
|
262
|
+
return systemMessage?.content || "";
|
|
263
|
+
}
|
|
264
|
+
function interpolate(prompt, values) {
|
|
265
|
+
const interpolateString = (str) => {
|
|
266
|
+
return str.replace(/\{\{(\w+)\}\}/g, (match, key) => {
|
|
267
|
+
if (key in values) return values[key];
|
|
268
|
+
if (prompt.variables?.[key]?.default) return prompt.variables[key].default;
|
|
269
|
+
return match;
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
return {
|
|
273
|
+
...prompt,
|
|
274
|
+
messages: prompt.messages.map((msg) => ({
|
|
275
|
+
...msg,
|
|
276
|
+
content: interpolateString(msg.content)
|
|
277
|
+
}))
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
281
|
+
0 && (module.exports = {
|
|
282
|
+
getSystemPrompt,
|
|
283
|
+
interpolate,
|
|
284
|
+
parse,
|
|
285
|
+
toJson,
|
|
286
|
+
toYaml
|
|
287
|
+
});
|
|
288
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/parser/index.ts"],"sourcesContent":["/**\n * Prompt Parser - Parse and load prompt files in various formats\n * \n * Supports:\n * - .prompt.yml / .prompt.yaml (YAML format)\n * - .prompt.json (JSON format)\n * - .prompt.md (Markdown with frontmatter)\n * - .txt (Plain text)\n * \n * @example\n * ```ts\n * import { parser } from 'prompts.chat';\n * \n * const prompt = parser.parse(`\n * name: Code Review\n * messages:\n * - role: system\n * content: You are a code reviewer.\n * `);\n * ```\n */\n\nexport interface PromptMessage {\n role: 'system' | 'user' | 'assistant';\n content: string;\n}\n\nexport interface ParsedPrompt {\n name?: string;\n description?: string;\n model?: string;\n modelParameters?: {\n temperature?: number;\n maxTokens?: number;\n topP?: number;\n frequencyPenalty?: number;\n presencePenalty?: number;\n };\n messages: PromptMessage[];\n variables?: Record<string, {\n description?: string;\n default?: string;\n required?: boolean;\n }>;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Parse YAML content\n * Note: This is a simple YAML parser for common prompt file structures\n * For full YAML support, the consuming project should use a proper YAML library\n */\nfunction parseSimpleYaml(content: string): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n const lines = content.split('\\n');\n \n let currentKey: string | null = null;\n let currentValue: unknown = null;\n let inArray = false;\n let inMultiline = false;\n let multilineContent = '';\n let arrayItems: unknown[] = [];\n let indent = 0;\n \n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n const trimmed = line.trim();\n \n // Skip empty lines and comments\n if (!trimmed || trimmed.startsWith('#')) {\n if (inMultiline) {\n multilineContent += '\\n';\n }\n continue;\n }\n \n // Handle multiline content (|)\n if (inMultiline) {\n const lineIndent = line.search(/\\S/);\n if (lineIndent > indent) {\n multilineContent += (multilineContent ? '\\n' : '') + line.slice(indent + 2);\n continue;\n } else {\n // End of multiline\n if (inArray && currentKey) {\n const lastItem = arrayItems[arrayItems.length - 1] as Record<string, unknown>;\n if (lastItem && typeof lastItem === 'object') {\n const keys = Object.keys(lastItem);\n const lastKey = keys[keys.length - 1];\n lastItem[lastKey] = multilineContent.trim();\n }\n } else if (currentKey) {\n result[currentKey] = multilineContent.trim();\n }\n inMultiline = false;\n multilineContent = '';\n }\n }\n \n // Handle array items\n if (trimmed.startsWith('- ')) {\n if (!inArray && currentKey) {\n inArray = true;\n arrayItems = [];\n }\n \n const itemContent = trimmed.slice(2);\n \n // Check if it's a key-value pair\n const kvMatch = itemContent.match(/^(\\w+):\\s*(.*)$/);\n if (kvMatch) {\n const obj: Record<string, unknown> = {};\n obj[kvMatch[1]] = kvMatch[2] === '|' ? '' : (kvMatch[2] || '');\n \n if (kvMatch[2] === '|') {\n inMultiline = true;\n indent = line.search(/\\S/);\n multilineContent = '';\n }\n \n arrayItems.push(obj);\n } else {\n arrayItems.push(itemContent);\n }\n continue;\n }\n \n // Handle nested object properties in arrays\n if (inArray && line.startsWith(' ')) {\n const propMatch = trimmed.match(/^(\\w+):\\s*(.*)$/);\n if (propMatch && arrayItems.length > 0) {\n const lastItem = arrayItems[arrayItems.length - 1];\n if (typeof lastItem === 'object' && lastItem !== null) {\n (lastItem as Record<string, unknown>)[propMatch[1]] = \n propMatch[2] === '|' ? '' : (propMatch[2] || '');\n \n if (propMatch[2] === '|') {\n inMultiline = true;\n indent = line.search(/\\S/);\n multilineContent = '';\n }\n }\n }\n continue;\n }\n \n // End array if we're back to root level\n if (inArray && !line.startsWith(' ') && !line.startsWith('\\t')) {\n if (currentKey) {\n result[currentKey] = arrayItems;\n }\n inArray = false;\n arrayItems = [];\n }\n \n // Handle key-value pairs\n const match = trimmed.match(/^(\\w+):\\s*(.*)$/);\n if (match) {\n currentKey = match[1];\n const value = match[2];\n \n if (value === '' || value === '|' || value === '>') {\n // Multiline or nested content\n if (value === '|' || value === '>') {\n inMultiline = true;\n indent = line.search(/\\S/);\n multilineContent = '';\n }\n } else if (value.startsWith('\"') && value.endsWith('\"')) {\n result[currentKey] = value.slice(1, -1);\n } else if (value.startsWith(\"'\") && value.endsWith(\"'\")) {\n result[currentKey] = value.slice(1, -1);\n } else if (value === 'true') {\n result[currentKey] = true;\n } else if (value === 'false') {\n result[currentKey] = false;\n } else if (!isNaN(Number(value))) {\n result[currentKey] = Number(value);\n } else {\n result[currentKey] = value;\n }\n }\n }\n \n // Handle remaining array\n if (inArray && currentKey) {\n result[currentKey] = arrayItems;\n }\n \n // Handle remaining multiline\n if (inMultiline && currentKey) {\n result[currentKey] = multilineContent.trim();\n }\n \n return result;\n}\n\n/**\n * Parse JSON content\n */\nfunction parseJson(content: string): Record<string, unknown> {\n return JSON.parse(content);\n}\n\n/**\n * Parse Markdown with frontmatter\n */\nfunction parseMarkdown(content: string): Record<string, unknown> {\n const frontmatterMatch = content.match(/^---\\n([\\s\\S]*?)\\n---\\n([\\s\\S]*)$/);\n \n if (frontmatterMatch) {\n const frontmatter = parseSimpleYaml(frontmatterMatch[1]);\n const body = frontmatterMatch[2].trim();\n \n return {\n ...frontmatter,\n messages: [{ role: 'system', content: body }],\n };\n }\n \n // No frontmatter, treat entire content as system message\n return {\n messages: [{ role: 'system', content: content.trim() }],\n };\n}\n\n/**\n * Normalize parsed data to ParsedPrompt format\n */\nfunction normalize(data: Record<string, unknown>): ParsedPrompt {\n const messages: PromptMessage[] = [];\n \n // Handle messages array\n if (Array.isArray(data.messages)) {\n for (const msg of data.messages) {\n if (typeof msg === 'object' && msg !== null) {\n const m = msg as Record<string, unknown>;\n messages.push({\n role: (m.role as PromptMessage['role']) || 'user',\n content: String(m.content || ''),\n });\n }\n }\n }\n \n // Handle single content field\n if (messages.length === 0 && typeof data.content === 'string') {\n messages.push({ role: 'system', content: data.content });\n }\n \n // Handle prompt field (alias for content)\n if (messages.length === 0 && typeof data.prompt === 'string') {\n messages.push({ role: 'system', content: data.prompt });\n }\n \n return {\n name: data.name as string | undefined,\n description: data.description as string | undefined,\n model: data.model as string | undefined,\n modelParameters: data.modelParameters as ParsedPrompt['modelParameters'],\n messages,\n variables: data.variables as ParsedPrompt['variables'],\n metadata: data.metadata as Record<string, unknown>,\n };\n}\n\n/**\n * Parse prompt content in various formats\n */\nexport function parse(content: string, format?: 'yaml' | 'json' | 'markdown' | 'text'): ParsedPrompt {\n const trimmed = content.trim();\n \n // Auto-detect format if not specified\n if (!format) {\n if (trimmed.startsWith('{')) {\n format = 'json';\n } else if (trimmed.startsWith('---')) {\n format = 'markdown';\n } else if (trimmed.includes(':') && (trimmed.includes('\\n ') || trimmed.includes('\\n-'))) {\n format = 'yaml';\n } else {\n format = 'text';\n }\n }\n \n let data: Record<string, unknown>;\n \n switch (format) {\n case 'json':\n data = parseJson(trimmed);\n break;\n case 'yaml':\n data = parseSimpleYaml(trimmed);\n break;\n case 'markdown':\n data = parseMarkdown(trimmed);\n break;\n case 'text':\n default:\n data = { messages: [{ role: 'system', content: trimmed }] };\n break;\n }\n \n return normalize(data);\n}\n\n/**\n * Serialize a ParsedPrompt to YAML format\n */\nexport function toYaml(prompt: ParsedPrompt): string {\n const lines: string[] = [];\n \n if (prompt.name) {\n lines.push(`name: ${prompt.name}`);\n }\n \n if (prompt.description) {\n lines.push(`description: ${prompt.description}`);\n }\n \n if (prompt.model) {\n lines.push(`model: ${prompt.model}`);\n }\n \n if (prompt.modelParameters) {\n lines.push('modelParameters:');\n for (const [key, value] of Object.entries(prompt.modelParameters)) {\n if (value !== undefined) {\n lines.push(` ${key}: ${value}`);\n }\n }\n }\n \n if (prompt.messages.length > 0) {\n lines.push('messages:');\n for (const msg of prompt.messages) {\n lines.push(` - role: ${msg.role}`);\n if (msg.content.includes('\\n')) {\n lines.push(' content: |');\n for (const line of msg.content.split('\\n')) {\n lines.push(` ${line}`);\n }\n } else {\n lines.push(` content: \"${msg.content.replace(/\"/g, '\\\\\"')}\"`);\n }\n }\n }\n \n return lines.join('\\n');\n}\n\n/**\n * Serialize a ParsedPrompt to JSON format\n */\nexport function toJson(prompt: ParsedPrompt, pretty: boolean = true): string {\n return JSON.stringify(prompt, null, pretty ? 2 : 0);\n}\n\n/**\n * Get the system message content from a parsed prompt\n */\nexport function getSystemPrompt(prompt: ParsedPrompt): string {\n const systemMessage = prompt.messages.find(m => m.role === 'system');\n return systemMessage?.content || '';\n}\n\n/**\n * Interpolate variables in a prompt\n */\nexport function interpolate(\n prompt: ParsedPrompt,\n values: Record<string, string>\n): ParsedPrompt {\n const interpolateString = (str: string): string => {\n return str.replace(/\\{\\{(\\w+)\\}\\}/g, (match, key) => {\n if (key in values) return values[key];\n if (prompt.variables?.[key]?.default) return prompt.variables[key].default!;\n return match;\n });\n };\n \n return {\n ...prompt,\n messages: prompt.messages.map(msg => ({\n ...msg,\n content: interpolateString(msg.content),\n })),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoDA,SAAS,gBAAgB,SAA0C;AACjE,QAAM,SAAkC,CAAC;AACzC,QAAM,QAAQ,QAAQ,MAAM,IAAI;AAEhC,MAAI,aAA4B;AAChC,MAAI,eAAwB;AAC5B,MAAI,UAAU;AACd,MAAI,cAAc;AAClB,MAAI,mBAAmB;AACvB,MAAI,aAAwB,CAAC;AAC7B,MAAI,SAAS;AAEb,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,UAAM,OAAO,MAAM,CAAC;AACpB,UAAM,UAAU,KAAK,KAAK;AAG1B,QAAI,CAAC,WAAW,QAAQ,WAAW,GAAG,GAAG;AACvC,UAAI,aAAa;AACf,4BAAoB;AAAA,MACtB;AACA;AAAA,IACF;AAGA,QAAI,aAAa;AACf,YAAM,aAAa,KAAK,OAAO,IAAI;AACnC,UAAI,aAAa,QAAQ;AACvB,6BAAqB,mBAAmB,OAAO,MAAM,KAAK,MAAM,SAAS,CAAC;AAC1E;AAAA,MACF,OAAO;AAEL,YAAI,WAAW,YAAY;AACzB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AAK,aAAa,IAAI,IAAI,EAAE;AAClC,UAAI,IAAI,QAAQ,SAAS,IAAI,GAAG;AAC9B,cAAM,KAAK,gBAAgB;AAC3B,mBAAW,QAAQ,IAAI,QAAQ,MAAM,IAAI,GAAG;AAC1C,gBAAM,KAAK,SAAS,IAAI,EAAE;AAAA,QAC5B;AAAA,MACF,OAAO;AACL,cAAM,KAAK,iBAAiB,IAAI,QAAQ,QAAQ,MAAM,KAAK,CAAC,GAAG;AAAA,MACjE;AAAA,IACF;AAAA,EACF;AAEA,SAAO,MAAM,KAAK,IAAI;AACxB;AAKO,SAAS,OAAO,QAAsB,SAAkB,MAAc;AAC3E,SAAO,KAAK,UAAU,QAAQ,MAAM,SAAS,IAAI,CAAC;AACpD;AAKO,SAAS,gBAAgB,QAA8B;AAC5D,QAAM,gBAAgB,OAAO,SAAS,KAAK,OAAK,EAAE,SAAS,QAAQ;AACnE,SAAO,eAAe,WAAW;AACnC;AAKO,SAAS,YACd,QACA,QACc;AACd,QAAM,oBAAoB,CAAC,QAAwB;AACjD,WAAO,IAAI,QAAQ,kBAAkB,CAAC,OAAO,QAAQ;AACnD,UAAI,OAAO,OAAQ,QAAO,OAAO,GAAG;AACpC,UAAI,OAAO,YAAY,GAAG,GAAG,QAAS,QAAO,OAAO,UAAU,GAAG,EAAE;AACnE,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,UAAU,OAAO,SAAS,IAAI,UAAQ;AAAA,MACpC,GAAG;AAAA,MACH,SAAS,kBAAkB,IAAI,OAAO;AAAA,IACxC,EAAE;AAAA,EACJ;AACF;","names":[]}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// src/parser/index.ts
|
|
2
|
+
function parseSimpleYaml(content) {
|
|
3
|
+
const result = {};
|
|
4
|
+
const lines = content.split("\n");
|
|
5
|
+
let currentKey = null;
|
|
6
|
+
let currentValue = null;
|
|
7
|
+
let inArray = false;
|
|
8
|
+
let inMultiline = false;
|
|
9
|
+
let multilineContent = "";
|
|
10
|
+
let arrayItems = [];
|
|
11
|
+
let indent = 0;
|
|
12
|
+
for (let i = 0; i < lines.length; i++) {
|
|
13
|
+
const line = lines[i];
|
|
14
|
+
const trimmed = line.trim();
|
|
15
|
+
if (!trimmed || trimmed.startsWith("#")) {
|
|
16
|
+
if (inMultiline) {
|
|
17
|
+
multilineContent += "\n";
|
|
18
|
+
}
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (inMultiline) {
|
|
22
|
+
const lineIndent = line.search(/\S/);
|
|
23
|
+
if (lineIndent > indent) {
|
|
24
|
+
multilineContent += (multilineContent ? "\n" : "") + line.slice(indent + 2);
|
|
25
|
+
continue;
|
|
26
|
+
} else {
|
|
27
|
+
if (inArray && currentKey) {
|
|
28
|
+
const lastItem = arrayItems[arrayItems.length - 1];
|
|
29
|
+
if (lastItem && typeof lastItem === "object") {
|
|
30
|
+
const keys = Object.keys(lastItem);
|
|
31
|
+
const lastKey = keys[keys.length - 1];
|
|
32
|
+
lastItem[lastKey] = multilineContent.trim();
|
|
33
|
+
}
|
|
34
|
+
} else if (currentKey) {
|
|
35
|
+
result[currentKey] = multilineContent.trim();
|
|
36
|
+
}
|
|
37
|
+
inMultiline = false;
|
|
38
|
+
multilineContent = "";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (trimmed.startsWith("- ")) {
|
|
42
|
+
if (!inArray && currentKey) {
|
|
43
|
+
inArray = true;
|
|
44
|
+
arrayItems = [];
|
|
45
|
+
}
|
|
46
|
+
const itemContent = trimmed.slice(2);
|
|
47
|
+
const kvMatch = itemContent.match(/^(\w+):\s*(.*)$/);
|
|
48
|
+
if (kvMatch) {
|
|
49
|
+
const obj = {};
|
|
50
|
+
obj[kvMatch[1]] = kvMatch[2] === "|" ? "" : kvMatch[2] || "";
|
|
51
|
+
if (kvMatch[2] === "|") {
|
|
52
|
+
inMultiline = true;
|
|
53
|
+
indent = line.search(/\S/);
|
|
54
|
+
multilineContent = "";
|
|
55
|
+
}
|
|
56
|
+
arrayItems.push(obj);
|
|
57
|
+
} else {
|
|
58
|
+
arrayItems.push(itemContent);
|
|
59
|
+
}
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (inArray && line.startsWith(" ")) {
|
|
63
|
+
const propMatch = trimmed.match(/^(\w+):\s*(.*)$/);
|
|
64
|
+
if (propMatch && arrayItems.length > 0) {
|
|
65
|
+
const lastItem = arrayItems[arrayItems.length - 1];
|
|
66
|
+
if (typeof lastItem === "object" && lastItem !== null) {
|
|
67
|
+
lastItem[propMatch[1]] = propMatch[2] === "|" ? "" : propMatch[2] || "";
|
|
68
|
+
if (propMatch[2] === "|") {
|
|
69
|
+
inMultiline = true;
|
|
70
|
+
indent = line.search(/\S/);
|
|
71
|
+
multilineContent = "";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (inArray && !line.startsWith(" ") && !line.startsWith(" ")) {
|
|
78
|
+
if (currentKey) {
|
|
79
|
+
result[currentKey] = arrayItems;
|
|
80
|
+
}
|
|
81
|
+
inArray = false;
|
|
82
|
+
arrayItems = [];
|
|
83
|
+
}
|
|
84
|
+
const match = trimmed.match(/^(\w+):\s*(.*)$/);
|
|
85
|
+
if (match) {
|
|
86
|
+
currentKey = match[1];
|
|
87
|
+
const value = match[2];
|
|
88
|
+
if (value === "" || value === "|" || value === ">") {
|
|
89
|
+
if (value === "|" || value === ">") {
|
|
90
|
+
inMultiline = true;
|
|
91
|
+
indent = line.search(/\S/);
|
|
92
|
+
multilineContent = "";
|
|
93
|
+
}
|
|
94
|
+
} else if (value.startsWith('"') && value.endsWith('"')) {
|
|
95
|
+
result[currentKey] = value.slice(1, -1);
|
|
96
|
+
} else if (value.startsWith("'") && value.endsWith("'")) {
|
|
97
|
+
result[currentKey] = value.slice(1, -1);
|
|
98
|
+
} else if (value === "true") {
|
|
99
|
+
result[currentKey] = true;
|
|
100
|
+
} else if (value === "false") {
|
|
101
|
+
result[currentKey] = false;
|
|
102
|
+
} else if (!isNaN(Number(value))) {
|
|
103
|
+
result[currentKey] = Number(value);
|
|
104
|
+
} else {
|
|
105
|
+
result[currentKey] = value;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (inArray && currentKey) {
|
|
110
|
+
result[currentKey] = arrayItems;
|
|
111
|
+
}
|
|
112
|
+
if (inMultiline && currentKey) {
|
|
113
|
+
result[currentKey] = multilineContent.trim();
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
function parseJson(content) {
|
|
118
|
+
return JSON.parse(content);
|
|
119
|
+
}
|
|
120
|
+
function parseMarkdown(content) {
|
|
121
|
+
const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
|
|
122
|
+
if (frontmatterMatch) {
|
|
123
|
+
const frontmatter = parseSimpleYaml(frontmatterMatch[1]);
|
|
124
|
+
const body = frontmatterMatch[2].trim();
|
|
125
|
+
return {
|
|
126
|
+
...frontmatter,
|
|
127
|
+
messages: [{ role: "system", content: body }]
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
messages: [{ role: "system", content: content.trim() }]
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function normalize(data) {
|
|
135
|
+
const messages = [];
|
|
136
|
+
if (Array.isArray(data.messages)) {
|
|
137
|
+
for (const msg of data.messages) {
|
|
138
|
+
if (typeof msg === "object" && msg !== null) {
|
|
139
|
+
const m = msg;
|
|
140
|
+
messages.push({
|
|
141
|
+
role: m.role || "user",
|
|
142
|
+
content: String(m.content || "")
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (messages.length === 0 && typeof data.content === "string") {
|
|
148
|
+
messages.push({ role: "system", content: data.content });
|
|
149
|
+
}
|
|
150
|
+
if (messages.length === 0 && typeof data.prompt === "string") {
|
|
151
|
+
messages.push({ role: "system", content: data.prompt });
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
name: data.name,
|
|
155
|
+
description: data.description,
|
|
156
|
+
model: data.model,
|
|
157
|
+
modelParameters: data.modelParameters,
|
|
158
|
+
messages,
|
|
159
|
+
variables: data.variables,
|
|
160
|
+
metadata: data.metadata
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function parse(content, format) {
|
|
164
|
+
const trimmed = content.trim();
|
|
165
|
+
if (!format) {
|
|
166
|
+
if (trimmed.startsWith("{")) {
|
|
167
|
+
format = "json";
|
|
168
|
+
} else if (trimmed.startsWith("---")) {
|
|
169
|
+
format = "markdown";
|
|
170
|
+
} else if (trimmed.includes(":") && (trimmed.includes("\n ") || trimmed.includes("\n-"))) {
|
|
171
|
+
format = "yaml";
|
|
172
|
+
} else {
|
|
173
|
+
format = "text";
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
let data;
|
|
177
|
+
switch (format) {
|
|
178
|
+
case "json":
|
|
179
|
+
data = parseJson(trimmed);
|
|
180
|
+
break;
|
|
181
|
+
case "yaml":
|
|
182
|
+
data = parseSimpleYaml(trimmed);
|
|
183
|
+
break;
|
|
184
|
+
case "markdown":
|
|
185
|
+
data = parseMarkdown(trimmed);
|
|
186
|
+
break;
|
|
187
|
+
case "text":
|
|
188
|
+
default:
|
|
189
|
+
data = { messages: [{ role: "system", content: trimmed }] };
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
return normalize(data);
|
|
193
|
+
}
|
|
194
|
+
function toYaml(prompt) {
|
|
195
|
+
const lines = [];
|
|
196
|
+
if (prompt.name) {
|
|
197
|
+
lines.push(`name: ${prompt.name}`);
|
|
198
|
+
}
|
|
199
|
+
if (prompt.description) {
|
|
200
|
+
lines.push(`description: ${prompt.description}`);
|
|
201
|
+
}
|
|
202
|
+
if (prompt.model) {
|
|
203
|
+
lines.push(`model: ${prompt.model}`);
|
|
204
|
+
}
|
|
205
|
+
if (prompt.modelParameters) {
|
|
206
|
+
lines.push("modelParameters:");
|
|
207
|
+
for (const [key, value] of Object.entries(prompt.modelParameters)) {
|
|
208
|
+
if (value !== void 0) {
|
|
209
|
+
lines.push(` ${key}: ${value}`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (prompt.messages.length > 0) {
|
|
214
|
+
lines.push("messages:");
|
|
215
|
+
for (const msg of prompt.messages) {
|
|
216
|
+
lines.push(` - role: ${msg.role}`);
|
|
217
|
+
if (msg.content.includes("\n")) {
|
|
218
|
+
lines.push(" content: |");
|
|
219
|
+
for (const line of msg.content.split("\n")) {
|
|
220
|
+
lines.push(` ${line}`);
|
|
221
|
+
}
|
|
222
|
+
} else {
|
|
223
|
+
lines.push(` content: "${msg.content.replace(/"/g, '\\"')}"`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return lines.join("\n");
|
|
228
|
+
}
|
|
229
|
+
function toJson(prompt, pretty = true) {
|
|
230
|
+
return JSON.stringify(prompt, null, pretty ? 2 : 0);
|
|
231
|
+
}
|
|
232
|
+
function getSystemPrompt(prompt) {
|
|
233
|
+
const systemMessage = prompt.messages.find((m) => m.role === "system");
|
|
234
|
+
return systemMessage?.content || "";
|
|
235
|
+
}
|
|
236
|
+
function interpolate(prompt, values) {
|
|
237
|
+
const interpolateString = (str) => {
|
|
238
|
+
return str.replace(/\{\{(\w+)\}\}/g, (match, key) => {
|
|
239
|
+
if (key in values) return values[key];
|
|
240
|
+
if (prompt.variables?.[key]?.default) return prompt.variables[key].default;
|
|
241
|
+
return match;
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
return {
|
|
245
|
+
...prompt,
|
|
246
|
+
messages: prompt.messages.map((msg) => ({
|
|
247
|
+
...msg,
|
|
248
|
+
content: interpolateString(msg.content)
|
|
249
|
+
}))
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
export {
|
|
253
|
+
getSystemPrompt,
|
|
254
|
+
interpolate,
|
|
255
|
+
parse,
|
|
256
|
+
toJson,
|
|
257
|
+
toYaml
|
|
258
|
+
};
|
|
259
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/parser/index.ts"],"sourcesContent":["/**\n * Prompt Parser - Parse and load prompt files in various formats\n * \n * Supports:\n * - .prompt.yml / .prompt.yaml (YAML format)\n * - .prompt.json (JSON format)\n * - .prompt.md (Markdown with frontmatter)\n * - .txt (Plain text)\n * \n * @example\n * ```ts\n * import { parser } from 'prompts.chat';\n * \n * const prompt = parser.parse(`\n * name: Code Review\n * messages:\n * - role: system\n * content: You are a code reviewer.\n * `);\n * ```\n */\n\nexport interface PromptMessage {\n role: 'system' | 'user' | 'assistant';\n content: string;\n}\n\nexport interface ParsedPrompt {\n name?: string;\n description?: string;\n model?: string;\n modelParameters?: {\n temperature?: number;\n maxTokens?: number;\n topP?: number;\n frequencyPenalty?: number;\n presencePenalty?: number;\n };\n messages: PromptMessage[];\n variables?: Record<string, {\n description?: string;\n default?: string;\n required?: boolean;\n }>;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Parse YAML content\n * Note: This is a simple YAML parser for common prompt file structures\n * For full YAML support, the consuming project should use a proper YAML library\n */\nfunction parseSimpleYaml(content: string): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n const lines = content.split('\\n');\n \n let currentKey: string | null = null;\n let currentValue: unknown = null;\n let inArray = false;\n let inMultiline = false;\n let multilineContent = '';\n let arrayItems: unknown[] = [];\n let indent = 0;\n \n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n const trimmed = line.trim();\n \n // Skip empty lines and comments\n if (!trimmed || trimmed.startsWith('#')) {\n if (inMultiline) {\n multilineContent += '\\n';\n }\n continue;\n }\n \n // Handle multiline content (|)\n if (inMultiline) {\n const lineIndent = line.search(/\\S/);\n if (lineIndent > indent) {\n multilineContent += (multilineContent ? '\\n' : '') + line.slice(indent + 2);\n continue;\n } else {\n // End of multiline\n if (inArray && currentKey) {\n const lastItem = arrayItems[arrayItems.length - 1] as Record<string, unknown>;\n if (lastItem && typeof lastItem === 'object') {\n const keys = Object.keys(lastItem);\n const lastKey = keys[keys.length - 1];\n lastItem[lastKey] = multilineContent.trim();\n }\n } else if (currentKey) {\n result[currentKey] = multilineContent.trim();\n }\n inMultiline = false;\n multilineContent = '';\n }\n }\n \n // Handle array items\n if (trimmed.startsWith('- ')) {\n if (!inArray && currentKey) {\n inArray = true;\n arrayItems = [];\n }\n \n const itemContent = trimmed.slice(2);\n \n // Check if it's a key-value pair\n const kvMatch = itemContent.match(/^(\\w+):\\s*(.*)$/);\n if (kvMatch) {\n const obj: Record<string, unknown> = {};\n obj[kvMatch[1]] = kvMatch[2] === '|' ? '' : (kvMatch[2] || '');\n \n if (kvMatch[2] === '|') {\n inMultiline = true;\n indent = line.search(/\\S/);\n multilineContent = '';\n }\n \n arrayItems.push(obj);\n } else {\n arrayItems.push(itemContent);\n }\n continue;\n }\n \n // Handle nested object properties in arrays\n if (inArray && line.startsWith(' ')) {\n const propMatch = trimmed.match(/^(\\w+):\\s*(.*)$/);\n if (propMatch && arrayItems.length > 0) {\n const lastItem = arrayItems[arrayItems.length - 1];\n if (typeof lastItem === 'object' && lastItem !== null) {\n (lastItem as Record<string, unknown>)[propMatch[1]] = \n propMatch[2] === '|' ? '' : (propMatch[2] || '');\n \n if (propMatch[2] === '|') {\n inMultiline = true;\n indent = line.search(/\\S/);\n multilineContent = '';\n }\n }\n }\n continue;\n }\n \n // End array if we're back to root level\n if (inArray && !line.startsWith(' ') && !line.startsWith('\\t')) {\n if (currentKey) {\n result[currentKey] = arrayItems;\n }\n inArray = false;\n arrayItems = [];\n }\n \n // Handle key-value pairs\n const match = trimmed.match(/^(\\w+):\\s*(.*)$/);\n if (match) {\n currentKey = match[1];\n const value = match[2];\n \n if (value === '' || value === '|' || value === '>') {\n // Multiline or nested content\n if (value === '|' || value === '>') {\n inMultiline = true;\n indent = line.search(/\\S/);\n multilineContent = '';\n }\n } else if (value.startsWith('\"') && value.endsWith('\"')) {\n result[currentKey] = value.slice(1, -1);\n } else if (value.startsWith(\"'\") && value.endsWith(\"'\")) {\n result[currentKey] = value.slice(1, -1);\n } else if (value === 'true') {\n result[currentKey] = true;\n } else if (value === 'false') {\n result[currentKey] = false;\n } else if (!isNaN(Number(value))) {\n result[currentKey] = Number(value);\n } else {\n result[currentKey] = value;\n }\n }\n }\n \n // Handle remaining array\n if (inArray && currentKey) {\n result[currentKey] = arrayItems;\n }\n \n // Handle remaining multiline\n if (inMultiline && currentKey) {\n result[currentKey] = multilineContent.trim();\n }\n \n return result;\n}\n\n/**\n * Parse JSON content\n */\nfunction parseJson(content: string): Record<string, unknown> {\n return JSON.parse(content);\n}\n\n/**\n * Parse Markdown with frontmatter\n */\nfunction parseMarkdown(content: string): Record<string, unknown> {\n const frontmatterMatch = content.match(/^---\\n([\\s\\S]*?)\\n---\\n([\\s\\S]*)$/);\n \n if (frontmatterMatch) {\n const frontmatter = parseSimpleYaml(frontmatterMatch[1]);\n const body = frontmatterMatch[2].trim();\n \n return {\n ...frontmatter,\n messages: [{ role: 'system', content: body }],\n };\n }\n \n // No frontmatter, treat entire content as system message\n return {\n messages: [{ role: 'system', content: content.trim() }],\n };\n}\n\n/**\n * Normalize parsed data to ParsedPrompt format\n */\nfunction normalize(data: Record<string, unknown>): ParsedPrompt {\n const messages: PromptMessage[] = [];\n \n // Handle messages array\n if (Array.isArray(data.messages)) {\n for (const msg of data.messages) {\n if (typeof msg === 'object' && msg !== null) {\n const m = msg as Record<string, unknown>;\n messages.push({\n role: (m.role as PromptMessage['role']) || 'user',\n content: String(m.content || ''),\n });\n }\n }\n }\n \n // Handle single content field\n if (messages.length === 0 && typeof data.content === 'string') {\n messages.push({ role: 'system', content: data.content });\n }\n \n // Handle prompt field (alias for content)\n if (messages.length === 0 && typeof data.prompt === 'string') {\n messages.push({ role: 'system', content: data.prompt });\n }\n \n return {\n name: data.name as string | undefined,\n description: data.description as string | undefined,\n model: data.model as string | undefined,\n modelParameters: data.modelParameters as ParsedPrompt['modelParameters'],\n messages,\n variables: data.variables as ParsedPrompt['variables'],\n metadata: data.metadata as Record<string, unknown>,\n };\n}\n\n/**\n * Parse prompt content in various formats\n */\nexport function parse(content: string, format?: 'yaml' | 'json' | 'markdown' | 'text'): ParsedPrompt {\n const trimmed = content.trim();\n \n // Auto-detect format if not specified\n if (!format) {\n if (trimmed.startsWith('{')) {\n format = 'json';\n } else if (trimmed.startsWith('---')) {\n format = 'markdown';\n } else if (trimmed.includes(':') && (trimmed.includes('\\n ') || trimmed.includes('\\n-'))) {\n format = 'yaml';\n } else {\n format = 'text';\n }\n }\n \n let data: Record<string, unknown>;\n \n switch (format) {\n case 'json':\n data = parseJson(trimmed);\n break;\n case 'yaml':\n data = parseSimpleYaml(trimmed);\n break;\n case 'markdown':\n data = parseMarkdown(trimmed);\n break;\n case 'text':\n default:\n data = { messages: [{ role: 'system', content: trimmed }] };\n break;\n }\n \n return normalize(data);\n}\n\n/**\n * Serialize a ParsedPrompt to YAML format\n */\nexport function toYaml(prompt: ParsedPrompt): string {\n const lines: string[] = [];\n \n if (prompt.name) {\n lines.push(`name: ${prompt.name}`);\n }\n \n if (prompt.description) {\n lines.push(`description: ${prompt.description}`);\n }\n \n if (prompt.model) {\n lines.push(`model: ${prompt.model}`);\n }\n \n if (prompt.modelParameters) {\n lines.push('modelParameters:');\n for (const [key, value] of Object.entries(prompt.modelParameters)) {\n if (value !== undefined) {\n lines.push(` ${key}: ${value}`);\n }\n }\n }\n \n if (prompt.messages.length > 0) {\n lines.push('messages:');\n for (const msg of prompt.messages) {\n lines.push(` - role: ${msg.role}`);\n if (msg.content.includes('\\n')) {\n lines.push(' content: |');\n for (const line of msg.content.split('\\n')) {\n lines.push(` ${line}`);\n }\n } else {\n lines.push(` content: \"${msg.content.replace(/\"/g, '\\\\\"')}\"`);\n }\n }\n }\n \n return lines.join('\\n');\n}\n\n/**\n * Serialize a ParsedPrompt to JSON format\n */\nexport function toJson(prompt: ParsedPrompt, pretty: boolean = true): string {\n return JSON.stringify(prompt, null, pretty ? 2 : 0);\n}\n\n/**\n * Get the system message content from a parsed prompt\n */\nexport function getSystemPrompt(prompt: ParsedPrompt): string {\n const systemMessage = prompt.messages.find(m => m.role === 'system');\n return systemMessage?.content || '';\n}\n\n/**\n * Interpolate variables in a prompt\n */\nexport function interpolate(\n prompt: ParsedPrompt,\n values: Record<string, string>\n): ParsedPrompt {\n const interpolateString = (str: string): string => {\n return str.replace(/\\{\\{(\\w+)\\}\\}/g, (match, key) => {\n if (key in values) return values[key];\n if (prompt.variables?.[key]?.default) return prompt.variables[key].default!;\n return match;\n });\n };\n \n return {\n ...prompt,\n messages: prompt.messages.map(msg => ({\n ...msg,\n content: interpolateString(msg.content),\n })),\n };\n}\n"],"mappings":";AAoDA,SAAS,gBAAgB,SAA0C;AACjE,QAAM,SAAkC,CAAC;AACzC,QAAM,QAAQ,QAAQ,MAAM,IAAI;AAEhC,MAAI,aAA4B;AAChC,MAAI,eAAwB;AAC5B,MAAI,UAAU;AACd,MAAI,cAAc;AAClB,MAAI,mBAAmB;AACvB,MAAI,aAAwB,CAAC;AAC7B,MAAI,SAAS;AAEb,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,UAAM,OAAO,MAAM,CAAC;AACpB,UAAM,UAAU,KAAK,KAAK;AAG1B,QAAI,CAAC,WAAW,QAAQ,WAAW,GAAG,GAAG;AACvC,UAAI,aAAa;AACf,4BAAoB;AAAA,MACtB;AACA;AAAA,IACF;AAGA,QAAI,aAAa;AACf,YAAM,aAAa,KAAK,OAAO,IAAI;AACnC,UAAI,aAAa,QAAQ;AACvB,6BAAqB,mBAAmB,OAAO,MAAM,KAAK,MAAM,SAAS,CAAC;AAC1E;AAAA,MACF,OAAO;AAEL,YAAI,WAAW,YAAY;AACzB,gBAAM,WAAW,WA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IAAI,EAAE;AAClC,UAAI,IAAI,QAAQ,SAAS,IAAI,GAAG;AAC9B,cAAM,KAAK,gBAAgB;AAC3B,mBAAW,QAAQ,IAAI,QAAQ,MAAM,IAAI,GAAG;AAC1C,gBAAM,KAAK,SAAS,IAAI,EAAE;AAAA,QAC5B;AAAA,MACF,OAAO;AACL,cAAM,KAAK,iBAAiB,IAAI,QAAQ,QAAQ,MAAM,KAAK,CAAC,GAAG;AAAA,MACjE;AAAA,IACF;AAAA,EACF;AAEA,SAAO,MAAM,KAAK,IAAI;AACxB;AAKO,SAAS,OAAO,QAAsB,SAAkB,MAAc;AAC3E,SAAO,KAAK,UAAU,QAAQ,MAAM,SAAS,IAAI,CAAC;AACpD;AAKO,SAAS,gBAAgB,QAA8B;AAC5D,QAAM,gBAAgB,OAAO,SAAS,KAAK,OAAK,EAAE,SAAS,QAAQ;AACnE,SAAO,eAAe,WAAW;AACnC;AAKO,SAAS,YACd,QACA,QACc;AACd,QAAM,oBAAoB,CAAC,QAAwB;AACjD,WAAO,IAAI,QAAQ,kBAAkB,CAAC,OAAO,QAAQ;AACnD,UAAI,OAAO,OAAQ,QAAO,OAAO,GAAG;AACpC,UAAI,OAAO,YAAY,GAAG,GAAG,QAAS,QAAO,OAAO,UAAU,GAAG,EAAE;AACnE,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,UAAU,OAAO,SAAS,IAAI,UAAQ;AAAA,MACpC,GAAG;AAAA,MACH,SAAS,kBAAkB,IAAI,OAAO;AAAA,IACxC,EAAE;AAAA,EACJ;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { b as QualityIssue, Q as QualityResult, c as check, g as getSuggestions, a as isValid, v as validate } from '../index-CSHEKYfQ.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { b as QualityIssue, Q as QualityResult, c as check, g as getSuggestions, a as isValid, v as validate } from '../index-CSHEKYfQ.js';
|