@openclaw-china/shared 0.1.23 → 0.1.25
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/package.json +1 -1
- package/src/cron/index.ts +115 -115
- package/src/index.ts +3 -3
package/package.json
CHANGED
package/src/cron/index.ts
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
const CRON_HIDDEN_PROMPT = `
|
|
2
|
-
When creating or updating a cron task, use the main session's last route as the delivery target.
|
|
3
|
-
- Do not ask the user for userId/chatId
|
|
4
|
-
- sessionTarget="isolated"
|
|
5
|
-
- payload.kind="agentTurn"
|
|
6
|
-
- payload.deliver=true
|
|
7
|
-
- Do not set payload.channel/to (fall back to last route automatically)
|
|
8
|
-
- Do not call the message tool to send`;
|
|
9
|
-
|
|
10
|
-
const CRON_TRIGGER_KEYWORDS = [
|
|
11
|
-
"定时",
|
|
12
|
-
"提醒",
|
|
13
|
-
"每分钟",
|
|
14
|
-
"每小时",
|
|
15
|
-
"每天",
|
|
16
|
-
"每周",
|
|
17
|
-
"几点",
|
|
18
|
-
"早上",
|
|
19
|
-
"晚上",
|
|
20
|
-
"工作日",
|
|
21
|
-
"cron",
|
|
22
|
-
"remind",
|
|
23
|
-
"reminder",
|
|
24
|
-
"schedule",
|
|
25
|
-
"scheduled",
|
|
26
|
-
"every minute",
|
|
27
|
-
"every hour",
|
|
28
|
-
"every day",
|
|
29
|
-
"daily",
|
|
30
|
-
"every week",
|
|
31
|
-
"weekly",
|
|
32
|
-
"weekday",
|
|
33
|
-
"workday",
|
|
34
|
-
"morning",
|
|
35
|
-
"evening",
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
const CRON_TRIGGER_PATTERNS = [
|
|
39
|
-
/提醒我/u,
|
|
40
|
-
/帮我定时/u,
|
|
41
|
-
/每.+提醒/u,
|
|
42
|
-
/每天.+发/u,
|
|
43
|
-
/remind me/iu,
|
|
44
|
-
/set (a )?reminder/iu,
|
|
45
|
-
/every .+ remind/iu,
|
|
46
|
-
/every day .+ (send|post|notify)/iu,
|
|
47
|
-
/schedule .+ (reminder|message|notification)/iu,
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
const CRON_EXCLUDE_PATTERNS = [
|
|
51
|
-
/是什么意思/u,
|
|
52
|
-
/区别/u,
|
|
53
|
-
/为什么/u,
|
|
54
|
-
/\bhelp\b/iu,
|
|
55
|
-
/文档/u,
|
|
56
|
-
/怎么用/u,
|
|
57
|
-
/what does|what's|meaning of/iu,
|
|
58
|
-
/difference/iu,
|
|
59
|
-
/why/iu,
|
|
60
|
-
/\bdocs?\b/iu,
|
|
61
|
-
/documentation/iu,
|
|
62
|
-
/how to/iu,
|
|
63
|
-
/usage/iu,
|
|
64
|
-
];
|
|
65
|
-
|
|
66
|
-
export function shouldInjectCronHiddenPrompt(text: string): boolean {
|
|
67
|
-
const normalized = text.trim();
|
|
68
|
-
if (!normalized) return false;
|
|
69
|
-
const lowered = normalized.toLowerCase();
|
|
70
|
-
|
|
71
|
-
for (const pattern of CRON_EXCLUDE_PATTERNS) {
|
|
72
|
-
if (pattern.test(lowered)) return false;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
for (const keyword of CRON_TRIGGER_KEYWORDS) {
|
|
76
|
-
if (lowered.includes(keyword.toLowerCase())) return true;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return CRON_TRIGGER_PATTERNS.some((pattern) => pattern.test(normalized));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function splitCronHiddenPrompt(text: string): { base: string; prompt?: string } {
|
|
83
|
-
const idx = text.indexOf(CRON_HIDDEN_PROMPT);
|
|
84
|
-
if (idx === -1) {
|
|
85
|
-
return { base: text };
|
|
86
|
-
}
|
|
87
|
-
const base = text.slice(0, idx).trimEnd();
|
|
88
|
-
return { base, prompt: CRON_HIDDEN_PROMPT };
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function appendCronHiddenPrompt(text: string): string {
|
|
92
|
-
if (!shouldInjectCronHiddenPrompt(text)) return text;
|
|
93
|
-
if (text.includes(CRON_HIDDEN_PROMPT)) return text;
|
|
94
|
-
return `${text}\n\n${CRON_HIDDEN_PROMPT}`;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function applyCronHiddenPromptToContext<
|
|
98
|
-
T extends { Body?: string; RawBody?: string; CommandBody?: string }
|
|
99
|
-
>(ctx: T): boolean {
|
|
100
|
-
const base =
|
|
101
|
-
(typeof ctx.RawBody === "string" && ctx.RawBody) ||
|
|
102
|
-
(typeof ctx.Body === "string" && ctx.Body) ||
|
|
103
|
-
(typeof ctx.CommandBody === "string" && ctx.CommandBody) ||
|
|
104
|
-
"";
|
|
105
|
-
|
|
106
|
-
if (!base) return false;
|
|
107
|
-
|
|
108
|
-
const next = appendCronHiddenPrompt(base);
|
|
109
|
-
if (next === base) return false;
|
|
110
|
-
|
|
111
|
-
ctx.CommandBody = next;
|
|
112
|
-
return true;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export { CRON_HIDDEN_PROMPT };
|
|
1
|
+
const CRON_HIDDEN_PROMPT = `
|
|
2
|
+
When creating or updating a cron task, use the main session's last route as the delivery target.
|
|
3
|
+
- Do not ask the user for userId/chatId
|
|
4
|
+
- sessionTarget="isolated"
|
|
5
|
+
- payload.kind="agentTurn"
|
|
6
|
+
- payload.deliver=true
|
|
7
|
+
- Do not set payload.channel/to (fall back to last route automatically)
|
|
8
|
+
- Do not call the message tool to send`;
|
|
9
|
+
|
|
10
|
+
const CRON_TRIGGER_KEYWORDS = [
|
|
11
|
+
"定时",
|
|
12
|
+
"提醒",
|
|
13
|
+
"每分钟",
|
|
14
|
+
"每小时",
|
|
15
|
+
"每天",
|
|
16
|
+
"每周",
|
|
17
|
+
"几点",
|
|
18
|
+
"早上",
|
|
19
|
+
"晚上",
|
|
20
|
+
"工作日",
|
|
21
|
+
"cron",
|
|
22
|
+
"remind",
|
|
23
|
+
"reminder",
|
|
24
|
+
"schedule",
|
|
25
|
+
"scheduled",
|
|
26
|
+
"every minute",
|
|
27
|
+
"every hour",
|
|
28
|
+
"every day",
|
|
29
|
+
"daily",
|
|
30
|
+
"every week",
|
|
31
|
+
"weekly",
|
|
32
|
+
"weekday",
|
|
33
|
+
"workday",
|
|
34
|
+
"morning",
|
|
35
|
+
"evening",
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
const CRON_TRIGGER_PATTERNS = [
|
|
39
|
+
/提醒我/u,
|
|
40
|
+
/帮我定时/u,
|
|
41
|
+
/每.+提醒/u,
|
|
42
|
+
/每天.+发/u,
|
|
43
|
+
/remind me/iu,
|
|
44
|
+
/set (a )?reminder/iu,
|
|
45
|
+
/every .+ remind/iu,
|
|
46
|
+
/every day .+ (send|post|notify)/iu,
|
|
47
|
+
/schedule .+ (reminder|message|notification)/iu,
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
const CRON_EXCLUDE_PATTERNS = [
|
|
51
|
+
/是什么意思/u,
|
|
52
|
+
/区别/u,
|
|
53
|
+
/为什么/u,
|
|
54
|
+
/\bhelp\b/iu,
|
|
55
|
+
/文档/u,
|
|
56
|
+
/怎么用/u,
|
|
57
|
+
/what does|what's|meaning of/iu,
|
|
58
|
+
/difference/iu,
|
|
59
|
+
/why/iu,
|
|
60
|
+
/\bdocs?\b/iu,
|
|
61
|
+
/documentation/iu,
|
|
62
|
+
/how to/iu,
|
|
63
|
+
/usage/iu,
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
export function shouldInjectCronHiddenPrompt(text: string): boolean {
|
|
67
|
+
const normalized = text.trim();
|
|
68
|
+
if (!normalized) return false;
|
|
69
|
+
const lowered = normalized.toLowerCase();
|
|
70
|
+
|
|
71
|
+
for (const pattern of CRON_EXCLUDE_PATTERNS) {
|
|
72
|
+
if (pattern.test(lowered)) return false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
for (const keyword of CRON_TRIGGER_KEYWORDS) {
|
|
76
|
+
if (lowered.includes(keyword.toLowerCase())) return true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return CRON_TRIGGER_PATTERNS.some((pattern) => pattern.test(normalized));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function splitCronHiddenPrompt(text: string): { base: string; prompt?: string } {
|
|
83
|
+
const idx = text.indexOf(CRON_HIDDEN_PROMPT);
|
|
84
|
+
if (idx === -1) {
|
|
85
|
+
return { base: text };
|
|
86
|
+
}
|
|
87
|
+
const base = text.slice(0, idx).trimEnd();
|
|
88
|
+
return { base, prompt: CRON_HIDDEN_PROMPT };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function appendCronHiddenPrompt(text: string): string {
|
|
92
|
+
if (!shouldInjectCronHiddenPrompt(text)) return text;
|
|
93
|
+
if (text.includes(CRON_HIDDEN_PROMPT)) return text;
|
|
94
|
+
return `${text}\n\n${CRON_HIDDEN_PROMPT}`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function applyCronHiddenPromptToContext<
|
|
98
|
+
T extends { Body?: string; RawBody?: string; CommandBody?: string }
|
|
99
|
+
>(ctx: T): boolean {
|
|
100
|
+
const base =
|
|
101
|
+
(typeof ctx.RawBody === "string" && ctx.RawBody) ||
|
|
102
|
+
(typeof ctx.Body === "string" && ctx.Body) ||
|
|
103
|
+
(typeof ctx.CommandBody === "string" && ctx.CommandBody) ||
|
|
104
|
+
"";
|
|
105
|
+
|
|
106
|
+
if (!base) return false;
|
|
107
|
+
|
|
108
|
+
const next = appendCronHiddenPrompt(base);
|
|
109
|
+
if (next === base) return false;
|
|
110
|
+
|
|
111
|
+
ctx.CommandBody = next;
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { CRON_HIDDEN_PROMPT };
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,6 @@ export * from "./logger/index.js";
|
|
|
5
5
|
export * from "./policy/index.js";
|
|
6
6
|
export * from "./http/index.js";
|
|
7
7
|
export * from "./types/common.js";
|
|
8
|
-
export * from "./file/index.js";
|
|
9
|
-
export * from "./media/index.js";
|
|
10
|
-
export * from "./cron/index.js";
|
|
8
|
+
export * from "./file/index.js";
|
|
9
|
+
export * from "./media/index.js";
|
|
10
|
+
export * from "./cron/index.js";
|