@linxiraos/pi-tui 1.4.13 → 1.5.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/CHANGELOG.md +17 -34
- package/dist/types/chat/messages.d.ts +2 -0
- package/dist/types/chat/spotlight.d.ts +8 -3
- package/dist/types/chat/transcript-render-helpers.d.ts +5 -0
- package/dist/types/components/editor.d.ts +4 -1
- package/dist/types/html-form/data.d.ts +56 -0
- package/dist/types/html-form/dialog.d.ts +51 -0
- package/dist/types/html-form/media.d.ts +28 -0
- package/dist/types/html-form/paginate.d.ts +43 -0
- package/dist/types/html-form/parse.d.ts +99 -0
- package/dist/types/overlays/ask-dialog.d.ts +11 -6
- package/dist/types/overlays/copy-targets.d.ts +8 -6
- package/dist/types/overlays/hook-editor.d.ts +3 -1
- package/dist/types/overlays/hub-frame.d.ts +2 -0
- package/dist/types/overlays/model-hub.d.ts +2 -0
- package/dist/types/overlays/team-hub.d.ts +150 -0
- package/dist/types/render/row-moves.d.ts +41 -0
- package/dist/types/status-line/component.d.ts +5 -0
- package/dist/types/status-line/host.d.ts +2 -2
- package/dist/types/status-line/schema.d.ts +1 -1
- package/dist/types/status-line/types.d.ts +8 -0
- package/dist/types/tools/ask.d.ts +11 -49
- package/dist/types/tools/autoresearch.d.ts +2 -2
- package/dist/types/tools/eval.d.ts +4 -0
- package/dist/types/tools/grouped-file-output.d.ts +2 -0
- package/dist/types/tools/shell-viz.d.ts +6 -2
- package/dist/types/tools/xd-url.d.ts +6 -0
- package/dist/types/windows-input-mode.d.ts +8 -0
- package/package.json +9 -9
- package/src/charts/table-data.ts +18 -5
- package/src/chat/chat-transcript-builder.ts +27 -10
- package/src/chat/image-loading.ts +55 -0
- package/src/chat/messages.d.ts +2 -0
- package/src/chat/messages.ts +3 -0
- package/src/chat/spotlight.d.ts +8 -3
- package/src/chat/spotlight.ts +23 -11
- package/src/chat/tool-execution.ts +5 -0
- package/src/chat/transcript-render-helpers.d.ts +5 -0
- package/src/chat/transcript-render-helpers.ts +13 -0
- package/src/chrome/transcript-container.ts +1 -1
- package/src/components/editor.d.ts +4 -1
- package/src/components/editor.ts +3 -2
- package/src/components/markdown.ts +70 -12
- package/src/html-form/data.d.ts +56 -0
- package/src/html-form/data.ts +177 -0
- package/src/html-form/dialog.ts +1450 -0
- package/src/html-form/media.ts +105 -0
- package/src/html-form/paginate.ts +99 -0
- package/src/html-form/parse.d.ts +99 -0
- package/src/html-form/parse.ts +568 -0
- package/src/lang-from-path.ts +1 -0
- package/src/latex-block.ts +3 -3
- package/src/latex-to-unicode.ts +18 -5
- package/src/overlays/ask-dialog.ts +69 -52
- package/src/overlays/copy-targets.d.ts +8 -6
- package/src/overlays/copy-targets.ts +25 -46
- package/src/overlays/hook-editor.ts +16 -15
- package/src/overlays/hub-frame.ts +8 -1
- package/src/overlays/model-hub.ts +12 -2
- package/src/overlays/spotlight-sheet.ts +18 -18
- package/src/overlays/team-hub.ts +901 -0
- package/src/render/row-moves.d.ts +41 -0
- package/src/render/row-moves.ts +109 -0
- package/src/setup/wizard-overlay.ts +7 -3
- package/src/status-line/component.ts +19 -0
- package/src/status-line/footer.ts +2 -2
- package/src/status-line/host.ts +2 -2
- package/src/status-line/presets.ts +6 -6
- package/src/status-line/schema.ts +2 -1
- package/src/status-line/segments.ts +31 -4
- package/src/status-line/startup.ts +1 -1
- package/src/status-line/types.ts +8 -0
- package/src/stdin-buffer.ts +15 -1
- package/src/terminal-capabilities.ts +12 -3
- package/src/terminal.ts +41 -3
- package/src/tools/ask.d.ts +11 -49
- package/src/tools/ask.ts +201 -606
- package/src/tools/autoresearch.ts +2 -2
- package/src/tools/debug.ts +31 -38
- package/src/tools/eval.d.ts +4 -0
- package/src/tools/eval.ts +4 -0
- package/src/tools/grep.ts +38 -16
- package/src/tools/grouped-file-output.d.ts +2 -0
- package/src/tools/grouped-file-output.ts +5 -0
- package/src/tools/shell-viz-render.ts +37 -6
- package/src/tools/shell-viz.d.ts +6 -2
- package/src/tools/shell-viz.ts +19 -6
- package/src/tools/xd-url.d.ts +6 -0
- package/src/tools/xd-url.ts +19 -1
- package/src/tui.ts +129 -1
- package/src/windows-input-mode.d.ts +8 -0
- package/src/windows-input-mode.ts +13 -0
package/src/tools/ask.ts
CHANGED
|
@@ -1,205 +1,51 @@
|
|
|
1
1
|
import type { NativeToolHead, NativeToolView, ToolRenderer, ToolRenderResult } from "./renderer";
|
|
2
|
-
import { formatCount } from "@linxiraos/pi-utils";
|
|
3
|
-
import
|
|
4
|
-
import { compact, md, node, row, span, text } from "../native/describe";
|
|
2
|
+
import { formatCount, isRecord, sanitizeText } from "@linxiraos/pi-utils";
|
|
3
|
+
import { compact, node, row, span, text } from "../native/describe";
|
|
5
4
|
import type { NativeChild, NativeNode } from "../native/node";
|
|
6
5
|
import { OwnerMemo } from "../native/memo";
|
|
7
|
-
import { plainText } from "../native/spans";
|
|
8
6
|
import { noteText, resultText } from "./native-view";
|
|
9
7
|
|
|
10
|
-
import {
|
|
11
|
-
type Component,
|
|
12
|
-
lexDocument,
|
|
13
|
-
Markdown,
|
|
14
|
-
type MarkdownTheme,
|
|
15
|
-
renderInlineMarkdown,
|
|
16
|
-
replaceTabs,
|
|
17
|
-
Text,
|
|
18
|
-
truncateToWidth,
|
|
19
|
-
visibleWidth,
|
|
20
|
-
} from "../index";
|
|
8
|
+
import { type Component, replaceTabs, Text, truncateToWidth, visibleWidth } from "../index";
|
|
21
9
|
|
|
22
10
|
import type { RenderResultOptions } from "./renderer";
|
|
23
11
|
|
|
24
|
-
import {
|
|
12
|
+
import type { Theme } from "../theme/theme";
|
|
25
13
|
|
|
26
|
-
import {
|
|
27
|
-
import { framedToolCard } from "../render/tool-card";
|
|
14
|
+
import { renderStatusLine } from "../render";
|
|
15
|
+
import { framedToolCard, type ToolCardSection } from "../render/tool-card";
|
|
28
16
|
import { wrapPrefixedLine } from "../render/hanging-wrap";
|
|
29
17
|
|
|
30
|
-
import {
|
|
31
|
-
|
|
32
|
-
/** Result for a single question */
|
|
33
|
-
export interface QuestionResult {
|
|
34
|
-
id: string;
|
|
35
|
-
question: string;
|
|
36
|
-
options: string[];
|
|
37
|
-
multi: boolean;
|
|
38
|
-
selectedOptions: string[];
|
|
39
|
-
customInput?: string;
|
|
40
|
-
/** Optional note attached to the selected answer in the rich ask dialog. */
|
|
41
|
-
note?: string;
|
|
42
|
-
/** Label of the option the note is on; unset when it is on the custom answer. */
|
|
43
|
-
noteOption?: string;
|
|
44
|
-
/** True when the answer was auto-selected because the dialog timed out. */
|
|
45
|
-
timedOut?: boolean;
|
|
46
|
-
}
|
|
18
|
+
import { formatStatusIcon, formatTitle, PREVIEW_LIMITS } from "../render/render-utils";
|
|
47
19
|
|
|
48
|
-
|
|
20
|
+
import { type FormAnswer, fieldQuestions, OTHER_LABEL } from "../html-form/data";
|
|
21
|
+
import {
|
|
22
|
+
type ChoiceField,
|
|
23
|
+
type FormField,
|
|
24
|
+
type HtmlForm,
|
|
25
|
+
parseHtmlForm,
|
|
26
|
+
spansText,
|
|
27
|
+
type TextField,
|
|
28
|
+
} from "../html-form/parse";
|
|
29
|
+
|
|
30
|
+
/** Answers displayed for an ask tool result. */
|
|
49
31
|
export interface AskToolDetails {
|
|
50
|
-
question
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
selectedOptions?: string[];
|
|
54
|
-
customInput?: string;
|
|
55
|
-
/** Optional note attached to the selected answer in the rich ask dialog. */
|
|
56
|
-
note?: string;
|
|
57
|
-
/** Label of the option the note is on; unset when it is on the custom answer. */
|
|
58
|
-
noteOption?: string;
|
|
59
|
-
/** True when the answer was auto-selected because the dialog timed out. */
|
|
32
|
+
/** Each named field's question and answer text, in form order (from `formAnswers`). */
|
|
33
|
+
answers: FormAnswer[];
|
|
34
|
+
/** The deadline submitted the form's current values instead of the user. */
|
|
60
35
|
timedOut?: boolean;
|
|
61
|
-
/** Multi-part question mode */
|
|
62
|
-
results?: QuestionResult[];
|
|
63
|
-
/** Chat redirect: the user chose "Chat about this" instead of answering. */
|
|
64
|
-
chatRedirect?: boolean;
|
|
65
|
-
/** Questions surfaced when chatRedirect is true. */
|
|
66
|
-
questions?: string[];
|
|
67
36
|
}
|
|
68
37
|
|
|
69
38
|
// =============================================================================
|
|
70
39
|
// TUI Renderer
|
|
71
40
|
// =============================================================================
|
|
72
41
|
|
|
73
|
-
interface AskRenderOption {
|
|
74
|
-
label: string;
|
|
75
|
-
description?: string;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
42
|
interface AskRenderArgs {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
multi?: boolean;
|
|
82
|
-
questions?: Array<{
|
|
83
|
-
id: string;
|
|
84
|
-
question: string;
|
|
85
|
-
options: AskRenderOption[];
|
|
86
|
-
multi?: boolean;
|
|
87
|
-
}>;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Coerce an untrusted option list (streamed or model-mangled call args) into
|
|
92
|
-
* well-formed render options. Bare strings become labels; entries without a
|
|
93
|
-
* string label are dropped.
|
|
94
|
-
*/
|
|
95
|
-
function normalizeRenderOptions(raw: unknown): AskRenderOption[] | undefined {
|
|
96
|
-
if (!Array.isArray(raw)) return undefined;
|
|
97
|
-
const out: AskRenderOption[] = [];
|
|
98
|
-
for (const entry of raw) {
|
|
99
|
-
if (typeof entry === "string") {
|
|
100
|
-
out.push({ label: sanitizeCarriageReturns(entry) });
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
if (!entry || typeof entry !== "object") continue;
|
|
104
|
-
const { label, description } = entry as Partial<AskRenderOption>;
|
|
105
|
-
if (typeof label !== "string") continue;
|
|
106
|
-
out.push(
|
|
107
|
-
typeof description === "string"
|
|
108
|
-
? { label: sanitizeCarriageReturns(label), description: sanitizeCarriageReturns(description) }
|
|
109
|
-
: { label: sanitizeCarriageReturns(label) },
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
return out;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Strip the `\r` runs degenerate models inject from persisted result details,
|
|
117
|
-
* so transcripts completed before params sanitization still render as prose.
|
|
118
|
-
* Display-only — the persisted payload is untouched.
|
|
119
|
-
*/
|
|
120
|
-
function sanitizeAskResultDetails(details: AskToolDetails): AskToolDetails {
|
|
121
|
-
return {
|
|
122
|
-
...details,
|
|
123
|
-
...(details.question !== undefined ? { question: sanitizeCarriageReturns(details.question) } : {}),
|
|
124
|
-
...(details.options !== undefined ? { options: details.options.map(sanitizeCarriageReturns) } : {}),
|
|
125
|
-
...(details.selectedOptions !== undefined
|
|
126
|
-
? { selectedOptions: details.selectedOptions.map(sanitizeCarriageReturns) }
|
|
127
|
-
: {}),
|
|
128
|
-
...(details.customInput !== undefined ? { customInput: sanitizeCarriageReturns(details.customInput) } : {}),
|
|
129
|
-
...(details.note !== undefined ? { note: sanitizeCarriageReturns(details.note) } : {}),
|
|
130
|
-
...(details.questions !== undefined ? { questions: details.questions.map(sanitizeCarriageReturns) } : {}),
|
|
131
|
-
...(details.results !== undefined
|
|
132
|
-
? {
|
|
133
|
-
results: details.results.map(entry => ({
|
|
134
|
-
...entry,
|
|
135
|
-
id: sanitizeCarriageReturns(entry.id),
|
|
136
|
-
question: sanitizeCarriageReturns(entry.question),
|
|
137
|
-
options: entry.options.map(sanitizeCarriageReturns),
|
|
138
|
-
selectedOptions: entry.selectedOptions.map(sanitizeCarriageReturns),
|
|
139
|
-
...(entry.customInput !== undefined
|
|
140
|
-
? { customInput: sanitizeCarriageReturns(entry.customInput) }
|
|
141
|
-
: {}),
|
|
142
|
-
...(entry.note !== undefined ? { note: sanitizeCarriageReturns(entry.note) } : {}),
|
|
143
|
-
})),
|
|
144
|
-
}
|
|
145
|
-
: {}),
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Coerce untrusted `questions` call args into a renderable array. Models
|
|
151
|
-
* occasionally double-encode the array as a JSON string — a bare string passes
|
|
152
|
-
* a truthy `.length` check but has no `.map`, which used to crash the TUI
|
|
153
|
-
* render loop. Partially streamed args can also be missing fields.
|
|
154
|
-
*/
|
|
155
|
-
function normalizeRenderQuestions(raw: unknown): NonNullable<AskRenderArgs["questions"]> | undefined {
|
|
156
|
-
if (typeof raw === "string") {
|
|
157
|
-
try {
|
|
158
|
-
raw = JSON.parse(raw);
|
|
159
|
-
} catch {
|
|
160
|
-
return undefined;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
if (!Array.isArray(raw)) return undefined;
|
|
164
|
-
const out: NonNullable<AskRenderArgs["questions"]> = [];
|
|
165
|
-
for (const entry of raw) {
|
|
166
|
-
if (!entry || typeof entry !== "object") continue;
|
|
167
|
-
const q = entry as Partial<NonNullable<AskRenderArgs["questions"]>[number]>;
|
|
168
|
-
out.push({
|
|
169
|
-
id: typeof q.id === "string" ? sanitizeCarriageReturns(q.id) : "?",
|
|
170
|
-
question: typeof q.question === "string" ? sanitizeCarriageReturns(q.question) : "",
|
|
171
|
-
options: normalizeRenderOptions(q.options) ?? [],
|
|
172
|
-
multi: q.multi === true,
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
return out;
|
|
43
|
+
/** The form the model asks with; streams in partially. */
|
|
44
|
+
html?: string;
|
|
176
45
|
}
|
|
177
46
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const lines = customInput.split("\n");
|
|
181
|
-
const icon = formatStatusIcon("success", uiTheme);
|
|
182
|
-
// Continuation rows line up under the answer text, past the glyph's own width.
|
|
183
|
-
const indent = " ".repeat(visibleWidth(icon) + 2);
|
|
184
|
-
const out: string[] = [` ${icon} ${uiTheme.fg("toolOutput", lines[0] ?? "")}`];
|
|
185
|
-
for (let i = 1; i < lines.length; i++) out.push(`${indent}${uiTheme.fg("toolOutput", lines[i])}`);
|
|
186
|
-
return out;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/** Render an answer note with tab replacement and line-width clamping. */
|
|
190
|
-
function renderNoteLines(uiTheme: Theme, note: string, width: number): string[] {
|
|
191
|
-
const prefix = " Note: ";
|
|
192
|
-
const continuationPrefix = " ";
|
|
193
|
-
const firstLineWidth = Math.max(1, width - visibleWidth(prefix));
|
|
194
|
-
const continuationWidth = Math.max(1, width - visibleWidth(continuationPrefix));
|
|
195
|
-
return replaceTabs(note)
|
|
196
|
-
.split("\n")
|
|
197
|
-
.map((line, index) => {
|
|
198
|
-
const linePrefix = index === 0 ? `${uiTheme.fg("dim", " Note:")} ` : continuationPrefix;
|
|
199
|
-
const maxWidth = index === 0 ? firstLineWidth : continuationWidth;
|
|
200
|
-
return `${linePrefix}${uiTheme.fg("toolOutput", truncateToWidth(line, maxWidth))}`;
|
|
201
|
-
});
|
|
202
|
-
}
|
|
47
|
+
const TIMED_OUT_NOTE = "auto-selected after timeout — not a user choice";
|
|
48
|
+
const NO_ANSWER = "(no answer)";
|
|
203
49
|
|
|
204
50
|
/**
|
|
205
51
|
* Marker glyph for a question option. Single-choice questions render circular radio
|
|
@@ -210,284 +56,190 @@ export function optionMarker(uiTheme: Theme, multi: boolean | undefined, selecte
|
|
|
210
56
|
return selected ? uiTheme.radio.selected : uiTheme.radio.unselected;
|
|
211
57
|
}
|
|
212
58
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
return
|
|
59
|
+
/** Model-authored text made safe for a terminal row: no escapes or control characters, tabs expanded. */
|
|
60
|
+
function clean(value: string): string {
|
|
61
|
+
return replaceTabs(sanitizeText(value));
|
|
216
62
|
}
|
|
217
63
|
|
|
218
|
-
/**
|
|
219
|
-
function
|
|
220
|
-
|
|
221
|
-
mdTheme: MarkdownTheme,
|
|
222
|
-
options: AskRenderOption[],
|
|
223
|
-
multi: boolean | undefined,
|
|
224
|
-
width: number,
|
|
225
|
-
): string[] {
|
|
226
|
-
const out: string[] = [];
|
|
227
|
-
for (const opt of options) {
|
|
228
|
-
const optLabel = renderInlineMarkdown(opt.label, mdTheme, t => uiTheme.fg("muted", t));
|
|
229
|
-
out.push(...wrapOptionLabel(uiTheme.fg("dim", optionMarker(uiTheme, multi, false)), optLabel, width));
|
|
230
|
-
if (opt.description?.trim()) {
|
|
231
|
-
const description = renderInlineMarkdown(opt.description.trim(), mdTheme, t => uiTheme.fg("dim", t));
|
|
232
|
-
const prefix = ` ${uiTheme.fg("dim", "↳")} `;
|
|
233
|
-
out.push(...wrapPrefixedLine(prefix, " ".repeat(visibleWidth(prefix)), description, width));
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
return out;
|
|
64
|
+
/** {@link clean} text folded onto one line. */
|
|
65
|
+
function oneLine(value: string): string {
|
|
66
|
+
return clean(value).replace(/\s+/g, " ").trim();
|
|
237
67
|
}
|
|
238
68
|
|
|
239
|
-
/**
|
|
240
|
-
function
|
|
241
|
-
const
|
|
242
|
-
if (
|
|
243
|
-
|
|
244
|
-
return flags;
|
|
69
|
+
/** The form in untrusted (streamed or model-mangled) call args; undefined until markup arrives. */
|
|
70
|
+
function argsForm(args: AskRenderArgs | undefined): HtmlForm | undefined {
|
|
71
|
+
const html = args?.html;
|
|
72
|
+
if (typeof html !== "string" || html.trim() === "") return undefined;
|
|
73
|
+
return parseHtmlForm(html);
|
|
245
74
|
}
|
|
246
75
|
|
|
247
|
-
/**
|
|
248
|
-
function
|
|
249
|
-
const
|
|
250
|
-
|
|
76
|
+
/** Names of the form's password fields, whose values never reach the transcript. */
|
|
77
|
+
function passwordNames(form: HtmlForm | undefined): Set<string> {
|
|
78
|
+
const names = new Set<string>();
|
|
79
|
+
for (const field of form?.fields ?? []) {
|
|
80
|
+
if (field.kind === "text" && field.type === "password" && field.name) names.add(field.name);
|
|
81
|
+
}
|
|
82
|
+
return names;
|
|
251
83
|
}
|
|
252
84
|
|
|
253
|
-
/**
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
85
|
+
/** Well-formed answers from persisted details; undefined for errors and sessions predating HTML forms. */
|
|
86
|
+
function detailsAnswers(details: AskToolDetails | undefined): FormAnswer[] | undefined {
|
|
87
|
+
const raw: unknown = details?.answers;
|
|
88
|
+
if (!Array.isArray(raw)) return undefined;
|
|
89
|
+
const answers: FormAnswer[] = [];
|
|
90
|
+
for (const entry of raw) {
|
|
91
|
+
if (!isRecord(entry)) continue;
|
|
92
|
+
const { name, question, answer } = entry;
|
|
93
|
+
if (typeof question !== "string" || typeof answer !== "string") continue;
|
|
94
|
+
answers.push({ name: typeof name === "string" ? name : "", question, answer });
|
|
95
|
+
}
|
|
96
|
+
return answers;
|
|
258
97
|
}
|
|
259
98
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
return {
|
|
265
|
-
text: uiTheme.fg("dim", `(${[label, ...flags].join(uiTheme.sep.dot)})`),
|
|
266
|
-
afterText: lastBlock?.type === "paragraph",
|
|
267
|
-
};
|
|
99
|
+
/** Shown text of an answer: masked for password fields, sanitized otherwise. */
|
|
100
|
+
function answerShown(answer: FormAnswer, passwords: ReadonlySet<string>): string {
|
|
101
|
+
if (passwords.has(answer.name)) return "•".repeat(Math.min(answer.answer.length, 12));
|
|
102
|
+
return clean(answer.answer);
|
|
268
103
|
}
|
|
269
104
|
|
|
270
|
-
/**
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const last = lines.at(-1)?.trimEnd() ?? "";
|
|
278
|
-
const fits = last.trim() !== "" && visibleWidth(last) + 1 + visibleWidth(tag.text) <= contentWidth;
|
|
279
|
-
// A tag wider than the row wraps under its own one-column indent.
|
|
280
|
-
if (!tag.afterText || !fits) return [...lines, ...wrapPrefixedLine(" ", " ", tag.text, contentWidth)];
|
|
281
|
-
return [...lines.slice(0, -1), `${last} ${tag.text}`];
|
|
105
|
+
/** `lines` capped at `limit`, with a dim `… N more lines` row standing in for the rest. */
|
|
106
|
+
function capLines(uiTheme: Theme, lines: string[], limit: number, indent: string): string[] {
|
|
107
|
+
if (lines.length <= limit) return lines;
|
|
108
|
+
return [
|
|
109
|
+
...lines.slice(0, limit),
|
|
110
|
+
`${indent}${uiTheme.fg("dim", `… ${formatCount("more line", lines.length - limit)}`)}`,
|
|
111
|
+
];
|
|
282
112
|
}
|
|
283
113
|
|
|
284
|
-
/**
|
|
285
|
-
function
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
114
|
+
/** Option rows of a choice field with its preselected state marked, capped unless expanded. */
|
|
115
|
+
function choiceFieldLines(uiTheme: Theme, field: ChoiceField, width: number, expanded: boolean): string[] {
|
|
116
|
+
const limit = expanded ? field.options.length : PREVIEW_LIMITS.COLLAPSED_ITEMS;
|
|
117
|
+
const out: string[] = [];
|
|
118
|
+
for (const option of field.options.slice(0, limit)) {
|
|
119
|
+
const marker = uiTheme.fg(option.checked ? "success" : "dim", optionMarker(uiTheme, field.multi, option.checked));
|
|
120
|
+
const color = option.disabled ? "dim" : option.checked ? "toolOutput" : "muted";
|
|
121
|
+
const prefix = ` ${marker} `;
|
|
122
|
+
const label = oneLine(spansText(option.label)) || oneLine(option.value);
|
|
123
|
+
out.push(...wrapPrefixedLine(prefix, " ".repeat(visibleWidth(prefix)), uiTheme.fg(color, label), width));
|
|
124
|
+
}
|
|
125
|
+
const hidden = field.options.length - limit;
|
|
126
|
+
if (hidden > 0) out.push(` ${uiTheme.fg("dim", `… ${formatCount("more option", hidden)}`)}`);
|
|
127
|
+
else if (field.other)
|
|
128
|
+
out.push(` ${uiTheme.fg("dim", `${optionMarker(uiTheme, field.multi, false)} ${OTHER_LABEL}…`)}`);
|
|
129
|
+
return out;
|
|
289
130
|
}
|
|
290
131
|
|
|
291
|
-
/**
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
* Returns undefined when raw options are missing so the caller falls back to
|
|
301
|
-
* label matching.
|
|
302
|
-
*/
|
|
303
|
-
function selectedIndicesFor(
|
|
304
|
-
rawOptions: string[] | undefined,
|
|
305
|
-
rawSelected: string[] | undefined,
|
|
306
|
-
): Set<number> | undefined {
|
|
307
|
-
if (!rawOptions || rawOptions.length === 0) return undefined;
|
|
308
|
-
const wanted = new Set(rawSelected ?? []);
|
|
309
|
-
const indices = new Set<number>();
|
|
310
|
-
rawOptions.forEach((option, index) => {
|
|
311
|
-
if (wanted.has(option)) indices.add(index);
|
|
312
|
-
});
|
|
313
|
-
return indices;
|
|
132
|
+
/** Input rows of a text field: its prefilled value, else its placeholder dimmed, behind an input bar. */
|
|
133
|
+
function textFieldLines(uiTheme: Theme, field: TextField, width: number, expanded: boolean): string[] {
|
|
134
|
+
const prefix = ` ${uiTheme.fg("border", uiTheme.boxRound.vertical)} `;
|
|
135
|
+
const inner = Math.max(1, width - visibleWidth(prefix));
|
|
136
|
+
const shown = field.type === "password" ? "•".repeat(Math.min(field.value.length, 12)) : clean(field.value);
|
|
137
|
+
const lines = shown
|
|
138
|
+
? shown.split("\n").map(line => `${prefix}${uiTheme.fg("toolOutput", truncateToWidth(line, inner))}`)
|
|
139
|
+
: [`${prefix}${uiTheme.fg("dim", truncateToWidth(oneLine(field.placeholder), inner))}`];
|
|
140
|
+
return capLines(uiTheme, lines, expanded ? PREVIEW_LIMITS.EXPANDED_LINES : PREVIEW_LIMITS.COLLAPSED_LINES, " ");
|
|
314
141
|
}
|
|
315
142
|
|
|
316
|
-
/**
|
|
317
|
-
|
|
318
|
-
* selection marker filled in, plus any custom free-text answer. Flat marker
|
|
319
|
-
* bullets — the frame is the container, so no tree guides are drawn.
|
|
320
|
-
*/
|
|
321
|
-
function renderAnswerOptionLines(
|
|
143
|
+
/** Pending form summary: one card section per fieldset, each field's question over its options or input. */
|
|
144
|
+
function formSections(
|
|
322
145
|
uiTheme: Theme,
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
selectedOptions: string[] | undefined,
|
|
326
|
-
multi: boolean | undefined,
|
|
327
|
-
customInput: string | undefined,
|
|
328
|
-
note: string | undefined,
|
|
146
|
+
form: HtmlForm,
|
|
147
|
+
questions: ReadonlyMap<FormField, string>,
|
|
329
148
|
width: number,
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
149
|
+
expanded: boolean,
|
|
150
|
+
): ToolCardSection[] {
|
|
151
|
+
const sections: ToolCardSection[] = [];
|
|
152
|
+
for (const section of form.sections) {
|
|
153
|
+
const title = oneLine(spansText(section.title));
|
|
154
|
+
const content: string[] = title
|
|
155
|
+
? wrapPrefixedLine(" ", " ", uiTheme.bold(uiTheme.fg("accent", title)), width)
|
|
156
|
+
: [];
|
|
157
|
+
for (const block of section.blocks) {
|
|
158
|
+
if (block.kind !== "field") continue;
|
|
159
|
+
const field = block.field;
|
|
160
|
+
const question = oneLine(questions.get(field) ?? field.name);
|
|
161
|
+
// A fieldset's lone group answers its legend; the title already says it.
|
|
162
|
+
if (question && question !== title) {
|
|
163
|
+
const required = field.required ? uiTheme.fg("error", " *") : "";
|
|
164
|
+
content.push(...wrapPrefixedLine(" ", " ", `${uiTheme.fg("text", question)}${required}`, width));
|
|
165
|
+
}
|
|
166
|
+
content.push(
|
|
167
|
+
...(field.kind === "choice"
|
|
168
|
+
? choiceFieldLines(uiTheme, field, width, expanded)
|
|
169
|
+
: textFieldLines(uiTheme, field, width, expanded)),
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
if (content.length > 0) sections.push({ content, separator: sections.length > 0 });
|
|
341
173
|
}
|
|
174
|
+
return sections;
|
|
175
|
+
}
|
|
342
176
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
177
|
+
/** Answer rows: a success check before the answer with continuation rows beneath it, or a dim placeholder. */
|
|
178
|
+
function answerLines(uiTheme: Theme, shown: string, width: number, expanded: boolean): string[] {
|
|
179
|
+
if (shown === "") return [` ${uiTheme.fg("dim", NO_ANSWER)}`];
|
|
180
|
+
const prefix = ` ${formatStatusIcon("success", uiTheme)} `;
|
|
181
|
+
const indent = " ".repeat(visibleWidth(prefix));
|
|
182
|
+
const rows = shown
|
|
183
|
+
.split("\n")
|
|
184
|
+
.flatMap((line, index) =>
|
|
185
|
+
wrapPrefixedLine(index === 0 ? prefix : indent, indent, uiTheme.fg("toolOutput", line), width),
|
|
350
186
|
);
|
|
351
|
-
|
|
352
|
-
}
|
|
353
|
-
if (customInput !== undefined) out.push(...renderCustomInputLines(uiTheme, customInput));
|
|
354
|
-
if (note !== undefined) out.push(...renderNoteLines(uiTheme, note, width));
|
|
355
|
-
return out;
|
|
187
|
+
return capLines(uiTheme, rows, expanded ? PREVIEW_LIMITS.OUTPUT_EXPANDED : PREVIEW_LIMITS.OUTPUT_COLLAPSED, indent);
|
|
356
188
|
}
|
|
357
189
|
|
|
358
190
|
function askHead(question: string | undefined, meta?: string): NativeToolHead {
|
|
359
|
-
const first = question ?
|
|
191
|
+
const first = question ? oneLine(question) : "";
|
|
360
192
|
return { title: "Ask", target: first || undefined, targetKind: "text", meta: meta ? [meta] : undefined };
|
|
361
193
|
}
|
|
362
194
|
|
|
363
|
-
/**
|
|
364
|
-
function
|
|
365
|
-
|
|
195
|
+
/** Questions of the form's named fields, in form order. */
|
|
196
|
+
function namedQuestions(form: HtmlForm | undefined): string[] {
|
|
197
|
+
if (!form) return [];
|
|
198
|
+
const questions = fieldQuestions(form);
|
|
199
|
+
return form.fields.flatMap(field => (field.name ? [questions.get(field) ?? field.name] : []));
|
|
366
200
|
}
|
|
367
201
|
|
|
368
|
-
/**
|
|
369
|
-
function answerRow(key: string, label: TspSpan[], chosen: boolean): NativeNode {
|
|
370
|
-
return row(
|
|
371
|
-
compact([chosen ? node("icon", { name: "check", tone: "success" }) : undefined, text(label, { wrap: "word" })]),
|
|
372
|
-
{ gap: "sm", align: "baseline", role: chosen ? "zeta.tool.answer" : "zeta.tool.answer.off", key },
|
|
373
|
-
);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* Answered option list: every offered option marked chosen or not, plus any
|
|
378
|
-
* quoted custom answer and a muted note. A lone "Cancelled" line when nothing was chosen.
|
|
379
|
-
*/
|
|
380
|
-
function describeAnswers(
|
|
381
|
-
options: string[] | undefined,
|
|
382
|
-
selectedOptions: string[] | undefined,
|
|
383
|
-
customInput: string | undefined,
|
|
384
|
-
note: string | undefined,
|
|
385
|
-
selectedIndices: ReadonlySet<number> | undefined,
|
|
386
|
-
): NativeChild[] {
|
|
387
|
-
const selected = new Set(selectedOptions ?? []);
|
|
388
|
-
if (selected.size === 0 && customInput === undefined && note === undefined) {
|
|
389
|
-
return [text([span("Cancelled", "warning")], { tone: "warning" })];
|
|
390
|
-
}
|
|
391
|
-
const labels = options && options.length > 0 ? options : (selectedOptions ?? []);
|
|
392
|
-
const rows = labels.map((label, index) => {
|
|
393
|
-
const isSelected = selectedIndices !== undefined ? selectedIndices.has(index) : selected.has(label);
|
|
394
|
-
return answerRow(`${index}`, [span(plainText(label), isSelected ? "toolOutput" : "muted")], isSelected);
|
|
395
|
-
});
|
|
396
|
-
if (customInput !== undefined) {
|
|
397
|
-
rows.push(answerRow("custom", [span(`\u201c${plainText(customInput)}\u201d`, "toolOutput")], true));
|
|
398
|
-
}
|
|
399
|
-
return compact([
|
|
400
|
-
...rows,
|
|
401
|
-
note !== undefined
|
|
402
|
-
? text([span(plainText(note), "muted")], { wrap: "word", role: "zeta.tool.context" })
|
|
403
|
-
: undefined,
|
|
404
|
-
]);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
/** Pending ask: an inline head naming the question; the ask dialog owns the form. */
|
|
202
|
+
/** Pending ask: an inline head naming the first question; the form dialog owns the interaction. */
|
|
408
203
|
function describeAskCall(args: AskRenderArgs): NativeToolView {
|
|
409
|
-
const questions =
|
|
410
|
-
const first = questions?.[0]?.question ?? (typeof args.question === "string" ? args.question : undefined);
|
|
411
|
-
const more = questions && questions.length > 1 ? `${questions.length} questions` : undefined;
|
|
204
|
+
const questions = namedQuestions(argsForm(args));
|
|
412
205
|
return {
|
|
413
|
-
tool: askHead(
|
|
206
|
+
tool: askHead(questions[0], questions.length > 1 ? formatCount("field", questions.length) : undefined),
|
|
414
207
|
inline: true,
|
|
415
208
|
body: [text([span("Waiting for your answer…", "muted")])],
|
|
416
209
|
};
|
|
417
210
|
}
|
|
418
211
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
if (details.chatRedirect) {
|
|
431
|
-
return {
|
|
432
|
-
tool: askHead(details.questions?.[0] ?? argQuestion, "chat redirect"),
|
|
433
|
-
tone: "info",
|
|
434
|
-
body: (details.questions ?? []).map(q => md(plainText(q))),
|
|
435
|
-
};
|
|
436
|
-
}
|
|
212
|
+
/** One answered field: its question over a checked answer row, or a dim placeholder when left empty. */
|
|
213
|
+
function describeAnswer(answer: FormAnswer, shown: string, key: string): NativeNode {
|
|
214
|
+
const body: NativeChild = shown
|
|
215
|
+
? row([node("icon", { name: "check", tone: "success" }), text([span(shown, "toolOutput")], { wrap: "word" })], {
|
|
216
|
+
gap: "sm",
|
|
217
|
+
align: "baseline",
|
|
218
|
+
role: "zeta.tool.answer",
|
|
219
|
+
})
|
|
220
|
+
: text([span(NO_ANSWER, "dim")], { role: "zeta.tool.answer.off" });
|
|
221
|
+
return node("section", {}, [text([span(oneLine(answer.question))], { wrap: "word" }), body], key);
|
|
222
|
+
}
|
|
437
223
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
r.customInput !== undefined || r.note !== undefined || (r.selectedOptions && r.selectedOptions.length > 0),
|
|
444
|
-
);
|
|
224
|
+
function describeAskResult(result: ToolRenderResult<AskToolDetails>, args: AskRenderArgs | undefined): NativeToolView {
|
|
225
|
+
const answers = detailsAnswers(result.details);
|
|
226
|
+
const form = argsForm(args);
|
|
227
|
+
if (!answers) {
|
|
228
|
+
const fallback = clean(resultText(result));
|
|
445
229
|
return {
|
|
446
|
-
tool: askHead(
|
|
447
|
-
tone:
|
|
448
|
-
|
|
449
|
-
body: results.map((r, index) =>
|
|
450
|
-
describeQuestionSection(
|
|
451
|
-
r.id,
|
|
452
|
-
r.question,
|
|
453
|
-
describeAnswers(
|
|
454
|
-
r.options,
|
|
455
|
-
r.selectedOptions,
|
|
456
|
-
r.customInput,
|
|
457
|
-
r.note,
|
|
458
|
-
selectedIndicesFor(rawResults[index]?.options, rawResults[index]?.selectedOptions),
|
|
459
|
-
),
|
|
460
|
-
),
|
|
461
|
-
),
|
|
230
|
+
tool: askHead(namedQuestions(form)[0]),
|
|
231
|
+
tone: "warning",
|
|
232
|
+
body: fallback ? [noteText(fallback)] : undefined,
|
|
462
233
|
};
|
|
463
234
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
return { tool: askHead(argQuestion), body: fallback ? [text(fallback, { wrap: "word" })] : undefined };
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
const answered =
|
|
470
|
-
details.customInput !== undefined ||
|
|
471
|
-
details.note !== undefined ||
|
|
472
|
-
(details.selectedOptions && details.selectedOptions.length > 0);
|
|
235
|
+
const passwords = passwordNames(form);
|
|
236
|
+
const timedOut = result.details?.timedOut === true;
|
|
473
237
|
return {
|
|
474
|
-
tool: askHead(
|
|
475
|
-
tone:
|
|
476
|
-
body: compact([
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
details.options,
|
|
480
|
-
details.selectedOptions,
|
|
481
|
-
details.customInput,
|
|
482
|
-
details.note,
|
|
483
|
-
selectedIndicesFor(rawDetails.options, rawDetails.selectedOptions),
|
|
484
|
-
),
|
|
485
|
-
details.timedOut
|
|
486
|
-
? text([span("auto-selected after timeout — not a user choice", "muted")], {
|
|
487
|
-
wrap: "word",
|
|
488
|
-
role: "zeta.tool.notice",
|
|
489
|
-
})
|
|
490
|
-
: undefined,
|
|
238
|
+
tool: askHead(answers[0]?.question, answers.length > 1 ? formatCount("question", answers.length) : undefined),
|
|
239
|
+
tone: timedOut ? "warning" : undefined,
|
|
240
|
+
body: compact<NativeChild>([
|
|
241
|
+
...answers.map((answer, index) => describeAnswer(answer, answerShown(answer, passwords), `${index}`)),
|
|
242
|
+
timedOut ? text([span(TIMED_OUT_NOTE, "muted")], { wrap: "word", role: "zeta.tool.notice" }) : undefined,
|
|
491
243
|
]),
|
|
492
244
|
};
|
|
493
245
|
}
|
|
@@ -495,10 +247,10 @@ function describeAskResult(result: ToolRenderResult<AskToolDetails>, args: AskRe
|
|
|
495
247
|
const askCallMemo = new OwnerMemo<NativeToolView | undefined>();
|
|
496
248
|
const askResultMemo = new OwnerMemo<NativeToolView | undefined>();
|
|
497
249
|
|
|
498
|
-
/** Render question forms and their
|
|
250
|
+
/** Render HTML question forms and their submitted answers. */
|
|
499
251
|
export const askToolRenderer = {
|
|
500
252
|
describeCall(args: AskRenderArgs): NativeToolView | undefined {
|
|
501
|
-
return askCallMemo.get(args, [
|
|
253
|
+
return askCallMemo.get(args, [args.html], () => describeAskCall(args));
|
|
502
254
|
},
|
|
503
255
|
describeResult(
|
|
504
256
|
result: ToolRenderResult<AskToolDetails>,
|
|
@@ -508,212 +260,55 @@ export const askToolRenderer = {
|
|
|
508
260
|
return askResultMemo.get(result, [], () => describeAskResult(result, args));
|
|
509
261
|
},
|
|
510
262
|
mergeCallAndResult: true,
|
|
511
|
-
renderCall(args: AskRenderArgs,
|
|
512
|
-
|
|
513
|
-
const
|
|
514
|
-
const
|
|
515
|
-
const
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
// Several: each question is tagged with its id and flags, divided by plain separators.
|
|
525
|
-
const lone = questions.length === 1 ? questions[0] : undefined;
|
|
526
|
-
const footerMeta = lone ? formatQuestionFlags(uiTheme, lone.multi, lone.options.length) : undefined;
|
|
527
|
-
const tags = lone
|
|
528
|
-
? undefined
|
|
529
|
-
: questions.map(q => questionTag(uiTheme, q.question, q.id, questionFlags(q.multi, q.options.length)));
|
|
530
|
-
return framedToolCard(uiTheme, ({ width, contentWidth }) => {
|
|
531
|
-
const sections = questions.map((q, index) => {
|
|
532
|
-
const mdLines = md(q.question, width);
|
|
533
|
-
// md() returns a shared cached array (module-level Markdown LRU) — copy before appending.
|
|
534
|
-
const content = [
|
|
535
|
-
...(tags ? appendQuestionTag(mdLines, tags[index]!, contentWidth) : mdLines),
|
|
536
|
-
...renderQuestionOptionLines(uiTheme, mdTheme, q.options, q.multi, contentWidth),
|
|
537
|
-
];
|
|
538
|
-
return { content, separator: index > 0 };
|
|
539
|
-
});
|
|
540
|
-
return { header, sections, footerMeta, phase: "pending", borderColor: "borderMuted" };
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
// Single question
|
|
545
|
-
if (typeof args.question !== "string" || !args.question) {
|
|
546
|
-
const errorLine = formatErrorMessage("No question provided", uiTheme);
|
|
547
|
-
return framedToolCard(uiTheme, () => ({
|
|
548
|
-
header: errorLine,
|
|
549
|
-
sections: [],
|
|
550
|
-
phase: "error",
|
|
551
|
-
borderColor: "error",
|
|
552
|
-
}));
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
const question = sanitizeCarriageReturns(args.question);
|
|
556
|
-
const questionOptions = normalizeRenderOptions(args.options) ?? [];
|
|
557
|
-
const multi = args.multi;
|
|
558
|
-
const footerMeta = formatQuestionFlags(uiTheme, multi, questionOptions.length);
|
|
559
|
-
return framedToolCard(uiTheme, ({ width, contentWidth }) => {
|
|
560
|
-
// md() returns a shared cached array (module-level Markdown LRU) — copy before appending.
|
|
561
|
-
const bodyLines = [
|
|
562
|
-
...md(question, width),
|
|
563
|
-
...renderQuestionOptionLines(uiTheme, mdTheme, questionOptions, multi, contentWidth),
|
|
564
|
-
];
|
|
565
|
-
return {
|
|
566
|
-
header: label,
|
|
567
|
-
sections: bodyLines.length > 0 ? [{ content: bodyLines }] : [],
|
|
568
|
-
footerMeta,
|
|
569
|
-
phase: "pending",
|
|
570
|
-
borderColor: "borderMuted",
|
|
571
|
-
};
|
|
572
|
-
});
|
|
263
|
+
renderCall(args: AskRenderArgs, options: RenderResultOptions, uiTheme: Theme): Component {
|
|
264
|
+
// Call args are untrusted (partially streamed or model-mangled); the parser tolerates truncated markup.
|
|
265
|
+
const form = argsForm(args);
|
|
266
|
+
const questions = form ? fieldQuestions(form) : undefined;
|
|
267
|
+
const named = form?.fields.filter(field => field.name).length ?? 0;
|
|
268
|
+
const footerMeta = named > 0 ? uiTheme.fg("dim", formatCount("field", named)) : undefined;
|
|
269
|
+
return framedToolCard(uiTheme, ({ contentWidth }) => ({
|
|
270
|
+
header: formatTitle("Ask", uiTheme),
|
|
271
|
+
sections: form && questions ? formSections(uiTheme, form, questions, contentWidth, options.expanded) : [],
|
|
272
|
+
footerMeta,
|
|
273
|
+
phase: "pending",
|
|
274
|
+
borderColor: "borderMuted",
|
|
275
|
+
}));
|
|
573
276
|
},
|
|
574
277
|
|
|
575
278
|
renderResult(
|
|
576
279
|
result: { content: Array<{ type: string; text?: string }>; details?: AskToolDetails },
|
|
577
|
-
|
|
280
|
+
options: RenderResultOptions,
|
|
578
281
|
uiTheme: Theme,
|
|
579
282
|
args?: AskRenderArgs,
|
|
580
283
|
): Component {
|
|
581
|
-
const
|
|
582
|
-
|
|
583
|
-
const accentStyle = { color: (t: string) => uiTheme.fg("accent", t) };
|
|
584
|
-
const md = (text: string, width: number) =>
|
|
585
|
-
new Markdown(text, 1, 0, mdTheme, accentStyle).render(Math.max(1, outputBlockContentWidth(width) + 1));
|
|
586
|
-
|
|
587
|
-
const argQuestions = normalizeRenderQuestions(args?.questions);
|
|
588
|
-
const argSubject = argQuestions?.length ? askSubject(argQuestions) : undefined;
|
|
589
|
-
|
|
590
|
-
if (!rawDetails) {
|
|
284
|
+
const answers = detailsAnswers(result.details);
|
|
285
|
+
if (!answers) {
|
|
591
286
|
const txt = result.content[0];
|
|
592
|
-
const fallback = txt?.type === "text" && txt.text ?
|
|
593
|
-
const header = renderStatusLine({ icon: "warning", title: "Ask"
|
|
287
|
+
const fallback = txt?.type === "text" && txt.text ? clean(txt.text) : "";
|
|
288
|
+
const header = renderStatusLine({ icon: "warning", title: "Ask" }, uiTheme);
|
|
594
289
|
const body = fallback ? `\n${uiTheme.fg("dim", fallback)}` : "";
|
|
595
290
|
return new Text(`${header}${body}`, 0, 0);
|
|
596
291
|
}
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
if (details.chatRedirect) {
|
|
601
|
-
const header = renderStatusLine(
|
|
602
|
-
{ icon: "info", title: "Ask", description: argSubject, meta: ["chat redirect"] },
|
|
603
|
-
uiTheme,
|
|
604
|
-
);
|
|
605
|
-
const questions = details.questions ?? [];
|
|
606
|
-
return framedToolCard(uiTheme, ({ width }) => ({
|
|
607
|
-
header,
|
|
608
|
-
sections: questions.length > 0 ? [{ content: questions.flatMap(q => md(q, width)) }] : [],
|
|
609
|
-
phase: "warning",
|
|
610
|
-
borderColor: "borderMuted",
|
|
611
|
-
}));
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
// Multi-part results: one separator-divided section per question, each tagged with its id.
|
|
615
|
-
if (details.results && details.results.length > 0) {
|
|
616
|
-
const results = details.results;
|
|
617
|
-
const hasAnySelection = results.some(
|
|
618
|
-
r =>
|
|
619
|
-
r.customInput !== undefined ||
|
|
620
|
-
r.note !== undefined ||
|
|
621
|
-
(r.selectedOptions && r.selectedOptions.length > 0),
|
|
622
|
-
);
|
|
623
|
-
const tags =
|
|
624
|
-
results.length === 1
|
|
625
|
-
? undefined
|
|
626
|
-
: results.map(r => questionTag(uiTheme, r.question, r.id, r.multi ? ["multi"] : []));
|
|
627
|
-
const header = renderStatusLine(
|
|
628
|
-
{
|
|
629
|
-
icon: hasAnySelection ? "success" : "warning",
|
|
630
|
-
title: "Ask",
|
|
631
|
-
description: askSubject(results),
|
|
632
|
-
},
|
|
633
|
-
uiTheme,
|
|
634
|
-
);
|
|
635
|
-
return framedToolCard(uiTheme, ({ width, contentWidth }) => {
|
|
636
|
-
const rawResults = rawDetails.results ?? [];
|
|
637
|
-
const sections = results.map((r, index) => {
|
|
638
|
-
// Sanitizing preserves order and length, so raw indices align with `r`.
|
|
639
|
-
const raw = rawResults[index];
|
|
640
|
-
const mdLines = md(r.question, width);
|
|
641
|
-
// md() returns a shared cached array (module-level Markdown LRU) — copy before appending.
|
|
642
|
-
const lines = [
|
|
643
|
-
...(tags ? appendQuestionTag(mdLines, tags[index]!, contentWidth) : mdLines),
|
|
644
|
-
...renderAnswerOptionLines(
|
|
645
|
-
uiTheme,
|
|
646
|
-
mdTheme,
|
|
647
|
-
r.options,
|
|
648
|
-
r.selectedOptions,
|
|
649
|
-
r.multi,
|
|
650
|
-
r.customInput,
|
|
651
|
-
r.note,
|
|
652
|
-
width,
|
|
653
|
-
contentWidth,
|
|
654
|
-
selectedIndicesFor(raw?.options, raw?.selectedOptions),
|
|
655
|
-
),
|
|
656
|
-
];
|
|
657
|
-
return { content: lines, separator: index > 0 };
|
|
658
|
-
});
|
|
659
|
-
return {
|
|
660
|
-
header,
|
|
661
|
-
sections,
|
|
662
|
-
phase: hasAnySelection ? "success" : "warning",
|
|
663
|
-
borderColor: "borderMuted",
|
|
664
|
-
};
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
// Single question result
|
|
669
|
-
if (!details.question) {
|
|
670
|
-
const txt = result.content[0];
|
|
671
|
-
const fallback = txt?.type === "text" && txt.text ? sanitizeCarriageReturns(txt.text) : "";
|
|
672
|
-
return new Text(fallback, 0, 0);
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
const question = details.question;
|
|
676
|
-
const hasSelection =
|
|
677
|
-
details.customInput !== undefined ||
|
|
678
|
-
details.note !== undefined ||
|
|
679
|
-
(details.selectedOptions && details.selectedOptions.length > 0);
|
|
292
|
+
const timedOut = result.details?.timedOut === true;
|
|
293
|
+
const passwords = passwordNames(argsForm(args));
|
|
294
|
+
const shown = answers.map(answer => answerShown(answer, passwords));
|
|
680
295
|
const header = renderStatusLine(
|
|
681
|
-
|
|
682
|
-
? {
|
|
683
|
-
: {
|
|
296
|
+
timedOut
|
|
297
|
+
? { icon: "warning", title: "Ask" }
|
|
298
|
+
: { iconOverride: uiTheme.styledSymbol("tool.ask", "accent"), title: "Ask" },
|
|
684
299
|
uiTheme,
|
|
685
300
|
);
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
// md() returns a shared cached array (module-level Markdown LRU) — copy before appending.
|
|
694
|
-
const bodyLines = [
|
|
695
|
-
...md(question, width),
|
|
696
|
-
...renderAnswerOptionLines(
|
|
697
|
-
uiTheme,
|
|
698
|
-
mdTheme,
|
|
699
|
-
dOptions,
|
|
700
|
-
dSelected,
|
|
701
|
-
dMulti,
|
|
702
|
-
dCustom,
|
|
703
|
-
dNote,
|
|
704
|
-
width,
|
|
705
|
-
contentWidth,
|
|
706
|
-
selectedIndicesFor(rawDetails.options, rawDetails.selectedOptions),
|
|
707
|
-
),
|
|
708
|
-
];
|
|
709
|
-
if (dTimedOut) {
|
|
710
|
-
// Distinguish auto-selection from a real user choice in the transcript.
|
|
711
|
-
bodyLines.push(uiTheme.fg("dim", "auto-selected after timeout — not a user choice"));
|
|
712
|
-
}
|
|
301
|
+
return framedToolCard(uiTheme, ({ contentWidth }) => {
|
|
302
|
+
const content = answers.flatMap((answer, index) => [
|
|
303
|
+
...wrapPrefixedLine(" ", " ", uiTheme.fg("text", oneLine(answer.question)), contentWidth),
|
|
304
|
+
...answerLines(uiTheme, shown[index]!, contentWidth, options.expanded),
|
|
305
|
+
]);
|
|
306
|
+
// Distinguish the deadline's submission from a real user choice in the transcript.
|
|
307
|
+
if (timedOut) content.push(...wrapPrefixedLine(" ", " ", uiTheme.fg("dim", TIMED_OUT_NOTE), contentWidth));
|
|
713
308
|
return {
|
|
714
309
|
header,
|
|
715
|
-
sections:
|
|
716
|
-
phase:
|
|
310
|
+
sections: content.length > 0 ? [{ content }] : [],
|
|
311
|
+
phase: timedOut ? "warning" : "success",
|
|
717
312
|
borderColor: "borderMuted",
|
|
718
313
|
};
|
|
719
314
|
});
|