kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: WIP stubs for cli commands
rodzic
b4dab71399
commit
6a19da284a
|
@ -31,13 +31,14 @@
|
||||||
"@agentic/platform-api-client": "workspace:*",
|
"@agentic/platform-api-client": "workspace:*",
|
||||||
"commander": "^14.0.0",
|
"commander": "^14.0.0",
|
||||||
"conf": "^13.1.0",
|
"conf": "^13.1.0",
|
||||||
|
"inquirer": "^9.2.15",
|
||||||
"ora": "^8.2.0",
|
"ora": "^8.2.0",
|
||||||
"restore-cursor": "catalog:",
|
"restore-cursor": "catalog:",
|
||||||
"zod": "catalog:"
|
"zod": "catalog:"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@agentic/platform-db": "workspace:*",
|
"@commander-js/extra-typings": "^14.0.0",
|
||||||
"@commander-js/extra-typings": "^14.0.0"
|
"@types/inquirer": "^9.0.7"
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
import { AgenticApiClient } from '@agentic/platform-api-client'
|
||||||
|
|
||||||
|
// Create a singleton instance of the API client
|
||||||
|
export const client = new AgenticApiClient({
|
||||||
|
apiKey: process.env.AGENTIC_API_KEY
|
||||||
|
})
|
|
@ -0,0 +1,37 @@
|
||||||
|
import fs from 'node:fs/promises'
|
||||||
|
import path from 'node:path'
|
||||||
|
|
||||||
|
import { Command } from 'commander'
|
||||||
|
import ora from 'ora'
|
||||||
|
|
||||||
|
import { client } from '../client'
|
||||||
|
|
||||||
|
export const deploy = new Command('deploy')
|
||||||
|
.description('Creates a new deployment')
|
||||||
|
.argument('[path]', 'path to project directory', process.cwd())
|
||||||
|
.action(async (projectPath: string) => {
|
||||||
|
const spinner = ora('Creating deployment').start()
|
||||||
|
try {
|
||||||
|
// Read agentic.json from the project path
|
||||||
|
const configPath = path.join(projectPath, 'agentic.json')
|
||||||
|
const configContent = await fs.readFile(configPath, 'utf8')
|
||||||
|
const config = JSON.parse(configContent)
|
||||||
|
|
||||||
|
const deployment = await client.createDeployment(
|
||||||
|
{
|
||||||
|
identifier: config.name,
|
||||||
|
projectId: config.projectId,
|
||||||
|
version: config.version,
|
||||||
|
originUrl: config.originUrl || '',
|
||||||
|
pricingPlans: config.pricingPlans || []
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
spinner.succeed('Deployment created successfully')
|
||||||
|
console.log(JSON.stringify(deployment, null, 2))
|
||||||
|
} catch (err) {
|
||||||
|
spinner.fail('Failed to create deployment')
|
||||||
|
console.error(err)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
})
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { Command } from 'commander'
|
||||||
|
import ora from 'ora'
|
||||||
|
|
||||||
|
import { client } from '../client'
|
||||||
|
|
||||||
|
export const get = new Command('get')
|
||||||
|
.description('Gets details for a specific deployment')
|
||||||
|
.argument('<id>', 'deployment ID')
|
||||||
|
.action(async (id: string) => {
|
||||||
|
const spinner = ora('Fetching deployment details').start()
|
||||||
|
try {
|
||||||
|
const deployment = await client.getDeployment({ deploymentId: id })
|
||||||
|
spinner.succeed('Deployment details retrieved')
|
||||||
|
console.log(JSON.stringify(deployment, null, 2))
|
||||||
|
} catch (err) {
|
||||||
|
spinner.fail('Failed to fetch deployment details')
|
||||||
|
console.error(err)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
})
|
|
@ -0,0 +1,21 @@
|
||||||
|
import { Command } from 'commander'
|
||||||
|
import ora from 'ora'
|
||||||
|
|
||||||
|
import { client } from '../client'
|
||||||
|
|
||||||
|
export const ls = new Command('ls')
|
||||||
|
.alias('list')
|
||||||
|
.description('Lists deployments by project')
|
||||||
|
.argument('[project]', 'project ID')
|
||||||
|
.action(async (projectId?: string) => {
|
||||||
|
const spinner = ora('Fetching deployments').start()
|
||||||
|
try {
|
||||||
|
const deployments = await client.listDeployments({ projectId })
|
||||||
|
spinner.succeed('Deployments retrieved')
|
||||||
|
console.log(JSON.stringify(deployments, null, 2))
|
||||||
|
} catch (err) {
|
||||||
|
spinner.fail('Failed to fetch deployments')
|
||||||
|
console.error(err)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
})
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { Command } from 'commander'
|
||||||
|
import ora from 'ora'
|
||||||
|
|
||||||
|
import { client } from '../client'
|
||||||
|
|
||||||
|
export const publish = new Command('publish')
|
||||||
|
.description('Publishes a deployment')
|
||||||
|
.argument('[deploymentId]', 'deployment ID')
|
||||||
|
.action(async (deploymentId: string) => {
|
||||||
|
const spinner = ora('Publishing deployment').start()
|
||||||
|
try {
|
||||||
|
const deployment = await client.publishDeployment(
|
||||||
|
{ version: '1.0.0' },
|
||||||
|
{ deploymentId }
|
||||||
|
)
|
||||||
|
spinner.succeed('Deployment published successfully')
|
||||||
|
console.log(JSON.stringify(deployment, null, 2))
|
||||||
|
} catch (err) {
|
||||||
|
spinner.fail('Failed to publish deployment')
|
||||||
|
console.error(err)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
})
|
|
@ -0,0 +1,42 @@
|
||||||
|
import { Command } from 'commander'
|
||||||
|
import inquirer from 'inquirer'
|
||||||
|
import ora from 'ora'
|
||||||
|
|
||||||
|
import { client } from '../client'
|
||||||
|
|
||||||
|
export const rm = new Command('rm')
|
||||||
|
.description('Removes deployments')
|
||||||
|
.argument('[deploymentIds...]', 'deployment IDs to remove')
|
||||||
|
.option('-y, --yes', 'Skip confirmation')
|
||||||
|
.action(async (deploymentIds: string[], options: { yes?: boolean }) => {
|
||||||
|
if (!deploymentIds.length) {
|
||||||
|
console.error('Please provide at least one deployment ID')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options.yes) {
|
||||||
|
const { confirm } = await inquirer.prompt([
|
||||||
|
{
|
||||||
|
type: 'confirm',
|
||||||
|
name: 'confirm',
|
||||||
|
message: `Are you sure you want to remove ${deploymentIds.length} deployment(s)?`,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
if (!confirm) {
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const spinner = ora('Removing deployments').start()
|
||||||
|
try {
|
||||||
|
// Note: The API client doesn't have a deleteDeployment method yet
|
||||||
|
// This is a placeholder for when it's implemented
|
||||||
|
spinner.succeed('Deployments removed successfully')
|
||||||
|
} catch (err) {
|
||||||
|
spinner.fail('Failed to remove deployments')
|
||||||
|
console.error(err)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
})
|
|
@ -1,6 +1,11 @@
|
||||||
import { Command } from 'commander'
|
import { Command } from 'commander'
|
||||||
import restoreCursor from 'restore-cursor'
|
import restoreCursor from 'restore-cursor'
|
||||||
|
|
||||||
|
import { deploy } from './commands/deploy'
|
||||||
|
import { get } from './commands/get'
|
||||||
|
import { ls } from './commands/ls'
|
||||||
|
import { publish } from './commands/publish'
|
||||||
|
import { rm } from './commands/rm'
|
||||||
import { signin } from './commands/signin'
|
import { signin } from './commands/signin'
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
@ -8,6 +13,11 @@ async function main() {
|
||||||
|
|
||||||
const program = new Command()
|
const program = new Command()
|
||||||
program.addCommand(signin)
|
program.addCommand(signin)
|
||||||
|
program.addCommand(get)
|
||||||
|
program.addCommand(ls)
|
||||||
|
program.addCommand(publish)
|
||||||
|
program.addCommand(rm)
|
||||||
|
program.addCommand(deploy)
|
||||||
|
|
||||||
program.parse()
|
program.parse()
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue