refactor(components): apply branded types at Svelte component call sites
GroupAgentsPanel, TaskBoardTab, SettingsTab now use GroupId/AgentId branded constructors at their IPC call sites.
This commit is contained in:
parent
ce389a2a39
commit
46df7949a7
3 changed files with 11 additions and 7 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
import { getActiveGroup, getEnabledProjects, setActiveProject } from '../../stores/workspace.svelte';
|
import { getActiveGroup, getEnabledProjects, setActiveProject } from '../../stores/workspace.svelte';
|
||||||
import type { GroupAgentConfig, GroupAgentStatus, ProjectConfig } from '../../types/groups';
|
import type { GroupAgentConfig, GroupAgentStatus, ProjectConfig } from '../../types/groups';
|
||||||
import { getGroupAgents, setAgentStatus, type BtmsgAgent } from '../../adapters/btmsg-bridge';
|
import { getGroupAgents, setAgentStatus, type BtmsgAgent } from '../../adapters/btmsg-bridge';
|
||||||
|
import type { AgentId } from '../../types/ids';
|
||||||
|
|
||||||
/** Runtime agent status from btmsg database */
|
/** Runtime agent status from btmsg database */
|
||||||
let btmsgAgents = $state<BtmsgAgent[]>([]);
|
let btmsgAgents = $state<BtmsgAgent[]>([]);
|
||||||
|
|
@ -46,12 +47,12 @@
|
||||||
if (pollTimer) clearInterval(pollTimer);
|
if (pollTimer) clearInterval(pollTimer);
|
||||||
});
|
});
|
||||||
|
|
||||||
function getStatus(agentId: string): GroupAgentStatus {
|
function getStatus(agentId: AgentId): GroupAgentStatus {
|
||||||
const btAgent = btmsgAgents.find(a => a.id === agentId);
|
const btAgent = btmsgAgents.find(a => a.id === agentId);
|
||||||
return (btAgent?.status as GroupAgentStatus) ?? 'stopped';
|
return (btAgent?.status as GroupAgentStatus) ?? 'stopped';
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUnread(agentId: string): number {
|
function getUnread(agentId: AgentId): number {
|
||||||
const btAgent = btmsgAgents.find(a => a.id === agentId);
|
const btAgent = btmsgAgents.find(a => a.id === agentId);
|
||||||
return btAgent?.unreadCount ?? 0;
|
return btAgent?.unreadCount ?? 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
switchGroup,
|
switchGroup,
|
||||||
} from '../../stores/workspace.svelte';
|
} from '../../stores/workspace.svelte';
|
||||||
import { deriveIdentifier, type GroupAgentRole, AGENT_ROLE_ICONS } from '../../types/groups';
|
import { deriveIdentifier, type GroupAgentRole, AGENT_ROLE_ICONS } from '../../types/groups';
|
||||||
|
import { ProjectId, GroupId } from '../../types/ids';
|
||||||
import { generateAgentPrompt } from '../../utils/agent-prompts';
|
import { generateAgentPrompt } from '../../utils/agent-prompts';
|
||||||
import { getSetting, setSetting } from '../../adapters/settings-bridge';
|
import { getSetting, setSetting } from '../../adapters/settings-bridge';
|
||||||
import { getCurrentTheme, setTheme } from '../../stores/theme.svelte';
|
import { getCurrentTheme, setTheme } from '../../stores/theme.svelte';
|
||||||
|
|
@ -284,7 +285,7 @@
|
||||||
|
|
||||||
function handleAddProject() {
|
function handleAddProject() {
|
||||||
if (!newName.trim() || !newCwd.trim() || !activeGroupId) return;
|
if (!newName.trim() || !newCwd.trim() || !activeGroupId) return;
|
||||||
const id = crypto.randomUUID();
|
const id = ProjectId(crypto.randomUUID());
|
||||||
addProject(activeGroupId, {
|
addProject(activeGroupId, {
|
||||||
id,
|
id,
|
||||||
name: newName.trim(),
|
name: newName.trim(),
|
||||||
|
|
@ -304,7 +305,7 @@
|
||||||
|
|
||||||
function handleAddGroup() {
|
function handleAddGroup() {
|
||||||
if (!newGroupName.trim()) return;
|
if (!newGroupName.trim()) return;
|
||||||
const id = crypto.randomUUID();
|
const id = GroupId(crypto.randomUUID());
|
||||||
addGroup({ id, name: newGroupName.trim(), projects: [] });
|
addGroup({ id, name: newGroupName.trim(), projects: [] });
|
||||||
newGroupName = '';
|
newGroupName = '';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount, onDestroy } from 'svelte';
|
import { onMount, onDestroy } from 'svelte';
|
||||||
import { listTasks, updateTaskStatus, createTask, deleteTask, addTaskComment, type Task, type TaskComment, getTaskComments } from '../../adapters/bttask-bridge';
|
import { listTasks, updateTaskStatus, createTask, deleteTask, addTaskComment, type Task, type TaskComment, getTaskComments } from '../../adapters/bttask-bridge';
|
||||||
|
import type { GroupId } from '../../types/ids';
|
||||||
|
import { AgentId } from '../../types/ids';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
groupId: string;
|
groupId: GroupId;
|
||||||
projectId?: string;
|
projectId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,7 +94,7 @@
|
||||||
async function handleAddTask() {
|
async function handleAddTask() {
|
||||||
if (!newTitle.trim()) return;
|
if (!newTitle.trim()) return;
|
||||||
try {
|
try {
|
||||||
await createTask(newTitle.trim(), newDesc.trim(), newPriority, groupId, 'admin');
|
await createTask(newTitle.trim(), newDesc.trim(), newPriority, groupId, AgentId('admin'));
|
||||||
newTitle = '';
|
newTitle = '';
|
||||||
newDesc = '';
|
newDesc = '';
|
||||||
newPriority = 'medium';
|
newPriority = 'medium';
|
||||||
|
|
@ -129,7 +131,7 @@
|
||||||
async function handleAddComment() {
|
async function handleAddComment() {
|
||||||
if (!expandedTaskId || !newComment.trim()) return;
|
if (!expandedTaskId || !newComment.trim()) return;
|
||||||
try {
|
try {
|
||||||
await addTaskComment(expandedTaskId, 'admin', newComment.trim());
|
await addTaskComment(expandedTaskId, AgentId('admin'), newComment.trim());
|
||||||
newComment = '';
|
newComment = '';
|
||||||
taskComments = await getTaskComments(expandedTaskId);
|
taskComments = await getTaskComments(expandedTaskId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue