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,129 @@
|
|
|
1
|
+
import { Type } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import type { ApprovalOption } from "../../shared/types.ts";
|
|
4
|
+
import { generateImage } from "./image.ts";
|
|
5
|
+
import type { HobRuntime } from "./runtime.ts";
|
|
6
|
+
|
|
7
|
+
function ok(text: string) {
|
|
8
|
+
return { content: [{ type: "text" as const, text }], details: undefined };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Worker 的收尾工具:必须调用一次提交结果。 */
|
|
12
|
+
export function registerReportTool(runtime: HobRuntime, jobId: string): ToolDefinition<any, any> {
|
|
13
|
+
return {
|
|
14
|
+
name: "report",
|
|
15
|
+
label: "提交结果",
|
|
16
|
+
description:
|
|
17
|
+
"任务结束时必须调用一次,提交结果。summary 用中文写给用户:一两句结论 + 关键数字,不要罗列过程。",
|
|
18
|
+
promptSnippet: "任务结束必须调用 report 提交结果。",
|
|
19
|
+
parameters: Type.Object({
|
|
20
|
+
outcome: Type.Unsafe<"done" | "stuck" | "need_approval">(
|
|
21
|
+
Type.String({ description: "done 已完成 / stuck 受阻 / need_approval 待确认" }),
|
|
22
|
+
),
|
|
23
|
+
summary: Type.String({ description: "中文摘要,一两句结论 + 关键数字,不超过 600 字" }),
|
|
24
|
+
files: Type.Optional(Type.Array(Type.String(), { description: "产出文件的绝对路径" })),
|
|
25
|
+
}),
|
|
26
|
+
execute: async (_id, params: any) => {
|
|
27
|
+
// 不认识的结果不能当成已完成:退回让模型重新调用
|
|
28
|
+
if (params.outcome !== "done" && params.outcome !== "stuck" && params.outcome !== "need_approval") {
|
|
29
|
+
return {
|
|
30
|
+
content: [{ type: "text" as const, text: "outcome 只能是 done、stuck 或 need_approval,请重新调用 report。" }],
|
|
31
|
+
details: undefined,
|
|
32
|
+
isError: true,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
runtime.jobs.reportFromTool(jobId, {
|
|
36
|
+
outcome: params.outcome,
|
|
37
|
+
summary: String(params.summary ?? ""),
|
|
38
|
+
...(Array.isArray(params.files) && params.files.length ? { files: params.files as string[] } : {}),
|
|
39
|
+
});
|
|
40
|
+
return ok("结果已记录。");
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Worker 的询问工具:阻塞等待用户选择一个选项。 */
|
|
46
|
+
export function registerAskTool(runtime: HobRuntime, jobId: string): ToolDefinition<any, any> {
|
|
47
|
+
return {
|
|
48
|
+
name: "ask_user",
|
|
49
|
+
label: "询问用户",
|
|
50
|
+
description: "遇到规则要求执行前确认、或者不可逆的操作时,用这个询问用户,会一直等到用户选择。返回用户选择的选项文字。",
|
|
51
|
+
promptSnippet: "规则要求执行前确认的事,执行前必须调用 ask_user。",
|
|
52
|
+
parameters: Type.Object({
|
|
53
|
+
title: Type.String({ description: "问题,一句话" }),
|
|
54
|
+
detail: Type.Optional(Type.String({ description: "补充说明,写清后果" })),
|
|
55
|
+
options: Type.Array(
|
|
56
|
+
Type.Object({
|
|
57
|
+
label: Type.String({ description: "选项文字" }),
|
|
58
|
+
always: Type.Optional(Type.Boolean({ description: "选中后将这句话记为规则" })),
|
|
59
|
+
}),
|
|
60
|
+
{ description: "2 到 3 个选项", minItems: 2, maxItems: 3 },
|
|
61
|
+
),
|
|
62
|
+
ruleText: Type.Optional(Type.String({ description: "always 选项要写进规则的文字" })),
|
|
63
|
+
}),
|
|
64
|
+
execute: async (_id, params: any) => {
|
|
65
|
+
const labels: { label: string; always?: boolean }[] = Array.isArray(params.options) ? params.options : [];
|
|
66
|
+
if (labels.length < 2 || labels.length > 3) {
|
|
67
|
+
return { content: [{ type: "text" as const, text: "选项要 2 到 3 个。" }], details: undefined, isError: true };
|
|
68
|
+
}
|
|
69
|
+
const options: ApprovalOption[] = labels.map((option, index) => ({
|
|
70
|
+
key: (["A", "B", "C"] as const)[index],
|
|
71
|
+
label: String(option.label),
|
|
72
|
+
...(option.always ? { always: true } : {}),
|
|
73
|
+
}));
|
|
74
|
+
const answer = await runtime.jobs.askQuestion(jobId, {
|
|
75
|
+
title: String(params.title),
|
|
76
|
+
...(params.detail ? { detail: String(params.detail) } : {}),
|
|
77
|
+
options,
|
|
78
|
+
...(params.ruleText ? { ruleText: String(params.ruleText) } : {}),
|
|
79
|
+
});
|
|
80
|
+
// 用户可能没选给出的选项,而是自己写了一段:answer 已经是回给模型的整句
|
|
81
|
+
return ok(answer);
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Worker 的图像生成工具:只在配了图像生成、且这个助手开着这项能力时才注册。 */
|
|
87
|
+
export function registerImageTool(runtime: HobRuntime, jobId: string): ToolDefinition<any, any> {
|
|
88
|
+
return {
|
|
89
|
+
name: "generate_image",
|
|
90
|
+
label: "生成图片",
|
|
91
|
+
description:
|
|
92
|
+
"按文字描述生成一张图片,返回图片的绝对路径(存在任务工作目录)。要把图给用户看,就把这个路径放进 report 的 files。",
|
|
93
|
+
promptSnippet: "生成图片用 generate_image;要给用户看就把它放进 report 的 files。",
|
|
94
|
+
parameters: Type.Object({
|
|
95
|
+
prompt: Type.String({ description: "要画什么,越具体越好" }),
|
|
96
|
+
size: Type.Optional(
|
|
97
|
+
Type.String({ description: "尺寸,如 1024x1024;不填用设置里的默认(有的模型不支持,会忽略)" }),
|
|
98
|
+
),
|
|
99
|
+
refs: Type.Optional(
|
|
100
|
+
Type.Array(Type.String(), { description: "参考图的绝对路径(改图、按图生成的时候给)" }),
|
|
101
|
+
),
|
|
102
|
+
}),
|
|
103
|
+
execute: async (_id, params: any) => {
|
|
104
|
+
const job = runtime.store.job(jobId);
|
|
105
|
+
if (!job) return { content: [{ type: "text" as const, text: "任务不存在。" }], details: undefined, isError: true };
|
|
106
|
+
try {
|
|
107
|
+
const path = await generateImage(
|
|
108
|
+
{
|
|
109
|
+
home: runtime.home,
|
|
110
|
+
dir: job.cwd ?? runtime.store.workDir(jobId),
|
|
111
|
+
config: runtime.settings.settings.image,
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
prompt: String(params.prompt ?? ""),
|
|
115
|
+
...(params.size ? { size: String(params.size) } : {}),
|
|
116
|
+
...(Array.isArray(params.refs) && params.refs.length ? { refs: params.refs.map(String) } : {}),
|
|
117
|
+
},
|
|
118
|
+
);
|
|
119
|
+
return ok(`图片已生成:${path}`);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
return {
|
|
122
|
+
content: [{ type: "text" as const, text: error instanceof Error ? error.message : String(error) }],
|
|
123
|
+
details: undefined,
|
|
124
|
+
isError: true,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// 命令的显示摘要:任务里的命令常套着 `cd 目录 &&`、`timeout 60`、`ssh 主机 'bash -lc "…"'` 这类外壳,
|
|
2
|
+
// 列表只有一行,外壳把真正执行的命令挤掉了。完整命令在任务详情里展开看。
|
|
3
|
+
export function commandSummary(command: string): string {
|
|
4
|
+
let text = command.trim();
|
|
5
|
+
for (;;) {
|
|
6
|
+
const next = text
|
|
7
|
+
.replace(/^cd\s+(?:"[^"]*"|'[^']*'|[^\s;&|]+)\s*(?:&&|;)\s*/, "")
|
|
8
|
+
// timeout 的 -k/-s 后面跟一个值,其余选项单独一个词
|
|
9
|
+
.replace(/^timeout\s+(?:-[ks]\s+\S+\s+|-\S+\s+)*\d+(?:\.\d+)?[smhd]?\s+/, "");
|
|
10
|
+
if (next === text) break;
|
|
11
|
+
text = next;
|
|
12
|
+
}
|
|
13
|
+
// ssh 到别的机器跑的,写成「主机: 命令」
|
|
14
|
+
const ssh = SSH.exec(text);
|
|
15
|
+
if (ssh) {
|
|
16
|
+
let remote = ssh[2];
|
|
17
|
+
const outer = quoted(remote);
|
|
18
|
+
if (outer) {
|
|
19
|
+
let [inner, tail] = outer;
|
|
20
|
+
const shell = /^(?:ba)?sh\s+-l?c\s+/.exec(inner);
|
|
21
|
+
const script = shell ? quoted(inner.slice(shell[0].length)) : undefined;
|
|
22
|
+
if (script) inner = script[0] + script[1];
|
|
23
|
+
remote = inner + tail;
|
|
24
|
+
}
|
|
25
|
+
text = `${ssh[1]}: ${commandSummary(remote)}`;
|
|
26
|
+
}
|
|
27
|
+
return text || command.trim();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ssh 的选项:-o BatchMode=yes、-p 22 这类带一个值,其余单独一个词;之后是主机和要跑的命令
|
|
31
|
+
const SSH = /^ssh\s+(?:-[BbcDEeFIiJLlmOoPpQRSWw]\s*\S+\s+|-[46AaCfGgKkMNnqsTtVvXxYy]+\s+)*([^\s'"-]\S*)\s+(.+)$/s;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 开头一段引号里的内容和剩下的部分。单引号里没有转义;双引号里 \" \\ \$ \` 是转义。
|
|
35
|
+
* 没有收尾的引号也认(旧任务存的是截断到 120 字的命令)。
|
|
36
|
+
*/
|
|
37
|
+
function quoted(text: string): [string, string] | undefined {
|
|
38
|
+
const m = /^'([^']*)'?/.exec(text) ?? /^"((?:[^"\\]|\\.)*)"?/s.exec(text);
|
|
39
|
+
if (!m) return undefined;
|
|
40
|
+
const inner = text[0] === '"' ? m[1].replace(/\\(["\\$`])/g, "$1") : m[1];
|
|
41
|
+
return [inner, text.slice(m[0].length)];
|
|
42
|
+
}
|
package/shared/files.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// 文件预览的种类判定:服务端给 content-type 和元数据、前端挑预览方式都用它。
|
|
2
|
+
// 只看扩展名(不读内容);不认识的扩展名(含无扩展名)返回 undefined,由服务端嗅探开头几个字节。
|
|
3
|
+
|
|
4
|
+
import type { FileKind } from "./types.ts";
|
|
5
|
+
|
|
6
|
+
const KIND_BY_EXT: Record<string, FileKind> = {
|
|
7
|
+
".png": "image",
|
|
8
|
+
".jpg": "image",
|
|
9
|
+
".jpeg": "image",
|
|
10
|
+
".gif": "image",
|
|
11
|
+
".webp": "image",
|
|
12
|
+
".avif": "image",
|
|
13
|
+
".bmp": "image",
|
|
14
|
+
".ico": "image",
|
|
15
|
+
".svg": "svg",
|
|
16
|
+
".pdf": "pdf",
|
|
17
|
+
".mp3": "audio",
|
|
18
|
+
".wav": "audio",
|
|
19
|
+
".ogg": "audio",
|
|
20
|
+
".m4a": "audio",
|
|
21
|
+
".flac": "audio",
|
|
22
|
+
".aac": "audio",
|
|
23
|
+
".mp4": "video",
|
|
24
|
+
".webm": "video",
|
|
25
|
+
".mov": "video",
|
|
26
|
+
".m4v": "video",
|
|
27
|
+
".md": "markdown",
|
|
28
|
+
".markdown": "markdown",
|
|
29
|
+
".json": "json",
|
|
30
|
+
".jsonl": "json",
|
|
31
|
+
".ndjson": "json",
|
|
32
|
+
".csv": "csv",
|
|
33
|
+
".tsv": "csv",
|
|
34
|
+
".html": "html",
|
|
35
|
+
".htm": "html",
|
|
36
|
+
".xml": "xml",
|
|
37
|
+
".ts": "code",
|
|
38
|
+
".tsx": "code",
|
|
39
|
+
".js": "code",
|
|
40
|
+
".jsx": "code",
|
|
41
|
+
".mjs": "code",
|
|
42
|
+
".cjs": "code",
|
|
43
|
+
".py": "code",
|
|
44
|
+
".sh": "code",
|
|
45
|
+
".bash": "code",
|
|
46
|
+
".zsh": "code",
|
|
47
|
+
".go": "code",
|
|
48
|
+
".rs": "code",
|
|
49
|
+
".java": "code",
|
|
50
|
+
".kt": "code",
|
|
51
|
+
".swift": "code",
|
|
52
|
+
".c": "code",
|
|
53
|
+
".h": "code",
|
|
54
|
+
".cc": "code",
|
|
55
|
+
".cpp": "code",
|
|
56
|
+
".hpp": "code",
|
|
57
|
+
".cs": "code",
|
|
58
|
+
".rb": "code",
|
|
59
|
+
".php": "code",
|
|
60
|
+
".scala": "code",
|
|
61
|
+
".lua": "code",
|
|
62
|
+
".pl": "code",
|
|
63
|
+
".css": "code",
|
|
64
|
+
".scss": "code",
|
|
65
|
+
".less": "code",
|
|
66
|
+
".vue": "code",
|
|
67
|
+
".svelte": "code",
|
|
68
|
+
".yaml": "code",
|
|
69
|
+
".yml": "code",
|
|
70
|
+
".toml": "code",
|
|
71
|
+
".ini": "code",
|
|
72
|
+
".conf": "code",
|
|
73
|
+
".cfg": "code",
|
|
74
|
+
".properties": "code",
|
|
75
|
+
".sql": "code",
|
|
76
|
+
".graphql": "code",
|
|
77
|
+
".proto": "code",
|
|
78
|
+
".diff": "code",
|
|
79
|
+
".patch": "code",
|
|
80
|
+
".log": "text",
|
|
81
|
+
".txt": "text",
|
|
82
|
+
".text": "text",
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const MIME_BY_EXT: Record<string, string> = {
|
|
86
|
+
".png": "image/png",
|
|
87
|
+
".jpg": "image/jpeg",
|
|
88
|
+
".jpeg": "image/jpeg",
|
|
89
|
+
".gif": "image/gif",
|
|
90
|
+
".webp": "image/webp",
|
|
91
|
+
".avif": "image/avif",
|
|
92
|
+
".bmp": "image/bmp",
|
|
93
|
+
".ico": "image/x-icon",
|
|
94
|
+
".svg": "image/svg+xml",
|
|
95
|
+
".pdf": "application/pdf",
|
|
96
|
+
".mp3": "audio/mpeg",
|
|
97
|
+
".wav": "audio/wav",
|
|
98
|
+
".ogg": "audio/ogg",
|
|
99
|
+
".m4a": "audio/mp4",
|
|
100
|
+
".flac": "audio/flac",
|
|
101
|
+
".aac": "audio/aac",
|
|
102
|
+
".mp4": "video/mp4",
|
|
103
|
+
".webm": "video/webm",
|
|
104
|
+
".mov": "video/quicktime",
|
|
105
|
+
".m4v": "video/mp4",
|
|
106
|
+
".md": "text/markdown; charset=utf-8",
|
|
107
|
+
".markdown": "text/markdown; charset=utf-8",
|
|
108
|
+
".json": "application/json; charset=utf-8",
|
|
109
|
+
".jsonl": "application/x-ndjson; charset=utf-8",
|
|
110
|
+
".ndjson": "application/x-ndjson; charset=utf-8",
|
|
111
|
+
".csv": "text/csv; charset=utf-8",
|
|
112
|
+
".tsv": "text/tab-separated-values; charset=utf-8",
|
|
113
|
+
".html": "text/html; charset=utf-8",
|
|
114
|
+
".htm": "text/html; charset=utf-8",
|
|
115
|
+
".xml": "application/xml; charset=utf-8",
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
function extension(name: string): string {
|
|
119
|
+
const dot = name.lastIndexOf(".");
|
|
120
|
+
return dot > 0 ? name.slice(dot).toLowerCase() : "";
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** 按扩展名判种类;不认识的扩展名(含无扩展名)返回 undefined。 */
|
|
124
|
+
export function fileKind(name: string): FileKind | undefined {
|
|
125
|
+
return KIND_BY_EXT[extension(name)];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** 按扩展名给 content-type;不认识的就是二进制。 */
|
|
129
|
+
export function mimeOf(name: string): string {
|
|
130
|
+
return MIME_BY_EXT[extension(name)] ?? "application/octet-stream";
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 这种文件是不是按文本处理(预览面板要不要拉内容、超过 1 MB 要不要截)。
|
|
135
|
+
* svg 不算:它按图片显示,不按文本。
|
|
136
|
+
*/
|
|
137
|
+
export function isTextKind(kind: FileKind): boolean {
|
|
138
|
+
return (
|
|
139
|
+
kind === "markdown" || kind === "json" || kind === "csv" || kind === "html" || kind === "xml" || kind === "code" || kind === "text"
|
|
140
|
+
);
|
|
141
|
+
}
|
package/shared/media.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// 图片种类的判定:前后端共用(Worker 认附件、任务收尾发图、对话里渲染缩略图都用它)。
|
|
2
|
+
|
|
3
|
+
/** 能当图片处理的扩展名 → MIME。 */
|
|
4
|
+
export const IMAGE_TYPES: Record<string, string> = {
|
|
5
|
+
".png": "image/png",
|
|
6
|
+
".jpg": "image/jpeg",
|
|
7
|
+
".jpeg": "image/jpeg",
|
|
8
|
+
".gif": "image/gif",
|
|
9
|
+
".webp": "image/webp",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/** 按扩展名判断是不是图片(不读文件)。 */
|
|
13
|
+
export function isImagePath(path: string): boolean {
|
|
14
|
+
const dot = path.lastIndexOf(".");
|
|
15
|
+
if (dot === -1) return false;
|
|
16
|
+
return path.slice(dot).toLowerCase() in IMAGE_TYPES;
|
|
17
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ModelScores } from "./types.ts";
|
|
2
|
+
|
|
3
|
+
export const SCORE_STAGES = {
|
|
4
|
+
smart: [{ value: 25, label: "一般" }, { value: 50, label: "较聪明" }, { value: 75, label: "很聪明" }, { value: 100, label: "最聪明" }],
|
|
5
|
+
cost: [{ value: 0, label: "免费" }, { value: 20, label: "很低" }, { value: 50, label: "中等" }, { value: 75, label: "较高" }, { value: 100, label: "特别贵" }],
|
|
6
|
+
speed: [{ value: 25, label: "较慢" }, { value: 50, label: "中等" }, { value: 75, label: "较快" }, { value: 100, label: "很快" }],
|
|
7
|
+
} as const;
|
|
8
|
+
|
|
9
|
+
// 只按公开的模型家族名称推测;轻量型号优先于 pro 等宽泛规则。
|
|
10
|
+
export function guessModelScores(model: { id: string; name: string; reasoning: boolean }): ModelScores {
|
|
11
|
+
const name = `${model.id} ${model.name}`;
|
|
12
|
+
if (/(?:^|[^a-z])mini|haiku|lite/i.test(name)) return { smart: 40, cost: 10, speed: 95 };
|
|
13
|
+
if (/flash/i.test(name)) return { smart: 60, cost: 20, speed: 85 };
|
|
14
|
+
if (/gpt[-\s]?[56](?:\D|$)|opus|pro|sol/i.test(name)) return { smart: 90, cost: 80, speed: 40 };
|
|
15
|
+
return model.reasoning ? { smart: 70, cost: 50, speed: 50 } : { smart: 50, cost: 50, speed: 60 };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function scoreLabel(kind: keyof ModelScores, value: number): string {
|
|
19
|
+
return SCORE_STAGES[kind].reduce((closest, stage) => Math.abs(stage.value - value) < Math.abs(closest.value - value) ? stage : closest).label;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function scoreSummary(scores: ModelScores): string {
|
|
23
|
+
return `聪明 ${scores.smart}% · 成本 ${scores.cost}% · 速度 ${scores.speed}%`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function contextText(contextWindow: number): string {
|
|
27
|
+
if (contextWindow >= 1_000_000) {
|
|
28
|
+
const millions = contextWindow / 1_000_000;
|
|
29
|
+
return `${Number.isInteger(millions) ? millions : millions.toFixed(1)}M`;
|
|
30
|
+
}
|
|
31
|
+
return `${Math.round(contextWindow / 1000)}K`;
|
|
32
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// 沙箱不允许弹窗;将用户点击的外链交给预览面板打开。离线单独打开时自行开新窗口。
|
|
2
|
+
const linkScript = `document.addEventListener('click',function(e){if(!e.isTrusted)return;const a=e.target.closest('a[href]');if(!a||!/^https?:\\/\\//i.test(a.getAttribute('href')||''))return;let u;try{u=new URL(a.href)}catch{return}if(!['http:','https:'].includes(u.protocol))return;e.preventDefault();if(window.parent!==window)window.parent.postMessage({type:'hob-page-link',url:u.href},'*');else window.open(u.href,'_blank','noopener')});`;
|
|
3
|
+
// 预览面板用 #dark / #light 传 Hob 当前的明暗;单独打开时跟随系统
|
|
4
|
+
// 手机上宽表格、宽图在自己的框里横向滚动:图按 viewBox 不缩到 0.75 倍以下,否则文字看不清
|
|
5
|
+
const fitScript = `addEventListener('DOMContentLoaded',function(){document.querySelectorAll('main table').forEach(function(t){if(t.parentElement.classList.contains('tw'))return;var w=document.createElement('div');w.className='tw';t.before(w);w.append(t)});document.querySelectorAll('main figure>svg').forEach(function(g){var v=g.viewBox&&g.viewBox.baseVal;if(v&&v.width)g.style.minWidth=Math.round(v.width*0.75)+'px'})});`;
|
|
6
|
+
const themeScript = `(function(){function f(){var h=location.hash;document.documentElement.classList.toggle('dark',h==='#dark'||(h!=='#light'&&matchMedia('(prefers-color-scheme: dark)').matches))}f();addEventListener('hashchange',f)})();`;
|
|
7
|
+
|
|
8
|
+
// 页面只能用内联样式和脚本,外部只允许 https 图片;不能联网取数据
|
|
9
|
+
const csp = "default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; img-src data: https:; media-src data: https:; font-src data:";
|
|
10
|
+
|
|
11
|
+
const css = `:root{--bg:#fff;--soft:#f5f5f2;--line:#e8e8e5;--ink:#18181a;--muted:#6d6d72;--faint:#a4a4a9;--accent:#ff6a2b;--accent-soft:#fff0e7;--ok:#1f9a5f;--ok-soft:#e8f5ee;--warn:#b7740a;--warn-soft:#fbf2df;--bad:#d92d20;--bad-soft:#fcebe9;color-scheme:light}
|
|
12
|
+
:root.dark{--bg:#151516;--soft:#1f1f21;--line:#2c2c2f;--ink:#ececed;--muted:#a1a1a7;--faint:#6b6b71;--accent:#ff7a42;--accent-soft:#36211a;--ok:#3cc183;--ok-soft:#15281e;--warn:#e9a53a;--warn-soft:#2c2414;--bad:#ff6b5e;--bad-soft:#321b19;color-scheme:dark}
|
|
13
|
+
*{box-sizing:border-box}
|
|
14
|
+
html{background:var(--bg);color:var(--ink);font:16px/1.75 system-ui,-apple-system,"PingFang SC","Hiragino Sans GB","Noto Sans CJK SC","Microsoft YaHei",sans-serif;-webkit-text-size-adjust:100%;text-rendering:optimizeLegibility}
|
|
15
|
+
body{margin:0;padding:52px 24px 80px}
|
|
16
|
+
.page{max-width:760px;margin:0 auto}
|
|
17
|
+
.hd{margin-bottom:40px;padding-bottom:28px;border-bottom:1px solid var(--line)}
|
|
18
|
+
.hd h1{font-size:32px;line-height:1.25;letter-spacing:-.015em;margin:0 0 10px;font-weight:700}
|
|
19
|
+
.hd p{margin:0;color:var(--muted);font-size:17px;line-height:1.6}
|
|
20
|
+
h2{font-size:22px;line-height:1.35;letter-spacing:-.01em;margin:48px 0 14px;font-weight:700}
|
|
21
|
+
h3{font-size:16.5px;line-height:1.45;margin:28px 0 8px;font-weight:650}
|
|
22
|
+
main>h2:first-child,main>section:first-child>h2:first-child{margin-top:0}
|
|
23
|
+
p,ul,ol,table,pre,figure,blockquote,.note,.cards,.cols,.kpis,.steps{margin:0 0 18px}
|
|
24
|
+
ul,ol{padding-left:1.4em}li{margin:5px 0}li::marker{color:var(--faint)}
|
|
25
|
+
a{color:var(--accent);text-decoration:none;border-bottom:1px solid color-mix(in srgb,var(--accent) 35%,transparent)}
|
|
26
|
+
strong,b{font-weight:650}
|
|
27
|
+
.muted{color:var(--muted)}.accent{color:var(--accent)}.ok{color:var(--ok)}.warn{color:var(--warn)}.bad{color:var(--bad)}
|
|
28
|
+
code{font:.88em/1.5 ui-monospace,"SF Mono","JetBrains Mono",Menlo,Consolas,monospace;background:var(--soft);padding:.12em .4em;border-radius:5px}
|
|
29
|
+
pre{background:var(--soft);border-radius:12px;padding:14px 18px;overflow:auto;line-height:1.6}pre code{background:none;padding:0;font-size:13.5px}
|
|
30
|
+
blockquote{border-left:3px solid var(--line);padding:2px 0 2px 16px;color:var(--muted)}
|
|
31
|
+
hr{border:0;border-top:1px solid var(--line);margin:36px 0}
|
|
32
|
+
table{width:100%;border-collapse:collapse;font-size:14.5px;line-height:1.6}
|
|
33
|
+
.tw{overflow-x:auto;margin:0 0 18px}.tw>table{margin:0}
|
|
34
|
+
th,td{text-align:left;padding:10px 12px;border-bottom:1px solid var(--line);vertical-align:top}
|
|
35
|
+
th{font-size:13px;font-weight:600;color:var(--muted);border-bottom-width:1.5px;white-space:nowrap}
|
|
36
|
+
td{min-width:5.5em}
|
|
37
|
+
th:first-child,td:first-child{padding-left:0}th:last-child,td:last-child{padding-right:0}
|
|
38
|
+
.cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:12px}
|
|
39
|
+
.card{background:var(--soft);border-radius:14px;padding:16px 18px}.card h3{margin:0 0 6px;font-size:15.5px}
|
|
40
|
+
.cols{display:grid;grid-template-columns:repeat(auto-fit,minmax(260px,1fr));gap:16px 28px}
|
|
41
|
+
.cols>div>h3:first-child{margin-top:0}
|
|
42
|
+
.kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:12px}
|
|
43
|
+
.kpi{border:1px solid var(--line);border-radius:14px;padding:14px 16px 12px}
|
|
44
|
+
.kpi b{display:block;font-size:28px;line-height:1.2;font-weight:700;letter-spacing:-.02em;font-variant-numeric:tabular-nums}.kpi span{color:var(--muted);font-size:13.5px}
|
|
45
|
+
.steps{list-style:none;padding:0;counter-reset:s}
|
|
46
|
+
.steps>li{position:relative;margin:0;padding:1px 0 20px 44px;counter-increment:s}
|
|
47
|
+
.steps>li::before{content:counter(s);position:absolute;left:0;top:0;width:28px;height:28px;border-radius:50%;background:var(--accent-soft);color:var(--accent);font-weight:700;font-size:14px;line-height:28px;text-align:center}
|
|
48
|
+
.steps>li::after{content:"";position:absolute;left:13.5px;top:34px;bottom:6px;width:1px;background:var(--line)}
|
|
49
|
+
.steps>li:last-child{padding-bottom:0}.steps>li:last-child::after{display:none}.steps>li>b:first-child{display:block}
|
|
50
|
+
.note{border-radius:12px;padding:12px 16px;background:var(--accent-soft)}.note.ok{background:var(--ok-soft)}.note.warn{background:var(--warn-soft)}.note.bad{background:var(--bad-soft)}
|
|
51
|
+
.card>:last-child,.note>:last-child,.cols>div>:last-child,section>:last-child{margin-bottom:0}
|
|
52
|
+
.tag{display:inline-block;font-size:12px;line-height:1.7;padding:0 8px;border-radius:99px;background:var(--soft);color:var(--muted);vertical-align:.08em;white-space:nowrap}
|
|
53
|
+
.card .tag{background:var(--bg)}
|
|
54
|
+
.tag.accent{background:var(--accent-soft);color:var(--accent)}.tag.ok{background:var(--ok-soft);color:var(--ok)}.tag.warn{background:var(--warn-soft);color:var(--warn)}.tag.bad{background:var(--bad-soft);color:var(--bad)}
|
|
55
|
+
figure{margin:28px 0;overflow-x:auto}img,svg{max-width:100%;height:auto}figure>svg,figure>img{display:block;margin:0 auto}
|
|
56
|
+
figcaption{color:var(--muted);font-size:13.5px;margin-top:10px;text-align:center}
|
|
57
|
+
svg{color:var(--ink)}svg text{fill:var(--ink);font-family:inherit;font-size:13px}
|
|
58
|
+
svg .box{fill:var(--bg);stroke:var(--line);stroke-width:1.5}svg .hl{fill:var(--accent-soft);stroke:var(--accent);stroke-width:1.5}
|
|
59
|
+
svg .line{fill:none;stroke:var(--faint);stroke-width:1.5}svg text.muted{fill:var(--muted)}svg text.accent{fill:var(--accent)}
|
|
60
|
+
@media (max-width:600px){body{padding:32px 18px 64px}.hd{margin-bottom:32px}.hd h1{font-size:26px}h2{font-size:19.5px;margin-top:40px}}`;
|
|
61
|
+
|
|
62
|
+
const escape = (text: string) => text.replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]!);
|
|
63
|
+
|
|
64
|
+
export function livePageHtml(): string {
|
|
65
|
+
const script = `
|
|
66
|
+
(function(){
|
|
67
|
+
let latest, scheduled = false, follow = true;
|
|
68
|
+
addEventListener('scroll', function(){ follow = document.documentElement.scrollHeight - innerHeight - scrollY < 48; }, {passive:true});
|
|
69
|
+
addEventListener('message', function(e){
|
|
70
|
+
if(e.source !== parent || e.data?.type !== 'hob-page-live') return;
|
|
71
|
+
latest = e.data;
|
|
72
|
+
if(scheduled) return;
|
|
73
|
+
scheduled = true;
|
|
74
|
+
requestAnimationFrame(function(){
|
|
75
|
+
scheduled = false;
|
|
76
|
+
document.documentElement.classList.toggle('dark', !!latest.dark);
|
|
77
|
+
document.title = latest.title || '';
|
|
78
|
+
document.querySelector('.hd h1').textContent = latest.title || '';
|
|
79
|
+
document.querySelector('.hd p').textContent = latest.summary || '';
|
|
80
|
+
const main = document.querySelector('main');
|
|
81
|
+
const template = document.createElement('template');
|
|
82
|
+
template.innerHTML = (latest.html || '').replace(/<[^>]*$/, '');
|
|
83
|
+
template.content.querySelectorAll('script,iframe,object,embed').forEach(function(el){el.remove()});
|
|
84
|
+
template.content.querySelectorAll('*').forEach(function(el){
|
|
85
|
+
Array.from(el.attributes).forEach(function(a){if(/^on/i.test(a.name)||a.name.toLowerCase()==='srcdoc'||/^\\s*javascript:/i.test(a.value))el.removeAttribute(a.name)});
|
|
86
|
+
});
|
|
87
|
+
main.innerHTML = template.innerHTML;
|
|
88
|
+
main.querySelectorAll('table').forEach(function(t){const w=document.createElement('div');w.className='tw';t.before(w);w.append(t)});
|
|
89
|
+
main.querySelectorAll('figure>svg').forEach(function(g){const v=g.viewBox&&g.viewBox.baseVal;if(v&&v.width)g.style.minWidth=Math.round(v.width*.75)+'px'});
|
|
90
|
+
if(follow) scrollTo(0, document.documentElement.scrollHeight);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
})();`;
|
|
94
|
+
return pageHtml("", "", "").replace("</body>", `<script>${script}</script></body>`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function pageHtml(title: string, summary: string, body: string): string {
|
|
98
|
+
return `<!doctype html>
|
|
99
|
+
<html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
100
|
+
<meta http-equiv="Content-Security-Policy" content="${csp}">
|
|
101
|
+
<title>${escape(title)}</title><script>${themeScript}${fitScript}</script><style>${css}</style></head>
|
|
102
|
+
<body><div class="page"><header class="hd"><h1>${escape(title)}</h1><p>${escape(summary)}</p></header>
|
|
103
|
+
<main>
|
|
104
|
+
${body}
|
|
105
|
+
</main></div><script>${linkScript}</script></body></html>
|
|
106
|
+
`;
|
|
107
|
+
}
|
|
108
|
+
|
package/shared/search.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const SEARCH_PROVIDERS = ["searxng", "exa", "tavily", "brave", "serper", "jina", "firecrawl", "perplexity", "youcom", "ollama"] as const;
|
|
2
|
+
export type SearchProviderName = typeof SEARCH_PROVIDERS[number];
|
|
3
|
+
export interface SearchProviderSetting { name: SearchProviderName; enabled: boolean; baseUrl?: string }
|
|
4
|
+
export type SearchSettings = SearchProviderSetting[];
|
|
5
|
+
export interface SearchView { providers: (SearchProviderSetting & { keyConfigured: boolean })[] }
|
|
6
|
+
|
|
7
|
+
export function defaultSearch(): SearchSettings {
|
|
8
|
+
return SEARCH_PROVIDERS.map((name) => ({ name, enabled: false }));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function normalizeSearch(raw: unknown): SearchSettings {
|
|
12
|
+
const entries = Array.isArray(raw) ? raw : [];
|
|
13
|
+
const result: SearchSettings = [];
|
|
14
|
+
for (const entry of entries) {
|
|
15
|
+
if (!entry || typeof entry !== "object" || !SEARCH_PROVIDERS.includes(entry.name) || result.some((p) => p.name === entry.name)) continue;
|
|
16
|
+
result.push({ name: entry.name, enabled: entry.enabled === true, ...(typeof entry.baseUrl === "string" && entry.baseUrl.trim() ? { baseUrl: entry.baseUrl.trim() } : {}) });
|
|
17
|
+
}
|
|
18
|
+
return [...result, ...defaultSearch().filter((p) => !result.some((entry) => entry.name === p.name))];
|
|
19
|
+
}
|
package/shared/skills.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type SkillSource = "hob" | "lore" | "common";
|
|
2
|
+
export type SkillImportSource = "pi" | "claude" | "codex";
|
|
3
|
+
|
|
4
|
+
export interface SkillView {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
source: SkillSource;
|
|
9
|
+
content: string;
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
overridden: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface SkillsView {
|
|
15
|
+
skills: SkillView[];
|
|
16
|
+
loreActive: boolean;
|
|
17
|
+
loreUrl: string | null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ImportSkill {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
description: string;
|
|
24
|
+
exists: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface SkillImportView {
|
|
28
|
+
found: boolean;
|
|
29
|
+
skills: ImportSkill[];
|
|
30
|
+
skipped: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface SkillImportResult {
|
|
34
|
+
imported: string[];
|
|
35
|
+
skipped: string[];
|
|
36
|
+
errors: string[];
|
|
37
|
+
}
|