@f5-sales-demo/pi-utils 20.2.4 → 20.2.7
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 +1 -43
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@f5-sales-demo/pi-utils",
|
|
4
|
-
"version": "20.2.
|
|
4
|
+
"version": "20.2.7",
|
|
5
5
|
"description": "Shared utilities for pi packages",
|
|
6
6
|
"homepage": "https://github.com/f5-sales-demo/xcsh",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/bun": "^1.3",
|
|
42
|
-
"@f5-sales-demo/pi-natives": "20.2.
|
|
42
|
+
"@f5-sales-demo/pi-natives": "20.2.7"
|
|
43
43
|
},
|
|
44
44
|
"engines": {
|
|
45
45
|
"bun": ">=1.3.7"
|
package/src/prompt.ts
CHANGED
|
@@ -11,16 +11,6 @@ export interface PromptFormatOptions {
|
|
|
11
11
|
boldRfc2119Keywords?: boolean;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
// Opening XML tag (not self-closing, not closing)
|
|
15
|
-
const OPENING_XML = /^<([a-z_-]+)(?:\s+[^>]*)?>$/;
|
|
16
|
-
// Closing XML tag
|
|
17
|
-
const CLOSING_XML = /^<\/([a-z_-]+)>$/;
|
|
18
|
-
// Handlebars block start: {{#if}}, {{#has}}, {{#list}}, etc.
|
|
19
|
-
const OPENING_HBS = /^\{\{#/;
|
|
20
|
-
// Handlebars block end: {{/if}}, {{/has}}, {{/list}}, etc.
|
|
21
|
-
const CLOSING_HBS = /^\{\{\//;
|
|
22
|
-
// List item (- or * or 1.)
|
|
23
|
-
const LIST_ITEM = /^(?:[-*]\s|\d+\.\s)/;
|
|
24
14
|
// Table row
|
|
25
15
|
const TABLE_ROW = /^\|.*\|$/;
|
|
26
16
|
// Table separator (|---|---|)
|
|
@@ -93,7 +83,6 @@ export function format(content: string, options: PromptFormatOptions = {}): stri
|
|
|
93
83
|
const result: string[] = [];
|
|
94
84
|
let inCodeBlock = false;
|
|
95
85
|
let inBoldSpan = false;
|
|
96
|
-
const topLevelTags: string[] = [];
|
|
97
86
|
|
|
98
87
|
for (let i = 0; i < lines.length; i++) {
|
|
99
88
|
let line = lines[i].trimEnd();
|
|
@@ -115,19 +104,7 @@ export function format(content: string, options: PromptFormatOptions = {}): stri
|
|
|
115
104
|
trimmedStart = line.trimStart();
|
|
116
105
|
const trimmed = line.trim();
|
|
117
106
|
|
|
118
|
-
|
|
119
|
-
if (isOpeningXml && line.length === trimmedStart.length) {
|
|
120
|
-
const match = OPENING_XML.exec(trimmedStart);
|
|
121
|
-
if (match) topLevelTags.push(match[1]);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const closingMatch = CLOSING_XML.exec(trimmedStart);
|
|
125
|
-
if (closingMatch) {
|
|
126
|
-
const tagName = closingMatch[1];
|
|
127
|
-
if (topLevelTags.length > 0 && topLevelTags[topLevelTags.length - 1] === tagName) {
|
|
128
|
-
topLevelTags.pop();
|
|
129
|
-
}
|
|
130
|
-
} else if (isPreRender && trimmedStart.startsWith("{{")) {
|
|
107
|
+
if (isPreRender && trimmedStart.startsWith("{{")) {
|
|
131
108
|
/* keep indentation as-is in pre-render for Handlebars markers */
|
|
132
109
|
} else if (TABLE_SEP.test(trimmedStart)) {
|
|
133
110
|
const leadingWhitespace = line.slice(0, line.length - trimmedStart.length);
|
|
@@ -147,19 +124,6 @@ export function format(content: string, options: PromptFormatOptions = {}): stri
|
|
|
147
124
|
const isBlank = trimmed === "";
|
|
148
125
|
if (isBlank) {
|
|
149
126
|
const prevLine = result[result.length - 1]?.trim() ?? "";
|
|
150
|
-
const nextLine = lines[i + 1]?.trim() ?? "";
|
|
151
|
-
|
|
152
|
-
if (LIST_ITEM.test(nextLine)) {
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (OPENING_XML.test(prevLine) || (isPreRender && OPENING_HBS.test(prevLine))) {
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (CLOSING_XML.test(nextLine) || (isPreRender && CLOSING_HBS.test(nextLine))) {
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
127
|
|
|
164
128
|
const prevIsBlank = prevLine === "";
|
|
165
129
|
if (prevIsBlank) {
|
|
@@ -167,12 +131,6 @@ export function format(content: string, options: PromptFormatOptions = {}): stri
|
|
|
167
131
|
}
|
|
168
132
|
}
|
|
169
133
|
|
|
170
|
-
if (CLOSING_XML.test(trimmed) || (isPreRender && CLOSING_HBS.test(trimmed))) {
|
|
171
|
-
while (result.length > 0 && result[result.length - 1].trim() === "") {
|
|
172
|
-
result.pop();
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
134
|
result.push(line);
|
|
177
135
|
}
|
|
178
136
|
|