Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(tokenjuice): declare compress's `explicit` as a schema enum

M3gA-Mind9bd7c07654e0
diff --git a/src/openhuman/inference/tokenjuice/schemas.rs b/src/openhuman/inference/tokenjuice/schemas.rs
index 6897a8d7bf..e725ae96b2 100644
--- a/src/openhuman/inference/tokenjuice/schemas.rs
+++ b/src/openhuman/inference/tokenjuice/schemas.rs
@@ -135,9 +135,25 @@ pub fn schemas(function: &str) -> ControllerSchema {
},
FieldSchema {
name: "explicit",
- ty: TypeSchema::String,
+ // Declared as an enum, not a bare string: `/schema` is what
+ // generators and model-facing tool definitions read, and an
+ // unrestricted string there invites callers to propose values
+ // that only fail once the handler runs. `check_type`
+ // (`core/all.rs`) enforces the variant list at the dispatch
+ // boundary, so the published contract and the rejection agree.
+ ty: TypeSchema::Option(Box::new(TypeSchema::Enum {
+ variants: vec![
+ "json",
+ "code",
+ "log",
+ "search",
+ "diff",
+ "html",
+ "plain_text",
+ ],
+ })),
comment: "Optional hard override of the detected kind, skipping detection \
- entirely. One of: json, code, log, search, diff, html, plain_text.",
+ entirely.",
required: false,
},
],
diff --git a/src/openhuman/inference/tokenjuice/schemas_tests.rs b/src/openhuman/inference/tokenjuice/schemas_tests.rs
index e8d76d8634..5d7625aa6c 100644
--- a/src/openhuman/inference/tokenjuice/schemas_tests.rs
+++ b/src/openhuman/inference/tokenjuice/schemas_tests.rs
@@ -147,3 +147,44 @@ fn compress_schema_declares_all_five_hint_inputs() {
);
}
}
+
+/// `/schema` is what generators and model-facing tool definitions read. Declaring
+/// `explicit` as a bare string there invites a caller to propose a value that only
+/// fails once the handler runs; as an enum, `check_type` rejects it at the dispatch
+/// boundary and the published contract matches the rejection.
+#[test]
+fn compress_declares_explicit_as_an_enum_of_the_accepted_kinds() {
+ let s = schemas("compress");
+ let explicit = s
+ .inputs
+ .iter()
+ .find(|f| f.name == "explicit")
+ .expect("`compress` must declare `explicit`");
+
+ let TypeSchema::Option(inner) = &explicit.ty else {
+ panic!(
+ "`explicit` is optional and must be declared as such: {:?}",
+ explicit.ty
+ );
+ };
+ let TypeSchema::Enum { variants } = inner.as_ref() else {
+ panic!(
+ "`explicit` must be an enum so the accepted kinds are discoverable \
+ from /schema rather than only from the handler: {inner:?}"
+ );
+ };
+ assert_eq!(
+ variants,
+ &[
+ "json",
+ "code",
+ "log",
+ "search",
+ "diff",
+ "html",
+ "plain_text"
+ ],
+ "the declared variants must be exactly what `ContentKind::from_str` parses \
+ — note `plain_text`, not serde's `plainText`"
+ );
+}