feat(dev): add Agent Inspector HTTP layer (server, security, assets) - #2082
Conversation
e59cda5 to
1b3491b
Compare
1b3491b to
f84a91f
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## refactor #2082 +/- ##
============================================
- Coverage 97.42% 97.41% -0.02%
============================================
Files 429 434 +5
Lines 26314 26558 +244
============================================
+ Hits 25637 25871 +234
- Misses 677 687 +10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
f84a91f to
ac74941
Compare
ac74941 to
a0dd0f6
Compare
a0dd0f6 to
defd2b1
Compare
|
Claude Security Review: no high-confidence findings. (run) |
| import { dirname } from "node:path"; | ||
|
|
||
| /** Read a file's raw bytes, or undefined when it is absent or unreadable. */ | ||
| export async function readOptionalBytes(path: string): Promise<Uint8Array | undefined> { |
There was a problem hiding this comment.
Is this helper necessary? Looking at where it's used, it doesn't seem to be reducing complexity or cognitive load? In other words, the code above would be just as easy to follow, or even easier, without this little helper.
AlexanderRichey
left a comment
There was a problem hiding this comment.
Primarily copy/pasting stuff as is, right?
Yep, split up into smaller chunks to make it easier to read |
Port the reference WebUIServer as a pure request to response handler the dev command composes with io/startHttpServer. This lands the HTTP contract and SPA delivery only; agent-proxy routes (invocations, MCP, A2A, resources) and the CLI wiring follow in later PRs. - security: loopback-only Host check (incl. IPv6 [::1]), server-side origin allowlist, X-Agentcore-Local on POSTs, CORS preflight, CSP on served HTML - routes: GET /api/status, POST /api/start, GET /api/traces[/:id], static SPA with index.html fallback, graceful JSON 404 for everything else - exact-match trace routing with decodeURIComponent :id extraction - InspectorAssets reads the staged SPA through AssetSource with an AGENT_INSPECTOR_PATH override and node_modules fallback; raw filesystem and package resolution live in src/io/packagedAssets, keeping node:fs/node:module out of core/dev - build stages @aws/agent-inspector/dist-assets into the asset tree before bundle and compile
- serve static assets over a zero-copy Buffer view of the cached bytes - hoist the constant CORS headers to module scope; the per-request origin pick reduces to origin || primary now that the guard runs first - drop the single-use InspectorAssetReader alias; inline read's signature - hoist the asset TextEncoder to module scope
defd2b1 to
31df625
Compare
|
Claude Security Review: no high-confidence findings. (run) |
What
First of three stacked PRs re-authoring the Agent Inspector from
feat/agent-inspectoragainst currentrefactorAPIs. This one lands the HTTP contract and SPA delivery only — a pure request to response handler the dev command will compose withio/startHttpServer. It is not yet reachable from the CLI.Stacked on #2041 (
feat/dev-supervisor); retarget torefactoronce that merges.Scope
src/core/dev/inspector/{types,respond,server,testkit}.ts— DI interfaces (InspectorSupervisor,InspectorTraces,InspectorAssets,InspectorDeps), response helpers, andcreateInspectorHandler.src/core/dev/inspectorAssets.ts— reads the staged SPA throughAssetSourcewith anAGENT_INSPECTOR_PATHoverride and a node_modules fallback.src/io/packagedAssets.ts— raw file reads and package-dir resolution, sonode:fs/node:modulestay out ofcore/dev.scripts/build.ts—stageInspectorAssets()copies@aws/agent-inspector/dist-assetsinto the asset tree before bundle and compile.Routes registered this PR:
GET /api/status,POST /api/start,GET /api/traces,GET /api/traces/:id, static SPA (withindex.htmlfallback), and a graceful{ success:false, error }404 for everything else. Agent-proxy routes (invocations, MCP, A2A, resources) and the CLI wiring land in the following PRs, so no stub routes appear here.Security model
Loopback-only Host check (accepts
localhost,127.0.0.1,[::1]), server-side Origin allowlist (plus the Vite:5173dev origins),X-Agentcore-Localrequired on POSTs, CORS preflight, and a CSP on served HTML.Design notes vs the reference branch
/api/tracesfor the list route andslice+decodeURIComponentfor:id, so/api/tracesXYZno longer matches the list route and encoded ids decode. Covered by tests.src/io/packagedAssets.ts;inspectorAssets.tsno longer importsnode:fs/node:module.TraceStore.list's existinglimitcontract, since each summary carries full spans/logs.test.each.Verification
bun test src/core/dev/inspector+inspectorAssets.test.ts— 26 pass.bun test(1812 pass),bun run typecheck,bun run lint:check,bun run format:checkall green.bun run buildstages the four SPA files intosrc/assets/agent-inspector/(gitignored) and mirrors them intodist/assets/.