From 379f0ffe9d2edec3e04b2116d7877955ba863c93 Mon Sep 17 00:00:00 2001 From: speakeasybot Date: Wed, 15 Jan 2025 00:13:57 +0000 Subject: [PATCH] ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.468.6 --- .gitignore | 1 + .speakeasy/gen.lock | 398 +++++++++++------- .speakeasy/gen.yaml | 4 +- .speakeasy/workflow.lock | 22 +- .speakeasy/workflow.yaml | 6 + README.md | 346 ++++++--------- RELEASES.md | 12 +- USAGE.md | 10 +- completions.go | 162 +++++-- docs/models/components/security.md | 2 +- docs/sdks/completions/README.md | 127 +++--- docs/sdks/feedback/README.md | 86 ++-- docs/sdks/feedbacktasks/README.md | 62 +-- docs/sdks/log10/README.md | 2 - docs/sdks/sessions/README.md | 20 +- feedback.go | 153 +++++-- feedbacktasks.go | 132 ++++-- go.mod | 5 +- go.sum | 2 - internal/globals/globals.go | 2 +- internal/hooks/hooks.go | 2 +- internal/utils/contenttype.go | 2 +- internal/utils/env.go | 16 + internal/utils/form.go | 2 +- internal/utils/headers.go | 2 +- internal/utils/json.go | 39 +- internal/utils/pathparams.go | 2 +- internal/utils/queryparams.go | 20 +- internal/utils/requestbody.go | 35 +- internal/utils/retries.go | 154 ++++++- internal/utils/security.go | 19 +- internal/utils/utils.go | 19 +- log10.go | 13 +- .../chatcompletionfunctioncalloption.go | 2 +- models/components/chatcompletionfunctions.go | 4 +- .../chatcompletionmessagetoolcall.go | 2 +- .../chatcompletionnamedtoolchoice.go | 2 +- .../chatcompletionrequestassistantmessage.go | 6 +- .../chatcompletionrequestfunctionmessage.go | 4 +- .../chatcompletionrequestmessage.go | 12 +- ...chatcompletionrequestmessagecontentpart.go | 6 +- ...ompletionrequestmessagecontentpartimage.go | 2 +- ...completionrequestmessagecontentparttext.go | 2 +- .../chatcompletionrequestsystemmessage.go | 2 +- .../chatcompletionrequesttoolmessage.go | 2 +- .../chatcompletionrequestusermessage.go | 6 +- .../chatcompletionresponsemessage.go | 6 +- .../components/chatcompletionstreamoptions.go | 2 +- .../components/chatcompletiontokenlogprob.go | 2 +- models/components/chatcompletiontool.go | 2 +- .../chatcompletiontoolchoiceoption.go | 6 +- models/components/completion.go | 2 +- models/components/completionusage.go | 2 +- .../components/createchatcompletionrequest.go | 20 +- .../createchatcompletionresponse.go | 2 +- models/components/feedback.go | 2 +- models/components/functionobject.go | 2 +- models/components/httpmetadata.go | 2 +- models/components/security.go | 8 +- models/components/session.go | 2 +- models/components/task.go | 2 +- models/operations/create.go | 2 +- models/operations/createfeedbacktask.go | 2 +- models/operations/createsession.go | 2 +- models/operations/get.go | 2 +- models/operations/getfeedbacktask.go | 2 +- models/operations/list.go | 2 +- models/operations/listfeedbacktasks.go | 2 +- models/operations/listungraded.go | 2 +- models/operations/options.go | 41 +- models/operations/update.go | 2 +- models/operations/upload.go | 6 +- models/sdkerrors/sdkerror.go | 2 +- retry/config.go | 134 +++++- sessions.go | 53 ++- types/bigint.go | 2 +- types/date.go | 2 +- types/datetime.go | 2 +- types/decimal.go | 2 +- types/pointers.go | 3 +- 80 files changed, 1421 insertions(+), 837 deletions(-) create mode 100644 internal/utils/env.go diff --git a/.gitignore b/.gitignore index d3c2f59..96942a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +.speakeasy/reports # .gitignore diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index cc70739..0ad6042 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -3,24 +3,24 @@ id: af921c1a-d48f-4ab5-a412-4cf4ba8a50ad management: docChecksum: 5e7cc152f137f5919734cc70b836a4d6 docVersion: 1.0.0 - speakeasyVersion: 1.337.1 - generationVersion: 2.373.2 - releaseVersion: 0.1.0 - configChecksum: 54bb041d3948fb5a80cc757eac556e7b + speakeasyVersion: 1.468.6 + generationVersion: 2.493.13 + releaseVersion: 0.2.0 + configChecksum: dbf323c419fb80f526737afd9a88e047 repoURL: https://github.com/log10-io/log10go.git installationURL: https://github.com/log10-io/log10go features: go: additionalDependencies: 0.1.0 - constsAndDefaults: 0.1.4 - core: 3.4.16 + constsAndDefaults: 0.1.6 + core: 3.6.5 defaultEnabledRetries: 0.2.0 - deprecations: 2.81.1 - envVarSecurityUsage: 0.2.0 - examples: 2.81.3 + deprecations: 2.81.2 + envVarSecurityUsage: 0.3.2 + examples: 2.81.4 flattening: 2.81.1 getRequestBodies: 2.81.1 - globalSecurity: 2.82.9 + globalSecurity: 2.82.10 globalSecurityCallbacks: 0.1.0 globalSecurityFlattening: 0.1.0 globalServerURLs: 2.82.2 @@ -29,180 +29,268 @@ features: nameOverrides: 2.81.2 nullables: 0.1.0 responseFormat: 0.1.2 - retries: 2.83.0 + retries: 2.83.2 sdkHooks: 0.1.0 typeOverrides: 2.81.1 - unions: 2.85.8 + unions: 2.85.10 generatedFiles: - - completions.go - - sessions.go - - feedback.go - - feedbacktasks.go - - log10.go - - go.mod - - models/sdkerrors/sdkerror.go - - retry/config.go - - types/bigint.go - - types/date.go - - types/datetime.go - - types/decimal.go - - types/pointers.go - - internal/utils/contenttype.go - - internal/utils/form.go - - internal/utils/headers.go - - internal/utils/json.go - - internal/utils/pathparams.go - - internal/utils/queryparams.go - - internal/utils/requestbody.go - - internal/utils/retries.go - - internal/utils/security.go - - internal/utils/utils.go - - internal/globals/globals.go - - /models/operations/create.go - - /models/operations/update.go - - /models/operations/listungraded.go - - /models/operations/createsession.go - - /models/operations/get.go - - /models/operations/list.go - - /models/operations/upload.go - - /models/operations/listfeedbacktasks.go - - /models/operations/createfeedbacktask.go - - /models/operations/getfeedbacktask.go - - /models/components/completion.go - - /models/components/createchatcompletionresponse.go - - /models/components/completionusage.go - - /models/components/chatcompletiontokenlogprob.go - - /models/components/chatcompletionresponsemessage.go - - /models/components/chatcompletionmessagetoolcall.go - - /models/components/createchatcompletionrequest.go - - /models/components/chatcompletionfunctions.go + - .gitattributes - /models/components/chatcompletionfunctioncalloption.go - - /models/components/chatcompletiontoolchoiceoption.go + - /models/components/chatcompletionfunctions.go + - /models/components/chatcompletionmessagetoolcall.go - /models/components/chatcompletionnamedtoolchoice.go - - /models/components/chatcompletiontool.go - - /models/components/functionobject.go - - /models/components/chatcompletionstreamoptions.go + - /models/components/chatcompletionrequestassistantmessage.go + - /models/components/chatcompletionrequestfunctionmessage.go - /models/components/chatcompletionrequestmessage.go - - /models/components/chatcompletionrequestsystemmessage.go - - /models/components/chatcompletionrequestusermessage.go - /models/components/chatcompletionrequestmessagecontentpart.go - - /models/components/chatcompletionrequestmessagecontentparttext.go - /models/components/chatcompletionrequestmessagecontentpartimage.go - - /models/components/chatcompletionrequestassistantmessage.go + - /models/components/chatcompletionrequestmessagecontentparttext.go + - /models/components/chatcompletionrequestsystemmessage.go - /models/components/chatcompletionrequesttoolmessage.go - - /models/components/chatcompletionrequestfunctionmessage.go + - /models/components/chatcompletionrequestusermessage.go + - /models/components/chatcompletionresponsemessage.go + - /models/components/chatcompletionstreamoptions.go + - /models/components/chatcompletiontokenlogprob.go + - /models/components/chatcompletiontool.go + - /models/components/chatcompletiontoolchoiceoption.go + - /models/components/completion.go + - /models/components/completionusage.go + - /models/components/createchatcompletionrequest.go + - /models/components/createchatcompletionresponse.go + - /models/components/feedback.go + - /models/components/functionobject.go - /models/components/httpmetadata.go + - /models/components/security.go - /models/components/session.go - - /models/components/feedback.go - /models/components/task.go - - /models/components/security.go + - /models/operations/create.go + - /models/operations/createfeedbacktask.go + - /models/operations/createsession.go + - /models/operations/get.go + - /models/operations/getfeedbacktask.go + - /models/operations/list.go + - /models/operations/listfeedbacktasks.go + - /models/operations/listungraded.go + - /models/operations/update.go + - /models/operations/upload.go + - USAGE.md + - completions.go + - docs/models/components/chatcompletionfunctioncalloption.md + - docs/models/components/chatcompletionfunctions.md + - docs/models/components/chatcompletionmessagetoolcall.md + - docs/models/components/chatcompletionmessagetoolcalltype.md + - docs/models/components/chatcompletionnamedtoolchoice.md + - docs/models/components/chatcompletionnamedtoolchoicefunction.md + - docs/models/components/chatcompletionnamedtoolchoicetype.md + - docs/models/components/chatcompletionrequestassistantmessage.md + - docs/models/components/chatcompletionrequestassistantmessagerole.md + - docs/models/components/chatcompletionrequestfunctionmessage.md + - docs/models/components/chatcompletionrequestfunctionmessagerole.md + - docs/models/components/chatcompletionrequestmessage.md + - docs/models/components/chatcompletionrequestmessagecontentpart.md + - docs/models/components/chatcompletionrequestmessagecontentpartimage.md + - docs/models/components/chatcompletionrequestmessagecontentpartimagetype.md + - docs/models/components/chatcompletionrequestmessagecontentparttext.md + - docs/models/components/chatcompletionrequestsystemmessage.md + - docs/models/components/chatcompletionrequesttoolmessage.md + - docs/models/components/chatcompletionrequesttoolmessagerole.md + - docs/models/components/chatcompletionrequestusermessage.md + - docs/models/components/chatcompletionrequestusermessagerole.md + - docs/models/components/chatcompletionresponsemessage.md + - docs/models/components/chatcompletionresponsemessagefunctioncall.md + - docs/models/components/chatcompletionresponsemessagerole.md + - docs/models/components/chatcompletionstreamoptions.md + - docs/models/components/chatcompletiontokenlogprob.md + - docs/models/components/chatcompletiontool.md + - docs/models/components/chatcompletiontoolchoiceoption.md + - docs/models/components/chatcompletiontoolchoiceoption1.md + - docs/models/components/chatcompletiontooltype.md + - docs/models/components/choices.md + - docs/models/components/completion.md + - docs/models/components/completiontagsselector.md + - docs/models/components/completionusage.md + - docs/models/components/content.md + - docs/models/components/createchatcompletionrequest.md + - docs/models/components/createchatcompletionrequestfunctioncall.md + - docs/models/components/createchatcompletionrequesttype.md + - docs/models/components/createchatcompletionresponse.md + - docs/models/components/detail.md + - docs/models/components/feedback.md + - docs/models/components/finishreason.md + - docs/models/components/function.md + - docs/models/components/functioncall.md + - docs/models/components/functionobject.md + - docs/models/components/httpmetadata.md + - docs/models/components/imageurl.md + - docs/models/components/jsonschema.md + - docs/models/components/jsonvalues.md + - docs/models/components/kind.md + - docs/models/components/logprobs.md + - docs/models/components/model.md + - docs/models/components/object.md + - docs/models/components/one.md + - docs/models/components/responseformat.md + - docs/models/components/role.md + - docs/models/components/security.md + - docs/models/components/session.md + - docs/models/components/stacktrace.md + - docs/models/components/status.md + - docs/models/components/stop.md + - docs/models/components/task.md + - docs/models/components/toplogprobs.md + - docs/models/components/two.md + - docs/models/components/type.md + - docs/models/operations/createfeedbacktaskresponse.md - docs/models/operations/createglobals.md - docs/models/operations/createrequest.md - docs/models/operations/createresponse.md - - docs/models/operations/updateglobals.md - - docs/models/operations/updaterequest.md - - docs/models/operations/updateresponse.md - - docs/models/operations/listungradedglobals.md - - docs/models/operations/listungradedrequest.md - - docs/models/operations/listungradedresponsebody.md - - docs/models/operations/listungradedresponse.md - docs/models/operations/createsessionglobals.md - docs/models/operations/createsessionrequest.md - - docs/models/operations/createsessionresponsebody.md - docs/models/operations/createsessionresponse.md + - docs/models/operations/createsessionresponsebody.md + - docs/models/operations/getfeedbacktaskrequest.md + - docs/models/operations/getfeedbacktaskresponse.md - docs/models/operations/getglobals.md - docs/models/operations/getrequest.md - docs/models/operations/getresponse.md + - docs/models/operations/jsonvalues.md + - docs/models/operations/listfeedbacktasksresponse.md - docs/models/operations/listglobals.md - - docs/models/operations/listrequestbody.md - docs/models/operations/listrequest.md - - docs/models/operations/listresponsebody.md + - docs/models/operations/listrequestbody.md - docs/models/operations/listresponse.md - - docs/models/operations/uploadglobals.md + - docs/models/operations/listresponsebody.md + - docs/models/operations/listungradedglobals.md + - docs/models/operations/listungradedrequest.md + - docs/models/operations/listungradedresponse.md + - docs/models/operations/listungradedresponsebody.md + - docs/models/operations/one.md + - docs/models/operations/option.md - docs/models/operations/requestbodyjsonvalues.md - docs/models/operations/two.md - - docs/models/operations/jsonvalues.md - - docs/models/operations/one.md - - docs/models/operations/uploadrequestbody.md + - docs/models/operations/updateglobals.md + - docs/models/operations/updaterequest.md + - docs/models/operations/updateresponse.md + - docs/models/operations/uploadglobals.md - docs/models/operations/uploadrequest.md + - docs/models/operations/uploadrequestbody.md - docs/models/operations/uploadresponse.md - - docs/models/operations/listfeedbacktasksresponse.md - - docs/models/operations/createfeedbacktaskresponse.md - - docs/models/operations/getfeedbacktaskrequest.md - - docs/models/operations/getfeedbacktaskresponse.md - - docs/models/components/kind.md - - docs/models/components/status.md - - docs/models/components/stacktrace.md - - docs/models/components/completion.md - - docs/models/components/finishreason.md - - docs/models/components/logprobs.md - - docs/models/components/choices.md - - docs/models/components/object.md - - docs/models/components/createchatcompletionresponse.md - - docs/models/components/completionusage.md - - docs/models/components/toplogprobs.md - - docs/models/components/chatcompletiontokenlogprob.md - - docs/models/components/chatcompletionresponsemessagerole.md - - docs/models/components/chatcompletionresponsemessagefunctioncall.md - - docs/models/components/chatcompletionresponsemessage.md - - docs/models/components/chatcompletionmessagetoolcalltype.md - - docs/models/components/function.md - - docs/models/components/chatcompletionmessagetoolcall.md - - docs/models/components/two.md - - docs/models/components/model.md - - docs/models/components/createchatcompletionrequesttype.md - - docs/models/components/responseformat.md - - docs/models/components/stop.md - - docs/models/components/one.md - - docs/models/components/createchatcompletionrequestfunctioncall.md - - docs/models/components/createchatcompletionrequest.md - - docs/models/components/chatcompletionfunctions.md - - docs/models/components/chatcompletionfunctioncalloption.md - - docs/models/components/chatcompletiontoolchoiceoption1.md - - docs/models/components/chatcompletiontoolchoiceoption.md - - docs/models/components/chatcompletionnamedtoolchoicetype.md - - docs/models/components/chatcompletionnamedtoolchoicefunction.md - - docs/models/components/chatcompletionnamedtoolchoice.md - - docs/models/components/chatcompletiontooltype.md - - docs/models/components/chatcompletiontool.md - - docs/models/components/functionobject.md - - docs/models/components/chatcompletionstreamoptions.md - - docs/models/components/chatcompletionrequestmessage.md - - docs/models/components/role.md - - docs/models/components/chatcompletionrequestsystemmessage.md - - docs/models/components/content.md - - docs/models/components/chatcompletionrequestusermessagerole.md - - docs/models/components/chatcompletionrequestusermessage.md - - docs/models/components/chatcompletionrequestmessagecontentpart.md - - docs/models/components/type.md - - docs/models/components/chatcompletionrequestmessagecontentparttext.md - - docs/models/components/chatcompletionrequestmessagecontentpartimagetype.md - - docs/models/components/detail.md - - docs/models/components/imageurl.md - - docs/models/components/chatcompletionrequestmessagecontentpartimage.md - - docs/models/components/chatcompletionrequestassistantmessagerole.md - - docs/models/components/functioncall.md - - docs/models/components/chatcompletionrequestassistantmessage.md - - docs/models/components/chatcompletionrequesttoolmessagerole.md - - docs/models/components/chatcompletionrequesttoolmessage.md - - docs/models/components/chatcompletionrequestfunctionmessagerole.md - - docs/models/components/chatcompletionrequestfunctionmessage.md - - docs/models/components/httpmetadata.md - - docs/models/components/session.md - - docs/models/components/jsonvalues.md - - docs/models/components/feedback.md - - docs/models/components/jsonschema.md - - docs/models/components/completiontagsselector.md - - docs/models/components/task.md - - docs/models/components/security.md - - docs/sdks/log10/README.md - - docs/models/operations/option.md - docs/sdks/completions/README.md - - docs/sdks/sessions/README.md - docs/sdks/feedback/README.md - docs/sdks/feedbacktasks/README.md - - USAGE.md - - models/operations/options.go - - .gitattributes + - docs/sdks/log10/README.md + - docs/sdks/sessions/README.md + - feedback.go + - feedbacktasks.go + - go.mod + - internal/globals/globals.go - internal/hooks/hooks.go - - CONTRIBUTING.md + - internal/utils/contenttype.go + - internal/utils/env.go + - internal/utils/form.go + - internal/utils/headers.go + - internal/utils/json.go + - internal/utils/pathparams.go + - internal/utils/queryparams.go + - internal/utils/requestbody.go + - internal/utils/retries.go + - internal/utils/security.go + - internal/utils/utils.go + - log10.go + - models/operations/options.go + - models/sdkerrors/sdkerror.go + - retry/config.go + - sessions.go + - types/bigint.go + - types/date.go + - types/datetime.go + - types/decimal.go + - types/pointers.go +examples: + create: + speakeasy-default-create: + parameters: + header: + X-Log10-Organization: "" + requestBody: + application/json: {"organization_id": "", "request": {"messages": [{"role": "tool", "content": "", "tool_call_id": ""}], "model": "gpt-4-turbo", "n": 1, "response_format": {"type": "json_object"}, "temperature": 1, "top_p": 1, "user": "user-1234"}} + responses: + "200": + application/json: "" + "201": + application/json: {"organization_id": "", "request": {"messages": [{"content": "", "role": "system"}], "model": "gpt-4-turbo", "n": 1, "response_format": {"type": "json_object"}, "temperature": 1, "top_p": 1, "user": "user-1234"}} + update: + speakeasy-default-update: + parameters: + path: + completionId: "" + header: + X-Log10-Organization: "" + requestBody: + application/json: {"organization_id": "", "request": {"messages": [{"role": "assistant"}, {"content": [{"type": "text", "text": ""}, {"type": "image_url", "image_url": {"url": "https://unlucky-hydrolyze.biz/"}}], "role": "user"}, {"content": "", "role": "user"}], "model": "gpt-4-turbo", "n": 1, "response_format": {"type": "json_object"}, "temperature": 1, "top_p": 1, "user": "user-1234"}} + responses: + "200": + application/json: {"organization_id": "", "request": {"messages": [{"role": "function", "content": "", "name": ""}, {"content": "", "role": "user"}, {"role": "tool", "content": "", "tool_call_id": ""}], "model": "gpt-4-turbo", "n": 1, "response_format": {"type": "json_object"}, "temperature": 1, "top_p": 1, "user": "user-1234"}} + listUngraded: + speakeasy-default-list-ungraded: + parameters: + header: + X-Log10-Organization: "" + responses: + "200": + application/json: {"completions": [{"organization_id": "", "request": {"messages": [], "model": "gpt-4-turbo", "n": 1, "response_format": {"type": "json_object"}, "temperature": 1, "top_p": 1, "user": "user-1234"}}, {"organization_id": "", "request": {"messages": [{"role": "assistant"}, {"role": "assistant"}, {"role": "tool", "content": "", "tool_call_id": ""}], "model": "gpt-4-turbo", "n": 1, "response_format": {"type": "json_object"}, "temperature": 1, "top_p": 1, "user": "user-1234"}}, {"organization_id": "", "request": {"messages": [], "model": "gpt-4-turbo", "n": 1, "response_format": {"type": "json_object"}, "temperature": 1, "top_p": 1, "user": "user-1234"}}]} + createSession: + speakeasy-default-create-session: + parameters: + header: + X-Log10-Organization: "" + responses: + "201": + application/json: {} + get: + speakeasy-default-get: + parameters: + path: + feedbackId: "" + header: + X-Log10-Organization: "" + responses: + "200": + application/json: {"task_id": "", "json_values": {}, "matched_completion_ids": ["", ""], "comment": "The Apollotech B340 is an affordable wireless mouse with reliable connectivity, 12 months battery life and modern design"} + list: + speakeasy-default-list: + parameters: + header: + X-Log10-Organization: "" + responses: + "200": + application/json: {} + upload: + speakeasy-default-upload: + parameters: + header: + X-Log10-Organization: "" + requestBody: + application/json: {"task_id": "", "json_values": {}, "matched_completion_ids": ["", ""], "comment": "The Apollotech B340 is an affordable wireless mouse with reliable connectivity, 12 months battery life and modern design", "completion_tags_selector": [""]} + responses: + "200": + application/json: {"task_id": "", "json_values": {}, "matched_completion_ids": ["", ""], "comment": "Ergonomic executive chair upholstered in bonded black leather and PVC padded seat and back for all-day comfort and support"} + listFeedbackTasks: + speakeasy-default-list-feedback-tasks: + responses: + "200": + application/json: [{"json_schema": {}, "name": "", "instruction": "", "completion_tags_selector": {}}, {"json_schema": {}, "name": "", "instruction": "", "completion_tags_selector": {}}, {"json_schema": {}, "name": "", "instruction": "", "completion_tags_selector": {}}] + createFeedbackTask: + speakeasy-default-create-feedback-task: + responses: + "200": + application/json: {"json_schema": {}, "name": "", "instruction": "", "completion_tags_selector": {}} + getFeedbackTask: + speakeasy-default-get-feedback-task: + parameters: + path: + taskId: "" + responses: + "200": + application/json: {"json_schema": {}, "name": "", "instruction": "", "completion_tags_selector": {}} +generatedTests: {} diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index 242f4d9..ff3ccab 100755 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -11,11 +11,13 @@ generation: requestResponseComponentNamesFeb2024: true auth: oAuth2ClientCredentialsEnabled: false + oAuth2PasswordEnabled: false go: - version: 0.1.0 + version: 0.2.0 additionalDependencies: {} allowUnknownFieldsInWeakUnions: false clientServerStatusCodesAsErrors: true + defaultErrorName: SDKError flattenGlobalSecurity: true imports: option: openapi diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index a07e1e4..6584359 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -1,19 +1,21 @@ -speakeasyVersion: 1.337.1 +speakeasyVersion: 1.468.6 sources: default: sourceNamespace: default - sourceRevisionDigest: sha256:42f8706dab31c314bf8313eac94101440ed747a92fba4f4053269541ccc4b989 - sourceBlobDigest: sha256:3ec92119b04b5301697a25fc0d890d3aace8103f8d6a26dff33c1d2779237e5b + sourceRevisionDigest: sha256:288d45255242bef85a8cf4e2a46e070fcb5559386738392309fbc443a4caec8a + sourceBlobDigest: sha256:93ded879aa864175c9f410fad70152b951b59ab51562e2e93002c0d0698dfff4 tags: - latest - - main + - speakeasy-sdk-regen-1736295204 + - 1.0.0 targets: my-first-target: source: default sourceNamespace: default - sourceRevisionDigest: sha256:42f8706dab31c314bf8313eac94101440ed747a92fba4f4053269541ccc4b989 - sourceBlobDigest: sha256:3ec92119b04b5301697a25fc0d890d3aace8103f8d6a26dff33c1d2779237e5b - outLocation: /github/workspace/repo + sourceRevisionDigest: sha256:288d45255242bef85a8cf4e2a46e070fcb5559386738392309fbc443a4caec8a + sourceBlobDigest: sha256:93ded879aa864175c9f410fad70152b951b59ab51562e2e93002c0d0698dfff4 + codeSamplesNamespace: default-go-code-samples + codeSamplesRevisionDigest: sha256:5ce42a58eff5493e9253cc5f6a472284f0da94ea87e31c453416e29cfd2d2938 workflow: workflowVersion: 1.0.0 speakeasyVersion: latest @@ -27,3 +29,9 @@ workflow: my-first-target: target: go source: default + codeSamples: + registry: + location: registry.speakeasyapi.dev/log10/log10/default-go-code-samples + labelOverride: + fixedValue: Go (SDK) + blocking: false diff --git a/.speakeasy/workflow.yaml b/.speakeasy/workflow.yaml index 266593e..25b85f6 100644 --- a/.speakeasy/workflow.yaml +++ b/.speakeasy/workflow.yaml @@ -10,3 +10,9 @@ targets: my-first-target: target: go source: default + codeSamples: + registry: + location: registry.speakeasyapi.dev/log10/log10/default-go-code-samples + labelOverride: + fixedValue: Go (SDK) + blocking: false diff --git a/README.md b/README.md index 0b1161c..35d51d6 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,35 @@ It has been generated successfully based on your OpenAPI spec. However, it is no - [ ] 🎁 Publish your SDK to package managers by [configuring automatic publishing](https://www.speakeasyapi.dev/docs/advanced-setup/publish-sdks) - [ ] ✨ When ready to productionize, delete this section from the README + +## Summary + +Log10 Feedback API Spec: Log10 Feedback API Spec + + + +## Table of Contents + +* [github.com/log10-io/log10go](#githubcomlog10-iolog10go) + * [🏗 **Welcome to your new SDK!** 🏗](#welcome-to-your-new-sdk) + * [SDK Installation](#sdk-installation) + * [SDK Example Usage](#sdk-example-usage) + * [Available Resources and Operations](#available-resources-and-operations) + * [Error Handling](#error-handling) + * [Server Selection](#server-selection) + * [Custom HTTP Client](#custom-http-client) + * [Authentication](#authentication) + * [Retries](#retries) +* [Development](#development) + * [Maturity](#maturity) + * [Contributions](#contributions) + + + ## SDK Installation +To add the SDK as a dependency to your project: ```bash go get github.com/log10-io/log10go ``` @@ -36,16 +62,16 @@ import ( "context" "github.com/log10-io/log10go" "log" - "os" ) func main() { + ctx := context.Background() + s := log10go.New( - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), + log10go.WithSecurity(""), ) - var xLog10Organization *string = log10go.String("") - ctx := context.Background() - res, err := s.Sessions.Create(ctx, xLog10Organization) + + res, err := s.Sessions.Create(ctx, log10go.String("")) if err != nil { log.Fatal(err) } @@ -60,16 +86,15 @@ func main() { ## Available Resources and Operations +
+Available methods + ### [Completions](docs/sdks/completions/README.md) * [Create](docs/sdks/completions/README.md#create) - Create a completion * [Update](docs/sdks/completions/README.md#update) - Update completion by id. * [ListUngraded](docs/sdks/completions/README.md#listungraded) - List ungraded completions i.e. completions that have not been associated with feedback but matches task selector. -### [Sessions](docs/sdks/sessions/README.md) - -* [Create](docs/sdks/sessions/README.md#create) - Create a session - ### [Feedback](docs/sdks/feedback/README.md) * [Get](docs/sdks/feedback/README.md#get) - Fetch feedback by id. @@ -81,91 +106,27 @@ func main() { * [List](docs/sdks/feedbacktasks/README.md#list) - List feedback tasks. * [Create](docs/sdks/feedbacktasks/README.md#create) - Create a new task. * [Get](docs/sdks/feedbacktasks/README.md#get) - Retrieves feedback task `taskId`. - - - -## Global Parameters - -A parameter is configured globally. This parameter may be set on the SDK client instance itself during initialization. When configured as an option during SDK initialization, This global value will be used as the default on the operations that use it. When such operations are called, there is a place in each to override the global value, if needed. - -For example, you can set `X-Log10-Organization` to `""` at SDK initialization and then you do not have to pass the same value on calls to operations like `Update`. But if you want to do so you may, which will locally override the global setting. See the example code below for a demonstration. - - -### Available Globals - -The following global parameter is available. - -| Name | Type | Required | Description | -| ---- | ---- |:--------:| ----------- | -| XLog10Organization | string | | The XLog10Organization parameter. | -### Example - -```go -package main - -import ( - "context" - "github.com/log10-io/log10go" - "github.com/log10-io/log10go/models/components" - "log" - "os" -) - -func main() { - s := log10go.New( - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), - ) - var completionID string = "" - - completion := components.Completion{ - OrganizationID: "", - Request: &components.CreateChatCompletionRequest{ - Messages: []components.ChatCompletionRequestMessage{ - components.CreateChatCompletionRequestMessageChatCompletionRequestFunctionMessage( - components.ChatCompletionRequestFunctionMessage{ - Role: components.ChatCompletionRequestFunctionMessageRoleFunction, - Content: "", - Name: "", - }, - ), - }, - Model: components.CreateModelTwo( - components.TwoGpt4Turbo, - ), - N: log10go.Int64(1), - ResponseFormat: &components.ResponseFormat{ - Type: components.CreateChatCompletionRequestTypeJSONObject.ToPointer(), - }, - Temperature: log10go.Float64(1), - TopP: log10go.Float64(1), - User: log10go.String("user-1234"), - }, - } +### [Sessions](docs/sdks/sessions/README.md) - var xLog10Organization *string = log10go.String("") - ctx := context.Background() - res, err := s.Completions.Update(ctx, completionID, completion, xLog10Organization) - if err != nil { - log.Fatal(err) - } - if res.Completion != nil { - // handle response - } -} +* [Create](docs/sdks/sessions/README.md#create) - Create a session -``` - +
+ ## Error Handling -Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both. When specified by the OpenAPI spec document, the SDK will return the appropriate subclass. +Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both. + +By Default, an API error will return `sdkerrors.SDKError`. When custom error responses are specified for an operation, the SDK may also return their associated error. You can refer to respective *Errors* tables in SDK docs for more details on possible error types for each operation. -| Error Object | Status Code | Content Type | -| ------------------ | ------------------ | ------------------ | -| sdkerrors.SDKError | 4xx-5xx | */* | +For example, the `Create` function may return the following errors: + +| Error Type | Status Code | Content Type | +| ------------------ | ----------- | ------------ | +| sdkerrors.SDKError | 4XX, 5XX | \*/\* | ### Example @@ -179,25 +140,29 @@ import ( "github.com/log10-io/log10go/models/components" "github.com/log10-io/log10go/models/sdkerrors" "log" - "os" ) func main() { + ctx := context.Background() + s := log10go.New( - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), + log10go.WithSecurity(""), ) - completion := components.Completion{ - OrganizationID: "", + + res, err := s.Completions.Create(ctx, components.Completion{ + OrganizationID: "", Request: &components.CreateChatCompletionRequest{ Messages: []components.ChatCompletionRequestMessage{ - components.CreateChatCompletionRequestMessageChatCompletionRequestAssistantMessage( - components.ChatCompletionRequestAssistantMessage{ - Role: components.ChatCompletionRequestAssistantMessageRoleAssistant, + components.CreateChatCompletionRequestMessageChatCompletionRequestToolMessage( + components.ChatCompletionRequestToolMessage{ + Role: components.ChatCompletionRequestToolMessageRoleTool, + Content: "", + ToolCallID: "", }, ), }, - Model: components.CreateModelTwo( - components.TwoGpt4Turbo, + Model: components.CreateModelStr( + "gpt-4-turbo", ), N: log10go.Int64(1), ResponseFormat: &components.ResponseFormat{ @@ -207,11 +172,7 @@ func main() { TopP: log10go.Float64(1), User: log10go.String("user-1234"), }, - } - - var xLog10Organization *string = log10go.String("") - ctx := context.Background() - res, err := s.Completions.Create(ctx, completion, xLog10Organization) + }, log10go.String("")) if err != nil { var e *sdkerrors.SDKError @@ -228,16 +189,9 @@ func main() { ## Server Selection -### Select Server by Index - -You can override the default server globally using the `WithServerIndex` option when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers: - -| # | Server | Variables | -| - | ------ | --------- | -| 0 | `https://log10.io` | None | - -#### Example +### Override Server URL Per-Client +The default server can also be overridden globally using the `WithServerURL(serverURL string)` option when initializing the SDK client instance. For example: ```go package main @@ -246,82 +200,30 @@ import ( "github.com/log10-io/log10go" "github.com/log10-io/log10go/models/components" "log" - "os" ) func main() { - s := log10go.New( - log10go.WithServerIndex(0), - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), - ) - completion := components.Completion{ - OrganizationID: "", - Request: &components.CreateChatCompletionRequest{ - Messages: []components.ChatCompletionRequestMessage{ - components.CreateChatCompletionRequestMessageChatCompletionRequestAssistantMessage( - components.ChatCompletionRequestAssistantMessage{ - Role: components.ChatCompletionRequestAssistantMessageRoleAssistant, - }, - ), - }, - Model: components.CreateModelTwo( - components.TwoGpt4Turbo, - ), - N: log10go.Int64(1), - ResponseFormat: &components.ResponseFormat{ - Type: components.CreateChatCompletionRequestTypeJSONObject.ToPointer(), - }, - Temperature: log10go.Float64(1), - TopP: log10go.Float64(1), - User: log10go.String("user-1234"), - }, - } - - var xLog10Organization *string = log10go.String("") ctx := context.Background() - res, err := s.Completions.Create(ctx, completion, xLog10Organization) - if err != nil { - log.Fatal(err) - } - if res.Any != nil { - // handle response - } -} - -``` - -### Override Server URL Per-Client - -The default server can also be overridden globally using the `WithServerURL` option when initializing the SDK client instance. For example: -```go -package main - -import ( - "context" - "github.com/log10-io/log10go" - "github.com/log10-io/log10go/models/components" - "log" - "os" -) - -func main() { s := log10go.New( log10go.WithServerURL("https://log10.io"), - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), + log10go.WithSecurity(""), ) - completion := components.Completion{ - OrganizationID: "", + + res, err := s.Completions.Create(ctx, components.Completion{ + OrganizationID: "", Request: &components.CreateChatCompletionRequest{ Messages: []components.ChatCompletionRequestMessage{ - components.CreateChatCompletionRequestMessageChatCompletionRequestAssistantMessage( - components.ChatCompletionRequestAssistantMessage{ - Role: components.ChatCompletionRequestAssistantMessageRoleAssistant, + components.CreateChatCompletionRequestMessageChatCompletionRequestToolMessage( + components.ChatCompletionRequestToolMessage{ + Role: components.ChatCompletionRequestToolMessageRoleTool, + Content: "", + ToolCallID: "", }, ), }, - Model: components.CreateModelTwo( - components.TwoGpt4Turbo, + Model: components.CreateModelStr( + "gpt-4-turbo", ), N: log10go.Int64(1), ResponseFormat: &components.ResponseFormat{ @@ -331,11 +233,7 @@ func main() { TopP: log10go.Float64(1), User: log10go.String("user-1234"), }, - } - - var xLog10Organization *string = log10go.String("") - ctx := context.Background() - res, err := s.Completions.Create(ctx, completion, xLog10Organization) + }, log10go.String("")) if err != nil { log.Fatal(err) } @@ -383,9 +281,9 @@ This can be a convenient way to configure timeouts, cookies, proxies, custom hea This SDK supports the following security scheme globally: -| Name | Type | Scheme | -| ------------ | ------------ | ------------ | -| `Log10Token` | apiKey | API key | +| Name | Type | Scheme | +| ------------ | ------ | ------- | +| `Log10Token` | apiKey | API key | You can configure it using the `WithSecurity` option when initializing the SDK client instance. For example: ```go @@ -396,25 +294,29 @@ import ( "github.com/log10-io/log10go" "github.com/log10-io/log10go/models/components" "log" - "os" ) func main() { + ctx := context.Background() + s := log10go.New( - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), + log10go.WithSecurity(""), ) - completion := components.Completion{ - OrganizationID: "", + + res, err := s.Completions.Create(ctx, components.Completion{ + OrganizationID: "", Request: &components.CreateChatCompletionRequest{ Messages: []components.ChatCompletionRequestMessage{ - components.CreateChatCompletionRequestMessageChatCompletionRequestAssistantMessage( - components.ChatCompletionRequestAssistantMessage{ - Role: components.ChatCompletionRequestAssistantMessageRoleAssistant, + components.CreateChatCompletionRequestMessageChatCompletionRequestToolMessage( + components.ChatCompletionRequestToolMessage{ + Role: components.ChatCompletionRequestToolMessageRoleTool, + Content: "", + ToolCallID: "", }, ), }, - Model: components.CreateModelTwo( - components.TwoGpt4Turbo, + Model: components.CreateModelStr( + "gpt-4-turbo", ), N: log10go.Int64(1), ResponseFormat: &components.ResponseFormat{ @@ -424,11 +326,7 @@ func main() { TopP: log10go.Float64(1), User: log10go.String("user-1234"), }, - } - - var xLog10Organization *string = log10go.String("") - ctx := context.Background() - res, err := s.Completions.Create(ctx, completion, xLog10Organization) + }, log10go.String("")) if err != nil { log.Fatal(err) } @@ -440,12 +338,6 @@ func main() { ``` - -## Special Types - - - - ## Retries @@ -462,25 +354,29 @@ import ( "github.com/log10-io/log10go/retry" "log" "models/operations" - "os" ) func main() { + ctx := context.Background() + s := log10go.New( - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), + log10go.WithSecurity(""), ) - completion := components.Completion{ - OrganizationID: "", + + res, err := s.Completions.Create(ctx, components.Completion{ + OrganizationID: "", Request: &components.CreateChatCompletionRequest{ Messages: []components.ChatCompletionRequestMessage{ - components.CreateChatCompletionRequestMessageChatCompletionRequestAssistantMessage( - components.ChatCompletionRequestAssistantMessage{ - Role: components.ChatCompletionRequestAssistantMessageRoleAssistant, + components.CreateChatCompletionRequestMessageChatCompletionRequestToolMessage( + components.ChatCompletionRequestToolMessage{ + Role: components.ChatCompletionRequestToolMessageRoleTool, + Content: "", + ToolCallID: "", }, ), }, - Model: components.CreateModelTwo( - components.TwoGpt4Turbo, + Model: components.CreateModelStr( + "gpt-4-turbo", ), N: log10go.Int64(1), ResponseFormat: &components.ResponseFormat{ @@ -490,11 +386,7 @@ func main() { TopP: log10go.Float64(1), User: log10go.String("user-1234"), }, - } - - var xLog10Organization *string = log10go.String("") - ctx := context.Background() - res, err := s.Completions.Create(ctx, completion, xLog10Organization, operations.WithRetries( + }, log10go.String(""), operations.WithRetries( retry.Config{ Strategy: "backoff", Backoff: &retry.BackoffStrategy{ @@ -525,10 +417,11 @@ import ( "github.com/log10-io/log10go/models/components" "github.com/log10-io/log10go/retry" "log" - "os" ) func main() { + ctx := context.Background() + s := log10go.New( log10go.WithRetryConfig( retry.Config{ @@ -541,20 +434,23 @@ func main() { }, RetryConnectionErrors: false, }), - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), + log10go.WithSecurity(""), ) - completion := components.Completion{ - OrganizationID: "", + + res, err := s.Completions.Create(ctx, components.Completion{ + OrganizationID: "", Request: &components.CreateChatCompletionRequest{ Messages: []components.ChatCompletionRequestMessage{ - components.CreateChatCompletionRequestMessageChatCompletionRequestAssistantMessage( - components.ChatCompletionRequestAssistantMessage{ - Role: components.ChatCompletionRequestAssistantMessageRoleAssistant, + components.CreateChatCompletionRequestMessageChatCompletionRequestToolMessage( + components.ChatCompletionRequestToolMessage{ + Role: components.ChatCompletionRequestToolMessageRoleTool, + Content: "", + ToolCallID: "", }, ), }, - Model: components.CreateModelTwo( - components.TwoGpt4Turbo, + Model: components.CreateModelStr( + "gpt-4-turbo", ), N: log10go.Int64(1), ResponseFormat: &components.ResponseFormat{ @@ -564,11 +460,7 @@ func main() { TopP: log10go.Float64(1), User: log10go.String("user-1234"), }, - } - - var xLog10Organization *string = log10go.String("") - ctx := context.Background() - res, err := s.Completions.Create(ctx, completion, xLog10Organization) + }, log10go.String("")) if err != nil { log.Fatal(err) } diff --git a/RELEASES.md b/RELEASES.md index 20f4db3..ac2d4ae 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -8,4 +8,14 @@ Based on: ### Generated - [go v0.1.0] . ### Releases -- [Go v0.1.0] https://github.com/log10-io/log10go/releases/tag/v0.1.0 - . \ No newline at end of file +- [Go v0.1.0] https://github.com/log10-io/log10go/releases/tag/v0.1.0 - . + +## 2025-01-15 00:12:57 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.468.6 (2.493.13) https://github.com/speakeasy-api/speakeasy +### Generated +- [go v0.2.0] . +### Releases +- [Go v0.2.0] https://github.com/log10-io/log10go/releases/tag/v0.2.0 - . \ No newline at end of file diff --git a/USAGE.md b/USAGE.md index cf67e52..0cb1c05 100644 --- a/USAGE.md +++ b/USAGE.md @@ -6,16 +6,16 @@ import ( "context" "github.com/log10-io/log10go" "log" - "os" ) func main() { + ctx := context.Background() + s := log10go.New( - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), + log10go.WithSecurity(""), ) - var xLog10Organization *string = log10go.String("") - ctx := context.Background() - res, err := s.Sessions.Create(ctx, xLog10Organization) + + res, err := s.Sessions.Create(ctx, log10go.String("")) if err != nil { log.Fatal(err) } diff --git a/completions.go b/completions.go index 0e3e802..67ea569 100644 --- a/completions.go +++ b/completions.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package log10go @@ -6,14 +6,14 @@ import ( "bytes" "context" "fmt" - "github.com/cenkalti/backoff/v4" "github.com/log10-io/log10go/internal/hooks" "github.com/log10-io/log10go/internal/utils" "github.com/log10-io/log10go/models/components" "github.com/log10-io/log10go/models/operations" "github.com/log10-io/log10go/models/sdkerrors" - "io" + "github.com/log10-io/log10go/retry" "net/http" + "net/url" ) // Completions @@ -56,8 +56,13 @@ func (s *Completions) Create(ctx context.Context, completion components.Completi } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) - opURL, err := utils.GenerateURL(ctx, baseURL, "/api/v1/completions", request, globals) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } + opURL, err := url.JoinPath(baseURL, "/api/v1/completions") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } @@ -84,18 +89,20 @@ func (s *Completions) Create(ctx context.Context, completion components.Completi } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } utils.PopulateHeaders(ctx, req, request, globals) - if err := utils.PopulateQueryParams(ctx, req, request, globals); err != nil { - return nil, fmt.Errorf("error populating query params: %w", err) - } - if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { return nil, err } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + globalRetryConfig := s.sdkConfiguration.RetryConfig retryConfig := o.Retries if retryConfig == nil { @@ -126,7 +133,11 @@ func (s *Completions) Create(ctx context.Context, completion components.Completi req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -188,17 +199,15 @@ func (s *Completions) Create(ctx context.Context, completion components.Completi }, } - rawBody, err := io.ReadAll(httpRes.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) - } - httpRes.Body.Close() - httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) - switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + var out any if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -206,11 +215,20 @@ func (s *Completions) Create(ctx context.Context, completion components.Completi res.Any = out default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 201: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + var out components.Completion if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -218,13 +236,25 @@ func (s *Completions) Create(ctx context.Context, completion components.Completi res.Completion = &out default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: fallthrough case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) } @@ -262,7 +292,12 @@ func (s *Completions) Update(ctx context.Context, completionID string, completio } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := utils.GenerateURL(ctx, baseURL, "/api/v1/completions/{completionId}", request, globals) if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) @@ -290,18 +325,20 @@ func (s *Completions) Update(ctx context.Context, completionID string, completio } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } utils.PopulateHeaders(ctx, req, request, globals) - if err := utils.PopulateQueryParams(ctx, req, request, globals); err != nil { - return nil, fmt.Errorf("error populating query params: %w", err) - } - if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { return nil, err } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + globalRetryConfig := s.sdkConfiguration.RetryConfig retryConfig := o.Retries if retryConfig == nil { @@ -332,7 +369,11 @@ func (s *Completions) Update(ctx context.Context, completionID string, completio req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -394,17 +435,15 @@ func (s *Completions) Update(ctx context.Context, completionID string, completio }, } - rawBody, err := io.ReadAll(httpRes.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) - } - httpRes.Body.Close() - httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) - switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + var out components.Completion if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -412,13 +451,25 @@ func (s *Completions) Update(ctx context.Context, completionID string, completio res.Completion = &out default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: fallthrough case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) } @@ -454,8 +505,13 @@ func (s *Completions) ListUngraded(ctx context.Context, xLog10Organization *stri } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) - opURL, err := utils.GenerateURL(ctx, baseURL, "/api/v1/completions/ungraded", request, globals) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } + opURL, err := url.JoinPath(baseURL, "/api/v1/completions/ungraded") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } @@ -480,14 +536,14 @@ func (s *Completions) ListUngraded(ctx context.Context, xLog10Organization *stri utils.PopulateHeaders(ctx, req, request, globals) - if err := utils.PopulateQueryParams(ctx, req, request, globals); err != nil { - return nil, fmt.Errorf("error populating query params: %w", err) - } - if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { return nil, err } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + globalRetryConfig := s.sdkConfiguration.RetryConfig retryConfig := o.Retries if retryConfig == nil { @@ -518,7 +574,11 @@ func (s *Completions) ListUngraded(ctx context.Context, xLog10Organization *stri req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -580,17 +640,15 @@ func (s *Completions) ListUngraded(ctx context.Context, xLog10Organization *stri }, } - rawBody, err := io.ReadAll(httpRes.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) - } - httpRes.Body.Close() - httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) - switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + var out operations.ListUngradedResponseBody if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -598,13 +656,25 @@ func (s *Completions) ListUngraded(ctx context.Context, xLog10Organization *stri res.Object = &out default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: fallthrough case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) } diff --git a/docs/models/components/security.md b/docs/models/components/security.md index 478391c..c5ca81c 100644 --- a/docs/models/components/security.md +++ b/docs/models/components/security.md @@ -5,4 +5,4 @@ | Field | Type | Required | Description | | ------------------ | ------------------ | ------------------ | ------------------ | -| `Log10Token` | **string* | :heavy_minus_sign: | N/A | \ No newline at end of file +| `Log10Token` | *string* | :heavy_check_mark: | N/A | \ No newline at end of file diff --git a/docs/sdks/completions/README.md b/docs/sdks/completions/README.md index 5cfa258..6752210 100644 --- a/docs/sdks/completions/README.md +++ b/docs/sdks/completions/README.md @@ -21,29 +21,33 @@ Create a completion package main import( - "os" + "context" "github.com/log10-io/log10go" "github.com/log10-io/log10go/models/components" - "context" "log" ) func main() { + ctx := context.Background() + s := log10go.New( - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), + log10go.WithSecurity(""), ) - completion := components.Completion{ - OrganizationID: "", + + res, err := s.Completions.Create(ctx, components.Completion{ + OrganizationID: "", Request: &components.CreateChatCompletionRequest{ Messages: []components.ChatCompletionRequestMessage{ - components.CreateChatCompletionRequestMessageChatCompletionRequestAssistantMessage( - components.ChatCompletionRequestAssistantMessage{ - Role: components.ChatCompletionRequestAssistantMessageRoleAssistant, + components.CreateChatCompletionRequestMessageChatCompletionRequestToolMessage( + components.ChatCompletionRequestToolMessage{ + Role: components.ChatCompletionRequestToolMessageRoleTool, + Content: "", + ToolCallID: "", }, ), }, - Model: components.CreateModelTwo( - components.TwoGpt4Turbo, + Model: components.CreateModelStr( + "gpt-4-turbo", ), N: log10go.Int64(1), ResponseFormat: &components.ResponseFormat{ @@ -53,11 +57,7 @@ func main() { TopP: log10go.Float64(1), User: log10go.String("user-1234"), }, - } - - var xLog10Organization *string = log10go.String("") - ctx := context.Background() - res, err := s.Completions.Create(ctx, completion, xLog10Organization) + }, log10go.String("")) if err != nil { log.Fatal(err) } @@ -76,13 +76,15 @@ func main() { | `xLog10Organization` | **string* | :heavy_minus_sign: | N/A | | `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. | - ### Response **[*operations.CreateResponse](../../models/operations/createresponse.md), error** -| Error Object | Status Code | Content Type | + +### Errors + +| Error Type | Status Code | Content Type | | ------------------ | ------------------ | ------------------ | -| sdkerrors.SDKError | 4xx-5xx | */* | +| sdkerrors.SDKError | 4XX, 5XX | \*/\* | ## Update @@ -94,33 +96,62 @@ Update completion by id. package main import( - "os" + "context" "github.com/log10-io/log10go" "github.com/log10-io/log10go/models/components" - "context" "log" ) func main() { + ctx := context.Background() + s := log10go.New( - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), + log10go.WithSecurity(""), ) - var completionID string = "" - completion := components.Completion{ - OrganizationID: "", + res, err := s.Completions.Update(ctx, "", components.Completion{ + OrganizationID: "", Request: &components.CreateChatCompletionRequest{ Messages: []components.ChatCompletionRequestMessage{ - components.CreateChatCompletionRequestMessageChatCompletionRequestFunctionMessage( - components.ChatCompletionRequestFunctionMessage{ - Role: components.ChatCompletionRequestFunctionMessageRoleFunction, - Content: "", - Name: "", + components.CreateChatCompletionRequestMessageChatCompletionRequestAssistantMessage( + components.ChatCompletionRequestAssistantMessage{ + Role: components.ChatCompletionRequestAssistantMessageRoleAssistant, + }, + ), + components.CreateChatCompletionRequestMessageChatCompletionRequestUserMessage( + components.ChatCompletionRequestUserMessage{ + Content: components.CreateContentArrayOfChatCompletionRequestMessageContentPart( + []components.ChatCompletionRequestMessageContentPart{ + components.CreateChatCompletionRequestMessageContentPartChatCompletionRequestMessageContentPartText( + components.ChatCompletionRequestMessageContentPartText{ + Type: components.TypeText, + Text: "", + }, + ), + components.CreateChatCompletionRequestMessageContentPartChatCompletionRequestMessageContentPartImage( + components.ChatCompletionRequestMessageContentPartImage{ + Type: components.ChatCompletionRequestMessageContentPartImageTypeImageURL, + ImageURL: components.ImageURL{ + URL: "https://unlucky-hydrolyze.biz/", + }, + }, + ), + }, + ), + Role: components.ChatCompletionRequestUserMessageRoleUser, + }, + ), + components.CreateChatCompletionRequestMessageChatCompletionRequestUserMessage( + components.ChatCompletionRequestUserMessage{ + Content: components.CreateContentStr( + "", + ), + Role: components.ChatCompletionRequestUserMessageRoleUser, }, ), }, - Model: components.CreateModelTwo( - components.TwoGpt4Turbo, + Model: components.CreateModelStr( + "gpt-4-turbo", ), N: log10go.Int64(1), ResponseFormat: &components.ResponseFormat{ @@ -130,11 +161,7 @@ func main() { TopP: log10go.Float64(1), User: log10go.String("user-1234"), }, - } - - var xLog10Organization *string = log10go.String("") - ctx := context.Background() - res, err := s.Completions.Update(ctx, completionID, completion, xLog10Organization) + }, log10go.String("")) if err != nil { log.Fatal(err) } @@ -154,13 +181,15 @@ func main() { | `xLog10Organization` | **string* | :heavy_minus_sign: | N/A | | `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. | - ### Response **[*operations.UpdateResponse](../../models/operations/updateresponse.md), error** -| Error Object | Status Code | Content Type | + +### Errors + +| Error Type | Status Code | Content Type | | ------------------ | ------------------ | ------------------ | -| sdkerrors.SDKError | 4xx-5xx | */* | +| sdkerrors.SDKError | 4XX, 5XX | \*/\* | ## ListUngraded @@ -172,19 +201,19 @@ List ungraded completions i.e. completions that have not been associated with fe package main import( - "os" - "github.com/log10-io/log10go" "context" + "github.com/log10-io/log10go" "log" ) func main() { + ctx := context.Background() + s := log10go.New( - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), + log10go.WithSecurity(""), ) - var xLog10Organization *string = log10go.String("") - ctx := context.Background() - res, err := s.Completions.ListUngraded(ctx, xLog10Organization) + + res, err := s.Completions.ListUngraded(ctx, log10go.String("")) if err != nil { log.Fatal(err) } @@ -202,10 +231,12 @@ func main() { | `xLog10Organization` | **string* | :heavy_minus_sign: | N/A | | `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. | - ### Response **[*operations.ListUngradedResponse](../../models/operations/listungradedresponse.md), error** -| Error Object | Status Code | Content Type | + +### Errors + +| Error Type | Status Code | Content Type | | ------------------ | ------------------ | ------------------ | -| sdkerrors.SDKError | 4xx-5xx | */* | +| sdkerrors.SDKError | 4XX, 5XX | \*/\* | \ No newline at end of file diff --git a/docs/sdks/feedback/README.md b/docs/sdks/feedback/README.md index 0b92f0f..6379718 100644 --- a/docs/sdks/feedback/README.md +++ b/docs/sdks/feedback/README.md @@ -21,21 +21,19 @@ Fetch feedback by id. package main import( - "os" - "github.com/log10-io/log10go" "context" + "github.com/log10-io/log10go" "log" ) func main() { + ctx := context.Background() + s := log10go.New( - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), + log10go.WithSecurity(""), ) - var feedbackID string = "" - var xLog10Organization *string = log10go.String("") - ctx := context.Background() - res, err := s.Feedback.Get(ctx, feedbackID, xLog10Organization) + res, err := s.Feedback.Get(ctx, "", log10go.String("")) if err != nil { log.Fatal(err) } @@ -54,13 +52,15 @@ func main() { | `xLog10Organization` | **string* | :heavy_minus_sign: | N/A | | `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. | - ### Response **[*operations.GetResponse](../../models/operations/getresponse.md), error** -| Error Object | Status Code | Content Type | + +### Errors + +| Error Type | Status Code | Content Type | | ------------------ | ------------------ | ------------------ | -| sdkerrors.SDKError | 4xx-5xx | */* | +| sdkerrors.SDKError | 4XX, 5XX | \*/\* | ## List @@ -72,22 +72,19 @@ List feedback package main import( - "os" - "github.com/log10-io/log10go" - "github.com/log10-io/log10go/models/operations" "context" + "github.com/log10-io/log10go" "log" ) func main() { + ctx := context.Background() + s := log10go.New( - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), + log10go.WithSecurity(""), ) - var xLog10Organization *string = log10go.String("") - var requestBody *operations.ListRequestBody = &operations.ListRequestBody{} - ctx := context.Background() - res, err := s.Feedback.List(ctx, xLog10Organization, requestBody) + res, err := s.Feedback.List(ctx, log10go.String(""), nil) if err != nil { log.Fatal(err) } @@ -106,13 +103,15 @@ func main() { | `requestBody` | [*operations.ListRequestBody](../../models/operations/listrequestbody.md) | :heavy_minus_sign: | N/A | | `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. | - ### Response **[*operations.ListResponse](../../models/operations/listresponse.md), error** -| Error Object | Status Code | Content Type | + +### Errors + +| Error Type | Status Code | Content Type | | ------------------ | ------------------ | ------------------ | -| sdkerrors.SDKError | 4xx-5xx | */* | +| sdkerrors.SDKError | 4XX, 5XX | \*/\* | ## Upload @@ -124,34 +123,33 @@ Upload a piece of feedback package main import( - "os" + "context" "github.com/log10-io/log10go" "github.com/log10-io/log10go/models/operations" - "context" "log" ) func main() { + ctx := context.Background() + s := log10go.New( - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), - ) - var requestBody operations.UploadRequestBody = operations.CreateUploadRequestBodyOne( - operations.One{ - TaskID: "", - JSONValues: operations.JSONValues{}, - MatchedCompletionIds: []string{ - "", - }, - Comment: "The slim & simple Maple Gaming Keyboard from Dev Byte comes with a sleek body and 7- Color RGB LED Back-lighting for smart functionality", - CompletionTagsSelector: []string{ - "", - }, - }, + log10go.WithSecurity(""), ) - var xLog10Organization *string = log10go.String("") - ctx := context.Background() - res, err := s.Feedback.Upload(ctx, requestBody, xLog10Organization) + res, err := s.Feedback.Upload(ctx, operations.CreateUploadRequestBodyOne( + operations.One{ + TaskID: "", + JSONValues: operations.JSONValues{}, + MatchedCompletionIds: []string{ + "", + "", + }, + Comment: "The Apollotech B340 is an affordable wireless mouse with reliable connectivity, 12 months battery life and modern design", + CompletionTagsSelector: []string{ + "", + }, + }, + ), log10go.String("")) if err != nil { log.Fatal(err) } @@ -170,10 +168,12 @@ func main() { | `xLog10Organization` | **string* | :heavy_minus_sign: | N/A | | `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. | - ### Response **[*operations.UploadResponse](../../models/operations/uploadresponse.md), error** -| Error Object | Status Code | Content Type | + +### Errors + +| Error Type | Status Code | Content Type | | ------------------ | ------------------ | ------------------ | -| sdkerrors.SDKError | 4xx-5xx | */* | +| sdkerrors.SDKError | 4XX, 5XX | \*/\* | \ No newline at end of file diff --git a/docs/sdks/feedbacktasks/README.md b/docs/sdks/feedbacktasks/README.md index af1e33d..d210a85 100644 --- a/docs/sdks/feedbacktasks/README.md +++ b/docs/sdks/feedbacktasks/README.md @@ -21,18 +21,18 @@ List feedback tasks. package main import( - "os" - "github.com/log10-io/log10go" "context" + "github.com/log10-io/log10go" "log" ) func main() { + ctx := context.Background() + s := log10go.New( - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), + log10go.WithSecurity(""), ) - ctx := context.Background() res, err := s.FeedbackTasks.List(ctx) if err != nil { log.Fatal(err) @@ -50,13 +50,15 @@ func main() { | `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. | | `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. | - ### Response **[*operations.ListFeedbackTasksResponse](../../models/operations/listfeedbacktasksresponse.md), error** -| Error Object | Status Code | Content Type | + +### Errors + +| Error Type | Status Code | Content Type | | ------------------ | ------------------ | ------------------ | -| sdkerrors.SDKError | 4xx-5xx | */* | +| sdkerrors.SDKError | 4XX, 5XX | \*/\* | ## Create @@ -68,25 +70,19 @@ Create a new task. package main import( - "os" - "github.com/log10-io/log10go" - "github.com/log10-io/log10go/models/components" "context" + "github.com/log10-io/log10go" "log" ) func main() { + ctx := context.Background() + s := log10go.New( - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), + log10go.WithSecurity(""), ) - var request *components.Task = &components.Task{ - JSONSchema: components.JSONSchema{}, - Name: "", - Instruction: "", - CompletionTagsSelector: components.CompletionTagsSelector{}, - } - ctx := context.Background() - res, err := s.FeedbackTasks.Create(ctx, request) + + res, err := s.FeedbackTasks.Create(ctx, nil) if err != nil { log.Fatal(err) } @@ -104,13 +100,15 @@ func main() { | `request` | [components.Task](../../models/components/task.md) | :heavy_check_mark: | The request object to use for the request. | | `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. | - ### Response **[*operations.CreateFeedbackTaskResponse](../../models/operations/createfeedbacktaskresponse.md), error** -| Error Object | Status Code | Content Type | + +### Errors + +| Error Type | Status Code | Content Type | | ------------------ | ------------------ | ------------------ | -| sdkerrors.SDKError | 4xx-5xx | */* | +| sdkerrors.SDKError | 4XX, 5XX | \*/\* | ## Get @@ -122,19 +120,19 @@ Retrieves feedback task `taskId`. package main import( - "os" - "github.com/log10-io/log10go" "context" + "github.com/log10-io/log10go" "log" ) func main() { + ctx := context.Background() + s := log10go.New( - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), + log10go.WithSecurity(""), ) - var taskID string = "" - ctx := context.Background() - res, err := s.FeedbackTasks.Get(ctx, taskID) + + res, err := s.FeedbackTasks.Get(ctx, "") if err != nil { log.Fatal(err) } @@ -152,10 +150,12 @@ func main() { | `taskID` | *string* | :heavy_check_mark: | The task id to fetch. | | `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. | - ### Response **[*operations.GetFeedbackTaskResponse](../../models/operations/getfeedbacktaskresponse.md), error** -| Error Object | Status Code | Content Type | + +### Errors + +| Error Type | Status Code | Content Type | | ------------------ | ------------------ | ------------------ | -| sdkerrors.SDKError | 4xx-5xx | */* | +| sdkerrors.SDKError | 4XX, 5XX | \*/\* | \ No newline at end of file diff --git a/docs/sdks/log10/README.md b/docs/sdks/log10/README.md index 89307d2..acfb2b3 100644 --- a/docs/sdks/log10/README.md +++ b/docs/sdks/log10/README.md @@ -1,9 +1,7 @@ # Log10 SDK - ## Overview Log10 Feedback API Spec: Log10 Feedback API Spec ### Available Operations - diff --git a/docs/sdks/sessions/README.md b/docs/sdks/sessions/README.md index b7efde1..3b67772 100644 --- a/docs/sdks/sessions/README.md +++ b/docs/sdks/sessions/README.md @@ -19,19 +19,19 @@ Create a session package main import( - "os" - "github.com/log10-io/log10go" "context" + "github.com/log10-io/log10go" "log" ) func main() { + ctx := context.Background() + s := log10go.New( - log10go.WithSecurity(os.Getenv("LOG10_TOKEN")), + log10go.WithSecurity(""), ) - var xLog10Organization *string = log10go.String("") - ctx := context.Background() - res, err := s.Sessions.Create(ctx, xLog10Organization) + + res, err := s.Sessions.Create(ctx, log10go.String("")) if err != nil { log.Fatal(err) } @@ -49,10 +49,12 @@ func main() { | `xLog10Organization` | **string* | :heavy_minus_sign: | N/A | | `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. | - ### Response **[*operations.CreateSessionResponse](../../models/operations/createsessionresponse.md), error** -| Error Object | Status Code | Content Type | + +### Errors + +| Error Type | Status Code | Content Type | | ------------------ | ------------------ | ------------------ | -| sdkerrors.SDKError | 4xx-5xx | */* | +| sdkerrors.SDKError | 4XX, 5XX | \*/\* | \ No newline at end of file diff --git a/feedback.go b/feedback.go index cb9be75..f4a09fe 100644 --- a/feedback.go +++ b/feedback.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package log10go @@ -6,14 +6,14 @@ import ( "bytes" "context" "fmt" - "github.com/cenkalti/backoff/v4" "github.com/log10-io/log10go/internal/hooks" "github.com/log10-io/log10go/internal/utils" "github.com/log10-io/log10go/models/components" "github.com/log10-io/log10go/models/operations" "github.com/log10-io/log10go/models/sdkerrors" - "io" + "github.com/log10-io/log10go/retry" "net/http" + "net/url" ) // Feedback @@ -56,7 +56,12 @@ func (s *Feedback) Get(ctx context.Context, feedbackID string, xLog10Organizatio } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := utils.GenerateURL(ctx, baseURL, "/api/v1/feedback/{feedbackId}", request, globals) if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) @@ -82,14 +87,14 @@ func (s *Feedback) Get(ctx context.Context, feedbackID string, xLog10Organizatio utils.PopulateHeaders(ctx, req, request, globals) - if err := utils.PopulateQueryParams(ctx, req, request, globals); err != nil { - return nil, fmt.Errorf("error populating query params: %w", err) - } - if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { return nil, err } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + globalRetryConfig := s.sdkConfiguration.RetryConfig retryConfig := o.Retries if retryConfig == nil { @@ -120,7 +125,11 @@ func (s *Feedback) Get(ctx context.Context, feedbackID string, xLog10Organizatio req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -182,17 +191,15 @@ func (s *Feedback) Get(ctx context.Context, feedbackID string, xLog10Organizatio }, } - rawBody, err := io.ReadAll(httpRes.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) - } - httpRes.Body.Close() - httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) - switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + var out components.Feedback if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -200,13 +207,25 @@ func (s *Feedback) Get(ctx context.Context, feedbackID string, xLog10Organizatio res.Feedback = &out default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: fallthrough case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) } @@ -243,8 +262,13 @@ func (s *Feedback) List(ctx context.Context, xLog10Organization *string, request } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) - opURL, err := utils.GenerateURL(ctx, baseURL, "/api/v1/feedback", request, globals) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } + opURL, err := url.JoinPath(baseURL, "/api/v1/feedback") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } @@ -271,18 +295,20 @@ func (s *Feedback) List(ctx context.Context, xLog10Organization *string, request } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } utils.PopulateHeaders(ctx, req, request, globals) - if err := utils.PopulateQueryParams(ctx, req, request, globals); err != nil { - return nil, fmt.Errorf("error populating query params: %w", err) - } - if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { return nil, err } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + globalRetryConfig := s.sdkConfiguration.RetryConfig retryConfig := o.Retries if retryConfig == nil { @@ -313,7 +339,11 @@ func (s *Feedback) List(ctx context.Context, xLog10Organization *string, request req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -375,17 +405,15 @@ func (s *Feedback) List(ctx context.Context, xLog10Organization *string, request }, } - rawBody, err := io.ReadAll(httpRes.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) - } - httpRes.Body.Close() - httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) - switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + var out operations.ListResponseBody if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -393,13 +421,25 @@ func (s *Feedback) List(ctx context.Context, xLog10Organization *string, request res.Object = &out default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: fallthrough case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) } @@ -436,8 +476,13 @@ func (s *Feedback) Upload(ctx context.Context, requestBody operations.UploadRequ } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) - opURL, err := utils.GenerateURL(ctx, baseURL, "/api/v1/feedback", request, globals) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } + opURL, err := url.JoinPath(baseURL, "/api/v1/feedback") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } @@ -464,18 +509,20 @@ func (s *Feedback) Upload(ctx context.Context, requestBody operations.UploadRequ } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } utils.PopulateHeaders(ctx, req, request, globals) - if err := utils.PopulateQueryParams(ctx, req, request, globals); err != nil { - return nil, fmt.Errorf("error populating query params: %w", err) - } - if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { return nil, err } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + globalRetryConfig := s.sdkConfiguration.RetryConfig retryConfig := o.Retries if retryConfig == nil { @@ -506,7 +553,11 @@ func (s *Feedback) Upload(ctx context.Context, requestBody operations.UploadRequ req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -568,17 +619,15 @@ func (s *Feedback) Upload(ctx context.Context, requestBody operations.UploadRequ }, } - rawBody, err := io.ReadAll(httpRes.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) - } - httpRes.Body.Close() - httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) - switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + var out components.Feedback if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -586,13 +635,25 @@ func (s *Feedback) Upload(ctx context.Context, requestBody operations.UploadRequ res.Feedback = &out default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: fallthrough case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) } diff --git a/feedbacktasks.go b/feedbacktasks.go index 867ca3b..3bff4d4 100644 --- a/feedbacktasks.go +++ b/feedbacktasks.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package log10go @@ -6,13 +6,12 @@ import ( "bytes" "context" "fmt" - "github.com/cenkalti/backoff/v4" "github.com/log10-io/log10go/internal/hooks" "github.com/log10-io/log10go/internal/utils" "github.com/log10-io/log10go/models/components" "github.com/log10-io/log10go/models/operations" "github.com/log10-io/log10go/models/sdkerrors" - "io" + "github.com/log10-io/log10go/retry" "net/http" "net/url" ) @@ -48,7 +47,12 @@ func (s *FeedbackTasks) List(ctx context.Context, opts ...operations.Option) (*o } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/api/v1/feedback_task") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) @@ -76,6 +80,10 @@ func (s *FeedbackTasks) List(ctx context.Context, opts ...operations.Option) (*o return nil, err } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + globalRetryConfig := s.sdkConfiguration.RetryConfig retryConfig := o.Retries if retryConfig == nil { @@ -106,7 +114,11 @@ func (s *FeedbackTasks) List(ctx context.Context, opts ...operations.Option) (*o req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -168,17 +180,15 @@ func (s *FeedbackTasks) List(ctx context.Context, opts ...operations.Option) (*o }, } - rawBody, err := io.ReadAll(httpRes.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) - } - httpRes.Body.Close() - httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) - switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + var out []components.Task if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -186,13 +196,25 @@ func (s *FeedbackTasks) List(ctx context.Context, opts ...operations.Option) (*o res.Tasks = out default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: fallthrough case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) } @@ -220,7 +242,12 @@ func (s *FeedbackTasks) Create(ctx context.Context, request *components.Task, op } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/api/v1/feedback_task") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) @@ -248,12 +275,18 @@ func (s *FeedbackTasks) Create(ctx context.Context, request *components.Task, op } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { return nil, err } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + globalRetryConfig := s.sdkConfiguration.RetryConfig retryConfig := o.Retries if retryConfig == nil { @@ -284,7 +317,11 @@ func (s *FeedbackTasks) Create(ctx context.Context, request *components.Task, op req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -346,17 +383,15 @@ func (s *FeedbackTasks) Create(ctx context.Context, request *components.Task, op }, } - rawBody, err := io.ReadAll(httpRes.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) - } - httpRes.Body.Close() - httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) - switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + var out components.Task if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -364,13 +399,25 @@ func (s *FeedbackTasks) Create(ctx context.Context, request *components.Task, op res.Task = &out default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: fallthrough case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) } @@ -402,7 +449,12 @@ func (s *FeedbackTasks) Get(ctx context.Context, taskID string, opts ...operatio } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := utils.GenerateURL(ctx, baseURL, "/api/v1/feedback_task/{taskId}", request, nil) if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) @@ -430,6 +482,10 @@ func (s *FeedbackTasks) Get(ctx context.Context, taskID string, opts ...operatio return nil, err } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + globalRetryConfig := s.sdkConfiguration.RetryConfig retryConfig := o.Retries if retryConfig == nil { @@ -460,7 +516,11 @@ func (s *FeedbackTasks) Get(ctx context.Context, taskID string, opts ...operatio req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -522,17 +582,15 @@ func (s *FeedbackTasks) Get(ctx context.Context, taskID string, opts ...operatio }, } - rawBody, err := io.ReadAll(httpRes.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) - } - httpRes.Body.Close() - httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) - switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + var out components.Task if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -540,13 +598,25 @@ func (s *FeedbackTasks) Get(ctx context.Context, taskID string, opts ...operatio res.Task = &out default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: fallthrough case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) } diff --git a/go.mod b/go.mod index 6547c96..78bf7b6 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,4 @@ module github.com/log10-io/log10go go 1.20 -require ( - github.com/cenkalti/backoff/v4 v4.2.0 - github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 -) +require github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 diff --git a/go.sum b/go.sum index f955779..c5a75f1 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,2 @@ -github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4= -github.com/cenkalti/backoff/v4 v4.2.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 h1:S92OBrGuLLZsyM5ybUzgc/mPjIYk2AZqufieooe98uw= github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05/go.mod h1:M9R1FoZ3y//hwwnJtO51ypFGwm8ZfpxPT/ZLtO1mcgQ= diff --git a/internal/globals/globals.go b/internal/globals/globals.go index 66a1a65..380be5b 100644 --- a/internal/globals/globals.go +++ b/internal/globals/globals.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package globals diff --git a/internal/hooks/hooks.go b/internal/hooks/hooks.go index 58e5a4e..224a6a3 100644 --- a/internal/hooks/hooks.go +++ b/internal/hooks/hooks.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package hooks diff --git a/internal/utils/contenttype.go b/internal/utils/contenttype.go index 763f2d6..f6487e0 100644 --- a/internal/utils/contenttype.go +++ b/internal/utils/contenttype.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package utils diff --git a/internal/utils/env.go b/internal/utils/env.go new file mode 100644 index 0000000..110d464 --- /dev/null +++ b/internal/utils/env.go @@ -0,0 +1,16 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package utils + +import ( + "os" +) + +// GetEnv returns the value of the environment variable named by the key or the defaultValue if the environment variable is not set. +func GetEnv(name, defaultValue string) string { + value := os.Getenv(name) + if value == "" { + return defaultValue + } + return value +} diff --git a/internal/utils/form.go b/internal/utils/form.go index 11daa62..67e2629 100644 --- a/internal/utils/form.go +++ b/internal/utils/form.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package utils diff --git a/internal/utils/headers.go b/internal/utils/headers.go index 107d210..a07608b 100644 --- a/internal/utils/headers.go +++ b/internal/utils/headers.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package utils diff --git a/internal/utils/json.go b/internal/utils/json.go index 9fca6c8..bcb66a4 100644 --- a/internal/utils/json.go +++ b/internal/utils/json.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package utils @@ -165,11 +165,17 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool if field.Tag.Get("const") != "" { if r, ok := unmarhsaled[fieldName]; ok { val := string(r) + if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) { - val = val[1 : len(val)-1] + var err error + val, err = strconv.Unquote(val) + if err != nil { + return fmt.Errorf("failed to unquote const field `%s` value `%s`: %w", fieldName, val, err) + } } - if val != field.Tag.Get("const") { - return fmt.Errorf("const field %s does not match expected value %s", fieldName, field.Tag.Get("const")) + constValue := field.Tag.Get("const") + if val != constValue { + return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } delete(unmarhsaled, fieldName) @@ -481,30 +487,29 @@ func unmarshalValue(value json.RawMessage, v reflect.Value, tag reflect.StructTa v.Set(m) return nil case reflect.Slice, reflect.Array: - if bytes.Equal(value, []byte("null")) || !isComplexValueType(dereferenceTypePointer(typ.Elem())) { - if v.CanAddr() { - return json.Unmarshal(value, v.Addr().Interface()) - } else { - return json.Unmarshal(value, v.Interface()) - } - } - - var unmarhsaled []json.RawMessage + var unmarshaled []json.RawMessage - if err := json.Unmarshal(value, &unmarhsaled); err != nil { + if err := json.Unmarshal(value, &unmarshaled); err != nil { return err } - arrVal := v + arrVal := reflect.MakeSlice(typ, len(unmarshaled), len(unmarshaled)) - for _, value := range unmarhsaled { + for index, value := range unmarshaled { itemVal := reflect.New(typ.Elem()) if err := unmarshalValue(value, itemVal, tag, disallowUnknownFields); err != nil { return err } - arrVal = reflect.Append(arrVal, itemVal.Elem()) + arrVal.Index(index).Set(itemVal.Elem()) + } + + if v.Kind() == reflect.Pointer { + if v.IsNil() { + v.Set(reflect.New(typ)) + } + v = v.Elem() } v.Set(arrVal) diff --git a/internal/utils/pathparams.go b/internal/utils/pathparams.go index 5bba66a..7354fe5 100644 --- a/internal/utils/pathparams.go +++ b/internal/utils/pathparams.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package utils diff --git a/internal/utils/queryparams.go b/internal/utils/queryparams.go index 38eac43..7f4523a 100644 --- a/internal/utils/queryparams.go +++ b/internal/utils/queryparams.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package utils @@ -18,6 +18,11 @@ import ( ) func PopulateQueryParams(_ context.Context, req *http.Request, queryParams interface{}, globals interface{}) error { + // Query parameters may already be present from overriding URL + if req.URL.RawQuery != "" { + return nil + } + values := url.Values{} globalsAlreadyPopulated, err := populateQueryParams(queryParams, globals, values, []string{}) @@ -209,7 +214,11 @@ func populateDeepObjectParamsStruct(qsValues url.Values, priorScope string, stru continue } - scope := priorScope + "[" + qpTag.ParamName + "]" + scope := priorScope + + if !qpTag.Inline { + scope = priorScope + "[" + qpTag.ParamName + "]" + } switch fieldValue.Kind() { case reflect.Array, reflect.Slice: @@ -247,6 +256,13 @@ type paramTag struct { Explode bool ParamName string Serialization string + + // Inline is a special case for union/oneOf. When a wrapper struct type is + // used, each union/oneOf value field should be inlined (e.g. not appended + // in deepObject style with the name) as if the value was directly on the + // parent struct field. Without this annotation, the value would not be + // encoded by downstream logic that requires the struct field tag. + Inline bool } func parseQueryParamTag(field reflect.StructField) *paramTag { diff --git a/internal/utils/requestbody.go b/internal/utils/requestbody.go index cfb2ba6..78479c6 100644 --- a/internal/utils/requestbody.go +++ b/internal/utils/requestbody.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package utils @@ -66,15 +66,16 @@ func serializeRequestBody(request interface{}, nullable, optional bool, requestF if tag != nil { // request object (non-flattened) requestVal := requestValType.FieldByName(requestFieldName) + val := reflect.ValueOf(requestVal.Interface()) if isNil(requestField.Type, requestVal) { if !nullable && optional { return nil, "", nil } - return serializeContentType(requestFieldName, tag.MediaType, requestVal, string(requestField.Tag)) + return serializeContentType(requestFieldName, tag.MediaType, val, string(requestField.Tag)) } - return serializeContentType(requestFieldName, tag.MediaType, requestVal, string(requestField.Tag)) + return serializeContentType(requestFieldName, tag.MediaType, val, string(requestField.Tag)) } } @@ -82,7 +83,7 @@ func serializeRequestBody(request interface{}, nullable, optional bool, requestF return serializeContentType(requestFieldName, SerializationMethodToContentType[serializationMethod], reflect.ValueOf(request), tag) } -func serializeContentType(fieldName string, mediaType string, val reflect.Value, tag string) (*bytes.Buffer, string, error) { +func serializeContentType(fieldName string, mediaType string, val reflect.Value, tag string) (io.Reader, string, error) { buf := &bytes.Buffer{} if isNil(val.Type(), val) { @@ -116,6 +117,8 @@ func serializeContentType(fieldName string, mediaType string, val reflect.Value, if err := encodeFormData(fieldName, buf, val.Interface()); err != nil { return nil, "", err } + case val.Type().Implements(reflect.TypeOf((*io.Reader)(nil)).Elem()): + return val.Interface().(io.Reader), mediaType, nil default: val = reflect.Indirect(val) @@ -124,8 +127,8 @@ func serializeContentType(fieldName string, mediaType string, val reflect.Value, if _, err := buf.WriteString(valToString(val.Interface())); err != nil { return nil, "", err } - case val.Type() == reflect.TypeOf([]byte(nil)): - if _, err := buf.Write(val.Bytes()); err != nil { + case reflect.TypeOf(val.Interface()) == reflect.TypeOf([]byte(nil)): + if _, err := buf.Write(val.Interface().([]byte)); err != nil { return nil, "", err } default: @@ -163,7 +166,7 @@ func encodeMultipartFormData(w io.Writer, data interface{}) (string, error) { tag := parseMultipartFormTag(field) if tag.File { - if err := encodeMultipartFormDataFile(writer, fieldType, valType); err != nil { + if err := encodeMultipartFormDataFile(writer, tag.Name, fieldType, valType); err != nil { writer.Close() return "", err } @@ -208,14 +211,13 @@ func encodeMultipartFormData(w io.Writer, data interface{}) (string, error) { return writer.FormDataContentType(), nil } -func encodeMultipartFormDataFile(w *multipart.Writer, fieldType reflect.Type, valType reflect.Value) error { +func encodeMultipartFormDataFile(w *multipart.Writer, fieldName string, fieldType reflect.Type, valType reflect.Value) error { if fieldType.Kind() != reflect.Struct { return fmt.Errorf("invalid type %s for multipart/form-data file", valType.Type()) } - var fieldName string var fileName string - var content []byte + var reader io.Reader for i := 0; i < fieldType.NumField(); i++ { field := fieldType.Field(i) @@ -226,15 +228,18 @@ func encodeMultipartFormDataFile(w *multipart.Writer, fieldType reflect.Type, va continue } - if tag.Content { - content = val.Bytes() + if tag.Content && val.CanInterface() { + if reflect.TypeOf(val.Interface()) == reflect.TypeOf([]byte(nil)) { + reader = bytes.NewReader(val.Interface().([]byte)) + } else if reflect.TypeOf(val.Interface()).Implements(reflect.TypeOf((*io.Reader)(nil)).Elem()) { + reader = val.Interface().(io.Reader) + } } else { - fieldName = tag.Name fileName = val.String() } } - if fieldName == "" || fileName == "" || content == nil { + if fileName == "" || reader == nil { return fmt.Errorf("invalid multipart/form-data file") } @@ -242,7 +247,7 @@ func encodeMultipartFormDataFile(w *multipart.Writer, fieldType reflect.Type, va if err != nil { return err } - if _, err := fw.Write(content); err != nil { + if _, err := io.Copy(fw, reader); err != nil { return err } diff --git a/internal/utils/retries.go b/internal/utils/retries.go index 73970f6..ff8821a 100644 --- a/internal/utils/retries.go +++ b/internal/utils/retries.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package utils @@ -6,8 +6,9 @@ import ( "context" "errors" "fmt" - "github.com/cenkalti/backoff/v4" "github.com/log10-io/log10go/retry" + "math" + "math/rand" "net/http" "net/url" "strconv" @@ -15,8 +16,6 @@ import ( "time" ) -var errRequestFailed = errors.New("request failed") - // Deprecated: Use retry.BackoffStrategy instead. type BackoffStrategy = retry.BackoffStrategy @@ -28,34 +27,27 @@ type Retries struct { StatusCodes []string } -func Retry(ctx context.Context, r Retries, action func() (*http.Response, error)) (*http.Response, error) { +func Retry(ctx context.Context, r Retries, operation func() (*http.Response, error)) (*http.Response, error) { switch r.Config.Strategy { case "backoff": if r.Config.Backoff == nil { - return action() + return operation() } - config := backoff.NewExponentialBackOff() - config.InitialInterval = time.Duration(r.Config.Backoff.InitialInterval) * time.Millisecond - config.MaxInterval = time.Duration(r.Config.Backoff.MaxInterval) * time.Millisecond - config.Multiplier = r.Config.Backoff.Exponent - config.MaxElapsedTime = time.Duration(r.Config.Backoff.MaxElapsedTime) * time.Millisecond - config.Reset() - var resp *http.Response - err := backoff.Retry(func() error { + err := retryWithBackoff(ctx, r.Config.Backoff, func() error { if resp != nil { resp.Body.Close() } select { case <-ctx.Done(): - return backoff.Permanent(ctx.Err()) + return retry.Permanent(ctx.Err()) default: } - res, err := action() + res, err := operation() if err != nil { urlError := new(url.Error) if errors.As(err, &urlError) { @@ -64,7 +56,7 @@ func Retry(ctx context.Context, r Retries, action func() (*http.Response, error) } } - return backoff.Permanent(err) + return retry.Permanent(err) } resp = res if res == nil { @@ -81,7 +73,7 @@ func Retry(ctx context.Context, r Retries, action func() (*http.Response, error) s := res.StatusCode / 100 if s >= codeRange && s < codeRange+1 { - return errRequestFailed + return retry.TemporaryFromResponse("request failed", res) } } else { parsedCode, err := strconv.Atoi(code) @@ -90,7 +82,7 @@ func Retry(ctx context.Context, r Retries, action func() (*http.Response, error) } if res.StatusCode == parsedCode { - return errRequestFailed + return retry.TemporaryFromResponse("request failed", res) } } } @@ -98,13 +90,131 @@ func Retry(ctx context.Context, r Retries, action func() (*http.Response, error) resp = res return nil - }, config) - if err != nil && !errors.Is(err, errRequestFailed) { + }) + + var tempErr *retry.TemporaryError + if err != nil && !errors.As(err, &tempErr) { return nil, err } return resp, nil default: - return action() + return operation() + } +} + +func retryWithBackoff(ctx context.Context, s *retry.BackoffStrategy, operation func() error) error { + var ( + err error + next time.Duration + attempt int + start = time.Now() + maxElapsedTime = time.Duration(s.MaxElapsedTime) * time.Millisecond + ) + + timer := &defaultTimer{} + defer func() { + timer.Stop() + }() + + for { + err = operation() + if err == nil { + return nil + } + + var permanent *retry.PermanentError + if errors.As(err, &permanent) { + return permanent.Unwrap() + } + + if time.Since(start) >= maxElapsedTime { + return err + } + + var temporary *retry.TemporaryError + if errors.As(err, &temporary) { + next = temporary.RetryAfter() + } + + if next <= 0 { + next = nextInterval(s, attempt) + } + + timer.Start(next) + + select { + case <-ctx.Done(): + return ctx.Err() + case <-timer.C(): + } + + attempt += 1 } } + +type Timer interface { + Start(duration time.Duration) + Stop() + C() <-chan time.Time +} + +// defaultTimer implements Timer interface using time.Timer +type defaultTimer struct { + timer *time.Timer +} + +// C returns the timers channel which receives the current time when the timer fires. +func (t *defaultTimer) C() <-chan time.Time { + return t.timer.C +} + +// Start starts the timer to fire after the given duration +func (t *defaultTimer) Start(duration time.Duration) { + if t.timer == nil { + t.timer = time.NewTimer(duration) + return + } + + if !t.timer.Stop() { + select { + case <-t.timer.C: + default: + } + } + + t.timer.Reset(duration) +} + +// Stop is called when the timer is not used anymore and resources may be freed. +func (t *defaultTimer) Stop() { + if t.timer != nil { + t.timer.Stop() + } +} + +func nextInterval(s *retry.BackoffStrategy, attempt int) time.Duration { + initialInterval := float64(time.Duration(s.InitialInterval) * time.Millisecond) + maxInterval := float64(time.Duration(s.MaxInterval) * time.Millisecond) + exponent := s.Exponent + jitterFactor := float64(0.25) + + interval := initialInterval * math.Pow(float64(attempt+1), exponent) + + jitter := rand.Float64() * jitterFactor * interval + if rand.Float64() < 0.5 { + jitter = -1 * jitter + } + + interval = interval + jitter + + if interval <= 0 { + interval = initialInterval + } + + if interval > maxInterval { + interval = maxInterval + } + + return time.Duration(interval) +} diff --git a/internal/utils/security.go b/internal/utils/security.go index f7abb69..19dfa6f 100644 --- a/internal/utils/security.go +++ b/internal/utils/security.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package utils @@ -21,6 +21,7 @@ type securityTag struct { Name string Type string SubType string + Env string } func PopulateSecurity(ctx context.Context, req *http.Request, securitySource func(context.Context) (interface{}, error)) error { @@ -118,9 +119,14 @@ func parseSecurityScheme(headers, queryParams map[string]string, schemeTag *secu } if schemeType.Kind() == reflect.Struct { - if schemeTag.Type == "http" && schemeTag.SubType == "basic" { - handleBasicAuthScheme(headers, schemeVal.Interface()) - return + if schemeTag.Type == "http" { + switch schemeTag.SubType { + case "basic": + handleBasicAuthScheme(headers, schemeVal.Interface()) + return + case "custom": + return + } } for i := 0; i < schemeType.NumField(); i++ { @@ -170,6 +176,7 @@ func parseSecuritySchemeValue(headers, queryParams map[string]string, schemeTag switch schemeTag.SubType { case "bearer": headers[secTag.Name] = prefixBearer(valToString(val)) + case "custom": default: panic("not supported") } @@ -227,6 +234,7 @@ func parseSecurityTag(field reflect.StructField) *securityTag { name := "" securityType := "" securitySubType := "" + env := "" options := strings.Split(tag, ",") for _, optionConf := range options { @@ -246,6 +254,8 @@ func parseSecurityTag(field reflect.StructField) *securityTag { option = true case "scheme": scheme = true + case "env": + env = parts[1] } } @@ -257,6 +267,7 @@ func parseSecurityTag(field reflect.StructField) *securityTag { Name: name, Type: securityType, SubType: securitySubType, + Env: env, } } diff --git a/internal/utils/utils.go b/internal/utils/utils.go index eab3682..031a71a 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -1,12 +1,14 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package utils import ( + "bytes" "context" "fmt" "io" "math/big" + "net/http" "reflect" "regexp" "strconv" @@ -125,6 +127,7 @@ func parseStructTag(tagKey string, field reflect.StructField) map[string]string func parseParamTag(tagKey string, field reflect.StructField, defaultStyle string, defaultExplode bool) *paramTag { // example `{tagKey}:"style=simple,explode=false,name=apiID"` + // example `{tagKey}:"inline"` values := parseStructTag(tagKey, field) if values == nil { return nil @@ -138,6 +141,8 @@ func parseParamTag(tagKey string, field reflect.StructField, defaultStyle string for k, v := range values { switch k { + case "inline": + tag.Inline = v == "true" case "style": tag.Style = v case "explode": @@ -228,3 +233,15 @@ func contains(arr []string, str string) bool { } return false } + +func ConsumeRawBody(res *http.Response) ([]byte, error) { + rawBody, err := io.ReadAll(res.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + + res.Body.Close() + res.Body = io.NopCloser(bytes.NewBuffer(rawBody)) + + return rawBody, nil +} diff --git a/log10.go b/log10.go index bb19771..c6e5a4c 100644 --- a/log10.go +++ b/log10.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package log10go @@ -42,6 +42,9 @@ func Float32(f float32) *float32 { return &f } // Float64 provides a helper function to return a pointer to a float64 func Float64(f float64) *float64 { return &f } +// Pointer provides a helper function to return a pointer to a type +func Pointer[T any](v T) *T { return &v } + type sdkConfiguration struct { Client HTTPClient Security func(context.Context) (interface{}, error) @@ -121,7 +124,7 @@ func WithClient(client HTTPClient) SDKOption { // WithSecurity configures the SDK to use the provided security details func WithSecurity(log10Token string) SDKOption { return func(sdk *Log10) { - security := components.Security{Log10Token: &log10Token} + security := components.Security{Log10Token: log10Token} sdk.sdkConfiguration.Security = utils.AsSecuritySource(&security) } } @@ -161,9 +164,9 @@ func New(opts ...SDKOption) *Log10 { sdkConfiguration: sdkConfiguration{ Language: "go", OpenAPIDocVersion: "1.0.0", - SDKVersion: "0.1.0", - GenVersion: "2.373.2", - UserAgent: "speakeasy-sdk/go 0.1.0 2.373.2 1.0.0 github.com/log10-io/log10go", + SDKVersion: "0.2.0", + GenVersion: "2.493.13", + UserAgent: "speakeasy-sdk/go 0.2.0 2.493.13 1.0.0 github.com/log10-io/log10go", Globals: globals.Globals{}, Hooks: hooks.New(), }, diff --git a/models/components/chatcompletionfunctioncalloption.go b/models/components/chatcompletionfunctioncalloption.go index 204c95d..25817f1 100644 --- a/models/components/chatcompletionfunctioncalloption.go +++ b/models/components/chatcompletionfunctioncalloption.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components diff --git a/models/components/chatcompletionfunctions.go b/models/components/chatcompletionfunctions.go index 3dffdb5..6745f6e 100644 --- a/models/components/chatcompletionfunctions.go +++ b/models/components/chatcompletionfunctions.go @@ -1,10 +1,10 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components // ChatCompletionFunctions // -// Deprecated type: This will be removed in a future release, please migrate away from it as soon as possible. +// Deprecated: This will be removed in a future release, please migrate away from it as soon as possible. type ChatCompletionFunctions struct { // A description of what the function does, used by the model to choose when and how to call the function. Description *string `json:"description,omitempty"` diff --git a/models/components/chatcompletionmessagetoolcall.go b/models/components/chatcompletionmessagetoolcall.go index 91ba092..05fb945 100644 --- a/models/components/chatcompletionmessagetoolcall.go +++ b/models/components/chatcompletionmessagetoolcall.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components diff --git a/models/components/chatcompletionnamedtoolchoice.go b/models/components/chatcompletionnamedtoolchoice.go index df7831b..3980a34 100644 --- a/models/components/chatcompletionnamedtoolchoice.go +++ b/models/components/chatcompletionnamedtoolchoice.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components diff --git a/models/components/chatcompletionrequestassistantmessage.go b/models/components/chatcompletionrequestassistantmessage.go index edac52d..cc1a81c 100644 --- a/models/components/chatcompletionrequestassistantmessage.go +++ b/models/components/chatcompletionrequestassistantmessage.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components @@ -33,7 +33,7 @@ func (e *ChatCompletionRequestAssistantMessageRole) UnmarshalJSON(data []byte) e // FunctionCall - Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model. // -// Deprecated type: This will be removed in a future release, please migrate away from it as soon as possible. +// Deprecated: This will be removed in a future release, please migrate away from it as soon as possible. type FunctionCall struct { // The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function. Arguments string `json:"arguments"` @@ -67,7 +67,7 @@ type ChatCompletionRequestAssistantMessage struct { ToolCalls []ChatCompletionMessageToolCall `json:"tool_calls,omitempty"` // Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model. // - // Deprecated field: This will be removed in a future release, please migrate away from it as soon as possible. + // Deprecated: This will be removed in a future release, please migrate away from it as soon as possible. FunctionCall *FunctionCall `json:"function_call,omitempty"` } diff --git a/models/components/chatcompletionrequestfunctionmessage.go b/models/components/chatcompletionrequestfunctionmessage.go index 34ba629..03977df 100644 --- a/models/components/chatcompletionrequestfunctionmessage.go +++ b/models/components/chatcompletionrequestfunctionmessage.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components @@ -33,7 +33,7 @@ func (e *ChatCompletionRequestFunctionMessageRole) UnmarshalJSON(data []byte) er // ChatCompletionRequestFunctionMessage // -// Deprecated type: This will be removed in a future release, please migrate away from it as soon as possible. +// Deprecated: This will be removed in a future release, please migrate away from it as soon as possible. type ChatCompletionRequestFunctionMessage struct { // The role of the messages author, in this case `function`. Role ChatCompletionRequestFunctionMessageRole `json:"role"` diff --git a/models/components/chatcompletionrequestmessage.go b/models/components/chatcompletionrequestmessage.go index 7315c6c..b05ed2f 100644 --- a/models/components/chatcompletionrequestmessage.go +++ b/models/components/chatcompletionrequestmessage.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components @@ -19,11 +19,11 @@ const ( ) type ChatCompletionRequestMessage struct { - ChatCompletionRequestSystemMessage *ChatCompletionRequestSystemMessage - ChatCompletionRequestUserMessage *ChatCompletionRequestUserMessage - ChatCompletionRequestAssistantMessage *ChatCompletionRequestAssistantMessage - ChatCompletionRequestToolMessage *ChatCompletionRequestToolMessage - ChatCompletionRequestFunctionMessage *ChatCompletionRequestFunctionMessage + ChatCompletionRequestSystemMessage *ChatCompletionRequestSystemMessage `queryParam:"inline"` + ChatCompletionRequestUserMessage *ChatCompletionRequestUserMessage `queryParam:"inline"` + ChatCompletionRequestAssistantMessage *ChatCompletionRequestAssistantMessage `queryParam:"inline"` + ChatCompletionRequestToolMessage *ChatCompletionRequestToolMessage `queryParam:"inline"` + ChatCompletionRequestFunctionMessage *ChatCompletionRequestFunctionMessage `queryParam:"inline"` Type ChatCompletionRequestMessageType } diff --git a/models/components/chatcompletionrequestmessagecontentpart.go b/models/components/chatcompletionrequestmessagecontentpart.go index 1743ae7..5617b77 100644 --- a/models/components/chatcompletionrequestmessagecontentpart.go +++ b/models/components/chatcompletionrequestmessagecontentpart.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components @@ -16,8 +16,8 @@ const ( ) type ChatCompletionRequestMessageContentPart struct { - ChatCompletionRequestMessageContentPartText *ChatCompletionRequestMessageContentPartText - ChatCompletionRequestMessageContentPartImage *ChatCompletionRequestMessageContentPartImage + ChatCompletionRequestMessageContentPartText *ChatCompletionRequestMessageContentPartText `queryParam:"inline"` + ChatCompletionRequestMessageContentPartImage *ChatCompletionRequestMessageContentPartImage `queryParam:"inline"` Type ChatCompletionRequestMessageContentPartType } diff --git a/models/components/chatcompletionrequestmessagecontentpartimage.go b/models/components/chatcompletionrequestmessagecontentpartimage.go index 67faaf2..e2a2531 100644 --- a/models/components/chatcompletionrequestmessagecontentpartimage.go +++ b/models/components/chatcompletionrequestmessagecontentpartimage.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components diff --git a/models/components/chatcompletionrequestmessagecontentparttext.go b/models/components/chatcompletionrequestmessagecontentparttext.go index b4e631b..60537c8 100644 --- a/models/components/chatcompletionrequestmessagecontentparttext.go +++ b/models/components/chatcompletionrequestmessagecontentparttext.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components diff --git a/models/components/chatcompletionrequestsystemmessage.go b/models/components/chatcompletionrequestsystemmessage.go index 8a56569..b9fc683 100644 --- a/models/components/chatcompletionrequestsystemmessage.go +++ b/models/components/chatcompletionrequestsystemmessage.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components diff --git a/models/components/chatcompletionrequesttoolmessage.go b/models/components/chatcompletionrequesttoolmessage.go index a68b303..3305c50 100644 --- a/models/components/chatcompletionrequesttoolmessage.go +++ b/models/components/chatcompletionrequesttoolmessage.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components diff --git a/models/components/chatcompletionrequestusermessage.go b/models/components/chatcompletionrequestusermessage.go index a5eb19c..e2f1775 100644 --- a/models/components/chatcompletionrequestusermessage.go +++ b/models/components/chatcompletionrequestusermessage.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components @@ -18,8 +18,8 @@ const ( // Content - The contents of the user message. type Content struct { - Str *string - ArrayOfChatCompletionRequestMessageContentPart []ChatCompletionRequestMessageContentPart + Str *string `queryParam:"inline"` + ArrayOfChatCompletionRequestMessageContentPart []ChatCompletionRequestMessageContentPart `queryParam:"inline"` Type ContentType } diff --git a/models/components/chatcompletionresponsemessage.go b/models/components/chatcompletionresponsemessage.go index 97a74b0..8ced614 100644 --- a/models/components/chatcompletionresponsemessage.go +++ b/models/components/chatcompletionresponsemessage.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components @@ -33,7 +33,7 @@ func (e *ChatCompletionResponseMessageRole) UnmarshalJSON(data []byte) error { // ChatCompletionResponseMessageFunctionCall - Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model. // -// Deprecated type: This will be removed in a future release, please migrate away from it as soon as possible. +// Deprecated: This will be removed in a future release, please migrate away from it as soon as possible. type ChatCompletionResponseMessageFunctionCall struct { // The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function. Arguments string `json:"arguments"` @@ -65,7 +65,7 @@ type ChatCompletionResponseMessage struct { Role ChatCompletionResponseMessageRole `json:"role"` // Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model. // - // Deprecated field: This will be removed in a future release, please migrate away from it as soon as possible. + // Deprecated: This will be removed in a future release, please migrate away from it as soon as possible. FunctionCall *ChatCompletionResponseMessageFunctionCall `json:"function_call,omitempty"` } diff --git a/models/components/chatcompletionstreamoptions.go b/models/components/chatcompletionstreamoptions.go index 4dfdecd..029d926 100644 --- a/models/components/chatcompletionstreamoptions.go +++ b/models/components/chatcompletionstreamoptions.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components diff --git a/models/components/chatcompletiontokenlogprob.go b/models/components/chatcompletiontokenlogprob.go index c6b244c..edf3fb8 100644 --- a/models/components/chatcompletiontokenlogprob.go +++ b/models/components/chatcompletiontokenlogprob.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components diff --git a/models/components/chatcompletiontool.go b/models/components/chatcompletiontool.go index 73ed115..375a834 100644 --- a/models/components/chatcompletiontool.go +++ b/models/components/chatcompletiontool.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components diff --git a/models/components/chatcompletiontoolchoiceoption.go b/models/components/chatcompletiontoolchoiceoption.go index dca2eee..98487a2 100644 --- a/models/components/chatcompletiontoolchoiceoption.go +++ b/models/components/chatcompletiontoolchoiceoption.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components @@ -54,8 +54,8 @@ const ( // // `none` is the default when no tools are present. `auto` is the default if tools are present. type ChatCompletionToolChoiceOption struct { - ChatCompletionToolChoiceOption1 *ChatCompletionToolChoiceOption1 - ChatCompletionNamedToolChoice *ChatCompletionNamedToolChoice + ChatCompletionToolChoiceOption1 *ChatCompletionToolChoiceOption1 `queryParam:"inline"` + ChatCompletionNamedToolChoice *ChatCompletionNamedToolChoice `queryParam:"inline"` Type ChatCompletionToolChoiceOptionType } diff --git a/models/components/completion.go b/models/components/completion.go index 24c27f4..97a7990 100644 --- a/models/components/completion.go +++ b/models/components/completion.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components diff --git a/models/components/completionusage.go b/models/components/completionusage.go index 26c1454..40e3a5b 100644 --- a/models/components/completionusage.go +++ b/models/components/completionusage.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components diff --git a/models/components/createchatcompletionrequest.go b/models/components/createchatcompletionrequest.go index 200e6ad..51686fb 100644 --- a/models/components/createchatcompletionrequest.go +++ b/models/components/createchatcompletionrequest.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components @@ -95,8 +95,8 @@ const ( // Model - ID of the model to use. See the [model endpoint compatibility](/docs/models/model-endpoint-compatibility) table for details on which models work with the Chat API. type Model struct { - Str *string - Two *Two + Str *string `queryParam:"inline"` + Two *Two `queryParam:"inline"` Type ModelType } @@ -214,8 +214,8 @@ const ( // Stop - Up to 4 sequences where the API will stop generating further tokens. type Stop struct { - Str *string - ArrayOfStr []string + Str *string `queryParam:"inline"` + ArrayOfStr []string `queryParam:"inline"` Type StopType } @@ -312,10 +312,10 @@ const ( // // `none` is the default when no functions are present. `auto` is the default if functions are present. // -// Deprecated type: This will be removed in a future release, please migrate away from it as soon as possible. +// Deprecated: This will be removed in a future release, please migrate away from it as soon as possible. type CreateChatCompletionRequestFunctionCall struct { - One *One - ChatCompletionFunctionCallOption *ChatCompletionFunctionCallOption + One *One `queryParam:"inline"` + ChatCompletionFunctionCallOption *ChatCompletionFunctionCallOption `queryParam:"inline"` Type CreateChatCompletionRequestFunctionCallType } @@ -456,14 +456,14 @@ type CreateChatCompletionRequest struct { // `none` is the default when no functions are present. `auto` is the default if functions are present. // // - // Deprecated field: This will be removed in a future release, please migrate away from it as soon as possible. + // Deprecated: This will be removed in a future release, please migrate away from it as soon as possible. FunctionCall *CreateChatCompletionRequestFunctionCall `json:"function_call,omitempty"` // Deprecated in favor of `tools`. // // A list of functions the model may generate JSON inputs for. // // - // Deprecated field: This will be removed in a future release, please migrate away from it as soon as possible. + // Deprecated: This will be removed in a future release, please migrate away from it as soon as possible. Functions []ChatCompletionFunctions `json:"functions,omitempty"` } diff --git a/models/components/createchatcompletionresponse.go b/models/components/createchatcompletionresponse.go index 8bf390b..6d43b7e 100644 --- a/models/components/createchatcompletionresponse.go +++ b/models/components/createchatcompletionresponse.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components diff --git a/models/components/feedback.go b/models/components/feedback.go index 79d0b7b..70a357b 100644 --- a/models/components/feedback.go +++ b/models/components/feedback.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components diff --git a/models/components/functionobject.go b/models/components/functionobject.go index bd04760..1f93aad 100644 --- a/models/components/functionobject.go +++ b/models/components/functionobject.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components diff --git a/models/components/httpmetadata.go b/models/components/httpmetadata.go index f6ec394..e18bdc0 100644 --- a/models/components/httpmetadata.go +++ b/models/components/httpmetadata.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components diff --git a/models/components/security.go b/models/components/security.go index 7522807..085069c 100644 --- a/models/components/security.go +++ b/models/components/security.go @@ -1,14 +1,14 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components type Security struct { - Log10Token *string `security:"scheme,type=apiKey,subtype=header,name=X-Log10-Token"` + Log10Token string `security:"scheme,type=apiKey,subtype=header,name=X-Log10-Token"` } -func (o *Security) GetLog10Token() *string { +func (o *Security) GetLog10Token() string { if o == nil { - return nil + return "" } return o.Log10Token } diff --git a/models/components/session.go b/models/components/session.go index 654ff42..63bd74e 100644 --- a/models/components/session.go +++ b/models/components/session.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components diff --git a/models/components/task.go b/models/components/task.go index b47532e..eec7eb6 100644 --- a/models/components/task.go +++ b/models/components/task.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package components diff --git a/models/operations/create.go b/models/operations/create.go index 1ab0ea3..0cdcca9 100644 --- a/models/operations/create.go +++ b/models/operations/create.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package operations diff --git a/models/operations/createfeedbacktask.go b/models/operations/createfeedbacktask.go index b282d8c..d2c972e 100644 --- a/models/operations/createfeedbacktask.go +++ b/models/operations/createfeedbacktask.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package operations diff --git a/models/operations/createsession.go b/models/operations/createsession.go index 2099aad..ef5e66d 100644 --- a/models/operations/createsession.go +++ b/models/operations/createsession.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package operations diff --git a/models/operations/get.go b/models/operations/get.go index d960282..f321ea2 100644 --- a/models/operations/get.go +++ b/models/operations/get.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package operations diff --git a/models/operations/getfeedbacktask.go b/models/operations/getfeedbacktask.go index 74a38b1..8cfba68 100644 --- a/models/operations/getfeedbacktask.go +++ b/models/operations/getfeedbacktask.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package operations diff --git a/models/operations/list.go b/models/operations/list.go index 6b06b10..e868c6d 100644 --- a/models/operations/list.go +++ b/models/operations/list.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package operations diff --git a/models/operations/listfeedbacktasks.go b/models/operations/listfeedbacktasks.go index c9d8387..5497933 100644 --- a/models/operations/listfeedbacktasks.go +++ b/models/operations/listfeedbacktasks.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package operations diff --git a/models/operations/listungraded.go b/models/operations/listungraded.go index 3e37748..77c3f53 100644 --- a/models/operations/listungraded.go +++ b/models/operations/listungraded.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package operations diff --git a/models/operations/options.go b/models/operations/options.go index 5c6d569..c64615e 100644 --- a/models/operations/options.go +++ b/models/operations/options.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package operations @@ -12,16 +12,18 @@ import ( var ErrUnsupportedOption = errors.New("unsupported option") const ( - SupportedOptionServerURL = "serverURL" SupportedOptionRetries = "retries" SupportedOptionTimeout = "timeout" SupportedOptionAcceptHeaderOverride = "acceptHeaderOverride" + SupportedOptionURLOverride = "urlOverride" ) type Options struct { - ServerURL *string - Retries *retry.Config - Timeout *time.Duration + ServerURL *string + Retries *retry.Config + Timeout *time.Duration + URLOverride *string + SetHeaders map[string]string } type Option func(*Options, ...string) error @@ -29,10 +31,6 @@ type Option func(*Options, ...string) error // WithServerURL allows providing an alternative server URL. func WithServerURL(serverURL string) Option { return func(opts *Options, supportedOptions ...string) error { - if !utils.Contains(supportedOptions, SupportedOptionServerURL) { - return ErrUnsupportedOption - } - opts.ServerURL = &serverURL return nil } @@ -41,10 +39,6 @@ func WithServerURL(serverURL string) Option { // WithTemplatedServerURL allows providing an alternative server URL with templated parameters. func WithTemplatedServerURL(serverURL string, params map[string]string) Option { return func(opts *Options, supportedOptions ...string) error { - if !utils.Contains(supportedOptions, SupportedOptionServerURL) { - return ErrUnsupportedOption - } - if params != nil { serverURL = utils.ReplaceParameters(serverURL, params) } @@ -77,3 +71,24 @@ func WithOperationTimeout(timeout time.Duration) Option { return nil } } + +// WithURLOverride allows overriding the URL. +func WithURLOverride(urlOverride string) Option { + return func(opts *Options, supportedOptions ...string) error { + if !utils.Contains(supportedOptions, SupportedOptionURLOverride) { + return ErrUnsupportedOption + } + + opts.URLOverride = &urlOverride + return nil + } +} + +// WithSetHeaders takes a map of headers that will applied to a request. If the +// request contains headers that are in the map then they will be overwritten. +func WithSetHeaders(hdrs map[string]string) Option { + return func(opts *Options, supportedOptions ...string) error { + opts.SetHeaders = hdrs + return nil + } +} diff --git a/models/operations/update.go b/models/operations/update.go index 5fe5570..ec6c2b5 100644 --- a/models/operations/update.go +++ b/models/operations/update.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package operations diff --git a/models/operations/upload.go b/models/operations/upload.go index d3966fc..57434c6 100644 --- a/models/operations/upload.go +++ b/models/operations/upload.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package operations @@ -213,8 +213,8 @@ const ( ) type UploadRequestBody struct { - One *One - Two *Two + One *One `queryParam:"inline"` + Two *Two `queryParam:"inline"` Type UploadRequestBodyType } diff --git a/models/sdkerrors/sdkerror.go b/models/sdkerrors/sdkerror.go index 5c1affd..7d63b98 100644 --- a/models/sdkerrors/sdkerror.go +++ b/models/sdkerrors/sdkerror.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package sdkerrors diff --git a/retry/config.go b/retry/config.go index dbbd57e..aa809fc 100644 --- a/retry/config.go +++ b/retry/config.go @@ -1,7 +1,16 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package retry +import ( + "errors" + "net/http" + "strconv" + "time" +) + +// BackoffStrategy defines the parameters for exponential backoff. This can be +// used to drive a retry loop for example. type BackoffStrategy struct { InitialInterval int MaxInterval int @@ -9,8 +18,131 @@ type BackoffStrategy struct { MaxElapsedTime int } +// Config configures a retry policy. type Config struct { + // Strategy sets the algorithm to use for a retry loop. It can be one of: + // - "backoff": retry with exponential backoff and random jitter. + // - "none" or "": disables retries. Strategy string Backoff *BackoffStrategy RetryConnectionErrors bool } + +// PermanentError is an error that signals that some operation has terminally +// failed and should not be retried. +type PermanentError struct { + cause error +} + +// Permanent creates a PermanentError that signals to a retry loop that it +// should stop retrying an operation and return the underlying error. +func Permanent(cause error) error { + if IsPermanentError(cause) { + return cause + } + + return &PermanentError{ + cause: cause, + } +} + +func (e *PermanentError) Error() string { + return e.cause.Error() +} + +func (e *PermanentError) Unwrap() error { + return e.cause +} + +// TemporaryError represents a retryable error and signals to a retry loop that +// an operation may be retried with an optional wait interval. +type TemporaryError struct { + wait time.Duration + message string +} + +// Temporary creates a TemporaryError that signals to a retry loop that an +// operation can be retried. The error may also carry details about how long to +// wait before retrying. This wait interval may be used to override the retry +// policy in use. +func Temporary(message string) error { + return &TemporaryError{ + message: message, + } +} + +// TemporaryFromResponse creates a TemporaryError similar to Temporary but +// additionally parses the Retry-After header from a response to determine the +// wait interval before the next retry attempt. +func TemporaryFromResponse(message string, res *http.Response) error { + return &TemporaryError{ + wait: retryIntervalFromResponse(res), + message: message, + } +} + +func (e *TemporaryError) Error() string { + return e.message +} + +// RetryAfter returns the time to wait before retrying the request. The zero +// value should be interpreted by retry loops to mean they should fallback on +// their default policy whether expenonential, constant backoff or something +// else. It does not mean that an operation should be retried immediately. +func (e *TemporaryError) RetryAfter() time.Duration { + return e.wait +} + +func retryIntervalFromResponse(res *http.Response) time.Duration { + if res == nil { + return 0 + } + + retryVal := res.Header.Get("retry-after") + if retryVal == "" { + return 0 + } + + parsedNumber, err := strconv.ParseInt(retryVal, 10, 64) + if err == nil { + if parsedNumber < 0 { + return 0 + } else { + return time.Duration(parsedNumber) * time.Second + } + } + + parsedDate, err := time.Parse(time.RFC1123, retryVal) + if err == nil { + delta := parsedDate.Sub(time.Now()) + if delta < 0 { + return 0 + } else { + return delta + } + } + + return 0 +} + +// IsPermanentError returns true if an error value is or contains a +// PermanentError in its chain of errors. +func IsPermanentError(err error) bool { + if err == nil { + return false + } + + var pe *PermanentError + return errors.As(err, &pe) +} + +// IsTemporaryError returns true if an error value is or contains a +// TemporaryError in its chain of errors. +func IsTemporaryError(err error) bool { + if err == nil { + return false + } + + var pe *TemporaryError + return errors.As(err, &pe) +} diff --git a/sessions.go b/sessions.go index 00c617a..20d6083 100644 --- a/sessions.go +++ b/sessions.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package log10go @@ -6,14 +6,14 @@ import ( "bytes" "context" "fmt" - "github.com/cenkalti/backoff/v4" "github.com/log10-io/log10go/internal/hooks" "github.com/log10-io/log10go/internal/utils" "github.com/log10-io/log10go/models/components" "github.com/log10-io/log10go/models/operations" "github.com/log10-io/log10go/models/sdkerrors" - "io" + "github.com/log10-io/log10go/retry" "net/http" + "net/url" ) // Sessions @@ -55,8 +55,13 @@ func (s *Sessions) Create(ctx context.Context, xLog10Organization *string, opts } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) - opURL, err := utils.GenerateURL(ctx, baseURL, "/api/v1/sessions", request, globals) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } + opURL, err := url.JoinPath(baseURL, "/api/v1/sessions") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } @@ -81,14 +86,14 @@ func (s *Sessions) Create(ctx context.Context, xLog10Organization *string, opts utils.PopulateHeaders(ctx, req, request, globals) - if err := utils.PopulateQueryParams(ctx, req, request, globals); err != nil { - return nil, fmt.Errorf("error populating query params: %w", err) - } - if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { return nil, err } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + globalRetryConfig := s.sdkConfiguration.RetryConfig retryConfig := o.Retries if retryConfig == nil { @@ -119,7 +124,11 @@ func (s *Sessions) Create(ctx context.Context, xLog10Organization *string, opts req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) if err != nil { - return nil, backoff.Permanent(err) + if retry.IsPermanentError(err) || retry.IsTemporaryError(err) { + return nil, err + } + + return nil, retry.Permanent(err) } httpRes, err := s.sdkConfiguration.Client.Do(req) @@ -181,17 +190,15 @@ func (s *Sessions) Create(ctx context.Context, xLog10Organization *string, opts }, } - rawBody, err := io.ReadAll(httpRes.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) - } - httpRes.Body.Close() - httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) - switch { case httpRes.StatusCode == 201: switch { case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + var out operations.CreateSessionResponseBody if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err @@ -199,13 +206,25 @@ func (s *Sessions) Create(ctx context.Context, xLog10Organization *string, opts res.Object = &out default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: fallthrough case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) } diff --git a/types/bigint.go b/types/bigint.go index afd0cd2..9c6a086 100644 --- a/types/bigint.go +++ b/types/bigint.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package types diff --git a/types/date.go b/types/date.go index c4648fa..5b2782f 100644 --- a/types/date.go +++ b/types/date.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package types diff --git a/types/datetime.go b/types/datetime.go index 0529b25..3eff332 100644 --- a/types/datetime.go +++ b/types/datetime.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package types diff --git a/types/decimal.go b/types/decimal.go index a42284b..d8429bc 100644 --- a/types/decimal.go +++ b/types/decimal.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package types diff --git a/types/pointers.go b/types/pointers.go index 4f15e99..35c439d 100644 --- a/types/pointers.go +++ b/types/pointers.go @@ -1,4 +1,4 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. package types @@ -8,3 +8,4 @@ func Int(i int) *int { return &i } func Int64(i int64) *int64 { return &i } func Float32(f float32) *float32 { return &f } func Float64(f float64) *float64 { return &f } +func Pointer[T any](v T) *T { return &v }