1111import type { DeminifyCache } from "./cache.ts" ;
1212import { shouldCache , hashSource } from "./cache.ts" ;
1313import { getFunctionContext } from "./call-graph.ts" ;
14- import type { BatchDeminifyClient , BatchStatus } from "./batch-client.ts" ;
14+ import type { BatchDeminifyClient } from "./batch-client.ts" ;
1515import type { OpenAIBatchClient , OpenAIBatchStatus } from "./openai-batch.ts" ;
16+ import { toCommonStatus , formatBatchProgress } from "./batch-utils.ts" ;
1617import {
1718 saveBatchState ,
1819 loadBatchState ,
@@ -35,28 +36,6 @@ import type {
3536} from "./types.ts" ;
3637import type { DeminifyFileOptions } from "./deminifier.ts" ;
3738
38- /** Convert OpenAI batch status to common BatchStatus */
39- function toCommonStatus ( status : OpenAIBatchStatus ) : BatchStatus {
40- return {
41- batchId : status . batchId ,
42- status : status . status === "completed" ? "ended" : "in_progress" ,
43- total : status . total ,
44- succeeded : status . completed ,
45- errored : status . failed ,
46- processing : status . total - status . completed - status . failed ,
47- } ;
48- }
49-
50- /** Format batch progress for terminal display */
51- function formatBatchProgress (
52- completed : number ,
53- total : number ,
54- failed : number ,
55- ) : string {
56- const pct = total > 0 ? Math . round ( ( completed / total ) * 100 ) : 0 ;
57- return `\r Progress: ${ String ( completed ) } /${ String ( total ) } (${ String ( pct ) } %) | Errors: ${ String ( failed ) } ` ;
58- }
59-
6039/** Batch mode orchestrator for de-minification. Manages batch API submissions, polling, and result retrieval. */
6140export class BatchModeProcessor {
6241 private readonly config : DeminifyConfig ;
@@ -479,9 +458,11 @@ export class BatchModeProcessor {
479458 console . log ( "\n\nRetrieving results..." ) ;
480459
481460 // Get results using appropriate client
482- const results = isOpenAI
483- ? await this . getOpenAIResults ( batchId , contexts )
484- : await this . getAnthropicResults ( batchId , contexts ) ;
461+ const client = isOpenAI ? this . openAIBatchClient : this . batchClient ;
462+ if ( ! client ) {
463+ throw new Error ( `${ isOpenAI ? "OpenAI" : "Anthropic" } batch client not initialized` ) ;
464+ }
465+ const results = await client . getResults ( batchId , contexts ) ;
485466
486467 console . log ( `Retrieved ${ String ( results . size ) } results` ) ;
487468
@@ -507,26 +488,4 @@ export class BatchModeProcessor {
507488
508489 return reassembled ;
509490 }
510-
511- /** Get results from OpenAI batch client */
512- private async getOpenAIResults (
513- batchId : string ,
514- contexts : Map < string , DeminifyContext > ,
515- ) : Promise < Map < string , DeminifyResult > > {
516- if ( ! this . openAIBatchClient ) {
517- throw new Error ( "OpenAI batch client not initialized" ) ;
518- }
519- return this . openAIBatchClient . getResults ( batchId , contexts ) ;
520- }
521-
522- /** Get results from Anthropic batch client */
523- private async getAnthropicResults (
524- batchId : string ,
525- contexts : Map < string , DeminifyContext > ,
526- ) : Promise < Map < string , DeminifyResult > > {
527- if ( ! this . batchClient ) {
528- throw new Error ( "Anthropic batch client not initialized" ) ;
529- }
530- return this . batchClient . getResults ( batchId , contexts ) ;
531- }
532491}
0 commit comments