v0.5.0
Supply typed input through complete program contracts
Code mode now models the complete agent-facing program surface with
ProgramContract: optional per-execution input plus the host tools available to
the program. An input-bearing contract validates and transforms each host value
before module execution, then exposes the transformed value as strongly typed
input beside codemode and console.
const contract = createProgramContract({
inputSchema: Event,
tools,
});
const client = createClient({ runtime, contract });
await client.run(source, {
input: event,
signal,
});Submitted programs receive the generated schema output type directly:
export default async function ({ input, codemode }: AgentProgramScope) {
switch (input.type) {
case "research.requested":
await codemode.startResearch(input.payload);
break;
}
}This works with the discriminated anyOf and oneOf schemas added in v0.4.0,
including contracts assembled dynamically from an event registry. Invalid or
non-JSON transformed input rejects on the host before the submitted module can
run.
Contracts that expect no input remain explicit:
const contract = createProgramContract({ tools });
await client.run(source, { signal });This is an intentionally breaking replacement for the tool-only API:
- Replace
ToolboxandcreateToolbox()withProgramContractand
createProgramContract(). - Replace
ToolSchemawithCodeModeSchema. - Pass
contract, nottoolbox, tocreateClient(). - Supply
inputtorun()only when the contract declaresinputSchema. - Runtime implementations must preserve whether
RuntimeExecuteRequest.input
is present when invoking the program.
Install with:
npm install @torkbot/code-mode@0.5.0