@celljs/ta-dash 0.0.0-stage → 4.42.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 ADDED
@@ -0,0 +1,13 @@
1
+ # Cell - Ta Dash
2
+
3
+ A pi package that comes with Ta (on by default; turn it off in Settings → Extensions of the web client): Dashboards. Ask about data your computer reaches (a database, the command line of a warehouse, an API, files) and Ta draws a dashboard in the reply that refreshes while you look at it; tap any number to see the query behind it.
4
+
5
+ - **How it is written**: under the Ta service every turn's system prompt has a `<ta-dash>` section: numbers the user keeps coming back to are written as a `ta-dash` block (JSON): `sources` are queries by name, each a shell command printing JSON (an array of objects, an object holding one, a JSON object a line), CSV or TSV with a header, a table split by `|`, or one number; `tiles` are its cards, `stat` (a key number, with its change from the last period and its trend), `line`, `bars`, `share` and `table`, each on a query.
6
+ - **Where it runs**: the server side of the package (`pi.host`) runs the queries on this computer, in the conversation's directory, with the user's shell (its profile read, as in a terminal), 60 seconds and 4 MB of output each, three at once; directories of another machine (`ssh://`) are not supported yet.
7
+ - **Who allows**: the commands of a dashboard Ta wrote in a conversation of the user's are allowed in that directory as the turn ends (Ta could run them there anyway); not those of a conversation a package opened for a role of its own (a visitor's, a group's). Otherwise (a dashboard someone sent, another directory) the card lists the commands and runs them once the user taps Allow and run. Only the owner of the computer runs and allows them; members see the last numbers. Allowed commands are kept in `<agent dir>/ta-dash/approved.json` (0600, the 500 used last).
8
+ - **When it refreshes**: fetched as the dashboard comes into view, again as often as its `refresh` says while it stays there (15 minutes by default, a minute at least, `off` by hand only); Refresh at its top runs them now; nothing runs while nobody looks. Results go to the package's data (`r:<key>`), the same on every page: the last 40, 500 rows and 48 KB each.
9
+ - **A tap on a number**: shows its query, when it was fetched, how long it took and how many rows, to copy the query or the data (to paste into a sheet) or to Ask Ta; Make it an animated explainer under the dashboard gives its numbers now to `ta-motion`.
10
+ - **How it is drawn**: key numbers by the tile itself; charts and tables as cards of `ta-glance` (embedded blocks), as Ta's other results. Pointed at, a tile is `tiles[n]`.
11
+ - **Works**: Keep makes it a work (ta-works), to put on the board; on its page it refreshes in the directory its commands were allowed in.
12
+
13
+ Methods of the server side (`callPackageHost('@celljs/ta-dash', …)`): `run(code, conversation, force)`, `approve(code, conversation)`, `approved()`, `forgetApproved()`. The format is in `web-src/dash-spec.ts`, the prompt in `web-src/dash-prompt.ts`, the design in `docs/design/ta-data-motion.md`.
package/README.md CHANGED
@@ -1,3 +1,13 @@
1
- # Temporary Holding Version
1
+ # Cell - Ta Dash
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Ta 自带的 pi 包(默认开启,可在 Web 客户端的 设置 → 扩展 关闭):数据看板。问你电脑能访问的数据(数据库、数仓的命令行、接口、文件)时,Ta 在回复里画出一个看板,你看着它时会按时刷新,点任一数字就能看到背后的查询。
4
+
5
+ - **写法**:在 Ta 服务下,每一轮的系统提示里多一段 `<ta-dash>`:用户常回来看的数字写成 `ta-dash` 代码块(JSON):`sources` 是按名字的查询,每条是一行 shell 命令,输出 JSON(对象数组、包着数组的对象、每行一个 JSON)、带表头的 CSV/TSV、`|` 分隔的表或一个数;`tiles` 是卡片:`stat`(关键数字,可带与上一期的变化和走势)、`line`、`bars`、`share`、`table`,各自指向一条查询。
6
+ - **在哪跑**:查询由本包的服务端(`pi.host`)在这台电脑上、对话所在目录里,用用户的 shell 运行(读取 profile,与终端一致),单条 60 秒、输出 4 MB 为限,最多同时 3 条;远程目录(`ssh://`)暂不支持。
7
+ - **谁允许**:Ta 在用户自己的对话里写出的看板,回合结束时它的命令在那个目录里自动算作允许(Ta 本来就能在那里运行它们);由包为别的角色打开的对话(访客、群等)写的不算。其他情况(别人发来的看板、换了目录)卡片上列出命令,用户点「允许并运行」后才跑。只有电脑主人能运行和允许,协作者只看到上次的数。允许过的命令记在 `<agent 目录>/ta-dash/approved.json`(0600,最近用过的 500 条)。
8
+ - **何时刷新**:看板进入视野时取一次,留在视野里按 `refresh` 再取(默认 15 分钟,最短 1 分钟,`off` 只手动),右上角「刷新」立即重跑;没人看时不跑。结果存进包数据(`r:<键>`),各页面同步,最近 40 条,每条最多 500 行、48 KB。
9
+ - **点数字**:点任一卡片显示它的查询、更新时间、用时与行数,可复制查询、复制数据(粘进表格)、「问 Ta」解释;回复底部「做成动画讲解」把现在的数字交给 `ta-motion`。
10
+ - **画法**:关键数字由卡片自己画;图表和表格交给 `ta-glance` 的卡片(作为内嵌块),和 Ta 其他结果一个样子。圈一块让 Ta 改时按 `tiles[n]` 报位置。
11
+ - **作品**:可「存下来」成作品(ta-works),放到小组件;作品页里在允许过的目录里照常刷新。
12
+
13
+ 服务端方法(`callPackageHost('@celljs/ta-dash', …)`):`run(code, conversation, force)`、`approve(code, conversation)`、`approved()`、`forgetApproved()`。格式见 `web-src/dash-spec.ts`,提示词见 `web-src/dash-prompt.ts`,设计见 `docs/design/ta-data-motion.md`。
@@ -0,0 +1,122 @@
1
+ // ../ta-protocol/esm/common/host-cloud-protocol.js
2
+ var TA_CLOUD_OUTPUT_BYTES = 1024 * 1024;
3
+
4
+ // ../ta-protocol/esm/common/ta-extension-host.js
5
+ var TA_HOST_EVENT = "ta:host";
6
+ var TaHostUtil;
7
+ (function(TaHostUtil2) {
8
+ TaHostUtil2.WAIT_MS = 1000;
9
+ function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
10
+ return new Promise((resolve) => {
11
+ let heard = false;
12
+ let answered = false;
13
+ const timer = setTimeout(() => resolve(undefined), waitMs);
14
+ const request = {
15
+ name,
16
+ heard: () => {
17
+ heard = true;
18
+ },
19
+ resolve: (answer) => {
20
+ answered = true;
21
+ clearTimeout(timer);
22
+ resolve(answer);
23
+ }
24
+ };
25
+ events.emit(TA_HOST_EVENT, request);
26
+ if (!heard && !answered) {
27
+ clearTimeout(timer);
28
+ resolve(undefined);
29
+ }
30
+ });
31
+ }
32
+ TaHostUtil2.reach = reach;
33
+ function marked(systemPrompt, mark) {
34
+ return role(systemPrompt).includes(mark);
35
+ }
36
+ TaHostUtil2.marked = marked;
37
+ function role(systemPrompt) {
38
+ if (!systemPrompt) {
39
+ return "";
40
+ }
41
+ const open = `<addendum>
42
+ `;
43
+ const start = systemPrompt.indexOf(open);
44
+ const context = systemPrompt.indexOf(`<project_context>
45
+ `);
46
+ if (start < 0 || context >= 0 && context < start) {
47
+ return "";
48
+ }
49
+ const end = systemPrompt.indexOf(`
50
+ </addendum>`, start);
51
+ return systemPrompt.slice(start + open.length, end < 0 ? undefined : end);
52
+ }
53
+ TaHostUtil2.role = role;
54
+ })(TaHostUtil || (TaHostUtil = {}));
55
+ var TA_DOUBLE_LOOK = {
56
+ name: "@celljs/ta-web",
57
+ key: "assistant.species",
58
+ given: ["trex", "triceratops", "stegosaurus", "brachiosaurus", "velociraptor", "ankylosaurus", "pteranodon", "parasaurolophus"]
59
+ };
60
+ var TaDoubleLookUtil;
61
+ (function(TaDoubleLookUtil2) {
62
+ function given(id) {
63
+ let hash = 2166136261;
64
+ for (let i = 0;i < id.length; i++) {
65
+ hash = Math.imul(hash ^ id.charCodeAt(i), 16777619);
66
+ }
67
+ return TA_DOUBLE_LOOK.given[(hash >>> 0) % TA_DOUBLE_LOOK.given.length];
68
+ }
69
+ TaDoubleLookUtil2.given = given;
70
+ })(TaDoubleLookUtil || (TaDoubleLookUtil = {}));
71
+
72
+ // web-src/dash-protocol.ts
73
+ var NAME = "@celljs/ta-dash";
74
+ var LANGUAGE = "ta-dash";
75
+ var DashKeys;
76
+ ((DashKeys) => {
77
+ DashKeys.ALLOWED = "allowed";
78
+ DashKeys.RESULTS = "results";
79
+ })(DashKeys ||= {});
80
+ var DashLimits;
81
+ ((DashLimits) => {
82
+ DashLimits.SOURCES = 12;
83
+ DashLimits.TILES = 16;
84
+ DashLimits.RUN = 4000;
85
+ DashLimits.ROWS = 500;
86
+ DashLimits.BYTES = 48 * 1024;
87
+ DashLimits.TIMEOUT_MS = 60000;
88
+ DashLimits.OUTPUT = 4 * 1024 * 1024;
89
+ DashLimits.PARALLEL = 3;
90
+ DashLimits.RESULTS = 40;
91
+ DashLimits.APPROVED = 500;
92
+ DashLimits.REFRESH_MS = 15 * 60000;
93
+ DashLimits.MIN_REFRESH_MS = 60000;
94
+ })(DashLimits ||= {});
95
+
96
+ // web-src/dash-prompt.ts
97
+ var DASH_PROMPT = `To show numbers the user keeps coming back to from data their computer can reach (a database, the command line of a warehouse, an API, files: signups this week, revenue by region, errors by service) as a dashboard that stays current, write a fenced block of language ${LANGUAGE} holding JSON; Ta runs its queries on the user's computer, in this conversation's directory, as the page shows it and again as often as it says, and every number shows the query behind it:
98
+ {"title": string, "refresh"?: "15m" (or "5m", "1h", "1d", "off"), "cwd"?: a directory, "sources": {"<name>": "<a shell command printing rows>"}, "tiles": [...]}
99
+ A command prints JSON (an array of objects, or an object holding one), lines of JSON, CSV or TSV with a header, or one number: sqlite3 -json, psql --csv, mysql -B, bq query --format=json, clickhouse-client -f JSONEachRow, curl … | jq, a script. Only commands that read; run each once yourself first, to check it works and see its columns; never put a secret in one.
100
+ Tiles, each on a source:
101
+ - {"type": "stat", "label": "…", "source": "<name>", "field"?: its column (else the first number), "row"?: "first" | "last", "compare"?: the column of the value before (the change is shown), "trend"?: a column drawn under it, "unit"?, "better"?: "higher" | "lower"}
102
+ - {"type": "line", "label", "source", "x": a column of time, "y": a column or a list of them}
103
+ - {"type": "bars" | "share", "label", "source", "x": the column naming each, "y": the column of its amount}
104
+ - {"type": "table", "label", "source", "columns"?: [...]}
105
+ Let each query compute what its tiles show (a sum, this week's count and last week's) rather than rows to add up; a few tiles, the key numbers first.`;
106
+
107
+ // web-src/extension.ts
108
+ function activate(pi) {
109
+ let served;
110
+ const underServe = () => served ??= TaHostUtil.reach(pi.events, NAME).then((answer) => answer !== undefined);
111
+ pi.on("session_start", () => {
112
+ underServe();
113
+ });
114
+ pi.on("before_agent_start", async (event) => {
115
+ if (await underServe()) {
116
+ event.systemPromptOptions.sections = { ...event.systemPromptOptions.sections, [LANGUAGE]: DASH_PROMPT };
117
+ }
118
+ });
119
+ }
120
+ export {
121
+ activate as default
122
+ };