()
| 122 | } |
| 123 | |
| 124 | export async function deploy() { |
| 125 | p.intro("@21st-sdk/cli deploy") |
| 126 | |
| 127 | // 1. Check auth |
| 128 | const apiKey = getApiKey() |
| 129 | if (!apiKey) { |
| 130 | p.log.error( |
| 131 | "Not logged in. Run `npx @21st-sdk/cli login` first, or set API_KEY_21ST.", |
| 132 | ) |
| 133 | process.exit(1) |
| 134 | } |
| 135 | |
| 136 | // Deprecation notice for old project config |
| 137 | if (existsSync(join(process.cwd(), ".an", "project.json"))) { |
| 138 | p.log.warn(".an/project.json is no longer used and can be removed.") |
| 139 | } |
| 140 | |
| 141 | // 2. Find agent entry points |
| 142 | let agents |
| 143 | try { |
| 144 | agents = await findAgentEntryPoints() |
| 145 | } catch (err: any) { |
| 146 | p.log.error(err.message) |
| 147 | process.exit(1) |
| 148 | } |
| 149 | |
| 150 | const onlySlug = getFlag("--agent") |
| 151 | if (onlySlug) { |
| 152 | agents = agents.filter((a) => a.slug === onlySlug) |
| 153 | if (agents.length === 0) { |
| 154 | p.log.error( |
| 155 | `No agent with slug "${onlySlug}" in ./agents/ (see npx @21st-sdk/cli deploy --help)`, |
| 156 | ) |
| 157 | process.exit(1) |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | const nameOverride = getFlag("--name") |
| 162 | if (nameOverride) { |
| 163 | const slugError = validateSlug(nameOverride) |
| 164 | if (slugError) { |
| 165 | p.log.error(`Invalid --name "${nameOverride}": ${slugError}`) |
| 166 | process.exit(1) |
| 167 | } |
| 168 | if (agents.length > 1) { |
| 169 | p.log.error( |
| 170 | `--name can only be used when deploying a single agent. Use --agent to select one.`, |
| 171 | ) |
| 172 | process.exit(1) |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | p.log.info(`Found ${agents.length} agent${agents.length > 1 ? "s" : ""}`) |
| 177 | |
| 178 | // 3. Deploy each agent |
| 179 | const deployed: { slug: string }[] = [] |
| 180 | |
| 181 | for (const agent of agents) { |
no test coverage detected