diff options
| author | Dax Raad <[email protected]> | 2025-05-28 12:53:22 -0400 |
|---|---|---|
| committer | Dax Raad <[email protected]> | 2025-05-28 12:53:22 -0400 |
| commit | 55a6fcdd3f5b3c55712e5cfc9dd4d994da38d4c8 (patch) | |
| tree | aef660f4e7b0fae135dc1f90cf6920b53238ed5b /pkg | |
| parent | 4132fcc1b286af5e61bf5eaa89f789988362f995 (diff) | |
| download | opencode-55a6fcdd3f5b3c55712e5cfc9dd4d994da38d4c8.tar.gz opencode-55a6fcdd3f5b3c55712e5cfc9dd4d994da38d4c8.zip | |
add provider_list
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/client/gen/openapi.json | 90 | ||||
| -rw-r--r-- | pkg/client/generated-client.go | 125 |
2 files changed, 212 insertions, 3 deletions
diff --git a/pkg/client/gen/openapi.json b/pkg/client/gen/openapi.json index 478eb02ae..b7e40b7f9 100644 --- a/pkg/client/gen/openapi.json +++ b/pkg/client/gen/openapi.json @@ -167,16 +167,46 @@ "sessionID": { "type": "string" }, + "providerID": { + "type": "string" + }, + "modelID": { + "type": "string" + }, "parts": {} }, "required": [ - "sessionID" + "sessionID", + "providerID", + "modelID" ] } } } } } + }, + "/provider_list": { + "post": { + "responses": { + "200": { + "description": "List of providers", + "content": { + "application/json": { + "schema": { + "type": "object", + "additionalProperties": { + "$ref": "#/components/schemas/Provider.Info" + } + } + } + } + } + }, + "operationId": "postProvider_list", + "parameters": [], + "description": "List all providers" + } } }, "components": { @@ -219,6 +249,64 @@ "title", "tokens" ] + }, + "Provider.Info": { + "type": "object", + "properties": { + "options": { + "type": "object", + "additionalProperties": {} + }, + "models": { + "type": "object", + "additionalProperties": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "cost": { + "type": "object", + "properties": { + "input": { + "type": "number" + }, + "inputCached": { + "type": "number" + }, + "output": { + "type": "number" + }, + "outputCached": { + "type": "number" + } + }, + "required": [ + "input", + "inputCached", + "output", + "outputCached" + ] + }, + "contextWindow": { + "type": "number" + }, + "maxTokens": { + "type": "number" + }, + "attachment": { + "type": "boolean" + } + }, + "required": [ + "cost", + "contextWindow", + "maxTokens", + "attachment" + ] + } + } + } } } } diff --git a/pkg/client/generated-client.go b/pkg/client/generated-client.go index 46fb60205..89d6a9273 100644 --- a/pkg/client/generated-client.go +++ b/pkg/client/generated-client.go @@ -14,6 +14,23 @@ import ( "strings" ) +// ProviderInfo defines model for Provider.Info. +type ProviderInfo struct { + Models *map[string]struct { + Attachment bool `json:"attachment"` + ContextWindow float32 `json:"contextWindow"` + Cost struct { + Input float32 `json:"input"` + InputCached float32 `json:"inputCached"` + Output float32 `json:"output"` + OutputCached float32 `json:"outputCached"` + } `json:"cost"` + MaxTokens float32 `json:"maxTokens"` + Name *string `json:"name,omitempty"` + } `json:"models,omitempty"` + Options *map[string]interface{} `json:"options,omitempty"` +} + // SessionInfo defines model for Session.Info. type SessionInfo struct { Id string `json:"id"` @@ -28,8 +45,10 @@ type SessionInfo struct { // PostSessionChatJSONBody defines parameters for PostSessionChat. type PostSessionChatJSONBody struct { - Parts *interface{} `json:"parts,omitempty"` - SessionID string `json:"sessionID"` + ModelID string `json:"modelID"` + Parts *interface{} `json:"parts,omitempty"` + ProviderID string `json:"providerID"` + SessionID string `json:"sessionID"` } // PostSessionMessagesJSONBody defines parameters for PostSessionMessages. @@ -124,6 +143,9 @@ func WithRequestEditorFn(fn RequestEditorFn) ClientOption { // The interface specification for the client above. type ClientInterface interface { + // PostProviderList request + PostProviderList(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) + // PostSessionChatWithBody request with any body PostSessionChatWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -146,6 +168,18 @@ type ClientInterface interface { PostSessionShare(ctx context.Context, body PostSessionShareJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) } +func (c *Client) PostProviderList(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostProviderListRequest(c.Server) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + func (c *Client) PostSessionChatWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewPostSessionChatRequestWithBody(c.Server, contentType, body) if err != nil { @@ -242,6 +276,33 @@ func (c *Client) PostSessionShare(ctx context.Context, body PostSessionShareJSON return c.Client.Do(req) } +// NewPostProviderListRequest generates requests for PostProviderList +func NewPostProviderListRequest(server string) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/provider_list") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + // NewPostSessionChatRequest calls the generic PostSessionChat builder with application/json body func NewPostSessionChatRequest(server string, body PostSessionChatJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader @@ -459,6 +520,9 @@ func WithBaseURL(baseURL string) ClientOption { // ClientWithResponsesInterface is the interface specification for the client with responses above. type ClientWithResponsesInterface interface { + // PostProviderListWithResponse request + PostProviderListWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostProviderListResponse, error) + // PostSessionChatWithBodyWithResponse request with any body PostSessionChatWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostSessionChatResponse, error) @@ -481,6 +545,28 @@ type ClientWithResponsesInterface interface { PostSessionShareWithResponse(ctx context.Context, body PostSessionShareJSONRequestBody, reqEditors ...RequestEditorFn) (*PostSessionShareResponse, error) } +type PostProviderListResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]ProviderInfo +} + +// Status returns HTTPResponse.Status +func (r PostProviderListResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r PostProviderListResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type PostSessionChatResponse struct { Body []byte HTTPResponse *http.Response @@ -599,6 +685,15 @@ func (r PostSessionShareResponse) StatusCode() int { return 0 } +// PostProviderListWithResponse request returning *PostProviderListResponse +func (c *ClientWithResponses) PostProviderListWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostProviderListResponse, error) { + rsp, err := c.PostProviderList(ctx, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostProviderListResponse(rsp) +} + // PostSessionChatWithBodyWithResponse request with arbitrary body returning *PostSessionChatResponse func (c *ClientWithResponses) PostSessionChatWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostSessionChatResponse, error) { rsp, err := c.PostSessionChatWithBody(ctx, contentType, body, reqEditors...) @@ -668,6 +763,32 @@ func (c *ClientWithResponses) PostSessionShareWithResponse(ctx context.Context, return ParsePostSessionShareResponse(rsp) } +// ParsePostProviderListResponse parses an HTTP response from a PostProviderListWithResponse call +func ParsePostProviderListResponse(rsp *http.Response) (*PostProviderListResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &PostProviderListResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]ProviderInfo + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + // ParsePostSessionChatResponse parses an HTTP response from a PostSessionChatWithResponse call func ParsePostSessionChatResponse(rsp *http.Response) (*PostSessionChatResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) |
