MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / handlePublish

Function handlePublish

cli/src/commands/publish.ts:95–203  ·  view source on GitHub ↗
(agentIds: string[])

Source from the content-addressed store, hash-verified

93 * @returns PublishResult with success/error information
94 */
95export async function handlePublish(agentIds: string[]): Promise<PublishResult> {
96 const user = getUserCredentials()
97
98 if (!user) {
99 return {
100 success: false,
101 error: 'Not logged in',
102 hint: 'Please log in first using "login" command or web UI.',
103 }
104 }
105
106 const availableAgents = getLoadedAgentsData()?.agents || []
107
108 if (agentIds?.length === 0) {
109 return {
110 success: false,
111 error: 'No agents specified',
112 hint: 'Usage: publish <agent-id> [agent-id2] ...',
113 }
114 }
115
116 try {
117 const loadedDefinitions = loadAgentDefinitions()
118
119 if (loadedDefinitions.length === 0) {
120 return {
121 success: false,
122 error: 'No valid agent templates found in .agents directory.',
123 }
124 }
125
126 const matchingTemplates: Record<string, any> = {}
127
128 for (const agentId of agentIds) {
129 // Find the specific agent
130 const matchingTemplate = loadedDefinitions.find(
131 (template) =>
132 template.id === agentId ||
133 (template as { displayName?: string }).displayName === agentId,
134 )
135
136 if (!matchingTemplate) {
137 const availableList = availableAgents
138 .map((agent) =>
139 agent.displayName && agent.displayName !== agent.id
140 ? `${agent.displayName} (${agent.id})`
141 : agent.displayName || agent.id,
142 )
143 .join(', ')
144 return {
145 success: false,
146 error: `Agent "${agentId}" not found`,
147 details: `Available agents: ${availableList}`,
148 }
149 }
150
151 // Process the template for publishing
152 const processedTemplate = { ...matchingTemplate }

Callers 2

mainFunction · 0.90
usePublishMutationFunction · 0.90

Calls 4

getUserCredentialsFunction · 0.90
getLoadedAgentsDataFunction · 0.90
loadAgentDefinitionsFunction · 0.90
publishAgentTemplatesFunction · 0.85

Tested by

no test coverage detected