@@ -26,6 +26,10 @@ import {
2626} from "../tools/scheduledTasks" ;
2727import { streamAnthropic } from "../providers/anthropic" ;
2828import { streamOpenAI } from "../providers/openai" ;
29+ import {
30+ runClaudeSubscriptionTurn ,
31+ runCodexSubscriptionTurn ,
32+ } from "../providers/cliSubscriptionTurn" ;
2933import { buildSystemPrompt } from "./prompt" ;
3034import { McpManager , type McpServerConfig } from "../mcp/client" ;
3135import { LspManager } from "../lsp/client" ;
@@ -113,6 +117,52 @@ export async function* runAgentLoop(options: AgentLoopOptions): AsyncGenerator<A
113117 const messages : ConversationMessage [ ] = [ ...conversationHistory ] ;
114118 messages . push ( { role : "user" , content : userMessage } ) ;
115119
120+ if ( config . provider === "anthropic" && config . upstream . kind === "claude_subscription" ) {
121+ for await ( const event of runClaudeSubscriptionTurn ( {
122+ model : config . model ,
123+ cwd : config . workspaceRoot ,
124+ systemPrompt,
125+ conversationHistory,
126+ userMessage,
127+ signal,
128+ claudeBinaryPath : config . upstream . claudeBinaryPath ,
129+ mode : config . mode ,
130+ harnessRuntimeMode : config . harnessRuntimeMode ?? "auto-accept-edits" ,
131+ } ) ) {
132+ yield event ;
133+ }
134+ await mcpManager . closeAll ( ) ;
135+ return ;
136+ }
137+
138+ if ( config . provider === "openai" && config . upstream . kind === "openai_subscription" ) {
139+ for await ( const event of runCodexSubscriptionTurn ( {
140+ model : config . model ,
141+ cwd : config . workspaceRoot ,
142+ systemPrompt,
143+ conversationHistory,
144+ userMessage,
145+ signal,
146+ codexBinaryPath : config . upstream . codexBinaryPath ,
147+ codexHomePath : config . upstream . codexHomePath ,
148+ } ) ) {
149+ yield event ;
150+ }
151+ await mcpManager . closeAll ( ) ;
152+ return ;
153+ }
154+
155+ if ( config . upstream . kind !== "api_key" ) {
156+ yield {
157+ type : "error" ,
158+ error : "Harness API routing needs an API key for this model provider." ,
159+ } ;
160+ await mcpManager . closeAll ( ) ;
161+ return ;
162+ }
163+
164+ const apiUpstream = config . upstream ;
165+
116166 let turnNumber = 0 ;
117167 const editedFiles : Set < string > = new Set ( ) ;
118168 let nudgeState = createNudgeState ( ) ;
@@ -134,8 +184,8 @@ export async function* runAgentLoop(options: AgentLoopOptions): AsyncGenerator<A
134184 config . provider === "anthropic"
135185 ? streamAnthropic ( {
136186 model : config . model ,
137- apiKey : config . apiKey ,
138- ...( config . baseURL ? { baseURL : config . baseURL } : { } ) ,
187+ apiKey : apiUpstream . apiKey ,
188+ ...( apiUpstream . baseURL ? { baseURL : apiUpstream . baseURL } : { } ) ,
139189 messages,
140190 tools : allTools ,
141191 systemPrompt,
@@ -144,9 +194,9 @@ export async function* runAgentLoop(options: AgentLoopOptions): AsyncGenerator<A
144194 } )
145195 : streamOpenAI ( {
146196 model : config . model ,
147- apiKey : config . apiKey ,
197+ apiKey : apiUpstream . apiKey ,
148198 baseURL :
149- config . baseURL ??
199+ apiUpstream . baseURL ??
150200 ( config . provider === "openrouter"
151201 ? "https://openrouter.ai/api/v1"
152202 : "https://api.openai.com/v1" ) ,
0 commit comments