@celljs/ta-app-use 0.0.0-stage → 4.17.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 +28 -0
- package/README.md +27 -2
- package/extension/index.mjs +534 -0
- package/host/index.mjs +136 -0
- package/package.json +60 -3
- package/web/index.js +1520 -0
package/README.en.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @celljs/ta-app-use
|
|
2
|
+
|
|
3
|
+
[简体中文](./README.md)
|
|
4
|
+
|
|
5
|
+
A built-in package of Ta: agents do to Ta what you do with its pages. Say "turn on call captions", "pin that conversation" or "turn the town off" and it runs the action of the catalog of ta serve, with the same result as your tap; every page of yours shows the change at once, with a notice and Undo. Design in [ta-app-use.md](../../docs/design/ta-app-use.md).
|
|
6
|
+
|
|
7
|
+
## Two kinds of doing
|
|
8
|
+
|
|
9
|
+
- **Direct calls**: what ends as data (settings, pins, stops, extensions on or off, answers to what waits for you to decide) goes through the catalog of actions, no page in between, with the phone locked too.
|
|
10
|
+
- **Operating the screen**: what needs what is on the screen now, a "show me", or a page of an extension with nothing else, is done on a page of Ta as a browser use, with a cursor and motion. By default on **Ta's own screen** (a `?ta-screen` frame in your page that leaves yours alone: in a corner of a computer, to drag, enlarge or put away; on a phone a pill "Ta is at work · Watch · Stop"); asked to take you somewhere or show you (`here: true`), on your own page.
|
|
11
|
+
|
|
12
|
+
## Tools
|
|
13
|
+
|
|
14
|
+
| Tool | Does |
|
|
15
|
+
| --- | --- |
|
|
16
|
+
| `app_commands({ query? })` | The actions: id, what each does, its input and risk |
|
|
17
|
+
| `app_run({ command, input? })` | Runs one, checked for who asked the run |
|
|
18
|
+
| `app_look({ part?, here? })` | What is on the screen: where it is, the places to go, the parts (the list of conversations, the conversation, the settings...) with their rows and what each does, and what else can be clicked or typed into, each with an id |
|
|
19
|
+
| `app_go({ to, here? })` | Goes to a page, a list, a section of the settings or a conversation (`chat:<name>`), and says what is there |
|
|
20
|
+
| `app_do({ id, action?, input?, show?, here? })` | Clicks, types, chooses, or does an action of a part; one that stands for an action of the catalog runs as `app_run` unless `show: true` |
|
|
21
|
+
|
|
22
|
+
Actions of Ta: `settings.get`, `settings.set`, `chats.list`, `chats.pin`, `chats.stop`, `asks.list`, `asks.answer`, `extensions.list`, `extensions.set`. Other packages add theirs with `host.commands.register(...)` on their server side; they go when the package is turned off.
|
|
23
|
+
|
|
24
|
+
What cannot be undone (`danger`) waits for you to agree on your screen. A call's front has these tools too, so "turn the captions on" is done as it talks, and what waits for you to decide is answered with what you say. A session that speaks with other people for you (a room) has none of them.
|
|
25
|
+
|
|
26
|
+
## Notices
|
|
27
|
+
|
|
28
|
+
An action that changed something is kept in `done` of the data of this package (the latest 20); a page shows a new one as "Ta changed settings: Call captions on · Undo". Undo goes through `callHost('undo', id)`, checked for who tapped it.
|
package/README.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @celljs/ta-app-use
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[English](./README.en.md)
|
|
4
|
+
|
|
5
|
+
Ta 的内置包:智能体替你操作 Ta。你说"打开通话字幕""把那个对话置顶""关掉小镇",它直接调 ta serve 的动作目录做好,和你在界面上点的结果一样;你的每一页马上看到变化,并弹一行提示,可以撤销。设计见 [ta-app-use.md](../../docs/design/ta-app-use.md)。
|
|
6
|
+
|
|
7
|
+
## 两类操作
|
|
8
|
+
|
|
9
|
+
- **直接调用**:结果是一份数据的(设置、置顶、停止、开关扩展、替你回答待你决定的),调动作目录,不经过页面,手机锁屏也能做。
|
|
10
|
+
- **界面操作**:要看屏幕上此刻有什么、要"做给你看"、或只有界面的扩展页,像 browser use 一样操作 Ta 的页面,带光标和动画。默认在 **Ta 自己的屏幕**上做(你页面里的一个 `?ta-screen` 小窗,和你互不打扰:电脑上在角落,可拖动、放大、收起;手机上顶部一个胶囊"Ta 正在操作 · 看看 · 停止");你说"带我去""做给我看"时(`here: true`)在你自己的页面上演示。
|
|
11
|
+
|
|
12
|
+
## 工具
|
|
13
|
+
|
|
14
|
+
| 工具 | 做什么 |
|
|
15
|
+
| --- | --- |
|
|
16
|
+
| `app_commands({ query? })` | 查有哪些动作:id、做什么、参数、风险 |
|
|
17
|
+
| `app_run({ command, input? })` | 执行一个动作,按这一轮的发起人检查权限 |
|
|
18
|
+
| `app_look({ part?, here? })` | 屏幕上现在有什么:在哪、能去哪、各部分(对话列表、对话、设置……)的行和能做的事、其余能点能输入的,每样带 id |
|
|
19
|
+
| `app_go({ to, here? })` | 走到一页、一个列表、设置某一节或一个对话(`chat:<名字>`),返回到了以后的样子 |
|
|
20
|
+
| `app_do({ id, action?, input?, show?, here? })` | 点、输入、选择,或做某一部分的动作;指向动作目录的直接按 `app_run` 做,除非 `show: true` |
|
|
21
|
+
|
|
22
|
+
核心动作:`settings.get`、`settings.set`、`chats.list`、`chats.pin`、`chats.stop`、`asks.list`、`asks.answer`、`extensions.list`、`extensions.set`。别的包在服务端用 `host.commands.register(...)` 加自己的动作,包关掉时随之去掉。
|
|
23
|
+
|
|
24
|
+
不能撤销的(`danger`)一律先在你的屏幕上弹确认框,你点了才做。通话的前台也有这些工具,"把字幕打开"当场就做,"待你决定"的照你说的替你回答。房间里替你和别人说话的会话没有它们。
|
|
25
|
+
|
|
26
|
+
## 页面提示
|
|
27
|
+
|
|
28
|
+
改了东西的动作记在本包数据的 `done` 里(最近 20 条);页面看到新的一条就弹提示"Ta 修改了设置:通话字幕 开 · 撤销"。撤销经 `callHost('undo', id)`,按点它的人检查权限。
|
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
// ../ta-protocol/esm/common/ta-extension-host.js
|
|
2
|
+
var TA_WEBHOOK_MAX_BYTES = 256 * 1024;
|
|
3
|
+
var TA_HOST_EVENT = "ta:host";
|
|
4
|
+
var TaHostUtil;
|
|
5
|
+
(function(TaHostUtil2) {
|
|
6
|
+
TaHostUtil2.WAIT_MS = 1000;
|
|
7
|
+
function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
|
|
8
|
+
return new Promise((resolve) => {
|
|
9
|
+
let heard = false;
|
|
10
|
+
let answered = false;
|
|
11
|
+
const timer = setTimeout(() => resolve(undefined), waitMs);
|
|
12
|
+
const request = {
|
|
13
|
+
name,
|
|
14
|
+
heard: () => {
|
|
15
|
+
heard = true;
|
|
16
|
+
},
|
|
17
|
+
resolve: (answer) => {
|
|
18
|
+
answered = true;
|
|
19
|
+
clearTimeout(timer);
|
|
20
|
+
resolve(answer);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
events.emit(TA_HOST_EVENT, request);
|
|
24
|
+
if (!heard && !answered) {
|
|
25
|
+
clearTimeout(timer);
|
|
26
|
+
resolve(undefined);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
TaHostUtil2.reach = reach;
|
|
31
|
+
function marked(systemPrompt, mark) {
|
|
32
|
+
return role(systemPrompt).includes(mark);
|
|
33
|
+
}
|
|
34
|
+
TaHostUtil2.marked = marked;
|
|
35
|
+
function role(systemPrompt) {
|
|
36
|
+
if (!systemPrompt) {
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
const open = `<addendum>
|
|
40
|
+
`;
|
|
41
|
+
const start = systemPrompt.indexOf(open);
|
|
42
|
+
const context = systemPrompt.indexOf(`<project_context>
|
|
43
|
+
`);
|
|
44
|
+
if (start < 0 || context >= 0 && context < start) {
|
|
45
|
+
return "";
|
|
46
|
+
}
|
|
47
|
+
const end = systemPrompt.indexOf(`
|
|
48
|
+
</addendum>`, start);
|
|
49
|
+
return systemPrompt.slice(start + open.length, end < 0 ? undefined : end);
|
|
50
|
+
}
|
|
51
|
+
TaHostUtil2.role = role;
|
|
52
|
+
})(TaHostUtil || (TaHostUtil = {}));
|
|
53
|
+
var TA_WITH_OTHERS_MARK = "[ta:speaks-with-others]";
|
|
54
|
+
var TA_ASK_ENTRY = "ta-ask";
|
|
55
|
+
var TaAskUtil;
|
|
56
|
+
(function(TaAskUtil2) {
|
|
57
|
+
const LENGTH = 120;
|
|
58
|
+
function entry(question) {
|
|
59
|
+
const line = question.replace(/\s+/g, " ").trim();
|
|
60
|
+
return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
|
|
61
|
+
}
|
|
62
|
+
TaAskUtil2.entry = entry;
|
|
63
|
+
function asking(entries) {
|
|
64
|
+
var _a;
|
|
65
|
+
for (let i = entries.length - 1;i >= 0; i--) {
|
|
66
|
+
const entry2 = entries[i];
|
|
67
|
+
if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
|
|
71
|
+
return read(entry2);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
TaAskUtil2.asking = asking;
|
|
77
|
+
function next(asked, entry2) {
|
|
78
|
+
var _a;
|
|
79
|
+
if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
|
|
83
|
+
}
|
|
84
|
+
TaAskUtil2.next = next;
|
|
85
|
+
function read(found) {
|
|
86
|
+
var _a;
|
|
87
|
+
const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
|
|
88
|
+
if (typeof question !== "string" || !question.trim()) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
|
|
92
|
+
return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
|
|
93
|
+
}
|
|
94
|
+
})(TaAskUtil || (TaAskUtil = {}));
|
|
95
|
+
|
|
96
|
+
// ../ta-protocol/esm/common/delegate-protocol.js
|
|
97
|
+
var TaDelegateUtil;
|
|
98
|
+
(function(TaDelegateUtil2) {
|
|
99
|
+
TaDelegateUtil2.LEVELS = ["less", "balanced", "more"];
|
|
100
|
+
TaDelegateUtil2.DEFAULT = "balanced";
|
|
101
|
+
TaDelegateUtil2.WORK_TOOLS = ["read", "bash", "powershell", "edit", "write", "grep", "find", "ls"];
|
|
102
|
+
TaDelegateUtil2.CHANGE_TOOLS = ["edit", "write"];
|
|
103
|
+
const LIMITS = {
|
|
104
|
+
less: { noChanges: false },
|
|
105
|
+
balanced: { noChanges: true, steps: 6 },
|
|
106
|
+
more: { noChanges: true, steps: 2 }
|
|
107
|
+
};
|
|
108
|
+
function parse(value) {
|
|
109
|
+
return TaDelegateUtil2.LEVELS.includes(value) ? value : TaDelegateUtil2.DEFAULT;
|
|
110
|
+
}
|
|
111
|
+
TaDelegateUtil2.parse = parse;
|
|
112
|
+
function mark(level) {
|
|
113
|
+
return `(delegate=${level})`;
|
|
114
|
+
}
|
|
115
|
+
TaDelegateUtil2.mark = mark;
|
|
116
|
+
function levelOf(systemPrompt) {
|
|
117
|
+
const role = TaHostUtil.role(systemPrompt);
|
|
118
|
+
return TaDelegateUtil2.LEVELS.find((level) => role.includes(mark(level)));
|
|
119
|
+
}
|
|
120
|
+
TaDelegateUtil2.levelOf = levelOf;
|
|
121
|
+
function limits(level) {
|
|
122
|
+
return LIMITS[level];
|
|
123
|
+
}
|
|
124
|
+
TaDelegateUtil2.limits = limits;
|
|
125
|
+
function refusal(level, tool, steps) {
|
|
126
|
+
if (!TaDelegateUtil2.WORK_TOOLS.includes(tool)) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const limit = LIMITS[level];
|
|
130
|
+
if (limit.noChanges && TaDelegateUtil2.CHANGE_TOOLS.includes(tool)) {
|
|
131
|
+
return "You do not change files yourself: hand this to a task with start_task, with instructions complete enough to do it. The user set how much you hand out in the settings of the double.";
|
|
132
|
+
}
|
|
133
|
+
if (limit.steps !== undefined && steps >= limit.steps) {
|
|
134
|
+
return "You have looked enough for this: hand the work to a task with start_task now, with what you found in its instructions, and tell the user what you started.";
|
|
135
|
+
}
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
TaDelegateUtil2.refusal = refusal;
|
|
139
|
+
})(TaDelegateUtil || (TaDelegateUtil = {}));
|
|
140
|
+
|
|
141
|
+
// ../ta-protocol/esm/common/language.js
|
|
142
|
+
var TaLanguageUtil;
|
|
143
|
+
(function(TaLanguageUtil2) {
|
|
144
|
+
TaLanguageUtil2.ALL = ["zh-CN", "zh-TW", "en-US", "ja-JP"];
|
|
145
|
+
TaLanguageUtil2.NAMES = { "zh-CN": "简体中文", "zh-TW": "繁體中文", "en-US": "English", "ja-JP": "日本語" };
|
|
146
|
+
function of(tag) {
|
|
147
|
+
const said = (tag !== null && tag !== undefined ? tag : "").toLowerCase().replace(/_/g, "-");
|
|
148
|
+
if (/^zh(\b|-)/.test(said)) {
|
|
149
|
+
return /-hant\b/.test(said) || !/-hans\b/.test(said) && /-(tw|hk|mo)\b/.test(said) ? "zh-TW" : "zh-CN";
|
|
150
|
+
}
|
|
151
|
+
return /^ja(\b|-)/.test(said) ? "ja-JP" : "en-US";
|
|
152
|
+
}
|
|
153
|
+
TaLanguageUtil2.of = of;
|
|
154
|
+
function server(env = typeof process === "undefined" ? {} : process.env) {
|
|
155
|
+
return of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG);
|
|
156
|
+
}
|
|
157
|
+
TaLanguageUtil2.server = server;
|
|
158
|
+
function pick(language, words) {
|
|
159
|
+
return words[of(language)];
|
|
160
|
+
}
|
|
161
|
+
TaLanguageUtil2.pick = pick;
|
|
162
|
+
function say(words) {
|
|
163
|
+
return words[server()];
|
|
164
|
+
}
|
|
165
|
+
TaLanguageUtil2.say = say;
|
|
166
|
+
function chinese(language) {
|
|
167
|
+
return of(language).startsWith("zh");
|
|
168
|
+
}
|
|
169
|
+
TaLanguageUtil2.chinese = chinese;
|
|
170
|
+
function cjk(language) {
|
|
171
|
+
return of(language) !== "en-US";
|
|
172
|
+
}
|
|
173
|
+
TaLanguageUtil2.cjk = cjk;
|
|
174
|
+
function list(language, items) {
|
|
175
|
+
return items.join(cjk(language) ? "、" : ", ");
|
|
176
|
+
}
|
|
177
|
+
TaLanguageUtil2.list = list;
|
|
178
|
+
})(TaLanguageUtil || (TaLanguageUtil = {}));
|
|
179
|
+
|
|
180
|
+
// ../ta-protocol/esm/common/app-protocol.js
|
|
181
|
+
var TA_APP_TOOLS = ["app_commands", "app_run", "app_look", "app_go", "app_do"];
|
|
182
|
+
var FONT_SIZES = ["small", "standard", "large", "xlarge"];
|
|
183
|
+
var words = (en, zh, tw, ja) => ({ "en-US": en, "zh-CN": zh, "zh-TW": tw, "ja-JP": ja });
|
|
184
|
+
var SYSTEM = words("as the system", "跟随系统", "跟隨系統", "システムに合わせる");
|
|
185
|
+
var FONT_SHOWN = {
|
|
186
|
+
small: words("small", "小", "小", "小"),
|
|
187
|
+
standard: words("standard", "标准", "標準", "標準"),
|
|
188
|
+
large: words("large", "大", "大", "大"),
|
|
189
|
+
xlarge: words("extra large", "特大", "特大", "特大")
|
|
190
|
+
};
|
|
191
|
+
var TA_WEB_SETTINGS = [
|
|
192
|
+
{
|
|
193
|
+
key: "theme",
|
|
194
|
+
type: "enum",
|
|
195
|
+
values: ["system", "light", "dark"],
|
|
196
|
+
default: "system",
|
|
197
|
+
what: "Light or dark look; system follows the device.",
|
|
198
|
+
title: words("Theme", "外观", "外觀", "外観"),
|
|
199
|
+
shown: { system: SYSTEM, light: words("light", "浅色", "淺色", "ライト"), dark: words("dark", "深色", "深色", "ダーク") }
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
key: "language",
|
|
203
|
+
type: "enum",
|
|
204
|
+
values: ["system", ...TaLanguageUtil.ALL],
|
|
205
|
+
default: "system",
|
|
206
|
+
what: "The language of Ta's pages and of what Ta says; system follows the device.",
|
|
207
|
+
title: words("Language", "语言", "語言", "言語"),
|
|
208
|
+
shown: {
|
|
209
|
+
system: SYSTEM,
|
|
210
|
+
...Object.fromEntries(TaLanguageUtil.ALL.map((language) => [
|
|
211
|
+
language,
|
|
212
|
+
words(TaLanguageUtil.NAMES[language], TaLanguageUtil.NAMES[language], TaLanguageUtil.NAMES[language], TaLanguageUtil.NAMES[language])
|
|
213
|
+
]))
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
key: "fontSize",
|
|
218
|
+
type: "enum",
|
|
219
|
+
values: FONT_SIZES,
|
|
220
|
+
default: "standard",
|
|
221
|
+
what: "The size of the text of the whole page.",
|
|
222
|
+
title: words("Text size", "字体大小", "字型大小", "文字サイズ"),
|
|
223
|
+
shown: FONT_SHOWN
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
key: "chatFontSize",
|
|
227
|
+
type: "enum",
|
|
228
|
+
values: FONT_SIZES,
|
|
229
|
+
default: "standard",
|
|
230
|
+
what: "The size of the text of conversations, on top of fontSize.",
|
|
231
|
+
title: words("Text size of conversations", "对话字体大小", "對話字型大小", "会話の文字サイズ"),
|
|
232
|
+
shown: FONT_SHOWN
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
key: "speak",
|
|
236
|
+
type: "boolean",
|
|
237
|
+
default: false,
|
|
238
|
+
what: "Read every reply aloud.",
|
|
239
|
+
title: words("Read replies aloud", "朗读回复", "朗讀回覆", "返信を読み上げ")
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
key: "speakTalk",
|
|
243
|
+
type: "boolean",
|
|
244
|
+
default: false,
|
|
245
|
+
what: "Read the reply aloud when the user spoke to the double by voice.",
|
|
246
|
+
title: words("Read aloud what was asked by voice", "语音提问时朗读回复", "語音提問時朗讀回覆", "音声で聞いたら読み上げ")
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
key: "callCaptions",
|
|
250
|
+
type: "boolean",
|
|
251
|
+
default: false,
|
|
252
|
+
what: "Show captions in a call: what the user says and what Ta reads.",
|
|
253
|
+
title: words("Call captions", "通话字幕", "通話字幕", "通話の字幕")
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
key: "voice",
|
|
257
|
+
type: "string",
|
|
258
|
+
default: "",
|
|
259
|
+
what: "The voice replies are read with (a voiceURI of the device's voices); empty for the most natural one.",
|
|
260
|
+
title: words("Voice", "朗读声音", "朗讀聲音", "読み上げの声")
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
key: "confirmTasks",
|
|
264
|
+
type: "boolean",
|
|
265
|
+
default: false,
|
|
266
|
+
what: "The double asks before it hands out work.",
|
|
267
|
+
title: words("Ask before handing out work", "派任务前先问我", "派任務前先問我", "作業を割り当てる前に確認")
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
key: "maxTasks",
|
|
271
|
+
type: "number",
|
|
272
|
+
values: [0, 2, 4, 8],
|
|
273
|
+
default: 0,
|
|
274
|
+
what: "How many of the double's tasks run at once; 0 for as many as it starts.",
|
|
275
|
+
title: words("Tasks at once", "同时运行的任务", "同時執行的任務", "同時に実行するタスク")
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
key: "delegate",
|
|
279
|
+
type: "enum",
|
|
280
|
+
values: TaDelegateUtil.LEVELS,
|
|
281
|
+
default: TaDelegateUtil.DEFAULT,
|
|
282
|
+
what: "How much of the work the double hands out to tasks rather than doing it itself.",
|
|
283
|
+
title: words("Hand out work", "派活多少", "派活多少", "作業の割り当て"),
|
|
284
|
+
shown: { less: words("less", "少", "少", "少なめ"), balanced: words("balanced", "适中", "適中", "ふつう"), more: words("more", "多", "多", "多め") }
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
key: "assistantModel",
|
|
288
|
+
type: "model",
|
|
289
|
+
default: "",
|
|
290
|
+
what: "The model of the double, <provider>/<model id>; empty for the default model.",
|
|
291
|
+
title: words("Model of the double", "分身的模型", "分身的模型", "分身のモデル")
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
key: "taskModel",
|
|
295
|
+
type: "model",
|
|
296
|
+
default: "",
|
|
297
|
+
what: "The model of the tasks the double starts; empty for the default model.",
|
|
298
|
+
title: words("Model of tasks", "任务的模型", "任務的模型", "タスクのモデル")
|
|
299
|
+
},
|
|
300
|
+
{ key: "reduceMotion", type: "boolean", default: false, what: "Fewer animations.", title: words("Reduce motion", "减少动画", "減少動畫", "動きを減らす") },
|
|
301
|
+
{
|
|
302
|
+
key: "keepAliveMinutes",
|
|
303
|
+
type: "number",
|
|
304
|
+
values: [1, 5, 15, 30],
|
|
305
|
+
default: 5,
|
|
306
|
+
what: "How long an extension started on open keeps running once left, in minutes.",
|
|
307
|
+
title: words("Keep extensions running", "扩展离开后保留", "擴充功能離開後保留", "拡張機能を保持")
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
key: "chatFoldDays",
|
|
311
|
+
type: "number",
|
|
312
|
+
values: [3, 7, 30, 0],
|
|
313
|
+
default: 7,
|
|
314
|
+
what: "Conversations not updated for these days fold at the end of the list; 0 for none.",
|
|
315
|
+
title: words("Fold old conversations", "折叠旧对话", "摺疊舊對話", "古い会話を折りたたむ")
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
key: "chatArchiveDays",
|
|
319
|
+
type: "number",
|
|
320
|
+
values: [30, 90, 365, 0],
|
|
321
|
+
default: 30,
|
|
322
|
+
what: "Conversations not updated for these days are archived (out of the list, found by search); 0 for none.",
|
|
323
|
+
title: words("Archive old conversations", "归档旧对话", "歸檔舊對話", "古い会話をアーカイブ")
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
key: "recentShots",
|
|
327
|
+
type: "boolean",
|
|
328
|
+
default: true,
|
|
329
|
+
what: "The screenshot just taken is offered above the message box, once.",
|
|
330
|
+
title: words("Offer recent screenshots", "提示刚截的图", "提示剛截的圖", "撮ったばかりのスクリーンショットを提案")
|
|
331
|
+
}
|
|
332
|
+
];
|
|
333
|
+
var TaAppUtil;
|
|
334
|
+
(function(TaAppUtil2) {
|
|
335
|
+
function check(spec, value) {
|
|
336
|
+
var _a, _b;
|
|
337
|
+
switch (spec.type) {
|
|
338
|
+
case "boolean":
|
|
339
|
+
return typeof value === "boolean" ? undefined : "true or false";
|
|
340
|
+
case "string":
|
|
341
|
+
return typeof value === "string" ? undefined : "a string";
|
|
342
|
+
case "model":
|
|
343
|
+
return value === "" || typeof value === "string" && /^[^/\s]+\/\S+$/.test(value) ? undefined : "<provider>/<model id>, or empty";
|
|
344
|
+
default:
|
|
345
|
+
return ((_a = spec.values) === null || _a === undefined ? undefined : _a.includes(value)) ? undefined : `one of ${(_b = spec.values) === null || _b === undefined ? undefined : _b.map((one) => JSON.stringify(one)).join(", ")}`;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
TaAppUtil2.check = check;
|
|
349
|
+
function shown(value, language, spec) {
|
|
350
|
+
var _a;
|
|
351
|
+
const named = (_a = spec === null || spec === undefined ? undefined : spec.shown) === null || _a === undefined ? undefined : _a[String(value)];
|
|
352
|
+
if (named) {
|
|
353
|
+
return TaLanguageUtil.pick(language, named);
|
|
354
|
+
}
|
|
355
|
+
if (typeof value === "boolean") {
|
|
356
|
+
return TaLanguageUtil.pick(language, value ? words("on", "开", "開", "オン") : words("off", "关", "關", "オフ"));
|
|
357
|
+
}
|
|
358
|
+
if (value === "" || value === undefined || value === null) {
|
|
359
|
+
return TaLanguageUtil.pick(language, words("default", "默认", "預設", "デフォルト"));
|
|
360
|
+
}
|
|
361
|
+
return String(value);
|
|
362
|
+
}
|
|
363
|
+
TaAppUtil2.shown = shown;
|
|
364
|
+
})(TaAppUtil || (TaAppUtil = {}));
|
|
365
|
+
|
|
366
|
+
// web-src/app-protocol.ts
|
|
367
|
+
var NAME = "@celljs/ta-app-use";
|
|
368
|
+
var DONE_MAX = 20;
|
|
369
|
+
|
|
370
|
+
// web-src/app-util.ts
|
|
371
|
+
var DATA_CHARS = 8000;
|
|
372
|
+
var AppUseUtil;
|
|
373
|
+
((AppUseUtil) => {
|
|
374
|
+
function find(commands, query) {
|
|
375
|
+
const words2 = (query ?? "").toLowerCase().split(/\s+/).filter(Boolean);
|
|
376
|
+
if (!words2.length) {
|
|
377
|
+
return [...commands];
|
|
378
|
+
}
|
|
379
|
+
return commands.filter((command) => {
|
|
380
|
+
const text = `${command.id} ${command.description}`.toLowerCase();
|
|
381
|
+
return words2.some((word) => text.includes(word));
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
AppUseUtil.find = find;
|
|
385
|
+
function listText(commands) {
|
|
386
|
+
if (!commands.length) {
|
|
387
|
+
return "No action matches; app_commands without a query lists them all.";
|
|
388
|
+
}
|
|
389
|
+
return commands.map((command) => {
|
|
390
|
+
const properties = command.input?.properties;
|
|
391
|
+
const required = command.input?.required;
|
|
392
|
+
const input = properties ? ` Input: ${JSON.stringify(properties)}${Array.isArray(required) && required.length ? `, required ${required.join(", ")}` : ""}.` : " No input.";
|
|
393
|
+
return `- ${command.id} (${command.risk}${command.owner ? `, of ${command.owner}` : ""}): ${command.description}${input}`;
|
|
394
|
+
}).join(`
|
|
395
|
+
`);
|
|
396
|
+
}
|
|
397
|
+
AppUseUtil.listText = listText;
|
|
398
|
+
function resultText(result) {
|
|
399
|
+
const lines = [result.text];
|
|
400
|
+
if (result.data !== undefined) {
|
|
401
|
+
const data = JSON.stringify(result.data);
|
|
402
|
+
lines.push(data.length > DATA_CHARS ? `${data.slice(0, DATA_CHARS)}… (cut; narrow it down)` : data);
|
|
403
|
+
}
|
|
404
|
+
if (result.notice) {
|
|
405
|
+
lines.push(`The user's pages show it already, and a notice with Undo.`);
|
|
406
|
+
}
|
|
407
|
+
return lines.join(`
|
|
408
|
+
`);
|
|
409
|
+
}
|
|
410
|
+
AppUseUtil.resultText = resultText;
|
|
411
|
+
function add(done, entry) {
|
|
412
|
+
return [...entries(done), entry].slice(-DONE_MAX);
|
|
413
|
+
}
|
|
414
|
+
AppUseUtil.add = add;
|
|
415
|
+
function entries(done) {
|
|
416
|
+
return Array.isArray(done) ? done.filter((one) => !!one && typeof one === "object" && typeof one.id === "string" && typeof one.notice === "string" && typeof one.at === "number") : [];
|
|
417
|
+
}
|
|
418
|
+
AppUseUtil.entries = entries;
|
|
419
|
+
function fresh(done, since) {
|
|
420
|
+
return entries(done).filter((entry) => entry.at > since && !entry.undone);
|
|
421
|
+
}
|
|
422
|
+
AppUseUtil.fresh = fresh;
|
|
423
|
+
})(AppUseUtil ||= {});
|
|
424
|
+
|
|
425
|
+
// web-src/extension.ts
|
|
426
|
+
var NO_SERVER = "Doing things to Ta needs the Ta service: start it with `ta serve`.";
|
|
427
|
+
var APP_RUN_DESCRIPTION = "Does something to Ta itself at once, as the user would on its pages but without them: change its settings (look, language, voice, captions of calls, the double, models), list, pin or stop conversations, read and answer what waits for the user to decide (with what they said), turn a built-in extension on or off. Prefer it to operating the screen: it is quick, needs no page open, and the user's pages show the change at once, with a notice and Undo. command: settings.get, settings.set, chats.list, chats.pin, chats.stop, asks.list, asks.answer, extensions.list, extensions.set, or another of app_commands (packages add theirs); input: as app_commands says. Do what the user asked; ask before anything they did not.";
|
|
428
|
+
var HERE = { type: "boolean", description: "On the user's own page, with Ta's cursor, to show them; else on Ta's own screen beside it." };
|
|
429
|
+
var SCREEN_TOOLS = [
|
|
430
|
+
{
|
|
431
|
+
name: "app_look",
|
|
432
|
+
label: "Look at the screen",
|
|
433
|
+
description: "What is on a screen of Ta now, as its page shows it: where it is, the places to go, the parts (the list of conversations, the conversation, the settings...) with their rows and what each does, and what else can be clicked or typed into, each with an id for app_do. Ta works its own screen, a second page beside the user's that does not disturb them; here: true reads the user's own page instead (what they look at now). part: one part only. Use it for what the user sees and what only the screen has (an extension's page, a dialog); to change data, app_run first.",
|
|
434
|
+
parameters: { type: "object", properties: { part: { type: "string" }, here: HERE } }
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
name: "app_go",
|
|
438
|
+
label: "Go on the screen",
|
|
439
|
+
description: `Goes to a place on a screen of Ta and says what is there then, as app_look: a place of app_look (list:..., page:<id>, discover, settings, settings:<section>) by its id or title, or a conversation (chat:<its name>). here: true goes on the user's own page, to show them ("take me to", "show me where").`,
|
|
440
|
+
parameters: { type: "object", properties: { to: { type: "string" }, here: HERE }, required: ["to"] }
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
name: "app_do",
|
|
444
|
+
label: "Do on the screen",
|
|
445
|
+
description: "Does something on a screen of Ta, as the user would, and says what was done and how it looks now. id: of the last app_look ([p1.2] a row, [p1] a part, [e3] a control). action: what of a part (open, pin, send, answer...; a row opens without), none to click a control; a text box takes input.text (input.submit: true presses Enter), a choice input.text. An action marked = app_run runs that action without the screen, unless show: true. What cannot be undone waits for the user to agree on their screen. here: true does it on the user's own page, to show them.",
|
|
446
|
+
parameters: {
|
|
447
|
+
type: "object",
|
|
448
|
+
properties: { id: { type: "string" }, action: { type: "string" }, input: { type: "object" }, show: { type: "boolean" }, here: HERE },
|
|
449
|
+
required: ["id"]
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
];
|
|
453
|
+
function activate(pi) {
|
|
454
|
+
let reached;
|
|
455
|
+
const reach = () => reached ??= TaHostUtil.reach(pi.events, NAME).then((answer) => ({
|
|
456
|
+
answered: !!answer,
|
|
457
|
+
app: answer?.service?.service
|
|
458
|
+
}));
|
|
459
|
+
const others = (ctx) => TaHostUtil.marked(ctx.getSystemPrompt(), TA_WITH_OTHERS_MARK);
|
|
460
|
+
const ours = (name) => TA_APP_TOOLS.includes(name);
|
|
461
|
+
pi.on("before_agent_start", (_event, ctx) => {
|
|
462
|
+
if (others(ctx)) {
|
|
463
|
+
const active = pi.getActiveTools();
|
|
464
|
+
if (active.some(ours)) {
|
|
465
|
+
pi.setActiveTools(active.filter((name) => !ours(name)));
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
pi.on("tool_call", (event, ctx) => others(ctx) && ours(event.toolName) ? { block: true, reason: "Here you speak with other people: what is the user's is not yours to change." } : undefined);
|
|
470
|
+
const tools = [
|
|
471
|
+
{
|
|
472
|
+
name: "app_commands",
|
|
473
|
+
label: "Find what Ta can do",
|
|
474
|
+
description: "The actions of Ta that app_run takes: id, what each does, its input and its risk; query: words to find some (settings, pin, extension), none for all.",
|
|
475
|
+
parameters: { type: "object", properties: { query: { type: "string" } } },
|
|
476
|
+
run: async (app, params) => AppUseUtil.listText(app.commands(typeof params.query === "string" ? params.query : undefined))
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
name: "app_run",
|
|
480
|
+
label: "Do it in Ta",
|
|
481
|
+
description: APP_RUN_DESCRIPTION,
|
|
482
|
+
parameters: {
|
|
483
|
+
type: "object",
|
|
484
|
+
properties: { command: { type: "string" }, input: { type: "object" } },
|
|
485
|
+
required: ["command"]
|
|
486
|
+
},
|
|
487
|
+
run: async (app, params, ctx) => {
|
|
488
|
+
const input = params.input && typeof params.input === "object" && !Array.isArray(params.input) ? params.input : {};
|
|
489
|
+
return AppUseUtil.resultText(await app.run(String(params.command ?? ""), input, ctx.sessionManager?.getSessionFile()));
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
];
|
|
493
|
+
const object = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
494
|
+
for (const tool of SCREEN_TOOLS) {
|
|
495
|
+
tools.push({
|
|
496
|
+
...tool,
|
|
497
|
+
run: async (app, params, ctx) => {
|
|
498
|
+
const kind = tool.name === "app_look" ? "look" : tool.name === "app_go" ? "go" : "do";
|
|
499
|
+
const input = object(params.input);
|
|
500
|
+
return app.screen({
|
|
501
|
+
kind,
|
|
502
|
+
...typeof params.part === "string" && params.part ? { part: params.part } : {},
|
|
503
|
+
...typeof params.to === "string" ? { to: params.to } : {},
|
|
504
|
+
...typeof params.id === "string" ? { id: params.id } : {},
|
|
505
|
+
...typeof params.action === "string" && params.action ? { action: params.action } : {},
|
|
506
|
+
...input ? { input } : {},
|
|
507
|
+
...params.here === true ? { here: true } : {},
|
|
508
|
+
...params.show === true ? { show: true } : {}
|
|
509
|
+
}, ctx.sessionManager?.getSessionFile());
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
for (const tool of tools) {
|
|
514
|
+
pi.registerTool({
|
|
515
|
+
name: tool.name,
|
|
516
|
+
label: tool.label,
|
|
517
|
+
description: tool.description,
|
|
518
|
+
parameters: tool.parameters,
|
|
519
|
+
execute: async (_id, params, _signal, _update, ctx) => {
|
|
520
|
+
const { answered, app } = await reach();
|
|
521
|
+
if (!app) {
|
|
522
|
+
throw new Error(answered ? "ta-app-use did not start in the Ta service; its log says why." : NO_SERVER);
|
|
523
|
+
}
|
|
524
|
+
const text = await tool.run(app, params ?? {}, ctx);
|
|
525
|
+
return { content: [{ type: "text", text }], details: undefined };
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
export {
|
|
531
|
+
activate as default,
|
|
532
|
+
SCREEN_TOOLS,
|
|
533
|
+
APP_RUN_DESCRIPTION
|
|
534
|
+
};
|