@celljs/ta-creator 0.0.0-stage → 4.32.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 +14 -0
- package/README.md +13 -2
- package/bin/render.mjs +1181 -0
- package/host/index.mjs +589 -0
- package/package.json +65 -4
- package/skills/creator-make/SKILL.md +93 -0
- package/skills/creator-publish/SKILL.md +33 -0
- package/web/index.js +1410 -0
package/host/index.mjs
ADDED
|
@@ -0,0 +1,589 @@
|
|
|
1
|
+
// web-src/creator-protocol.ts
|
|
2
|
+
var NAME = "@celljs/ta-creator";
|
|
3
|
+
var PAGE = `${NAME}/home`;
|
|
4
|
+
var Keys;
|
|
5
|
+
((Keys) => {
|
|
6
|
+
Keys.SETTINGS = "settings";
|
|
7
|
+
Keys.ITEMS = "items";
|
|
8
|
+
Keys.WEEKS = "weeks";
|
|
9
|
+
Keys.TASKS = "tasks";
|
|
10
|
+
})(Keys ||= {});
|
|
11
|
+
var STAGES = ["topic", "making", "review", "published"];
|
|
12
|
+
var FORMS = ["video", "post"];
|
|
13
|
+
var KINDS = ["hot", "howto", "explain"];
|
|
14
|
+
var STEPS = ["script", "visuals", "voice", "captions", "versions", "checks"];
|
|
15
|
+
var ASPECTS = ["16:9", "9:16", "3:4", "1:1"];
|
|
16
|
+
var PLATFORMS = [
|
|
17
|
+
{
|
|
18
|
+
id: "bilibili",
|
|
19
|
+
name: "B站",
|
|
20
|
+
color: "#fb7299",
|
|
21
|
+
video: { aspect: "16:9" },
|
|
22
|
+
publish: "https://member.bilibili.com/platform/upload/video/frame",
|
|
23
|
+
declare: "创作声明 → 该视频使用人工智能合成技术"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: "xiaohongshu",
|
|
27
|
+
name: "小红书",
|
|
28
|
+
color: "#ff2442",
|
|
29
|
+
video: { aspect: "3:4", maxSeconds: 900 },
|
|
30
|
+
post: { aspect: "3:4", maxImages: 18 },
|
|
31
|
+
publish: "https://creator.xiaohongshu.com",
|
|
32
|
+
declare: "内容类型声明 → 笔记含 AI 合成内容"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: "channels",
|
|
36
|
+
name: "视频号",
|
|
37
|
+
color: "#fa9d3b",
|
|
38
|
+
video: { aspect: "9:16" },
|
|
39
|
+
publish: "https://channels.weixin.qq.com",
|
|
40
|
+
declare: "声明 → 内容由 AI 生成"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: "douyin",
|
|
44
|
+
name: "抖音",
|
|
45
|
+
color: "#25f4ee",
|
|
46
|
+
video: { aspect: "9:16" },
|
|
47
|
+
post: { aspect: "3:4", maxImages: 35 },
|
|
48
|
+
publish: "https://creator.douyin.com",
|
|
49
|
+
declare: "作品声明 → 内容由 AI 生成"
|
|
50
|
+
},
|
|
51
|
+
{ id: "kuaishou", name: "快手", color: "#ff6a00", video: { aspect: "9:16" }, publish: "https://cp.kuaishou.com", declare: "作者声明 → 内容由 AI 生成" },
|
|
52
|
+
{
|
|
53
|
+
id: "youtube",
|
|
54
|
+
name: "YouTube",
|
|
55
|
+
color: "#ff0033",
|
|
56
|
+
video: { aspect: "16:9" },
|
|
57
|
+
publish: "https://studio.youtube.com",
|
|
58
|
+
declare: "Altered or synthetic content → Yes"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "wechat-article",
|
|
62
|
+
name: "公众号",
|
|
63
|
+
color: "#07c160",
|
|
64
|
+
post: { aspect: "16:9" },
|
|
65
|
+
publish: "https://mp.weixin.qq.com",
|
|
66
|
+
declare: "创作来源 → 内容由 AI 生成"
|
|
67
|
+
}
|
|
68
|
+
];
|
|
69
|
+
var SOURCES = [
|
|
70
|
+
{ name: "Hacker News", url: "https://news.ycombinator.com" },
|
|
71
|
+
{ name: "GitHub Trending", url: "https://github.com/trending" },
|
|
72
|
+
{ name: "Product Hunt", url: "https://www.producthunt.com" },
|
|
73
|
+
{ name: "Hugging Face Papers", url: "https://huggingface.co/papers" }
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
// web-src/creator-util.ts
|
|
77
|
+
var DAY = 86400000;
|
|
78
|
+
var MAX_TOPICS = 200;
|
|
79
|
+
var HOT_FOR = 2 * DAY;
|
|
80
|
+
var text = (value, max = 2000) => typeof value === "string" ? value.trim().slice(0, max) : "";
|
|
81
|
+
var texts = (value, max = 50) => Array.isArray(value) ? value.map((one) => text(one, 200)).filter(Boolean).slice(0, max) : [];
|
|
82
|
+
var time = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined;
|
|
83
|
+
var oneOf = (all, value, fallback) => all.includes(value) ? value : fallback;
|
|
84
|
+
var object = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
85
|
+
var CreatorUtil;
|
|
86
|
+
((CreatorUtil) => {
|
|
87
|
+
function settings(value) {
|
|
88
|
+
const kept = object(value) ?? {};
|
|
89
|
+
const platforms = Array.isArray(kept.platforms) ? kept.platforms.map(platform).filter((one) => !!one) : [...PLATFORMS];
|
|
90
|
+
const ids = new Set(platforms.map((one) => one.id));
|
|
91
|
+
const goal = object(kept.goal);
|
|
92
|
+
return {
|
|
93
|
+
niche: text(kept.niche, 500),
|
|
94
|
+
picked: texts(kept.picked).filter((id) => ids.has(id)),
|
|
95
|
+
platforms,
|
|
96
|
+
sources: Array.isArray(kept.sources) ? kept.sources.map(source).filter((one) => !!one) : [...SOURCES],
|
|
97
|
+
...goal && time(goal.from) ? { goal: { from: time(goal.from), days: count(goal.days, 30), videos: count(goal.videos, 0), posts: count(goal.posts, 0) } } : {},
|
|
98
|
+
minutesCap: count(kept.minutesCap, 120),
|
|
99
|
+
voice: text(kept.voice, 60) || "zh-CN-XiaoxiaoNeural"
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
CreatorUtil.settings = settings;
|
|
103
|
+
function platform(value) {
|
|
104
|
+
const kept = object(value);
|
|
105
|
+
const id = text(kept?.id, 60);
|
|
106
|
+
const name = text(kept?.name, 60);
|
|
107
|
+
if (!kept || !id || !name) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const shape = (one) => {
|
|
111
|
+
const it = object(one);
|
|
112
|
+
return it ? { aspect: oneOf(ASPECTS, it.aspect, "16:9"), ...count(it.maxSeconds, 0) ? { maxSeconds: count(it.maxSeconds, 0) } : {} } : undefined;
|
|
113
|
+
};
|
|
114
|
+
const video = shape(kept.video);
|
|
115
|
+
const post = object(kept.post) ? {
|
|
116
|
+
aspect: oneOf(ASPECTS, object(kept.post)?.aspect, "3:4"),
|
|
117
|
+
...count(object(kept.post)?.maxImages, 0) ? { maxImages: count(object(kept.post)?.maxImages, 0) } : {}
|
|
118
|
+
} : undefined;
|
|
119
|
+
const publish = url(kept.publish);
|
|
120
|
+
const declare = text(kept.declare, 200);
|
|
121
|
+
return {
|
|
122
|
+
id,
|
|
123
|
+
name,
|
|
124
|
+
color: text(kept.color, 40) || "#8e8e93",
|
|
125
|
+
...video ? { video } : {},
|
|
126
|
+
...post ? { post } : {},
|
|
127
|
+
...publish ? { publish } : {},
|
|
128
|
+
...declare ? { declare } : {}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
CreatorUtil.platform = platform;
|
|
132
|
+
function items(value) {
|
|
133
|
+
return Array.isArray(value) ? value.map(item).filter((one) => !!one) : [];
|
|
134
|
+
}
|
|
135
|
+
CreatorUtil.items = items;
|
|
136
|
+
function item(value) {
|
|
137
|
+
const kept = object(value);
|
|
138
|
+
const id = text(kept?.id, 80);
|
|
139
|
+
const title = text(kept?.title, 200);
|
|
140
|
+
const at = time(kept?.at);
|
|
141
|
+
if (!kept || !id || !title || !at) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const origin = object(kept.origin);
|
|
145
|
+
const originUrl = url(origin?.url);
|
|
146
|
+
return {
|
|
147
|
+
id,
|
|
148
|
+
title,
|
|
149
|
+
form: oneOf(FORMS, kept.form, "video"),
|
|
150
|
+
kind: oneOf(KINDS, kept.kind, "howto"),
|
|
151
|
+
stage: oneOf(STAGES, kept.stage, "topic"),
|
|
152
|
+
...text(kept.why, 300) ? { why: text(kept.why, 300) } : {},
|
|
153
|
+
...typeof kept.heat === "number" ? { heat: Math.max(0, Math.min(100, Math.round(kept.heat))) } : {},
|
|
154
|
+
...time(kept.until) ? { until: time(kept.until) } : {},
|
|
155
|
+
...texts(kept.seen, 10).length ? { seen: texts(kept.seen, 10) } : {},
|
|
156
|
+
...origin && originUrl ? {
|
|
157
|
+
origin: {
|
|
158
|
+
url: originUrl,
|
|
159
|
+
...text(origin.title, 200) ? { title: text(origin.title, 200) } : {},
|
|
160
|
+
...text(origin.author, 100) ? { author: text(origin.author, 100) } : {},
|
|
161
|
+
...text(origin.licence, 100) ? { licence: text(origin.licence, 100) } : {}
|
|
162
|
+
}
|
|
163
|
+
} : {},
|
|
164
|
+
...Array.isArray(kept.done) ? { done: STEPS.filter((step) => kept.done.includes(step)) } : {},
|
|
165
|
+
...text(kept.script, 20000) ? { script: text(kept.script, 20000) } : {},
|
|
166
|
+
...Array.isArray(kept.versions) ? { versions: kept.versions.map(version).filter((one) => !!one) } : {},
|
|
167
|
+
...Array.isArray(kept.checks) ? { checks: kept.checks.map(check).filter((one) => !!one) } : {},
|
|
168
|
+
...text(kept.session, 1000) ? { session: text(kept.session, 1000) } : {},
|
|
169
|
+
...time(kept.approved) ? { approved: time(kept.approved) } : {},
|
|
170
|
+
...Array.isArray(kept.links) ? { links: kept.links.map(link).filter((one) => !!one) } : {},
|
|
171
|
+
...kept.dropped === true ? { dropped: true } : {},
|
|
172
|
+
at,
|
|
173
|
+
changedAt: time(kept.changedAt) ?? at
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
CreatorUtil.item = item;
|
|
177
|
+
function weeks(value) {
|
|
178
|
+
if (!Array.isArray(value)) {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
return value.map((one) => object(one)).filter((one) => !!one && /^\d{4}-\d{2}-\d{2}$/.test(String(one.week))).map((one) => ({
|
|
182
|
+
week: String(one.week),
|
|
183
|
+
platforms: (Array.isArray(one.platforms) ? one.platforms : []).map((it) => object(it)).filter((it) => !!it && !!text(it.platform, 60)).map((it) => ({
|
|
184
|
+
platform: text(it.platform, 60),
|
|
185
|
+
views: count(it.views, 0),
|
|
186
|
+
...typeof it.likes === "number" ? { likes: count(it.likes, 0) } : {},
|
|
187
|
+
...typeof it.follows === "number" ? { follows: count(it.follows, 0) } : {},
|
|
188
|
+
...typeof it.completion === "number" ? { completion: Math.max(0, Math.min(1, it.completion)) } : {}
|
|
189
|
+
})),
|
|
190
|
+
minutes: count(one.minutes, 0)
|
|
191
|
+
}));
|
|
192
|
+
}
|
|
193
|
+
CreatorUtil.weeks = weeks;
|
|
194
|
+
function picked(settings2) {
|
|
195
|
+
return settings2.picked.map((id) => settings2.platforms.find((one) => one.id === id)).filter((one) => !!one);
|
|
196
|
+
}
|
|
197
|
+
CreatorUtil.picked = picked;
|
|
198
|
+
function columns(items2, now) {
|
|
199
|
+
const latest = (a, b) => b.changedAt - a.changedAt;
|
|
200
|
+
const of = (stage) => items2.filter((one) => one.stage === stage && !one.dropped);
|
|
201
|
+
return {
|
|
202
|
+
topic: of("topic").filter((one) => !expired(one, now)).sort((a, b) => (b.heat ?? 0) - (a.heat ?? 0) || b.at - a.at),
|
|
203
|
+
making: of("making").sort(latest),
|
|
204
|
+
review: of("review").sort(latest),
|
|
205
|
+
published: of("published").sort((a, b) => publishedAt(b) - publishedAt(a))
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
CreatorUtil.columns = columns;
|
|
209
|
+
function expired(item2, now) {
|
|
210
|
+
return item2.stage === "topic" && item2.kind === "hot" && now > (item2.until ?? item2.at + HOT_FOR);
|
|
211
|
+
}
|
|
212
|
+
CreatorUtil.expired = expired;
|
|
213
|
+
function publishedAt(item2) {
|
|
214
|
+
return Math.min(...(item2.links ?? []).map((one) => one.at), item2.changedAt);
|
|
215
|
+
}
|
|
216
|
+
CreatorUtil.publishedAt = publishedAt;
|
|
217
|
+
function addTopics(items2, topics, now, id) {
|
|
218
|
+
const key = (title) => title.toLowerCase().replace(/[\s\p{P}]+/gu, "");
|
|
219
|
+
const titles = new Set(items2.map((one) => key(one.title)));
|
|
220
|
+
const origins = new Set(items2.map((one) => one.origin?.url).filter(Boolean));
|
|
221
|
+
const added = [];
|
|
222
|
+
for (const topic of topics) {
|
|
223
|
+
const made = item({ ...topic, id: id(), stage: "topic", at: now, changedAt: now });
|
|
224
|
+
if (!made || titles.has(key(made.title)) || made.origin && origins.has(made.origin.url)) {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
titles.add(key(made.title));
|
|
228
|
+
if (made.origin) {
|
|
229
|
+
origins.add(made.origin.url);
|
|
230
|
+
}
|
|
231
|
+
added.push(made);
|
|
232
|
+
}
|
|
233
|
+
const all = [...items2, ...added];
|
|
234
|
+
const topicsKept = all.filter((one) => one.stage === "topic");
|
|
235
|
+
const over = new Set(topicsKept.sort((a, b) => b.at - a.at).slice(MAX_TOPICS).map((one) => one.id));
|
|
236
|
+
return { items: all.filter((one) => !over.has(one.id)), added: added.filter((one) => !over.has(one.id)) };
|
|
237
|
+
}
|
|
238
|
+
CreatorUtil.addTopics = addTopics;
|
|
239
|
+
function change(items2, id, patch, now) {
|
|
240
|
+
const at = items2.findIndex((one) => one.id === id);
|
|
241
|
+
if (at < 0) {
|
|
242
|
+
throw new Error(`No such piece: ${id}.`);
|
|
243
|
+
}
|
|
244
|
+
const before = items2[at];
|
|
245
|
+
const changed = item({ ...before, ...patch, id: before.id, at: before.at, changedAt: now });
|
|
246
|
+
if (!changed) {
|
|
247
|
+
throw new Error("The change leaves the piece without a title.");
|
|
248
|
+
}
|
|
249
|
+
return items2.map((one, index) => index === at ? changed : one);
|
|
250
|
+
}
|
|
251
|
+
CreatorUtil.change = change;
|
|
252
|
+
function progress(items2, goal, now) {
|
|
253
|
+
if (!goal) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const end = goal.from + goal.days * DAY;
|
|
257
|
+
const published = items2.filter((one) => one.stage === "published" && (one.links?.length ?? 0) > 0).filter((one) => {
|
|
258
|
+
const at = publishedAt(one);
|
|
259
|
+
return at >= goal.from && at < end;
|
|
260
|
+
});
|
|
261
|
+
return {
|
|
262
|
+
videos: published.filter((one) => one.form === "video").length,
|
|
263
|
+
posts: published.filter((one) => one.form === "post").length,
|
|
264
|
+
day: Math.max(1, Math.min(goal.days, Math.floor((now - goal.from) / DAY) + 1))
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
CreatorUtil.progress = progress;
|
|
268
|
+
function weekOf(at) {
|
|
269
|
+
const day = new Date(at);
|
|
270
|
+
day.setHours(0, 0, 0, 0);
|
|
271
|
+
day.setDate(day.getDate() - (day.getDay() + 6) % 7);
|
|
272
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
273
|
+
return `${day.getFullYear()}-${two(day.getMonth() + 1)}-${two(day.getDate())}`;
|
|
274
|
+
}
|
|
275
|
+
CreatorUtil.weekOf = weekOf;
|
|
276
|
+
function minutes(weeks2, now) {
|
|
277
|
+
return weeks2.find((one) => one.week === weekOf(now))?.minutes ?? 0;
|
|
278
|
+
}
|
|
279
|
+
CreatorUtil.minutes = minutes;
|
|
280
|
+
function addMinutes(weeks2, minutes2, now) {
|
|
281
|
+
const week = weekOf(now);
|
|
282
|
+
const kept = weeks2.find((one) => one.week === week);
|
|
283
|
+
const next = { week, platforms: kept?.platforms ?? [], minutes: Math.max(0, (kept?.minutes ?? 0) + Math.round(minutes2)) };
|
|
284
|
+
return [...weeks2.filter((one) => one.week !== week), next].sort((a, b) => a.week.localeCompare(b.week)).slice(-26);
|
|
285
|
+
}
|
|
286
|
+
CreatorUtil.addMinutes = addMinutes;
|
|
287
|
+
function setWeek(weeks2, week, platforms) {
|
|
288
|
+
const kept = weeks2.find((one) => one.week === week);
|
|
289
|
+
const next = CreatorUtil.weeks([{ week, platforms, minutes: kept?.minutes ?? 0 }]);
|
|
290
|
+
if (!next.length) {
|
|
291
|
+
throw new Error(`A week is its Monday, YYYY-MM-DD: ${week}.`);
|
|
292
|
+
}
|
|
293
|
+
return [...weeks2.filter((one) => one.week !== week), ...next].sort((a, b) => a.week.localeCompare(b.week)).slice(-26);
|
|
294
|
+
}
|
|
295
|
+
CreatorUtil.setWeek = setWeek;
|
|
296
|
+
function offer(settings2, weeks2, now) {
|
|
297
|
+
return minutes(weeks2, now) >= settings2.minutesCap * 0.75 ? 2 : 6;
|
|
298
|
+
}
|
|
299
|
+
CreatorUtil.offer = offer;
|
|
300
|
+
function version(value) {
|
|
301
|
+
const kept = object(value);
|
|
302
|
+
const platform2 = text(kept?.platform, 60);
|
|
303
|
+
if (!kept || !platform2) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
const cover = text(kept.cover, 500);
|
|
307
|
+
return {
|
|
308
|
+
platform: platform2,
|
|
309
|
+
title: text(kept.title, 200),
|
|
310
|
+
text: text(kept.text, 5000),
|
|
311
|
+
tags: texts(kept.tags, 20),
|
|
312
|
+
files: texts(kept.files, 40),
|
|
313
|
+
...cover ? { cover } : {}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function check(value) {
|
|
317
|
+
const kept = object(value);
|
|
318
|
+
return kept && text(kept.text, 200) ? { text: text(kept.text, 200), ok: kept.ok === true } : undefined;
|
|
319
|
+
}
|
|
320
|
+
function link(value) {
|
|
321
|
+
const kept = object(value);
|
|
322
|
+
const href = url(kept?.url);
|
|
323
|
+
return kept && href && text(kept.platform, 60) ? { platform: text(kept.platform, 60), url: href, at: time(kept.at) ?? Date.now() } : undefined;
|
|
324
|
+
}
|
|
325
|
+
function source(value) {
|
|
326
|
+
const kept = object(value);
|
|
327
|
+
const href = url(kept?.url);
|
|
328
|
+
return kept && href && text(kept.name, 80) ? { name: text(kept.name, 80), url: href } : undefined;
|
|
329
|
+
}
|
|
330
|
+
function url(value) {
|
|
331
|
+
const raw = text(value, 1000);
|
|
332
|
+
return /^https?:\/\/\S+$/i.test(raw) ? raw : undefined;
|
|
333
|
+
}
|
|
334
|
+
function count(value, fallback) {
|
|
335
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? Math.round(value) : fallback;
|
|
336
|
+
}
|
|
337
|
+
})(CreatorUtil ||= {});
|
|
338
|
+
|
|
339
|
+
// web-src/host.ts
|
|
340
|
+
var CRON = "@celljs/ta-cron";
|
|
341
|
+
var DAY2 = 86400000;
|
|
342
|
+
var CreatorTasks;
|
|
343
|
+
((CreatorTasks) => {
|
|
344
|
+
CreatorTasks.IDS = ["topics", "review"];
|
|
345
|
+
function of(id) {
|
|
346
|
+
const call = (method) => `ta call ${NAME} ${method}`;
|
|
347
|
+
switch (id) {
|
|
348
|
+
case "topics":
|
|
349
|
+
return {
|
|
350
|
+
name: "创作者 · 热点选题",
|
|
351
|
+
when: "cron 0 8,12,18 * * *",
|
|
352
|
+
notify: "error",
|
|
353
|
+
prompt: [
|
|
354
|
+
`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) and the titles already there.`,
|
|
355
|
+
"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:",
|
|
356
|
+
'- 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.',
|
|
357
|
+
'- 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.',
|
|
358
|
+
'- kind "howto": something to show step by step on screen.',
|
|
359
|
+
"Never a topic that rewrites news unchecked, plays on fear, or touches politics, people in the news, film and TV of others, or anything of the user's employer.",
|
|
360
|
+
`Add them with \`${call("topics")} '<JSON array of { title, form: "video" | "post", kind, why (one line: why now), heat, until?, seen: [source names], origin? }>'\`.`,
|
|
361
|
+
"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."
|
|
362
|
+
].join(`
|
|
363
|
+
`)
|
|
364
|
+
};
|
|
365
|
+
case "review":
|
|
366
|
+
return {
|
|
367
|
+
name: "创作者 · 每周数据复盘",
|
|
368
|
+
when: "mon 09:00",
|
|
369
|
+
notify: "always",
|
|
370
|
+
prompt: [
|
|
371
|
+
`Run \`${call("brief review")}\` and read the JSON: what was published last week with its links, the numbers kept, the minutes the user gave it, and the goal.`,
|
|
372
|
+
"Where the numbers of a platform of last week are missing, read them from its page of data for creators in the user's browser (only read; change nothing, answer no comment, click no ads) and keep them with",
|
|
373
|
+
`\`${call("week")} <monday YYYY-MM-DD> '<JSON array of { platform, views, likes?, follows?, completion? (0–1) }>'\`.`,
|
|
374
|
+
"Then write the review as a ta-glance card: the numbers by platform against the week before, what worked and what did not (by kind and form), the minutes against the cap, how far the goal is, and three topics for this week. When the minutes passed the cap, say what to make less of. Reply in Chinese, short, for a phone."
|
|
375
|
+
].join(`
|
|
376
|
+
`)
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
CreatorTasks.of = of;
|
|
381
|
+
})(CreatorTasks ||= {});
|
|
382
|
+
|
|
383
|
+
class CreatorHost {
|
|
384
|
+
host;
|
|
385
|
+
now;
|
|
386
|
+
stops = [];
|
|
387
|
+
queue = Promise.resolve();
|
|
388
|
+
count = 0;
|
|
389
|
+
constructor(host, now = Date.now) {
|
|
390
|
+
this.host = host;
|
|
391
|
+
this.now = now;
|
|
392
|
+
}
|
|
393
|
+
async begin() {
|
|
394
|
+
this.stops.push(this.host.onExtensionData((name, key, cwd) => {
|
|
395
|
+
if (name === NAME && !cwd && key === Keys.SETTINGS) {
|
|
396
|
+
this.syncTasks();
|
|
397
|
+
}
|
|
398
|
+
}));
|
|
399
|
+
const first = setTimeout(() => void this.syncTasks(), 5000);
|
|
400
|
+
this.stops.push(() => clearTimeout(first));
|
|
401
|
+
}
|
|
402
|
+
dispose() {
|
|
403
|
+
for (const stop of this.stops) {
|
|
404
|
+
stop();
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
settings() {
|
|
408
|
+
return this.data(Keys.SETTINGS).then(CreatorUtil.settings);
|
|
409
|
+
}
|
|
410
|
+
setSettings(patch) {
|
|
411
|
+
return this.serial(async () => {
|
|
412
|
+
const next = CreatorUtil.settings({ ...await this.settings(), ...patch && typeof patch === "object" ? patch : {} });
|
|
413
|
+
await this.host.setExtensionData(NAME, Keys.SETTINGS, next);
|
|
414
|
+
return next;
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
async list(stage) {
|
|
418
|
+
const items = await this.items();
|
|
419
|
+
return stage ? items.filter((one) => one.stage === stage && !one.dropped) : items;
|
|
420
|
+
}
|
|
421
|
+
async brief(task) {
|
|
422
|
+
const now = this.now();
|
|
423
|
+
const [settings, items, weeks] = await Promise.all([this.settings(), this.items(), this.weeks()]);
|
|
424
|
+
const platforms = CreatorUtil.picked(settings).map((one) => one.name);
|
|
425
|
+
switch (task) {
|
|
426
|
+
case "topics":
|
|
427
|
+
return {
|
|
428
|
+
niche: settings.niche,
|
|
429
|
+
platforms,
|
|
430
|
+
sources: settings.sources,
|
|
431
|
+
offer: CreatorUtil.offer(settings, weeks, now),
|
|
432
|
+
titles: items.filter((one) => now - one.at < 30 * DAY2).map((one) => one.title).slice(-80),
|
|
433
|
+
waiting: CreatorUtil.columns(items, now).topic.length
|
|
434
|
+
};
|
|
435
|
+
case "review": {
|
|
436
|
+
const week = CreatorUtil.weekOf(now - 7 * DAY2);
|
|
437
|
+
const from = new Date(`${week}T00:00:00`).getTime();
|
|
438
|
+
return {
|
|
439
|
+
week,
|
|
440
|
+
platforms,
|
|
441
|
+
published: items.filter((one) => one.stage === "published").filter((one) => {
|
|
442
|
+
const at = CreatorUtil.publishedAt(one);
|
|
443
|
+
return at >= from && at < from + 7 * DAY2;
|
|
444
|
+
}).map((one) => ({ title: one.title, form: one.form, kind: one.kind, links: one.links })),
|
|
445
|
+
numbers: weeks.filter((one) => one.week >= CreatorUtil.weekOf(now - 21 * DAY2)),
|
|
446
|
+
minutes: weeks.find((one) => one.week === week)?.minutes ?? 0,
|
|
447
|
+
minutesCap: settings.minutesCap,
|
|
448
|
+
goal: settings.goal ? { ...settings.goal, progress: CreatorUtil.progress(items, settings.goal, now) } : undefined
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
default:
|
|
452
|
+
throw new Error(`No such brief: ${task}. One of topics, review.`);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
topics(topics) {
|
|
456
|
+
if (!Array.isArray(topics)) {
|
|
457
|
+
return Promise.reject(new Error("Topics are an array of { title, form, kind, why, heat, until?, seen, origin? }."));
|
|
458
|
+
}
|
|
459
|
+
return this.serial(async () => {
|
|
460
|
+
const { items, added } = CreatorUtil.addTopics(await this.items(), topics, this.now(), () => this.id());
|
|
461
|
+
await this.host.setExtensionData(NAME, Keys.ITEMS, items);
|
|
462
|
+
return added;
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
update(id, patch) {
|
|
466
|
+
const kept = ["stage", "approved", "links", "dropped"];
|
|
467
|
+
return this.change(id, Object.fromEntries(Object.entries(patch ?? {}).filter(([key]) => !kept.includes(key))));
|
|
468
|
+
}
|
|
469
|
+
start(id) {
|
|
470
|
+
return this.change(id, { stage: "making", done: [] });
|
|
471
|
+
}
|
|
472
|
+
drop(id) {
|
|
473
|
+
return this.change(id, { dropped: true });
|
|
474
|
+
}
|
|
475
|
+
async submit(id) {
|
|
476
|
+
const [settings, items] = await Promise.all([this.settings(), this.items()]);
|
|
477
|
+
const item = items.find((one) => one.id === id);
|
|
478
|
+
const missing = CreatorUtil.picked(settings).filter((platform) => !item?.versions?.some((one) => one.platform === platform.id && one.files.length));
|
|
479
|
+
if (!item) {
|
|
480
|
+
throw new Error(`No such piece: ${id}.`);
|
|
481
|
+
}
|
|
482
|
+
if (missing.length) {
|
|
483
|
+
throw new Error(`No version yet for ${missing.map((one) => one.name).join(", ")}.`);
|
|
484
|
+
}
|
|
485
|
+
if (!item.checks?.length) {
|
|
486
|
+
throw new Error("Check it first (the AI label, private information, the length of each version), and keep the checks.");
|
|
487
|
+
}
|
|
488
|
+
return this.change(id, { stage: "review", done: [...STEPS] });
|
|
489
|
+
}
|
|
490
|
+
approve(id, minutes = 0) {
|
|
491
|
+
return this.change(id, { approved: this.now() }, minutes);
|
|
492
|
+
}
|
|
493
|
+
revise(id, note, minutes = 0) {
|
|
494
|
+
return this.items().then((items) => {
|
|
495
|
+
const item = items.find((one) => one.id === id);
|
|
496
|
+
const checks = [...item?.checks ?? [], { text: String(note).slice(0, 200), ok: false }];
|
|
497
|
+
return this.change(id, { stage: "making", approved: undefined, checks }, minutes);
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
published(id, links, minutes = 0) {
|
|
501
|
+
const now = this.now();
|
|
502
|
+
return this.items().then((items) => {
|
|
503
|
+
const kept = items.find((one) => one.id === id)?.links ?? [];
|
|
504
|
+
const added = (Array.isArray(links) ? links : []).map((one) => ({ ...one, at: now }));
|
|
505
|
+
const all = [...kept.filter((one) => !added.some((it) => it.platform === one.platform)), ...added];
|
|
506
|
+
return this.change(id, { stage: "published", links: all }, minutes);
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
week(week, platforms) {
|
|
510
|
+
return this.serial(async () => {
|
|
511
|
+
const weeks = CreatorUtil.setWeek(await this.weeks(), week, platforms);
|
|
512
|
+
await this.host.setExtensionData(NAME, Keys.WEEKS, weeks);
|
|
513
|
+
return weeks;
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
change(id, patch, minutes = 0) {
|
|
517
|
+
return this.serial(async () => {
|
|
518
|
+
const now = this.now();
|
|
519
|
+
const items = CreatorUtil.change(await this.items(), id, patch, now);
|
|
520
|
+
await this.host.setExtensionData(NAME, Keys.ITEMS, items);
|
|
521
|
+
if (minutes > 0) {
|
|
522
|
+
await this.host.setExtensionData(NAME, Keys.WEEKS, CreatorUtil.addMinutes(await this.weeks(), Math.min(minutes, 120), now));
|
|
523
|
+
}
|
|
524
|
+
return items.find((one) => one.id === id);
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
syncTasks() {
|
|
528
|
+
return this.serial(async () => {
|
|
529
|
+
const settings = await this.settings();
|
|
530
|
+
const on = settings.picked.length > 0;
|
|
531
|
+
const made = await this.data(Keys.TASKS) ?? {};
|
|
532
|
+
const tasks = await this.host.callPackageHost(CRON, "list");
|
|
533
|
+
const next = { ...made };
|
|
534
|
+
for (const id of CreatorTasks.IDS) {
|
|
535
|
+
const record = made[id];
|
|
536
|
+
if (on && !record) {
|
|
537
|
+
const added = await this.host.callPackageHost(CRON, "add", [CreatorTasks.of(id)]);
|
|
538
|
+
next[id] = { id: added.id };
|
|
539
|
+
} else if (record && "id" in record && !tasks.some((task) => task.id === record.id)) {
|
|
540
|
+
next[id] = { removed: true };
|
|
541
|
+
}
|
|
542
|
+
if (!on && record) {
|
|
543
|
+
if ("id" in record && tasks.some((task) => task.id === record.id)) {
|
|
544
|
+
await this.host.callPackageHost(CRON, "remove", [record.id]).catch(() => {
|
|
545
|
+
return;
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
delete next[id];
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
if (JSON.stringify(next) !== JSON.stringify(made)) {
|
|
552
|
+
await this.host.setExtensionData(NAME, Keys.TASKS, next);
|
|
553
|
+
}
|
|
554
|
+
}).catch(() => {
|
|
555
|
+
return;
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
items() {
|
|
559
|
+
return this.data(Keys.ITEMS).then(CreatorUtil.items);
|
|
560
|
+
}
|
|
561
|
+
weeks() {
|
|
562
|
+
return this.data(Keys.WEEKS).then(CreatorUtil.weeks);
|
|
563
|
+
}
|
|
564
|
+
id() {
|
|
565
|
+
return `c${this.now().toString(36)}${(++this.count).toString(36)}${Math.random().toString(36).slice(2, 6)}`;
|
|
566
|
+
}
|
|
567
|
+
serial(work) {
|
|
568
|
+
const run = this.queue.then(work, work);
|
|
569
|
+
this.queue = run.catch(() => {
|
|
570
|
+
return;
|
|
571
|
+
});
|
|
572
|
+
return run;
|
|
573
|
+
}
|
|
574
|
+
data(key) {
|
|
575
|
+
return this.host.getExtensionData(NAME, key).catch(() => {
|
|
576
|
+
return;
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
async function activate(host) {
|
|
581
|
+
const creator = new CreatorHost(host);
|
|
582
|
+
await creator.begin();
|
|
583
|
+
return creator;
|
|
584
|
+
}
|
|
585
|
+
export {
|
|
586
|
+
activate as default,
|
|
587
|
+
CreatorTasks,
|
|
588
|
+
CreatorHost
|
|
589
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-creator",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "4.32.0",
|
|
4
|
+
"description": "A pi package for Ta: a channel of content without showing your face, hot topics of your field found three times a day, videos and posts made for each platform, reviewed on your phone and filled in for you up to Publish",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package",
|
|
7
|
+
"ta-industry"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/cellbang/ta",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/cellbang/ta/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/cellbang/cell.git"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"files": [
|
|
19
|
+
"web",
|
|
20
|
+
"host",
|
|
21
|
+
"bin",
|
|
22
|
+
"skills",
|
|
23
|
+
"!**/*.map"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc -b && bun build web-src/index.tsx --format esm --target browser --outfile web/index.js && bun build web-src/host.ts --format esm --target node --outfile host/index.mjs && bun build web-src/render.ts --format esm --target node --outfile bin/render.mjs",
|
|
27
|
+
"clean": "rm -rf lib web host bin *.tsbuildinfo",
|
|
28
|
+
"test": "bun test ./lib",
|
|
29
|
+
"watch": "tsc -b -w --preserveWatchOutput"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@celljs/ta-protocol": "4.32.0",
|
|
33
|
+
"@celljs/ta-web": "4.32.0",
|
|
34
|
+
"@types/react": "^19.3.0"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"pi": {
|
|
40
|
+
"title": {
|
|
41
|
+
"en": "Creator",
|
|
42
|
+
"zh-CN": "创作者",
|
|
43
|
+
"zh-TW": "創作者",
|
|
44
|
+
"ja-JP": "クリエイター"
|
|
45
|
+
},
|
|
46
|
+
"summary": {
|
|
47
|
+
"en": "Run a channel without showing your face: hot topics of your field three times a day, videos and posts made for each platform you pick, reviewed on your phone, filled in for you up to Publish, and a review of the numbers each Monday.",
|
|
48
|
+
"zh-CN": "不出镜也能做内容号:每天三次找你所在领域的热点选题,按你选的平台各做一版视频或图文,手机上一张卡审稿,替你填到发布按钮前,每周一复盘数据。",
|
|
49
|
+
"zh-TW": "不出鏡也能做內容號:每天三次找你所在領域的熱點選題,按你選的平台各做一版影片或圖文,手機上一張卡審稿,替你填到發佈按鈕前,每週一複盤數據。",
|
|
50
|
+
"ja-JP": "顔出しなしでチャンネル運営:分野の話題を1日3回探し、選んだプラットフォームごとに動画や投稿を作り、スマホのカードで確認、投稿ボタンの手前まで入力、毎週月曜にデータを振り返ります。"
|
|
51
|
+
},
|
|
52
|
+
"icon": "Film",
|
|
53
|
+
"web": [
|
|
54
|
+
"./web/index.js"
|
|
55
|
+
],
|
|
56
|
+
"host": "./host/index.mjs",
|
|
57
|
+
"skills": [
|
|
58
|
+
"./skills"
|
|
59
|
+
],
|
|
60
|
+
"offByDefault": true,
|
|
61
|
+
"permissions": {
|
|
62
|
+
"host": {
|
|
63
|
+
"*": "task.manage"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|