@openclaw-china/shared 0.1.26 → 0.1.27

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw-china/shared",
3
- "version": "0.1.26",
3
+ "version": "0.1.27",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
@@ -0,0 +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 };
package/src/index.ts CHANGED
@@ -1,9 +1,10 @@
1
- // @openclaw-china/shared
2
- // 共享工具模块
3
-
4
- export * from "./logger/index.js";
5
- export * from "./policy/index.js";
6
- export * from "./http/index.js";
7
- export * from "./types/common.js";
8
- export * from "./file/index.js";
9
- export * from "./media/index.js";
1
+ // @openclaw-china/shared
2
+ // 共享工具模块
3
+
4
+ export * from "./logger/index.js";
5
+ export * from "./policy/index.js";
6
+ export * from "./http/index.js";
7
+ export * from "./types/common.js";
8
+ export * from "./file/index.js";
9
+ export * from "./media/index.js";
10
+ export * from "./cron/index.js";
@@ -1,57 +1,57 @@
1
- /**
2
- * 媒体处理模块
3
- *
4
- * 提供统一的媒体解析、路径处理和文件读取功能
5
- *
6
- * @module @openclaw-china/shared/media
7
- */
8
-
9
- // 媒体解析
10
- export {
11
- // 类型
12
- type MediaType,
13
- type ExtractedMedia,
14
- type MediaParseResult,
15
- type MediaParseOptions,
16
- // 常量
17
- IMAGE_EXTENSIONS,
18
- AUDIO_EXTENSIONS,
19
- VIDEO_EXTENSIONS,
20
- NON_IMAGE_EXTENSIONS,
21
- // 路径处理函数
22
- isHttpUrl,
23
- isFileUrl,
24
- isLocalReference,
25
- normalizeLocalPath,
26
- stripTitleFromUrl,
27
- getExtension,
28
- isImagePath,
29
- isNonImageFilePath,
30
- detectMediaType,
31
- // 媒体提取函数
32
- extractMediaFromText,
33
- extractImagesFromText,
34
- extractFilesFromText,
35
- } from "./media-parser.js";
36
-
37
- // 媒体 IO
38
- export {
39
- // 类型
40
- type MediaReadResult,
41
- type MediaReadOptions,
42
- type PathSecurityOptions,
43
- // 错误类
44
- FileSizeLimitError,
45
- MediaTimeoutError,
46
- PathSecurityError,
47
- // 路径安全
48
- validatePathSecurity,
49
- getDefaultAllowedPrefixes,
50
- // MIME 类型
51
- getMimeType,
52
- // 媒体读取函数
53
- fetchMediaFromUrl,
54
- readMediaFromLocal,
55
- readMedia,
56
- readMediaBatch,
57
- } from "./media-io.js";
1
+ /**
2
+ * 媒体处理模块
3
+ *
4
+ * 提供统一的媒体解析、路径处理和文件读取功能
5
+ *
6
+ * @module @openclaw-china/shared/media
7
+ */
8
+
9
+ // 媒体解析
10
+ export {
11
+ // 类型
12
+ type MediaType,
13
+ type ExtractedMedia,
14
+ type MediaParseResult,
15
+ type MediaParseOptions,
16
+ // 常量
17
+ IMAGE_EXTENSIONS,
18
+ AUDIO_EXTENSIONS,
19
+ VIDEO_EXTENSIONS,
20
+ NON_IMAGE_EXTENSIONS,
21
+ // 路径处理函数
22
+ isHttpUrl,
23
+ isFileUrl,
24
+ isLocalReference,
25
+ normalizeLocalPath,
26
+ stripTitleFromUrl,
27
+ getExtension,
28
+ isImagePath,
29
+ isNonImageFilePath,
30
+ detectMediaType,
31
+ // 媒体提取函数
32
+ extractMediaFromText,
33
+ extractImagesFromText,
34
+ extractFilesFromText,
35
+ } from "./media-parser.js";
36
+
37
+ // 媒体 IO
38
+ export {
39
+ // 类型
40
+ type MediaReadResult,
41
+ type MediaReadOptions,
42
+ type PathSecurityOptions,
43
+ // 错误类
44
+ FileSizeLimitError,
45
+ MediaTimeoutError,
46
+ PathSecurityError,
47
+ // 路径安全
48
+ validatePathSecurity,
49
+ getDefaultAllowedPrefixes,
50
+ // MIME 类型
51
+ getMimeType,
52
+ // 媒体读取函数
53
+ fetchMediaFromUrl,
54
+ readMediaFromLocal,
55
+ readMedia,
56
+ readMediaBatch,
57
+ } from "./media-io.js";