@seed-ship/mcp-ui-solid 5.1.0 → 5.3.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 +97 -0
- package/README.md +64 -13
- package/dist/components/ElicitationForm.cjs +51 -0
- package/dist/components/ElicitationForm.cjs.map +1 -0
- package/dist/components/ElicitationForm.d.ts +68 -0
- package/dist/components/ElicitationForm.d.ts.map +1 -0
- package/dist/components/ElicitationForm.js +51 -0
- package/dist/components/ElicitationForm.js.map +1 -0
- package/dist/components/FeedbackInline.cjs +57 -0
- package/dist/components/FeedbackInline.cjs.map +1 -0
- package/dist/components/FeedbackInline.d.ts +71 -0
- package/dist/components/FeedbackInline.d.ts.map +1 -0
- package/dist/components/FeedbackInline.js +57 -0
- package/dist/components/FeedbackInline.js.map +1 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components.cjs +2 -0
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +2 -0
- package/dist/components.d.ts +2 -0
- package/dist/components.js +2 -0
- package/dist/components.js.map +1 -1
- package/dist/index.cjs +17 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -2
- package/dist/index.js.map +1 -1
- package/dist/services/chat-bus.cjs +71 -0
- package/dist/services/chat-bus.cjs.map +1 -1
- package/dist/services/chat-bus.d.ts +31 -1
- package/dist/services/chat-bus.d.ts.map +1 -1
- package/dist/services/chat-bus.js +71 -0
- package/dist/services/chat-bus.js.map +1 -1
- package/dist/services/chat-prompt-controller.cjs +83 -0
- package/dist/services/chat-prompt-controller.cjs.map +1 -0
- package/dist/services/chat-prompt-controller.d.ts +93 -0
- package/dist/services/chat-prompt-controller.d.ts.map +1 -0
- package/dist/services/chat-prompt-controller.js +83 -0
- package/dist/services/chat-prompt-controller.js.map +1 -0
- package/dist/stores/scratchpad-store.cjs +105 -77
- package/dist/stores/scratchpad-store.cjs.map +1 -1
- package/dist/stores/scratchpad-store.d.ts +88 -19
- package/dist/stores/scratchpad-store.d.ts.map +1 -1
- package/dist/stores/scratchpad-store.js +105 -77
- package/dist/stores/scratchpad-store.js.map +1 -1
- package/dist/stores/server-capabilities-store.cjs +61 -0
- package/dist/stores/server-capabilities-store.cjs.map +1 -0
- package/dist/stores/server-capabilities-store.d.ts +172 -0
- package/dist/stores/server-capabilities-store.d.ts.map +1 -0
- package/dist/stores/server-capabilities-store.js +61 -0
- package/dist/stores/server-capabilities-store.js.map +1 -0
- package/dist/types/chat-bus.d.ts +39 -0
- package/dist/types/chat-bus.d.ts.map +1 -1
- package/docs/recipes/elicitation-pseudo-spec-adapter.md +171 -0
- package/docs/recipes/feedback-inline-wiring.md +142 -0
- package/package.json +1 -1
- package/src/components/ElicitationForm.test.tsx +197 -0
- package/src/components/ElicitationForm.tsx +126 -0
- package/src/components/FeedbackInline.test.tsx +117 -0
- package/src/components/FeedbackInline.tsx +143 -0
- package/src/components/index.ts +4 -0
- package/src/index.ts +39 -1
- package/src/services/chat-bus.test.ts +154 -2
- package/src/services/chat-bus.ts +115 -0
- package/src/services/chat-prompt-controller.test.ts +144 -0
- package/src/services/chat-prompt-controller.ts +214 -0
- package/src/stores/scratchpad-store.test.tsx +140 -0
- package/src/stores/scratchpad-store.tsx +244 -0
- package/src/stores/server-capabilities-store.test.tsx +206 -0
- package/src/stores/server-capabilities-store.tsx +215 -0
- package/src/types/chat-bus.ts +40 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/stores/scratchpad-store.ts +0 -126
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,103 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [5.3.0] - 2026-04-22
|
|
9
|
+
|
|
10
|
+
### Added — A. `<ElicitationForm>` schema-driven renderer
|
|
11
|
+
|
|
12
|
+
- **`<ElicitationForm event onAccept onCancel? onDecline? dismissLabel?>`** — thin wrapper over `<ChatPrompt>` + `elicitationToPromptConfig()` that accepts a spec-shaped `ElicitationEvent` (MCP 2025-06-18) and exposes a spec-shaped `onAccept(content)` callback whose payload is ready to send back as the `accept` outcome of an `elicitation/create` reply.
|
|
13
|
+
- Inverse mapping owned here : single boolean → `{ propName: true }`, single enum → `{ propName: enumValue }` (numeric coerced when schema is `integer`/`number`), multi-property form → values map passed through unchanged.
|
|
14
|
+
- Forward mapping (spec → ChatPromptConfig) reuses the existing `elicitationToPromptConfig` helper from v5.2.0 — same rules, same tests, no duplication.
|
|
15
|
+
- `dismissLabel="Decline"` + `onDecline` lets you surface an explicit decline action distinct from passive cancel.
|
|
16
|
+
- Type export : `ElicitationFormProps`.
|
|
17
|
+
|
|
18
|
+
### Added — B. `useServerCapabilities()` hook + store
|
|
19
|
+
|
|
20
|
+
- **`createServerCapabilitiesStore()`** factory + module singleton + **`<ServerCapabilitiesProvider>`** for multi-instance scoping (mirrors the v5.2.0 `scratchpad-store` pattern).
|
|
21
|
+
- **`setServerCapabilities(info)`** — push the parsed MCP `initialize` response into the singleton from your transport adapter.
|
|
22
|
+
- **`useServerCapabilities()`** — reactive accessor returning `{ info, capabilities, serverInfo, protocolVersion, hasCapability }`. Components can gate rendering on advertised capabilities (e.g. `<Show when={hasCapability('tools')}>`).
|
|
23
|
+
- Type exports : `ServerCapabilities`, `ServerInitializeInfo`, `ServerCapabilitiesStoreHandle`.
|
|
24
|
+
- Note : `elicitation` is a **client** capability per MCP spec 2025-06-18 — this store tracks **server** capabilities only. Gate `<ElicitationForm>` on your own client-side state, not on this store.
|
|
25
|
+
|
|
26
|
+
### Added — C. Recipe : pseudo-elicit → spec adapter
|
|
27
|
+
|
|
28
|
+
- New doc `docs/recipes/elicitation-pseudo-spec-adapter.md` — drop-in TypeScript adapter for consumer apps talking to MCP servers that ship a legacy "pseudo-elicit" payload inline with `tools/call` results (e.g. deposium_MCPs as of 2026-04). Adapter lives in the consumer app — mcp-ui stays vendor-agnostic by design.
|
|
29
|
+
|
|
30
|
+
### Added — D. Recipe : `<FeedbackInline>` wiring
|
|
31
|
+
|
|
32
|
+
- New doc `docs/recipes/feedback-inline-wiring.md` — concrete pattern for wiring `<FeedbackInline>.onSubmit` to a feedback HTTP endpoint, with the Deposium `POST /api/feedback` shape as a worked example. Mapping `'positive' | 'negative'` to the endpoint is direct.
|
|
33
|
+
|
|
34
|
+
### Tests
|
|
35
|
+
|
|
36
|
+
- New file : `components/ElicitationForm.test.tsx` (7 tests) — covers boolean/enum/numeric/multi-property accept paths, X-dismiss, confirm-cancel button, and `onDecline` precedence.
|
|
37
|
+
- New file : `stores/server-capabilities-store.test.tsx` (10 tests) — factory isolation, derived accessors, singleton fallback, provider scoping, reactive update propagation.
|
|
38
|
+
|
|
39
|
+
### Non-breaking
|
|
40
|
+
|
|
41
|
+
- All additions are optional and additive. v5.2.0 consumers upgrade with zero code changes.
|
|
42
|
+
|
|
43
|
+
### Aligned with deposium_MCPs
|
|
44
|
+
|
|
45
|
+
- v5.3.0 closes the items in mcp-ui's court per the `mcp-ui ↔ deposium_MCPs alignment 2026-04-22` doc :
|
|
46
|
+
- Plan B B.3.5 unblock acknowledged (HTTP transport now bidirectional via SDK `StreamableHTTPServerTransport`).
|
|
47
|
+
- Pseudo-elicit confirmed as stable legacy ; consumer-side adapter pattern now documented.
|
|
48
|
+
- Feedback endpoint `POST /api/feedback` wire shape documented.
|
|
49
|
+
- `<ElicitationForm>` and `useServerCapabilities()` deferred items shipped.
|
|
50
|
+
|
|
51
|
+
## [5.2.0] - 2026-04-22
|
|
52
|
+
|
|
53
|
+
### Added — D1 multi-instance scratchpad store
|
|
54
|
+
|
|
55
|
+
- **`createScratchpadStore()`** factory — returns an isolated `ScratchpadStoreHandle` (`dispatch`, `state`, `pinned`, `close`). Closes the v4.x known limitation that two `ScratchpadPanel` instances shared state.
|
|
56
|
+
- **`ScratchpadStoreProvider`** + **`ScratchpadStoreContext`** — scope a store to a SolidJS subtree. Accepts an optional `store` prop; creates one internally otherwise.
|
|
57
|
+
- **`useScratchpadState()` is now context-aware** — reads the provider's store when mounted inside one, falls back to the module singleton otherwise. Zero-breaking for v4.x single-instance consumers.
|
|
58
|
+
- Type export : `ScratchpadStoreHandle`.
|
|
59
|
+
|
|
60
|
+
### Added — D2 ChatPrompt controller primitive
|
|
61
|
+
|
|
62
|
+
- **`createChatPromptController()`** — one primitive owning resolver closure + `AbortSignal` wiring + re-entrance policy. Consumers go from ~20 LOC of hand-threaded resolver to `bus.commands.handle('showChatPrompt', ctrl.handle)` + `<Show when={ctrl.activePrompt()}>{cfg => <ChatPrompt ... />}</Show>`.
|
|
63
|
+
- **`PromptReplacedError`** — exported error class thrown when a new `showChatPrompt` arrives before the previous resolves. Use `instanceof` or `err.name === 'PromptReplacedError'`.
|
|
64
|
+
- **`AbortSignal` honoured** — already-aborted signals reject synchronously with `DOMException('Prompt aborted', 'AbortError')` without showing UI. In-flight aborts reject + clear `activePrompt`.
|
|
65
|
+
- **`ctrl.abort(reason?)`** — programmatic cancellation (route change, modal close, ...).
|
|
66
|
+
- Type export : `ChatPromptController`.
|
|
67
|
+
|
|
68
|
+
### Added — D5 per-message inline feedback
|
|
69
|
+
|
|
70
|
+
- **`<FeedbackInline>`** — per-message thumbs up/down, non-blocking, many can coexist. Complements `ChatPrompt` (modal one-at-a-time) and `ScratchpadPanel` feedback section (structured, panel-side). Optimistic UI, best-effort persistence via consumer-owned `onSubmit(rating, context)`.
|
|
71
|
+
- Type exports : `FeedbackInlineProps`, `FeedbackInlineContext`.
|
|
72
|
+
|
|
73
|
+
### Added — D6 MCP elicitation handling
|
|
74
|
+
|
|
75
|
+
- **`ChatEvents.onElicitation`** — new event for MCP `elicitation/create` requests (spec 2025-06-18). Symmetric to `onClarificationNeeded`.
|
|
76
|
+
- **Types** : `ElicitationEvent`, `ElicitationRequestedSchema`, `ElicitationPropertySchema`.
|
|
77
|
+
- **`elicitationToPromptConfig(event)`** — converts an MCP elicitation payload to a `ChatPromptConfig`. Smart mapping :
|
|
78
|
+
- Single `boolean` property → `type: 'confirm'`
|
|
79
|
+
- Single property with `enum` of ≤4 values → `type: 'choice'`
|
|
80
|
+
- Anything else → `type: 'form'` with per-property field-type inference
|
|
81
|
+
- Inferences : `string` → `text`, `string/format:email` → `email`, `string/format:date|date-time` → `date`, `number|integer` → `number`, `boolean` → `checkbox`, any `enum` → `select`.
|
|
82
|
+
|
|
83
|
+
### Tests
|
|
84
|
+
|
|
85
|
+
- **467 passing** (+29 vs v5.1.0).
|
|
86
|
+
- New files : `stores/scratchpad-store.test.tsx` (7), `services/chat-prompt-controller.test.ts` (7), `components/FeedbackInline.test.tsx` (7).
|
|
87
|
+
- Extended `services/chat-bus.test.ts` with 8 new elicitation tests.
|
|
88
|
+
|
|
89
|
+
### Non-breaking
|
|
90
|
+
|
|
91
|
+
- All additions are optional.
|
|
92
|
+
- `scratchpad-store.ts` refactored to extract a factory; module singleton remains as default so `dispatchScratchpad` / `useScratchpadState` keep working identically.
|
|
93
|
+
|
|
94
|
+
### Design rationale
|
|
95
|
+
|
|
96
|
+
Full scope doc lives in the Deposium project : `docs/2026/r&d/mcpui-v5.2.0-scope.md`. It regroups v5.1.0 consensus carry-forward (D1, D2) with two new items arising from the MCP SDK audit 2026-04-14 (D5 feedback inline, D6 elicitation helper).
|
|
97
|
+
|
|
98
|
+
### Deferred
|
|
99
|
+
|
|
100
|
+
- `<ElicitationForm>` schema-driven form renderer — waiting for real Claude Desktop payloads.
|
|
101
|
+
- `createChatPromptController` FIFO queue mode — YAGNI until a concrete need.
|
|
102
|
+
- `useServerCapabilities()` hook — needs a second consumer + Phase B protocol align on `capabilities.extensions`.
|
|
103
|
+
- OAuth client-side docs — add as a doc patch when Deposium moves to OAuth Resource Server.
|
|
104
|
+
|
|
8
105
|
## [5.1.0] - 2026-04-14
|
|
9
106
|
|
|
10
107
|
### Added — D4 custom choice rendering
|
package/README.md
CHANGED
|
@@ -5,13 +5,21 @@ SolidJS components + chat toolkit for MCP-generated UI. Part of the [MCP UI ecos
|
|
|
5
5
|
[](https://www.npmjs.com/package/@seed-ship/mcp-ui-solid)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
|
|
8
|
+
## What's New in v5.2.0 (`mcp-ui-solid` only)
|
|
9
|
+
|
|
10
|
+
- **`createChatPromptController()`** primitive — closes the v5.1.0 boilerplate. Owns resolver closure + `AbortSignal` wiring + re-entrance. Consumers write `bus.commands.handle('showChatPrompt', ctrl.handle)` + `<Show when={ctrl.activePrompt()}>{cfg => <ChatPrompt ... />}</Show>`. `PromptReplacedError` exported for `instanceof` checks.
|
|
11
|
+
- **`createScratchpadStore()`** factory + `ScratchpadStoreProvider` + `ScratchpadStoreContext` — isolated scratchpad state per subtree. `useScratchpadState()` now context-aware with module-singleton fallback (zero-breaking for v4.x).
|
|
12
|
+
- **`<FeedbackInline>`** — per-message thumbs up/down, non-blocking. Complements `ChatPrompt` (modal) and `ScratchpadPanel` feedback section (panel-side).
|
|
13
|
+
- **`onElicitation` event + `elicitationToPromptConfig()` helper** — MCP `elicitation/create` (spec 2025-06-18) mapped to `ChatPromptConfig`. Smart mapping : single boolean → confirm, single enum ≤4 → choice, everything else → form with per-property field inference.
|
|
14
|
+
- **29 new tests** (438 → 467). Scope doc : `docs/2026/r&d/mcpui-v5.2.0-scope.md` in the Deposium project.
|
|
15
|
+
|
|
8
16
|
## What's New in v5.1.0 (`mcp-ui-solid` only)
|
|
9
17
|
|
|
10
18
|
- **`optionRenderer` render prop** on `ChoicePromptConfig` — take full control of option bodies (confidence badges, rich layouts). mcp-ui still wraps the returned JSX in its own `<button>` with `onClick` + focus handling. See `optionRenderer (v5.1.0)` tests in `ChatPrompt.test.tsx` for usage.
|
|
11
19
|
- **Generic `ChoicePromptConfig<TMeta>`** — `ChoiceOption<TMeta>` flows through so your renderer closures get strongly-typed `option.metadata` without casting. Default `TMeta = Record<string, unknown>` keeps the non-generic shape valid for existing callers.
|
|
12
20
|
- **`buttonClass?` + `containerClass?`** escape hatches on `ChoicePromptConfig` — Tailwind class extensions that append to mcp-ui's defaults for light cosmetic tweaks without writing a full renderer.
|
|
13
21
|
- **`type="button"` on option buttons** — prevents accidental form submission when a `ChatPrompt` is nested inside an HTML `<form>`.
|
|
14
|
-
- **`ChatPrompt` + `showChatPrompt` JSDoc rewritten** — explicitly states the consumer contract : no default handler, Promise wiring is host-side, `AbortSignal` rejects with `DOMException('AbortError')` per Web Platform convention, re-entrance policy is host-enforced.
|
|
22
|
+
- **`ChatPrompt` + `showChatPrompt` JSDoc rewritten** — explicitly states the consumer contract : no default handler, Promise wiring is host-side, `AbortSignal` rejects with `DOMException('AbortError')` per Web Platform convention, re-entrance policy is host-enforced. Now available as a one-call primitive via `createChatPromptController()` in v5.2.0.
|
|
15
23
|
|
|
16
24
|
## What's New in v5.0.0
|
|
17
25
|
|
|
@@ -417,18 +425,60 @@ Every `ChatPrompt` exchange ends in one of three outcomes:
|
|
|
417
425
|
| Dismissed | Click the X icon, click Cancel (confirm type) | `true` | resolves |
|
|
418
426
|
| Aborted | Host app rejects the Promise via `AbortSignal` | *(n/a — never resolves)* | rejects with `DOMException('AbortError')` |
|
|
419
427
|
|
|
420
|
-
> **v5.
|
|
421
|
-
>
|
|
422
|
-
>
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
428
|
+
> **v5.2.0** — use `createChatPromptController()` (below). The manual pattern
|
|
429
|
+
> documented after it is kept for context and for consumers who prefer full
|
|
430
|
+
> control over the resolver lifecycle.
|
|
431
|
+
|
|
432
|
+
#### Recommended — `createChatPromptController()` (v5.2.0)
|
|
433
|
+
|
|
434
|
+
```tsx
|
|
435
|
+
import { Show } from 'solid-js'
|
|
436
|
+
import {
|
|
437
|
+
ChatPrompt,
|
|
438
|
+
useChatBus,
|
|
439
|
+
createChatPromptController,
|
|
440
|
+
PromptReplacedError,
|
|
441
|
+
} from '@seed-ship/mcp-ui-solid'
|
|
442
|
+
|
|
443
|
+
function HitlHost() {
|
|
444
|
+
const bus = useChatBus()
|
|
445
|
+
const ctrl = createChatPromptController()
|
|
446
|
+
bus.commands.handle('showChatPrompt', ctrl.handle)
|
|
447
|
+
|
|
448
|
+
return (
|
|
449
|
+
<Show when={ctrl.activePrompt()}>
|
|
450
|
+
{(cfg) => (
|
|
451
|
+
<ChatPrompt
|
|
452
|
+
config={cfg()}
|
|
453
|
+
onSubmit={ctrl.resolveActive}
|
|
454
|
+
onDismiss={ctrl.dismissActive}
|
|
455
|
+
/>
|
|
456
|
+
)}
|
|
457
|
+
</Show>
|
|
458
|
+
)
|
|
459
|
+
}
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
Caller-side, re-entrance and abort are standard :
|
|
463
|
+
|
|
464
|
+
```ts
|
|
465
|
+
try {
|
|
466
|
+
const response = await bus.commands.exec('showChatPrompt', config, ac.signal)
|
|
467
|
+
// ...
|
|
468
|
+
} catch (err) {
|
|
469
|
+
if (err instanceof PromptReplacedError) return // superseded by a newer prompt
|
|
470
|
+
if (err instanceof Error && err.name === 'AbortError') return // navigation killed it
|
|
471
|
+
throw err
|
|
472
|
+
}
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
`ctrl.abort(reason?)` is also available for programmatic cancellation
|
|
476
|
+
(modal close, route change, ...).
|
|
426
477
|
|
|
427
|
-
####
|
|
478
|
+
#### Manual wiring (v5.1.0 reference pattern)
|
|
428
479
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
prompt) and `AbortSignal` (rejects with a Web-Platform `DOMException`):
|
|
480
|
+
Equivalent to the controller above — useful if you want full control over
|
|
481
|
+
the resolver closure, or if you're maintaining a v5.1.0 codebase :
|
|
432
482
|
|
|
433
483
|
```tsx
|
|
434
484
|
import { createSignal } from 'solid-js'
|
|
@@ -513,8 +563,9 @@ try {
|
|
|
513
563
|
}
|
|
514
564
|
```
|
|
515
565
|
|
|
516
|
-
|
|
517
|
-
|
|
566
|
+
v5.2.0 collapses this to a single `createChatPromptController()` call — see
|
|
567
|
+
above. Prefer the controller unless you have a reason to manage the
|
|
568
|
+
lifecycle yourself.
|
|
518
569
|
|
|
519
570
|
### correlationId — host-propagated (v4.3.9)
|
|
520
571
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const web = require("solid-js/web");
|
|
4
|
+
const ChatPrompt = require("./ChatPrompt.cjs");
|
|
5
|
+
const chatBus = require("../services/chat-bus.cjs");
|
|
6
|
+
const ElicitationForm = (props) => {
|
|
7
|
+
const config = () => chatBus.elicitationToPromptConfig(props.event);
|
|
8
|
+
const handleSubmit = (response) => {
|
|
9
|
+
var _a;
|
|
10
|
+
if (response.dismissed) {
|
|
11
|
+
(_a = props.onDecline ?? props.onCancel) == null ? void 0 : _a();
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
props.onAccept(extractContent(response, props.event));
|
|
15
|
+
};
|
|
16
|
+
return web.createComponent(ChatPrompt.ChatPrompt, {
|
|
17
|
+
get config() {
|
|
18
|
+
return config();
|
|
19
|
+
},
|
|
20
|
+
get dismissLabel() {
|
|
21
|
+
return props.dismissLabel;
|
|
22
|
+
},
|
|
23
|
+
onSubmit: handleSubmit
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
function extractContent(response, event) {
|
|
27
|
+
if (typeof response.value !== "string") {
|
|
28
|
+
return response.value;
|
|
29
|
+
}
|
|
30
|
+
const propEntries = Object.entries(event.requestedSchema.properties);
|
|
31
|
+
if (propEntries.length === 1) {
|
|
32
|
+
const [name, schema] = propEntries[0];
|
|
33
|
+
return {
|
|
34
|
+
[name]: coerceScalar(response.value, schema)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
console.warn("[MCP-UI] ElicitationForm: received string value for multi-property schema. Falling back to _value.");
|
|
38
|
+
return {
|
|
39
|
+
_value: response.value
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function coerceScalar(value, schema) {
|
|
43
|
+
if (schema.type === "boolean") return true;
|
|
44
|
+
if (schema.type === "number" || schema.type === "integer") {
|
|
45
|
+
const n = Number(value);
|
|
46
|
+
return Number.isFinite(n) ? n : value;
|
|
47
|
+
}
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
exports.ElicitationForm = ElicitationForm;
|
|
51
|
+
//# sourceMappingURL=ElicitationForm.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElicitationForm.cjs","sources":["../../src/components/ElicitationForm.tsx"],"sourcesContent":["/**\n * ElicitationForm — schema-driven renderer for MCP `elicitation/create` requests\n *\n * @experimental\n * @since v5.3.0\n *\n * Thin wrapper over `<ChatPrompt>` + `elicitationToPromptConfig()` that\n * accepts a spec-shaped `ElicitationEvent` (MCP 2025-06-18) and exposes a\n * spec-shaped `onAccept(content)` callback whose payload is ready to send\n * back as the `accept` outcome of an `elicitation/create` reply.\n *\n * The mapping (boolean → confirm, single enum ≤4 → choice, else → form) is\n * delegated to the `elicitationToPromptConfig` helper — same rules, same\n * tests. This component owns the inverse mapping : extracting a spec-shaped\n * `Record<string, unknown>` from the `ChatPromptResponse`.\n *\n * ## Outcome semantics (per MCP spec 2025-06-18)\n *\n * | User action | Callback fired | Payload |\n * |---------------------------------------|--------------------|----------------------------------|\n * | Submit form / pick choice / confirm | `onAccept(content)`| `{ [propName]: value, ... }` |\n * | X icon / Cancel button | `onCancel()` *or* `onDecline()` if provided | none |\n *\n * mcp-ui's `<ChatPrompt>` does not natively distinguish \"decline\" (explicit\n * refusal) from \"cancel\" (passive close). To surface a decline action,\n * pass `dismissLabel=\"Decline\"` and route the callback via `onDecline`.\n *\n * @example\n * ```tsx\n * bus.events.on('onElicitation', ({ elicitation }) => {\n * render(() => (\n * <ElicitationForm\n * event={elicitation}\n * onAccept={(content) => sendElicitationReply({ action: 'accept', content })}\n * onCancel={() => sendElicitationReply({ action: 'cancel' })}\n * />\n * ), mountPoint)\n * })\n * ```\n */\n\nimport { Component } from 'solid-js'\nimport { ChatPrompt } from './ChatPrompt'\nimport { elicitationToPromptConfig } from '../services/chat-bus'\nimport type {\n ChatPromptResponse,\n ElicitationEvent,\n ElicitationPropertySchema,\n} from '../types/chat-bus'\n\nexport interface ElicitationFormProps {\n /** MCP `elicitation/create` request payload to render. */\n event: ElicitationEvent\n /**\n * Called when user submits a valid response. `content` is keyed by the\n * elicitation `requestedSchema.properties` names — ready to send back as\n * the `accept` outcome of an `elicitation/create` reply.\n */\n onAccept: (content: Record<string, unknown>) => void\n /** Called when user dismisses (X icon, confirm-cancel button). */\n onCancel?: () => void\n /**\n * Optional explicit decline action. When provided, takes precedence over\n * `onCancel` on dismiss. Pair with `dismissLabel=\"Decline\"` to surface as\n * a decline action in the UI.\n */\n onDecline?: () => void\n /** Label on the dismiss button (default: X icon). */\n dismissLabel?: string\n}\n\n/**\n * @experimental\n * Schema-driven renderer for MCP `elicitation/create` requests.\n */\nexport const ElicitationForm: Component<ElicitationFormProps> = (props) => {\n const config = () => elicitationToPromptConfig(props.event)\n\n const handleSubmit = (response: ChatPromptResponse): void => {\n if (response.dismissed) {\n ;(props.onDecline ?? props.onCancel)?.()\n return\n }\n props.onAccept(extractContent(response, props.event))\n }\n\n return <ChatPrompt config={config()} dismissLabel={props.dismissLabel} onSubmit={handleSubmit} />\n}\n\nfunction extractContent(\n response: ChatPromptResponse,\n event: ElicitationEvent\n): Record<string, unknown> {\n // Form: response.value is already a Record keyed by property names.\n if (typeof response.value !== 'string') {\n return response.value\n }\n\n const propEntries = Object.entries(event.requestedSchema.properties)\n\n // Single-property cases (boolean confirm or single enum choice).\n if (propEntries.length === 1) {\n const [name, schema] = propEntries[0]\n return { [name]: coerceScalar(response.value, schema) }\n }\n\n // Multi-property string response — shouldn't happen since the helper\n // routes multi-prop schemas to 'form'. Fall back gracefully.\n console.warn(\n '[MCP-UI] ElicitationForm: received string value for multi-property schema. Falling back to _value.'\n )\n return { _value: response.value }\n}\n\nfunction coerceScalar(value: string, schema: ElicitationPropertySchema): unknown {\n // Confirm always emits the literal 'confirmed' on accept (cancel path is\n // trapped earlier by `dismissed: true`). Map to boolean true.\n if (schema.type === 'boolean') return true\n\n if (schema.type === 'number' || schema.type === 'integer') {\n const n = Number(value)\n return Number.isFinite(n) ? n : value\n }\n\n return value\n}\n"],"names":["ElicitationForm","props","config","elicitationToPromptConfig","event","handleSubmit","response","dismissed","onDecline","onCancel","onAccept","extractContent","_$createComponent","ChatPrompt","dismissLabel","onSubmit","value","propEntries","Object","entries","requestedSchema","properties","length","name","schema","coerceScalar","console","warn","_value","type","n","Number","isFinite"],"mappings":";;;;;AA2EO,MAAMA,kBAAoDC,CAAAA,UAAU;AACzE,QAAMC,SAASA,MAAMC,kCAA0BF,MAAMG,KAAK;AAE1D,QAAMC,eAAeA,CAACC,aAAuC;;AAC3D,QAAIA,SAASC,WAAW;AACrB,OAACN,WAAMO,aAAaP,MAAMQ,aAAzBR;AACF;AAAA,IACF;AACAA,UAAMS,SAASC,eAAeL,UAAUL,MAAMG,KAAK,CAAC;AAAA,EACtD;AAEA,SAAAQ,IAAAA,gBAAQC,WAAAA,YAAU;AAAA,IAAA,IAACX,SAAM;AAAA,aAAEA,OAAAA;AAAAA,IAAQ;AAAA,IAAA,IAAEY,eAAY;AAAA,aAAEb,MAAMa;AAAAA,IAAY;AAAA,IAAEC,UAAUV;AAAAA,EAAAA,CAAY;AAC/F;AAEA,SAASM,eACPL,UACAF,OACyB;AAEzB,MAAI,OAAOE,SAASU,UAAU,UAAU;AACtC,WAAOV,SAASU;AAAAA,EAClB;AAEA,QAAMC,cAAcC,OAAOC,QAAQf,MAAMgB,gBAAgBC,UAAU;AAGnE,MAAIJ,YAAYK,WAAW,GAAG;AAC5B,UAAM,CAACC,MAAMC,MAAM,IAAIP,YAAY,CAAC;AACpC,WAAO;AAAA,MAAE,CAACM,IAAI,GAAGE,aAAanB,SAASU,OAAOQ,MAAM;AAAA,IAAA;AAAA,EACtD;AAIAE,UAAQC,KACN,oGACF;AACA,SAAO;AAAA,IAAEC,QAAQtB,SAASU;AAAAA,EAAAA;AAC5B;AAEA,SAASS,aAAaT,OAAeQ,QAA4C;AAG/E,MAAIA,OAAOK,SAAS,UAAW,QAAO;AAEtC,MAAIL,OAAOK,SAAS,YAAYL,OAAOK,SAAS,WAAW;AACzD,UAAMC,IAAIC,OAAOf,KAAK;AACtB,WAAOe,OAAOC,SAASF,CAAC,IAAIA,IAAId;AAAAA,EAClC;AAEA,SAAOA;AACT;;"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ElicitationForm — schema-driven renderer for MCP `elicitation/create` requests
|
|
3
|
+
*
|
|
4
|
+
* @experimental
|
|
5
|
+
* @since v5.3.0
|
|
6
|
+
*
|
|
7
|
+
* Thin wrapper over `<ChatPrompt>` + `elicitationToPromptConfig()` that
|
|
8
|
+
* accepts a spec-shaped `ElicitationEvent` (MCP 2025-06-18) and exposes a
|
|
9
|
+
* spec-shaped `onAccept(content)` callback whose payload is ready to send
|
|
10
|
+
* back as the `accept` outcome of an `elicitation/create` reply.
|
|
11
|
+
*
|
|
12
|
+
* The mapping (boolean → confirm, single enum ≤4 → choice, else → form) is
|
|
13
|
+
* delegated to the `elicitationToPromptConfig` helper — same rules, same
|
|
14
|
+
* tests. This component owns the inverse mapping : extracting a spec-shaped
|
|
15
|
+
* `Record<string, unknown>` from the `ChatPromptResponse`.
|
|
16
|
+
*
|
|
17
|
+
* ## Outcome semantics (per MCP spec 2025-06-18)
|
|
18
|
+
*
|
|
19
|
+
* | User action | Callback fired | Payload |
|
|
20
|
+
* |---------------------------------------|--------------------|----------------------------------|
|
|
21
|
+
* | Submit form / pick choice / confirm | `onAccept(content)`| `{ [propName]: value, ... }` |
|
|
22
|
+
* | X icon / Cancel button | `onCancel()` *or* `onDecline()` if provided | none |
|
|
23
|
+
*
|
|
24
|
+
* mcp-ui's `<ChatPrompt>` does not natively distinguish "decline" (explicit
|
|
25
|
+
* refusal) from "cancel" (passive close). To surface a decline action,
|
|
26
|
+
* pass `dismissLabel="Decline"` and route the callback via `onDecline`.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* bus.events.on('onElicitation', ({ elicitation }) => {
|
|
31
|
+
* render(() => (
|
|
32
|
+
* <ElicitationForm
|
|
33
|
+
* event={elicitation}
|
|
34
|
+
* onAccept={(content) => sendElicitationReply({ action: 'accept', content })}
|
|
35
|
+
* onCancel={() => sendElicitationReply({ action: 'cancel' })}
|
|
36
|
+
* />
|
|
37
|
+
* ), mountPoint)
|
|
38
|
+
* })
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
import { Component } from 'solid-js';
|
|
42
|
+
import type { ElicitationEvent } from '../types/chat-bus';
|
|
43
|
+
export interface ElicitationFormProps {
|
|
44
|
+
/** MCP `elicitation/create` request payload to render. */
|
|
45
|
+
event: ElicitationEvent;
|
|
46
|
+
/**
|
|
47
|
+
* Called when user submits a valid response. `content` is keyed by the
|
|
48
|
+
* elicitation `requestedSchema.properties` names — ready to send back as
|
|
49
|
+
* the `accept` outcome of an `elicitation/create` reply.
|
|
50
|
+
*/
|
|
51
|
+
onAccept: (content: Record<string, unknown>) => void;
|
|
52
|
+
/** Called when user dismisses (X icon, confirm-cancel button). */
|
|
53
|
+
onCancel?: () => void;
|
|
54
|
+
/**
|
|
55
|
+
* Optional explicit decline action. When provided, takes precedence over
|
|
56
|
+
* `onCancel` on dismiss. Pair with `dismissLabel="Decline"` to surface as
|
|
57
|
+
* a decline action in the UI.
|
|
58
|
+
*/
|
|
59
|
+
onDecline?: () => void;
|
|
60
|
+
/** Label on the dismiss button (default: X icon). */
|
|
61
|
+
dismissLabel?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @experimental
|
|
65
|
+
* Schema-driven renderer for MCP `elicitation/create` requests.
|
|
66
|
+
*/
|
|
67
|
+
export declare const ElicitationForm: Component<ElicitationFormProps>;
|
|
68
|
+
//# sourceMappingURL=ElicitationForm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElicitationForm.d.ts","sourceRoot":"","sources":["../../src/components/ElicitationForm.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGpC,OAAO,KAAK,EAEV,gBAAgB,EAEjB,MAAM,mBAAmB,CAAA;AAE1B,MAAM,WAAW,oBAAoB;IACnC,0DAA0D;IAC1D,KAAK,EAAE,gBAAgB,CAAA;IACvB;;;;OAIG;IACH,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;IACpD,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IACtB,qDAAqD;IACrD,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,SAAS,CAAC,oBAAoB,CAY3D,CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createComponent } from "solid-js/web";
|
|
2
|
+
import { ChatPrompt } from "./ChatPrompt.js";
|
|
3
|
+
import { elicitationToPromptConfig } from "../services/chat-bus.js";
|
|
4
|
+
const ElicitationForm = (props) => {
|
|
5
|
+
const config = () => elicitationToPromptConfig(props.event);
|
|
6
|
+
const handleSubmit = (response) => {
|
|
7
|
+
var _a;
|
|
8
|
+
if (response.dismissed) {
|
|
9
|
+
(_a = props.onDecline ?? props.onCancel) == null ? void 0 : _a();
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
props.onAccept(extractContent(response, props.event));
|
|
13
|
+
};
|
|
14
|
+
return createComponent(ChatPrompt, {
|
|
15
|
+
get config() {
|
|
16
|
+
return config();
|
|
17
|
+
},
|
|
18
|
+
get dismissLabel() {
|
|
19
|
+
return props.dismissLabel;
|
|
20
|
+
},
|
|
21
|
+
onSubmit: handleSubmit
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
function extractContent(response, event) {
|
|
25
|
+
if (typeof response.value !== "string") {
|
|
26
|
+
return response.value;
|
|
27
|
+
}
|
|
28
|
+
const propEntries = Object.entries(event.requestedSchema.properties);
|
|
29
|
+
if (propEntries.length === 1) {
|
|
30
|
+
const [name, schema] = propEntries[0];
|
|
31
|
+
return {
|
|
32
|
+
[name]: coerceScalar(response.value, schema)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
console.warn("[MCP-UI] ElicitationForm: received string value for multi-property schema. Falling back to _value.");
|
|
36
|
+
return {
|
|
37
|
+
_value: response.value
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function coerceScalar(value, schema) {
|
|
41
|
+
if (schema.type === "boolean") return true;
|
|
42
|
+
if (schema.type === "number" || schema.type === "integer") {
|
|
43
|
+
const n = Number(value);
|
|
44
|
+
return Number.isFinite(n) ? n : value;
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
ElicitationForm
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=ElicitationForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElicitationForm.js","sources":["../../src/components/ElicitationForm.tsx"],"sourcesContent":["/**\n * ElicitationForm — schema-driven renderer for MCP `elicitation/create` requests\n *\n * @experimental\n * @since v5.3.0\n *\n * Thin wrapper over `<ChatPrompt>` + `elicitationToPromptConfig()` that\n * accepts a spec-shaped `ElicitationEvent` (MCP 2025-06-18) and exposes a\n * spec-shaped `onAccept(content)` callback whose payload is ready to send\n * back as the `accept` outcome of an `elicitation/create` reply.\n *\n * The mapping (boolean → confirm, single enum ≤4 → choice, else → form) is\n * delegated to the `elicitationToPromptConfig` helper — same rules, same\n * tests. This component owns the inverse mapping : extracting a spec-shaped\n * `Record<string, unknown>` from the `ChatPromptResponse`.\n *\n * ## Outcome semantics (per MCP spec 2025-06-18)\n *\n * | User action | Callback fired | Payload |\n * |---------------------------------------|--------------------|----------------------------------|\n * | Submit form / pick choice / confirm | `onAccept(content)`| `{ [propName]: value, ... }` |\n * | X icon / Cancel button | `onCancel()` *or* `onDecline()` if provided | none |\n *\n * mcp-ui's `<ChatPrompt>` does not natively distinguish \"decline\" (explicit\n * refusal) from \"cancel\" (passive close). To surface a decline action,\n * pass `dismissLabel=\"Decline\"` and route the callback via `onDecline`.\n *\n * @example\n * ```tsx\n * bus.events.on('onElicitation', ({ elicitation }) => {\n * render(() => (\n * <ElicitationForm\n * event={elicitation}\n * onAccept={(content) => sendElicitationReply({ action: 'accept', content })}\n * onCancel={() => sendElicitationReply({ action: 'cancel' })}\n * />\n * ), mountPoint)\n * })\n * ```\n */\n\nimport { Component } from 'solid-js'\nimport { ChatPrompt } from './ChatPrompt'\nimport { elicitationToPromptConfig } from '../services/chat-bus'\nimport type {\n ChatPromptResponse,\n ElicitationEvent,\n ElicitationPropertySchema,\n} from '../types/chat-bus'\n\nexport interface ElicitationFormProps {\n /** MCP `elicitation/create` request payload to render. */\n event: ElicitationEvent\n /**\n * Called when user submits a valid response. `content` is keyed by the\n * elicitation `requestedSchema.properties` names — ready to send back as\n * the `accept` outcome of an `elicitation/create` reply.\n */\n onAccept: (content: Record<string, unknown>) => void\n /** Called when user dismisses (X icon, confirm-cancel button). */\n onCancel?: () => void\n /**\n * Optional explicit decline action. When provided, takes precedence over\n * `onCancel` on dismiss. Pair with `dismissLabel=\"Decline\"` to surface as\n * a decline action in the UI.\n */\n onDecline?: () => void\n /** Label on the dismiss button (default: X icon). */\n dismissLabel?: string\n}\n\n/**\n * @experimental\n * Schema-driven renderer for MCP `elicitation/create` requests.\n */\nexport const ElicitationForm: Component<ElicitationFormProps> = (props) => {\n const config = () => elicitationToPromptConfig(props.event)\n\n const handleSubmit = (response: ChatPromptResponse): void => {\n if (response.dismissed) {\n ;(props.onDecline ?? props.onCancel)?.()\n return\n }\n props.onAccept(extractContent(response, props.event))\n }\n\n return <ChatPrompt config={config()} dismissLabel={props.dismissLabel} onSubmit={handleSubmit} />\n}\n\nfunction extractContent(\n response: ChatPromptResponse,\n event: ElicitationEvent\n): Record<string, unknown> {\n // Form: response.value is already a Record keyed by property names.\n if (typeof response.value !== 'string') {\n return response.value\n }\n\n const propEntries = Object.entries(event.requestedSchema.properties)\n\n // Single-property cases (boolean confirm or single enum choice).\n if (propEntries.length === 1) {\n const [name, schema] = propEntries[0]\n return { [name]: coerceScalar(response.value, schema) }\n }\n\n // Multi-property string response — shouldn't happen since the helper\n // routes multi-prop schemas to 'form'. Fall back gracefully.\n console.warn(\n '[MCP-UI] ElicitationForm: received string value for multi-property schema. Falling back to _value.'\n )\n return { _value: response.value }\n}\n\nfunction coerceScalar(value: string, schema: ElicitationPropertySchema): unknown {\n // Confirm always emits the literal 'confirmed' on accept (cancel path is\n // trapped earlier by `dismissed: true`). Map to boolean true.\n if (schema.type === 'boolean') return true\n\n if (schema.type === 'number' || schema.type === 'integer') {\n const n = Number(value)\n return Number.isFinite(n) ? n : value\n }\n\n return value\n}\n"],"names":["ElicitationForm","props","config","elicitationToPromptConfig","event","handleSubmit","response","dismissed","onDecline","onCancel","onAccept","extractContent","_$createComponent","ChatPrompt","dismissLabel","onSubmit","value","propEntries","Object","entries","requestedSchema","properties","length","name","schema","coerceScalar","console","warn","_value","type","n","Number","isFinite"],"mappings":";;;AA2EO,MAAMA,kBAAoDC,CAAAA,UAAU;AACzE,QAAMC,SAASA,MAAMC,0BAA0BF,MAAMG,KAAK;AAE1D,QAAMC,eAAeA,CAACC,aAAuC;;AAC3D,QAAIA,SAASC,WAAW;AACrB,OAACN,WAAMO,aAAaP,MAAMQ,aAAzBR;AACF;AAAA,IACF;AACAA,UAAMS,SAASC,eAAeL,UAAUL,MAAMG,KAAK,CAAC;AAAA,EACtD;AAEA,SAAAQ,gBAAQC,YAAU;AAAA,IAAA,IAACX,SAAM;AAAA,aAAEA,OAAAA;AAAAA,IAAQ;AAAA,IAAA,IAAEY,eAAY;AAAA,aAAEb,MAAMa;AAAAA,IAAY;AAAA,IAAEC,UAAUV;AAAAA,EAAAA,CAAY;AAC/F;AAEA,SAASM,eACPL,UACAF,OACyB;AAEzB,MAAI,OAAOE,SAASU,UAAU,UAAU;AACtC,WAAOV,SAASU;AAAAA,EAClB;AAEA,QAAMC,cAAcC,OAAOC,QAAQf,MAAMgB,gBAAgBC,UAAU;AAGnE,MAAIJ,YAAYK,WAAW,GAAG;AAC5B,UAAM,CAACC,MAAMC,MAAM,IAAIP,YAAY,CAAC;AACpC,WAAO;AAAA,MAAE,CAACM,IAAI,GAAGE,aAAanB,SAASU,OAAOQ,MAAM;AAAA,IAAA;AAAA,EACtD;AAIAE,UAAQC,KACN,oGACF;AACA,SAAO;AAAA,IAAEC,QAAQtB,SAASU;AAAAA,EAAAA;AAC5B;AAEA,SAASS,aAAaT,OAAeQ,QAA4C;AAG/E,MAAIA,OAAOK,SAAS,UAAW,QAAO;AAEtC,MAAIL,OAAOK,SAAS,YAAYL,OAAOK,SAAS,WAAW;AACzD,UAAMC,IAAIC,OAAOf,KAAK;AACtB,WAAOe,OAAOC,SAASF,CAAC,IAAIA,IAAId;AAAAA,EAClC;AAEA,SAAOA;AACT;"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const web = require("solid-js/web");
|
|
4
|
+
const solidJs = require("solid-js");
|
|
5
|
+
var _tmpl$ = /* @__PURE__ */ web.template(`<button type=button class="p-1 rounded hover:bg-green-500/10 text-deposium-slate-500 hover:text-green-500 transition-colors"title=Utile aria-label="Mark response as useful"data-feedback-inline-rating=positive><svg class="w-3.5 h-3.5"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M14 9V5a3 3 0 00-3-3l-4 9v11h11.28a2 2 0 002-1.7l1.38-9a2 2 0 00-2-2.3H14z M3 15v7">`), _tmpl$2 = /* @__PURE__ */ web.template(`<button type=button class="p-1 rounded hover:bg-red-500/10 text-deposium-slate-500 hover:text-red-500 transition-colors"title="Pas utile"aria-label="Mark response as not useful"data-feedback-inline-rating=negative><svg class="w-3.5 h-3.5"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M10 15v4a3 3 0 003 3l4-9V2H5.72a2 2 0 00-2 1.7l-1.38 9a2 2 0 002 2.3H10z M21 4v7">`), _tmpl$3 = /* @__PURE__ */ web.template(`<div>`), _tmpl$4 = /* @__PURE__ */ web.template(`<span class="text-[11px] text-deposium-slate-500">`);
|
|
6
|
+
const FeedbackInline = (props) => {
|
|
7
|
+
const [rating, setRating] = solidJs.createSignal(null);
|
|
8
|
+
const handle = (value) => {
|
|
9
|
+
if (rating() !== null) return;
|
|
10
|
+
setRating(value);
|
|
11
|
+
try {
|
|
12
|
+
const result = props.onSubmit(value, props.context);
|
|
13
|
+
if (result && typeof result.catch === "function") {
|
|
14
|
+
;
|
|
15
|
+
result.catch(() => {
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
return (() => {
|
|
22
|
+
var _el$ = web.getNextElement(_tmpl$3);
|
|
23
|
+
web.insert(_el$, web.createComponent(solidJs.Show, {
|
|
24
|
+
get when() {
|
|
25
|
+
return rating() === null;
|
|
26
|
+
},
|
|
27
|
+
get fallback() {
|
|
28
|
+
return (() => {
|
|
29
|
+
var _el$4 = web.getNextElement(_tmpl$4);
|
|
30
|
+
web.insert(_el$4, (() => {
|
|
31
|
+
var _c$ = web.memo(() => rating() === "positive");
|
|
32
|
+
return () => _c$() ? props.positiveAck ?? "Merci !" : props.negativeAck ?? "Noté, on s'améliore";
|
|
33
|
+
})());
|
|
34
|
+
return _el$4;
|
|
35
|
+
})();
|
|
36
|
+
},
|
|
37
|
+
get children() {
|
|
38
|
+
return [(() => {
|
|
39
|
+
var _el$2 = web.getNextElement(_tmpl$);
|
|
40
|
+
_el$2.$$click = () => handle("positive");
|
|
41
|
+
web.runHydrationEvents();
|
|
42
|
+
return _el$2;
|
|
43
|
+
})(), (() => {
|
|
44
|
+
var _el$3 = web.getNextElement(_tmpl$2);
|
|
45
|
+
_el$3.$$click = () => handle("negative");
|
|
46
|
+
web.runHydrationEvents();
|
|
47
|
+
return _el$3;
|
|
48
|
+
})()];
|
|
49
|
+
}
|
|
50
|
+
}));
|
|
51
|
+
web.effect(() => web.className(_el$, `flex items-center gap-1 ${props.class ?? ""}`.trim()));
|
|
52
|
+
return _el$;
|
|
53
|
+
})();
|
|
54
|
+
};
|
|
55
|
+
web.delegateEvents(["click"]);
|
|
56
|
+
exports.FeedbackInline = FeedbackInline;
|
|
57
|
+
//# sourceMappingURL=FeedbackInline.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FeedbackInline.cjs","sources":["../../src/components/FeedbackInline.tsx"],"sourcesContent":["/**\n * FeedbackInline — per-message inline feedback (thumbs up/down)\n *\n * @experimental\n * @since v5.2.0\n *\n * A small, non-blocking per-message feedback primitive. Sits next to an\n * assistant message, captures a rating, calls back to the consumer for\n * persistence. Best-effort by design — no retry UX, no revision UX.\n *\n * ## When to use vs other feedback primitives\n *\n * - **`FeedbackInline`** (this) → per-message thumb-up/down, non-blocking,\n * many can coexist.\n * - **`ChatPrompt` (type=choice)** → modal, one-at-a-time above the input,\n * used when the agent needs a blocking answer.\n * - **`ScratchpadPanel` feedback section** → structured feedback bound to a\n * scratchpad turn, panel-side.\n *\n * ## Persistence is the consumer's job\n *\n * The component flips to \"submitted\" state *optimistically* on click and\n * calls `onSubmit(rating, context)`. Network failures do not revert the UI —\n * feedback is best-effort. If you need stricter semantics (offline retry,\n * revision, ...) wrap this in your own component.\n *\n * @example\n * ```tsx\n * <FeedbackInline\n * messageHash={msg.hash}\n * context={{ intent: msg.intent, confidenceBand: msg.band }}\n * onSubmit={(rating, ctx) =>\n * fetch('/api/feedback', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ message_hash: msg.hash, rating, ...ctx }),\n * })\n * }\n * />\n * ```\n */\n\nimport { Component, Show, createSignal } from 'solid-js'\n\nexport interface FeedbackInlineContext {\n intent?: string\n confidenceBand?: string\n tags?: string[]\n [key: string]: unknown\n}\n\nexport interface FeedbackInlineProps {\n /** Stable identifier for the message being rated. */\n messageHash?: string\n /**\n * Called on click. Consumer is responsible for persistence (HTTP, store,\n * localStorage). Return value ignored.\n */\n onSubmit: (rating: 'positive' | 'negative', context?: FeedbackInlineContext) => void | Promise<void>\n /** Extra context forwarded to `onSubmit`. */\n context?: FeedbackInlineContext\n /** Ack text shown after positive rating. Default: 'Merci !' */\n positiveAck?: string\n /** Ack text shown after negative rating. Default: \"Noté, on s'améliore\" */\n negativeAck?: string\n /** Extra Tailwind classes on the container. */\n class?: string\n}\n\n/**\n * @experimental\n * Per-message inline feedback (thumbs up/down). Non-blocking.\n */\nexport const FeedbackInline: Component<FeedbackInlineProps> = (props) => {\n const [rating, setRating] = createSignal<'positive' | 'negative' | null>(null)\n\n const handle = (value: 'positive' | 'negative') => {\n if (rating() !== null) return // already submitted, final state\n setRating(value)\n try {\n // Fire-and-forget. If the consumer returns a Promise that rejects,\n // swallow it — feedback is best-effort by design.\n const result = props.onSubmit(value, props.context)\n if (result && typeof (result as Promise<void>).catch === 'function') {\n ;(result as Promise<void>).catch(() => {\n /* non-blocking */\n })\n }\n } catch {\n /* non-blocking */\n }\n }\n\n return (\n <div class={`flex items-center gap-1 ${props.class ?? ''}`.trim()}>\n <Show\n when={rating() === null}\n fallback={\n <span class=\"text-[11px] text-deposium-slate-500\">\n {rating() === 'positive'\n ? (props.positiveAck ?? 'Merci !')\n : (props.negativeAck ?? \"Noté, on s'améliore\")}\n </span>\n }\n >\n <button\n type=\"button\"\n onClick={() => handle('positive')}\n class=\"p-1 rounded hover:bg-green-500/10 text-deposium-slate-500 hover:text-green-500 transition-colors\"\n title=\"Utile\"\n aria-label=\"Mark response as useful\"\n data-feedback-inline-rating=\"positive\"\n >\n <svg class=\"w-3.5 h-3.5\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n <path\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n stroke-width=\"2\"\n d=\"M14 9V5a3 3 0 00-3-3l-4 9v11h11.28a2 2 0 002-1.7l1.38-9a2 2 0 00-2-2.3H14z M3 15v7\"\n />\n </svg>\n </button>\n <button\n type=\"button\"\n onClick={() => handle('negative')}\n class=\"p-1 rounded hover:bg-red-500/10 text-deposium-slate-500 hover:text-red-500 transition-colors\"\n title=\"Pas utile\"\n aria-label=\"Mark response as not useful\"\n data-feedback-inline-rating=\"negative\"\n >\n <svg class=\"w-3.5 h-3.5\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n <path\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n stroke-width=\"2\"\n d=\"M10 15v4a3 3 0 003 3l4-9V2H5.72a2 2 0 00-2 1.7l-1.38 9a2 2 0 002 2.3H10z M21 4v7\"\n />\n </svg>\n </button>\n </Show>\n </div>\n )\n}\n"],"names":["FeedbackInline","props","rating","setRating","createSignal","handle","value","result","onSubmit","context","catch","_el$","_$getNextElement","_tmpl$3","_$insert","_$createComponent","Show","when","fallback","_el$4","_tmpl$4","_c$","_$memo","positiveAck","negativeAck","children","_el$2","_tmpl$","$$click","_$runHydrationEvents","_el$3","_tmpl$2","_$effect","_$className","class","trim","_$delegateEvents"],"mappings":";;;;;AAyEO,MAAMA,iBAAkDC,CAAAA,UAAU;AACvE,QAAM,CAACC,QAAQC,SAAS,IAAIC,QAAAA,aAA6C,IAAI;AAE7E,QAAMC,SAASA,CAACC,UAAmC;AACjD,QAAIJ,OAAAA,MAAa,KAAM;AACvBC,cAAUG,KAAK;AACf,QAAI;AAGF,YAAMC,SAASN,MAAMO,SAASF,OAAOL,MAAMQ,OAAO;AAClD,UAAIF,UAAU,OAAQA,OAAyBG,UAAU,YAAY;AACnE;AAAEH,eAAyBG,MAAM,MAAM;AAAA,QACrC,CACD;AAAA,MACH;AAAA,IACF,QAAQ;AAAA,IACN;AAAA,EAEJ;AAEA,UAAA,MAAA;AAAA,QAAAC,OAAAC,IAAAA,eAAAC,OAAA;AAAAC,eAAAH,MAAAI,IAAAA,gBAEKC,cAAI;AAAA,MAAA,IACHC,OAAI;AAAA,eAAEf,aAAa;AAAA,MAAI;AAAA,MAAA,IACvBgB,WAAQ;AAAA,gBAAA,MAAA;AAAA,cAAAC,QAAAP,IAAAA,eAAAQ,OAAA;AAAAN,cAAAA,OAAAK,QAAA,MAAA;AAAA,gBAAAE,MAAAC,IAAAA,KAAA,MAEHpB,OAAAA,MAAa,UAAU;AAAA,mBAAA,MAAvBmB,IAAAA,IACIpB,MAAMsB,eAAe,YACrBtB,MAAMuB,eAAe;AAAA,UAAsB,IAAA;AAAA,iBAAAL;AAAAA,QAAA,GAAA;AAAA,MAAA;AAAA,MAAA,IAAAM,WAAA;AAAA,eAAA,EAAA,MAAA;AAAA,cAAAC,QAAAd,IAAAA,eAAAe,MAAA;AAAAD,gBAAAE,UAMzC,MAAMvB,OAAO,UAAU;AAACwB,iCAAAA;AAAA,iBAAAH;AAAAA,QAAA,GAAA,IAAA,MAAA;AAAA,cAAAI,QAAAlB,IAAAA,eAAAmB,OAAA;AAAAD,gBAAAF,UAiBxB,MAAMvB,OAAO,UAAU;AAACwB,iCAAAA;AAAA,iBAAAC;AAAAA,QAAA,IAAA;AAAA,MAAA;AAAA,IAAA,CAAA,CAAA;AAAAE,QAAAA,OAAA,MAAAC,IAAAA,UAAAtB,MA9B3B,2BAA2BV,MAAMiC,SAAS,EAAE,GAAGC,KAAAA,CAAM,CAAA;AAAA,WAAAxB;AAAAA,EAAA,GAAA;AAgDrE;AAACyB,IAAAA,eAAA,CAAA,OAAA,CAAA;;"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FeedbackInline — per-message inline feedback (thumbs up/down)
|
|
3
|
+
*
|
|
4
|
+
* @experimental
|
|
5
|
+
* @since v5.2.0
|
|
6
|
+
*
|
|
7
|
+
* A small, non-blocking per-message feedback primitive. Sits next to an
|
|
8
|
+
* assistant message, captures a rating, calls back to the consumer for
|
|
9
|
+
* persistence. Best-effort by design — no retry UX, no revision UX.
|
|
10
|
+
*
|
|
11
|
+
* ## When to use vs other feedback primitives
|
|
12
|
+
*
|
|
13
|
+
* - **`FeedbackInline`** (this) → per-message thumb-up/down, non-blocking,
|
|
14
|
+
* many can coexist.
|
|
15
|
+
* - **`ChatPrompt` (type=choice)** → modal, one-at-a-time above the input,
|
|
16
|
+
* used when the agent needs a blocking answer.
|
|
17
|
+
* - **`ScratchpadPanel` feedback section** → structured feedback bound to a
|
|
18
|
+
* scratchpad turn, panel-side.
|
|
19
|
+
*
|
|
20
|
+
* ## Persistence is the consumer's job
|
|
21
|
+
*
|
|
22
|
+
* The component flips to "submitted" state *optimistically* on click and
|
|
23
|
+
* calls `onSubmit(rating, context)`. Network failures do not revert the UI —
|
|
24
|
+
* feedback is best-effort. If you need stricter semantics (offline retry,
|
|
25
|
+
* revision, ...) wrap this in your own component.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* <FeedbackInline
|
|
30
|
+
* messageHash={msg.hash}
|
|
31
|
+
* context={{ intent: msg.intent, confidenceBand: msg.band }}
|
|
32
|
+
* onSubmit={(rating, ctx) =>
|
|
33
|
+
* fetch('/api/feedback', {
|
|
34
|
+
* method: 'POST',
|
|
35
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
36
|
+
* body: JSON.stringify({ message_hash: msg.hash, rating, ...ctx }),
|
|
37
|
+
* })
|
|
38
|
+
* }
|
|
39
|
+
* />
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
import { Component } from 'solid-js';
|
|
43
|
+
export interface FeedbackInlineContext {
|
|
44
|
+
intent?: string;
|
|
45
|
+
confidenceBand?: string;
|
|
46
|
+
tags?: string[];
|
|
47
|
+
[key: string]: unknown;
|
|
48
|
+
}
|
|
49
|
+
export interface FeedbackInlineProps {
|
|
50
|
+
/** Stable identifier for the message being rated. */
|
|
51
|
+
messageHash?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Called on click. Consumer is responsible for persistence (HTTP, store,
|
|
54
|
+
* localStorage). Return value ignored.
|
|
55
|
+
*/
|
|
56
|
+
onSubmit: (rating: 'positive' | 'negative', context?: FeedbackInlineContext) => void | Promise<void>;
|
|
57
|
+
/** Extra context forwarded to `onSubmit`. */
|
|
58
|
+
context?: FeedbackInlineContext;
|
|
59
|
+
/** Ack text shown after positive rating. Default: 'Merci !' */
|
|
60
|
+
positiveAck?: string;
|
|
61
|
+
/** Ack text shown after negative rating. Default: "Noté, on s'améliore" */
|
|
62
|
+
negativeAck?: string;
|
|
63
|
+
/** Extra Tailwind classes on the container. */
|
|
64
|
+
class?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* @experimental
|
|
68
|
+
* Per-message inline feedback (thumbs up/down). Non-blocking.
|
|
69
|
+
*/
|
|
70
|
+
export declare const FeedbackInline: Component<FeedbackInlineProps>;
|
|
71
|
+
//# sourceMappingURL=FeedbackInline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FeedbackInline.d.ts","sourceRoot":"","sources":["../../src/components/FeedbackInline.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,EAAE,SAAS,EAAsB,MAAM,UAAU,CAAA;AAExD,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,mBAAmB;IAClC,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,EAAE,OAAO,CAAC,EAAE,qBAAqB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACpG,6CAA6C;IAC7C,OAAO,CAAC,EAAE,qBAAqB,CAAA;IAC/B,+DAA+D;IAC/D,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,2EAA2E;IAC3E,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,CAAC,mBAAmB,CAqEzD,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { delegateEvents, getNextElement, template, insert, createComponent, runHydrationEvents, memo, effect, className } from "solid-js/web";
|
|
2
|
+
import { createSignal, Show } from "solid-js";
|
|
3
|
+
var _tmpl$ = /* @__PURE__ */ template(`<button type=button class="p-1 rounded hover:bg-green-500/10 text-deposium-slate-500 hover:text-green-500 transition-colors"title=Utile aria-label="Mark response as useful"data-feedback-inline-rating=positive><svg class="w-3.5 h-3.5"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M14 9V5a3 3 0 00-3-3l-4 9v11h11.28a2 2 0 002-1.7l1.38-9a2 2 0 00-2-2.3H14z M3 15v7">`), _tmpl$2 = /* @__PURE__ */ template(`<button type=button class="p-1 rounded hover:bg-red-500/10 text-deposium-slate-500 hover:text-red-500 transition-colors"title="Pas utile"aria-label="Mark response as not useful"data-feedback-inline-rating=negative><svg class="w-3.5 h-3.5"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M10 15v4a3 3 0 003 3l4-9V2H5.72a2 2 0 00-2 1.7l-1.38 9a2 2 0 002 2.3H10z M21 4v7">`), _tmpl$3 = /* @__PURE__ */ template(`<div>`), _tmpl$4 = /* @__PURE__ */ template(`<span class="text-[11px] text-deposium-slate-500">`);
|
|
4
|
+
const FeedbackInline = (props) => {
|
|
5
|
+
const [rating, setRating] = createSignal(null);
|
|
6
|
+
const handle = (value) => {
|
|
7
|
+
if (rating() !== null) return;
|
|
8
|
+
setRating(value);
|
|
9
|
+
try {
|
|
10
|
+
const result = props.onSubmit(value, props.context);
|
|
11
|
+
if (result && typeof result.catch === "function") {
|
|
12
|
+
;
|
|
13
|
+
result.catch(() => {
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
} catch {
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
return (() => {
|
|
20
|
+
var _el$ = getNextElement(_tmpl$3);
|
|
21
|
+
insert(_el$, createComponent(Show, {
|
|
22
|
+
get when() {
|
|
23
|
+
return rating() === null;
|
|
24
|
+
},
|
|
25
|
+
get fallback() {
|
|
26
|
+
return (() => {
|
|
27
|
+
var _el$4 = getNextElement(_tmpl$4);
|
|
28
|
+
insert(_el$4, (() => {
|
|
29
|
+
var _c$ = memo(() => rating() === "positive");
|
|
30
|
+
return () => _c$() ? props.positiveAck ?? "Merci !" : props.negativeAck ?? "Noté, on s'améliore";
|
|
31
|
+
})());
|
|
32
|
+
return _el$4;
|
|
33
|
+
})();
|
|
34
|
+
},
|
|
35
|
+
get children() {
|
|
36
|
+
return [(() => {
|
|
37
|
+
var _el$2 = getNextElement(_tmpl$);
|
|
38
|
+
_el$2.$$click = () => handle("positive");
|
|
39
|
+
runHydrationEvents();
|
|
40
|
+
return _el$2;
|
|
41
|
+
})(), (() => {
|
|
42
|
+
var _el$3 = getNextElement(_tmpl$2);
|
|
43
|
+
_el$3.$$click = () => handle("negative");
|
|
44
|
+
runHydrationEvents();
|
|
45
|
+
return _el$3;
|
|
46
|
+
})()];
|
|
47
|
+
}
|
|
48
|
+
}));
|
|
49
|
+
effect(() => className(_el$, `flex items-center gap-1 ${props.class ?? ""}`.trim()));
|
|
50
|
+
return _el$;
|
|
51
|
+
})();
|
|
52
|
+
};
|
|
53
|
+
delegateEvents(["click"]);
|
|
54
|
+
export {
|
|
55
|
+
FeedbackInline
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=FeedbackInline.js.map
|