@frontmcp/ui 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +438 -0
- package/package.json +147 -0
- package/src/adapters/index.d.ts +10 -0
- package/src/adapters/index.js +18 -0
- package/src/adapters/index.js.map +1 -0
- package/src/adapters/platform-meta.d.ts +165 -0
- package/src/adapters/platform-meta.js +310 -0
- package/src/adapters/platform-meta.js.map +1 -0
- package/src/base-template/bridge.d.ts +89 -0
- package/src/base-template/bridge.js +452 -0
- package/src/base-template/bridge.js.map +1 -0
- package/src/base-template/default-base-template.d.ts +91 -0
- package/src/base-template/default-base-template.js +435 -0
- package/src/base-template/default-base-template.js.map +1 -0
- package/src/base-template/index.d.ts +14 -0
- package/src/base-template/index.js +30 -0
- package/src/base-template/index.js.map +1 -0
- package/src/base-template/polyfills.d.ts +30 -0
- package/src/base-template/polyfills.js +190 -0
- package/src/base-template/polyfills.js.map +1 -0
- package/src/base-template/theme-styles.d.ts +73 -0
- package/src/base-template/theme-styles.js +95 -0
- package/src/base-template/theme-styles.js.map +1 -0
- package/src/bridge/adapters/base-adapter.d.ts +103 -0
- package/src/bridge/adapters/base-adapter.js +314 -0
- package/src/bridge/adapters/base-adapter.js.map +1 -0
- package/src/bridge/adapters/claude.adapter.d.ts +66 -0
- package/src/bridge/adapters/claude.adapter.js +145 -0
- package/src/bridge/adapters/claude.adapter.js.map +1 -0
- package/src/bridge/adapters/ext-apps.adapter.d.ts +142 -0
- package/src/bridge/adapters/ext-apps.adapter.js +416 -0
- package/src/bridge/adapters/ext-apps.adapter.js.map +1 -0
- package/src/bridge/adapters/gemini.adapter.d.ts +63 -0
- package/src/bridge/adapters/gemini.adapter.js +160 -0
- package/src/bridge/adapters/gemini.adapter.js.map +1 -0
- package/src/bridge/adapters/generic.adapter.d.ts +55 -0
- package/src/bridge/adapters/generic.adapter.js +108 -0
- package/src/bridge/adapters/generic.adapter.js.map +1 -0
- package/src/bridge/adapters/index.d.ts +25 -0
- package/src/bridge/adapters/index.js +65 -0
- package/src/bridge/adapters/index.js.map +1 -0
- package/src/bridge/adapters/openai.adapter.d.ts +64 -0
- package/src/bridge/adapters/openai.adapter.js +194 -0
- package/src/bridge/adapters/openai.adapter.js.map +1 -0
- package/src/bridge/core/adapter-registry.d.ts +121 -0
- package/src/bridge/core/adapter-registry.js +271 -0
- package/src/bridge/core/adapter-registry.js.map +1 -0
- package/src/bridge/core/bridge-factory.d.ts +198 -0
- package/src/bridge/core/bridge-factory.js +428 -0
- package/src/bridge/core/bridge-factory.js.map +1 -0
- package/src/bridge/core/index.d.ts +9 -0
- package/src/bridge/core/index.js +22 -0
- package/src/bridge/core/index.js.map +1 -0
- package/src/bridge/index.d.ts +61 -0
- package/src/bridge/index.js +94 -0
- package/src/bridge/index.js.map +1 -0
- package/src/bridge/runtime/iife-generator.d.ts +61 -0
- package/src/bridge/runtime/iife-generator.js +940 -0
- package/src/bridge/runtime/iife-generator.js.map +1 -0
- package/src/bridge/runtime/index.d.ts +8 -0
- package/src/bridge/runtime/index.js +16 -0
- package/src/bridge/runtime/index.js.map +1 -0
- package/src/bridge/types.d.ts +385 -0
- package/src/bridge/types.js +11 -0
- package/src/bridge/types.js.map +1 -0
- package/src/build/cdn-resources.d.ts +140 -0
- package/src/build/cdn-resources.js +314 -0
- package/src/build/cdn-resources.js.map +1 -0
- package/src/build/index.d.ts +294 -0
- package/src/build/index.js +325 -0
- package/src/build/index.js.map +1 -0
- package/src/build/widget-manifest.d.ts +212 -0
- package/src/build/widget-manifest.js +652 -0
- package/src/build/widget-manifest.js.map +1 -0
- package/src/bundler/bundler.d.ts +110 -0
- package/src/bundler/bundler.js +432 -0
- package/src/bundler/bundler.js.map +1 -0
- package/src/bundler/cache.d.ts +172 -0
- package/src/bundler/cache.js +250 -0
- package/src/bundler/cache.js.map +1 -0
- package/src/bundler/index.d.ts +41 -0
- package/src/bundler/index.js +73 -0
- package/src/bundler/index.js.map +1 -0
- package/src/bundler/sandbox/enclave-adapter.d.ts +120 -0
- package/src/bundler/sandbox/enclave-adapter.js +339 -0
- package/src/bundler/sandbox/enclave-adapter.js.map +1 -0
- package/src/bundler/sandbox/executor.d.ts +13 -0
- package/src/bundler/sandbox/executor.js +22 -0
- package/src/bundler/sandbox/executor.js.map +1 -0
- package/src/bundler/sandbox/policy.d.ts +61 -0
- package/src/bundler/sandbox/policy.js +238 -0
- package/src/bundler/sandbox/policy.js.map +1 -0
- package/src/bundler/types.d.ts +347 -0
- package/src/bundler/types.js +132 -0
- package/src/bundler/types.js.map +1 -0
- package/src/components/alert.d.ts +71 -0
- package/src/components/alert.js +189 -0
- package/src/components/alert.js.map +1 -0
- package/src/components/alert.schema.d.ts +114 -0
- package/src/components/alert.schema.js +105 -0
- package/src/components/alert.schema.js.map +1 -0
- package/src/components/avatar.d.ts +76 -0
- package/src/components/avatar.js +176 -0
- package/src/components/avatar.js.map +1 -0
- package/src/components/avatar.schema.d.ts +169 -0
- package/src/components/avatar.schema.js +103 -0
- package/src/components/avatar.schema.js.map +1 -0
- package/src/components/badge.d.ts +70 -0
- package/src/components/badge.js +149 -0
- package/src/components/badge.js.map +1 -0
- package/src/components/badge.schema.d.ts +109 -0
- package/src/components/badge.schema.js +96 -0
- package/src/components/badge.schema.js.map +1 -0
- package/src/components/button.d.ts +111 -0
- package/src/components/button.js +336 -0
- package/src/components/button.js.map +1 -0
- package/src/components/button.schema.d.ts +148 -0
- package/src/components/button.schema.js +121 -0
- package/src/components/button.schema.js.map +1 -0
- package/src/components/card.d.ts +60 -0
- package/src/components/card.js +117 -0
- package/src/components/card.js.map +1 -0
- package/src/components/card.schema.d.ts +113 -0
- package/src/components/card.schema.js +98 -0
- package/src/components/card.schema.js.map +1 -0
- package/src/components/form.d.ts +239 -0
- package/src/components/form.js +420 -0
- package/src/components/form.js.map +1 -0
- package/src/components/form.schema.d.ts +441 -0
- package/src/components/form.schema.js +406 -0
- package/src/components/form.schema.js.map +1 -0
- package/src/components/index.d.ts +29 -0
- package/src/components/index.js +98 -0
- package/src/components/index.js.map +1 -0
- package/src/components/list.d.ts +127 -0
- package/src/components/list.js +279 -0
- package/src/components/list.js.map +1 -0
- package/src/components/list.schema.d.ts +134 -0
- package/src/components/list.schema.js +168 -0
- package/src/components/list.schema.js.map +1 -0
- package/src/components/modal.d.ts +111 -0
- package/src/components/modal.js +260 -0
- package/src/components/modal.js.map +1 -0
- package/src/components/modal.schema.d.ts +186 -0
- package/src/components/modal.schema.js +167 -0
- package/src/components/modal.schema.js.map +1 -0
- package/src/components/table.d.ts +105 -0
- package/src/components/table.js +283 -0
- package/src/components/table.js.map +1 -0
- package/src/components/table.schema.d.ts +159 -0
- package/src/components/table.schema.js +173 -0
- package/src/components/table.schema.js.map +1 -0
- package/src/handlebars/helpers.d.ts +348 -0
- package/src/handlebars/helpers.js +605 -0
- package/src/handlebars/helpers.js.map +1 -0
- package/src/handlebars/index.d.ts +193 -0
- package/src/handlebars/index.js +350 -0
- package/src/handlebars/index.js.map +1 -0
- package/src/index.d.ts +50 -0
- package/src/index.js +192 -0
- package/src/index.js.map +1 -0
- package/src/layouts/base.d.ts +88 -0
- package/src/layouts/base.js +227 -0
- package/src/layouts/base.js.map +1 -0
- package/src/layouts/index.d.ts +7 -0
- package/src/layouts/index.js +25 -0
- package/src/layouts/index.js.map +1 -0
- package/src/layouts/presets.d.ts +133 -0
- package/src/layouts/presets.js +277 -0
- package/src/layouts/presets.js.map +1 -0
- package/src/pages/consent.d.ts +116 -0
- package/src/pages/consent.js +218 -0
- package/src/pages/consent.js.map +1 -0
- package/src/pages/error.d.ts +100 -0
- package/src/pages/error.js +263 -0
- package/src/pages/error.js.map +1 -0
- package/src/pages/index.d.ts +8 -0
- package/src/pages/index.js +27 -0
- package/src/pages/index.js.map +1 -0
- package/src/react/Alert.d.ts +101 -0
- package/src/react/Alert.js +51 -0
- package/src/react/Alert.js.map +1 -0
- package/src/react/Badge.d.ts +100 -0
- package/src/react/Badge.js +55 -0
- package/src/react/Badge.js.map +1 -0
- package/src/react/Button.d.ts +108 -0
- package/src/react/Button.js +52 -0
- package/src/react/Button.js.map +1 -0
- package/src/react/Card.d.ts +103 -0
- package/src/react/Card.js +55 -0
- package/src/react/Card.js.map +1 -0
- package/src/react/hooks/context.d.ts +178 -0
- package/src/react/hooks/context.js +287 -0
- package/src/react/hooks/context.js.map +1 -0
- package/src/react/hooks/index.d.ts +41 -0
- package/src/react/hooks/index.js +61 -0
- package/src/react/hooks/index.js.map +1 -0
- package/src/react/hooks/tools.d.ts +283 -0
- package/src/react/hooks/tools.js +465 -0
- package/src/react/hooks/tools.js.map +1 -0
- package/src/react/index.d.ts +80 -0
- package/src/react/index.js +113 -0
- package/src/react/index.js.map +1 -0
- package/src/react/types.d.ts +105 -0
- package/src/react/types.js +12 -0
- package/src/react/types.js.map +1 -0
- package/src/react/utils.d.ts +42 -0
- package/src/react/utils.js +99 -0
- package/src/react/utils.js.map +1 -0
- package/src/registry/index.d.ts +45 -0
- package/src/registry/index.js +67 -0
- package/src/registry/index.js.map +1 -0
- package/src/registry/render-template.d.ts +86 -0
- package/src/registry/render-template.js +239 -0
- package/src/registry/render-template.js.map +1 -0
- package/src/registry/tool-ui.registry.d.ts +260 -0
- package/src/registry/tool-ui.registry.js +438 -0
- package/src/registry/tool-ui.registry.js.map +1 -0
- package/src/registry/uri-utils.d.ts +55 -0
- package/src/registry/uri-utils.js +97 -0
- package/src/registry/uri-utils.js.map +1 -0
- package/src/render/index.d.ts +7 -0
- package/src/render/index.js +14 -0
- package/src/render/index.js.map +1 -0
- package/src/render/prerender.d.ts +56 -0
- package/src/render/prerender.js +98 -0
- package/src/render/prerender.js.map +1 -0
- package/src/renderers/cache.d.ts +144 -0
- package/src/renderers/cache.js +240 -0
- package/src/renderers/cache.js.map +1 -0
- package/src/renderers/html.renderer.d.ts +122 -0
- package/src/renderers/html.renderer.js +204 -0
- package/src/renderers/html.renderer.js.map +1 -0
- package/src/renderers/index.d.ts +35 -0
- package/src/renderers/index.js +70 -0
- package/src/renderers/index.js.map +1 -0
- package/src/renderers/mdx.renderer.d.ts +119 -0
- package/src/renderers/mdx.renderer.js +305 -0
- package/src/renderers/mdx.renderer.js.map +1 -0
- package/src/renderers/react.renderer.d.ts +95 -0
- package/src/renderers/react.renderer.js +260 -0
- package/src/renderers/react.renderer.js.map +1 -0
- package/src/renderers/registry.d.ts +133 -0
- package/src/renderers/registry.js +232 -0
- package/src/renderers/registry.js.map +1 -0
- package/src/renderers/types.d.ts +341 -0
- package/src/renderers/types.js +9 -0
- package/src/renderers/types.js.map +1 -0
- package/src/renderers/utils/detect.d.ts +106 -0
- package/src/renderers/utils/detect.js +267 -0
- package/src/renderers/utils/detect.js.map +1 -0
- package/src/renderers/utils/hash.d.ts +39 -0
- package/src/renderers/utils/hash.js +75 -0
- package/src/renderers/utils/hash.js.map +1 -0
- package/src/renderers/utils/index.d.ts +8 -0
- package/src/renderers/utils/index.js +28 -0
- package/src/renderers/utils/index.js.map +1 -0
- package/src/renderers/utils/transpiler.d.ts +88 -0
- package/src/renderers/utils/transpiler.js +215 -0
- package/src/renderers/utils/transpiler.js.map +1 -0
- package/src/runtime/adapters/html.adapter.d.ts +58 -0
- package/src/runtime/adapters/html.adapter.js +131 -0
- package/src/runtime/adapters/html.adapter.js.map +1 -0
- package/src/runtime/adapters/index.d.ts +25 -0
- package/src/runtime/adapters/index.js +54 -0
- package/src/runtime/adapters/index.js.map +1 -0
- package/src/runtime/adapters/mdx.adapter.d.ts +72 -0
- package/src/runtime/adapters/mdx.adapter.js +241 -0
- package/src/runtime/adapters/mdx.adapter.js.map +1 -0
- package/src/runtime/adapters/react.adapter.d.ts +69 -0
- package/src/runtime/adapters/react.adapter.js +245 -0
- package/src/runtime/adapters/react.adapter.js.map +1 -0
- package/src/runtime/adapters/types.d.ts +94 -0
- package/src/runtime/adapters/types.js +11 -0
- package/src/runtime/adapters/types.js.map +1 -0
- package/src/runtime/csp.d.ts +37 -0
- package/src/runtime/csp.js +140 -0
- package/src/runtime/csp.js.map +1 -0
- package/src/runtime/index.d.ts +16 -0
- package/src/runtime/index.js +72 -0
- package/src/runtime/index.js.map +1 -0
- package/src/runtime/mcp-bridge.d.ts +100 -0
- package/src/runtime/mcp-bridge.js +581 -0
- package/src/runtime/mcp-bridge.js.map +1 -0
- package/src/runtime/renderer-runtime.d.ts +132 -0
- package/src/runtime/renderer-runtime.js +389 -0
- package/src/runtime/renderer-runtime.js.map +1 -0
- package/src/runtime/sanitizer.d.ts +171 -0
- package/src/runtime/sanitizer.js +318 -0
- package/src/runtime/sanitizer.js.map +1 -0
- package/src/runtime/types.d.ts +414 -0
- package/src/runtime/types.js +12 -0
- package/src/runtime/types.js.map +1 -0
- package/src/runtime/wrapper.d.ts +375 -0
- package/src/runtime/wrapper.js +1793 -0
- package/src/runtime/wrapper.js.map +1 -0
- package/src/styles/index.d.ts +7 -0
- package/src/styles/index.js +11 -0
- package/src/styles/index.js.map +1 -0
- package/src/styles/variants.d.ts +50 -0
- package/src/styles/variants.js +175 -0
- package/src/styles/variants.js.map +1 -0
- package/src/theme/cdn.d.ts +194 -0
- package/src/theme/cdn.js +375 -0
- package/src/theme/cdn.js.map +1 -0
- package/src/theme/index.d.ts +17 -0
- package/src/theme/index.js +57 -0
- package/src/theme/index.js.map +1 -0
- package/src/theme/platforms.d.ts +106 -0
- package/src/theme/platforms.js +161 -0
- package/src/theme/platforms.js.map +1 -0
- package/src/theme/presets/github-openai.d.ts +49 -0
- package/src/theme/presets/github-openai.js +189 -0
- package/src/theme/presets/github-openai.js.map +1 -0
- package/src/theme/presets/index.d.ts +10 -0
- package/src/theme/presets/index.js +17 -0
- package/src/theme/presets/index.js.map +1 -0
- package/src/theme/theme.d.ts +395 -0
- package/src/theme/theme.js +332 -0
- package/src/theme/theme.js.map +1 -0
- package/src/tool-template/builder.d.ts +212 -0
- package/src/tool-template/builder.js +397 -0
- package/src/tool-template/builder.js.map +1 -0
- package/src/tool-template/index.d.ts +15 -0
- package/src/tool-template/index.js +38 -0
- package/src/tool-template/index.js.map +1 -0
- package/src/types/index.d.ts +13 -0
- package/src/types/index.js +26 -0
- package/src/types/index.js.map +1 -0
- package/src/types/ui-config.d.ts +357 -0
- package/src/types/ui-config.js +12 -0
- package/src/types/ui-config.js.map +1 -0
- package/src/types/ui-runtime.d.ts +965 -0
- package/src/types/ui-runtime.js +117 -0
- package/src/types/ui-runtime.js.map +1 -0
- package/src/validation/error-box.d.ts +55 -0
- package/src/validation/error-box.js +75 -0
- package/src/validation/error-box.js.map +1 -0
- package/src/validation/index.d.ts +12 -0
- package/src/validation/index.js +21 -0
- package/src/validation/index.js.map +1 -0
- package/src/validation/wrapper.d.ts +96 -0
- package/src/validation/wrapper.js +117 -0
- package/src/validation/wrapper.js.map +1 -0
- package/src/web-components/core/attribute-parser.d.ts +85 -0
- package/src/web-components/core/attribute-parser.js +189 -0
- package/src/web-components/core/attribute-parser.js.map +1 -0
- package/src/web-components/core/base-element.d.ts +197 -0
- package/src/web-components/core/base-element.js +289 -0
- package/src/web-components/core/base-element.js.map +1 -0
- package/src/web-components/core/index.d.ts +8 -0
- package/src/web-components/core/index.js +18 -0
- package/src/web-components/core/index.js.map +1 -0
- package/src/web-components/elements/fmcp-alert.d.ts +45 -0
- package/src/web-components/elements/fmcp-alert.js +93 -0
- package/src/web-components/elements/fmcp-alert.js.map +1 -0
- package/src/web-components/elements/fmcp-badge.d.ts +46 -0
- package/src/web-components/elements/fmcp-badge.js +99 -0
- package/src/web-components/elements/fmcp-badge.js.map +1 -0
- package/src/web-components/elements/fmcp-button.d.ts +124 -0
- package/src/web-components/elements/fmcp-button.js +233 -0
- package/src/web-components/elements/fmcp-button.js.map +1 -0
- package/src/web-components/elements/fmcp-card.d.ts +52 -0
- package/src/web-components/elements/fmcp-card.js +115 -0
- package/src/web-components/elements/fmcp-card.js.map +1 -0
- package/src/web-components/elements/fmcp-input.d.ts +95 -0
- package/src/web-components/elements/fmcp-input.js +248 -0
- package/src/web-components/elements/fmcp-input.js.map +1 -0
- package/src/web-components/elements/fmcp-select.d.ts +99 -0
- package/src/web-components/elements/fmcp-select.js +243 -0
- package/src/web-components/elements/fmcp-select.js.map +1 -0
- package/src/web-components/elements/index.d.ts +12 -0
- package/src/web-components/elements/index.js +34 -0
- package/src/web-components/elements/index.js.map +1 -0
- package/src/web-components/index.d.ts +49 -0
- package/src/web-components/index.js +75 -0
- package/src/web-components/index.js.map +1 -0
- package/src/web-components/register.d.ts +56 -0
- package/src/web-components/register.js +80 -0
- package/src/web-components/register.js.map +1 -0
- package/src/web-components/types.d.ts +121 -0
- package/src/web-components/types.js +25 -0
- package/src/web-components/types.js.map +1 -0
- package/src/widgets/index.d.ts +7 -0
- package/src/widgets/index.js +24 -0
- package/src/widgets/index.js.map +1 -0
- package/src/widgets/progress.d.ts +132 -0
- package/src/widgets/progress.js +303 -0
- package/src/widgets/progress.js.map +1 -0
- package/src/widgets/resource.d.ts +162 -0
- package/src/widgets/resource.js +340 -0
- package/src/widgets/resource.js.map +1 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* @description React hooks for FrontMCP bridge and tools.
|
|
4
|
+
*
|
|
5
|
+
* @example Provider setup
|
|
6
|
+
* ```tsx
|
|
7
|
+
* import { McpBridgeProvider } from '@frontmcp/ui/react';
|
|
8
|
+
*
|
|
9
|
+
* function App() {
|
|
10
|
+
* return (
|
|
11
|
+
* <McpBridgeProvider>
|
|
12
|
+
* <MyWidget />
|
|
13
|
+
* </McpBridgeProvider>
|
|
14
|
+
* );
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @example Using hooks
|
|
19
|
+
* ```tsx
|
|
20
|
+
* import {
|
|
21
|
+
* useMcpBridge,
|
|
22
|
+
* useToolInput,
|
|
23
|
+
* useToolOutput,
|
|
24
|
+
* useCallTool,
|
|
25
|
+
* useTheme,
|
|
26
|
+
* } from '@frontmcp/ui/react';
|
|
27
|
+
*
|
|
28
|
+
* function MyWidget() {
|
|
29
|
+
* const bridge = useMcpBridge();
|
|
30
|
+
* const input = useToolInput<{ location: string }>();
|
|
31
|
+
* const theme = useTheme();
|
|
32
|
+
* const [callTool, { data, loading }] = useCallTool('my_tool');
|
|
33
|
+
*
|
|
34
|
+
* return <div>...</div>;
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @module @frontmcp/ui/react/hooks
|
|
39
|
+
*/
|
|
40
|
+
export { McpBridgeProvider, useMcpBridgeContext, useMcpBridge, useTheme, useDisplayMode, useHostContext, useCapability, type McpBridgeContextValue, type McpBridgeProviderProps, } from './context';
|
|
41
|
+
export { useToolInput, useToolOutput, useStructuredContent, useCallTool, useToolCalls, useSendMessage, useOpenLink, type ToolState, type UseCallToolOptions, type UseCallToolReturn, } from './tools';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file index.ts
|
|
4
|
+
* @description React hooks for FrontMCP bridge and tools.
|
|
5
|
+
*
|
|
6
|
+
* @example Provider setup
|
|
7
|
+
* ```tsx
|
|
8
|
+
* import { McpBridgeProvider } from '@frontmcp/ui/react';
|
|
9
|
+
*
|
|
10
|
+
* function App() {
|
|
11
|
+
* return (
|
|
12
|
+
* <McpBridgeProvider>
|
|
13
|
+
* <MyWidget />
|
|
14
|
+
* </McpBridgeProvider>
|
|
15
|
+
* );
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example Using hooks
|
|
20
|
+
* ```tsx
|
|
21
|
+
* import {
|
|
22
|
+
* useMcpBridge,
|
|
23
|
+
* useToolInput,
|
|
24
|
+
* useToolOutput,
|
|
25
|
+
* useCallTool,
|
|
26
|
+
* useTheme,
|
|
27
|
+
* } from '@frontmcp/ui/react';
|
|
28
|
+
*
|
|
29
|
+
* function MyWidget() {
|
|
30
|
+
* const bridge = useMcpBridge();
|
|
31
|
+
* const input = useToolInput<{ location: string }>();
|
|
32
|
+
* const theme = useTheme();
|
|
33
|
+
* const [callTool, { data, loading }] = useCallTool('my_tool');
|
|
34
|
+
*
|
|
35
|
+
* return <div>...</div>;
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @module @frontmcp/ui/react/hooks
|
|
40
|
+
*/
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.useOpenLink = exports.useSendMessage = exports.useToolCalls = exports.useCallTool = exports.useStructuredContent = exports.useToolOutput = exports.useToolInput = exports.useCapability = exports.useHostContext = exports.useDisplayMode = exports.useTheme = exports.useMcpBridge = exports.useMcpBridgeContext = exports.McpBridgeProvider = void 0;
|
|
43
|
+
// Context and Provider
|
|
44
|
+
var context_1 = require("./context");
|
|
45
|
+
Object.defineProperty(exports, "McpBridgeProvider", { enumerable: true, get: function () { return context_1.McpBridgeProvider; } });
|
|
46
|
+
Object.defineProperty(exports, "useMcpBridgeContext", { enumerable: true, get: function () { return context_1.useMcpBridgeContext; } });
|
|
47
|
+
Object.defineProperty(exports, "useMcpBridge", { enumerable: true, get: function () { return context_1.useMcpBridge; } });
|
|
48
|
+
Object.defineProperty(exports, "useTheme", { enumerable: true, get: function () { return context_1.useTheme; } });
|
|
49
|
+
Object.defineProperty(exports, "useDisplayMode", { enumerable: true, get: function () { return context_1.useDisplayMode; } });
|
|
50
|
+
Object.defineProperty(exports, "useHostContext", { enumerable: true, get: function () { return context_1.useHostContext; } });
|
|
51
|
+
Object.defineProperty(exports, "useCapability", { enumerable: true, get: function () { return context_1.useCapability; } });
|
|
52
|
+
// Tool Hooks
|
|
53
|
+
var tools_1 = require("./tools");
|
|
54
|
+
Object.defineProperty(exports, "useToolInput", { enumerable: true, get: function () { return tools_1.useToolInput; } });
|
|
55
|
+
Object.defineProperty(exports, "useToolOutput", { enumerable: true, get: function () { return tools_1.useToolOutput; } });
|
|
56
|
+
Object.defineProperty(exports, "useStructuredContent", { enumerable: true, get: function () { return tools_1.useStructuredContent; } });
|
|
57
|
+
Object.defineProperty(exports, "useCallTool", { enumerable: true, get: function () { return tools_1.useCallTool; } });
|
|
58
|
+
Object.defineProperty(exports, "useToolCalls", { enumerable: true, get: function () { return tools_1.useToolCalls; } });
|
|
59
|
+
Object.defineProperty(exports, "useSendMessage", { enumerable: true, get: function () { return tools_1.useSendMessage; } });
|
|
60
|
+
Object.defineProperty(exports, "useOpenLink", { enumerable: true, get: function () { return tools_1.useOpenLink; } });
|
|
61
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/react/hooks/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;;;AAEH,uBAAuB;AACvB,qCAUmB;AATjB,4GAAA,iBAAiB,OAAA;AACjB,8GAAA,mBAAmB,OAAA;AACnB,uGAAA,YAAY,OAAA;AACZ,mGAAA,QAAQ,OAAA;AACR,yGAAA,cAAc,OAAA;AACd,yGAAA,cAAc,OAAA;AACd,wGAAA,aAAa,OAAA;AAKf,aAAa;AACb,iCAWiB;AAVf,qGAAA,YAAY,OAAA;AACZ,sGAAA,aAAa,OAAA;AACb,6GAAA,oBAAoB,OAAA;AACpB,oGAAA,WAAW,OAAA;AACX,qGAAA,YAAY,OAAA;AACZ,uGAAA,cAAc,OAAA;AACd,oGAAA,WAAW,OAAA","sourcesContent":["/**\n * @file index.ts\n * @description React hooks for FrontMCP bridge and tools.\n *\n * @example Provider setup\n * ```tsx\n * import { McpBridgeProvider } from '@frontmcp/ui/react';\n *\n * function App() {\n * return (\n * <McpBridgeProvider>\n * <MyWidget />\n * </McpBridgeProvider>\n * );\n * }\n * ```\n *\n * @example Using hooks\n * ```tsx\n * import {\n * useMcpBridge,\n * useToolInput,\n * useToolOutput,\n * useCallTool,\n * useTheme,\n * } from '@frontmcp/ui/react';\n *\n * function MyWidget() {\n * const bridge = useMcpBridge();\n * const input = useToolInput<{ location: string }>();\n * const theme = useTheme();\n * const [callTool, { data, loading }] = useCallTool('my_tool');\n *\n * return <div>...</div>;\n * }\n * ```\n *\n * @module @frontmcp/ui/react/hooks\n */\n\n// Context and Provider\nexport {\n McpBridgeProvider,\n useMcpBridgeContext,\n useMcpBridge,\n useTheme,\n useDisplayMode,\n useHostContext,\n useCapability,\n type McpBridgeContextValue,\n type McpBridgeProviderProps,\n} from './context';\n\n// Tool Hooks\nexport {\n useToolInput,\n useToolOutput,\n useStructuredContent,\n useCallTool,\n useToolCalls,\n useSendMessage,\n useOpenLink,\n type ToolState,\n type UseCallToolOptions,\n type UseCallToolReturn,\n} from './tools';\n"]}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file tools.tsx
|
|
3
|
+
* @description React hooks for MCP tool interactions.
|
|
4
|
+
*
|
|
5
|
+
* Provides hooks for calling tools, accessing tool input/output,
|
|
6
|
+
* and managing tool execution state.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { useCallTool, useToolInput, useToolOutput } from '@frontmcp/ui/react';
|
|
11
|
+
*
|
|
12
|
+
* function WeatherWidget() {
|
|
13
|
+
* const input = useToolInput<{ location: string }>();
|
|
14
|
+
* const output = useToolOutput<WeatherData>();
|
|
15
|
+
* const [callWeather, { data, loading, error }] = useCallTool<WeatherData>('get_weather');
|
|
16
|
+
*
|
|
17
|
+
* return (
|
|
18
|
+
* <div>
|
|
19
|
+
* <p>Location: {input?.location}</p>
|
|
20
|
+
* <button onClick={() => callWeather({ location: 'NYC' })}>
|
|
21
|
+
* Get Weather
|
|
22
|
+
* </button>
|
|
23
|
+
* {loading && <p>Loading...</p>}
|
|
24
|
+
* {data && <p>Temperature: {data.temperature}</p>}
|
|
25
|
+
* </div>
|
|
26
|
+
* );
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @module @frontmcp/ui/react/hooks
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* State for tool execution.
|
|
34
|
+
*/
|
|
35
|
+
export interface ToolState<T = unknown> {
|
|
36
|
+
/** Tool result data */
|
|
37
|
+
data: T | null;
|
|
38
|
+
/** Whether the tool is currently executing */
|
|
39
|
+
loading: boolean;
|
|
40
|
+
/** Execution error, if any */
|
|
41
|
+
error: Error | null;
|
|
42
|
+
/** Whether the tool has been called at least once */
|
|
43
|
+
called: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Options for useCallTool hook.
|
|
47
|
+
*/
|
|
48
|
+
export interface UseCallToolOptions {
|
|
49
|
+
/** Automatically reset state when tool name changes */
|
|
50
|
+
resetOnToolChange?: boolean;
|
|
51
|
+
/** Callback when tool execution succeeds */
|
|
52
|
+
onSuccess?: (data: unknown) => void;
|
|
53
|
+
/** Callback when tool execution fails */
|
|
54
|
+
onError?: (error: Error) => void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Return type for useCallTool hook.
|
|
58
|
+
*/
|
|
59
|
+
export type UseCallToolReturn<TInput extends object, TOutput> = [
|
|
60
|
+
/** Function to call the tool */
|
|
61
|
+
(args: TInput) => Promise<TOutput | null>,
|
|
62
|
+
/** Current tool state */
|
|
63
|
+
ToolState<TOutput>,
|
|
64
|
+
/** Reset state to initial values */
|
|
65
|
+
() => void
|
|
66
|
+
];
|
|
67
|
+
/**
|
|
68
|
+
* Hook to get the current tool input arguments.
|
|
69
|
+
* Returns the arguments passed to the tool when it was invoked.
|
|
70
|
+
*
|
|
71
|
+
* @typeParam T - Expected shape of the tool input
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```tsx
|
|
75
|
+
* interface WeatherInput {
|
|
76
|
+
* location: string;
|
|
77
|
+
* units?: 'celsius' | 'fahrenheit';
|
|
78
|
+
* }
|
|
79
|
+
*
|
|
80
|
+
* function WeatherWidget() {
|
|
81
|
+
* const input = useToolInput<WeatherInput>();
|
|
82
|
+
*
|
|
83
|
+
* return (
|
|
84
|
+
* <div>
|
|
85
|
+
* <h1>Weather for {input?.location}</h1>
|
|
86
|
+
* <p>Units: {input?.units ?? 'celsius'}</p>
|
|
87
|
+
* </div>
|
|
88
|
+
* );
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function useToolInput<T extends object = Record<string, unknown>>(): T | null;
|
|
93
|
+
/**
|
|
94
|
+
* Hook to get the current tool output/result.
|
|
95
|
+
* Returns the result data from the tool execution.
|
|
96
|
+
*
|
|
97
|
+
* @typeParam T - Expected shape of the tool output
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```tsx
|
|
101
|
+
* interface WeatherOutput {
|
|
102
|
+
* temperature: number;
|
|
103
|
+
* condition: string;
|
|
104
|
+
* humidity: number;
|
|
105
|
+
* }
|
|
106
|
+
*
|
|
107
|
+
* function WeatherDisplay() {
|
|
108
|
+
* const output = useToolOutput<WeatherOutput>();
|
|
109
|
+
*
|
|
110
|
+
* if (!output) return <div>No data</div>;
|
|
111
|
+
*
|
|
112
|
+
* return (
|
|
113
|
+
* <div>
|
|
114
|
+
* <p>Temperature: {output.temperature}°</p>
|
|
115
|
+
* <p>Condition: {output.condition}</p>
|
|
116
|
+
* </div>
|
|
117
|
+
* );
|
|
118
|
+
* }
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function useToolOutput<T = unknown>(): T | null;
|
|
122
|
+
/**
|
|
123
|
+
* Hook to get the structured content from the tool output.
|
|
124
|
+
* This is the parsed/structured version of the tool result.
|
|
125
|
+
*
|
|
126
|
+
* @typeParam T - Expected shape of the structured content
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```tsx
|
|
130
|
+
* interface WeatherData {
|
|
131
|
+
* forecast: Array<{ day: string; temp: number }>;
|
|
132
|
+
* }
|
|
133
|
+
*
|
|
134
|
+
* function ForecastDisplay() {
|
|
135
|
+
* const content = useStructuredContent<WeatherData>();
|
|
136
|
+
*
|
|
137
|
+
* return (
|
|
138
|
+
* <ul>
|
|
139
|
+
* {content?.forecast.map(day => (
|
|
140
|
+
* <li key={day.day}>{day.day}: {day.temp}°</li>
|
|
141
|
+
* ))}
|
|
142
|
+
* </ul>
|
|
143
|
+
* );
|
|
144
|
+
* }
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
export declare function useStructuredContent<T = unknown>(): T | null;
|
|
148
|
+
/**
|
|
149
|
+
* Hook to call an MCP tool with loading and error state management.
|
|
150
|
+
*
|
|
151
|
+
* Returns a tuple with:
|
|
152
|
+
* 1. The call function
|
|
153
|
+
* 2. State object (data, loading, error, called)
|
|
154
|
+
* 3. Reset function
|
|
155
|
+
*
|
|
156
|
+
* @typeParam TInput - Shape of the tool input arguments
|
|
157
|
+
* @typeParam TOutput - Expected shape of the tool output
|
|
158
|
+
*
|
|
159
|
+
* @example Basic usage
|
|
160
|
+
* ```tsx
|
|
161
|
+
* function WeatherButton() {
|
|
162
|
+
* const [getWeather, { data, loading, error }] = useCallTool<
|
|
163
|
+
* { location: string },
|
|
164
|
+
* { temperature: number; condition: string }
|
|
165
|
+
* >('get_weather');
|
|
166
|
+
*
|
|
167
|
+
* return (
|
|
168
|
+
* <div>
|
|
169
|
+
* <button
|
|
170
|
+
* onClick={() => getWeather({ location: 'San Francisco' })}
|
|
171
|
+
* disabled={loading}
|
|
172
|
+
* >
|
|
173
|
+
* {loading ? 'Loading...' : 'Get Weather'}
|
|
174
|
+
* </button>
|
|
175
|
+
* {error && <p className="error">{error.message}</p>}
|
|
176
|
+
* {data && <p>{data.temperature}° - {data.condition}</p>}
|
|
177
|
+
* </div>
|
|
178
|
+
* );
|
|
179
|
+
* }
|
|
180
|
+
* ```
|
|
181
|
+
*
|
|
182
|
+
* @example With callbacks
|
|
183
|
+
* ```tsx
|
|
184
|
+
* function WeatherWidget() {
|
|
185
|
+
* const [getWeather, state, reset] = useCallTool('get_weather', {
|
|
186
|
+
* onSuccess: (data) => console.log('Got weather:', data),
|
|
187
|
+
* onError: (err) => console.error('Failed:', err),
|
|
188
|
+
* });
|
|
189
|
+
*
|
|
190
|
+
* return (
|
|
191
|
+
* <div>
|
|
192
|
+
* <button onClick={() => getWeather({ location: 'NYC' })}>
|
|
193
|
+
* Get Weather
|
|
194
|
+
* </button>
|
|
195
|
+
* <button onClick={reset}>Reset</button>
|
|
196
|
+
* </div>
|
|
197
|
+
* );
|
|
198
|
+
* }
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
export declare function useCallTool<TInput extends object = Record<string, unknown>, TOutput = unknown>(toolName: string, options?: UseCallToolOptions): UseCallToolReturn<TInput, TOutput>;
|
|
202
|
+
/**
|
|
203
|
+
* Hook to manage multiple tool calls.
|
|
204
|
+
* Useful when you need to track state for multiple tools.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```tsx
|
|
208
|
+
* function MultiToolWidget() {
|
|
209
|
+
* const tools = useToolCalls({
|
|
210
|
+
* weather: 'get_weather',
|
|
211
|
+
* news: 'get_news',
|
|
212
|
+
* stocks: 'get_stocks',
|
|
213
|
+
* });
|
|
214
|
+
*
|
|
215
|
+
* return (
|
|
216
|
+
* <div>
|
|
217
|
+
* <button onClick={() => tools.weather.call({ location: 'NYC' })}>
|
|
218
|
+
* Get Weather
|
|
219
|
+
* </button>
|
|
220
|
+
* <button onClick={() => tools.news.call({ topic: 'tech' })}>
|
|
221
|
+
* Get News
|
|
222
|
+
* </button>
|
|
223
|
+
* {tools.weather.loading && <p>Loading weather...</p>}
|
|
224
|
+
* {tools.news.data && <p>News: {tools.news.data.headline}</p>}
|
|
225
|
+
* </div>
|
|
226
|
+
* );
|
|
227
|
+
* }
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
export declare function useToolCalls<T extends Record<string, string>>(toolMap: T): {
|
|
231
|
+
[K in keyof T]: {
|
|
232
|
+
call: (args: Record<string, unknown>) => Promise<unknown>;
|
|
233
|
+
data: unknown;
|
|
234
|
+
loading: boolean;
|
|
235
|
+
error: Error | null;
|
|
236
|
+
reset: () => void;
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* Hook to send a message to the conversation.
|
|
241
|
+
* Returns a function and state for sending messages.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```tsx
|
|
245
|
+
* function ChatWidget() {
|
|
246
|
+
* const [sendMessage, { loading, error, sent }] = useSendMessage();
|
|
247
|
+
*
|
|
248
|
+
* return (
|
|
249
|
+
* <button
|
|
250
|
+
* onClick={() => sendMessage('Here is the weather update!')}
|
|
251
|
+
* disabled={loading}
|
|
252
|
+
* >
|
|
253
|
+
* {loading ? 'Sending...' : 'Send Update'}
|
|
254
|
+
* </button>
|
|
255
|
+
* );
|
|
256
|
+
* }
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
export declare function useSendMessage(): [
|
|
260
|
+
(content: string) => Promise<void>,
|
|
261
|
+
{
|
|
262
|
+
loading: boolean;
|
|
263
|
+
error: Error | null;
|
|
264
|
+
sent: boolean;
|
|
265
|
+
}
|
|
266
|
+
];
|
|
267
|
+
/**
|
|
268
|
+
* Hook to open external links via the bridge.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```tsx
|
|
272
|
+
* function LinkButton() {
|
|
273
|
+
* const openLink = useOpenLink();
|
|
274
|
+
*
|
|
275
|
+
* return (
|
|
276
|
+
* <button onClick={() => openLink('https://example.com')}>
|
|
277
|
+
* Open Website
|
|
278
|
+
* </button>
|
|
279
|
+
* );
|
|
280
|
+
* }
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
export declare function useOpenLink(): (url: string) => Promise<void>;
|