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,198 +1,198 @@
|
|
|
1
|
-
import { parse, text, hasCredential } from "../util.js";
|
|
2
|
-
import { intentRecipient, intentMessageSources } from "./intent.js";
|
|
3
|
-
import { spokenDate } from "./schedule.js";
|
|
4
|
-
import { isExecutable } from "./kinds.js";
|
|
5
|
-
const ACTION =
|
|
6
|
-
/写|读|玩|看|整理|想一想|解释|分析|发|给你|做|聊|陪|提醒|联系|分享|检查/;
|
|
7
|
-
const FUTURE =
|
|
8
|
-
/(?:我(?:会|要|想|打算|准备|答应|来)|回头|晚点|稍后|过会|等会|下次|改天|明天|后天|明晚|今晚|这周|周末|以后|到时候|等我|给你|帮你)/;
|
|
9
|
-
export class CommitmentReview {
|
|
10
|
-
constructor(life) {
|
|
11
|
-
this.life = life;
|
|
12
|
-
this.time = life.mind.time;
|
|
13
|
-
this.db = life.db;
|
|
14
|
-
}
|
|
15
|
-
batch(now) {
|
|
16
|
-
const cursor = this.life.repo.config("own-day", {}).reviewSeq || 0;
|
|
17
|
-
const rows = this.db
|
|
18
|
-
.prepare(
|
|
19
|
-
"SELECT seq,time,session_id,payload FROM core_events WHERE role='assistant' AND seq>? AND time<=? AND seq NOT IN (SELECT seq FROM mind_unlived) AND seq NOT IN (SELECT seq FROM mind_time_commitment_reviews) AND COALESCE(json_extract(payload,'$.simulated'),0)=0 AND json_extract(payload,'$.artifact') IS NULL ORDER BY seq LIMIT 48",
|
|
20
|
-
)
|
|
21
|
-
.all(cursor, now);
|
|
22
|
-
if (!rows.length) return null;
|
|
23
|
-
const rooms = new Set(this.life.living().map((s) => s.id));
|
|
24
|
-
const enabled = rows.filter((r) => {
|
|
25
|
-
const words = String(parse(r.payload, {}).text || "");
|
|
26
|
-
const candidate =
|
|
27
|
-
rooms.has(r.session_id) &&
|
|
28
|
-
((FUTURE.test(words) && ACTION.test(words)) ||
|
|
29
|
-
/^(?:嗯[,,]?|好|行|可以|没问题|会的|答应)/.test(words));
|
|
30
|
-
if (!candidate)
|
|
31
|
-
this.db
|
|
32
|
-
.prepare(
|
|
33
|
-
"INSERT OR IGNORE INTO mind_time_commitment_reviews(seq,reviewed) VALUES(?,?)",
|
|
34
|
-
)
|
|
35
|
-
.run(r.seq, now);
|
|
36
|
-
return candidate;
|
|
37
|
-
});
|
|
38
|
-
if (!enabled.length)
|
|
39
|
-
return {
|
|
40
|
-
through: rows.at(-1).seq,
|
|
41
|
-
rows: [],
|
|
42
|
-
session: null,
|
|
43
|
-
messages: [],
|
|
44
|
-
};
|
|
45
|
-
const session = enabled[0].session_id,
|
|
46
|
-
same = enabled.filter((r) => r.session_id === session);
|
|
47
|
-
const selected = same.slice(0, 12);
|
|
48
|
-
const chosen = new Set(selected.map((r) => r.seq));
|
|
49
|
-
const firstOther = enabled.find((r) => !chosen.has(r.seq));
|
|
50
|
-
const messages = selected.map((r) => {
|
|
51
|
-
const m = parse(r.payload, {}),
|
|
52
|
-
refs = Array.isArray(m.replyTargetIds) ? m.replyTargetIds : [];
|
|
53
|
-
const earlier = this.db
|
|
54
|
-
.prepare(
|
|
55
|
-
"SELECT seq,role,payload FROM core_events WHERE session_id=? AND seq<? AND time<=? AND seq NOT IN (SELECT seq FROM mind_unlived) AND COALESCE(json_extract(payload,'$.simulated'),0)=0 ORDER BY seq DESC LIMIT 3",
|
|
56
|
-
)
|
|
57
|
-
.all(session, r.seq, now)
|
|
58
|
-
.reverse();
|
|
59
|
-
const targets = refs
|
|
60
|
-
.map((seq) =>
|
|
61
|
-
this.db
|
|
62
|
-
.prepare(
|
|
63
|
-
"SELECT seq,role,payload FROM core_events WHERE seq=? AND session_id=? AND seq<? AND time<=? AND seq NOT IN (SELECT seq FROM mind_unlived) AND COALESCE(json_extract(payload,'$.simulated'),0)=0 AND json_extract(payload,'$.artifact') IS NULL",
|
|
64
|
-
)
|
|
65
|
-
.get(seq, session, r.seq, now),
|
|
66
|
-
)
|
|
67
|
-
.filter(Boolean);
|
|
68
|
-
return {
|
|
69
|
-
source: `m:${r.seq}`,
|
|
70
|
-
said: text(m.text, 700),
|
|
71
|
-
earlier: [
|
|
72
|
-
...new Map([...earlier, ...targets].map((x) => [x.seq, x])).values(),
|
|
73
|
-
].map((x) => ({
|
|
74
|
-
ref: `m:${x.seq}`,
|
|
75
|
-
role: x.role,
|
|
76
|
-
text: text(parse(x.payload, {}).text, 240),
|
|
77
|
-
})),
|
|
78
|
-
};
|
|
79
|
-
});
|
|
80
|
-
return {
|
|
81
|
-
session,
|
|
82
|
-
rows: selected,
|
|
83
|
-
messages,
|
|
84
|
-
through: firstOther ? firstOther.seq - 1 : rows.at(-1).seq,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
apply(batch, result, now) {
|
|
88
|
-
if (!Array.isArray(result?.commitments)) throw Error("约定回看格式无效");
|
|
89
|
-
const added = [],
|
|
90
|
-
perSource = new Map();
|
|
91
|
-
for (const item of result.commitments.slice(0, 6)) {
|
|
92
|
-
const row = batch.rows.find((r) => `m:${r.seq}` === item.source),
|
|
93
|
-
quote = text(item.quote, 240),
|
|
94
|
-
title = text(item.title, 240);
|
|
95
|
-
if (
|
|
96
|
-
!row ||
|
|
97
|
-
item.accepted !== true ||
|
|
98
|
-
!quote ||
|
|
99
|
-
!title ||
|
|
100
|
-
hasCredential(title + quote)
|
|
101
|
-
)
|
|
102
|
-
continue;
|
|
103
|
-
const m = parse(row.payload, {}),
|
|
104
|
-
message = batch.messages.find((x) => x.source === item.source);
|
|
105
|
-
if (
|
|
106
|
-
!String(m.text || "").includes(quote) ||
|
|
107
|
-
!ACTION.test(title) ||
|
|
108
|
-
/(?:开玩笑|角色台词|小说里|故事里|假如|假设|不答应|没答应|不能答应)/.test(
|
|
109
|
-
m.text,
|
|
110
|
-
)
|
|
111
|
-
)
|
|
112
|
-
continue;
|
|
113
|
-
const future = FUTURE.test(m.text) && ACTION.test(m.text);
|
|
114
|
-
const accepted =
|
|
115
|
-
/^(?:嗯[,,]?|好|行|可以|没问题|会的|答应)/.test(m.text) &&
|
|
116
|
-
message.earlier.some(
|
|
117
|
-
(e) =>
|
|
118
|
-
e.role === "user" &&
|
|
119
|
-
/(?:帮我|给我|能不能|你能|你可以|请你|你来)/.test(e.text) &&
|
|
120
|
-
ACTION.test(e.text),
|
|
121
|
-
);
|
|
122
|
-
if (!future && !accepted) continue;
|
|
123
|
-
if (this.time.tasks.delivery.resolve(row, m, {}, now)) continue;
|
|
124
|
-
const linked = this.db
|
|
125
|
-
.prepare(
|
|
126
|
-
"SELECT task_id FROM mind_time_task_aliases WHERE kind='source' AND substr(alias_id,instr(alias_id,':')+1)=?",
|
|
127
|
-
)
|
|
128
|
-
.all(item.source)
|
|
129
|
-
.map((r) =>
|
|
130
|
-
this.time.tasks.get(this.time.tasks.links.canonical(r.task_id)),
|
|
131
|
-
)
|
|
132
|
-
.filter(Boolean);
|
|
133
|
-
if (linked.length) {
|
|
134
|
-
added.push(...linked.map((t) => t.id));
|
|
135
|
-
perSource.set(
|
|
136
|
-
row.seq,
|
|
137
|
-
linked.map((t) => t.id),
|
|
138
|
-
);
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
if (item.activity !== "unknown" && !isExecutable(item.activity)) continue;
|
|
142
|
-
const kind = item.kind === "plan" ? "plan" : "promise",
|
|
143
|
-
subject =
|
|
144
|
-
kind === "promise"
|
|
145
|
-
? intentRecipient(this.db, {
|
|
146
|
-
session: row.session_id,
|
|
147
|
-
title: m.text,
|
|
148
|
-
sources: [row.seq],
|
|
149
|
-
accepted: true,
|
|
150
|
-
})
|
|
151
|
-
: null;
|
|
152
|
-
const result = this.time.tasks.add(
|
|
153
|
-
{
|
|
154
|
-
kind,
|
|
155
|
-
activity: item.activity,
|
|
156
|
-
title,
|
|
157
|
-
why: "独处回看时补回自己实际说出口的约定",
|
|
158
|
-
sources: intentMessageSources(this.db, row, m),
|
|
159
|
-
session: row.session_id,
|
|
160
|
-
subject,
|
|
161
|
-
origin: "commitment-review",
|
|
162
|
-
...spokenDate(m.text, row.time, this.time.mind.timeZone()),
|
|
163
|
-
},
|
|
164
|
-
now,
|
|
165
|
-
);
|
|
166
|
-
const id = result.id || result.duplicate;
|
|
167
|
-
if (id) {
|
|
168
|
-
added.push(id);
|
|
169
|
-
perSource.set(row.seq, [...(perSource.get(row.seq) || []), id]);
|
|
170
|
-
if (result.id && kind === "promise" && !subject)
|
|
171
|
-
this.time.tasks.wait(
|
|
172
|
-
this.time.tasks.get(id),
|
|
173
|
-
"等待明确交付给谁",
|
|
174
|
-
Number.MAX_SAFE_INTEGER,
|
|
175
|
-
now,
|
|
176
|
-
);
|
|
177
|
-
this.time.event(
|
|
178
|
-
id,
|
|
179
|
-
"commitment-recovered",
|
|
180
|
-
"从实际说出口的话中补回约定",
|
|
181
|
-
{ source: item.source, quote },
|
|
182
|
-
now,
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
for (const row of batch.rows)
|
|
187
|
-
this.db
|
|
188
|
-
.prepare(
|
|
189
|
-
"INSERT OR IGNORE INTO mind_time_commitment_reviews(seq,reviewed,task_ids) VALUES(?,?,?)",
|
|
190
|
-
)
|
|
191
|
-
.run(
|
|
192
|
-
row.seq,
|
|
193
|
-
now,
|
|
194
|
-
JSON.stringify([...new Set(perSource.get(row.seq) || [])]),
|
|
195
|
-
);
|
|
196
|
-
return [...new Set(added)];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
1
|
+
import { parse, text, hasCredential } from "../util.js";
|
|
2
|
+
import { intentRecipient, intentMessageSources } from "./intent.js";
|
|
3
|
+
import { spokenDate } from "./schedule.js";
|
|
4
|
+
import { isExecutable } from "./kinds.js";
|
|
5
|
+
const ACTION =
|
|
6
|
+
/写|读|玩|看|整理|想一想|解释|分析|发|给你|做|聊|陪|提醒|联系|分享|检查/;
|
|
7
|
+
const FUTURE =
|
|
8
|
+
/(?:我(?:会|要|想|打算|准备|答应|来)|回头|晚点|稍后|过会|等会|下次|改天|明天|后天|明晚|今晚|这周|周末|以后|到时候|等我|给你|帮你)/;
|
|
9
|
+
export class CommitmentReview {
|
|
10
|
+
constructor(life) {
|
|
11
|
+
this.life = life;
|
|
12
|
+
this.time = life.mind.time;
|
|
13
|
+
this.db = life.db;
|
|
14
|
+
}
|
|
15
|
+
batch(now) {
|
|
16
|
+
const cursor = this.life.repo.config("own-day", {}).reviewSeq || 0;
|
|
17
|
+
const rows = this.db
|
|
18
|
+
.prepare(
|
|
19
|
+
"SELECT seq,time,session_id,payload FROM core_events WHERE role='assistant' AND seq>? AND time<=? AND seq NOT IN (SELECT seq FROM mind_unlived) AND seq NOT IN (SELECT seq FROM mind_time_commitment_reviews) AND COALESCE(json_extract(payload,'$.simulated'),0)=0 AND json_extract(payload,'$.artifact') IS NULL ORDER BY seq LIMIT 48",
|
|
20
|
+
)
|
|
21
|
+
.all(cursor, now);
|
|
22
|
+
if (!rows.length) return null;
|
|
23
|
+
const rooms = new Set(this.life.living().map((s) => s.id));
|
|
24
|
+
const enabled = rows.filter((r) => {
|
|
25
|
+
const words = String(parse(r.payload, {}).text || "");
|
|
26
|
+
const candidate =
|
|
27
|
+
rooms.has(r.session_id) &&
|
|
28
|
+
((FUTURE.test(words) && ACTION.test(words)) ||
|
|
29
|
+
/^(?:嗯[,,]?|好|行|可以|没问题|会的|答应)/.test(words));
|
|
30
|
+
if (!candidate)
|
|
31
|
+
this.db
|
|
32
|
+
.prepare(
|
|
33
|
+
"INSERT OR IGNORE INTO mind_time_commitment_reviews(seq,reviewed) VALUES(?,?)",
|
|
34
|
+
)
|
|
35
|
+
.run(r.seq, now);
|
|
36
|
+
return candidate;
|
|
37
|
+
});
|
|
38
|
+
if (!enabled.length)
|
|
39
|
+
return {
|
|
40
|
+
through: rows.at(-1).seq,
|
|
41
|
+
rows: [],
|
|
42
|
+
session: null,
|
|
43
|
+
messages: [],
|
|
44
|
+
};
|
|
45
|
+
const session = enabled[0].session_id,
|
|
46
|
+
same = enabled.filter((r) => r.session_id === session);
|
|
47
|
+
const selected = same.slice(0, 12);
|
|
48
|
+
const chosen = new Set(selected.map((r) => r.seq));
|
|
49
|
+
const firstOther = enabled.find((r) => !chosen.has(r.seq));
|
|
50
|
+
const messages = selected.map((r) => {
|
|
51
|
+
const m = parse(r.payload, {}),
|
|
52
|
+
refs = Array.isArray(m.replyTargetIds) ? m.replyTargetIds : [];
|
|
53
|
+
const earlier = this.db
|
|
54
|
+
.prepare(
|
|
55
|
+
"SELECT seq,role,payload FROM core_events WHERE session_id=? AND seq<? AND time<=? AND seq NOT IN (SELECT seq FROM mind_unlived) AND COALESCE(json_extract(payload,'$.simulated'),0)=0 ORDER BY seq DESC LIMIT 3",
|
|
56
|
+
)
|
|
57
|
+
.all(session, r.seq, now)
|
|
58
|
+
.reverse();
|
|
59
|
+
const targets = refs
|
|
60
|
+
.map((seq) =>
|
|
61
|
+
this.db
|
|
62
|
+
.prepare(
|
|
63
|
+
"SELECT seq,role,payload FROM core_events WHERE seq=? AND session_id=? AND seq<? AND time<=? AND seq NOT IN (SELECT seq FROM mind_unlived) AND COALESCE(json_extract(payload,'$.simulated'),0)=0 AND json_extract(payload,'$.artifact') IS NULL",
|
|
64
|
+
)
|
|
65
|
+
.get(seq, session, r.seq, now),
|
|
66
|
+
)
|
|
67
|
+
.filter(Boolean);
|
|
68
|
+
return {
|
|
69
|
+
source: `m:${r.seq}`,
|
|
70
|
+
said: text(m.text, 700),
|
|
71
|
+
earlier: [
|
|
72
|
+
...new Map([...earlier, ...targets].map((x) => [x.seq, x])).values(),
|
|
73
|
+
].map((x) => ({
|
|
74
|
+
ref: `m:${x.seq}`,
|
|
75
|
+
role: x.role,
|
|
76
|
+
text: text(parse(x.payload, {}).text, 240),
|
|
77
|
+
})),
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
return {
|
|
81
|
+
session,
|
|
82
|
+
rows: selected,
|
|
83
|
+
messages,
|
|
84
|
+
through: firstOther ? firstOther.seq - 1 : rows.at(-1).seq,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
apply(batch, result, now) {
|
|
88
|
+
if (!Array.isArray(result?.commitments)) throw Error("约定回看格式无效");
|
|
89
|
+
const added = [],
|
|
90
|
+
perSource = new Map();
|
|
91
|
+
for (const item of result.commitments.slice(0, 6)) {
|
|
92
|
+
const row = batch.rows.find((r) => `m:${r.seq}` === item.source),
|
|
93
|
+
quote = text(item.quote, 240),
|
|
94
|
+
title = text(item.title, 240);
|
|
95
|
+
if (
|
|
96
|
+
!row ||
|
|
97
|
+
item.accepted !== true ||
|
|
98
|
+
!quote ||
|
|
99
|
+
!title ||
|
|
100
|
+
hasCredential(title + quote)
|
|
101
|
+
)
|
|
102
|
+
continue;
|
|
103
|
+
const m = parse(row.payload, {}),
|
|
104
|
+
message = batch.messages.find((x) => x.source === item.source);
|
|
105
|
+
if (
|
|
106
|
+
!String(m.text || "").includes(quote) ||
|
|
107
|
+
!ACTION.test(title) ||
|
|
108
|
+
/(?:开玩笑|角色台词|小说里|故事里|假如|假设|不答应|没答应|不能答应)/.test(
|
|
109
|
+
m.text,
|
|
110
|
+
)
|
|
111
|
+
)
|
|
112
|
+
continue;
|
|
113
|
+
const future = FUTURE.test(m.text) && ACTION.test(m.text);
|
|
114
|
+
const accepted =
|
|
115
|
+
/^(?:嗯[,,]?|好|行|可以|没问题|会的|答应)/.test(m.text) &&
|
|
116
|
+
message.earlier.some(
|
|
117
|
+
(e) =>
|
|
118
|
+
e.role === "user" &&
|
|
119
|
+
/(?:帮我|给我|能不能|你能|你可以|请你|你来)/.test(e.text) &&
|
|
120
|
+
ACTION.test(e.text),
|
|
121
|
+
);
|
|
122
|
+
if (!future && !accepted) continue;
|
|
123
|
+
if (this.time.tasks.delivery.resolve(row, m, {}, now)) continue;
|
|
124
|
+
const linked = this.db
|
|
125
|
+
.prepare(
|
|
126
|
+
"SELECT task_id FROM mind_time_task_aliases WHERE kind='source' AND substr(alias_id,instr(alias_id,':')+1)=?",
|
|
127
|
+
)
|
|
128
|
+
.all(item.source)
|
|
129
|
+
.map((r) =>
|
|
130
|
+
this.time.tasks.get(this.time.tasks.links.canonical(r.task_id)),
|
|
131
|
+
)
|
|
132
|
+
.filter(Boolean);
|
|
133
|
+
if (linked.length) {
|
|
134
|
+
added.push(...linked.map((t) => t.id));
|
|
135
|
+
perSource.set(
|
|
136
|
+
row.seq,
|
|
137
|
+
linked.map((t) => t.id),
|
|
138
|
+
);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (item.activity !== "unknown" && !isExecutable(item.activity)) continue;
|
|
142
|
+
const kind = item.kind === "plan" ? "plan" : "promise",
|
|
143
|
+
subject =
|
|
144
|
+
kind === "promise"
|
|
145
|
+
? intentRecipient(this.db, {
|
|
146
|
+
session: row.session_id,
|
|
147
|
+
title: m.text,
|
|
148
|
+
sources: [row.seq],
|
|
149
|
+
accepted: true,
|
|
150
|
+
})
|
|
151
|
+
: null;
|
|
152
|
+
const result = this.time.tasks.add(
|
|
153
|
+
{
|
|
154
|
+
kind,
|
|
155
|
+
activity: item.activity,
|
|
156
|
+
title,
|
|
157
|
+
why: "独处回看时补回自己实际说出口的约定",
|
|
158
|
+
sources: intentMessageSources(this.db, row, m),
|
|
159
|
+
session: row.session_id,
|
|
160
|
+
subject,
|
|
161
|
+
origin: "commitment-review",
|
|
162
|
+
...spokenDate(m.text, row.time, this.time.mind.timeZone()),
|
|
163
|
+
},
|
|
164
|
+
now,
|
|
165
|
+
);
|
|
166
|
+
const id = result.id || result.duplicate;
|
|
167
|
+
if (id) {
|
|
168
|
+
added.push(id);
|
|
169
|
+
perSource.set(row.seq, [...(perSource.get(row.seq) || []), id]);
|
|
170
|
+
if (result.id && kind === "promise" && !subject)
|
|
171
|
+
this.time.tasks.wait(
|
|
172
|
+
this.time.tasks.get(id),
|
|
173
|
+
"等待明确交付给谁",
|
|
174
|
+
Number.MAX_SAFE_INTEGER,
|
|
175
|
+
now,
|
|
176
|
+
);
|
|
177
|
+
this.time.event(
|
|
178
|
+
id,
|
|
179
|
+
"commitment-recovered",
|
|
180
|
+
"从实际说出口的话中补回约定",
|
|
181
|
+
{ source: item.source, quote },
|
|
182
|
+
now,
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
for (const row of batch.rows)
|
|
187
|
+
this.db
|
|
188
|
+
.prepare(
|
|
189
|
+
"INSERT OR IGNORE INTO mind_time_commitment_reviews(seq,reviewed,task_ids) VALUES(?,?,?)",
|
|
190
|
+
)
|
|
191
|
+
.run(
|
|
192
|
+
row.seq,
|
|
193
|
+
now,
|
|
194
|
+
JSON.stringify([...new Set(perSource.get(row.seq) || [])]),
|
|
195
|
+
);
|
|
196
|
+
return [...new Set(added)];
|
|
197
|
+
}
|
|
198
|
+
}
|