@seed-ship/mcp-ui-solid 6.6.0 → 6.7.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 +62 -0
- package/dist/adapters/index.d.ts +2 -1
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/macro-run.cjs +226 -0
- package/dist/adapters/macro-run.cjs.map +1 -0
- package/dist/adapters/macro-run.d.ts +65 -0
- package/dist/adapters/macro-run.d.ts.map +1 -0
- package/dist/adapters/macro-run.js +226 -0
- package/dist/adapters/macro-run.js.map +1 -0
- package/dist/adapters.cjs +3 -0
- package/dist/adapters.cjs.map +1 -1
- package/dist/adapters.d.cts +2 -1
- package/dist/adapters.d.ts +2 -1
- package/dist/adapters.js +4 -1
- package/dist/adapters.js.map +1 -1
- package/dist/components/ActionGroupRenderer.cjs +12 -3
- package/dist/components/ActionGroupRenderer.cjs.map +1 -1
- package/dist/components/ActionGroupRenderer.d.ts.map +1 -1
- package/dist/components/ActionGroupRenderer.js +12 -3
- package/dist/components/ActionGroupRenderer.js.map +1 -1
- package/dist/components/UIResourceRenderer.cjs +22 -15
- package/dist/components/UIResourceRenderer.cjs.map +1 -1
- package/dist/components/UIResourceRenderer.d.ts.map +1 -1
- package/dist/components/UIResourceRenderer.js +22 -15
- package/dist/components/UIResourceRenderer.js.map +1 -1
- package/dist/context/MCPActionContext.cjs +4 -1
- package/dist/context/MCPActionContext.cjs.map +1 -1
- package/dist/context/MCPActionContext.d.ts +13 -1
- package/dist/context/MCPActionContext.d.ts.map +1 -1
- package/dist/context/MCPActionContext.js +4 -1
- package/dist/context/MCPActionContext.js.map +1 -1
- package/dist/mcp-ui-spec/dist/schemas.cjs +250 -1
- package/dist/mcp-ui-spec/dist/schemas.cjs.map +1 -1
- package/dist/mcp-ui-spec/dist/schemas.js +251 -2
- package/dist/mcp-ui-spec/dist/schemas.js.map +1 -1
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.cjs +2 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.cjs.map +1 -1
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js +2 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js.map +1 -1
- package/package.json +2 -2
- package/src/adapters/index.ts +4 -5
- package/src/adapters/macro-run.test.ts +293 -0
- package/src/adapters/macro-run.ts +362 -0
- package/src/components/ActionGroupRenderer.test.tsx +1 -0
- package/src/components/ActionGroupRenderer.tsx +19 -4
- package/src/components/ActionSubmit.test.tsx +188 -0
- package/src/components/UIResourceRenderer.tsx +19 -6
- package/src/context/MCPActionContext.tsx +17 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -12,7 +12,10 @@ const defaultExecutor = async (request) => {
|
|
|
12
12
|
toolName: request.toolName,
|
|
13
13
|
params: request.params || {},
|
|
14
14
|
spaceIds: request.spaceIds,
|
|
15
|
-
macroId: request.macroId
|
|
15
|
+
macroId: request.macroId,
|
|
16
|
+
// v6.6.1 — action kind so a window-level listener can route a
|
|
17
|
+
// `submit` (POST to params.submit_url) vs a tool call.
|
|
18
|
+
action: request.action ?? "tool-call"
|
|
16
19
|
},
|
|
17
20
|
bubbles: true
|
|
18
21
|
});
|
|
@@ -1 +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 // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const [spaceIds, _setSpaceIds] = createSignal<string[]>(props.spaceIds || [])\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const [macroId, _setMacroId] = createSignal<string | undefined>(props.macroId)\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\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;AA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B,mBAAe,IAAI;AACnB,QAAI;AACF,YAAMW,SAAS,MAAMzC,gBAAgBC,OAAO;AAC5CgC,oBAAcQ,MAAM;AACpB,aAAOA;AAAAA,IACT,UAAA;AACEX,qBAAe,KAAK;AAAA,IACtB;AAAA,EACF;AAEA,SAAO;AAAA,IACLQ;AAAAA,IACAF,gBAAgBA,MAAM,CAAA;AAAA,IACtBvB,UAAUA,MAAM,CAAA;AAAA,IAChBC,SAASA,MAAM4C;AAAAA,IACf7B;AAAAA,IACAG;AAAAA,EAAAA;AAEJ;;;;;"}
|
|
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. For a `submit` action with no associated\n * tool, renderers pass the sentinel `'submit'` — branch on `action`,\n * not on `toolName`, to tell a submit apart from a tool call.\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 * Action kind (v6.6.1). Lets a host `executor` tell a tool call apart\n * from a form-style `submit`. Absent ⇒ treat as `'tool-call'` (backward\n * compatible — every pre-v6.6.1 request omits it).\n *\n * A `submit` action carries its payload in `params` (e.g. `submit_url`,\n * `connector_id`, `feedback_value`) and **must NOT** be executed as a\n * tool call — the host routes it (e.g. POST to `params.submit_url`).\n */\n action?: 'tool-call' | 'submit' | 'link'\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 // v6.6.1 — action kind so a window-level listener can route a\n // `submit` (POST to params.submit_url) vs a tool call.\n action: request.action ?? 'tool-call',\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 // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const [spaceIds, _setSpaceIds] = createSignal<string[]>(props.spaceIds || [])\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const [macroId, _setMacroId] = createSignal<string | undefined>(props.macroId)\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\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","action","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":";;;;AAkJA,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;AAAAA;AAAAA,UAGjBC,QAAQd,QAAQc,UAAU;AAAA,QAAA;AAAA,QAE5BC,SAAS;AAAA,MAAA,CACV;AAGD,YAAMC,kBAAkBA,CAACC,MAAa;;AACpC,cAAMC,cAAcD;AACpBX,eAAOa,oBAAoB,uBAAuBH,eAAe;AACjEd,gBAAQ;AAAA,UACNkB,WAASF,iBAAYT,WAAZS,mBAAoBE,YAAW;AAAA,UACxCC,OAAMH,iBAAYT,WAAZS,mBAAoBG;AAAAA,UAC1BC,QAAOJ,iBAAYT,WAAZS,mBAAoBI;AAAAA,UAC3BnB;AAAAA,UACAO,UAAUV,QAAQU;AAAAA,QAAAA,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Ae,IAAI;AACnB,QAAI;AACF,YAAMW,SAAS,MAAM1C,gBAAgBC,OAAO;AAC5CiC,oBAAcQ,MAAM;AACpB,aAAOA;AAAAA,IACT,UAAA;AACEX,qBAAe,KAAK;AAAA,IACtB;AAAA,EACF;AAEA,SAAO;AAAA,IACLQ;AAAAA,IACAF,gBAAgBA,MAAM,CAAA;AAAA,IACtBxB,UAAUA,MAAM,CAAA;AAAA,IAChBC,SAASA,MAAM6C;AAAAA,IACf7B;AAAAA,IACAG;AAAAA,EAAAA;AAEJ;;;;;"}
|
|
@@ -8,7 +8,9 @@ import { ParentComponent, Accessor } from 'solid-js';
|
|
|
8
8
|
*/
|
|
9
9
|
export interface ActionRequest {
|
|
10
10
|
/**
|
|
11
|
-
* MCP tool name to execute
|
|
11
|
+
* MCP tool name to execute. For a `submit` action with no associated
|
|
12
|
+
* tool, renderers pass the sentinel `'submit'` — branch on `action`,
|
|
13
|
+
* not on `toolName`, to tell a submit apart from a tool call.
|
|
12
14
|
*/
|
|
13
15
|
toolName: string;
|
|
14
16
|
/**
|
|
@@ -23,6 +25,16 @@ export interface ActionRequest {
|
|
|
23
25
|
* Optional macro ID for template execution
|
|
24
26
|
*/
|
|
25
27
|
macroId?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Action kind (v6.6.1). Lets a host `executor` tell a tool call apart
|
|
30
|
+
* from a form-style `submit`. Absent ⇒ treat as `'tool-call'` (backward
|
|
31
|
+
* compatible — every pre-v6.6.1 request omits it).
|
|
32
|
+
*
|
|
33
|
+
* A `submit` action carries its payload in `params` (e.g. `submit_url`,
|
|
34
|
+
* `connector_id`, `feedback_value`) and **must NOT** be executed as a
|
|
35
|
+
* tool call — the host routes it (e.g. POST to `params.submit_url`).
|
|
36
|
+
*/
|
|
37
|
+
action?: 'tool-call' | 'submit' | 'link';
|
|
26
38
|
}
|
|
27
39
|
/**
|
|
28
40
|
* Action result from execution
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MCPActionContext.d.ts","sourceRoot":"","sources":["../../src/context/MCPActionContext.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAA2C,eAAe,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAE7F;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B
|
|
1
|
+
{"version":3,"file":"MCPActionContext.d.ts","sourceRoot":"","sources":["../../src/context/MCPActionContext.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAA2C,eAAe,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAE7F;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAE5B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,WAAW,GAAG,QAAQ,GAAG,MAAM,CAAA;CACzC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,OAAO,EAAE,OAAO,CAAA;IAEhB;;OAEG;IACH,IAAI,CAAC,EAAE,GAAG,CAAA;IAEV;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,aAAa,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,YAAY,CAAC,CAAA;IAEhE;;OAEG;IACH,cAAc,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;IAElC;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;IAE5B;;OAEG;IACH,OAAO,EAAE,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;IAErC;;OAEG;IACH,WAAW,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAE9B;;OAEG;IACH,UAAU,EAAE,QAAQ,CAAC,YAAY,GAAG,SAAS,CAAC,CAAA;CAC/C;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;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;AAgE/D;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,EAAE,eAAe,CAAC,sBAAsB,CA4ErE,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,IAAI,qBAAqB,CAMpD;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,IAAI,qBAAqB,CA8BxD;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAA"}
|
|
@@ -10,7 +10,10 @@ const defaultExecutor = async (request) => {
|
|
|
10
10
|
toolName: request.toolName,
|
|
11
11
|
params: request.params || {},
|
|
12
12
|
spaceIds: request.spaceIds,
|
|
13
|
-
macroId: request.macroId
|
|
13
|
+
macroId: request.macroId,
|
|
14
|
+
// v6.6.1 — action kind so a window-level listener can route a
|
|
15
|
+
// `submit` (POST to params.submit_url) vs a tool call.
|
|
16
|
+
action: request.action ?? "tool-call"
|
|
14
17
|
},
|
|
15
18
|
bubbles: true
|
|
16
19
|
});
|
|
@@ -1 +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 // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const [spaceIds, _setSpaceIds] = createSignal<string[]>(props.spaceIds || [])\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const [macroId, _setMacroId] = createSignal<string | undefined>(props.macroId)\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\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,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SAAAkB,gBACGpD,iBAAiBqD,UAAQ;AAAA,IAACC,OAAOH;AAAAA,IAAY,IAAAI,WAAA;AAAA,aAC3CzB,MAAMyB;AAAAA,IAAQ;AAAA,EAAA,CAAA;AAGrB;AAkBO,SAASC,eAAsC;AACpD,QAAMC,UAAUC,WAAW1D,gBAAgB;AAC3C,MAAI,CAACyD,SAAS;AACZ,UAAM,IAAIR,MAAM,uDAAuD;AAAA,EACzE;AACA,SAAOQ;AACT;AAYO,SAASE,mBAA0C;AACxD,QAAMF,UAAUC,WAAW1D,gBAAgB;AAE3C,MAAIyD,SAAS;AACX,WAAOA;AAAAA,EACT;AAGA,QAAM,CAAC1B,aAAaC,cAAc,IAAIC,aAAa,KAAK;AACxD,QAAM,CAACC,YAAYC,aAAa,IAAIF,aAAAA;AAEpC,QAAMO,gBAAgB,OAAOrC,YAAkD;AAC7E6B,mBAAe,IAAI;AACnB,QAAI;AACF,YAAMW,SAAS,MAAMzC,gBAAgBC,OAAO;AAC5CgC,oBAAcQ,MAAM;AACpB,aAAOA;AAAAA,IACT,UAAA;AACEX,qBAAe,KAAK;AAAA,IACtB;AAAA,EACF;AAEA,SAAO;AAAA,IACLQ;AAAAA,IACAF,gBAAgBA,MAAM,CAAA;AAAA,IACtBvB,UAAUA,MAAM,CAAA;AAAA,IAChBC,SAASA,MAAM4C;AAAAA,IACf7B;AAAAA,IACAG;AAAAA,EAAAA;AAEJ;"}
|
|
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. For a `submit` action with no associated\n * tool, renderers pass the sentinel `'submit'` — branch on `action`,\n * not on `toolName`, to tell a submit apart from a tool call.\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 * Action kind (v6.6.1). Lets a host `executor` tell a tool call apart\n * from a form-style `submit`. Absent ⇒ treat as `'tool-call'` (backward\n * compatible — every pre-v6.6.1 request omits it).\n *\n * A `submit` action carries its payload in `params` (e.g. `submit_url`,\n * `connector_id`, `feedback_value`) and **must NOT** be executed as a\n * tool call — the host routes it (e.g. POST to `params.submit_url`).\n */\n action?: 'tool-call' | 'submit' | 'link'\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 // v6.6.1 — action kind so a window-level listener can route a\n // `submit` (POST to params.submit_url) vs a tool call.\n action: request.action ?? 'tool-call',\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 // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const [spaceIds, _setSpaceIds] = createSignal<string[]>(props.spaceIds || [])\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const [macroId, _setMacroId] = createSignal<string | undefined>(props.macroId)\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\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","action","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":";;AAkJA,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,UAAU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A,aAC3CzB,MAAMyB;AAAAA,IAAQ;AAAA,EAAA,CAAA;AAGrB;AAkBO,SAASC,eAAsC;AACpD,QAAMC,UAAUC,WAAW3D,gBAAgB;AAC3C,MAAI,CAAC0D,SAAS;AACZ,UAAM,IAAIR,MAAM,uDAAuD;AAAA,EACzE;AACA,SAAOQ;AACT;AAYO,SAASE,mBAA0C;AACxD,QAAMF,UAAUC,WAAW3D,gBAAgB;AAE3C,MAAI0D,SAAS;AACX,WAAOA;AAAAA,EACT;AAGA,QAAM,CAAC1B,aAAaC,cAAc,IAAIC,aAAa,KAAK;AACxD,QAAM,CAACC,YAAYC,aAAa,IAAIF,aAAAA;AAEpC,QAAMO,gBAAgB,OAAOtC,YAAkD;AAC7E8B,mBAAe,IAAI;AACnB,QAAI;AACF,YAAMW,SAAS,MAAM1C,gBAAgBC,OAAO;AAC5CiC,oBAAcQ,MAAM;AACpB,aAAOA;AAAAA,IACT,UAAA;AACEX,qBAAe,KAAK;AAAA,IACtB;AAAA,EACF;AAEA,SAAO;AAAA,IACLQ;AAAAA,IACAF,gBAAgBA,MAAM,CAAA;AAAA,IACtBxB,UAAUA,MAAM,CAAA;AAAA,IAChBC,SAASA,MAAM6C;AAAAA,IACf7B;AAAAA,IACAG;AAAAA,EAAAA;AAEJ;"}
|
|
@@ -252,6 +252,99 @@ const MapMarkerSchema = types.object({
|
|
|
252
252
|
tooltip: types.string().optional(),
|
|
253
253
|
popup: types.string().optional()
|
|
254
254
|
});
|
|
255
|
+
const GeoJSONPositionSchema = types.array(types.number()).min(2);
|
|
256
|
+
const GeoJSONCoordinatesSchema = types.union([
|
|
257
|
+
GeoJSONPositionSchema,
|
|
258
|
+
types.array(GeoJSONPositionSchema),
|
|
259
|
+
types.array(types.array(GeoJSONPositionSchema)),
|
|
260
|
+
types.array(types.array(types.array(GeoJSONPositionSchema)))
|
|
261
|
+
]);
|
|
262
|
+
const GeoJSONGeometryTypeSchema = types.enum([
|
|
263
|
+
"Point",
|
|
264
|
+
"MultiPoint",
|
|
265
|
+
"LineString",
|
|
266
|
+
"MultiLineString",
|
|
267
|
+
"Polygon",
|
|
268
|
+
"MultiPolygon",
|
|
269
|
+
"GeometryCollection"
|
|
270
|
+
]);
|
|
271
|
+
const GeoJSONSimpleGeometrySchema = types.object({
|
|
272
|
+
type: GeoJSONGeometryTypeSchema,
|
|
273
|
+
coordinates: GeoJSONCoordinatesSchema.optional(),
|
|
274
|
+
bbox: types.array(types.number()).optional()
|
|
275
|
+
});
|
|
276
|
+
const GeoJSONGeometrySchema = types.object({
|
|
277
|
+
type: GeoJSONGeometryTypeSchema,
|
|
278
|
+
coordinates: GeoJSONCoordinatesSchema.optional(),
|
|
279
|
+
geometries: types.array(GeoJSONSimpleGeometrySchema).optional(),
|
|
280
|
+
bbox: types.array(types.number()).optional()
|
|
281
|
+
});
|
|
282
|
+
const GeoJSONFeatureSchema = types.object({
|
|
283
|
+
type: types.literal("Feature"),
|
|
284
|
+
geometry: GeoJSONGeometrySchema.nullable(),
|
|
285
|
+
properties: types.record(types.unknown()).nullable().optional(),
|
|
286
|
+
id: types.union([types.string(), types.number()]).optional(),
|
|
287
|
+
bbox: types.array(types.number()).optional()
|
|
288
|
+
});
|
|
289
|
+
const GeoJSONFeatureCollectionSchema = types.object({
|
|
290
|
+
type: types.literal("FeatureCollection"),
|
|
291
|
+
features: types.array(GeoJSONFeatureSchema),
|
|
292
|
+
bbox: types.array(types.number()).optional()
|
|
293
|
+
});
|
|
294
|
+
const GeoJSONSchema = types.union([
|
|
295
|
+
GeoJSONFeatureCollectionSchema,
|
|
296
|
+
GeoJSONFeatureSchema,
|
|
297
|
+
GeoJSONGeometrySchema
|
|
298
|
+
]);
|
|
299
|
+
const MapGeoJSONStyleSchema = types.object({
|
|
300
|
+
fillColor: types.string().optional(),
|
|
301
|
+
fillOpacity: types.number().optional(),
|
|
302
|
+
strokeColor: types.string().optional(),
|
|
303
|
+
strokeWeight: types.number().optional(),
|
|
304
|
+
strokeOpacity: types.number().optional(),
|
|
305
|
+
choroplethField: types.string().optional(),
|
|
306
|
+
choroplethScale: types.array(types.tuple([types.number(), types.string()])).optional(),
|
|
307
|
+
choroplethFallback: types.string().optional()
|
|
308
|
+
});
|
|
309
|
+
const MapPopupConfigSchema = types.object({
|
|
310
|
+
titleField: types.string().optional(),
|
|
311
|
+
fields: types.array(types.string()).optional(),
|
|
312
|
+
template: types.string().optional()
|
|
313
|
+
});
|
|
314
|
+
const MapLayerSchema = types.object({
|
|
315
|
+
name: types.string().min(1),
|
|
316
|
+
visible: types.boolean().optional(),
|
|
317
|
+
geojson: GeoJSONSchema,
|
|
318
|
+
style: MapGeoJSONStyleSchema.optional(),
|
|
319
|
+
popup: MapPopupConfigSchema.optional()
|
|
320
|
+
});
|
|
321
|
+
const MapClusterOptionsSchema = types.object({
|
|
322
|
+
maxClusterRadius: types.number().optional(),
|
|
323
|
+
spiderfyOnMaxZoom: types.boolean().optional(),
|
|
324
|
+
showCoverageOnHover: types.boolean().optional(),
|
|
325
|
+
disableClusteringAtZoom: types.number().optional(),
|
|
326
|
+
animateAddingMarkers: types.boolean().optional()
|
|
327
|
+
});
|
|
328
|
+
const MapPMTilesPaintRuleSchema = types.object({
|
|
329
|
+
dataLayer: types.string(),
|
|
330
|
+
symbolizer: types.enum(["polygon", "line", "circle"]),
|
|
331
|
+
color: types.string().optional(),
|
|
332
|
+
width: types.number().optional(),
|
|
333
|
+
opacity: types.number().optional()
|
|
334
|
+
});
|
|
335
|
+
const MapPMTilesLabelRuleSchema = types.object({
|
|
336
|
+
dataLayer: types.string(),
|
|
337
|
+
textField: types.string(),
|
|
338
|
+
fontSize: types.number().optional()
|
|
339
|
+
});
|
|
340
|
+
const MapPMTilesConfigSchema = types.object({
|
|
341
|
+
url: types.string(),
|
|
342
|
+
attribution: types.string().optional(),
|
|
343
|
+
paintRules: types.array(MapPMTilesPaintRuleSchema).optional(),
|
|
344
|
+
labelRules: types.array(MapPMTilesLabelRuleSchema).optional(),
|
|
345
|
+
maxZoom: types.number().optional(),
|
|
346
|
+
minZoom: types.number().optional()
|
|
347
|
+
});
|
|
255
348
|
const MapComponentParamsSchema = types.object({
|
|
256
349
|
center: LatLngPointSchema.optional(),
|
|
257
350
|
zoom: types.number().optional(),
|
|
@@ -261,7 +354,18 @@ const MapComponentParamsSchema = types.object({
|
|
|
261
354
|
zoomControl: types.boolean().optional(),
|
|
262
355
|
scrollWheelZoom: types.boolean().optional(),
|
|
263
356
|
tileLayer: types.string().optional(),
|
|
264
|
-
attribution: types.string().optional()
|
|
357
|
+
attribution: types.string().optional(),
|
|
358
|
+
className: types.string().optional(),
|
|
359
|
+
// GeoJSON layer (v5.2.0) — polygons / lines / points from structured data.
|
|
360
|
+
geojson: GeoJSONSchema.optional(),
|
|
361
|
+
geojsonStyle: MapGeoJSONStyleSchema.optional(),
|
|
362
|
+
popup: MapPopupConfigSchema.optional(),
|
|
363
|
+
// Multiple named GeoJSON overlays with a Leaflet layer control (v5.2.0).
|
|
364
|
+
layers: types.array(MapLayerSchema).optional(),
|
|
365
|
+
// Marker clustering — `true` for defaults, or an options object (v5.2.0).
|
|
366
|
+
clustering: types.union([types.boolean(), MapClusterOptionsSchema]).optional(),
|
|
367
|
+
// PMTiles vector-tile source for large datasets (v5.2.0).
|
|
368
|
+
pmtiles: MapPMTilesConfigSchema.optional()
|
|
265
369
|
});
|
|
266
370
|
const GraphNodeSchema = types.object({
|
|
267
371
|
id: types.string().min(1),
|
|
@@ -641,6 +745,125 @@ types.object({
|
|
|
641
745
|
/** Free-text comment. */
|
|
642
746
|
comment: types.string().optional()
|
|
643
747
|
});
|
|
748
|
+
const MACRO_RUN_V1 = "macro-run/v1";
|
|
749
|
+
const MACRO_INTERROGATION_V1 = "macro-interrogation/v1";
|
|
750
|
+
const MacroRunStatusSchema = types.enum([
|
|
751
|
+
"pending",
|
|
752
|
+
"running",
|
|
753
|
+
"awaiting_input",
|
|
754
|
+
"completed",
|
|
755
|
+
"failed",
|
|
756
|
+
"aborted"
|
|
757
|
+
]);
|
|
758
|
+
const MacroStepStatusSchema = types.enum(["pending", "active", "done", "skipped", "failed"]);
|
|
759
|
+
const MacroInvocationTypeSchema = types.enum([
|
|
760
|
+
"slash_command",
|
|
761
|
+
"natural_language",
|
|
762
|
+
"api_direct",
|
|
763
|
+
"pipeline",
|
|
764
|
+
"chat_stream"
|
|
765
|
+
]);
|
|
766
|
+
const MacroStepV1Schema = types.lazy(
|
|
767
|
+
() => types.object({
|
|
768
|
+
id: types.string().min(1),
|
|
769
|
+
label: types.string(),
|
|
770
|
+
toolName: types.string().optional(),
|
|
771
|
+
status: MacroStepStatusSchema,
|
|
772
|
+
summary: types.string().optional(),
|
|
773
|
+
durationMs: types.number().optional(),
|
|
774
|
+
error: types.string().optional(),
|
|
775
|
+
resultRef: types.string().optional(),
|
|
776
|
+
parallel: types.array(MacroStepV1Schema).optional()
|
|
777
|
+
})
|
|
778
|
+
);
|
|
779
|
+
const MacroInterrogationOptionSchema = types.object({
|
|
780
|
+
value: types.string(),
|
|
781
|
+
label: types.string(),
|
|
782
|
+
icon: types.string().optional(),
|
|
783
|
+
description: types.string().optional(),
|
|
784
|
+
metadata: types.record(types.unknown()).optional()
|
|
785
|
+
});
|
|
786
|
+
const MacroInterrogationKindSchema = types.enum(["choice", "confirm", "form", "elicitation"]);
|
|
787
|
+
const MacroInterrogationV1Schema = types.object({
|
|
788
|
+
schemaVersion: types.literal(MACRO_INTERROGATION_V1),
|
|
789
|
+
interrogationId: types.string().min(1),
|
|
790
|
+
runId: types.string().min(1),
|
|
791
|
+
correlationId: types.string().optional(),
|
|
792
|
+
stepId: types.string().optional(),
|
|
793
|
+
/** Free-form tag describing what the run is blocked on. */
|
|
794
|
+
waitingFor: types.string().optional(),
|
|
795
|
+
kind: MacroInterrogationKindSchema,
|
|
796
|
+
title: types.string(),
|
|
797
|
+
message: types.string().optional(),
|
|
798
|
+
/** Options for a `choice` interrogation. */
|
|
799
|
+
options: types.array(MacroInterrogationOptionSchema).optional(),
|
|
800
|
+
/** Labels / variant for a `confirm` interrogation. */
|
|
801
|
+
confirm: types.object({
|
|
802
|
+
confirmLabel: types.string().optional(),
|
|
803
|
+
cancelLabel: types.string().optional(),
|
|
804
|
+
variant: types.enum(["default", "danger"]).optional()
|
|
805
|
+
}).optional(),
|
|
806
|
+
/** Opaque field list for a `form` interrogation (renderer-side shape). */
|
|
807
|
+
fields: types.array(types.unknown()).optional(),
|
|
808
|
+
/** Opaque MCP elicitation JSON Schema for an `elicitation` interrogation. */
|
|
809
|
+
elicitationSchema: types.unknown().optional(),
|
|
810
|
+
/** A pre-selected default the host may surface (e.g. timeout fallback). */
|
|
811
|
+
defaultChoice: types.object({
|
|
812
|
+
value: types.string(),
|
|
813
|
+
reason: types.string().optional()
|
|
814
|
+
}).optional(),
|
|
815
|
+
/** How the host resumes the run once answered — host-side, opaque to the lib. */
|
|
816
|
+
resume: types.object({
|
|
817
|
+
endpoint: types.string(),
|
|
818
|
+
mode: types.enum(["agent_resume", "legacy_chat_prompt", "macro_resume"])
|
|
819
|
+
}).optional(),
|
|
820
|
+
metadata: types.record(types.unknown()).optional()
|
|
821
|
+
});
|
|
822
|
+
const MacroRunAgentSchema = types.object({
|
|
823
|
+
id: types.string(),
|
|
824
|
+
name: types.string(),
|
|
825
|
+
avatar: types.string().optional(),
|
|
826
|
+
capabilities: types.array(types.string()).optional(),
|
|
827
|
+
status: types.enum(["idle", "running", "waiting", "done", "error"]).optional(),
|
|
828
|
+
currentStep: types.object({ id: types.string(), label: types.string() }).optional()
|
|
829
|
+
});
|
|
830
|
+
const MacroRunErrorSchema = types.object({
|
|
831
|
+
message: types.string(),
|
|
832
|
+
code: types.string().optional(),
|
|
833
|
+
stepId: types.string().optional(),
|
|
834
|
+
retryable: types.boolean().optional()
|
|
835
|
+
});
|
|
836
|
+
const MacroRunOutcomeSchema = types.object({
|
|
837
|
+
kind: types.enum(["verified_text", "briefing_diff", "agent_result", "raw"]),
|
|
838
|
+
content: types.unknown()
|
|
839
|
+
});
|
|
840
|
+
types.object({
|
|
841
|
+
schemaVersion: types.literal(MACRO_RUN_V1),
|
|
842
|
+
// Identity
|
|
843
|
+
runId: types.string().min(1),
|
|
844
|
+
correlationId: types.string().optional(),
|
|
845
|
+
macroId: types.string().min(1),
|
|
846
|
+
macroName: types.string().optional(),
|
|
847
|
+
macroVersion: types.string().optional(),
|
|
848
|
+
title: types.string().optional(),
|
|
849
|
+
invocationType: MacroInvocationTypeSchema.optional(),
|
|
850
|
+
// State
|
|
851
|
+
status: MacroRunStatusSchema,
|
|
852
|
+
startedAt: types.string().optional(),
|
|
853
|
+
updatedAt: types.string().optional(),
|
|
854
|
+
completedAt: types.string().optional(),
|
|
855
|
+
// Presentation
|
|
856
|
+
agent: MacroRunAgentSchema.optional(),
|
|
857
|
+
// Execution
|
|
858
|
+
steps: types.array(MacroStepV1Schema),
|
|
859
|
+
/** `UIComponent`-shaped results (passthrough). Optional — see header. */
|
|
860
|
+
results: types.array(types.record(types.unknown())).optional(),
|
|
861
|
+
pendingInterrogation: MacroInterrogationV1Schema.optional(),
|
|
862
|
+
error: MacroRunErrorSchema.optional(),
|
|
863
|
+
outcome: MacroRunOutcomeSchema.optional(),
|
|
864
|
+
variables: types.record(types.unknown()).optional(),
|
|
865
|
+
metadata: types.record(types.unknown()).optional()
|
|
866
|
+
});
|
|
644
867
|
exports.ActionGroupGapSchema = ActionGroupGapSchema;
|
|
645
868
|
exports.ActionGroupLayoutSchema = ActionGroupLayoutSchema;
|
|
646
869
|
exports.ActionGroupParamsSchema = ActionGroupParamsSchema;
|
|
@@ -669,6 +892,13 @@ exports.FormFieldSchema = FormFieldSchema;
|
|
|
669
892
|
exports.FormFieldTypeSchema = FormFieldTypeSchema;
|
|
670
893
|
exports.FormSubmitActionSchema = FormSubmitActionSchema;
|
|
671
894
|
exports.GalleryImageSchema = GalleryImageSchema;
|
|
895
|
+
exports.GeoJSONCoordinatesSchema = GeoJSONCoordinatesSchema;
|
|
896
|
+
exports.GeoJSONFeatureCollectionSchema = GeoJSONFeatureCollectionSchema;
|
|
897
|
+
exports.GeoJSONFeatureSchema = GeoJSONFeatureSchema;
|
|
898
|
+
exports.GeoJSONGeometrySchema = GeoJSONGeometrySchema;
|
|
899
|
+
exports.GeoJSONGeometryTypeSchema = GeoJSONGeometryTypeSchema;
|
|
900
|
+
exports.GeoJSONPositionSchema = GeoJSONPositionSchema;
|
|
901
|
+
exports.GeoJSONSchema = GeoJSONSchema;
|
|
672
902
|
exports.GraphComponentParamsSchema = GraphComponentParamsSchema;
|
|
673
903
|
exports.GraphEdgeSchema = GraphEdgeSchema;
|
|
674
904
|
exports.GraphLayoutNameSchema = GraphLayoutNameSchema;
|
|
@@ -684,8 +914,27 @@ exports.LatLngObjectSchema = LatLngObjectSchema;
|
|
|
684
914
|
exports.LatLngPointSchema = LatLngPointSchema;
|
|
685
915
|
exports.LatLngTupleSchema = LatLngTupleSchema;
|
|
686
916
|
exports.LinkComponentParamsSchema = LinkComponentParamsSchema;
|
|
917
|
+
exports.MACRO_INTERROGATION_V1 = MACRO_INTERROGATION_V1;
|
|
918
|
+
exports.MACRO_RUN_V1 = MACRO_RUN_V1;
|
|
919
|
+
exports.MacroInterrogationKindSchema = MacroInterrogationKindSchema;
|
|
920
|
+
exports.MacroInterrogationOptionSchema = MacroInterrogationOptionSchema;
|
|
921
|
+
exports.MacroInterrogationV1Schema = MacroInterrogationV1Schema;
|
|
922
|
+
exports.MacroInvocationTypeSchema = MacroInvocationTypeSchema;
|
|
923
|
+
exports.MacroRunAgentSchema = MacroRunAgentSchema;
|
|
924
|
+
exports.MacroRunErrorSchema = MacroRunErrorSchema;
|
|
925
|
+
exports.MacroRunOutcomeSchema = MacroRunOutcomeSchema;
|
|
926
|
+
exports.MacroRunStatusSchema = MacroRunStatusSchema;
|
|
927
|
+
exports.MacroStepStatusSchema = MacroStepStatusSchema;
|
|
928
|
+
exports.MacroStepV1Schema = MacroStepV1Schema;
|
|
929
|
+
exports.MapClusterOptionsSchema = MapClusterOptionsSchema;
|
|
687
930
|
exports.MapComponentParamsSchema = MapComponentParamsSchema;
|
|
931
|
+
exports.MapGeoJSONStyleSchema = MapGeoJSONStyleSchema;
|
|
932
|
+
exports.MapLayerSchema = MapLayerSchema;
|
|
688
933
|
exports.MapMarkerSchema = MapMarkerSchema;
|
|
934
|
+
exports.MapPMTilesConfigSchema = MapPMTilesConfigSchema;
|
|
935
|
+
exports.MapPMTilesLabelRuleSchema = MapPMTilesLabelRuleSchema;
|
|
936
|
+
exports.MapPMTilesPaintRuleSchema = MapPMTilesPaintRuleSchema;
|
|
937
|
+
exports.MapPopupConfigSchema = MapPopupConfigSchema;
|
|
689
938
|
exports.MetricComponentParamsSchema = MetricComponentParamsSchema;
|
|
690
939
|
exports.MetricTrendSchema = MetricTrendSchema;
|
|
691
940
|
exports.ModalSizeSchema = ModalSizeSchema;
|