Repository navigation
refactor(runtime): extract computer-use wire codec and contract types… - #1507
Conversation
|
Reviewed at This branch now conflicts with P3: The new type owner is not used at the adapter and public export seams.
The codec and type move itself is behavior-equivalent; differential probes found no parsing, adaptation, summary, export, or dependency-cycle regression. |
5d2030d to
0cd84fc
Compare
|
Thanks for the review! I learned a lot from your feedback. Rebased onto latest main and resolved the CuObservedElement conflict — the #1555 fields (enabled, selected, parentElementId) are in computer-use-types.ts, and their model-text output in observationText is preserved. Also addressed P3: openai-computer-loop.ts now imports CuDispatchOutcome/CuRunResult directly from computer-use-types.ts, and index.ts re-exports the Cu* contract types from computer-use-types.ts (keeping ComputerUseToolSet from computer-use-tools.ts since it's not a pure contract type). The compatibility re-export from computer-use-tools.ts is retained. |
Summary
Splits
packages/runtime/src/computer-use-tools.ts(1836 lines) into three focused files per #1405, keeping the@maka/runtimepublic surface stable via re-exports. Behavior-neutral — the moved code is byte-identical, only its location changes.computer-use-types.ts(new, ~180 lines) — pure contract types (zero runtime deps), consumed by adapters without dragging in the tool assembly:CuScreenshot,CuDispatchEvidence,CuDispatchOutcome,CuRunResult,CuAppSummary,CuObservedElement,CuObservation,CuSemanticAction,CuRunContext,CuDispatchBackendCuPresentationFence,CuOverlayHookContext,CuOverlayHook(overlay hooks)computer-use-codec.ts(new, ~320 lines) — wire-protocol codec (mirrors the establishedopenai-computer-codec.tspattern):computerParamszod discriminated union (+ sharedcoordinate/texthelpers)snapshotComputerParams,adaptToCuActionsummarize+summarizeEvidence(moved together since they're tightly coupled)computer-use-tools.ts(retained, 1836 → ~1300 lines) —buildComputerUseToolsand its assembly logic stay here.Implementation notes
computerParams,summarize, andsummarizeEvidencewere previously module-private; they become exports on the codec sobuildComputerUseToolscan import them back.summarizeEvidenceis also called directly insidebuildComputerUseTools(not just viasummarize), so it must be exported.coordinate/textzod helpers move withcomputerParamsto the codec;computerWireParams(stays in tools, used at the tool schema level) imports them back — one-way, no cycle.summarizewas renamed (point→pointStr) to avoid a shadowing clash with thepointhelper that moved into the same file.computer-use-tools.tsre-exports the moved types and codec functions, soindex.ts,openai-computer-loop.ts, and test files keep their import paths unchanged.@maka/coretypes + 3 re-exported-only types +CU_ACTION_TYPESin the codec).Dependency direction is acyclic:
computer-use-types.ts(leaf) ←computer-use-codec.ts←computer-use-tools.ts.Verification
npm --workspace @maka/runtime run typecheck— cleannpm --workspace @maka/runtime run build— cleannpm --workspace @maka/runtime run test— 2554 tests, 2547 pass, 0 fail, 7 skippednpm run lint— clean (biome, 2087 files)npm run format:check— clean (biome, 1049 files)git diff origin/main...HEAD --check— no whitespace errorsReview focus
computer-use-tools.tscovers all symbols that downstream consumers (index.ts,openai-computer-loop.ts, tests) previously imported from it.point→pointStrrename insummarizeis purely cosmetic (avoids shadowing); the function's input/output is unchanged.