luckytri 1.0.0 → 1.0.2
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/.github/SECURITY.md +4 -4
- package/README.en.md +252 -250
- package/README.md +252 -250
- package/bin/luckytri.js +5 -1
- package/docs/en/CHANGELOG.md +8 -0
- package/docs/en/connect.md +18 -18
- package/docs/en/guide.md +202 -216
- package/docs/en/npm-release.md +25 -25
- package/docs/zh/CHANGELOG.md +8 -0
- package/docs/zh/connect.md +17 -17
- package/docs/zh/guide.md +202 -216
- package/docs/zh/npm-release.md +33 -33
- package/package.json +110 -108
- package/plugins/sdk/index.d.ts +155 -155
- package/plugins/sdk/testing.js +58 -58
- package/plugins/weather/index.js +82 -82
- package/plugins/weather/luckytri-plugin.json +29 -29
- package/public/app/assets/ChatsPage-BhlJHseG.js +3 -0
- package/public/app/assets/Empty-DP6WMGHi.js +2 -0
- package/public/app/assets/Field-CtbdqaiB.js +1 -0
- package/public/app/assets/HeartPage-32BeTPn2.js +1 -0
- package/public/app/assets/LifePage-CxSm0XKI.js +1 -0
- package/public/app/assets/MemoryPage-BeKBcPCY.js +1 -0
- package/public/app/assets/NaturePage-NEPYl2HS.js +3 -0
- package/public/app/assets/PeoplePage-DxtpekwM.js +1 -0
- package/public/app/assets/PluginsPage-CVVQwEBI.css +1 -0
- package/public/app/assets/PluginsPage-DksEZbUU.js +2 -0
- package/public/app/assets/{SystemPage-CAMPoYqM.css → SystemPage-BkRu0Rvx.css} +1 -1
- package/public/app/assets/SystemPage-BvzJlHuY.js +1 -0
- package/public/app/assets/TimePage-7-awH5XL.js +3 -0
- package/public/app/assets/index-4rItIkD-.js +4 -0
- package/public/app/assets/{index-YDz1ree1.css → index-DY4e15Kh.css} +1 -1
- package/public/app/assets/{knowledge-DG0e0uKw.js → knowledge-C6_HvoyB.js} +1 -1
- package/public/app/assets/media-SMfTT-yc.js +1 -0
- package/public/app/index.html +3 -3
- package/public/guide.en.html +72 -99
- package/public/guide.html +44 -86
- package/public/tutorial.en.md +25 -39
- package/public/tutorial.md +25 -39
- package/scripts/backup.js +311 -311
- package/scripts/browser.js +41 -41
- package/scripts/import-data.js +128 -0
- package/scripts/launch.js +101 -94
- package/scripts/plugin.js +150 -150
- package/scripts/reset-password.js +22 -0
- package/scripts/runtime.js +25 -25
- package/scripts/service.js +56 -47
- package/scripts/setup.js +50 -50
- package/scripts/start-server.js +41 -41
- package/scripts/stop.js +36 -36
- package/server/app.js +112 -96
- package/server/auth.js +217 -0
- package/server/channels/contract.js +57 -57
- package/server/channels/hub.js +165 -165
- package/server/channels/index.js +28 -25
- package/server/channels/onebot/index.js +335 -336
- package/server/channels/onebot/token.js +22 -3
- package/server/core/capabilities.js +208 -208
- package/server/core/events.js +64 -60
- package/server/core/image-preprocessor.js +208 -208
- package/server/core/model-manager.js +1213 -1213
- package/server/core/net-guard.js +49 -49
- package/server/core/orchestrator.js +569 -569
- package/server/core/perceivers.js +91 -91
- package/server/core/persona-manager.js +243 -243
- package/server/core/repository.js +293 -293
- package/server/core/response-validator.js +508 -508
- package/server/core/turn-processor.js +630 -630
- package/server/core/turn.js +236 -236
- package/server/core/vision-manager.js +633 -633
- package/server/i18n/errors.js +548 -497
- package/server/i18n/labels.js +649 -653
- package/server/index.js +151 -102
- package/server/knowledge/manager.js +386 -386
- package/server/knowledge/schema.js +12 -8
- package/server/local-access.js +32 -0
- package/server/mind/anticipations.js +507 -507
- package/server/mind/api.js +703 -703
- package/server/mind/budget.js +152 -152
- package/server/mind/context-selection.js +61 -61
- package/server/mind/day-planner.js +324 -324
- package/server/mind/evidence.js +148 -148
- package/server/mind/index.js +445 -445
- package/server/mind/life/diary.js +786 -786
- package/server/mind/life/index.js +1049 -1049
- package/server/mind/observations.js +84 -84
- package/server/mind/own-day.js +324 -324
- package/server/mind/own-voice.js +318 -318
- package/server/mind/senses.js +53 -53
- package/server/mind/time/activity-clock.js +196 -196
- package/server/mind/time/availability.js +69 -69
- package/server/mind/time/commitment-review.js +198 -198
- package/server/mind/time/executor.js +512 -512
- package/server/mind/time/experiences.js +128 -128
- package/server/mind/time/games.js +562 -562
- package/server/mind/time/index.js +739 -739
- package/server/mind/time/intent.js +166 -166
- package/server/mind/time/kinds.js +171 -171
- package/server/mind/time/plugin-activity.js +207 -207
- package/server/mind/time/tasks.js +587 -587
- package/server/mind/util.js +110 -110
- package/server/mind/view.js +273 -273
- package/server/paths.js +102 -102
- package/server/plugins/api.js +204 -204
- package/server/plugins/host.js +967 -967
- package/server/plugins/install.js +295 -295
- package/server/plugins/manifest.js +201 -201
- package/server/plugins/permissions.js +42 -42
- package/server/plugins/runner/guard.mjs +36 -36
- package/server/plugins/runner/worker.mjs +250 -250
- package/server/plugins/schema.js +91 -91
- package/server/plugins/zip.js +112 -112
- package/server/startup-lock.js +118 -118
- package/server/storage/archive.js +242 -241
- package/server/storage/backup-cleanup-worker.js +8 -8
- package/server/storage/backup-cleanup.js +415 -414
- package/server/storage/backup-lock.js +76 -76
- package/server/storage/backup-scheduler.js +131 -131
- package/server/storage/data-package.js +298 -0
- package/server/storage/data-transfer-api.js +50 -0
- package/server/storage/data-transfer-worker.js +18 -0
- package/server/storage/data-transfer.js +415 -0
- package/server/storage/store.js +202 -199
- package/server/studio/readiness.js +181 -190
- package/server/studio/settings.js +236 -236
- package/public/app/assets/ChatsPage-C-FcRapR.js +0 -3
- package/public/app/assets/Empty-CpP5kQHH.js +0 -2
- package/public/app/assets/Field-D4gY-INU.js +0 -1
- package/public/app/assets/HeartPage-CPy_thQd.js +0 -1
- package/public/app/assets/LifePage-CxWvwmSf.js +0 -1
- package/public/app/assets/MemoryPage-DC4rhQ68.js +0 -1
- package/public/app/assets/NaturePage-IvYw04Zq.js +0 -3
- package/public/app/assets/PeoplePage-Cqefm9-q.js +0 -1
- package/public/app/assets/PluginsPage-DKSaKvXb.js +0 -2
- package/public/app/assets/PluginsPage-HyBe5D8w.css +0 -1
- package/public/app/assets/SystemPage-CJmtJkrK.js +0 -1
- package/public/app/assets/TimePage-Cw44inM4.js +0 -3
- package/public/app/assets/index-BheRW-1t.js +0 -4
- package/public/app/assets/media-BzPDBm7e.js +0 -1
|
@@ -1,166 +1,166 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { parseSessionKey } from "../../channels/session-key.js";
|
|
3
|
-
import { evidence, normalized, parse } from "../util.js";
|
|
4
|
-
|
|
5
|
-
export function gameTopic(title) {
|
|
6
|
-
return (
|
|
7
|
-
String(title).match(
|
|
8
|
-
/Rewrite|ATRI|CLANNAD|Summer Pockets|星露谷物语|原神|崩坏:星穹铁道|Minecraft/i,
|
|
9
|
-
)?.[0] ||
|
|
10
|
-
String(title).match(/[《「]([^》」]{1,60})[》」]/)?.[1] ||
|
|
11
|
-
""
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
function ordinal(value) {
|
|
15
|
-
if (/^\d+$/.test(value)) return String(Number(value));
|
|
16
|
-
const digits = {
|
|
17
|
-
零: 0,
|
|
18
|
-
〇: 0,
|
|
19
|
-
一: 1,
|
|
20
|
-
二: 2,
|
|
21
|
-
两: 2,
|
|
22
|
-
三: 3,
|
|
23
|
-
四: 4,
|
|
24
|
-
五: 5,
|
|
25
|
-
六: 6,
|
|
26
|
-
七: 7,
|
|
27
|
-
八: 8,
|
|
28
|
-
九: 9,
|
|
29
|
-
};
|
|
30
|
-
if (value === "十") return "10";
|
|
31
|
-
if (value.includes("十")) {
|
|
32
|
-
const [a, b] = value.split("十");
|
|
33
|
-
return String((a ? digits[a] : 1) * 10 + (b ? digits[b] : 0));
|
|
34
|
-
}
|
|
35
|
-
return digits[value] === undefined ? value : String(digits[value]);
|
|
36
|
-
}
|
|
37
|
-
export function intentUnit(title) {
|
|
38
|
-
const match = String(title).match(
|
|
39
|
-
/第\s*([\d零〇一二两三四五六七八九十]+)\s*(章|节|幕|篇|关|卷|部)/,
|
|
40
|
-
);
|
|
41
|
-
return match
|
|
42
|
-
? {
|
|
43
|
-
key: ordinal(match[1]) + match[2],
|
|
44
|
-
label: "第" + ordinal(match[1]) + match[2],
|
|
45
|
-
}
|
|
46
|
-
: null;
|
|
47
|
-
}
|
|
48
|
-
export function intentScope(db, session = "") {
|
|
49
|
-
if (!session) return "self";
|
|
50
|
-
try {
|
|
51
|
-
const p = parseSessionKey(session);
|
|
52
|
-
let account = p.accountId;
|
|
53
|
-
if (account === "_") {
|
|
54
|
-
const accounts = db
|
|
55
|
-
.prepare(
|
|
56
|
-
"SELECT DISTINCT account_id FROM core_events WHERE session_id=? AND account_id IS NOT NULL AND account_id!='' AND time<=? LIMIT 2",
|
|
57
|
-
)
|
|
58
|
-
.all(session, Number.MAX_SAFE_INTEGER);
|
|
59
|
-
if (accounts.length === 1) account = String(accounts[0].account_id);
|
|
60
|
-
}
|
|
61
|
-
return `${p.channel}:${account}:${p.kind}:${p.nativeId}`;
|
|
62
|
-
} catch {
|
|
63
|
-
return String(session);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
export function intentRecipient(
|
|
67
|
-
db,
|
|
68
|
-
{ session, subject, title, sources = [], accepted = false },
|
|
69
|
-
) {
|
|
70
|
-
if (subject) return String(subject);
|
|
71
|
-
try {
|
|
72
|
-
const p = parseSessionKey(session);
|
|
73
|
-
if (p.kind === "private") return p.nativeId;
|
|
74
|
-
} catch {}
|
|
75
|
-
if (!accepted && !/汇报|发给|给你|让你看|交付|分享/.test(title)) return "";
|
|
76
|
-
const recipients = new Set();
|
|
77
|
-
for (const ref of evidence(sources).filter((s) => s.startsWith("m:"))) {
|
|
78
|
-
const event = db
|
|
79
|
-
.prepare(
|
|
80
|
-
"SELECT seq,session_id,payload FROM core_events WHERE seq=? AND role='assistant'",
|
|
81
|
-
)
|
|
82
|
-
.get(Number(ref.slice(2)));
|
|
83
|
-
for (const seq of parse(event?.payload, {}).replyTargetIds || []) {
|
|
84
|
-
const m = db
|
|
85
|
-
.prepare(
|
|
86
|
-
"SELECT payload FROM core_events WHERE seq=? AND seq<? AND session_id=? AND role='user' AND seq NOT IN (SELECT seq FROM mind_unlived)",
|
|
87
|
-
)
|
|
88
|
-
.get(Number(seq), event.seq, event.session_id);
|
|
89
|
-
const user = parse(m?.payload, {}).userId;
|
|
90
|
-
if (user) recipients.add(String(user));
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return recipients.size === 1 ? [...recipients][0] : "";
|
|
94
|
-
}
|
|
95
|
-
export function intentMessageSources(db, row, message) {
|
|
96
|
-
const targets = (
|
|
97
|
-
Array.isArray(message.replyTargetIds) ? message.replyTargetIds : []
|
|
98
|
-
).filter((seq) =>
|
|
99
|
-
db
|
|
100
|
-
.prepare(
|
|
101
|
-
"SELECT 1 FROM core_events WHERE seq=? AND seq<? AND session_id=? AND role='user' AND seq NOT IN (SELECT seq FROM mind_unlived) AND COALESCE(json_extract(payload,'$.simulated'),0)=0",
|
|
102
|
-
)
|
|
103
|
-
.get(Number(seq), row.seq, row.session_id),
|
|
104
|
-
);
|
|
105
|
-
return evidence([row.seq, ...targets.map(Number)]);
|
|
106
|
-
}
|
|
107
|
-
export function taskIntent(
|
|
108
|
-
db,
|
|
109
|
-
{
|
|
110
|
-
title = "",
|
|
111
|
-
activity,
|
|
112
|
-
session,
|
|
113
|
-
session_id,
|
|
114
|
-
subject,
|
|
115
|
-
sources = [],
|
|
116
|
-
projectId,
|
|
117
|
-
project_id,
|
|
118
|
-
},
|
|
119
|
-
) {
|
|
120
|
-
session ??= session_id;
|
|
121
|
-
const scope = intentScope(db, session),
|
|
122
|
-
recipient = intentRecipient(db, { session, subject, title, sources }),
|
|
123
|
-
unit = intentUnit(title);
|
|
124
|
-
let topic = "",
|
|
125
|
-
operation = "do";
|
|
126
|
-
if (activity === "game") topic = gameTopic(title);
|
|
127
|
-
else if (
|
|
128
|
-
activity === "write" ||
|
|
129
|
-
activity === "read" ||
|
|
130
|
-
String(activity).includes(".")
|
|
131
|
-
)
|
|
132
|
-
topic = String(title).match(/[《「]([^》」]{1,100})[》」]/)?.[1] || "";
|
|
133
|
-
if (activity === "write") {
|
|
134
|
-
operation = /修改|重写|修订/.test(title)
|
|
135
|
-
? "revise"
|
|
136
|
-
: /续写|接续|下一篇/.test(title)
|
|
137
|
-
? "continue"
|
|
138
|
-
: "write";
|
|
139
|
-
}
|
|
140
|
-
if (/重玩|重新玩|重读|再读一遍|再玩一遍/.test(title)) operation = "repeat";
|
|
141
|
-
const anchored = !!topic,
|
|
142
|
-
key = anchored
|
|
143
|
-
? createHash("sha256")
|
|
144
|
-
.update(
|
|
145
|
-
JSON.stringify([
|
|
146
|
-
scope,
|
|
147
|
-
recipient,
|
|
148
|
-
activity,
|
|
149
|
-
normalized(topic),
|
|
150
|
-
unit?.key || "",
|
|
151
|
-
operation,
|
|
152
|
-
]),
|
|
153
|
-
)
|
|
154
|
-
.digest("hex")
|
|
155
|
-
: null;
|
|
156
|
-
return {
|
|
157
|
-
key,
|
|
158
|
-
anchored,
|
|
159
|
-
scope,
|
|
160
|
-
recipient,
|
|
161
|
-
topic,
|
|
162
|
-
unit,
|
|
163
|
-
operation,
|
|
164
|
-
project: projectId || project_id || null,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { parseSessionKey } from "../../channels/session-key.js";
|
|
3
|
+
import { evidence, normalized, parse } from "../util.js";
|
|
4
|
+
|
|
5
|
+
export function gameTopic(title) {
|
|
6
|
+
return (
|
|
7
|
+
String(title).match(
|
|
8
|
+
/Rewrite|ATRI|CLANNAD|Summer Pockets|星露谷物语|原神|崩坏:星穹铁道|Minecraft/i,
|
|
9
|
+
)?.[0] ||
|
|
10
|
+
String(title).match(/[《「]([^》」]{1,60})[》」]/)?.[1] ||
|
|
11
|
+
""
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
function ordinal(value) {
|
|
15
|
+
if (/^\d+$/.test(value)) return String(Number(value));
|
|
16
|
+
const digits = {
|
|
17
|
+
零: 0,
|
|
18
|
+
〇: 0,
|
|
19
|
+
一: 1,
|
|
20
|
+
二: 2,
|
|
21
|
+
两: 2,
|
|
22
|
+
三: 3,
|
|
23
|
+
四: 4,
|
|
24
|
+
五: 5,
|
|
25
|
+
六: 6,
|
|
26
|
+
七: 7,
|
|
27
|
+
八: 8,
|
|
28
|
+
九: 9,
|
|
29
|
+
};
|
|
30
|
+
if (value === "十") return "10";
|
|
31
|
+
if (value.includes("十")) {
|
|
32
|
+
const [a, b] = value.split("十");
|
|
33
|
+
return String((a ? digits[a] : 1) * 10 + (b ? digits[b] : 0));
|
|
34
|
+
}
|
|
35
|
+
return digits[value] === undefined ? value : String(digits[value]);
|
|
36
|
+
}
|
|
37
|
+
export function intentUnit(title) {
|
|
38
|
+
const match = String(title).match(
|
|
39
|
+
/第\s*([\d零〇一二两三四五六七八九十]+)\s*(章|节|幕|篇|关|卷|部)/,
|
|
40
|
+
);
|
|
41
|
+
return match
|
|
42
|
+
? {
|
|
43
|
+
key: ordinal(match[1]) + match[2],
|
|
44
|
+
label: "第" + ordinal(match[1]) + match[2],
|
|
45
|
+
}
|
|
46
|
+
: null;
|
|
47
|
+
}
|
|
48
|
+
export function intentScope(db, session = "") {
|
|
49
|
+
if (!session) return "self";
|
|
50
|
+
try {
|
|
51
|
+
const p = parseSessionKey(session);
|
|
52
|
+
let account = p.accountId;
|
|
53
|
+
if (account === "_") {
|
|
54
|
+
const accounts = db
|
|
55
|
+
.prepare(
|
|
56
|
+
"SELECT DISTINCT account_id FROM core_events WHERE session_id=? AND account_id IS NOT NULL AND account_id!='' AND time<=? LIMIT 2",
|
|
57
|
+
)
|
|
58
|
+
.all(session, Number.MAX_SAFE_INTEGER);
|
|
59
|
+
if (accounts.length === 1) account = String(accounts[0].account_id);
|
|
60
|
+
}
|
|
61
|
+
return `${p.channel}:${account}:${p.kind}:${p.nativeId}`;
|
|
62
|
+
} catch {
|
|
63
|
+
return String(session);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export function intentRecipient(
|
|
67
|
+
db,
|
|
68
|
+
{ session, subject, title, sources = [], accepted = false },
|
|
69
|
+
) {
|
|
70
|
+
if (subject) return String(subject);
|
|
71
|
+
try {
|
|
72
|
+
const p = parseSessionKey(session);
|
|
73
|
+
if (p.kind === "private") return p.nativeId;
|
|
74
|
+
} catch {}
|
|
75
|
+
if (!accepted && !/汇报|发给|给你|让你看|交付|分享/.test(title)) return "";
|
|
76
|
+
const recipients = new Set();
|
|
77
|
+
for (const ref of evidence(sources).filter((s) => s.startsWith("m:"))) {
|
|
78
|
+
const event = db
|
|
79
|
+
.prepare(
|
|
80
|
+
"SELECT seq,session_id,payload FROM core_events WHERE seq=? AND role='assistant'",
|
|
81
|
+
)
|
|
82
|
+
.get(Number(ref.slice(2)));
|
|
83
|
+
for (const seq of parse(event?.payload, {}).replyTargetIds || []) {
|
|
84
|
+
const m = db
|
|
85
|
+
.prepare(
|
|
86
|
+
"SELECT payload FROM core_events WHERE seq=? AND seq<? AND session_id=? AND role='user' AND seq NOT IN (SELECT seq FROM mind_unlived)",
|
|
87
|
+
)
|
|
88
|
+
.get(Number(seq), event.seq, event.session_id);
|
|
89
|
+
const user = parse(m?.payload, {}).userId;
|
|
90
|
+
if (user) recipients.add(String(user));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return recipients.size === 1 ? [...recipients][0] : "";
|
|
94
|
+
}
|
|
95
|
+
export function intentMessageSources(db, row, message) {
|
|
96
|
+
const targets = (
|
|
97
|
+
Array.isArray(message.replyTargetIds) ? message.replyTargetIds : []
|
|
98
|
+
).filter((seq) =>
|
|
99
|
+
db
|
|
100
|
+
.prepare(
|
|
101
|
+
"SELECT 1 FROM core_events WHERE seq=? AND seq<? AND session_id=? AND role='user' AND seq NOT IN (SELECT seq FROM mind_unlived) AND COALESCE(json_extract(payload,'$.simulated'),0)=0",
|
|
102
|
+
)
|
|
103
|
+
.get(Number(seq), row.seq, row.session_id),
|
|
104
|
+
);
|
|
105
|
+
return evidence([row.seq, ...targets.map(Number)]);
|
|
106
|
+
}
|
|
107
|
+
export function taskIntent(
|
|
108
|
+
db,
|
|
109
|
+
{
|
|
110
|
+
title = "",
|
|
111
|
+
activity,
|
|
112
|
+
session,
|
|
113
|
+
session_id,
|
|
114
|
+
subject,
|
|
115
|
+
sources = [],
|
|
116
|
+
projectId,
|
|
117
|
+
project_id,
|
|
118
|
+
},
|
|
119
|
+
) {
|
|
120
|
+
session ??= session_id;
|
|
121
|
+
const scope = intentScope(db, session),
|
|
122
|
+
recipient = intentRecipient(db, { session, subject, title, sources }),
|
|
123
|
+
unit = intentUnit(title);
|
|
124
|
+
let topic = "",
|
|
125
|
+
operation = "do";
|
|
126
|
+
if (activity === "game") topic = gameTopic(title);
|
|
127
|
+
else if (
|
|
128
|
+
activity === "write" ||
|
|
129
|
+
activity === "read" ||
|
|
130
|
+
String(activity).includes(".")
|
|
131
|
+
)
|
|
132
|
+
topic = String(title).match(/[《「]([^》」]{1,100})[》」]/)?.[1] || "";
|
|
133
|
+
if (activity === "write") {
|
|
134
|
+
operation = /修改|重写|修订/.test(title)
|
|
135
|
+
? "revise"
|
|
136
|
+
: /续写|接续|下一篇/.test(title)
|
|
137
|
+
? "continue"
|
|
138
|
+
: "write";
|
|
139
|
+
}
|
|
140
|
+
if (/重玩|重新玩|重读|再读一遍|再玩一遍/.test(title)) operation = "repeat";
|
|
141
|
+
const anchored = !!topic,
|
|
142
|
+
key = anchored
|
|
143
|
+
? createHash("sha256")
|
|
144
|
+
.update(
|
|
145
|
+
JSON.stringify([
|
|
146
|
+
scope,
|
|
147
|
+
recipient,
|
|
148
|
+
activity,
|
|
149
|
+
normalized(topic),
|
|
150
|
+
unit?.key || "",
|
|
151
|
+
operation,
|
|
152
|
+
]),
|
|
153
|
+
)
|
|
154
|
+
.digest("hex")
|
|
155
|
+
: null;
|
|
156
|
+
return {
|
|
157
|
+
key,
|
|
158
|
+
anchored,
|
|
159
|
+
scope,
|
|
160
|
+
recipient,
|
|
161
|
+
topic,
|
|
162
|
+
unit,
|
|
163
|
+
operation,
|
|
164
|
+
project: projectId || project_id || null,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
@@ -1,171 +1,171 @@
|
|
|
1
|
-
// What she can spend time on. The four built-in kinds keep their own
|
|
2
|
-
// execution paths; a plugin adds a kind and only supplies material. Nothing
|
|
3
|
-
// here knows that plugins exist: a kind is a kind.
|
|
4
|
-
|
|
5
|
-
const registry = new Map();
|
|
6
|
-
|
|
7
|
-
function define(kind) {
|
|
8
|
-
registry.set(kind.kind, kind);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
define({
|
|
12
|
-
kind: "write",
|
|
13
|
-
label: "写作",
|
|
14
|
-
builtin: true,
|
|
15
|
-
minutes: [15, "写作、推敲与收尾"],
|
|
16
|
-
energy: true,
|
|
17
|
-
pattern: /写|小说|短篇|诗|随笔|故事/,
|
|
18
|
-
});
|
|
19
|
-
define({
|
|
20
|
-
kind: "game",
|
|
21
|
-
label: "正在玩",
|
|
22
|
-
builtin: true,
|
|
23
|
-
minutes: [25, "本段剧情与场景体验"],
|
|
24
|
-
energy: true,
|
|
25
|
-
pattern: /游戏|Rewrite|ATRI|盲开|通关|打完.+章|游玩/i,
|
|
26
|
-
});
|
|
27
|
-
define({
|
|
28
|
-
kind: "read",
|
|
29
|
-
label: "阅读",
|
|
30
|
-
builtin: true,
|
|
31
|
-
minutes: [15, "阅读与消化本段内容"],
|
|
32
|
-
pattern: /读|阅读|看.{0,12}(?:书|资料|文章)/,
|
|
33
|
-
});
|
|
34
|
-
define({
|
|
35
|
-
kind: "think",
|
|
36
|
-
label: "独处思考",
|
|
37
|
-
builtin: true,
|
|
38
|
-
minutes: [10, "思考与整理本段想法"],
|
|
39
|
-
pattern: /思考|想一想|想想|整理思路/,
|
|
40
|
-
});
|
|
41
|
-
define({
|
|
42
|
-
kind: "unknown",
|
|
43
|
-
label: "等待澄清",
|
|
44
|
-
builtin: true,
|
|
45
|
-
placeholder: true,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
export const BUILTIN_ACTIVITIES = ["write", "read", "think", "game"];
|
|
49
|
-
|
|
50
|
-
const KIND_NAME = /^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]{0,40}$/;
|
|
51
|
-
|
|
52
|
-
export function registerActivity(kind) {
|
|
53
|
-
if (!KIND_NAME.test(kind?.kind || "")) throw Error("活动类型无效");
|
|
54
|
-
if (registry.get(kind.kind)?.builtin) throw Error("不能覆盖内置的活动");
|
|
55
|
-
registry.set(kind.kind, {
|
|
56
|
-
minutes: [15, "本段活动"],
|
|
57
|
-
energy: false,
|
|
58
|
-
enabled: true,
|
|
59
|
-
blockReason: "",
|
|
60
|
-
...kind,
|
|
61
|
-
plugin: true,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function unregisterActivities(pluginId) {
|
|
66
|
-
for (const [kind, def] of registry)
|
|
67
|
-
if (def.pluginId === pluginId) registry.delete(kind);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function setActivityEnabled(kind, enabled, reason = "") {
|
|
71
|
-
const def = registry.get(kind);
|
|
72
|
-
if (!def?.plugin) return;
|
|
73
|
-
def.enabled = !!enabled;
|
|
74
|
-
def.blockReason = enabled ? "" : reason || "所需插件已停用";
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function activityOf(kind) {
|
|
78
|
-
return registry.get(kind) || null;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function activityLabel(kind, fallback = "活动") {
|
|
82
|
-
return registry.get(kind)?.label || fallback;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function activityMinutes(kind) {
|
|
86
|
-
return registry.get(kind)?.minutes || [15, "本段活动"];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function needsEnergy(kind) {
|
|
90
|
-
return !!registry.get(kind)?.energy;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function isPluginActivity(kind) {
|
|
94
|
-
return !!registry.get(kind)?.plugin;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// A kind she can actually begin. Unknown is a placeholder, and a stopped
|
|
98
|
-
// plugin's kind is not.
|
|
99
|
-
export function isExecutable(kind) {
|
|
100
|
-
const def = registry.get(kind);
|
|
101
|
-
if (!def || def.placeholder) return false;
|
|
102
|
-
return def.builtin || !!def.enabled;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function activityEnum({ unknown = false } = {}) {
|
|
106
|
-
const kinds = [...BUILTIN_ACTIVITIES];
|
|
107
|
-
for (const def of registry.values())
|
|
108
|
-
if (def.plugin && def.enabled) kinds.push(def.kind);
|
|
109
|
-
if (unknown) kinds.push("unknown");
|
|
110
|
-
return kinds.join("|");
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export function pluginActivities() {
|
|
114
|
-
return [...registry.values()].filter((def) => def.plugin);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Same order as before: writing wins over a game, a game over reading.
|
|
118
|
-
export function classifyActivity(words) {
|
|
119
|
-
const source = String(words || "");
|
|
120
|
-
for (const kind of ["write", "game", "read", "think"])
|
|
121
|
-
if (registry.get(kind).pattern.test(source)) return kind;
|
|
122
|
-
for (const def of registry.values())
|
|
123
|
-
if (def.plugin && def.enabled && def.pattern?.test(source)) return def.kind;
|
|
124
|
-
return "unknown";
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function wakeActivities(db, pluginId, now) {
|
|
128
|
-
const kinds = pluginActivities()
|
|
129
|
-
.filter((def) => def.pluginId === pluginId && def.enabled)
|
|
130
|
-
.map((def) => def.kind);
|
|
131
|
-
if (!kinds.length) return 0;
|
|
132
|
-
const waiting = db
|
|
133
|
-
.prepare(
|
|
134
|
-
`SELECT id,ready_at FROM mind_time_tasks WHERE state='waiting' AND wait_reason='所需插件已停用' AND activity IN (${kinds.map(() => "?").join(",")}) AND json_extract(checkpoint,'$.mergedInto') IS NULL`,
|
|
135
|
-
)
|
|
136
|
-
.all(...kinds);
|
|
137
|
-
const resume = db.prepare(
|
|
138
|
-
"UPDATE mind_time_tasks SET state='todo',wait_reason='',ready_at=?,updated=? WHERE id=? AND state='waiting'",
|
|
139
|
-
);
|
|
140
|
-
for (const row of waiting)
|
|
141
|
-
resume.run(Math.max(now, row.ready_at || now), now, row.id);
|
|
142
|
-
return waiting.length;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Keeps the built-in wording when no plugin kind is registered, and extends
|
|
146
|
-
// it once one is.
|
|
147
|
-
export function withActivities(prompt) {
|
|
148
|
-
const extra = pluginActivities()
|
|
149
|
-
.filter((def) => def.enabled)
|
|
150
|
-
.map((def) => def.kind);
|
|
151
|
-
const quoted = ["read", "write", "think", "game", ...extra]
|
|
152
|
-
.map((kind) => `"${kind}"`)
|
|
153
|
-
.join("|");
|
|
154
|
-
return String(prompt)
|
|
155
|
-
.replaceAll(
|
|
156
|
-
"write|read|think|game|unknown",
|
|
157
|
-
activityEnum({ unknown: true }),
|
|
158
|
-
)
|
|
159
|
-
.replaceAll("write|read|think|game", activityEnum())
|
|
160
|
-
.replaceAll('"read"|"write"|"think"|"game"', quoted);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export function pluginAvailable() {
|
|
164
|
-
const out = {};
|
|
165
|
-
for (const def of pluginActivities()) out[def.kind] = !!def.enabled;
|
|
166
|
-
return out;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export function holdsClock(kind) {
|
|
170
|
-
return kind === "game" || isPluginActivity(kind);
|
|
171
|
-
}
|
|
1
|
+
// What she can spend time on. The four built-in kinds keep their own
|
|
2
|
+
// execution paths; a plugin adds a kind and only supplies material. Nothing
|
|
3
|
+
// here knows that plugins exist: a kind is a kind.
|
|
4
|
+
|
|
5
|
+
const registry = new Map();
|
|
6
|
+
|
|
7
|
+
function define(kind) {
|
|
8
|
+
registry.set(kind.kind, kind);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
define({
|
|
12
|
+
kind: "write",
|
|
13
|
+
label: "写作",
|
|
14
|
+
builtin: true,
|
|
15
|
+
minutes: [15, "写作、推敲与收尾"],
|
|
16
|
+
energy: true,
|
|
17
|
+
pattern: /写|小说|短篇|诗|随笔|故事/,
|
|
18
|
+
});
|
|
19
|
+
define({
|
|
20
|
+
kind: "game",
|
|
21
|
+
label: "正在玩",
|
|
22
|
+
builtin: true,
|
|
23
|
+
minutes: [25, "本段剧情与场景体验"],
|
|
24
|
+
energy: true,
|
|
25
|
+
pattern: /游戏|Rewrite|ATRI|盲开|通关|打完.+章|游玩/i,
|
|
26
|
+
});
|
|
27
|
+
define({
|
|
28
|
+
kind: "read",
|
|
29
|
+
label: "阅读",
|
|
30
|
+
builtin: true,
|
|
31
|
+
minutes: [15, "阅读与消化本段内容"],
|
|
32
|
+
pattern: /读|阅读|看.{0,12}(?:书|资料|文章)/,
|
|
33
|
+
});
|
|
34
|
+
define({
|
|
35
|
+
kind: "think",
|
|
36
|
+
label: "独处思考",
|
|
37
|
+
builtin: true,
|
|
38
|
+
minutes: [10, "思考与整理本段想法"],
|
|
39
|
+
pattern: /思考|想一想|想想|整理思路/,
|
|
40
|
+
});
|
|
41
|
+
define({
|
|
42
|
+
kind: "unknown",
|
|
43
|
+
label: "等待澄清",
|
|
44
|
+
builtin: true,
|
|
45
|
+
placeholder: true,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export const BUILTIN_ACTIVITIES = ["write", "read", "think", "game"];
|
|
49
|
+
|
|
50
|
+
const KIND_NAME = /^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]{0,40}$/;
|
|
51
|
+
|
|
52
|
+
export function registerActivity(kind) {
|
|
53
|
+
if (!KIND_NAME.test(kind?.kind || "")) throw Error("活动类型无效");
|
|
54
|
+
if (registry.get(kind.kind)?.builtin) throw Error("不能覆盖内置的活动");
|
|
55
|
+
registry.set(kind.kind, {
|
|
56
|
+
minutes: [15, "本段活动"],
|
|
57
|
+
energy: false,
|
|
58
|
+
enabled: true,
|
|
59
|
+
blockReason: "",
|
|
60
|
+
...kind,
|
|
61
|
+
plugin: true,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function unregisterActivities(pluginId) {
|
|
66
|
+
for (const [kind, def] of registry)
|
|
67
|
+
if (def.pluginId === pluginId) registry.delete(kind);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function setActivityEnabled(kind, enabled, reason = "") {
|
|
71
|
+
const def = registry.get(kind);
|
|
72
|
+
if (!def?.plugin) return;
|
|
73
|
+
def.enabled = !!enabled;
|
|
74
|
+
def.blockReason = enabled ? "" : reason || "所需插件已停用";
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function activityOf(kind) {
|
|
78
|
+
return registry.get(kind) || null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function activityLabel(kind, fallback = "活动") {
|
|
82
|
+
return registry.get(kind)?.label || fallback;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function activityMinutes(kind) {
|
|
86
|
+
return registry.get(kind)?.minutes || [15, "本段活动"];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function needsEnergy(kind) {
|
|
90
|
+
return !!registry.get(kind)?.energy;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function isPluginActivity(kind) {
|
|
94
|
+
return !!registry.get(kind)?.plugin;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// A kind she can actually begin. Unknown is a placeholder, and a stopped
|
|
98
|
+
// plugin's kind is not.
|
|
99
|
+
export function isExecutable(kind) {
|
|
100
|
+
const def = registry.get(kind);
|
|
101
|
+
if (!def || def.placeholder) return false;
|
|
102
|
+
return def.builtin || !!def.enabled;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function activityEnum({ unknown = false } = {}) {
|
|
106
|
+
const kinds = [...BUILTIN_ACTIVITIES];
|
|
107
|
+
for (const def of registry.values())
|
|
108
|
+
if (def.plugin && def.enabled) kinds.push(def.kind);
|
|
109
|
+
if (unknown) kinds.push("unknown");
|
|
110
|
+
return kinds.join("|");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function pluginActivities() {
|
|
114
|
+
return [...registry.values()].filter((def) => def.plugin);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Same order as before: writing wins over a game, a game over reading.
|
|
118
|
+
export function classifyActivity(words) {
|
|
119
|
+
const source = String(words || "");
|
|
120
|
+
for (const kind of ["write", "game", "read", "think"])
|
|
121
|
+
if (registry.get(kind).pattern.test(source)) return kind;
|
|
122
|
+
for (const def of registry.values())
|
|
123
|
+
if (def.plugin && def.enabled && def.pattern?.test(source)) return def.kind;
|
|
124
|
+
return "unknown";
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function wakeActivities(db, pluginId, now) {
|
|
128
|
+
const kinds = pluginActivities()
|
|
129
|
+
.filter((def) => def.pluginId === pluginId && def.enabled)
|
|
130
|
+
.map((def) => def.kind);
|
|
131
|
+
if (!kinds.length) return 0;
|
|
132
|
+
const waiting = db
|
|
133
|
+
.prepare(
|
|
134
|
+
`SELECT id,ready_at FROM mind_time_tasks WHERE state='waiting' AND wait_reason='所需插件已停用' AND activity IN (${kinds.map(() => "?").join(",")}) AND json_extract(checkpoint,'$.mergedInto') IS NULL`,
|
|
135
|
+
)
|
|
136
|
+
.all(...kinds);
|
|
137
|
+
const resume = db.prepare(
|
|
138
|
+
"UPDATE mind_time_tasks SET state='todo',wait_reason='',ready_at=?,updated=? WHERE id=? AND state='waiting'",
|
|
139
|
+
);
|
|
140
|
+
for (const row of waiting)
|
|
141
|
+
resume.run(Math.max(now, row.ready_at || now), now, row.id);
|
|
142
|
+
return waiting.length;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Keeps the built-in wording when no plugin kind is registered, and extends
|
|
146
|
+
// it once one is.
|
|
147
|
+
export function withActivities(prompt) {
|
|
148
|
+
const extra = pluginActivities()
|
|
149
|
+
.filter((def) => def.enabled)
|
|
150
|
+
.map((def) => def.kind);
|
|
151
|
+
const quoted = ["read", "write", "think", "game", ...extra]
|
|
152
|
+
.map((kind) => `"${kind}"`)
|
|
153
|
+
.join("|");
|
|
154
|
+
return String(prompt)
|
|
155
|
+
.replaceAll(
|
|
156
|
+
"write|read|think|game|unknown",
|
|
157
|
+
activityEnum({ unknown: true }),
|
|
158
|
+
)
|
|
159
|
+
.replaceAll("write|read|think|game", activityEnum())
|
|
160
|
+
.replaceAll('"read"|"write"|"think"|"game"', quoted);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function pluginAvailable() {
|
|
164
|
+
const out = {};
|
|
165
|
+
for (const def of pluginActivities()) out[def.kind] = !!def.enabled;
|
|
166
|
+
return out;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function holdsClock(kind) {
|
|
170
|
+
return kind === "game" || isPluginActivity(kind);
|
|
171
|
+
}
|