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,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<title>Bilibili Overlay</title>
|
|
7
|
+
<link rel="stylesheet" href="/overlay/styles.css">
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<main id="stage" aria-label="Bilibili Overlay"></main>
|
|
11
|
+
<script src="/overlay/app.js"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
color-scheme: dark;
|
|
3
|
+
font-family: "Microsoft YaHei", sans-serif;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
* { box-sizing: border-box; }
|
|
7
|
+
|
|
8
|
+
html,
|
|
9
|
+
body {
|
|
10
|
+
width: 100%;
|
|
11
|
+
height: 100%;
|
|
12
|
+
margin: 0;
|
|
13
|
+
overflow: hidden;
|
|
14
|
+
background: transparent;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
body.preview {
|
|
18
|
+
--wall-base: #202735;
|
|
19
|
+
--wall-tile: #2b3445;
|
|
20
|
+
background-color: var(--wall-base);
|
|
21
|
+
background-image:
|
|
22
|
+
linear-gradient(45deg, var(--wall-tile) 25%, transparent 25%),
|
|
23
|
+
linear-gradient(-45deg, var(--wall-tile) 25%, transparent 25%),
|
|
24
|
+
linear-gradient(45deg, transparent 75%, var(--wall-tile) 75%),
|
|
25
|
+
linear-gradient(-45deg, transparent 75%, var(--wall-tile) 75%);
|
|
26
|
+
background-position: 0 0, 0 16px, 16px -16px, -16px 0;
|
|
27
|
+
background-size: 32px 32px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
body.preview[data-wall-mode="light"] {
|
|
31
|
+
--wall-base: #e8edf1;
|
|
32
|
+
--wall-tile: #f5f7f9;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
body.preview[data-wall-mode="dark"] {
|
|
36
|
+
--wall-base: #202735;
|
|
37
|
+
--wall-tile: #2b3445;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
#stage {
|
|
41
|
+
position: absolute;
|
|
42
|
+
left: 0;
|
|
43
|
+
top: 0;
|
|
44
|
+
overflow: hidden;
|
|
45
|
+
transform-origin: left top;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.overlay-component {
|
|
49
|
+
position: absolute;
|
|
50
|
+
overflow: hidden;
|
|
51
|
+
box-sizing: border-box;
|
|
52
|
+
display: flex;
|
|
53
|
+
flex-direction: column;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.component-content {
|
|
57
|
+
position: relative;
|
|
58
|
+
flex: 1 1 auto;
|
|
59
|
+
min-width: 0;
|
|
60
|
+
min-height: 0;
|
|
61
|
+
overflow: hidden;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.overlay-component.title-left,
|
|
65
|
+
.overlay-component.title-right {
|
|
66
|
+
flex-direction: row;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.component-title {
|
|
70
|
+
display: flex;
|
|
71
|
+
flex: 0 0 auto;
|
|
72
|
+
align-items: center;
|
|
73
|
+
min-width: 0;
|
|
74
|
+
min-height: 0;
|
|
75
|
+
padding: .28em .62em;
|
|
76
|
+
overflow: hidden;
|
|
77
|
+
line-height: 1.15;
|
|
78
|
+
white-space: nowrap;
|
|
79
|
+
background: rgba(0, 0, 0, .08);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.title-left .component-title,
|
|
83
|
+
.title-right .component-title {
|
|
84
|
+
align-self: stretch;
|
|
85
|
+
padding: .62em .28em;
|
|
86
|
+
writing-mode: vertical-rl;
|
|
87
|
+
text-orientation: upright;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.component-title.align-left {
|
|
91
|
+
justify-content: flex-start;
|
|
92
|
+
text-align: left;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.component-title.align-center {
|
|
96
|
+
justify-content: center;
|
|
97
|
+
text-align: center;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.component-title.align-right {
|
|
101
|
+
justify-content: flex-end;
|
|
102
|
+
text-align: right;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.overlay-text,
|
|
106
|
+
.audience-name,
|
|
107
|
+
.audience-body {
|
|
108
|
+
white-space: pre-wrap;
|
|
109
|
+
overflow-wrap: anywhere;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.fixed-notice > .component-content,
|
|
113
|
+
.agent-notice > .component-content {
|
|
114
|
+
display: flex;
|
|
115
|
+
align-items: center;
|
|
116
|
+
justify-content: center;
|
|
117
|
+
text-align: center;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.image-component:not(.has-title) {
|
|
121
|
+
background: transparent !important;
|
|
122
|
+
border: 0 !important;
|
|
123
|
+
padding: 0 !important;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.image-component .component-content img {
|
|
127
|
+
display: block;
|
|
128
|
+
width: 100%;
|
|
129
|
+
height: 100%;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.agent-typing-cursor {
|
|
133
|
+
display: inline-block;
|
|
134
|
+
width: .08em;
|
|
135
|
+
height: 1em;
|
|
136
|
+
margin-left: .1em;
|
|
137
|
+
vertical-align: -.1em;
|
|
138
|
+
background: currentColor;
|
|
139
|
+
animation: agent-cursor-blink 720ms steps(1, end) infinite;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.danmaku-feed {
|
|
143
|
+
position: relative;
|
|
144
|
+
width: 100%;
|
|
145
|
+
height: 100%;
|
|
146
|
+
overflow: hidden;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.danmaku-feed.vertical {
|
|
150
|
+
display: flex;
|
|
151
|
+
flex-direction: column;
|
|
152
|
+
justify-content: flex-end;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.audience-item {
|
|
156
|
+
display: flex;
|
|
157
|
+
align-items: center;
|
|
158
|
+
min-width: 0;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.danmaku-feed.vertical .audience-item {
|
|
162
|
+
flex: 0 0 auto;
|
|
163
|
+
animation: vertical-in 220ms ease-out both;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.danmaku-feed.horizontal .audience-item {
|
|
167
|
+
position: absolute;
|
|
168
|
+
left: 100%;
|
|
169
|
+
width: max-content;
|
|
170
|
+
max-width: none;
|
|
171
|
+
white-space: nowrap;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.audience-avatar {
|
|
175
|
+
flex: 0 0 auto;
|
|
176
|
+
width: 1.7em;
|
|
177
|
+
height: 1.7em;
|
|
178
|
+
margin-right: .45em;
|
|
179
|
+
border-radius: 50%;
|
|
180
|
+
object-fit: cover;
|
|
181
|
+
background: rgba(255,255,255,.22);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.audience-avatar.fallback {
|
|
185
|
+
display: grid;
|
|
186
|
+
place-items: center;
|
|
187
|
+
color: white;
|
|
188
|
+
font-size: .75em;
|
|
189
|
+
font-weight: 700;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.audience-name { margin-right: .45em; }
|
|
193
|
+
|
|
194
|
+
.scroll-viewport {
|
|
195
|
+
position: relative;
|
|
196
|
+
width: 100%;
|
|
197
|
+
height: 100%;
|
|
198
|
+
overflow: hidden;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.scroll-track {
|
|
202
|
+
position: absolute;
|
|
203
|
+
display: flex;
|
|
204
|
+
align-items: center;
|
|
205
|
+
width: max-content;
|
|
206
|
+
height: max-content;
|
|
207
|
+
will-change: transform;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
.scroll-track.horizontal {
|
|
211
|
+
top: 50%;
|
|
212
|
+
left: 100%;
|
|
213
|
+
transform: translateY(-50%);
|
|
214
|
+
white-space: nowrap;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.scroll-track.vertical {
|
|
218
|
+
left: 50%;
|
|
219
|
+
top: 100%;
|
|
220
|
+
flex-direction: column;
|
|
221
|
+
transform: translateX(-50%);
|
|
222
|
+
text-align: center;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
.scroll-track.line-carousel {
|
|
226
|
+
top: 0;
|
|
227
|
+
left: 0;
|
|
228
|
+
transform: none;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.scroll-track.line-carousel.horizontal {
|
|
232
|
+
height: 100%;
|
|
233
|
+
white-space: normal;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
.scroll-track.line-carousel.vertical {
|
|
237
|
+
width: 100%;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.notice-slide {
|
|
241
|
+
display: flex;
|
|
242
|
+
flex: 0 0 auto;
|
|
243
|
+
align-items: center;
|
|
244
|
+
justify-content: center;
|
|
245
|
+
padding: 0 .25em;
|
|
246
|
+
overflow: hidden;
|
|
247
|
+
text-align: center;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
@keyframes vertical-in {
|
|
251
|
+
from { opacity: 0; transform: translateY(12px); }
|
|
252
|
+
to { opacity: 1; transform: translateY(0); }
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
@keyframes agent-cursor-blink {
|
|
256
|
+
0%, 52% { opacity: 1; }
|
|
257
|
+
53%, 100% { opacity: 0; }
|
|
258
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* protobuf 线格式读取器,仅解字段号、wire type 与原始值,不使用 .proto 或执行类型映射;调用方解释字段布局。
|
|
3
|
+
* 读取失败返回 null、undefined 或空串,由调用方处理。
|
|
4
|
+
* 单值字段按 protobuf 语义取同字段号最后一次出现的值。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** 一个字段的原始读数。`varint` / `bytes` 按 wire type 二选一。 */
|
|
8
|
+
export interface PbField {
|
|
9
|
+
readonly field: number;
|
|
10
|
+
readonly wire: number;
|
|
11
|
+
readonly varint?: bigint;
|
|
12
|
+
readonly bytes?: Uint8Array;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const TEXT = new TextDecoder('utf-8', { fatal: true });
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 解析一层字段;内容截断、长度越界或 wire type 不受支持时返回 null。
|
|
19
|
+
*/
|
|
20
|
+
export function pbDecode(buf: Uint8Array): PbField[] | null {
|
|
21
|
+
const out: PbField[] = [];
|
|
22
|
+
let i = 0;
|
|
23
|
+
while (i < buf.length) {
|
|
24
|
+
const key = readVarint(buf, i);
|
|
25
|
+
if (!key) return null;
|
|
26
|
+
i = key.next;
|
|
27
|
+
const field = Number(key.value >> 3n);
|
|
28
|
+
const wire = Number(key.value & 7n);
|
|
29
|
+
if (field <= 0) return null;
|
|
30
|
+
if (wire === 0) {
|
|
31
|
+
const value = readVarint(buf, i);
|
|
32
|
+
if (!value) return null;
|
|
33
|
+
i = value.next;
|
|
34
|
+
out.push({ field, wire, varint: value.value });
|
|
35
|
+
} else if (wire === 2) {
|
|
36
|
+
const len = readVarint(buf, i);
|
|
37
|
+
if (!len) return null;
|
|
38
|
+
const start = len.next;
|
|
39
|
+
const end = start + Number(len.value);
|
|
40
|
+
if (!Number.isSafeInteger(end) || end > buf.length) return null;
|
|
41
|
+
out.push({ field, wire, bytes: buf.subarray(start, end) });
|
|
42
|
+
i = end;
|
|
43
|
+
} else if (wire === 5 || wire === 1) {
|
|
44
|
+
const width = wire === 5 ? 4 : 8;
|
|
45
|
+
if (i + width > buf.length) return null;
|
|
46
|
+
out.push({ field, wire, bytes: buf.subarray(i, i + width) });
|
|
47
|
+
i += width;
|
|
48
|
+
} else {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 按 Node Buffer 的 base64 规则解码;空输入、空结果或 protobuf 解析失败时返回 null。 */
|
|
56
|
+
export function pbFromBase64(value: unknown): PbField[] | null {
|
|
57
|
+
if (typeof value !== 'string' || !value) return null;
|
|
58
|
+
let bytes: Buffer;
|
|
59
|
+
try {
|
|
60
|
+
bytes = Buffer.from(value, 'base64');
|
|
61
|
+
} catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
if (bytes.length === 0) return null;
|
|
65
|
+
return pbDecode(bytes);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 将字段字节解析为嵌套消息;缺少字节或解析失败时返回 null。 */
|
|
69
|
+
export function pbSub(fields: readonly PbField[] | null, field: number): PbField[] | null {
|
|
70
|
+
const bytes = pick(fields, field)?.bytes;
|
|
71
|
+
return bytes ? pbDecode(bytes) : null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** 将字段字节解码为 UTF-8;缺少字节、解码失败或包含控制字符时返回空串。 */
|
|
75
|
+
export function pbText(fields: readonly PbField[] | null, field: number): string {
|
|
76
|
+
const bytes = pick(fields, field)?.bytes;
|
|
77
|
+
if (!bytes) return '';
|
|
78
|
+
let text: string;
|
|
79
|
+
try {
|
|
80
|
+
text = TEXT.decode(bytes);
|
|
81
|
+
} catch {
|
|
82
|
+
return '';
|
|
83
|
+
}
|
|
84
|
+
return hasControlChars(text) ? '' : text;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 读取 varint;缺失或超出 JavaScript 安全整数范围时返回 undefined。
|
|
89
|
+
*/
|
|
90
|
+
export function pbInt(fields: readonly PbField[] | null, field: number): number | undefined {
|
|
91
|
+
const value = pick(fields, field)?.varint;
|
|
92
|
+
if (value === undefined) return undefined;
|
|
93
|
+
const num = Number(value);
|
|
94
|
+
return Number.isSafeInteger(num) ? num : undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function hasControlChars(text: string): boolean {
|
|
98
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
99
|
+
if (text.charCodeAt(i) < 0x20) return true;
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function pick(fields: readonly PbField[] | null, field: number): PbField | undefined {
|
|
105
|
+
if (!fields) return undefined;
|
|
106
|
+
for (let i = fields.length - 1; i >= 0; i -= 1) {
|
|
107
|
+
if (fields[i].field === field) return fields[i];
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** varint 最多读取 10 字节;没有终止位时返回 null。 */
|
|
113
|
+
function readVarint(buf: Uint8Array, from: number): { value: bigint; next: number } | null {
|
|
114
|
+
let value = 0n;
|
|
115
|
+
let shift = 0n;
|
|
116
|
+
for (let i = from; i < buf.length && i - from < 10; i += 1) {
|
|
117
|
+
const byte = buf[i];
|
|
118
|
+
value |= BigInt(byte & 0x7f) << shift;
|
|
119
|
+
if ((byte & 0x80) === 0) return { value, next: i + 1 };
|
|
120
|
+
shift += 7n;
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* B 站直播长连的帧编解码。
|
|
3
|
+
*
|
|
4
|
+
* 帧头固定 16 字节:总长 u32 | 头长 u16 | protover u16 | op u32 | seq u32。
|
|
5
|
+
* 一个 WebSocket 消息可包含多个包;op=5 且 protover 为 2/3 时,包体是 zlib/brotli 压缩的嵌套包序列。
|
|
6
|
+
*/
|
|
7
|
+
import { brotliDecompressSync, inflateSync } from 'node:zlib';
|
|
8
|
+
|
|
9
|
+
export const OP = {
|
|
10
|
+
HEARTBEAT: 2,
|
|
11
|
+
HEARTBEAT_REPLY: 3,
|
|
12
|
+
MESSAGE: 5,
|
|
13
|
+
AUTH: 7,
|
|
14
|
+
AUTH_REPLY: 8,
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
const HEADER_LEN = 16;
|
|
18
|
+
|
|
19
|
+
/** 编码为未压缩包(protover 1)。 */
|
|
20
|
+
export function encodePacket(op: number, body: string): Buffer {
|
|
21
|
+
const payload = Buffer.from(body, 'utf8');
|
|
22
|
+
const buf = Buffer.alloc(HEADER_LEN + payload.length);
|
|
23
|
+
buf.writeUInt32BE(HEADER_LEN + payload.length, 0);
|
|
24
|
+
buf.writeUInt16BE(HEADER_LEN, 4);
|
|
25
|
+
buf.writeUInt16BE(1, 6);
|
|
26
|
+
buf.writeUInt32BE(op, 8);
|
|
27
|
+
buf.writeUInt32BE(1, 12);
|
|
28
|
+
payload.copy(buf, HEADER_LEN);
|
|
29
|
+
return buf;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type Frame =
|
|
33
|
+
| { kind: 'auth'; code: number }
|
|
34
|
+
| { kind: 'popularity'; value: number }
|
|
35
|
+
| { kind: 'cmd'; msg: Record<string, unknown> };
|
|
36
|
+
|
|
37
|
+
interface RawPacket {
|
|
38
|
+
ver: number;
|
|
39
|
+
op: number;
|
|
40
|
+
body: Buffer;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 长度字段越界时停止解析,丢弃剩余字节。 */
|
|
44
|
+
function* iterPackets(buf: Buffer): Generator<RawPacket> {
|
|
45
|
+
let off = 0;
|
|
46
|
+
while (off + HEADER_LEN <= buf.length) {
|
|
47
|
+
const total = buf.readUInt32BE(off);
|
|
48
|
+
const headLen = buf.readUInt16BE(off + 4);
|
|
49
|
+
const ver = buf.readUInt16BE(off + 6);
|
|
50
|
+
const op = buf.readUInt32BE(off + 8);
|
|
51
|
+
if (total < headLen || headLen < HEADER_LEN || off + total > buf.length) return;
|
|
52
|
+
yield { ver, op, body: buf.subarray(off + headLen, off + total) };
|
|
53
|
+
off += total;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 解码消息中的包;解压或 JSON 解析失败的包跳过。 */
|
|
58
|
+
export function parseFrame(buf: Buffer): Frame[] {
|
|
59
|
+
const out: Frame[] = [];
|
|
60
|
+
collect(buf, out);
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function collect(buf: Buffer, out: Frame[]): void {
|
|
65
|
+
for (const pkt of iterPackets(buf)) {
|
|
66
|
+
if (pkt.op === OP.AUTH_REPLY) {
|
|
67
|
+
out.push({ kind: 'auth', code: readJson(pkt.body)?.code as number ?? 0 });
|
|
68
|
+
} else if (pkt.op === OP.HEARTBEAT_REPLY) {
|
|
69
|
+
out.push({ kind: 'popularity', value: pkt.body.length >= 4 ? pkt.body.readUInt32BE(0) : 0 });
|
|
70
|
+
} else if (pkt.op === OP.MESSAGE) {
|
|
71
|
+
if (pkt.ver === 2 || pkt.ver === 3) {
|
|
72
|
+
let inner: Buffer;
|
|
73
|
+
try {
|
|
74
|
+
inner = pkt.ver === 2 ? inflateSync(pkt.body) : brotliDecompressSync(pkt.body);
|
|
75
|
+
} catch {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
collect(inner, out);
|
|
79
|
+
} else {
|
|
80
|
+
const msg = readJson(pkt.body);
|
|
81
|
+
if (msg) out.push({ kind: 'cmd', msg });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function readJson(body: Buffer): Record<string, unknown> | null {
|
|
88
|
+
try {
|
|
89
|
+
const parsed: unknown = JSON.parse(body.toString('utf8'));
|
|
90
|
+
return parsed !== null && typeof parsed === 'object' ? (parsed as Record<string, unknown>) : null;
|
|
91
|
+
} catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|