mirror of
https://github.com/router-for-me/CLIProxyAPIPlus.git
synced 2026-03-09 15:25:17 +00:00
Merge pull request #191 from CheesesNguyen/feat/kiro-api-models-and-context-usage
feat(kiro): add contextUsageEvent handler
This commit is contained in:
@@ -238,7 +238,7 @@ func (k *KiroAuth) ListAvailableModels(ctx context.Context, tokenData *KiroToken
|
||||
Description string `json:"description"`
|
||||
RateMultiplier float64 `json:"rateMultiplier"`
|
||||
RateUnit string `json:"rateUnit"`
|
||||
TokenLimits struct {
|
||||
TokenLimits *struct {
|
||||
MaxInputTokens int `json:"maxInputTokens"`
|
||||
} `json:"tokenLimits"`
|
||||
} `json:"models"`
|
||||
@@ -250,13 +250,17 @@ func (k *KiroAuth) ListAvailableModels(ctx context.Context, tokenData *KiroToken
|
||||
|
||||
models := make([]*KiroModel, 0, len(result.Models))
|
||||
for _, m := range result.Models {
|
||||
maxInputTokens := 0
|
||||
if m.TokenLimits != nil {
|
||||
maxInputTokens = m.TokenLimits.MaxInputTokens
|
||||
}
|
||||
models = append(models, &KiroModel{
|
||||
ModelID: m.ModelID,
|
||||
ModelName: m.ModelName,
|
||||
Description: m.Description,
|
||||
RateMultiplier: m.RateMultiplier,
|
||||
RateUnit: m.RateUnit,
|
||||
MaxInputTokens: m.TokenLimits.MaxInputTokens,
|
||||
MaxInputTokens: maxInputTokens,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2102,6 +2102,22 @@ func (e *KiroExecutor) parseEventStream(body io.Reader) (string, []kiroclaude.Ki
|
||||
}
|
||||
}
|
||||
|
||||
case "contextUsageEvent":
|
||||
// Handle context usage events from Kiro API
|
||||
// Format: {"contextUsageEvent": {"contextUsagePercentage": 0.53}}
|
||||
if ctxUsage, ok := event["contextUsageEvent"].(map[string]interface{}); ok {
|
||||
if ctxPct, ok := ctxUsage["contextUsagePercentage"].(float64); ok {
|
||||
upstreamContextPercentage = ctxPct
|
||||
log.Debugf("kiro: parseEventStream received contextUsageEvent: %.2f%%", ctxPct*100)
|
||||
}
|
||||
} else {
|
||||
// Try direct field (fallback)
|
||||
if ctxPct, ok := event["contextUsagePercentage"].(float64); ok {
|
||||
upstreamContextPercentage = ctxPct
|
||||
log.Debugf("kiro: parseEventStream received contextUsagePercentage (direct): %.2f%%", ctxPct*100)
|
||||
}
|
||||
}
|
||||
|
||||
case "error", "exception", "internalServerException", "invalidStateEvent":
|
||||
// Handle error events from Kiro API stream
|
||||
errMsg := ""
|
||||
@@ -2705,6 +2721,22 @@ func (e *KiroExecutor) streamToChannel(ctx context.Context, body io.Reader, out
|
||||
}
|
||||
}
|
||||
|
||||
case "contextUsageEvent":
|
||||
// Handle context usage events from Kiro API
|
||||
// Format: {"contextUsageEvent": {"contextUsagePercentage": 0.53}}
|
||||
if ctxUsage, ok := event["contextUsageEvent"].(map[string]interface{}); ok {
|
||||
if ctxPct, ok := ctxUsage["contextUsagePercentage"].(float64); ok {
|
||||
upstreamContextPercentage = ctxPct
|
||||
log.Debugf("kiro: streamToChannel received contextUsageEvent: %.2f%%", ctxPct*100)
|
||||
}
|
||||
} else {
|
||||
// Try direct field (fallback)
|
||||
if ctxPct, ok := event["contextUsagePercentage"].(float64); ok {
|
||||
upstreamContextPercentage = ctxPct
|
||||
log.Debugf("kiro: streamToChannel received contextUsagePercentage (direct): %.2f%%", ctxPct*100)
|
||||
}
|
||||
}
|
||||
|
||||
case "error", "exception", "internalServerException":
|
||||
// Handle error events from Kiro API stream
|
||||
errMsg := ""
|
||||
|
||||
Reference in New Issue
Block a user