@runic-artifex/vite-plugin-runic 0.19.0 → 0.20.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/dist/index.d.ts CHANGED
@@ -1,10 +1,17 @@
1
1
  import type { Plugin } from "vite";
2
2
  import type { RunicDiagnosticEntry } from "./diagnostics.js";
3
+ import { type RunicOtlpOptions } from "./otlp.js";
3
4
  import { type RunicComponentOptions } from "./component.js";
4
5
  export type { RunicComponentOptions } from "./component.js";
6
+ export type { RunicOtlpOptions } from "./otlp.js";
5
7
  export { runicDevSessionProxy } from "./dev-session.js";
6
8
  export type { RunicDevSessionProxyOptions } from "./dev-session.js";
7
9
  export type { RunicDevelopmentState, RunicViewSnapshot } from "./timeline.js";
10
+ export type { RunicBridgeCall, RunicBridgeCallHandler, RunicBridgeCallOutcome } from "./calls.js";
11
+ export type { RunicHandlerAnalysis, RunicHandlerBinding, RunicHandlerCall, RunicHandlerPosition } from "./handlers.js";
12
+ export type { RunicInspectApi } from "./inspect.js";
13
+ export type { RunicInspectCall, RunicInspectCommand, RunicInspectComponent, RunicInspectDescription, RunicInspectEvidence, RunicInspectLocation, RunicInspectMember, RunicInspectMessage, RunicInspectText, RunicInspectViewModel, } from "./inspect-data.js";
14
+ export type { RunicSourceLocation, RunicSourceMap, RunicSourceMember, RunicSourceMemberKind, RunicSourceViewModel, } from "./sources.js";
8
15
  export type { RunicDiagnosticDetail, RunicDiagnosticDetailValue, RunicDiagnosticFailure, RunicDiagnosticEntry, RunicDiagnosticSource, RunicTraceKind, RunicViewStateValue, } from "./diagnostics.js";
9
16
  /** The API another Vite plugin reaches through `plugin.api`, Vite's inter-plugin convention. */
10
17
  export interface RunicVitePluginApi {
@@ -51,5 +58,37 @@ export interface RunicViteOptions {
51
58
  * development server serves the page only.
52
59
  */
53
60
  readonly component?: RunicComponentOptions;
61
+ /**
62
+ * The development source map that the Bridge generator writes to `obj` (`runic-bridge/sources.json`), which
63
+ * `vite dev` serves at `/__runic/sources` and opens in the editor through `/__runic/open`. A path names the file or
64
+ * a directory to search, relative to the Vite root. By default the plugin takes the path `dotnet runic dev` passes,
65
+ * else searches `obj` of the project, the Vite root and its parent. `false` reads no map: no `/__runic/sources`, and
66
+ * `/__runic/open` opens only frontend files that Vite serves. The build
67
+ * never reads it.
68
+ */
69
+ readonly sourceMap?: string | false;
70
+ /**
71
+ * `false` leaves Runic Inspect out of the development client: the select mode (Alt+Shift+X) that shows how an
72
+ * element is connected to its ViewModels, and `globalThis[Symbol.for("runic.vite.inspect")]`. Defaults to `true`.
73
+ * The build never contains it.
74
+ */
75
+ readonly inspect?: boolean;
76
+ /**
77
+ * Hosts and networks besides this machine whose pages may read Runic Inspect's data (`/__runic/sources`,
78
+ * `/__runic/handlers`) when the development server is reachable from them (`server.host`): IPv4 or IPv6 addresses,
79
+ * CIDR networks (a Tailscale network: `100.64.0.0/10`, `fd7a:115c:a1e0::/48`) and host names, resolved when a request
80
+ * arrives. The `RUNIC_DEV_ALLOW` environment variable adds to them; Runic Translations' in-page editing API reads the
81
+ * same variable. Loopback only by default. `/__runic/open` stays loopback-only: it launches the editor on this machine.
82
+ */
83
+ readonly allow?: readonly string[];
84
+ /**
85
+ * Exports the page's spans of Bridge calls over OTLP while serving, so they join the .NET host's spans in one trace
86
+ * (W3C trace context in each call's request, `trace-context/1`). By default it is on when `OTEL_EXPORTER_OTLP_ENDPOINT`
87
+ * or `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` is set in the development server's environment, and off with
88
+ * `OTEL_SDK_DISABLED=true` or `OTEL_TRACES_EXPORTER=none`. The development server posts OTLP/HTTP JSON, so the endpoint
89
+ * is an OTLP/HTTP receiver. `false` turns it off; an object sets the URL, headers or service name. Requires the
90
+ * development client (`devtools` not `false`).
91
+ */
92
+ readonly otlp?: boolean | RunicOtlpOptions;
54
93
  }
55
94
  export declare function runic(options?: RunicViteOptions): RunicVitePlugin;
package/dist/index.js CHANGED
@@ -1,9 +1,17 @@
1
1
  /// <reference types="@vitejs/devtools-kit" />
2
+ import { isFileLoadingAllowed } from "vite";
3
+ import { readFileSync } from "node:fs";
2
4
  import { isAbsolute, relative } from "node:path";
3
5
  import { rewriteHostScripts, webRootPrefix } from "./host-scripts.js";
4
- import { clientOptionsKey, connectionEvent, diagnosticEvent, diagnosticsPath, viewEvent } from "./channel.js";
6
+ import { callEvent, clientOptionsKey, connectionEvent, diagnosticEvent, diagnosticsPath, handlersPath, requestEvent, responseEvent, viewEvent, } from "./channel.js";
5
7
  import { answerClientMessage, answerState, devSessionValue, devSessionVariable, statePath } from "./dev-session.js";
6
8
  import { createDevelopmentTimeline, initialDevelopmentState, timelineLimit, withoutFailures } from "./timeline.js";
9
+ import { answerClientRequest, answerOpen, answerSources, createSourceMapReader, launchSourceEditor, listsFile, openPath, resolveOpenLocation, sourcesPath, } from "./sources.js";
10
+ import { formatMilliseconds, stackFrames } from "./calls.js";
11
+ import { findMessageSource, readMessageReply } from "./translations-source.js";
12
+ import { allowVariable, parseAllowList, resolveAccessList } from "./access.js";
13
+ import { answerHandlers, createHandlerAnalyzer, handlerFile } from "./handlers.js";
14
+ import { createOtlpForwarder, resolveOtlp, spanEvent } from "./otlp.js";
7
15
  import { buildComponent, componentEnvironment, componentEnvironmentOptions, componentHooks, resolveComponentOptions, } from "./component.js";
8
16
  export { runicDevSessionProxy } from "./dev-session.js";
9
17
  const virtualClientId = "virtual:runic/client";
@@ -25,13 +33,28 @@ export function runic(options = {}) {
25
33
  if (options.html !== undefined && typeof options.html !== "boolean") {
26
34
  throw new TypeError("html must be true or false.");
27
35
  }
36
+ if (options.otlp !== undefined && typeof options.otlp !== "boolean" && (typeof options.otlp !== "object" || options.otlp === null)) {
37
+ throw new TypeError("otlp must be true, false or { url?, headers?, serviceName? }.");
38
+ }
28
39
  const html = options.html !== false;
40
+ if (options.inspect !== undefined && typeof options.inspect !== "boolean") {
41
+ throw new TypeError("inspect must be true or false.");
42
+ }
43
+ if (options.sourceMap !== undefined && options.sourceMap !== false &&
44
+ (typeof options.sourceMap !== "string" || options.sourceMap.length === 0)) {
45
+ throw new TypeError("sourceMap must be a path or false.");
46
+ }
29
47
  const client = options.devtools !== false;
48
+ const allowRules = options.allow === undefined ? [] : parseAllowList(options.allow, "allow");
30
49
  let server;
50
+ // The OTLP export of the page's spans, while serving with the development client.
51
+ let otlp;
31
52
  let sharedState;
32
53
  let jsonRenderer;
33
54
  let resolvedRoot = process.cwd();
34
55
  let base = "/";
56
+ // Whether the Vite DevTools dock is registered (DevTools() from @vitejs/devtools), which the client then loads.
57
+ let dock = false;
35
58
  const desktopBootstrapUrl = resolveDesktopBootstrapUrl(options.desktop);
36
59
  if (!html && desktopBootstrapUrl !== undefined) {
37
60
  throw new TypeError("desktop requires html: true: the Desktop bootstrap is a script tag the plugin adds to the HTML.");
@@ -41,11 +64,32 @@ export function runic(options = {}) {
41
64
  const relocatableOption = desktopBootstrapUrl !== undefined ? "desktop: true" : "component";
42
65
  const components = component === undefined ? undefined : componentHooks(component, () => resolvedRoot);
43
66
  const inComponent = (environment) => components !== undefined && environment?.name === componentEnvironment;
67
+ // The development source map, read while serving only (sources.ts).
68
+ const readSourceMap = options.sourceMap === false
69
+ ? () => undefined
70
+ : createSourceMapReader(options.sourceMap, () => resolvedRoot);
44
71
  const timeline = createDevelopmentTimeline(initialDevelopmentState(options.contract), maxTimelineEntries, (state) => {
45
72
  sharedState?.mutate((draft) => Object.assign(draft, structuredClone(state)));
46
- void jsonRenderer?.updateSpec(createDevtoolsSpec(state));
73
+ void jsonRenderer?.updateSpec(createDevtoolsSpec(state, readSourceMap()));
47
74
  server?.ws.send({ type: "custom", event: stateEvent, data: state });
48
75
  });
76
+ // What /__runic/open opens besides the map's files: a frontend file Vite itself would serve to the page
77
+ // (server.fs.allow and deny; with fs.strict: false, any file, as Vite then serves any), such as a component Runic
78
+ // Inspect links to. Nothing before Vite serves. The dock's open action opens the map's files only.
79
+ const frontendFile = (file) => server !== undefined && isFileLoadingAllowed(server.config, file);
80
+ // /__runic/open and the dock's action open with launch-editor, the package behind Vite's /__open-in-editor
81
+ // (sources.ts, launchSourceEditor), so the editor is chosen as Vite chooses it.
82
+ const openLocation = (location) => launchSourceEditor(location, (message) => server?.config.logger.warn(`[runic] ${message}`));
83
+ // What else /__runic/open opens besides the map's locations: frontend files Vite serves, and with Runic Inspect, where
84
+ // the Translations dev server says a message is.
85
+ const openResolution = (viteServer) => ({
86
+ frontendFile,
87
+ ...(options.inspect === false ? {} : {
88
+ findMessage: (message) => findMessageSource({
89
+ address: viteServer.httpServer?.address(), https: Boolean(viteServer.config?.server?.https), base,
90
+ }, message),
91
+ }),
92
+ });
49
93
  const deliver = (event, data) => {
50
94
  if (event === connectionEvent)
51
95
  timeline.applyConnection(data);
@@ -53,6 +97,10 @@ export function runic(options = {}) {
53
97
  timeline.appendDiagnostic(data);
54
98
  else if (event === viewEvent)
55
99
  timeline.applyView(data);
100
+ else if (event === callEvent)
101
+ timeline.appendCall(data, readSourceMap());
102
+ else if (event === spanEvent)
103
+ otlp?.add(data);
56
104
  };
57
105
  const command = () => timeline.state.vite.command;
58
106
  const transformIndexHtml = {
@@ -137,7 +185,22 @@ export function runic(options = {}) {
137
185
  !resolved.plugins.some((plugin) => plugin.name === "vite:devtools:server")) {
138
186
  throw new Error('RUNICP007: devtools: true requires DevTools() from @vitejs/devtools in the Vite plugins array.');
139
187
  }
188
+ dock = resolved.command === "serve" && resolved.plugins.some((plugin) => plugin.name === "vite:devtools:server");
189
+ if (dock && !html) {
190
+ // With html: false the page owns its HTML (SvelteKit renders it and runs no transformIndexHtml, and warns about
191
+ // a plugin that has one), so the dock's HTML loader never runs: the client loads the dock instead.
192
+ const injection = resolved.plugins.find((plugin) => plugin.name === "vite:devtools:injection");
193
+ if (injection !== undefined)
194
+ delete injection.transformIndexHtml;
195
+ }
140
196
  resolvedRoot = resolved.root;
197
+ if (resolved.command === "serve" && client) {
198
+ const exported = resolveOtlp(options.otlp, process.env, resolved.root);
199
+ if (exported !== undefined) {
200
+ otlp = createOtlpForwarder(exported, { version: pluginVersion(), warn: (message) => resolved.logger.warn(message) });
201
+ resolved.logger.info(`[runic] Exporting the page's Bridge call spans to ${exported.url} as ${exported.serviceName} (OTLP/HTTP JSON).`);
202
+ }
203
+ }
141
204
  const configuredBase = resolved.base || "/";
142
205
  base = configuredBase.endsWith("/") ? configuredBase : `${configuredBase}/`;
143
206
  timeline.configure((state) => ({
@@ -150,6 +213,34 @@ export function runic(options = {}) {
150
213
  viteServer.ws.on(connectionEvent, (payload) => deliver(connectionEvent, payload));
151
214
  viteServer.ws.on(diagnosticEvent, (payload) => deliver(diagnosticEvent, payload));
152
215
  viteServer.ws.on(viewEvent, (payload) => deliver(viewEvent, payload));
216
+ viteServer.ws.on(callEvent, (payload) => deliver(callEvent, payload));
217
+ viteServer.ws.on(spanEvent, (payload) => deliver(spanEvent, payload));
218
+ // Who besides this machine may read Runic Inspect's data: runic({ allow }) and RUNIC_DEV_ALLOW (access.ts).
219
+ const access = resolveAccessList(allowRules);
220
+ // Runic Inspect's source map, handler analysis, message and open requests over the HMR connection, which the page
221
+ // has also when it is not Vite's own, as under dotnet runic dev (channel.ts, requestEvent). The same answers and the
222
+ // same access rules as the HTTP endpoints: Vite's WebSocket server reports each connection's peer address, which
223
+ // the access list judges per request (reads: loopback or allowed; open: loopback only).
224
+ const peers = new WeakMap();
225
+ viteServer.ws.on("connection", (socket, request) => {
226
+ peers.set(socket, request.socket?.remoteAddress);
227
+ });
228
+ const requestResolution = openResolution(viteServer);
229
+ const requestAnalyzer = client && options.inspect !== false ? createHandlerAnalyzer(() => resolvedRoot) : undefined;
230
+ viteServer.ws.on(requestEvent, (payload, hotClient) => {
231
+ const socket = hotClient.socket;
232
+ void answerClientRequest(payload, {
233
+ read: readSourceMap, launch: openLocation, resolution: requestResolution,
234
+ ...(requestAnalyzer === undefined ? {} : { analyze: (file) => requestAnalyzer(handlerFile(file, resolvedRoot)) }),
235
+ ...(options.inspect === false ? {} : {
236
+ message: (message) => readMessageReply({
237
+ address: viteServer.httpServer?.address(), https: Boolean(viteServer.config?.server?.https), base,
238
+ }, message),
239
+ }),
240
+ peer: socket === undefined ? undefined : peers.get(socket), access,
241
+ }).then((answer) => { if (answer !== undefined)
242
+ hotClient.send(responseEvent, answer); });
243
+ });
153
244
  const devSession = devSessionValue(process.env[devSessionVariable]);
154
245
  viteServer.middlewares.use(statePath, (_request, response) => {
155
246
  answerState(response, timeline.state, devSession);
@@ -158,8 +249,35 @@ export function runic(options = {}) {
158
249
  viteServer.middlewares.use(diagnosticsPath, (request, response, next) => {
159
250
  answerClientMessage(request, response, deliver).catch(next);
160
251
  });
252
+ if (access.remote && (options.sourceMap !== false || (client && options.inspect !== false))) {
253
+ viteServer.config?.logger?.info(`[runic] Runic Inspect's data (/__runic/sources, /__runic/handlers) accepts requests from loopback and ${access.rules.map((rule) => rule.text).join(", ")} (runic({ allow }), ${allowVariable}); /__runic/open stays loopback-only`, { timestamp: true });
254
+ }
255
+ if (options.sourceMap !== false) {
256
+ viteServer.middlewares.use(sourcesPath, (request, response, next) => {
257
+ answerSources(request, response, readSourceMap, access).catch(next);
258
+ });
259
+ }
260
+ if (client && options.inspect !== false) {
261
+ // Runic Inspect asks which of a file's event handlers reach which client calls, before any click.
262
+ const analyze = createHandlerAnalyzer(() => resolvedRoot);
263
+ viteServer.middlewares.use(handlersPath, (request, response, next) => {
264
+ // A mounted handler sees the URL without the mount path.
265
+ request.url = `${handlersPath}${request.url ?? ""}`;
266
+ answerHandlers(request, response, analyze, resolvedRoot, access).catch(next);
267
+ });
268
+ }
269
+ // The open action (sources.ts, resolveOpenLocation; D066.36): the source map's locations, frontend files Vite
270
+ // serves, and Runic Inspect's Translations messages. With sourceMap: false the reader has no map, so it opens only
271
+ // what Inspect links to.
272
+ if (options.sourceMap !== false || options.inspect !== false) {
273
+ const resolution = openResolution(viteServer);
274
+ viteServer.middlewares.use(openPath, (request, response, next) => {
275
+ answerOpen(request, response, readSourceMap, openLocation, resolution).catch(next);
276
+ });
277
+ }
161
278
  viteServer.httpServer?.once("close", () => {
162
279
  server = undefined;
280
+ void otlp?.close();
163
281
  });
164
282
  },
165
283
  resolveId(id, importer, resolveOptions) {
@@ -186,7 +304,13 @@ export function runic(options = {}) {
186
304
  if (id === resolvedEmptyClientId)
187
305
  return "export {};";
188
306
  if (id === resolvedClientOptionsId) {
189
- const statements = [`globalThis[Symbol.for(${JSON.stringify(clientOptionsKey.description)})] = { channel: "hot" };`];
307
+ // trace: the client gives each Bridge call a trace context and sends its span, which the server exports.
308
+ const clientOptions = {
309
+ channel: "hot", base, root: resolvedRoot, ...(options.inspect === false ? { inspect: false } : {}),
310
+ ...(dock ? { dock: true } : {}),
311
+ ...(otlp === undefined ? {} : { trace: true }),
312
+ };
313
+ const statements = [`globalThis[Symbol.for(${JSON.stringify(clientOptionsKey.description)})] = ${JSON.stringify(clientOptions)};`];
190
314
  if (options.staleInputWarning === false) {
191
315
  statements.push(`globalThis[Symbol.for("runic.vite.staleInputWarning")] = false;`);
192
316
  }
@@ -210,7 +334,7 @@ export function runic(options = {}) {
210
334
  if (!client)
211
335
  return;
212
336
  sharedState = await context.rpc.sharedState.get(stateKey, { initialValue: timeline.state });
213
- const renderer = context.createJsonRenderer(createDevtoolsSpec(timeline.state));
337
+ const renderer = context.createJsonRenderer(createDevtoolsSpec(timeline.state, readSourceMap()));
214
338
  jsonRenderer = renderer;
215
339
  context.docks.register({
216
340
  id: "runic:overview",
@@ -219,6 +343,23 @@ export function runic(options = {}) {
219
343
  type: "json-render",
220
344
  view: renderer.view,
221
345
  });
346
+ // The dock's open buttons: `{ id }` of a map entry or `{ file, line }` of a stack frame. The same decision as
347
+ // /__runic/open (resolveOpenLocation), limited to the source map: a location in a file it lists, while it exists.
348
+ // Vite DevTools lets only the clients it trusts call an action, so there is no request origin to check here.
349
+ context.rpc.register({
350
+ name: openInEditorAction,
351
+ type: "action",
352
+ setup: () => ({
353
+ handler: async (target) => {
354
+ // With sourceMap: false the reader has no map, so nothing opens.
355
+ // Map entries and .NET stack frames only: the dock links nothing else.
356
+ const location = await resolveOpenLocation(readSourceMap, target);
357
+ if (location === undefined || location === "invalid")
358
+ throw new Error("The source map lists no such location.");
359
+ openLocation(location);
360
+ },
361
+ }),
362
+ });
222
363
  context.commands.register({
223
364
  id: "runic:copy-diagnostic-state",
224
365
  title: "Runic: Copy sanitized diagnostic state",
@@ -228,6 +369,15 @@ export function runic(options = {}) {
228
369
  },
229
370
  };
230
371
  }
372
+ function pluginVersion() {
373
+ try {
374
+ const manifest = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
375
+ return typeof manifest.version === "string" ? manifest.version : "0";
376
+ }
377
+ catch {
378
+ return "0";
379
+ }
380
+ }
231
381
  function resolveDesktopBootstrapUrl(options) {
232
382
  if (options === undefined || options === false)
233
383
  return undefined;
@@ -248,7 +398,66 @@ function resolveDesktopBootstrapUrl(options) {
248
398
  }
249
399
  return url.href;
250
400
  }
251
- function createDevtoolsSpec(current) {
401
+ const openInEditorAction = "runic:open-in-editor";
402
+ // The dock shows the most recent calls; the state keeps as many as the timeline.
403
+ const dockCalls = 20;
404
+ const dockFrames = 8;
405
+ function openButton(label, target) {
406
+ return {
407
+ type: "Button",
408
+ props: { label, icon: "ph:arrow-square-out", variant: "ghost" },
409
+ on: { press: { action: openInEditorAction, params: target } },
410
+ };
411
+ }
412
+ // A .NET stack as text, with a button for each frame in a file of the source map.
413
+ function stackElements(id, stack, map) {
414
+ const elements = {};
415
+ const frames = stackFrames(stack, dockFrames).filter((frame) => listsFile(map, frame.file));
416
+ const children = frames.map((frame, index) => {
417
+ const name = `${id}-frame-${index}`;
418
+ const fileName = frame.file.split(/[\\/]/u).pop();
419
+ elements[name] = openButton(`${frame.method.replace(/^.*\.(?=[^.]+\.[^.]+$)/u, "")} · ${fileName}:${frame.line}`, { file: frame.file, line: frame.line });
420
+ return name;
421
+ });
422
+ return [children, elements];
423
+ }
424
+ // The call timeline: the newest call first, each with its handler's open button and a failed call's frames.
425
+ function callsSection(current, map) {
426
+ const calls = current.calls.slice(-dockCalls).reverse();
427
+ const elements = {};
428
+ const rows = calls.map((call) => {
429
+ const id = `calls-${call.id}`;
430
+ const children = [`${id}-label`];
431
+ elements[`${id}-label`] = { type: "Text", props: { text: call.label, variant: call.outcome === "error" ? "body" : "code" } };
432
+ const details = [
433
+ ...(call.handlerDuration === undefined ? [] : [`C# ${formatMilliseconds(call.handlerDuration)}`]),
434
+ ...(call.revision === undefined ? [] : [`revision ${call.revision}`]),
435
+ ...(call.handler?.fileName === undefined ? [] : [`${call.handler.fileName}${call.handler.line === undefined ? "" : `:${call.handler.line}`}`]),
436
+ call.timestamp,
437
+ ];
438
+ elements[`${id}-detail`] = { type: "Text", props: { text: details.join(" · "), variant: "caption" } };
439
+ children.push(`${id}-detail`);
440
+ if (call.handler?.line !== undefined) {
441
+ elements[`${id}-open`] = openButton(`Open ${call.handler.method}`, { id: call.handler.source });
442
+ children.push(`${id}-open`);
443
+ }
444
+ if (call.failure) {
445
+ elements[`${id}-failure`] = { type: "Text", props: { text: `${call.failure.type}: ${call.failure.message}`, variant: "caption" } };
446
+ const [frames, frameElements] = stackElements(id, call.failure.stack, map);
447
+ Object.assign(elements, frameElements);
448
+ children.push(`${id}-failure`, ...frames);
449
+ }
450
+ elements[id] = { type: "Stack", props: { direction: "column", gap: 2 }, children };
451
+ return id;
452
+ });
453
+ if (rows.length === 0)
454
+ elements["calls-none"] = { type: "Text", props: { text: "No Bridge call yet" } };
455
+ return {
456
+ calls: { type: "Card", props: { title: "Bridge calls" }, children: rows.length === 0 ? ["calls-none"] : rows },
457
+ ...elements,
458
+ };
459
+ }
460
+ function createDevtoolsSpec(current, map) {
252
461
  const section = (id, title, data) => ({
253
462
  [id]: { type: "Card", props: { title }, children: [`${id}-data`] },
254
463
  [`${id}-data`]: { type: "KeyValueTable", props: { data } },
@@ -259,7 +468,7 @@ function createDevtoolsSpec(current) {
259
468
  root: {
260
469
  type: "Stack",
261
470
  props: { direction: "column", gap: 12 },
262
- children: ["heading", "connection", "contract", "views", "superseded", "failure", "timeline"],
471
+ children: ["heading", "connection", "contract", "calls", "views", "superseded", "failure", "timeline"],
263
472
  },
264
473
  heading: { type: "Text", props: { text: "Runic", variant: "heading" } },
265
474
  ...section("connection", "Connection", {
@@ -270,9 +479,10 @@ function createDevtoolsSpec(current) {
270
479
  Version: current.contract.version || "not reported",
271
480
  Fingerprint: current.contract.fingerprint || "not reported",
272
481
  }),
482
+ ...callsSection(current, map),
273
483
  ...viewsSection(current),
274
484
  ...section("superseded", "Superseded commands", supersededCommands(current)),
275
- ...section("failure", "Last failure", lastFailure(current)),
485
+ ...failureSection(current, map),
276
486
  ...section("timeline", "Recent timeline", current.timeline.length === 0
277
487
  ? { Events: "none" }
278
488
  : Object.fromEntries(current.timeline.slice(-12).reverse().map((entry) => [
@@ -314,15 +524,20 @@ function supersededCommands(current) {
314
524
  `${entry.detail.route ?? "?"}.${entry.detail.member ?? "?"} from epoch ${entry.detail.epoch ?? "?"}`,
315
525
  ]));
316
526
  }
317
- function lastFailure(current) {
527
+ // The last failure, with an open button for each of its frames in a file of the source map.
528
+ function failureSection(current, map) {
318
529
  const entry = [...current.timeline].reverse().find((candidate) => candidate.failure !== undefined);
319
- if (!entry?.failure)
320
- return { Failure: "none" };
321
- return {
530
+ const data = !entry?.failure ? { Failure: "none" } : {
322
531
  Event: `${entry.id} · ${entry.source} · ${entry.timestamp}`,
323
532
  Label: entry.label,
324
533
  Type: entry.failure.type,
325
534
  Message: entry.failure.message,
326
535
  ...(entry.failure.stack ? { Stack: entry.failure.stack } : {}),
327
536
  };
537
+ const [frames, elements] = stackElements("failure", entry?.failure?.stack, map);
538
+ return {
539
+ failure: { type: "Card", props: { title: "Last failure" }, children: ["failure-data", ...frames] },
540
+ "failure-data": { type: "KeyValueTable", props: { data } },
541
+ ...elements,
542
+ };
328
543
  }