@wonanut/dsh-agent-lab 0.0.0-stage → 0.2.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/CONTRACT.md +276 -0
- package/LICENSE +21 -0
- package/README.md +299 -2
- package/build.mjs +89 -0
- package/client.js +7871 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +26 -0
- package/index.js +390 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +66 -4
- package/preview/dataflow.png +0 -0
- package/preview/inspector-context.png +0 -0
- package/preview/model-switch.png +0 -0
- package/preview/overview-dark.png +0 -0
- package/preview/overview-light.png +0 -0
- package/preview/principles.png +0 -0
- package/preview/source.png +0 -0
- package/src/00-core.js +209 -0
- package/src/10-engine.js +1960 -0
- package/src/20-tools.js +600 -0
- package/src/30-llm.js +495 -0
- package/src/40-ui-kit.js +596 -0
- package/src/45-real-client.js +190 -0
- package/src/50-tui.js +472 -0
- package/src/60-inspector.js +621 -0
- package/src/65-dataflow.js +341 -0
- package/src/70-docs.js +1226 -0
- package/src/80-source.js +576 -0
- package/src/90-page.js +476 -0
- package/src/95-apply.js +58 -0
- package/test/engine.test.mjs +800 -0
- package/test/extra-tools.test.mjs +168 -0
- package/test/real-mode.test.mjs +177 -0
package/build.mjs
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds client.js from src/*.js.
|
|
3
|
+
*
|
|
4
|
+
* The Web Client loads one plain-JS module per plugin: a lazy factory registered
|
|
5
|
+
* on window.__ModuleLoader__. We concatenate the numbered source files into that
|
|
6
|
+
* factory and embed every source file as a JSON string so the in-app source
|
|
7
|
+
* browser shows exactly the code that is running.
|
|
8
|
+
*
|
|
9
|
+
* Usage: node build.mjs → writes client.js and syntax-checks it
|
|
10
|
+
* node build.mjs --check → syntax-check only
|
|
11
|
+
*/
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import vm from 'node:vm';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
|
|
17
|
+
const root = path.dirname(fileURLToPath(import.meta.url));
|
|
18
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
|
19
|
+
const moduleId = manifest.name;
|
|
20
|
+
|
|
21
|
+
/** Build order matters: later files see earlier declarations in one scope. */
|
|
22
|
+
const FILES = [
|
|
23
|
+
['00-core.js', '常量、token 估算与通用工具'],
|
|
24
|
+
['10-engine.js', '会话 / 记忆 / 上下文 / 压缩 / createLab'],
|
|
25
|
+
['20-tools.js', '工具注册表与四个工具'],
|
|
26
|
+
['30-llm.js', '规则驱动的模拟 LLM'],
|
|
27
|
+
['40-ui-kit.js', '全局样式与 UI 原语'],
|
|
28
|
+
['45-real-client.js', '真实模型客户端:状态与模型请求'],
|
|
29
|
+
['50-tui.js', '模拟 TUI 终端'],
|
|
30
|
+
['60-inspector.js', '流转 / 上下文 / 记忆检查器'],
|
|
31
|
+
['65-dataflow.js', 'Agent 数据流转视图(回放)'],
|
|
32
|
+
['70-docs.js', 'Agent 原理页'],
|
|
33
|
+
['80-source.js', '源码浏览器'],
|
|
34
|
+
['90-page.js', '页面外壳与会话栏'],
|
|
35
|
+
['95-apply.js', 'slot 注册入口'],
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
const readSource = ([file, role]) => ({
|
|
39
|
+
id: file.replace(/\.js$/, ''),
|
|
40
|
+
name: file,
|
|
41
|
+
role,
|
|
42
|
+
code: fs.readFileSync(path.join(root, 'src', file), 'utf8'),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const bodySources = FILES.map(readSource).filter((item) => item.code.trim().length > 0);
|
|
46
|
+
|
|
47
|
+
const hostSource = {
|
|
48
|
+
id: 'index-host',
|
|
49
|
+
name: 'index.js (Host 半侧)',
|
|
50
|
+
role: '真实模型路由:status / complete(调用 DSH 当前 DeepSeek 模型)',
|
|
51
|
+
code: fs.readFileSync(path.join(root, 'index.js'), 'utf8'),
|
|
52
|
+
};
|
|
53
|
+
const sources = bodySources.concat([hostSource]);
|
|
54
|
+
const missing = FILES.filter(([file]) => !fs.existsSync(path.join(root, 'src', file)));
|
|
55
|
+
if (missing.length > 0) {
|
|
56
|
+
console.warn('[build] waiting for source files:', missing.map(([file]) => file).join(', '));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const body = bodySources
|
|
60
|
+
.map((source) => `/* ── ${source.name} · ${source.role} ── */\n${source.code}`)
|
|
61
|
+
.join('\n\n');
|
|
62
|
+
|
|
63
|
+
const output = `/* Generated by build.mjs from src/*.js — do not edit by hand. */
|
|
64
|
+
window.__ModuleLoader__.load({
|
|
65
|
+
id: ${JSON.stringify(moduleId)},
|
|
66
|
+
factory(require) {
|
|
67
|
+
const React = require('react');
|
|
68
|
+
const e = React.createElement;
|
|
69
|
+
const { useState, useEffect, useMemo, useRef, useCallback } = React;
|
|
70
|
+
const SOURCES = ${JSON.stringify(sources)};
|
|
71
|
+
|
|
72
|
+
${body}
|
|
73
|
+
|
|
74
|
+
return { inject: ['slots'], apply };
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
`;
|
|
78
|
+
|
|
79
|
+
const target = path.join(root, 'client.js');
|
|
80
|
+
|
|
81
|
+
if (process.argv.includes('--check')) {
|
|
82
|
+
new vm.Script(output, { filename: target });
|
|
83
|
+
console.log('[build] syntax OK,', output.length, 'bytes (not written)');
|
|
84
|
+
process.exit(0);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
fs.writeFileSync(target, output);
|
|
88
|
+
new vm.Script(output, { filename: target });
|
|
89
|
+
console.log(`[build] wrote ${target} (${output.length} bytes, ${sources.length} sources)`);
|