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.
Files changed (311) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -0
  3. package/package.json +43 -0
  4. package/src/boot.ts +46 -0
  5. package/src/bot.ts +1342 -0
  6. package/src/config-file.ts +41 -0
  7. package/src/core/README.md +92 -0
  8. package/src/core/billing.ts +26 -0
  9. package/src/core/blobs.ts +106 -0
  10. package/src/core/bus.ts +311 -0
  11. package/src/core/config-schema.ts +201 -0
  12. package/src/core/config.ts +262 -0
  13. package/src/core/core.ts +699 -0
  14. package/src/core/cost.ts +244 -0
  15. package/src/core/event-store.ts +304 -0
  16. package/src/core/fork.ts +113 -0
  17. package/src/core/generation.ts +118 -0
  18. package/src/core/instance-lock.ts +215 -0
  19. package/src/core/ipc-logger.ts +105 -0
  20. package/src/core/language.ts +62 -0
  21. package/src/core/log-context.ts +38 -0
  22. package/src/core/loop.ts +1858 -0
  23. package/src/core/markers.ts +48 -0
  24. package/src/core/prefix.ts +121 -0
  25. package/src/core/run.ts +95 -0
  26. package/src/core/secrets.ts +18 -0
  27. package/src/core/session.ts +56 -0
  28. package/src/core/sessions.ts +261 -0
  29. package/src/core/state.ts +104 -0
  30. package/src/core/template.ts +72 -0
  31. package/src/core/timers.ts +129 -0
  32. package/src/core/tool-log.ts +135 -0
  33. package/src/core/transcript.ts +92 -0
  34. package/src/core/truncate.ts +121 -0
  35. package/src/core/types.ts +1140 -0
  36. package/src/core/usage-log.ts +79 -0
  37. package/src/core/util.ts +386 -0
  38. package/src/deploy-listing.ts +160 -0
  39. package/src/deploy.ts +162 -0
  40. package/src/extensions/README.md +72 -0
  41. package/src/extensions/dry-mount.ts +390 -0
  42. package/src/extensions/manifest.ts +153 -0
  43. package/src/extensions/runtime.ts +42 -0
  44. package/src/extensions.ts +519 -0
  45. package/src/launcher.ts +285 -0
  46. package/src/paths.ts +155 -0
  47. package/src/protocol/open-responses/LICENSE +201 -0
  48. package/src/protocol/open-responses/README.md +14 -0
  49. package/src/protocol/open-responses/context-helpers.ts +27 -0
  50. package/src/protocol/open-responses/context-log.ts +59 -0
  51. package/src/protocol/open-responses/context.ts +89 -0
  52. package/src/protocol/open-responses/generated.ts +115 -0
  53. package/src/protocol/open-responses/index.ts +33 -0
  54. package/src/protocol/open-responses/openapi.json +4230 -0
  55. package/src/protocol/open-responses/stream.ts +146 -0
  56. package/src/protocol/open-responses/tokens.ts +31 -0
  57. package/src/providers/README.md +86 -0
  58. package/src/providers/base.ts +111 -0
  59. package/src/providers/configuration.ts +97 -0
  60. package/src/providers/console/config.ts +21 -0
  61. package/src/providers/console/settings.ts +443 -0
  62. package/src/providers/console/strings.ts +74 -0
  63. package/src/providers/console/types.ts +11 -0
  64. package/src/providers/llamacpp/archive.ts +148 -0
  65. package/src/providers/llamacpp/catalog.ts +247 -0
  66. package/src/providers/llamacpp/config.ts +36 -0
  67. package/src/providers/llamacpp/console/client.ts +6 -0
  68. package/src/providers/llamacpp/console/models-panel.ts +120 -0
  69. package/src/providers/llamacpp/console/runtime-panel.ts +173 -0
  70. package/src/providers/llamacpp/console/server.ts +153 -0
  71. package/src/providers/llamacpp/index.ts +95 -0
  72. package/src/providers/llamacpp/native.ts +51 -0
  73. package/src/providers/llamacpp/options.ts +117 -0
  74. package/src/providers/llamacpp/runtime-store.ts +139 -0
  75. package/src/providers/llamacpp/runtime.ts +214 -0
  76. package/src/providers/llamacpp/server.ts +286 -0
  77. package/src/providers/llamacpp/strings.ts +230 -0
  78. package/src/providers/openai-responses-compat/config.ts +20 -0
  79. package/src/providers/openai-responses-compat/index.ts +89 -0
  80. package/src/providers/openai-responses-compat/native.ts +127 -0
  81. package/src/providers/openai-responses-compat/strings.ts +19 -0
  82. package/src/providers/pricebook.ts +75 -0
  83. package/src/providers/registry.ts +137 -0
  84. package/src/providers/strings.ts +71 -0
  85. package/src/providers/transport/chat.ts +156 -0
  86. package/src/providers/transport/errors.ts +48 -0
  87. package/src/providers/transport/history.ts +68 -0
  88. package/src/providers/transport/native-input.ts +83 -0
  89. package/src/providers/transport/native-types.ts +13 -0
  90. package/src/providers/transport/response-assembly.ts +191 -0
  91. package/src/providers/transport/response-http.ts +196 -0
  92. package/src/providers/transport/response-meters.ts +27 -0
  93. package/src/providers/transport/responses-input.ts +56 -0
  94. package/src/web/README.md +84 -0
  95. package/src/web/client/console-pages/builtins/llm-settings/panel.ts +625 -0
  96. package/src/web/client/console-pages/builtins/llm-settings/pricing-panel.ts +168 -0
  97. package/src/web/client/console-pages/builtins/llm-settings/strings.ts +213 -0
  98. package/src/web/client/console-pages/builtins.ts +10 -0
  99. package/src/web/client/console-pages/context.ts +135 -0
  100. package/src/web/client/console-pages/host.ts +633 -0
  101. package/src/web/client/console-pages/loader.ts +132 -0
  102. package/src/web/client/console-pages/strings.ts +90 -0
  103. package/src/web/client/console-pages/tools/strings.ts +49 -0
  104. package/src/web/client/console-pages/tools/view.ts +215 -0
  105. package/src/web/client/core/api.ts +200 -0
  106. package/src/web/client/core/language.ts +56 -0
  107. package/src/web/client/core/lifecycle.ts +132 -0
  108. package/src/web/client/core/router.ts +199 -0
  109. package/src/web/client/core/stream.ts +157 -0
  110. package/src/web/client/core/websocket.ts +82 -0
  111. package/src/web/client/features/appearance/index.ts +333 -0
  112. package/src/web/client/features/appearance/strings.ts +87 -0
  113. package/src/web/client/features/config/index.ts +11 -0
  114. package/src/web/client/features/config/strings.ts +41 -0
  115. package/src/web/client/features/config/view.ts +428 -0
  116. package/src/web/client/features/core/events.ts +197 -0
  117. package/src/web/client/features/core/index.ts +254 -0
  118. package/src/web/client/features/core/run.ts +56 -0
  119. package/src/web/client/features/core/runlog.ts +214 -0
  120. package/src/web/client/features/core/sessions.ts +53 -0
  121. package/src/web/client/features/core/strings.ts +157 -0
  122. package/src/web/client/features/extensions/index.ts +422 -0
  123. package/src/web/client/features/extensions/strings.ts +164 -0
  124. package/src/web/client/features/feature.ts +93 -0
  125. package/src/web/client/features/live/context.ts +280 -0
  126. package/src/web/client/features/live/fork.ts +156 -0
  127. package/src/web/client/features/live/index.ts +392 -0
  128. package/src/web/client/features/live/onboarding.ts +113 -0
  129. package/src/web/client/features/live/protocol.ts +122 -0
  130. package/src/web/client/features/live/sessions.ts +71 -0
  131. package/src/web/client/features/live/status.ts +68 -0
  132. package/src/web/client/features/live/strings.ts +252 -0
  133. package/src/web/client/features/live/timeline.ts +590 -0
  134. package/src/web/client/features/prompts/editor.ts +292 -0
  135. package/src/web/client/features/prompts/index.ts +346 -0
  136. package/src/web/client/features/prompts/strings.ts +136 -0
  137. package/src/web/client/features/prompts/view.ts +256 -0
  138. package/src/web/client/features/providers/index.ts +100 -0
  139. package/src/web/client/features/providers/strings.ts +23 -0
  140. package/src/web/client/features/settings/general.ts +28 -0
  141. package/src/web/client/features/settings/index.ts +82 -0
  142. package/src/web/client/features/settings/strings.ts +33 -0
  143. package/src/web/client/features/storage/index.ts +1 -0
  144. package/src/web/client/features/storage/strings.ts +45 -0
  145. package/src/web/client/features/storage/view.ts +154 -0
  146. package/src/web/client/features/usage/chart.ts +486 -0
  147. package/src/web/client/features/usage/index.ts +407 -0
  148. package/src/web/client/features/usage/labels.ts +46 -0
  149. package/src/web/client/features/usage/range.ts +36 -0
  150. package/src/web/client/features/usage/state.ts +37 -0
  151. package/src/web/client/features/usage/strings.ts +191 -0
  152. package/src/web/client/features/usage/tooltip.ts +86 -0
  153. package/src/web/client/features/usage/types.ts +96 -0
  154. package/src/web/client/features/worlds/index.ts +424 -0
  155. package/src/web/client/features/worlds/strings.ts +121 -0
  156. package/src/web/client/main.ts +273 -0
  157. package/src/web/client/shell/avatar.ts +233 -0
  158. package/src/web/client/shell/index.ts +549 -0
  159. package/src/web/client/shell/strings.ts +89 -0
  160. package/src/web/client/theme/handoff.ts +43 -0
  161. package/src/web/client/theme/palette.ts +109 -0
  162. package/src/web/client/theme/registry.ts +130 -0
  163. package/src/web/client/theme/storage.ts +72 -0
  164. package/src/web/client/theme/strings.ts +123 -0
  165. package/src/web/client/theme/studio.ts +366 -0
  166. package/src/web/client/ui/actions.ts +109 -0
  167. package/src/web/client/ui/data.ts +185 -0
  168. package/src/web/client/ui/dom.ts +23 -0
  169. package/src/web/client/ui/fields.ts +191 -0
  170. package/src/web/client/ui/format.ts +75 -0
  171. package/src/web/client/ui/icons.ts +183 -0
  172. package/src/web/client/ui/images.ts +91 -0
  173. package/src/web/client/ui/index.ts +89 -0
  174. package/src/web/client/ui/lamp.ts +125 -0
  175. package/src/web/client/ui/log.ts +98 -0
  176. package/src/web/client/ui/overlay.ts +184 -0
  177. package/src/web/client/ui/page.ts +8 -0
  178. package/src/web/client/ui/prompt-input.tsx +311 -0
  179. package/src/web/client/ui/sheet.ts +131 -0
  180. package/src/web/client/ui/strings.ts +71 -0
  181. package/src/web/console-pages.ts +367 -0
  182. package/src/web/files.ts +107 -0
  183. package/src/web/path-picker.ts +296 -0
  184. package/src/web/public/index.html +17 -0
  185. package/src/web/public/styles.css +1715 -0
  186. package/src/web/server.ts +1883 -0
  187. package/src/web/shared/client-panel.ts +603 -0
  188. package/src/web/shared/console-protocol.ts +560 -0
  189. package/src/web/shared/css.d.ts +1 -0
  190. package/src/web/shared/path-picker.ts +23 -0
  191. package/src/web/shared/theme.ts +256 -0
  192. package/src/web/theme-store.ts +37 -0
  193. package/src/world.ts +449 -0
  194. package/src/worlds/bilibili/ENV_PROMPT.md +5 -0
  195. package/src/worlds/bilibili/README.md +176 -0
  196. package/src/worlds/bilibili/audience-admission.ts +995 -0
  197. package/src/worlds/bilibili/client.ts +528 -0
  198. package/src/worlds/bilibili/coalescing-buffer.ts +125 -0
  199. package/src/worlds/bilibili/config.ts +185 -0
  200. package/src/worlds/bilibili/console/client.ts +202 -0
  201. package/src/worlds/bilibili/definition.ts +35 -0
  202. package/src/worlds/bilibili/gift-frame.ts +131 -0
  203. package/src/worlds/bilibili/normalize.ts +452 -0
  204. package/src/worlds/bilibili/overlay/announcement.ts +76 -0
  205. package/src/worlds/bilibili/overlay/assets.ts +82 -0
  206. package/src/worlds/bilibili/overlay/model.ts +494 -0
  207. package/src/worlds/bilibili/overlay/project.ts +202 -0
  208. package/src/worlds/bilibili/overlay/server.ts +286 -0
  209. package/src/worlds/bilibili/overlay/types.ts +217 -0
  210. package/src/worlds/bilibili/overlay/web/app.js +690 -0
  211. package/src/worlds/bilibili/overlay/web/editor.css +297 -0
  212. package/src/worlds/bilibili/overlay/web/editor.html +102 -0
  213. package/src/worlds/bilibili/overlay/web/editor.js +2116 -0
  214. package/src/worlds/bilibili/overlay/web/overlay.html +13 -0
  215. package/src/worlds/bilibili/overlay/web/styles.css +258 -0
  216. package/src/worlds/bilibili/protobuf.ts +123 -0
  217. package/src/worlds/bilibili/wire.ts +94 -0
  218. package/src/worlds/bilibili/world.ts +1389 -0
  219. package/src/worlds/console-fixture/ENV_PROMPT.md +1 -0
  220. package/src/worlds/console-fixture/console/client.ts +72 -0
  221. package/src/worlds/console-fixture/world.ts +73 -0
  222. package/src/worlds/index.ts +15 -0
  223. package/src/worlds/minecraft/ENV_PROMPT.md +32 -0
  224. package/src/worlds/minecraft/ENV_PROMPT_CAMERA.md +2 -0
  225. package/src/worlds/minecraft/LICENSE-mineflayer-pathfinder.txt +21 -0
  226. package/src/worlds/minecraft/README.md +917 -0
  227. package/src/worlds/minecraft/blueprint-plan.ts +915 -0
  228. package/src/worlds/minecraft/blueprint-registry.ts +566 -0
  229. package/src/worlds/minecraft/blueprint-repair.ts +236 -0
  230. package/src/worlds/minecraft/blueprint-resource.ts +272 -0
  231. package/src/worlds/minecraft/blueprint.ts +492 -0
  232. package/src/worlds/minecraft/body-lease.ts +340 -0
  233. package/src/worlds/minecraft/bridge.ts +749 -0
  234. package/src/worlds/minecraft/check.ts +651 -0
  235. package/src/worlds/minecraft/chests.ts +292 -0
  236. package/src/worlds/minecraft/client-launch.ts +272 -0
  237. package/src/worlds/minecraft/client-options.ts +85 -0
  238. package/src/worlds/minecraft/client-skins.ts +164 -0
  239. package/src/worlds/minecraft/client-window.ps1 +91 -0
  240. package/src/worlds/minecraft/client.ts +423 -0
  241. package/src/worlds/minecraft/combat-context.ts +109 -0
  242. package/src/worlds/minecraft/combat.ts +1552 -0
  243. package/src/worlds/minecraft/config.ts +499 -0
  244. package/src/worlds/minecraft/console/access.ts +218 -0
  245. package/src/worlds/minecraft/console/client.ts +244 -0
  246. package/src/worlds/minecraft/console/log.ts +110 -0
  247. package/src/worlds/minecraft/console/mount.ts +420 -0
  248. package/src/worlds/minecraft/console/skin.ts +257 -0
  249. package/src/worlds/minecraft/console/style.css +154 -0
  250. package/src/worlds/minecraft/console/world.ts +449 -0
  251. package/src/worlds/minecraft/deaths.ts +135 -0
  252. package/src/worlds/minecraft/definition.ts +18 -0
  253. package/src/worlds/minecraft/engine-child.ts +274 -0
  254. package/src/worlds/minecraft/engine-ipc.ts +98 -0
  255. package/src/worlds/minecraft/entity-facts.ts +132 -0
  256. package/src/worlds/minecraft/escape.ts +407 -0
  257. package/src/worlds/minecraft/executor.ts +14494 -0
  258. package/src/worlds/minecraft/explored.ts +156 -0
  259. package/src/worlds/minecraft/geometry.ts +205 -0
  260. package/src/worlds/minecraft/goal-plan.ts +647 -0
  261. package/src/worlds/minecraft/item-break.ts +126 -0
  262. package/src/worlds/minecraft/item-facts.ts +146 -0
  263. package/src/worlds/minecraft/item-pick.ts +67 -0
  264. package/src/worlds/minecraft/level-dat.ts +176 -0
  265. package/src/worlds/minecraft/log.ts +132 -0
  266. package/src/worlds/minecraft/mineflayer-fixes.ts +1180 -0
  267. package/src/worlds/minecraft/names.ts +377 -0
  268. package/src/worlds/minecraft/pathfinder-lib.d.ts +13 -0
  269. package/src/worlds/minecraft/pathfinder-perf.ts +796 -0
  270. package/src/worlds/minecraft/piglin.ts +49 -0
  271. package/src/worlds/minecraft/policy.ts +547 -0
  272. package/src/worlds/minecraft/precheck.ts +655 -0
  273. package/src/worlds/minecraft/proxy.ts +445 -0
  274. package/src/worlds/minecraft/ranged.ts +635 -0
  275. package/src/worlds/minecraft/readouts.ts +102 -0
  276. package/src/worlds/minecraft/round.ts +26 -0
  277. package/src/worlds/minecraft/search-observation.ts +92 -0
  278. package/src/worlds/minecraft/server-config.ts +467 -0
  279. package/src/worlds/minecraft/server.ts +658 -0
  280. package/src/worlds/minecraft/show.ts +84 -0
  281. package/src/worlds/minecraft/skills.ts +1763 -0
  282. package/src/worlds/minecraft/terrain.ts +1735 -0
  283. package/src/worlds/minecraft/window.ts +96 -0
  284. package/src/worlds/minecraft/works.ts +179 -0
  285. package/src/worlds/minecraft/world.ts +6438 -0
  286. package/src/worlds/qq/ENV_PROMPT.md +5 -0
  287. package/src/worlds/qq/config.ts +108 -0
  288. package/src/worlds/qq/console/client.ts +126 -0
  289. package/src/worlds/qq/console/events.ts +155 -0
  290. package/src/worlds/qq/console/gate.ts +232 -0
  291. package/src/worlds/qq/console/roster.ts +203 -0
  292. package/src/worlds/qq/console/style.css +65 -0
  293. package/src/worlds/qq/conversation.ts +28 -0
  294. package/src/worlds/qq/definition.ts +62 -0
  295. package/src/worlds/qq/driver.ts +375 -0
  296. package/src/worlds/qq/history-tools.ts +209 -0
  297. package/src/worlds/qq/normalize.ts +323 -0
  298. package/src/worlds/qq/qface-map.ts +282 -0
  299. package/src/worlds/qq/vision-prompt.ts +27 -0
  300. package/src/worlds/qq/vision.ts +642 -0
  301. package/src/worlds/qq/vlm.ts +142 -0
  302. package/src/worlds/qq/world.ts +1503 -0
  303. package/src/worlds/terminal/ENV_PROMPT.md +11 -0
  304. package/src/worlds/terminal/config.ts +9 -0
  305. package/src/worlds/terminal/definition.ts +14 -0
  306. package/src/worlds/terminal/world.ts +700 -0
  307. package/src/worlds/websearch/ENV_PROMPT.md +1 -0
  308. package/src/worlds/websearch/brave-client.ts +261 -0
  309. package/src/worlds/websearch/config.ts +75 -0
  310. package/src/worlds/websearch/definition.ts +20 -0
  311. 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
+ };