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

Function createAgentDefinitionPathFor

internal/api/core/agent_create.go:36–83  ·  view source on GitHub ↗
(
	ctx context.Context,
	req contract.CreateAgentRequest,
	homePaths aghconfig.HomePaths,
	workspaces WorkspaceService,
	transportName string,
)

Source from the content-addressed store, hash-verified

34}
35
36func 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}

Callers 2

CreateAgentFromRequestFunction · 0.85

Calls 1

ResolveMethod · 0.65

Tested by

no test coverage detected