@celljs/ta-creator 4.33.0 → 4.35.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
@@ -23,6 +23,16 @@ var FORM_FALLBACKS = {
23
23
  var KINDS = ["hot", "howto", "explain", "original"];
24
24
  var STEPS = ["script", "visuals", "voice", "captions", "versions", "checks"];
25
25
  var REACHES = ["public", "internal", "both"];
26
+ var TONES = {
27
+ humorous: "humorous: light and witty, a joke or a playful image where it helps, never at anyone's expense",
28
+ serious: "serious: plain and earnest, no jokes, no exaggeration, facts first",
29
+ rigorous: "rigorous: step by step, each claim with its reason or source, terms defined, no leaps",
30
+ warm: 'warm: like a friend explaining, "you" and "we", patient and encouraging',
31
+ lively: "lively: high energy, short punchy sentences, a strong hook and rhythm",
32
+ plain: "plain: everyday words, everyday examples, no jargon left unexplained",
33
+ story: "storytelling: a scene, a person or a moment first, the point drawn from it",
34
+ sharp: "sharp: a clear opinion, straight to the point, the counter-intuitive first, never rude"
35
+ };
26
36
  var SERIES_COLORS = ["#22c55e", "#f97316", "#3b82f6", "#a855f7", "#ec4899", "#14b8a6", "#eab308", "#64748b"];
27
37
  var ASPECTS = ["16:9", "9:16", "3:4", "1:1"];
28
38
  var PLATFORMS = [
@@ -133,10 +143,114 @@ var REPLY_KINDS = {
133
143
  }
134
144
  };
135
145
 
136
- // web-src/publish-util.ts
137
- 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) : [];
138
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;
139
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;
140
254
  var PublishUtil;
141
255
  ((PublishUtil) => {
142
256
  function dayOf(at) {
@@ -184,68 +298,54 @@ var PublishUtil;
184
298
  const at = new Date(value.trim().replace(" ", "T")).getTime();
185
299
  return Number.isFinite(at) ? at : undefined;
186
300
  }
187
- return time(value);
301
+ return time2(value);
188
302
  }
189
303
  PublishUtil.timeOf = timeOf;
304
+ function of(piece) {
305
+ const approved = time2(piece.approved);
306
+ return publishing(piece.publishing) ?? (piece.stage === "review" && approved && !piece.publishing ? { state: "queued", since: approved } : undefined);
307
+ }
308
+ PublishUtil.of = of;
190
309
  function publishing(value) {
191
- const kept = object(value);
192
- const since = time(kept?.since);
310
+ const kept = object2(value);
311
+ const since = time2(kept?.since);
193
312
  const state = kept && ["queued", "running", "stopped"].find((one) => one === kept.state);
194
313
  if (!kept || !since || !state) {
195
314
  return;
196
315
  }
197
- 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;
198
317
  return {
199
318
  state,
200
319
  since,
201
320
  ...slots2 ? { slots: slots2 } : {},
202
- ...text(kept.note, 300) ? { note: text(kept.note, 300) } : {},
203
- ...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) } : {}
204
323
  };
205
324
  }
206
325
  PublishUtil.publishing = publishing;
207
326
  })(PublishUtil ||= {});
208
327
 
209
- // web-src/values.ts
210
- var text2 = (value, max = 2000) => typeof value === "string" ? value.trim().slice(0, max) : "";
211
- var texts = (value, max = 50) => Array.isArray(value) ? value.map((one) => text2(one, 200)).filter(Boolean).slice(0, max) : [];
212
- var time2 = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined;
213
- var oneOf = (all, value, fallback) => all.includes(value) ? value : fallback;
214
- var object2 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
215
- function hash(value) {
216
- let h = 0;
217
- for (const char of value) {
218
- h = Math.imul(h, 31) + (char.codePointAt(0) ?? 0) | 0;
219
- }
220
- return (h >>> 0).toString(36);
221
- }
222
- function url(value) {
223
- const raw = text2(value, 1000);
224
- return /^https?:\/\/\S+$/i.test(raw) ? raw : undefined;
225
- }
226
- function count(value, fallback) {
227
- return typeof value === "number" && Number.isFinite(value) && value >= 0 ? Math.round(value) : fallback;
228
- }
229
-
230
328
  // web-src/creator-util.ts
231
- var DAY = 86400000;
329
+ var DAY2 = 86400000;
232
330
  var MAX_TOPICS = 200;
233
- var HOT_FOR = 2 * DAY;
331
+ var HOT_FOR = 2 * DAY2;
332
+ var MAX_TONES = 3;
234
333
  var CreatorUtil;
235
334
  ((CreatorUtil) => {
236
335
  function settings(value) {
237
- const kept = object2(value) ?? {};
336
+ const kept = object(value) ?? {};
238
337
  const platforms = Array.isArray(kept.platforms) ? withBuiltins(kept.platforms.map(platform).filter((one) => !!one)) : [...PLATFORMS];
239
338
  const ids = new Set(platforms.map((one) => one.id));
240
- const goal = object2(kept.goal);
339
+ const goal = object(kept.goal);
241
340
  return {
242
- niche: text2(kept.niche, 500),
341
+ niche: text(kept.niche, 500),
243
342
  picked: texts(kept.picked).filter((id) => ids.has(id)),
244
343
  platforms,
245
344
  sources: Array.isArray(kept.sources) ? kept.sources.map(source).filter((one) => !!one) : [...SOURCES],
246
- ...goal && time2(goal.from) ? { goal: { from: time2(goal.from), days: count(goal.days, 30), videos: count(goal.videos, 0), posts: count(goal.posts, 0) } } : {},
345
+ ...goal && time(goal.from) ? { goal: { from: time(goal.from), days: count(goal.days, 30), videos: count(goal.videos, 0), posts: count(goal.posts, 0) } } : {},
247
346
  minutesCap: count(kept.minutesCap, 120),
248
- voice: text2(kept.voice, 60) || "zh-CN-XiaoxiaoNeural",
347
+ voice: text(kept.voice, 60) || "zh-CN-XiaoxiaoNeural",
348
+ tone: tones(kept.tone),
249
349
  series: Array.isArray(kept.series) ? seriesOf(kept.series) : [],
250
350
  strategy: kept.strategy === "manual" ? "manual" : "auto",
251
351
  phaseWeeks: typeof kept.phaseWeeks === "number" ? Math.min(26, count(kept.phaseWeeks, 4)) : 4,
@@ -267,6 +367,17 @@ var CreatorUtil;
267
367
  return [...known, ...PLATFORMS.filter((one) => !kept.some((it) => it.id === one.id))];
268
368
  }
269
369
  CreatorUtil.withBuiltins = withBuiltins;
370
+ function tones(value) {
371
+ return [
372
+ ...new Set(texts(value).map((one) => text(one, 20)).filter(Boolean))
373
+ ].slice(0, MAX_TONES);
374
+ }
375
+ CreatorUtil.tones = tones;
376
+ function toneOf(item2, settings2) {
377
+ const own = settings2.series.find((one) => one.id === item2?.series)?.tone;
378
+ return (own ? [own] : settings2.tone).map((one) => (one in TONES) ? TONES[one] : one);
379
+ }
380
+ CreatorUtil.toneOf = toneOf;
270
381
  function reach(item2, settings2) {
271
382
  return item2.reach ?? settings2.series.find((one) => one.id === item2.series)?.reach ?? "public";
272
383
  }
@@ -291,60 +402,62 @@ var CreatorUtil;
291
402
  function seriesOf(values) {
292
403
  const all = [];
293
404
  for (const value of values) {
294
- const kept = object2(value);
295
- const name = text2(kept?.name, 40);
405
+ const kept = object(value);
406
+ const name = text(kept?.name, 40);
296
407
  if (!kept || !name) {
297
408
  continue;
298
409
  }
299
- const id = text2(kept.id, 60) || `s${hash(name)}`;
410
+ const id = text(kept.id, 60) || `s${hash(name)}`;
300
411
  if (all.some((one) => one.id === id)) {
301
412
  continue;
302
413
  }
303
- const about = text2(kept.about, 200);
414
+ const about = text(kept.about, 200);
304
415
  const perWeek = count(kept.perWeek, 0);
416
+ const tone = text(kept.tone, 20);
305
417
  all.push({
306
418
  id,
307
419
  name,
308
420
  ...about ? { about } : {},
309
- color: text2(kept.color, 40) || SERIES_COLORS[all.length % SERIES_COLORS.length],
421
+ color: text(kept.color, 40) || SERIES_COLORS[all.length % SERIES_COLORS.length],
310
422
  ...kept.ordered === true ? { ordered: true } : {},
311
423
  ...perWeek ? { perWeek: Math.min(perWeek, 14) } : {},
312
- ...kept.reach === "internal" || kept.reach === "both" ? { reach: kept.reach } : {}
424
+ ...kept.reach === "internal" || kept.reach === "both" ? { reach: kept.reach } : {},
425
+ ...tone ? { tone } : {}
313
426
  });
314
427
  }
315
428
  return all.slice(0, 12);
316
429
  }
317
430
  CreatorUtil.seriesOf = seriesOf;
318
431
  function platform(value) {
319
- const kept = object2(value);
320
- const id = text2(kept?.id, 60);
321
- const name = text2(kept?.name, 60);
432
+ const kept = object(value);
433
+ const id = text(kept?.id, 60);
434
+ const name = text(kept?.name, 60);
322
435
  if (!kept || !id || !name) {
323
436
  return;
324
437
  }
325
438
  const shape = (one) => {
326
- const it = object2(one);
439
+ const it = object(one);
327
440
  return it ? { aspect: oneOf(ASPECTS, it.aspect, "16:9"), ...count(it.maxSeconds, 0) ? { maxSeconds: count(it.maxSeconds, 0) } : {} } : undefined;
328
441
  };
329
442
  const video = shape(kept.video);
330
- const post = object2(kept.post) ? {
331
- aspect: oneOf(ASPECTS, object2(kept.post)?.aspect, "3:4"),
332
- ...count(object2(kept.post)?.maxImages, 0) ? { maxImages: count(object2(kept.post)?.maxImages, 0) } : {}
443
+ const post = object(kept.post) ? {
444
+ aspect: oneOf(ASPECTS, object(kept.post)?.aspect, "3:4"),
445
+ ...count(object(kept.post)?.maxImages, 0) ? { maxImages: count(object(kept.post)?.maxImages, 0) } : {}
333
446
  } : undefined;
334
447
  const words = (one) => {
335
- const it = object2(one);
448
+ const it = object(one);
336
449
  return it ? count(it.maxChars, 0) ? { maxChars: count(it.maxChars, 0) } : {} : undefined;
337
450
  };
338
451
  const article = words(kept.article);
339
452
  const note = words(kept.note);
340
453
  const publish = url(kept.publish);
341
- const declare = text2(kept.declare, 200);
454
+ const declare = text(kept.declare, 200);
342
455
  const inside = kept.internal === true ? { internal: true } : {};
343
456
  return {
344
457
  ...inside,
345
458
  id,
346
459
  name,
347
- color: text2(kept.color, 40) || "#8e8e93",
460
+ color: text(kept.color, 40) || "#8e8e93",
348
461
  ...video ? { video } : {},
349
462
  ...post ? { post } : {},
350
463
  ...article ? { article } : {},
@@ -359,14 +472,14 @@ var CreatorUtil;
359
472
  }
360
473
  CreatorUtil.items = items;
361
474
  function item(value) {
362
- const kept = object2(value);
363
- const id = text2(kept?.id, 80);
364
- const title = text2(kept?.title, 200);
365
- const at = time2(kept?.at);
475
+ const kept = object(value);
476
+ const id = text(kept?.id, 80);
477
+ const title = text(kept?.title, 200);
478
+ const at = time(kept?.at);
366
479
  if (!kept || !id || !title || !at) {
367
480
  return;
368
481
  }
369
- const origin = object2(kept.origin);
482
+ const origin = object(kept.origin);
370
483
  const originUrl = url(origin?.url);
371
484
  return {
372
485
  id,
@@ -374,38 +487,39 @@ var CreatorUtil;
374
487
  form: oneOf(FORMS, kept.form, "video"),
375
488
  kind: oneOf(KINDS, kept.kind, "howto"),
376
489
  stage: oneOf(STAGES, kept.stage, "topic"),
377
- ...text2(kept.series, 60) ? { series: text2(kept.series, 60) } : {},
490
+ ...text(kept.series, 60) ? { series: text(kept.series, 60) } : {},
378
491
  ...count(kept.number, 0) ? { number: count(kept.number, 0) } : {},
379
492
  ...REACHES.includes(kept.reach) ? { reach: kept.reach } : {},
380
- ...text2(kept.why, 300) ? { why: text2(kept.why, 300) } : {},
493
+ ...text(kept.why, 300) ? { why: text(kept.why, 300) } : {},
381
494
  ...typeof kept.heat === "number" ? { heat: Math.max(0, Math.min(100, Math.round(kept.heat))) } : {},
382
- ...time2(kept.until) ? { until: time2(kept.until) } : {},
495
+ ...time(kept.until) ? { until: time(kept.until) } : {},
383
496
  ...texts(kept.seen, 10).length ? { seen: texts(kept.seen, 10) } : {},
384
497
  ...origin && originUrl ? {
385
498
  origin: {
386
499
  url: originUrl,
387
- ...text2(origin.title, 200) ? { title: text2(origin.title, 200) } : {},
388
- ...text2(origin.author, 100) ? { author: text2(origin.author, 100) } : {},
389
- ...text2(origin.licence, 100) ? { licence: text2(origin.licence, 100) } : {}
500
+ ...text(origin.title, 200) ? { title: text(origin.title, 200) } : {},
501
+ ...text(origin.author, 100) ? { author: text(origin.author, 100) } : {},
502
+ ...text(origin.licence, 100) ? { licence: text(origin.licence, 100) } : {}
390
503
  }
391
504
  } : {},
392
505
  ...Array.isArray(kept.needs) ? {
393
506
  needs: kept.needs.map(need).filter((one) => !!one).slice(0, 12)
394
507
  } : {},
395
508
  ...Array.isArray(kept.done) ? { done: STEPS.filter((step) => kept.done.includes(step)) } : {},
396
- ...text2(kept.script, 20000) ? { script: text2(kept.script, 20000) } : {},
509
+ ...text(kept.script, 20000) ? { script: text(kept.script, 20000) } : {},
397
510
  ...Array.isArray(kept.versions) ? { versions: kept.versions.map(version).filter((one) => !!one) } : {},
398
511
  ...Array.isArray(kept.checks) ? { checks: kept.checks.map(check).filter((one) => !!one) } : {},
399
- ...text2(kept.session, 1000) ? { session: text2(kept.session, 1000) } : {},
400
- ...time2(kept.approved) ? { approved: time2(kept.approved) } : {},
401
- ...PublishUtil.publishing(kept.publishing) ? { publishing: PublishUtil.publishing(kept.publishing) } : {},
512
+ ...text(kept.session, 1000) ? { session: text(kept.session, 1000) } : {},
513
+ ...time(kept.approved) ? { approved: time(kept.approved) } : {},
514
+ ...PublishUtil.of(kept) ? { publishing: PublishUtil.of(kept) } : {},
402
515
  ...Array.isArray(kept.links) ? { links: kept.links.map(link).filter((one) => !!one) } : {},
403
516
  ...Array.isArray(kept.stats) ? { stats: kept.stats.map(stat).filter((one) => !!one) } : {},
404
517
  ...kept.dropped === true ? { dropped: true } : {},
405
- ...time2(kept.commentsAt) ? { commentsAt: time2(kept.commentsAt) } : {},
406
- ...time2(kept.commentsGap) ? { commentsGap: time2(kept.commentsGap) } : {},
518
+ ...time(kept.commentsAt) ? { commentsAt: time(kept.commentsAt) } : {},
519
+ ...time(kept.commentsGap) ? { commentsGap: time(kept.commentsGap) } : {},
520
+ ...Efficiency.fields(kept),
407
521
  at,
408
- changedAt: time2(kept.changedAt) ?? at
522
+ changedAt: time(kept.changedAt) ?? at
409
523
  };
410
524
  }
411
525
  CreatorUtil.item = item;
@@ -413,10 +527,10 @@ var CreatorUtil;
413
527
  if (!Array.isArray(value)) {
414
528
  return [];
415
529
  }
416
- return value.map((one) => object2(one)).filter((one) => !!one && /^\d{4}-\d{2}-\d{2}$/.test(String(one.week))).map((one) => ({
530
+ return value.map((one) => object(one)).filter((one) => !!one && /^\d{4}-\d{2}-\d{2}$/.test(String(one.week))).map((one) => ({
417
531
  week: String(one.week),
418
- platforms: (Array.isArray(one.platforms) ? one.platforms : []).map((it) => object2(it)).filter((it) => !!it && !!text2(it.platform, 60)).map((it) => ({
419
- platform: text2(it.platform, 60),
532
+ platforms: (Array.isArray(one.platforms) ? one.platforms : []).map((it) => object(it)).filter((it) => !!it && !!text(it.platform, 60)).map((it) => ({
533
+ platform: text(it.platform, 60),
420
534
  views: count(it.views, 0),
421
535
  ...typeof it.likes === "number" ? { likes: count(it.likes, 0) } : {},
422
536
  ...typeof it.follows === "number" ? { follows: count(it.follows, 0) } : {},
@@ -437,7 +551,8 @@ var CreatorUtil;
437
551
  topic: of("topic").filter((one) => !expired(one, now)).sort((a, b) => (b.heat ?? 0) - (a.heat ?? 0) || b.at - a.at),
438
552
  materials: of("materials").sort(latest),
439
553
  making: of("making").sort(latest),
440
- review: of("review").sort(latest),
554
+ review: of("review").filter((one) => !one.approved).sort(latest),
555
+ publishing: of("review").filter((one) => !!one.approved).sort((a, b) => (a.approved ?? 0) - (b.approved ?? 0)),
441
556
  published: of("published").sort((a, b) => publishedAt(b) - publishedAt(a))
442
557
  };
443
558
  }
@@ -488,7 +603,7 @@ var CreatorUtil;
488
603
  }
489
604
  CreatorUtil.change = change;
490
605
  function seriesNamed(series, value) {
491
- const key = text2(value, 60).toLowerCase();
606
+ const key = text(value, 60).toLowerCase();
492
607
  return key ? series.find((one) => one.id.toLowerCase() === key || one.name.toLowerCase() === key) : undefined;
493
608
  }
494
609
  CreatorUtil.seriesNamed = seriesNamed;
@@ -515,7 +630,7 @@ var CreatorUtil;
515
630
  }
516
631
  CreatorUtil.views = views;
517
632
  function setStats(items2, id, stats, now) {
518
- const read = stats.map((one) => stat({ at: now, ...object2(one) ?? {} })).filter((one) => !!one);
633
+ const read = stats.map((one) => stat({ at: now, ...object(one) ?? {} })).filter((one) => !!one);
519
634
  const before = items2.find((one) => one.id === id);
520
635
  if (!before) {
521
636
  throw new Error(`No such piece: ${id}.`);
@@ -528,7 +643,7 @@ var CreatorUtil;
528
643
  if (!goal) {
529
644
  return;
530
645
  }
531
- const end = goal.from + goal.days * DAY;
646
+ const end = goal.from + goal.days * DAY2;
532
647
  const published = items2.filter((one) => one.stage === "published" && (one.links?.length ?? 0) > 0).filter((one) => {
533
648
  const at = publishedAt(one);
534
649
  return at >= goal.from && at < end;
@@ -536,7 +651,7 @@ var CreatorUtil;
536
651
  return {
537
652
  videos: published.filter((one) => one.form === "video").length,
538
653
  posts: published.filter((one) => one.form !== "video").length,
539
- day: Math.max(1, Math.min(goal.days, Math.floor((now - goal.from) / DAY) + 1))
654
+ day: Math.max(1, Math.min(goal.days, Math.floor((now - goal.from) / DAY2) + 1))
540
655
  };
541
656
  }
542
657
  CreatorUtil.progress = progress;
@@ -573,44 +688,44 @@ var CreatorUtil;
573
688
  }
574
689
  CreatorUtil.offer = offer;
575
690
  function need(value) {
576
- const kept = object2(value);
577
- const words = text2(kept?.text, 300);
691
+ const kept = object(value);
692
+ const words = text(kept?.text, 300);
578
693
  if (!kept || !words) {
579
694
  return;
580
695
  }
581
- return { id: text2(kept.id, 60), text: words, ...kept.done === true ? { done: true } : {} };
696
+ return { id: text(kept.id, 60), text: words, ...kept.done === true ? { done: true } : {} };
582
697
  }
583
698
  CreatorUtil.need = need;
584
699
  function version(value) {
585
- const kept = object2(value);
586
- const platform2 = text2(kept?.platform, 60);
700
+ const kept = object(value);
701
+ const platform2 = text(kept?.platform, 60);
587
702
  if (!kept || !platform2) {
588
703
  return;
589
704
  }
590
- const cover = text2(kept.cover, 500);
705
+ const cover = text(kept.cover, 500);
591
706
  return {
592
707
  platform: platform2,
593
708
  ...FORMS.includes(kept.form) ? { form: kept.form } : {},
594
- title: text2(kept.title, 200),
595
- text: text2(kept.text, 20000),
709
+ title: text(kept.title, 200),
710
+ text: text(kept.text, 20000),
596
711
  tags: texts(kept.tags, 20),
597
712
  files: texts(kept.files, 40),
598
713
  ...cover ? { cover } : {}
599
714
  };
600
715
  }
601
716
  function check(value) {
602
- const kept = object2(value);
603
- return kept && text2(kept.text, 200) ? { text: text2(kept.text, 200), ok: kept.ok === true } : undefined;
717
+ const kept = object(value);
718
+ return kept && text(kept.text, 200) ? { text: text(kept.text, 200), ok: kept.ok === true } : undefined;
604
719
  }
605
720
  function link(value) {
606
- const kept = object2(value);
721
+ const kept = object(value);
607
722
  const href = url(kept?.url);
608
723
  const scheduled = PublishUtil.timeOf(kept?.scheduled);
609
- return kept && href && text2(kept.platform, 60) ? { platform: text2(kept.platform, 60), url: href, at: time2(kept.at) ?? Date.now(), ...scheduled ? { scheduled } : {} } : undefined;
724
+ return kept && href && text(kept.platform, 60) ? { platform: text(kept.platform, 60), url: href, at: time(kept.at) ?? Date.now(), ...scheduled ? { scheduled } : {} } : undefined;
610
725
  }
611
726
  function stat(value) {
612
- const kept = object2(value);
613
- const platform2 = text2(kept?.platform, 60);
727
+ const kept = object(value);
728
+ const platform2 = text(kept?.platform, 60);
614
729
  if (!kept || !platform2 || typeof kept.views !== "number") {
615
730
  return;
616
731
  }
@@ -618,25 +733,23 @@ var CreatorUtil;
618
733
  return {
619
734
  platform: platform2,
620
735
  views: count(kept.views, 0),
621
- ...optional("likes"),
622
- ...optional("comments"),
623
- ...optional("follows"),
736
+ ...Object.assign({}, ...["likes", "comments", "follows", "watch"].map(optional)),
624
737
  ...typeof kept.completion === "number" && Number.isFinite(kept.completion) ? { completion: Math.max(0, Math.min(1, kept.completion)) } : {},
625
- at: time2(kept.at) ?? Date.now()
738
+ at: time(kept.at) ?? Date.now()
626
739
  };
627
740
  }
628
741
  function source(value) {
629
- const kept = object2(value);
742
+ const kept = object(value);
630
743
  const href = url(kept?.url);
631
- return kept && href && text2(kept.name, 80) ? { name: text2(kept.name, 80), url: href } : undefined;
744
+ return kept && href && text(kept.name, 80) ? { name: text(kept.name, 80), url: href } : undefined;
632
745
  }
633
746
  })(CreatorUtil ||= {});
634
747
 
635
748
  // web-src/channel-util.ts
636
- var HOUR = 3600000;
637
- var DAY2 = 24 * HOUR;
749
+ var HOUR2 = 3600000;
750
+ var DAY3 = 24 * HOUR2;
638
751
  var MAX_COMMENTS = 600;
639
- var COMMENTS_FOR = 60 * DAY2;
752
+ var COMMENTS_FOR = 60 * DAY3;
640
753
  var MAX_LESSONS = 40;
641
754
  var ChannelUtil;
642
755
  ((ChannelUtil) => {
@@ -680,14 +793,14 @@ var ChannelUtil;
680
793
  }
681
794
  ChannelUtil.analysis = analysis;
682
795
  function insights(value) {
683
- const all = (Array.isArray(value) ? value : []).map((one) => object2(one)).filter((one) => !!one && !!text2(one.text, 300) && !!time2(one.at)).map((one) => {
684
- const at = time2(one.at);
685
- const words = text2(one.text, 300);
796
+ const all = (Array.isArray(value) ? value : []).map((one) => object(one)).filter((one) => !!one && !!text(one.text, 300) && !!time(one.at)).map((one) => {
797
+ const at = time(one.at);
798
+ const words = text(one.text, 300);
686
799
  return {
687
- id: text2(one.id, 60) || `i${hash(words + at)}`,
800
+ id: text(one.id, 60) || `i${hash(words + at)}`,
688
801
  text: words,
689
802
  tone: oneOf(["good", "bad", "idea"], one.tone, "idea"),
690
- ...text2(one.series, 60) ? { series: text2(one.series, 60) } : {},
803
+ ...text(one.series, 60) ? { series: text(one.series, 60) } : {},
691
804
  ...one.by === "user" ? { by: "user" } : {},
692
805
  ...one.state === "proposed" || one.state === "declined" ? { state: one.state } : {},
693
806
  at
@@ -699,7 +812,7 @@ var ChannelUtil;
699
812
  }
700
813
  ChannelUtil.insights = insights;
701
814
  function addInsights(kept, added, series, now, mode = "auto") {
702
- const read = added.map((one) => typeof one === "string" ? { text: one } : object2(one)).filter((one) => !!one).map((one, at) => ({
815
+ const read = added.map((one) => typeof one === "string" ? { text: one } : object(one)).filter((one) => !!one).map((one, at) => ({
703
816
  ...one,
704
817
  id: `i${now.toString(36)}${at}`,
705
818
  by: undefined,
@@ -711,7 +824,7 @@ var ChannelUtil;
711
824
  }
712
825
  ChannelUtil.addInsights = addInsights;
713
826
  function addRule(kept, words, series, now, seriesId) {
714
- const rule = text2(words, 300);
827
+ const rule = text(words, 300);
715
828
  if (!rule) {
716
829
  throw new Error("A rule needs its words.");
717
830
  }
@@ -743,7 +856,7 @@ var ChannelUtil;
743
856
  function latestInsights(insights2) {
744
857
  const ta = insights2.filter((one) => one.by !== "user" && !one.state);
745
858
  const newest = ta[0]?.at ?? 0;
746
- return insights2.filter((one) => one.by === "user" || !one.state && newest - one.at < DAY2);
859
+ return insights2.filter((one) => one.by === "user" || !one.state && newest - one.at < DAY3);
747
860
  }
748
861
  ChannelUtil.latestInsights = latestInsights;
749
862
  function proposed(insights2) {
@@ -751,12 +864,12 @@ var ChannelUtil;
751
864
  }
752
865
  ChannelUtil.proposed = proposed;
753
866
  function phases(value) {
754
- 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) => ({
755
- from: time2(one.from),
756
- to: time2(one.to),
757
- summary: text2(one.summary, 2000),
758
- ...text2(one.topic, 80) ? { topic: text2(one.topic, 80) } : {},
759
- at: time2(one.at)
867
+ 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) => ({
868
+ from: time(one.from),
869
+ to: time(one.to),
870
+ summary: text(one.summary, 2000),
871
+ ...text(one.topic, 80) ? { topic: text(one.topic, 80) } : {},
872
+ at: time(one.at)
760
873
  })).sort((a, b) => b.at - a.at).slice(0, 24);
761
874
  }
762
875
  ChannelUtil.phases = phases;
@@ -766,21 +879,21 @@ var ChannelUtil;
766
879
  }
767
880
  const published = items.filter((one) => one.stage === "published" && !one.dropped).map(CreatorUtil.publishedAt);
768
881
  const from = phases2[0]?.to ?? (published.length ? Math.min(...published) : undefined);
769
- if (from === undefined || now - from < settings.phaseWeeks * 7 * DAY2 || !published.some((at) => at >= from)) {
882
+ if (from === undefined || now - from < settings.phaseWeeks * 7 * DAY3 || !published.some((at) => at >= from)) {
770
883
  return;
771
884
  }
772
885
  return { from, to: now };
773
886
  }
774
887
  ChannelUtil.phaseDue = phaseDue;
775
888
  function needsOf(values, now) {
776
- 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);
889
+ 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);
777
890
  }
778
891
  ChannelUtil.needsOf = needsOf;
779
892
  function given(item) {
780
893
  return (item.needs ?? []).every((one) => one.done);
781
894
  }
782
895
  ChannelUtil.given = given;
783
- ChannelUtil.PACE = { start: 6 * HOUR, first: 12 * HOUR, min: HOUR, max: 2 * DAY2, many: 3 };
896
+ ChannelUtil.PACE = { start: 12 * HOUR2, first: 24 * HOUR2, min: 2 * HOUR2, max: 2 * DAY3, many: 3, ride: 0.5 };
784
897
  function nextGap(gap, added) {
785
898
  if (added >= ChannelUtil.PACE.many) {
786
899
  return Math.max(ChannelUtil.PACE.min, Math.round(gap / 2));
@@ -794,9 +907,46 @@ var ChannelUtil;
794
907
  }
795
908
  ChannelUtil.firstGap = firstGap;
796
909
  function commentsGap(item, items, settings) {
797
- return settings.commentsEvery ? settings.commentsEvery * HOUR : item.commentsGap ?? firstGap(items);
910
+ return settings.commentsEvery ? settings.commentsEvery * HOUR2 : item.commentsGap ?? firstGap(items);
798
911
  }
799
912
  ChannelUtil.commentsGap = commentsGap;
913
+ function live(item, now) {
914
+ return (item.links ?? []).filter((one) => (one.scheduled ?? one.at) <= now);
915
+ }
916
+ ChannelUtil.live = live;
917
+ function due(items, settings, now, share = 1) {
918
+ return items.filter((one) => {
919
+ const out = live(one, now).map((link) => link.scheduled ?? link.at);
920
+ if (one.stage !== "published" || one.dropped || !out.length) {
921
+ return false;
922
+ }
923
+ const published = Math.min(...out);
924
+ const since = now - Math.max(one.commentsAt ?? 0, published);
925
+ return now - published < settings.commentsDays * DAY3 && since >= share * commentsGap(one, items, settings);
926
+ });
927
+ }
928
+ ChannelUtil.due = due;
929
+ ChannelUtil.STATS = { first: 20 * HOUR2, again: 7 * DAY3, until: 14 * DAY3 };
930
+ function enough(waiting, settings) {
931
+ const perWeek = settings.series.reduce((all, one) => all + (one.perWeek ?? 1), 0);
932
+ return perWeek > 0 && waiting >= 2 * perWeek;
933
+ }
934
+ ChannelUtil.enough = enough;
935
+ function statsDue(items, now) {
936
+ return items.filter((one) => one.stage === "published" && !one.dropped).map((item) => ({
937
+ item,
938
+ links: live(item, now).filter((link) => {
939
+ const out = link.scheduled ?? link.at;
940
+ const read = item.stats?.find((one) => one.platform === link.platform);
941
+ const age = now - out;
942
+ if (age < ChannelUtil.STATS.first || age >= ChannelUtil.STATS.until) {
943
+ return false;
944
+ }
945
+ return !read || age >= ChannelUtil.STATS.again && read.at - out < ChannelUtil.STATS.again - DAY3;
946
+ })
947
+ })).filter((one) => one.links.length > 0);
948
+ }
949
+ ChannelUtil.statsDue = statsDue;
800
950
  function comments(value, now = Date.now()) {
801
951
  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);
802
952
  }
@@ -805,16 +955,16 @@ var ChannelUtil;
805
955
  const all = [...kept];
806
956
  const added = [];
807
957
  for (const value of input) {
808
- const read = object2(value);
809
- const platform = text2(read?.platform, 60);
810
- const words = text2(read?.text, 1000);
958
+ const read = object(value);
959
+ const platform = text(read?.platform, 60);
960
+ const words = text(read?.text, 1000);
811
961
  if (!read || !platform || !words) {
812
962
  continue;
813
963
  }
814
- const key = text2(read.key, 120) || `t${hash(words)}`;
964
+ const key = text(read.key, 120) || `t${hash(words)}`;
815
965
  const cls = oneOf(COMMENT_CLASSES, read.class, "question");
816
966
  const level = REPLY_CLASSES.includes(cls) ? levels[cls] : "off";
817
- const answer = text2(read.reply, 500);
967
+ const answer = text(read.reply, 500);
818
968
  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;
819
969
  const at = all.findIndex((one) => one.item === item && one.platform === platform && one.key === key);
820
970
  if (at >= 0) {
@@ -849,25 +999,25 @@ var ChannelUtil;
849
999
  }
850
1000
  ChannelUtil.examples = examples;
851
1001
  function lessons(value) {
852
- 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);
1002
+ 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);
853
1003
  }
854
1004
  ChannelUtil.lessons = lessons;
855
1005
  function comment(value) {
856
- const kept = object2(value);
857
- const id = text2(kept?.id, 80);
858
- const words = text2(kept?.text, 1000);
859
- const at = time2(kept?.at);
860
- if (!kept || !id || !words || !at || !text2(kept.item, 80) || !text2(kept.platform, 60)) {
1006
+ const kept = object(value);
1007
+ const id = text(kept?.id, 80);
1008
+ const words = text(kept?.text, 1000);
1009
+ const at = time(kept?.at);
1010
+ if (!kept || !id || !words || !at || !text(kept.item, 80) || !text(kept.platform, 60)) {
861
1011
  return;
862
1012
  }
863
- const reply = object2(kept.reply);
864
- const answer = text2(reply?.text, 500);
865
- const draft = text2(reply?.draft, 500);
1013
+ const reply = object(kept.reply);
1014
+ const answer = text(reply?.text, 500);
1015
+ const draft = text(reply?.draft, 500);
866
1016
  return {
867
1017
  id,
868
- item: text2(kept.item, 80),
869
- platform: text2(kept.platform, 60),
870
- key: text2(kept.key, 120) || `t${hash(words)}`,
1018
+ item: text(kept.item, 80),
1019
+ platform: text(kept.platform, 60),
1020
+ key: text(kept.key, 120) || `t${hash(words)}`,
871
1021
  text: words,
872
1022
  class: oneOf(COMMENT_CLASSES, kept.class, "question"),
873
1023
  ...typeof kept.likes === "number" ? { likes: count(kept.likes, 0) } : {},
@@ -877,10 +1027,10 @@ var ChannelUtil;
877
1027
  state: oneOf(REPLY_STATES, reply.state, "draft"),
878
1028
  ...reply.auto === true ? { auto: true } : {},
879
1029
  ...draft ? { draft } : {},
880
- at: time2(reply.at) ?? at
1030
+ at: time(reply.at) ?? at
881
1031
  }
882
1032
  } : {},
883
- ...text2(kept.topic, 80) ? { topic: text2(kept.topic, 80) } : {},
1033
+ ...text(kept.topic, 80) ? { topic: text(kept.topic, 80) } : {},
884
1034
  at
885
1035
  };
886
1036
  }
@@ -908,7 +1058,7 @@ var CreatorTasks;
908
1058
  notify: "error",
909
1059
  prompt: [
910
1060
  `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).`,
911
- "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.",
1061
+ "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.",
912
1062
  "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.",
913
1063
  '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].',
914
1064
  '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.',
@@ -919,7 +1069,7 @@ var CreatorTasks;
919
1069
  `- 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.`,
920
1070
  `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.`,
921
1071
  `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? }>'\`.`,
922
- "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."
1072
+ "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."
923
1073
  ].join(`
924
1074
  `)
925
1075
  };
@@ -931,7 +1081,7 @@ var CreatorTasks;
931
1081
  prompt: [
932
1082
  `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.`,
933
1083
  "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):",
934
- `- for each piece published in the last 4 weeks: \`${call("stats")} <id> '<JSON array of { platform, views, likes?, comments?, follows?, completion? (0–1) }>'\`;`,
1084
+ `- 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) }>'\`;`,
935
1085
  `- for last week, each platform: \`${call("week")} <monday YYYY-MM-DD> '<JSON array of { platform, views, likes?, follows?, completion? }>'\`.`,
936
1086
  `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.`,
937
1087
  `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.`,
@@ -946,14 +1096,16 @@ var CreatorTasks;
946
1096
  when: "cron 30 21 * * *",
947
1097
  notify: "error",
948
1098
  prompt: [
949
- `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.`,
1099
+ `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.`,
1100
+ "When due, stats, send and withdraw are all empty, there is nothing to do: call nothing_new and stop, opening no browser.",
950
1101
  "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.",
951
1102
  `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" }>'\`.`,
952
1103
  "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).",
953
- "3. Write an answer for a question, a suggestion, a correction or praise whose class is not off: short, warm, 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.",
1104
+ "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.",
954
1105
  `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.`,
955
- "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.",
956
- "Reply in Chinese in one short line: how many read, answered and waiting."
1106
+ `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? }>'\`.`,
1107
+ "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.",
1108
+ "Reply in Chinese in one short line: how many read, answered and waiting, and the numbers of how many pieces kept."
957
1109
  ].join(`
958
1110
  `)
959
1111
  };
@@ -1309,7 +1461,7 @@ class PublishQueue {
1309
1461
  this.now = now;
1310
1462
  }
1311
1463
  begin() {
1312
- const stop = this.host.onSessionEvent((event) => void this.watch(event));
1464
+ const stop = this.host.onSessionEvent((event) => void this.watch(event).catch((error) => PublishQueue.failed(error)));
1313
1465
  return () => {
1314
1466
  stop();
1315
1467
  this.rest();
@@ -1397,11 +1549,14 @@ class PublishQueue {
1397
1549
  return this.store.stopped(id, "Its conversation went idle without publishing it or saying why.");
1398
1550
  }
1399
1551
  return;
1400
- });
1552
+ }).catch((error) => PublishQueue.failed(error));
1401
1553
  }, ms);
1402
1554
  timer.unref?.();
1403
1555
  this.idle = { id, timer };
1404
1556
  }
1557
+ static failed(error) {
1558
+ console.error(`${NAME}: the queue of publishing failed: ${error instanceof Error ? error.message : String(error)}`);
1559
+ }
1405
1560
  rest(id) {
1406
1561
  if (this.idle && (!id || this.idle.id === id)) {
1407
1562
  clearTimeout(this.idle.timer);
@@ -1452,11 +1607,11 @@ class CreatorHostBase {
1452
1607
  return stage ? items.filter((one) => one.stage === stage && !one.dropped) : items;
1453
1608
  }
1454
1609
  update(id, patch) {
1455
- const kept = ["stage", "approved", "publishing", "links", "dropped", "stats", "needs", "commentsAt", "commentsGap"];
1610
+ const kept = ["stage", "approved", "publishing", "links", "dropped", "stats", "needs", "commentsAt", "commentsGap", "started", "cost"];
1456
1611
  return this.change(id, Object.fromEntries(Object.entries(patch ?? {}).filter(([key]) => !kept.includes(key))));
1457
1612
  }
1458
1613
  start(id) {
1459
- return this.change(id, { stage: "making", done: [] });
1614
+ return this.change(id, { stage: "making", done: [], started: this.now() });
1460
1615
  }
1461
1616
  async remove(id) {
1462
1617
  const item = (await this.items()).find((one) => one.id === id);
@@ -1470,7 +1625,7 @@ class CreatorHostBase {
1470
1625
  }
1471
1626
  stats(id, stats) {
1472
1627
  if (!Array.isArray(stats)) {
1473
- return Promise.reject(new Error("Stats are an array of { platform, views, likes?, comments?, follows?, completion? }."));
1628
+ return Promise.reject(new Error("Stats are an array of { platform, views, likes?, comments?, follows?, completion?, watch? }."));
1474
1629
  }
1475
1630
  return this.serial(async () => {
1476
1631
  const items = CreatorUtil.setStats(await this.items(), id, stats, this.now());
@@ -1500,6 +1655,7 @@ class CreatorHostBase {
1500
1655
  const now = this.now();
1501
1656
  const item = await this.change(id, { approved: now, publishing: { state: "queued", since: now, ...ask ? { ask: String(ask) } : {} } }, minutes);
1502
1657
  this.publisher.pump();
1658
+ this.measure(item.id);
1503
1659
  return item;
1504
1660
  }
1505
1661
  async stopped(id, why) {
@@ -1585,13 +1741,15 @@ class CreatorHostBase {
1585
1741
  const task = CreatorTasks.of(id);
1586
1742
  const v = CreatorTasks.version(task);
1587
1743
  if (on && !record) {
1588
- const added = await this.host.callPackageHost(CRON, "add", [task]);
1744
+ const added = await this.host.callPackageHost(CRON, "add", [{ ...task, owner: NAME }]);
1589
1745
  next[id] = { id: added.id, v };
1590
1746
  } else if (record && "id" in record && !tasks.some((one) => one.id === record.id)) {
1591
1747
  next[id] = { removed: true };
1592
1748
  } else if (on && record && "id" in record && record.v !== v) {
1593
- await this.host.callPackageHost(CRON, "update", [record.id, { prompt: task.prompt }]);
1749
+ await this.host.callPackageHost(CRON, "update", [record.id, { prompt: task.prompt, owner: NAME }]);
1594
1750
  next[id] = { id: record.id, v };
1751
+ } else if (on && record && "id" in record && tasks.some((one) => one.id === record.id && one.owner !== NAME)) {
1752
+ await this.host.callPackageHost(CRON, "update", [record.id, { owner: NAME }]);
1595
1753
  }
1596
1754
  if (!on && record) {
1597
1755
  if ("id" in record && tasks.some((task2) => task2.id === record.id)) {
@@ -1609,6 +1767,19 @@ class CreatorHostBase {
1609
1767
  return;
1610
1768
  });
1611
1769
  }
1770
+ async measure(...ids) {
1771
+ const items = (await this.items()).filter((one) => one.session && (ids.length ? ids.includes(one.id) : one.stage === "published" && !one.cost));
1772
+ let kept = 0;
1773
+ for (const item of items) {
1774
+ const messages = await this.host.sessionMessages(item.session).catch(() => []);
1775
+ const cost = Efficiency.costOf(messages, this.now());
1776
+ if (cost) {
1777
+ await this.change(item.id, { cost });
1778
+ kept++;
1779
+ }
1780
+ }
1781
+ return kept;
1782
+ }
1612
1783
  items() {
1613
1784
  return this.data(Keys.ITEMS).then(CreatorUtil.items);
1614
1785
  }
@@ -1647,9 +1818,9 @@ class CreatorHostBase {
1647
1818
  // web-src/host.ts
1648
1819
  var CRON2 = "@celljs/ta-cron";
1649
1820
  var INITIATIVE = "@celljs/ta-initiative";
1650
- var DAY3 = 86400000;
1821
+ var DAY4 = 86400000;
1651
1822
  var TICK = 10 * 60000;
1652
- var RUN_GAP = 30 * 60000;
1823
+ var RUN_GAP = 2 * 3600000;
1653
1824
  var SEND_GAP = 5 * 60000;
1654
1825
  var AWAKE = [9, 23];
1655
1826
  function replyLevel(level) {
@@ -1705,7 +1876,7 @@ class CreatorHost extends CreatorHostBase {
1705
1876
  ...one.by ? { by: one.by } : {}
1706
1877
  }));
1707
1878
  const insights = strategy;
1708
- 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 }));
1879
+ 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 }));
1709
1880
  switch (task) {
1710
1881
  case "topics":
1711
1882
  return {
@@ -1716,29 +1887,29 @@ class CreatorHost extends CreatorHostBase {
1716
1887
  id: one.id,
1717
1888
  title: one.title,
1718
1889
  missing: (one.needs ?? []).filter((need) => !need.done).map((need) => need.text),
1719
- days: Math.floor((now - one.changedAt) / DAY3)
1890
+ days: Math.floor((now - one.changedAt) / DAY4)
1720
1891
  })),
1721
1892
  niche: settings.niche,
1722
1893
  platforms,
1723
1894
  inside: CreatorUtil.picked(settings).filter((one) => one.internal).map((one) => one.name),
1724
1895
  sources: settings.sources,
1725
- offer: CreatorUtil.offer(settings, weeks, now),
1726
- titles: items.filter((one) => now - one.at < 30 * DAY3).map((one) => one.title).slice(-80),
1896
+ offer: ChannelUtil.enough(columns.topic.length, settings) ? 0 : CreatorUtil.offer(settings, weeks, now),
1897
+ titles: items.filter((one) => now - one.at < 30 * DAY4).map((one) => one.title).slice(-80),
1727
1898
  waiting: columns.topic.length
1728
1899
  };
1729
1900
  case "review": {
1730
- const week = CreatorUtil.weekOf(now - 7 * DAY3);
1901
+ const week = CreatorUtil.weekOf(now - 7 * DAY4);
1731
1902
  const from = new Date(`${week}T00:00:00`).getTime();
1732
1903
  return {
1733
1904
  week,
1734
1905
  platforms,
1735
1906
  published: items.filter((one) => one.stage === "published").filter((one) => {
1736
1907
  const at = CreatorUtil.publishedAt(one);
1737
- return at >= from && at < from + 7 * DAY3;
1908
+ return at >= from && at < from + 7 * DAY4;
1738
1909
  }).map((one) => ({ id: one.id, title: one.title, series: one.series, form: one.form, kind: one.kind, links: one.links })),
1739
- 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 })),
1910
+ 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 })),
1740
1911
  series,
1741
- numbers: weeks.filter((one) => one.week >= CreatorUtil.weekOf(now - 21 * DAY3)),
1912
+ numbers: weeks.filter((one) => one.week >= CreatorUtil.weekOf(now - 21 * DAY4)),
1742
1913
  minutes: weeks.find((one) => one.week === week)?.minutes ?? 0,
1743
1914
  minutesCap: settings.minutesCap,
1744
1915
  goal: settings.goal ? { ...settings.goal, progress: CreatorUtil.progress(items, settings.goal, now) } : undefined,
@@ -1776,6 +1947,7 @@ class CreatorHost extends CreatorHostBase {
1776
1947
  inside: CreatorUtil.picked(settings).filter((one) => one.internal).map((one) => one.name),
1777
1948
  strategy,
1778
1949
  lessons: (await this.lessons()).slice(0, 15).map((one) => one.text),
1950
+ tone: CreatorUtil.toneOf(item, settings),
1779
1951
  voice: settings.voice
1780
1952
  };
1781
1953
  }
@@ -1783,7 +1955,12 @@ class CreatorHost extends CreatorHostBase {
1783
1955
  const title = (item) => items.find((one) => one.id === item)?.title;
1784
1956
  const link = (one) => items.find((it) => it.id === one.item)?.links?.find((it) => it.platform === one.platform)?.url;
1785
1957
  return {
1786
- due: this.due(items, settings, now).map((one) => ({ id: one.id, title: one.title, links: one.links, since: one.commentsAt })),
1958
+ due: ChannelUtil.due(items, settings, now, ChannelUtil.PACE.ride).map((one) => ({
1959
+ id: one.id,
1960
+ title: one.title,
1961
+ links: ChannelUtil.live(one, now),
1962
+ since: one.commentsAt
1963
+ })),
1787
1964
  send: comments.filter((one) => one.reply?.state === "approved").map((one) => ({
1788
1965
  id: one.id,
1789
1966
  piece: title(one.item),
@@ -1800,7 +1977,14 @@ class CreatorHost extends CreatorHostBase {
1800
1977
  comment: one.text,
1801
1978
  reply: one.reply?.text
1802
1979
  })),
1980
+ stats: ChannelUtil.statsDue(items, now).map(({ item, links }) => ({
1981
+ id: item.id,
1982
+ title: item.title,
1983
+ form: item.form,
1984
+ links: links.map((one) => ({ platform: one.platform, url: one.url }))
1985
+ })),
1803
1986
  levels: await this.levels(),
1987
+ tone: CreatorUtil.toneOf(undefined, settings),
1804
1988
  examples: ChannelUtil.examples(comments),
1805
1989
  limit: 20
1806
1990
  };
@@ -1823,7 +2007,7 @@ class CreatorHost extends CreatorHostBase {
1823
2007
  comments: {
1824
2008
  byClass: Object.fromEntries(["question", "suggestion", "correction", "praise", "negative", "spam"].map((cls) => [
1825
2009
  cls,
1826
- comments.filter((one) => one.class === cls && now - one.at < 28 * DAY3).length
2010
+ comments.filter((one) => one.class === cls && now - one.at < 28 * DAY4).length
1827
2011
  ])),
1828
2012
  asked
1829
2013
  }
@@ -2016,11 +2200,26 @@ class CreatorHost extends CreatorHostBase {
2016
2200
  }
2017
2201
  const [items, comments, settings] = await Promise.all([this.items(), this.commentsKept(), this.settings()]);
2018
2202
  const sending = comments.some((one) => one.reply?.state === "approved" || one.reply?.state === "withdrawn");
2019
- const due = this.due(items, settings, now).length > 0;
2203
+ const due = ChannelUtil.due(items, settings, now).length > 0 || ChannelUtil.statsDue(items, now).length > 0;
2020
2204
  if (sending && now - this.ranAt >= SEND_GAP || due && now - this.ranAt >= RUN_GAP) {
2021
2205
  await this.runComments();
2022
2206
  }
2023
2207
  }
2208
+ async efficiency() {
2209
+ await this.measure();
2210
+ const [items, made] = await Promise.all([this.items(), this.data(Keys.TASKS)]);
2211
+ const runs = Object.fromEntries(await Promise.all(CreatorTasks.IDS.map(async (id) => {
2212
+ const record = made?.[id];
2213
+ const list = record && "id" in record ? await this.host.callPackageHost(CRON2, "runs", [record.id, 200]).catch(() => []) : [];
2214
+ return [id, list];
2215
+ })));
2216
+ const { before, after } = Efficiency.windows(this.now());
2217
+ const of = ([from, to]) => ({
2218
+ pieces: Efficiency.pieces(items, from, to),
2219
+ tasks: Object.fromEntries(CreatorTasks.IDS.map((id) => [id, Efficiency.taskRuns(runs[id] ?? [], from, to)]))
2220
+ });
2221
+ return { before: of(before), after: of(after) };
2222
+ }
2024
2223
  runSoon() {
2025
2224
  if (this.soon) {
2026
2225
  return;
@@ -2041,16 +2240,6 @@ class CreatorHost extends CreatorHostBase {
2041
2240
  });
2042
2241
  }
2043
2242
  }
2044
- due(items, settings, now) {
2045
- return items.filter((one) => {
2046
- if (one.stage !== "published" || one.dropped || !one.links?.length) {
2047
- return false;
2048
- }
2049
- const published = CreatorUtil.publishedAt(one);
2050
- const since = now - (one.commentsAt ?? published);
2051
- return now - published < settings.commentsDays * DAY3 && since >= ChannelUtil.commentsGap(one, items, settings);
2052
- });
2053
- }
2054
2243
  async levels() {
2055
2244
  const levels = await Promise.all(REPLY_CLASSES.map((cls) => this.initiative("level", REPLY_KINDS[cls].id)));
2056
2245
  return Object.fromEntries(REPLY_CLASSES.map((cls, at) => [cls, replyLevel(levels[at] ?? REPLY_KINDS[cls].level)]));