@celljs/ta-call 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 +9 -0
- package/README.md +8 -2
- package/extension/index.mjs +474 -0
- package/host/index.mjs +899 -0
- package/package.json +62 -4
- package/web/index.js +552 -0
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-call",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "4.17.0",
|
|
4
|
+
"description": "A pi package for Ta: in a call, a front that talks at once, whatever the work does, hands the work to the conversation and looks up any detail of it when asked",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package"
|
|
7
|
+
],
|
|
8
|
+
"homepage": "https://github.com/cellbang/ta",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/cellbang/ta/issues"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/cellbang/cell.git"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"files": [
|
|
18
|
+
"web",
|
|
19
|
+
"host",
|
|
20
|
+
"extension",
|
|
21
|
+
"!**/*.map"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc -b && bun build web-src/index.tsx --format esm --target browser --outfile web/index.js && bun build web-src/host.ts --format esm --target node --outfile host/index.mjs && bun build web-src/extension.ts --format esm --target node --outfile extension/index.mjs",
|
|
25
|
+
"clean": "rm -rf lib web host extension *.tsbuildinfo",
|
|
26
|
+
"test": "bun test ./lib",
|
|
27
|
+
"watch": "tsc -b -w --preserveWatchOutput"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@celljs/ta-protocol": "4.17.0",
|
|
31
|
+
"@celljs/ta-web": "4.17.0",
|
|
32
|
+
"@types/react": "^19.3.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"pi": {
|
|
38
|
+
"title": {
|
|
39
|
+
"en": "Calls",
|
|
40
|
+
"zh-CN": "通话",
|
|
41
|
+
"zh-TW": "通話",
|
|
42
|
+
"ja-JP": "通話"
|
|
43
|
+
},
|
|
44
|
+
"summary": {
|
|
45
|
+
"en": "Talk with Ta as with a person: it answers at once while the work goes on, chats, reads you a poem, hands the work over and knows any detail of it when you ask.",
|
|
46
|
+
"zh-CN": "像和真人打电话一样和 Ta 说话:干活的时候也随时回应你,能闲聊、念诗,把要做的事交给后台,问到任务的任何细节都答得上来。",
|
|
47
|
+
"zh-TW": "像和真人打電話一樣和 Ta 說話:幹活的時候也隨時回應你,能閒聊、念詩,把要做的事交給後台,問到任務的任何細節都答得上來。",
|
|
48
|
+
"ja-JP": "人と電話するように Ta と話せます。作業中でもすぐに応え、雑談や詩の朗読もでき、作業は裏に任せ、聞かれれば細部まで答えます。"
|
|
49
|
+
},
|
|
50
|
+
"icon": "Phone",
|
|
51
|
+
"web": [
|
|
52
|
+
"./web/index.js"
|
|
53
|
+
],
|
|
54
|
+
"host": "./host/index.mjs",
|
|
55
|
+
"extensions": [
|
|
56
|
+
"./extension/index.mjs"
|
|
57
|
+
],
|
|
58
|
+
"permissions": {
|
|
59
|
+
"host": {
|
|
60
|
+
"*": "models.use"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
package/web/index.js
ADDED
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
// web-src/call-protocol.ts
|
|
2
|
+
var NAME = "@celljs/ta-call";
|
|
3
|
+
var CALL_MARK = "[ta-call]";
|
|
4
|
+
|
|
5
|
+
// ../ta-protocol/esm/common/language.js
|
|
6
|
+
var TaLanguageUtil;
|
|
7
|
+
(function(TaLanguageUtil2) {
|
|
8
|
+
TaLanguageUtil2.ALL = ["zh-CN", "zh-TW", "en-US", "ja-JP"];
|
|
9
|
+
TaLanguageUtil2.NAMES = { "zh-CN": "简体中文", "zh-TW": "繁體中文", "en-US": "English", "ja-JP": "日本語" };
|
|
10
|
+
function of(tag) {
|
|
11
|
+
const said = (tag !== null && tag !== undefined ? tag : "").toLowerCase().replace(/_/g, "-");
|
|
12
|
+
if (/^zh(\b|-)/.test(said)) {
|
|
13
|
+
return /-hant\b/.test(said) || !/-hans\b/.test(said) && /-(tw|hk|mo)\b/.test(said) ? "zh-TW" : "zh-CN";
|
|
14
|
+
}
|
|
15
|
+
return /^ja(\b|-)/.test(said) ? "ja-JP" : "en-US";
|
|
16
|
+
}
|
|
17
|
+
TaLanguageUtil2.of = of;
|
|
18
|
+
function server(env = typeof process === "undefined" ? {} : process.env) {
|
|
19
|
+
return of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG);
|
|
20
|
+
}
|
|
21
|
+
TaLanguageUtil2.server = server;
|
|
22
|
+
function pick(language, words) {
|
|
23
|
+
return words[of(language)];
|
|
24
|
+
}
|
|
25
|
+
TaLanguageUtil2.pick = pick;
|
|
26
|
+
function say(words) {
|
|
27
|
+
return words[server()];
|
|
28
|
+
}
|
|
29
|
+
TaLanguageUtil2.say = say;
|
|
30
|
+
function chinese(language) {
|
|
31
|
+
return of(language).startsWith("zh");
|
|
32
|
+
}
|
|
33
|
+
TaLanguageUtil2.chinese = chinese;
|
|
34
|
+
function cjk(language) {
|
|
35
|
+
return of(language) !== "en-US";
|
|
36
|
+
}
|
|
37
|
+
TaLanguageUtil2.cjk = cjk;
|
|
38
|
+
function list(language, items) {
|
|
39
|
+
return items.join(cjk(language) ? "、" : ", ");
|
|
40
|
+
}
|
|
41
|
+
TaLanguageUtil2.list = list;
|
|
42
|
+
})(TaLanguageUtil || (TaLanguageUtil = {}));
|
|
43
|
+
|
|
44
|
+
// ../ta-protocol/esm/common/message-protocol.js
|
|
45
|
+
var TaMessageContext;
|
|
46
|
+
(function(TaMessageContext2) {
|
|
47
|
+
const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
|
|
48
|
+
function wrap(context, message) {
|
|
49
|
+
return `<context>
|
|
50
|
+
${context}
|
|
51
|
+
</context>
|
|
52
|
+
${message}`;
|
|
53
|
+
}
|
|
54
|
+
TaMessageContext2.wrap = wrap;
|
|
55
|
+
function strip(message) {
|
|
56
|
+
return message.replace(BLOCK, "");
|
|
57
|
+
}
|
|
58
|
+
TaMessageContext2.strip = strip;
|
|
59
|
+
function read(message) {
|
|
60
|
+
var _a;
|
|
61
|
+
const block = (_a = BLOCK.exec(message)) === null || _a === undefined ? undefined : _a[0];
|
|
62
|
+
return block === null || block === undefined ? undefined : block.replace(/^<context>\n?/, "").replace(/\n?<\/context>\n?$/, "");
|
|
63
|
+
}
|
|
64
|
+
TaMessageContext2.read = read;
|
|
65
|
+
})(TaMessageContext || (TaMessageContext = {}));
|
|
66
|
+
var TaMessageSource;
|
|
67
|
+
(function(TaMessageSource2) {
|
|
68
|
+
TaMessageSource2.DOUBLE = "ta:double";
|
|
69
|
+
const LINE = /^\[ta:from ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
|
|
70
|
+
function mark(message, from, detail) {
|
|
71
|
+
if (/^[/!]/.test(message) || of(message)) {
|
|
72
|
+
return message;
|
|
73
|
+
}
|
|
74
|
+
const line = `[ta:from ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
|
|
75
|
+
const context = TaMessageContext.read(message);
|
|
76
|
+
return TaMessageContext.wrap(context === undefined ? line : `${context}
|
|
77
|
+
${line}`, TaMessageContext.strip(message));
|
|
78
|
+
}
|
|
79
|
+
TaMessageSource2.mark = mark;
|
|
80
|
+
function of(message) {
|
|
81
|
+
const context = TaMessageContext.read(message);
|
|
82
|
+
const match = context === undefined ? null : LINE.exec(context);
|
|
83
|
+
return match ? { from: match[1], ...match[2] ? { detail: match[2].trim() } : {} } : undefined;
|
|
84
|
+
}
|
|
85
|
+
TaMessageSource2.of = of;
|
|
86
|
+
})(TaMessageSource || (TaMessageSource = {}));
|
|
87
|
+
var TaImageNote;
|
|
88
|
+
(function(TaImageNote2) {
|
|
89
|
+
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 [^\]]+\.\]$/;
|
|
90
|
+
function strip(text) {
|
|
91
|
+
const lines = text.split(`
|
|
92
|
+
`);
|
|
93
|
+
const kept = lines.filter((line) => !NOTE.test(line.trim()));
|
|
94
|
+
if (kept.length === lines.length) {
|
|
95
|
+
return text;
|
|
96
|
+
}
|
|
97
|
+
return kept.join(`
|
|
98
|
+
`).replace(/\n+$/, "").replace(/^\n+/, "");
|
|
99
|
+
}
|
|
100
|
+
TaImageNote2.strip = strip;
|
|
101
|
+
})(TaImageNote || (TaImageNote = {}));
|
|
102
|
+
var TaImageSize;
|
|
103
|
+
(function(TaImageSize2) {
|
|
104
|
+
const JPEG_BYTES = 256 * 1024;
|
|
105
|
+
function of(base64) {
|
|
106
|
+
var _a, _b, _c;
|
|
107
|
+
let bytes;
|
|
108
|
+
try {
|
|
109
|
+
const binary = atob(base64.slice(0, Math.ceil(JPEG_BYTES * 4 / 3 / 4) * 4));
|
|
110
|
+
bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
111
|
+
} catch (_d) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
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);
|
|
115
|
+
return size && size.width > 0 && size.height > 0 ? size : undefined;
|
|
116
|
+
}
|
|
117
|
+
TaImageSize2.of = of;
|
|
118
|
+
function u16be(bytes, at) {
|
|
119
|
+
return bytes[at] << 8 | bytes[at + 1];
|
|
120
|
+
}
|
|
121
|
+
function u16le(bytes, at) {
|
|
122
|
+
return bytes[at] | bytes[at + 1] << 8;
|
|
123
|
+
}
|
|
124
|
+
function u24le(bytes, at) {
|
|
125
|
+
return bytes[at] | bytes[at + 1] << 8 | bytes[at + 2] << 16;
|
|
126
|
+
}
|
|
127
|
+
function u32be(bytes, at) {
|
|
128
|
+
return (bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3]) >>> 0;
|
|
129
|
+
}
|
|
130
|
+
function text(bytes, at, length) {
|
|
131
|
+
return String.fromCharCode(...bytes.subarray(at, at + length));
|
|
132
|
+
}
|
|
133
|
+
function png(bytes) {
|
|
134
|
+
return bytes.length >= 24 && bytes[0] === 137 && text(bytes, 1, 3) === "PNG" ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
|
|
135
|
+
}
|
|
136
|
+
function gif(bytes) {
|
|
137
|
+
return bytes.length >= 10 && text(bytes, 0, 3) === "GIF" ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
|
|
138
|
+
}
|
|
139
|
+
function webp(bytes) {
|
|
140
|
+
if (bytes.length < 30 || text(bytes, 0, 4) !== "RIFF" || text(bytes, 8, 4) !== "WEBP") {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
switch (text(bytes, 12, 4)) {
|
|
144
|
+
case "VP8 ":
|
|
145
|
+
return { width: u16le(bytes, 26) & 16383, height: u16le(bytes, 28) & 16383 };
|
|
146
|
+
case "VP8L": {
|
|
147
|
+
const bits = bytes[21] | bytes[22] << 8 | bytes[23] << 16 | bytes[24] << 24;
|
|
148
|
+
return { width: (bits & 16383) + 1, height: (bits >> 14 & 16383) + 1 };
|
|
149
|
+
}
|
|
150
|
+
case "VP8X":
|
|
151
|
+
return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
|
|
152
|
+
default:
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function jpeg(bytes) {
|
|
157
|
+
if (bytes[0] !== 255 || bytes[1] !== 216) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
let at = 2;
|
|
161
|
+
while (at + 9 < bytes.length) {
|
|
162
|
+
if (bytes[at] !== 255) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const marker = bytes[at + 1];
|
|
166
|
+
if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
|
|
167
|
+
return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
|
|
168
|
+
}
|
|
169
|
+
at += 2 + u16be(bytes, at + 2);
|
|
170
|
+
}
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
})(TaImageSize || (TaImageSize = {}));
|
|
174
|
+
var TaAgentSummary;
|
|
175
|
+
(function(TaAgentSummary2) {
|
|
176
|
+
const START = /^\s*<conversation_history_summary>/;
|
|
177
|
+
const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
|
|
178
|
+
function read(text) {
|
|
179
|
+
if (!START.test(text)) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
return text.replace(/<\/?(?:conversation_history_summary|summary)>/g, "").replace(/<\/?\w*$/, "").trim();
|
|
183
|
+
}
|
|
184
|
+
TaAgentSummary2.read = read;
|
|
185
|
+
function strip(text) {
|
|
186
|
+
return text.replace(BLOCK, "");
|
|
187
|
+
}
|
|
188
|
+
TaAgentSummary2.strip = strip;
|
|
189
|
+
})(TaAgentSummary || (TaAgentSummary = {}));
|
|
190
|
+
var TaSkillUse;
|
|
191
|
+
(function(TaSkillUse2) {
|
|
192
|
+
const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
|
|
193
|
+
function parse(message) {
|
|
194
|
+
var _a;
|
|
195
|
+
const match = BLOCK.exec(message);
|
|
196
|
+
if (!match) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === undefined ? undefined : _a.trim()) || undefined };
|
|
200
|
+
}
|
|
201
|
+
TaSkillUse2.parse = parse;
|
|
202
|
+
function command(use) {
|
|
203
|
+
return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
|
|
204
|
+
}
|
|
205
|
+
TaSkillUse2.command = command;
|
|
206
|
+
})(TaSkillUse || (TaSkillUse = {}));
|
|
207
|
+
var TaTaskNote;
|
|
208
|
+
(function(TaTaskNote2) {
|
|
209
|
+
const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
|
|
210
|
+
const ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
211
|
+
function write(note) {
|
|
212
|
+
const attributes = [`id="${quote(note.id)}"`];
|
|
213
|
+
if (note.was !== undefined) {
|
|
214
|
+
attributes.push(`was="${quote(note.was)}"`);
|
|
215
|
+
}
|
|
216
|
+
attributes.push(`title="${quote(note.title)}"`);
|
|
217
|
+
if (note.status !== undefined) {
|
|
218
|
+
attributes.push(`status="${quote(note.status)}"`);
|
|
219
|
+
}
|
|
220
|
+
return `<task_${note.kind} ${attributes.join(" ")}>
|
|
221
|
+
${note.body}
|
|
222
|
+
</task_${note.kind}>`;
|
|
223
|
+
}
|
|
224
|
+
TaTaskNote2.write = write;
|
|
225
|
+
function parse(text) {
|
|
226
|
+
const match = NOTE.exec(text.trim());
|
|
227
|
+
if (!match) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const attributes = {};
|
|
231
|
+
for (const [, name, value] of match[2].matchAll(ATTRIBUTE)) {
|
|
232
|
+
attributes[name] = unquote(value);
|
|
233
|
+
}
|
|
234
|
+
if (!attributes.id || attributes.title === undefined) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const { id, title, status, was } = attributes;
|
|
238
|
+
return { kind: match[1], id, title, ...status ? { status } : {}, ...was ? { was } : {}, body: match[3] };
|
|
239
|
+
}
|
|
240
|
+
TaTaskNote2.parse = parse;
|
|
241
|
+
function quote(text) {
|
|
242
|
+
return text.replace(/&/g, "&").replace(/"/g, """).replace(/\n/g, " ");
|
|
243
|
+
}
|
|
244
|
+
function unquote(text) {
|
|
245
|
+
return text.replace(/"/g, '"').replace(/&/g, "&");
|
|
246
|
+
}
|
|
247
|
+
})(TaTaskNote || (TaTaskNote = {}));
|
|
248
|
+
|
|
249
|
+
// web-src/call-util.ts
|
|
250
|
+
var LOOK_CHARS = 1500;
|
|
251
|
+
var ENTRY_CHARS = 600;
|
|
252
|
+
var SEED_CHARS = 1200;
|
|
253
|
+
var ROLE_CHARS = 800;
|
|
254
|
+
var LAST_ENTRIES = 12;
|
|
255
|
+
var NEWS = "[news]";
|
|
256
|
+
var QUIET = "-";
|
|
257
|
+
var FAST = /(mini|flash|haiku|lite|nano|turbo|small|fast|air)\b/i;
|
|
258
|
+
var CallUtil;
|
|
259
|
+
((CallUtil) => {
|
|
260
|
+
function role(id, target, seed) {
|
|
261
|
+
const work = target.double ? "the user's double, which hands out tasks of its own" : `their conversation${target.cwd ? ` in ${target.cwd}` : ""}`;
|
|
262
|
+
return [
|
|
263
|
+
`${CALL_MARK} ${id}`,
|
|
264
|
+
`You are Ta, on a voice call with the user. You only talk: what you write is read aloud at once. The work goes on elsewhere, in ${work}, while you talk.`,
|
|
265
|
+
"- Answer in the language of the user, short, as on the phone: one to three sentences of plain words. No markdown, lists, tables, code, paths, links or cards.",
|
|
266
|
+
"- Chat, tell a poem, sing a song (say its words), answer what you know: do it yourself, never through the work.",
|
|
267
|
+
"- What needs files, commands, code, research or anything the work does: tell the work (into what it does now, or after it); for something apart from it, open a side conversation with side. Then say in a few words that you did. You cannot do it yourself.",
|
|
268
|
+
"- Asked how the work goes or about any detail of it: status, then look with a question for the detail; answer from what they return, never guess.",
|
|
269
|
+
"- When the user wants what the work or a side conversation does stopped: stop.",
|
|
270
|
+
"- To change Ta itself (its settings, the captions of this call, pin a conversation, turn an extension on or off): app_run yourself, at once, then say in a few words it is done.",
|
|
271
|
+
"- When the work waits for the user to decide: read them the question (app_run asks.list), and answer it with what they say (app_run asks.answer); never decide for them.",
|
|
272
|
+
"- What only the screen has (what the user looks at, a page of an extension): app_look, app_go, app_do; to show them where something is, with here: true.",
|
|
273
|
+
"- A message that starts with [sent] went to the work already: acknowledge it in a few words.",
|
|
274
|
+
`- A message that starts with ${NEWS} is news of the work, not the user speaking: when the user should hear it (a result, a failure, a question for them), say it in one short sentence as you would on the phone, the answer first; else answer ${QUIET} alone.`,
|
|
275
|
+
...seed ? ["", seedText(seed, target.double)] : []
|
|
276
|
+
].join(`
|
|
277
|
+
`);
|
|
278
|
+
}
|
|
279
|
+
CallUtil.role = role;
|
|
280
|
+
function seedText(seed, double) {
|
|
281
|
+
const lines = ["<called>"];
|
|
282
|
+
if (seed.name) {
|
|
283
|
+
lines.push(`Conversation: ${flat(seed.name).slice(0, 120)}${seed.cwd ? ` (in ${seed.cwd})` : ""}`);
|
|
284
|
+
}
|
|
285
|
+
const role2 = seed.role && !double ? flat(seed.role).slice(0, ROLE_CHARS) : "";
|
|
286
|
+
if (role2) {
|
|
287
|
+
lines.push(`Its role: speak as it would, with its focus. ${role2}`);
|
|
288
|
+
}
|
|
289
|
+
lines.push(`Now: ${seed.working ? "working" : "idle"}${seed.queued ? `, ${seed.queued} queued` : ""}${seed.waiting ? ", waiting for the user" : ""}.`);
|
|
290
|
+
const recent = [];
|
|
291
|
+
let length = 0;
|
|
292
|
+
const said2 = seed.entries.filter((entry) => entry.role !== "tool");
|
|
293
|
+
for (let i = said2.length - 1;i >= 0; i--) {
|
|
294
|
+
const line = `${said2[i].role}: ${said2[i].text.slice(0, 300)}`;
|
|
295
|
+
if (length + line.length > SEED_CHARS) {
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
recent.unshift(line);
|
|
299
|
+
length += line.length + 1;
|
|
300
|
+
}
|
|
301
|
+
if (recent.length) {
|
|
302
|
+
lines.push("Its last lines (look for more):", ...recent);
|
|
303
|
+
}
|
|
304
|
+
lines.push("</called>");
|
|
305
|
+
return lines.join(`
|
|
306
|
+
`);
|
|
307
|
+
}
|
|
308
|
+
CallUtil.seedText = seedText;
|
|
309
|
+
function side(text, from) {
|
|
310
|
+
const about = from ? ` about the conversation "${flat(from).slice(0, 120)}"` : "";
|
|
311
|
+
return `<from_call>Opened from a call with the user${about}, as work apart from it: do it, then say in a few words how it went.</from_call>
|
|
312
|
+
${text}`;
|
|
313
|
+
}
|
|
314
|
+
CallUtil.side = side;
|
|
315
|
+
function sideOfDouble(text, title) {
|
|
316
|
+
const named = title ? ` ("${flat(title).slice(0, 80)}")` : "";
|
|
317
|
+
return `The user asked in a call for this as a task of its own${named}: start it with start_task, then go on.
|
|
318
|
+
${text}`;
|
|
319
|
+
}
|
|
320
|
+
CallUtil.sideOfDouble = sideOfDouble;
|
|
321
|
+
function callOf(role2) {
|
|
322
|
+
const at = role2.indexOf(CALL_MARK);
|
|
323
|
+
return at < 0 ? undefined : role2.slice(at + CALL_MARK.length).trim().split(/\s/)[0] || undefined;
|
|
324
|
+
}
|
|
325
|
+
CallUtil.callOf = callOf;
|
|
326
|
+
function name(language, called) {
|
|
327
|
+
const call = TaLanguageUtil.pick(language, { "zh-CN": "通话", "zh-TW": "通話", "en-US": "Call", "ja-JP": "通話" });
|
|
328
|
+
const other = called ? flat(called).slice(0, 40) : "";
|
|
329
|
+
return other ? `${call} · ${other}` : call;
|
|
330
|
+
}
|
|
331
|
+
CallUtil.name = name;
|
|
332
|
+
function news(lines) {
|
|
333
|
+
return [NEWS, ...lines].join(`
|
|
334
|
+
`);
|
|
335
|
+
}
|
|
336
|
+
CallUtil.news = news;
|
|
337
|
+
function toSay(reply) {
|
|
338
|
+
const said2 = reply?.trim();
|
|
339
|
+
return said2 && said2 !== QUIET && !said2.startsWith(NEWS) ? said2 : undefined;
|
|
340
|
+
}
|
|
341
|
+
CallUtil.toSay = toSay;
|
|
342
|
+
function ended(name2, how) {
|
|
343
|
+
if (how.error) {
|
|
344
|
+
return `${name2} failed: ${how.error.replace(/\s+/g, " ").slice(0, 200)}`;
|
|
345
|
+
}
|
|
346
|
+
if (how.aborted) {
|
|
347
|
+
return `${name2} was stopped.`;
|
|
348
|
+
}
|
|
349
|
+
const last = how.last?.replace(/\s+/g, " ").trim();
|
|
350
|
+
return last ? `${name2} finished. Its last words: ${last.slice(0, 400)}` : `${name2} finished.`;
|
|
351
|
+
}
|
|
352
|
+
CallUtil.ended = ended;
|
|
353
|
+
function waits(name2) {
|
|
354
|
+
return `${name2} waits for the user to decide or confirm, on the screen.`;
|
|
355
|
+
}
|
|
356
|
+
CallUtil.waits = waits;
|
|
357
|
+
function said(text, sent) {
|
|
358
|
+
return sent ? `[sent] ${text}` : text;
|
|
359
|
+
}
|
|
360
|
+
CallUtil.said = said;
|
|
361
|
+
function model(models, chosen, current) {
|
|
362
|
+
if (chosen && models.includes(chosen)) {
|
|
363
|
+
return chosen;
|
|
364
|
+
}
|
|
365
|
+
const provider = current?.split("/")[0];
|
|
366
|
+
const fast = models.filter((model2) => FAST.test(model2.split("/").slice(1).join("/")));
|
|
367
|
+
return fast.find((model2) => model2.split("/")[0] === provider) ?? current;
|
|
368
|
+
}
|
|
369
|
+
CallUtil.model = model;
|
|
370
|
+
function entries(messages) {
|
|
371
|
+
const lines = [];
|
|
372
|
+
for (const raw of messages) {
|
|
373
|
+
const message = raw;
|
|
374
|
+
const parts = typeof message.content === "string" ? [{ type: "text", text: message.content }] : message.content ?? [];
|
|
375
|
+
if (message.role === "user") {
|
|
376
|
+
const text = TaMessageContext.strip(texts(parts)).trim();
|
|
377
|
+
if (text) {
|
|
378
|
+
lines.push({ role: "user", text: short(text) });
|
|
379
|
+
}
|
|
380
|
+
} else if (message.role === "assistant") {
|
|
381
|
+
const text = texts(parts).trim();
|
|
382
|
+
if (text) {
|
|
383
|
+
lines.push({ role: "assistant", text: short(text) });
|
|
384
|
+
}
|
|
385
|
+
for (const call of parts.filter((part) => part.type === "toolCall")) {
|
|
386
|
+
lines.push({ role: "tool", text: short(`${call.name}(${JSON.stringify(call.arguments ?? {})})`) });
|
|
387
|
+
}
|
|
388
|
+
} else if (message.role === "toolResult") {
|
|
389
|
+
const text = texts(parts).trim();
|
|
390
|
+
lines.push({ role: "tool", text: short(`${message.toolName ?? "tool"} → ${text || "(nothing)"}`) });
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return lines;
|
|
394
|
+
}
|
|
395
|
+
CallUtil.entries = entries;
|
|
396
|
+
function look(entries2, question) {
|
|
397
|
+
const words = terms(question);
|
|
398
|
+
let picked;
|
|
399
|
+
if (!words.length) {
|
|
400
|
+
picked = entries2.slice(-LAST_ENTRIES);
|
|
401
|
+
} else {
|
|
402
|
+
const scored = entries2.map((entry, index) => ({ entry, index, score: score(entry.text, words) })).filter((each) => each.score > 0);
|
|
403
|
+
scored.sort((a, b) => b.score - a.score || b.index - a.index);
|
|
404
|
+
picked = scored.slice(0, LAST_ENTRIES).sort((a, b) => a.index - b.index).map((each) => each.entry);
|
|
405
|
+
}
|
|
406
|
+
const lines = [];
|
|
407
|
+
let length = 0;
|
|
408
|
+
for (const entry of picked) {
|
|
409
|
+
const line = `${entry.role}: ${entry.text}`;
|
|
410
|
+
if (length + line.length > LOOK_CHARS) {
|
|
411
|
+
lines.push("…");
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
lines.push(line);
|
|
415
|
+
length += line.length + 1;
|
|
416
|
+
}
|
|
417
|
+
return lines.join(`
|
|
418
|
+
`) || "Nothing about that in the work.";
|
|
419
|
+
}
|
|
420
|
+
CallUtil.look = look;
|
|
421
|
+
function terms(question) {
|
|
422
|
+
const found = new Set;
|
|
423
|
+
for (const word of question.toLowerCase().match(/[a-z0-9_.-]{2,}/g) ?? []) {
|
|
424
|
+
found.add(word);
|
|
425
|
+
}
|
|
426
|
+
for (const run of question.match(/[\u3040-\u30ff\u3400-\u9fff]+/g) ?? []) {
|
|
427
|
+
for (let i = 0;i + 1 < run.length; i++) {
|
|
428
|
+
found.add(run.slice(i, i + 2));
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return [...found];
|
|
432
|
+
}
|
|
433
|
+
CallUtil.terms = terms;
|
|
434
|
+
function score(text, words) {
|
|
435
|
+
const lower = text.toLowerCase();
|
|
436
|
+
return words.filter((word) => lower.includes(word)).length;
|
|
437
|
+
}
|
|
438
|
+
function texts(parts) {
|
|
439
|
+
return parts.filter((part) => part.type === "text" && typeof part.text === "string").map((part) => part.text).join(`
|
|
440
|
+
`);
|
|
441
|
+
}
|
|
442
|
+
function short(text) {
|
|
443
|
+
const line = flat(text);
|
|
444
|
+
return line.length > ENTRY_CHARS ? `${line.slice(0, ENTRY_CHARS)}…` : line;
|
|
445
|
+
}
|
|
446
|
+
function flat(text) {
|
|
447
|
+
return text.replace(/\s+/g, " ").trim();
|
|
448
|
+
}
|
|
449
|
+
})(CallUtil ||= {});
|
|
450
|
+
|
|
451
|
+
// web-src/i18n.ts
|
|
452
|
+
var EN = {
|
|
453
|
+
settings: "Calls",
|
|
454
|
+
model: "Model of calls",
|
|
455
|
+
modelHint: "Who talks with you in a call while the work goes on. A fast one answers at once and costs little; the work keeps its own model.",
|
|
456
|
+
fast: "A fast one of the same provider"
|
|
457
|
+
};
|
|
458
|
+
var ZH = {
|
|
459
|
+
settings: "通话",
|
|
460
|
+
model: "通话用的模型",
|
|
461
|
+
modelHint: "通话时陪你说话的模型,任务照常在后台跑。用快的模型回应更及时、也更省钱;干活仍用对话自己的模型。",
|
|
462
|
+
fast: "同一提供商里快的那个"
|
|
463
|
+
};
|
|
464
|
+
var ZH_TW = {
|
|
465
|
+
settings: "通話",
|
|
466
|
+
model: "通話用的模型",
|
|
467
|
+
modelHint: "通話時陪你說話的模型,任務照常在後台跑。用快的模型回應更及時、也更省錢;幹活仍用對話自己的模型。",
|
|
468
|
+
fast: "同一供應商裡快的那個"
|
|
469
|
+
};
|
|
470
|
+
var JA = {
|
|
471
|
+
settings: "通話",
|
|
472
|
+
model: "通話のモデル",
|
|
473
|
+
modelHint: "通話中に話し相手になるモデルです。作業は裏で続きます。速いモデルなら即座に応え、コストも抑えられます。作業には会話自身のモデルを使います。",
|
|
474
|
+
fast: "同じプロバイダーの速いモデル"
|
|
475
|
+
};
|
|
476
|
+
var WORDS = { "zh-CN": ZH, "zh-TW": ZH_TW, "en-US": EN, "ja-JP": JA };
|
|
477
|
+
var CallWords;
|
|
478
|
+
((CallWords) => {
|
|
479
|
+
function of(language) {
|
|
480
|
+
return TaLanguageUtil.pick(language, WORDS);
|
|
481
|
+
}
|
|
482
|
+
CallWords.of = of;
|
|
483
|
+
})(CallWords ||= {});
|
|
484
|
+
|
|
485
|
+
// web-src/react.ts
|
|
486
|
+
var React;
|
|
487
|
+
function bind(react) {
|
|
488
|
+
React = react;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
// web-src/index.tsx
|
|
492
|
+
var MODEL = "model";
|
|
493
|
+
function activate(pi) {
|
|
494
|
+
bind(pi.React);
|
|
495
|
+
if (!pi.registerCallPartner) {
|
|
496
|
+
return () => {
|
|
497
|
+
return;
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
pi.registerCallPartner({
|
|
501
|
+
open: async (target) => {
|
|
502
|
+
const model = await modelFor(pi, target.cwd);
|
|
503
|
+
const { callId } = await pi.callHost("open", target, model);
|
|
504
|
+
return {
|
|
505
|
+
say: (text, options) => pi.callHost("say", callId, text, options?.sent === true),
|
|
506
|
+
next: () => pi.callHost("next", callId),
|
|
507
|
+
close: () => void pi.callHost("close", callId).catch(() => {
|
|
508
|
+
return;
|
|
509
|
+
})
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
const words = () => CallWords.of(pi.ui.language);
|
|
514
|
+
pi.registerChatIcon?.({ icon: (chat) => chat.group === NAME ? { icon: pi.ui.icons.Phone, folder: words().settings } : undefined });
|
|
515
|
+
pi.registerSettings({
|
|
516
|
+
title: () => words().settings,
|
|
517
|
+
icon: pi.ui.icons.Phone,
|
|
518
|
+
group: "ta",
|
|
519
|
+
rows: [{ key: "model", label: () => words().model, description: () => words().modelHint, stacked: true, render: () => /* @__PURE__ */ React.createElement(ModelRow, {
|
|
520
|
+
pi
|
|
521
|
+
}) }]
|
|
522
|
+
});
|
|
523
|
+
return () => {
|
|
524
|
+
return;
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
async function modelFor(pi, cwd) {
|
|
528
|
+
const [chosen, settings] = await Promise.all([pi.storage.get(MODEL), pi.settings.getSettings(cwd).catch(() => {
|
|
529
|
+
return;
|
|
530
|
+
})]);
|
|
531
|
+
const current = settings?.project.model ?? settings?.user.model;
|
|
532
|
+
return CallUtil.model(settings?.models ?? [], chosen ?? "", current);
|
|
533
|
+
}
|
|
534
|
+
function ModelRow({ pi }) {
|
|
535
|
+
const [value, setValue] = React.useState("");
|
|
536
|
+
React.useEffect(() => {
|
|
537
|
+
pi.storage.get(MODEL).then((chosen) => setValue(chosen ?? ""));
|
|
538
|
+
}, [pi]);
|
|
539
|
+
const { ModelPicker } = pi.ui;
|
|
540
|
+
return /* @__PURE__ */ React.createElement(ModelPicker, {
|
|
541
|
+
value,
|
|
542
|
+
defaultLabel: CallWords.of(pi.ui.language).fast,
|
|
543
|
+
label: CallWords.of(pi.ui.language).model,
|
|
544
|
+
onChange: (next) => {
|
|
545
|
+
setValue(next);
|
|
546
|
+
pi.storage.set(MODEL, next || null);
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
export {
|
|
551
|
+
activate as default
|
|
552
|
+
};
|