Skip to main content

objectiveai_sdk/laboratories/
laboratories.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4/// A laboratory attached to an agent completion — dialed by the proxy as a
5/// client-side MCP upstream across every agent (and fallback).
6///
7/// Untagged: each variant's payload carries its own `type` discriminator
8/// field, so the wire shape is exactly that of the inner struct (e.g.
9/// `{"type":"client","id":"…"}`).
10#[derive(
11    Debug,
12    Clone,
13    Serialize,
14    Deserialize,
15    PartialEq,
16    Eq,
17    JsonSchema,
18    arbitrary::Arbitrary,
19)]
20#[serde(untagged)]
21#[schemars(rename = "laboratories.Laboratory")]
22// Single-variant untagged enum: schemars emits a single-variant `anyOf` that
23// the json-schema builder flattens to a bare top-level `$ref`, which the SDK
24// code generators inline (breaking the schema roundtrip). The transform adds a
25// sibling `"type": "object"` so it lands as the round-trippable `{type, $ref}`
26// ref-wrapper shape. See `crate::json_schema::ref_wrapper_object`.
27#[schemars(transform = crate::json_schema::ref_wrapper_object)]
28pub enum Laboratory {
29    /// A client-resolved laboratory, identified by an opaque `id`.
30    Client(ClientLaboratory),
31}
32
33/// A client-resolved laboratory: a client-side MCP server keyed by an
34/// opaque `id`. Wire shape: `{"type":"client","id":"…"}`.
35#[derive(
36    Debug,
37    Clone,
38    Serialize,
39    Deserialize,
40    PartialEq,
41    Eq,
42    JsonSchema,
43    arbitrary::Arbitrary,
44)]
45#[schemars(rename = "laboratories.ClientLaboratory")]
46pub struct ClientLaboratory {
47    /// Discriminator — always `"client"`.
48    pub r#type: ClientLaboratoryType,
49    /// The opaque laboratory id.
50    pub id: String,
51}
52
53/// Discriminator for [`ClientLaboratory`]. Ser/de's to the static string
54/// `"client"`.
55#[derive(
56    Debug,
57    Clone,
58    Copy,
59    Serialize,
60    Deserialize,
61    PartialEq,
62    Eq,
63    Hash,
64    JsonSchema,
65    arbitrary::Arbitrary,
66)]
67#[serde(rename_all = "snake_case")]
68#[schemars(rename = "laboratories.ClientLaboratoryType")]
69pub enum ClientLaboratoryType {
70    // NOTE: no variant-level `#[schemars(title = "...")]`. This is a
71    // single-variant unit enum, which schemars collapses to a bare string
72    // schema and hoists the variant title to the schema's top-level
73    // `title`. A title of "Client" makes the JS codegen route this type to
74    // `src/client.ts` (clobbering the real SDK client). Leaving it off lets
75    // the type's `rename` drive the title, matching its siblings.
76    /// Serializes to `"client"`.
77    Client,
78}