MCPcopy Create free account
hub / github.com/compozy/agh / CreateWorkspace

Method CreateWorkspace

internal/api/core/workspaces.go:20–58  ·  view source on GitHub ↗

CreateWorkspace registers a workspace.

(c *gin.Context)

Source from the content-addressed store, hash-verified

18
19// CreateWorkspace registers a workspace.
20func (h *BaseHandlers) CreateWorkspace(c *gin.Context) {
21 var req contract.CreateWorkspaceRequest
22 if err := c.ShouldBindJSON(&req); err != nil {
23 h.respondError(
24 c,
25 http.StatusBadRequest,
26 fmt.Errorf("%s: decode create workspace request: %w", h.transportName(), err),
27 )
28 return
29 }
30
31 rootDir := strings.TrimSpace(req.RootDir)
32 if err := validateAbsolutePathInternal(h.transportName(), "root_dir", rootDir); err != nil {
33 h.respondError(c, http.StatusBadRequest, err)
34 return
35 }
36
37 addDirs := trimStringSliceInternal(req.AddDirs)
38 if err := validateAbsolutePathsInternal(h.transportName(), "add_dirs", addDirs); err != nil {
39 h.respondError(c, http.StatusBadRequest, err)
40 return
41 }
42
43 workspace, err := h.Workspaces.Register(c.Request.Context(), workspacepkg.RegisterOptions{
44 RootDir: rootDir,
45 Name: strings.TrimSpace(req.Name),
46 AdditionalDirs: addDirs,
47 DefaultAgent: strings.TrimSpace(req.DefaultAgent),
48 SandboxRef: strings.TrimSpace(req.SandboxRef),
49 })
50 if err != nil {
51 h.respondError(c, StatusForWorkspaceError(err), err)
52 return
53 }
54
55 c.JSON(http.StatusCreated, contract.WorkspaceResponse{
56 Workspace: WorkspacePayloadFromWorkspace(workspace),
57 })
58}
59
60// ListWorkspaces returns all registered workspaces.
61func (h *BaseHandlers) ListWorkspaces(c *gin.Context) {

Callers

nothing calls this directly

Calls 8

respondErrorMethod · 0.95
transportNameMethod · 0.95
trimStringSliceInternalFunction · 0.85
StatusForWorkspaceErrorFunction · 0.85
RegisterMethod · 0.65

Tested by

no test coverage detected