The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
chore(web-chat): align progress bridge with range utility
Steven Enamakelf9a470b25b18
diff --git a/app/src/components/assistant-ui/utils/range.ts b/app/src/components/assistant-ui/utils/range.tsnew file mode 100644index 0000000000..9ebeeb5305--- /dev/null+++ b/app/src/components/assistant-ui/utils/range.ts@@ -0,0 +1,57 @@+/**+ * Range normalization for the numeric props the elements take.+ *+ * Elements are driven by a caller's state, so a prop can arrive negative, past+ * the end of its collection, or NaN. Left raw, those reach the DOM: a negative+ * percentage is an invalid CSS width that the browser drops, leaving a bar at+ * its natural full width, and a negative slice length counts from the end of+ * the array instead of returning nothing.+ */++/**+ * Constrains a value to `min…max`. NaN is decided first and maps to `min`.+ * For any other value, an empty collection can invert the bounds and `max`+ * wins there: `clamp(3, 1, 0)` is `0`, which is what lets a floor of one item+ * still yield none.+ */+export function clamp(value: number, min: number, max: number) {+ if (Number.isNaN(value)) return min;+ return Math.min(max, Math.max(min, value));+}++/** The first `count` items, for a `count` that may be out of range. */+export function take<T>(items: readonly T[], count: number) {+ return items.slice(0, Math.floor(clamp(count, 0, items.length)));+}++/** The position `index` names in `items`, for an `index` out of range. */+export function indexIn<T>(items: readonly T[], index: number) {+ return Math.floor(clamp(index, 0, Math.max(0, items.length - 1)));+}++/** The item at `index`, for an `index` that may be out of range. */+export function at<T>(items: readonly T[], index: number) {+ if (items.length === 0) return undefined;+ return items[indexIn(items, index)];+}++/** `value` as a share of `total`, as a percentage in `0…100`. */+export function pct(value: number, total: number) {+ if (!(total > 0)) return 0;+ return clamp((value / total) * 100, 0, 100);+}++/**+ * A `0…100` share as it should be announced. `pct` divides, so a share that+ * reads as a whole number on screen can still reach `aria-valuenow` carrying+ * float error, which a screen reader reads out in full.+ */+export function announced(share: number) {+ return Math.round(share * 10) / 10;+}++/** A count of completed items out of `total`, in `0…total`. */+export function progressOf(index: number, total: number) {+ if (!(total > 0)) return 0;+ return Math.floor(clamp(index, 0, total));+}diff --git a/crates/openhuman-core/src/web_chat/progress_bridge.rs b/crates/openhuman-core/src/web_chat/progress_bridge.rsindex bfcb40e3f3..a645d872a4 100644--- a/crates/openhuman-core/src/web_chat/progress_bridge.rs+++ b/crates/openhuman-core/src/web_chat/progress_bridge.rs@@ -1164,6 +1164,11 @@ pub(crate) fn spawn_progress_bridge(// bounded size for the wire (#4007); `output_chars` +// `elapsed_ms` still ride along in `subagent` below.output: Some(cap_wire_output(output)),+ args: arguments.filter(|v| !v.is_null()),+ elapsed_ms: Some(elapsed_ms),+ structured,+ tool_display_label: display_label,+ tool_display_detail: display_detail,failure: failure_json,subagent: Some(SubagentProgressDetail {child_iteration: Some(iteration),