@@ -96,92 +96,6 @@ impl AiTranscript {
9696 messages : filtered_messages,
9797 }
9898 }
99-
100- /// Parse a Claude Code JSONL file into a transcript and extract model info
101- pub fn from_claude_code_jsonl_with_model (
102- jsonl_content : & str ,
103- ) -> Result < ( Self , Option < String > ) , serde_json:: Error > {
104- let mut transcript = AiTranscript :: new ( ) ;
105- let mut model = None ;
106-
107- for line in jsonl_content. lines ( ) {
108- if !line. trim ( ) . is_empty ( ) {
109- // Parse the raw JSONL entry
110- let raw_entry: serde_json:: Value = serde_json:: from_str ( line) ?;
111- let timestamp = raw_entry[ "timestamp" ] . as_str ( ) . map ( |s| s. to_string ( ) ) ;
112-
113- // Extract model from assistant messages if we haven't found it yet
114- if model. is_none ( ) && raw_entry[ "type" ] . as_str ( ) == Some ( "assistant" ) {
115- if let Some ( model_str) = raw_entry[ "message" ] [ "model" ] . as_str ( ) {
116- model = Some ( model_str. to_string ( ) ) ;
117- }
118- }
119-
120- // Extract messages based on the type
121- match raw_entry[ "type" ] . as_str ( ) {
122- Some ( "user" ) => {
123- // Handle user messages
124- if let Some ( content) = raw_entry[ "message" ] [ "content" ] . as_str ( ) {
125- if !content. trim ( ) . is_empty ( ) {
126- transcript. add_message ( Message :: User {
127- text : content. to_string ( ) ,
128- timestamp : timestamp. clone ( ) ,
129- } ) ;
130- }
131- } else if let Some ( content_array) =
132- raw_entry[ "message" ] [ "content" ] . as_array ( )
133- {
134- // Handle user messages with content array (like tool results)
135- for item in content_array {
136- if let Some ( text) = item[ "content" ] . as_str ( ) {
137- if !text. trim ( ) . is_empty ( ) {
138- transcript. add_message ( Message :: User {
139- text : text. to_string ( ) ,
140- timestamp : timestamp. clone ( ) ,
141- } ) ;
142- }
143- }
144- }
145- }
146- }
147- Some ( "assistant" ) => {
148- // Handle assistant messages
149- if let Some ( content_array) = raw_entry[ "message" ] [ "content" ] . as_array ( ) {
150- for item in content_array {
151- match item[ "type" ] . as_str ( ) {
152- Some ( "text" ) => {
153- if let Some ( text) = item[ "text" ] . as_str ( ) {
154- if !text. trim ( ) . is_empty ( ) {
155- transcript. add_message ( Message :: Assistant {
156- text : text. to_string ( ) ,
157- timestamp : timestamp. clone ( ) ,
158- } ) ;
159- }
160- }
161- }
162- Some ( "tool_use" ) => {
163- if let ( Some ( name) , Some ( _input) ) =
164- ( item[ "name" ] . as_str ( ) , item[ "input" ] . as_object ( ) )
165- {
166- transcript. add_message ( Message :: ToolUse {
167- name : name. to_string ( ) ,
168- input : item[ "input" ] . clone ( ) ,
169- timestamp : timestamp. clone ( ) ,
170- } ) ;
171- }
172- }
173- _ => continue , // Skip unknown content types
174- }
175- }
176- }
177- }
178- _ => continue , // Skip unknown message types
179- }
180- }
181- }
182-
183- Ok ( ( transcript, model) )
184- }
18599}
186100
187101impl Default for AiTranscript {
0 commit comments