mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-10-05 12:13:05 +08:00
- Added initial server setup with Cargo.toml defining dependencies and project structure. - Created build.rs for generating protobuf bindings and validating wire contracts. - Established database schema with initial migration files for conversations, messages, and runs. - Introduced tools and prompts for Cursor functionality, enhancing user interaction capabilities.
51 lines
1.5 KiB
Rust
51 lines
1.5 KiB
Rust
//! Defines provider-independent model requests and streaming responses.
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use super::{ModelSpec, ProjectedContent, ProjectedMessage, ToolDefinition};
|
|
|
|
const PROVIDER_TOOL_CALL_ID_MAX_CHARS: usize = 64;
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
pub struct PromptSpec {
|
|
pub instructions: String,
|
|
pub tools: Vec<ToolDefinition>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
pub struct ModelRequest {
|
|
pub prompt: PromptSpec,
|
|
pub model: ModelSpec,
|
|
pub history: Vec<ProjectedMessage>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
pub struct ModelInvocation {
|
|
pub call_id: String,
|
|
pub run_id: String,
|
|
pub conversation_id: String,
|
|
pub provider_call_index: u64,
|
|
pub request: ModelRequest,
|
|
}
|
|
|
|
pub(crate) fn normalize_provider_tool_call_ids(history: &mut [ProjectedMessage]) {
|
|
for message in history {
|
|
match &mut message.content {
|
|
ProjectedContent::Assistant { calls, .. } => {
|
|
for call in calls {
|
|
truncate_tool_call_id(&mut call.call_id);
|
|
}
|
|
}
|
|
ProjectedContent::ToolResult(result) => {
|
|
truncate_tool_call_id(&mut result.call_id);
|
|
}
|
|
ProjectedContent::Parts(_) => {}
|
|
}
|
|
}
|
|
}
|
|
|
|
fn truncate_tool_call_id(call_id: &mut String) {
|
|
if let Some((end, _)) = call_id.char_indices().nth(PROVIDER_TOOL_CALL_ID_MAX_CHARS) {
|
|
call_id.truncate(end);
|
|
}
|
|
}
|