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
|
@@ -1,323 +1,330 @@
|
|
|
1
|
-
import { localClock } from "../../core/conversation-cues.js";
|
|
2
|
-
import { agoLabel, elapsedLabel } from "../clock.js";
|
|
3
|
-
import { isPrivateSession } from "../memory.js";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
.
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
.
|
|
33
|
-
.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
});
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
.
|
|
200
|
-
.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
...(
|
|
238
|
-
|
|
239
|
-
...(
|
|
240
|
-
? {
|
|
241
|
-
: {}),
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
now,
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
))
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
.
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
1
|
+
import { localClock } from "../../core/conversation-cues.js";
|
|
2
|
+
import { agoLabel, elapsedLabel } from "../clock.js";
|
|
3
|
+
import { isPrivateSession } from "../memory.js";
|
|
4
|
+
import { relationshipHistory } from "../relationship-context.js";
|
|
5
|
+
import {
|
|
6
|
+
DAY,
|
|
7
|
+
evidence,
|
|
8
|
+
hasCredential,
|
|
9
|
+
messageSeqs,
|
|
10
|
+
parse,
|
|
11
|
+
text,
|
|
12
|
+
} from "../util.js";
|
|
13
|
+
const LIVE = "COALESCE(json_extract(payload,'$.simulated'),0)=0";
|
|
14
|
+
|
|
15
|
+
// Owns this part of the lifecycle; the facade keeps the shared runtime state.
|
|
16
|
+
export class LifeContext {
|
|
17
|
+
constructor(owner) {
|
|
18
|
+
this.owner = owner;
|
|
19
|
+
}
|
|
20
|
+
experiences(since, now, { limit = 5, rows = 24 } = {}) {
|
|
21
|
+
const names = new Map(this.owner.living().map((s) => [s.id, s]));
|
|
22
|
+
const aside = new Set(
|
|
23
|
+
this.owner.db
|
|
24
|
+
.prepare("SELECT seq FROM mind_unlived")
|
|
25
|
+
.all()
|
|
26
|
+
.map((row) => row.seq),
|
|
27
|
+
);
|
|
28
|
+
const active = this.owner.db
|
|
29
|
+
.prepare(
|
|
30
|
+
`SELECT session_id, MAX(time) t, COUNT(*) n FROM core_events WHERE seq>? AND time<=? AND seq NOT IN (SELECT seq FROM mind_unlived) AND ${LIVE} GROUP BY session_id ORDER BY t DESC`,
|
|
31
|
+
)
|
|
32
|
+
.all(since, now)
|
|
33
|
+
.filter((r) => names.has(r.session_id))
|
|
34
|
+
.slice(0, limit);
|
|
35
|
+
return active
|
|
36
|
+
.map((r) => {
|
|
37
|
+
const events = this.owner.repo
|
|
38
|
+
.eventsAfter(r.session_id, since, { simulated: false })
|
|
39
|
+
.filter((m) => m.time <= now && !aside.has(m.seq));
|
|
40
|
+
if (!events.length) return null;
|
|
41
|
+
const stage = this.owner.db
|
|
42
|
+
.prepare(
|
|
43
|
+
"SELECT data FROM core_stages WHERE session_id=? ORDER BY last_seq DESC LIMIT 1",
|
|
44
|
+
)
|
|
45
|
+
.get(r.session_id);
|
|
46
|
+
const selfName = this.owner.mind.nature.current(now).name;
|
|
47
|
+
const earlier = stage ? text(parse(stage.data, {}).summary, 400) : "";
|
|
48
|
+
return {
|
|
49
|
+
session: r.session_id,
|
|
50
|
+
name: names.get(r.session_id).name,
|
|
51
|
+
kind: names.get(r.session_id).kind,
|
|
52
|
+
lastActive: elapsedLabel(r.t, now, this.owner.mind.timeZone()),
|
|
53
|
+
newEvents: r.n,
|
|
54
|
+
...(earlier ? { earlier } : {}),
|
|
55
|
+
messages: events.slice(-rows).map((m) => ({
|
|
56
|
+
seq: m.seq,
|
|
57
|
+
...(m.artifact ? { artifact: m.artifact } : {}),
|
|
58
|
+
name: m.role === "assistant" ? selfName : m.name,
|
|
59
|
+
...(m.role === "assistant" ? { self: true } : { userId: m.userId }),
|
|
60
|
+
time: localClock(m.time, this.owner.mind.timeZone()).local.slice(5),
|
|
61
|
+
text: text(m.text, 160),
|
|
62
|
+
})),
|
|
63
|
+
};
|
|
64
|
+
})
|
|
65
|
+
.filter(Boolean);
|
|
66
|
+
}
|
|
67
|
+
feedbackSince(since) {
|
|
68
|
+
const labels = {
|
|
69
|
+
too_long: "太长了",
|
|
70
|
+
too_formal: "太端着",
|
|
71
|
+
too_meme: "梗太多",
|
|
72
|
+
natural: "挺自然",
|
|
73
|
+
};
|
|
74
|
+
return this.owner.db
|
|
75
|
+
.prepare(
|
|
76
|
+
"SELECT f.decision_id id,f.tag,d.reply,d.session_id FROM reply_feedback f JOIN decisions d ON d.id=f.decision_id WHERE f.time>? AND d.is_demo=0 ORDER BY f.time DESC LIMIT 6",
|
|
77
|
+
)
|
|
78
|
+
.all(since)
|
|
79
|
+
.map((r) => ({
|
|
80
|
+
ref: `f:${r.id}`,
|
|
81
|
+
session: r.session_id,
|
|
82
|
+
said: text(r.reply, 60),
|
|
83
|
+
felt: labels[r.tag] || r.tag,
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
selfView(now, { open = false, room } = {}) {
|
|
87
|
+
const relationships = this.owner.mind.relationships.context({
|
|
88
|
+
now,
|
|
89
|
+
open,
|
|
90
|
+
room,
|
|
91
|
+
limit: 8,
|
|
92
|
+
});
|
|
93
|
+
return this.owner.mind.self
|
|
94
|
+
.active({ before: now, now, limit: 16 })
|
|
95
|
+
.filter((t) =>
|
|
96
|
+
room !== undefined
|
|
97
|
+
? this.owner.mind.meetings.stays(t, room)
|
|
98
|
+
: !open || this.owner.mind.meetings.stays(t, ""),
|
|
99
|
+
)
|
|
100
|
+
.map((t) => ({
|
|
101
|
+
thread: t.thread,
|
|
102
|
+
kind: t.kind,
|
|
103
|
+
content: relationshipHistory(t.content, t.created, relationships),
|
|
104
|
+
strength: t.strength,
|
|
105
|
+
...(t.status === "emerging" ? { emerging: true } : {}),
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
livingForView(now, { since = 0, open = false } = {}) {
|
|
109
|
+
const thread = this.owner.mind.self.living({
|
|
110
|
+
before: now,
|
|
111
|
+
now,
|
|
112
|
+
...(open ? { room: "" } : {}),
|
|
113
|
+
});
|
|
114
|
+
const rows = this.owner.mind.meetings.traces({
|
|
115
|
+
...(open ? { session: "" } : {}),
|
|
116
|
+
before: now,
|
|
117
|
+
since,
|
|
118
|
+
inclusive: true,
|
|
119
|
+
limit: 3,
|
|
120
|
+
});
|
|
121
|
+
const also = rows
|
|
122
|
+
.filter((row) => !thread || row.thread !== thread.thread)
|
|
123
|
+
.map((row) => ({
|
|
124
|
+
content: text(row.content, 80),
|
|
125
|
+
touched: row.touched,
|
|
126
|
+
}));
|
|
127
|
+
if (!thread && !also.length) return null;
|
|
128
|
+
if (!thread) return { also };
|
|
129
|
+
const mine = rows.find((row) => row.thread === thread.thread);
|
|
130
|
+
return {
|
|
131
|
+
thread: thread.thread,
|
|
132
|
+
content: text(thread.content, 80),
|
|
133
|
+
...(mine?.touched ? { touched: mine.touched } : {}),
|
|
134
|
+
...(also.length ? { also } : {}),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
faceView(experiences, now) {
|
|
138
|
+
const seen = new Map();
|
|
139
|
+
const notes = (face) =>
|
|
140
|
+
(face?.notes || []).slice(-6).map((note) => ({
|
|
141
|
+
id: note.id,
|
|
142
|
+
kind: note.kind,
|
|
143
|
+
content: text(note.content, 160),
|
|
144
|
+
why: text(note.why, 80),
|
|
145
|
+
}));
|
|
146
|
+
for (const experience of experiences) {
|
|
147
|
+
const face = this.owner.mind.faces.current(experience.session, now);
|
|
148
|
+
seen.set(experience.session, {
|
|
149
|
+
session: experience.session,
|
|
150
|
+
name: experience.name,
|
|
151
|
+
notes: notes(face),
|
|
152
|
+
freshSources: experience.messages.slice(-4).map((m) => m.seq),
|
|
153
|
+
});
|
|
154
|
+
if (seen.size >= 6) break;
|
|
155
|
+
}
|
|
156
|
+
for (const face of this.owner.mind.faces.all(now)) {
|
|
157
|
+
if (seen.has(face.session_id)) continue;
|
|
158
|
+
seen.set(face.session_id, {
|
|
159
|
+
session: face.session_id,
|
|
160
|
+
notes: notes(face),
|
|
161
|
+
});
|
|
162
|
+
if (seen.size >= 6) break;
|
|
163
|
+
}
|
|
164
|
+
return [...seen.values()];
|
|
165
|
+
}
|
|
166
|
+
identityMeetings(now, sessions) {
|
|
167
|
+
const allowed = new Set(sessions);
|
|
168
|
+
const used = new Map();
|
|
169
|
+
const out = [];
|
|
170
|
+
for (const row of this.owner.db
|
|
171
|
+
.prepare(
|
|
172
|
+
`SELECT id,created,session_id,exchange,discretion FROM mind_meetings m
|
|
173
|
+
WHERE created>? AND created<? AND choice!='silent' AND exchange IS NOT NULL
|
|
174
|
+
AND id NOT IN (SELECT target_id FROM mind_revocations WHERE target_kind='meeting')
|
|
175
|
+
ORDER BY created DESC LIMIT 500`,
|
|
176
|
+
)
|
|
177
|
+
.all(now - 7 * DAY, now)) {
|
|
178
|
+
if (!allowed.has(row.session_id) || (used.get(row.session_id) || 0) >= 4)
|
|
179
|
+
continue;
|
|
180
|
+
const exchange = parse(row.exchange, null);
|
|
181
|
+
if (!exchange?.they?.length || !exchange.iSaid?.length) continue;
|
|
182
|
+
const they = exchange.they
|
|
183
|
+
.filter((m) => !hasCredential(m.text))
|
|
184
|
+
.slice(-2)
|
|
185
|
+
.map((m) => ({ name: m.name, text: text(m.text, 120) }));
|
|
186
|
+
const said = exchange.iSaid
|
|
187
|
+
.filter((line) => !hasCredential(line))
|
|
188
|
+
.slice(0, 2)
|
|
189
|
+
.map((line) => text(line, 120));
|
|
190
|
+
if (!they.length || !said.length) continue;
|
|
191
|
+
out.push({
|
|
192
|
+
ref: `g:${row.id}`,
|
|
193
|
+
session: row.session_id,
|
|
194
|
+
when: elapsedLabel(row.created, now, this.owner.mind.timeZone()),
|
|
195
|
+
private: row.discretion !== "open",
|
|
196
|
+
they,
|
|
197
|
+
iSaid: said,
|
|
198
|
+
});
|
|
199
|
+
used.set(row.session_id, (used.get(row.session_id) || 0) + 1);
|
|
200
|
+
if (out.length >= 12) break;
|
|
201
|
+
}
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
fadingView(now) {
|
|
205
|
+
return this.owner.mind.self
|
|
206
|
+
.fading({ before: now, now, limit: 3 })
|
|
207
|
+
.map((t) => ({
|
|
208
|
+
thread: t.thread,
|
|
209
|
+
kind: t.kind,
|
|
210
|
+
content: t.content,
|
|
211
|
+
lastTouched: elapsedLabel(t.created, now, this.owner.mind.timeZone()),
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
214
|
+
bondCards(list, now, { talk = false } = {}) {
|
|
215
|
+
const living = new Set(this.owner.living().map((s) => s.id));
|
|
216
|
+
const lastSaid = this.owner.db.prepare(
|
|
217
|
+
"SELECT sources FROM mind_bond_events WHERE subject_kind='person' AND subject_id=? AND created<=? AND sources!='[]' ORDER BY created DESC LIMIT 1",
|
|
218
|
+
);
|
|
219
|
+
const event = this.owner.db.prepare(
|
|
220
|
+
"SELECT seq,session_id,payload FROM core_events WHERE seq=?",
|
|
221
|
+
);
|
|
222
|
+
return list.map((p) => {
|
|
223
|
+
p =
|
|
224
|
+
this.owner.mind.bonds.person(p.userId, now, {
|
|
225
|
+
room: "group:__open__",
|
|
226
|
+
}) || p;
|
|
227
|
+
const seq = evidence(parse(lastSaid.get(p.userId, now)?.sources, []))
|
|
228
|
+
.filter((s) => s.startsWith("m:"))
|
|
229
|
+
.map((s) => Number(s.slice(2)))
|
|
230
|
+
.at(-1);
|
|
231
|
+
const row = seq ? event.get(seq) : null;
|
|
232
|
+
const said = row ? parse(row.payload, {}) : null;
|
|
233
|
+
return {
|
|
234
|
+
userId: p.userId,
|
|
235
|
+
name: p.name,
|
|
236
|
+
feel: p.feel,
|
|
237
|
+
...(p.relationship ? { relationship: p.relationship } : {}),
|
|
238
|
+
lastSeen: agoLabel(now - p.seenAt),
|
|
239
|
+
...(talk && p.lastTalkedAt
|
|
240
|
+
? { lastTalked: agoLabel(now - p.lastTalkedAt) }
|
|
241
|
+
: {}),
|
|
242
|
+
...(p.impression ? { impression: p.impression } : {}),
|
|
243
|
+
sessions: p.sessions.filter((s) => living.has(s)),
|
|
244
|
+
...(row ? { ref: `m:${row.seq}` } : {}),
|
|
245
|
+
// What was said in a private chat stays out of her solitary notes.
|
|
246
|
+
...(said && !isPrivateSession(row.session_id)
|
|
247
|
+
? { lastSaid: text(said.text, 80) }
|
|
248
|
+
: {}),
|
|
249
|
+
};
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
missingView(now) {
|
|
253
|
+
return this.owner.bondCards(
|
|
254
|
+
this.owner.mind.bonds.missing({ now, limit: 3 }),
|
|
255
|
+
now,
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
quietView(now) {
|
|
259
|
+
return this.owner.bondCards(
|
|
260
|
+
this.owner.mind.bonds.quiet({ now, limit: 3 }),
|
|
261
|
+
now,
|
|
262
|
+
{
|
|
263
|
+
talk: true,
|
|
264
|
+
},
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
sourcePlaces(sources) {
|
|
268
|
+
const refs = evidence(sources);
|
|
269
|
+
const seqs = messageSeqs(refs);
|
|
270
|
+
const sessions = seqs.length
|
|
271
|
+
? this.owner.db
|
|
272
|
+
.prepare(
|
|
273
|
+
`SELECT DISTINCT session_id FROM core_events WHERE seq IN (${seqs.map(() => "?").join(",")})`,
|
|
274
|
+
)
|
|
275
|
+
.all(...seqs)
|
|
276
|
+
.map((r) => r.session_id)
|
|
277
|
+
: [];
|
|
278
|
+
for (const ref of refs.filter((r) => r.startsWith("t:"))) {
|
|
279
|
+
const owned = this.owner.mind.thoughts.get(ref.slice(2))?.sessions || [];
|
|
280
|
+
const publicOnes = owned.filter((id) => !isPrivateSession(id));
|
|
281
|
+
sessions.push(...(publicOnes.length ? publicOnes : owned));
|
|
282
|
+
}
|
|
283
|
+
for (const row of this.owner.mind.meetings.places(
|
|
284
|
+
refs.filter((r) => r.startsWith("g:")),
|
|
285
|
+
))
|
|
286
|
+
sessions.push(row.session_id);
|
|
287
|
+
return [...new Set(sessions)];
|
|
288
|
+
}
|
|
289
|
+
placeOf(sources) {
|
|
290
|
+
const sessions = this.owner.sourcePlaces(sources);
|
|
291
|
+
const hidden = sessions.find((s) => isPrivateSession(s));
|
|
292
|
+
if (hidden) return { session: hidden, discretion: "private" };
|
|
293
|
+
return {
|
|
294
|
+
session: sessions.length === 1 ? sessions[0] : null,
|
|
295
|
+
discretion: "open",
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
peopleIn(experiences, now, { open = false } = {}) {
|
|
299
|
+
const ids = [
|
|
300
|
+
...new Set(
|
|
301
|
+
experiences
|
|
302
|
+
.flatMap((e) => e.messages.map((m) => m.userId).filter(Boolean))
|
|
303
|
+
.concat(
|
|
304
|
+
this.owner.mind.relationships
|
|
305
|
+
.list(now)
|
|
306
|
+
.filter((r) => !open || r.discretion === "open")
|
|
307
|
+
.map((r) => r.subject_id),
|
|
308
|
+
),
|
|
309
|
+
),
|
|
310
|
+
].slice(0, 8);
|
|
311
|
+
// A diary page can be quoted in other rooms, so it only receives notes
|
|
312
|
+
// that were already fit to say in the open. Solitude still sees the rest.
|
|
313
|
+
return ids
|
|
314
|
+
.map((id) =>
|
|
315
|
+
this.owner.mind.bonds.person(
|
|
316
|
+
id,
|
|
317
|
+
now,
|
|
318
|
+
open ? { room: "group:__open__" } : {},
|
|
319
|
+
),
|
|
320
|
+
)
|
|
321
|
+
.filter(Boolean)
|
|
322
|
+
.map((p) => ({
|
|
323
|
+
userId: p.userId,
|
|
324
|
+
name: p.name,
|
|
325
|
+
feel: p.feel,
|
|
326
|
+
...(p.impression ? { impression: p.impression } : {}),
|
|
327
|
+
...(p.relationship ? { relationship: p.relationship } : {}),
|
|
328
|
+
}));
|
|
329
|
+
}
|
|
330
|
+
}
|