Skip to content

v0.5.0

Choose a tag to compare

@ggoodman ggoodman released this 29 Jul 16:36
aad10be

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 Toolbox and createToolbox() with ProgramContract and
    createProgramContract().
  • Replace ToolSchema with CodeModeSchema.
  • Pass contract, not toolbox, to createClient().
  • Supply input to run() only when the contract declares inputSchema.
  • Runtime implementations must preserve whether RuntimeExecuteRequest.input
    is present when invoking the program.

Install with:

npm install @torkbot/code-mode@0.5.0