luckytri 1.0.0 → 1.0.1

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 (133) hide show
  1. package/.github/SECURITY.md +4 -4
  2. package/README.en.md +252 -250
  3. package/README.md +252 -250
  4. package/bin/luckytri.js +5 -1
  5. package/docs/en/CHANGELOG.md +8 -0
  6. package/docs/en/connect.md +18 -18
  7. package/docs/en/guide.md +192 -216
  8. package/docs/en/npm-release.md +25 -25
  9. package/docs/zh/CHANGELOG.md +8 -0
  10. package/docs/zh/connect.md +17 -17
  11. package/docs/zh/guide.md +192 -216
  12. package/docs/zh/npm-release.md +33 -33
  13. package/package.json +109 -108
  14. package/plugins/sdk/index.d.ts +155 -155
  15. package/plugins/sdk/testing.js +58 -58
  16. package/plugins/weather/index.js +82 -82
  17. package/plugins/weather/luckytri-plugin.json +29 -29
  18. package/public/app/assets/ChatsPage-B9Odvzfz.js +3 -0
  19. package/public/app/assets/Empty-SkA8PyMo.js +2 -0
  20. package/public/app/assets/Field-BjLhi8pL.js +1 -0
  21. package/public/app/assets/HeartPage-CscKqMsr.js +1 -0
  22. package/public/app/assets/LifePage-BHCmBHlH.js +1 -0
  23. package/public/app/assets/MemoryPage-Bhs2xa1k.js +1 -0
  24. package/public/app/assets/NaturePage-CaPIar_5.js +3 -0
  25. package/public/app/assets/PeoplePage-CuwSSVeX.js +1 -0
  26. package/public/app/assets/PluginsPage-BhVm1SUi.js +2 -0
  27. package/public/app/assets/PluginsPage-CVVQwEBI.css +1 -0
  28. package/public/app/assets/{SystemPage-CAMPoYqM.css → SystemPage-5yYqyUgR.css} +1 -1
  29. package/public/app/assets/SystemPage-Chm5fiGP.js +1 -0
  30. package/public/app/assets/TimePage-BUm4eUzB.js +3 -0
  31. package/public/app/assets/index-BIAdfObg.js +4 -0
  32. package/public/app/assets/{index-YDz1ree1.css → index-DY4e15Kh.css} +1 -1
  33. package/public/app/assets/{knowledge-DG0e0uKw.js → knowledge-DNDLyN9m.js} +1 -1
  34. package/public/app/assets/media-CKVAvML2.js +1 -0
  35. package/public/app/index.html +3 -3
  36. package/public/guide.en.html +32 -99
  37. package/public/guide.html +21 -86
  38. package/public/tutorial.en.md +15 -39
  39. package/public/tutorial.md +15 -39
  40. package/scripts/backup.js +311 -311
  41. package/scripts/browser.js +41 -41
  42. package/scripts/launch.js +101 -94
  43. package/scripts/plugin.js +150 -150
  44. package/scripts/reset-password.js +22 -0
  45. package/scripts/runtime.js +25 -25
  46. package/scripts/service.js +56 -47
  47. package/scripts/setup.js +50 -50
  48. package/scripts/start-server.js +41 -41
  49. package/scripts/stop.js +36 -36
  50. package/server/app.js +110 -96
  51. package/server/auth.js +217 -0
  52. package/server/channels/contract.js +57 -57
  53. package/server/channels/hub.js +165 -165
  54. package/server/channels/index.js +28 -25
  55. package/server/channels/onebot/index.js +335 -336
  56. package/server/channels/onebot/token.js +22 -3
  57. package/server/core/capabilities.js +208 -208
  58. package/server/core/events.js +64 -60
  59. package/server/core/image-preprocessor.js +208 -208
  60. package/server/core/model-manager.js +1213 -1213
  61. package/server/core/net-guard.js +49 -49
  62. package/server/core/orchestrator.js +569 -569
  63. package/server/core/perceivers.js +91 -91
  64. package/server/core/persona-manager.js +243 -243
  65. package/server/core/repository.js +293 -293
  66. package/server/core/response-validator.js +508 -508
  67. package/server/core/turn-processor.js +630 -630
  68. package/server/core/turn.js +236 -236
  69. package/server/core/vision-manager.js +633 -633
  70. package/server/i18n/errors.js +512 -497
  71. package/server/i18n/labels.js +649 -653
  72. package/server/index.js +107 -102
  73. package/server/knowledge/manager.js +386 -386
  74. package/server/local-access.js +32 -0
  75. package/server/mind/anticipations.js +507 -507
  76. package/server/mind/api.js +703 -703
  77. package/server/mind/budget.js +152 -152
  78. package/server/mind/context-selection.js +61 -61
  79. package/server/mind/day-planner.js +324 -324
  80. package/server/mind/evidence.js +148 -148
  81. package/server/mind/index.js +445 -445
  82. package/server/mind/life/diary.js +786 -786
  83. package/server/mind/life/index.js +1049 -1049
  84. package/server/mind/observations.js +84 -84
  85. package/server/mind/own-day.js +324 -324
  86. package/server/mind/own-voice.js +318 -318
  87. package/server/mind/senses.js +53 -53
  88. package/server/mind/time/activity-clock.js +196 -196
  89. package/server/mind/time/availability.js +69 -69
  90. package/server/mind/time/commitment-review.js +198 -198
  91. package/server/mind/time/executor.js +512 -512
  92. package/server/mind/time/experiences.js +128 -128
  93. package/server/mind/time/games.js +562 -562
  94. package/server/mind/time/index.js +739 -739
  95. package/server/mind/time/intent.js +166 -166
  96. package/server/mind/time/kinds.js +171 -171
  97. package/server/mind/time/plugin-activity.js +207 -207
  98. package/server/mind/time/tasks.js +587 -587
  99. package/server/mind/util.js +110 -110
  100. package/server/mind/view.js +273 -273
  101. package/server/paths.js +102 -102
  102. package/server/plugins/api.js +204 -204
  103. package/server/plugins/host.js +967 -967
  104. package/server/plugins/install.js +295 -295
  105. package/server/plugins/manifest.js +201 -201
  106. package/server/plugins/permissions.js +42 -42
  107. package/server/plugins/runner/guard.mjs +36 -36
  108. package/server/plugins/runner/worker.mjs +250 -250
  109. package/server/plugins/schema.js +91 -91
  110. package/server/plugins/zip.js +112 -112
  111. package/server/startup-lock.js +118 -118
  112. package/server/storage/archive.js +241 -241
  113. package/server/storage/backup-cleanup-worker.js +8 -8
  114. package/server/storage/backup-cleanup.js +414 -414
  115. package/server/storage/backup-lock.js +76 -76
  116. package/server/storage/backup-scheduler.js +131 -131
  117. package/server/storage/store.js +199 -199
  118. package/server/studio/readiness.js +181 -190
  119. package/server/studio/settings.js +236 -236
  120. package/public/app/assets/ChatsPage-C-FcRapR.js +0 -3
  121. package/public/app/assets/Empty-CpP5kQHH.js +0 -2
  122. package/public/app/assets/Field-D4gY-INU.js +0 -1
  123. package/public/app/assets/HeartPage-CPy_thQd.js +0 -1
  124. package/public/app/assets/LifePage-CxWvwmSf.js +0 -1
  125. package/public/app/assets/MemoryPage-DC4rhQ68.js +0 -1
  126. package/public/app/assets/NaturePage-IvYw04Zq.js +0 -3
  127. package/public/app/assets/PeoplePage-Cqefm9-q.js +0 -1
  128. package/public/app/assets/PluginsPage-DKSaKvXb.js +0 -2
  129. package/public/app/assets/PluginsPage-HyBe5D8w.css +0 -1
  130. package/public/app/assets/SystemPage-CJmtJkrK.js +0 -1
  131. package/public/app/assets/TimePage-Cw44inM4.js +0 -3
  132. package/public/app/assets/index-BheRW-1t.js +0 -4
  133. package/public/app/assets/media-BzPDBm7e.js +0 -1
@@ -1,208 +1,208 @@
1
- import sharp from "sharp";
2
-
3
- const MIB = 1024 * 1024;
4
- const TYPES = {
5
- jpeg: "image/jpeg",
6
- png: "image/png",
7
- webp: "image/webp",
8
- gif: "image/gif",
9
- heif: "image/avif",
10
- };
11
-
12
- function configured(value, fallback, min, max) {
13
- const number = Number(value);
14
- return value != null && value !== "" && Number.isFinite(number)
15
- ? Math.min(max, Math.max(min, number))
16
- : fallback;
17
- }
18
-
19
- export function visionImageLimits(env = process.env) {
20
- return {
21
- maxSourceBytes: Math.floor(
22
- configured(env.VISION_SOURCE_MAX_MB, 32, 4, 64) * MIB,
23
- ),
24
- maxModelBytes: Math.floor(
25
- configured(env.VISION_MODEL_MAX_MB, 4, 1, 4) * MIB,
26
- ),
27
- maxPixels: 80_000_000,
28
- maxDimension: 8192,
29
- maxOutputPixels: 16_000_000,
30
- downloadTimeoutMs: Math.floor(
31
- configured(env.VISION_DOWNLOAD_TIMEOUT_SECONDS, 30, 5, 120) * 1000,
32
- ),
33
- };
34
- }
35
-
36
- export function imageMime(bytes) {
37
- if (
38
- bytes.length >= 3 &&
39
- bytes[0] === 0xff &&
40
- bytes[1] === 0xd8 &&
41
- bytes[2] === 0xff
42
- )
43
- return "image/jpeg";
44
- if (
45
- bytes.length >= 8 &&
46
- bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))
47
- )
48
- return "image/png";
49
- if (
50
- bytes.length >= 6 &&
51
- /^(GIF87a|GIF89a)$/.test(bytes.toString("ascii", 0, 6))
52
- )
53
- return "image/gif";
54
- if (
55
- bytes.length >= 12 &&
56
- bytes.toString("ascii", 0, 4) === "RIFF" &&
57
- bytes.toString("ascii", 8, 12) === "WEBP"
58
- )
59
- return "image/webp";
60
- if (bytes.length >= 16 && bytes.toString("ascii", 4, 8) === "ftyp") {
61
- const length = bytes.readUInt32BE(0);
62
- if (length >= 16 && length <= bytes.length) {
63
- for (let offset = 8; offset < Math.min(length, 64); offset += 4) {
64
- if (offset === 12) continue; // Minor version, not a compatible brand.
65
- if (
66
- ["avif", "avis"].includes(bytes.toString("ascii", offset, offset + 4))
67
- )
68
- return "image/avif";
69
- }
70
- }
71
- }
72
- return "";
73
- }
74
-
75
- // Bound work across all conversations, including downloads and decoded images.
76
- let active = 0;
77
- const waiting = [];
78
- export async function withVisionImageSlot(run) {
79
- if (active >= 2) await new Promise((resolve) => waiting.push(resolve));
80
- else active++;
81
- try {
82
- return await run();
83
- } finally {
84
- const next = waiting.shift();
85
- if (next) next();
86
- else active--;
87
- }
88
- }
89
-
90
- export async function prepareVisionImage(bytes, limits = visionImageLimits()) {
91
- if (!bytes.length || bytes.length > limits.maxSourceBytes)
92
- throw Error("图片超过大小限制");
93
- const mime = imageMime(bytes);
94
- if (!mime) throw Error("不是支持的图片格式");
95
- const input = { limitInputPixels: limits.maxPixels, pages: 1 };
96
- let metadata;
97
- try {
98
- metadata = await sharp(bytes, input).metadata();
99
- } catch (error) {
100
- if (/pixel limit/i.test(error.message)) throw Error("图片像素超过处理限制");
101
- throw Error("图片读取失败");
102
- }
103
- if (
104
- !TYPES[metadata.format] ||
105
- (metadata.format === "heif" && metadata.compression !== "av1")
106
- )
107
- throw Error("不是支持的图片格式");
108
- const oriented =
109
- metadata.autoOrient ||
110
- ([5, 6, 7, 8].includes(metadata.orientation)
111
- ? { width: metadata.height, height: metadata.width }
112
- : metadata);
113
- const { width, height } = oriented;
114
- if (!width || !height || width * height > limits.maxPixels)
115
- throw Error("图片像素超过处理限制");
116
- const scale = Math.min(
117
- 1,
118
- limits.maxDimension / width,
119
- limits.maxDimension / height,
120
- Math.sqrt(limits.maxOutputPixels / (width * height)),
121
- );
122
- let targetWidth = Math.max(1, Math.floor(width * scale));
123
- let targetHeight = Math.max(1, Math.floor(height * scale));
124
- const frameOnly = metadata.pages > 1;
125
- if (
126
- bytes.length <= limits.maxModelBytes &&
127
- scale === 1 &&
128
- !frameOnly &&
129
- (!metadata.orientation || metadata.orientation === 1) &&
130
- mime !== "image/avif" &&
131
- mime !== "image/gif"
132
- ) {
133
- try {
134
- // Decode before passing through: intact headers can hide a truncated
135
- // image body. Discard the tiny probe and retain the original bytes.
136
- await sharp(bytes, input)
137
- .resize({ width: 1, height: 1, fit: "inside" })
138
- .raw()
139
- .timeout({ seconds: 10 })
140
- .toBuffer();
141
- } catch (error) {
142
- if (/timeout|timed out/i.test(error.message)) throw Error("图片处理超时");
143
- throw Error("图片读取失败");
144
- }
145
- return {
146
- bytes,
147
- mime,
148
- width,
149
- height,
150
- originalBytes: bytes.length,
151
- transformed: false,
152
- frameOnly: false,
153
- };
154
- }
155
-
156
- const pipeline = () =>
157
- sharp(bytes, input)
158
- .rotate()
159
- .resize({
160
- width: targetWidth,
161
- height: targetHeight,
162
- fit: "inside",
163
- withoutEnlargement: true,
164
- })
165
- .timeout({ seconds: 10 });
166
- const result = (output, format) => ({
167
- bytes: output.data,
168
- mime: format,
169
- width: output.info.width,
170
- height: output.info.height,
171
- originalBytes: bytes.length,
172
- transformed: true,
173
- frameOnly,
174
- });
175
- try {
176
- // Try lossless encoding first: large uncompressed screenshots often fit
177
- // without shrinking text or introducing JPEG artefacts.
178
- if (mime !== "image/jpeg") {
179
- const png = await pipeline()
180
- .png({ compressionLevel: 6 })
181
- .toBuffer({ resolveWithObject: true });
182
- if (png.data.length <= limits.maxModelBytes)
183
- return result(png, "image/png");
184
- }
185
- for (let attempt = 0; attempt < 4; attempt++) {
186
- const output = await pipeline()
187
- .flatten({ background: "#ffffff" })
188
- .jpeg({ quality: attempt === 0 ? 90 : 82, chromaSubsampling: "4:4:4" })
189
- .toBuffer({ resolveWithObject: true });
190
- if (output.data.length <= limits.maxModelBytes)
191
- return result(output, "image/jpeg");
192
- // First reduce encoding size while keeping the full dimensions. Only
193
- // shrink if that still cannot fit the model's request budget.
194
- if (attempt > 0) {
195
- const shrink = Math.min(
196
- 0.85,
197
- Math.sqrt(limits.maxModelBytes / output.data.length) * 0.9,
198
- );
199
- targetWidth = Math.max(1, Math.floor(targetWidth * shrink));
200
- targetHeight = Math.max(1, Math.floor(targetHeight * shrink));
201
- }
202
- }
203
- } catch (error) {
204
- if (/timeout|timed out/i.test(error.message)) throw Error("图片处理超时");
205
- throw Error("图片读取失败");
206
- }
207
- throw Error("图片超过大小限制");
208
- }
1
+ import sharp from "sharp";
2
+
3
+ const MIB = 1024 * 1024;
4
+ const TYPES = {
5
+ jpeg: "image/jpeg",
6
+ png: "image/png",
7
+ webp: "image/webp",
8
+ gif: "image/gif",
9
+ heif: "image/avif",
10
+ };
11
+
12
+ function configured(value, fallback, min, max) {
13
+ const number = Number(value);
14
+ return value != null && value !== "" && Number.isFinite(number)
15
+ ? Math.min(max, Math.max(min, number))
16
+ : fallback;
17
+ }
18
+
19
+ export function visionImageLimits(env = process.env) {
20
+ return {
21
+ maxSourceBytes: Math.floor(
22
+ configured(env.VISION_SOURCE_MAX_MB, 32, 4, 64) * MIB,
23
+ ),
24
+ maxModelBytes: Math.floor(
25
+ configured(env.VISION_MODEL_MAX_MB, 4, 1, 4) * MIB,
26
+ ),
27
+ maxPixels: 80_000_000,
28
+ maxDimension: 8192,
29
+ maxOutputPixels: 16_000_000,
30
+ downloadTimeoutMs: Math.floor(
31
+ configured(env.VISION_DOWNLOAD_TIMEOUT_SECONDS, 30, 5, 120) * 1000,
32
+ ),
33
+ };
34
+ }
35
+
36
+ export function imageMime(bytes) {
37
+ if (
38
+ bytes.length >= 3 &&
39
+ bytes[0] === 0xff &&
40
+ bytes[1] === 0xd8 &&
41
+ bytes[2] === 0xff
42
+ )
43
+ return "image/jpeg";
44
+ if (
45
+ bytes.length >= 8 &&
46
+ bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))
47
+ )
48
+ return "image/png";
49
+ if (
50
+ bytes.length >= 6 &&
51
+ /^(GIF87a|GIF89a)$/.test(bytes.toString("ascii", 0, 6))
52
+ )
53
+ return "image/gif";
54
+ if (
55
+ bytes.length >= 12 &&
56
+ bytes.toString("ascii", 0, 4) === "RIFF" &&
57
+ bytes.toString("ascii", 8, 12) === "WEBP"
58
+ )
59
+ return "image/webp";
60
+ if (bytes.length >= 16 && bytes.toString("ascii", 4, 8) === "ftyp") {
61
+ const length = bytes.readUInt32BE(0);
62
+ if (length >= 16 && length <= bytes.length) {
63
+ for (let offset = 8; offset < Math.min(length, 64); offset += 4) {
64
+ if (offset === 12) continue; // Minor version, not a compatible brand.
65
+ if (
66
+ ["avif", "avis"].includes(bytes.toString("ascii", offset, offset + 4))
67
+ )
68
+ return "image/avif";
69
+ }
70
+ }
71
+ }
72
+ return "";
73
+ }
74
+
75
+ // Bound work across all conversations, including downloads and decoded images.
76
+ let active = 0;
77
+ const waiting = [];
78
+ export async function withVisionImageSlot(run) {
79
+ if (active >= 2) await new Promise((resolve) => waiting.push(resolve));
80
+ else active++;
81
+ try {
82
+ return await run();
83
+ } finally {
84
+ const next = waiting.shift();
85
+ if (next) next();
86
+ else active--;
87
+ }
88
+ }
89
+
90
+ export async function prepareVisionImage(bytes, limits = visionImageLimits()) {
91
+ if (!bytes.length || bytes.length > limits.maxSourceBytes)
92
+ throw Error("图片超过大小限制");
93
+ const mime = imageMime(bytes);
94
+ if (!mime) throw Error("不是支持的图片格式");
95
+ const input = { limitInputPixels: limits.maxPixels, pages: 1 };
96
+ let metadata;
97
+ try {
98
+ metadata = await sharp(bytes, input).metadata();
99
+ } catch (error) {
100
+ if (/pixel limit/i.test(error.message)) throw Error("图片像素超过处理限制");
101
+ throw Error("图片读取失败");
102
+ }
103
+ if (
104
+ !TYPES[metadata.format] ||
105
+ (metadata.format === "heif" && metadata.compression !== "av1")
106
+ )
107
+ throw Error("不是支持的图片格式");
108
+ const oriented =
109
+ metadata.autoOrient ||
110
+ ([5, 6, 7, 8].includes(metadata.orientation)
111
+ ? { width: metadata.height, height: metadata.width }
112
+ : metadata);
113
+ const { width, height } = oriented;
114
+ if (!width || !height || width * height > limits.maxPixels)
115
+ throw Error("图片像素超过处理限制");
116
+ const scale = Math.min(
117
+ 1,
118
+ limits.maxDimension / width,
119
+ limits.maxDimension / height,
120
+ Math.sqrt(limits.maxOutputPixels / (width * height)),
121
+ );
122
+ let targetWidth = Math.max(1, Math.floor(width * scale));
123
+ let targetHeight = Math.max(1, Math.floor(height * scale));
124
+ const frameOnly = metadata.pages > 1;
125
+ if (
126
+ bytes.length <= limits.maxModelBytes &&
127
+ scale === 1 &&
128
+ !frameOnly &&
129
+ (!metadata.orientation || metadata.orientation === 1) &&
130
+ mime !== "image/avif" &&
131
+ mime !== "image/gif"
132
+ ) {
133
+ try {
134
+ // Decode before passing through: intact headers can hide a truncated
135
+ // image body. Discard the tiny probe and retain the original bytes.
136
+ await sharp(bytes, input)
137
+ .resize({ width: 1, height: 1, fit: "inside" })
138
+ .raw()
139
+ .timeout({ seconds: 10 })
140
+ .toBuffer();
141
+ } catch (error) {
142
+ if (/timeout|timed out/i.test(error.message)) throw Error("图片处理超时");
143
+ throw Error("图片读取失败");
144
+ }
145
+ return {
146
+ bytes,
147
+ mime,
148
+ width,
149
+ height,
150
+ originalBytes: bytes.length,
151
+ transformed: false,
152
+ frameOnly: false,
153
+ };
154
+ }
155
+
156
+ const pipeline = () =>
157
+ sharp(bytes, input)
158
+ .rotate()
159
+ .resize({
160
+ width: targetWidth,
161
+ height: targetHeight,
162
+ fit: "inside",
163
+ withoutEnlargement: true,
164
+ })
165
+ .timeout({ seconds: 10 });
166
+ const result = (output, format) => ({
167
+ bytes: output.data,
168
+ mime: format,
169
+ width: output.info.width,
170
+ height: output.info.height,
171
+ originalBytes: bytes.length,
172
+ transformed: true,
173
+ frameOnly,
174
+ });
175
+ try {
176
+ // Try lossless encoding first: large uncompressed screenshots often fit
177
+ // without shrinking text or introducing JPEG artefacts.
178
+ if (mime !== "image/jpeg") {
179
+ const png = await pipeline()
180
+ .png({ compressionLevel: 6 })
181
+ .toBuffer({ resolveWithObject: true });
182
+ if (png.data.length <= limits.maxModelBytes)
183
+ return result(png, "image/png");
184
+ }
185
+ for (let attempt = 0; attempt < 4; attempt++) {
186
+ const output = await pipeline()
187
+ .flatten({ background: "#ffffff" })
188
+ .jpeg({ quality: attempt === 0 ? 90 : 82, chromaSubsampling: "4:4:4" })
189
+ .toBuffer({ resolveWithObject: true });
190
+ if (output.data.length <= limits.maxModelBytes)
191
+ return result(output, "image/jpeg");
192
+ // First reduce encoding size while keeping the full dimensions. Only
193
+ // shrink if that still cannot fit the model's request budget.
194
+ if (attempt > 0) {
195
+ const shrink = Math.min(
196
+ 0.85,
197
+ Math.sqrt(limits.maxModelBytes / output.data.length) * 0.9,
198
+ );
199
+ targetWidth = Math.max(1, Math.floor(targetWidth * shrink));
200
+ targetHeight = Math.max(1, Math.floor(targetHeight * shrink));
201
+ }
202
+ }
203
+ } catch (error) {
204
+ if (/timeout|timed out/i.test(error.message)) throw Error("图片处理超时");
205
+ throw Error("图片读取失败");
206
+ }
207
+ throw Error("图片超过大小限制");
208
+ }