Docs / docs (push) Successful in 30s
Playwright Tests / test-playwright (1, 2) (push) Successful in 3m7s
Playwright Tests / test-playwright (2, 2) (push) Successful in 1m54s
pre-commit / pre-commit (push) Failing after 4m24s
Test Backend / test-backend (push) Successful in 3m8s
Compose Smoke Test / test-compose (push) Successful in 40s
Playwright Tests / merge-reports (push) Successful in 1m33s
A port may now declare `image`, `audio` or `video`. Each is the artifact
reference the engine already had, narrowed by the `media_type` on it, so a
speech recogniser declares what it eats rather than taking any bytes at all and
finding out. Bytes still never travel as a message and nothing on the wire
stops being JSON: a camera publishes one reference per frame, a microphone one
per chunk, and a reference may carry a `meta` dict nothing here interprets.
Streaming media is therefore an ordinary streaming port — with one change to
what that means. An emission used to journal an item with no payload, so
downstream read whatever was current when the item was claimed; a consumer
slower than its producer saw only the newest chunk and the ones between were
lost. That is right for a training curve and wrong for a second of speech, so
an emission now journals a `kind="emission"` item carrying its values, and the
executor hands them to the nodes reading that message instead of writing them
to state again. The value in state stays the latest, which is what everything
else reads, and the wave is filtered by what actually changed rather than
walking everything reachable. No queue serialization change — the existing
`outputs` field carries it.
Continuous media makes the store's missing GC a real problem, so this closes
it: `sweep_artifacts` runs hourly, keeps every digest a `run_artifact` row
records or a live message holds, spares anything written in the last hour, and
stands aside entirely while a run is in flight, since a node may store a
checkpoint long before it returns the reference to it. That also collects the
orphans a deleted flow has always left behind. `ARTIFACT_GC_INTERVAL_S=0` turns
it off.
Around the edges: `GET /artifacts/{digest}` serves the media type the caller
passes and answers ranged requests, so a browser plays a clip rather than
downloading it; `PUT` spools to disk instead of holding the whole body in
memory, as does `save_artifact` given a path; a Media widget draws whatever its
message points at, and a wall panel may fetch the bytes its own tiles are
showing and nothing else; and a connector gets `save_artifact`, for a device
whose readings are bytes.
What this cannot do is live video: a frame every second or two is a glance, and
the honest answer above that is the camera's own stream, which the widget takes
as a URL and the browser plays from source.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
134 lines
4.4 KiB
TypeScript
134 lines
4.4 KiB
TypeScript
import { ChevronRight } from "lucide-react"
|
|
import { useState } from "react"
|
|
|
|
import type { DType } from "@/client"
|
|
import { Marquee } from "@/components/Common/Marquee"
|
|
import { cn, si } from "@/lib/utils"
|
|
|
|
/**
|
|
* How much of a structured value is worth unfolding in a side panel.
|
|
*
|
|
* The cap sits on the `pre` itself rather than on a `ScrollArea`: that one
|
|
* sizes its viewport in percent, which resolves to the content's own height
|
|
* against a box that has only a maximum, so a long value spills out of the
|
|
* panel or popover and paints over whatever is below it.
|
|
*/
|
|
const MAX_HEIGHT = "max-h-48"
|
|
|
|
function count(n: number, one: string, many = `${one}s`): string {
|
|
return `${n} ${n === 1 ? one : many}`
|
|
}
|
|
|
|
/** Whether this is an artifact reference rather than data of its own. */
|
|
function isArtifact(value: Record<string, unknown>): boolean {
|
|
return typeof value.digest === "string" && value.digest.startsWith("sha256:")
|
|
}
|
|
|
|
/**
|
|
* What a structured value *is*, in the space a value would have taken.
|
|
*
|
|
* The shape is what you want while wiring — that this port carries a record of
|
|
* three fields, or a checkpoint of sixty kilobytes — and the contents are what
|
|
* you want once something looks wrong. Serialising the whole thing into a line
|
|
* answers the second question badly and the first one not at all.
|
|
*/
|
|
function summarize(value: object, dtype?: DType): string {
|
|
if (Array.isArray(value)) {
|
|
return `${dtype ?? "list"} · ${count(value.length, "item")}`
|
|
}
|
|
|
|
const record = value as Record<string, unknown>
|
|
if (isArtifact(record)) {
|
|
const name =
|
|
typeof record.name === "string" && record.name ? record.name : ""
|
|
const size = typeof record.size === "number" ? `${si(record.size)}B` : ""
|
|
// The media type when there is one: what kind of bytes these are is the
|
|
// first thing worth knowing about a frame or a clip, and it is what the
|
|
// port's own type was declared against.
|
|
const media =
|
|
typeof record.media_type === "string" &&
|
|
record.media_type &&
|
|
record.media_type !== "application/octet-stream"
|
|
? record.media_type
|
|
: "artifact"
|
|
return [media, name, size].filter(Boolean).join(" · ")
|
|
}
|
|
|
|
if (Array.isArray(record.lines)) {
|
|
const points = record.lines.reduce(
|
|
(total: number, line: unknown) =>
|
|
total +
|
|
(Array.isArray((line as { points?: unknown[] })?.points)
|
|
? ((line as { points: unknown[] }).points.length as number)
|
|
: 0),
|
|
0,
|
|
)
|
|
return `series · ${count(record.lines.length, "line")}, ${count(points, "point")}`
|
|
}
|
|
|
|
return `${dtype ?? "record"} · ${count(Object.keys(record).length, "field")}`
|
|
}
|
|
|
|
/**
|
|
* What a message is carrying: its shape at rest, its contents on request.
|
|
*
|
|
* A scalar simply reads, scrolling itself when it is longer than the room it
|
|
* was given. Anything structured shows what it is and unfolds when asked —
|
|
* which is what keeps a panel four hundred pixels wide from being pushed open
|
|
* by one checkpoint reference.
|
|
*/
|
|
export function ValuePreview({
|
|
value,
|
|
dtype,
|
|
defaultOpen = false,
|
|
className,
|
|
}: {
|
|
value: unknown
|
|
dtype?: DType
|
|
/** Start unfolded, where there is room for it — an inspector, not a row. */
|
|
defaultOpen?: boolean
|
|
className?: string
|
|
}) {
|
|
const [open, setOpen] = useState(defaultOpen)
|
|
const structured = value !== null && typeof value === "object"
|
|
|
|
if (!structured) {
|
|
return (
|
|
<Marquee
|
|
text={value === undefined ? "" : String(value)}
|
|
className={cn("block font-mono text-xs", className)}
|
|
/>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<div className={cn("min-w-0", className)}>
|
|
<button
|
|
type="button"
|
|
onClick={() => setOpen((was) => !was)}
|
|
aria-expanded={open}
|
|
className="flex w-full min-w-0 items-center gap-1 text-left text-xs text-muted-foreground transition-colors hover:text-foreground"
|
|
data-testid="value-preview-toggle"
|
|
>
|
|
<ChevronRight
|
|
className={cn(
|
|
"size-3 shrink-0 transition-transform duration-[var(--duration-fast)]",
|
|
open && "rotate-90",
|
|
)}
|
|
/>
|
|
<Marquee text={summarize(value, dtype)} className="flex-1 font-mono" />
|
|
</button>
|
|
{open ? (
|
|
<pre
|
|
className={cn(
|
|
"mt-1 overflow-auto whitespace-pre-wrap break-all font-mono text-xs",
|
|
MAX_HEIGHT,
|
|
)}
|
|
>
|
|
{JSON.stringify(value, null, 2)}
|
|
</pre>
|
|
) : null}
|
|
</div>
|
|
)
|
|
}
|