paseo-office 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/OVERVIEW.md +27 -0
- package/README.md +65 -134
- package/client/action-button.tsx +4 -1
- package/client/activity-panel.tsx +6 -4
- package/client/agent-appearance.tsx +257 -0
- package/client/agent-card.tsx +2 -1
- package/client/agent-picker-text.ts +23 -4
- package/client/agent-picker.tsx +5 -8
- package/client/board-sheet.tsx +48 -16
- package/client/board-text.ts +12 -2
- package/client/brand.ts +1 -0
- package/client/chat-chrome.tsx +318 -0
- package/client/chat-compose-tools.tsx +314 -0
- package/client/chat-dictation.tsx +133 -0
- package/client/chat-more.tsx +119 -0
- package/client/chat-panel.tsx +401 -146
- package/client/chat-quick.tsx +198 -0
- package/client/chat-text.ts +25 -6
- package/client/column-sheet.tsx +93 -23
- package/client/conversation-model.ts +19 -5
- package/client/duty-sheet.tsx +321 -0
- package/client/duty-text.ts +20 -0
- package/client/fullscreen-header.tsx +28 -13
- package/client/fullscreen-theme.ts +38 -0
- package/client/host-details.tsx +269 -0
- package/client/host-styles.ts +129 -0
- package/client/host-switches.tsx +197 -73
- package/client/incidents-card.tsx +2 -1
- package/client/janitor-card.tsx +1 -1
- package/client/library-card.tsx +2 -1
- package/client/list-text.ts +8 -6
- package/client/lobby-board.tsx +73 -53
- package/client/machine-card.tsx +225 -85
- package/client/messenger-styles.ts +216 -0
- package/client/new-agent-form.tsx +153 -61
- package/client/new-agent-model.ts +2 -0
- package/client/notes-card.tsx +111 -83
- package/client/notes-days.tsx +1 -1
- package/client/office-brand-context.ts +44 -0
- package/client/office-column.tsx +2 -1
- package/client/office-keyboard.ts +79 -0
- package/client/office-link.ts +7 -1
- package/client/office-mark.tsx +29 -0
- package/client/office-modal.tsx +440 -0
- package/client/office-settings.tsx +75 -30
- package/client/office-state.ts +12 -2
- package/client/office-surface.tsx +591 -81
- package/client/pixel/actors.ts +2 -1
- package/client/pixel/art.ts +33 -19
- package/client/pixel/pixel-office.tsx +2 -2
- package/client/prompt-coach.tsx +152 -0
- package/client/qa-card.tsx +2 -1
- package/client/review-card.tsx +2 -1
- package/client/room-board.tsx +26 -2
- package/client/scene-picker.tsx +158 -0
- package/client/scene-previews.ts +10 -0
- package/client/session-pane.tsx +25 -5
- package/client/session-panel-detail.tsx +238 -0
- package/client/session-panel.tsx +222 -137
- package/client/session-styles.ts +224 -1
- package/client/session-transcript.tsx +243 -0
- package/client/sessions-panel.tsx +181 -22
- package/client/sessions-text.ts +18 -0
- package/client/settings-sections.tsx +126 -0
- package/client/sidebar-launcher.ts +29 -0
- package/client/ssh-hosts.tsx +331 -0
- package/client/ssh-metrics.ts +76 -0
- package/client/standup-card.tsx +2 -1
- package/client/structure-view.tsx +20 -3
- package/client/styles.ts +170 -62
- package/client/team-chat-preview.tsx +96 -0
- package/client/transcript-styles.ts +90 -0
- package/client/use-device-switch.ts +21 -12
- package/client/use-duty-actions.ts +43 -0
- package/client/use-group-photo.ts +48 -0
- package/client/use-new-agent.ts +4 -0
- package/client/use-street.ts +8 -0
- package/client/workspace-office-tools.tsx +102 -0
- package/client/workspace-overlay-route.web.ts +47 -0
- package/client/workspace-overlay.tsx +195 -0
- package/client/world/adapter.ts +37 -2
- package/client/world/escape.ts +58 -0
- package/client/world/use-world-feed.ts +6 -2
- package/client/world/workspace-dock.ts +6 -0
- package/client/world/world-api.ts +45 -4
- package/client/world/world-bridge-page.ts +14 -3
- package/client/world/world-bridge.ts +50 -5
- package/client/world/world-frame.web.ts +8 -0
- package/client/world/world-view-native.tsx +31 -10
- package/client/world/world-view-shared.ts +36 -7
- package/client/world/world-view.tsx +93 -21
- package/docs/office.md +148 -58
- package/index.client.tsx +13 -6
- package/index.server.ts +125 -9
- package/package.json +2 -1
- package/server/activity.ts +42 -19
- package/server/agent-tools.ts +11 -5
- package/server/board-service.ts +381 -10
- package/server/brand-logo.ts +34 -0
- package/server/chat-group.ts +83 -0
- package/server/chat-service.ts +406 -62
- package/server/chat-store.ts +1 -4
- package/server/directory.ts +22 -7
- package/server/duty-service.ts +230 -0
- package/server/group-photo.ts +39 -0
- package/server/home-departure.ts +47 -0
- package/server/hub.ts +43 -1
- package/server/live-ports.ts +114 -18
- package/server/lobby-pickup.ts +170 -0
- package/server/machine/details.ts +91 -0
- package/server/mention-queue.ts +14 -0
- package/server/office.ts +110 -6
- package/server/paths.ts +9 -0
- package/server/ssh/LICENSE.paseo +211 -0
- package/server/ssh/client.ts +401 -0
- package/server/ssh/discovery.ts +230 -0
- package/server/ssh/installed.ts +104 -0
- package/server/ssh/monitor.ts +104 -0
- package/server/ssh/pid-files.ts +194 -0
- package/server/ssh/read.ts +136 -0
- package/server/subagent-names.ts +4 -0
- package/server/words.generated.ts +1 -1
- package/server/world.generated.ts +1 -1
- package/shared/appearance.ts +43 -0
- package/shared/branding.ts +53 -0
- package/shared/chat-words.ts +2 -2
- package/shared/contracts.ts +135 -4
- package/shared/duties.ts +100 -0
- package/shared/host-details.ts +25 -0
- package/shared/lobby-assignment.ts +34 -0
- package/shared/model.ts +9 -1
- package/shared/names.ts +2 -0
- package/shared/settings.ts +14 -3
- package/shared/ssh.ts +34 -0
- package/shared/upstream/README.md +1 -3
- package/shared/upstream/chat-engine.d.ts +4 -0
- package/shared/upstream/prompt-coach.d.ts +6 -0
- package/shared/upstream/prompt-coach.js +178 -0
package/client/chat-panel.tsx
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { Appearance } from "../shared/appearance.js";
|
|
1
2
|
import {
|
|
3
|
+
Fragment,
|
|
2
4
|
memo,
|
|
3
5
|
useCallback,
|
|
4
6
|
useEffect,
|
|
@@ -6,10 +8,12 @@ import {
|
|
|
6
8
|
useReducer,
|
|
7
9
|
useRef,
|
|
8
10
|
useState,
|
|
11
|
+
type ComponentRef,
|
|
9
12
|
type ReactNode,
|
|
10
13
|
} from "react";
|
|
11
14
|
import {
|
|
12
15
|
Pressable,
|
|
16
|
+
Image,
|
|
13
17
|
Text,
|
|
14
18
|
View,
|
|
15
19
|
type NativeSyntheticEvent,
|
|
@@ -19,8 +23,14 @@ import {
|
|
|
19
23
|
import { useRpc } from "@getpaseo/plugin/client";
|
|
20
24
|
import { Icon, ScrollView, TextInput } from "@getpaseo/plugin/client/ui";
|
|
21
25
|
import { CHAT_TEXT_MAX, chatRpc, type ChatMessage, type ChatRequest } from "../shared/contracts.js";
|
|
22
|
-
import { buildOfficeModel } from "../shared/model.js";
|
|
23
|
-
import {
|
|
26
|
+
import { agentTitle, buildOfficeModel } from "../shared/model.js";
|
|
27
|
+
import { failureText } from "./action-button.js";
|
|
28
|
+
import { ChatHeader } from "./chat-chrome.js";
|
|
29
|
+
import { PromptCoach } from "./prompt-coach.js";
|
|
30
|
+
import { tabOf } from "./list-text.js";
|
|
31
|
+
import type { ChatShortcuts } from "./chat-more.js";
|
|
32
|
+
import { ComposeTools } from "./chat-compose-tools.js";
|
|
33
|
+
import { messengerTheme } from "./messenger-styles.js";
|
|
24
34
|
import { loadProblem } from "./activity-panel.js";
|
|
25
35
|
import {
|
|
26
36
|
CHAT_EMPTY,
|
|
@@ -46,11 +56,11 @@ import {
|
|
|
46
56
|
typingText,
|
|
47
57
|
type MentionOption,
|
|
48
58
|
} from "./chat-text.js";
|
|
49
|
-
import { markChatSeen } from "./chat-seen.js";
|
|
59
|
+
import { getChatSeen, markChatSeen } from "./chat-seen.js";
|
|
50
60
|
import { useFollowEnd } from "./follow-end.js";
|
|
51
61
|
import type { ChatDraft, ColumnPanelProps, OfficeLink } from "./office-link.js";
|
|
52
62
|
import { hasTouchScreen, readPointer } from "./office-surface.js";
|
|
53
|
-
import type
|
|
63
|
+
import { useOfficeStyles, type OfficeStyles } from "./styles.js";
|
|
54
64
|
|
|
55
65
|
/** Sends a request to the chat; false when it failed, and the error is then under the box. */
|
|
56
66
|
type Run = (input: ChatRequest) => Promise<boolean>;
|
|
@@ -207,41 +217,19 @@ interface BodyProps {
|
|
|
207
217
|
styles: OfficeStyles;
|
|
208
218
|
}
|
|
209
219
|
|
|
210
|
-
/** Words, clipped at eight lines until Show more
|
|
211
|
-
function TextBody({ message,
|
|
220
|
+
/** Words, clipped at eight lines until Show more. */
|
|
221
|
+
function TextBody({ message, keep, styles }: BodyProps) {
|
|
212
222
|
const [expanded, setExpanded] = useState(false);
|
|
213
223
|
const expand = useCallback(() => setExpanded(true), []);
|
|
214
|
-
const { from } = message;
|
|
215
|
-
const open = useCallback(() => {
|
|
216
|
-
if (from !== undefined) link.openSession(from);
|
|
217
|
-
}, [from, link]);
|
|
218
224
|
const clipped = !expanded && isLong(message.text);
|
|
219
|
-
const openable = onFloor && !isYours(message);
|
|
220
225
|
return (
|
|
221
226
|
<>
|
|
222
227
|
<Text style={styles.chatText} numberOfLines={clipped ? SHOW_MORE_LINES : 0}>
|
|
223
228
|
{message.text}
|
|
224
229
|
</Text>
|
|
225
|
-
{clipped
|
|
230
|
+
{clipped ? (
|
|
226
231
|
<View style={styles.chatActions}>
|
|
227
|
-
{
|
|
228
|
-
<ChatButton
|
|
229
|
-
label="Show more"
|
|
230
|
-
value="more"
|
|
231
|
-
onPress={expand}
|
|
232
|
-
keep={keep}
|
|
233
|
-
styles={styles}
|
|
234
|
-
/>
|
|
235
|
-
) : null}
|
|
236
|
-
{openable ? (
|
|
237
|
-
<ChatButton
|
|
238
|
-
label="Open session"
|
|
239
|
-
value="open"
|
|
240
|
-
onPress={open}
|
|
241
|
-
keep={keep}
|
|
242
|
-
styles={styles}
|
|
243
|
-
/>
|
|
244
|
-
) : null}
|
|
232
|
+
<ChatButton label="Show more" value="more" onPress={expand} keep={keep} styles={styles} />
|
|
245
233
|
</View>
|
|
246
234
|
) : null}
|
|
247
235
|
</>
|
|
@@ -309,10 +297,24 @@ function RemindBody({ message, run, keep, styles }: BodyProps) {
|
|
|
309
297
|
);
|
|
310
298
|
}
|
|
311
299
|
|
|
300
|
+
function OfficePhoto({ photo, styles }: { photo: string; styles: OfficeStyles }) {
|
|
301
|
+
const source = useMemo(() => ({ uri: photo }), [photo]);
|
|
302
|
+
return (
|
|
303
|
+
<Image
|
|
304
|
+
accessibilityLabel="Office photo"
|
|
305
|
+
accessible
|
|
306
|
+
source={source}
|
|
307
|
+
resizeMode="contain"
|
|
308
|
+
style={styles.messenger.photo}
|
|
309
|
+
/>
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
312
|
function Body(props: BodyProps) {
|
|
313
313
|
const { message, styles } = props;
|
|
314
314
|
if (message.recalled === true) return <Text style={styles.chatMeta}>{CHAT_RECALLED}</Text>;
|
|
315
315
|
switch (message.kind) {
|
|
316
|
+
case "photo":
|
|
317
|
+
return message.photo ? <OfficePhoto photo={message.photo} styles={styles} /> : null;
|
|
316
318
|
case "sticker":
|
|
317
319
|
return (
|
|
318
320
|
<View style={styles.chatChip}>
|
|
@@ -353,6 +355,7 @@ function Reactions({ message, run, keep, styles }: BodyProps) {
|
|
|
353
355
|
|
|
354
356
|
interface ActionsProps extends BodyProps {
|
|
355
357
|
shown: boolean;
|
|
358
|
+
inline: boolean;
|
|
356
359
|
recallable: boolean;
|
|
357
360
|
picking: boolean;
|
|
358
361
|
onPicking(): void;
|
|
@@ -366,14 +369,17 @@ function Actions({
|
|
|
366
369
|
keep,
|
|
367
370
|
styles,
|
|
368
371
|
shown,
|
|
372
|
+
inline,
|
|
369
373
|
recallable,
|
|
370
374
|
picking,
|
|
371
375
|
onPicking,
|
|
372
376
|
onReply,
|
|
373
377
|
}: ActionsProps) {
|
|
374
378
|
const { id } = message;
|
|
379
|
+
const floating = shown ? styles.messenger.tools : styles.messenger.toolsHidden;
|
|
375
380
|
const reply = useCallback(() => onReply(message), [onReply, message]);
|
|
376
381
|
const recall = useCallback(() => void run({ op: "recall", id }), [run, id]);
|
|
382
|
+
const pin = useCallback(() => void run({ op: "pin", id }), [run, id]);
|
|
377
383
|
const choose = useCallback(
|
|
378
384
|
(emoji: string) => {
|
|
379
385
|
onPicking();
|
|
@@ -383,7 +389,7 @@ function Actions({
|
|
|
383
389
|
);
|
|
384
390
|
return (
|
|
385
391
|
<>
|
|
386
|
-
<View style={
|
|
392
|
+
<View style={inline ? styles.chatActions : floating}>
|
|
387
393
|
<ChatButton
|
|
388
394
|
label="React"
|
|
389
395
|
value="react"
|
|
@@ -393,6 +399,9 @@ function Actions({
|
|
|
393
399
|
styles={styles}
|
|
394
400
|
/>
|
|
395
401
|
<ChatButton label="Reply" value="reply" onPress={reply} keep={keep} styles={styles} />
|
|
402
|
+
<ChatButton label="Pin message" value="pin" onPress={pin} keep={keep} styles={styles}>
|
|
403
|
+
<Icon name="Pin" size={13} color={styles.iconColor} />
|
|
404
|
+
</ChatButton>
|
|
396
405
|
{recallable ? (
|
|
397
406
|
<ChatButton label="Recall" value="recall" onPress={recall} keep={keep} styles={styles} />
|
|
398
407
|
) : null}
|
|
@@ -429,6 +438,7 @@ function useRecallable(message: ChatMessage): boolean {
|
|
|
429
438
|
}
|
|
430
439
|
|
|
431
440
|
interface ChatRowProps {
|
|
441
|
+
appearance?: Appearance;
|
|
432
442
|
message: ChatMessage;
|
|
433
443
|
onFloor: boolean;
|
|
434
444
|
/** A touch screen, where nothing hovers. */
|
|
@@ -444,6 +454,7 @@ interface ChatRowProps {
|
|
|
444
454
|
* actions show on hover and focus on the web, and always on a touch screen.
|
|
445
455
|
*/
|
|
446
456
|
const ChatRow = memo(function ChatRow({
|
|
457
|
+
appearance,
|
|
447
458
|
message,
|
|
448
459
|
onFloor,
|
|
449
460
|
always,
|
|
@@ -453,7 +464,7 @@ const ChatRow = memo(function ChatRow({
|
|
|
453
464
|
styles,
|
|
454
465
|
}: ChatRowProps) {
|
|
455
466
|
const mine = isYours(message);
|
|
456
|
-
const avatar = avatarOf(message);
|
|
467
|
+
const avatar = avatarOf(message, appearance);
|
|
457
468
|
const time = timeLabel(message.at, Date.now());
|
|
458
469
|
const recallable = useRecallable(message);
|
|
459
470
|
const [hovered, setHovered] = useState(false);
|
|
@@ -462,6 +473,14 @@ const ChatRow = memo(function ChatRow({
|
|
|
462
473
|
const [inner, setInner] = useState(false);
|
|
463
474
|
const [focused, setFocused] = useState(false);
|
|
464
475
|
const keep = useMemo<Keep>(() => ({ hover: setInner, focus: setFocused }), []);
|
|
476
|
+
const openSender = useCallback(() => {
|
|
477
|
+
if (message.from !== undefined) link.openSession(message.from);
|
|
478
|
+
}, [link, message.from]);
|
|
479
|
+
const senderName = (
|
|
480
|
+
<Text style={styles.chatName} numberOfLines={1}>
|
|
481
|
+
{message.name ?? ""}
|
|
482
|
+
</Text>
|
|
483
|
+
);
|
|
465
484
|
const [picking, setPicking] = useState(false);
|
|
466
485
|
const togglePicking = useCallback(() => setPicking((open) => !open), []);
|
|
467
486
|
const body: BodyProps = { message, onFloor, link, run, keep, styles };
|
|
@@ -477,24 +496,36 @@ const ChatRow = memo(function ChatRow({
|
|
|
477
496
|
<Avatar initials={avatar.initials} color={avatar.color} styles={styles} />
|
|
478
497
|
)}
|
|
479
498
|
<View style={mine ? styles.chatBubbleMine : styles.chatBubble}>
|
|
480
|
-
{mine
|
|
499
|
+
{!mine && (
|
|
481
500
|
<View style={styles.boardHeading}>
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
501
|
+
{onFloor ? (
|
|
502
|
+
<ChatButton
|
|
503
|
+
label="Open session"
|
|
504
|
+
value="sender"
|
|
505
|
+
onPress={openSender}
|
|
506
|
+
keep={keep}
|
|
507
|
+
style={styles.boardHeading}
|
|
508
|
+
styles={styles}
|
|
509
|
+
>
|
|
510
|
+
{senderName}
|
|
511
|
+
<Icon name="ArrowUpRight" size={11} color={styles.iconColor} />
|
|
512
|
+
</ChatButton>
|
|
513
|
+
) : (
|
|
514
|
+
senderName
|
|
515
|
+
)}
|
|
486
516
|
</View>
|
|
487
517
|
)}
|
|
488
518
|
{message.reply ? (
|
|
489
519
|
<Quote name={message.reply.name} text={message.reply.text} styles={styles} />
|
|
490
520
|
) : null}
|
|
491
521
|
<Body {...body} />
|
|
492
|
-
|
|
522
|
+
<Text style={styles.chatMeta}>{time}</Text>
|
|
493
523
|
{message.recalled === true ? null : <Reactions {...body} />}
|
|
494
524
|
{message.recalled === true ? null : (
|
|
495
525
|
<Actions
|
|
496
526
|
{...body}
|
|
497
527
|
shown={always || hovered || inner || focused || picking}
|
|
528
|
+
inline={always || picking}
|
|
498
529
|
recallable={recallable}
|
|
499
530
|
picking={picking}
|
|
500
531
|
onPicking={togglePicking}
|
|
@@ -508,8 +539,10 @@ const ChatRow = memo(function ChatRow({
|
|
|
508
539
|
|
|
509
540
|
interface MessagesProps {
|
|
510
541
|
messages: readonly ChatMessage[];
|
|
542
|
+
emptyLabel: string;
|
|
543
|
+
firstUnread?: string;
|
|
511
544
|
/** The agents on the floor. */
|
|
512
|
-
agents: ReadonlyMap<string,
|
|
545
|
+
agents: ReadonlyMap<string, { appearance?: Appearance }>;
|
|
513
546
|
problem: string | null;
|
|
514
547
|
always: boolean;
|
|
515
548
|
link: OfficeLink;
|
|
@@ -521,6 +554,8 @@ interface MessagesProps {
|
|
|
521
554
|
/** The conversation, oldest first; a state that cannot load says so in its place. */
|
|
522
555
|
function Messages({
|
|
523
556
|
messages,
|
|
557
|
+
emptyLabel,
|
|
558
|
+
firstUnread,
|
|
524
559
|
agents,
|
|
525
560
|
problem,
|
|
526
561
|
always,
|
|
@@ -538,25 +573,34 @@ function Messages({
|
|
|
538
573
|
</View>
|
|
539
574
|
);
|
|
540
575
|
}
|
|
541
|
-
if (messages.length === 0) return <Text style={styles.
|
|
542
|
-
return messages.map((message) =>
|
|
543
|
-
message.
|
|
544
|
-
|
|
545
|
-
{
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
576
|
+
if (messages.length === 0) return <Text style={styles.messenger.empty}>{emptyLabel}</Text>;
|
|
577
|
+
return messages.map((message) => (
|
|
578
|
+
<Fragment key={message.id}>
|
|
579
|
+
{message.id === firstUnread && (
|
|
580
|
+
<View style={styles.messenger.unread}>
|
|
581
|
+
<View style={styles.messenger.unreadRule} />
|
|
582
|
+
<Text style={styles.messenger.unreadText}>New messages</Text>
|
|
583
|
+
<View style={styles.messenger.unreadRule} />
|
|
584
|
+
</View>
|
|
585
|
+
)}
|
|
586
|
+
{message.kind === "sys" ? (
|
|
587
|
+
<Text testID={`chat-${message.id}`} style={styles.chatSystem}>
|
|
588
|
+
{message.text}
|
|
589
|
+
</Text>
|
|
590
|
+
) : (
|
|
591
|
+
<ChatRow
|
|
592
|
+
appearance={message.from ? agents.get(message.from)?.appearance : undefined}
|
|
593
|
+
message={message}
|
|
594
|
+
onFloor={message.from !== undefined && agents.has(message.from)}
|
|
595
|
+
always={always}
|
|
596
|
+
link={link}
|
|
597
|
+
run={run}
|
|
598
|
+
onReply={onReply}
|
|
599
|
+
styles={styles}
|
|
600
|
+
/>
|
|
601
|
+
)}
|
|
602
|
+
</Fragment>
|
|
603
|
+
));
|
|
560
604
|
}
|
|
561
605
|
|
|
562
606
|
interface ReplyBarProps {
|
|
@@ -641,6 +685,93 @@ function StickerTray({ onPick, styles }: { onPick(index: number): void; styles:
|
|
|
641
685
|
* The Chat tab of the office's column, fed by the surface's subscription: the team conversation,
|
|
642
686
|
* which the surface keeps apart from the floor's state.
|
|
643
687
|
*/
|
|
688
|
+
function readyToSend({ images, recipient, text }: ChatDraft, reading: boolean): boolean {
|
|
689
|
+
return !reading && (images.length ? recipient !== null : text.trim() !== "");
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
function SendButton({
|
|
693
|
+
like,
|
|
694
|
+
canSend,
|
|
695
|
+
send,
|
|
696
|
+
sendLike,
|
|
697
|
+
styles,
|
|
698
|
+
color,
|
|
699
|
+
muted,
|
|
700
|
+
size,
|
|
701
|
+
}: {
|
|
702
|
+
like: boolean;
|
|
703
|
+
canSend: boolean;
|
|
704
|
+
send(): void;
|
|
705
|
+
sendLike(): void;
|
|
706
|
+
styles: OfficeStyles;
|
|
707
|
+
color: string;
|
|
708
|
+
muted: string;
|
|
709
|
+
size: number;
|
|
710
|
+
}) {
|
|
711
|
+
const enabled = like || canSend;
|
|
712
|
+
return (
|
|
713
|
+
<Pressable
|
|
714
|
+
accessibilityRole="button"
|
|
715
|
+
accessibilityLabel={like ? "Send thumbs up" : "Send"}
|
|
716
|
+
onPress={like ? sendLike : send}
|
|
717
|
+
disabled={!enabled}
|
|
718
|
+
style={enabled ? styles.messenger.send : styles.messenger.sendOff}
|
|
719
|
+
>
|
|
720
|
+
<Icon name={like ? "ThumbsUp" : "Send"} size={size} color={enabled ? color : muted} />
|
|
721
|
+
</Pressable>
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
function canLike(draft: ChatDraft, reading: boolean): boolean {
|
|
726
|
+
return !reading && draft.images.length === 0 && draft.text.trim() === "";
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
function Pinned({
|
|
730
|
+
message,
|
|
731
|
+
active,
|
|
732
|
+
onPress,
|
|
733
|
+
styles,
|
|
734
|
+
}: {
|
|
735
|
+
message: ChatMessage | undefined;
|
|
736
|
+
active: boolean;
|
|
737
|
+
onPress(): void;
|
|
738
|
+
styles: OfficeStyles;
|
|
739
|
+
}) {
|
|
740
|
+
if (!message) return null;
|
|
741
|
+
return (
|
|
742
|
+
<Pressable
|
|
743
|
+
accessibilityRole="button"
|
|
744
|
+
accessibilityLabel="Pinned message"
|
|
745
|
+
aria-pressed={active}
|
|
746
|
+
onPress={onPress}
|
|
747
|
+
style={styles.messenger.pin}
|
|
748
|
+
>
|
|
749
|
+
<Icon name="Pin" size={15} color={styles.iconColor} />
|
|
750
|
+
<View style={styles.rowBody}>
|
|
751
|
+
<Text style={styles.chatName}>Pinned message</Text>
|
|
752
|
+
<Text numberOfLines={1} style={styles.chatMeta}>
|
|
753
|
+
{quotedText(message)}
|
|
754
|
+
</Text>
|
|
755
|
+
</View>
|
|
756
|
+
<Icon name={active ? "X" : "ChevronRight"} size={14} color={styles.iconColor} />
|
|
757
|
+
</Pressable>
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
const memberStatuses = { attention: "Needs you", working: "Working", resting: "Resting" } as const;
|
|
762
|
+
type ChatPanelProps = ColumnPanelProps &
|
|
763
|
+
ChatShortcuts & { draft: ChatDraft; onClose?: (() => void) | undefined };
|
|
764
|
+
|
|
765
|
+
export function FloatingTeamChat(props: ChatPanelProps & { onClose(): void }) {
|
|
766
|
+
const theme = useMemo(() => messengerTheme(props.theme), [props.theme]);
|
|
767
|
+
const styles = useOfficeStyles(theme, props.layout.compact, props.layout.platform !== "web");
|
|
768
|
+
return (
|
|
769
|
+
<View role="region" aria-label="Team chat" style={styles.messenger.floating}>
|
|
770
|
+
<ChatPanel {...props} theme={theme} styles={styles} />
|
|
771
|
+
</View>
|
|
772
|
+
);
|
|
773
|
+
}
|
|
774
|
+
|
|
644
775
|
export function ChatPanel({
|
|
645
776
|
office,
|
|
646
777
|
styles,
|
|
@@ -648,16 +779,68 @@ export function ChatPanel({
|
|
|
648
779
|
layout,
|
|
649
780
|
link,
|
|
650
781
|
draft,
|
|
651
|
-
|
|
782
|
+
onClose,
|
|
783
|
+
onBoard,
|
|
784
|
+
onDuties,
|
|
785
|
+
onNewAgent,
|
|
786
|
+
onGroupPhoto,
|
|
787
|
+
}: ChatPanelProps) {
|
|
652
788
|
const { state, subscription, chat } = office;
|
|
653
789
|
const call = useRpc(chatRpc);
|
|
654
790
|
const model = useMemo(() => buildOfficeModel(state), [state]);
|
|
655
791
|
// The surface holds what is typed, so a look at another tab or a closed sheet keeps it.
|
|
656
|
-
const { text, setText, replyTo, setReplyTo } = draft;
|
|
792
|
+
const { text, setText, replyTo, setReplyTo, recipient, images, setImages } = draft;
|
|
793
|
+
const [reading, setReading] = useState(false);
|
|
794
|
+
const canSend = readyToSend(draft, reading);
|
|
795
|
+
const [searching, setSearching] = useState(false);
|
|
796
|
+
const [query, setQuery] = useState("");
|
|
797
|
+
const toggleSearch = useCallback(() => {
|
|
798
|
+
setSearching((value) => !value);
|
|
799
|
+
setQuery("");
|
|
800
|
+
}, []);
|
|
801
|
+
const [openedAt] = useState(getChatSeen);
|
|
802
|
+
const [pinnedOnly, setPinnedOnly] = useState(false);
|
|
803
|
+
const togglePin = useCallback(() => {
|
|
804
|
+
setPinnedOnly((value) => !value);
|
|
805
|
+
setQuery("");
|
|
806
|
+
}, []);
|
|
807
|
+
const members = useMemo(
|
|
808
|
+
() =>
|
|
809
|
+
model.rooms.flatMap((room) =>
|
|
810
|
+
room.rows.map((row) => ({
|
|
811
|
+
id: row.agent.id,
|
|
812
|
+
name: agentTitle(row.agent),
|
|
813
|
+
room: room.name,
|
|
814
|
+
appearance: row.agent.appearance,
|
|
815
|
+
status: memberStatuses[tabOf(row)],
|
|
816
|
+
})),
|
|
817
|
+
),
|
|
818
|
+
[model],
|
|
819
|
+
);
|
|
657
820
|
const [error, setError] = useState<string | null>(null);
|
|
658
821
|
const [stickersOpen, setStickersOpen] = useState(false);
|
|
659
822
|
const all = chat?.messages;
|
|
660
823
|
const messages = useMemo(() => (all ?? []).filter(shows), [all]);
|
|
824
|
+
const pinned = messages.find((m) => m.id === chat?.pinned && !m.recalled);
|
|
825
|
+
const needle = query.trim().toLowerCase();
|
|
826
|
+
const visible = useMemo(
|
|
827
|
+
() =>
|
|
828
|
+
needle
|
|
829
|
+
? messages.filter((message) =>
|
|
830
|
+
[message.name, quotedText(message), message.reply?.text].some((part) =>
|
|
831
|
+
part?.toLowerCase().includes(needle),
|
|
832
|
+
),
|
|
833
|
+
)
|
|
834
|
+
: messages,
|
|
835
|
+
[needle, messages],
|
|
836
|
+
);
|
|
837
|
+
const shownMessages = useMemo(
|
|
838
|
+
() => (pinnedOnly && pinned && !needle ? [pinned] : visible),
|
|
839
|
+
[pinnedOnly, pinned, needle, visible],
|
|
840
|
+
);
|
|
841
|
+
const firstUnread = messages.find(
|
|
842
|
+
(message) => message.at > openedAt && !isYours(message) && message.kind !== "sys",
|
|
843
|
+
)?.id;
|
|
661
844
|
const problem = loadProblem(subscription);
|
|
662
845
|
// Asked once, as the surface does. A phone, or a browser on a touch screen, has nothing to hover
|
|
663
846
|
// with and no Enter that sends: the actions always show and the Send button sends.
|
|
@@ -668,8 +851,8 @@ export function ChatPanel({
|
|
|
668
851
|
// The chat is seen up to its newest message while it is open.
|
|
669
852
|
const newest = messages.at(-1)?.at ?? 0;
|
|
670
853
|
useEffect(() => {
|
|
671
|
-
if (newest > 0) markChatSeen(newest);
|
|
672
|
-
}, [newest]);
|
|
854
|
+
if (newest > 0 && needle === "") markChatSeen(newest);
|
|
855
|
+
}, [newest, needle]);
|
|
673
856
|
// Stays at the bottom while you are there.
|
|
674
857
|
const { scroller, onScroll, followEnd } = useFollowEnd();
|
|
675
858
|
|
|
@@ -689,30 +872,43 @@ export function ChatPanel({
|
|
|
689
872
|
);
|
|
690
873
|
// Enter and the Send button can both fire before the first send returns.
|
|
691
874
|
const sending = useRef(false);
|
|
692
|
-
const
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
875
|
+
const post = useCallback(
|
|
876
|
+
async (like: boolean) => {
|
|
877
|
+
const sent = like ? "👍" : text.trim();
|
|
878
|
+
if ((!like && !canSend) || sending.current) return;
|
|
879
|
+
sending.current = true;
|
|
880
|
+
const ok = await run({
|
|
881
|
+
op: "send",
|
|
882
|
+
text: sent,
|
|
883
|
+
...(replyTo ? { replyTo: replyTo.id } : {}),
|
|
884
|
+
...(recipient ? { to: recipient } : {}),
|
|
885
|
+
...(images.length
|
|
886
|
+
? { images: images.map(({ data, mimeType }) => ({ data, mimeType })) }
|
|
887
|
+
: {}),
|
|
888
|
+
});
|
|
889
|
+
sending.current = false;
|
|
890
|
+
if (!ok) return;
|
|
891
|
+
setText((current) => textAfterSend(current, sent));
|
|
892
|
+
if (images.length) setImages((current) => current.filter((image) => !images.includes(image)));
|
|
893
|
+
setReplyTo(null);
|
|
894
|
+
},
|
|
895
|
+
[text, replyTo, recipient, images, setImages, canSend, run, setText, setReplyTo],
|
|
896
|
+
);
|
|
897
|
+
const send = useCallback(() => post(false), [post]);
|
|
898
|
+
const sendLike = useCallback(() => post(true), [post]);
|
|
706
899
|
const sendSticker = useCallback(
|
|
707
900
|
async (sticker: number) => {
|
|
708
|
-
const ok = await run(
|
|
709
|
-
|
|
710
|
-
|
|
901
|
+
const ok = await run({
|
|
902
|
+
op: "send",
|
|
903
|
+
sticker,
|
|
904
|
+
...(replyTo ? { replyTo: replyTo.id } : {}),
|
|
905
|
+
...(recipient ? { to: recipient } : {}),
|
|
906
|
+
});
|
|
711
907
|
if (!ok) return;
|
|
712
908
|
setStickersOpen(false);
|
|
713
909
|
setReplyTo(null);
|
|
714
910
|
},
|
|
715
|
-
[replyTo, run, setReplyTo],
|
|
911
|
+
[replyTo, recipient, run, setReplyTo],
|
|
716
912
|
);
|
|
717
913
|
|
|
718
914
|
const options = useMemo(() => {
|
|
@@ -720,12 +916,25 @@ export function ChatPanel({
|
|
|
720
916
|
return mention === null ? [] : mentionOptions(model, mention.query);
|
|
721
917
|
}, [text, model]);
|
|
722
918
|
const first = options[0];
|
|
919
|
+
const input = useRef<ComponentRef<typeof TextInput>>(null);
|
|
920
|
+
const useQuick = useCallback(
|
|
921
|
+
(message: string) => {
|
|
922
|
+
setText(message);
|
|
923
|
+
input.current?.focus();
|
|
924
|
+
},
|
|
925
|
+
[setText],
|
|
926
|
+
);
|
|
927
|
+
const insertMention = useCallback(() => {
|
|
928
|
+
setText((value) => (value.trimEnd() ? value.trimEnd() + " @" : "@"));
|
|
929
|
+
input.current?.focus();
|
|
930
|
+
}, [setText]);
|
|
723
931
|
const pick = useCallback(
|
|
724
932
|
(name: string) => {
|
|
725
933
|
setText((current) => {
|
|
726
934
|
const mention = mentionAt(current);
|
|
727
935
|
return mention === null ? current : putMention(current, mention, name);
|
|
728
936
|
});
|
|
937
|
+
input.current?.focus();
|
|
729
938
|
},
|
|
730
939
|
[setText],
|
|
731
940
|
);
|
|
@@ -756,76 +965,122 @@ export function ChatPanel({
|
|
|
756
965
|
const iconSize = layout.compact ? 20 : 16;
|
|
757
966
|
return (
|
|
758
967
|
<View style={styles.screen}>
|
|
759
|
-
<
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
</ScrollView>
|
|
779
|
-
<Text style={styles.chatTyping}>{typing}</Text>
|
|
780
|
-
<View style={styles.chatBox}>
|
|
781
|
-
{replyTo === null ? null : (
|
|
782
|
-
<ReplyBar
|
|
783
|
-
message={replyTo}
|
|
784
|
-
onClose={closeReply}
|
|
785
|
-
iconSize={iconSize}
|
|
786
|
-
color={theme.colors.foreground}
|
|
787
|
-
styles={styles}
|
|
968
|
+
<ChatHeader
|
|
969
|
+
members={members}
|
|
970
|
+
onOpenSession={link.openSession}
|
|
971
|
+
searching={searching}
|
|
972
|
+
onSearch={toggleSearch}
|
|
973
|
+
onClose={onClose}
|
|
974
|
+
styles={styles}
|
|
975
|
+
/>
|
|
976
|
+
<Pinned message={pinned} active={pinnedOnly} onPress={togglePin} styles={styles} />
|
|
977
|
+
{searching && (
|
|
978
|
+
<View style={styles.messenger.searchRow}>
|
|
979
|
+
<TextInput
|
|
980
|
+
autoFocus
|
|
981
|
+
accessibilityLabel="Search messages"
|
|
982
|
+
placeholder="Search messages"
|
|
983
|
+
placeholderTextColor={styles.placeholderColor}
|
|
984
|
+
value={query}
|
|
985
|
+
onChangeText={setQuery}
|
|
986
|
+
style={styles.fieldInput}
|
|
788
987
|
/>
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
{
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
value="stickers"
|
|
812
|
-
onPress={toggleStickers}
|
|
813
|
-
on={stickersOpen}
|
|
814
|
-
style={styles.segment}
|
|
815
|
-
styles={styles}
|
|
816
|
-
>
|
|
817
|
-
<Icon name="Smile" size={iconSize} color={theme.colors.foreground} />
|
|
818
|
-
</ChatButton>
|
|
819
|
-
<ActionButton
|
|
820
|
-
label="Send"
|
|
821
|
-
pendingLabel="Sending..."
|
|
822
|
-
onPress={send}
|
|
823
|
-
disabled={text.trim() === ""}
|
|
824
|
-
primary
|
|
988
|
+
</View>
|
|
989
|
+
)}
|
|
990
|
+
<View style={styles.messenger.conversationBody}>
|
|
991
|
+
<ScrollView
|
|
992
|
+
ref={scroller}
|
|
993
|
+
contentContainerStyle={styles.chatList}
|
|
994
|
+
onScroll={onScroll}
|
|
995
|
+
onContentSizeChange={followEnd}
|
|
996
|
+
onLayout={followEnd}
|
|
997
|
+
scrollEventThrottle={16}
|
|
998
|
+
keyboardShouldPersistTaps="handled"
|
|
999
|
+
>
|
|
1000
|
+
<Messages
|
|
1001
|
+
messages={shownMessages}
|
|
1002
|
+
emptyLabel={needle ? "No matching messages" : CHAT_EMPTY}
|
|
1003
|
+
firstUnread={needle ? undefined : firstUnread}
|
|
1004
|
+
agents={model.agents}
|
|
1005
|
+
problem={problem}
|
|
1006
|
+
always={touchScreen}
|
|
1007
|
+
link={link}
|
|
1008
|
+
run={run}
|
|
1009
|
+
onReply={setReplyTo}
|
|
825
1010
|
styles={styles}
|
|
826
1011
|
/>
|
|
1012
|
+
</ScrollView>
|
|
1013
|
+
{typing && <Text style={styles.chatTyping}>{typing}</Text>}
|
|
1014
|
+
<View style={styles.messenger.composer}>
|
|
1015
|
+
<ScrollView
|
|
1016
|
+
style={styles.messenger.composeOptions}
|
|
1017
|
+
contentContainerStyle={styles.messenger.composeOptionsBody}
|
|
1018
|
+
keyboardShouldPersistTaps="handled"
|
|
1019
|
+
nestedScrollEnabled
|
|
1020
|
+
>
|
|
1021
|
+
{replyTo === null ? null : (
|
|
1022
|
+
<ReplyBar
|
|
1023
|
+
message={replyTo}
|
|
1024
|
+
onClose={closeReply}
|
|
1025
|
+
iconSize={iconSize}
|
|
1026
|
+
color={theme.colors.foreground}
|
|
1027
|
+
styles={styles}
|
|
1028
|
+
/>
|
|
1029
|
+
)}
|
|
1030
|
+
<ComposeTools
|
|
1031
|
+
draft={draft}
|
|
1032
|
+
members={members}
|
|
1033
|
+
web={layout.platform === "web"}
|
|
1034
|
+
run={run}
|
|
1035
|
+
styles={styles}
|
|
1036
|
+
onBoard={onBoard}
|
|
1037
|
+
onDuties={onDuties}
|
|
1038
|
+
onNewAgent={onNewAgent}
|
|
1039
|
+
onGroupPhoto={onGroupPhoto}
|
|
1040
|
+
openSession={link.openSession}
|
|
1041
|
+
onUse={useQuick}
|
|
1042
|
+
insertMention={insertMention}
|
|
1043
|
+
setReading={setReading}
|
|
1044
|
+
stickersOpen={stickersOpen}
|
|
1045
|
+
toggleStickers={toggleStickers}
|
|
1046
|
+
/>
|
|
1047
|
+
{options.length > 0 ? (
|
|
1048
|
+
<MentionList options={options} onPick={pick} styles={styles} />
|
|
1049
|
+
) : null}
|
|
1050
|
+
{counter === null ? null : <Text style={styles.chatMeta}>{counter}</Text>}
|
|
1051
|
+
<PromptCoach draft={draft} styles={styles} />
|
|
1052
|
+
{stickersOpen ? <StickerTray onPick={sendSticker} styles={styles} /> : null}
|
|
1053
|
+
</ScrollView>
|
|
1054
|
+
<View style={styles.messenger.composerRow}>
|
|
1055
|
+
<TextInput
|
|
1056
|
+
ref={input}
|
|
1057
|
+
accessibilityLabel="Message"
|
|
1058
|
+
placeholder="Write a message"
|
|
1059
|
+
placeholderTextColor={styles.placeholderColor}
|
|
1060
|
+
value={text}
|
|
1061
|
+
onChangeText={setText}
|
|
1062
|
+
onKeyPress={onKeyPress}
|
|
1063
|
+
multiline
|
|
1064
|
+
maxLength={CHAT_TEXT_MAX}
|
|
1065
|
+
style={styles.messenger.field}
|
|
1066
|
+
/>
|
|
1067
|
+
<SendButton
|
|
1068
|
+
like={canLike(draft, reading)}
|
|
1069
|
+
canSend={canSend}
|
|
1070
|
+
send={send}
|
|
1071
|
+
sendLike={sendLike}
|
|
1072
|
+
styles={styles}
|
|
1073
|
+
color={theme.colors.accentForeground}
|
|
1074
|
+
muted={theme.colors.foregroundMuted}
|
|
1075
|
+
size={iconSize}
|
|
1076
|
+
/>
|
|
1077
|
+
</View>
|
|
1078
|
+
{error === null ? null : (
|
|
1079
|
+
<Text accessibilityRole="alert" style={styles.actionError}>
|
|
1080
|
+
{error}
|
|
1081
|
+
</Text>
|
|
1082
|
+
)}
|
|
827
1083
|
</View>
|
|
828
|
-
{stickersOpen ? <StickerTray onPick={sendSticker} styles={styles} /> : null}
|
|
829
1084
|
</View>
|
|
830
1085
|
</View>
|
|
831
1086
|
);
|