{"version":3,"file":"index.mjs","sources":["webpack://@multimodal/seed-gui-agent/./src/index.ts","webpack://@multimodal/seed-gui-agent/webpack/runtime/esm_module_decorator"],"sourcesContent":["/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport os from 'node:os';\nimport { env } from 'process';\nimport * as p from '@clack/prompts';\nimport { Command } from 'commander';\nimport { SYSTEM_PROMPT_LATEST, SYSTEM_PROMPT } from './constants';\nimport { SeedGUIAgent } from './SeedGUIAgent';\nimport { ProviderOptions } from '@tarko/agent-interface';\n\ninterface TestOptions {\n  target?: string;\n}\n\ninterface CliOptions {\n  target?: string;\n  query?: string;\n}\n\ninterface ConfigFileData {\n  baseURL?: string;\n  model?: string;\n  apiKey?: string;\n}\n\nfunction validateEnvironmentVariables() {\n  // secretlint-disable-next-line\n  if (!env.ARK_BASE_URL || !env.ARK_MODEL || !env.ARK_API_KEY) {\n    console.error('❌ 缺少必需的环境变量:');\n    if (!env.ARK_BASE_URL) console.error('  - ARK_BASE_URL 未设置');\n    if (!env.ARK_MODEL) console.error('  - ARK_MODEL 未设置');\n    if (!env.ARK_API_KEY) console.error('  - ARK_API_KEY 未设置'); // secretlint-disable-line\n    console.error('请设置所有必需的环境变量后重试。');\n    process.exit(1);\n  }\n}\n\nfunction getModelConfig(): ProviderOptions {\n  return {\n    provider: 'openai-non-streaming',\n    baseURL: env.ARK_BASE_URL!,\n    id: env.ARK_MODEL!,\n    apiKey: env.ARK_API_KEY!, // secretlint-disable-line\n  };\n}\n\nasync function getConfigFromFile(): Promise<ConfigFileData> {\n  const CONFIG_PATH = path.join(os.homedir(), '.seed-gui-agent-cli.json');\n\n  if (env.ARK_API_KEY && env.ARK_BASE_URL && env.ARK_MODEL) {\n    return {\n      baseURL: env.ARK_BASE_URL,\n      model: env.ARK_MODEL,\n      apiKey: env.ARK_API_KEY, // secretlint-disable-line\n    };\n  }\n\n  if (fs.existsSync(CONFIG_PATH)) {\n    try {\n      const config = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8'));\n      return {\n        baseURL: config.baseURL,\n        model: config.model,\n        apiKey: config.apiKey, // secretlint-disable-line\n      };\n    } catch (error) {\n      console.warn('读取配置文件失败', error);\n    }\n  }\n\n  return {};\n}\n\nasync function runWithOperator(\n  operatorType: 'browser' | 'computer' | 'android',\n  instruction: string,\n  modelConfig: ConfigFileData,\n) {\n  console.log(`🚀 运行 ${operatorType} operator...`);\n\n  const seedGUIAgent = new SeedGUIAgent({\n    operatorType,\n    model: {\n      provider: 'openai-non-streaming',\n      baseURL: modelConfig.baseURL,\n      id: modelConfig.model, // 注意这里是model而不是id\n      apiKey: modelConfig.apiKey, // secretlint-disable-line\n    },\n    uiTarsVersion: 'latest',\n    systemPrompt: SYSTEM_PROMPT,\n  });\n\n  const response = await seedGUIAgent.run({\n    input: [{ type: 'text', text: instruction }],\n  });\n\n  console.log(`\\n📝 ${operatorType} 场景响应:`);\n  console.log('================================================');\n  console.log(response.content);\n  console.log('================================================');\n}\n\nasync function startCli(options: CliOptions) {\n  let modelConfig = await getConfigFromFile();\n\n  if (!modelConfig.baseURL || !modelConfig.apiKey || !modelConfig.model) {\n    console.log('🔧请输入模型配置信息:');\n    const configAnswers = await p.group(\n      {\n        baseURL: () =>\n          p.text({\n            message: '请输入模型 baseURL:',\n            defaultValue: modelConfig.baseURL || '',\n          }),\n        // secretlint-disable-next-line\n        apiKey: () =>\n          p.text({\n            message: '请输入模型 apiKey:', // secretlint-disable-line\n            defaultValue: modelConfig.apiKey || '', // secretlint-disable-line\n          }),\n        model: () =>\n          p.text({\n            message: '请输入模型名称:',\n            defaultValue: modelConfig.model || '',\n          }),\n      },\n      {\n        onCancel: () => {\n          p.cancel('操作已取消');\n          process.exit(0);\n        },\n      },\n    );\n\n    modelConfig = { ...modelConfig, ...configAnswers };\n\n    const CONFIG_PATH = path.join(os.homedir(), '.seed-gui-agent-cli.json');\n    try {\n      fs.writeFileSync(CONFIG_PATH, JSON.stringify(modelConfig, null, 2));\n      console.log('✅ 配置文件已保存到:', CONFIG_PATH);\n    } catch (error) {\n      console.error('❌ 保存配置文件失败', error);\n    }\n  } else {\n    console.log('✅ 使用已有模型配置');\n  }\n\n  const targetType =\n    options.target ||\n    ((await p.select({\n      message: '请选择operator类型:',\n      options: [\n        { value: 'browser', label: 'browser operator' },\n        { value: 'computer', label: 'computer operator' },\n        { value: 'android', label: 'android operator' },\n      ],\n    })) as string);\n\n  const instruction = options.query || ((await p.text({ message: '请输入您的指令:' })) as string);\n\n  if (!instruction) {\n    console.error('❌ 未提供指令');\n    process.exit(1);\n  }\n\n  await runWithOperator(targetType as 'browser' | 'computer' | 'android', instruction, modelConfig);\n}\n\nasync function testBrowserOperator() {\n  console.log('🌐 Testing Browser Operator...');\n\n  const seedGUIAgentForBrowser = new SeedGUIAgent({\n    operatorType: 'browser',\n    model: getModelConfig(),\n    uiTarsVersion: 'latest',\n    systemPrompt: SYSTEM_PROMPT,\n  });\n\n  const browserResponse = await seedGUIAgentForBrowser.run({\n    input: [{ type: 'text', text: 'What is Agent TARS' }],\n  });\n\n  console.log('\\n📝 Agent with Browser Operator Response:');\n  console.log('================================================');\n  console.log(browserResponse.content);\n  console.log('================================================');\n}\n\nasync function testComputerOperator() {\n  console.log('💻 Testing Computer Operator...');\n\n  const seedGUIAgentForComputer = new SeedGUIAgent({\n    operatorType: 'computer',\n    model: {\n      provider: getModelConfig().provider,\n      baseURL: getModelConfig().baseURL,\n      id: getModelConfig().id,\n      apiKey: getModelConfig().apiKey, // secretlint-disable-line\n    },\n    uiTarsVersion: 'latest',\n    systemPrompt: SYSTEM_PROMPT,\n  });\n\n  const computerResponse = await seedGUIAgentForComputer.run({\n    input: [{ type: 'text', text: 'What is Agent TARS' }],\n  });\n\n  console.log('\\n📝 Agent with Computer Operator Response:');\n  console.log('================================================');\n  console.log(computerResponse.content);\n  console.log('================================================');\n}\n\nasync function testAndroidOperator() {\n  console.log('📱 Testing Android Operator...');\n\n  const seedGUIAgentForAndroid = new SeedGUIAgent({\n    operatorType: 'android',\n    model: getModelConfig(),\n    uiTarsVersion: 'latest',\n    // TODO: 这里的systemPrompt需要根据android的prompt来写\n    systemPrompt: SYSTEM_PROMPT,\n  });\n\n  const androidResponse = await seedGUIAgentForAndroid.run({\n    input: [{ type: 'text', text: 'What is Agent TARS' }],\n  });\n\n  console.log('\\n📝 Agent with Android Operator Response:');\n  console.log('================================================');\n  console.log(androidResponse.content);\n  console.log('================================================');\n}\n\nasync function testAllOperators() {\n  console.log('🚀 Testing All Operators...');\n  await testBrowserOperator();\n  await testComputerOperator();\n  await testAndroidOperator();\n}\n\nasync function main() {\n  const program = new Command();\n  program.name('seed-gui-agent').description('SeedGUIAgent CLI').version('0.0.1');\n\n  program\n    .command('start')\n    .description('启动 SeedGUIAgent...')\n    .option('-t, --target <target>', '目标operator (browser|computer|android)')\n    .option('-q, --query <query>', '用户指令')\n    .action(async (options: CliOptions) => {\n      try {\n        await startCli(options);\n      } catch (err) {\n        console.error('启动失败');\n        console.error(err);\n        process.exit(1);\n      }\n    });\n\n  program\n    .command('test')\n    .description('测试 SeedGUIAgent 不同Operator')\n    .option('-t, --target <target>', '目标Operator (browser|computer|android|all)', 'all')\n    .action(async (options: TestOptions) => {\n      validateEnvironmentVariables();\n      const { target } = options;\n      switch (target?.toLowerCase()) {\n        case 'browser':\n          await testBrowserOperator();\n          break;\n        case 'computer':\n          await testComputerOperator();\n          break;\n        case 'android':\n          await testAndroidOperator();\n          break;\n        case 'all':\n          await testAllOperators();\n          break;\n        default:\n          console.error(`❌ 未知的目标类型: ${target}`);\n          console.error('支持的类型: browser, computer, android, all');\n          process.exit(1);\n      }\n    });\n\n  await program.parseAsync(process.argv);\n}\n\nif (require.main === module) {\n  main().catch(console.error);\n}\n\nexport * from './SeedGUIAgent';\nexport { SeedGUIAgent as default } from './SeedGUIAgent';\n","__webpack_require__.hmd = (module) => {\n  module = Object.create(module);\n  if (!module.children) module.children = [];\n  Object.defineProperty(module, 'exports', {\n      enumerable: true,\n      set: () => {\n          throw new Error('ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: ' + module.id);\n      }\n  });\n  return module;\n};"],"names":["validateEnvironmentVariables","env","console","process","getModelConfig","getConfigFromFile","CONFIG_PATH","path","os","fs","config","JSON","error","runWithOperator","operatorType","instruction","modelConfig","seedGUIAgent","SeedGUIAgent","SYSTEM_PROMPT","response","startCli","options","configAnswers","p","targetType","testBrowserOperator","seedGUIAgentForBrowser","browserResponse","testComputerOperator","seedGUIAgentForComputer","computerResponse","testAndroidOperator","seedGUIAgentForAndroid","androidResponse","testAllOperators","main","program","Command","err","target","require","module","__webpack_require__","Object","Error"],"mappings":";;;;;;;;;;;;;;;;QA6BA,SAASA;YAEP,IAAI,CAACC,IAAI,YAAY,IAAI,CAACA,IAAI,SAAS,IAAI,CAACA,IAAI,WAAW,EAAE;gBAC3DC,QAAQ,KAAK,CAAC;gBACd,IAAI,CAACD,IAAI,YAAY,EAAEC,QAAQ,KAAK,CAAC;gBACrC,IAAI,CAACD,IAAI,SAAS,EAAEC,QAAQ,KAAK,CAAC;gBAClC,IAAI,CAACD,IAAI,WAAW,EAAEC,QAAQ,KAAK,CAAC;gBACpCA,QAAQ,KAAK,CAAC;gBACdC,QAAQ,IAAI,CAAC;YACf;QACF;QAEA,SAASC;YACP,OAAO;gBACL,UAAU;gBACV,SAASH,IAAI,YAAY;gBACzB,IAAIA,IAAI,SAAS;gBACjB,QAAQA,IAAI,WAAW;YACzB;QACF;QAEA,eAAeI;YACb,MAAMC,cAAcC,UAAAA,IAAS,CAACC,QAAAA,OAAU,IAAI;YAE5C,IAAIP,IAAI,WAAW,IAAIA,IAAI,YAAY,IAAIA,IAAI,SAAS,EACtD,OAAO;gBACL,SAASA,IAAI,YAAY;gBACzB,OAAOA,IAAI,SAAS;gBACpB,QAAQA,IAAI,WAAW;YACzB;YAGF,IAAIQ,QAAAA,UAAa,CAACH,cACh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