dsh-contextos-devops 0.0.0-stage → 1.48.31

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 (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +207 -2
  3. package/assets/avatar.jpg +0 -0
  4. package/assets/client.css +3316 -0
  5. package/assets/icon-180.png +0 -0
  6. package/build/client.mjs +64 -0
  7. package/client.js +7622 -0
  8. package/cordis.patch.yml +3 -0
  9. package/icon.svg +15 -0
  10. package/index.js +345 -0
  11. package/lib/base/env.js +22 -0
  12. package/lib/base/field.js +25 -0
  13. package/lib/base/http.js +140 -0
  14. package/lib/base/platform.js +33 -0
  15. package/lib/base/registry.js +186 -0
  16. package/lib/base/state.js +66 -0
  17. package/lib/base/table.js +47 -0
  18. package/lib/base/texttable.js +26 -0
  19. package/lib/base/url.js +178 -0
  20. package/lib/core/README.md +17 -0
  21. package/lib/core/apps.js +675 -0
  22. package/lib/core/auth.js +110 -0
  23. package/lib/core/avatar.js +289 -0
  24. package/lib/core/backup.js +105 -0
  25. package/lib/core/codegen.js +401 -0
  26. package/lib/core/copilot.js +419 -0
  27. package/lib/core/data.js +157 -0
  28. package/lib/core/device.js +148 -0
  29. package/lib/core/files.js +152 -0
  30. package/lib/core/gobuild.js +63 -0
  31. package/lib/core/iam.js +122 -0
  32. package/lib/core/identity.js +22 -0
  33. package/lib/core/nodes.js +627 -0
  34. package/lib/core/ops.js +306 -0
  35. package/lib/core/project.js +393 -0
  36. package/lib/core/spaces.js +406 -0
  37. package/lib/core/terminal.js +137 -0
  38. package/lib/core/terminal2.js +141 -0
  39. package/lib/core/users.js +51 -0
  40. package/lib/core/vocab.js +158 -0
  41. package/lib/misc/async.js +15 -0
  42. package/lib/misc/shell.js +27 -0
  43. package/lib/misc/static.js +33 -0
  44. package/locale/en.json +10 -0
  45. package/locale/zh.json +10 -0
  46. package/package.json +91 -4
  47. package/src/client/README.md +37 -0
  48. package/src/client/parts/00-prelude.js +315 -0
  49. package/src/client/parts/05-bootstrap.js +61 -0
  50. package/src/client/parts/08-store.js +85 -0
  51. package/src/client/parts/10-ui.js +188 -0
  52. package/src/client/parts/12-debug.js +361 -0
  53. package/src/client/parts/15-layout.js +86 -0
  54. package/src/client/parts/20-devworkspace.js +789 -0
  55. package/src/client/parts/25-editor-ui.js +28 -0
  56. package/src/client/parts/30-modals.js +85 -0
  57. package/src/client/parts/32-cards.js +176 -0
  58. package/src/client/parts/34-forms.js +176 -0
  59. package/src/client/parts/36-data.js +267 -0
  60. package/src/client/parts/40-project.js +430 -0
  61. package/src/client/parts/45-map.js +109 -0
  62. package/src/client/parts/46-pm.js +158 -0
  63. package/src/client/parts/47-three.js +324 -0
  64. package/src/client/parts/49-msg.js +167 -0
  65. package/src/client/parts/50-chat.js +1422 -0
  66. package/src/client/parts/51-pmselection.js +31 -0
  67. package/src/client/parts/52-pmdata.js +29 -0
  68. package/src/client/parts/55-pm.js +146 -0
  69. package/src/client/parts/58-config.js +381 -0
  70. package/src/client/parts/59-monitor.js +262 -0
  71. package/src/client/parts/60-page.js +1518 -0
  72. package/src/client/styles/kit.css +20 -0
  73. package/src/client/styles/main.css +3294 -0
  74. package/src/client/styles/tokens.css +2 -0
  75. package/vendor/leaflet/leaflet.css +661 -0
  76. package/vendor/leaflet/leaflet.js +6 -0
  77. package/vendor/three/three.module.js +53044 -0
  78. package/vendor/xterm/addon-fit.js +2 -0
  79. package/vendor/xterm/xterm.css +218 -0
  80. package/vendor/xterm/xterm.js +2 -0
@@ -0,0 +1,267 @@
1
+ function AvatarModal({ node, data, active, onSelect, onCreated, onUpdated, onClose }) {
2
+ const QUESTIONS = [
3
+ { key: 'name', q: '先给分身起个名字?', d: '我的分身' },
4
+ { key: 'city', q: '所在城市?', d: '深圳市' },
5
+ { key: 'company', q: '公司名称?', d: '云轩领航' },
6
+ { key: 'persona', q: '人格设定?例如:专业、稳重、直接', d: '专业、稳重、直接' },
7
+ { key: 'preferences', q: '喜好/关注什么?例如:技术、产品、效率', d: '技术、产品、效率' },
8
+ { key: 'style', q: '表达风格?例如:简洁、结构化、少客套', d: '简洁、结构化' },
9
+ ];
10
+ const [step, setStep] = useState(-1);
11
+ const [answers, setAnswers] = useState({});
12
+ const [msgs, setMsgs] = useState([]);
13
+ const [input, setInput] = useState('');
14
+ const [busy, setBusy] = useState(false);
15
+ const [err, setErr] = useState('');
16
+ const [skill, setSkill] = useState('');
17
+ const imageRef = useRef(null);
18
+ const update = async (patch) => {
19
+ if (!active?.uid) return;
20
+ setBusy(true); setErr('');
21
+ try { const a = await api('updateAvatar', { node, uid: active.uid, patch }); onUpdated?.(a); }
22
+ catch (e) { setErr(String(e?.message || e)); } finally { setBusy(false); }
23
+ };
24
+ const upload = (file) => {
25
+ if (!file) return;
26
+ const reader = new FileReader();
27
+ reader.onload = () => {
28
+ const img = new Image();
29
+ img.onload = () => {
30
+ const max = 512, scale = Math.min(1, max / Math.max(img.width, img.height));
31
+ const canvas = document.createElement('canvas');
32
+ canvas.width = Math.round(img.width * scale); canvas.height = Math.round(img.height * scale);
33
+ canvas.getContext('2d').drawImage(img, 0, 0, canvas.width, canvas.height);
34
+ update({ image: canvas.toDataURL('image/jpeg', 0.86) });
35
+ };
36
+ img.src = String(reader.result);
37
+ };
38
+ reader.readAsDataURL(file);
39
+ };
40
+ const begin = () => {
41
+ setStep(0); setAnswers({}); setMsgs([{ role: 'ai', text: QUESTIONS[0].q }]); setInput('');
42
+ };
43
+ const send = () => {
44
+ if (step < 0 || step >= QUESTIONS.length) return;
45
+ const q = QUESTIONS[step];
46
+ const value = (input.trim() || q.d);
47
+ const nextAnswers = { ...answers, [q.key]: value };
48
+ setAnswers(nextAnswers);
49
+ setMsgs((xs) => [...xs, { role: 'user', text: value }]);
50
+ setInput('');
51
+ if (step + 1 < QUESTIONS.length) {
52
+ setMsgs((xs) => [...xs, { role: 'ai', text: QUESTIONS[step + 1].q }]);
53
+ setStep(step + 1);
54
+ } else {
55
+ setStep(QUESTIONS.length);
56
+ setMsgs((xs) => [...xs, { role: 'ai', text: '信息齐了。确认后创建分身,使用独立 user.uid。' }]);
57
+ }
58
+ };
59
+ const create = async () => {
60
+ setBusy(true); setErr('');
61
+ try {
62
+ const a = await api('createAvatar', { node, ...answers });
63
+ onCreated(a);
64
+ } catch (e) { setErr(String(e?.message || e)); } finally { setBusy(false); }
65
+ };
66
+ const choose = async (a) => {
67
+ setBusy(true); setErr('');
68
+ try { await api('setAvatar', { node, uid: a.uid }); onSelect(a); }
69
+ catch (e) { setErr(String(e?.message || e)); } finally { setBusy(false); }
70
+ };
71
+ return h(Modal, { title: '数字分身 / DIGITAL AVATARS', desc: '每个分身有独立 user.uid、公司、城市、人格、喜好、风格。', onClose },
72
+ h('div', { className: 'cx-avatar-list' }, (data?.items || []).map((a) => h('div', { key: a.uid, className: `cx-avatar${active?.uid === a.uid ? ' on' : ''}`, onClick: () => choose(a) },
73
+ h('span', { className: 'cx-led on' }),
74
+ h('div', { style: { flex: 1, minWidth: 0 } },
75
+ h('div', { className: 'an' }, a.name || a.username),
76
+ h('div', { className: 'ad' }, `${a.city || '—'} · ${a.company || '—'} · ${a.persona || '—'} · ${a.style || '—'}`),
77
+ h('div', { className: 'ad' }, a.project?.place_uid ? `项目:${a.project.name || a.project.space}` : (a.project?.error ? `项目:${a.project.error}` : '项目:未创建'))),
78
+ h('span', { className: 'cx-tag cy' }, active?.uid === a.uid ? 'ACTIVE' : 'SELECT')))),
79
+ active ? h('div', { className: 'cx-avatar-extra' },
80
+ h('div', { className: 'cx-avatar-preview' }, active.image ? h('img', { src: active.image, alt: '' }) : h('span', null, '3D')),
81
+ h('div', { style: { flex: 1, minWidth: 0 } },
82
+ h('div', { className: 'cx-avatar-extra-title' }, '形象与技能'),
83
+ h('div', { className: 'cx-avatar-extra-sub' }, '上传照片生成你的数字人形象;技能会进入 AI 上下文。'),
84
+ h('div', { className: 'cx-avatar-skills' }, (active.skills || []).map((x, i) => h('span', { key: i, className: 'cx-tag cy' }, x, h(IconButton, { name: 'close', className: 'cx-tag-x', onClick: () => update({ skills: (active.skills || []).filter((_, j) => j !== i) }) }))), h('span', { className: 'cx-avatar-skill-empty' }, (active.skills || []).length ? '' : '暂无技能')),
85
+ h('div', { className: 'cx-avatar-skill-add' },
86
+ h('input', { className: 'cx-input', value: skill, placeholder: '添加技能,例如 数据分析', onChange: (e) => setSkill(e.target.value), onKeyDown: (e) => { if (e.key === 'Enter' && skill.trim()) { update({ skills: [...(active.skills || []), skill.trim()] }); setSkill(''); } } }),
87
+ h('button', { className: 'cx-btn xs', disabled: !skill.trim() || busy, onClick: () => { update({ skills: [...(active.skills || []), skill.trim()] }); setSkill(''); } }, T('+ 技能')),
88
+ h('button', { className: 'cx-btn xs pri', onClick: () => imageRef.current?.click() }, T('上传形象')))),
89
+ h('input', { type: 'file', ref: imageRef, accept: 'image/*', style: { display: 'none' }, onChange: (e) => { upload(e.target.files?.[0]); e.target.value = ''; } })) : null,
90
+ step < 0
91
+ ? h('div', { className: 'cx-foot' }, h('button', { className: 'cx-btn', onClick: onClose }, T('关闭')), h('button', { className: 'cx-btn pri', onClick: begin }, '+ ' + T('创建分身')))
92
+ : h('div', null,
93
+ h('div', { className: 'cx-chat-b', style: { maxHeight: 220 } }, msgs.map((m, i) => h('div', { key: i, className: `cx-msg ${m.role}` }, m.text))),
94
+ step < QUESTIONS.length
95
+ ? h('div', { className: 'cx-chat-i' },
96
+ h('input', { className: 'cx-input', value: input, placeholder: QUESTIONS[step].d, onChange: (e) => setInput(e.target.value), onKeyDown: (e) => { if (e.key === 'Enter') send(); } }),
97
+ h('button', { className: 'cx-btn pri', onClick: send }, T('发送')))
98
+ : h('div', null,
99
+ h('div', { className: 'desc' }, `${answers.name} · ${answers.city} · ${answers.company}\n人格:${answers.persona}\n喜好:${answers.preferences}\n风格:${answers.style}`),
100
+ h('div', { className: 'cx-foot' }, h('button', { className: 'cx-btn', onClick: () => setStep(-1) }, T('上一步')), h('button', { className: 'cx-btn pri', disabled: busy, onClick: create }, busy ? T('创建中…') : T('创建分身'))))),
101
+ err ? h(ErrorBox, { text: err }) : null);
102
+ }
103
+
104
+ function DeviceModal({ node, onClose }) {
105
+ const [data, setData] = useState(null);
106
+ const [busy, setBusy] = useState(true);
107
+ const [err, setErr] = useState('');
108
+ useEffect(() => {
109
+ let alive = true;
110
+ loadSsh();
111
+ api('devices', { node }).then((d) => { if (alive) { setData(d); setBusy(false); } }).catch((e) => { if (alive) { setErr(String(e?.message || e)); setBusy(false); } });
112
+ return () => { alive = false; };
113
+ }, [node]);
114
+ const [scanKind, setScanKind] = useState('');
115
+ const [ssh, setSsh] = useState(null);
116
+ const [tab, setTab] = useState('hosts');
117
+ const loadSsh = async () => { try { const r = await api('sshHosts'); setSsh(r && (r.services || r.knownHosts) ? r : { unavailable: true }); } catch { setSsh({ unavailable: true }); } };
118
+ const scan = async (kind) => {
119
+ setScanKind(kind); setBusy(true); setErr('');
120
+ try { setData(await api('devices', { node })); await loadSsh(); }
121
+ catch (e) { setErr(String(e?.message || e)); }
122
+ finally { setBusy(false); }
123
+ };
124
+ const groups = {};
125
+ for (const d of data?.devices || []) (groups[d.kind] || (groups[d.kind] = [])).push(d);
126
+ const renderDevice = (d) => h('div', { className: 'cx-device', key: d.id },
127
+ h('span', { className: `cx-led${['running', 'online', 'paired'].includes(d.status) ? ' on' : ''}` }),
128
+ h('div', { style: { flex: 1, minWidth: 0 } },
129
+ h('div', { className: 'dn' }, d.name),
130
+ h('div', { className: 'dd' }, `${d.address || '—'} · ${d.status || ''}`)),
131
+ h('span', { className: 'cx-tag cy' }, d.controllable ? 'CONTROL' : 'DISCOVER'),
132
+ d.kind === 'contextos' ? h('button', { className: 'cx-btn xs', onClick: () => { try { window.open(`http://127.0.0.1:${String(d.address).split(':').pop()}`, '_blank'); } catch {} } }, '打开') : null);
133
+ const renderGroup = ([kind, list]) => h('div', { key: kind },
134
+ h('div', { className: 'oh', style: { marginTop: 6 } }, `${kind.toUpperCase()} · ${list.length}`),
135
+ list.map(renderDevice));
136
+ return h(Modal, { title: '扫描设备 / SCAN', desc: '远程主机(SSH 服务)/ WiFi 网络 / WiFi 设备(同网)/ 蓝牙设备 / ContextOS 节点;每条数据带复制、打开等操作。', onClose },
137
+ busy ? h('div', { className: 'desc' }, '扫描中…') : null,
138
+ err ? h(ErrorBox, { text: err }) : null,
139
+ data ? h('div', { className: 'cx-devices' },
140
+ h('div', { className: 'cx-adapter' }, (data.adapters || []).map((a) => h('span', { key: a.kind, className: `cx-tag ${a.supported ? 'gr' : ''}` }, `${a.kind}${a.supported ? '' : ' ✕'}`))),
141
+ h('div', { className: 'cx-dev-actions' },
142
+ h('button', { className: `cx-btn xs${scanKind === 'lan' ? ' on' : ''}`, onClick: () => scan('lan') }, '扫描同网设备'),
143
+ h('button', { className: `cx-btn xs${scanKind === 'wifi' ? ' on' : ''}`, onClick: () => scan('wifi') }, '扫描无线网络'),
144
+ h('button', { className: `cx-btn xs${scanKind === 'bt' ? ' on' : ''}`, onClick: () => scan('bt') }, '扫描蓝牙设备'),
145
+ h('button', { className: 'cx-btn xs', style: { marginLeft: 'auto' }, onClick: () => scan('') }, '重新扫描')),
146
+ h('div', { className: 'cx-scan-tabs' },
147
+ [
148
+ { id: 'hosts', label: '远程主机', n: (ssh?.services || []).length },
149
+ { id: 'lan', label: 'WIFI 设备', n: (data.lanHosts || []).length },
150
+ { id: 'wifi', label: 'WIFI 网络', n: (data.wifiNetworks || []).length },
151
+ { id: 'bt', label: '蓝牙设备', n: (data.bluetoothNearby || []).length + (data.devices || []).filter((d) => d.kind === 'bluetooth').length },
152
+ { id: 'ir', label: '红外设备', n: 0 },
153
+ ].map((t) => h('button', { key: t.id, className: `cx-scan-tab${tab === t.id ? ' on' : ''}`, onClick: () => setTab(t.id) }, t.label, h('span', { className: 'n' }, t.n)))),
154
+ h('div', { className: 'cx-scan-body' },
155
+ tab === 'hosts' ? ((ssh?.services || []).length
156
+ ? ssh.services.map((x, i) => h('div', { className: 'cx-device', key: 'svc' + i },
157
+ h('span', { className: 'cx-led on' }),
158
+ h('div', { style: { flex: 1, minWidth: 0 } }, h('div', { className: 'dn' }, x.name), h('div', { className: 'dd' }, `${x.username ? x.username + '@' : ''}${x.host}:${x.port}${x.init ? ' · ' + x.init : ''}`)),
159
+ h('button', { className: 'cx-btn xs', onClick: () => { try { navigator.clipboard.writeText(`ssh ${x.username ? x.username + '@' : ''}${x.host} -p ${x.port}`); } catch {} } }, '复制')))
160
+ : h('div', { className: 'cx-empty-d' }, ssh && ssh.unavailable ? '服务端版本过旧:请重启 DSH 以启用 SSH 主机扫描' : '没有读取到 ~/.ssh/host 服务(目录:~/.ssh/host/*.json)'))
161
+ : null,
162
+ tab === 'wifi' ? ((data.wifiNetworks || []).length
163
+ ? data.wifiNetworks.slice(0, 30).map((n, i) => h('div', { className: 'cx-device', key: 'wn' + i },
164
+ h('span', { className: 'cx-led on' }),
165
+ h('div', { style: { flex: 1, minWidth: 0 } }, h('div', { className: 'dn' }, n.ssid || '(隐藏)'), h('div', { className: 'dd' }, `${n.bssid || '—'} · ch ${n.channel || '—'}${n.rssi != null ? ` · ${n.rssi} dBm` : ''}`)),
166
+ h('button', { className: 'cx-btn xs', onClick: () => { try { navigator.clipboard.writeText(n.ssid || ''); } catch {} } }, '复制')))
167
+ : h('div', { className: 'cx-empty-d' }, '没有扫描到无线网络'))
168
+ : null,
169
+ tab === 'lan' ? ((data.lanHosts || []).length
170
+ ? data.lanHosts.slice(0, 40).map((x, i) => h('div', { className: 'cx-device', key: 'lan' + i },
171
+ h('span', { className: 'cx-led on' }),
172
+ h('div', { style: { flex: 1, minWidth: 0 } }, h('div', { className: 'dn' }, x.name || x.ip), h('div', { className: 'dd' }, `${x.ip} · ${x.mac}`)),
173
+ h('button', { className: 'cx-btn xs', onClick: () => { try { window.open(`http://${x.ip}`, '_blank'); } catch {} } }, '打开'),
174
+ h('button', { className: 'cx-btn xs', onClick: () => { try { navigator.clipboard.writeText(x.ip || ''); } catch {} } }, '复制')))
175
+ : h('div', { className: 'cx-empty-d' }, '没有同网设备'))
176
+ : null,
177
+ tab === 'bt' ? (((data.bluetoothNearby || []).length || (data.devices || []).some((d) => d.kind === 'bluetooth'))
178
+ ? [(data.bluetoothNearby || []).map((d, i) => h('div', { className: 'cx-device', key: 'bt' + i },
179
+ h('span', { className: 'cx-led on' }),
180
+ h('div', { style: { flex: 1, minWidth: 0 } }, h('div', { className: 'dn' }, d.name || d.address || 'BLE'), h('div', { className: 'dd' }, `${d.address || '—'}${d.rssi != null ? ` · ${d.rssi} dBm` : ''} · 附近`)),
181
+ h('button', { className: 'cx-btn xs', onClick: () => { try { navigator.clipboard.writeText(d.address || d.name || ''); } catch {} } }, '复制'))),
182
+ (data.devices || []).filter((d) => d.kind === 'bluetooth').map((d) => h('div', { className: 'cx-device', key: d.id },
183
+ h('span', { className: 'cx-led on' }),
184
+ h('div', { style: { flex: 1, minWidth: 0 } }, h('div', { className: 'dn' }, d.name), h('div', { className: 'dd' }, `${d.address || '—'} · ${d.status || 'paired'}`)),
185
+ h('span', { className: 'cx-tag cy' }, 'PAIRED')))]
186
+ : h('div', { className: 'cx-empty-d' }, '没有蓝牙设备(附近扫描需安装 blueutil)'))
187
+ : null,
188
+ tab === 'ir' ? (() => {
189
+ const ad = (data.adapters || []).find((a) => a.kind === 'infrared');
190
+ return ad && ad.supported
191
+ ? h('div', { className: 'cx-empty-d' }, '红外适配器已就绪,等待发现设备')
192
+ : h('div', { className: 'cx-empty-d' }, `当前宿主无红外适配器${ad && ad.reason ? '(' + ad.reason + ')' : ''}`);
193
+ })() : null),
194
+ h('div', { className: 'desc' }, data.note || '')) : null);
195
+ }
196
+
197
+ function DataModal({ node, space, app, onClose }) {
198
+ const funcs = app?.functions?.length ? app.functions : ['profile'];
199
+ const [fn, setFn] = useState(funcs[0]);
200
+ const [rows, setRows] = useState([{ k: 'title', v: '张三' }, { k: 'content', v: '员工档案' }]);
201
+ const [data, setData] = useState(null);
202
+ const [busy, setBusy] = useState(false);
203
+ const [err, setErr] = useState('');
204
+ const [fresh, setFresh] = useState(false);
205
+ const command = `web.team.${app.name}.${fn}`;
206
+ const fields = Object.fromEntries(rows.filter((r) => r.k.trim()).map((r) => [r.k.trim(), r.v]));
207
+ const run = async (write) => {
208
+ setBusy(true); setErr('');
209
+ try {
210
+ if (write) await api('writeData', { node: Number(node), space, command, fields });
211
+ setData(await api('readData', { node: Number(node), space, command }));
212
+ if (write) { setFresh(true); setTimeout(() => setFresh(false), 1800); }
213
+ } catch (e) { setErr(String(e?.message || e)); } finally { setBusy(false); }
214
+ };
215
+ let table = null;
216
+ if (data) {
217
+ const columns = (data.columns || []).slice(0, 6);
218
+ table = h('div', { className: `cx-data-table${fresh ? ' fresh' : ''}`, style: { marginTop: 10, maxHeight: 180, overflow: 'auto' } },
219
+ h('div', { className: 'cx-meta' }, `count=${data.count || '—'} · rows=${data.rows?.length || 0}`),
220
+ h('table', { className: 'cx-table' },
221
+ h('thead', null, h('tr', null, columns.map((c) => h('th', { key: c }, c)))),
222
+ h('tbody', null, (data.rows || []).slice(0, 8).map((row, i) => h('tr', { key: i },
223
+ columns.map((c) => h('td', { key: c }, String(row[c] ?? '').slice(0, 28))))))));
224
+ }
225
+ return h(Modal, { title: `DATA / ${app.title || app.name}`, desc: `目标命令:${command};写后回读,200/0x0 不算成功。`, onClose },
226
+ h('div', { className: 'cx-form' },
227
+ h('label', { className: 'cx-field full' }, 'FUNCTION', h('select', { className: 'cx-select', value: fn, onChange: (e) => setFn(e.target.value) }, funcs.map((f) => h('option', { key: f, value: f }, f)))),
228
+ rows.map((r, i) => h('div', { key: i, className: 'cx-row full' },
229
+ h('input', { className: 'cx-input', value: r.k, placeholder: 'field', onChange: (e) => setRows((rs) => rs.map((x, j) => j === i ? { ...x, k: e.target.value } : x)) }),
230
+ h('input', { className: 'cx-input', value: r.v, placeholder: 'value', onChange: (e) => setRows((rs) => rs.map((x, j) => j === i ? { ...x, v: e.target.value } : x)) }),
231
+ h(IconButton, { name: 'close', className: 'cx-btn xs', onClick: () => setRows((rs) => rs.filter((_, j) => j !== i)) })))),
232
+ h('button', { className: 'cx-btn xs', onClick: () => setRows((rs) => [...rs, { k: '', v: '' }]) }, '+ FIELD'),
233
+ err ? h(ErrorBox, { text: err }) : null,
234
+ table,
235
+ h('div', { className: 'cx-foot' }, h('button', { className: 'cx-btn', onClick: onClose }, T('关闭')), h('button', { className: 'cx-btn', disabled: busy, onClick: () => run(false) }, 'READ'), h('button', { className: 'cx-btn pri', disabled: busy, onClick: () => run(true) }, busy ? 'WORKING…' : 'WRITE + READ')));
236
+ }
237
+
238
+ async function fallbackApps(node, space) {
239
+ try {
240
+ const d = await api('listDir', { node, space, path: 'src' });
241
+ const out = [];
242
+ for (const e of d.entries || []) {
243
+ if (e.type !== 'dir') continue;
244
+ try {
245
+ const f = await api('readFile', { node, space, path: `src/${e.name}/portal.json` });
246
+ const portal = JSON.parse(f.content);
247
+ out.push({
248
+ name: e.name,
249
+ title: portal.portal || e.name,
250
+ command: `web.team.${e.name}.portal`,
251
+ path: `src/${e.name}/portal.json`,
252
+ functions: Object.keys(portal).filter((k) => !['portal', 'input', 'value'].includes(k)),
253
+ offlineFallback: true,
254
+ });
255
+ } catch {}
256
+ }
257
+ return out;
258
+ } catch { return []; }
259
+ }
260
+
261
+ const INIT_DEFAULTS = { dir: '~/ContextOS-9188', port: 9188, repo: 'https://shylinux.com/x/ContextOS' };
262
+ const repoName = (repo) => {
263
+ const text = String(repo || '').trim().replace(/\/$/, '');
264
+ if (!text) return '';
265
+ const name = text.split('/').pop().replace(/\.git$/i, '');
266
+ return /^[A-Za-z0-9._-]+$/.test(name) ? name : '';
267
+ };