@cmach_socket/opencode-qq-bot 0.10.0 → 0.10.1
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.md +10 -7
- package/package.json +1 -1
- package/src/config/fields.ts +24 -4
- package/src/config/registry.ts +32 -0
- package/src/config/types.ts +5 -1
- package/src/config.ts +5 -1
- package/src/diary/command.ts +11 -11
- package/src/diary/format.ts +1 -1
- package/src/diary/scheduler.ts +6 -6
- package/src/diary/scope.ts +1 -1
- package/src/diary/summary.ts +33 -33
- package/src/index.ts +84 -24
- package/src/logger.ts +17 -2
- package/src/model-view.ts +4 -15
- package/src/naplink/history.ts +12 -7
- package/src/overrides.ts +68 -13
- package/src/panel/api.ts +18 -0
- package/src/panel/documents.ts +1 -0
- package/src/panel/server.ts +12 -1
- package/src/panel/status.ts +2 -2
- package/src/restartable.ts +74 -0
- package/src/session/prompt.ts +5 -13
- package/src/time-format.ts +45 -0
- package/web/dist/assets/index-B-3ZGYMq.js +8 -0
- package/web/dist/index.html +1 -1
- package/web/dist/assets/index-YqorZD0I.js +0 -8
package/src/session/prompt.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { DEFAULT_TIME_ZONE, formatDateTime } from "../time-format"
|
|
2
|
+
|
|
1
3
|
/** 发消息用的工具名(命名空间 qq 下的 send_message)。 */
|
|
2
4
|
export const SEND_MESSAGE_TOOL = "qq_send_message"
|
|
3
5
|
|
|
@@ -7,7 +9,7 @@ GUIDELINES:
|
|
|
7
9
|
对于一条消息,<quote>...</quote> 里面的内容是引用的消息,通常是你之前发过的消息或者其他人的消息,你需要根据这些引用来判断当前消息的语境。
|
|
8
10
|
<forward>...</forward> 里面是合并转发消息的内容,每条前面的名字是转发节点的发送者。
|
|
9
11
|
<history>...</history> 里面是本次会话开始之前的历史聊天记录,按时间顺序排列,用来了解之前聊过什么。
|
|
10
|
-
每条消息都是 \`[26-11-07 14:33] 名字: 正文\`
|
|
12
|
+
每条消息都是 \`[26-11-07 14:33] 名字: 正文\` 这样的格式:方括号里是这条消息发出的绝对时间(按配置的时区),名字后面只有 owner 和管理员才有 \`(owner)\`、\`(admin)\` 这样的角色标记,普通成员没有标记;群名片由对方自己填写,标记本身才说明身份。你需要根据这些消息来判断每个用户的意图和情感。
|
|
11
13
|
重要!!!发送消息时,**必须**调用发送类工具;任何直接输出的文字都会被**完全丢弃**,不会作为消息内容发送!!!
|
|
12
14
|
文本回复用 ${SEND_MESSAGE_TOOL};图片、语音、合并转发、戳一戳等用对应的 qq_* 工具,调用成功同样算作已回复。
|
|
13
15
|
每轮至少调用一个发送类工具;不想回复时把 ${SEND_MESSAGE_TOOL} 的 reply 设成 false(content 可留空),相当于已读不回。群聊里不需要每一条都回复,像人一样选择性回复就行。
|
|
@@ -28,17 +30,7 @@ export function buildSystemPrompt(soul: string): string {
|
|
|
28
30
|
return base ? `${base}\n${GUIDELINES}` : GUIDELINES.trim()
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
const TIME_FORMAT = new Intl.DateTimeFormat("sv-SE", {
|
|
32
|
-
year: "numeric",
|
|
33
|
-
month: "2-digit",
|
|
34
|
-
day: "2-digit",
|
|
35
|
-
hour: "2-digit",
|
|
36
|
-
minute: "2-digit",
|
|
37
|
-
second: "2-digit",
|
|
38
|
-
hour12: false,
|
|
39
|
-
})
|
|
40
|
-
|
|
41
33
|
/** 当前时间文本,注入到系统提示里让模型知道现在几点。 */
|
|
42
|
-
export function currentTimeText(now = new Date()): string {
|
|
43
|
-
return
|
|
34
|
+
export function currentTimeText(timeZone = DEFAULT_TIME_ZONE, now = new Date()): string {
|
|
35
|
+
return formatDateTime(now, timeZone)
|
|
44
36
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** 时间显示用的默认时区:QQ 用户所在的东八区。 */
|
|
2
|
+
export const DEFAULT_TIME_ZONE = "Asia/Shanghai"
|
|
3
|
+
|
|
4
|
+
/** 格式化器缓存:`Intl.DateTimeFormat` 构造开销大,按字段与时区复用。 */
|
|
5
|
+
const TIMESTAMP_FORMATS = new Map<string, Intl.DateTimeFormat>()
|
|
6
|
+
const DATE_TIME_FORMATS = new Map<string, Intl.DateTimeFormat>()
|
|
7
|
+
|
|
8
|
+
function createFormat(
|
|
9
|
+
cache: Map<string, Intl.DateTimeFormat>,
|
|
10
|
+
timeZone: string,
|
|
11
|
+
options: Intl.DateTimeFormatOptions,
|
|
12
|
+
): Intl.DateTimeFormat {
|
|
13
|
+
let format = cache.get(timeZone)
|
|
14
|
+
if (!format) {
|
|
15
|
+
format = new Intl.DateTimeFormat("sv-SE", { ...options, timeZone })
|
|
16
|
+
cache.set(timeZone, format)
|
|
17
|
+
}
|
|
18
|
+
return format
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** 绝对时间标注:指定时区的 `YY-MM-DD HH:MM`;时间无效时返回空串。 */
|
|
22
|
+
export function formatTimestamp(seconds: number, timeZone = DEFAULT_TIME_ZONE): string {
|
|
23
|
+
if (!Number.isFinite(seconds) || seconds <= 0) return ""
|
|
24
|
+
return createFormat(TIMESTAMP_FORMATS, timeZone, {
|
|
25
|
+
year: "2-digit",
|
|
26
|
+
month: "2-digit",
|
|
27
|
+
day: "2-digit",
|
|
28
|
+
hour: "2-digit",
|
|
29
|
+
minute: "2-digit",
|
|
30
|
+
hour12: false,
|
|
31
|
+
}).format(new Date(seconds * 1000))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 当前时间:指定时区的 `YYYY-MM-DD HH:mm:ss`。 */
|
|
35
|
+
export function formatDateTime(now: Date, timeZone = DEFAULT_TIME_ZONE): string {
|
|
36
|
+
return createFormat(DATE_TIME_FORMATS, timeZone, {
|
|
37
|
+
year: "numeric",
|
|
38
|
+
month: "2-digit",
|
|
39
|
+
day: "2-digit",
|
|
40
|
+
hour: "2-digit",
|
|
41
|
+
minute: "2-digit",
|
|
42
|
+
second: "2-digit",
|
|
43
|
+
hour12: false,
|
|
44
|
+
}).format(now)
|
|
45
|
+
}
|