@@ -144,6 +144,10 @@ function estimateKiroImageTokens(image: KiroImage): number {
144144 return Math . max ( 256 , Math . ceil ( decodedBytes / 512 ) ) ;
145145}
146146
147+ function estimateKiroTokens ( text : string , modelId ?: string ) : number {
148+ return estimateTokens ( text , modelId ? `kiro/${ modelId } ` : "kiro" ) ;
149+ }
150+
147151function estimateKiroPayloadInputTokens ( payload : Record < string , unknown > , modelId : string ) : number {
148152 const conversationState = ( payload as {
149153 conversationState ?: {
@@ -174,7 +178,7 @@ function estimateKiroPayloadInputTokens(payload: Record<string, unknown>, modelI
174178 if ( assistant . toolUses ?. length ) parts . push ( serializeForUsage ( assistant . toolUses ) ) ;
175179 }
176180 }
177- return estimateTokens ( parts . join ( "\n" ) , modelId ) + imageTokens ;
181+ return estimateKiroTokens ( parts . join ( "\n" ) , modelId ) + imageTokens ;
178182}
179183
180184function shouldCountStablePromptOverhead ( parsed : OcxParsedRequest ) : boolean {
@@ -191,14 +195,14 @@ function estimateKiroInputTokens(parsed: OcxParsedRequest): number {
191195 if ( parsed . context . tools ?. length ) parts . push ( serializeForUsage ( parsed . context . tools ) ) ;
192196 }
193197
194- return estimateTokens ( parts . join ( "\n" ) , parsed . modelId ) ;
198+ return estimateKiroTokens ( parts . join ( "\n" ) , parsed . modelId ) ;
195199}
196200
197201function estimateKiroLogInputTokens ( parsed : OcxParsedRequest ) : number {
198202 const parts = parsed . context . messages . map ( messageLogText ) . filter ( Boolean ) ;
199203 if ( parsed . context . systemPrompt ?. length ) parts . push ( ...parsed . context . systemPrompt ) ;
200204 if ( parsed . context . tools ?. length ) parts . push ( serializeForUsage ( parsed . context . tools ) ) ;
201- return Math . max ( estimateKiroInputTokens ( parsed ) , estimateTokens ( parts . join ( "\n" ) , parsed . modelId ) ) ;
205+ return Math . max ( estimateKiroInputTokens ( parsed ) , estimateKiroTokens ( parts . join ( "\n" ) , parsed . modelId ) ) ;
202206}
203207
204208function kiroUpstreamContextWindow ( modelId : string | undefined ) : number | undefined {
@@ -631,7 +635,7 @@ async function* parseKiroAttempt(
631635 const usage = ( ) : OcxUsage => {
632636 const base = authoritativeUsage ?? {
633637 inputTokens,
634- outputTokens : estimateTokens ( outputChars , modelId ) ,
638+ outputTokens : estimateKiroTokens ( outputChars , modelId ) ,
635639 estimated : true ,
636640 } ;
637641 const estimatedContextTotal = contextInputEstimate !== undefined
0 commit comments