Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(store): load agent message history via RPC
Naiyuan Qing4d6d57187c2a
diff --git a/packages/sdk/src/actions/index.ts b/packages/sdk/src/actions/index.tsindex 0c673bbde0..ab6307fa95 100644--- a/packages/sdk/src/actions/index.ts+++ b/packages/sdk/src/actions/index.ts@@ -14,6 +14,7 @@ export {type ResponseErrorPayload,isResponseSuccess,isResponseError,+ type AgentMessageItem,type GetAgentMessagesParams,type GetAgentMessagesResult,type GetHubInfoResult,diff --git a/packages/sdk/src/actions/rpc.ts b/packages/sdk/src/actions/rpc.tsindex 11c0e66552..a81a15b1e4 100644--- a/packages/sdk/src/actions/rpc.ts+++ b/packages/sdk/src/actions/rpc.ts@@ -65,9 +65,38 @@ export interface GetAgentMessagesParams {limit?: number;}+/** Content block types from the agent engine */+export interface TextContentBlock {+ type: "text";+ text: string;+}++export interface ThinkingContentBlock {+ type: "thinking";+ thinking: string;+}++export interface ToolCallBlock {+ type: "tool_use";+ id: string;+ name: string;+ input: unknown;+}++export interface ImageContentBlock {+ type: "image";+ url: string;+}++/** Agent message returned by getAgentMessages (mirrors pi-ai Message) */+export type AgentMessageItem =+ | { role: "user"; content: string | (TextContentBlock | ImageContentBlock)[]; timestamp: number }+ | { role: "assistant"; content: (TextContentBlock | ThinkingContentBlock | ToolCallBlock)[]; timestamp: number }+ | { role: "tool_result"; toolCallId: string; content: (TextContentBlock | ImageContentBlock)[]; isError: boolean; timestamp: number }+/** getAgentMessages - response payload */export interface GetAgentMessagesResult {- messages: unknown[];+ messages: AgentMessageItem[];total: number;offset: number;limit: number;diff --git a/packages/store/src/hub.ts b/packages/store/src/hub.tsindex b5101eec9c..2bb0ef7081 100644--- a/packages/store/src/hub.ts+++ b/packages/store/src/hub.ts@@ -1,12 +1,25 @@import { create } from "zustand"import { toast } from "sonner"+import { v7 as uuidv7 } from "uuid"import type {GetHubInfoResult,ListAgentsResult,CreateAgentResult,DeleteAgentResult,+ GetAgentMessagesResult,+ AgentMessageItem,} from "@multica/sdk"import { useGatewayStore } from "./gateway"+import { useMessagesStore } from "./messages"++/** Extract plain text from agent message content (string or content block array) */+function extractText(content: string | { type: string; text?: string }[]): string {+ if (typeof content === "string") return content+ return content+ .filter((b) => b.type === "text" && b.text)+ .map((b) => b.text!)+ .join("\n")+}export type HubInfo = GetHubInfoResult@@ -28,6 +41,7 @@ interface HubActions {setActiveAgentId: (id: string | null) => voidfetchHub: () => Promise<void>fetchAgents: () => Promise<void>+ fetchAgentMessages: (agentId: string) => Promise<void>createAgent: (options?: Record<string, unknown>) => Promise<void>deleteAgent: (id: string) => Promise<void>}@@ -40,7 +54,16 @@ export const useHubStore = create<HubStore>()((set, get) => ({agents: [],activeAgentId: null,- setActiveAgentId: (id) => set({ activeAgentId: id }),+ setActiveAgentId: (id) => {+ set({ activeAgentId: id })+ if (id) {+ // Load history if no messages exist for this agent yet+ const existing = useMessagesStore.getState().messages.filter((m) => m.agentId === id)+ if (existing.length === 0) {+ get().fetchAgentMessages(id)+ }+ }+ },fetchHub: async () => {set({ status: "loading" })@@ -64,6 +87,27 @@ export const useHubStore = create<HubStore>()((set, get) => ({}},+ fetchAgentMessages: async (agentId) => {+ try {+ const { request } = useGatewayStore.getState()+ const data = await request<GetAgentMessagesResult>("getAgentMessages", { agentId })+ const msgs = data.messages+ .filter((m): m is AgentMessageItem & { role: "user" | "assistant" } =>+ m.role === "user" || m.role === "assistant"+ )+ .map((m) => ({+ id: uuidv7(),+ role: m.role,+ content: extractText(m.content),+ agentId,+ }))+ .filter((m) => m.content.length > 0)+ useMessagesStore.getState().loadMessages(agentId, msgs)+ } catch (e) {+ console.error("Failed to fetch agent messages:", e)+ }+ },+createAgent: async (options?) => {try {const { request } = useGatewayStore.getState()