mirror of
https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-11-11 13:37:47 +08:00
* feat(web): advertise a configured public application URL * test(session): restore migration verifier prefix coverage * test(llm): synchronize idle timeout with provider request * Remove unrelated migration Worker lifecycle changes --------- Co-authored-by: liukx0205 <harusoda@berkeley.edu>
108 lines
4.4 KiB
TypeScript
108 lines
4.4 KiB
TypeScript
/**
|
|
* The web app's command-line provider: it parses the `dsh --profile web` flag
|
|
* family (`--host`, `--port`, `--public-url`, `--trusted-host`, `--no-open`)
|
|
* and its `--help` text, then provides the immutable values as
|
|
* {@link WEB_STARTUP_SERVICE}. Ordinary rows inject that service before
|
|
* reading it from lazy config.
|
|
* @module @deepseek-ai/dsh-web-app/startup
|
|
*/
|
|
|
|
import { Command } from 'commander'
|
|
import type { Context } from '@deepseek-ai/cordis'
|
|
import { parseCmdline } from '@deepseek-ai/dsh-cmdline'
|
|
import { parsePublicUrl } from './public-url.ts'
|
|
|
|
/** Stable Cordis plugin name. */
|
|
export const name = 'web-startup'
|
|
|
|
/** Services required before the flags can be resolved. */
|
|
export const inject = ['cmdlineArgs']
|
|
|
|
/** Service provided by this ordinary plugin and injected by flag-configured rows. */
|
|
export const WEB_STARTUP_SERVICE = 'webStartup'
|
|
|
|
/** What the web rows read from {@link WEB_STARTUP_SERVICE}. */
|
|
export interface WebStartupValues {
|
|
/** Whether this invocation opens the default browser after startup. */
|
|
openBrowser: boolean
|
|
/** `--host`, absent when the invocation did not name one. */
|
|
host?: string
|
|
/** `--port`, absent when the invocation did not name one. */
|
|
port?: number
|
|
/**
|
|
* `--public-url`, absent when not specified: the advertised HTTP(S) root.
|
|
* See [public deployments](../README.md#public-deployments).
|
|
*/
|
|
publicUrl?: string
|
|
/** Explicit `--trusted-host` authorities, in argument order. */
|
|
trustedHosts: string[]
|
|
}
|
|
|
|
/** The web flag family, as commander parsed it. */
|
|
interface WebOptions {
|
|
host?: string
|
|
open: boolean
|
|
port?: string
|
|
publicUrl?: string
|
|
trustedHost?: string[]
|
|
}
|
|
|
|
/**
|
|
* This app's command: its flags, its description, and its help text.
|
|
* @returns a fresh program, so one process can parse more than once (tests).
|
|
*/
|
|
function webCommand(): Command {
|
|
return new Command()
|
|
.name('dsh --profile web')
|
|
.description('Serve the DeepSeek Harness browser UI.')
|
|
.helpOption('-h, --help', 'show this help')
|
|
.option('--host <host>', 'bind host')
|
|
.option('--no-open', 'do not open the Web UI in the default browser')
|
|
.option('--port <port>', 'listen port; pass 0 to let the OS pick a free one')
|
|
.option('--public-url <url>', 'advertise this HTTP(S) root in the printed, opened, web-surface, and DSH_WEB_URL forms; grants no trust')
|
|
.option('--trusted-host <authority...>', 'extra authority the /api browser-trust fence accepts (host or host:port; repeatable)')
|
|
.addHelpText('after', `
|
|
Examples:
|
|
dsh --profile web serve on the composed host and port
|
|
dsh --profile web --no-open serve without opening a browser
|
|
dsh --profile web --port 8080 serve on another port
|
|
dsh --profile web --public-url https://app.example/ui/ --trusted-host app.example
|
|
advertise a prefix-stripping HTTPS proxy entry and admit its authority
|
|
`)
|
|
}
|
|
|
|
/**
|
|
* Parse and provide the Web invocation as an ordinary Cordis service. The
|
|
* command's action publishes the flags this invocation named; `--host 0.0.0.0`,
|
|
* a non-numeric `--port`, or a malformed `--public-url` is a usage error, so on
|
|
* rejection (and on `--help`) nothing is provided.
|
|
* @param ctx - plugin context carrying the command line.
|
|
*/
|
|
export function apply(ctx: Context): void {
|
|
const program = webCommand()
|
|
program.action(() => {
|
|
const options = program.opts<WebOptions>()
|
|
if (options.host === '0.0.0.0') {
|
|
program.error('error: --host 0.0.0.0 is intentionally not supported yet for safety: it would expose remote code execution to the network; use 127.0.0.1 instead')
|
|
}
|
|
if (options.port !== undefined && !/^\d+$/.test(options.port)) {
|
|
program.error(`error: --port must be a number, got ${JSON.stringify(options.port)}`)
|
|
}
|
|
if (options.publicUrl !== undefined) {
|
|
try {
|
|
parsePublicUrl(options.publicUrl, '--public-url')
|
|
} catch (error) {
|
|
program.error(`error: ${(error as Error).message}`)
|
|
}
|
|
}
|
|
ctx.provide(WEB_STARTUP_SERVICE, {
|
|
openBrowser: options.open,
|
|
...options.host !== undefined && { host: options.host },
|
|
...options.port !== undefined && { port: Number(options.port) },
|
|
...options.publicUrl !== undefined && { publicUrl: options.publicUrl },
|
|
trustedHosts: options.trustedHost ?? [],
|
|
} satisfies WebStartupValues)
|
|
})
|
|
parseCmdline(ctx, program)
|
|
}
|