Repository navigation
@cloudflare/computer@0.10.0
This release is all about codemode. It adds codemode modules, which let a host module return objects with methods and keep state for a run, and builds a codemode:browser module on them, so the model can drive an agents Browser. Runs can now carry metadata for host modules, and the JavaScript backend has been renamed to CodemodeBackend.
Highlights
- Codemode modules:
createCodemodeModule()builds host modules whose functions return objects with methods. Each method call is journaled like any other host call, and an object keeps working after a pause or a restart, because the backend rebuilds it from its saved state.context()adds values toctx, made once per connection or once per scope of a run and disposed when the scope ends. Experimental. See Codemode modules. - A browser for code the model runs:
createBrowserModule()from@cloudflare/computer/modules/browserservescodemode:browser, with the samebrowser.*functions as agents'browserTool. A run opens one session in its browser scope, runs in the same scope take turns, a run waiting for a person keeps its scope, and notices such as a restarted browser go to the run's stderr when it ends. It needs a read-write backend. Experimental. Seecodemode:browser. - Run metadata:
runtime.exec()takesmetadata, a record of strings the run's code never sees, so host modules can tell which conversation or user a run is for. Host module calls read it, with the run's id, ascontext.execution,runtime.pending()lists it with each waiting call, and theexectool can set it withexec: { metadata }. See Run metadata. - Richer values in replayable runs: codemode modules can take and return
Date,bigint, byte and typed arrays,Headers, and errors with their name and properties, which the journal stores with Cap'n Web's encoding. In runs that don't replay, they can also take callbacks and return streams and live stubs. - Other changes: a host module call can return more than 4,096 values, as long as the response fits the byte limits. The worker shell no longer double-encodes non-ASCII bytes from redirected
cat, heredocs andtee. capnweb is now 0.12.
Upgrading
-
Rename
WorkerJavaScriptBackendtoCodemodeBackend. There is no alias for the old names.- import { WorkerJavaScriptBackend } from "@cloudflare/computer/backends/worker-javascript"; - new WorkerJavaScriptBackend({ loader: env.LOADER }); + import { CodemodeBackend } from "@cloudflare/computer/backends/codemode"; + new CodemodeBackend({ loader: env.LOADER });
WorkerJavaScriptBackendOptionsis nowCodemodeBackendOptions. -
Check the backend's id. A backend without
idnow registers as"codemode"instead of"worker-javascript", and theexectool shows it to the model under that name. Itstype, which traces record asworkspace.backend.type, is now"codemode"whatever the id. A backend only sees runs saved under its own id, so runs saved under"worker-javascript"are ignored: they aren't resumed, listed bypending()or found bygetExec().- To keep those runs, including any waiting for a person when you deploy, pass
id: "worker-javascript". - Otherwise, change
backend: "worker-javascript"andexec.backendskeys to"codemode". Old references throw an unknown-backend error.
- To keep those runs, including any waiting for a person when you deploy, pass
-
Move the tool sets'
execoptions underexec. An old backend map orexec: {}now throws.createAITools({ workspace, - exec: { codemode: {} }, - execOutput: { maxBytes: 50_000 } + exec: { + backends: { codemode: {} }, + output: { maxBytes: 50_000 } + } });For no
exectool, passexec: { backends: {} }instead ofexec: {}. -
Update code that builds host call contexts or pending calls by hand, such as a test that calls a host module function directly or a fake
runtime.pending().WorkspaceModuleCallContextnow has a requiredexecution: { id, metadata }, andWorkspaceRuntimePendingCallhas a requiredmetadata. -
Coming from 0.8? 0.9.0 renamed host and source modules from
ws:*tocodemode:*, such asws:gittocodemode:git.
Minor Changes
-
#299 Add
createBrowserModule(), the experimentalcodemode:browserhost module, which drives an agentsBrowserfrom isolate JavaScript. Seecodemode:browser. (536bb96) - Thanks @ben-reitz -
#305 Rename
WorkerJavaScriptBackendtoCodemodeBackend, imported from@cloudflare/computer/backends/codemode, and change its default id from"worker-javascript"to"codemode". See the upgrade steps above. (f4aec31) - Thanks @ben-reitz -
#301 Add experimental
createCodemodeModule()for host modules that return objects with methods and share context across a run. See Codemode modules. (af4b3dc) - Thanks @aron-cf -
#291
runtime.exec()takesmetadatafor host modules, which they read ascontext.execution.metadata. See Host modules. (1f8dfee) - Thanks @ben-reitz -
#292 The
exectool can start each run withmetadata, set withexec: { metadata }. See Run metadata. (feac0ff) - Thanks @ben-reitz -
#300 The tool sets'
execoption now takes{ backends, output, metadata }, replacing the backend map andexecOutput. See the upgrade steps above. (3c3734c) - Thanks @ben-reitz -
#290 Host module calls get
context.execution, with theidof their run. See Host modules. (72421fc) - Thanks @ben-reitz
Patch Changes
-
#289 A host module call can now return more than 4,096 values, as long as the response fits the backend's byte limits. (
1fbd37f) - Thanks @ben-reitz -
#287 The worker shell no longer double-encodes non-ASCII bytes written by redirected
cat, heredocs,teeand other byte-oriented commands. (b995d86) - Thanks @github-actions