@celljs/ta-notify 4.12.0 → 4.13.1

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
@@ -4,6 +4,7 @@ A pi package that comes with Ta (on by default; turn it off in Settings → Exte
4
4
 
5
5
  - **A turn ends**: the first two lines of its last answer (the error when it failed). A turn you stopped says nothing.
6
6
  - **It waits for you**: a dialog of an extension waits for your answer (pi's `ui_prompt_start`), told by its title.
7
+ - **A turn ends asking**: a turn another package marked as waiting for you to decide (`TA_ASK_ENTRY`, as a card of choices of Glance) is told as asking, by its question. What `notify_user` asks is marked so too, and the list of chats keeps showing it until you answer.
7
8
  - **Ta asks you**: Ta has a tool `notify_user({ message, options?, kind? })`, for a decision only you can make, something that blocks it, or a long job you asked to hear about; `options` are up to 4 short answers, buttons on the notice, one tapped sent to that conversation as your message (once, even when a computer and a phone tap at the same time). A turn that used it says nothing more when it ends. The question and its answers also stay in the conversation as a card (the model does not read it), to tap on any device.
8
9
 
9
10
  The page decides how to tell you: nothing of the conversation you look at; a task the double follows is told by the double (unless it asks). On a phone or a tablet nothing pops up, as in WeChat in front: an amber dot on the row of the list and on the Chats tab, a decision tapped on the card in its conversation. On a computer with the page in front, a banner at the bottom right with the face and name of the conversation, a tap opening it. With the page not in front, a notice of the system (silent for an answer); on a computer without one, a question or a failure leaves a banner that waits for your return.
@@ -11,7 +12,7 @@ The page decides how to tell you: nothing of the conversation you look at; a tas
11
12
  Settings → Notifications:
12
13
 
13
14
  - **Tell me**: every answer (default), when it needs me (questions and failures only), or off.
14
- - **Notices of the system**: Allow turns on the notices of the browser or of Ta Desktop. Pushes to the phone app while it is closed or the phone locked are not set up yet (they need APNs); meanwhile the dots of the list tell once the app is open.
15
+ - **Notices of the system**: Allow turns on those of the browser. Ta Desktop needs no Allow: the app shows them itself, also while its window is closed, minimized or behind another (as long as it runs in the Dock or the tray). Pushes to the phone app while it is closed or the phone locked are not set up yet (they need APNs); meanwhile the dots of the list tell once the app is open.
15
16
  - **Muted conversations**: Mute on a banner of an answer or a failure adds one; they tell you only when they need you. Unmute them here.
16
17
 
17
18
  Sessions another package opened for a role of its own (an agent of a channel, a run of a schedule) say nothing when a turn ends, their package telling you in its own way; they still tell you when they ask or a dialog waits.
@@ -23,6 +24,7 @@ The data of the package (`@celljs/ta-notify`): `notices` (the latest 30, the new
23
24
  What its host (`pi.host`) answers, for web extensions through `callPackageHost('@celljs/ta-notify', …)`:
24
25
 
25
26
  - `mute(target, muted, title?)`: mutes a conversation or not; the list after.
27
+ - `notify({ from, id, level, title, text, view? })`: another package tells the user of what is no conversation's (a double in a room asks for a permission), as the setting Tell me allows; a notice of the system while the page is not in front, a tap opening `view`.
26
28
 
27
29
  Another extension that tells the user news of its own uses the page's `ui.notifySession` (see @celljs/ta-web), not the data of this package.
28
30
 
package/README.md CHANGED
@@ -4,6 +4,7 @@ Ta 自带的 pi 包(默认开启,可在 Web 客户端的 设置 → 扩展
4
4
 
5
5
  - **一轮结束**:最后的回答取前两行做成提醒(失败时是错误信息)。你停下的一轮不提醒。
6
6
  - **在等你**:扩展的对话框在等回答时(pi 的 `ui_prompt_start`),用它的标题提醒你。
7
+ - **一轮以提问结束**:别的包把这一轮记成在等你决定(`TA_ASK_ENTRY`,如速览的选项卡片)时,按“需要你”提醒,内容是那个问题。`notify_user` 的提问也这样记下,对话列表就一直标着它,直到你回答。
7
8
  - **Ta 主动问你**:Ta 有一个工具 `notify_user({ message, options?, kind? })`。只有你能做的决定、卡住它的事、你说过要听结果的长任务才用;`options` 是最多 4 个短回答,在提醒上是按钮,点一个就以你的身份发进那个对话(电脑和手机同时点也只发一次)。用过它的一轮,结束时不再另外提醒。问题和回答按钮也作为一张卡片留在对话里(模型读不到),任何设备打开对话都能点。
8
9
 
9
10
  页面决定怎么告诉你:你正在看的对话不提醒;分身跟进的任务由分身告诉你(除非它在问你)。手机和平板上像微信在前台时一样不弹窗:对话列表行上和底部"对话"标签上有黄点,要你拍板的事在对话的卡片上点选。电脑上页面在前台时是右下角一条带对话头像和名字的横幅,点一下打开对话。页面不在前台时是系统通知(回复是静音的);电脑上没有系统通知时,提问和失败留一条横幅等你回来。
@@ -11,7 +12,7 @@ Ta 自带的 pi 包(默认开启,可在 Web 客户端的 设置 → 扩展
11
12
  设置 → 提醒:
12
13
 
13
14
  - **提醒我**:每次回复(默认)、需要我时(只有提问和失败)、关闭。
14
- - **系统通知**:点"允许"开启浏览器或 Ta 桌面版的系统通知。手机 App 被关掉或锁屏后的推送还没有接入(需要 APNs),这时只在 App 打开后从列表的黄点看到。
15
+ - **系统通知**:浏览器里点"允许"开启。Ta 桌面版不用点:由应用自己发,窗口关掉、最小化或在后面时也会提醒(应用在程序坞或托盘里运行着就行)。手机 App 被关掉或锁屏后的推送还没有接入(需要 APNs),这时只在 App 打开后从列表的黄点看到。
15
16
  - **免打扰的对话**:在回复或失败的横幅上点"免打扰"加入;这些对话只在需要你时提醒。这里可以取消。
16
17
 
17
18
  由别的包打开、承担固定角色的会话(频道里的智能体、定时任务的运行)一轮结束时不提醒,由那个包自己告诉你;它们问你或有对话框在等时照样提醒。
@@ -23,6 +24,7 @@ Ta 自带的 pi 包(默认开启,可在 Web 客户端的 设置 → 扩展
23
24
  包宿主(`pi.host`)的方法,Web 扩展经 `callPackageHost('@celljs/ta-notify', …)` 调用:
24
25
 
25
26
  - `mute(target, muted, title?)`:设成或取消免打扰,返回新的列表。
27
+ - `notify({ from, id, level, title, text, view? })`:别的包告诉用户不属于某个对话的事(如房间里分身请你授权),按"提醒我"的设置过滤;页面不在前台时发系统通知,点开打开 `view`。
26
28
 
27
29
  别的扩展要告诉用户自己的消息,用页面的 `ui.notifySession`(见 @celljs/ta-web),不要写这个包的数据。
28
30
 
@@ -5,19 +5,91 @@ var TaHostUtil;
5
5
  TaHostUtil2.WAIT_MS = 1000;
6
6
  function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
7
7
  return new Promise((resolve) => {
8
+ let heard = false;
9
+ let answered = false;
8
10
  const timer = setTimeout(() => resolve(undefined), waitMs);
9
11
  const request = {
10
12
  name,
13
+ heard: () => {
14
+ heard = true;
15
+ },
11
16
  resolve: (answer) => {
17
+ answered = true;
12
18
  clearTimeout(timer);
13
19
  resolve(answer);
14
20
  }
15
21
  };
16
22
  events.emit(TA_HOST_EVENT, request);
23
+ if (!heard && !answered) {
24
+ clearTimeout(timer);
25
+ resolve(undefined);
26
+ }
17
27
  });
18
28
  }
19
29
  TaHostUtil2.reach = reach;
30
+ function marked(systemPrompt, mark) {
31
+ return role(systemPrompt).includes(mark);
32
+ }
33
+ TaHostUtil2.marked = marked;
34
+ function role(systemPrompt) {
35
+ if (!systemPrompt) {
36
+ return "";
37
+ }
38
+ const open = `<addendum>
39
+ `;
40
+ const start = systemPrompt.indexOf(open);
41
+ const context = systemPrompt.indexOf(`<project_context>
42
+ `);
43
+ if (start < 0 || context >= 0 && context < start) {
44
+ return "";
45
+ }
46
+ const end = systemPrompt.indexOf(`
47
+ </addendum>`, start);
48
+ return systemPrompt.slice(start + open.length, end < 0 ? undefined : end);
49
+ }
50
+ TaHostUtil2.role = role;
20
51
  })(TaHostUtil || (TaHostUtil = {}));
52
+ var TA_ASK_ENTRY = "ta-ask";
53
+ var TaAskUtil;
54
+ (function(TaAskUtil2) {
55
+ const LENGTH = 120;
56
+ function entry(question) {
57
+ const line = question.replace(/\s+/g, " ").trim();
58
+ return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
59
+ }
60
+ TaAskUtil2.entry = entry;
61
+ function asking(entries) {
62
+ var _a;
63
+ for (let i = entries.length - 1;i >= 0; i--) {
64
+ const entry2 = entries[i];
65
+ if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
66
+ return;
67
+ }
68
+ if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
69
+ return read(entry2);
70
+ }
71
+ }
72
+ return;
73
+ }
74
+ TaAskUtil2.asking = asking;
75
+ function next(asked, entry2) {
76
+ var _a;
77
+ if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
78
+ return;
79
+ }
80
+ return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
81
+ }
82
+ TaAskUtil2.next = next;
83
+ function read(found) {
84
+ var _a;
85
+ const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
86
+ if (typeof question !== "string" || !question.trim()) {
87
+ return;
88
+ }
89
+ const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
90
+ return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
91
+ }
92
+ })(TaAskUtil || (TaAskUtil = {}));
21
93
 
22
94
  // web-src/notify-protocol.ts
23
95
  var NAME = "@celljs/ta-notify";
@@ -189,6 +261,8 @@ function activate(pi) {
189
261
  let told = false;
190
262
  let asked;
191
263
  let last;
264
+ let startedAt = 0;
265
+ let marked = false;
192
266
  pi.on("session_start", () => {
193
267
  reach();
194
268
  });
@@ -196,6 +270,8 @@ function activate(pi) {
196
270
  told = false;
197
271
  asked = undefined;
198
272
  last = undefined;
273
+ startedAt = Date.now();
274
+ marked = false;
199
275
  });
200
276
  pi.on("context", (event) => {
201
277
  const messages = event.messages.filter((message) => !(message.role === "custom" && message.customType === ASK_TYPE));
@@ -203,6 +279,10 @@ function activate(pi) {
203
279
  });
204
280
  pi.on("agent_end", (event) => {
205
281
  last = NotifyUtil.lastAnswer(event.messages ?? []) ?? last;
282
+ if (asked && !marked) {
283
+ marked = true;
284
+ pi.appendEntry(TA_ASK_ENTRY, TaAskUtil.entry(asked.text));
285
+ }
206
286
  });
207
287
  pi.on("agent_settled", (event, ctx) => {
208
288
  const answer = last;
@@ -215,6 +295,11 @@ function activate(pi) {
215
295
  if (event.aborted || told || !answer || answer.aborted) {
216
296
  return;
217
297
  }
298
+ const asking = answer.failed ? undefined : TaAskUtil.asking(ctx.sessionManager.getBranch?.() ?? []);
299
+ if (asking && asking.at >= startedAt) {
300
+ post({ piSessionId: ctx.sessionManager.getSessionId(), id: String(answer.at), level: "ask", source: "turn", text: asking.question });
301
+ return;
302
+ }
218
303
  const text = NotifyUtil.text(answer.text) || (answer.failed ? NotifyServerTexts.failed() : "");
219
304
  if (!text) {
220
305
  return;
package/host/index.mjs CHANGED
@@ -103,7 +103,7 @@ class NotifyHost {
103
103
  post(input) {
104
104
  return this.serial(async () => {
105
105
  const info = (await this.host.listSessions()).find((session) => session.piSessionId === input.piSessionId);
106
- if (input.source === "turn" && info?.group) {
106
+ if (input.source === "turn" && input.level !== "ask" && info?.group) {
107
107
  return;
108
108
  }
109
109
  const target = info?.sessionFile ?? info?.sessionId;
@@ -131,6 +131,29 @@ class NotifyHost {
131
131
  return notice;
132
132
  });
133
133
  }
134
+ notify(input) {
135
+ return this.serial(async () => {
136
+ const text = NotifyUtil.text(String(input?.text ?? ""));
137
+ const level = input?.level;
138
+ if (!text || typeof input?.from !== "string" || typeof input.id !== "string" || !(level === "ask" || level === "failed" || level === "done")) {
139
+ return;
140
+ }
141
+ if (!NotifyUtil.allows(level, NotifyUtil.level(await this.read(Keys.LEVEL)), false)) {
142
+ return;
143
+ }
144
+ const notice = {
145
+ key: NotifyUtil.key(input.from, "package", input.id),
146
+ at: Date.now(),
147
+ level,
148
+ source: "package",
149
+ text,
150
+ title: String(input.title ?? "").slice(0, 80),
151
+ ...typeof input.view === "string" && input.view ? { view: input.view } : {}
152
+ };
153
+ await this.host.setExtensionData(NAME, Keys.NOTICES, NotifyUtil.keep(NotifyUtil.notices(await this.read(Keys.NOTICES)), notice));
154
+ return notice;
155
+ });
156
+ }
134
157
  mute(target, muted, title) {
135
158
  return this.serial(async () => {
136
159
  const list = NotifyUtil.muted(await this.read(Keys.MUTED)).filter((item) => item.target !== target);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-notify",
3
- "version": "4.12.0",
3
+ "version": "4.13.1",
4
4
  "description": "A pi package for Ta: tells the user when a conversation needs them, failed or answered, while they look elsewhere, and lets Ta ask them to decide with answers to pick",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -27,8 +27,8 @@
27
27
  "watch": "tsc -b -w --preserveWatchOutput"
28
28
  },
29
29
  "devDependencies": {
30
- "@celljs/ta-protocol": "4.12.0",
31
- "@celljs/ta-web": "4.12.0",
30
+ "@celljs/ta-protocol": "4.13.1",
31
+ "@celljs/ta-web": "4.13.1",
32
32
  "@types/react": "^19.3.0"
33
33
  },
34
34
  "publishConfig": {
@@ -50,6 +50,11 @@
50
50
  "host": "./host/index.mjs",
51
51
  "extensions": [
52
52
  "./extension/index.mjs"
53
- ]
53
+ ],
54
+ "permissions": {
55
+ "host": {
56
+ "*": "settings.manage"
57
+ }
58
+ }
54
59
  }
55
60
  }
package/web/index.js CHANGED
@@ -324,7 +324,7 @@ var STYLE = `
324
324
  .ta-notify-ask-head { display: flex; align-items: center; gap: 6px; color: color-mix(in srgb, var(--ta-yellow) 85%, var(--ta-muted)); font-size: calc(12px * var(--ta-font-scale)); }
325
325
  .ta-notify-ask-text { margin-top: 6px; color: var(--ta-text); line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
326
326
  .ta-notify-ask-options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
327
- .ta-notify-ask-option { min-height: 32px; padding: 0 12px; border: 1px solid var(--ta-border-field); border-radius: 8px; background: transparent; color: var(--ta-text); font: inherit; font-weight: 500; cursor: pointer; transition: background 120ms, opacity 120ms; }
327
+ .ta-notify-ask-option { min-height: 32px; padding: 0 12px; border: 1px solid var(--ta-border); border-radius: 8px; background: transparent; color: var(--ta-text); font: inherit; font-weight: 500; cursor: pointer; transition: background 120ms, opacity 120ms; }
328
328
  .ta-notify-ask-option:hover:not(:disabled) { background: var(--ta-hover); }
329
329
  .ta-notify-ask-option.ta-on { border-color: var(--ta-green); color: var(--ta-green); }
330
330
  .ta-notify-ask-option:disabled { opacity: 0.45; cursor: default; }
@@ -369,7 +369,8 @@ var NoticeWatchUtil;
369
369
  level: notice.level,
370
370
  text: notice.text,
371
371
  options: notice.options,
372
- actions: mute && words && notice.level !== "ask" ? [{ label: words.mute, run: mute }] : undefined
372
+ actions: mute && words && notice.level !== "ask" && notice.source !== "package" ? [{ label: words.mute, run: mute }] : undefined,
373
+ ...notice.source === "package" ? { title: notice.title, view: notice.view } : {}
373
374
  };
374
375
  }
375
376
  NoticeWatchUtil.sessionNotice = sessionNotice;