luckytri 1.0.6 → 1.0.7
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/docs/en/CHANGELOG.md +25 -16
- package/docs/en/chat-style.md +28 -9
- package/docs/en/guide.md +5 -5
- package/docs/en/her-life.md +2 -2
- package/docs/en/webui.md +1 -1
- package/docs/zh/CHANGELOG.md +25 -16
- package/docs/zh/chat-style.md +30 -9
- package/docs/zh/guide.md +5 -5
- package/docs/zh/her-life.md +2 -2
- package/docs/zh/webui.md +1 -1
- package/package.json +1 -1
- package/public/app/assets/{ChatsPage-DCYMkJ91.js → ChatsPage-CshdtTzV.js} +2 -2
- package/public/app/assets/ChatsPage-DfyPCS9N.css +1 -0
- package/public/app/assets/{Empty-CLyZkxR5.js → Empty-C7yzOBzy.js} +1 -1
- package/public/app/assets/{Empty-DIobYG3x.css → Empty-DmUB2-Bk.css} +1 -1
- package/public/app/assets/{Field-BpaRwLI_.js → Field-BjFv4Rfn.js} +1 -1
- package/public/app/assets/HeartPage-Bft9wZp5.css +1 -0
- package/public/app/assets/{HeartPage-BIOMTiwr.js → HeartPage-eqo6ru16.js} +1 -1
- package/public/app/assets/LifePage-BUi5euBF.css +1 -0
- package/public/app/assets/{LifePage-BCgM4JkR.js → LifePage-CN8GE5NK.js} +1 -1
- package/public/app/assets/{MemoryPage-vShvRqMt.js → MemoryPage-CCpMN4Wg.js} +1 -1
- package/public/app/assets/MemoryPage-cZvXfkXb.css +1 -0
- package/public/app/assets/{NaturePage-Cy9ptr4G.js → NaturePage-C0JqdBTR.js} +2 -2
- package/public/app/assets/NaturePage-CHkpb5NK.css +1 -0
- package/public/app/assets/PeoplePage-BTU0H1pM.css +1 -0
- package/public/app/assets/{PeoplePage-CUZekB2E.js → PeoplePage-BXGBbO4u.js} +1 -1
- package/public/app/assets/{PluginsPage-1RM4rmJP.js → PluginsPage-Dksp5AV5.js} +1 -1
- package/public/app/assets/{SystemPage-BI2CB5Ig.css → SystemPage-BenIyTvk.css} +1 -1
- package/public/app/assets/{SystemPage-BeT5TmIV.js → SystemPage-Cd7aa8eE.js} +1 -1
- package/public/app/assets/TimePage-BOms_n4I.css +1 -0
- package/public/app/assets/{TimePage-taTmPMM8.js → TimePage-Bs_zImb4.js} +2 -2
- package/public/app/assets/{index-DY5AM0Hz.css → index-BHZcHUMh.css} +1 -1
- package/public/app/assets/{index-DdYwC5ZU.js → index-CyRtYxP3.js} +3 -3
- package/public/app/assets/{knowledge-DJmfu2KN.js → knowledge-BJOIyuJo.js} +1 -1
- package/public/app/assets/{media-BEtnE0Gv.js → media-Bwtx8blz.js} +1 -1
- package/public/app/assets/{mind-Dtiw0-QK.js → mind-DtTVrW6Z.js} +1 -1
- package/public/app/index.html +5 -6
- package/public/guide.en.html +3 -3
- package/public/guide.html +3 -3
- package/scripts/import-data.js +128 -128
- package/scripts/proxy-config.js +167 -167
- 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 +365 -325
- package/server/core/conversation-grounding.js +178 -0
- package/server/core/conversation-manager.js +87 -87
- package/server/core/dialogue-context.js +52 -0
- 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 +324 -269
- package/server/core/reply-delivery.js +472 -404
- package/server/core/reply-target-resolver.js +50 -50
- package/server/core/response-generator.js +58 -50
- package/server/core/response-validator.js +30 -27
- 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/core/turn.js +42 -8
- package/server/http.js +18 -18
- package/server/i18n/decisions.js +209 -209
- package/server/i18n/index.js +144 -144
- package/server/i18n/labels.js +0 -5
- 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/context-selection.js +16 -4
- 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 +68 -60
- package/server/mind/initiative.js +338 -338
- package/server/mind/life/activities.js +21 -21
- package/server/mind/life/context.js +330 -330
- package/server/mind/life/growth.js +261 -261
- 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 -71
- package/server/mind/relationships.js +390 -390
- package/server/mind/salience.js +201 -201
- package/server/mind/schema.js +567 -567
- package/server/mind/self.js +496 -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/games.js +7 -3
- package/server/mind/time/index.js +3 -0
- package/server/mind/time/model-material.js +77 -77
- package/server/mind/time/presentation.js +35 -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 +438 -432
- package/server/mind/traits.js +191 -191
- package/server/mind/view.js +43 -6
- package/server/runtime/installation.js +116 -116
- 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-CFMVozoG.css +0 -1
- package/public/app/assets/HeartPage-C-2jvgzF.css +0 -1
- package/public/app/assets/LifePage-CG1OHbRK.css +0 -1
- package/public/app/assets/MemoryPage-C_Bu4rfb.css +0 -1
- package/public/app/assets/NaturePage-CPZlImT0.css +0 -1
- package/public/app/assets/PeoplePage-3RRUITDz.css +0 -1
- package/public/app/assets/TimePage-C-guwPk2.css +0 -1
|
@@ -1,330 +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 { 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
|
-
}
|
|
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
|
+
}
|