feat(web-core): WASM-ready broker core + browser CoreBackend + dev.sh build (W0/X0/X1/X2)#172
Merged
Merged
Conversation
First implementation slice of docs/plan/web-flow/wire-real-paths.md (merged #162): a typed, host-agnostic `agentkeys-core::broker::BrokerClient` that the daemon ui-bridge, the future WASM CoreBackend (web), and the mobile UniFFI shell all share — so the browser/phone never re-implement broker calls in TS/Swift ("consistency is structural"). Covers the master-plane endpoints the web wiring proxies: - cap-mint: /v1/cap/{memory-put,memory-get,cred-store,cred-fetch} → CapToken - pairing (§10.2 method A, master-side): /v1/agent/pairing/claim, /v1/agent/pending-bindings, /v1/agent/pending-bindings/ack Design: builds on init_flow's conventions (BrokerError{Transport,Rejected,Decode}; trim trailing slash); stores no secret (bearer passed per call); host-agnostic (no fs/clock/env) so it compiles for the wasm32 browser-fetch target — feature- gating the crate's reqwest for wasm is the separate X1 build step. The email/OAuth/SIWE auth flow already lives in init_flow and is unchanged. Tests: axum-stub server per method (cap round-trip + bearer; pairing claim; pending→ack; non-2xx → Rejected mapping). cargo test -p agentkeys-core: 145+3 ok; clippy --all-targets -D warnings clean; fmt clean. Next (separate PRs): X1 wasm-pack build + reqwest wasm feature-gate; daemon ui-bridge consumes this client; X2 CoreBackend behind AgentKeysClient.
… build (X0/X1/X2) Evolves the #172 broker client into the phone-first host model. agentkeys-core is native-heavy (aws-sdk, keyring) → can't compile to wasm, so the host-agnostic broker client moves to a new minimal crate that builds for BOTH native and wasm32. - NEW crate `agentkeys-web-core`: the broker client (moved from agentkeys-core via git mv — cap-mint + pairing) + wasm-bindgen exports (`WebCore`, behind `--features wasm`). reqwest is default-features=false with the browser fetch backend on wasm32 and rustls-tls on native (target-gated). crate-type = [cdylib, rlib]. - agentkeys-core: drops the broker module (no consumer yet; future native consumers depend on agentkeys-web-core directly). Workspace member + dep added. - web app: `lib/client/core.ts` — `CoreBackend` lazy-loads the WASM pkg + talks to the broker directly (X1); exposes the cap/pairing calls for the onboarding/pairing slices. Registered as `NEXT_PUBLIC_AGENTKEYS_BACKEND=core` (default broker broker.litentry.org). The AgentKeysClient read endpoints inherit EmptyBackend's disconnected state until the later W-phases wire them (honest empty states). - dev.sh: `build_wasm` step — wasm-pack build, cached by a src+Cargo.toml+wasm-pack version hash (skip when unchanged), copies the .wasm to public/wasm; graceful no-op if wasm-pack absent. Generated pkg + public/wasm are gitignored. Verified: cargo test/clippy (-D warnings)/fmt on agentkeys-web-core + agentkeys-core; wasm32 build + wasm-pack pkg generate; apps/parent-control tsc + next build clean; bash -n dev.sh.
ba2a2fb to
6b1c424
Compare
- core.ts: memoize the WASM core per broker URL (Map) + evict on reject, so a second CoreBackend with a different broker gets its own instance and a transient load/broker failure no longer poisons the cache forever (HIGH). - broker.rs: native client gets a 20s request timeout (wasm keeps the fetch backend) so a stalled broker can't hang a worker thread (MED). - broker.rs: bound the echoed broker error body to 512 chars so an oversized response can't bloat a JS rejection/log line; status + endpoint preserved. Adds a regression test (MED). - dev.sh: stabilize the wasm src-hash -- sort the file list (filesystem order no longer flips the hash) + add workspace Cargo.toml/Cargo.lock + rustc version so a transitive-dep bump busts the cache (MED). Deferred (tracked): broker CORS for the browser-direct path + typed TS DTOs land with the live web e2e slice. status() stays disconnected by design until the read endpoints are wired. Verified: cargo test (5 passed) + clippy -D warnings + fmt + wasm-pack build + tsc --noEmit + next build all green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the keystone slices of the web-wiring plan (
docs/plan/web-flow/wire-real-paths.md), toward #163. (Supersedes the original "broker client in agentkeys-core" framing — agentkeys-core is native-heavy and can't compile to wasm, so the client moves to a minimal dual-target crate.)What
agentkeys-web-core— the host-agnostic broker client (cap-mint/v1/cap/{memory,cred}-*+ pairingclaim/pending/ack), moved from agentkeys-core viagit mv. Builds for native ANDwasm32:reqwestisdefault-features=falsewith the browserfetchbackend on wasm andrustls-tlson native (target-gated);crate-type = [cdylib, rlib]. wasm-bindgen exports (WebCore) behind--features wasm.agentkeys-web-core).CoreBackend(lib/client/core.ts) — lazy-loads the WASM pkg and talks to the broker directly (the phone-first X1 path, no daemon); exposes the cap/pairing calls for the onboarding/pairing slices. Selectable viaNEXT_PUBLIC_AGENTKEYS_BACKEND=core(default brokerbroker.litentry.org). AgentKeysClient read endpoints inherit EmptyBackend's disconnected state until the later W-phases wire them (honest empty states).build_wasm—wasm-pack build, cached by a src+Cargo.toml+wasm-pack-version hash (skip when unchanged — the "verify same version"), copies the.wasmtopublic/wasm; graceful no-op ifwasm-packis absent. The generated pkg +public/wasmare gitignored (never committed).Verified
cargo test -p agentkeys-web-core(broker tests) +cargo clippy --all-targets -- -D warnings+cargo fmtclean;agentkeys-corestill builds.cargo build --target wasm32-unknown-unknown -p agentkeys-web-core --features wasm+wasm-pack buildgenerate the pkg.apps/parent-control:tsc --noEmit+next buildclean (the wasm import bundles).bash -n dev.sh.Next slices (separate PRs)
CoreBackendimplements more ofAgentKeysClient.broker.litentry.org(the user-provided live broker) + the harness WebAuthn-driving approach.🤖 Generated with Claude Code