@celljs/ta-channels 4.34.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/host/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/language.js
2
397
  var TaLanguageUtil;
3
398
  (function(TaLanguageUtil2) {
@@ -267,7 +662,7 @@ var TaTaskNote;
267
662
  (function(TaTaskNote2) {
268
663
  const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
269
664
  const ATTRIBUTE = /(\w+)="([^"]*)"/g;
270
- function write(note) {
665
+ function write2(note) {
271
666
  const attributes = [`id="${quote(note.id)}"`];
272
667
  if (note.was !== undefined) {
273
668
  attributes.push(`was="${quote(note.was)}"`);
@@ -280,7 +675,7 @@ var TaTaskNote;
280
675
  ${note.body}
281
676
  </task_${note.kind}>`;
282
677
  }
283
- TaTaskNote2.write = write;
678
+ TaTaskNote2.write = write2;
284
679
  function parse(text) {
285
680
  const match = NOTE.exec(text.trim());
286
681
  if (!match) {
@@ -1082,8 +1477,9 @@ var ChannelsUtil;
1082
1477
  }
1083
1478
  ChannelsUtil.updateChannel = updateChannel;
1084
1479
  function standing(team) {
1085
- const inChannel = new Set(team.channels.flatMap((channel) => channel.members));
1086
- return team.agents.filter((agent) => !agent.temporary || !inChannel.has(agent.id));
1480
+ const inTeams = new Set(taskChannels(team).flatMap((channel) => channel.members));
1481
+ const inOwn = new Set(team.channels.filter((channel) => channel.by !== "ta").flatMap((channel) => channel.members));
1482
+ return team.agents.filter((agent) => !agent.temporary || !inTeams.has(agent.id) || inOwn.has(agent.id));
1087
1483
  }
1088
1484
  ChannelsUtil.standing = standing;
1089
1485
  function taskChannels(team) {
@@ -2146,47 +2542,6 @@ var TaDoubleLookUtil;
2146
2542
  TaDoubleLookUtil2.given = given;
2147
2543
  })(TaDoubleLookUtil || (TaDoubleLookUtil = {}));
2148
2544
  var TA_WITH_OTHERS_MARK = "[ta:speaks-with-others]";
2149
- var TA_ASK_ENTRY = "ta-ask";
2150
- var TaAskUtil;
2151
- (function(TaAskUtil2) {
2152
- const LENGTH = 120;
2153
- function entry(question) {
2154
- const line = question.replace(/\s+/g, " ").trim();
2155
- return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
2156
- }
2157
- TaAskUtil2.entry = entry;
2158
- function asking(entries) {
2159
- var _a;
2160
- for (let i = entries.length - 1;i >= 0; i--) {
2161
- const entry2 = entries[i];
2162
- if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
2163
- return;
2164
- }
2165
- if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
2166
- return read(entry2);
2167
- }
2168
- }
2169
- return;
2170
- }
2171
- TaAskUtil2.asking = asking;
2172
- function next(asked, entry2) {
2173
- var _a;
2174
- if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
2175
- return;
2176
- }
2177
- return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
2178
- }
2179
- TaAskUtil2.next = next;
2180
- function read(found) {
2181
- var _a;
2182
- const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
2183
- if (typeof question !== "string" || !question.trim()) {
2184
- return;
2185
- }
2186
- const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
2187
- return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
2188
- }
2189
- })(TaAskUtil || (TaAskUtil = {}));
2190
2545
 
2191
2546
  // ../ta-protocol/esm/common/delegate-protocol.js
2192
2547
  var TaDelegateUtil;
@@ -2431,6 +2786,48 @@ var TaAppUtil;
2431
2786
  }
2432
2787
  TaAppUtil2.shown = shown;
2433
2788
  })(TaAppUtil || (TaAppUtil = {}));
2789
+ // ../ta-protocol/esm/common/ask-protocol.js
2790
+ var TA_ASK_ENTRY = "ta-ask";
2791
+ var TaAskUtil;
2792
+ (function(TaAskUtil2) {
2793
+ const LENGTH = 120;
2794
+ function entry(question) {
2795
+ const line = question.replace(/\s+/g, " ").trim();
2796
+ return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
2797
+ }
2798
+ TaAskUtil2.entry = entry;
2799
+ function asking(entries) {
2800
+ var _a;
2801
+ for (let i = entries.length - 1;i >= 0; i--) {
2802
+ const entry2 = entries[i];
2803
+ if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
2804
+ return;
2805
+ }
2806
+ if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
2807
+ return read(entry2);
2808
+ }
2809
+ }
2810
+ return;
2811
+ }
2812
+ TaAskUtil2.asking = asking;
2813
+ function next(asked, entry2) {
2814
+ var _a;
2815
+ if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
2816
+ return;
2817
+ }
2818
+ return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
2819
+ }
2820
+ TaAskUtil2.next = next;
2821
+ function read(found) {
2822
+ var _a;
2823
+ const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
2824
+ if (typeof question !== "string" || !question.trim()) {
2825
+ return;
2826
+ }
2827
+ const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
2828
+ return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
2829
+ }
2830
+ })(TaAskUtil || (TaAskUtil = {}));
2434
2831
  // ../ta-protocol/esm/common/auth-protocol.js
2435
2832
  var TaAuthServer = Symbol("TaAuthServer");
2436
2833
  // ../ta-protocol/esm/common/boundary-protocol.js
@@ -2964,6 +3361,7 @@ var TaErrorCode = {
2964
3361
  RATE_LIMITED: "CELL_TA_RATE_LIMITED",
2965
3362
  FORBIDDEN: "CELL_TA_FORBIDDEN",
2966
3363
  LIMIT: "CELL_TA_LIMIT",
3364
+ DEVICE_NOT_WAITING: "CELL_TA_DEVICE_NOT_WAITING",
2967
3365
  CONNECTION_LOST: "CELL_TA_CONNECTION_LOST"
2968
3366
  };
2969
3367
  var TaErrorUtil;
@@ -3279,6 +3677,52 @@ var TaLocation;
3279
3677
  return squeezed.length > 1 ? squeezed.replace(/\/$/, "") : squeezed;
3280
3678
  }
3281
3679
  })(TaLocation || (TaLocation = {}));
3680
+ // ../ta-protocol/esm/common/storage-protocol.js
3681
+ var TaStorageUtil;
3682
+ (function(TaStorageUtil2) {
3683
+ TaStorageUtil2.DAYS = [7, 30, 90, 180, 365, 0];
3684
+ TaStorageUtil2.MB = [100, 500, 1024, 2048, 5120, 0];
3685
+ TaStorageUtil2.KEY = "storage";
3686
+ function id(owner, name) {
3687
+ return `${owner}/${name}`;
3688
+ }
3689
+ TaStorageUtil2.id = id;
3690
+ function set(ta, id2, kinds) {
3691
+ const all = ta && typeof ta === "object" ? ta[TaStorageUtil2.KEY] : undefined;
3692
+ const mine = all && typeof all === "object" ? all[id2] : undefined;
3693
+ return check(mine, kinds);
3694
+ }
3695
+ TaStorageUtil2.set = set;
3696
+ function check(given, kinds) {
3697
+ const out = {};
3698
+ const value = given && typeof given === "object" ? given : {};
3699
+ for (const kind of ["keepDays", "maxMB"]) {
3700
+ const n = Number(value[kind]);
3701
+ if (kinds[kind] !== undefined && value[kind] !== undefined && value[kind] !== null && Number.isFinite(n) && n >= 0) {
3702
+ out[kind] = Math.floor(n);
3703
+ }
3704
+ }
3705
+ return out;
3706
+ }
3707
+ TaStorageUtil2.check = check;
3708
+ function limits(defaults = {}, set2 = {}) {
3709
+ return { ...defaults, ...set2 };
3710
+ }
3711
+ TaStorageUtil2.limits = limits;
3712
+ function retention(limits2) {
3713
+ return {
3714
+ keepDays: limits2.keepDays ? limits2.keepDays : undefined,
3715
+ maxBytes: limits2.maxMB ? limits2.maxMB * 1024 * 1024 : undefined
3716
+ };
3717
+ }
3718
+ TaStorageUtil2.retention = retention;
3719
+ function choices(list, value) {
3720
+ const all = value === undefined || list.includes(value) ? [...list] : [...list, value];
3721
+ return all.sort((a, b) => a === 0 ? 1 : b === 0 ? -1 : a - b);
3722
+ }
3723
+ TaStorageUtil2.choices = choices;
3724
+ })(TaStorageUtil || (TaStorageUtil = {}));
3725
+
3282
3726
  // ../ta-protocol/esm/common/metrics-protocol.js
3283
3727
  var TA_METRICS_BOUNDS = [10, 50, 200, 1000, 5000, 30000];
3284
3728
  var NOT_RUNS = new Set(["turn", "section", "tooldef"]);
@@ -3288,10 +3732,13 @@ var TaMetricsUtil;
3288
3732
  TaMetricsUtil2.KEEP_DAYS = 90;
3289
3733
  TaMetricsUtil2.MAX_DAYS = 365;
3290
3734
  TaMetricsUtil2.MAX_MB = 20;
3735
+ TaMetricsUtil2.STORAGE_ID = "ta/metrics";
3291
3736
  function limits(ta) {
3292
- const set = ta && typeof ta === "object" ? ta : {};
3293
- const days = Number(set.metricsKeepDays);
3294
- const mb = Number(set.metricsMaxMB);
3737
+ var _a, _b;
3738
+ const before = ta && typeof ta === "object" ? ta : {};
3739
+ const set = TaStorageUtil.set(ta, TaMetricsUtil2.STORAGE_ID, { keepDays: TaMetricsUtil2.KEEP_DAYS, maxMB: TaMetricsUtil2.MAX_MB });
3740
+ const days = set.keepDays === 0 ? TaMetricsUtil2.MAX_DAYS : Number((_a = set.keepDays) !== null && _a !== undefined ? _a : before.metricsKeepDays);
3741
+ const mb = set.maxMB === 0 ? 1024 : Number((_b = set.maxMB) !== null && _b !== undefined ? _b : before.metricsMaxMB);
3295
3742
  return {
3296
3743
  keepDays: Number.isFinite(days) && days >= 1 ? Math.min(TaMetricsUtil2.MAX_DAYS, Math.floor(days)) : TaMetricsUtil2.KEEP_DAYS,
3297
3744
  maxBytes: Math.round((Number.isFinite(mb) && mb > 0 ? Math.min(1024, Math.max(1, mb)) : TaMetricsUtil2.MAX_MB) * 1024 * 1024)
@@ -3442,6 +3889,19 @@ var TaMetricsUtil;
3442
3889
  })(TaMetricsUtil || (TaMetricsUtil = {}));
3443
3890
  // ../ta-protocol/esm/common/package-protocol.js
3444
3891
  var TaPackageServer = Symbol("TaPackageServer");
3892
+ var TaExtensionAccessUtil;
3893
+ (function(TaExtensionAccessUtil2) {
3894
+ TaExtensionAccessUtil2.LEVELS = ["browser", "app", "full"];
3895
+ function reaches(granted, needed) {
3896
+ return TaExtensionAccessUtil2.LEVELS.indexOf(granted) >= TaExtensionAccessUtil2.LEVELS.indexOf(needed);
3897
+ }
3898
+ TaExtensionAccessUtil2.reaches = reaches;
3899
+ function parse(value) {
3900
+ return TaExtensionAccessUtil2.LEVELS.includes(value) ? value : "full";
3901
+ }
3902
+ TaExtensionAccessUtil2.parse = parse;
3903
+ TaExtensionAccessUtil2.TRUSTS = ["off", "browser", "ask", "all"];
3904
+ })(TaExtensionAccessUtil || (TaExtensionAccessUtil = {}));
3445
3905
  var TaPackageTextUtil;
3446
3906
  (function(TaPackageTextUtil2) {
3447
3907
  function pick(text, language) {
@@ -3600,6 +4060,31 @@ ${line}`, TaMessageContext.strip(plain));
3600
4060
  var TaRelayServer = Symbol("TaRelayServer");
3601
4061
  // ../ta-protocol/esm/common/remote-protocol.js
3602
4062
  var TaRemoteServer = Symbol("TaRemoteServer");
4063
+ // ../ta-protocol/esm/common/request-error-protocol.js
4064
+ var TaRequestErrorUtil;
4065
+ (function(TaRequestErrorUtil2) {
4066
+ function reason(errorMessage) {
4067
+ const message = errorMessage !== null && errorMessage !== undefined ? errorMessage : "";
4068
+ if (/\b429\b|rate.?limit|too many requests|quota|usage limit/i.test(message)) {
4069
+ return "rateLimit";
4070
+ }
4071
+ if (/overload|\b529\b|\b503\b|capacity|unavailable/i.test(message)) {
4072
+ return "overloaded";
4073
+ }
4074
+ if (/fetch failed|network|socket|ECONN|ETIMEDOUT|ENOTFOUND|EAI_AGAIN|ENETUNREACH|EHOSTUNREACH|timed? ?out|terminated/i.test(message)) {
4075
+ return "network";
4076
+ }
4077
+ return "error";
4078
+ }
4079
+ TaRequestErrorUtil2.reason = reason;
4080
+ function host(errorMessage) {
4081
+ var _a;
4082
+ const message = errorMessage !== null && errorMessage !== undefined ? errorMessage : "";
4083
+ const named = (_a = /\b(?:ENOTFOUND|EAI_AGAIN)\s+([a-z0-9.-]+\.[a-z]{2,})/i.exec(message)) !== null && _a !== undefined ? _a : /https?:\/\/([a-z0-9.-]+\.[a-z]{2,})/i.exec(message);
4084
+ return named === null || named === undefined ? undefined : named[1].toLowerCase();
4085
+ }
4086
+ TaRequestErrorUtil2.host = host;
4087
+ })(TaRequestErrorUtil || (TaRequestErrorUtil = {}));
3603
4088
  // ../ta-protocol/esm/common/room-protocol.js
3604
4089
  var TaRoomServer = Symbol("TaRoomServer");
3605
4090
  var TA_PICTURE = { key: "picture:", maxChars: 16 * 1024 };
@@ -3736,6 +4221,7 @@ var TA_SETTINGS = [
3736
4221
  { key: "compaction.keepRecentTokens", type: "number", default: 20000 },
3737
4222
  { key: "retry.enabled", type: "boolean", default: true },
3738
4223
  { key: "retry.maxRetries", type: "number", default: 3 },
4224
+ { key: "retry.untilOnline", type: "boolean", default: true },
3739
4225
  { key: "codemode.mode", type: "enum", values: ["only", "on"], default: "only" },
3740
4226
  { key: "enableSkillCommands", type: "boolean", default: true },
3741
4227
  { key: "images.autoResize", type: "boolean", default: true },
@@ -3743,9 +4229,7 @@ var TA_SETTINGS = [
3743
4229
  { key: "shellPath", type: "string" },
3744
4230
  { key: "shellCommandPrefix", type: "string" }
3745
4231
  ];
3746
- // ../ta-protocol/esm/common/ta-protocol.js
3747
- var TaServer = Symbol("TaServer");
3748
- var TaClient = Symbol("TaClient");
4232
+ // ../ta-protocol/esm/common/slash-command-protocol.js
3749
4233
  var TaSlashCommandUtil;
3750
4234
  (function(TaSlashCommandUtil2) {
3751
4235
  function description(command2, language) {
@@ -3755,6 +4239,18 @@ var TaSlashCommandUtil;
3755
4239
  }
3756
4240
  TaSlashCommandUtil2.description = description;
3757
4241
  })(TaSlashCommandUtil || (TaSlashCommandUtil = {}));
4242
+ // ../ta-protocol/esm/common/ta-credentials.js
4243
+ var TA_CREDENTIAL_FEATURES = ["desktop", "bot", "relay", "store", "model"];
4244
+ var TaCredentialUtil;
4245
+ (function(TaCredentialUtil2) {
4246
+ function feature(value) {
4247
+ return TA_CREDENTIAL_FEATURES.includes(value) ? value : "desktop";
4248
+ }
4249
+ TaCredentialUtil2.feature = feature;
4250
+ })(TaCredentialUtil || (TaCredentialUtil = {}));
4251
+ // ../ta-protocol/esm/common/ta-protocol.js
4252
+ var TaServer = Symbol("TaServer");
4253
+ var TaClient = Symbol("TaClient");
3758
4254
  // ../ta-protocol/esm/common/team-protocol.js
3759
4255
  var TA_OWNER = "owner";
3760
4256
  var TA_UNDECLARED = "extensions.install";
@@ -3812,6 +4308,7 @@ var TA_ACTIONS = [
3812
4308
  action("cron.manage", "Change scheduled tasks", "管理定时任务", "管理定時任務", "スケジュールタスクを管理"),
3813
4309
  action("extensions.use", "Use extensions", "使用扩展", "使用擴充功能", "拡張機能を使用"),
3814
4310
  action("extensions.install", "Install and turn off extensions", "安装、停用扩展", "安裝、停用擴充功能", "拡張機能をインストール・無効化"),
4311
+ action("extensions.trust", "Decide how far others' extensions reach", "决定别人的扩展能用到哪一步", "決定別人的擴充功能能用到哪一步", "他の人の拡張機能に許す範囲を決める", { risky: true }),
3815
4312
  action("settings.view", "See settings", "查看设置", "檢視設定", "設定を確認"),
3816
4313
  action("settings.manage", "Change settings", "修改设置", "修改設定", "設定を変更"),
3817
4314
  action("members.view", "See members", "查看成员", "檢視成員", "メンバーを確認"),
@@ -3822,7 +4319,10 @@ var TA_ACTIONS = [
3822
4319
  ];
3823
4320
  var TA_OWNER_ACTIONS = [
3824
4321
  action("desktop.view", "See remote desktops", "查看远程桌面", "檢視遠端桌面", "リモートデスクトップを見る", { risky: true }),
3825
- action("desktop.control", "Work remote desktops", "操作远程桌面", "操作遠端桌面", "リモートデスクトップを操作", { risky: true })
4322
+ action("desktop.control", "Work remote desktops", "操作远程桌面", "操作遠端桌面", "リモートデスクトップを操作", { risky: true }),
4323
+ action("models.owner", "Ask models on the owner's keys", "用你的密钥和本机模型做判断", "用你的金鑰和本機模型做判斷", "あなたのキーとローカルモデルで判断", {
4324
+ risky: true
4325
+ })
3826
4326
  ];
3827
4327
  var OWNER_AREAS = ["desktop"];
3828
4328
  var TaActionUtil;
@@ -4499,6 +4999,7 @@ class TeamStore {
4499
4999
  }
4500
5000
  async listAgents() {
4501
5001
  const faces = ChannelsUtil.faces(this.team.agents);
5002
+ const standing = new Set(ChannelsUtil.standing(this.team).map((agent) => agent.id));
4502
5003
  const sessions = await this.host.listSessions().catch(() => []);
4503
5004
  const busy = new Set(Object.values(this.working).flat());
4504
5005
  const waiting = new Set;
@@ -4519,7 +5020,7 @@ class TeamStore {
4519
5020
  face: faces.get(agent.id) ?? 0,
4520
5021
  ...agent.cwd ? { cwd: agent.cwd } : {},
4521
5022
  ...agent.model ? { model: agent.model } : {},
4522
- ...agent.temporary ? { temporary: true } : {},
5023
+ ...standing.has(agent.id) ? {} : { temporary: true },
4523
5024
  ...busy.has(agent.id) ? { busy: true } : {},
4524
5025
  ...waiting.has(agent.id) ? { waiting: true } : {}
4525
5026
  }));
@@ -4685,6 +5186,8 @@ class TeamAnswers extends TeamStore {
4685
5186
  }
4686
5187
 
4687
5188
  // web-src/team.ts
5189
+ var logger = Loggers.get("ta-channels");
5190
+
4688
5191
  class TeamService extends TeamAnswers {
4689
5192
  async start() {
4690
5193
  this.team = await this.get(Keys.TEAM) ?? ChannelsUtil.emptyTeam();
@@ -5013,7 +5516,7 @@ class TeamService extends TeamAnswers {
5013
5516
  this.started.add(job.id);
5014
5517
  const next = (this.agents.get(job.agentId) ?? Promise.resolve()).catch(() => {
5015
5518
  return;
5016
- }).then(() => this.work(job)).catch((error) => console.error(`${NAME}: ${error instanceof Error ? error.message : error}`));
5519
+ }).then(() => this.work(job)).catch((error) => logger.error(error instanceof Error ? error.message : error));
5017
5520
  this.agents.set(job.agentId, next);
5018
5521
  }
5019
5522
  async work(job) {