Dsml.CodecSourceA bidirectional combinator codec for the DSML tool-call grammar, in the style of Json.Codec: one description both decodes a tool-call block to OCaml values and encodes them back.
type edit = { path : string; line : int }
let edit_codec =
let open Dsml.Codec in
Invoke.map "edit" (fun path line -> { path; line })
|> Invoke.param ~enc:(fun e -> e.path) "path" string
|> Invoke.param ~enc:(fun e -> e.line) "line" int
|> Invoke.seal
let block =
Dsml.Codec.encode edit_codec [ { path = "/tmp/x.c"; line = 42 } ]
let calls = Dsml.Codec.decode edit_codec blockA codec for one parameter value.
map_value ~dec ~enc v adapts the value codec v to another type.
A codec for one tool invocation, producing a value of type 'a.
dynamic decodes/encodes any tool, mapping parameters to JSON arguments.
map ~dec ~enc c adapts an invoke codec to another type.
schema c is the JSON Schema for c's parameters object, with one property per Invoke.param and a required list. Pass it to Tool.v to advertise the tool to the model.
decode_arguments c arguments decodes one tool call's JSON-object arguments string (as carried by tool_call) through c, returning the typed value or an error message.
case ~inject ~project c makes invoke codec c a case of a sum type 'b: inject lifts a decoded value in, project selects it for encoding.
choice ?default cases dispatches an invocation on its tool name to the matching case; default handles unmatched names (e.g. dynamic).
decode c s decodes the tool-call block found in s with c.