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,603 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 控制台页浏览器扩展与控制台内核的契约,仅浏览器端 import,服务端不 import。此文件使用 DOM 类型,根 tsconfig 从初始文件表排除,由 tsconfig.web.json 检查。
|
|
3
|
+
* 扩展通过 ConsolePanelContext 获取调用、根节点、取消、定时器、动画帧、存储、离开拦截及 UI。
|
|
4
|
+
* 卸载依次 abort、dispose、清空 root;离开面板后轮询、RAF、observer、listener、挂起 fetch 与音频播放均停止。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ConsoleBadge } from './console-protocol.ts';
|
|
8
|
+
import type { ConfigValue } from '../../core/config-schema.ts';
|
|
9
|
+
import type { Language } from '../../core/language.ts';
|
|
10
|
+
import type { PathPickerOptions } from './path-picker.ts';
|
|
11
|
+
|
|
12
|
+
/** 可释放资源。`ResizeObserver` 这类原生对象用 `toDisposable` 包一下即可。 */
|
|
13
|
+
export interface Disposable {
|
|
14
|
+
dispose(): void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** 把任意清理函数包成 `Disposable`。 */
|
|
18
|
+
export function toDisposable(cleanup: () => void): Disposable {
|
|
19
|
+
let done = false;
|
|
20
|
+
return {
|
|
21
|
+
dispose() {
|
|
22
|
+
if (done) return;
|
|
23
|
+
done = true;
|
|
24
|
+
cleanup();
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
// Panel Context
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 面板运行时上下文。**这是扩展与外界的唯一接口。**
|
|
35
|
+
*
|
|
36
|
+
* 身份、DOM 根、生命周期与自有数据面是稳定基线;通用框架能力可以增量扩充。
|
|
37
|
+
* 接口不接受任何具体页的专用成员。
|
|
38
|
+
*/
|
|
39
|
+
export interface ConsolePanelContext {
|
|
40
|
+
/** `world:chat` / `persona:demo` */
|
|
41
|
+
readonly pageId: string;
|
|
42
|
+
/** 本页内的局部 id,如 `gate` */
|
|
43
|
+
readonly panelId: string;
|
|
44
|
+
/**
|
|
45
|
+
* 这个浏览器的界面语言(`zh` / `en`):部署默认,或操作员在设置里改过的那种。扩展自己
|
|
46
|
+
* 决定要不要带第二套文案;没有这一语言的就给中文,宿主不翻译、不告警。
|
|
47
|
+
*/
|
|
48
|
+
readonly language: Language;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 扩展的 DOM 根。**扩展只往这里面写**,不碰 `document.body`。
|
|
52
|
+
* unmount 时由 host 清空。
|
|
53
|
+
*/
|
|
54
|
+
readonly root: HTMLElement;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* unmount 时 abort。传给 `addEventListener` 与 `fetch` 即可自动清理——
|
|
58
|
+
* 这两个 API 原生认识 `AbortSignal`,所以 context 不再重复提供包装。
|
|
59
|
+
*/
|
|
60
|
+
readonly signal: AbortSignal;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 调本面板的数据面方法(`ConsolePageContribution.invoke`)。
|
|
64
|
+
* 走 POST,请求随 `signal` 取消;非 2xx 抛 `ConsoleInvokeError`。
|
|
65
|
+
*/
|
|
66
|
+
invoke<T = unknown>(method: string, args?: unknown[]): Promise<T>;
|
|
67
|
+
|
|
68
|
+
/** 同上,但按二进制取回(音频试听、图片这类)。 */
|
|
69
|
+
invokeBinary(method: string, args?: unknown[]): Promise<Blob>;
|
|
70
|
+
|
|
71
|
+
/** 面板卸载时发送小型清理 POST;该请求不随面板的 abort signal 取消。 */
|
|
72
|
+
notifyOnUnmount?(method: string, args?: unknown[]): void;
|
|
73
|
+
|
|
74
|
+
/** 打开服务端主机的本机文件/目录选择器。取消返回 null。 */
|
|
75
|
+
pickPath(options: PathPickerOptions): Promise<string | null>;
|
|
76
|
+
|
|
77
|
+
/** 按配置组写回已声明字段;校验、热更新与持久化均走框架配置面。 */
|
|
78
|
+
setConfig(groupId: string, values: Record<string, ConfigValue>): Promise<string>;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 本面板的推送通道对应服务端 ConsolePageContribution.stream。连接中断后退避重连,unmount 同时终止连接与重连;已有推送的数据不另行轮询。
|
|
82
|
+
*/
|
|
83
|
+
stream(handlers: ConsoleStreamHandlers): ConsoleStreamHandle;
|
|
84
|
+
|
|
85
|
+
/** 轮询。返回的 `Disposable` 已登记,unmount 自动停;提前停就手动 `dispose()`。 */
|
|
86
|
+
interval(fn: () => void, ms: number): Disposable;
|
|
87
|
+
|
|
88
|
+
/** 一次性延时,触发后移除登记;unmount 自动取消。 */
|
|
89
|
+
timeout(fn: () => void, ms: number): Disposable;
|
|
90
|
+
|
|
91
|
+
/** RAF 循环。`fn` 返回 `false` 即自行结束;unmount 自动停。 */
|
|
92
|
+
frame(fn: (dtMs: number) => void | false): Disposable;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 登记一个资源,unmount 时自动 `dispose()`。
|
|
96
|
+
* `AudioContext`、`ObjectURL`、`ResizeObserver`、子进程连接都走这里。
|
|
97
|
+
*/
|
|
98
|
+
own<T extends Disposable>(d: T): T;
|
|
99
|
+
|
|
100
|
+
/** 面板局部存储,按 page:panel 隔离键。浏览器存储不可用时退回内存,不抛错。 */
|
|
101
|
+
readonly memo: ConsoleMemo;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 离开拦截。`fn` 返回一句话 = 拦下并让用户确认;返回 null = 放行。
|
|
105
|
+
* 编辑器类面板(有未保存改动)用它。unmount 时自动解除。
|
|
106
|
+
*/
|
|
107
|
+
guardLeave(fn: () => string | null): Disposable;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 宿主面板挂载本面板时给的作用域(如选中的端点名)。自己占一个页签时为空对象。
|
|
111
|
+
*/
|
|
112
|
+
readonly scope: Readonly<Record<string, string>>;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 把本页声明到该插槽的面板按声明顺序挂进 `host`,`scope` 传给它们的 `ctx.scope`。
|
|
116
|
+
* 返回句柄的 `dispose()` 结束这些面板;`host` 的内容由调用方清理。
|
|
117
|
+
* 插槽里没有面板时挂载为空。
|
|
118
|
+
*/
|
|
119
|
+
mountSlot(
|
|
120
|
+
slot: string,
|
|
121
|
+
host: HTMLElement,
|
|
122
|
+
scope?: Readonly<Record<string, string>>,
|
|
123
|
+
): Promise<Disposable>;
|
|
124
|
+
|
|
125
|
+
/** UI 原语。 */
|
|
126
|
+
readonly ui: ConsoleUi;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 重新读取 manifest 并更新 host 渲染的 badges、availability 与 prefixDrifted。保持面板挂载和表单状态;面板自身的数据由面板另行刷新。
|
|
130
|
+
*/
|
|
131
|
+
refresh(): Promise<void>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** invoke 失败,携带 HTTP 状态与服务端按界面语言提供的消息。 */
|
|
135
|
+
export class ConsoleInvokeError extends Error {
|
|
136
|
+
readonly status: number;
|
|
137
|
+
constructor(message: string, status: number) {
|
|
138
|
+
super(message);
|
|
139
|
+
this.name = 'ConsoleInvokeError';
|
|
140
|
+
this.status = status;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface ConsoleStreamHandlers {
|
|
145
|
+
/** 收到一帧。 */
|
|
146
|
+
message(text: string): void;
|
|
147
|
+
/** 连上了(含每次重连成功)。用来重置面板里的"连接中"状态。 */
|
|
148
|
+
open?(): void;
|
|
149
|
+
/** 断开了。`willRetry` 为 false 表示不再重连(面板已卸载)。 */
|
|
150
|
+
close?(willRetry: boolean): void;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface ConsoleStreamHandle extends Disposable {
|
|
154
|
+
/** 往回推一帧。连接未就绪时排队,连上后按序发出。 */
|
|
155
|
+
send(text: string): void;
|
|
156
|
+
readonly open: boolean;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface ConsoleMemo {
|
|
160
|
+
get<T>(key: string, fallback: T): T;
|
|
161
|
+
set(key: string, value: unknown): void;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// ---------------------------------------------------------------------------
|
|
165
|
+
// UI 原语
|
|
166
|
+
// ---------------------------------------------------------------------------
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 控制台 UI 原语仅包含跨页通用的能力,领域波形、预览和播放器由各扩展实现。原语返回真实 DOM 元素,复用统一样式,不接受 HTML 字符串或 JSON UI 描述。
|
|
170
|
+
* ctx.ui 绑定面板 signal:abort 时关闭 toast、confirm 与 drawer,待决 confirm resolve 为 false 以允许调用方清理;abort 后 confirm 立即返回 false,toast/drawer 不显示。
|
|
171
|
+
*/
|
|
172
|
+
export interface ConsoleUi {
|
|
173
|
+
/** `h('div', 'sheet', '文本')` */
|
|
174
|
+
h<K extends keyof HTMLElementTagNameMap>(
|
|
175
|
+
tag: K,
|
|
176
|
+
cls?: string | null,
|
|
177
|
+
text?: string | null,
|
|
178
|
+
): HTMLElementTagNameMap[K];
|
|
179
|
+
|
|
180
|
+
/** HTML 转义。拼 innerHTML 的场合用。 */
|
|
181
|
+
esc(s: unknown): string;
|
|
182
|
+
|
|
183
|
+
/** 档案卡。 */
|
|
184
|
+
sheet(opts: ConsoleSheetOptions): ConsoleSheet;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* 可折叠档案卡(`details.sheet.tabbed.fold`)。展开状态按 `id` 记在 `ctx.memo` 里,
|
|
188
|
+
* 跨导航重建 DOM 后恢复。`note` 是折叠状态下唯一可见的字段。
|
|
189
|
+
*/
|
|
190
|
+
foldSheet(id: string, opts: ConsoleSheetOptions & { defaultOpen?: boolean }): ConsoleSheet;
|
|
191
|
+
|
|
192
|
+
/** 按钮与状态行。 */
|
|
193
|
+
rowbar(): HTMLDivElement;
|
|
194
|
+
|
|
195
|
+
/** 卡片分区标题。 */
|
|
196
|
+
section(title: string, description?: string): HTMLDivElement;
|
|
197
|
+
|
|
198
|
+
/** 卡片动作行。 */
|
|
199
|
+
actions(): HTMLDivElement;
|
|
200
|
+
|
|
201
|
+
/** 按钮(`.btn` / `.btn.sm` / `.btn.primary` / `.btn.danger`)。 */
|
|
202
|
+
button(label: string, opts?: {
|
|
203
|
+
variant?: 'plain' | 'primary' | 'danger';
|
|
204
|
+
size?: 'sm' | 'md';
|
|
205
|
+
onClick?: (ev: MouseEvent) => void;
|
|
206
|
+
}): HTMLButtonElement;
|
|
207
|
+
|
|
208
|
+
/** 点击时读取函数形式的文本。Clipboard API 失败后尝试 execCommand;均失败则显示错误和含原文的抽屉。 */
|
|
209
|
+
copyButton(text: string | (() => string), opts?: ConsoleCopyOptions): HTMLButtonElement;
|
|
210
|
+
|
|
211
|
+
/** 状态标签;on、off 分别使用启用和关闭色,plain 使用中性色。 */
|
|
212
|
+
pill(text: string, tone?: ConsoleBadge['tone']): HTMLSpanElement;
|
|
213
|
+
|
|
214
|
+
/** 读数标签,支持中性、警示与强调色;可追加节点突出数值。 */
|
|
215
|
+
chip(text: string, tone?: ConsoleChipTone): HTMLSpanElement;
|
|
216
|
+
|
|
217
|
+
/** 一行消息(保存结果、错误)。`bad` 走警示配色(`.msgline` / `.msgline.bad`)。 */
|
|
218
|
+
msgline(text?: string, bad?: boolean): HTMLDivElement;
|
|
219
|
+
|
|
220
|
+
/** 空态说明节点,可作为表格单元格内容。 */
|
|
221
|
+
placeholder(text: string): HTMLDivElement;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* 单行输入(`input.field`)。`cls` 追加到 `field` 后面(常用 `mono`)。
|
|
225
|
+
* 监听随面板 `signal` 自动摘,扩展不必自己收尾。
|
|
226
|
+
*/
|
|
227
|
+
input(opts?: ConsoleInputOptions): HTMLInputElement;
|
|
228
|
+
|
|
229
|
+
/** 下拉选择(`select.field`)。选项给字符串就是 value=label。 */
|
|
230
|
+
select(opts?: ConsoleSelectOptions): HTMLSelectElement;
|
|
231
|
+
|
|
232
|
+
/** 多行输入(`textarea.field`,可竖向拉伸)。 */
|
|
233
|
+
textarea(opts?: ConsoleTextareaOptions): HTMLTextAreaElement;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* 对话输入器。textarea、提交动作与快捷键共享一个交互边界;面板卸载时 React 根随
|
|
237
|
+
* `signal` 销毁。适用于消息式输入,不替代普通表单的 `input` / `textarea`。
|
|
238
|
+
*/
|
|
239
|
+
promptInput(opts: ConsolePromptInputOptions): ConsolePromptInput;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* 可编辑勾选框,使用 label.check 包裹 input[type=checkbox];只读状态使用 pill。
|
|
243
|
+
* 返回句柄供读取 checked 和程序更新;setChecked 不触发代表用户操作的 onChange。
|
|
244
|
+
*/
|
|
245
|
+
checkbox(label: string, opts?: ConsoleCheckboxOptions): ConsoleCheckbox;
|
|
246
|
+
|
|
247
|
+
/** 将标签与任意控件包在 label 中;返回包装节点,控件句柄由调用方保留。 */
|
|
248
|
+
field(label: string, control: HTMLElement): HTMLLabelElement;
|
|
249
|
+
|
|
250
|
+
/** 分段选择器;点击已选项和 setValue 均不触发用户回调,重复 value 的选项一同更新。 */
|
|
251
|
+
segmented(
|
|
252
|
+
items: readonly (string | { value: string; label?: string })[],
|
|
253
|
+
opts?: ConsoleSegmentedOptions,
|
|
254
|
+
): ConsoleSegmented;
|
|
255
|
+
|
|
256
|
+
/** 数据表返回节点及 clear/addRow 句柄;可选表头保持置顶。 */
|
|
257
|
+
table(opts?: ConsoleTableOptions): ConsoleTable;
|
|
258
|
+
|
|
259
|
+
/** 无表头的键值表,节点值直接挂入。值格使用等宽字体;需要保留换行时使用 table 的 txt 单元格。 */
|
|
260
|
+
kv(rows: readonly ConsoleKvRow[]): HTMLTableElement;
|
|
261
|
+
|
|
262
|
+
/** 追加式日志,有行数上限。贴底时随新增行滚动,上翻后暂停,返回底部后恢复。 */
|
|
263
|
+
log(opts?: ConsoleLogOptions): ConsoleLog;
|
|
264
|
+
|
|
265
|
+
/** 概览读数(`.stat`,内含 `.k` 小标题与 `.v` 大数字;`accent` 上强调色)。 */
|
|
266
|
+
stat(item: ConsoleStat): HTMLDivElement;
|
|
267
|
+
|
|
268
|
+
/** 读数网格(`.statgrid`,自适应列宽)。把一组 `stat` 排进去。 */
|
|
269
|
+
statgrid(items?: readonly ConsoleStat[]): HTMLDivElement;
|
|
270
|
+
|
|
271
|
+
/** 占比条;默认显示百分比,可用 format 定义读数文本。 */
|
|
272
|
+
progress(opts?: ConsoleProgressOptions): ConsoleProgress;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* 瞬时提示(`.toast` / `.toast.bad`,屏幕下沿居中)。
|
|
276
|
+
* 同一面板同时只留一条,后来的顶掉前面的。返回的 `Disposable` 可提前撤下;
|
|
277
|
+
* 面板 unmount 时自动消失,不必登记。
|
|
278
|
+
*/
|
|
279
|
+
toast(text: string, tone?: 'ok' | 'bad'): Disposable;
|
|
280
|
+
|
|
281
|
+
/** 模态确认;danger 使用危险配色与继续文案。取消或面板 unmount 时返回 false。 */
|
|
282
|
+
confirm(opts: { title: string; body?: string; danger?: boolean }): Promise<boolean>;
|
|
283
|
+
|
|
284
|
+
/** 抽屉响应 Esc、遮罩和关闭按钮。字符串放入 pre.mono,节点放入 modalbody;面板卸载时关闭。 */
|
|
285
|
+
drawer(title: string, body: string | HTMLElement): Disposable;
|
|
286
|
+
|
|
287
|
+
/** busy 只能由 Disposable 或面板 abort 关闭,不响应用户关闭操作。abort 后不显示,并返回可释放的空句柄。 */
|
|
288
|
+
busy(title: string, text?: string): Disposable;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* 局部禁用一组控件,dispose() 恢复各自原本的 disabled 状态;整页阻塞使用 busy。
|
|
292
|
+
* 同一控件只记录首次原值;dispose() 幂等。
|
|
293
|
+
*/
|
|
294
|
+
disable(...els: readonly ConsoleDisablable[]): Disposable;
|
|
295
|
+
|
|
296
|
+
readonly fmt: ConsoleFormat;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export interface ConsoleSheetOptions {
|
|
300
|
+
title: string;
|
|
301
|
+
/** 标题后的英文小注(`h3 > .en`) */
|
|
302
|
+
en?: string;
|
|
303
|
+
/** 卡片说明行(`.sh-desc`,标题下方一行灰字)。解释这张卡是干嘛的,不放读数。 */
|
|
304
|
+
desc?: string;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export interface ConsoleSheet {
|
|
308
|
+
/** 整张卡,扩展把它 append 到 `ctx.root` */
|
|
309
|
+
el: HTMLElement;
|
|
310
|
+
/** 内容区 */
|
|
311
|
+
body: HTMLElement;
|
|
312
|
+
/** 折叠态下显示的一行摘要(`sheet()` 也有,只是不折叠时不显示) */
|
|
313
|
+
note: HTMLElement;
|
|
314
|
+
/** 说明行(`.sh-desc`)。只有传了 `opts.desc` 才存在;给出来是为了之后改写它。 */
|
|
315
|
+
desc: HTMLElement | null;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** chip 的中性、警示与强调配色。 */
|
|
319
|
+
export type ConsoleChipTone = 'plain' | 'warn' | 'accent';
|
|
320
|
+
|
|
321
|
+
/** 输入控件的回调分别对应输入、change 与提交键;监听随面板 signal 释放。 */
|
|
322
|
+
export interface ConsoleFieldOptions {
|
|
323
|
+
value?: string;
|
|
324
|
+
placeholder?: string;
|
|
325
|
+
/** 追加到 `field` 之后的 class,如 `mono` */
|
|
326
|
+
cls?: string;
|
|
327
|
+
disabled?: boolean;
|
|
328
|
+
/** 值变了。input/textarea 听 `input`,select 听 `change`。 */
|
|
329
|
+
onInput?: (value: string) => void;
|
|
330
|
+
/** change 事件:input/textarea 值变化后失焦,select 选项变化。select 的 onInput 也监听 change,若两者均提供则都会触发。 */
|
|
331
|
+
onChange?: (value: string) => void;
|
|
332
|
+
/** Enter 提交;textarea 使用 Ctrl/⌘+Enter,IME 组词期间不提交。浏览器可能继续派发 change,同时使用两种提交回调时由调用方去重。 */
|
|
333
|
+
onCommit?: (value: string) => void;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** `checkbox` 的选项。 */
|
|
337
|
+
export interface ConsoleCheckboxOptions {
|
|
338
|
+
checked?: boolean;
|
|
339
|
+
disabled?: boolean;
|
|
340
|
+
/** 悬停气泡(`title` 属性)。写"点一下会发生什么",别重复标签本身。 */
|
|
341
|
+
title?: string;
|
|
342
|
+
/** 用户拨动时。**`setChecked` 不触发它。** */
|
|
343
|
+
onChange?: (checked: boolean) => void;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export interface ConsoleCheckbox {
|
|
347
|
+
/** `label.check`(含方框与标签文字),扩展把它 append 到卡里 */
|
|
348
|
+
el: HTMLLabelElement;
|
|
349
|
+
/** 里面那个 `input[type=checkbox]`。要设 `disabled`、要聚焦时用。 */
|
|
350
|
+
input: HTMLInputElement;
|
|
351
|
+
/** 当前是否勾选 */
|
|
352
|
+
readonly checked: boolean;
|
|
353
|
+
/** 程序化设值,不触发 `onChange` */
|
|
354
|
+
setChecked(checked: boolean): void;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export interface ConsoleSegmentedOptions {
|
|
358
|
+
/** 初始选中的 value。不给(或给了一个不在 items 里的值)就一颗都不亮。 */
|
|
359
|
+
value?: string;
|
|
360
|
+
/** `.segwrap.sm`:塞进 `rowbar` 与 `.btn.sm` 并排时用 */
|
|
361
|
+
size?: 'sm' | 'md';
|
|
362
|
+
/** 用户切换时。**点已经选中的那颗不触发**,`setValue` 也不触发。 */
|
|
363
|
+
onSelect?: (value: string) => void;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export interface ConsoleSegmented {
|
|
367
|
+
/** `.segwrap`,扩展把它 append 到卡里 */
|
|
368
|
+
el: HTMLDivElement;
|
|
369
|
+
/** 当前选中的 value */
|
|
370
|
+
readonly value: string;
|
|
371
|
+
/** 程序化切换选中态,不触发 `onSelect` */
|
|
372
|
+
setValue(value: string): void;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** `kv` 的一行。`k` 是字段名(左列窄灰),`v` 给节点就直接放。 */
|
|
376
|
+
export interface ConsoleKvRow {
|
|
377
|
+
k: string;
|
|
378
|
+
v: string | number | HTMLElement | null | undefined;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export interface ConsoleInputOptions extends ConsoleFieldOptions {
|
|
382
|
+
/** 缺省 `text`。`search` 会带上浏览器的清除按钮。 */
|
|
383
|
+
type?: 'text' | 'number' | 'password' | 'search' | 'date';
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export interface ConsoleSelectOptions extends ConsoleFieldOptions {
|
|
387
|
+
/** 给字符串等价于 `{ value: s, label: s }` */
|
|
388
|
+
options?: readonly (string | { value: string; label?: string })[];
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export interface ConsoleTextareaOptions extends ConsoleFieldOptions {
|
|
392
|
+
rows?: number;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* 输入器交出的一张图:已按 `ConsolePromptImagesOptions` 归一化(长边缩到上限、超限的
|
|
397
|
+
* 重编码),base64 不带 `data:` 前缀,直接可进 JSON 帧。
|
|
398
|
+
*/
|
|
399
|
+
export interface ConsoleImageAttachment {
|
|
400
|
+
name: string;
|
|
401
|
+
/** image/jpeg | image/png | image/webp | image/gif */
|
|
402
|
+
mime: string;
|
|
403
|
+
base64: string;
|
|
404
|
+
/** 编码后的字节数 */
|
|
405
|
+
bytes: number;
|
|
406
|
+
width: number;
|
|
407
|
+
height: number;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* 输入器的图片通道。给了就出现附图按钮、接收粘贴与拖放,输入框上方长出缩略图托盘;
|
|
412
|
+
* 不给就是纯文本输入器。
|
|
413
|
+
*/
|
|
414
|
+
export interface ConsolePromptImagesOptions {
|
|
415
|
+
/** 一条消息最多带几张,缺省 8。超出的拒收并就地提示。 */
|
|
416
|
+
max?: number;
|
|
417
|
+
/** 长边上限(像素),缺省 2048。超过的按比例缩小。 */
|
|
418
|
+
maxEdge?: number;
|
|
419
|
+
/** 单张编码后字节上限,缺省 6MB。超限的按 JPEG 重编码;仍超就拒收。 */
|
|
420
|
+
maxBytes?: number;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export interface ConsolePromptInputOptions {
|
|
424
|
+
label?: string;
|
|
425
|
+
placeholder?: string;
|
|
426
|
+
hint?: string;
|
|
427
|
+
disabled?: boolean;
|
|
428
|
+
/** 发送键左侧的紧凑工具入口。节点所有权随 prompt input 一起结束。 */
|
|
429
|
+
tools?: HTMLElement;
|
|
430
|
+
/** 图片通道。不给 = 不收图,`onSubmit` 的第二参恒为空数组。 */
|
|
431
|
+
images?: ConsolePromptImagesOptions;
|
|
432
|
+
/**
|
|
433
|
+
* 文本与图片至少一样非空才触发。
|
|
434
|
+
* 返回 `false` 保留当前内容(文本与托盘都留);其余返回值表示已接收并清空。
|
|
435
|
+
*/
|
|
436
|
+
onSubmit(text: string, images: readonly ConsoleImageAttachment[]): boolean | void;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export interface ConsolePromptInput {
|
|
440
|
+
el: HTMLDivElement;
|
|
441
|
+
focus(): void;
|
|
442
|
+
setDisabled(disabled: boolean): void;
|
|
443
|
+
/** 设置输入框占位文本;`null` 恢复初值。 */
|
|
444
|
+
setPlaceholder(text: string | null): void;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export interface ConsoleTableOptions {
|
|
448
|
+
/** 表头文字。不给就不渲染 `<thead>`。 */
|
|
449
|
+
head?: readonly string[];
|
|
450
|
+
/** 外框最高多少(如 `calc(100vh - 300px)`)。给了才滚,表头的 sticky 也才有意义。 */
|
|
451
|
+
maxHeight?: string;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* 一格。给字符串/数字就是纯文本;给节点就直接放进去(塞 `pill`、按钮用);
|
|
456
|
+
* 给对象可以额外指定单元格 class(既有的 `mono` = 等宽不换行,`txt` = 保留换行)。
|
|
457
|
+
*/
|
|
458
|
+
export type ConsoleCell =
|
|
459
|
+
| string
|
|
460
|
+
| number
|
|
461
|
+
| null
|
|
462
|
+
| undefined
|
|
463
|
+
| HTMLElement
|
|
464
|
+
| { text?: string | number | null; el?: HTMLElement; cls?: string };
|
|
465
|
+
|
|
466
|
+
export interface ConsoleTable {
|
|
467
|
+
/** 外框 `.tablewrap`,扩展把它 append 到卡里 */
|
|
468
|
+
el: HTMLDivElement;
|
|
469
|
+
/** `<tbody>`,想自己操作行时用 */
|
|
470
|
+
body: HTMLTableSectionElement;
|
|
471
|
+
/** 追加一行 */
|
|
472
|
+
addRow(cells: readonly ConsoleCell[]): HTMLTableRowElement;
|
|
473
|
+
/** 清空。带一句话就铺一行跨列的 `.placeholder` 空态。 */
|
|
474
|
+
clear(empty?: string): void;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
export interface ConsoleStat {
|
|
478
|
+
/** 小标题(`.k`) */
|
|
479
|
+
k: string;
|
|
480
|
+
/** 大数字(`.v`)。给节点就直接放。 */
|
|
481
|
+
v: string | number | HTMLElement;
|
|
482
|
+
/** 数字后面的小字单位(`.v small`),如 `次` / `tok` */
|
|
483
|
+
unit?: string;
|
|
484
|
+
/** 上强调色(`.stat.accent`)。一屏里只该有一两个。 */
|
|
485
|
+
accent?: boolean;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* 一行日志的配色,对应 `.logline` / `.logline.dim` / `.logline.warn` / `.logline.bad`。
|
|
490
|
+
* 与 `ConsoleChipTone` 一样按**角色**命名:`dim` 是次要噪声(心跳、回执),
|
|
491
|
+
* `warn` 是需要留意但没坏,`bad` 是真出事了。
|
|
492
|
+
*/
|
|
493
|
+
export type ConsoleLogTone = 'plain' | 'dim' | 'warn' | 'bad';
|
|
494
|
+
|
|
495
|
+
export interface ConsoleLogOptions {
|
|
496
|
+
/** `conversation` 使用阅读型正文排版;缺省保留等宽日志排版。 */
|
|
497
|
+
variant?: 'plain' | 'conversation';
|
|
498
|
+
/**
|
|
499
|
+
* 日志保留行数上限,超出时从头裁剪,避免长期运行时节点无界增长;缺省 400。
|
|
500
|
+
*/
|
|
501
|
+
max?: number;
|
|
502
|
+
/** 外框最高多少(缺省 `240px`)。给了才滚,粘滞也才有意义。 */
|
|
503
|
+
maxHeight?: string;
|
|
504
|
+
/** 一行都没有时铺的空态(`.placeholder`)。不给就留一个空框。 */
|
|
505
|
+
empty?: string;
|
|
506
|
+
/** 贴底容差,单位像素,默认 24;scrollTop 可能包含小数。 */
|
|
507
|
+
stickThreshold?: number;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
export interface ConsoleLog {
|
|
511
|
+
/** `.logview`,扩展把它 append 到卡里 */
|
|
512
|
+
el: HTMLDivElement;
|
|
513
|
+
/** 追加一行,返回那一行的节点(想再往里塞 `chip` / 链接时用) */
|
|
514
|
+
append(line: string, tone?: ConsoleLogTone): HTMLDivElement;
|
|
515
|
+
/** 清空(回到空态) */
|
|
516
|
+
clear(): void;
|
|
517
|
+
/** 当前有几行 */
|
|
518
|
+
readonly count: number;
|
|
519
|
+
/** 此刻是否粘在底部。用来画一颗"回到底部"的按钮。 */
|
|
520
|
+
readonly stuck: boolean;
|
|
521
|
+
/** 滚到底并重新粘住("回到底部"那颗按钮点下去做的事) */
|
|
522
|
+
scrollToEnd(): void;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
export interface ConsoleProgressOptions {
|
|
526
|
+
/** 满值,缺省 1。给 0 或非有限数一律当 1(否则读数是 `NaN%`)。 */
|
|
527
|
+
max?: number;
|
|
528
|
+
/** 初值,缺省 0 */
|
|
529
|
+
value?: number;
|
|
530
|
+
/** 左侧小标题。不给就只有右侧读数。 */
|
|
531
|
+
label?: string;
|
|
532
|
+
/** 右侧读数怎么印。不给就是百分比;给了可以印成 `3 / 12`。 */
|
|
533
|
+
format?: (value: number, max: number) => string;
|
|
534
|
+
/** 条的配色,与 `ConsoleChipTone` 同一套词。 */
|
|
535
|
+
tone?: ConsoleChipTone;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
export interface ConsoleProgress {
|
|
539
|
+
/** `.progress`,扩展把它 append 到卡里 */
|
|
540
|
+
el: HTMLDivElement;
|
|
541
|
+
readonly value: number;
|
|
542
|
+
readonly max: number;
|
|
543
|
+
/** 设值;顺带改满值(总量是边跑边知道的时候用) */
|
|
544
|
+
setValue(value: number, max?: number): void;
|
|
545
|
+
/** 改左侧小标题 */
|
|
546
|
+
setLabel(text: string): void;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
export interface ConsoleCopyOptions {
|
|
550
|
+
/** 按钮上的字,缺省「复制」 */
|
|
551
|
+
label?: string;
|
|
552
|
+
/** 缺省 `sm`:这颗几乎总是跟在别的东西后面,不该抢主按钮的份量 */
|
|
553
|
+
size?: 'sm' | 'md';
|
|
554
|
+
variant?: 'plain' | 'primary';
|
|
555
|
+
/** 成功那条 toast 的措辞,缺省「已复制」 */
|
|
556
|
+
okText?: string;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/** 接受任意带 disabled 字段的控件,忽略 null 与 undefined。 */
|
|
560
|
+
export type ConsoleDisablable = { disabled: boolean } | null | undefined;
|
|
561
|
+
|
|
562
|
+
export interface ConsoleFormat {
|
|
563
|
+
/** 12345 → `12.3k` */
|
|
564
|
+
count(n: number | null | undefined): string;
|
|
565
|
+
/** 1536 → `1.5K` */
|
|
566
|
+
bytes(n: number | null | undefined): string;
|
|
567
|
+
/** 0.42 → `42%` */
|
|
568
|
+
percent(r: number | null | undefined): string;
|
|
569
|
+
/** ISO 时间戳 → `18:56:48` */
|
|
570
|
+
clock(ts: unknown): string;
|
|
571
|
+
/** 金额,带货币符号 */
|
|
572
|
+
money(n: number | null | undefined, currency?: string): string;
|
|
573
|
+
/** 毫秒 → `1.2s` / `3m 04s` */
|
|
574
|
+
duration(ms: number | null | undefined): string;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// ---------------------------------------------------------------------------
|
|
578
|
+
// Bundle
|
|
579
|
+
// ---------------------------------------------------------------------------
|
|
580
|
+
|
|
581
|
+
export interface ConsolePanel {
|
|
582
|
+
/**
|
|
583
|
+
* 渲染面板,返回的 Disposable 在 unmount 时释放;ctx.own、interval、frame 已登记的资源无需再次返回。抛错由 host 转成当前面板错误卡,不影响其他面板或其他页。
|
|
584
|
+
*/
|
|
585
|
+
mount(ctx: ConsolePanelContext): void | Disposable | Promise<void | Disposable>;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/** console/client.ts 的 default 导出。panels 以局部 panel id 为键;服务端已声明但扩展未提供的面板显示错误。 */
|
|
589
|
+
export interface ConsoleClientBundle {
|
|
590
|
+
panels: Record<string, ConsolePanel>;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* host 侧用来校验 `import()` 回来的东西确实是个扩展。
|
|
595
|
+
*
|
|
596
|
+
* 数组要排掉:`{panels: []}` 也满足 `typeof === 'object'`,放过去之后 host 会
|
|
597
|
+
* 按 `panels[panelId]` 全部取空,报成"扩展缺这个面板"——那是条误导的诊断,
|
|
598
|
+
* 真相是"这压根不是个扩展"。
|
|
599
|
+
*/
|
|
600
|
+
export function isConsoleClientBundle(v: unknown): v is ConsoleClientBundle {
|
|
601
|
+
const panels = (v as ConsoleClientBundle | null)?.panels;
|
|
602
|
+
return !!panels && typeof panels === 'object' && !Array.isArray(panels);
|
|
603
|
+
}
|