refactor(adapters): brand btmsg/bttask/groups bridge interfaces with GroupId/AgentId
Apply branded types to all IPC bridge interfaces and function parameters. Update test mock data with branded constructors.
This commit is contained in:
parent
f928abd6ce
commit
0742309595
5 changed files with 82 additions and 77 deletions
|
|
@ -5,12 +5,13 @@
|
|||
*/
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import type { GroupId, AgentId } from '../types/ids';
|
||||
|
||||
export interface BtmsgAgent {
|
||||
id: string;
|
||||
id: AgentId;
|
||||
name: string;
|
||||
role: string;
|
||||
groupId: string;
|
||||
groupId: GroupId;
|
||||
tier: number;
|
||||
model: string | null;
|
||||
status: string;
|
||||
|
|
@ -19,8 +20,8 @@ export interface BtmsgAgent {
|
|||
|
||||
export interface BtmsgMessage {
|
||||
id: string;
|
||||
fromAgent: string;
|
||||
toAgent: string;
|
||||
fromAgent: AgentId;
|
||||
toAgent: AgentId;
|
||||
content: string;
|
||||
read: boolean;
|
||||
replyTo: string | null;
|
||||
|
|
@ -31,8 +32,8 @@ export interface BtmsgMessage {
|
|||
|
||||
export interface BtmsgFeedMessage {
|
||||
id: string;
|
||||
fromAgent: string;
|
||||
toAgent: string;
|
||||
fromAgent: AgentId;
|
||||
toAgent: AgentId;
|
||||
content: string;
|
||||
createdAt: string;
|
||||
replyTo: string | null;
|
||||
|
|
@ -45,8 +46,8 @@ export interface BtmsgFeedMessage {
|
|||
export interface BtmsgChannel {
|
||||
id: string;
|
||||
name: string;
|
||||
groupId: string;
|
||||
createdBy: string;
|
||||
groupId: GroupId;
|
||||
createdBy: AgentId;
|
||||
memberCount: number;
|
||||
createdAt: string;
|
||||
}
|
||||
|
|
@ -54,7 +55,7 @@ export interface BtmsgChannel {
|
|||
export interface BtmsgChannelMessage {
|
||||
id: string;
|
||||
channelId: string;
|
||||
fromAgent: string;
|
||||
fromAgent: AgentId;
|
||||
content: string;
|
||||
createdAt: string;
|
||||
senderName: string;
|
||||
|
|
@ -64,70 +65,70 @@ export interface BtmsgChannelMessage {
|
|||
/**
|
||||
* Get all agents in a group with their unread counts.
|
||||
*/
|
||||
export async function getGroupAgents(groupId: string): Promise<BtmsgAgent[]> {
|
||||
export async function getGroupAgents(groupId: GroupId): Promise<BtmsgAgent[]> {
|
||||
return invoke('btmsg_get_agents', { groupId });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unread message count for an agent.
|
||||
*/
|
||||
export async function getUnreadCount(agentId: string): Promise<number> {
|
||||
export async function getUnreadCount(agentId: AgentId): Promise<number> {
|
||||
return invoke('btmsg_unread_count', { agentId });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unread messages for an agent.
|
||||
*/
|
||||
export async function getUnreadMessages(agentId: string): Promise<BtmsgMessage[]> {
|
||||
export async function getUnreadMessages(agentId: AgentId): Promise<BtmsgMessage[]> {
|
||||
return invoke('btmsg_unread_messages', { agentId });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get conversation history between two agents.
|
||||
*/
|
||||
export async function getHistory(agentId: string, otherId: string, limit: number = 20): Promise<BtmsgMessage[]> {
|
||||
export async function getHistory(agentId: AgentId, otherId: AgentId, limit: number = 20): Promise<BtmsgMessage[]> {
|
||||
return invoke('btmsg_history', { agentId, otherId, limit });
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message from one agent to another.
|
||||
*/
|
||||
export async function sendMessage(fromAgent: string, toAgent: string, content: string): Promise<string> {
|
||||
export async function sendMessage(fromAgent: AgentId, toAgent: AgentId, content: string): Promise<string> {
|
||||
return invoke('btmsg_send', { fromAgent, toAgent, content });
|
||||
}
|
||||
|
||||
/**
|
||||
* Update agent status (active/sleeping/stopped).
|
||||
*/
|
||||
export async function setAgentStatus(agentId: string, status: string): Promise<void> {
|
||||
export async function setAgentStatus(agentId: AgentId, status: string): Promise<void> {
|
||||
return invoke('btmsg_set_status', { agentId, status });
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure admin agent exists with contacts to all agents.
|
||||
*/
|
||||
export async function ensureAdmin(groupId: string): Promise<void> {
|
||||
export async function ensureAdmin(groupId: GroupId): Promise<void> {
|
||||
return invoke('btmsg_ensure_admin', { groupId });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all messages in group (admin global feed).
|
||||
*/
|
||||
export async function getAllFeed(groupId: string, limit: number = 100): Promise<BtmsgFeedMessage[]> {
|
||||
export async function getAllFeed(groupId: GroupId, limit: number = 100): Promise<BtmsgFeedMessage[]> {
|
||||
return invoke('btmsg_all_feed', { groupId, limit });
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark all messages from sender to reader as read.
|
||||
*/
|
||||
export async function markRead(readerId: string, senderId: string): Promise<void> {
|
||||
export async function markRead(readerId: AgentId, senderId: AgentId): Promise<void> {
|
||||
return invoke('btmsg_mark_read', { readerId, senderId });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get channels in a group.
|
||||
*/
|
||||
export async function getChannels(groupId: string): Promise<BtmsgChannel[]> {
|
||||
export async function getChannels(groupId: GroupId): Promise<BtmsgChannel[]> {
|
||||
return invoke('btmsg_get_channels', { groupId });
|
||||
}
|
||||
|
||||
|
|
@ -141,20 +142,20 @@ export async function getChannelMessages(channelId: string, limit: number = 100)
|
|||
/**
|
||||
* Send a message to a channel.
|
||||
*/
|
||||
export async function sendChannelMessage(channelId: string, fromAgent: string, content: string): Promise<string> {
|
||||
export async function sendChannelMessage(channelId: string, fromAgent: AgentId, content: string): Promise<string> {
|
||||
return invoke('btmsg_channel_send', { channelId, fromAgent, content });
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new channel.
|
||||
*/
|
||||
export async function createChannel(name: string, groupId: string, createdBy: string): Promise<string> {
|
||||
export async function createChannel(name: string, groupId: GroupId, createdBy: AgentId): Promise<string> {
|
||||
return invoke('btmsg_create_channel', { name, groupId, createdBy });
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a member to a channel.
|
||||
*/
|
||||
export async function addChannelMember(channelId: string, agentId: string): Promise<void> {
|
||||
export async function addChannelMember(channelId: string, agentId: AgentId): Promise<void> {
|
||||
return invoke('btmsg_add_channel_member', { channelId, agentId });
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue