@celljs/ta-channels 4.29.0 → 4.30.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.
Files changed (2) hide show
  1. package/host/index.mjs +231 -0
  2. package/package.json +4 -4
package/host/index.mjs CHANGED
@@ -2403,6 +2403,76 @@ var TaAppUtil;
2403
2403
  })(TaAppUtil || (TaAppUtil = {}));
2404
2404
  // ../ta-protocol/esm/common/auth-protocol.js
2405
2405
  var TaAuthServer = Symbol("TaAuthServer");
2406
+ // ../ta-protocol/esm/common/boundary-protocol.js
2407
+ var TA_BOUNDARY_KINDS = ["general", "work", "private", "guest"];
2408
+ var TA_GENERAL_BOUNDARY = Object.freeze({ kind: "general" });
2409
+ var TaBoundaryUtil;
2410
+ (function(TaBoundaryUtil2) {
2411
+ async function of(host, location) {
2412
+ if (!host.boundaries || !location) {
2413
+ return TA_GENERAL_BOUNDARY;
2414
+ }
2415
+ try {
2416
+ return await host.boundaries.of(location);
2417
+ } catch (_a) {
2418
+ return TA_GENERAL_BOUNDARY;
2419
+ }
2420
+ }
2421
+ TaBoundaryUtil2.of = of;
2422
+ async function ofAll(host, locations) {
2423
+ const found = new Map;
2424
+ for (const location of new Set(locations)) {
2425
+ found.set(location, await of(host, location));
2426
+ }
2427
+ return found;
2428
+ }
2429
+ TaBoundaryUtil2.ofAll = ofAll;
2430
+ function key(boundary) {
2431
+ var _a;
2432
+ return boundary.kind === "general" ? "general" : `${boundary.kind}:${(_a = boundary.root) !== null && _a !== undefined ? _a : ""}`;
2433
+ }
2434
+ TaBoundaryUtil2.key = key;
2435
+ function canSee(from, of2) {
2436
+ if (from.kind === "guest" || of2.kind === "guest") {
2437
+ return false;
2438
+ }
2439
+ if (of2.kind === "general") {
2440
+ return from.kind !== "private";
2441
+ }
2442
+ return key(from) === key(of2);
2443
+ }
2444
+ TaBoundaryUtil2.canSee = canSee;
2445
+ function profile(boundary, general, notes) {
2446
+ const own = (notes === null || notes === undefined ? undefined : notes.trim()) || undefined;
2447
+ const all = (general === null || general === undefined ? undefined : general.trim()) || undefined;
2448
+ switch (boundary.kind) {
2449
+ case "general":
2450
+ return all ? { general: all } : {};
2451
+ case "work":
2452
+ return { ...all ? { general: all } : {}, ...own ? { notes: own } : {} };
2453
+ case "private":
2454
+ return own ? { notes: own } : {};
2455
+ default:
2456
+ return {};
2457
+ }
2458
+ }
2459
+ TaBoundaryUtil2.profile = profile;
2460
+ function valid(value) {
2461
+ const boundary = value;
2462
+ if (!boundary || typeof boundary !== "object" || !TA_BOUNDARY_KINDS.includes(boundary.kind)) {
2463
+ return TA_GENERAL_BOUNDARY;
2464
+ }
2465
+ if (boundary.kind === "general") {
2466
+ return TA_GENERAL_BOUNDARY;
2467
+ }
2468
+ return {
2469
+ kind: boundary.kind,
2470
+ ...typeof boundary.root === "string" && boundary.root ? { root: boundary.root } : {},
2471
+ ...typeof boundary.name === "string" && boundary.name.trim() ? { name: boundary.name.trim() } : {}
2472
+ };
2473
+ }
2474
+ TaBoundaryUtil2.valid = valid;
2475
+ })(TaBoundaryUtil || (TaBoundaryUtil = {}));
2406
2476
  // ../ta-protocol/esm/common/call-moves.js
2407
2477
  var TaCallMoves;
2408
2478
  (function(TaCallMoves2) {
@@ -3015,6 +3085,167 @@ var TaLocation;
3015
3085
  return squeezed.length > 1 ? squeezed.replace(/\/$/, "") : squeezed;
3016
3086
  }
3017
3087
  })(TaLocation || (TaLocation = {}));
3088
+ // ../ta-protocol/esm/common/metrics-protocol.js
3089
+ var TA_METRICS_BOUNDS = [10, 50, 200, 1000, 5000, 30000];
3090
+ var NOT_RUNS = new Set(["turn", "section", "tooldef"]);
3091
+ var TaMetricsUtil;
3092
+ (function(TaMetricsUtil2) {
3093
+ TaMetricsUtil2.DAY = /^\d{4}-\d{2}-\d{2}$/;
3094
+ TaMetricsUtil2.KEEP_DAYS = 90;
3095
+ TaMetricsUtil2.MAX_DAYS = 365;
3096
+ TaMetricsUtil2.MAX_MB = 20;
3097
+ function limits(ta) {
3098
+ const set = ta && typeof ta === "object" ? ta : {};
3099
+ const days = Number(set.metricsKeepDays);
3100
+ const mb = Number(set.metricsMaxMB);
3101
+ return {
3102
+ keepDays: Number.isFinite(days) && days >= 1 ? Math.min(TaMetricsUtil2.MAX_DAYS, Math.floor(days)) : TaMetricsUtil2.KEEP_DAYS,
3103
+ maxBytes: Math.round((Number.isFinite(mb) && mb > 0 ? Math.min(1024, Math.max(1, mb)) : TaMetricsUtil2.MAX_MB) * 1024 * 1024)
3104
+ };
3105
+ }
3106
+ TaMetricsUtil2.limits = limits;
3107
+ function toRemove(days, limits2, today, otherBytes = 0) {
3108
+ const { since } = span({ days: limits2.keepDays, until: today });
3109
+ const sorted = [...days].sort((a, b) => a.day.localeCompare(b.day));
3110
+ const out = [];
3111
+ let total = otherBytes + sorted.reduce((sum, one) => sum + one.bytes, 0);
3112
+ for (const one of sorted) {
3113
+ if (one.day === today) {
3114
+ break;
3115
+ }
3116
+ if (one.day < since || total > limits2.maxBytes) {
3117
+ out.push(one.day);
3118
+ total -= one.bytes;
3119
+ }
3120
+ }
3121
+ return out;
3122
+ }
3123
+ TaMetricsUtil2.toRemove = toRemove;
3124
+ function bucket(ms) {
3125
+ const bounds = TA_METRICS_BOUNDS;
3126
+ let i = 0;
3127
+ while (i < bounds.length && ms >= bounds[i]) {
3128
+ i++;
3129
+ }
3130
+ return i;
3131
+ }
3132
+ TaMetricsUtil2.bucket = bucket;
3133
+ function quantile(buckets, q) {
3134
+ var _a;
3135
+ const total = (_a = buckets === null || buckets === undefined ? undefined : buckets.reduce((sum, n) => sum + n, 0)) !== null && _a !== undefined ? _a : 0;
3136
+ if (!buckets || total === 0) {
3137
+ return;
3138
+ }
3139
+ const bounds = TA_METRICS_BOUNDS;
3140
+ const rank = q * total;
3141
+ let seen = 0;
3142
+ for (let i = 0;i < buckets.length; i++) {
3143
+ const n = buckets[i];
3144
+ if (n > 0 && seen + n >= rank) {
3145
+ if (i >= bounds.length) {
3146
+ return bounds[bounds.length - 1];
3147
+ }
3148
+ const low = i === 0 ? 0 : bounds[i - 1];
3149
+ return Math.round(low + (bounds[i] - low) * ((rank - seen) / n));
3150
+ }
3151
+ seen += n;
3152
+ }
3153
+ return bounds[bounds.length - 1];
3154
+ }
3155
+ TaMetricsUtil2.quantile = quantile;
3156
+ function add(into, stat) {
3157
+ var _a, _b, _c, _d;
3158
+ into.n += stat.n || 0;
3159
+ if (stat.err) {
3160
+ into.err = ((_a = into.err) !== null && _a !== undefined ? _a : 0) + stat.err;
3161
+ }
3162
+ if (stat.abort) {
3163
+ into.abort = ((_b = into.abort) !== null && _b !== undefined ? _b : 0) + stat.abort;
3164
+ }
3165
+ if (stat.ms) {
3166
+ (_c = into.ms) !== null && _c !== undefined || (into.ms = new Array(TA_METRICS_BOUNDS.length + 1).fill(0));
3167
+ const ms = into.ms;
3168
+ stat.ms.forEach((n, i) => {
3169
+ if (i < ms.length) {
3170
+ ms[i] += n || 0;
3171
+ }
3172
+ });
3173
+ }
3174
+ if (stat.chars !== undefined) {
3175
+ into.chars = Math.max((_d = into.chars) !== null && _d !== undefined ? _d : 0, stat.chars);
3176
+ }
3177
+ return into;
3178
+ }
3179
+ TaMetricsUtil2.add = add;
3180
+ function day(at) {
3181
+ const date = new Date(at);
3182
+ return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
3183
+ }
3184
+ TaMetricsUtil2.day = day;
3185
+ function span(query = {}, now = Date.now()) {
3186
+ const until = typeof query.until === "string" && TaMetricsUtil2.DAY.test(query.until) ? query.until : day(now);
3187
+ if (typeof query.since === "string" && TaMetricsUtil2.DAY.test(query.since)) {
3188
+ return { since: query.since, until };
3189
+ }
3190
+ const days = Math.min(TaMetricsUtil2.MAX_DAYS, Math.max(1, Math.floor(Number(query.days) || 7)));
3191
+ const last = new Date(`${until}T12:00:00`);
3192
+ last.setDate(last.getDate() - (days - 1));
3193
+ return { since: day(last.getTime()), until };
3194
+ }
3195
+ TaMetricsUtil2.span = span;
3196
+ function report(days, since, until, packages) {
3197
+ var _a, _b;
3198
+ const only = (packages === null || packages === undefined ? undefined : packages.length) ? new Set(packages) : undefined;
3199
+ const merged = new Map;
3200
+ for (const one of days) {
3201
+ for (const [name, pkg] of Object.entries((_a = one.packages) !== null && _a !== undefined ? _a : {})) {
3202
+ if (only && !only.has(name)) {
3203
+ continue;
3204
+ }
3205
+ let items = merged.get(name);
3206
+ if (!items) {
3207
+ items = new Map;
3208
+ merged.set(name, items);
3209
+ }
3210
+ for (const [item, stat] of Object.entries((_b = pkg === null || pkg === undefined ? undefined : pkg.items) !== null && _b !== undefined ? _b : {})) {
3211
+ let into = items.get(item);
3212
+ if (!into) {
3213
+ into = { n: 0 };
3214
+ items.set(item, into);
3215
+ }
3216
+ add(into, stat);
3217
+ }
3218
+ }
3219
+ }
3220
+ const rows = [...merged].map(([name, items]) => {
3221
+ var _a2, _b2;
3222
+ const all = { n: 0 };
3223
+ const list = [...items].map(([item, stat]) => {
3224
+ var _a3, _b3;
3225
+ if (!NOT_RUNS.has(item.slice(0, item.indexOf(":")))) {
3226
+ add(all, { ...stat, chars: undefined });
3227
+ }
3228
+ const p50 = quantile(stat.ms, 0.5);
3229
+ const p952 = quantile(stat.ms, 0.95);
3230
+ return {
3231
+ item,
3232
+ n: stat.n,
3233
+ err: (_a3 = stat.err) !== null && _a3 !== undefined ? _a3 : 0,
3234
+ abort: (_b3 = stat.abort) !== null && _b3 !== undefined ? _b3 : 0,
3235
+ ...p50 !== undefined ? { p50 } : {},
3236
+ ...p952 !== undefined ? { p95: p952 } : {},
3237
+ ...stat.chars !== undefined ? { chars: stat.chars } : {}
3238
+ };
3239
+ });
3240
+ list.sort((a, b) => b.err - a.err || b.n - a.n || a.item.localeCompare(b.item));
3241
+ const p95 = quantile(all.ms, 0.95);
3242
+ return { name, n: all.n, err: (_a2 = all.err) !== null && _a2 !== undefined ? _a2 : 0, abort: (_b2 = all.abort) !== null && _b2 !== undefined ? _b2 : 0, ...p95 !== undefined ? { p95 } : {}, items: list };
3243
+ });
3244
+ rows.sort((a, b) => Math.sign(b.err) - Math.sign(a.err) || b.n - a.n || a.name.localeCompare(b.name));
3245
+ return { since, until, days: days.map((one) => one.day).sort(), packages: rows };
3246
+ }
3247
+ TaMetricsUtil2.report = report;
3248
+ })(TaMetricsUtil || (TaMetricsUtil = {}));
3018
3249
  // ../ta-protocol/esm/common/package-protocol.js
3019
3250
  var TaPackageServer = Symbol("TaPackageServer");
3020
3251
  var TaPackageTextUtil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-channels",
3
- "version": "4.29.0",
3
+ "version": "4.30.0",
4
4
  "description": "A pi package for Ta: agents with roles of their own and channels where the user, Ta and the agents talk; Ta builds the team for what the user wants",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -27,9 +27,9 @@
27
27
  "watch": "tsc -b -w --preserveWatchOutput"
28
28
  },
29
29
  "devDependencies": {
30
- "@celljs/ta-protocol": "4.29.0",
31
- "@celljs/ta-relay": "4.29.0",
32
- "@celljs/ta-web": "4.29.0",
30
+ "@celljs/ta-protocol": "4.30.0",
31
+ "@celljs/ta-relay": "4.30.0",
32
+ "@celljs/ta-web": "4.30.0",
33
33
  "@types/react": "^19.3.0"
34
34
  },
35
35
  "publishConfig": {