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:
91
akode-rs/message-board/src/tools/arguments.rs
Normal file
91
akode-rs/message-board/src/tools/arguments.rs
Normal file
@@ -0,0 +1,91 @@
|
||||
//! Flat model arguments; runtime identities are supplied by the host.
|
||||
|
||||
use crate::ChannelDescription;
|
||||
use crate::ThreadSort;
|
||||
use serde::Deserialize;
|
||||
use std::num::NonZeroU32;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub(super) struct CreateChannel {
|
||||
pub(super) channel_name: String,
|
||||
pub(super) description: Option<ChannelDescription>,
|
||||
pub(super) subscribe: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub(super) struct GetChannels {
|
||||
pub(super) query: Option<String>,
|
||||
pub(super) recent_first: Option<bool>,
|
||||
pub(super) limit: Option<NonZeroU32>,
|
||||
pub(super) cursor: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub(super) struct ListThreads {
|
||||
pub(super) channel_name: String,
|
||||
pub(super) sort: Option<ThreadSort>,
|
||||
pub(super) recent_first: Option<bool>,
|
||||
pub(super) limit: Option<NonZeroU32>,
|
||||
pub(super) cursor: Option<String>,
|
||||
pub(super) max_chars_per_post: Option<NonZeroU32>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub(super) struct SearchPosts {
|
||||
pub(super) channel_name: Option<String>,
|
||||
pub(super) query: Option<String>,
|
||||
pub(super) after_message_id: Option<Uuid>,
|
||||
pub(super) author: Option<String>,
|
||||
pub(super) limit: Option<NonZeroU32>,
|
||||
pub(super) cursor: Option<String>,
|
||||
pub(super) max_chars_per_post: Option<NonZeroU32>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub(super) struct ReadThread {
|
||||
pub(super) thread_id: Uuid,
|
||||
pub(super) limit: Option<NonZeroU32>,
|
||||
pub(super) cursor: Option<String>,
|
||||
pub(super) max_chars_per_post: Option<NonZeroU32>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub(super) struct ReadPost {
|
||||
pub(super) message_id: Uuid,
|
||||
pub(super) offset_chars: Option<u32>,
|
||||
pub(super) limit_chars: Option<NonZeroU32>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub(super) struct Subscription {
|
||||
pub(super) channel_name: Option<String>,
|
||||
pub(super) thread_id: Option<Uuid>,
|
||||
pub(super) target_agent: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub(super) struct Post {
|
||||
pub(super) text: String,
|
||||
pub(super) channel_name: Option<String>,
|
||||
pub(super) new_channel_name: Option<String>,
|
||||
pub(super) thread_id: Option<Uuid>,
|
||||
pub(super) agents_to_notify: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub(super) struct Append {
|
||||
pub(super) text: String,
|
||||
pub(super) channel_name: Option<String>,
|
||||
pub(super) new_channel_name: Option<String>,
|
||||
pub(super) thread_id: Option<Uuid>,
|
||||
}
|
||||
68
akode-rs/message-board/src/tools/selection.rs
Normal file
68
akode-rs/message-board/src/tools/selection.rs
Normal file
@@ -0,0 +1,68 @@
|
||||
//! Tool choices supplied by consumers. Each tool has one fixed contract.
|
||||
|
||||
/// Shared tools a consumer can expose through `message_board_tools`.
|
||||
/// Tool selection does not grant storage permissions to the underlying connection.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum MessageBoardTool {
|
||||
CreateChannel,
|
||||
/// Creates a channel or updates its description, without subscriptions or notifications.
|
||||
UpsertChannel,
|
||||
GetChannels,
|
||||
ListThreads,
|
||||
SearchPosts,
|
||||
ReadThread,
|
||||
ReadPost,
|
||||
Subscribe,
|
||||
Unsubscribe,
|
||||
/// Posts, subscribes the author unless opted out, and notifies recipients.
|
||||
Post,
|
||||
/// Writes evidence without automatic subscriptions or notifications.
|
||||
Append,
|
||||
}
|
||||
|
||||
impl MessageBoardTool {
|
||||
pub(super) const READ_ONLY: [Self; 5] = [
|
||||
Self::GetChannels,
|
||||
Self::ListThreads,
|
||||
Self::SearchPosts,
|
||||
Self::ReadThread,
|
||||
Self::ReadPost,
|
||||
];
|
||||
|
||||
/// Existing agent discussion tools, in their original registration order.
|
||||
pub const DISCUSSION: [Self; 9] = [
|
||||
Self::CreateChannel,
|
||||
Self::GetChannels,
|
||||
Self::ListThreads,
|
||||
Self::SearchPosts,
|
||||
Self::ReadThread,
|
||||
Self::ReadPost,
|
||||
Self::Subscribe,
|
||||
Self::Unsubscribe,
|
||||
Self::Post,
|
||||
];
|
||||
|
||||
/// Bundled schema for discovery before a caller has been bound to a board.
|
||||
pub fn spec(self) -> akode_tools::ToolSpec {
|
||||
super::spec::tool(
|
||||
self, /*namespace*/ None, /*namespace_description*/ "",
|
||||
/*description_override*/ None,
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn name(self) -> &'static str {
|
||||
match self {
|
||||
Self::CreateChannel => "create_channel",
|
||||
Self::UpsertChannel => "upsert_channel",
|
||||
Self::GetChannels => "get_channels",
|
||||
Self::ListThreads => "list_threads",
|
||||
Self::SearchPosts => "search_posts",
|
||||
Self::ReadThread => "read_thread",
|
||||
Self::ReadPost => "read_post",
|
||||
Self::Subscribe => "subscribe",
|
||||
Self::Unsubscribe => "unsubscribe",
|
||||
Self::Post => "post",
|
||||
Self::Append => "append",
|
||||
}
|
||||
}
|
||||
}
|
||||
153
akode-rs/message-board/src/tools/spec.rs
Normal file
153
akode-rs/message-board/src/tools/spec.rs
Normal file
@@ -0,0 +1,153 @@
|
||||
//! Schemas for shared board tools. The host supplies their selection and namespace.
|
||||
|
||||
use super::selection::MessageBoardTool;
|
||||
use akode_tools::ResponsesApiNamespace;
|
||||
use akode_tools::ResponsesApiNamespaceTool;
|
||||
use akode_tools::ResponsesApiTool;
|
||||
use akode_tools::ToolSpec;
|
||||
use akode_tools::parse_tool_input_schema;
|
||||
use serde_json::json;
|
||||
|
||||
pub(super) fn tool(
|
||||
tool: MessageBoardTool,
|
||||
namespace: Option<&str>,
|
||||
namespace_description: &str,
|
||||
description_override: Option<&str>,
|
||||
) -> ToolSpec {
|
||||
let (description, fields, required): (&str, &[&str], &[&str]) = match tool {
|
||||
MessageBoardTool::CreateChannel => (
|
||||
"Create a channel where all agents in this collaboration can read and post messages. You are subscribed to new top-level posts by default.",
|
||||
&["channel_name", "description", "subscribe"],
|
||||
&["channel_name"],
|
||||
),
|
||||
MessageBoardTool::UpsertChannel => (
|
||||
"Create a channel or update only its description. Existing posts, author, creation time and subscriptions are preserved. Does not subscribe anyone or send notifications. Returns null on success.",
|
||||
&["channel_name", "description"],
|
||||
&["channel_name", "description"],
|
||||
),
|
||||
MessageBoardTool::GetChannels => (
|
||||
"List channels, most recently active first, or search by a case-insensitive part of the name. Creating a channel or posting in it counts as activity.",
|
||||
&["query", "recent_first", "limit", "cursor"],
|
||||
&[],
|
||||
),
|
||||
MessageBoardTool::ListThreads => (
|
||||
"List a channel's threads with previews of the first post and latest reply. New threads come first by default; sorting by activity brings threads with recent replies to the top.",
|
||||
&[
|
||||
"channel_name",
|
||||
"sort",
|
||||
"recent_first",
|
||||
"limit",
|
||||
"cursor",
|
||||
"max_chars_per_post",
|
||||
],
|
||||
&["channel_name"],
|
||||
),
|
||||
MessageBoardTool::SearchPosts => (
|
||||
"Search top-level posts and replies, newest first. Text matches are case-insensitive substrings; omit the query to see recent activity. You can narrow by channel, author, or posts after a message ID. Results are previews; read_post can retrieve the full text.",
|
||||
&[
|
||||
"channel_name",
|
||||
"query",
|
||||
"after_message_id",
|
||||
"author",
|
||||
"limit",
|
||||
"cursor",
|
||||
"max_chars_per_post",
|
||||
],
|
||||
&[],
|
||||
),
|
||||
MessageBoardTool::ReadThread => (
|
||||
"Read a thread using its first post's message ID. Every page includes previews of the first post and the newest replies; the cursor advances through replies.",
|
||||
&["thread_id", "limit", "cursor", "max_chars_per_post"],
|
||||
&["thread_id"],
|
||||
),
|
||||
MessageBoardTool::ReadPost => (
|
||||
"Read a post or reply by message ID, without needing its channel. Offsets count Unicode characters; continue at next_offset_chars while it is less than n_chars.",
|
||||
&["message_id", "offset_chars", "limit_chars"],
|
||||
&["message_id"],
|
||||
),
|
||||
MessageBoardTool::Subscribe => (
|
||||
"Subscribe yourself or another agent to a channel for new top-level posts, or to a thread for replies. Provide exactly one of channel_name or thread_id. Notification delivery, queueing, and wake behavior follow the host's agent-message policy.",
|
||||
&["channel_name", "thread_id", "target_agent"],
|
||||
&[],
|
||||
),
|
||||
MessageBoardTool::Unsubscribe => (
|
||||
"Unsubscribe yourself or another agent from a channel or thread. Provide exactly one of channel_name or thread_id. Posting again does not undo a thread unsubscribe. Agents explicitly named on a post can still receive that notification.",
|
||||
&["channel_name", "thread_id", "target_agent"],
|
||||
&[],
|
||||
),
|
||||
MessageBoardTool::Post => (
|
||||
"Start a thread in an existing or new channel, or reply using the first post's message ID as thread_id. Exactly one destination is required. Posting subscribes you to the thread unless you previously unsubscribed. agents_to_notify requests a one-time notification without subscribing recipients; delivery, queueing, and wake behavior follow the host's agent-message policy. Returns metadata, not the post text.",
|
||||
&[
|
||||
"text",
|
||||
"channel_name",
|
||||
"new_channel_name",
|
||||
"thread_id",
|
||||
"agents_to_notify",
|
||||
],
|
||||
&["text"],
|
||||
),
|
||||
MessageBoardTool::Append => (
|
||||
"Store a post in an existing or new channel, or reply using the first post's message ID as thread_id. Exactly one destination is required. Does not subscribe anyone or send notifications, including to existing subscribers. Returns metadata, not the post text.",
|
||||
&["text", "channel_name", "new_channel_name", "thread_id"],
|
||||
&["text"],
|
||||
),
|
||||
};
|
||||
let mut properties = serde_json::Map::new();
|
||||
for field in fields {
|
||||
let schema = match *field {
|
||||
"description" if tool == MessageBoardTool::UpsertChannel => {
|
||||
json!({"type":"string","description":"Channel purpose, at most 512 UTF-8 bytes."})
|
||||
}
|
||||
"description" => {
|
||||
json!({"type":"string","description":"Optional channel purpose, at most 512 UTF-8 bytes."})
|
||||
}
|
||||
"new_channel_name" if tool == MessageBoardTool::Append => {
|
||||
json!({"type":"string","description":"Create this channel without subscribing anyone."})
|
||||
}
|
||||
"new_channel_name" => {
|
||||
json!({"type":"string","description":"Create and subscribe to this channel."})
|
||||
}
|
||||
"subscribe" => {
|
||||
json!({"type":"boolean","description":"Subscribe to new top-level posts. Default true."})
|
||||
}
|
||||
"author" | "target_agent" => {
|
||||
json!({"type":"string","description":"An absolute agent path or a reference relative to you."})
|
||||
}
|
||||
"recent_first" => json!({"type":"boolean","description":"Newest first by default."}),
|
||||
"limit" => {
|
||||
json!({"type":"integer","minimum":1,"description":"Maximum results, default 20; output budgets may return fewer. Continue with next_cursor."})
|
||||
}
|
||||
"offset_chars" => json!({"type":"integer","minimum":0,"description":"Default 0."}),
|
||||
"limit_chars" | "max_chars_per_post" => {
|
||||
json!({"type":"integer","minimum":1,"description":"Maximum characters; further capped by output budget. Defaults: limit_chars 20000, max_chars_per_post 1000."})
|
||||
}
|
||||
"sort" => json!({"type":"string","enum":["created","activity"]}),
|
||||
"agents_to_notify" => {
|
||||
json!({"type":"array","items":{"type":"string"},"description":"Absolute agent paths or references relative to you; maximum 256."})
|
||||
}
|
||||
"cursor" => {
|
||||
json!({"type":"string","description":"Opaque next_cursor from the same query. Keep filters and sorting unchanged. Concurrent posts may shift pages; omit the cursor to refresh."})
|
||||
}
|
||||
_ => json!({"type":"string"}),
|
||||
};
|
||||
properties.insert((*field).into(), schema);
|
||||
}
|
||||
let parameters = json!({"type":"object","properties":properties,"required":required,"additionalProperties":false});
|
||||
let tool = ResponsesApiTool {
|
||||
name: tool.name().into(),
|
||||
description: description_override.unwrap_or(description).into(),
|
||||
strict: false,
|
||||
defer_loading: None,
|
||||
parameters: parse_tool_input_schema(¶meters)
|
||||
.unwrap_or_else(|error| panic!("message-board schema must parse: {error}")),
|
||||
output_schema: None,
|
||||
};
|
||||
match namespace {
|
||||
Some(namespace) => ToolSpec::Namespace(ResponsesApiNamespace {
|
||||
name: namespace.into(),
|
||||
description: namespace_description.into(),
|
||||
tools: vec![ResponsesApiNamespaceTool::Function(tool)],
|
||||
}),
|
||||
None => ToolSpec::Function(tool),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user