hob-bot 0.0.0-stage → 1.0.2
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 -0
- package/README.md +111 -2
- package/README.zh-CN.md +112 -0
- package/bin/hob.mjs +7 -0
- package/dist/web/assets/index-D88l35PH.css +1 -0
- package/dist/web/assets/index-DUs8nN3E.js +218 -0
- package/dist/web/favicon.ico +0 -0
- package/dist/web/fonts/inter-latin.woff2 +0 -0
- package/dist/web/fonts/jetbrains-mono-latin.woff2 +0 -0
- package/dist/web/icons/apple-touch-icon-180.png +0 -0
- package/dist/web/icons/favicon-32.png +0 -0
- package/dist/web/icons/icon-192.png +0 -0
- package/dist/web/icons/icon-512.png +0 -0
- package/dist/web/icons/icon-maskable-512.png +0 -0
- package/dist/web/index.html +32 -0
- package/dist/web/manifest.webmanifest +16 -0
- package/dist/web/sw.js +131 -0
- package/package.json +62 -4
- package/server/src/actions.ts +230 -0
- package/server/src/boot.ts +85 -0
- package/server/src/bus.ts +21 -0
- package/server/src/config.ts +123 -0
- package/server/src/cron-text.ts +49 -0
- package/server/src/delegations.ts +113 -0
- package/server/src/files.ts +142 -0
- package/server/src/http.ts +802 -0
- package/server/src/ids.ts +19 -0
- package/server/src/image.ts +218 -0
- package/server/src/imports.ts +302 -0
- package/server/src/jobs.ts +730 -0
- package/server/src/main.ts +69 -0
- package/server/src/memory.ts +272 -0
- package/server/src/models.ts +358 -0
- package/server/src/overview.ts +116 -0
- package/server/src/pages.ts +54 -0
- package/server/src/password.ts +23 -0
- package/server/src/pi.ts +273 -0
- package/server/src/prompt.ts +227 -0
- package/server/src/providers.ts +532 -0
- package/server/src/push.ts +285 -0
- package/server/src/router-tools.ts +549 -0
- package/server/src/router.ts +841 -0
- package/server/src/routines.ts +129 -0
- package/server/src/runtime.ts +104 -0
- package/server/src/search.ts +91 -0
- package/server/src/secrets.ts +46 -0
- package/server/src/settings.ts +452 -0
- package/server/src/skills.ts +150 -0
- package/server/src/store.ts +324 -0
- package/server/src/text.ts +14 -0
- package/server/src/time.ts +42 -0
- package/server/src/transcript.ts +272 -0
- package/server/src/worker-tools.ts +129 -0
- package/shared/command.ts +42 -0
- package/shared/files.ts +141 -0
- package/shared/media.ts +17 -0
- package/shared/model-note.ts +32 -0
- package/shared/page-shell.ts +108 -0
- package/shared/search.ts +19 -0
- package/shared/skills.ts +37 -0
- package/shared/sprites.ts +422 -0
- package/shared/thinking.ts +118 -0
- package/shared/types.ts +631 -0
- package/vendor/lore-pi-extension/README.md +28 -0
- package/vendor/lore-pi-extension/api.ts +140 -0
- package/vendor/lore-pi-extension/formatters.ts +204 -0
- package/vendor/lore-pi-extension/hooks.ts +195 -0
- package/vendor/lore-pi-extension/index.ts +25 -0
- package/vendor/lore-pi-extension/package.json +23 -0
- package/vendor/lore-pi-extension/skills.ts +447 -0
- package/vendor/lore-pi-extension/tools.ts +344 -0
- package/vendor/lore-pi-extension/uri.ts +67 -0
- package/vendor/lore-pi-extension/vendor/skill-workcopy/index.d.mts +266 -0
- package/vendor/lore-pi-extension/vendor/skill-workcopy/index.mjs +1328 -0
- package/vendor/lore-pi-extension/vendor/skill-workcopy/skills-sync.d.mts +33 -0
- package/vendor/lore-pi-extension/vendor/skill-workcopy/skills-sync.mjs +202 -0
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
// 助手头像:都是 Hob 的像素小火苗,换一种颜色、带一件和职责有关的道具。
|
|
2
|
+
// sprite 记成「道具」或「道具:颜色」,如 "server"、"wifi:green";只写道具时用这件道具的默认颜色。
|
|
3
|
+
// 库里没有合适的道具时,AI 可以自己画一件:sprite 记成 "custom" 或 "custom:颜色",画法存在 Assistant.prop,格式和 PROPS 里的一项相同。
|
|
4
|
+
// 旧数据里的 page、server、bird 这些 id 就是道具 id,不用迁移。
|
|
5
|
+
|
|
6
|
+
import type { CustomProp } from "./types.ts";
|
|
7
|
+
|
|
8
|
+
/** 12×12 的火苗(主助手 Hob 就是它,应用图标也是)。k 描边,o 外焰,y 内焰,e 眼睛。 */
|
|
9
|
+
export const FLAME = [
|
|
10
|
+
"......k.....",
|
|
11
|
+
".....kok....",
|
|
12
|
+
".....kook...",
|
|
13
|
+
"..k.koook...",
|
|
14
|
+
".kokoooook..",
|
|
15
|
+
".kooooooook.",
|
|
16
|
+
"kooyyyyyyook",
|
|
17
|
+
"koyyeyyeyyok",
|
|
18
|
+
"koyyeyyeyyok",
|
|
19
|
+
"koyyyyyyyyok",
|
|
20
|
+
".kooyyyyook.",
|
|
21
|
+
"..kkkkkkkk..",
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
const SIZE = 16;
|
|
25
|
+
const INK = "#40261a";
|
|
26
|
+
|
|
27
|
+
export const COLORS = {
|
|
28
|
+
orange: { name: "橙", o: "#ff7a2e", y: "#ffcf4a", bg: "#ffe6d3" },
|
|
29
|
+
red: { name: "红", o: "#ff5a3c", y: "#ffd2a8", bg: "#ffe3dc" },
|
|
30
|
+
pink: { name: "粉", o: "#ff6b8a", y: "#ffd6de", bg: "#ffe4ef" },
|
|
31
|
+
purple: { name: "紫", o: "#8f7bff", y: "#ddd6ff", bg: "#e9e5ff" },
|
|
32
|
+
blue: { name: "蓝", o: "#4ea3ff", y: "#cfe6ff", bg: "#fff0c4" },
|
|
33
|
+
slate: { name: "灰蓝", o: "#6f8fb3", y: "#d8e5f2", bg: "#e3eeff" },
|
|
34
|
+
teal: { name: "青", o: "#20b8b0", y: "#c2f0ea", bg: "#d6f3f1" },
|
|
35
|
+
green: { name: "绿", o: "#2fbf71", y: "#c9f2da", bg: "#e4f5d9" },
|
|
36
|
+
};
|
|
37
|
+
export type ColorId = keyof typeof COLORS;
|
|
38
|
+
|
|
39
|
+
interface Prop {
|
|
40
|
+
/** 适合的职责,建助手时给模型挑头像用 */
|
|
41
|
+
label: string;
|
|
42
|
+
color: ColorId;
|
|
43
|
+
/** 火苗在 16×16 里的横向位置:头顶的道具居中(2),手边的靠左(0、1),道具放右边不挡右眼 */
|
|
44
|
+
dx: number;
|
|
45
|
+
pal: Record<string, string>;
|
|
46
|
+
/** 从第 0 行起逐行盖上去:'.' 不动,其它字符换成 pal 里的颜色 */
|
|
47
|
+
art: string[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const at = (y: number, rows: string[]) => [...Array<string>(y).fill(""), ...rows];
|
|
51
|
+
|
|
52
|
+
export const PROPS = {
|
|
53
|
+
hob: { label: "主助手", color: "orange", dx: 2, pal: {}, art: [] },
|
|
54
|
+
page: {
|
|
55
|
+
label: "写作/文档",
|
|
56
|
+
color: "purple",
|
|
57
|
+
dx: 1,
|
|
58
|
+
pal: { p: "#ff9db0", g: "#b9c0c8", h: "#ffc21a", b: "#f2c58f" },
|
|
59
|
+
art: at(5, [
|
|
60
|
+
"............kkkk",
|
|
61
|
+
"............kppk",
|
|
62
|
+
"............kppk",
|
|
63
|
+
"............kggk",
|
|
64
|
+
"............khhk",
|
|
65
|
+
"............khhk",
|
|
66
|
+
"............khhk",
|
|
67
|
+
"............khhk",
|
|
68
|
+
"............kbbk",
|
|
69
|
+
".............kk.",
|
|
70
|
+
]),
|
|
71
|
+
},
|
|
72
|
+
server: {
|
|
73
|
+
label: "服务器/运维",
|
|
74
|
+
color: "slate",
|
|
75
|
+
dx: 2,
|
|
76
|
+
pal: { h: "#ffc21a", w: "#fff1b8" },
|
|
77
|
+
art: at(2, [
|
|
78
|
+
"......kkkk......",
|
|
79
|
+
".....khhwwk.....",
|
|
80
|
+
"....khhhhwhk....",
|
|
81
|
+
"....khhhhhhk....",
|
|
82
|
+
"...kkkkkkkkkk...",
|
|
83
|
+
]),
|
|
84
|
+
},
|
|
85
|
+
bird: {
|
|
86
|
+
label: "资讯/动态",
|
|
87
|
+
color: "blue",
|
|
88
|
+
dx: 0,
|
|
89
|
+
pal: { l: "#dff3ff", w: "#ffffff" },
|
|
90
|
+
art: at(6, [
|
|
91
|
+
"..........kkkk..",
|
|
92
|
+
".........kllllk.",
|
|
93
|
+
".........kwlllk.",
|
|
94
|
+
".........kllllk.",
|
|
95
|
+
".........kllllk.",
|
|
96
|
+
"..........kkkk..",
|
|
97
|
+
".............kk.",
|
|
98
|
+
"..............kk",
|
|
99
|
+
"...............k",
|
|
100
|
+
]),
|
|
101
|
+
},
|
|
102
|
+
house: {
|
|
103
|
+
label: "家/NAS/生活",
|
|
104
|
+
color: "teal",
|
|
105
|
+
dx: 0,
|
|
106
|
+
pal: { r: "#ff8b6a", w: "#fff7ea", d: "#9b6b52" },
|
|
107
|
+
art: at(9, [
|
|
108
|
+
"............k...",
|
|
109
|
+
"...........krk..",
|
|
110
|
+
"..........krrrk.",
|
|
111
|
+
".........krrrrrk",
|
|
112
|
+
"..........kwwwk.",
|
|
113
|
+
"..........kwdwk.",
|
|
114
|
+
"..........kkkkk.",
|
|
115
|
+
]),
|
|
116
|
+
},
|
|
117
|
+
coin: {
|
|
118
|
+
label: "钱/记账",
|
|
119
|
+
color: "green",
|
|
120
|
+
dx: 0,
|
|
121
|
+
pal: { h: "#ffc21a", w: "#fff1b8", d: "#d18f00" },
|
|
122
|
+
art: at(9, [
|
|
123
|
+
"...........kkk..",
|
|
124
|
+
"..........khhhk.",
|
|
125
|
+
".........khwdhhk",
|
|
126
|
+
".........khwdhhk",
|
|
127
|
+
".........khhdhhk",
|
|
128
|
+
"..........khhhk.",
|
|
129
|
+
"...........kkk..",
|
|
130
|
+
]),
|
|
131
|
+
},
|
|
132
|
+
book: {
|
|
133
|
+
label: "学习/读书",
|
|
134
|
+
color: "red",
|
|
135
|
+
dx: 2,
|
|
136
|
+
pal: { d: "#3a3f58", t: "#ffc21a" },
|
|
137
|
+
art: at(1, [
|
|
138
|
+
".......kk.......",
|
|
139
|
+
".....kkddkk.....",
|
|
140
|
+
"...kkddddddkk...",
|
|
141
|
+
".kkddddddddddkk.",
|
|
142
|
+
"...kkddddddkk.t.",
|
|
143
|
+
"....kddddddk..t.",
|
|
144
|
+
"....kkkkkkkk..t.",
|
|
145
|
+
"..............t.",
|
|
146
|
+
]),
|
|
147
|
+
},
|
|
148
|
+
leaf: {
|
|
149
|
+
label: "健康/植物",
|
|
150
|
+
color: "pink",
|
|
151
|
+
dx: 2,
|
|
152
|
+
pal: { g: "#5ccf6b", s: "#3a9a4f" },
|
|
153
|
+
art: at(0, [
|
|
154
|
+
"....kk.....kk...",
|
|
155
|
+
"...kggk...kggk..",
|
|
156
|
+
"....kggkskggk...",
|
|
157
|
+
".....kk.s.kk....",
|
|
158
|
+
]),
|
|
159
|
+
},
|
|
160
|
+
wifi: {
|
|
161
|
+
label: "网络/路由器",
|
|
162
|
+
color: "teal",
|
|
163
|
+
dx: 2,
|
|
164
|
+
pal: {},
|
|
165
|
+
art: at(0, ["......kkkkk.....", ".....k.....k....", ".......kkk......", "......k...k....."]),
|
|
166
|
+
},
|
|
167
|
+
calendar: {
|
|
168
|
+
label: "日程/提醒",
|
|
169
|
+
color: "purple",
|
|
170
|
+
dx: 0,
|
|
171
|
+
pal: { r: "#ff4d4d", w: "#ffffff" },
|
|
172
|
+
art: at(8, [
|
|
173
|
+
"..........k...k.",
|
|
174
|
+
".........kkkkkkk",
|
|
175
|
+
".........krrrrrk",
|
|
176
|
+
".........kkkkkkk",
|
|
177
|
+
".........kwwwwwk",
|
|
178
|
+
".........kwwkwwk",
|
|
179
|
+
".........kwwwwwk",
|
|
180
|
+
".........kkkkkkk",
|
|
181
|
+
]),
|
|
182
|
+
},
|
|
183
|
+
chef: {
|
|
184
|
+
label: "做饭/饮食",
|
|
185
|
+
color: "red",
|
|
186
|
+
dx: 2,
|
|
187
|
+
pal: { w: "#ffffff", g: "#d9dde2" },
|
|
188
|
+
art: at(1, [
|
|
189
|
+
".....kk..kk.....",
|
|
190
|
+
"....kwwkkwwk....",
|
|
191
|
+
"...kwwwwwwwwk...",
|
|
192
|
+
"...kwwwwwwwwk...",
|
|
193
|
+
"....kwwwwwwk....",
|
|
194
|
+
"....kggggggk....",
|
|
195
|
+
"....kkkkkkkk....",
|
|
196
|
+
]),
|
|
197
|
+
},
|
|
198
|
+
chart: {
|
|
199
|
+
label: "股票/数据",
|
|
200
|
+
color: "slate",
|
|
201
|
+
dx: 0,
|
|
202
|
+
pal: { w: "#ffffff", g: "#f04848" },
|
|
203
|
+
art: at(9, [
|
|
204
|
+
".........kkkkkkk",
|
|
205
|
+
".........kwwwwgk",
|
|
206
|
+
".........kwwgwgk",
|
|
207
|
+
".........kwwgwgk",
|
|
208
|
+
".........kgwgwgk",
|
|
209
|
+
".........kgwgwgk",
|
|
210
|
+
".........kkkkkkk",
|
|
211
|
+
]),
|
|
212
|
+
},
|
|
213
|
+
bag: {
|
|
214
|
+
label: "旅行/出行",
|
|
215
|
+
color: "blue",
|
|
216
|
+
dx: 0,
|
|
217
|
+
pal: { b: "#e8833a", s: "#ffd59a" },
|
|
218
|
+
art: at(9, [
|
|
219
|
+
"...........kkk..",
|
|
220
|
+
"...........k.k..",
|
|
221
|
+
".........kkkkkkk",
|
|
222
|
+
".........kbsbsbk",
|
|
223
|
+
".........kbsbsbk",
|
|
224
|
+
".........kbsbsbk",
|
|
225
|
+
".........kkkkkkk",
|
|
226
|
+
]),
|
|
227
|
+
},
|
|
228
|
+
paw: {
|
|
229
|
+
label: "宠物",
|
|
230
|
+
color: "purple",
|
|
231
|
+
dx: 0,
|
|
232
|
+
pal: { c: "#ffb36b", p: "#ff8fa6" },
|
|
233
|
+
art: at(9, [
|
|
234
|
+
".........k.....k",
|
|
235
|
+
".........kck.kck",
|
|
236
|
+
".........kccccck",
|
|
237
|
+
".........kckckck",
|
|
238
|
+
".........kccpcck",
|
|
239
|
+
"..........kkkkk.",
|
|
240
|
+
]),
|
|
241
|
+
},
|
|
242
|
+
note: {
|
|
243
|
+
label: "音乐",
|
|
244
|
+
color: "pink",
|
|
245
|
+
dx: 1,
|
|
246
|
+
pal: {},
|
|
247
|
+
art: at(2, [
|
|
248
|
+
"..............k.",
|
|
249
|
+
"..............kk",
|
|
250
|
+
"..............kk",
|
|
251
|
+
"..............k.",
|
|
252
|
+
"..............k.",
|
|
253
|
+
"............kkk.",
|
|
254
|
+
"............kkk.",
|
|
255
|
+
]),
|
|
256
|
+
},
|
|
257
|
+
code: {
|
|
258
|
+
label: "代码/开发",
|
|
259
|
+
color: "green",
|
|
260
|
+
dx: 0,
|
|
261
|
+
pal: { d: "#2b3240", g: "#6ef0a0" },
|
|
262
|
+
art: at(10, [
|
|
263
|
+
".........kkkkkkk",
|
|
264
|
+
".........kgddddk",
|
|
265
|
+
".........kdgdddk",
|
|
266
|
+
".........kgdggdk",
|
|
267
|
+
".........kdddddk",
|
|
268
|
+
".........kkkkkkk",
|
|
269
|
+
]),
|
|
270
|
+
},
|
|
271
|
+
gym: {
|
|
272
|
+
label: "健身/运动",
|
|
273
|
+
color: "blue",
|
|
274
|
+
dx: 2,
|
|
275
|
+
pal: { r: "#ff3b5c" },
|
|
276
|
+
art: at(9, ["...krrrrrrrrk...", "..krrrrrrrrrrkr.", "...............r"]),
|
|
277
|
+
},
|
|
278
|
+
} satisfies Record<string, Prop>;
|
|
279
|
+
export type PropId = keyof typeof PROPS;
|
|
280
|
+
|
|
281
|
+
export const PROP_IDS = Object.keys(PROPS) as PropId[];
|
|
282
|
+
export const COLOR_IDS = Object.keys(COLORS) as ColorId[];
|
|
283
|
+
|
|
284
|
+
export type ParsedSprite = { prop: PropId; color: ColorId } | { prop: "custom"; color: ColorId };
|
|
285
|
+
|
|
286
|
+
/** 拆成道具和颜色;自画的记成 custom / custom:颜色(默认橙色);不认识的(含旧的生成头像 img:…)返回 undefined。 */
|
|
287
|
+
export function parseSprite(sprite: string): ParsedSprite | undefined {
|
|
288
|
+
if (sprite === "custom") return { prop: "custom", color: "orange" };
|
|
289
|
+
if (sprite.startsWith("custom:")) {
|
|
290
|
+
const color = sprite.slice("custom:".length);
|
|
291
|
+
return Object.hasOwn(COLORS, color) ? { prop: "custom", color: color as ColorId } : undefined;
|
|
292
|
+
}
|
|
293
|
+
const [prop, color, ...rest] = sprite.split(":");
|
|
294
|
+
if (rest.length || !Object.hasOwn(PROPS, prop)) return undefined;
|
|
295
|
+
const p = prop as PropId;
|
|
296
|
+
if (color === undefined) return { prop: p, color: PROPS[p].color };
|
|
297
|
+
return Object.hasOwn(COLORS, color) ? { prop: p, color: color as ColorId } : undefined;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** 自画道具的 sprite:默认颜色(橙)就只写 custom。 */
|
|
301
|
+
export function customSprite(color: ColorId): string {
|
|
302
|
+
return color === "orange" ? "custom" : `custom:${color}`;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const HEX = /^#[0-9a-f]{6}$/;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* 校验 AI 画的自定义道具(前后端共用)。不合格返回清楚的原因,让模型照着改了重画。
|
|
309
|
+
* art 最多 16 行、每行恰好 16 个字符,字符只能是 `.`、`k`(描边色,固定)或 pal 里的键;
|
|
310
|
+
* pal 键是单个小写字母,不能用火苗自己的 o y e 和描边 k,最多 6 种,值是 #rrggbb;
|
|
311
|
+
* 不能盖住火苗的两只眼睛;至少画 6 个像素。
|
|
312
|
+
*/
|
|
313
|
+
export function validateCustomProp(input: unknown): { ok: true; prop: CustomProp } | { ok: false; error: string } {
|
|
314
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) {
|
|
315
|
+
return { ok: false, error: "prop_art 要是一个对象:art(字符串数组)、pal(字母 → 颜色)、dx(0|1|2)" };
|
|
316
|
+
}
|
|
317
|
+
const { art, pal, dx } = input as Record<string, unknown>;
|
|
318
|
+
if (!Array.isArray(art) || art.length === 0) return { ok: false, error: "prop_art.art 要是非空的字符串数组" };
|
|
319
|
+
if (art.length > SIZE) return { ok: false, error: `prop_art.art 最多 ${SIZE} 行,收到 ${art.length} 行` };
|
|
320
|
+
for (const row of art) {
|
|
321
|
+
if (typeof row !== "string") return { ok: false, error: "prop_art.art 的每行都要是字符串" };
|
|
322
|
+
if ([...row].length !== SIZE) {
|
|
323
|
+
return { ok: false, error: `prop_art.art 每行要正好 ${SIZE} 个字符,这一行是 ${[...row].length} 个:「${row}」` };
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (!pal || typeof pal !== "object" || Array.isArray(pal)) {
|
|
327
|
+
return { ok: false, error: "prop_art.pal 要是对象:单个小写字母 → #rrggbb" };
|
|
328
|
+
}
|
|
329
|
+
const entries = Object.entries(pal as Record<string, unknown>);
|
|
330
|
+
if (entries.length > 6) return { ok: false, error: `prop_art.pal 最多 6 种颜色,收到 ${entries.length} 种` };
|
|
331
|
+
for (const [key, value] of entries) {
|
|
332
|
+
if (!/^[a-z]$/.test(key)) return { ok: false, error: `pal 的键要是单个小写字母,收到「${key}」` };
|
|
333
|
+
if (key === "k") return { ok: false, error: "pal 不能有 k:描边色是固定的,art 里直接用 k 就行" };
|
|
334
|
+
if ("oye".includes(key)) return { ok: false, error: `pal 不能用 ${key}:这是火苗自己的颜色` };
|
|
335
|
+
if (typeof value !== "string" || !HEX.test(value)) {
|
|
336
|
+
return { ok: false, error: `pal[${key}] 要是 #rrggbb 格式的颜色,收到「${String(value)}」` };
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
const drawn = (art as string[]).join("");
|
|
340
|
+
for (const ch of new Set([...drawn].filter((c) => c !== "."))) {
|
|
341
|
+
if (ch === "k") continue;
|
|
342
|
+
if (!Object.hasOwn(pal as Record<string, unknown>, ch)) {
|
|
343
|
+
return { ok: false, error: `art 里的「${ch}」没有在 pal 里定义颜色` };
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
const pixels = [...drawn].filter((c) => c !== ".").length;
|
|
347
|
+
if (pixels < 6) return { ok: false, error: `至少要画 6 个像素,现在只有 ${pixels} 个` };
|
|
348
|
+
if (dx !== 0 && dx !== 1 && dx !== 2) return { ok: false, error: `prop_art.dx 要是 0、1 或 2,收到 ${String(dx)}` };
|
|
349
|
+
// 火苗两只眼睛在画布的第 12、13 行(第 5 行起是火苗),道具不能盖住
|
|
350
|
+
const top = SIZE - FLAME.length;
|
|
351
|
+
for (let y = 0; y < FLAME.length; y++) {
|
|
352
|
+
for (let x = 0; x < FLAME[y].length; x++) {
|
|
353
|
+
if (FLAME[y][x] !== "e") continue;
|
|
354
|
+
const row = (art as string[])[top + y];
|
|
355
|
+
const ch = row?.[dx + x];
|
|
356
|
+
if (ch && ch !== ".") {
|
|
357
|
+
return {
|
|
358
|
+
ok: false,
|
|
359
|
+
error: `art 第 ${top + y + 1} 行第 ${dx + x + 1} 列会盖住火苗的眼睛,把图案挪开(或调小 dx)`,
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return { ok: true, prop: { art: art as string[], pal: pal as Record<string, string>, dx } };
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** 组回 sprite:颜色就是默认的就只写道具。 */
|
|
368
|
+
export function spriteId(prop: PropId, color: ColorId): string {
|
|
369
|
+
return color === PROPS[prop].color ? prop : `${prop}:${color}`;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* 画出来的样子:16×16 的行、调色板、圆底颜色,以及让图案居中的偏移(按实际像素的包围盒)。
|
|
374
|
+
* sprite 是 custom 时用传入的自画道具(数据坏了或没传就画空手火苗);认不出的画成灰蓝色的空手火苗。都不报错。
|
|
375
|
+
*/
|
|
376
|
+
export function spriteArt(
|
|
377
|
+
sprite: string,
|
|
378
|
+
custom?: CustomProp,
|
|
379
|
+
): {
|
|
380
|
+
rows: string[];
|
|
381
|
+
pal: Record<string, string>;
|
|
382
|
+
bg: string;
|
|
383
|
+
offset: [number, number];
|
|
384
|
+
} {
|
|
385
|
+
const parsed: ParsedSprite = parseSprite(sprite) ?? { prop: "hob", color: "slate" };
|
|
386
|
+
const checked = parsed.prop === "custom" && custom ? validateCustomProp(custom) : undefined;
|
|
387
|
+
const overlay: Pick<Prop, "dx" | "pal" | "art"> =
|
|
388
|
+
parsed.prop === "custom" ? (checked?.ok ? checked.prop : PROPS.hob) : PROPS[parsed.prop];
|
|
389
|
+
const c = COLORS[parsed.color];
|
|
390
|
+
const rows = [...Array<string>(SIZE - FLAME.length).fill(""), ...FLAME].map((row, y) => {
|
|
391
|
+
const base = row ? `${".".repeat(overlay.dx)}${row}`.padEnd(SIZE, ".") : ".".repeat(SIZE);
|
|
392
|
+
const over = overlay.art[y] ?? "";
|
|
393
|
+
return [...base].map((ch, x) => (over[x] && over[x] !== "." ? over[x] : ch)).join("");
|
|
394
|
+
});
|
|
395
|
+
let [x0, y0, x1, y1] = [SIZE, SIZE, 0, 0];
|
|
396
|
+
rows.forEach((row, y) =>
|
|
397
|
+
[...row].forEach((ch, x) => {
|
|
398
|
+
if (ch === ".") return;
|
|
399
|
+
[x0, y0, x1, y1] = [Math.min(x0, x), Math.min(y0, y), Math.max(x1, x + 1), Math.max(y1, y + 1)];
|
|
400
|
+
}),
|
|
401
|
+
);
|
|
402
|
+
return {
|
|
403
|
+
rows,
|
|
404
|
+
pal: { k: INK, e: INK, o: c.o, y: c.y, ...overlay.pal },
|
|
405
|
+
bg: c.bg,
|
|
406
|
+
offset: [(x0 + x1 - SIZE) / 2, (y0 + y1 - SIZE) / 2],
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** 新建助手时:已有助手用着同一个头像就换成这件道具还没人用的颜色(橙色留给 Hob);自画的图案各不相同,不算撞。 */
|
|
411
|
+
export function distinctSprite(sprite: string, taken: string[]): string {
|
|
412
|
+
const want = parseSprite(sprite);
|
|
413
|
+
if (!want || want.prop === "custom") return sprite;
|
|
414
|
+
const key = (s: string) => {
|
|
415
|
+
const p = parseSprite(s);
|
|
416
|
+
return p ? `${p.prop}:${p.color}` : s;
|
|
417
|
+
};
|
|
418
|
+
const used = new Set(taken.map(key));
|
|
419
|
+
if (!used.has(`${want.prop}:${want.color}`)) return sprite;
|
|
420
|
+
const free = COLOR_IDS.find((c) => c !== "orange" && !used.has(`${want.prop}:${c}`));
|
|
421
|
+
return free ? spriteId(want.prop, free) : sprite;
|
|
422
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// 思考档的规则:7 个标准档、默认档位、写给引擎的稀疏 thinkingLevelMap。前后端和假后端共用一份,别各写一遍。
|
|
2
|
+
import type { ThinkingLevel, ThinkingLevelMapSetting } from "./types.ts";
|
|
3
|
+
|
|
4
|
+
/** 7 个标准档,从低到高(和引擎的 ThinkingLevel 一致)。 */
|
|
5
|
+
export const THINKING_LEVELS: ThinkingLevel[] = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
6
|
+
|
|
7
|
+
/** 界面和报错用的中文档名。 */
|
|
8
|
+
export const THINKING_TEXT: Record<ThinkingLevel, string> = {
|
|
9
|
+
off: "关闭",
|
|
10
|
+
minimal: "最低",
|
|
11
|
+
low: "低",
|
|
12
|
+
medium: "中",
|
|
13
|
+
high: "高",
|
|
14
|
+
xhigh: "很高",
|
|
15
|
+
max: "最高",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** 思考档字符的长度上限(存得下,也给服务商发得出去)。 */
|
|
19
|
+
export const THINKING_TEXT_MAX = 40;
|
|
20
|
+
|
|
21
|
+
export function isThinkingLevel(value: unknown): value is ThinkingLevel {
|
|
22
|
+
return typeof value === "string" && THINKING_LEVELS.includes(value as ThinkingLevel);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 默认档位(唯一的默认规则):
|
|
27
|
+
* - 会推理的模型 off … max;
|
|
28
|
+
* - 模型 id 含 gpt(不分大小写)的只到 xhigh;
|
|
29
|
+
* - 不会推理的只有 off。
|
|
30
|
+
*/
|
|
31
|
+
export function defaultThinkingLevels(id: string, reasoning: boolean): ThinkingLevel[] {
|
|
32
|
+
if (!reasoning) return ["off"];
|
|
33
|
+
return /gpt/i.test(id) ? THINKING_LEVELS.slice(0, 6) : [...THINKING_LEVELS];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 引擎默认不开 xhigh / max:要开就得在映射里写个值。
|
|
38
|
+
* Google 那套只有 low / medium / high,写档名会被引擎当成不认识的档(请求时直接抛错),
|
|
39
|
+
* 所以在 Google 协议上按它能给的最高档 high 开。
|
|
40
|
+
*/
|
|
41
|
+
function enableText(level: ThinkingLevel, api?: string): string {
|
|
42
|
+
return api === "google-generative-ai" || api === "google-vertex" ? "high" : level;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ThinkingPlan {
|
|
46
|
+
/** Hob 认为这个模型能选的档,从低到高(等于引擎对这个模型算出的可选档) */
|
|
47
|
+
levels: ThinkingLevel[];
|
|
48
|
+
/** 每档现在的字符:用户填的;空串 = 这一档开着,按服务商协议的默认 */
|
|
49
|
+
chars: Partial<Record<ThinkingLevel, string>>;
|
|
50
|
+
/**
|
|
51
|
+
* 写给引擎的 thinkingLevelMap(稀疏):只放必要的键——
|
|
52
|
+
* 用户自己填的字符、要开的 xhigh / max、关掉的档写 null。
|
|
53
|
+
* 没改过的 off、minimal…high 不写:引擎对写了字符串的档会原样发出去,
|
|
54
|
+
* 没写的档才按各协议的默认翻译(off 写字符串会被当成 reasoning_effort 发出去)。
|
|
55
|
+
*/
|
|
56
|
+
map: Partial<Record<ThinkingLevel, string | null>>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 这个模型的思考档:设置里存了自定义就按自定义,没存就按默认规则。
|
|
61
|
+
* 不看引擎注册表里自带的 thinkingLevelMap:Hob 决定有哪些档,引擎只负责按协议把字符发出去。
|
|
62
|
+
*/
|
|
63
|
+
export function thinkingPlan(
|
|
64
|
+
id: string,
|
|
65
|
+
reasoning: boolean,
|
|
66
|
+
custom?: ThinkingLevelMapSetting,
|
|
67
|
+
api?: string,
|
|
68
|
+
): ThinkingPlan {
|
|
69
|
+
if (!reasoning) return { levels: ["off"], chars: {}, map: {} };
|
|
70
|
+
const range = defaultThinkingLevels(id, reasoning);
|
|
71
|
+
const levels: ThinkingLevel[] = [];
|
|
72
|
+
const chars: Partial<Record<ThinkingLevel, string>> = {};
|
|
73
|
+
const map: Partial<Record<ThinkingLevel, string | null>> = {};
|
|
74
|
+
for (const level of THINKING_LEVELS) {
|
|
75
|
+
const value = custom?.[level];
|
|
76
|
+
// 设置里明写了这一档就按它(空串 = 开着的默认字符),没写就按默认范围
|
|
77
|
+
const wanted = value !== undefined ? value !== null : range.includes(level);
|
|
78
|
+
if (!wanted) {
|
|
79
|
+
// 关掉的档写 null:内置服务商的底表里可能开着它
|
|
80
|
+
map[level] = null;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
levels.push(level);
|
|
84
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
85
|
+
chars[level] = text;
|
|
86
|
+
if (text) map[level] = text;
|
|
87
|
+
else if (level === "xhigh" || level === "max") map[level] = enableText(level, api);
|
|
88
|
+
}
|
|
89
|
+
return { levels, chars, map };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 规整一个模型的自定义思考档(读设置文件时用):
|
|
94
|
+
* 只认 7 个标准档;null = 这一档不要;字符串去首尾空白,空串 = 按协议默认;
|
|
95
|
+
* 超长的按没填处理(不因此把这一档删掉);off 不能删。
|
|
96
|
+
* 返回 undefined 表示没有可用的自定义档(用默认规则)。
|
|
97
|
+
*/
|
|
98
|
+
export function normalizeThinkingMap(raw: unknown): ThinkingLevelMapSetting | undefined {
|
|
99
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return undefined;
|
|
100
|
+
const input = raw as Record<string, unknown>;
|
|
101
|
+
const map: ThinkingLevelMapSetting = {};
|
|
102
|
+
let seen = false;
|
|
103
|
+
for (const level of THINKING_LEVELS) {
|
|
104
|
+
if (!(level in input)) continue;
|
|
105
|
+
seen = true;
|
|
106
|
+
const value = input[level];
|
|
107
|
+
if (value === null) {
|
|
108
|
+
map[level] = null;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
112
|
+
map[level] = text.length <= THINKING_TEXT_MAX ? text : "";
|
|
113
|
+
}
|
|
114
|
+
if (!seen) return undefined;
|
|
115
|
+
// off 是关掉思考这一档,不能没有
|
|
116
|
+
if (map.off === null) map.off = "";
|
|
117
|
+
return map;
|
|
118
|
+
}
|