@seed-ship/mcp-ui-solid 1.1.0 → 1.2.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/CHANGELOG.md +41 -0
- package/README.md +94 -3
- package/dist/components/FooterRenderer.cjs +75 -0
- package/dist/components/FooterRenderer.cjs.map +1 -0
- package/dist/components/FooterRenderer.js +75 -0
- package/dist/components/FooterRenderer.js.map +1 -0
- package/dist/components/GridRenderer.cjs +82 -0
- package/dist/components/GridRenderer.cjs.map +1 -0
- package/dist/components/GridRenderer.d.ts +49 -0
- package/dist/components/GridRenderer.d.ts.map +1 -0
- package/dist/components/GridRenderer.js +82 -0
- package/dist/components/GridRenderer.js.map +1 -0
- package/dist/components/UIResourceRenderer.cjs +88 -36
- package/dist/components/UIResourceRenderer.cjs.map +1 -1
- package/dist/components/UIResourceRenderer.d.ts.map +1 -1
- package/dist/components/UIResourceRenderer.js +90 -38
- package/dist/components/UIResourceRenderer.js.map +1 -1
- package/dist/context/MCPActionContext.cjs +149 -0
- package/dist/context/MCPActionContext.cjs.map +1 -0
- package/dist/context/MCPActionContext.d.ts +158 -0
- package/dist/context/MCPActionContext.d.ts.map +1 -0
- package/dist/context/MCPActionContext.js +149 -0
- package/dist/context/MCPActionContext.js.map +1 -0
- package/dist/context/index.d.ts +8 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/useAction.cjs +49 -0
- package/dist/hooks/useAction.cjs.map +1 -0
- package/dist/hooks/useAction.d.ts +79 -0
- package/dist/hooks/useAction.d.ts.map +1 -0
- package/dist/hooks/useAction.js +49 -0
- package/dist/hooks/useAction.js.map +1 -0
- package/dist/hooks.cjs +3 -0
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +2 -0
- package/dist/hooks.js +4 -1
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +8 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +41 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types.d.ts +41 -2
- package/package.json +1 -1
- package/src/components/GridRenderer.tsx +140 -0
- package/src/components/UIResourceRenderer.tsx +65 -25
- package/src/context/MCPActionContext.tsx +350 -0
- package/src/context/index.ts +19 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useAction.ts +138 -0
- package/src/index.ts +14 -1
- package/src/types/index.ts +48 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const web = require("solid-js/web");
|
|
4
|
+
const solidJs = require("solid-js");
|
|
5
|
+
const MCPActionContext = solidJs.createContext();
|
|
6
|
+
const defaultExecutor = async (request) => {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
9
|
+
if (typeof window !== "undefined") {
|
|
10
|
+
const event = new CustomEvent("mcp-action", {
|
|
11
|
+
detail: {
|
|
12
|
+
toolName: request.toolName,
|
|
13
|
+
params: request.params || {},
|
|
14
|
+
spaceIds: request.spaceIds,
|
|
15
|
+
macroId: request.macroId
|
|
16
|
+
},
|
|
17
|
+
bubbles: true
|
|
18
|
+
});
|
|
19
|
+
const responseHandler = (e) => {
|
|
20
|
+
var _a, _b, _c;
|
|
21
|
+
const customEvent = e;
|
|
22
|
+
window.removeEventListener("mcp-action-response", responseHandler);
|
|
23
|
+
resolve({
|
|
24
|
+
success: ((_a = customEvent.detail) == null ? void 0 : _a.success) ?? true,
|
|
25
|
+
data: (_b = customEvent.detail) == null ? void 0 : _b.data,
|
|
26
|
+
error: (_c = customEvent.detail) == null ? void 0 : _c.error,
|
|
27
|
+
timestamp,
|
|
28
|
+
toolName: request.toolName
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
window.addEventListener("mcp-action-response", responseHandler);
|
|
32
|
+
window.dispatchEvent(event);
|
|
33
|
+
setTimeout(() => {
|
|
34
|
+
window.removeEventListener("mcp-action-response", responseHandler);
|
|
35
|
+
resolve({
|
|
36
|
+
success: true,
|
|
37
|
+
data: {
|
|
38
|
+
dispatched: true
|
|
39
|
+
},
|
|
40
|
+
timestamp,
|
|
41
|
+
toolName: request.toolName
|
|
42
|
+
});
|
|
43
|
+
}, 100);
|
|
44
|
+
} else {
|
|
45
|
+
resolve({
|
|
46
|
+
success: false,
|
|
47
|
+
error: "Actions not available server-side",
|
|
48
|
+
timestamp,
|
|
49
|
+
toolName: request.toolName
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
const MCPActionProvider = (props) => {
|
|
55
|
+
const [isExecuting, setIsExecuting] = solidJs.createSignal(false);
|
|
56
|
+
const [lastResult, setLastResult] = solidJs.createSignal();
|
|
57
|
+
const [spaceIds, setSpaceIds] = solidJs.createSignal(props.spaceIds || []);
|
|
58
|
+
const [macroId, setMacroId] = solidJs.createSignal(props.macroId);
|
|
59
|
+
const [availableTools, setAvailableTools] = solidJs.createSignal(props.availableTools || []);
|
|
60
|
+
const executeAction = async (request) => {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
setIsExecuting(true);
|
|
63
|
+
try {
|
|
64
|
+
const enrichedRequest = {
|
|
65
|
+
...request,
|
|
66
|
+
spaceIds: request.spaceIds || spaceIds(),
|
|
67
|
+
macroId: request.macroId || macroId()
|
|
68
|
+
};
|
|
69
|
+
const executor = props.executor || defaultExecutor;
|
|
70
|
+
const result = await executor(enrichedRequest);
|
|
71
|
+
setLastResult(result);
|
|
72
|
+
(_a = props.onAction) == null ? void 0 : _a.call(props, enrichedRequest, result);
|
|
73
|
+
if (result.success && props.onWebhook) {
|
|
74
|
+
props.onWebhook({
|
|
75
|
+
type: "action-completed",
|
|
76
|
+
payload: {
|
|
77
|
+
request: enrichedRequest,
|
|
78
|
+
result
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
const errorResult = {
|
|
85
|
+
success: false,
|
|
86
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
87
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
88
|
+
toolName: request.toolName
|
|
89
|
+
};
|
|
90
|
+
setLastResult(errorResult);
|
|
91
|
+
(_b = props.onAction) == null ? void 0 : _b.call(props, request, errorResult);
|
|
92
|
+
return errorResult;
|
|
93
|
+
} finally {
|
|
94
|
+
setIsExecuting(false);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const contextValue = {
|
|
98
|
+
executeAction,
|
|
99
|
+
availableTools,
|
|
100
|
+
spaceIds,
|
|
101
|
+
macroId,
|
|
102
|
+
isExecuting,
|
|
103
|
+
lastResult
|
|
104
|
+
};
|
|
105
|
+
return web.createComponent(MCPActionContext.Provider, {
|
|
106
|
+
value: contextValue,
|
|
107
|
+
get children() {
|
|
108
|
+
return props.children;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
function useMCPAction() {
|
|
113
|
+
const context = solidJs.useContext(MCPActionContext);
|
|
114
|
+
if (!context) {
|
|
115
|
+
throw new Error("useMCPAction must be used within an MCPActionProvider");
|
|
116
|
+
}
|
|
117
|
+
return context;
|
|
118
|
+
}
|
|
119
|
+
function useMCPActionSafe() {
|
|
120
|
+
const context = solidJs.useContext(MCPActionContext);
|
|
121
|
+
if (context) {
|
|
122
|
+
return context;
|
|
123
|
+
}
|
|
124
|
+
const [isExecuting, setIsExecuting] = solidJs.createSignal(false);
|
|
125
|
+
const [lastResult, setLastResult] = solidJs.createSignal();
|
|
126
|
+
const executeAction = async (request) => {
|
|
127
|
+
setIsExecuting(true);
|
|
128
|
+
try {
|
|
129
|
+
const result = await defaultExecutor(request);
|
|
130
|
+
setLastResult(result);
|
|
131
|
+
return result;
|
|
132
|
+
} finally {
|
|
133
|
+
setIsExecuting(false);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
return {
|
|
137
|
+
executeAction,
|
|
138
|
+
availableTools: () => [],
|
|
139
|
+
spaceIds: () => [],
|
|
140
|
+
macroId: () => void 0,
|
|
141
|
+
isExecuting,
|
|
142
|
+
lastResult
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
exports.MCPActionContext = MCPActionContext;
|
|
146
|
+
exports.MCPActionProvider = MCPActionProvider;
|
|
147
|
+
exports.useMCPAction = useMCPAction;
|
|
148
|
+
exports.useMCPActionSafe = useMCPActionSafe;
|
|
149
|
+
//# sourceMappingURL=MCPActionContext.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MCPActionContext.cjs","sources":["../../src/context/MCPActionContext.tsx"],"sourcesContent":["/**\n * MCPActionContext - Context provider for MCP action execution\n * Phase 5.0: Quick Wins - Replaces CustomEvent with typed context for Mastra integration\n */\n\nimport { createContext, createSignal, useContext, ParentComponent, Accessor } from 'solid-js'\n\n/**\n * Action request payload\n */\nexport interface ActionRequest {\n /**\n * MCP tool name to execute\n */\n toolName: string\n\n /**\n * Tool parameters\n */\n params?: Record<string, any>\n\n /**\n * Optional space IDs for multi-space context\n */\n spaceIds?: string[]\n\n /**\n * Optional macro ID for template execution\n */\n macroId?: string\n}\n\n/**\n * Action result from execution\n */\nexport interface ActionResult {\n /**\n * Whether the action was successful\n */\n success: boolean\n\n /**\n * Result data (if successful)\n */\n data?: any\n\n /**\n * Error message (if failed)\n */\n error?: string\n\n /**\n * Execution timestamp\n */\n timestamp: string\n\n /**\n * Tool that was executed\n */\n toolName: string\n}\n\n/**\n * Context value interface\n */\nexport interface MCPActionContextValue {\n /**\n * Execute an MCP action\n */\n executeAction: (request: ActionRequest) => Promise<ActionResult>\n\n /**\n * Currently available tools (from MCP server)\n */\n availableTools: Accessor<string[]>\n\n /**\n * Space IDs in current context\n */\n spaceIds: Accessor<string[]>\n\n /**\n * Current macro ID (if executing within a template)\n */\n macroId: Accessor<string | undefined>\n\n /**\n * Whether an action is currently executing\n */\n isExecuting: Accessor<boolean>\n\n /**\n * Last action result\n */\n lastResult: Accessor<ActionResult | undefined>\n}\n\n/**\n * Props for MCPActionProvider\n */\nexport interface MCPActionProviderProps {\n /**\n * Space IDs for multi-space queries\n */\n spaceIds?: string[]\n\n /**\n * Macro ID when executing within a template\n */\n macroId?: string\n\n /**\n * Available MCP tools\n */\n availableTools?: string[]\n\n /**\n * Callback for action execution (for audit logging)\n */\n onAction?: (request: ActionRequest, result: ActionResult) => void\n\n /**\n * Callback for webhook events (n8n, Zapier integration)\n */\n onWebhook?: (event: { type: string; payload: any }) => void\n\n /**\n * Custom action executor (override default)\n */\n executor?: (request: ActionRequest) => Promise<ActionResult>\n}\n\n// Create the context with undefined default\nconst MCPActionContext = createContext<MCPActionContextValue>()\n\n/**\n * Default action executor using CustomEvent fallback\n * This maintains backward compatibility while allowing Context-based usage\n */\nconst defaultExecutor = async (request: ActionRequest): Promise<ActionResult> => {\n return new Promise((resolve) => {\n const timestamp = new Date().toISOString()\n\n // Dispatch CustomEvent for backward compatibility with existing listeners\n if (typeof window !== 'undefined') {\n const event = new CustomEvent('mcp-action', {\n detail: {\n toolName: request.toolName,\n params: request.params || {},\n spaceIds: request.spaceIds,\n macroId: request.macroId,\n },\n bubbles: true,\n })\n\n // Listen for response event\n const responseHandler = (e: Event) => {\n const customEvent = e as CustomEvent\n window.removeEventListener('mcp-action-response', responseHandler)\n resolve({\n success: customEvent.detail?.success ?? true,\n data: customEvent.detail?.data,\n error: customEvent.detail?.error,\n timestamp,\n toolName: request.toolName,\n })\n }\n\n window.addEventListener('mcp-action-response', responseHandler)\n window.dispatchEvent(event)\n\n // Timeout fallback - resolve as success if no response in 100ms\n // (indicates no listener, action was dispatched)\n setTimeout(() => {\n window.removeEventListener('mcp-action-response', responseHandler)\n resolve({\n success: true,\n data: { dispatched: true },\n timestamp,\n toolName: request.toolName,\n })\n }, 100)\n } else {\n // Server-side: return immediately\n resolve({\n success: false,\n error: 'Actions not available server-side',\n timestamp,\n toolName: request.toolName,\n })\n }\n })\n}\n\n/**\n * MCPActionProvider - Provides action execution context to child components\n *\n * @example\n * ```tsx\n * <MCPActionProvider\n * spaceIds={['space-123']}\n * macroId=\"sales_overview\"\n * onAction={(req, res) => audit(req, res)}\n * >\n * <UIResourceRenderer layout={layout} />\n * </MCPActionProvider>\n * ```\n */\nexport const MCPActionProvider: ParentComponent<MCPActionProviderProps> = (props) => {\n const [isExecuting, setIsExecuting] = createSignal(false)\n const [lastResult, setLastResult] = createSignal<ActionResult>()\n const [spaceIds, setSpaceIds] = createSignal<string[]>(props.spaceIds || [])\n const [macroId, setMacroId] = createSignal<string | undefined>(props.macroId)\n const [availableTools, setAvailableTools] = createSignal<string[]>(props.availableTools || [])\n\n // Update signals when props change\n // Note: This is a simple approach; for more complex scenarios, consider createEffect\n\n const executeAction = async (request: ActionRequest): Promise<ActionResult> => {\n setIsExecuting(true)\n\n try {\n // Enrich request with context\n const enrichedRequest: ActionRequest = {\n ...request,\n spaceIds: request.spaceIds || spaceIds(),\n macroId: request.macroId || macroId(),\n }\n\n // Execute using custom executor or default\n const executor = props.executor || defaultExecutor\n const result = await executor(enrichedRequest)\n\n setLastResult(result)\n\n // Call audit callback if provided\n props.onAction?.(enrichedRequest, result)\n\n // Trigger webhook if provided and action was successful\n if (result.success && props.onWebhook) {\n props.onWebhook({\n type: 'action-completed',\n payload: {\n request: enrichedRequest,\n result,\n },\n })\n }\n\n return result\n } catch (error) {\n const errorResult: ActionResult = {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error',\n timestamp: new Date().toISOString(),\n toolName: request.toolName,\n }\n\n setLastResult(errorResult)\n props.onAction?.(request, errorResult)\n\n return errorResult\n } finally {\n setIsExecuting(false)\n }\n }\n\n const contextValue: MCPActionContextValue = {\n executeAction,\n availableTools,\n spaceIds,\n macroId,\n isExecuting,\n lastResult,\n }\n\n return (\n <MCPActionContext.Provider value={contextValue}>\n {props.children}\n </MCPActionContext.Provider>\n )\n}\n\n/**\n * Hook to access MCP action context\n * Throws if used outside of MCPActionProvider\n *\n * @example\n * ```tsx\n * const { executeAction, isExecuting } = useMCPAction()\n *\n * const handleClick = async () => {\n * const result = await executeAction({\n * toolName: 'search.hub',\n * params: { query: 'revenue Q4' },\n * })\n * }\n * ```\n */\nexport function useMCPAction(): MCPActionContextValue {\n const context = useContext(MCPActionContext)\n if (!context) {\n throw new Error('useMCPAction must be used within an MCPActionProvider')\n }\n return context\n}\n\n/**\n * Hook to access MCP action context with fallback for components\n * outside of provider (uses CustomEvent fallback)\n *\n * @example\n * ```tsx\n * const { executeAction, isExecuting } = useMCPActionSafe()\n * // Works even without MCPActionProvider\n * ```\n */\nexport function useMCPActionSafe(): MCPActionContextValue {\n const context = useContext(MCPActionContext)\n\n if (context) {\n return context\n }\n\n // Fallback implementation for components outside provider\n const [isExecuting, setIsExecuting] = createSignal(false)\n const [lastResult, setLastResult] = createSignal<ActionResult>()\n\n const executeAction = async (request: ActionRequest): Promise<ActionResult> => {\n setIsExecuting(true)\n try {\n const result = await defaultExecutor(request)\n setLastResult(result)\n return result\n } finally {\n setIsExecuting(false)\n }\n }\n\n return {\n executeAction,\n availableTools: () => [],\n spaceIds: () => [],\n macroId: () => undefined,\n isExecuting,\n lastResult,\n }\n}\n\nexport { MCPActionContext }\n"],"names":["MCPActionContext","createContext","defaultExecutor","request","Promise","resolve","timestamp","Date","toISOString","window","event","CustomEvent","detail","toolName","params","spaceIds","macroId","bubbles","responseHandler","e","customEvent","removeEventListener","success","data","error","addEventListener","dispatchEvent","setTimeout","dispatched","MCPActionProvider","props","isExecuting","setIsExecuting","createSignal","lastResult","setLastResult","setSpaceIds","setMacroId","availableTools","setAvailableTools","executeAction","enrichedRequest","executor","result","onAction","onWebhook","type","payload","errorResult","Error","message","contextValue","_$createComponent","Provider","value","children","useMCPAction","context","useContext","useMCPActionSafe","undefined"],"mappings":";;;;AAqIA,MAAMA,mBAAmBC,QAAAA,cAAAA;AAMzB,MAAMC,kBAAkB,OAAOC,YAAkD;AAC/E,SAAO,IAAIC,QAASC,CAAAA,YAAY;AAC9B,UAAMC,aAAY,oBAAIC,KAAAA,GAAOC,YAAAA;AAG7B,QAAI,OAAOC,WAAW,aAAa;AACjC,YAAMC,QAAQ,IAAIC,YAAY,cAAc;AAAA,QAC1CC,QAAQ;AAAA,UACNC,UAAUV,QAAQU;AAAAA,UAClBC,QAAQX,QAAQW,UAAU,CAAA;AAAA,UAC1BC,UAAUZ,QAAQY;AAAAA,UAClBC,SAASb,QAAQa;AAAAA,QAAAA;AAAAA,QAEnBC,SAAS;AAAA,MAAA,CACV;AAGD,YAAMC,kBAAkBA,CAACC,MAAa;;AACpC,cAAMC,cAAcD;AACpBV,eAAOY,oBAAoB,uBAAuBH,eAAe;AACjEb,gBAAQ;AAAA,UACNiB,WAASF,iBAAYR,WAAZQ,mBAAoBE,YAAW;AAAA,UACxCC,OAAMH,iBAAYR,WAAZQ,mBAAoBG;AAAAA,UAC1BC,QAAOJ,iBAAYR,WAAZQ,mBAAoBI;AAAAA,UAC3BlB;AAAAA,UACAO,UAAUV,QAAQU;AAAAA,QAAAA,CACnB;AAAA,MACH;AAEAJ,aAAOgB,iBAAiB,uBAAuBP,eAAe;AAC9DT,aAAOiB,cAAchB,KAAK;AAI1BiB,iBAAW,MAAM;AACflB,eAAOY,oBAAoB,uBAAuBH,eAAe;AACjEb,gBAAQ;AAAA,UACNiB,SAAS;AAAA,UACTC,MAAM;AAAA,YAAEK,YAAY;AAAA,UAAA;AAAA,UACpBtB;AAAAA,UACAO,UAAUV,QAAQU;AAAAA,QAAAA,CACnB;AAAA,MACH,GAAG,GAAG;AAAA,IACR,OAAO;AAELR,cAAQ;AAAA,QACNiB,SAAS;AAAA,QACTE,OAAO;AA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
* MCPActionContext - Context provider for MCP action execution
|
|
3
|
+
* Phase 5.0: Quick Wins - Replaces CustomEvent with typed context for Mastra integration
|
|
4
|
+
*/
|
|
5
|
+
import { ParentComponent, Accessor } from 'solid-js';
|
|
6
|
+
/**
|
|
7
|
+
* Action request payload
|
|
8
|
+
*/
|
|
9
|
+
export interface ActionRequest {
|
|
10
|
+
/**
|
|
11
|
+
* MCP tool name to execute
|
|
12
|
+
*/
|
|
13
|
+
toolName: string;
|
|
14
|
+
/**
|
|
15
|
+
* Tool parameters
|
|
16
|
+
*/
|
|
17
|
+
params?: Record<string, any>;
|
|
18
|
+
/**
|
|
19
|
+
* Optional space IDs for multi-space context
|
|
20
|
+
*/
|
|
21
|
+
spaceIds?: string[];
|
|
22
|
+
/**
|
|
23
|
+
* Optional macro ID for template execution
|
|
24
|
+
*/
|
|
25
|
+
macroId?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Action result from execution
|
|
29
|
+
*/
|
|
30
|
+
export interface ActionResult {
|
|
31
|
+
/**
|
|
32
|
+
* Whether the action was successful
|
|
33
|
+
*/
|
|
34
|
+
success: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Result data (if successful)
|
|
37
|
+
*/
|
|
38
|
+
data?: any;
|
|
39
|
+
/**
|
|
40
|
+
* Error message (if failed)
|
|
41
|
+
*/
|
|
42
|
+
error?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Execution timestamp
|
|
45
|
+
*/
|
|
46
|
+
timestamp: string;
|
|
47
|
+
/**
|
|
48
|
+
* Tool that was executed
|
|
49
|
+
*/
|
|
50
|
+
toolName: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Context value interface
|
|
54
|
+
*/
|
|
55
|
+
export interface MCPActionContextValue {
|
|
56
|
+
/**
|
|
57
|
+
* Execute an MCP action
|
|
58
|
+
*/
|
|
59
|
+
executeAction: (request: ActionRequest) => Promise<ActionResult>;
|
|
60
|
+
/**
|
|
61
|
+
* Currently available tools (from MCP server)
|
|
62
|
+
*/
|
|
63
|
+
availableTools: Accessor<string[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Space IDs in current context
|
|
66
|
+
*/
|
|
67
|
+
spaceIds: Accessor<string[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Current macro ID (if executing within a template)
|
|
70
|
+
*/
|
|
71
|
+
macroId: Accessor<string | undefined>;
|
|
72
|
+
/**
|
|
73
|
+
* Whether an action is currently executing
|
|
74
|
+
*/
|
|
75
|
+
isExecuting: Accessor<boolean>;
|
|
76
|
+
/**
|
|
77
|
+
* Last action result
|
|
78
|
+
*/
|
|
79
|
+
lastResult: Accessor<ActionResult | undefined>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Props for MCPActionProvider
|
|
83
|
+
*/
|
|
84
|
+
export interface MCPActionProviderProps {
|
|
85
|
+
/**
|
|
86
|
+
* Space IDs for multi-space queries
|
|
87
|
+
*/
|
|
88
|
+
spaceIds?: string[];
|
|
89
|
+
/**
|
|
90
|
+
* Macro ID when executing within a template
|
|
91
|
+
*/
|
|
92
|
+
macroId?: string;
|
|
93
|
+
/**
|
|
94
|
+
* Available MCP tools
|
|
95
|
+
*/
|
|
96
|
+
availableTools?: string[];
|
|
97
|
+
/**
|
|
98
|
+
* Callback for action execution (for audit logging)
|
|
99
|
+
*/
|
|
100
|
+
onAction?: (request: ActionRequest, result: ActionResult) => void;
|
|
101
|
+
/**
|
|
102
|
+
* Callback for webhook events (n8n, Zapier integration)
|
|
103
|
+
*/
|
|
104
|
+
onWebhook?: (event: {
|
|
105
|
+
type: string;
|
|
106
|
+
payload: any;
|
|
107
|
+
}) => void;
|
|
108
|
+
/**
|
|
109
|
+
* Custom action executor (override default)
|
|
110
|
+
*/
|
|
111
|
+
executor?: (request: ActionRequest) => Promise<ActionResult>;
|
|
112
|
+
}
|
|
113
|
+
declare const MCPActionContext: import("solid-js").Context<MCPActionContextValue | undefined>;
|
|
114
|
+
/**
|
|
115
|
+
* MCPActionProvider - Provides action execution context to child components
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```tsx
|
|
119
|
+
* <MCPActionProvider
|
|
120
|
+
* spaceIds={['space-123']}
|
|
121
|
+
* macroId="sales_overview"
|
|
122
|
+
* onAction={(req, res) => audit(req, res)}
|
|
123
|
+
* >
|
|
124
|
+
* <UIResourceRenderer layout={layout} />
|
|
125
|
+
* </MCPActionProvider>
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export declare const MCPActionProvider: ParentComponent<MCPActionProviderProps>;
|
|
129
|
+
/**
|
|
130
|
+
* Hook to access MCP action context
|
|
131
|
+
* Throws if used outside of MCPActionProvider
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```tsx
|
|
135
|
+
* const { executeAction, isExecuting } = useMCPAction()
|
|
136
|
+
*
|
|
137
|
+
* const handleClick = async () => {
|
|
138
|
+
* const result = await executeAction({
|
|
139
|
+
* toolName: 'search.hub',
|
|
140
|
+
* params: { query: 'revenue Q4' },
|
|
141
|
+
* })
|
|
142
|
+
* }
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export declare function useMCPAction(): MCPActionContextValue;
|
|
146
|
+
/**
|
|
147
|
+
* Hook to access MCP action context with fallback for components
|
|
148
|
+
* outside of provider (uses CustomEvent fallback)
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```tsx
|
|
152
|
+
* const { executeAction, isExecuting } = useMCPActionSafe()
|
|
153
|
+
* // Works even without MCPActionProvider
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export declare function useMCPActionSafe(): MCPActionContextValue;
|
|
157
|
+
export { MCPActionContext };
|
|
158
|
+
//# sourceMappingURL=MCPActionContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MCPActionContext.d.ts","sourceRoot":"","sources":["../../src/context/MCPActionContext.tsx"],"names":[],"mappings":"AAAA;;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AA;IAEhB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IAEzB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,KAAK,IAAI,CAAA;IAEjE;;OAEG;IACH,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,KAAK,IAAI,CAAA;IAE3D;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,YAAY,CAAC,CAAA;CAC7D;AAGD,QAAA,MAAM,gBAAgB,+DAAyC,CAAA;AA6D/D;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,EAAE,eAAe,CAAC,sBAAsB,CAyErE,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,IAAI,qBAAqB,CAMpD;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,IAAI,qBAAqB,CA8BxD;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAA"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { createComponent } from "solid-js/web";
|
|
2
|
+
import { createContext, createSignal, useContext } from "solid-js";
|
|
3
|
+
const MCPActionContext = createContext();
|
|
4
|
+
const defaultExecutor = async (request) => {
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
7
|
+
if (typeof window !== "undefined") {
|
|
8
|
+
const event = new CustomEvent("mcp-action", {
|
|
9
|
+
detail: {
|
|
10
|
+
toolName: request.toolName,
|
|
11
|
+
params: request.params || {},
|
|
12
|
+
spaceIds: request.spaceIds,
|
|
13
|
+
macroId: request.macroId
|
|
14
|
+
},
|
|
15
|
+
bubbles: true
|
|
16
|
+
});
|
|
17
|
+
const responseHandler = (e) => {
|
|
18
|
+
var _a, _b, _c;
|
|
19
|
+
const customEvent = e;
|
|
20
|
+
window.removeEventListener("mcp-action-response", responseHandler);
|
|
21
|
+
resolve({
|
|
22
|
+
success: ((_a = customEvent.detail) == null ? void 0 : _a.success) ?? true,
|
|
23
|
+
data: (_b = customEvent.detail) == null ? void 0 : _b.data,
|
|
24
|
+
error: (_c = customEvent.detail) == null ? void 0 : _c.error,
|
|
25
|
+
timestamp,
|
|
26
|
+
toolName: request.toolName
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
window.addEventListener("mcp-action-response", responseHandler);
|
|
30
|
+
window.dispatchEvent(event);
|
|
31
|
+
setTimeout(() => {
|
|
32
|
+
window.removeEventListener("mcp-action-response", responseHandler);
|
|
33
|
+
resolve({
|
|
34
|
+
success: true,
|
|
35
|
+
data: {
|
|
36
|
+
dispatched: true
|
|
37
|
+
},
|
|
38
|
+
timestamp,
|
|
39
|
+
toolName: request.toolName
|
|
40
|
+
});
|
|
41
|
+
}, 100);
|
|
42
|
+
} else {
|
|
43
|
+
resolve({
|
|
44
|
+
success: false,
|
|
45
|
+
error: "Actions not available server-side",
|
|
46
|
+
timestamp,
|
|
47
|
+
toolName: request.toolName
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
const MCPActionProvider = (props) => {
|
|
53
|
+
const [isExecuting, setIsExecuting] = createSignal(false);
|
|
54
|
+
const [lastResult, setLastResult] = createSignal();
|
|
55
|
+
const [spaceIds, setSpaceIds] = createSignal(props.spaceIds || []);
|
|
56
|
+
const [macroId, setMacroId] = createSignal(props.macroId);
|
|
57
|
+
const [availableTools, setAvailableTools] = createSignal(props.availableTools || []);
|
|
58
|
+
const executeAction = async (request) => {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
setIsExecuting(true);
|
|
61
|
+
try {
|
|
62
|
+
const enrichedRequest = {
|
|
63
|
+
...request,
|
|
64
|
+
spaceIds: request.spaceIds || spaceIds(),
|
|
65
|
+
macroId: request.macroId || macroId()
|
|
66
|
+
};
|
|
67
|
+
const executor = props.executor || defaultExecutor;
|
|
68
|
+
const result = await executor(enrichedRequest);
|
|
69
|
+
setLastResult(result);
|
|
70
|
+
(_a = props.onAction) == null ? void 0 : _a.call(props, enrichedRequest, result);
|
|
71
|
+
if (result.success && props.onWebhook) {
|
|
72
|
+
props.onWebhook({
|
|
73
|
+
type: "action-completed",
|
|
74
|
+
payload: {
|
|
75
|
+
request: enrichedRequest,
|
|
76
|
+
result
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
} catch (error) {
|
|
82
|
+
const errorResult = {
|
|
83
|
+
success: false,
|
|
84
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
85
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
86
|
+
toolName: request.toolName
|
|
87
|
+
};
|
|
88
|
+
setLastResult(errorResult);
|
|
89
|
+
(_b = props.onAction) == null ? void 0 : _b.call(props, request, errorResult);
|
|
90
|
+
return errorResult;
|
|
91
|
+
} finally {
|
|
92
|
+
setIsExecuting(false);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const contextValue = {
|
|
96
|
+
executeAction,
|
|
97
|
+
availableTools,
|
|
98
|
+
spaceIds,
|
|
99
|
+
macroId,
|
|
100
|
+
isExecuting,
|
|
101
|
+
lastResult
|
|
102
|
+
};
|
|
103
|
+
return createComponent(MCPActionContext.Provider, {
|
|
104
|
+
value: contextValue,
|
|
105
|
+
get children() {
|
|
106
|
+
return props.children;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
function useMCPAction() {
|
|
111
|
+
const context = useContext(MCPActionContext);
|
|
112
|
+
if (!context) {
|
|
113
|
+
throw new Error("useMCPAction must be used within an MCPActionProvider");
|
|
114
|
+
}
|
|
115
|
+
return context;
|
|
116
|
+
}
|
|
117
|
+
function useMCPActionSafe() {
|
|
118
|
+
const context = useContext(MCPActionContext);
|
|
119
|
+
if (context) {
|
|
120
|
+
return context;
|
|
121
|
+
}
|
|
122
|
+
const [isExecuting, setIsExecuting] = createSignal(false);
|
|
123
|
+
const [lastResult, setLastResult] = createSignal();
|
|
124
|
+
const executeAction = async (request) => {
|
|
125
|
+
setIsExecuting(true);
|
|
126
|
+
try {
|
|
127
|
+
const result = await defaultExecutor(request);
|
|
128
|
+
setLastResult(result);
|
|
129
|
+
return result;
|
|
130
|
+
} finally {
|
|
131
|
+
setIsExecuting(false);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
executeAction,
|
|
136
|
+
availableTools: () => [],
|
|
137
|
+
spaceIds: () => [],
|
|
138
|
+
macroId: () => void 0,
|
|
139
|
+
isExecuting,
|
|
140
|
+
lastResult
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
export {
|
|
144
|
+
MCPActionContext,
|
|
145
|
+
MCPActionProvider,
|
|
146
|
+
useMCPAction,
|
|
147
|
+
useMCPActionSafe
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=MCPActionContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MCPActionContext.js","sources":["../../src/context/MCPActionContext.tsx"],"sourcesContent":["/**\n * MCPActionContext - Context provider for MCP action execution\n * Phase 5.0: Quick Wins - Replaces CustomEvent with typed context for Mastra integration\n */\n\nimport { createContext, createSignal, useContext, ParentComponent, Accessor } from 'solid-js'\n\n/**\n * Action request payload\n */\nexport interface ActionRequest {\n /**\n * MCP tool name to execute\n */\n toolName: string\n\n /**\n * Tool parameters\n */\n params?: Record<string, any>\n\n /**\n * Optional space IDs for multi-space context\n */\n spaceIds?: string[]\n\n /**\n * Optional macro ID for template execution\n */\n macroId?: string\n}\n\n/**\n * Action result from execution\n */\nexport interface ActionResult {\n /**\n * Whether the action was successful\n */\n success: boolean\n\n /**\n * Result data (if successful)\n */\n data?: any\n\n /**\n * Error message (if failed)\n */\n error?: string\n\n /**\n * Execution timestamp\n */\n timestamp: string\n\n /**\n * Tool that was executed\n */\n toolName: string\n}\n\n/**\n * Context value interface\n */\nexport interface MCPActionContextValue {\n /**\n * Execute an MCP action\n */\n executeAction: (request: ActionRequest) => Promise<ActionResult>\n\n /**\n * Currently available tools (from MCP server)\n */\n availableTools: Accessor<string[]>\n\n /**\n * Space IDs in current context\n */\n spaceIds: Accessor<string[]>\n\n /**\n * Current macro ID (if executing within a template)\n */\n macroId: Accessor<string | undefined>\n\n /**\n * Whether an action is currently executing\n */\n isExecuting: Accessor<boolean>\n\n /**\n * Last action result\n */\n lastResult: Accessor<ActionResult | undefined>\n}\n\n/**\n * Props for MCPActionProvider\n */\nexport interface MCPActionProviderProps {\n /**\n * Space IDs for multi-space queries\n */\n spaceIds?: string[]\n\n /**\n * Macro ID when executing within a template\n */\n macroId?: string\n\n /**\n * Available MCP tools\n */\n availableTools?: string[]\n\n /**\n * Callback for action execution (for audit logging)\n */\n onAction?: (request: ActionRequest, result: ActionResult) => void\n\n /**\n * Callback for webhook events (n8n, Zapier integration)\n */\n onWebhook?: (event: { type: string; payload: any }) => void\n\n /**\n * Custom action executor (override default)\n */\n executor?: (request: ActionRequest) => Promise<ActionResult>\n}\n\n// Create the context with undefined default\nconst MCPActionContext = createContext<MCPActionContextValue>()\n\n/**\n * Default action executor using CustomEvent fallback\n * This maintains backward compatibility while allowing Context-based usage\n */\nconst defaultExecutor = async (request: ActionRequest): Promise<ActionResult> => {\n return new Promise((resolve) => {\n const timestamp = new Date().toISOString()\n\n // Dispatch CustomEvent for backward compatibility with existing listeners\n if (typeof window !== 'undefined') {\n const event = new CustomEvent('mcp-action', {\n detail: {\n toolName: request.toolName,\n params: request.params || {},\n spaceIds: request.spaceIds,\n macroId: request.macroId,\n },\n bubbles: true,\n })\n\n // Listen for response event\n const responseHandler = (e: Event) => {\n const customEvent = e as CustomEvent\n window.removeEventListener('mcp-action-response', responseHandler)\n resolve({\n success: customEvent.detail?.success ?? true,\n data: customEvent.detail?.data,\n error: customEvent.detail?.error,\n timestamp,\n toolName: request.toolName,\n })\n }\n\n window.addEventListener('mcp-action-response', responseHandler)\n window.dispatchEvent(event)\n\n // Timeout fallback - resolve as success if no response in 100ms\n // (indicates no listener, action was dispatched)\n setTimeout(() => {\n window.removeEventListener('mcp-action-response', responseHandler)\n resolve({\n success: true,\n data: { dispatched: true },\n timestamp,\n toolName: request.toolName,\n })\n }, 100)\n } else {\n // Server-side: return immediately\n resolve({\n success: false,\n error: 'Actions not available server-side',\n timestamp,\n toolName: request.toolName,\n })\n }\n })\n}\n\n/**\n * MCPActionProvider - Provides action execution context to child components\n *\n * @example\n * ```tsx\n * <MCPActionProvider\n * spaceIds={['space-123']}\n * macroId=\"sales_overview\"\n * onAction={(req, res) => audit(req, res)}\n * >\n * <UIResourceRenderer layout={layout} />\n * </MCPActionProvider>\n * ```\n */\nexport const MCPActionProvider: ParentComponent<MCPActionProviderProps> = (props) => {\n const [isExecuting, setIsExecuting] = createSignal(false)\n const [lastResult, setLastResult] = createSignal<ActionResult>()\n const [spaceIds, setSpaceIds] = createSignal<string[]>(props.spaceIds || [])\n const [macroId, setMacroId] = createSignal<string | undefined>(props.macroId)\n const [availableTools, setAvailableTools] = createSignal<string[]>(props.availableTools || [])\n\n // Update signals when props change\n // Note: This is a simple approach; for more complex scenarios, consider createEffect\n\n const executeAction = async (request: ActionRequest): Promise<ActionResult> => {\n setIsExecuting(true)\n\n try {\n // Enrich request with context\n const enrichedRequest: ActionRequest = {\n ...request,\n spaceIds: request.spaceIds || spaceIds(),\n macroId: request.macroId || macroId(),\n }\n\n // Execute using custom executor or default\n const executor = props.executor || defaultExecutor\n const result = await executor(enrichedRequest)\n\n setLastResult(result)\n\n // Call audit callback if provided\n props.onAction?.(enrichedRequest, result)\n\n // Trigger webhook if provided and action was successful\n if (result.success && props.onWebhook) {\n props.onWebhook({\n type: 'action-completed',\n payload: {\n request: enrichedRequest,\n result,\n },\n })\n }\n\n return result\n } catch (error) {\n const errorResult: ActionResult = {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error',\n timestamp: new Date().toISOString(),\n toolName: request.toolName,\n }\n\n setLastResult(errorResult)\n props.onAction?.(request, errorResult)\n\n return errorResult\n } finally {\n setIsExecuting(false)\n }\n }\n\n const contextValue: MCPActionContextValue = {\n executeAction,\n availableTools,\n spaceIds,\n macroId,\n isExecuting,\n lastResult,\n }\n\n return (\n <MCPActionContext.Provider value={contextValue}>\n {props.children}\n </MCPActionContext.Provider>\n )\n}\n\n/**\n * Hook to access MCP action context\n * Throws if used outside of MCPActionProvider\n *\n * @example\n * ```tsx\n * const { executeAction, isExecuting } = useMCPAction()\n *\n * const handleClick = async () => {\n * const result = await executeAction({\n * toolName: 'search.hub',\n * params: { query: 'revenue Q4' },\n * })\n * }\n * ```\n */\nexport function useMCPAction(): MCPActionContextValue {\n const context = useContext(MCPActionContext)\n if (!context) {\n throw new Error('useMCPAction must be used within an MCPActionProvider')\n }\n return context\n}\n\n/**\n * Hook to access MCP action context with fallback for components\n * outside of provider (uses CustomEvent fallback)\n *\n * @example\n * ```tsx\n * const { executeAction, isExecuting } = useMCPActionSafe()\n * // Works even without MCPActionProvider\n * ```\n */\nexport function useMCPActionSafe(): MCPActionContextValue {\n const context = useContext(MCPActionContext)\n\n if (context) {\n return context\n }\n\n // Fallback implementation for components outside provider\n const [isExecuting, setIsExecuting] = createSignal(false)\n const [lastResult, setLastResult] = createSignal<ActionResult>()\n\n const executeAction = async (request: ActionRequest): Promise<ActionResult> => {\n setIsExecuting(true)\n try {\n const result = await defaultExecutor(request)\n setLastResult(result)\n return result\n } finally {\n setIsExecuting(false)\n }\n }\n\n return {\n executeAction,\n availableTools: () => [],\n spaceIds: () => [],\n macroId: () => undefined,\n isExecuting,\n lastResult,\n }\n}\n\nexport { MCPActionContext }\n"],"names":["MCPActionContext","createContext","defaultExecutor","request","Promise","resolve","timestamp","Date","toISOString","window","event","CustomEvent","detail","toolName","params","spaceIds","macroId","bubbles","responseHandler","e","customEvent","removeEventListener","success","data","error","addEventListener","dispatchEvent","setTimeout","dispatched","MCPActionProvider","props","isExecuting","setIsExecuting","createSignal","lastResult","setLastResult","setSpaceIds","setMacroId","availableTools","setAvailableTools","executeAction","enrichedRequest","executor","result","onAction","onWebhook","type","payload","errorResult","Error","message","contextValue","_$createComponent","Provider","value","children","useMCPAction","context","useContext","useMCPActionSafe","undefined"],"mappings":";;AAqIA,MAAMA,mBAAmBC,cAAAA;AAMzB,MAAMC,kBAAkB,OAAOC,YAAkD;AAC/E,SAAO,IAAIC,QAASC,CAAAA,YAAY;AAC9B,UAAMC,aAAY,oBAAIC,KAAAA,GAAOC,YAAAA;AAG7B,QAAI,OAAOC,WAAW,aAAa;AACjC,YAAMC,QAAQ,IAAIC,YAAY,cAAc;AAAA,QAC1CC,QAAQ;AAAA,UACNC,UAAUV,QAAQU;AAAAA,UAClBC,QAAQX,QAAQW,UAAU,CAAA;AAAA,UAC1BC,UAAUZ,QAAQY;AAAAA,UAClBC,SAASb,QAAQa;AAAAA,QAAAA;AAAAA,QAEnBC,SAAS;AAAA,MAAA,CACV;AAGD,YAAMC,kBAAkBA,CAACC,MAAa;;AACpC,cAAMC,cAAcD;AACpBV,eAAOY,oBAAoB,uBAAuBH,eAAe;AACjEb,gBAAQ;AAAA,UACNiB,WAASF,iBAAYR,WAAZQ,mBAAoBE,YAAW;AAAA,UACxCC,OAAMH,iBAAYR,WAAZQ,mBAAoBG;AAAAA,UAC1BC,QAAOJ,iBAAYR,WAAZQ,mBAAoBI;AAAAA,UAC3BlB;AAAAA,UACAO,UAAUV,QAAQU;AAAAA,QAAAA,CACnB;AAAA,MACH;AAEAJ,aAAOgB,iBAAiB,uBAAuBP,eAAe;AAC9DT,aAAOiB,cAAchB,KAAK;AAI1BiB,iBAAW,MAAM;AACflB,eAAOY,oBAAoB,uBAAuBH,eAAe;AACjEb,gBAAQ;AAAA,UACNiB,SAAS;AAAA,UACTC,MAAM;AAAA,YAAEK,YAAY;AAAA,UAA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;AAAAA,IACAG;AAAAA,EAAAA;AAEJ;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP UI Solid - Context Providers
|
|
3
|
+
*
|
|
4
|
+
* Context providers for action execution and state management
|
|
5
|
+
*/
|
|
6
|
+
export { MCPActionProvider, MCPActionContext, useMCPAction, useMCPActionSafe, } from './MCPActionContext';
|
|
7
|
+
export type { MCPActionContextValue, MCPActionProviderProps, ActionRequest, ActionResult, } from './MCPActionContext';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,GACjB,MAAM,oBAAoB,CAAA;AAE3B,YAAY,EACV,qBAAqB,EACrB,sBAAsB,EACtB,aAAa,EACb,YAAY,GACb,MAAM,oBAAoB,CAAA"}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -5,4 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { useStreamingUI } from './useStreamingUI';
|
|
7
7
|
export type { UseStreamingUIOptions, StreamingUIState, StreamProgress, StreamError, CompleteMetadata, } from './useStreamingUI';
|
|
8
|
+
export { useAction, useToolAction } from './useAction';
|
|
9
|
+
export type { UseActionReturn, ActionRequest, ActionResult } from './useAction';
|
|
8
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,YAAY,EACV,qBAAqB,EACrB,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,gBAAgB,GACjB,MAAM,kBAAkB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,YAAY,EACV,qBAAqB,EACrB,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,gBAAgB,GACjB,MAAM,kBAAkB,CAAA;AAGzB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AACtD,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const solidJs = require("solid-js");
|
|
4
|
+
const MCPActionContext = require("../context/MCPActionContext.cjs");
|
|
5
|
+
function useAction() {
|
|
6
|
+
const context = MCPActionContext.useMCPActionSafe();
|
|
7
|
+
const [lastError, setLastError] = solidJs.createSignal();
|
|
8
|
+
const execute = async (toolName, params) => {
|
|
9
|
+
setLastError(void 0);
|
|
10
|
+
const result = await context.executeAction({
|
|
11
|
+
toolName,
|
|
12
|
+
params
|
|
13
|
+
});
|
|
14
|
+
if (!result.success && result.error) {
|
|
15
|
+
setLastError(result.error);
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
const executeAction = async (request) => {
|
|
20
|
+
setLastError(void 0);
|
|
21
|
+
const result = await context.executeAction(request);
|
|
22
|
+
if (!result.success && result.error) {
|
|
23
|
+
setLastError(result.error);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
execute,
|
|
29
|
+
executeAction,
|
|
30
|
+
isExecuting: context.isExecuting,
|
|
31
|
+
lastResult: context.lastResult,
|
|
32
|
+
lastError
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function useToolAction(toolName) {
|
|
36
|
+
const { execute: baseExecute, isExecuting, lastResult, lastError } = useAction();
|
|
37
|
+
const execute = async (params) => {
|
|
38
|
+
return baseExecute(toolName, params);
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
execute,
|
|
42
|
+
isExecuting,
|
|
43
|
+
lastResult,
|
|
44
|
+
lastError
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
exports.useAction = useAction;
|
|
48
|
+
exports.useToolAction = useToolAction;
|
|
49
|
+
//# sourceMappingURL=useAction.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAction.cjs","sources":["../../src/hooks/useAction.ts"],"sourcesContent":["/**\n * useAction - Hook for executing MCP actions from components\n * Phase 5.0: Quick Wins - Simplified API for ActionRenderer and custom components\n */\n\nimport { createSignal, Accessor } from 'solid-js'\nimport { useMCPActionSafe, ActionRequest, ActionResult } from '../context/MCPActionContext'\n\n/**\n * Return type for useAction hook\n */\nexport interface UseActionReturn {\n /**\n * Execute a tool action\n */\n execute: (toolName: string, params?: Record<string, any>) => Promise<ActionResult>\n\n /**\n * Full execute with ActionRequest\n */\n executeAction: (request: ActionRequest) => Promise<ActionResult>\n\n /**\n * Whether an action is currently executing\n */\n isExecuting: Accessor<boolean>\n\n /**\n * Last result from action execution\n */\n lastResult: Accessor<ActionResult | undefined>\n\n /**\n * Last error (if any)\n */\n lastError: Accessor<string | undefined>\n}\n\n/**\n * Hook for executing MCP actions\n *\n * @example\n * ```tsx\n * function MyButton() {\n * const { execute, isExecuting, lastError } = useAction()\n *\n * const handleClick = async () => {\n * const result = await execute('search.hub', { query: 'test' })\n * if (result.success) {\n * console.log('Data:', result.data)\n * }\n * }\n *\n * return (\n * <button onClick={handleClick} disabled={isExecuting()}>\n * {isExecuting() ? 'Loading...' : 'Search'}\n * </button>\n * )\n * }\n * ```\n */\nexport function useAction(): UseActionReturn {\n const context = useMCPActionSafe()\n const [lastError, setLastError] = createSignal<string>()\n\n const execute = async (toolName: string, params?: Record<string, any>): Promise<ActionResult> => {\n setLastError(undefined)\n\n const result = await context.executeAction({\n toolName,\n params,\n })\n\n if (!result.success && result.error) {\n setLastError(result.error)\n }\n\n return result\n }\n\n const executeAction = async (request: ActionRequest): Promise<ActionResult> => {\n setLastError(undefined)\n\n const result = await context.executeAction(request)\n\n if (!result.success && result.error) {\n setLastError(result.error)\n }\n\n return result\n }\n\n return {\n execute,\n executeAction,\n isExecuting: context.isExecuting,\n lastResult: context.lastResult,\n lastError,\n }\n}\n\n/**\n * Hook for binding action to a specific tool\n *\n * @example\n * ```tsx\n * function SearchButton() {\n * const { execute, isExecuting } = useToolAction('search.hub')\n *\n * return (\n * <button onClick={() => execute({ query: 'test' })} disabled={isExecuting()}>\n * Search\n * </button>\n * )\n * }\n * ```\n */\nexport function useToolAction(toolName: string): {\n execute: (params?: Record<string, any>) => Promise<ActionResult>\n isExecuting: Accessor<boolean>\n lastResult: Accessor<ActionResult | undefined>\n lastError: Accessor<string | undefined>\n} {\n const { execute: baseExecute, isExecuting, lastResult, lastError } = useAction()\n\n const execute = async (params?: Record<string, any>): Promise<ActionResult> => {\n return baseExecute(toolName, params)\n }\n\n return {\n execute,\n isExecuting,\n lastResult,\n lastError,\n }\n}\n\nexport type { ActionRequest, ActionResult }\n"],"names":["useMCPActionSafe","createSignal"],"mappings":";;;;AA6DO,SAAS,YAA6B;AAC3C,QAAM,UAAUA,iBAAAA,iBAAA;AAChB,QAAM,CAAC,WAAW,YAAY,IAAIC,qBAAA;AAElC,QAAM,UAAU,OAAO,UAAkB,WAAwD;AAC/F,iBAAa,MAAS;AAEtB,UAAM,SAAS,MAAM,QAAQ,cAAc;AAAA,MACzC;AAAA,MACA;AAAA,IAAA,CACD;AAED,QAAI,CAAC,OAAO,WAAW,OAAO,OAAO;AACnC,mBAAa,OAAO,KAAK;AAAA,IAC3B;AAEA,WAAO;AAAA,EACT;AAEA,QAAM,gBAAgB,OAAO,YAAkD;AAC7E,iBAAa,MAAS;AAEtB,UAAM,SAAS,MAAM,QAAQ,cAAc,OAAO;AAElD,QAAI,CAAC,OAAO,WAAW,OAAO,OAAO;AACnC,mBAAa,OAAO,KAAK;AAAA,IAC3B;AAEA,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,aAAa,QAAQ;AAAA,IACrB,YAAY,QAAQ;AAAA,IACpB;AAAA,EAAA;AAEJ;AAkBO,SAAS,cAAc,UAK5B;AACA,QAAM,EAAE,SAAS,aAAa,aAAa,YAAY,UAAA,IAAc,UAAA;AAErE,QAAM,UAAU,OAAO,WAAwD;AAC7E,WAAO,YAAY,UAAU,MAAM;AAAA,EACrC;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;;;"}
|