Download packages/coding-agent/src/cli/experimental/commands/server.ts from SaylorTwift/pi: direct link, hf CLI and curl.
- Browser
- Download file 2.36 kB
-
https://huggingface.co/SaylorTwift/pi/resolve/main/packages/coding-agent/src/cli/experimental/commands/server.ts
- Command line
-
hf download hf://SaylorTwift/pi/packages/coding-agent/src/cli/experimental/commands/server.ts
-
curl -L -o server.ts https://huggingface.co/SaylorTwift/pi/resolve/main/packages/coding-agent/src/cli/experimental/commands/server.ts
2.36 kB
| import { isServerId, type ServerId } from "@earendil-works/pi-protocol"; | |
| import { Command, stringOption, valueOption } from "../command.ts"; | |
| import { | |
| type AuthInput, | |
| authTokenFileOption, | |
| authTokenOption, | |
| parseAuth, | |
| unsupportedOptions, | |
| } from "../command-options.ts"; | |
| export interface ServerCommand { | |
| readonly command: "server"; | |
| readonly auth?: AuthInput; | |
| readonly provider?: string; | |
| readonly model?: string; | |
| readonly pluginPackages?: readonly string[]; | |
| readonly serverId?: ServerId; | |
| readonly sessionDir?: string; | |
| } | |
| export interface ServerCommandContext { | |
| runServer(command: ServerCommand): void | Promise<void>; | |
| } | |
| const serverIdOption = valueOption("--server-id", (value) => | |
| isServerId(value) | |
| ? { ok: true, value } | |
| : { ok: false, error: `Invalid --server-id "${value}"; expected a lowercase UUIDv4` }, | |
| ); | |
| const sessionDirOption = stringOption("--session-dir"); | |
| const providerOption = stringOption("--provider"); | |
| const modelOption = stringOption("--model"); | |
| const pluginPackageOption = stringOption("-e", { repeatable: true }); | |
| export const serverCommand = new Command<ServerCommand, ServerCommandContext>("server") | |
| .option(serverIdOption) | |
| .option(sessionDirOption) | |
| .option(providerOption) | |
| .option(modelOption) | |
| .option(pluginPackageOption) | |
| .option(authTokenOption) | |
| .option(authTokenFileOption) | |
| .build((input) => { | |
| const { auth, errors: authErrors } = parseAuth(input); | |
| const serverId = input.value(serverIdOption); | |
| const sessionDir = input.value(sessionDirOption); | |
| const provider = input.value(providerOption); | |
| const model = input.value(modelOption); | |
| const pluginPackages = input.values(pluginPackageOption); | |
| const modelErrors = provider !== undefined && model === undefined ? ["--provider requires --model"] : []; | |
| const errors = [...authErrors, ...modelErrors, ...unsupportedOptions("server", input)]; | |
| if (errors.length > 0) return { ok: false, errors }; | |
| return { | |
| ok: true, | |
| command: { | |
| command: "server", | |
| ...(auth === undefined ? {} : { auth }), | |
| ...(provider === undefined ? {} : { provider }), | |
| ...(model === undefined ? {} : { model }), | |
| ...(pluginPackages.length === 0 ? {} : { pluginPackages }), | |
| ...(serverId === undefined ? {} : { serverId }), | |
| ...(sessionDir === undefined ? {} : { sessionDir }), | |
| }, | |
| }; | |
| }) | |
| .action((command, context) => context.runServer(command)); | |