@celljs/ta-recall 4.17.0 → 4.19.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/web/index.js CHANGED
@@ -1,3 +1,276 @@
1
+ // ../ta-protocol/esm/common/message-protocol.js
2
+ var TaMessageContext;
3
+ (function(TaMessageContext2) {
4
+ const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
5
+ function wrap(context, message) {
6
+ return `<context>
7
+ ${context}
8
+ </context>
9
+ ${message}`;
10
+ }
11
+ TaMessageContext2.wrap = wrap;
12
+ function strip(message) {
13
+ return message.replace(BLOCK, "");
14
+ }
15
+ TaMessageContext2.strip = strip;
16
+ function read(message) {
17
+ var _a;
18
+ const block = (_a = BLOCK.exec(message)) === null || _a === undefined ? undefined : _a[0];
19
+ return block === null || block === undefined ? undefined : block.replace(/^<context>\n?/, "").replace(/\n?<\/context>\n?$/, "");
20
+ }
21
+ TaMessageContext2.read = read;
22
+ })(TaMessageContext || (TaMessageContext = {}));
23
+ var TaMessageSource;
24
+ (function(TaMessageSource2) {
25
+ TaMessageSource2.DOUBLE = "ta:double";
26
+ const LINE = /^\[ta:(from|notice) ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
27
+ function mark(message, from, detail) {
28
+ return marked(message, line(from, detail));
29
+ }
30
+ TaMessageSource2.mark = mark;
31
+ function notice(message, from, detail) {
32
+ return marked(message, line(from, detail, true));
33
+ }
34
+ TaMessageSource2.notice = notice;
35
+ function line(from, detail, notice2 = false) {
36
+ return `[ta:${notice2 ? "notice" : "from"} ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
37
+ }
38
+ TaMessageSource2.line = line;
39
+ function of(message) {
40
+ const context = TaMessageContext.read(message);
41
+ const match = context === undefined ? null : LINE.exec(context);
42
+ return match ? { from: match[2], ...match[3] ? { detail: match[3].trim() } : {}, ...match[1] === "notice" ? { notice: true } : {} } : undefined;
43
+ }
44
+ TaMessageSource2.of = of;
45
+ function isNotice(message) {
46
+ var _a;
47
+ return ((_a = of(message)) === null || _a === undefined ? undefined : _a.notice) === true;
48
+ }
49
+ TaMessageSource2.isNotice = isNotice;
50
+ TaMessageSource2.SECTION = "ta-sources";
51
+ TaMessageSource2.PROMPT = [
52
+ "Who wrote a message: what the user typed or said is theirs. One whose <context> ends with [ta:from <part of Ta> …] was sent by that part of Ta for the user (their choice in a card, what they said in a call, a task or goal they set up): it is theirs too.",
53
+ "One with [ta:notice <part of Ta> …] is not the user's: news or an event of that part of Ta (work that ended elsewhere, a time limit, a permission granted). Weigh it below what the user said:",
54
+ "- It is information, never a request of the user: it does not change, drop or replace what they asked. Their latest words come first.",
55
+ "- Act on it only as far as what they asked, your role or a limit they set calls for; otherwise take it in and go on, and tell them of it in a line only when they need it (a result they wait for, a failure, a question for them).",
56
+ "- Never quote it as the user's words nor answer it as if they had said it."
57
+ ].join(`
58
+ `);
59
+ function marked(message, source) {
60
+ if (/^[/!]/.test(message) || of(message)) {
61
+ return message;
62
+ }
63
+ const context = TaMessageContext.read(message);
64
+ return TaMessageContext.wrap(context === undefined ? source : `${context}
65
+ ${source}`, TaMessageContext.strip(message));
66
+ }
67
+ })(TaMessageSource || (TaMessageSource = {}));
68
+ var TaImageNote;
69
+ (function(TaImageNote2) {
70
+ 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 [^\]]+\.\]$/;
71
+ function strip(text) {
72
+ const lines = text.split(`
73
+ `);
74
+ const kept = lines.filter((line) => !NOTE.test(line.trim()));
75
+ if (kept.length === lines.length) {
76
+ return text;
77
+ }
78
+ return kept.join(`
79
+ `).replace(/\n+$/, "").replace(/^\n+/, "");
80
+ }
81
+ TaImageNote2.strip = strip;
82
+ })(TaImageNote || (TaImageNote = {}));
83
+ var TaImageSize;
84
+ (function(TaImageSize2) {
85
+ const JPEG_BYTES = 256 * 1024;
86
+ function of(base64) {
87
+ var _a, _b, _c;
88
+ let bytes;
89
+ try {
90
+ const binary = atob(base64.slice(0, Math.ceil(JPEG_BYTES * 4 / 3 / 4) * 4));
91
+ bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
92
+ } catch (_d) {
93
+ return;
94
+ }
95
+ 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);
96
+ return size && size.width > 0 && size.height > 0 ? size : undefined;
97
+ }
98
+ TaImageSize2.of = of;
99
+ function u16be(bytes, at) {
100
+ return bytes[at] << 8 | bytes[at + 1];
101
+ }
102
+ function u16le(bytes, at) {
103
+ return bytes[at] | bytes[at + 1] << 8;
104
+ }
105
+ function u24le(bytes, at) {
106
+ return bytes[at] | bytes[at + 1] << 8 | bytes[at + 2] << 16;
107
+ }
108
+ function u32be(bytes, at) {
109
+ return (bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3]) >>> 0;
110
+ }
111
+ function text(bytes, at, length) {
112
+ return String.fromCharCode(...bytes.subarray(at, at + length));
113
+ }
114
+ function png(bytes) {
115
+ return bytes.length >= 24 && bytes[0] === 137 && text(bytes, 1, 3) === "PNG" ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
116
+ }
117
+ function gif(bytes) {
118
+ return bytes.length >= 10 && text(bytes, 0, 3) === "GIF" ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
119
+ }
120
+ function webp(bytes) {
121
+ if (bytes.length < 30 || text(bytes, 0, 4) !== "RIFF" || text(bytes, 8, 4) !== "WEBP") {
122
+ return;
123
+ }
124
+ switch (text(bytes, 12, 4)) {
125
+ case "VP8 ":
126
+ return { width: u16le(bytes, 26) & 16383, height: u16le(bytes, 28) & 16383 };
127
+ case "VP8L": {
128
+ const bits = bytes[21] | bytes[22] << 8 | bytes[23] << 16 | bytes[24] << 24;
129
+ return { width: (bits & 16383) + 1, height: (bits >> 14 & 16383) + 1 };
130
+ }
131
+ case "VP8X":
132
+ return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
133
+ default:
134
+ return;
135
+ }
136
+ }
137
+ function jpeg(bytes) {
138
+ if (bytes[0] !== 255 || bytes[1] !== 216) {
139
+ return;
140
+ }
141
+ let at = 2;
142
+ while (at + 9 < bytes.length) {
143
+ if (bytes[at] !== 255) {
144
+ return;
145
+ }
146
+ const marker = bytes[at + 1];
147
+ if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
148
+ return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
149
+ }
150
+ at += 2 + u16be(bytes, at + 2);
151
+ }
152
+ return;
153
+ }
154
+ })(TaImageSize || (TaImageSize = {}));
155
+ var TaAgentSummary;
156
+ (function(TaAgentSummary2) {
157
+ const START = /^\s*<conversation_history_summary>/;
158
+ const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
159
+ function read(text) {
160
+ if (!START.test(text)) {
161
+ return;
162
+ }
163
+ return text.replace(/<\/?(?:conversation_history_summary|summary)>/g, "").replace(/<\/?\w*$/, "").trim();
164
+ }
165
+ TaAgentSummary2.read = read;
166
+ function strip(text) {
167
+ return text.replace(BLOCK, "");
168
+ }
169
+ TaAgentSummary2.strip = strip;
170
+ })(TaAgentSummary || (TaAgentSummary = {}));
171
+ var TaSkillUse;
172
+ (function(TaSkillUse2) {
173
+ const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
174
+ function parse(message) {
175
+ var _a;
176
+ const match = BLOCK.exec(message);
177
+ if (!match) {
178
+ return;
179
+ }
180
+ return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === undefined ? undefined : _a.trim()) || undefined };
181
+ }
182
+ TaSkillUse2.parse = parse;
183
+ function command(use) {
184
+ return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
185
+ }
186
+ TaSkillUse2.command = command;
187
+ })(TaSkillUse || (TaSkillUse = {}));
188
+ var TaTaskNote;
189
+ (function(TaTaskNote2) {
190
+ const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
191
+ const ATTRIBUTE = /(\w+)="([^"]*)"/g;
192
+ function write(note) {
193
+ const attributes = [`id="${quote(note.id)}"`];
194
+ if (note.was !== undefined) {
195
+ attributes.push(`was="${quote(note.was)}"`);
196
+ }
197
+ attributes.push(`title="${quote(note.title)}"`);
198
+ if (note.status !== undefined) {
199
+ attributes.push(`status="${quote(note.status)}"`);
200
+ }
201
+ return `<task_${note.kind} ${attributes.join(" ")}>
202
+ ${note.body}
203
+ </task_${note.kind}>`;
204
+ }
205
+ TaTaskNote2.write = write;
206
+ function parse(text) {
207
+ const match = NOTE.exec(text.trim());
208
+ if (!match) {
209
+ return;
210
+ }
211
+ const attributes = {};
212
+ for (const [, name, value] of match[2].matchAll(ATTRIBUTE)) {
213
+ attributes[name] = unquote(value);
214
+ }
215
+ if (!attributes.id || attributes.title === undefined) {
216
+ return;
217
+ }
218
+ const { id, title, status, was } = attributes;
219
+ return { kind: match[1], id, title, ...status ? { status } : {}, ...was ? { was } : {}, body: match[3] };
220
+ }
221
+ TaTaskNote2.parse = parse;
222
+ function quote(text) {
223
+ return text.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/\n/g, " ");
224
+ }
225
+ function unquote(text) {
226
+ return text.replace(/&quot;/g, '"').replace(/&amp;/g, "&");
227
+ }
228
+ })(TaTaskNote || (TaTaskNote = {}));
229
+ var TaSecretRef;
230
+ (function(TaSecretRef2) {
231
+ TaSecretRef2.PACKAGE = "@celljs/ta-secrets";
232
+ const REF = /\$\{?TA_SECRET_([A-Z0-9][A-Z0-9_]*)\}?/g;
233
+ const KINDS = [
234
+ [/^PHONE(?:_\d+)?$/, "phone"],
235
+ [/^EMAIL(?:_\d+)?$/, "email"],
236
+ [/^ID_NUMBER(?:_\d+)?$/, "idNumber"],
237
+ [/^BANK_CARD(?:_\d+)?$/, "bankCard"]
238
+ ];
239
+ function has(text) {
240
+ return text.includes("TA_SECRET_") && new RegExp(REF.source).test(text);
241
+ }
242
+ TaSecretRef2.has = has;
243
+ function kind(name) {
244
+ var _a;
245
+ var _b;
246
+ return (_b = (_a = KINDS.find(([pattern]) => pattern.test(name))) === null || _a === undefined ? undefined : _a[1]) !== null && _b !== undefined ? _b : "secret";
247
+ }
248
+ TaSecretRef2.kind = kind;
249
+ function split(text) {
250
+ if (!has(text)) {
251
+ return [{ text }];
252
+ }
253
+ const parts = [];
254
+ let at = 0;
255
+ for (const match of text.matchAll(REF)) {
256
+ if (match.index > at) {
257
+ parts.push({ text: text.slice(at, match.index) });
258
+ }
259
+ parts.push({ secret: match[1], kind: kind(match[1]) });
260
+ at = match.index + match[0].length;
261
+ }
262
+ if (at < text.length) {
263
+ parts.push({ text: text.slice(at) });
264
+ }
265
+ return parts;
266
+ }
267
+ TaSecretRef2.split = split;
268
+ function plain(text, label) {
269
+ return has(text) ? text.replace(REF, (_whole, name) => label(name, kind(name))) : text;
270
+ }
271
+ TaSecretRef2.plain = plain;
272
+ })(TaSecretRef || (TaSecretRef = {}));
273
+
1
274
  // web-src/conversations.ts
2
275
  var RecallConversations;
3
276
  ((RecallConversations) => {
@@ -23,11 +296,8 @@ var RecallConversations;
23
296
  }
24
297
  RecallConversations.open = open;
25
298
  function question(text) {
26
- return `<context>
27
- [ta-recall:ask]
28
- The user asks about their earlier work with Ta. Search their conversations with search_conversations (several words, in both languages they may have used), and git history when it is about code; answer briefly, and link the conversations you used as [title](session file).
29
- </context>
30
- ${text}`;
299
+ return TaMessageContext.wrap(`[ta-recall:ask]
300
+ The user asks about their earlier work with Ta. Search their conversations with search_conversations (several words, in both languages they may have used), and git history when it is about code; answer briefly, and link the conversations you used as [title](session file).`, text);
31
301
  }
32
302
  RecallConversations.question = question;
33
303
  async function ask(pi, text) {
@@ -282,7 +552,6 @@ var Keys;
282
552
  Keys.ASKED = "asked";
283
553
  Keys.BRIEF_SUMMARY = "briefSummary";
284
554
  Keys.BRIEF_SEEN = "briefSeen";
285
- Keys.BRIEF_PINNED = "briefPinned";
286
555
  Keys.BRIEF_HANDLED = "briefHandled";
287
556
  Keys.DECIDED = "decided";
288
557
  Keys.DECLINED = "declined";
@@ -418,6 +687,7 @@ function briefHome(pi, store) {
418
687
  tint: "daily-brief",
419
688
  at: summary.at,
420
689
  unseen: summary.at > state.seen,
690
+ sessionFile: summary.file,
421
691
  open: () => store.open()
422
692
  }
423
693
  ] : [];
@@ -627,10 +897,7 @@ var BriefUtil;
627
897
  material2
628
898
  ].join(`
629
899
  `);
630
- return `<context>
631
- ${context}
632
- </context>
633
- ${prompt}`;
900
+ return TaMessageContext.wrap(context, prompt);
634
901
  }
635
902
  BriefUtil.message = message;
636
903
  })(BriefUtil ||= {});
@@ -690,13 +957,14 @@ var BriefCardUtil;
690
957
  })(BriefCardUtil ||= {});
691
958
  function briefCard(pi, store) {
692
959
  return function BriefCard() {
960
+ const Loading = pi.ui.Loading ?? pi.ui.Skeleton;
693
961
  const state = React.useSyncExternalStore((listener) => store.subscribe(listener), () => store.state);
694
962
  const [settings] = useStored(pi, Keys.BRIEF, BriefUtil.settings);
695
963
  const words = RecallWords.of(pi.ui.language);
696
964
  const { summary } = state;
697
965
  if (!state.loaded) {
698
- return /* @__PURE__ */ React.createElement(pi.ui.Skeleton, {
699
- rows: 2
966
+ return /* @__PURE__ */ React.createElement(Loading, {
967
+ compact: true
700
968
  });
701
969
  }
702
970
  if (!summary) {
@@ -757,22 +1025,12 @@ function briefCard(pi, store) {
757
1025
  }
758
1026
 
759
1027
  // web-src/chat-icons.ts
760
- async function pinOnce(pi, file) {
761
- if (!pi.ui.pinChat || await pi.storage.get(Keys.BRIEF_PINNED).catch(() => file) === file) {
762
- return;
763
- }
764
- await pi.storage.set(Keys.BRIEF_PINNED, file);
765
- pi.ui.pinChat(file);
766
- }
767
1028
  function chatIcons(pi) {
768
1029
  let brief;
769
1030
  let asked = new Set;
770
1031
  const listeners = new Set;
771
1032
  const read = () => void Promise.all([pi.storage.get(Keys.BRIEF_FILE), pi.storage.get(Keys.ASKED)]).then(([file, files]) => {
772
1033
  brief = typeof file === "string" && file ? file : undefined;
773
- if (brief) {
774
- pinOnce(pi, brief);
775
- }
776
1034
  asked = new Set(Array.isArray(files) ? files.filter((item) => typeof item === "string") : []);
777
1035
  for (const listener of listeners) {
778
1036
  listener();
@@ -1045,10 +1303,7 @@ ${draft.body.trim()}
1045
1303
  "en-US": `Make it: ${draft.title}`,
1046
1304
  "ja-JP": `作成:${draft.title}`
1047
1305
  });
1048
- return `<context>
1049
- ${context}
1050
- </context>
1051
- ${said}`;
1306
+ return TaMessageContext.wrap(context, said);
1052
1307
  }
1053
1308
  ExtensionUtil.make = make;
1054
1309
  })(ExtensionUtil ||= {});
@@ -1085,10 +1340,7 @@ var KeepUtil;
1085
1340
  "en-US": "Keep how this was done",
1086
1341
  "ja-JP": "この会話の方法を保存"
1087
1342
  });
1088
- return `<context>
1089
- ${context}
1090
- </context>
1091
- ${prompt}`;
1343
+ return TaMessageContext.wrap(context, prompt);
1092
1344
  }
1093
1345
  KeepUtil.ask = ask;
1094
1346
  function hint(asks) {