Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
refactor(core-sdk): enforce conversation-only client protocol
Jiayuan Zhange622b8c6ba1a
diff --git a/apps/web/components/pages/chat-page.tsx b/apps/web/components/pages/chat-page.tsxindex 67c7bb788d..e2b13147c3 100644--- a/apps/web/components/pages/chat-page.tsx+++ b/apps/web/components/pages/chat-page.tsx@@ -32,7 +32,7 @@ const ChatPage = () => {/>)}- {pageState === "connected" && client && identity && (+ {pageState === "connected" && client && identity && identity.conversationId && (<ConnectedChatclient={client}hubId={identity.hubId}@@ -56,7 +56,7 @@ function ConnectedChat({client: NonNullable<ReturnType<typeof useGatewayConnection>["client"]>;hubId: string;agentId: string;- conversationId?: string;+ conversationId: string;onDisconnect: () => void;}) {const chat = useGatewayChat({ client, hubId, agentId, conversationId });diff --git a/packages/core/src/agent/tools/exec-approval-types.ts b/packages/core/src/agent/tools/exec-approval-types.tsindex 4253c06d98..671883b2f2 100644--- a/packages/core/src/agent/tools/exec-approval-types.ts+++ b/packages/core/src/agent/tools/exec-approval-types.ts@@ -26,8 +26,6 @@ export interface ExecApprovalRequest {agentId: string;/** Conversation ID that initiated the command. */conversationId: string;- /** Session ID alias (same value as conversationId). */- sessionId?: string;/** Shell command to execute */command: string;/** Working directory */diff --git a/packages/core/src/client/actions/exec-approval.ts b/packages/core/src/client/actions/exec-approval.tsindex 5802435661..0b314d7753 100644--- a/packages/core/src/client/actions/exec-approval.ts+++ b/packages/core/src/client/actions/exec-approval.ts@@ -16,8 +16,6 @@ export interface ExecApprovalRequestPayload {agentId: string;/** Conversation ID that initiated the approval request. */conversationId: string;- /** Session ID alias (same value as conversationId). */- sessionId?: string;/** Shell command requiring approval */command: string;/** Working directory */diff --git a/packages/core/src/client/actions/index.ts b/packages/core/src/client/actions/index.tsindex b3ef94e331..b1193cac42 100644--- a/packages/core/src/client/actions/index.ts+++ b/packages/core/src/client/actions/index.ts@@ -19,11 +19,11 @@ export {type GetAgentMessagesParams,type GetAgentMessagesResult,type GetHubInfoResult,- type ListAgentsResult,- type CreateAgentParams,- type CreateAgentResult,- type DeleteAgentParams,- type DeleteAgentResult,+ type ListConversationsResult,+ type CreateConversationParams,+ type CreateConversationResult,+ type DeleteConversationParams,+ type DeleteConversationResult,type UpdateGatewayParams,type UpdateGatewayResult,type DeviceMeta,diff --git a/packages/core/src/client/actions/rpc.ts b/packages/core/src/client/actions/rpc.tsindex fd9af1b697..52dcc133c6 100644--- a/packages/core/src/client/actions/rpc.ts+++ b/packages/core/src/client/actions/rpc.ts@@ -66,8 +66,8 @@ export const DEFAULT_MESSAGES_LIMIT = 200;/** getAgentMessages - request params */export interface GetAgentMessagesParams {agentId: string;- /** Optional conversation ID. Falls back to agent main conversation when omitted. */- conversationId?: string;+ /** Conversation ID to read. */+ conversationId: string;offset?: number;limit?: number;}@@ -84,8 +84,8 @@ export interface GetAgentMessagesResult {total: number;offset: number;limit: number;- /** Resolved conversation ID used by the server */- conversationId?: string;+ /** Conversation ID used by the server. */+ conversationId: string;/** Context window size (tokens) used by this session */contextWindowTokens?: number;}@@ -98,26 +98,11 @@ export interface GetHubInfoResult {agentCount: number;}-/** listAgents - no params needed */-export interface ListAgentsResult {- agents: { id: string; closed: boolean }[];-}--/** listConversations - no params needed (conversation-first alias of listAgents) */+/** listConversations - no params needed */export interface ListConversationsResult {conversations: { id: string; closed: boolean }[];}-/** createAgent - request params */-export interface CreateAgentParams {- id?: string;-}--/** createAgent - response payload */-export interface CreateAgentResult {- id: string;-}-/** createConversation - request params (create a conversation, optionally under a specific agent) */export interface CreateConversationParams {id?: string;@@ -129,17 +114,7 @@ export interface CreateConversationResult {id: string;}-/** deleteAgent - request params */-export interface DeleteAgentParams {- id: string;-}--/** deleteAgent - response payload */-export interface DeleteAgentResult {- ok: boolean;-}--/** deleteConversation - request params (conversation-first alias of deleteAgent) */+/** deleteConversation - request params */export interface DeleteConversationParams {id: string;}@@ -178,9 +153,5 @@ export interface VerifyResult {hubId: string;agentId: string;/** Authorized conversation scope for this device. */- conversationId?: string;- /** Session ID alias (same value as conversationId). */- sessionId?: string;- /** Backward-compatible alias for conversationId. */- mainConversationId?: string;+ conversationId: string;}diff --git a/packages/core/src/client/actions/stream.ts b/packages/core/src/client/actions/stream.tsindex 1898235204..777b9734e4 100644--- a/packages/core/src/client/actions/stream.ts+++ b/packages/core/src/client/actions/stream.ts@@ -64,8 +64,6 @@ export interface StreamPayload {agentId: string;/** Conversation ID of this stream event. */conversationId: string;- /** Session ID alias (same value as conversationId). */- sessionId?: string;event: AgentEvent | CompactionEvent | AgentErrorEvent;}diff --git a/packages/core/src/client/client.ts b/packages/core/src/client/client.tsindex d1c9ef9ba9..b94b3a640d 100644--- a/packages/core/src/client/client.ts+++ b/packages/core/src/client/client.ts@@ -239,9 +239,7 @@ export class GatewayClient {result: {hubId: string;agentId: string;- conversationId?: string;- sessionId?: string;- mainConversationId?: string;+ conversationId: string;isNewDevice?: boolean;}) => void,@@ -332,9 +330,7 @@ export class GatewayClient {this.request<{hubId: string;agentId: string;- conversationId?: string;- sessionId?: string;- mainConversationId?: string;+ conversationId: string;isNewDevice?: boolean;}>(this.options.hubId,@@ -343,13 +339,8 @@ export class GatewayClient {this.options.verifyTimeout,).then((result) => {- const sessionId = result.sessionId ?? result.conversationId ?? result.mainConversationId;- const normalizedResult = {- ...result,- ...(sessionId ? { sessionId, conversationId: sessionId, mainConversationId: sessionId } : {}),- };// Verify succeeded — now expose "registered" to upper layer- this.callbacks.onVerified?.(normalizedResult);+ this.callbacks.onVerified?.(result);this.callbacks.onRegistered?.(response.deviceId);this.callbacks.onStateChange?.("registered");})diff --git a/packages/core/src/client/types.ts b/packages/core/src/client/types.tsindex 887d31bfc6..9a2a13208a 100644--- a/packages/core/src/client/types.ts+++ b/packages/core/src/client/types.ts@@ -114,9 +114,7 @@ export interface GatewayClientCallbacks {result: {hubId: string;agentId: string;- conversationId?: string;- sessionId?: string;- mainConversationId?: string;+ conversationId: string;isNewDevice?: boolean;}) => void;diff --git a/packages/core/src/hub/exec-approval-manager.ts b/packages/core/src/hub/exec-approval-manager.tsindex 59fb6175df..eda4d1b59d 100644--- a/packages/core/src/hub/exec-approval-manager.ts+++ b/packages/core/src/hub/exec-approval-manager.ts@@ -60,7 +60,6 @@ export class ExecApprovalManager {approvalId,agentId: params.agentId,conversationId,- sessionId: conversationId,command: params.command,cwd: params.cwd,riskLevel: params.riskLevel,@@ -128,7 +127,6 @@ export class ExecApprovalManager {if (entry.request.agentId === agentId|| entry.request.conversationId === agentId- || entry.request.sessionId === agentId) {if (entry.timer) clearTimeout(entry.timer);this.pending.delete(id);diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 93b6b560e6..5ac40e6efe 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -41,11 +41,11 @@ export {type GetAgentMessagesParams,type GetAgentMessagesResult,type GetHubInfoResult,- type ListAgentsResult,- type CreateAgentParams,- type CreateAgentResult,- type DeleteAgentParams,- type DeleteAgentResult,+ type ListConversationsResult,+ type CreateConversationParams,+ type CreateConversationResult,+ type DeleteConversationParams,+ type DeleteConversationResult,type UpdateGatewayParams,type UpdateGatewayResult,type VerifyParams,diff --git a/packages/hooks/src/use-chat.ts b/packages/hooks/src/use-chat.tsindex 0adde14bc5..842034b68f 100644--- a/packages/hooks/src/use-chat.ts+++ b/packages/hooks/src/use-chat.ts@@ -56,7 +56,7 @@ export interface Message {role: "user" | "assistant" | "toolResult" | "system";content: ContentBlock[];agentId: string;- conversationId?: string;+ conversationId: string;stopReason?: string;toolCallId?: string;toolName?: string;@@ -188,7 +188,7 @@ export function useChat() {const convertMessages = useCallback((raw: AgentMessageItem[],agentId: string,- conversationId = agentId,+ conversationId: string,): Message[] => {const toolCallArgsMap = new Map<string, { name: string; args: Record<string, unknown> }>();for (const m of raw) {@@ -244,10 +244,10 @@ export function useChat() {const setHistory = useCallback((raw: AgentMessageItem[],agentId: string,+ conversationId: string,meta?: { total: number; offset: number; contextWindowTokens?: number },- conversationId?: string,) => {- const loaded = convertMessages(raw, agentId, conversationId ?? agentId);+ const loaded = convertMessages(raw, agentId, conversationId);setMessages(loaded);if (meta) {setHasMore(meta.offset > 0);@@ -261,10 +261,10 @@ export function useChat() {const prependHistory = useCallback((raw: AgentMessageItem[],agentId: string,+ conversationId: string,meta: { total: number; offset: number; contextWindowTokens?: number },- conversationId?: string,) => {- const older = convertMessages(raw, agentId, conversationId ?? agentId);+ const older = convertMessages(raw, agentId, conversationId);setMessages((prev) => [...older, ...prev]);setHasMore(meta.offset > 0);if (meta.contextWindowTokens !== undefined) {@@ -276,8 +276,8 @@ export function useChat() {const addUserMessage = useCallback((text: string,agentId: string,+ conversationId: string,source?: MessageSource,- conversationId?: string,) => {setMessages((prev) => [...prev,@@ -286,7 +286,7 @@ export function useChat() {role: "user",content: [{ type: "text", text }],agentId,- conversationId: conversationId ?? agentId,+ conversationId,source,},]);@@ -295,7 +295,7 @@ export function useChat() {/** Process a StreamPayload → update messages + streamingIds */const handleStream = useCallback((payload: StreamPayload) => {const { event } = payload;- const sessionId = payload.sessionId ?? payload.conversationId ?? payload.agentId;+ const conversationId = payload.conversationId;switch (event.type) {case "message_start": {@@ -304,7 +304,7 @@ export function useChat() {role: "assistant",content: [],agentId: payload.agentId,- conversationId: sessionId,+ conversationId,};const content = extractContent(event);if (content.length) newMsg.content = content;@@ -334,7 +334,7 @@ export function useChat() {m.role === "toolResult"&& m.toolStatus === "running"&& m.agentId === payload.agentId- && (m.conversationId ?? m.agentId) === sessionId+ && m.conversationId === conversationId) {return { ...m, toolStatus: "interrupted" as ToolStatus };}@@ -356,7 +356,7 @@ export function useChat() {role: "toolResult",content: [],agentId: payload.agentId,- conversationId: sessionId,+ conversationId,toolCallId: event.toolCallId,toolName: event.toolName,toolArgs: event.args as Record<string, unknown> | undefined,@@ -409,7 +409,7 @@ export function useChat() {role: "system",content: [],agentId: payload.agentId,- conversationId: sessionId,+ conversationId,systemType: "compaction",compaction: {removed: ce.removed,diff --git a/packages/hooks/src/use-gateway-chat.ts b/packages/hooks/src/use-gateway-chat.tsindex 6038bb98a7..f5d6f868d9 100644--- a/packages/hooks/src/use-gateway-chat.ts+++ b/packages/hooks/src/use-gateway-chat.ts@@ -17,12 +17,11 @@ interface UseGatewayChatOptions {client: GatewayClient;hubId: string;agentId: string;- conversationId?: string;+ conversationId: string;}export function useGatewayChat({ client, hubId, agentId, conversationId }: UseGatewayChatOptions) {const chat = useChat();- const resolvedConversationId = conversationId ?? agentId;const [isLoading, setIsLoading] = useState(false);const [isLoadingHistory, setIsLoadingHistory] = useState(true);const [isLoadingMore, setIsLoadingMore] = useState(false);@@ -34,28 +33,27 @@ export function useGatewayChat({ client, hubId, agentId, conversationId }: UseGaclient.request<GetAgentMessagesResult>(hubId, "getAgentMessages", {agentId,- conversationId: resolvedConversationId,+ conversationId,limit: DEFAULT_MESSAGES_LIMIT,}).then((result) => {- chat.setHistory(result.messages, agentId, {+ chat.setHistory(result.messages, agentId, result.conversationId, {total: result.total,offset: result.offset,contextWindowTokens: result.contextWindowTokens,- }, result.conversationId ?? resolvedConversationId);+ });offsetRef.current = result.offset;}).catch(() => {}).finally(() => setIsLoadingHistory(false));- }, [client, hubId, agentId, resolvedConversationId]);+ }, [client, hubId, agentId, conversationId]);// Subscribe to eventsuseEffect(() => {client.onMessage((msg) => {if (msg.action === StreamAction) {const payload = msg.payload as StreamPayload;- const payloadConversationId = payload.sessionId ?? payload.conversationId ?? payload.agentId;- if (payload.agentId !== agentId || payloadConversationId !== resolvedConversationId) {+ if (payload.agentId !== agentId || payload.conversationId !== conversationId) {return;}if (payload.event.type === "agent_error") {@@ -71,8 +69,7 @@ export function useGatewayChat({ client, hubId, agentId, conversationId }: UseGa}if (msg.action === ExecApprovalRequestAction) {const approval = msg.payload as ExecApprovalRequestPayload;- const approvalConversationId = approval.sessionId ?? approval.conversationId ?? approval.agentId;- if (approval.agentId !== agentId || approvalConversationId !== resolvedConversationId) {+ if (approval.agentId !== agentId || approval.conversationId !== conversationId) {return;}chat.addApproval(approval);@@ -84,23 +81,22 @@ export function useGatewayChat({ client, hubId, agentId, conversationId }: UseGa}});return () => { client.onMessage(() => {}); };- }, [client, agentId, resolvedConversationId]);+ }, [client, agentId, conversationId]);const sendMessage = useCallback((text: string) => {const trimmed = text.trim();if (!trimmed) return;- chat.addUserMessage(trimmed, agentId, { type: "local" }, resolvedConversationId);+ chat.addUserMessage(trimmed, agentId, conversationId, { type: "local" });chat.setError(null);client.send(hubId, "message", {agentId,- conversationId: resolvedConversationId,- sessionId: resolvedConversationId,+ conversationId,content: trimmed,});setIsLoading(true);},- [client, hubId, agentId, resolvedConversationId],+ [client, hubId, agentId, conversationId],);const loadMore = useCallback(async () => {@@ -113,13 +109,13 @@ export function useGatewayChat({ client, hubId, agentId, conversationId }: UseGaconst newOffset = Math.max(0, currentOffset - DEFAULT_MESSAGES_LIMIT);const limit = currentOffset - newOffset;const result = await client.request<GetAgentMessagesResult>(- hubId, "getAgentMessages", { agentId, conversationId: resolvedConversationId, offset: newOffset, limit },+ hubId, "getAgentMessages", { agentId, conversationId, offset: newOffset, limit },);- chat.prependHistory(result.messages, agentId, {+ chat.prependHistory(result.messages, agentId, result.conversationId, {total: result.total,offset: result.offset,contextWindowTokens: result.contextWindowTokens,- }, result.conversationId ?? resolvedConversationId);+ });offsetRef.current = result.offset;} catch {// Best-effort — pagination failure does not block chat@@ -127,7 +123,7 @@ export function useGatewayChat({ client, hubId, agentId, conversationId }: UseGaisLoadingMoreRef.current = false;setIsLoadingMore(false);}- }, [client, hubId, agentId, resolvedConversationId]);+ }, [client, hubId, agentId, conversationId]);const resolveApproval = useCallback((approvalId: string, decision: ApprovalDecision) => {diff --git a/packages/hooks/src/use-gateway-connection.ts b/packages/hooks/src/use-gateway-connection.tsindex d1f7b48e90..0248aa7d89 100644--- a/packages/hooks/src/use-gateway-connection.ts+++ b/packages/hooks/src/use-gateway-connection.ts@@ -132,10 +132,7 @@ export function useGatewayConnection(): UseGatewayConnectionReturn {agentId: result.agentId,conversationId:id.conversationId- ?? result.sessionId- ?? result.conversationId- ?? result.mainConversationId- ?? result.agentId,+ ?? result.conversationId,};}).onStateChange((state: ConnectionState) => {diff --git a/packages/sdk/src/actions/exec-approval.ts b/packages/sdk/src/actions/exec-approval.tsindex 5802435661..0b314d7753 100644--- a/packages/sdk/src/actions/exec-approval.ts+++ b/packages/sdk/src/actions/exec-approval.ts@@ -16,8 +16,6 @@ export interface ExecApprovalRequestPayload {agentId: string;/** Conversation ID that initiated the approval request. */conversationId: string;- /** Session ID alias (same value as conversationId). */- sessionId?: string;/** Shell command requiring approval */command: string;/** Working directory */diff --git a/packages/sdk/src/actions/index.ts b/packages/sdk/src/actions/index.tsindex 13ad3a5500..04074de59c 100644--- a/packages/sdk/src/actions/index.ts+++ b/packages/sdk/src/actions/index.ts@@ -20,11 +20,11 @@ export {type GetAgentMessagesParams,type GetAgentMessagesResult,type GetHubInfoResult,- type ListAgentsResult,- type CreateAgentParams,- type CreateAgentResult,- type DeleteAgentParams,- type DeleteAgentResult,+ type ListConversationsResult,+ type CreateConversationParams,+ type CreateConversationResult,+ type DeleteConversationParams,+ type DeleteConversationResult,type UpdateGatewayParams,type UpdateGatewayResult,type DeviceMeta,diff --git a/packages/sdk/src/actions/rpc.ts b/packages/sdk/src/actions/rpc.tsindex bdc103b66c..a6a5827e28 100644--- a/packages/sdk/src/actions/rpc.ts+++ b/packages/sdk/src/actions/rpc.ts@@ -66,8 +66,8 @@ export const DEFAULT_MESSAGES_LIMIT = 200;/** getAgentMessages - request params */export interface GetAgentMessagesParams {agentId: string;- /** Optional conversation ID. Falls back to agent main conversation when omitted. */- conversationId?: string;+ /** Conversation ID to read. */+ conversationId: string;offset?: number;limit?: number;}@@ -93,8 +93,8 @@ export interface GetAgentMessagesResult {total: number;offset: number;limit: number;- /** Resolved conversation ID used by the server */- conversationId?: string;+ /** Conversation ID used by the server. */+ conversationId: string;/** Context window size (tokens) used by this session */contextWindowTokens?: number;}@@ -107,26 +107,11 @@ export interface GetHubInfoResult {agentCount: number;}-/** listAgents - no params needed */-export interface ListAgentsResult {- agents: { id: string; closed: boolean }[];-}--/** listConversations - no params needed (conversation-first alias of listAgents) */+/** listConversations - no params needed */export interface ListConversationsResult {conversations: { id: string; closed: boolean }[];}-/** createAgent - request params */-export interface CreateAgentParams {- id?: string;-}--/** createAgent - response payload */-export interface CreateAgentResult {- id: string;-}-/** createConversation - request params (create a conversation, optionally under a specific agent) */export interface CreateConversationParams {id?: string;@@ -138,17 +123,7 @@ export interface CreateConversationResult {id: string;}-/** deleteAgent - request params */-export interface DeleteAgentParams {- id: string;-}--/** deleteAgent - response payload */-export interface DeleteAgentResult {- ok: boolean;-}--/** deleteConversation - request params (conversation-first alias of deleteAgent) */+/** deleteConversation - request params */export interface DeleteConversationParams {id: string;}@@ -188,9 +163,5 @@ export interface VerifyResult {hubId: string;agentId: string;/** Authorized conversation scope for this device. */- conversationId?: string;- /** Session ID alias (same value as conversationId). */- sessionId?: string;- /** Backward-compatible alias for conversationId. */- mainConversationId?: string;+ conversationId: string;}diff --git a/packages/sdk/src/actions/stream.ts b/packages/sdk/src/actions/stream.tsindex 1898235204..777b9734e4 100644--- a/packages/sdk/src/actions/stream.ts+++ b/packages/sdk/src/actions/stream.ts@@ -64,8 +64,6 @@ export interface StreamPayload {agentId: string;/** Conversation ID of this stream event. */conversationId: string;- /** Session ID alias (same value as conversationId). */- sessionId?: string;event: AgentEvent | CompactionEvent | AgentErrorEvent;}diff --git a/packages/sdk/src/client.ts b/packages/sdk/src/client.tsindex d1c9ef9ba9..b94b3a640d 100644--- a/packages/sdk/src/client.ts+++ b/packages/sdk/src/client.ts@@ -239,9 +239,7 @@ export class GatewayClient {result: {hubId: string;agentId: string;- conversationId?: string;- sessionId?: string;- mainConversationId?: string;+ conversationId: string;isNewDevice?: boolean;}) => void,@@ -332,9 +330,7 @@ export class GatewayClient {this.request<{hubId: string;agentId: string;- conversationId?: string;- sessionId?: string;- mainConversationId?: string;+ conversationId: string;isNewDevice?: boolean;}>(this.options.hubId,@@ -343,13 +339,8 @@ export class GatewayClient {this.options.verifyTimeout,).then((result) => {- const sessionId = result.sessionId ?? result.conversationId ?? result.mainConversationId;- const normalizedResult = {- ...result,- ...(sessionId ? { sessionId, conversationId: sessionId, mainConversationId: sessionId } : {}),- };// Verify succeeded — now expose "registered" to upper layer- this.callbacks.onVerified?.(normalizedResult);+ this.callbacks.onVerified?.(result);this.callbacks.onRegistered?.(response.deviceId);this.callbacks.onStateChange?.("registered");})diff --git a/packages/sdk/src/types.ts b/packages/sdk/src/types.tsindex 887d31bfc6..9a2a13208a 100644--- a/packages/sdk/src/types.ts+++ b/packages/sdk/src/types.ts@@ -114,9 +114,7 @@ export interface GatewayClientCallbacks {result: {hubId: string;agentId: string;- conversationId?: string;- sessionId?: string;- mainConversationId?: string;+ conversationId: string;isNewDevice?: boolean;}) => void;