@djangocfg/widget-agent

中文文档
0.1.37发布于 2026/11/09MITTypeScriptES Module近 30 天下载 4634

Agent tooling: page snapshot and browser bridge, plus viewers for an OpenAPI schema, a request, a log and an environment

原始使用文档
文档目录7 节
  1. Install
  2. Import a subpath
  3. The round trip
  4. Mounting the copilot
  5. The split runs through the dependencies too
  6. Redaction is part of capture, not a step after it
  7. Testing

@djangocfg/widget-agent

What an agent needs to see an app and act on it, plus the viewers that put an API, a request, a log or an environment on screen.

Two halves with different weights:

  • Instrumentation — page-snapshot captures the page as a compact tree an LLM can read; browser-bridge takes the refs from that snapshot and lets the model point at, focus or scroll to a live element; page-copilot wires both to a chat and gates what may act on the page. No viewer, no heavy dependency, and where all 31 test suites are.
  • Viewers — surfaces for developer data. openapi alone carries a sampler, an HTTP client and a store.

Install

pnpm add @djangocfg/widget-agent

Peers: react 19, react-dom 19, @djangocfg/ui-core, lucide-react, zustand.

Import a subpath

SubpathWhat it is
./page-snapshotcapture the page as a CST, with redaction and a ref registry
./browser-bridgeresolve a ref to an element; highlight, focus, scroll
./page-copilotwrap a chat adapter so every turn carries the page, and gate the actions it proposes
./openapiOpenapiViewer, lazy — a schema browser with a request playground
./request-viewerone HTTP exchange, headers and bodies
./api-ref-tableendpoints as a table
./log-viewervirtualised log stream, lazy
./log-viewer/fullthe same, eager
./env-tableenvironment variables, with the values masked
import { PageSnapshotProvider } from '@djangocfg/widget-agent/page-snapshot';
import { HighlightOverlay } from '@djangocfg/widget-agent/browser-bridge';

The round trip

capture   page-snapshot assigns @e1, @e2, … to interactive nodes and keeps a
          ref → element registry
   ↓      snapshot travels with the request
model     may answer with a directive: point at @e4
   ↓      directive arrives on the client
bridge    resolve @e4 → element, draw the spotlight, optionally focus

Read-only by default. A point directive highlights, focuses or scrolls. It never types, clicks or changes the user's data.

fill and click do change it, so they arrive as a PROPOSAL: a data part with kind: 'ui-action' that renders as a card with Approve and Skip, and reaches the page only on Approve. The ref is re-resolved at that moment — the page moves between the agent proposing and the user reading — and every outcome (approved, rejected, stale, not-visible, expired) is reported back exactly once, because an agent with no answer re-proposes.

The two modules stay independent: browser-bridge depends on a structural RefResolver interface, not on the capture engine, so either can be used alone.

Mounting the copilot

Three hooks, and no change to the chat — it gets no new prop, no capability and no import.

const copilot = usePageCopilot(adapter);            // page rides every turn
const queue = useProposals(                          // the gate
  snapshot.sentSnapshot?.refs ?? null,               // the SENT registry
  copilot.reportResult,
);
const renderers = {
  data: createActionRenderer({ queue, fallback: DataRenderer }),
};

Two things that are silent when wrong:

  • The resolver must be sentSnapshot.refs, never the newest capture. CST refs are positional, so a later capture renumbers them and @e1 resolves to a different element than the one the agent named.
  • fallback is not optional in practice. The registry dispatches on part.type, so one renderer owns EVERY data part; registering ours without delegating blanks every media block the chat already draws.

Widgets/Agent/PageCopilot Live is this wiring, running.

The split runs through the dependencies too

@djangocfg/widget-code and @djangocfg/widget-data are reached from the viewers only — nine files, all under openapi/ and request-viewer/, for syntax highlighting, markdown and a JSON tree. Nothing in page-snapshot or browser-bridge touches them, which is what makes the instrumentation half usable in a page that renders no viewer at all.

Redaction is part of capture, not a step after it

A snapshot leaves the user's browser. page-snapshot/redaction runs during the walk — patterns, heuristics and a Luhn check for card numbers — and has its own audit suite. A value that reaches the serialiser unredacted has already left.

Testing

pnpm --filter @djangocfg/widget-agent check-types test

22 suites: the capture walk, budget, scoping and folding; CST serialisation; the ref registry and locator; staleness hashing; every redaction layer; the React provider and chip; and the overlay's ref resolution.

版本与发布记录

@djangocfg/widget-agent 共发布 33 个版本,首次发布于 2026/09/09;过去 12 个月发布了 33 个版本。

版本发布日期距今
0.1.37latest2026/11/092 天前
0.1.362026/11/092 天前
0.1.352026/11/093 天前
0.1.342026/11/083 天前
0.1.332026/11/083 天前
0.1.322026/11/084 天前

关于 @djangocfg/widget-agent 的常见问题

@djangocfg/widget-agent 是什么?

Agent tooling: page snapshot and browser bridge, plus viewers for an OpenAPI schema, a request, a log and an environment

如何安装 @djangocfg/widget-agent?

在项目目录运行 npm install @djangocfg/widget-agent,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.0.0)、zustand(^5.0.0)、react-dom(^19.0.0)、lucide-react(^1.68.0)、@djangocfg/api(^2.1.644)、@djangocfg/ui-core(^2.1.644)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@djangocfg/widget-agent 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@djangocfg/widget-agent 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@djangocfg/widget-agent 可以商用吗?

@djangocfg/widget-agent 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@djangocfg/widget-agent 的下载量有多少?

根据 npm 官方下载统计,@djangocfg/widget-agent 在 2026/10/13 – 2026/11/11 这 30 天内被下载 4,634 次,日均约 154 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@djangocfg/widget-agent 还在维护吗?

最新版本 0.1.37 发布于 2026/11/09(2 天前);至今共发布 33 个版本,其中过去 12 个月发布了 33 个;首次发布于 2026/09/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。