@elicitkit/renderers 0.1.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.
@@ -0,0 +1,345 @@
1
+ /**
2
+ * `elicitation` tier — no custom UI; drive the host's *native* MCP
3
+ * elicitation primitive (form mode). Unlike the panel tiers this resolves
4
+ * inline against the host's elicitInput; the server is responsible for
5
+ * driving each step from `elicit` / `elicit_next`. Each Ask maps to one
6
+ * or more elicitInputs (`ask_code_diff` issues one confirm per hunk per
7
+ * SPEC §7.4); the bound is "one elicitInput per tool call" so the
8
+ * per-call MCP timeout is never the gating factor.
9
+ *
10
+ * action → status: accept → answered · decline → declined · cancel → deferred
11
+ */
12
+ /**
13
+ * Compile an Ask into the *sequence* of elicitInputs needed to fully
14
+ * elicit it on the elicitation tier. The list is almost always length-1;
15
+ * `ask_code_diff` is the v0.1 exception (one confirm per hunk so the
16
+ * user reviews each change separately — SPEC §7.4).
17
+ */
18
+ export function compileAskToInputs(ask) {
19
+ switch (ask.type) {
20
+ case "ask_text":
21
+ return [
22
+ {
23
+ message: msg(ask),
24
+ requestedSchema: {
25
+ type: "object",
26
+ properties: {
27
+ value: {
28
+ type: "string",
29
+ title: ask.prompt,
30
+ ...(ask.spec.maxLen ? { maxLength: ask.spec.maxLen } : {}),
31
+ },
32
+ },
33
+ required: ["value"],
34
+ },
35
+ },
36
+ ];
37
+ case "ask_confirm":
38
+ return [
39
+ {
40
+ message: ask.spec.consequence
41
+ ? `${msg(ask)}\n\n${ask.spec.consequence}`
42
+ : msg(ask),
43
+ requestedSchema: {
44
+ type: "object",
45
+ properties: {
46
+ value: { type: "boolean", title: ask.prompt },
47
+ },
48
+ required: ["value"],
49
+ },
50
+ },
51
+ ];
52
+ case "ask_select": {
53
+ const s = ask.spec;
54
+ const branches = s.options.map((o) => ({ const: o.id, title: o.label }));
55
+ const ids = s.options.map((o) => o.id);
56
+ const descLines = s.options
57
+ .filter((o) => !!o.description)
58
+ .map((o) => `- ${o.label}: ${o.description}`);
59
+ const message = descLines.length > 0
60
+ ? `${msg(ask)}\n\n${descLines.join("\n")}`
61
+ : msg(ask);
62
+ return [
63
+ {
64
+ message,
65
+ requestedSchema: {
66
+ type: "object",
67
+ properties: {
68
+ value: s.multiple
69
+ ? {
70
+ type: "array",
71
+ title: ask.prompt,
72
+ items: { anyOf: branches },
73
+ ...(s.min ? { minItems: s.min } : {}),
74
+ ...(s.max ? { maxItems: s.max } : {}),
75
+ }
76
+ : {
77
+ type: "string",
78
+ title: ask.prompt,
79
+ oneOf: branches,
80
+ default: ids[0],
81
+ },
82
+ },
83
+ required: ["value"],
84
+ },
85
+ },
86
+ ];
87
+ }
88
+ case "ask_code_diff": {
89
+ // One confirm per hunk, sequential (SPEC §7.4).
90
+ const inputs = [];
91
+ for (const file of ask.spec.files) {
92
+ for (const h of file.hunks) {
93
+ inputs.push({
94
+ message: `${ask.prompt}\n\n${file.path}` +
95
+ (h.header ? ` — ${h.header}` : ` — hunk ${h.id}`) +
96
+ `\n\n${h.after}`,
97
+ requestedSchema: {
98
+ type: "object",
99
+ properties: {
100
+ accept: {
101
+ type: "boolean",
102
+ title: `Accept this hunk (${h.id})?`,
103
+ default: true,
104
+ },
105
+ },
106
+ required: ["accept"],
107
+ },
108
+ });
109
+ }
110
+ }
111
+ return inputs;
112
+ }
113
+ case "ask_number": {
114
+ const s = ask.spec ?? {};
115
+ return [
116
+ {
117
+ message: msg(ask) + (s.unit ? `\n\n(unit: ${s.unit})` : ""),
118
+ requestedSchema: {
119
+ type: "object",
120
+ properties: {
121
+ value: {
122
+ type: s.integer ? "integer" : "number",
123
+ title: ask.prompt,
124
+ ...(typeof s.min === "number" ? { minimum: s.min } : {}),
125
+ ...(typeof s.max === "number" ? { maximum: s.max } : {}),
126
+ },
127
+ },
128
+ required: ["value"],
129
+ },
130
+ },
131
+ ];
132
+ }
133
+ case "ask_slider": {
134
+ const s = ask.spec;
135
+ return [
136
+ {
137
+ message: msg(ask) + `\n\n(${s.min}–${s.max}${s.unit ? " " + s.unit : ""})`,
138
+ requestedSchema: {
139
+ type: "object",
140
+ properties: {
141
+ value: { type: "number", title: ask.prompt, minimum: s.min, maximum: s.max },
142
+ },
143
+ required: ["value"],
144
+ },
145
+ },
146
+ ];
147
+ }
148
+ case "ask_rating": {
149
+ const max = ask.spec?.max ?? 5;
150
+ return [
151
+ {
152
+ message: msg(ask) + `\n\n(1 = lowest, ${max} = highest)`,
153
+ requestedSchema: {
154
+ type: "object",
155
+ properties: {
156
+ value: { type: "integer", title: ask.prompt, minimum: 1, maximum: max },
157
+ },
158
+ required: ["value"],
159
+ },
160
+ },
161
+ ];
162
+ }
163
+ case "ask_date": {
164
+ return [
165
+ {
166
+ message: msg(ask),
167
+ requestedSchema: {
168
+ type: "object",
169
+ properties: {
170
+ value: {
171
+ type: "string",
172
+ title: ask.prompt,
173
+ format: ask.spec?.time ? "date-time" : "date",
174
+ },
175
+ },
176
+ required: ["value"],
177
+ },
178
+ },
179
+ ];
180
+ }
181
+ case "ask_rank": {
182
+ const items = ask.spec.items;
183
+ const branches = items.map((i) => ({ const: i.id, title: i.label }));
184
+ return [
185
+ {
186
+ message: `${msg(ask)}\n\nRank by listing every option in order, best first:\n` +
187
+ items.map((i) => `- ${i.id}: ${i.label}`).join("\n"),
188
+ requestedSchema: {
189
+ type: "object",
190
+ properties: {
191
+ value: {
192
+ type: "array",
193
+ title: ask.prompt,
194
+ items: { anyOf: branches },
195
+ minItems: items.length,
196
+ maxItems: items.length,
197
+ },
198
+ },
199
+ required: ["value"],
200
+ },
201
+ },
202
+ ];
203
+ }
204
+ case "ask_color": {
205
+ const pal = ask.spec?.palette ?? [];
206
+ const fixed = pal.length > 0 && ask.spec?.allowCustom !== true;
207
+ const branches = pal.map((c) => ({ const: c, title: c }));
208
+ return [
209
+ {
210
+ message: fixed
211
+ ? msg(ask)
212
+ : `${msg(ask)}\n\nEnter a CSS color (e.g. #1d4ed8)` +
213
+ (pal.length ? `\nSuggested: ${pal.join(", ")}` : ""),
214
+ requestedSchema: {
215
+ type: "object",
216
+ properties: {
217
+ value: fixed
218
+ ? { type: "string", title: ask.prompt, oneOf: branches }
219
+ : { type: "string", title: ask.prompt },
220
+ },
221
+ required: ["value"],
222
+ },
223
+ },
224
+ ];
225
+ }
226
+ default: {
227
+ const a = ask;
228
+ return [
229
+ {
230
+ message: msg(a),
231
+ requestedSchema: {
232
+ type: "object",
233
+ properties: { value: { type: "string", title: a.prompt } },
234
+ required: ["value"],
235
+ },
236
+ },
237
+ ];
238
+ }
239
+ }
240
+ }
241
+ /**
242
+ * Assemble an Answer from the collected ElicitResults for a single Ask.
243
+ * `responses.length === compileAskToInputs(ask).length`. For asks with a
244
+ * single elicitInput this is a one-shot decode; `ask_code_diff` folds N
245
+ * per-hunk confirms into one `{ accepted, rejected }` value.
246
+ *
247
+ * The decline-on-first-non-accept rule (SPEC §7.4) is implemented here:
248
+ * the server passes through every collected response, including the
249
+ * non-accepts, and the decoder turns the first non-accept into the
250
+ * ask's final status.
251
+ */
252
+ export function decodeAskAnswer(ask, responses) {
253
+ // Common short-circuit: a non-accept on the first elicitInput is the
254
+ // ask's outcome for everything except ask_code_diff (which we handle
255
+ // hunk-by-hunk below).
256
+ if (ask.type !== "ask_code_diff") {
257
+ const r = responses[0];
258
+ if (!r)
259
+ return answer(ask, "deferred");
260
+ return answer(ask, statusFor(r.action), readValue(ask, r));
261
+ }
262
+ // ask_code_diff: one confirm per hunk. A non-accept on any hunk ends
263
+ // the ask with that hunk's outcome; previously-decided hunks are kept.
264
+ const accepted = [];
265
+ const rejected = [];
266
+ let i = 0;
267
+ for (const file of ask.spec.files) {
268
+ for (const h of file.hunks) {
269
+ const r = responses[i++];
270
+ if (!r)
271
+ return answer(ask, "deferred", { accepted, rejected });
272
+ if (r.action !== "accept") {
273
+ return answer(ask, statusFor(r.action));
274
+ }
275
+ (r.content?.accept === false ? rejected : accepted).push(h.id);
276
+ }
277
+ }
278
+ return answer(ask, "answered", { accepted, rejected });
279
+ }
280
+ /** How many elicitInputs an ask compiles to on the elicitation tier. */
281
+ export function askInputCount(ask) {
282
+ if (ask.type === "ask_code_diff") {
283
+ return ask.spec.files.reduce((n, f) => n + (f.hunks?.length ?? 0), 0);
284
+ }
285
+ return 1;
286
+ }
287
+ /**
288
+ * The legacy whole-set runner — kept as a thin wrapper over the new
289
+ * per-ask compile + decode primitives, used by tests and adapters that
290
+ * want a one-call "drive the elicitation tier end-to-end" path.
291
+ */
292
+ export async function runElicitation(set, elicit) {
293
+ const out = [];
294
+ for (const ask of set.asks) {
295
+ const inputs = compileAskToInputs(ask);
296
+ const responses = [];
297
+ for (const params of inputs) {
298
+ const r = await elicit(params);
299
+ responses.push(r);
300
+ // Mirror the per-hunk early-exit for ask_code_diff: stop on the
301
+ // first non-accept so we don't keep asking after the user
302
+ // declines (SPEC §7.4). For other asks there's only one input
303
+ // anyway, so the early-exit is a no-op.
304
+ if (r.action !== "accept" && ask.type === "ask_code_diff")
305
+ break;
306
+ }
307
+ out.push(decodeAskAnswer(ask, responses));
308
+ }
309
+ return out;
310
+ }
311
+ function statusFor(action) {
312
+ return action === "accept"
313
+ ? "answered"
314
+ : action === "decline"
315
+ ? "declined"
316
+ : "deferred";
317
+ }
318
+ function msg(ask) {
319
+ return ask.help ? `${ask.prompt}\n\n${ask.help}` : ask.prompt;
320
+ }
321
+ function answer(ask, status, value) {
322
+ return {
323
+ id: ask.id,
324
+ type: ask.type,
325
+ status,
326
+ ...(status === "answered" ? { value } : {}),
327
+ meta: { tier: "elicitation", specVersion: ask.meta?.specVersion },
328
+ };
329
+ }
330
+ /** Read the `value` (or `accept`, for ask_code_diff) field from the
331
+ * elicitInput response, normalising ask_rank's degraded
332
+ * comma-separated-string fallback into the canonical id[] permutation. */
333
+ function readValue(ask, r) {
334
+ if (ask.type === "ask_rank") {
335
+ const raw = r.content?.value;
336
+ return Array.isArray(raw)
337
+ ? raw.map((x) => String(x))
338
+ : String(raw ?? "")
339
+ .split(/[,\s]+/)
340
+ .map((x) => x.trim())
341
+ .filter(Boolean);
342
+ }
343
+ return r.content?.value;
344
+ }
345
+ //# sourceMappingURL=elicitation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elicitation.js","sourceRoot":"","sources":["../src/elicitation.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;GAUG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAQ;IACzC,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC;QACjB,KAAK,UAAU;YACb,OAAO;gBACL;oBACE,OAAO,EAAE,GAAG,CAAC,GAAG,CAAC;oBACjB,eAAe,EAAE;wBACf,IAAI,EAAE,QAAQ;wBACd,UAAU,EAAE;4BACV,KAAK,EAAE;gCACL,IAAI,EAAE,QAAQ;gCACd,KAAK,EAAE,GAAG,CAAC,MAAM;gCACjB,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;6BAC3D;yBACF;wBACD,QAAQ,EAAE,CAAC,OAAO,CAAC;qBACpB;iBACF;aACF,CAAC;QAEJ,KAAK,aAAa;YAChB,OAAO;gBACL;oBACE,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,WAAW;wBAC3B,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE;wBAC1C,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;oBACZ,eAAe,EAAE;wBACf,IAAI,EAAE,QAAQ;wBACd,UAAU,EAAE;4BACV,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE;yBAC9C;wBACD,QAAQ,EAAE,CAAC,OAAO,CAAC;qBACpB;iBACF;aACF,CAAC;QAEJ,KAAK,YAAY,CAAC,CAAC,CAAC;YAClB,MA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d,MAAM;QACN,GAAG,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3C,IAAI,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,CAAC,IAAI,EAAE,WAAW,EAAE;KAClE,CAAC;AACJ,CAAC;AAED;;2EAE2E;AAC3E,SAAS,SAAS,CAAC,GAAQ,EAAE,CAAe;IAC1C,IAAI,GAAG,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QAC5B,MAAM,GAAG,GAAG,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC;QAC7B,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;YACvB,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAC3B,CAAC,CAAC,MAAM,CAAC,GAAG,IAAI,EAAE,CAAC;iBACd,KAAK,CAAC,QAAQ,CAAC;iBACf,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;iBACpB,MAAM,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { renderApps } from "./apps.js";
2
+ export { renderUrl } from "./url.js";
3
+ export { renderTui } from "./tui.js";
4
+ export { runElicitation, compileAskToInputs, decodeAskAnswer, askInputCount, } from "./elicitation.js";
5
+ export { buildPanelHtml, SAFE_COLOR_PATTERN, SAFE_COLOR_RE } from "./panel.js";
6
+ export type { PanelOptions } from "./panel.js";
7
+ export type { RenderedPanel, UiBlock, ElicitFn, ElicitParams, ElicitResult, ElicitFormProperty, } from "./contract.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC/E,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,YAAY,EACV,aAAa,EACb,OAAO,EACP,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,kBAAkB,GACnB,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export { renderApps } from "./apps.js";
2
+ export { renderUrl } from "./url.js";
3
+ export { renderTui } from "./tui.js";
4
+ export { runElicitation, compileAskToInputs, decodeAskAnswer, askInputCount, } from "./elicitation.js";
5
+ export { buildPanelHtml, SAFE_COLOR_PATTERN, SAFE_COLOR_RE } from "./panel.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,36 @@
1
+ import type { AskSet, Tier } from "@elicitkit/core";
2
+ /**
3
+ * The ONE canonical safe-color grammar — identical to the JSON Schema
4
+ * `safeColor` pattern, the conformance corpus, and SPEC §7.y. Accepts
5
+ * `#hex` (3/4/6/8), a CSS named/keyword color, and the common functional
6
+ * notations with a safe inner charset; it structurally cannot express
7
+ * `url(`, `var(`, `image-set(`, `element(`, gradients, quotes, `;`, or a
8
+ * nested `(` — i.e. no CSS value-injection / exfiltration / breakout. Held
9
+ * as a string so it round-trips through `jsonForScript` into the panel
10
+ * script with layer-proof escaping (regex literals in a template string
11
+ * mangle backslashes; a JSON string + `new RegExp` does not).
12
+ */
13
+ export declare const SAFE_COLOR_PATTERN = "^(?:#[0-9a-fA-F]{3,8}|[a-zA-Z]+|(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch|color)\\([0-9a-zA-Z.,%/ +\\-]*\\))$";
14
+ export declare const SAFE_COLOR_RE: RegExp;
15
+ /**
16
+ * The shared interactive panel HTML used by the `apps` and `url` tiers (one
17
+ * source of truth for rich rendering). The DOM is built client-side from
18
+ * embedded JSON via textContent, so ask content can never inject markup.
19
+ * Icons are a curated, static inline-SVG set keyed by name — never sourced
20
+ * from ask content (unknown names fall back to textContent). Self-contained,
21
+ * dependency-free, CSP-safe (inline CSS/JS only).
22
+ *
23
+ * Display is progressively enhanced and fully backward-compatible:
24
+ * - `set.meta.layout`: "auto" (default) | "single" | "grid"
25
+ * - `ask.meta.span`: "half" | "full" (overrides the auto heuristic)
26
+ * - `ask.spec.display` (ask_select): "list" | "cards" | "segmented" | "grid"
27
+ * - `option.icon` / `option.color`: optional per-option adornments
28
+ * Older renderers ignore all of the above and still render correctly.
29
+ */
30
+ export interface PanelOptions {
31
+ /** If set, the panel POSTs `{token,answers}` here (hosted url tier) in
32
+ * addition to the mcp-ui postMessage + copy-paste fallbacks. */
33
+ submitUrl?: string;
34
+ }
35
+ export declare function buildPanelHtml(set: AskSet, token: string, tier: Tier, opts?: PanelOptions): string;
36
+ //# sourceMappingURL=panel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panel.d.ts","sourceRoot":"","sources":["../src/panel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAGpD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,qHACqF,CAAC;AACrH,eAAO,MAAM,aAAa,QAAiC,CAAC;AAE5D;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,YAAY;IAC3B;qEACiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,IAAI,EACV,IAAI,GAAE,YAAiB,GACtB,MAAM,CAklBR"}