aKode fase 5: rinomina interna (crate akode-*, akode-rs/, akode-cli/, binario akode, AKODE_*, ~/.akode, snapshot)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
200
akode-rs/protocol/src/openai_models/guardian.rs
Normal file
200
akode-rs/protocol/src/openai_models/guardian.rs
Normal file
@@ -0,0 +1,200 @@
|
||||
//! Model-owned Guardian coverage. Missing policy preserves legacy behavior;
|
||||
//! unknown modes retain synchronous review and never enable the fast path.
|
||||
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use ts_rs::TS;
|
||||
|
||||
use super::ModelInfo;
|
||||
use crate::ToolName;
|
||||
use crate::mcp::is_node_repl_backed_server;
|
||||
use crate::mcp::is_node_repl_backed_tool;
|
||||
|
||||
/// How Guardian handles an action when the user selects automatic approval.
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, TS, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum GuardianReviewMode {
|
||||
#[default]
|
||||
Disabled,
|
||||
Synchronous,
|
||||
/// Use a current low-risk score; otherwise run synchronous review.
|
||||
Adaptive,
|
||||
#[serde(other)]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
/// How actions outside adaptive coverage affect cached classification evidence.
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, TS, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum GuardianUnscoredAction {
|
||||
Ignore,
|
||||
AgeScore,
|
||||
#[default]
|
||||
#[serde(other)]
|
||||
InvalidateScore,
|
||||
}
|
||||
|
||||
/// A complete model policy. Omitted scopes are disabled; unknown fields are ignored.
|
||||
/// Code Mode wrappers have no approval scope; their nested tools follow this policy.
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
|
||||
pub struct GuardianModelPolicy {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub computer_use: Option<GuardianReviewMode>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub shell: Option<GuardianReviewMode>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub file_changes: Option<GuardianReviewMode>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub mcp: Option<GuardianReviewMode>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub network: Option<GuardianReviewMode>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub permissions: Option<GuardianReviewMode>,
|
||||
/// Coverage for tools without an approval category.
|
||||
#[serde(default)]
|
||||
pub other_tools: GuardianReviewMode,
|
||||
#[serde(default)]
|
||||
pub unscored_action: GuardianUnscoredAction,
|
||||
/// Omission retains the existing allowance for adaptive computer use.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub initial_cua_call: Option<bool>,
|
||||
/// Whether adaptive shell coverage includes ordinary sandboxed commands.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub sandboxed_exec_commands: Option<bool>,
|
||||
}
|
||||
|
||||
impl GuardianModelPolicy {
|
||||
pub fn review_mode(&self, scope: GuardianScope) -> GuardianReviewMode {
|
||||
match scope {
|
||||
GuardianScope::ComputerUse => self.computer_use,
|
||||
GuardianScope::Shell => self.shell,
|
||||
GuardianScope::FileChanges => self.file_changes,
|
||||
GuardianScope::Mcp => self.mcp,
|
||||
GuardianScope::Network => self.network,
|
||||
GuardianScope::Permissions => self.permissions,
|
||||
GuardianScope::NativeTool => Some(GuardianReviewMode::Synchronous),
|
||||
}
|
||||
.unwrap_or(GuardianReviewMode::Disabled)
|
||||
}
|
||||
|
||||
pub fn scoring_enabled(&self) -> bool {
|
||||
[
|
||||
self.computer_use,
|
||||
self.shell,
|
||||
self.file_changes,
|
||||
self.mcp,
|
||||
self.network,
|
||||
self.permissions,
|
||||
]
|
||||
.contains(&Some(GuardianReviewMode::Adaptive))
|
||||
}
|
||||
|
||||
pub fn disable_scoring(&mut self) {
|
||||
for mode in [
|
||||
&mut self.computer_use,
|
||||
&mut self.shell,
|
||||
&mut self.file_changes,
|
||||
&mut self.mcp,
|
||||
&mut self.network,
|
||||
&mut self.permissions,
|
||||
] {
|
||||
if *mode == Some(GuardianReviewMode::Adaptive) {
|
||||
*mode = Some(GuardianReviewMode::Synchronous);
|
||||
}
|
||||
}
|
||||
self.other_tools = GuardianReviewMode::Synchronous;
|
||||
}
|
||||
|
||||
pub fn allows_initial_cua_call(&self) -> bool {
|
||||
self.initial_cua_call
|
||||
.unwrap_or(self.computer_use == Some(GuardianReviewMode::Adaptive))
|
||||
}
|
||||
}
|
||||
|
||||
/// Approval categories understood by this client. Future catalog keys are ignored.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum GuardianScope {
|
||||
ComputerUse,
|
||||
Shell,
|
||||
FileChanges,
|
||||
Mcp,
|
||||
Network,
|
||||
Permissions,
|
||||
NativeTool,
|
||||
}
|
||||
|
||||
impl GuardianScope {
|
||||
pub fn for_mcp_server(server: &str) -> Self {
|
||||
if is_node_repl_backed_server(server) {
|
||||
Self::ComputerUse
|
||||
} else {
|
||||
Self::Mcp
|
||||
}
|
||||
}
|
||||
|
||||
/// Classifies state-changing MAv2 calls in the configured namespace.
|
||||
/// An absent namespace accepts the default namespace spellings; callers gate this lookup.
|
||||
pub fn for_multi_agent_tool(tool: &ToolName, namespace: Option<&str>) -> Option<Self> {
|
||||
let matches_namespace = match namespace {
|
||||
Some(namespace) => tool.namespace.as_deref() == Some(namespace),
|
||||
None => tool.is_default_namespace(),
|
||||
};
|
||||
if matches_namespace
|
||||
&& matches!(
|
||||
tool.name.as_str(),
|
||||
"spawn_agent" | "send_message" | "followup_task" | "interrupt_agent"
|
||||
)
|
||||
{
|
||||
Some(Self::NativeTool)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn for_tool(tool: &ToolName) -> Option<Self> {
|
||||
if is_node_repl_backed_tool(&tool.name, tool.namespace.as_deref()) {
|
||||
return Some(Self::ComputerUse);
|
||||
}
|
||||
if tool
|
||||
.namespace
|
||||
.as_deref()
|
||||
.is_some_and(|namespace| namespace.starts_with("mcp__"))
|
||||
|| tool.name.starts_with("mcp__")
|
||||
{
|
||||
return Some(Self::Mcp);
|
||||
}
|
||||
if !tool.is_default_namespace() {
|
||||
return None;
|
||||
}
|
||||
match tool.name.as_str() {
|
||||
"shell" | "shell_command" | "exec_command" | "write_stdin" | "execve" => {
|
||||
Some(Self::Shell)
|
||||
}
|
||||
"apply_patch" => Some(Self::FileChanges),
|
||||
"request_permissions" => Some(Self::Permissions),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ModelInfo {
|
||||
/// An absent map uses legacy config; an omitted scope in a supplied map is disabled.
|
||||
pub fn guardian_review_mode(&self, scope: GuardianScope) -> Option<GuardianReviewMode> {
|
||||
self.guardian
|
||||
.as_ref()
|
||||
.map(|policy| policy.review_mode(scope))
|
||||
}
|
||||
|
||||
/// The legacy metadata bit remains the transport understood by older CUA servers.
|
||||
pub fn computer_use_review_required(&self) -> bool {
|
||||
self.guardian_review_mode(GuardianScope::ComputerUse)
|
||||
.map_or(self.node_repl_auto_review_required, |mode| {
|
||||
mode != GuardianReviewMode::Disabled
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "guardian_tests.rs"]
|
||||
mod tests;
|
||||
48
akode-rs/protocol/src/openai_models/guardian_tests.rs
Normal file
48
akode-rs/protocol/src/openai_models/guardian_tests.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use super::super::tests::test_model;
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn guardian_policy_is_optional_and_tolerates_future_config() -> anyhow::Result<()> {
|
||||
let model = test_model(/*spec*/ None);
|
||||
let mut wire = serde_json::to_value(&model)?;
|
||||
assert!(
|
||||
!wire
|
||||
.as_object()
|
||||
.expect("model object")
|
||||
.contains_key("guardian")
|
||||
);
|
||||
assert_eq!(serde_json::from_value::<ModelInfo>(wire.clone())?, model);
|
||||
|
||||
wire["guardian"] = serde_json::json!({
|
||||
"computer_use": "adaptive", "shell": "future_mode", "future_scope": {"version": 2},
|
||||
"mcp": null, "permissions": "adaptive",
|
||||
});
|
||||
let model: ModelInfo = serde_json::from_value(wire)?;
|
||||
assert_eq!(
|
||||
model.guardian,
|
||||
Some(GuardianModelPolicy {
|
||||
computer_use: Some(GuardianReviewMode::Adaptive),
|
||||
shell: Some(GuardianReviewMode::Unknown),
|
||||
permissions: Some(GuardianReviewMode::Adaptive),
|
||||
..Default::default()
|
||||
})
|
||||
);
|
||||
assert!(model.computer_use_review_required());
|
||||
assert_eq!(
|
||||
model.guardian_review_mode(GuardianScope::Mcp),
|
||||
Some(GuardianReviewMode::Disabled)
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guardian_policy_overrides_the_legacy_cua_bit_only_when_present() {
|
||||
let mut model = test_model(/*spec*/ None);
|
||||
model.node_repl_auto_review_required = true;
|
||||
assert!(model.computer_use_review_required());
|
||||
model.guardian = Some(GuardianModelPolicy::default());
|
||||
assert!(!model.computer_use_review_required());
|
||||
model.guardian.as_mut().expect("policy").computer_use = Some(GuardianReviewMode::Synchronous);
|
||||
assert!(model.computer_use_review_required());
|
||||
}
|
||||
64
akode-rs/protocol/src/openai_models/guardian_v2.rs
Normal file
64
akode-rs/protocol/src/openai_models/guardian_v2.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use ts_rs::TS;
|
||||
|
||||
use super::ReasoningEffort;
|
||||
|
||||
/// Legacy classifier modes retained for configuration and model-catalog compatibility.
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, TS, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[ts(rename_all = "snake_case")]
|
||||
pub enum AsyncClassifierMode {
|
||||
Snapshot,
|
||||
#[default]
|
||||
Conversation,
|
||||
}
|
||||
|
||||
/// Optional model-owned defaults for Guardian v2 classification experiments.
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
|
||||
pub struct GuardianV2ModelConfig {
|
||||
/// Deprecated and ignored; asynchronous classification always uses conversations.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub async_classifier_mode: Option<AsyncClassifierMode>,
|
||||
/// Reset retained async history when the next request exceeds this token estimate.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub async_classifier_conversation_token_limit: Option<usize>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub classifier_instructions: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub review_threshold_basis_points: Option<u16>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub max_tool_call_lag: Option<usize>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub reasoning_effort: Option<ReasoningEffort>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub transcript: Option<GuardianV2TranscriptModelConfig>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub max_action_tokens: Option<usize>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub max_classifier_instruction_tokens: Option<usize>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub reuse_parent_compaction: Option<bool>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub max_parent_compaction_tokens: Option<usize>,
|
||||
}
|
||||
|
||||
/// Optional model-owned defaults for selecting and bounding Guardian v2 history.
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
|
||||
pub struct GuardianV2TranscriptModelConfig {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub sources: Option<Vec<String>>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub include_images: Option<bool>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub max_message_entry_tokens: Option<usize>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub max_tool_entry_tokens: Option<usize>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub max_message_transcript_tokens: Option<usize>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub max_tool_transcript_tokens: Option<usize>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub max_recent_non_user_entries: Option<usize>,
|
||||
}
|
||||
30
akode-rs/protocol/src/openai_models/incremental_tools.rs
Normal file
30
akode-rs/protocol/src/openai_models/incremental_tools.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
//! Optional model-catalog overrides for harness-owned incremental tool notices.
|
||||
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use ts_rs::TS;
|
||||
|
||||
/// Incremental tool notice overrides; missing/null or >512-byte values use bundled defaults.
|
||||
/// Empty strings omit static text but retain runtime names and instructions.
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
|
||||
pub struct IncrementalToolMessages {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub tool_update_hint: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub removed_tools_header: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub removed_namespaces_header: Option<String>,
|
||||
/// Prefix supporting `{name}`; the namespace instructions are appended verbatim.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub namespace_instructions_prefix: Option<String>,
|
||||
/// Message supporting `{name}` when a namespace's instructions are cleared.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub namespace_instructions_cleared: Option<String>,
|
||||
/// Literal hint before changed Code Mode tool definitions and namespace instructions.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub exec_tools_update_hint: Option<String>,
|
||||
/// Literal header before removed Code Mode tool and namespace-instruction identities.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub exec_tools_removed_definitions_header: Option<String>,
|
||||
}
|
||||
52
akode-rs/protocol/src/openai_models/memento_v2.rs
Normal file
52
akode-rs/protocol/src/openai_models/memento_v2.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
//! Sparse Memento V2 tool definitions. Runtime data remains with consumers.
|
||||
|
||||
use super::ToolMessage;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use ts_rs::TS;
|
||||
|
||||
/// Model-owned history namespace and public tool definitions.
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
|
||||
pub struct HistoryToolMessages {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub namespace_description: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub list_windows: Option<ToolMessage>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub list_items: Option<ToolMessage>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub read_item: Option<ToolMessage>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub search_contents: Option<ToolMessage>,
|
||||
}
|
||||
|
||||
/// Model-owned notes namespace and public tool definitions.
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
|
||||
pub struct NotesToolMessages {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub namespace_description: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub list_files_by_prefix: Option<ToolMessage>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub read_file: Option<ToolMessage>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub search_contents: Option<ToolMessage>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub append_to_file: Option<ToolMessage>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub write_file: Option<ToolMessage>,
|
||||
}
|
||||
|
||||
/// Model-owned context-window control tool definitions.
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
|
||||
pub struct ContextManagementToolMessages {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub new_context: Option<ToolMessage>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub get_context_remaining: Option<ToolMessage>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "memento_v2_tests.rs"]
|
||||
mod tests;
|
||||
18
akode-rs/protocol/src/openai_models/memento_v2_tests.rs
Normal file
18
akode-rs/protocol/src/openai_models/memento_v2_tests.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use crate::openai_models::ModelMessages;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn memento_catalog_round_trip_preserves_sparse_tools_and_explicit_empty() {
|
||||
for tools in [
|
||||
json!({}),
|
||||
json!({
|
||||
"history": {"namespace_description": "", "read_item": {"description": "", "parameters": "not JSON"}},
|
||||
"notes": {"read_file": {"parameters": "{}"}},
|
||||
"context_management": {"new_context": {"description": "catalog"}}
|
||||
}),
|
||||
] {
|
||||
let messages: ModelMessages = serde_json::from_value(json!({"tools": tools})).unwrap();
|
||||
assert_eq!(serde_json::to_value(messages.tools).unwrap(), tools);
|
||||
}
|
||||
}
|
||||
66
akode-rs/protocol/src/openai_models/plugins.rs
Normal file
66
akode-rs/protocol/src/openai_models/plugins.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
//! Sparse model-catalog wording for generic, selected, and recommended plugins.
|
||||
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use ts_rs::TS;
|
||||
|
||||
/// Sparse plugin wording families, independent of runtime availability and authorization.
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
|
||||
pub struct PluginMessages {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub generic: Option<GenericPluginMessages>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub selected: Option<SelectedPluginMessages>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub recommendations: Option<PluginRecommendationMessages>,
|
||||
}
|
||||
|
||||
/// Literal generic plugin wording. Missing, null, blank, or invalid values use bundled text.
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
|
||||
pub struct GenericPluginMessages {
|
||||
/// Literal text, up to 500 UTF-8 bytes.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub intro: Option<String>,
|
||||
/// Up to 2,000 UTF-8 bytes.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub usage_instructions: Option<String>,
|
||||
}
|
||||
|
||||
/// Selected-plugin wording. Fact-bearing fields require exactly one documented placeholder.
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
|
||||
pub struct SelectedPluginMessages {
|
||||
/// Up to 500 UTF-8 bytes. Selected intro requires `{{ plugin_name }}`.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub intro: Option<String>,
|
||||
/// Up to 500 UTF-8 bytes.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub search_tools: Option<String>,
|
||||
/// Up to 500 UTF-8 bytes; requires `{{ skill_namespace }}`.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub skill_namespace: Option<String>,
|
||||
/// Up to 500 UTF-8 bytes; requires `{{ apps }}`.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub apps: Option<String>,
|
||||
/// Up to 500 UTF-8 bytes; requires `{{ mcp_servers }}`.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub mcp_servers: Option<String>,
|
||||
/// Up to 500 UTF-8 bytes.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub closing: Option<String>,
|
||||
/// Nonblank omission notice, up to 500 UTF-8 bytes, including any desired separator.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub omitted: Option<String>,
|
||||
}
|
||||
|
||||
/// Literal recommendation introduction; plugin identities remain supplied by the harness.
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
|
||||
pub struct PluginRecommendationMessages {
|
||||
/// Literal text, up to 500 UTF-8 bytes.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub intro: Option<String>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "plugins_tests.rs"]
|
||||
mod tests;
|
||||
34
akode-rs/protocol/src/openai_models/plugins_tests.rs
Normal file
34
akode-rs/protocol/src/openai_models/plugins_tests.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
#![cfg(test)]
|
||||
|
||||
use crate::openai_models::ModelMessages;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn plugin_messages_preserve_sparse_nested_and_literal_wire_values() {
|
||||
for plugins in [
|
||||
serde_json::Value::Null,
|
||||
json!({}),
|
||||
json!({"generic": {}, "selected": {}, "recommendations": {}}),
|
||||
json!({
|
||||
"generic": {"intro": "", "usage_instructions": " \r\n\t"},
|
||||
"selected": {
|
||||
"intro": " {{ plugin_name }}\r\n",
|
||||
"search_tools": "literal {{braces}}",
|
||||
"skill_namespace": "{{ skill_namespace }}",
|
||||
"apps": "{{ apps }}",
|
||||
"mcp_servers": "{{ mcp_servers }}",
|
||||
"closing": "é".repeat(251),
|
||||
"omitted": "omitted"
|
||||
},
|
||||
"recommendations": {"intro": "recommendations"}
|
||||
}),
|
||||
] {
|
||||
let messages: ModelMessages = serde_json::from_value(json!({"plugins": plugins})).unwrap();
|
||||
let mut expected = serde_json::to_value(ModelMessages::default()).unwrap();
|
||||
if !plugins.is_null() {
|
||||
expected["plugins"] = plugins;
|
||||
}
|
||||
assert_eq!(serde_json::to_value(messages).unwrap(), expected);
|
||||
}
|
||||
}
|
||||
44
akode-rs/protocol/src/openai_models/reasoning_effort.rs
Normal file
44
akode-rs/protocol/src/openai_models/reasoning_effort.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
//! Model-owned effort normalization shared by native requests and configuration update items.
|
||||
//!
|
||||
//! UI aliases resolve through the same model defaults and fallbacks in both paths.
|
||||
|
||||
use super::ModelInfo;
|
||||
use super::ReasoningEffort;
|
||||
|
||||
impl ModelInfo {
|
||||
/// Resolves a selected effort to the value sent in an ordinary inference request.
|
||||
pub fn resolve_reasoning_effort(&self, effort: ReasoningEffort) -> ReasoningEffort {
|
||||
match effort {
|
||||
ReasoningEffort::Ultra => self
|
||||
.multi_agent_reasoning_effort
|
||||
.as_ref()
|
||||
.filter(|effort| {
|
||||
*effort != &ReasoningEffort::Ultra
|
||||
&& self
|
||||
.supported_reasoning_levels
|
||||
.iter()
|
||||
.any(|preset| &preset.effort == *effort)
|
||||
})
|
||||
.cloned()
|
||||
.or_else(|| {
|
||||
self.supported_reasoning_levels
|
||||
.iter()
|
||||
.find(|preset| preset.effort == ReasoningEffort::Max)
|
||||
.or_else(|| {
|
||||
self.supported_reasoning_levels
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|preset| preset.effort != ReasoningEffort::Ultra)
|
||||
})
|
||||
.map(|preset| preset.effort.clone())
|
||||
})
|
||||
.unwrap_or(ReasoningEffort::Medium),
|
||||
// Keep "persistent" in local settings; the Responses API calls it "disabled".
|
||||
ReasoningEffort::Persistent => ReasoningEffort::Custom("disabled".to_string()),
|
||||
effort => effort,
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
#[path = "reasoning_effort_tests.rs"]
|
||||
mod tests;
|
||||
@@ -0,0 +1,52 @@
|
||||
use super::super::ReasoningEffortPreset;
|
||||
use super::super::tests::test_model;
|
||||
use super::ReasoningEffort;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn resolves_ultra_using_model_override_and_supported_fallbacks() {
|
||||
use ReasoningEffort::High;
|
||||
use ReasoningEffort::Low;
|
||||
use ReasoningEffort::Max;
|
||||
use ReasoningEffort::Medium;
|
||||
use ReasoningEffort::Ultra;
|
||||
use ReasoningEffort::XHigh;
|
||||
|
||||
for (supported, multi_agent_effort, expected) in [
|
||||
(vec![High, Max, Ultra], Some(High), High),
|
||||
(vec![High, Max, Ultra], None, Max),
|
||||
(vec![High, XHigh, Ultra], None, XHigh),
|
||||
(vec![High, XHigh, Ultra], Some(Ultra), XHigh),
|
||||
(vec![High, XHigh, Ultra], Some(Low), XHigh),
|
||||
(vec![], None, Medium),
|
||||
] {
|
||||
let mut model = test_model(/*spec*/ None);
|
||||
model.supported_reasoning_levels = supported
|
||||
.into_iter()
|
||||
.map(|effort| ReasoningEffortPreset {
|
||||
effort,
|
||||
description: String::new(),
|
||||
})
|
||||
.collect();
|
||||
model.multi_agent_reasoning_effort = multi_agent_effort;
|
||||
assert_eq!(model.resolve_reasoning_effort(Ultra), expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preserves_native_efforts_and_translates_persistent_mode() {
|
||||
let model = test_model(/*spec*/ None);
|
||||
for effort in [
|
||||
ReasoningEffort::Low,
|
||||
ReasoningEffort::Medium,
|
||||
ReasoningEffort::High,
|
||||
ReasoningEffort::Max,
|
||||
ReasoningEffort::Custom("future-effort".to_string()),
|
||||
] {
|
||||
assert_eq!(model.resolve_reasoning_effort(effort.clone()), effort);
|
||||
}
|
||||
assert_eq!(
|
||||
model.resolve_reasoning_effort(ReasoningEffort::Persistent),
|
||||
ReasoningEffort::Custom("disabled".to_string()),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user