@miragon/mcp-toolkit-ui 0.10.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/README.md +36 -0
- package/dist/app/adapt-data-widget.d.ts +33 -0
- package/dist/app/adapt-data-widget.d.ts.map +1 -0
- package/dist/app/adapt-data-widget.js +35 -0
- package/dist/app/adapt-data-widget.js.map +1 -0
- package/dist/app/builder/CatalogueSheet.d.ts +13 -0
- package/dist/app/builder/CatalogueSheet.d.ts.map +1 -0
- package/dist/app/builder/CatalogueSheet.js +33 -0
- package/dist/app/builder/CatalogueSheet.js.map +1 -0
- package/dist/app/builder/PipelineStrip.d.ts +22 -0
- package/dist/app/builder/PipelineStrip.d.ts.map +1 -0
- package/dist/app/builder/PipelineStrip.js +31 -0
- package/dist/app/builder/PipelineStrip.js.map +1 -0
- package/dist/app/builder/PreviewPane.d.ts +13 -0
- package/dist/app/builder/PreviewPane.d.ts.map +1 -0
- package/dist/app/builder/PreviewPane.js +21 -0
- package/dist/app/builder/PreviewPane.js.map +1 -0
- package/dist/app/builder/SaveDialog.d.ts +14 -0
- package/dist/app/builder/SaveDialog.d.ts.map +1 -0
- package/dist/app/builder/SaveDialog.js +14 -0
- package/dist/app/builder/SaveDialog.js.map +1 -0
- package/dist/app/builder/Toolbar.d.ts +17 -0
- package/dist/app/builder/Toolbar.d.ts.map +1 -0
- package/dist/app/builder/Toolbar.js +15 -0
- package/dist/app/builder/Toolbar.js.map +1 -0
- package/dist/app/builder/Workspace.d.ts +28 -0
- package/dist/app/builder/Workspace.d.ts.map +1 -0
- package/dist/app/builder/Workspace.js +117 -0
- package/dist/app/builder/Workspace.js.map +1 -0
- package/dist/app/builder/builder-model.d.ts +86 -0
- package/dist/app/builder/builder-model.d.ts.map +1 -0
- package/dist/app/builder/builder-model.js +174 -0
- package/dist/app/builder/builder-model.js.map +1 -0
- package/dist/app/builder/builder-reducer.d.ts +71 -0
- package/dist/app/builder/builder-reducer.d.ts.map +1 -0
- package/dist/app/builder/builder-reducer.js +201 -0
- package/dist/app/builder/builder-reducer.js.map +1 -0
- package/dist/app/builder/labels.d.ts +78 -0
- package/dist/app/builder/labels.d.ts.map +1 -0
- package/dist/app/builder/labels.js +71 -0
- package/dist/app/builder/labels.js.map +1 -0
- package/dist/app/builder/status-chip.d.ts +10 -0
- package/dist/app/builder/status-chip.d.ts.map +1 -0
- package/dist/app/builder/status-chip.js +16 -0
- package/dist/app/builder/status-chip.js.map +1 -0
- package/dist/app/host-bridge.d.ts +211 -0
- package/dist/app/host-bridge.d.ts.map +1 -0
- package/dist/app/host-bridge.js +247 -0
- package/dist/app/host-bridge.js.map +1 -0
- package/dist/app/index.d.ts +16 -0
- package/dist/app/index.d.ts.map +1 -0
- package/dist/app/index.js +18 -0
- package/dist/app/index.js.map +1 -0
- package/dist/app/layout-builder.d.ts +48 -0
- package/dist/app/layout-builder.d.ts.map +1 -0
- package/dist/app/layout-builder.js +418 -0
- package/dist/app/layout-builder.js.map +1 -0
- package/dist/app/mcp-app-view.d.ts +43 -0
- package/dist/app/mcp-app-view.d.ts.map +1 -0
- package/dist/app/mcp-app-view.js +169 -0
- package/dist/app/mcp-app-view.js.map +1 -0
- package/dist/app/mcp-toolkit-app.d.ts +18 -0
- package/dist/app/mcp-toolkit-app.d.ts.map +1 -0
- package/dist/app/mcp-toolkit-app.js +22 -0
- package/dist/app/mcp-toolkit-app.js.map +1 -0
- package/dist/app/use-host-actions.d.ts +57 -0
- package/dist/app/use-host-actions.d.ts.map +1 -0
- package/dist/app/use-host-actions.js +42 -0
- package/dist/app/use-host-actions.js.map +1 -0
- package/dist/app/widget-fixture.d.ts +180 -0
- package/dist/app/widget-fixture.d.ts.map +1 -0
- package/dist/app/widget-fixture.js +273 -0
- package/dist/app/widget-fixture.js.map +1 -0
- package/dist/app/widget-props-sheet.d.ts +20 -0
- package/dist/app/widget-props-sheet.d.ts.map +1 -0
- package/dist/app/widget-props-sheet.js +87 -0
- package/dist/app/widget-props-sheet.js.map +1 -0
- package/dist/app/widget-renderer.d.ts +87 -0
- package/dist/app/widget-renderer.d.ts.map +1 -0
- package/dist/app/widget-renderer.js +105 -0
- package/dist/app/widget-renderer.js.map +1 -0
- package/dist/components/DrillButton.d.ts +22 -0
- package/dist/components/DrillButton.d.ts.map +1 -0
- package/dist/components/DrillButton.js +13 -0
- package/dist/components/DrillButton.js.map +1 -0
- package/dist/components/FilterBar.d.ts +28 -0
- package/dist/components/FilterBar.d.ts.map +1 -0
- package/dist/components/FilterBar.js +12 -0
- package/dist/components/FilterBar.js.map +1 -0
- package/dist/components/GridLayout.d.ts +26 -0
- package/dist/components/GridLayout.d.ts.map +1 -0
- package/dist/components/GridLayout.js +31 -0
- package/dist/components/GridLayout.js.map +1 -0
- package/dist/components/GroupCard.d.ts +21 -0
- package/dist/components/GroupCard.d.ts.map +1 -0
- package/dist/components/GroupCard.js +24 -0
- package/dist/components/GroupCard.js.map +1 -0
- package/dist/components/KpiGrid.d.ts +43 -0
- package/dist/components/KpiGrid.d.ts.map +1 -0
- package/dist/components/KpiGrid.js +35 -0
- package/dist/components/KpiGrid.js.map +1 -0
- package/dist/components/ListFooter.d.ts +22 -0
- package/dist/components/ListFooter.d.ts.map +1 -0
- package/dist/components/ListFooter.js +13 -0
- package/dist/components/ListFooter.js.map +1 -0
- package/dist/components/Pills.d.ts +25 -0
- package/dist/components/Pills.d.ts.map +1 -0
- package/dist/components/Pills.js +17 -0
- package/dist/components/Pills.js.map +1 -0
- package/dist/components/SectionHeading.d.ts +16 -0
- package/dist/components/SectionHeading.d.ts.map +1 -0
- package/dist/components/SectionHeading.js +10 -0
- package/dist/components/SectionHeading.js.map +1 -0
- package/dist/components/WidgetHeader.d.ts +21 -0
- package/dist/components/WidgetHeader.d.ts.map +1 -0
- package/dist/components/WidgetHeader.js +11 -0
- package/dist/components/WidgetHeader.js.map +1 -0
- package/dist/hooks/index.d.ts +11 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +7 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/use-debounced-value.d.ts +7 -0
- package/dist/hooks/use-debounced-value.d.ts.map +1 -0
- package/dist/hooks/use-debounced-value.js +15 -0
- package/dist/hooks/use-debounced-value.js.map +1 -0
- package/dist/hooks/use-mobile.d.ts +6 -0
- package/dist/hooks/use-mobile.d.ts.map +1 -0
- package/dist/hooks/use-mobile.js +19 -0
- package/dist/hooks/use-mobile.js.map +1 -0
- package/dist/hooks/use-tool-query.d.ts +21 -0
- package/dist/hooks/use-tool-query.d.ts.map +1 -0
- package/dist/hooks/use-tool-query.js +47 -0
- package/dist/hooks/use-tool-query.js.map +1 -0
- package/dist/hooks/use-tool-result-recovery.d.ts +54 -0
- package/dist/hooks/use-tool-result-recovery.d.ts.map +1 -0
- package/dist/hooks/use-tool-result-recovery.js +93 -0
- package/dist/hooks/use-tool-result-recovery.js.map +1 -0
- package/dist/hooks/use-view-data.d.ts +19 -0
- package/dist/hooks/use-view-data.d.ts.map +1 -0
- package/dist/hooks/use-view-data.js +18 -0
- package/dist/hooks/use-view-data.js.map +1 -0
- package/dist/hooks/use-view-tool-query.d.ts +18 -0
- package/dist/hooks/use-view-tool-query.d.ts.map +1 -0
- package/dist/hooks/use-view-tool-query.js +29 -0
- package/dist/hooks/use-view-tool-query.js.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/parse-tool-result.d.ts +39 -0
- package/dist/lib/parse-tool-result.d.ts.map +1 -0
- package/dist/lib/parse-tool-result.js +66 -0
- package/dist/lib/parse-tool-result.js.map +1 -0
- package/dist/lib/tone-utils.d.ts +18 -0
- package/dist/lib/tone-utils.d.ts.map +1 -0
- package/dist/lib/tone-utils.js +25 -0
- package/dist/lib/tone-utils.js.map +1 -0
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +6 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/locale/index.d.ts +3 -0
- package/dist/locale/index.d.ts.map +1 -0
- package/dist/locale/index.js +7 -0
- package/dist/locale/index.js.map +1 -0
- package/dist/locale/locale-provider.d.ts +50 -0
- package/dist/locale/locale-provider.d.ts.map +1 -0
- package/dist/locale/locale-provider.js +47 -0
- package/dist/locale/locale-provider.js.map +1 -0
- package/dist/primitives/alert.d.ts +10 -0
- package/dist/primitives/alert.d.ts.map +1 -0
- package/dist/primitives/alert.js +25 -0
- package/dist/primitives/alert.js.map +1 -0
- package/dist/primitives/badge.d.ts +8 -0
- package/dist/primitives/badge.d.ts.map +1 -0
- package/dist/primitives/badge.js +34 -0
- package/dist/primitives/badge.js.map +1 -0
- package/dist/primitives/button.d.ts +11 -0
- package/dist/primitives/button.d.ts.map +1 -0
- package/dist/primitives/button.js +36 -0
- package/dist/primitives/button.js.map +1 -0
- package/dist/primitives/card.d.ts +12 -0
- package/dist/primitives/card.d.ts.map +1 -0
- package/dist/primitives/card.js +25 -0
- package/dist/primitives/card.js.map +1 -0
- package/dist/primitives/dialog.d.ts +18 -0
- package/dist/primitives/dialog.d.ts.map +1 -0
- package/dist/primitives/dialog.js +38 -0
- package/dist/primitives/dialog.js.map +1 -0
- package/dist/primitives/input.d.ts +4 -0
- package/dist/primitives/input.d.ts.map +1 -0
- package/dist/primitives/input.js +7 -0
- package/dist/primitives/input.js.map +1 -0
- package/dist/primitives/scroll-area.d.ts +6 -0
- package/dist/primitives/scroll-area.d.ts.map +1 -0
- package/dist/primitives/scroll-area.js +11 -0
- package/dist/primitives/scroll-area.js.map +1 -0
- package/dist/primitives/select.d.ts +16 -0
- package/dist/primitives/select.d.ts.map +1 -0
- package/dist/primitives/select.js +38 -0
- package/dist/primitives/select.js.map +1 -0
- package/dist/primitives/separator.d.ts +4 -0
- package/dist/primitives/separator.d.ts.map +1 -0
- package/dist/primitives/separator.js +9 -0
- package/dist/primitives/separator.js.map +1 -0
- package/dist/primitives/sheet.d.ts +15 -0
- package/dist/primitives/sheet.d.ts.map +1 -0
- package/dist/primitives/sheet.js +41 -0
- package/dist/primitives/sheet.js.map +1 -0
- package/dist/primitives/skeleton.d.ts +3 -0
- package/dist/primitives/skeleton.d.ts.map +1 -0
- package/dist/primitives/skeleton.js +7 -0
- package/dist/primitives/skeleton.js.map +1 -0
- package/dist/primitives/switch.d.ts +5 -0
- package/dist/primitives/switch.d.ts.map +1 -0
- package/dist/primitives/switch.js +8 -0
- package/dist/primitives/switch.js.map +1 -0
- package/dist/primitives/table.d.ts +11 -0
- package/dist/primitives/table.d.ts.map +1 -0
- package/dist/primitives/table.js +28 -0
- package/dist/primitives/table.js.map +1 -0
- package/dist/primitives/tabs.d.ts +12 -0
- package/dist/primitives/tabs.d.ts.map +1 -0
- package/dist/primitives/tabs.js +29 -0
- package/dist/primitives/tabs.js.map +1 -0
- package/dist/providers/query-provider.d.ts +11 -0
- package/dist/providers/query-provider.d.ts.map +1 -0
- package/dist/providers/query-provider.js +20 -0
- package/dist/providers/query-provider.js.map +1 -0
- package/dist/theme/create-theme.d.ts +130 -0
- package/dist/theme/create-theme.d.ts.map +1 -0
- package/dist/theme/create-theme.js +65 -0
- package/dist/theme/create-theme.js.map +1 -0
- package/dist/theme/index.d.ts +7 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +7 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/theme/presets.d.ts +25 -0
- package/dist/theme/presets.d.ts.map +1 -0
- package/dist/theme/presets.js +68 -0
- package/dist/theme/presets.js.map +1 -0
- package/dist/theme/theme-provider.d.ts +69 -0
- package/dist/theme/theme-provider.d.ts.map +1 -0
- package/dist/theme/theme-provider.js +79 -0
- package/dist/theme/theme-provider.js.map +1 -0
- package/package.json +71 -0
- package/src/app/adapt-data-widget.tsx +51 -0
- package/src/app/builder/CatalogueSheet.tsx +230 -0
- package/src/app/builder/PipelineStrip.tsx +260 -0
- package/src/app/builder/PreviewPane.tsx +72 -0
- package/src/app/builder/SaveDialog.tsx +95 -0
- package/src/app/builder/Toolbar.tsx +95 -0
- package/src/app/builder/Workspace.tsx +483 -0
- package/src/app/builder/builder-model.test.ts +351 -0
- package/src/app/builder/builder-model.ts +213 -0
- package/src/app/builder/builder-reducer.test.ts +441 -0
- package/src/app/builder/builder-reducer.ts +289 -0
- package/src/app/builder/labels.ts +139 -0
- package/src/app/builder/status-chip.tsx +37 -0
- package/src/app/host-bridge.test.ts +206 -0
- package/src/app/host-bridge.tsx +371 -0
- package/src/app/index.ts +51 -0
- package/src/app/layout-builder.tsx +872 -0
- package/src/app/mcp-app-view.tsx +367 -0
- package/src/app/mcp-toolkit-app.tsx +25 -0
- package/src/app/use-host-actions.test.ts +16 -0
- package/src/app/use-host-actions.tsx +88 -0
- package/src/app/widget-fixture.test.ts +108 -0
- package/src/app/widget-fixture.tsx +441 -0
- package/src/app/widget-props-sheet.tsx +285 -0
- package/src/app/widget-renderer.test.ts +42 -0
- package/src/app/widget-renderer.tsx +200 -0
- package/src/components/DrillButton.tsx +37 -0
- package/src/components/FilterBar.tsx +68 -0
- package/src/components/GridLayout.tsx +49 -0
- package/src/components/GroupCard.tsx +52 -0
- package/src/components/KpiGrid.tsx +134 -0
- package/src/components/ListFooter.tsx +48 -0
- package/src/components/Pills.tsx +45 -0
- package/src/components/SectionHeading.tsx +26 -0
- package/src/components/WidgetHeader.tsx +51 -0
- package/src/globals.css +168 -0
- package/src/hooks/index.ts +17 -0
- package/src/hooks/use-debounced-value.ts +15 -0
- package/src/hooks/use-mobile.ts +24 -0
- package/src/hooks/use-tool-query.ts +63 -0
- package/src/hooks/use-tool-result-recovery.test.ts +65 -0
- package/src/hooks/use-tool-result-recovery.ts +144 -0
- package/src/hooks/use-view-data.ts +31 -0
- package/src/hooks/use-view-tool-query.ts +38 -0
- package/src/index.ts +134 -0
- package/src/lib/parse-tool-result.test.ts +139 -0
- package/src/lib/parse-tool-result.ts +89 -0
- package/src/lib/tone-utils.test.ts +35 -0
- package/src/lib/tone-utils.ts +38 -0
- package/src/lib/utils.ts +6 -0
- package/src/locale/index.ts +7 -0
- package/src/locale/locale-provider.tsx +81 -0
- package/src/primitives/alert.tsx +60 -0
- package/src/primitives/badge.tsx +49 -0
- package/src/primitives/button.tsx +62 -0
- package/src/primitives/card.tsx +92 -0
- package/src/primitives/dialog.tsx +144 -0
- package/src/primitives/input.tsx +21 -0
- package/src/primitives/scroll-area.tsx +54 -0
- package/src/primitives/select.tsx +173 -0
- package/src/primitives/separator.tsx +21 -0
- package/src/primitives/sheet.tsx +134 -0
- package/src/primitives/skeleton.tsx +13 -0
- package/src/primitives/switch.tsx +24 -0
- package/src/primitives/table.tsx +87 -0
- package/src/primitives/tabs.tsx +79 -0
- package/src/providers/query-provider.tsx +38 -0
- package/src/theme/create-theme.test.ts +108 -0
- package/src/theme/create-theme.ts +158 -0
- package/src/theme/index.ts +9 -0
- package/src/theme/presets.ts +82 -0
- package/src/theme/theme-provider.tsx +152 -0
- package/src/ui-catalog.test.ts +112 -0
- package/ui-catalog.json +1280 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface UseToolQueryOptions<TData = unknown, TSelected = TData> {
|
|
2
|
+
enabled?: boolean;
|
|
3
|
+
select?: (data: TData) => TSelected;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Loads data from a widget tool via TanStack Query.
|
|
7
|
+
*
|
|
8
|
+
* `args` is appended to the effective query key so two callers that share
|
|
9
|
+
* the supplied `queryKey` but pass different `args` get separate cache
|
|
10
|
+
* entries (otherwise the second caller silently reads stale data from the
|
|
11
|
+
* first — the classic queryKey-vs-args trap). `select` transforms data on
|
|
12
|
+
* each read without mutating the cache.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useToolQuery<TData = unknown, TSelected = TData>(queryKey: unknown[], toolName: string, args: object, opts?: UseToolQueryOptions<TData, TSelected>): import("@tanstack/react-query").UseQueryResult<NoInfer<TSelected>, Error>;
|
|
15
|
+
/**
|
|
16
|
+
* Executes a mutation via a widget tool and invalidates configured query keys.
|
|
17
|
+
*/
|
|
18
|
+
export declare function useToolMutation<TData = unknown>(toolName: string, opts?: {
|
|
19
|
+
invalidateKeys?: unknown[][];
|
|
20
|
+
}): import("@tanstack/react-query").UseMutationResult<TData, Error, Record<string, unknown>, unknown>;
|
|
21
|
+
//# sourceMappingURL=use-tool-query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-tool-query.d.ts","sourceRoot":"","sources":["../../src/hooks/use-tool-query.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,mBAAmB,CAAC,KAAK,GAAG,OAAO,EAAE,SAAS,GAAG,KAAK;IACrE,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,SAAS,CAAA;CACpC;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,KAAK,GAAG,OAAO,EAAE,SAAS,GAAG,KAAK,EAC7D,QAAQ,EAAE,OAAO,EAAE,EACnB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,mBAAmB,CAAC,KAAK,EAAE,SAAS,CAAC,6EAc7C;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,GAAG,OAAO,EAC7C,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE;IAAE,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,CAAA;CAAE,qGAmBxC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|
2
|
+
import { useCallTool } from "../providers/query-provider.js";
|
|
3
|
+
import { parseToolResult } from "../lib/parse-tool-result.js";
|
|
4
|
+
/**
|
|
5
|
+
* Loads data from a widget tool via TanStack Query.
|
|
6
|
+
*
|
|
7
|
+
* `args` is appended to the effective query key so two callers that share
|
|
8
|
+
* the supplied `queryKey` but pass different `args` get separate cache
|
|
9
|
+
* entries (otherwise the second caller silently reads stale data from the
|
|
10
|
+
* first — the classic queryKey-vs-args trap). `select` transforms data on
|
|
11
|
+
* each read without mutating the cache.
|
|
12
|
+
*/
|
|
13
|
+
export function useToolQuery(queryKey, toolName, args, opts) {
|
|
14
|
+
const callTool = useCallTool();
|
|
15
|
+
return useQuery({
|
|
16
|
+
queryKey: [...queryKey, args],
|
|
17
|
+
queryFn: async () => {
|
|
18
|
+
if (!callTool)
|
|
19
|
+
throw new Error("callTool not available");
|
|
20
|
+
const result = await callTool(toolName, args);
|
|
21
|
+
return parseToolResult(result);
|
|
22
|
+
},
|
|
23
|
+
select: opts?.select,
|
|
24
|
+
enabled: !!callTool && (opts?.enabled ?? true),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Executes a mutation via a widget tool and invalidates configured query keys.
|
|
29
|
+
*/
|
|
30
|
+
export function useToolMutation(toolName, opts) {
|
|
31
|
+
const callTool = useCallTool();
|
|
32
|
+
const queryClient = useQueryClient();
|
|
33
|
+
return useMutation({
|
|
34
|
+
mutationFn: async (args) => {
|
|
35
|
+
if (!callTool)
|
|
36
|
+
throw new Error("callTool not available");
|
|
37
|
+
const result = await callTool(toolName, args);
|
|
38
|
+
return parseToolResult(result);
|
|
39
|
+
},
|
|
40
|
+
onSuccess: async () => {
|
|
41
|
+
if (opts?.invalidateKeys) {
|
|
42
|
+
await Promise.all(opts.invalidateKeys.map((key) => queryClient.refetchQueries({ queryKey: key })));
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=use-tool-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-tool-query.js","sourceRoot":"","sources":["../../src/hooks/use-tool-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC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C;gBACzB,MAAM,OAAO,CAAC,GAAG,CACf,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,cAAc,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,CAChF,CAAA;YACH,CAAC;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recovery for hosts that deliver the `ui/notifications/tool-result`
|
|
3
|
+
* notification without `structuredContent` (observed on claude.ai and Claude
|
|
4
|
+
* Desktop, which forward only the model-facing `content` blocks). The
|
|
5
|
+
* mcp-use bridge then hands the widget an empty props object and the shell
|
|
6
|
+
* would idle on its loading skeleton forever.
|
|
7
|
+
*
|
|
8
|
+
* When the result is ready but the payload is invalid, the hook re-executes
|
|
9
|
+
* the originating tool once via the host bridge's official `callTool` —
|
|
10
|
+
* tool-call RESPONSES carry `structuredContent` intact on those hosts — and
|
|
11
|
+
* exposes the decoded payload. Spec-conforming hosts (e.g. the mcp-use
|
|
12
|
+
* inspector) deliver a valid payload up front, so the recovery never fires
|
|
13
|
+
* there.
|
|
14
|
+
*
|
|
15
|
+
* Assumes the originating tool is a read-only render pipeline (true for all
|
|
16
|
+
* toolkit `render-view`/`show_*` tools) — the re-execution must be safe to
|
|
17
|
+
* repeat.
|
|
18
|
+
*/
|
|
19
|
+
export interface ToolResultRecoveryOptions {
|
|
20
|
+
/** `!isPending` from `useWidget` — the host reported a finished tool call. */
|
|
21
|
+
resultReady: boolean;
|
|
22
|
+
/** The props the host delivered (`useWidget().props`). */
|
|
23
|
+
props: unknown;
|
|
24
|
+
/**
|
|
25
|
+
* Validates a candidate payload. MUST be referentially stable (module-level
|
|
26
|
+
* function or memoised) — it is an effect dependency.
|
|
27
|
+
*/
|
|
28
|
+
isValid: (value: unknown) => boolean;
|
|
29
|
+
/** The tool arguments from `ui/notifications/tool-input` (`useWidget().toolInput`). */
|
|
30
|
+
toolInput: Record<string, unknown> | null | undefined;
|
|
31
|
+
/** Raw host context (`useWidget().hostContext`); `toolInfo` names the originating tool. */
|
|
32
|
+
hostContext: Record<string, unknown> | null | undefined;
|
|
33
|
+
/** The bridge's `callTool` (`useWidget().callTool`). */
|
|
34
|
+
callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
35
|
+
}
|
|
36
|
+
export interface ToolResultRecoveryState<T> {
|
|
37
|
+
/** The recovered payload, `null` until the re-execution resolved (or when it failed). */
|
|
38
|
+
data: T | null;
|
|
39
|
+
/** `true` when the single recovery attempt failed — the shell keeps its skeleton, no retry loop. */
|
|
40
|
+
failed: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Resolves the originating tool name from the host context's `toolInfo`.
|
|
44
|
+
* Reads the SEP-1865 shape first (`toolInfo.tool.name`), then the flattened
|
|
45
|
+
* variants some hosts send (`toolInfo.name`, `toolInfo.toolName`).
|
|
46
|
+
*/
|
|
47
|
+
export declare function resolveRecoveryToolName(hostContext: unknown): string | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Decodes a re-executed tool result and validates it. Exposed for tests;
|
|
50
|
+
* the hook uses it on the `callTool` response.
|
|
51
|
+
*/
|
|
52
|
+
export declare function decodeRecoveredResult<T>(result: unknown, isValid: (value: unknown) => boolean): T | null;
|
|
53
|
+
export declare function useToolResultRecovery<T>(options: ToolResultRecoveryOptions): ToolResultRecoveryState<T>;
|
|
54
|
+
//# sourceMappingURL=use-tool-result-recovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-tool-result-recovery.d.ts","sourceRoot":"","sources":["../../src/hooks/use-tool-result-recovery.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,WAAW,yBAAyB;IACxC,8EAA8E;IAC9E,WAAW,EAAE,OAAO,CAAA;IACpB,0DAA0D;IAC1D,KAAK,EAAE,OAAO,CAAA;IACd;;;OAGG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAA;IACpC,uFAAuF;IACvF,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,CAAA;IACrD,2FAA2F;IAC3F,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,CAAA;IACvD,wDAAwD;IACxD,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAC5E;AAED,MAAM,WAAW,uBAAuB,CAAC,CAAC;IACxC,yFAAyF;IACzF,IAAI,EAAE,CAAC,GAAG,IAAI,CAAA;IACd,oGAAoG;IACpG,MAAM,EAAE,OAAO,CAAA;CAChB;AAID;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAehF;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,GACnC,CAAC,GAAG,IAAI,CAQV;AAED,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,OAAO,EAAE,yBAAyB,GACjC,uBAAuB,CAAC,CAAC,CAAC,CAqD5B"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { parseToolResult } from "../lib/parse-tool-result.js";
|
|
3
|
+
const IDLE = { data: null, failed: false };
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the originating tool name from the host context's `toolInfo`.
|
|
6
|
+
* Reads the SEP-1865 shape first (`toolInfo.tool.name`), then the flattened
|
|
7
|
+
* variants some hosts send (`toolInfo.name`, `toolInfo.toolName`).
|
|
8
|
+
*/
|
|
9
|
+
export function resolveRecoveryToolName(hostContext) {
|
|
10
|
+
if (!hostContext || typeof hostContext !== "object")
|
|
11
|
+
return undefined;
|
|
12
|
+
const info = hostContext.toolInfo;
|
|
13
|
+
if (!info || typeof info !== "object")
|
|
14
|
+
return undefined;
|
|
15
|
+
const rec = info;
|
|
16
|
+
const tool = rec.tool;
|
|
17
|
+
const candidates = [
|
|
18
|
+
tool && typeof tool === "object" ? tool.name : undefined,
|
|
19
|
+
rec.name,
|
|
20
|
+
rec.toolName,
|
|
21
|
+
];
|
|
22
|
+
for (const candidate of candidates) {
|
|
23
|
+
if (typeof candidate === "string" && candidate.length > 0)
|
|
24
|
+
return candidate;
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Decodes a re-executed tool result and validates it. Exposed for tests;
|
|
30
|
+
* the hook uses it on the `callTool` response.
|
|
31
|
+
*/
|
|
32
|
+
export function decodeRecoveredResult(result, isValid) {
|
|
33
|
+
let decoded;
|
|
34
|
+
try {
|
|
35
|
+
decoded = parseToolResult(result);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return decoded !== null && isValid(decoded) ? decoded : null;
|
|
41
|
+
}
|
|
42
|
+
export function useToolResultRecovery(options) {
|
|
43
|
+
const { resultReady, props, isValid, toolInput, hostContext, callTool } = options;
|
|
44
|
+
const [state, setState] = useState(IDLE);
|
|
45
|
+
// Single-flight: the promise ref survives StrictMode's dev-mode
|
|
46
|
+
// effect re-run (cleanup + setup on the same instance), so the re-run
|
|
47
|
+
// re-subscribes to the SAME in-flight call instead of firing a second one.
|
|
48
|
+
const flightRef = useRef(null);
|
|
49
|
+
const flightInputRef = useRef(null);
|
|
50
|
+
const toolName = resolveRecoveryToolName(hostContext);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
// A new tool run (result no longer ready, or fresh tool-input identity)
|
|
53
|
+
// invalidates any previous recovery attempt and re-arms the single-flight.
|
|
54
|
+
if (flightRef.current && (!resultReady || flightInputRef.current !== toolInput)) {
|
|
55
|
+
flightRef.current = null;
|
|
56
|
+
setState((prev) => (prev.data === null && !prev.failed ? prev : IDLE));
|
|
57
|
+
}
|
|
58
|
+
// Never fire on conforming hosts (valid payload) or before the
|
|
59
|
+
// originating tool is known.
|
|
60
|
+
if (!resultReady || isValid(props) || toolName === undefined)
|
|
61
|
+
return;
|
|
62
|
+
if (!flightRef.current) {
|
|
63
|
+
flightInputRef.current = toolInput;
|
|
64
|
+
flightRef.current = (async () => {
|
|
65
|
+
try {
|
|
66
|
+
const result = await callTool(toolName, toolInput ?? {});
|
|
67
|
+
const data = decodeRecoveredResult(result, isValid);
|
|
68
|
+
if (data !== null)
|
|
69
|
+
return { data, failed: false };
|
|
70
|
+
console.warn(`[mcp-toolkit] tool-result recovery: re-executing "${toolName}" returned no usable payload`);
|
|
71
|
+
return { data: null, failed: true };
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
console.warn(`[mcp-toolkit] tool-result recovery for "${toolName}" failed:`, err);
|
|
75
|
+
return { data: null, failed: true };
|
|
76
|
+
}
|
|
77
|
+
})();
|
|
78
|
+
}
|
|
79
|
+
const flight = flightRef.current;
|
|
80
|
+
let stale = false;
|
|
81
|
+
void flight.then((outcome) => {
|
|
82
|
+
// Drop the outcome when this subscription was superseded or the flight
|
|
83
|
+
// was invalidated by a newer tool run.
|
|
84
|
+
if (!stale && flightRef.current === flight)
|
|
85
|
+
setState(outcome);
|
|
86
|
+
});
|
|
87
|
+
return () => {
|
|
88
|
+
stale = true;
|
|
89
|
+
};
|
|
90
|
+
}, [resultReady, props, isValid, toolName, toolInput, callTool]);
|
|
91
|
+
return state;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=use-tool-result-recovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-tool-result-recovery.js","sourceRoot":"","sources":["../../src/hooks/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True while self-fetching with no data yet — the first paint of a cockpit cell. */
|
|
4
|
+
loading: boolean;
|
|
5
|
+
error: Error | null;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The seam that lets one widget component serve both modes without a duplicate UI.
|
|
9
|
+
*
|
|
10
|
+
* Standalone (a `*_show_*` widget) the agent's tool result is handed in via
|
|
11
|
+
* `initialData` (from the view's stepData, e.g. through `adaptDataWidget`) and
|
|
12
|
+
* returned verbatim. Embedded in a self-fetching cockpit only scope params are
|
|
13
|
+
* passed, so the component fetches `tool` with `args` under `key` — disabled
|
|
14
|
+
* unless data is absent AND `ready` (i.e. the required id/key is present).
|
|
15
|
+
* Sibling widgets sharing `key` dedupe to a single call, so a composed view of
|
|
16
|
+
* N widgets over one data feed fetches once.
|
|
17
|
+
*/
|
|
18
|
+
export declare function useViewData<T>(initialData: T | null | undefined, key: ReadonlyArray<unknown>, tool: string, args: Record<string, unknown>, ready: boolean): ViewDataResult<T>;
|
|
19
|
+
//# sourceMappingURL=use-view-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-view-data.d.ts","sourceRoot":"","sources":["../../src/hooks/use-view-data.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,IAAI,EAAE,CAAC,GAAG,IAAI,CAAA;IACd,qFAAqF;IACrF,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CACpB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,WAAW,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EACjC,GAAG,EAAE,aAAa,CAAC,OAAO,CAAC,EAC3B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,KAAK,EAAE,OAAO,GACb,cAAc,CAAC,CAAC,CAAC,CAInB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useToolQuery } from "./use-tool-query.js";
|
|
2
|
+
/**
|
|
3
|
+
* The seam that lets one widget component serve both modes without a duplicate UI.
|
|
4
|
+
*
|
|
5
|
+
* Standalone (a `*_show_*` widget) the agent's tool result is handed in via
|
|
6
|
+
* `initialData` (from the view's stepData, e.g. through `adaptDataWidget`) and
|
|
7
|
+
* returned verbatim. Embedded in a self-fetching cockpit only scope params are
|
|
8
|
+
* passed, so the component fetches `tool` with `args` under `key` — disabled
|
|
9
|
+
* unless data is absent AND `ready` (i.e. the required id/key is present).
|
|
10
|
+
* Sibling widgets sharing `key` dedupe to a single call, so a composed view of
|
|
11
|
+
* N widgets over one data feed fetches once.
|
|
12
|
+
*/
|
|
13
|
+
export function useViewData(initialData, key, tool, args, ready) {
|
|
14
|
+
const query = useToolQuery([...key], tool, args, { enabled: !initialData && ready });
|
|
15
|
+
const data = initialData ?? query.data ?? null;
|
|
16
|
+
return { data, loading: !data && ready && !query.isError, error: query.error ?? null };
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=use-view-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-view-data.js","sourceRoot":"","sources":["../../src/hooks/use-view-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AASlD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CACzB,WAAiC,EACjC,GAA2B,EAC3B,IAAY,EACZ,IAA6B,EAC7B,KAAc;IAEd,MAAM,KAAK,GAAG,YAAY,CAAI,CAAC,GAAG,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,WAAW,IAAI,KAAK,EAAE,CAAC,CAAA;IACvF,MAAM,IAAI,GAAG,WAAW,IAAI,KAAK,CAAC,IAAI,IAAI,IAAI,CAAA;IAC9C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,IAAI,EAAE,CAAA;AACxF,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type UseQueryResult } from "@tanstack/react-query";
|
|
2
|
+
export interface UseViewToolQueryOptions {
|
|
3
|
+
enabled?: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Self-fetch hook for `*_show_*` widget tools — the envelope-unwrapping sibling
|
|
7
|
+
* of {@link useToolQuery}. A widget tool's text channel carries only a model
|
|
8
|
+
* summary and its `structuredContent` is the full view envelope, so decoding
|
|
9
|
+
* with the plain {@link parseToolResult} would hand the widget the whole
|
|
10
|
+
* envelope; this hook decodes via {@link parseViewToolResult} (single-step →
|
|
11
|
+
* flat data, multi-step → keyed by step id) instead.
|
|
12
|
+
*
|
|
13
|
+
* `args` is appended to the effective query key — same queryKey-vs-args
|
|
14
|
+
* contract as {@link useToolQuery}, so sibling widgets sharing a query key
|
|
15
|
+
* collapse to a single deduped tool call.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useViewToolQuery<T = unknown>(queryKey: unknown[], toolName: string, args: object, opts?: UseViewToolQueryOptions): UseQueryResult<T, Error>;
|
|
18
|
+
//# sourceMappingURL=use-view-tool-query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-view-tool-query.d.ts","sourceRoot":"","sources":["../../src/hooks/use-view-tool-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAIrE,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,GAAG,OAAO,EAC1C,QAAQ,EAAE,OAAO,EAAE,EACnB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,uBAAuB,GAC7B,cAAc,CAAC,CAAC,EAAE,KAAK,CAAC,CAY1B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useQuery } from "@tanstack/react-query";
|
|
2
|
+
import { useCallTool } from "../providers/query-provider.js";
|
|
3
|
+
import { parseViewToolResult } from "../lib/parse-tool-result.js";
|
|
4
|
+
/**
|
|
5
|
+
* Self-fetch hook for `*_show_*` widget tools — the envelope-unwrapping sibling
|
|
6
|
+
* of {@link useToolQuery}. A widget tool's text channel carries only a model
|
|
7
|
+
* summary and its `structuredContent` is the full view envelope, so decoding
|
|
8
|
+
* with the plain {@link parseToolResult} would hand the widget the whole
|
|
9
|
+
* envelope; this hook decodes via {@link parseViewToolResult} (single-step →
|
|
10
|
+
* flat data, multi-step → keyed by step id) instead.
|
|
11
|
+
*
|
|
12
|
+
* `args` is appended to the effective query key — same queryKey-vs-args
|
|
13
|
+
* contract as {@link useToolQuery}, so sibling widgets sharing a query key
|
|
14
|
+
* collapse to a single deduped tool call.
|
|
15
|
+
*/
|
|
16
|
+
export function useViewToolQuery(queryKey, toolName, args, opts) {
|
|
17
|
+
const callTool = useCallTool();
|
|
18
|
+
return useQuery({
|
|
19
|
+
queryKey: [...queryKey, args],
|
|
20
|
+
queryFn: async () => {
|
|
21
|
+
if (!callTool)
|
|
22
|
+
throw new Error("callTool not available");
|
|
23
|
+
const result = await callTool(toolName, args);
|
|
24
|
+
return parseViewToolResult(result);
|
|
25
|
+
},
|
|
26
|
+
enabled: !!callTool && (opts?.enabled ?? true),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=use-view-tool-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-view-tool-query.js","sourceRoot":"","sources":["../../src/hooks/use-view-tool-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAuB,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAMjE;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAAmB,EACnB,QAAgB,EAChB,IAAY,EACZ,IAA8B;IAE9B,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAA;IAE9B,OAAO,QAAQ,CAAW;QACxB,QAAQ,EAAE,CAAC,GAAG,QAAQ,EAAE,IAAI,CAAC;QAC7B,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,IAAI,CAAC,QAAQ;gBAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;YACxD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;YAC7C,OAAO,mBAAmB,CAAI,MAAM,CAAC,CAAA;QACvC,CAAC;QACD,OAAO,EAAE,CAAC,CAAC,QAAQ,IAAI,CAAC,IAAI,EAAE,OAAO,IAAI,IAAI,CAAC;KAC/C,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export { Card, CardHeader, CardFooter, CardTitle, CardAction, CardDescription, CardContent, } from "./primitives/card.js";
|
|
2
|
+
export { Badge, badgeVariants } from "./primitives/badge.js";
|
|
3
|
+
export { Table, TableHeader, TableBody, TableFooter, TableRow, TableHead, TableCell, TableCaption, } from "./primitives/table.js";
|
|
4
|
+
export { Separator } from "./primitives/separator.js";
|
|
5
|
+
export { Skeleton } from "./primitives/skeleton.js";
|
|
6
|
+
export { Tabs, TabsList, TabsTrigger, TabsContent } from "./primitives/tabs.js";
|
|
7
|
+
export { Button, buttonVariants } from "./primitives/button.js";
|
|
8
|
+
export { Input } from "./primitives/input.js";
|
|
9
|
+
export { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, } from "./primitives/select.js";
|
|
10
|
+
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, } from "./primitives/dialog.js";
|
|
11
|
+
export { Alert, AlertDescription, AlertTitle } from "./primitives/alert.js";
|
|
12
|
+
export { Switch } from "./primitives/switch.js";
|
|
13
|
+
export { ScrollArea, ScrollBar } from "./primitives/scroll-area.js";
|
|
14
|
+
export { Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger, } from "./primitives/sheet.js";
|
|
15
|
+
export { useIsMobile } from "./hooks/use-mobile.js";
|
|
16
|
+
export { useToolQuery, useToolMutation } from "./hooks/use-tool-query.js";
|
|
17
|
+
export type { UseToolQueryOptions } from "./hooks/use-tool-query.js";
|
|
18
|
+
export { useDebouncedValue } from "./hooks/use-debounced-value.js";
|
|
19
|
+
export { TONE_SOFT, TONE_DOT, TONE_TEXT } from "./lib/tone-utils.js";
|
|
20
|
+
export type { ToneVariant } from "./lib/tone-utils.js";
|
|
21
|
+
export { GridLayout, GridItem } from "./components/GridLayout.js";
|
|
22
|
+
export type { GridLayoutProps, GridItemProps } from "./components/GridLayout.js";
|
|
23
|
+
export { KpiGrid } from "./components/KpiGrid.js";
|
|
24
|
+
export type { KpiGridProps, KpiGridHeader, KpiCell } from "./components/KpiGrid.js";
|
|
25
|
+
export { LivePill, CountPill } from "./components/Pills.js";
|
|
26
|
+
export type { LivePillProps, CountPillProps } from "./components/Pills.js";
|
|
27
|
+
export { SectionHeading } from "./components/SectionHeading.js";
|
|
28
|
+
export type { SectionHeadingProps } from "./components/SectionHeading.js";
|
|
29
|
+
export { WidgetHeader } from "./components/WidgetHeader.js";
|
|
30
|
+
export type { WidgetHeaderProps } from "./components/WidgetHeader.js";
|
|
31
|
+
export { GroupCard } from "./components/GroupCard.js";
|
|
32
|
+
export type { GroupCardProps } from "./components/GroupCard.js";
|
|
33
|
+
export { FilterBar } from "./components/FilterBar.js";
|
|
34
|
+
export type { FilterBarProps, FilterChip } from "./components/FilterBar.js";
|
|
35
|
+
export { DrillButton } from "./components/DrillButton.js";
|
|
36
|
+
export type { DrillButtonProps } from "./components/DrillButton.js";
|
|
37
|
+
export { ListFooter } from "./components/ListFooter.js";
|
|
38
|
+
export type { ListFooterProps } from "./components/ListFooter.js";
|
|
39
|
+
export { AppQueryProvider, useCallTool, queryClient } from "./providers/query-provider.js";
|
|
40
|
+
export { createTheme, ThemeProvider, useTheme, themePresets } from "./theme/index.js";
|
|
41
|
+
export type { ThemeTokens, ThemeDefinition, ThemeVars, CreateThemeOptions, ThemeMode, ThemeContextValue, ThemeProviderProps, ThemePresetId, } from "./theme/index.js";
|
|
42
|
+
export { LocaleProvider, useLocale, useTranslate } from "./locale/index.js";
|
|
43
|
+
export type { LocaleContextValue, LocaleProviderProps, BoundTranslate } from "./locale/index.js";
|
|
44
|
+
export { cn } from "./lib/utils.js";
|
|
45
|
+
export { parseToolResult, parseViewToolResult } from "./lib/parse-tool-result.js";
|
|
46
|
+
export type { ParseToolResultOptions } from "./lib/parse-tool-result.js";
|
|
47
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,IAAI,EACJ,UAAU,EACV,UAAU,EACV,SAAS,EACT,UAAU,EACV,eAAe,EACf,WAAW,GACZ,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,EACL,KAAK,EACL,WAAW,EACX,SAAS,EACT,WAAW,EACX,QAAQ,EACR,SAAS,EACT,SAAS,EACT,YAAY,GACb,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAA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,MAAM,kBAAkB,CAAA;AAOzB,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC3E,YAAY,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAQhG,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AACjF,YAAY,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// shadcn base primitives
|
|
2
|
+
export { Card, CardHeader, CardFooter, CardTitle, CardAction, CardDescription, CardContent, } from "./primitives/card.js";
|
|
3
|
+
export { Badge, badgeVariants } from "./primitives/badge.js";
|
|
4
|
+
export { Table, TableHeader, TableBody, TableFooter, TableRow, TableHead, TableCell, TableCaption, } from "./primitives/table.js";
|
|
5
|
+
export { Separator } from "./primitives/separator.js";
|
|
6
|
+
export { Skeleton } from "./primitives/skeleton.js";
|
|
7
|
+
export { Tabs, TabsList, TabsTrigger, TabsContent } from "./primitives/tabs.js";
|
|
8
|
+
export { Button, buttonVariants } from "./primitives/button.js";
|
|
9
|
+
export { Input } from "./primitives/input.js";
|
|
10
|
+
export { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, } from "./primitives/select.js";
|
|
11
|
+
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, } from "./primitives/dialog.js";
|
|
12
|
+
export { Alert, AlertDescription, AlertTitle } from "./primitives/alert.js";
|
|
13
|
+
export { Switch } from "./primitives/switch.js";
|
|
14
|
+
export { ScrollArea, ScrollBar } from "./primitives/scroll-area.js";
|
|
15
|
+
export { Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger, } from "./primitives/sheet.js";
|
|
16
|
+
// Hooks
|
|
17
|
+
// NOTE: the view-tool hooks (`useViewToolQuery`, `useViewData`) are exported
|
|
18
|
+
// from the `./hooks` subpath only — see `packages/ui/src/hooks/index.ts`.
|
|
19
|
+
export { useIsMobile } from "./hooks/use-mobile.js";
|
|
20
|
+
export { useToolQuery, useToolMutation } from "./hooks/use-tool-query.js";
|
|
21
|
+
export { useDebouncedValue } from "./hooks/use-debounced-value.js";
|
|
22
|
+
// Tone token system — the semantic status tones (ToneVariant + TONE_* maps)
|
|
23
|
+
// behind the tone-aware components below. Pure data + class strings.
|
|
24
|
+
export { TONE_SOFT, TONE_DOT, TONE_TEXT } from "./lib/tone-utils.js";
|
|
25
|
+
// Composed components — focused widget building blocks assembled from the
|
|
26
|
+
// primitives. Pure (React + primitives + cn), so they live in the root barrel.
|
|
27
|
+
export { GridLayout, GridItem } from "./components/GridLayout.js";
|
|
28
|
+
export { KpiGrid } from "./components/KpiGrid.js";
|
|
29
|
+
export { LivePill, CountPill } from "./components/Pills.js";
|
|
30
|
+
export { SectionHeading } from "./components/SectionHeading.js";
|
|
31
|
+
export { WidgetHeader } from "./components/WidgetHeader.js";
|
|
32
|
+
export { GroupCard } from "./components/GroupCard.js";
|
|
33
|
+
export { FilterBar } from "./components/FilterBar.js";
|
|
34
|
+
export { DrillButton } from "./components/DrillButton.js";
|
|
35
|
+
export { ListFooter } from "./components/ListFooter.js";
|
|
36
|
+
// Providers
|
|
37
|
+
export { AppQueryProvider, useCallTool, queryClient } from "./providers/query-provider.js";
|
|
38
|
+
// Theming / white-label token system. Browser-safe (React + DOM only, no
|
|
39
|
+
// `mcp-use/react`), so it belongs in this root barrel: a consumer can re-skin
|
|
40
|
+
// the toolkit's primitives from a single switch without pulling in the host
|
|
41
|
+
// runtime. See packages/ui/src/theme/ and docs/guides/white-labeling.md.
|
|
42
|
+
export { createTheme, ThemeProvider, useTheme, themePresets } from "./theme/index.js";
|
|
43
|
+
// i18n / localization. Browser-safe (React only, no `mcp-use/react`), so it
|
|
44
|
+
// belongs in this root barrel: a consumer wraps its widget tree in
|
|
45
|
+
// <LocaleProvider locale=… translator=…> and reads the active locale with
|
|
46
|
+
// useLocale/useTranslate. Pairs with `createTranslator` from
|
|
47
|
+
// `@miragon/mcp-toolkit-core`. See packages/ui/src/locale/.
|
|
48
|
+
export { LocaleProvider, useLocale, useTranslate } from "./locale/index.js";
|
|
49
|
+
// NOTE: MCP App shell (McpAppView, WidgetRenderer) is exported from the
|
|
50
|
+
// `./app` subpath only. Keeping it out of the main barrel prevents consumers
|
|
51
|
+
// that only need primitives (e.g. an admin portal) from pulling `mcp-use/react`
|
|
52
|
+
// and its langchain transitive peer into their Vite bundle.
|
|
53
|
+
// Utils
|
|
54
|
+
export { cn } from "./lib/utils.js";
|
|
55
|
+
export { parseToolResult, parseViewToolResult } from "./lib/parse-tool-result.js";
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,OAAO,EACL,IAAI,EACJ,UAAU,EACV,UAAU,EACV,SAAS,EACT,UAAU,EACV,eAAe,EACf,WAAW,GACZ,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,EACL,KAAK,EACL,WAAW,EACX,SAAS,EACT,WAAW,EACX,QAAQ,EACR,SAAS,EACT,SAAS,EACT,YAAY,GACb,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAC/E,O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AAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAGvD,YAAY;AACZ,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAE1F,yEAAyE;AACzE,8EAA8E;AAC9E,4EAA4E;AAC5E,yEAAyE;AACzE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAYrF,4EAA4E;AAC5E,mEAAmE;AACnE,0EAA0E;AAC1E,6DAA6D;AAC7D,4DAA4D;AAC5D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAG3E,wEAAwE;AACxE,6EAA6E;AAC7E,gFAAgF;AAChF,4DAA4D;AAE5D,QAAQ;AACR,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface ParseToolResultOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Which channel to read first when both are present.
|
|
4
|
+
*
|
|
5
|
+
* - `"structured"` (default): `structuredContent`-first. Since the widget-tool
|
|
6
|
+
* "text-channel diet" the text block carries only a short model-facing
|
|
7
|
+
* summary, while the data payload lives in `structuredContent` (the view
|
|
8
|
+
* builders and `*_data` feeds always set it). The text channel remains a
|
|
9
|
+
* fallback for plain results from other servers.
|
|
10
|
+
* - `"text"`: text-first (the pre-0.4 behaviour) — JSON-decode the first text
|
|
11
|
+
* block, then fall back to `structuredContent`. Kept for callers that
|
|
12
|
+
* deliberately prefer a tool's human-readable text payload.
|
|
13
|
+
*/
|
|
14
|
+
prefer?: "structured" | "text";
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Decodes an MCP tool result down to its data payload.
|
|
18
|
+
*
|
|
19
|
+
* Default (`prefer: "structured"`): `isError` → throw the first text block,
|
|
20
|
+
* then `structuredContent` (if non-null), then JSON-decode the first text
|
|
21
|
+
* block (verbatim string if it isn't JSON), then the raw result.
|
|
22
|
+
*
|
|
23
|
+
* This is **structured-first** — a deliberate, observable change from the
|
|
24
|
+
* pre-0.4 text-first parsing: tools that return BOTH a text summary and
|
|
25
|
+
* `structuredContent` now yield the structured payload, not the summary
|
|
26
|
+
* string. `useToolQuery`/`useToolMutation` and the MCP App shell all decode
|
|
27
|
+
* through this one parser so the convention is uniform.
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseToolResult<T = unknown>(result: unknown, opts?: ParseToolResultOptions): T;
|
|
30
|
+
/**
|
|
31
|
+
* Decodes a `*_show_*` widget-tool result down to the widget's flat data
|
|
32
|
+
* payload. `buildSingleWidgetView`/`buildComposedView` wrap the data in the
|
|
33
|
+
* `McpAppView` envelope (`context.stepData[<id>].data`); this unwraps it:
|
|
34
|
+
* single-step views yield the step's data directly, multi-step composed views
|
|
35
|
+
* yield an object keyed by step id. Non-envelope results (e.g. `*_data`
|
|
36
|
+
* feeds) pass through {@link parseToolResult} unchanged.
|
|
37
|
+
*/
|
|
38
|
+
export declare function parseViewToolResult<T = unknown>(result: unknown): T;
|
|
39
|
+
//# sourceMappingURL=parse-tool-result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-tool-result.d.ts","sourceRoot":"","sources":["../../src/lib/parse-tool-result.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,sBAAsB;IACrC;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,EAAE,YAAY,GAAG,MAAM,CAAA;CAC/B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,sBAAsB,GAAG,CAAC,CAmC9F;AAKD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,CAAC,CASnE"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes an MCP tool result down to its data payload.
|
|
3
|
+
*
|
|
4
|
+
* Default (`prefer: "structured"`): `isError` → throw the first text block,
|
|
5
|
+
* then `structuredContent` (if non-null), then JSON-decode the first text
|
|
6
|
+
* block (verbatim string if it isn't JSON), then the raw result.
|
|
7
|
+
*
|
|
8
|
+
* This is **structured-first** — a deliberate, observable change from the
|
|
9
|
+
* pre-0.4 text-first parsing: tools that return BOTH a text summary and
|
|
10
|
+
* `structuredContent` now yield the structured payload, not the summary
|
|
11
|
+
* string. `useToolQuery`/`useToolMutation` and the MCP App shell all decode
|
|
12
|
+
* through this one parser so the convention is uniform.
|
|
13
|
+
*/
|
|
14
|
+
export function parseToolResult(result, opts) {
|
|
15
|
+
const r = result;
|
|
16
|
+
if (r?.isError)
|
|
17
|
+
throw new Error(r.content?.[0]?.text ?? "Tool call failed");
|
|
18
|
+
const fromStructured = () => r?.structuredContent != null ? r.structuredContent : undefined;
|
|
19
|
+
const fromText = () => {
|
|
20
|
+
const text = r?.content?.[0]?.text;
|
|
21
|
+
if (text == null)
|
|
22
|
+
return undefined;
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(text);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return text;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
if (opts?.prefer === "text") {
|
|
31
|
+
const text = fromText();
|
|
32
|
+
if (text !== undefined)
|
|
33
|
+
return text;
|
|
34
|
+
const structured = fromStructured();
|
|
35
|
+
if (structured !== undefined)
|
|
36
|
+
return structured;
|
|
37
|
+
return r;
|
|
38
|
+
}
|
|
39
|
+
const structured = fromStructured();
|
|
40
|
+
if (structured !== undefined)
|
|
41
|
+
return structured;
|
|
42
|
+
const text = fromText();
|
|
43
|
+
if (text !== undefined)
|
|
44
|
+
return text;
|
|
45
|
+
return r;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Decodes a `*_show_*` widget-tool result down to the widget's flat data
|
|
49
|
+
* payload. `buildSingleWidgetView`/`buildComposedView` wrap the data in the
|
|
50
|
+
* `McpAppView` envelope (`context.stepData[<id>].data`); this unwraps it:
|
|
51
|
+
* single-step views yield the step's data directly, multi-step composed views
|
|
52
|
+
* yield an object keyed by step id. Non-envelope results (e.g. `*_data`
|
|
53
|
+
* feeds) pass through {@link parseToolResult} unchanged.
|
|
54
|
+
*/
|
|
55
|
+
export function parseViewToolResult(result) {
|
|
56
|
+
const parsed = parseToolResult(result);
|
|
57
|
+
const ctx = parsed?.context;
|
|
58
|
+
const stepIds = ctx?.stepIds;
|
|
59
|
+
if (ctx?.stepData && Array.isArray(stepIds) && stepIds.length > 0) {
|
|
60
|
+
if (stepIds.length === 1)
|
|
61
|
+
return ctx.stepData[stepIds[0] ?? ""]?.data;
|
|
62
|
+
return Object.fromEntries(stepIds.map((id) => [id, ctx.stepData[id]?.data]));
|
|
63
|
+
}
|
|
64
|
+
return parsed;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=parse-tool-result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-tool-result.js","sourceRoot":"","sources":["../../src/lib/parse-tool-result.ts"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,eAAe,CAAc,MAAe,EAAE,IAA6B;IACzF,MAAM,CAAC,GAAG,MAMG,CAAA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AC,CAAA;IAC/C,MAAM,GAAG,GAAI,MAA8B,EAAE,OAAO,CAAA;IACpD,MAAM,OAAO,GAAG,GAAG,EAAE,OAAO,CAAA;IAC5B,IAAI,GAAG,EAAE,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClE,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,IAAS,CAAA;QAC1E,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAM,CAAA;IACnF,CAAC;IACD,OAAO,MAAW,CAAA;AACpB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for the semantic "tones" used across the tone-aware
|
|
3
|
+
* components (`Pills`, `KpiGrid`, `WidgetHeader`, …).
|
|
4
|
+
*
|
|
5
|
+
* Each tone maps to the status tokens defined in `globals.css`
|
|
6
|
+
* (`--danger`, `--warning`, `--success`, `--info`) plus the shadcn neutral ramp
|
|
7
|
+
* for the `neutral` tone. All tokens carry light + dark values, so these class
|
|
8
|
+
* strings re-theme automatically — change a tone in one place instead of
|
|
9
|
+
* hand-rolling `tone === "x" ? "…" : "…"` ternaries at every call site.
|
|
10
|
+
*/
|
|
11
|
+
export type ToneVariant = "neutral" | "info" | "success" | "warning" | "danger";
|
|
12
|
+
/** Tinted background + readable foreground — badges, icon tiles, pills. */
|
|
13
|
+
export declare const TONE_SOFT: Record<ToneVariant, string>;
|
|
14
|
+
/** Solid dot color — status dots next to a label. */
|
|
15
|
+
export declare const TONE_DOT: Record<ToneVariant, string>;
|
|
16
|
+
/** Foreground-only color — metric values, inline emphasis. */
|
|
17
|
+
export declare const TONE_TEXT: Record<ToneVariant, string>;
|
|
18
|
+
//# sourceMappingURL=tone-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tone-utils.d.ts","sourceRoot":"","sources":["../../src/lib/tone-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAA;AAE/E,2EAA2E;AAC3E,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAMjD,CAAA;AAED,qDAAqD;AACrD,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAMhD,CAAA;AAED,8DAA8D;AAC9D,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAMjD,CAAA"}
|