feat: add workflow studio and postgres support

This commit is contained in:
boos
2026-05-25 16:03:07 +08:00
parent 7cdb02ef1d
commit cb35d5fc6e
96 changed files with 12414 additions and 15548 deletions
+25 -9
View File
@@ -294,7 +294,13 @@ fn parse_message_content(
return Ok((Vec::new(), None, None));
};
if let Some(text) = content.as_str() {
return Ok((vec![ContentPart::Text { text: text.to_string() }], None, None));
return Ok((
vec![ContentPart::Text {
text: text.to_string(),
}],
None,
None,
));
}
let mut parts = Vec::new();
@@ -307,7 +313,9 @@ fn parse_message_content(
match item["type"].as_str() {
Some("text") => {
if let Some(text) = item["text"].as_str() {
parts.push(ContentPart::Text { text: text.to_string() });
parts.push(ContentPart::Text {
text: text.to_string(),
});
}
}
Some("image") => {
@@ -317,9 +325,7 @@ fn parse_message_content(
detail: None,
});
} else if item["source"]["type"].as_str() == Some("base64") {
let media_type = item["source"]["media_type"]
.as_str()
.unwrap_or("image/png");
let media_type = item["source"]["media_type"].as_str().unwrap_or("image/png");
if let Some(data) = item["source"]["data"].as_str() {
parts.push(ContentPart::Image {
url: format!("data:{media_type};base64,{data}"),
@@ -350,14 +356,20 @@ fn parse_message_content(
}
Ok((
parts,
if tool_calls.is_empty() { None } else { Some(tool_calls) },
if tool_calls.is_empty() {
None
} else {
Some(tool_calls)
},
tool_call_id,
))
}
fn parse_anthropic_content(value: &Value) -> Result<Vec<ContentPart>, String> {
if let Some(text) = value.as_str() {
return Ok(vec![ContentPart::Text { text: text.to_string() }]);
return Ok(vec![ContentPart::Text {
text: text.to_string(),
}]);
}
let Some(items) = value.as_array() else {
return Ok(Vec::new());
@@ -366,7 +378,9 @@ fn parse_anthropic_content(value: &Value) -> Result<Vec<ContentPart>, String> {
for item in items {
if item["type"].as_str() == Some("text") {
if let Some(text) = item["text"].as_str() {
parts.push(ContentPart::Text { text: text.to_string() });
parts.push(ContentPart::Text {
text: text.to_string(),
});
}
}
}
@@ -387,7 +401,9 @@ fn parse_anthropic_tool_choice(value: Option<&Value>) -> Option<ToolChoice> {
match value["type"].as_str()? {
"auto" => Some(ToolChoice::Auto),
"any" => Some(ToolChoice::Required),
"tool" => value["name"].as_str().map(|name| ToolChoice::Specific(name.to_string())),
"tool" => value["name"]
.as_str()
.map(|name| ToolChoice::Specific(name.to_string())),
"none" => Some(ToolChoice::None),
_ => None,
}
+3 -1
View File
@@ -5,6 +5,8 @@ pub mod outbound;
pub mod stream;
pub use compatibility::AnthropicMessagesCompatibility;
pub use inbound::{format_messages_request, format_messages_request_with_compat, parse_messages_request};
pub use inbound::{
format_messages_request, format_messages_request_with_compat, parse_messages_request,
};
pub use outbound::parse_messages_response;
pub use stream::parse_stream_event;