@tsplc/tmp-debug 0.0.0-stage → 0.6.3

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 (78) hide show
  1. package/README.md +38 -2
  2. package/dist/api.js +744 -0
  3. package/dist/api.js.map +12 -0
  4. package/dist/constant.js +33 -0
  5. package/dist/constant.js.map +10 -0
  6. package/dist/explain-file.js +468 -0
  7. package/dist/explain-file.js.map +11 -0
  8. package/dist/explain.js +1310 -0
  9. package/dist/explain.js.map +19 -0
  10. package/dist/format.js +214 -0
  11. package/dist/format.js.map +12 -0
  12. package/dist/index.js +4066 -0
  13. package/dist/index.js.map +44 -0
  14. package/dist/manifest.js +240 -0
  15. package/dist/manifest.js.map +10 -0
  16. package/dist/paths.js +242 -0
  17. package/dist/paths.js.map +10 -0
  18. package/package.json +72 -4
  19. package/src/adapter.ts +77 -0
  20. package/src/api.ts +446 -0
  21. package/src/app-server.ts +151 -0
  22. package/src/build-files.ts +46 -0
  23. package/src/constant.ts +41 -0
  24. package/src/debugger.ts +237 -0
  25. package/src/errors.ts +13 -0
  26. package/src/explain-expressions.ts +484 -0
  27. package/src/explain-file.ts +325 -0
  28. package/src/explain-frames.ts +155 -0
  29. package/src/explain-loops.ts +151 -0
  30. package/src/explain-operations.ts +232 -0
  31. package/src/explain-tables.ts +345 -0
  32. package/src/explain-value.ts +203 -0
  33. package/src/explain-verdicts.ts +548 -0
  34. package/src/explain.ts +82 -0
  35. package/src/hardware.ts +159 -0
  36. package/src/http.ts +218 -0
  37. package/src/index.ts +44 -0
  38. package/src/jobs.ts +139 -0
  39. package/src/login-value.ts +165 -0
  40. package/src/login.ts +315 -0
  41. package/src/manifest.ts +328 -0
  42. package/src/opcua.ts +80 -0
  43. package/src/paths.ts +363 -0
  44. package/src/requests.ts +99 -0
  45. package/src/server-cursor.ts +22 -0
  46. package/src/shown.ts +229 -0
  47. package/src/telemetry.ts +125 -0
  48. package/src/timeline.ts +148 -0
  49. package/src/trace.ts +62 -0
  50. package/src/ui/bits.ts +48 -0
  51. package/src/ui/client.ts +87 -0
  52. package/src/ui/dom.ts +61 -0
  53. package/src/ui/explain-read.ts +105 -0
  54. package/src/ui/format.ts +261 -0
  55. package/src/ui/hardware.ts +425 -0
  56. package/src/ui/header.ts +207 -0
  57. package/src/ui/health.ts +64 -0
  58. package/src/ui/index.ts +27 -0
  59. package/src/ui/jobs.ts +263 -0
  60. package/src/ui/links.ts +59 -0
  61. package/src/ui/live-value.ts +85 -0
  62. package/src/ui/main.ts +76 -0
  63. package/src/ui/overview.ts +178 -0
  64. package/src/ui/page.ts +286 -0
  65. package/src/ui/pages.ts +64 -0
  66. package/src/ui/recent-window.ts +49 -0
  67. package/src/ui/recent.ts +355 -0
  68. package/src/ui/request-trace.ts +38 -0
  69. package/src/ui/requests.ts +80 -0
  70. package/src/ui/routes.ts +98 -0
  71. package/src/ui/store.ts +295 -0
  72. package/src/ui/success-cache.ts +11 -0
  73. package/src/ui/tree.ts +162 -0
  74. package/src/ui/variables.ts +597 -0
  75. package/src/ui/why-watch.ts +11 -0
  76. package/src/ui/why.ts +694 -0
  77. package/src/values.ts +170 -0
  78. package/src/watch.ts +32 -0
@@ -0,0 +1,159 @@
1
+ import type { Quality } from "@tsplc/opcua/contract";
2
+ import {
3
+ scalarRead,
4
+ type TargetRead,
5
+ type TargetSample,
6
+ worstQuality,
7
+ } from "./adapter";
8
+ import type { DeviceState } from "./api";
9
+ import type { DebugDevice, DebugIo, DebugType } from "./manifest";
10
+
11
+ /** Driver state names that mean the connection isn't working. */
12
+ const faultyState = /error|fault|fail|timeout|lost|closed/i;
13
+
14
+ /** What a device's health is read from: the driver's own state, when the build names it. */
15
+ export const healthReads = (device: DebugDevice): TargetRead[] => {
16
+ const { state, states, diagnostic, message } = device.health ?? {};
17
+ return [
18
+ // The driver's state is an enum, which the login names, whether or not the manifest lists its members.
19
+ ...(state
20
+ ? [
21
+ {
22
+ target: state,
23
+ type: {
24
+ kind: "enum" as const,
25
+ name: "state",
26
+ members: states ?? {},
27
+ },
28
+ },
29
+ ]
30
+ : []),
31
+ ...(diagnostic ? [scalarRead(diagnostic, "BOOL")] : []),
32
+ ...(message ? [scalarRead(message, "STRING")] : []),
33
+ ];
34
+ };
35
+
36
+ /** Everything a device's page shows: its health, raw assembly bytes, bound channels and status symbols. */
37
+ export const deviceReads = (
38
+ device: DebugDevice,
39
+ io: readonly DebugIo[],
40
+ typeOf: (id: string) => DebugType,
41
+ ): TargetRead[] => [
42
+ ...healthReads(device),
43
+ ...device.assemblies.flatMap(({ raw, bytes }) =>
44
+ raw
45
+ ? [
46
+ {
47
+ target: raw,
48
+ type: {
49
+ kind: "array" as const,
50
+ element: "BYTE",
51
+ length: bytes,
52
+ lower: 0,
53
+ },
54
+ },
55
+ ]
56
+ : [],
57
+ ),
58
+ ...io
59
+ .filter((binding) => binding.device === device.id)
60
+ .map(({ target, type }) => ({ target, type: typeOf(type) })),
61
+ // Hand-configured status symbols have no type in the manifest; they show as read.
62
+ ...Object.values(device.status ?? {}).map((target) =>
63
+ scalarRead(target, "ANY"),
64
+ ),
65
+ ];
66
+
67
+ /** A reading that is no longer good says nothing current, fault or not. */
68
+ const healthState = (quality: Quality, faulted: boolean) => {
69
+ if (quality !== "good") {
70
+ return "stale";
71
+ }
72
+ return faulted ? "fault" : "ok";
73
+ };
74
+
75
+ const health = (
76
+ device: DebugDevice,
77
+ value: (target: string) => TargetSample | undefined,
78
+ ): DeviceState["health"] => {
79
+ const { state, states, diagnostic, message } = device.health ?? {};
80
+ if (!state && !diagnostic) {
81
+ return { state: "unknown", quality: "unavailable" };
82
+ }
83
+ const stateSample = state ? value(state) : undefined;
84
+ const diagnosticSample = diagnostic ? value(diagnostic) : undefined;
85
+ const messageSample = message ? value(message) : undefined;
86
+ const quality = worstQuality([
87
+ ...(state ? [stateSample] : []),
88
+ ...(diagnostic ? [diagnosticSample] : []),
89
+ ]);
90
+ const number =
91
+ typeof stateSample?.value === "number" ? stateSample.value : undefined;
92
+ // The login names enum members the manifest may not list.
93
+ const name =
94
+ Object.entries(states ?? {}).find(([, member]) => member === number)?.[0] ??
95
+ (typeof stateSample?.value === "string" ? stateSample.value : undefined);
96
+ const faulted =
97
+ diagnosticSample?.value === true ||
98
+ (name !== undefined && faultyState.test(name));
99
+ return {
100
+ state: healthState(quality, faulted),
101
+ ...(number !== undefined && { value: number }),
102
+ ...(name && { name }),
103
+ ...(typeof diagnosticSample?.value === "boolean" && {
104
+ diagnostic: diagnosticSample.value,
105
+ }),
106
+ ...(typeof messageSample?.value === "string" && {
107
+ message: messageSample.value,
108
+ }),
109
+ quality,
110
+ };
111
+ };
112
+
113
+ const reading = (sample: TargetSample | undefined) => ({
114
+ value: sample?.value ?? null,
115
+ quality: sample?.quality ?? "unavailable",
116
+ });
117
+
118
+ /**
119
+ * A device's driver health, raw assembly bytes, bound channel values and status symbols. Health
120
+ * is "unknown" unless the manifest names the driver's own state.
121
+ */
122
+ export const deviceState = (
123
+ device: DebugDevice,
124
+ io: readonly DebugIo[],
125
+ value: (target: string) => TargetSample | undefined,
126
+ ): DeviceState => ({
127
+ id: device.id,
128
+ health: health(device, value),
129
+ assemblies: device.assemblies.map(({ direction, address, raw }) => {
130
+ const sample = raw ? value(raw) : undefined;
131
+ return {
132
+ direction,
133
+ ...(address && { address }),
134
+ bytes:
135
+ Array.isArray(sample?.value) &&
136
+ sample.value.every((byte): byte is number => typeof byte === "number")
137
+ ? sample.value
138
+ : null,
139
+ quality: sample?.quality ?? "unavailable",
140
+ };
141
+ }),
142
+ channels: io.flatMap((binding) =>
143
+ binding.device === device.id && binding.channel
144
+ ? [
145
+ {
146
+ id: binding.channel,
147
+ path: binding.path,
148
+ ...reading(value(binding.target)),
149
+ },
150
+ ]
151
+ : [],
152
+ ),
153
+ status: Object.fromEntries(
154
+ Object.entries(device.status ?? {}).map(([label, target]) => [
155
+ label,
156
+ reading(value(target)),
157
+ ]),
158
+ ),
159
+ });
package/src/http.ts ADDED
@@ -0,0 +1,218 @@
1
+ import { z } from "zod";
2
+ import {
3
+ type ErrorBody,
4
+ type Interest,
5
+ type StreamEvent,
6
+ watchGroupsSchema,
7
+ } from "./api";
8
+ import type { Debugger } from "./debugger";
9
+ import { DebugError } from "./errors";
10
+ import { TooManyMatches } from "./paths";
11
+ import { isTimelineCursor, type TimelineQuery } from "./timeline";
12
+ import { loadUi } from "./ui/index";
13
+
14
+ /** Comments keep proxies and Bun's idle timeout from closing a quiet stream. */
15
+ const heartbeatMs = 5000;
16
+ const encoder = new TextEncoder();
17
+
18
+ const json = (body: unknown, status = 200) =>
19
+ Response.json(body, { status, headers: { "Cache-Control": "no-store" } });
20
+
21
+ const failure = (error: string, status: number) =>
22
+ json({ error } satisfies ErrorBody, status);
23
+
24
+ const list = (value: string | null) =>
25
+ (value ?? "")
26
+ .split(",")
27
+ .map((item) => item.trim())
28
+ .filter(Boolean);
29
+
30
+ /** What a stream's page shows, from its query. */
31
+ const interest = (search: URLSearchParams): Interest => {
32
+ const jobs = list(search.get("jobs")).map(Number);
33
+ if (!jobs.every(Number.isInteger)) {
34
+ throw new DebugError("jobs must be job ids", 400);
35
+ }
36
+ const slots = list(search.get("slots")).map(Number);
37
+ if (!slots.every(Number.isInteger)) {
38
+ throw new DebugError("slots must be writer indexes", 400);
39
+ }
40
+ return {
41
+ watch: list(search.get("watch")),
42
+ jobs,
43
+ health: list(search.get("health")),
44
+ devices: list(search.get("devices")),
45
+ clocks: list(search.get("clocks")),
46
+ slots,
47
+ };
48
+ };
49
+
50
+ /** Where `GET /api/timeline` resumes, from its query. */
51
+ const timelineQuery = (search: URLSearchParams): TimelineQuery => {
52
+ const after = search.get("after");
53
+ if (after === null) {
54
+ const since = search.get("since");
55
+ return since === null ? {} : { since };
56
+ }
57
+ if (!isTimelineCursor(after)) {
58
+ throw new DebugError("after must be a timeline cursor", 400);
59
+ }
60
+ return { after };
61
+ };
62
+
63
+ /** The path `GET /api/explain` explains, from its query. */
64
+ const explainedPath = (search: URLSearchParams) => {
65
+ const path = search.get("path");
66
+ if (!path) {
67
+ throw new DebugError("path must name the path to explain", 400);
68
+ }
69
+ return path;
70
+ };
71
+
72
+ /** Every stream event, plus samples of the watched paths and states of the shown jobs and devices. */
73
+ const stream = (
74
+ debug: Debugger,
75
+ { watch, clocks, slots, ...shown }: Interest,
76
+ ) => {
77
+ // Refuse a watch that matches too much before the stream starts.
78
+ debug.paths.expand(watch);
79
+ let stop = () => {};
80
+ return new Response(
81
+ new ReadableStream<Uint8Array>({
82
+ start: (controller) => {
83
+ let open = true;
84
+ const write = (text: string) => {
85
+ if (open) {
86
+ controller.enqueue(encoder.encode(text));
87
+ }
88
+ };
89
+ const send = ({ name, data }: StreamEvent) =>
90
+ write(`event: ${name}\ndata: ${JSON.stringify(data)}\n\n`);
91
+ send({ name: "session", data: debug.session() });
92
+ const unsubscribe = debug.subscribe(send);
93
+ const unwatch = debug.watch(
94
+ watch,
95
+ (sample) => send({ name: "sample", data: sample }),
96
+ { clocks, slots },
97
+ );
98
+ const unshow = debug.show(shown);
99
+ const heartbeat = setInterval(
100
+ () => write(": keepalive\n\n"),
101
+ heartbeatMs,
102
+ );
103
+ stop = () => {
104
+ open = false;
105
+ clearInterval(heartbeat);
106
+ unsubscribe();
107
+ unwatch();
108
+ unshow();
109
+ };
110
+ },
111
+ cancel: () => stop(),
112
+ }),
113
+ {
114
+ headers: {
115
+ "Content-Type": "text/event-stream",
116
+ "Cache-Control": "no-store",
117
+ },
118
+ },
119
+ );
120
+ };
121
+
122
+ /**
123
+ * The debugger's routes, with `route` the request's path below where
124
+ * the host mounts them. There is no route that writes to the controller; hosts authenticate.
125
+ */
126
+ export const createDebugHandler =
127
+ (debug: Debugger, log: (message: string) => void) =>
128
+ async (request: Request, route: string): Promise<Response> => {
129
+ const { searchParams } = new URL(request.url);
130
+ const key = `${request.method} ${route}`;
131
+ try {
132
+ switch (key) {
133
+ case "GET /":
134
+ return new Response((await loadUi()).html, {
135
+ headers: { "Content-Type": "text/html; charset=utf-8" },
136
+ });
137
+ case "GET /ui.js":
138
+ return new Response((await loadUi()).script, {
139
+ headers: { "Content-Type": "text/javascript; charset=utf-8" },
140
+ });
141
+ case "GET /api/session":
142
+ return json(debug.session());
143
+ case "GET /api/manifest":
144
+ return json(debug.manifest);
145
+ case "GET /api/stream":
146
+ return stream(debug, interest(searchParams));
147
+ case "GET /api/values":
148
+ return json(await debug.values(list(searchParams.get("paths"))));
149
+ case "GET /api/jobs":
150
+ return json(debug.jobs());
151
+ case "GET /api/hardware":
152
+ return json(debug.hardware());
153
+ case "GET /api/timeline":
154
+ return json(debug.timeline(timelineQuery(searchParams)));
155
+ case "GET /api/watch":
156
+ return json(debug.watchGroups());
157
+ case "GET /api/explain":
158
+ return json(debug.explain(explainedPath(searchParams)));
159
+ case "GET /api/explain-file": {
160
+ const loaded = debug.explanationFile();
161
+ // The digest names the content, so a client keeps the file until the build changes.
162
+ return new Response(loaded.text, {
163
+ headers: {
164
+ "Content-Type": "application/json",
165
+ ETag: `"${loaded.sha256}"`,
166
+ "Cache-Control": "private, max-age=31536000, immutable",
167
+ },
168
+ });
169
+ }
170
+ case "GET /api/forced":
171
+ return json(await debug.forced());
172
+ case "PUT /api/watch":
173
+ return json(
174
+ await debug.saveWatchGroups(
175
+ watchGroupsSchema.parse(await request.json()),
176
+ ),
177
+ );
178
+ }
179
+ return failure(`No route ${key}`, 404);
180
+ } catch (error) {
181
+ if (error instanceof DebugError) {
182
+ return failure(error.message, error.status);
183
+ }
184
+ // SyntaxError: a body isn't JSON.
185
+ if (error instanceof TooManyMatches || error instanceof SyntaxError) {
186
+ return failure(error.message, 400);
187
+ }
188
+ if (error instanceof z.ZodError) {
189
+ return failure(z.prettifyError(error), 400);
190
+ }
191
+ log(
192
+ `${key} failed: ${error instanceof Error ? error.stack : String(error)}`,
193
+ );
194
+ return failure("The debugger failed; see its log", 500);
195
+ }
196
+ };
197
+
198
+ /**
199
+ * Serves the debugger on 127.0.0.1 without a token. Requests that name another host are refused,
200
+ * so no website can reach it by rebinding a domain name to 127.0.0.1.
201
+ */
202
+ export const serveDebugger = (
203
+ debug: Debugger,
204
+ options: { port: number; log: (message: string) => void },
205
+ ) => {
206
+ const handle = createDebugHandler(debug, options.log);
207
+ return Bun.serve({
208
+ hostname: "127.0.0.1",
209
+ port: options.port,
210
+ fetch: (request) => {
211
+ const host = request.headers.get("host")?.replace(/:\d+$/, "");
212
+ if (host !== "127.0.0.1" && host !== "localhost") {
213
+ return failure("Use http://127.0.0.1 or http://localhost", 403);
214
+ }
215
+ return handle(request, new URL(request.url).pathname);
216
+ },
217
+ });
218
+ };
package/src/index.ts ADDED
@@ -0,0 +1,44 @@
1
+ export type { Quality } from "@tsplc/opcua/contract";
2
+ export type {
3
+ Connection,
4
+ TargetAdapter,
5
+ TargetRead,
6
+ TargetSample,
7
+ } from "./adapter";
8
+ export type {
9
+ ApiResponses,
10
+ AppRecord,
11
+ ConnectionState,
12
+ DeviceState,
13
+ Interest,
14
+ JobState,
15
+ RequestTrace,
16
+ Sample,
17
+ Session,
18
+ StreamEvents,
19
+ TimelineEntry,
20
+ TraceEvent,
21
+ WatchGroups,
22
+ } from "./api";
23
+ export { loadDebugBuild, loadExplanations, loadManifest } from "./build-files";
24
+ export {
25
+ createDebugger,
26
+ type Debugger,
27
+ type DebuggerOptions,
28
+ } from "./debugger";
29
+ export { DebugError } from "./errors";
30
+ export { createDebugHandler, serveDebugger } from "./http";
31
+ export {
32
+ createLoginAdapter,
33
+ LoginUnavailable,
34
+ loginReader,
35
+ noLogin,
36
+ } from "./login";
37
+ export { createOpcUaAdapter, opcUaConnection } from "./opcua";
38
+ export {
39
+ createPaths,
40
+ type PathNode,
41
+ type Paths,
42
+ type ResolvedPath,
43
+ } from "./paths";
44
+ export { timelineEntries } from "./timeline";
package/src/jobs.ts ADDED
@@ -0,0 +1,139 @@
1
+ import { scalarRead, type TargetRead, type TargetSample } from "./adapter";
2
+ import type { JobState, Session } from "./api";
3
+ import {
4
+ type DebugJob,
5
+ instrumentationFields,
6
+ jobStateFields,
7
+ } from "./manifest";
8
+ import type { ServiceCallLookup } from "./requests";
9
+
10
+ /** What the trace said of a job: whether it is running, and when it last started. */
11
+ export interface TracedJob {
12
+ busy: boolean;
13
+ startedAt?: string;
14
+ }
15
+
16
+ const stateRead = (job: DebugJob, field: keyof typeof jobStateFields) =>
17
+ scalarRead(`${job.target}.${field}`, jobStateFields[field]);
18
+
19
+ /** The job's `busy` flag, read while a page shows the job and the trace says nothing of it. */
20
+ export const busyRead = (job: DebugJob) => stateRead(job, "busy");
21
+
22
+ /** What a busy job shows: where it waits, since when, and its latest request. */
23
+ export const detailReads = (job: DebugJob): TargetRead[] => [
24
+ stateRead(job, "step"),
25
+ stateRead(job, "cancelling"),
26
+ ...(job.startedAt
27
+ ? [scalarRead(job.startedAt, instrumentationFields.startedAt)]
28
+ : []),
29
+ ...job.requests.map(({ sequence }) =>
30
+ scalarRead(sequence, instrumentationFields.sequence),
31
+ ),
32
+ ];
33
+
34
+ const busyFrom = (
35
+ read: TargetSample | undefined,
36
+ traced: TracedJob | undefined,
37
+ ) => (read?.quality === "good" ? read.value === true : (traced?.busy ?? null));
38
+
39
+ /**
40
+ * From the last read, else from the trace; null when neither knows. A read wins: a job's caller
41
+ * stops running it once it finishes, so the trace can miss the finish.
42
+ */
43
+ export const busyOf = (
44
+ job: DebugJob,
45
+ value: (target: string) => TargetSample | undefined,
46
+ traced: TracedJob | undefined,
47
+ ) => busyFrom(value(busyRead(job).target), traced);
48
+
49
+ const numberOf = (sample: TargetSample | undefined) =>
50
+ sample?.quality === "good" && typeof sample.value === "number"
51
+ ? sample.value
52
+ : undefined;
53
+
54
+ /**
55
+ * A job as the debugger shows it at host time `now`. Details are shown only while it is busy;
56
+ * its last start stays, so a later run tells a failure apart from the current state. Without a
57
+ * clock estimate there is no start time from the PLC's own `startedAt`.
58
+ */
59
+ export const jobState = (
60
+ job: DebugJob,
61
+ inputs: {
62
+ value: (target: string) => TargetSample | undefined;
63
+ traced: TracedJob | undefined;
64
+ failure: JobState["failure"];
65
+ /** Busy, but its details aren't read for want of room in the poll. */
66
+ unread: boolean;
67
+ clock: Session["clock"];
68
+ now: number;
69
+ request: ServiceCallLookup;
70
+ },
71
+ ): JobState => {
72
+ const { value, traced, clock, now } = inputs;
73
+ const busySample = value(busyRead(job).target);
74
+ const busy = busyFrom(busySample, traced);
75
+ const startedPlc =
76
+ job.startedAt === undefined ? undefined : numberOf(value(job.startedAt));
77
+ const startedAt =
78
+ traced?.startedAt ??
79
+ (clock && startedPlc !== undefined
80
+ ? new Date(startedPlc - clock.offsetMs).toISOString()
81
+ : undefined);
82
+ const base: JobState = {
83
+ id: job.id,
84
+ quality: busySample?.quality ?? (traced ? "good" : "unavailable"),
85
+ busy,
86
+ ...(startedAt && { startedAt }),
87
+ ...(inputs.failure && { failure: inputs.failure }),
88
+ };
89
+ if (!busy) {
90
+ return base;
91
+ }
92
+ if (inputs.unread) {
93
+ return { ...base, unread: true };
94
+ }
95
+
96
+ const step = numberOf(value(stateRead(job, "step").target));
97
+ const current = job.steps.find((candidate) => candidate.step === step);
98
+ // Each call site counts its own requests, so the latest is the one the server saw start last,
99
+ // or the one counted furthest while the server has yet to report them.
100
+ const calls = job.requests
101
+ .map((call) => {
102
+ const sequence = numberOf(value(call.sequence)) ?? 0;
103
+ const trace = inputs.request({
104
+ job: call.job ?? job.id,
105
+ service: call.service,
106
+ sequence,
107
+ });
108
+ return { service: call.service, sequence, trace };
109
+ })
110
+ .filter(({ sequence }) => sequence > 0);
111
+ const later = (call: (typeof calls)[number], than: (typeof calls)[number]) =>
112
+ call.trace && than.trace
113
+ ? call.trace.startedAt > than.trace.startedAt
114
+ : call.sequence > than.sequence;
115
+ const latest = calls.reduce<(typeof calls)[number] | undefined>(
116
+ (latest, call) => (latest && !later(call, latest) ? latest : call),
117
+ undefined,
118
+ );
119
+ const cancelling = value(stateRead(job, "cancelling").target);
120
+
121
+ return {
122
+ ...base,
123
+ ...(cancelling?.quality === "good" && {
124
+ cancelling: cancelling.value === true,
125
+ }),
126
+ ...(step !== undefined && { step }),
127
+ ...(current && {
128
+ current: { kind: current.kind, range: current.range, text: current.text },
129
+ }),
130
+ ...(startedAt && { elapsedMs: Math.max(0, now - Date.parse(startedAt)) }),
131
+ ...(latest && {
132
+ request: {
133
+ service: latest.service,
134
+ sequence: latest.sequence,
135
+ ...(latest.trace && { trace: latest.trace }),
136
+ },
137
+ }),
138
+ };
139
+ };