From 6f1847542891421e2be44218c7e31fb329582452 Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Tue, 24 Jun 2025 11:07:41 -0500 Subject: feat: delete sessions (#362) Co-authored-by: adamdottv <2363879+adamdottv@users.noreply.github.com> --- packages/tui/pkg/client/gen/openapi.json | 64 ++++++++++ packages/tui/pkg/client/generated-client.go | 185 ++++++++++++++++++++++++++++ 2 files changed, 249 insertions(+) (limited to 'packages/tui/pkg') diff --git a/packages/tui/pkg/client/gen/openapi.json b/packages/tui/pkg/client/gen/openapi.json index 0b434e76c..e804accf3 100644 --- a/packages/tui/pkg/client/gen/openapi.json +++ b/packages/tui/pkg/client/gen/openapi.json @@ -363,6 +363,42 @@ } } }, + "/session_delete": { + "post": { + "responses": { + "200": { + "description": "Successfully deleted session", + "content": { + "application/json": { + "schema": { + "type": "boolean" + } + } + } + } + }, + "operationId": "postSession_delete", + "parameters": [], + "description": "Delete a session and all its data", + "requestBody": { + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "sessionID": { + "type": "string" + } + }, + "required": [ + "sessionID" + ] + } + } + } + } + } + }, "/session_summarize": { "post": { "responses": { @@ -579,6 +615,9 @@ { "$ref": "#/components/schemas/Event.session.updated" }, + { + "$ref": "#/components/schemas/Event.session.deleted" + }, { "$ref": "#/components/schemas/Event.session.error" } @@ -593,6 +632,7 @@ "message.updated": "#/components/schemas/Event.message.updated", "message.part.updated": "#/components/schemas/Event.message.part.updated", "session.updated": "#/components/schemas/Event.session.updated", + "session.deleted": "#/components/schemas/Event.session.deleted", "session.error": "#/components/schemas/Event.session.error" } } @@ -1339,6 +1379,30 @@ "time" ] }, + "Event.session.deleted": { + "type": "object", + "properties": { + "type": { + "type": "string", + "const": "session.deleted" + }, + "properties": { + "type": "object", + "properties": { + "info": { + "$ref": "#/components/schemas/session.info" + } + }, + "required": [ + "info" + ] + } + }, + "required": [ + "type", + "properties" + ] + }, "Event.session.error": { "type": "object", "properties": { diff --git a/packages/tui/pkg/client/generated-client.go b/packages/tui/pkg/client/generated-client.go index 739795e7c..4ef9b77e3 100644 --- a/packages/tui/pkg/client/generated-client.go +++ b/packages/tui/pkg/client/generated-client.go @@ -254,6 +254,14 @@ type EventPermissionUpdated struct { Type string `json:"type"` } +// EventSessionDeleted defines model for Event.session.deleted. +type EventSessionDeleted struct { + Properties struct { + Info SessionInfo `json:"info"` + } `json:"properties"` + Type string `json:"type"` +} + // EventSessionError defines model for Event.session.error. type EventSessionError struct { Properties struct { @@ -518,6 +526,11 @@ type PostSessionChatJSONBody struct { SessionID string `json:"sessionID"` } +// PostSessionDeleteJSONBody defines parameters for PostSessionDelete. +type PostSessionDeleteJSONBody struct { + SessionID string `json:"sessionID"` +} + // PostSessionInitializeJSONBody defines parameters for PostSessionInitialize. type PostSessionInitializeJSONBody struct { ModelID string `json:"modelID"` @@ -556,6 +569,9 @@ type PostSessionAbortJSONRequestBody PostSessionAbortJSONBody // PostSessionChatJSONRequestBody defines body for PostSessionChat for application/json ContentType. type PostSessionChatJSONRequestBody PostSessionChatJSONBody +// PostSessionDeleteJSONRequestBody defines body for PostSessionDelete for application/json ContentType. +type PostSessionDeleteJSONRequestBody PostSessionDeleteJSONBody + // PostSessionInitializeJSONRequestBody defines body for PostSessionInitialize for application/json ContentType. type PostSessionInitializeJSONRequestBody PostSessionInitializeJSONBody @@ -935,6 +951,34 @@ func (t *Event) MergeEventSessionUpdated(v EventSessionUpdated) error { return err } +// AsEventSessionDeleted returns the union data inside the Event as a EventSessionDeleted +func (t Event) AsEventSessionDeleted() (EventSessionDeleted, error) { + var body EventSessionDeleted + err := json.Unmarshal(t.union, &body) + return body, err +} + +// FromEventSessionDeleted overwrites any union data inside the Event as the provided EventSessionDeleted +func (t *Event) FromEventSessionDeleted(v EventSessionDeleted) error { + v.Type = "session.deleted" + b, err := json.Marshal(v) + t.union = b + return err +} + +// MergeEventSessionDeleted performs a merge with any union data inside the Event, using the provided EventSessionDeleted +func (t *Event) MergeEventSessionDeleted(v EventSessionDeleted) error { + v.Type = "session.deleted" + b, err := json.Marshal(v) + if err != nil { + return err + } + + merged, err := runtime.JSONMerge(t.union, b) + t.union = merged + return err +} + // AsEventSessionError returns the union data inside the Event as a EventSessionError func (t Event) AsEventSessionError() (EventSessionError, error) { var body EventSessionError @@ -987,6 +1031,8 @@ func (t Event) ValueByDiscriminator() (interface{}, error) { return t.AsEventMessageUpdated() case "permission.updated": return t.AsEventPermissionUpdated() + case "session.deleted": + return t.AsEventSessionDeleted() case "session.error": return t.AsEventSessionError() case "session.updated": @@ -1626,6 +1672,11 @@ type ClientInterface interface { // PostSessionCreate request PostSessionCreate(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) + // PostSessionDeleteWithBody request with any body + PostSessionDeleteWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + PostSessionDelete(ctx context.Context, body PostSessionDeleteJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // PostSessionInitializeWithBody request with any body PostSessionInitializeWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -1823,6 +1874,30 @@ func (c *Client) PostSessionCreate(ctx context.Context, reqEditors ...RequestEdi return c.Client.Do(req) } +func (c *Client) PostSessionDeleteWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostSessionDeleteRequestWithBody(c.Server, contentType, body) + 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) PostSessionDelete(ctx context.Context, body PostSessionDeleteJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostSessionDeleteRequest(c.Server, body) + 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) PostSessionInitializeWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewPostSessionInitializeRequestWithBody(c.Server, contentType, body) if err != nil { @@ -2291,6 +2366,46 @@ func NewPostSessionCreateRequest(server string) (*http.Request, error) { return req, nil } +// NewPostSessionDeleteRequest calls the generic PostSessionDelete builder with application/json body +func NewPostSessionDeleteRequest(server string, body PostSessionDeleteJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewPostSessionDeleteRequestWithBody(server, "application/json", bodyReader) +} + +// NewPostSessionDeleteRequestWithBody generates requests for PostSessionDelete with any type of body +func NewPostSessionDeleteRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/session_delete") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + // NewPostSessionInitializeRequest calls the generic PostSessionInitialize builder with application/json body func NewPostSessionInitializeRequest(server string, body PostSessionInitializeJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader @@ -2600,6 +2715,11 @@ type ClientWithResponsesInterface interface { // PostSessionCreateWithResponse request PostSessionCreateWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostSessionCreateResponse, error) + // PostSessionDeleteWithBodyWithResponse request with any body + PostSessionDeleteWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostSessionDeleteResponse, error) + + PostSessionDeleteWithResponse(ctx context.Context, body PostSessionDeleteJSONRequestBody, reqEditors ...RequestEditorFn) (*PostSessionDeleteResponse, error) + // PostSessionInitializeWithBodyWithResponse request with any body PostSessionInitializeWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostSessionInitializeResponse, error) @@ -2880,6 +3000,28 @@ func (r PostSessionCreateResponse) StatusCode() int { return 0 } +type PostSessionDeleteResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *bool +} + +// Status returns HTTPResponse.Status +func (r PostSessionDeleteResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r PostSessionDeleteResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type PostSessionInitializeResponse struct { Body []byte HTTPResponse *http.Response @@ -3135,6 +3277,23 @@ func (c *ClientWithResponses) PostSessionCreateWithResponse(ctx context.Context, return ParsePostSessionCreateResponse(rsp) } +// PostSessionDeleteWithBodyWithResponse request with arbitrary body returning *PostSessionDeleteResponse +func (c *ClientWithResponses) PostSessionDeleteWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostSessionDeleteResponse, error) { + rsp, err := c.PostSessionDeleteWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostSessionDeleteResponse(rsp) +} + +func (c *ClientWithResponses) PostSessionDeleteWithResponse(ctx context.Context, body PostSessionDeleteJSONRequestBody, reqEditors ...RequestEditorFn) (*PostSessionDeleteResponse, error) { + rsp, err := c.PostSessionDelete(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostSessionDeleteResponse(rsp) +} + // PostSessionInitializeWithBodyWithResponse request with arbitrary body returning *PostSessionInitializeResponse func (c *ClientWithResponses) PostSessionInitializeWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostSessionInitializeResponse, error) { rsp, err := c.PostSessionInitializeWithBody(ctx, contentType, body, reqEditors...) @@ -3530,6 +3689,32 @@ func ParsePostSessionCreateResponse(rsp *http.Response) (*PostSessionCreateRespo return response, nil } +// ParsePostSessionDeleteResponse parses an HTTP response from a PostSessionDeleteWithResponse call +func ParsePostSessionDeleteResponse(rsp *http.Response) (*PostSessionDeleteResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &PostSessionDeleteResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest bool + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + // ParsePostSessionInitializeResponse parses an HTTP response from a PostSessionInitializeWithResponse call func ParsePostSessionInitializeResponse(rsp *http.Response) (*PostSessionInitializeResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) -- cgit v1.2.3