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.
Files changed (155) hide show
  1. package/LICENSE +21 -21
  2. package/docs/en/CHANGELOG.md +25 -16
  3. package/docs/en/chat-style.md +28 -9
  4. package/docs/en/guide.md +5 -5
  5. package/docs/en/her-life.md +2 -2
  6. package/docs/en/webui.md +1 -1
  7. package/docs/zh/CHANGELOG.md +25 -16
  8. package/docs/zh/chat-style.md +30 -9
  9. package/docs/zh/guide.md +5 -5
  10. package/docs/zh/her-life.md +2 -2
  11. package/docs/zh/webui.md +1 -1
  12. package/package.json +1 -1
  13. package/public/app/assets/{ChatsPage-DCYMkJ91.js → ChatsPage-CshdtTzV.js} +2 -2
  14. package/public/app/assets/ChatsPage-DfyPCS9N.css +1 -0
  15. package/public/app/assets/{Empty-CLyZkxR5.js → Empty-C7yzOBzy.js} +1 -1
  16. package/public/app/assets/{Empty-DIobYG3x.css → Empty-DmUB2-Bk.css} +1 -1
  17. package/public/app/assets/{Field-BpaRwLI_.js → Field-BjFv4Rfn.js} +1 -1
  18. package/public/app/assets/HeartPage-Bft9wZp5.css +1 -0
  19. package/public/app/assets/{HeartPage-BIOMTiwr.js → HeartPage-eqo6ru16.js} +1 -1
  20. package/public/app/assets/LifePage-BUi5euBF.css +1 -0
  21. package/public/app/assets/{LifePage-BCgM4JkR.js → LifePage-CN8GE5NK.js} +1 -1
  22. package/public/app/assets/{MemoryPage-vShvRqMt.js → MemoryPage-CCpMN4Wg.js} +1 -1
  23. package/public/app/assets/MemoryPage-cZvXfkXb.css +1 -0
  24. package/public/app/assets/{NaturePage-Cy9ptr4G.js → NaturePage-C0JqdBTR.js} +2 -2
  25. package/public/app/assets/NaturePage-CHkpb5NK.css +1 -0
  26. package/public/app/assets/PeoplePage-BTU0H1pM.css +1 -0
  27. package/public/app/assets/{PeoplePage-CUZekB2E.js → PeoplePage-BXGBbO4u.js} +1 -1
  28. package/public/app/assets/{PluginsPage-1RM4rmJP.js → PluginsPage-Dksp5AV5.js} +1 -1
  29. package/public/app/assets/{SystemPage-BI2CB5Ig.css → SystemPage-BenIyTvk.css} +1 -1
  30. package/public/app/assets/{SystemPage-BeT5TmIV.js → SystemPage-Cd7aa8eE.js} +1 -1
  31. package/public/app/assets/TimePage-BOms_n4I.css +1 -0
  32. package/public/app/assets/{TimePage-taTmPMM8.js → TimePage-Bs_zImb4.js} +2 -2
  33. package/public/app/assets/{index-DY5AM0Hz.css → index-BHZcHUMh.css} +1 -1
  34. package/public/app/assets/{index-DdYwC5ZU.js → index-CyRtYxP3.js} +3 -3
  35. package/public/app/assets/{knowledge-DJmfu2KN.js → knowledge-BJOIyuJo.js} +1 -1
  36. package/public/app/assets/{media-BEtnE0Gv.js → media-Bwtx8blz.js} +1 -1
  37. package/public/app/assets/{mind-Dtiw0-QK.js → mind-DtTVrW6Z.js} +1 -1
  38. package/public/app/index.html +5 -6
  39. package/public/guide.en.html +3 -3
  40. package/public/guide.html +3 -3
  41. package/scripts/import-data.js +128 -128
  42. package/scripts/proxy-config.js +167 -167
  43. package/scripts/update-instance.js +201 -201
  44. package/server/channels/adapters.js +27 -27
  45. package/server/channels/onebot/adapter.js +288 -288
  46. package/server/channels/qqbot/adapter.js +253 -253
  47. package/server/channels/qqbot/api.js +199 -199
  48. package/server/channels/qqbot/credentials.js +11 -11
  49. package/server/channels/qqbot/gateway.js +274 -274
  50. package/server/channels/qqbot/index.js +389 -389
  51. package/server/channels/segments.js +40 -40
  52. package/server/channels/session-key.js +153 -153
  53. package/server/channels/state.js +42 -42
  54. package/server/core/api.js +564 -564
  55. package/server/core/context-builder.js +288 -288
  56. package/server/core/context-compactor.js +454 -454
  57. package/server/core/conversation-cues.js +365 -325
  58. package/server/core/conversation-grounding.js +178 -0
  59. package/server/core/conversation-manager.js +87 -87
  60. package/server/core/dialogue-context.js +52 -0
  61. package/server/core/feedback.js +8 -8
  62. package/server/core/group-style.js +72 -72
  63. package/server/core/initiative-context.js +66 -66
  64. package/server/core/input-budget.js +32 -32
  65. package/server/core/local-demo.js +98 -98
  66. package/server/core/message-manager.js +118 -118
  67. package/server/core/message-scheduler.js +78 -78
  68. package/server/core/model-json.js +190 -190
  69. package/server/core/model-presets.js +900 -900
  70. package/server/core/name-call.js +29 -29
  71. package/server/core/network.js +157 -157
  72. package/server/core/person-name.js +22 -22
  73. package/server/core/persona-manager.js +324 -269
  74. package/server/core/reply-delivery.js +472 -404
  75. package/server/core/reply-target-resolver.js +50 -50
  76. package/server/core/response-generator.js +58 -50
  77. package/server/core/response-validator.js +30 -27
  78. package/server/core/retired-prompts.js +51 -51
  79. package/server/core/sessions.js +109 -109
  80. package/server/core/speaker-names.js +92 -92
  81. package/server/core/topic-tracker.js +65 -65
  82. package/server/core/turn.js +42 -8
  83. package/server/http.js +18 -18
  84. package/server/i18n/decisions.js +209 -209
  85. package/server/i18n/index.js +144 -144
  86. package/server/i18n/labels.js +0 -5
  87. package/server/i18n/models.js +111 -111
  88. package/server/knowledge/api.js +342 -342
  89. package/server/knowledge/embedding-profile.js +114 -114
  90. package/server/knowledge/index.js +13 -13
  91. package/server/knowledge/retrieval.js +93 -93
  92. package/server/knowledge/schema.js +158 -158
  93. package/server/knowledge/vector-index.js +90 -90
  94. package/server/mind/affect.js +265 -265
  95. package/server/mind/attention.js +200 -200
  96. package/server/mind/bonds.js +565 -565
  97. package/server/mind/clock.js +83 -83
  98. package/server/mind/context-selection.js +16 -4
  99. package/server/mind/continuity.js +562 -562
  100. package/server/mind/conversation-origin.js +175 -175
  101. package/server/mind/days.js +210 -210
  102. package/server/mind/evidence-read.js +45 -45
  103. package/server/mind/faces.js +373 -373
  104. package/server/mind/guard.js +68 -60
  105. package/server/mind/initiative.js +338 -338
  106. package/server/mind/life/activities.js +21 -21
  107. package/server/mind/life/context.js +330 -330
  108. package/server/mind/life/growth.js +261 -261
  109. package/server/mind/life/presence.js +305 -305
  110. package/server/mind/meetings.js +1069 -1069
  111. package/server/mind/memory-policy.js +48 -48
  112. package/server/mind/memory.js +888 -888
  113. package/server/mind/nature.js +358 -358
  114. package/server/mind/novelty.js +19 -19
  115. package/server/mind/periods.js +118 -118
  116. package/server/mind/reading.js +120 -120
  117. package/server/mind/relationship-context.js +71 -71
  118. package/server/mind/relationships.js +390 -390
  119. package/server/mind/salience.js +201 -201
  120. package/server/mind/schema.js +567 -567
  121. package/server/mind/self.js +496 -484
  122. package/server/mind/thoughts.js +274 -274
  123. package/server/mind/time/agenda.js +242 -242
  124. package/server/mind/time/api.js +200 -200
  125. package/server/mind/time/attention.js +34 -34
  126. package/server/mind/time/delivery-links.js +130 -130
  127. package/server/mind/time/games.js +7 -3
  128. package/server/mind/time/index.js +3 -0
  129. package/server/mind/time/model-material.js +77 -77
  130. package/server/mind/time/presentation.js +35 -51
  131. package/server/mind/time/schedule.js +83 -83
  132. package/server/mind/time/schema.js +84 -84
  133. package/server/mind/time/search.js +383 -383
  134. package/server/mind/time/sharing.js +472 -472
  135. package/server/mind/time/task-links.js +311 -311
  136. package/server/mind/time/works.js +438 -432
  137. package/server/mind/traits.js +191 -191
  138. package/server/mind/view.js +43 -6
  139. package/server/runtime/installation.js +116 -116
  140. package/server/runtime/update-manager.js +140 -140
  141. package/server/storage/data-package.js +298 -298
  142. package/server/storage/data-transfer-api.js +50 -50
  143. package/server/storage/data-transfer-worker.js +18 -18
  144. package/server/storage/data-transfer.js +416 -416
  145. package/server/studio/display-names.js +139 -139
  146. package/server/studio/management.js +102 -102
  147. package/server/studio/updates.js +144 -144
  148. package/server/version.js +10 -10
  149. package/public/app/assets/ChatsPage-CFMVozoG.css +0 -1
  150. package/public/app/assets/HeartPage-C-2jvgzF.css +0 -1
  151. package/public/app/assets/LifePage-CG1OHbRK.css +0 -1
  152. package/public/app/assets/MemoryPage-C_Bu4rfb.css +0 -1
  153. package/public/app/assets/NaturePage-CPZlImT0.css +0 -1
  154. package/public/app/assets/PeoplePage-3RRUITDz.css +0 -1
  155. package/public/app/assets/TimePage-C-guwPk2.css +0 -1
@@ -1,175 +1,175 @@
1
- import {
2
- parseSessionKey,
3
- scopedSessionAliases,
4
- } from "../channels/session-key.js";
5
- import { evidence, parse } from "./util.js";
6
-
7
- // A public memory may be recalled everywhere. That does not turn everyone
8
- // into a participant. Retellings retain the original speakers and add no one.
9
- export function conversationOrigin(db, sources, before = Date.now()) {
10
- const queue = evidence(sources),
11
- seen = new Set(),
12
- rooms = new Map();
13
- let incomplete = false;
14
- const event = db.prepare(
15
- "SELECT seq,session_id,time,role,payload FROM core_events WHERE seq=? AND time<=? AND COALESCE(json_extract(payload,'$.simulated'),0)=0 AND seq NOT IN (SELECT seq FROM mind_unlived)",
16
- );
17
- const take = (row) => {
18
- if (!row) return;
19
- let identity;
20
- try {
21
- identity = parseSessionKey(row.session_id);
22
- } catch {
23
- return;
24
- }
25
- if (!rooms.has(row.session_id))
26
- rooms.set(row.session_id, {
27
- sessionId: row.session_id,
28
- channel: identity.channel,
29
- kind: identity.kind,
30
- people: new Map(),
31
- });
32
- const room = rooms.get(row.session_id),
33
- payload = parse(row.payload, {});
34
- if (row.role === "user" && payload.userId && payload.userId !== "bot")
35
- room.people.set(String(payload.userId), {
36
- id: String(payload.userId),
37
- name: payload.name || "这位参与者",
38
- });
39
- if (row.role === "assistant") {
40
- // Confirmed replies credit their actual addressees, never nearby members.
41
- for (const seq of (Array.isArray(payload.replyTargetIds)
42
- ? payload.replyTargetIds
43
- : []
44
- ).slice(0, 24)) {
45
- const target = event.get(Number(seq), Math.min(before, row.time));
46
- if (!target) incomplete = true;
47
- if (target?.role === "user" && target.session_id === row.session_id)
48
- take(target);
49
- }
50
- }
51
- };
52
- for (let cursor = 0; cursor < queue.length; cursor++) {
53
- if (seen.size >= 512)
54
- return { kind: "conversation", rooms: [], incomplete: true };
55
- const ref = queue[cursor];
56
- if (seen.has(ref)) continue;
57
- seen.add(ref);
58
- const kind = ref[0],
59
- id = ref.slice(2);
60
- if (kind === "m") {
61
- const row = event.get(Number(id), before);
62
- if (!row) incomplete = true;
63
- take(row);
64
- continue;
65
- }
66
- // Reading and her own executed activities are hers to introduce. Their
67
- // original motivation does not make the finished work someone else's chat.
68
- let rows = [];
69
- if (kind === "t")
70
- rows = db
71
- .prepare(
72
- "SELECT sources,parent_id FROM mind_thoughts WHERE id=? AND created<=? AND hidden=0",
73
- )
74
- .all(id, before);
75
- else if (kind === "s")
76
- rows = db
77
- .prepare(
78
- "SELECT sources FROM mind_self WHERE thread=? AND created<=? AND thread NOT IN (SELECT target_id FROM mind_revocations WHERE target_kind='self')",
79
- )
80
- .all(id, before);
81
- else if (kind === "g")
82
- rows = db
83
- .prepare(
84
- "SELECT sources FROM mind_meetings WHERE id=? AND created<=? AND id NOT IN (SELECT target_id FROM mind_revocations WHERE target_kind='meeting')",
85
- )
86
- .all(id, before);
87
- else if (kind === "a")
88
- rows = db
89
- .prepare(
90
- "SELECT sources FROM mind_anticipations WHERE id=? AND created<=?",
91
- )
92
- .all(id, before);
93
- else if (kind === "d")
94
- rows = db
95
- .prepare("SELECT sources FROM mind_diary WHERE day=? AND created<=?")
96
- .all(id, before);
97
- if (["t", "s", "g", "a", "d"].includes(kind) && !rows.length)
98
- incomplete = true;
99
- for (const row of rows) {
100
- queue.push(...evidence(parse(row.sources, [])));
101
- if (row.parent_id) queue.push("t:" + row.parent_id);
102
- }
103
- }
104
- return {
105
- kind: rooms.size ? "conversation" : "own",
106
- rooms: [...rooms.values()].map((room) => ({
107
- ...room,
108
- people: [...room.people.values()],
109
- })),
110
- incomplete,
111
- };
112
- }
113
-
114
- export function originSummary(origin) {
115
- return {
116
- ...origin,
117
- rooms: origin.rooms
118
- .slice(0, 6)
119
- .map((room) => ({ ...room, people: room.people.slice(0, 8) })),
120
- };
121
- }
122
-
123
- export function initiativeAudience(mind, thought, session, now = Date.now()) {
124
- const sources = evidence(thought?.sources || []),
125
- before = Math.min(now, thought?.created || now);
126
- const origin = conversationOrigin(mind.db, sources, before);
127
- if (!mind.meetings.stays({ sources }, session, before))
128
- return {
129
- allowed: false,
130
- shared: false,
131
- origin,
132
- reason: "这份想法含有其他会话的私下来源,不能在这里继续",
133
- };
134
- if (origin.incomplete)
135
- return {
136
- allowed: false,
137
- shared: false,
138
- origin,
139
- reason: "话题来源缺失、已撤销或过长,参与者尚未核实",
140
- };
141
- if (!origin.rooms.length)
142
- return { allowed: true, shared: false, origin, mode: "new_topic" };
143
- let destination;
144
- try {
145
- destination = parseSessionKey(session);
146
- } catch {
147
- return {
148
- allowed: false,
149
- shared: false,
150
- origin,
151
- reason: "主动交流对象不明确",
152
- };
153
- }
154
- const aliases = new Set(scopedSessionAliases(mind.db, session));
155
- const shared = origin.rooms.some(
156
- (room) =>
157
- room.channel === destination.channel &&
158
- (destination.kind === "private"
159
- ? room.people.some((person) => person.id === destination.nativeId) ||
160
- (room.kind === "private" && aliases.has(room.sessionId))
161
- : aliases.has(room.sessionId)),
162
- );
163
- return {
164
- allowed: true,
165
- shared,
166
- origin,
167
- mode: shared ? "continuation" : "new_topic",
168
- ...(!shared
169
- ? {
170
- guidance:
171
- "对方未参与原话题。由她判断是否值得分享、是否适合这个人;值得就自然开启新话题并给必要背景,不能当成之前共同聊过、共同项目或对方的约定。也可以选择不聊。",
172
- }
173
- : {}),
174
- };
175
- }
1
+ import {
2
+ parseSessionKey,
3
+ scopedSessionAliases,
4
+ } from "../channels/session-key.js";
5
+ import { evidence, parse } from "./util.js";
6
+
7
+ // A public memory may be recalled everywhere. That does not turn everyone
8
+ // into a participant. Retellings retain the original speakers and add no one.
9
+ export function conversationOrigin(db, sources, before = Date.now()) {
10
+ const queue = evidence(sources),
11
+ seen = new Set(),
12
+ rooms = new Map();
13
+ let incomplete = false;
14
+ const event = db.prepare(
15
+ "SELECT seq,session_id,time,role,payload FROM core_events WHERE seq=? AND time<=? AND COALESCE(json_extract(payload,'$.simulated'),0)=0 AND seq NOT IN (SELECT seq FROM mind_unlived)",
16
+ );
17
+ const take = (row) => {
18
+ if (!row) return;
19
+ let identity;
20
+ try {
21
+ identity = parseSessionKey(row.session_id);
22
+ } catch {
23
+ return;
24
+ }
25
+ if (!rooms.has(row.session_id))
26
+ rooms.set(row.session_id, {
27
+ sessionId: row.session_id,
28
+ channel: identity.channel,
29
+ kind: identity.kind,
30
+ people: new Map(),
31
+ });
32
+ const room = rooms.get(row.session_id),
33
+ payload = parse(row.payload, {});
34
+ if (row.role === "user" && payload.userId && payload.userId !== "bot")
35
+ room.people.set(String(payload.userId), {
36
+ id: String(payload.userId),
37
+ name: payload.name || "这位参与者",
38
+ });
39
+ if (row.role === "assistant") {
40
+ // Confirmed replies credit their actual addressees, never nearby members.
41
+ for (const seq of (Array.isArray(payload.replyTargetIds)
42
+ ? payload.replyTargetIds
43
+ : []
44
+ ).slice(0, 24)) {
45
+ const target = event.get(Number(seq), Math.min(before, row.time));
46
+ if (!target) incomplete = true;
47
+ if (target?.role === "user" && target.session_id === row.session_id)
48
+ take(target);
49
+ }
50
+ }
51
+ };
52
+ for (let cursor = 0; cursor < queue.length; cursor++) {
53
+ if (seen.size >= 512)
54
+ return { kind: "conversation", rooms: [], incomplete: true };
55
+ const ref = queue[cursor];
56
+ if (seen.has(ref)) continue;
57
+ seen.add(ref);
58
+ const kind = ref[0],
59
+ id = ref.slice(2);
60
+ if (kind === "m") {
61
+ const row = event.get(Number(id), before);
62
+ if (!row) incomplete = true;
63
+ take(row);
64
+ continue;
65
+ }
66
+ // Reading and her own executed activities are hers to introduce. Their
67
+ // original motivation does not make the finished work someone else's chat.
68
+ let rows = [];
69
+ if (kind === "t")
70
+ rows = db
71
+ .prepare(
72
+ "SELECT sources,parent_id FROM mind_thoughts WHERE id=? AND created<=? AND hidden=0",
73
+ )
74
+ .all(id, before);
75
+ else if (kind === "s")
76
+ rows = db
77
+ .prepare(
78
+ "SELECT sources FROM mind_self WHERE thread=? AND created<=? AND thread NOT IN (SELECT target_id FROM mind_revocations WHERE target_kind='self')",
79
+ )
80
+ .all(id, before);
81
+ else if (kind === "g")
82
+ rows = db
83
+ .prepare(
84
+ "SELECT sources FROM mind_meetings WHERE id=? AND created<=? AND id NOT IN (SELECT target_id FROM mind_revocations WHERE target_kind='meeting')",
85
+ )
86
+ .all(id, before);
87
+ else if (kind === "a")
88
+ rows = db
89
+ .prepare(
90
+ "SELECT sources FROM mind_anticipations WHERE id=? AND created<=?",
91
+ )
92
+ .all(id, before);
93
+ else if (kind === "d")
94
+ rows = db
95
+ .prepare("SELECT sources FROM mind_diary WHERE day=? AND created<=?")
96
+ .all(id, before);
97
+ if (["t", "s", "g", "a", "d"].includes(kind) && !rows.length)
98
+ incomplete = true;
99
+ for (const row of rows) {
100
+ queue.push(...evidence(parse(row.sources, [])));
101
+ if (row.parent_id) queue.push("t:" + row.parent_id);
102
+ }
103
+ }
104
+ return {
105
+ kind: rooms.size ? "conversation" : "own",
106
+ rooms: [...rooms.values()].map((room) => ({
107
+ ...room,
108
+ people: [...room.people.values()],
109
+ })),
110
+ incomplete,
111
+ };
112
+ }
113
+
114
+ export function originSummary(origin) {
115
+ return {
116
+ ...origin,
117
+ rooms: origin.rooms
118
+ .slice(0, 6)
119
+ .map((room) => ({ ...room, people: room.people.slice(0, 8) })),
120
+ };
121
+ }
122
+
123
+ export function initiativeAudience(mind, thought, session, now = Date.now()) {
124
+ const sources = evidence(thought?.sources || []),
125
+ before = Math.min(now, thought?.created || now);
126
+ const origin = conversationOrigin(mind.db, sources, before);
127
+ if (!mind.meetings.stays({ sources }, session, before))
128
+ return {
129
+ allowed: false,
130
+ shared: false,
131
+ origin,
132
+ reason: "这份想法含有其他会话的私下来源,不能在这里继续",
133
+ };
134
+ if (origin.incomplete)
135
+ return {
136
+ allowed: false,
137
+ shared: false,
138
+ origin,
139
+ reason: "话题来源缺失、已撤销或过长,参与者尚未核实",
140
+ };
141
+ if (!origin.rooms.length)
142
+ return { allowed: true, shared: false, origin, mode: "new_topic" };
143
+ let destination;
144
+ try {
145
+ destination = parseSessionKey(session);
146
+ } catch {
147
+ return {
148
+ allowed: false,
149
+ shared: false,
150
+ origin,
151
+ reason: "主动交流对象不明确",
152
+ };
153
+ }
154
+ const aliases = new Set(scopedSessionAliases(mind.db, session));
155
+ const shared = origin.rooms.some(
156
+ (room) =>
157
+ room.channel === destination.channel &&
158
+ (destination.kind === "private"
159
+ ? room.people.some((person) => person.id === destination.nativeId) ||
160
+ (room.kind === "private" && aliases.has(room.sessionId))
161
+ : aliases.has(room.sessionId)),
162
+ );
163
+ return {
164
+ allowed: true,
165
+ shared,
166
+ origin,
167
+ mode: shared ? "continuation" : "new_topic",
168
+ ...(!shared
169
+ ? {
170
+ guidance:
171
+ "对方未参与原话题。由她判断是否值得分享、是否适合这个人;值得就自然开启新话题并给必要背景,不能当成之前共同聊过、共同项目或对方的约定。也可以选择不聊。",
172
+ }
173
+ : {}),
174
+ };
175
+ }