okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
61c43ca
main
1"""Scripted upstream events for real-daemon workflows. No daemon wire fixtures.""" 2 3 4def chat_events (reply ,arguments ,call_id ,chunk_size ): 5if reply .reasoning : 6yield ( 7 { 8"id" :"fixture" , 9"choices" : [ 10 { 11"index" :0 , 12"delta" : {"reasoning_content" :reply .reasoning }, 13"finish_reason" :None , 14 } 15 ], 16 } 17 ) 18if reply .kind == "python" : 19for offset in range (0 ,len (arguments ),chunk_size ): 20tool_call :dict [str ,object ]= { 21"index" :0 , 22"function" : {"arguments" :arguments [offset :offset + chunk_size ]}, 23 } 24if offset == 0 : 25tool_call .update ( 26 { 27"id" :call_id , 28"type" :"function" , 29"function" : { 30"name" :reply .tool_name , 31"arguments" :arguments [:chunk_size ], 32 }, 33 } 34 ) 35delta = {"tool_calls" : [tool_call ]} 36yield ( 37 { 38"id" :"fixture" , 39"choices" : [{"index" :0 ,"delta" :delta ,"finish_reason" :None }], 40 } 41 ) 42yield ( 43 { 44"id" :"fixture" , 45"choices" : [{"index" :0 ,"delta" : {},"finish_reason" :"tool_calls" }], 46 } 47 ) 48else : 49for offset in range (0 ,len (reply .value ),chunk_size ): 50yield ( 51 { 52"id" :"fixture" , 53"choices" : [ 54 { 55"index" :0 , 56"delta" : { 57"content" :reply .value [offset :offset + chunk_size ] 58 }, 59"finish_reason" :None , 60 } 61 ], 62 } 63 ) 64yield ( 65 { 66"id" :"fixture" , 67"choices" : [{"index" :0 ,"delta" : {},"finish_reason" :"stop" }], 68 } 69 ) 70 71 72def responses_events (reply ,arguments ,call_id ,chunk_size ): 73yield ({"type" :"response.created" ,"response" : {"id" :"fixture" }}) 74output = [] 75if reply .reasoning : 76yield ( 77 { 78"type" :"response.reasoning_summary_text.delta" , 79"output_index" :0 , 80"summary_index" :0 , 81"delta" :reply .reasoning , 82 } 83 ) 84output .append ( 85 { 86"id" :"reasoning" , 87"type" :"reasoning" , 88"summary" : [{"type" :"summary_text" ,"text" :reply .reasoning }], 89 } 90 ) 91if reply .kind == "python" : 92yield ( 93 { 94"type" :"response.output_item.added" , 95"output_index" :0 , 96"item" : { 97"id" :"call" , 98"type" :"function_call" , 99"call_id" :call_id , 100"name" :reply .tool_name , 101 }, 102 } 103 ) 104for offset in range (0 ,len (arguments ),chunk_size ): 105yield ( 106 { 107"type" :"response.function_call_arguments.delta" , 108"output_index" :0 , 109"delta" :arguments [offset :offset + chunk_size ], 110 } 111 ) 112output .append ( 113 { 114"id" :"call" , 115"type" :"function_call" , 116"call_id" :call_id , 117"name" :reply .tool_name , 118"arguments" :arguments , 119"status" :"completed" , 120 } 121 ) 122else : 123for offset in range (0 ,len (reply .value ),chunk_size ): 124yield ( 125 { 126"type" :"response.output_text.delta" , 127"output_index" :0 , 128"content_index" :0 , 129"delta" :reply .value [offset :offset + chunk_size ], 130 } 131 ) 132output .append ( 133 { 134"id" :"message" , 135"type" :"message" , 136"role" :"assistant" , 137"status" :"completed" , 138"content" : [ 139 { 140"type" :"output_text" , 141"text" :reply .value , 142"annotations" : [], 143 } 144 ], 145 } 146 ) 147completed = {"id" :"fixture" ,"status" :"completed" ,"output" :output } 148if reply .usage is not None : 149completed ["usage" ]= reply .usage 150yield ({"type" :"response.completed" ,"response" :completed })