Skip to content

armgit / pibot

Public Imported from GitHub
0

Open-source, local-first AI agent team for your desktop: multi-agent group chats, computer use, browser, MCP, routines and approvals. macOS, Windows, Linux + Android. Built on pi.

fix(chat): committed reply attachments reach the chat without a refresh

leen.zhou7d08a4374e1b
diff --git a/packages/client-core/src/chat/events.ts b/packages/client-core/src/chat/events.ts
index 6b22441..634fb25 100644
--- a/packages/client-core/src/chat/events.ts
+++ b/packages/client-core/src/chat/events.ts
@@ -1,3 +1,4 @@
+// Chat events update the active topic and reconcile missing live rows with persisted history.
import { chatReplyTo } from "@pibot/protocol";
import { appendReplyDelta, preserveLiveReply } from "./reply-delta.ts";
import type { ChatSession } from "./session.ts";
@@ -52,11 +53,13 @@ export function applyEvent(this: ChatSession, event: ChatEvent) {
});
return;
}
- if (
- !this.matches(event.payload) ||
- !this.state.messages.some((m) => m.id === messageId && m.runId === runId)
- )
+ if (!this.matches(event.payload)) return;
+ if (!this.state.messages.some((m) => m.id === messageId && m.runId === runId)) {
+ // A split reply can finish before its row reaches this viewport. Its terminal event
+ // still gives us a chance to recover committed attachments from the current topic.
+ if (event.kind !== "delta") void this.refreshHistory();
return;
+ }
this.patch(
{
messages: this.state.messages.map((message) => {
diff --git a/packages/protocol-base/src/core/kernel-api.ts b/packages/protocol-base/src/core/kernel-api.ts
index 5a151bd..401f58f 100644
--- a/packages/protocol-base/src/core/kernel-api.ts
+++ b/packages/protocol-base/src/core/kernel-api.ts
@@ -1,3 +1,4 @@
+// The brain kernel uses these wire contracts before product capabilities are composed.
import { z } from "zod";
import { ProxyAddressSchema } from "../app/network-proxy.ts";
import { AcpEvents, AcpMethods } from "../execution/independent-background.ts";
@@ -76,6 +77,7 @@ import {
KnowledgeDetectHostMethods,
KnowledgeOpenHostMethods,
MAX_ATTACHMENTS,
+ MAX_REPLY_ATTACHMENTS,
MemoryEvents,
MemoryMethods,
MessageActionMethods,
@@ -166,7 +168,7 @@ export const KernelEvents = {
...ChatRouteFields,
runId: IdSchema,
messageId: IdSchema,
- attachments: z.array(AttachmentSchema).max(10),
+ attachments: z.array(AttachmentSchema).max(MAX_REPLY_ATTACHMENTS),
}),
"chat.done": z.strictObject({
...ChatRouteFields,
diff --git a/packages/protocol/src/aggregate/api.ts b/packages/protocol/src/aggregate/api.ts
index 859cef2..064aa4c 100644
--- a/packages/protocol/src/aggregate/api.ts
+++ b/packages/protocol/src/aggregate/api.ts
@@ -1,3 +1,4 @@
+// Product peers add capability contracts to the shared brain kernel API.
import {
BrowserDebugMethods,
BrowserEvents,
@@ -234,12 +235,6 @@ export const Events = {
text: z.string(),
newReply: z.boolean().optional(),
}),
- "chat.attachments": z.strictObject({
- ...ChatRouteFields,
- runId: IdSchema,
- messageId: IdSchema,
- attachments: z.array(AttachmentSchema).max(MAX_ATTACHMENTS),
- }),
"chat.done": z.strictObject({
...ChatRouteFields,
runId: IdSchema,