@celljs/ta-channels 4.35.0 → 4.36.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/extension/index.mjs +399 -3
- package/host/index.mjs +495 -10
- package/package.json +5 -4
- package/web/index.js +402 -2
package/extension/index.mjs
CHANGED
|
@@ -1,3 +1,398 @@
|
|
|
1
|
+
// ../../packages/core/esm/common/utils/error-util.js
|
|
2
|
+
class ErrorUtil {
|
|
3
|
+
static fixProto(target, prototype) {
|
|
4
|
+
const setPrototypeOf = Object.setPrototypeOf;
|
|
5
|
+
if (setPrototypeOf) {
|
|
6
|
+
setPrototypeOf(target, prototype);
|
|
7
|
+
} else {
|
|
8
|
+
target.__proto__ = prototype;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
static fixStack(target, fn = target.constructor) {
|
|
12
|
+
const captureStackTrace = Error.captureStackTrace;
|
|
13
|
+
if (captureStackTrace) {
|
|
14
|
+
captureStackTrace(target, fn);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
static describe(error) {
|
|
18
|
+
let text = ErrorUtil.describeOne(error);
|
|
19
|
+
let cause = ErrorUtil.causeOf(error);
|
|
20
|
+
for (let depth = 0;cause !== undefined && depth < 5; depth++) {
|
|
21
|
+
text += `
|
|
22
|
+
Caused by: ${ErrorUtil.describeOne(cause)}`;
|
|
23
|
+
cause = ErrorUtil.causeOf(cause);
|
|
24
|
+
}
|
|
25
|
+
return text;
|
|
26
|
+
}
|
|
27
|
+
static causeOf(error) {
|
|
28
|
+
return error instanceof Error ? error.cause : undefined;
|
|
29
|
+
}
|
|
30
|
+
static describeOne(error) {
|
|
31
|
+
var _a;
|
|
32
|
+
if (error instanceof Error) {
|
|
33
|
+
return (_a = error.stack) !== null && _a !== undefined ? _a : `${error.name}: ${error.message}`;
|
|
34
|
+
}
|
|
35
|
+
return String(error);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ../../packages/core/esm/common/utils/event.js
|
|
40
|
+
var Event;
|
|
41
|
+
(function(Event2) {
|
|
42
|
+
const _disposable = { dispose() {} };
|
|
43
|
+
Event2.None = Object.assign(function() {
|
|
44
|
+
return _disposable;
|
|
45
|
+
}, {
|
|
46
|
+
get maxListeners() {
|
|
47
|
+
return 0;
|
|
48
|
+
},
|
|
49
|
+
set maxListeners(maxListeners) {}
|
|
50
|
+
});
|
|
51
|
+
function map(event, mapFunc) {
|
|
52
|
+
return Object.assign((listener, thisArgs, disposables) => event((i) => listener.call(thisArgs, mapFunc(i)), undefined, disposables), {
|
|
53
|
+
maxListeners: 0
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
Event2.map = map;
|
|
57
|
+
})(Event || (Event = {}));
|
|
58
|
+
|
|
59
|
+
class CallbackList {
|
|
60
|
+
get length() {
|
|
61
|
+
return this._callbacks && this._callbacks.length || 0;
|
|
62
|
+
}
|
|
63
|
+
add(callback, context = undefined, bucket) {
|
|
64
|
+
if (!this._callbacks) {
|
|
65
|
+
this._callbacks = [];
|
|
66
|
+
this._contexts = [];
|
|
67
|
+
}
|
|
68
|
+
this._callbacks.push(callback);
|
|
69
|
+
this._contexts.push(context);
|
|
70
|
+
if (Array.isArray(bucket)) {
|
|
71
|
+
bucket.push({ dispose: () => this.remove(callback, context) });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
remove(callback, context = undefined) {
|
|
75
|
+
if (!this._callbacks) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
let foundCallbackWithDifferentContext = false;
|
|
79
|
+
for (let i = 0;i < this._callbacks.length; i++) {
|
|
80
|
+
if (this._callbacks[i] === callback) {
|
|
81
|
+
if (this._contexts[i] === context) {
|
|
82
|
+
this._callbacks.splice(i, 1);
|
|
83
|
+
this._contexts.splice(i, 1);
|
|
84
|
+
return;
|
|
85
|
+
} else {
|
|
86
|
+
foundCallbackWithDifferentContext = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (foundCallbackWithDifferentContext) {
|
|
91
|
+
throw new Error("When adding a listener with a context, you should remove it with the same context");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
*[Symbol.iterator]() {
|
|
95
|
+
if (!this._callbacks) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const callbacks = this._callbacks.slice(0);
|
|
99
|
+
const contexts = this._contexts.slice(0);
|
|
100
|
+
for (let i = 0;i < callbacks.length; i++) {
|
|
101
|
+
const callback = callbacks[i];
|
|
102
|
+
const context = contexts[i];
|
|
103
|
+
yield (...args) => callback.apply(context, args);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
invoke(...args) {
|
|
107
|
+
if (!this._callbacks) {
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
const callbacks = this._callbacks.slice(0);
|
|
111
|
+
const contexts = this._contexts.slice(0);
|
|
112
|
+
const ret = [];
|
|
113
|
+
for (let i = 0;i < callbacks.length; i++) {
|
|
114
|
+
try {
|
|
115
|
+
ret.push(callbacks[i].apply(contexts[i], args));
|
|
116
|
+
} catch (e) {
|
|
117
|
+
console.error(e);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return ret;
|
|
121
|
+
}
|
|
122
|
+
isEmpty() {
|
|
123
|
+
return !this._callbacks || this._callbacks.length === 0;
|
|
124
|
+
}
|
|
125
|
+
dispose() {
|
|
126
|
+
this._callbacks = undefined;
|
|
127
|
+
this._contexts = undefined;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ../../packages/core/esm/common/utils/emitter.js
|
|
132
|
+
class Emitter {
|
|
133
|
+
constructor(_options) {
|
|
134
|
+
this._options = _options;
|
|
135
|
+
this._disposed = false;
|
|
136
|
+
this._leakWarnCountdown = 0;
|
|
137
|
+
}
|
|
138
|
+
get event() {
|
|
139
|
+
if (!this._event) {
|
|
140
|
+
this._event = Object.assign((listener, thisArgs, disposables) => {
|
|
141
|
+
if (!this._callbacks) {
|
|
142
|
+
this._callbacks = new CallbackList;
|
|
143
|
+
}
|
|
144
|
+
if (this._options && this._options.onFirstListenerAdd && this._callbacks.isEmpty()) {
|
|
145
|
+
this._options.onFirstListenerAdd(this);
|
|
146
|
+
}
|
|
147
|
+
this._callbacks.add(listener, thisArgs);
|
|
148
|
+
const removeMaxListenersCheck = this.checkMaxListeners(this._event.maxListeners);
|
|
149
|
+
const result = {
|
|
150
|
+
dispose: () => {
|
|
151
|
+
if (removeMaxListenersCheck) {
|
|
152
|
+
removeMaxListenersCheck();
|
|
153
|
+
}
|
|
154
|
+
result.dispose = Emitter._noop;
|
|
155
|
+
if (!this._disposed) {
|
|
156
|
+
this._callbacks.remove(listener, thisArgs);
|
|
157
|
+
result.dispose = Emitter._noop;
|
|
158
|
+
if (this._options && this._options.onLastListenerRemove && this._callbacks.isEmpty()) {
|
|
159
|
+
this._options.onLastListenerRemove(this);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
if (Array.isArray(disposables)) {
|
|
165
|
+
disposables.push(result);
|
|
166
|
+
}
|
|
167
|
+
return result;
|
|
168
|
+
}, {
|
|
169
|
+
maxListeners: Emitter.LEAK_WARNING_THRESHHOLD
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return this._event;
|
|
173
|
+
}
|
|
174
|
+
checkMaxListeners(maxListeners) {
|
|
175
|
+
if (maxListeners === 0 || !this._callbacks) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const listenerCount = this._callbacks.length;
|
|
179
|
+
if (listenerCount <= maxListeners) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const popStack = this.pushLeakingStack();
|
|
183
|
+
this._leakWarnCountdown -= 1;
|
|
184
|
+
if (this._leakWarnCountdown <= 0) {
|
|
185
|
+
this._leakWarnCountdown = maxListeners * 0.5;
|
|
186
|
+
let topStack;
|
|
187
|
+
let topCount = 0;
|
|
188
|
+
this._leakingStacks.forEach((stackCount, stack) => {
|
|
189
|
+
if (!topStack || topCount < stackCount) {
|
|
190
|
+
topStack = stack;
|
|
191
|
+
topCount = stackCount;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
console.warn(`Possible Emitter memory leak detected. ${listenerCount} listeners added. Use event.maxListeners to increase the limit (${maxListeners}). MOST frequent listener (${topCount}):`);
|
|
195
|
+
console.warn(topStack);
|
|
196
|
+
}
|
|
197
|
+
return popStack;
|
|
198
|
+
}
|
|
199
|
+
pushLeakingStack() {
|
|
200
|
+
if (!this._leakingStacks) {
|
|
201
|
+
this._leakingStacks = new Map;
|
|
202
|
+
}
|
|
203
|
+
const stack = new Error().stack.split(`
|
|
204
|
+
`).slice(3).join(`
|
|
205
|
+
`);
|
|
206
|
+
const count = this._leakingStacks.get(stack) || 0;
|
|
207
|
+
this._leakingStacks.set(stack, count + 1);
|
|
208
|
+
return () => this.popLeakingStack(stack);
|
|
209
|
+
}
|
|
210
|
+
popLeakingStack(stack) {
|
|
211
|
+
if (!this._leakingStacks) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const count = this._leakingStacks.get(stack) || 0;
|
|
215
|
+
this._leakingStacks.set(stack, count - 1);
|
|
216
|
+
}
|
|
217
|
+
get hasListeners() {
|
|
218
|
+
return !!this._callbacks && !this._callbacks.isEmpty();
|
|
219
|
+
}
|
|
220
|
+
fire(event) {
|
|
221
|
+
if (this._callbacks) {
|
|
222
|
+
this._callbacks.invoke(event);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async sequence(processor) {
|
|
226
|
+
if (this._callbacks) {
|
|
227
|
+
for (const listener of this._callbacks) {
|
|
228
|
+
if (!await processor(listener)) {
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
dispose() {
|
|
235
|
+
if (this._leakingStacks) {
|
|
236
|
+
this._leakingStacks.clear();
|
|
237
|
+
this._leakingStacks = undefined;
|
|
238
|
+
}
|
|
239
|
+
if (this._callbacks) {
|
|
240
|
+
this._callbacks.dispose();
|
|
241
|
+
this._callbacks = undefined;
|
|
242
|
+
}
|
|
243
|
+
this._disposed = true;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
Emitter.LEAK_WARNING_THRESHHOLD = 175;
|
|
247
|
+
Emitter._noop = function() {};
|
|
248
|
+
var WaitUntilEvent;
|
|
249
|
+
(function(WaitUntilEvent2) {
|
|
250
|
+
async function fire(emitter, event, timeout = undefined) {
|
|
251
|
+
const waitables = [];
|
|
252
|
+
const asyncEvent = Object.assign(event, {
|
|
253
|
+
waitUntil: (thenable) => {
|
|
254
|
+
if (Object.isFrozen(waitables)) {
|
|
255
|
+
throw new Error("waitUntil cannot be called asynchronously.");
|
|
256
|
+
}
|
|
257
|
+
waitables.push(thenable);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
try {
|
|
261
|
+
emitter.fire(asyncEvent);
|
|
262
|
+
Object.freeze(waitables);
|
|
263
|
+
} finally {
|
|
264
|
+
delete asyncEvent.waitUntil;
|
|
265
|
+
}
|
|
266
|
+
if (!waitables.length) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
if (timeout !== undefined) {
|
|
270
|
+
await Promise.race([Promise.all(waitables), new Promise((resolve) => setTimeout(resolve, timeout))]);
|
|
271
|
+
} else {
|
|
272
|
+
await Promise.all(waitables);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
WaitUntilEvent2.fire = fire;
|
|
276
|
+
})(WaitUntilEvent || (WaitUntilEvent = {}));
|
|
277
|
+
|
|
278
|
+
// ../../packages/core/esm/common/logger/logger-protocol.js
|
|
279
|
+
var LOGGER_CONFIG = "logger";
|
|
280
|
+
var LOGGER_LEVEL = `${LOGGER_CONFIG}.level`;
|
|
281
|
+
var Logger = Symbol("Logger");
|
|
282
|
+
var TraceIdProvider = Symbol("TraceIdProvider");
|
|
283
|
+
var LoggerService = Symbol("LoggerService");
|
|
284
|
+
var LOG_LEVELS = ["verbose", "debug", "info", "warn", "error"];
|
|
285
|
+
var onLogEmitter = new Emitter;
|
|
286
|
+
|
|
287
|
+
// ../../packages/core/esm/common/logger/console-logger.js
|
|
288
|
+
var RANK = Object.fromEntries(LOG_LEVELS.map((level, index) => [level, index]));
|
|
289
|
+
var write = {
|
|
290
|
+
error: (text) => console.error(text),
|
|
291
|
+
warn: (text) => console.warn(text),
|
|
292
|
+
info: (text) => console.info(text),
|
|
293
|
+
debug: (text) => console.debug(text)
|
|
294
|
+
};
|
|
295
|
+
var LEVEL = Symbol.for("@celljs/core/logger/level");
|
|
296
|
+
var Loggers;
|
|
297
|
+
(function(Loggers2) {
|
|
298
|
+
function get(context) {
|
|
299
|
+
return new ConsoleLogger(context);
|
|
300
|
+
}
|
|
301
|
+
Loggers2.get = get;
|
|
302
|
+
function level() {
|
|
303
|
+
var _a;
|
|
304
|
+
const set = globalThis[LEVEL];
|
|
305
|
+
if (set) {
|
|
306
|
+
return set;
|
|
307
|
+
}
|
|
308
|
+
const env = typeof process === "undefined" ? undefined : (_a = process.env) === null || _a === undefined ? undefined : _a.CELL_LOGGER__LEVEL;
|
|
309
|
+
return env && env in RANK ? env : "info";
|
|
310
|
+
}
|
|
311
|
+
Loggers2.level = level;
|
|
312
|
+
function setLevel(level2) {
|
|
313
|
+
globalThis[LEVEL] = level2 && level2 in RANK ? level2 : undefined;
|
|
314
|
+
}
|
|
315
|
+
Loggers2.setLevel = setLevel;
|
|
316
|
+
})(Loggers || (Loggers = {}));
|
|
317
|
+
|
|
318
|
+
class ConsoleLogger {
|
|
319
|
+
constructor(context) {
|
|
320
|
+
this.context = context;
|
|
321
|
+
}
|
|
322
|
+
setContext(context) {
|
|
323
|
+
this.context = context;
|
|
324
|
+
}
|
|
325
|
+
isEnabled(level) {
|
|
326
|
+
var _a, _b;
|
|
327
|
+
return RANK[level] >= ((_b = RANK[(_a = this.level) !== null && _a !== undefined ? _a : Loggers.level()]) !== null && _b !== undefined ? _b : RANK.info);
|
|
328
|
+
}
|
|
329
|
+
error(message, context) {
|
|
330
|
+
this.log(message, context, write.error, "error");
|
|
331
|
+
}
|
|
332
|
+
warn(message, context) {
|
|
333
|
+
if (this.isEnabled("warn")) {
|
|
334
|
+
this.log(message, context, write.warn, "warn");
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
info(message, context) {
|
|
338
|
+
if (this.isEnabled("info")) {
|
|
339
|
+
this.log(message, context, write.info, "info");
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
debug(message, context) {
|
|
343
|
+
if (this.isEnabled("debug")) {
|
|
344
|
+
this.log(message, context, write.debug, "debug");
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
time(label) {
|
|
348
|
+
var _a;
|
|
349
|
+
((_a = this.timeRecords) !== null && _a !== undefined ? _a : this.timeRecords = new Map).set(label, Date.now());
|
|
350
|
+
}
|
|
351
|
+
timeEnd(label, context) {
|
|
352
|
+
var _a;
|
|
353
|
+
const start = (_a = this.timeRecords) === null || _a === undefined ? undefined : _a.get(label);
|
|
354
|
+
if (start !== undefined) {
|
|
355
|
+
const duration = Date.now() - start;
|
|
356
|
+
this.timeRecords.delete(label);
|
|
357
|
+
this.log(`${label} [${duration}ms]`, context);
|
|
358
|
+
return duration;
|
|
359
|
+
} else {
|
|
360
|
+
this.log(`No such label: ${label} for timeEnd`, context);
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
resolveContextString(context) {
|
|
365
|
+
if (this.context) {
|
|
366
|
+
return context ? `[${this.context}] [${context}] ` : `[${this.context}] `;
|
|
367
|
+
}
|
|
368
|
+
return context ? `[${context}] ` : "";
|
|
369
|
+
}
|
|
370
|
+
resolvePrefix(level) {
|
|
371
|
+
const time = new Date().toISOString();
|
|
372
|
+
return `${time} [${level}]`;
|
|
373
|
+
}
|
|
374
|
+
log(message, context, logFn = write.info, level = "info") {
|
|
375
|
+
var _a;
|
|
376
|
+
const traceId = (_a = this.traceIdProvider) === null || _a === undefined ? undefined : _a.provide();
|
|
377
|
+
const contextStr = this.resolveContextString(context);
|
|
378
|
+
const text = message instanceof Error ? ErrorUtil.describe(message) : message;
|
|
379
|
+
let head = this.resolvePrefix(level);
|
|
380
|
+
if (traceId) {
|
|
381
|
+
head = head ? `${head} [trace: ${traceId}]` : `[trace: ${traceId}]`;
|
|
382
|
+
}
|
|
383
|
+
logFn(`${head ? `${head} ` : ""}${contextStr}${text}`);
|
|
384
|
+
if (onLogEmitter.hasListeners) {
|
|
385
|
+
onLogEmitter.fire({
|
|
386
|
+
level,
|
|
387
|
+
traceId,
|
|
388
|
+
rootContext: this.context,
|
|
389
|
+
context,
|
|
390
|
+
message
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
1
396
|
// ../ta-protocol/esm/common/ta-extension-host.js
|
|
2
397
|
var TA_WEBHOOK_MAX_BYTES = 256 * 1024;
|
|
3
398
|
var TA_HOST_EVENT = "ta:host";
|
|
@@ -1099,7 +1494,7 @@ var TaTaskNote;
|
|
|
1099
1494
|
(function(TaTaskNote2) {
|
|
1100
1495
|
const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
|
|
1101
1496
|
const ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
1102
|
-
function
|
|
1497
|
+
function write2(note) {
|
|
1103
1498
|
const attributes = [`id="${quote(note.id)}"`];
|
|
1104
1499
|
if (note.was !== undefined) {
|
|
1105
1500
|
attributes.push(`was="${quote(note.was)}"`);
|
|
@@ -1112,7 +1507,7 @@ var TaTaskNote;
|
|
|
1112
1507
|
${note.body}
|
|
1113
1508
|
</task_${note.kind}>`;
|
|
1114
1509
|
}
|
|
1115
|
-
TaTaskNote2.write =
|
|
1510
|
+
TaTaskNote2.write = write2;
|
|
1116
1511
|
function parse(text) {
|
|
1117
1512
|
const match = NOTE.exec(text.trim());
|
|
1118
1513
|
if (!match) {
|
|
@@ -1920,6 +2315,7 @@ var TeamTools;
|
|
|
1920
2315
|
})(TeamTools ||= {});
|
|
1921
2316
|
|
|
1922
2317
|
// web-src/extension.ts
|
|
2318
|
+
var logger = Loggers.get("ta-channels");
|
|
1923
2319
|
var NO_SERVER = "The team tools need the Ta service, which runs the agents: start it with `ta serve` and talk to Ta in its web page. In Ta in a terminal there are no agents or channels.";
|
|
1924
2320
|
var NO_TEAM = "The team did not start in the Ta service; its log says why.";
|
|
1925
2321
|
var NOT_FOR_AGENTS = "Agents do not build teams or post to channels: answer in your reply, and name a member with @ to hand on.";
|
|
@@ -2016,7 +2412,7 @@ function activate(pi) {
|
|
|
2016
2412
|
cards.push({ target: await (await team()).handOff(to, brief, ctx.sessionManager.getSessionFile()), brief });
|
|
2017
2413
|
}
|
|
2018
2414
|
} catch (error) {
|
|
2019
|
-
|
|
2415
|
+
logger.error(`could not hand the work over: ${ErrorUtil.describe(error)}`);
|
|
2020
2416
|
}
|
|
2021
2417
|
for (const card of cards.splice(0)) {
|
|
2022
2418
|
pi.sendMessage({ customType: HandOff.CARD, content: HandOff.ref(card.target), display: true, details: card }, { triggerTurn: false });
|