@frontmcp/react 1.11.2 → 1.12.0-rc.1
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/ai/createToolHandler.d.ts +1 -1
- package/ai/createToolHandler.d.ts.map +1 -1
- package/ai/types.d.ts +2 -2
- package/ai/types.d.ts.map +1 -1
- package/ai/useAITools.d.ts +1 -1
- package/ai/useAITools.d.ts.map +1 -1
- package/ai/useTools.d.ts +1 -1
- package/ai/useTools.d.ts.map +1 -1
- package/components/AgentContent.d.ts +1 -2
- package/components/AgentContent.d.ts.map +1 -1
- package/components/AgentSearch.d.ts +1 -2
- package/components/AgentSearch.d.ts.map +1 -1
- package/components/DynamicRenderer.d.ts.map +1 -1
- package/components/PromptForm.d.ts +1 -1
- package/components/PromptForm.d.ts.map +1 -1
- package/esm/ai/index.mjs +5 -3
- package/esm/index.mjs +153 -22
- package/esm/package.json +6 -6
- package/esm/router/index.mjs +451 -12
- package/events/createRemoteEventForwarder.d.ts +36 -0
- package/events/createRemoteEventForwarder.d.ts.map +1 -0
- package/events/index.d.ts +3 -0
- package/events/index.d.ts.map +1 -0
- package/hooks/index.d.ts +5 -0
- package/hooks/index.d.ts.map +1 -1
- package/hooks/useCallTool.d.ts.map +1 -1
- package/hooks/useComponentTree.d.ts +1 -1
- package/hooks/useComponentTree.d.ts.map +1 -1
- package/hooks/useDomEventSource.d.ts +27 -0
- package/hooks/useDomEventSource.d.ts.map +1 -0
- package/hooks/useEventSubscription.d.ts +34 -0
- package/hooks/useEventSubscription.d.ts.map +1 -0
- package/hooks/useGetPrompt.d.ts.map +1 -1
- package/hooks/usePublishEvent.d.ts +14 -0
- package/hooks/usePublishEvent.d.ts.map +1 -0
- package/hooks/useReadResource.d.ts.map +1 -1
- package/hooks/useResolvedServer.d.ts +1 -1
- package/hooks/useResolvedServer.d.ts.map +1 -1
- package/index.d.ts +6 -2
- package/index.d.ts.map +1 -1
- package/index.js +208 -77
- package/package.json +6 -6
- package/registry/createWrappedServer.d.ts.map +1 -1
- package/router/current-route.resource.d.ts.map +1 -1
- package/router/index.d.ts +3 -1
- package/router/index.d.ts.map +1 -1
- package/router/index.js +456 -17
- package/router/route-changed.event.d.ts +8 -0
- package/router/route-changed.event.d.ts.map +1 -0
- package/router/router-bridge.d.ts +2 -0
- package/router/router-bridge.d.ts.map +1 -1
- package/router/useRouterBridge.d.ts +14 -2
- package/router/useRouterBridge.d.ts.map +1 -1
- package/state/useStoreRegistration.d.ts.map +1 -1
- package/state/useValtioResource.d.ts.map +1 -1
package/index.js
CHANGED
|
@@ -37,11 +37,13 @@ __export(index_exports, {
|
|
|
37
37
|
ComponentRegistry: () => ComponentRegistry,
|
|
38
38
|
DynamicRegistry: () => DynamicRegistry,
|
|
39
39
|
DynamicRenderer: () => DynamicRenderer,
|
|
40
|
-
|
|
40
|
+
Event: () => import_sdk5.Event,
|
|
41
|
+
ExecutionContextBase: () => import_sdk6.ExecutionContextBase,
|
|
41
42
|
FrontMcp: () => import_sdk3.FrontMcp,
|
|
42
43
|
FrontMcpAdapter: () => import_sdk3.FrontMcpAdapter,
|
|
43
44
|
FrontMcpApp: () => import_sdk3.FrontMcpApp,
|
|
44
45
|
FrontMcpContext: () => FrontMcpContext,
|
|
46
|
+
FrontMcpEvent: () => import_sdk5.FrontMcpEvent,
|
|
45
47
|
FrontMcpPlugin: () => import_sdk3.FrontMcpPlugin,
|
|
46
48
|
FrontMcpPrompt: () => import_sdk3.FrontMcpPrompt,
|
|
47
49
|
FrontMcpProvider: () => FrontMcpProvider,
|
|
@@ -51,15 +53,16 @@ __export(index_exports, {
|
|
|
51
53
|
OutputDisplay: () => OutputDisplay,
|
|
52
54
|
Plugin: () => import_sdk3.Plugin,
|
|
53
55
|
Prompt: () => import_sdk3.Prompt,
|
|
54
|
-
PromptContext: () =>
|
|
56
|
+
PromptContext: () => import_sdk6.PromptContext,
|
|
55
57
|
PromptForm: () => PromptForm,
|
|
58
|
+
RemoteEventForwardError: () => RemoteEventForwardError,
|
|
56
59
|
Resource: () => import_sdk3.Resource,
|
|
57
|
-
ResourceContext: () =>
|
|
60
|
+
ResourceContext: () => import_sdk6.ResourceContext,
|
|
58
61
|
ResourceTemplate: () => import_sdk3.ResourceTemplate,
|
|
59
62
|
ResourceViewer: () => ResourceViewer,
|
|
60
63
|
ServerRegistry: () => ServerRegistry,
|
|
61
64
|
Tool: () => import_sdk3.Tool,
|
|
62
|
-
ToolContext: () =>
|
|
65
|
+
ToolContext: () => import_sdk6.ToolContext,
|
|
63
66
|
ToolForm: () => ToolForm,
|
|
64
67
|
bindDynamicTools: () => bindDynamicTools,
|
|
65
68
|
clearCreateCache: () => import_sdk.clearCreateCache,
|
|
@@ -69,7 +72,10 @@ __export(index_exports, {
|
|
|
69
72
|
connectOpenAI: () => import_sdk2.connectOpenAI,
|
|
70
73
|
connectVercelAI: () => import_sdk2.connectVercelAI,
|
|
71
74
|
create: () => import_sdk.create,
|
|
75
|
+
createRemoteEventForwarder: () => createRemoteEventForwarder,
|
|
72
76
|
createStore: () => createStore,
|
|
77
|
+
event: () => import_sdk5.event,
|
|
78
|
+
frontMcpEvent: () => import_sdk5.frontMcpEvent,
|
|
73
79
|
frontMcpPrompt: () => import_sdk3.frontMcpPrompt,
|
|
74
80
|
frontMcpResource: () => import_sdk3.frontMcpResource,
|
|
75
81
|
frontMcpResourceTemplate: () => import_sdk3.frontMcpResourceTemplate,
|
|
@@ -86,13 +92,16 @@ __export(index_exports, {
|
|
|
86
92
|
tool: () => import_sdk3.tool,
|
|
87
93
|
useCallTool: () => useCallTool,
|
|
88
94
|
useComponentTree: () => useComponentTree,
|
|
95
|
+
useDomEventSource: () => useDomEventSource,
|
|
89
96
|
useDynamicResource: () => useDynamicResource,
|
|
90
97
|
useDynamicTool: () => useDynamicTool,
|
|
98
|
+
useEventSubscription: () => useEventSubscription,
|
|
91
99
|
useFrontMcp: () => useFrontMcp,
|
|
92
100
|
useGetPrompt: () => useGetPrompt,
|
|
93
101
|
useListPrompts: () => useListPrompts,
|
|
94
102
|
useListResources: () => useListResources,
|
|
95
103
|
useListTools: () => useListTools,
|
|
104
|
+
usePublishEvent: () => usePublishEvent,
|
|
96
105
|
useReadResource: () => useReadResource,
|
|
97
106
|
useResolvedServer: () => useResolvedServer,
|
|
98
107
|
useServer: () => useServer,
|
|
@@ -106,6 +115,7 @@ var import_sdk2 = require("@frontmcp/sdk");
|
|
|
106
115
|
var import_sdk3 = require("@frontmcp/sdk");
|
|
107
116
|
var import_sdk4 = require("@frontmcp/sdk");
|
|
108
117
|
var import_sdk5 = require("@frontmcp/sdk");
|
|
118
|
+
var import_sdk6 = require("@frontmcp/sdk");
|
|
109
119
|
|
|
110
120
|
// libs/react/src/registry/ServerRegistry.ts
|
|
111
121
|
function sameListing(a, b) {
|
|
@@ -623,6 +633,10 @@ function createWrappedServer(base, dynamicRegistry) {
|
|
|
623
633
|
},
|
|
624
634
|
async dispose() {
|
|
625
635
|
return base.dispose();
|
|
636
|
+
},
|
|
637
|
+
/** The server's own event publisher. */
|
|
638
|
+
get events() {
|
|
639
|
+
return base.events;
|
|
626
640
|
}
|
|
627
641
|
};
|
|
628
642
|
}
|
|
@@ -1428,15 +1442,132 @@ function useComponentTree(options) {
|
|
|
1428
1442
|
});
|
|
1429
1443
|
}
|
|
1430
1444
|
|
|
1445
|
+
// libs/react/src/hooks/useEventSubscription.ts
|
|
1446
|
+
var import_react14 = require("react");
|
|
1447
|
+
function toError(error) {
|
|
1448
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
1449
|
+
}
|
|
1450
|
+
function useEventSubscription(name, args, handlerOrOptions) {
|
|
1451
|
+
const options = typeof handlerOrOptions === "function" ? { onEvent: handlerOrOptions } : handlerOrOptions;
|
|
1452
|
+
const { entry } = useResolvedServer(options.server);
|
|
1453
|
+
const client = entry?.client;
|
|
1454
|
+
const argsKey = JSON.stringify(args ?? {});
|
|
1455
|
+
const enabled = options.enabled !== false;
|
|
1456
|
+
const { delivery } = options;
|
|
1457
|
+
const optionsRef = (0, import_react14.useRef)(options);
|
|
1458
|
+
const [state, setState] = (0, import_react14.useState)({ status: "idle" });
|
|
1459
|
+
useIsomorphicLayoutEffect(() => {
|
|
1460
|
+
optionsRef.current = options;
|
|
1461
|
+
});
|
|
1462
|
+
(0, import_react14.useEffect)(() => {
|
|
1463
|
+
if (!client || !enabled) {
|
|
1464
|
+
setState((current) => current.status === "idle" ? current : { status: "idle" });
|
|
1465
|
+
return;
|
|
1466
|
+
}
|
|
1467
|
+
let unmounted = false;
|
|
1468
|
+
let subscription;
|
|
1469
|
+
const run = async () => {
|
|
1470
|
+
setState({ status: "subscribing" });
|
|
1471
|
+
try {
|
|
1472
|
+
subscription = await client.events.subscribe(name, JSON.parse(argsKey), { delivery });
|
|
1473
|
+
if (unmounted) return void await subscription.cancel();
|
|
1474
|
+
const { mode } = subscription;
|
|
1475
|
+
setState({ status: "active", mode });
|
|
1476
|
+
for await (const occurrence of subscription) optionsRef.current.onEvent(occurrence);
|
|
1477
|
+
if (!unmounted) setState({ status: "ended", mode });
|
|
1478
|
+
} catch (caught) {
|
|
1479
|
+
if (unmounted) return;
|
|
1480
|
+
const error = toError(caught);
|
|
1481
|
+
setState({ status: "error", mode: subscription?.mode, error });
|
|
1482
|
+
optionsRef.current.onError?.(error);
|
|
1483
|
+
}
|
|
1484
|
+
};
|
|
1485
|
+
void run();
|
|
1486
|
+
return () => {
|
|
1487
|
+
unmounted = true;
|
|
1488
|
+
void subscription?.cancel();
|
|
1489
|
+
};
|
|
1490
|
+
}, [client, name, argsKey, enabled, delivery]);
|
|
1491
|
+
return state;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
// libs/react/src/hooks/usePublishEvent.ts
|
|
1495
|
+
var import_react15 = require("react");
|
|
1496
|
+
function usePublishEvent(serverName) {
|
|
1497
|
+
const { entry, name } = useResolvedServer(serverName);
|
|
1498
|
+
const server = entry?.server;
|
|
1499
|
+
return (0, import_react15.useCallback)(
|
|
1500
|
+
((event2, data, options) => {
|
|
1501
|
+
if (!server) return Promise.reject(new Error(`FrontMCP server "${name}" is not registered`));
|
|
1502
|
+
return server.events.publish(event2, data, options);
|
|
1503
|
+
}),
|
|
1504
|
+
[server, name]
|
|
1505
|
+
);
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
// libs/react/src/hooks/useDomEventSource.ts
|
|
1509
|
+
var import_react16 = require("react");
|
|
1510
|
+
function useDomEventSource(target, type, toEvent, options = {}) {
|
|
1511
|
+
const publish = usePublishEvent(options.server);
|
|
1512
|
+
const callbacksRef = (0, import_react16.useRef)({ toEvent, onError: options.onError });
|
|
1513
|
+
useIsomorphicLayoutEffect(() => {
|
|
1514
|
+
callbacksRef.current = { toEvent, onError: options.onError };
|
|
1515
|
+
});
|
|
1516
|
+
(0, import_react16.useEffect)(() => {
|
|
1517
|
+
const element = target && "current" in target ? target.current : target;
|
|
1518
|
+
if (!element) return;
|
|
1519
|
+
const listener = (domEvent) => {
|
|
1520
|
+
const published = callbacksRef.current.toEvent(domEvent);
|
|
1521
|
+
if (!published) return;
|
|
1522
|
+
publish(published.name, published.data, published.options).catch((caught) => {
|
|
1523
|
+
const error = caught instanceof Error ? caught : new Error(String(caught));
|
|
1524
|
+
const report = callbacksRef.current.onError;
|
|
1525
|
+
if (report) report(error);
|
|
1526
|
+
else console.warn(`[frontmcp] event "${published.name}" was not published: ${error.message}`);
|
|
1527
|
+
});
|
|
1528
|
+
};
|
|
1529
|
+
element.addEventListener(type, listener);
|
|
1530
|
+
return () => element.removeEventListener(type, listener);
|
|
1531
|
+
}, [target, type, publish]);
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
// libs/react/src/events/createRemoteEventForwarder.ts
|
|
1535
|
+
var RemoteEventForwardError = class extends Error {
|
|
1536
|
+
/** Carries the HTTP status and the body the endpoint answered with. */
|
|
1537
|
+
constructor(status, body) {
|
|
1538
|
+
super(`The remote publish endpoint answered ${status}: ${body.slice(0, 200)}`);
|
|
1539
|
+
this.status = status;
|
|
1540
|
+
this.body = body;
|
|
1541
|
+
this.name = "RemoteEventForwardError";
|
|
1542
|
+
}
|
|
1543
|
+
status;
|
|
1544
|
+
body;
|
|
1545
|
+
};
|
|
1546
|
+
function createRemoteEventForwarder(options) {
|
|
1547
|
+
return {
|
|
1548
|
+
/** POST the event with the current token; throws RemoteEventForwardError on a non-2xx answer. */
|
|
1549
|
+
async forward(name, data, publishOptions = {}) {
|
|
1550
|
+
const token = await options.getToken();
|
|
1551
|
+
const response = await (options.fetch ?? globalThis.fetch.bind(globalThis))(options.url, {
|
|
1552
|
+
method: "POST",
|
|
1553
|
+
headers: { "content-type": "application/json", ...token ? { authorization: `Bearer ${token}` } : {} },
|
|
1554
|
+
body: JSON.stringify({ name, data, ...publishOptions })
|
|
1555
|
+
});
|
|
1556
|
+
if (!response.ok) throw new RemoteEventForwardError(response.status, await response.text());
|
|
1557
|
+
return await response.json();
|
|
1558
|
+
}
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1431
1562
|
// libs/react/src/components/DynamicRenderer.tsx
|
|
1432
|
-
var
|
|
1563
|
+
var import_react17 = __toESM(require("react"));
|
|
1433
1564
|
function DynamicRenderer({ tree, registry, fallback }) {
|
|
1434
1565
|
return renderNode(tree, registry, fallback, 0);
|
|
1435
1566
|
}
|
|
1436
1567
|
function renderNode(node, registry, fallback, index) {
|
|
1437
1568
|
const Component = registry.resolve(node.type) ?? fallback ?? "div";
|
|
1438
1569
|
const childElements = renderChildren(node.children, registry, fallback);
|
|
1439
|
-
return
|
|
1570
|
+
return import_react17.default.createElement(
|
|
1440
1571
|
Component,
|
|
1441
1572
|
{ ...node.props, key: `dynamic-${index}` },
|
|
1442
1573
|
...childElements
|
|
@@ -1548,7 +1679,7 @@ function readDomBySelector(selector) {
|
|
|
1548
1679
|
}
|
|
1549
1680
|
|
|
1550
1681
|
// libs/react/src/components/ToolForm.tsx
|
|
1551
|
-
var
|
|
1682
|
+
var import_react18 = __toESM(require("react"));
|
|
1552
1683
|
function ToolForm({
|
|
1553
1684
|
tool: tool2,
|
|
1554
1685
|
onSubmit,
|
|
@@ -1558,7 +1689,7 @@ function ToolForm({
|
|
|
1558
1689
|
const schema = tool2.inputSchema ?? {};
|
|
1559
1690
|
const properties = schema["properties"] ?? {};
|
|
1560
1691
|
const required = schema["required"] ?? [];
|
|
1561
|
-
const [values, setValues] = (0,
|
|
1692
|
+
const [values, setValues] = (0, import_react18.useState)({});
|
|
1562
1693
|
const initialValue = (key, prop) => {
|
|
1563
1694
|
const options = prop["enum"];
|
|
1564
1695
|
if (!options) return "";
|
|
@@ -1566,7 +1697,7 @@ function ToolForm({
|
|
|
1566
1697
|
if (typeof fallback === "string" && options.includes(fallback)) return fallback;
|
|
1567
1698
|
return required.includes(key) ? options[0] ?? "" : "";
|
|
1568
1699
|
};
|
|
1569
|
-
const handleSubmit = (0,
|
|
1700
|
+
const handleSubmit = (0, import_react18.useCallback)(
|
|
1570
1701
|
(e) => {
|
|
1571
1702
|
e.preventDefault();
|
|
1572
1703
|
const args = {};
|
|
@@ -1585,10 +1716,10 @@ function ToolForm({
|
|
|
1585
1716
|
},
|
|
1586
1717
|
[values, properties, required, onSubmit]
|
|
1587
1718
|
);
|
|
1588
|
-
const handleChange = (0,
|
|
1719
|
+
const handleChange = (0, import_react18.useCallback)((key, value) => {
|
|
1589
1720
|
setValues((prev) => ({ ...prev, [key]: value }));
|
|
1590
1721
|
}, []);
|
|
1591
|
-
return
|
|
1722
|
+
return import_react18.default.createElement(
|
|
1592
1723
|
"form",
|
|
1593
1724
|
{ onSubmit: handleSubmit },
|
|
1594
1725
|
...Object.entries(properties).map(([key, prop]) => {
|
|
@@ -1597,8 +1728,8 @@ function ToolForm({
|
|
|
1597
1728
|
const fieldType = getFieldType(prop);
|
|
1598
1729
|
const value = values[key] ?? initialValue(key, prop);
|
|
1599
1730
|
if (renderField) {
|
|
1600
|
-
return
|
|
1601
|
-
|
|
1731
|
+
return import_react18.default.createElement(
|
|
1732
|
+
import_react18.default.Fragment,
|
|
1602
1733
|
{ key },
|
|
1603
1734
|
renderField({
|
|
1604
1735
|
name: key,
|
|
@@ -1611,24 +1742,24 @@ function ToolForm({
|
|
|
1611
1742
|
})
|
|
1612
1743
|
);
|
|
1613
1744
|
}
|
|
1614
|
-
return
|
|
1745
|
+
return import_react18.default.createElement(
|
|
1615
1746
|
"div",
|
|
1616
1747
|
{ key, style: { marginBottom: "8px" } },
|
|
1617
|
-
|
|
1748
|
+
import_react18.default.createElement(
|
|
1618
1749
|
"label",
|
|
1619
1750
|
{ htmlFor: `field-${key}`, style: { display: "block", marginBottom: "4px" } },
|
|
1620
1751
|
`${key}${isRequired ? " *" : ""}`
|
|
1621
1752
|
),
|
|
1622
|
-
enumValues ?
|
|
1753
|
+
enumValues ? import_react18.default.createElement(
|
|
1623
1754
|
"select",
|
|
1624
1755
|
{
|
|
1625
1756
|
id: `field-${key}`,
|
|
1626
1757
|
value,
|
|
1627
1758
|
onChange: (e) => handleChange(key, e.target.value)
|
|
1628
1759
|
},
|
|
1629
|
-
...isRequired ? [] : [
|
|
1630
|
-
...enumValues.map((v) =>
|
|
1631
|
-
) :
|
|
1760
|
+
...isRequired ? [] : [import_react18.default.createElement("option", { key: "", value: "" }, "")],
|
|
1761
|
+
...enumValues.map((v) => import_react18.default.createElement("option", { key: v, value: v }, v))
|
|
1762
|
+
) : import_react18.default.createElement("input", {
|
|
1632
1763
|
id: `field-${key}`,
|
|
1633
1764
|
type: fieldType === "number" || fieldType === "integer" ? "number" : "text",
|
|
1634
1765
|
step: fieldType === "integer" ? "1" : void 0,
|
|
@@ -1639,7 +1770,7 @@ function ToolForm({
|
|
|
1639
1770
|
})
|
|
1640
1771
|
);
|
|
1641
1772
|
}),
|
|
1642
|
-
|
|
1773
|
+
import_react18.default.createElement("button", { type: "submit" }, submitLabel)
|
|
1643
1774
|
);
|
|
1644
1775
|
}
|
|
1645
1776
|
function getFieldType(prop) {
|
|
@@ -1648,7 +1779,7 @@ function getFieldType(prop) {
|
|
|
1648
1779
|
}
|
|
1649
1780
|
|
|
1650
1781
|
// libs/react/src/components/PromptForm.tsx
|
|
1651
|
-
var
|
|
1782
|
+
var import_react19 = __toESM(require("react"));
|
|
1652
1783
|
function PromptForm({
|
|
1653
1784
|
prompt: prompt2,
|
|
1654
1785
|
onSubmit,
|
|
@@ -1656,8 +1787,8 @@ function PromptForm({
|
|
|
1656
1787
|
submitLabel = "Get Prompt"
|
|
1657
1788
|
}) {
|
|
1658
1789
|
const args = prompt2.arguments ?? [];
|
|
1659
|
-
const [values, setValues] = (0,
|
|
1660
|
-
const handleSubmit = (0,
|
|
1790
|
+
const [values, setValues] = (0, import_react19.useState)({});
|
|
1791
|
+
const handleSubmit = (0, import_react19.useCallback)(
|
|
1661
1792
|
(e) => {
|
|
1662
1793
|
e.preventDefault();
|
|
1663
1794
|
const result = {};
|
|
@@ -1668,17 +1799,17 @@ function PromptForm({
|
|
|
1668
1799
|
},
|
|
1669
1800
|
[values, args, onSubmit]
|
|
1670
1801
|
);
|
|
1671
|
-
const handleChange = (0,
|
|
1802
|
+
const handleChange = (0, import_react19.useCallback)((key, value) => {
|
|
1672
1803
|
setValues((prev) => ({ ...prev, [key]: value }));
|
|
1673
1804
|
}, []);
|
|
1674
|
-
return
|
|
1805
|
+
return import_react19.default.createElement(
|
|
1675
1806
|
"form",
|
|
1676
1807
|
{ onSubmit: handleSubmit },
|
|
1677
1808
|
...args.map((arg) => {
|
|
1678
1809
|
const value = values[arg.name] ?? "";
|
|
1679
1810
|
if (renderField) {
|
|
1680
|
-
return
|
|
1681
|
-
|
|
1811
|
+
return import_react19.default.createElement(
|
|
1812
|
+
import_react19.default.Fragment,
|
|
1682
1813
|
{ key: arg.name },
|
|
1683
1814
|
renderField({
|
|
1684
1815
|
name: arg.name,
|
|
@@ -1690,15 +1821,15 @@ function PromptForm({
|
|
|
1690
1821
|
})
|
|
1691
1822
|
);
|
|
1692
1823
|
}
|
|
1693
|
-
return
|
|
1824
|
+
return import_react19.default.createElement(
|
|
1694
1825
|
"div",
|
|
1695
1826
|
{ key: arg.name, style: { marginBottom: "8px" } },
|
|
1696
|
-
|
|
1827
|
+
import_react19.default.createElement(
|
|
1697
1828
|
"label",
|
|
1698
1829
|
{ htmlFor: `prompt-${arg.name}`, style: { display: "block", marginBottom: "4px" } },
|
|
1699
1830
|
`${arg.name}${arg.required ? " *" : ""}`
|
|
1700
1831
|
),
|
|
1701
|
-
|
|
1832
|
+
import_react19.default.createElement("textarea", {
|
|
1702
1833
|
id: `prompt-${arg.name}`,
|
|
1703
1834
|
name: arg.name,
|
|
1704
1835
|
placeholder: arg.description ?? "",
|
|
@@ -1710,35 +1841,35 @@ function PromptForm({
|
|
|
1710
1841
|
})
|
|
1711
1842
|
);
|
|
1712
1843
|
}),
|
|
1713
|
-
|
|
1844
|
+
import_react19.default.createElement("button", { type: "submit" }, submitLabel)
|
|
1714
1845
|
);
|
|
1715
1846
|
}
|
|
1716
1847
|
|
|
1717
1848
|
// libs/react/src/components/ResourceViewer.tsx
|
|
1718
|
-
var
|
|
1849
|
+
var import_react20 = __toESM(require("react"));
|
|
1719
1850
|
function ResourceViewer({ data, loading, error }) {
|
|
1720
1851
|
if (loading) {
|
|
1721
|
-
return
|
|
1852
|
+
return import_react20.default.createElement("div", { "data-testid": "resource-loading" }, "Loading...");
|
|
1722
1853
|
}
|
|
1723
1854
|
if (error) {
|
|
1724
|
-
return
|
|
1855
|
+
return import_react20.default.createElement(
|
|
1725
1856
|
"div",
|
|
1726
1857
|
{ "data-testid": "resource-error", style: { color: "red" } },
|
|
1727
1858
|
`Error: ${error.message}`
|
|
1728
1859
|
);
|
|
1729
1860
|
}
|
|
1730
1861
|
if (!data || !data.contents || data.contents.length === 0) {
|
|
1731
|
-
return
|
|
1862
|
+
return import_react20.default.createElement("div", { "data-testid": "resource-empty" }, "No content");
|
|
1732
1863
|
}
|
|
1733
|
-
return
|
|
1864
|
+
return import_react20.default.createElement(
|
|
1734
1865
|
"div",
|
|
1735
1866
|
{ "data-testid": "resource-viewer" },
|
|
1736
1867
|
...data.contents.map(
|
|
1737
|
-
(content, i) =>
|
|
1868
|
+
(content, i) => import_react20.default.createElement(
|
|
1738
1869
|
"div",
|
|
1739
1870
|
{ key: `${content.uri}-${i}`, style: { marginBottom: "8px" } },
|
|
1740
|
-
|
|
1741
|
-
content.mimeType === "application/json" ?
|
|
1871
|
+
import_react20.default.createElement("div", { style: { fontSize: "0.8em", color: "#666" } }, content.uri),
|
|
1872
|
+
content.mimeType === "application/json" ? import_react20.default.createElement("pre", { style: { overflow: "auto" } }, formatJson(content.text ?? "")) : import_react20.default.createElement("div", null, content.text ?? "")
|
|
1742
1873
|
)
|
|
1743
1874
|
)
|
|
1744
1875
|
);
|
|
@@ -1752,20 +1883,20 @@ function formatJson(text) {
|
|
|
1752
1883
|
}
|
|
1753
1884
|
|
|
1754
1885
|
// libs/react/src/components/OutputDisplay.tsx
|
|
1755
|
-
var
|
|
1886
|
+
var import_react21 = __toESM(require("react"));
|
|
1756
1887
|
function OutputDisplay({ data, loading, error }) {
|
|
1757
1888
|
if (loading) {
|
|
1758
|
-
return
|
|
1889
|
+
return import_react21.default.createElement("div", { "data-testid": "output-loading" }, "Loading...");
|
|
1759
1890
|
}
|
|
1760
1891
|
if (error) {
|
|
1761
|
-
return
|
|
1892
|
+
return import_react21.default.createElement(
|
|
1762
1893
|
"div",
|
|
1763
1894
|
{ "data-testid": "output-error", style: { color: "red" } },
|
|
1764
1895
|
`Error: ${error.message}`
|
|
1765
1896
|
);
|
|
1766
1897
|
}
|
|
1767
1898
|
if (data === null || data === void 0) {
|
|
1768
|
-
return
|
|
1899
|
+
return import_react21.default.createElement("div", { "data-testid": "output-empty" }, "");
|
|
1769
1900
|
}
|
|
1770
1901
|
let formatted;
|
|
1771
1902
|
if (typeof data === "string") {
|
|
@@ -1777,7 +1908,7 @@ function OutputDisplay({ data, loading, error }) {
|
|
|
1777
1908
|
formatted = String(data);
|
|
1778
1909
|
}
|
|
1779
1910
|
}
|
|
1780
|
-
return
|
|
1911
|
+
return import_react21.default.createElement(
|
|
1781
1912
|
"pre",
|
|
1782
1913
|
{ "data-testid": "output-display", style: { overflow: "auto", whiteSpace: "pre-wrap" } },
|
|
1783
1914
|
formatted
|
|
@@ -1785,7 +1916,7 @@ function OutputDisplay({ data, loading, error }) {
|
|
|
1785
1916
|
}
|
|
1786
1917
|
|
|
1787
1918
|
// libs/react/src/components/AgentContent.tsx
|
|
1788
|
-
var
|
|
1919
|
+
var import_react22 = __toESM(require("react"));
|
|
1789
1920
|
function AgentContent({
|
|
1790
1921
|
name,
|
|
1791
1922
|
description,
|
|
@@ -1794,8 +1925,8 @@ function AgentContent({
|
|
|
1794
1925
|
fallback = null,
|
|
1795
1926
|
server
|
|
1796
1927
|
}) {
|
|
1797
|
-
const [lastData, setLastData] = (0,
|
|
1798
|
-
const execute = (0,
|
|
1928
|
+
const [lastData, setLastData] = (0, import_react22.useState)(null);
|
|
1929
|
+
const execute = (0, import_react22.useCallback)(
|
|
1799
1930
|
async (args) => {
|
|
1800
1931
|
setLastData(args);
|
|
1801
1932
|
return {
|
|
@@ -1805,11 +1936,11 @@ function AgentContent({
|
|
|
1805
1936
|
[name]
|
|
1806
1937
|
);
|
|
1807
1938
|
useDynamicTool({ name, description, inputSchema, execute, server });
|
|
1808
|
-
return
|
|
1939
|
+
return import_react22.default.createElement(import_react22.default.Fragment, null, lastData !== null ? render(lastData) : fallback);
|
|
1809
1940
|
}
|
|
1810
1941
|
|
|
1811
1942
|
// libs/react/src/components/AgentSearch.tsx
|
|
1812
|
-
var
|
|
1943
|
+
var import_react23 = __toESM(require("react"));
|
|
1813
1944
|
function AgentSearch({
|
|
1814
1945
|
toolName,
|
|
1815
1946
|
description,
|
|
@@ -1818,8 +1949,8 @@ function AgentSearch({
|
|
|
1818
1949
|
renderInput,
|
|
1819
1950
|
server
|
|
1820
1951
|
}) {
|
|
1821
|
-
const [query, setQuery] = (0,
|
|
1822
|
-
const execute = (0,
|
|
1952
|
+
const [query, setQuery] = (0, import_react23.useState)("");
|
|
1953
|
+
const execute = (0, import_react23.useCallback)(
|
|
1823
1954
|
async (args) => {
|
|
1824
1955
|
const results = args["results"] ?? args;
|
|
1825
1956
|
onResults(results);
|
|
@@ -1842,7 +1973,7 @@ function AgentSearch({
|
|
|
1842
1973
|
execute,
|
|
1843
1974
|
server
|
|
1844
1975
|
});
|
|
1845
|
-
const readQuery = (0,
|
|
1976
|
+
const readQuery = (0, import_react23.useCallback)(
|
|
1846
1977
|
async () => ({
|
|
1847
1978
|
contents: [{ uri: `search://${toolName}/query`, mimeType: "text/plain", text: query }]
|
|
1848
1979
|
}),
|
|
@@ -1862,9 +1993,9 @@ function AgentSearch({
|
|
|
1862
1993
|
placeholder
|
|
1863
1994
|
};
|
|
1864
1995
|
if (renderInput) {
|
|
1865
|
-
return
|
|
1996
|
+
return import_react23.default.createElement(import_react23.default.Fragment, null, renderInput(inputProps));
|
|
1866
1997
|
}
|
|
1867
|
-
return
|
|
1998
|
+
return import_react23.default.createElement("input", {
|
|
1868
1999
|
type: "text",
|
|
1869
2000
|
value: query,
|
|
1870
2001
|
onChange: (e) => setQuery(e.target.value),
|
|
@@ -1873,36 +2004,36 @@ function AgentSearch({
|
|
|
1873
2004
|
}
|
|
1874
2005
|
|
|
1875
2006
|
// libs/react/src/components/mcpComponent.tsx
|
|
1876
|
-
var
|
|
2007
|
+
var import_react24 = __toESM(require("react"));
|
|
1877
2008
|
var import_lazy_zod2 = require("@frontmcp/lazy-zod");
|
|
1878
2009
|
var MCP_LAZY_MARKER = /* @__PURE__ */ Symbol.for("frontmcp:lazy");
|
|
1879
2010
|
function mcpLazy(factory) {
|
|
1880
2011
|
return Object.assign(factory, { [MCP_LAZY_MARKER]: true });
|
|
1881
2012
|
}
|
|
1882
2013
|
function DefaultTable({ rows, columns }) {
|
|
1883
|
-
return
|
|
2014
|
+
return import_react24.default.createElement(
|
|
1884
2015
|
"table",
|
|
1885
2016
|
null,
|
|
1886
|
-
|
|
2017
|
+
import_react24.default.createElement(
|
|
1887
2018
|
"thead",
|
|
1888
2019
|
null,
|
|
1889
|
-
|
|
2020
|
+
import_react24.default.createElement(
|
|
1890
2021
|
"tr",
|
|
1891
2022
|
null,
|
|
1892
|
-
columns.map((col) =>
|
|
2023
|
+
columns.map((col) => import_react24.default.createElement("th", { key: col.key }, col.header))
|
|
1893
2024
|
)
|
|
1894
2025
|
),
|
|
1895
|
-
|
|
2026
|
+
import_react24.default.createElement(
|
|
1896
2027
|
"tbody",
|
|
1897
2028
|
null,
|
|
1898
2029
|
rows.map(
|
|
1899
|
-
(row, i) =>
|
|
2030
|
+
(row, i) => import_react24.default.createElement(
|
|
1900
2031
|
"tr",
|
|
1901
2032
|
{ key: i },
|
|
1902
2033
|
columns.map((col) => {
|
|
1903
2034
|
const value = row[col.key];
|
|
1904
2035
|
const rendered = col.render ? col.render(value) : String(value ?? "");
|
|
1905
|
-
return
|
|
2036
|
+
return import_react24.default.createElement("td", { key: col.key }, rendered);
|
|
1906
2037
|
})
|
|
1907
2038
|
)
|
|
1908
2039
|
)
|
|
@@ -1919,7 +2050,7 @@ function mcpComponent(component, options) {
|
|
|
1919
2050
|
let ResolvedComponent = null;
|
|
1920
2051
|
if (component !== null && !isTableMode) {
|
|
1921
2052
|
if (isLazyImport(component)) {
|
|
1922
|
-
ResolvedComponent =
|
|
2053
|
+
ResolvedComponent = import_react24.default.lazy(component);
|
|
1923
2054
|
} else {
|
|
1924
2055
|
ResolvedComponent = component;
|
|
1925
2056
|
}
|
|
@@ -1933,9 +2064,9 @@ function mcpComponent(component, options) {
|
|
|
1933
2064
|
const isLazy = component !== null && !isTableMode && isLazyImport(component);
|
|
1934
2065
|
const McpWrappedComponent = Object.assign(
|
|
1935
2066
|
function McpWrappedComponentInner(directProps) {
|
|
1936
|
-
const [lastData, setLastData] = (0,
|
|
1937
|
-
const [tableRows, setTableRows] = (0,
|
|
1938
|
-
const execute = (0,
|
|
2067
|
+
const [lastData, setLastData] = (0, import_react24.useState)(null);
|
|
2068
|
+
const [tableRows, setTableRows] = (0, import_react24.useState)(null);
|
|
2069
|
+
const execute = (0, import_react24.useCallback)(
|
|
1939
2070
|
async (args) => {
|
|
1940
2071
|
if (isTableMode) {
|
|
1941
2072
|
const data2 = args;
|
|
@@ -1959,32 +2090,32 @@ function mcpComponent(component, options) {
|
|
|
1959
2090
|
const hasDirectProps = Object.keys(directProps).length > 0;
|
|
1960
2091
|
if (isTableMode && columns) {
|
|
1961
2092
|
if (tableRows !== null) {
|
|
1962
|
-
return
|
|
2093
|
+
return import_react24.default.createElement(DefaultTable, { rows: tableRows, columns });
|
|
1963
2094
|
}
|
|
1964
|
-
return
|
|
2095
|
+
return import_react24.default.createElement(import_react24.default.Fragment, null, fallback);
|
|
1965
2096
|
}
|
|
1966
2097
|
const data = hasDirectProps ? { ...lastData, ...directProps } : lastData;
|
|
1967
2098
|
if (data !== null && ResolvedComponent) {
|
|
1968
2099
|
if (isLazy) {
|
|
1969
|
-
return
|
|
1970
|
-
|
|
2100
|
+
return import_react24.default.createElement(
|
|
2101
|
+
import_react24.Suspense,
|
|
1971
2102
|
{ fallback: fallback ?? null },
|
|
1972
|
-
|
|
2103
|
+
import_react24.default.createElement(ResolvedComponent, data)
|
|
1973
2104
|
);
|
|
1974
2105
|
}
|
|
1975
|
-
return
|
|
2106
|
+
return import_react24.default.createElement(ResolvedComponent, data);
|
|
1976
2107
|
}
|
|
1977
2108
|
if (hasDirectProps && ResolvedComponent) {
|
|
1978
2109
|
if (isLazy) {
|
|
1979
|
-
return
|
|
1980
|
-
|
|
2110
|
+
return import_react24.default.createElement(
|
|
2111
|
+
import_react24.Suspense,
|
|
1981
2112
|
{ fallback: fallback ?? null },
|
|
1982
|
-
|
|
2113
|
+
import_react24.default.createElement(ResolvedComponent, directProps)
|
|
1983
2114
|
);
|
|
1984
2115
|
}
|
|
1985
|
-
return
|
|
2116
|
+
return import_react24.default.createElement(ResolvedComponent, directProps);
|
|
1986
2117
|
}
|
|
1987
|
-
return
|
|
2118
|
+
return import_react24.default.createElement(import_react24.default.Fragment, null, fallback);
|
|
1988
2119
|
},
|
|
1989
2120
|
{ toolName: name }
|
|
1990
2121
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontmcp/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0-rc.1",
|
|
4
4
|
"description": "Run a FrontMCP server inside a React app: provider, hooks, components and AI SDK integration",
|
|
5
5
|
"author": "AgentFront <info@agentfront.dev>",
|
|
6
6
|
"homepage": "https://frontmcp.dev/reference/react",
|
|
@@ -89,9 +89,9 @@
|
|
|
89
89
|
"node": ">=24.0.0"
|
|
90
90
|
},
|
|
91
91
|
"peerDependencies": {
|
|
92
|
-
"@frontmcp/lazy-zod": "1.
|
|
93
|
-
"@frontmcp/sdk": "1.
|
|
94
|
-
"@frontmcp/utils": "1.
|
|
92
|
+
"@frontmcp/lazy-zod": "1.12.0-rc.1",
|
|
93
|
+
"@frontmcp/sdk": "1.12.0-rc.1",
|
|
94
|
+
"@frontmcp/utils": "1.12.0-rc.1",
|
|
95
95
|
"react": "^18.0.0 || ^19.0.0",
|
|
96
96
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
97
97
|
"react-router-dom": "^7.0.0"
|
|
@@ -105,8 +105,8 @@
|
|
|
105
105
|
}
|
|
106
106
|
},
|
|
107
107
|
"dependencies": {
|
|
108
|
-
"@frontmcp/sdk": "1.
|
|
109
|
-
"@frontmcp/utils": "1.
|
|
108
|
+
"@frontmcp/sdk": "1.12.0-rc.1",
|
|
109
|
+
"@frontmcp/utils": "1.12.0-rc.1"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
112
|
"typescript": "^5.9.3"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createWrappedServer.d.ts","sourceRoot":"","sources":["../../src/registry/createWrappedServer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAIV,eAAe,EAEhB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAmDzD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,GAAG,eAAe,
|
|
1
|
+
{"version":3,"file":"createWrappedServer.d.ts","sourceRoot":"","sources":["../../src/registry/createWrappedServer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAIV,eAAe,EAEhB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAmDzD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,GAAG,eAAe,CA8G5G"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"current-route.resource.d.ts","sourceRoot":"","sources":["../../src/router/current-route.resource.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"current-route.resource.d.ts","sourceRoot":"","sources":["../../src/router/current-route.resource.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAIxD,qBAAa,oBAAoB;IAC/B,MAAM,CAAC,QAAQ,CAAC,GAAG,qBAAqB;IACxC,MAAM,CAAC,QAAQ,CAAC,YAAY,mBAAmB;IAC/C,MAAM,CAAC,QAAQ,CAAC,WAAW,wDAAwD;IAEnF,MAAM,CAAC,IAAI,IAAI,kBAAkB;CA+BlC"}
|
package/router/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export { useRouterBridge } from './useRouterBridge';
|
|
2
|
+
export type { RouterBridgeOptions } from './useRouterBridge';
|
|
3
|
+
export { createRouteChangedEvent } from './route-changed.event';
|
|
2
4
|
export { NavigateTool } from './navigate.tool';
|
|
3
5
|
export { GoBackTool } from './go-back.tool';
|
|
4
6
|
export { CurrentRouteResource } from './current-route.resource';
|
|
5
7
|
export { createRouterEntries } from './router.entries';
|
|
6
8
|
export type { RouterEntries } from './router.entries';
|
|
7
9
|
export type { BridgeLocation, NavigateFn } from './router-bridge';
|
|
8
|
-
export { setNavigate, setLocation, getNavigate, getLocation, clearBridge } from './router-bridge';
|
|
10
|
+
export { setNavigate, setLocation, getNavigate, getLocation, clearBridge, ROUTE_CHANGED_EVENT } from './router-bridge';
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|