@mrclrchtr/supi-ask-user 4.0.0 → 4.2.0
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/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-core/src/settings/settings-action-menu.ts +1 -0
- package/node_modules/@mrclrchtr/supi-core/src/settings/settings-schema.ts +9 -0
- package/node_modules/@mrclrchtr/supi-core/src/settings.ts +1 -0
- package/package.json +2 -2
- package/src/normalize.ts +17 -8
|
@@ -34,6 +34,7 @@ export function buildActionMenu(field: ScopedFieldValue, scope: SettingsScope):
|
|
|
34
34
|
if (choices.length > 0) {
|
|
35
35
|
for (const choice of choices) menu.push({ value: `set:${choice}`, label: choice });
|
|
36
36
|
} else if (field.field.kind === "number") menu.push({ value: "edit", label: "Edit value…" });
|
|
37
|
+
else if (field.field.kind === "string") menu.push({ value: "edit", label: "Edit value…" });
|
|
37
38
|
else if (field.field.kind === "stringList") menu.push({ value: "edit", label: "Edit values…" });
|
|
38
39
|
else if (field.field.kind === "modelPicker")
|
|
39
40
|
menu.push({ value: "edit", label: "Choose model…" });
|
|
@@ -86,6 +86,11 @@ export interface NumberField extends BaseField {
|
|
|
86
86
|
values?: string[];
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
/** One free-form string. */
|
|
90
|
+
export interface StringField extends BaseField {
|
|
91
|
+
kind: "string";
|
|
92
|
+
}
|
|
93
|
+
|
|
89
94
|
/** Comma-separated string list. */
|
|
90
95
|
export interface StringListField extends BaseField {
|
|
91
96
|
kind: "stringList";
|
|
@@ -164,6 +169,7 @@ export type SettingsField =
|
|
|
164
169
|
| BoolField
|
|
165
170
|
| EnumField
|
|
166
171
|
| NumberField
|
|
172
|
+
| StringField
|
|
167
173
|
| StringListField
|
|
168
174
|
| ModelPickerField
|
|
169
175
|
| CustomField;
|
|
@@ -248,6 +254,8 @@ export function formatValue(value: unknown, field: SettingsField): string {
|
|
|
248
254
|
return value ? "on" : "off";
|
|
249
255
|
case "number":
|
|
250
256
|
return String(value ?? "");
|
|
257
|
+
case "string":
|
|
258
|
+
return typeof value === "string" && value ? value : "none";
|
|
251
259
|
case "stringList": {
|
|
252
260
|
const arr = Array.isArray(value) ? value : [];
|
|
253
261
|
return arr.length > 0 ? arr.map(String).join(", ") : "none";
|
|
@@ -271,6 +279,7 @@ export function sourceBadge(displayValue: string, source: ValueSource): string {
|
|
|
271
279
|
|
|
272
280
|
/** Format the value used to prefill editors and compare concrete choices. */
|
|
273
281
|
export function formatEditValue(value: unknown, field: SettingsField): string {
|
|
282
|
+
if (field.kind === "string") return typeof value === "string" ? value : "";
|
|
274
283
|
if (field.kind === "stringList") {
|
|
275
284
|
const arr = Array.isArray(value) ? value : [];
|
|
276
285
|
return arr.map(String).join(", ");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrclrchtr/supi-ask-user",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "SuPi ask-user extension — rich questionnaire UI for structured agent-user decisions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"!__tests__"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@mrclrchtr/supi-core": "4.
|
|
35
|
+
"@mrclrchtr/supi-core": "4.2.0"
|
|
36
36
|
},
|
|
37
37
|
"bundledDependencies": [
|
|
38
38
|
"@mrclrchtr/supi-core"
|
package/src/normalize.ts
CHANGED
|
@@ -80,8 +80,8 @@ function validateQuestionCount(count: number): void {
|
|
|
80
80
|
|
|
81
81
|
function validateCommonFields(question: ExternalQuestion): void {
|
|
82
82
|
const id = question.id.trim();
|
|
83
|
-
const header = question.header
|
|
84
|
-
const prompt = question.prompt
|
|
83
|
+
const header = normalizeDisplayText(question.header);
|
|
84
|
+
const prompt = normalizeDisplayText(question.prompt);
|
|
85
85
|
|
|
86
86
|
if (!id) throw new AskUserValidationError("Question id must be a non-empty string.");
|
|
87
87
|
if (!header) {
|
|
@@ -119,8 +119,8 @@ function normalizeChoice(question: ExternalChoiceQuestion): NormalizedChoiceQues
|
|
|
119
119
|
|
|
120
120
|
return {
|
|
121
121
|
id: question.id.trim(),
|
|
122
|
-
header: question.header
|
|
123
|
-
prompt: question.prompt
|
|
122
|
+
header: normalizeDisplayText(question.header),
|
|
123
|
+
prompt: normalizeDisplayText(question.prompt),
|
|
124
124
|
type: "choice",
|
|
125
125
|
options,
|
|
126
126
|
multi,
|
|
@@ -155,8 +155,8 @@ function normalizeText(question: ExternalTextQuestion): NormalizedTextQuestion {
|
|
|
155
155
|
|
|
156
156
|
return {
|
|
157
157
|
id: question.id.trim(),
|
|
158
|
-
header: question.header
|
|
159
|
-
prompt: question.prompt
|
|
158
|
+
header: normalizeDisplayText(question.header),
|
|
159
|
+
prompt: normalizeDisplayText(question.prompt),
|
|
160
160
|
type: "text",
|
|
161
161
|
...(recommendation ? { recommendation } : {}),
|
|
162
162
|
...(placeholder ? { placeholder } : {}),
|
|
@@ -179,7 +179,7 @@ function normalizeOptions(
|
|
|
179
179
|
const seen = new Set<string>();
|
|
180
180
|
return options.map((option) => {
|
|
181
181
|
const value = option.value.trim();
|
|
182
|
-
const label = option.label
|
|
182
|
+
const label = normalizeDisplayText(option.label);
|
|
183
183
|
if (!value || !label) {
|
|
184
184
|
throw new AskUserValidationError(
|
|
185
185
|
`choice question "${questionId}" has an option with empty value or label.`,
|
|
@@ -251,7 +251,16 @@ function resolveIndexes(args: {
|
|
|
251
251
|
});
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
+
/** Decodes JSON-style Unicode escapes that models sometimes emit literally in display text. */
|
|
255
|
+
function normalizeDisplayText(value: string): string {
|
|
256
|
+
return value
|
|
257
|
+
.replace(/\\u([0-9a-fA-F]{4})/g, (_escape, hex: string) =>
|
|
258
|
+
String.fromCharCode(Number.parseInt(hex, 16)),
|
|
259
|
+
)
|
|
260
|
+
.trim();
|
|
261
|
+
}
|
|
262
|
+
|
|
254
263
|
function trimOptional(value: string | undefined): string | undefined {
|
|
255
|
-
const trimmed = value
|
|
264
|
+
const trimmed = value === undefined ? undefined : normalizeDisplayText(value);
|
|
256
265
|
return trimmed ? trimmed : undefined;
|
|
257
266
|
}
|