@celljs/ta-cron 4.9.1 → 4.11.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 +6 -4
- package/README.md +6 -4
- package/extension/index.mjs +416 -44
- package/host/index.mjs +30 -3
- package/package.json +14 -3
- package/web/index.js +1346 -415
package/host/index.mjs
CHANGED
|
@@ -16,6 +16,8 @@ var Limits;
|
|
|
16
16
|
Limits.SUMMARY_MAX = 4000;
|
|
17
17
|
Limits.MIN_INTERVAL_MS = 60000;
|
|
18
18
|
Limits.RUN_TIMEOUT_MS = 30 * 60000;
|
|
19
|
+
Limits.RUN_TIMEOUT_MIN_MS = 5 * 60000;
|
|
20
|
+
Limits.RUN_TIMEOUT_MAX_MS = 4 * 60 * 60000;
|
|
19
21
|
Limits.GRACE_MS = 5 * 60000;
|
|
20
22
|
Limits.PARALLEL_RUNS = 3;
|
|
21
23
|
})(Limits ||= {});
|
|
@@ -508,7 +510,10 @@ var TaskUtil;
|
|
|
508
510
|
if (input.notify !== undefined) {
|
|
509
511
|
task.notify = checkNotify(input.notify);
|
|
510
512
|
}
|
|
511
|
-
|
|
513
|
+
if (input.timeout !== undefined) {
|
|
514
|
+
task.timeout = checkTimeout(input.timeout);
|
|
515
|
+
}
|
|
516
|
+
for (const key of ["model", "thinking", "notify", "timeout"]) {
|
|
512
517
|
if (task[key] === undefined) {
|
|
513
518
|
delete task[key];
|
|
514
519
|
}
|
|
@@ -547,6 +552,21 @@ var TaskUtil;
|
|
|
547
552
|
}
|
|
548
553
|
return level || undefined;
|
|
549
554
|
}
|
|
555
|
+
function timeoutMs(task, fallback) {
|
|
556
|
+
return task.timeout && Duration.parse(task.timeout) || fallback;
|
|
557
|
+
}
|
|
558
|
+
TaskUtil.timeoutMs = timeoutMs;
|
|
559
|
+
function checkTimeout(value) {
|
|
560
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
561
|
+
if (!text) {
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
const ms = Duration.parse(text);
|
|
565
|
+
if (ms === undefined || ms < Limits.RUN_TIMEOUT_MIN_MS || ms > Limits.RUN_TIMEOUT_MAX_MS) {
|
|
566
|
+
throw new Error(`A timeout is a duration from 5m to 4h, as 90m or 2h; not ${JSON.stringify(text)}.`);
|
|
567
|
+
}
|
|
568
|
+
return Duration.format(ms);
|
|
569
|
+
}
|
|
550
570
|
function checkNotify(value) {
|
|
551
571
|
if (value === "" || value === null) {
|
|
552
572
|
return;
|
|
@@ -556,6 +576,12 @@ var TaskUtil;
|
|
|
556
576
|
}
|
|
557
577
|
return value;
|
|
558
578
|
}
|
|
579
|
+
function firstLine(text) {
|
|
580
|
+
const line = text.split(`
|
|
581
|
+
`).find((candidate) => candidate.trim()) ?? "";
|
|
582
|
+
return line.replace(/^\s*(?:#{1,6}\s+|[-*+]\s+|>\s*|\d+[.)]\s+)/, "").replace(/\*\*|__|`/g, "").replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").trim();
|
|
583
|
+
}
|
|
584
|
+
TaskUtil.firstLine = firstLine;
|
|
559
585
|
function missed(task, now) {
|
|
560
586
|
return task.schedule.kind === "once" && !!task.nextRunAt && now.getTime() - new Date(task.nextRunAt).getTime() > Limits.GRACE_MS;
|
|
561
587
|
}
|
|
@@ -757,11 +783,12 @@ class CronScheduler {
|
|
|
757
783
|
if (!state.isStreaming && state.pendingMessageCount === 0 && state.messageCount > before) {
|
|
758
784
|
return;
|
|
759
785
|
}
|
|
760
|
-
|
|
786
|
+
const timeoutMs = TaskUtil.timeoutMs(active.task, this.options.timeoutMs);
|
|
787
|
+
if (Date.now() - start > timeoutMs) {
|
|
761
788
|
await this.host.abort(sessionId).catch(() => {
|
|
762
789
|
return;
|
|
763
790
|
});
|
|
764
|
-
throw new TimeoutError(`The run took longer than ${Math.round(
|
|
791
|
+
throw new TimeoutError(`The run took longer than ${Math.round(timeoutMs / 60000)} minutes and was stopped.`);
|
|
765
792
|
}
|
|
766
793
|
await new Promise((resolve) => setTimeout(resolve, this.options.pollMs));
|
|
767
794
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-cron",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.11.0",
|
|
4
4
|
"description": "A pi package for Ta: prompts that run on a schedule, once, every so often or by a cron expression, each run in a conversation of its own in the Ta service",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@celljs/ta-protocol": "4.
|
|
31
|
-
"@celljs/ta-web": "4.
|
|
30
|
+
"@celljs/ta-protocol": "4.11.0",
|
|
31
|
+
"@celljs/ta-web": "4.11.0",
|
|
32
32
|
"@types/react": "^19.3.0"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
@@ -43,6 +43,17 @@
|
|
|
43
43
|
"en": "Has Ta do things on time: reminders, regular checks, a daily summary (/loop, /remind).",
|
|
44
44
|
"zh-CN": "让 Ta 按时做事:到点提醒、定期检查、每天汇总(/loop、/remind)。"
|
|
45
45
|
},
|
|
46
|
+
"descriptions": {
|
|
47
|
+
"loop": {
|
|
48
|
+
"zh-CN": "按计划反复运行一段提示:/loop 30m <提示>、/loop @daily <提示>、/loop \"0 9 * * 1-5\" <提示>"
|
|
49
|
+
},
|
|
50
|
+
"remind": {
|
|
51
|
+
"zh-CN": "到点运行一次提示:/remind in 45m <提示>、/remind at 15:30 <提示>"
|
|
52
|
+
},
|
|
53
|
+
"schedule": {
|
|
54
|
+
"zh-CN": "管理定时任务:list 列出、show 查看、run 立即运行、enable 启用、disable 停用、set 修改、remove 删除、clear 清空、help 帮助"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
46
57
|
"icon": "AlarmClock",
|
|
47
58
|
"web": [
|
|
48
59
|
"./web/index.js"
|