diff options
| author | Adam Malczewski <[email protected]> | 2026-06-05 21:20:34 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-06-05 21:20:34 +0900 |
| commit | 552c22d74e5df915088d9e9ff4a286c96c2a54d6 (patch) | |
| tree | 7d9db1052bab91ef994446d80efc3bfc38026cad /packages/cli/src/message.ts | |
| parent | 7fb3269c698ae583ea7997ce206c4ae252fd3218 (diff) | |
| download | dispatch-552c22d74e5df915088d9e9ff4a286c96c2a54d6.tar.gz dispatch-552c22d74e5df915088d9e9ff4a286c96c2a54d6.zip | |
feat(cli): one-shot terminal client (models, chat, --text/--file/--cwd/--conversation)
HTTP client of transport-contract; pure-core arg/render/ndjson + injected fetch/fs shell.
Docs: GLOSSARY (credential/key/model name/model catalog), tasks.md milestone, ORCHESTRATOR geography.
Diffstat (limited to 'packages/cli/src/message.ts')
| -rw-r--r-- | packages/cli/src/message.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/packages/cli/src/message.ts b/packages/cli/src/message.ts new file mode 100644 index 0000000..0c3f538 --- /dev/null +++ b/packages/cli/src/message.ts @@ -0,0 +1,55 @@ +/** + * Pure message composition — zero I/O. + * + * Combines text and file content into a single message string, + * and builds a ChatRequest from a parsed command. + */ + +import type { ChatRequest } from "@dispatch/transport-contract"; + +interface ComposeInput { + readonly text?: string; + readonly file?: string; + readonly fileContent?: string; +} + +function basename(filePath: string): string { + const segments = filePath.split("/"); + return segments[segments.length - 1] ?? filePath; +} + +export function composeMessage(input: ComposeInput): string { + const { text, fileContent } = input; + const file = input.file; + + if (text && file) { + return `${text}\n\nAttached file (${basename(file)}):\n${fileContent ?? ""}`; + } + if (file) { + return `Attached file (${basename(file)}):\n${fileContent ?? ""}`; + } + return text ?? ""; +} + +interface ChatCmd { + readonly modelName: string; + readonly text?: string | undefined; + readonly file?: string | undefined; + readonly cwd?: string | undefined; + readonly conversationId?: string | undefined; + readonly showReasoning: boolean; +} + +interface BuildCtx { + readonly cwd: string; + readonly message: string; +} + +export function buildChatRequest(cmd: ChatCmd, ctx: BuildCtx): ChatRequest { + return { + message: ctx.message, + model: cmd.modelName, + ...(cmd.conversationId !== undefined && { conversationId: cmd.conversationId }), + ...(cmd.cwd !== undefined ? { cwd: cmd.cwd } : { cwd: ctx.cwd }), + }; +} |
