Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: show the full URL while a web fetch waits for approval (#11694)
Wasim Yousef Said46a468d57550
diff --git a/studio/frontend/src/components/assistant-ui/tool-ui-web-search.tsx b/studio/frontend/src/components/assistant-ui/tool-ui-web-search.tsxindex e57d6c91189..004893a2c1c 100644--- a/studio/frontend/src/components/assistant-ui/tool-ui-web-search.tsx+++ b/studio/frontend/src/components/assistant-ui/tool-ui-web-search.tsx@@ -13,9 +13,11 @@ import {isSearchImagesToolResult,useToolAwaitingApproval,} from "@/features/chat";+import { escapeBidiControls } from "@/lib/escape-bidi-controls";import { openLink } from "@/lib/open-link";import { stringifyToolResult } from "@/lib/strip-ansi";import { memo } from "react";+import { ScrollPane } from "./scroll-pane";import { SearchImageThumb } from "./search-image";import { Source, SourceIcon, SourceTitle } from "./sources";import {@@ -29,7 +31,6 @@ import {ToolFallbackTrigger,} from "./tool-fallback";import { useToolActivityOpen } from "./use-tool-activity-open";-import { ScrollPane } from "./scroll-pane";interface ParsedSource {title: string;@@ -188,6 +189,26 @@ const WebSearchToolUIImpl: ToolCallMessagePartComponent = ({icon={GlobeIcon}/><ToolFallbackContent>+ {/* The trigger shows only the host; Allow/Deny needs the full url. Inert text: untrusted. */}+ {isRunning && url ? (+ <div+ data-slot="tool-web-fetch-url"+ className="flex min-w-0 items-start gap-2 text-xs"+ >+ <span className="shrink-0 font-medium text-muted-foreground">+ URL:+ </span>+ {/* Capped so a huge url cannot push Allow/Deny off screen. */}+ <ScrollPane+ className="min-w-0 rounded bg-muted/50 px-2 py-1"+ scrollerClassName="max-h-24 overflow-auto whitespace-pre-wrap break-all text-foreground/85"+ >+ <code dir="ltr" className="break-all text-foreground/85">+ {escapeBidiControls(url)}+ </code>+ </ScrollPane>+ </div>+ ) : null}{isRunning ? (<div className="flex items-center text-sm text-muted-foreground"><span>diff --git a/studio/frontend/src/lib/escape-bidi-controls.ts b/studio/frontend/src/lib/escape-bidi-controls.tsnew file mode 100644index 00000000000..14590c1183d--- /dev/null+++ b/studio/frontend/src/lib/escape-bidi-controls.ts@@ -0,0 +1,13 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++const BIDI_CONTROL_RE = /[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/g;++/** Show bidi controls as `\uXXXX` so a url cannot display reordered. Display only. */+export function escapeBidiControls(value: string): string {+ return value.replace(+ BIDI_CONTROL_RE,+ (control) =>+ `\\u${(control.codePointAt(0) ?? 0).toString(16).padStart(4, "0")}`,+ );+}diff --git a/studio/frontend/tests/escape-bidi-controls.test.ts b/studio/frontend/tests/escape-bidi-controls.test.tsnew file mode 100644index 00000000000..5330b325467--- /dev/null+++ b/studio/frontend/tests/escape-bidi-controls.test.ts@@ -0,0 +1,48 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import assert from "node:assert/strict";+import test from "node:test";++import { escapeBidiControls } from "../src/lib/escape-bidi-controls.ts";++test("a right-to-left override is shown instead of obeyed", () => {+ const shown = escapeBidiControls("https://example.com/safe/\u202egpj.exe");+ assert.equal(shown, "https://example.com/safe/\\u202egpj.exe");+});++test("every bidi control is escaped, including the isolates and the marks", () => {+ for (const control of [+ "\u202a",+ "\u202b",+ "\u202c",+ "\u202d",+ "\u202e",+ "\u2066",+ "\u2067",+ "\u2068",+ "\u2069",+ "\u200e",+ "\u200f",+ "\u061c",+ ]) {+ const escaped = escapeBidiControls(`a${control}b`);+ assert.ok(+ !escaped.includes(control),+ `U+${(control.codePointAt(0) ?? 0).toString(16)} survived escaping`,+ );+ assert.match(escaped, /^a\\u[0-9a-f]{4}b$/);+ }+});++test("ordinary text and non-bidi unicode are left alone", () => {+ for (const value of [+ "https://example.com/path/to/page.html?utm_source=lambda&q=alpha%20beta#section-2",+ "",+ "example.com",+ "https://example.com/caf\u00e9/\u4e2d\u6587?q=1",+ "a\u200db",+ ]) {+ assert.equal(escapeBidiControls(value), value);+ }+});diff --git a/studio/frontend/tests/web-fetch-parked-url.test.ts b/studio/frontend/tests/web-fetch-parked-url.test.tsnew file mode 100644index 00000000000..e7fe0f483e1--- /dev/null+++ b/studio/frontend/tests/web-fetch-parked-url.test.ts@@ -0,0 +1,301 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// The running (Allow/Deny) web-fetch card must show the full url, not just the host.+// JSX cannot run here, so claims go through the TypeScript AST.++import assert from "node:assert/strict";+import test from "node:test";++import ts from "typescript";++import { readSrc } from "./helpers/kit.ts";+import { openingTag } from "./helpers/tsx-ast.ts";++const CARD_PATH = "components/assistant-ui/tool-ui-web-search.tsx";+const URL_SLOT = "tool-web-fetch-url";++const source = ts.createSourceFile(+ CARD_PATH,+ readSrc(CARD_PATH),+ ts.ScriptTarget.Latest,+ true,+ ts.ScriptKind.TSX,+);++function walk(node: ts.Node, visit: (node: ts.Node) => void): void {+ visit(node);+ node.forEachChild((child) => walk(child, visit));+}++function find<T extends ts.Node>(+ root: ts.Node,+ match: (node: ts.Node) => node is T,+): T[] {+ const hits: T[] = [];+ walk(root, (node) => {+ if (match(node)) hits.push(node);+ });+ return hits;+}++function tagsNamed(name: string): ts.JsxOpeningLikeElement[] {+ const hits: ts.JsxOpeningLikeElement[] = [];+ walk(source, (node) => {+ const opening = openingTag(node);+ if (+ opening &&+ ts.isIdentifier(opening.tagName) &&+ opening.tagName.text === name+ ) {+ hits.push(opening);+ }+ });+ return hits;+}++function attributeOf(+ opening: ts.JsxOpeningLikeElement,+ name: string,+): ts.JsxAttribute | undefined {+ return opening.attributes.properties.find(+ (property): property is ts.JsxAttribute =>+ ts.isJsxAttribute(property) && property.name.getText(source) === name,+ );+}++function dataSlotOf(opening: ts.JsxOpeningLikeElement): string | undefined {+ const initializer = attributeOf(opening, "data-slot")?.initializer;+ return initializer && ts.isStringLiteral(initializer)+ ? initializer.text+ : undefined;+}++function classNameOf(opening: ts.JsxOpeningLikeElement): string {+ return opening.attributes.properties+ .filter(+ (property): property is ts.JsxAttribute =>+ ts.isJsxAttribute(property) &&+ property.name.getText(source) === "className",+ )+ .map((attribute) => attribute.initializer?.getText(source) ?? "")+ .join(" ");+}++/** The nearest enclosing conditional, so a sibling's guard cannot satisfy the check. */+function guardCondition(node: ts.Node): ts.Expression | undefined {+ for (let parent = node.parent; parent; parent = parent.parent) {+ if (ts.isConditionalExpression(parent)) {+ return parent.condition;+ }+ }+ return undefined;+}++function slotElement(slot: string): ts.JsxElement | undefined {+ return find(+ source,+ (node): node is ts.JsxElement =>+ ts.isJsxElement(node) && dataSlotOf(node.openingElement) === slot,+ )[0];+}++function requireRow(): ts.JsxElement {+ const row = slotElement(URL_SLOT);+ assert.ok(+ row,+ `the expanded card has no ${URL_SLOT} row, so a url fetch parked on Allow/Deny still shows only the hostname it is reading`,+ );+ return row;+}++const [contentTag] = tagsNamed("ToolFallbackContent");++test("the parked web-fetch card shows the complete raw url", () => {+ const row = requireRow();++ assert.ok(+ contentTag && row.getStart(source) > contentTag.getEnd(),+ "the url must render inside the expanded content; the collapsed trigger stays hostname-only",+ );++ const guard = guardCondition(row.openingElement);+ assert.ok(+ guard,+ "the url row renders unconditionally, so the completed card would show it twice",+ );+ const condition = guard.getText(source);+ assert.match(+ condition,+ /isRunning/,+ "the row must cover the running (parked) arm, which is where the decision is made",+ );+ assert.match(+ condition,+ /url/,+ "the row must be gated on a url being present, or a plain search gains an empty URL line",+ );++ const rendered = find(row, ts.isJsxExpression).map(+ (expression) => expression.expression?.getText(source) ?? "",+ );+ assert.ok(+ rendered.some(+ (expression) =>+ expression.includes("url") && !expression.includes("safeUrl"),+ ),+ `the row must render the raw argument; it renders ${JSON.stringify(rendered)}`,+ );+});++test("the raw url is inert text that wraps inside the card", () => {+ const row = requireRow();+ const code = find(+ row,+ (node): node is ts.JsxElement =>+ ts.isJsxElement(node) &&+ ts.isIdentifier(node.openingElement.tagName) &&+ node.openingElement.tagName.text === "code",+ );+ assert.equal(+ code.length,+ 1,+ "the raw url must be rendered as one <code> element",+ );++ const dir = attributeOf(code[0].openingElement, "dir");+ assert.equal(+ dir?.initializer?.getText(source),+ '"ltr"',+ "a url must keep a stable left-to-right reading direction",+ );++ assert.match(+ classNameOf(code[0].openingElement),+ /break-all/,+ "a long url must wrap instead of clipping",+ );+ const rowClasses = [+ classNameOf(row.openingElement),+ ...find(row, ts.isJsxElement)+ .filter(+ (element) =>+ ts.isIdentifier(element.openingElement.tagName) &&+ element.openingElement.tagName.text === "ScrollPane",+ )+ .map((element) => classNameOf(element.openingElement)),+ ].join(" ");+ assert.match(+ rowClasses,+ /min-w-0/,+ "a flex item without min-w-0 refuses to shrink below its content, which clips the row",+ );++ assert.deepEqual(+ find(+ row,+ (node): node is ts.JsxElement =>+ ts.isJsxElement(node) &&+ ts.isIdentifier(node.openingElement.tagName) &&+ node.openingElement.tagName.text === "a",+ ),+ [],+ "the url row must not render an anchor: the argument is provider-controlled, and the " ++ "completed card already links the url",+ );+ assert.equal(+ attributeOf(row.openingElement, "href"),+ undefined,+ "the url row must not carry an href",+ );+});++test("a bidi control in the url is escaped before it reaches the row", () => {+ const row = requireRow();+ const rendered = find(row, ts.isJsxExpression).map(+ (expression) => expression.expression?.getText(source) ?? "",+ );+ assert.ok(+ rendered.some((expression) => expression.includes("escapeBidiControls(")),+ `the row must escape bidi controls; it renders ${JSON.stringify(rendered)}`,+ );+ const imported = find(source, (node): node is ts.ImportDeclaration =>+ ts.isImportDeclaration(node),+ ).some((declaration) =>+ declaration.getText(source).includes("escape-bidi-controls"),+ );+ assert.ok(imported, "the row must import its escape from the shared helper");+});++test("the url row is height-capped so the approval controls stay reachable", () => {+ const row = requireRow();+ const pane = find(+ row,+ (node): node is ts.JsxElement =>+ ts.isJsxElement(node) &&+ ts.isIdentifier(node.openingElement.tagName) &&+ node.openingElement.tagName.text === "ScrollPane",+ );+ assert.equal(+ pane.length,+ 1,+ "the url must sit in exactly one scroller rather than setting the card's height",+ );+ // The cap must sit on the inner scroller, not the padded wrapper, or nothing scrolls.+ const scroller =+ attributeOf(+ pane[0].openingElement,+ "scrollerClassName",+ )?.initializer?.getText(source) ?? "";+ assert.match(+ scroller,+ /max-h-/,+ "the scroller needs an explicit max height, or it still grows with the url",+ );+ assert.match(+ scroller,+ /overflow-auto/,+ "the capped pane must scroll, so the complete value stays reachable",+ );+ assert.doesNotMatch(+ classNameOf(pane[0].openingElement),+ /max-h-/,+ "a cap on the wrapper leaves the scroller at full height, so its overflow never scrolls",+ );+ assert.ok(+ pane[0].getStart(source) >= row.getStart(source) &&+ pane[0].getEnd() <= row.getEnd(),+ "the scroller must wrap the url row's content",+ );+});++test("the completed card keeps the url link that landed with #5787", () => {+ const anchors = tagsNamed("a");+ assert.equal(+ anchors.length,+ 1,+ "the card has exactly one anchor: the completed card's url link",+ );+ assert.equal(+ attributeOf(anchors[0], "href")?.initializer?.getText(source),+ "{safeUrl}",+ "the completed card's link must keep reading the scheme-checked url",+ );+ assert.ok(+ requireRow().getEnd() < anchors[0].getStart(source),+ "the parked row renders above the completed-card link, so it is not that element",+ );+});++test("the collapsed trigger does not leak the raw url", () => {+ const [trigger] = tagsNamed("ToolFallbackTrigger");+ assert.ok(trigger, "the card no longer has a trigger");+ const identifiers = new Set<string>();+ walk(trigger, (node) => {+ if (ts.isIdentifier(node)) identifiers.add(node.text);+ });+ assert.ok(+ !identifiers.has("url"),+ `the trigger must stay hostname-only; it reads ${JSON.stringify([...identifiers])}`,+ );+});