Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(chat): improve bot conversation usability (#159)

Leo4196bee09fe5
diff --git a/apps/mobile/src/features/threads/ThreadFeed.tsx b/apps/mobile/src/features/threads/ThreadFeed.tsx
index 9f8f31a81..f2437f2b8 100644
--- a/apps/mobile/src/features/threads/ThreadFeed.tsx
+++ b/apps/mobile/src/features/threads/ThreadFeed.tsx
@@ -205,6 +205,33 @@ function MessageAttachmentImage(props: {
);
}
+function MessageAttachmentFile(props: {
+ readonly environmentId: EnvironmentId;
+ readonly attachmentId: string;
+ readonly name: string;
+}) {
+ const uri = useAssetUrl(props.environmentId, {
+ _tag: "attachment",
+ attachmentId: props.attachmentId,
+ });
+ return (
+ <Pressable
+ accessibilityRole="button"
+ accessibilityLabel={`Open ${props.name}`}
+ className="flex-row items-center gap-2 rounded-[14px] bg-black/5 px-3 py-3 dark:bg-white/10"
+ disabled={uri === null}
+ onPress={() => {
+ if (uri) void tryOpenExternalUrl(uri, "file-preview");
+ }}
+ >
+ <SymbolView name="doc.text" size={20} tintColor="gray" />
+ <Text className="min-w-0 flex-1" numberOfLines={1}>
+ {props.name}
+ </Text>
+ </Pressable>
+ );
+}
+
function ThreadMarkdownImageView(props: {
readonly uri: string | null;
readonly sourceKey: string;
@@ -1102,7 +1129,14 @@ function renderFeedEntry(
/>
) : null}
{attachments.map((attachment) => {
- return (
+ return attachment.type === "file" ? (
+ <MessageAttachmentFile
+ key={attachment.id}
+ environmentId={props.environmentId}
+ attachmentId={attachment.id}
+ name={attachment.name}
+ />
+ ) : (
<MessageAttachmentImage
key={attachment.id}
environmentId={props.environmentId}
@@ -1165,7 +1199,14 @@ function renderFeedEntry(
)
) : null}
{attachments.map((attachment) => {
- return (
+ return attachment.type === "file" ? (
+ <MessageAttachmentFile
+ key={attachment.id}
+ environmentId={props.environmentId}
+ attachmentId={attachment.id}
+ name={attachment.name}
+ />
+ ) : (
<MessageAttachmentImage
key={attachment.id}
environmentId={props.environmentId}
diff --git a/apps/server/src/assets/AttachmentUpload.ts b/apps/server/src/assets/AttachmentUpload.ts
index 6142b69d7..117b671cc 100644
--- a/apps/server/src/assets/AttachmentUpload.ts
+++ b/apps/server/src/assets/AttachmentUpload.ts
@@ -15,6 +15,7 @@ import * as Schema from "effect/Schema";
import {
createPendingAttachmentId,
+ inferAttachmentExtension,
parseThreadSegmentFromAttachmentId,
PENDING_ATTACHMENT_THREAD_SEGMENT,
resolveAttachmentPathById,
@@ -29,7 +30,6 @@ import {
} from "../auth/utils.ts";
import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
import * as ServerConfig from "../config.ts";
-import { inferImageExtension } from "../imageMime.ts";
export const ATTACHMENT_UPLOAD_ROUTE_PREFIX = "/api/attachments/upload";
@@ -152,7 +152,7 @@ export const storeAttachmentUpload = Effect.fn("AttachmentUpload.store")(functio
}
const config = yield* ServerConfig.ServerConfig;
- const extension = inferImageExtension({ mimeType: claims.mimeType, fileName: claims.name });
+ const extension = inferAttachmentExtension({ mimeType: claims.mimeType, name: claims.name });
const relativePath = `${claims.attachmentId}${extension}`;
const finalPath = resolveAttachmentRelativePath({
attachmentsDir: config.attachmentsDir,
diff --git a/apps/server/src/attachmentStore.ts b/apps/server/src/attachmentStore.ts
index d0334bce0..d24c2f074 100644
--- a/apps/server/src/attachmentStore.ts
+++ b/apps/server/src/attachmentStore.ts
@@ -11,7 +11,36 @@ import {
} from "./attachmentPaths.ts";
import { inferImageExtension, SAFE_IMAGE_FILE_EXTENSIONS } from "./imageMime.ts";
-const ATTACHMENT_FILENAME_EXTENSIONS = [...SAFE_IMAGE_FILE_EXTENSIONS, ".bin"];
+const FILE_EXTENSION_BY_MIME_TYPE: Readonly<Record<string, string>> = {
+ "application/json": ".json",
+ "application/pdf": ".pdf",
+ "application/toml": ".toml",
+ "application/xml": ".xml",
+ "application/x-yaml": ".yaml",
+ "text/csv": ".csv",
+ "text/markdown": ".md",
+ "text/plain": ".txt",
+ "text/toml": ".toml",
+ "text/xml": ".xml",
+ "text/yaml": ".yaml",
+};
+const SAFE_FILE_EXTENSIONS = new Set([
+ ".csv",
+ ".json",
+ ".md",
+ ".markdown",
+ ".pdf",
+ ".toml",
+ ".txt",
+ ".xml",
+ ".yaml",
+ ".yml",
+]);
+const ATTACHMENT_FILENAME_EXTENSIONS = [
+ ...SAFE_IMAGE_FILE_EXTENSIONS,
+ ...SAFE_FILE_EXTENSIONS,
+ ".bin",
+];
const ATTACHMENT_ID_THREAD_SEGMENT_MAX_CHARS = 80;
const ATTACHMENT_ID_THREAD_SEGMENT_PATTERN = "[a-z0-9_]+(?:-[a-z0-9_]+)*";
const ATTACHMENT_ID_UUID_PATTERN = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
@@ -80,9 +109,31 @@ export function attachmentRelativePath(attachment: ChatAttachment): string {
});
return `${attachment.id}${extension}`;
}
+ case "file":
+ return `${attachment.id}${inferFileExtension(attachment)}`;
}
}
+export function inferFileExtension(input: { readonly mimeType: string; readonly name?: string }) {
+ const fromMime = FILE_EXTENSION_BY_MIME_TYPE[input.mimeType.toLowerCase()];
+ if (fromMime) return fromMime;
+ const match = /\.([a-z0-9]{1,12})$/i.exec(input.name?.trim() ?? "");
+ const fromName = match ? `.${match[1]!.toLowerCase()}` : "";
+ return SAFE_FILE_EXTENSIONS.has(fromName) ? fromName : ".bin";
+}
+
+export function inferAttachmentExtension(input: {
+ readonly mimeType: string;
+ readonly name?: string;
+}) {
+ return input.mimeType.toLowerCase().startsWith("image/")
+ ? inferImageExtension({
+ mimeType: input.mimeType,
+ ...(input.name !== undefined ? { fileName: input.name } : {}),
+ })
+ : inferFileExtension(input);
+}
+
export function resolveAttachmentPath(input: {
readonly attachmentsDir: string;
readonly attachment: ChatAttachment;
diff --git a/apps/server/src/environment/ServerEnvironment.test.ts b/apps/server/src/environment/ServerEnvironment.test.ts
index 04175683b..aa0f3cbbf 100644
--- a/apps/server/src/environment/ServerEnvironment.test.ts
+++ b/apps/server/src/environment/ServerEnvironment.test.ts
@@ -70,6 +70,7 @@ it.layer(NodeServices.layer)("ServerEnvironmentLive", (it) => {
expect(second.capabilities.repositoryIdentity).toBe(true);
expect(second.capabilities.connectionProbe).toBe(true);
expect(second.capabilities.attachmentUploads).toBe(true);
+ expect(second.capabilities.fileAttachments).toBe(true);
expect(second.capabilities.pullRequests).toBe(true);
expect(second.capabilities.threadTitleRegeneration).toBe(true);
expect(second.capabilities.threadPullRequestLinking).toBe(true);
diff --git a/apps/server/src/environment/ServerEnvironment.ts b/apps/server/src/environment/ServerEnvironment.ts
index 8b3c6f016..4de2b31ac 100644
--- a/apps/server/src/environment/ServerEnvironment.ts
+++ b/apps/server/src/environment/ServerEnvironment.ts
@@ -144,6 +144,7 @@ export const make = Effect.gen(function* () {
repositoryIdentity: true,
connectionProbe: true,
attachmentUploads: true,
+ fileAttachments: true,
pullRequests: true,
threadSettlement: true,
threadSnooze: true,
diff --git a/apps/server/src/orchestration/Layers/ProjectionPipeline.ts b/apps/server/src/orchestration/Layers/ProjectionPipeline.ts
index 24f91985f..0518fff97 100644
--- a/apps/server/src/orchestration/Layers/ProjectionPipeline.ts
+++ b/apps/server/src/orchestration/Layers/ProjectionPipeline.ts
@@ -387,9 +387,6 @@ function collectThreadAttachmentRelativePaths(
const relativePaths = new Set<string>();
for (const message of messages) {
for (const attachment of message.attachments ?? []) {
- if (attachment.type !== "image") {
- continue;
- }
const attachmentThreadSegment = parseThreadSegmentFromAttachmentId(attachment.id);
if (!attachmentThreadSegment || attachmentThreadSegment !== threadSegment) {
continue;
@@ -1321,6 +1318,7 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
}
case "thread.message-sent":
+ case "thread.message-reaction-set":
case "thread.proposed-plan-upserted":
case "thread.activity-appended":
case "thread.approval-response-requested":
@@ -1489,12 +1487,22 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
if (Option.isNone(existingMessage)) return;
const withoutReaction = (existingMessage.value.reactions ?? []).filter(
(reaction) =>
- reaction.botId !== event.payload.botId || reaction.emoji !== event.payload.emoji,
+ reaction.botId !== event.payload.botId ||
+ reaction.personId !== event.payload.personId ||
+ reaction.emoji !== event.payload.emoji,
);
yield* projectionThreadMessageRepository.upsert({
...existingMessage.value,
reactions: event.payload.present
- ? [...withoutReaction, { botId: event.payload.botId, emoji: event.payload.emoji }]
+ ? [
+ ...withoutReaction,
+ {
+ ...(event.payload.botId !== undefined
+ ? { botId: event.payload.botId }
+ : { personId: event.payload.personId }),
+ emoji: event.payload.emoji,
+ },
+ ]
: withoutReaction,
updatedAt: event.payload.updatedAt,
});
diff --git a/apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts b/apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts
index e8385767a..a7043a784 100644
--- a/apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts
+++ b/apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts
@@ -6,7 +6,6 @@ import {
BotUsageCap,
ChannelBinding,
ChatAttachment,
- ChannelMessageOrigin,
CheckpointRef,
GroupMembership,
IsoDateTime,
@@ -1326,6 +1325,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
AND sequence <= ${maxSequence}
AND event_type IN (
'thread.message-sent',
+ 'thread.message-reaction-set',
'thread.proposed-plan-upserted',
'thread.activity-appended',
'thread.turn-diff-completed',
diff --git a/apps/server/src/orchestration/Normalizer.attachments.test.ts b/apps/server/src/orchestration/Normalizer.attachments.test.ts
index 27a35977f..f76a0c3b3 100644
--- a/apps/server/src/orchestration/Normalizer.attachments.test.ts
+++ b/apps/server/src/orchestration/Normalizer.attachments.test.ts
@@ -73,6 +73,44 @@ describe("normalizeDispatchCommand attachments", () => {
}).pipe(Effect.provide(testLayer)),
);
+ it.effect("persists inline document attachments", () =>
+ Effect.gen(function* () {
+ const config = yield* ServerConfig.ServerConfig;
+ const command: Extract<ClientOrchestrationCommand, { type: "thread.turn.start" }> = {
+ type: "thread.turn.start",
+ commandId: CommandId.make("command-file"),
+ threadId: ThreadId.make("thread-1"),
+ message: {
+ messageId: MessageId.make("message-file"),
+ role: "user" as const,
+ text: "read this",
+ attachments: [
+ {
+ type: "file" as const,
+ name: "notes.md",
+ mimeType: "text/markdown" as const,
+ sizeBytes: 5,
+ dataUrl: "data:text/markdown;base64,aGVsbG8=",
+ },
+ ],
+ },
+ runtimeMode: "full-access",
+ interactionMode: "default",
+ createdAt: "2026-08-01T00:00:00.000Z",
+ };
+ const normalized = yield* normalizeDispatchCommand(command);
+ if (normalized.type !== "thread.turn.start") {
+ throw new Error("Expected a thread.turn.start command.");
+ }
+
+ const attachment = normalized.message.attachments[0]!;
+ expect(attachment.type).toBe("file");
+ expect(
+ NodeFS.readFileSync(NodePath.join(config.attachmentsDir, `${attachment.id}.md`)),
+ ).toEqual(Buffer.from("hello"));
+ }).pipe(Effect.provide(testLayer)),
+ );
+
it.effect("claims uploaded attachments while retaining a retryable pending copy", () =>
Effect.gen(function* () {
const config = yield* ServerConfig.ServerConfig;
@@ -306,10 +344,9 @@ describe("normalizeDispatchCommand attachments", () => {
...mismatchedTypeCommand,
message: {
...mismatchedTypeCommand.message,
- attachments: mismatchedTypeCommand.message.attachments.map((attachment) => ({
- ...attachment,
- mimeType: "image/jpeg",
- })),
+ attachments: mismatchedTypeCommand.message.attachments.map((attachment) =>
+ attachment.type === "image" ? { ...attachment, mimeType: "image/jpeg" } : attachment,
+ ),
},
}).pipe(Effect.flip);
expect(mismatchedType.message).toContain("image type");
diff --git a/apps/server/src/orchestration/Normalizer.ts b/apps/server/src/orchestration/Normalizer.ts
index bd6a8f242..4ca0b11ad 100644
--- a/apps/server/src/orchestration/Normalizer.ts
+++ b/apps/server/src/orchestration/Normalizer.ts
@@ -7,6 +7,7 @@ import {
type IsoDateTime,
type OrchestrationCommand,
OrchestrationDispatchCommandError,
+ PROVIDER_SEND_TURN_MAX_FILE_BYTES,
PROVIDER_SEND_TURN_MAX_IMAGE_BYTES,
} from "@t3tools/contracts";
@@ -26,12 +27,14 @@ export const canonicalizeClientCommandTimestamps = (
receivedAt: IsoDateTime,
): ClientOrchestrationCommand => {
const canonicalCommand =
- "createdAt" in command
- ? {
- ...command,
- createdAt: receivedAt,
- }
- : command;
+ command.type === "thread.message.reaction.set"
+ ? { ...command, updatedAt: receivedAt }
+ : "createdAt" in command
+ ? {
+ ...command,
+ createdAt: receivedAt,
+ }
+ : command;
if (canonicalCommand.type !== "thread.turn.start" || !canonicalCommand.bootstrap?.createThread) {
return canonicalCommand;
@@ -165,18 +168,21 @@ export const normalizeDispatchCommand = (command: ClientOrchestrationCommand) =>
});
}
- const normalizedAttachment = {
- ...attachment,
- id: claim.finalId,
- mimeType: attachment.mimeType.toLowerCase(),
- };
+ const normalizedAttachment =
+ attachment.type === "file"
+ ? { ...attachment, id: claim.finalId }
+ : {
+ ...attachment,
+ id: claim.finalId,
+ mimeType: attachment.mimeType.toLowerCase(),
+ };
const expectedPath = resolveAttachmentPath({
attachmentsDir: serverConfig.attachmentsDir,
attachment: normalizedAttachment,
});
if (expectedPath !== claim.finalPath) {
return yield* new OrchestrationDispatchCommandError({
- message: `Attachment '${attachment.name}' cannot be sent: image type does not match the upload.`,
+ message: `Attachment '${attachment.name}' cannot be sent: ${attachment.type} type does not match the upload.`,
});
}
@@ -197,16 +203,24 @@ export const normalizeDispatchCommand = (command: ClientOrchestrationCommand) =>
}
const parsed = parseBase64DataUrl(attachment.dataUrl);
- if (!parsed || !parsed.mimeType.startsWith("image/")) {
+ if (
+ !parsed ||
+ parsed.mimeType !== attachment.mimeType.toLowerCase() ||
+ (attachment.type === "image" && !parsed.mimeType.startsWith("image/"))
+ ) {
return yield* new OrchestrationDispatchCommandError({
- message: `Invalid image attachment payload for '${attachment.name}'.`,
+ message: `Invalid attachment payload for '${attachment.name}'.`,
});
}
const bytes = Buffer.from(parsed.base64, "base64");
- if (bytes.byteLength === 0 || bytes.byteLength > PROVIDER_SEND_TURN_MAX_IMAGE_BYTES) {
+ const maxBytes =
+ attachment.type === "image"
+ ? PROVIDER_SEND_TURN_MAX_IMAGE_BYTES
+ : PROVIDER_SEND_TURN_MAX_FILE_BYTES;
+ if (bytes.byteLength === 0 || bytes.byteLength > maxBytes) {
return yield* new OrchestrationDispatchCommandError({
- message: `Image attachment '${attachment.name}' is empty or too large.`,
+ message: `Attachment '${attachment.name}' is empty or too large.`,
});
}
@@ -217,13 +231,22 @@ export const normalizeDispatchCommand = (command: ClientOrchestrationCommand) =>
});
}
- const persistedAttachment = {
- type: "image" as const,
- id: attachmentId,
- name: attachment.name,
- mimeType: parsed.mimeType.toLowerCase(),
- sizeBytes: bytes.byteLength,
- };
+ const persistedAttachment =
+ attachment.type === "file"
+ ? {
+ type: "file" as const,
+ id: attachmentId,
+ name: attachment.name,
+ mimeType: attachment.mimeType,
+ sizeBytes: bytes.byteLength,
+ }
+ : {
+ type: "image" as const,
+ id: attachmentId,
+ name: attachment.name,
+ mimeType: parsed.mimeType.toLowerCase(),
+ sizeBytes: bytes.byteLength,
+ };
const attachmentPath = resolveAttachmentPath({
attachmentsDir: serverConfig.attachmentsDir,
diff --git a/apps/server/src/orchestration/decider.groups.test.ts b/apps/server/src/orchestration/decider.groups.test.ts
index b5670ba49..a8f4d029e 100644
--- a/apps/server/src/orchestration/decider.groups.test.ts
+++ b/apps/server/src/orchestration/decider.groups.test.ts
@@ -573,6 +573,16 @@ it.layer(NodeServices.layer)("group membership decider", (it) => {
threadId: ThreadId.make("thread-group"),
createdAt: NOW,
},
+ {
+ type: "thread.message.reaction.set",
+ commandId: CommandId.make("cmd-outsider-thread-reaction"),
+ threadId: ThreadId.make("thread-group"),
+ messageId: MessageId.make("message-1"),
+ botId: BOSS_ID,
+ emoji: "👍",
+ present: true,
+ updatedAt: NOW,
+ },
] satisfies ReadonlyArray<OrchestrationCommand>;
const errors = yield* Effect.all(
commands.map((command) =>
@@ -607,6 +617,111 @@ it.layer(NodeServices.layer)("group membership decider", (it) => {
}),
);
+ it.effect("binds client group reactions to the authenticated person", () =>
+ Effect.gen(function* () {
+ const messageId = MessageId.make("message-1");
+ const readModel = makeReadModel({
+ bots: [
+ makeBot({ id: BOSS_ID, groupId: GROUP_ID }),
+ makeBot({ id: SPECIALIST_ID, groupId: GROUP_ID }),
+ ],
+ groups: [makeGroup()],
+ threads: [
+ {
+ ...makeGroupThread(),
+ respondingBotId: BOSS_ID,
+ messages: [
+ {
+ id: messageId,
+ role: "user",
+ text: "Please investigate.",
+ turnId: null,
+ streaming: false,
+ createdAt: NOW,
+ updatedAt: NOW,
+ },
+ ],
+ },
+ ],
+ });
+ const command = {
+ type: "thread.message.reaction.set",
+ commandId: CommandId.make("cmd-member-thread-reaction"),
+ threadId: ThreadId.make("thread-group"),
+ messageId,
+ botId: SPECIALIST_ID,
+ emoji: "👍",
+ present: true,
+ updatedAt: NOW,
+ } as const;
+
+ const result = yield* decideOrchestrationCommand({
+ command,
+ readModel,
+ actor: { personId: PERSON_ID, canManageGroups: false },
+ });
+
+ const event = (Array.isArray(result) ? result : [result]).find(
+ (candidate) => candidate.type === "thread.message-reaction-set",
+ );
+ if (event?.type !== "thread.message-reaction-set") {
+ throw new Error("Expected thread.message-reaction-set");
+ }
+ expect(event.payload).toMatchObject({ personId: PERSON_ID, emoji: "👍", present: true });
+ expect(event.payload.botId).toBeUndefined();
+ }),
+ );
+
+ it.effect("keeps trusted internal group reactions bot-authored", () =>
+ Effect.gen(function* () {
+ const messageId = MessageId.make("message-1");
+ const readModel = makeReadModel({
+ bots: [makeBot({ id: BOSS_ID, groupId: GROUP_ID })],
+ groups: [makeGroup()],
+ threads: [
+ {
+ ...makeGroupThread(),
+ respondingBotId: BOSS_ID,
+ messages: [
+ {
+ id: messageId,
+ role: "user",
+ text: "Please investigate.",
+ turnId: null,
+ streaming: false,
+ createdAt: NOW,
+ updatedAt: NOW,
+ },
+ ],
+ },
+ ],
+ });
+
+ const result = yield* decideOrchestrationCommand({
+ command: {
+ type: "thread.message.reaction.set",
+ commandId: CommandId.make("cmd-internal-thread-reaction"),
+ threadId: ThreadId.make("thread-group"),
+ messageId,
+ botId: BOSS_ID,
+ emoji: "👍",
+ present: true,
+ updatedAt: NOW,
+ },
+ readModel,
+ });
+
+ const event = (Array.isArray(result) ? result : [result]).find(
+ (candidate) => candidate.type === "thread.message-reaction-set",
+ );
+ if (event?.type !== "thread.message-reaction-set") {
+ throw new Error("Expected thread.message-reaction-set");
+ }
+ expect(event.payload).toMatchObject({ botId: BOSS_ID, emoji: "👍", present: true });
+ expect(event.payload.personId).toBeUndefined();
+ }),
+ );
+
it.effect("lets an administrator mutate a group-owned thread without membership", () =>
Effect.gen(function* () {
const result = yield* decideOrchestrationCommand({
diff --git a/apps/server/src/orchestration/decider.ts b/apps/server/src/orchestration/decider.ts
index 7750ef4d1..2bc7c0978 100644
--- a/apps/server/src/orchestration/decider.ts
+++ b/apps/server/src/orchestration/decider.ts
@@ -397,6 +397,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
case "thread.runtime-mode.set":
case "thread.interaction-mode.set":
case "thread.voice-transcript.append":
+ case "thread.message.reaction.set":
case "thread.turn.interrupt":
case "thread.approval.respond":
case "thread.user-input.respond":
@@ -852,7 +853,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
}
case "group.rename": {
- const group = yield* requireGroup({ readModel, command, groupId: command.groupId });
+ yield* requireGroup({ readModel, command, groupId: command.groupId });
const occurredAt = yield* nowIso;
return {
...(yield* withEventBase({
@@ -3050,14 +3051,32 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
detail: `Message '${command.messageId}' is not visible in thread '${command.threadId}'.`,
});
}
- if (thread.groupId != null) {
+ if (actor === undefined && command.botId === undefined) {
+ return yield* new OrchestrationCommandInvariantError({
+ commandType: command.type,
+ detail: "Trusted bot reactions require a bot identity.",
+ });
+ }
+ if (actor === undefined && thread.groupId != null) {
+ const group = yield* requireGroup({
+ readModel,
+ command,
+ groupId: thread.groupId,
+ });
+ const reactionBotId = thread.respondingBotId ?? group.bossBotId;
+ if (reactionBotId === null || command.botId !== reactionBotId) {
+ return yield* new OrchestrationCommandInvariantError({
+ commandType: command.type,
+ detail: `Bot '${command.botId}' cannot react in thread '${command.threadId}'.`,
+ });
+ }
yield* requireActiveGroupMember({
readModel,
command,
groupId: thread.groupId,
- botId: command.botId,
+ botId: reactionBotId,
});
- } else if (thread.botId !== command.botId) {
+ } else if (actor === undefined && thread.botId !== command.botId) {
return yield* new OrchestrationCommandInvariantError({
commandType: command.type,
detail: `Bot '${command.botId}' cannot react in thread '${command.threadId}'.`,
@@ -3074,7 +3093,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
payload: {
threadId: command.threadId,
messageId: command.messageId,
- botId: command.botId,
+ ...(actor === undefined ? { botId: command.botId } : { personId: actor.personId }),
emoji: command.emoji,
present: command.present,
updatedAt: command.updatedAt,
diff --git a/apps/server/src/orchestration/projector.ts b/apps/server/src/orchestration/projector.ts
index 9d3a25e49..568cef33d 100644
--- a/apps/server/src/orchestration/projector.ts
+++ b/apps/server/src/orchestration/projector.ts
@@ -1058,12 +1058,23 @@ export function projectEvent(
const messages = thread.messages.map((message) => {
if (message.id !== payload.messageId) return message;
const withoutReaction = (message.reactions ?? []).filter(
- (reaction) => reaction.botId !== payload.botId || reaction.emoji !== payload.emoji,
+ (reaction) =>
+ reaction.botId !== payload.botId ||
+ reaction.personId !== payload.personId ||
+ reaction.emoji !== payload.emoji,
);
return {
...message,
reactions: payload.present
- ? [...withoutReaction, { botId: payload.botId, emoji: payload.emoji }]
+ ? [
+ ...withoutReaction,
+ {
+ ...(payload.botId !== undefined
+ ? { botId: payload.botId }
+ : { personId: payload.personId }),
+ emoji: payload.emoji,
+ },
+ ]
: withoutReaction,
updatedAt: payload.updatedAt,
};
diff --git a/apps/server/src/provider/Layers/AgentController.ts b/apps/server/src/provider/Layers/AgentController.ts
index c4cda9c13..fa4226053 100644
--- a/apps/server/src/provider/Layers/AgentController.ts
+++ b/apps/server/src/provider/Layers/AgentController.ts
@@ -2122,7 +2122,7 @@ const make = (options?: AgentControllerLiveOptions) =>
mediaType: attachment.mimeType,
filename: attachment.name,
},
- pathLine: `[Attached image "${attachment.name}" is saved at: ${path}]`,
+ pathLine: `[Attached ${attachment.type} "${attachment.name}" is saved at: ${path}]`,
}),
catch: (cause) =>
new AgentControllerRuntimeError({
diff --git a/apps/server/src/provider/Layers/CodexAdapter.ts b/apps/server/src/provider/Layers/CodexAdapter.ts
index 7c2e83255..ce43bf6af 100644
--- a/apps/server/src/provider/Layers/CodexAdapter.ts
+++ b/apps/server/src/provider/Layers/CodexAdapter.ts
@@ -1852,7 +1852,7 @@ export const makeCodexAdapter = Effect.fn("makeCodexAdapter")(function* (
const sendTurn: CodexAdapterShape["sendTurn"] = Effect.fn("sendTurn")(function* (input) {
const codexAttachments = yield* Effect.forEach(
- input.attachments ?? [],
+ (input.attachments ?? []).filter((attachment) => attachment.type === "image"),
(attachment) => resolveAttachment(input, attachment),
{ concurrency: 1 },
);
diff --git a/apps/server/src/provider/Layers/CursorAdapter.ts b/apps/server/src/provider/Layers/CursorAdapter.ts
index 3d57d07b7..4b4f2c84c 100644
--- a/apps/server/src/provider/Layers/CursorAdapter.ts
+++ b/apps/server/src/provider/Layers/CursorAdapter.ts
@@ -974,6 +974,9 @@ export function makeCursorAdapter(
}
if (input.attachments && input.attachments.length > 0) {
for (const attachment of input.attachments) {
+ if (attachment.type !== "image") {
+ continue;
+ }
const attachmentPath = resolveAttachmentPath({
attachmentsDir: serverConfig.attachmentsDir,
attachment,
diff --git a/apps/server/src/provider/Layers/GrokAdapter.ts b/apps/server/src/provider/Layers/GrokAdapter.ts
index 3be105555..27283ded5 100644
--- a/apps/server/src/provider/Layers/GrokAdapter.ts
+++ b/apps/server/src/provider/Layers/GrokAdapter.ts
@@ -960,7 +960,7 @@ export function makeGrokAdapter(grokSettings: GrokSettings, options?: GrokAdapte
const text = input.input?.trim();
const imagePromptParts = yield* Effect.forEach(
- input.attachments ?? [],
+ (input.attachments ?? []).filter((attachment) => attachment.type === "image"),
(attachment) =>
Effect.gen(function* () {
const attachmentPath = resolveAttachmentPath({
diff --git a/apps/server/src/subscription-auth/snapshot.test.ts b/apps/server/src/subscription-auth/snapshot.test.ts
index 92a3d3026..2ff990bc1 100644
--- a/apps/server/src/subscription-auth/snapshot.test.ts
+++ b/apps/server/src/subscription-auth/snapshot.test.ts
@@ -150,6 +150,19 @@ describe("provider access capabilities", () => {
);
});
+ it("lets a recovered real request override a stale provider scan error", () => {
+ const provider = {
+ ...providerFixture("custom-openai", "codex", "apiKey"),
+ status: "error" as const,
+ };
+
+ const capabilities = buildProviderAccessCapabilities([], [provider], () => "recovered");
+
+ expect(capabilities.find((item) => item.id === "api-key-custom-openai")?.health).toBe(
+ "recovered",
+ );
+ });
+
it("labels unsupported browser gaps as temporary and gives a repair action", () => {
const capabilities = buildProviderAccessCapabilities([], []);
diff --git a/apps/server/src/subscription-auth/snapshot.ts b/apps/server/src/subscription-auth/snapshot.ts
index 84be5e923..c73d6aaa9 100644
--- a/apps/server/src/subscription-auth/snapshot.ts
+++ b/apps/server/src/subscription-auth/snapshot.ts
@@ -85,8 +85,8 @@ function providerAccessHealth(
) {
if (!provider || !provider.installed) return "missing" as const;
if (provider.availability === "unavailable") return "unsupported" as const;
- if (provider.status === "error") return "failed-first-request" as const;
if (actualRequestHealth) return actualRequestHealth;
+ if (provider.status === "error") return "failed-first-request" as const;
return "detected" as const;
}
diff --git a/apps/server/src/ws.ts b/apps/server/src/ws.ts
index 7c5a83c77..135b16130 100644
--- a/apps/server/src/ws.ts
+++ b/apps/server/src/ws.ts
@@ -383,6 +383,7 @@ export function isThreadDetailEvent(event: OrchestrationEvent): event is Extract
{
type:
| "thread.message-sent"
+ | "thread.message-reaction-set"
| "thread.proposed-plan-upserted"
| "thread.activity-appended"
| "thread.turn-diff-completed"
@@ -392,6 +393,7 @@ export function isThreadDetailEvent(event: OrchestrationEvent): event is Extract
> {
return (
event.type === "thread.message-sent" ||
+ event.type === "thread.message-reaction-set" ||
event.type === "thread.proposed-plan-upserted" ||
event.type === "thread.activity-appended" ||
event.type === "thread.turn-diff-completed" ||
@@ -511,10 +513,10 @@ const makeWsRpcLayer = (
const dispatchFromClient: OrchestrationEngine.OrchestrationEngineShape["dispatch"] = (
command,
) =>
- orchestrationEngine.dispatch(
- command,
- hasClientOrigin ? { origin: clientOrigin } : undefined,
- );
+ orchestrationEngine.dispatch(command, {
+ actor: dispatchActor,
+ ...(hasClientOrigin ? { origin: clientOrigin } : {}),
+ });
const checkpointDiffQuery = yield* CheckpointDiffQuery.CheckpointDiffQuery;
const keybindings = yield* Keybindings.Keybindings;
const externalLauncher = yield* ExternalLauncher.ExternalLauncher;
diff --git a/apps/web/src/browser/BrowserSurfaceSlot.tsx b/apps/web/src/browser/BrowserSurfaceSlot.tsx
index a9d3f541f..78835abad 100644
--- a/apps/web/src/browser/BrowserSurfaceSlot.tsx
+++ b/apps/web/src/browser/BrowserSurfaceSlot.tsx
@@ -7,6 +7,7 @@ import { acquireBrowserSurface } from "./browserSurfaceStore";
export function BrowserSurfaceSlot(props: {
readonly tabId: string;
readonly visible: boolean;
+ readonly interactive?: boolean;
readonly cornerRadius?: number;
readonly layoutVersion?: string | number;
readonly className?: string;
@@ -15,13 +16,14 @@ export function BrowserSurfaceSlot(props: {
const {
tabId,
visible,
+ interactive = visible,
cornerRadius = 0,
layoutVersion,
className,
fitSourceContent = false,
} = props;
const elementRef = useRef<HTMLDivElement | null>(null);
- const presentationRef = useRef({ visible, cornerRadius });
+ const presentationRef = useRef({ visible, interactive, cornerRadius });
const updateRef = useRef<(() => void) | null>(null);
useLayoutEffect(() => {
@@ -39,6 +41,7 @@ export function BrowserSurfaceSlot(props: {
height: Math.max(1, Math.round(rect.height)),
},
presentation.visible && rect.width > 0 && rect.height > 0,
+ presentation.interactive,
presentation.cornerRadius,
);
if (presentation.visible && !presented) {
@@ -52,6 +55,7 @@ export function BrowserSurfaceSlot(props: {
height: Math.max(1, Math.round(rect.height)),
},
rect.width > 0 && rect.height > 0,
+ presentation.interactive,
presentation.cornerRadius,
);
}
@@ -72,9 +76,9 @@ export function BrowserSurfaceSlot(props: {
}, [fitSourceContent, tabId]);
useLayoutEffect(() => {
- presentationRef.current = { visible, cornerRadius };
+ presentationRef.current = { visible, interactive, cornerRadius };
updateRef.current?.();
- }, [cornerRadius, layoutVersion, visible]);
+ }, [cornerRadius, interactive, layoutVersion, visible]);
return <div ref={elementRef} className={className} data-browser-surface-slot={tabId} />;
}
diff --git a/apps/web/src/browser/HostedBrowserWebview.tsx b/apps/web/src/browser/HostedBrowserWebview.tsx
index 998f564a5..74f4167dd 100644
--- a/apps/web/src/browser/HostedBrowserWebview.tsx
+++ b/apps/web/src/browser/HostedBrowserWebview.tsx
@@ -70,6 +70,7 @@ export function HostedBrowserWebview(props: {
fittedSourceContent: current?.fittedSourceContent ?? null,
rect: resolveBrowserSurfacePanelRect(state.byTabId, runtimeTabId),
visible: current?.visible ?? false,
+ interactive: current?.interactive ?? false,
};
}),
);
@@ -241,6 +242,7 @@ export function HostedBrowserWebview(props: {
const renderingActive = active || backgroundActivity || pictureInPicture || recordingActive;
const wrapperStyle = resolveHostedBrowserWebviewWrapperStyle({
active,
+ interactive: presentation.interactive,
renderingActive,
cornerRadius: presentation.cornerRadius,
rect: lastRect,
@@ -292,6 +294,7 @@ export function HostedBrowserWebview(props: {
: effectiveViewport.height
}
aria-hidden={active ? undefined : true}
+ tabIndex={active && presentation.interactive ? undefined : -1}
className={cn(
"absolute flex overflow-hidden bg-background",
active && !layout.fillsPanel && "ring-1 ring-border/70 shadow-sm",
diff --git a/apps/web/src/browser/browserSurfaceStore.test.ts b/apps/web/src/browser/browserSurfaceStore.test.ts
index 249d3dcb2..30d13597a 100644
--- a/apps/web/src/browser/browserSurfaceStore.test.ts
+++ b/apps/web/src/browser/browserSurfaceStore.test.ts
@@ -94,6 +94,7 @@ describe("browserSurfaceStore", () => {
expect(useBrowserSurfaceStore.getState().byTabId[tabId]).toMatchObject({
rect: null,
visible: false,
+ interactive: false,
content: { width: 393, height: 852 },
});
});
@@ -107,6 +108,7 @@ describe("browserSurfaceStore", () => {
hidden: {
rect: staleRect,
visible: false,
+ interactive: false,
content: null,
fittedSourceContent: null,
fitSourceContent: false,
@@ -117,6 +119,7 @@ describe("browserSurfaceStore", () => {
active: {
rect: liveRect,
visible: true,
+ interactive: true,
content: null,
fittedSourceContent: null,
fitSourceContent: false,
diff --git a/apps/web/src/browser/browserSurfaceStore.ts b/apps/web/src/browser/browserSurfaceStore.ts
index fe85c9e38..e0616a12c 100644
--- a/apps/web/src/browser/browserSurfaceStore.ts
+++ b/apps/web/src/browser/browserSurfaceStore.ts
@@ -10,6 +10,7 @@ export interface BrowserSurfaceRect {
export interface BrowserSurfacePresentation {
readonly rect: BrowserSurfaceRect | null;
readonly visible: boolean;
+ readonly interactive: boolean;
readonly content: BrowserSurfaceContentPresentation | null;
readonly fittedSourceContent: BrowserSurfaceContentPresentation | null;
readonly fitSourceContent: boolean;
@@ -38,6 +39,7 @@ interface BrowserSurfaceStoreState {
owner: symbol,
rect: BrowserSurfaceRect,
visible: boolean,
+ interactive: boolean,
cornerRadius: number,
) => void;
readonly presentContent: (tabId: string, content: BrowserSurfaceContentPresentation) => void;
@@ -45,7 +47,12 @@ interface BrowserSurfaceStoreState {
}
export interface BrowserSurfaceLease {
- readonly present: (rect: BrowserSurfaceRect, visible: boolean, cornerRadius?: number) => boolean;
+ readonly present: (
+ rect: BrowserSurfaceRect,
+ visible: boolean,
+ interactive?: boolean,
+ cornerRadius?: number,
+ ) => boolean;
readonly release: () => void;
}
@@ -97,6 +104,7 @@ export const useBrowserSurfaceStore = create<BrowserSurfaceStoreState>()((set) =
[tabId]: {
rect: current?.rect ?? null,
visible: false,
+ interactive: false,
content: current?.content ?? null,
fittedSourceContent: fitSourceContent ? (current?.content ?? null) : null,
fitSourceContent,
@@ -107,13 +115,14 @@ export const useBrowserSurfaceStore = create<BrowserSurfaceStoreState>()((set) =
},
};
}),
- present: (tabId, owner, rect, visible, cornerRadius) =>
+ present: (tabId, owner, rect, visible, interactive, cornerRadius) =>
set((state) => {
const current = state.byTabId[tabId];
if (current?.owner !== owner) return state;
if (
current &&
current.visible === visible &&
+ current.interactive === interactive &&
current.cornerRadius === cornerRadius &&
rectEquals(current.rect, rect)
) {
@@ -122,7 +131,7 @@ export const useBrowserSurfaceStore = create<BrowserSurfaceStoreState>()((set) =
return {
byTabId: {
...state.byTabId,
- [tabId]: { ...current, rect, visible, cornerRadius, updatedAt: Date.now() },
+ [tabId]: { ...current, rect, visible, interactive, cornerRadius, updatedAt: Date.now() },
},
};
}),
@@ -136,6 +145,7 @@ export const useBrowserSurfaceStore = create<BrowserSurfaceStoreState>()((set) =
[tabId]: {
rect: null,
visible: false,
+ interactive: false,
content,
fittedSourceContent: null,
fitSourceContent: false,
@@ -184,6 +194,7 @@ export const useBrowserSurfaceStore = create<BrowserSurfaceStoreState>()((set) =
[tabId]: {
...current,
visible: false,
+ interactive: false,
fittedSourceContent: null,
fitSourceContent: false,
updatedAt: Date.now(),
@@ -206,10 +217,12 @@ export function acquireBrowserSurface(
useBrowserSurfaceStore.getState().claim(tabId, owner, fitSourceContent);
return {
- present: (rect, visible, cornerRadius = 0) => {
+ present: (rect, visible, interactive = visible, cornerRadius = 0) => {
if (released) return false;
if (useBrowserSurfaceStore.getState().byTabId[tabId]?.owner !== owner) return false;
- useBrowserSurfaceStore.getState().present(tabId, owner, rect, visible, cornerRadius);
+ useBrowserSurfaceStore
+ .getState()
+ .present(tabId, owner, rect, visible, interactive, cornerRadius);
return true;
},
release: () => {
diff --git a/apps/web/src/browser/hostedBrowserWebviewStyle.test.ts b/apps/web/src/browser/hostedBrowserWebviewStyle.test.ts
index c2c78f4ac..b6b47fdce 100644
--- a/apps/web/src/browser/hostedBrowserWebviewStyle.test.ts
+++ b/apps/web/src/browser/hostedBrowserWebviewStyle.test.ts
@@ -10,6 +10,7 @@ describe("resolveHostedBrowserWebviewWrapperStyle", () => {
expect(
resolveHostedBrowserWebviewWrapperStyle({
active: true,
+ interactive: true,
renderingActive: true,
rect: { x: 12, y: 34, width: 800, height: 600 },
hiddenSize: { width: 1280, height: 800 },
@@ -28,6 +29,7 @@ describe("resolveHostedBrowserWebviewWrapperStyle", () => {
expect(
resolveHostedBrowserWebviewWrapperStyle({
active: true,
+ interactive: true,
renderingActive: true,
cornerRadius: 12,
rect: { x: 12, y: 34, width: 360, height: 203 },
@@ -45,6 +47,7 @@ describe("resolveHostedBrowserWebviewWrapperStyle", () => {
it("suspends painting for an inactive webview", () => {
const style = resolveHostedBrowserWebviewWrapperStyle({
active: false,
+ interactive: false,
renderingActive: false,
rect: { x: 12, y: 34, width: 800, height: 600 },
hiddenSize: { width: 393, height: 852 },
@@ -64,6 +67,7 @@ describe("resolveHostedBrowserWebviewWrapperStyle", () => {
it("keeps an active background task paintable offscreen", () => {
const style = resolveHostedBrowserWebviewWrapperStyle({
active: false,
+ interactive: false,
renderingActive: true,
rect: null,
hiddenSize: { width: 1280, height: 800 },
@@ -79,4 +83,16 @@ describe("resolveHostedBrowserWebviewWrapperStyle", () => {
visibility: "visible",
});
});
+
+ it("keeps a visible docked preview inert", () => {
+ expect(
+ resolveHostedBrowserWebviewWrapperStyle({
+ active: true,
+ interactive: false,
+ renderingActive: true,
+ rect: { x: 12, y: 34, width: 360, height: 203 },
+ hiddenSize: { width: 1280, height: 800 },
+ }),
+ ).toMatchObject({ pointerEvents: "none" });
+ });
});
diff --git a/apps/web/src/browser/hostedBrowserWebviewStyle.ts b/apps/web/src/browser/hostedBrowserWebviewStyle.ts
index 1e6ff0bea..3258df628 100644
--- a/apps/web/src/browser/hostedBrowserWebviewStyle.ts
+++ b/apps/web/src/browser/hostedBrowserWebviewStyle.ts
@@ -20,12 +20,13 @@ export const HIDDEN_BROWSER_WEBVIEW_OFFSET = -100_000;
export function resolveHostedBrowserWebviewWrapperStyle(input: {
readonly active: boolean;
+ readonly interactive: boolean;
readonly renderingActive: boolean;
readonly cornerRadius?: number;
readonly rect: BrowserSurfaceRect | null;
readonly hiddenSize: HostedBrowserWebviewSize;
}): HostedBrowserWebviewWrapperStyle {
- const { active, cornerRadius = 0, hiddenSize, rect, renderingActive } = input;
+ const { active, interactive, cornerRadius = 0, hiddenSize, rect, renderingActive } = input;
if (active && rect) {
return {
left: rect.x,
@@ -33,7 +34,7 @@ export function resolveHostedBrowserWebviewWrapperStyle(input: {
width: rect.width,
height: rect.height,
zIndex: 30,
- pointerEvents: "auto",
+ pointerEvents: interactive ? "auto" : "none",
...(cornerRadius > 0 ? { borderRadius: cornerRadius } : {}),
};
}
diff --git a/apps/web/src/components/QuitHoldOverlay.tsx b/apps/web/src/components/QuitHoldOverlay.tsx
index 29c044015..1201b14f6 100644
--- a/apps/web/src/components/QuitHoldOverlay.tsx
+++ b/apps/web/src/components/QuitHoldOverlay.tsx
@@ -37,7 +37,7 @@ export function QuitHoldOverlay() {
return (
<div
role="status"
- className="pointer-events-none fixed inset-x-0 top-[22%] z-100 flex justify-center"
+ className="pointer-events-none fixed inset-0 z-100 flex items-center justify-center"
>
<div className="rounded-full bg-neutral-700/95 px-8 py-4 text-2xl font-bold text-white shadow-xl">
Hold {shortcut} to Quit
diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx
index 9a3eef5cc..f7027e97d 100644
--- a/apps/web/src/components/chat/ChatComposer.tsx
+++ b/apps/web/src/components/chat/ChatComposer.tsx
@@ -230,7 +230,7 @@ import { Button } from "../ui/button";
import { Dialog, DialogPopup, DialogTitle } from "../ui/dialog";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
import { toastManager } from "../ui/toast";
-import { CircleAlertIcon, RotateCcwIcon, XIcon } from "lucide-react";
+import { CircleAlertIcon, PaperclipIcon, RotateCcwIcon, XIcon } from "lucide-react";
import { proposedPlanTitle } from "../../proposedPlan";
import {
applyProviderInstanceSettings,
@@ -922,6 +922,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
// Refs
// ------------------------------------------------------------------
const composerEditorRef = useRef<ComposerPromptEditorHandle>(null);
+ const attachmentInputRef = useRef<HTMLInputElement>(null);
const composerFormRef = useRef<HTMLFormElement>(null);
const composerSurfaceRef = useRef<HTMLDivElement>(null);
const providerInputRejectedRef = useRef(false);
@@ -3259,6 +3260,30 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
)}
>
<div className="-m-1 -ms-3.5 flex min-w-0 flex-1 items-center gap-1 overflow-x-auto p-1 ps-3.5 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
+ {activeThreadId && pendingUserInputs.length === 0 ? (
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <Button
+ type="button"
+ aria-label="Attach images"
+ className="shrink-0"
+ disabled={
+ isConnecting ||
+ projectSelectionRequired ||
+ composerImages.length >= PROVIDER_SEND_TURN_MAX_ATTACHMENTS
+ }
+ size="icon-sm"
+ variant="ghost"
+ onClick={() => attachmentInputRef.current?.click()}
+ />
+ }
+ >
+ <PaperclipIcon className="size-4" />
+ </TooltipTrigger>
+ <TooltipPopup side="top">Attach images</TooltipPopup>
+ </Tooltip>
+ ) : null}
{noProviderAvailable ? (
<Button
type="button"
@@ -3323,6 +3348,19 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
</div>
</div>
</div>
+ <input
+ ref={attachmentInputRef}
+ className="sr-only"
+ type="file"
+ accept="image/gif,image/heic,image/heif,image/jpeg,image/png,image/webp"
+ multiple
+ tabIndex={-1}
+ onChange={(event) => {
+ const files = Array.from(event.currentTarget.files ?? []);
+ event.currentTarget.value = "";
+ void addComposerImages(files);
+ }}
+ />
{noProviderAvailable ? null : (
<Dialog open={isComposerModelPickerOpen} onOpenChange={setIsComposerModelPickerOpen}>
<DialogPopup
diff --git a/apps/web/src/components/chat/MessageControls.test.ts b/apps/web/src/components/chat/MessageControls.test.ts
new file mode 100644
index 000000000..412680b34
--- /dev/null
+++ b/apps/web/src/components/chat/MessageControls.test.ts
@@ -0,0 +1,59 @@
+import { createElement } from "react";
+import { renderToStaticMarkup } from "react-dom/server";
+import { describe, expect, it, vi } from "vite-plus/test";
+
+import {
+ buildReplyPrompt,
+ MESSAGE_REACTION_OPTIONS,
+ MessageControls,
+ selectedReactionForPerson,
+} from "./MessageControls";
+
+const mocks = vi.hoisted(() => ({
+ isCopied: false,
+}));
+
+vi.mock("~/hooks/useCopyToClipboard", () => ({
+ useCopyToClipboard: () => ({
+ copyToClipboard: vi.fn(),
+ isCopied: mocks.isCopied,
+ }),
+}));
+
+describe("message controls", () => {
+ it("offers the accepted compact reaction set in order", () => {
+ expect(MESSAGE_REACTION_OPTIONS).toEqual(["👍", "👎", "❤️", "😂", "🎉", "😮"]);
+ });
+
+ it("resolves the current person reaction and quotes a reply into the sent prompt", () => {
+ expect(
+ selectedReactionForPerson(
+ [
+ { personId: "person-1", emoji: "👍" },
+ { personId: "person-2", emoji: "😂" },
+ ],
+ "person-2",
+ ),
+ ).toBe("😂");
+ expect(
+ buildReplyPrompt(
+ { messageId: "message-1", label: "Akeru", text: "First line\nSecond line" },
+ "My reply",
+ ),
+ ).toBe("> Replying to Akeru\n> First line\n> Second line\n\nMy reply");
+ });
+
+ it("replaces the message actions icon with a checkmark after copying", () => {
+ mocks.isCopied = true;
+
+ const html = renderToStaticMarkup(
+ createElement(MessageControls, { copyText: "Copied message" }),
+ );
+
+ expect(html).toContain('aria-label="Copied"');
+ expect(html).toContain("lucide-check");
+ expect(html).not.toContain("Copied!");
+
+ mocks.isCopied = false;
+ });
+});
diff --git a/apps/web/src/components/chat/MessageControls.tsx b/apps/web/src/components/chat/MessageControls.tsx
new file mode 100644
index 000000000..b51f65fad
--- /dev/null
+++ b/apps/web/src/components/chat/MessageControls.tsx
@@ -0,0 +1,166 @@
+import { CheckIcon, CopyIcon, EllipsisIcon, ReplyIcon, SmilePlusIcon } from "lucide-react";
+
+import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
+import { cn } from "~/lib/utils";
+import { Button } from "../ui/button";
+import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
+import { toastManager } from "../ui/toast";
+import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
+
+export const MESSAGE_REACTION_OPTIONS = ["👍", "👎", "❤️", "😂", "🎉", "😮"] as const;
+export type MessageReactionOption = (typeof MESSAGE_REACTION_OPTIONS)[number];
+
+export interface MessageReplyTarget {
+ readonly messageId: string;
+ readonly label: string;
+ readonly text: string;
+}
+
+export function selectedReactionForPerson(
+ reactions:
+ | ReadonlyArray<{ readonly personId?: string | undefined; readonly emoji: string }>
+ | undefined,
+ personId: string | null | undefined,
+): MessageReactionOption | null {
+ if (!personId) return null;
+ const emoji = reactions?.find((reaction) => reaction.personId === personId)?.emoji;
+ return MESSAGE_REACTION_OPTIONS.find((option) => option === emoji) ?? null;
+}
+
+export function buildReplyPrompt(reply: MessageReplyTarget | null, prompt: string): string {
+ if (!reply) return prompt;
+ const quoted = reply.text
+ .trim()
+ .split("\n")
+ .map((line) => `> ${line}`)
+ .join("\n");
+ return `> Replying to ${reply.label}\n${quoted}\n\n${prompt}`.trimEnd();
+}
+
+export function MessageControls(props: {
+ readonly copyText: string;
+ readonly align?: "start" | "end";
+ readonly selectedReaction?: MessageReactionOption | null;
+ readonly onReply?: () => void;
+ readonly onReactionChange?: (reaction: MessageReactionOption | null) => void;
+}) {
+ const { copyToClipboard, isCopied } = useCopyToClipboard({
+ target: "message",
+ timeout: 1200,
+ onError: (error) => {
+ toastManager.add({
+ type: "error",
+ title: "Failed to copy message",
+ description: error.message,
+ });
+ },
+ });
+ const chooseReaction = (next: MessageReactionOption) => {
+ const value = props.selectedReaction === next ? null : next;
+ props.onReactionChange?.(value);
+ };
+
+ return (
+ <div
+ className={cn("flex items-center gap-0.5", props.align === "end" && "justify-end")}
+ data-message-controls="true"
+ >
+ <Menu>
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <MenuTrigger
+ render={
+ <Button
+ aria-label={isCopied ? "Copied" : "More message actions"}
+ size="icon-xs"
+ variant="ghost"
+ />
+ }
+ />
+ }
+ >
+ {isCopied ? (
+ <CheckIcon className="size-3.5 text-primary" />
+ ) : (
+ <EllipsisIcon className="size-3.5" />
+ )}
+ </TooltipTrigger>
+ <TooltipPopup side="top">{isCopied ? "Copied" : "More"}</TooltipPopup>
+ </Tooltip>
+ <MenuPopup align={props.align === "end" ? "end" : "start"} side="top">
+ <MenuItem onClick={() => copyToClipboard(props.copyText)}>
+ <CopyIcon />
+ Copy
+ </MenuItem>
+ </MenuPopup>
+ </Menu>
+ {props.onReply ? (
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <Button
+ aria-label="Reply to message"
+ size="icon-xs"
+ variant="ghost"
+ onClick={props.onReply}
+ />
+ }
+ >
+ <ReplyIcon className="size-3.5" />
+ </TooltipTrigger>
+ <TooltipPopup side="top">Reply</TooltipPopup>
+ </Tooltip>
+ ) : null}
+ {props.onReactionChange ? (
+ <Menu>
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <MenuTrigger
+ render={
+ <Button
+ aria-label={
+ props.selectedReaction
+ ? `Change reaction, ${props.selectedReaction} selected`
+ : "React"
+ }
+ size="icon-xs"
+ variant="ghost"
+ />
+ }
+ />
+ }
+ >
+ {props.selectedReaction ? (
+ <span className="text-sm [font-family:'Apple_Color_Emoji','Segoe_UI_Emoji',sans-serif]">
+ {props.selectedReaction}
+ </span>
+ ) : (
+ <SmilePlusIcon className="size-3.5" />
+ )}
+ </TooltipTrigger>
+ <TooltipPopup side="top">React</TooltipPopup>
+ </Tooltip>
+ <MenuPopup className="min-w-0" side="top">
+ <div aria-label="Choose a reaction" className="flex gap-0.5" role="group">
+ {MESSAGE_REACTION_OPTIONS.map((option) => (
+ <Button
+ key={option}
+ aria-label={`React ${option}`}
+ aria-pressed={props.selectedReaction === option}
+ className="text-base [font-family:'Apple_Color_Emoji','Segoe_UI_Emoji',sans-serif]"
+ size="icon-sm"
+ variant={props.selectedReaction === option ? "secondary" : "ghost"}
+ onClick={() => chooseReaction(option)}
+ >
+ {option}
+ </Button>
+ ))}
+ </div>
+ </MenuPopup>
+ </Menu>
+ ) : null}
+ </div>
+ );
+}
diff --git a/apps/web/src/components/chat/MessageCopyButton.tsx b/apps/web/src/components/chat/MessageCopyButton.tsx
index e6a6a491b..a51dd8221 100644
--- a/apps/web/src/components/chat/MessageCopyButton.tsx
+++ b/apps/web/src/components/chat/MessageCopyButton.tsx
@@ -61,7 +61,7 @@ export const MessageCopyButton = memo(function MessageCopyButton({
<TooltipTrigger
render={
<Button
- aria-label="Copy link"
+ aria-label={isCopied ? "Copied message" : "Copy message"}
disabled={isCopied}
onClick={() => copyToClipboard(text)}
ref={ref}
@@ -75,7 +75,7 @@ export const MessageCopyButton = memo(function MessageCopyButton({
{isCopied ? <CheckIcon className="size-3 text-primary" /> : <CopyIcon className="size-3" />}
</TooltipTrigger>
<TooltipPopup>
- <p>Copy to clipboard</p>
+ <p>{isCopied ? "Copied" : "Copy message"}</p>
</TooltipPopup>
</Tooltip>
);
diff --git a/apps/web/src/components/chat/MessageImageAttachments.tsx b/apps/web/src/components/chat/MessageImageAttachments.tsx
index fc67d790d..b2f144599 100644
--- a/apps/web/src/components/chat/MessageImageAttachments.tsx
+++ b/apps/web/src/components/chat/MessageImageAttachments.tsx
@@ -1,4 +1,5 @@
import type { ChatAttachment, EnvironmentId } from "@t3tools/contracts";
+import { FileTextIcon } from "lucide-react";
import { useMemo, useState } from "react";
import { useAssetUrls } from "~/assets/assetUrls";
@@ -22,12 +23,13 @@ export function MessageImageAttachments(props: {
);
const urls = useAssetUrls(props.environmentId, resources);
const [expanded, setExpanded] = useState<ExpandedImagePreview | null>(null);
- const images = props.attachments.map((attachment, index) => ({
+ const attachments = props.attachments.map((attachment, index) => ({
...attachment,
...(urls[index] ? { previewUrl: urls[index] } : {}),
}));
+ const images = attachments.filter((attachment) => attachment.type === "image");
- if (images.length === 0) return null;
+ if (attachments.length === 0) return null;
return (
<>
@@ -35,34 +37,46 @@ export function MessageImageAttachments(props: {
className={cn("grid max-w-[520px] grid-cols-1 gap-2 sm:grid-cols-2", props.className)}
data-testid="message-image-attachments"
>
- {images.map((image) => (
- <div
- key={image.id}
- className="overflow-hidden rounded-xl border border-border/80 bg-background/70"
- >
- {image.previewUrl ? (
- <button
- type="button"
- className="block w-full cursor-zoom-in"
- aria-label={`Preview ${image.name}`}
- onClick={() => {
- const preview = buildExpandedImagePreview(images, image.id);
- if (preview) setExpanded(preview);
- }}
- >
- <img
- src={image.previewUrl}
- alt={image.name}
- className="block max-h-[320px] w-full object-cover"
- />
- </button>
- ) : (
- <div className="flex min-h-24 items-center justify-center px-3 py-4 text-center text-muted-foreground text-xs">
- {image.name}
- </div>
- )}
- </div>
- ))}
+ {attachments.map((attachment) =>
+ attachment.type === "file" ? (
+ <a
+ key={attachment.id}
+ className="flex min-h-14 items-center gap-2 rounded-xl border border-border/80 bg-background/70 px-3 py-2 text-sm hover:bg-muted/50"
+ href={attachment.previewUrl}
+ download={attachment.name}
+ >
+ <FileTextIcon className="size-5 shrink-0 text-muted-foreground" />
+ <span className="min-w-0 truncate">{attachment.name}</span>
+ </a>
+ ) : (
+ <div
+ key={attachment.id}
+ className="overflow-hidden rounded-xl border border-border/80 bg-background/70"
+ >
+ {attachment.previewUrl ? (
+ <button
+ type="button"
+ className="block w-full cursor-zoom-in"
+ aria-label={`Preview ${attachment.name}`}
+ onClick={() => {
+ const preview = buildExpandedImagePreview(images, attachment.id);
+ if (preview) setExpanded(preview);
+ }}
+ >
+ <img
+ src={attachment.previewUrl}
+ alt={attachment.name}
+ className="block max-h-[320px] w-full object-cover"
+ />
+ </button>
+ ) : (
+ <div className="flex min-h-24 items-center justify-center px-3 py-4 text-center text-muted-foreground text-xs">
+ {attachment.name}
+ </div>
+ )}
+ </div>
+ ),
+ )}
</div>
{expanded ? (
<ExpandedImageDialog preview={expanded} onClose={() => setExpanded(null)} />
diff --git a/apps/web/src/components/chat/MessagesTimeline.test.tsx b/apps/web/src/components/chat/MessagesTimeline.test.tsx
index 7ee4514c3..4556c5ae5 100644
--- a/apps/web/src/components/chat/MessagesTimeline.test.tsx
+++ b/apps/web/src/components/chat/MessagesTimeline.test.tsx
@@ -879,7 +879,7 @@ describe("MessagesTimeline", () => {
/>,
);
- expect(markup).toContain('aria-label="Copy link"');
+ expect(markup).toContain('aria-label="More message actions"');
expect(markup).toContain('data-user-message-collapsed="true"');
expect(markup).toContain('data-user-message-footer="true"');
});
diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx
index 166845f94..8a8f75463 100644
--- a/apps/web/src/components/chat/MessagesTimeline.tsx
+++ b/apps/web/src/components/chat/MessagesTimeline.tsx
@@ -70,7 +70,7 @@ import { ProposedPlanCard } from "./ProposedPlanCard";
import { ChangedFilesCard } from "./ChangedFilesTree";
import { shouldAutoExpandChangedFiles } from "./changedFilesPresentation";
import { keepTimelineEndVisibleAfterOverlayGrowth } from "./timelineScrollAnchoring";
-import { MessageCopyButton } from "./MessageCopyButton";
+import { MessageControls } from "./MessageControls";
import { MessageImageAttachments } from "./MessageImageAttachments";
import {
computeStableMessagesTimelineRows,
@@ -1084,9 +1084,9 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
</Tooltip>
<div className="flex items-center gap-0.5">
{canRevertAgentWork && <RevertUserMessageButton messageId={row.message.id} />}
- {displayedUserMessage.copyText && (
- <MessageCopyButton text={displayedUserMessage.copyText} variant="ghost" />
- )}
+ {displayedUserMessage.copyText ? (
+ <MessageControls align="end" copyText={displayedUserMessage.copyText} />
+ ) : null}
</div>
</div>
</div>
@@ -1177,7 +1177,7 @@ function AssistantTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "mess
/>
{row.showAssistantMeta ? (
<div className="mt-1.5 flex items-center gap-2 text-xs tabular-nums opacity-0 transition-opacity duration-200 focus-within:opacity-100 group-hover/assistant:opacity-100">
- <AssistantCopyButton row={row} />
+ <AssistantMessageControls row={row} />
{!row.message.streaming && (
<Tooltip>
<TooltipTrigger
@@ -1198,7 +1198,7 @@ function AssistantTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "mess
);
}
-function AssistantCopyButton({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
+function AssistantMessageControls({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
const assistantCopyState = resolveAssistantMessageCopyState({
text: row.message.text ?? null,
showCopyButton: row.showAssistantCopyButton,
@@ -1209,7 +1209,7 @@ function AssistantCopyButton({ row }: { row: Extract<TimelineRow, { kind: "messa
return null;
}
- return <MessageCopyButton text={assistantCopyState.text ?? ""} variant="ghost" />;
+ return <MessageControls copyText={assistantCopyState.text ?? ""} />;
}
function ProposedPlanTimelineRow({
diff --git a/apps/web/src/components/preview/PreviewView.tsx b/apps/web/src/components/preview/PreviewView.tsx
index 9a8129237..b9d9ec4d1 100644
--- a/apps/web/src/components/preview/PreviewView.tsx
+++ b/apps/web/src/components/preview/PreviewView.tsx
@@ -705,6 +705,7 @@ export function PreviewView({
key={runtimeTabId}
tabId={runtimeTabId}
visible={visible && !isUnreachable}
+ interactive={visible && !isUnreachable}
className="absolute inset-0 h-full w-full"
/>
) : null}
diff --git a/apps/web/src/components/preview/ThreadPreviewMiniPlayer.tsx b/apps/web/src/components/preview/ThreadPreviewMiniPlayer.tsx
index 623928d10..349df22a7 100644
--- a/apps/web/src/components/preview/ThreadPreviewMiniPlayer.tsx
+++ b/apps/web/src/components/preview/ThreadPreviewMiniPlayer.tsx
@@ -320,6 +320,7 @@ export function ThreadPreviewMiniPlayer({ threadRef, tabId, bottomInset }: Props
<BrowserSurfaceSlot
tabId={runtimeTabId}
visible={Boolean(desktopOverlay?.hasWebContents)}
+ interactive={false}
cornerRadius={12}
fitSourceContent
layoutVersion={
@@ -329,6 +330,17 @@ export function ThreadPreviewMiniPlayer({ threadRef, tabId, bottomInset }: Props
}
className="absolute inset-0"
/>
+ {desktopOverlay?.hasWebContents ? (
+ <Button
+ type="button"
+ className="pointer-events-auto absolute bottom-3 left-1/2 z-[32] -translate-x-1/2 bg-background/92 shadow-sm backdrop-blur"
+ size="xs"
+ variant="outline"
+ onClick={openInPanel}
+ >
+ Open to interact
+ </Button>
+ ) : null}
<div className="pointer-events-none absolute inset-0 z-[31] rounded-xl ring-1 ring-inset ring-border/80" />
{!desktopOverlay?.hasWebContents ? (
<div className="pointer-events-none absolute inset-0 z-[32] flex items-center justify-center rounded-xl bg-muted text-xs text-muted-foreground">
diff --git a/apps/web/src/components/roster/BotBrowserPreview.tsx b/apps/web/src/components/roster/BotBrowserPreview.tsx
index 4ea476e6a..103421dde 100644
--- a/apps/web/src/components/roster/BotBrowserPreview.tsx
+++ b/apps/web/src/components/roster/BotBrowserPreview.tsx
@@ -101,24 +101,9 @@ function ConnectedBotBrowserPreview({
<section className="flex min-h-0 flex-1 flex-col" data-testid="bot-browser-expanded">
<header className="flex h-[var(--workspace-topbar-height)] shrink-0 items-center gap-2 px-3">
<h2 className="min-w-0 flex-1 truncate text-sm font-medium">{botName}'s browser</h2>
- <Tooltip>
- <TooltipTrigger
- render={
- <Button
- aria-label={`Restore ${botName} browser preview`}
- size="icon-sm"
- variant="ghost"
- onClick={() => onExpandedChange(false)}
- />
- }
- >
- <Minimize2Icon />
- </TooltipTrigger>
- <TooltipPopup side="left">Restore preview</TooltipPopup>
- </Tooltip>
{trailingAction}
</header>
- <div className="min-h-0 flex-1 overflow-hidden border-t border-border">
+ <div className="relative min-h-0 flex-1 overflow-hidden border-t border-border">
{nativeSupported ? (
<PreviewPanel mode="embedded" threadRef={threadRef} visible={visible} />
) : (
@@ -129,6 +114,12 @@ function ConnectedBotBrowserPreview({
className="size-full rounded-none"
/>
)}
+ <PreviewSizeButton
+ label={`Restore ${botName} browser preview`}
+ tooltip="Restore preview"
+ onClick={() => onExpandedChange(false)}
+ expanded
+ />
</div>
</section>
);
@@ -171,23 +162,6 @@ function BotBrowserPreviewFrame({
<section className="shrink-0 px-3 pt-3" data-testid="bot-browser-preview">
<div className="mb-2 flex min-h-7 items-center gap-2">
<h2 className="min-w-0 flex-1 truncate text-sm font-medium">{botName}'s browser</h2>
- {onExpand ? (
- <Tooltip>
- <TooltipTrigger
- render={
- <Button
- aria-label={`Expand ${botName} browser`}
- size="icon-xs"
- variant="ghost"
- onClick={onExpand}
- />
- }
- >
- <Maximize2Icon />
- </TooltipTrigger>
- <TooltipPopup side="left">Expand browser</TooltipPopup>
- </Tooltip>
- ) : null}
{trailingAction}
</div>
<BrowserFrame
@@ -205,11 +179,47 @@ function BotBrowserPreviewFrame({
className="absolute inset-0"
/>
) : null}
+ {onExpand ? (
+ <PreviewSizeButton
+ label={`Expand ${botName} browser`}
+ tooltip="Expand browser"
+ onClick={onExpand}
+ />
+ ) : null}
</BrowserFrame>
</section>
);
}
+function PreviewSizeButton(props: {
+ readonly label: string;
+ readonly tooltip: string;
+ readonly expanded?: boolean;
+ readonly onClick: () => void;
+}) {
+ const Icon = props.expanded ? Minimize2Icon : Maximize2Icon;
+ return (
+ <div className="absolute bottom-2 right-2 z-40">
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <Button
+ aria-label={props.label}
+ className="bg-background/88 shadow-sm backdrop-blur hover:bg-background"
+ size="icon-sm"
+ variant="outline"
+ onClick={props.onClick}
+ />
+ }
+ >
+ <Icon />
+ </TooltipTrigger>
+ <TooltipPopup side="left">{props.tooltip}</TooltipPopup>
+ </Tooltip>
+ </div>
+ );
+}
+
function BrowserFrame({
botName,
frame,
diff --git a/apps/web/src/components/roster/BotDetailsPanel.tsx b/apps/web/src/components/roster/BotDetailsPanel.tsx
index c73589404..ace9b6588 100644
--- a/apps/web/src/components/roster/BotDetailsPanel.tsx
+++ b/apps/web/src/components/roster/BotDetailsPanel.tsx
@@ -586,7 +586,9 @@ export function BotDetailsPanel({
<>
<header className="relative flex h-[var(--workspace-topbar-height)] shrink-0 items-center justify-center px-4">
<h2 className="text-sm font-medium">Settings</h2>
- <div className="absolute right-3 flex items-center">{closeButton}</div>
+ <div className="absolute right-3 flex items-center min-[981px]:fixed min-[981px]:right-[var(--workspace-controls-right)] min-[981px]:top-[var(--workspace-controls-top)] min-[981px]:z-40 min-[981px]:h-[var(--workspace-topbar-height)]">
+ {closeButton}
+ </div>
</header>
<BotProfileEditor
bot={bot}
diff --git a/apps/web/src/components/roster/BotMessageAttachments.test.tsx b/apps/web/src/components/roster/BotMessageAttachments.test.tsx
index fa326f203..1d87cc77b 100644
--- a/apps/web/src/components/roster/BotMessageAttachments.test.tsx
+++ b/apps/web/src/components/roster/BotMessageAttachments.test.tsx
@@ -19,6 +19,13 @@ const attachments: ChatAttachment[] = [
sizeBytes: 20,
},
];
+const fileAttachment: ChatAttachment = {
+ type: "file",
+ id: "attachment-notes",
+ name: "notes.md",
+ mimeType: "text/markdown",
+ sizeBytes: 30,
+};
describe("sent bot message attachments", () => {
it("preserves image order and opens the selected image", () => {
@@ -54,4 +61,14 @@ describe("sent bot message attachments", () => {
),
).toBeNull();
});
+
+ it("keeps documents out of the image lightbox", () => {
+ expect(
+ buildBotMessageAttachmentPreview(
+ [...attachments, fileAttachment],
+ ["http://example.test/first", "http://example.test/second", "http://example.test/notes"],
+ fileAttachment.id,
+ ),
+ ).toBeNull();
+ });
});
diff --git a/apps/web/src/components/roster/BotMessageAttachments.tsx b/apps/web/src/components/roster/BotMessageAttachments.tsx
index 07e173dcc..ba055e67f 100644
--- a/apps/web/src/components/roster/BotMessageAttachments.tsx
+++ b/apps/web/src/components/roster/BotMessageAttachments.tsx
@@ -1,4 +1,5 @@
import type { ChatAttachment, EnvironmentId } from "@t3tools/contracts";
+import { FileTextIcon } from "lucide-react";
import { useMemo, useState } from "react";
import { useAssetUrls } from "../../assets/assetUrls";
@@ -12,11 +13,17 @@ export function buildBotMessageAttachmentPreview(
failedIds: ReadonlySet<string> = new Set(),
): ExpandedImagePreview | null {
return buildExpandedImagePreview(
- attachments.map((attachment, index) => ({
- id: attachment.id,
- name: attachment.name,
- ...(urls[index] && !failedIds.has(attachment.id) ? { previewUrl: urls[index] } : {}),
- })),
+ attachments.flatMap((attachment, index) =>
+ attachment.type === "image"
+ ? [
+ {
+ id: attachment.id,
+ name: attachment.name,
+ ...(urls[index] && !failedIds.has(attachment.id) ? { previewUrl: urls[index] } : {}),
+ },
+ ]
+ : [],
+ ),
selectedAttachmentId,
);
}
@@ -46,7 +53,22 @@ export function BotMessageAttachments({
<div className="grid max-w-[420px] grid-cols-1 gap-2 sm:grid-cols-2">
{attachments.map((attachment, index) => {
const url = urls[index];
- const canPreview = url !== null && !failedIds.has(attachment.id);
+ const canPreview =
+ attachment.type === "image" && url !== null && !failedIds.has(attachment.id);
+ if (attachment.type === "file") {
+ return (
+ <a
+ key={attachment.id}
+ data-testid="bot-message-attachment"
+ className="flex min-h-14 items-center gap-2 rounded-lg border border-border/70 bg-background/45 px-3 py-2 text-sm hover:bg-muted/50"
+ href={url ?? undefined}
+ download={attachment.name}
+ >
+ <FileTextIcon className="size-5 shrink-0 text-muted-foreground" />
+ <span className="min-w-0 truncate">{attachment.name}</span>
+ </a>
+ );
+ }
return (
<div
key={attachment.id}
diff --git a/apps/web/src/components/roster/BotPromptComposer.tsx b/apps/web/src/components/roster/BotPromptComposer.tsx
index be20788f1..de93f7bea 100644
--- a/apps/web/src/components/roster/BotPromptComposer.tsx
+++ b/apps/web/src/components/roster/BotPromptComposer.tsx
@@ -1,6 +1,6 @@
import { useAtomValue } from "@effect/atom-react";
import { PROVIDER_SEND_TURN_MAX_ATTACHMENTS } from "@t3tools/contracts";
-import { ArrowUpIcon, AtSignIcon, PaperclipIcon, PlusIcon } from "lucide-react";
+import { ArrowUpIcon, AtSignIcon, PaperclipIcon, PlusIcon, XIcon } from "lucide-react";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { type ReactNode, useCallback, useEffect, useRef, useState } from "react";
@@ -112,6 +112,8 @@ export function BotPromptComposer({
mentionBots = EMPTY_MENTION_BOTS,
pendingActionSlot = null,
placeholder,
+ replyPreview,
+ onCancelReply,
onSubmit,
}: {
botName: string;
@@ -122,6 +124,8 @@ export function BotPromptComposer({
/** Rendered above the prompt box so a pending decision reads as part of the composer. */
pendingActionSlot?: ReactNode;
placeholder?: string;
+ replyPreview?: { readonly label: string; readonly text: string } | null;
+ onCancelReply?: () => void;
onSubmit: (prompt: string, files: readonly File[], respondingBotId?: string) => Promise<boolean>;
}) {
const prefersReducedMotion = useReducedMotion();
@@ -185,7 +189,7 @@ export function BotPromptComposer({
[releaseAttachments],
);
- const expanded = attachments.length > 0 || isBotPromptExpanded(draft);
+ const expanded = attachments.length > 0 || replyPreview != null || isBotPromptExpanded(draft);
const addFiles = (next: FileList | readonly File[]) => {
revisionRef.current += 1;
const added = createBotPromptAttachments(Array.from(next));
@@ -545,6 +549,22 @@ export function BotPromptComposer({
pendingActionSlot ? "rounded-t-md border-t-transparent" : undefined,
)}
>
+ {replyPreview ? (
+ <div className="mx-3 mt-3 flex items-start gap-2 rounded-xl bg-foreground/8 px-3 py-2 text-xs">
+ <div className="min-w-0 flex-1">
+ <div className="font-medium">Replying to {replyPreview.label}</div>
+ <div className="truncate text-muted-foreground">{replyPreview.text}</div>
+ </div>
+ <button
+ type="button"
+ aria-label="Cancel reply"
+ className="flex size-6 shrink-0 items-center justify-center rounded-full text-muted-foreground hover:bg-foreground/8 hover:text-foreground"
+ onClick={onCancelReply}
+ >
+ <XIcon className="size-3.5" />
+ </button>
+ </div>
+ ) : null}
<BotPromptAttachments
attachments={attachments}
className="px-3 pt-3"
@@ -605,7 +625,7 @@ export function BotPromptComposer({
<MenuPopup align="start" side="top" sideOffset={8}>
<MenuItem onClick={() => fileInputRef.current?.click()}>
<PaperclipIcon />
- Attach image
+ Attach file
</MenuItem>
{mentionBots.map((bot) => (
<MenuItem
@@ -632,7 +652,7 @@ export function BotPromptComposer({
<input
ref={fileInputRef}
type="file"
- accept="image/*"
+ accept="image/*,.txt,.md,.markdown,.csv,.json,.yaml,.yml,.toml,.xml,.pdf"
multiple
disabled={readOnly}
className="sr-only"
diff --git a/apps/web/src/components/roster/BotThreadLanding.tsx b/apps/web/src/components/roster/BotThreadLanding.tsx
index 03729ea62..fa804839d 100644
--- a/apps/web/src/components/roster/BotThreadLanding.tsx
+++ b/apps/web/src/components/roster/BotThreadLanding.tsx
@@ -23,6 +23,7 @@ import { usePrimaryEnvironmentId } from "../../state/environments";
import { useThreadActivities } from "../../state/entities";
import { primaryServerProvidersAtom, serverEnvironment } from "../../state/server";
import { environmentSnapshotAtom } from "../../state/shell";
+import { threadEnvironment } from "../../state/threads";
import { useEnvironmentQuery } from "../../state/query";
import { useEnvironmentSessionState } from "../../state/session";
import { useAtomCommand } from "../../state/use-atom-command";
@@ -51,6 +52,14 @@ import { BotMessageAttachments } from "./BotMessageAttachments";
import { BotStepMeter } from "./BotStepMeter";
import { buildBotStepMeters } from "./botStepMeter.logic";
import { ThreadErrorBanner } from "../chat/ThreadErrorBanner";
+import {
+ buildReplyPrompt,
+ MessageControls,
+ type MessageReactionOption,
+ type MessageReplyTarget,
+ selectedReactionForPerson,
+} from "../chat/MessageControls";
+import { MessageReactions } from "../chat/MessageReactions";
import { BotVoiceCallButton, useVoiceCall } from "../voice/VoiceCall";
import { useBotPresence } from "./botPresence";
import { useRosterStore } from "./rosterStore";
@@ -117,8 +126,12 @@ export function BotThreadLanding({ botId }: { readonly botId: string }) {
const canManageChannelBindings = canManageChannels(channelSession.data);
const settings = usePrimarySettings();
const providers = useAtomValue(primaryServerProvidersAtom);
+ const setMessageReaction = useAtomCommand(threadEnvironment.setMessageReaction, {
+ reportFailure: false,
+ });
const bots = useRosterStore((state) => state.bots);
const bot = bots.find((candidate) => candidate.id === botId);
+ const [replyTarget, setReplyTarget] = useState<MessageReplyTarget | null>(null);
const configuredEngine = bot?.engine ?? null;
const instanceEntries = useMemo(
() =>
@@ -155,6 +168,10 @@ export function BotThreadLanding({ botId }: { readonly botId: string }) {
);
const snapshot = useAtomValue(environmentSnapshotAtom(environmentId ?? NO_ENVIRONMENT));
+ useEffect(() => {
+ setReplyTarget(null);
+ }, [botId, runtime.linkedThreadRef?.environmentId, runtime.linkedThreadRef?.threadId]);
+
useEffect(() => {
if (!bot || bot.archivedAt !== null) {
void navigate({ to: "/", replace: true });
@@ -178,6 +195,38 @@ export function BotThreadLanding({ botId }: { readonly botId: string }) {
(delegation) => delegation.parentThreadId === runtime.linkedThreadRef?.threadId,
) ?? [])
: [];
+ const currentPersonId = snapshot?.currentPersonId;
+ const updateReaction = async (
+ messageId: MessageId,
+ current: MessageReactionOption | null,
+ next: MessageReactionOption | null,
+ ) => {
+ const threadRef = runtime.linkedThreadRef;
+ if (!threadRef) return;
+ const dispatch = (emoji: MessageReactionOption, present: boolean) =>
+ setMessageReaction({
+ environmentId: threadRef.environmentId,
+ input: {
+ threadId: threadRef.threadId,
+ messageId,
+ emoji,
+ present,
+ },
+ });
+ if (current && current !== next) {
+ const removed = await dispatch(current, false);
+ if (removed._tag === "Failure") {
+ toastManager.add({ type: "error", title: "Could not update reaction" });
+ return;
+ }
+ }
+ if (next) {
+ const added = await dispatch(next, true);
+ if (added._tag === "Failure") {
+ toastManager.add({ type: "error", title: "Could not update reaction" });
+ }
+ }
+ };
return (
<SidebarInset
@@ -210,7 +259,7 @@ export function BotThreadLanding({ botId }: { readonly botId: string }) {
message.role === "assistant" ? (
<div
key={message.id}
- className="flex items-start gap-3"
+ className="group/message flex items-start gap-3"
data-testid="bot-provider-message"
>
<BotAvatarView
@@ -229,6 +278,30 @@ export function BotThreadLanding({ botId }: { readonly botId: string }) {
text={message.text}
threadRef={runtime.linkedThreadRef ?? undefined}
/>
+ <div className="mt-1 flex opacity-0 transition-opacity focus-within:opacity-100 group-hover/message:opacity-100 max-md:opacity-100">
+ <MessageControls
+ copyText={message.text || "Attachment"}
+ selectedReaction={selectedReactionForPerson(
+ message.reactions,
+ currentPersonId,
+ )}
+ onReply={() =>
+ setReplyTarget({
+ messageId: message.id,
+ label: bot.name,
+ text: message.text || "Attachment",
+ })
+ }
+ onReactionChange={(next) =>
+ void updateReaction(
+ message.id,
+ selectedReactionForPerson(message.reactions, currentPersonId),
+ next,
+ )
+ }
+ />
+ </div>
+ <MessageReactions reactions={message.reactions ?? []} />
{canManageChannelBindings && environmentId && runtime.linkedThreadRef
? (() => {
const origin = channelOriginForAssistantMessage(messages, messageIndex);
@@ -250,17 +323,59 @@ export function BotThreadLanding({ botId }: { readonly botId: string }) {
</div>
</div>
) : (
- <div key={message.id} className="flex justify-end" data-testid="bot-user-message">
- <div className="max-w-[78%] rounded-2xl bg-foreground/10 px-3.5 py-2 text-sm leading-6">
- {message.text ? <p className="whitespace-pre-wrap">{message.text}</p> : null}
- {message.attachments?.length ? (
- <div className={message.text ? "mt-2" : undefined}>
- <BotMessageAttachments
- attachments={message.attachments}
- environmentId={environmentId ?? NO_ENVIRONMENT}
- />
- </div>
- ) : null}
+ <div
+ key={message.id}
+ className="group/message flex items-end justify-end gap-1"
+ data-testid="bot-user-message"
+ >
+ <div className="opacity-0 transition-opacity focus-within:opacity-100 group-hover/message:opacity-100 max-md:opacity-100">
+ <MessageControls
+ align="end"
+ copyText={
+ message.text ||
+ message.attachments?.map((attachment) => attachment.name).join(", ") ||
+ "Attachment"
+ }
+ selectedReaction={selectedReactionForPerson(
+ message.reactions,
+ currentPersonId,
+ )}
+ onReply={() =>
+ setReplyTarget({
+ messageId: message.id,
+ label: "you",
+ text:
+ message.text ||
+ message.attachments
+ ?.map((attachment) => attachment.name)
+ .join(", ") ||
+ "Attachment",
+ })
+ }
+ onReactionChange={(next) =>
+ void updateReaction(
+ message.id,
+ selectedReactionForPerson(message.reactions, currentPersonId),
+ next,
+ )
+ }
+ />
+ </div>
+ <div className="flex max-w-[78%] flex-col items-end">
+ <div className="w-full rounded-2xl bg-foreground/10 px-3.5 py-2 text-sm leading-6">
+ {message.text ? (
+ <p className="whitespace-pre-wrap">{message.text}</p>
+ ) : null}
+ {message.attachments?.length ? (
+ <div className={message.text ? "mt-2" : undefined}>
+ <BotMessageAttachments
+ attachments={message.attachments}
+ environmentId={environmentId ?? NO_ENVIRONMENT}
+ />
+ </div>
+ ) : null}
+ </div>
+ <MessageReactions reactions={message.reactions ?? []} />
</div>
</div>
),
@@ -326,7 +441,13 @@ export function BotThreadLanding({ botId }: { readonly botId: string }) {
!runtime.bootstrapped ||
runtime.defaultProject === null
}
- onSubmit={runtime.send}
+ replyPreview={replyTarget}
+ onCancelReply={() => setReplyTarget(null)}
+ onSubmit={async (prompt, files) => {
+ const sent = await runtime.send(buildReplyPrompt(replyTarget, prompt), files);
+ if (sent) setReplyTarget(null);
+ return sent;
+ }}
/>
{stickyEngine === null ? (
<p className="px-4 pb-3 text-center text-xs text-muted-foreground">
diff --git a/apps/web/src/components/roster/GroupDetailsPanel.tsx b/apps/web/src/components/roster/GroupDetailsPanel.tsx
index 4fe184e36..677be3dd4 100644
--- a/apps/web/src/components/roster/GroupDetailsPanel.tsx
+++ b/apps/web/src/components/roster/GroupDetailsPanel.tsx
@@ -302,7 +302,9 @@ export function GroupDetailsPanel(props: {
<>
<header className="relative flex h-[var(--workspace-topbar-height)] shrink-0 items-center justify-center px-4">
<h2 className="text-sm font-medium">Group</h2>
- <div className="absolute right-3 flex items-center">{closeButton}</div>
+ <div className="absolute right-3 flex items-center min-[981px]:fixed min-[981px]:right-[var(--workspace-controls-right)] min-[981px]:top-[var(--workspace-controls-top)] min-[981px]:z-40 min-[981px]:h-[var(--workspace-topbar-height)]">
+ {closeButton}
+ </div>
</header>
<GroupEditor {...props} />
</>
diff --git a/apps/web/src/components/roster/GroupThreadLanding.tsx b/apps/web/src/components/roster/GroupThreadLanding.tsx
index d30515bb6..cc2df3668 100644
--- a/apps/web/src/components/roster/GroupThreadLanding.tsx
+++ b/apps/web/src/components/roster/GroupThreadLanding.tsx
@@ -1,7 +1,6 @@
import { useAtomValue } from "@effect/atom-react";
-import type { EnvironmentId } from "@t3tools/contracts";
-import { useNavigate } from "@tanstack/react-router";
-import { useEffect, useMemo } from "react";
+import { type EnvironmentId, type MessageId } from "@t3tools/contracts";
+import { useEffect, useMemo, useState } from "react";
import { selectOpenBotInboxItems } from "../../botInbox";
import { openSettings } from "../../settingsDialogStore";
@@ -11,9 +10,20 @@ import { useEnvironmentQuery } from "../../state/query";
import { useThreadActivities } from "../../state/entities";
import { serverEnvironment } from "../../state/server";
import { environmentSnapshotAtom } from "../../state/shell";
+import { threadEnvironment } from "../../state/threads";
+import { useAtomCommand } from "../../state/use-atom-command";
import { SidebarInset } from "../ui/sidebar";
+import { toastManager } from "../ui/toast";
import ChatMarkdown from "../ChatMarkdown";
import { WorkspacePageHeader } from "../WorkspacePageHeader";
+import {
+ buildReplyPrompt,
+ MessageControls,
+ type MessageReactionOption,
+ type MessageReplyTarget,
+ selectedReactionForPerson,
+} from "../chat/MessageControls";
+import { MessageReactions } from "../chat/MessageReactions";
import { ThreadErrorBanner } from "../chat/ThreadErrorBanner";
import { BotActivityStatus } from "./BotActivityStatus";
import { BotApprovalPrompt } from "./BotApprovalPrompt";
@@ -53,6 +63,10 @@ export function GroupThreadLanding({ groupId }: { readonly groupId: string }) {
);
const bots = useRosterStore((state) => state.bots);
const runtime = useGroupThreadRuntime(groupId);
+ const setMessageReaction = useAtomCommand(threadEnvironment.setMessageReaction, {
+ reportFailure: false,
+ });
+ const [replyTarget, setReplyTarget] = useState<MessageReplyTarget | null>(null);
const approvalState = useRosterPendingApproval(runtime.linkedThreadRef);
const activities = useThreadActivities(runtime.linkedThreadRef);
const stepMeters = useMemo(() => buildBotStepMeters(activities), [activities]);
@@ -64,6 +78,10 @@ export function GroupThreadLanding({ groupId }: { readonly groupId: string }) {
);
const snapshot = useAtomValue(environmentSnapshotAtom(environmentId ?? NO_ENVIRONMENT));
+ useEffect(() => {
+ setReplyTarget(null);
+ }, [groupId, runtime.linkedThreadRef?.environmentId, runtime.linkedThreadRef?.threadId]);
+
if (!group) return null;
const members = groupBotMembers(group, bots).filter((bot) => bot.archivedAt === null);
const boss = resolveAvailableGroupBoss(members, group.bossBotId);
@@ -82,6 +100,37 @@ export function GroupThreadLanding({ groupId }: { readonly groupId: string }) {
(delegation) => delegation.parentThreadId === runtime.linkedThreadRef?.threadId,
) ?? [])
: [];
+ const updateReaction = async (
+ messageId: MessageId,
+ current: MessageReactionOption | null,
+ next: MessageReactionOption | null,
+ ) => {
+ const threadRef = runtime.linkedThreadRef;
+ if (!threadRef) return;
+ const dispatch = (emoji: MessageReactionOption, present: boolean) =>
+ setMessageReaction({
+ environmentId: threadRef.environmentId,
+ input: {
+ threadId: threadRef.threadId,
+ messageId,
+ emoji,
+ present,
+ },
+ });
+ if (current && current !== next) {
+ const removed = await dispatch(current, false);
+ if (removed._tag === "Failure") {
+ toastManager.add({ type: "error", title: "Could not update reaction" });
+ return;
+ }
+ }
+ if (next) {
+ const added = await dispatch(next, true);
+ if (added._tag === "Failure") {
+ toastManager.add({ type: "error", title: "Could not update reaction" });
+ }
+ }
+ };
return (
<SidebarInset
@@ -116,8 +165,9 @@ export function GroupThreadLanding({ groupId }: { readonly groupId: string }) {
) : (
messages.map((message) => {
if (message.role === "assistant") {
- const respondingBot =
- members.find((bot) => bot.id === message.respondingBotId) ?? boss;
+ const respondingBot = message.respondingBotId
+ ? members.find((bot) => bot.id === message.respondingBotId)
+ : boss;
if (!respondingBot) {
return (
<div
@@ -132,13 +182,25 @@ export function GroupThreadLanding({ groupId }: { readonly groupId: string }) {
text={message.text}
threadRef={runtime.linkedThreadRef ?? undefined}
/>
+ <div className="mt-1">
+ <MessageControls
+ copyText={message.text || "Attachment"}
+ onReply={() =>
+ setReplyTarget({
+ messageId: message.id,
+ label: "Unavailable bot",
+ text: message.text || "Attachment",
+ })
+ }
+ />
+ </div>
</div>
);
}
return (
<div
key={message.id}
- className="flex items-start gap-3"
+ className="group/message flex items-start gap-3"
data-testid="group-provider-message"
>
<BotAvatarView
@@ -157,6 +219,33 @@ export function GroupThreadLanding({ groupId }: { readonly groupId: string }) {
text={message.text}
threadRef={runtime.linkedThreadRef ?? undefined}
/>
+ <div className="mt-1 flex opacity-0 transition-opacity focus-within:opacity-100 group-hover/message:opacity-100 max-md:opacity-100">
+ <MessageControls
+ copyText={message.text || "Attachment"}
+ selectedReaction={selectedReactionForPerson(
+ message.reactions,
+ peopleIdentity.current?.id,
+ )}
+ onReply={() =>
+ setReplyTarget({
+ messageId: message.id,
+ label: respondingBot.name,
+ text: message.text || "Attachment",
+ })
+ }
+ onReactionChange={(next) =>
+ void updateReaction(
+ message.id,
+ selectedReactionForPerson(
+ message.reactions,
+ peopleIdentity.current?.id,
+ ),
+ next,
+ )
+ }
+ />
+ </div>
+ <MessageReactions reactions={message.reactions ?? []} />
</div>
</div>
);
@@ -167,17 +256,55 @@ export function GroupThreadLanding({ groupId }: { readonly groupId: string }) {
peopleIdentity.host?.id,
);
return (
- <div key={message.id} className="flex justify-end" data-testid="group-user-message">
- <div className="max-w-[78%] rounded-2xl bg-foreground/10 px-3.5 py-2 text-sm leading-6">
- {message.text ? <p className="whitespace-pre-wrap">{message.text}</p> : null}
- {message.attachments?.length ? (
- <div className={message.text ? "mt-2" : undefined}>
- <BotMessageAttachments
- attachments={message.attachments}
- environmentId={environmentId ?? NO_ENVIRONMENT}
- />
- </div>
- ) : null}
+ <div
+ key={message.id}
+ className="group/message flex items-end justify-end gap-1"
+ data-testid="group-user-message"
+ >
+ <div className="opacity-0 transition-opacity focus-within:opacity-100 group-hover/message:opacity-100 max-md:opacity-100">
+ <MessageControls
+ align="end"
+ copyText={
+ message.text ||
+ message.attachments?.map((attachment) => attachment.name).join(", ") ||
+ "Attachment"
+ }
+ selectedReaction={selectedReactionForPerson(
+ message.reactions,
+ peopleIdentity.current?.id,
+ )}
+ onReply={() =>
+ setReplyTarget({
+ messageId: message.id,
+ label: current ? "you" : "participant",
+ text:
+ message.text ||
+ message.attachments?.map((attachment) => attachment.name).join(", ") ||
+ "Attachment",
+ })
+ }
+ onReactionChange={(next: MessageReactionOption | null) =>
+ void updateReaction(
+ message.id,
+ selectedReactionForPerson(message.reactions, peopleIdentity.current?.id),
+ next,
+ )
+ }
+ />
+ </div>
+ <div className="flex max-w-[78%] flex-col items-end">
+ <div className="w-full rounded-2xl bg-foreground/10 px-3.5 py-2 text-sm leading-6">
+ {message.text ? <p className="whitespace-pre-wrap">{message.text}</p> : null}
+ {message.attachments?.length ? (
+ <div className={message.text ? "mt-2" : undefined}>
+ <BotMessageAttachments
+ attachments={message.attachments}
+ environmentId={environmentId ?? NO_ENVIRONMENT}
+ />
+ </div>
+ ) : null}
+ </div>
+ <MessageReactions reactions={message.reactions ?? []} />
</div>
</div>
);
@@ -248,7 +375,17 @@ export function GroupThreadLanding({ groupId }: { readonly groupId: string }) {
boss === null
}
mentionBots={members.map((bot) => ({ id: bot.id, name: bot.name }))}
- onSubmit={runtime.send}
+ replyPreview={replyTarget}
+ onCancelReply={() => setReplyTarget(null)}
+ onSubmit={async (prompt, files, respondingBotId) => {
+ const sent = await runtime.send(
+ buildReplyPrompt(replyTarget, prompt),
+ files,
+ respondingBotId,
+ );
+ if (sent) setReplyTarget(null);
+ return sent;
+ }}
/>
</div>
</SidebarInset>
diff --git a/apps/web/src/components/roster/botFileAttachment.test.ts b/apps/web/src/components/roster/botFileAttachment.test.ts
new file mode 100644
index 000000000..df32e0c3b
--- /dev/null
+++ b/apps/web/src/components/roster/botFileAttachment.test.ts
@@ -0,0 +1,27 @@
+import { describe, expect, it } from "vite-plus/test";
+
+import { resolveBotFileAttachment } from "./botFileAttachment";
+
+describe("resolveBotFileAttachment", () => {
+ it("accepts supported images and documents", () => {
+ expect(resolveBotFileAttachment({ name: "image.png", size: 3, type: "image/png" })).toEqual({
+ type: "image",
+ mimeType: "image/png",
+ });
+ expect(resolveBotFileAttachment({ name: "notes.md", size: 3, type: "" })).toEqual({
+ type: "file",
+ mimeType: "text/markdown",
+ });
+ expect(
+ resolveBotFileAttachment({ name: "report.pdf", size: 3, type: "application/pdf" }),
+ ).toEqual({ type: "file", mimeType: "application/pdf" });
+ });
+
+ it("rejects active content, unknown files, and empty files", () => {
+ expect(resolveBotFileAttachment({ name: "page.html", size: 3, type: "text/html" })).toBeNull();
+ expect(
+ resolveBotFileAttachment({ name: "vector.svg", size: 3, type: "image/svg+xml" }),
+ ).toBeNull();
+ expect(resolveBotFileAttachment({ name: "notes.txt", size: 0, type: "text/plain" })).toBeNull();
+ });
+});
diff --git a/apps/web/src/components/roster/botFileAttachment.ts b/apps/web/src/components/roster/botFileAttachment.ts
new file mode 100644
index 000000000..e18eb1488
--- /dev/null
+++ b/apps/web/src/components/roster/botFileAttachment.ts
@@ -0,0 +1,43 @@
+import {
+ isProviderSendTurnSupportedFileMimeType,
+ isProviderSendTurnSupportedImageMimeType,
+ PROVIDER_SEND_TURN_MAX_FILE_BYTES,
+ PROVIDER_SEND_TURN_MAX_IMAGE_BYTES,
+ type UploadChatFileAttachment,
+ type UploadChatImageAttachment,
+} from "@t3tools/contracts";
+
+const FILE_MIME_BY_EXTENSION: Readonly<Record<string, string>> = {
+ csv: "text/csv",
+ json: "application/json",
+ markdown: "text/markdown",
+ md: "text/markdown",
+ pdf: "application/pdf",
+ toml: "application/toml",
+ txt: "text/plain",
+ xml: "application/xml",
+ yaml: "application/x-yaml",
+ yml: "application/x-yaml",
+};
+
+export type BotFileAttachmentKind =
+ | Pick<UploadChatFileAttachment, "mimeType" | "type">
+ | Pick<UploadChatImageAttachment, "mimeType" | "type">;
+
+export function resolveBotFileAttachment(
+ file: Pick<File, "name" | "size" | "type">,
+): BotFileAttachmentKind | null {
+ const declaredMimeType = file.type.trim().toLowerCase();
+ if (isProviderSendTurnSupportedImageMimeType(declaredMimeType)) {
+ return file.size > 0 && file.size <= PROVIDER_SEND_TURN_MAX_IMAGE_BYTES
+ ? { type: "image", mimeType: declaredMimeType }
+ : null;
+ }
+ const extension = file.name.split(".").at(-1)?.toLowerCase() ?? "";
+ const mimeType = isProviderSendTurnSupportedFileMimeType(declaredMimeType)
+ ? declaredMimeType
+ : FILE_MIME_BY_EXTENSION[extension];
+ return mimeType && file.size > 0 && file.size <= PROVIDER_SEND_TURN_MAX_FILE_BYTES
+ ? { type: "file", mimeType: mimeType as UploadChatFileAttachment["mimeType"] }
+ : null;
+}
diff --git a/apps/web/src/components/roster/useBotThreadRuntime.ts b/apps/web/src/components/roster/useBotThreadRuntime.ts
index 0ad93e0bd..3ca7b500a 100644
--- a/apps/web/src/components/roster/useBotThreadRuntime.ts
+++ b/apps/web/src/components/roster/useBotThreadRuntime.ts
@@ -19,6 +19,7 @@ import { resolveAppModelSelectionState } from "../../modelSelection";
import {
useAllEnvironmentShellsBootstrapped,
useProjects,
+ readEnvironmentSupportsFileAttachments,
useThreadActivities,
useThreadMessages,
useThreadShell,
@@ -47,6 +48,7 @@ import {
} from "./botThreadRuntime.logic";
import { useRosterStore } from "./rosterStore";
import { ensureLocalApi } from "../../localApi";
+import { resolveBotFileAttachment } from "./botFileAttachment";
const NO_ENVIRONMENT = "" as EnvironmentId;
@@ -55,7 +57,12 @@ function errorMessage(result: Parameters<typeof squashAtomCommandFailure>[0]): s
return error instanceof Error ? error.message : "Could not send the message.";
}
-function readFileAsDataUrl(file: File): Promise<string> {
+function threadTitle(prompt: string, files: readonly File[]): string {
+ const seed = prompt || (files[0] ? `File: ${files[0].name}` : "New thread");
+ return seed.length > 80 ? `${seed.slice(0, 79)}…` : seed;
+}
+
+function readFileAsDataUrl(file: File, mimeType: string): Promise<string> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.addEventListener(
@@ -67,7 +74,7 @@ function readFileAsDataUrl(file: File): Promise<string> {
"load",
() =>
typeof reader.result === "string"
- ? resolve(reader.result)
+ ? resolve(`data:${mimeType};base64,${reader.result.split(",", 2)[1] ?? ""}`)
: reject(new Error(`Could not read ${file.name}.`)),
{ once: true },
);
@@ -280,9 +287,9 @@ export function useBotThreadRuntime(botId: string, effectiveModelSelection: Mode
setError("Add a project before you message a bot.");
return Promise.resolve(false);
}
- const unsupported = files.find((file) => !file.type.startsWith("image/"));
+ const unsupported = files.find((file) => resolveBotFileAttachment(file) === null);
if (unsupported) {
- setError("Bot attachments must be images.");
+ setError(`This file type is not supported: ${unsupported.name}`);
return Promise.resolve(false);
}
@@ -300,17 +307,20 @@ export function useBotThreadRuntime(botId: string, effectiveModelSelection: Mode
bot?.sandbox ?? null,
settings.localExecutionMode,
);
- const title = bot?.name ?? "Bot";
+ const title = threadTitle(prompt, files);
try {
const attachments = await Promise.all(
- files.map(async (file) => ({
- type: "image" as const,
- name: file.name,
- mimeType: file.type,
- sizeBytes: file.size,
- dataUrl: await readFileAsDataUrl(file),
- })),
+ files.map(async (file) => {
+ const attachment = resolveBotFileAttachment(file);
+ if (!attachment) throw new Error(`This file type is not supported: ${file.name}`);
+ return {
+ ...attachment,
+ name: file.name,
+ sizeBytes: file.size,
+ dataUrl: await readFileAsDataUrl(file, attachment.mimeType),
+ };
+ }),
);
const currentThreadRef =
retainedThreadRef.current.threadRef ?? (await ensureTranscriptThread(title));
@@ -318,6 +328,13 @@ export function useBotThreadRuntime(botId: string, effectiveModelSelection: Mode
setError("Could not send the message.");
return false;
}
+ if (
+ files.some((file) => resolveBotFileAttachment(file)?.type === "file") &&
+ !readEnvironmentSupportsFileAttachments(activeProject.environmentId)
+ ) {
+ setError("Update the connected Akeru server to attach files.");
+ return false;
+ }
if (rememberedThread && rememberedThread.runtimeMode !== runtimeMode) {
const modeResult = await setRuntimeMode({
environmentId: currentThreadRef.environmentId,
diff --git a/apps/web/src/components/roster/useGroupThreadRuntime.ts b/apps/web/src/components/roster/useGroupThreadRuntime.ts
index 9145264a3..69bd00f91 100644
--- a/apps/web/src/components/roster/useGroupThreadRuntime.ts
+++ b/apps/web/src/components/roster/useGroupThreadRuntime.ts
@@ -20,6 +20,7 @@ import { environmentGroupsAtom } from "../../state/bots";
import {
useAllEnvironmentShellsBootstrapped,
useProjects,
+ readEnvironmentSupportsFileAttachments,
useThreadActivities,
useThreadMessages,
useThreadShell,
@@ -42,6 +43,7 @@ import { resolveBotRuntimeMode } from "./botSandbox";
import { buildGroupTurnStartInput, findLatestGroupThreadTarget } from "./botThreadRuntime.logic";
import { groupContainsBot } from "./roster.logic";
import { useRosterStore } from "./rosterStore";
+import { resolveBotFileAttachment } from "./botFileAttachment";
const NO_ENVIRONMENT = "" as EnvironmentId;
@@ -50,7 +52,12 @@ function errorMessage(result: Parameters<typeof squashAtomCommandFailure>[0]): s
return error instanceof Error ? error.message : "Could not send the message.";
}
-function readFileAsDataUrl(file: File): Promise<string> {
+function threadTitle(prompt: string, files: readonly File[]): string {
+ const seed = prompt || (files[0] ? `File: ${files[0].name}` : "New thread");
+ return seed.length > 80 ? `${seed.slice(0, 79)}…` : seed;
+}
+
+function readFileAsDataUrl(file: File, mimeType: string): Promise<string> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.addEventListener(
@@ -62,7 +69,7 @@ function readFileAsDataUrl(file: File): Promise<string> {
"load",
() =>
typeof reader.result === "string"
- ? resolve(reader.result)
+ ? resolve(`data:${mimeType};base64,${reader.result.split(",", 2)[1] ?? ""}`)
: reject(new Error(`Could not read ${file.name}.`)),
{ once: true },
);
@@ -209,9 +216,16 @@ export function useGroupThreadRuntime(groupId: string) {
setError("Add a project before you message a group.");
return false;
}
- const unsupported = files.find((file) => !file.type.startsWith("image/"));
+ const unsupported = files.find((file) => resolveBotFileAttachment(file) === null);
if (unsupported) {
- setError("Group attachments must be images.");
+ setError(`This file type is not supported: ${unsupported.name}`);
+ return false;
+ }
+ if (
+ files.some((file) => resolveBotFileAttachment(file)?.type === "file") &&
+ !readEnvironmentSupportsFileAttachments(activeProject.environmentId)
+ ) {
+ setError("Update the connected Akeru server to attach files.");
return false;
}
@@ -241,13 +255,16 @@ export function useGroupThreadRuntime(groupId: string) {
try {
const attachments = await Promise.all(
- files.map(async (file) => ({
- type: "image" as const,
- name: file.name,
- mimeType: file.type,
- sizeBytes: file.size,
- dataUrl: await readFileAsDataUrl(file),
- })),
+ files.map(async (file) => {
+ const attachment = resolveBotFileAttachment(file);
+ if (!attachment) throw new Error(`This file type is not supported: ${file.name}`);
+ return {
+ ...attachment,
+ name: file.name,
+ sizeBytes: file.size,
+ dataUrl: await readFileAsDataUrl(file, attachment.mimeType),
+ };
+ }),
);
const environmentId = currentThreadRef?.environmentId ?? activeProject.environmentId;
if (currentThreadRef && rememberedThread?.runtimeMode !== runtimeMode) {
@@ -267,7 +284,7 @@ export function useGroupThreadRuntime(groupId: string) {
respondingBotId: BotId.make(respondingBot.id),
threadId,
projectId: activeProject.id,
- title: group.name,
+ title: threadTitle(prompt, files),
message: {
messageId: newMessageId(),
role: "user",
diff --git a/apps/web/src/components/settings/ThemeSettings.test.ts b/apps/web/src/components/settings/ThemeSettings.test.ts
new file mode 100644
index 000000000..e49324d37
--- /dev/null
+++ b/apps/web/src/components/settings/ThemeSettings.test.ts
@@ -0,0 +1,33 @@
+import { describe, expect, it } from "vite-plus/test";
+
+import { resolveSelectedThemeCardId, standardThemePreference } from "./ThemeSettings";
+
+describe("resolveSelectedThemeCardId", () => {
+ it("marks Akeru Classic only when it owns the visible appearance", () => {
+ expect(
+ resolveSelectedThemeCardId({
+ appearanceMode: "light",
+ initialAppearance: "dark",
+ lightOwner: null,
+ darkOwner: "akeru-paper",
+ }),
+ ).toBeNull();
+ });
+
+ it("marks Akeru Paper for dark mode and the active system appearance", () => {
+ const input = {
+ initialAppearance: "dark" as const,
+ lightOwner: null,
+ darkOwner: "akeru-paper",
+ };
+ expect(resolveSelectedThemeCardId({ ...input, appearanceMode: "dark" })).toBe("akeru-paper");
+ expect(resolveSelectedThemeCardId({ ...input, appearanceMode: "system" })).toBe("akeru-paper");
+ });
+});
+
+describe("standardThemePreference", () => {
+ it("keeps system appearance while storing the visible Classic palette", () => {
+ expect(standardThemePreference("system", "dark")).toBe("dark");
+ expect(standardThemePreference("system", "light")).toBe("light");
+ });
+});
diff --git a/apps/web/src/components/settings/ThemeSettings.tsx b/apps/web/src/components/settings/ThemeSettings.tsx
index d6309417a..4a84785c9 100644
--- a/apps/web/src/components/settings/ThemeSettings.tsx
+++ b/apps/web/src/components/settings/ThemeSettings.tsx
@@ -48,6 +48,24 @@ import { ThemeWireframe } from "./ThemeWireframe";
const MAINTAINER_THEMES: ReadonlyArray<ThemeDefinition> = BUILT_IN_THEMES;
+export function resolveSelectedThemeCardId(input: {
+ readonly appearanceMode: ThemeMode;
+ readonly initialAppearance: ThemeAppearance;
+ readonly lightOwner: string | null;
+ readonly darkOwner: string | null;
+}): string | null {
+ if (input.appearanceMode === "dark") return input.darkOwner;
+ if (input.appearanceMode === "light") return input.lightOwner;
+ return input.initialAppearance === "dark" ? input.darkOwner : input.lightOwner;
+}
+
+export function standardThemePreference(
+ appearanceMode: ThemeMode,
+ initialAppearance: ThemeAppearance,
+): ThemeMode {
+ return appearanceMode === "system" ? initialAppearance : appearanceMode;
+}
+
function collectionVariantLabels(themes: ReadonlyArray<ThemeDefinition>): ReadonlyArray<string> {
if (themes.length === 0) return [];
const words = themes.map((theme) => theme.label.trim().split(/\s+/));
@@ -681,6 +699,13 @@ export function ThemeLibrary({
return rings;
};
+ const selectedCardId = resolveSelectedThemeCardId({
+ appearanceMode,
+ initialAppearance,
+ lightOwner,
+ darkOwner,
+ });
+
const wireframeColors = (appearance: ThemeAppearance) =>
pickColors(appearance === "light" ? lightOwner : darkOwner, appearance);
@@ -763,7 +788,7 @@ export function ThemeLibrary({
{STANDARD_THEME_CARDS.map((standardTheme) => (
<ThemeLibraryCard
activeModes={pickedModesFor(null)}
- isActive={false}
+ isActive={selectedCardId === null}
key={standardTheme.id}
onDuplicate={() =>
openThemeEditor({
@@ -773,7 +798,7 @@ export function ThemeLibrary({
initialAppearance,
})
}
- onUse={() => persistTheme(appearanceMode === "system" ? "system" : appearanceMode)}
+ onUse={() => persistTheme(standardThemePreference(appearanceMode, initialAppearance))}
onUseMode={handlePairPick(null)}
theme={standardTheme}
/>
@@ -783,7 +808,7 @@ export function ThemeLibrary({
return (
<ThemeLibraryCard
activeModes={pickedModesFor(maintainerTheme.id)}
- isActive={false}
+ isActive={selectedCardId === maintainerTheme.id}
key={maintainerTheme.id}
onDuplicate={() =>
openThemeEditor({
diff --git a/apps/web/src/components/sidebar/SidebarChrome.tsx b/apps/web/src/components/sidebar/SidebarChrome.tsx
index 64a7235cb..c2f577c87 100644
--- a/apps/web/src/components/sidebar/SidebarChrome.tsx
+++ b/apps/web/src/components/sidebar/SidebarChrome.tsx
@@ -393,7 +393,7 @@ export const SidebarChromeFooter = memo(function SidebarChromeFooter() {
<SidebarProviderUpdatePill />
<SidebarUpdateArchitectureWarning />
</div>
- <SidebarMenu className="flex-row items-center justify-center gap-1 group-data-[collapsible=icon]:flex-col">
+ <SidebarMenu className="flex-row flex-wrap items-center justify-center gap-1 overflow-visible group-data-[collapsible=icon]:flex-col group-data-[collapsible=icon]:flex-nowrap">
<SidebarPluginSummary onClick={handlePluginsClick} />
<SidebarUtilityItem
icon={<AppIcon className="size-4" icon={Settings02Icon} />}
diff --git a/apps/web/src/historyBootstrap.ts b/apps/web/src/historyBootstrap.ts
index b6a2570f0..2130bde80 100644
--- a/apps/web/src/historyBootstrap.ts
+++ b/apps/web/src/historyBootstrap.ts
@@ -19,17 +19,17 @@ function messageRoleLabel(message: ChatMessage): "USER" | "ASSISTANT" {
}
function attachmentSummary(message: ChatMessage): string | null {
- const imageAttachments = message.attachments?.filter((attachment) => attachment.type === "image");
- const count = imageAttachments?.length ?? 0;
+ const attachments = message.attachments ?? [];
+ const count = attachments.length;
if (count === 0) {
return null;
}
- const names = imageAttachments?.slice(0, 3).map((image) => image.name) ?? [];
+ const names = attachments.slice(0, 3).map((attachment) => attachment.name);
const namesSummary = names.join(", ");
const extraCount = count - names.length;
const extraSummary = extraCount > 0 ? ` (+${extraCount} more)` : "";
- return `[Attached image${count === 1 ? "" : "s"}: ${namesSummary}${extraSummary}]`;
+ return `[Attached file${count === 1 ? "" : "s"}: ${namesSummary}${extraSummary}]`;
}
function buildMessageBlock(message: ChatMessage): string {
diff --git a/apps/web/src/state/entities.ts b/apps/web/src/state/entities.ts
index 7bca31182..63b68cb0b 100644
--- a/apps/web/src/state/entities.ts
+++ b/apps/web/src/state/entities.ts
@@ -232,6 +232,13 @@ export function readEnvironmentSupportsSettlement(environmentId: EnvironmentId):
);
}
+export function readEnvironmentSupportsFileAttachments(environmentId: EnvironmentId): boolean {
+ return (
+ appAtomRegistry.get(environmentServerConfigsAtom).get(environmentId)?.environment.capabilities
+ .fileAttachments === true
+ );
+}
+
/** Whether the environment's server understands thread.snooze/unsnooze.
Same version-skew contract as settlement. */
export function readEnvironmentSupportsSnooze(environmentId: EnvironmentId): boolean {
diff --git a/apps/web/src/types.ts b/apps/web/src/types.ts
index 45a8539a1..957dc2f08 100644
--- a/apps/web/src/types.ts
+++ b/apps/web/src/types.ts
@@ -1,4 +1,5 @@
import type {
+ ChatAttachment as ContractChatAttachment,
ChatImageAttachment as ContractChatImageAttachment,
OrchestrationCheckpointFile,
OrchestrationCheckpointSummary,
@@ -35,7 +36,7 @@ export interface ChatImageAttachment extends ContractChatImageAttachment {
readonly previewUrl?: string;
}
-export type ChatAttachment = ChatImageAttachment;
+export type ChatAttachment = ContractChatAttachment & { readonly previewUrl?: string };
export interface ChatMessage extends Omit<OrchestrationMessage, "attachments"> {
readonly attachments?: ReadonlyArray<ChatAttachment> | undefined;
diff --git a/packages/client-runtime/src/operations/commands.test.ts b/packages/client-runtime/src/operations/commands.test.ts
index 9bd4bc95e..bb96621b1 100644
--- a/packages/client-runtime/src/operations/commands.test.ts
+++ b/packages/client-runtime/src/operations/commands.test.ts
@@ -36,6 +36,7 @@ import {
disconnectChannel,
reconnectChannel,
sendChannelMessage,
+ setThreadMessageReaction,
settleThread,
setGroupBoss,
startThreadTurn,
@@ -347,4 +348,32 @@ describe("environment commands", () => {
]);
}).pipe(Effect.provide(TEST_CRYPTO_LAYER)),
);
+
+ it.effect("dispatches message reactions", () =>
+ Effect.gen(function* () {
+ const dispatched: ClientOrchestrationCommand[] = [];
+ const supervisor = yield* makeSupervisor(dispatched);
+
+ yield* setThreadMessageReaction({
+ commandId: CommandId.make("reaction-command"),
+ threadId: ThreadId.make("thread-1"),
+ messageId: MessageId.make("message-1"),
+ emoji: "👍",
+ present: true,
+ updatedAt: "2026-09-01T00:00:00.000Z",
+ }).pipe(Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor));
+
+ expect(dispatched).toEqual([
+ {
+ type: "thread.message.reaction.set",
+ commandId: "reaction-command",
+ threadId: "thread-1",
+ messageId: "message-1",
+ emoji: "👍",
+ present: true,
+ updatedAt: "2026-09-01T00:00:00.000Z",
+ },
+ ]);
+ }).pipe(Effect.provide(TEST_CRYPTO_LAYER)),
+ );
});
diff --git a/packages/client-runtime/src/operations/commands.ts b/packages/client-runtime/src/operations/commands.ts
index 5c38c3be9..2c8a34948 100644
--- a/packages/client-runtime/src/operations/commands.ts
+++ b/packages/client-runtime/src/operations/commands.ts
@@ -78,6 +78,12 @@ export type ReorderPinnedThreadInput = CommandInput<"thread.pin.reorder">;
export type UpdateThreadMetadataInput = CommandInput<"thread.meta.update">;
export type SetThreadRuntimeModeInput = CommandInput<"thread.runtime-mode.set">;
export type SetThreadInteractionModeInput = CommandInput<"thread.interaction-mode.set">;
+export type SetThreadMessageReactionInput = Omit<
+ CommandInput<"thread.message.reaction.set">,
+ "updatedAt"
+> & {
+ readonly updatedAt?: CommandOf<"thread.message.reaction.set">["updatedAt"];
+};
export type StartThreadTurnInput = CommandInput<"thread.turn.start">;
export type AppendVoiceTranscriptInput = CommandInput<"thread.voice-transcript.append">;
export type InterruptThreadTurnInput = CommandInput<"thread.turn.interrupt">;
@@ -660,6 +666,16 @@ export const setThreadInteractionMode: (input: SetThreadInteractionModeInput) =>
});
});
+export const setThreadMessageReaction: (input: SetThreadMessageReactionInput) => CommandEffect =
+ Effect.fn("EnvironmentCommands.setThreadMessageReaction")(function* (input) {
+ return yield* dispatch({
+ ...input,
+ type: "thread.message.reaction.set",
+ commandId: yield* commandId(input),
+ updatedAt: input.updatedAt ?? (yield* DateTime.now.pipe(Effect.map(DateTime.formatIso))),
+ });
+ });
+
export const startThreadTurn: (input: StartThreadTurnInput) => CommandEffect = Effect.fn(
"EnvironmentCommands.startThreadTurn",
)(function* (input) {
diff --git a/packages/client-runtime/src/state/threadCommands.ts b/packages/client-runtime/src/state/threadCommands.ts
index 27ee94053..c45e85169 100644
--- a/packages/client-runtime/src/state/threadCommands.ts
+++ b/packages/client-runtime/src/state/threadCommands.ts
@@ -17,6 +17,7 @@ import {
type RespondToThreadUserInputInput,
type RevertThreadCheckpointInput,
type SetThreadInteractionModeInput,
+ type SetThreadMessageReactionInput,
type SetThreadRuntimeModeInput,
type PinThreadInput,
type ReorderPinnedThreadInput,
@@ -38,6 +39,7 @@ import {
respondToThreadUserInput,
revertThreadCheckpoint,
setThreadInteractionMode,
+ setThreadMessageReaction,
setThreadRuntimeMode,
pinThread,
reorderPinnedThread,
@@ -62,6 +64,7 @@ export type {
RespondToThreadUserInputInput,
RevertThreadCheckpointInput,
SetThreadInteractionModeInput,
+ SetThreadMessageReactionInput,
SetThreadRuntimeModeInput,
PinThreadInput,
ReorderPinnedThreadInput,
@@ -170,6 +173,12 @@ export function createThreadEnvironmentAtoms<R, E>(
scheduler,
concurrency,
}),
+ setMessageReaction: createEnvironmentCommand(runtime, {
+ label: "environment-data:commands:thread:set-message-reaction",
+ execute: (input: SetThreadMessageReactionInput) => setThreadMessageReaction(input),
+ scheduler,
+ concurrency,
+ }),
startTurn: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:start-turn",
execute: (input: StartThreadTurnInput) => startThreadTurn(input),
diff --git a/packages/client-runtime/src/state/threadReducer.test.ts b/packages/client-runtime/src/state/threadReducer.test.ts
index f6cc2dbd7..bc28029a9 100644
--- a/packages/client-runtime/src/state/threadReducer.test.ts
+++ b/packages/client-runtime/src/state/threadReducer.test.ts
@@ -514,6 +514,49 @@ describe("applyThreadDetailEvent", () => {
});
});
+ describe("thread.message-reaction-set", () => {
+ it("projects person-authored reactions without a bot identity", () => {
+ const personId = AuthSessionId.make("person-1");
+ const messageId = MessageId.make("msg-reaction");
+ const threadWithMessage: OrchestrationThread = {
+ ...baseThread,
+ messages: [
+ {
+ id: messageId,
+ role: "assistant",
+ text: "Done.",
+ turnId: null,
+ streaming: false,
+ createdAt: "2026-04-01T07:00:00.000Z",
+ updatedAt: "2026-04-01T07:00:00.000Z",
+ },
+ ],
+ };
+
+ const result = applyThreadDetailEvent(threadWithMessage, {
+ ...baseEventFields,
+ sequence: 9,
+ occurredAt: "2026-04-01T07:01:00.000Z",
+ aggregateKind: "thread",
+ aggregateId: ThreadId.make("thread-1"),
+ type: "thread.message-reaction-set",
+ payload: {
+ threadId: ThreadId.make("thread-1"),
+ messageId,
+ personId,
+ emoji: "👍",
+ present: true,
+ updatedAt: "2026-04-01T07:01:00.000Z",
+ },
+ });
+
+ expect(result.kind).toBe("updated");
+ if (result.kind === "updated") {
+ expect(result.thread.messages[0]?.reactions).toEqual([{ personId, emoji: "👍" }]);
+ }
+ });
+ });
+
describe("thread.session-set", () => {
it("settles a running latestTurn when the session leaves the running status", () => {
const threadWithRunningTurn: OrchestrationThread = {
diff --git a/packages/client-runtime/src/state/threadReducer.ts b/packages/client-runtime/src/state/threadReducer.ts
index 840b9c067..59fd4bcd7 100644
--- a/packages/client-runtime/src/state/threadReducer.ts
+++ b/packages/client-runtime/src/state/threadReducer.ts
@@ -399,7 +399,9 @@ export function applyThreadDetailEvent(
if (!message) return { kind: "unchanged" };
const withoutReaction = (message.reactions ?? []).filter(
(reaction) =>
- reaction.botId !== event.payload.botId || reaction.emoji !== event.payload.emoji,
+ reaction.botId !== event.payload.botId ||
+ reaction.personId !== event.payload.personId ||
+ reaction.emoji !== event.payload.emoji,
);
return {
kind: "updated",
@@ -412,7 +414,12 @@ export function applyThreadDetailEvent(
reactions: event.payload.present
? [
...withoutReaction,
- { botId: event.payload.botId, emoji: event.payload.emoji },
+ {
+ ...(event.payload.botId !== undefined
+ ? { botId: event.payload.botId }
+ : { personId: event.payload.personId }),
+ emoji: event.payload.emoji,
+ },
]
: withoutReaction,
updatedAt: event.payload.updatedAt,
diff --git a/packages/contracts/src/assets.test.ts b/packages/contracts/src/assets.test.ts
index ce4214d30..ea99041c7 100644
--- a/packages/contracts/src/assets.test.ts
+++ b/packages/contracts/src/assets.test.ts
@@ -17,10 +17,21 @@ describe("AttachmentCreateUploadUrlInput", () => {
expect(isUploadInput(uploadInput)).toBe(true);
});
+ it("accepts supported document attachments", () => {
+ expect(isUploadInput({ name: "notes.md", mimeType: "text/markdown", sizeBytes: 3 })).toBe(true);
+ expect(isUploadInput({ name: "report.pdf", mimeType: "application/pdf", sizeBytes: 3 })).toBe(
+ true,
+ );
+ });
+
it("rejects image types that providers do not support", () => {
expect(isUploadInput({ ...uploadInput, mimeType: "image/svg+xml" })).toBe(false);
});
+ it("rejects active document content", () => {
+ expect(isUploadInput({ name: "page.html", mimeType: "text/html", sizeBytes: 3 })).toBe(false);
+ });
+
it("rejects empty and oversized uploads", () => {
expect(isUploadInput({ ...uploadInput, sizeBytes: 0 })).toBe(false);
expect(
diff --git a/packages/contracts/src/assets.ts b/packages/contracts/src/assets.ts
index bfc2c9472..37bc67f98 100644
--- a/packages/contracts/src/assets.ts
+++ b/packages/contracts/src/assets.ts
@@ -2,7 +2,9 @@ import * as Schema from "effect/Schema";
import { NonNegativeInt, ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
import {
+ PROVIDER_SEND_TURN_MAX_FILE_BYTES,
PROVIDER_SEND_TURN_MAX_IMAGE_BYTES,
+ PROVIDER_SEND_TURN_SUPPORTED_FILE_MIME_TYPES,
PROVIDER_SEND_TURN_SUPPORTED_IMAGE_MIME_TYPES,
ProjectFaviconPath,
} from "./orchestration.ts";
@@ -44,10 +46,15 @@ export const ATTACHMENT_UPLOAD_URL_TTL_MS = 10 * 60_000;
export const AttachmentCreateUploadUrlInput = Schema.Struct({
name: TrimmedNonEmptyString.check(Schema.isMaxLength(255)),
- mimeType: Schema.Literals(PROVIDER_SEND_TURN_SUPPORTED_IMAGE_MIME_TYPES),
+ mimeType: Schema.Literals([
+ ...PROVIDER_SEND_TURN_SUPPORTED_IMAGE_MIME_TYPES,
+ ...PROVIDER_SEND_TURN_SUPPORTED_FILE_MIME_TYPES,
+ ]),
sizeBytes: NonNegativeInt.check(
Schema.isGreaterThanOrEqualTo(1),
- Schema.isLessThanOrEqualTo(PROVIDER_SEND_TURN_MAX_IMAGE_BYTES),
+ Schema.isLessThanOrEqualTo(
+ Math.max(PROVIDER_SEND_TURN_MAX_IMAGE_BYTES, PROVIDER_SEND_TURN_MAX_FILE_BYTES),
+ ),
),
});
export type AttachmentCreateUploadUrlInput = typeof AttachmentCreateUploadUrlInput.Type;
diff --git a/packages/contracts/src/environment.ts b/packages/contracts/src/environment.ts
index 3d7546435..4c6b9058f 100644
--- a/packages/contracts/src/environment.ts
+++ b/packages/contracts/src/environment.ts
@@ -50,6 +50,8 @@ export const ExecutionEnvironmentCapabilities = Schema.Struct({
connectionProbe: Schema.optionalKey(Schema.Boolean),
/** Missing on older servers, which still accept inline image attachments. */
attachmentUploads: Schema.optionalKey(Schema.Boolean),
+ /** Missing on image-only servers. Clients must not send document attachment variants. */
+ fileAttachments: Schema.optionalKey(Schema.Boolean),
/** Server exposes the pull-request list, detail, activity, diff, and mutation APIs. Absent on
servers from before the pull-request workspace shipped, so clients must not probe them. */
pullRequests: Schema.optionalKey(Schema.Boolean),
diff --git a/packages/contracts/src/orchestration.ts b/packages/contracts/src/orchestration.ts
index c41eb4a89..ce9f5b1e6 100644
--- a/packages/contracts/src/orchestration.ts
+++ b/packages/contracts/src/orchestration.ts
@@ -188,6 +188,7 @@ export type ProviderUserInputAnswers = typeof ProviderUserInputAnswers.Type;
export const PROVIDER_SEND_TURN_MAX_INPUT_CHARS = 120_000;
export const PROVIDER_SEND_TURN_MAX_ATTACHMENTS = 8;
export const PROVIDER_SEND_TURN_MAX_IMAGE_BYTES = 10 * 1024 * 1024;
+export const PROVIDER_SEND_TURN_MAX_FILE_BYTES = 10 * 1024 * 1024;
export const PROVIDER_SEND_TURN_SUPPORTED_IMAGE_MIME_TYPES = [
"image/gif",
"image/jpeg",
@@ -202,7 +203,28 @@ const PROVIDER_SEND_TURN_SUPPORTED_IMAGE_MIME_TYPE_SET = new Set<string>(
export function isProviderSendTurnSupportedImageMimeType(mimeType: string): boolean {
return PROVIDER_SEND_TURN_SUPPORTED_IMAGE_MIME_TYPE_SET.has(mimeType.toLowerCase());
}
+export const PROVIDER_SEND_TURN_SUPPORTED_FILE_MIME_TYPES = [
+ "application/json",
+ "application/pdf",
+ "application/toml",
+ "application/xml",
+ "application/x-yaml",
+ "text/csv",
+ "text/markdown",
+ "text/plain",
+ "text/toml",
+ "text/xml",
+ "text/yaml",
+] as const;
+const PROVIDER_SEND_TURN_SUPPORTED_FILE_MIME_TYPE_SET = new Set<string>(
+ PROVIDER_SEND_TURN_SUPPORTED_FILE_MIME_TYPES,
+);
+
+export function isProviderSendTurnSupportedFileMimeType(mimeType: string): boolean {
+ return PROVIDER_SEND_TURN_SUPPORTED_FILE_MIME_TYPE_SET.has(mimeType.toLowerCase());
+}
const PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS = 14_000_000;
+const PROVIDER_SEND_TURN_MAX_FILE_DATA_URL_CHARS = 14_000_000;
const CHAT_ATTACHMENT_ID_MAX_CHARS = 128;
// Correlation id is command id by design in this model.
export const CorrelationId = CommandId;
@@ -234,9 +256,29 @@ const UploadChatImageAttachment = Schema.Struct({
});
export type UploadChatImageAttachment = typeof UploadChatImageAttachment.Type;
-export const ChatAttachment = Schema.Union([ChatImageAttachment]);
+export const ChatFileAttachment = Schema.Struct({
+ type: Schema.Literal("file"),
+ id: ChatAttachmentId,
+ name: TrimmedNonEmptyString.check(Schema.isMaxLength(255)),
+ mimeType: Schema.Literals(PROVIDER_SEND_TURN_SUPPORTED_FILE_MIME_TYPES),
+ sizeBytes: NonNegativeInt.check(Schema.isLessThanOrEqualTo(PROVIDER_SEND_TURN_MAX_FILE_BYTES)),
+});
+export type ChatFileAttachment = typeof ChatFileAttachment.Type;
+
+const UploadChatFileAttachment = Schema.Struct({
+ type: Schema.Literal("file"),
+ name: TrimmedNonEmptyString.check(Schema.isMaxLength(255)),
+ mimeType: Schema.Literals(PROVIDER_SEND_TURN_SUPPORTED_FILE_MIME_TYPES),
+ sizeBytes: NonNegativeInt.check(Schema.isLessThanOrEqualTo(PROVIDER_SEND_TURN_MAX_FILE_BYTES)),
+ dataUrl: TrimmedNonEmptyString.check(
+ Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_FILE_DATA_URL_CHARS),
+ ),
+});
+export type UploadChatFileAttachment = typeof UploadChatFileAttachment.Type;
+
+export const ChatAttachment = Schema.Union([ChatImageAttachment, ChatFileAttachment]);
export type ChatAttachment = typeof ChatAttachment.Type;
-const UploadChatAttachment = Schema.Union([UploadChatImageAttachment]);
+const UploadChatAttachment = Schema.Union([UploadChatImageAttachment, UploadChatFileAttachment]);
export type UploadChatAttachment = typeof UploadChatAttachment.Type;
export const ProjectScriptIcon = Schema.Literals([
@@ -453,7 +495,8 @@ export type OrchestrationMessageRole = typeof OrchestrationMessageRole.Type;
export const OrchestrationMessageReaction = Schema.Struct({
emoji: TrimmedNonEmptyString,
- botId: BotId,
+ botId: Schema.optional(BotId),
+ personId: Schema.optional(AuthSessionId),
});
export type OrchestrationMessageReaction = typeof OrchestrationMessageReaction.Type;
@@ -1580,6 +1623,17 @@ export const DelegationCancelCommand = Schema.Struct({
createdAt: IsoDateTime,
});
+const ThreadMessageReactionSetCommand = Schema.Struct({
+ type: Schema.Literal("thread.message.reaction.set"),
+ commandId: CommandId,
+ threadId: ThreadId,
+ messageId: MessageId,
+ botId: Schema.optional(BotId),
+ emoji: TrimmedNonEmptyString,
+ present: Schema.Boolean,
+ updatedAt: IsoDateTime,
+});
+
const DispatchableClientOrchestrationCommand = Schema.Union([
ProjectCreateCommand,
ProjectMetaUpdateCommand,
@@ -1623,6 +1677,7 @@ const DispatchableClientOrchestrationCommand = Schema.Union([
ThreadApprovalRespondCommand,
ThreadUserInputRespondCommand,
ThreadCheckpointRevertCommand,
+ ThreadMessageReactionSetCommand,
ThreadSessionStopCommand,
DelegationCancelCommand,
]);
@@ -1679,6 +1734,7 @@ export const ClientOrchestrationCommand = Schema.Union([
ThreadApprovalRespondCommand,
ThreadUserInputRespondCommand,
ThreadCheckpointRevertCommand,
+ ThreadMessageReactionSetCommand,
ThreadSessionStopCommand,
DelegationCancelCommand,
]);
@@ -1712,17 +1768,6 @@ const ThreadMessageAssistantCompleteCommand = Schema.Struct({
createdAt: IsoDateTime,
});
-const ThreadMessageReactionSetCommand = Schema.Struct({
- type: Schema.Literal("thread.message.reaction.set"),
- commandId: CommandId,
- threadId: ThreadId,
- messageId: MessageId,
- botId: BotId,
- emoji: TrimmedNonEmptyString,
- present: Schema.Boolean,
- updatedAt: IsoDateTime,
-});
-
const ThreadProposedPlanUpsertCommand = Schema.Struct({
type: Schema.Literal("thread.proposed-plan.upsert"),
commandId: CommandId,
@@ -1803,7 +1848,6 @@ const InternalOrchestrationCommand = Schema.Union([
ThreadSessionSetCommand,
ThreadMessageAssistantDeltaCommand,
ThreadMessageAssistantCompleteCommand,
- ThreadMessageReactionSetCommand,
ThreadProposedPlanUpsertCommand,
ThreadTurnDiffCompleteCommand,
ThreadActivityAppendCommand,
@@ -2198,7 +2242,8 @@ export const ThreadMessageSentPayload = Schema.Struct({
export const ThreadMessageReactionSetPayload = Schema.Struct({
threadId: ThreadId,
messageId: MessageId,
- botId: BotId,
+ botId: Schema.optional(BotId),
+ personId: Schema.optional(AuthSessionId),
emoji: TrimmedNonEmptyString,
present: Schema.Boolean,
updatedAt: IsoDateTime,