( ctx context.Context, req contract.CreateAgentRequest, homePaths aghconfig.HomePaths, workspaces WorkspaceService, transportName string, )
| 34 | } |
| 35 | |
| 36 | func createAgentDefinitionPathFor( |
| 37 | ctx context.Context, |
| 38 | req contract.CreateAgentRequest, |
| 39 | homePaths aghconfig.HomePaths, |
| 40 | workspaces WorkspaceService, |
| 41 | transportName string, |
| 42 | ) (string, error) { |
| 43 | name := aghconfig.NormalizeAgentName(req.Agent.Name) |
| 44 | switch req.Scope { |
| 45 | case contract.AgentCreateScopeGlobal: |
| 46 | return filepath.Join(homePaths.AgentsDir, name, aghconfig.AgentDefinitionFileName), nil |
| 47 | case contract.AgentCreateScopeWorkspace: |
| 48 | workspaceRef := strings.TrimSpace(req.Workspace) |
| 49 | if workspaceRef == "" { |
| 50 | return "", errors.Join( |
| 51 | errCreateAgentRequestInvalid, |
| 52 | errors.New("workspace is required for workspace-scoped agents"), |
| 53 | ) |
| 54 | } |
| 55 | if workspaces == nil { |
| 56 | return "", fmt.Errorf("%s: %w", transportName, workspacepkg.ErrWorkspaceResolverUnavailable) |
| 57 | } |
| 58 | resolved, err := workspaces.Resolve(ctx, workspaceRef) |
| 59 | if err != nil { |
| 60 | return "", err |
| 61 | } |
| 62 | rootDir := strings.TrimSpace(resolved.RootDir) |
| 63 | if rootDir == "" { |
| 64 | return "", fmt.Errorf("%s: %w", transportName, workspacepkg.ErrWorkspaceRootMissing) |
| 65 | } |
| 66 | return filepath.Join( |
| 67 | rootDir, |
| 68 | aghconfig.DirName, |
| 69 | aghconfig.AgentsDirName, |
| 70 | name, |
| 71 | aghconfig.AgentDefinitionFileName, |
| 72 | ), nil |
| 73 | default: |
| 74 | return "", errors.Join( |
| 75 | errCreateAgentRequestInvalid, |
| 76 | fmt.Errorf( |
| 77 | "scope must be %q or %q", |
| 78 | contract.AgentCreateScopeWorkspace, |
| 79 | contract.AgentCreateScopeGlobal, |
| 80 | ), |
| 81 | ) |
| 82 | } |
| 83 | } |
no test coverage detected