@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* createToolCallHandler — non-React utility for vanilla JS usage.
|
|
3
3
|
*/
|
|
4
|
-
import type
|
|
4
|
+
import { type DirectMcpServer, type LLMPlatform } from '@frontmcp/sdk';
|
|
5
5
|
import type { CallToolFn } from '@frontmcp/utils';
|
|
6
6
|
export interface ToolCallHandler {
|
|
7
7
|
callTool: CallToolFn;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createToolHandler.d.ts","sourceRoot":"","sources":["../../src/ai/createToolHandler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"createToolHandler.d.ts","sourceRoot":"","sources":["../../src/ai/createToolHandler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAA2B,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAIlD,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,UAAU,CAAC;CACtB;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,WAAW,GAAG,eAAe,CAOrG"}
|
package/ai/types.d.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Platform-specific tool call types are re-exported from @frontmcp/utils.
|
|
5
5
|
* SDK-dependent types (tool shapes, hook return types) remain here.
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
7
|
+
import type { CallToolResult, ClaudeTool, LangChainTool, LLMPlatform, OpenAITool, VercelAITools } from '@frontmcp/sdk';
|
|
8
|
+
import type { ClaudeToolUseBlock as _ClaudeToolUseBlock, OpenAIToolCallItem as _OpenAIToolCallItem, VercelToolCallInfo as _VercelToolCallInfo } from '@frontmcp/utils';
|
|
9
9
|
export type OpenAIToolCallItem = _OpenAIToolCallItem;
|
|
10
10
|
export type ClaudeToolUseBlock = _ClaudeToolUseBlock;
|
|
11
11
|
export type VercelToolCallInfo = _VercelToolCallInfo;
|
package/ai/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ai/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ai/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACvH,OAAO,KAAK,EACV,kBAAkB,IAAI,mBAAmB,EACzC,kBAAkB,IAAI,mBAAmB,EACzC,kBAAkB,IAAI,mBAAmB,EAC1C,MAAM,iBAAiB,CAAC;AAGzB,MAAM,MAAM,kBAAkB,GAAG,mBAAmB,CAAC;AACrD,MAAM,MAAM,kBAAkB,GAAG,mBAAmB,CAAC;AACrD,MAAM,MAAM,kBAAkB,GAAG,mBAAmB,CAAC;AAErD;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAC3B,MAAM,GACN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,GACrC,cAAc,CAAC,SAAS,CAAC,GACzB;IAAE,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,GACtF;IAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC;AAM5E,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAMD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,WAAW,EAAE,aAAa,CAAC;IAC3B,GAAG,EAAE,WAAW,EAAE,CAAC;CACpB,CAAC;AAMF,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,WAAW;IACrD,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAClC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACzF,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB"}
|
package/ai/useAITools.d.ts
CHANGED
package/ai/useAITools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAITools.d.ts","sourceRoot":"","sources":["../../src/ai/useAITools.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"useAITools.d.ts","sourceRoot":"","sources":["../../src/ai/useAITools.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAmD,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAGlG,OAAO,KAAK,EAAsD,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEpG,UAAU,cAAc;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,WAAW,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,gBAAgB,CAAC,CAAC,CAAC,CA0D5G"}
|
package/ai/useTools.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Delegates tool call processing to `processPlatformToolCalls` from
|
|
5
5
|
* `@frontmcp/utils`, making the logic reusable in Node.js backends.
|
|
6
6
|
*/
|
|
7
|
-
import
|
|
7
|
+
import { type PlatformToolCallsInput, type PlatformToolCallsOutput, type SupportedPlatform } from '@frontmcp/utils';
|
|
8
8
|
import type { PlatformToolsMap } from './types';
|
|
9
9
|
export interface UseToolsResult<P extends SupportedPlatform> {
|
|
10
10
|
tools: PlatformToolsMap[P] | null;
|
package/ai/useTools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTools.d.ts","sourceRoot":"","sources":["../../src/ai/useTools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useTools.d.ts","sourceRoot":"","sources":["../../src/ai/useTools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAGhD,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,iBAAiB;IACzD,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAClC,gBAAgB,EAAE,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5F,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAcD,wBAAgB,QAAQ,CAAC,CAAC,SAAS,iBAAiB,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,cAAc,CAAC,CAAC,CAAC,CAS5G"}
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
* @deprecated Use `mcpComponent()` instead for type-safe schemas and
|
|
9
9
|
* a cleaner component-wrapping API.
|
|
10
10
|
*/
|
|
11
|
-
import React from 'react';
|
|
12
|
-
import type { ReactNode } from 'react';
|
|
11
|
+
import React, { type ReactNode } from 'react';
|
|
13
12
|
/** @deprecated Use `mcpComponent()` instead. */
|
|
14
13
|
export interface AgentContentProps {
|
|
15
14
|
/** MCP tool name that agents will call to push data. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentContent.d.ts","sourceRoot":"","sources":["../../src/components/AgentContent.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"AgentContent.d.ts","sourceRoot":"","sources":["../../src/components/AgentContent.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,EAAyB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAMrE,gDAAgD;AAChD,MAAM,WAAW,iBAAiB;IAChC,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,wCAAwC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,0DAA0D;IAC1D,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,SAAS,CAAC;IACrD,iDAAiD;IACjD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,gDAAgD;AAChD,wBAAgB,YAAY,CAAC,EAC3B,IAAI,EACJ,WAAW,EACX,WAAgC,EAChC,MAAM,EACN,QAAe,EACf,MAAM,GACP,EAAE,iBAAiB,GAAG,KAAK,CAAC,YAAY,CAgBxC"}
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
* @deprecated Use `mcpComponent()` with `columns` option for table-based
|
|
9
9
|
* search result rendering.
|
|
10
10
|
*/
|
|
11
|
-
import React from 'react';
|
|
12
|
-
import type { ReactNode } from 'react';
|
|
11
|
+
import React, { type ReactNode } from 'react';
|
|
13
12
|
export interface SearchInputRenderProps {
|
|
14
13
|
value: string;
|
|
15
14
|
onChange: (value: string) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentSearch.d.ts","sourceRoot":"","sources":["../../src/components/AgentSearch.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"AgentSearch.d.ts","sourceRoot":"","sources":["../../src/components/AgentSearch.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,EAAyB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAOrE,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,sEAAsE;AACtE,MAAM,WAAW,gBAAgB;IAC/B,qDAAqD;IACrD,QAAQ,EAAE,MAAM,CAAC;IACjB,mCAAmC;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,8BAA8B;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0DAA0D;IAC1D,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC,+EAA+E;IAC/E,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,SAAS,CAAC;IAC3D,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,sEAAsE;AACtE,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,WAAW,EACX,WAAW,EACX,SAAS,EACT,WAAW,EACX,MAAM,GACP,EAAE,gBAAgB,GAAG,KAAK,CAAC,YAAY,CA4DvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicRenderer.d.ts","sourceRoot":"","sources":["../../src/components/DynamicRenderer.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"DynamicRenderer.d.ts","sourceRoot":"","sources":["../../src/components/DynamicRenderer.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,aAAa,CAAC;IACpB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,QAAQ,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACzD;AAED,wBAAgB,eAAe,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,oBAAoB,GAAG,KAAK,CAAC,YAAY,CAEtG"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* PromptForm — headless form generator from prompt.arguments.
|
|
3
3
|
*/
|
|
4
4
|
import React from 'react';
|
|
5
|
-
import type {
|
|
5
|
+
import type { FieldRenderProps, PromptInfo } from '../types';
|
|
6
6
|
export interface PromptFormProps {
|
|
7
7
|
prompt: PromptInfo;
|
|
8
8
|
onSubmit: (args: Record<string, string>) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PromptForm.d.ts","sourceRoot":"","sources":["../../src/components/PromptForm.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAgC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"PromptForm.d.ts","sourceRoot":"","sources":["../../src/components/PromptForm.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAgC,MAAM,OAAO,CAAC;AAErD,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE7D,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;IACjD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,KAAK,CAAC,SAAS,CAAC;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,QAAQ,EACR,WAAW,EACX,WAA0B,GAC3B,EAAE,eAAe,GAAG,KAAK,CAAC,YAAY,CA+DtC"}
|
package/esm/ai/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// libs/react/src/ai/useAITools.ts
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { useCallback as useCallback2, useEffect, useState } from "react";
|
|
3
|
+
import { formatResultForPlatform, formatToolsForPlatform } from "@frontmcp/sdk";
|
|
4
4
|
|
|
5
5
|
// libs/react/src/hooks/useResolvedServer.ts
|
|
6
6
|
import { useContext as useContext2 } from "react";
|
|
@@ -452,7 +452,9 @@ function useAITools(platform, options) {
|
|
|
452
452
|
|
|
453
453
|
// libs/react/src/ai/useTools.ts
|
|
454
454
|
import { useCallback as useCallback3 } from "react";
|
|
455
|
-
import {
|
|
455
|
+
import {
|
|
456
|
+
processPlatformToolCalls
|
|
457
|
+
} from "@frontmcp/utils";
|
|
456
458
|
function useTools(platform, options) {
|
|
457
459
|
const { tools, callTool, loading, error } = useAITools(platform, options);
|
|
458
460
|
const processToolCalls = useCallback3(
|
package/esm/index.mjs
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
FrontMcpPlugin
|
|
28
28
|
} from "@frontmcp/sdk";
|
|
29
29
|
import { z as z2 } from "@frontmcp/sdk";
|
|
30
|
+
import { Event, FrontMcpEvent, event, frontMcpEvent } from "@frontmcp/sdk";
|
|
30
31
|
import { ToolContext, ResourceContext, PromptContext, ExecutionContextBase } from "@frontmcp/sdk";
|
|
31
32
|
|
|
32
33
|
// libs/react/src/registry/ServerRegistry.ts
|
|
@@ -545,6 +546,10 @@ function createWrappedServer(base, dynamicRegistry) {
|
|
|
545
546
|
},
|
|
546
547
|
async dispose() {
|
|
547
548
|
return base.dispose();
|
|
549
|
+
},
|
|
550
|
+
/** The server's own event publisher. */
|
|
551
|
+
get events() {
|
|
552
|
+
return base.events;
|
|
548
553
|
}
|
|
549
554
|
};
|
|
550
555
|
}
|
|
@@ -969,7 +974,7 @@ function useFrontMcp(name) {
|
|
|
969
974
|
}
|
|
970
975
|
|
|
971
976
|
// libs/react/src/hooks/useCallTool.ts
|
|
972
|
-
import {
|
|
977
|
+
import { useCallback as useCallback3, useEffect as useEffect4, useState } from "react";
|
|
973
978
|
function useCallTool(toolName, options = {}) {
|
|
974
979
|
const { onSuccess, onError, resetOnToolChange = true, server: serverName } = options;
|
|
975
980
|
const { entry } = useResolvedServer(serverName);
|
|
@@ -1017,7 +1022,7 @@ function useCallTool(toolName, options = {}) {
|
|
|
1017
1022
|
}
|
|
1018
1023
|
|
|
1019
1024
|
// libs/react/src/hooks/useReadResource.ts
|
|
1020
|
-
import {
|
|
1025
|
+
import { useCallback as useCallback4, useEffect as useEffect5, useState as useState2 } from "react";
|
|
1021
1026
|
function useReadResource(uriOrOptions, maybeOptions) {
|
|
1022
1027
|
const uri = typeof uriOrOptions === "string" ? uriOrOptions : void 0;
|
|
1023
1028
|
const options = typeof uriOrOptions === "object" ? uriOrOptions : maybeOptions;
|
|
@@ -1067,7 +1072,7 @@ function useReadResource(uriOrOptions, maybeOptions) {
|
|
|
1067
1072
|
}
|
|
1068
1073
|
|
|
1069
1074
|
// libs/react/src/hooks/useGetPrompt.ts
|
|
1070
|
-
import {
|
|
1075
|
+
import { useCallback as useCallback5, useState as useState3 } from "react";
|
|
1071
1076
|
function useGetPrompt(promptName, options) {
|
|
1072
1077
|
const { entry } = useResolvedServer(options?.server);
|
|
1073
1078
|
const client = entry?.client ?? null;
|
|
@@ -1350,6 +1355,123 @@ function useComponentTree(options) {
|
|
|
1350
1355
|
});
|
|
1351
1356
|
}
|
|
1352
1357
|
|
|
1358
|
+
// libs/react/src/hooks/useEventSubscription.ts
|
|
1359
|
+
import { useEffect as useEffect9, useRef as useRef5, useState as useState5 } from "react";
|
|
1360
|
+
function toError(error) {
|
|
1361
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
1362
|
+
}
|
|
1363
|
+
function useEventSubscription(name, args, handlerOrOptions) {
|
|
1364
|
+
const options = typeof handlerOrOptions === "function" ? { onEvent: handlerOrOptions } : handlerOrOptions;
|
|
1365
|
+
const { entry } = useResolvedServer(options.server);
|
|
1366
|
+
const client = entry?.client;
|
|
1367
|
+
const argsKey = JSON.stringify(args ?? {});
|
|
1368
|
+
const enabled = options.enabled !== false;
|
|
1369
|
+
const { delivery } = options;
|
|
1370
|
+
const optionsRef = useRef5(options);
|
|
1371
|
+
const [state, setState] = useState5({ status: "idle" });
|
|
1372
|
+
useIsomorphicLayoutEffect(() => {
|
|
1373
|
+
optionsRef.current = options;
|
|
1374
|
+
});
|
|
1375
|
+
useEffect9(() => {
|
|
1376
|
+
if (!client || !enabled) {
|
|
1377
|
+
setState((current) => current.status === "idle" ? current : { status: "idle" });
|
|
1378
|
+
return;
|
|
1379
|
+
}
|
|
1380
|
+
let unmounted = false;
|
|
1381
|
+
let subscription;
|
|
1382
|
+
const run = async () => {
|
|
1383
|
+
setState({ status: "subscribing" });
|
|
1384
|
+
try {
|
|
1385
|
+
subscription = await client.events.subscribe(name, JSON.parse(argsKey), { delivery });
|
|
1386
|
+
if (unmounted) return void await subscription.cancel();
|
|
1387
|
+
const { mode } = subscription;
|
|
1388
|
+
setState({ status: "active", mode });
|
|
1389
|
+
for await (const occurrence of subscription) optionsRef.current.onEvent(occurrence);
|
|
1390
|
+
if (!unmounted) setState({ status: "ended", mode });
|
|
1391
|
+
} catch (caught) {
|
|
1392
|
+
if (unmounted) return;
|
|
1393
|
+
const error = toError(caught);
|
|
1394
|
+
setState({ status: "error", mode: subscription?.mode, error });
|
|
1395
|
+
optionsRef.current.onError?.(error);
|
|
1396
|
+
}
|
|
1397
|
+
};
|
|
1398
|
+
void run();
|
|
1399
|
+
return () => {
|
|
1400
|
+
unmounted = true;
|
|
1401
|
+
void subscription?.cancel();
|
|
1402
|
+
};
|
|
1403
|
+
}, [client, name, argsKey, enabled, delivery]);
|
|
1404
|
+
return state;
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
// libs/react/src/hooks/usePublishEvent.ts
|
|
1408
|
+
import { useCallback as useCallback8 } from "react";
|
|
1409
|
+
function usePublishEvent(serverName) {
|
|
1410
|
+
const { entry, name } = useResolvedServer(serverName);
|
|
1411
|
+
const server = entry?.server;
|
|
1412
|
+
return useCallback8(
|
|
1413
|
+
((event2, data, options) => {
|
|
1414
|
+
if (!server) return Promise.reject(new Error(`FrontMCP server "${name}" is not registered`));
|
|
1415
|
+
return server.events.publish(event2, data, options);
|
|
1416
|
+
}),
|
|
1417
|
+
[server, name]
|
|
1418
|
+
);
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
// libs/react/src/hooks/useDomEventSource.ts
|
|
1422
|
+
import { useEffect as useEffect10, useRef as useRef6 } from "react";
|
|
1423
|
+
function useDomEventSource(target, type, toEvent, options = {}) {
|
|
1424
|
+
const publish = usePublishEvent(options.server);
|
|
1425
|
+
const callbacksRef = useRef6({ toEvent, onError: options.onError });
|
|
1426
|
+
useIsomorphicLayoutEffect(() => {
|
|
1427
|
+
callbacksRef.current = { toEvent, onError: options.onError };
|
|
1428
|
+
});
|
|
1429
|
+
useEffect10(() => {
|
|
1430
|
+
const element = target && "current" in target ? target.current : target;
|
|
1431
|
+
if (!element) return;
|
|
1432
|
+
const listener = (domEvent) => {
|
|
1433
|
+
const published = callbacksRef.current.toEvent(domEvent);
|
|
1434
|
+
if (!published) return;
|
|
1435
|
+
publish(published.name, published.data, published.options).catch((caught) => {
|
|
1436
|
+
const error = caught instanceof Error ? caught : new Error(String(caught));
|
|
1437
|
+
const report = callbacksRef.current.onError;
|
|
1438
|
+
if (report) report(error);
|
|
1439
|
+
else console.warn(`[frontmcp] event "${published.name}" was not published: ${error.message}`);
|
|
1440
|
+
});
|
|
1441
|
+
};
|
|
1442
|
+
element.addEventListener(type, listener);
|
|
1443
|
+
return () => element.removeEventListener(type, listener);
|
|
1444
|
+
}, [target, type, publish]);
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
// libs/react/src/events/createRemoteEventForwarder.ts
|
|
1448
|
+
var RemoteEventForwardError = class extends Error {
|
|
1449
|
+
/** Carries the HTTP status and the body the endpoint answered with. */
|
|
1450
|
+
constructor(status, body) {
|
|
1451
|
+
super(`The remote publish endpoint answered ${status}: ${body.slice(0, 200)}`);
|
|
1452
|
+
this.status = status;
|
|
1453
|
+
this.body = body;
|
|
1454
|
+
this.name = "RemoteEventForwardError";
|
|
1455
|
+
}
|
|
1456
|
+
status;
|
|
1457
|
+
body;
|
|
1458
|
+
};
|
|
1459
|
+
function createRemoteEventForwarder(options) {
|
|
1460
|
+
return {
|
|
1461
|
+
/** POST the event with the current token; throws RemoteEventForwardError on a non-2xx answer. */
|
|
1462
|
+
async forward(name, data, publishOptions = {}) {
|
|
1463
|
+
const token = await options.getToken();
|
|
1464
|
+
const response = await (options.fetch ?? globalThis.fetch.bind(globalThis))(options.url, {
|
|
1465
|
+
method: "POST",
|
|
1466
|
+
headers: { "content-type": "application/json", ...token ? { authorization: `Bearer ${token}` } : {} },
|
|
1467
|
+
body: JSON.stringify({ name, data, ...publishOptions })
|
|
1468
|
+
});
|
|
1469
|
+
if (!response.ok) throw new RemoteEventForwardError(response.status, await response.text());
|
|
1470
|
+
return await response.json();
|
|
1471
|
+
}
|
|
1472
|
+
};
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1353
1475
|
// libs/react/src/components/DynamicRenderer.tsx
|
|
1354
1476
|
import React2 from "react";
|
|
1355
1477
|
function DynamicRenderer({ tree, registry, fallback }) {
|
|
@@ -1470,7 +1592,7 @@ function readDomBySelector(selector) {
|
|
|
1470
1592
|
}
|
|
1471
1593
|
|
|
1472
1594
|
// libs/react/src/components/ToolForm.tsx
|
|
1473
|
-
import React3, { useCallback as
|
|
1595
|
+
import React3, { useCallback as useCallback9, useState as useState6 } from "react";
|
|
1474
1596
|
function ToolForm({
|
|
1475
1597
|
tool: tool2,
|
|
1476
1598
|
onSubmit,
|
|
@@ -1480,7 +1602,7 @@ function ToolForm({
|
|
|
1480
1602
|
const schema = tool2.inputSchema ?? {};
|
|
1481
1603
|
const properties = schema["properties"] ?? {};
|
|
1482
1604
|
const required = schema["required"] ?? [];
|
|
1483
|
-
const [values, setValues] =
|
|
1605
|
+
const [values, setValues] = useState6({});
|
|
1484
1606
|
const initialValue = (key, prop) => {
|
|
1485
1607
|
const options = prop["enum"];
|
|
1486
1608
|
if (!options) return "";
|
|
@@ -1488,7 +1610,7 @@ function ToolForm({
|
|
|
1488
1610
|
if (typeof fallback === "string" && options.includes(fallback)) return fallback;
|
|
1489
1611
|
return required.includes(key) ? options[0] ?? "" : "";
|
|
1490
1612
|
};
|
|
1491
|
-
const handleSubmit =
|
|
1613
|
+
const handleSubmit = useCallback9(
|
|
1492
1614
|
(e) => {
|
|
1493
1615
|
e.preventDefault();
|
|
1494
1616
|
const args = {};
|
|
@@ -1507,7 +1629,7 @@ function ToolForm({
|
|
|
1507
1629
|
},
|
|
1508
1630
|
[values, properties, required, onSubmit]
|
|
1509
1631
|
);
|
|
1510
|
-
const handleChange =
|
|
1632
|
+
const handleChange = useCallback9((key, value) => {
|
|
1511
1633
|
setValues((prev) => ({ ...prev, [key]: value }));
|
|
1512
1634
|
}, []);
|
|
1513
1635
|
return React3.createElement(
|
|
@@ -1570,7 +1692,7 @@ function getFieldType(prop) {
|
|
|
1570
1692
|
}
|
|
1571
1693
|
|
|
1572
1694
|
// libs/react/src/components/PromptForm.tsx
|
|
1573
|
-
import React4, {
|
|
1695
|
+
import React4, { useCallback as useCallback10, useState as useState7 } from "react";
|
|
1574
1696
|
function PromptForm({
|
|
1575
1697
|
prompt: prompt2,
|
|
1576
1698
|
onSubmit,
|
|
@@ -1578,8 +1700,8 @@ function PromptForm({
|
|
|
1578
1700
|
submitLabel = "Get Prompt"
|
|
1579
1701
|
}) {
|
|
1580
1702
|
const args = prompt2.arguments ?? [];
|
|
1581
|
-
const [values, setValues] =
|
|
1582
|
-
const handleSubmit =
|
|
1703
|
+
const [values, setValues] = useState7({});
|
|
1704
|
+
const handleSubmit = useCallback10(
|
|
1583
1705
|
(e) => {
|
|
1584
1706
|
e.preventDefault();
|
|
1585
1707
|
const result = {};
|
|
@@ -1590,7 +1712,7 @@ function PromptForm({
|
|
|
1590
1712
|
},
|
|
1591
1713
|
[values, args, onSubmit]
|
|
1592
1714
|
);
|
|
1593
|
-
const handleChange =
|
|
1715
|
+
const handleChange = useCallback10((key, value) => {
|
|
1594
1716
|
setValues((prev) => ({ ...prev, [key]: value }));
|
|
1595
1717
|
}, []);
|
|
1596
1718
|
return React4.createElement(
|
|
@@ -1707,7 +1829,7 @@ function OutputDisplay({ data, loading, error }) {
|
|
|
1707
1829
|
}
|
|
1708
1830
|
|
|
1709
1831
|
// libs/react/src/components/AgentContent.tsx
|
|
1710
|
-
import React7, {
|
|
1832
|
+
import React7, { useCallback as useCallback11, useState as useState8 } from "react";
|
|
1711
1833
|
function AgentContent({
|
|
1712
1834
|
name,
|
|
1713
1835
|
description,
|
|
@@ -1716,8 +1838,8 @@ function AgentContent({
|
|
|
1716
1838
|
fallback = null,
|
|
1717
1839
|
server
|
|
1718
1840
|
}) {
|
|
1719
|
-
const [lastData, setLastData] =
|
|
1720
|
-
const execute =
|
|
1841
|
+
const [lastData, setLastData] = useState8(null);
|
|
1842
|
+
const execute = useCallback11(
|
|
1721
1843
|
async (args) => {
|
|
1722
1844
|
setLastData(args);
|
|
1723
1845
|
return {
|
|
@@ -1731,7 +1853,7 @@ function AgentContent({
|
|
|
1731
1853
|
}
|
|
1732
1854
|
|
|
1733
1855
|
// libs/react/src/components/AgentSearch.tsx
|
|
1734
|
-
import React8, {
|
|
1856
|
+
import React8, { useCallback as useCallback12, useState as useState9 } from "react";
|
|
1735
1857
|
function AgentSearch({
|
|
1736
1858
|
toolName,
|
|
1737
1859
|
description,
|
|
@@ -1740,8 +1862,8 @@ function AgentSearch({
|
|
|
1740
1862
|
renderInput,
|
|
1741
1863
|
server
|
|
1742
1864
|
}) {
|
|
1743
|
-
const [query, setQuery] =
|
|
1744
|
-
const execute =
|
|
1865
|
+
const [query, setQuery] = useState9("");
|
|
1866
|
+
const execute = useCallback12(
|
|
1745
1867
|
async (args) => {
|
|
1746
1868
|
const results = args["results"] ?? args;
|
|
1747
1869
|
onResults(results);
|
|
@@ -1764,7 +1886,7 @@ function AgentSearch({
|
|
|
1764
1886
|
execute,
|
|
1765
1887
|
server
|
|
1766
1888
|
});
|
|
1767
|
-
const readQuery =
|
|
1889
|
+
const readQuery = useCallback12(
|
|
1768
1890
|
async () => ({
|
|
1769
1891
|
contents: [{ uri: `search://${toolName}/query`, mimeType: "text/plain", text: query }]
|
|
1770
1892
|
}),
|
|
@@ -1795,7 +1917,7 @@ function AgentSearch({
|
|
|
1795
1917
|
}
|
|
1796
1918
|
|
|
1797
1919
|
// libs/react/src/components/mcpComponent.tsx
|
|
1798
|
-
import React9, { Suspense, useCallback as
|
|
1920
|
+
import React9, { Suspense, useCallback as useCallback13, useState as useState10 } from "react";
|
|
1799
1921
|
import { z } from "@frontmcp/lazy-zod";
|
|
1800
1922
|
var MCP_LAZY_MARKER = /* @__PURE__ */ Symbol.for("frontmcp:lazy");
|
|
1801
1923
|
function mcpLazy(factory) {
|
|
@@ -1855,9 +1977,9 @@ function mcpComponent(component, options) {
|
|
|
1855
1977
|
const isLazy = component !== null && !isTableMode && isLazyImport(component);
|
|
1856
1978
|
const McpWrappedComponent = Object.assign(
|
|
1857
1979
|
function McpWrappedComponentInner(directProps) {
|
|
1858
|
-
const [lastData, setLastData] =
|
|
1859
|
-
const [tableRows, setTableRows] =
|
|
1860
|
-
const execute =
|
|
1980
|
+
const [lastData, setLastData] = useState10(null);
|
|
1981
|
+
const [tableRows, setTableRows] = useState10(null);
|
|
1982
|
+
const execute = useCallback13(
|
|
1861
1983
|
async (args) => {
|
|
1862
1984
|
if (isTableMode) {
|
|
1863
1985
|
const data2 = args;
|
|
@@ -1989,11 +2111,13 @@ export {
|
|
|
1989
2111
|
ComponentRegistry,
|
|
1990
2112
|
DynamicRegistry,
|
|
1991
2113
|
DynamicRenderer,
|
|
2114
|
+
Event,
|
|
1992
2115
|
ExecutionContextBase,
|
|
1993
2116
|
FrontMcp,
|
|
1994
2117
|
FrontMcpAdapter,
|
|
1995
2118
|
FrontMcpApp,
|
|
1996
2119
|
FrontMcpContext,
|
|
2120
|
+
FrontMcpEvent,
|
|
1997
2121
|
FrontMcpPlugin,
|
|
1998
2122
|
FrontMcpPrompt,
|
|
1999
2123
|
FrontMcpProvider,
|
|
@@ -2005,6 +2129,7 @@ export {
|
|
|
2005
2129
|
Prompt,
|
|
2006
2130
|
PromptContext,
|
|
2007
2131
|
PromptForm,
|
|
2132
|
+
RemoteEventForwardError,
|
|
2008
2133
|
Resource,
|
|
2009
2134
|
ResourceContext,
|
|
2010
2135
|
ResourceTemplate,
|
|
@@ -2021,7 +2146,10 @@ export {
|
|
|
2021
2146
|
connectOpenAI,
|
|
2022
2147
|
connectVercelAI,
|
|
2023
2148
|
create,
|
|
2149
|
+
createRemoteEventForwarder,
|
|
2024
2150
|
createStore,
|
|
2151
|
+
event,
|
|
2152
|
+
frontMcpEvent,
|
|
2025
2153
|
frontMcpPrompt,
|
|
2026
2154
|
frontMcpResource,
|
|
2027
2155
|
frontMcpResourceTemplate,
|
|
@@ -2038,13 +2166,16 @@ export {
|
|
|
2038
2166
|
tool,
|
|
2039
2167
|
useCallTool,
|
|
2040
2168
|
useComponentTree,
|
|
2169
|
+
useDomEventSource,
|
|
2041
2170
|
useDynamicResource,
|
|
2042
2171
|
useDynamicTool,
|
|
2172
|
+
useEventSubscription,
|
|
2043
2173
|
useFrontMcp,
|
|
2044
2174
|
useGetPrompt,
|
|
2045
2175
|
useListPrompts,
|
|
2046
2176
|
useListResources,
|
|
2047
2177
|
useListTools,
|
|
2178
|
+
usePublishEvent,
|
|
2048
2179
|
useReadResource,
|
|
2049
2180
|
useResolvedServer,
|
|
2050
2181
|
useServer,
|
package/esm/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"
|