@celljs/ta-creator 4.32.1 → 4.34.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 +3 -1
- package/README.md +10 -2
- package/host/index.mjs +1576 -279
- package/package.json +3 -3
- package/skills/creator-make/SKILL.md +41 -15
- package/skills/creator-publish/SKILL.md +24 -8
- package/skills/creator-publish/platforms.md +112 -0
- package/web/index.js +1761 -258
package/host/index.mjs
CHANGED
|
@@ -8,11 +8,31 @@ var Keys;
|
|
|
8
8
|
Keys.WEEKS = "weeks";
|
|
9
9
|
Keys.TASKS = "tasks";
|
|
10
10
|
Keys.INSIGHTS = "insights";
|
|
11
|
+
Keys.COMMENTS = "comments";
|
|
12
|
+
Keys.LESSONS = "lessons";
|
|
13
|
+
Keys.PHASES = "phases";
|
|
11
14
|
})(Keys ||= {});
|
|
12
|
-
var STAGES = ["topic", "making", "review", "published"];
|
|
13
|
-
var FORMS = ["video", "post"];
|
|
14
|
-
var
|
|
15
|
+
var STAGES = ["topic", "materials", "making", "review", "published"];
|
|
16
|
+
var FORMS = ["video", "post", "article", "note"];
|
|
17
|
+
var FORM_FALLBACKS = {
|
|
18
|
+
video: ["video", "article", "post"],
|
|
19
|
+
post: ["post", "note", "article"],
|
|
20
|
+
article: ["article", "post", "note"],
|
|
21
|
+
note: ["note", "post"]
|
|
22
|
+
};
|
|
23
|
+
var KINDS = ["hot", "howto", "explain", "original"];
|
|
15
24
|
var STEPS = ["script", "visuals", "voice", "captions", "versions", "checks"];
|
|
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
|
+
};
|
|
16
36
|
var SERIES_COLORS = ["#22c55e", "#f97316", "#3b82f6", "#a855f7", "#ec4899", "#14b8a6", "#eab308", "#64748b"];
|
|
17
37
|
var ASPECTS = ["16:9", "9:16", "3:4", "1:1"];
|
|
18
38
|
var PLATFORMS = [
|
|
@@ -21,6 +41,8 @@ var PLATFORMS = [
|
|
|
21
41
|
name: "B站",
|
|
22
42
|
color: "#fb7299",
|
|
23
43
|
video: { aspect: "16:9" },
|
|
44
|
+
article: {},
|
|
45
|
+
note: { maxChars: 1000 },
|
|
24
46
|
publish: "https://member.bilibili.com/platform/upload/video/frame",
|
|
25
47
|
declare: "创作声明 → 该视频使用人工智能合成技术"
|
|
26
48
|
},
|
|
@@ -30,6 +52,7 @@ var PLATFORMS = [
|
|
|
30
52
|
color: "#ff2442",
|
|
31
53
|
video: { aspect: "3:4", maxSeconds: 900 },
|
|
32
54
|
post: { aspect: "3:4", maxImages: 18 },
|
|
55
|
+
article: {},
|
|
33
56
|
publish: "https://creator.xiaohongshu.com",
|
|
34
57
|
declare: "内容类型声明 → 笔记含 AI 合成内容"
|
|
35
58
|
},
|
|
@@ -38,6 +61,7 @@ var PLATFORMS = [
|
|
|
38
61
|
name: "视频号",
|
|
39
62
|
color: "#fa9d3b",
|
|
40
63
|
video: { aspect: "9:16" },
|
|
64
|
+
post: { aspect: "3:4", maxImages: 9 },
|
|
41
65
|
publish: "https://channels.weixin.qq.com",
|
|
42
66
|
declare: "声明 → 内容由 AI 生成"
|
|
43
67
|
},
|
|
@@ -56,6 +80,7 @@ var PLATFORMS = [
|
|
|
56
80
|
name: "YouTube",
|
|
57
81
|
color: "#ff0033",
|
|
58
82
|
video: { aspect: "16:9" },
|
|
83
|
+
note: { maxChars: 1500 },
|
|
59
84
|
publish: "https://studio.youtube.com",
|
|
60
85
|
declare: "Altered or synthetic content → Yes"
|
|
61
86
|
},
|
|
@@ -63,9 +88,19 @@ var PLATFORMS = [
|
|
|
63
88
|
id: "wechat-article",
|
|
64
89
|
name: "公众号",
|
|
65
90
|
color: "#07c160",
|
|
66
|
-
|
|
91
|
+
article: {},
|
|
67
92
|
publish: "https://mp.weixin.qq.com",
|
|
68
93
|
declare: "创作来源 → 内容由 AI 生成"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: "zhihu",
|
|
97
|
+
name: "知乎",
|
|
98
|
+
color: "#1772f6",
|
|
99
|
+
video: { aspect: "16:9" },
|
|
100
|
+
article: {},
|
|
101
|
+
note: { maxChars: 1000 },
|
|
102
|
+
publish: "https://www.zhihu.com/creator",
|
|
103
|
+
declare: "创作声明 → 包含 AI 辅助创作"
|
|
69
104
|
}
|
|
70
105
|
];
|
|
71
106
|
var SOURCES = [
|
|
@@ -74,85 +109,276 @@ var SOURCES = [
|
|
|
74
109
|
{ name: "Product Hunt", url: "https://www.producthunt.com" },
|
|
75
110
|
{ name: "Hugging Face Papers", url: "https://huggingface.co/papers" }
|
|
76
111
|
];
|
|
112
|
+
var COMMENT_CLASSES = ["question", "suggestion", "correction", "praise", "negative", "spam"];
|
|
113
|
+
var REPLY_CLASSES = ["question", "suggestion", "correction", "praise"];
|
|
114
|
+
var REPLY_STATES = ["draft", "approved", "sent", "dropped", "withdrawn", "removed"];
|
|
115
|
+
var REPLY_KINDS = {
|
|
116
|
+
question: {
|
|
117
|
+
id: "creator.reply-question",
|
|
118
|
+
owner: NAME,
|
|
119
|
+
title: { en: "Answer questions in the comments", zh: "回复评论里的提问", tw: "回覆留言裡的提問", ja: "コメントの質問に返信" },
|
|
120
|
+
reversible: true,
|
|
121
|
+
level: "act"
|
|
122
|
+
},
|
|
123
|
+
praise: {
|
|
124
|
+
id: "creator.reply-praise",
|
|
125
|
+
owner: NAME,
|
|
126
|
+
title: { en: "Thank those who praise a piece", zh: "感谢评论里的夸奖", tw: "感謝留言裡的稱讚", ja: "コメントの称賛にお礼" },
|
|
127
|
+
reversible: true,
|
|
128
|
+
level: "act"
|
|
129
|
+
},
|
|
130
|
+
suggestion: {
|
|
131
|
+
id: "creator.reply-suggestion",
|
|
132
|
+
owner: NAME,
|
|
133
|
+
title: { en: "Answer suggestions in the comments", zh: "回复评论里的建议", tw: "回覆留言裡的建議", ja: "コメントの提案に返信" },
|
|
134
|
+
reversible: true,
|
|
135
|
+
level: "ask"
|
|
136
|
+
},
|
|
137
|
+
correction: {
|
|
138
|
+
id: "creator.reply-correction",
|
|
139
|
+
owner: NAME,
|
|
140
|
+
title: { en: "Answer corrections in the comments", zh: "回复评论里的纠错", tw: "回覆留言裡的糾錯", ja: "コメントの指摘に返信" },
|
|
141
|
+
reversible: true,
|
|
142
|
+
level: "ask"
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// web-src/publish-util.ts
|
|
147
|
+
var text = (value, max) => typeof value === "string" ? value.trim().slice(0, max) : "";
|
|
148
|
+
var time = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined;
|
|
149
|
+
var object = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
150
|
+
var PublishUtil;
|
|
151
|
+
((PublishUtil) => {
|
|
152
|
+
function dayOf(at) {
|
|
153
|
+
const day = new Date(at);
|
|
154
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
155
|
+
return `${day.getFullYear()}-${two(day.getMonth() + 1)}-${two(day.getDate())}`;
|
|
156
|
+
}
|
|
157
|
+
PublishUtil.dayOf = dayOf;
|
|
158
|
+
function publishQueue(items) {
|
|
159
|
+
const due = (item) => item.kind === "hot" && item.until ? item.until : Number.POSITIVE_INFINITY;
|
|
160
|
+
return items.filter((one) => one.publishing?.state === "queued" && !one.dropped).sort((a, b) => due(a) - due(b) || (a.approved ?? a.changedAt) - (b.approved ?? b.changedAt));
|
|
161
|
+
}
|
|
162
|
+
PublishUtil.publishQueue = publishQueue;
|
|
163
|
+
function ahead(items, id) {
|
|
164
|
+
const running = items.some((one) => one.publishing?.state === "running" && !one.dropped && one.id !== id) ? 1 : 0;
|
|
165
|
+
const at = publishQueue(items).findIndex((one) => one.id === id);
|
|
166
|
+
return at < 0 ? 0 : at + running;
|
|
167
|
+
}
|
|
168
|
+
PublishUtil.ahead = ahead;
|
|
169
|
+
function slots(items, item, now, hour = 12) {
|
|
170
|
+
const done = new Set((item.links ?? []).map((one) => one.platform));
|
|
171
|
+
const platforms = [
|
|
172
|
+
...new Set((item.versions ?? []).filter((one) => one.files.length || ["article", "note"].includes(one.form ?? item.form) && !!one.text).map((one) => one.platform))
|
|
173
|
+
].filter((one) => !done.has(one));
|
|
174
|
+
const others = items.filter((one) => one.id !== item.id && !one.dropped);
|
|
175
|
+
return platforms.map((platform) => {
|
|
176
|
+
const taken = new Set([
|
|
177
|
+
...others.flatMap((one) => (one.links ?? []).filter((link) => link.platform === platform).map((link) => dayOf(link.scheduled ?? link.at))),
|
|
178
|
+
...others.filter((one) => one.publishing?.state === "running").flatMap((one) => (one.publishing?.slots ?? []).filter((slot) => slot.platform === platform).map((slot) => dayOf(slot.at ?? one.publishing?.since ?? now)))
|
|
179
|
+
]);
|
|
180
|
+
if (!taken.has(dayOf(now))) {
|
|
181
|
+
return { platform };
|
|
182
|
+
}
|
|
183
|
+
const day = new Date(now);
|
|
184
|
+
day.setHours(hour, 0, 0, 0);
|
|
185
|
+
do {
|
|
186
|
+
day.setDate(day.getDate() + 1);
|
|
187
|
+
} while (taken.has(dayOf(day.getTime())));
|
|
188
|
+
return { platform, at: day.getTime() };
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
PublishUtil.slots = slots;
|
|
192
|
+
function timeOf(value) {
|
|
193
|
+
if (typeof value === "string" && /^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}/.test(value.trim())) {
|
|
194
|
+
const at = new Date(value.trim().replace(" ", "T")).getTime();
|
|
195
|
+
return Number.isFinite(at) ? at : undefined;
|
|
196
|
+
}
|
|
197
|
+
return time(value);
|
|
198
|
+
}
|
|
199
|
+
PublishUtil.timeOf = timeOf;
|
|
200
|
+
function of(piece) {
|
|
201
|
+
const approved = time(piece.approved);
|
|
202
|
+
return publishing(piece.publishing) ?? (piece.stage === "review" && approved && !piece.publishing ? { state: "queued", since: approved } : undefined);
|
|
203
|
+
}
|
|
204
|
+
PublishUtil.of = of;
|
|
205
|
+
function publishing(value) {
|
|
206
|
+
const kept = object(value);
|
|
207
|
+
const since = time(kept?.since);
|
|
208
|
+
const state = kept && ["queued", "running", "stopped"].find((one) => one === kept.state);
|
|
209
|
+
if (!kept || !since || !state) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const slots2 = Array.isArray(kept.slots) ? kept.slots.map((one) => object(one)).filter((one) => !!one && !!text(one.platform, 60)).map((one) => ({ platform: text(one.platform, 60), ...time(one.at) ? { at: time(one.at) } : {} })) : undefined;
|
|
213
|
+
return {
|
|
214
|
+
state,
|
|
215
|
+
since,
|
|
216
|
+
...slots2 ? { slots: slots2 } : {},
|
|
217
|
+
...text(kept.note, 300) ? { note: text(kept.note, 300) } : {},
|
|
218
|
+
...text(kept.ask, 500) ? { ask: text(kept.ask, 500) } : {}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
PublishUtil.publishing = publishing;
|
|
222
|
+
})(PublishUtil ||= {});
|
|
223
|
+
|
|
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
|
+
}
|
|
77
244
|
|
|
78
245
|
// web-src/creator-util.ts
|
|
79
246
|
var DAY = 86400000;
|
|
80
247
|
var MAX_TOPICS = 200;
|
|
81
248
|
var HOT_FOR = 2 * DAY;
|
|
82
|
-
var
|
|
83
|
-
var texts = (value, max = 50) => Array.isArray(value) ? value.map((one) => text(one, 200)).filter(Boolean).slice(0, max) : [];
|
|
84
|
-
var time = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined;
|
|
85
|
-
var oneOf = (all, value, fallback) => all.includes(value) ? value : fallback;
|
|
86
|
-
var object = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
249
|
+
var MAX_TONES = 3;
|
|
87
250
|
var CreatorUtil;
|
|
88
251
|
((CreatorUtil) => {
|
|
89
252
|
function settings(value) {
|
|
90
|
-
const kept =
|
|
91
|
-
const platforms = Array.isArray(kept.platforms) ? kept.platforms.map(platform).filter((one) => !!one) : [...PLATFORMS];
|
|
253
|
+
const kept = object2(value) ?? {};
|
|
254
|
+
const platforms = Array.isArray(kept.platforms) ? withBuiltins(kept.platforms.map(platform).filter((one) => !!one)) : [...PLATFORMS];
|
|
92
255
|
const ids = new Set(platforms.map((one) => one.id));
|
|
93
|
-
const goal =
|
|
256
|
+
const goal = object2(kept.goal);
|
|
94
257
|
return {
|
|
95
|
-
niche:
|
|
258
|
+
niche: text2(kept.niche, 500),
|
|
96
259
|
picked: texts(kept.picked).filter((id) => ids.has(id)),
|
|
97
260
|
platforms,
|
|
98
261
|
sources: Array.isArray(kept.sources) ? kept.sources.map(source).filter((one) => !!one) : [...SOURCES],
|
|
99
|
-
...goal &&
|
|
262
|
+
...goal && time2(goal.from) ? { goal: { from: time2(goal.from), days: count(goal.days, 30), videos: count(goal.videos, 0), posts: count(goal.posts, 0) } } : {},
|
|
100
263
|
minutesCap: count(kept.minutesCap, 120),
|
|
101
|
-
voice:
|
|
102
|
-
|
|
264
|
+
voice: text2(kept.voice, 60) || "zh-CN-XiaoxiaoNeural",
|
|
265
|
+
tone: tones(kept.tone),
|
|
266
|
+
series: Array.isArray(kept.series) ? seriesOf(kept.series) : [],
|
|
267
|
+
strategy: kept.strategy === "manual" ? "manual" : "auto",
|
|
268
|
+
phaseWeeks: typeof kept.phaseWeeks === "number" ? Math.min(26, count(kept.phaseWeeks, 4)) : 4,
|
|
269
|
+
commentsEvery: Math.min(72, count(kept.commentsEvery, 0)),
|
|
270
|
+
commentsDays: Math.max(1, Math.min(60, count(kept.commentsDays, 14)))
|
|
103
271
|
};
|
|
104
272
|
}
|
|
105
273
|
CreatorUtil.settings = settings;
|
|
274
|
+
function withBuiltins(kept) {
|
|
275
|
+
const forms = (one) => ({ video: one.video, post: one.post, article: one.article, note: one.note });
|
|
276
|
+
const known = kept.map((one) => {
|
|
277
|
+
const builtin = PLATFORMS.find((it) => it.id === one.id);
|
|
278
|
+
if (!builtin) {
|
|
279
|
+
return one;
|
|
280
|
+
}
|
|
281
|
+
const { video: _v, post: _p, article: _a, note: _n, ...rest } = one;
|
|
282
|
+
return JSON.parse(JSON.stringify({ ...rest, ...forms(builtin) }));
|
|
283
|
+
});
|
|
284
|
+
return [...known, ...PLATFORMS.filter((one) => !kept.some((it) => it.id === one.id))];
|
|
285
|
+
}
|
|
286
|
+
CreatorUtil.withBuiltins = withBuiltins;
|
|
287
|
+
function tones(value) {
|
|
288
|
+
return [
|
|
289
|
+
...new Set(texts(value).map((one) => text2(one, 20)).filter(Boolean))
|
|
290
|
+
].slice(0, MAX_TONES);
|
|
291
|
+
}
|
|
292
|
+
CreatorUtil.tones = tones;
|
|
293
|
+
function toneOf(item2, settings2) {
|
|
294
|
+
const own = settings2.series.find((one) => one.id === item2?.series)?.tone;
|
|
295
|
+
return (own ? [own] : settings2.tone).map((one) => (one in TONES) ? TONES[one] : one);
|
|
296
|
+
}
|
|
297
|
+
CreatorUtil.toneOf = toneOf;
|
|
298
|
+
function reach(item2, settings2) {
|
|
299
|
+
return item2.reach ?? settings2.series.find((one) => one.id === item2.series)?.reach ?? "public";
|
|
300
|
+
}
|
|
301
|
+
CreatorUtil.reach = reach;
|
|
302
|
+
function platformsFor(settings2, item2) {
|
|
303
|
+
const to = reach(item2, settings2);
|
|
304
|
+
return picked(settings2).filter((platform2) => to === "both" || to === "internal" === !!platform2.internal).map((platform2) => ({ platform: platform2, form: formFor(platform2, item2.form) })).filter((one) => !!one.form);
|
|
305
|
+
}
|
|
306
|
+
CreatorUtil.platformsFor = platformsFor;
|
|
307
|
+
function takes(platform2, form) {
|
|
308
|
+
return !!platform2[form];
|
|
309
|
+
}
|
|
310
|
+
CreatorUtil.takes = takes;
|
|
311
|
+
function formFor(platform2, form) {
|
|
312
|
+
return FORM_FALLBACKS[form].find((one) => takes(platform2, one));
|
|
313
|
+
}
|
|
314
|
+
CreatorUtil.formFor = formFor;
|
|
315
|
+
function ready(version2, form) {
|
|
316
|
+
return version2.files.length > 0 || (version2.form ?? form) !== "video" && (version2.form ?? form) !== "post" && !!version2.text;
|
|
317
|
+
}
|
|
318
|
+
CreatorUtil.ready = ready;
|
|
106
319
|
function seriesOf(values) {
|
|
107
320
|
const all = [];
|
|
108
321
|
for (const value of values) {
|
|
109
|
-
const kept =
|
|
110
|
-
const name =
|
|
322
|
+
const kept = object2(value);
|
|
323
|
+
const name = text2(kept?.name, 40);
|
|
111
324
|
if (!kept || !name) {
|
|
112
325
|
continue;
|
|
113
326
|
}
|
|
114
|
-
const id =
|
|
327
|
+
const id = text2(kept.id, 60) || `s${hash(name)}`;
|
|
115
328
|
if (all.some((one) => one.id === id)) {
|
|
116
329
|
continue;
|
|
117
330
|
}
|
|
118
|
-
const about =
|
|
331
|
+
const about = text2(kept.about, 200);
|
|
119
332
|
const perWeek = count(kept.perWeek, 0);
|
|
333
|
+
const tone = text2(kept.tone, 20);
|
|
120
334
|
all.push({
|
|
121
335
|
id,
|
|
122
336
|
name,
|
|
123
337
|
...about ? { about } : {},
|
|
124
|
-
color:
|
|
338
|
+
color: text2(kept.color, 40) || SERIES_COLORS[all.length % SERIES_COLORS.length],
|
|
125
339
|
...kept.ordered === true ? { ordered: true } : {},
|
|
126
|
-
...perWeek ? { perWeek: Math.min(perWeek, 14) } : {}
|
|
340
|
+
...perWeek ? { perWeek: Math.min(perWeek, 14) } : {},
|
|
341
|
+
...kept.reach === "internal" || kept.reach === "both" ? { reach: kept.reach } : {},
|
|
342
|
+
...tone ? { tone } : {}
|
|
127
343
|
});
|
|
128
344
|
}
|
|
129
345
|
return all.slice(0, 12);
|
|
130
346
|
}
|
|
131
347
|
CreatorUtil.seriesOf = seriesOf;
|
|
132
348
|
function platform(value) {
|
|
133
|
-
const kept =
|
|
134
|
-
const id =
|
|
135
|
-
const name =
|
|
349
|
+
const kept = object2(value);
|
|
350
|
+
const id = text2(kept?.id, 60);
|
|
351
|
+
const name = text2(kept?.name, 60);
|
|
136
352
|
if (!kept || !id || !name) {
|
|
137
353
|
return;
|
|
138
354
|
}
|
|
139
355
|
const shape = (one) => {
|
|
140
|
-
const it =
|
|
356
|
+
const it = object2(one);
|
|
141
357
|
return it ? { aspect: oneOf(ASPECTS, it.aspect, "16:9"), ...count(it.maxSeconds, 0) ? { maxSeconds: count(it.maxSeconds, 0) } : {} } : undefined;
|
|
142
358
|
};
|
|
143
359
|
const video = shape(kept.video);
|
|
144
|
-
const post =
|
|
145
|
-
aspect: oneOf(ASPECTS,
|
|
146
|
-
...count(
|
|
360
|
+
const post = object2(kept.post) ? {
|
|
361
|
+
aspect: oneOf(ASPECTS, object2(kept.post)?.aspect, "3:4"),
|
|
362
|
+
...count(object2(kept.post)?.maxImages, 0) ? { maxImages: count(object2(kept.post)?.maxImages, 0) } : {}
|
|
147
363
|
} : undefined;
|
|
364
|
+
const words = (one) => {
|
|
365
|
+
const it = object2(one);
|
|
366
|
+
return it ? count(it.maxChars, 0) ? { maxChars: count(it.maxChars, 0) } : {} : undefined;
|
|
367
|
+
};
|
|
368
|
+
const article = words(kept.article);
|
|
369
|
+
const note = words(kept.note);
|
|
148
370
|
const publish = url(kept.publish);
|
|
149
|
-
const declare =
|
|
371
|
+
const declare = text2(kept.declare, 200);
|
|
372
|
+
const inside = kept.internal === true ? { internal: true } : {};
|
|
150
373
|
return {
|
|
374
|
+
...inside,
|
|
151
375
|
id,
|
|
152
376
|
name,
|
|
153
|
-
color:
|
|
377
|
+
color: text2(kept.color, 40) || "#8e8e93",
|
|
154
378
|
...video ? { video } : {},
|
|
155
379
|
...post ? { post } : {},
|
|
380
|
+
...article ? { article } : {},
|
|
381
|
+
...note ? { note } : {},
|
|
156
382
|
...publish ? { publish } : {},
|
|
157
383
|
...declare ? { declare } : {}
|
|
158
384
|
};
|
|
@@ -163,14 +389,14 @@ var CreatorUtil;
|
|
|
163
389
|
}
|
|
164
390
|
CreatorUtil.items = items;
|
|
165
391
|
function item(value) {
|
|
166
|
-
const kept =
|
|
167
|
-
const id =
|
|
168
|
-
const title =
|
|
169
|
-
const at =
|
|
392
|
+
const kept = object2(value);
|
|
393
|
+
const id = text2(kept?.id, 80);
|
|
394
|
+
const title = text2(kept?.title, 200);
|
|
395
|
+
const at = time2(kept?.at);
|
|
170
396
|
if (!kept || !id || !title || !at) {
|
|
171
397
|
return;
|
|
172
398
|
}
|
|
173
|
-
const origin =
|
|
399
|
+
const origin = object2(kept.origin);
|
|
174
400
|
const originUrl = url(origin?.url);
|
|
175
401
|
return {
|
|
176
402
|
id,
|
|
@@ -178,31 +404,38 @@ var CreatorUtil;
|
|
|
178
404
|
form: oneOf(FORMS, kept.form, "video"),
|
|
179
405
|
kind: oneOf(KINDS, kept.kind, "howto"),
|
|
180
406
|
stage: oneOf(STAGES, kept.stage, "topic"),
|
|
181
|
-
...
|
|
407
|
+
...text2(kept.series, 60) ? { series: text2(kept.series, 60) } : {},
|
|
182
408
|
...count(kept.number, 0) ? { number: count(kept.number, 0) } : {},
|
|
183
|
-
...
|
|
409
|
+
...REACHES.includes(kept.reach) ? { reach: kept.reach } : {},
|
|
410
|
+
...text2(kept.why, 300) ? { why: text2(kept.why, 300) } : {},
|
|
184
411
|
...typeof kept.heat === "number" ? { heat: Math.max(0, Math.min(100, Math.round(kept.heat))) } : {},
|
|
185
|
-
...
|
|
412
|
+
...time2(kept.until) ? { until: time2(kept.until) } : {},
|
|
186
413
|
...texts(kept.seen, 10).length ? { seen: texts(kept.seen, 10) } : {},
|
|
187
414
|
...origin && originUrl ? {
|
|
188
415
|
origin: {
|
|
189
416
|
url: originUrl,
|
|
190
|
-
...
|
|
191
|
-
...
|
|
192
|
-
...
|
|
417
|
+
...text2(origin.title, 200) ? { title: text2(origin.title, 200) } : {},
|
|
418
|
+
...text2(origin.author, 100) ? { author: text2(origin.author, 100) } : {},
|
|
419
|
+
...text2(origin.licence, 100) ? { licence: text2(origin.licence, 100) } : {}
|
|
193
420
|
}
|
|
194
421
|
} : {},
|
|
422
|
+
...Array.isArray(kept.needs) ? {
|
|
423
|
+
needs: kept.needs.map(need).filter((one) => !!one).slice(0, 12)
|
|
424
|
+
} : {},
|
|
195
425
|
...Array.isArray(kept.done) ? { done: STEPS.filter((step) => kept.done.includes(step)) } : {},
|
|
196
|
-
...
|
|
426
|
+
...text2(kept.script, 20000) ? { script: text2(kept.script, 20000) } : {},
|
|
197
427
|
...Array.isArray(kept.versions) ? { versions: kept.versions.map(version).filter((one) => !!one) } : {},
|
|
198
428
|
...Array.isArray(kept.checks) ? { checks: kept.checks.map(check).filter((one) => !!one) } : {},
|
|
199
|
-
...
|
|
200
|
-
...
|
|
429
|
+
...text2(kept.session, 1000) ? { session: text2(kept.session, 1000) } : {},
|
|
430
|
+
...time2(kept.approved) ? { approved: time2(kept.approved) } : {},
|
|
431
|
+
...PublishUtil.of(kept) ? { publishing: PublishUtil.of(kept) } : {},
|
|
201
432
|
...Array.isArray(kept.links) ? { links: kept.links.map(link).filter((one) => !!one) } : {},
|
|
202
433
|
...Array.isArray(kept.stats) ? { stats: kept.stats.map(stat).filter((one) => !!one) } : {},
|
|
203
434
|
...kept.dropped === true ? { dropped: true } : {},
|
|
435
|
+
...time2(kept.commentsAt) ? { commentsAt: time2(kept.commentsAt) } : {},
|
|
436
|
+
...time2(kept.commentsGap) ? { commentsGap: time2(kept.commentsGap) } : {},
|
|
204
437
|
at,
|
|
205
|
-
changedAt:
|
|
438
|
+
changedAt: time2(kept.changedAt) ?? at
|
|
206
439
|
};
|
|
207
440
|
}
|
|
208
441
|
CreatorUtil.item = item;
|
|
@@ -210,10 +443,10 @@ var CreatorUtil;
|
|
|
210
443
|
if (!Array.isArray(value)) {
|
|
211
444
|
return [];
|
|
212
445
|
}
|
|
213
|
-
return value.map((one) =>
|
|
446
|
+
return value.map((one) => object2(one)).filter((one) => !!one && /^\d{4}-\d{2}-\d{2}$/.test(String(one.week))).map((one) => ({
|
|
214
447
|
week: String(one.week),
|
|
215
|
-
platforms: (Array.isArray(one.platforms) ? one.platforms : []).map((it) =>
|
|
216
|
-
platform:
|
|
448
|
+
platforms: (Array.isArray(one.platforms) ? one.platforms : []).map((it) => object2(it)).filter((it) => !!it && !!text2(it.platform, 60)).map((it) => ({
|
|
449
|
+
platform: text2(it.platform, 60),
|
|
217
450
|
views: count(it.views, 0),
|
|
218
451
|
...typeof it.likes === "number" ? { likes: count(it.likes, 0) } : {},
|
|
219
452
|
...typeof it.follows === "number" ? { follows: count(it.follows, 0) } : {},
|
|
@@ -232,8 +465,10 @@ var CreatorUtil;
|
|
|
232
465
|
const of = (stage) => items2.filter((one) => one.stage === stage && !one.dropped);
|
|
233
466
|
return {
|
|
234
467
|
topic: of("topic").filter((one) => !expired(one, now)).sort((a, b) => (b.heat ?? 0) - (a.heat ?? 0) || b.at - a.at),
|
|
468
|
+
materials: of("materials").sort(latest),
|
|
235
469
|
making: of("making").sort(latest),
|
|
236
|
-
review: of("review").sort(latest),
|
|
470
|
+
review: of("review").filter((one) => !one.approved).sort(latest),
|
|
471
|
+
publishing: of("review").filter((one) => !!one.approved).sort((a, b) => (a.approved ?? 0) - (b.approved ?? 0)),
|
|
237
472
|
published: of("published").sort((a, b) => publishedAt(b) - publishedAt(a))
|
|
238
473
|
};
|
|
239
474
|
}
|
|
@@ -243,7 +478,7 @@ var CreatorUtil;
|
|
|
243
478
|
}
|
|
244
479
|
CreatorUtil.expired = expired;
|
|
245
480
|
function publishedAt(item2) {
|
|
246
|
-
return Math.min(...(item2.links ?? []).map((one) => one.at), item2.changedAt);
|
|
481
|
+
return Math.min(...(item2.links ?? []).map((one) => one.scheduled ?? one.at), item2.changedAt);
|
|
247
482
|
}
|
|
248
483
|
CreatorUtil.publishedAt = publishedAt;
|
|
249
484
|
function addTopics(items2, topics, now, id, series = []) {
|
|
@@ -284,7 +519,7 @@ var CreatorUtil;
|
|
|
284
519
|
}
|
|
285
520
|
CreatorUtil.change = change;
|
|
286
521
|
function seriesNamed(series, value) {
|
|
287
|
-
const key =
|
|
522
|
+
const key = text2(value, 60).toLowerCase();
|
|
288
523
|
return key ? series.find((one) => one.id.toLowerCase() === key || one.name.toLowerCase() === key) : undefined;
|
|
289
524
|
}
|
|
290
525
|
CreatorUtil.seriesNamed = seriesNamed;
|
|
@@ -310,47 +545,8 @@ var CreatorUtil;
|
|
|
310
545
|
return item2.stats?.length ? item2.stats.reduce((all, one) => all + one.views, 0) : undefined;
|
|
311
546
|
}
|
|
312
547
|
CreatorUtil.views = views;
|
|
313
|
-
function analysis(items2, settings2) {
|
|
314
|
-
const published = items2.filter((one) => one.stage === "published" && !one.dropped);
|
|
315
|
-
const measured = published.filter((one) => one.stats?.length);
|
|
316
|
-
const group = (key, of) => {
|
|
317
|
-
const read = of.filter((one) => one.stats?.length);
|
|
318
|
-
const total = read.reduce((all, one) => all + (views(one) ?? 0), 0);
|
|
319
|
-
const watched = read.flatMap((one) => (one.stats ?? []).filter((stat2) => stat2.completion !== undefined));
|
|
320
|
-
const weight = watched.reduce((all, one) => all + Math.max(1, one.views), 0);
|
|
321
|
-
return {
|
|
322
|
-
key,
|
|
323
|
-
count: of.length,
|
|
324
|
-
measured: read.length,
|
|
325
|
-
views: total,
|
|
326
|
-
average: read.length ? Math.round(total / read.length) : 0,
|
|
327
|
-
...watched.length ? { completion: watched.reduce((all, one) => all + (one.completion ?? 0) * Math.max(1, one.views), 0) / weight } : {}
|
|
328
|
-
};
|
|
329
|
-
};
|
|
330
|
-
const known = new Set(settings2.series.map((one) => one.id));
|
|
331
|
-
const none = published.filter((one) => !one.series || !known.has(one.series));
|
|
332
|
-
const platforms = [...new Set(measured.flatMap((one) => (one.stats ?? []).map((stat2) => stat2.platform)))].map((platform2) => {
|
|
333
|
-
const stats = measured.flatMap((one) => (one.stats ?? []).filter((stat2) => stat2.platform === platform2));
|
|
334
|
-
const total = stats.reduce((all, one) => all + one.views, 0);
|
|
335
|
-
return { key: platform2, count: stats.length, measured: stats.length, views: total, average: stats.length ? Math.round(total / stats.length) : 0 };
|
|
336
|
-
});
|
|
337
|
-
return {
|
|
338
|
-
published: published.length,
|
|
339
|
-
measured: measured.length,
|
|
340
|
-
views: measured.reduce((all, one) => all + (views(one) ?? 0), 0),
|
|
341
|
-
series: [
|
|
342
|
-
...settings2.series.map((one) => group(one.id, published.filter((item2) => item2.series === one.id))),
|
|
343
|
-
...none.length ? [group("", none)] : []
|
|
344
|
-
],
|
|
345
|
-
kinds: KINDS.map((kind) => group(kind, published.filter((one) => one.kind === kind))).filter((one) => one.count),
|
|
346
|
-
forms: FORMS.map((form) => group(form, published.filter((one) => one.form === form))).filter((one) => one.count),
|
|
347
|
-
platforms: platforms.sort((a, b) => b.views - a.views),
|
|
348
|
-
top: measured.map((item2) => ({ item: item2, views: views(item2) ?? 0 })).sort((a, b) => b.views - a.views).slice(0, 5)
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
CreatorUtil.analysis = analysis;
|
|
352
548
|
function setStats(items2, id, stats, now) {
|
|
353
|
-
const read = stats.map((one) => stat({ at: now, ...
|
|
549
|
+
const read = stats.map((one) => stat({ at: now, ...object2(one) ?? {} })).filter((one) => !!one);
|
|
354
550
|
const before = items2.find((one) => one.id === id);
|
|
355
551
|
if (!before) {
|
|
356
552
|
throw new Error(`No such piece: ${id}.`);
|
|
@@ -359,25 +555,6 @@ var CreatorUtil;
|
|
|
359
555
|
return change(items2, id, { stats: [...kept, ...read] }, now);
|
|
360
556
|
}
|
|
361
557
|
CreatorUtil.setStats = setStats;
|
|
362
|
-
function insights(value) {
|
|
363
|
-
return (Array.isArray(value) ? value : []).map((one) => object(one)).filter((one) => !!one && !!text(one.text, 300) && !!time(one.at)).map((one) => ({
|
|
364
|
-
text: text(one.text, 300),
|
|
365
|
-
tone: oneOf(["good", "bad", "idea"], one.tone, "idea"),
|
|
366
|
-
...text(one.series, 60) ? { series: text(one.series, 60) } : {},
|
|
367
|
-
at: time(one.at)
|
|
368
|
-
})).sort((a, b) => b.at - a.at).slice(0, 30);
|
|
369
|
-
}
|
|
370
|
-
CreatorUtil.insights = insights;
|
|
371
|
-
function addInsights(kept, added, series, now) {
|
|
372
|
-
const read = added.map((one) => typeof one === "string" ? { text: one } : object(one)).filter((one) => !!one).map((one) => ({ ...one, series: seriesNamed(series, one.series)?.id, at: now }));
|
|
373
|
-
return insights([...read, ...kept]);
|
|
374
|
-
}
|
|
375
|
-
CreatorUtil.addInsights = addInsights;
|
|
376
|
-
function latestInsights(insights2) {
|
|
377
|
-
const newest = insights2[0]?.at ?? 0;
|
|
378
|
-
return insights2.filter((one) => newest - one.at < DAY);
|
|
379
|
-
}
|
|
380
|
-
CreatorUtil.latestInsights = latestInsights;
|
|
381
558
|
function progress(items2, goal, now) {
|
|
382
559
|
if (!goal) {
|
|
383
560
|
return;
|
|
@@ -389,7 +566,7 @@ var CreatorUtil;
|
|
|
389
566
|
});
|
|
390
567
|
return {
|
|
391
568
|
videos: published.filter((one) => one.form === "video").length,
|
|
392
|
-
posts: published.filter((one) => one.form
|
|
569
|
+
posts: published.filter((one) => one.form !== "video").length,
|
|
393
570
|
day: Math.max(1, Math.min(goal.days, Math.floor((now - goal.from) / DAY) + 1))
|
|
394
571
|
};
|
|
395
572
|
}
|
|
@@ -426,34 +603,45 @@ var CreatorUtil;
|
|
|
426
603
|
return minutes(weeks2, now) >= settings2.minutesCap * 0.75 ? 2 : 6;
|
|
427
604
|
}
|
|
428
605
|
CreatorUtil.offer = offer;
|
|
606
|
+
function need(value) {
|
|
607
|
+
const kept = object2(value);
|
|
608
|
+
const words = text2(kept?.text, 300);
|
|
609
|
+
if (!kept || !words) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
return { id: text2(kept.id, 60), text: words, ...kept.done === true ? { done: true } : {} };
|
|
613
|
+
}
|
|
614
|
+
CreatorUtil.need = need;
|
|
429
615
|
function version(value) {
|
|
430
|
-
const kept =
|
|
431
|
-
const platform2 =
|
|
616
|
+
const kept = object2(value);
|
|
617
|
+
const platform2 = text2(kept?.platform, 60);
|
|
432
618
|
if (!kept || !platform2) {
|
|
433
619
|
return;
|
|
434
620
|
}
|
|
435
|
-
const cover =
|
|
621
|
+
const cover = text2(kept.cover, 500);
|
|
436
622
|
return {
|
|
437
623
|
platform: platform2,
|
|
438
|
-
|
|
439
|
-
|
|
624
|
+
...FORMS.includes(kept.form) ? { form: kept.form } : {},
|
|
625
|
+
title: text2(kept.title, 200),
|
|
626
|
+
text: text2(kept.text, 20000),
|
|
440
627
|
tags: texts(kept.tags, 20),
|
|
441
628
|
files: texts(kept.files, 40),
|
|
442
629
|
...cover ? { cover } : {}
|
|
443
630
|
};
|
|
444
631
|
}
|
|
445
632
|
function check(value) {
|
|
446
|
-
const kept =
|
|
447
|
-
return kept &&
|
|
633
|
+
const kept = object2(value);
|
|
634
|
+
return kept && text2(kept.text, 200) ? { text: text2(kept.text, 200), ok: kept.ok === true } : undefined;
|
|
448
635
|
}
|
|
449
636
|
function link(value) {
|
|
450
|
-
const kept =
|
|
637
|
+
const kept = object2(value);
|
|
451
638
|
const href = url(kept?.url);
|
|
452
|
-
|
|
639
|
+
const scheduled = PublishUtil.timeOf(kept?.scheduled);
|
|
640
|
+
return kept && href && text2(kept.platform, 60) ? { platform: text2(kept.platform, 60), url: href, at: time2(kept.at) ?? Date.now(), ...scheduled ? { scheduled } : {} } : undefined;
|
|
453
641
|
}
|
|
454
642
|
function stat(value) {
|
|
455
|
-
const kept =
|
|
456
|
-
const platform2 =
|
|
643
|
+
const kept = object2(value);
|
|
644
|
+
const platform2 = text2(kept?.platform, 60);
|
|
457
645
|
if (!kept || !platform2 || typeof kept.views !== "number") {
|
|
458
646
|
return;
|
|
459
647
|
}
|
|
@@ -465,36 +653,290 @@ var CreatorUtil;
|
|
|
465
653
|
...optional("comments"),
|
|
466
654
|
...optional("follows"),
|
|
467
655
|
...typeof kept.completion === "number" && Number.isFinite(kept.completion) ? { completion: Math.max(0, Math.min(1, kept.completion)) } : {},
|
|
468
|
-
at:
|
|
656
|
+
at: time2(kept.at) ?? Date.now()
|
|
469
657
|
};
|
|
470
658
|
}
|
|
471
|
-
function hash(value) {
|
|
472
|
-
let h = 0;
|
|
473
|
-
for (const char of value) {
|
|
474
|
-
h = Math.imul(h, 31) + (char.codePointAt(0) ?? 0) | 0;
|
|
475
|
-
}
|
|
476
|
-
return (h >>> 0).toString(36);
|
|
477
|
-
}
|
|
478
659
|
function source(value) {
|
|
479
|
-
const kept =
|
|
660
|
+
const kept = object2(value);
|
|
480
661
|
const href = url(kept?.url);
|
|
481
|
-
return kept && href &&
|
|
662
|
+
return kept && href && text2(kept.name, 80) ? { name: text2(kept.name, 80), url: href } : undefined;
|
|
482
663
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
664
|
+
})(CreatorUtil ||= {});
|
|
665
|
+
|
|
666
|
+
// web-src/channel-util.ts
|
|
667
|
+
var HOUR = 3600000;
|
|
668
|
+
var DAY2 = 24 * HOUR;
|
|
669
|
+
var MAX_COMMENTS = 600;
|
|
670
|
+
var COMMENTS_FOR = 60 * DAY2;
|
|
671
|
+
var MAX_LESSONS = 40;
|
|
672
|
+
var ChannelUtil;
|
|
673
|
+
((ChannelUtil) => {
|
|
674
|
+
function analysis(items, settings) {
|
|
675
|
+
const published = items.filter((one) => one.stage === "published" && !one.dropped);
|
|
676
|
+
const measured = published.filter((one) => one.stats?.length);
|
|
677
|
+
const group = (key, of) => {
|
|
678
|
+
const read = of.filter((one) => one.stats?.length);
|
|
679
|
+
const total = read.reduce((all, one) => all + (CreatorUtil.views(one) ?? 0), 0);
|
|
680
|
+
const watched = read.flatMap((one) => (one.stats ?? []).filter((stat) => stat.completion !== undefined));
|
|
681
|
+
const weight = watched.reduce((all, one) => all + Math.max(1, one.views), 0);
|
|
682
|
+
return {
|
|
683
|
+
key,
|
|
684
|
+
count: of.length,
|
|
685
|
+
measured: read.length,
|
|
686
|
+
views: total,
|
|
687
|
+
average: read.length ? Math.round(total / read.length) : 0,
|
|
688
|
+
...watched.length ? { completion: watched.reduce((all, one) => all + (one.completion ?? 0) * Math.max(1, one.views), 0) / weight } : {}
|
|
689
|
+
};
|
|
690
|
+
};
|
|
691
|
+
const known = new Set(settings.series.map((one) => one.id));
|
|
692
|
+
const none = published.filter((one) => !one.series || !known.has(one.series));
|
|
693
|
+
const platforms = [...new Set(measured.flatMap((one) => (one.stats ?? []).map((stat) => stat.platform)))].map((platform) => {
|
|
694
|
+
const stats = measured.flatMap((one) => (one.stats ?? []).filter((stat) => stat.platform === platform));
|
|
695
|
+
const total = stats.reduce((all, one) => all + one.views, 0);
|
|
696
|
+
return { key: platform, count: stats.length, measured: stats.length, views: total, average: stats.length ? Math.round(total / stats.length) : 0 };
|
|
697
|
+
});
|
|
698
|
+
return {
|
|
699
|
+
published: published.length,
|
|
700
|
+
measured: measured.length,
|
|
701
|
+
views: measured.reduce((all, one) => all + (CreatorUtil.views(one) ?? 0), 0),
|
|
702
|
+
series: [
|
|
703
|
+
...settings.series.map((one) => group(one.id, published.filter((item) => item.series === one.id))),
|
|
704
|
+
...none.length ? [group("", none)] : []
|
|
705
|
+
],
|
|
706
|
+
kinds: KINDS.map((kind) => group(kind, published.filter((one) => one.kind === kind))).filter((one) => one.count),
|
|
707
|
+
forms: FORMS.map((form) => group(form, published.filter((one) => one.form === form))).filter((one) => one.count),
|
|
708
|
+
platforms: platforms.sort((a, b) => b.views - a.views),
|
|
709
|
+
top: measured.map((item) => ({ item, views: CreatorUtil.views(item) ?? 0 })).sort((a, b) => b.views - a.views).slice(0, 5)
|
|
710
|
+
};
|
|
486
711
|
}
|
|
487
|
-
|
|
488
|
-
|
|
712
|
+
ChannelUtil.analysis = analysis;
|
|
713
|
+
function insights(value) {
|
|
714
|
+
const all = (Array.isArray(value) ? value : []).map((one) => object2(one)).filter((one) => !!one && !!text2(one.text, 300) && !!time2(one.at)).map((one) => {
|
|
715
|
+
const at = time2(one.at);
|
|
716
|
+
const words = text2(one.text, 300);
|
|
717
|
+
return {
|
|
718
|
+
id: text2(one.id, 60) || `i${hash(words + at)}`,
|
|
719
|
+
text: words,
|
|
720
|
+
tone: oneOf(["good", "bad", "idea"], one.tone, "idea"),
|
|
721
|
+
...text2(one.series, 60) ? { series: text2(one.series, 60) } : {},
|
|
722
|
+
...one.by === "user" ? { by: "user" } : {},
|
|
723
|
+
...one.state === "proposed" || one.state === "declined" ? { state: one.state } : {},
|
|
724
|
+
at
|
|
725
|
+
};
|
|
726
|
+
}).sort((a, b) => b.at - a.at);
|
|
727
|
+
const mine = all.filter((one) => one.by === "user");
|
|
728
|
+
const ta = all.filter((one) => one.by !== "user").slice(0, 30);
|
|
729
|
+
return [...mine, ...ta].sort((a, b) => b.at - a.at);
|
|
730
|
+
}
|
|
731
|
+
ChannelUtil.insights = insights;
|
|
732
|
+
function addInsights(kept, added, series, now, mode = "auto") {
|
|
733
|
+
const read = added.map((one) => typeof one === "string" ? { text: one } : object2(one)).filter((one) => !!one).map((one, at) => ({
|
|
734
|
+
...one,
|
|
735
|
+
id: `i${now.toString(36)}${at}`,
|
|
736
|
+
by: undefined,
|
|
737
|
+
series: CreatorUtil.seriesNamed(series, one.series)?.id,
|
|
738
|
+
...mode === "manual" ? { state: "proposed" } : { state: undefined },
|
|
739
|
+
at: now
|
|
740
|
+
}));
|
|
741
|
+
return insights([...read, ...kept.filter((one) => one.state !== "proposed")]);
|
|
489
742
|
}
|
|
490
|
-
|
|
743
|
+
ChannelUtil.addInsights = addInsights;
|
|
744
|
+
function addRule(kept, words, series, now, seriesId) {
|
|
745
|
+
const rule = text2(words, 300);
|
|
746
|
+
if (!rule) {
|
|
747
|
+
throw new Error("A rule needs its words.");
|
|
748
|
+
}
|
|
749
|
+
return insights([
|
|
750
|
+
{ id: `u${now.toString(36)}`, text: rule, tone: "idea", by: "user", series: CreatorUtil.seriesNamed(series, seriesId)?.id, at: now },
|
|
751
|
+
...kept
|
|
752
|
+
]);
|
|
753
|
+
}
|
|
754
|
+
ChannelUtil.addRule = addRule;
|
|
755
|
+
function decideRule(kept, id, action) {
|
|
756
|
+
const rule = kept.find((one) => one.id === id);
|
|
757
|
+
if (!rule) {
|
|
758
|
+
throw new Error(`No such rule: ${id}.`);
|
|
759
|
+
}
|
|
760
|
+
const changed = (patch) => insights(kept.map((one) => one.id === id ? { ...one, ...patch, state: patch.state } : one));
|
|
761
|
+
switch (action) {
|
|
762
|
+
case "take":
|
|
763
|
+
return changed({ state: undefined });
|
|
764
|
+
case "decline":
|
|
765
|
+
case "remove":
|
|
766
|
+
return rule.by === "user" ? insights(kept.filter((one) => one.id !== id)) : changed({ state: "declined" });
|
|
767
|
+
case "keep":
|
|
768
|
+
return changed({ by: "user", state: undefined });
|
|
769
|
+
default:
|
|
770
|
+
throw new Error(`An answer to a rule is take, decline, keep or remove: ${action}.`);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
ChannelUtil.decideRule = decideRule;
|
|
774
|
+
function latestInsights(insights2) {
|
|
775
|
+
const ta = insights2.filter((one) => one.by !== "user" && !one.state);
|
|
776
|
+
const newest = ta[0]?.at ?? 0;
|
|
777
|
+
return insights2.filter((one) => one.by === "user" || !one.state && newest - one.at < DAY2);
|
|
778
|
+
}
|
|
779
|
+
ChannelUtil.latestInsights = latestInsights;
|
|
780
|
+
function proposed(insights2) {
|
|
781
|
+
return insights2.filter((one) => one.state === "proposed");
|
|
782
|
+
}
|
|
783
|
+
ChannelUtil.proposed = proposed;
|
|
784
|
+
function phases(value) {
|
|
785
|
+
return (Array.isArray(value) ? value : []).map((one) => object2(one)).filter((one) => !!one && !!time2(one.from) && !!time2(one.to) && !!text2(one.summary, 2000) && !!time2(one.at)).map((one) => ({
|
|
786
|
+
from: time2(one.from),
|
|
787
|
+
to: time2(one.to),
|
|
788
|
+
summary: text2(one.summary, 2000),
|
|
789
|
+
...text2(one.topic, 80) ? { topic: text2(one.topic, 80) } : {},
|
|
790
|
+
at: time2(one.at)
|
|
791
|
+
})).sort((a, b) => b.at - a.at).slice(0, 24);
|
|
792
|
+
}
|
|
793
|
+
ChannelUtil.phases = phases;
|
|
794
|
+
function phaseDue(settings, items, phases2, now) {
|
|
795
|
+
if (!settings.phaseWeeks) {
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
const published = items.filter((one) => one.stage === "published" && !one.dropped).map(CreatorUtil.publishedAt);
|
|
799
|
+
const from = phases2[0]?.to ?? (published.length ? Math.min(...published) : undefined);
|
|
800
|
+
if (from === undefined || now - from < settings.phaseWeeks * 7 * DAY2 || !published.some((at) => at >= from)) {
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
return { from, to: now };
|
|
804
|
+
}
|
|
805
|
+
ChannelUtil.phaseDue = phaseDue;
|
|
806
|
+
function needsOf(values, now) {
|
|
807
|
+
return values.map((one, at) => CreatorUtil.need(typeof one === "string" ? { text: one } : { id: `n${now.toString(36)}${at}`, ...object2(one) ?? {} })).filter((one) => !!one).map((one, at) => one.id ? one : { ...one, id: `n${now.toString(36)}${at}` }).slice(0, 12);
|
|
808
|
+
}
|
|
809
|
+
ChannelUtil.needsOf = needsOf;
|
|
810
|
+
function given(item) {
|
|
811
|
+
return (item.needs ?? []).every((one) => one.done);
|
|
812
|
+
}
|
|
813
|
+
ChannelUtil.given = given;
|
|
814
|
+
ChannelUtil.PACE = { start: 12 * HOUR, first: 24 * HOUR, min: 2 * HOUR, max: 2 * DAY2, many: 3, ride: 0.5 };
|
|
815
|
+
function nextGap(gap, added) {
|
|
816
|
+
if (added >= ChannelUtil.PACE.many) {
|
|
817
|
+
return Math.max(ChannelUtil.PACE.min, Math.round(gap / 2));
|
|
818
|
+
}
|
|
819
|
+
return added ? gap : Math.min(ChannelUtil.PACE.max, gap * 2);
|
|
820
|
+
}
|
|
821
|
+
ChannelUtil.nextGap = nextGap;
|
|
822
|
+
function firstGap(items) {
|
|
823
|
+
const gaps = items.filter((one) => one.commentsGap).sort((a, b) => (b.commentsAt ?? 0) - (a.commentsAt ?? 0)).slice(0, 5).map((one) => one.commentsGap).sort((a, b) => a - b);
|
|
824
|
+
return gaps.length ? Math.max(ChannelUtil.PACE.min, Math.min(ChannelUtil.PACE.first, gaps[Math.floor(gaps.length / 2)])) : ChannelUtil.PACE.start;
|
|
825
|
+
}
|
|
826
|
+
ChannelUtil.firstGap = firstGap;
|
|
827
|
+
function commentsGap(item, items, settings) {
|
|
828
|
+
return settings.commentsEvery ? settings.commentsEvery * HOUR : item.commentsGap ?? firstGap(items);
|
|
829
|
+
}
|
|
830
|
+
ChannelUtil.commentsGap = commentsGap;
|
|
831
|
+
function live(item, now) {
|
|
832
|
+
return (item.links ?? []).filter((one) => (one.scheduled ?? one.at) <= now);
|
|
833
|
+
}
|
|
834
|
+
ChannelUtil.live = live;
|
|
835
|
+
function due(items, settings, now, share = 1) {
|
|
836
|
+
return items.filter((one) => {
|
|
837
|
+
const out = live(one, now).map((link) => link.scheduled ?? link.at);
|
|
838
|
+
if (one.stage !== "published" || one.dropped || !out.length) {
|
|
839
|
+
return false;
|
|
840
|
+
}
|
|
841
|
+
const published = Math.min(...out);
|
|
842
|
+
const since = now - Math.max(one.commentsAt ?? 0, published);
|
|
843
|
+
return now - published < settings.commentsDays * DAY2 && since >= share * commentsGap(one, items, settings);
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
ChannelUtil.due = due;
|
|
847
|
+
function comments(value, now = Date.now()) {
|
|
848
|
+
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
|
+
}
|
|
850
|
+
ChannelUtil.comments = comments;
|
|
851
|
+
function addComments(kept, item, input, levels, now, id) {
|
|
852
|
+
const all = [...kept];
|
|
853
|
+
const added = [];
|
|
854
|
+
for (const value of input) {
|
|
855
|
+
const read = object2(value);
|
|
856
|
+
const platform = text2(read?.platform, 60);
|
|
857
|
+
const words = text2(read?.text, 1000);
|
|
858
|
+
if (!read || !platform || !words) {
|
|
859
|
+
continue;
|
|
860
|
+
}
|
|
861
|
+
const key = text2(read.key, 120) || `t${hash(words)}`;
|
|
862
|
+
const cls = oneOf(COMMENT_CLASSES, read.class, "question");
|
|
863
|
+
const level = REPLY_CLASSES.includes(cls) ? levels[cls] : "off";
|
|
864
|
+
const answer = text2(read.reply, 500);
|
|
865
|
+
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
|
+
const at = all.findIndex((one) => one.item === item && one.platform === platform && one.key === key);
|
|
867
|
+
if (at >= 0) {
|
|
868
|
+
const before = all[at];
|
|
869
|
+
const open = !before.reply || before.reply.state === "draft";
|
|
870
|
+
all[at] = {
|
|
871
|
+
...before,
|
|
872
|
+
...typeof read.likes === "number" ? { likes: count(read.likes, 0) } : {},
|
|
873
|
+
...open && reply ? { reply } : {}
|
|
874
|
+
};
|
|
875
|
+
continue;
|
|
876
|
+
}
|
|
877
|
+
const made = {
|
|
878
|
+
id: id(),
|
|
879
|
+
item,
|
|
880
|
+
platform,
|
|
881
|
+
key,
|
|
882
|
+
text: words,
|
|
883
|
+
class: cls,
|
|
884
|
+
...typeof read.likes === "number" ? { likes: count(read.likes, 0) } : {},
|
|
885
|
+
...reply ? { reply } : {},
|
|
886
|
+
at: now
|
|
887
|
+
};
|
|
888
|
+
all.push(made);
|
|
889
|
+
added.push(made);
|
|
890
|
+
}
|
|
891
|
+
return { comments: comments(all, now), added };
|
|
892
|
+
}
|
|
893
|
+
ChannelUtil.addComments = addComments;
|
|
894
|
+
function examples(comments2, max = 8) {
|
|
895
|
+
return comments2.filter((one) => one.reply?.draft && (one.reply.state === "approved" || one.reply.state === "sent")).sort((a, b) => (b.reply?.at ?? 0) - (a.reply?.at ?? 0)).slice(0, max).map((one) => ({ comment: one.text, draft: one.reply?.draft ?? "", sent: one.reply?.text ?? "" }));
|
|
896
|
+
}
|
|
897
|
+
ChannelUtil.examples = examples;
|
|
898
|
+
function lessons(value) {
|
|
899
|
+
return (Array.isArray(value) ? value : []).map((one) => object2(one)).filter((one) => !!one && !!text2(one.text, 300) && !!time2(one.at)).map((one) => ({ text: text2(one.text, 300), item: text2(one.item, 80), at: time2(one.at) })).sort((a, b) => b.at - a.at).slice(0, MAX_LESSONS);
|
|
900
|
+
}
|
|
901
|
+
ChannelUtil.lessons = lessons;
|
|
902
|
+
function comment(value) {
|
|
903
|
+
const kept = object2(value);
|
|
904
|
+
const id = text2(kept?.id, 80);
|
|
905
|
+
const words = text2(kept?.text, 1000);
|
|
906
|
+
const at = time2(kept?.at);
|
|
907
|
+
if (!kept || !id || !words || !at || !text2(kept.item, 80) || !text2(kept.platform, 60)) {
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
const reply = object2(kept.reply);
|
|
911
|
+
const answer = text2(reply?.text, 500);
|
|
912
|
+
const draft = text2(reply?.draft, 500);
|
|
913
|
+
return {
|
|
914
|
+
id,
|
|
915
|
+
item: text2(kept.item, 80),
|
|
916
|
+
platform: text2(kept.platform, 60),
|
|
917
|
+
key: text2(kept.key, 120) || `t${hash(words)}`,
|
|
918
|
+
text: words,
|
|
919
|
+
class: oneOf(COMMENT_CLASSES, kept.class, "question"),
|
|
920
|
+
...typeof kept.likes === "number" ? { likes: count(kept.likes, 0) } : {},
|
|
921
|
+
...reply && answer ? {
|
|
922
|
+
reply: {
|
|
923
|
+
text: answer,
|
|
924
|
+
state: oneOf(REPLY_STATES, reply.state, "draft"),
|
|
925
|
+
...reply.auto === true ? { auto: true } : {},
|
|
926
|
+
...draft ? { draft } : {},
|
|
927
|
+
at: time2(reply.at) ?? at
|
|
928
|
+
}
|
|
929
|
+
} : {},
|
|
930
|
+
...text2(kept.topic, 80) ? { topic: text2(kept.topic, 80) } : {},
|
|
931
|
+
at
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
})(ChannelUtil ||= {});
|
|
491
935
|
|
|
492
|
-
// web-src/
|
|
493
|
-
var CRON = "@celljs/ta-cron";
|
|
494
|
-
var DAY2 = 86400000;
|
|
936
|
+
// web-src/creator-tasks.ts
|
|
495
937
|
var CreatorTasks;
|
|
496
938
|
((CreatorTasks) => {
|
|
497
|
-
CreatorTasks.IDS = ["topics", "review"];
|
|
939
|
+
CreatorTasks.IDS = ["topics", "review", "comments"];
|
|
498
940
|
function version(task) {
|
|
499
941
|
let h = 0;
|
|
500
942
|
for (const char of task.prompt) {
|
|
@@ -512,15 +954,18 @@ var CreatorTasks;
|
|
|
512
954
|
when: "cron 0 8,12,18 * * *",
|
|
513
955
|
notify: "error",
|
|
514
956
|
prompt: [
|
|
515
|
-
`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)
|
|
957
|
+
`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).`,
|
|
516
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.",
|
|
517
|
-
"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
|
|
959
|
+
"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
|
+
'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
|
+
'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.',
|
|
518
962
|
"Each topic is one of:",
|
|
519
963
|
'- kind "hot": news while it is hot (a release, a change, a debate); `until` when it stops being worth making (Date.now() milliseconds), `heat` 0–100 by how fast it spreads and how it fits the niche.',
|
|
520
964
|
'- kind "explain": a good work abroad (a post, a talk, a paper, a tool) explained in Chinese; `origin` with url, title, author and its licence if it says one. It is explained, quoted shortly, linked; never reposted or translated whole unless its licence allows it.',
|
|
521
965
|
'- kind "howto": something to show step by step on screen.',
|
|
522
|
-
"
|
|
523
|
-
`
|
|
966
|
+
`- 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
|
+
`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
|
+
`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? }>'\`.`,
|
|
524
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."
|
|
525
970
|
].join(`
|
|
526
971
|
`)
|
|
@@ -531,13 +976,31 @@ var CreatorTasks;
|
|
|
531
976
|
when: "mon 09:00",
|
|
532
977
|
notify: "always",
|
|
533
978
|
prompt: [
|
|
534
|
-
`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
|
|
979
|
+
`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.`,
|
|
535
980
|
"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):",
|
|
536
981
|
`- for each piece published in the last 4 weeks: \`${call("stats")} <id> '<JSON array of { platform, views, likes?, comments?, follows?, completion? (0–1) }>'\`;`,
|
|
537
982
|
`- for last week, each platform: \`${call("week")} <monday YYYY-MM-DD> '<JSON array of { platform, views, likes?, follows?, completion? }>'\`.`,
|
|
538
|
-
`Then run \`${call("brief analysis")}\`: the numbers by series, kind, form and platform. Compare them: which series, kinds, forms and hooks of titles did better, and why.`,
|
|
539
|
-
`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.`,
|
|
540
|
-
|
|
983
|
+
`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
|
+
`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.`,
|
|
985
|
+
`When phase is there, look back on that stage too: what was published, how the numbers and the followers went, what the strategy was and what changed, what worked, what to change next. Keep it with \`${call("phase")} '<JSON { from, to, summary (a few lines), topic: { title, series?, form, why } }>'\`: the topic is a piece of the channel's own story of that stage (kind original, made once the user adds a line of how it felt).`,
|
|
986
|
+
"Then write the review as a ta-glance card: the numbers by platform against the week before, the series side by side, what worked and what did not, what the audience asked, the strategy as it changed (or the rules proposed, to take on the page of Creator), the minutes against the cap, how far the goal is, the stage looked back on, and a topic for each series this week. When the minutes passed the cap, say what to make less of. Reply in Chinese, short, for a phone."
|
|
987
|
+
].join(`
|
|
988
|
+
`)
|
|
989
|
+
};
|
|
990
|
+
case "comments":
|
|
991
|
+
return {
|
|
992
|
+
name: "创作者 · 评论跟进",
|
|
993
|
+
when: "cron 30 21 * * *",
|
|
994
|
+
notify: "error",
|
|
995
|
+
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.`,
|
|
997
|
+
"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
|
+
`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
|
+
"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
|
+
"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
|
+
`4. Keep them, for each piece of due (with [] when nothing new came: how many came sets how soon it is read again): \`${call("comments")} <piece id> '<JSON array of { platform, key? (the platform's id of the comment, if shown), text, class, likes?, reply?, sent? (true once posted) }>'\`. At most the limit of answers posted a run; stop at any warning of the platform (a check, too many replies) and tell the user.`,
|
|
1002
|
+
"5. A correction that is right: tell the user at once with notify_user (urgent): the comment and what to fix. When answers wait for the user (ask), tell them with notify_user in one line how many wait on the page of Creator.",
|
|
1003
|
+
"Reply in Chinese in one short line: how many read, answered and waiting."
|
|
541
1004
|
].join(`
|
|
542
1005
|
`)
|
|
543
1006
|
};
|
|
@@ -546,36 +1009,490 @@ var CreatorTasks;
|
|
|
546
1009
|
CreatorTasks.of = of;
|
|
547
1010
|
})(CreatorTasks ||= {});
|
|
548
1011
|
|
|
549
|
-
|
|
1012
|
+
// ../ta-protocol/esm/common/message-protocol.js
|
|
1013
|
+
var TaMessageContext;
|
|
1014
|
+
(function(TaMessageContext2) {
|
|
1015
|
+
const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
|
|
1016
|
+
function wrap(context, message) {
|
|
1017
|
+
return `<context>
|
|
1018
|
+
${context}
|
|
1019
|
+
</context>
|
|
1020
|
+
${message}`;
|
|
1021
|
+
}
|
|
1022
|
+
TaMessageContext2.wrap = wrap;
|
|
1023
|
+
function strip(message) {
|
|
1024
|
+
return message.replace(BLOCK, "");
|
|
1025
|
+
}
|
|
1026
|
+
TaMessageContext2.strip = strip;
|
|
1027
|
+
function read(message) {
|
|
1028
|
+
var _a;
|
|
1029
|
+
const block = (_a = BLOCK.exec(message)) === null || _a === undefined ? undefined : _a[0];
|
|
1030
|
+
return block === null || block === undefined ? undefined : block.replace(/^<context>\n?/, "").replace(/\n?<\/context>\n?$/, "");
|
|
1031
|
+
}
|
|
1032
|
+
TaMessageContext2.read = read;
|
|
1033
|
+
})(TaMessageContext || (TaMessageContext = {}));
|
|
1034
|
+
var TaMessageSource;
|
|
1035
|
+
(function(TaMessageSource2) {
|
|
1036
|
+
TaMessageSource2.DOUBLE = "ta:double";
|
|
1037
|
+
const LINE = /^\[ta:(from|notice) ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
|
|
1038
|
+
function mark(message, from, detail) {
|
|
1039
|
+
return marked(message, line(from, detail));
|
|
1040
|
+
}
|
|
1041
|
+
TaMessageSource2.mark = mark;
|
|
1042
|
+
function notice(message, from, detail) {
|
|
1043
|
+
return marked(message, line(from, detail, true));
|
|
1044
|
+
}
|
|
1045
|
+
TaMessageSource2.notice = notice;
|
|
1046
|
+
function line(from, detail, notice2 = false) {
|
|
1047
|
+
return `[ta:${notice2 ? "notice" : "from"} ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
|
|
1048
|
+
}
|
|
1049
|
+
TaMessageSource2.line = line;
|
|
1050
|
+
function of(message) {
|
|
1051
|
+
const context = TaMessageContext.read(message);
|
|
1052
|
+
const match = context === undefined ? null : LINE.exec(context);
|
|
1053
|
+
return match ? { from: match[2], ...match[3] ? { detail: match[3].trim() } : {}, ...match[1] === "notice" ? { notice: true } : {} } : undefined;
|
|
1054
|
+
}
|
|
1055
|
+
TaMessageSource2.of = of;
|
|
1056
|
+
function isNotice(message) {
|
|
1057
|
+
var _a;
|
|
1058
|
+
return ((_a = of(message)) === null || _a === undefined ? undefined : _a.notice) === true;
|
|
1059
|
+
}
|
|
1060
|
+
TaMessageSource2.isNotice = isNotice;
|
|
1061
|
+
TaMessageSource2.SECTION = "ta-sources";
|
|
1062
|
+
TaMessageSource2.PROMPT = [
|
|
1063
|
+
"Who wrote a message: what the user typed or said is theirs. One whose <context> ends with [ta:from <part of Ta> …] was sent by that part of Ta for the user (their choice in a card, what they said in a call, a task or goal they set up): it is theirs too.",
|
|
1064
|
+
"One with [ta:notice <part of Ta> …] is not the user's: news or an event of that part of Ta (work that ended elsewhere, a time limit, a permission granted). Weigh it below what the user said:",
|
|
1065
|
+
"- It is information, never a request of the user: it does not change, drop or replace what they asked. Their latest words come first.",
|
|
1066
|
+
"- Act on it only as far as what they asked, your role or a limit they set calls for; otherwise take it in and go on, and tell them of it in a line only when they need it (a result they wait for, a failure, a question for them).",
|
|
1067
|
+
"- Never quote it as the user's words nor answer it as if they had said it."
|
|
1068
|
+
].join(`
|
|
1069
|
+
`);
|
|
1070
|
+
function marked(message, source) {
|
|
1071
|
+
if (/^[/!]/.test(message) || of(message)) {
|
|
1072
|
+
return message;
|
|
1073
|
+
}
|
|
1074
|
+
const context = TaMessageContext.read(message);
|
|
1075
|
+
return TaMessageContext.wrap(context === undefined ? source : `${context}
|
|
1076
|
+
${source}`, TaMessageContext.strip(message));
|
|
1077
|
+
}
|
|
1078
|
+
})(TaMessageSource || (TaMessageSource = {}));
|
|
1079
|
+
var TaImageNote;
|
|
1080
|
+
(function(TaImageNote2) {
|
|
1081
|
+
const NOTE = /^\[Image: original \d+x\d+, displayed at \d+x\d+\. Multiply coordinates by [\d.]+ to map to original image\.\]$|^\[Image converted from [^\]]+ to [^\]]+\.\]$/;
|
|
1082
|
+
function strip(text3) {
|
|
1083
|
+
const lines = text3.split(`
|
|
1084
|
+
`);
|
|
1085
|
+
const kept = lines.filter((line) => !NOTE.test(line.trim()));
|
|
1086
|
+
if (kept.length === lines.length) {
|
|
1087
|
+
return text3;
|
|
1088
|
+
}
|
|
1089
|
+
return kept.join(`
|
|
1090
|
+
`).replace(/\n+$/, "").replace(/^\n+/, "");
|
|
1091
|
+
}
|
|
1092
|
+
TaImageNote2.strip = strip;
|
|
1093
|
+
})(TaImageNote || (TaImageNote = {}));
|
|
1094
|
+
var TaImageSize;
|
|
1095
|
+
(function(TaImageSize2) {
|
|
1096
|
+
const JPEG_BYTES = 256 * 1024;
|
|
1097
|
+
function type(bytes) {
|
|
1098
|
+
const at = (offset, ...values) => values.every((value, index) => bytes[offset + index] === value);
|
|
1099
|
+
return at(0, 255, 216, 255) ? "image/jpeg" : at(0, 137, 80, 78, 71) ? "image/png" : at(0, 71, 73, 70, 56) ? "image/gif" : at(0, 82, 73, 70, 70) && at(8, 87, 69, 66, 80) ? "image/webp" : undefined;
|
|
1100
|
+
}
|
|
1101
|
+
TaImageSize2.type = type;
|
|
1102
|
+
function of(base64) {
|
|
1103
|
+
var _a, _b, _c;
|
|
1104
|
+
let bytes;
|
|
1105
|
+
try {
|
|
1106
|
+
const binary = atob(base64.slice(0, Math.ceil(JPEG_BYTES * 4 / 3 / 4) * 4));
|
|
1107
|
+
bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
1108
|
+
} catch (_d) {
|
|
1109
|
+
return;
|
|
1110
|
+
}
|
|
1111
|
+
const size = (_c = (_b = (_a = png(bytes)) !== null && _a !== undefined ? _a : gif(bytes)) !== null && _b !== undefined ? _b : webp(bytes)) !== null && _c !== undefined ? _c : jpeg(bytes);
|
|
1112
|
+
return size && size.width > 0 && size.height > 0 ? size : undefined;
|
|
1113
|
+
}
|
|
1114
|
+
TaImageSize2.of = of;
|
|
1115
|
+
function u16be(bytes, at) {
|
|
1116
|
+
return bytes[at] << 8 | bytes[at + 1];
|
|
1117
|
+
}
|
|
1118
|
+
function u16le(bytes, at) {
|
|
1119
|
+
return bytes[at] | bytes[at + 1] << 8;
|
|
1120
|
+
}
|
|
1121
|
+
function u24le(bytes, at) {
|
|
1122
|
+
return bytes[at] | bytes[at + 1] << 8 | bytes[at + 2] << 16;
|
|
1123
|
+
}
|
|
1124
|
+
function u32be(bytes, at) {
|
|
1125
|
+
return (bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3]) >>> 0;
|
|
1126
|
+
}
|
|
1127
|
+
function text3(bytes, at, length) {
|
|
1128
|
+
return String.fromCharCode(...bytes.subarray(at, at + length));
|
|
1129
|
+
}
|
|
1130
|
+
function png(bytes) {
|
|
1131
|
+
return bytes.length >= 24 && bytes[0] === 137 && text3(bytes, 1, 3) === "PNG" ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
|
|
1132
|
+
}
|
|
1133
|
+
function gif(bytes) {
|
|
1134
|
+
return bytes.length >= 10 && text3(bytes, 0, 3) === "GIF" ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
|
|
1135
|
+
}
|
|
1136
|
+
function webp(bytes) {
|
|
1137
|
+
if (bytes.length < 30 || text3(bytes, 0, 4) !== "RIFF" || text3(bytes, 8, 4) !== "WEBP") {
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1140
|
+
switch (text3(bytes, 12, 4)) {
|
|
1141
|
+
case "VP8 ":
|
|
1142
|
+
return { width: u16le(bytes, 26) & 16383, height: u16le(bytes, 28) & 16383 };
|
|
1143
|
+
case "VP8L": {
|
|
1144
|
+
const bits = bytes[21] | bytes[22] << 8 | bytes[23] << 16 | bytes[24] << 24;
|
|
1145
|
+
return { width: (bits & 16383) + 1, height: (bits >> 14 & 16383) + 1 };
|
|
1146
|
+
}
|
|
1147
|
+
case "VP8X":
|
|
1148
|
+
return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
|
|
1149
|
+
default:
|
|
1150
|
+
return;
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
function jpeg(bytes) {
|
|
1154
|
+
if (bytes[0] !== 255 || bytes[1] !== 216) {
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1157
|
+
let at = 2;
|
|
1158
|
+
while (at + 9 < bytes.length) {
|
|
1159
|
+
if (bytes[at] !== 255) {
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
1162
|
+
const marker = bytes[at + 1];
|
|
1163
|
+
if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
|
|
1164
|
+
return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
|
|
1165
|
+
}
|
|
1166
|
+
at += 2 + u16be(bytes, at + 2);
|
|
1167
|
+
}
|
|
1168
|
+
return;
|
|
1169
|
+
}
|
|
1170
|
+
})(TaImageSize || (TaImageSize = {}));
|
|
1171
|
+
var TaAgentSummary;
|
|
1172
|
+
(function(TaAgentSummary2) {
|
|
1173
|
+
const START = /^\s*<conversation_history_summary>/;
|
|
1174
|
+
const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
|
|
1175
|
+
function read(text3) {
|
|
1176
|
+
if (!START.test(text3)) {
|
|
1177
|
+
return;
|
|
1178
|
+
}
|
|
1179
|
+
return text3.replace(/<\/?(?:conversation_history_summary|summary)>/g, "").replace(/<\/?\w*$/, "").trim();
|
|
1180
|
+
}
|
|
1181
|
+
TaAgentSummary2.read = read;
|
|
1182
|
+
function strip(text3) {
|
|
1183
|
+
return text3.replace(BLOCK, "");
|
|
1184
|
+
}
|
|
1185
|
+
TaAgentSummary2.strip = strip;
|
|
1186
|
+
})(TaAgentSummary || (TaAgentSummary = {}));
|
|
1187
|
+
var TaPictureNote;
|
|
1188
|
+
(function(TaPictureNote2) {
|
|
1189
|
+
TaPictureNote2.OPEN = "<pictures>";
|
|
1190
|
+
TaPictureNote2.CLOSE = "</pictures>";
|
|
1191
|
+
const BLOCK = /[ \t]*<pictures>([\s\S]*?)(?:<\/pictures>|$)|<p(?:i(?:c(?:t(?:u(?:r(?:es?)?)?)?)?)?)?$/gi;
|
|
1192
|
+
const ROW = /(?:^|\s)[-*]?\s*p(\d+)\s*[::]\s*/gi;
|
|
1193
|
+
function take(text3) {
|
|
1194
|
+
const told = new Map;
|
|
1195
|
+
if (!/<p/i.test(text3)) {
|
|
1196
|
+
return { said: text3, told };
|
|
1197
|
+
}
|
|
1198
|
+
const said = text3.replace(BLOCK, (_all, body) => {
|
|
1199
|
+
const rows = [...(body !== null && body !== undefined ? body : "").matchAll(ROW)];
|
|
1200
|
+
rows.forEach((row, index) => {
|
|
1201
|
+
var _a;
|
|
1202
|
+
var _b, _c;
|
|
1203
|
+
const end = (_b = (_a = rows[index + 1]) === null || _a === undefined ? undefined : _a.index) !== null && _b !== undefined ? _b : body === null || body === undefined ? undefined : body.length;
|
|
1204
|
+
const what = body === null || body === undefined ? undefined : body.slice(((_c = row.index) !== null && _c !== undefined ? _c : 0) + row[0].length, end).trim();
|
|
1205
|
+
if (what) {
|
|
1206
|
+
told.set(Number(row[1]), what);
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1209
|
+
return "";
|
|
1210
|
+
});
|
|
1211
|
+
return { said: said === text3 ? text3 : said.replace(/\n{3,}/g, `
|
|
1212
|
+
|
|
1213
|
+
`).trim(), told };
|
|
1214
|
+
}
|
|
1215
|
+
TaPictureNote2.take = take;
|
|
1216
|
+
function strip(text3) {
|
|
1217
|
+
return take(text3).said;
|
|
1218
|
+
}
|
|
1219
|
+
TaPictureNote2.strip = strip;
|
|
1220
|
+
})(TaPictureNote || (TaPictureNote = {}));
|
|
1221
|
+
var TaSkillUse;
|
|
1222
|
+
(function(TaSkillUse2) {
|
|
1223
|
+
const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
|
|
1224
|
+
function parse(message) {
|
|
1225
|
+
var _a;
|
|
1226
|
+
const match = BLOCK.exec(message);
|
|
1227
|
+
if (!match) {
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === undefined ? undefined : _a.trim()) || undefined };
|
|
1231
|
+
}
|
|
1232
|
+
TaSkillUse2.parse = parse;
|
|
1233
|
+
function command(use) {
|
|
1234
|
+
return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
|
|
1235
|
+
}
|
|
1236
|
+
TaSkillUse2.command = command;
|
|
1237
|
+
})(TaSkillUse || (TaSkillUse = {}));
|
|
1238
|
+
var TaTaskNote;
|
|
1239
|
+
(function(TaTaskNote2) {
|
|
1240
|
+
const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
|
|
1241
|
+
const ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
1242
|
+
function write(note) {
|
|
1243
|
+
const attributes = [`id="${quote(note.id)}"`];
|
|
1244
|
+
if (note.was !== undefined) {
|
|
1245
|
+
attributes.push(`was="${quote(note.was)}"`);
|
|
1246
|
+
}
|
|
1247
|
+
attributes.push(`title="${quote(note.title)}"`);
|
|
1248
|
+
if (note.status !== undefined) {
|
|
1249
|
+
attributes.push(`status="${quote(note.status)}"`);
|
|
1250
|
+
}
|
|
1251
|
+
return `<task_${note.kind} ${attributes.join(" ")}>
|
|
1252
|
+
${note.body}
|
|
1253
|
+
</task_${note.kind}>`;
|
|
1254
|
+
}
|
|
1255
|
+
TaTaskNote2.write = write;
|
|
1256
|
+
function parse(text3) {
|
|
1257
|
+
const match = NOTE.exec(text3.trim());
|
|
1258
|
+
if (!match) {
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
const attributes = {};
|
|
1262
|
+
for (const [, name, value] of match[2].matchAll(ATTRIBUTE)) {
|
|
1263
|
+
attributes[name] = unquote(value);
|
|
1264
|
+
}
|
|
1265
|
+
if (!attributes.id || attributes.title === undefined) {
|
|
1266
|
+
return;
|
|
1267
|
+
}
|
|
1268
|
+
const { id, title, status, was } = attributes;
|
|
1269
|
+
return { kind: match[1], id, title, ...status ? { status } : {}, ...was ? { was } : {}, body: match[3] };
|
|
1270
|
+
}
|
|
1271
|
+
TaTaskNote2.parse = parse;
|
|
1272
|
+
function quote(text3) {
|
|
1273
|
+
return text3.replace(/&/g, "&").replace(/"/g, """).replace(/\n/g, " ");
|
|
1274
|
+
}
|
|
1275
|
+
function unquote(text3) {
|
|
1276
|
+
return text3.replace(/"/g, '"').replace(/&/g, "&");
|
|
1277
|
+
}
|
|
1278
|
+
})(TaTaskNote || (TaTaskNote = {}));
|
|
1279
|
+
var TaSecretRef;
|
|
1280
|
+
(function(TaSecretRef2) {
|
|
1281
|
+
TaSecretRef2.PACKAGE = "@celljs/ta-secrets";
|
|
1282
|
+
const REF = /\$\{?TA_SECRET_([A-Z0-9][A-Z0-9_]*)\}?/g;
|
|
1283
|
+
const KINDS2 = [
|
|
1284
|
+
[/^PHONE(?:_\d+)?$/, "phone"],
|
|
1285
|
+
[/^EMAIL(?:_\d+)?$/, "email"],
|
|
1286
|
+
[/^ID_NUMBER(?:_\d+)?$/, "idNumber"],
|
|
1287
|
+
[/^BANK_CARD(?:_\d+)?$/, "bankCard"]
|
|
1288
|
+
];
|
|
1289
|
+
function has(text3) {
|
|
1290
|
+
return text3.includes("TA_SECRET_") && new RegExp(REF.source).test(text3);
|
|
1291
|
+
}
|
|
1292
|
+
TaSecretRef2.has = has;
|
|
1293
|
+
function kind(name) {
|
|
1294
|
+
var _a;
|
|
1295
|
+
var _b;
|
|
1296
|
+
return (_b = (_a = KINDS2.find(([pattern]) => pattern.test(name))) === null || _a === undefined ? undefined : _a[1]) !== null && _b !== undefined ? _b : "secret";
|
|
1297
|
+
}
|
|
1298
|
+
TaSecretRef2.kind = kind;
|
|
1299
|
+
function split(text3) {
|
|
1300
|
+
if (!has(text3)) {
|
|
1301
|
+
return [{ text: text3 }];
|
|
1302
|
+
}
|
|
1303
|
+
const parts = [];
|
|
1304
|
+
let at = 0;
|
|
1305
|
+
for (const match of text3.matchAll(REF)) {
|
|
1306
|
+
if (match.index > at) {
|
|
1307
|
+
parts.push({ text: text3.slice(at, match.index) });
|
|
1308
|
+
}
|
|
1309
|
+
parts.push({ secret: match[1], kind: kind(match[1]) });
|
|
1310
|
+
at = match.index + match[0].length;
|
|
1311
|
+
}
|
|
1312
|
+
if (at < text3.length) {
|
|
1313
|
+
parts.push({ text: text3.slice(at) });
|
|
1314
|
+
}
|
|
1315
|
+
return parts;
|
|
1316
|
+
}
|
|
1317
|
+
TaSecretRef2.split = split;
|
|
1318
|
+
function plain(text3, label) {
|
|
1319
|
+
return has(text3) ? text3.replace(REF, (_whole, name) => label(name, kind(name))) : text3;
|
|
1320
|
+
}
|
|
1321
|
+
TaSecretRef2.plain = plain;
|
|
1322
|
+
})(TaSecretRef || (TaSecretRef = {}));
|
|
1323
|
+
|
|
1324
|
+
// web-src/publish-queue.ts
|
|
1325
|
+
var IDLE_MS = 10 * 60000;
|
|
1326
|
+
var PublishPrompt;
|
|
1327
|
+
((PublishPrompt) => {
|
|
1328
|
+
function context(item, slots, settings) {
|
|
1329
|
+
const call = (method) => `ta call ${NAME} ${method}`;
|
|
1330
|
+
const name = (id) => settings.platforms.find((one) => one.id === id)?.name ?? id;
|
|
1331
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
1332
|
+
const when = (at) => {
|
|
1333
|
+
const day = new Date(at);
|
|
1334
|
+
return `${day.getFullYear()}-${two(day.getMonth() + 1)}-${two(day.getDate())} ${two(day.getHours())}:${two(day.getMinutes())}`;
|
|
1335
|
+
};
|
|
1336
|
+
return [
|
|
1337
|
+
`Creator's queue gave piece ${item.id} the browser now: pieces are published one at a time, so no other conversation uses it meanwhile. Do not wait for one, and keep no locks or schedules of your own.`,
|
|
1338
|
+
"When it goes out on each platform, worked out from what is published and scheduled (one piece a day on a platform):",
|
|
1339
|
+
...slots.map((slot) => `- ${name(slot.platform)} (${slot.platform}): ${slot.at ? `schedule it with the platform's scheduled publishing for ${when(slot.at)}` : "publish it now"}`),
|
|
1340
|
+
`Once done, keep the links: \`${call("published")} ${item.id} '[{"platform": "...", "url": "...", "scheduled"?: "YYYY-MM-DD HH:mm"}]' <minutes>\`.`,
|
|
1341
|
+
`When it cannot be done (not signed in, a warning of the platform), say why: \`${call("stopped")} ${item.id} '<why, a line>'\`. Either lets the next piece go.`
|
|
1342
|
+
].join(`
|
|
1343
|
+
`);
|
|
1344
|
+
}
|
|
1345
|
+
PublishPrompt.context = context;
|
|
1346
|
+
})(PublishPrompt ||= {});
|
|
1347
|
+
|
|
1348
|
+
class PublishQueue {
|
|
550
1349
|
host;
|
|
1350
|
+
store;
|
|
551
1351
|
now;
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
count = 0;
|
|
555
|
-
constructor(host, now = Date.now) {
|
|
1352
|
+
idle;
|
|
1353
|
+
constructor(host, store, now) {
|
|
556
1354
|
this.host = host;
|
|
1355
|
+
this.store = store;
|
|
557
1356
|
this.now = now;
|
|
558
1357
|
}
|
|
559
|
-
|
|
560
|
-
this.
|
|
561
|
-
|
|
562
|
-
|
|
1358
|
+
begin() {
|
|
1359
|
+
const stop = this.host.onSessionEvent((event) => void this.watch(event).catch((error) => PublishQueue.failed(error)));
|
|
1360
|
+
return () => {
|
|
1361
|
+
stop();
|
|
1362
|
+
this.rest();
|
|
1363
|
+
};
|
|
1364
|
+
}
|
|
1365
|
+
async pump() {
|
|
1366
|
+
const started = await this.store.serial(async () => {
|
|
1367
|
+
const items = await this.store.items();
|
|
1368
|
+
if (items.some((one) => one.publishing?.state === "running" && !one.dropped)) {
|
|
1369
|
+
return;
|
|
563
1370
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
1371
|
+
const next = PublishUtil.publishQueue(items)[0];
|
|
1372
|
+
if (!next?.publishing) {
|
|
1373
|
+
return;
|
|
1374
|
+
}
|
|
1375
|
+
const now = this.now();
|
|
1376
|
+
const publishing = { ...next.publishing, state: "running", since: now, slots: PublishUtil.slots(items, next, now) };
|
|
1377
|
+
const changed = CreatorUtil.change(items, next.id, { publishing }, now);
|
|
1378
|
+
await this.store.write(changed);
|
|
1379
|
+
return changed.find((one) => one.id === next.id);
|
|
1380
|
+
}).catch(() => {
|
|
1381
|
+
return;
|
|
1382
|
+
});
|
|
1383
|
+
if (started) {
|
|
1384
|
+
await this.tell(started).catch((error) => this.store.stopped(started.id, `Its conversation could not be told: ${error instanceof Error ? error.message : error}`));
|
|
1385
|
+
}
|
|
567
1386
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
1387
|
+
async tell(item) {
|
|
1388
|
+
const { host } = this;
|
|
1389
|
+
const settings = await this.store.settings();
|
|
1390
|
+
const publishing = item.publishing;
|
|
1391
|
+
const ask = publishing?.ask ?? `${item.id}: publish it on each platform and keep the links`;
|
|
1392
|
+
const message = TaMessageSource.mark(TaMessageContext.wrap(PublishPrompt.context(item, publishing?.slots ?? [], settings), ask), NAME);
|
|
1393
|
+
let sessionId;
|
|
1394
|
+
if (item.session) {
|
|
1395
|
+
const open = (await host.listSessions()).find((one) => one.sessionFile === item.session);
|
|
1396
|
+
const cwd = open?.cwd ?? await host.sessionCwd(item.session);
|
|
1397
|
+
sessionId = open?.sessionId ?? (cwd ? (await host.openSession({ cwd, sessionFile: item.session })).sessionId : undefined);
|
|
1398
|
+
}
|
|
1399
|
+
if (!sessionId) {
|
|
1400
|
+
const { cwd } = await host.getServerInfo();
|
|
1401
|
+
const opened = await host.openSession({ cwd });
|
|
1402
|
+
sessionId = opened.sessionId;
|
|
1403
|
+
await host.setSessionName(sessionId, item.title);
|
|
1404
|
+
if (opened.sessionFile) {
|
|
1405
|
+
await this.store.change(item.id, { session: opened.sessionFile });
|
|
1406
|
+
}
|
|
571
1407
|
}
|
|
1408
|
+
const state = await host.getState(sessionId);
|
|
1409
|
+
const input = { message, clientMessageId: `ta-creator-publish-${item.id}-${publishing?.since ?? this.now()}` };
|
|
1410
|
+
await (state.isStreaming ? host.followUp(sessionId, input) : host.prompt(sessionId, input));
|
|
1411
|
+
this.arm(item.id, IDLE_MS);
|
|
572
1412
|
}
|
|
573
|
-
|
|
574
|
-
|
|
1413
|
+
async watch(event) {
|
|
1414
|
+
if (!event.sessionFile) {
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1417
|
+
const item = (await this.store.items()).find((one) => one.publishing?.state === "running" && one.session === event.sessionFile);
|
|
1418
|
+
if (!item) {
|
|
1419
|
+
return;
|
|
1420
|
+
}
|
|
1421
|
+
if (event.type === "turn_start") {
|
|
1422
|
+
this.rest(item.id);
|
|
1423
|
+
} else if (event.aborted || event.error) {
|
|
1424
|
+
await this.store.stopped(item.id, event.aborted ? "Stopped by the user." : event.error ?? "");
|
|
1425
|
+
} else {
|
|
1426
|
+
this.arm(item.id, IDLE_MS);
|
|
1427
|
+
}
|
|
575
1428
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
1429
|
+
async resume() {
|
|
1430
|
+
const running = (await this.store.items()).find((one) => one.publishing?.state === "running");
|
|
1431
|
+
if (running) {
|
|
1432
|
+
this.arm(running.id, IDLE_MS);
|
|
1433
|
+
} else {
|
|
1434
|
+
await this.pump();
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
arm(id, ms) {
|
|
1438
|
+
this.rest();
|
|
1439
|
+
const timer = setTimeout(() => {
|
|
1440
|
+
this.idle = undefined;
|
|
1441
|
+
this.store.items().then((items) => {
|
|
1442
|
+
const item = items.find((one) => one.id === id);
|
|
1443
|
+
if (item?.publishing?.state === "running") {
|
|
1444
|
+
return this.store.stopped(id, "Its conversation went idle without publishing it or saying why.");
|
|
1445
|
+
}
|
|
1446
|
+
return;
|
|
1447
|
+
}).catch((error) => PublishQueue.failed(error));
|
|
1448
|
+
}, ms);
|
|
1449
|
+
timer.unref?.();
|
|
1450
|
+
this.idle = { id, timer };
|
|
1451
|
+
}
|
|
1452
|
+
static failed(error) {
|
|
1453
|
+
console.error(`${NAME}: the queue of publishing failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1454
|
+
}
|
|
1455
|
+
rest(id) {
|
|
1456
|
+
if (this.idle && (!id || this.idle.id === id)) {
|
|
1457
|
+
clearTimeout(this.idle.timer);
|
|
1458
|
+
this.idle = undefined;
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
// web-src/host-base.ts
|
|
1464
|
+
var CRON = "@celljs/ta-cron";
|
|
1465
|
+
|
|
1466
|
+
class CreatorHostBase {
|
|
1467
|
+
host;
|
|
1468
|
+
now;
|
|
1469
|
+
stops = [];
|
|
1470
|
+
queue = Promise.resolve();
|
|
1471
|
+
count = 0;
|
|
1472
|
+
publisher;
|
|
1473
|
+
constructor(host, now = Date.now) {
|
|
1474
|
+
this.host = host;
|
|
1475
|
+
this.now = now;
|
|
1476
|
+
this.publisher = new PublishQueue(host, {
|
|
1477
|
+
items: () => this.items(),
|
|
1478
|
+
settings: () => this.settings(),
|
|
1479
|
+
serial: (work) => this.serial(work),
|
|
1480
|
+
write: (items) => this.host.setExtensionData(NAME, Keys.ITEMS, items),
|
|
1481
|
+
change: (id, patch) => this.change(id, patch),
|
|
1482
|
+
stopped: (id, why) => this.stopped(id, why)
|
|
1483
|
+
}, now);
|
|
1484
|
+
}
|
|
1485
|
+
dispose() {
|
|
1486
|
+
for (const stop of this.stops) {
|
|
1487
|
+
stop();
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
settings() {
|
|
1491
|
+
return this.data(Keys.SETTINGS).then(CreatorUtil.settings);
|
|
1492
|
+
}
|
|
1493
|
+
setSettings(patch) {
|
|
1494
|
+
return this.serial(async () => {
|
|
1495
|
+
const next = CreatorUtil.settings({ ...await this.settings(), ...patch && typeof patch === "object" ? patch : {} });
|
|
579
1496
|
await this.host.setExtensionData(NAME, Keys.SETTINGS, next);
|
|
580
1497
|
return next;
|
|
581
1498
|
});
|
|
@@ -584,89 +1501,8 @@ class CreatorHost {
|
|
|
584
1501
|
const items = await this.items();
|
|
585
1502
|
return stage ? items.filter((one) => one.stage === stage && !one.dropped) : items;
|
|
586
1503
|
}
|
|
587
|
-
async brief(task) {
|
|
588
|
-
const now = this.now();
|
|
589
|
-
const [settings, items, weeks] = await Promise.all([this.settings(), this.items(), this.weeks()]);
|
|
590
|
-
const platforms = CreatorUtil.picked(settings).map((one) => one.name);
|
|
591
|
-
const columns = CreatorUtil.columns(items, now);
|
|
592
|
-
const series = settings.series.map((one) => ({
|
|
593
|
-
id: one.id,
|
|
594
|
-
name: one.name,
|
|
595
|
-
about: one.about,
|
|
596
|
-
ordered: one.ordered,
|
|
597
|
-
perWeek: one.perWeek,
|
|
598
|
-
waiting: columns.topic.filter((item) => item.series === one.id).length,
|
|
599
|
-
making: columns.making.filter((item) => item.series === one.id).length + columns.review.filter((item) => item.series === one.id).length,
|
|
600
|
-
published: columns.published.filter((item) => item.series === one.id).length,
|
|
601
|
-
...one.ordered ? {
|
|
602
|
-
lessons: items.filter((item) => item.series === one.id && !item.dropped).sort((a, b) => (a.number ?? 0) - (b.number ?? 0)).map((item) => `${item.number ?? "?"}. ${item.title}`)
|
|
603
|
-
} : {}
|
|
604
|
-
}));
|
|
605
|
-
const insights = CreatorUtil.latestInsights(await this.insightsKept()).map((one) => ({ text: one.text, tone: one.tone, series: one.series }));
|
|
606
|
-
switch (task) {
|
|
607
|
-
case "topics":
|
|
608
|
-
return {
|
|
609
|
-
series,
|
|
610
|
-
insights,
|
|
611
|
-
niche: settings.niche,
|
|
612
|
-
platforms,
|
|
613
|
-
sources: settings.sources,
|
|
614
|
-
offer: CreatorUtil.offer(settings, weeks, now),
|
|
615
|
-
titles: items.filter((one) => now - one.at < 30 * DAY2).map((one) => one.title).slice(-80),
|
|
616
|
-
waiting: columns.topic.length
|
|
617
|
-
};
|
|
618
|
-
case "review": {
|
|
619
|
-
const week = CreatorUtil.weekOf(now - 7 * DAY2);
|
|
620
|
-
const from = new Date(`${week}T00:00:00`).getTime();
|
|
621
|
-
return {
|
|
622
|
-
week,
|
|
623
|
-
platforms,
|
|
624
|
-
published: items.filter((one) => one.stage === "published").filter((one) => {
|
|
625
|
-
const at = CreatorUtil.publishedAt(one);
|
|
626
|
-
return at >= from && at < from + 7 * DAY2;
|
|
627
|
-
}).map((one) => ({ id: one.id, title: one.title, series: one.series, form: one.form, kind: one.kind, links: one.links })),
|
|
628
|
-
recent: items.filter((one) => one.stage === "published" && !one.dropped && now - CreatorUtil.publishedAt(one) < 28 * DAY2).map((one) => ({ id: one.id, title: one.title, series: one.series, links: one.links, stats: one.stats })),
|
|
629
|
-
series,
|
|
630
|
-
numbers: weeks.filter((one) => one.week >= CreatorUtil.weekOf(now - 21 * DAY2)),
|
|
631
|
-
minutes: weeks.find((one) => one.week === week)?.minutes ?? 0,
|
|
632
|
-
minutesCap: settings.minutesCap,
|
|
633
|
-
goal: settings.goal ? { ...settings.goal, progress: CreatorUtil.progress(items, settings.goal, now) } : undefined
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
|
-
case "analysis": {
|
|
637
|
-
const analysis = CreatorUtil.analysis(items, settings);
|
|
638
|
-
const name = (id) => settings.series.find((one) => one.id === id)?.name ?? id;
|
|
639
|
-
return {
|
|
640
|
-
...analysis,
|
|
641
|
-
series: analysis.series.map((one) => ({ ...one, name: name(one.key) })),
|
|
642
|
-
top: analysis.top.map((one) => ({
|
|
643
|
-
id: one.item.id,
|
|
644
|
-
title: one.item.title,
|
|
645
|
-
series: one.item.series,
|
|
646
|
-
kind: one.item.kind,
|
|
647
|
-
form: one.item.form,
|
|
648
|
-
views: one.views
|
|
649
|
-
})),
|
|
650
|
-
insights
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
default:
|
|
654
|
-
throw new Error(`No such brief: ${task}. One of topics, review, analysis.`);
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
topics(topics) {
|
|
658
|
-
if (!Array.isArray(topics)) {
|
|
659
|
-
return Promise.reject(new Error("Topics are an array of { title, form, kind, why, heat, until?, seen, origin? }."));
|
|
660
|
-
}
|
|
661
|
-
return this.serial(async () => {
|
|
662
|
-
const [kept, settings] = await Promise.all([this.items(), this.settings()]);
|
|
663
|
-
const { items, added } = CreatorUtil.addTopics(kept, topics, this.now(), () => this.id(), settings.series);
|
|
664
|
-
await this.host.setExtensionData(NAME, Keys.ITEMS, items);
|
|
665
|
-
return added;
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
1504
|
update(id, patch) {
|
|
669
|
-
const kept = ["stage", "approved", "links", "dropped", "stats"];
|
|
1505
|
+
const kept = ["stage", "approved", "publishing", "links", "dropped", "stats", "needs", "commentsAt", "commentsGap"];
|
|
670
1506
|
return this.change(id, Object.fromEntries(Object.entries(patch ?? {}).filter(([key]) => !kept.includes(key))));
|
|
671
1507
|
}
|
|
672
1508
|
start(id) {
|
|
@@ -692,53 +1528,63 @@ class CreatorHost {
|
|
|
692
1528
|
return items.find((one) => one.id === id);
|
|
693
1529
|
});
|
|
694
1530
|
}
|
|
695
|
-
insights(insights) {
|
|
696
|
-
if (!Array.isArray(insights)) {
|
|
697
|
-
return Promise.reject(new Error('Insights are an array of { text, tone: "good" | "bad" | "idea", series? }.'));
|
|
698
|
-
}
|
|
699
|
-
return this.serial(async () => {
|
|
700
|
-
const [kept, settings] = await Promise.all([this.insightsKept(), this.settings()]);
|
|
701
|
-
const next = CreatorUtil.addInsights(kept, insights, settings.series, this.now());
|
|
702
|
-
await this.host.setExtensionData(NAME, Keys.INSIGHTS, next);
|
|
703
|
-
return CreatorUtil.latestInsights(next);
|
|
704
|
-
});
|
|
705
|
-
}
|
|
706
1531
|
async submit(id) {
|
|
707
1532
|
const [settings, items] = await Promise.all([this.settings(), this.items()]);
|
|
708
1533
|
const item = items.find((one) => one.id === id);
|
|
709
|
-
const missing = CreatorUtil.picked(settings).filter((platform) => item?.form === "post" ? !!platform.post : true).filter((platform) => !item?.versions?.some((one) => one.platform === platform.id && one.files.length));
|
|
710
1534
|
if (!item) {
|
|
711
1535
|
throw new Error(`No such piece: ${id}.`);
|
|
712
1536
|
}
|
|
1537
|
+
const missing = CreatorUtil.platformsFor(settings, item).filter(({ platform }) => !item.versions?.some((one) => one.platform === platform.id && CreatorUtil.ready(one, item.form)));
|
|
713
1538
|
if (missing.length) {
|
|
714
|
-
throw new Error(`No version yet for ${missing.map((
|
|
1539
|
+
throw new Error(`No version yet for ${missing.map(({ platform, form }) => `${platform.name} (${form})`).join(", ")}.`);
|
|
715
1540
|
}
|
|
716
|
-
if (!item.versions?.some((one) => one.
|
|
717
|
-
throw new Error("No version yet: none of the platforms picked takes this
|
|
1541
|
+
if (!item.versions?.some((one) => CreatorUtil.ready(one, item.form))) {
|
|
1542
|
+
throw new Error("No version yet: none of the platforms picked takes a form of this piece.");
|
|
718
1543
|
}
|
|
719
1544
|
if (!item.checks?.length) {
|
|
720
1545
|
throw new Error("Check it first (the AI label, private information, the length of each version), and keep the checks.");
|
|
721
1546
|
}
|
|
722
1547
|
return this.change(id, { stage: "review", done: [...STEPS] });
|
|
723
1548
|
}
|
|
724
|
-
approve(id, minutes = 0) {
|
|
725
|
-
|
|
1549
|
+
async approve(id, minutes = 0, ask) {
|
|
1550
|
+
const now = this.now();
|
|
1551
|
+
const item = await this.change(id, { approved: now, publishing: { state: "queued", since: now, ...ask ? { ask: String(ask) } : {} } }, minutes);
|
|
1552
|
+
this.publisher.pump();
|
|
1553
|
+
return item;
|
|
1554
|
+
}
|
|
1555
|
+
async stopped(id, why) {
|
|
1556
|
+
const item = await this.changeIf(id, (one) => !!one.publishing, (one) => ({ publishing: { ...one.publishing, state: "stopped", since: this.now(), note: String(why ?? "") } }));
|
|
1557
|
+
this.publisher.pump();
|
|
1558
|
+
return item;
|
|
1559
|
+
}
|
|
1560
|
+
async slots(id) {
|
|
1561
|
+
const items = await this.items();
|
|
1562
|
+
const item = items.find((one) => one.id === id);
|
|
1563
|
+
if (!item) {
|
|
1564
|
+
throw new Error(`No such piece: ${id}.`);
|
|
1565
|
+
}
|
|
1566
|
+
return item.publishing?.state === "running" && item.publishing.slots ? item.publishing.slots : PublishUtil.slots(items, item, this.now());
|
|
726
1567
|
}
|
|
727
1568
|
revise(id, note, minutes = 0) {
|
|
728
1569
|
return this.items().then((items) => {
|
|
729
1570
|
const item = items.find((one) => one.id === id);
|
|
730
1571
|
const checks = [...item?.checks ?? [], { text: String(note).slice(0, 200), ok: false }];
|
|
731
|
-
return this.change(id, { stage: "making", approved: undefined, checks }, minutes)
|
|
1572
|
+
return this.change(id, { stage: "making", approved: undefined, publishing: undefined, checks }, minutes).then(async (changed) => {
|
|
1573
|
+
await this.serial(async () => this.host.setExtensionData(NAME, Keys.LESSONS, ChannelUtil.lessons([{ text: String(note).slice(0, 300), item: id, at: this.now() }, ...await this.lessons()])));
|
|
1574
|
+
return changed;
|
|
1575
|
+
});
|
|
732
1576
|
});
|
|
733
1577
|
}
|
|
734
|
-
published(id, links, minutes = 0) {
|
|
1578
|
+
async published(id, links, minutes = 0) {
|
|
735
1579
|
const now = this.now();
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
});
|
|
1580
|
+
const added = (Array.isArray(links) ? links : []).map((one) => ({ ...one, at: now }));
|
|
1581
|
+
const item = await this.changeIf(id, () => true, (one) => ({
|
|
1582
|
+
stage: "published",
|
|
1583
|
+
publishing: undefined,
|
|
1584
|
+
links: [...(one.links ?? []).filter((link) => !added.some((it) => it.platform === link.platform)), ...added]
|
|
1585
|
+
}), minutes);
|
|
1586
|
+
this.publisher.pump();
|
|
1587
|
+
return item;
|
|
742
1588
|
}
|
|
743
1589
|
week(week, platforms) {
|
|
744
1590
|
return this.serial(async () => {
|
|
@@ -747,6 +1593,25 @@ class CreatorHost {
|
|
|
747
1593
|
return weeks;
|
|
748
1594
|
});
|
|
749
1595
|
}
|
|
1596
|
+
changeIf(id, when, patch, minutes = 0) {
|
|
1597
|
+
return this.serial(async () => {
|
|
1598
|
+
const items = await this.items();
|
|
1599
|
+
const item = items.find((one) => one.id === id);
|
|
1600
|
+
if (!item) {
|
|
1601
|
+
throw new Error(`No such piece: ${id}.`);
|
|
1602
|
+
}
|
|
1603
|
+
if (!when(item)) {
|
|
1604
|
+
return item;
|
|
1605
|
+
}
|
|
1606
|
+
const now = this.now();
|
|
1607
|
+
const changed = CreatorUtil.change(items, id, patch(item), now);
|
|
1608
|
+
await this.host.setExtensionData(NAME, Keys.ITEMS, changed);
|
|
1609
|
+
if (minutes > 0) {
|
|
1610
|
+
await this.host.setExtensionData(NAME, Keys.WEEKS, CreatorUtil.addMinutes(await this.weeks(), Math.min(minutes, 120), now));
|
|
1611
|
+
}
|
|
1612
|
+
return changed.find((one) => one.id === id);
|
|
1613
|
+
});
|
|
1614
|
+
}
|
|
750
1615
|
change(id, patch, minutes = 0) {
|
|
751
1616
|
return this.serial(async () => {
|
|
752
1617
|
const now = this.now();
|
|
@@ -797,8 +1662,17 @@ class CreatorHost {
|
|
|
797
1662
|
items() {
|
|
798
1663
|
return this.data(Keys.ITEMS).then(CreatorUtil.items);
|
|
799
1664
|
}
|
|
1665
|
+
async commentsKept() {
|
|
1666
|
+
return ChannelUtil.comments(await this.data(Keys.COMMENTS), this.now());
|
|
1667
|
+
}
|
|
1668
|
+
lessons() {
|
|
1669
|
+
return this.data(Keys.LESSONS).then(ChannelUtil.lessons);
|
|
1670
|
+
}
|
|
1671
|
+
phasesKept() {
|
|
1672
|
+
return this.data(Keys.PHASES).then(ChannelUtil.phases);
|
|
1673
|
+
}
|
|
800
1674
|
insightsKept() {
|
|
801
|
-
return this.data(Keys.INSIGHTS).then(
|
|
1675
|
+
return this.data(Keys.INSIGHTS).then(ChannelUtil.insights);
|
|
802
1676
|
}
|
|
803
1677
|
weeks() {
|
|
804
1678
|
return this.data(Keys.WEEKS).then(CreatorUtil.weeks);
|
|
@@ -819,6 +1693,429 @@ class CreatorHost {
|
|
|
819
1693
|
});
|
|
820
1694
|
}
|
|
821
1695
|
}
|
|
1696
|
+
|
|
1697
|
+
// web-src/host.ts
|
|
1698
|
+
var CRON2 = "@celljs/ta-cron";
|
|
1699
|
+
var INITIATIVE = "@celljs/ta-initiative";
|
|
1700
|
+
var DAY3 = 86400000;
|
|
1701
|
+
var TICK = 10 * 60000;
|
|
1702
|
+
var RUN_GAP = 2 * 3600000;
|
|
1703
|
+
var SEND_GAP = 5 * 60000;
|
|
1704
|
+
var AWAKE = [9, 23];
|
|
1705
|
+
function replyLevel(level) {
|
|
1706
|
+
return level === "act" || level === "ask" ? level : "off";
|
|
1707
|
+
}
|
|
1708
|
+
class CreatorHost extends CreatorHostBase {
|
|
1709
|
+
ranAt = 0;
|
|
1710
|
+
soon;
|
|
1711
|
+
defined = false;
|
|
1712
|
+
async begin() {
|
|
1713
|
+
this.stops.push(this.host.onExtensionData((name, key, cwd) => {
|
|
1714
|
+
if (name === NAME && !cwd && key === Keys.SETTINGS) {
|
|
1715
|
+
this.syncTasks();
|
|
1716
|
+
}
|
|
1717
|
+
}));
|
|
1718
|
+
this.stops.push(this.publisher.begin());
|
|
1719
|
+
const first = setTimeout(() => {
|
|
1720
|
+
this.syncTasks();
|
|
1721
|
+
this.publisher.resume();
|
|
1722
|
+
}, 5000);
|
|
1723
|
+
const tick = setInterval(() => void this.tick(), TICK);
|
|
1724
|
+
tick.unref?.();
|
|
1725
|
+
this.stops.push(() => clearTimeout(first), () => clearInterval(tick), () => this.soon && clearTimeout(this.soon));
|
|
1726
|
+
}
|
|
1727
|
+
async brief(task, id) {
|
|
1728
|
+
const now = this.now();
|
|
1729
|
+
const [settings, items, weeks, kept, comments] = await Promise.all([
|
|
1730
|
+
this.settings(),
|
|
1731
|
+
this.items(),
|
|
1732
|
+
this.weeks(),
|
|
1733
|
+
this.insightsKept(),
|
|
1734
|
+
this.commentsKept()
|
|
1735
|
+
]);
|
|
1736
|
+
const platforms = CreatorUtil.picked(settings).map((one) => one.name);
|
|
1737
|
+
const columns = CreatorUtil.columns(items, now);
|
|
1738
|
+
const series = settings.series.map((one) => ({
|
|
1739
|
+
id: one.id,
|
|
1740
|
+
name: one.name,
|
|
1741
|
+
about: one.about,
|
|
1742
|
+
ordered: one.ordered,
|
|
1743
|
+
perWeek: one.perWeek,
|
|
1744
|
+
waiting: columns.topic.filter((item) => item.series === one.id).length,
|
|
1745
|
+
making: columns.making.filter((item) => item.series === one.id).length + columns.review.filter((item) => item.series === one.id).length,
|
|
1746
|
+
published: columns.published.filter((item) => item.series === one.id).length,
|
|
1747
|
+
...one.ordered ? {
|
|
1748
|
+
lessons: items.filter((item) => item.series === one.id && !item.dropped).sort((a, b) => (a.number ?? 0) - (b.number ?? 0)).map((item) => `${item.number ?? "?"}. ${item.title}`)
|
|
1749
|
+
} : {}
|
|
1750
|
+
}));
|
|
1751
|
+
const strategy = ChannelUtil.latestInsights(kept).map((one) => ({
|
|
1752
|
+
text: one.text,
|
|
1753
|
+
tone: one.tone,
|
|
1754
|
+
series: one.series,
|
|
1755
|
+
...one.by ? { by: one.by } : {}
|
|
1756
|
+
}));
|
|
1757
|
+
const insights = strategy;
|
|
1758
|
+
const asked = comments.filter((one) => (one.class === "question" || one.class === "suggestion") && !one.topic && now - one.at < 14 * DAY3).slice(-40).map((one) => ({ id: one.id, class: one.class, text: one.text, likes: one.likes }));
|
|
1759
|
+
switch (task) {
|
|
1760
|
+
case "topics":
|
|
1761
|
+
return {
|
|
1762
|
+
series,
|
|
1763
|
+
strategy,
|
|
1764
|
+
asked,
|
|
1765
|
+
materials: columns.materials.map((one) => ({
|
|
1766
|
+
id: one.id,
|
|
1767
|
+
title: one.title,
|
|
1768
|
+
missing: (one.needs ?? []).filter((need) => !need.done).map((need) => need.text),
|
|
1769
|
+
days: Math.floor((now - one.changedAt) / DAY3)
|
|
1770
|
+
})),
|
|
1771
|
+
niche: settings.niche,
|
|
1772
|
+
platforms,
|
|
1773
|
+
inside: CreatorUtil.picked(settings).filter((one) => one.internal).map((one) => one.name),
|
|
1774
|
+
sources: settings.sources,
|
|
1775
|
+
offer: CreatorUtil.offer(settings, weeks, now),
|
|
1776
|
+
titles: items.filter((one) => now - one.at < 30 * DAY3).map((one) => one.title).slice(-80),
|
|
1777
|
+
waiting: columns.topic.length
|
|
1778
|
+
};
|
|
1779
|
+
case "review": {
|
|
1780
|
+
const week = CreatorUtil.weekOf(now - 7 * DAY3);
|
|
1781
|
+
const from = new Date(`${week}T00:00:00`).getTime();
|
|
1782
|
+
return {
|
|
1783
|
+
week,
|
|
1784
|
+
platforms,
|
|
1785
|
+
published: items.filter((one) => one.stage === "published").filter((one) => {
|
|
1786
|
+
const at = CreatorUtil.publishedAt(one);
|
|
1787
|
+
return at >= from && at < from + 7 * DAY3;
|
|
1788
|
+
}).map((one) => ({ id: one.id, title: one.title, series: one.series, form: one.form, kind: one.kind, links: one.links })),
|
|
1789
|
+
recent: items.filter((one) => one.stage === "published" && !one.dropped && now - CreatorUtil.publishedAt(one) < 28 * DAY3).map((one) => ({ id: one.id, title: one.title, series: one.series, links: one.links, stats: one.stats })),
|
|
1790
|
+
series,
|
|
1791
|
+
numbers: weeks.filter((one) => one.week >= CreatorUtil.weekOf(now - 21 * DAY3)),
|
|
1792
|
+
minutes: weeks.find((one) => one.week === week)?.minutes ?? 0,
|
|
1793
|
+
minutesCap: settings.minutesCap,
|
|
1794
|
+
goal: settings.goal ? { ...settings.goal, progress: CreatorUtil.progress(items, settings.goal, now) } : undefined,
|
|
1795
|
+
strategy: settings.strategy,
|
|
1796
|
+
rules: strategy,
|
|
1797
|
+
declined: kept.filter((one) => one.state === "declined").map((one) => one.text),
|
|
1798
|
+
phase: ChannelUtil.phaseDue(settings, items, await this.phasesKept(), now)
|
|
1799
|
+
};
|
|
1800
|
+
}
|
|
1801
|
+
case "make": {
|
|
1802
|
+
const item = items.find((one) => one.id === id);
|
|
1803
|
+
if (!item) {
|
|
1804
|
+
throw new Error(`brief make needs the id of a piece: ${id}.`);
|
|
1805
|
+
}
|
|
1806
|
+
return {
|
|
1807
|
+
item: {
|
|
1808
|
+
id: item.id,
|
|
1809
|
+
title: item.title,
|
|
1810
|
+
form: item.form,
|
|
1811
|
+
kind: item.kind,
|
|
1812
|
+
series: settings.series.find((one) => one.id === item.series)?.name,
|
|
1813
|
+
number: item.number,
|
|
1814
|
+
why: item.why,
|
|
1815
|
+
origin: item.origin,
|
|
1816
|
+
needs: item.needs
|
|
1817
|
+
},
|
|
1818
|
+
reach: CreatorUtil.reach(item, settings),
|
|
1819
|
+
platforms: CreatorUtil.platformsFor(settings, item).map(({ platform, form }) => ({
|
|
1820
|
+
id: platform.id,
|
|
1821
|
+
name: platform.name,
|
|
1822
|
+
form,
|
|
1823
|
+
shape: platform[form],
|
|
1824
|
+
...platform.internal ? { internal: true } : {}
|
|
1825
|
+
})),
|
|
1826
|
+
inside: CreatorUtil.picked(settings).filter((one) => one.internal).map((one) => one.name),
|
|
1827
|
+
strategy,
|
|
1828
|
+
lessons: (await this.lessons()).slice(0, 15).map((one) => one.text),
|
|
1829
|
+
tone: CreatorUtil.toneOf(item, settings),
|
|
1830
|
+
voice: settings.voice
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
case "comments": {
|
|
1834
|
+
const title = (item) => items.find((one) => one.id === item)?.title;
|
|
1835
|
+
const link = (one) => items.find((it) => it.id === one.item)?.links?.find((it) => it.platform === one.platform)?.url;
|
|
1836
|
+
return {
|
|
1837
|
+
due: ChannelUtil.due(items, settings, now, ChannelUtil.PACE.ride).map((one) => ({
|
|
1838
|
+
id: one.id,
|
|
1839
|
+
title: one.title,
|
|
1840
|
+
links: ChannelUtil.live(one, now),
|
|
1841
|
+
since: one.commentsAt
|
|
1842
|
+
})),
|
|
1843
|
+
send: comments.filter((one) => one.reply?.state === "approved").map((one) => ({
|
|
1844
|
+
id: one.id,
|
|
1845
|
+
piece: title(one.item),
|
|
1846
|
+
platform: one.platform,
|
|
1847
|
+
link: link(one),
|
|
1848
|
+
comment: one.text,
|
|
1849
|
+
reply: one.reply?.text
|
|
1850
|
+
})),
|
|
1851
|
+
withdraw: comments.filter((one) => one.reply?.state === "withdrawn").map((one) => ({
|
|
1852
|
+
id: one.id,
|
|
1853
|
+
piece: title(one.item),
|
|
1854
|
+
platform: one.platform,
|
|
1855
|
+
link: link(one),
|
|
1856
|
+
comment: one.text,
|
|
1857
|
+
reply: one.reply?.text
|
|
1858
|
+
})),
|
|
1859
|
+
levels: await this.levels(),
|
|
1860
|
+
tone: CreatorUtil.toneOf(undefined, settings),
|
|
1861
|
+
examples: ChannelUtil.examples(comments),
|
|
1862
|
+
limit: 20
|
|
1863
|
+
};
|
|
1864
|
+
}
|
|
1865
|
+
case "analysis": {
|
|
1866
|
+
const analysis = ChannelUtil.analysis(items, settings);
|
|
1867
|
+
const name = (id2) => settings.series.find((one) => one.id === id2)?.name ?? id2;
|
|
1868
|
+
return {
|
|
1869
|
+
...analysis,
|
|
1870
|
+
series: analysis.series.map((one) => ({ ...one, name: name(one.key) })),
|
|
1871
|
+
top: analysis.top.map((one) => ({
|
|
1872
|
+
id: one.item.id,
|
|
1873
|
+
title: one.item.title,
|
|
1874
|
+
series: one.item.series,
|
|
1875
|
+
kind: one.item.kind,
|
|
1876
|
+
form: one.item.form,
|
|
1877
|
+
views: one.views
|
|
1878
|
+
})),
|
|
1879
|
+
insights,
|
|
1880
|
+
comments: {
|
|
1881
|
+
byClass: Object.fromEntries(["question", "suggestion", "correction", "praise", "negative", "spam"].map((cls) => [
|
|
1882
|
+
cls,
|
|
1883
|
+
comments.filter((one) => one.class === cls && now - one.at < 28 * DAY3).length
|
|
1884
|
+
])),
|
|
1885
|
+
asked
|
|
1886
|
+
}
|
|
1887
|
+
};
|
|
1888
|
+
}
|
|
1889
|
+
default:
|
|
1890
|
+
throw new Error(`No such brief: ${task}. One of topics, review, analysis, make, comments.`);
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
topics(topics) {
|
|
1894
|
+
if (!Array.isArray(topics)) {
|
|
1895
|
+
return Promise.reject(new Error("Topics are an array of { title, form, kind, why, heat, until?, seen, origin? }."));
|
|
1896
|
+
}
|
|
1897
|
+
return this.serial(async () => {
|
|
1898
|
+
const [kept, settings] = await Promise.all([this.items(), this.settings()]);
|
|
1899
|
+
const { items, added } = CreatorUtil.addTopics(kept, topics, this.now(), () => this.id(), settings.series);
|
|
1900
|
+
await this.host.setExtensionData(NAME, Keys.ITEMS, items);
|
|
1901
|
+
const linked = new Map;
|
|
1902
|
+
for (const topic of topics) {
|
|
1903
|
+
const made = added.find((one) => one.title === String(topic?.title ?? "").trim());
|
|
1904
|
+
for (const comment of Array.isArray(topic?.comments) ? topic.comments : []) {
|
|
1905
|
+
if (made && typeof comment === "string") {
|
|
1906
|
+
linked.set(comment, made.id);
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
if (linked.size) {
|
|
1911
|
+
const comments = await this.commentsKept();
|
|
1912
|
+
await this.host.setExtensionData(NAME, Keys.COMMENTS, comments.map((one) => linked.has(one.id) ? { ...one, topic: linked.get(one.id) } : one));
|
|
1913
|
+
}
|
|
1914
|
+
return added;
|
|
1915
|
+
});
|
|
1916
|
+
}
|
|
1917
|
+
insights(insights) {
|
|
1918
|
+
if (!Array.isArray(insights)) {
|
|
1919
|
+
return Promise.reject(new Error('Insights are an array of { text, tone: "good" | "bad" | "idea", series? }.'));
|
|
1920
|
+
}
|
|
1921
|
+
return this.serial(async () => {
|
|
1922
|
+
const [kept, settings] = await Promise.all([this.insightsKept(), this.settings()]);
|
|
1923
|
+
const next = ChannelUtil.addInsights(kept, insights, settings.series, this.now(), settings.strategy);
|
|
1924
|
+
await this.host.setExtensionData(NAME, Keys.INSIGHTS, next);
|
|
1925
|
+
return settings.strategy === "manual" ? ChannelUtil.proposed(next) : ChannelUtil.latestInsights(next);
|
|
1926
|
+
});
|
|
1927
|
+
}
|
|
1928
|
+
addRule(text3, series) {
|
|
1929
|
+
return this.serial(async () => {
|
|
1930
|
+
const [kept, settings] = await Promise.all([this.insightsKept(), this.settings()]);
|
|
1931
|
+
const next = ChannelUtil.addRule(kept, String(text3 ?? ""), settings.series, this.now(), series);
|
|
1932
|
+
await this.host.setExtensionData(NAME, Keys.INSIGHTS, next);
|
|
1933
|
+
return ChannelUtil.latestInsights(next);
|
|
1934
|
+
});
|
|
1935
|
+
}
|
|
1936
|
+
rule(id, action) {
|
|
1937
|
+
return this.serial(async () => {
|
|
1938
|
+
const next = ChannelUtil.decideRule(await this.insightsKept(), id, action);
|
|
1939
|
+
await this.host.setExtensionData(NAME, Keys.INSIGHTS, next);
|
|
1940
|
+
return ChannelUtil.latestInsights(next);
|
|
1941
|
+
});
|
|
1942
|
+
}
|
|
1943
|
+
phase(input) {
|
|
1944
|
+
return this.serial(async () => {
|
|
1945
|
+
const now = this.now();
|
|
1946
|
+
let topic;
|
|
1947
|
+
if (input?.topic && typeof input.topic === "object") {
|
|
1948
|
+
const [kept, settings] = await Promise.all([this.items(), this.settings()]);
|
|
1949
|
+
const { items, added } = CreatorUtil.addTopics(kept, [{ ...input.topic, kind: "original", seen: ["阶段回顾"] }], now, () => this.id(), settings.series);
|
|
1950
|
+
await this.host.setExtensionData(NAME, Keys.ITEMS, items);
|
|
1951
|
+
topic = added[0]?.id;
|
|
1952
|
+
}
|
|
1953
|
+
const next = ChannelUtil.phases([{ ...input, topic, at: now }, ...await this.phasesKept()]);
|
|
1954
|
+
if (next[0]?.at !== now) {
|
|
1955
|
+
throw new Error("A stage is { from, to, summary, topic? }, its times Date.now() milliseconds.");
|
|
1956
|
+
}
|
|
1957
|
+
await this.host.setExtensionData(NAME, Keys.PHASES, next);
|
|
1958
|
+
return next;
|
|
1959
|
+
});
|
|
1960
|
+
}
|
|
1961
|
+
needs(id, needs) {
|
|
1962
|
+
if (!Array.isArray(needs) || !needs.length) {
|
|
1963
|
+
return Promise.reject(new Error("Needs are an array of lines, what the piece needs that you found nowhere."));
|
|
1964
|
+
}
|
|
1965
|
+
return this.change(id, { stage: "materials", needs: ChannelUtil.needsOf(needs, this.now()) });
|
|
1966
|
+
}
|
|
1967
|
+
give(id, need) {
|
|
1968
|
+
return this.items().then((items) => {
|
|
1969
|
+
const item = items.find((one) => one.id === id);
|
|
1970
|
+
if (!item?.needs?.some((one) => one.id === need)) {
|
|
1971
|
+
throw new Error(`No such need of ${id}: ${need}.`);
|
|
1972
|
+
}
|
|
1973
|
+
const needs = item.needs.map((one) => one.id === need ? { ...one, done: true } : one);
|
|
1974
|
+
const all = needs.every((one) => one.done);
|
|
1975
|
+
return this.change(id, { needs, ...all && item.stage === "materials" ? { stage: "making" } : {} });
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
skip(id) {
|
|
1979
|
+
return this.change(id, { stage: "making" });
|
|
1980
|
+
}
|
|
1981
|
+
async comments(id, input) {
|
|
1982
|
+
if (!Array.isArray(input)) {
|
|
1983
|
+
throw new Error("Comments are an array of { platform, key?, text, class, likes?, reply?, sent? }.");
|
|
1984
|
+
}
|
|
1985
|
+
const levels = await this.levels();
|
|
1986
|
+
return this.serial(async () => {
|
|
1987
|
+
const now = this.now();
|
|
1988
|
+
const items = await this.items();
|
|
1989
|
+
if (!items.some((one) => one.id === id)) {
|
|
1990
|
+
throw new Error(`No such piece: ${id}.`);
|
|
1991
|
+
}
|
|
1992
|
+
const { comments, added } = ChannelUtil.addComments(await this.commentsKept(), id, input, levels, now, () => this.id());
|
|
1993
|
+
const gap = ChannelUtil.nextGap(items.find((one) => one.id === id)?.commentsGap ?? ChannelUtil.firstGap(items), added.length);
|
|
1994
|
+
await this.host.setExtensionData(NAME, Keys.COMMENTS, comments);
|
|
1995
|
+
await this.host.setExtensionData(NAME, Keys.ITEMS, CreatorUtil.change(items, id, { commentsAt: now, commentsGap: gap }, now));
|
|
1996
|
+
return {
|
|
1997
|
+
read: input.length,
|
|
1998
|
+
added: added.length,
|
|
1999
|
+
sent: added.filter((one) => one.reply?.state === "sent").length,
|
|
2000
|
+
drafts: comments.filter((one) => one.reply?.state === "draft").length
|
|
2001
|
+
};
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
2004
|
+
replied(done) {
|
|
2005
|
+
if (!Array.isArray(done)) {
|
|
2006
|
+
return Promise.reject(new Error('Replied is an array of { id, state: "sent" | "removed" }.'));
|
|
2007
|
+
}
|
|
2008
|
+
return this.serial(async () => {
|
|
2009
|
+
const now = this.now();
|
|
2010
|
+
const states = new Map(done.map((one) => one && typeof one === "object" ? one : {}).filter((one) => typeof one.id === "string" && (one.state === "sent" || one.state === "removed")).map((one) => [one.id, one.state]));
|
|
2011
|
+
const comments = (await this.commentsKept()).map((one) => one.reply && states.has(one.id) ? { ...one, reply: { ...one.reply, state: states.get(one.id), at: now } } : one);
|
|
2012
|
+
await this.host.setExtensionData(NAME, Keys.COMMENTS, comments);
|
|
2013
|
+
return states.size;
|
|
2014
|
+
});
|
|
2015
|
+
}
|
|
2016
|
+
reply(id, action, text3) {
|
|
2017
|
+
return this.serial(async () => {
|
|
2018
|
+
const now = this.now();
|
|
2019
|
+
const comments = await this.commentsKept();
|
|
2020
|
+
const comment = comments.find((one) => one.id === id);
|
|
2021
|
+
if (!comment?.reply) {
|
|
2022
|
+
throw new Error(`No answer to: ${id}.`);
|
|
2023
|
+
}
|
|
2024
|
+
const reply = comment.reply;
|
|
2025
|
+
let next;
|
|
2026
|
+
let outcome;
|
|
2027
|
+
if (action === "send" && reply.state === "draft") {
|
|
2028
|
+
const sent = String(text3 ?? "").trim().slice(0, 500) || reply.text;
|
|
2029
|
+
next = { ...comment, reply: { ...reply, text: sent, state: "approved", ...sent !== reply.text ? { draft: reply.text } : {}, at: now } };
|
|
2030
|
+
outcome = "accepted";
|
|
2031
|
+
} else if (action === "drop" && reply.state === "draft") {
|
|
2032
|
+
next = { ...comment, reply: { ...reply, state: "dropped", at: now } };
|
|
2033
|
+
outcome = "declined";
|
|
2034
|
+
} else if (action === "withdraw" && reply.state === "sent") {
|
|
2035
|
+
next = { ...comment, reply: { ...reply, state: "withdrawn", at: now } };
|
|
2036
|
+
outcome = "declined";
|
|
2037
|
+
} else {
|
|
2038
|
+
throw new Error(`An answer ${reply.state} cannot ${action}.`);
|
|
2039
|
+
}
|
|
2040
|
+
await this.host.setExtensionData(NAME, Keys.COMMENTS, comments.map((one) => one.id === id ? next : one));
|
|
2041
|
+
if (REPLY_CLASSES.includes(comment.class)) {
|
|
2042
|
+
const kind = REPLY_KINDS[comment.class];
|
|
2043
|
+
this.initiative("record", { kind: kind.id, title: comment.text.slice(0, 120), why: next.reply?.text ?? "", outcome });
|
|
2044
|
+
}
|
|
2045
|
+
if (action !== "drop") {
|
|
2046
|
+
this.runSoon();
|
|
2047
|
+
}
|
|
2048
|
+
return next;
|
|
2049
|
+
});
|
|
2050
|
+
}
|
|
2051
|
+
async replyLevels() {
|
|
2052
|
+
const kinds = await this.initiative("kinds");
|
|
2053
|
+
return REPLY_CLASSES.map((cls) => {
|
|
2054
|
+
const status = Array.isArray(kinds) ? kinds.find((one) => one.kind?.id === REPLY_KINDS[cls].id) : undefined;
|
|
2055
|
+
return { class: cls, level: replyLevel(status?.level ?? REPLY_KINDS[cls].level), locked: !!status?.locked };
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
async setReplyLevel(cls, level) {
|
|
2059
|
+
if (!REPLY_CLASSES.includes(cls)) {
|
|
2060
|
+
throw new Error(`A class of comment answered is one of ${REPLY_CLASSES.join(", ")}.`);
|
|
2061
|
+
}
|
|
2062
|
+
const done = await this.initiative("setLevel", REPLY_KINDS[cls].id, level);
|
|
2063
|
+
if (done === undefined) {
|
|
2064
|
+
throw new Error("Turn on Initiative (ta-initiative) to set how comments are answered.");
|
|
2065
|
+
}
|
|
2066
|
+
return this.replyLevels();
|
|
2067
|
+
}
|
|
2068
|
+
async tick() {
|
|
2069
|
+
const now = this.now();
|
|
2070
|
+
const hour = new Date(now).getHours();
|
|
2071
|
+
if (hour < AWAKE[0] || hour >= AWAKE[1]) {
|
|
2072
|
+
return;
|
|
2073
|
+
}
|
|
2074
|
+
const [items, comments, settings] = await Promise.all([this.items(), this.commentsKept(), this.settings()]);
|
|
2075
|
+
const sending = comments.some((one) => one.reply?.state === "approved" || one.reply?.state === "withdrawn");
|
|
2076
|
+
const due = ChannelUtil.due(items, settings, now).length > 0;
|
|
2077
|
+
if (sending && now - this.ranAt >= SEND_GAP || due && now - this.ranAt >= RUN_GAP) {
|
|
2078
|
+
await this.runComments();
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
runSoon() {
|
|
2082
|
+
if (this.soon) {
|
|
2083
|
+
return;
|
|
2084
|
+
}
|
|
2085
|
+
this.soon = setTimeout(() => {
|
|
2086
|
+
this.soon = undefined;
|
|
2087
|
+
this.tick();
|
|
2088
|
+
}, SEND_GAP);
|
|
2089
|
+
this.soon.unref?.();
|
|
2090
|
+
}
|
|
2091
|
+
async runComments() {
|
|
2092
|
+
const made = await this.data(Keys.TASKS) ?? {};
|
|
2093
|
+
const record = made.comments;
|
|
2094
|
+
if (record && "id" in record) {
|
|
2095
|
+
this.ranAt = this.now();
|
|
2096
|
+
await this.host.callPackageHost(CRON2, "run", [record.id]).catch(() => {
|
|
2097
|
+
return;
|
|
2098
|
+
});
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
async levels() {
|
|
2102
|
+
const levels = await Promise.all(REPLY_CLASSES.map((cls) => this.initiative("level", REPLY_KINDS[cls].id)));
|
|
2103
|
+
return Object.fromEntries(REPLY_CLASSES.map((cls, at) => [cls, replyLevel(levels[at] ?? REPLY_KINDS[cls].level)]));
|
|
2104
|
+
}
|
|
2105
|
+
async initiative(method, ...params) {
|
|
2106
|
+
try {
|
|
2107
|
+
if (!this.defined) {
|
|
2108
|
+
for (const kind of Object.values(REPLY_KINDS)) {
|
|
2109
|
+
await this.host.callPackageHost(INITIATIVE, "defineKind", [kind]);
|
|
2110
|
+
}
|
|
2111
|
+
this.defined = true;
|
|
2112
|
+
}
|
|
2113
|
+
return await this.host.callPackageHost(INITIATIVE, method, params);
|
|
2114
|
+
} catch {
|
|
2115
|
+
return;
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
822
2119
|
async function activate(host) {
|
|
823
2120
|
const creator = new CreatorHost(host);
|
|
824
2121
|
await creator.begin();
|