@oh-my-pi/pi-utils 14.9.2 → 14.9.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/package.json +2 -2
- package/src/prompt.ts +9 -32
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@oh-my-pi/pi-utils",
|
|
4
|
-
"version": "14.9.
|
|
4
|
+
"version": "14.9.3",
|
|
5
5
|
"description": "Shared utilities for pi packages",
|
|
6
6
|
"homepage": "https://github.com/can1357/oh-my-pi",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/bun": "^1.3.13",
|
|
41
|
-
"@oh-my-pi/pi-natives": "14.9.
|
|
41
|
+
"@oh-my-pi/pi-natives": "14.9.3"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
44
|
"bun": ">=1.3.7"
|
package/src/prompt.ts
CHANGED
|
@@ -15,12 +15,8 @@ export interface PromptFormatOptions {
|
|
|
15
15
|
const OPENING_XML = /^<([a-z_-]+)(?:\s+[^>]*)?>$/;
|
|
16
16
|
// Closing XML tag
|
|
17
17
|
const CLOSING_XML = /^<\/([a-z_-]+)>$/;
|
|
18
|
-
// Handlebars block start: {{#if}}, {{#has}}, {{#list}}, etc.
|
|
19
|
-
const OPENING_HBS = /^\{\{#/;
|
|
20
18
|
// Handlebars block end: {{/if}}, {{/has}}, {{/list}}, etc.
|
|
21
19
|
const CLOSING_HBS = /^\{\{\//;
|
|
22
|
-
// List item (- or * or 1.)
|
|
23
|
-
const LIST_ITEM = /^(?:[-*]\s|\d+\.\s)/;
|
|
24
20
|
// Table row
|
|
25
21
|
const TABLE_ROW = /^\|.*\|$/;
|
|
26
22
|
// Table separator (|---|---|)
|
|
@@ -133,25 +129,18 @@ export function format(content: string, options: PromptFormatOptions = {}): stri
|
|
|
133
129
|
line = boldRfc2119Keywords(line);
|
|
134
130
|
}
|
|
135
131
|
|
|
136
|
-
|
|
137
|
-
if (isBlank) {
|
|
138
|
-
const prevLine = result[result.length - 1]?.trim() ?? "";
|
|
132
|
+
if (trimmed === "") {
|
|
139
133
|
const nextLine = lines[i + 1]?.trim() ?? "";
|
|
140
|
-
|
|
141
|
-
if (
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (CLOSING_XML.test(nextLine) || (isPreRender && CLOSING_HBS.test(nextLine))) {
|
|
134
|
+
// Strip any run of 2+ consecutive blank lines entirely; preserve a single blank.
|
|
135
|
+
if (nextLine === "") {
|
|
136
|
+
while (result.length > 0 && result[result.length - 1].trim() === "") {
|
|
137
|
+
result.pop();
|
|
138
|
+
}
|
|
139
|
+
while (i + 1 < lines.length && lines[i + 1].trim() === "") i++;
|
|
150
140
|
continue;
|
|
151
141
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (prevIsBlank) {
|
|
142
|
+
const prevLine = result[result.length - 1]?.trim() ?? "";
|
|
143
|
+
if (prevLine === "") {
|
|
155
144
|
continue;
|
|
156
145
|
}
|
|
157
146
|
}
|
|
@@ -382,18 +371,6 @@ handlebars.registerHelper("not", (value: unknown): boolean => !value);
|
|
|
382
371
|
|
|
383
372
|
handlebars.registerHelper("jsonStringify", (value: unknown): string => JSON.stringify(value));
|
|
384
373
|
|
|
385
|
-
/**
|
|
386
|
-
* {{SECTION_SEPARATOR "Name"}}
|
|
387
|
-
* Renders a visible section header separator used by system-prompt templates.
|
|
388
|
-
*/
|
|
389
|
-
export function sectionSeparator(name: string): string {
|
|
390
|
-
return `\n\n═══════════${name}═══════════\n`;
|
|
391
|
-
}
|
|
392
|
-
const sectionSeparatorHelper = (name: unknown): string => sectionSeparator(String(name));
|
|
393
|
-
handlebars.registerHelper("SECTION_SEPARATOR", sectionSeparatorHelper);
|
|
394
|
-
// Legacy misspelled alias retained for external templates copied from pre-rename versions.
|
|
395
|
-
handlebars.registerHelper("SECTION_SEPERATOR", sectionSeparatorHelper);
|
|
396
|
-
|
|
397
374
|
export function registerHelper(name: string, fn: HelperDelegate): void {
|
|
398
375
|
handlebars.registerHelper(name, fn);
|
|
399
376
|
}
|