@emseepea/svelte 0.0.0-bootstrap.0 → 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Windy Road Technology Pty. Limited
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Svelte Result Renderer
2
+
3
+ `@emseepea/svelte` renders a validated Em See Pea result view with native HTML.
4
+ It is unstyled and does not send requests, authenticate people, or authorize
5
+ server actions.
6
+
7
+ ```svelte
8
+ <script>
9
+ import { ResultCard, createMcpApp } from "@emseepea/svelte";
10
+ import { parseResultView } from "@emseepea/server/ui";
11
+
12
+ const app = createMcpApp({ name: "Result", version: "1.0.0", parseResult: parseResultView });
13
+ const view = $derived($app.result ?? loadingView);
14
+ </script>
15
+
16
+ <ResultCard {view} headingLevel={2} onAction={() => app.sendMessage("Continue")} />
17
+ ```
18
+
19
+ `createMcpApp` implements the standards-first MCP Apps initialization,
20
+ host-context, tool-result, cancellation, teardown, and `ui/message` lifecycle.
21
+ Keep domain result parsing and mapping in the adopter, and treat host messages
22
+ as untrusted.
23
+
24
+ For a self-contained resource that does not already use either framework, see
25
+ the measured [React and Svelte bundle guidance](../framework/README.md#choose-a-result-card-package).
26
+
27
+ This package is open source under MIT and remains pre-alpha while its version is below 1.0.
package/package.json CHANGED
@@ -1,12 +1,44 @@
1
1
  {
2
2
  "name": "@emseepea/svelte",
3
- "version": "0.0.0-bootstrap.0",
4
- "description": "Reserved package identity for the governed Em See Pea release pipeline.",
3
+ "version": "0.1.0",
4
+ "private": false,
5
5
  "license": "MIT",
6
- "repository": "git+https://github.com/emseepea/emseepea.git",
7
- "publishConfig": {
8
- "access": "public",
9
- "tag": "bootstrap",
10
- "provenance": false
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/emseepea/emseepea.git",
9
+ "directory": "packages/svelte"
10
+ },
11
+ "homepage": "https://emseepea.github.io/emseepea/examples/",
12
+ "bugs": "https://github.com/emseepea/emseepea/issues",
13
+ "publishConfig": { "access": "public", "provenance": true },
14
+ "type": "module",
15
+ "svelte": "./src/index.js",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./src/index.d.ts",
19
+ "svelte": "./src/index.js",
20
+ "import": "./src/index.js"
21
+ }
22
+ },
23
+ "files": ["src", "LICENSE", "README.md"],
24
+ "scripts": {
25
+ "build": "node test/compile.test.mjs",
26
+ "prepack": "npm run build",
27
+ "test": "npm run build && npm run test:built",
28
+ "test:built": "node --test test/*.test.mjs"
29
+ },
30
+ "dependencies": {
31
+ "@emseepea/server": "0.11.0"
32
+ },
33
+ "peerDependencies": {
34
+ "svelte": "^5.0.0"
35
+ },
36
+ "devDependencies": {
37
+ "esbuild": "0.28.2",
38
+ "playwright": "1.62.1",
39
+ "svelte": "5.57.0"
40
+ },
41
+ "engines": {
42
+ "node": ">=22"
11
43
  }
12
44
  }
@@ -0,0 +1,116 @@
1
+ <script>
2
+ import { parseResultView } from "@emseepea/server/ui";
3
+ import { tick } from "svelte";
4
+
5
+ let { view: candidate, headingLevel, onAction, idPrefix } = $props();
6
+ const componentId = $props.id();
7
+ const view = $derived(parseResultView(candidate));
8
+ const level = $derived(checkedHeadingLevel(headingLevel));
9
+ const prefix = $derived(idPrefix === undefined
10
+ ? `${view.id}-${componentId.replaceAll(":", "")}`
11
+ : checkedIdentifier("idPrefix", idPrefix));
12
+ const headingId = $derived(`${prefix}--heading`);
13
+ let result = $state();
14
+ let lastFocusKey = "";
15
+
16
+ $effect(() => {
17
+ if (view.state.focusTarget === "none") {
18
+ lastFocusKey = "";
19
+ return;
20
+ }
21
+ const focusKey = `${view.state.kind}\u0000${view.state.focusTarget}\u0000${view.state.status}`;
22
+ if (lastFocusKey === focusKey) return;
23
+ lastFocusKey = focusKey;
24
+ tick().then(() => {
25
+ if (lastFocusKey !== focusKey) return;
26
+ const target = view.state.focusTarget === "result"
27
+ ? result
28
+ : view.state.focusTarget === "status"
29
+ ? result?.querySelector('[data-emseepea-part="status"]')
30
+ : result?.querySelector('[data-emseepea-part="action"]:not(:disabled)');
31
+ target?.focus();
32
+ });
33
+ });
34
+
35
+ function checkedHeadingLevel(value) {
36
+ if (![2, 3, 4, 5, 6].includes(value)) throw new TypeError("headingLevel must be an integer from 2 to 6");
37
+ return value;
38
+ }
39
+
40
+ function checkedIdentifier(field, value) {
41
+ if (typeof value !== "string" || !/^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(value)) {
42
+ throw new TypeError(`${field} must be a valid identifier`);
43
+ }
44
+ return value;
45
+ }
46
+ </script>
47
+
48
+ <section
49
+ bind:this={result}
50
+ data-emseepea-part="result-view"
51
+ data-emseepea-state={view.state.kind}
52
+ aria-labelledby={headingId}
53
+ tabindex={view.state.focusTarget === "result" ? -1 : undefined}
54
+ autofocus={view.state.focusTarget === "result"}
55
+ >
56
+ <svelte:element this={`h${level}`} id={headingId}>{view.heading}</svelte:element>
57
+ <div
58
+ data-emseepea-part="status"
59
+ role="status"
60
+ aria-live="polite"
61
+ aria-atomic="true"
62
+ aria-relevant="additions text"
63
+ tabindex={view.state.focusTarget === "status" ? -1 : undefined}
64
+ autofocus={view.state.focusTarget === "status"}
65
+ >{view.state.status}</div>
66
+ {#if view.headline}<p data-emseepea-part="headline">{view.headline}</p>{/if}
67
+ {#if view.summary}<p data-emseepea-part="summary">{view.summary}</p>{/if}
68
+ {#if view.metrics.length}
69
+ <dl data-emseepea-part="metrics">
70
+ {#each view.metrics as metric (`${metric.label}:${metric.value}`)}
71
+ <div data-emseepea-part="metric">
72
+ <dt>{metric.label}{#if metric.hint} <span data-emseepea-part="hint">({metric.hint})</span>{/if}</dt>
73
+ <dd>{metric.value}</dd>
74
+ </div>
75
+ {/each}
76
+ </dl>
77
+ {/if}
78
+ {#if view.reasons}
79
+ <div data-emseepea-part="reasons">
80
+ <p id={`${prefix}--reasons-label`} data-emseepea-part="reasons-label">{view.reasons.label}</p>
81
+ <ul aria-labelledby={`${prefix}--reasons-label`}>
82
+ {#each view.reasons.items as item (item)}<li>{item}</li>{/each}
83
+ </ul>
84
+ </div>
85
+ {/if}
86
+ {#if view.assumptions}
87
+ <div data-emseepea-part="assumptions">
88
+ <p id={`${prefix}--assumptions-label`} data-emseepea-part="assumptions-label">{view.assumptions.label}</p>
89
+ <ul aria-labelledby={`${prefix}--assumptions-label`}>
90
+ {#each view.assumptions.items as item (item)}<li>{item}</li>{/each}
91
+ </ul>
92
+ </div>
93
+ {/if}
94
+ {#if view.disclosure}
95
+ <details data-emseepea-part="disclosure">
96
+ <summary>{view.disclosure.label}</summary>
97
+ <ul>{#each view.disclosure.items as item (item)}<li>{item}</li>{/each}</ul>
98
+ </details>
99
+ {/if}
100
+ {#if view.actions.length}
101
+ <div data-emseepea-part="actions" role="group" aria-label={view.actionsLabel}>
102
+ {#each view.actions as action (action.id)}
103
+ <button
104
+ type="button"
105
+ data-emseepea-part="action"
106
+ data-emseepea-action={action.id}
107
+ aria-label={action.accessibleName}
108
+ disabled={action.disabled}
109
+ autofocus={view.state.focusTarget === "actions" && !action.disabled && view.actions.findIndex((item) => !item.disabled) === view.actions.indexOf(action)}
110
+ onclick={() => onAction?.(action)}
111
+ >{action.label}</button>
112
+ {/each}
113
+ </div>
114
+ {/if}
115
+ <p data-emseepea-part="disclaimer">{view.disclaimer}</p>
116
+ </section>
package/src/index.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { ResultAction, ResultView, McpAppControllerOptions, McpAppState } from "@emseepea/server/ui";
2
+ import type { Component } from "svelte";
3
+ import type { Readable } from "svelte/store";
4
+
5
+ export interface ResultCardProps {
6
+ readonly view: ResultView;
7
+ readonly headingLevel: 2 | 3 | 4 | 5 | 6;
8
+ readonly onAction?: (action: ResultAction) => void;
9
+ readonly idPrefix?: string;
10
+ }
11
+
12
+ export const ResultCard: Component<ResultCardProps>;
13
+
14
+ export interface McpApp<Result> extends Readable<McpAppState<Result>> {
15
+ readonly sendMessage: (text: string) => Promise<void>;
16
+ }
17
+
18
+ export function createMcpApp<Result>(options: Omit<McpAppControllerOptions<Result>, "requestId">): McpApp<Result>;
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { default as ResultCard } from "./ResultCard.svelte";
2
+ export { createMcpApp } from "./mcp.js";
package/src/mcp.js ADDED
@@ -0,0 +1,15 @@
1
+ import { createMcpAppController } from "@emseepea/server/ui";
2
+ import { readable } from "svelte/store";
3
+
4
+ export function createMcpApp(options) {
5
+ const controller = createMcpAppController(options);
6
+ const state = readable(controller.getState(), (set) => {
7
+ const unsubscribe = controller.subscribe(() => set(controller.getState()));
8
+ const disconnect = typeof window === "undefined" ? undefined : controller.connect(window);
9
+ return () => {
10
+ unsubscribe();
11
+ disconnect?.();
12
+ };
13
+ });
14
+ return { subscribe: state.subscribe, sendMessage: controller.sendMessage };
15
+ }