/ components / execd / pkg / web / model / session.go
session.go
 1  // Copyright 2026 Alibaba Group Holding Ltd.
 2  //
 3  // Licensed under the Apache License, Version 2.0 (the "License");
 4  // you may not use this file except in compliance with the License.
 5  // You may obtain a copy of the License at
 6  //
 7  //     http://www.apache.org/licenses/LICENSE-2.0
 8  //
 9  // Unless required by applicable law or agreed to in writing, software
10  // distributed under the License is distributed on an "AS IS" BASIS,
11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  // See the License for the specific language governing permissions and
13  // limitations under the License.
14  
15  package model
16  
17  import (
18  	"github.com/go-playground/validator/v10"
19  
20  	"github.com/alibaba/opensandbox/execd/pkg/runtime"
21  )
22  
23  // CreateSessionRequest is the request body for creating a bash session.
24  type CreateSessionRequest struct {
25  	Cwd string `json:"cwd,omitempty"`
26  }
27  
28  // CreateSessionResponse is the response for create_session.
29  type CreateSessionResponse struct {
30  	SessionID string `json:"session_id"`
31  }
32  
33  // RunInSessionRequest is the request body for running a command in an existing session.
34  type RunInSessionRequest struct {
35  	Command string `json:"command" validate:"required"`
36  	Cwd     string `json:"cwd,omitempty"`
37  	Timeout int64  `json:"timeout,omitempty" validate:"omitempty,gte=0"`
38  }
39  
40  // Validate validates RunInSessionRequest.
41  func (r *RunInSessionRequest) Validate() error {
42  	validate := validator.New()
43  	if err := validate.Struct(r); err != nil {
44  		return err
45  	}
46  	return runtime.ValidateWorkingDir(r.Cwd)
47  }