luckytri 1.0.8 → 1.1.0
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/README.en.md +1 -1
- package/README.md +1 -1
- package/docs/en/CHANGELOG.md +44 -24
- package/docs/en/architecture.md +4 -0
- package/docs/en/cognition.md +34 -0
- package/docs/en/guide.md +8 -6
- package/docs/zh/CHANGELOG.md +44 -24
- package/docs/zh/architecture.md +4 -0
- package/docs/zh/cognition.md +34 -0
- package/docs/zh/guide.md +8 -6
- package/package.json +112 -112
- package/public/app/assets/ChatsPage-DH4ZPRXB.js +3 -0
- package/public/app/assets/{Empty-C7yzOBzy.js → Empty-DRsHeX-L.js} +1 -1
- package/public/app/assets/Field-BfIUcaNa.js +1 -0
- package/public/app/assets/HeartPage-BxgSUJJ_.js +1 -0
- package/public/app/assets/LifePage-CAKr8h_q.js +1 -0
- package/public/app/assets/MemoryPage-CFq8L_TC.js +1 -0
- package/public/app/assets/NaturePage-BU1iDno3.js +3 -0
- package/public/app/assets/PeoplePage-C6i_nAfr.js +1 -0
- package/public/app/assets/PluginsPage-DRV8lzk3.js +2 -0
- package/public/app/assets/SystemPage-21AlQBiC.js +1 -0
- package/public/app/assets/SystemPage-CMcuUdLm.css +1 -0
- package/public/app/assets/TimePage-DUzjLnZV.js +3 -0
- package/public/app/assets/index-WAvrlAcO.js +4 -0
- package/public/app/assets/{knowledge-BJOIyuJo.js → knowledge-V_blbx9R.js} +1 -1
- package/public/app/assets/media-C7j5HqxK.js +1 -0
- package/public/app/assets/{mind-DtTVrW6Z.js → mind-BBAstMqH.js} +1 -1
- package/public/app/index.html +3 -3
- package/public/guide.en.html +13 -5
- package/public/guide.html +12 -5
- package/public/tutorial.en.md +3 -1
- package/public/tutorial.md +3 -1
- package/server/core/backoff.js +123 -0
- package/server/core/context-builder.js +307 -288
- package/server/core/contribution-check.js +50 -0
- package/server/core/conversation-cues.js +377 -385
- package/server/core/conversation-grounding.js +547 -304
- package/server/core/dialogue-context.js +247 -244
- package/server/core/dialogue-contract.js +33 -9
- package/server/core/embedding.js +246 -0
- package/server/core/expression-strategy.js +90 -0
- package/server/core/initiative-context.js +88 -68
- package/server/core/model-json.js +223 -190
- package/server/core/model-manager.js +256 -56
- package/server/core/model-presets.js +1045 -900
- package/server/core/orchestrator.js +41 -3
- package/server/core/persona-manager.js +364 -359
- package/server/core/reader-check.js +166 -62
- package/server/core/reply-delivery.js +688 -537
- package/server/core/repository.js +36 -0
- package/server/core/response-generator.js +101 -92
- package/server/core/response-validator.js +18 -3
- package/server/core/retired-prompts.js +53 -51
- package/server/core/time-expressions.js +143 -0
- package/server/core/turn-processor.js +175 -5
- package/server/core/turn.js +299 -44
- package/server/core/understanding.js +85 -0
- package/server/core/working-memory.js +149 -0
- package/server/i18n/decisions.js +225 -209
- package/server/i18n/errors.js +14 -0
- package/server/i18n/models.js +120 -111
- package/server/knowledge/api.js +362 -342
- package/server/knowledge/embedding-profile.js +158 -114
- package/server/knowledge/manager.js +6 -1
- package/server/mind/api.js +68 -0
- package/server/mind/continuity.js +634 -562
- package/server/mind/day-planner.js +52 -3
- package/server/mind/episodes.js +242 -0
- package/server/mind/expression-grounding.js +24 -21
- package/server/mind/index.js +13 -2
- package/server/mind/initiative.js +356 -338
- package/server/mind/life/index.js +6 -0
- package/server/mind/meetings.js +1112 -1069
- package/server/mind/memory.js +1091 -888
- package/server/mind/recall/index.js +776 -0
- package/server/mind/recall/schema.js +132 -0
- package/server/mind/recall/sources.js +220 -0
- package/server/mind/recall/store.js +368 -0
- package/server/mind/salience.js +202 -201
- package/server/mind/schema.js +568 -567
- package/server/mind/self.js +537 -496
- package/server/mind/time/activity-recall.js +65 -0
- package/server/mind/time/index.js +6 -2
- package/server/mind/time/tasks.js +36 -10
- package/server/mind/time/works.js +528 -527
- package/server/mind/view.js +63 -17
- package/server/storage/archive.js +1 -1
- package/public/app/assets/ChatsPage-CshdtTzV.js +0 -3
- package/public/app/assets/Field-BjFv4Rfn.js +0 -1
- package/public/app/assets/HeartPage-eqo6ru16.js +0 -1
- package/public/app/assets/LifePage-CN8GE5NK.js +0 -1
- package/public/app/assets/MemoryPage-CCpMN4Wg.js +0 -1
- package/public/app/assets/NaturePage-C0JqdBTR.js +0 -3
- package/public/app/assets/PeoplePage-BXGBbO4u.js +0 -1
- package/public/app/assets/PluginsPage-Dksp5AV5.js +0 -2
- package/public/app/assets/SystemPage-BenIyTvk.css +0 -1
- package/public/app/assets/SystemPage-Cd7aa8eE.js +0 -1
- package/public/app/assets/TimePage-Bs_zImb4.js +0 -3
- package/public/app/assets/index-CyRtYxP3.js +0 -4
- package/public/app/assets/media-Bwtx8blz.js +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { parseSessionKey } from "../channels/session-key.js";
|
|
2
2
|
import { initiativeContext, initiativeSnapshot } from "./initiative-context.js";
|
|
3
3
|
import { withFallback } from "./model-manager.js";
|
|
4
|
+
import { activityRecallCue } from "../mind/time/activity-recall.js";
|
|
4
5
|
import { replyPrompt, prompts } from "./persona-manager.js";
|
|
5
6
|
import { buildContext, perceive } from "./context-builder.js";
|
|
6
7
|
import {
|
|
@@ -15,6 +16,10 @@ import {
|
|
|
15
16
|
visionWindow,
|
|
16
17
|
} from "./vision-manager.js";
|
|
17
18
|
import { normalizeTurn, takeTurn } from "./turn.js";
|
|
19
|
+
import { RECOLLECTION_NOTE } from "../mind/recall/index.js";
|
|
20
|
+
import { workingMemory } from "./working-memory.js";
|
|
21
|
+
import { expressionStrategy } from "./expression-strategy.js";
|
|
22
|
+
import { localClock } from "./conversation-cues.js";
|
|
18
23
|
import {
|
|
19
24
|
initiativeAudience,
|
|
20
25
|
originSummary,
|
|
@@ -50,6 +55,86 @@ export class TurnProcessor {
|
|
|
50
55
|
constructor(owner) {
|
|
51
56
|
this.owner = owner;
|
|
52
57
|
}
|
|
58
|
+
// What this conversation is holding now, and older lines of it that the
|
|
59
|
+
// current words reach by meaning when vectors cover the room's messages.
|
|
60
|
+
async addWorkingMemory(session, snapshot, batch, now, { replay, zone }) {
|
|
61
|
+
const fresh = new Set(snapshot.batchIds || []);
|
|
62
|
+
const before = Math.min(...(snapshot.batchIds || [Infinity]));
|
|
63
|
+
const earlier = (snapshot.messages || []).filter(
|
|
64
|
+
(m) => m.role === "assistant" && !fresh.has(m.id) && m.id < before,
|
|
65
|
+
);
|
|
66
|
+
const previousTalk =
|
|
67
|
+
earlier.at(-1)?.time ??
|
|
68
|
+
this.owner.repo.db
|
|
69
|
+
.prepare(
|
|
70
|
+
"SELECT MAX(time) t FROM core_events WHERE session_id=? AND role='assistant' AND seq<? AND COALESCE(json_extract(payload,'$.simulated'),0)=0",
|
|
71
|
+
)
|
|
72
|
+
.get(
|
|
73
|
+
session,
|
|
74
|
+
Number.isFinite(before) ? before : Number.MAX_SAFE_INTEGER,
|
|
75
|
+
)?.t ??
|
|
76
|
+
null;
|
|
77
|
+
const working = workingMemory({
|
|
78
|
+
messages: snapshot.messages || [],
|
|
79
|
+
batchIds: snapshot.batchIds || [],
|
|
80
|
+
now,
|
|
81
|
+
zone,
|
|
82
|
+
previousTalk,
|
|
83
|
+
});
|
|
84
|
+
const ownLines = this.owner.repo.db
|
|
85
|
+
.prepare(
|
|
86
|
+
"SELECT payload FROM core_events WHERE session_id=? AND role='assistant' AND seq<? AND COALESCE(json_extract(payload,'$.simulated'),0)=0 ORDER BY seq DESC LIMIT 12",
|
|
87
|
+
)
|
|
88
|
+
.all(session, Number.isFinite(before) ? before : Number.MAX_SAFE_INTEGER)
|
|
89
|
+
.map((row) => JSON.parse(row.payload).text || "")
|
|
90
|
+
.reverse();
|
|
91
|
+
const style = expressionStrategy({
|
|
92
|
+
ownLines,
|
|
93
|
+
theirLines: (snapshot.messages || [])
|
|
94
|
+
.filter((m) => fresh.has(m.id) && m.role === "user")
|
|
95
|
+
.map((m) => m.text || ""),
|
|
96
|
+
});
|
|
97
|
+
if (working || style)
|
|
98
|
+
snapshot.working = { ...(working || {}), ...(style ? { style } : {}) };
|
|
99
|
+
if (replay || !snapshot.historyStart) return;
|
|
100
|
+
const kept = new Set((snapshot.messages || []).map((m) => m.id));
|
|
101
|
+
const older = await this.owner.mind.recall.olderMessages(
|
|
102
|
+
session,
|
|
103
|
+
batch,
|
|
104
|
+
now,
|
|
105
|
+
{ before: snapshot.historyStart, exclude: kept },
|
|
106
|
+
);
|
|
107
|
+
if (!older) return;
|
|
108
|
+
if (!older.length) {
|
|
109
|
+
delete snapshot.recalled;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const rows = this.owner.repo.db
|
|
113
|
+
.prepare(
|
|
114
|
+
`SELECT seq,time,role,payload FROM core_events WHERE seq IN (${older.map(() => "?").join(",")}) ORDER BY seq`,
|
|
115
|
+
)
|
|
116
|
+
.all(...older);
|
|
117
|
+
snapshot.recalled = {
|
|
118
|
+
note: "同一个聊天里更早、和现在说的事意思相关的原文,不是本轮新消息。",
|
|
119
|
+
messages: rows.map((row) => {
|
|
120
|
+
const message = JSON.parse(row.payload);
|
|
121
|
+
return {
|
|
122
|
+
id: row.seq,
|
|
123
|
+
speaker: row.role === "assistant" ? "self" : message.userId,
|
|
124
|
+
name:
|
|
125
|
+
row.role === "assistant"
|
|
126
|
+
? undefined
|
|
127
|
+
: this.owner.mind.bonds.name(message.userId) || message.name,
|
|
128
|
+
role: row.role,
|
|
129
|
+
localTime: localClock(row.time, zone).local,
|
|
130
|
+
text:
|
|
131
|
+
String(message.text || "").length > 300
|
|
132
|
+
? `${String(message.text).slice(0, 300)}…`
|
|
133
|
+
: message.text,
|
|
134
|
+
};
|
|
135
|
+
}),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
53
138
|
async process(
|
|
54
139
|
session,
|
|
55
140
|
batch,
|
|
@@ -104,6 +189,15 @@ export class TurnProcessor {
|
|
|
104
189
|
session,
|
|
105
190
|
replay ? "replay" : preview ? "preview" : simulatedTurn ? "demo" : "live",
|
|
106
191
|
);
|
|
192
|
+
// Where the wait before the first model call goes, phase by phase.
|
|
193
|
+
let phaseAt = performance.now();
|
|
194
|
+
const lap = (name) => {
|
|
195
|
+
const at = performance.now();
|
|
196
|
+
if (trace.timings)
|
|
197
|
+
trace.timings[name] =
|
|
198
|
+
(trace.timings[name] || 0) + Math.round(at - phaseAt);
|
|
199
|
+
phaseAt = at;
|
|
200
|
+
};
|
|
107
201
|
const policy = this.owner.policy(preview?.viewSession || session);
|
|
108
202
|
const state = this.owner.sessionState(session);
|
|
109
203
|
const clearEpoch = this.owner.clearEpoch.get(session) || 0;
|
|
@@ -172,8 +266,10 @@ export class TurnProcessor {
|
|
|
172
266
|
batch = gate.rows.length ? gate.rows : batch;
|
|
173
267
|
watermark = Math.max(watermark, batch.at(-1).seq);
|
|
174
268
|
}
|
|
269
|
+
lap("gate");
|
|
175
270
|
if (!replay && !preview)
|
|
176
271
|
await this.owner.restoreQuotes(session, batch, trace);
|
|
272
|
+
lap("quotes");
|
|
177
273
|
const prompt = prompts(this.owner.repo);
|
|
178
274
|
const now = clock();
|
|
179
275
|
const hasKey =
|
|
@@ -195,15 +291,23 @@ export class TurnProcessor {
|
|
|
195
291
|
this.owner.models,
|
|
196
292
|
this.owner.fallbackFor(policy, model, trace),
|
|
197
293
|
);
|
|
198
|
-
resolved
|
|
294
|
+
resolved = perceive(
|
|
199
295
|
this.owner.repo,
|
|
200
296
|
session,
|
|
201
297
|
watermark,
|
|
202
298
|
eventMode,
|
|
203
299
|
nature.name,
|
|
300
|
+
{ resolved, sentBefore: live ? now : 0 },
|
|
204
301
|
);
|
|
205
302
|
const batchIds = batch.map((m) => m.seq);
|
|
206
303
|
const window = resolved.filter((m) => !m.referenceOnly).slice(-60);
|
|
304
|
+
const cues = batch.map((m) => ({
|
|
305
|
+
id: m.seq,
|
|
306
|
+
role: m.role,
|
|
307
|
+
speaker: m.userId,
|
|
308
|
+
userId: m.userId,
|
|
309
|
+
text: m.text || "",
|
|
310
|
+
}));
|
|
207
311
|
// The speakers in this batch are the people whose history matters now.
|
|
208
312
|
// Pulling everyone from a long room window made unrelated plans compete
|
|
209
313
|
// with the exchange actually taking place.
|
|
@@ -219,21 +323,24 @@ export class TurnProcessor {
|
|
|
219
323
|
/* An unparseable destination has no person to infer. */
|
|
220
324
|
}
|
|
221
325
|
}
|
|
326
|
+
lap("perceive");
|
|
222
327
|
// Replays exclude mutable memory so later corrections cannot leak into
|
|
223
328
|
// the past; her inner state is folded as of the replayed moment.
|
|
224
329
|
const memories =
|
|
225
330
|
policy.memory && !replay && !ownInitiative
|
|
226
|
-
? this.owner.mind.
|
|
331
|
+
? await this.owner.mind.recall.memories(session, batch, now, {
|
|
227
332
|
people,
|
|
228
333
|
touch: live,
|
|
229
334
|
forSpeech: true,
|
|
230
335
|
})
|
|
231
336
|
: [];
|
|
337
|
+
lap("memory");
|
|
232
338
|
const knowledge = ownInitiative
|
|
233
339
|
? []
|
|
234
340
|
: replay
|
|
235
341
|
? this.owner.knowledge.retrieve(session, batch, now)
|
|
236
342
|
: await this.owner.knowledge.retrieveWithEmbed(session, batch, now);
|
|
343
|
+
lap("knowledge");
|
|
237
344
|
const summaryView =
|
|
238
345
|
!ownInitiative && !simulatedTurn && policy.compaction !== false
|
|
239
346
|
? this.owner.compactor.forPrompt(session, {
|
|
@@ -261,19 +368,54 @@ export class TurnProcessor {
|
|
|
261
368
|
"未核实的阶段线索,不是人物事实;冲突时以原文和记忆为准",
|
|
262
369
|
}))
|
|
263
370
|
: [];
|
|
371
|
+
lap("summaries");
|
|
372
|
+
const meant =
|
|
373
|
+
!replay && !ownInitiative
|
|
374
|
+
? await this.owner.mind.recall.relatedOwn(session, batch, now)
|
|
375
|
+
: null;
|
|
264
376
|
const view = this.owner.mind.view({
|
|
265
377
|
session: preview?.viewSession || session,
|
|
266
378
|
kind: privateChat ? "private" : "group",
|
|
267
379
|
people,
|
|
268
380
|
cue: batch.map((m) => ({
|
|
269
|
-
|
|
270
|
-
userId: m.userId,
|
|
271
|
-
text: m.text || "",
|
|
381
|
+
...cues.find((row) => row.id === m.seq),
|
|
272
382
|
relation: resolved.find((line) => line.id === m.seq)?.relation,
|
|
273
383
|
mentioned: m.mentioned === true,
|
|
274
384
|
})),
|
|
275
385
|
now,
|
|
386
|
+
meant,
|
|
387
|
+
});
|
|
388
|
+
const botSpeakers = new Set(
|
|
389
|
+
(view.inner?.relationships?.known || [])
|
|
390
|
+
.filter((relationship) => relationship.kind === "bot")
|
|
391
|
+
.map((relationship) => String(relationship.subjectId)),
|
|
392
|
+
);
|
|
393
|
+
const activityCue = activityRecallCue(cues, window, {
|
|
394
|
+
excludedSpeakers: botSpeakers,
|
|
276
395
|
});
|
|
396
|
+
if (activityCue !== cues)
|
|
397
|
+
view.inner.currentLife = this.owner.mind.meetings.memo(() =>
|
|
398
|
+
this.owner.mind.time.view({
|
|
399
|
+
session: preview?.viewSession || session,
|
|
400
|
+
now,
|
|
401
|
+
cue: cues,
|
|
402
|
+
activityCue,
|
|
403
|
+
}),
|
|
404
|
+
);
|
|
405
|
+
if (policy.memory && !replay && !ownInitiative) {
|
|
406
|
+
const recollections = await this.owner.mind.recall.recollect(
|
|
407
|
+
session,
|
|
408
|
+
batch,
|
|
409
|
+
now,
|
|
410
|
+
{ people },
|
|
411
|
+
);
|
|
412
|
+
if (recollections.length)
|
|
413
|
+
view.inner.recollections = {
|
|
414
|
+
note: RECOLLECTION_NOTE,
|
|
415
|
+
items: recollections,
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
lap("view");
|
|
277
419
|
const snapshot = ownInitiative
|
|
278
420
|
? initiativeSnapshot(session, window, nature, now, policy.timeZone)
|
|
279
421
|
: buildContext(
|
|
@@ -303,6 +445,7 @@ export class TurnProcessor {
|
|
|
303
445
|
snapshot.self = view.self;
|
|
304
446
|
snapshot.inner = view.inner;
|
|
305
447
|
}
|
|
448
|
+
lap("context");
|
|
306
449
|
const visionModel = model.vision
|
|
307
450
|
? model
|
|
308
451
|
: this.owner.fallbackFor(null, model).find((item) => item.vision) ||
|
|
@@ -341,6 +484,13 @@ export class TurnProcessor {
|
|
|
341
484
|
let show = planned.show.slice();
|
|
342
485
|
if (!replay)
|
|
343
486
|
snapshot.topics = this.owner.topics.recent(session, watermark, now);
|
|
487
|
+
if (!ownInitiative) {
|
|
488
|
+
await this.addWorkingMemory(session, snapshot, batch, now, {
|
|
489
|
+
replay,
|
|
490
|
+
zone: policy.timeZone,
|
|
491
|
+
});
|
|
492
|
+
lap("working");
|
|
493
|
+
}
|
|
344
494
|
snapshot.unavailableImages = [
|
|
345
495
|
...media.unavailable,
|
|
346
496
|
...loaded.unavailable,
|
|
@@ -425,6 +575,7 @@ export class TurnProcessor {
|
|
|
425
575
|
if (offered.length) snapshot.canDo = offered;
|
|
426
576
|
}
|
|
427
577
|
const generationImages = model.vision ? show : [];
|
|
578
|
+
lap("vision");
|
|
428
579
|
if (!replay && !preview) {
|
|
429
580
|
const rounds = this.owner.repo.db
|
|
430
581
|
.prepare(
|
|
@@ -470,6 +621,7 @@ export class TurnProcessor {
|
|
|
470
621
|
);
|
|
471
622
|
return finish("stale", "读房间时又有新话,并入下一批");
|
|
472
623
|
}
|
|
624
|
+
lap("checks");
|
|
473
625
|
let turn;
|
|
474
626
|
try {
|
|
475
627
|
turn = normalizeTurn(
|
|
@@ -518,6 +670,24 @@ export class TurnProcessor {
|
|
|
518
670
|
}
|
|
519
671
|
trace.decision = turn;
|
|
520
672
|
if (live) this.owner.mind.time.adjust(turn, clock());
|
|
673
|
+
const reading = turn.understanding;
|
|
674
|
+
if (
|
|
675
|
+
live &&
|
|
676
|
+
reading?.messageIds?.length &&
|
|
677
|
+
(reading.tone || reading.stance)
|
|
678
|
+
) {
|
|
679
|
+
const keep = this.owner.repo.db.prepare(
|
|
680
|
+
"INSERT INTO core_message_cues(seq,tone,stance,trace_id,created) VALUES (?,?,?,?,?) ON CONFLICT(seq) DO UPDATE SET tone=excluded.tone,stance=excluded.stance,trace_id=excluded.trace_id",
|
|
681
|
+
);
|
|
682
|
+
for (const seq of reading.messageIds)
|
|
683
|
+
keep.run(
|
|
684
|
+
seq,
|
|
685
|
+
reading.tone || null,
|
|
686
|
+
reading.stance || null,
|
|
687
|
+
trace.id,
|
|
688
|
+
now,
|
|
689
|
+
);
|
|
690
|
+
}
|
|
521
691
|
trace.path = occasion?.type || (direct ? "direct" : "contextual");
|
|
522
692
|
const roomKind = privateChat ? "private" : "group";
|
|
523
693
|
let talkSettled = false;
|