objectiveai_sdk/agent/script/script.rs
1//! The script code definition — a `type`-tagged enum flattened into
2//! [`AgentBase`](super::AgentBase).
3
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6
7/// The code a script agent executes on the CLIENT, discriminated by a
8/// required `type` field (no default). Flattened into the agent base,
9/// so the wire shape is `{"upstream":"script","type":"python","python":"…",…}`.
10#[derive(
11 Debug,
12 Clone,
13 PartialEq,
14 Eq,
15 Serialize,
16 Deserialize,
17 JsonSchema,
18 arbitrary::Arbitrary,
19)]
20#[serde(tag = "type", rename_all = "snake_case")]
21#[schemars(rename = "agent.script.Script")]
22pub enum Script {
23 // NOTE: no variant-level `#[schemars(title = "...")]`. This is a
24 // single-variant enum, which schemars collapses to the lone
25 // variant's schema and HOISTS the variant title to the schema's
26 // top-level `title` — a title of "Python" makes the JS codegen
27 // route this type to `src/python.ts` and leaves every
28 // `agent.script.Script` reference dangling. Leaving it off lets
29 // the type's `rename` drive the title, matching
30 // `ClientLaboratoryType`.
31 /// Python code executed on the client's embedded runtime — the
32 /// SAME shared runtime the `python` command uses. The code
33 /// receives the FULL conversation (a messages array, continuation
34 /// included) as the `input` global and must output an array of
35 /// [`OutputMessage`](super::OutputMessage)s (assistant/tool only).
36 Python {
37 /// The python source. Preserved verbatim — never normalized
38 /// (whitespace is significant).
39 python: String,
40 },
41}
42
43impl Script {
44 /// Validates the script definition.
45 pub fn validate(&self) -> Result<(), String> {
46 match self {
47 Script::Python { python } => {
48 if python.is_empty() {
49 return Err("`python` must not be empty".to_string());
50 }
51 }
52 }
53 Ok(())
54 }
55}