diff --git a/.agents/skills/verify-deepseekbot/features/remote-hosts.md b/.agents/skills/verify-deepseekbot/features/remote-hosts.md index 3a98726340..0dc94b6c47 100644 --- a/.agents/skills/verify-deepseekbot/features/remote-hosts.md +++ b/.agents/skills/verify-deepseekbot/features/remote-hosts.md @@ -10,6 +10,7 @@ The browser pairs a Remote Host as a Paired Device and reads its Host Feed throu - `avatars`: remote Bot portraits and group images/member stacks appear in rows and conversation headers; Bot message authors and live drafts use the same remote portrait. - `activity-unread`: remote Bot rows display received activity; DM/group unread counts come from their Host Inbox. - `read`: a visible remote conversation at its latest message marks that message read on its owning Host and refreshes the shared Inbox. +- `message-body`: remote images, files, rich text and request cards use the existing message body, with authenticated resources and decisions on the source Host. - `upgrade`: existing browser pairings and the selected tab survive the storage-key rename. - `remove`: removing a Host forgets its rows, stops its Inbox and releases cached avatar object URLs. - `viewers`: a remote Bot DM opens Browser or Computer when that Bot has access. The shared Host viewer modules read frames and send input to that Host only; closing, switching source or losing the connection tears down the viewer and releases requested control. @@ -38,13 +39,15 @@ For Remote settings, use two disposable Hosts with different home basenames and The default-model proof must change the model value on a Profile whose native settings owner can save it; a same-value no-op is insufficient. Keep a page's observed revision, change the default from another client, and verify the old page refuses without overwriting it. Explicit refresh must permit a subsequent save. Omit the catalog revision at the test transport boundary to verify the shared client refuses before any write; label that case as fault injection. For existing presets, verify Enter plus blur increments the revision once, a later blur saves independently, composition Enter does not submit, and a delayed write remains on its original Host/preset after closing and switching Hosts. Preserve the draft/error on a rejected save. New presets retain an explicit create action. Reject a remote storage preview token on the other Host, and verify neither cleanup command proceeds without its confirmation flag. +For message bodies, upload an image and a text file to Host B through its attachment API and send them in a disposable Channel. Open that Channel from Host A: the image may load immediately, but files and audio must not fetch until Download or Play is selected. Repeated pending clicks must share one request; downloading audio must not start playback. Verify that GET requests use Host B's device gateway. Switch source or close during a delayed response and verify that it cannot trigger a download or playback afterward. Refuse or remove source access and confirm the conversation retains its title and usable Close control without a timeline, composer or viewer. Request a real tool approval with `deepseek-v4-pro`, decide its card from Host A, and compare Host B's decision record with the unchanged Host A history. Capture the same conversation in light and dark before and after the renderer change. Switch between Hosts and Channels to verify draft/card isolation and media cleanup. A revoked device must never load an attachment through Host A instead. + ## Gotchas - The workspace hides `data-panel-empty-action` descendants. Viewer reconnect must stay in its own controls; verify the button is visible and clickable inside the real workspace, not only in a standalone panel render. - Remote avatars consume the authenticated image cache; This Host retains its current read adapter. - With unread messages on both Hosts, compare each row and tab with `channelUnreadCounts`. Open the remote DM/group, verify its count clears on that Host while the other Host stays unread. Keep an active Bot running to inspect its activity indicator. Stop only the task-owned remote Host and verify cached rows/counts remain with an offline tab. - Activity timestamps are receipt times; they are not authoritative tool start times. -- Remote chat displays text and attachment names; images and cards are not qualified. -- Host looks remain device-local, including each phone's own icon and colour. DSH Desktop and two physical machines over a real tailnet are not qualified by a two-Host local run. +- The remote message renderer replaces the earlier text-and-attachment-names-only view. Qualify images and cards through the two-Host path above; test results remain separate from Human acceptance. +- Host looks are device-local by design. DSH Desktop and two physical machines over a real tailnet are not qualified by a two-Host local run; native phone qualification is separate. - Control release uses the same device credential. An unreachable Host is retried when this viewer reconnects or reopens; a revoked credential cannot resume a Browser. In that case the Host operator resumes it. The Computer also has its existing Host-side pause lease. - Dismiss Continue and Skip onboarding overlays before selecting Messages. Retain any failed drive evidence before retrying. diff --git a/.github/pr-screenshots/2500-t5/after-card-dark.png b/.github/pr-screenshots/2500-t5/after-card-dark.png new file mode 100644 index 0000000000..9522313766 Binary files /dev/null and b/.github/pr-screenshots/2500-t5/after-card-dark.png differ diff --git a/.github/pr-screenshots/2500-t5/after-card-light.png b/.github/pr-screenshots/2500-t5/after-card-light.png new file mode 100644 index 0000000000..2ee89cd0a1 Binary files /dev/null and b/.github/pr-screenshots/2500-t5/after-card-light.png differ diff --git a/.github/pr-screenshots/2500-t5/after-dark.png b/.github/pr-screenshots/2500-t5/after-dark.png new file mode 100644 index 0000000000..5e729817d9 Binary files /dev/null and b/.github/pr-screenshots/2500-t5/after-dark.png differ diff --git a/.github/pr-screenshots/2500-t5/after-light.png b/.github/pr-screenshots/2500-t5/after-light.png new file mode 100644 index 0000000000..c459ac3c29 Binary files /dev/null and b/.github/pr-screenshots/2500-t5/after-light.png differ diff --git a/.github/pr-screenshots/2500-t5/before-card-dark.png b/.github/pr-screenshots/2500-t5/before-card-dark.png new file mode 100644 index 0000000000..c8ad2d664c Binary files /dev/null and b/.github/pr-screenshots/2500-t5/before-card-dark.png differ diff --git a/.github/pr-screenshots/2500-t5/before-card-light.png b/.github/pr-screenshots/2500-t5/before-card-light.png new file mode 100644 index 0000000000..79abdd85e7 Binary files /dev/null and b/.github/pr-screenshots/2500-t5/before-card-light.png differ diff --git a/.github/pr-screenshots/2500-t5/before-dark.png b/.github/pr-screenshots/2500-t5/before-dark.png new file mode 100644 index 0000000000..0afd2b748e Binary files /dev/null and b/.github/pr-screenshots/2500-t5/before-dark.png differ diff --git a/.github/pr-screenshots/2500-t5/before-light.png b/.github/pr-screenshots/2500-t5/before-light.png new file mode 100644 index 0000000000..a52eec1099 Binary files /dev/null and b/.github/pr-screenshots/2500-t5/before-light.png differ diff --git a/apps/mobile/src/host/attention-actions.ts b/apps/mobile/src/host/attention-actions.ts index 61b4c3cd18..9653aab30c 100644 --- a/apps/mobile/src/host/attention-actions.ts +++ b/apps/mobile/src/host/attention-actions.ts @@ -2,6 +2,7 @@ import { HostAnswerInvalid } from './bot-settings'; import type { HostClient } from './client'; import { uuid } from './conversation'; import type { HumanAssignmentContext, HumanAttentionItem, HumanAttentionPage } from './wire'; +export { decideApproval, answerQuestion, decideGrantRequest } from './requests'; export interface AttentionRef { id: string; diff --git a/apps/mobile/src/host/conversation.ts b/apps/mobile/src/host/conversation.ts index f784c6cf74..be87bbef9f 100644 --- a/apps/mobile/src/host/conversation.ts +++ b/apps/mobile/src/host/conversation.ts @@ -112,6 +112,8 @@ export function shownInChat(message: ConversationMessage): boolean { return false; if (message.welcome === true) return false; return ( + message.source?.message.contentPurge !== undefined || + message.source?.message.sessionFailure !== undefined || message.activity !== undefined || message.body.trim() !== '' || message.attachments.length > 0 || @@ -121,6 +123,7 @@ export function shownInChat(message: ConversationMessage): boolean { } export interface ConversationMessage { + source?: JournalEntry; id: string; revision?: number; at: string; @@ -418,6 +421,7 @@ function present( const activity = activityOf(message); return { id: message.id, + source: entry, revision: entry.revision, at: message.at, author: kind === 'human' ? 'human' : kind === 'bot' ? 'bot' : 'system', diff --git a/apps/mobile/src/host/message-display.ts b/apps/mobile/src/host/message-display.ts index 7894766941..6d3dfd88d5 100644 --- a/apps/mobile/src/host/message-display.ts +++ b/apps/mobile/src/host/message-display.ts @@ -1,3 +1,20 @@ +import type { ConversationMessage } from './conversation'; +import type { ChannelWireMessage } from './wire'; + +export function messageForDisplay(message: ConversationMessage): ChannelWireMessage { + return ( + message.source?.message ?? { + id: message.id, + at: message.at, + body: message.body, + author: + message.author === 'bot' + ? { kind: 'bot', slug: message.bot ?? '' } + : { kind: message.author }, + } + ); +} + export type MessageDisplayMode = 'streaming' | 'complete'; export function createMessageDisplayPreferences(storage: { diff --git a/apps/mobile/src/host/requests.ts b/apps/mobile/src/host/requests.ts index 777da6c1a7..5d3ca2dfff 100644 --- a/apps/mobile/src/host/requests.ts +++ b/apps/mobile/src/host/requests.ts @@ -52,7 +52,7 @@ export interface QuestionRequest extends RequestRef { export type DecisionResult = 'accepted' | 'decided' | 'expired'; -export type ApprovalChoice = 'allowed-once' | 'allowed-always-tool' | 'rejected'; +export type ApprovalChoice = ToolApprovalOutcome; export function requestRef(item: HumanAttentionItem): RequestRef | undefined { if (item.channelId === undefined || item.messageId === undefined) return undefined; diff --git a/apps/mobile/src/host/wire.ts b/apps/mobile/src/host/wire.ts index cfab6048d8..7137474536 100644 --- a/apps/mobile/src/host/wire.ts +++ b/apps/mobile/src/host/wire.ts @@ -40,6 +40,7 @@ export interface WireAllBotMention { } export interface ChannelWireMessage extends WireMessage { + contentPurge?: unknown; author: WireAuthor; mentions?: WireMention[]; reactions?: WireReaction[]; diff --git a/apps/mobile/test/conversation.test.ts b/apps/mobile/test/conversation.test.ts index 093836c94e..84a0748340 100644 --- a/apps/mobile/test/conversation.test.ts +++ b/apps/mobile/test/conversation.test.ts @@ -10,6 +10,7 @@ import { type ConversationSnapshot, } from '../src/host/conversation'; import { createConversationPlayback } from '../src/host/conversation-playback'; +import { messageForDisplay } from '../src/host/message-display'; import { FakeHost, type FakeChannel } from './fake-host'; import wire from './fixtures/host-wire.json'; import type { ChannelMessage } from '../../../packages/core/src/channels/channel'; @@ -89,6 +90,47 @@ function contiguous(snapshot: ConversationSnapshot): boolean { } describe('DM conversation', () => { + it('retains the source Channel and rich payload through the shared display projection', async () => { + const host = new FakeHost(); + const channel = host.channel(DM); + channel.append( + { + id: 'rich-message', + author: { kind: 'bot', slug: SLUG }, + body: 'Image and approval', + format: 'text', + attachments: [ + { + fileId: 'file:11111111-1111-4111-8111-111111111111', + name: 'photo.png', + mime: 'image/png', + size: 12, + }, + ], + toolApprovalRequest: { + sessionId: 'session', + callId: 'call', + toolName: 'bash', + role: 'orchestrator', + cwd: '/source', + input: '{"command":"pwd"}', + }, + }, + false, + ); + const live = await until(open(host), (snapshot) => snapshot.status === 'live'); + const message = live.messages.find((entry) => entry.id === 'rich-message')!; + expect(message.source?.channelId).toBe(DM); + expect(messageForDisplay(message)).toMatchObject({ + format: 'text', + toolApprovalRequest: { callId: 'call' }, + attachments: [{ fileId: 'file:11111111-1111-4111-8111-111111111111' }], + }); + expect(message.attachments[0]?.source?.uri).toContain( + `${ROUTE}/botharness-device/api/botharness/attachment?`, + ); + }); + it('shows paged committed history immediately while playback is held away from latest', async () => { const host = new FakeHost(); seed(host.channel(DM), 25); diff --git a/changes/2500-remote-message-body.md b/changes/2500-remote-message-body.md new file mode 100644 index 0000000000..b3062823aa --- /dev/null +++ b/changes/2500-remote-message-body.md @@ -0,0 +1,15 @@ +--- +section: Added +--- + +## en + +- Remote Host conversations show message images, files and request cards using the same message body as This Host; attachments and decisions go directly to the source Host with this browser's device credential ([#2500](https://github.com/BotHarness/DeepSeekBot/issues/2500)). +- Remote folder requests show localized retry guidance when browsing or authorization fails, while retaining the source Host's error for diagnostics ([#2500](https://github.com/BotHarness/DeepSeekBot/issues/2500)). +- Remote file downloads and audio playback load only after an explicit action; unavailable remote conversations retain their title and Close control, and images reopened offline offer Retry ([#2500](https://github.com/BotHarness/DeepSeekBot/issues/2500)). + +## zh + +- 远程会话复用本机的消息正文,显示图片、文件和请求卡片;附件读取与处理请求使用此浏览器的设备凭据,直接发往消息所属的 Host([#2500](https://github.com/BotHarness/DeepSeekBot/issues/2500))。 +- 远程文件夹请求在浏览或授权失败时显示本地化重试提示,同时保留来源 Host 的原始错误供诊断([#2500](https://github.com/BotHarness/DeepSeekBot/issues/2500))。 +- 远程文件下载与音频播放仅在操作后加载;远程会话不可用时仍保留标题和关闭入口,离线重开的图片显示重试操作([#2500](https://github.com/BotHarness/DeepSeekBot/issues/2500))。 diff --git a/docs/architecture/botharness-architecture.md b/docs/architecture/botharness-architecture.md index d7da660bd0..dc67458e48 100644 --- a/docs/architecture/botharness-architecture.md +++ b/docs/architecture/botharness-architecture.md @@ -1140,6 +1140,8 @@ Remote Bot Browser and Computer viewers reuse `apps/mobile/src/host/browser-view The application-defined browser `RemoteHosts` owner keeps its pairings and selected Host tab in device-local storage. Each Remote Host reuses the phone's Host client and conversation module through the device gateway; This Host never relays the Remote Host's credential. The shared `createInbox(client, { activity: true })` supplies each Remote Host's Human Inbox and unread snapshot. The first browser subscriber starts the client and Inbox, and the last stops them while retaining the last Inbox snapshot. Authenticated avatar fetches publish an immutable URL-to-object-URL map; removal, roster replacement and final unsubscribe release obsolete objects and discard late fetch results. The storage-key rename imports existing browser pairings and the selected tab. See [ADR-0242](../adr/0242-a-browser-pairs-other-computers-through-their-device-gateway.md) and [ADR-0243](../adr/0243-every-client-reads-every-host-through-one-host-feed.md). +Remote conversation presentation retains the source Channel Journal entry through the shared conversation and message-display modules, then uses the existing Web message body and request cards. A conversation-scoped adapter supplies the source Host client and validates the active Host/Channel before decisions. Attachment reads resolve through that client's `resource(path)` and device credential, with no local-store or local-URL fallback; changing conversations aborts reads and releases object URLs. Activity and conversation cards share `createHostRequestActions`, with request references from the Inbox and Journal respectively. Only a Host-accepted decision completes a submission; stale decisions trigger the existing cards' status reload. Decisions reuse the shared attention actions and remain subject to the source Host's ownership and permission checks. + Activity Center consumes each Remote Host's shared Inbox through `RemoteHosts.activity`, reusing the existing `HumanInboxView` for Host groups. Its Host-scoped source supplies identity, pagination, source navigation and commands; it never receives This Host's `BridgeActions`. `createHostActivityActions` adapts the shared attention and request operations to the existing approval and question cards. Each operation resolves the current pairing before calling its Host client, and confirmed changes refresh that Host's Inbox. Filtered observers share the Host client and stop with their last subscriber. This Host still reads its existing bridge/store until that Host Feed slice migrates. Device Notification Preference remains a subsequent device-owned slice; the browser has no closed-page notification path. Remote Host settings resolve the selected Host's existing client from `RemoteHosts`. The browser reuses `apps/mobile/src/host/model-settings`, `usage` and `storage` for default models, presets, usage/Memory activity and cleanup; the existing Web settings, model picker, charts and destructive confirmation controls present those operations. Settings unmount their content when the source is disconnected or removed. Model resources are keyed by client and scope; there is no This Host fallback, Bot-profile link or automatic write replay. Cleanup retains the owning Host's preview token, scope and explicit confirmation. Host looks remain device-local and independent of these Host-owned settings. diff --git a/packages/client/src/client/bridge-audio-resource.ts b/packages/client/src/client/bridge-audio-resource.ts index fbe1f9c2d6..e485910ba7 100644 --- a/packages/client/src/client/bridge-audio-resource.ts +++ b/packages/client/src/client/bridge-audio-resource.ts @@ -1,3 +1,4 @@ +import { fetchMessageResource, type MessageHost } from './message-host.js'; import { subscribeMessagingDefaults } from './messaging-defaults-live.js'; interface AudioState { @@ -11,6 +12,7 @@ export function createBridgeAudioResource( channelId: string, sourceEventId: string, attachmentId: string, + host?: MessageHost, ) { let state = EMPTY; let controller: AbortController | undefined; @@ -34,15 +36,16 @@ export function createBridgeAudioResource( const signal = AbortSignal.any([request.signal, AbortSignal.timeout(30000)]); update({ loading: true }); try { - const response = await fetch( - './api/botharness/attachment?' + + const response = await fetchMessageResource( + '/api/botharness/attachment?' + new URLSearchParams({ channelId, sourceEventId, attachmentId, representation: 'playback', }), - { signal }, + signal, + host, ); signal.throwIfAborted(); if (!response.ok || response.headers.get('content-type')?.split(';', 1)[0] !== 'audio/wav') { @@ -96,7 +99,8 @@ export function createBridgeAudioResource( getSnapshot: () => state, subscribe(listener: () => void) { listeners.add(listener); - if (listeners.size === 1) stopLive = subscribeMessagingDefaults(reset); + if (listeners.size === 1) + stopLive = host === undefined ? subscribeMessagingDefaults(reset) : undefined; return () => { listeners.delete(listener); if (!listeners.size) { diff --git a/packages/client/src/client/bridge-audio.tsx b/packages/client/src/client/bridge-audio.tsx index 59d438729d..e98f7c2627 100644 --- a/packages/client/src/client/bridge-audio.tsx +++ b/packages/client/src/client/bridge-audio.tsx @@ -1,7 +1,9 @@ +import { useMessageHost } from './message-host.js'; import { useMemo, useSyncExternalStore, type ReactElement } from 'react'; import { Button } from '@deepseek-ai/dsh-client-ui-primitives'; import { MessageAudio } from './message-audio.js'; import { createBridgeAudioResource } from './bridge-audio-resource.js'; +import { createBridgeFileResource } from './bridge-file-resource.js'; import type { BotHarnessTranslate } from './locale.js'; export function BridgeAudio({ @@ -19,15 +21,29 @@ export function BridgeAudio({ sizeBytes?: number | undefined; t: BotHarnessTranslate; }): ReactElement { + const host = useMessageHost(); const resource = useMemo( - () => createBridgeAudioResource(channelId, sourceEventId, attachmentId), - [channelId, sourceEventId, attachmentId], + () => createBridgeAudioResource(channelId, sourceEventId, attachmentId, host), + [channelId, sourceEventId, attachmentId, host], ); const state = useSyncExternalStore( resource.subscribe, resource.getSnapshot, resource.getSnapshot, ); + const download = useMemo( + () => createBridgeFileResource(channelId, sourceEventId, attachmentId, host), + [channelId, sourceEventId, attachmentId, host], + ); + const subscribeDownload = useMemo( + () => (host === undefined ? () => () => {} : download.subscribe), + [host, download], + ); + const downloadState = useSyncExternalStore( + subscribeDownload, + download.getSnapshot, + download.getSnapshot, + ); const failures = { unavailable: 'im.voiceAudioUnavailable', format: 'im.voiceAudioFormat', @@ -43,10 +59,13 @@ export function BridgeAudio({ size={sizeBytes} url={state.url} downloadUrl={ - './api/botharness/attachment?' + - new URLSearchParams({ channelId, sourceEventId, attachmentId }) + host === undefined + ? './api/botharness/attachment?' + + new URLSearchParams({ channelId, sourceEventId, attachmentId }) + : state.url } onError={resource.fail} + onDownload={host === undefined ? undefined : () => void download.download(name)} t={t} /> {state.url ? null : ( @@ -64,6 +83,7 @@ export function BridgeAudio({ )}

{t('im.voiceAudioHint')}

{state.failure ?

{t(failures[state.failure])}

: null} + {downloadState.failure ?

{t('bridgeFile.failed')}

: null} ); } diff --git a/packages/client/src/client/bridge-file-resource.ts b/packages/client/src/client/bridge-file-resource.ts index 0bea26cd32..85517e64fc 100644 --- a/packages/client/src/client/bridge-file-resource.ts +++ b/packages/client/src/client/bridge-file-resource.ts @@ -1,3 +1,4 @@ +import { fetchMessageResource, type MessageHost } from './message-host.js'; import { subscribeMessagingDefaults } from './messaging-defaults-live.js'; import { boundedBridgeMediaRequest } from './bridge-media-request.js'; @@ -12,6 +13,7 @@ export function createBridgeFileResource( channelId: string, sourceEventId: string, attachmentId: string, + host?: MessageHost, ) { let state = EMPTY; let controller: AbortController | undefined; @@ -38,10 +40,11 @@ export function createBridgeFileResource( update({ loading: true }); try { await boundedBridgeMediaRequest(signal, async () => { - const response = await fetch( - './api/botharness/attachment?' + + const response = await fetchMessageResource( + '/api/botharness/attachment?' + new URLSearchParams({ channelId, sourceEventId, attachmentId }), - { signal }, + signal, + host, ); signal.throwIfAborted(); if (!response.ok) { @@ -109,7 +112,8 @@ export function createBridgeFileResource( getSnapshot: () => state, subscribe(listener: () => void) { listeners.add(listener); - if (listeners.size === 1) stopLive = subscribeMessagingDefaults(reset); + if (listeners.size === 1) + stopLive = host === undefined ? subscribeMessagingDefaults(reset) : undefined; return () => { listeners.delete(listener); if (!listeners.size) { diff --git a/packages/client/src/client/bridge-file.tsx b/packages/client/src/client/bridge-file.tsx index 0e9f05d126..9626281a64 100644 --- a/packages/client/src/client/bridge-file.tsx +++ b/packages/client/src/client/bridge-file.tsx @@ -1,3 +1,4 @@ +import { useMessageHost } from './message-host.js'; import { useMemo, useState, useSyncExternalStore, type ReactElement } from 'react'; import { FileTypeIcon, IconFolderOpenOutlineRegular } from '@deepseek-ai/dsh-client-ui-primitives'; import type { BotHarnessTranslate } from './locale.js'; @@ -23,9 +24,10 @@ export function BridgeFile({ actions?: Pick | undefined; t: BotHarnessTranslate; }): ReactElement { + const host = useMessageHost(); const resource = useMemo( - () => createBridgeFileResource(channelId, sourceEventId, attachmentId), - [channelId, sourceEventId, attachmentId], + () => createBridgeFileResource(channelId, sourceEventId, attachmentId, host), + [channelId, sourceEventId, attachmentId, host], ); const state = useSyncExternalStore( resource.subscribe, diff --git a/packages/client/src/client/bridge-image-resource.ts b/packages/client/src/client/bridge-image-resource.ts index a42302f4ea..232b244b95 100644 --- a/packages/client/src/client/bridge-image-resource.ts +++ b/packages/client/src/client/bridge-image-resource.ts @@ -1,3 +1,4 @@ +import { fetchMessageResource, type MessageHost } from './message-host.js'; import { subscribeMessagingDefaults } from './messaging-defaults-live.js'; import { boundedBridgeMediaRequest } from './bridge-media-request.js'; @@ -12,6 +13,7 @@ export function createBridgeImageResource( channelId: string, sourceEventId: string, attachmentId: string, + host?: MessageHost, ) { let state = EMPTY; let element: HTMLDivElement | null = null; @@ -39,10 +41,11 @@ export function createBridgeImageResource( if (!request.signal.aborted) update({ failure: value }); }; void boundedBridgeMediaRequest(request.signal, async () => { - const response = await fetch( - './api/botharness/attachment?' + + const response = await fetchMessageResource( + '/api/botharness/attachment?' + new URLSearchParams({ channelId, sourceEventId, attachmentId }), - { signal: request.signal }, + request.signal, + host, ); request.signal.throwIfAborted(); if (!response.ok) { @@ -120,7 +123,7 @@ export function createBridgeImageResource( subscribe(listener: () => void) { listeners.add(listener); if (listeners.size === 1) { - stopLive = subscribeMessagingDefaults(reload); + stopLive = host === undefined ? subscribeMessagingDefaults(reload) : undefined; observe(); } return () => { diff --git a/packages/client/src/client/bridge-image.tsx b/packages/client/src/client/bridge-image.tsx index 175cd6e072..c06565995e 100644 --- a/packages/client/src/client/bridge-image.tsx +++ b/packages/client/src/client/bridge-image.tsx @@ -1,3 +1,4 @@ +import { useMessageHost } from './message-host.js'; import { useMemo, useState, useSyncExternalStore, type ReactElement } from 'react'; import { Modal } from './modal.js'; import { createBridgeImageResource } from './bridge-image-resource.js'; @@ -16,9 +17,10 @@ export function BridgeImage({ name: string; t: BotHarnessTranslate; }): ReactElement { + const host = useMessageHost(); const resource = useMemo( - () => createBridgeImageResource(channelId, sourceEventId, attachmentId), - [channelId, sourceEventId, attachmentId], + () => createBridgeImageResource(channelId, sourceEventId, attachmentId, host), + [channelId, sourceEventId, attachmentId, host], ); const state = useSyncExternalStore( resource.subscribe, diff --git a/packages/client/src/client/channel-message-body.tsx b/packages/client/src/client/channel-message-body.tsx index a35668a304..3920c6b245 100644 --- a/packages/client/src/client/channel-message-body.tsx +++ b/packages/client/src/client/channel-message-body.tsx @@ -1,3 +1,4 @@ +import { useMessageHost } from './message-host.js'; import { BridgeAudio } from './bridge-audio.js'; import { BridgeFile } from './bridge-file.js'; import { UserQuestionCard } from './user-question-card.js'; @@ -7,7 +8,7 @@ import { OnboardingWelcome } from './onboarding-view.js'; import { BridgeImage } from './bridge-image.js'; import { ExternalMessageText } from './external-message-text.js'; import { ClearedMessageAttachment, MessageAttachment } from './message-attachment.js'; -import { useMemo, useRef, useState, type ReactElement } from 'react'; +import { useMemo, useRef, useState, type ReactElement, type ReactNode } from 'react'; import { Button, @@ -28,8 +29,8 @@ import type { ChannelHumanMember } from './store.js'; import { referenceRuns } from './channel-refs.js'; import { preserveHumanLineBreaks, rendersHumanMarkdown } from './human-markdown.js'; import { attachmentReferenceRuns, messageAttachmentReferences } from './attachment-refs.js'; -import type { BridgeActions, HostDirectoryListing } from './actions.js'; -import { FolderBrowser } from './workspace-grants-entry.js'; +import type { BridgeActions } from './actions.js'; +import { FolderBrowser, type FolderBrowserActions } from './workspace-grants-entry.js'; import type { BotHarnessTranslate } from './locale.js'; import { toolApprovalText } from './approval-text.js'; import { useFooterPreferences } from './composer-footer-preferences.js'; @@ -85,13 +86,14 @@ function SessionFailureNotice({ t: BotHarnessTranslate; nativeChatT?: NativeChatFailureText | undefined; }): ReactElement { + const host = useMessageHost(); const failure = message.sessionFailure!; const [busy, setBusy] = useState(false); const [error, setError] = useState(); const title = nativeChatT?.('message.turnError') ?? t('failure.title'); - const needsModels = ['AUTH', 'MISSING_CREDENTIAL', 'INVALID_CREDENTIAL', 'QUOTA'].includes( - failure.code ?? '', - ); + const needsModels = + host === undefined && + ['AUTH', 'MISSING_CREDENTIAL', 'INVALID_CREDENTIAL', 'QUOTA'].includes(failure.code ?? ''); return (
@@ -167,7 +169,8 @@ export function GrantRequestCard({ t, }: { message: ChannelMessage; - actions: BridgeActions; + actions: Pick & + FolderBrowserActions; channelId?: string | undefined; workspacePickerRequest?: number | undefined; resolved: boolean; @@ -175,7 +178,8 @@ export function GrantRequestCard({ beforeOpen?: () => Promise; t: BotHarnessTranslate; }): ReactElement { - const [listing, setListing] = useState(); + const [listing, setListing] = + useState>>(); const [busy, setBusy] = useState(false); const [opening, setOpening] = useState(false); const [completed, setCompleted] = useState(false); @@ -321,6 +325,7 @@ function leadingBotMentions(message: ChannelMessage): export function ChannelMessageBody({ message: storedMessage, + requestCard, channelId, t, actions, @@ -333,6 +338,7 @@ export function ChannelMessageBody({ nativeChatT, }: { message: ChannelMessage; + requestCard?: ReactNode; channelId?: string | undefined; t: BotHarnessTranslate; actions?: BridgeActions; @@ -360,6 +366,7 @@ export function ChannelMessageBody({ }), [t], ); + const host = useMessageHost(); const approvalBody = toolApprovalText(storedMessage, t); const message = approvalBody === undefined ? storedMessage : { ...storedMessage, body: approvalBody }; @@ -369,6 +376,7 @@ export function ChannelMessageBody({ const format = message.format ?? (message.author.kind === 'human' && !humanMarkdown ? 'text' : 'markdown'); if (message.contentPurged) return
{t('purge.purged')}
; + if (requestCard !== undefined) return <>{requestCard}; if (message.onboardingWelcome?.kind === 'tob') return (
@@ -523,6 +531,12 @@ export function ChannelMessageBody({ @{label} ); + if (host !== undefined) + return ( + + @{label} + + ); const bot = bots.find((candidate) => candidate.slug === mention.botSlug); const badge = ( <> diff --git a/packages/client/src/client/host-activity-actions.ts b/packages/client/src/client/host-activity-actions.ts index b18f0b9c04..d24e3e2fc5 100644 --- a/packages/client/src/client/host-activity-actions.ts +++ b/packages/client/src/client/host-activity-actions.ts @@ -1,13 +1,13 @@ import { allowAutoRejectionOnce, + answerQuestion, + decideApproval, clearAttentionItem, decideJoinRequest, snoozeAttentionItem, } from '../../../../apps/mobile/src/host/attention-actions.js'; import type { HostClient } from '../../../../apps/mobile/src/host/client.js'; import { - answerQuestion, - decideApproval, loadApproval, loadQuestion, type DecisionResult, @@ -37,6 +37,58 @@ export interface HostActivityActions extends HumanInboxCommands, HostRequestActi message(item: HumanAttentionItem, signal?: AbortSignal): Promise; } +export function createHostRequestActions(options: { + client(): HostClient; + ref(channelId: string, messageId: string, retained?: boolean): RequestRef; + refresh?(): Promise; + requestUnavailable: string; +}): HostRequestActions { + const request = async (run: () => Promise): Promise => { + try { + return await run(); + } catch (cause) { + throw new Error(options.requestUnavailable, { cause }); + } + }; + const decided = async (run: () => Promise): Promise => { + const result = await request(run); + await options.refresh?.(); + if (result !== 'accepted') throw new Error(options.requestUnavailable); + }; + const approval = (channelId: string, messageId: string) => + request(() => loadApproval(options.client(), options.ref(channelId, messageId))); + return { + async toolApprovalStatus(channelId, messageId) { + return (await approval(channelId, messageId)).status === 'pending' ? 'pending' : 'expired'; + }, + async toolApprovalState(channelId, messageId) { + const value = await approval(channelId, messageId); + return { + status: value.status === 'pending' ? 'pending' : 'expired', + ...(value.expiresAt === undefined ? {} : { expiresAt: value.expiresAt }), + }; + }, + async toolApprovalExecutionState(channelId, messageId) { + return (await approval(channelId, messageId)).execution; + }, + async decideToolApproval(channelId, messageId, outcome) { + await decided(() => + decideApproval(options.client(), options.ref(channelId, messageId, false), outcome), + ); + }, + async userQuestionStatus(channelId, messageId) { + const value = await request(() => + loadQuestion(options.client(), options.ref(channelId, messageId)), + ); + return value.status === 'decided' ? 'answered' : value.status; + }, + answerUserQuestion: (channelId, messageId, answers) => + decided(() => + answerQuestion(options.client(), options.ref(channelId, messageId, false), { answers }), + ), + }; +} + export function createHostActivityActions(options: { client(): HostClient; items(): readonly HumanAttentionItem[]; @@ -65,21 +117,9 @@ export function createHostActivityActions(options: { await run(); await options.refresh(); }; - const request = async (run: () => Promise): Promise => { - try { - return await run(); - } catch (cause) { - throw new Error(options.requestUnavailable, { cause }); - } - }; - const decided = async (run: () => Promise): Promise => { - const result = await request(run); - await options.refresh(); - if (result !== 'accepted') throw new Error(options.requestUnavailable); - }; - const approval = (channelId: string, messageId: string) => - request(() => loadApproval(options.client(), ref(channelId, messageId))); + const requests = createHostRequestActions({ ...options, ref }); return { + ...requests, refreshHumanInbox: options.refresh, openChannelAtMessage: (channelId) => options.open(channelId), async decideGroupJoin(channelId, requestId, accept) { @@ -111,33 +151,10 @@ export function createHostActivityActions(options: { throw new Error('Activity request author changed'); return message; }, - async toolApprovalStatus(channelId, messageId) { - return (await approval(channelId, messageId)).status === 'pending' ? 'pending' : 'expired'; - }, - async toolApprovalState(channelId, messageId) { - const value = await approval(channelId, messageId); - return { - status: value.status === 'pending' ? 'pending' : 'expired', - ...(value.expiresAt === undefined ? {} : { expiresAt: value.expiresAt }), - }; - }, - async toolApprovalExecutionState(channelId, messageId) { - return (await approval(channelId, messageId)).execution; - }, async decideToolApproval(channelId, messageId, outcome) { if (outcome === 'allowed-always-exact' || outcome === 'allowed-always-all') throw new Error('This approval choice is unavailable'); - await decided(() => - decideApproval(options.client(), ref(channelId, messageId, false), outcome), - ); - }, - async userQuestionStatus(channelId, messageId) { - const value = await request(() => loadQuestion(options.client(), ref(channelId, messageId))); - return value.status === 'decided' ? 'answered' : value.status; + await requests.decideToolApproval(channelId, messageId, outcome); }, - answerUserQuestion: (channelId, messageId, answers) => - decided(() => - answerQuestion(options.client(), ref(channelId, messageId, false), { answers }), - ), }; } diff --git a/packages/client/src/client/message-attachment.tsx b/packages/client/src/client/message-attachment.tsx index 78c2c1a451..e0be4ecca9 100644 --- a/packages/client/src/client/message-attachment.tsx +++ b/packages/client/src/client/message-attachment.tsx @@ -1,5 +1,6 @@ import { useMemo, type ReactElement, type ReactNode } from 'react'; import { + Button, FileTypeIcon, IconDownloadOutlineRegular, IconEllipsisOutlineRegular, @@ -13,6 +14,8 @@ import type { BotHarnessTranslate } from './locale.js'; import type { ChannelAttachmentRef } from './store.js'; import { MessageAudio } from './message-audio.js'; import { galleryImageKey, SingleImageGallery, useImageGallery } from './message-image-gallery.js'; +import { useMessageResource } from './message-resource.js'; +import { useMessageHost } from './message-host.js'; const INLINE_IMAGE_TYPES = ['image/png', 'image/jpeg', 'image/gif', 'image/webp']; @@ -72,6 +75,7 @@ export function MessageAttachment({ | undefined; t: BotHarnessTranslate; }): ReactElement { + const host = useMessageHost(); const commands = useMemo( () => actions === undefined @@ -90,10 +94,22 @@ export function MessageAttachment({ const menu = useHostFileMenu(commands, channelId, t); const gallery = useImageGallery(); const id = ref.fileId; - const url = - channelId !== undefined ? channelAttachmentUrl(ref, { channelId, messageId }) : undefined; const image = inlineImageAttachment(ref.mime); + const resource = useMessageResource( + channelId !== undefined ? channelAttachmentUrl(ref, { channelId, messageId }) : undefined, + image, + ); + const { url } = resource; const audio = ref.mime.startsWith('audio/'); + if (resource.failed) + return ( +
+ {t('bridgeMedia.unavailable')}{' '} + +
+ ); if (audio && !compact) { return (
menu.open(id, event)} onKeyDown={id === undefined ? undefined : (event) => menu.onKey(id, event)} > - + void resource.download(ref.name)} + t={t} + /> {menu.menu} {menu.feedback}
@@ -121,24 +144,37 @@ export function MessageAttachment({ ); const downloadAction = - url === undefined ? null : ( + url === undefined && host === undefined ? null : ( <>
- {downloadUrl === undefined ? null : ( + {downloadUrl === undefined && onDownload === undefined ? null : ( <>
-
{ - event.preventDefault(); - send(); - }} - > -