@maxhealth.tech/prefab 0.1.2
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 +51 -0
- package/LICENSE +21 -0
- package/README.md +340 -0
- package/dist/actions/client.d.ts +98 -0
- package/dist/actions/client.d.ts.map +1 -0
- package/dist/actions/client.js +188 -0
- package/dist/actions/client.js.map +1 -0
- package/dist/actions/index.d.ts +6 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +3 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/mcp.d.ts +37 -0
- package/dist/actions/mcp.d.ts.map +1 -0
- package/dist/actions/mcp.js +64 -0
- package/dist/actions/mcp.js.map +1 -0
- package/dist/actions/types.d.ts +16 -0
- package/dist/actions/types.d.ts.map +1 -0
- package/dist/actions/types.js +8 -0
- package/dist/actions/types.js.map +1 -0
- package/dist/app.d.ts +65 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +120 -0
- package/dist/app.js.map +1 -0
- package/dist/auto/chart.d.ts +36 -0
- package/dist/auto/chart.d.ts.map +1 -0
- package/dist/auto/chart.js +50 -0
- package/dist/auto/chart.js.map +1 -0
- package/dist/auto/comparison.d.ts +32 -0
- package/dist/auto/comparison.d.ts.map +1 -0
- package/dist/auto/comparison.js +66 -0
- package/dist/auto/comparison.js.map +1 -0
- package/dist/auto/form.d.ts +50 -0
- package/dist/auto/form.d.ts.map +1 -0
- package/dist/auto/form.js +68 -0
- package/dist/auto/form.js.map +1 -0
- package/dist/auto/index.d.ts +84 -0
- package/dist/auto/index.d.ts.map +1 -0
- package/dist/auto/index.js +240 -0
- package/dist/auto/index.js.map +1 -0
- package/dist/auto/metrics.d.ts +44 -0
- package/dist/auto/metrics.d.ts.map +1 -0
- package/dist/auto/metrics.js +55 -0
- package/dist/auto/metrics.js.map +1 -0
- package/dist/auto/progress.d.ts +38 -0
- package/dist/auto/progress.d.ts.map +1 -0
- package/dist/auto/progress.js +72 -0
- package/dist/auto/progress.js.map +1 -0
- package/dist/auto/timeline.d.ts +41 -0
- package/dist/auto/timeline.d.ts.map +1 -0
- package/dist/auto/timeline.js +72 -0
- package/dist/auto/timeline.js.map +1 -0
- package/dist/components/alert/index.d.ts +14 -0
- package/dist/components/alert/index.d.ts.map +1 -0
- package/dist/components/alert/index.js +31 -0
- package/dist/components/alert/index.js.map +1 -0
- package/dist/components/card/index.d.ts +12 -0
- package/dist/components/card/index.d.ts.map +1 -0
- package/dist/components/card/index.js +33 -0
- package/dist/components/card/index.js.map +1 -0
- package/dist/components/charts/index.d.ts +57 -0
- package/dist/components/charts/index.d.ts.map +1 -0
- package/dist/components/charts/index.js +91 -0
- package/dist/components/charts/index.js.map +1 -0
- package/dist/components/control/index.d.ts +48 -0
- package/dist/components/control/index.d.ts.map +1 -0
- package/dist/components/control/index.js +47 -0
- package/dist/components/control/index.js.map +1 -0
- package/dist/components/data/index.d.ts +53 -0
- package/dist/components/data/index.d.ts.map +1 -0
- package/dist/components/data/index.js +88 -0
- package/dist/components/data/index.js.map +1 -0
- package/dist/components/form/index.d.ts +103 -0
- package/dist/components/form/index.d.ts.map +1 -0
- package/dist/components/form/index.js +247 -0
- package/dist/components/form/index.js.map +1 -0
- package/dist/components/interactive/index.d.ts +33 -0
- package/dist/components/interactive/index.d.ts.map +1 -0
- package/dist/components/interactive/index.js +59 -0
- package/dist/components/interactive/index.js.map +1 -0
- package/dist/components/layout/index.d.ts +61 -0
- package/dist/components/layout/index.d.ts.map +1 -0
- package/dist/components/layout/index.js +86 -0
- package/dist/components/layout/index.js.map +1 -0
- package/dist/components/media/index.d.ts +17 -0
- package/dist/components/media/index.d.ts.map +1 -0
- package/dist/components/media/index.js +41 -0
- package/dist/components/media/index.js.map +1 -0
- package/dist/components/table/index.d.ts +28 -0
- package/dist/components/table/index.d.ts.map +1 -0
- package/dist/components/table/index.js +56 -0
- package/dist/components/table/index.js.map +1 -0
- package/dist/components/typography/index.d.ts +34 -0
- package/dist/components/typography/index.d.ts.map +1 -0
- package/dist/components/typography/index.js +93 -0
- package/dist/components/typography/index.js.map +1 -0
- package/dist/core/component.d.ts +67 -0
- package/dist/core/component.d.ts.map +1 -0
- package/dist/core/component.js +122 -0
- package/dist/core/component.js.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/validate.d.ts +30 -0
- package/dist/core/validate.d.ts.map +1 -0
- package/dist/core/validate.js +178 -0
- package/dist/core/validate.js.map +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/display.d.ts +102 -0
- package/dist/mcp/display.d.ts.map +1 -0
- package/dist/mcp/display.js +124 -0
- package/dist/mcp/display.js.map +1 -0
- package/dist/mcp/index.d.ts +7 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +5 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/types.d.ts +35 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +8 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/renderer/actions.d.ts +36 -0
- package/dist/renderer/actions.d.ts.map +1 -0
- package/dist/renderer/actions.js +296 -0
- package/dist/renderer/actions.js.map +1 -0
- package/dist/renderer/app.d.ts +87 -0
- package/dist/renderer/app.d.ts.map +1 -0
- package/dist/renderer/app.js +166 -0
- package/dist/renderer/app.js.map +1 -0
- package/dist/renderer/bridge.d.ts +91 -0
- package/dist/renderer/bridge.d.ts.map +1 -0
- package/dist/renderer/bridge.js +302 -0
- package/dist/renderer/bridge.js.map +1 -0
- package/dist/renderer/components/alert.d.ts +5 -0
- package/dist/renderer/components/alert.d.ts.map +1 -0
- package/dist/renderer/components/alert.js +44 -0
- package/dist/renderer/components/alert.js.map +1 -0
- package/dist/renderer/components/card.d.ts +5 -0
- package/dist/renderer/components/card.d.ts.map +1 -0
- package/dist/renderer/components/card.js +38 -0
- package/dist/renderer/components/card.js.map +1 -0
- package/dist/renderer/components/charts.d.ts +8 -0
- package/dist/renderer/components/charts.d.ts.map +1 -0
- package/dist/renderer/components/charts.js +232 -0
- package/dist/renderer/components/charts.js.map +1 -0
- package/dist/renderer/components/control.d.ts +5 -0
- package/dist/renderer/components/control.d.ts.map +1 -0
- package/dist/renderer/components/control.js +140 -0
- package/dist/renderer/components/control.js.map +1 -0
- package/dist/renderer/components/data.d.ts +5 -0
- package/dist/renderer/components/data.d.ts.map +1 -0
- package/dist/renderer/components/data.js +268 -0
- package/dist/renderer/components/data.js.map +1 -0
- package/dist/renderer/components/form.d.ts +5 -0
- package/dist/renderer/components/form.d.ts.map +1 -0
- package/dist/renderer/components/form.js +523 -0
- package/dist/renderer/components/form.js.map +1 -0
- package/dist/renderer/components/index.d.ts +5 -0
- package/dist/renderer/components/index.d.ts.map +1 -0
- package/dist/renderer/components/index.js +32 -0
- package/dist/renderer/components/index.js.map +1 -0
- package/dist/renderer/components/interactive.d.ts +5 -0
- package/dist/renderer/components/interactive.d.ts.map +1 -0
- package/dist/renderer/components/interactive.js +324 -0
- package/dist/renderer/components/interactive.js.map +1 -0
- package/dist/renderer/components/layout.d.ts +5 -0
- package/dist/renderer/components/layout.d.ts.map +1 -0
- package/dist/renderer/components/layout.js +113 -0
- package/dist/renderer/components/layout.js.map +1 -0
- package/dist/renderer/components/media.d.ts +5 -0
- package/dist/renderer/components/media.d.ts.map +1 -0
- package/dist/renderer/components/media.js +132 -0
- package/dist/renderer/components/media.js.map +1 -0
- package/dist/renderer/components/table.d.ts +5 -0
- package/dist/renderer/components/table.d.ts.map +1 -0
- package/dist/renderer/components/table.js +101 -0
- package/dist/renderer/components/table.js.map +1 -0
- package/dist/renderer/components/typography.d.ts +5 -0
- package/dist/renderer/components/typography.d.ts.map +1 -0
- package/dist/renderer/components/typography.js +90 -0
- package/dist/renderer/components/typography.js.map +1 -0
- package/dist/renderer/engine.d.ts +53 -0
- package/dist/renderer/engine.d.ts.map +1 -0
- package/dist/renderer/engine.js +112 -0
- package/dist/renderer/engine.js.map +1 -0
- package/dist/renderer/index.d.ts +94 -0
- package/dist/renderer/index.d.ts.map +1 -0
- package/dist/renderer/index.js +215 -0
- package/dist/renderer/index.js.map +1 -0
- package/dist/renderer/rx.d.ts +37 -0
- package/dist/renderer/rx.d.ts.map +1 -0
- package/dist/renderer/rx.js +360 -0
- package/dist/renderer/rx.js.map +1 -0
- package/dist/renderer/state.d.ts +34 -0
- package/dist/renderer/state.d.ts.map +1 -0
- package/dist/renderer/state.js +132 -0
- package/dist/renderer/state.js.map +1 -0
- package/dist/renderer/theme.d.ts +13 -0
- package/dist/renderer/theme.d.ts.map +1 -0
- package/dist/renderer/theme.js +69 -0
- package/dist/renderer/theme.js.map +1 -0
- package/dist/renderer/transport.d.ts +22 -0
- package/dist/renderer/transport.d.ts.map +1 -0
- package/dist/renderer/transport.js +69 -0
- package/dist/renderer/transport.js.map +1 -0
- package/dist/renderer.min.js +83 -0
- package/dist/rx/index.d.ts +2 -0
- package/dist/rx/index.d.ts.map +1 -0
- package/dist/rx/index.js +2 -0
- package/dist/rx/index.js.map +1 -0
- package/dist/rx/rx.d.ts +81 -0
- package/dist/rx/rx.d.ts.map +1 -0
- package/dist/rx/rx.js +196 -0
- package/dist/rx/rx.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Display Helpers — return prefab UIs as MCP tool results.
|
|
3
|
+
*
|
|
4
|
+
* These functions wrap PrefabApp / Component trees into MCP-compatible
|
|
5
|
+
* tool result content arrays, ready to return from tool handlers.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { display, display_error } from '@maxhealth.tech/prefab/mcp'
|
|
10
|
+
* import { autoTable } from '@maxhealth.tech/prefab'
|
|
11
|
+
*
|
|
12
|
+
* // In a FastMCP tool handler:
|
|
13
|
+
* async function listPatients(args, context) {
|
|
14
|
+
* const patients = await fetchPatients()
|
|
15
|
+
* return display(autoTable(patients), { title: 'Patient List' })
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
import {} from '../core/component.js';
|
|
20
|
+
import { PrefabApp } from '../app.js';
|
|
21
|
+
/**
|
|
22
|
+
* Wrap a Component (or PrefabApp) as an MCP tool result.
|
|
23
|
+
*
|
|
24
|
+
* If given a Component, it's wrapped in a PrefabApp automatically.
|
|
25
|
+
* If given a PrefabApp, it's serialized as-is.
|
|
26
|
+
*
|
|
27
|
+
* @returns MCP tool result with the prefab wire format JSON as text content.
|
|
28
|
+
*/
|
|
29
|
+
export function display(viewOrApp, options) {
|
|
30
|
+
const app = viewOrApp instanceof PrefabApp
|
|
31
|
+
? viewOrApp
|
|
32
|
+
: new PrefabApp({
|
|
33
|
+
title: options?.title ?? 'Prefab',
|
|
34
|
+
view: viewOrApp,
|
|
35
|
+
state: options?.state,
|
|
36
|
+
theme: options?.theme,
|
|
37
|
+
defs: options?.defs,
|
|
38
|
+
onMount: options?.onMount,
|
|
39
|
+
keyBindings: options?.keyBindings,
|
|
40
|
+
cssClass: options?.cssClass,
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
content: [{ type: 'text', text: JSON.stringify(app.toJSON()) }],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// ── display_form() ───────────────────────────────────────────────────────────
|
|
47
|
+
import { autoForm } from '../auto/form.js';
|
|
48
|
+
/**
|
|
49
|
+
* Return a form UI as an MCP tool result.
|
|
50
|
+
*
|
|
51
|
+
* The form submits back to the specified MCP tool via CallTool.
|
|
52
|
+
* Field definitions map to Input components; the submit action
|
|
53
|
+
* invokes `submitTool` with all field values.
|
|
54
|
+
*
|
|
55
|
+
* @returns MCP tool result with form prefab UI.
|
|
56
|
+
*/
|
|
57
|
+
export function display_form(fields, submitTool, options) {
|
|
58
|
+
const view = autoForm(fields, submitTool, options);
|
|
59
|
+
const app = new PrefabApp({
|
|
60
|
+
title: options?.title ?? 'Form',
|
|
61
|
+
view,
|
|
62
|
+
state: options?.state,
|
|
63
|
+
theme: options?.theme,
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
content: [{ type: 'text', text: JSON.stringify(app.toJSON()) }],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Return a partial state update for an existing prefab UI.
|
|
71
|
+
*
|
|
72
|
+
* Instead of re-rendering the entire UI, this sends a state delta
|
|
73
|
+
* that the renderer merges into its reactive store.
|
|
74
|
+
*
|
|
75
|
+
* @returns MCP tool result with a $prefab update payload.
|
|
76
|
+
*/
|
|
77
|
+
export function display_update(state) {
|
|
78
|
+
const payload = {
|
|
79
|
+
$prefab: { version: '0.2' },
|
|
80
|
+
update: { state },
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
content: [{ type: 'text', text: JSON.stringify(payload) }],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// ── display_error() ──────────────────────────────────────────────────────────
|
|
87
|
+
import { Column } from '../components/layout/index.js';
|
|
88
|
+
import { Muted, Code } from '../components/typography/index.js';
|
|
89
|
+
import { Alert, AlertTitle, AlertDescription } from '../components/alert/index.js';
|
|
90
|
+
import { Card, CardContent } from '../components/card/index.js';
|
|
91
|
+
/**
|
|
92
|
+
* Return a standardized error view as an MCP tool result.
|
|
93
|
+
*
|
|
94
|
+
* Renders a destructive Alert with title + message, optional detail
|
|
95
|
+
* code block, and optional hint. Sets `isError: true` on the MCP result.
|
|
96
|
+
*
|
|
97
|
+
* @returns MCP tool result with error UI and isError flag.
|
|
98
|
+
*/
|
|
99
|
+
export function display_error(title, message, options) {
|
|
100
|
+
const alertChildren = [
|
|
101
|
+
AlertTitle(title),
|
|
102
|
+
AlertDescription(message),
|
|
103
|
+
];
|
|
104
|
+
const bodyChildren = [
|
|
105
|
+
Alert({ variant: 'destructive', icon: 'AlertCircle', children: alertChildren }),
|
|
106
|
+
];
|
|
107
|
+
if (options?.detail) {
|
|
108
|
+
bodyChildren.push(Card({ children: [CardContent({ children: [Code(options.detail)] })] }));
|
|
109
|
+
}
|
|
110
|
+
if (options?.hint) {
|
|
111
|
+
bodyChildren.push(Muted(options.hint));
|
|
112
|
+
}
|
|
113
|
+
const view = Column({ gap: 4, cssClass: 'p-6 max-w-2xl', children: bodyChildren });
|
|
114
|
+
const app = new PrefabApp({
|
|
115
|
+
title: 'Error',
|
|
116
|
+
view,
|
|
117
|
+
theme: options?.theme,
|
|
118
|
+
});
|
|
119
|
+
return {
|
|
120
|
+
content: [{ type: 'text', text: JSON.stringify(app.toJSON()) }],
|
|
121
|
+
isError: true,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=display.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display.js","sourceRoot":"","sources":["../../src/mcp/display.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAkB,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAwBrC;;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,CACrB,SAAgC,EAChC,OAAwB;IAExB,MAAM,GAAG,GAAG,SAAS,YAAY,SAAS;QACxC,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,IAAI,SAAS,CAAC;YACZ,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,QAAQ;YACjC,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,OAAO,EAAE,KAAK;YACrB,KAAK,EAAE,OAAO,EAAE,KAAK;YACrB,IAAI,EAAE,OAAO,EAAE,IAAI;YACnB,OAAO,EAAE,OAAO,EAAE,OAAO;YACzB,WAAW,EAAE,OAAO,EAAE,WAAW;YACjC,QAAQ,EAAE,OAAO,EAAE,QAAQ;SAC5B,CAAC,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AO,EAAE,IAAI;KACd,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP display helpers — return prefab UIs as MCP tool results.
|
|
3
|
+
*/
|
|
4
|
+
export { display, display_form, display_update, display_error } from './display.js';
|
|
5
|
+
export type { DisplayOptions, DisplayFormOptions, DisplayErrorOptions, StateUpdate, PrefabUpdateWire, } from './display.js';
|
|
6
|
+
export type { McpToolResult, McpContent, McpTextContent, McpImageContent, McpResourceContent } from './types.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AACnF,YAAY,EACV,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,WAAW,EACX,gBAAgB,GACjB,MAAM,cAAc,CAAA;AACrB,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP protocol types used by display helpers.
|
|
3
|
+
*
|
|
4
|
+
* These match the Model Context Protocol spec for tool results.
|
|
5
|
+
* @see https://spec.modelcontextprotocol.io/specification/server/tools/
|
|
6
|
+
*/
|
|
7
|
+
/** MCP text content block */
|
|
8
|
+
export interface McpTextContent {
|
|
9
|
+
type: 'text';
|
|
10
|
+
text: string;
|
|
11
|
+
}
|
|
12
|
+
/** MCP image content block */
|
|
13
|
+
export interface McpImageContent {
|
|
14
|
+
type: 'image';
|
|
15
|
+
data: string;
|
|
16
|
+
mimeType: string;
|
|
17
|
+
}
|
|
18
|
+
/** MCP embedded resource content block */
|
|
19
|
+
export interface McpResourceContent {
|
|
20
|
+
type: 'resource';
|
|
21
|
+
resource: {
|
|
22
|
+
uri: string;
|
|
23
|
+
mimeType?: string;
|
|
24
|
+
text?: string;
|
|
25
|
+
blob?: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** Any MCP content block */
|
|
29
|
+
export type McpContent = McpTextContent | McpImageContent | McpResourceContent;
|
|
30
|
+
/** MCP tool result — returned from tool handlers */
|
|
31
|
+
export interface McpToolResult {
|
|
32
|
+
content: McpContent[];
|
|
33
|
+
isError?: boolean;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/mcp/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,6BAA6B;AAC7B,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb;AAED,8BAA8B;AAC9B,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,OAAO,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,0CAA0C;AAC1C,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,UAAU,CAAA;IAChB,QAAQ,EAAE;QACR,GAAG,EAAE,MAAM,CAAA;QACX,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;CACF;AAED,4BAA4B;AAC5B,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,eAAe,GAAG,kBAAkB,CAAA;AAE9E,oDAAoD;AACpD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,UAAU,EAAE,CAAA;IACrB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/mcp/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Action dispatcher — executes serialized actions at runtime.
|
|
3
|
+
*
|
|
4
|
+
* Client actions (setState, showToast, etc.) run locally.
|
|
5
|
+
* MCP actions (toolCall, sendMessage) delegate to the transport layer.
|
|
6
|
+
*/
|
|
7
|
+
import type { Store } from './state.js';
|
|
8
|
+
import type { EvalScope } from './rx.js';
|
|
9
|
+
/** MCP transport interface — injected at mount time */
|
|
10
|
+
export interface McpTransport {
|
|
11
|
+
callTool(name: string, args: Record<string, unknown>): Promise<unknown>;
|
|
12
|
+
sendMessage(message: string): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
/** Toast event — emitted for showToast actions */
|
|
15
|
+
export interface ToastEvent {
|
|
16
|
+
message: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
variant?: string;
|
|
19
|
+
duration?: number;
|
|
20
|
+
}
|
|
21
|
+
/** Action dispatcher context */
|
|
22
|
+
export interface DispatchContext {
|
|
23
|
+
store: Store;
|
|
24
|
+
transport?: McpTransport;
|
|
25
|
+
scope?: EvalScope;
|
|
26
|
+
rerender: () => void;
|
|
27
|
+
onToast?: (toast: ToastEvent) => void;
|
|
28
|
+
}
|
|
29
|
+
export type ActionJSON = Record<string, unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* Dispatch one or more serialized actions.
|
|
32
|
+
*/
|
|
33
|
+
export declare function dispatchActions(actions: ActionJSON | ActionJSON[], ctx: DispatchContext): Promise<void>;
|
|
34
|
+
/** Clear all active intervals (called on destroy). */
|
|
35
|
+
export declare function clearAllIntervals(): void;
|
|
36
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/renderer/actions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAGxC,uDAAuD;AACvD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACvE,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC5C;AAED,kDAAkD;AAClD,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,gCAAgC;AAChC,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,KAAK,CAAA;IACZ,SAAS,CAAC,EAAE,YAAY,CAAA;IACxB,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;CACtC;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEhD;;GAEG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,UAAU,GAAG,UAAU,EAAE,EAClC,GAAG,EAAE,eAAe,GACnB,OAAO,CAAC,IAAI,CAAC,CAKf;AAoHD,sDAAsD;AACtD,wBAAgB,iBAAiB,IAAI,IAAI,CAGxC"}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Action dispatcher — executes serialized actions at runtime.
|
|
3
|
+
*
|
|
4
|
+
* Client actions (setState, showToast, etc.) run locally.
|
|
5
|
+
* MCP actions (toolCall, sendMessage) delegate to the transport layer.
|
|
6
|
+
*/
|
|
7
|
+
import { evaluateTemplate, isRxExpression } from './rx.js';
|
|
8
|
+
/**
|
|
9
|
+
* Dispatch one or more serialized actions.
|
|
10
|
+
*/
|
|
11
|
+
export async function dispatchActions(actions, ctx) {
|
|
12
|
+
const list = Array.isArray(actions) ? actions : [actions];
|
|
13
|
+
for (const action of list) {
|
|
14
|
+
await dispatchOne(action, ctx);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function dispatchOne(action, ctx) {
|
|
18
|
+
const type = action.action;
|
|
19
|
+
switch (type) {
|
|
20
|
+
case 'setState':
|
|
21
|
+
{
|
|
22
|
+
handleSetState(action, ctx);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
case 'toggleState':
|
|
26
|
+
{
|
|
27
|
+
handleToggleState(action, ctx);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
case 'appendState':
|
|
31
|
+
{
|
|
32
|
+
handleAppendState(action, ctx);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
case 'popState':
|
|
36
|
+
{
|
|
37
|
+
handlePopState(action, ctx);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
case 'showToast':
|
|
41
|
+
{
|
|
42
|
+
handleShowToast(action, ctx);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
case 'closeOverlay':
|
|
46
|
+
{
|
|
47
|
+
handleCloseOverlay(action, ctx);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
case 'openLink':
|
|
51
|
+
{
|
|
52
|
+
handleOpenLink(action);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
case 'setInterval':
|
|
56
|
+
{
|
|
57
|
+
handleSetInterval(action, ctx);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
case 'toolCall':
|
|
61
|
+
return handleToolCall(action, ctx);
|
|
62
|
+
case 'sendMessage':
|
|
63
|
+
return handleSendMessage(action, ctx);
|
|
64
|
+
case 'updateContext':
|
|
65
|
+
{
|
|
66
|
+
handleUpdateContext(action, ctx);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
case 'fetch':
|
|
70
|
+
return handleFetch(action, ctx);
|
|
71
|
+
case 'openFilePicker':
|
|
72
|
+
{
|
|
73
|
+
handleOpenFilePicker(action, ctx);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
case 'callHandler':
|
|
77
|
+
return handleCallHandler(action, ctx);
|
|
78
|
+
case 'requestDisplayMode':
|
|
79
|
+
{
|
|
80
|
+
handleRequestDisplayMode(action, ctx);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
default:
|
|
84
|
+
console.warn(`[prefab] Unknown action: ${type}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// ── Client Actions ───────────────────────────────────────────────────────────
|
|
88
|
+
function handleSetState(action, ctx) {
|
|
89
|
+
const key = action.key;
|
|
90
|
+
let value = action.value;
|
|
91
|
+
if (isRxExpression(value)) {
|
|
92
|
+
value = evaluateTemplate(value, ctx.store, ctx.scope);
|
|
93
|
+
}
|
|
94
|
+
ctx.store.set(key, value);
|
|
95
|
+
ctx.rerender();
|
|
96
|
+
void runCallbacks(action.onSuccess, ctx);
|
|
97
|
+
}
|
|
98
|
+
function handleToggleState(action, ctx) {
|
|
99
|
+
ctx.store.toggle(action.key);
|
|
100
|
+
ctx.rerender();
|
|
101
|
+
}
|
|
102
|
+
function handleAppendState(action, ctx) {
|
|
103
|
+
let value = action.value;
|
|
104
|
+
if (isRxExpression(value)) {
|
|
105
|
+
value = evaluateTemplate(value, ctx.store, ctx.scope);
|
|
106
|
+
}
|
|
107
|
+
ctx.store.append(action.key, value, action.index);
|
|
108
|
+
ctx.rerender();
|
|
109
|
+
}
|
|
110
|
+
function handlePopState(action, ctx) {
|
|
111
|
+
ctx.store.pop(action.key, action.index);
|
|
112
|
+
ctx.rerender();
|
|
113
|
+
}
|
|
114
|
+
function handleShowToast(action, ctx) {
|
|
115
|
+
ctx.onToast?.({
|
|
116
|
+
message: resolveStr(action.message, ctx),
|
|
117
|
+
description: action.description != null ? resolveStr(action.description, ctx) : undefined,
|
|
118
|
+
variant: action.variant,
|
|
119
|
+
duration: action.duration,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function handleCloseOverlay(_action, _ctx) {
|
|
123
|
+
// Close any open dialog/popover — dispatched as custom event
|
|
124
|
+
if (typeof document !== 'undefined') {
|
|
125
|
+
document.dispatchEvent(new CustomEvent('prefab:close-overlay'));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function handleOpenLink(action) {
|
|
129
|
+
if (typeof window !== 'undefined') {
|
|
130
|
+
const url = action.url;
|
|
131
|
+
if (!isSafeUrl(url)) {
|
|
132
|
+
console.warn(`[prefab] Blocked unsafe URL scheme: ${url}`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
window.open(url, action.target ?? '_blank');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/** Active interval IDs for cleanup. */
|
|
139
|
+
const activeIntervals = new Set();
|
|
140
|
+
const MAX_INTERVALS = 20;
|
|
141
|
+
const MIN_INTERVAL_MS = 100;
|
|
142
|
+
function handleSetInterval(action, ctx) {
|
|
143
|
+
const ms = Math.max(action.intervalMs, MIN_INTERVAL_MS);
|
|
144
|
+
const onTick = action.onTick;
|
|
145
|
+
if (typeof globalThis.setInterval !== 'function')
|
|
146
|
+
return;
|
|
147
|
+
if (activeIntervals.size >= MAX_INTERVALS) {
|
|
148
|
+
console.warn('[prefab] Max intervals reached, ignoring new setInterval');
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const id = globalThis.setInterval(() => void dispatchActions(onTick, ctx), ms);
|
|
152
|
+
activeIntervals.add(id);
|
|
153
|
+
}
|
|
154
|
+
/** Clear all active intervals (called on destroy). */
|
|
155
|
+
export function clearAllIntervals() {
|
|
156
|
+
for (const id of activeIntervals)
|
|
157
|
+
globalThis.clearInterval(id);
|
|
158
|
+
activeIntervals.clear();
|
|
159
|
+
}
|
|
160
|
+
// ── MCP Actions ──────────────────────────────────────────────────────────────
|
|
161
|
+
async function handleToolCall(action, ctx) {
|
|
162
|
+
if (!ctx.transport) {
|
|
163
|
+
console.warn('[prefab] No MCP transport configured for toolCall');
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const tool = action.tool;
|
|
167
|
+
const args = resolveArgs(action.arguments, ctx);
|
|
168
|
+
try {
|
|
169
|
+
const result = await ctx.transport.callTool(tool, args);
|
|
170
|
+
if (action.resultKey != null) {
|
|
171
|
+
ctx.store.set(action.resultKey, result);
|
|
172
|
+
}
|
|
173
|
+
ctx.rerender();
|
|
174
|
+
await runCallbacks(action.onSuccess, ctx, { $result: result });
|
|
175
|
+
}
|
|
176
|
+
catch (err) {
|
|
177
|
+
await runCallbacks(action.onError, ctx, { $error: err });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async function handleSendMessage(action, ctx) {
|
|
181
|
+
if (!ctx.transport) {
|
|
182
|
+
console.warn('[prefab] No MCP transport configured for sendMessage');
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
await ctx.transport.sendMessage(resolveStr(action.message, ctx));
|
|
186
|
+
}
|
|
187
|
+
function handleUpdateContext(action, ctx) {
|
|
188
|
+
const context = action.context;
|
|
189
|
+
if (context != null) {
|
|
190
|
+
ctx.store.merge(context);
|
|
191
|
+
ctx.rerender();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
async function handleFetch(action, ctx) {
|
|
195
|
+
const url = resolveStr(action.url, ctx);
|
|
196
|
+
if (!isSafeUrl(url)) {
|
|
197
|
+
console.warn(`[prefab] Blocked unsafe URL in fetch: ${url}`);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const method = action.method ?? 'GET';
|
|
201
|
+
const headers = action.headers;
|
|
202
|
+
const body = action.body !== undefined ? JSON.stringify(action.body) : undefined;
|
|
203
|
+
try {
|
|
204
|
+
const resp = await globalThis.fetch(url, {
|
|
205
|
+
method,
|
|
206
|
+
headers: { 'Content-Type': 'application/json', ...headers },
|
|
207
|
+
...(body && { body }),
|
|
208
|
+
});
|
|
209
|
+
const result = await resp.json().catch(() => resp.text());
|
|
210
|
+
if (action.resultKey != null) {
|
|
211
|
+
ctx.store.set(action.resultKey, result);
|
|
212
|
+
}
|
|
213
|
+
ctx.rerender();
|
|
214
|
+
await runCallbacks(action.onSuccess, ctx, { $result: result });
|
|
215
|
+
}
|
|
216
|
+
catch (err) {
|
|
217
|
+
await runCallbacks(action.onError, ctx, { $error: err });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function handleOpenFilePicker(action, ctx) {
|
|
221
|
+
if (typeof document === 'undefined')
|
|
222
|
+
return;
|
|
223
|
+
const input = document.createElement('input');
|
|
224
|
+
input.type = 'file';
|
|
225
|
+
if (action.accept != null)
|
|
226
|
+
input.accept = action.accept;
|
|
227
|
+
if (action.multiple === true)
|
|
228
|
+
input.multiple = true;
|
|
229
|
+
input.addEventListener('change', () => {
|
|
230
|
+
const files = Array.from(input.files ?? []);
|
|
231
|
+
if (action.resultKey != null) {
|
|
232
|
+
ctx.store.set(action.resultKey, files);
|
|
233
|
+
}
|
|
234
|
+
ctx.rerender();
|
|
235
|
+
void runCallbacks(action.onSuccess, ctx, { $result: files });
|
|
236
|
+
});
|
|
237
|
+
input.click();
|
|
238
|
+
}
|
|
239
|
+
async function handleCallHandler(action, ctx) {
|
|
240
|
+
const handler = action.handler;
|
|
241
|
+
const args = resolveArgs(action.arguments, ctx);
|
|
242
|
+
// callHandler delegates to the transport like toolCall
|
|
243
|
+
if (!ctx.transport) {
|
|
244
|
+
console.warn(`[prefab] No transport configured for callHandler: ${handler}`);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
try {
|
|
248
|
+
const result = await ctx.transport.callTool(handler, args);
|
|
249
|
+
if (action.resultKey != null) {
|
|
250
|
+
ctx.store.set(action.resultKey, result);
|
|
251
|
+
}
|
|
252
|
+
ctx.rerender();
|
|
253
|
+
await runCallbacks(action.onSuccess, ctx, { $result: result });
|
|
254
|
+
}
|
|
255
|
+
catch (err) {
|
|
256
|
+
await runCallbacks(action.onError, ctx, { $error: err });
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function handleRequestDisplayMode(action, _ctx) {
|
|
260
|
+
if (typeof document !== 'undefined') {
|
|
261
|
+
document.dispatchEvent(new CustomEvent('prefab:request-display-mode', {
|
|
262
|
+
detail: { mode: action.mode },
|
|
263
|
+
}));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
267
|
+
/** Blocked URL schemes that can execute code. */
|
|
268
|
+
const UNSAFE_SCHEME_RE = /^\s*(javascript|vbscript|data):/i;
|
|
269
|
+
function isSafeUrl(url) {
|
|
270
|
+
return !UNSAFE_SCHEME_RE.test(url);
|
|
271
|
+
}
|
|
272
|
+
function resolveStr(val, ctx) {
|
|
273
|
+
if (isRxExpression(val)) {
|
|
274
|
+
const result = evaluateTemplate(val, ctx.store, ctx.scope);
|
|
275
|
+
return result == null ? '' : String(result);
|
|
276
|
+
}
|
|
277
|
+
return val == null ? '' : String(val);
|
|
278
|
+
}
|
|
279
|
+
function resolveArgs(args, ctx) {
|
|
280
|
+
if (!args)
|
|
281
|
+
return {};
|
|
282
|
+
const resolved = {};
|
|
283
|
+
for (const [key, value] of Object.entries(args)) {
|
|
284
|
+
resolved[key] = isRxExpression(value)
|
|
285
|
+
? evaluateTemplate(value, ctx.store, ctx.scope)
|
|
286
|
+
: value;
|
|
287
|
+
}
|
|
288
|
+
return resolved;
|
|
289
|
+
}
|
|
290
|
+
async function runCallbacks(callbacks, ctx, extraScope) {
|
|
291
|
+
if (callbacks == null)
|
|
292
|
+
return;
|
|
293
|
+
const merged = { ...ctx.scope, ...extraScope };
|
|
294
|
+
await dispatchActions(callbacks, { ...ctx, scope: merged });
|
|
295
|
+
}
|
|
296
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/renderer/actions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AA2B1D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAAkC,EAClC,GAAoB;IAEpB,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;IACzD,KAAK,MAAM,MAAM,IAAI,IAAI,EAAE,CAAC;QAC1B,MAAM,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAChC,CAAC;AACH,CAAC;AAED,KAAK,UAAU,WAAW,CAAC,MAAkB,EAAE,GAAoB;IACjE,MAAM,IAAI,GAAG,MAAM,CAAC,MAAgB,CAAA;IACpC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,UAAU;YACb,CAAC;gBAAC,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;gBAAC,OAAO;YAAC,CAAC;QAC1C,KAAK,aAAa;YAChB,CAAC;gBAAC,iBAAiB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;gBAAC,OAAO;YAAC,CAAC;QAC7C,KAAK,aAAa;YAChB,CAAC;gBAAC,iBAAiB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;gBAAC,OAAO;YAAC,CAAC;QAC7C,KAAK,UAAU;YACb,CAAC;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AE,OAAO,EAAE,CAAA;IACpB,MAAM,QAAQ,GAA4B,EAAE,CAAA;IAC5C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,QAAQ,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC;YACnC,CAAC,CAAC,gBAAgB,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC;YAC/C,CAAC,CAAC,KAAK,CAAA;IACX,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,KAAK,UAAU,YAAY,CACzB,SAAkB,EAClB,GAAoB,EACpB,UAAsB;IAEtB,IAAI,SAAS,IAAI,IAAI;QAAE,OAAM;IAC7B,MAAM,MAAM,GAAG,EAAE,GAAG,GAAG,CAAC,KAAK,EAAE,GAAG,UAAU,EAAE,CAAA;IAC9C,MAAM,eAAe,CACnB,SAAsC,EACtC,EAAE,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,CAC1B,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* app() factory — the one-call entry point for prefab apps.
|
|
3
|
+
*
|
|
4
|
+
* Auto-detects environment (iframe → postMessage bridge, standalone → HTTP transport),
|
|
5
|
+
* performs handshake if in iframe, applies host theme, and returns a clean API object.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```ts
|
|
9
|
+
* const ui = await prefab.app();
|
|
10
|
+
*
|
|
11
|
+
* ui.onToolInput((args) => {
|
|
12
|
+
* ui.render('#root', Column(
|
|
13
|
+
* H1('Results'),
|
|
14
|
+
* autoTable(args.data),
|
|
15
|
+
* ));
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
import type { PrefabWireData, MountOptions, MountedApp } from './index.js';
|
|
20
|
+
import type { AppCapabilities, HostContext, HostCapabilities, HostTheme, DisplayMode } from './bridge.js';
|
|
21
|
+
import type { McpTransportOptions } from './transport.js';
|
|
22
|
+
import type { McpTransport } from './actions.js';
|
|
23
|
+
import { Store } from './state.js';
|
|
24
|
+
import type { ComponentNode } from './engine.js';
|
|
25
|
+
export interface AppOptions {
|
|
26
|
+
/** Override environment detection: force bridge or standalone mode. */
|
|
27
|
+
mode?: 'bridge' | 'standalone' | 'auto';
|
|
28
|
+
/** Allowed host origin for postMessage (default: '*'). Set explicitly in production. */
|
|
29
|
+
hostOrigin?: string;
|
|
30
|
+
/** HTTP transport options (for standalone mode). */
|
|
31
|
+
transport?: McpTransportOptions;
|
|
32
|
+
/** App capabilities to advertise to host. */
|
|
33
|
+
capabilities?: AppCapabilities;
|
|
34
|
+
}
|
|
35
|
+
export type ToolInputHandler = (args: Record<string, unknown>) => void;
|
|
36
|
+
export type ToolResultHandler = (result: unknown) => void;
|
|
37
|
+
export type VoidHandler = () => void;
|
|
38
|
+
export interface PrefabApp {
|
|
39
|
+
/** Call an MCP tool through the transport. */
|
|
40
|
+
callTool: (name: string, args?: Record<string, unknown>) => Promise<unknown>;
|
|
41
|
+
/** Send a message through the transport. */
|
|
42
|
+
sendMessage: (message: string) => Promise<void>;
|
|
43
|
+
/** Register a handler for tool input from the host. */
|
|
44
|
+
onToolInput: (handler: ToolInputHandler) => void;
|
|
45
|
+
/** Register a handler for tool results from the host. */
|
|
46
|
+
onToolResult: (handler: ToolResultHandler) => void;
|
|
47
|
+
/** Register a handler for tool cancellation. */
|
|
48
|
+
onToolCancelled: (handler: VoidHandler) => void;
|
|
49
|
+
/** Register a handler for partial/streaming tool input. */
|
|
50
|
+
onToolInputPartial: (handler: ToolInputHandler) => void;
|
|
51
|
+
/** Render a component tree into a DOM element. */
|
|
52
|
+
render: (target: string | HTMLElement, ...components: ComponentNode[]) => MountHandle;
|
|
53
|
+
/** Mount full wire-format data (legacy API). */
|
|
54
|
+
mount: (target: string | HTMLElement, data: PrefabWireData, opts?: MountOptions) => MountedApp;
|
|
55
|
+
/** Request a display mode change. */
|
|
56
|
+
requestMode: (mode: DisplayMode) => void;
|
|
57
|
+
/** Request the host to open a URL. */
|
|
58
|
+
openLink: (url: string, target?: string) => void;
|
|
59
|
+
/** Send context updates. */
|
|
60
|
+
updateContext: (context: Record<string, unknown>) => void;
|
|
61
|
+
/** Host context from initialization. */
|
|
62
|
+
host: HostContext;
|
|
63
|
+
/** Host capabilities. */
|
|
64
|
+
capabilities: HostCapabilities;
|
|
65
|
+
/** Host theme (if provided). */
|
|
66
|
+
theme: HostTheme | undefined;
|
|
67
|
+
/** The underlying MCP transport. */
|
|
68
|
+
transport: McpTransport;
|
|
69
|
+
/** Destroy the app and clean up. */
|
|
70
|
+
destroy: () => void;
|
|
71
|
+
}
|
|
72
|
+
export interface MountHandle {
|
|
73
|
+
/** Re-render the current component tree. */
|
|
74
|
+
rerender: () => void;
|
|
75
|
+
/** Access the reactive store. */
|
|
76
|
+
store: Store;
|
|
77
|
+
/** Unmount. */
|
|
78
|
+
destroy: () => void;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a prefab app. Auto-detects iframe vs standalone.
|
|
82
|
+
*
|
|
83
|
+
* In an iframe: uses postMessage bridge, performs handshake with host.
|
|
84
|
+
* Standalone: uses HTTP transport (or noop if no config).
|
|
85
|
+
*/
|
|
86
|
+
export declare function app(options?: AppOptions): Promise<PrefabApp>;
|
|
87
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/renderer/app.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE1E,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,WAAW,EACZ,MAAM,aAA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