Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 22 additions & 3 deletions crates/adapter-smith/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,25 @@ pub async fn run(
if user_text.trim().is_empty() {
continue;
}
let user_content = match crate::image_input::user_content(user_text.clone(), &cwd) {
Ok(content) => content,
Err(e) => {
emit.emit(SessionEvent::Error {
message: format!("image input error: {e:#}"),
});
continue;
}
};
if let Err(e) = provider::ensure_image_input_supported(
provider.as_ref(),
&messages,
Some(&user_content),
) {
emit.emit(SessionEvent::Error {
message: e.to_string(),
});
continue;
}
hooks
.run(
"user_prompt_submit",
Expand All @@ -779,7 +798,7 @@ pub async fn run(
persist,
Message {
role: Role::User,
content: Content::Text { text: user_text },
content: user_content,
}
);

Expand Down Expand Up @@ -1723,7 +1742,7 @@ pub fn resolve_model_from_spec(spec_str: &str) -> Result<ResolvedModel> {
Some(GROK_BASE_URL.to_string()),
grok_api_key()?,
)?),
provider::routing::Provider::DeepSeek => Box::new(provider::openai::OpenAi::with_config(
provider::routing::Provider::DeepSeek => Box::new(provider::openai::OpenAi::text_only(
Some(DEEPSEEK_BASE_URL.to_string()),
deepseek_api_key()?,
)?),
Expand Down Expand Up @@ -1839,7 +1858,7 @@ fn build_profile_model(
base_url.or_else(|| Some(GROK_BASE_URL.to_string())),
profile_api_key(profile, name, &["GROK_API_KEY", "XAI_API_KEY"])?,
)?),
provider::routing::Provider::DeepSeek => Box::new(provider::openai::OpenAi::with_config(
provider::routing::Provider::DeepSeek => Box::new(provider::openai::OpenAi::text_only(
base_url.or_else(|| Some(DEEPSEEK_BASE_URL.to_string())),
profile_api_key(profile, name, &["DEEPSEEK_API_KEY"])?,
)?),
Expand Down
10 changes: 10 additions & 0 deletions crates/adapter-smith/src/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ fn render_head_for_summarizer(head: &[Message]) -> String {
out.push_str(text.trim());
out.push_str("\n\n");
}
(Role::User, Content::UserInput { text, images }) => {
out.push_str("USER: ");
out.push_str(text.trim());
out.push_str(&format!("\n[{} image attachment(s)]\n\n", images.len()));
}
(_, Content::AssistantToolCalls { text, calls }) => {
if let Some(t) = text {
if !t.is_empty() {
Expand Down Expand Up @@ -304,6 +309,11 @@ fn render_head_for_summarizer(head: &[Message]) -> String {
out.push_str(text.trim());
out.push_str("\n\n");
}
(Role::System | Role::Assistant | Role::Tool, Content::UserInput { text, images }) => {
out.push_str("OTHER: ");
out.push_str(text.trim());
out.push_str(&format!("\n[{} image attachment(s)]\n\n", images.len()));
}
}
}
out
Expand Down
8 changes: 8 additions & 0 deletions crates/adapter-smith/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ pub fn estimate_tokens(messages: &[Message]) -> usize {
for m in messages {
match &m.content {
Content::Text { text: t } => chars += t.len(),
Content::UserInput { text, images } => {
chars += text.len();
// Image tokenization is provider- and resolution-dependent.
// A conservative fixed allowance keeps base64 storage bytes
// from masquerading as text tokens while still budgeting the
// visual context carried by each image.
chars += images.len() * 6_000;
}
Content::AssistantToolCalls { text, calls } => {
if let Some(t) = text {
chars += t.len();
Expand Down
Loading
Loading