11import { DynamicAgentTemplate } from '@codebuff/common/types/dynamic-agent-template'
22import * as fs from 'fs'
33import { green , red , yellow , cyan } from 'picocolors'
4- import { Client } from '../client'
54import { websiteUrl } from '../config'
65import { logger } from '../utils/logger'
76import { loadLocalAgents } from '../agents/load-agents'
87import { getAgentsDirectory } from '../agents/agent-utils'
8+ import { getUserCredentials } from '../credentials'
99
1010interface PublishResponse {
1111 success : boolean
@@ -17,18 +17,17 @@ interface PublishResponse {
1717
1818/**
1919 * Handle the publish command to upload agent templates to the backend
20- * @param agentName The name of the agent to publish (required)
21- */
22- export async function handlePublish ( agentName ?: string ) : Promise < void > {
23- const client = Client . getInstance ( )
20+ * @param agentId The id of the agent to publish (required)
21+ */ export async function handlePublish ( agentId ?: string ) : Promise < void > {
22+ const user = getUserCredentials ( )
2423
25- if ( ! client . user ) {
24+ if ( ! user ) {
2625 console . log ( red ( 'Please log in first using "login".' ) )
2726 return
2827 }
2928
30- if ( ! agentName ) {
31- console . log ( red ( 'Agent name is required. Usage: publish <agent-name >' ) )
29+ if ( ! agentId ) {
30+ console . log ( red ( 'Agent id is required. Usage: publish <agent-id >' ) )
3231 console . log (
3332 yellow ( 'This prevents accidentally publishing all agents at once.' )
3433 )
@@ -69,13 +68,13 @@ export async function handlePublish(agentName?: string): Promise<void> {
6968 // Find the specific agent
7069 const matchingTemplate = Object . entries ( agentTemplates ) . find (
7170 ( [ key , template ] ) =>
72- key === agentName ||
73- template . id === agentName ||
74- template . displayName === agentName
71+ key === agentId ||
72+ template . id === agentId ||
73+ template . displayName === agentId
7574 )
7675
7776 if ( ! matchingTemplate ) {
78- console . log ( red ( `Agent "${ agentName } " not found. Available agents:` ) )
77+ console . log ( red ( `Agent "${ agentId } " not found. Available agents:` ) )
7978 Object . values ( agentTemplates ) . forEach ( ( template ) => {
8079 console . log ( ` - ${ template . displayName } (${ template . id } )` )
8180 } )
@@ -87,10 +86,7 @@ export async function handlePublish(agentName?: string): Promise<void> {
8786 )
8887
8988 try {
90- const result = await publishAgentTemplate (
91- template ,
92- client . user . authToken !
93- )
89+ const result = await publishAgentTemplate ( template , user . authToken ! )
9490
9591 if ( result . success ) {
9692 console . log (
0 commit comments