@celljs/ta-creator 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
@@ -143,10 +143,114 @@ var REPLY_KINDS = {
143
143
  }
144
144
  };
145
145
 
146
- // web-src/publish-util.ts
147
- var text = (value, max) => typeof value === "string" ? value.trim().slice(0, max) : "";
146
+ // web-src/values.ts
147
+ var text = (value, max = 2000) => typeof value === "string" ? value.trim().slice(0, max) : "";
148
+ var texts = (value, max = 50) => Array.isArray(value) ? value.map((one) => text(one, 200)).filter(Boolean).slice(0, max) : [];
148
149
  var time = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined;
150
+ var oneOf = (all, value, fallback) => all.includes(value) ? value : fallback;
149
151
  var object = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
152
+ function hash(value) {
153
+ let h = 0;
154
+ for (const char of value) {
155
+ h = Math.imul(h, 31) + (char.codePointAt(0) ?? 0) | 0;
156
+ }
157
+ return (h >>> 0).toString(36);
158
+ }
159
+ function url(value) {
160
+ const raw = text(value, 1000);
161
+ return /^https?:\/\/\S+$/i.test(raw) ? raw : undefined;
162
+ }
163
+ function count(value, fallback) {
164
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? Math.round(value) : fallback;
165
+ }
166
+
167
+ // web-src/efficiency.ts
168
+ var HOUR = 3600000;
169
+ var DAY = 24 * HOUR;
170
+ var Efficiency;
171
+ ((Efficiency) => {
172
+ Efficiency.SPAN = 7 * DAY;
173
+ function costOf(messages, now) {
174
+ let ms = 0;
175
+ let tokens = 0;
176
+ let turns = 0;
177
+ for (const message of messages) {
178
+ const kept = object(message);
179
+ if (kept?.role === "assistant") {
180
+ ms += count(kept.durationMs, 0);
181
+ tokens += count(object(kept.usage)?.totalTokens, 0);
182
+ } else if (kept?.role === "user") {
183
+ turns++;
184
+ }
185
+ }
186
+ return ms ? { minutes: Math.round(ms / 6000) / 10, ...tokens ? { tokens } : {}, turns, at: now } : undefined;
187
+ }
188
+ Efficiency.costOf = costOf;
189
+ function cost(value) {
190
+ const kept = object(value);
191
+ const at = time(kept?.at);
192
+ return kept && at && typeof kept.minutes === "number" ? { minutes: Math.max(0, kept.minutes), ...count(kept.tokens, 0) ? { tokens: count(kept.tokens, 0) } : {}, turns: count(kept.turns, 0), at } : undefined;
193
+ }
194
+ Efficiency.cost = cost;
195
+ function fields(kept) {
196
+ const made = cost(kept.cost);
197
+ return { ...time(kept.started) ? { started: time(kept.started) } : {}, ...made ? { cost: made } : {} };
198
+ }
199
+ Efficiency.fields = fields;
200
+ function leadHours(item) {
201
+ return item.stage === "published" && item.links?.length ? Math.round((outAt(item) - item.at) / HOUR * 10) / 10 : undefined;
202
+ }
203
+ Efficiency.leadHours = leadHours;
204
+ function taskRuns(runs, from, to) {
205
+ const of = runs.filter((one) => {
206
+ const at = Date.parse(one.startedAt);
207
+ return at >= from && at < to && one.status !== "running";
208
+ });
209
+ return {
210
+ runs: of.length,
211
+ empty: of.filter((one) => one.quiet).length,
212
+ failed: of.filter((one) => one.status === "error").length,
213
+ minutes: Math.round(of.reduce((all, one) => all + (one.ranMs ?? 0), 0) / 60000)
214
+ };
215
+ }
216
+ Efficiency.taskRuns = taskRuns;
217
+ function pieces(items, from, to) {
218
+ const of = items.filter((one) => {
219
+ const at = one.stage === "published" && one.links?.length ? outAt(one) : 0;
220
+ return !one.dropped && at >= from && at < to;
221
+ });
222
+ const costs = of.flatMap((one) => one.cost ? [one.cost] : []);
223
+ return {
224
+ pieces: of.length,
225
+ leadHours: middle(of.map(leadHours)),
226
+ minutes: middle(costs.map((one) => one.minutes)),
227
+ tokens: middle(costs.map((one) => one.tokens)),
228
+ turns: middle(costs.map((one) => one.turns))
229
+ };
230
+ }
231
+ Efficiency.pieces = pieces;
232
+ function outAt(item) {
233
+ return Math.min(...(item.links ?? []).map((one) => one.scheduled ?? one.at));
234
+ }
235
+ function middle(values) {
236
+ const known = values.filter((one) => typeof one === "number").sort((a, b) => a - b);
237
+ if (!known.length) {
238
+ return;
239
+ }
240
+ const at = Math.floor(known.length / 2);
241
+ return known.length % 2 ? known[at] : Math.round((known[at - 1] + known[at]) / 2 * 10) / 10;
242
+ }
243
+ Efficiency.middle = middle;
244
+ function windows(now) {
245
+ return { before: [now - 2 * Efficiency.SPAN, now - Efficiency.SPAN], after: [now - Efficiency.SPAN, now + 1] };
246
+ }
247
+ Efficiency.windows = windows;
248
+ })(Efficiency ||= {});
249
+
250
+ // web-src/publish-util.ts
251
+ var text2 = (value, max) => typeof value === "string" ? value.trim().slice(0, max) : "";
252
+ var time2 = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined;
253
+ var object2 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
150
254
  var PublishUtil;
151
255
  ((PublishUtil) => {
152
256
  function dayOf(at) {
@@ -194,74 +298,88 @@ var PublishUtil;
194
298
  const at = new Date(value.trim().replace(" ", "T")).getTime();
195
299
  return Number.isFinite(at) ? at : undefined;
196
300
  }
197
- return time(value);
301
+ return time2(value);
198
302
  }
199
303
  PublishUtil.timeOf = timeOf;
200
304
  function of(piece) {
201
- const approved = time(piece.approved);
305
+ const approved = time2(piece.approved);
202
306
  return publishing(piece.publishing) ?? (piece.stage === "review" && approved && !piece.publishing ? { state: "queued", since: approved } : undefined);
203
307
  }
204
308
  PublishUtil.of = of;
205
309
  function publishing(value) {
206
- const kept = object(value);
207
- const since = time(kept?.since);
310
+ const kept = object2(value);
311
+ const since = time2(kept?.since);
208
312
  const state = kept && ["queued", "running", "stopped"].find((one) => one === kept.state);
209
313
  if (!kept || !since || !state) {
210
314
  return;
211
315
  }
212
- const slots2 = Array.isArray(kept.slots) ? kept.slots.map((one) => object(one)).filter((one) => !!one && !!text(one.platform, 60)).map((one) => ({ platform: text(one.platform, 60), ...time(one.at) ? { at: time(one.at) } : {} })) : undefined;
316
+ const slots2 = Array.isArray(kept.slots) ? kept.slots.map((one) => object2(one)).filter((one) => !!one && !!text2(one.platform, 60)).map((one) => ({ platform: text2(one.platform, 60), ...time2(one.at) ? { at: time2(one.at) } : {} })) : undefined;
213
317
  return {
214
318
  state,
215
319
  since,
216
320
  ...slots2 ? { slots: slots2 } : {},
217
- ...text(kept.note, 300) ? { note: text(kept.note, 300) } : {},
218
- ...text(kept.ask, 500) ? { ask: text(kept.ask, 500) } : {}
321
+ ...text2(kept.note, 300) ? { note: text2(kept.note, 300) } : {},
322
+ ...text2(kept.ask, 500) ? { ask: text2(kept.ask, 500) } : {}
219
323
  };
220
324
  }
221
325
  PublishUtil.publishing = publishing;
222
326
  })(PublishUtil ||= {});
223
327
 
224
- // web-src/values.ts
225
- var text2 = (value, max = 2000) => typeof value === "string" ? value.trim().slice(0, max) : "";
226
- var texts = (value, max = 50) => Array.isArray(value) ? value.map((one) => text2(one, 200)).filter(Boolean).slice(0, max) : [];
227
- var time2 = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined;
228
- var oneOf = (all, value, fallback) => all.includes(value) ? value : fallback;
229
- var object2 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
230
- function hash(value) {
231
- let h = 0;
232
- for (const char of value) {
233
- h = Math.imul(h, 31) + (char.codePointAt(0) ?? 0) | 0;
328
+ // web-src/quality.ts
329
+ var RUBRIC = [
330
+ { id: "hook", weight: 20, asks: "the first 3 seconds give the point, a question or a picture that moves; no slow greeting" },
331
+ { id: "clarity", weight: 20, asks: "one idea, its terms explained, every fact checked; a newcomer follows it" },
332
+ { id: "visuals", weight: 15, asks: "scenes vary (a device or a flow every other one), none of the host talking 20 seconds on" },
333
+ { id: "pace", weight: 15, asks: "its length fits the platform, short sentences, no dead air, it ends when the point is made" },
334
+ { id: "title", weight: 10, asks: "title and cover say truly and plainly what one gets: a number, a question, never exaggerated" },
335
+ { id: "series", weight: 10, asks: "of a series: its number, a line to the last piece, and the next piece told at the end" },
336
+ { id: "fit", weight: 10, asks: "each version in its platform's form, voice, length and tags; its declaration ticked" }
337
+ ];
338
+ var PASS = 80;
339
+ var Quality;
340
+ ((Quality) => {
341
+ function score(value, now) {
342
+ const given = Array.isArray(value) ? value.map(object).filter((one) => !!one) : [];
343
+ const parts = RUBRIC.map(({ id }) => {
344
+ const one = given.find((it) => it.id === id);
345
+ const note = text(one?.note, 200);
346
+ return { id, score: Math.min(100, count(one?.score, 0)), ...note ? { note } : {} };
347
+ });
348
+ const total = Math.round(parts.reduce((all, one, at) => all + one.score * RUBRIC[at].weight / 100, 0));
349
+ return { total, parts, at: now };
234
350
  }
235
- return (h >>> 0).toString(36);
236
- }
237
- function url(value) {
238
- const raw = text2(value, 1000);
239
- return /^https?:\/\/\S+$/i.test(raw) ? raw : undefined;
240
- }
241
- function count(value, fallback) {
242
- return typeof value === "number" && Number.isFinite(value) && value >= 0 ? Math.round(value) : fallback;
243
- }
351
+ Quality.score = score;
352
+ function weak(score2) {
353
+ return score2.parts.filter((one) => one.score < PASS).sort((a, b) => a.score - b.score);
354
+ }
355
+ Quality.weak = weak;
356
+ function fields(kept) {
357
+ const one = object(kept.score);
358
+ return one && time(one.at) ? { score: { ...score(one.parts, time(one.at)) } } : {};
359
+ }
360
+ Quality.fields = fields;
361
+ })(Quality ||= {});
244
362
 
245
363
  // web-src/creator-util.ts
246
- var DAY = 86400000;
364
+ var DAY2 = 86400000;
247
365
  var MAX_TOPICS = 200;
248
- var HOT_FOR = 2 * DAY;
366
+ var HOT_FOR = 2 * DAY2;
249
367
  var MAX_TONES = 3;
250
368
  var CreatorUtil;
251
369
  ((CreatorUtil) => {
252
370
  function settings(value) {
253
- const kept = object2(value) ?? {};
371
+ const kept = object(value) ?? {};
254
372
  const platforms = Array.isArray(kept.platforms) ? withBuiltins(kept.platforms.map(platform).filter((one) => !!one)) : [...PLATFORMS];
255
373
  const ids = new Set(platforms.map((one) => one.id));
256
- const goal = object2(kept.goal);
374
+ const goal = object(kept.goal);
257
375
  return {
258
- niche: text2(kept.niche, 500),
376
+ niche: text(kept.niche, 500),
259
377
  picked: texts(kept.picked).filter((id) => ids.has(id)),
260
378
  platforms,
261
379
  sources: Array.isArray(kept.sources) ? kept.sources.map(source).filter((one) => !!one) : [...SOURCES],
262
- ...goal && time2(goal.from) ? { goal: { from: time2(goal.from), days: count(goal.days, 30), videos: count(goal.videos, 0), posts: count(goal.posts, 0) } } : {},
380
+ ...goal && time(goal.from) ? { goal: { from: time(goal.from), days: count(goal.days, 30), videos: count(goal.videos, 0), posts: count(goal.posts, 0) } } : {},
263
381
  minutesCap: count(kept.minutesCap, 120),
264
- voice: text2(kept.voice, 60) || "zh-CN-XiaoxiaoNeural",
382
+ voice: text(kept.voice, 60) || "zh-CN-XiaoxiaoNeural",
265
383
  tone: tones(kept.tone),
266
384
  series: Array.isArray(kept.series) ? seriesOf(kept.series) : [],
267
385
  strategy: kept.strategy === "manual" ? "manual" : "auto",
@@ -286,7 +404,7 @@ var CreatorUtil;
286
404
  CreatorUtil.withBuiltins = withBuiltins;
287
405
  function tones(value) {
288
406
  return [
289
- ...new Set(texts(value).map((one) => text2(one, 20)).filter(Boolean))
407
+ ...new Set(texts(value).map((one) => text(one, 20)).filter(Boolean))
290
408
  ].slice(0, MAX_TONES);
291
409
  }
292
410
  CreatorUtil.tones = tones;
@@ -319,23 +437,23 @@ var CreatorUtil;
319
437
  function seriesOf(values) {
320
438
  const all = [];
321
439
  for (const value of values) {
322
- const kept = object2(value);
323
- const name = text2(kept?.name, 40);
440
+ const kept = object(value);
441
+ const name = text(kept?.name, 40);
324
442
  if (!kept || !name) {
325
443
  continue;
326
444
  }
327
- const id = text2(kept.id, 60) || `s${hash(name)}`;
445
+ const id = text(kept.id, 60) || `s${hash(name)}`;
328
446
  if (all.some((one) => one.id === id)) {
329
447
  continue;
330
448
  }
331
- const about = text2(kept.about, 200);
449
+ const about = text(kept.about, 200);
332
450
  const perWeek = count(kept.perWeek, 0);
333
- const tone = text2(kept.tone, 20);
451
+ const tone = text(kept.tone, 20);
334
452
  all.push({
335
453
  id,
336
454
  name,
337
455
  ...about ? { about } : {},
338
- color: text2(kept.color, 40) || SERIES_COLORS[all.length % SERIES_COLORS.length],
456
+ color: text(kept.color, 40) || SERIES_COLORS[all.length % SERIES_COLORS.length],
339
457
  ...kept.ordered === true ? { ordered: true } : {},
340
458
  ...perWeek ? { perWeek: Math.min(perWeek, 14) } : {},
341
459
  ...kept.reach === "internal" || kept.reach === "both" ? { reach: kept.reach } : {},
@@ -346,35 +464,35 @@ var CreatorUtil;
346
464
  }
347
465
  CreatorUtil.seriesOf = seriesOf;
348
466
  function platform(value) {
349
- const kept = object2(value);
350
- const id = text2(kept?.id, 60);
351
- const name = text2(kept?.name, 60);
467
+ const kept = object(value);
468
+ const id = text(kept?.id, 60);
469
+ const name = text(kept?.name, 60);
352
470
  if (!kept || !id || !name) {
353
471
  return;
354
472
  }
355
473
  const shape = (one) => {
356
- const it = object2(one);
474
+ const it = object(one);
357
475
  return it ? { aspect: oneOf(ASPECTS, it.aspect, "16:9"), ...count(it.maxSeconds, 0) ? { maxSeconds: count(it.maxSeconds, 0) } : {} } : undefined;
358
476
  };
359
477
  const video = shape(kept.video);
360
- const post = object2(kept.post) ? {
361
- aspect: oneOf(ASPECTS, object2(kept.post)?.aspect, "3:4"),
362
- ...count(object2(kept.post)?.maxImages, 0) ? { maxImages: count(object2(kept.post)?.maxImages, 0) } : {}
478
+ const post = object(kept.post) ? {
479
+ aspect: oneOf(ASPECTS, object(kept.post)?.aspect, "3:4"),
480
+ ...count(object(kept.post)?.maxImages, 0) ? { maxImages: count(object(kept.post)?.maxImages, 0) } : {}
363
481
  } : undefined;
364
482
  const words = (one) => {
365
- const it = object2(one);
483
+ const it = object(one);
366
484
  return it ? count(it.maxChars, 0) ? { maxChars: count(it.maxChars, 0) } : {} : undefined;
367
485
  };
368
486
  const article = words(kept.article);
369
487
  const note = words(kept.note);
370
488
  const publish = url(kept.publish);
371
- const declare = text2(kept.declare, 200);
489
+ const declare = text(kept.declare, 200);
372
490
  const inside = kept.internal === true ? { internal: true } : {};
373
491
  return {
374
492
  ...inside,
375
493
  id,
376
494
  name,
377
- color: text2(kept.color, 40) || "#8e8e93",
495
+ color: text(kept.color, 40) || "#8e8e93",
378
496
  ...video ? { video } : {},
379
497
  ...post ? { post } : {},
380
498
  ...article ? { article } : {},
@@ -389,14 +507,14 @@ var CreatorUtil;
389
507
  }
390
508
  CreatorUtil.items = items;
391
509
  function item(value) {
392
- const kept = object2(value);
393
- const id = text2(kept?.id, 80);
394
- const title = text2(kept?.title, 200);
395
- const at = time2(kept?.at);
510
+ const kept = object(value);
511
+ const id = text(kept?.id, 80);
512
+ const title = text(kept?.title, 200);
513
+ const at = time(kept?.at);
396
514
  if (!kept || !id || !title || !at) {
397
515
  return;
398
516
  }
399
- const origin = object2(kept.origin);
517
+ const origin = object(kept.origin);
400
518
  const originUrl = url(origin?.url);
401
519
  return {
402
520
  id,
@@ -404,38 +522,40 @@ var CreatorUtil;
404
522
  form: oneOf(FORMS, kept.form, "video"),
405
523
  kind: oneOf(KINDS, kept.kind, "howto"),
406
524
  stage: oneOf(STAGES, kept.stage, "topic"),
407
- ...text2(kept.series, 60) ? { series: text2(kept.series, 60) } : {},
525
+ ...text(kept.series, 60) ? { series: text(kept.series, 60) } : {},
408
526
  ...count(kept.number, 0) ? { number: count(kept.number, 0) } : {},
409
527
  ...REACHES.includes(kept.reach) ? { reach: kept.reach } : {},
410
- ...text2(kept.why, 300) ? { why: text2(kept.why, 300) } : {},
528
+ ...text(kept.why, 300) ? { why: text(kept.why, 300) } : {},
411
529
  ...typeof kept.heat === "number" ? { heat: Math.max(0, Math.min(100, Math.round(kept.heat))) } : {},
412
- ...time2(kept.until) ? { until: time2(kept.until) } : {},
530
+ ...time(kept.until) ? { until: time(kept.until) } : {},
413
531
  ...texts(kept.seen, 10).length ? { seen: texts(kept.seen, 10) } : {},
414
532
  ...origin && originUrl ? {
415
533
  origin: {
416
534
  url: originUrl,
417
- ...text2(origin.title, 200) ? { title: text2(origin.title, 200) } : {},
418
- ...text2(origin.author, 100) ? { author: text2(origin.author, 100) } : {},
419
- ...text2(origin.licence, 100) ? { licence: text2(origin.licence, 100) } : {}
535
+ ...text(origin.title, 200) ? { title: text(origin.title, 200) } : {},
536
+ ...text(origin.author, 100) ? { author: text(origin.author, 100) } : {},
537
+ ...text(origin.licence, 100) ? { licence: text(origin.licence, 100) } : {}
420
538
  }
421
539
  } : {},
422
540
  ...Array.isArray(kept.needs) ? {
423
541
  needs: kept.needs.map(need).filter((one) => !!one).slice(0, 12)
424
542
  } : {},
425
543
  ...Array.isArray(kept.done) ? { done: STEPS.filter((step) => kept.done.includes(step)) } : {},
426
- ...text2(kept.script, 20000) ? { script: text2(kept.script, 20000) } : {},
544
+ ...text(kept.script, 20000) ? { script: text(kept.script, 20000) } : {},
427
545
  ...Array.isArray(kept.versions) ? { versions: kept.versions.map(version).filter((one) => !!one) } : {},
428
546
  ...Array.isArray(kept.checks) ? { checks: kept.checks.map(check).filter((one) => !!one) } : {},
429
- ...text2(kept.session, 1000) ? { session: text2(kept.session, 1000) } : {},
430
- ...time2(kept.approved) ? { approved: time2(kept.approved) } : {},
547
+ ...text(kept.session, 1000) ? { session: text(kept.session, 1000) } : {},
548
+ ...time(kept.approved) ? { approved: time(kept.approved) } : {},
431
549
  ...PublishUtil.of(kept) ? { publishing: PublishUtil.of(kept) } : {},
432
550
  ...Array.isArray(kept.links) ? { links: kept.links.map(link).filter((one) => !!one) } : {},
433
551
  ...Array.isArray(kept.stats) ? { stats: kept.stats.map(stat).filter((one) => !!one) } : {},
434
552
  ...kept.dropped === true ? { dropped: true } : {},
435
- ...time2(kept.commentsAt) ? { commentsAt: time2(kept.commentsAt) } : {},
436
- ...time2(kept.commentsGap) ? { commentsGap: time2(kept.commentsGap) } : {},
553
+ ...time(kept.commentsAt) ? { commentsAt: time(kept.commentsAt) } : {},
554
+ ...time(kept.commentsGap) ? { commentsGap: time(kept.commentsGap) } : {},
555
+ ...Efficiency.fields(kept),
556
+ ...Quality.fields(kept),
437
557
  at,
438
- changedAt: time2(kept.changedAt) ?? at
558
+ changedAt: time(kept.changedAt) ?? at
439
559
  };
440
560
  }
441
561
  CreatorUtil.item = item;
@@ -443,10 +563,10 @@ var CreatorUtil;
443
563
  if (!Array.isArray(value)) {
444
564
  return [];
445
565
  }
446
- return value.map((one) => object2(one)).filter((one) => !!one && /^\d{4}-\d{2}-\d{2}$/.test(String(one.week))).map((one) => ({
566
+ return value.map((one) => object(one)).filter((one) => !!one && /^\d{4}-\d{2}-\d{2}$/.test(String(one.week))).map((one) => ({
447
567
  week: String(one.week),
448
- platforms: (Array.isArray(one.platforms) ? one.platforms : []).map((it) => object2(it)).filter((it) => !!it && !!text2(it.platform, 60)).map((it) => ({
449
- platform: text2(it.platform, 60),
568
+ platforms: (Array.isArray(one.platforms) ? one.platforms : []).map((it) => object(it)).filter((it) => !!it && !!text(it.platform, 60)).map((it) => ({
569
+ platform: text(it.platform, 60),
450
570
  views: count(it.views, 0),
451
571
  ...typeof it.likes === "number" ? { likes: count(it.likes, 0) } : {},
452
572
  ...typeof it.follows === "number" ? { follows: count(it.follows, 0) } : {},
@@ -519,7 +639,7 @@ var CreatorUtil;
519
639
  }
520
640
  CreatorUtil.change = change;
521
641
  function seriesNamed(series, value) {
522
- const key = text2(value, 60).toLowerCase();
642
+ const key = text(value, 60).toLowerCase();
523
643
  return key ? series.find((one) => one.id.toLowerCase() === key || one.name.toLowerCase() === key) : undefined;
524
644
  }
525
645
  CreatorUtil.seriesNamed = seriesNamed;
@@ -546,7 +666,7 @@ var CreatorUtil;
546
666
  }
547
667
  CreatorUtil.views = views;
548
668
  function setStats(items2, id, stats, now) {
549
- const read = stats.map((one) => stat({ at: now, ...object2(one) ?? {} })).filter((one) => !!one);
669
+ const read = stats.map((one) => stat({ at: now, ...object(one) ?? {} })).filter((one) => !!one);
550
670
  const before = items2.find((one) => one.id === id);
551
671
  if (!before) {
552
672
  throw new Error(`No such piece: ${id}.`);
@@ -559,7 +679,7 @@ var CreatorUtil;
559
679
  if (!goal) {
560
680
  return;
561
681
  }
562
- const end = goal.from + goal.days * DAY;
682
+ const end = goal.from + goal.days * DAY2;
563
683
  const published = items2.filter((one) => one.stage === "published" && (one.links?.length ?? 0) > 0).filter((one) => {
564
684
  const at = publishedAt(one);
565
685
  return at >= goal.from && at < end;
@@ -567,7 +687,7 @@ var CreatorUtil;
567
687
  return {
568
688
  videos: published.filter((one) => one.form === "video").length,
569
689
  posts: published.filter((one) => one.form !== "video").length,
570
- day: Math.max(1, Math.min(goal.days, Math.floor((now - goal.from) / DAY) + 1))
690
+ day: Math.max(1, Math.min(goal.days, Math.floor((now - goal.from) / DAY2) + 1))
571
691
  };
572
692
  }
573
693
  CreatorUtil.progress = progress;
@@ -604,44 +724,41 @@ var CreatorUtil;
604
724
  }
605
725
  CreatorUtil.offer = offer;
606
726
  function need(value) {
607
- const kept = object2(value);
608
- const words = text2(kept?.text, 300);
609
- if (!kept || !words) {
610
- return;
611
- }
612
- return { id: text2(kept.id, 60), text: words, ...kept.done === true ? { done: true } : {} };
727
+ const kept = object(value);
728
+ const words = text(kept?.text, 300);
729
+ return kept && words ? { id: text(kept.id, 60), text: words, ...kept.done === true ? { done: true } : {} } : undefined;
613
730
  }
614
731
  CreatorUtil.need = need;
615
732
  function version(value) {
616
- const kept = object2(value);
617
- const platform2 = text2(kept?.platform, 60);
733
+ const kept = object(value);
734
+ const platform2 = text(kept?.platform, 60);
618
735
  if (!kept || !platform2) {
619
736
  return;
620
737
  }
621
- const cover = text2(kept.cover, 500);
738
+ const cover = text(kept.cover, 500);
622
739
  return {
623
740
  platform: platform2,
624
741
  ...FORMS.includes(kept.form) ? { form: kept.form } : {},
625
- title: text2(kept.title, 200),
626
- text: text2(kept.text, 20000),
742
+ title: text(kept.title, 200),
743
+ text: text(kept.text, 20000),
627
744
  tags: texts(kept.tags, 20),
628
745
  files: texts(kept.files, 40),
629
746
  ...cover ? { cover } : {}
630
747
  };
631
748
  }
632
749
  function check(value) {
633
- const kept = object2(value);
634
- return kept && text2(kept.text, 200) ? { text: text2(kept.text, 200), ok: kept.ok === true } : undefined;
750
+ const kept = object(value);
751
+ return kept && text(kept.text, 200) ? { text: text(kept.text, 200), ok: kept.ok === true } : undefined;
635
752
  }
636
753
  function link(value) {
637
- const kept = object2(value);
754
+ const kept = object(value);
638
755
  const href = url(kept?.url);
639
756
  const scheduled = PublishUtil.timeOf(kept?.scheduled);
640
- return kept && href && text2(kept.platform, 60) ? { platform: text2(kept.platform, 60), url: href, at: time2(kept.at) ?? Date.now(), ...scheduled ? { scheduled } : {} } : undefined;
757
+ return kept && href && text(kept.platform, 60) ? { platform: text(kept.platform, 60), url: href, at: time(kept.at) ?? Date.now(), ...scheduled ? { scheduled } : {} } : undefined;
641
758
  }
642
759
  function stat(value) {
643
- const kept = object2(value);
644
- const platform2 = text2(kept?.platform, 60);
760
+ const kept = object(value);
761
+ const platform2 = text(kept?.platform, 60);
645
762
  if (!kept || !platform2 || typeof kept.views !== "number") {
646
763
  return;
647
764
  }
@@ -649,25 +766,23 @@ var CreatorUtil;
649
766
  return {
650
767
  platform: platform2,
651
768
  views: count(kept.views, 0),
652
- ...optional("likes"),
653
- ...optional("comments"),
654
- ...optional("follows"),
769
+ ...Object.assign({}, ...["likes", "comments", "follows", "watch"].map(optional)),
655
770
  ...typeof kept.completion === "number" && Number.isFinite(kept.completion) ? { completion: Math.max(0, Math.min(1, kept.completion)) } : {},
656
- at: time2(kept.at) ?? Date.now()
771
+ at: time(kept.at) ?? Date.now()
657
772
  };
658
773
  }
659
774
  function source(value) {
660
- const kept = object2(value);
775
+ const kept = object(value);
661
776
  const href = url(kept?.url);
662
- return kept && href && text2(kept.name, 80) ? { name: text2(kept.name, 80), url: href } : undefined;
777
+ return kept && href && text(kept.name, 80) ? { name: text(kept.name, 80), url: href } : undefined;
663
778
  }
664
779
  })(CreatorUtil ||= {});
665
780
 
666
781
  // web-src/channel-util.ts
667
- var HOUR = 3600000;
668
- var DAY2 = 24 * HOUR;
782
+ var HOUR2 = 3600000;
783
+ var DAY3 = 24 * HOUR2;
669
784
  var MAX_COMMENTS = 600;
670
- var COMMENTS_FOR = 60 * DAY2;
785
+ var COMMENTS_FOR = 60 * DAY3;
671
786
  var MAX_LESSONS = 40;
672
787
  var ChannelUtil;
673
788
  ((ChannelUtil) => {
@@ -711,14 +826,14 @@ var ChannelUtil;
711
826
  }
712
827
  ChannelUtil.analysis = analysis;
713
828
  function insights(value) {
714
- const all = (Array.isArray(value) ? value : []).map((one) => object2(one)).filter((one) => !!one && !!text2(one.text, 300) && !!time2(one.at)).map((one) => {
715
- const at = time2(one.at);
716
- const words = text2(one.text, 300);
829
+ const all = (Array.isArray(value) ? value : []).map((one) => object(one)).filter((one) => !!one && !!text(one.text, 300) && !!time(one.at)).map((one) => {
830
+ const at = time(one.at);
831
+ const words = text(one.text, 300);
717
832
  return {
718
- id: text2(one.id, 60) || `i${hash(words + at)}`,
833
+ id: text(one.id, 60) || `i${hash(words + at)}`,
719
834
  text: words,
720
835
  tone: oneOf(["good", "bad", "idea"], one.tone, "idea"),
721
- ...text2(one.series, 60) ? { series: text2(one.series, 60) } : {},
836
+ ...text(one.series, 60) ? { series: text(one.series, 60) } : {},
722
837
  ...one.by === "user" ? { by: "user" } : {},
723
838
  ...one.state === "proposed" || one.state === "declined" ? { state: one.state } : {},
724
839
  at
@@ -730,7 +845,7 @@ var ChannelUtil;
730
845
  }
731
846
  ChannelUtil.insights = insights;
732
847
  function addInsights(kept, added, series, now, mode = "auto") {
733
- const read = added.map((one) => typeof one === "string" ? { text: one } : object2(one)).filter((one) => !!one).map((one, at) => ({
848
+ const read = added.map((one) => typeof one === "string" ? { text: one } : object(one)).filter((one) => !!one).map((one, at) => ({
734
849
  ...one,
735
850
  id: `i${now.toString(36)}${at}`,
736
851
  by: undefined,
@@ -742,7 +857,7 @@ var ChannelUtil;
742
857
  }
743
858
  ChannelUtil.addInsights = addInsights;
744
859
  function addRule(kept, words, series, now, seriesId) {
745
- const rule = text2(words, 300);
860
+ const rule = text(words, 300);
746
861
  if (!rule) {
747
862
  throw new Error("A rule needs its words.");
748
863
  }
@@ -774,7 +889,7 @@ var ChannelUtil;
774
889
  function latestInsights(insights2) {
775
890
  const ta = insights2.filter((one) => one.by !== "user" && !one.state);
776
891
  const newest = ta[0]?.at ?? 0;
777
- return insights2.filter((one) => one.by === "user" || !one.state && newest - one.at < DAY2);
892
+ return insights2.filter((one) => one.by === "user" || !one.state && newest - one.at < DAY3);
778
893
  }
779
894
  ChannelUtil.latestInsights = latestInsights;
780
895
  function proposed(insights2) {
@@ -782,12 +897,12 @@ var ChannelUtil;
782
897
  }
783
898
  ChannelUtil.proposed = proposed;
784
899
  function phases(value) {
785
- return (Array.isArray(value) ? value : []).map((one) => object2(one)).filter((one) => !!one && !!time2(one.from) && !!time2(one.to) && !!text2(one.summary, 2000) && !!time2(one.at)).map((one) => ({
786
- from: time2(one.from),
787
- to: time2(one.to),
788
- summary: text2(one.summary, 2000),
789
- ...text2(one.topic, 80) ? { topic: text2(one.topic, 80) } : {},
790
- at: time2(one.at)
900
+ return (Array.isArray(value) ? value : []).map((one) => object(one)).filter((one) => !!one && !!time(one.from) && !!time(one.to) && !!text(one.summary, 2000) && !!time(one.at)).map((one) => ({
901
+ from: time(one.from),
902
+ to: time(one.to),
903
+ summary: text(one.summary, 2000),
904
+ ...text(one.topic, 80) ? { topic: text(one.topic, 80) } : {},
905
+ at: time(one.at)
791
906
  })).sort((a, b) => b.at - a.at).slice(0, 24);
792
907
  }
793
908
  ChannelUtil.phases = phases;
@@ -797,21 +912,21 @@ var ChannelUtil;
797
912
  }
798
913
  const published = items.filter((one) => one.stage === "published" && !one.dropped).map(CreatorUtil.publishedAt);
799
914
  const from = phases2[0]?.to ?? (published.length ? Math.min(...published) : undefined);
800
- if (from === undefined || now - from < settings.phaseWeeks * 7 * DAY2 || !published.some((at) => at >= from)) {
915
+ if (from === undefined || now - from < settings.phaseWeeks * 7 * DAY3 || !published.some((at) => at >= from)) {
801
916
  return;
802
917
  }
803
918
  return { from, to: now };
804
919
  }
805
920
  ChannelUtil.phaseDue = phaseDue;
806
921
  function needsOf(values, now) {
807
- return values.map((one, at) => CreatorUtil.need(typeof one === "string" ? { text: one } : { id: `n${now.toString(36)}${at}`, ...object2(one) ?? {} })).filter((one) => !!one).map((one, at) => one.id ? one : { ...one, id: `n${now.toString(36)}${at}` }).slice(0, 12);
922
+ return values.map((one, at) => CreatorUtil.need(typeof one === "string" ? { text: one } : { id: `n${now.toString(36)}${at}`, ...object(one) ?? {} })).filter((one) => !!one).map((one, at) => one.id ? one : { ...one, id: `n${now.toString(36)}${at}` }).slice(0, 12);
808
923
  }
809
924
  ChannelUtil.needsOf = needsOf;
810
925
  function given(item) {
811
926
  return (item.needs ?? []).every((one) => one.done);
812
927
  }
813
928
  ChannelUtil.given = given;
814
- ChannelUtil.PACE = { start: 12 * HOUR, first: 24 * HOUR, min: 2 * HOUR, max: 2 * DAY2, many: 3, ride: 0.5 };
929
+ ChannelUtil.PACE = { start: 12 * HOUR2, first: 24 * HOUR2, min: 2 * HOUR2, max: 2 * DAY3, many: 3, ride: 0.5 };
815
930
  function nextGap(gap, added) {
816
931
  if (added >= ChannelUtil.PACE.many) {
817
932
  return Math.max(ChannelUtil.PACE.min, Math.round(gap / 2));
@@ -825,7 +940,7 @@ var ChannelUtil;
825
940
  }
826
941
  ChannelUtil.firstGap = firstGap;
827
942
  function commentsGap(item, items, settings) {
828
- return settings.commentsEvery ? settings.commentsEvery * HOUR : item.commentsGap ?? firstGap(items);
943
+ return settings.commentsEvery ? settings.commentsEvery * HOUR2 : item.commentsGap ?? firstGap(items);
829
944
  }
830
945
  ChannelUtil.commentsGap = commentsGap;
831
946
  function live(item, now) {
@@ -840,10 +955,31 @@ var ChannelUtil;
840
955
  }
841
956
  const published = Math.min(...out);
842
957
  const since = now - Math.max(one.commentsAt ?? 0, published);
843
- return now - published < settings.commentsDays * DAY2 && since >= share * commentsGap(one, items, settings);
958
+ return now - published < settings.commentsDays * DAY3 && since >= share * commentsGap(one, items, settings);
844
959
  });
845
960
  }
846
961
  ChannelUtil.due = due;
962
+ ChannelUtil.STATS = { first: 20 * HOUR2, again: 7 * DAY3, until: 14 * DAY3 };
963
+ function enough(waiting, settings) {
964
+ const perWeek = settings.series.reduce((all, one) => all + (one.perWeek ?? 1), 0);
965
+ return perWeek > 0 && waiting >= 2 * perWeek;
966
+ }
967
+ ChannelUtil.enough = enough;
968
+ function statsDue(items, now) {
969
+ return items.filter((one) => one.stage === "published" && !one.dropped).map((item) => ({
970
+ item,
971
+ links: live(item, now).filter((link) => {
972
+ const out = link.scheduled ?? link.at;
973
+ const read = item.stats?.find((one) => one.platform === link.platform);
974
+ const age = now - out;
975
+ if (age < ChannelUtil.STATS.first || age >= ChannelUtil.STATS.until) {
976
+ return false;
977
+ }
978
+ return !read || age >= ChannelUtil.STATS.again && read.at - out < ChannelUtil.STATS.again - DAY3;
979
+ })
980
+ })).filter((one) => one.links.length > 0);
981
+ }
982
+ ChannelUtil.statsDue = statsDue;
847
983
  function comments(value, now = Date.now()) {
848
984
  return (Array.isArray(value) ? value : []).map(comment).filter((one) => !!one && now - one.at < COMMENTS_FOR).sort((a, b) => a.at - b.at).slice(-MAX_COMMENTS);
849
985
  }
@@ -852,16 +988,16 @@ var ChannelUtil;
852
988
  const all = [...kept];
853
989
  const added = [];
854
990
  for (const value of input) {
855
- const read = object2(value);
856
- const platform = text2(read?.platform, 60);
857
- const words = text2(read?.text, 1000);
991
+ const read = object(value);
992
+ const platform = text(read?.platform, 60);
993
+ const words = text(read?.text, 1000);
858
994
  if (!read || !platform || !words) {
859
995
  continue;
860
996
  }
861
- const key = text2(read.key, 120) || `t${hash(words)}`;
997
+ const key = text(read.key, 120) || `t${hash(words)}`;
862
998
  const cls = oneOf(COMMENT_CLASSES, read.class, "question");
863
999
  const level = REPLY_CLASSES.includes(cls) ? levels[cls] : "off";
864
- const answer = text2(read.reply, 500);
1000
+ const answer = text(read.reply, 500);
865
1001
  const reply = answer && level !== "off" ? level === "act" && read.sent === true ? { text: answer, state: "sent", auto: true, at: now } : { text: answer, state: "draft", at: now } : undefined;
866
1002
  const at = all.findIndex((one) => one.item === item && one.platform === platform && one.key === key);
867
1003
  if (at >= 0) {
@@ -896,25 +1032,25 @@ var ChannelUtil;
896
1032
  }
897
1033
  ChannelUtil.examples = examples;
898
1034
  function lessons(value) {
899
- return (Array.isArray(value) ? value : []).map((one) => object2(one)).filter((one) => !!one && !!text2(one.text, 300) && !!time2(one.at)).map((one) => ({ text: text2(one.text, 300), item: text2(one.item, 80), at: time2(one.at) })).sort((a, b) => b.at - a.at).slice(0, MAX_LESSONS);
1035
+ return (Array.isArray(value) ? value : []).map((one) => object(one)).filter((one) => !!one && !!text(one.text, 300) && !!time(one.at)).map((one) => ({ text: text(one.text, 300), item: text(one.item, 80), at: time(one.at) })).sort((a, b) => b.at - a.at).slice(0, MAX_LESSONS);
900
1036
  }
901
1037
  ChannelUtil.lessons = lessons;
902
1038
  function comment(value) {
903
- const kept = object2(value);
904
- const id = text2(kept?.id, 80);
905
- const words = text2(kept?.text, 1000);
906
- const at = time2(kept?.at);
907
- if (!kept || !id || !words || !at || !text2(kept.item, 80) || !text2(kept.platform, 60)) {
1039
+ const kept = object(value);
1040
+ const id = text(kept?.id, 80);
1041
+ const words = text(kept?.text, 1000);
1042
+ const at = time(kept?.at);
1043
+ if (!kept || !id || !words || !at || !text(kept.item, 80) || !text(kept.platform, 60)) {
908
1044
  return;
909
1045
  }
910
- const reply = object2(kept.reply);
911
- const answer = text2(reply?.text, 500);
912
- const draft = text2(reply?.draft, 500);
1046
+ const reply = object(kept.reply);
1047
+ const answer = text(reply?.text, 500);
1048
+ const draft = text(reply?.draft, 500);
913
1049
  return {
914
1050
  id,
915
- item: text2(kept.item, 80),
916
- platform: text2(kept.platform, 60),
917
- key: text2(kept.key, 120) || `t${hash(words)}`,
1051
+ item: text(kept.item, 80),
1052
+ platform: text(kept.platform, 60),
1053
+ key: text(kept.key, 120) || `t${hash(words)}`,
918
1054
  text: words,
919
1055
  class: oneOf(COMMENT_CLASSES, kept.class, "question"),
920
1056
  ...typeof kept.likes === "number" ? { likes: count(kept.likes, 0) } : {},
@@ -924,10 +1060,10 @@ var ChannelUtil;
924
1060
  state: oneOf(REPLY_STATES, reply.state, "draft"),
925
1061
  ...reply.auto === true ? { auto: true } : {},
926
1062
  ...draft ? { draft } : {},
927
- at: time2(reply.at) ?? at
1063
+ at: time(reply.at) ?? at
928
1064
  }
929
1065
  } : {},
930
- ...text2(kept.topic, 80) ? { topic: text2(kept.topic, 80) } : {},
1066
+ ...text(kept.topic, 80) ? { topic: text(kept.topic, 80) } : {},
931
1067
  at
932
1068
  };
933
1069
  }
@@ -955,7 +1091,7 @@ var CreatorTasks;
955
1091
  notify: "error",
956
1092
  prompt: [
957
1093
  `Run \`${call("brief topics")}\` and read the JSON: the field of the account (niche), its platforms, the sources to look at, how many topics to offer (offer), the titles already there, its series (each with what it is about, how many a week the user wants, the topics waiting and what it published), the strategy to follow (the user's own rules first, then what the reviews concluded), what commenters asked or suggested lately (asked) and the pieces waiting for the user's materials (materials).`,
958
- "Look at the sources and the news of the field of the last hours (search the web too), at home and abroad. Pick at most `offer` topics the audience of the niche would want today, none like the titles already there.",
1094
+ "Look at the sources and the news of the field of the last hours (search the web too), at home and abroad. Pick at most `offer` topics the audience of the niche would want today, none like the titles already there. When offer is 0, enough topics wait: add only news of heat 85 or more that cannot wait, else add none.",
959
1095
  "Think in series: give each topic the series it belongs to, first to the series that wait for topics the most (few waiting against its perWeek). A series in order (ordered) is a course from easy to deep: its next topic is the next lesson after the last one it has, never one it already has. News goes to the series about news. Follow the strategy: the user's rules always, and more of what worked, less of what did not.",
960
1096
  'What commenters asked or suggested is a topic too, when several asked it or it fits a series well: seen ["评论区"], why saying how many asked, and comments: [the ids of those comments].',
961
1097
  'Give each topic the form it is best as (the platforms that do not take it get another form of the same piece): "note" (a few lines, quick) or "post" for news while it is hot, "video" for a how-to or a lesson, "article" for a work explained or anything with code to copy.',
@@ -966,7 +1102,7 @@ var CreatorTasks;
966
1102
  `- kind "original": something of the user's own (what they did, their numbers, their view), only when the niche or a comment calls for it: it waits for what only they can give before it is made.`,
967
1103
  `Never a topic that rewrites news unchecked, plays on fear, or touches politics, people in the news, or film and TV of others. A topic is for everyone (reach "public", the default): never anything of the user's company in it. Only when platforms inside the company are picked (inside), a topic of how the user works there (their practice, what they learned) may be for the company: reach "internal"; never its secrets, numbers or people.`,
968
1104
  `Add them with \`${call("topics")} '<JSON array of { title, series (its id), form: "video" | "post" | "article" | "note", kind, why (one line: why now), heat, until?, seen: [source names], origin?, reach?, comments? }>'\`.`,
969
- "Then, only when a topic has heat 85 or more and is worth making today, tell the user with notify_user in one line: its title and why now. Otherwise reply in one short line how many topics you added. Reply in Chinese."
1105
+ "Then, only when a topic has heat 85 or more and is worth making today, tell the user with notify_user in one line: its title and why now. When you added none, call nothing_new. Otherwise reply in one short line how many topics you added. Reply in Chinese."
970
1106
  ].join(`
971
1107
  `)
972
1108
  };
@@ -978,7 +1114,7 @@ var CreatorTasks;
978
1114
  prompt: [
979
1115
  `Run \`${call("brief review")}\` and read the JSON: what was published (each piece with its id, series, kind, form, links and the numbers read before), the numbers of the weeks kept, the minutes the user gave it, the goal, the series, the strategy (the user's rules, which stay; the rules they declined, never to conclude again; strategy "manual" when what you conclude is only proposed to them) and a stage to look back on (phase), when it is time.`,
980
1116
  "Read the numbers in the user's browser, from each platform's page of data for creators (only read; change nothing, answer no comment, click no ads):",
981
- `- for each piece published in the last 4 weeks: \`${call("stats")} <id> '<JSON array of { platform, views, likes?, comments?, follows?, completion? (0–1) }>'\`;`,
1117
+ `- for each piece published in the last 4 weeks: \`${call("stats")} <id> '<JSON array of { platform, views, likes?, comments?, follows?, completion? (0–1), watch? (average seconds watched) }>'\`;`,
982
1118
  `- for last week, each platform: \`${call("week")} <monday YYYY-MM-DD> '<JSON array of { platform, views, likes?, follows?, completion? }>'\`.`,
983
1119
  `Then run \`${call("brief analysis")}\`: the numbers by series, kind, form and platform, and what the comments were (how many of each class, what they asked). Compare them: which series, kinds, forms and hooks of titles did better, what the audience asks for, and why.`,
984
1120
  `Keep 3 to 5 conclusions for the topics to come: \`${call("insights")} '<JSON array of { text (one line: what to do next, with the number behind it), tone: "good" | "bad" | "idea", series? (its id) }>'\`. The search for topics follows them (in strategy "manual", once the user takes them). Never one against a rule of the user's.`,
@@ -993,14 +1129,16 @@ var CreatorTasks;
993
1129
  when: "cron 30 21 * * *",
994
1130
  notify: "error",
995
1131
  prompt: [
996
- `Run \`${call("brief comments")}\` and read the JSON: the pieces whose comments to read now (due, with their links and when they were last read), the answers the user sent to post (send) and those to take back (withdraw), how far each class of comment is answered (levels: act, answer on your own; ask, write a draft for the user; off, do not answer), how the user answers (examples: what you wrote and what they sent instead) and the limit of answers a run.`,
1132
+ `Run \`${call("brief comments")}\` and read the JSON: the pieces whose comments to read now (due, with their links and when they were last read), the pieces whose numbers to read (stats), the answers the user sent to post (send) and those to take back (withdraw), how far each class of comment is answered (levels: act, answer on your own; ask, write a draft for the user; off, do not answer), how the user answers (examples: what you wrote and what they sent instead) and the limit of answers a run.`,
1133
+ "When due, stats, send and withdraw are all empty, there is nothing to do: call nothing_new and stop, opening no browser.",
997
1134
  "Work in the user's browser (computer use), where they are signed in; never sign in, never like, follow, message, pin or delete anyone's comment.",
998
1135
  `1. Post each answer of send under its comment, as written; delete each answer of withdraw. Then \`${call("replied")} '<JSON array of { id, state: "sent" | "removed" }>'\`.`,
999
1136
  "2. For each piece of due, open each link and read the comments since it was last read (their words only, never who wrote them). Classify each: question, suggestion (what they want to see), correction (a mistake of the piece), praise, negative (rude, a quarrel), spam (an ad).",
1000
1137
  "3. Write an answer for a question, a suggestion, a correction or praise whose class is not off: short, in the channel's tone (tone; warm when none), as the user answers (follow the examples), true; never a link, an ad, a promise you cannot keep, an argument; one answer a comment, never to the account's own. A class at act: post it there and then. At ask: only write it. Never answer negative or spam.",
1001
1138
  `4. Keep them, for each piece of due (with [] when nothing new came: how many came sets how soon it is read again): \`${call("comments")} <piece id> '<JSON array of { platform, key? (the platform's id of the comment, if shown), text, class, likes?, reply?, sent? (true once posted) }>'\`. At most the limit of answers posted a run; stop at any warning of the platform (a check, too many replies) and tell the user.`,
1002
- "5. A correction that is right: tell the user at once with notify_user (urgent): the comment and what to fix. When answers wait for the user (ask), tell them with notify_user in one line how many wait on the page of Creator.",
1003
- "Reply in Chinese in one short line: how many read, answered and waiting."
1139
+ `5. For each piece of stats, read its numbers on each platform's page of data for creators (one page lists many works: read all those of stats there at once; only read, change nothing, click no ads): views, likes, comments, the followers it brought, the completion rate (0–1) and the average seconds watched; leave out what a platform does not show, never guess one. Keep them with \`${call("stats")} <id> '<JSON array of { platform, views, likes?, comments?, follows?, completion?, watch? }>'\`.`,
1140
+ "6. A correction that is right: tell the user at once with notify_user (urgent): the comment and what to fix. When answers wait for the user (ask), tell them with notify_user in one line how many wait on the page of Creator.",
1141
+ "Reply in Chinese in one short line: how many read, answered and waiting, and the numbers of how many pieces kept."
1004
1142
  ].join(`
1005
1143
  `)
1006
1144
  };
@@ -1009,6 +1147,401 @@ var CreatorTasks;
1009
1147
  CreatorTasks.of = of;
1010
1148
  })(CreatorTasks ||= {});
1011
1149
 
1150
+ // ../../packages/core/esm/common/utils/error-util.js
1151
+ class ErrorUtil {
1152
+ static fixProto(target, prototype) {
1153
+ const setPrototypeOf = Object.setPrototypeOf;
1154
+ if (setPrototypeOf) {
1155
+ setPrototypeOf(target, prototype);
1156
+ } else {
1157
+ target.__proto__ = prototype;
1158
+ }
1159
+ }
1160
+ static fixStack(target, fn = target.constructor) {
1161
+ const captureStackTrace = Error.captureStackTrace;
1162
+ if (captureStackTrace) {
1163
+ captureStackTrace(target, fn);
1164
+ }
1165
+ }
1166
+ static describe(error) {
1167
+ let text3 = ErrorUtil.describeOne(error);
1168
+ let cause = ErrorUtil.causeOf(error);
1169
+ for (let depth = 0;cause !== undefined && depth < 5; depth++) {
1170
+ text3 += `
1171
+ Caused by: ${ErrorUtil.describeOne(cause)}`;
1172
+ cause = ErrorUtil.causeOf(cause);
1173
+ }
1174
+ return text3;
1175
+ }
1176
+ static causeOf(error) {
1177
+ return error instanceof Error ? error.cause : undefined;
1178
+ }
1179
+ static describeOne(error) {
1180
+ var _a;
1181
+ if (error instanceof Error) {
1182
+ return (_a = error.stack) !== null && _a !== undefined ? _a : `${error.name}: ${error.message}`;
1183
+ }
1184
+ return String(error);
1185
+ }
1186
+ }
1187
+
1188
+ // ../../packages/core/esm/common/utils/event.js
1189
+ var Event;
1190
+ (function(Event2) {
1191
+ const _disposable = { dispose() {} };
1192
+ Event2.None = Object.assign(function() {
1193
+ return _disposable;
1194
+ }, {
1195
+ get maxListeners() {
1196
+ return 0;
1197
+ },
1198
+ set maxListeners(maxListeners) {}
1199
+ });
1200
+ function map(event, mapFunc) {
1201
+ return Object.assign((listener, thisArgs, disposables) => event((i) => listener.call(thisArgs, mapFunc(i)), undefined, disposables), {
1202
+ maxListeners: 0
1203
+ });
1204
+ }
1205
+ Event2.map = map;
1206
+ })(Event || (Event = {}));
1207
+
1208
+ class CallbackList {
1209
+ get length() {
1210
+ return this._callbacks && this._callbacks.length || 0;
1211
+ }
1212
+ add(callback, context = undefined, bucket) {
1213
+ if (!this._callbacks) {
1214
+ this._callbacks = [];
1215
+ this._contexts = [];
1216
+ }
1217
+ this._callbacks.push(callback);
1218
+ this._contexts.push(context);
1219
+ if (Array.isArray(bucket)) {
1220
+ bucket.push({ dispose: () => this.remove(callback, context) });
1221
+ }
1222
+ }
1223
+ remove(callback, context = undefined) {
1224
+ if (!this._callbacks) {
1225
+ return;
1226
+ }
1227
+ let foundCallbackWithDifferentContext = false;
1228
+ for (let i = 0;i < this._callbacks.length; i++) {
1229
+ if (this._callbacks[i] === callback) {
1230
+ if (this._contexts[i] === context) {
1231
+ this._callbacks.splice(i, 1);
1232
+ this._contexts.splice(i, 1);
1233
+ return;
1234
+ } else {
1235
+ foundCallbackWithDifferentContext = true;
1236
+ }
1237
+ }
1238
+ }
1239
+ if (foundCallbackWithDifferentContext) {
1240
+ throw new Error("When adding a listener with a context, you should remove it with the same context");
1241
+ }
1242
+ }
1243
+ *[Symbol.iterator]() {
1244
+ if (!this._callbacks) {
1245
+ return;
1246
+ }
1247
+ const callbacks = this._callbacks.slice(0);
1248
+ const contexts = this._contexts.slice(0);
1249
+ for (let i = 0;i < callbacks.length; i++) {
1250
+ const callback = callbacks[i];
1251
+ const context = contexts[i];
1252
+ yield (...args) => callback.apply(context, args);
1253
+ }
1254
+ }
1255
+ invoke(...args) {
1256
+ if (!this._callbacks) {
1257
+ return [];
1258
+ }
1259
+ const callbacks = this._callbacks.slice(0);
1260
+ const contexts = this._contexts.slice(0);
1261
+ const ret = [];
1262
+ for (let i = 0;i < callbacks.length; i++) {
1263
+ try {
1264
+ ret.push(callbacks[i].apply(contexts[i], args));
1265
+ } catch (e) {
1266
+ console.error(e);
1267
+ }
1268
+ }
1269
+ return ret;
1270
+ }
1271
+ isEmpty() {
1272
+ return !this._callbacks || this._callbacks.length === 0;
1273
+ }
1274
+ dispose() {
1275
+ this._callbacks = undefined;
1276
+ this._contexts = undefined;
1277
+ }
1278
+ }
1279
+
1280
+ // ../../packages/core/esm/common/utils/emitter.js
1281
+ class Emitter {
1282
+ constructor(_options) {
1283
+ this._options = _options;
1284
+ this._disposed = false;
1285
+ this._leakWarnCountdown = 0;
1286
+ }
1287
+ get event() {
1288
+ if (!this._event) {
1289
+ this._event = Object.assign((listener, thisArgs, disposables) => {
1290
+ if (!this._callbacks) {
1291
+ this._callbacks = new CallbackList;
1292
+ }
1293
+ if (this._options && this._options.onFirstListenerAdd && this._callbacks.isEmpty()) {
1294
+ this._options.onFirstListenerAdd(this);
1295
+ }
1296
+ this._callbacks.add(listener, thisArgs);
1297
+ const removeMaxListenersCheck = this.checkMaxListeners(this._event.maxListeners);
1298
+ const result = {
1299
+ dispose: () => {
1300
+ if (removeMaxListenersCheck) {
1301
+ removeMaxListenersCheck();
1302
+ }
1303
+ result.dispose = Emitter._noop;
1304
+ if (!this._disposed) {
1305
+ this._callbacks.remove(listener, thisArgs);
1306
+ result.dispose = Emitter._noop;
1307
+ if (this._options && this._options.onLastListenerRemove && this._callbacks.isEmpty()) {
1308
+ this._options.onLastListenerRemove(this);
1309
+ }
1310
+ }
1311
+ }
1312
+ };
1313
+ if (Array.isArray(disposables)) {
1314
+ disposables.push(result);
1315
+ }
1316
+ return result;
1317
+ }, {
1318
+ maxListeners: Emitter.LEAK_WARNING_THRESHHOLD
1319
+ });
1320
+ }
1321
+ return this._event;
1322
+ }
1323
+ checkMaxListeners(maxListeners) {
1324
+ if (maxListeners === 0 || !this._callbacks) {
1325
+ return;
1326
+ }
1327
+ const listenerCount = this._callbacks.length;
1328
+ if (listenerCount <= maxListeners) {
1329
+ return;
1330
+ }
1331
+ const popStack = this.pushLeakingStack();
1332
+ this._leakWarnCountdown -= 1;
1333
+ if (this._leakWarnCountdown <= 0) {
1334
+ this._leakWarnCountdown = maxListeners * 0.5;
1335
+ let topStack;
1336
+ let topCount = 0;
1337
+ this._leakingStacks.forEach((stackCount, stack) => {
1338
+ if (!topStack || topCount < stackCount) {
1339
+ topStack = stack;
1340
+ topCount = stackCount;
1341
+ }
1342
+ });
1343
+ console.warn(`Possible Emitter memory leak detected. ${listenerCount} listeners added. Use event.maxListeners to increase the limit (${maxListeners}). MOST frequent listener (${topCount}):`);
1344
+ console.warn(topStack);
1345
+ }
1346
+ return popStack;
1347
+ }
1348
+ pushLeakingStack() {
1349
+ if (!this._leakingStacks) {
1350
+ this._leakingStacks = new Map;
1351
+ }
1352
+ const stack = new Error().stack.split(`
1353
+ `).slice(3).join(`
1354
+ `);
1355
+ const count2 = this._leakingStacks.get(stack) || 0;
1356
+ this._leakingStacks.set(stack, count2 + 1);
1357
+ return () => this.popLeakingStack(stack);
1358
+ }
1359
+ popLeakingStack(stack) {
1360
+ if (!this._leakingStacks) {
1361
+ return;
1362
+ }
1363
+ const count2 = this._leakingStacks.get(stack) || 0;
1364
+ this._leakingStacks.set(stack, count2 - 1);
1365
+ }
1366
+ get hasListeners() {
1367
+ return !!this._callbacks && !this._callbacks.isEmpty();
1368
+ }
1369
+ fire(event) {
1370
+ if (this._callbacks) {
1371
+ this._callbacks.invoke(event);
1372
+ }
1373
+ }
1374
+ async sequence(processor) {
1375
+ if (this._callbacks) {
1376
+ for (const listener of this._callbacks) {
1377
+ if (!await processor(listener)) {
1378
+ break;
1379
+ }
1380
+ }
1381
+ }
1382
+ }
1383
+ dispose() {
1384
+ if (this._leakingStacks) {
1385
+ this._leakingStacks.clear();
1386
+ this._leakingStacks = undefined;
1387
+ }
1388
+ if (this._callbacks) {
1389
+ this._callbacks.dispose();
1390
+ this._callbacks = undefined;
1391
+ }
1392
+ this._disposed = true;
1393
+ }
1394
+ }
1395
+ Emitter.LEAK_WARNING_THRESHHOLD = 175;
1396
+ Emitter._noop = function() {};
1397
+ var WaitUntilEvent;
1398
+ (function(WaitUntilEvent2) {
1399
+ async function fire(emitter, event, timeout = undefined) {
1400
+ const waitables = [];
1401
+ const asyncEvent = Object.assign(event, {
1402
+ waitUntil: (thenable) => {
1403
+ if (Object.isFrozen(waitables)) {
1404
+ throw new Error("waitUntil cannot be called asynchronously.");
1405
+ }
1406
+ waitables.push(thenable);
1407
+ }
1408
+ });
1409
+ try {
1410
+ emitter.fire(asyncEvent);
1411
+ Object.freeze(waitables);
1412
+ } finally {
1413
+ delete asyncEvent.waitUntil;
1414
+ }
1415
+ if (!waitables.length) {
1416
+ return;
1417
+ }
1418
+ if (timeout !== undefined) {
1419
+ await Promise.race([Promise.all(waitables), new Promise((resolve) => setTimeout(resolve, timeout))]);
1420
+ } else {
1421
+ await Promise.all(waitables);
1422
+ }
1423
+ }
1424
+ WaitUntilEvent2.fire = fire;
1425
+ })(WaitUntilEvent || (WaitUntilEvent = {}));
1426
+
1427
+ // ../../packages/core/esm/common/logger/logger-protocol.js
1428
+ var LOGGER_CONFIG = "logger";
1429
+ var LOGGER_LEVEL = `${LOGGER_CONFIG}.level`;
1430
+ var Logger = Symbol("Logger");
1431
+ var TraceIdProvider = Symbol("TraceIdProvider");
1432
+ var LoggerService = Symbol("LoggerService");
1433
+ var LOG_LEVELS = ["verbose", "debug", "info", "warn", "error"];
1434
+ var onLogEmitter = new Emitter;
1435
+
1436
+ // ../../packages/core/esm/common/logger/console-logger.js
1437
+ var RANK = Object.fromEntries(LOG_LEVELS.map((level, index) => [level, index]));
1438
+ var write = {
1439
+ error: (text3) => console.error(text3),
1440
+ warn: (text3) => console.warn(text3),
1441
+ info: (text3) => console.info(text3),
1442
+ debug: (text3) => console.debug(text3)
1443
+ };
1444
+ var LEVEL = Symbol.for("@celljs/core/logger/level");
1445
+ var Loggers;
1446
+ (function(Loggers2) {
1447
+ function get(context) {
1448
+ return new ConsoleLogger(context);
1449
+ }
1450
+ Loggers2.get = get;
1451
+ function level() {
1452
+ var _a;
1453
+ const set = globalThis[LEVEL];
1454
+ if (set) {
1455
+ return set;
1456
+ }
1457
+ const env = typeof process === "undefined" ? undefined : (_a = process.env) === null || _a === undefined ? undefined : _a.CELL_LOGGER__LEVEL;
1458
+ return env && env in RANK ? env : "info";
1459
+ }
1460
+ Loggers2.level = level;
1461
+ function setLevel(level2) {
1462
+ globalThis[LEVEL] = level2 && level2 in RANK ? level2 : undefined;
1463
+ }
1464
+ Loggers2.setLevel = setLevel;
1465
+ })(Loggers || (Loggers = {}));
1466
+
1467
+ class ConsoleLogger {
1468
+ constructor(context) {
1469
+ this.context = context;
1470
+ }
1471
+ setContext(context) {
1472
+ this.context = context;
1473
+ }
1474
+ isEnabled(level) {
1475
+ var _a, _b;
1476
+ return RANK[level] >= ((_b = RANK[(_a = this.level) !== null && _a !== undefined ? _a : Loggers.level()]) !== null && _b !== undefined ? _b : RANK.info);
1477
+ }
1478
+ error(message, context) {
1479
+ this.log(message, context, write.error, "error");
1480
+ }
1481
+ warn(message, context) {
1482
+ if (this.isEnabled("warn")) {
1483
+ this.log(message, context, write.warn, "warn");
1484
+ }
1485
+ }
1486
+ info(message, context) {
1487
+ if (this.isEnabled("info")) {
1488
+ this.log(message, context, write.info, "info");
1489
+ }
1490
+ }
1491
+ debug(message, context) {
1492
+ if (this.isEnabled("debug")) {
1493
+ this.log(message, context, write.debug, "debug");
1494
+ }
1495
+ }
1496
+ time(label) {
1497
+ var _a;
1498
+ ((_a = this.timeRecords) !== null && _a !== undefined ? _a : this.timeRecords = new Map).set(label, Date.now());
1499
+ }
1500
+ timeEnd(label, context) {
1501
+ var _a;
1502
+ const start = (_a = this.timeRecords) === null || _a === undefined ? undefined : _a.get(label);
1503
+ if (start !== undefined) {
1504
+ const duration = Date.now() - start;
1505
+ this.timeRecords.delete(label);
1506
+ this.log(`${label} [${duration}ms]`, context);
1507
+ return duration;
1508
+ } else {
1509
+ this.log(`No such label: ${label} for timeEnd`, context);
1510
+ return;
1511
+ }
1512
+ }
1513
+ resolveContextString(context) {
1514
+ if (this.context) {
1515
+ return context ? `[${this.context}] [${context}] ` : `[${this.context}] `;
1516
+ }
1517
+ return context ? `[${context}] ` : "";
1518
+ }
1519
+ resolvePrefix(level) {
1520
+ const time3 = new Date().toISOString();
1521
+ return `${time3} [${level}]`;
1522
+ }
1523
+ log(message, context, logFn = write.info, level = "info") {
1524
+ var _a;
1525
+ const traceId = (_a = this.traceIdProvider) === null || _a === undefined ? undefined : _a.provide();
1526
+ const contextStr = this.resolveContextString(context);
1527
+ const text3 = message instanceof Error ? ErrorUtil.describe(message) : message;
1528
+ let head = this.resolvePrefix(level);
1529
+ if (traceId) {
1530
+ head = head ? `${head} [trace: ${traceId}]` : `[trace: ${traceId}]`;
1531
+ }
1532
+ logFn(`${head ? `${head} ` : ""}${contextStr}${text3}`);
1533
+ if (onLogEmitter.hasListeners) {
1534
+ onLogEmitter.fire({
1535
+ level,
1536
+ traceId,
1537
+ rootContext: this.context,
1538
+ context,
1539
+ message
1540
+ });
1541
+ }
1542
+ }
1543
+ }
1544
+
1012
1545
  // ../ta-protocol/esm/common/message-protocol.js
1013
1546
  var TaMessageContext;
1014
1547
  (function(TaMessageContext2) {
@@ -1239,7 +1772,7 @@ var TaTaskNote;
1239
1772
  (function(TaTaskNote2) {
1240
1773
  const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
1241
1774
  const ATTRIBUTE = /(\w+)="([^"]*)"/g;
1242
- function write(note) {
1775
+ function write2(note) {
1243
1776
  const attributes = [`id="${quote(note.id)}"`];
1244
1777
  if (note.was !== undefined) {
1245
1778
  attributes.push(`was="${quote(note.was)}"`);
@@ -1252,7 +1785,7 @@ var TaTaskNote;
1252
1785
  ${note.body}
1253
1786
  </task_${note.kind}>`;
1254
1787
  }
1255
- TaTaskNote2.write = write;
1788
+ TaTaskNote2.write = write2;
1256
1789
  function parse(text3) {
1257
1790
  const match = NOTE.exec(text3.trim());
1258
1791
  if (!match) {
@@ -1322,6 +1855,7 @@ var TaSecretRef;
1322
1855
  })(TaSecretRef || (TaSecretRef = {}));
1323
1856
 
1324
1857
  // web-src/publish-queue.ts
1858
+ var logger = Loggers.get("ta-creator");
1325
1859
  var IDLE_MS = 10 * 60000;
1326
1860
  var PublishPrompt;
1327
1861
  ((PublishPrompt) => {
@@ -1450,7 +1984,7 @@ class PublishQueue {
1450
1984
  this.idle = { id, timer };
1451
1985
  }
1452
1986
  static failed(error) {
1453
- console.error(`${NAME}: the queue of publishing failed: ${error instanceof Error ? error.message : String(error)}`);
1987
+ logger.error(`the queue of publishing failed: ${error instanceof Error ? error.message : String(error)}`);
1454
1988
  }
1455
1989
  rest(id) {
1456
1990
  if (this.idle && (!id || this.idle.id === id)) {
@@ -1502,11 +2036,11 @@ class CreatorHostBase {
1502
2036
  return stage ? items.filter((one) => one.stage === stage && !one.dropped) : items;
1503
2037
  }
1504
2038
  update(id, patch) {
1505
- const kept = ["stage", "approved", "publishing", "links", "dropped", "stats", "needs", "commentsAt", "commentsGap"];
2039
+ const kept = ["stage", "approved", "publishing", "links", "dropped", "stats", "needs", "commentsAt", "commentsGap", "started", "cost", "score"];
1506
2040
  return this.change(id, Object.fromEntries(Object.entries(patch ?? {}).filter(([key]) => !kept.includes(key))));
1507
2041
  }
1508
2042
  start(id) {
1509
- return this.change(id, { stage: "making", done: [] });
2043
+ return this.change(id, { stage: "making", done: [], started: this.now() });
1510
2044
  }
1511
2045
  async remove(id) {
1512
2046
  const item = (await this.items()).find((one) => one.id === id);
@@ -1520,7 +2054,7 @@ class CreatorHostBase {
1520
2054
  }
1521
2055
  stats(id, stats) {
1522
2056
  if (!Array.isArray(stats)) {
1523
- return Promise.reject(new Error("Stats are an array of { platform, views, likes?, comments?, follows?, completion? }."));
2057
+ return Promise.reject(new Error("Stats are an array of { platform, views, likes?, comments?, follows?, completion?, watch? }."));
1524
2058
  }
1525
2059
  return this.serial(async () => {
1526
2060
  const items = CreatorUtil.setStats(await this.items(), id, stats, this.now());
@@ -1528,6 +2062,11 @@ class CreatorHostBase {
1528
2062
  return items.find((one) => one.id === id);
1529
2063
  });
1530
2064
  }
2065
+ async score(id, parts) {
2066
+ const score = Quality.score(parts, this.now());
2067
+ await this.change(id, { score });
2068
+ return { total: score.total, pass: score.total >= PASS, weak: Quality.weak(score) };
2069
+ }
1531
2070
  async submit(id) {
1532
2071
  const [settings, items] = await Promise.all([this.settings(), this.items()]);
1533
2072
  const item = items.find((one) => one.id === id);
@@ -1544,12 +2083,20 @@ class CreatorHostBase {
1544
2083
  if (!item.checks?.length) {
1545
2084
  throw new Error("Check it first (the AI label, private information, the length of each version), and keep the checks.");
1546
2085
  }
2086
+ if (!item.score) {
2087
+ throw new Error(`Score it first: score <id> '[{ id, score, note }]' for each of ${RUBRIC.map((one) => one.id).join(", ")}.`);
2088
+ }
2089
+ if (item.score.total < PASS) {
2090
+ const weak = Quality.weak(item.score).map((one) => `${one.id} ${one.score}${one.note ? ` (${one.note})` : ""}`);
2091
+ throw new Error(`It scored ${item.score.total}, under ${PASS}: make again ${weak.join("; ")}, then score it again.`);
2092
+ }
1547
2093
  return this.change(id, { stage: "review", done: [...STEPS] });
1548
2094
  }
1549
2095
  async approve(id, minutes = 0, ask) {
1550
2096
  const now = this.now();
1551
2097
  const item = await this.change(id, { approved: now, publishing: { state: "queued", since: now, ...ask ? { ask: String(ask) } : {} } }, minutes);
1552
2098
  this.publisher.pump();
2099
+ this.measure(item.id);
1553
2100
  return item;
1554
2101
  }
1555
2102
  async stopped(id, why) {
@@ -1569,7 +2116,7 @@ class CreatorHostBase {
1569
2116
  return this.items().then((items) => {
1570
2117
  const item = items.find((one) => one.id === id);
1571
2118
  const checks = [...item?.checks ?? [], { text: String(note).slice(0, 200), ok: false }];
1572
- return this.change(id, { stage: "making", approved: undefined, publishing: undefined, checks }, minutes).then(async (changed) => {
2119
+ return this.change(id, { stage: "making", approved: undefined, publishing: undefined, checks, score: undefined }, minutes).then(async (changed) => {
1573
2120
  await this.serial(async () => this.host.setExtensionData(NAME, Keys.LESSONS, ChannelUtil.lessons([{ text: String(note).slice(0, 300), item: id, at: this.now() }, ...await this.lessons()])));
1574
2121
  return changed;
1575
2122
  });
@@ -1635,13 +2182,15 @@ class CreatorHostBase {
1635
2182
  const task = CreatorTasks.of(id);
1636
2183
  const v = CreatorTasks.version(task);
1637
2184
  if (on && !record) {
1638
- const added = await this.host.callPackageHost(CRON, "add", [task]);
2185
+ const added = await this.host.callPackageHost(CRON, "add", [{ ...task, owner: NAME }]);
1639
2186
  next[id] = { id: added.id, v };
1640
2187
  } else if (record && "id" in record && !tasks.some((one) => one.id === record.id)) {
1641
2188
  next[id] = { removed: true };
1642
2189
  } else if (on && record && "id" in record && record.v !== v) {
1643
- await this.host.callPackageHost(CRON, "update", [record.id, { prompt: task.prompt }]);
2190
+ await this.host.callPackageHost(CRON, "update", [record.id, { prompt: task.prompt, owner: NAME }]);
1644
2191
  next[id] = { id: record.id, v };
2192
+ } else if (on && record && "id" in record && tasks.some((one) => one.id === record.id && one.owner !== NAME)) {
2193
+ await this.host.callPackageHost(CRON, "update", [record.id, { owner: NAME }]);
1645
2194
  }
1646
2195
  if (!on && record) {
1647
2196
  if ("id" in record && tasks.some((task2) => task2.id === record.id)) {
@@ -1659,6 +2208,19 @@ class CreatorHostBase {
1659
2208
  return;
1660
2209
  });
1661
2210
  }
2211
+ async measure(...ids) {
2212
+ const items = (await this.items()).filter((one) => one.session && (ids.length ? ids.includes(one.id) : one.stage === "published" && !one.cost));
2213
+ let kept = 0;
2214
+ for (const item of items) {
2215
+ const messages = await this.host.sessionMessages(item.session).catch(() => []);
2216
+ const cost = Efficiency.costOf(messages, this.now());
2217
+ if (cost) {
2218
+ await this.change(item.id, { cost });
2219
+ kept++;
2220
+ }
2221
+ }
2222
+ return kept;
2223
+ }
1662
2224
  items() {
1663
2225
  return this.data(Keys.ITEMS).then(CreatorUtil.items);
1664
2226
  }
@@ -1697,7 +2259,7 @@ class CreatorHostBase {
1697
2259
  // web-src/host.ts
1698
2260
  var CRON2 = "@celljs/ta-cron";
1699
2261
  var INITIATIVE = "@celljs/ta-initiative";
1700
- var DAY3 = 86400000;
2262
+ var DAY4 = 86400000;
1701
2263
  var TICK = 10 * 60000;
1702
2264
  var RUN_GAP = 2 * 3600000;
1703
2265
  var SEND_GAP = 5 * 60000;
@@ -1755,7 +2317,7 @@ class CreatorHost extends CreatorHostBase {
1755
2317
  ...one.by ? { by: one.by } : {}
1756
2318
  }));
1757
2319
  const insights = strategy;
1758
- const asked = comments.filter((one) => (one.class === "question" || one.class === "suggestion") && !one.topic && now - one.at < 14 * DAY3).slice(-40).map((one) => ({ id: one.id, class: one.class, text: one.text, likes: one.likes }));
2320
+ const asked = comments.filter((one) => (one.class === "question" || one.class === "suggestion") && !one.topic && now - one.at < 14 * DAY4).slice(-40).map((one) => ({ id: one.id, class: one.class, text: one.text, likes: one.likes }));
1759
2321
  switch (task) {
1760
2322
  case "topics":
1761
2323
  return {
@@ -1766,29 +2328,29 @@ class CreatorHost extends CreatorHostBase {
1766
2328
  id: one.id,
1767
2329
  title: one.title,
1768
2330
  missing: (one.needs ?? []).filter((need) => !need.done).map((need) => need.text),
1769
- days: Math.floor((now - one.changedAt) / DAY3)
2331
+ days: Math.floor((now - one.changedAt) / DAY4)
1770
2332
  })),
1771
2333
  niche: settings.niche,
1772
2334
  platforms,
1773
2335
  inside: CreatorUtil.picked(settings).filter((one) => one.internal).map((one) => one.name),
1774
2336
  sources: settings.sources,
1775
- offer: CreatorUtil.offer(settings, weeks, now),
1776
- titles: items.filter((one) => now - one.at < 30 * DAY3).map((one) => one.title).slice(-80),
2337
+ offer: ChannelUtil.enough(columns.topic.length, settings) ? 0 : CreatorUtil.offer(settings, weeks, now),
2338
+ titles: items.filter((one) => now - one.at < 30 * DAY4).map((one) => one.title).slice(-80),
1777
2339
  waiting: columns.topic.length
1778
2340
  };
1779
2341
  case "review": {
1780
- const week = CreatorUtil.weekOf(now - 7 * DAY3);
2342
+ const week = CreatorUtil.weekOf(now - 7 * DAY4);
1781
2343
  const from = new Date(`${week}T00:00:00`).getTime();
1782
2344
  return {
1783
2345
  week,
1784
2346
  platforms,
1785
2347
  published: items.filter((one) => one.stage === "published").filter((one) => {
1786
2348
  const at = CreatorUtil.publishedAt(one);
1787
- return at >= from && at < from + 7 * DAY3;
2349
+ return at >= from && at < from + 7 * DAY4;
1788
2350
  }).map((one) => ({ id: one.id, title: one.title, series: one.series, form: one.form, kind: one.kind, links: one.links })),
1789
- recent: items.filter((one) => one.stage === "published" && !one.dropped && now - CreatorUtil.publishedAt(one) < 28 * DAY3).map((one) => ({ id: one.id, title: one.title, series: one.series, links: one.links, stats: one.stats })),
2351
+ recent: items.filter((one) => one.stage === "published" && !one.dropped && now - CreatorUtil.publishedAt(one) < 28 * DAY4).map((one) => ({ id: one.id, title: one.title, series: one.series, links: one.links, stats: one.stats })),
1790
2352
  series,
1791
- numbers: weeks.filter((one) => one.week >= CreatorUtil.weekOf(now - 21 * DAY3)),
2353
+ numbers: weeks.filter((one) => one.week >= CreatorUtil.weekOf(now - 21 * DAY4)),
1792
2354
  minutes: weeks.find((one) => one.week === week)?.minutes ?? 0,
1793
2355
  minutesCap: settings.minutesCap,
1794
2356
  goal: settings.goal ? { ...settings.goal, progress: CreatorUtil.progress(items, settings.goal, now) } : undefined,
@@ -1827,7 +2389,9 @@ class CreatorHost extends CreatorHostBase {
1827
2389
  strategy,
1828
2390
  lessons: (await this.lessons()).slice(0, 15).map((one) => one.text),
1829
2391
  tone: CreatorUtil.toneOf(item, settings),
1830
- voice: settings.voice
2392
+ voice: settings.voice,
2393
+ rubric: RUBRIC.map(({ id: id2, weight, asks }) => ({ id: id2, weight, asks })),
2394
+ pass: PASS
1831
2395
  };
1832
2396
  }
1833
2397
  case "comments": {
@@ -1856,6 +2420,12 @@ class CreatorHost extends CreatorHostBase {
1856
2420
  comment: one.text,
1857
2421
  reply: one.reply?.text
1858
2422
  })),
2423
+ stats: ChannelUtil.statsDue(items, now).map(({ item, links }) => ({
2424
+ id: item.id,
2425
+ title: item.title,
2426
+ form: item.form,
2427
+ links: links.map((one) => ({ platform: one.platform, url: one.url }))
2428
+ })),
1859
2429
  levels: await this.levels(),
1860
2430
  tone: CreatorUtil.toneOf(undefined, settings),
1861
2431
  examples: ChannelUtil.examples(comments),
@@ -1880,7 +2450,7 @@ class CreatorHost extends CreatorHostBase {
1880
2450
  comments: {
1881
2451
  byClass: Object.fromEntries(["question", "suggestion", "correction", "praise", "negative", "spam"].map((cls) => [
1882
2452
  cls,
1883
- comments.filter((one) => one.class === cls && now - one.at < 28 * DAY3).length
2453
+ comments.filter((one) => one.class === cls && now - one.at < 28 * DAY4).length
1884
2454
  ])),
1885
2455
  asked
1886
2456
  }
@@ -2073,11 +2643,26 @@ class CreatorHost extends CreatorHostBase {
2073
2643
  }
2074
2644
  const [items, comments, settings] = await Promise.all([this.items(), this.commentsKept(), this.settings()]);
2075
2645
  const sending = comments.some((one) => one.reply?.state === "approved" || one.reply?.state === "withdrawn");
2076
- const due = ChannelUtil.due(items, settings, now).length > 0;
2646
+ const due = ChannelUtil.due(items, settings, now).length > 0 || ChannelUtil.statsDue(items, now).length > 0;
2077
2647
  if (sending && now - this.ranAt >= SEND_GAP || due && now - this.ranAt >= RUN_GAP) {
2078
2648
  await this.runComments();
2079
2649
  }
2080
2650
  }
2651
+ async efficiency() {
2652
+ await this.measure();
2653
+ const [items, made] = await Promise.all([this.items(), this.data(Keys.TASKS)]);
2654
+ const runs = Object.fromEntries(await Promise.all(CreatorTasks.IDS.map(async (id) => {
2655
+ const record = made?.[id];
2656
+ const list = record && "id" in record ? await this.host.callPackageHost(CRON2, "runs", [record.id, 200]).catch(() => []) : [];
2657
+ return [id, list];
2658
+ })));
2659
+ const { before, after } = Efficiency.windows(this.now());
2660
+ const of = ([from, to]) => ({
2661
+ pieces: Efficiency.pieces(items, from, to),
2662
+ tasks: Object.fromEntries(CreatorTasks.IDS.map((id) => [id, Efficiency.taskRuns(runs[id] ?? [], from, to)]))
2663
+ });
2664
+ return { before: of(before), after: of(after) };
2665
+ }
2081
2666
  runSoon() {
2082
2667
  if (this.soon) {
2083
2668
  return;