Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions crates/contrib/schematic_macros/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,44 @@ struct SchematicImplArgs<'a> {
instrument: &'a TokenStream,
}

/// The body of a `schema_name` that says which instantiation it describes.
///
/// A schema names each type it expands and refers back to that name wherever
/// the type appears again, so a name has to identify one type.
/// A generic named after its base alone does not: `MergeableMap<ToolConfig>`
/// and `MergeableMap<ToolParameterConfig>` would both answer `MergeableMap`,
/// and a consumer resolving a reference by name would walk a value against
/// whichever of them it met first.
///
/// The arguments are appended instead, so the two are `MergeableMap_ToolConfig`
/// and `MergeableMap_ToolParameterConfig`.
/// An argument with no name of its own (a primitive) contributes nothing, which
/// leaves the base name for a type generic only over those.
#[cfg(feature = "schema")]
fn generate_schema_name(base: &str, generics: &syn::Generics) -> TokenStream {
let type_params = generics.type_params().map(|param| &param.ident);
let mut appends = type_params.peekable();

if appends.peek().is_none() {
return quote! { Some(#base.into()) };
}

let appends = appends.map(|ident| {
quote! {
if let Some(argument) = <#ident as schematic::Schematic>::schema_name() {
name.push('_');
name.push_str(&argument);
}
}
});

quote! {
let mut name = String::from(#base);
#(#appends)*
Some(name)
}
}

#[cfg(feature = "schema")]
fn emit_schematic_impls(args: &SchematicImplArgs<'_>) -> TokenStream {
let &SchematicImplArgs {
Expand All @@ -153,6 +191,9 @@ fn emit_schematic_impls(args: &SchematicImplArgs<'_>) -> TokenStream {
let partial_schema_name = partial_name.to_string();
let partial_schema_impl = crate::common::Container::generate_partial_schema(name, cfg.generics);

let schema_name_impl = generate_schema_name(&schema_name, cfg.generics);
let partial_schema_name_impl = generate_schema_name(&partial_schema_name, cfg.generics);

// `schema_union_with` unions the derived schema with caller-supplied
// variants, for a type that deserializes from more shapes than its fields
// describe. Using it asserts the extra shapes are shorthands for the fields,
Expand Down Expand Up @@ -180,7 +221,7 @@ fn emit_schematic_impls(args: &SchematicImplArgs<'_>) -> TokenStream {
#[automatically_derived]
impl #impl_generics schematic::Schematic for #name #ty_generics #schematic_where {
fn schema_name() -> Option<String> {
Some(#schema_name.into())
#schema_name_impl
}

#instrument
Expand All @@ -194,7 +235,7 @@ fn emit_schematic_impls(args: &SchematicImplArgs<'_>) -> TokenStream {
#[automatically_derived]
impl #impl_generics schematic::Schematic for #partial_name #ty_generics #partial_schematic_where {
fn schema_name() -> Option<String> {
Some(#partial_schema_name.into())
#partial_schema_name_impl
}

#instrument
Expand Down
6 changes: 3 additions & 3 deletions crates/jp_cli/src/cmd/conversation/print_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ fn tool_with_style(style: DisplayStyleConfig) -> ToolConfig {
summary: None,
description: None,
examples: None,
parameters: IndexMap::new(),
parameters: IndexMap::new().into(),
run: None,
format: None,
result: None,
cancellation_response: None,
style: Some(style),
questions: IndexMap::new(),
options: IndexMap::new(),
questions: IndexMap::new().into(),
options: IndexMap::new().into(),
access: None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/jp_cli/src/cmd/plugin/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ async fn prepare_turn(
// added to the workspace since then is otherwise unknown to it, and starting
// it fails.
ctx.mcp_client
.set_servers(config.providers.mcp.clone())
.set_servers(config.providers.mcp.clone().into_map())
.await;

// Shared, because a turn spawned earlier may still be using a server this
Expand Down
4 changes: 2 additions & 2 deletions crates/jp_cli/src/cmd/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2558,12 +2558,12 @@ fn apply_enable_tools(
for d in directives.iter() {
match d {
ToolDirective::EnableAll => {
for (name, tool) in &mut partial.conversation.tools.tools {
for (name, tool) in partial.conversation.tools.tools.iter_mut() {
apply_directive_to_tool(name, tool, &defaults, ToggleScope::Bulk, true)?;
}
}
ToolDirective::DisableAll => {
for (name, tool) in &mut partial.conversation.tools.tools {
for (name, tool) in partial.conversation.tools.tools.iter_mut() {
apply_directive_to_tool(name, tool, &defaults, ToggleScope::Bulk, false)?;
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/jp_cli/src/cmd/query/tool/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ pub fn describe_tools() -> PartialToolConfig {
..Default::default()
})),
..Default::default()
})]),
})])
.into(),
run: Some(RunMode::Unattended),
style: Some(PartialDisplayStyleConfig {
hidden: Some(true),
Expand Down
6 changes: 4 additions & 2 deletions crates/jp_cli/src/cmd/query/tool/coordinator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ fn test_question_target_with_configured_question() {
target: Some(QuestionTarget::Assistant(Box::default())),
answer: None,
}
},
}
.into(),
..Default::default()
},
vec![],
Expand Down Expand Up @@ -247,7 +248,8 @@ fn test_static_answer_with_configured_answer() {
target: Some(QuestionTarget::User),
answer: None,
}
},
}
.into(),
..Default::default()
},
vec![],
Expand Down
Loading
Loading