Skip to content

强化统计系统、优化ADMINUI面板、增强BASE64图片发送#11

Open
luluxiuxiu wants to merge 61 commits intohank9999:masterfrom
luluxiuxiu:master
Open

强化统计系统、优化ADMINUI面板、增强BASE64图片发送#11
luluxiuxiu wants to merge 61 commits intohank9999:masterfrom
luluxiuxiu:master

Conversation

@luluxiuxiu
Copy link

1、强化统计系统
2、优化ADMINUI面板
3、增强BASE64图片识别
4、优化部分代码
5、增加本地日志输出

感谢您的项目,增加了部分内容,请您按需增加,给您添麻烦了,谢谢

jackliu added 2 commits January 7, 2026 13:45
# Conflicts:
#	src/admin/service.rs
#	src/anthropic/converter.rs
#	src/anthropic/handlers.rs
#	src/anthropic/stream.rs
#	src/kiro/machine_id.rs
#	src/kiro/provider.rs
#	src/kiro/token_manager.rs
#	src/main.rs
@hank9999
Copy link
Owner

hank9999 commented Jan 7, 2026

好大的PR (((((
得等我有空了慢慢看((

@hank9999
Copy link
Owner

hank9999 commented Jan 7, 2026

不过这边建议您最好拆开提交PR(

@BenedictKing
Copy link
Contributor

建议让cc给你拆成小的一系列feat再帮你完成批量pr提交

jackliu and others added 4 commits January 8, 2026 14:22
- Resolve merge conflicts and keep existing behavior\n- Admin UI: show primary account info; format token stats as K/M/B

Co-Authored-By: Warp <agent@warp.dev>
@BenedictKing
Copy link
Contributor

这个pr肯定是废了,重新开几个吧

jackliu and others added 13 commits January 9, 2026 10:19
- 实现了 cbor_timestamp 模块,支持将 CBOR Tag(1) 时间戳和普通字符串统一转换为 RFC3339 字符串。
- 在 Bonus、FreeTrialInfo、UsageBreakdownItem 和 UsageAndLimitsResponse 结构体中添加了对 expires_at、free_trial_expiry、next_date_reset 字段的反序列化支持。
- 更新了 Kiro API 请求和响应处理,增加了详细的日志记录以便调试 CBOR 格式。
- provider: 识别 402 + MONTHLY_REQUEST_COUNT,调用 report_quota_exhausted 切换到其他凭据
- token_manager: 增加 QuotaExceeded 禁用原因与对应逻辑/测试
@hank9999
Copy link
Owner

现在这个PR太大了 我只能一部分一部分的cherry pick了 (((((9

@hank9999
Copy link
Owner

@luluxiuxiu Hi, 感谢您的提交, 由于改动范围较大, review 比较困难, 能否拆分成多个PR提交?

jackliu added 23 commits January 16, 2026 13:13
- Add stream state management with `StreamState` struct to track retry attempts
- Implement automatic retry logic for interrupted streams with configurable thresholds
- Add `STREAM_RETRY_MIN_OUTPUT_TOKENS` constant (100 tokens) to prevent retries on short outputs
- Add `STREAM_MAX_RETRIES` constant (2 retries) to limit retry attempts
- Pass provider and request body to stream handler for retry capability
- Refactor `create_sse_stream` to use unfold pattern with state management
- Preserve request context across stream interruptions to enable seamless retries
- Only trigger retries on stream read errors, not on normal EOF completion
- 适合多种凭证混用时,节省主凭证的部分消耗,小模型可以使用低价购买的试用凭证
- 在凭据API中添加setCredentialEnabledModels接口用于更新启用模型列表
- 在添加凭据对话框中增加模型选择开关,支持全选/全不选功能
- 在凭据卡片中添加模型配置编辑功能,支持实时保存
- 新增models.ts工具库,提供模型ID和标签的统一管理
- 更新凭据类型定义,添加enabledModels字段支持
- 在后端handlers、service和types中实现模型列表的CRUD操作
- 更新token_manager和provider逻辑以支持按凭据过滤模型
- 允许用户限制凭据可用模型,避免请求命中不支持模型导致400错误
- Add detection for ContentLengthExceeded errors in stream request handler
- Return synthetic SSE stream with stop_reason=max_tokens to trigger Claude Code compression
- Add detection for ContentLengthExceeded errors in non-stream request handler
- Return success response with stop_reason=max_tokens instead of 502 error
- Include helpful user guidance message about context compression options
- Move KiroCredentials import outside of test-only cfg block for broader availability
- Update base_url documentation comment to clarify global region usage
- Improve error handling to gracefully manage context length limits while maintaining API compatibility
- 在credentials.example.idc.json中添加profileArn字段示例
- 在KiroCredentials模型中新增account_email、user_id和provider字段
- 实现DiagnosticLog结构体用于生成详细的诊断日志
- 添加format_credential_info函数用于格式化凭据信息展示
- 添加base64_decode_jwt_payload函数用于解码JWT token payload
- 在provider.rs中添加全局诊断标志和请求计数器
- 更新测试用例以包含新增的凭据字段
- 增强错误诊断能力,便于调试凭据和token相关问题
…gement

- Extract session ID from metadata.user_id to isolate Claude Code sessions
- Pass session_id and app_state through stream and non-stream request handlers
- Implement session-level token tracking to ensure tokens only increase within a session
- Add update_session_tokens method to AppState for maintaining token consistency
- Update StreamState struct to include app_state and session_id fields
- Apply consistent token values at stream completion and error handling points
- Add AUTO_COMPACT_THRESHOLD constant (85%) to trigger automatic context compression
- Log context usage percentage when approaching compression threshold
- Ensure token consistency across stream interruptions and retries
- Improve session isolation for concurrent Claude Code interactions
- Change stop_reason from "max_tokens" to "end_turn" for proper error responses
- Remove misleading hint about automatic Claude Code compression
- Update output_tokens from 50 to 100 for more accurate token usage reporting
- Include actual input_tokens value in usage metrics instead of hardcoded output
- Simplify user-facing warning message by removing compression hint
- Update logging messages to reflect actual response behavior
- Apply corrections to both streaming and non-streaming request handlers
This change ensures that when content length is exceeded, the API returns accurate token usage information and proper stop reasons instead of attempting to trigger client-side compression through misleading response signals.
…etry

- Add async-trait dependency for async trait support
- Create history_manager.rs module for managing conversation history with Kiro summary generation
- Create history_store.rs module for persistent storage of conversation history
- Extend ConversionResult to include original_history and model_id for retry scenarios
- Add rebuild_with_truncated_history() function to reconstruct ConversationState with truncated history
- Implement automatic history persistence to file storage on each message
- Add ContentLengthExceeded error handling with automatic history truncation and retry logic
- Support both stream and non-stream request retry with truncated context
- Generate Kiro-compatible summaries for truncated conversation segments
- Preserve session continuity across truncation retries with new agent_continuation_id
- Add summary model setting component to dashboard for managing AI model selection
- Implement getSummaryModel and setSummaryModel API endpoints in credentials service
- Add SummaryModelSetting component with model selection UI and persistence
- Create useSummaryModel and useSetSummaryModel hooks for state management
- Add summary model routes and handlers in admin router and handlers
- Update dashboard to display summary model settings in configuration area
- Add VSCode settings configuration file
- Integrate summary model configuration with credential management system
- Support model selection for history message compression and summarization
- Add `truncate_str_safe()` function to safely truncate UTF-8 strings without breaking multi-byte characters
- Add `truncate_with_ellipsis()` function to truncate strings and append ellipsis suffix
- Replace unsafe string slicing operations in history_manager.rs with safe truncation calls
- Replace unsafe string slicing in websearch.rs snippet truncation with safe truncation
- Replace unsafe string slicing in provider.rs token preview and header formatting with safe truncation
- Improve code safety and prevent potential panics from invalid UTF-8 character boundaries
- Add received_upstream_error and upstream_error_message fields to StreamContext to track upstream errors
- Detect error and exception events from upstream service and mark them for retry handling
- Return SSE error event when upstream error is detected with abnormally short output to trigger Claude Code retry
- Log upstream error status in stream completion diagnostics for better debugging
- Record error statistics when upstream errors occur with short output
- Include upstream error information in stream context logging for comprehensive error tracking
…delta

- Remove monotonic increment enforcement from update_tokens() to allow input_tokens to decrease when context is compacted
- Simplify token update logic by directly storing values instead of complex compare-exchange loops
- Add handle_message_delta_usage() method to SseStateManager for sending intermediate usage updates
- Make SseStateManager fields public (message_started, message_delta_sent, message_ended) for external access
- Emit message_delta events with real-time token usage during stream processing to help Claude Code detect context changes
- Update .gitignore to exclude AI workflow artifacts and progress tracking files
- Refactor token management to treat input_tokens as state (reflects current context size) rather than monotonically increasing counter, enabling proper handling of /compact operations
…handling

- Extract session ID from metadata.user_id with "__session_" delimiter
- Add session_id to request logging for better traceability
- Pass state and session_id to websearch request handler
- Handle InvalidRequest error variant in conversion error mapping
- Clone conversation_state to avoid ownership issues
- Enhance non-stream request handler with state, session_id, and conversion_result parameters
- Improve request context preservation across streaming and non-streaming paths
- Remove tracing_subscriber initialization from run() function
- Logging setup is now handled elsewhere in the application startup
- Simplifies main function and reduces code duplication
- Add credential_id tracking to buffered stream request handling
- Implement statistics recording for API calls with credential and model info
- Refactor create_buffered_sse_stream to create_buffered_sse_stream_with_stats
- Add BufferedStreamState struct to manage stream state with stats support
- Pass session_id and app_state to buffered stream handler for context
- Record error statistics when API calls fail with credential tracking
- Improve error handling for SSE response building with proper error responses
- Enhance stream processing to support real-time statistics collection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants