@lincyaw/studio 0.2.0-rc.3 → 0.2.0-rc.30
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 +5 -5
- package/package.json +4 -4
- package/src/cli.ts +4 -1
- package/src/messages.ts +11 -6
- package/src/proxy.ts +62 -0
- package/src/studio.ts +85 -14
package/README.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
# @lincyaw/studio
|
|
2
2
|
|
|
3
|
-
`presmium studio`: Presmium's workbench in one command. It starts [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (MIT) with Presmium's bundle, [`@lincyaw/dsh`](https://www.npmjs.com/package/@lincyaw/dsh), and the workspace service of a directory (`presmium serve`, from
|
|
3
|
+
`presmium studio`: Presmium's workbench in one command. It starts [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (MIT) with Presmium's bundle, [`@lincyaw/dsh`](https://www.npmjs.com/package/@lincyaw/dsh), and the workspace service of a directory (`presmium serve`, from its host package `@lincyaw/presmium`), and prints the one address to open in the browser. Experimental (0.x): it installs one exact version of DeepSeek Harness, `0.2.1-alpha.4` (about 865 MB with its dependencies).
|
|
4
4
|
|
|
5
5
|
Part of [Presmium](https://github.com/Lincyaw/presmium), which turns structured teaching documents into web pages, slides, Jupyter notebooks and narrated lectures.
|
|
6
6
|
|
|
7
7
|
## Usage
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
pnpm add -g @lincyaw/
|
|
11
|
-
presmium
|
|
10
|
+
pnpm add -g @lincyaw/presmium
|
|
11
|
+
presmium studio [dir] [--port <n>] [--host <addr>]
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
In a project with `pnpm add -D @lincyaw/
|
|
14
|
+
Studio is included with Presmium. In a project with `pnpm add -D @lincyaw/presmium`, use `pnpm exec presmium studio`. The separate `presmium-studio` command remains available when this package is installed directly; it runs the `presmium` command on PATH (install it with `pnpm add -g @lincyaw/presmium`).
|
|
15
15
|
|
|
16
|
-
`dir` is a workspace root (`presmium.workspace.yaml`) or a deck's directory, as for `presmium serve`. The workbench listens on 127.0.0.1, port 4320 by default (a free port when that one is in use); `--host <addr>` makes it listen on one address
|
|
16
|
+
`dir` is a workspace root (`presmium.workspace.yaml`) or a deck's directory, as for `presmium serve`. The workbench listens on 127.0.0.1, port 4320 by default (a free port when that one is in use); `--host <addr>` makes it listen on one local IP address, and `--host 0.0.0.0` makes it listen on all local IPv4 network interfaces, with no login. Network access prints one address for each local network interface.
|
|
17
17
|
|
|
18
18
|
Sessions use the workspace root as their working directory and can read and write files throughout it. Opening another lecture changes document context, not the session or its directory.
|
|
19
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/studio",
|
|
3
|
-
"version": "0.2.0-rc.
|
|
3
|
+
"version": "0.2.0-rc.30",
|
|
4
4
|
"description": "presmium studio: Presmium's workbench on DeepSeek Harness in one command, with the workspace service of a directory (experimental)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@deepseek-ai/dsh": "0.2.1-alpha.4",
|
|
40
|
+
"http-proxy-3": "2.0.1",
|
|
40
41
|
"jiti": "^2.7.0",
|
|
41
|
-
"@lincyaw/
|
|
42
|
-
"@lincyaw/dsh": "0.2.0-rc.3"
|
|
42
|
+
"@lincyaw/dsh": "0.2.0-rc.30"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@lincyaw/cli": "1.0.0-rc.
|
|
45
|
+
"@lincyaw/cli": "1.0.0-rc.31"
|
|
46
46
|
}
|
|
47
47
|
}
|
package/src/cli.ts
CHANGED
|
@@ -61,9 +61,12 @@ export async function main(argv: string[], options: MainOptions = {}): Promise<n
|
|
|
61
61
|
return 2
|
|
62
62
|
}
|
|
63
63
|
process.stdout.write(`studio ${studio.url}\n`)
|
|
64
|
+
for (const url of studio.networkUrls) process.stdout.write(`network ${url}\n`)
|
|
64
65
|
process.stderr.write(`${t.log(studio.log)}\n`)
|
|
65
66
|
if (values.host && values.host !== '127.0.0.1' && values.host !== '::1' && !values['public-url']) {
|
|
66
|
-
process.stderr.write(`${
|
|
67
|
+
process.stderr.write(`${studio.networkUrls.length
|
|
68
|
+
? t.openOnAllNetworks(new URL(studio.url).port, new URL(studio.workspaceServerUrl).port)
|
|
69
|
+
: t.openOnNetwork(values.host, new URL(studio.url).port, new URL(studio.workspaceServerUrl).port)}\n`)
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
const signals = ['SIGINT', 'SIGTERM', 'SIGHUP'] as const
|
package/src/messages.ts
CHANGED
|
@@ -10,6 +10,7 @@ export interface StudioMessages {
|
|
|
10
10
|
notDirectory(dir: string): string
|
|
11
11
|
log(file: string): string
|
|
12
12
|
openOnNetwork(address: string, port: string, previewPort: string): string
|
|
13
|
+
openOnAllNetworks(port: string, previewPort: string): string
|
|
13
14
|
ended(how: string, log: string): string
|
|
14
15
|
portInUse(port: number, address: string): string
|
|
15
16
|
noFreePort(address: string): string
|
|
@@ -18,6 +19,7 @@ export interface StudioMessages {
|
|
|
18
19
|
serviceEnded: string
|
|
19
20
|
appEnded: string
|
|
20
21
|
modelVariables(variables: readonly string[], unset: string[]): string
|
|
22
|
+
presmiumMissing: string
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export const STUDIO_MESSAGES: Record<Locale, StudioMessages> = {
|
|
@@ -32,7 +34,7 @@ presmium-studio-<散列>.log(每个安装一个)保存在 $XDG_STATE_HOME/pr
|
|
|
32
34
|
|
|
33
35
|
选项:
|
|
34
36
|
--port <端口> Presmium Studio 的端口(默认为 4320,被占用时取空闲端口)
|
|
35
|
-
--host <地址>
|
|
37
|
+
--host <地址> 改为监听本机在局域网中的一个 IP 地址或 0.0.0.0,且没有登录:
|
|
36
38
|
任何能访问这个端口的人都以你的身份操作
|
|
37
39
|
--public-url <网址> 有反向代理在前面时浏览器打开的根地址(例如 Presmium 云端);
|
|
38
40
|
它的主机受信任,打印的网址用它。代理需保留 Host 并转发 WebSocket
|
|
@@ -42,14 +44,16 @@ presmium-studio-<散列>.log(每个安装一个)保存在 $XDG_STATE_HOME/pr
|
|
|
42
44
|
-h, --help 显示本说明`,
|
|
43
45
|
badPort: value => `--port 需要 0 到 65535 之间的端口号,而不是“${value}”。`,
|
|
44
46
|
badUrl: (option, value) => `${option} 需要一个完整的网址,例如 https://studio.example.com/,而不是“${value}”。`,
|
|
47
|
+
presmiumMissing: 'presmium-studio 找不到 presmium 命令。Presmium Studio 随 Presmium 一起安装:请运行 pnpm add -g @lincyaw/presmium,然后用 presmium studio 启动。',
|
|
45
48
|
unexpectedArgument: argument => `多余的参数“${argument}”。只能给出一个目录。`,
|
|
46
49
|
notDirectory: dir => `${dir} 不是目录。请给出工作区的根目录或一份文稿所在的目录。`,
|
|
47
50
|
log: file => `presmium studio: 日志在 ${file}`,
|
|
48
51
|
openOnNetwork: (address, port, previewPort) => `presmium studio: 正在 ${address} 上监听,局域网中的设备可以访问,且没有登录:任何能用上面的网址访问端口 ${port}(以及预览的端口 ${previewPort})的人都以你的身份使用这个工作区(编辑、运行代码、使用你的模型)。请只在可信的网络中使用;不加 --host 时只在本机监听。`,
|
|
52
|
+
openOnAllNetworks: (port, previewPort) => `presmium studio: 正在全部局域网网络接口上监听,且没有登录:任何能用上面的网址访问端口 ${port}(以及预览的端口 ${previewPort})的人都以你的身份使用这个工作区(编辑、运行代码、使用你的模型)。请只在可信的网络中使用;不加 --host 时只在本机监听。`,
|
|
49
53
|
ended: (how, log) => `presmium studio: ${how}。日志在 ${log}`,
|
|
50
54
|
portInUse: (port, address) => `${address} 的端口 ${port} 已被占用。请用 --port 指定另一个端口。`,
|
|
51
55
|
noFreePort: address => `${address} 上没有空闲的端口。请停止占用端口的服务后重试。`,
|
|
52
|
-
badHost: address => `--host
|
|
56
|
+
badHost: address => `--host 需要本机的一个 IP 地址,例如 192.168.0.21,也可以使用 0.0.0.0,而不是“${address}”。`,
|
|
53
57
|
wholeLog: (message, file) => `${message}${message.endsWith('\n') ? '' : '。'}完整的日志在 ${file}`,
|
|
54
58
|
serviceEnded: '工作区服务(presmium serve)已停止',
|
|
55
59
|
appEnded: 'Presmium Studio 的应用进程已停止',
|
|
@@ -67,8 +71,8 @@ presmium-studio-<hash>.log (one per installation) are kept in $XDG_STATE_HOME/pr
|
|
|
67
71
|
|
|
68
72
|
Options:
|
|
69
73
|
--port <n> Presmium Studio’s port (default: 4320, or a free one when that is in use)
|
|
70
|
-
--host <addr> listen on
|
|
71
|
-
no login: whoever reaches the port works as you
|
|
74
|
+
--host <addr> listen on one local IP address, or on all IPv4 network interfaces with 0.0.0.0,
|
|
75
|
+
with no login: whoever reaches the port works as you
|
|
72
76
|
--public-url <url> the root browsers open when a reverse proxy fronts Studio (as in Presmium
|
|
73
77
|
Cloud): its host is trusted, and the printed address uses it. The proxy keeps Host and
|
|
74
78
|
forwards WebSockets
|
|
@@ -79,18 +83,19 @@ Options:
|
|
|
79
83
|
-h, --help show this help`,
|
|
80
84
|
badPort: value => `--port takes a port number from 0 to 65535, not “${value}”.`,
|
|
81
85
|
badUrl: (option, value) => `${option} takes a full address, such as https://studio.example.com/, not “${value}”.`,
|
|
86
|
+
presmiumMissing: 'presmium-studio can’t find the presmium command. Presmium Studio comes with Presmium: run pnpm add -g @lincyaw/presmium, then start it with presmium studio.',
|
|
82
87
|
unexpectedArgument: argument => `Unexpected argument “${argument}”. Give one directory.`,
|
|
83
88
|
notDirectory: dir => `${dir} is not a directory. Give the workspace root, or the directory of a document.`,
|
|
84
89
|
log: file => `presmium studio: log ${file}`,
|
|
85
90
|
openOnNetwork: (address, port, previewPort) => `presmium studio: listening on ${address}, on the local network, with no login: anyone who reaches port ${port} (and the previews’ port ${previewPort}) with the address above works in this workspace as you (edits, runs code, uses your model). Use it on a network you trust; without --host it listens on this machine only.`,
|
|
91
|
+
openOnAllNetworks: (port, previewPort) => `presmium studio: listening on all local network interfaces, with no login: anyone who reaches port ${port} (and the previews’ port ${previewPort}) with the addresses above works in this workspace as you (edits, runs code, uses your model). Use it on a network you trust; without --host it listens on this machine only.`,
|
|
86
92
|
ended: (how, log) => `presmium studio: ${how}; the log is ${log}`,
|
|
87
93
|
portInUse: (port, address) => `Port ${port} of ${address} is in use. Give another with --port.`,
|
|
88
94
|
noFreePort: address => `There is no free port on ${address}. Stop a service that uses one, then retry.`,
|
|
89
|
-
badHost: address => `--host takes one
|
|
95
|
+
badHost: address => `--host takes one local IP address, such as 192.168.0.21, or 0.0.0.0 to listen on all IPv4 network interfaces, not “${address}”.`,
|
|
90
96
|
wholeLog: (message, file) => `${message.endsWith('\n') ? message : `${message}; `}the whole log is ${file}`,
|
|
91
97
|
serviceEnded: 'the workspace service (presmium serve) ended',
|
|
92
98
|
appEnded: 'the Presmium Studio app ended',
|
|
93
99
|
modelVariables: (variables, unset) => `${variables.join(', ')} go together; ${unset.join(' and ')} ${unset.length > 1 ? 'are' : 'is'} not set.`,
|
|
94
100
|
},
|
|
95
101
|
}
|
|
96
|
-
|
package/src/proxy.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createServer } from 'node:http'
|
|
2
|
+
import type { Server } from 'node:http'
|
|
3
|
+
import type { Duplex } from 'node:stream'
|
|
4
|
+
import { createProxyServer } from 'http-proxy-3'
|
|
5
|
+
|
|
6
|
+
export interface ProxyOptions {
|
|
7
|
+
host: string
|
|
8
|
+
port: number
|
|
9
|
+
target: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface Proxy {
|
|
13
|
+
close(): Promise<void>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function listen(server: Server, port: number, host: string): Promise<void> {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
server.once('error', reject)
|
|
19
|
+
server.listen(port, host, () => {
|
|
20
|
+
server.off('error', reject)
|
|
21
|
+
resolve()
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function startProxy(options: ProxyOptions): Promise<Proxy> {
|
|
27
|
+
const proxy = createProxyServer({ ws: true, xfwd: false })
|
|
28
|
+
proxy.on('error', (error: Error, _request: unknown, response: unknown) => {
|
|
29
|
+
const answer = response as { writeHead?: (status: number, headers: Record<string, string>) => void, end?: (body: string) => void, destroy?: () => void, headersSent?: boolean } | undefined
|
|
30
|
+
if (answer?.writeHead && answer.end && !answer.headersSent) {
|
|
31
|
+
answer.writeHead(502, { 'Content-Type': 'text/plain; charset=utf-8' })
|
|
32
|
+
answer.end(`proxy error: ${error.message}`)
|
|
33
|
+
} else {
|
|
34
|
+
answer?.destroy?.()
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
const upgrades = new Set<Duplex>()
|
|
38
|
+
const server: Server = createServer((request, response) => {
|
|
39
|
+
request.url = request.url ?? '/'
|
|
40
|
+
proxy.web(request, response, { target: options.target })
|
|
41
|
+
})
|
|
42
|
+
server.on('upgrade', (request, socket, head) => {
|
|
43
|
+
upgrades.add(socket)
|
|
44
|
+
socket.once('close', () => upgrades.delete(socket))
|
|
45
|
+
request.url = request.url ?? '/'
|
|
46
|
+
proxy.ws(request, socket, head, { target: options.target })
|
|
47
|
+
})
|
|
48
|
+
try {
|
|
49
|
+
await listen(server, options.port, options.host)
|
|
50
|
+
} catch (error) {
|
|
51
|
+
proxy.close()
|
|
52
|
+
throw error
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
close: () => new Promise((resolve) => {
|
|
56
|
+
server.close(() => resolve())
|
|
57
|
+
server.closeAllConnections()
|
|
58
|
+
for (const socket of upgrades) socket.destroy()
|
|
59
|
+
proxy.close()
|
|
60
|
+
}),
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/studio.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { createHash, randomBytes } from 'node:crypto'
|
|
2
|
-
import { closeSync, copyFileSync, existsSync, mkdirSync, openSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from 'node:fs'
|
|
2
|
+
import { closeSync, copyFileSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from 'node:fs'
|
|
3
3
|
import { createRequire } from 'node:module'
|
|
4
4
|
import { createServer, isIP } from 'node:net'
|
|
5
5
|
import type { AddressInfo } from 'node:net'
|
|
6
|
-
import { homedir } from 'node:os'
|
|
7
|
-
import { dirname, join, resolve } from 'node:path'
|
|
6
|
+
import { homedir, hostname, networkInterfaces } from 'node:os'
|
|
7
|
+
import { delimiter, dirname, join, resolve } from 'node:path'
|
|
8
8
|
import { fileURLToPath } from 'node:url'
|
|
9
9
|
import { bracketIPv6, dshBin, inheritedEnv, isLauncherVariable, launchArgs, launchEnv, launchNode, launchWorkspaceServer, WEB_READY, writeProfile } from '@lincyaw/dsh/launch'
|
|
10
10
|
import type { LaunchedProcess } from '@lincyaw/dsh/launch'
|
|
11
11
|
import { STUDIO_MESSAGES, systemLocale } from './messages.ts'
|
|
12
12
|
import { modelEnv } from './model-env.ts'
|
|
13
|
+
import { startProxy } from './proxy.ts'
|
|
14
|
+
import type { Proxy } from './proxy.ts'
|
|
13
15
|
|
|
14
16
|
const PROFILE = 'presmium-studio'
|
|
15
17
|
const DEFAULT_PORT = 4320
|
|
@@ -38,6 +40,7 @@ export interface StudioOptions {
|
|
|
38
40
|
|
|
39
41
|
export interface Studio {
|
|
40
42
|
url: string
|
|
43
|
+
networkUrls: string[]
|
|
41
44
|
workspaceServerUrl: string
|
|
42
45
|
root: string
|
|
43
46
|
home: string
|
|
@@ -81,12 +84,59 @@ function installProfile(home: string, bundle: string): string {
|
|
|
81
84
|
return name
|
|
82
85
|
}
|
|
83
86
|
|
|
84
|
-
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
/**
|
|
88
|
+
* The `presmium` command a Studio started by itself (`presmium-studio`) runs: `@lincyaw/presmium` where it can be
|
|
89
|
+
* resolved from here, else the one on PATH. `presmium studio` passes its own instead; Studio does not depend on it, which
|
|
90
|
+
* would make the two packages depend on each other.
|
|
91
|
+
*/
|
|
92
|
+
function presmiumBin(env: NodeJS.ProcessEnv, missing: string): string {
|
|
93
|
+
try {
|
|
94
|
+
return join(dirname(createRequire(join(PACKAGE_DIR, 'package.json')).resolve('@lincyaw/presmium/package.json')), 'bin', 'presmium.mjs')
|
|
95
|
+
} catch {}
|
|
96
|
+
const names = process.platform === 'win32' ? ['presmium.cmd', 'presmium'] : ['presmium']
|
|
97
|
+
for (const dir of (env.PATH ?? '').split(delimiter).filter(Boolean)) {
|
|
98
|
+
for (const name of names) {
|
|
99
|
+
const script = existsSync(join(dir, name)) ? nodeScript(join(dir, name)) : undefined
|
|
100
|
+
if (script) return script
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
throw new Error(missing)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The Node script a command runs: the file itself (an npm link), or the target a pnpm shim names. */
|
|
107
|
+
function nodeScript(command: string): string | undefined {
|
|
108
|
+
try {
|
|
109
|
+
const file = realpathSync(command)
|
|
110
|
+
const head = readFileSync(file, 'utf8').slice(0, 4096)
|
|
111
|
+
if (/\.[cm]?js$/.test(file) || /^#!.*\bnode\b/.test(head)) return file
|
|
112
|
+
const target = /cmd-shim-target=(.+)$/m.exec(head)?.[1]?.trim()
|
|
113
|
+
return target && existsSync(target) ? target : undefined
|
|
114
|
+
} catch {
|
|
115
|
+
return undefined
|
|
116
|
+
}
|
|
87
117
|
}
|
|
88
118
|
|
|
89
|
-
const WILDCARD = /^
|
|
119
|
+
const WILDCARD = /^0\.0\.0\.0$/
|
|
120
|
+
|
|
121
|
+
function networkHosts(): string[] {
|
|
122
|
+
return [...new Set(Object.values(networkInterfaces()).flatMap(entries => entries ?? []).filter(entry => entry.family === 'IPv4' && !entry.internal).map(entry => entry.address))]
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function authority(host: string, port: number): string {
|
|
126
|
+
return `${bracketIPv6(host)}:${port}`
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function httpOrigin(host: string, port: number): string {
|
|
130
|
+
return `http://${authority(host, port)}`
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function studioUrl(backend: string, publicUrl: string | undefined, host: string, port: number): string {
|
|
134
|
+
const token = new URL(backend).searchParams.get('token')
|
|
135
|
+
if (!token) throw new Error('DeepSeek Harness printed an address without its launch token')
|
|
136
|
+
const url = new URL(publicUrl ?? `http://${authority(host, port)}/`)
|
|
137
|
+
url.searchParams.set('token', token)
|
|
138
|
+
return url.href
|
|
139
|
+
}
|
|
90
140
|
|
|
91
141
|
function freePort(listenAddress: string, port: number): Promise<number | undefined> {
|
|
92
142
|
return new Promise((done) => {
|
|
@@ -147,11 +197,21 @@ export async function startStudio(options: StudioOptions): Promise<Studio> {
|
|
|
147
197
|
const env = options.env ?? process.env
|
|
148
198
|
const t = STUDIO_MESSAGES[systemLocale(env)]
|
|
149
199
|
const { listenAddress } = options
|
|
150
|
-
if (listenAddress !== undefined &&
|
|
200
|
+
if (listenAddress !== undefined && isIP(listenAddress) === 0) {
|
|
151
201
|
throw new Error(t.badHost(listenAddress))
|
|
152
202
|
}
|
|
153
|
-
const
|
|
154
|
-
const
|
|
203
|
+
const boundAddress = listenAddress ?? '127.0.0.1'
|
|
204
|
+
const wildcard = WILDCARD.test(boundAddress)
|
|
205
|
+
const port = await choosePort(boundAddress, options.port)
|
|
206
|
+
const dshAddress = wildcard ? '127.0.0.1' : boundAddress
|
|
207
|
+
const dshPort = wildcard ? await choosePort(dshAddress, undefined) : port
|
|
208
|
+
const hosts = wildcard ? networkHosts() : []
|
|
209
|
+
const primaryHost = hosts[0] ?? dshAddress
|
|
210
|
+
const origins = options.publicUrl
|
|
211
|
+
? [new URL(options.publicUrl).origin, ...hosts.map(host => httpOrigin(host, port)), httpOrigin('127.0.0.1', port)]
|
|
212
|
+
: wildcard
|
|
213
|
+
? [...hosts.map(host => httpOrigin(host, port)), httpOrigin('127.0.0.1', port), `http://localhost:${port}`]
|
|
214
|
+
: [httpOrigin(boundAddress, port), ...boundAddress === '127.0.0.1' ? [`http://localhost:${port}`] : []]
|
|
155
215
|
|
|
156
216
|
const home = studioHome(env)
|
|
157
217
|
mkdirSync(home, { recursive: true, mode: 0o700 })
|
|
@@ -161,14 +221,17 @@ export async function startStudio(options: StudioOptions): Promise<Studio> {
|
|
|
161
221
|
const log = new Log(join(home, `${profile}.log`))
|
|
162
222
|
const serviceToken = randomBytes(24).toString('base64url')
|
|
163
223
|
const started: LaunchedProcess[] = []
|
|
224
|
+
let proxy: Proxy | undefined
|
|
164
225
|
const stopAll = async () => {
|
|
226
|
+
await proxy?.close()
|
|
227
|
+
proxy = undefined
|
|
165
228
|
for (const launched of started.reverse()) await launched.stop()
|
|
166
229
|
started.length = 0
|
|
167
230
|
}
|
|
168
231
|
|
|
169
232
|
try {
|
|
170
233
|
const server = launchWorkspaceServer({
|
|
171
|
-
presmium: options.presmium ?? presmiumBin(),
|
|
234
|
+
presmium: options.presmium ?? presmiumBin(env, t.presmiumMissing),
|
|
172
235
|
dir: resolve(options.dir),
|
|
173
236
|
serviceToken,
|
|
174
237
|
...options.previewPort ? { port: options.previewPort } : {},
|
|
@@ -183,9 +246,13 @@ export async function startStudio(options: StudioOptions): Promise<Studio> {
|
|
|
183
246
|
started.push(server.process)
|
|
184
247
|
const { url, root } = await server.ready
|
|
185
248
|
|
|
249
|
+
const trustedHosts = wildcard
|
|
250
|
+
? [...hosts, hostname(), `${hostname()}.local`]
|
|
251
|
+
: listenAddress ? [listenAddress] : []
|
|
186
252
|
const dsh = launchNode('DeepSeek Harness', [
|
|
187
|
-
dshBin(PACKAGE_DIR), ...launchArgs(profile, 'web'), '--port', String(
|
|
188
|
-
...listenAddress ? ['--host',
|
|
253
|
+
dshBin(PACKAGE_DIR), ...launchArgs(profile, 'web'), '--port', String(dshPort), '--no-open',
|
|
254
|
+
...wildcard || listenAddress ? ['--host', dshAddress] : [],
|
|
255
|
+
...trustedHosts.flatMap(host => ['--trusted-host', authority(host, port)]),
|
|
189
256
|
...options.publicUrl ? ['--public-url', options.publicUrl, '--trusted-host', new URL(options.publicUrl).host] : [],
|
|
190
257
|
], {
|
|
191
258
|
cwd: root,
|
|
@@ -200,8 +267,11 @@ export async function startStudio(options: StudioOptions): Promise<Studio> {
|
|
|
200
267
|
onOutput: text => log.write('dsh', text),
|
|
201
268
|
})
|
|
202
269
|
started.push(dsh)
|
|
203
|
-
const
|
|
270
|
+
const backend = (await dsh.ready(WEB_READY))[1]!
|
|
271
|
+
if (wildcard) proxy = await startProxy({ host: boundAddress, port, target: `http://${authority(dshAddress, dshPort)}` })
|
|
204
272
|
dsh.stopBuffering()
|
|
273
|
+
const address = studioUrl(backend, options.publicUrl, primaryHost, port)
|
|
274
|
+
const networkUrls = hosts.slice(1).map(host => studioUrl(backend, `http://${authority(host, port)}/`, host, port))
|
|
205
275
|
// The address with its launch token, for a host that opens Studio for the user (0600, removed on close).
|
|
206
276
|
const state = join(home, `${profile}.json`)
|
|
207
277
|
writeFileSync(state, `${JSON.stringify({ url: address, workspace: root, workspaceServerUrl: url, pid: process.pid }, null, 2)}\n`, { mode: 0o600 })
|
|
@@ -213,6 +283,7 @@ export async function startStudio(options: StudioOptions): Promise<Studio> {
|
|
|
213
283
|
]).then(how => (closing ? new Promise<string>(() => {}) : how))
|
|
214
284
|
return {
|
|
215
285
|
url: address,
|
|
286
|
+
networkUrls,
|
|
216
287
|
workspaceServerUrl: url,
|
|
217
288
|
root,
|
|
218
289
|
home,
|