dsh-chat-background 0.0.0-stage → 1.0.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/index.js ADDED
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Host half of the dsh-chat-background bundle.
3
+ *
4
+ * Serves the user's background folder over the local Web server so the browser
5
+ * half can list and display those images, and aggregates the all-sessions token
6
+ * total the sidebar line shows. It deliberately imports nothing outside
7
+ * `node:` builtins and its own `host/` modules: a profile-installed package
8
+ * cannot resolve the installation's `@deepseek-ai/*` packages.
9
+ *
10
+ * The routes are registered next to the application's own `/api` route and are
11
+ * equally reachable from a browser, so they apply their own request fence
12
+ * (`SEC-02`). The token total prefers the documented Host services and falls
13
+ * back to scanning the projection cache on disk.
14
+ */
15
+ import { existsSync, readFileSync } from 'node:fs'
16
+ import { join } from 'node:path'
17
+ import {
18
+ FILE_PREFIX,
19
+ FOLDER_PATH,
20
+ HEALTH_PATH,
21
+ LIST_PATH,
22
+ TOKEN_CACHE_MS,
23
+ TOKEN_PATH,
24
+ TRUSTED_HOSTS_ENV
25
+ } from './host/constants.js'
26
+ import { backgroundsDir, dshHomeDir } from './host/paths.js'
27
+ import { createHandlers } from './host/routes.js'
28
+ import { readTokenTotals, readTokenTotalsFromServices } from './host/token-usage.js'
29
+
30
+ /** This plugin owns five routes on the Web server. */
31
+ export const inject = ['webServer']
32
+
33
+ /** The installed package version, reported by the health route. */
34
+ const PACKAGE_VERSION = (() => {
35
+ try {
36
+ return JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version ?? 'unknown'
37
+ } catch {
38
+ return 'unknown'
39
+ }
40
+ })()
41
+
42
+ /** Hostnames that always identify this machine. */
43
+ const LOOPBACK_HOSTNAMES = ['127.0.0.1', 'localhost', '[::1]', '::1']
44
+
45
+ /**
46
+ * The hostnames the request fence accepts: loopback names, the Web server's own
47
+ * advertised origin, and anything listed in the env override. `*` disables the
48
+ * host check for a remote-access proxy that rewrites `Host`.
49
+ * @param ctx - host plugin context.
50
+ * @returns accepted hostnames, or null when the check is disabled.
51
+ */
52
+ function resolveTrustedHosts(ctx) {
53
+ const override = process.env[TRUSTED_HOSTS_ENV]
54
+ if (typeof override === 'string' && override.trim() === '*') return null
55
+ const hosts = new Set(LOOPBACK_HOSTNAMES)
56
+ try {
57
+ const origin = ctx.webServer?.getOrigin?.()
58
+ if (typeof origin === 'string' && origin !== '') hosts.add(new URL(origin).hostname.toLowerCase())
59
+ } catch {
60
+ /* An unavailable origin just leaves the loopback list in place. */
61
+ }
62
+ if (typeof override === 'string') {
63
+ for (const part of override.split(',')) {
64
+ const name = part.trim().toLowerCase()
65
+ if (name !== '') hosts.add(name)
66
+ }
67
+ }
68
+ return hosts
69
+ }
70
+
71
+ /**
72
+ * Build the token-total provider. Prefers the documented Host services, falls
73
+ * back to the projection-cache files when they are not mounted.
74
+ * @param ctx - host plugin context.
75
+ * @param tokenDirectory - projection-cache directory used by the fallback.
76
+ * @returns a function returning the aggregate payload or null.
77
+ */
78
+ function createTokenProvider(ctx, tokenDirectory) {
79
+ const serviceTotals = async () => {
80
+ const persistence = ctx.get?.('sessionPersistence')
81
+ const projectionCache = ctx.get?.('sessionProjectionCache')
82
+ if (typeof persistence?.list !== 'function' || typeof projectionCache?.cachedSnapshot !== 'function') return null
83
+ return readTokenTotalsFromServices({ persistence, projectionCache })
84
+ }
85
+ return async () => {
86
+ try {
87
+ const fromServices = await serviceTotals()
88
+ if (fromServices !== null) return fromServices
89
+ } catch (error) {
90
+ ctx.logger?.warn?.(error instanceof Error ? error : new Error(String(error)))
91
+ }
92
+ return readTokenTotals(tokenDirectory)
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Register the background routes; disposal removes them with the plugin.
98
+ * @param ctx - host plugin context carrying the Web server service.
99
+ */
100
+ export function apply(ctx) {
101
+ const folder = backgroundsDir()
102
+ const tokenDirectory = join(dshHomeDir(), 'storages', 'session_projcache', 'sessions')
103
+ const handlers = createHandlers({
104
+ folder,
105
+ logger: ctx.logger,
106
+ tokenCacheMs: TOKEN_CACHE_MS,
107
+ tokenProvider: createTokenProvider(ctx, tokenDirectory),
108
+ trustedHosts: resolveTrustedHosts(ctx),
109
+ version: PACKAGE_VERSION
110
+ })
111
+ if (!existsSync(folder)) ctx.logger?.info?.(`chat-background: folder ${folder} will be created on first request`)
112
+ ctx.effect(
113
+ () => ctx.webServer.register({ kind: 'exact', path: LIST_PATH, handler: handlers.list }),
114
+ 'chat-background: background list route'
115
+ )
116
+ ctx.effect(
117
+ () => ctx.webServer.register({ kind: 'prefix', path: FILE_PREFIX, handler: handlers.file }),
118
+ 'chat-background: background image route'
119
+ )
120
+ ctx.effect(
121
+ () => ctx.webServer.register({ kind: 'exact', path: FOLDER_PATH, handler: handlers.revealFolder }),
122
+ 'chat-background: open folder route'
123
+ )
124
+ ctx.effect(
125
+ () => ctx.webServer.register({ kind: 'exact', path: TOKEN_PATH, handler: handlers.tokenTotal }),
126
+ 'chat-background: token total route'
127
+ )
128
+ ctx.effect(
129
+ () => ctx.webServer.register({ kind: 'exact', path: HEALTH_PATH, handler: handlers.health }),
130
+ 'chat-background: health route'
131
+ )
132
+ }
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Chat Background",
4
+ "description": "Background image, sidebar veil, composer strip, task progress bar and all-session token total for the DSH Web GUI."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "聊天背景",
4
+ "description": "背景图、侧栏柔化、输入栏下方背景条、任务进度条与全会话 token 总用量,为 DSH Web 界面提供可配置的视觉背景。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,90 @@
1
1
  {
2
2
  "name": "dsh-chat-background",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Chat background image, sidebar veil, composer strip, task progress bar and all-session token total for the DeepSeek Harness (DSH) Web GUI.",
5
+ "meta": {
6
+ "title": "聊天背景",
7
+ "description": "背景图、侧栏柔化、输入栏下方背景条、任务进度条与全会话 token 总用量"
8
+ },
9
+ "icon": "./icon.svg",
10
+ "author": "LittleLemonJam",
11
+ "license": "MIT",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/LittleLemonJam/dsh-chat-background.git"
15
+ },
16
+ "homepage": "https://github.com/LittleLemonJam/dsh-chat-background",
17
+ "bugs": {
18
+ "url": "https://github.com/LittleLemonJam/dsh-chat-background/issues"
19
+ },
20
+ "type": "module",
21
+ "main": "./index.js",
22
+ "exports": {
23
+ ".": "./index.js",
24
+ "./client": "./client.js",
25
+ "./icon": "./icon.svg",
26
+ "./package.json": "./package.json",
27
+ "./cordis.patch.yml": "./cordis.patch.yml",
28
+ "./locale/*.json": "./locale/*.json"
29
+ },
30
+ "files": [
31
+ "index.js",
32
+ "host/",
33
+ "client.js",
34
+ "cordis.patch.yml",
35
+ "locale/*.json",
36
+ "icon.svg",
37
+ "README.md",
38
+ "README.en.md",
39
+ "LICENSE",
40
+ "CHANGELOG.md",
41
+ "docs/",
42
+ "assets/screenshots/"
43
+ ],
44
+ "engines": {
45
+ "node": "^22.19.0 || >=24.0.0",
46
+ "dsh": ">=0.2.1-rc.3"
47
+ },
48
+ "keywords": [
49
+ "deepseek-harness",
50
+ "dsh",
51
+ "dsh-plugin",
52
+ "cordis",
53
+ "chat-background",
54
+ "background",
55
+ "wallpaper",
56
+ "theme",
57
+ "ui"
58
+ ],
59
+ "dsh": {
60
+ "manifestVersion": 1,
61
+ "bundle": {
62
+ "patch": "./cordis.patch.yml"
63
+ },
64
+ "client": {
65
+ "platform": "web",
66
+ "immediately": true,
67
+ "inject": [
68
+ "@deepseek-ai/dsh-client-ui-settings-general",
69
+ "@deepseek-ai/dsh-client-ui-conversation"
70
+ ]
71
+ }
72
+ },
73
+ "scripts": {
74
+ "build": "node scripts/build.mjs",
75
+ "format": "prettier --write .",
76
+ "format:check": "prettier --check .",
77
+ "check": "node scripts/check.mjs",
78
+ "check:install": "node scripts/check-install.mjs --profile desktop",
79
+ "test:unit": "node --test \"test/unit/*.test.mjs\"",
80
+ "test:e2e": "node scripts/e2e/run.mjs",
81
+ "test": "npm run build && npm run check && npm run test:unit",
82
+ "verify": "npm run format:check && npm test",
83
+ "prepack": "npm run build",
84
+ "cleanup:local": "node scripts/cleanup-local.mjs --profile desktop"
85
+ },
86
+ "devDependencies": {
87
+ "esbuild": "^0.28.2",
88
+ "prettier": "^3.9.10"
89
+ }
90
+ }