Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions src/adapter/openai-to-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* Converts OpenAI chat request format to Claude CLI input
*/

import type { OpenAIChatRequest } from "../types/openai.js";
import type { OpenAIChatRequest, OpenAIContentBlock } from "../types/openai.js";

export type ClaudeModel = "opus" | "sonnet" | "haiku";
export type ClaudeModel = "opus" | "sonnet" | "haiku" | "claude-sonnet-4-6";

export interface CliInput {
prompt: string;
Expand All @@ -15,18 +15,42 @@ export interface CliInput {
const MODEL_MAP: Record<string, ClaudeModel> = {
// Direct model names
"claude-opus-4": "opus",
"claude-opus-4-6": "opus",
"claude-sonnet-4": "sonnet",
"claude-sonnet-4-6": "claude-sonnet-4-6",
"claude-haiku-4": "haiku",
// With provider prefix
"claude-code-cli/claude-opus-4": "opus",
"claude-code-cli/claude-opus-4-6": "opus",
"claude-code-cli/claude-sonnet-4": "sonnet",
"claude-code-cli/claude-sonnet-4-6": "claude-sonnet-4-6",
"claude-code-cli/claude-haiku-4": "haiku",
// Aliases
"opus": "opus",
"sonnet": "sonnet",
"haiku": "haiku",
};

/**
* Extract text from OpenAI content field, which can be:
* - a plain string
* - an array of content blocks [{type: "text", text: "..."}, ...]
* - null/undefined
*/
function extractContentText(content: string | OpenAIContentBlock[] | null | undefined): string {
if (typeof content === "string") return content;
if (Array.isArray(content)) {
return content
.filter((b): b is OpenAIContentBlock & { type: "text"; text: string } =>
b != null && typeof b === "object" && b.type === "text" && typeof b.text === "string"
)
.map((b) => b.text)
.join("\n");
}
if (content == null) return "";
return String(content);
}

/**
* Extract Claude model alias from request model string
*/
Expand Down Expand Up @@ -56,20 +80,21 @@ export function messagesToPrompt(messages: OpenAIChatRequest["messages"]): strin
const parts: string[] = [];

for (const msg of messages) {
const text = extractContentText(msg.content);
switch (msg.role) {
case "system":
// System messages become context instructions
parts.push(`<system>\n${msg.content}\n</system>\n`);
parts.push(`<system>\n${text}\n</system>\n`);
break;

case "user":
// User messages are the main prompt
parts.push(msg.content);
parts.push(text);
break;

case "assistant":
// Previous assistant responses for context
parts.push(`<previous_response>\n${msg.content}\n</previous_response>\n`);
parts.push(`<previous_response>\n${text}\n</previous_response>\n`);
break;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/subprocess/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export interface SubprocessEvents {
raw: (line: string) => void;
}

const DEFAULT_TIMEOUT = 300000; // 5 minutes
// 15 minutes — agentic/research tasks with multiple tool calls (web search,
// multi-step reasoning) routinely exceed 5 minutes; a short timeout kills them mid-run.
const DEFAULT_TIMEOUT = 900000;

export class ClaudeSubprocess extends EventEmitter {
private process: ChildProcess | null = null;
Expand Down
7 changes: 6 additions & 1 deletion src/types/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
* Used for Clawdbot integration
*/

export interface OpenAIContentBlock {
type: string;
text?: string;
}

export interface OpenAIChatMessage {
role: "system" | "user" | "assistant";
content: string;
content: string | OpenAIContentBlock[] | null;
}

export interface OpenAIChatRequest {
Expand Down