Skip to content
← Public packages

@cameronpak/box

Full Box Public API v1 client: lifecycle, prompts, files, commands, snapshots, environments, webhooks, desktop, hosting, and account.

src/prompt-box.ts

47 lines · 1.4 KB · TypeScript
import { assertBoxId, boxRequest, failure, type Result } from './client.ts'
import type { PromptRun } from './types.ts'

export type PromptBoxInput = {
	boxId: string
	/** codex or claude-code. The backend also accepts claude as an alias. */
	provider: 'codex' | 'claude-code'
	prompt: string
	/** Codex: gpt-5.5, gpt-5.4, gpt-5.4-mini, gpt-5.3-codex. Claude Code: claude-fable-5, opus, sonnet, haiku. */
	model?: string | null
	reasoningEffort?: 'none' | 'low' | 'medium' | 'high' | 'xhigh' | 'max' | null
}

export type PromptBoxOutput = {
	id: string
	promptId: string
	promptRun: PromptRun
	status: string
	provider: string
	model?: string | null
	reasoningEffort?: string | null
}

/**
 * Queue natural-language work for Codex or Claude Code inside a box.
 * Requires provider credentials in the Box dashboard, otherwise the API
 * returns provider_not_configured. Watch progress with listEvents.
 */
export default async function promptBox(
	input: PromptBoxInput,
): Promise<Result<PromptBoxOutput>> {
	const invalid = assertBoxId(input?.boxId)
	if (invalid) return failure<PromptBoxOutput>(invalid)

	const body: Record<string, unknown> = {
		provider: input.provider,
		prompt: input.prompt,
	}
	if (input.model !== undefined) body.model = input.model
	if (input.reasoningEffort !== undefined) body.reasoningEffort = input.reasoningEffort

	return boxRequest<PromptBoxOutput>({
		path: '/boxes/' + input.boxId + '/prompt',
		method: 'POST',
		body,
	})
}