MoonBit SDK for embedding the Codex agent in workflows and applications
Dependencies
import {
"totto2727/codex-sdk/cli" @codex,
}| Surface | Native | Wasm |
|---|---|---|
| Module and src/cli package | Supported | Supported |
| CI validation | Not run in CI | Preferred target |
| Codex subprocess execution | Uses the host process runtime | Requires a host/runtime process bridge |
nix develop
nix develop .#ci --command codex --versionasync fn main {
let client = @codex.Client::Client()
let thread = client.start_thread()
let turn = thread.run(
@codex.Input::Prompt("Diagnose the test failure and propose a fix"),
)
println(turn.final_response)
}thread.run_streamed(
@codex.Input::Prompt("Diagnose the test failure"),
async fn(event) {
match event {
@codex.ItemCompleted(completed) => println("\{completed.item}")
@codex.TurnCompleted(completed) => println("\{completed.usage}")
_ => ()
}
},
)let schema = Json::object({
"type": "object",
"properties": {
"summary": Json::object({ "type": "string" }),
},
"required": ["summary"],
"additionalProperties": false,
})
let turn = thread.run(
@codex.Input::Prompt("Summarize repository status"),
turn_options=@codex.TurnOptions::TurnOptions(output_schema=schema),
)flowchart LR
Thread[Codex Thread] --> Exec[Exec]
Exec --> Invocation[agent_cli.Invocation]
Invocation --> Run[agent_cli.run]
Run --> Process[codex process]
Process --> Jsonl[JSONL events]
Jsonl --> Event[ThreadEvent callback]
Event --> Thread| Upstream TypeScript | MoonBit |
|---|---|
| codex.ts | client.mbt |
| codexOptions.ts | client_options.mbt |
| events.ts | events.mbt |
| exec.ts | exec.mbt |
| index.ts | index.mbt |
| items.ts | items.mbt |
| outputSchemaFile.ts | internal_output_schema_file.mbt |
| thread.ts | thread.mbt |
| threadOptions.ts | thread_options.mbt |
| turnOptions.ts | turn_options.mbt |
moon check
moon test
moon buildflowchart TD
Shell[CI Nix devShell] --> Codex[codex --version]
Codex --> Metadata[moon info]
Metadata --> Check[moon check]
Check --> Test[moon test]
Test --> Build[moon build]MoonBit SDK for embedding the Codex agent in workflows and applications
Dependencies