@celljs/ta-extensions 4.9.1 → 4.11.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 CHANGED
@@ -10,6 +10,8 @@ A built-in pi package for Ta (enabled by default, can be disabled in Settings
10
10
  - Import: use the button, the page's top-right menu, or drag files to the page. In the dialog, select a `.tgz` file or enter an `npm:…` / Git address to install (`installPackage`, equivalent to `ta install`). After import, install, or remove, call `reloadExtensions` so the current session and page get the updates immediately.
11
11
  - "Share with Others": export → send .tgz file → they import. A three-step diagram shows this flow, with a note explaining that npm, Git sources, or telling Ta directly also work.
12
12
  - Each row and the page of a package of the marketplace have Share: the share dialog of Ta (a QR code, a link).
13
+ - Settings → Making extensions (`settings.tsx`, `registerSettings`): the model of the conversations that make or change an extension, kept as `makeModel` in the data of this package (`make-model.ts`); unset, the default model, and the default too, the user told why, when the one set cannot be used (its credentials went). Make and Change of the Extensions page, and Make an extension of a scheduled task, open their conversation on it.
14
+ - Make an extension in the + of the message box of every conversation (`composer.tsx`, `registerComposerAddon`): asks Ta, in that conversation, to make an extension of what it did, its inputs a form or buttons, its steps a command or a tool, its results a view that suits them. The conversation shows one line, the rest for the model is in a `<context>` block; while a reply runs, it waits its turn. With a model set for making extensions, the conversation is copied instead (`forkToFile`) and the copy goes on on that model, the conversation left as it was; the entry names the model. The box of a channel has it too ([@celljs/ta-channels](../ta-channels/README.en.md)), for its lead; the one of a scheduled task is [@celljs/ta-cron](../ta-cron/README.en.md)'s.
13
15
  - The search of Quick open gets three sections from here (`search.ts`, `registerSearch`): Installed and Come with Ta, filtered in memory, and Marketplace, npm searched through the host a page at a time, with Install on those not installed.
14
16
  - Extensions opened without installing are not listed under "Mine": Quick open installs or deletes them ([@celljs/ta-launcher](../ta-launcher/README.en.md)). The page of a package of the marketplace with a web extension has Open besides Install: its pages run at once as a temporary extension (`pi.openTemporary`), found in Quick open afterwards.
15
17
  - "Marketplace" (`market-view.tsx`, `market-detail.tsx`): npm packages with the `pi-package` keyword—the ones listed in pi's official package directory.
@@ -17,7 +19,7 @@ A built-in pi package for Ta (enabled by default, can be disabled in Settings
17
19
  - Each card shows an avatar from the first letter of the name (same name, same color), name (scope faded), author, monthly downloads, description, category tags, and publish date, with an "Install" button on the right: one-click install as user-level `npm:<name>` (`installPackage`, unpinned version, updatable with `ta update`). A loading spinner appears during install; "Installed" shows when done; built-in extensions show "Built-in". Installation continues if you leave the page.
18
20
  - Click a card to see its detail page (`Esc` or "Back" returns to the list, scroll position preserved): avatar, name, description, author/version/downloads/license/date, install or remove, npm/source/homepage links, previews from `pi.video` / `pi.image`, and README.
19
21
  - **Server** (`pi.host`, `web-src/host.ts` → `host/index.mjs`): the page calls it via `callHost` (`TaPackageServer.callPackageHost`).
20
- - `exportPackage(id)`: packs a package directory into a `.tgz` file (gzip tar, top level is the package, skips `node_modules`, `.git`, and symlinks), sends it to the page as base64 for download. The format is the same as `tar -czf <name>.tgz <name>`, so it can be unpacked with `tar` without Ta.
22
+ - `exportPackage(id)`: packs a package directory into a `.tgz` file (gzip tar, top level is the package, skips `node_modules`, `.git`, the files of secrets `.env*` (but `.env.example`) and `.npmrc`, and symlinks), sends it to the page as base64 for download. The format is the same as `tar -czf <name>.tgz <name>`, so it can be unpacked with `tar` without Ta.
21
23
  - `searchMarket(query, from?)`, `marketPackage(name)` (`market.ts`): queries npm on the server (packages are installed there). Results are cached for 5 minutes; identical requests are deduplicated. Search uses `/-/v1/search?text=<term> keywords:pi-package`. Npm still ranks all `pi-package` packages below relevant results, so this filters to keep only packages with the term in their name, description, or keywords, stopping at the first irrelevant result. The detail doesn't fetch npm's entire package doc (frequently-updated packages can be tens of MB)—just the `/<name>/latest` manifest and last month's downloads. The README is first fetched from jsDelivr for the published version; if not found, fetches from GitHub. HTML images, links, and headings in READMEs are converted to Markdown (Ta's Markdown doesn't render HTML), badges removed, relative links point to the GitHub repo.
22
24
  - `importPackage(data, overwrite?)`: validates the file (single top-level directory, contains `package.json`, paths don't escape, at most 5000 files and 20 MB; skips symlinks and macOS tar's `._*` files), places it in `extensions/<package-name-without-scope>` in the agent directory, and pi loads it without configuration. Returns `exists` if a directory with the same name already exists; the page asks the user and retries with `overwrite`. Writes to a hidden temporary directory first, then swaps it in, so the session won't load a half-written file. Packages output by `npm pack` (with top-level `package/`) can also be imported.
23
25
 
@@ -27,4 +29,4 @@ A built-in pi package for Ta (enabled by default, can be disabled in Settings
27
29
  - Extensions imported from files are placed only in the user's `extensions/`. To use one in a project, place the directory in the project's `.ta/extensions/` and commit it.
28
30
  - Extensions run code on this machine. Before importing extensions from others, the page warns to only import from trusted sources, and the skill asks Ta to review it first and explain what it does. Marketplace installs are one-click (no approval prompts, following pi's practice); you can view the intro and source code at the bottom of the list or in the detail page.
29
31
  - The marketplace only recognizes the official npm registry (search, manifests, and download counts at registry.npmjs.org). READMEs depend on jsDelivr or GitHub. If either is unreachable, the page shows why and offers "Retry"; this doesn't affect already-installed extensions. Installation still uses pi's npm, respecting your npm config.
30
- - Most npm data is in English; Chinese searches won't find everything. Topic buttons use English keywords.
32
+ - Most npm data is in English; Chinese searches won't find everything. Topic buttons use English keywords.
package/README.md CHANGED
@@ -15,9 +15,11 @@ Ta 自带的 pi 包(默认开启,可在 设置 → 扩展 关闭):告诉
15
15
  - 点卡片进入详情页(`Esc` 或"返回"回到列表,滚动位置不变):头像、名称、说明、作者/版本/下载量/许可证/时间、安装或移除、npm/源代码/主页链接,`pi.video` / `pi.image` 预览,以及 README。带 Web 扩展的包还有"打开":不安装,作为临时扩展直接运行它的页面(`pi.openTemporary`,见 [@celljs/ta-launcher](../ta-launcher/README.md)),之后在"快捷打开"里找到它。
16
16
  - 免安装打开的临时扩展不列在"我的"里,由"快捷打开"安装或删除。
17
17
  - 每一行和市场详情页都有"分享":打开 Ta 的分享弹窗(二维码、链接)。
18
+ - 设置 → 做扩展(`settings.tsx`,`registerSettings`):做、改扩展的对话用哪个模型,存在本包数据的 `makeModel`(`make-model.ts`),不选就跟随默认模型;选的模型用不了时(凭据没了)改用默认模型并提示原因。扩展页的"做一个扩展""修改"、定时任务的"做成扩展"都按它开新对话。
19
+ - 每个对话输入框 + 菜单里的"做成扩展"(`composer.tsx`,`registerComposerAddon`):在这个对话里请 Ta 把对话做的事做成扩展,输入做成表单或按钮,步骤做成命令或工具,结果用合适的界面呈现。对话里只显示一句话,给模型的说明在 `<context>` 块里;回答进行中时排在它后面。设置了做扩展的模型时,改为把这个对话复制一份(`forkToFile`),在副本里用那个模型来做,原对话不动;菜单项的说明会写出模型。频道的输入框也有这个入口([@celljs/ta-channels](../ta-channels/README.md)),由负责人来做;定时任务的"做成扩展"见 [@celljs/ta-cron](../ta-cron/README.md)。
18
20
  - 快捷打开的搜索里加了"已安装""内置""市场"三个分区(`search.ts`,`registerSearch`):前两个在内存里过滤,市场经服务端搜 npm、分页,未安装的有"安装"按钮。
19
21
  - **服务端**(`pi.host`,`web-src/host.ts` → `host/index.mjs`):页面经 `callHost`(`TaPackageServer.callPackageHost`)调用。
20
- - `exportPackage(id)`:把包目录打成一个 `.tgz`(gzip 的 tar,顶层是包目录,去掉 `node_modules`、`.git` 和链接),用 base64 交给页面下载。和 `tar -czf <名字>.tgz <名字>` 的格式相同,没有 Ta 也能用 `tar` 解开。
22
+ - `exportPackage(id)`:把包目录打成一个 `.tgz`(gzip 的 tar,顶层是包目录,去掉 `node_modules`、`.git`、存放密钥的 `.env*`(`.env.example` 除外)与 `.npmrc`,以及链接),用 base64 交给页面下载。和 `tar -czf <名字>.tgz <名字>` 的格式相同,没有 Ta 也能用 `tar` 解开。
21
23
  - `searchMarket(query, from?)`、`marketPackage(name)`(`market.ts`):在服务端查 npm,因为包也装在服务端;结果缓存 5 分钟,同一请求合并。搜索走 `/-/v1/search?text=<词> keywords:pi-package`;npm 对有关键词的搜索仍会把所有 `pi-package` 排在后面,所以只保留名称、说明或关键词里含有每个词的包,出现第一个不相关的就结束分页。详情不取 npm 的整份包文档(发版频繁的包有几十 MB),只取 `/<名字>/latest` 清单、上月下载量,README 先从 jsDelivr 取发布的那一版,没有再取 GitHub 仓库的;README 里的 HTML 图片、链接、标题转成 Markdown(Ta 的 Markdown 不渲染 HTML),去掉徽章,相对链接指向 GitHub 仓库。
22
24
  - `importPackage(data, overwrite?)`:检查文件(只有一个顶层目录、里面有 `package.json`、路径不出目录、不超过 5000 个文件和 20 MB;跳过链接和 macOS tar 附带的 `._*`),放进 agent 目录的 `extensions/<包名去掉 scope>`,pi 无需设置就会加载。同名目录已存在时返回 `exists`,页面问过用户再带 `overwrite` 重来;先写到隐藏的临时目录再换上,会话不会加载到一半的文件。`npm pack` 打出的包(顶层是 `package/`)也能导入。
23
25
 
@@ -27,4 +29,4 @@ Ta 自带的 pi 包(默认开启,可在 设置 → 扩展 关闭):告诉
27
29
  - 从文件导入的扩展只放进用户的 `extensions/`;要给一个项目用,把目录放进项目的 `.ta/extensions/` 并提交。
28
30
  - 扩展会在本机运行代码:导入别人给的扩展前,页面提示只导入信任的来源,技能也要求 Ta 先读一遍再说明它做什么。市场的安装是一键的(照 pi 的做法不弹审批),列表底部和详情里都可以先看介绍和源代码。
29
31
  - 市场只认 npm 官方源(搜索、清单、下载量都在 registry.npmjs.org),README 依赖 jsDelivr 或 GitHub;连不上时页面显示原因和"重试",不影响已安装的扩展。安装仍走 pi 的 npm 安装,遵循用户自己的 npm 配置。
30
- - npm 的数据大多是英文,按中文搜不到;话题按钮用英文关键词。
32
+ - npm 的数据大多是英文,按中文搜不到;话题按钮用英文关键词。
package/host/index.mjs CHANGED
@@ -9,6 +9,7 @@ import { basename, dirname, join } from "node:path";
9
9
  import { gunzipSync, gzipSync } from "node:zlib";
10
10
  var BLOCK = 512;
11
11
  var LEFT_OUT = new Set(["node_modules", ".git", ".DS_Store"]);
12
+ var SECRETS = /^(\.env(\.(?!example$|sample$).+)?|\.npmrc)$/;
12
13
  var PackageArchive;
13
14
  (function(PackageArchive2) {
14
15
  PackageArchive2.MAX_BYTES = 20 * 1024 * 1024;
@@ -18,7 +19,7 @@ var PackageArchive;
18
19
  let bytes = 0;
19
20
  const walk = (directory, prefix) => {
20
21
  for (const name of readdirSync(directory).sort()) {
21
- if (LEFT_OUT.has(name)) {
22
+ if (LEFT_OUT.has(name) || SECRETS.test(name)) {
22
23
  continue;
23
24
  }
24
25
  const file = join(directory, name);
@@ -314,7 +315,7 @@ var MarketUtil;
314
315
  for (let i = 0;i < name.length; i++) {
315
316
  hash = hash * 31 + name.charCodeAt(i) | 0;
316
317
  }
317
- return { letters, hue: Math.abs(hash) % 360 };
318
+ return { letters, tint: Math.abs(hash) % 9 };
318
319
  }
319
320
  MarketUtil.monogram = monogram;
320
321
  function repositoryUrl(repository) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-extensions",
3
- "version": "4.9.1",
3
+ "version": "4.11.0",
4
4
  "description": "A pi package for Ta: the page of extensions, where the user makes one by saying what it should do, and hands extensions on or takes them in as one file",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -27,9 +27,9 @@
27
27
  "watch": "tsc -b -w --preserveWatchOutput"
28
28
  },
29
29
  "devDependencies": {
30
- "@celljs/ta-harness": "4.9.1",
31
- "@celljs/ta-protocol": "4.9.1",
32
- "@celljs/ta-web": "4.9.1",
30
+ "@celljs/ta-harness": "4.11.0",
31
+ "@celljs/ta-protocol": "4.11.0",
32
+ "@celljs/ta-web": "4.11.0",
33
33
  "@types/react": "^19.3.0"
34
34
  },
35
35
  "publishConfig": {
@@ -44,6 +44,11 @@
44
44
  "en": "The Extensions page: ask Ta for a new extension in a sentence, import or export one, or install one from the market.",
45
45
  "zh-CN": "导航栏里的\"扩展\"页:用一句话让 Ta 做扩展,导入、导出,或从市场安装。"
46
46
  },
47
+ "descriptions": {
48
+ "skill:ta-package": {
49
+ "zh-CN": "创建、修改、导出或导入 Ta 的扩展包:扩展给 Ta 加命令和工具,Web 扩展给 Ta 的页面加页面、小组件和消息视图。想让 Ta 或它的页面做点新事、显示新东西,或要分享、导入扩展时用它"
50
+ }
51
+ },
47
52
  "icon": "Puzzle",
48
53
  "web": [
49
54
  "./web/index.js"
@@ -20,7 +20,7 @@ A small tool for now, which the user wants to use for a while rather than keep (
20
20
  web.js the web extension, if the package shows something on the web page
21
21
  ```
22
22
 
23
- List in `pi` only the parts that exist. A web extension with only pages, used now and then, can start when one of them opens rather than with the page: `"webActivation": "open"` in `pi` (temporary ones always do); it is then in Quick open, not in the navigation, and what else it registers is there only while it runs. Also give `pi` what the user reads in the lists of extensions, in the user's language and English: `"title": {"en": "Timer", "zh-CN": "计时器"}`, `"summary"` (one sentence: what it does and where it shows), and `"icon"`, the name of one of `pi.ui.icons`. The pi extension is an ordinary pi extension: read pi's extension documentation (its path is in your instructions) before writing one.
23
+ List in `pi` only the parts that exist. A web extension with only pages, used now and then, can start when one of them opens rather than with the page: `"webActivation": "open"` in `pi` (temporary ones always do); it is then in Quick open, not in the navigation, and what else it registers is there only while it runs. Also give `pi` what the user reads in the lists of extensions, in the user's language and English: `"title": {"en": "Timer", "zh-CN": "计时器"}`, `"summary"` (one sentence: what it does and where it shows), and `"icon"`, the name of one of `pi.ui.icons`; `"category": "game"` for a game, which the Games page then lists (instead of Discover or the navigation). A package whose page lists the extensions of a kind says so: `"lists": ["<kind>"]`, and those are then found only there and in Quick open. Its commands and skills keep their description in English, which pi and the model read; the `/` menu shows them in the user's language from `"descriptions"`, by the name in the menu: `{"standup": {"zh-CN": "汇总今天的进展"}, "skill:standup": {"zh-CN": "…"}}`. The pi extension is an ordinary pi extension: read pi's extension documentation (its path is in your instructions) before writing one.
24
24
 
25
25
  ## The web extension
26
26
 
@@ -45,37 +45,52 @@ export default function (pi) {
45
45
 
46
46
  - `React`: the React of the page. Use it for components and hooks; never bring another.
47
47
  - `ui.setWidget(key, Component, options?)`: a widget. `options.placement` is `'aboveEditor'` (default) or `'belowEditor'`, around the message box as in pi, or `'panel'`, a card in the cards tab of the workbench on the right (it opens when the first card comes): the place for what stays in view, like a timer or a list; `options.title` titles a card. `setWidget(key, undefined)` removes it.
48
- - `registerView(name, { title, render, icon?, location?, order?, head?, pages?, menu? })`: a view of its own; `render` is a component, `icon` a component that draws an icon of `size` pixels in `currentColor` (take one of `ui.icons`). `location: 'page'` (default) fills the main area, with an icon in the navigation on the left; `'sidebar'` is a list of the sidebar: its icon is at the top of the navigation, above the one of the chats (a tab at the bottom of a phone, before the chats), and it fills the sidebar when picked; `'panel'` is a tool of the workbench beside the conversation, as the explorer or the terminal of an IDE: the workbench's `+` and its empty state list it, and it opens as one of its tabs. `'board'` is a card of the board, which a phone brings out with a swipe to the left over its first tab (a button of the navigation elsewhere), for what is good to see at a glance (what runs, what is next): the user takes cards off, puts them back and orders them; render a few lines, no title. `'launcher'` is a section of Quick open, under Recent and Mine. A `sidebar` or `panel` view gets a title and scrolling: render only the content. `order` sorts the views, smaller first (default 100). `head` is a component for the top bar in place of the title: for a `sidebar` view, the row at the top of the sidebar (a search, a button to add), or the middle of a page's bar beside the menu and the workbench button. `pages`, on a `sidebar` view, lists the pages it leads to (ids `<package name>/<view name>`; `assistant/assistant` is the double): the navigation leaves them out. `menu`, on a page, returns its actions as sections of `{ key, label, icon?, disabled?, danger?, run }`; it is called each time the menu opens, and the sidebar view that lists the page draws it as a … on hover.
48
+ - `registerView(name, { title, render, icon?, location?, order?, head?, pages?, menu? })`: a view of its own; `render` is a component, `icon` a component that draws an icon of `size` pixels in `currentColor` (take one of `ui.icons`). `location: 'page'` (default) fills the main area, with an icon in the navigation on the left; `'sidebar'` is a list of the sidebar: its icon is at the top of the navigation, above the one of the chats (a tab at the bottom of a phone, before the chats), and it fills the sidebar when picked; `'panel'` is a tool of the workbench beside the conversation, as the explorer or the terminal of an IDE: the workbench's `+` and its empty state list it, and it opens as one of its tabs. `'board'` is a card of the board, which a phone brings out with a swipe to the left over its first tab (a button of the navigation elsewhere), for what is good to see at a glance (what runs, what is next): the user takes cards off, puts them back and orders them; render a few lines, no title. `'launcher'` is a section of Quick open, under Recent and Mine. A `sidebar` or `panel` view gets a title and scrolling: render only the content; a `page` scrolls itself (its root `{ height: '100%', overflowY: 'auto' }` when it can be taller than the window). `order` sorts the views, smaller first (default 100). `head` is a component for the top bar in place of the title: for a `sidebar` view, the row at the top of the sidebar (a search, a button to add), or the middle of a page's bar beside the menu and the workbench button. `pages`, on a `sidebar` view, lists the pages it leads to (ids `<package name>/<view name>`; `assistant/assistant` is the double): the navigation leaves them out. `menu`, on a page, returns its actions as sections of `{ key, label, icon?, disabled?, danger?, run }`; it is called each time the menu opens, and the sidebar view that lists the page draws it as a … on hover.
49
49
  - `registerMessageRenderer(customType, Component)`: shows the messages the pi extension sends with `pi.sendMessage({ customType, content, display: true, details })`; the component gets `{ message }`, `message.details` holds the data.
50
+ - `registerCodeRenderer(language, Component)`: draws the fenced blocks of that language (` ```name `) in replies and in `ui.Markdown`, as a card of the package's own: the component gets `{ code, language, closed }`, `closed` false while the reply still streams the block (the code may stop anywhere); when it throws, the block shows as code. The way to have the model show something rather than write it: tell it in a `<ta-…>` section of the system prompt (`before_agent_start` of the pi extension) to write such a block, as `@celljs/ta-glance` does with `ta-glance`. Newer than some Ta apps: `pi.registerCodeRenderer?.(…)`.
50
51
  - `registerTool({ name, description, parameters, execute(toolCallId, params) })`: a tool the model can call in the conversations the page opens, which runs in the browser; `parameters` is a JSON schema of an object; `execute` returns the text the model reads, or throws.
51
- - `registerOpener(link => boolean)`: opens what links of replies point to: `{ type: 'file', cwd, path, selection? }` (`selection` is `{ startLine, startColumn?, endLine?, endColumn? }`, from 1), `{ type: 'directory', cwd, path }` or `{ type: 'url', url }`; return `true` when it opened it, else the next opener is asked. @celljs/ta-workspace opens files, directories and pages already; register one only for links the package shows its own way.
52
- - `registerComposerAddon({ actions?(conversation), above?, subscribe?(listener) })`: adds to the message box of every conversation (the double's, an agent's, any other): `actions` gives a section of entries of its + menu (`{ key, label, icon?, detail?, run() }`, or `items` for a list shown in its place, entries with `checked` and `group`); `above` is a component drawn above the box with `{ conversation }`; `subscribe` tells the boxes to read `actions` again. `conversation` is `{ sessionId, sessionFile?, cwd?, kind: 'double' | 'chat', group?, title? }`.
52
+ - `registerToolRenderer((toolName, next) => renderer | undefined)`: how calls of tools read in conversations, as pi's `registerToolRenderer` does in a terminal; for the tools of the package's pi extension, of `registerTool`, or any other. `renderer.renderCall(args)` returns `{ verb, target?, code?, icon? }`: the verb in the language of the page (`ui.language`), what it is on, `code` for a command set in monospace, `icon` a component drawn at `size` pixels before the target (keep one component per target, not a new one each call). Without one a tool shows its name. `next()` is what the resolvers after it would use: return `next()` for the tools that are not yours.
53
+ - `registerOpener(link => boolean)`: opens what links of replies point to: `{ type: 'file', cwd, path, selection? }` (`selection` is `{ startLine, startColumn?, endLine?, endColumn? }`, from 1), `{ type: 'directory', cwd, path }` or `{ type: 'url', url }`; return `true` when it opened it, else the next opener is asked. @celljs/ta-workspace opens files, directories and pages already; register one only for links the package shows its own way. `registerOpener(opener, { specific: true })` is for links of its own kind only (a link of a share): it is asked first, and also for a link that goes out of Ta (scanned, opened with Cmd or Ctrl, pasted in Quick open).
54
+ - `registerSessionMenu(session => items)`: entries of the menu of a conversation in a list (a right click or a held finger on its row), `session` being `{ sessionId?, sessionFile?, cwd, title, group? }`; items `{ key, label, icon?, disabled?, danger?, run }`. `ui.custom(({ close }) => …)` shows a component of the extension over the page wherever the user is, as pi's `ctx.ui.custom`: draw a `ui.Dialog` in it; it returns a function that takes it away. Both are newer than some Ta apps: `pi.registerSessionMenu?.(…)`, `pi.ui.custom ?? fallback`.
55
+ - `registerComposerAddon({ actions?(conversation), above?, subscribe?(listener) })`: adds to the message box of every conversation (the double's, an agent's, any other): `actions` gives entries of its + menu (`{ key, label, icon?, detail?, run() }`, or `items` for a list shown in its place, entries with `checked` and `group`). Every entry is a tile of the menu's grid, four by two a page that swipes sideways, so more entries never make the menu taller: an icon above a short label (2 to 6 characters in Chinese; a longer one goes in `title`, and `detail` shows on hover only). A setting of the conversation has `setting: true` and its value as `detail`, shown under the label; one that is on or off has `toggle: true` and `checked` (its icon lit, on or off under it; the menu stays open); `above` is a component drawn above the box with `{ conversation }`; `subscribe` tells the boxes to read `actions` again. `conversation` is `{ sessionId, sessionFile?, cwd?, kind: 'double' | 'chat', group?, title? }`.
56
+ - `registerChatIcon({ icon(chat), subscribe?(listener) })`: an icon for conversations of the package that are no agent (a brief it writes, a question it asks), by `chat.sessionFile`: `{ icon, tint?, archiveDays? }` (`archiveDays`: archived sooner than the user's setting, for a question asked in passing), a tile in the lists and on their notices in place of the letter of the directory; answer at once from what the extension holds, and call the listener when that changes. Newer than some Ta apps: `pi.registerChatIcon?.(…)`.
57
+ - `registerHomeItems({ items(), subscribe(listener) })`: rows of the double's home, under the double (`{ id, title, detail?, icon, tint?, at?, unseen?, open() }`), for what the user looks at each day (a daily brief): not tasks (`registerTasks`) nor a conversation of the lists alone; `unseen` is the amber dot of a row. The page lists them with `ui.useHomeItems()`. `ui.pinChat(sessionFile, pinned?)` pins a conversation the extension made to the top of the lists, once (the user may unpin it). Both newer than some Ta apps: `pi.registerHomeItems?.(…)`, `pi.ui.pinChat?.(…)`.
58
+ - `registerSettings({ title, icon?, rows })`: a section of Ta's settings, after its own, for what the user sets once (a model the extension uses, a choice it makes); `rows` are `{ key, label, description?, render, stacked? }`, `render` the component of the control (beside the label, under it with `stacked`), its value kept with `storage`. Do not add one for what a page of the extension shows anyway.
53
59
  - `on(type, handler)`: events of the conversation shown, as pi sends them (`agent_start`, `agent_end`, `message_end`, `tool_execution_end`, ...).
54
60
  - `sendUserMessage(text)`: sends a message to the conversation shown as if the user typed it; `'/name args'` runs a command of a pi extension.
55
61
  - `switchSession(sessionId, opening?)`: shows another open session of ta serve (an id of `server.listSessions()`) as the conversation; on a phone the drawer closes. Pass a promise of the id for a session still opening (`{ title, cwd }` in `opening` says what it is): it is in front at once, showing that it opens, so a click never waits on the server.
56
62
  - `reloadExtensions()`: after the extension installed, imported, turned on or off (`packages.setPackageEnabled(id, enabled)`) or removed a package itself (`packages.installPackage`, `packages.removePackage`), loads the web extensions and the pi extensions of the conversation again, as the end of a reply does. `packages.listPackages()` lists every package Ta loads, with what each holds.
57
63
  - `ui.notify(message, type?)`: a short notice; `type` is `'info'`, `'warning'` or `'error'`. `ui.confirm(title, message?, { confirmLabel?, danger? })` asks before going ahead and resolves with the answer; `danger` for what cannot be undone.
64
+ - `ui.notifySession({ key, sessionId?, sessionFile?, cwd?, level, text, options?, actions? })`: tells the user what a conversation said, as a messenger tells of a message; `level` is `'ask'` (it needs them), `'failed'` or `'done'`. The page decides how: nothing while they look at that conversation (nor for a task the double follows, unless it asks), on a phone or a tablet nothing pops up (the unread dots of the list and of the Chats tab tell), on a computer a banner with its face and name while the page is in front (a tap opens it; `options` are answers sent as their message, once from whichever page), a notice of the system otherwise. Give each piece of news one `key` on every page; call it with `?.` for an older Ta app. The built-in `ta-notify` already tells of every turn, failure, dialog and `notify_user`: use this only for news of your own.
58
65
  - `ui.input(title, placeholder?, { value? })` and `ui.editor(title, prefill?)`: ask for one line or several, as pi's; they resolve with the text, or `undefined` when the user cancelled.
59
66
  - `ui.openEditor({ id, title, render, icon?, onClose? }, { preview?, preserveFocus? })`: a tab beside the conversation, for a file, a diff, a page or anything to read at length; opening an id that is open shows it again. With `preview` (a single click), the next preview takes its place until it is kept (`ui.pinEditor(id)`, or a double click on it). `ui.setEditorDirty(id, dirty)` marks it changed and not saved: the user is asked before it closes. `ui.closeEditor(id)` closes it; `onClose` runs when the user does. `ui.useActiveEditor()`: a React hook, the id of the tab shown.
60
67
  - `ui.CodeEditor` (`{ path, value, readOnly?, line?, column?, endColumn?, selection?, onChange?, onSave? }`; `selection`, `{ startLine, startColumn?, endLine?, endColumn? }`, selects those lines and shows them in the middle) and `ui.DiffEditor` (`{ path, original, modified, inline?, readOnly?, onChange?, onSave?, onDiff? }`): Monaco, bundled with the page, for the text of a file and the change between two texts.
68
+ - `ui.Game` (`{ config(Phaser, page), onReady?(game) }`) and `ui.Game3D` (`{ setup(context), onReady?(context) }`): a game on Phaser 4 or a 3D one on Three.js, the game engines of the page; read the ta-game skill before making one. An element that takes the touches that start on it (a canvas to draw on, a joystick; a game has it already) carries the attribute `data-own-gestures`: Ta's slides then start only from an edge of the screen there, and a held finger opens no menu. `ui.FullScreen` (`{ children, className?, style? }`) covers all of the page while it is mounted, the shell and the notch too (pad what you draw by `env(safe-area-inset-*)`), above the keyboard; its touches are all its own, even at an edge, so give the user a button out. Mount it once around what it shows, not around a toggle (its children would start again), and write `pi.ui.FullScreen ?? Fallback` for an app older than it.
61
69
  - `ui.createTerminal({ cols?, rows?, cwd? })`: a terminal as VS Code's (xterm.js on WebGL, in the page's theme), loaded the first time one is made; URLs and paths of files in it (`src/a.ts:10:5`) open with Cmd or Ctrl + click, paths from `cwd` or the directory the shell reports (OSC 7): `write(data)` the program's output, `onData(listener)` what the user types, `onResize(listener)` its new size in characters, `attach(element)` shows it in an element with a size and `position: relative` (returns the function that takes it out; it keeps its screen meanwhile), `focus()`, `dispose()`. `pi.terminals` runs a shell of the server behind it.
62
- - `ui.useCwd()`: a React hook, the directory of the conversation shown. `ui.useSessionId()`: the session of the conversation shown.
70
+ - `ui.useDevice()`: a React hook, where the page runs: `{ layout, touch, handheld, keyboard }`, `layout` being `'compact'` (a phone, a narrow window: the navigation a drawer, the workbench over the conversation), `'medium'` or `'expanded'`; `touch` a finger, `handheld` a phone, `keyboard` the on-screen keyboard open. The root carries the same as `data-layout`, `data-touch`, `data-handheld` and `data-keyboard`, for styles (`:root[data-handheld] .my-row { … }`). Adapt how things look by these, never by a width, `matchMedia` or a user agent of your own.
71
+ - What only some devices have: `ui.scanCode` and `ui.scan` only in the Ta app on a phone; `ui.desktop` (the file manager, the user's browsers), `ui.debugWebview` and `ui.supportsWebview` only in Ta Desktop; elsewhere they are `undefined` (`supportsWebview` false). A package loads on every device, so check for what it needs where it uses it (`pi.ui.scanCode && h(ScanButton)`) and let the rest work without it. Register views, widgets and settings on every device and let their components draw what fits: the function of the extension runs once, and a window is resized, a tablet turns, so what it registered by the layout of that moment would stay wrong. Register a tool only where what it runs on is there (`if (pi.ui.scanCode) pi.registerTool(…)`), and say in its description what it needs: a conversation keeps the tools of the page that opened it, and a call of one waits until a page that has the tool is in the conversation.
72
+ - `ui.useCwd()`: a React hook, the directory of the conversation shown; the default directory while a page, Discover or the lists of a phone are in front. `ui.useSessionId()`: the session of the conversation shown.
63
73
  - `ui.showView(id)`: shows a view of any extension by its id, a page in the main area or a workbench tool as its tab; `''` shows the conversation again. `ui.useView(id)`: a React hook, `{ title, location, shown, menu? }` while that view is loaded, else `undefined`.
64
- - `ui.Composer`: the message box of every conversation, `{ placeholder?, onSend(text), mentions?, mentionLabel?, actions? }`: `mentions` (`{ name, detail? }[]`) is what `@` lists; `actions` are sections of its + menu, entries `{ key, label, icon?, detail?, insert? | run() }` (`insert` puts text at the caret). Use it for any conversation an extension shows, rather than a box of its own. `ui.Markdown` (`{ text }`) renders messages as the conversations do. `ui.Empty` (`{ title, hint?, compact?, tone?, picture?, children? }`) is what an empty list or view shows, as Ta's own lists: a short title without a full stop, at most one quieter hint, centered in its parent (a column of flex); `compact` in a menu, picker or dialog; `picture` above it where seeing what will be there helps (a first page, a list the user fills). Use it rather than text of your own. `ui.Picture` (`{ width?, height?, frame?, className?, children }`, 160 by 96 in a rounded frame unless told) is a small picture as Ta's own: draw a few `rect`, `circle`, `path` and `text` in it with the classes `ta-pic-pane` (a surface), `ta-pic-line` (a bar of text), `ta-pic-box` (an outline), `ta-pic-accent` (what it is about), `ta-pic-mark` (green), `ta-pic-soft` (half of it), `ta-pic-dot`, `ta-pic-bad` (red), `ta-pic-path` (a dashed way), `ta-pic-stroke` (a green line), `ta-pic-tick` (a line on green) and `ta-pic-text` (code), never colors of your own, so it follows the theme. `ui.PictureCards` (`{ cards, columns?, compactColumns? }`, cards `{ key, picture, label, hint?, title?, disabled?, onPick() }`) is a row of them to pick from, as the suggestions of an empty conversation. `ui.Dialog` (`{ title, onClose, children }`) is a dialog over the whole page, as Ta's own: use it to make or change things rather than a form in a sidebar.
65
- - `ui.usePages()`: a React hook, every page there is (`{ id, extension, title, icon?, state, onOpen, place, usedAt?, source?, temporary? }`), what Quick open lists; `ui.stopExtension(name)` stops one that started on open, `ui.forgetPage(id)` takes one out of Recent. `openTemporary(source, 'link')` opens a package of npm or Git without installing it and shows its first page: ask the user first. `ui.useContextMenu()`: a React hook, `[menu, open]`: render `menu`, and call `open(event, sections)` from `onContextMenu` (a long press on a touch screen is one), sections of `{ key, label, icon?, disabled?, danger?, run }`. `ui.shareExtension({ title, source?, packageId? })` opens Ta's dialog that shares an extension (a link and its QR code), `ui.openShared(text)` opens such a link after asking, and `registerSearch({ key, title, order?, remote?, search(query, offset), subscribe? })` adds a section to the search of Quick open (entries `{ key, title, detail?, icon?, tint?, action?, open(), menu? }`). `ui.QrCode` (`{ text }`) draws a QR code; `ui.scanCode?.(instructions)`, only in the Ta app, scans one with the camera.
74
+ - `ui.Composer`: the message box of every conversation, with its microphone and its hold to talk, `{ placeholder?, onSend(text), mentions?, mentionLabel?, actions?, voiceSends?, onTalkSent?(), onListening?(listening), working?, onStop?(), after? }`: `mentions` (`{ name, detail? }[]`) is what `@` lists; `actions` are sections of its + menu, entries `{ key, label, icon?, detail?, setting?, toggle?, checked?, insert? | run() }` (`insert` puts text at the caret; tiles, `setting` and `toggle` as above). As the double's box: `voiceSends` sends what the microphone hears at once, `onTalkSent` says a message was said by voice (read its answer aloud with `ui.voice`), `onListening` says the user talks now, `working` makes the send button stop (`onStop`) while nothing is typed, `after` are buttons of the page before the microphone. Use it for any conversation an extension shows, rather than a box of its own. `ui.HoldToTalk` (`{ onSend(text), onEdit?(text), hints?, title?, className?, children }`) is a button held to talk, as the bar of the message box: the page dims and listens with its own recognizer (the app's on iOS), 取消 and 编辑 to slide onto; it renders nothing where the page cannot listen. `ui.voice` (`canListen()`, `canSpeak()`, `speak(text, onEnd?)`, `hush()`) reads aloud in the voice of the settings. Never a `SpeechRecognition` or `speechSynthesis` of your own. A page that is a conversation may take a message from another extension: `ui.useView(id).send?.(text)` (the double's page, `assistant/assistant`, has it; its answer comes as the view's `preview`). `ui.Markdown` (`{ text }`) renders messages as the conversations do. `ui.Empty` (`{ title, hint?, compact?, tone?, picture?, children? }`) is what an empty list or view shows, as Ta's own lists: a short title without a full stop, at most one quieter hint, centered in its parent (a column of flex); `compact` in a menu, picker or dialog; `picture` above it where seeing what will be there helps (a first page, a list the user fills). Use it rather than text of your own. `ui.Picture` (`{ width?, height?, frame?, className?, children }`, 160 by 96 in a rounded frame unless told) is a small picture as Ta's own: draw a few `rect`, `circle`, `path` and `text` in it with the classes `ta-pic-pane` (a surface), `ta-pic-line` (a bar of text), `ta-pic-box` (an outline), `ta-pic-accent` (what it is about), `ta-pic-mark` (green), `ta-pic-soft` (half of it), `ta-pic-dot`, `ta-pic-bad` (red), `ta-pic-path` (a dashed way), `ta-pic-stroke` (a green line), `ta-pic-tick` (a line on green) and `ta-pic-text` (code), never colors of your own, so it follows the theme. `ui.PictureCards` (`{ cards, columns?, compactColumns? }`, cards `{ key, picture, label, hint?, title?, disabled?, onPick() }`) is a row of them to pick from, as the suggestions of an empty conversation. `ui.Dialog` (`{ title, onClose, children }`) is a dialog over the whole page, as Ta's own: use it to make or change things rather than a form in a sidebar.
75
+ - `ui.usePages()`: a React hook, every page there is (`{ id, extension, title, icon?, state, onOpen, place, usedAt?, source?, temporary? }`), what Quick open lists; `ui.stopExtension(name)` stops one that started on open, `ui.forgetPage(id)` takes one out of Recent. `openTemporary(source, 'link')` opens a package of npm or Git without installing it and shows its first page: ask the user first. `ui.useContextMenu()`: a React hook, `[menu, open]`: render `menu`, and call `open(event, sections)` from `onContextMenu` (a long press on a touch screen is one), sections of `{ key, label, icon?, disabled?, danger?, run }`. `ui.shareExtension({ title, source?, packageId? })` opens Ta's dialog that shares an extension (a link and its QR code), `ui.openShared(text)` opens such a link after asking, and `registerSearch({ key, title, order?, remote?, search(query, offset), subscribe? })` adds a section to the search of Quick open (entries `{ key, title, detail?, icon?, tint?, action?, open(), menu? }`). `ui.QrCode` (`{ text }`) draws a QR code; `ui.ImageViewer` (`{ src, alt?, className?, onLoad?, onBackground?, onPrevious?, onNext?, autoFocus? }`) shows a picture to zoom and drag, as the previews of the workbench do (it fills a column of flex; `onPrevious` / `onNext` go to the pictures beside it, by side buttons and ← →); `ui.scanCode?.(instructions)`, only in the Ta app, scans one with the camera; `ui.scan?.()` is the Scan of the page itself (Discover, the + of the first list), which opens what the code carries (a computer, a link of an extension, a page, text to copy).
76
+ - What waits on ta serve says so, so that the user sees the click took: `ui.useBusy()`, a React hook, `[busy, run]`; `run(action)` stays busy until what `action` returns settles and runs nothing else meanwhile (a second click). Mark what waits with the page's classes, which show it only once it took a moment: `ta-busy` on a button with `<span className="ta-spinner ta-busy-mark" />` in it (add `ta-on-brand` on a button of the brand's color), `ta-pending` on a row being taken away, `<span className="ta-spinner ta-later" />` for a spinner of its own. `ui.Switch` (`{ checked, onChange, label, disabled? }`) is the page's switch: an `onChange` that returns a promise moves it at once, its knob turning until done. Both are newer than some Ta apps: `(pi.ui.useBusy ?? fallback)()`, `pi.ui.Switch ?? fallback`.
66
77
  - `ui.Avatar`: Ta's avatar, the Cell logo, as a component `{ size?, mood?, mark? }`; `mark`, one or two characters, tells agents apart. Use it wherever Ta speaks, and draw Ta no other way.
67
78
  - `ui.icons`: the lucide icons of the page by name (`Plus`, `Hash`, `Search`, `Files`, ...): a web extension cannot import them. Check for one before using it: the list only grows.
68
79
  - `storage.get(key)` and `storage.set(key, value)`: small JSON values kept on the server for the package, so they stay across browsers and devices; setting `null` removes a key. A package keeps at most 4 MB there. `storage.onChange(keys => ...)` hears keys changed by other pages or the server. `storage.directory(cwd)` has the same methods for values of one directory (use `ui.useCwd()`), such as the folders open in a tree: keep there what belongs to a directory, and in `storage` what belongs to the user.
69
80
  - `ui.theme` (`'light'` or `'dark'`) and `ui.language` (`'zh-CN'` or `'en-US'`): write the words of the extension in the language of the page.
81
+ - `files`: the bytes of a file, for what the page cannot load by URL. `files.byUrl` is false when the page is not served by ta serve itself (the app on a phone, a page through a relay): then a URL of `workspace.fileUrl` (an image, a page) does not load, and `files.read(url)` gives `{ type, size, data }` instead — over the WebSocket, sealed end to end. Use it for pictures and pages of the workspace that must show anywhere.
70
82
  - The services of ta serve, for what the rest cannot do, all on its one connection: `server` (sessions: the commands of pi's RPC mode, `listSessions`, `openSession`, `prompt`, ...), `workspace` (files and programs of a directory: `listDirectory`, `readFile`, `writeFile`, `fileUrl`, `findFiles`, `runCommand`), `terminals` (`openTerminal`, `writeTerminal`, ...; output by `onTerminalData`) and `packages` (`listPackages`, `installPackage`, `removePackage`, and for temporary packages `openTemporaryPackage`, `updateTemporaryPackage`, `installTemporaryPackage`).
83
+ - `rooms`: rooms shared with other Ta through the relay, end to end (docs/design/ta-link.md 3), for playing or working together: `createRoom({ kind, title, view? })` (`kind` your own, to find your rooms by; `view` the page "Open" shows), `invite(room)` (a link and, with `ui.QrCode`, its code; the owner only), `join(link)` (ask the user first: it only asks the owner, who answers in their own Ta), `listRooms()` (`{ id, kind, title, owner, status, connected, members: [{ member, name, online, self, owner }] }`), `send(room, data, to?)` (JSON, 64 KB, to every other member or one), `getState(room)` and `setState(room, key, value, version?)` (with `version`, only if it is still that one: `{ ok, version }`; read again and set again when `ok` is false), `leave(room)`. `onRoomEvent(event => …, { messages? })` hears `message`, `state`, `request` and `rooms` (read the list again); pass `messages: false` where you only list rooms. Never call `answer` but on the user's word: the Rooms page (@celljs/ta-rooms) asks them. Newer than some Ta apps: `pi.rooms?.…`, `pi.onRoomEvent?.(…)`.
71
84
 
72
- Look like the page: inherit its font, and use its colors through CSS variables, which follow the light and dark theme: `var(--ta-text)`, `var(--ta-secondary)`, `var(--ta-muted)`, `var(--ta-card)`, `var(--ta-raised)`, `var(--ta-border)`, `var(--ta-accent)`, `var(--ta-red)`. Radius 8px for controls. Write a font size in px as `calc(13px * var(--ta-font-scale))` (a line height in px too), so that it follows the font size of the settings; the messages of a conversation and its field carry the class `ta-conversation`, which adds the font size of conversations. Keep data the extension must remember with `pi.storage`; `localStorage` only for what belongs to one browser, under keys that start with the package name.
85
+ Look like the page: inherit its font, and use its colors through CSS variables, which follow the light and dark theme: `var(--ta-text)`, `var(--ta-secondary)`, `var(--ta-muted)`, `var(--ta-card)`, `var(--ta-raised)`, `var(--ta-border)`, `var(--ta-accent)`, `var(--ta-red)`; a tile or a letter in a color of its own as `var(--ta-tint-<n>)` under `var(--ta-tint-ink-<n>)`, with `<n>` from 0 to 8 (taken from the colors of the agents' faces: blue, red, yellow, green, orange, violet, teal, pink, sky). Radius 8px for controls. A button is the page's: 32px high, `1px solid var(--ta-border)`, transparent, `font-weight: 500`; a segmented control a track of `var(--ta-raised)` with its chosen segment on `var(--ta-segment)`. Write a font size in px as `calc(13px * var(--ta-font-scale))` (a line height in px too), so that it follows the font size of the settings; the messages of a conversation and its field carry the class `ta-conversation`, which adds the font size of conversations. Keep data the extension must remember with `pi.storage`; `localStorage` only for what belongs to one browser, under keys that start with the package name.
73
86
 
74
87
  The two halves talk through the conversation: the web extension sends `/command args` with `sendUserMessage`; the pi extension answers with `pi.sendMessage` and a `customType` the web extension renders.
75
88
 
76
89
  ## Packages that come with Ta
77
90
 
78
- Ta comes with some packages of its own, which are on until the user turns them off in Settings → Extensions: `@celljs/ta-workspace` (the explorer, search, source control, terminals and browser beside the conversation), `@celljs/ta-channels` (agents and channels), `@celljs/ta-computer-use` (desktop apps through Cua Driver), `@celljs/ta-changes` (the files each reply changed, their diffs, and undo), `@celljs/ta-cron` (prompts that run on a schedule, with the Scheduled page, `/loop`, `/remind`, `/schedule` and the tool `schedule_task`), `@celljs/ta-bots` (bots of WeChat and WeCom connected to the double, an agent or a conversation, with the tool `bot_send_file`), `@celljs/ta-agents` (other coding agents such as CodeBuddy Code, Claude Code and Codex as models), `@celljs/ta-launcher` (Quick open: Recent and Mine, and links of extensions opened without installing) and `@celljs/ta-extensions` (this skill, and the Extensions page in the navigation, which lists the user's packages to change, export or remove and imports others). Do not copy or change them; build a new package for something new. The web page calls packages "extensions": use that word with the user.
91
+ Ta comes with some packages of its own, which are on until the user turns them off in Settings → Extensions: `@celljs/ta-workspace` (the explorer, search, source control, terminals and browser beside the conversation), `@celljs/ta-channels` (agents and channels), `@celljs/ta-computer-use` (desktop apps through Cua Driver), `@celljs/ta-changes` (the files each reply changed, their diffs, and undo), `@celljs/ta-cron` (prompts that run on a schedule, with the Scheduled page, `/loop`, `/remind`, `/schedule` and the tool `schedule_task`), `@celljs/ta-games` (the Games page, and the ta-game skill: games and game-like extensions on Phaser and Three.js, the engines of the page, `ui.Game` and `ui.Game3D`), `@celljs/ta-bots` (bots of WeChat and WeCom connected to the double, an agent or a conversation, with the tool `bot_send_file`), `@celljs/ta-agents` (other coding agents such as CodeBuddy Code, Claude Code and Codex as models), `@celljs/ta-manual` (the User manual page under Discover and the ta-manual skill: how to use Ta, a picture and a sentence for each step), `@celljs/ta-launcher` (Quick open: Recent and Mine, and links of extensions opened without installing), `@celljs/ta-share` (conversations, pages and files shared by links, My shares, and the tool `share_link`), `@celljs/ta-rooms` (the Rooms page under Discover: who asks to join, the user's rooms and Ta friends, and links that invite) and `@celljs/ta-extensions` (this skill, and the Extensions page in the navigation, which lists the user's packages to change, export or remove and imports others). Do not copy or change them; build a new package for something new. The web page calls packages "extensions": use that word with the user.
92
+
93
+ A web extension can read and drive the scheduled tasks of `@celljs/ta-cron`, to show what a task finds in a page of its own: `pi.packages.callPackageHost('@celljs/ta-cron', method, params)` with `list` (the tasks: `{ id, name, prompt, schedule, cwd, enabled, nextRunAt?, lastRunAt?, lastStatus?, runCount, failCount }`), `get` `[id]`, `runs` `[id, limit?]` (newest first: `{ id, status, trigger, startedAt, endedAt?, summary?, error?, sessionFile? }`, `status` one of `running`, `success`, `error`, `missed`; `summary` is the last answer of the run, at most 4000 characters), `run` `[id]` (now; resolves once it started), `setEnabled` `[id, enabled]` and `update` `[id, patch]` (the fields of the update of `schedule_task`). Read them again when the page shows and every few seconds while a run is `running`; the task keeps its schedule, so the extension schedules nothing of its own.
79
94
 
80
95
  Under `ta serve`, with `@celljs/ta-channels` on, you have tools to build a team for what the user wants: `create_agent` (a name and a role: another Ta with its own session), `create_channel` (agents, the lead first), `add_to_channel` (agents that exist, after the members; the lead stays), `post_to_channel` (a message; the agents it names with @ answer, or the lead, and they may hand on a few times) and `list_channels`. The agents run in ta serve, so they go on when the page closes. When the user asks for a team, for roles working together or for a review by several hands, create the agents and the channel and post the goal; do not write a package for it. In `ta` without `serve` the tools say they need `ta serve`: tell the user so.
81
96
 
@@ -92,4 +107,4 @@ A package travels as one `.tgz` file: a gzipped tar of its directory, the direct
92
107
 
93
108
  1. `node --check web.js` and, for the pi extension, read it once more against pi's documentation.
94
109
  2. When your reply on the web page ends, the page loads new and changed web extensions and their tools, and reloads the pi extensions of its conversation. Otherwise the page loads them when it is shown again, and `/reload` reloads pi extensions in the terminal. Do not ask the user to restart anything.
95
- 3. Tell the user in one or two sentences what the package does and where it shows. No file listings unless asked.
110
+ 3. Tell the user in one or two sentences what the package does and where it shows. No file listings unless asked.
package/web/index.js CHANGED
@@ -1,6 +1,12 @@
1
1
  // web-src/extensions-util.ts
2
2
  var ExtensionsUtil;
3
3
  ((ExtensionsUtil) => {
4
+ function request(text, ask) {
5
+ const typed = text.trim();
6
+ const command = /^(\/\S+)\s*([\s\S]*)$/.exec(typed);
7
+ return command ? `${command[1]} ${ask(command[2].trim())}` : ask(typed);
8
+ }
9
+ ExtensionsUtil.request = request;
4
10
  function group(packages) {
5
11
  const byName = (a, b) => a.name.localeCompare(b.name);
6
12
  return {
@@ -40,6 +46,14 @@ var EN = {
40
46
  placeholder: "Describe the extension, for example: a pomodoro timer beside the conversation",
41
47
  makePrompt: "Make an extension: {text}",
42
48
  changePrompt: "Change the extension {name} (in {root}): {text}",
49
+ fromChat: "Make an extension",
50
+ fromChatDetail: "Of what this conversation did",
51
+ fromChatAsk: "Make what this conversation did an extension, to do it again in a click",
52
+ fromChatModel: "In a new conversation, on {model}",
53
+ settingsTitle: "Making extensions",
54
+ modelLabel: "Model",
55
+ modelHint: "The new conversations that make or change an extension use it (the Extensions page, Make an extension of a scheduled task, and of a conversation, which then goes on in a copy of it); unset, the default model",
56
+ modelFailed: "The model for making extensions ({model}) cannot be used, so the default one is: {message}",
43
57
  changeTitle: "Change {name}",
44
58
  changePlaceholder: "What should it do differently?",
45
59
  mine: "Yours",
@@ -89,6 +103,7 @@ var EN = {
89
103
  change: "Change",
90
104
  remove: "Remove",
91
105
  copySource: "Copy the source",
106
+ more: "More",
92
107
  copied: "Copied {source}",
93
108
  removeTitle: "Remove {name}?",
94
109
  removeDetail: "Its pages, cards and commands go with it.",
@@ -160,6 +175,14 @@ var ZH = {
160
175
  placeholder: "描述你想要的扩展,例如:在对话旁放一个番茄钟",
161
176
  makePrompt: "做一个扩展:{text}",
162
177
  changePrompt: "修改扩展 {name}(在 {root}):{text}",
178
+ fromChat: "做成扩展",
179
+ fromChatDetail: "把这次对话做成工具",
180
+ fromChatAsk: "把这次对话做的事做成扩展,以后一键就能再用",
181
+ fromChatModel: "用 {model} 在新对话里做",
182
+ settingsTitle: "做扩展",
183
+ modelLabel: "模型",
184
+ modelHint: "扩展页和各处“做成扩展”开的对话用这个模型;不选就跟随默认模型",
185
+ modelFailed: "做扩展的模型({model})现在用不了,已改用默认模型:{message}",
163
186
  changeTitle: "修改 {name}",
164
187
  changePlaceholder: "想让它有什么不同?",
165
188
  mine: "我的扩展",
@@ -209,6 +232,7 @@ var ZH = {
209
232
  change: "修改",
210
233
  remove: "移除",
211
234
  copySource: "复制来源",
235
+ more: "更多",
212
236
  copied: "已复制 {source}",
213
237
  removeTitle: "移除扩展 {name}?",
214
238
  removeDetail: "它的页面、卡片和命令也会一起移除。",
@@ -270,6 +294,36 @@ var ExtensionWords;
270
294
  ExtensionWords.fill = fill;
271
295
  })(ExtensionWords ||= {});
272
296
 
297
+ // web-src/make-model.ts
298
+ var MAKE_MODEL_KEY = "makeModel";
299
+ var MakeModel;
300
+ ((MakeModel) => {
301
+ async function get(pi) {
302
+ const value = await pi.storage.get(MAKE_MODEL_KEY).catch(() => {
303
+ return;
304
+ });
305
+ return typeof value === "string" && value ? value : undefined;
306
+ }
307
+ MakeModel.get = get;
308
+ function set(pi, model) {
309
+ return pi.storage.set(MAKE_MODEL_KEY, model || null);
310
+ }
311
+ MakeModel.set = set;
312
+ async function open(pi, options) {
313
+ const model = await get(pi);
314
+ if (model) {
315
+ try {
316
+ return (await pi.server.openSession({ ...options, model })).sessionId;
317
+ } catch (error) {
318
+ const message = error instanceof Error ? error.message : String(error);
319
+ pi.ui.notify(ExtensionWords.fill(ExtensionWords.of(pi.ui.language).modelFailed, { model, message }), "warning");
320
+ }
321
+ }
322
+ return (await pi.server.openSession(options)).sessionId;
323
+ }
324
+ MakeModel.open = open;
325
+ })(MakeModel ||= {});
326
+
273
327
  // web-src/actions.ts
274
328
  class PackagesStore {
275
329
  pi;
@@ -286,14 +340,19 @@ class PackagesStore {
286
340
  return () => this.listeners.delete(listener);
287
341
  }
288
342
  patch(id, change) {
289
- this.current = { packages: this.current.packages?.map((pkg) => pkg.id === id ? { ...pkg, ...change } : pkg) };
343
+ this.current = { ...this.current, packages: this.current.packages?.map((pkg) => pkg.id === id ? { ...pkg, ...change } : pkg) };
344
+ this.publish();
345
+ }
346
+ setRemoving(id, on) {
347
+ const others = (this.current.removing ?? []).filter((other) => other !== id);
348
+ this.current = { ...this.current, removing: on ? [...others, id] : others };
290
349
  this.publish();
291
350
  }
292
351
  async load() {
293
352
  try {
294
- this.current = { packages: (await this.pi.packages.listPackages()).filter((pkg) => pkg.origin !== "temporary") };
353
+ this.current = { ...this.current, packages: (await this.pi.packages.listPackages()).filter((pkg) => pkg.origin !== "temporary") };
295
354
  } catch (error) {
296
- this.current = { packages: this.current.packages ?? [] };
355
+ this.current = { ...this.current, packages: this.current.packages ?? [] };
297
356
  this.pi.ui.notify(error instanceof Error ? error.message : String(error), "error");
298
357
  }
299
358
  this.publish();
@@ -318,7 +377,7 @@ class ExtensionActions {
318
377
  return ExtensionWords.of(this.pi.ui.language);
319
378
  }
320
379
  make(text) {
321
- return this.converse(ExtensionWords.fill(this.words.makePrompt, { text: text.trim() }));
380
+ return this.converse(ExtensionsUtil.request(text, (request) => ExtensionWords.fill(this.words.makePrompt, { text: request })));
322
381
  }
323
382
  async change(pkg) {
324
383
  const words = this.words;
@@ -348,11 +407,13 @@ class ExtensionActions {
348
407
  danger: true
349
408
  });
350
409
  if (confirmed) {
410
+ this.store.setRemoving(pkg.id, true);
351
411
  await this.guard(async () => {
352
412
  await this.pi.packages.removePackage(pkg.id);
353
413
  await this.changed();
354
414
  this.pi.ui.notify(ExtensionWords.fill(words.removed, { name: pkg.name }));
355
415
  });
416
+ this.store.setRemoving(pkg.id, false);
356
417
  }
357
418
  }
358
419
  async setEnabled(pkg, enabled) {
@@ -434,7 +495,7 @@ class ExtensionActions {
434
495
  async converse(text) {
435
496
  await this.guard(async () => {
436
497
  const { cwd } = await this.pi.server.getServerInfo();
437
- const { sessionId } = await this.pi.server.openSession({ cwd });
498
+ const sessionId = await MakeModel.open(this.pi, { cwd });
438
499
  await this.pi.switchSession(sessionId);
439
500
  await this.pi.sendUserMessage(text);
440
501
  });
@@ -450,6 +511,90 @@ class ExtensionActions {
450
511
  }
451
512
  }
452
513
 
514
+ // web-src/context.ts
515
+ function icon(pi, name, fallback = "Square") {
516
+ return pi.ui.icons[name] ?? pi.ui.icons[fallback] ?? (() => null);
517
+ }
518
+
519
+ // web-src/react.ts
520
+ var React;
521
+ function bind(react) {
522
+ React = react;
523
+ }
524
+ var idle = () => [false, async (action) => await action()];
525
+ function useBusy(ui) {
526
+ return (ui.useBusy ?? idle)();
527
+ }
528
+
529
+ // web-src/composer.tsx
530
+ var ConversationExtension;
531
+ ((ConversationExtension) => {
532
+ ConversationExtension.CONTEXT = [
533
+ "The user wants what was done in this conversation made into an extension of Ta, with the ta-package skill, kept in extensions/: a tool that does it again without it being explained again.",
534
+ "- Look back over the conversation for what is worth keeping: the task, the steps that worked, the inputs that change from one time to the next, and what came out.",
535
+ "- The inputs become a form or a few buttons, the steps a command or a tool of its pi extension (or a prompt it sends), and the results a view that suits them: a page, a card of the board, or the view of a message, rather than plain text.",
536
+ "- Leave out what was only tried and dropped. When the conversation holds nothing to make a tool of, say so and ask what the extension should do."
537
+ ].join(`
538
+ `);
539
+ function message(language) {
540
+ return `<context>
541
+ ${ConversationExtension.CONTEXT}
542
+ </context>
543
+ ${ExtensionWords.of(language).fromChatAsk}`;
544
+ }
545
+ ConversationExtension.message = message;
546
+ })(ConversationExtension ||= {});
547
+ function composerAddon(pi) {
548
+ let model;
549
+ const listeners = new Set;
550
+ const read = () => void MakeModel.get(pi).then((next) => {
551
+ if (next !== model) {
552
+ model = next;
553
+ for (const listener of listeners) {
554
+ listener();
555
+ }
556
+ }
557
+ });
558
+ read();
559
+ pi.storage.onChange((keys) => keys.includes(MAKE_MODEL_KEY) && read());
560
+ const failed = (error) => pi.ui.notify(error instanceof Error ? error.message : String(error), "error");
561
+ const ask = () => ({ clientMessageId: `ta-extensions:conversation:${Date.now()}`, message: ConversationExtension.message(pi.ui.language) });
562
+ const send = async (conversation) => {
563
+ if (!await MakeModel.get(pi)) {
564
+ await pi.server.prompt(conversation.sessionId, { ...ask(), streamingBehavior: "followUp" });
565
+ return;
566
+ }
567
+ const cwd = conversation.cwd ?? (await pi.server.getServerInfo()).cwd;
568
+ const { entries } = await pi.server.getEntries(conversation.sessionId);
569
+ const last = entries.at(-1)?.id;
570
+ const { sessionFile } = last ? await pi.server.forkToFile(conversation.sessionId, last, "at") : { sessionFile: undefined };
571
+ const sessionId = MakeModel.open(pi, { cwd, sessionFile });
572
+ await pi.switchSession(sessionId, { title: ExtensionWords.of(pi.ui.language).fromChat, cwd });
573
+ await pi.server.prompt(await sessionId, ask());
574
+ };
575
+ return {
576
+ subscribe: (listener) => {
577
+ listeners.add(listener);
578
+ return () => listeners.delete(listener);
579
+ },
580
+ actions: (conversation) => {
581
+ const words = ExtensionWords.of(pi.ui.language);
582
+ const Sparkles = icon(pi, "Sparkles");
583
+ return [
584
+ {
585
+ key: "make-extension",
586
+ label: words.fromChat,
587
+ detail: model ? ExtensionWords.fill(words.fromChatModel, { model: model.slice(model.indexOf("/") + 1) }) : words.fromChatDetail,
588
+ icon: /* @__PURE__ */ React.createElement(Sparkles, {
589
+ size: 16
590
+ }),
591
+ run: () => void send(conversation).catch(failed)
592
+ }
593
+ ];
594
+ }
595
+ };
596
+ }
597
+
453
598
  // web-src/market-store.ts
454
599
  class MarketStore {
455
600
  pi;
@@ -672,6 +817,21 @@ var TaLocation;
672
817
  return name || (remote === null || remote === undefined ? undefined : remote.host) || location;
673
818
  }
674
819
  TaLocation2.basename = basename;
820
+ function homeRelative(location) {
821
+ var _a;
822
+ const remote = parse(location);
823
+ const path2 = remote ? remote.path ? remote.path.slice(1) : "~" : location;
824
+ const match = /^~(?:[\\/]+(.*))?$/.exec(path2);
825
+ return match ? ((_a = match[1]) !== null && _a !== undefined ? _a : "").replace(/[\\/]+$/, "") : undefined;
826
+ }
827
+ TaLocation2.homeRelative = homeRelative;
828
+ function isAbsolute(location) {
829
+ if (homeRelative(location) !== undefined) {
830
+ return false;
831
+ }
832
+ return isRemote(location) || /^([\\/]|[A-Za-z]:)/.test(location);
833
+ }
834
+ TaLocation2.isAbsolute = isAbsolute;
675
835
  function parentPath(path2) {
676
836
  const trimmed = path2.replace(/[\\/]+$/, "");
677
837
  const at = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
@@ -707,8 +867,64 @@ var TaPackageTextUtil;
707
867
  var TaRelayServer = Symbol("TaRelayServer");
708
868
  // ../ta-protocol/esm/common/remote-protocol.js
709
869
  var TaRemoteServer = Symbol("TaRemoteServer");
870
+ // ../ta-protocol/esm/common/room-protocol.js
871
+ var TaRoomServer = Symbol("TaRoomServer");
872
+ var TaRoomWatchUtil;
873
+ (function(TaRoomWatchUtil2) {
874
+ function of(messages, state) {
875
+ const prefixes = Array.isArray(state) ? state.filter((prefix) => typeof prefix === "string" && prefix.length > 0) : [];
876
+ return { messages: messages !== false, state: [...new Set(prefixes)].sort() };
877
+ }
878
+ TaRoomWatchUtil2.of = of;
879
+ function union(watches) {
880
+ let messages = false;
881
+ const state = [];
882
+ for (const watch of watches) {
883
+ messages || (messages = watch.messages);
884
+ state.push(...watch.state);
885
+ }
886
+ return of(messages, messages ? [] : state);
887
+ }
888
+ TaRoomWatchUtil2.union = union;
889
+ function same(a, b) {
890
+ return a === b || !!a && !!b && a.messages === b.messages && a.state.join(`
891
+ `) === b.state.join(`
892
+ `);
893
+ }
894
+ TaRoomWatchUtil2.same = same;
895
+ function hears(watch, event) {
896
+ if (event.type === "message") {
897
+ return watch.messages;
898
+ }
899
+ if (event.type === "state") {
900
+ return watch.messages || watch.state.some((prefix) => event.key.startsWith(prefix));
901
+ }
902
+ return true;
903
+ }
904
+ TaRoomWatchUtil2.hears = hears;
905
+ })(TaRoomWatchUtil || (TaRoomWatchUtil = {}));
710
906
  // ../ta-protocol/esm/common/settings-protocol.js
711
907
  var TaSettingsServer = Symbol("TaSettingsServer");
908
+ // ../ta-protocol/esm/common/ta-extension-host.js
909
+ var TA_HOST_EVENT = "ta:host";
910
+ var TaHostUtil;
911
+ (function(TaHostUtil2) {
912
+ TaHostUtil2.WAIT_MS = 1000;
913
+ function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
914
+ return new Promise((resolve) => {
915
+ const timer = setTimeout(() => resolve(undefined), waitMs);
916
+ const request = {
917
+ name,
918
+ resolve: (answer) => {
919
+ clearTimeout(timer);
920
+ resolve(answer);
921
+ }
922
+ };
923
+ events.emit(TA_HOST_EVENT, request);
924
+ });
925
+ }
926
+ TaHostUtil2.reach = reach;
927
+ })(TaHostUtil || (TaHostUtil = {}));
712
928
  // ../ta-protocol/esm/common/ta-protocol.js
713
929
  var TaServer = Symbol("TaServer");
714
930
  var TaClient = Symbol("TaClient");
@@ -723,6 +939,15 @@ var TaErrorUtil;
723
939
  }
724
940
  TaErrorUtil2.code = code;
725
941
  })(TaErrorUtil || (TaErrorUtil = {}));
942
+ var TaSlashCommandUtil;
943
+ (function(TaSlashCommandUtil2) {
944
+ function description(command, language) {
945
+ var _a, _b;
946
+ const { descriptions } = command;
947
+ return (_b = (_a = descriptions === null || descriptions === undefined ? undefined : descriptions[language]) !== null && _a !== undefined ? _a : descriptions === null || descriptions === undefined ? undefined : descriptions[language.split("-")[0]]) !== null && _b !== undefined ? _b : command.description;
948
+ }
949
+ TaSlashCommandUtil2.description = description;
950
+ })(TaSlashCommandUtil || (TaSlashCommandUtil = {}));
726
951
  var TaMessageContext;
727
952
  (function(TaMessageContext2) {
728
953
  const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
@@ -738,6 +963,109 @@ ${message}`;
738
963
  }
739
964
  TaMessageContext2.strip = strip;
740
965
  })(TaMessageContext || (TaMessageContext = {}));
966
+ var TaImageNote;
967
+ (function(TaImageNote2) {
968
+ const NOTE = /^\[Image: original \d+x\d+, displayed at \d+x\d+\. Multiply coordinates by [\d.]+ to map to original image\.\]$|^\[Image converted from [^\]]+ to [^\]]+\.\]$/;
969
+ function strip(text) {
970
+ const lines = text.split(`
971
+ `);
972
+ const kept = lines.filter((line) => !NOTE.test(line.trim()));
973
+ if (kept.length === lines.length) {
974
+ return text;
975
+ }
976
+ return kept.join(`
977
+ `).replace(/\n+$/, "").replace(/^\n+/, "");
978
+ }
979
+ TaImageNote2.strip = strip;
980
+ })(TaImageNote || (TaImageNote = {}));
981
+ var TaImageSize;
982
+ (function(TaImageSize2) {
983
+ const JPEG_BYTES = 256 * 1024;
984
+ function of(base64) {
985
+ var _a, _b, _c;
986
+ let bytes;
987
+ try {
988
+ const binary = atob(base64.slice(0, Math.ceil(JPEG_BYTES * 4 / 3 / 4) * 4));
989
+ bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
990
+ } catch (_d) {
991
+ return;
992
+ }
993
+ const size = (_c = (_b = (_a = png(bytes)) !== null && _a !== undefined ? _a : gif(bytes)) !== null && _b !== undefined ? _b : webp(bytes)) !== null && _c !== undefined ? _c : jpeg(bytes);
994
+ return size && size.width > 0 && size.height > 0 ? size : undefined;
995
+ }
996
+ TaImageSize2.of = of;
997
+ function u16be(bytes, at) {
998
+ return bytes[at] << 8 | bytes[at + 1];
999
+ }
1000
+ function u16le(bytes, at) {
1001
+ return bytes[at] | bytes[at + 1] << 8;
1002
+ }
1003
+ function u24le(bytes, at) {
1004
+ return bytes[at] | bytes[at + 1] << 8 | bytes[at + 2] << 16;
1005
+ }
1006
+ function u32be(bytes, at) {
1007
+ return (bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3]) >>> 0;
1008
+ }
1009
+ function text(bytes, at, length) {
1010
+ return String.fromCharCode(...bytes.subarray(at, at + length));
1011
+ }
1012
+ function png(bytes) {
1013
+ return bytes.length >= 24 && bytes[0] === 137 && text(bytes, 1, 3) === "PNG" ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
1014
+ }
1015
+ function gif(bytes) {
1016
+ return bytes.length >= 10 && text(bytes, 0, 3) === "GIF" ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
1017
+ }
1018
+ function webp(bytes) {
1019
+ if (bytes.length < 30 || text(bytes, 0, 4) !== "RIFF" || text(bytes, 8, 4) !== "WEBP") {
1020
+ return;
1021
+ }
1022
+ switch (text(bytes, 12, 4)) {
1023
+ case "VP8 ":
1024
+ return { width: u16le(bytes, 26) & 16383, height: u16le(bytes, 28) & 16383 };
1025
+ case "VP8L": {
1026
+ const bits = bytes[21] | bytes[22] << 8 | bytes[23] << 16 | bytes[24] << 24;
1027
+ return { width: (bits & 16383) + 1, height: (bits >> 14 & 16383) + 1 };
1028
+ }
1029
+ case "VP8X":
1030
+ return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
1031
+ default:
1032
+ return;
1033
+ }
1034
+ }
1035
+ function jpeg(bytes) {
1036
+ if (bytes[0] !== 255 || bytes[1] !== 216) {
1037
+ return;
1038
+ }
1039
+ let at = 2;
1040
+ while (at + 9 < bytes.length) {
1041
+ if (bytes[at] !== 255) {
1042
+ return;
1043
+ }
1044
+ const marker = bytes[at + 1];
1045
+ if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
1046
+ return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
1047
+ }
1048
+ at += 2 + u16be(bytes, at + 2);
1049
+ }
1050
+ return;
1051
+ }
1052
+ })(TaImageSize || (TaImageSize = {}));
1053
+ var TaAgentSummary;
1054
+ (function(TaAgentSummary2) {
1055
+ const START = /^\s*<conversation_history_summary>/;
1056
+ const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
1057
+ function read(text) {
1058
+ if (!START.test(text)) {
1059
+ return;
1060
+ }
1061
+ return text.replace(/<\/?(?:conversation_history_summary|summary)>/g, "").replace(/<\/?\w*$/, "").trim();
1062
+ }
1063
+ TaAgentSummary2.read = read;
1064
+ function strip(text) {
1065
+ return text.replace(BLOCK, "");
1066
+ }
1067
+ TaAgentSummary2.strip = strip;
1068
+ })(TaAgentSummary || (TaAgentSummary = {}));
741
1069
  var TaSkillUse;
742
1070
  (function(TaSkillUse2) {
743
1071
  const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
@@ -771,17 +1099,6 @@ var TaExcludedFiles;
771
1099
  TaExcludedFiles2.filter = filter;
772
1100
  })(TaExcludedFiles || (TaExcludedFiles = {}));
773
1101
  var TA_UPLOAD_PART_BYTES = 4 * 1024 * 1024;
774
- // web-src/context.ts
775
- function icon(pi, name, fallback = "Square") {
776
- return pi.ui.icons[name] ?? pi.ui.icons[fallback] ?? (() => null);
777
- }
778
-
779
- // web-src/react.ts
780
- var React;
781
- function bind(react) {
782
- React = react;
783
- }
784
-
785
1102
  // web-src/import-dialog.tsx
786
1103
  function ImportDialog({ pi, actions, onClose }) {
787
1104
  const words = actions.words;
@@ -941,7 +1258,7 @@ var MarketUtil;
941
1258
  for (let i = 0;i < name.length; i++) {
942
1259
  hash = hash * 31 + name.charCodeAt(i) | 0;
943
1260
  }
944
- return { letters, hue: Math.abs(hash) % 360 };
1261
+ return { letters, tint: Math.abs(hash) % 9 };
945
1262
  }
946
1263
  MarketUtil.monogram = monogram;
947
1264
  function repositoryUrl(repository) {
@@ -1021,11 +1338,17 @@ function useMarketStatus(context, name) {
1021
1338
  return !pkg ? { kind: "none" } : pkg.origin === "builtin" ? { kind: "builtin" } : { kind: "installed", pkg };
1022
1339
  }
1023
1340
  function PackageFace({ name, size }) {
1024
- const { letters, hue } = MarketUtil.monogram(name);
1341
+ const { letters, tint } = MarketUtil.monogram(name);
1025
1342
  return /* @__PURE__ */ React.createElement("span", {
1026
1343
  className: "tax-face",
1027
1344
  "aria-hidden": "true",
1028
- style: { width: size, height: size, fontSize: Math.round(size * 0.36), ["--tax-hue"]: hue }
1345
+ style: {
1346
+ width: size,
1347
+ height: size,
1348
+ fontSize: Math.round(size * 0.36),
1349
+ ["--tax-tint"]: `var(--ta-tint-${tint})`,
1350
+ ["--tax-ink"]: `var(--ta-tint-ink-${tint})`
1351
+ }
1029
1352
  }, letters);
1030
1353
  }
1031
1354
  function PackageName({ name }) {
@@ -1673,7 +1996,7 @@ function ExtensionsPage({ context }) {
1673
1996
  function MineView({ context }) {
1674
1997
  const { pi, store, actions, importing } = context;
1675
1998
  const words = actions.words;
1676
- const { packages } = React.useSyncExternalStore((listener) => store.subscribe(listener), () => store.state);
1999
+ const { packages, removing } = React.useSyncExternalStore((listener) => store.subscribe(listener), () => store.state);
1677
2000
  const [starting, setStarting] = React.useState(false);
1678
2001
  const groups = ExtensionsUtil.group(packages ?? []);
1679
2002
  const Composer = pi.ui.Composer;
@@ -1696,7 +2019,8 @@ function MineView({ context }) {
1696
2019
  size: 20
1697
2020
  }), " ", words.heroTitle), /* @__PURE__ */ React.createElement("p", null, words.heroText), /* @__PURE__ */ React.createElement(Composer, {
1698
2021
  placeholder: words.placeholder,
1699
- onSend: make
2022
+ onSend: make,
2023
+ commands: true
1700
2024
  }), /* @__PURE__ */ React.createElement("div", {
1701
2025
  className: "tax-kinds"
1702
2026
  }, /* @__PURE__ */ React.createElement(PictureCards, {
@@ -1743,7 +2067,8 @@ function MineView({ context }) {
1743
2067
  key: pkg.id,
1744
2068
  pi,
1745
2069
  actions,
1746
- pkg
2070
+ pkg,
2071
+ removing: !!removing?.includes(pkg.id)
1747
2072
  })))), groups.installed.length > 0 && /* @__PURE__ */ React.createElement("section", {
1748
2073
  className: "tax-section"
1749
2074
  }, /* @__PURE__ */ React.createElement("div", {
@@ -1756,7 +2081,8 @@ function MineView({ context }) {
1756
2081
  key: pkg.id,
1757
2082
  pi,
1758
2083
  actions,
1759
- pkg
2084
+ pkg,
2085
+ removing: !!removing?.includes(pkg.id)
1760
2086
  })))), /* @__PURE__ */ React.createElement("section", {
1761
2087
  className: "tax-section"
1762
2088
  }, /* @__PURE__ */ React.createElement("div", {
@@ -1790,26 +2116,50 @@ function ShareSteps({ pi, actions }) {
1790
2116
  className: "tax-note"
1791
2117
  }, words.shareMore));
1792
2118
  }
1793
- function PackageRow({ pi, actions, pkg }) {
2119
+ function PackageRow({ pi, actions, pkg, removing }) {
1794
2120
  const words = actions.words;
2121
+ const [switching, run] = useBusy(pi.ui);
2122
+ const { touch, handheld } = pi.ui.useDevice();
2123
+ const [menu, openMenu] = pi.ui.useContextMenu();
1795
2124
  const mine = pkg.origin === "directory";
1796
2125
  const Icon = icon(pi, pkg.icon ?? (mine ? "Puzzle" : "PackageOpen"), mine ? "Puzzle" : "PackageOpen");
2126
+ const More = icon(pi, "Ellipsis");
1797
2127
  const title = TaPackageTextUtil.pick(pkg.title, pi.ui.language) ?? pkg.name;
1798
2128
  const summary = TaPackageTextUtil.pick(pkg.summary, pi.ui.language) ?? pkg.description;
1799
2129
  const tags = [...pkg.resources.map((type) => words.kinds[type]), ...pkg.scope === "project" ? [words.project] : []];
1800
2130
  const share = () => pi.ui.shareExtension({ title, source: mine ? undefined : pkg.source, packageId: pkg.id });
2131
+ const remove = { key: "remove", label: words.remove, icon: "Trash2", danger: true, run: () => actions.remove(pkg) };
1801
2132
  const buttons = mine ? [
1802
2133
  { key: "change", label: words.change, icon: "Pencil", run: () => actions.change(pkg) },
1803
2134
  { key: "export", label: words.export, icon: "Download", run: () => actions.exportPackage(pkg) },
1804
2135
  { key: "share", label: words.share, icon: "QrCode", run: async () => share() },
1805
- { key: "remove", label: words.remove, icon: "Trash2", danger: true, run: () => actions.remove(pkg) }
2136
+ remove
1806
2137
  ] : [
1807
2138
  { key: "copy", label: words.copySource, icon: "Copy", run: () => actions.copySource(pkg) },
1808
2139
  { key: "share", label: words.share, icon: "QrCode", run: async () => share() },
1809
- { key: "remove", label: words.remove, icon: "Trash2", danger: true, run: () => actions.remove(pkg) }
2140
+ remove
1810
2141
  ];
1811
- return /* @__PURE__ */ React.createElement("div", {
1812
- className: `tax-row${pkg.enabled ? "" : " tax-off"}`
2142
+ const item = (button) => ({
2143
+ key: button.key,
2144
+ label: button.label,
2145
+ icon: icon(pi, button.icon),
2146
+ danger: button.danger,
2147
+ run: () => void button.run()
2148
+ });
2149
+ const items = [buttons.filter((button) => button !== remove).map(item), [item(remove)]];
2150
+ const tagList = tags.map((tag) => /* @__PURE__ */ React.createElement("span", {
2151
+ key: tag,
2152
+ className: "tax-tag"
2153
+ }, tag));
2154
+ const description = summary || (mine ? undefined : pkg.source);
2155
+ const SwipeRow = pi.ui.SwipeRow;
2156
+ return /* @__PURE__ */ React.createElement(SwipeRow, {
2157
+ className: "tax-item",
2158
+ actions: [{ key: "remove", label: words.remove, danger: true, run: () => void remove.run() }]
2159
+ }, /* @__PURE__ */ React.createElement("div", {
2160
+ className: `tax-row${pkg.enabled ? "" : " tax-off"}${removing ? " ta-pending" : ""}`,
2161
+ "aria-busy": removing || undefined,
2162
+ onContextMenu: (event) => openMenu(event, items)
1813
2163
  }, /* @__PURE__ */ React.createElement("span", {
1814
2164
  className: "tax-icon"
1815
2165
  }, /* @__PURE__ */ React.createElement(Icon, {
@@ -1822,12 +2172,20 @@ function PackageRow({ pi, actions, pkg }) {
1822
2172
  title: title === pkg.name ? undefined : pkg.name
1823
2173
  }, title), pkg.version && /* @__PURE__ */ React.createElement("span", {
1824
2174
  className: "tax-version"
1825
- }, pkg.version), tags.map((tag) => /* @__PURE__ */ React.createElement("span", {
1826
- key: tag,
1827
- className: "tax-tag"
1828
- }, tag))), (summary || !mine) && /* @__PURE__ */ React.createElement("div", {
2175
+ }, pkg.version), !handheld && tagList), (description || handheld && tags.length > 0) && /* @__PURE__ */ React.createElement("div", {
2176
+ className: "tax-meta"
2177
+ }, handheld && tagList, description && /* @__PURE__ */ React.createElement("span", {
1829
2178
  className: "tax-description"
1830
- }, summary || pkg.source)), /* @__PURE__ */ React.createElement("div", {
2179
+ }, description))), touch ? /* @__PURE__ */ React.createElement("button", {
2180
+ type: "button",
2181
+ className: "tax-action tax-more",
2182
+ title: words.more,
2183
+ "aria-label": words.more,
2184
+ "aria-haspopup": "menu",
2185
+ onClick: (event) => openMenu(event, items)
2186
+ }, /* @__PURE__ */ React.createElement(More, {
2187
+ size: 17
2188
+ })) : /* @__PURE__ */ React.createElement("div", {
1831
2189
  className: "tax-actions"
1832
2190
  }, buttons.map((button) => {
1833
2191
  const ButtonIcon = icon(pi, button.icon);
@@ -1844,12 +2202,16 @@ function PackageRow({ pi, actions, pkg }) {
1844
2202
  })), /* @__PURE__ */ React.createElement("input", {
1845
2203
  type: "checkbox",
1846
2204
  role: "switch",
1847
- className: "tax-switch",
2205
+ className: `ta-switch tax-switch${switching || removing ? " ta-busy" : ""}`,
1848
2206
  "aria-label": ExtensionWords.fill(words.turnOn, { name: title }),
1849
2207
  "aria-checked": pkg.enabled,
2208
+ "aria-busy": switching || undefined,
1850
2209
  checked: pkg.enabled,
1851
- onChange: (event) => void actions.setEnabled(pkg, event.target.checked)
1852
- }));
2210
+ onChange: (event) => {
2211
+ const on = event.target.checked;
2212
+ run(() => actions.setEnabled(pkg, on));
2213
+ }
2214
+ })), menu);
1853
2215
  }
1854
2216
 
1855
2217
  // web-src/search.ts
@@ -1957,6 +2319,48 @@ function registerSearches(context) {
1957
2319
  });
1958
2320
  }
1959
2321
 
2322
+ // web-src/settings.tsx
2323
+ function ModelSetting({ pi }) {
2324
+ const [value, setValue] = React.useState("");
2325
+ React.useEffect(() => {
2326
+ let live = true;
2327
+ const read = () => void MakeModel.get(pi).then((model) => live && setValue(model ?? ""));
2328
+ read();
2329
+ const stop = pi.storage.onChange((keys) => keys.includes(MAKE_MODEL_KEY) && read());
2330
+ return () => {
2331
+ live = false;
2332
+ stop();
2333
+ };
2334
+ }, [pi]);
2335
+ const ModelPicker = pi.ui.ModelPicker;
2336
+ return /* @__PURE__ */ React.createElement(ModelPicker, {
2337
+ value,
2338
+ label: ExtensionWords.of(pi.ui.language).modelLabel,
2339
+ onChange: (model) => {
2340
+ setValue(model);
2341
+ MakeModel.set(pi, model).catch((error) => pi.ui.notify(error instanceof Error ? error.message : String(error), "error"));
2342
+ }
2343
+ });
2344
+ }
2345
+ function makeSettings(pi) {
2346
+ const words = () => ExtensionWords.of(pi.ui.language);
2347
+ return {
2348
+ title: () => words().settingsTitle,
2349
+ icon: icon(pi, "Sparkles", "Puzzle"),
2350
+ rows: [
2351
+ {
2352
+ key: "model",
2353
+ label: () => words().modelLabel,
2354
+ description: () => words().modelHint,
2355
+ stacked: true,
2356
+ render: () => /* @__PURE__ */ React.createElement(ModelSetting, {
2357
+ pi
2358
+ })
2359
+ }
2360
+ ]
2361
+ };
2362
+ }
2363
+
1960
2364
  // web-src/signal.ts
1961
2365
  class Signal {
1962
2366
  value;
@@ -1986,11 +2390,11 @@ class Signal {
1986
2390
 
1987
2391
  // web-src/market-style.ts
1988
2392
  var MARKET_STYLE = `
1989
- .tax-tabs { display: inline-flex; align-self: flex-start; gap: 2px; margin-bottom: -10px; padding: 3px; border-radius: 10px; background: var(--ta-chip); }
2393
+ .tax-tabs { display: inline-flex; align-self: flex-start; gap: 2px; margin-bottom: -10px; padding: 3px; border-radius: 10px; background: var(--ta-raised); }
1990
2394
  .tax-tab { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 14px 0 11px; border: 0; border-radius: 7px; background: none; color: var(--ta-secondary); font: inherit; font-size: calc(13px * var(--ta-font-scale)); font-weight: 500; cursor: pointer; transition: background 140ms, color 140ms, box-shadow 140ms; }
1991
2395
  .tax-tab:hover { color: var(--ta-text); }
1992
- .tax-tab.tax-active { background: var(--ta-hover-strong); color: var(--ta-text); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
1993
- :root[data-theme='light'] .tax-tab.tax-active { background: var(--ta-card); box-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 0 0 .5px rgba(0, 0, 0, .06); }
2396
+ /* As the segmented controls of the page (its settings). */
2397
+ .tax-tab.tax-active { background: var(--ta-segment, var(--ta-card)); color: var(--ta-text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 0 0 1px var(--ta-border); }
1994
2398
  .tax-tab:focus-visible { outline: 2px solid var(--ta-border-focus); outline-offset: 1px; }
1995
2399
  .tax-empty-action { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 22px 16px; }
1996
2400
  .tax-market { display: flex; flex-direction: column; gap: 14px; }
@@ -2024,8 +2428,7 @@ var MARKET_STYLE = `
2024
2428
  .tax-card-description { display: -webkit-box; margin: 0; overflow: hidden; color: var(--ta-secondary); font-size: calc(12.5px * var(--ta-font-scale)); line-height: 1.55; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow-wrap: anywhere; }
2025
2429
  .tax-card-foot { display: flex; align-items: center; gap: 6px; margin-top: auto; min-height: 17px; }
2026
2430
  .tax-card-time { margin-left: auto; color: var(--ta-muted); font-size: calc(11.5px * var(--ta-font-scale)); white-space: nowrap; }
2027
- .tax-face { display: inline-flex; align-items: center; justify-content: center; flex: none; border-radius: 26%; background: hsl(var(--tax-hue) 70% 50% / .13); color: hsl(var(--tax-hue) 55% 38%); font-weight: 700; letter-spacing: -.02em; user-select: none; }
2028
- :root:not([data-theme='light']) .tax-face { background: hsl(var(--tax-hue) 60% 55% / .17); color: hsl(var(--tax-hue) 75% 74%); }
2431
+ .tax-face { display: inline-flex; align-items: center; justify-content: center; flex: none; border-radius: 26%; background: var(--tax-tint); color: var(--tax-ink); font-weight: 700; letter-spacing: -.02em; user-select: none; }
2029
2432
  .tax-install { display: inline-flex; align-items: center; justify-content: center; gap: 5px; flex: none; height: 28px; padding: 0 14px; border: 0; border-radius: 14px; background: color-mix(in srgb, var(--ta-green) 14%, transparent); color: color-mix(in srgb, var(--ta-green) 82%, var(--ta-text)); font: inherit; font-size: calc(12.5px * var(--ta-font-scale)); font-weight: 600; white-space: nowrap; cursor: pointer; transition: background 140ms, color 140ms, transform 120ms var(--ta-ease), filter 140ms; }
2030
2433
  .tax-install:hover { background: color-mix(in srgb, var(--ta-green) 24%, transparent); }
2031
2434
  .tax-install:active { transform: scale(.95); }
@@ -2092,12 +2495,13 @@ var STYLE = `
2092
2495
  .tax-section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 30px; }
2093
2496
  .tax-section-head h2 { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--ta-secondary); font-size: calc(12.5px * var(--ta-font-scale)); font-weight: 600; }
2094
2497
  .tax-count { padding: 0 6px; border-radius: 8px; background: var(--ta-chip); color: var(--ta-muted); font-size: calc(11px * var(--ta-font-scale)); font-weight: 500; line-height: calc(16px * var(--ta-font-scale)); }
2095
- .tax-button { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border: 1px solid var(--ta-border-muted); border-radius: 8px; background: var(--ta-raised); color: var(--ta-text); font: inherit; font-size: calc(13px * var(--ta-font-scale)); cursor: pointer; transition: background 120ms, border-color 120ms; }
2096
- .tax-button:hover { background: var(--ta-hover); border-color: var(--ta-border); }
2498
+ /* As the buttons of the page (.ta-button). */
2499
+ .tax-button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px; border: 1px solid var(--ta-border); border-radius: 8px; background: transparent; color: var(--ta-text); font: inherit; font-size: calc(13px * var(--ta-font-scale)); font-weight: 500; white-space: nowrap; cursor: pointer; transition: background 120ms, border-color 120ms; }
2500
+ .tax-button:hover:not(:disabled) { background: var(--ta-hover); }
2097
2501
  .tax-button:disabled { opacity: .55; cursor: default; }
2098
- .tax-list { border: 1px solid var(--ta-border-muted); border-radius: 12px; overflow: hidden; }
2502
+ .tax-list { --ta-swipe-bg: var(--ta-main); border: 1px solid var(--ta-border-muted); border-radius: 12px; overflow: hidden; }
2099
2503
  .tax-row { position: relative; display: flex; align-items: center; gap: 12px; padding: 11px 14px; }
2100
- .tax-row + .tax-row { border-top: 1px solid var(--ta-border-muted); }
2504
+ .tax-item + .tax-item { border-top: 1px solid var(--ta-border-muted); }
2101
2505
  .tax-row:hover { background: var(--ta-hover); }
2102
2506
  .tax-row:hover .tax-icon, .tax-row:hover .tax-tag { background: var(--ta-hover-strong); }
2103
2507
  .tax-icon { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; flex: none; border-radius: 9px; background: var(--ta-chip); color: var(--tax-accent); transition: color 160ms; }
@@ -2105,16 +2509,22 @@ var STYLE = `
2105
2509
  .tax-name { display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 600; }
2106
2510
  .tax-name > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
2107
2511
  .tax-version { flex: none; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); font-weight: 400; }
2108
- .tax-description { overflow: hidden; color: var(--ta-secondary); font-size: calc(12.5px * var(--ta-font-scale)); text-overflow: ellipsis; white-space: nowrap; }
2512
+ .tax-meta { display: flex; align-items: center; gap: 6px; min-width: 0; }
2513
+ .tax-description { flex: 1; min-width: 0; overflow: hidden; color: var(--ta-secondary); font-size: calc(12.5px * var(--ta-font-scale)); text-overflow: ellipsis; white-space: nowrap; }
2109
2514
  .tax-tag { flex: none; padding: 0 6px; border-radius: 5px; background: var(--ta-chip); color: var(--ta-muted); font-size: calc(11px * var(--ta-font-scale)); font-weight: 400; line-height: calc(17px * var(--ta-font-scale)); }
2110
2515
  .tax-off .tax-main { opacity: .5; }
2111
2516
  .tax-off .tax-icon { color: var(--ta-muted); }
2112
2517
  .tax-actions { display: flex; gap: 2px; flex: none; opacity: 0; transition: opacity 120ms; }
2113
2518
  .tax-row:hover .tax-actions, .tax-row:focus-within .tax-actions { opacity: 1; }
2114
- @media (hover: none) { .tax-actions { opacity: 1; } }
2115
2519
  .tax-action { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 7px; background: none; color: var(--ta-muted); cursor: pointer; }
2116
2520
  .tax-action:hover { background: var(--ta-hover-strong); color: var(--ta-text); }
2117
2521
  .tax-action.tax-danger:hover { color: var(--ta-red); }
2522
+ /* A finger: one … for the menu instead of a row of icons, and a target of a finger's size */
2523
+ .tax-more { flex: none; width: 36px; height: 36px; margin-right: -4px; }
2524
+ :root[data-handheld] .tax-body { gap: 24px; padding: 16px 12px 40px; }
2525
+ :root[data-handheld] .tax-row { gap: 10px; padding: 10px 12px; }
2526
+ :root[data-handheld] .tax-steps { gap: 4px; }
2527
+ :root[data-handheld] .tax-step { flex: 1; width: auto; min-width: 0; }
2118
2528
  .tax-switch { appearance: none; -webkit-appearance: none; position: relative; width: 36px; height: 20px; flex: none; margin: 0 0 0 4px; border-radius: 10px; background: var(--ta-hover-strong); cursor: pointer; transition: background 160ms; }
2119
2529
  .tax-switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform 180ms var(--ta-ease); }
2120
2530
  .tax-switch:checked { background: var(--ta-green); }
@@ -2184,6 +2594,8 @@ function activate(pi) {
2184
2594
  order: 90
2185
2595
  });
2186
2596
  registerSearches(context);
2597
+ pi.registerComposerAddon(composerAddon(pi));
2598
+ pi.registerSettings(makeSettings(pi));
2187
2599
  pi.on("agent_end", () => void store.load());
2188
2600
  return removeStyle;
2189
2601
  }