@@ -19,40 +19,109 @@ pub mod tool_manager;
1919pub mod tools;
2020pub mod util;
2121use std:: borrow:: Cow ;
22- use std:: collections:: { HashMap , VecDeque } ;
23- use std:: io:: { IsTerminal , Read , Write } ;
22+ use std:: collections:: {
23+ HashMap ,
24+ VecDeque ,
25+ } ;
26+ use std:: io:: {
27+ IsTerminal ,
28+ Read ,
29+ Write ,
30+ } ;
2431use std:: process:: ExitCode ;
2532use std:: sync:: Arc ;
26- use std:: time:: { Duration , Instant } ;
33+ use std:: time:: {
34+ Duration ,
35+ Instant ,
36+ } ;
2737
2838use amzn_codewhisperer_client:: types:: SubscriptionStatus ;
29- use clap:: { Args , CommandFactory , Parser } ;
39+ use clap:: {
40+ Args ,
41+ CommandFactory ,
42+ Parser ,
43+ } ;
3044use cli:: compact:: CompactStrategy ;
31- use cli:: model:: { get_available_models, select_model} ;
45+ use cli:: model:: {
46+ get_available_models,
47+ select_model,
48+ } ;
3249pub use conversation:: ConversationState ;
3350use conversation:: TokenWarningLevel ;
34- use crossterm:: style:: { Attribute , Color , Stylize } ;
35- use crossterm:: { cursor, execute, queue, style, terminal} ;
36- use tool_manager:: { PromptQuery , PromptQueryResult } ;
37- use eyre:: { Report , Result , bail, eyre} ;
51+ use crossterm:: style:: {
52+ Attribute ,
53+ Color ,
54+ Stylize ,
55+ } ;
56+ use crossterm:: {
57+ cursor,
58+ execute,
59+ queue,
60+ style,
61+ terminal,
62+ } ;
63+ use eyre:: {
64+ Report ,
65+ Result ,
66+ bail,
67+ eyre,
68+ } ;
3869use input_source:: InputSource ;
39- use message:: { AssistantMessage , AssistantToolUse , ToolUseResult , ToolUseResultBlock } ;
40- use parse:: { ParseState , interpret_markdown} ;
41- use parser:: { RecvErrorKind , RequestMetadata , SendMessageStream } ;
70+ use message:: {
71+ AssistantMessage ,
72+ AssistantToolUse ,
73+ ToolUseResult ,
74+ ToolUseResultBlock ,
75+ } ;
76+ use parse:: {
77+ ParseState ,
78+ interpret_markdown,
79+ } ;
80+ use parser:: {
81+ RecvErrorKind ,
82+ RequestMetadata ,
83+ SendMessageStream ,
84+ } ;
4285use regex:: Regex ;
43- use spinners:: { Spinner , Spinners } ;
86+ use spinners:: {
87+ Spinner ,
88+ Spinners ,
89+ } ;
4490use thiserror:: Error ;
4591use time:: OffsetDateTime ;
4692use token_counter:: TokenCounter ;
4793use tokio:: signal:: ctrl_c;
48- use tokio:: sync:: { Mutex , broadcast} ;
49- use tool_manager:: { ToolManager , ToolManagerBuilder } ;
94+ use tokio:: sync:: {
95+ Mutex ,
96+ broadcast,
97+ } ;
98+ use tool_manager:: {
99+ PromptQuery ,
100+ PromptQueryResult ,
101+ ToolManager ,
102+ ToolManagerBuilder ,
103+ } ;
50104use tools:: gh_issue:: GhIssueContext ;
51- use tools:: { NATIVE_TOOLS , OutputKind , QueuedTool , Tool , ToolSpec } ;
52- use tracing:: { debug, error, info, trace, warn} ;
105+ use tools:: {
106+ NATIVE_TOOLS ,
107+ OutputKind ,
108+ QueuedTool ,
109+ Tool ,
110+ ToolSpec ,
111+ } ;
112+ use tracing:: {
113+ debug,
114+ error,
115+ info,
116+ trace,
117+ warn,
118+ } ;
53119use util:: images:: RichImageBlock ;
54120use util:: ui:: draw_box;
55- use util:: { animate_output, play_notification_bell} ;
121+ use util:: {
122+ animate_output,
123+ play_notification_bell,
124+ } ;
56125use winnow:: Partial ;
57126use winnow:: stream:: Offset ;
58127
@@ -61,22 +130,36 @@ use super::agent::{
61130 PermissionEvalResult ,
62131} ;
63132use crate :: api_client:: model:: ToolResultStatus ;
64- use crate :: api_client:: { self , ApiClientError } ;
133+ use crate :: api_client:: {
134+ self ,
135+ ApiClientError ,
136+ } ;
65137use crate :: auth:: AuthError ;
66138use crate :: auth:: builder_id:: is_idc_user;
67139use crate :: cli:: agent:: Agents ;
68140use crate :: cli:: chat:: cli:: SlashCommand ;
69141use crate :: cli:: chat:: cli:: model:: find_model;
70- use crate :: cli:: chat:: cli:: prompts:: { GetPromptError , PromptsSubcommand } ;
142+ use crate :: cli:: chat:: cli:: prompts:: {
143+ GetPromptError ,
144+ PromptsSubcommand ,
145+ } ;
71146use crate :: cli:: chat:: util:: sanitize_unicode_tags;
72147use crate :: database:: settings:: Setting ;
73148use crate :: mcp_client:: Prompt ;
74149use crate :: os:: Os ;
75150use crate :: telemetry:: core:: {
76- AgentConfigInitArgs , ChatAddedMessageParams , ChatConversationType , MessageMetaTag , RecordUserTurnCompletionArgs ,
151+ AgentConfigInitArgs ,
152+ ChatAddedMessageParams ,
153+ ChatConversationType ,
154+ MessageMetaTag ,
155+ RecordUserTurnCompletionArgs ,
77156 ToolUseEventBuilder ,
78157} ;
79- use crate :: telemetry:: { ReasonCode , TelemetryResult , get_error_reason} ;
158+ use crate :: telemetry:: {
159+ ReasonCode ,
160+ TelemetryResult ,
161+ get_error_reason,
162+ } ;
80163use crate :: util:: MCP_SERVER_TOOL_DELIMITER ;
81164
82165const LIMIT_REACHED_TEXT : & str = color_print:: cstr! { "You've used all your free requests for this month. You have two options:
@@ -189,17 +272,13 @@ impl ChatArgs {
189272 agents. trust_all_tools = self . trust_all_tools ;
190273
191274 os. telemetry
192- . send_agent_config_init (
193- & os. database ,
194- conversation_id. clone ( ) ,
195- AgentConfigInitArgs {
196- agents_loaded_count : md. load_count as i64 ,
197- agents_loaded_failed_count : md. load_failed_count as i64 ,
198- legacy_profile_migration_executed : md. migration_performed ,
199- legacy_profile_migrated_count : md. migrated_count as i64 ,
200- launched_agent : md. launched_agent ,
201- } ,
202- )
275+ . send_agent_config_init ( & os. database , conversation_id. clone ( ) , AgentConfigInitArgs {
276+ agents_loaded_count : md. load_count as i64 ,
277+ agents_loaded_failed_count : md. load_failed_count as i64 ,
278+ legacy_profile_migration_executed : md. migration_performed ,
279+ legacy_profile_migrated_count : md. migrated_count as i64 ,
280+ launched_agent : md. launched_agent ,
281+ } )
203282 . await
204283 . map_err ( |err| error ! ( ?err, "failed to send agent config init telemetry" ) )
205284 . ok ( ) ;
@@ -2693,31 +2772,26 @@ impl ChatSession {
26932772 } ;
26942773
26952774 os. telemetry
2696- . send_record_user_turn_completion (
2697- & os. database ,
2698- conversation_id,
2699- result,
2700- RecordUserTurnCompletionArgs {
2701- message_ids : mds. iter ( ) . map ( |md| md. message_id . clone ( ) ) . collect :: < _ > ( ) ,
2702- request_ids : mds. iter ( ) . map ( |md| md. request_id . clone ( ) ) . collect :: < _ > ( ) ,
2703- reason,
2704- reason_desc,
2705- status_code,
2706- time_to_first_chunks_ms : mds
2707- . iter ( )
2708- . map ( |md| md. time_to_first_chunk . map ( |d| d. as_secs_f64 ( ) * 1000.0 ) )
2709- . collect :: < _ > ( ) ,
2710- chat_conversation_type : md. and_then ( |md| md. chat_conversation_type ) ,
2711- assistant_response_length : mds. iter ( ) . map ( |md| md. response_size as i64 ) . sum ( ) ,
2712- message_meta_tags : mds. last ( ) . map ( |md| md. message_meta_tags . clone ( ) ) . unwrap_or_default ( ) ,
2713- user_prompt_length : mds. first ( ) . map ( |md| md. user_prompt_length ) . unwrap_or_default ( ) as i64 ,
2714- user_turn_duration_seconds,
2715- follow_up_count : mds
2716- . iter ( )
2717- . filter ( |md| matches ! ( md. chat_conversation_type, Some ( ChatConversationType :: ToolUse ) ) )
2718- . count ( ) as i64 ,
2719- } ,
2720- )
2775+ . send_record_user_turn_completion ( & os. database , conversation_id, result, RecordUserTurnCompletionArgs {
2776+ message_ids : mds. iter ( ) . map ( |md| md. message_id . clone ( ) ) . collect :: < _ > ( ) ,
2777+ request_ids : mds. iter ( ) . map ( |md| md. request_id . clone ( ) ) . collect :: < _ > ( ) ,
2778+ reason,
2779+ reason_desc,
2780+ status_code,
2781+ time_to_first_chunks_ms : mds
2782+ . iter ( )
2783+ . map ( |md| md. time_to_first_chunk . map ( |d| d. as_secs_f64 ( ) * 1000.0 ) )
2784+ . collect :: < _ > ( ) ,
2785+ chat_conversation_type : md. and_then ( |md| md. chat_conversation_type ) ,
2786+ assistant_response_length : mds. iter ( ) . map ( |md| md. response_size as i64 ) . sum ( ) ,
2787+ message_meta_tags : mds. last ( ) . map ( |md| md. message_meta_tags . clone ( ) ) . unwrap_or_default ( ) ,
2788+ user_prompt_length : mds. first ( ) . map ( |md| md. user_prompt_length ) . unwrap_or_default ( ) as i64 ,
2789+ user_turn_duration_seconds,
2790+ follow_up_count : mds
2791+ . iter ( )
2792+ . filter ( |md| matches ! ( md. chat_conversation_type, Some ( ChatConversationType :: ToolUse ) ) )
2793+ . count ( ) as i64 ,
2794+ } )
27212795 . await
27222796 . ok ( ) ;
27232797 }
0 commit comments