luckytri 1.0.4 → 1.0.6
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/LICENSE +21 -21
- package/README.en.md +2 -0
- package/README.md +2 -0
- package/docs/en/CHANGELOG.md +20 -13
- package/docs/en/guide.md +7 -5
- package/docs/en/her-life.md +2 -2
- package/docs/en/webui.md +1 -1
- package/docs/zh/CHANGELOG.md +20 -13
- package/docs/zh/guide.md +7 -5
- package/docs/zh/her-life.md +2 -2
- package/docs/zh/webui.md +1 -1
- package/package.json +2 -1
- package/public/app/assets/ChatsPage-CFMVozoG.css +1 -0
- package/public/app/assets/{ChatsPage-CshdtTzV.js → ChatsPage-DCYMkJ91.js} +2 -2
- package/public/app/assets/{Empty-C7yzOBzy.js → Empty-CLyZkxR5.js} +1 -1
- package/public/app/assets/{Empty-DmUB2-Bk.css → Empty-DIobYG3x.css} +1 -1
- package/public/app/assets/{Field-BjFv4Rfn.js → Field-BpaRwLI_.js} +1 -1
- package/public/app/assets/{HeartPage-eqo6ru16.js → HeartPage-BIOMTiwr.js} +1 -1
- package/public/app/assets/HeartPage-C-2jvgzF.css +1 -0
- package/public/app/assets/{LifePage-CN8GE5NK.js → LifePage-BCgM4JkR.js} +1 -1
- package/public/app/assets/LifePage-CG1OHbRK.css +1 -0
- package/public/app/assets/MemoryPage-C_Bu4rfb.css +1 -0
- package/public/app/assets/{MemoryPage-CCpMN4Wg.js → MemoryPage-vShvRqMt.js} +1 -1
- package/public/app/assets/NaturePage-CPZlImT0.css +1 -0
- package/public/app/assets/{NaturePage-C0JqdBTR.js → NaturePage-Cy9ptr4G.js} +2 -2
- package/public/app/assets/PeoplePage-3RRUITDz.css +1 -0
- package/public/app/assets/{PeoplePage-BXGBbO4u.js → PeoplePage-CUZekB2E.js} +1 -1
- package/public/app/assets/{PluginsPage-Dksp5AV5.js → PluginsPage-1RM4rmJP.js} +1 -1
- package/public/app/assets/{SystemPage-BenIyTvk.css → SystemPage-BI2CB5Ig.css} +1 -1
- package/public/app/assets/{SystemPage-Cd7aa8eE.js → SystemPage-BeT5TmIV.js} +1 -1
- package/public/app/assets/TimePage-C-guwPk2.css +1 -0
- package/public/app/assets/{TimePage-Bs_zImb4.js → TimePage-taTmPMM8.js} +2 -2
- package/public/app/assets/{index-BHZcHUMh.css → index-DY5AM0Hz.css} +1 -1
- package/public/app/assets/{index-CyRtYxP3.js → index-DdYwC5ZU.js} +3 -3
- package/public/app/assets/{knowledge-BJOIyuJo.js → knowledge-DJmfu2KN.js} +1 -1
- package/public/app/assets/{media-Bwtx8blz.js → media-BEtnE0Gv.js} +1 -1
- package/public/app/assets/{mind-DtTVrW6Z.js → mind-Dtiw0-QK.js} +1 -1
- package/public/app/index.html +6 -5
- package/public/guide.en.html +11 -3
- package/public/guide.html +6 -3
- package/public/tutorial.en.md +2 -0
- package/public/tutorial.md +2 -0
- package/scripts/import-data.js +128 -128
- package/scripts/proxy-config.js +167 -167
- package/scripts/service-supervisor.js +50 -0
- package/scripts/start-server.js +71 -16
- package/scripts/update-instance.js +201 -201
- package/server/channels/adapters.js +27 -27
- package/server/channels/onebot/adapter.js +288 -288
- package/server/channels/qqbot/adapter.js +253 -253
- package/server/channels/qqbot/api.js +199 -199
- package/server/channels/qqbot/credentials.js +11 -11
- package/server/channels/qqbot/gateway.js +274 -274
- package/server/channels/qqbot/index.js +389 -389
- package/server/channels/segments.js +40 -40
- package/server/channels/session-key.js +153 -153
- package/server/channels/state.js +42 -42
- package/server/core/api.js +564 -564
- package/server/core/context-builder.js +288 -288
- package/server/core/context-compactor.js +454 -454
- package/server/core/conversation-cues.js +325 -325
- package/server/core/conversation-manager.js +87 -87
- package/server/core/feedback.js +8 -8
- package/server/core/group-style.js +72 -72
- package/server/core/initiative-context.js +66 -66
- package/server/core/input-budget.js +32 -32
- package/server/core/local-demo.js +98 -98
- package/server/core/message-manager.js +118 -118
- package/server/core/message-scheduler.js +78 -78
- package/server/core/model-json.js +190 -190
- package/server/core/model-presets.js +900 -900
- package/server/core/name-call.js +29 -29
- package/server/core/network.js +157 -157
- package/server/core/person-name.js +22 -22
- package/server/core/persona-manager.js +2 -1
- package/server/core/reply-delivery.js +404 -403
- package/server/core/reply-target-resolver.js +50 -50
- package/server/core/response-generator.js +50 -50
- package/server/core/response-validator.js +14 -2
- package/server/core/retired-prompts.js +51 -51
- package/server/core/sessions.js +109 -109
- package/server/core/speaker-names.js +92 -92
- package/server/core/topic-tracker.js +65 -65
- package/server/http.js +18 -18
- package/server/i18n/decisions.js +209 -206
- package/server/i18n/errors.js +4 -0
- package/server/i18n/index.js +144 -144
- package/server/i18n/models.js +111 -111
- package/server/knowledge/api.js +342 -342
- package/server/knowledge/embedding-profile.js +114 -114
- package/server/knowledge/index.js +13 -13
- package/server/knowledge/retrieval.js +93 -93
- package/server/knowledge/schema.js +158 -158
- package/server/knowledge/vector-index.js +90 -90
- package/server/mind/affect.js +265 -265
- package/server/mind/attention.js +200 -200
- package/server/mind/bonds.js +565 -565
- package/server/mind/clock.js +83 -83
- package/server/mind/continuity.js +562 -562
- package/server/mind/conversation-origin.js +175 -175
- package/server/mind/days.js +210 -210
- package/server/mind/evidence-read.js +45 -45
- package/server/mind/faces.js +373 -373
- package/server/mind/guard.js +60 -60
- package/server/mind/initiative.js +338 -338
- package/server/mind/life/activities.js +21 -21
- package/server/mind/life/context.js +330 -323
- package/server/mind/life/diary.js +20 -0
- package/server/mind/life/growth.js +261 -254
- package/server/mind/life/index.js +10 -2
- package/server/mind/life/presence.js +305 -305
- package/server/mind/meetings.js +1069 -1069
- package/server/mind/memory-policy.js +48 -48
- package/server/mind/memory.js +888 -888
- package/server/mind/nature.js +358 -358
- package/server/mind/novelty.js +19 -19
- package/server/mind/periods.js +118 -118
- package/server/mind/reading.js +120 -120
- package/server/mind/relationship-context.js +71 -0
- package/server/mind/relationships.js +390 -279
- package/server/mind/salience.js +201 -201
- package/server/mind/schema.js +567 -567
- package/server/mind/self.js +484 -484
- package/server/mind/thoughts.js +274 -274
- package/server/mind/time/agenda.js +242 -242
- package/server/mind/time/api.js +200 -200
- package/server/mind/time/attention.js +34 -34
- package/server/mind/time/delivery-links.js +130 -130
- package/server/mind/time/model-material.js +77 -77
- package/server/mind/time/presentation.js +51 -51
- package/server/mind/time/schedule.js +83 -83
- package/server/mind/time/schema.js +84 -84
- package/server/mind/time/search.js +383 -383
- package/server/mind/time/sharing.js +472 -472
- package/server/mind/time/task-links.js +311 -311
- package/server/mind/time/works.js +432 -432
- package/server/mind/traits.js +191 -191
- package/server/mind/view.js +9 -1
- package/server/runtime/installation.js +116 -116
- package/server/runtime/update-execution.js +2 -1
- package/server/runtime/update-manager.js +140 -140
- package/server/storage/data-package.js +298 -298
- package/server/storage/data-transfer-api.js +50 -50
- package/server/storage/data-transfer-worker.js +18 -18
- package/server/storage/data-transfer.js +416 -416
- package/server/studio/display-names.js +139 -139
- package/server/studio/management.js +102 -102
- package/server/studio/updates.js +144 -144
- package/server/version.js +10 -10
- package/public/app/assets/ChatsPage-DfyPCS9N.css +0 -1
- package/public/app/assets/HeartPage-Bft9wZp5.css +0 -1
- package/public/app/assets/LifePage-BUi5euBF.css +0 -1
- package/public/app/assets/MemoryPage-cZvXfkXb.css +0 -1
- package/public/app/assets/NaturePage-CHkpb5NK.css +0 -1
- package/public/app/assets/PeoplePage-BTU0H1pM.css +0 -1
- package/public/app/assets/TimePage-BOms_n4I.css +0 -1
package/server/mind/time/api.js
CHANGED
|
@@ -1,200 +1,200 @@
|
|
|
1
|
-
import { wrap } from "../../http.js";
|
|
2
|
-
import { displayNames } from "../../studio/display-names.js";
|
|
3
|
-
import { zonedTime } from "../util.js";
|
|
4
|
-
import { experiences } from "./experiences.js";
|
|
5
|
-
|
|
6
|
-
// What a waiting task is waiting for, as a code the page can rely on in any
|
|
7
|
-
// language. The wording of `wait_reason` is for people, not for logic.
|
|
8
|
-
function waitKind(task) {
|
|
9
|
-
if (task.state !== "waiting") return "";
|
|
10
|
-
const reason = String(task.wait_reason || "");
|
|
11
|
-
if (/执行能力|调整.*约定|仍未兑现/.test(reason)) return "adjust";
|
|
12
|
-
if (/选定|想具体|明确.*内容/.test(reason)) return "specify";
|
|
13
|
-
return "condition";
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function mountTime(app, life) {
|
|
17
|
-
const time = life.mind.time;
|
|
18
|
-
app.get(
|
|
19
|
-
"/api/mind/time/agenda",
|
|
20
|
-
wrap((req, res) => res.json(time.agenda.view(life.now()))),
|
|
21
|
-
);
|
|
22
|
-
app.post(
|
|
23
|
-
"/api/mind/time/plan",
|
|
24
|
-
wrap((req, res) => res.json(life.planner.request())),
|
|
25
|
-
);
|
|
26
|
-
app.get(
|
|
27
|
-
"/api/mind/time/care",
|
|
28
|
-
wrap((req, res) => res.json(life.ownDay.status())),
|
|
29
|
-
);
|
|
30
|
-
app.post(
|
|
31
|
-
"/api/mind/time/care",
|
|
32
|
-
wrap((req, res) => {
|
|
33
|
-
life.ownDay.request();
|
|
34
|
-
res.json(life.ownDay.status());
|
|
35
|
-
}),
|
|
36
|
-
);
|
|
37
|
-
app.get(
|
|
38
|
-
"/api/mind/time/search",
|
|
39
|
-
wrap((req, res) => {
|
|
40
|
-
if (
|
|
41
|
-
req.query.provider &&
|
|
42
|
-
!["tavily", "brave"].includes(req.query.provider)
|
|
43
|
-
)
|
|
44
|
-
throw Error("搜索提供方无效");
|
|
45
|
-
res.json(time.search.public(req.query.provider));
|
|
46
|
-
}),
|
|
47
|
-
);
|
|
48
|
-
app.patch(
|
|
49
|
-
"/api/mind/time/search",
|
|
50
|
-
wrap((req, res) => res.json(time.search.save(req.body))),
|
|
51
|
-
);
|
|
52
|
-
app.post(
|
|
53
|
-
"/api/mind/time/search/test",
|
|
54
|
-
wrap(async (req, res) => {
|
|
55
|
-
res.json(await time.search.test(req.body));
|
|
56
|
-
}),
|
|
57
|
-
);
|
|
58
|
-
app.get(
|
|
59
|
-
"/api/mind/time/projects/:id/sources",
|
|
60
|
-
wrap((req, res) => res.json(time.search.sources(req.params.id))),
|
|
61
|
-
);
|
|
62
|
-
app.get(
|
|
63
|
-
"/api/mind/time/sources/:id",
|
|
64
|
-
wrap((req, res) =>
|
|
65
|
-
res.json(
|
|
66
|
-
life.db
|
|
67
|
-
.prepare("SELECT * FROM mind_time_sources WHERE id=?")
|
|
68
|
-
.get(req.params.id) || null,
|
|
69
|
-
),
|
|
70
|
-
),
|
|
71
|
-
);
|
|
72
|
-
app.get(
|
|
73
|
-
"/api/mind/time/experiences",
|
|
74
|
-
wrap((req, res) => res.json(experiences(life.db, req.query))),
|
|
75
|
-
);
|
|
76
|
-
app.get(
|
|
77
|
-
"/api/mind/time/game-mode",
|
|
78
|
-
wrap((req, res) =>
|
|
79
|
-
res.json({
|
|
80
|
-
mode: "reference",
|
|
81
|
-
label: "正在玩",
|
|
82
|
-
realEnabled: false,
|
|
83
|
-
realStatus: "开发中",
|
|
84
|
-
}),
|
|
85
|
-
),
|
|
86
|
-
);
|
|
87
|
-
app.get(
|
|
88
|
-
"/api/mind/time/projects",
|
|
89
|
-
wrap((req, res) => res.json(time.works.projects(req.query))),
|
|
90
|
-
);
|
|
91
|
-
app.get(
|
|
92
|
-
"/api/mind/time/projects/:id",
|
|
93
|
-
wrap((req, res) => res.json(time.works.project(req.params.id))),
|
|
94
|
-
);
|
|
95
|
-
app.post(
|
|
96
|
-
"/api/mind/time/projects/:id/suggest",
|
|
97
|
-
wrap((req, res) => res.json(time.works.suggest(req.params.id, req.body))),
|
|
98
|
-
);
|
|
99
|
-
app.get(
|
|
100
|
-
"/api/mind/time/works",
|
|
101
|
-
wrap((req, res) => res.json(time.works.list(req.query))),
|
|
102
|
-
);
|
|
103
|
-
app.get(
|
|
104
|
-
"/api/mind/time/works/:id",
|
|
105
|
-
wrap((req, res) =>
|
|
106
|
-
res.json(time.works.get(req.params.id, req.query.version)),
|
|
107
|
-
),
|
|
108
|
-
);
|
|
109
|
-
app.get(
|
|
110
|
-
"/api/mind/time/works/:id/export",
|
|
111
|
-
wrap((req, res) => {
|
|
112
|
-
const work = time.works.get(req.params.id, req.query.version);
|
|
113
|
-
if (!work) throw Error("作品不存在");
|
|
114
|
-
res
|
|
115
|
-
.type("text/plain")
|
|
116
|
-
.attachment("luckytri-work.txt")
|
|
117
|
-
.send(work.title + "\n\n" + work.content);
|
|
118
|
-
}),
|
|
119
|
-
);
|
|
120
|
-
app.get(
|
|
121
|
-
"/api/mind/time/shares",
|
|
122
|
-
wrap((req, res) => res.json(time.sharing.list())),
|
|
123
|
-
);
|
|
124
|
-
app.get(
|
|
125
|
-
"/api/mind/time",
|
|
126
|
-
wrap((req, res) => {
|
|
127
|
-
time.tasks.sync(life.now());
|
|
128
|
-
res.json({
|
|
129
|
-
...time.view(),
|
|
130
|
-
today: time.today(),
|
|
131
|
-
agenda: time.agenda.view(life.now()),
|
|
132
|
-
care: life.ownDay.status(),
|
|
133
|
-
next: time.tasks
|
|
134
|
-
.ready()
|
|
135
|
-
.slice(0, 5)
|
|
136
|
-
.map((t) => ({
|
|
137
|
-
id: t.id,
|
|
138
|
-
title: t.title,
|
|
139
|
-
state: t.state,
|
|
140
|
-
why: t.why,
|
|
141
|
-
due_at: t.due_at,
|
|
142
|
-
priority: t.priority,
|
|
143
|
-
})),
|
|
144
|
-
settings: time.settings(),
|
|
145
|
-
events: time.events({ limit: 20 }),
|
|
146
|
-
affect: life.mind.affect.state(life.now()),
|
|
147
|
-
counts: life.db
|
|
148
|
-
.prepare(
|
|
149
|
-
"SELECT state,COUNT(*) count FROM mind_time_tasks WHERE json_extract(checkpoint,'$.mergedInto') IS NULL GROUP BY state",
|
|
150
|
-
)
|
|
151
|
-
.all(),
|
|
152
|
-
});
|
|
153
|
-
}),
|
|
154
|
-
);
|
|
155
|
-
app.get(
|
|
156
|
-
"/api/mind/time/tasks",
|
|
157
|
-
wrap((req, res) => {
|
|
158
|
-
const names = displayNames(life.db, life.now());
|
|
159
|
-
res.json(
|
|
160
|
-
(req.query.id
|
|
161
|
-
? [time.tasks.present(time.tasks.get(String(req.query.id)))].filter(
|
|
162
|
-
Boolean,
|
|
163
|
-
)
|
|
164
|
-
: time.tasks.list(req.query)
|
|
165
|
-
).map((task) => ({
|
|
166
|
-
...task,
|
|
167
|
-
person: task.subject
|
|
168
|
-
? names.get(String(task.subject)) || "相关的人"
|
|
169
|
-
: null,
|
|
170
|
-
waitKind: waitKind(task),
|
|
171
|
-
elapsedMs: time.elapsed(task.id),
|
|
172
|
-
})),
|
|
173
|
-
);
|
|
174
|
-
}),
|
|
175
|
-
);
|
|
176
|
-
app.get(
|
|
177
|
-
"/api/mind/time/tasks/:id",
|
|
178
|
-
wrap((req, res) => res.json(time.tasks.get(req.params.id))),
|
|
179
|
-
);
|
|
180
|
-
app.post(
|
|
181
|
-
"/api/mind/time/tasks/:id/control",
|
|
182
|
-
wrap((req, res) => {
|
|
183
|
-
const input = { ...req.body };
|
|
184
|
-
if (typeof input.readyAt === "string") {
|
|
185
|
-
input.readyAt = zonedTime(input.readyAt, life.mind.timeZone());
|
|
186
|
-
if (input.readyAt === null)
|
|
187
|
-
throw Error("开始时间格式应为 YYYY-MM-DD HH:mm");
|
|
188
|
-
}
|
|
189
|
-
res.json(time.tasks.control(req.params.id, input));
|
|
190
|
-
}),
|
|
191
|
-
);
|
|
192
|
-
app.put(
|
|
193
|
-
"/api/mind/time/settings",
|
|
194
|
-
wrap((req, res) => res.json(time.save(req.body))),
|
|
195
|
-
);
|
|
196
|
-
app.get(
|
|
197
|
-
"/api/mind/time/events",
|
|
198
|
-
wrap((req, res) => res.json(time.events(req.query))),
|
|
199
|
-
);
|
|
200
|
-
}
|
|
1
|
+
import { wrap } from "../../http.js";
|
|
2
|
+
import { displayNames } from "../../studio/display-names.js";
|
|
3
|
+
import { zonedTime } from "../util.js";
|
|
4
|
+
import { experiences } from "./experiences.js";
|
|
5
|
+
|
|
6
|
+
// What a waiting task is waiting for, as a code the page can rely on in any
|
|
7
|
+
// language. The wording of `wait_reason` is for people, not for logic.
|
|
8
|
+
function waitKind(task) {
|
|
9
|
+
if (task.state !== "waiting") return "";
|
|
10
|
+
const reason = String(task.wait_reason || "");
|
|
11
|
+
if (/执行能力|调整.*约定|仍未兑现/.test(reason)) return "adjust";
|
|
12
|
+
if (/选定|想具体|明确.*内容/.test(reason)) return "specify";
|
|
13
|
+
return "condition";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function mountTime(app, life) {
|
|
17
|
+
const time = life.mind.time;
|
|
18
|
+
app.get(
|
|
19
|
+
"/api/mind/time/agenda",
|
|
20
|
+
wrap((req, res) => res.json(time.agenda.view(life.now()))),
|
|
21
|
+
);
|
|
22
|
+
app.post(
|
|
23
|
+
"/api/mind/time/plan",
|
|
24
|
+
wrap((req, res) => res.json(life.planner.request())),
|
|
25
|
+
);
|
|
26
|
+
app.get(
|
|
27
|
+
"/api/mind/time/care",
|
|
28
|
+
wrap((req, res) => res.json(life.ownDay.status())),
|
|
29
|
+
);
|
|
30
|
+
app.post(
|
|
31
|
+
"/api/mind/time/care",
|
|
32
|
+
wrap((req, res) => {
|
|
33
|
+
life.ownDay.request();
|
|
34
|
+
res.json(life.ownDay.status());
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
app.get(
|
|
38
|
+
"/api/mind/time/search",
|
|
39
|
+
wrap((req, res) => {
|
|
40
|
+
if (
|
|
41
|
+
req.query.provider &&
|
|
42
|
+
!["tavily", "brave"].includes(req.query.provider)
|
|
43
|
+
)
|
|
44
|
+
throw Error("搜索提供方无效");
|
|
45
|
+
res.json(time.search.public(req.query.provider));
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
app.patch(
|
|
49
|
+
"/api/mind/time/search",
|
|
50
|
+
wrap((req, res) => res.json(time.search.save(req.body))),
|
|
51
|
+
);
|
|
52
|
+
app.post(
|
|
53
|
+
"/api/mind/time/search/test",
|
|
54
|
+
wrap(async (req, res) => {
|
|
55
|
+
res.json(await time.search.test(req.body));
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
app.get(
|
|
59
|
+
"/api/mind/time/projects/:id/sources",
|
|
60
|
+
wrap((req, res) => res.json(time.search.sources(req.params.id))),
|
|
61
|
+
);
|
|
62
|
+
app.get(
|
|
63
|
+
"/api/mind/time/sources/:id",
|
|
64
|
+
wrap((req, res) =>
|
|
65
|
+
res.json(
|
|
66
|
+
life.db
|
|
67
|
+
.prepare("SELECT * FROM mind_time_sources WHERE id=?")
|
|
68
|
+
.get(req.params.id) || null,
|
|
69
|
+
),
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
app.get(
|
|
73
|
+
"/api/mind/time/experiences",
|
|
74
|
+
wrap((req, res) => res.json(experiences(life.db, req.query))),
|
|
75
|
+
);
|
|
76
|
+
app.get(
|
|
77
|
+
"/api/mind/time/game-mode",
|
|
78
|
+
wrap((req, res) =>
|
|
79
|
+
res.json({
|
|
80
|
+
mode: "reference",
|
|
81
|
+
label: "正在玩",
|
|
82
|
+
realEnabled: false,
|
|
83
|
+
realStatus: "开发中",
|
|
84
|
+
}),
|
|
85
|
+
),
|
|
86
|
+
);
|
|
87
|
+
app.get(
|
|
88
|
+
"/api/mind/time/projects",
|
|
89
|
+
wrap((req, res) => res.json(time.works.projects(req.query))),
|
|
90
|
+
);
|
|
91
|
+
app.get(
|
|
92
|
+
"/api/mind/time/projects/:id",
|
|
93
|
+
wrap((req, res) => res.json(time.works.project(req.params.id))),
|
|
94
|
+
);
|
|
95
|
+
app.post(
|
|
96
|
+
"/api/mind/time/projects/:id/suggest",
|
|
97
|
+
wrap((req, res) => res.json(time.works.suggest(req.params.id, req.body))),
|
|
98
|
+
);
|
|
99
|
+
app.get(
|
|
100
|
+
"/api/mind/time/works",
|
|
101
|
+
wrap((req, res) => res.json(time.works.list(req.query))),
|
|
102
|
+
);
|
|
103
|
+
app.get(
|
|
104
|
+
"/api/mind/time/works/:id",
|
|
105
|
+
wrap((req, res) =>
|
|
106
|
+
res.json(time.works.get(req.params.id, req.query.version)),
|
|
107
|
+
),
|
|
108
|
+
);
|
|
109
|
+
app.get(
|
|
110
|
+
"/api/mind/time/works/:id/export",
|
|
111
|
+
wrap((req, res) => {
|
|
112
|
+
const work = time.works.get(req.params.id, req.query.version);
|
|
113
|
+
if (!work) throw Error("作品不存在");
|
|
114
|
+
res
|
|
115
|
+
.type("text/plain")
|
|
116
|
+
.attachment("luckytri-work.txt")
|
|
117
|
+
.send(work.title + "\n\n" + work.content);
|
|
118
|
+
}),
|
|
119
|
+
);
|
|
120
|
+
app.get(
|
|
121
|
+
"/api/mind/time/shares",
|
|
122
|
+
wrap((req, res) => res.json(time.sharing.list())),
|
|
123
|
+
);
|
|
124
|
+
app.get(
|
|
125
|
+
"/api/mind/time",
|
|
126
|
+
wrap((req, res) => {
|
|
127
|
+
time.tasks.sync(life.now());
|
|
128
|
+
res.json({
|
|
129
|
+
...time.view(),
|
|
130
|
+
today: time.today(),
|
|
131
|
+
agenda: time.agenda.view(life.now()),
|
|
132
|
+
care: life.ownDay.status(),
|
|
133
|
+
next: time.tasks
|
|
134
|
+
.ready()
|
|
135
|
+
.slice(0, 5)
|
|
136
|
+
.map((t) => ({
|
|
137
|
+
id: t.id,
|
|
138
|
+
title: t.title,
|
|
139
|
+
state: t.state,
|
|
140
|
+
why: t.why,
|
|
141
|
+
due_at: t.due_at,
|
|
142
|
+
priority: t.priority,
|
|
143
|
+
})),
|
|
144
|
+
settings: time.settings(),
|
|
145
|
+
events: time.events({ limit: 20 }),
|
|
146
|
+
affect: life.mind.affect.state(life.now()),
|
|
147
|
+
counts: life.db
|
|
148
|
+
.prepare(
|
|
149
|
+
"SELECT state,COUNT(*) count FROM mind_time_tasks WHERE json_extract(checkpoint,'$.mergedInto') IS NULL GROUP BY state",
|
|
150
|
+
)
|
|
151
|
+
.all(),
|
|
152
|
+
});
|
|
153
|
+
}),
|
|
154
|
+
);
|
|
155
|
+
app.get(
|
|
156
|
+
"/api/mind/time/tasks",
|
|
157
|
+
wrap((req, res) => {
|
|
158
|
+
const names = displayNames(life.db, life.now());
|
|
159
|
+
res.json(
|
|
160
|
+
(req.query.id
|
|
161
|
+
? [time.tasks.present(time.tasks.get(String(req.query.id)))].filter(
|
|
162
|
+
Boolean,
|
|
163
|
+
)
|
|
164
|
+
: time.tasks.list(req.query)
|
|
165
|
+
).map((task) => ({
|
|
166
|
+
...task,
|
|
167
|
+
person: task.subject
|
|
168
|
+
? names.get(String(task.subject)) || "相关的人"
|
|
169
|
+
: null,
|
|
170
|
+
waitKind: waitKind(task),
|
|
171
|
+
elapsedMs: time.elapsed(task.id),
|
|
172
|
+
})),
|
|
173
|
+
);
|
|
174
|
+
}),
|
|
175
|
+
);
|
|
176
|
+
app.get(
|
|
177
|
+
"/api/mind/time/tasks/:id",
|
|
178
|
+
wrap((req, res) => res.json(time.tasks.get(req.params.id))),
|
|
179
|
+
);
|
|
180
|
+
app.post(
|
|
181
|
+
"/api/mind/time/tasks/:id/control",
|
|
182
|
+
wrap((req, res) => {
|
|
183
|
+
const input = { ...req.body };
|
|
184
|
+
if (typeof input.readyAt === "string") {
|
|
185
|
+
input.readyAt = zonedTime(input.readyAt, life.mind.timeZone());
|
|
186
|
+
if (input.readyAt === null)
|
|
187
|
+
throw Error("开始时间格式应为 YYYY-MM-DD HH:mm");
|
|
188
|
+
}
|
|
189
|
+
res.json(time.tasks.control(req.params.id, input));
|
|
190
|
+
}),
|
|
191
|
+
);
|
|
192
|
+
app.put(
|
|
193
|
+
"/api/mind/time/settings",
|
|
194
|
+
wrap((req, res) => res.json(time.save(req.body))),
|
|
195
|
+
);
|
|
196
|
+
app.get(
|
|
197
|
+
"/api/mind/time/events",
|
|
198
|
+
wrap((req, res) => res.json(time.events(req.query))),
|
|
199
|
+
);
|
|
200
|
+
}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
// One main activity can coexist with one conversation, never two conversations
|
|
2
|
-
// or two activity steps. Waiting on another room does not invent another self.
|
|
3
|
-
export class Attention {
|
|
4
|
-
constructor() {
|
|
5
|
-
this.tail = Promise.resolve();
|
|
6
|
-
this.activityBusy = false;
|
|
7
|
-
this.closed = false;
|
|
8
|
-
}
|
|
9
|
-
async chat(run) {
|
|
10
|
-
const previous = this.tail;
|
|
11
|
-
let release;
|
|
12
|
-
this.tail = new Promise((resolve) => {
|
|
13
|
-
release = resolve;
|
|
14
|
-
});
|
|
15
|
-
await previous;
|
|
16
|
-
try {
|
|
17
|
-
if (!this.closed) return await run();
|
|
18
|
-
} finally {
|
|
19
|
-
release();
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
async activity(run) {
|
|
23
|
-
if (this.activityBusy || this.closed) return null;
|
|
24
|
-
this.activityBusy = true;
|
|
25
|
-
try {
|
|
26
|
-
return await run();
|
|
27
|
-
} finally {
|
|
28
|
-
this.activityBusy = false;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
close() {
|
|
32
|
-
this.closed = true;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
1
|
+
// One main activity can coexist with one conversation, never two conversations
|
|
2
|
+
// or two activity steps. Waiting on another room does not invent another self.
|
|
3
|
+
export class Attention {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.tail = Promise.resolve();
|
|
6
|
+
this.activityBusy = false;
|
|
7
|
+
this.closed = false;
|
|
8
|
+
}
|
|
9
|
+
async chat(run) {
|
|
10
|
+
const previous = this.tail;
|
|
11
|
+
let release;
|
|
12
|
+
this.tail = new Promise((resolve) => {
|
|
13
|
+
release = resolve;
|
|
14
|
+
});
|
|
15
|
+
await previous;
|
|
16
|
+
try {
|
|
17
|
+
if (!this.closed) return await run();
|
|
18
|
+
} finally {
|
|
19
|
+
release();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async activity(run) {
|
|
23
|
+
if (this.activityBusy || this.closed) return null;
|
|
24
|
+
this.activityBusy = true;
|
|
25
|
+
try {
|
|
26
|
+
return await run();
|
|
27
|
+
} finally {
|
|
28
|
+
this.activityBusy = false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
close() {
|
|
32
|
+
this.closed = true;
|
|
33
|
+
}
|
|
34
|
+
}
|