@frontmcp/react 1.9.1-rc.1 → 1.9.1-rc.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/api/index.js +12 -8
- package/api/useApiClient.d.ts.map +1 -1
- package/esm/api/index.mjs +7 -3
- package/esm/index.mjs +38 -25
- package/esm/package.json +6 -6
- package/esm/state/index.mjs +20 -14
- package/hooks/useDynamicResource.d.ts.map +1 -1
- package/hooks/useDynamicTool.d.ts.map +1 -1
- package/hooks/useStoreResource.d.ts.map +1 -1
- package/index.js +151 -138
- package/package.json +6 -6
- package/provider/FrontMcpProvider.d.ts.map +1 -1
- package/state/index.js +30 -24
- package/state/useStoreResource.d.ts.map +1 -1
- package/utils/useIsomorphicLayoutEffect.d.ts +4 -0
- package/utils/useIsomorphicLayoutEffect.d.ts.map +1 -0
package/index.js
CHANGED
|
@@ -581,7 +581,7 @@ function getOrCreateContext() {
|
|
|
581
581
|
var FrontMcpContext = getOrCreateContext();
|
|
582
582
|
|
|
583
583
|
// libs/react/src/provider/FrontMcpProvider.tsx
|
|
584
|
-
var
|
|
584
|
+
var import_react4 = __toESM(require("react"));
|
|
585
585
|
|
|
586
586
|
// libs/react/src/registry/bindDynamicTools.ts
|
|
587
587
|
function fingerprintOf(def) {
|
|
@@ -789,6 +789,10 @@ function useStoreRegistration(stores, dynamicRegistry) {
|
|
|
789
789
|
}, [stores, dynamicRegistry]);
|
|
790
790
|
}
|
|
791
791
|
|
|
792
|
+
// libs/react/src/utils/useIsomorphicLayoutEffect.ts
|
|
793
|
+
var import_react3 = require("react");
|
|
794
|
+
var useIsomorphicLayoutEffect = typeof document !== "undefined" ? import_react3.useLayoutEffect : import_react3.useEffect;
|
|
795
|
+
|
|
792
796
|
// libs/react/src/provider/FrontMcpProvider.tsx
|
|
793
797
|
function FrontMcpProvider({
|
|
794
798
|
name: nameProp,
|
|
@@ -803,19 +807,21 @@ function FrontMcpProvider({
|
|
|
803
807
|
onError
|
|
804
808
|
}) {
|
|
805
809
|
const resolvedName = nameProp ?? "default";
|
|
806
|
-
const mountedRef = (0,
|
|
807
|
-
const clientRef = (0,
|
|
808
|
-
const onErrorRef = (0,
|
|
809
|
-
|
|
810
|
-
|
|
810
|
+
const mountedRef = (0, import_react4.useRef)(true);
|
|
811
|
+
const clientRef = (0, import_react4.useRef)(null);
|
|
812
|
+
const onErrorRef = (0, import_react4.useRef)(onError);
|
|
813
|
+
useIsomorphicLayoutEffect(() => {
|
|
814
|
+
onErrorRef.current = onError;
|
|
815
|
+
}, [onError]);
|
|
816
|
+
const registry = (0, import_react4.useMemo)(() => {
|
|
811
817
|
const reg = new ComponentRegistry();
|
|
812
818
|
if (components) {
|
|
813
819
|
reg.registerAll(components);
|
|
814
820
|
}
|
|
815
821
|
return reg;
|
|
816
822
|
}, [components]);
|
|
817
|
-
const registryMapRef = (0,
|
|
818
|
-
const getDynamicRegistry = (0,
|
|
823
|
+
const registryMapRef = (0, import_react4.useRef)(/* @__PURE__ */ new Map());
|
|
824
|
+
const getDynamicRegistry = (0, import_react4.useCallback)(
|
|
819
825
|
(serverName) => {
|
|
820
826
|
const key = serverName ?? resolvedName;
|
|
821
827
|
let reg = registryMapRef.current.get(key);
|
|
@@ -827,25 +833,25 @@ function FrontMcpProvider({
|
|
|
827
833
|
},
|
|
828
834
|
[resolvedName]
|
|
829
835
|
);
|
|
830
|
-
const dynamicRegistry = (0,
|
|
836
|
+
const dynamicRegistry = (0, import_react4.useMemo)(() => getDynamicRegistry(resolvedName), [getDynamicRegistry, resolvedName]);
|
|
831
837
|
useStoreRegistration(stores ?? [], dynamicRegistry);
|
|
832
|
-
const wrappedServer = (0,
|
|
833
|
-
const reportToolError = (0,
|
|
838
|
+
const wrappedServer = (0, import_react4.useMemo)(() => createWrappedServer(server, dynamicRegistry), [server, dynamicRegistry]);
|
|
839
|
+
const reportToolError = (0, import_react4.useCallback)((error, toolName) => {
|
|
834
840
|
const report = onErrorRef.current;
|
|
835
841
|
if (report) report(new Error(`Dynamic tool "${toolName}" was not registered: ${error.message}`));
|
|
836
842
|
else console.warn(`[frontmcp] dynamic tool "${toolName}" was not registered: ${error.message}`);
|
|
837
843
|
}, []);
|
|
838
844
|
const dynamicToolAppsKey = JSON.stringify(dynamicToolApps ?? {});
|
|
839
|
-
const toolApps = (0,
|
|
845
|
+
const toolApps = (0, import_react4.useMemo)(
|
|
840
846
|
() => JSON.parse(dynamicToolAppsKey),
|
|
841
847
|
[dynamicToolAppsKey]
|
|
842
848
|
);
|
|
843
849
|
const primaryToolApp = toolApps[resolvedName];
|
|
844
|
-
(0,
|
|
850
|
+
(0, import_react4.useEffect)(
|
|
845
851
|
() => bindDynamicTools(dynamicRegistry, server, { onError: reportToolError, app: primaryToolApp }),
|
|
846
852
|
[dynamicRegistry, server, reportToolError, primaryToolApp]
|
|
847
853
|
);
|
|
848
|
-
(0,
|
|
854
|
+
(0, import_react4.useEffect)(() => {
|
|
849
855
|
const unbinds = [];
|
|
850
856
|
serverRegistry.register(resolvedName, wrappedServer);
|
|
851
857
|
if (servers) {
|
|
@@ -873,7 +879,7 @@ function FrontMcpProvider({
|
|
|
873
879
|
}
|
|
874
880
|
};
|
|
875
881
|
}, [resolvedName, wrappedServer, servers, getDynamicRegistry, reportToolError, toolApps]);
|
|
876
|
-
(0,
|
|
882
|
+
(0, import_react4.useEffect)(() => {
|
|
877
883
|
const refreshServerEntry = (name) => {
|
|
878
884
|
const entry = serverRegistry.get(name);
|
|
879
885
|
if (!entry || !entry.client) return;
|
|
@@ -912,7 +918,7 @@ function FrontMcpProvider({
|
|
|
912
918
|
});
|
|
913
919
|
};
|
|
914
920
|
}, [dynamicRegistry, resolvedName, servers]);
|
|
915
|
-
const connectClient = (0,
|
|
921
|
+
const connectClient = (0, import_react4.useCallback)(async () => {
|
|
916
922
|
if (clientRef.current) return;
|
|
917
923
|
try {
|
|
918
924
|
serverRegistry.update(resolvedName, { status: "connecting", error: null });
|
|
@@ -962,7 +968,7 @@ function FrontMcpProvider({
|
|
|
962
968
|
}
|
|
963
969
|
}
|
|
964
970
|
}, [resolvedName, wrappedServer, servers, onConnected, onError, dynamicRegistry]);
|
|
965
|
-
(0,
|
|
971
|
+
(0, import_react4.useEffect)(() => {
|
|
966
972
|
mountedRef.current = true;
|
|
967
973
|
if (autoConnect) {
|
|
968
974
|
connectClient();
|
|
@@ -972,7 +978,7 @@ function FrontMcpProvider({
|
|
|
972
978
|
clientRef.current = null;
|
|
973
979
|
};
|
|
974
980
|
}, [autoConnect, connectClient]);
|
|
975
|
-
const contextValue = (0,
|
|
981
|
+
const contextValue = (0, import_react4.useMemo)(
|
|
976
982
|
() => ({
|
|
977
983
|
name: resolvedName,
|
|
978
984
|
registry,
|
|
@@ -982,27 +988,27 @@ function FrontMcpProvider({
|
|
|
982
988
|
}),
|
|
983
989
|
[resolvedName, registry, dynamicRegistry, getDynamicRegistry, connectClient]
|
|
984
990
|
);
|
|
985
|
-
return
|
|
991
|
+
return import_react4.default.createElement(FrontMcpContext.Provider, { value: contextValue }, children);
|
|
986
992
|
}
|
|
987
993
|
|
|
988
994
|
// libs/react/src/hooks/useResolvedServer.ts
|
|
989
|
-
var
|
|
995
|
+
var import_react6 = require("react");
|
|
990
996
|
|
|
991
997
|
// libs/react/src/hooks/useServer.ts
|
|
992
|
-
var
|
|
998
|
+
var import_react5 = require("react");
|
|
993
999
|
function useServer(name) {
|
|
994
|
-
const ctx = (0,
|
|
1000
|
+
const ctx = (0, import_react5.useContext)(FrontMcpContext);
|
|
995
1001
|
const serverName = name ?? ctx.name;
|
|
996
|
-
const subscribe = (0,
|
|
997
|
-
const getSnapshot = (0,
|
|
1002
|
+
const subscribe = (0, import_react5.useCallback)((cb) => serverRegistry.subscribe(cb), []);
|
|
1003
|
+
const getSnapshot = (0, import_react5.useCallback)(() => {
|
|
998
1004
|
return serverRegistry.get(serverName);
|
|
999
1005
|
}, [serverName]);
|
|
1000
|
-
return (0,
|
|
1006
|
+
return (0, import_react5.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
1001
1007
|
}
|
|
1002
1008
|
|
|
1003
1009
|
// libs/react/src/hooks/useResolvedServer.ts
|
|
1004
1010
|
function useResolvedServer(serverName) {
|
|
1005
|
-
const ctx = (0,
|
|
1011
|
+
const ctx = (0, import_react6.useContext)(FrontMcpContext);
|
|
1006
1012
|
const resolvedName = serverName ?? ctx.name;
|
|
1007
1013
|
const entry = useServer(resolvedName);
|
|
1008
1014
|
return { entry, name: resolvedName, registry: ctx.registry, connect: ctx.connect };
|
|
@@ -1027,27 +1033,27 @@ function useFrontMcp(name) {
|
|
|
1027
1033
|
}
|
|
1028
1034
|
|
|
1029
1035
|
// libs/react/src/hooks/useCallTool.ts
|
|
1030
|
-
var
|
|
1036
|
+
var import_react7 = require("react");
|
|
1031
1037
|
function useCallTool(toolName, options = {}) {
|
|
1032
1038
|
const { onSuccess, onError, resetOnToolChange = true, server: serverName } = options;
|
|
1033
1039
|
const { entry } = useResolvedServer(serverName);
|
|
1034
1040
|
const client = entry?.client ?? null;
|
|
1035
1041
|
const status = entry?.status ?? "idle";
|
|
1036
|
-
const [state, setState] = (0,
|
|
1042
|
+
const [state, setState] = (0, import_react7.useState)({
|
|
1037
1043
|
data: null,
|
|
1038
1044
|
loading: false,
|
|
1039
1045
|
error: null,
|
|
1040
1046
|
called: false
|
|
1041
1047
|
});
|
|
1042
|
-
(0,
|
|
1048
|
+
(0, import_react7.useEffect)(() => {
|
|
1043
1049
|
if (resetOnToolChange) {
|
|
1044
1050
|
setState({ data: null, loading: false, error: null, called: false });
|
|
1045
1051
|
}
|
|
1046
1052
|
}, [toolName, resetOnToolChange]);
|
|
1047
|
-
const reset = (0,
|
|
1053
|
+
const reset = (0, import_react7.useCallback)(() => {
|
|
1048
1054
|
setState({ data: null, loading: false, error: null, called: false });
|
|
1049
1055
|
}, []);
|
|
1050
|
-
const callTool = (0,
|
|
1056
|
+
const callTool = (0, import_react7.useCallback)(
|
|
1051
1057
|
async (args) => {
|
|
1052
1058
|
if (status !== "connected" || !client) {
|
|
1053
1059
|
const error = new Error("FrontMCP not connected");
|
|
@@ -1075,7 +1081,7 @@ function useCallTool(toolName, options = {}) {
|
|
|
1075
1081
|
}
|
|
1076
1082
|
|
|
1077
1083
|
// libs/react/src/hooks/useReadResource.ts
|
|
1078
|
-
var
|
|
1084
|
+
var import_react8 = require("react");
|
|
1079
1085
|
function useReadResource(uriOrOptions, maybeOptions) {
|
|
1080
1086
|
const uri = typeof uriOrOptions === "string" ? uriOrOptions : void 0;
|
|
1081
1087
|
const options = typeof uriOrOptions === "object" ? uriOrOptions : maybeOptions;
|
|
@@ -1083,12 +1089,12 @@ function useReadResource(uriOrOptions, maybeOptions) {
|
|
|
1083
1089
|
const { entry } = useResolvedServer(serverName);
|
|
1084
1090
|
const client = entry?.client ?? null;
|
|
1085
1091
|
const status = entry?.status ?? "idle";
|
|
1086
|
-
const [state, setState] = (0,
|
|
1092
|
+
const [state, setState] = (0, import_react8.useState)({
|
|
1087
1093
|
data: null,
|
|
1088
1094
|
loading: false,
|
|
1089
1095
|
error: null
|
|
1090
1096
|
});
|
|
1091
|
-
const read = (0,
|
|
1097
|
+
const read = (0, import_react8.useCallback)(
|
|
1092
1098
|
async (targetUri) => {
|
|
1093
1099
|
if (status !== "connected" || !client) {
|
|
1094
1100
|
const error = new Error("FrontMCP not connected");
|
|
@@ -1108,7 +1114,7 @@ function useReadResource(uriOrOptions, maybeOptions) {
|
|
|
1108
1114
|
},
|
|
1109
1115
|
[client, status]
|
|
1110
1116
|
);
|
|
1111
|
-
(0,
|
|
1117
|
+
(0, import_react8.useEffect)(() => {
|
|
1112
1118
|
if (uri && status === "connected" && client) {
|
|
1113
1119
|
read(uri);
|
|
1114
1120
|
}
|
|
@@ -1125,17 +1131,17 @@ function useReadResource(uriOrOptions, maybeOptions) {
|
|
|
1125
1131
|
}
|
|
1126
1132
|
|
|
1127
1133
|
// libs/react/src/hooks/useGetPrompt.ts
|
|
1128
|
-
var
|
|
1134
|
+
var import_react9 = require("react");
|
|
1129
1135
|
function useGetPrompt(promptName, options) {
|
|
1130
1136
|
const { entry } = useResolvedServer(options?.server);
|
|
1131
1137
|
const client = entry?.client ?? null;
|
|
1132
1138
|
const status = entry?.status ?? "idle";
|
|
1133
|
-
const [state, setState] = (0,
|
|
1139
|
+
const [state, setState] = (0, import_react9.useState)({
|
|
1134
1140
|
data: null,
|
|
1135
1141
|
loading: false,
|
|
1136
1142
|
error: null
|
|
1137
1143
|
});
|
|
1138
|
-
const getPrompt = (0,
|
|
1144
|
+
const getPrompt = (0, import_react9.useCallback)(
|
|
1139
1145
|
async (args) => {
|
|
1140
1146
|
if (status !== "connected" || !client) {
|
|
1141
1147
|
const error = new Error("FrontMCP not connected");
|
|
@@ -1184,7 +1190,7 @@ function useListPrompts(options) {
|
|
|
1184
1190
|
}
|
|
1185
1191
|
|
|
1186
1192
|
// libs/react/src/hooks/useStoreResource.ts
|
|
1187
|
-
var
|
|
1193
|
+
var import_react10 = require("react");
|
|
1188
1194
|
function parseResourceContent(result) {
|
|
1189
1195
|
const r = result;
|
|
1190
1196
|
if (r?.contents?.[0]?.text) {
|
|
@@ -1200,10 +1206,9 @@ function useStoreResource(uri, options) {
|
|
|
1200
1206
|
const { entry } = useResolvedServer(options?.server);
|
|
1201
1207
|
const client = entry?.client ?? null;
|
|
1202
1208
|
const status = entry?.status ?? "idle";
|
|
1203
|
-
const [state, setState] = (0,
|
|
1204
|
-
const uriRef = (0,
|
|
1205
|
-
|
|
1206
|
-
const fetchResource = (0, import_react9.useCallback)(async () => {
|
|
1209
|
+
const [state, setState] = (0, import_react10.useState)({ data: null, loading: true, error: null });
|
|
1210
|
+
const uriRef = (0, import_react10.useRef)(uri);
|
|
1211
|
+
const fetchResource = (0, import_react10.useCallback)(async () => {
|
|
1207
1212
|
if (status !== "connected" || !client) return;
|
|
1208
1213
|
try {
|
|
1209
1214
|
const result = await client.readResource(uri);
|
|
@@ -1212,9 +1217,12 @@ function useStoreResource(uri, options) {
|
|
|
1212
1217
|
setState({ data: null, loading: false, error: err instanceof Error ? err : new Error(String(err)) });
|
|
1213
1218
|
}
|
|
1214
1219
|
}, [uri, client, status]);
|
|
1215
|
-
const fetchRef = (0,
|
|
1216
|
-
|
|
1217
|
-
|
|
1220
|
+
const fetchRef = (0, import_react10.useRef)(fetchResource);
|
|
1221
|
+
useIsomorphicLayoutEffect(() => {
|
|
1222
|
+
uriRef.current = uri;
|
|
1223
|
+
fetchRef.current = fetchResource;
|
|
1224
|
+
}, [uri, fetchResource]);
|
|
1225
|
+
(0, import_react10.useEffect)(() => {
|
|
1218
1226
|
if (status !== "connected" || !client) return;
|
|
1219
1227
|
let cancelled = false;
|
|
1220
1228
|
setState((prev) => ({ ...prev, loading: true }));
|
|
@@ -1250,7 +1258,7 @@ function useStoreResource(uri, options) {
|
|
|
1250
1258
|
}
|
|
1251
1259
|
|
|
1252
1260
|
// libs/react/src/hooks/useDynamicTool.ts
|
|
1253
|
-
var
|
|
1261
|
+
var import_react11 = require("react");
|
|
1254
1262
|
|
|
1255
1263
|
// libs/react/src/utils/zodToJsonSchema.ts
|
|
1256
1264
|
var import_lazy_zod = require("@frontmcp/lazy-zod");
|
|
@@ -1267,21 +1275,24 @@ function stableKey(value) {
|
|
|
1267
1275
|
}
|
|
1268
1276
|
}
|
|
1269
1277
|
function useDynamicTool(options) {
|
|
1270
|
-
const { name, description, app, enabled = true } = options;
|
|
1271
|
-
const
|
|
1278
|
+
const { name, description, app, execute, enabled = true } = options;
|
|
1279
|
+
const schema = "schema" in options && options.schema ? options.schema : null;
|
|
1280
|
+
const { getDynamicRegistry } = (0, import_react11.useContext)(FrontMcpContext);
|
|
1272
1281
|
const dynamicRegistry = getDynamicRegistry(options.server);
|
|
1273
|
-
const computedInputSchema =
|
|
1282
|
+
const computedInputSchema = schema ? zodToJsonSchema(schema) : options.inputSchema;
|
|
1274
1283
|
const inputSchemaKey = stableKey(computedInputSchema);
|
|
1275
|
-
const resolvedInputSchema = (0,
|
|
1284
|
+
const resolvedInputSchema = (0, import_react11.useMemo)(() => computedInputSchema, [inputSchemaKey]);
|
|
1276
1285
|
const annotationsKey = stableKey(options.annotations ?? null);
|
|
1277
|
-
const annotations = (0,
|
|
1286
|
+
const annotations = (0, import_react11.useMemo)(() => options.annotations, [annotationsKey]);
|
|
1278
1287
|
const availableWhenKey = stableKey(options.availableWhen ?? null);
|
|
1279
|
-
const availableWhen = (0,
|
|
1280
|
-
const executeRef = (0,
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1288
|
+
const availableWhen = (0, import_react11.useMemo)(() => options.availableWhen, [availableWhenKey]);
|
|
1289
|
+
const executeRef = (0, import_react11.useRef)(execute);
|
|
1290
|
+
const schemaRef = (0, import_react11.useRef)(schema);
|
|
1291
|
+
useIsomorphicLayoutEffect(() => {
|
|
1292
|
+
executeRef.current = execute;
|
|
1293
|
+
schemaRef.current = schema;
|
|
1294
|
+
}, [execute, schema]);
|
|
1295
|
+
(0, import_react11.useEffect)(() => {
|
|
1285
1296
|
if (!enabled) return;
|
|
1286
1297
|
const stableExecute = async (args) => {
|
|
1287
1298
|
const zodSchema = schemaRef.current;
|
|
@@ -1322,14 +1333,16 @@ function useDynamicTool(options) {
|
|
|
1322
1333
|
}
|
|
1323
1334
|
|
|
1324
1335
|
// libs/react/src/hooks/useDynamicResource.ts
|
|
1325
|
-
var
|
|
1336
|
+
var import_react12 = require("react");
|
|
1326
1337
|
function useDynamicResource(options) {
|
|
1327
1338
|
const { uri, name, description, mimeType, read, enabled = true } = options;
|
|
1328
|
-
const { getDynamicRegistry } = (0,
|
|
1339
|
+
const { getDynamicRegistry } = (0, import_react12.useContext)(FrontMcpContext);
|
|
1329
1340
|
const dynamicRegistry = getDynamicRegistry(options.server);
|
|
1330
|
-
const readRef = (0,
|
|
1331
|
-
|
|
1332
|
-
|
|
1341
|
+
const readRef = (0, import_react12.useRef)(read);
|
|
1342
|
+
useIsomorphicLayoutEffect(() => {
|
|
1343
|
+
readRef.current = read;
|
|
1344
|
+
}, [read]);
|
|
1345
|
+
(0, import_react12.useEffect)(() => {
|
|
1333
1346
|
if (!enabled) return;
|
|
1334
1347
|
const stableRead = () => readRef.current();
|
|
1335
1348
|
const unregister = dynamicRegistry.registerResource({
|
|
@@ -1344,7 +1357,7 @@ function useDynamicResource(options) {
|
|
|
1344
1357
|
}
|
|
1345
1358
|
|
|
1346
1359
|
// libs/react/src/hooks/useComponentTree.ts
|
|
1347
|
-
var
|
|
1360
|
+
var import_react13 = require("react");
|
|
1348
1361
|
var RFC_3986_SCHEME_RE = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//;
|
|
1349
1362
|
function walkDom(element, maxDepth, includeProps, depth = 0) {
|
|
1350
1363
|
if (depth > maxDepth) return null;
|
|
@@ -1379,7 +1392,7 @@ function useComponentTree(options) {
|
|
|
1379
1392
|
if (!RFC_3986_SCHEME_RE.test(uri)) {
|
|
1380
1393
|
throw new Error("URI must have a valid scheme (e.g., file://, https://, custom://)");
|
|
1381
1394
|
}
|
|
1382
|
-
const read = (0,
|
|
1395
|
+
const read = (0, import_react13.useCallback)(async () => {
|
|
1383
1396
|
const root = rootRef.current;
|
|
1384
1397
|
if (!root) {
|
|
1385
1398
|
return {
|
|
@@ -1402,14 +1415,14 @@ function useComponentTree(options) {
|
|
|
1402
1415
|
}
|
|
1403
1416
|
|
|
1404
1417
|
// libs/react/src/components/DynamicRenderer.tsx
|
|
1405
|
-
var
|
|
1418
|
+
var import_react14 = __toESM(require("react"));
|
|
1406
1419
|
function DynamicRenderer({ tree, registry, fallback }) {
|
|
1407
1420
|
return renderNode(tree, registry, fallback, 0);
|
|
1408
1421
|
}
|
|
1409
1422
|
function renderNode(node, registry, fallback, index) {
|
|
1410
1423
|
const Component = registry.resolve(node.type) ?? fallback ?? "div";
|
|
1411
1424
|
const childElements = renderChildren(node.children, registry, fallback);
|
|
1412
|
-
return
|
|
1425
|
+
return import_react14.default.createElement(
|
|
1413
1426
|
Component,
|
|
1414
1427
|
{ ...node.props, key: `dynamic-${index}` },
|
|
1415
1428
|
...childElements
|
|
@@ -1521,7 +1534,7 @@ function readDomBySelector(selector) {
|
|
|
1521
1534
|
}
|
|
1522
1535
|
|
|
1523
1536
|
// libs/react/src/components/ToolForm.tsx
|
|
1524
|
-
var
|
|
1537
|
+
var import_react15 = __toESM(require("react"));
|
|
1525
1538
|
function ToolForm({
|
|
1526
1539
|
tool: tool2,
|
|
1527
1540
|
onSubmit,
|
|
@@ -1531,7 +1544,7 @@ function ToolForm({
|
|
|
1531
1544
|
const schema = tool2.inputSchema ?? {};
|
|
1532
1545
|
const properties = schema["properties"] ?? {};
|
|
1533
1546
|
const required = schema["required"] ?? [];
|
|
1534
|
-
const [values, setValues] = (0,
|
|
1547
|
+
const [values, setValues] = (0, import_react15.useState)({});
|
|
1535
1548
|
const initialValue = (key, prop) => {
|
|
1536
1549
|
const options = prop["enum"];
|
|
1537
1550
|
if (!options) return "";
|
|
@@ -1539,7 +1552,7 @@ function ToolForm({
|
|
|
1539
1552
|
if (typeof fallback === "string" && options.includes(fallback)) return fallback;
|
|
1540
1553
|
return required.includes(key) ? options[0] ?? "" : "";
|
|
1541
1554
|
};
|
|
1542
|
-
const handleSubmit = (0,
|
|
1555
|
+
const handleSubmit = (0, import_react15.useCallback)(
|
|
1543
1556
|
(e) => {
|
|
1544
1557
|
e.preventDefault();
|
|
1545
1558
|
const args = {};
|
|
@@ -1558,10 +1571,10 @@ function ToolForm({
|
|
|
1558
1571
|
},
|
|
1559
1572
|
[values, properties, required, onSubmit]
|
|
1560
1573
|
);
|
|
1561
|
-
const handleChange = (0,
|
|
1574
|
+
const handleChange = (0, import_react15.useCallback)((key, value) => {
|
|
1562
1575
|
setValues((prev) => ({ ...prev, [key]: value }));
|
|
1563
1576
|
}, []);
|
|
1564
|
-
return
|
|
1577
|
+
return import_react15.default.createElement(
|
|
1565
1578
|
"form",
|
|
1566
1579
|
{ onSubmit: handleSubmit },
|
|
1567
1580
|
...Object.entries(properties).map(([key, prop]) => {
|
|
@@ -1570,8 +1583,8 @@ function ToolForm({
|
|
|
1570
1583
|
const fieldType = getFieldType(prop);
|
|
1571
1584
|
const value = values[key] ?? initialValue(key, prop);
|
|
1572
1585
|
if (renderField) {
|
|
1573
|
-
return
|
|
1574
|
-
|
|
1586
|
+
return import_react15.default.createElement(
|
|
1587
|
+
import_react15.default.Fragment,
|
|
1575
1588
|
{ key },
|
|
1576
1589
|
renderField({
|
|
1577
1590
|
name: key,
|
|
@@ -1584,24 +1597,24 @@ function ToolForm({
|
|
|
1584
1597
|
})
|
|
1585
1598
|
);
|
|
1586
1599
|
}
|
|
1587
|
-
return
|
|
1600
|
+
return import_react15.default.createElement(
|
|
1588
1601
|
"div",
|
|
1589
1602
|
{ key, style: { marginBottom: "8px" } },
|
|
1590
|
-
|
|
1603
|
+
import_react15.default.createElement(
|
|
1591
1604
|
"label",
|
|
1592
1605
|
{ htmlFor: `field-${key}`, style: { display: "block", marginBottom: "4px" } },
|
|
1593
1606
|
`${key}${isRequired ? " *" : ""}`
|
|
1594
1607
|
),
|
|
1595
|
-
enumValues ?
|
|
1608
|
+
enumValues ? import_react15.default.createElement(
|
|
1596
1609
|
"select",
|
|
1597
1610
|
{
|
|
1598
1611
|
id: `field-${key}`,
|
|
1599
1612
|
value,
|
|
1600
1613
|
onChange: (e) => handleChange(key, e.target.value)
|
|
1601
1614
|
},
|
|
1602
|
-
...isRequired ? [] : [
|
|
1603
|
-
...enumValues.map((v) =>
|
|
1604
|
-
) :
|
|
1615
|
+
...isRequired ? [] : [import_react15.default.createElement("option", { key: "", value: "" }, "")],
|
|
1616
|
+
...enumValues.map((v) => import_react15.default.createElement("option", { key: v, value: v }, v))
|
|
1617
|
+
) : import_react15.default.createElement("input", {
|
|
1605
1618
|
id: `field-${key}`,
|
|
1606
1619
|
type: fieldType === "number" || fieldType === "integer" ? "number" : "text",
|
|
1607
1620
|
step: fieldType === "integer" ? "1" : void 0,
|
|
@@ -1612,7 +1625,7 @@ function ToolForm({
|
|
|
1612
1625
|
})
|
|
1613
1626
|
);
|
|
1614
1627
|
}),
|
|
1615
|
-
|
|
1628
|
+
import_react15.default.createElement("button", { type: "submit" }, submitLabel)
|
|
1616
1629
|
);
|
|
1617
1630
|
}
|
|
1618
1631
|
function getFieldType(prop) {
|
|
@@ -1621,7 +1634,7 @@ function getFieldType(prop) {
|
|
|
1621
1634
|
}
|
|
1622
1635
|
|
|
1623
1636
|
// libs/react/src/components/PromptForm.tsx
|
|
1624
|
-
var
|
|
1637
|
+
var import_react16 = __toESM(require("react"));
|
|
1625
1638
|
function PromptForm({
|
|
1626
1639
|
prompt: prompt2,
|
|
1627
1640
|
onSubmit,
|
|
@@ -1629,8 +1642,8 @@ function PromptForm({
|
|
|
1629
1642
|
submitLabel = "Get Prompt"
|
|
1630
1643
|
}) {
|
|
1631
1644
|
const args = prompt2.arguments ?? [];
|
|
1632
|
-
const [values, setValues] = (0,
|
|
1633
|
-
const handleSubmit = (0,
|
|
1645
|
+
const [values, setValues] = (0, import_react16.useState)({});
|
|
1646
|
+
const handleSubmit = (0, import_react16.useCallback)(
|
|
1634
1647
|
(e) => {
|
|
1635
1648
|
e.preventDefault();
|
|
1636
1649
|
const result = {};
|
|
@@ -1641,17 +1654,17 @@ function PromptForm({
|
|
|
1641
1654
|
},
|
|
1642
1655
|
[values, args, onSubmit]
|
|
1643
1656
|
);
|
|
1644
|
-
const handleChange = (0,
|
|
1657
|
+
const handleChange = (0, import_react16.useCallback)((key, value) => {
|
|
1645
1658
|
setValues((prev) => ({ ...prev, [key]: value }));
|
|
1646
1659
|
}, []);
|
|
1647
|
-
return
|
|
1660
|
+
return import_react16.default.createElement(
|
|
1648
1661
|
"form",
|
|
1649
1662
|
{ onSubmit: handleSubmit },
|
|
1650
1663
|
...args.map((arg) => {
|
|
1651
1664
|
const value = values[arg.name] ?? "";
|
|
1652
1665
|
if (renderField) {
|
|
1653
|
-
return
|
|
1654
|
-
|
|
1666
|
+
return import_react16.default.createElement(
|
|
1667
|
+
import_react16.default.Fragment,
|
|
1655
1668
|
{ key: arg.name },
|
|
1656
1669
|
renderField({
|
|
1657
1670
|
name: arg.name,
|
|
@@ -1663,15 +1676,15 @@ function PromptForm({
|
|
|
1663
1676
|
})
|
|
1664
1677
|
);
|
|
1665
1678
|
}
|
|
1666
|
-
return
|
|
1679
|
+
return import_react16.default.createElement(
|
|
1667
1680
|
"div",
|
|
1668
1681
|
{ key: arg.name, style: { marginBottom: "8px" } },
|
|
1669
|
-
|
|
1682
|
+
import_react16.default.createElement(
|
|
1670
1683
|
"label",
|
|
1671
1684
|
{ htmlFor: `prompt-${arg.name}`, style: { display: "block", marginBottom: "4px" } },
|
|
1672
1685
|
`${arg.name}${arg.required ? " *" : ""}`
|
|
1673
1686
|
),
|
|
1674
|
-
|
|
1687
|
+
import_react16.default.createElement("textarea", {
|
|
1675
1688
|
id: `prompt-${arg.name}`,
|
|
1676
1689
|
name: arg.name,
|
|
1677
1690
|
placeholder: arg.description ?? "",
|
|
@@ -1683,35 +1696,35 @@ function PromptForm({
|
|
|
1683
1696
|
})
|
|
1684
1697
|
);
|
|
1685
1698
|
}),
|
|
1686
|
-
|
|
1699
|
+
import_react16.default.createElement("button", { type: "submit" }, submitLabel)
|
|
1687
1700
|
);
|
|
1688
1701
|
}
|
|
1689
1702
|
|
|
1690
1703
|
// libs/react/src/components/ResourceViewer.tsx
|
|
1691
|
-
var
|
|
1704
|
+
var import_react17 = __toESM(require("react"));
|
|
1692
1705
|
function ResourceViewer({ data, loading, error }) {
|
|
1693
1706
|
if (loading) {
|
|
1694
|
-
return
|
|
1707
|
+
return import_react17.default.createElement("div", { "data-testid": "resource-loading" }, "Loading...");
|
|
1695
1708
|
}
|
|
1696
1709
|
if (error) {
|
|
1697
|
-
return
|
|
1710
|
+
return import_react17.default.createElement(
|
|
1698
1711
|
"div",
|
|
1699
1712
|
{ "data-testid": "resource-error", style: { color: "red" } },
|
|
1700
1713
|
`Error: ${error.message}`
|
|
1701
1714
|
);
|
|
1702
1715
|
}
|
|
1703
1716
|
if (!data || !data.contents || data.contents.length === 0) {
|
|
1704
|
-
return
|
|
1717
|
+
return import_react17.default.createElement("div", { "data-testid": "resource-empty" }, "No content");
|
|
1705
1718
|
}
|
|
1706
|
-
return
|
|
1719
|
+
return import_react17.default.createElement(
|
|
1707
1720
|
"div",
|
|
1708
1721
|
{ "data-testid": "resource-viewer" },
|
|
1709
1722
|
...data.contents.map(
|
|
1710
|
-
(content, i) =>
|
|
1723
|
+
(content, i) => import_react17.default.createElement(
|
|
1711
1724
|
"div",
|
|
1712
1725
|
{ key: `${content.uri}-${i}`, style: { marginBottom: "8px" } },
|
|
1713
|
-
|
|
1714
|
-
content.mimeType === "application/json" ?
|
|
1726
|
+
import_react17.default.createElement("div", { style: { fontSize: "0.8em", color: "#666" } }, content.uri),
|
|
1727
|
+
content.mimeType === "application/json" ? import_react17.default.createElement("pre", { style: { overflow: "auto" } }, formatJson(content.text ?? "")) : import_react17.default.createElement("div", null, content.text ?? "")
|
|
1715
1728
|
)
|
|
1716
1729
|
)
|
|
1717
1730
|
);
|
|
@@ -1725,20 +1738,20 @@ function formatJson(text) {
|
|
|
1725
1738
|
}
|
|
1726
1739
|
|
|
1727
1740
|
// libs/react/src/components/OutputDisplay.tsx
|
|
1728
|
-
var
|
|
1741
|
+
var import_react18 = __toESM(require("react"));
|
|
1729
1742
|
function OutputDisplay({ data, loading, error }) {
|
|
1730
1743
|
if (loading) {
|
|
1731
|
-
return
|
|
1744
|
+
return import_react18.default.createElement("div", { "data-testid": "output-loading" }, "Loading...");
|
|
1732
1745
|
}
|
|
1733
1746
|
if (error) {
|
|
1734
|
-
return
|
|
1747
|
+
return import_react18.default.createElement(
|
|
1735
1748
|
"div",
|
|
1736
1749
|
{ "data-testid": "output-error", style: { color: "red" } },
|
|
1737
1750
|
`Error: ${error.message}`
|
|
1738
1751
|
);
|
|
1739
1752
|
}
|
|
1740
1753
|
if (data === null || data === void 0) {
|
|
1741
|
-
return
|
|
1754
|
+
return import_react18.default.createElement("div", { "data-testid": "output-empty" }, "");
|
|
1742
1755
|
}
|
|
1743
1756
|
let formatted;
|
|
1744
1757
|
if (typeof data === "string") {
|
|
@@ -1750,7 +1763,7 @@ function OutputDisplay({ data, loading, error }) {
|
|
|
1750
1763
|
formatted = String(data);
|
|
1751
1764
|
}
|
|
1752
1765
|
}
|
|
1753
|
-
return
|
|
1766
|
+
return import_react18.default.createElement(
|
|
1754
1767
|
"pre",
|
|
1755
1768
|
{ "data-testid": "output-display", style: { overflow: "auto", whiteSpace: "pre-wrap" } },
|
|
1756
1769
|
formatted
|
|
@@ -1758,7 +1771,7 @@ function OutputDisplay({ data, loading, error }) {
|
|
|
1758
1771
|
}
|
|
1759
1772
|
|
|
1760
1773
|
// libs/react/src/components/AgentContent.tsx
|
|
1761
|
-
var
|
|
1774
|
+
var import_react19 = __toESM(require("react"));
|
|
1762
1775
|
function AgentContent({
|
|
1763
1776
|
name,
|
|
1764
1777
|
description,
|
|
@@ -1767,8 +1780,8 @@ function AgentContent({
|
|
|
1767
1780
|
fallback = null,
|
|
1768
1781
|
server
|
|
1769
1782
|
}) {
|
|
1770
|
-
const [lastData, setLastData] = (0,
|
|
1771
|
-
const execute = (0,
|
|
1783
|
+
const [lastData, setLastData] = (0, import_react19.useState)(null);
|
|
1784
|
+
const execute = (0, import_react19.useCallback)(
|
|
1772
1785
|
async (args) => {
|
|
1773
1786
|
setLastData(args);
|
|
1774
1787
|
return {
|
|
@@ -1778,11 +1791,11 @@ function AgentContent({
|
|
|
1778
1791
|
[name]
|
|
1779
1792
|
);
|
|
1780
1793
|
useDynamicTool({ name, description, inputSchema, execute, server });
|
|
1781
|
-
return
|
|
1794
|
+
return import_react19.default.createElement(import_react19.default.Fragment, null, lastData !== null ? render(lastData) : fallback);
|
|
1782
1795
|
}
|
|
1783
1796
|
|
|
1784
1797
|
// libs/react/src/components/AgentSearch.tsx
|
|
1785
|
-
var
|
|
1798
|
+
var import_react20 = __toESM(require("react"));
|
|
1786
1799
|
function AgentSearch({
|
|
1787
1800
|
toolName,
|
|
1788
1801
|
description,
|
|
@@ -1791,8 +1804,8 @@ function AgentSearch({
|
|
|
1791
1804
|
renderInput,
|
|
1792
1805
|
server
|
|
1793
1806
|
}) {
|
|
1794
|
-
const [query, setQuery] = (0,
|
|
1795
|
-
const execute = (0,
|
|
1807
|
+
const [query, setQuery] = (0, import_react20.useState)("");
|
|
1808
|
+
const execute = (0, import_react20.useCallback)(
|
|
1796
1809
|
async (args) => {
|
|
1797
1810
|
const results = args["results"] ?? args;
|
|
1798
1811
|
onResults(results);
|
|
@@ -1815,7 +1828,7 @@ function AgentSearch({
|
|
|
1815
1828
|
execute,
|
|
1816
1829
|
server
|
|
1817
1830
|
});
|
|
1818
|
-
const readQuery = (0,
|
|
1831
|
+
const readQuery = (0, import_react20.useCallback)(
|
|
1819
1832
|
async () => ({
|
|
1820
1833
|
contents: [{ uri: `search://${toolName}/query`, mimeType: "text/plain", text: query }]
|
|
1821
1834
|
}),
|
|
@@ -1835,9 +1848,9 @@ function AgentSearch({
|
|
|
1835
1848
|
placeholder
|
|
1836
1849
|
};
|
|
1837
1850
|
if (renderInput) {
|
|
1838
|
-
return
|
|
1851
|
+
return import_react20.default.createElement(import_react20.default.Fragment, null, renderInput(inputProps));
|
|
1839
1852
|
}
|
|
1840
|
-
return
|
|
1853
|
+
return import_react20.default.createElement("input", {
|
|
1841
1854
|
type: "text",
|
|
1842
1855
|
value: query,
|
|
1843
1856
|
onChange: (e) => setQuery(e.target.value),
|
|
@@ -1846,36 +1859,36 @@ function AgentSearch({
|
|
|
1846
1859
|
}
|
|
1847
1860
|
|
|
1848
1861
|
// libs/react/src/components/mcpComponent.tsx
|
|
1849
|
-
var
|
|
1862
|
+
var import_react21 = __toESM(require("react"));
|
|
1850
1863
|
var import_lazy_zod2 = require("@frontmcp/lazy-zod");
|
|
1851
1864
|
var MCP_LAZY_MARKER = /* @__PURE__ */ Symbol.for("frontmcp:lazy");
|
|
1852
1865
|
function mcpLazy(factory) {
|
|
1853
1866
|
return Object.assign(factory, { [MCP_LAZY_MARKER]: true });
|
|
1854
1867
|
}
|
|
1855
1868
|
function DefaultTable({ rows, columns }) {
|
|
1856
|
-
return
|
|
1869
|
+
return import_react21.default.createElement(
|
|
1857
1870
|
"table",
|
|
1858
1871
|
null,
|
|
1859
|
-
|
|
1872
|
+
import_react21.default.createElement(
|
|
1860
1873
|
"thead",
|
|
1861
1874
|
null,
|
|
1862
|
-
|
|
1875
|
+
import_react21.default.createElement(
|
|
1863
1876
|
"tr",
|
|
1864
1877
|
null,
|
|
1865
|
-
columns.map((col) =>
|
|
1878
|
+
columns.map((col) => import_react21.default.createElement("th", { key: col.key }, col.header))
|
|
1866
1879
|
)
|
|
1867
1880
|
),
|
|
1868
|
-
|
|
1881
|
+
import_react21.default.createElement(
|
|
1869
1882
|
"tbody",
|
|
1870
1883
|
null,
|
|
1871
1884
|
rows.map(
|
|
1872
|
-
(row, i) =>
|
|
1885
|
+
(row, i) => import_react21.default.createElement(
|
|
1873
1886
|
"tr",
|
|
1874
1887
|
{ key: i },
|
|
1875
1888
|
columns.map((col) => {
|
|
1876
1889
|
const value = row[col.key];
|
|
1877
1890
|
const rendered = col.render ? col.render(value) : String(value ?? "");
|
|
1878
|
-
return
|
|
1891
|
+
return import_react21.default.createElement("td", { key: col.key }, rendered);
|
|
1879
1892
|
})
|
|
1880
1893
|
)
|
|
1881
1894
|
)
|
|
@@ -1892,7 +1905,7 @@ function mcpComponent(component, options) {
|
|
|
1892
1905
|
let ResolvedComponent = null;
|
|
1893
1906
|
if (component !== null && !isTableMode) {
|
|
1894
1907
|
if (isLazyImport(component)) {
|
|
1895
|
-
ResolvedComponent =
|
|
1908
|
+
ResolvedComponent = import_react21.default.lazy(component);
|
|
1896
1909
|
} else {
|
|
1897
1910
|
ResolvedComponent = component;
|
|
1898
1911
|
}
|
|
@@ -1906,9 +1919,9 @@ function mcpComponent(component, options) {
|
|
|
1906
1919
|
const isLazy = component !== null && !isTableMode && isLazyImport(component);
|
|
1907
1920
|
const McpWrappedComponent = Object.assign(
|
|
1908
1921
|
function McpWrappedComponentInner(directProps) {
|
|
1909
|
-
const [lastData, setLastData] = (0,
|
|
1910
|
-
const [tableRows, setTableRows] = (0,
|
|
1911
|
-
const execute = (0,
|
|
1922
|
+
const [lastData, setLastData] = (0, import_react21.useState)(null);
|
|
1923
|
+
const [tableRows, setTableRows] = (0, import_react21.useState)(null);
|
|
1924
|
+
const execute = (0, import_react21.useCallback)(
|
|
1912
1925
|
async (args) => {
|
|
1913
1926
|
if (isTableMode) {
|
|
1914
1927
|
const data2 = args;
|
|
@@ -1932,32 +1945,32 @@ function mcpComponent(component, options) {
|
|
|
1932
1945
|
const hasDirectProps = Object.keys(directProps).length > 0;
|
|
1933
1946
|
if (isTableMode && columns) {
|
|
1934
1947
|
if (tableRows !== null) {
|
|
1935
|
-
return
|
|
1948
|
+
return import_react21.default.createElement(DefaultTable, { rows: tableRows, columns });
|
|
1936
1949
|
}
|
|
1937
|
-
return
|
|
1950
|
+
return import_react21.default.createElement(import_react21.default.Fragment, null, fallback);
|
|
1938
1951
|
}
|
|
1939
1952
|
const data = hasDirectProps ? { ...lastData, ...directProps } : lastData;
|
|
1940
1953
|
if (data !== null && ResolvedComponent) {
|
|
1941
1954
|
if (isLazy) {
|
|
1942
|
-
return
|
|
1943
|
-
|
|
1955
|
+
return import_react21.default.createElement(
|
|
1956
|
+
import_react21.Suspense,
|
|
1944
1957
|
{ fallback: fallback ?? null },
|
|
1945
|
-
|
|
1958
|
+
import_react21.default.createElement(ResolvedComponent, data)
|
|
1946
1959
|
);
|
|
1947
1960
|
}
|
|
1948
|
-
return
|
|
1961
|
+
return import_react21.default.createElement(ResolvedComponent, data);
|
|
1949
1962
|
}
|
|
1950
1963
|
if (hasDirectProps && ResolvedComponent) {
|
|
1951
1964
|
if (isLazy) {
|
|
1952
|
-
return
|
|
1953
|
-
|
|
1965
|
+
return import_react21.default.createElement(
|
|
1966
|
+
import_react21.Suspense,
|
|
1954
1967
|
{ fallback: fallback ?? null },
|
|
1955
|
-
|
|
1968
|
+
import_react21.default.createElement(ResolvedComponent, directProps)
|
|
1956
1969
|
);
|
|
1957
1970
|
}
|
|
1958
|
-
return
|
|
1971
|
+
return import_react21.default.createElement(ResolvedComponent, directProps);
|
|
1959
1972
|
}
|
|
1960
|
-
return
|
|
1973
|
+
return import_react21.default.createElement(import_react21.default.Fragment, null, fallback);
|
|
1961
1974
|
},
|
|
1962
1975
|
{ toolName: name }
|
|
1963
1976
|
);
|