dsh-learning-assistant 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -7
- package/assets/collect/README.md +55 -0
- package/assets/skills/course-inbox-sync.md +182 -0
- package/assets/skills/course-material-digest.md +173 -0
- package/assets/skills/one-to-one-tutor.md +320 -0
- package/assets/tools/pdf/pdf-render.ps1 +30 -0
- package/assets/tools/pptx-digest.py +99 -0
- package/assets/tools/pptx-map.py +98 -0
- package/assets/tools/pptx-media.py +101 -0
- package/assets/tools/qq-group-msg.py +258 -0
- package/assets/tools/qq-group-sync.py +265 -0
- package/docs//345/215/217/344/275/234/345/274/200/345/217/221.md +18 -10
- package/lib/client.js +110 -0
- package/lib/{index.d.mts → index.d.ts} +3 -1
- package/lib/index.js +392 -0
- package/package.json +8 -7
- package/src/client/settings.tsx +6 -4
- package/src/index.ts +36 -11
- package/src/practice/learn/api.mjs +393 -0
- package/src/practice/learn/cli.mjs +175 -0
- package/src/practice/learn/curriculum.mjs +292 -0
- package/src/practice/learn/handoff.mjs +73 -0
- package/src/practice/learn/jsonschema.mjs +171 -0
- package/src/practice/learn/mapping.mjs +90 -0
- package/src/practice/learn/progress.mjs +247 -0
- package/src/practice/learn/schema/curriculum.schema.json +88 -0
- package/src/practice/learn/schema/handoff.schema.json +56 -0
- package/src/practice/learn/schema/node-practice-map.schema.json +28 -0
- package/src/practice/learn/schema/progress.schema.json +66 -0
- package/src/practice/learn/schemas.mjs +53 -0
- package/src/practice/learn/store.mjs +247 -0
- package/src/practice/public/app.js +883 -0
- package/src/practice/public/index.html +19 -0
- package/src/practice/public/ink.js +349 -0
- package/src/practice/public/learn.css +20 -0
- package/src/practice/public/learn.js +329 -0
- package/src/practice/public/style.css +326 -0
- package/src/practice/public/vendor/katex/contrib/auto-render.min.js +1 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_AMS-Regular.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_Main-Bold.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_Main-Italic.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_Main-Regular.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_Math-Italic.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_Script-Regular.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_Size1-Regular.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_Size2-Regular.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_Size3-Regular.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_Size4-Regular.woff2 +0 -0
- package/src/practice/public/vendor/katex/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
- package/src/practice/public/vendor/katex/katex.min.css +1 -0
- package/src/practice/public/vendor/katex/katex.min.js +1 -0
- package/src/practice//346/234/215/345/212/241.mjs +443 -0
- package/src/practice//346/240/241/351/252/214/351/242/230/347/233/256.mjs +114 -0
- package/src/practice//347/255/211/345/276/205/346/217/220/344/272/244.mjs +100 -0
- package/src/practice-service.ts +99 -0
- package/src/practice-tool.ts +91 -0
- package/src/skills.ts +156 -0
- package/lib/client.d.mts +0 -10
- package/lib/client.mjs +0 -87
- package/lib/index.mjs +0 -29
package/lib/client.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "dsh-learning-assistant",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
+
let react = require("react");
|
|
8
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
+
// src/client/settings.tsx
|
|
10
|
+
/** 设置对话框里的分区 id。 */
|
|
11
|
+
const SECTION_ID = "dsh-learning-assistant";
|
|
12
|
+
/** 三个板块,顺序即页面顺序。 */
|
|
13
|
+
const TABS = [
|
|
14
|
+
{
|
|
15
|
+
id: "material",
|
|
16
|
+
label: "资料整理"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: "teach",
|
|
20
|
+
label: "知识整理与讲解"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: "data",
|
|
24
|
+
label: "学习助手数据"
|
|
25
|
+
}
|
|
26
|
+
];
|
|
27
|
+
/**
|
|
28
|
+
* 三分区页面。
|
|
29
|
+
* @returns 设置页内容。
|
|
30
|
+
*/
|
|
31
|
+
function LearningAssistantSection() {
|
|
32
|
+
const [active, setActive] = (0, react.useState)(TABS[0].id);
|
|
33
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
34
|
+
style: {
|
|
35
|
+
display: "flex",
|
|
36
|
+
flexDirection: "column",
|
|
37
|
+
gap: 12
|
|
38
|
+
},
|
|
39
|
+
children: [
|
|
40
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("nav", {
|
|
41
|
+
style: {
|
|
42
|
+
display: "flex",
|
|
43
|
+
gap: 8,
|
|
44
|
+
borderBottom: "1px solid var(--dsh-border, #e5e7eb)"
|
|
45
|
+
},
|
|
46
|
+
children: TABS.map((tab) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
47
|
+
onClick: () => setActive(tab.id),
|
|
48
|
+
style: {
|
|
49
|
+
padding: "6px 10px",
|
|
50
|
+
border: "none",
|
|
51
|
+
background: "none",
|
|
52
|
+
cursor: "pointer",
|
|
53
|
+
fontWeight: active === tab.id ? 600 : 400,
|
|
54
|
+
borderBottom: active === tab.id ? "2px solid currentColor" : "2px solid transparent"
|
|
55
|
+
},
|
|
56
|
+
children: tab.label
|
|
57
|
+
}, tab.id))
|
|
58
|
+
}),
|
|
59
|
+
active === "material" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", { children: [
|
|
60
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: "资料整理" }),
|
|
61
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "采集脚本随插件分发(assets/tools):QQ 群文件与群消息走 NapCat OneBot HTTP;企业微信走 UIA 白名单采集;微信 4.x 不做(待社区适配)。" }),
|
|
62
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "白名单纪律:只采集下面配置里点名的群。群号 / NapCat 地址与令牌 / 下载根的接线在阶段 4 服务化时提供表单。" })
|
|
63
|
+
] }),
|
|
64
|
+
active === "teach" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", { children: [
|
|
65
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: "知识整理与讲解" }),
|
|
66
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "三个技能已随插件内嵌:course-material-digest(资料整理)、one-to-one-tutor(一对一带学)、course-inbox-sync(跨平台收件箱 + DDL)。无需另装技能文件。" }),
|
|
67
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "按学科选择讲解方案(粒度、是否先出导图、例题风格)在阶段 3 方案层提供。" })
|
|
68
|
+
] }),
|
|
69
|
+
active === "data" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", { children: [
|
|
70
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: "学习助手数据" }),
|
|
71
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", { children: [
|
|
72
|
+
"课程计划、学习历史、作答记录落在「数据根目录」配置指向的位置(默认 ",
|
|
73
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: "<DSH_HOME>/learning-assistant/data" }),
|
|
74
|
+
";指向某个工作区根时直接用其 练习台/ 与 学习助手数据/ 子目录)。"
|
|
75
|
+
] }),
|
|
76
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "练习台按需启动:对话里让助手调用 practice_desk 工具(action=open)即可,已有健康实例会自动复用,不会重复起服务。" })
|
|
77
|
+
] })
|
|
78
|
+
]
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 注册设置页分区。
|
|
83
|
+
* @param ctx - 客户端根上下文。
|
|
84
|
+
*/
|
|
85
|
+
function registerSettingsSection(ctx) {
|
|
86
|
+
const slots = ctx.slots;
|
|
87
|
+
slots.inject("settings.section", () => slots.register({
|
|
88
|
+
name: "settings.section",
|
|
89
|
+
id: SECTION_ID,
|
|
90
|
+
order: 96,
|
|
91
|
+
label: () => "学习助手"
|
|
92
|
+
}, LearningAssistantSection));
|
|
93
|
+
}
|
|
94
|
+
// src/client/index.tsx
|
|
95
|
+
const name = "dsh-learning-assistant";
|
|
96
|
+
/** 只要 slot 注册表;其余能力(locale、configForms)在页面里按需查找。 */
|
|
97
|
+
const inject = ["slots"];
|
|
98
|
+
/**
|
|
99
|
+
* 注册设置页分区。
|
|
100
|
+
* @param ctx - 客户端根上下文。
|
|
101
|
+
*/
|
|
102
|
+
function apply(ctx) {
|
|
103
|
+
registerSettingsSection(ctx);
|
|
104
|
+
}
|
|
105
|
+
exports.apply = apply;
|
|
106
|
+
exports.inject = inject;
|
|
107
|
+
exports.name = name;
|
|
108
|
+
return module.exports;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
@@ -4,6 +4,8 @@ import { Context } from "@deepseek-ai/cordis";
|
|
|
4
4
|
declare const name = "dsh-learning-assistant";
|
|
5
5
|
/** 需要宿主提供的服务:工具注册表、技能注册表、文件系统接缝。 */
|
|
6
6
|
declare const inject: string[];
|
|
7
|
+
/** 练习台默认端口(学习区原版口径)。 */
|
|
8
|
+
declare const DEFAULT_PORT = 18800;
|
|
7
9
|
/** 部署配置(设置页表单由 schemastery 自动生成)。 */
|
|
8
10
|
interface Config {
|
|
9
11
|
/**
|
|
@@ -28,4 +30,4 @@ declare const Config: z<Config>;
|
|
|
28
30
|
* @param config - 已校验的部署配置。
|
|
29
31
|
*/
|
|
30
32
|
declare function apply(ctx: Context, config: Config): void;
|
|
31
|
-
export { Config, apply, inject, name };
|
|
33
|
+
export { Config, DEFAULT_PORT, apply, inject, name };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import z from "@deepseek-ai/schemastery";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import "@deepseek-ai/dsh-skill";
|
|
5
|
+
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
// src/skills.ts
|
|
9
|
+
/**
|
|
10
|
+
* 内嵌技能提供者(板块②)。
|
|
11
|
+
*
|
|
12
|
+
* 把学习区验证过的三个技能随插件分发:正文在 `assets/skills/`,
|
|
13
|
+
* 用 `ctx.skills.registerProvider` 注册成一个 bundled provider。
|
|
14
|
+
* 形状照抄 dsh-visualize 的 `src/skill.ts`(BUNDLED_SKILL_RANK + locator + resourceBase)。
|
|
15
|
+
*
|
|
16
|
+
* 优先级策略:rank 取 700(> 宿主 BUNDLED_SKILL_RANK=600)。同层重复名 rank 小者胜,
|
|
17
|
+
* 我们故意排在文件系统提供者之后,让用户工作区(project/user 层)的同名技能继续覆盖;
|
|
18
|
+
* 只有当部署环境没有同名技能时,这里的内嵌版才生效。
|
|
19
|
+
*
|
|
20
|
+
* 每个 skill 的正文按需读盘,并自动追加一节「插件环境附录」:把 dataRoot、
|
|
21
|
+
* 练习台地址等部署事实写进去,让技能正文保持「不含本机值」的可分发状态。
|
|
22
|
+
*
|
|
23
|
+
* @module dsh-learning-assistant/skills
|
|
24
|
+
*/
|
|
25
|
+
/** Provider 名,注册到 ctx.skills 时对外可见。 */
|
|
26
|
+
const PROVIDER_NAME = "dsh-learning-assistant";
|
|
27
|
+
/** assets/skills/ 目录(lib/ 上一级的 assets)。 */
|
|
28
|
+
const SKILL_DIR = fileURLToPath(new URL("../assets/skills/", import.meta.url));
|
|
29
|
+
/** 三个内嵌技能。description 即路由摘要,措辞与学习区原版保持同源。 */
|
|
30
|
+
const SKILLS = [
|
|
31
|
+
{
|
|
32
|
+
name: "one-to-one-tutor",
|
|
33
|
+
description: "一对一家教教学模式:先基于「知识整理」已有材料备课,再按知识点逐轮讲解,每轮只讲一个知识点,并把快速检查与易/中/难三道分层练习出成选择题写进练习台网页,用户作答、提交后自动把成绩送回来批改,批改通过才进入下一知识点。",
|
|
34
|
+
whenToUse: "用户说「开始教我」「进入教学模式」「带我学某某内容」「一对一辅导我」等要求开始教学时使用;也适用于出易中难分层练习、批改作答、按掌握度推进复习的场景。整理课件用 course-material-digest。",
|
|
35
|
+
file: "one-to-one-tutor.md"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "course-material-digest",
|
|
39
|
+
description: "把大学课程原始资料(PPT / PDF)整理成知识材料:思维导图、分节详解、公式速查表、考点分布。核心纪律:读原始文件(读图),不读 OCR;宁可少写,不许猜。整理课件、做思维导图、提炼知识点、复习提纲时使用。",
|
|
40
|
+
whenToUse: "用户提到「整理课件 / 做思维导图 / 知识点整理 / 复习提纲 / 这门课的 PPT / 教材」,或要把课程原始文件变成可复习的知识材料时。",
|
|
41
|
+
file: "course-material-digest.md"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "course-inbox-sync",
|
|
45
|
+
description: "跨平台课程资料同步 + 作业 DDL 提醒:扫描 QQ/微信/企业微信已落盘的附件与群文件,与「知识整理」比对找出未整理资料并补齐;从附件正文抽取作业截止时间并提醒。五层流水线:采集 → 比对 → 补做 → 台账 → DDL。",
|
|
46
|
+
whenToUse: "用户说「更新学习进度」「同步课程资料」「看看有没有新课件」「作业 DDL 提醒」「跨平台收件箱」时使用。",
|
|
47
|
+
file: "course-inbox-sync.md"
|
|
48
|
+
}
|
|
49
|
+
];
|
|
50
|
+
const INVOCATION = {
|
|
51
|
+
modelInvocable: true,
|
|
52
|
+
userInvocable: true
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* 组装一节「插件环境附录」,追加到技能正文末尾。
|
|
56
|
+
* @param env - 部署事实(dataRoot / practiceUrl)。
|
|
57
|
+
* @param skillName - 技能名(附录按技能微调内容)。
|
|
58
|
+
* @returns 附录 markdown(带标题)。
|
|
59
|
+
*/
|
|
60
|
+
function envAppendix(env, skillName) {
|
|
61
|
+
const lines = [
|
|
62
|
+
"",
|
|
63
|
+
"---",
|
|
64
|
+
"",
|
|
65
|
+
"## 插件环境附录(由 dsh-learning-assistant 自动追加)",
|
|
66
|
+
"",
|
|
67
|
+
`> 本节是**本机部署事实**,优先级高于正文里的默认值。`,
|
|
68
|
+
`- 数据根目录(题库/答卷/笔迹/收件箱/进度/采集产物):\`${env.dataRoot}\``,
|
|
69
|
+
`- 练习台入口:\`${env.practiceUrl}\``
|
|
70
|
+
];
|
|
71
|
+
if (skillName === "one-to-one-tutor") lines.push(`- 题目 JSON 落盘:\`${env.dataRoot}\\_题库\\<科目>\\<练习id>.json\`(校验/探针脚本与练习台服务脚本随插件 assets 提供)`, `- 上面的 \`curl\` 示例中的答卷路径前缀按数据根改写;record 字段以答卷 JSON 里的实际路径为准。`);
|
|
72
|
+
if (skillName === "course-material-digest") lines.push(`- 工具脚本:随插件 assets 的 \`tools\\pptx-digest.py\` / \`tools\\pptx-media.py\` / \`tools\\pptx-map.py\` / \`tools\\pdf\\pdf-render.ps1\``);
|
|
73
|
+
if (skillName === "course-inbox-sync") lines.push(`- 采集脚本:随插件 assets 的 \`tools\\qq-group-sync.py\` / \`tools\\qq-group-msg.py\` / \`tools\\im-collect\\wecom_collect.py\``, `- 群号白名单、NapCat 端点与令牌、下载根、企微 Cache 根:见插件设置「资料整理」分区,配置后即成上述脚本的 --config/环境变量。`);
|
|
74
|
+
return lines.join("\n");
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 构建内嵌 provider。
|
|
78
|
+
* @param env - 读取部署事实(每次 get 都读,配置热改即生效)。
|
|
79
|
+
* @returns 可注册到 ctx.skills 的 provider。
|
|
80
|
+
*/
|
|
81
|
+
function learningSkillProvider(env) {
|
|
82
|
+
const candidates = SKILLS.map((s, i) => ({
|
|
83
|
+
name: s.name,
|
|
84
|
+
description: s.description,
|
|
85
|
+
...s.whenToUse ? { whenToUse: s.whenToUse } : {},
|
|
86
|
+
invocation: INVOCATION,
|
|
87
|
+
provider: PROVIDER_NAME,
|
|
88
|
+
source: "bundled",
|
|
89
|
+
resourceBase: {
|
|
90
|
+
kind: "directory",
|
|
91
|
+
path: SKILL_DIR
|
|
92
|
+
},
|
|
93
|
+
rank: 700,
|
|
94
|
+
locator: i
|
|
95
|
+
}));
|
|
96
|
+
return {
|
|
97
|
+
name: PROVIDER_NAME,
|
|
98
|
+
list: () => Promise.resolve(candidates),
|
|
99
|
+
async get(candidate) {
|
|
100
|
+
const meta = SKILLS[candidate.locator];
|
|
101
|
+
if (!meta || candidate.name !== meta.name) return void 0;
|
|
102
|
+
let body;
|
|
103
|
+
try {
|
|
104
|
+
body = await readFile(new URL(`../assets/skills/${meta.file}`, import.meta.url), "utf8");
|
|
105
|
+
} catch {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
name: meta.name,
|
|
110
|
+
description: meta.description,
|
|
111
|
+
...meta.whenToUse ? { whenToUse: meta.whenToUse } : {},
|
|
112
|
+
invocation: INVOCATION,
|
|
113
|
+
provider: PROVIDER_NAME,
|
|
114
|
+
source: "bundled",
|
|
115
|
+
resourceBase: {
|
|
116
|
+
kind: "directory",
|
|
117
|
+
path: SKILL_DIR
|
|
118
|
+
},
|
|
119
|
+
content: body + envAppendix(env(), meta.name)
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
// src/practice-service.ts
|
|
125
|
+
/**
|
|
126
|
+
* 练习台服务管理(板块③,宿主半)。
|
|
127
|
+
*
|
|
128
|
+
* 「按需起服务」:不常驻。`ensure()` 先探测目标端口是否已有健康的练习台
|
|
129
|
+
* (学习区手工部署的也算),有就收编复用;没有才拉起随包的 服务.mjs 子进程
|
|
130
|
+
* (`--data-root` 指向配置的数据根目录)。`stop()` 只停自己拉起的进程。
|
|
131
|
+
*
|
|
132
|
+
* 服务脚本随 npm 包的 `src/practice/` 分发(files 含 src/),用 import.meta 相对定位,
|
|
133
|
+
* 开发仓(lib/ 构建)与安装包两种布局都成立。
|
|
134
|
+
*
|
|
135
|
+
* @module dsh-learning-assistant/practice-service
|
|
136
|
+
*/
|
|
137
|
+
/** 随包服务脚本的绝对路径(lib/index.mjs → ../src/practice/服务.mjs = 包根/src/practice/)。 */
|
|
138
|
+
const SERVER_SCRIPT = fileURLToPath(new URL("../src/practice/服务.mjs", import.meta.url));
|
|
139
|
+
/** 单例状态:本插件生命周期内最多持有一个子进程。 */
|
|
140
|
+
let child;
|
|
141
|
+
let owned = false;
|
|
142
|
+
let runningPort = 0;
|
|
143
|
+
let runningRoot = "";
|
|
144
|
+
/** /api/health 探测:返回是否已有健康的练习台在跑。 */
|
|
145
|
+
async function healthy(port) {
|
|
146
|
+
try {
|
|
147
|
+
const r = await fetch(`http://127.0.0.1:${port}/api/health`, { signal: AbortSignal.timeout(1500) });
|
|
148
|
+
const j = await r.json();
|
|
149
|
+
return r.ok && j.ok === true;
|
|
150
|
+
} catch {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** 等服务起来(最多 ~8s),起来即返回 true。 */
|
|
155
|
+
async function waitUp(port) {
|
|
156
|
+
for (let i = 0; i < 40; i++) {
|
|
157
|
+
if (await healthy(port)) return true;
|
|
158
|
+
await new Promise((s) => setTimeout(s, 200));
|
|
159
|
+
}
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 确保练习台在跑并返回入口地址。
|
|
164
|
+
* @param port - 配置的端口。
|
|
165
|
+
* @param dataRoot - 数据根目录(= 服务的工作区/数据基目录)。
|
|
166
|
+
* @returns 状态与入口 URL。
|
|
167
|
+
*/
|
|
168
|
+
async function ensurePractice(port, dataRoot) {
|
|
169
|
+
if (await healthy(port)) {
|
|
170
|
+
runningPort = port;
|
|
171
|
+
runningRoot = dataRoot;
|
|
172
|
+
return {
|
|
173
|
+
url: `http://127.0.0.1:${port}/`,
|
|
174
|
+
adopted: true,
|
|
175
|
+
started: false
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
if (!child || owned === false) {
|
|
179
|
+
child = spawn(process.execPath, [
|
|
180
|
+
SERVER_SCRIPT,
|
|
181
|
+
String(port),
|
|
182
|
+
"--data-root",
|
|
183
|
+
dataRoot
|
|
184
|
+
], {
|
|
185
|
+
cwd: fileURLToPath(new URL("../src/practice/", import.meta.url)),
|
|
186
|
+
env: {
|
|
187
|
+
...process.env,
|
|
188
|
+
LEARN_DATA_BASE: dataRoot,
|
|
189
|
+
LEARN_WORKSPACE: dataRoot,
|
|
190
|
+
LEARN_PRACTICE_DIR: join(dataRoot, "练习台")
|
|
191
|
+
},
|
|
192
|
+
stdio: "ignore",
|
|
193
|
+
windowsHide: true
|
|
194
|
+
});
|
|
195
|
+
child.on("exit", () => {
|
|
196
|
+
child = void 0;
|
|
197
|
+
owned = false;
|
|
198
|
+
});
|
|
199
|
+
owned = true;
|
|
200
|
+
}
|
|
201
|
+
if (!await waitUp(port)) throw new Error(`练习台服务没能启动(端口 ${port})。可能被其他程序占用且不是练习台。`);
|
|
202
|
+
runningPort = port;
|
|
203
|
+
runningRoot = dataRoot;
|
|
204
|
+
return {
|
|
205
|
+
url: `http://127.0.0.1:${port}/`,
|
|
206
|
+
adopted: false,
|
|
207
|
+
started: true
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/** 停掉本插件拉起的进程(收编的不停)。 */
|
|
211
|
+
function stopPractice() {
|
|
212
|
+
if (child && owned) {
|
|
213
|
+
try {
|
|
214
|
+
child.kill();
|
|
215
|
+
} catch {}
|
|
216
|
+
child = void 0;
|
|
217
|
+
owned = false;
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
/** 当前状态快照(给工具与设置页)。 */
|
|
223
|
+
function practiceStatus() {
|
|
224
|
+
return {
|
|
225
|
+
running: runningPort > 0,
|
|
226
|
+
owned,
|
|
227
|
+
port: runningPort,
|
|
228
|
+
root: runningRoot
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
// src/practice-tool.ts
|
|
232
|
+
/**
|
|
233
|
+
* 「练习台」工具(板块③):让模型按需起练习台并把入口地址报给用户。
|
|
234
|
+
*
|
|
235
|
+
* 动作:
|
|
236
|
+
* - open:确保服务在跑(已有健康实例则收编复用),返回入口 URL。
|
|
237
|
+
* - status:报告服务运行状态与数据根。
|
|
238
|
+
* - stop:停掉本插件拉起的服务进程(收编的不停)。
|
|
239
|
+
*
|
|
240
|
+
* @module dsh-learning-assistant/practice-tool
|
|
241
|
+
*/
|
|
242
|
+
/** 构建工具定义。 */
|
|
243
|
+
function practiceTool(dataRoot, port) {
|
|
244
|
+
return defineTool({
|
|
245
|
+
name: "practice_desk",
|
|
246
|
+
description: "学习助手练习台:本地答题网页(题库 JSON + 白板手写 + 成绩记录)。action=open 确保服务在跑并返回入口 URL(给用户在 DSH 右侧栏浏览器打开);action=status 报告运行状态;action=stop 停掉本插件拉起的服务(收编的外部实例不停)。数据落在数据根目录的 练习台/ 与 学习助手数据/ 下;教学流程见 one-to-one-tutor 技能。",
|
|
247
|
+
parameters: { action: {
|
|
248
|
+
type: "string",
|
|
249
|
+
enum: [
|
|
250
|
+
"open",
|
|
251
|
+
"status",
|
|
252
|
+
"stop"
|
|
253
|
+
],
|
|
254
|
+
description: "open=确保服务在跑并返回入口;status=只看状态;stop=停本插件拉起的进程。"
|
|
255
|
+
} },
|
|
256
|
+
output: {
|
|
257
|
+
schema: {
|
|
258
|
+
type: "object",
|
|
259
|
+
additionalProperties: false,
|
|
260
|
+
properties: {
|
|
261
|
+
action: {
|
|
262
|
+
type: "string",
|
|
263
|
+
required: true,
|
|
264
|
+
enum: [
|
|
265
|
+
"open",
|
|
266
|
+
"status",
|
|
267
|
+
"stop"
|
|
268
|
+
]
|
|
269
|
+
},
|
|
270
|
+
url: { type: "string" },
|
|
271
|
+
running: {
|
|
272
|
+
type: "boolean",
|
|
273
|
+
required: true
|
|
274
|
+
},
|
|
275
|
+
owned: {
|
|
276
|
+
type: "boolean",
|
|
277
|
+
required: true
|
|
278
|
+
},
|
|
279
|
+
started: { type: "boolean" },
|
|
280
|
+
adopted: { type: "boolean" },
|
|
281
|
+
stopped: { type: "boolean" },
|
|
282
|
+
port: { type: "integer" },
|
|
283
|
+
dataRoot: {
|
|
284
|
+
type: "string",
|
|
285
|
+
required: true
|
|
286
|
+
},
|
|
287
|
+
message: {
|
|
288
|
+
type: "string",
|
|
289
|
+
required: true
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
render: (_args, value) => [{
|
|
294
|
+
type: "text",
|
|
295
|
+
text: value.message
|
|
296
|
+
}]
|
|
297
|
+
},
|
|
298
|
+
isConcurrencySafe: () => false,
|
|
299
|
+
async execute(args) {
|
|
300
|
+
const action = args.action ?? "open";
|
|
301
|
+
if (action === "status") {
|
|
302
|
+
const st = practiceStatus();
|
|
303
|
+
const message = st.running ? `练习台运行中(端口 ${st.port}${st.owned ? ",本插件拉起" : ",外部实例"})` : "练习台未运行";
|
|
304
|
+
return {
|
|
305
|
+
action,
|
|
306
|
+
running: st.running,
|
|
307
|
+
owned: st.owned,
|
|
308
|
+
port: st.port,
|
|
309
|
+
dataRoot: dataRoot(),
|
|
310
|
+
message
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
if (action === "stop") {
|
|
314
|
+
const stopped = stopPractice();
|
|
315
|
+
const st = practiceStatus();
|
|
316
|
+
return {
|
|
317
|
+
action,
|
|
318
|
+
running: st.running,
|
|
319
|
+
owned: st.owned,
|
|
320
|
+
stopped,
|
|
321
|
+
dataRoot: dataRoot(),
|
|
322
|
+
message: stopped ? "练习台(本插件拉起的实例)已停止。" : "没有本插件拉起的练习台进程在跑(外部实例不动)。"
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
const r = await ensurePractice(port(), dataRoot());
|
|
326
|
+
const st = practiceStatus();
|
|
327
|
+
const how = r.started ? "已启动随包服务" : r.adopted && st.owned ? "随包服务已在运行(插件加载时预热)" : r.adopted ? "检测到已有健康实例(可能是学习区手工部署),直接复用" : "已在运行";
|
|
328
|
+
return {
|
|
329
|
+
action,
|
|
330
|
+
url: r.url,
|
|
331
|
+
started: r.started,
|
|
332
|
+
adopted: r.adopted,
|
|
333
|
+
running: true,
|
|
334
|
+
owned: st.owned,
|
|
335
|
+
dataRoot: dataRoot(),
|
|
336
|
+
message: `练习台${how}。入口:${r.url}(让用户在 DSH 右侧栏「浏览器」tab 打开)。数据根:${dataRoot()}`
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
// src/index.ts
|
|
342
|
+
/** Cordis 插件名,与 package.json 的 name、cordis.patch.yml 的 entry id 一致。 */
|
|
343
|
+
const name = "dsh-learning-assistant";
|
|
344
|
+
/** 需要宿主提供的服务:工具注册表、技能注册表、文件系统接缝。 */
|
|
345
|
+
const inject = [
|
|
346
|
+
"tools",
|
|
347
|
+
"skills",
|
|
348
|
+
"fs"
|
|
349
|
+
];
|
|
350
|
+
/** 练习台默认端口(学习区原版口径)。 */
|
|
351
|
+
const DEFAULT_PORT = 18800;
|
|
352
|
+
/** Loader 校验的配置 schema。 */
|
|
353
|
+
const Config = z.object({
|
|
354
|
+
dataRoot: z.string().default("").description("数据根目录 / Data root"),
|
|
355
|
+
practiceDeskPort: z.natural().default(DEFAULT_PORT).description("练习台端口 / Practice desk port"),
|
|
356
|
+
collectGroups: z.object({
|
|
357
|
+
qq: z.array(z.string()).default([]).description("QQ 群号白名单"),
|
|
358
|
+
wecom: z.array(z.string()).default([]).description("企微群名白名单")
|
|
359
|
+
}).default({
|
|
360
|
+
qq: [],
|
|
361
|
+
wecom: []
|
|
362
|
+
})
|
|
363
|
+
});
|
|
364
|
+
/** 解析生效的数据根:配置为空时退回插件数据目录(<DSH_HOME>/learning-assistant/data)。 */
|
|
365
|
+
function resolveDataRoot(ctx, config) {
|
|
366
|
+
if (config.dataRoot.trim()) return config.dataRoot.trim();
|
|
367
|
+
try {
|
|
368
|
+
const homePath = ctx.get("dshHomePath");
|
|
369
|
+
if (typeof homePath === "function") return homePath("learning-assistant", "data");
|
|
370
|
+
} catch {}
|
|
371
|
+
return "learning-assistant/data";
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* 注册全部能力。
|
|
375
|
+
* @param ctx - 注册上下文。
|
|
376
|
+
* @param config - 已校验的部署配置。
|
|
377
|
+
*/
|
|
378
|
+
function apply(ctx, config) {
|
|
379
|
+
const dataRoot = resolveDataRoot(ctx, config);
|
|
380
|
+
const port = config.practiceDeskPort || 18800;
|
|
381
|
+
const env = () => ({
|
|
382
|
+
dataRoot,
|
|
383
|
+
practiceUrl: `http://127.0.0.1:${port}/`
|
|
384
|
+
});
|
|
385
|
+
ctx.skills.registerProvider(() => learningSkillProvider(env));
|
|
386
|
+
ensurePractice(port, dataRoot).catch((e) => {
|
|
387
|
+
console.warn(`[dsh-learning-assistant] 练习台预热失败(稍后调用工具时会重试):${e && e.message}`);
|
|
388
|
+
});
|
|
389
|
+
ctx.tools.register(practiceTool(() => dataRoot, () => port));
|
|
390
|
+
process.on("exit", () => stopPractice());
|
|
391
|
+
}
|
|
392
|
+
export { Config, DEFAULT_PORT, apply, inject, name };
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-learning-assistant",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "DSH
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "DSH 学习助手插件:资料整理 / 知识整理与讲解(内嵌三技能)/ 学习助手数据(练习台)三分区",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "lib/index.
|
|
7
|
-
"types": "lib/index.d.
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"types": "./lib/index.d.
|
|
11
|
-
"default": "./lib/index.
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"default": "./lib/index.js"
|
|
12
12
|
},
|
|
13
|
-
"./client": "./lib/client.
|
|
13
|
+
"./client": "./lib/client.js",
|
|
14
|
+
"./assets/*": "./assets/*",
|
|
14
15
|
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
15
16
|
"./package.json": "./package.json"
|
|
16
17
|
},
|
package/src/client/settings.tsx
CHANGED
|
@@ -56,20 +56,22 @@ export function LearningAssistantSection() {
|
|
|
56
56
|
{active === 'material' && (
|
|
57
57
|
<section>
|
|
58
58
|
<h3>资料整理</h3>
|
|
59
|
-
<p
|
|
60
|
-
<p
|
|
59
|
+
<p>采集脚本随插件分发(assets/tools):QQ 群文件与群消息走 NapCat OneBot HTTP;企业微信走 UIA 白名单采集;微信 4.x 不做(待社区适配)。</p>
|
|
60
|
+
<p>白名单纪律:只采集下面配置里点名的群。群号 / NapCat 地址与令牌 / 下载根的接线在阶段 4 服务化时提供表单。</p>
|
|
61
61
|
</section>
|
|
62
62
|
)}
|
|
63
63
|
{active === 'teach' && (
|
|
64
64
|
<section>
|
|
65
65
|
<h3>知识整理与讲解</h3>
|
|
66
|
-
<p
|
|
66
|
+
<p>三个技能已随插件内嵌:course-material-digest(资料整理)、one-to-one-tutor(一对一带学)、course-inbox-sync(跨平台收件箱 + DDL)。无需另装技能文件。</p>
|
|
67
|
+
<p>按学科选择讲解方案(粒度、是否先出导图、例题风格)在阶段 3 方案层提供。</p>
|
|
67
68
|
</section>
|
|
68
69
|
)}
|
|
69
70
|
{active === 'data' && (
|
|
70
71
|
<section>
|
|
71
72
|
<h3>学习助手数据</h3>
|
|
72
|
-
<p
|
|
73
|
+
<p>课程计划、学习历史、作答记录落在「数据根目录」配置指向的位置(默认 <code><DSH_HOME>/learning-assistant/data</code>;指向某个工作区根时直接用其 练习台/ 与 学习助手数据/ 子目录)。</p>
|
|
74
|
+
<p>练习台按需启动:对话里让助手调用 practice_desk 工具(action=open)即可,已有健康实例会自动复用,不会重复起服务。</p>
|
|
73
75
|
</section>
|
|
74
76
|
)}
|
|
75
77
|
</div>
|
package/src/index.ts
CHANGED
|
@@ -2,18 +2,21 @@
|
|
|
2
2
|
* dsh-learning-assistant,宿主半(node)。
|
|
3
3
|
*
|
|
4
4
|
* 三个板块都从这里接线:
|
|
5
|
-
* 1. 资料整理 →
|
|
5
|
+
* 1. 资料整理 → 采集脚本随 assets 分发(QQ/NapCat、企微 UIA),服务化接线在阶段 4
|
|
6
6
|
* 2. 知识整理 → ctx.skills.registerProvider(内嵌 course-material-digest、
|
|
7
|
-
* one-to-one-tutor
|
|
8
|
-
* 3. 学习助手数据 → 练习台服务 +
|
|
7
|
+
* one-to-one-tutor、course-inbox-sync)
|
|
8
|
+
* 3. 学习助手数据 → 练习台服务 + 数据根目录(阶段 1 接线)
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* 现状:技能内嵌已实现;练习台与采集服务化仍是 TODO。
|
|
11
11
|
*
|
|
12
12
|
* @module dsh-learning-assistant
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import type { Context } from '@deepseek-ai/cordis'
|
|
16
16
|
import z from '@deepseek-ai/schemastery'
|
|
17
|
+
import { learningSkillProvider, type SkillEnv } from './skills.ts'
|
|
18
|
+
import { practiceTool } from './practice-tool.ts'
|
|
19
|
+
import { ensurePractice, stopPractice } from './practice-service.ts'
|
|
17
20
|
|
|
18
21
|
/** Cordis 插件名,与 package.json 的 name、cordis.patch.yml 的 entry id 一致。 */
|
|
19
22
|
export const name = 'dsh-learning-assistant'
|
|
@@ -21,6 +24,9 @@ export const name = 'dsh-learning-assistant'
|
|
|
21
24
|
/** 需要宿主提供的服务:工具注册表、技能注册表、文件系统接缝。 */
|
|
22
25
|
export const inject = ['tools', 'skills', 'fs']
|
|
23
26
|
|
|
27
|
+
/** 练习台默认端口(学习区原版口径)。 */
|
|
28
|
+
export const DEFAULT_PORT = 18800
|
|
29
|
+
|
|
24
30
|
/** 部署配置(设置页表单由 schemastery 自动生成)。 */
|
|
25
31
|
export interface Config {
|
|
26
32
|
/**
|
|
@@ -41,7 +47,7 @@ export interface Config {
|
|
|
41
47
|
/** Loader 校验的配置 schema。 */
|
|
42
48
|
export const Config: z<Config> = z.object({
|
|
43
49
|
dataRoot: z.string().default('').description('数据根目录 / Data root'),
|
|
44
|
-
practiceDeskPort: z.natural().default(
|
|
50
|
+
practiceDeskPort: z.natural().default(DEFAULT_PORT).description('练习台端口 / Practice desk port'),
|
|
45
51
|
collectGroups: z
|
|
46
52
|
.object({
|
|
47
53
|
qq: z.array(z.string()).default([]).description('QQ 群号白名单'),
|
|
@@ -50,15 +56,34 @@ export const Config: z<Config> = z.object({
|
|
|
50
56
|
.default({ qq: [], wecom: [] }),
|
|
51
57
|
}) as unknown as z<Config>
|
|
52
58
|
|
|
59
|
+
/** 解析生效的数据根:配置为空时退回插件数据目录(<DSH_HOME>/learning-assistant/data)。 */
|
|
60
|
+
function resolveDataRoot(ctx: Context, config: Config): string {
|
|
61
|
+
if (config.dataRoot.trim()) return config.dataRoot.trim()
|
|
62
|
+
try {
|
|
63
|
+
const homePath = ctx.get('dshHomePath') as ((...segments: string[]) => string) | undefined
|
|
64
|
+
if (typeof homePath === 'function') return homePath('learning-assistant', 'data')
|
|
65
|
+
} catch { /* 宿主没提供 home,退到 cwd 相对目录 */ }
|
|
66
|
+
return 'learning-assistant/data'
|
|
67
|
+
}
|
|
68
|
+
|
|
53
69
|
/**
|
|
54
70
|
* 注册全部能力。
|
|
55
71
|
* @param ctx - 注册上下文。
|
|
56
72
|
* @param config - 已校验的部署配置。
|
|
57
73
|
*/
|
|
58
74
|
export function apply(ctx: Context, config: Config): void {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
75
|
+
const dataRoot = resolveDataRoot(ctx, config)
|
|
76
|
+
const port = config.practiceDeskPort || DEFAULT_PORT
|
|
77
|
+
const env: () => SkillEnv = () => ({ dataRoot, practiceUrl: `http://127.0.0.1:${port}/` })
|
|
78
|
+
// 板块②:三个技能随插件分发(one-to-one-tutor / course-material-digest / course-inbox-sync)
|
|
79
|
+
ctx.skills.registerProvider(() => learningSkillProvider(env))
|
|
80
|
+
// 板块③:练习台按需起停。注册时预热一次(fail-soft:起不来不阻塞插件加载,
|
|
81
|
+
// 用户调用 practice_desk 时 ensure 会再试并给出具体错误)。
|
|
82
|
+
ensurePractice(port, dataRoot).catch((e) => {
|
|
83
|
+
console.warn(`[dsh-learning-assistant] 练习台预热失败(稍后调用工具时会重试):${e && e.message}`)
|
|
84
|
+
})
|
|
85
|
+
ctx.tools.register(practiceTool(() => dataRoot, () => port))
|
|
86
|
+
// 插件卸载时只停自己拉起的进程
|
|
87
|
+
process.on('exit', () => stopPractice())
|
|
88
|
+
// TODO(板块1) collect(ctx, config):QQ/NapCat 采集服务化(企微/微信待开发,不随包)
|
|
89
|
+
}
|