@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.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/esm/browser/assistant/assistant-view.js +5 -2
- package/esm/browser/chat/chat-view.js +6 -5
- package/esm/browser/components/app-view.js +8 -4
- package/esm/browser/components/composer-box.d.ts +1 -0
- package/esm/browser/components/composer-box.js +50 -28
- package/esm/browser/components/composer.d.ts +3 -0
- package/esm/browser/components/composer.js +28 -2
- package/esm/browser/components/conversation-scroll-hooks.d.ts +16 -0
- package/esm/browser/components/conversation-scroll-hooks.js +98 -0
- package/esm/browser/components/conversation-scroll-util.d.ts +30 -0
- package/esm/browser/components/conversation-scroll-util.js +56 -0
- package/esm/browser/components/conversation-scroll.d.ts +45 -31
- package/esm/browser/components/conversation-scroll.js +125 -123
- package/esm/browser/components/face.d.ts +24 -0
- package/esm/browser/components/face.js +42 -0
- package/esm/browser/components/host-view.d.ts +1 -1
- package/esm/browser/components/media.js +59 -10
- package/esm/browser/components/message-actions.js +1 -0
- package/esm/browser/components/message-footer.d.ts +2 -0
- package/esm/browser/components/message-list.d.ts +3 -1
- package/esm/browser/components/message-list.js +55 -23
- package/esm/browser/components/phone-shell.js +2 -0
- package/esm/browser/components/session-view.d.ts +3 -1
- package/esm/browser/components/session-view.js +7 -3
- package/esm/browser/components/stop-times.d.ts +47 -0
- package/esm/browser/components/stop-times.js +81 -0
- package/esm/browser/components/use-stop-times.d.ts +3 -0
- package/esm/browser/components/use-stop-times.js +17 -0
- package/esm/browser/device/photo-picker.d.ts +14 -0
- package/esm/browser/device/photo-picker.js +48 -0
- package/esm/browser/device/row-swipe.d.ts +2 -0
- package/esm/browser/device/row-swipe.js +8 -2
- package/esm/browser/device/sheet-swipe.d.ts +1 -1
- package/esm/browser/device/sheet-swipe.js +17 -3
- package/esm/browser/extension/icons.js +2 -1
- package/esm/browser/extension/web-api-components.d.ts +18 -0
- package/esm/browser/extension/web-api-contributions.d.ts +9 -0
- package/esm/browser/extension/web-extension-api.d.ts +22 -2
- package/esm/browser/extension/web-extension-context.js +9 -1
- package/esm/browser/extension/web-extension-protocol.d.ts +13 -1
- package/esm/browser/extension/web-extension-protocol.js +1 -0
- package/esm/browser/extension/web-extensions.js +3 -0
- package/esm/browser/i18n/locales.d.ts +11 -1
- package/esm/browser/i18n/messages.d.ts +10 -0
- package/esm/browser/i18n/messages.js +20 -0
- package/esm/browser/links/links-protocol.d.ts +2 -0
- package/esm/browser/links/links.d.ts +7 -2
- package/esm/browser/links/links.js +16 -9
- package/esm/browser/style/conversation.d.ts +1 -1
- package/esm/browser/style/conversation.js +2 -0
- package/esm/browser/style/layout.d.ts +1 -1
- package/esm/browser/style/layout.js +3 -0
- package/esm/browser/style/pages.d.ts +1 -1
- package/esm/browser/style/pages.js +3 -0
- package/esm/browser/style/shell.d.ts +1 -1
- package/esm/browser/style/shell.js +2 -0
- package/esm/browser/style/surfaces.d.ts +1 -1
- package/esm/browser/style/surfaces.js +19 -0
- package/esm/browser/util/frame.d.ts +2 -0
- package/esm/browser/util/frame.js +2 -0
- package/esm/browser/util/process.d.ts +43 -1
- package/esm/browser/util/process.js +84 -3
- package/lib/browser/assistant/assistant-view.js +5 -2
- package/lib/browser/chat/chat-view.js +6 -5
- package/lib/browser/components/app-view.js +8 -4
- package/lib/browser/components/composer-box.d.ts +1 -0
- package/lib/browser/components/composer-box.js +48 -26
- package/lib/browser/components/composer.d.ts +3 -0
- package/lib/browser/components/composer.js +28 -2
- package/lib/browser/components/conversation-scroll-hooks.d.ts +17 -0
- package/lib/browser/components/conversation-scroll-hooks.js +135 -0
- package/lib/browser/components/conversation-scroll-util.d.ts +31 -0
- package/lib/browser/components/conversation-scroll-util.js +60 -0
- package/lib/browser/components/conversation-scroll.d.ts +45 -31
- package/lib/browser/components/conversation-scroll.js +126 -158
- package/lib/browser/components/face.d.ts +25 -0
- package/lib/browser/components/face.js +79 -0
- package/lib/browser/components/host-view.d.ts +1 -1
- package/lib/browser/components/media.js +59 -10
- package/lib/browser/components/message-actions.js +1 -0
- package/lib/browser/components/message-footer.d.ts +2 -0
- package/lib/browser/components/message-list.d.ts +3 -1
- package/lib/browser/components/message-list.js +53 -21
- package/lib/browser/components/phone-shell.js +2 -0
- package/lib/browser/components/session-view.d.ts +3 -1
- package/lib/browser/components/session-view.js +8 -4
- package/lib/browser/components/stop-times.d.ts +48 -0
- package/lib/browser/components/stop-times.js +85 -0
- package/lib/browser/components/use-stop-times.d.ts +4 -0
- package/lib/browser/components/use-stop-times.js +53 -0
- package/lib/browser/device/photo-picker.d.ts +15 -0
- package/lib/browser/device/photo-picker.js +51 -0
- package/lib/browser/device/row-swipe.d.ts +2 -0
- package/lib/browser/device/row-swipe.js +8 -2
- package/lib/browser/device/sheet-swipe.d.ts +1 -1
- package/lib/browser/device/sheet-swipe.js +17 -3
- package/lib/browser/extension/icons.js +1 -0
- package/lib/browser/extension/web-api-components.d.ts +18 -0
- package/lib/browser/extension/web-api-contributions.d.ts +9 -0
- package/lib/browser/extension/web-extension-api.d.ts +22 -2
- package/lib/browser/extension/web-extension-context.js +10 -2
- package/lib/browser/extension/web-extension-protocol.d.ts +13 -1
- package/lib/browser/extension/web-extension-protocol.js +1 -0
- package/lib/browser/extension/web-extensions.js +3 -0
- package/lib/browser/i18n/locales.d.ts +11 -1
- package/lib/browser/i18n/messages.d.ts +10 -0
- package/lib/browser/i18n/messages.js +20 -0
- package/lib/browser/links/links-protocol.d.ts +2 -0
- package/lib/browser/links/links.d.ts +7 -2
- package/lib/browser/links/links.js +16 -9
- package/lib/browser/style/conversation.d.ts +1 -1
- package/lib/browser/style/conversation.js +2 -0
- package/lib/browser/style/layout.d.ts +1 -1
- package/lib/browser/style/layout.js +3 -0
- package/lib/browser/style/pages.d.ts +1 -1
- package/lib/browser/style/pages.js +3 -0
- package/lib/browser/style/shell.d.ts +1 -1
- package/lib/browser/style/shell.js +2 -0
- package/lib/browser/style/surfaces.d.ts +1 -1
- package/lib/browser/style/surfaces.js +19 -0
- package/lib/browser/util/frame.d.ts +2 -0
- package/lib/browser/util/frame.js +2 -0
- package/lib/browser/util/process.d.ts +43 -1
- package/lib/browser/util/process.js +86 -4
- package/package.json +7 -7
package/README.en.md
CHANGED
|
@@ -23,7 +23,7 @@ Initially, the interface shows only conversations. You tell Ta what you want thi
|
|
|
23
23
|
Everything new in the interface comes from **web extensions** within packages, using the same mechanism and terminology as pi extensions:
|
|
24
24
|
|
|
25
25
|
- **Packages** are pi packages. In the `pi` field of `package.json`, `extensions` are extensions for Ta (terminal and server), and `web` are extensions for this page; when not declared, modules in the `web/` directory are used. Packages can be placed in `~/.ta/agent/extensions/<name>/` or the project's `.ta/extensions/` to take effect, or installed with `ta install`.
|
|
26
|
-
- **Web extensions** are ES modules without import statements, with a default export of a function that the page calls with `pi`; the returned function is called on unload. The `pi` interface follows pi's ExtensionAPI naming: `ui.setWidget` (default above the input box, same as pi; `placement: 'panel'` puts it in the right workbench's card tabs), `registerView` (pages in the navigation bar, or a list of the sidebar at the top of the navigation bar; `location: 'panel'` is a tool in the right workbench; `discover: true` keeps a page not used every day under Discover until the user pins it), `registerMessageRenderer` (displays custom messages sent by pi extensions with `sendMessage`), `registerCodeRenderer` (draws the fenced blocks of a language in replies and in `ui.Markdown` as a card of the extension's own; the component gets `{ code, language, closed }`, `closed` false while the block streams, and a renderer that throws shows the block as code, as the `ta-glance` cards of `@celljs/ta-glance`), `registerTool` (tools executed by the browser in conversations opened on the page), `registerToolRenderer` (as pi's, a resolver `(toolName, next) => renderer` that chooses how calls of any tool read in conversations: `renderCall(args)` gives a verb, a target and a small icon in the language of the page, in place of the tool's name; `next()` is what the resolvers after it would use), `registerSettings` (a section of the settings, after those of Ta: rows of a label, a description and a control the extension draws, the values kept with `storage`), `registerTasks` / `ui.useTasks` (work done for the user, listed by the double with its own tasks and those of other extensions; see docs/design/ta-double.md. A task with `remove` and `removeHint` can be swiped away in the lists, or selected with others and deleted at once; `ui.removeTasks` asks the user), `ui.SelectCheck` / `ui.SelectBar` (the round mark at the start of a row and the bar under a list while it selects several, as the lists of the page), `registerOpener` (opens links in replies: files and their lines, directories, web pages, asked in registration order, returns true if opened), `registerComposerAddon` (adds to the message box of every conversation: `actions(conversation)` are entries of the + menu, each a tile of its grid (four by two a page, more a page to swipe to): `setting: true` shows its value (`detail`) under its label, `toggle: true` is a switch (`checked` is on, its icon lit; turning it leaves the menu open), and entries may have `items`, a list in its place; `above` is drawn above the box; `subscribe` says the entries changed. `conversation` says which: `sessionId`, `sessionFile`, `cwd`, `kind` `double` or `chat`, `group`, `title`; the double, agents and plain conversations all have it), `ui.Game3D` (a 3D game on Three.js: `setup(context)` gets a renderer, a scene, a camera and OrbitControls, fills the scene and returns what to do each frame; loaded, asleep and ended as `ui.Game`, its scene and WebGL context given back at the end), `ui.FullScreen` (covers all of the page: the shell, its head and side columns under it, under the notch and the home bar, below the title bar of the desktop app and above the keyboard; its touches are all its own, an edge brings out no panel of Ta; for a game held sideways or a world to walk in, `??` back to its place in an app older than it), `data-own-gestures` (an attribute of an element whose touches are its own: the slides of Ta start there only from an edge of the screen, a held finger opens no menu; games carry it), `ui.Game` (a game on Phaser 4, the game engine of the page, loaded when the first game starts; it fills its parent, sleeps while out of sight and ends when it unmounts, takes the keyboard only while it has the focus, and finds the colors of the theme in its registry; see docs/design/ta-games.md), `ui.QrCode` (a QR code of a text, black on white whatever the theme), `ui.ImageViewer` (a picture to look at closely: all of it at first and never larger than its own pixels, pinched with two fingers or a trackpad, zoomed with Ctrl/⌘ and the wheel or a double click or tap, dragged or scrolled once zoomed, with − / the scale / + / fit to window / actual size below it, and given `onPrevious` / `onNext` the pictures beside it by buttons at its sides and, unless zoomed, ← →; the previews of pictures in the workbench and the large pictures of a conversation are this), `on` (events of the current conversation), `sendUserMessage` (sends to the current conversation; a `/command` runs a command of a pi extension), `switchSession` (shows another session open in ta serve as the current conversation; given a Promise of the session id it switches at once and shows "Opening", `opening` giving the title meanwhile), `callHost` (calls a method of the package's `pi.host`, through `callPackageHost`), `reloadExtensions` (after an extension installed, imported or removed packages itself, reloads the web extensions and the pi extensions of the current conversation as at the end of a reply), `ui.showView` / `ui.useView` (shows and reads any extension's view), `ui.Composer` / `ui.Markdown` (the message box and the Markdown of the conversations, the microphone and the hold to talk too; with `commands`, `/` lists the commands a new conversation in `cwd` will have; `voiceSends`, `onTalkSent`, `onListening`, `working` / `onStop` and `after` are those of the double's box: what is heard is sent at once, the page knows what was said by voice to read its answer aloud, that the user talks now, the send button stops what answers, buttons of its own on the right), `ui.HoldToTalk` (a button held to talk, as the bar of the message box: the page dims and listens with its recognizer, 取消 and 编辑 to slide onto, the words given as the finger lets go; nothing where the page cannot listen), `ui.voice` (`canListen` / `canSpeak` / `speak` / `hush`: read aloud in the voice of the settings), the `send` of a view (a page that is a conversation takes a message from another extension as if typed in its box; the double's page has it, its answer comes as its `preview`), `ui.useChatScroll` (scrolls as the conversations: at the bottom it follows new messages, scrolled up it is never pulled back and what is read does not jump, a part opened by a click stays where it was; `sent` is how many messages the user sent, one more of which goes to the bottom), `ui.Empty` (what a list or a view shows while empty: a title and at most one line of hint, centred in its space; `compact` in menus, pickers and dialogs; `picture` puts a picture above), `ui.Picture` / `ui.PictureCards` (small pictures as those of Ta: the shapes of an SVG take the classes `ta-pic-*` and follow the theme; a row of picture cards to click, with a label and a line of description), `ui.Dialog` (a dialog over the page), `preview` of `ui.openEditor` (a preview tab opened by a click, its title in italics, replaced by the next preview, kept by a double click or `ui.pinEditor`), `ui.setEditorDirty` (the tab shows an unsaved dot and asks before closing), `ui.useActiveEditor` (the current tab of the workbench), `ui.DiffEditor` (Monaco's diff editor, side by side or inline, the right side editable), `confirmLabel` / `danger` of `ui.confirm`, `head` of a view (a top bar of its own), `ui.input` / `ui.editor` (asks the user for a line or lines of text, `undefined` when cancelled), the page's `menu` (floating … menu when the page is listed in sidebar) and `pages` (pages listed in sidebar, navigation bar no longer lists them separately), `ui.notify` (notifications in bottom right of page), `ui.notifySession` (tells the user what a conversation said, as a messenger does: nothing while they look at it, nothing of a task the double follows unless it asks; nothing that pops up on a phone or a tablet, the unread dots of the list and of the Chats tab telling; on a computer in front, a banner with the face and name of the conversation, a tap opening it, its `options` buttons that send that answer once from whichever page; a notice of the system while it is not, silent for an answer; without those, a banner that waits for the user when it asks or failed), `ui.confirm` (confirm before continuing, returns whether user agreed), `ui.theme`, `ui.language`, `ui.supportsWebview` (whether a view can show a site in a `<webview>`, as in Ta Desktop, rather than an iframe), `ui.debugWebview` (Ta Desktop: a command of the Chrome DevTools Protocol to the page of such a webview, limited to the page itself), `ui.desktop.browserData` (Ta Desktop on macOS and Windows: the cookies of a profile of the user's browser taken into the browser of Ta once the user says yes in a dialog of the app, and clearing that browser's data), and page services: `server` (session, pi's RPC commands), `workspace` (files and commands in directory), `terminals` (terminals), `packages` (packages) (types see `WebExtensionAPI`).
|
|
26
|
+
- **Web extensions** are ES modules without import statements, with a default export of a function that the page calls with `pi`; the returned function is called on unload. The `pi` interface follows pi's ExtensionAPI naming: `ui.setWidget` (default above the input box, same as pi; `placement: 'panel'` puts it in the right workbench's card tabs), `registerView` (pages in the navigation bar, or a list of the sidebar at the top of the navigation bar; `location: 'panel'` is a tool in the right workbench; `discover: true` keeps a page not used every day under Discover until the user pins it), `registerMessageRenderer` (displays custom messages sent by pi extensions with `sendMessage`), `registerCodeRenderer` (draws the fenced blocks of a language in replies and in `ui.Markdown` as a card of the extension's own; the component gets `{ code, language, closed }`, `closed` false while the block streams, and a renderer that throws shows the block as code, as the `ta-glance` cards of `@celljs/ta-glance`), `registerTool` (tools executed by the browser in conversations opened on the page), `registerToolRenderer` (as pi's, a resolver `(toolName, next) => renderer` that chooses how calls of any tool read in conversations: `renderCall(args)` gives a verb, a target and a small icon in the language of the page, in place of the tool's name; `next()` is what the resolvers after it would use), `registerSettings` (a section of the settings, after those of Ta: rows of a label, a description and a control the extension draws, the values kept with `storage`), `registerTasks` / `ui.useTasks` (work done for the user, listed by the double with its own tasks and those of other extensions; see docs/design/ta-double.md. A task with `remove` and `removeHint` can be swiped away in the lists, or selected with others and deleted at once; `ui.removeTasks` asks the user), `ui.SelectCheck` / `ui.SelectBar` (the round mark at the start of a row and the bar under a list while it selects several, as the lists of the page), `registerOpener` (opens links in replies: files and their lines, directories, web pages, asked in registration order, returns true if opened), `registerComposerAddon` (adds to the message box of every conversation: `actions(conversation)` are entries of the + menu, each a tile of its grid (four by two a page, more a page to swipe to): `setting: true` shows its value (`detail`) under its label, `toggle: true` is a switch (`checked` is on, its icon lit; turning it leaves the menu open), and entries may have `items`, a list in its place; `above` is drawn above the box; `subscribe` says the entries changed. `conversation` says which: `sessionId`, `sessionFile`, `cwd`, `kind` `double` or `chat`, `group`, `title`; the double, agents and plain conversations all have it), `ui.Game3D` (a 3D game on Three.js: `setup(context)` gets a renderer, a scene, a camera and OrbitControls, fills the scene and returns what to do each frame; loaded, asleep and ended as `ui.Game`, its scene and WebGL context given back at the end), `ui.FullScreen` (covers all of the page: the shell, its head and side columns under it, under the notch and the home bar, below the title bar of the desktop app and above the keyboard; its touches are all its own, an edge brings out no panel of Ta; for a game held sideways or a world to walk in, `??` back to its place in an app older than it), `data-own-gestures` (an attribute of an element whose touches are its own: the slides of Ta start there only from an edge of the screen, a held finger opens no menu; games carry it), `ui.Game` (a game on Phaser 4, the game engine of the page, loaded when the first game starts; it fills its parent, sleeps while out of sight and ends when it unmounts, takes the keyboard only while it has the focus, and finds the colors of the theme in its registry; see docs/design/ta-games.md), `ui.QrCode` (a QR code of a text, black on white whatever the theme), `ui.ImageViewer` (a picture to look at closely: all of it at first and never larger than its own pixels, pinched with two fingers or a trackpad, zoomed with Ctrl/⌘ and the wheel or a double click or tap, dragged or scrolled once zoomed, with − / the scale / + / fit to window / actual size below it, and given `onPrevious` / `onNext` the pictures beside it by buttons at its sides and, unless zoomed, ← →; the previews of pictures in the workbench and the large pictures of a conversation are this), `on` (events of the current conversation), `sendUserMessage` (sends to the current conversation; a `/command` runs a command of a pi extension), `switchSession` (shows another session open in ta serve as the current conversation; given a Promise of the session id it switches at once and shows "Opening", `opening` giving the title meanwhile), `openChat` (opens the conversation of a session file as the lists do: at once from what the page or the device has, opened again in one round trip when it closed; false when no conversation has it), `callHost` (calls a method of the package's `pi.host`, through `callPackageHost`), `reloadExtensions` (after an extension installed, imported or removed packages itself, reloads the web extensions and the pi extensions of the current conversation as at the end of a reply), `ui.showView` / `ui.useView` (shows and reads any extension's view), `ui.Composer` / `ui.Markdown` (the message box and the Markdown of the conversations, the microphone and the hold to talk too; with `commands`, `/` lists the commands a new conversation in `cwd` will have; `voiceSends`, `onTalkSent`, `onListening`, `working` / `onStop` and `after` are those of the double's box: what is heard is sent at once, the page knows what was said by voice to read its answer aloud, that the user talks now, the send button stops what answers, buttons of its own on the right), `ui.HoldToTalk` (a button held to talk, as the bar of the message box: the page dims and listens with its recognizer, 取消 and 编辑 to slide onto, the words given as the finger lets go; nothing where the page cannot listen), `ui.voice` (`canListen` / `canSpeak` / `speak` / `hush`: read aloud in the voice of the settings), the `send` of a view (a page that is a conversation takes a message from another extension as if typed in its box; the double's page has it, its answer comes as its `preview`), `ui.useChatScroll` (scrolls as the conversations: at the bottom it follows new messages, scrolled up it is never pulled back and what is read does not jump, a part opened by a click stays where it was; `sent` is how many messages the user sent, one more of which goes to the bottom), `ui.Empty` (what a list or a view shows while empty: a title and at most one line of hint, centred in its space; `compact` in menus, pickers and dialogs; `picture` puts a picture above), `ui.Picture` / `ui.PictureCards` (small pictures as those of Ta: the shapes of an SVG take the classes `ta-pic-*` and follow the theme; a row of picture cards to click, with a label and a line of description), `ui.Dialog` (a dialog over the page), `preview` of `ui.openEditor` (a preview tab opened by a click, its title in italics, replaced by the next preview, kept by a double click or `ui.pinEditor`), `ui.setEditorDirty` (the tab shows an unsaved dot and asks before closing), `ui.useActiveEditor` (the current tab of the workbench), `ui.DiffEditor` (Monaco's diff editor, side by side or inline, the right side editable), `confirmLabel` / `danger` of `ui.confirm`, `head` of a view (a top bar of its own), `ui.input` / `ui.editor` (asks the user for a line or lines of text, `undefined` when cancelled), the page's `menu` (floating … menu when the page is listed in sidebar) and `pages` (pages listed in sidebar, navigation bar no longer lists them separately), `ui.notify` (notifications in bottom right of page), `ui.notifySession` (tells the user what a conversation said, as a messenger does: nothing while they look at it, nothing of a task the double follows unless it asks; nothing that pops up on a phone or a tablet, the unread dots of the list and of the Chats tab telling; on a computer in front, a banner with the face and name of the conversation, a tap opening it, its `options` buttons that send that answer once from whichever page; a notice of the system while it is not, silent for an answer; without those, a banner that waits for the user when it asks or failed), `ui.confirm` (confirm before continuing, returns whether user agreed), `ui.theme`, `ui.language`, `ui.supportsWebview` (whether a view can show a site in a `<webview>`, as in Ta Desktop, rather than an iframe), `ui.debugWebview` (Ta Desktop: a command of the Chrome DevTools Protocol to the page of such a webview, limited to the page itself), `ui.desktop.browserData` (Ta Desktop on macOS and Windows: the cookies of a profile of the user's browser taken into the browser of Ta once the user says yes in a dialog of the app, and clearing that browser's data), and page services: `server` (session, pi's RPC commands), `workspace` (files and commands in directory), `terminals` (terminals), `packages` (packages) (types see `WebExtensionAPI`).
|
|
27
27
|
- **The bytes of files**: `pi.files` gives the bytes of a file of the workspace. When the page is served by ta serve itself, `byUrl` is true and the URL of `workspace.fileUrl` loads as it is; in the app on a phone, or when the page is opened through a relay, that URL is not there to load, `byUrl` is false, and `pi.files.read(url)` gives `{ type, size, data }` over the WebSocket (sealed end to end: the relay reads none of it). The previews of @celljs/ta-workspace are built on it: pictures, videos, sounds and PDFs as `blob:` URLs, an HTML report from the text of the file in a sandboxed frame.
|
|
28
28
|
- **Make packages with natural language**: the built-in extension [@celljs/ta-extensions](../ta-extensions/README.md) includes the skill `ta-package` (also available in the Ta terminal) and adds an "Extensions" page in the navigation bar (create an extension in one sentence, export or import). It documents package format, the web extension interface, and validation steps. At the end of each reply in the current conversation, the page reloads web extensions: new ones load, changed ones reload, and deleted ones unload; when tools change, the conversation reopens that part in the same session file (only for conversations opened on this page); when packages change, the session reloads pi extensions. The page checks again when redisplayed (packages might change in the terminal too).
|
|
29
29
|
- **Stable**: each extension owns what it registers and removes it all on unload; if one extension fails to load or render, only that extension's area shows an error, without affecting the page or other extensions.
|
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ Web 客户端可以装成桌面或手机上的应用:Chrome / Edge 地址栏
|
|
|
23
23
|
界面上新增的一切都来自包里的 **Web 扩展**,和 pi 的扩展同一套机制、同一套叫法:
|
|
24
24
|
|
|
25
25
|
- **包**就是 pi 的包。`package.json` 的 `pi` 里,`extensions` 是给 Ta(终端和服务端)的扩展,`web` 是给这个页面的扩展;没有声明时取 `web/` 目录下的模块。包放在 `~/.ta/agent/extensions/<名字>/`(项目的 `.ta/extensions/`)即可生效,也可以用 `ta install` 安装。
|
|
26
|
-
- **Web 扩展**是一个不带 import 的 ES 模块,默认导出一个函数,页面用 `pi` 调用它;返回的函数在卸载时调用。`pi` 的接口照 pi 的 ExtensionAPI 命名:`ui.setWidget`(默认在输入框上方,和 pi 一样;`placement: 'panel'` 放进右侧工作台的卡片标签)、`registerView`(导航栏里的页面,或导航栏上方的一个侧栏列表;`location: 'panel'` 是右侧工作台的工具)、`registerMessageRenderer`(显示 pi 扩展用 `sendMessage` 发出的自定义消息)、`registerCodeRenderer`(把回复和 `ui.Markdown` 里某种语言的代码块画成扩展自己的卡片,组件拿到 `{ code, language, closed }`,流式时 `closed` 为假;抛错时显示为代码,如 `@celljs/ta-glance` 的 `ta-glance` 卡片)、`registerTool`(页面打开的对话里由浏览器执行的工具)、`registerToolRenderer`(照 pi 的同名接口传一个 resolver `(toolName, next) => renderer`,决定任意工具的调用在对话里怎么读:`renderCall(args)` 给出页面语言的动词、对象和可选的小图标,代替工具名;`next()` 是后面的 resolver 的结果)、`registerSettings`(设置里的一个分区,排在 Ta 自己的分区之后:每行是标签、说明和扩展自己画的控件,值用 `storage` 保存)、`registerTasks` / `ui.useTasks`(替用户做的事,由分身和其他扩展的任务一起列出,见 docs/design/ta-double.md;任务带 `remove` 和 `removeHint` 时,列表里可以左滑删除、多选后批量删除,询问统一由 `ui.removeTasks` 做)、`ui.SelectCheck` / `ui.SelectBar`(列表多选时行首的圆形勾选和列表底部的操作栏,样式与页面一致)、`registerOpener`(打开回复里的链接:文件及其行、目录、网页,按注册顺序询问,返回 true 表示已打开)、`registerComposerAddon`(给所有对话的输入框加东西:`actions(conversation)` 是 + 菜单里的条目,每个都是一个图标方块(每页 4×2,多了左右滑动翻页):`setting: true` 在名字下显示当前值(`detail`),`toggle: true` 是开关(`checked` 表示开着,图标点亮,点了不关菜单),条目可以带 `items` 二级列表;`above` 画在输入框上方;`subscribe` 通知条目变了。`conversation` 说明是哪个对话:`sessionId`、`sessionFile`、`cwd`、`kind` 为 `double` 或 `chat`、`group`、`title`;分身、智能体和普通对话都有)、`ui.Game3D`(Three.js 3D 游戏:`setup(context)` 拿到渲染器、场景、相机和 OrbitControls,往场景里放东西并返回每帧要做的事;同样懒加载、休眠、卸载时释放场景和 WebGL 上下文)、`ui.FullScreen`(盖住整个页面:外壳、它的顶栏和侧栏都在下面,铺到刘海和底部横条下,在桌面版标题栏之下、键盘之上;触摸全归它,屏幕边缘也不会拉出 Ta 的面板;给横屏游戏、能走进去的世界用,旧版 App 没有它时用 `??` 退回原处显示)、`data-own-gestures`(元素上的属性:从它开始的触摸归它,Ta 的滑动只从屏幕边缘开始,长按不出菜单;游戏自动带上)、`ui.Game`(Phaser 4 游戏:页面自带的游戏引擎,第一次开始游戏时才加载;填满父元素,看不见时休眠,卸载时销毁,键盘只在游戏获得焦点时归它,主题颜色放在游戏的 registry 里,见 docs/design/ta-games.md)、`ui.QrCode`(文字的二维码,任何主题下都是白底黑码)、`ui.ImageViewer`(看图:先完整显示且不超过原始像素,双指或触控板捏合、Ctrl/⌘ 加滚轮、双击或双点缩放,放大后拖动或滚动,底部是 − / 比例 / + / 适应窗口 / 实际大小;给了 `onPrevious` / `onNext` 时两侧有上一张、下一张按钮,未放大时 ← → 也能切换;工作台的图片预览和对话里的大图用的都是它)、`on`(当前对话的事件)、`sendUserMessage`(发到当前对话;`/命令` 会执行 pi 扩展的命令)、`switchSession`(把 ta serve 里另一个打开的会话显示为当前对话;传会话 id 的 Promise 时立即切过去显示"正在打开",`opening` 给出占位的标题)、`callHost`(调用本包 `pi.host` 的方法,经 `callPackageHost`)、`reloadExtensions`(扩展自己安装、导入或移除了包之后,像回复结束时一样重新加载 Web 扩展和当前对话的 pi 扩展)、`ui.showView` / `ui.useView`(显示、查看任意扩展的视图)、`ui.Composer` / `ui.Markdown`(和对话一样的输入框与 Markdown,麦克风和按住说话也一样;输入框的 `commands` 让 `/` 列出在 `cwd` 新开对话时会有的命令,`voiceSends`、`onTalkSent`、`onListening`、`working` / `onStop`、`after` 和分身的输入框一样:听到的话直接发出、知道哪句是说的以便朗读回答、正在听、正在回答时发送键变成停止、右侧放自己的按钮)、`ui.HoldToTalk`(按住说话的按钮,和输入框的“按住 说话”条一样:页面变暗、用页面的识别器听,可滑到“取消”“编辑”,松手交出文字;页面不能识别语音时不显示)、`ui.voice`(`canListen` / `canSpeak` / `speak` / `hush`:用设置里的声音朗读)、视图的 `send`(对话式页面接收别的扩展发来的一条消息,就像在它的输入框里输入;分身页面有它,回答经 `preview` 读到)、`ui.useChatScroll`(和对话一样的滚动:停在底部时跟随新消息,往上翻看时不会被拉回、正在看的内容不跳,点开的部分留在原处;`sent` 是用户发出的消息数,多一条就回到底部)、`ui.Empty`(列表或视图为空时的提示:一行标题加至多一行说明,在所在区域居中;菜单、选择器和弹窗里用 `compact`;`picture` 在上方放一张插图)、`ui.Picture` / `ui.PictureCards`(和 Ta 一样的小插图:SVG 里的图形用 `ta-pic-*` 类名,跟随主题;一排可点的插图卡片,带标签和一行说明)、`ui.Dialog`(盖住整页的弹窗)、`ui.openEditor` 的 `preview`(单击打开的预览标签,标题斜体,下一个预览会替换它,双击或 `ui.pinEditor` 固定)、`ui.setEditorDirty`(标签显示未保存圆点,关闭前确认)、`ui.useActiveEditor`(工作台当前标签)、`ui.DiffEditor`(Monaco 差异编辑器,并排或内联,可编辑右侧)、`ui.confirm` 的 `confirmLabel` / `danger`、视图的 `head`(自己的顶栏)、`ui.input` / `ui.editor`(向用户要一行或多行文字,取消时为 `undefined`)、页面的 `menu`(侧栏列出该页面时悬浮显示的 … 菜单)与 `pages`(侧栏列出的页面,导航栏不再单列)、`discover`(不常用的页面默认收在"发现",用户固定后才进导航栏)、`ui.notify`(页面右下角的通知)、`ui.notifySession`(像聊天软件那样告诉用户某个对话说了什么:用户正在看它时不提醒,分身跟进的任务交给分身,除非它在提问;手机和平板上不弹窗,由列表和“对话”标签上的未读黄点告诉;电脑上页面在前台时是带对话头像和名字的横幅,点一下打开对话,`options` 是可点的回答,同一个回答从各个页面只发一次;页面不在前台时是系统通知,回复是静音的;没有系统通知时,提问和失败留一条横幅等用户回来)、`ui.confirm`(继续前先确认,返回用户是否同意)、`ui.theme`、`ui.language`、`ui.supportsWebview`(能否用 `<webview>` 显示网站,Ta 桌面版里可以,其他地方用 iframe)、`ui.debugWebview`(Ta 桌面版:向这种 webview 里的网页发 Chrome DevTools Protocol 命令,只限网页本身)、`ui.desktop.browserData`(Ta 桌面版,macOS 和 Windows:用户在应用的原生对话框里同意后,把其浏览器某个个人资料的 Cookie 导入内置浏览器;也可清除内置浏览器数据),以及页面的 `React` 和 ta serve 的服务:`server`(会话,pi 的 RPC 命令)、`workspace`(目录里的文件与命令)、`terminals`(终端)、`packages`(包)(类型见 `WebExtensionAPI`)。
|
|
26
|
+
- **Web 扩展**是一个不带 import 的 ES 模块,默认导出一个函数,页面用 `pi` 调用它;返回的函数在卸载时调用。`pi` 的接口照 pi 的 ExtensionAPI 命名:`ui.setWidget`(默认在输入框上方,和 pi 一样;`placement: 'panel'` 放进右侧工作台的卡片标签)、`registerView`(导航栏里的页面,或导航栏上方的一个侧栏列表;`location: 'panel'` 是右侧工作台的工具)、`registerMessageRenderer`(显示 pi 扩展用 `sendMessage` 发出的自定义消息)、`registerCodeRenderer`(把回复和 `ui.Markdown` 里某种语言的代码块画成扩展自己的卡片,组件拿到 `{ code, language, closed }`,流式时 `closed` 为假;抛错时显示为代码,如 `@celljs/ta-glance` 的 `ta-glance` 卡片)、`registerTool`(页面打开的对话里由浏览器执行的工具)、`registerToolRenderer`(照 pi 的同名接口传一个 resolver `(toolName, next) => renderer`,决定任意工具的调用在对话里怎么读:`renderCall(args)` 给出页面语言的动词、对象和可选的小图标,代替工具名;`next()` 是后面的 resolver 的结果)、`registerSettings`(设置里的一个分区,排在 Ta 自己的分区之后:每行是标签、说明和扩展自己画的控件,值用 `storage` 保存)、`registerTasks` / `ui.useTasks`(替用户做的事,由分身和其他扩展的任务一起列出,见 docs/design/ta-double.md;任务带 `remove` 和 `removeHint` 时,列表里可以左滑删除、多选后批量删除,询问统一由 `ui.removeTasks` 做)、`ui.SelectCheck` / `ui.SelectBar`(列表多选时行首的圆形勾选和列表底部的操作栏,样式与页面一致)、`registerOpener`(打开回复里的链接:文件及其行、目录、网页,按注册顺序询问,返回 true 表示已打开)、`registerComposerAddon`(给所有对话的输入框加东西:`actions(conversation)` 是 + 菜单里的条目,每个都是一个图标方块(每页 4×2,多了左右滑动翻页):`setting: true` 在名字下显示当前值(`detail`),`toggle: true` 是开关(`checked` 表示开着,图标点亮,点了不关菜单),条目可以带 `items` 二级列表;`above` 画在输入框上方;`subscribe` 通知条目变了。`conversation` 说明是哪个对话:`sessionId`、`sessionFile`、`cwd`、`kind` 为 `double` 或 `chat`、`group`、`title`;分身、智能体和普通对话都有)、`ui.Game3D`(Three.js 3D 游戏:`setup(context)` 拿到渲染器、场景、相机和 OrbitControls,往场景里放东西并返回每帧要做的事;同样懒加载、休眠、卸载时释放场景和 WebGL 上下文)、`ui.FullScreen`(盖住整个页面:外壳、它的顶栏和侧栏都在下面,铺到刘海和底部横条下,在桌面版标题栏之下、键盘之上;触摸全归它,屏幕边缘也不会拉出 Ta 的面板;给横屏游戏、能走进去的世界用,旧版 App 没有它时用 `??` 退回原处显示)、`data-own-gestures`(元素上的属性:从它开始的触摸归它,Ta 的滑动只从屏幕边缘开始,长按不出菜单;游戏自动带上)、`ui.Game`(Phaser 4 游戏:页面自带的游戏引擎,第一次开始游戏时才加载;填满父元素,看不见时休眠,卸载时销毁,键盘只在游戏获得焦点时归它,主题颜色放在游戏的 registry 里,见 docs/design/ta-games.md)、`ui.QrCode`(文字的二维码,任何主题下都是白底黑码)、`ui.ImageViewer`(看图:先完整显示且不超过原始像素,双指或触控板捏合、Ctrl/⌘ 加滚轮、双击或双点缩放,放大后拖动或滚动,底部是 − / 比例 / + / 适应窗口 / 实际大小;给了 `onPrevious` / `onNext` 时两侧有上一张、下一张按钮,未放大时 ← → 也能切换;工作台的图片预览和对话里的大图用的都是它)、`on`(当前对话的事件)、`sendUserMessage`(发到当前对话;`/命令` 会执行 pi 扩展的命令)、`switchSession`(把 ta serve 里另一个打开的会话显示为当前对话;传会话 id 的 Promise 时立即切过去显示"正在打开",`opening` 给出占位的标题)、`openChat`(按会话文件打开对话,和对话列表一样:先显示页面或设备上已有的内容,已关闭的一次往返重新打开;没有这个对话时返回 false)、`callHost`(调用本包 `pi.host` 的方法,经 `callPackageHost`)、`reloadExtensions`(扩展自己安装、导入或移除了包之后,像回复结束时一样重新加载 Web 扩展和当前对话的 pi 扩展)、`ui.showView` / `ui.useView`(显示、查看任意扩展的视图)、`ui.Composer` / `ui.Markdown`(和对话一样的输入框与 Markdown,麦克风和按住说话也一样;输入框的 `commands` 让 `/` 列出在 `cwd` 新开对话时会有的命令,`voiceSends`、`onTalkSent`、`onListening`、`working` / `onStop`、`after` 和分身的输入框一样:听到的话直接发出、知道哪句是说的以便朗读回答、正在听、正在回答时发送键变成停止、右侧放自己的按钮)、`ui.HoldToTalk`(按住说话的按钮,和输入框的“按住 说话”条一样:页面变暗、用页面的识别器听,可滑到“取消”“编辑”,松手交出文字;页面不能识别语音时不显示)、`ui.voice`(`canListen` / `canSpeak` / `speak` / `hush`:用设置里的声音朗读)、视图的 `send`(对话式页面接收别的扩展发来的一条消息,就像在它的输入框里输入;分身页面有它,回答经 `preview` 读到)、`ui.useChatScroll`(和对话一样的滚动:停在底部时跟随新消息,往上翻看时不会被拉回、正在看的内容不跳,点开的部分留在原处;`sent` 是用户发出的消息数,多一条就回到底部)、`ui.Empty`(列表或视图为空时的提示:一行标题加至多一行说明,在所在区域居中;菜单、选择器和弹窗里用 `compact`;`picture` 在上方放一张插图)、`ui.Picture` / `ui.PictureCards`(和 Ta 一样的小插图:SVG 里的图形用 `ta-pic-*` 类名,跟随主题;一排可点的插图卡片,带标签和一行说明)、`ui.Dialog`(盖住整页的弹窗)、`ui.openEditor` 的 `preview`(单击打开的预览标签,标题斜体,下一个预览会替换它,双击或 `ui.pinEditor` 固定)、`ui.setEditorDirty`(标签显示未保存圆点,关闭前确认)、`ui.useActiveEditor`(工作台当前标签)、`ui.DiffEditor`(Monaco 差异编辑器,并排或内联,可编辑右侧)、`ui.confirm` 的 `confirmLabel` / `danger`、视图的 `head`(自己的顶栏)、`ui.input` / `ui.editor`(向用户要一行或多行文字,取消时为 `undefined`)、页面的 `menu`(侧栏列出该页面时悬浮显示的 … 菜单)与 `pages`(侧栏列出的页面,导航栏不再单列)、`discover`(不常用的页面默认收在"发现",用户固定后才进导航栏)、`ui.notify`(页面右下角的通知)、`ui.notifySession`(像聊天软件那样告诉用户某个对话说了什么:用户正在看它时不提醒,分身跟进的任务交给分身,除非它在提问;手机和平板上不弹窗,由列表和“对话”标签上的未读黄点告诉;电脑上页面在前台时是带对话头像和名字的横幅,点一下打开对话,`options` 是可点的回答,同一个回答从各个页面只发一次;页面不在前台时是系统通知,回复是静音的;没有系统通知时,提问和失败留一条横幅等用户回来)、`ui.confirm`(继续前先确认,返回用户是否同意)、`ui.theme`、`ui.language`、`ui.supportsWebview`(能否用 `<webview>` 显示网站,Ta 桌面版里可以,其他地方用 iframe)、`ui.debugWebview`(Ta 桌面版:向这种 webview 里的网页发 Chrome DevTools Protocol 命令,只限网页本身)、`ui.desktop.browserData`(Ta 桌面版,macOS 和 Windows:用户在应用的原生对话框里同意后,把其浏览器某个个人资料的 Cookie 导入内置浏览器;也可清除内置浏览器数据),以及页面的 `React` 和 ta serve 的服务:`server`(会话,pi 的 RPC 命令)、`workspace`(目录里的文件与命令)、`terminals`(终端)、`packages`(包)(类型见 `WebExtensionAPI`)。
|
|
27
27
|
- **文件的字节**:`pi.files` 给出工作区的文件字节。页面由 ta serve 自己提供时 `byUrl` 为真,直接用 `workspace.fileUrl` 的地址加载就行;手机应用里、或页面经中继打开时,那个地址在页面里加载不到,`byUrl` 为假,`pi.files.read(url)` 经 WebSocket 取回 `{ type, size, data }`(端到端加密,中继读不到)。`@celljs/ta-workspace` 的预览就靠它:图片、视频、声音、PDF 做成 `blob:`,HTML 报告按文件文本放进沙框。
|
|
28
28
|
- **用自然语言做包**:内置扩展 [@celljs/ta-extensions](../ta-extensions/README.md) 带技能 `ta-package`(终端里的 Ta 也有),并在导航栏加了"扩展"页(一句话做扩展、导出导入),写明了包的格式、Web 扩展接口和验证步骤。当前对话每次回复结束,页面重新读取 Web 扩展:新的加载、改过的重新加载、删掉的卸载;工具有变化时,用同一个会话文件重新打开这段对话(只限本页打开的对话),包有改动时让会话重新加载 pi 扩展。页面重新显示时也会检查一次(包也可能在终端里改)。
|
|
29
29
|
- **稳定**:每个扩展注册的东西归它自己,卸载时一并撤掉;一个扩展加载失败或渲染出错,只在它自己的位置显示错误,不影响页面和其他扩展。
|
|
@@ -4,7 +4,8 @@ import { Callout } from '../components/callout.js';
|
|
|
4
4
|
import { Composer } from '../components/composer.js';
|
|
5
5
|
import { useComposerAddons } from '../components/composer-addons.js';
|
|
6
6
|
import { ConnectionBanner } from '../components/connection-bar.js';
|
|
7
|
-
import { ASK_CLASS
|
|
7
|
+
import { ASK_CLASS } from '../components/conversation-scroll.js';
|
|
8
|
+
import { useConversationScroll } from '../components/conversation-scroll-hooks.js';
|
|
8
9
|
import { DialogView } from '../components/dialog-view.js';
|
|
9
10
|
import { useAsked, useEarlierMessages } from '../components/earlier-messages.js';
|
|
10
11
|
import { HeroCards, HeroSteps } from '../components/hero-cards.js';
|
|
@@ -17,6 +18,7 @@ import { useMessageMenu } from '../components/message-menu.js';
|
|
|
17
18
|
import { RunStatus } from '../components/run-status.js';
|
|
18
19
|
import { useSessionSettings } from '../components/session-settings.js';
|
|
19
20
|
import { TaAvatar } from '../components/ta-avatar.js';
|
|
21
|
+
import { useStopTimes } from '../components/use-stop-times.js';
|
|
20
22
|
import { SpeakingButton } from '../components/voice-button.js';
|
|
21
23
|
import { WorkbenchToggle } from '../components/workbench-toggle.js';
|
|
22
24
|
import { CustomMessage, MessageRenderers } from '../extension/extension-view.js';
|
|
@@ -180,6 +182,7 @@ function Chat({ store, tasks, taskStates, onTask, onMood, onTasks }) {
|
|
|
180
182
|
const [workbench, bench] = useWorkbench();
|
|
181
183
|
const [settingsState, settings] = useSettings();
|
|
182
184
|
const state = useSessionState(store);
|
|
185
|
+
const stopTimed = useStopTimes(store.sessionId, 'double');
|
|
183
186
|
const now = useNow(1000);
|
|
184
187
|
const lastActive = useLastActive();
|
|
185
188
|
const [listening, setListening] = React.useState(false);
|
|
@@ -351,7 +354,7 @@ function Chat({ store, tasks, taskStates, onTask, onMood, onTasks }) {
|
|
|
351
354
|
React.createElement(DialogView, { request: request, respond: response => from.respondUi(response).catch(() => undefined) })))),
|
|
352
355
|
React.createElement(ConnectionBanner, null),
|
|
353
356
|
addons.above,
|
|
354
|
-
React.createElement(Composer, { ref: box, store: store, server: bench.server, workspace: bench.workspace, working: state.working, commands: session.settings.commands, cwd: cwd, placeholder: t('ta.assistant.placeholder'), actions: actions, onSending: hush, onError: fail, after: speaking ? React.createElement(SpeakingButton, { onStop: hush }) : undefined, voiceSends: true, recentShots: settingsState.settings.recentShots, talkPlace: "double", onTalkSent: () => {
|
|
357
|
+
React.createElement(Composer, { ref: box, store: store, server: bench.server, workspace: bench.workspace, working: state.working, commands: session.settings.commands, cwd: cwd, placeholder: t('ta.assistant.placeholder'), actions: actions, onSending: hush, onStopTimed: stopTimed, onError: fail, after: speaking ? React.createElement(SpeakingButton, { onStop: hush }) : undefined, voiceSends: true, recentShots: settingsState.settings.recentShots, talkPlace: "double", onTalkSent: () => {
|
|
355
358
|
aloud.current = speakTalk;
|
|
356
359
|
}, onListening: on => {
|
|
357
360
|
setListening(on);
|
|
@@ -124,9 +124,8 @@ export function ChatView({ widgets, onMenu, back }) {
|
|
|
124
124
|
const menu = React.createElement(IconButton, { icon: back ? ChevronLeft : SidebarLeft, label: t(back ? 'ta.back' : 'ta.sidebar'), className: "ta-narrow-only", onClick: onMenu });
|
|
125
125
|
const around = (placement) => widgets.filter(widget => widget.placement === placement).map(widget => React.createElement(Widget, { key: widget.id, widget: widget }));
|
|
126
126
|
// On a phone, the state of the connection is a row over the message box.
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
around('aboveEditor')));
|
|
127
|
+
const notice = React.createElement(ConnectionBanner, null);
|
|
128
|
+
const aboveComposer = around('aboveEditor');
|
|
130
129
|
// The conversation picked shows at once, as it opens: its head and that it is on its way, rather than the one before.
|
|
131
130
|
const coming = pending && pending !== (store === null || store === void 0 ? void 0 : store.sessionId) ? pending : arriving && store && store.sessionId !== before ? store.sessionId : undefined;
|
|
132
131
|
if (coming) {
|
|
@@ -134,7 +133,9 @@ export function ChatView({ widgets, onMenu, back }) {
|
|
|
134
133
|
return React.createElement(OpeningView, { info: opening !== null && opening !== void 0 ? opening : (info && { title: info.sessionName, cwd: info.cwd }), menu: menu });
|
|
135
134
|
}
|
|
136
135
|
if (draft) {
|
|
137
|
-
return React.createElement(DraftView, { draft: draft, menu: menu, aboveComposer:
|
|
136
|
+
return (React.createElement(DraftView, { draft: draft, menu: menu, aboveComposer: React.createElement(React.Fragment, null,
|
|
137
|
+
notice,
|
|
138
|
+
aboveComposer), belowComposer: around('belowEditor') }));
|
|
138
139
|
}
|
|
139
140
|
if (!store) {
|
|
140
141
|
return (React.createElement(React.Fragment, null,
|
|
@@ -152,6 +153,6 @@ export function ChatView({ widgets, onMenu, back }) {
|
|
|
152
153
|
// The same view while the conversation shown from the device becomes the one attached: nothing drawn again.
|
|
153
154
|
, {
|
|
154
155
|
// The same view while the conversation shown from the device becomes the one attached: nothing drawn again.
|
|
155
|
-
key: view !== null && view !== void 0 ? view : store.sessionId, store: store, server: workbench.server, workspace: workbench.workspace, info: info, onClosed: refresh, onActivity: refresh, leading: menu, trailing: React.createElement(WorkbenchToggle, null), empty: React.createElement(Hero, { cwd: (_e = info === null || info === void 0 ? void 0 : info.cwd) !== null && _e !== void 0 ? _e : '', onPick: text => store.send(text).catch(() => undefined) }), aboveComposer: aboveComposer, belowComposer: around('belowEditor') }));
|
|
156
|
+
key: view !== null && view !== void 0 ? view : store.sessionId, store: store, server: workbench.server, workspace: workbench.workspace, info: info, onClosed: refresh, onActivity: refresh, leading: menu, trailing: React.createElement(WorkbenchToggle, null), empty: React.createElement(Hero, { cwd: (_e = info === null || info === void 0 ? void 0 : info.cwd) !== null && _e !== void 0 ? _e : '', onPick: text => store.send(text).catch(() => undefined) }), notice: notice, aboveComposer: aboveComposer, belowComposer: around('belowEditor') }));
|
|
156
157
|
}
|
|
157
158
|
//# sourceMappingURL=chat-view.js.map
|
|
@@ -36,6 +36,7 @@ import { KeptPages } from './kept-pages.js';
|
|
|
36
36
|
import { LauncherSurface } from './launcher-surface.js';
|
|
37
37
|
import { OpenLink } from './link.js';
|
|
38
38
|
import { LinkDialog } from './link-dialog.js';
|
|
39
|
+
import { ListSkeleton } from './list-skeleton.js';
|
|
39
40
|
import { MeView } from './me-view.js';
|
|
40
41
|
import { FileUrls } from './media.js';
|
|
41
42
|
import { DISCOVER, ME_TAB, phoneTabs } from './nav-places.js';
|
|
@@ -161,7 +162,7 @@ function AppShell() {
|
|
|
161
162
|
React.useEffect(() => {
|
|
162
163
|
host.setSessionSwitcher(async (session, opening) => {
|
|
163
164
|
// In front at once, while it opens.
|
|
164
|
-
const shown = chat.show(session, opening);
|
|
165
|
+
const shown = typeof session === 'object' && 'sessionFile' in session ? chat.resume(session.sessionFile) : chat.show(session, opening);
|
|
165
166
|
setNavOpen(false);
|
|
166
167
|
setSurface(undefined);
|
|
167
168
|
setSettings(undefined);
|
|
@@ -211,7 +212,9 @@ function AppShell() {
|
|
|
211
212
|
const view = extensions.views.find(candidate => candidate.id === page && candidate.location === 'page');
|
|
212
213
|
const sideViews = SideListUtil.sidebarViews(extensions.views);
|
|
213
214
|
const sideView = sideId === FIRST_SIDE ? sideViews[0] : sideViews.find(candidate => candidate.id === sideId);
|
|
214
|
-
|
|
215
|
+
// The first start, nothing kept: the double's list may still come, rather than the chats shown a moment before it.
|
|
216
|
+
const sideComing = sideId === FIRST_SIDE && !sideView && !extensions.loaded;
|
|
217
|
+
const side = sideView ? sideView.id : sideComing ? FIRST_SIDE : '';
|
|
215
218
|
const showPage = (id) => {
|
|
216
219
|
host.showPage(id);
|
|
217
220
|
setNavOpen(false);
|
|
@@ -392,6 +395,7 @@ function AppShell() {
|
|
|
392
395
|
}
|
|
393
396
|
};
|
|
394
397
|
const chats = (React.createElement(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 }));
|
|
398
|
+
const sideList = sideView ? React.createElement(SidebarView, { view: sideView }) : sideComing ? React.createElement(ListSkeleton, null) : chats;
|
|
395
399
|
const editorArea = (React.createElement(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 = WebCwdUtil.shown(extensions)) !== null && _f !== void 0 ? _f : (_c = workbench.server) === null || _c === void 0 ? void 0 : _c.cwd, maximized: maximized, onMaximize: () => setMaximized(!maximized) }));
|
|
396
400
|
// A photo of the scan screen to the double: its conversation shows, the photo goes with what to do with it.
|
|
397
401
|
const askDouble = async (text, image) => {
|
|
@@ -507,7 +511,7 @@ function AppShell() {
|
|
|
507
511
|
}
|
|
508
512
|
}, home: tabPage === 'me' ? (React.createElement("div", { className: "ta-main" },
|
|
509
513
|
React.createElement(MeView, { onSettings: openSettings }))) : tabPage === 'discover' ? (React.createElement("div", { className: "ta-main" }, discoverView())) : tabView ? (React.createElement("div", { className: "ta-main" },
|
|
510
|
-
React.createElement(PageView, { view: tabView }))) : (React.createElement("div", { className: "ta-sidebar" },
|
|
514
|
+
React.createElement(PageView, { view: tabView }))) : (React.createElement("div", { className: "ta-sidebar" }, sideList)), screen: React.createElement(React.Fragment, null,
|
|
511
515
|
React.createElement(KeptPages, { views: extensions.views, kept: extensions.kept, shown: screenPage, render: page => (React.createElement(PageView, { view: page, leading: React.createElement(IconButton, { icon: ChevronLeft, label: t('ta.back'), className: "ta-narrow-only", onClick: closeScreen }) })) }),
|
|
512
516
|
settings !== undefined ? (React.createElement(SettingsView, { key: settingsOpened, section: settings || undefined, onClose: closeSettings, onBack: closeSettings })) : screenPage ? null : (React.createElement(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 },
|
|
513
517
|
navOpen && React.createElement("button", { type: "button", className: "ta-scrim", "aria-label": t('ta.close'), onClick: () => setNavOpen(false) }),
|
|
@@ -518,7 +522,7 @@ function AppShell() {
|
|
|
518
522
|
setTabPage('discover');
|
|
519
523
|
}, onSettings: openSettings, settingsShown: settings !== undefined, surfaces: surfaces, surface: surface, onSurface: setSurface, holds: holds }),
|
|
520
524
|
sideShown && (React.createElement("div", { className: "ta-sidebar", style: paneStyle(sidebar) },
|
|
521
|
-
|
|
525
|
+
sideList,
|
|
522
526
|
React.createElement(Sash, { pane: sidebar, side: "start", label: t('ta.layout.sidebar') })))),
|
|
523
527
|
React.createElement("main", { className: "ta-main" },
|
|
524
528
|
React.createElement(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>;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { ArrowUp, AtSign, ImagePlus, Keyboard, Mic, Plus, Slash, Square, X } from 'lucide-react';
|
|
1
|
+
import { ArrowUp, AtSign, Camera, ImagePlus, Images, Keyboard, Mic, Plus, Slash, Square, X } from 'lucide-react';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useDevice } from '../device/device.js';
|
|
4
4
|
import { useHeld } from '../device/hold.js';
|
|
5
5
|
import { LongPressUtil } from '../device/long-press.js';
|
|
6
|
+
import { PhotoPicker } from '../device/photo-picker.js';
|
|
6
7
|
import { RecentShots } from '../device/recent-shots.js';
|
|
7
8
|
import { useT } from '../i18n/use-t.js';
|
|
8
|
-
import { ComposerUtil, IMAGE_TYPES } from '../util/composer.js';
|
|
9
|
+
import { ComposerUtil, IMAGE_TYPES, MAX_IMAGES } from '../util/composer.js';
|
|
9
10
|
import { FileDragUtil } from '../util/file-drag.js';
|
|
10
11
|
import { Voice } from '../util/voice.js';
|
|
11
12
|
import { ComposerMenu } from './composer-menu.js';
|
|
@@ -59,6 +60,20 @@ export const ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
|
|
|
59
60
|
const [dragging, setDragging] = React.useState(false);
|
|
60
61
|
const [menu, setMenu] = React.useState(false);
|
|
61
62
|
const [listening, setListening] = React.useState(false);
|
|
63
|
+
// Stop pressed: the run may take a moment to end (a tool winding down), and the press must show at once.
|
|
64
|
+
const [stopping, setStopping] = React.useState(false);
|
|
65
|
+
React.useEffect(() => {
|
|
66
|
+
if (!working) {
|
|
67
|
+
setStopping(false);
|
|
68
|
+
}
|
|
69
|
+
}, [working]);
|
|
70
|
+
const stop = () => {
|
|
71
|
+
if (!onStop || stopping) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
setStopping(true);
|
|
75
|
+
Promise.resolve(onStop()).catch(() => setStopping(false));
|
|
76
|
+
};
|
|
62
77
|
const touch = useDevice(device => device.touch);
|
|
63
78
|
// On a phone the + menu is a panel under the box, in place of the keyboard, as WeChat's.
|
|
64
79
|
const handheld = useDevice(device => device.handheld);
|
|
@@ -70,6 +85,7 @@ export const ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
|
|
|
70
85
|
const [focused, setFocused] = React.useState(false);
|
|
71
86
|
const input = React.useRef(null);
|
|
72
87
|
const picker = React.useRef(null);
|
|
88
|
+
const camera = React.useRef(null);
|
|
73
89
|
const plus = React.useRef(null);
|
|
74
90
|
const panel = React.useRef(null);
|
|
75
91
|
const menuId = React.useId();
|
|
@@ -364,6 +380,12 @@ export const ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
|
|
|
364
380
|
});
|
|
365
381
|
}
|
|
366
382
|
};
|
|
383
|
+
const onPicked = (event) => {
|
|
384
|
+
if (event.target.files) {
|
|
385
|
+
addFiles(event.target.files);
|
|
386
|
+
}
|
|
387
|
+
event.target.value = '';
|
|
388
|
+
};
|
|
367
389
|
const onKeyDown = (event) => {
|
|
368
390
|
var _a;
|
|
369
391
|
const composing = event.nativeEvent.isComposing || event.keyCode === 229;
|
|
@@ -385,7 +407,7 @@ export const ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
|
|
|
385
407
|
}
|
|
386
408
|
else if (event.key === 'Escape' && working && onStop) {
|
|
387
409
|
event.preventDefault();
|
|
388
|
-
|
|
410
|
+
stop();
|
|
389
411
|
}
|
|
390
412
|
};
|
|
391
413
|
const onPaste = (event) => {
|
|
@@ -409,20 +431,25 @@ export const ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
|
|
|
409
431
|
}
|
|
410
432
|
};
|
|
411
433
|
const own = [];
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
434
|
+
const pickImages = () => {
|
|
435
|
+
var _a, _b, _c;
|
|
436
|
+
// The Ta app on iOS opens its library at once (and asks for the photos, for the screenshots, once picked).
|
|
437
|
+
if (PhotoPicker.available()) {
|
|
438
|
+
void PhotoPicker.pick(MAX_IMAGES - attachments.length).then(files => files.length && addFiles(files));
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
if (recentShots) {
|
|
442
|
+
(_b = (_a = RecentShots.source()) === null || _a === void 0 ? void 0 : _a.ask) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
443
|
+
}
|
|
444
|
+
(_c = picker.current) === null || _c === void 0 ? void 0 : _c.click();
|
|
445
|
+
};
|
|
446
|
+
if (takesImages && handheld && touch) {
|
|
447
|
+
// On a phone the album and the camera are two tiles, as WeChat's: each opens at once, without the menu of
|
|
448
|
+
// the system's file field (Photo Library, Take Photo, Choose File) in between.
|
|
449
|
+
own.push({ key: 'album', label: t('ta.composer.album'), icon: React.createElement(Icon, { icon: Images, size: 16 }), run: pickImages }, { key: 'camera', label: t('ta.composer.camera'), icon: React.createElement(Icon, { icon: Camera, size: 16 }), run: () => { var _a; return (_a = camera.current) === null || _a === void 0 ? void 0 : _a.click(); } });
|
|
450
|
+
}
|
|
451
|
+
else if (takesImages) {
|
|
452
|
+
own.push({ key: 'image', label: t('ta.composer.addImage'), icon: React.createElement(Icon, { icon: ImagePlus, size: 16 }), run: pickImages });
|
|
426
453
|
}
|
|
427
454
|
if (mentionLabel) {
|
|
428
455
|
own.push({ key: 'mention', label: mentionLabel, icon: React.createElement(Icon, { icon: AtSign, size: 16 }), run: () => edit(...ComposerUtil.insert(text, caret, '@')) });
|
|
@@ -461,12 +488,8 @@ export const ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
|
|
|
461
488
|
React.createElement(IconButton, { icon: Plus, label: t('ta.composer.more'), className: `ta-attach ta-plus-button ${menu ? 'ta-on' : ''}`, onClick: toggleMenu }),
|
|
462
489
|
menu && !handheld && React.createElement(PlusMenu, { sections: sections, onClose: closeMenu }),
|
|
463
490
|
takesImages && recentShots && (React.createElement(RecentShotOffer, { box: box, activity: `${text}|${attachments.length}|${menu}|${talkMode}`, onPick: file => addFiles([file]) })))),
|
|
464
|
-
takesImages &&
|
|
465
|
-
|
|
466
|
-
addFiles(event.target.files);
|
|
467
|
-
}
|
|
468
|
-
event.target.value = '';
|
|
469
|
-
} })),
|
|
491
|
+
takesImages && React.createElement("input", { ref: picker, type: "file", accept: IMAGE_TYPES.join(','), multiple: true, hidden: true, onChange: onPicked }),
|
|
492
|
+
takesImages && handheld && touch && React.createElement("input", { ref: camera, type: "file", accept: "image/*", capture: "environment", hidden: true, onChange: onPicked }),
|
|
470
493
|
talkMode && React.createElement(TalkBar, { talk: talk }),
|
|
471
494
|
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 => {
|
|
472
495
|
setText(event.target.value);
|
|
@@ -481,16 +504,15 @@ export const ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
|
|
|
481
504
|
}, onBlur: () => setFocused(false) }),
|
|
482
505
|
after,
|
|
483
506
|
microphone,
|
|
484
|
-
React.createElement("button", { type: "button", className: `ta-send ${action === 'stop' ? 'ta-send-stop' : ''}`, disabled: action === 'send' && (!sendable || reading), title: action === 'stop'
|
|
485
|
-
? t('ta.composer.stopTitle')
|
|
507
|
+
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'
|
|
508
|
+
? t(stopping ? 'ta.composer.stopping' : 'ta.composer.stopTitle')
|
|
486
509
|
: reading
|
|
487
510
|
? t('ta.composer.imageLoading')
|
|
488
511
|
: working
|
|
489
512
|
? t('ta.composer.steerTitle')
|
|
490
|
-
: t('ta.send'), "aria-label": action === 'stop' ? t('ta.stop') : t('ta.send'),
|
|
513
|
+
: t('ta.send'), "aria-label": action === 'stop' ? t(stopping ? 'ta.composer.stopping' : 'ta.stop') : t('ta.send'), "aria-busy": action === 'stop' && stopping,
|
|
491
514
|
// Pressed with the keyboard open, the box keeps the focus and the keyboard stays, as in WeChat.
|
|
492
|
-
onPointerDown: event => document.activeElement === input.current && event.preventDefault(), onClick: () => (action === 'stop' ?
|
|
493
|
-
React.createElement(Icon, { icon: action === 'stop' ? Square : ArrowUp, size: action === 'stop' ? 14 : 18 })))),
|
|
515
|
+
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, { icon: action === 'stop' ? Square : ArrowUp, size: action === 'stop' ? 14 : 18 }))))),
|
|
494
516
|
handheld && (menu || closing) && sections.length > 0 && (React.createElement(PlusMenu, { ref: panel, sections: sections, docked: true, closing: !menu, onClosed: () => setClosing(false), onClose: closeMenu }))));
|
|
495
517
|
});
|
|
496
518
|
//# sourceMappingURL=composer-box.js.map
|
|
@@ -4,6 +4,7 @@ import * as React from 'react';
|
|
|
4
4
|
import { type ComposerImage } from '../util/composer.js';
|
|
5
5
|
import { type ComposerAction, type ComposerBoxHandle } from './composer-box.js';
|
|
6
6
|
import type { TalkPlace } from './held-talk.js';
|
|
7
|
+
import { type StopTiming } from './stop-times.js';
|
|
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
|
/**
|
|
@@ -6,6 +6,7 @@ import { useLanguage, useT } from '../i18n/use-t.js';
|
|
|
6
6
|
import { ComposerUtil } from '../util/composer.js';
|
|
7
7
|
import { ComposerBox } from './composer-box.js';
|
|
8
8
|
import { Icon } from './icon.js';
|
|
9
|
+
import { StopClock } from './stop-times.js';
|
|
9
10
|
const FILE_LIMIT = 20;
|
|
10
11
|
const FILE_DELAY_MS = 120;
|
|
11
12
|
const EMPTY_QUEUE = { steering: [], followUp: [] };
|
|
@@ -57,7 +58,7 @@ function useQueue(store, working) {
|
|
|
57
58
|
* and Alt+Enter queues a follow-up; Escape stops it.
|
|
58
59
|
*/
|
|
59
60
|
export const Composer = React.forwardRef(function Composer(props, ref) {
|
|
60
|
-
const { store, onSubmit, head, after, voiceSends, recentShots, talkPlace, onTalkSent, onListening, server, workspace, working, commands, cwd, actions, placeholder, above, onSending, onStop, onError, } = props;
|
|
61
|
+
const { store, onSubmit, head, after, voiceSends, recentShots, talkPlace, onTalkSent, onListening, server, workspace, working, commands, cwd, actions, placeholder, above, onSending, onStop, onStopTimed, onError, } = props;
|
|
61
62
|
// A finger: the keyboard opens on focus, over the conversation, and there are no keys to name.
|
|
62
63
|
const touch = useDevice(device => device.touch);
|
|
63
64
|
const t = useT();
|
|
@@ -68,7 +69,32 @@ export const Composer = React.forwardRef(function Composer(props, ref) {
|
|
|
68
69
|
const files = useFiles(workspace, cwd, query);
|
|
69
70
|
const box = React.useRef(null);
|
|
70
71
|
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); } }));
|
|
71
|
-
|
|
72
|
+
// The stop pressed, timed until the computer answered it and the run was seen ended.
|
|
73
|
+
const stopping = React.useRef(undefined);
|
|
74
|
+
const timed = (clock, timing) => {
|
|
75
|
+
if (timing) {
|
|
76
|
+
stopping.current = stopping.current === clock ? undefined : stopping.current;
|
|
77
|
+
onStopTimed === null || onStopTimed === void 0 ? void 0 : onStopTimed(timing);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
const clock = stopping.current;
|
|
82
|
+
if (!working && clock) {
|
|
83
|
+
timed(clock, clock.ended(performance.now()));
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
const stop = () => {
|
|
87
|
+
if (!store) {
|
|
88
|
+
return onStop === null || onStop === void 0 ? void 0 : onStop();
|
|
89
|
+
}
|
|
90
|
+
const clock = new StopClock(performance.now(), Date.now());
|
|
91
|
+
stopping.current = clock;
|
|
92
|
+
return server.abort(store.sessionId).then(() => timed(clock, clock.answered(performance.now())), error => {
|
|
93
|
+
timed(clock, clock.answered(performance.now(), true));
|
|
94
|
+
onError(error);
|
|
95
|
+
throw error;
|
|
96
|
+
});
|
|
97
|
+
};
|
|
72
98
|
const send = (message, images, followUp) => {
|
|
73
99
|
var _a;
|
|
74
100
|
onSending === null || onSending === void 0 ? void 0 : onSending();
|
|
@@ -0,0 +1,16 @@
|
|
|
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];
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ASK_CLASS, ConversationScroller, calm } from './conversation-scroll.js';
|
|
3
|
+
/**
|
|
4
|
+
* The scrolling of a conversation (ConversationScroller), whose thread is the first child of the element of the
|
|
5
|
+
* returned ref. Opened, and when messages of the user go (a rewind), the view goes to the bottom.
|
|
6
|
+
*
|
|
7
|
+
* `asked`: how many messages of the user there are; the thread marks them with ASK_CLASS.
|
|
8
|
+
*/
|
|
9
|
+
export function useConversationScroll(asked, options = {}) {
|
|
10
|
+
const { sentTo = 'top', key } = options;
|
|
11
|
+
const ref = React.useRef(null);
|
|
12
|
+
const attached = React.useRef(undefined);
|
|
13
|
+
const before = React.useRef(undefined);
|
|
14
|
+
// After each render, the view may only now be there (a page that shows it once its data came).
|
|
15
|
+
React.useLayoutEffect(() => {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
const view = ref.current;
|
|
18
|
+
const thread = view === null || view === void 0 ? void 0 : view.firstElementChild;
|
|
19
|
+
if (((_a = attached.current) === null || _a === void 0 ? void 0 : _a.view) === view) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
(_b = attached.current) === null || _b === void 0 ? void 0 : _b.detach();
|
|
23
|
+
attached.current = undefined;
|
|
24
|
+
if (view && thread instanceof HTMLElement) {
|
|
25
|
+
const scroller = new ConversationScroller(view, thread);
|
|
26
|
+
attached.current = { view, scroller, detach: scroller.attach(view, thread) };
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
React.useLayoutEffect(() => () => {
|
|
30
|
+
var _a;
|
|
31
|
+
(_a = attached.current) === null || _a === void 0 ? void 0 : _a.detach();
|
|
32
|
+
attached.current = undefined;
|
|
33
|
+
}, []);
|
|
34
|
+
React.useLayoutEffect(() => {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
const previous = before.current;
|
|
37
|
+
before.current = { asked, key };
|
|
38
|
+
const current = (_a = attached.current) === null || _a === void 0 ? void 0 : _a.scroller;
|
|
39
|
+
const thread = (_b = ref.current) === null || _b === void 0 ? void 0 : _b.firstElementChild;
|
|
40
|
+
if (!current || !thread) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// One more: sent now. More at once is the conversation loaded again, which opens at its bottom.
|
|
44
|
+
const sent = previous !== undefined && previous.key === key && asked === previous.asked + 1;
|
|
45
|
+
const asks = sent && sentTo === 'top' ? thread.getElementsByClassName(ASK_CLASS) : undefined;
|
|
46
|
+
const message = asks === null || asks === void 0 ? void 0 : asks[asks.length - 1];
|
|
47
|
+
if (message) {
|
|
48
|
+
current.send(message);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
current.reset();
|
|
52
|
+
}
|
|
53
|
+
}, [asked, key, sentTo]);
|
|
54
|
+
return ref;
|
|
55
|
+
}
|
|
56
|
+
/** Away from the bottom by more than half of the view: the button back to the latest shows. */
|
|
57
|
+
const AWAY_SHARE = 0.5;
|
|
58
|
+
/** Lower than this (a phone held sideways, its keyboard open) the view has no room for the button. */
|
|
59
|
+
const AWAY_MIN_PX = 240;
|
|
60
|
+
/** Whether the conversation of `ref` is scrolled up from its latest, and a way back to it. */
|
|
61
|
+
export function useAwayFromBottom(ref) {
|
|
62
|
+
const [away, setAway] = React.useState(false);
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
const element = ref.current;
|
|
65
|
+
if (!element) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
let frame = 0;
|
|
69
|
+
const measure = () => {
|
|
70
|
+
cancelAnimationFrame(frame);
|
|
71
|
+
frame = requestAnimationFrame(() => {
|
|
72
|
+
const { scrollHeight, scrollTop, clientHeight } = element;
|
|
73
|
+
setAway(clientHeight >= AWAY_MIN_PX && scrollHeight - scrollTop - clientHeight > clientHeight * AWAY_SHARE);
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
element.addEventListener('scroll', measure, { passive: true });
|
|
77
|
+
// The keyboard and a turn of the phone change the height of the view, not where it is.
|
|
78
|
+
const observer = typeof ResizeObserver !== 'undefined' ? new ResizeObserver(measure) : undefined;
|
|
79
|
+
observer === null || observer === void 0 ? void 0 : observer.observe(element);
|
|
80
|
+
return () => {
|
|
81
|
+
cancelAnimationFrame(frame);
|
|
82
|
+
observer === null || observer === void 0 ? void 0 : observer.disconnect();
|
|
83
|
+
element.removeEventListener('scroll', measure);
|
|
84
|
+
};
|
|
85
|
+
}, [ref]);
|
|
86
|
+
const back = React.useCallback(() => {
|
|
87
|
+
const element = ref.current;
|
|
88
|
+
const scroller = element ? ConversationScroller.of(element) : undefined;
|
|
89
|
+
if (scroller) {
|
|
90
|
+
scroller.toBottom();
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
element === null || element === void 0 ? void 0 : element.scrollTo({ top: element.scrollHeight, behavior: calm() ? 'auto' : 'smooth' });
|
|
94
|
+
}
|
|
95
|
+
}, [ref]);
|
|
96
|
+
return [away, back];
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=conversation-scroll-hooks.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { FrameScheduler } from '../util/frame.js';
|
|
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
|
+
}
|