2025-05-22 17:19:04 +00:00
|
|
|
import 'dotenv/config'
|
|
|
|
|
|
|
|
import { AgenticApiClient } from '@agentic/platform-api-client'
|
2025-05-19 15:19:34 +00:00
|
|
|
import { Command } from 'commander'
|
|
|
|
import restoreCursor from 'restore-cursor'
|
|
|
|
|
2025-05-26 19:13:30 +00:00
|
|
|
import { registerDebugCommand } from './commands/debug'
|
2025-05-26 17:35:19 +00:00
|
|
|
import { registerDeployCommand } from './commands/deploy'
|
2025-05-26 19:09:46 +00:00
|
|
|
import { registerGetDeploymentCommand } from './commands/get'
|
|
|
|
import { registerListDeploymentsCommand } from './commands/list'
|
2025-05-26 18:23:16 +00:00
|
|
|
import { registerPublishCommand } from './commands/publish'
|
2025-05-22 17:19:04 +00:00
|
|
|
import { registerSigninCommand } from './commands/signin'
|
2025-05-22 17:23:39 +00:00
|
|
|
import { registerSignoutCommand } from './commands/signout'
|
2025-05-22 17:19:04 +00:00
|
|
|
import { registerWhoAmICommand } from './commands/whoami'
|
2025-05-26 18:23:16 +00:00
|
|
|
import { AuthStore } from './lib/auth-store'
|
2025-05-21 19:14:46 +00:00
|
|
|
|
2025-05-19 15:19:34 +00:00
|
|
|
async function main() {
|
|
|
|
restoreCursor()
|
|
|
|
|
2025-05-26 18:28:18 +00:00
|
|
|
// Initialize the API client
|
2025-05-22 17:19:04 +00:00
|
|
|
const client = new AgenticApiClient({
|
2025-05-24 15:02:24 +00:00
|
|
|
apiBaseUrl: process.env.AGENTIC_API_BASE_URL,
|
|
|
|
onUpdateAuth: (update) => {
|
|
|
|
if (update) {
|
2025-06-03 09:48:24 +00:00
|
|
|
AuthStore.setAuth(update)
|
2025-05-24 15:02:24 +00:00
|
|
|
} else {
|
|
|
|
AuthStore.clearAuth()
|
|
|
|
}
|
|
|
|
}
|
2025-05-21 19:14:46 +00:00
|
|
|
})
|
2025-05-22 17:19:04 +00:00
|
|
|
|
2025-05-24 16:17:30 +00:00
|
|
|
// Initialize the existing auth session if one exists
|
2025-05-24 15:02:24 +00:00
|
|
|
const authSession = AuthStore.tryGetAuth()
|
|
|
|
if (authSession) {
|
|
|
|
try {
|
2025-06-03 09:48:24 +00:00
|
|
|
await client.setAuth(authSession.session)
|
2025-05-24 15:50:17 +00:00
|
|
|
} catch {
|
|
|
|
console.warn('Existing auth session is invalid; logging out.\n')
|
2025-05-24 15:02:24 +00:00
|
|
|
AuthStore.clearAuth()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-05-26 18:28:18 +00:00
|
|
|
// Initialize the CLI program
|
2025-05-22 17:19:04 +00:00
|
|
|
const program = new Command('agentic')
|
2025-06-03 09:48:24 +00:00
|
|
|
.option('-j, --json', 'Print output as JSON')
|
2025-05-22 17:19:04 +00:00
|
|
|
.showHelpAfterError()
|
|
|
|
|
|
|
|
const logger = {
|
|
|
|
log: (...args: any[]) => {
|
|
|
|
if (program.opts().json) {
|
|
|
|
console.log(
|
2025-06-03 19:57:33 +00:00
|
|
|
args.length === 1
|
|
|
|
? JSON.stringify(args[0], null, 2)
|
|
|
|
: JSON.stringify(args, null, 2)
|
2025-05-22 17:19:04 +00:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
console.log(...args)
|
|
|
|
}
|
2025-05-26 17:35:19 +00:00
|
|
|
},
|
2025-05-26 18:23:16 +00:00
|
|
|
info: (...args: any[]) => {
|
|
|
|
console.info(...args)
|
|
|
|
},
|
2025-05-26 17:35:19 +00:00
|
|
|
error: (...args: any[]) => {
|
|
|
|
console.error(...args)
|
2025-05-22 17:19:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const ctx = {
|
|
|
|
client,
|
|
|
|
program,
|
|
|
|
logger
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register all commands
|
|
|
|
registerSigninCommand(ctx)
|
|
|
|
registerWhoAmICommand(ctx)
|
2025-05-22 17:23:39 +00:00
|
|
|
registerSignoutCommand(ctx)
|
2025-05-26 17:35:19 +00:00
|
|
|
registerDeployCommand(ctx)
|
2025-05-26 18:23:16 +00:00
|
|
|
registerPublishCommand(ctx)
|
2025-05-26 19:09:46 +00:00
|
|
|
registerGetDeploymentCommand(ctx)
|
|
|
|
registerListDeploymentsCommand(ctx)
|
2025-05-26 19:13:30 +00:00
|
|
|
registerDebugCommand(ctx)
|
2025-05-19 15:19:34 +00:00
|
|
|
|
|
|
|
program.parse()
|
|
|
|
}
|
|
|
|
|
|
|
|
await main()
|