@celljs/ta-creator 4.34.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/README.en.md +2 -2
- package/README.md +2 -2
- package/bin/render.mjs +284 -149
- package/host/index.mjs +303 -161
- package/package.json +3 -3
- package/skills/creator-make/SKILL.md +8 -4
- package/web/index.js +691 -27
package/host/index.mjs
CHANGED
|
@@ -143,10 +143,114 @@ var REPLY_KINDS = {
|
|
|
143
143
|
}
|
|
144
144
|
};
|
|
145
145
|
|
|
146
|
-
// web-src/
|
|
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,53 @@ 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
|
|
301
|
+
return time2(value);
|
|
198
302
|
}
|
|
199
303
|
PublishUtil.timeOf = timeOf;
|
|
200
304
|
function of(piece) {
|
|
201
|
-
const 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 =
|
|
207
|
-
const 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) =>
|
|
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
|
-
...
|
|
218
|
-
...
|
|
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;
|
|
234
|
-
}
|
|
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
|
-
}
|
|
244
|
-
|
|
245
328
|
// web-src/creator-util.ts
|
|
246
|
-
var
|
|
329
|
+
var DAY2 = 86400000;
|
|
247
330
|
var MAX_TOPICS = 200;
|
|
248
|
-
var HOT_FOR = 2 *
|
|
331
|
+
var HOT_FOR = 2 * DAY2;
|
|
249
332
|
var MAX_TONES = 3;
|
|
250
333
|
var CreatorUtil;
|
|
251
334
|
((CreatorUtil) => {
|
|
252
335
|
function settings(value) {
|
|
253
|
-
const kept =
|
|
336
|
+
const kept = object(value) ?? {};
|
|
254
337
|
const platforms = Array.isArray(kept.platforms) ? withBuiltins(kept.platforms.map(platform).filter((one) => !!one)) : [...PLATFORMS];
|
|
255
338
|
const ids = new Set(platforms.map((one) => one.id));
|
|
256
|
-
const goal =
|
|
339
|
+
const goal = object(kept.goal);
|
|
257
340
|
return {
|
|
258
|
-
niche:
|
|
341
|
+
niche: text(kept.niche, 500),
|
|
259
342
|
picked: texts(kept.picked).filter((id) => ids.has(id)),
|
|
260
343
|
platforms,
|
|
261
344
|
sources: Array.isArray(kept.sources) ? kept.sources.map(source).filter((one) => !!one) : [...SOURCES],
|
|
262
|
-
...goal &&
|
|
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) } } : {},
|
|
263
346
|
minutesCap: count(kept.minutesCap, 120),
|
|
264
|
-
voice:
|
|
347
|
+
voice: text(kept.voice, 60) || "zh-CN-XiaoxiaoNeural",
|
|
265
348
|
tone: tones(kept.tone),
|
|
266
349
|
series: Array.isArray(kept.series) ? seriesOf(kept.series) : [],
|
|
267
350
|
strategy: kept.strategy === "manual" ? "manual" : "auto",
|
|
@@ -286,7 +369,7 @@ var CreatorUtil;
|
|
|
286
369
|
CreatorUtil.withBuiltins = withBuiltins;
|
|
287
370
|
function tones(value) {
|
|
288
371
|
return [
|
|
289
|
-
...new Set(texts(value).map((one) =>
|
|
372
|
+
...new Set(texts(value).map((one) => text(one, 20)).filter(Boolean))
|
|
290
373
|
].slice(0, MAX_TONES);
|
|
291
374
|
}
|
|
292
375
|
CreatorUtil.tones = tones;
|
|
@@ -319,23 +402,23 @@ var CreatorUtil;
|
|
|
319
402
|
function seriesOf(values) {
|
|
320
403
|
const all = [];
|
|
321
404
|
for (const value of values) {
|
|
322
|
-
const kept =
|
|
323
|
-
const name =
|
|
405
|
+
const kept = object(value);
|
|
406
|
+
const name = text(kept?.name, 40);
|
|
324
407
|
if (!kept || !name) {
|
|
325
408
|
continue;
|
|
326
409
|
}
|
|
327
|
-
const id =
|
|
410
|
+
const id = text(kept.id, 60) || `s${hash(name)}`;
|
|
328
411
|
if (all.some((one) => one.id === id)) {
|
|
329
412
|
continue;
|
|
330
413
|
}
|
|
331
|
-
const about =
|
|
414
|
+
const about = text(kept.about, 200);
|
|
332
415
|
const perWeek = count(kept.perWeek, 0);
|
|
333
|
-
const tone =
|
|
416
|
+
const tone = text(kept.tone, 20);
|
|
334
417
|
all.push({
|
|
335
418
|
id,
|
|
336
419
|
name,
|
|
337
420
|
...about ? { about } : {},
|
|
338
|
-
color:
|
|
421
|
+
color: text(kept.color, 40) || SERIES_COLORS[all.length % SERIES_COLORS.length],
|
|
339
422
|
...kept.ordered === true ? { ordered: true } : {},
|
|
340
423
|
...perWeek ? { perWeek: Math.min(perWeek, 14) } : {},
|
|
341
424
|
...kept.reach === "internal" || kept.reach === "both" ? { reach: kept.reach } : {},
|
|
@@ -346,35 +429,35 @@ var CreatorUtil;
|
|
|
346
429
|
}
|
|
347
430
|
CreatorUtil.seriesOf = seriesOf;
|
|
348
431
|
function platform(value) {
|
|
349
|
-
const kept =
|
|
350
|
-
const id =
|
|
351
|
-
const name =
|
|
432
|
+
const kept = object(value);
|
|
433
|
+
const id = text(kept?.id, 60);
|
|
434
|
+
const name = text(kept?.name, 60);
|
|
352
435
|
if (!kept || !id || !name) {
|
|
353
436
|
return;
|
|
354
437
|
}
|
|
355
438
|
const shape = (one) => {
|
|
356
|
-
const it =
|
|
439
|
+
const it = object(one);
|
|
357
440
|
return it ? { aspect: oneOf(ASPECTS, it.aspect, "16:9"), ...count(it.maxSeconds, 0) ? { maxSeconds: count(it.maxSeconds, 0) } : {} } : undefined;
|
|
358
441
|
};
|
|
359
442
|
const video = shape(kept.video);
|
|
360
|
-
const post =
|
|
361
|
-
aspect: oneOf(ASPECTS,
|
|
362
|
-
...count(
|
|
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) } : {}
|
|
363
446
|
} : undefined;
|
|
364
447
|
const words = (one) => {
|
|
365
|
-
const it =
|
|
448
|
+
const it = object(one);
|
|
366
449
|
return it ? count(it.maxChars, 0) ? { maxChars: count(it.maxChars, 0) } : {} : undefined;
|
|
367
450
|
};
|
|
368
451
|
const article = words(kept.article);
|
|
369
452
|
const note = words(kept.note);
|
|
370
453
|
const publish = url(kept.publish);
|
|
371
|
-
const declare =
|
|
454
|
+
const declare = text(kept.declare, 200);
|
|
372
455
|
const inside = kept.internal === true ? { internal: true } : {};
|
|
373
456
|
return {
|
|
374
457
|
...inside,
|
|
375
458
|
id,
|
|
376
459
|
name,
|
|
377
|
-
color:
|
|
460
|
+
color: text(kept.color, 40) || "#8e8e93",
|
|
378
461
|
...video ? { video } : {},
|
|
379
462
|
...post ? { post } : {},
|
|
380
463
|
...article ? { article } : {},
|
|
@@ -389,14 +472,14 @@ var CreatorUtil;
|
|
|
389
472
|
}
|
|
390
473
|
CreatorUtil.items = items;
|
|
391
474
|
function item(value) {
|
|
392
|
-
const kept =
|
|
393
|
-
const id =
|
|
394
|
-
const title =
|
|
395
|
-
const 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);
|
|
396
479
|
if (!kept || !id || !title || !at) {
|
|
397
480
|
return;
|
|
398
481
|
}
|
|
399
|
-
const origin =
|
|
482
|
+
const origin = object(kept.origin);
|
|
400
483
|
const originUrl = url(origin?.url);
|
|
401
484
|
return {
|
|
402
485
|
id,
|
|
@@ -404,38 +487,39 @@ var CreatorUtil;
|
|
|
404
487
|
form: oneOf(FORMS, kept.form, "video"),
|
|
405
488
|
kind: oneOf(KINDS, kept.kind, "howto"),
|
|
406
489
|
stage: oneOf(STAGES, kept.stage, "topic"),
|
|
407
|
-
...
|
|
490
|
+
...text(kept.series, 60) ? { series: text(kept.series, 60) } : {},
|
|
408
491
|
...count(kept.number, 0) ? { number: count(kept.number, 0) } : {},
|
|
409
492
|
...REACHES.includes(kept.reach) ? { reach: kept.reach } : {},
|
|
410
|
-
...
|
|
493
|
+
...text(kept.why, 300) ? { why: text(kept.why, 300) } : {},
|
|
411
494
|
...typeof kept.heat === "number" ? { heat: Math.max(0, Math.min(100, Math.round(kept.heat))) } : {},
|
|
412
|
-
...
|
|
495
|
+
...time(kept.until) ? { until: time(kept.until) } : {},
|
|
413
496
|
...texts(kept.seen, 10).length ? { seen: texts(kept.seen, 10) } : {},
|
|
414
497
|
...origin && originUrl ? {
|
|
415
498
|
origin: {
|
|
416
499
|
url: originUrl,
|
|
417
|
-
...
|
|
418
|
-
...
|
|
419
|
-
...
|
|
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) } : {}
|
|
420
503
|
}
|
|
421
504
|
} : {},
|
|
422
505
|
...Array.isArray(kept.needs) ? {
|
|
423
506
|
needs: kept.needs.map(need).filter((one) => !!one).slice(0, 12)
|
|
424
507
|
} : {},
|
|
425
508
|
...Array.isArray(kept.done) ? { done: STEPS.filter((step) => kept.done.includes(step)) } : {},
|
|
426
|
-
...
|
|
509
|
+
...text(kept.script, 20000) ? { script: text(kept.script, 20000) } : {},
|
|
427
510
|
...Array.isArray(kept.versions) ? { versions: kept.versions.map(version).filter((one) => !!one) } : {},
|
|
428
511
|
...Array.isArray(kept.checks) ? { checks: kept.checks.map(check).filter((one) => !!one) } : {},
|
|
429
|
-
...
|
|
430
|
-
...
|
|
512
|
+
...text(kept.session, 1000) ? { session: text(kept.session, 1000) } : {},
|
|
513
|
+
...time(kept.approved) ? { approved: time(kept.approved) } : {},
|
|
431
514
|
...PublishUtil.of(kept) ? { publishing: PublishUtil.of(kept) } : {},
|
|
432
515
|
...Array.isArray(kept.links) ? { links: kept.links.map(link).filter((one) => !!one) } : {},
|
|
433
516
|
...Array.isArray(kept.stats) ? { stats: kept.stats.map(stat).filter((one) => !!one) } : {},
|
|
434
517
|
...kept.dropped === true ? { dropped: true } : {},
|
|
435
|
-
...
|
|
436
|
-
...
|
|
518
|
+
...time(kept.commentsAt) ? { commentsAt: time(kept.commentsAt) } : {},
|
|
519
|
+
...time(kept.commentsGap) ? { commentsGap: time(kept.commentsGap) } : {},
|
|
520
|
+
...Efficiency.fields(kept),
|
|
437
521
|
at,
|
|
438
|
-
changedAt:
|
|
522
|
+
changedAt: time(kept.changedAt) ?? at
|
|
439
523
|
};
|
|
440
524
|
}
|
|
441
525
|
CreatorUtil.item = item;
|
|
@@ -443,10 +527,10 @@ var CreatorUtil;
|
|
|
443
527
|
if (!Array.isArray(value)) {
|
|
444
528
|
return [];
|
|
445
529
|
}
|
|
446
|
-
return value.map((one) =>
|
|
530
|
+
return value.map((one) => object(one)).filter((one) => !!one && /^\d{4}-\d{2}-\d{2}$/.test(String(one.week))).map((one) => ({
|
|
447
531
|
week: String(one.week),
|
|
448
|
-
platforms: (Array.isArray(one.platforms) ? one.platforms : []).map((it) =>
|
|
449
|
-
platform:
|
|
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),
|
|
450
534
|
views: count(it.views, 0),
|
|
451
535
|
...typeof it.likes === "number" ? { likes: count(it.likes, 0) } : {},
|
|
452
536
|
...typeof it.follows === "number" ? { follows: count(it.follows, 0) } : {},
|
|
@@ -519,7 +603,7 @@ var CreatorUtil;
|
|
|
519
603
|
}
|
|
520
604
|
CreatorUtil.change = change;
|
|
521
605
|
function seriesNamed(series, value) {
|
|
522
|
-
const key =
|
|
606
|
+
const key = text(value, 60).toLowerCase();
|
|
523
607
|
return key ? series.find((one) => one.id.toLowerCase() === key || one.name.toLowerCase() === key) : undefined;
|
|
524
608
|
}
|
|
525
609
|
CreatorUtil.seriesNamed = seriesNamed;
|
|
@@ -546,7 +630,7 @@ var CreatorUtil;
|
|
|
546
630
|
}
|
|
547
631
|
CreatorUtil.views = views;
|
|
548
632
|
function setStats(items2, id, stats, now) {
|
|
549
|
-
const read = stats.map((one) => stat({ at: now, ...
|
|
633
|
+
const read = stats.map((one) => stat({ at: now, ...object(one) ?? {} })).filter((one) => !!one);
|
|
550
634
|
const before = items2.find((one) => one.id === id);
|
|
551
635
|
if (!before) {
|
|
552
636
|
throw new Error(`No such piece: ${id}.`);
|
|
@@ -559,7 +643,7 @@ var CreatorUtil;
|
|
|
559
643
|
if (!goal) {
|
|
560
644
|
return;
|
|
561
645
|
}
|
|
562
|
-
const end = goal.from + goal.days *
|
|
646
|
+
const end = goal.from + goal.days * DAY2;
|
|
563
647
|
const published = items2.filter((one) => one.stage === "published" && (one.links?.length ?? 0) > 0).filter((one) => {
|
|
564
648
|
const at = publishedAt(one);
|
|
565
649
|
return at >= goal.from && at < end;
|
|
@@ -567,7 +651,7 @@ var CreatorUtil;
|
|
|
567
651
|
return {
|
|
568
652
|
videos: published.filter((one) => one.form === "video").length,
|
|
569
653
|
posts: published.filter((one) => one.form !== "video").length,
|
|
570
|
-
day: Math.max(1, Math.min(goal.days, Math.floor((now - goal.from) /
|
|
654
|
+
day: Math.max(1, Math.min(goal.days, Math.floor((now - goal.from) / DAY2) + 1))
|
|
571
655
|
};
|
|
572
656
|
}
|
|
573
657
|
CreatorUtil.progress = progress;
|
|
@@ -604,44 +688,44 @@ var CreatorUtil;
|
|
|
604
688
|
}
|
|
605
689
|
CreatorUtil.offer = offer;
|
|
606
690
|
function need(value) {
|
|
607
|
-
const kept =
|
|
608
|
-
const words =
|
|
691
|
+
const kept = object(value);
|
|
692
|
+
const words = text(kept?.text, 300);
|
|
609
693
|
if (!kept || !words) {
|
|
610
694
|
return;
|
|
611
695
|
}
|
|
612
|
-
return { id:
|
|
696
|
+
return { id: text(kept.id, 60), text: words, ...kept.done === true ? { done: true } : {} };
|
|
613
697
|
}
|
|
614
698
|
CreatorUtil.need = need;
|
|
615
699
|
function version(value) {
|
|
616
|
-
const kept =
|
|
617
|
-
const platform2 =
|
|
700
|
+
const kept = object(value);
|
|
701
|
+
const platform2 = text(kept?.platform, 60);
|
|
618
702
|
if (!kept || !platform2) {
|
|
619
703
|
return;
|
|
620
704
|
}
|
|
621
|
-
const cover =
|
|
705
|
+
const cover = text(kept.cover, 500);
|
|
622
706
|
return {
|
|
623
707
|
platform: platform2,
|
|
624
708
|
...FORMS.includes(kept.form) ? { form: kept.form } : {},
|
|
625
|
-
title:
|
|
626
|
-
text:
|
|
709
|
+
title: text(kept.title, 200),
|
|
710
|
+
text: text(kept.text, 20000),
|
|
627
711
|
tags: texts(kept.tags, 20),
|
|
628
712
|
files: texts(kept.files, 40),
|
|
629
713
|
...cover ? { cover } : {}
|
|
630
714
|
};
|
|
631
715
|
}
|
|
632
716
|
function check(value) {
|
|
633
|
-
const kept =
|
|
634
|
-
return kept &&
|
|
717
|
+
const kept = object(value);
|
|
718
|
+
return kept && text(kept.text, 200) ? { text: text(kept.text, 200), ok: kept.ok === true } : undefined;
|
|
635
719
|
}
|
|
636
720
|
function link(value) {
|
|
637
|
-
const kept =
|
|
721
|
+
const kept = object(value);
|
|
638
722
|
const href = url(kept?.url);
|
|
639
723
|
const scheduled = PublishUtil.timeOf(kept?.scheduled);
|
|
640
|
-
return kept && href &&
|
|
724
|
+
return kept && href && text(kept.platform, 60) ? { platform: text(kept.platform, 60), url: href, at: time(kept.at) ?? Date.now(), ...scheduled ? { scheduled } : {} } : undefined;
|
|
641
725
|
}
|
|
642
726
|
function stat(value) {
|
|
643
|
-
const kept =
|
|
644
|
-
const platform2 =
|
|
727
|
+
const kept = object(value);
|
|
728
|
+
const platform2 = text(kept?.platform, 60);
|
|
645
729
|
if (!kept || !platform2 || typeof kept.views !== "number") {
|
|
646
730
|
return;
|
|
647
731
|
}
|
|
@@ -649,25 +733,23 @@ var CreatorUtil;
|
|
|
649
733
|
return {
|
|
650
734
|
platform: platform2,
|
|
651
735
|
views: count(kept.views, 0),
|
|
652
|
-
...
|
|
653
|
-
...optional("comments"),
|
|
654
|
-
...optional("follows"),
|
|
736
|
+
...Object.assign({}, ...["likes", "comments", "follows", "watch"].map(optional)),
|
|
655
737
|
...typeof kept.completion === "number" && Number.isFinite(kept.completion) ? { completion: Math.max(0, Math.min(1, kept.completion)) } : {},
|
|
656
|
-
at:
|
|
738
|
+
at: time(kept.at) ?? Date.now()
|
|
657
739
|
};
|
|
658
740
|
}
|
|
659
741
|
function source(value) {
|
|
660
|
-
const kept =
|
|
742
|
+
const kept = object(value);
|
|
661
743
|
const href = url(kept?.url);
|
|
662
|
-
return kept && href &&
|
|
744
|
+
return kept && href && text(kept.name, 80) ? { name: text(kept.name, 80), url: href } : undefined;
|
|
663
745
|
}
|
|
664
746
|
})(CreatorUtil ||= {});
|
|
665
747
|
|
|
666
748
|
// web-src/channel-util.ts
|
|
667
|
-
var
|
|
668
|
-
var
|
|
749
|
+
var HOUR2 = 3600000;
|
|
750
|
+
var DAY3 = 24 * HOUR2;
|
|
669
751
|
var MAX_COMMENTS = 600;
|
|
670
|
-
var COMMENTS_FOR = 60 *
|
|
752
|
+
var COMMENTS_FOR = 60 * DAY3;
|
|
671
753
|
var MAX_LESSONS = 40;
|
|
672
754
|
var ChannelUtil;
|
|
673
755
|
((ChannelUtil) => {
|
|
@@ -711,14 +793,14 @@ var ChannelUtil;
|
|
|
711
793
|
}
|
|
712
794
|
ChannelUtil.analysis = analysis;
|
|
713
795
|
function insights(value) {
|
|
714
|
-
const all = (Array.isArray(value) ? value : []).map((one) =>
|
|
715
|
-
const at =
|
|
716
|
-
const words =
|
|
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);
|
|
717
799
|
return {
|
|
718
|
-
id:
|
|
800
|
+
id: text(one.id, 60) || `i${hash(words + at)}`,
|
|
719
801
|
text: words,
|
|
720
802
|
tone: oneOf(["good", "bad", "idea"], one.tone, "idea"),
|
|
721
|
-
...
|
|
803
|
+
...text(one.series, 60) ? { series: text(one.series, 60) } : {},
|
|
722
804
|
...one.by === "user" ? { by: "user" } : {},
|
|
723
805
|
...one.state === "proposed" || one.state === "declined" ? { state: one.state } : {},
|
|
724
806
|
at
|
|
@@ -730,7 +812,7 @@ var ChannelUtil;
|
|
|
730
812
|
}
|
|
731
813
|
ChannelUtil.insights = insights;
|
|
732
814
|
function addInsights(kept, added, series, now, mode = "auto") {
|
|
733
|
-
const read = added.map((one) => typeof one === "string" ? { text: one } :
|
|
815
|
+
const read = added.map((one) => typeof one === "string" ? { text: one } : object(one)).filter((one) => !!one).map((one, at) => ({
|
|
734
816
|
...one,
|
|
735
817
|
id: `i${now.toString(36)}${at}`,
|
|
736
818
|
by: undefined,
|
|
@@ -742,7 +824,7 @@ var ChannelUtil;
|
|
|
742
824
|
}
|
|
743
825
|
ChannelUtil.addInsights = addInsights;
|
|
744
826
|
function addRule(kept, words, series, now, seriesId) {
|
|
745
|
-
const rule =
|
|
827
|
+
const rule = text(words, 300);
|
|
746
828
|
if (!rule) {
|
|
747
829
|
throw new Error("A rule needs its words.");
|
|
748
830
|
}
|
|
@@ -774,7 +856,7 @@ var ChannelUtil;
|
|
|
774
856
|
function latestInsights(insights2) {
|
|
775
857
|
const ta = insights2.filter((one) => one.by !== "user" && !one.state);
|
|
776
858
|
const newest = ta[0]?.at ?? 0;
|
|
777
|
-
return insights2.filter((one) => one.by === "user" || !one.state && newest - one.at <
|
|
859
|
+
return insights2.filter((one) => one.by === "user" || !one.state && newest - one.at < DAY3);
|
|
778
860
|
}
|
|
779
861
|
ChannelUtil.latestInsights = latestInsights;
|
|
780
862
|
function proposed(insights2) {
|
|
@@ -782,12 +864,12 @@ var ChannelUtil;
|
|
|
782
864
|
}
|
|
783
865
|
ChannelUtil.proposed = proposed;
|
|
784
866
|
function phases(value) {
|
|
785
|
-
return (Array.isArray(value) ? value : []).map((one) =>
|
|
786
|
-
from:
|
|
787
|
-
to:
|
|
788
|
-
summary:
|
|
789
|
-
...
|
|
790
|
-
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)
|
|
791
873
|
})).sort((a, b) => b.at - a.at).slice(0, 24);
|
|
792
874
|
}
|
|
793
875
|
ChannelUtil.phases = phases;
|
|
@@ -797,21 +879,21 @@ var ChannelUtil;
|
|
|
797
879
|
}
|
|
798
880
|
const published = items.filter((one) => one.stage === "published" && !one.dropped).map(CreatorUtil.publishedAt);
|
|
799
881
|
const from = phases2[0]?.to ?? (published.length ? Math.min(...published) : undefined);
|
|
800
|
-
if (from === undefined || now - from < settings.phaseWeeks * 7 *
|
|
882
|
+
if (from === undefined || now - from < settings.phaseWeeks * 7 * DAY3 || !published.some((at) => at >= from)) {
|
|
801
883
|
return;
|
|
802
884
|
}
|
|
803
885
|
return { from, to: now };
|
|
804
886
|
}
|
|
805
887
|
ChannelUtil.phaseDue = phaseDue;
|
|
806
888
|
function needsOf(values, now) {
|
|
807
|
-
return values.map((one, at) => CreatorUtil.need(typeof one === "string" ? { text: one } : { id: `n${now.toString(36)}${at}`, ...
|
|
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);
|
|
808
890
|
}
|
|
809
891
|
ChannelUtil.needsOf = needsOf;
|
|
810
892
|
function given(item) {
|
|
811
893
|
return (item.needs ?? []).every((one) => one.done);
|
|
812
894
|
}
|
|
813
895
|
ChannelUtil.given = given;
|
|
814
|
-
ChannelUtil.PACE = { start: 12 *
|
|
896
|
+
ChannelUtil.PACE = { start: 12 * HOUR2, first: 24 * HOUR2, min: 2 * HOUR2, max: 2 * DAY3, many: 3, ride: 0.5 };
|
|
815
897
|
function nextGap(gap, added) {
|
|
816
898
|
if (added >= ChannelUtil.PACE.many) {
|
|
817
899
|
return Math.max(ChannelUtil.PACE.min, Math.round(gap / 2));
|
|
@@ -825,7 +907,7 @@ var ChannelUtil;
|
|
|
825
907
|
}
|
|
826
908
|
ChannelUtil.firstGap = firstGap;
|
|
827
909
|
function commentsGap(item, items, settings) {
|
|
828
|
-
return settings.commentsEvery ? settings.commentsEvery *
|
|
910
|
+
return settings.commentsEvery ? settings.commentsEvery * HOUR2 : item.commentsGap ?? firstGap(items);
|
|
829
911
|
}
|
|
830
912
|
ChannelUtil.commentsGap = commentsGap;
|
|
831
913
|
function live(item, now) {
|
|
@@ -840,10 +922,31 @@ var ChannelUtil;
|
|
|
840
922
|
}
|
|
841
923
|
const published = Math.min(...out);
|
|
842
924
|
const since = now - Math.max(one.commentsAt ?? 0, published);
|
|
843
|
-
return now - published < settings.commentsDays *
|
|
925
|
+
return now - published < settings.commentsDays * DAY3 && since >= share * commentsGap(one, items, settings);
|
|
844
926
|
});
|
|
845
927
|
}
|
|
846
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;
|
|
847
950
|
function comments(value, now = Date.now()) {
|
|
848
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);
|
|
849
952
|
}
|
|
@@ -852,16 +955,16 @@ var ChannelUtil;
|
|
|
852
955
|
const all = [...kept];
|
|
853
956
|
const added = [];
|
|
854
957
|
for (const value of input) {
|
|
855
|
-
const read =
|
|
856
|
-
const platform =
|
|
857
|
-
const words =
|
|
958
|
+
const read = object(value);
|
|
959
|
+
const platform = text(read?.platform, 60);
|
|
960
|
+
const words = text(read?.text, 1000);
|
|
858
961
|
if (!read || !platform || !words) {
|
|
859
962
|
continue;
|
|
860
963
|
}
|
|
861
|
-
const key =
|
|
964
|
+
const key = text(read.key, 120) || `t${hash(words)}`;
|
|
862
965
|
const cls = oneOf(COMMENT_CLASSES, read.class, "question");
|
|
863
966
|
const level = REPLY_CLASSES.includes(cls) ? levels[cls] : "off";
|
|
864
|
-
const answer =
|
|
967
|
+
const answer = text(read.reply, 500);
|
|
865
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;
|
|
866
969
|
const at = all.findIndex((one) => one.item === item && one.platform === platform && one.key === key);
|
|
867
970
|
if (at >= 0) {
|
|
@@ -896,25 +999,25 @@ var ChannelUtil;
|
|
|
896
999
|
}
|
|
897
1000
|
ChannelUtil.examples = examples;
|
|
898
1001
|
function lessons(value) {
|
|
899
|
-
return (Array.isArray(value) ? value : []).map((one) =>
|
|
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);
|
|
900
1003
|
}
|
|
901
1004
|
ChannelUtil.lessons = lessons;
|
|
902
1005
|
function comment(value) {
|
|
903
|
-
const kept =
|
|
904
|
-
const id =
|
|
905
|
-
const words =
|
|
906
|
-
const at =
|
|
907
|
-
if (!kept || !id || !words || !at || !
|
|
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)) {
|
|
908
1011
|
return;
|
|
909
1012
|
}
|
|
910
|
-
const reply =
|
|
911
|
-
const answer =
|
|
912
|
-
const draft =
|
|
1013
|
+
const reply = object(kept.reply);
|
|
1014
|
+
const answer = text(reply?.text, 500);
|
|
1015
|
+
const draft = text(reply?.draft, 500);
|
|
913
1016
|
return {
|
|
914
1017
|
id,
|
|
915
|
-
item:
|
|
916
|
-
platform:
|
|
917
|
-
key:
|
|
1018
|
+
item: text(kept.item, 80),
|
|
1019
|
+
platform: text(kept.platform, 60),
|
|
1020
|
+
key: text(kept.key, 120) || `t${hash(words)}`,
|
|
918
1021
|
text: words,
|
|
919
1022
|
class: oneOf(COMMENT_CLASSES, kept.class, "question"),
|
|
920
1023
|
...typeof kept.likes === "number" ? { likes: count(kept.likes, 0) } : {},
|
|
@@ -924,10 +1027,10 @@ var ChannelUtil;
|
|
|
924
1027
|
state: oneOf(REPLY_STATES, reply.state, "draft"),
|
|
925
1028
|
...reply.auto === true ? { auto: true } : {},
|
|
926
1029
|
...draft ? { draft } : {},
|
|
927
|
-
at:
|
|
1030
|
+
at: time(reply.at) ?? at
|
|
928
1031
|
}
|
|
929
1032
|
} : {},
|
|
930
|
-
...
|
|
1033
|
+
...text(kept.topic, 80) ? { topic: text(kept.topic, 80) } : {},
|
|
931
1034
|
at
|
|
932
1035
|
};
|
|
933
1036
|
}
|
|
@@ -955,7 +1058,7 @@ var CreatorTasks;
|
|
|
955
1058
|
notify: "error",
|
|
956
1059
|
prompt: [
|
|
957
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).`,
|
|
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.",
|
|
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.",
|
|
959
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.",
|
|
960
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].',
|
|
961
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.',
|
|
@@ -966,7 +1069,7 @@ var CreatorTasks;
|
|
|
966
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.`,
|
|
967
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.`,
|
|
968
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? }>'\`.`,
|
|
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."
|
|
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."
|
|
970
1073
|
].join(`
|
|
971
1074
|
`)
|
|
972
1075
|
};
|
|
@@ -978,7 +1081,7 @@ var CreatorTasks;
|
|
|
978
1081
|
prompt: [
|
|
979
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.`,
|
|
980
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):",
|
|
981
|
-
`- 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) }>'\`;`,
|
|
982
1085
|
`- for last week, each platform: \`${call("week")} <monday YYYY-MM-DD> '<JSON array of { platform, views, likes?, follows?, completion? }>'\`.`,
|
|
983
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.`,
|
|
984
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.`,
|
|
@@ -993,14 +1096,16 @@ var CreatorTasks;
|
|
|
993
1096
|
when: "cron 30 21 * * *",
|
|
994
1097
|
notify: "error",
|
|
995
1098
|
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.`,
|
|
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.",
|
|
997
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.",
|
|
998
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" }>'\`.`,
|
|
999
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).",
|
|
1000
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.",
|
|
1001
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.`,
|
|
1002
|
-
|
|
1003
|
-
"
|
|
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."
|
|
1004
1109
|
].join(`
|
|
1005
1110
|
`)
|
|
1006
1111
|
};
|
|
@@ -1502,11 +1607,11 @@ class CreatorHostBase {
|
|
|
1502
1607
|
return stage ? items.filter((one) => one.stage === stage && !one.dropped) : items;
|
|
1503
1608
|
}
|
|
1504
1609
|
update(id, patch) {
|
|
1505
|
-
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"];
|
|
1506
1611
|
return this.change(id, Object.fromEntries(Object.entries(patch ?? {}).filter(([key]) => !kept.includes(key))));
|
|
1507
1612
|
}
|
|
1508
1613
|
start(id) {
|
|
1509
|
-
return this.change(id, { stage: "making", done: [] });
|
|
1614
|
+
return this.change(id, { stage: "making", done: [], started: this.now() });
|
|
1510
1615
|
}
|
|
1511
1616
|
async remove(id) {
|
|
1512
1617
|
const item = (await this.items()).find((one) => one.id === id);
|
|
@@ -1520,7 +1625,7 @@ class CreatorHostBase {
|
|
|
1520
1625
|
}
|
|
1521
1626
|
stats(id, stats) {
|
|
1522
1627
|
if (!Array.isArray(stats)) {
|
|
1523
|
-
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? }."));
|
|
1524
1629
|
}
|
|
1525
1630
|
return this.serial(async () => {
|
|
1526
1631
|
const items = CreatorUtil.setStats(await this.items(), id, stats, this.now());
|
|
@@ -1550,6 +1655,7 @@ class CreatorHostBase {
|
|
|
1550
1655
|
const now = this.now();
|
|
1551
1656
|
const item = await this.change(id, { approved: now, publishing: { state: "queued", since: now, ...ask ? { ask: String(ask) } : {} } }, minutes);
|
|
1552
1657
|
this.publisher.pump();
|
|
1658
|
+
this.measure(item.id);
|
|
1553
1659
|
return item;
|
|
1554
1660
|
}
|
|
1555
1661
|
async stopped(id, why) {
|
|
@@ -1635,13 +1741,15 @@ class CreatorHostBase {
|
|
|
1635
1741
|
const task = CreatorTasks.of(id);
|
|
1636
1742
|
const v = CreatorTasks.version(task);
|
|
1637
1743
|
if (on && !record) {
|
|
1638
|
-
const added = await this.host.callPackageHost(CRON, "add", [task]);
|
|
1744
|
+
const added = await this.host.callPackageHost(CRON, "add", [{ ...task, owner: NAME }]);
|
|
1639
1745
|
next[id] = { id: added.id, v };
|
|
1640
1746
|
} else if (record && "id" in record && !tasks.some((one) => one.id === record.id)) {
|
|
1641
1747
|
next[id] = { removed: true };
|
|
1642
1748
|
} else if (on && record && "id" in record && record.v !== v) {
|
|
1643
|
-
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 }]);
|
|
1644
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 }]);
|
|
1645
1753
|
}
|
|
1646
1754
|
if (!on && record) {
|
|
1647
1755
|
if ("id" in record && tasks.some((task2) => task2.id === record.id)) {
|
|
@@ -1659,6 +1767,19 @@ class CreatorHostBase {
|
|
|
1659
1767
|
return;
|
|
1660
1768
|
});
|
|
1661
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
|
+
}
|
|
1662
1783
|
items() {
|
|
1663
1784
|
return this.data(Keys.ITEMS).then(CreatorUtil.items);
|
|
1664
1785
|
}
|
|
@@ -1697,7 +1818,7 @@ class CreatorHostBase {
|
|
|
1697
1818
|
// web-src/host.ts
|
|
1698
1819
|
var CRON2 = "@celljs/ta-cron";
|
|
1699
1820
|
var INITIATIVE = "@celljs/ta-initiative";
|
|
1700
|
-
var
|
|
1821
|
+
var DAY4 = 86400000;
|
|
1701
1822
|
var TICK = 10 * 60000;
|
|
1702
1823
|
var RUN_GAP = 2 * 3600000;
|
|
1703
1824
|
var SEND_GAP = 5 * 60000;
|
|
@@ -1755,7 +1876,7 @@ class CreatorHost extends CreatorHostBase {
|
|
|
1755
1876
|
...one.by ? { by: one.by } : {}
|
|
1756
1877
|
}));
|
|
1757
1878
|
const insights = strategy;
|
|
1758
|
-
const asked = comments.filter((one) => (one.class === "question" || one.class === "suggestion") && !one.topic && now - one.at < 14 *
|
|
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 }));
|
|
1759
1880
|
switch (task) {
|
|
1760
1881
|
case "topics":
|
|
1761
1882
|
return {
|
|
@@ -1766,29 +1887,29 @@ class CreatorHost extends CreatorHostBase {
|
|
|
1766
1887
|
id: one.id,
|
|
1767
1888
|
title: one.title,
|
|
1768
1889
|
missing: (one.needs ?? []).filter((need) => !need.done).map((need) => need.text),
|
|
1769
|
-
days: Math.floor((now - one.changedAt) /
|
|
1890
|
+
days: Math.floor((now - one.changedAt) / DAY4)
|
|
1770
1891
|
})),
|
|
1771
1892
|
niche: settings.niche,
|
|
1772
1893
|
platforms,
|
|
1773
1894
|
inside: CreatorUtil.picked(settings).filter((one) => one.internal).map((one) => one.name),
|
|
1774
1895
|
sources: settings.sources,
|
|
1775
|
-
offer: CreatorUtil.offer(settings, weeks, now),
|
|
1776
|
-
titles: items.filter((one) => now - one.at < 30 *
|
|
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),
|
|
1777
1898
|
waiting: columns.topic.length
|
|
1778
1899
|
};
|
|
1779
1900
|
case "review": {
|
|
1780
|
-
const week = CreatorUtil.weekOf(now - 7 *
|
|
1901
|
+
const week = CreatorUtil.weekOf(now - 7 * DAY4);
|
|
1781
1902
|
const from = new Date(`${week}T00:00:00`).getTime();
|
|
1782
1903
|
return {
|
|
1783
1904
|
week,
|
|
1784
1905
|
platforms,
|
|
1785
1906
|
published: items.filter((one) => one.stage === "published").filter((one) => {
|
|
1786
1907
|
const at = CreatorUtil.publishedAt(one);
|
|
1787
|
-
return at >= from && at < from + 7 *
|
|
1908
|
+
return at >= from && at < from + 7 * DAY4;
|
|
1788
1909
|
}).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 *
|
|
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 })),
|
|
1790
1911
|
series,
|
|
1791
|
-
numbers: weeks.filter((one) => one.week >= CreatorUtil.weekOf(now - 21 *
|
|
1912
|
+
numbers: weeks.filter((one) => one.week >= CreatorUtil.weekOf(now - 21 * DAY4)),
|
|
1792
1913
|
minutes: weeks.find((one) => one.week === week)?.minutes ?? 0,
|
|
1793
1914
|
minutesCap: settings.minutesCap,
|
|
1794
1915
|
goal: settings.goal ? { ...settings.goal, progress: CreatorUtil.progress(items, settings.goal, now) } : undefined,
|
|
@@ -1856,6 +1977,12 @@ class CreatorHost extends CreatorHostBase {
|
|
|
1856
1977
|
comment: one.text,
|
|
1857
1978
|
reply: one.reply?.text
|
|
1858
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
|
+
})),
|
|
1859
1986
|
levels: await this.levels(),
|
|
1860
1987
|
tone: CreatorUtil.toneOf(undefined, settings),
|
|
1861
1988
|
examples: ChannelUtil.examples(comments),
|
|
@@ -1880,7 +2007,7 @@ class CreatorHost extends CreatorHostBase {
|
|
|
1880
2007
|
comments: {
|
|
1881
2008
|
byClass: Object.fromEntries(["question", "suggestion", "correction", "praise", "negative", "spam"].map((cls) => [
|
|
1882
2009
|
cls,
|
|
1883
|
-
comments.filter((one) => one.class === cls && now - one.at < 28 *
|
|
2010
|
+
comments.filter((one) => one.class === cls && now - one.at < 28 * DAY4).length
|
|
1884
2011
|
])),
|
|
1885
2012
|
asked
|
|
1886
2013
|
}
|
|
@@ -2073,11 +2200,26 @@ class CreatorHost extends CreatorHostBase {
|
|
|
2073
2200
|
}
|
|
2074
2201
|
const [items, comments, settings] = await Promise.all([this.items(), this.commentsKept(), this.settings()]);
|
|
2075
2202
|
const sending = comments.some((one) => one.reply?.state === "approved" || one.reply?.state === "withdrawn");
|
|
2076
|
-
const due = ChannelUtil.due(items, settings, now).length > 0;
|
|
2203
|
+
const due = ChannelUtil.due(items, settings, now).length > 0 || ChannelUtil.statsDue(items, now).length > 0;
|
|
2077
2204
|
if (sending && now - this.ranAt >= SEND_GAP || due && now - this.ranAt >= RUN_GAP) {
|
|
2078
2205
|
await this.runComments();
|
|
2079
2206
|
}
|
|
2080
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
|
+
}
|
|
2081
2223
|
runSoon() {
|
|
2082
2224
|
if (this.soon) {
|
|
2083
2225
|
return;
|