cortico 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/LICENSE +21 -0
- package/README.md +47 -0
- package/package.json +43 -0
- package/src/boot.ts +46 -0
- package/src/bot.ts +1342 -0
- package/src/config-file.ts +41 -0
- package/src/core/README.md +92 -0
- package/src/core/billing.ts +26 -0
- package/src/core/blobs.ts +106 -0
- package/src/core/bus.ts +311 -0
- package/src/core/config-schema.ts +201 -0
- package/src/core/config.ts +262 -0
- package/src/core/core.ts +699 -0
- package/src/core/cost.ts +244 -0
- package/src/core/event-store.ts +304 -0
- package/src/core/fork.ts +113 -0
- package/src/core/generation.ts +118 -0
- package/src/core/instance-lock.ts +215 -0
- package/src/core/ipc-logger.ts +105 -0
- package/src/core/language.ts +62 -0
- package/src/core/log-context.ts +38 -0
- package/src/core/loop.ts +1858 -0
- package/src/core/markers.ts +48 -0
- package/src/core/prefix.ts +121 -0
- package/src/core/run.ts +95 -0
- package/src/core/secrets.ts +18 -0
- package/src/core/session.ts +56 -0
- package/src/core/sessions.ts +261 -0
- package/src/core/state.ts +104 -0
- package/src/core/template.ts +72 -0
- package/src/core/timers.ts +129 -0
- package/src/core/tool-log.ts +135 -0
- package/src/core/transcript.ts +92 -0
- package/src/core/truncate.ts +121 -0
- package/src/core/types.ts +1140 -0
- package/src/core/usage-log.ts +79 -0
- package/src/core/util.ts +386 -0
- package/src/deploy-listing.ts +160 -0
- package/src/deploy.ts +162 -0
- package/src/extensions/README.md +72 -0
- package/src/extensions/dry-mount.ts +390 -0
- package/src/extensions/manifest.ts +153 -0
- package/src/extensions/runtime.ts +42 -0
- package/src/extensions.ts +519 -0
- package/src/launcher.ts +285 -0
- package/src/paths.ts +155 -0
- package/src/protocol/open-responses/LICENSE +201 -0
- package/src/protocol/open-responses/README.md +14 -0
- package/src/protocol/open-responses/context-helpers.ts +27 -0
- package/src/protocol/open-responses/context-log.ts +59 -0
- package/src/protocol/open-responses/context.ts +89 -0
- package/src/protocol/open-responses/generated.ts +115 -0
- package/src/protocol/open-responses/index.ts +33 -0
- package/src/protocol/open-responses/openapi.json +4230 -0
- package/src/protocol/open-responses/stream.ts +146 -0
- package/src/protocol/open-responses/tokens.ts +31 -0
- package/src/providers/README.md +86 -0
- package/src/providers/base.ts +111 -0
- package/src/providers/configuration.ts +97 -0
- package/src/providers/console/config.ts +21 -0
- package/src/providers/console/settings.ts +443 -0
- package/src/providers/console/strings.ts +74 -0
- package/src/providers/console/types.ts +11 -0
- package/src/providers/llamacpp/archive.ts +148 -0
- package/src/providers/llamacpp/catalog.ts +247 -0
- package/src/providers/llamacpp/config.ts +36 -0
- package/src/providers/llamacpp/console/client.ts +6 -0
- package/src/providers/llamacpp/console/models-panel.ts +120 -0
- package/src/providers/llamacpp/console/runtime-panel.ts +173 -0
- package/src/providers/llamacpp/console/server.ts +153 -0
- package/src/providers/llamacpp/index.ts +95 -0
- package/src/providers/llamacpp/native.ts +51 -0
- package/src/providers/llamacpp/options.ts +117 -0
- package/src/providers/llamacpp/runtime-store.ts +139 -0
- package/src/providers/llamacpp/runtime.ts +214 -0
- package/src/providers/llamacpp/server.ts +286 -0
- package/src/providers/llamacpp/strings.ts +230 -0
- package/src/providers/openai-responses-compat/config.ts +20 -0
- package/src/providers/openai-responses-compat/index.ts +89 -0
- package/src/providers/openai-responses-compat/native.ts +127 -0
- package/src/providers/openai-responses-compat/strings.ts +19 -0
- package/src/providers/pricebook.ts +75 -0
- package/src/providers/registry.ts +137 -0
- package/src/providers/strings.ts +71 -0
- package/src/providers/transport/chat.ts +156 -0
- package/src/providers/transport/errors.ts +48 -0
- package/src/providers/transport/history.ts +68 -0
- package/src/providers/transport/native-input.ts +83 -0
- package/src/providers/transport/native-types.ts +13 -0
- package/src/providers/transport/response-assembly.ts +191 -0
- package/src/providers/transport/response-http.ts +196 -0
- package/src/providers/transport/response-meters.ts +27 -0
- package/src/providers/transport/responses-input.ts +56 -0
- package/src/web/README.md +84 -0
- package/src/web/client/console-pages/builtins/llm-settings/panel.ts +625 -0
- package/src/web/client/console-pages/builtins/llm-settings/pricing-panel.ts +168 -0
- package/src/web/client/console-pages/builtins/llm-settings/strings.ts +213 -0
- package/src/web/client/console-pages/builtins.ts +10 -0
- package/src/web/client/console-pages/context.ts +135 -0
- package/src/web/client/console-pages/host.ts +633 -0
- package/src/web/client/console-pages/loader.ts +132 -0
- package/src/web/client/console-pages/strings.ts +90 -0
- package/src/web/client/console-pages/tools/strings.ts +49 -0
- package/src/web/client/console-pages/tools/view.ts +215 -0
- package/src/web/client/core/api.ts +200 -0
- package/src/web/client/core/language.ts +56 -0
- package/src/web/client/core/lifecycle.ts +132 -0
- package/src/web/client/core/router.ts +199 -0
- package/src/web/client/core/stream.ts +157 -0
- package/src/web/client/core/websocket.ts +82 -0
- package/src/web/client/features/appearance/index.ts +333 -0
- package/src/web/client/features/appearance/strings.ts +87 -0
- package/src/web/client/features/config/index.ts +11 -0
- package/src/web/client/features/config/strings.ts +41 -0
- package/src/web/client/features/config/view.ts +428 -0
- package/src/web/client/features/core/events.ts +197 -0
- package/src/web/client/features/core/index.ts +254 -0
- package/src/web/client/features/core/run.ts +56 -0
- package/src/web/client/features/core/runlog.ts +214 -0
- package/src/web/client/features/core/sessions.ts +53 -0
- package/src/web/client/features/core/strings.ts +157 -0
- package/src/web/client/features/extensions/index.ts +422 -0
- package/src/web/client/features/extensions/strings.ts +164 -0
- package/src/web/client/features/feature.ts +93 -0
- package/src/web/client/features/live/context.ts +280 -0
- package/src/web/client/features/live/fork.ts +156 -0
- package/src/web/client/features/live/index.ts +392 -0
- package/src/web/client/features/live/onboarding.ts +113 -0
- package/src/web/client/features/live/protocol.ts +122 -0
- package/src/web/client/features/live/sessions.ts +71 -0
- package/src/web/client/features/live/status.ts +68 -0
- package/src/web/client/features/live/strings.ts +252 -0
- package/src/web/client/features/live/timeline.ts +590 -0
- package/src/web/client/features/prompts/editor.ts +292 -0
- package/src/web/client/features/prompts/index.ts +346 -0
- package/src/web/client/features/prompts/strings.ts +136 -0
- package/src/web/client/features/prompts/view.ts +256 -0
- package/src/web/client/features/providers/index.ts +100 -0
- package/src/web/client/features/providers/strings.ts +23 -0
- package/src/web/client/features/settings/general.ts +28 -0
- package/src/web/client/features/settings/index.ts +82 -0
- package/src/web/client/features/settings/strings.ts +33 -0
- package/src/web/client/features/storage/index.ts +1 -0
- package/src/web/client/features/storage/strings.ts +45 -0
- package/src/web/client/features/storage/view.ts +154 -0
- package/src/web/client/features/usage/chart.ts +486 -0
- package/src/web/client/features/usage/index.ts +407 -0
- package/src/web/client/features/usage/labels.ts +46 -0
- package/src/web/client/features/usage/range.ts +36 -0
- package/src/web/client/features/usage/state.ts +37 -0
- package/src/web/client/features/usage/strings.ts +191 -0
- package/src/web/client/features/usage/tooltip.ts +86 -0
- package/src/web/client/features/usage/types.ts +96 -0
- package/src/web/client/features/worlds/index.ts +424 -0
- package/src/web/client/features/worlds/strings.ts +121 -0
- package/src/web/client/main.ts +273 -0
- package/src/web/client/shell/avatar.ts +233 -0
- package/src/web/client/shell/index.ts +549 -0
- package/src/web/client/shell/strings.ts +89 -0
- package/src/web/client/theme/handoff.ts +43 -0
- package/src/web/client/theme/palette.ts +109 -0
- package/src/web/client/theme/registry.ts +130 -0
- package/src/web/client/theme/storage.ts +72 -0
- package/src/web/client/theme/strings.ts +123 -0
- package/src/web/client/theme/studio.ts +366 -0
- package/src/web/client/ui/actions.ts +109 -0
- package/src/web/client/ui/data.ts +185 -0
- package/src/web/client/ui/dom.ts +23 -0
- package/src/web/client/ui/fields.ts +191 -0
- package/src/web/client/ui/format.ts +75 -0
- package/src/web/client/ui/icons.ts +183 -0
- package/src/web/client/ui/images.ts +91 -0
- package/src/web/client/ui/index.ts +89 -0
- package/src/web/client/ui/lamp.ts +125 -0
- package/src/web/client/ui/log.ts +98 -0
- package/src/web/client/ui/overlay.ts +184 -0
- package/src/web/client/ui/page.ts +8 -0
- package/src/web/client/ui/prompt-input.tsx +311 -0
- package/src/web/client/ui/sheet.ts +131 -0
- package/src/web/client/ui/strings.ts +71 -0
- package/src/web/console-pages.ts +367 -0
- package/src/web/files.ts +107 -0
- package/src/web/path-picker.ts +296 -0
- package/src/web/public/index.html +17 -0
- package/src/web/public/styles.css +1715 -0
- package/src/web/server.ts +1883 -0
- package/src/web/shared/client-panel.ts +603 -0
- package/src/web/shared/console-protocol.ts +560 -0
- package/src/web/shared/css.d.ts +1 -0
- package/src/web/shared/path-picker.ts +23 -0
- package/src/web/shared/theme.ts +256 -0
- package/src/web/theme-store.ts +37 -0
- package/src/world.ts +449 -0
- package/src/worlds/bilibili/ENV_PROMPT.md +5 -0
- package/src/worlds/bilibili/README.md +176 -0
- package/src/worlds/bilibili/audience-admission.ts +995 -0
- package/src/worlds/bilibili/client.ts +528 -0
- package/src/worlds/bilibili/coalescing-buffer.ts +125 -0
- package/src/worlds/bilibili/config.ts +185 -0
- package/src/worlds/bilibili/console/client.ts +202 -0
- package/src/worlds/bilibili/definition.ts +35 -0
- package/src/worlds/bilibili/gift-frame.ts +131 -0
- package/src/worlds/bilibili/normalize.ts +452 -0
- package/src/worlds/bilibili/overlay/announcement.ts +76 -0
- package/src/worlds/bilibili/overlay/assets.ts +82 -0
- package/src/worlds/bilibili/overlay/model.ts +494 -0
- package/src/worlds/bilibili/overlay/project.ts +202 -0
- package/src/worlds/bilibili/overlay/server.ts +286 -0
- package/src/worlds/bilibili/overlay/types.ts +217 -0
- package/src/worlds/bilibili/overlay/web/app.js +690 -0
- package/src/worlds/bilibili/overlay/web/editor.css +297 -0
- package/src/worlds/bilibili/overlay/web/editor.html +102 -0
- package/src/worlds/bilibili/overlay/web/editor.js +2116 -0
- package/src/worlds/bilibili/overlay/web/overlay.html +13 -0
- package/src/worlds/bilibili/overlay/web/styles.css +258 -0
- package/src/worlds/bilibili/protobuf.ts +123 -0
- package/src/worlds/bilibili/wire.ts +94 -0
- package/src/worlds/bilibili/world.ts +1389 -0
- package/src/worlds/console-fixture/ENV_PROMPT.md +1 -0
- package/src/worlds/console-fixture/console/client.ts +72 -0
- package/src/worlds/console-fixture/world.ts +73 -0
- package/src/worlds/index.ts +15 -0
- package/src/worlds/minecraft/ENV_PROMPT.md +32 -0
- package/src/worlds/minecraft/ENV_PROMPT_CAMERA.md +2 -0
- package/src/worlds/minecraft/LICENSE-mineflayer-pathfinder.txt +21 -0
- package/src/worlds/minecraft/README.md +917 -0
- package/src/worlds/minecraft/blueprint-plan.ts +915 -0
- package/src/worlds/minecraft/blueprint-registry.ts +566 -0
- package/src/worlds/minecraft/blueprint-repair.ts +236 -0
- package/src/worlds/minecraft/blueprint-resource.ts +272 -0
- package/src/worlds/minecraft/blueprint.ts +492 -0
- package/src/worlds/minecraft/body-lease.ts +340 -0
- package/src/worlds/minecraft/bridge.ts +749 -0
- package/src/worlds/minecraft/check.ts +651 -0
- package/src/worlds/minecraft/chests.ts +292 -0
- package/src/worlds/minecraft/client-launch.ts +272 -0
- package/src/worlds/minecraft/client-options.ts +85 -0
- package/src/worlds/minecraft/client-skins.ts +164 -0
- package/src/worlds/minecraft/client-window.ps1 +91 -0
- package/src/worlds/minecraft/client.ts +423 -0
- package/src/worlds/minecraft/combat-context.ts +109 -0
- package/src/worlds/minecraft/combat.ts +1552 -0
- package/src/worlds/minecraft/config.ts +499 -0
- package/src/worlds/minecraft/console/access.ts +218 -0
- package/src/worlds/minecraft/console/client.ts +244 -0
- package/src/worlds/minecraft/console/log.ts +110 -0
- package/src/worlds/minecraft/console/mount.ts +420 -0
- package/src/worlds/minecraft/console/skin.ts +257 -0
- package/src/worlds/minecraft/console/style.css +154 -0
- package/src/worlds/minecraft/console/world.ts +449 -0
- package/src/worlds/minecraft/deaths.ts +135 -0
- package/src/worlds/minecraft/definition.ts +18 -0
- package/src/worlds/minecraft/engine-child.ts +274 -0
- package/src/worlds/minecraft/engine-ipc.ts +98 -0
- package/src/worlds/minecraft/entity-facts.ts +132 -0
- package/src/worlds/minecraft/escape.ts +407 -0
- package/src/worlds/minecraft/executor.ts +14494 -0
- package/src/worlds/minecraft/explored.ts +156 -0
- package/src/worlds/minecraft/geometry.ts +205 -0
- package/src/worlds/minecraft/goal-plan.ts +647 -0
- package/src/worlds/minecraft/item-break.ts +126 -0
- package/src/worlds/minecraft/item-facts.ts +146 -0
- package/src/worlds/minecraft/item-pick.ts +67 -0
- package/src/worlds/minecraft/level-dat.ts +176 -0
- package/src/worlds/minecraft/log.ts +132 -0
- package/src/worlds/minecraft/mineflayer-fixes.ts +1180 -0
- package/src/worlds/minecraft/names.ts +377 -0
- package/src/worlds/minecraft/pathfinder-lib.d.ts +13 -0
- package/src/worlds/minecraft/pathfinder-perf.ts +796 -0
- package/src/worlds/minecraft/piglin.ts +49 -0
- package/src/worlds/minecraft/policy.ts +547 -0
- package/src/worlds/minecraft/precheck.ts +655 -0
- package/src/worlds/minecraft/proxy.ts +445 -0
- package/src/worlds/minecraft/ranged.ts +635 -0
- package/src/worlds/minecraft/readouts.ts +102 -0
- package/src/worlds/minecraft/round.ts +26 -0
- package/src/worlds/minecraft/search-observation.ts +92 -0
- package/src/worlds/minecraft/server-config.ts +467 -0
- package/src/worlds/minecraft/server.ts +658 -0
- package/src/worlds/minecraft/show.ts +84 -0
- package/src/worlds/minecraft/skills.ts +1763 -0
- package/src/worlds/minecraft/terrain.ts +1735 -0
- package/src/worlds/minecraft/window.ts +96 -0
- package/src/worlds/minecraft/works.ts +179 -0
- package/src/worlds/minecraft/world.ts +6438 -0
- package/src/worlds/qq/ENV_PROMPT.md +5 -0
- package/src/worlds/qq/config.ts +108 -0
- package/src/worlds/qq/console/client.ts +126 -0
- package/src/worlds/qq/console/events.ts +155 -0
- package/src/worlds/qq/console/gate.ts +232 -0
- package/src/worlds/qq/console/roster.ts +203 -0
- package/src/worlds/qq/console/style.css +65 -0
- package/src/worlds/qq/conversation.ts +28 -0
- package/src/worlds/qq/definition.ts +62 -0
- package/src/worlds/qq/driver.ts +375 -0
- package/src/worlds/qq/history-tools.ts +209 -0
- package/src/worlds/qq/normalize.ts +323 -0
- package/src/worlds/qq/qface-map.ts +282 -0
- package/src/worlds/qq/vision-prompt.ts +27 -0
- package/src/worlds/qq/vision.ts +642 -0
- package/src/worlds/qq/vlm.ts +142 -0
- package/src/worlds/qq/world.ts +1503 -0
- package/src/worlds/terminal/ENV_PROMPT.md +11 -0
- package/src/worlds/terminal/config.ts +9 -0
- package/src/worlds/terminal/definition.ts +14 -0
- package/src/worlds/terminal/world.ts +700 -0
- package/src/worlds/websearch/ENV_PROMPT.md +1 -0
- package/src/worlds/websearch/brave-client.ts +261 -0
- package/src/worlds/websearch/config.ts +75 -0
- package/src/worlds/websearch/definition.ts +20 -0
- package/src/worlds/websearch/world.ts +171 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { pick } from '../../core/language.ts';
|
|
2
|
+
|
|
3
|
+
const zh = {
|
|
4
|
+
// index.ts
|
|
5
|
+
navLabel: '运行诊断',
|
|
6
|
+
navGroup: 'Core',
|
|
7
|
+
pageTitle: '运行诊断',
|
|
8
|
+
subRun: '运行',
|
|
9
|
+
subSessions: '会话统计',
|
|
10
|
+
subEvents: '事件流',
|
|
11
|
+
subRunlog: '运行日志',
|
|
12
|
+
subData: '数据',
|
|
13
|
+
subConfig: '配置',
|
|
14
|
+
dataTitle: 'Core 的数据',
|
|
15
|
+
dataDesc: '',
|
|
16
|
+
configTitle: 'Core 配置',
|
|
17
|
+
configDesc: '修改自动保存到 config.json。标有重启要求的配置在重启后生效,其余立即生效。',
|
|
18
|
+
configEmpty: 'Core 没有可调配置。',
|
|
19
|
+
netOffline: '接口不可达',
|
|
20
|
+
|
|
21
|
+
// events.ts
|
|
22
|
+
eventsDesc: '事件记录,agent 可查询。',
|
|
23
|
+
allSources: '全部来源',
|
|
24
|
+
showArchive: '显示原始归档',
|
|
25
|
+
showArchiveTitle: '包括仅归档、未直接投递到上下文的事件',
|
|
26
|
+
loadEarlier: '← 加载更早',
|
|
27
|
+
evHeadTime: '时间',
|
|
28
|
+
evHeadSource: '来源',
|
|
29
|
+
evHeadType: '类型',
|
|
30
|
+
evHeadText: '正文',
|
|
31
|
+
noEvents: '暂无事件',
|
|
32
|
+
|
|
33
|
+
// run.ts
|
|
34
|
+
runTitle: '运行态',
|
|
35
|
+
noStatus: '暂无状态',
|
|
36
|
+
statContext: '上下文',
|
|
37
|
+
statMessages: 'session 消息',
|
|
38
|
+
statCache: '缓存命中',
|
|
39
|
+
statRounds: '本批轮数',
|
|
40
|
+
statBatches: '累计批次',
|
|
41
|
+
statEvents: '事件库',
|
|
42
|
+
statOnline: '终端在线',
|
|
43
|
+
statRun: '运行',
|
|
44
|
+
unitMsgs: '条',
|
|
45
|
+
unitEvents: '条',
|
|
46
|
+
unitPeople: '人',
|
|
47
|
+
runPaused: '暂停',
|
|
48
|
+
runBlocked: '闹钟阻断',
|
|
49
|
+
runRunning: '进行',
|
|
50
|
+
|
|
51
|
+
// runlog.ts
|
|
52
|
+
currentRun: '当前 run',
|
|
53
|
+
allLevels: '全部级别',
|
|
54
|
+
areaPlaceholder: '区域前缀,如 worlds.minecraft', // arch-allow: 日志区域筛选框的示例前缀,只是示意文字
|
|
55
|
+
grepPlaceholder: '正则,匹配内容与 data',
|
|
56
|
+
roundPlaceholder: '轮次',
|
|
57
|
+
roundField: '轮次',
|
|
58
|
+
refresh: '刷新',
|
|
59
|
+
runlogDesc: '运行日志,agent 不可见。',
|
|
60
|
+
logHeadTime: '时间',
|
|
61
|
+
logHeadLevel: '级别',
|
|
62
|
+
logHeadArea: '区域',
|
|
63
|
+
logHeadMsg: '内容',
|
|
64
|
+
noLog: '暂无日志',
|
|
65
|
+
|
|
66
|
+
// sessions.ts
|
|
67
|
+
sessionsTitle: '会话统计',
|
|
68
|
+
sessionsDesc: '本次运行中各 session 的 token 用量与缓存命中。跨重启统计见「用量与成本」。',
|
|
69
|
+
sesHeadStatus: '状态',
|
|
70
|
+
sesHeadCalls: '调用',
|
|
71
|
+
sesHeadInput: '输入 tok',
|
|
72
|
+
sesHeadCache: '缓存命中',
|
|
73
|
+
sesHeadOutput: '输出 tok',
|
|
74
|
+
sesHeadMsgs: '消息',
|
|
75
|
+
noSessions: '暂无 session',
|
|
76
|
+
running: '进行中',
|
|
77
|
+
ended: '已结束',
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const en: typeof zh = {
|
|
81
|
+
// index.ts
|
|
82
|
+
navLabel: 'Diagnostics',
|
|
83
|
+
navGroup: 'Core',
|
|
84
|
+
pageTitle: 'Diagnostics',
|
|
85
|
+
subRun: 'Run',
|
|
86
|
+
subSessions: 'Sessions',
|
|
87
|
+
subEvents: 'Events',
|
|
88
|
+
subRunlog: 'Run log',
|
|
89
|
+
subData: 'Data',
|
|
90
|
+
subConfig: 'Config',
|
|
91
|
+
dataTitle: 'Core data',
|
|
92
|
+
dataDesc: '',
|
|
93
|
+
configTitle: 'Core config',
|
|
94
|
+
configDesc: 'Changes save to config.json automatically. Settings marked for restart apply after restarting; the rest apply immediately.',
|
|
95
|
+
configEmpty: 'Core has no tunable settings.',
|
|
96
|
+
netOffline: 'API unreachable',
|
|
97
|
+
|
|
98
|
+
// events.ts
|
|
99
|
+
eventsDesc: 'Event records, queryable by the agent.',
|
|
100
|
+
allSources: 'All sources',
|
|
101
|
+
showArchive: 'Show raw archive',
|
|
102
|
+
showArchiveTitle: 'Include archived events that are not delivered directly to the context',
|
|
103
|
+
loadEarlier: '← Load earlier',
|
|
104
|
+
evHeadTime: 'Time',
|
|
105
|
+
evHeadSource: 'Source',
|
|
106
|
+
evHeadType: 'Type',
|
|
107
|
+
evHeadText: 'Text',
|
|
108
|
+
noEvents: 'No events yet',
|
|
109
|
+
|
|
110
|
+
// run.ts
|
|
111
|
+
runTitle: 'Loop status',
|
|
112
|
+
noStatus: 'No status yet',
|
|
113
|
+
statContext: 'Context',
|
|
114
|
+
statMessages: 'session messages',
|
|
115
|
+
statCache: 'Cache hit',
|
|
116
|
+
statRounds: 'Rounds this batch',
|
|
117
|
+
statBatches: 'Total batches',
|
|
118
|
+
statEvents: 'Event store',
|
|
119
|
+
statOnline: 'Terminal online',
|
|
120
|
+
statRun: 'Run',
|
|
121
|
+
unitMsgs: 'msgs',
|
|
122
|
+
unitEvents: 'events',
|
|
123
|
+
unitPeople: 'users',
|
|
124
|
+
runPaused: 'paused',
|
|
125
|
+
runBlocked: 'schedule blocked',
|
|
126
|
+
runRunning: 'running',
|
|
127
|
+
|
|
128
|
+
// runlog.ts
|
|
129
|
+
currentRun: 'Current run',
|
|
130
|
+
allLevels: 'All levels',
|
|
131
|
+
areaPlaceholder: 'Area prefix, e.g. worlds.minecraft', // arch-allow: 日志区域筛选框的示例前缀,只是示意文字
|
|
132
|
+
grepPlaceholder: 'Regex, matches message and data',
|
|
133
|
+
roundPlaceholder: 'Round',
|
|
134
|
+
roundField: 'Round',
|
|
135
|
+
refresh: 'Refresh',
|
|
136
|
+
runlogDesc: 'Run logs, invisible to the agent.',
|
|
137
|
+
logHeadTime: 'Time',
|
|
138
|
+
logHeadLevel: 'Level',
|
|
139
|
+
logHeadArea: 'Area',
|
|
140
|
+
logHeadMsg: 'Message',
|
|
141
|
+
noLog: 'No log entries',
|
|
142
|
+
|
|
143
|
+
// sessions.ts
|
|
144
|
+
sessionsTitle: 'Session stats',
|
|
145
|
+
sessionsDesc: 'Token usage and cache hits for each session in this run. For history across restarts, see "Usage & cost".',
|
|
146
|
+
sesHeadStatus: 'Status',
|
|
147
|
+
sesHeadCalls: 'Calls',
|
|
148
|
+
sesHeadInput: 'Input tok',
|
|
149
|
+
sesHeadCache: 'Cache hit',
|
|
150
|
+
sesHeadOutput: 'Output tok',
|
|
151
|
+
sesHeadMsgs: 'Messages',
|
|
152
|
+
noSessions: 'No sessions yet',
|
|
153
|
+
running: 'running',
|
|
154
|
+
ended: 'ended',
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export const S = pick({ zh, en });
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
/** 扩展管理页。扩展信息与运行状态由服务端提供;安装、卸载后需重启进程才能生效。 */
|
|
2
|
+
|
|
3
|
+
import { get, post } from '../../core/api.ts';
|
|
4
|
+
import { pageIntro } from '../../ui/page.ts';
|
|
5
|
+
import type { FeatureContext, FrameworkFeature } from '../feature.ts';
|
|
6
|
+
import { S } from './strings.ts';
|
|
7
|
+
|
|
8
|
+
/** 扩展类别。与 `ExtensionKind` 同形;这一页只用它分组与选关键字。 */
|
|
9
|
+
export type ExtensionKindView = 'world' | 'provider' | 'bot';
|
|
10
|
+
|
|
11
|
+
/** 与 `src/web/server.ts` 的 `ExtensionInfo` 同形。 */
|
|
12
|
+
export interface ExtensionView {
|
|
13
|
+
name: string;
|
|
14
|
+
spec: string;
|
|
15
|
+
version: string | null;
|
|
16
|
+
description?: string;
|
|
17
|
+
kind?: ExtensionKindView;
|
|
18
|
+
api?: number;
|
|
19
|
+
consoleClient: boolean;
|
|
20
|
+
console?: 'none' | 'served' | 'missing';
|
|
21
|
+
loaded: boolean;
|
|
22
|
+
reason?: string;
|
|
23
|
+
worldId?: string;
|
|
24
|
+
label?: string;
|
|
25
|
+
state: 'loaded' | 'failed' | 'pending-restart' | 'removed' | 'idle';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** 与 `ExtensionSearchHit` 同形。 */
|
|
29
|
+
export interface SearchHitView {
|
|
30
|
+
name: string;
|
|
31
|
+
version: string;
|
|
32
|
+
description: string;
|
|
33
|
+
date?: string;
|
|
34
|
+
publisher?: string;
|
|
35
|
+
downloads: number;
|
|
36
|
+
links: { npm?: string; repository?: string; homepage?: string };
|
|
37
|
+
installed: boolean;
|
|
38
|
+
kind?: ExtensionKindView;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface PowerReport {
|
|
42
|
+
ok?: boolean;
|
|
43
|
+
localComplete?: boolean;
|
|
44
|
+
result?: string;
|
|
45
|
+
error?: string;
|
|
46
|
+
steps?: Array<{ label: string; ok: boolean; elapsedMs: number; detail?: string }>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function errText(err: unknown): string {
|
|
50
|
+
return err instanceof Error ? err.message : String(err);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function isAbort(err: unknown): boolean {
|
|
54
|
+
return (err as { name?: unknown } | null)?.name === 'AbortError';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 手动安装框里的一行:含路径分隔符或以 `.` 开头的当本机目录,其余按 `name[@version]`
|
|
59
|
+
* 拆(作用域包的第一个 `@` 是名字的一部分)。
|
|
60
|
+
*/
|
|
61
|
+
export function parseInstallInput(raw: string): { name: string; version?: string } | { path: string } | null {
|
|
62
|
+
const text = raw.trim();
|
|
63
|
+
if (!text) return null;
|
|
64
|
+
if (text.startsWith('.') || text.includes('/') && !text.startsWith('@') || text.includes('\\') || /^[A-Za-z]:/.test(text)) {
|
|
65
|
+
return { path: text };
|
|
66
|
+
}
|
|
67
|
+
const at = text.indexOf('@', 1);
|
|
68
|
+
if (at < 0) return { name: text };
|
|
69
|
+
return { name: text.slice(0, at), version: text.slice(at + 1) };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const STATE_LABEL: Record<ExtensionView['state'], string> = {
|
|
73
|
+
loaded: S.stateLoaded,
|
|
74
|
+
failed: S.stateFailed,
|
|
75
|
+
'pending-restart': S.statePendingRestart,
|
|
76
|
+
removed: S.stateRemoved,
|
|
77
|
+
idle: S.stateIdle,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const KIND_LABEL: Record<ExtensionKindView, string> = {
|
|
81
|
+
world: 'World',
|
|
82
|
+
provider: 'LLM Provider',
|
|
83
|
+
bot: 'Bot',
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** 卡片副标题里 id 前面的那个词。 */
|
|
87
|
+
const KIND_NOUN: Record<ExtensionKindView, string> = {
|
|
88
|
+
world: 'World',
|
|
89
|
+
provider: 'provider',
|
|
90
|
+
bot: 'bot',
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/** npm 上按类发现用的关键字。与 `src/extensions/manifest.ts` 的 `EXTENSION_KEYWORDS` 对齐。 */
|
|
94
|
+
const KIND_KEYWORD: Record<ExtensionKindView, string> = {
|
|
95
|
+
world: 'cortico-world',
|
|
96
|
+
provider: 'cortico-provider',
|
|
97
|
+
bot: 'cortico-bot',
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** 已安装清单的分组。`kind` 为 null 的一组收所有读不出 manifest 的包。 */
|
|
101
|
+
const GROUPS: ReadonlyArray<{ kind: ExtensionKindView | null; title: string; desc: string }> = [
|
|
102
|
+
{ kind: 'world', title: KIND_LABEL.world, desc: S.groupWorldDesc },
|
|
103
|
+
{ kind: 'provider', title: KIND_LABEL.provider, desc: S.groupProviderDesc },
|
|
104
|
+
{ kind: 'bot', title: KIND_LABEL.bot, desc: S.groupBotDesc },
|
|
105
|
+
{ kind: null, title: S.groupUnknownTitle, desc: S.groupUnknownDesc },
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
export function mountExtensions(ctx: FeatureContext): void {
|
|
109
|
+
const { ui, root } = ctx;
|
|
110
|
+
const view = root.ownerDocument?.defaultView ?? null;
|
|
111
|
+
const canRestart = ctx.capabilities.restart === true;
|
|
112
|
+
const supervised = ctx.capabilities.supervised === true;
|
|
113
|
+
|
|
114
|
+
const intro = pageIntro(ui, S.introTitle, S.introDesc);
|
|
115
|
+
|
|
116
|
+
// -------------------------------------------------------------------------
|
|
117
|
+
// 已安装
|
|
118
|
+
// -------------------------------------------------------------------------
|
|
119
|
+
|
|
120
|
+
const installedSheet = ui.sheet({
|
|
121
|
+
title: S.installedTitle,
|
|
122
|
+
en: 'extensions/',
|
|
123
|
+
});
|
|
124
|
+
const sumBar = ui.rowbar();
|
|
125
|
+
const msg = ui.msgline();
|
|
126
|
+
const refreshBtn = ui.button(S.refresh, { size: 'sm', onClick: () => void load() });
|
|
127
|
+
const restartBtn = ui.button(S.restartProcess, {
|
|
128
|
+
size: 'sm',
|
|
129
|
+
variant: 'primary',
|
|
130
|
+
onClick: (ev) => void restartProcess(ev.currentTarget as HTMLButtonElement),
|
|
131
|
+
});
|
|
132
|
+
installedSheet.body.append(sumBar, msg);
|
|
133
|
+
/** 分组容器:每组一条 section 标题 + 一张 `.iogrid`。 */
|
|
134
|
+
const installedGroups = ui.h('div');
|
|
135
|
+
|
|
136
|
+
function setMsg(text: string, bad?: boolean): void {
|
|
137
|
+
msg.textContent = text;
|
|
138
|
+
msg.className = 'msgline' + (bad ? ' bad' : '');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 重启 = 落标志 + 规范关机。没有启动器循环时它就是一次关机,确认框上说清楚。
|
|
143
|
+
* `confirmed` = 调用方已经问过一遍(装完那一问),不再重复。
|
|
144
|
+
*/
|
|
145
|
+
async function restartProcess(btn?: HTMLButtonElement, confirmed = false): Promise<void> {
|
|
146
|
+
if (!canRestart) return;
|
|
147
|
+
if (!confirmed) {
|
|
148
|
+
const ok = await ui.confirm({
|
|
149
|
+
title: supervised ? S.restartConfirmTitle : S.restartNoLoopTitle,
|
|
150
|
+
body: supervised ? S.restartConfirmBody : S.restartNoLoopBody,
|
|
151
|
+
danger: !supervised,
|
|
152
|
+
});
|
|
153
|
+
if (!ok || ctx.signal.aborted) return;
|
|
154
|
+
}
|
|
155
|
+
const lock = btn ? ui.disable(btn) : null;
|
|
156
|
+
const hold = ui.toast(S.finishingToast);
|
|
157
|
+
try {
|
|
158
|
+
const out = await post<PowerReport>('/api/run/restart', undefined, { signal: ctx.signal });
|
|
159
|
+
if (ctx.signal.aborted) return;
|
|
160
|
+
if (out?.error) throw new Error(out.error);
|
|
161
|
+
const lines = (out?.steps ?? []).map((s) =>
|
|
162
|
+
`${s.ok ? '✓' : '✗'} ${s.label} · ${(s.elapsedMs / 1000).toFixed(1)}s${s.ok ? '' : ` — ${s.detail ?? S.stepIncomplete}`}`);
|
|
163
|
+
void ui.confirm({
|
|
164
|
+
title: supervised ? S.doneRestartSupervised : S.doneRestart,
|
|
165
|
+
body: [out?.result ?? S.resultDefault, '', ...lines].join('\n'),
|
|
166
|
+
});
|
|
167
|
+
} catch (err) {
|
|
168
|
+
if (isAbort(err) || ctx.signal.aborted) return;
|
|
169
|
+
// 连接在收尾途中断掉是预期之一:进程退出得比回执快。
|
|
170
|
+
ui.toast(S.noReceipt(errText(err)), 'bad');
|
|
171
|
+
} finally {
|
|
172
|
+
hold.dispose();
|
|
173
|
+
lock?.dispose();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async function uninstall(p: ExtensionView, btn: HTMLButtonElement): Promise<void> {
|
|
178
|
+
const ok = await ui.confirm({
|
|
179
|
+
title: S.uninstallTitle(p.label || p.name),
|
|
180
|
+
body: S.uninstallBody(p.name),
|
|
181
|
+
danger: true,
|
|
182
|
+
});
|
|
183
|
+
if (!ok || ctx.signal.aborted) return;
|
|
184
|
+
const lock = ui.disable(btn);
|
|
185
|
+
const hold = ui.toast(S.uninstalling);
|
|
186
|
+
try {
|
|
187
|
+
const out = await post<{ result?: string }>('/api/extensions/uninstall', { name: p.name }, { signal: ctx.signal });
|
|
188
|
+
if (ctx.signal.aborted) return;
|
|
189
|
+
setMsg(out?.result?.split('\n')[0] || S.uninstalled);
|
|
190
|
+
await load();
|
|
191
|
+
} catch (err) {
|
|
192
|
+
if (isAbort(err) || ctx.signal.aborted) return;
|
|
193
|
+
setMsg(S.uninstallFailed(errText(err)), true);
|
|
194
|
+
} finally {
|
|
195
|
+
hold.dispose();
|
|
196
|
+
lock.dispose();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** 装完问一句要不要顺手重启;答"否"也留在清单里标「待重启」。 */
|
|
201
|
+
async function install(target: { name: string; version?: string } | { path: string }, btn?: HTMLButtonElement): Promise<void> {
|
|
202
|
+
const lock = btn ? ui.disable(btn) : null;
|
|
203
|
+
const hold = ui.toast(S.installing);
|
|
204
|
+
let result = '';
|
|
205
|
+
try {
|
|
206
|
+
const out = await post<{ result?: string }>('/api/extensions/install', target, { signal: ctx.signal });
|
|
207
|
+
if (ctx.signal.aborted) return;
|
|
208
|
+
result = out?.result ?? S.installed;
|
|
209
|
+
setMsg(result.split('\n')[0]);
|
|
210
|
+
await load();
|
|
211
|
+
} catch (err) {
|
|
212
|
+
if (isAbort(err) || ctx.signal.aborted) return;
|
|
213
|
+
setMsg(S.installFailed(errText(err)), true);
|
|
214
|
+
return;
|
|
215
|
+
} finally {
|
|
216
|
+
hold.dispose();
|
|
217
|
+
lock?.dispose();
|
|
218
|
+
}
|
|
219
|
+
if (!canRestart) return;
|
|
220
|
+
const go = await ui.confirm({
|
|
221
|
+
title: S.installedRestartTitle,
|
|
222
|
+
body: result + '\n\n' + (supervised ? S.installedRestartNote : S.installedNoLoopNote),
|
|
223
|
+
danger: !supervised,
|
|
224
|
+
});
|
|
225
|
+
if (!go || ctx.signal.aborted) return;
|
|
226
|
+
await restartProcess(undefined, true);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function extensionCard(p: ExtensionView): HTMLElement {
|
|
230
|
+
const en = `${p.name}@${p.version ?? '?'}${p.worldId && p.kind ? ` · ${KIND_NOUN[p.kind]} ${p.worldId}` : ''}`;
|
|
231
|
+
const card = ui.sheet({ title: p.label || p.name, en });
|
|
232
|
+
card.el.classList.add('iocard');
|
|
233
|
+
if (p.state !== 'loaded') card.el.classList.add('iocard-inactive');
|
|
234
|
+
const bar = ui.rowbar();
|
|
235
|
+
bar.append(ui.pill(STATE_LABEL[p.state], p.state === 'loaded' ? 'on' : 'off'));
|
|
236
|
+
if (p.kind) bar.appendChild(ui.pill(KIND_LABEL[p.kind]));
|
|
237
|
+
if (p.api !== undefined) bar.appendChild(ui.chip(`v${p.api}`));
|
|
238
|
+
if (p.console === 'served') bar.appendChild(ui.pill(S.panelLoaded, 'on'));
|
|
239
|
+
card.body.appendChild(bar);
|
|
240
|
+
if (p.description) card.body.appendChild(ui.msgline(p.description));
|
|
241
|
+
if (p.reason) card.body.appendChild(ui.msgline(p.reason, true));
|
|
242
|
+
if (p.state === 'idle') card.body.appendChild(ui.msgline(S.noteIdle));
|
|
243
|
+
if (p.console === 'missing') card.body.appendChild(ui.msgline(S.noteConsoleMissing, true));
|
|
244
|
+
if (p.state !== 'removed') {
|
|
245
|
+
const actions = ui.actions();
|
|
246
|
+
actions.appendChild(ui.button(S.uninstall, {
|
|
247
|
+
size: 'sm',
|
|
248
|
+
variant: 'danger',
|
|
249
|
+
onClick: (ev) => void uninstall(p, ev.currentTarget as HTMLButtonElement),
|
|
250
|
+
}));
|
|
251
|
+
card.body.appendChild(actions);
|
|
252
|
+
}
|
|
253
|
+
return card.el;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function renderInstalled(extensions: readonly ExtensionView[], dir: string): void {
|
|
257
|
+
sumBar.replaceChildren();
|
|
258
|
+
installedGroups.replaceChildren();
|
|
259
|
+
const loaded = extensions.filter((p) => p.state === 'loaded').length;
|
|
260
|
+
const pending = extensions.filter((p) => p.state === 'pending-restart' || p.state === 'removed').length;
|
|
261
|
+
const failed = extensions.filter((p) => p.state === 'failed').length;
|
|
262
|
+
sumBar.appendChild(ui.pill(S.sumLoaded(loaded), 'on'));
|
|
263
|
+
if (pending > 0) sumBar.appendChild(ui.pill(S.sumPending(pending), 'off'));
|
|
264
|
+
if (failed > 0) sumBar.appendChild(ui.pill(S.sumFailed(failed), 'off'));
|
|
265
|
+
sumBar.appendChild(ui.chip(dir));
|
|
266
|
+
sumBar.append(ui.h('span', 'grow'), refreshBtn);
|
|
267
|
+
if (canRestart) sumBar.appendChild(restartBtn);
|
|
268
|
+
if (extensions.length === 0) {
|
|
269
|
+
installedGroups.appendChild(ui.placeholder(S.noExtensions));
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
for (const g of GROUPS) {
|
|
273
|
+
const mine = extensions.filter((p) => (p.kind ?? null) === g.kind);
|
|
274
|
+
if (mine.length === 0) continue;
|
|
275
|
+
const grid = ui.h('div', 'iogrid');
|
|
276
|
+
for (const p of mine) grid.appendChild(extensionCard(p));
|
|
277
|
+
installedGroups.append(ui.section(g.title, g.desc), grid);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
async function load(): Promise<void> {
|
|
282
|
+
try {
|
|
283
|
+
const data = await get<{ dir?: string; extensions?: ExtensionView[] }>('/api/extensions', { signal: ctx.signal });
|
|
284
|
+
if (ctx.signal.aborted) return;
|
|
285
|
+
renderInstalled(Array.isArray(data?.extensions) ? data.extensions : [], data?.dir ?? '');
|
|
286
|
+
} catch (err) {
|
|
287
|
+
if (isAbort(err) || ctx.signal.aborted) return;
|
|
288
|
+
installedGroups.replaceChildren(ui.placeholder(S.listLoadFailed(errText(err))));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// -------------------------------------------------------------------------
|
|
293
|
+
// 搜索 npm
|
|
294
|
+
// -------------------------------------------------------------------------
|
|
295
|
+
|
|
296
|
+
const searchSheet = ui.sheet({
|
|
297
|
+
title: S.searchTitle,
|
|
298
|
+
en: 'npm registry',
|
|
299
|
+
desc: S.searchDesc,
|
|
300
|
+
});
|
|
301
|
+
let searchKind: ExtensionKindView = 'world';
|
|
302
|
+
const searchBar = ui.rowbar();
|
|
303
|
+
const kindSeg = ui.segmented(
|
|
304
|
+
[
|
|
305
|
+
{ value: 'world', label: KIND_LABEL.world },
|
|
306
|
+
{ value: 'provider', label: KIND_LABEL.provider },
|
|
307
|
+
{ value: 'bot', label: KIND_LABEL.bot },
|
|
308
|
+
],
|
|
309
|
+
{
|
|
310
|
+
size: 'sm',
|
|
311
|
+
value: searchKind,
|
|
312
|
+
onSelect: (v) => {
|
|
313
|
+
searchKind = v as ExtensionKindView;
|
|
314
|
+
paintKeyword();
|
|
315
|
+
// 换了类就换了关键字,上一类的命中留在屏幕上会被当成这一类的结果
|
|
316
|
+
resultGrid.replaceChildren();
|
|
317
|
+
searchMsg.textContent = '';
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
);
|
|
321
|
+
const searchInput = ui.input({ type: 'search', placeholder: S.searchPlaceholder });
|
|
322
|
+
const searchBtn = ui.button(S.search, { size: 'sm', variant: 'primary', onClick: () => void search() });
|
|
323
|
+
searchInput.addEventListener('keydown', (ev) => { if (ev.key === 'Enter') void search(); }, { signal: ctx.signal });
|
|
324
|
+
searchBar.append(kindSeg.el, searchInput, searchBtn);
|
|
325
|
+
const keywordLine = ui.msgline();
|
|
326
|
+
function paintKeyword(): void {
|
|
327
|
+
keywordLine.textContent = S.searchKeywordNote(KIND_KEYWORD[searchKind]);
|
|
328
|
+
}
|
|
329
|
+
paintKeyword();
|
|
330
|
+
const searchMsg = ui.msgline();
|
|
331
|
+
const resultGrid = ui.h('div', 'iogrid');
|
|
332
|
+
searchSheet.body.append(searchBar, keywordLine, searchMsg, resultGrid);
|
|
333
|
+
|
|
334
|
+
function openLink(href: string): void {
|
|
335
|
+
view?.open(href, '_blank', 'noopener');
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function hitCard(h: SearchHitView): HTMLElement {
|
|
339
|
+
const card = ui.sheet({ title: h.name, en: S.hitMeta(h.version, h.downloads, h.publisher) });
|
|
340
|
+
card.el.classList.add('iocard');
|
|
341
|
+
if (h.kind) {
|
|
342
|
+
const bar = ui.rowbar();
|
|
343
|
+
bar.appendChild(ui.pill(KIND_LABEL[h.kind]));
|
|
344
|
+
card.body.appendChild(bar);
|
|
345
|
+
}
|
|
346
|
+
if (h.description) card.body.appendChild(ui.msgline(h.description));
|
|
347
|
+
const actions = ui.actions();
|
|
348
|
+
const links: Array<[string, string | undefined]> = [['npm', h.links.npm], [S.linkRepo, h.links.repository], [S.linkHome, h.links.homepage]];
|
|
349
|
+
for (const [label, href] of links) {
|
|
350
|
+
if (href) actions.appendChild(ui.button(label, { size: 'sm', onClick: () => openLink(href) }));
|
|
351
|
+
}
|
|
352
|
+
const installBtn = ui.button(h.installed ? S.alreadyInstalled : S.install, {
|
|
353
|
+
size: 'sm',
|
|
354
|
+
variant: 'primary',
|
|
355
|
+
onClick: (ev) => void install({ name: h.name, version: h.version }, ev.currentTarget as HTMLButtonElement),
|
|
356
|
+
});
|
|
357
|
+
installBtn.disabled = h.installed;
|
|
358
|
+
actions.appendChild(installBtn);
|
|
359
|
+
card.body.appendChild(actions);
|
|
360
|
+
return card.el;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
async function search(): Promise<void> {
|
|
364
|
+
const lock = ui.disable(searchBtn);
|
|
365
|
+
searchMsg.textContent = S.searching;
|
|
366
|
+
searchMsg.className = 'msgline';
|
|
367
|
+
try {
|
|
368
|
+
const q = encodeURIComponent(searchInput.value.trim());
|
|
369
|
+
const data = await get<{ hits?: SearchHitView[] }>(
|
|
370
|
+
`/api/extensions/search?q=${q}&kind=${searchKind}`,
|
|
371
|
+
{ signal: ctx.signal },
|
|
372
|
+
);
|
|
373
|
+
if (ctx.signal.aborted) return;
|
|
374
|
+
const hits = Array.isArray(data?.hits) ? data.hits : [];
|
|
375
|
+
resultGrid.replaceChildren();
|
|
376
|
+
searchMsg.textContent = hits.length === 0 ? S.noHits : S.hitCount(hits.length);
|
|
377
|
+
for (const h of hits) resultGrid.appendChild(hitCard(h));
|
|
378
|
+
} catch (err) {
|
|
379
|
+
if (isAbort(err) || ctx.signal.aborted) return;
|
|
380
|
+
searchMsg.textContent = S.searchFailed(errText(err));
|
|
381
|
+
searchMsg.className = 'msgline bad';
|
|
382
|
+
} finally {
|
|
383
|
+
lock.dispose();
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// -------------------------------------------------------------------------
|
|
388
|
+
// 手动安装
|
|
389
|
+
// -------------------------------------------------------------------------
|
|
390
|
+
|
|
391
|
+
const manualSheet = ui.sheet({
|
|
392
|
+
title: S.manualTitle,
|
|
393
|
+
en: 'name@version · ./path',
|
|
394
|
+
desc: S.manualDesc,
|
|
395
|
+
});
|
|
396
|
+
const manualBar = ui.rowbar();
|
|
397
|
+
const manualInput = ui.input({ cls: 'mono', placeholder: S.manualPlaceholder });
|
|
398
|
+
const manualBtn = ui.button(S.install, {
|
|
399
|
+
size: 'sm',
|
|
400
|
+
variant: 'primary',
|
|
401
|
+
onClick: (ev) => {
|
|
402
|
+
const target = parseInstallInput(manualInput.value);
|
|
403
|
+
if (!target) { setMsg(S.manualEmpty, true); return; }
|
|
404
|
+
void install(target, ev.currentTarget as HTMLButtonElement);
|
|
405
|
+
},
|
|
406
|
+
});
|
|
407
|
+
manualBar.append(manualInput, manualBtn);
|
|
408
|
+
manualSheet.body.append(manualBar);
|
|
409
|
+
|
|
410
|
+
root.append(intro, installedSheet.el, installedGroups, searchSheet.el, manualSheet.el);
|
|
411
|
+
installedGroups.appendChild(ui.placeholder(S.loading));
|
|
412
|
+
void load();
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export const extensionsFeature: FrameworkFeature = {
|
|
416
|
+
route: 'extensions',
|
|
417
|
+
label: S.navLabel,
|
|
418
|
+
icon: 'download',
|
|
419
|
+
navGroup: S.navGroup,
|
|
420
|
+
needsAny: ['extensions'],
|
|
421
|
+
mount: mountExtensions,
|
|
422
|
+
};
|