melara 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- melara/__init__.py +13 -0
- melara/_hooks/__init__.py +3 -0
- melara/_hooks/registration.py +13 -0
- melara/_hooks/sdkhooks.py +74 -0
- melara/_hooks/types.py +122 -0
- melara/_version.py +13 -0
- melara/basesdk.py +405 -0
- melara/beta.py +21 -0
- melara/beta_responses.py +3 -0
- melara/chat.py +1912 -0
- melara/components/__init__.py +4934 -0
- melara/components/additionaltoolsitem.py +281 -0
- melara/components/agentmessageitem.py +214 -0
- melara/components/alignment.py +19 -0
- melara/components/alignmentallowedcallrecord.py +26 -0
- melara/components/alignmentblockedcallrecord.py +26 -0
- melara/components/alignmentcallrecord.py +66 -0
- melara/components/alignmentchataudio.py +40 -0
- melara/components/alignmentchatimage.py +26 -0
- melara/components/alignmentchatrejected.py +65 -0
- melara/components/alignmentchattoolcall.py +32 -0
- melara/components/alignmentplugin.py +71 -0
- melara/components/alignmentrejected.py +19 -0
- melara/components/alignmentresponsesrejected.py +102 -0
- melara/components/alignmentrulerecord.py +18 -0
- melara/components/alignmentunavailablecallrecord.py +34 -0
- melara/components/annotationaddedevent.py +41 -0
- melara/components/anthropicadvisormessageusageiteration.py +77 -0
- melara/components/anthropiccachecontroldirective.py +40 -0
- melara/components/anthropiccachecontrolttl.py +12 -0
- melara/components/anthropiccachecreation.py +14 -0
- melara/components/anthropiccompactionusageiteration.py +74 -0
- melara/components/anthropiciterationcachecreation.py +34 -0
- melara/components/anthropicmessageusageiteration.py +78 -0
- melara/components/anthropicspeed.py +12 -0
- melara/components/anthropicunknownusageiteration.py +71 -0
- melara/components/anthropicusageiteration.py +41 -0
- melara/components/apierrortype.py +38 -0
- melara/components/applypatchcallitem.py +72 -0
- melara/components/applypatchcalloperation.py +68 -0
- melara/components/applypatchcalloperationdiffdeltaevent.py +33 -0
- melara/components/applypatchcalloperationdiffdoneevent.py +33 -0
- melara/components/applypatchcalloutputitem.py +73 -0
- melara/components/applypatchcallstatus.py +13 -0
- melara/components/applypatchcreatefileoperation.py +25 -0
- melara/components/applypatchdeletefileoperation.py +22 -0
- melara/components/applypatchservertool.py +19 -0
- melara/components/applypatchupdatefileoperation.py +25 -0
- melara/components/autobetarouterplugin.py +84 -0
- melara/components/autorouterplugin.py +90 -0
- melara/components/badgatewayresponseerrordata.py +54 -0
- melara/components/badrequestresponseerrordata.py +54 -0
- melara/components/baseinputs_union.py +242 -0
- melara/components/basereasoningconfig.py +60 -0
- melara/components/chatassistantimages.py +21 -0
- melara/components/chatassistantmessage.py +125 -0
- melara/components/chataudiooutput.py +50 -0
- melara/components/chatchoice.py +65 -0
- melara/components/chatcontentaudio.py +44 -0
- melara/components/chatcontentcachecontrol.py +40 -0
- melara/components/chatcontentfile.py +59 -0
- melara/components/chatcontentimage.py +66 -0
- melara/components/chatcontentitems.py +74 -0
- melara/components/chatcontenttext.py +69 -0
- melara/components/chatcontentvideo.py +25 -0
- melara/components/chatcontentvideoinput.py +50 -0
- melara/components/chatdebugoptions.py +35 -0
- melara/components/chatdevelopermessage.py +101 -0
- melara/components/chatdynamicservertool.py +36 -0
- melara/components/chatfinishreasonenum.py +15 -0
- melara/components/chatformatgrammarconfig.py +24 -0
- melara/components/chatformatjsonobjectconfig.py +19 -0
- melara/components/chatformatjsonschemaconfig.py +25 -0
- melara/components/chatformatpythonconfig.py +19 -0
- melara/components/chatformattextconfig.py +19 -0
- melara/components/chatfunctiontool.py +149 -0
- melara/components/chatjsonschemaconfig.py +72 -0
- melara/components/chatmessages.py +36 -0
- melara/components/chatnamedtoolchoice.py +32 -0
- melara/components/chatreasoningsummaryverbosityenum.py +13 -0
- melara/components/chatrequest.py +548 -0
- melara/components/chatresult.py +89 -0
- melara/components/chatservertoolchoice.py +17 -0
- melara/components/chatstreamchoice.py +65 -0
- melara/components/chatstreamchunk.py +178 -0
- melara/components/chatstreamdelta.py +95 -0
- melara/components/chatstreamingresponse.py +14 -0
- melara/components/chatstreamoptions.py +35 -0
- melara/components/chatstreamtoolcall.py +89 -0
- melara/components/chatsystemmessage.py +99 -0
- melara/components/chattokenlogprob.py +87 -0
- melara/components/chattokenlogprobs.py +56 -0
- melara/components/chattoolcall.py +42 -0
- melara/components/chattoolchoice.py +40 -0
- melara/components/chattoolmessage.py +42 -0
- melara/components/chatusage.py +228 -0
- melara/components/chatusermessage.py +59 -0
- melara/components/chatwebsearchshorthand.py +126 -0
- melara/components/codeinterpretercallcodedeltaevent.py +33 -0
- melara/components/codeinterpretercallcodedoneevent.py +33 -0
- melara/components/codeinterpretercallcompletedevent.py +30 -0
- melara/components/codeinterpretercallinprogressevent.py +30 -0
- melara/components/codeinterpretercallinterpretingevent.py +30 -0
- melara/components/codeinterpreterfileoutput.py +94 -0
- melara/components/codeinterpreterimageoutput.py +18 -0
- melara/components/codeinterpreterlogsoutput.py +18 -0
- melara/components/codeinterpreterservertool.py +91 -0
- melara/components/compactionitem.py +74 -0
- melara/components/compoundfilter.py +28 -0
- melara/components/computeruseservertool.py +40 -0
- melara/components/configurationupdateitem.py +63 -0
- melara/components/configurationupdatereasoning.py +33 -0
- melara/components/contentpartaddedevent.py +90 -0
- melara/components/contentpartdoneevent.py +90 -0
- melara/components/contentpartimage.py +26 -0
- melara/components/contentpartinputaudio.py +19 -0
- melara/components/contentpartinputfile.py +19 -0
- melara/components/contentpartinputvideo.py +19 -0
- melara/components/contextcompactionitem.py +74 -0
- melara/components/contextcompressionengine.py +6 -0
- melara/components/contextcompressionplugin.py +43 -0
- melara/components/costdetails.py +58 -0
- melara/components/customtool.py +135 -0
- melara/components/customtoolcallinputdeltaevent.py +31 -0
- melara/components/customtoolcallinputdoneevent.py +31 -0
- melara/components/customtoolcallitem.py +84 -0
- melara/components/customtoolcalloutputitem.py +147 -0
- melara/components/debugevent.py +78 -0
- melara/components/deferredbm25search.py +39 -0
- melara/components/deferredcustomsearch.py +45 -0
- melara/components/deferredregexsearch.py +39 -0
- melara/components/deferredtoolscontrol.py +46 -0
- melara/components/deferredtoolssearchstrategy.py +30 -0
- melara/components/easyinputmessage.py +213 -0
- melara/components/edgenetworktimeoutresponseerrordata.py +54 -0
- melara/components/errorevent.py +46 -0
- melara/components/failabletoolcallstatus.py +14 -0
- melara/components/filecitation.py +24 -0
- melara/components/fileparserplugin.py +43 -0
- melara/components/filepath.py +21 -0
- melara/components/filesearchservertool.py +158 -0
- melara/components/forbiddenresponseerrordata.py +54 -0
- melara/components/formatjsonobjectconfig.py +19 -0
- melara/components/formatjsonschemaconfig.py +70 -0
- melara/components/formats.py +62 -0
- melara/components/formattextconfig.py +19 -0
- melara/components/functioncallargsdeltaevent.py +31 -0
- melara/components/functioncallargsdoneevent.py +34 -0
- melara/components/functioncallitem.py +119 -0
- melara/components/functioncalloutputitem.py +160 -0
- melara/components/fusionanalysisresult.py +72 -0
- melara/components/fusioncallanalysiscompletedevent.py +36 -0
- melara/components/fusioncallanalysisinprogressevent.py +46 -0
- melara/components/fusioncallcompletedevent.py +28 -0
- melara/components/fusioncallinprogressevent.py +28 -0
- melara/components/fusioncallpaneladdedevent.py +31 -0
- melara/components/fusioncallpanelcompletedevent.py +34 -0
- melara/components/fusioncallpaneldeltaevent.py +34 -0
- melara/components/fusioncallpanelfailedevent.py +54 -0
- melara/components/fusioncallpanelreasoningdeltaevent.py +36 -0
- melara/components/fusionplugin.py +138 -0
- melara/components/gatewaytimeoutresponseerrordata.py +54 -0
- melara/components/imageconfig.py +11 -0
- melara/components/imagegencallcompletedevent.py +28 -0
- melara/components/imagegencallgeneratingevent.py +28 -0
- melara/components/imagegencallinprogressevent.py +28 -0
- melara/components/imagegencallpartialimageevent.py +36 -0
- melara/components/imagegencompletedevent.py +60 -0
- melara/components/imagegenerationproviderpreferences.py +758 -0
- melara/components/imagegenerationrequest.py +224 -0
- melara/components/imagegenerationresponse.py +81 -0
- melara/components/imagegenerationservertool.py +171 -0
- melara/components/imagegenerationstatus.py +14 -0
- melara/components/imagegenerationusage.py +318 -0
- melara/components/imagegenpartialimageevent.py +32 -0
- melara/components/imagegenstreamerrorevent.py +88 -0
- melara/components/imagegentextchunkevent.py +43 -0
- melara/components/imagestreamingresponse.py +81 -0
- melara/components/incompletedetails.py +38 -0
- melara/components/inputaudio.py +49 -0
- melara/components/inputfile.py +63 -0
- melara/components/inputimage.py +72 -0
- melara/components/inputmessageitem.py +175 -0
- melara/components/inputs_union.py +399 -0
- melara/components/inputtext.py +60 -0
- melara/components/inputvideo.py +56 -0
- melara/components/internalserverresponseerrordata.py +54 -0
- melara/components/itemreferenceitem.py +22 -0
- melara/components/jevrouterplugin.py +54 -0
- melara/components/legacy_chatcontentvideo.py +35 -0
- melara/components/legacy_chatcontentvideoinput.py +50 -0
- melara/components/legacy_websearchservertool.py +106 -0
- melara/components/localshellcallitem.py +90 -0
- melara/components/localshellcalloutputitem.py +61 -0
- melara/components/localshelltool.py +19 -0
- melara/components/mcpapprovalrequestitem.py +31 -0
- melara/components/mcpapprovalresponseitem.py +63 -0
- melara/components/mcpcallitem.py +72 -0
- melara/components/mcphttperror.py +25 -0
- melara/components/mcplisttoolsitem.py +105 -0
- melara/components/mcpprotocolerror.py +25 -0
- melara/components/mcpservertool.py +229 -0
- melara/components/mcptoolcallerror.py +25 -0
- melara/components/mcptoolexecutionerror.py +39 -0
- melara/components/model.py +26 -0
- melara/components/modelslistresponse.py +15 -0
- melara/components/moderationplugin.py +15 -0
- melara/components/multimodalmedia.py +39 -0
- melara/components/namespacefunctiontool.py +106 -0
- melara/components/namespacetool.py +70 -0
- melara/components/notfoundresponseerrordata.py +54 -0
- melara/components/openairesponsecustomtoolcall.py +61 -0
- melara/components/openairesponsecustomtoolcalloutput.py +101 -0
- melara/components/openairesponsefunctiontoolcall.py +100 -0
- melara/components/openairesponsefunctiontoolcalloutput.py +120 -0
- melara/components/openairesponseinputmessageitem.py +123 -0
- melara/components/openairesponsesannotation.py +48 -0
- melara/components/openairesponsesrefusalcontent.py +18 -0
- melara/components/openairesponsesresponsestatus.py +16 -0
- melara/components/openairesponsestoolchoice_union.py +114 -0
- melara/components/openairesponsestruncation.py +12 -0
- melara/components/openresponsescreatedevent.py +28 -0
- melara/components/openresponseserrorfield.py +74 -0
- melara/components/openresponseserrormetadata.py +70 -0
- melara/components/openresponsesinprogressevent.py +28 -0
- melara/components/openresponsesresult.py +605 -0
- melara/components/outputapplypatchcallitem.py +40 -0
- melara/components/outputcodeinterpretercallitem.py +157 -0
- melara/components/outputcomputercallitem.py +71 -0
- melara/components/outputcustomtoolcallitem.py +78 -0
- melara/components/outputfilesearchcallitem.py +25 -0
- melara/components/outputfunctioncallitem.py +126 -0
- melara/components/outputimagegenerationcallitem.py +60 -0
- melara/components/outputitemapplypatchcall.py +117 -0
- melara/components/outputitemcodeinterpretercall.py +153 -0
- melara/components/outputitemcustomtoolcall.py +74 -0
- melara/components/outputitemfilesearchcall.py +25 -0
- melara/components/outputitemfunctioncall.py +93 -0
- melara/components/outputitemimagegenerationcall.py +55 -0
- melara/components/outputitemreasoning.py +93 -0
- melara/components/outputitems.py +136 -0
- melara/components/outputitemwebsearchcall.py +207 -0
- melara/components/outputmessage.py +162 -0
- melara/components/outputmessageitem.py +168 -0
- melara/components/outputmodalityenum.py +12 -0
- melara/components/outputreasoningitem.py +117 -0
- melara/components/outputshellcallitem.py +99 -0
- melara/components/outputshellcalloutputitem.py +114 -0
- melara/components/outputtoolsearchcallitem.py +55 -0
- melara/components/outputwebsearchcallitem.py +207 -0
- melara/components/outputwebsearchservertoolitem.py +104 -0
- melara/components/paretorouterplugin.py +64 -0
- melara/components/payloadtoolargeresponseerrordata.py +54 -0
- melara/components/paymentrequiredresponseerrordata.py +54 -0
- melara/components/pdfparserengine.py +29 -0
- melara/components/pdfparseroptions.py +36 -0
- melara/components/percentilelatencycutoffs.py +64 -0
- melara/components/percentilethroughputcutoffs.py +64 -0
- melara/components/prediction.py +33 -0
- melara/components/predictioncontenttext.py +22 -0
- melara/components/preferredmaxlatency.py +19 -0
- melara/components/preferredminthroughput.py +20 -0
- melara/components/preview_20250311_websearchservertool.py +107 -0
- melara/components/preview_websearchservertool.py +107 -0
- melara/components/preview_websearchuserlocation.py +59 -0
- melara/components/promptcachebreakpoint.py +19 -0
- melara/components/promptcacheoptions.py +54 -0
- melara/components/providername.py +9 -0
- melara/components/provideroptions.py +632 -0
- melara/components/provideroverloadedresponseerrordata.py +54 -0
- melara/components/providerpreferences.py +280 -0
- melara/components/providersort.py +15 -0
- melara/components/providersortconfig.py +78 -0
- melara/components/quantization.py +22 -0
- melara/components/reasoningcontext.py +14 -0
- melara/components/reasoningdeltaevent.py +34 -0
- melara/components/reasoningdetailencrypted.py +73 -0
- melara/components/reasoningdetailservertoolcall.py +82 -0
- melara/components/reasoningdetailsummary.py +73 -0
- melara/components/reasoningdetailtext.py +76 -0
- melara/components/reasoningdetailunion.py +72 -0
- melara/components/reasoningdoneevent.py +34 -0
- melara/components/reasoningeffort.py +17 -0
- melara/components/reasoningformat.py +16 -0
- melara/components/reasoningitem.py +115 -0
- melara/components/reasoningmode.py +13 -0
- melara/components/reasoningsummarypartaddedevent.py +35 -0
- melara/components/reasoningsummarypartdoneevent.py +35 -0
- melara/components/reasoningsummarytext.py +18 -0
- melara/components/reasoningsummarytextdeltaevent.py +34 -0
- melara/components/reasoningsummarytextdoneevent.py +34 -0
- melara/components/reasoningsummaryverbosity.py +13 -0
- melara/components/reasoningtextcontent.py +18 -0
- melara/components/refusaldeltaevent.py +34 -0
- melara/components/refusaldoneevent.py +34 -0
- melara/components/requesttimeoutresponseerrordata.py +54 -0
- melara/components/responsehealingplugin.py +37 -0
- melara/components/responseincludesenum.py +15 -0
- melara/components/responseoutputtext.py +87 -0
- melara/components/responsesrequest.py +621 -0
- melara/components/responsesstreamingresponse.py +14 -0
- melara/components/searchcontextsizeenum.py +14 -0
- melara/components/searchqualitylevel.py +14 -0
- melara/components/security.py +40 -0
- melara/components/servertoolusedetails.py +63 -0
- melara/components/serviceunavailableresponseerrordata.py +54 -0
- melara/components/shellcallitem.py +111 -0
- melara/components/shellcalloutputcontent.py +126 -0
- melara/components/shellcalloutputitem.py +114 -0
- melara/components/shellcallstatus.py +14 -0
- melara/components/shellservertool.py +19 -0
- melara/components/speechinput.py +14 -0
- melara/components/speechinputreference.py +39 -0
- melara/components/speechinputreferenceaudio.py +28 -0
- melara/components/speechinputreferenceaudioinput.py +52 -0
- melara/components/speechinputreferenceimage.py +28 -0
- melara/components/speechinputreferenceimageinput.py +17 -0
- melara/components/speechinputreferencetext.py +24 -0
- melara/components/speechrequest.py +189 -0
- melara/components/speechturn.py +41 -0
- melara/components/stopservertoolswhencondition.py +51 -0
- melara/components/stopservertoolswhenfinishreasonis.py +22 -0
- melara/components/stopservertoolswhenhastoolcall.py +22 -0
- melara/components/stopservertoolswhenmaxcost.py +22 -0
- melara/components/stopservertoolswhenmaxtokensused.py +22 -0
- melara/components/stopservertoolswhenstepcountis.py +22 -0
- melara/components/storedprompttemplate.py +59 -0
- melara/components/streamevents.py +357 -0
- melara/components/streameventsresponsecompleted.py +28 -0
- melara/components/streameventsresponsefailed.py +28 -0
- melara/components/streameventsresponseincomplete.py +28 -0
- melara/components/streameventsresponseoutputitemadded.py +31 -0
- melara/components/streameventsresponseoutputitemdone.py +31 -0
- melara/components/streamlogprob.py +53 -0
- melara/components/streamlogprobtoplogprob.py +46 -0
- melara/components/sttentity.py +32 -0
- melara/components/sttresponse.py +96 -0
- melara/components/sttsegment.py +107 -0
- melara/components/sttusage.py +57 -0
- melara/components/sttword.py +82 -0
- melara/components/switchyardrouterplugin.py +56 -0
- melara/components/textdeltaevent.py +38 -0
- melara/components/textdoneevent.py +38 -0
- melara/components/textextendedconfig.py +74 -0
- melara/components/toolcallstatus.py +13 -0
- melara/components/toolchoiceallowed.py +37 -0
- melara/components/toolsearchcallitem.py +86 -0
- melara/components/toolsearchoutputitem.py +291 -0
- melara/components/toomanyrequestsresponseerrordata.py +54 -0
- melara/components/traceconfig.py +64 -0
- melara/components/truncation.py +12 -0
- melara/components/unauthorizedresponseerrordata.py +54 -0
- melara/components/unprocessableentityresponseerrordata.py +54 -0
- melara/components/urlcitation.py +47 -0
- melara/components/webfetchplugin.py +54 -0
- melara/components/websearchcallcompletedevent.py +28 -0
- melara/components/websearchcallinprogressevent.py +28 -0
- melara/components/websearchcallsearchingevent.py +28 -0
- melara/components/websearchconfig.py +103 -0
- melara/components/websearchdomainfilter.py +54 -0
- melara/components/websearchengine.py +16 -0
- melara/components/websearchengineenum.py +17 -0
- melara/components/websearchmode.py +20 -0
- melara/components/websearchplugin.py +159 -0
- melara/components/websearchservertool.py +106 -0
- melara/components/websearchsource.py +18 -0
- melara/components/websearchstatus.py +14 -0
- melara/components/websearchuserlocation.py +63 -0
- melara/components/websearchuserlocationservertool.py +63 -0
- melara/components/xsearchoptions.py +70 -0
- melara/embeddings.py +476 -0
- melara/endpoints.json +3 -0
- melara/errors/__init__.py +148 -0
- melara/errors/badgatewayresponse_error.py +33 -0
- melara/errors/badrequestresponse_error.py +33 -0
- melara/errors/edgenetworktimeoutresponse_error.py +33 -0
- melara/errors/forbiddenresponse_error.py +33 -0
- melara/errors/gatewaytimeoutresponse_error.py +33 -0
- melara/errors/internalserverresponse_error.py +33 -0
- melara/errors/melaradefaulterror.py +14 -0
- melara/errors/melaraerror.py +28 -0
- melara/errors/no_response_error.py +16 -0
- melara/errors/notfoundresponse_error.py +33 -0
- melara/errors/payloadtoolargeresponse_error.py +33 -0
- melara/errors/paymentrequiredresponse_error.py +33 -0
- melara/errors/provideroverloadedresponse_error.py +33 -0
- melara/errors/requesttimeoutresponse_error.py +33 -0
- melara/errors/responsevalidationerror.py +25 -0
- melara/errors/serviceunavailableresponse_error.py +33 -0
- melara/errors/toomanyrequestsresponse_error.py +33 -0
- melara/errors/unauthorizedresponse_error.py +33 -0
- melara/errors/unprocessableentityresponse_error.py +33 -0
- melara/httpclient.py +123 -0
- melara/images.py +1014 -0
- melara/locales/__init__.py +0 -0
- melara/locales/en.py +53 -0
- melara/models/__init__.py +21 -0
- melara/models/internal/__init__.py +23 -0
- melara/models/internal/globals.py +57 -0
- melara/models_.py +390 -0
- melara/operations/__init__.py +269 -0
- melara/operations/createaudiospeech.py +114 -0
- melara/operations/createaudiotranscriptions_multipart.py +286 -0
- melara/operations/createembeddings.py +556 -0
- melara/operations/createimages.py +157 -0
- melara/operations/createresponses.py +151 -0
- melara/operations/getmodels.py +274 -0
- melara/operations/sendchatcompletionrequest.py +153 -0
- melara/py.typed +1 -0
- melara/realtime.py +252 -0
- melara/responses.py +1830 -0
- melara/sdk.py +219 -0
- melara/sdkconfiguration.py +60 -0
- melara/stt.py +466 -0
- melara/tts.py +517 -0
- melara/types/__init__.py +22 -0
- melara/types/base64fileinput.py +42 -0
- melara/types/basemodel.py +75 -0
- melara/utils/__init__.py +179 -0
- melara/utils/annotations.py +78 -0
- melara/utils/datetimes.py +21 -0
- melara/utils/dynamic_imports.py +53 -0
- melara/utils/enums.py +132 -0
- melara/utils/eventstreaming.py +344 -0
- melara/utils/forms.py +238 -0
- melara/utils/headers.py +134 -0
- melara/utils/logger.py +26 -0
- melara/utils/metadata.py +117 -0
- melara/utils/queryparams.py +216 -0
- melara/utils/requestbodies.py +66 -0
- melara/utils/retries.py +355 -0
- melara/utils/security.py +214 -0
- melara/utils/serializers.py +305 -0
- melara/utils/unions.py +40 -0
- melara/utils/unmarshal_json_response.py +37 -0
- melara/utils/url.py +153 -0
- melara/utils/values.py +136 -0
- melara-0.1.1.dist-info/METADATA +98 -0
- melara-0.1.1.dist-info/RECORD +442 -0
- melara-0.1.1.dist-info/WHEEL +5 -0
- melara-0.1.1.dist-info/licenses/LICENSE +201 -0
- melara-0.1.1.dist-info/top_level.txt +1 -0
melara/__init__.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from ._version import (
|
|
2
|
+
__title__,
|
|
3
|
+
__version__,
|
|
4
|
+
__openapi_doc_version__,
|
|
5
|
+
__user_agent__,
|
|
6
|
+
)
|
|
7
|
+
from .sdk import *
|
|
8
|
+
from .sdkconfiguration import *
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
VERSION: str = __version__
|
|
12
|
+
OPENAPI_DOC_VERSION = __openapi_doc_version__
|
|
13
|
+
USER_AGENT = __user_agent__
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from .types import Hooks
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# This file is only ever generated once on the first generation and then is free to be modified.
|
|
5
|
+
# Any hooks you wish to add should be registered in the init_hooks function. Feel free to define them
|
|
6
|
+
# in this file or in separate files in the hooks folder.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def init_hooks(hooks: Hooks):
|
|
10
|
+
# pylint: disable=unused-argument
|
|
11
|
+
"""Add hooks by calling hooks.register{sdk_init/before_request/after_success/after_error}Hook
|
|
12
|
+
with an instance of a hook that implements that specific Hook interface
|
|
13
|
+
Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance"""
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import httpx
|
|
2
|
+
from .types import (
|
|
3
|
+
SDKInitHook,
|
|
4
|
+
BeforeRequestContext,
|
|
5
|
+
BeforeRequestHook,
|
|
6
|
+
AfterSuccessContext,
|
|
7
|
+
AfterSuccessHook,
|
|
8
|
+
AfterErrorContext,
|
|
9
|
+
AfterErrorHook,
|
|
10
|
+
Hooks,
|
|
11
|
+
)
|
|
12
|
+
from .registration import init_hooks
|
|
13
|
+
from typing import List, Optional, Tuple
|
|
14
|
+
from melara.sdkconfiguration import SDKConfiguration
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class SDKHooks(Hooks):
|
|
18
|
+
def __init__(self) -> None:
|
|
19
|
+
self.sdk_init_hooks: List[SDKInitHook] = []
|
|
20
|
+
self.before_request_hooks: List[BeforeRequestHook] = []
|
|
21
|
+
self.after_success_hooks: List[AfterSuccessHook] = []
|
|
22
|
+
self.after_error_hooks: List[AfterErrorHook] = []
|
|
23
|
+
init_hooks(self)
|
|
24
|
+
|
|
25
|
+
def register_sdk_init_hook(self, hook: SDKInitHook) -> None:
|
|
26
|
+
self.sdk_init_hooks.append(hook)
|
|
27
|
+
|
|
28
|
+
def register_before_request_hook(self, hook: BeforeRequestHook) -> None:
|
|
29
|
+
self.before_request_hooks.append(hook)
|
|
30
|
+
|
|
31
|
+
def register_after_success_hook(self, hook: AfterSuccessHook) -> None:
|
|
32
|
+
self.after_success_hooks.append(hook)
|
|
33
|
+
|
|
34
|
+
def register_after_error_hook(self, hook: AfterErrorHook) -> None:
|
|
35
|
+
self.after_error_hooks.append(hook)
|
|
36
|
+
|
|
37
|
+
def sdk_init(self, config: SDKConfiguration) -> SDKConfiguration:
|
|
38
|
+
for hook in self.sdk_init_hooks:
|
|
39
|
+
config = hook.sdk_init(config)
|
|
40
|
+
return config
|
|
41
|
+
|
|
42
|
+
def before_request(
|
|
43
|
+
self, hook_ctx: BeforeRequestContext, request: httpx.Request
|
|
44
|
+
) -> httpx.Request:
|
|
45
|
+
for hook in self.before_request_hooks:
|
|
46
|
+
out = hook.before_request(hook_ctx, request)
|
|
47
|
+
if isinstance(out, Exception):
|
|
48
|
+
raise out
|
|
49
|
+
request = out
|
|
50
|
+
|
|
51
|
+
return request
|
|
52
|
+
|
|
53
|
+
def after_success(
|
|
54
|
+
self, hook_ctx: AfterSuccessContext, response: httpx.Response
|
|
55
|
+
) -> httpx.Response:
|
|
56
|
+
for hook in self.after_success_hooks:
|
|
57
|
+
out = hook.after_success(hook_ctx, response)
|
|
58
|
+
if isinstance(out, Exception):
|
|
59
|
+
raise out
|
|
60
|
+
response = out
|
|
61
|
+
return response
|
|
62
|
+
|
|
63
|
+
def after_error(
|
|
64
|
+
self,
|
|
65
|
+
hook_ctx: AfterErrorContext,
|
|
66
|
+
response: Optional[httpx.Response],
|
|
67
|
+
error: Optional[Exception],
|
|
68
|
+
) -> Tuple[Optional[httpx.Response], Optional[Exception]]:
|
|
69
|
+
for hook in self.after_error_hooks:
|
|
70
|
+
result = hook.after_error(hook_ctx, response, error)
|
|
71
|
+
if isinstance(result, Exception):
|
|
72
|
+
raise result
|
|
73
|
+
response, error = result
|
|
74
|
+
return response, error
|
melara/_hooks/types.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
import httpx
|
|
3
|
+
from melara.sdkconfiguration import SDKConfiguration
|
|
4
|
+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class HookContext:
|
|
8
|
+
config: SDKConfiguration
|
|
9
|
+
base_url: str
|
|
10
|
+
operation_id: str
|
|
11
|
+
oauth2_scopes: Optional[List[str]] = None
|
|
12
|
+
security_source: Optional[Union[Any, Callable[[], Any]]] = None
|
|
13
|
+
tags: Optional[List[str]] = None
|
|
14
|
+
extensions: Optional[Dict[str, Any]] = None
|
|
15
|
+
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
config: SDKConfiguration,
|
|
19
|
+
base_url: str,
|
|
20
|
+
operation_id: str,
|
|
21
|
+
oauth2_scopes: Optional[List[str]],
|
|
22
|
+
security_source: Optional[Union[Any, Callable[[], Any]]],
|
|
23
|
+
tags: Optional[List[str]],
|
|
24
|
+
extensions: Optional[Dict[str, Any]],
|
|
25
|
+
):
|
|
26
|
+
self.config = config
|
|
27
|
+
self.base_url = base_url
|
|
28
|
+
self.operation_id = operation_id
|
|
29
|
+
self.oauth2_scopes = oauth2_scopes
|
|
30
|
+
self.security_source = security_source
|
|
31
|
+
self.tags = tags
|
|
32
|
+
self.extensions = extensions
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class BeforeRequestContext(HookContext):
|
|
36
|
+
def __init__(self, hook_ctx: HookContext):
|
|
37
|
+
super().__init__(
|
|
38
|
+
hook_ctx.config,
|
|
39
|
+
hook_ctx.base_url,
|
|
40
|
+
hook_ctx.operation_id,
|
|
41
|
+
hook_ctx.oauth2_scopes,
|
|
42
|
+
hook_ctx.security_source,
|
|
43
|
+
hook_ctx.tags,
|
|
44
|
+
hook_ctx.extensions,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class AfterSuccessContext(HookContext):
|
|
49
|
+
def __init__(self, hook_ctx: HookContext):
|
|
50
|
+
super().__init__(
|
|
51
|
+
hook_ctx.config,
|
|
52
|
+
hook_ctx.base_url,
|
|
53
|
+
hook_ctx.operation_id,
|
|
54
|
+
hook_ctx.oauth2_scopes,
|
|
55
|
+
hook_ctx.security_source,
|
|
56
|
+
hook_ctx.tags,
|
|
57
|
+
hook_ctx.extensions,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class AfterErrorContext(HookContext):
|
|
62
|
+
def __init__(self, hook_ctx: HookContext):
|
|
63
|
+
super().__init__(
|
|
64
|
+
hook_ctx.config,
|
|
65
|
+
hook_ctx.base_url,
|
|
66
|
+
hook_ctx.operation_id,
|
|
67
|
+
hook_ctx.oauth2_scopes,
|
|
68
|
+
hook_ctx.security_source,
|
|
69
|
+
hook_ctx.tags,
|
|
70
|
+
hook_ctx.extensions,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class SDKInitHook(ABC):
|
|
75
|
+
@abstractmethod
|
|
76
|
+
def sdk_init(self, config: SDKConfiguration) -> SDKConfiguration:
|
|
77
|
+
pass
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class BeforeRequestHook(ABC):
|
|
81
|
+
@abstractmethod
|
|
82
|
+
def before_request(
|
|
83
|
+
self, hook_ctx: BeforeRequestContext, request: httpx.Request
|
|
84
|
+
) -> Union[httpx.Request, Exception]:
|
|
85
|
+
pass
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class AfterSuccessHook(ABC):
|
|
89
|
+
@abstractmethod
|
|
90
|
+
def after_success(
|
|
91
|
+
self, hook_ctx: AfterSuccessContext, response: httpx.Response
|
|
92
|
+
) -> Union[httpx.Response, Exception]:
|
|
93
|
+
pass
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class AfterErrorHook(ABC):
|
|
97
|
+
@abstractmethod
|
|
98
|
+
def after_error(
|
|
99
|
+
self,
|
|
100
|
+
hook_ctx: AfterErrorContext,
|
|
101
|
+
response: Optional[httpx.Response],
|
|
102
|
+
error: Optional[Exception],
|
|
103
|
+
) -> Union[Tuple[Optional[httpx.Response], Optional[Exception]], Exception]:
|
|
104
|
+
pass
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class Hooks(ABC):
|
|
108
|
+
@abstractmethod
|
|
109
|
+
def register_sdk_init_hook(self, hook: SDKInitHook):
|
|
110
|
+
pass
|
|
111
|
+
|
|
112
|
+
@abstractmethod
|
|
113
|
+
def register_before_request_hook(self, hook: BeforeRequestHook):
|
|
114
|
+
pass
|
|
115
|
+
|
|
116
|
+
@abstractmethod
|
|
117
|
+
def register_after_success_hook(self, hook: AfterSuccessHook):
|
|
118
|
+
pass
|
|
119
|
+
|
|
120
|
+
@abstractmethod
|
|
121
|
+
def register_after_error_hook(self, hook: AfterErrorHook):
|
|
122
|
+
pass
|
melara/_version.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import importlib.metadata
|
|
2
|
+
|
|
3
|
+
__title__: str = "melara"
|
|
4
|
+
__version__: str = "0.1.1"
|
|
5
|
+
__openapi_doc_version__: str = "1.0.0"
|
|
6
|
+
__gen_version__: str = "2.914.0"
|
|
7
|
+
__user_agent__: str = "melara-python/0.1.1"
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
if __package__ is not None:
|
|
11
|
+
__version__ = importlib.metadata.version(__package__)
|
|
12
|
+
except importlib.metadata.PackageNotFoundError:
|
|
13
|
+
pass
|
melara/basesdk.py
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
from .sdkconfiguration import SDKConfiguration
|
|
2
|
+
import httpx
|
|
3
|
+
from melara.locales import en as messages
|
|
4
|
+
from melara import components, errors, utils
|
|
5
|
+
from melara._hooks import (
|
|
6
|
+
AfterErrorContext,
|
|
7
|
+
AfterSuccessContext,
|
|
8
|
+
BeforeRequestContext,
|
|
9
|
+
HookContext,
|
|
10
|
+
)
|
|
11
|
+
from melara.utils import (
|
|
12
|
+
RetryConfig,
|
|
13
|
+
SerializedRequestBody,
|
|
14
|
+
get_body_content,
|
|
15
|
+
run_sync_in_thread,
|
|
16
|
+
)
|
|
17
|
+
from typing import Callable, List, Mapping, Optional, Tuple
|
|
18
|
+
from urllib.parse import parse_qs, urlparse
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class BaseSDK:
|
|
22
|
+
sdk_configuration: SDKConfiguration
|
|
23
|
+
parent_ref: Optional[object] = None
|
|
24
|
+
"""
|
|
25
|
+
Reference to the root SDK instance, if any. This will prevent it from
|
|
26
|
+
being garbage collected while there are active streams.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
def __init__(
|
|
30
|
+
self,
|
|
31
|
+
sdk_config: SDKConfiguration,
|
|
32
|
+
parent_ref: Optional[object] = None,
|
|
33
|
+
) -> None:
|
|
34
|
+
self.sdk_configuration = sdk_config
|
|
35
|
+
self.parent_ref = parent_ref
|
|
36
|
+
|
|
37
|
+
def _get_url(self, base_url, url_variables):
|
|
38
|
+
sdk_url, sdk_variables = self.sdk_configuration.get_server_details()
|
|
39
|
+
|
|
40
|
+
if base_url is None:
|
|
41
|
+
base_url = sdk_url
|
|
42
|
+
|
|
43
|
+
if url_variables is None:
|
|
44
|
+
url_variables = sdk_variables
|
|
45
|
+
|
|
46
|
+
return utils.template_url(base_url, url_variables)
|
|
47
|
+
|
|
48
|
+
def _build_request_async(
|
|
49
|
+
self,
|
|
50
|
+
method,
|
|
51
|
+
path,
|
|
52
|
+
base_url,
|
|
53
|
+
url_variables,
|
|
54
|
+
request,
|
|
55
|
+
request_body_required,
|
|
56
|
+
request_has_path_params,
|
|
57
|
+
request_has_query_params,
|
|
58
|
+
user_agent_header,
|
|
59
|
+
accept_header_value,
|
|
60
|
+
_globals=None,
|
|
61
|
+
security=None,
|
|
62
|
+
timeout_ms: Optional[int] = None,
|
|
63
|
+
get_serialized_body: Optional[
|
|
64
|
+
Callable[[], Optional[SerializedRequestBody]]
|
|
65
|
+
] = None,
|
|
66
|
+
url_override: Optional[str] = None,
|
|
67
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
68
|
+
allow_empty_value: Optional[List[str]] = None,
|
|
69
|
+
allowed_fields: Optional[List[str]] = None,
|
|
70
|
+
) -> httpx.Request:
|
|
71
|
+
client = self.sdk_configuration.async_client
|
|
72
|
+
return self._build_request_with_client(
|
|
73
|
+
client,
|
|
74
|
+
method,
|
|
75
|
+
path,
|
|
76
|
+
base_url,
|
|
77
|
+
url_variables,
|
|
78
|
+
request,
|
|
79
|
+
request_body_required,
|
|
80
|
+
request_has_path_params,
|
|
81
|
+
request_has_query_params,
|
|
82
|
+
user_agent_header,
|
|
83
|
+
accept_header_value,
|
|
84
|
+
_globals,
|
|
85
|
+
security,
|
|
86
|
+
timeout_ms,
|
|
87
|
+
get_serialized_body,
|
|
88
|
+
url_override,
|
|
89
|
+
http_headers,
|
|
90
|
+
allow_empty_value,
|
|
91
|
+
allowed_fields,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
def _build_request(
|
|
95
|
+
self,
|
|
96
|
+
method,
|
|
97
|
+
path,
|
|
98
|
+
base_url,
|
|
99
|
+
url_variables,
|
|
100
|
+
request,
|
|
101
|
+
request_body_required,
|
|
102
|
+
request_has_path_params,
|
|
103
|
+
request_has_query_params,
|
|
104
|
+
user_agent_header,
|
|
105
|
+
accept_header_value,
|
|
106
|
+
_globals=None,
|
|
107
|
+
security=None,
|
|
108
|
+
timeout_ms: Optional[int] = None,
|
|
109
|
+
get_serialized_body: Optional[
|
|
110
|
+
Callable[[], Optional[SerializedRequestBody]]
|
|
111
|
+
] = None,
|
|
112
|
+
url_override: Optional[str] = None,
|
|
113
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
114
|
+
allow_empty_value: Optional[List[str]] = None,
|
|
115
|
+
allowed_fields: Optional[List[str]] = None,
|
|
116
|
+
) -> httpx.Request:
|
|
117
|
+
client = self.sdk_configuration.client
|
|
118
|
+
return self._build_request_with_client(
|
|
119
|
+
client,
|
|
120
|
+
method,
|
|
121
|
+
path,
|
|
122
|
+
base_url,
|
|
123
|
+
url_variables,
|
|
124
|
+
request,
|
|
125
|
+
request_body_required,
|
|
126
|
+
request_has_path_params,
|
|
127
|
+
request_has_query_params,
|
|
128
|
+
user_agent_header,
|
|
129
|
+
accept_header_value,
|
|
130
|
+
_globals,
|
|
131
|
+
security,
|
|
132
|
+
timeout_ms,
|
|
133
|
+
get_serialized_body,
|
|
134
|
+
url_override,
|
|
135
|
+
http_headers,
|
|
136
|
+
allow_empty_value,
|
|
137
|
+
allowed_fields,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
def _build_request_with_client(
|
|
141
|
+
self,
|
|
142
|
+
client,
|
|
143
|
+
method,
|
|
144
|
+
path,
|
|
145
|
+
base_url,
|
|
146
|
+
url_variables,
|
|
147
|
+
request,
|
|
148
|
+
request_body_required,
|
|
149
|
+
request_has_path_params,
|
|
150
|
+
request_has_query_params,
|
|
151
|
+
user_agent_header,
|
|
152
|
+
accept_header_value,
|
|
153
|
+
_globals=None,
|
|
154
|
+
security=None,
|
|
155
|
+
timeout_ms: Optional[int] = None,
|
|
156
|
+
get_serialized_body: Optional[
|
|
157
|
+
Callable[[], Optional[SerializedRequestBody]]
|
|
158
|
+
] = None,
|
|
159
|
+
url_override: Optional[str] = None,
|
|
160
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
161
|
+
allow_empty_value: Optional[List[str]] = None,
|
|
162
|
+
allowed_fields: Optional[List[str]] = None,
|
|
163
|
+
) -> httpx.Request:
|
|
164
|
+
query_params = {}
|
|
165
|
+
|
|
166
|
+
url = url_override
|
|
167
|
+
if url is None:
|
|
168
|
+
url = utils.generate_url(
|
|
169
|
+
self._get_url(base_url, url_variables),
|
|
170
|
+
path,
|
|
171
|
+
request if request_has_path_params else None,
|
|
172
|
+
_globals if request_has_path_params else None,
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
query_params = utils.get_query_params(
|
|
176
|
+
request if request_has_query_params else None,
|
|
177
|
+
_globals if request_has_query_params else None,
|
|
178
|
+
allow_empty_value,
|
|
179
|
+
)
|
|
180
|
+
else:
|
|
181
|
+
# Pick up the query parameter from the override so they can be
|
|
182
|
+
# preserved when building the request later on (necessary as of
|
|
183
|
+
# httpx 0.28).
|
|
184
|
+
parsed_override = urlparse(str(url_override))
|
|
185
|
+
query_params = parse_qs(parsed_override.query, keep_blank_values=True)
|
|
186
|
+
|
|
187
|
+
headers = utils.get_headers(request, _globals)
|
|
188
|
+
headers["Accept"] = accept_header_value
|
|
189
|
+
headers[user_agent_header] = self.sdk_configuration.user_agent
|
|
190
|
+
|
|
191
|
+
if security is not None:
|
|
192
|
+
if callable(security):
|
|
193
|
+
security = security()
|
|
194
|
+
security = utils.get_security_from_env(security, components.Security)
|
|
195
|
+
if security is not None:
|
|
196
|
+
security_headers, security_query_params = utils.get_security(
|
|
197
|
+
security, allowed_fields
|
|
198
|
+
)
|
|
199
|
+
headers = {**headers, **security_headers}
|
|
200
|
+
query_params = {**query_params, **security_query_params}
|
|
201
|
+
|
|
202
|
+
serialized_request_body = SerializedRequestBody()
|
|
203
|
+
if get_serialized_body is not None:
|
|
204
|
+
rb = get_serialized_body()
|
|
205
|
+
if request_body_required and rb is None:
|
|
206
|
+
raise ValueError(messages.REQUEST_BODY_IS_REQUIRED)
|
|
207
|
+
|
|
208
|
+
if rb is not None:
|
|
209
|
+
serialized_request_body = rb
|
|
210
|
+
|
|
211
|
+
if (
|
|
212
|
+
serialized_request_body.media_type is not None
|
|
213
|
+
and serialized_request_body.media_type
|
|
214
|
+
not in (
|
|
215
|
+
"multipart/form-data",
|
|
216
|
+
"multipart/mixed",
|
|
217
|
+
)
|
|
218
|
+
):
|
|
219
|
+
headers["content-type"] = serialized_request_body.media_type
|
|
220
|
+
|
|
221
|
+
# Normalize attribution at the shared sync and async request boundary.
|
|
222
|
+
attribution = {
|
|
223
|
+
"http-referer": "X-Melara-App-Url",
|
|
224
|
+
"x-title": "X-Melara-App-Name",
|
|
225
|
+
}
|
|
226
|
+
request_headers = httpx.Headers(headers)
|
|
227
|
+
if http_headers is not None:
|
|
228
|
+
explicit_headers = {header.lower() for header in http_headers}
|
|
229
|
+
for header, value in http_headers.items():
|
|
230
|
+
canonical = attribution.get(header.lower())
|
|
231
|
+
if canonical is not None and canonical.lower() in explicit_headers:
|
|
232
|
+
continue
|
|
233
|
+
request_headers[canonical or header] = value
|
|
234
|
+
|
|
235
|
+
timeout = timeout_ms / 1000 if timeout_ms is not None else None
|
|
236
|
+
|
|
237
|
+
return client.build_request(
|
|
238
|
+
method,
|
|
239
|
+
url,
|
|
240
|
+
params=query_params,
|
|
241
|
+
content=serialized_request_body.content,
|
|
242
|
+
data=serialized_request_body.data,
|
|
243
|
+
files=serialized_request_body.files,
|
|
244
|
+
headers=request_headers,
|
|
245
|
+
timeout=timeout if timeout is not None else httpx.USE_CLIENT_DEFAULT,
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
def do_request(
|
|
249
|
+
self,
|
|
250
|
+
hook_ctx: HookContext,
|
|
251
|
+
request: httpx.Request,
|
|
252
|
+
is_error_status_code: Callable[[int], bool],
|
|
253
|
+
stream: bool = False,
|
|
254
|
+
retry_config: Optional[Tuple[RetryConfig, List[str]]] = None,
|
|
255
|
+
) -> httpx.Response:
|
|
256
|
+
client = self.sdk_configuration.client
|
|
257
|
+
logger = self.sdk_configuration.debug_logger
|
|
258
|
+
|
|
259
|
+
hooks = self.sdk_configuration.__dict__["_hooks"]
|
|
260
|
+
|
|
261
|
+
def do():
|
|
262
|
+
http_res = None
|
|
263
|
+
try:
|
|
264
|
+
req = hooks.before_request(BeforeRequestContext(hook_ctx), request)
|
|
265
|
+
if "timeout" in request.extensions and "timeout" not in req.extensions:
|
|
266
|
+
req.extensions["timeout"] = request.extensions["timeout"]
|
|
267
|
+
logger.debug(
|
|
268
|
+
messages.REQUEST_METHOD_S_URL_S_HEADERS_S_BODY_S,
|
|
269
|
+
req.method,
|
|
270
|
+
req.url,
|
|
271
|
+
req.headers,
|
|
272
|
+
get_body_content(req),
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
if client is None:
|
|
276
|
+
raise ValueError(messages.CLIENT_IS_REQUIRED)
|
|
277
|
+
|
|
278
|
+
http_res = client.send(req, stream=stream)
|
|
279
|
+
except Exception as e:
|
|
280
|
+
_, e = hooks.after_error(AfterErrorContext(hook_ctx), None, e)
|
|
281
|
+
if e is not None:
|
|
282
|
+
logger.debug(messages.REQUEST_EXCEPTION, exc_info=True)
|
|
283
|
+
raise e
|
|
284
|
+
|
|
285
|
+
if http_res is None:
|
|
286
|
+
logger.debug(messages.RAISING_NO_RESPONSE_SDK_ERROR)
|
|
287
|
+
raise errors.NoResponseError(messages.NO_RESPONSE_RECEIVED)
|
|
288
|
+
|
|
289
|
+
logger.debug(
|
|
290
|
+
messages.RESPONSE_STATUS_CODE_S_URL_S_HEADERS_S_BODY,
|
|
291
|
+
http_res.status_code,
|
|
292
|
+
http_res.url,
|
|
293
|
+
http_res.headers,
|
|
294
|
+
messages.STREAMING_RESPONSE if stream else http_res.text,
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
return http_res
|
|
298
|
+
|
|
299
|
+
if retry_config is not None:
|
|
300
|
+
http_res = utils.retry(do, utils.Retries(retry_config[0], retry_config[1]))
|
|
301
|
+
else:
|
|
302
|
+
http_res = do()
|
|
303
|
+
|
|
304
|
+
if is_error_status_code(http_res.status_code):
|
|
305
|
+
result, err = hooks.after_error(AfterErrorContext(hook_ctx), http_res, None)
|
|
306
|
+
if err is not None:
|
|
307
|
+
logger.debug(messages.REQUEST_EXCEPTION, exc_info=True)
|
|
308
|
+
raise err
|
|
309
|
+
if result is not None:
|
|
310
|
+
http_res = result
|
|
311
|
+
else:
|
|
312
|
+
logger.debug(messages.RAISING_UNEXPECTED_SDK_ERROR)
|
|
313
|
+
raise errors.MelaraDefaultError(
|
|
314
|
+
messages.UNEXPECTED_ERROR_OCCURRED, http_res
|
|
315
|
+
)
|
|
316
|
+
else:
|
|
317
|
+
http_res = hooks.after_success(AfterSuccessContext(hook_ctx), http_res)
|
|
318
|
+
|
|
319
|
+
return http_res
|
|
320
|
+
|
|
321
|
+
async def do_request_async(
|
|
322
|
+
self,
|
|
323
|
+
hook_ctx: HookContext,
|
|
324
|
+
request: httpx.Request,
|
|
325
|
+
is_error_status_code: Callable[[int], bool],
|
|
326
|
+
stream: bool = False,
|
|
327
|
+
retry_config: Optional[Tuple[RetryConfig, List[str]]] = None,
|
|
328
|
+
) -> httpx.Response:
|
|
329
|
+
client = self.sdk_configuration.async_client
|
|
330
|
+
logger = self.sdk_configuration.debug_logger
|
|
331
|
+
|
|
332
|
+
hooks = self.sdk_configuration.__dict__["_hooks"]
|
|
333
|
+
|
|
334
|
+
async def do():
|
|
335
|
+
http_res = None
|
|
336
|
+
try:
|
|
337
|
+
req = await run_sync_in_thread(
|
|
338
|
+
hooks.before_request, BeforeRequestContext(hook_ctx), request
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
if "timeout" in request.extensions and "timeout" not in req.extensions:
|
|
342
|
+
req.extensions["timeout"] = request.extensions["timeout"]
|
|
343
|
+
logger.debug(
|
|
344
|
+
messages.REQUEST_METHOD_S_URL_S_HEADERS_S_BODY_S,
|
|
345
|
+
req.method,
|
|
346
|
+
req.url,
|
|
347
|
+
req.headers,
|
|
348
|
+
get_body_content(req),
|
|
349
|
+
)
|
|
350
|
+
|
|
351
|
+
if client is None:
|
|
352
|
+
raise ValueError(messages.CLIENT_IS_REQUIRED)
|
|
353
|
+
|
|
354
|
+
http_res = await client.send(req, stream=stream)
|
|
355
|
+
except Exception as e:
|
|
356
|
+
_, e = await run_sync_in_thread(
|
|
357
|
+
hooks.after_error, AfterErrorContext(hook_ctx), None, e
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
if e is not None:
|
|
361
|
+
logger.debug(messages.REQUEST_EXCEPTION, exc_info=True)
|
|
362
|
+
raise e
|
|
363
|
+
|
|
364
|
+
if http_res is None:
|
|
365
|
+
logger.debug(messages.RAISING_NO_RESPONSE_SDK_ERROR)
|
|
366
|
+
raise errors.NoResponseError(messages.NO_RESPONSE_RECEIVED)
|
|
367
|
+
|
|
368
|
+
logger.debug(
|
|
369
|
+
messages.RESPONSE_STATUS_CODE_S_URL_S_HEADERS_S_BODY,
|
|
370
|
+
http_res.status_code,
|
|
371
|
+
http_res.url,
|
|
372
|
+
http_res.headers,
|
|
373
|
+
messages.STREAMING_RESPONSE if stream else http_res.text,
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
return http_res
|
|
377
|
+
|
|
378
|
+
if retry_config is not None:
|
|
379
|
+
http_res = await utils.retry_async(
|
|
380
|
+
do, utils.Retries(retry_config[0], retry_config[1])
|
|
381
|
+
)
|
|
382
|
+
else:
|
|
383
|
+
http_res = await do()
|
|
384
|
+
|
|
385
|
+
if is_error_status_code(http_res.status_code):
|
|
386
|
+
result, err = await run_sync_in_thread(
|
|
387
|
+
hooks.after_error, AfterErrorContext(hook_ctx), http_res, None
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
if err is not None:
|
|
391
|
+
logger.debug(messages.REQUEST_EXCEPTION, exc_info=True)
|
|
392
|
+
raise err
|
|
393
|
+
if result is not None:
|
|
394
|
+
http_res = result
|
|
395
|
+
else:
|
|
396
|
+
logger.debug(messages.RAISING_UNEXPECTED_SDK_ERROR)
|
|
397
|
+
raise errors.MelaraDefaultError(
|
|
398
|
+
messages.UNEXPECTED_ERROR_OCCURRED, http_res
|
|
399
|
+
)
|
|
400
|
+
else:
|
|
401
|
+
http_res = await run_sync_in_thread(
|
|
402
|
+
hooks.after_success, AfterSuccessContext(hook_ctx), http_res
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
return http_res
|
melara/beta.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from .basesdk import BaseSDK
|
|
2
|
+
from .sdkconfiguration import SDKConfiguration
|
|
3
|
+
from melara.beta_responses import BetaResponses
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Beta(BaseSDK):
|
|
8
|
+
responses: BetaResponses
|
|
9
|
+
r"""Deprecated alias for responses endpoints. Use responses instead. Scheduled for removal (sunset date TBD)."""
|
|
10
|
+
|
|
11
|
+
def __init__(
|
|
12
|
+
self, sdk_config: SDKConfiguration, parent_ref: Optional[object] = None
|
|
13
|
+
) -> None:
|
|
14
|
+
BaseSDK.__init__(self, sdk_config, parent_ref=parent_ref)
|
|
15
|
+
self.sdk_configuration = sdk_config
|
|
16
|
+
self._init_sdks()
|
|
17
|
+
|
|
18
|
+
def _init_sdks(self):
|
|
19
|
+
self.responses = BetaResponses(
|
|
20
|
+
self.sdk_configuration, parent_ref=self.parent_ref
|
|
21
|
+
)
|
melara/beta_responses.py
ADDED