@seed-ship/mcp-ui-solid 6.6.1 → 6.8.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.
Files changed (39) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/dist/adapters/index.d.ts +2 -1
  3. package/dist/adapters/index.d.ts.map +1 -1
  4. package/dist/adapters/macro-run.cjs +226 -0
  5. package/dist/adapters/macro-run.cjs.map +1 -0
  6. package/dist/adapters/macro-run.d.ts +65 -0
  7. package/dist/adapters/macro-run.d.ts.map +1 -0
  8. package/dist/adapters/macro-run.js +226 -0
  9. package/dist/adapters/macro-run.js.map +1 -0
  10. package/dist/adapters.cjs +3 -0
  11. package/dist/adapters.cjs.map +1 -1
  12. package/dist/adapters.d.cts +2 -1
  13. package/dist/adapters.d.ts +2 -1
  14. package/dist/adapters.js +4 -1
  15. package/dist/adapters.js.map +1 -1
  16. package/dist/mcp-ui-spec/dist/schemas.cjs +250 -1
  17. package/dist/mcp-ui-spec/dist/schemas.cjs.map +1 -1
  18. package/dist/mcp-ui-spec/dist/schemas.js +251 -2
  19. package/dist/mcp-ui-spec/dist/schemas.js.map +1 -1
  20. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.cjs +2 -0
  21. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.cjs.map +1 -1
  22. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js +2 -0
  23. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js.map +1 -1
  24. package/dist/services/validation.cjs +11 -2
  25. package/dist/services/validation.cjs.map +1 -1
  26. package/dist/services/validation.d.ts.map +1 -1
  27. package/dist/services/validation.js +11 -2
  28. package/dist/services/validation.js.map +1 -1
  29. package/dist/types/index.d.ts +1 -1
  30. package/dist/types.d.cts +1 -1
  31. package/dist/types.d.ts +1 -1
  32. package/package.json +2 -2
  33. package/src/adapters/index.ts +4 -5
  34. package/src/adapters/macro-run.test.ts +293 -0
  35. package/src/adapters/macro-run.ts +362 -0
  36. package/src/services/validation.test.ts +79 -1
  37. package/src/services/validation.ts +10 -1
  38. package/src/types/index.ts +1 -1
  39. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,58 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [6.8.0] - 2026-05-22
9
+
10
+ ### Changed — payload-size limit raised 50KB → 512KB
11
+
12
+ `DEFAULT_RESOURCE_LIMITS.maxPayloadSize` moved from `50 * 1024` to
13
+ `512 * 1024`. The single payload-size guard is shared by every component
14
+ type; at 50KB it rejected otherwise-valid `type:'map'` components carrying a
15
+ realistic `params.geojson` `FeatureCollection` as `PAYLOAD_TOO_LARGE`. A
16
+ dense multi-feature map (e.g. a département-wide choropleth) runs 300-500KB
17
+ even after reasonable geometry simplification — 512KB leaves real headroom
18
+ for that while still rejecting runaway payloads. Genuinely large datasets
19
+ belong in vector tiles (PMTiles), not inline GeoJSON.
20
+
21
+ - `validatePayloadSize()` and the reject-on-oversize principle are
22
+ **unchanged** — only the default ceiling moved. Validation is not disabled,
23
+ and a caller passing stricter `limits` keeps full control.
24
+ - Behaviour before/after: a valid component between 50KB and 512KB was
25
+ rejected, now passes; a payload over 512KB is still rejected. Components
26
+ under 50KB are unaffected. Per-registry limits (e.g. the 5KB/10KB presets
27
+ in `component-registry.ts`) are independent and untouched.
28
+
29
+ ## [6.7.0] - 2026-05-22
30
+
31
+ ### Added — MacroRun Phase 2 adapters
32
+
33
+ Pure adapters from the `MacroRunV1` contract (new in
34
+ `@seed-ship/mcp-ui-spec@5.3.0`) to existing MCP-UI primitives. Published on
35
+ the opt-in `@seed-ship/mcp-ui-solid/adapters` subpath — never imported by the
36
+ core renderer path.
37
+
38
+ - `macroRunToScratchpadState(run: MacroRunV1): ScratchpadState` — builds an
39
+ `agent_card` section, a `stepper` (or `split_stepper` when steps carry
40
+ `parallel` branches), a `prompt` section for an embedded
41
+ `pendingInterrogation`, and one section per `results` entry. Run status
42
+ maps `pending→loading`, `running→processing`, `awaiting_input→waiting_human`,
43
+ `completed→complete`, `failed`/`aborted`→`error` (aborted is never
44
+ retryable). `results` is optional — the adapter works without UI results.
45
+ - `macroInterrogationToChatPromptConfig(q: MacroInterrogationV1): ChatPromptConfig`
46
+ — maps `choice` / `confirm` / `form` directly, and routes `elicitation`
47
+ through the existing `elicitationToPromptConfig()` helper. Always returns a
48
+ `ChatPromptConfig`. Usable standalone or via `macroRunToScratchpadState`.
49
+
50
+ Both are **pure functions** — no fetch, no SSE listener, no persistence, no
51
+ global state.
52
+
53
+ **Out of scope (host / runtime responsibility):** the producer runtime that
54
+ emits a `macro-run/v1` snapshot (a later goal on the producing repo), and all
55
+ host-side wiring — SSE listener, fetch, persistence, resume. These adapters
56
+ only translate a snapshot the host already has. The `action:'submit'`
57
+ executors are untouched, and MacroRun is kept separate from the tool-call
58
+ action path.
59
+
8
60
  ## [6.6.1] - 2026-05-22
9
61
 
10
62
  ### Fixed — `action: 'submit'` is no longer inert outside a `<form>`
@@ -13,6 +13,7 @@
13
13
  * // → <UIResourceRenderer content={layout} />
14
14
  * ```
15
15
  */
16
- export { connectorResultToUILayout, connectorActionsToActionGroup, } from './connector';
16
+ export { connectorResultToUILayout, connectorActionsToActionGroup } from './connector';
17
17
  export type { ConnectorResultToUILayoutOptions, ConnectorActionsToActionGroupOptions, } from './connector';
18
+ export { macroRunToScratchpadState, macroInterrogationToChatPromptConfig } from './macro-run';
18
19
  //# 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,EACL,yBAAyB,EACzB,6BAA6B,GAC9B,MAAM,aAAa,CAAA;AACpB,YAAY,EACV,gCAAgC,EAChC,oCAAoC,GACrC,MAAM,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,yBAAyB,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AACvF,YAAY,EACV,gCAAgC,EAChC,oCAAoC,GACrC,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,yBAAyB,EAAE,oCAAoC,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,226 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const chatBus = require("../services/chat-bus.cjs");
4
+ const RUN_STATUS_TO_SCRATCHPAD = {
5
+ pending: "loading",
6
+ running: "processing",
7
+ awaiting_input: "waiting_human",
8
+ completed: "complete",
9
+ failed: "error",
10
+ aborted: "error"
11
+ };
12
+ function runStatusToAgentStatus(status) {
13
+ switch (status) {
14
+ case "pending":
15
+ return "idle";
16
+ case "running":
17
+ return "running";
18
+ case "awaiting_input":
19
+ return "waiting";
20
+ case "completed":
21
+ return "done";
22
+ case "failed":
23
+ case "aborted":
24
+ return "error";
25
+ }
26
+ }
27
+ function stepToStepperStatus(status) {
28
+ return status === "failed" ? "error" : status;
29
+ }
30
+ function buildAgentCard(run) {
31
+ const agent = run.agent;
32
+ const card = {
33
+ agentId: (agent == null ? void 0 : agent.id) ?? run.macroId,
34
+ name: (agent == null ? void 0 : agent.name) ?? run.macroName ?? run.macroId,
35
+ status: (agent == null ? void 0 : agent.status) ?? runStatusToAgentStatus(run.status)
36
+ };
37
+ if (agent == null ? void 0 : agent.avatar) card.avatar = agent.avatar;
38
+ if (agent == null ? void 0 : agent.capabilities) card.capabilities = agent.capabilities;
39
+ if (agent == null ? void 0 : agent.currentStep) card.currentStep = agent.currentStep;
40
+ return card;
41
+ }
42
+ function buildStepperContent(steps) {
43
+ return {
44
+ orientation: "horizontal",
45
+ steps: steps.map((step) => {
46
+ const out = {
47
+ id: step.id,
48
+ label: step.label,
49
+ status: stepToStepperStatus(step.status)
50
+ };
51
+ if (step.summary) out.summary = step.summary;
52
+ if (typeof step.durationMs === "number") out.duration_ms = step.durationMs;
53
+ return out;
54
+ })
55
+ };
56
+ }
57
+ function laneStatus(subSteps) {
58
+ if (subSteps.some((s) => s.status === "failed")) return "error";
59
+ if (subSteps.some((s) => s.status === "active")) return "active";
60
+ if (subSteps.length > 0 && subSteps.every((s) => s.status === "done" || s.status === "skipped"))
61
+ return "done";
62
+ return "pending";
63
+ }
64
+ function buildSplitStepperContent(steps) {
65
+ return {
66
+ agents: steps.map((step) => {
67
+ const subSteps = step.parallel && step.parallel.length > 0 ? step.parallel : [step];
68
+ return {
69
+ id: step.id,
70
+ name: step.label,
71
+ status: laneStatus(subSteps),
72
+ steps: subSteps.map((sub) => ({
73
+ id: sub.id,
74
+ label: sub.label,
75
+ status: stepToStepperStatus(sub.status)
76
+ }))
77
+ };
78
+ })
79
+ };
80
+ }
81
+ function resultSectionType(componentType) {
82
+ switch (componentType) {
83
+ case "chart":
84
+ return "chart";
85
+ case "map":
86
+ return "map";
87
+ case "table":
88
+ return "data_preview";
89
+ default:
90
+ return "data";
91
+ }
92
+ }
93
+ function buildError(run) {
94
+ if (run.status !== "failed" && run.status !== "aborted") return void 0;
95
+ const aborted = run.status === "aborted";
96
+ if (run.error) {
97
+ const err = {
98
+ message: run.error.message,
99
+ // An aborted run is never retryable, regardless of the producer flag.
100
+ retryable: aborted ? false : run.error.retryable ?? false
101
+ };
102
+ if (run.error.code) err.code = run.error.code;
103
+ return err;
104
+ }
105
+ return {
106
+ message: aborted ? "Macro run aborted." : "Macro run failed.",
107
+ retryable: false
108
+ };
109
+ }
110
+ function macroRunToScratchpadState(run) {
111
+ const sections = [];
112
+ sections.push({
113
+ id: "macro-agent",
114
+ title: "Agent",
115
+ type: "agent_card",
116
+ content: buildAgentCard(run),
117
+ editable: false,
118
+ source: "agent"
119
+ });
120
+ if (run.steps.length > 0) {
121
+ const hasParallel = run.steps.some((s) => Array.isArray(s.parallel) && s.parallel.length > 0);
122
+ sections.push(
123
+ hasParallel ? {
124
+ id: "macro-split-stepper",
125
+ title: "Progress",
126
+ type: "split_stepper",
127
+ content: buildSplitStepperContent(run.steps),
128
+ editable: false,
129
+ source: "agent"
130
+ } : {
131
+ id: "macro-stepper",
132
+ title: "Progress",
133
+ type: "stepper",
134
+ content: buildStepperContent(run.steps),
135
+ editable: false,
136
+ source: "agent"
137
+ }
138
+ );
139
+ }
140
+ if (run.pendingInterrogation) {
141
+ sections.push({
142
+ id: "macro-prompt",
143
+ title: run.pendingInterrogation.title,
144
+ type: "prompt",
145
+ content: macroInterrogationToChatPromptConfig(run.pendingInterrogation),
146
+ editable: false,
147
+ source: "agent"
148
+ });
149
+ }
150
+ const results = run.results ?? [];
151
+ results.forEach((component, index) => {
152
+ sections.push({
153
+ id: `macro-result-${String((component == null ? void 0 : component.id) ?? index)}`,
154
+ title: "Result",
155
+ type: resultSectionType(component == null ? void 0 : component.type),
156
+ content: component,
157
+ editable: false,
158
+ source: "agent"
159
+ });
160
+ });
161
+ const state = {
162
+ id: run.runId,
163
+ title: run.title ?? run.macroName ?? run.macroId,
164
+ sections,
165
+ filters: {},
166
+ agentMessages: [],
167
+ status: RUN_STATUS_TO_SCRATCHPAD[run.status]
168
+ };
169
+ const error = buildError(run);
170
+ if (error) state.error = error;
171
+ return state;
172
+ }
173
+ function isElicitationSchema(value) {
174
+ if (typeof value !== "object" || value === null) return false;
175
+ const v = value;
176
+ return v.type === "object" && typeof v.properties === "object" && v.properties !== null;
177
+ }
178
+ function macroInterrogationToChatPromptConfig(q) {
179
+ var _a, _b, _c;
180
+ switch (q.kind) {
181
+ case "choice": {
182
+ const options = (q.options ?? []).map((o) => {
183
+ const opt = { value: o.value, label: o.label };
184
+ if (o.icon) opt.icon = o.icon;
185
+ if (o.description) opt.description = o.description;
186
+ if (o.metadata) opt.metadata = o.metadata;
187
+ return opt;
188
+ });
189
+ return {
190
+ type: "choice",
191
+ title: q.title,
192
+ config: { options, layout: "vertical" }
193
+ };
194
+ }
195
+ case "confirm": {
196
+ const config = {};
197
+ if (q.message) config.message = q.message;
198
+ if ((_a = q.confirm) == null ? void 0 : _a.confirmLabel) config.confirmLabel = q.confirm.confirmLabel;
199
+ if ((_b = q.confirm) == null ? void 0 : _b.cancelLabel) config.cancelLabel = q.confirm.cancelLabel;
200
+ if ((_c = q.confirm) == null ? void 0 : _c.variant) config.variant = q.confirm.variant;
201
+ return { type: "confirm", title: q.title, config };
202
+ }
203
+ case "form":
204
+ return {
205
+ type: "form",
206
+ title: q.title,
207
+ config: { fields: q.fields ?? [] }
208
+ };
209
+ case "elicitation": {
210
+ if (isElicitationSchema(q.elicitationSchema)) {
211
+ return chatBus.elicitationToPromptConfig({
212
+ message: q.message ?? q.title,
213
+ requestedSchema: q.elicitationSchema
214
+ });
215
+ }
216
+ return {
217
+ type: "confirm",
218
+ title: q.title,
219
+ config: { message: q.message ?? "Please confirm to continue." }
220
+ };
221
+ }
222
+ }
223
+ }
224
+ exports.macroInterrogationToChatPromptConfig = macroInterrogationToChatPromptConfig;
225
+ exports.macroRunToScratchpadState = macroRunToScratchpadState;
226
+ //# sourceMappingURL=macro-run.cjs.map
@@ -0,0 +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;AAC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MAAM;AAAA,QACN,OAAO,EAAE;AAAA,QACT,QAAQ,EAAE,SAAS,EAAE,WAAW,8BAAA;AAAA,MAA8B;AAAA,IAElE;AAAA,EAAA;AAEJ;;;"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * MacroRun adapters — `MacroRunV1` / `MacroInterrogationV1` → MCP-UI render
3
+ * primitives.
4
+ *
5
+ * @since v6.7.0 (MacroRun Phase 2 — contract consolidated in deposium_MCPs
6
+ * `docs/2026/briefs/2026-05-22-macro-run-runtime-contract-consolidation.md`)
7
+ *
8
+ * ## Opt-in, pure
9
+ *
10
+ * Published under the dedicated subpath `@seed-ship/mcp-ui-solid/adapters` —
11
+ * never imported by the core renderer path. Every function here is a **pure
12
+ * function**: same input → same output, no `fetch`, no SSE listener, no
13
+ * persistence, no global state, no clock, no randomness.
14
+ *
15
+ * ## Scope boundary
16
+ *
17
+ * These adapters only translate the agnostic `MacroRunV1` contract (defined
18
+ * in `@seed-ship/mcp-ui-spec`) into existing MCP-UI primitives — a
19
+ * `ScratchpadState` and a `ChatPromptConfig`. They do NOT:
20
+ *
21
+ * - emit or consume any SSE event (a `macro_run_snapshot` producer is a
22
+ * separate, later goal on the producing runtime repo);
23
+ * - perform any fetch, persistence or resume;
24
+ * - know anything about a specific runtime, host, corpus or domain;
25
+ * - touch the `action:'submit'` executors, nor mix MacroRun with the
26
+ * existing tool-call action path.
27
+ *
28
+ * The host owns all of the above — it feeds a `MacroRunV1` snapshot in and
29
+ * decides where to render the result.
30
+ */
31
+ import type { MacroRunV1, MacroInterrogationV1 } from '@seed-ship/mcp-ui-spec';
32
+ import type { ScratchpadState, ChatPromptConfig } from '../types/chat-bus';
33
+ /**
34
+ * Convert a `MacroRunV1` snapshot into a `ScratchpadState`.
35
+ *
36
+ * Sections produced, in order:
37
+ * 1. `agent_card` — always (derived from `run.agent`, or from the macro
38
+ * identity when the run carries no agent, e.g. a non-interactive macro).
39
+ * 2. `stepper` — when the run has steps and none carry `parallel` branches.
40
+ * `split_stepper` instead when any step carries `parallel` (future model).
41
+ * 3. `prompt` — when `run.pendingInterrogation` is set; its content is the
42
+ * `ChatPromptConfig` produced by {@link macroInterrogationToChatPromptConfig}.
43
+ * 4. one section per `run.results` entry (`chart` / `map` / `data_preview` /
44
+ * `data`, by component type). Optional — the adapter works without results.
45
+ *
46
+ * Pure: no fetch, no SSE, no persistence. The host owns all wiring.
47
+ */
48
+ export declare function macroRunToScratchpadState(run: MacroRunV1): ScratchpadState;
49
+ /**
50
+ * Convert a `MacroInterrogationV1` into a `ChatPromptConfig`.
51
+ *
52
+ * - `choice` → `{ type: 'choice' }` (vertical layout).
53
+ * - `confirm` → `{ type: 'confirm' }`.
54
+ * - `form` → `{ type: 'form' }` (the opaque `fields` are passed through).
55
+ * - `elicitation` → routed through the existing `elicitationToPromptConfig()`
56
+ * helper. If the interrogation carries no usable elicitation JSON Schema,
57
+ * it degrades to a `confirm` prompt rather than throwing.
58
+ *
59
+ * Always returns a `ChatPromptConfig` — never an `ElicitationEvent` — so the
60
+ * host has a single entry point. Usable standalone or via
61
+ * {@link macroRunToScratchpadState} (which calls it for an embedded
62
+ * `pendingInterrogation`).
63
+ */
64
+ export declare function macroInterrogationToChatPromptConfig(q: MacroInterrogationV1): ChatPromptConfig;
65
+ //# sourceMappingURL=macro-run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"macro-run.d.ts","sourceRoot":"","sources":["../../src/adapters/macro-run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAe,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC5F,OAAO,KAAK,EACV,eAAe,EAEf,gBAAgB,EAOjB,MAAM,mBAAmB,CAAC;AA0J3B;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,UAAU,GAAG,eAAe,CA6E1E;AAUD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oCAAoC,CAAC,CAAC,EAAE,oBAAoB,GAAG,gBAAgB,CAgD9F"}
@@ -0,0 +1,226 @@
1
+ import { elicitationToPromptConfig } from "../services/chat-bus.js";
2
+ const RUN_STATUS_TO_SCRATCHPAD = {
3
+ pending: "loading",
4
+ running: "processing",
5
+ awaiting_input: "waiting_human",
6
+ completed: "complete",
7
+ failed: "error",
8
+ aborted: "error"
9
+ };
10
+ function runStatusToAgentStatus(status) {
11
+ switch (status) {
12
+ case "pending":
13
+ return "idle";
14
+ case "running":
15
+ return "running";
16
+ case "awaiting_input":
17
+ return "waiting";
18
+ case "completed":
19
+ return "done";
20
+ case "failed":
21
+ case "aborted":
22
+ return "error";
23
+ }
24
+ }
25
+ function stepToStepperStatus(status) {
26
+ return status === "failed" ? "error" : status;
27
+ }
28
+ function buildAgentCard(run) {
29
+ const agent = run.agent;
30
+ const card = {
31
+ agentId: (agent == null ? void 0 : agent.id) ?? run.macroId,
32
+ name: (agent == null ? void 0 : agent.name) ?? run.macroName ?? run.macroId,
33
+ status: (agent == null ? void 0 : agent.status) ?? runStatusToAgentStatus(run.status)
34
+ };
35
+ if (agent == null ? void 0 : agent.avatar) card.avatar = agent.avatar;
36
+ if (agent == null ? void 0 : agent.capabilities) card.capabilities = agent.capabilities;
37
+ if (agent == null ? void 0 : agent.currentStep) card.currentStep = agent.currentStep;
38
+ return card;
39
+ }
40
+ function buildStepperContent(steps) {
41
+ return {
42
+ orientation: "horizontal",
43
+ steps: steps.map((step) => {
44
+ const out = {
45
+ id: step.id,
46
+ label: step.label,
47
+ status: stepToStepperStatus(step.status)
48
+ };
49
+ if (step.summary) out.summary = step.summary;
50
+ if (typeof step.durationMs === "number") out.duration_ms = step.durationMs;
51
+ return out;
52
+ })
53
+ };
54
+ }
55
+ function laneStatus(subSteps) {
56
+ if (subSteps.some((s) => s.status === "failed")) return "error";
57
+ if (subSteps.some((s) => s.status === "active")) return "active";
58
+ if (subSteps.length > 0 && subSteps.every((s) => s.status === "done" || s.status === "skipped"))
59
+ return "done";
60
+ return "pending";
61
+ }
62
+ function buildSplitStepperContent(steps) {
63
+ return {
64
+ agents: steps.map((step) => {
65
+ const subSteps = step.parallel && step.parallel.length > 0 ? step.parallel : [step];
66
+ return {
67
+ id: step.id,
68
+ name: step.label,
69
+ status: laneStatus(subSteps),
70
+ steps: subSteps.map((sub) => ({
71
+ id: sub.id,
72
+ label: sub.label,
73
+ status: stepToStepperStatus(sub.status)
74
+ }))
75
+ };
76
+ })
77
+ };
78
+ }
79
+ function resultSectionType(componentType) {
80
+ switch (componentType) {
81
+ case "chart":
82
+ return "chart";
83
+ case "map":
84
+ return "map";
85
+ case "table":
86
+ return "data_preview";
87
+ default:
88
+ return "data";
89
+ }
90
+ }
91
+ function buildError(run) {
92
+ if (run.status !== "failed" && run.status !== "aborted") return void 0;
93
+ const aborted = run.status === "aborted";
94
+ if (run.error) {
95
+ const err = {
96
+ message: run.error.message,
97
+ // An aborted run is never retryable, regardless of the producer flag.
98
+ retryable: aborted ? false : run.error.retryable ?? false
99
+ };
100
+ if (run.error.code) err.code = run.error.code;
101
+ return err;
102
+ }
103
+ return {
104
+ message: aborted ? "Macro run aborted." : "Macro run failed.",
105
+ retryable: false
106
+ };
107
+ }
108
+ function macroRunToScratchpadState(run) {
109
+ const sections = [];
110
+ sections.push({
111
+ id: "macro-agent",
112
+ title: "Agent",
113
+ type: "agent_card",
114
+ content: buildAgentCard(run),
115
+ editable: false,
116
+ source: "agent"
117
+ });
118
+ if (run.steps.length > 0) {
119
+ const hasParallel = run.steps.some((s) => Array.isArray(s.parallel) && s.parallel.length > 0);
120
+ sections.push(
121
+ hasParallel ? {
122
+ id: "macro-split-stepper",
123
+ title: "Progress",
124
+ type: "split_stepper",
125
+ content: buildSplitStepperContent(run.steps),
126
+ editable: false,
127
+ source: "agent"
128
+ } : {
129
+ id: "macro-stepper",
130
+ title: "Progress",
131
+ type: "stepper",
132
+ content: buildStepperContent(run.steps),
133
+ editable: false,
134
+ source: "agent"
135
+ }
136
+ );
137
+ }
138
+ if (run.pendingInterrogation) {
139
+ sections.push({
140
+ id: "macro-prompt",
141
+ title: run.pendingInterrogation.title,
142
+ type: "prompt",
143
+ content: macroInterrogationToChatPromptConfig(run.pendingInterrogation),
144
+ editable: false,
145
+ source: "agent"
146
+ });
147
+ }
148
+ const results = run.results ?? [];
149
+ results.forEach((component, index) => {
150
+ sections.push({
151
+ id: `macro-result-${String((component == null ? void 0 : component.id) ?? index)}`,
152
+ title: "Result",
153
+ type: resultSectionType(component == null ? void 0 : component.type),
154
+ content: component,
155
+ editable: false,
156
+ source: "agent"
157
+ });
158
+ });
159
+ const state = {
160
+ id: run.runId,
161
+ title: run.title ?? run.macroName ?? run.macroId,
162
+ sections,
163
+ filters: {},
164
+ agentMessages: [],
165
+ status: RUN_STATUS_TO_SCRATCHPAD[run.status]
166
+ };
167
+ const error = buildError(run);
168
+ if (error) state.error = error;
169
+ return state;
170
+ }
171
+ function isElicitationSchema(value) {
172
+ if (typeof value !== "object" || value === null) return false;
173
+ const v = value;
174
+ return v.type === "object" && typeof v.properties === "object" && v.properties !== null;
175
+ }
176
+ function macroInterrogationToChatPromptConfig(q) {
177
+ var _a, _b, _c;
178
+ switch (q.kind) {
179
+ case "choice": {
180
+ const options = (q.options ?? []).map((o) => {
181
+ const opt = { value: o.value, label: o.label };
182
+ if (o.icon) opt.icon = o.icon;
183
+ if (o.description) opt.description = o.description;
184
+ if (o.metadata) opt.metadata = o.metadata;
185
+ return opt;
186
+ });
187
+ return {
188
+ type: "choice",
189
+ title: q.title,
190
+ config: { options, layout: "vertical" }
191
+ };
192
+ }
193
+ case "confirm": {
194
+ const config = {};
195
+ if (q.message) config.message = q.message;
196
+ if ((_a = q.confirm) == null ? void 0 : _a.confirmLabel) config.confirmLabel = q.confirm.confirmLabel;
197
+ if ((_b = q.confirm) == null ? void 0 : _b.cancelLabel) config.cancelLabel = q.confirm.cancelLabel;
198
+ if ((_c = q.confirm) == null ? void 0 : _c.variant) config.variant = q.confirm.variant;
199
+ return { type: "confirm", title: q.title, config };
200
+ }
201
+ case "form":
202
+ return {
203
+ type: "form",
204
+ title: q.title,
205
+ config: { fields: q.fields ?? [] }
206
+ };
207
+ case "elicitation": {
208
+ if (isElicitationSchema(q.elicitationSchema)) {
209
+ return elicitationToPromptConfig({
210
+ message: q.message ?? q.title,
211
+ requestedSchema: q.elicitationSchema
212
+ });
213
+ }
214
+ return {
215
+ type: "confirm",
216
+ title: q.title,
217
+ config: { message: q.message ?? "Please confirm to continue." }
218
+ };
219
+ }
220
+ }
221
+ }
222
+ export {
223
+ macroInterrogationToChatPromptConfig,
224
+ macroRunToScratchpadState
225
+ };
226
+ //# sourceMappingURL=macro-run.js.map