@seed-ship/mcp-ui-solid 6.19.1 → 6.21.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 +663 -0
- package/README.md +911 -4
- package/dist/adapters/connector.cjs +15 -4
- package/dist/adapters/connector.cjs.map +1 -1
- package/dist/adapters/connector.d.ts +38 -0
- package/dist/adapters/connector.d.ts.map +1 -1
- package/dist/adapters/connector.js +15 -4
- package/dist/adapters/connector.js.map +1 -1
- package/dist/adapters/index.d.ts +4 -3
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/macro-run.cjs +25 -13
- package/dist/adapters/macro-run.cjs.map +1 -1
- package/dist/adapters/macro-run.d.ts +37 -2
- package/dist/adapters/macro-run.d.ts.map +1 -1
- package/dist/adapters/macro-run.js +25 -13
- package/dist/adapters/macro-run.js.map +1 -1
- package/dist/adapters.cjs +2 -0
- package/dist/adapters.cjs.map +1 -1
- package/dist/adapters.js +4 -2
- package/dist/components/ActionGroupRenderer.cjs +3 -1
- package/dist/components/ActionGroupRenderer.cjs.map +1 -1
- package/dist/components/ActionGroupRenderer.d.ts.map +1 -1
- package/dist/components/ActionGroupRenderer.js +3 -1
- package/dist/components/ActionGroupRenderer.js.map +1 -1
- package/dist/components/AgentCard.cjs +11 -8
- package/dist/components/AgentCard.cjs.map +1 -1
- package/dist/components/AgentCard.d.ts.map +1 -1
- package/dist/components/AgentCard.js +11 -8
- package/dist/components/AgentCard.js.map +1 -1
- package/dist/components/AgentHandoff.cjs +6 -1
- package/dist/components/AgentHandoff.cjs.map +1 -1
- package/dist/components/AgentHandoff.d.ts.map +1 -1
- package/dist/components/AgentHandoff.js +6 -1
- package/dist/components/AgentHandoff.js.map +1 -1
- package/dist/components/ArtifactRenderer.cjs +25 -6
- package/dist/components/ArtifactRenderer.cjs.map +1 -1
- package/dist/components/ArtifactRenderer.d.ts.map +1 -1
- package/dist/components/ArtifactRenderer.js +25 -6
- package/dist/components/ArtifactRenderer.js.map +1 -1
- package/dist/components/AutocompleteDropdown.cjs +30 -24
- package/dist/components/AutocompleteDropdown.cjs.map +1 -1
- package/dist/components/AutocompleteDropdown.d.ts.map +1 -1
- package/dist/components/AutocompleteDropdown.js +30 -24
- package/dist/components/AutocompleteDropdown.js.map +1 -1
- package/dist/components/AutocompleteFormField.cjs +3 -1
- package/dist/components/AutocompleteFormField.cjs.map +1 -1
- package/dist/components/AutocompleteFormField.d.ts.map +1 -1
- package/dist/components/AutocompleteFormField.js +4 -2
- package/dist/components/AutocompleteFormField.js.map +1 -1
- package/dist/components/BriefingDiff.cjs +45 -39
- package/dist/components/BriefingDiff.cjs.map +1 -1
- package/dist/components/BriefingDiff.d.ts.map +1 -1
- package/dist/components/BriefingDiff.js +45 -39
- package/dist/components/BriefingDiff.js.map +1 -1
- package/dist/components/CarouselRenderer.cjs +8 -2
- package/dist/components/CarouselRenderer.cjs.map +1 -1
- package/dist/components/CarouselRenderer.d.ts.map +1 -1
- package/dist/components/CarouselRenderer.js +8 -2
- package/dist/components/CarouselRenderer.js.map +1 -1
- package/dist/components/ChartJSRenderer.cjs +60 -36
- package/dist/components/ChartJSRenderer.cjs.map +1 -1
- package/dist/components/ChartJSRenderer.d.ts.map +1 -1
- package/dist/components/ChartJSRenderer.js +61 -37
- package/dist/components/ChartJSRenderer.js.map +1 -1
- package/dist/components/ChatPrompt.cjs +15 -9
- package/dist/components/ChatPrompt.cjs.map +1 -1
- package/dist/components/ChatPrompt.d.ts.map +1 -1
- package/dist/components/ChatPrompt.js +15 -9
- package/dist/components/ChatPrompt.js.map +1 -1
- package/dist/components/CodeBlockRenderer.cjs +34 -16
- package/dist/components/CodeBlockRenderer.cjs.map +1 -1
- package/dist/components/CodeBlockRenderer.d.ts.map +1 -1
- package/dist/components/CodeBlockRenderer.js +34 -16
- package/dist/components/CodeBlockRenderer.js.map +1 -1
- package/dist/components/DataPreviewSection.cjs +91 -44
- package/dist/components/DataPreviewSection.cjs.map +1 -1
- package/dist/components/DataPreviewSection.d.ts.map +1 -1
- package/dist/components/DataPreviewSection.js +92 -45
- package/dist/components/DataPreviewSection.js.map +1 -1
- package/dist/components/DegradedFallback.cjs +20 -16
- package/dist/components/DegradedFallback.cjs.map +1 -1
- package/dist/components/DegradedFallback.d.ts.map +1 -1
- package/dist/components/DegradedFallback.js +20 -16
- package/dist/components/DegradedFallback.js.map +1 -1
- package/dist/components/FooterRenderer.cjs +21 -17
- package/dist/components/FooterRenderer.cjs.map +1 -1
- package/dist/components/FooterRenderer.d.ts.map +1 -1
- package/dist/components/FooterRenderer.js +21 -17
- package/dist/components/FooterRenderer.js.map +1 -1
- package/dist/components/FormFieldRenderer.cjs +116 -93
- package/dist/components/FormFieldRenderer.cjs.map +1 -1
- package/dist/components/FormFieldRenderer.d.ts.map +1 -1
- package/dist/components/FormFieldRenderer.js +116 -93
- package/dist/components/FormFieldRenderer.js.map +1 -1
- package/dist/components/FormRenderer.cjs +55 -31
- package/dist/components/FormRenderer.cjs.map +1 -1
- package/dist/components/FormRenderer.d.ts.map +1 -1
- package/dist/components/FormRenderer.js +55 -31
- package/dist/components/FormRenderer.js.map +1 -1
- package/dist/components/GenerativeUIErrorBoundary.cjs +20 -15
- package/dist/components/GenerativeUIErrorBoundary.cjs.map +1 -1
- package/dist/components/GenerativeUIErrorBoundary.d.ts.map +1 -1
- package/dist/components/GenerativeUIErrorBoundary.js +20 -15
- package/dist/components/GenerativeUIErrorBoundary.js.map +1 -1
- package/dist/components/GraphRenderer.cjs +56 -33
- package/dist/components/GraphRenderer.cjs.map +1 -1
- package/dist/components/GraphRenderer.d.ts.map +1 -1
- package/dist/components/GraphRenderer.js +56 -33
- package/dist/components/GraphRenderer.js.map +1 -1
- package/dist/components/IframeFallbackLink.cjs +37 -0
- package/dist/components/IframeFallbackLink.cjs.map +1 -0
- package/dist/components/IframeFallbackLink.d.ts +23 -0
- package/dist/components/IframeFallbackLink.d.ts.map +1 -0
- package/dist/components/IframeFallbackLink.js +37 -0
- package/dist/components/IframeFallbackLink.js.map +1 -0
- package/dist/components/ImageGalleryRenderer.cjs +13 -4
- package/dist/components/ImageGalleryRenderer.cjs.map +1 -1
- package/dist/components/ImageGalleryRenderer.d.ts.map +1 -1
- package/dist/components/ImageGalleryRenderer.js +13 -4
- package/dist/components/ImageGalleryRenderer.js.map +1 -1
- package/dist/components/LightboxOverlay.cjs +16 -8
- package/dist/components/LightboxOverlay.cjs.map +1 -1
- package/dist/components/LightboxOverlay.d.ts.map +1 -1
- package/dist/components/LightboxOverlay.js +17 -9
- package/dist/components/LightboxOverlay.js.map +1 -1
- package/dist/components/MapRenderer.cjs +59 -29
- package/dist/components/MapRenderer.cjs.map +1 -1
- package/dist/components/MapRenderer.d.ts +10 -2
- package/dist/components/MapRenderer.d.ts.map +1 -1
- package/dist/components/MapRenderer.js +60 -30
- package/dist/components/MapRenderer.js.map +1 -1
- package/dist/components/ModalRenderer.cjs +4 -1
- package/dist/components/ModalRenderer.cjs.map +1 -1
- package/dist/components/ModalRenderer.d.ts.map +1 -1
- package/dist/components/ModalRenderer.js +5 -2
- package/dist/components/ModalRenderer.js.map +1 -1
- package/dist/components/ScratchpadPanel.cjs +578 -535
- package/dist/components/ScratchpadPanel.cjs.map +1 -1
- package/dist/components/ScratchpadPanel.d.ts.map +1 -1
- package/dist/components/ScratchpadPanel.js +578 -535
- package/dist/components/ScratchpadPanel.js.map +1 -1
- package/dist/components/StreamingUIRenderer.cjs +92 -28
- package/dist/components/StreamingUIRenderer.cjs.map +1 -1
- package/dist/components/StreamingUIRenderer.d.ts.map +1 -1
- package/dist/components/StreamingUIRenderer.js +92 -28
- package/dist/components/StreamingUIRenderer.js.map +1 -1
- package/dist/components/UIResourceRenderer.cjs +481 -365
- package/dist/components/UIResourceRenderer.cjs.map +1 -1
- package/dist/components/UIResourceRenderer.d.ts +21 -0
- package/dist/components/UIResourceRenderer.d.ts.map +1 -1
- package/dist/components/UIResourceRenderer.js +484 -368
- package/dist/components/UIResourceRenderer.js.map +1 -1
- package/dist/components/VerifiedText.cjs +39 -20
- package/dist/components/VerifiedText.cjs.map +1 -1
- package/dist/components/VerifiedText.d.ts +2 -1
- package/dist/components/VerifiedText.d.ts.map +1 -1
- package/dist/components/VerifiedText.js +39 -20
- package/dist/components/VerifiedText.js.map +1 -1
- package/dist/components/VideoRenderer.cjs +51 -20
- package/dist/components/VideoRenderer.cjs.map +1 -1
- package/dist/components/VideoRenderer.d.ts.map +1 -1
- package/dist/components/VideoRenderer.js +51 -20
- package/dist/components/VideoRenderer.js.map +1 -1
- package/dist/components/chart-data-table.cjs +38 -17
- package/dist/components/chart-data-table.cjs.map +1 -1
- package/dist/components/chart-data-table.d.ts +30 -1
- package/dist/components/chart-data-table.d.ts.map +1 -1
- package/dist/components/chart-data-table.js +38 -17
- package/dist/components/chart-data-table.js.map +1 -1
- package/dist/context/MCPActionContext.cjs +3 -1
- package/dist/context/MCPActionContext.cjs.map +1 -1
- package/dist/context/MCPActionContext.d.ts.map +1 -1
- package/dist/context/MCPActionContext.js +3 -1
- package/dist/context/MCPActionContext.js.map +1 -1
- package/dist/context/MCPUIConfigContext.cjs +29 -0
- package/dist/context/MCPUIConfigContext.cjs.map +1 -0
- package/dist/context/MCPUIConfigContext.d.ts +124 -0
- package/dist/context/MCPUIConfigContext.d.ts.map +1 -0
- package/dist/context/MCPUIConfigContext.js +29 -0
- package/dist/context/MCPUIConfigContext.js.map +1 -0
- package/dist/context/MCPUIStringsContext.cjs +287 -2
- package/dist/context/MCPUIStringsContext.cjs.map +1 -1
- package/dist/context/MCPUIStringsContext.d.ts +607 -3
- package/dist/context/MCPUIStringsContext.d.ts.map +1 -1
- package/dist/context/MCPUIStringsContext.js +287 -2
- package/dist/context/MCPUIStringsContext.js.map +1 -1
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/useStreamingUI.cjs +28 -10
- package/dist/hooks/useStreamingUI.cjs.map +1 -1
- package/dist/hooks/useStreamingUI.d.ts +37 -0
- package/dist/hooks/useStreamingUI.d.ts.map +1 -1
- package/dist/hooks/useStreamingUI.js +28 -10
- package/dist/hooks/useStreamingUI.js.map +1 -1
- package/dist/hooks.cjs +1 -0
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.js +2 -1
- package/dist/index.cjs +29 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -4
- package/dist/index.d.ts +12 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -3
- package/dist/index.js.map +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/validation.cjs +52 -26
- package/dist/services/validation.cjs.map +1 -1
- package/dist/services/validation.d.ts +67 -2
- package/dist/services/validation.d.ts.map +1 -1
- package/dist/services/validation.js +52 -26
- package/dist/services/validation.js.map +1 -1
- package/dist/utils/degraded-projections.cjs +37 -12
- package/dist/utils/degraded-projections.cjs.map +1 -1
- package/dist/utils/degraded-projections.d.ts +39 -3
- package/dist/utils/degraded-projections.d.ts.map +1 -1
- package/dist/utils/degraded-projections.js +37 -12
- package/dist/utils/degraded-projections.js.map +1 -1
- package/dist/utils/format-string.cjs +10 -0
- package/dist/utils/format-string.cjs.map +1 -0
- package/dist/utils/format-string.d.ts +26 -0
- package/dist/utils/format-string.d.ts.map +1 -0
- package/dist/utils/format-string.js +10 -0
- package/dist/utils/format-string.js.map +1 -0
- package/dist/utils/iframe-coep.cjs +30 -0
- package/dist/utils/iframe-coep.cjs.map +1 -0
- package/dist/utils/iframe-coep.d.ts +46 -0
- package/dist/utils/iframe-coep.d.ts.map +1 -0
- package/dist/utils/iframe-coep.js +30 -0
- package/dist/utils/iframe-coep.js.map +1 -0
- package/dist/validation.cjs +5 -0
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.d.cts +2 -1
- package/dist/validation.d.ts +2 -1
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +6 -1
- package/package.json +1 -1
- package/src/adapters/connector.ts +58 -4
- package/src/adapters/index.ts +12 -2
- package/src/adapters/macro-run.ts +71 -11
- package/src/components/ActionGroupRenderer.tsx +3 -1
- package/src/components/AgentCard.tsx +27 -9
- package/src/components/AgentHandoff.tsx +4 -1
- package/src/components/ArtifactRenderer.tsx +17 -5
- package/src/components/AutocompleteDropdown.tsx +8 -6
- package/src/components/AutocompleteFormField.tsx +5 -1
- package/src/components/BriefingDiff.tsx +11 -3
- package/src/components/CarouselRenderer.tsx +4 -2
- package/src/components/ChartJSRenderer.tsx +18 -9
- package/src/components/ChatPrompt.tsx +13 -8
- package/src/components/CodeBlockRenderer.tsx +12 -10
- package/src/components/DataPreviewSection.tsx +92 -26
- package/src/components/DegradedFallback.tsx +4 -2
- package/src/components/FooterRenderer.tsx +3 -1
- package/src/components/FormFieldRenderer.tsx +34 -19
- package/src/components/FormRenderer.tsx +38 -10
- package/src/components/GenerativeUIErrorBoundary.tsx +8 -3
- package/src/components/GraphRenderer.tsx +31 -16
- package/src/components/IframeFallbackLink.tsx +57 -0
- package/src/components/ImageGalleryRenderer.tsx +8 -4
- package/src/components/LightboxOverlay.tsx +6 -4
- package/src/components/MapRenderer.tsx +57 -20
- package/src/components/ModalRenderer.tsx +3 -1
- package/src/components/ScratchpadPanel.tsx +95 -44
- package/src/components/StreamingUIRenderer.tsx +41 -11
- package/src/components/UIResourceRenderer.tsx +176 -67
- package/src/components/VerifiedText.tsx +19 -9
- package/src/components/VideoRenderer.tsx +26 -4
- package/src/components/chart-data-table.ts +68 -14
- package/src/context/MCPActionContext.tsx +4 -1
- package/src/context/MCPUIConfigContext.tsx +151 -0
- package/src/context/MCPUIStringsContext.tsx +1014 -1
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useStreamingUI.ts +64 -10
- package/src/index.ts +38 -0
- package/src/services/index.ts +1 -0
- package/src/services/validation.ts +131 -32
- package/src/solid-jsx-attrs.d.ts +24 -0
- package/src/utils/degraded-projections.ts +75 -12
- package/src/utils/format-string.ts +33 -0
- package/src/utils/iframe-coep.ts +74 -0
- package/src/validation.ts +9 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const mcpUiSpec = require("@seed-ship/mcp-ui-spec");
|
|
4
4
|
const zod = require("zod");
|
|
5
|
+
const formatString = require("../utils/format-string.cjs");
|
|
5
6
|
function connectorActionsToActionGroup(actions, options = {}) {
|
|
6
7
|
return {
|
|
7
8
|
id: options.id ?? "connector-actions",
|
|
@@ -15,6 +16,11 @@ function connectorActionsToActionGroup(actions, options = {}) {
|
|
|
15
16
|
}
|
|
16
17
|
};
|
|
17
18
|
}
|
|
19
|
+
const DEFAULT_CONNECTOR_MESSAGES = {
|
|
20
|
+
degradedNotice: "### Result not rendered\n\nThe connector result could not be interpreted{versionSuffix}. This explicit state replaces a silent disappearance of the rendering.",
|
|
21
|
+
degradedVersionSuffix: " (schema: `{version}`)",
|
|
22
|
+
versionWarning: "> ⚠ Unrecognized connector schema (`{version}`, expected `{expected}`). The rendering below is in degraded mode."
|
|
23
|
+
};
|
|
18
24
|
const LenientResultSchema = zod.z.object({
|
|
19
25
|
schemaVersion: zod.z.string(),
|
|
20
26
|
connectorId: zod.z.string().min(1),
|
|
@@ -44,6 +50,7 @@ function degradedTextComponent(id, message) {
|
|
|
44
50
|
}
|
|
45
51
|
function connectorResultToUILayout(result, options = {}) {
|
|
46
52
|
const strict = mcpUiSpec.ConnectorDynamicResultV1Schema.safeParse(result);
|
|
53
|
+
const messages = { ...DEFAULT_CONNECTOR_MESSAGES, ...options.messages };
|
|
47
54
|
if (!strict.success) {
|
|
48
55
|
const lenient = LenientResultSchema.safeParse(result);
|
|
49
56
|
if (!lenient.success) {
|
|
@@ -53,9 +60,9 @@ function connectorResultToUILayout(result, options = {}) {
|
|
|
53
60
|
components: [
|
|
54
61
|
degradedTextComponent(
|
|
55
62
|
"connector-degraded-notice",
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
formatString.formatMCPUIString(messages.degradedNotice, {
|
|
64
|
+
versionSuffix: typeof version === "string" ? formatString.formatMCPUIString(messages.degradedVersionSuffix, { version }) : ""
|
|
65
|
+
})
|
|
59
66
|
)
|
|
60
67
|
],
|
|
61
68
|
grid: { ...DEFAULT_GRID }
|
|
@@ -65,7 +72,10 @@ Le résultat du connecteur n'a pas pu être interprété${typeof version === "st
|
|
|
65
72
|
const components2 = [
|
|
66
73
|
degradedTextComponent(
|
|
67
74
|
"connector-version-warning",
|
|
68
|
-
|
|
75
|
+
formatString.formatMCPUIString(messages.versionWarning, {
|
|
76
|
+
version: r2.schemaVersion,
|
|
77
|
+
expected: mcpUiSpec.CONNECTOR_DYNAMIC_RESULT_V1
|
|
78
|
+
})
|
|
69
79
|
),
|
|
70
80
|
...collectComponents(r2)
|
|
71
81
|
];
|
|
@@ -107,6 +117,7 @@ function collectComponents(r, actionsTitle) {
|
|
|
107
117
|
function layoutId(connectorId, suffix) {
|
|
108
118
|
return `connector-${connectorId}-${suffix}`;
|
|
109
119
|
}
|
|
120
|
+
exports.DEFAULT_CONNECTOR_MESSAGES = DEFAULT_CONNECTOR_MESSAGES;
|
|
110
121
|
exports.connectorActionsToActionGroup = connectorActionsToActionGroup;
|
|
111
122
|
exports.connectorResultToUILayout = connectorResultToUILayout;
|
|
112
123
|
//# sourceMappingURL=connector.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector.cjs","sources":["../../src/adapters/connector.ts"],"sourcesContent":["/**\n * Connector adapters — `ConnectorDynamicResultV1` → MCP-UI render structures.\n *\n * @since v6.6.0 (D5 / D6 of ROADMAP-opendata-macro-mcpui)\n *\n * ## Opt-in, pure\n *\n * These adapters are published under the dedicated subpath\n * `@seed-ship/mcp-ui-solid/adapters` — they are NEVER imported by the core\n * renderer path, so a consumer that does not emit connector results pays\n * nothing for them.\n *\n * Every adapter here is a **pure function** (D5) : same input → same\n * output, no `fetch`, no `localStorage`, no global state, no clock, no\n * randomness. This is what lets a host re-run an adapter deterministically\n * after presentation feedback (D1) and replay fixtures in tests.\n *\n * ## Unknown schema version — never throw (R2)\n *\n * `connectorResultToUILayout()` never throws on the runtime render path.\n * A payload it cannot read becomes an explicit degraded `UILayout` (a\n * visible notice), never a silent disappearance and never an exception.\n */\n\nimport type { UIComponent, UILayout, GridPosition } from '../types'\nimport {\n ConnectorDynamicResultV1Schema,\n CONNECTOR_DYNAMIC_RESULT_V1,\n type ConnectorAction,\n} from '@seed-ship/mcp-ui-spec'\nimport { z } from 'zod'\n\n// ─────────────────────────────────────────────────────────────\n// connectorActionsToActionGroup\n// ─────────────────────────────────────────────────────────────\n\nexport interface ConnectorActionsToActionGroupOptions {\n /** Component id. Default `'connector-actions'`. */\n id?: string\n /** Optional heading shown above the buttons. */\n title?: string\n /** Button row layout. Default `'horizontal'`. */\n layout?: 'horizontal' | 'vertical' | 'space-between' | 'end' | 'center'\n /** Gap between buttons. Default `'md'`. */\n gap?: 'none' | 'sm' | 'md' | 'lg'\n /** Grid position. Default full-width. */\n position?: GridPosition\n}\n\n/**\n * Wraps a connector's `actions` into an `action-group` `UIComponent`.\n *\n * `ConnectorAction` is the exact `action-group` action shape, so this is a\n * thin, pure envelope — no transformation of the actions themselves.\n */\nexport function connectorActionsToActionGroup(\n actions: ConnectorAction[],\n options: ConnectorActionsToActionGroupOptions = {}\n): UIComponent {\n return {\n id: options.id ?? 'connector-actions',\n type: 'action-group',\n position: options.position ?? { colStart: 1, colSpan: 12 },\n params: {\n actions,\n ...(options.title ? { title: options.title } : {}),\n layout: options.layout ?? 'horizontal',\n gap: options.gap ?? 'md',\n },\n } as UIComponent\n}\n\n// ─────────────────────────────────────────────────────────────\n// connectorResultToUILayout\n// ─────────────────────────────────────────────────────────────\n\nexport interface ConnectorResultToUILayoutOptions {\n /** Layout id. Default derived from `connectorId` + `queryHash` / `toolName`. */\n id?: string\n /** Heading for the actions `action-group`. */\n actionsTitle?: string\n}\n\n/**\n * Lenient mirror of `ConnectorDynamicResultV1Schema` — `schemaVersion`\n * relaxed to any string. Used to tell apart \"unknown version but otherwise\n * a usable envelope\" (→ render with a warning, R2) from \"truly unreadable\"\n * (→ explicit error state).\n */\nconst LenientResultSchema = z.object({\n schemaVersion: z.string(),\n connectorId: z.string().min(1),\n toolName: z.string().min(1),\n query: z.string(),\n queryHash: z.string().optional(),\n intent: z.string().optional(),\n primary: z.record(z.unknown()),\n supplemental: z.array(z.record(z.unknown())).optional(),\n actions: z.array(z.record(z.unknown())).optional(),\n})\n\nconst DEFAULT_GRID = { columns: 12, gap: '1rem' } as const\n\nfunction withPosition(component: UIComponent): UIComponent {\n if (component && component.position) return component\n return { ...component, position: { colStart: 1, colSpan: 12 } }\n}\n\n/** A component is a UILayout when it carries a `components` array. */\nfunction isLayoutShape(value: Record<string, unknown>): boolean {\n return Array.isArray((value as { components?: unknown }).components)\n}\n\nfunction degradedTextComponent(id: string, message: string): UIComponent {\n return {\n id,\n type: 'text',\n position: { colStart: 1, colSpan: 12 },\n params: { markdown: true, content: message },\n } as UIComponent\n}\n\n/**\n * Assembles a `ConnectorDynamicResultV1` into a single `UILayout` :\n * `primary` + `supplemental[]` + (`actions` → an `action-group`).\n *\n * - When `primary` is itself a layout, its components are spread in.\n * - Raw data is never sacrificed — every supplied component is kept.\n * - Pure : no side effects, deterministic.\n *\n * ### Degraded behavior (R2)\n *\n * - Valid v1 payload → normal assembled layout.\n * - Unknown `schemaVersion` but an otherwise-usable envelope → the\n * components are still rendered, prefixed with a visible warning notice.\n * - Unreadable payload → an explicit error `UILayout` (a single `text`\n * notice). Never throws, never returns an empty layout silently.\n *\n * A degraded layout always has an `id` starting with `connector-degraded`,\n * so a host can detect it (e.g. for telemetry) without inspecting content.\n */\nexport function connectorResultToUILayout(\n result: unknown,\n options: ConnectorResultToUILayoutOptions = {}\n): UILayout {\n const strict = ConnectorDynamicResultV1Schema.safeParse(result)\n\n // ── Tier 3 : unreadable ───────────────────────────────────\n if (!strict.success) {\n const lenient = LenientResultSchema.safeParse(result)\n if (!lenient.success) {\n const version =\n result && typeof result === 'object'\n ? (result as { schemaVersion?: unknown }).schemaVersion\n : undefined\n return {\n id: 'connector-degraded',\n components: [\n degradedTextComponent(\n 'connector-degraded-notice',\n `### Résultat non rendu\\n\\nLe résultat du connecteur n'a pas pu être interprété${\n typeof version === 'string' ? ` (schéma : \\`${version}\\`)` : ''\n }. Cet état explicite remplace une disparition silencieuse du rendu.`\n ),\n ],\n grid: { ...DEFAULT_GRID },\n }\n }\n // ── Tier 2 : usable envelope, unknown version ───────────\n const r = lenient.data\n const components: UIComponent[] = [\n degradedTextComponent(\n 'connector-version-warning',\n `> ⚠ Schéma connecteur non reconnu (\\`${r.schemaVersion}\\`, attendu \\`${CONNECTOR_DYNAMIC_RESULT_V1}\\`). Le rendu ci-dessous est en mode dégradé.`\n ),\n ...collectComponents(r),\n ]\n return {\n id: options.id ?? `connector-degraded-${r.connectorId}`,\n components: components.map(withPosition),\n grid: { ...DEFAULT_GRID },\n }\n }\n\n // ── Tier 1 : valid v1 ─────────────────────────────────────\n const r = strict.data\n const components = collectComponents(r, options.actionsTitle).map(withPosition)\n return {\n id: options.id ?? layoutId(r.connectorId, r.queryHash ?? r.toolName),\n components,\n grid: { ...DEFAULT_GRID },\n }\n}\n\n/**\n * Flattens `primary` + `supplemental` + `actions` into a component list.\n * Shared by the valid and degraded-but-usable paths.\n */\nfunction collectComponents(\n r: {\n primary: Record<string, unknown>\n supplemental?: Record<string, unknown>[]\n actions?: unknown[]\n },\n actionsTitle?: string\n): UIComponent[] {\n const components: UIComponent[] = []\n\n if (isLayoutShape(r.primary)) {\n const inner = (r.primary as { components?: UIComponent[] }).components ?? []\n components.push(...inner)\n } else {\n components.push(r.primary as unknown as UIComponent)\n }\n\n if (r.supplemental) {\n components.push(...(r.supplemental as unknown as UIComponent[]))\n }\n\n if (Array.isArray(r.actions) && r.actions.length > 0) {\n components.push(\n connectorActionsToActionGroup(r.actions as ConnectorAction[], {\n id: 'connector-actions',\n title: actionsTitle,\n })\n )\n }\n\n return components\n}\n\nfunction layoutId(connectorId: string, suffix: string): string {\n return `connector-${connectorId}-${suffix}`\n}\n"],"names":["z","ConnectorDynamicResultV1Schema","r","components","CONNECTOR_DYNAMIC_RESULT_V1"],"mappings":";;;;AAuDO,SAAS,8BACd,SACA,UAAgD,IACnC;AACb,SAAO;AAAA,IACL,IAAI,QAAQ,MAAM;AAAA,IAClB,MAAM;AAAA,IACN,UAAU,QAAQ,YAAY,EAAE,UAAU,GAAG,SAAS,GAAA;AAAA,IACtD,QAAQ;AAAA,MACN;AAAA,MACA,GAAI,QAAQ,QAAQ,EAAE,OAAO,QAAQ,MAAA,IAAU,CAAA;AAAA,MAC/C,QAAQ,QAAQ,UAAU;AAAA,MAC1B,KAAK,QAAQ,OAAO;AAAA,IAAA;AAAA,EACtB;AAEJ;AAmBA,MAAM,sBAAsBA,IAAAA,EAAE,OAAO;AAAA,EACnC,eAAeA,IAAAA,EAAE,OAAA;AAAA,EACjB,aAAaA,IAAAA,EAAE,SAAS,IAAI,CAAC;AAAA,EAC7B,UAAUA,IAAAA,EAAE,SAAS,IAAI,CAAC;AAAA,EAC1B,OAAOA,IAAAA,EAAE,OAAA;AAAA,EACT,WAAWA,IAAAA,EAAE,OAAA,EAAS,SAAA;AAAA,EACtB,QAAQA,IAAAA,EAAE,OAAA,EAAS,SAAA;AAAA,EACnB,SAASA,IAAAA,EAAE,OAAOA,IAAAA,EAAE,SAAS;AAAA,EAC7B,cAAcA,IAAAA,EAAE,MAAMA,MAAE,OAAOA,IAAAA,EAAE,QAAA,CAAS,CAAC,EAAE,SAAA;AAAA,EAC7C,SAASA,IAAAA,EAAE,MAAMA,IAAAA,EAAE,OAAOA,MAAE,SAAS,CAAC,EAAE,SAAA;AAC1C,CAAC;AAED,MAAM,eAAe,EAAE,SAAS,IAAI,KAAK,OAAA;AAEzC,SAAS,aAAa,WAAqC;AACzD,MAAI,aAAa,UAAU,SAAU,QAAO;AAC5C,SAA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,SAAO;AAAA,IACL,IAAI,QAAQ,MAAM,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ;AAAA,IACnE;AAAA,IACA,MAAM,EAAE,GAAG,aAAA;AAAA,EAAa;AAE5B;AAMA,SAAS,kBACP,GAKA,cACe;AACf,QAAM,aAA4B,CAAA;AAElC,MAAI,cAAc,EAAE,OAAO,GAAG;AAC5B,UAAM,QAAS,EAAE,QAA2C,cAAc,CAAA;AAC1E,eAAW,KAAK,GAAG,KAAK;AAAA,EAC1B,OAAO;AACL,eAAW,KAAK,EAAE,OAAiC;AAAA,EACrD;AAEA,MAAI,EAAE,cAAc;AAClB,eAAW,KAAK,GAAI,EAAE,YAAyC;AAAA,EACjE;AAEA,MAAI,MAAM,QAAQ,EAAE,OAAO,KAAK,EAAE,QAAQ,SAAS,GAAG;AACpD,eAAW;AAAA,MACT,8BAA8B,EAAE,SAA8B;AAAA,QAC5D,IAAI;AAAA,QACJ,OAAO;AAAA,MAAA,CACR;AAAA,IAAA;AAAA,EAEL;AAEA,SAAO;AACT;AAEA,SAAS,SAAS,aAAqB,QAAwB;AAC7D,SAAO,aAAa,WAAW,IAAI,MAAM;AAC3C;;;"}
|
|
1
|
+
{"version":3,"file":"connector.cjs","sources":["../../src/adapters/connector.ts"],"sourcesContent":["/**\n * Connector adapters — `ConnectorDynamicResultV1` → MCP-UI render structures.\n *\n * @since v6.6.0 (D5 / D6 of ROADMAP-opendata-macro-mcpui)\n *\n * ## Opt-in, pure\n *\n * These adapters are published under the dedicated subpath\n * `@seed-ship/mcp-ui-solid/adapters` — they are NEVER imported by the core\n * renderer path, so a consumer that does not emit connector results pays\n * nothing for them.\n *\n * Every adapter here is a **pure function** (D5) : same input → same\n * output, no `fetch`, no `localStorage`, no global state, no clock, no\n * randomness. This is what lets a host re-run an adapter deterministically\n * after presentation feedback (D1) and replay fixtures in tests.\n *\n * ## Unknown schema version — never throw (R2)\n *\n * `connectorResultToUILayout()` never throws on the runtime render path.\n * A payload it cannot read becomes an explicit degraded `UILayout` (a\n * visible notice), never a silent disappearance and never an exception.\n */\n\nimport type { UIComponent, UILayout, GridPosition } from '../types'\nimport {\n ConnectorDynamicResultV1Schema,\n CONNECTOR_DYNAMIC_RESULT_V1,\n type ConnectorAction,\n} from '@seed-ship/mcp-ui-spec'\nimport { z } from 'zod'\nimport { formatMCPUIString } from '../utils/format-string'\n\n// ─────────────────────────────────────────────────────────────\n// connectorActionsToActionGroup\n// ─────────────────────────────────────────────────────────────\n\nexport interface ConnectorActionsToActionGroupOptions {\n /** Component id. Default `'connector-actions'`. */\n id?: string\n /** Optional heading shown above the buttons. */\n title?: string\n /** Button row layout. Default `'horizontal'`. */\n layout?: 'horizontal' | 'vertical' | 'space-between' | 'end' | 'center'\n /** Gap between buttons. Default `'md'`. */\n gap?: 'none' | 'sm' | 'md' | 'lg'\n /** Grid position. Default full-width. */\n position?: GridPosition\n}\n\n/**\n * Wraps a connector's `actions` into an `action-group` `UIComponent`.\n *\n * `ConnectorAction` is the exact `action-group` action shape, so this is a\n * thin, pure envelope — no transformation of the actions themselves.\n */\nexport function connectorActionsToActionGroup(\n actions: ConnectorAction[],\n options: ConnectorActionsToActionGroupOptions = {}\n): UIComponent {\n return {\n id: options.id ?? 'connector-actions',\n type: 'action-group',\n position: options.position ?? { colStart: 1, colSpan: 12 },\n params: {\n actions,\n ...(options.title ? { title: options.title } : {}),\n layout: options.layout ?? 'horizontal',\n gap: options.gap ?? 'md',\n },\n } as UIComponent\n}\n\n// ─────────────────────────────────────────────────────────────\n// connectorResultToUILayout\n// ─────────────────────────────────────────────────────────────\n\n/**\n * The visible wording of the two degraded states (R2).\n *\n * These paragraphs are rendered as `text` components, so unlike the payload\n * they are the LIBRARY's own chrome. They cannot go through\n * `MCPUIStrings` — the adapters are runtime-free and never import\n * `solid-js` — so a host localizes them through\n * `ConnectorResultToUILayoutOptions.messages` instead.\n *\n * Every field is a template resolved with `formatMCPUIString`.\n *\n * @since v6.20.0 — the defaults used to be hardcoded French.\n */\nexport interface ConnectorAdapterMessages {\n /**\n * Unreadable payload (tier 3). Template — `{versionSuffix}` is\n * `degradedVersionSuffix` when the payload carried a string\n * `schemaVersion`, and `''` otherwise.\n */\n degradedNotice: string\n /** Inserted into `degradedNotice`. Template — `{version}`. */\n degradedVersionSuffix: string\n /**\n * Usable envelope, unknown version (tier 2). Template — `{version}` = the\n * version read, `{expected}` = `CONNECTOR_DYNAMIC_RESULT_V1`.\n */\n versionWarning: string\n}\n\n/** English defaults for {@link ConnectorAdapterMessages}. */\nexport const DEFAULT_CONNECTOR_MESSAGES: ConnectorAdapterMessages = {\n degradedNotice:\n '### Result not rendered\\n\\nThe connector result could not be interpreted{versionSuffix}. This explicit state replaces a silent disappearance of the rendering.',\n degradedVersionSuffix: ' (schema: `{version}`)',\n versionWarning:\n '> \\u26A0 Unrecognized connector schema (`{version}`, expected `{expected}`). The rendering below is in degraded mode.',\n}\n\nexport interface ConnectorResultToUILayoutOptions {\n /** Layout id. Default derived from `connectorId` + `queryHash` / `toolName`. */\n id?: string\n /** Heading for the actions `action-group`. */\n actionsTitle?: string\n /**\n * Partial override of the degraded-state wording, merged over\n * {@link DEFAULT_CONNECTOR_MESSAGES}. Hosts that render in another\n * language pass their own paragraphs here.\n *\n * @since v6.20.0\n */\n messages?: Partial<ConnectorAdapterMessages>\n}\n\n/**\n * Lenient mirror of `ConnectorDynamicResultV1Schema` — `schemaVersion`\n * relaxed to any string. Used to tell apart \"unknown version but otherwise\n * a usable envelope\" (→ render with a warning, R2) from \"truly unreadable\"\n * (→ explicit error state).\n */\nconst LenientResultSchema = z.object({\n schemaVersion: z.string(),\n connectorId: z.string().min(1),\n toolName: z.string().min(1),\n query: z.string(),\n queryHash: z.string().optional(),\n intent: z.string().optional(),\n primary: z.record(z.unknown()),\n supplemental: z.array(z.record(z.unknown())).optional(),\n actions: z.array(z.record(z.unknown())).optional(),\n})\n\nconst DEFAULT_GRID = { columns: 12, gap: '1rem' } as const\n\nfunction withPosition(component: UIComponent): UIComponent {\n if (component && component.position) return component\n return { ...component, position: { colStart: 1, colSpan: 12 } }\n}\n\n/** A component is a UILayout when it carries a `components` array. */\nfunction isLayoutShape(value: Record<string, unknown>): boolean {\n return Array.isArray((value as { components?: unknown }).components)\n}\n\nfunction degradedTextComponent(id: string, message: string): UIComponent {\n return {\n id,\n type: 'text',\n position: { colStart: 1, colSpan: 12 },\n params: { markdown: true, content: message },\n } as UIComponent\n}\n\n/**\n * Assembles a `ConnectorDynamicResultV1` into a single `UILayout` :\n * `primary` + `supplemental[]` + (`actions` → an `action-group`).\n *\n * - When `primary` is itself a layout, its components are spread in.\n * - Raw data is never sacrificed — every supplied component is kept.\n * - Pure : no side effects, deterministic.\n *\n * ### Degraded behavior (R2)\n *\n * - Valid v1 payload → normal assembled layout.\n * - Unknown `schemaVersion` but an otherwise-usable envelope → the\n * components are still rendered, prefixed with a visible warning notice.\n * - Unreadable payload → an explicit error `UILayout` (a single `text`\n * notice). Never throws, never returns an empty layout silently.\n *\n * A degraded layout always has an `id` starting with `connector-degraded`,\n * so a host can detect it (e.g. for telemetry) without inspecting content.\n */\nexport function connectorResultToUILayout(\n result: unknown,\n options: ConnectorResultToUILayoutOptions = {}\n): UILayout {\n const strict = ConnectorDynamicResultV1Schema.safeParse(result)\n const messages: ConnectorAdapterMessages = { ...DEFAULT_CONNECTOR_MESSAGES, ...options.messages }\n\n // ── Tier 3 : unreadable ───────────────────────────────────\n if (!strict.success) {\n const lenient = LenientResultSchema.safeParse(result)\n if (!lenient.success) {\n const version =\n result && typeof result === 'object'\n ? (result as { schemaVersion?: unknown }).schemaVersion\n : undefined\n return {\n id: 'connector-degraded',\n components: [\n degradedTextComponent(\n 'connector-degraded-notice',\n formatMCPUIString(messages.degradedNotice, {\n versionSuffix:\n typeof version === 'string'\n ? formatMCPUIString(messages.degradedVersionSuffix, { version })\n : '',\n })\n ),\n ],\n grid: { ...DEFAULT_GRID },\n }\n }\n // ── Tier 2 : usable envelope, unknown version ───────────\n const r = lenient.data\n const components: UIComponent[] = [\n degradedTextComponent(\n 'connector-version-warning',\n formatMCPUIString(messages.versionWarning, {\n version: r.schemaVersion,\n expected: CONNECTOR_DYNAMIC_RESULT_V1,\n })\n ),\n ...collectComponents(r),\n ]\n return {\n id: options.id ?? `connector-degraded-${r.connectorId}`,\n components: components.map(withPosition),\n grid: { ...DEFAULT_GRID },\n }\n }\n\n // ── Tier 1 : valid v1 ─────────────────────────────────────\n const r = strict.data\n const components = collectComponents(r, options.actionsTitle).map(withPosition)\n return {\n id: options.id ?? layoutId(r.connectorId, r.queryHash ?? r.toolName),\n components,\n grid: { ...DEFAULT_GRID },\n }\n}\n\n/**\n * Flattens `primary` + `supplemental` + `actions` into a component list.\n * Shared by the valid and degraded-but-usable paths.\n */\nfunction collectComponents(\n r: {\n primary: Record<string, unknown>\n supplemental?: Record<string, unknown>[]\n actions?: unknown[]\n },\n actionsTitle?: string\n): UIComponent[] {\n const components: UIComponent[] = []\n\n if (isLayoutShape(r.primary)) {\n const inner = (r.primary as { components?: UIComponent[] }).components ?? []\n components.push(...inner)\n } else {\n components.push(r.primary as unknown as UIComponent)\n }\n\n if (r.supplemental) {\n components.push(...(r.supplemental as unknown as UIComponent[]))\n }\n\n if (Array.isArray(r.actions) && r.actions.length > 0) {\n components.push(\n connectorActionsToActionGroup(r.actions as ConnectorAction[], {\n id: 'connector-actions',\n title: actionsTitle,\n })\n )\n }\n\n return components\n}\n\nfunction layoutId(connectorId: string, suffix: string): string {\n return `connector-${connectorId}-${suffix}`\n}\n"],"names":["z","ConnectorDynamicResultV1Schema","formatMCPUIString","r","components","CONNECTOR_DYNAMIC_RESULT_V1"],"mappings":";;;;;AAwDO,SAAS,8BACd,SACA,UAAgD,IACnC;AACb,SAAO;AAAA,IACL,IAAI,QAAQ,MAAM;AAAA,IAClB,MAAM;AAAA,IACN,UAAU,QAAQ,YAAY,EAAE,UAAU,GAAG,SAAS,GAAA;AAAA,IACtD,QAAQ;AAAA,MACN;AAAA,MAC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AAM,EAAE,GAAG,aAAA;AAAA,EAAa;AAE5B;AAMA,SAAS,kBACP,GAKA,cACe;AACf,QAAM,aAA4B,CAAA;AAElC,MAAI,cAAc,EAAE,OAAO,GAAG;AAC5B,UAAM,QAAS,EAAE,QAA2C,cAAc,CAAA;AAC1E,eAAW,KAAK,GAAG,KAAK;AAAA,EAC1B,OAAO;AACL,eAAW,KAAK,EAAE,OAAiC;AAAA,EACrD;AAEA,MAAI,EAAE,cAAc;AAClB,eAAW,KAAK,GAAI,EAAE,YAAyC;AAAA,EACjE;AAEA,MAAI,MAAM,QAAQ,EAAE,OAAO,KAAK,EAAE,QAAQ,SAAS,GAAG;AACpD,eAAW;AAAA,MACT,8BAA8B,EAAE,SAA8B;AAAA,QAC5D,IAAI;AAAA,QACJ,OAAO;AAAA,MAAA,CACR;AAAA,IAAA;AAAA,EAEL;AAEA,SAAO;AACT;AAEA,SAAS,SAAS,aAAqB,QAAwB;AAC7D,SAAO,aAAa,WAAW,IAAI,MAAM;AAC3C;;;;"}
|
|
@@ -42,11 +42,49 @@ export interface ConnectorActionsToActionGroupOptions {
|
|
|
42
42
|
* thin, pure envelope — no transformation of the actions themselves.
|
|
43
43
|
*/
|
|
44
44
|
export declare function connectorActionsToActionGroup(actions: ConnectorAction[], options?: ConnectorActionsToActionGroupOptions): UIComponent;
|
|
45
|
+
/**
|
|
46
|
+
* The visible wording of the two degraded states (R2).
|
|
47
|
+
*
|
|
48
|
+
* These paragraphs are rendered as `text` components, so unlike the payload
|
|
49
|
+
* they are the LIBRARY's own chrome. They cannot go through
|
|
50
|
+
* `MCPUIStrings` — the adapters are runtime-free and never import
|
|
51
|
+
* `solid-js` — so a host localizes them through
|
|
52
|
+
* `ConnectorResultToUILayoutOptions.messages` instead.
|
|
53
|
+
*
|
|
54
|
+
* Every field is a template resolved with `formatMCPUIString`.
|
|
55
|
+
*
|
|
56
|
+
* @since v6.20.0 — the defaults used to be hardcoded French.
|
|
57
|
+
*/
|
|
58
|
+
export interface ConnectorAdapterMessages {
|
|
59
|
+
/**
|
|
60
|
+
* Unreadable payload (tier 3). Template — `{versionSuffix}` is
|
|
61
|
+
* `degradedVersionSuffix` when the payload carried a string
|
|
62
|
+
* `schemaVersion`, and `''` otherwise.
|
|
63
|
+
*/
|
|
64
|
+
degradedNotice: string;
|
|
65
|
+
/** Inserted into `degradedNotice`. Template — `{version}`. */
|
|
66
|
+
degradedVersionSuffix: string;
|
|
67
|
+
/**
|
|
68
|
+
* Usable envelope, unknown version (tier 2). Template — `{version}` = the
|
|
69
|
+
* version read, `{expected}` = `CONNECTOR_DYNAMIC_RESULT_V1`.
|
|
70
|
+
*/
|
|
71
|
+
versionWarning: string;
|
|
72
|
+
}
|
|
73
|
+
/** English defaults for {@link ConnectorAdapterMessages}. */
|
|
74
|
+
export declare const DEFAULT_CONNECTOR_MESSAGES: ConnectorAdapterMessages;
|
|
45
75
|
export interface ConnectorResultToUILayoutOptions {
|
|
46
76
|
/** Layout id. Default derived from `connectorId` + `queryHash` / `toolName`. */
|
|
47
77
|
id?: string;
|
|
48
78
|
/** Heading for the actions `action-group`. */
|
|
49
79
|
actionsTitle?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Partial override of the degraded-state wording, merged over
|
|
82
|
+
* {@link DEFAULT_CONNECTOR_MESSAGES}. Hosts that render in another
|
|
83
|
+
* language pass their own paragraphs here.
|
|
84
|
+
*
|
|
85
|
+
* @since v6.20.0
|
|
86
|
+
*/
|
|
87
|
+
messages?: Partial<ConnectorAdapterMessages>;
|
|
50
88
|
}
|
|
51
89
|
/**
|
|
52
90
|
* Assembles a `ConnectorDynamicResultV1` into a single `UILayout` :
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../src/adapters/connector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,UAAU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OAAO,CAAC,wBAAwB,CAAC,CAAA;CAC7C;AAyCD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,OAAO,EACf,OAAO,GAAE,gCAAqC,GAC7C,QAAQ,CAuDV"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ConnectorDynamicResultV1Schema, CONNECTOR_DYNAMIC_RESULT_V1 } from "@seed-ship/mcp-ui-spec";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { formatMCPUIString } from "../utils/format-string.js";
|
|
3
4
|
function connectorActionsToActionGroup(actions, options = {}) {
|
|
4
5
|
return {
|
|
5
6
|
id: options.id ?? "connector-actions",
|
|
@@ -13,6 +14,11 @@ function connectorActionsToActionGroup(actions, options = {}) {
|
|
|
13
14
|
}
|
|
14
15
|
};
|
|
15
16
|
}
|
|
17
|
+
const DEFAULT_CONNECTOR_MESSAGES = {
|
|
18
|
+
degradedNotice: "### Result not rendered\n\nThe connector result could not be interpreted{versionSuffix}. This explicit state replaces a silent disappearance of the rendering.",
|
|
19
|
+
degradedVersionSuffix: " (schema: `{version}`)",
|
|
20
|
+
versionWarning: "> ⚠ Unrecognized connector schema (`{version}`, expected `{expected}`). The rendering below is in degraded mode."
|
|
21
|
+
};
|
|
16
22
|
const LenientResultSchema = z.object({
|
|
17
23
|
schemaVersion: z.string(),
|
|
18
24
|
connectorId: z.string().min(1),
|
|
@@ -42,6 +48,7 @@ function degradedTextComponent(id, message) {
|
|
|
42
48
|
}
|
|
43
49
|
function connectorResultToUILayout(result, options = {}) {
|
|
44
50
|
const strict = ConnectorDynamicResultV1Schema.safeParse(result);
|
|
51
|
+
const messages = { ...DEFAULT_CONNECTOR_MESSAGES, ...options.messages };
|
|
45
52
|
if (!strict.success) {
|
|
46
53
|
const lenient = LenientResultSchema.safeParse(result);
|
|
47
54
|
if (!lenient.success) {
|
|
@@ -51,9 +58,9 @@ function connectorResultToUILayout(result, options = {}) {
|
|
|
51
58
|
components: [
|
|
52
59
|
degradedTextComponent(
|
|
53
60
|
"connector-degraded-notice",
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
formatMCPUIString(messages.degradedNotice, {
|
|
62
|
+
versionSuffix: typeof version === "string" ? formatMCPUIString(messages.degradedVersionSuffix, { version }) : ""
|
|
63
|
+
})
|
|
57
64
|
)
|
|
58
65
|
],
|
|
59
66
|
grid: { ...DEFAULT_GRID }
|
|
@@ -63,7 +70,10 @@ Le résultat du connecteur n'a pas pu être interprété${typeof version === "st
|
|
|
63
70
|
const components2 = [
|
|
64
71
|
degradedTextComponent(
|
|
65
72
|
"connector-version-warning",
|
|
66
|
-
|
|
73
|
+
formatMCPUIString(messages.versionWarning, {
|
|
74
|
+
version: r2.schemaVersion,
|
|
75
|
+
expected: CONNECTOR_DYNAMIC_RESULT_V1
|
|
76
|
+
})
|
|
67
77
|
),
|
|
68
78
|
...collectComponents(r2)
|
|
69
79
|
];
|
|
@@ -106,6 +116,7 @@ function layoutId(connectorId, suffix) {
|
|
|
106
116
|
return `connector-${connectorId}-${suffix}`;
|
|
107
117
|
}
|
|
108
118
|
export {
|
|
119
|
+
DEFAULT_CONNECTOR_MESSAGES,
|
|
109
120
|
connectorActionsToActionGroup,
|
|
110
121
|
connectorResultToUILayout
|
|
111
122
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector.js","sources":["../../src/adapters/connector.ts"],"sourcesContent":["/**\n * Connector adapters — `ConnectorDynamicResultV1` → MCP-UI render structures.\n *\n * @since v6.6.0 (D5 / D6 of ROADMAP-opendata-macro-mcpui)\n *\n * ## Opt-in, pure\n *\n * These adapters are published under the dedicated subpath\n * `@seed-ship/mcp-ui-solid/adapters` — they are NEVER imported by the core\n * renderer path, so a consumer that does not emit connector results pays\n * nothing for them.\n *\n * Every adapter here is a **pure function** (D5) : same input → same\n * output, no `fetch`, no `localStorage`, no global state, no clock, no\n * randomness. This is what lets a host re-run an adapter deterministically\n * after presentation feedback (D1) and replay fixtures in tests.\n *\n * ## Unknown schema version — never throw (R2)\n *\n * `connectorResultToUILayout()` never throws on the runtime render path.\n * A payload it cannot read becomes an explicit degraded `UILayout` (a\n * visible notice), never a silent disappearance and never an exception.\n */\n\nimport type { UIComponent, UILayout, GridPosition } from '../types'\nimport {\n ConnectorDynamicResultV1Schema,\n CONNECTOR_DYNAMIC_RESULT_V1,\n type ConnectorAction,\n} from '@seed-ship/mcp-ui-spec'\nimport { z } from 'zod'\n\n// ─────────────────────────────────────────────────────────────\n// connectorActionsToActionGroup\n// ─────────────────────────────────────────────────────────────\n\nexport interface ConnectorActionsToActionGroupOptions {\n /** Component id. Default `'connector-actions'`. */\n id?: string\n /** Optional heading shown above the buttons. */\n title?: string\n /** Button row layout. Default `'horizontal'`. */\n layout?: 'horizontal' | 'vertical' | 'space-between' | 'end' | 'center'\n /** Gap between buttons. Default `'md'`. */\n gap?: 'none' | 'sm' | 'md' | 'lg'\n /** Grid position. Default full-width. */\n position?: GridPosition\n}\n\n/**\n * Wraps a connector's `actions` into an `action-group` `UIComponent`.\n *\n * `ConnectorAction` is the exact `action-group` action shape, so this is a\n * thin, pure envelope — no transformation of the actions themselves.\n */\nexport function connectorActionsToActionGroup(\n actions: ConnectorAction[],\n options: ConnectorActionsToActionGroupOptions = {}\n): UIComponent {\n return {\n id: options.id ?? 'connector-actions',\n type: 'action-group',\n position: options.position ?? { colStart: 1, colSpan: 12 },\n params: {\n actions,\n ...(options.title ? { title: options.title } : {}),\n layout: options.layout ?? 'horizontal',\n gap: options.gap ?? 'md',\n },\n } as UIComponent\n}\n\n// ─────────────────────────────────────────────────────────────\n// connectorResultToUILayout\n// ─────────────────────────────────────────────────────────────\n\nexport interface ConnectorResultToUILayoutOptions {\n /** Layout id. Default derived from `connectorId` + `queryHash` / `toolName`. */\n id?: string\n /** Heading for the actions `action-group`. */\n actionsTitle?: string\n}\n\n/**\n * Lenient mirror of `ConnectorDynamicResultV1Schema` — `schemaVersion`\n * relaxed to any string. Used to tell apart \"unknown version but otherwise\n * a usable envelope\" (→ render with a warning, R2) from \"truly unreadable\"\n * (→ explicit error state).\n */\nconst LenientResultSchema = z.object({\n schemaVersion: z.string(),\n connectorId: z.string().min(1),\n toolName: z.string().min(1),\n query: z.string(),\n queryHash: z.string().optional(),\n intent: z.string().optional(),\n primary: z.record(z.unknown()),\n supplemental: z.array(z.record(z.unknown())).optional(),\n actions: z.array(z.record(z.unknown())).optional(),\n})\n\nconst DEFAULT_GRID = { columns: 12, gap: '1rem' } as const\n\nfunction withPosition(component: UIComponent): UIComponent {\n if (component && component.position) return component\n return { ...component, position: { colStart: 1, colSpan: 12 } }\n}\n\n/** A component is a UILayout when it carries a `components` array. */\nfunction isLayoutShape(value: Record<string, unknown>): boolean {\n return Array.isArray((value as { components?: unknown }).components)\n}\n\nfunction degradedTextComponent(id: string, message: string): UIComponent {\n return {\n id,\n type: 'text',\n position: { colStart: 1, colSpan: 12 },\n params: { markdown: true, content: message },\n } as UIComponent\n}\n\n/**\n * Assembles a `ConnectorDynamicResultV1` into a single `UILayout` :\n * `primary` + `supplemental[]` + (`actions` → an `action-group`).\n *\n * - When `primary` is itself a layout, its components are spread in.\n * - Raw data is never sacrificed — every supplied component is kept.\n * - Pure : no side effects, deterministic.\n *\n * ### Degraded behavior (R2)\n *\n * - Valid v1 payload → normal assembled layout.\n * - Unknown `schemaVersion` but an otherwise-usable envelope → the\n * components are still rendered, prefixed with a visible warning notice.\n * - Unreadable payload → an explicit error `UILayout` (a single `text`\n * notice). Never throws, never returns an empty layout silently.\n *\n * A degraded layout always has an `id` starting with `connector-degraded`,\n * so a host can detect it (e.g. for telemetry) without inspecting content.\n */\nexport function connectorResultToUILayout(\n result: unknown,\n options: ConnectorResultToUILayoutOptions = {}\n): UILayout {\n const strict = ConnectorDynamicResultV1Schema.safeParse(result)\n\n // ── Tier 3 : unreadable ───────────────────────────────────\n if (!strict.success) {\n const lenient = LenientResultSchema.safeParse(result)\n if (!lenient.success) {\n const version =\n result && typeof result === 'object'\n ? (result as { schemaVersion?: unknown }).schemaVersion\n : undefined\n return {\n id: 'connector-degraded',\n components: [\n degradedTextComponent(\n 'connector-degraded-notice',\n `### Résultat non rendu\\n\\nLe résultat du connecteur n'a pas pu être interprété${\n typeof version === 'string' ? ` (schéma : \\`${version}\\`)` : ''\n }. Cet état explicite remplace une disparition silencieuse du rendu.`\n ),\n ],\n grid: { ...DEFAULT_GRID },\n }\n }\n // ── Tier 2 : usable envelope, unknown version ───────────\n const r = lenient.data\n const components: UIComponent[] = [\n degradedTextComponent(\n 'connector-version-warning',\n `> ⚠ Schéma connecteur non reconnu (\\`${r.schemaVersion}\\`, attendu \\`${CONNECTOR_DYNAMIC_RESULT_V1}\\`). Le rendu ci-dessous est en mode dégradé.`\n ),\n ...collectComponents(r),\n ]\n return {\n id: options.id ?? `connector-degraded-${r.connectorId}`,\n components: components.map(withPosition),\n grid: { ...DEFAULT_GRID },\n }\n }\n\n // ── Tier 1 : valid v1 ─────────────────────────────────────\n const r = strict.data\n const components = collectComponents(r, options.actionsTitle).map(withPosition)\n return {\n id: options.id ?? layoutId(r.connectorId, r.queryHash ?? r.toolName),\n components,\n grid: { ...DEFAULT_GRID },\n }\n}\n\n/**\n * Flattens `primary` + `supplemental` + `actions` into a component list.\n * Shared by the valid and degraded-but-usable paths.\n */\nfunction collectComponents(\n r: {\n primary: Record<string, unknown>\n supplemental?: Record<string, unknown>[]\n actions?: unknown[]\n },\n actionsTitle?: string\n): UIComponent[] {\n const components: UIComponent[] = []\n\n if (isLayoutShape(r.primary)) {\n const inner = (r.primary as { components?: UIComponent[] }).components ?? []\n components.push(...inner)\n } else {\n components.push(r.primary as unknown as UIComponent)\n }\n\n if (r.supplemental) {\n components.push(...(r.supplemental as unknown as UIComponent[]))\n }\n\n if (Array.isArray(r.actions) && r.actions.length > 0) {\n components.push(\n connectorActionsToActionGroup(r.actions as ConnectorAction[], {\n id: 'connector-actions',\n title: actionsTitle,\n })\n )\n }\n\n return components\n}\n\nfunction layoutId(connectorId: string, suffix: string): string {\n return `connector-${connectorId}-${suffix}`\n}\n"],"names":["r","components"],"mappings":";;AAuDO,SAAS,8BACd,SACA,UAAgD,IACnC;AACb,SAAO;AAAA,IACL,IAAI,QAAQ,MAAM;AAAA,IAClB,MAAM;AAAA,IACN,UAAU,QAAQ,YAAY,EAAE,UAAU,GAAG,SAAS,GAAA;AAAA,IACtD,QAAQ;AAAA,MACN;AAAA,MACA,GAAI,QAAQ,QAAQ,EAAE,OAAO,QAAQ,MAAA,IAAU,CAAA;AAAA,MAC/C,QAAQ,QAAQ,UAAU;AAAA,MAC1B,KAAK,QAAQ,OAAO;AAAA,IAAA;AAAA,EACtB;AAEJ;AAmBA,MAAM,sBAAsB,EAAE,OAAO;AAAA,EACnC,eAAe,EAAE,OAAA;AAAA,EACjB,aAAa,EAAE,SAAS,IAAI,CAAC;AAAA,EAC7B,UAAU,EAAE,SAAS,IAAI,CAAC;AAAA,EAC1B,OAAO,EAAE,OAAA;AAAA,EACT,WAAW,EAAE,OAAA,EAAS,SAAA;AAAA,EACtB,QAAQ,EAAE,OAAA,EAAS,SAAA;AAAA,EACnB,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,QAAA,CAAS,CAAC,EAAE,SAAA;AAAA,EAC7C,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,SAAA;AAC1C,CAAC;AAED,MAAM,eAAe,EAAE,SAAS,IAAI,KAAK,OAAA;AAEzC,SAAS,aAAa,WAAqC;AACzD,MAAI,aAAa,UAAU,SAAU,QAAO;AAC5C,SAAO,EAAE,GAAG,WAAW,UAAU,EAAE,UAAU,GAAG,SAAS,KAAG;AAC9D;AAGA,SAAS,cAAc,OAAyC;AAC9D,SAAO,MAAM,QAAS,MAAmC,UAAU;AACrE;AAEA,SAAS,sBAAsB,IAAY,SAA8B;AACvE,SAAO;AAAA,IACL;A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AAI,cAAc,EAAE,OAAO,GAAG;AAC5B,UAAM,QAAS,EAAE,QAA2C,cAAc,CAAA;AAC1E,eAAW,KAAK,GAAG,KAAK;AAAA,EAC1B,OAAO;AACL,eAAW,KAAK,EAAE,OAAiC;AAAA,EACrD;AAEA,MAAI,EAAE,cAAc;AAClB,eAAW,KAAK,GAAI,EAAE,YAAyC;AAAA,EACjE;AAEA,MAAI,MAAM,QAAQ,EAAE,OAAO,KAAK,EAAE,QAAQ,SAAS,GAAG;AACpD,eAAW;AAAA,MACT,8BAA8B,EAAE,SAA8B;AAAA,QAC5D,IAAI;AAAA,QACJ,OAAO;AAAA,MAAA,CACR;AAAA,IAAA;AAAA,EAEL;AAEA,SAAO;AACT;AAEA,SAAS,SAAS,aAAqB,QAAwB;AAC7D,SAAO,aAAa,WAAW,IAAI,MAAM;AAC3C;"}
|
|
1
|
+
{"version":3,"file":"connector.js","sources":["../../src/adapters/connector.ts"],"sourcesContent":["/**\n * Connector adapters — `ConnectorDynamicResultV1` → MCP-UI render structures.\n *\n * @since v6.6.0 (D5 / D6 of ROADMAP-opendata-macro-mcpui)\n *\n * ## Opt-in, pure\n *\n * These adapters are published under the dedicated subpath\n * `@seed-ship/mcp-ui-solid/adapters` — they are NEVER imported by the core\n * renderer path, so a consumer that does not emit connector results pays\n * nothing for them.\n *\n * Every adapter here is a **pure function** (D5) : same input → same\n * output, no `fetch`, no `localStorage`, no global state, no clock, no\n * randomness. This is what lets a host re-run an adapter deterministically\n * after presentation feedback (D1) and replay fixtures in tests.\n *\n * ## Unknown schema version — never throw (R2)\n *\n * `connectorResultToUILayout()` never throws on the runtime render path.\n * A payload it cannot read becomes an explicit degraded `UILayout` (a\n * visible notice), never a silent disappearance and never an exception.\n */\n\nimport type { UIComponent, UILayout, GridPosition } from '../types'\nimport {\n ConnectorDynamicResultV1Schema,\n CONNECTOR_DYNAMIC_RESULT_V1,\n type ConnectorAction,\n} from '@seed-ship/mcp-ui-spec'\nimport { z } from 'zod'\nimport { formatMCPUIString } from '../utils/format-string'\n\n// ─────────────────────────────────────────────────────────────\n// connectorActionsToActionGroup\n// ─────────────────────────────────────────────────────────────\n\nexport interface ConnectorActionsToActionGroupOptions {\n /** Component id. Default `'connector-actions'`. */\n id?: string\n /** Optional heading shown above the buttons. */\n title?: string\n /** Button row layout. Default `'horizontal'`. */\n layout?: 'horizontal' | 'vertical' | 'space-between' | 'end' | 'center'\n /** Gap between buttons. Default `'md'`. */\n gap?: 'none' | 'sm' | 'md' | 'lg'\n /** Grid position. Default full-width. */\n position?: GridPosition\n}\n\n/**\n * Wraps a connector's `actions` into an `action-group` `UIComponent`.\n *\n * `ConnectorAction` is the exact `action-group` action shape, so this is a\n * thin, pure envelope — no transformation of the actions themselves.\n */\nexport function connectorActionsToActionGroup(\n actions: ConnectorAction[],\n options: ConnectorActionsToActionGroupOptions = {}\n): UIComponent {\n return {\n id: options.id ?? 'connector-actions',\n type: 'action-group',\n position: options.position ?? { colStart: 1, colSpan: 12 },\n params: {\n actions,\n ...(options.title ? { title: options.title } : {}),\n layout: options.layout ?? 'horizontal',\n gap: options.gap ?? 'md',\n },\n } as UIComponent\n}\n\n// ─────────────────────────────────────────────────────────────\n// connectorResultToUILayout\n// ─────────────────────────────────────────────────────────────\n\n/**\n * The visible wording of the two degraded states (R2).\n *\n * These paragraphs are rendered as `text` components, so unlike the payload\n * they are the LIBRARY's own chrome. They cannot go through\n * `MCPUIStrings` — the adapters are runtime-free and never import\n * `solid-js` — so a host localizes them through\n * `ConnectorResultToUILayoutOptions.messages` instead.\n *\n * Every field is a template resolved with `formatMCPUIString`.\n *\n * @since v6.20.0 — the defaults used to be hardcoded French.\n */\nexport interface ConnectorAdapterMessages {\n /**\n * Unreadable payload (tier 3). Template — `{versionSuffix}` is\n * `degradedVersionSuffix` when the payload carried a string\n * `schemaVersion`, and `''` otherwise.\n */\n degradedNotice: string\n /** Inserted into `degradedNotice`. Template — `{version}`. */\n degradedVersionSuffix: string\n /**\n * Usable envelope, unknown version (tier 2). Template — `{version}` = the\n * version read, `{expected}` = `CONNECTOR_DYNAMIC_RESULT_V1`.\n */\n versionWarning: string\n}\n\n/** English defaults for {@link ConnectorAdapterMessages}. */\nexport const DEFAULT_CONNECTOR_MESSAGES: ConnectorAdapterMessages = {\n degradedNotice:\n '### Result not rendered\\n\\nThe connector result could not be interpreted{versionSuffix}. This explicit state replaces a silent disappearance of the rendering.',\n degradedVersionSuffix: ' (schema: `{version}`)',\n versionWarning:\n '> \\u26A0 Unrecognized connector schema (`{version}`, expected `{expected}`). The rendering below is in degraded mode.',\n}\n\nexport interface ConnectorResultToUILayoutOptions {\n /** Layout id. Default derived from `connectorId` + `queryHash` / `toolName`. */\n id?: string\n /** Heading for the actions `action-group`. */\n actionsTitle?: string\n /**\n * Partial override of the degraded-state wording, merged over\n * {@link DEFAULT_CONNECTOR_MESSAGES}. Hosts that render in another\n * language pass their own paragraphs here.\n *\n * @since v6.20.0\n */\n messages?: Partial<ConnectorAdapterMessages>\n}\n\n/**\n * Lenient mirror of `ConnectorDynamicResultV1Schema` — `schemaVersion`\n * relaxed to any string. Used to tell apart \"unknown version but otherwise\n * a usable envelope\" (→ render with a warning, R2) from \"truly unreadable\"\n * (→ explicit error state).\n */\nconst LenientResultSchema = z.object({\n schemaVersion: z.string(),\n connectorId: z.string().min(1),\n toolName: z.string().min(1),\n query: z.string(),\n queryHash: z.string().optional(),\n intent: z.string().optional(),\n primary: z.record(z.unknown()),\n supplemental: z.array(z.record(z.unknown())).optional(),\n actions: z.array(z.record(z.unknown())).optional(),\n})\n\nconst DEFAULT_GRID = { columns: 12, gap: '1rem' } as const\n\nfunction withPosition(component: UIComponent): UIComponent {\n if (component && component.position) return component\n return { ...component, position: { colStart: 1, colSpan: 12 } }\n}\n\n/** A component is a UILayout when it carries a `components` array. */\nfunction isLayoutShape(value: Record<string, unknown>): boolean {\n return Array.isArray((value as { components?: unknown }).components)\n}\n\nfunction degradedTextComponent(id: string, message: string): UIComponent {\n return {\n id,\n type: 'text',\n position: { colStart: 1, colSpan: 12 },\n params: { markdown: true, content: message },\n } as UIComponent\n}\n\n/**\n * Assembles a `ConnectorDynamicResultV1` into a single `UILayout` :\n * `primary` + `supplemental[]` + (`actions` → an `action-group`).\n *\n * - When `primary` is itself a layout, its components are spread in.\n * - Raw data is never sacrificed — every supplied component is kept.\n * - Pure : no side effects, deterministic.\n *\n * ### Degraded behavior (R2)\n *\n * - Valid v1 payload → normal assembled layout.\n * - Unknown `schemaVersion` but an otherwise-usable envelope → the\n * components are still rendered, prefixed with a visible warning notice.\n * - Unreadable payload → an explicit error `UILayout` (a single `text`\n * notice). Never throws, never returns an empty layout silently.\n *\n * A degraded layout always has an `id` starting with `connector-degraded`,\n * so a host can detect it (e.g. for telemetry) without inspecting content.\n */\nexport function connectorResultToUILayout(\n result: unknown,\n options: ConnectorResultToUILayoutOptions = {}\n): UILayout {\n const strict = ConnectorDynamicResultV1Schema.safeParse(result)\n const messages: ConnectorAdapterMessages = { ...DEFAULT_CONNECTOR_MESSAGES, ...options.messages }\n\n // ── Tier 3 : unreadable ───────────────────────────────────\n if (!strict.success) {\n const lenient = LenientResultSchema.safeParse(result)\n if (!lenient.success) {\n const version =\n result && typeof result === 'object'\n ? (result as { schemaVersion?: unknown }).schemaVersion\n : undefined\n return {\n id: 'connector-degraded',\n components: [\n degradedTextComponent(\n 'connector-degraded-notice',\n formatMCPUIString(messages.degradedNotice, {\n versionSuffix:\n typeof version === 'string'\n ? formatMCPUIString(messages.degradedVersionSuffix, { version })\n : '',\n })\n ),\n ],\n grid: { ...DEFAULT_GRID },\n }\n }\n // ── Tier 2 : usable envelope, unknown version ───────────\n const r = lenient.data\n const components: UIComponent[] = [\n degradedTextComponent(\n 'connector-version-warning',\n formatMCPUIString(messages.versionWarning, {\n version: r.schemaVersion,\n expected: CONNECTOR_DYNAMIC_RESULT_V1,\n })\n ),\n ...collectComponents(r),\n ]\n return {\n id: options.id ?? `connector-degraded-${r.connectorId}`,\n components: components.map(withPosition),\n grid: { ...DEFAULT_GRID },\n }\n }\n\n // ── Tier 1 : valid v1 ─────────────────────────────────────\n const r = strict.data\n const components = collectComponents(r, options.actionsTitle).map(withPosition)\n return {\n id: options.id ?? layoutId(r.connectorId, r.queryHash ?? r.toolName),\n components,\n grid: { ...DEFAULT_GRID },\n }\n}\n\n/**\n * Flattens `primary` + `supplemental` + `actions` into a component list.\n * Shared by the valid and degraded-but-usable paths.\n */\nfunction collectComponents(\n r: {\n primary: Record<string, unknown>\n supplemental?: Record<string, unknown>[]\n actions?: unknown[]\n },\n actionsTitle?: string\n): UIComponent[] {\n const components: UIComponent[] = []\n\n if (isLayoutShape(r.primary)) {\n const inner = (r.primary as { components?: UIComponent[] }).components ?? []\n components.push(...inner)\n } else {\n components.push(r.primary as unknown as UIComponent)\n }\n\n if (r.supplemental) {\n components.push(...(r.supplemental as unknown as UIComponent[]))\n }\n\n if (Array.isArray(r.actions) && r.actions.length > 0) {\n components.push(\n connectorActionsToActionGroup(r.actions as ConnectorAction[], {\n id: 'connector-actions',\n title: actionsTitle,\n })\n )\n }\n\n return components\n}\n\nfunction layoutId(connectorId: string, suffix: string): string {\n return `connector-${connectorId}-${suffix}`\n}\n"],"names":["r","components"],"mappings":";;;AAwDO,SAAS,8BACd,SACA,UAAgD,IACnC;AACb,SAAO;AAAA,IACL,IAAI,QAAQ,MAAM;AAAA,IAClB,MAAM;AAAA,IACN,UAAU,QAAQ,YAAY,EAAE,UAAU,GAAG,SAAS,GAAA;AAAA,IACtD,QAAQ;AAAA,MACN;AAAA,MACA,GAAI,QAAQ,QAAQ,EAAE,OAAO,QAAQ,MAAA,IAAU,CAAA;AAAA,MAC/C,QAAQ,QAAQ,UAAU;AAAA,MAC1B,KAAK,QAAQ,OAAO;AAAA,IAAA;AAAA,EACtB;AAEJ;AAoCO,MAAM,6BAAuD;AAAA,EAClE,gBACE;AAAA,EACF,uBAAuB;AAAA,EACvB,gBACE;AACJ;AAuBA,MAAM,sBAAsB,EAAE,OAAO;AA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,MACT,8BAA8B,EAAE,SAA8B;AAAA,QAC5D,IAAI;AAAA,QACJ,OAAO;AAAA,MAAA,CACR;AAAA,IAAA;AAAA,EAEL;AAEA,SAAO;AACT;AAEA,SAAS,SAAS,aAAqB,QAAwB;AAC7D,SAAO,aAAa,WAAW,IAAI,MAAM;AAC3C;"}
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
* // → <UIResourceRenderer content={layout} />
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
|
-
export { connectorResultToUILayout, connectorActionsToActionGroup } from './connector';
|
|
17
|
-
export type { ConnectorResultToUILayoutOptions, ConnectorActionsToActionGroupOptions, } from './connector';
|
|
18
|
-
export { macroRunToScratchpadState, macroInterrogationToChatPromptConfig } from './macro-run';
|
|
16
|
+
export { connectorResultToUILayout, connectorActionsToActionGroup, DEFAULT_CONNECTOR_MESSAGES, } from './connector';
|
|
17
|
+
export type { ConnectorResultToUILayoutOptions, ConnectorActionsToActionGroupOptions, ConnectorAdapterMessages, } from './connector';
|
|
18
|
+
export { macroRunToScratchpadState, macroInterrogationToChatPromptConfig, DEFAULT_MACRO_RUN_MESSAGES, } from './macro-run';
|
|
19
|
+
export type { MacroRunAdapterMessages, MacroRunAdapterOptions } from './macro-run';
|
|
19
20
|
export { createComparisonLayout, createGeographyLayout, createEvidenceLayout, } from './presentation';
|
|
20
21
|
export type { ComparisonLayoutInput, GeographyLayoutInput, EvidenceLayoutInput, PresentationComponent, ChartComponent, TableComponent, MapComponent, MetricComponent, TextComponent, LinkComponent, } from './presentation';
|
|
21
22
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,yBAAyB,EACzB,6BAA6B,EAC7B,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,gCAAgC,EAChC,oCAAoC,EACpC,wBAAwB,GACzB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,yBAAyB,EACzB,oCAAoC,EACpC,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAEnF,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,YAAY,EACZ,eAAe,EACf,aAAa,EACb,aAAa,GACd,MAAM,gBAAgB,CAAC"}
|
|
@@ -90,7 +90,16 @@ function resultSectionType(componentType) {
|
|
|
90
90
|
return "data";
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
|
|
93
|
+
const DEFAULT_MACRO_RUN_MESSAGES = {
|
|
94
|
+
agentSectionTitle: "Agent",
|
|
95
|
+
progressSectionTitle: "Progress",
|
|
96
|
+
resultSectionTitle: "Result",
|
|
97
|
+
runAborted: "Macro run aborted.",
|
|
98
|
+
runFailed: "Macro run failed.",
|
|
99
|
+
confirmDefault: "Please confirm to continue."
|
|
100
|
+
};
|
|
101
|
+
const withMessages = (options = {}) => ({ ...DEFAULT_MACRO_RUN_MESSAGES, ...options.messages });
|
|
102
|
+
function buildError(run, messages) {
|
|
94
103
|
if (run.status !== "failed" && run.status !== "aborted") return void 0;
|
|
95
104
|
const aborted = run.status === "aborted";
|
|
96
105
|
if (run.error) {
|
|
@@ -103,15 +112,16 @@ function buildError(run) {
|
|
|
103
112
|
return err;
|
|
104
113
|
}
|
|
105
114
|
return {
|
|
106
|
-
message: aborted ?
|
|
115
|
+
message: aborted ? messages.runAborted : messages.runFailed,
|
|
107
116
|
retryable: false
|
|
108
117
|
};
|
|
109
118
|
}
|
|
110
|
-
function macroRunToScratchpadState(run) {
|
|
119
|
+
function macroRunToScratchpadState(run, options = {}) {
|
|
120
|
+
const messages = withMessages(options);
|
|
111
121
|
const sections = [];
|
|
112
122
|
sections.push({
|
|
113
123
|
id: "macro-agent",
|
|
114
|
-
title:
|
|
124
|
+
title: messages.agentSectionTitle,
|
|
115
125
|
type: "agent_card",
|
|
116
126
|
content: buildAgentCard(run),
|
|
117
127
|
editable: false,
|
|
@@ -122,14 +132,14 @@ function macroRunToScratchpadState(run) {
|
|
|
122
132
|
sections.push(
|
|
123
133
|
hasParallel ? {
|
|
124
134
|
id: "macro-split-stepper",
|
|
125
|
-
title:
|
|
135
|
+
title: messages.progressSectionTitle,
|
|
126
136
|
type: "split_stepper",
|
|
127
137
|
content: buildSplitStepperContent(run.steps),
|
|
128
138
|
editable: false,
|
|
129
139
|
source: "agent"
|
|
130
140
|
} : {
|
|
131
141
|
id: "macro-stepper",
|
|
132
|
-
title:
|
|
142
|
+
title: messages.progressSectionTitle,
|
|
133
143
|
type: "stepper",
|
|
134
144
|
content: buildStepperContent(run.steps),
|
|
135
145
|
editable: false,
|
|
@@ -142,7 +152,7 @@ function macroRunToScratchpadState(run) {
|
|
|
142
152
|
id: "macro-prompt",
|
|
143
153
|
title: run.pendingInterrogation.title,
|
|
144
154
|
type: "prompt",
|
|
145
|
-
content: macroInterrogationToChatPromptConfig(run.pendingInterrogation),
|
|
155
|
+
content: macroInterrogationToChatPromptConfig(run.pendingInterrogation, options),
|
|
146
156
|
editable: false,
|
|
147
157
|
source: "agent"
|
|
148
158
|
});
|
|
@@ -151,7 +161,7 @@ function macroRunToScratchpadState(run) {
|
|
|
151
161
|
results.forEach((component, index) => {
|
|
152
162
|
sections.push({
|
|
153
163
|
id: `macro-result-${String((component == null ? void 0 : component.id) ?? index)}`,
|
|
154
|
-
title:
|
|
164
|
+
title: messages.resultSectionTitle,
|
|
155
165
|
type: resultSectionType(component == null ? void 0 : component.type),
|
|
156
166
|
content: component,
|
|
157
167
|
editable: false,
|
|
@@ -166,7 +176,7 @@ function macroRunToScratchpadState(run) {
|
|
|
166
176
|
agentMessages: [],
|
|
167
177
|
status: RUN_STATUS_TO_SCRATCHPAD[run.status]
|
|
168
178
|
};
|
|
169
|
-
const error = buildError(run);
|
|
179
|
+
const error = buildError(run, messages);
|
|
170
180
|
if (error) state.error = error;
|
|
171
181
|
return state;
|
|
172
182
|
}
|
|
@@ -175,11 +185,12 @@ function isElicitationSchema(value) {
|
|
|
175
185
|
const v = value;
|
|
176
186
|
return v.type === "object" && typeof v.properties === "object" && v.properties !== null;
|
|
177
187
|
}
|
|
178
|
-
function macroInterrogationToChatPromptConfig(q) {
|
|
188
|
+
function macroInterrogationToChatPromptConfig(q, options = {}) {
|
|
179
189
|
var _a, _b, _c;
|
|
190
|
+
const messages = withMessages(options);
|
|
180
191
|
switch (q.kind) {
|
|
181
192
|
case "choice": {
|
|
182
|
-
const
|
|
193
|
+
const options2 = (q.options ?? []).map((o) => {
|
|
183
194
|
const opt = { value: o.value, label: o.label };
|
|
184
195
|
if (o.icon) opt.icon = o.icon;
|
|
185
196
|
if (o.description) opt.description = o.description;
|
|
@@ -189,7 +200,7 @@ function macroInterrogationToChatPromptConfig(q) {
|
|
|
189
200
|
return {
|
|
190
201
|
type: "choice",
|
|
191
202
|
title: q.title,
|
|
192
|
-
config: { options, layout: "vertical" }
|
|
203
|
+
config: { options: options2, layout: "vertical" }
|
|
193
204
|
};
|
|
194
205
|
}
|
|
195
206
|
case "confirm": {
|
|
@@ -216,11 +227,12 @@ function macroInterrogationToChatPromptConfig(q) {
|
|
|
216
227
|
return {
|
|
217
228
|
type: "confirm",
|
|
218
229
|
title: q.title,
|
|
219
|
-
config: { message: q.message ??
|
|
230
|
+
config: { message: q.message ?? messages.confirmDefault }
|
|
220
231
|
};
|
|
221
232
|
}
|
|
222
233
|
}
|
|
223
234
|
}
|
|
235
|
+
exports.DEFAULT_MACRO_RUN_MESSAGES = DEFAULT_MACRO_RUN_MESSAGES;
|
|
224
236
|
exports.macroInterrogationToChatPromptConfig = macroInterrogationToChatPromptConfig;
|
|
225
237
|
exports.macroRunToScratchpadState = macroRunToScratchpadState;
|
|
226
238
|
//# sourceMappingURL=macro-run.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macro-run.cjs","sources":["../../src/adapters/macro-run.ts"],"sourcesContent":["/**\n * MacroRun adapters — `MacroRunV1` / `MacroInterrogationV1` → MCP-UI render\n * primitives.\n *\n * @since v6.7.0 (MacroRun Phase 2 — contract consolidated in deposium_MCPs\n * `docs/2026/briefs/2026-05-22-macro-run-runtime-contract-consolidation.md`)\n *\n * ## Opt-in, pure\n *\n * Published under the dedicated subpath `@seed-ship/mcp-ui-solid/adapters` —\n * never imported by the core renderer path. Every function here is a **pure\n * function**: same input → same output, no `fetch`, no SSE listener, no\n * persistence, no global state, no clock, no randomness.\n *\n * ## Scope boundary\n *\n * These adapters only translate the agnostic `MacroRunV1` contract (defined\n * in `@seed-ship/mcp-ui-spec`) into existing MCP-UI primitives — a\n * `ScratchpadState` and a `ChatPromptConfig`. They do NOT:\n *\n * - emit or consume any SSE event (a `macro_run_snapshot` producer is a\n * separate, later goal on the producing runtime repo);\n * - perform any fetch, persistence or resume;\n * - know anything about a specific runtime, host, corpus or domain;\n * - touch the `action:'submit'` executors, nor mix MacroRun with the\n * existing tool-call action path.\n *\n * The host owns all of the above — it feeds a `MacroRunV1` snapshot in and\n * decides where to render the result.\n */\n\nimport type { MacroRunV1, MacroStepV1, MacroInterrogationV1 } from '@seed-ship/mcp-ui-spec';\nimport type {\n ScratchpadState,\n ScratchpadSection,\n ChatPromptConfig,\n ChoiceOption,\n ConfirmPromptConfig,\n AgentCardContent,\n SplitStepperContent,\n ElicitationRequestedSchema,\n FormPromptConfig,\n} from '../types/chat-bus';\nimport { elicitationToPromptConfig } from '../services/chat-bus';\n\n// ─── Status mappings ─────────────────────────────────────────\n\n/**\n * Run status → top-level `ScratchpadState` status. `aborted` and `failed`\n * both surface as `error` (an aborted run is additionally non-retryable —\n * see `buildError`).\n */\nconst RUN_STATUS_TO_SCRATCHPAD: Record<MacroRunV1['status'], ScratchpadState['status']> = {\n pending: 'loading',\n running: 'processing',\n awaiting_input: 'waiting_human',\n completed: 'complete',\n failed: 'error',\n aborted: 'error',\n};\n\n/** Run status → `AgentCardContent` status, used when the run carries no agent. */\nfunction runStatusToAgentStatus(status: MacroRunV1['status']): AgentCardContent['status'] {\n switch (status) {\n case 'pending':\n return 'idle';\n case 'running':\n return 'running';\n case 'awaiting_input':\n return 'waiting';\n case 'completed':\n return 'done';\n case 'failed':\n case 'aborted':\n return 'error';\n }\n}\n\n/**\n * Step status → stepper status. The MCP-UI stepper primitive renders\n * `failed` as `error`; every other value passes through unchanged.\n */\nfunction stepToStepperStatus(\n status: MacroStepV1['status']\n): 'pending' | 'active' | 'done' | 'skipped' | 'error' {\n return status === 'failed' ? 'error' : status;\n}\n\n// ─── Section builders ────────────────────────────────────────\n\ninterface StepperSectionContent {\n steps: Array<{\n id: string;\n label: string;\n status: 'pending' | 'active' | 'done' | 'skipped' | 'error';\n summary?: string;\n duration_ms?: number;\n }>;\n orientation: 'horizontal' | 'vertical';\n}\n\nfunction buildAgentCard(run: MacroRunV1): AgentCardContent {\n const agent = run.agent;\n const card: AgentCardContent = {\n agentId: agent?.id ?? run.macroId,\n name: agent?.name ?? run.macroName ?? run.macroId,\n status: agent?.status ?? runStatusToAgentStatus(run.status),\n };\n if (agent?.avatar) card.avatar = agent.avatar;\n if (agent?.capabilities) card.capabilities = agent.capabilities;\n if (agent?.currentStep) card.currentStep = agent.currentStep;\n return card;\n}\n\nfunction buildStepperContent(steps: MacroStepV1[]): StepperSectionContent {\n return {\n orientation: 'horizontal',\n steps: steps.map((step) => {\n const out: StepperSectionContent['steps'][number] = {\n id: step.id,\n label: step.label,\n status: stepToStepperStatus(step.status),\n };\n if (step.summary) out.summary = step.summary;\n if (typeof step.durationMs === 'number') out.duration_ms = step.durationMs;\n return out;\n }),\n };\n}\n\n/** Collapse a set of sub-step statuses into a single parallel-lane status. */\nfunction laneStatus(subSteps: MacroStepV1[]): 'done' | 'active' | 'pending' | 'error' {\n if (subSteps.some((s) => s.status === 'failed')) return 'error';\n if (subSteps.some((s) => s.status === 'active')) return 'active';\n if (subSteps.length > 0 && subSteps.every((s) => s.status === 'done' || s.status === 'skipped'))\n return 'done';\n return 'pending';\n}\n\n/**\n * Build a `split_stepper` content from steps that carry `parallel` branches.\n * Each top-level step becomes a lane: a step with `parallel` sub-steps shows\n * those sub-steps; a step without falls back to a single-step lane.\n */\nfunction buildSplitStepperContent(steps: MacroStepV1[]): SplitStepperContent {\n return {\n agents: steps.map((step) => {\n const subSteps = step.parallel && step.parallel.length > 0 ? step.parallel : [step];\n return {\n id: step.id,\n name: step.label,\n status: laneStatus(subSteps),\n steps: subSteps.map((sub) => ({\n id: sub.id,\n label: sub.label,\n status: stepToStepperStatus(sub.status),\n })),\n };\n }),\n };\n}\n\n/** Component `type` → the closest `ScratchpadSection` type for a result. */\nfunction resultSectionType(componentType: unknown): ScratchpadSection['type'] {\n switch (componentType) {\n case 'chart':\n return 'chart';\n case 'map':\n return 'map';\n case 'table':\n return 'data_preview';\n default:\n return 'data';\n }\n}\n\nfunction buildError(run: MacroRunV1): ScratchpadState['error'] | undefined {\n if (run.status !== 'failed' && run.status !== 'aborted') return undefined;\n const aborted = run.status === 'aborted';\n if (run.error) {\n const err: NonNullable<ScratchpadState['error']> = {\n message: run.error.message,\n // An aborted run is never retryable, regardless of the producer flag.\n retryable: aborted ? false : (run.error.retryable ?? false),\n };\n if (run.error.code) err.code = run.error.code;\n return err;\n }\n return {\n message: aborted ? 'Macro run aborted.' : 'Macro run failed.',\n retryable: false,\n };\n}\n\n// ─── macroRunToScratchpadState ───────────────────────────────\n\n/**\n * Convert a `MacroRunV1` snapshot into a `ScratchpadState`.\n *\n * Sections produced, in order:\n * 1. `agent_card` — always (derived from `run.agent`, or from the macro\n * identity when the run carries no agent, e.g. a non-interactive macro).\n * 2. `stepper` — when the run has steps and none carry `parallel` branches.\n * `split_stepper` instead when any step carries `parallel` (future model).\n * 3. `prompt` — when `run.pendingInterrogation` is set; its content is the\n * `ChatPromptConfig` produced by {@link macroInterrogationToChatPromptConfig}.\n * 4. one section per `run.results` entry (`chart` / `map` / `data_preview` /\n * `data`, by component type). Optional — the adapter works without results.\n *\n * Pure: no fetch, no SSE, no persistence. The host owns all wiring.\n */\nexport function macroRunToScratchpadState(run: MacroRunV1): ScratchpadState {\n const sections: ScratchpadSection[] = [];\n\n // 1. Agent card — always present.\n sections.push({\n id: 'macro-agent',\n title: 'Agent',\n type: 'agent_card',\n content: buildAgentCard(run),\n editable: false,\n source: 'agent',\n });\n\n // 2. Stepper / split_stepper — when there are steps.\n if (run.steps.length > 0) {\n const hasParallel = run.steps.some((s) => Array.isArray(s.parallel) && s.parallel.length > 0);\n sections.push(\n hasParallel\n ? {\n id: 'macro-split-stepper',\n title: 'Progress',\n type: 'split_stepper',\n content: buildSplitStepperContent(run.steps),\n editable: false,\n source: 'agent',\n }\n : {\n id: 'macro-stepper',\n title: 'Progress',\n type: 'stepper',\n content: buildStepperContent(run.steps),\n editable: false,\n source: 'agent',\n }\n );\n }\n\n // 3. Pending interrogation → a `prompt` section.\n if (run.pendingInterrogation) {\n sections.push({\n id: 'macro-prompt',\n title: run.pendingInterrogation.title,\n type: 'prompt',\n content: macroInterrogationToChatPromptConfig(run.pendingInterrogation),\n editable: false,\n source: 'agent',\n });\n }\n\n // 4. Result components → one section each (results are optional). A result\n // is a `UIComponent`-shaped object — passthrough, read loosely (the spec\n // validates the run envelope, the renderer validates each component).\n const results = run.results ?? [];\n results.forEach((component, index) => {\n sections.push({\n id: `macro-result-${String(component?.id ?? index)}`,\n title: 'Result',\n type: resultSectionType(component?.type),\n content: component,\n editable: false,\n source: 'agent',\n });\n });\n\n const state: ScratchpadState = {\n id: run.runId,\n title: run.title ?? run.macroName ?? run.macroId,\n sections,\n filters: {},\n agentMessages: [],\n status: RUN_STATUS_TO_SCRATCHPAD[run.status],\n };\n\n const error = buildError(run);\n if (error) state.error = error;\n\n return state;\n}\n\n// ─── macroInterrogationToChatPromptConfig ────────────────────\n\nfunction isElicitationSchema(value: unknown): value is ElicitationRequestedSchema {\n if (typeof value !== 'object' || value === null) return false;\n const v = value as { type?: unknown; properties?: unknown };\n return v.type === 'object' && typeof v.properties === 'object' && v.properties !== null;\n}\n\n/**\n * Convert a `MacroInterrogationV1` into a `ChatPromptConfig`.\n *\n * - `choice` → `{ type: 'choice' }` (vertical layout).\n * - `confirm` → `{ type: 'confirm' }`.\n * - `form` → `{ type: 'form' }` (the opaque `fields` are passed through).\n * - `elicitation` → routed through the existing `elicitationToPromptConfig()`\n * helper. If the interrogation carries no usable elicitation JSON Schema,\n * it degrades to a `confirm` prompt rather than throwing.\n *\n * Always returns a `ChatPromptConfig` — never an `ElicitationEvent` — so the\n * host has a single entry point. Usable standalone or via\n * {@link macroRunToScratchpadState} (which calls it for an embedded\n * `pendingInterrogation`).\n */\nexport function macroInterrogationToChatPromptConfig(q: MacroInterrogationV1): ChatPromptConfig {\n switch (q.kind) {\n case 'choice': {\n const options: ChoiceOption[] = (q.options ?? []).map((o) => {\n const opt: ChoiceOption = { value: o.value, label: o.label };\n if (o.icon) opt.icon = o.icon;\n if (o.description) opt.description = o.description;\n if (o.metadata) opt.metadata = o.metadata;\n return opt;\n });\n return {\n type: 'choice',\n title: q.title,\n config: { options, layout: 'vertical' },\n };\n }\n\n case 'confirm': {\n const config: ConfirmPromptConfig = {};\n if (q.message) config.message = q.message;\n if (q.confirm?.confirmLabel) config.confirmLabel = q.confirm.confirmLabel;\n if (q.confirm?.cancelLabel) config.cancelLabel = q.confirm.cancelLabel;\n if (q.confirm?.variant) config.variant = q.confirm.variant;\n return { type: 'confirm', title: q.title, config };\n }\n\n case 'form':\n return {\n type: 'form',\n title: q.title,\n config: { fields: (q.fields ?? []) as FormPromptConfig['fields'] },\n };\n\n case 'elicitation': {\n if (isElicitationSchema(q.elicitationSchema)) {\n return elicitationToPromptConfig({\n message: q.message ?? q.title,\n requestedSchema: q.elicitationSchema,\n });\n }\n // No usable schema — degrade gracefully instead of crashing.\n return {\n type: 'confirm',\n title: q.title,\n config: { message: q.message ?? 'Please confirm to continue.' },\n };\n }\n }\n}\n"],"names":["elicitationToPromptConfig"],"mappings":";;;AAoDA,MAAM,2BAAoF;AAAA,EACxF,SAAS;AAAA,EACT,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,SAAS;AACX;AAGA,SAAS,uBAAuB,QAA0D;AACxF,UAAQ,QAAA;AAAA,IACN,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,EAAA;AAEb;AAMA,SAAS,oBACP,QACqD;AACrD,SAAO,WAAW,WAAW,UAAU;AACzC;AAeA,SAAS,eAAe,KAAmC;AACzD,QAAM,QAAQ,IAAI;AAClB,QAAM,OAAyB;AAAA,IAC7B,UAAS,+BAAO,OAAM,IAAI;AAAA,IAC1B,OAAM,+BAAO,SAAQ,IAAI,aAAa,IAAI;AAAA,IAC1C,SAAQ,+BAAO,WAAU,uBAAuB,IAAI,MAAM;AAAA,EAAA;AAE5D,MAAI,+BAAO,OAAQ,MAAK,SAAS,MAAM;AACvC,MAAI,+BAAO,aAAc,MAAK,eAAe,MAAM;AACnD,MAAI,+BAAO,YAAa,MAAK,cAAc,MAAM;AACjD,SAAO;AACT;AAEA,SAAS,oBAAoB,OAA6C;AACxE,SAAO;AAAA,IACL,aAAa;AAAA,IACb,OAAO,MAAM,IAAI,CAAC,SAAS;AACzB,YAAM,MAA8C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,SAA8B,CAAA;AACpC,UAAI,EAAE,QAAS,QAAO,UAAU,EAAE;AAClC,WAAI,OAAE,YAAF,mBAAW,aAAc,QAAO,eAAe,EAAE,QAAQ;AAC7D,WAAI,OAAE,YAAF,mBAAW,YAAa,QAAO,cAAc,EAAE,QAAQ;AAC3D,WAAI,OAAE,YAAF,mBAAW,QAAS,QAAO,UAAU,EAAE,QAAQ;AACnD,aAAO,EAAE,MAAM,WAAW,OAAO,EAAE,OAAO,OAAA;AAAA,IAC5C;AAAA,IAEA,KAAK;AACH,aAAO;AAAA,QACL,MAAM;AAAA,QACN,OAAO,EAAE;AAAA,QACT,QAAQ,EAAE,QAAS,EAAE,UAAU,CAAA,EAAC;AAAA,MAAiC;AAAA,IAGrE,KAAK,eAAe;AAClB,UAAI,oBAAoB,EAAE,iBAAiB,GAAG;AAC5C,eAAOA,kCAA0B;AAAA,UAC/B,SAAS,EAAE,WAAW,EAAE;AAAA,UACxB,iBAAiB,EAAE;AAAA,QAAA,CACpB;AAAA,MACH;AAEA,aAAO;AAAA,QACL,MAAM;AAAA,QACN,OAAO,EAAE;AAAA,QACT,QAAQ,EAAE,SAAS,EAAE,WAAW,8BAAA;AAAA,MAA8B;AAAA,IAElE;AAAA,EAAA;AAEJ;;;"}
|
|
1
|
+
{"version":3,"file":"macro-run.cjs","sources":["../../src/adapters/macro-run.ts"],"sourcesContent":["/**\n * MacroRun adapters — `MacroRunV1` / `MacroInterrogationV1` → MCP-UI render\n * primitives.\n *\n * @since v6.7.0 (MacroRun Phase 2 — contract consolidated in deposium_MCPs\n * `docs/2026/briefs/2026-05-22-macro-run-runtime-contract-consolidation.md`)\n *\n * ## Opt-in, pure\n *\n * Published under the dedicated subpath `@seed-ship/mcp-ui-solid/adapters` —\n * never imported by the core renderer path. Every function here is a **pure\n * function**: same input → same output, no `fetch`, no SSE listener, no\n * persistence, no global state, no clock, no randomness.\n *\n * ## Scope boundary\n *\n * These adapters only translate the agnostic `MacroRunV1` contract (defined\n * in `@seed-ship/mcp-ui-spec`) into existing MCP-UI primitives — a\n * `ScratchpadState` and a `ChatPromptConfig`. They do NOT:\n *\n * - emit or consume any SSE event (a `macro_run_snapshot` producer is a\n * separate, later goal on the producing runtime repo);\n * - perform any fetch, persistence or resume;\n * - know anything about a specific runtime, host, corpus or domain;\n * - touch the `action:'submit'` executors, nor mix MacroRun with the\n * existing tool-call action path.\n *\n * The host owns all of the above — it feeds a `MacroRunV1` snapshot in and\n * decides where to render the result.\n */\n\nimport type { MacroRunV1, MacroStepV1, MacroInterrogationV1 } from '@seed-ship/mcp-ui-spec';\nimport type {\n ScratchpadState,\n ScratchpadSection,\n ChatPromptConfig,\n ChoiceOption,\n ConfirmPromptConfig,\n AgentCardContent,\n SplitStepperContent,\n ElicitationRequestedSchema,\n FormPromptConfig,\n} from '../types/chat-bus';\nimport { elicitationToPromptConfig } from '../services/chat-bus';\n\n// ─── Status mappings ─────────────────────────────────────────\n\n/**\n * Run status → top-level `ScratchpadState` status. `aborted` and `failed`\n * both surface as `error` (an aborted run is additionally non-retryable —\n * see `buildError`).\n */\nconst RUN_STATUS_TO_SCRATCHPAD: Record<MacroRunV1['status'], ScratchpadState['status']> = {\n pending: 'loading',\n running: 'processing',\n awaiting_input: 'waiting_human',\n completed: 'complete',\n failed: 'error',\n aborted: 'error',\n};\n\n/** Run status → `AgentCardContent` status, used when the run carries no agent. */\nfunction runStatusToAgentStatus(status: MacroRunV1['status']): AgentCardContent['status'] {\n switch (status) {\n case 'pending':\n return 'idle';\n case 'running':\n return 'running';\n case 'awaiting_input':\n return 'waiting';\n case 'completed':\n return 'done';\n case 'failed':\n case 'aborted':\n return 'error';\n }\n}\n\n/**\n * Step status → stepper status. The MCP-UI stepper primitive renders\n * `failed` as `error`; every other value passes through unchanged.\n */\nfunction stepToStepperStatus(\n status: MacroStepV1['status']\n): 'pending' | 'active' | 'done' | 'skipped' | 'error' {\n return status === 'failed' ? 'error' : status;\n}\n\n// ─── Section builders ────────────────────────────────────────\n\ninterface StepperSectionContent {\n steps: Array<{\n id: string;\n label: string;\n status: 'pending' | 'active' | 'done' | 'skipped' | 'error';\n summary?: string;\n duration_ms?: number;\n }>;\n orientation: 'horizontal' | 'vertical';\n}\n\nfunction buildAgentCard(run: MacroRunV1): AgentCardContent {\n const agent = run.agent;\n const card: AgentCardContent = {\n agentId: agent?.id ?? run.macroId,\n name: agent?.name ?? run.macroName ?? run.macroId,\n status: agent?.status ?? runStatusToAgentStatus(run.status),\n };\n if (agent?.avatar) card.avatar = agent.avatar;\n if (agent?.capabilities) card.capabilities = agent.capabilities;\n if (agent?.currentStep) card.currentStep = agent.currentStep;\n return card;\n}\n\nfunction buildStepperContent(steps: MacroStepV1[]): StepperSectionContent {\n return {\n orientation: 'horizontal',\n steps: steps.map((step) => {\n const out: StepperSectionContent['steps'][number] = {\n id: step.id,\n label: step.label,\n status: stepToStepperStatus(step.status),\n };\n if (step.summary) out.summary = step.summary;\n if (typeof step.durationMs === 'number') out.duration_ms = step.durationMs;\n return out;\n }),\n };\n}\n\n/** Collapse a set of sub-step statuses into a single parallel-lane status. */\nfunction laneStatus(subSteps: MacroStepV1[]): 'done' | 'active' | 'pending' | 'error' {\n if (subSteps.some((s) => s.status === 'failed')) return 'error';\n if (subSteps.some((s) => s.status === 'active')) return 'active';\n if (subSteps.length > 0 && subSteps.every((s) => s.status === 'done' || s.status === 'skipped'))\n return 'done';\n return 'pending';\n}\n\n/**\n * Build a `split_stepper` content from steps that carry `parallel` branches.\n * Each top-level step becomes a lane: a step with `parallel` sub-steps shows\n * those sub-steps; a step without falls back to a single-step lane.\n */\nfunction buildSplitStepperContent(steps: MacroStepV1[]): SplitStepperContent {\n return {\n agents: steps.map((step) => {\n const subSteps = step.parallel && step.parallel.length > 0 ? step.parallel : [step];\n return {\n id: step.id,\n name: step.label,\n status: laneStatus(subSteps),\n steps: subSteps.map((sub) => ({\n id: sub.id,\n label: sub.label,\n status: stepToStepperStatus(sub.status),\n })),\n };\n }),\n };\n}\n\n/** Component `type` → the closest `ScratchpadSection` type for a result. */\nfunction resultSectionType(componentType: unknown): ScratchpadSection['type'] {\n switch (componentType) {\n case 'chart':\n return 'chart';\n case 'map':\n return 'map';\n case 'table':\n return 'data_preview';\n default:\n return 'data';\n }\n}\n\n/**\n * The English wording this adapter produces on its own — section titles and\n * the fallbacks used when the run (or the interrogation) carries none.\n *\n * The adapter is runtime-free by contract: no `solid-js`, no\n * `MCPUIStringsContext`. Hosts that render in another language pass a\n * partial override through `MacroRunAdapterOptions.messages`, exactly like\n * `ConnectorResultToUILayoutOptions.messages`.\n *\n * @since v6.20.0\n */\nexport interface MacroRunAdapterMessages {\n /** Title of the always-present `agent_card` section. */\n agentSectionTitle: string;\n /** Title of the `stepper` / `split_stepper` section. */\n progressSectionTitle: string;\n /** Title of each result section. */\n resultSectionTitle: string;\n /** Error message of an aborted run that carries no `error`. */\n runAborted: string;\n /** Error message of a failed run that carries no `error`. */\n runFailed: string;\n /** Prompt body of an elicitation with no usable schema and no message. */\n confirmDefault: string;\n}\n\n/** English defaults for {@link MacroRunAdapterMessages}. */\nexport const DEFAULT_MACRO_RUN_MESSAGES: MacroRunAdapterMessages = {\n agentSectionTitle: 'Agent',\n progressSectionTitle: 'Progress',\n resultSectionTitle: 'Result',\n runAborted: 'Macro run aborted.',\n runFailed: 'Macro run failed.',\n confirmDefault: 'Please confirm to continue.',\n};\n\n/** Options shared by the MacroRun adapters. @since v6.20.0 */\nexport interface MacroRunAdapterOptions {\n /**\n * Partial override of the adapter's own wording, merged over\n * {@link DEFAULT_MACRO_RUN_MESSAGES}.\n */\n messages?: Partial<MacroRunAdapterMessages>;\n}\n\nconst withMessages = (\n options: MacroRunAdapterOptions = {}\n): MacroRunAdapterMessages => ({ ...DEFAULT_MACRO_RUN_MESSAGES, ...options.messages });\n\nfunction buildError(\n run: MacroRunV1,\n messages: MacroRunAdapterMessages\n): ScratchpadState['error'] | undefined {\n if (run.status !== 'failed' && run.status !== 'aborted') return undefined;\n const aborted = run.status === 'aborted';\n if (run.error) {\n const err: NonNullable<ScratchpadState['error']> = {\n message: run.error.message,\n // An aborted run is never retryable, regardless of the producer flag.\n retryable: aborted ? false : (run.error.retryable ?? false),\n };\n if (run.error.code) err.code = run.error.code;\n return err;\n }\n return {\n message: aborted ? messages.runAborted : messages.runFailed,\n retryable: false,\n };\n}\n\n// ─── macroRunToScratchpadState ───────────────────────────────\n\n/**\n * Convert a `MacroRunV1` snapshot into a `ScratchpadState`.\n *\n * Sections produced, in order:\n * 1. `agent_card` — always (derived from `run.agent`, or from the macro\n * identity when the run carries no agent, e.g. a non-interactive macro).\n * 2. `stepper` — when the run has steps and none carry `parallel` branches.\n * `split_stepper` instead when any step carries `parallel` (future model).\n * 3. `prompt` — when `run.pendingInterrogation` is set; its content is the\n * `ChatPromptConfig` produced by {@link macroInterrogationToChatPromptConfig}.\n * 4. one section per `run.results` entry (`chart` / `map` / `data_preview` /\n * `data`, by component type). Optional — the adapter works without results.\n *\n * Pure: no fetch, no SSE, no persistence. The host owns all wiring.\n */\nexport function macroRunToScratchpadState(\n run: MacroRunV1,\n options: MacroRunAdapterOptions = {}\n): ScratchpadState {\n const messages = withMessages(options);\n const sections: ScratchpadSection[] = [];\n\n // 1. Agent card — always present.\n sections.push({\n id: 'macro-agent',\n title: messages.agentSectionTitle,\n type: 'agent_card',\n content: buildAgentCard(run),\n editable: false,\n source: 'agent',\n });\n\n // 2. Stepper / split_stepper — when there are steps.\n if (run.steps.length > 0) {\n const hasParallel = run.steps.some((s) => Array.isArray(s.parallel) && s.parallel.length > 0);\n sections.push(\n hasParallel\n ? {\n id: 'macro-split-stepper',\n title: messages.progressSectionTitle,\n type: 'split_stepper',\n content: buildSplitStepperContent(run.steps),\n editable: false,\n source: 'agent',\n }\n : {\n id: 'macro-stepper',\n title: messages.progressSectionTitle,\n type: 'stepper',\n content: buildStepperContent(run.steps),\n editable: false,\n source: 'agent',\n }\n );\n }\n\n // 3. Pending interrogation → a `prompt` section.\n if (run.pendingInterrogation) {\n sections.push({\n id: 'macro-prompt',\n title: run.pendingInterrogation.title,\n type: 'prompt',\n content: macroInterrogationToChatPromptConfig(run.pendingInterrogation, options),\n editable: false,\n source: 'agent',\n });\n }\n\n // 4. Result components → one section each (results are optional). A result\n // is a `UIComponent`-shaped object — passthrough, read loosely (the spec\n // validates the run envelope, the renderer validates each component).\n const results = run.results ?? [];\n results.forEach((component, index) => {\n sections.push({\n id: `macro-result-${String(component?.id ?? index)}`,\n title: messages.resultSectionTitle,\n type: resultSectionType(component?.type),\n content: component,\n editable: false,\n source: 'agent',\n });\n });\n\n const state: ScratchpadState = {\n id: run.runId,\n title: run.title ?? run.macroName ?? run.macroId,\n sections,\n filters: {},\n agentMessages: [],\n status: RUN_STATUS_TO_SCRATCHPAD[run.status],\n };\n\n const error = buildError(run, messages);\n if (error) state.error = error;\n\n return state;\n}\n\n// ─── macroInterrogationToChatPromptConfig ────────────────────\n\nfunction isElicitationSchema(value: unknown): value is ElicitationRequestedSchema {\n if (typeof value !== 'object' || value === null) return false;\n const v = value as { type?: unknown; properties?: unknown };\n return v.type === 'object' && typeof v.properties === 'object' && v.properties !== null;\n}\n\n/**\n * Convert a `MacroInterrogationV1` into a `ChatPromptConfig`.\n *\n * - `choice` → `{ type: 'choice' }` (vertical layout).\n * - `confirm` → `{ type: 'confirm' }`.\n * - `form` → `{ type: 'form' }` (the opaque `fields` are passed through).\n * - `elicitation` → routed through the existing `elicitationToPromptConfig()`\n * helper. If the interrogation carries no usable elicitation JSON Schema,\n * it degrades to a `confirm` prompt rather than throwing.\n *\n * Always returns a `ChatPromptConfig` — never an `ElicitationEvent` — so the\n * host has a single entry point. Usable standalone or via\n * {@link macroRunToScratchpadState} (which calls it for an embedded\n * `pendingInterrogation`).\n */\nexport function macroInterrogationToChatPromptConfig(\n q: MacroInterrogationV1,\n options: MacroRunAdapterOptions = {}\n): ChatPromptConfig {\n const messages = withMessages(options);\n switch (q.kind) {\n case 'choice': {\n const options: ChoiceOption[] = (q.options ?? []).map((o) => {\n const opt: ChoiceOption = { value: o.value, label: o.label };\n if (o.icon) opt.icon = o.icon;\n if (o.description) opt.description = o.description;\n if (o.metadata) opt.metadata = o.metadata;\n return opt;\n });\n return {\n type: 'choice',\n title: q.title,\n config: { options, layout: 'vertical' },\n };\n }\n\n case 'confirm': {\n const config: ConfirmPromptConfig = {};\n if (q.message) config.message = q.message;\n if (q.confirm?.confirmLabel) config.confirmLabel = q.confirm.confirmLabel;\n if (q.confirm?.cancelLabel) config.cancelLabel = q.confirm.cancelLabel;\n if (q.confirm?.variant) config.variant = q.confirm.variant;\n return { type: 'confirm', title: q.title, config };\n }\n\n case 'form':\n return {\n type: 'form',\n title: q.title,\n config: { fields: (q.fields ?? []) as FormPromptConfig['fields'] },\n };\n\n case 'elicitation': {\n if (isElicitationSchema(q.elicitationSchema)) {\n return elicitationToPromptConfig({\n message: q.message ?? q.title,\n requestedSchema: q.elicitationSchema,\n });\n }\n // No usable schema — degrade gracefully instead of crashing.\n return {\n type: 'confirm',\n title: q.title,\n config: { message: q.message ?? messages.confirmDefault },\n };\n }\n }\n}\n"],"names":["options","elicitationToPromptConfig"],"mappings":";;;AAoDA,MAAM,2BAAoF;AAAA,EACxF,SAAS;AAAA,EACT,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,SAAS;AACX;AAGA,SAAS,uBAAuB,QAA0D;AACxF,UAAQ,QAAA;AAAA,IACN,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,EAAA;AAEb;AAMA,SAAS,oBACP,QACqD;AACrD,SAAO,WAAW,WAAW,UAAU;AACzC;AAeA,SAAS,eAAe,KAAmC;AACzD,QAAM,QAAQ,IAAI;AAClB,QAAM,OAAyB;AAAA,IAC7B,UAAS,+BAAO,OAAM,IA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,EAAE,iBAAiB,GAAG;AAC5C,eAAOC,kCAA0B;AAAA,UAC/B,SAAS,EAAE,WAAW,EAAE;AAAA,UACxB,iBAAiB,EAAE;AAAA,QAAA,CACpB;AAAA,MACH;AAEA,aAAO;AAAA,QACL,MAAM;AAAA,QACN,OAAO,EAAE;AAAA,QACT,QAAQ,EAAE,SAAS,EAAE,WAAW,SAAS,eAAA;AAAA,MAAe;AAAA,IAE5D;AAAA,EAAA;AAEJ;;;;"}
|
|
@@ -30,6 +30,41 @@
|
|
|
30
30
|
*/
|
|
31
31
|
import type { MacroRunV1, MacroInterrogationV1 } from '@seed-ship/mcp-ui-spec';
|
|
32
32
|
import type { ScratchpadState, ChatPromptConfig } from '../types/chat-bus';
|
|
33
|
+
/**
|
|
34
|
+
* The English wording this adapter produces on its own — section titles and
|
|
35
|
+
* the fallbacks used when the run (or the interrogation) carries none.
|
|
36
|
+
*
|
|
37
|
+
* The adapter is runtime-free by contract: no `solid-js`, no
|
|
38
|
+
* `MCPUIStringsContext`. Hosts that render in another language pass a
|
|
39
|
+
* partial override through `MacroRunAdapterOptions.messages`, exactly like
|
|
40
|
+
* `ConnectorResultToUILayoutOptions.messages`.
|
|
41
|
+
*
|
|
42
|
+
* @since v6.20.0
|
|
43
|
+
*/
|
|
44
|
+
export interface MacroRunAdapterMessages {
|
|
45
|
+
/** Title of the always-present `agent_card` section. */
|
|
46
|
+
agentSectionTitle: string;
|
|
47
|
+
/** Title of the `stepper` / `split_stepper` section. */
|
|
48
|
+
progressSectionTitle: string;
|
|
49
|
+
/** Title of each result section. */
|
|
50
|
+
resultSectionTitle: string;
|
|
51
|
+
/** Error message of an aborted run that carries no `error`. */
|
|
52
|
+
runAborted: string;
|
|
53
|
+
/** Error message of a failed run that carries no `error`. */
|
|
54
|
+
runFailed: string;
|
|
55
|
+
/** Prompt body of an elicitation with no usable schema and no message. */
|
|
56
|
+
confirmDefault: string;
|
|
57
|
+
}
|
|
58
|
+
/** English defaults for {@link MacroRunAdapterMessages}. */
|
|
59
|
+
export declare const DEFAULT_MACRO_RUN_MESSAGES: MacroRunAdapterMessages;
|
|
60
|
+
/** Options shared by the MacroRun adapters. @since v6.20.0 */
|
|
61
|
+
export interface MacroRunAdapterOptions {
|
|
62
|
+
/**
|
|
63
|
+
* Partial override of the adapter's own wording, merged over
|
|
64
|
+
* {@link DEFAULT_MACRO_RUN_MESSAGES}.
|
|
65
|
+
*/
|
|
66
|
+
messages?: Partial<MacroRunAdapterMessages>;
|
|
67
|
+
}
|
|
33
68
|
/**
|
|
34
69
|
* Convert a `MacroRunV1` snapshot into a `ScratchpadState`.
|
|
35
70
|
*
|
|
@@ -45,7 +80,7 @@ import type { ScratchpadState, ChatPromptConfig } from '../types/chat-bus';
|
|
|
45
80
|
*
|
|
46
81
|
* Pure: no fetch, no SSE, no persistence. The host owns all wiring.
|
|
47
82
|
*/
|
|
48
|
-
export declare function macroRunToScratchpadState(run: MacroRunV1): ScratchpadState;
|
|
83
|
+
export declare function macroRunToScratchpadState(run: MacroRunV1, options?: MacroRunAdapterOptions): ScratchpadState;
|
|
49
84
|
/**
|
|
50
85
|
* Convert a `MacroInterrogationV1` into a `ChatPromptConfig`.
|
|
51
86
|
*
|
|
@@ -61,5 +96,5 @@ export declare function macroRunToScratchpadState(run: MacroRunV1): ScratchpadSt
|
|
|
61
96
|
* {@link macroRunToScratchpadState} (which calls it for an embedded
|
|
62
97
|
* `pendingInterrogation`).
|
|
63
98
|
*/
|
|
64
|
-
export declare function macroInterrogationToChatPromptConfig(q: MacroInterrogationV1): ChatPromptConfig;
|
|
99
|
+
export declare function macroInterrogationToChatPromptConfig(q: MacroInterrogationV1, options?: MacroRunAdapterOptions): ChatPromptConfig;
|
|
65
100
|
//# sourceMappingURL=macro-run.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macro-run.d.ts","sourceRoot":"","sources":["../../src/adapters/macro-run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;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