Skip to content

What is the devtools panel?

View as Markdown

The devtools panel is Studio’s view of one conversation, drawn in a corner of your own app’s page. One script tag loads it from Studio’s /panel.js. It shows the turns of the conversation the page is having, each step’s story with its tool calls, usage and timing, and a live tail of the running turn. It reads Studio’s API, so it needs a Studio to talk to and records nothing itself.

<script type="module" src="/studio/panel.js" data-weft></script>

That tag is the whole install for a Go app that embeds Studio at /studio/ (setup A). Install the devtools panel covers the other setups and the npm package.

The weft devtools panel docked on the right of an app page, its Story tab showing a step's tool calls and their errorsThe weft devtools panel docked on the right of an app page, its Story tab showing a step's tool calls and their errors
The panel docked on the right of an app's page, on its story tab.

The panel is one custom element, <weft-devtools>, which draws itself inside its own shadow DOM. Your page’s CSS does not reach it, and its CSS does not reach your page. The element is defined by one ES module, panel.js, which Studio’s handler serves at <base>/panel.js with no token. The file is embedded in the studio package, so a Studio of version X serves the panel of version X. The same bytes ship in the npm package @weftgo/devtools, for apps that bundle their JavaScript instead of loading script tags.

When the module loads, it does four things in order:

  1. It defines <weft-devtools>, so markup already in the page upgrades.
  2. It watches window.__WEFT__, the global a single-page app sets to switch conversations.
  3. It reads its configuration: <meta name="weft:…"> tags and its own script tag.
  4. It mounts the dock, unless the page has its own <weft-devtools> or the tag says data-auto="false".

The panel then asks Studio’s /api/meta. If no Studio answers, the dock it mounted by itself removes itself, unless you named a loopback endpoint (When the panel does not connect). Your page loses nothing when Studio is down. A Studio that refuses the token (a 401 or 403) is there, so since 0.20.0 the panel stays and says which token it wants.

Inside the panel, the open turn has four tabs:

TabWhat it shows
storyThe steps of the turn: what the model was sent and replied, each tool call and its result, the step’s attempts and timing (“attempt 4 of 4 · fallback to glm-b”, “1.2 s · first token 180 ms”), approvals, and each child run inline at any depth
requestOne step’s request: the prompt, the messages, the tool catalog and the parameters
waterfallThe run’s spans on a time axis (Timeline before 0.20.0), or its steps in event order when it has no spans
rawThe run’s JSON, as a tree you can filter and copy

A badge marks anything the recording does not hold: a truncated result, a gap, content stripped by a content-off destination. ⤢ links open the same run, at the same step, in Studio. Read a run in the panel explains each tab.

The panel follows a scope: a conversation’s public id, and optionally the session, flow and run inside it, written pub_…;session=…;flow=…;run=…. The public id is the one your app gave its thread session with thread.PublicID. Its runs carry it as weft.public_id, and the panel lists them as the conversation’s turns.

Since 0.20.0 a scope may also name a page of unrelated runs, with or without a public id. tag.<k>=<v> matches a run’s metadata pair; repeat it to require several. agent= narrows to one agent. ;tag.arena.batch=b1 is a whole scope.

The page names the scope, or the panel detects it: from data-scope on the tag, from the Weft-Scope header your chat handler sets, from a data-weft-scope attribute on the chat’s element, or from the page URL. Since 0.20.0, when nothing names a scope, a panel token’s claims become it: its public id and its tags. With none of these, the header reads no conversation detected on this page · how to scope and lists the newest runs. Scope the panel to a conversation is the whole ladder.

While a run of the conversation runs, the collapsed dock (the pill) pulses and shows the live step count, ● 3.

The panel and Studio read the same database through the same JSON API and the same live stream. They differ in how much they show and where:

AspectThe panelStudio
WhereA corner or a side of your app’s pageIts own pages, at <base>
WhatOne conversation: the scope the page namesEvery run, session and trace in the database
Finds runs byThe scope (public id, session, run)Lists, search, filters, ⌘K
ExtraReplay verbs, and deciding your app’s parked turnsThe run page, compare, cost, settings, the playground, export
Loaded by<script src=…/panel.js> or @weftgo/devtoolsstudio.Handler, weft studio or weft dev

The panel is for the developer who is using the app: ask a question in your own chat, and the turn it started is open beside it. Studio is where you go for everything else, and the panel’s ⤢ links open the same run there.

The panel adds one element and, under the script tag, one global, window.weft.devtools, its host API. data-global="off" keeps that global off; the npm package never adds it. Two of the scope rungs read your page’s DOM or its traffic:

  • The DOM-marker rung reads data-weft-scope attributes through one MutationObserver and never writes your DOM.
  • The header rung wraps window.fetch to read the Weft-Scope response header. It is on by default only when the page and Studio are both on loopback and the panel has no panel token (weft_pt.), and it is put back as found when the panel disconnects.

Neither rung reads a response body.

  • It is not a recorder. The runs it shows were recorded by your app’s pipeline (Record your runs). A run that was never recorded never appears.
  • It is not a security boundary. Studio enforces what a token may read on every route. In a page you ship, the panel carries a per-page panel token (Secure the devtools panel).
  • It needs no Go code of its own. Studio’s /panel.js and /panel-config.json routes serve it, and package scope is the optional Go side of the header rung.

The docs example docs-site/examples/devtools is a Go app that embeds Studio, serves a chat page with the script tag above, and sets the Weft-Scope header on its chat responses. Run it and open http://127.0.0.1:8080/:

Terminal window
go run ./devtools
app: http://127.0.0.1:8080/ · studio: http://127.0.0.1:8080/studio/

The dock mounts and reads no conversation detected on this page. Ask a question: the response carries Weft-Scope: pub_demo;run=…, and the panel follows that conversation and pins that turn. Install the devtools panel walks through the program.

  • Keep the panel and Studio on one version. The panel compares its version with /api/meta’s studio_version and, when Studio is newer, says Studio is newer than this panel; update panel.js. Loading /panel.js from the Studio you talk to keeps them equal. (Source: studio/web/npm/README.md:22-27; studio/web/src/panel/element.ts:4027)
  • Read the source, not the bundle. panel.js ships minified, with no sourcemap; its source is studio/web/src/panel in weft’s repository. (Source: studio/README.md:1330-1352)
  • Expect silence when Studio is down off loopback. The self-mounted dock removes itself without a line on the page. A bare tag whose guessed endpoint is on loopback logs one console line. On a loopback endpoint you named, and for a <weft-devtools> you wrote or a mount() call, it shows Studio not reachable at … · retry instead. (Source: studio/README.md:1301-1330)

Symbols used: thread.PublicID · studio.Handler