Files
sdk/api_exec.go

385 lines
13 KiB
Go

/*
Hanzo Cloud API
The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
API version: v1
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hanzoai
import (
"bytes"
"context"
"io"
"net/http"
"net/url"
"strings"
)
// ExecAPIService ExecAPI service
type ExecAPIService service
type ExecAPIGetExecFilesBySidRequest struct {
ctx context.Context
ApiService *ExecAPIService
sid string
}
func (r ExecAPIGetExecFilesBySidRequest) Execute() ([]ExecListing, *http.Response, error) {
return r.ApiService.GetExecFilesBySidExecute(r)
}
/*
GetExecFilesBySid Lists the files in an execution session.
Lists the files in an execution session.
Everything the session's sandbox holds — the uploads a run can read and the
artifacts it produced — each then fetched from GET /v1/exec/download.
The answer is a BARE JSON ARRAY of {name, lastModified}, where `name` is the
same {session_id}/{fileId} identifier download takes, because that is what the
client matches on. The obvious typed shape, `{files: […]}`, would have been a
silent wire change: the request still succeeds and `response.data.find(...)`
finds nothing, which reads as a session holding no files.
It lists with one recursive `find`, the same traversal the artifact sweep
makes, so a nested artifact a run reports in its reply is listed here too: one
traversal of the directory, one answer about what a session holds.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param sid SID is the session identifier — the sandbox this listing is of. The URL is the addressing authority: a path segment binds after the body and after the query, so the address decides which session is read whatever else is sent.
@return ExecAPIGetExecFilesBySidRequest
*/
func (a *ExecAPIService) GetExecFilesBySid(ctx context.Context, sid string) ExecAPIGetExecFilesBySidRequest {
return ExecAPIGetExecFilesBySidRequest{
ApiService: a,
ctx: ctx,
sid: sid,
}
}
// Execute executes the request
//
// @return []ExecListing
func (a *ExecAPIService) GetExecFilesBySidExecute(r ExecAPIGetExecFilesBySidRequest) ([]ExecListing, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue []ExecListing
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "ExecAPIService.GetExecFilesBySid")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/exec/files/{sid}"
localVarPath = strings.Replace(localVarPath, "{"+"sid"+"}", url.PathEscape(parameterValueToString(r.sid, "sid")), -1)
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
var v ProblemDetails
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ExecAPIPostExecRequest struct {
ctx context.Context
ApiService *ExecAPIService
execCodeRun *ExecCodeRun
}
func (r ExecAPIPostExecRequest) ExecCodeRun(execCodeRun ExecCodeRun) ExecAPIPostExecRequest {
r.execCodeRun = &execCodeRun
return r
}
func (r ExecAPIPostExecRequest) Execute() (*ExecCodeResult, *http.Response, error) {
return r.ApiService.PostExecExecute(r)
}
/*
PostExec Run a code snippet in a sandboxed interpreter
Executes a program in a throwaway sandbox and answers with what it printed
and what it left behind.
`lang` names one of the thirteen the sandbox image carries — py, js, ts, bash, r,
php, go, rs, c, cpp, java, d, f90 — and `code` is the whole program, not a
fragment: a compiled language is compiled and then run, an interpreted one is
interpreted, and `args` becomes the program's own argv either way. Nothing is
installed for you; the image is the environment.
A PROGRAM THAT FAILS IS A SUCCESSFUL CALL. A non-zero exit answers 200 with the
diagnostics on `stderr`, because "the code threw" and "the interpreter is down"
are different facts a caller renders differently. Only the second is an error
status.
Runs are stateful through `session_id`. Omit it and the run gets a fresh sandbox
whose id comes back on the answer; pass that id again and the next run sees the
same filesystem, so a program can write a file one call and read it the next.
`files` names bytes already uploaded to a session (POST /v1/exec/upload), copied in
before the program starts. `files` on the ANSWER is what the program created or
changed, by comparison against a marker taken at start — so it is the run's real
output, not a listing of the directory — and each is fetched from
GET /v1/exec/download/{session}/{name}.
The tenant is the caller's, never the body's, at every entry point. A typed op is
also an MCP tool and an op-plane op; MCP's tools/call invokes it directly, with no
route and therefore no middleware, so nothing there could have checked a
credential. tenantOf refuses a context carrying no validated principal, so those
entry points fail closed without a second gate to keep in step.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return ExecAPIPostExecRequest
*/
func (a *ExecAPIService) PostExec(ctx context.Context) ExecAPIPostExecRequest {
return ExecAPIPostExecRequest{
ApiService: a,
ctx: ctx,
}
}
// Execute executes the request
//
// @return ExecCodeResult
func (a *ExecAPIService) PostExecExecute(r ExecAPIPostExecRequest) (*ExecCodeResult, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodPost
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *ExecCodeResult
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "ExecAPIService.PostExec")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/exec"
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if r.execCodeRun == nil {
return localVarReturnValue, nil, reportError("execCodeRun is required and must be specified")
}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{"application/json"}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
// body params
localVarPostBody = r.execCodeRun
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
var v ProblemDetails
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type ExecAPIPostExecUploadRequest struct {
ctx context.Context
ApiService *ExecAPIService
}
func (r ExecAPIPostExecUploadRequest) Execute() (*http.Response, error) {
return r.ApiService.PostExecUploadExecute(r)
}
/*
PostExecUpload Upload a file into an execution session
Takes a multipart upload and writes the file into the session's sandbox, so a later run can read it. Answers the session id and the identifier the file is addressed by; `session_id` in the form joins an existing session instead of opening one.
The body is multipart/form-data, which is why this is not a typed operation: every non-empty typed body is decoded as JSON.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return ExecAPIPostExecUploadRequest
*/
func (a *ExecAPIService) PostExecUpload(ctx context.Context) ExecAPIPostExecUploadRequest {
return ExecAPIPostExecUploadRequest{
ApiService: a,
ctx: ctx,
}
}
// Execute executes the request
func (a *ExecAPIService) PostExecUploadExecute(r ExecAPIPostExecUploadRequest) (*http.Response, error) {
var (
localVarHTTPMethod = http.MethodPost
localVarPostBody interface{}
formFiles []formFile
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "ExecAPIService.PostExecUpload")
if err != nil {
return nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/exec/upload"
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
return localVarHTTPResponse, newErr
}
return localVarHTTPResponse, nil
}