@goodandready/dsh-lanmode 0.2.0 → 0.3.1

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/README.md CHANGED
@@ -1,61 +1,105 @@
1
1
  # dsh-lanmode
2
2
 
3
- **Settings over the LAN** for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (dsh).
3
+ Open the [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) Web UI from another device — a phone, a tablet, the laptop on the other side of the room — and have **all of it** work, including the parts the UI switches off when the page is not `localhost`.
4
4
 
5
- Open the Web UI at `http://192.168.1.50:3080` instead of `http://localhost:3080` and every settings card in the deployment goes blank your plugins' cards, and **Settings → Plugins → Plugin configuration** with them. No error appears, the plugins load fine, and reloading does not help. Saving silently does nothing.
5
+ Works whether you put a reverse proxy in front of the harness or let this plugin serve the network itself. Pick a mode, restart, done.
6
6
 
7
- This plugin fixes that. Install it, reload the page, and the settings work from any address.
7
+ ## What breaks without it
8
+
9
+ Reach the UI at a LAN address and you get some mix of:
10
+
11
+ - **Settings → Models**: `settings are unavailable in this browser`
12
+ - **Settings → Plugins → Plugin configuration**: empty, no cards at all
13
+ - every plugin's settings card: blank, and saving silently does nothing
14
+ - on plain HTTP, nothing loads at all: sessions and models never render
15
+
16
+ None of that is the server refusing. The server serves settings over the network perfectly well.
8
17
 
9
18
  ## Why it happens
10
19
 
11
- The decision is made in the browser, from the page's hostname:
20
+ Two independent things.
21
+
22
+ **The settings service turns itself off.** The UI decides from the page's hostname:
12
23
 
13
24
  ```js
14
- isLoopback: pageLocation === undefined || isLoopbackHostname(pageLocation.hostname)
25
+ isLoopback: pageLocation === undefined || isLoopbackHostname(hostname)
15
26
  ```
16
27
 
17
- `isLoopbackHostname` accepts `localhost`, `[::1]` and `127.0.0.0/8` nothing else. A page served at a LAN address is therefore "remote", and the settings service switches to a process-local mode where the shared mirror of the settings document is never read at all:
28
+ `isLoopbackHostname` accepts `localhost`, `[::1]` and `127.0.0.0/8`, nothing else. Anything else puts the settings service into a process-local mode where the shared mirror of the settings document is never read, every namespace reports `status: "unavailable"` for the life of the page, and writes are dropped before they reach the wire.
18
29
 
19
- ```js
20
- ensure() { if (this.persistence === "memory") return Promise.resolve() }
21
- status: persistence === "host" ? "loading" : "unavailable"
22
- enqueue() { if (this.persistence === "memory") return Promise.resolve() }
30
+ **Some Web APIs only exist on a secure context.** `crypto.randomUUID` is called on boot-critical paths, and `navigator.clipboard` behind the copy buttons. Over plain HTTP from a LAN address the browser withholds both.
31
+
32
+ ## What the plugin does
33
+
34
+ Everything happens through the web server's official index tap: one script is injected into `index.html` ahead of the boot manifest. No product source is modified, and removing the plugin restores the page exactly.
35
+
36
+ | Piece | Setting | What it does |
37
+ |---|---|---|
38
+ | Settings | `settings` | Hands the two settings packages a connection whose `isLoopback` reads `true`. Everything downstream — the shared mirror, every namespace scope, the core's own pages — then behaves as it does on localhost. |
39
+ | `crypto.randomUUID` | `randomUuid` | Provides an RFC 4122 v4 implementation over `crypto.getRandomValues`, which insecure origins do have. A no-op where the real one exists. |
40
+ | `navigator.clipboard` | `clipboard` | Provides a `writeText` fallback so the copy buttons keep working. A no-op where the real one exists. |
41
+
42
+ The settings substitution is deliberately narrow. Three packages read that flag, and the third is deliverables, where it decides whether a produced file may be opened locally — forcing it there would ask the Host to open paths on the server's desktop. Only the settings packages see the substitute.
43
+
44
+ ## Two modes
45
+
46
+ ```yaml
47
+ - id: dsh-lanmode
48
+ config:
49
+ mode: proxy # proxy | direct
23
50
  ```
24
51
 
25
- Every bound namespace reports `status: "unavailable"` for the life of the page, and writes are dropped before they reach the wire.
52
+ **`proxy`** (default) something already listens on the network in front of the harness: nginx, Caddy, Tailscale serve, an SSH tunnel. The plugin only repairs the page and touches nothing else. This is the safe default: it cannot collide with whatever you already run.
26
53
 
27
- **The server does not share this restriction.** Both `settings.describe` and `settings.mutate` answer normally over the network as long as the request's `Origin` matches the page it came from — which is exactly the case for requests the UI itself makes. Verified against a live harness behind a reverse proxy.
54
+ **`direct`** no proxy anywhere. The plugin opens a listener of its own and forwards to the harness, rewriting `Host` and `Origin` to the loopback authority so the harness's same-origin fence is satisfied:
28
55
 
29
- ## What the plugin does
56
+ ```yaml
57
+ - id: dsh-lanmode
58
+ config:
59
+ mode: direct
60
+ directHost: '0.0.0.0' # every interface
61
+ directPort: 3088
62
+ ```
63
+
64
+ Then open `http://<the machine's IP>:3088` from any device on the network.
30
65
 
31
- It injects one script into the served `index.html`, through the web server's official index tap, ahead of the boot manifest. The script intercepts module registration and hands the two settings packages a connection whose `isLoopback` reads `true`. Everything downstream — the shared mirror of the settings document, every namespace scope, the core's own settings pages then behaves exactly as it does on localhost.
66
+ A listener rather than rebinding the harness itself, for two reasons: a bind host lives in the config tree and cannot be a switch inside the plugin, and rebinding to `0.0.0.0` collides with a reverse proxy already holding that port.
32
67
 
33
- The substitution is narrow on purpose. Three packages read that flag, and the third is deliverables, where it decides whether a produced file may be opened locally: forcing it there would ask the Host to open paths on the server's desktop. Only the settings packages see the substitute; the rest of the UI keeps the truth.
68
+ Changing the mode takes effect on restart.
34
69
 
35
- Taking the core settings service over instead is not possible — cordis refuses a second provider for a registered name, and refuses assignment across fibers.
70
+ ## Settings
71
+
72
+ All of it can be edited as the `dsh-lanmode` namespace — in `$DSH_HOME/settings.yaml`, or from the UI once the settings pages work.
73
+
74
+ | Setting | Default | Meaning |
75
+ |---|---|---|
76
+ | `mode` | `proxy` | `proxy` or `direct` |
77
+ | `directHost` | `0.0.0.0` | `direct`: which address to listen on |
78
+ | `directPort` | `3088` | `direct`: which port to listen on |
79
+ | `settings` | `true` | return the settings service |
80
+ | `randomUuid` | `true` | provide `crypto.randomUUID` on plain HTTP |
81
+ | `clipboard` | `true` | provide a clipboard fallback on plain HTTP |
36
82
 
37
83
  ## Checking it
38
84
 
39
- - `?lanmode=invert` — report the flag as `false` even on a loopback page. The harness then fails exactly the way it does over the LAN, which is how this plugin is verified.
40
- - `?lanmode=off` — stand the plugin down entirely.
85
+ - `?lanmode=invert` — report the loopback flag as `false` even on localhost. The harness then fails exactly the way it does over the LAN; this is how the plugin is verified.
86
+ - `?lanmode=off` — stand the plugin down entirely, to see the page as it would be without it.
41
87
 
42
88
  On a loopback page the plugin substitutes `true` where the real value is already `true`, so it cannot change behaviour there.
43
89
 
44
90
  ## What it is not
45
91
 
46
- Not authentication. The plugin does not add a password and does not widen what the server accepts — the harness answers those same calls with or without it. If your harness is reachable by other people, put a real gate in front of it (HTTP auth in your reverse proxy, or a VPN); a plugin cannot do that job, because the web server service hands plugins their own routes and no way to intercept anyone else's.
92
+ **Not authentication.** It adds no password and does not widen what the server accepts — the harness answers those same calls with or without it. `direct` mode does make the harness reachable by anyone who can reach that port, exactly as a reverse proxy would. If other people share your network, put a real gate in front of the harness. A plugin cannot do that job: the web server hands plugins their own routes and no way to intercept anyone else's.
47
93
 
48
- ## Structure
94
+ **No microphone over plain HTTP.** Browsers withhold `navigator.mediaDevices` outside a secure context, so voice input plugins stop working on a plain-HTTP LAN address. Nothing can polyfill that. If you need the microphone, keep HTTPS in front and use `proxy` mode.
49
95
 
96
+ ## Install
97
+
98
+ ```bash
99
+ dsh plugin --profile web add @goodandready/dsh-lanmode
50
100
  ```
51
- dsh-lanmode/
52
- ├── package.json # dsh bundle/plugin metadata
53
- ├── cordis.patch.yml # bundle layer: inserts the plugin row
54
- ├── lib/index.js # host: nothing but a log line — the work is in the browser
55
- ├── lib/client.js # browser: the settings mirror and namespace scopes
56
- ├── README.md
57
- └── LICENSE # MIT
58
- ```
101
+
102
+ Restart the harness, then reload the browser.
59
103
 
60
104
  ## License
61
105
 
package/cordis.patch.yml CHANGED
@@ -1,10 +1,22 @@
1
1
  # dsh-lanmode bundle layer: applied automatically when the package is installed
2
2
  # as a profile bundle (package.json declares dsh.bundle.patch).
3
3
  #
4
- # `name` must stay the full npm package name: the client-modules registry
5
- # resolves the browser bundle by the loader entry name, so a shortened name
6
- # leaves the UI half silently out of window.__DSH_BOOT__ — and the UI half is
7
- # the whole plugin here.
4
+ # `name` must stay the full npm package name: the loader entry name is how the
5
+ # served bundle is resolved.
6
+ #
7
+ # Everything is configurable in the `dsh-lanmode` settings namespace, so the
8
+ # row below stays empty. To pin the mode in the tree instead of the settings
9
+ # document, override it in your own profile patch:
10
+ #
11
+ # - id: dsh-lanmode
12
+ # config:
13
+ # mode: direct
14
+ # directPort: 3088
15
+ #
16
+ # Note there is deliberately no webserver override here: a bind host lives in
17
+ # the config tree, so it cannot be switched from inside a plugin, and it
18
+ # collides with a reverse proxy already holding the port. Direct mode opens a
19
+ # listener of its own instead.
8
20
  - insert:
9
21
  - id: dsh-lanmode
10
22
  name: '@goodandready/dsh-lanmode'
package/lib/bridge.js ADDED
@@ -0,0 +1,92 @@
1
+ // Прямой режим: слушатель на сетевом адресе, который передаёт всё харнессу.
2
+ //
3
+ // Зачем не привязка харнесса к 0.0.0.0, как делают соседние плагины. Привязка
4
+ // задаётся в дереве конфигурации и меняется только перезапуском, то есть
5
+ // «переключателем в плагине» быть не может. Хуже того, если перед харнессом
6
+ // уже стоит обратный прокси на том же порту, привязка столкнётся с ним лбами.
7
+ // Отдельный слушатель включается и гасится вместе со строкой плагина и живёт
8
+ // рядом с любым прокси.
9
+ //
10
+ // Заголовки Host и Origin переписываются на локальные: харнесс пропускает
11
+ // запрос, только когда Origin совпадает с адресом, по которому он слушает.
12
+ // Это ровно то, что делает любой обратный прокси, и это же означает, что
13
+ // прямой режим открывает харнесс всем, кто дотянется до этого порта, — как и
14
+ // nginx сегодня. Пароля здесь нет и быть не может: плагин чужие маршруты не
15
+ // перехватывает.
16
+
17
+ import http from 'node:http'
18
+
19
+ function rewritten(headers, authority) {
20
+ const out = { ...headers, host: authority }
21
+ if (out.origin) out.origin = 'http://' + authority
22
+ if (out.referer) out.referer = String(out.referer).replace(/^https?:\/\/[^/]+/, 'http://' + authority)
23
+ return out
24
+ }
25
+
26
+ /**
27
+ * @param ctx контекст плагина (нужен ctx.webServer.port)
28
+ * @param options {{host: string, port: number, log: (message: string) => void}}
29
+ * @returns функция остановки
30
+ */
31
+ export function startDirectBridge(ctx, options) {
32
+ const upstreamPort = ctx.webServer.port
33
+ if (!upstreamPort) {
34
+ options.log('прямой режим не поднят: веб-сервер ещё не сообщил порт')
35
+ return () => {}
36
+ }
37
+ const authority = '127.0.0.1:' + upstreamPort
38
+
39
+ const bridge = http.createServer((req, res) => {
40
+ const upstream = http.request({
41
+ host: '127.0.0.1',
42
+ port: upstreamPort,
43
+ method: req.method,
44
+ path: req.url,
45
+ headers: rewritten(req.headers, authority),
46
+ }, (answer) => {
47
+ res.writeHead(answer.statusCode || 502, answer.headers)
48
+ answer.pipe(res)
49
+ })
50
+ upstream.on('error', () => {
51
+ if (!res.headersSent) res.writeHead(502, { 'content-type': 'text/plain; charset=utf-8' })
52
+ res.end('dsh-lanmode: харнесс не отвечает')
53
+ })
54
+ req.pipe(upstream)
55
+ })
56
+
57
+ // Веб-сокеты интерфейса идут через Upgrade: их надо передать сырыми.
58
+ bridge.on('upgrade', (req, socket, head) => {
59
+ const upstream = http.request({
60
+ host: '127.0.0.1',
61
+ port: upstreamPort,
62
+ method: req.method,
63
+ path: req.url,
64
+ headers: rewritten(req.headers, authority),
65
+ })
66
+ upstream.on('upgrade', (answer, upstreamSocket, upstreamHead) => {
67
+ const lines = ['HTTP/1.1 101 Switching Protocols']
68
+ for (const [key, value] of Object.entries(answer.headers)) lines.push(key + ': ' + value)
69
+ socket.write(lines.join('\r\n') + '\r\n\r\n')
70
+ if (upstreamHead && upstreamHead.length) socket.unshift(upstreamHead)
71
+ upstreamSocket.pipe(socket)
72
+ socket.pipe(upstreamSocket)
73
+ const drop = () => { try { upstreamSocket.destroy() } catch (already) { /* уже мертво */ } }
74
+ socket.on('error', drop)
75
+ socket.on('close', drop)
76
+ })
77
+ upstream.on('error', () => { try { socket.destroy() } catch (already) { /* уже мертво */ } })
78
+ if (head && head.length) upstream.write(head)
79
+ upstream.end()
80
+ })
81
+
82
+ bridge.on('error', (failure) => {
83
+ options.log('прямой режим не поднялся: ' + String(failure && failure.message || failure))
84
+ })
85
+
86
+ bridge.listen(options.port, options.host, () => {
87
+ options.log('прямой режим: слушаю ' + options.host + ':' + options.port
88
+ + ', передаю на ' + authority)
89
+ })
90
+
91
+ return () => { bridge.close() }
92
+ }
package/lib/index.js CHANGED
@@ -1,50 +1,138 @@
1
1
  // dsh-lanmode — хост-половина.
2
2
  //
3
- // Задача плагина: вернуть настройки на страницах, открытых не с localhost.
3
+ // Плагин возвращает веб-интерфейсу то, что он сам себе запрещает на странице,
4
+ // открытой не с localhost. Три независимых куска, каждый выключается отдельно.
4
5
  //
5
- // Веб-интерфейс решает это в браузере, по имени хоста страницы:
6
+ // 1. Настройки. Интерфейс решает по имени хоста страницы:
6
7
  //
7
- // isLoopback: pageLocation === undefined || isLoopbackHostname(hostname)
8
+ // isLoopback: pageLocation === undefined || isLoopbackHostname(hostname)
8
9
  //
9
- // где своими считаются только localhost, [::1] и 127.0.0.0/8. Дальше сервис
10
- // настроек уходит в режим «памяти»: общий вид документа не читается никогда,
11
- // каждый раздел получает статус "unavailable", запись выбрасывается до
12
- // отправки. Внешне пустые карточки всех плагинов, пустая вкладка «Настройки
13
- // плагинов» и страница «Модели» с надписью
14
- // "settings are unavailable in this browser".
10
+ // и своими считает только localhost, [::1] и 127.0.0.0/8. Дальше сервис
11
+ // настроек уходит в режим «памяти»: общий вид документа не читается никогда,
12
+ // каждый раздел получает статус "unavailable", запись выбрасывается до
13
+ // отправки. Наружу это выглядит как пустые карточки всех плагинов, пустая
14
+ // вкладка «Настройки плагинов» и страница «Модели» с надписью
15
+ // "settings are unavailable in this browser". Сервер это ограничение не
16
+ // разделяет: describe и mutate по сети отвечают штатно.
15
17
  //
16
- // Сервер это ограничение не разделяет: settings.describe и settings.mutate по
17
- // сети отвечают штатно, когда Origin совпадает с адресом страницы, то есть
18
- // ровно в том случае, когда запрос шлёт сам интерфейс.
18
+ // 2. crypto.randomUUID. Существует только на защищённом соединении, а
19
+ // интерфейс зовёт его на пути загрузки. На чистом HTTP по сетевому адресу
20
+ // его нет, и каждый вызов к серверу падает.
19
21
  //
20
- // Поэтому плагин вставляет в index.html короткий скрипт (через официальную
21
- // точку webServer.tapIndex) и подменяет флаг ТОЧЕЧНО — только для двух
22
- // настроечных пакетов ядра. Флаг читают трое, и третьему подменять нельзя:
23
- // в результатах работы isLoopback решает, можно ли открыть файл локально, и
24
- // с подменой браузер просил бы открыть путь на машине сервера.
22
+ // 3. navigator.clipboard. Тоже только для защищённого соединения без него
23
+ // кнопки «Копировать» молчат. Подставляем запасной путь.
24
+ //
25
+ // Всё это вставляется в index.html через официальную точку webServer.tapIndex.
26
+ //
27
+ // Привязки харнесса к 0.0.0.0 здесь намеренно нет: она задаётся в дереве
28
+ // конфигурации, переключателем быть не может и сталкивается с обратным
29
+ // прокси на том же порту. Вместо неё — прямой режим со своим слушателем.
25
30
 
31
+ import z from '@deepseek-ai/schemastery'
26
32
  import { readFileSync } from 'node:fs'
27
33
  import path from 'node:path'
28
34
  import { fileURLToPath } from 'node:url'
35
+ import { startDirectBridge } from './bridge.js'
29
36
 
30
37
  export const name = 'dsh-lanmode'
31
38
  export const inject = ['webServer']
32
39
 
40
+ export const Config = z.object({
41
+ mode: z
42
+ .string()
43
+ .description('How the browser reaches the harness. '
44
+ + '"proxy": something in front of it already listens on the network (nginx and friends) — '
45
+ + 'the plugin only repairs the page. '
46
+ + '"direct": the plugin also opens a listener of its own on the network and forwards to the '
47
+ + 'harness, so nothing else is needed.')
48
+ .default('proxy'),
49
+ directHost: z
50
+ .string()
51
+ .description('mode=direct: which address to listen on. 0.0.0.0 means every interface.')
52
+ .default('0.0.0.0'),
53
+ directPort: z
54
+ .number()
55
+ .description('mode=direct: which port to listen on. Keep it clear of whatever else is running.')
56
+ .default(3088),
57
+ settings: z
58
+ .boolean()
59
+ .description('Return the settings service on pages that are not localhost. '
60
+ + 'This is the part no other plugin does.')
61
+ .default(true),
62
+ randomUuid: z
63
+ .boolean()
64
+ .description('Provide crypto.randomUUID where the browser withholds it (plain HTTP). '
65
+ + 'A no-op on HTTPS and on localhost.')
66
+ .default(true),
67
+ clipboard: z
68
+ .boolean()
69
+ .description('Provide a fallback for navigator.clipboard.writeText on plain HTTP, '
70
+ + 'so the copy buttons keep working. A no-op where the real one exists.')
71
+ .default(true),
72
+ })
73
+
33
74
  const here = path.dirname(fileURLToPath(import.meta.url))
34
75
 
35
- /** Скрипт-заплатка читается с диска: так его видно и правится он как код. */
76
+ /** Заплатка лежит рядом обычным файлом: так её видно и правится она как код. */
36
77
  function shimSource() {
37
78
  return readFileSync(path.join(here, 'shim.js'), 'utf8')
38
79
  }
39
80
 
40
- export function apply(ctx) {
41
- const script = '<script data-dsh-lanmode="1">' + shimSource() + '</script>'
81
+ /** Namespace, который плагин объявляет: через него режим правится настройками. */
82
+ const NS = 'dsh-lanmode'
83
+
84
+ export function apply(ctx, config) {
85
+ // Значения берём из сервиса настроек, если он есть: тогда режим правится
86
+ // в настройках, а не только в дереве плагинов. Смена режима требует
87
+ // перезапуска — слушатель поднимается один раз при старте.
88
+ ctx.inject(['settings'], (sctx) => {
89
+ let effective = config
90
+ try {
91
+ const scope = sctx.settings.register(NS, Config, { base: config })
92
+ effective = scope.get() ?? config
93
+ } catch (alreadyRegistered) {
94
+ effective = config
95
+ }
96
+ start(sctx, effective)
97
+ })
98
+
99
+ // Без сервиса настроек тоже должно работать — тогда только дерево плагинов.
100
+ ctx.effect(() => {
101
+ if (ctx.get && ctx.get('settings')) return () => {}
102
+ start(ctx, config)
103
+ return () => {}
104
+ }, 'dsh-lanmode: запуск без сервиса настроек')
105
+ }
106
+
107
+ function start(ctx, config) {
108
+ // Прямой режим: свой слушатель на сетевом адресе. В режиме прокси не
109
+ // поднимаем ничего — сеть уже обслуживает кто-то другой.
110
+ if (config.mode === 'direct') {
111
+ ctx.effect(() => startDirectBridge(ctx, {
112
+ host: config.directHost || '0.0.0.0',
113
+ port: config.directPort || 3088,
114
+ // eslint-disable-next-line no-console
115
+ log: (message) => console.info('[dsh-lanmode] ' + message),
116
+ }), 'dsh-lanmode: слушатель прямого режима')
117
+ }
118
+
119
+ const pieces = {
120
+ settings: config.settings !== false,
121
+ randomUuid: config.randomUuid !== false,
122
+ clipboard: config.clipboard !== false,
123
+ }
124
+ // Ничего не включено — и вставлять нечего.
125
+ if (!pieces.settings && !pieces.randomUuid && !pieces.clipboard) return
126
+
127
+ const script = '<script data-dsh-lanmode="1">'
128
+ + 'window.__DSH_LANMODE__=' + JSON.stringify(pieces) + ';'
129
+ + shimSource()
130
+ + '</script>'
42
131
 
43
132
  ctx.effect(() => ctx.webServer.tapIndex((html) => {
44
133
  if (html.includes('data-dsh-lanmode')) return html
45
- // Сразу за <head>: к моменту, когда страница начнёт грузить бандлы,
46
- // перехватчик уже стоит. Загрузчик к этому моменту может ещё не
47
- // существовать — заплатка это учитывает.
134
+ // Сразу за <head>: заплатка должна отработать раньше всего остального,
135
+ // иначе заглушка приедет после первого же вызова, который её ждёт.
48
136
  const at = html.indexOf('<head>')
49
137
  if (at === -1) return script + html
50
138
  return html.slice(0, at + '<head>'.length) + script + html.slice(at + '<head>'.length)
package/lib/shim.js CHANGED
@@ -1,29 +1,85 @@
1
1
  (function () {
2
- // Заплатка выполняется в самом начале страницы, до загрузки бандлов ядра.
2
+ // Заплатка выполняется первой на странице, до загрузки чего бы то ни было.
3
+ // Что включено — решает хост-половина, значения приезжают в __DSH_LANMODE__.
4
+ var options = window.__DSH_LANMODE__ || {}
5
+
6
+ // Отладочные переключатели в адресной строке:
7
+ // ?lanmode=off — не вмешиваться совсем (посмотреть, как без плагина);
8
+ // ?lanmode=invert — притвориться чужой страницей на своей же
9
+ // (так проверяется, что заплатка правда управляет флагом).
10
+ var mode = ''
11
+ try { mode = new URLSearchParams(location.search).get('lanmode') || '' } catch (noSearch) { mode = '' }
12
+ if (mode === 'off') return
13
+ var loopbackAnswer = mode !== 'invert'
14
+
15
+ // ------------------------------------------------------- crypto.randomUUID
3
16
  //
4
- // Она перехватывает регистрацию двух настроечных пакетов и подсовывает им
5
- // связь, у которой isLoopback всегда true. Остальные пакеты видят правду:
6
- // в результатах работы этот же флаг решает, открывать ли файл локально, и
7
- // подменять его там нельзя.
17
+ // Существует только на защищённом соединении, а интерфейс зовёт его при
18
+ // загрузке: на чистом HTTP по сетевому адресу без этого не поднимается
19
+ // вообще ничего.
20
+ if (options.randomUuid) {
21
+ var crypto_ = globalThis.crypto
22
+ if (!crypto_) { try { crypto_ = globalThis.crypto = {} } catch (frozen) { crypto_ = null } }
23
+ if (crypto_ && typeof crypto_.randomUUID !== 'function' && typeof crypto_.getRandomValues === 'function') {
24
+ crypto_.randomUUID = function randomUUID() {
25
+ var bytes = new Uint8Array(16)
26
+ crypto_.getRandomValues(bytes)
27
+ bytes[6] = (bytes[6] & 15) | 64
28
+ bytes[8] = (bytes[8] & 63) | 128
29
+ var hex = ''
30
+ for (var i = 0; i < 16; i++) hex += bytes[i].toString(16).padStart(2, '0')
31
+ return hex.slice(0, 8) + '-' + hex.slice(8, 12) + '-' + hex.slice(12, 16)
32
+ + '-' + hex.slice(16, 20) + '-' + hex.slice(20)
33
+ }
34
+ }
35
+ }
36
+
37
+ // ------------------------------------------------------ navigator.clipboard
38
+ //
39
+ // Тоже только для защищённого соединения. Без него кнопки «Копировать»
40
+ // молча ничего не делают; подставляем старый способ через скрытое поле.
41
+ if (options.clipboard) {
42
+ var nav = window.navigator
43
+ if (nav && (!nav.clipboard || typeof nav.clipboard.writeText !== 'function')) {
44
+ var writeText = function (text) {
45
+ return new Promise(function (resolve, reject) {
46
+ try {
47
+ var area = document.createElement('textarea')
48
+ area.value = String(text)
49
+ area.setAttribute('readonly', '')
50
+ area.style.position = 'fixed'
51
+ area.style.opacity = '0'
52
+ document.body.appendChild(area)
53
+ area.select()
54
+ var copied = document.execCommand('copy')
55
+ document.body.removeChild(area)
56
+ copied ? resolve() : reject(new Error('copy rejected'))
57
+ } catch (failure) { reject(failure) }
58
+ })
59
+ }
60
+ try {
61
+ if (nav.clipboard) nav.clipboard.writeText = writeText
62
+ else Object.defineProperty(nav, 'clipboard', { configurable: true, value: { writeText: writeText } })
63
+ } catch (cannotDefine) { /* останется как было */ }
64
+ }
65
+ }
66
+
67
+ // ------------------------------------------------------------- настройки
68
+ if (!options.settings) return
69
+
70
+ // Флаг читают трое, и третьему подменять нельзя: в результатах работы он
71
+ // решает, можно ли открыть файл локально, и с подменой браузер просил бы
72
+ // открыть путь на машине сервера. Поэтому — только два настроечных пакета.
8
73
  var TARGETS = [
9
74
  '@deepseek-ai/dsh-client-ui-settings',
10
75
  '@deepseek-ai/dsh-client-ui-settings-general',
11
76
  ]
12
77
 
13
- // Отладочные переключатели через адресную строку:
14
- // ?lanmode=off — не вмешиваться (проверить, как было без плагина);
15
- // ?lanmode=invert — притвориться чужим на своей же странице
16
- // (так проверяется, что заплатка вообще управляет флагом).
17
- var mode = ''
18
- try { mode = new URLSearchParams(location.search).get('lanmode') || '' } catch (noSearch) { mode = '' }
19
- if (mode === 'off') return
20
- var forced = mode === 'invert' ? false : true
21
-
22
78
  function connectionWithForcedFlag(connection) {
23
79
  if (!connection || typeof connection !== 'object') return connection
24
80
  return new Proxy(connection, {
25
- get: function (target, prop, receiver) {
26
- if (prop === 'isLoopback') return forced
81
+ get: function (target, prop) {
82
+ if (prop === 'isLoopback') return loopbackAnswer
27
83
  var value = Reflect.get(target, prop, target)
28
84
  return typeof value === 'function' ? value.bind(target) : value
29
85
  },
@@ -32,7 +88,7 @@
32
88
 
33
89
  function ctxWithForcedConnection(ctx) {
34
90
  return new Proxy(ctx, {
35
- get: function (target, prop, receiver) {
91
+ get: function (target, prop) {
36
92
  if (prop === 'get') {
37
93
  return function (nameRequested) {
38
94
  var value = target.get(nameRequested)
@@ -64,11 +120,12 @@
64
120
  return patched
65
121
  }
66
122
 
67
- // Загрузчик подменяет собственный load, когда переходит из режима очереди
68
- // в рабочий, — обёртка при этом слетала бы. Поэтому ставим её через
123
+ // Загрузчик подменяет собственный load, когда переходит из режима очереди в
124
+ // рабочий, — обёртка при этом слетала бы. Поэтому ставим её через
69
125
  // свойство-аксессор: любая новая функция оборачивается снова.
70
126
  function install(loader) {
71
127
  if (!loader || typeof loader !== 'object') return loader
128
+ if (loader.load && loader.load.__dshLanmode) return loader
72
129
  var wrapped
73
130
 
74
131
  function rewrap(fn) {
@@ -78,7 +135,6 @@
78
135
  wrapped.__dshLanmode = true
79
136
  }
80
137
 
81
- if (loader.load && loader.load.__dshLanmode) return loader
82
138
  rewrap(loader.load)
83
139
  try {
84
140
  Object.defineProperty(loader, 'load', {
@@ -96,15 +152,9 @@
96
152
  loader.pendingQueue[i] = wrap(loader.pendingQueue[i])
97
153
  }
98
154
  }
99
- try {
100
- console.info('[dsh-lanmode] настройки будут работать на этой странице'
101
- + (forced ? '' : ' (перевёрнутый режим: притворяемся чужим)'))
102
- } catch (noConsole) { /* незачем */ }
103
155
  return loader
104
156
  }
105
157
 
106
- // Загрузчик объявляется встроенным скриптом страницы. Если он уже есть —
107
- // оборачиваем сразу; если нет — дожидаемся присваивания.
108
158
  if (window.__ModuleLoader__) {
109
159
  install(window.__ModuleLoader__)
110
160
  return
@@ -117,7 +167,7 @@
117
167
  set: function (value) { held = install(value) },
118
168
  })
119
169
  } catch (cannotDefine) {
120
- // Свойство неподатливо — молчим: без заплатки страница остаётся такой же,
121
- // какой была без плагина.
170
+ // Свойство неподатливо — молчим: страница останется такой же, какой была
171
+ // без плагина.
122
172
  }
123
173
  })()
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-lanmode",
3
- "version": "0.2.0",
4
- "description": "Settings over the LAN for DeepSeek Harness: the Web UI turns its settings service off on any page that is not localhost, even though the server serves settings over the network fine. This plugin taps the served index.html and hands the two settings packages a connection that reports loopback, so every settings surface works from any address.",
3
+ "version": "0.3.1",
4
+ "description": "LAN and reverse-proxy access for the DeepSeek Harness Web UI: returns the settings service on pages that are not localhost, fills in the Web APIs the browser withholds on plain HTTP, and can open a listener of its own so nothing else is needed.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "./lib/index.js",
@@ -22,7 +22,9 @@
22
22
  "deepseek-harness",
23
23
  "settings",
24
24
  "lan",
25
- "remote"
25
+ "remote",
26
+ "proxy",
27
+ "nginx"
26
28
  ],
27
29
  "repository": {
28
30
  "type": "git",