
    /cj $                        d Z ddlZi ddefddefddefd	d
efddefddefddefddefddd fddefddefddefddefddefdd efd!d"efd#d$efi d%d&efd'd(efd)d*efd+d,efd-d.efd/d0efd1d2efd3d4efd5d6efd7d8efd9d:efd;d<efd=d>efd?d@efdAdBefdCdDefdEdFdG fdHdI fdJdK fdLZdM ZdN ZdS )Oz
Profile configuration mapping for the Qwen Pipeline.

Converts ChromaDB profile data (HTML element IDs from the dashboard)
into server config dicts that PipelineSession expects.
    N
agentANameagent_a_name	agentData
agent_datavadThresholdvad_thresholdsilenceDurationsilence_duration_msbargeInEnabledbarge_in_enabledbargeInMinDurationbarge_in_min_duration_msllmModel	llm_modeltemperature	maxTokens
max_tokensc                 (    | rt          |           nd S N)intvs    L/home/m1-ai/DEPLOYMENTS/AI-PHONE/ZACK-UPDATE/fixing_leaked/profile_config.py<lambda>r      s    A2G#a&&&4     topPtop_penableThinkingenable_thinkingttsModetts_modetoolRoutingtool_routing
speechRatespeech_rate	pitchRate
pitch_rate	ttsVolume
tts_volumeenableLanguageAgentenable_language_agentlanguageAgentGreetinglanguage_agent_greetinglanguageAgentInstructionslanguage_agent_instructionstransferDelaytransfer_delaysttProviderstt_providergeminiModelgemini_modelgeminiLangHintgemini_lang_hint
enableOmnienable_omni	omniModel
omni_model	omniVoice
omni_voiceomniSpeechStyleomni_speech_styleomniBargeInRmsomni_barge_in_rmsomniSmoothBargeInomni_smooth_barge_innoiseSuppressionnoise_suppressionidleTimeoutEnabledidle_timeout_enabledidleTimeoutSecondsidle_timeout_somniAudioBufferDelayomni_audio_buffer_delayvariableMappingsvariable_mappingsc                 \    t          | t                    rt          j        |           n| pg S r   
isinstancestrjsonloadsr   s    r   r   r   1   s*    TUWZI[I[8j
1bcbigi r   disabled_builtin_toolsc                 \    t          | t                    rt          j        |           n| pg S r   rO   r   s    r   r   r   2   s+    R\]^`cRdRdAsAklkrpr r   placeholder_fieldsc                 \    t          | t                    rt          j        |           n| pi S r   rO   r   s    r   r   r   3   s*    :VWY\K]K]:l$*Q---dedkik r   )disabledBuiltinToolsplaceholderFieldsc                 V	   ddi}t                                           D ];\  }\  }}|| vr| |         }	  ||          ||<   %# t          t          f$ r Y 8w xY wdD ]\  }}|| vr
| |         }t	          |t
                    rx|                                }|                    d          rO	 t          j	        |          }t	          |t                    r|}n"# t          j        t          t          f$ r Y nw xY w|||<   d| v ri	 | d         }t	          |t
                    rt          j	        |          }t	          |t                    r||d<   n# t          j        t          f$ r Y nw xY wd| v ri	 | d         }	t	          |	t
                    rt          j	        |	          }	t	          |	t                    r|	|d<   n# t          j        t          f$ r Y nw xY wd	| v ri	 | d	         }
t	          |
t
                    rt          j	        |
          }
t	          |
t                    r|
|d	<   n# t          j        t          f$ r Y nw xY wd
| v ri	 | d
         }t	          |t
                    rt          j	        |          }t	          |t                    r||d<   n# t          j        t          f$ r Y nw xY wd| v ri	 | d         }t	          |t
                    rt          j	        |          }t	          |t                    r||d<   n# t          j        t          f$ r Y nw xY wd| v rW	 t          j	        | d                   }t	          |t                    r||d<   n!# t          j        t          f$ r g |d<   Y nw xY wd| v ri	 | d         }t	          |t
                    rt          j	        |          }t	          |t                    r||d<   n# t          j        t          f$ r Y nw xY wd| v ri	 | d         }t	          |t
                    rt          j	        |          }t	          |t                    r||d<   n# t          j        t          f$ r Y nw xY wd| v rNd|vrJ|                     d          }|dv r1|                     dd          |                     dd          dg|d<   |S )zFConvert a ChromaDB profile (HTML element IDs) to a server config dict.typeconfig))fixedGreetingfixed_greeting)agentAReturnedGreetingagent_a_returned_greeting)instructionsra   {voiceMap	voice_mapomniVoiceMapomni_voice_mapacrsconversationValidatorconversation_validatoremotionConfigemotionfunctionsTextareacustom_toolstransferAgentstransfer_agentsallowedLanguagesallowed_languagesenableAgentB)Ttrue1   
agentBNamezSales DepartmentagentBInstructionszYou are a sales representative. Help the caller with product information, pricing, and purchases. Be friendly and professional. Keep responses brief (2-3 sentences). This is a live phone call.)namera   )PROFILE_TO_CONFIG_MAPitems
ValueError	TypeErrorrP   rQ   strip
startswithrR   rS   dictJSONDecodeErrorlistget)profile_datar\   profile_key
config_key	convertervalstrippedparsedvmovmrg   cvemotoolstaalenableds                    r   profile_to_configr   7   s   hF0E0K0K0M0M  ,,j)l**;'	!*3F:I& 	 	 	D	
$ ! !Z
 l**;'c3 		yy{{H""3'' !Z11F!&$// %$,j)D   D z \!!	j)B"c"" $Z^^"d## )&({#$i0 	 	 	D	 %%	~.C#s## &joo#t$$ /+.'($i0 	 	 	D	 	'D$$$ (z$''$%% &!%v$i0 	 	 	D	 ,..	56B"c"" $Z^^"d## 635/0$i0 	 	 	D	 ,&&	/C#s## &joo#t$$ ($'y!$i0 	 	 	D	 l**	(J|,?@AAE%&& /).~&$i0 	( 	( 	(%'F>"""	( <''	./B"c"" $Z^^"d## /,.()$i0 	 	 	D	 \))	01B"c"" $Z^^"d## 1.0*+$i0 	 	 	D	 %%*;6*I*I"">22,,,$((7IJJ , 0 01EW!X !X* * )F$% Ms   AAA-+CC87C8AE E+*E+3AF? ?GG AH, ,IIAJ J21J2:AL LL'4M M:9M:AO O'&O'/AP; ;QQc           
      *   |sdS 	 |                     | g          }|d         rt          j        |d         d                   }t          |          }|                     dd          }t	          |          }t          d|  d	t          |           d
|dd          d           |                     dd          }|r(t          dt	          |          dd          d           |S n)# t          $ r}t          d|            Y d}~nd}~ww xY wdS )zLoad a profile from ChromaDB and return it as a config dict, or None.

    Args:
        profile_name: The profile ID to load.
        profiles_collection: The ChromaDB collection for profiles.
    N)idsr   	documentsr   ra    z[Profiles] Loaded "u   " — instructions: z
 chars = "x   z..."r^   z[Profiles] Fixed greeting: "P   z[Profiles] Load error: )r   rR   rS   r   rQ   printlen	Exception)	profile_nameprofiles_collectionresultr   r\   instr	instr_strgreetinges	            r   load_profile_configr      sw     t-$((l^(<<%= 	:f[&9!&<==L&|44F JJ~r22EE

I S S S#&y>>S S=Ftt_S S S T T Tzz"2B77H OMS]]3B35GMMMNNNM	  - - -+++,,,,,,,,-4s   C"C* *
D4DD)	__doc__rR   rQ   floatr   boolry   r   r    r   r   <module>r      s    
'.#.' ,,	'
 /51' /5' ,d3' 4c:' +s+' -/' ,(G(GH' '5)' +T2' *c*' .#.'  -/!'" ,.#'$ ,,%'& 3T:'' '( 7=)'*  "?!E+', &.-'. nc*/'0 nc*1'2 )3/3'4 mT*5'6 lC(7'8 lC(9': +S1;'< *E2='> 0$7?'@ ,c2A'B 148C'D +S1E'F 6>G'H ,.j.jkI' 'J 67s7st.0l0lmM' ' ' TD D DN    r   