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

Function publishAgentTemplates

cli/src/commands/publish.ts:28–88  ·  view source on GitHub ↗

* Publish agent templates to the backend

(
  data: Record<string, any>[],
  authToken: string,
  allLocalAgentIds: string[],
)

Source from the content-addressed store, hash-verified

26 * Publish agent templates to the backend
27 */
28async function publishAgentTemplates(
29 data: Record<string, any>[],
30 authToken: string,
31 allLocalAgentIds: string[],
32): Promise<PublishAgentsResponse & { statusCode?: number }> {
33 setApiClientAuthToken(authToken)
34 const apiClient = getApiClient()
35
36 try {
37 const response = await apiClient.publish(data, allLocalAgentIds)
38
39 if (!response.ok) {
40 // Try to use the full error data if available (includes details, hint, etc.)
41 const errorData = response.errorData as
42 | Partial<PublishAgentsErrorResponse>
43 | undefined
44 return {
45 success: false,
46 error: errorData?.error ?? response.error ?? 'Unknown error',
47 details: errorData?.details,
48 hint: errorData?.hint,
49 availablePublishers: errorData?.availablePublishers,
50 validationErrors: errorData?.validationErrors,
51 statusCode: response.status,
52 }
53 }
54
55 // Guard against empty/undefined response data
56 if (!response.data) {
57 return {
58 success: false,
59 error: 'Failed to parse server response - empty response body',
60 statusCode: response.status,
61 }
62 }
63
64 return {
65 ...response.data,
66 statusCode: response.status,
67 }
68 } catch (err: any) {
69 if (err instanceof TypeError && err.message.includes('fetch')) {
70 return {
71 success: false,
72 error: `Network error: Unable to connect to ${WEBSITE_URL}. Please check your internet connection and try again.`,
73 }
74 }
75
76 const body = err?.responseBody || err?.body || err
77 const error = body?.error || body?.message || 'Failed to publish'
78 const details = body?.details
79 const hint = body?.hint
80
81 return {
82 success: false,
83 error,
84 details,
85 hint,

Callers 1

handlePublishFunction · 0.85

Calls 3

setApiClientAuthTokenFunction · 0.90
getApiClientFunction · 0.90
publishMethod · 0.80

Tested by

no test coverage detected