@celljs/ta-web 4.11.0 → 4.12.0

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.
Files changed (127) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/esm/browser/assistant/assistant-view.js +5 -2
  4. package/esm/browser/chat/chat-view.js +6 -5
  5. package/esm/browser/components/app-view.js +8 -4
  6. package/esm/browser/components/composer-box.d.ts +1 -0
  7. package/esm/browser/components/composer-box.js +50 -28
  8. package/esm/browser/components/composer.d.ts +3 -0
  9. package/esm/browser/components/composer.js +28 -2
  10. package/esm/browser/components/conversation-scroll-hooks.d.ts +16 -0
  11. package/esm/browser/components/conversation-scroll-hooks.js +98 -0
  12. package/esm/browser/components/conversation-scroll-util.d.ts +30 -0
  13. package/esm/browser/components/conversation-scroll-util.js +56 -0
  14. package/esm/browser/components/conversation-scroll.d.ts +45 -31
  15. package/esm/browser/components/conversation-scroll.js +125 -123
  16. package/esm/browser/components/face.d.ts +24 -0
  17. package/esm/browser/components/face.js +42 -0
  18. package/esm/browser/components/host-view.d.ts +1 -1
  19. package/esm/browser/components/media.js +59 -10
  20. package/esm/browser/components/message-actions.js +1 -0
  21. package/esm/browser/components/message-footer.d.ts +2 -0
  22. package/esm/browser/components/message-list.d.ts +3 -1
  23. package/esm/browser/components/message-list.js +55 -23
  24. package/esm/browser/components/phone-shell.js +2 -0
  25. package/esm/browser/components/session-view.d.ts +3 -1
  26. package/esm/browser/components/session-view.js +7 -3
  27. package/esm/browser/components/stop-times.d.ts +47 -0
  28. package/esm/browser/components/stop-times.js +81 -0
  29. package/esm/browser/components/use-stop-times.d.ts +3 -0
  30. package/esm/browser/components/use-stop-times.js +17 -0
  31. package/esm/browser/device/photo-picker.d.ts +14 -0
  32. package/esm/browser/device/photo-picker.js +48 -0
  33. package/esm/browser/device/row-swipe.d.ts +2 -0
  34. package/esm/browser/device/row-swipe.js +8 -2
  35. package/esm/browser/device/sheet-swipe.d.ts +1 -1
  36. package/esm/browser/device/sheet-swipe.js +17 -3
  37. package/esm/browser/extension/icons.js +2 -1
  38. package/esm/browser/extension/web-api-components.d.ts +18 -0
  39. package/esm/browser/extension/web-api-contributions.d.ts +9 -0
  40. package/esm/browser/extension/web-extension-api.d.ts +22 -2
  41. package/esm/browser/extension/web-extension-context.js +9 -1
  42. package/esm/browser/extension/web-extension-protocol.d.ts +13 -1
  43. package/esm/browser/extension/web-extension-protocol.js +1 -0
  44. package/esm/browser/extension/web-extensions.js +3 -0
  45. package/esm/browser/i18n/locales.d.ts +11 -1
  46. package/esm/browser/i18n/messages.d.ts +10 -0
  47. package/esm/browser/i18n/messages.js +20 -0
  48. package/esm/browser/links/links-protocol.d.ts +2 -0
  49. package/esm/browser/links/links.d.ts +7 -2
  50. package/esm/browser/links/links.js +16 -9
  51. package/esm/browser/style/conversation.d.ts +1 -1
  52. package/esm/browser/style/conversation.js +2 -0
  53. package/esm/browser/style/layout.d.ts +1 -1
  54. package/esm/browser/style/layout.js +3 -0
  55. package/esm/browser/style/pages.d.ts +1 -1
  56. package/esm/browser/style/pages.js +3 -0
  57. package/esm/browser/style/shell.d.ts +1 -1
  58. package/esm/browser/style/shell.js +2 -0
  59. package/esm/browser/style/surfaces.d.ts +1 -1
  60. package/esm/browser/style/surfaces.js +19 -0
  61. package/esm/browser/util/frame.d.ts +2 -0
  62. package/esm/browser/util/frame.js +2 -0
  63. package/esm/browser/util/process.d.ts +43 -1
  64. package/esm/browser/util/process.js +84 -3
  65. package/lib/browser/assistant/assistant-view.js +5 -2
  66. package/lib/browser/chat/chat-view.js +6 -5
  67. package/lib/browser/components/app-view.js +8 -4
  68. package/lib/browser/components/composer-box.d.ts +1 -0
  69. package/lib/browser/components/composer-box.js +48 -26
  70. package/lib/browser/components/composer.d.ts +3 -0
  71. package/lib/browser/components/composer.js +28 -2
  72. package/lib/browser/components/conversation-scroll-hooks.d.ts +17 -0
  73. package/lib/browser/components/conversation-scroll-hooks.js +135 -0
  74. package/lib/browser/components/conversation-scroll-util.d.ts +31 -0
  75. package/lib/browser/components/conversation-scroll-util.js +60 -0
  76. package/lib/browser/components/conversation-scroll.d.ts +45 -31
  77. package/lib/browser/components/conversation-scroll.js +126 -158
  78. package/lib/browser/components/face.d.ts +25 -0
  79. package/lib/browser/components/face.js +79 -0
  80. package/lib/browser/components/host-view.d.ts +1 -1
  81. package/lib/browser/components/media.js +59 -10
  82. package/lib/browser/components/message-actions.js +1 -0
  83. package/lib/browser/components/message-footer.d.ts +2 -0
  84. package/lib/browser/components/message-list.d.ts +3 -1
  85. package/lib/browser/components/message-list.js +53 -21
  86. package/lib/browser/components/phone-shell.js +2 -0
  87. package/lib/browser/components/session-view.d.ts +3 -1
  88. package/lib/browser/components/session-view.js +8 -4
  89. package/lib/browser/components/stop-times.d.ts +48 -0
  90. package/lib/browser/components/stop-times.js +85 -0
  91. package/lib/browser/components/use-stop-times.d.ts +4 -0
  92. package/lib/browser/components/use-stop-times.js +53 -0
  93. package/lib/browser/device/photo-picker.d.ts +15 -0
  94. package/lib/browser/device/photo-picker.js +51 -0
  95. package/lib/browser/device/row-swipe.d.ts +2 -0
  96. package/lib/browser/device/row-swipe.js +8 -2
  97. package/lib/browser/device/sheet-swipe.d.ts +1 -1
  98. package/lib/browser/device/sheet-swipe.js +17 -3
  99. package/lib/browser/extension/icons.js +1 -0
  100. package/lib/browser/extension/web-api-components.d.ts +18 -0
  101. package/lib/browser/extension/web-api-contributions.d.ts +9 -0
  102. package/lib/browser/extension/web-extension-api.d.ts +22 -2
  103. package/lib/browser/extension/web-extension-context.js +10 -2
  104. package/lib/browser/extension/web-extension-protocol.d.ts +13 -1
  105. package/lib/browser/extension/web-extension-protocol.js +1 -0
  106. package/lib/browser/extension/web-extensions.js +3 -0
  107. package/lib/browser/i18n/locales.d.ts +11 -1
  108. package/lib/browser/i18n/messages.d.ts +10 -0
  109. package/lib/browser/i18n/messages.js +20 -0
  110. package/lib/browser/links/links-protocol.d.ts +2 -0
  111. package/lib/browser/links/links.d.ts +7 -2
  112. package/lib/browser/links/links.js +16 -9
  113. package/lib/browser/style/conversation.d.ts +1 -1
  114. package/lib/browser/style/conversation.js +2 -0
  115. package/lib/browser/style/layout.d.ts +1 -1
  116. package/lib/browser/style/layout.js +3 -0
  117. package/lib/browser/style/pages.d.ts +1 -1
  118. package/lib/browser/style/pages.js +3 -0
  119. package/lib/browser/style/shell.d.ts +1 -1
  120. package/lib/browser/style/shell.js +2 -0
  121. package/lib/browser/style/surfaces.d.ts +1 -1
  122. package/lib/browser/style/surfaces.js +19 -0
  123. package/lib/browser/util/frame.d.ts +2 -0
  124. package/lib/browser/util/frame.js +2 -0
  125. package/lib/browser/util/process.d.ts +43 -1
  126. package/lib/browser/util/process.js +86 -4
  127. package/package.json +7 -7
@@ -72,6 +72,7 @@ const kept_pages_1 = require("./kept-pages");
72
72
  const launcher_surface_1 = require("./launcher-surface");
73
73
  const link_1 = require("./link");
74
74
  const link_dialog_1 = require("./link-dialog");
75
+ const list_skeleton_1 = require("./list-skeleton");
75
76
  const me_view_1 = require("./me-view");
76
77
  const media_1 = require("./media");
77
78
  const nav_places_1 = require("./nav-places");
@@ -197,7 +198,7 @@ function AppShell() {
197
198
  React.useEffect(() => {
198
199
  host.setSessionSwitcher(async (session, opening) => {
199
200
  // In front at once, while it opens.
200
- const shown = chat.show(session, opening);
201
+ const shown = typeof session === 'object' && 'sessionFile' in session ? chat.resume(session.sessionFile) : chat.show(session, opening);
201
202
  setNavOpen(false);
202
203
  setSurface(undefined);
203
204
  setSettings(undefined);
@@ -247,7 +248,9 @@ function AppShell() {
247
248
  const view = extensions.views.find(candidate => candidate.id === page && candidate.location === 'page');
248
249
  const sideViews = side_lists_1.SideListUtil.sidebarViews(extensions.views);
249
250
  const sideView = sideId === app_shell_hooks_1.FIRST_SIDE ? sideViews[0] : sideViews.find(candidate => candidate.id === sideId);
250
- const side = sideView ? sideView.id : '';
251
+ // The first start, nothing kept: the double's list may still come, rather than the chats shown a moment before it.
252
+ const sideComing = sideId === app_shell_hooks_1.FIRST_SIDE && !sideView && !extensions.loaded;
253
+ const side = sideView ? sideView.id : sideComing ? app_shell_hooks_1.FIRST_SIDE : '';
251
254
  const showPage = (id) => {
252
255
  host.showPage(id);
253
256
  setNavOpen(false);
@@ -428,6 +431,7 @@ function AppShell() {
428
431
  }
429
432
  };
430
433
  const chats = (React.createElement(assistant_chat_list_1.AssistantChatList, { sessions: workbench.sessions, saved: workbench.saved, removed: removedChats, archived: workbench.archived, onArchive: readArchived, foldDays: chatSettings.chatFoldDays, archiveDays: chatSettings.chatArchiveDays, selected: view || phone ? undefined : (pending !== null && pending !== void 0 ? pending : store === null || store === void 0 ? void 0 : store.sessionId), chat: chat, byDirectory: chatsByDirectory, onByDirectory: setChatsByDirectory, folded: foldedChats, onFolded: setFoldedChats, pinned: pinnedChats, onPinned: setPinnedChats, looking: looking, seen: seenChats, onPicked: picked }));
434
+ const sideList = sideView ? React.createElement(app_nav_1.SidebarView, { view: sideView }) : sideComing ? React.createElement(list_skeleton_1.ListSkeleton, null) : chats;
431
435
  const editorArea = (React.createElement(editor_area_1.EditorArea, { editors: extensions.editors, active: activeEditor, views: tools, onShow: id => host.showEditor(id), onClose: ids => void host.closeEditors(ids), onPin: id => host.pinEditor(id), onOpenView: openTool, onHide: editor.toggle, cwd: (_f = web_extension_protocol_1.WebCwdUtil.shown(extensions)) !== null && _f !== void 0 ? _f : (_c = workbench.server) === null || _c === void 0 ? void 0 : _c.cwd, maximized: maximized, onMaximize: () => setMaximized(!maximized) }));
432
436
  // A photo of the scan screen to the double: its conversation shows, the photo goes with what to do with it.
433
437
  const askDouble = async (text, image) => {
@@ -543,7 +547,7 @@ function AppShell() {
543
547
  }
544
548
  }, home: tabPage === 'me' ? (React.createElement("div", { className: "ta-main" },
545
549
  React.createElement(me_view_1.MeView, { onSettings: openSettings }))) : tabPage === 'discover' ? (React.createElement("div", { className: "ta-main" }, discoverView())) : tabView ? (React.createElement("div", { className: "ta-main" },
546
- React.createElement(app_nav_1.PageView, { view: tabView }))) : (React.createElement("div", { className: "ta-sidebar" }, sideView ? React.createElement(app_nav_1.SidebarView, { view: sideView }) : chats)), screen: React.createElement(React.Fragment, null,
550
+ React.createElement(app_nav_1.PageView, { view: tabView }))) : (React.createElement("div", { className: "ta-sidebar" }, sideList)), screen: React.createElement(React.Fragment, null,
547
551
  React.createElement(kept_pages_1.KeptPages, { views: extensions.views, kept: extensions.kept, shown: screenPage, render: page => (React.createElement(app_nav_1.PageView, { view: page, leading: React.createElement(icon_1.IconButton, { icon: lucide_react_1.ChevronLeft, label: t('ta.back'), className: "ta-narrow-only", onClick: closeScreen }) })) }),
548
552
  settings !== undefined ? (React.createElement(settings_view_1.SettingsView, { key: settingsOpened, section: settings || undefined, onClose: closeSettings, onBack: closeSettings })) : screenPage ? null : (React.createElement(chat_view_1.ChatView, { widgets: extensions.widgets, onMenu: closeScreen, back: true }))), screenOpen: screenOpen, onBack: closeScreen, workbench: editors && !settingsShown ? (React.createElement("div", { className: "ta-editors-pane", inert: !showEditors }, editorArea)) : undefined, workbenchOpen: showEditors, onWorkbench: open => (open ? toggleWorkbench() : showEditors && toggleRight()) }, overlays)) : (React.createElement("div", { className: classes.filter(Boolean).join(' '), style: sideWidths },
549
553
  navOpen && React.createElement("button", { type: "button", className: "ta-scrim", "aria-label": t('ta.close'), onClick: () => setNavOpen(false) }),
@@ -554,7 +558,7 @@ function AppShell() {
554
558
  setTabPage('discover');
555
559
  }, onSettings: openSettings, settingsShown: settings !== undefined, surfaces: surfaces, surface: surface, onSurface: setSurface, holds: holds }),
556
560
  sideShown && (React.createElement("div", { className: "ta-sidebar", style: (0, split_pane_1.paneStyle)(sidebar) },
557
- sideView ? React.createElement(app_nav_1.SidebarView, { view: sideView }) : chats,
561
+ sideList,
558
562
  React.createElement(split_pane_1.Sash, { pane: sidebar, side: "start", label: t('ta.layout.sidebar') })))),
559
563
  React.createElement("main", { className: "ta-main" },
560
564
  React.createElement(connection_bar_1.ConnectionBar, null),
@@ -45,6 +45,7 @@ export interface ComposerBoxProps {
45
45
  placeholder: string;
46
46
  /** Something runs: with nothing typed, the button stops it. */
47
47
  working?: boolean;
48
+ /** Stops it; the button spins from the press until `working` is false, or a promise it returns fails. */
48
49
  onStop?(): void;
49
50
  /** Sends; when it fails, what was sent comes back into the box. `followUp`: Alt+Enter. */
50
51
  onSend(message: string, images: ComposerImage[], followUp: boolean): Promise<unknown>;
@@ -40,6 +40,7 @@ const React = __importStar(require("react"));
40
40
  const device_1 = require("../device/device");
41
41
  const hold_1 = require("../device/hold");
42
42
  const long_press_1 = require("../device/long-press");
43
+ const photo_picker_1 = require("../device/photo-picker");
43
44
  const recent_shots_1 = require("../device/recent-shots");
44
45
  const use_t_1 = require("../i18n/use-t");
45
46
  const composer_1 = require("../util/composer");
@@ -96,6 +97,20 @@ exports.ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
96
97
  const [dragging, setDragging] = React.useState(false);
97
98
  const [menu, setMenu] = React.useState(false);
98
99
  const [listening, setListening] = React.useState(false);
100
+ // Stop pressed: the run may take a moment to end (a tool winding down), and the press must show at once.
101
+ const [stopping, setStopping] = React.useState(false);
102
+ React.useEffect(() => {
103
+ if (!working) {
104
+ setStopping(false);
105
+ }
106
+ }, [working]);
107
+ const stop = () => {
108
+ if (!onStop || stopping) {
109
+ return;
110
+ }
111
+ setStopping(true);
112
+ Promise.resolve(onStop()).catch(() => setStopping(false));
113
+ };
99
114
  const touch = (0, device_1.useDevice)(device => device.touch);
100
115
  // On a phone the + menu is a panel under the box, in place of the keyboard, as WeChat's.
101
116
  const handheld = (0, device_1.useDevice)(device => device.handheld);
@@ -107,6 +122,7 @@ exports.ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
107
122
  const [focused, setFocused] = React.useState(false);
108
123
  const input = React.useRef(null);
109
124
  const picker = React.useRef(null);
125
+ const camera = React.useRef(null);
110
126
  const plus = React.useRef(null);
111
127
  const panel = React.useRef(null);
112
128
  const menuId = React.useId();
@@ -401,6 +417,12 @@ exports.ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
401
417
  });
402
418
  }
403
419
  };
420
+ const onPicked = (event) => {
421
+ if (event.target.files) {
422
+ addFiles(event.target.files);
423
+ }
424
+ event.target.value = '';
425
+ };
404
426
  const onKeyDown = (event) => {
405
427
  var _a;
406
428
  const composing = event.nativeEvent.isComposing || event.keyCode === 229;
@@ -422,7 +444,7 @@ exports.ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
422
444
  }
423
445
  else if (event.key === 'Escape' && working && onStop) {
424
446
  event.preventDefault();
425
- onStop();
447
+ stop();
426
448
  }
427
449
  };
428
450
  const onPaste = (event) => {
@@ -446,20 +468,25 @@ exports.ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
446
468
  }
447
469
  };
448
470
  const own = [];
449
- if (takesImages) {
450
- own.push({
451
- key: 'image',
452
- label: t('ta.composer.addImage'),
453
- icon: React.createElement(icon_1.Icon, { icon: lucide_react_1.ImagePlus, size: 16 }),
454
- run: () => {
455
- var _a, _b, _c;
456
- // The Ta app on iOS asks for the photos here the first time, where the user is picking one anyway.
457
- if (recentShots) {
458
- (_b = (_a = recent_shots_1.RecentShots.source()) === null || _a === void 0 ? void 0 : _a.ask) === null || _b === void 0 ? void 0 : _b.call(_a);
459
- }
460
- (_c = picker.current) === null || _c === void 0 ? void 0 : _c.click();
461
- },
462
- });
471
+ const pickImages = () => {
472
+ var _a, _b, _c;
473
+ // The Ta app on iOS opens its library at once (and asks for the photos, for the screenshots, once picked).
474
+ if (photo_picker_1.PhotoPicker.available()) {
475
+ void photo_picker_1.PhotoPicker.pick(composer_1.MAX_IMAGES - attachments.length).then(files => files.length && addFiles(files));
476
+ return;
477
+ }
478
+ if (recentShots) {
479
+ (_b = (_a = recent_shots_1.RecentShots.source()) === null || _a === void 0 ? void 0 : _a.ask) === null || _b === void 0 ? void 0 : _b.call(_a);
480
+ }
481
+ (_c = picker.current) === null || _c === void 0 ? void 0 : _c.click();
482
+ };
483
+ if (takesImages && handheld && touch) {
484
+ // On a phone the album and the camera are two tiles, as WeChat's: each opens at once, without the menu of
485
+ // the system's file field (Photo Library, Take Photo, Choose File) in between.
486
+ own.push({ key: 'album', label: t('ta.composer.album'), icon: React.createElement(icon_1.Icon, { icon: lucide_react_1.Images, size: 16 }), run: pickImages }, { key: 'camera', label: t('ta.composer.camera'), icon: React.createElement(icon_1.Icon, { icon: lucide_react_1.Camera, size: 16 }), run: () => { var _a; return (_a = camera.current) === null || _a === void 0 ? void 0 : _a.click(); } });
487
+ }
488
+ else if (takesImages) {
489
+ own.push({ key: 'image', label: t('ta.composer.addImage'), icon: React.createElement(icon_1.Icon, { icon: lucide_react_1.ImagePlus, size: 16 }), run: pickImages });
463
490
  }
464
491
  if (mentionLabel) {
465
492
  own.push({ key: 'mention', label: mentionLabel, icon: React.createElement(icon_1.Icon, { icon: lucide_react_1.AtSign, size: 16 }), run: () => edit(...composer_1.ComposerUtil.insert(text, caret, '@')) });
@@ -498,12 +525,8 @@ exports.ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
498
525
  React.createElement(icon_1.IconButton, { icon: lucide_react_1.Plus, label: t('ta.composer.more'), className: `ta-attach ta-plus-button ${menu ? 'ta-on' : ''}`, onClick: toggleMenu }),
499
526
  menu && !handheld && React.createElement(plus_menu_1.PlusMenu, { sections: sections, onClose: closeMenu }),
500
527
  takesImages && recentShots && (React.createElement(recent_shot_1.RecentShotOffer, { box: box, activity: `${text}|${attachments.length}|${menu}|${talkMode}`, onPick: file => addFiles([file]) })))),
501
- takesImages && (React.createElement("input", { ref: picker, type: "file", accept: composer_1.IMAGE_TYPES.join(','), multiple: true, hidden: true, onChange: event => {
502
- if (event.target.files) {
503
- addFiles(event.target.files);
504
- }
505
- event.target.value = '';
506
- } })),
528
+ takesImages && React.createElement("input", { ref: picker, type: "file", accept: composer_1.IMAGE_TYPES.join(','), multiple: true, hidden: true, onChange: onPicked }),
529
+ takesImages && handheld && touch && React.createElement("input", { ref: camera, type: "file", accept: "image/*", capture: "environment", hidden: true, onChange: onPicked }),
507
530
  talkMode && React.createElement(voice_talk_1.TalkBar, { talk: talk }),
508
531
  React.createElement("textarea", { ref: input, hidden: talkMode, rows: 1, value: text, autoFocus: autoFocus, enterKeyHint: "send", "aria-label": t('ta.composer.label'), "aria-controls": items.length ? menuId : undefined, "aria-activedescendant": items.length ? `${menuId}-${selected}` : undefined, placeholder: listening ? t('ta.composer.listening') : placeholder, onChange: event => {
509
532
  setText(event.target.value);
@@ -518,16 +541,15 @@ exports.ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
518
541
  }, onBlur: () => setFocused(false) }),
519
542
  after,
520
543
  microphone,
521
- React.createElement("button", { type: "button", className: `ta-send ${action === 'stop' ? 'ta-send-stop' : ''}`, disabled: action === 'send' && (!sendable || reading), title: action === 'stop'
522
- ? t('ta.composer.stopTitle')
544
+ React.createElement("button", { type: "button", className: `ta-send ${action === 'stop' ? 'ta-send-stop' : ''} ${action === 'stop' && stopping ? 'ta-send-stopping' : ''}`, disabled: action === 'send' && (!sendable || reading), title: action === 'stop'
545
+ ? t(stopping ? 'ta.composer.stopping' : 'ta.composer.stopTitle')
523
546
  : reading
524
547
  ? t('ta.composer.imageLoading')
525
548
  : working
526
549
  ? t('ta.composer.steerTitle')
527
- : t('ta.send'), "aria-label": action === 'stop' ? t('ta.stop') : t('ta.send'),
550
+ : t('ta.send'), "aria-label": action === 'stop' ? t(stopping ? 'ta.composer.stopping' : 'ta.stop') : t('ta.send'), "aria-busy": action === 'stop' && stopping,
528
551
  // Pressed with the keyboard open, the box keeps the focus and the keyboard stays, as in WeChat.
529
- onPointerDown: event => document.activeElement === input.current && event.preventDefault(), onClick: () => (action === 'stop' ? onStop === null || onStop === void 0 ? void 0 : onStop() : send(false)) },
530
- React.createElement(icon_1.Icon, { icon: action === 'stop' ? lucide_react_1.Square : lucide_react_1.ArrowUp, size: action === 'stop' ? 14 : 18 })))),
552
+ onPointerDown: event => document.activeElement === input.current && event.preventDefault(), onClick: () => (action === 'stop' ? stop() : send(false)) }, action === 'stop' && stopping ? (React.createElement("span", { className: "ta-spinner" })) : (React.createElement(icon_1.Icon, { icon: action === 'stop' ? lucide_react_1.Square : lucide_react_1.ArrowUp, size: action === 'stop' ? 14 : 18 }))))),
531
553
  handheld && (menu || closing) && sections.length > 0 && (React.createElement(plus_menu_1.PlusMenu, { ref: panel, sections: sections, docked: true, closing: !menu, onClosed: () => setClosing(false), onClose: closeMenu }))));
532
554
  });
533
555
  //# sourceMappingURL=composer-box.js.map
@@ -4,6 +4,7 @@ import * as React from 'react';
4
4
  import { type ComposerImage } from '../util/composer';
5
5
  import { type ComposerAction, type ComposerBoxHandle } from './composer-box';
6
6
  import type { TalkPlace } from './held-talk';
7
+ import { type StopTiming } from './stop-times';
7
8
  export interface ComposerProps {
8
9
  /** The session it sends to; none for a new conversation, which sends with `onSubmit`. */
9
10
  store?: SessionStore;
@@ -38,6 +39,8 @@ export interface ComposerProps {
38
39
  onSending?(): void;
39
40
  /** Stops the work with no session yet (a new conversation still opening). */
40
41
  onStop?(): void;
42
+ /** A stop of the session's run pressed here ended (or failed): how long it took (useStopTimes). */
43
+ onStopTimed?(timing: StopTiming): void;
41
44
  onError(error: unknown): void;
42
45
  }
43
46
  /**
@@ -42,6 +42,7 @@ const use_t_1 = require("../i18n/use-t");
42
42
  const composer_1 = require("../util/composer");
43
43
  const composer_box_1 = require("./composer-box");
44
44
  const icon_1 = require("./icon");
45
+ const stop_times_1 = require("./stop-times");
45
46
  const FILE_LIMIT = 20;
46
47
  const FILE_DELAY_MS = 120;
47
48
  const EMPTY_QUEUE = { steering: [], followUp: [] };
@@ -93,7 +94,7 @@ function useQueue(store, working) {
93
94
  * and Alt+Enter queues a follow-up; Escape stops it.
94
95
  */
95
96
  exports.Composer = React.forwardRef(function Composer(props, ref) {
96
- const { store, onSubmit, head, after, voiceSends, recentShots, talkPlace, onTalkSent, onListening, server, workspace, working, commands, cwd, actions, placeholder, above, onSending, onStop, onError, } = props;
97
+ const { store, onSubmit, head, after, voiceSends, recentShots, talkPlace, onTalkSent, onListening, server, workspace, working, commands, cwd, actions, placeholder, above, onSending, onStop, onStopTimed, onError, } = props;
97
98
  // A finger: the keyboard opens on focus, over the conversation, and there are no keys to name.
98
99
  const touch = (0, device_1.useDevice)(device => device.touch);
99
100
  const t = (0, use_t_1.useT)();
@@ -104,7 +105,32 @@ exports.Composer = React.forwardRef(function Composer(props, ref) {
104
105
  const files = useFiles(workspace, cwd, query);
105
106
  const box = React.useRef(null);
106
107
  React.useImperativeHandle(ref, () => ({ text: () => { var _a; var _b; return (_b = (_a = box.current) === null || _a === void 0 ? void 0 : _a.text()) !== null && _b !== void 0 ? _b : ''; }, setText: text => { var _a; return (_a = box.current) === null || _a === void 0 ? void 0 : _a.setText(text); } }));
107
- const stop = () => (store ? server.abort(store.sessionId).catch(onError) : onStop === null || onStop === void 0 ? void 0 : onStop());
108
+ // The stop pressed, timed until the computer answered it and the run was seen ended.
109
+ const stopping = React.useRef(undefined);
110
+ const timed = (clock, timing) => {
111
+ if (timing) {
112
+ stopping.current = stopping.current === clock ? undefined : stopping.current;
113
+ onStopTimed === null || onStopTimed === void 0 ? void 0 : onStopTimed(timing);
114
+ }
115
+ };
116
+ React.useEffect(() => {
117
+ const clock = stopping.current;
118
+ if (!working && clock) {
119
+ timed(clock, clock.ended(performance.now()));
120
+ }
121
+ });
122
+ const stop = () => {
123
+ if (!store) {
124
+ return onStop === null || onStop === void 0 ? void 0 : onStop();
125
+ }
126
+ const clock = new stop_times_1.StopClock(performance.now(), Date.now());
127
+ stopping.current = clock;
128
+ return server.abort(store.sessionId).then(() => timed(clock, clock.answered(performance.now())), error => {
129
+ timed(clock, clock.answered(performance.now(), true));
130
+ onError(error);
131
+ throw error;
132
+ });
133
+ };
108
134
  const send = (message, images, followUp) => {
109
135
  var _a;
110
136
  onSending === null || onSending === void 0 ? void 0 : onSending();
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ export interface ConversationScrollOptions {
3
+ /** Where a message sent goes: to the top of the view with its answer under it (a conversation), or to the bottom (a group chat). */
4
+ sentTo?: 'top' | 'bottom';
5
+ /** Another key (another chat in the same view) goes to the bottom. */
6
+ key?: string;
7
+ }
8
+ /**
9
+ * The scrolling of a conversation (ConversationScroller), whose thread is the first child of the element of the
10
+ * returned ref. Opened, and when messages of the user go (a rewind), the view goes to the bottom.
11
+ *
12
+ * `asked`: how many messages of the user there are; the thread marks them with ASK_CLASS.
13
+ */
14
+ export declare function useConversationScroll(asked: number, options?: ConversationScrollOptions): React.RefObject<HTMLDivElement | null>;
15
+ /** Whether the conversation of `ref` is scrolled up from its latest, and a way back to it. */
16
+ export declare function useAwayFromBottom(ref: React.RefObject<HTMLDivElement | null>): [boolean, () => void];
17
+ //# sourceMappingURL=conversation-scroll-hooks.d.ts.map
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.useConversationScroll = useConversationScroll;
37
+ exports.useAwayFromBottom = useAwayFromBottom;
38
+ const React = __importStar(require("react"));
39
+ const conversation_scroll_1 = require("./conversation-scroll");
40
+ /**
41
+ * The scrolling of a conversation (ConversationScroller), whose thread is the first child of the element of the
42
+ * returned ref. Opened, and when messages of the user go (a rewind), the view goes to the bottom.
43
+ *
44
+ * `asked`: how many messages of the user there are; the thread marks them with ASK_CLASS.
45
+ */
46
+ function useConversationScroll(asked, options = {}) {
47
+ const { sentTo = 'top', key } = options;
48
+ const ref = React.useRef(null);
49
+ const attached = React.useRef(undefined);
50
+ const before = React.useRef(undefined);
51
+ // After each render, the view may only now be there (a page that shows it once its data came).
52
+ React.useLayoutEffect(() => {
53
+ var _a, _b;
54
+ const view = ref.current;
55
+ const thread = view === null || view === void 0 ? void 0 : view.firstElementChild;
56
+ if (((_a = attached.current) === null || _a === void 0 ? void 0 : _a.view) === view) {
57
+ return;
58
+ }
59
+ (_b = attached.current) === null || _b === void 0 ? void 0 : _b.detach();
60
+ attached.current = undefined;
61
+ if (view && thread instanceof HTMLElement) {
62
+ const scroller = new conversation_scroll_1.ConversationScroller(view, thread);
63
+ attached.current = { view, scroller, detach: scroller.attach(view, thread) };
64
+ }
65
+ });
66
+ React.useLayoutEffect(() => () => {
67
+ var _a;
68
+ (_a = attached.current) === null || _a === void 0 ? void 0 : _a.detach();
69
+ attached.current = undefined;
70
+ }, []);
71
+ React.useLayoutEffect(() => {
72
+ var _a, _b;
73
+ const previous = before.current;
74
+ before.current = { asked, key };
75
+ const current = (_a = attached.current) === null || _a === void 0 ? void 0 : _a.scroller;
76
+ const thread = (_b = ref.current) === null || _b === void 0 ? void 0 : _b.firstElementChild;
77
+ if (!current || !thread) {
78
+ return;
79
+ }
80
+ // One more: sent now. More at once is the conversation loaded again, which opens at its bottom.
81
+ const sent = previous !== undefined && previous.key === key && asked === previous.asked + 1;
82
+ const asks = sent && sentTo === 'top' ? thread.getElementsByClassName(conversation_scroll_1.ASK_CLASS) : undefined;
83
+ const message = asks === null || asks === void 0 ? void 0 : asks[asks.length - 1];
84
+ if (message) {
85
+ current.send(message);
86
+ }
87
+ else {
88
+ current.reset();
89
+ }
90
+ }, [asked, key, sentTo]);
91
+ return ref;
92
+ }
93
+ /** Away from the bottom by more than half of the view: the button back to the latest shows. */
94
+ const AWAY_SHARE = 0.5;
95
+ /** Lower than this (a phone held sideways, its keyboard open) the view has no room for the button. */
96
+ const AWAY_MIN_PX = 240;
97
+ /** Whether the conversation of `ref` is scrolled up from its latest, and a way back to it. */
98
+ function useAwayFromBottom(ref) {
99
+ const [away, setAway] = React.useState(false);
100
+ React.useEffect(() => {
101
+ const element = ref.current;
102
+ if (!element) {
103
+ return;
104
+ }
105
+ let frame = 0;
106
+ const measure = () => {
107
+ cancelAnimationFrame(frame);
108
+ frame = requestAnimationFrame(() => {
109
+ const { scrollHeight, scrollTop, clientHeight } = element;
110
+ setAway(clientHeight >= AWAY_MIN_PX && scrollHeight - scrollTop - clientHeight > clientHeight * AWAY_SHARE);
111
+ });
112
+ };
113
+ element.addEventListener('scroll', measure, { passive: true });
114
+ // The keyboard and a turn of the phone change the height of the view, not where it is.
115
+ const observer = typeof ResizeObserver !== 'undefined' ? new ResizeObserver(measure) : undefined;
116
+ observer === null || observer === void 0 ? void 0 : observer.observe(element);
117
+ return () => {
118
+ cancelAnimationFrame(frame);
119
+ observer === null || observer === void 0 ? void 0 : observer.disconnect();
120
+ element.removeEventListener('scroll', measure);
121
+ };
122
+ }, [ref]);
123
+ const back = React.useCallback(() => {
124
+ const element = ref.current;
125
+ const scroller = element ? conversation_scroll_1.ConversationScroller.of(element) : undefined;
126
+ if (scroller) {
127
+ scroller.toBottom();
128
+ }
129
+ else {
130
+ element === null || element === void 0 ? void 0 : element.scrollTo({ top: element.scrollHeight, behavior: (0, conversation_scroll_1.calm)() ? 'auto' : 'smooth' });
131
+ }
132
+ }, [ref]);
133
+ return [away, back];
134
+ }
135
+ //# sourceMappingURL=conversation-scroll-hooks.js.map
@@ -0,0 +1,31 @@
1
+ import type { FrameScheduler } from '../util/frame';
2
+ /** A row of the thread. */
3
+ export interface ScrollRow {
4
+ /** From the top of the thread. */
5
+ readonly offsetTop: number;
6
+ readonly offsetHeight: number;
7
+ readonly isConnected: boolean;
8
+ /** `scrollSkip`: SCROLL_SKIP. */
9
+ readonly dataset?: {
10
+ readonly scrollSkip?: string;
11
+ };
12
+ }
13
+ export declare namespace ScrollUtil {
14
+ /** The first of `rows` (in order, as laid out) in a view scrolled to `top`; past what says earlier rows load. */
15
+ function firstRow(rows: ArrayLike<ScrollRow>, top: number): ScrollRow | undefined;
16
+ }
17
+ /**
18
+ * A view gliding where it goes rather than jumping there: each frame it goes the share of the way left it would
19
+ * in that time by an exponential ease of GLIDE_MS, however often the end of the way moves (more coming in).
20
+ */
21
+ export declare class ScrollGlide {
22
+ private readonly frames;
23
+ private readonly now;
24
+ static readonly GLIDE_MS = 70;
25
+ private frame;
26
+ constructor(frames: FrameScheduler, now: () => number);
27
+ /** Gliding: `step` moves the view by the share of the way left it is given, each frame, until it answers false. */
28
+ start(step: (share: number) => boolean): void;
29
+ stop(): void;
30
+ }
31
+ //# sourceMappingURL=conversation-scroll-util.d.ts.map
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScrollGlide = exports.ScrollUtil = void 0;
4
+ var ScrollUtil;
5
+ (function (ScrollUtil) {
6
+ /** The first of `rows` (in order, as laid out) in a view scrolled to `top`; past what says earlier rows load. */
7
+ function firstRow(rows, top) {
8
+ var _a, _b;
9
+ let low = 0;
10
+ let high = rows.length - 1;
11
+ while (low < high) {
12
+ const middle = (low + high) >> 1;
13
+ const row = rows[middle];
14
+ if (row.offsetTop + row.offsetHeight > top) {
15
+ high = middle;
16
+ }
17
+ else {
18
+ low = middle + 1;
19
+ }
20
+ }
21
+ return ((_b = (_a = rows[low]) === null || _a === void 0 ? void 0 : _a.dataset) === null || _b === void 0 ? void 0 : _b.scrollSkip) !== undefined && low + 1 < rows.length ? rows[low + 1] : rows[low];
22
+ }
23
+ ScrollUtil.firstRow = firstRow;
24
+ })(ScrollUtil || (exports.ScrollUtil = ScrollUtil = {}));
25
+ /**
26
+ * A view gliding where it goes rather than jumping there: each frame it goes the share of the way left it would
27
+ * in that time by an exponential ease of GLIDE_MS, however often the end of the way moves (more coming in).
28
+ */
29
+ class ScrollGlide {
30
+ constructor(frames, now) {
31
+ this.frames = frames;
32
+ this.now = now;
33
+ }
34
+ /** Gliding: `step` moves the view by the share of the way left it is given, each frame, until it answers false. */
35
+ start(step) {
36
+ if (this.frame !== undefined) {
37
+ return;
38
+ }
39
+ let last = this.now();
40
+ const next = () => {
41
+ this.frame = undefined;
42
+ const now = this.now();
43
+ const share = 1 - Math.exp(-Math.max(1, now - last) / ScrollGlide.GLIDE_MS);
44
+ last = now;
45
+ if (step(share)) {
46
+ this.frame = this.frames.request(next);
47
+ }
48
+ };
49
+ this.frame = this.frames.request(next);
50
+ }
51
+ stop() {
52
+ if (this.frame !== undefined) {
53
+ this.frames.cancel(this.frame);
54
+ this.frame = undefined;
55
+ }
56
+ }
57
+ }
58
+ exports.ScrollGlide = ScrollGlide;
59
+ ScrollGlide.GLIDE_MS = 70;
60
+ //# sourceMappingURL=conversation-scroll-util.js.map