Team Ai
Apppublic

delqhi/code-devops

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
cli.ts65 linesDownload Raw Back to src
1#!/usr/bin/env node2 3import process from 'node:process';4import { restoreAuthSession, startKeepAlivePing, startAutoBackup } from './hf_sync.js';5import { createTemplateAgentHttpServer } from './a2a-http.js';6import { buildAgentCard, resolveTemplateAgentConfig } from './metadata.js';7import { startMcpServer } from './mcp-server.js';8import { executeTemplateAgentAction, type TemplateAgentAction } from './runtime.js';9 10async function main(): Promise<void> {11  const command = process.argv[2] || 'help';12  switch (command) {13    case 'serve':14    case 'serve-a2a':15      await serveA2A();16      return;17    case 'serve-mcp':18      await startMcpServer();19      return;20    case 'print-card':21      printJson(buildAgentCard(resolveTemplateAgentConfig().publicBaseUrl));22      return;23    case 'run-action':24      await runAction();25      return;26    default:27      printUsage();28  }29}30 31async function serveA2A() {32  const config = resolveTemplateAgentConfig();33  const handle = createTemplateAgentHttpServer();34  await handle.start();35  printJson({ ok: true, command: 'serve-a2a', host: config.host, port: config.port, baseUrl: config.publicBaseUrl });36}37 38async function runAction() {39  const raw = process.argv[3]?.trim() || (await readStdin()).trim();40  if (!raw) throw new Error('missing_action_json');41  printJson(await executeTemplateAgentAction(JSON.parse(raw) as TemplateAgentAction));42}43 44function printUsage() {45  process.stderr.write(46    ['Usage:', '  sin-code-devops serve-a2a', '  sin-code-devops serve-mcp', '  sin-code-devops print-card', `  sin-code-devops run-action '{"action":"agent.help"}'`].join('\n') + '\n',47  );48}49 50function printJson(payload: unknown) {51  process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);52}53 54async function readStdin() {55  const chunks: Buffer[] = [];56  for await (const chunk of process.stdin) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));57  return Buffer.concat(chunks).toString('utf8');58}59 60main().catch((error) => {61  process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);62  process.exitCode = 1;63});64 65