coze_lab 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +31 -14
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -4156,11 +4156,12 @@ function parseArgs() {
|
|
|
4156
4156
|
const VALID_AGENTS = ['claude-code', 'codex', 'openclaw'];
|
|
4157
4157
|
|
|
4158
4158
|
// resolveAgent 读 ~/.coze/agents/<agentId>/config.json,返回 { framework, workspace, agentId, root }。
|
|
4159
|
-
//
|
|
4160
|
-
function resolveAgent(agentId) {
|
|
4159
|
+
// soft=true 时,config 不存在 / 解析失败 / framework 非法均返回 null(不退出),供云端回退到显式 --agent。
|
|
4160
|
+
function resolveAgent(agentId, soft) {
|
|
4161
4161
|
const root = path.join(os.homedir(), '.coze', 'agents', agentId);
|
|
4162
4162
|
const configPath = path.join(root, 'config.json');
|
|
4163
4163
|
if (!fs.existsSync(configPath)) {
|
|
4164
|
+
if (soft) return null;
|
|
4164
4165
|
errorBox([
|
|
4165
4166
|
`ERROR: agent "${agentId}" 不存在`,
|
|
4166
4167
|
'',
|
|
@@ -4172,10 +4173,12 @@ function resolveAgent(agentId) {
|
|
|
4172
4173
|
try {
|
|
4173
4174
|
cfg = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
4174
4175
|
} catch (e) {
|
|
4176
|
+
if (soft) return null;
|
|
4175
4177
|
errorBox([`ERROR: 解析 ${configPath} 失败`, '', e.message]);
|
|
4176
4178
|
}
|
|
4177
4179
|
const framework = cfg.framework;
|
|
4178
4180
|
if (!VALID_AGENTS.includes(framework)) {
|
|
4181
|
+
if (soft) return null;
|
|
4179
4182
|
errorBox([
|
|
4180
4183
|
`ERROR: agent "${agentId}" 的 framework="${framework}" 不受支持`,
|
|
4181
4184
|
'',
|
|
@@ -4192,21 +4195,33 @@ function validateArgs(args) {
|
|
|
4192
4195
|
if (args['refresh']) return { refresh: true };
|
|
4193
4196
|
if (args['verify']) return { verify: true, pairCode: args['pair-code'] };
|
|
4194
4197
|
|
|
4195
|
-
// --cloud + --agent-id
|
|
4196
|
-
//
|
|
4198
|
+
// --cloud + --agent-id:优先读云端 ~/.coze/agents/<id>/config.json 拿 framework + workspace
|
|
4199
|
+
// (云端 config.json 稳定存在);读不到再回退到命令行显式 --agent(workspace 在 main 推断)。
|
|
4197
4200
|
if (args['cloud'] && args['agent-id']) {
|
|
4201
|
+
const resolved = resolveAgent(args['agent-id'], true /* soft */);
|
|
4202
|
+
if (resolved) {
|
|
4203
|
+
return {
|
|
4204
|
+
agent: resolved.framework,
|
|
4205
|
+
agentId: resolved.agentId,
|
|
4206
|
+
workspace: resolved.workspace,
|
|
4207
|
+
agentRoot: resolved.root,
|
|
4208
|
+
'codex-home': args['codex-home'],
|
|
4209
|
+
pairCode: args['pair-code'],
|
|
4210
|
+
cloud: true,
|
|
4211
|
+
};
|
|
4212
|
+
}
|
|
4213
|
+
// config.json 缺失:回退到显式 --agent
|
|
4198
4214
|
if (!args['agent'] || !VALID_AGENTS.includes(args['agent'])) {
|
|
4199
4215
|
errorBox([
|
|
4200
|
-
|
|
4216
|
+
`ERROR: 未找到 agent "${args['agent-id']}" 的 config.json,且未显式指定 --agent`,
|
|
4201
4217
|
'',
|
|
4202
|
-
'
|
|
4203
|
-
|
|
4218
|
+
'请确认 agentId 正确,或显式拼上 framework:',
|
|
4219
|
+
` npx coze_lab --cloud --agent-id=${args['agent-id']} --agent=claude-code|codex|openclaw`,
|
|
4204
4220
|
]);
|
|
4205
4221
|
}
|
|
4206
4222
|
return {
|
|
4207
4223
|
agent: args['agent'],
|
|
4208
4224
|
agentId: args['agent-id'],
|
|
4209
|
-
// 云端 claude-code 配置写进 agent workspace,缺省按约定路径推断(见 main)。
|
|
4210
4225
|
workspace: args['workspace'] || '',
|
|
4211
4226
|
'codex-home': args['codex-home'],
|
|
4212
4227
|
pairCode: args['pair-code'],
|
|
@@ -5157,21 +5172,23 @@ async function main() {
|
|
|
5157
5172
|
}
|
|
5158
5173
|
|
|
5159
5174
|
// Step 1: Authorize.
|
|
5160
|
-
// 云端(--cloud):token
|
|
5175
|
+
// 云端(--cloud):token 取自 sandbox 注入的环境变量,跳过 OAuth / credentials.json。
|
|
5176
|
+
// 云端真实变量名是 COZELOOP_API_TOKEN(兼容历史的 COZE_API_TOKEN)。
|
|
5161
5177
|
// 本地:load cached → refresh → device code。
|
|
5178
|
+
// 注意:workspace_id 始终用写死的 WORKSPACE_ID(团队固定上报 workspace),不读环境。
|
|
5162
5179
|
let token;
|
|
5163
5180
|
if (args.cloud) {
|
|
5164
|
-
info('Step 1/5:
|
|
5165
|
-
token = process.env.COZE_API_TOKEN;
|
|
5181
|
+
info('Step 1/5: 云端模式,从环境变量读取 COZELOOP_API_TOKEN...');
|
|
5182
|
+
token = process.env.COZELOOP_API_TOKEN || process.env.COZE_API_TOKEN;
|
|
5166
5183
|
if (!token) {
|
|
5167
5184
|
errorBox([
|
|
5168
|
-
'ERROR: --cloud 模式要求环境变量
|
|
5185
|
+
'ERROR: --cloud 模式要求环境变量 COZELOOP_API_TOKEN',
|
|
5169
5186
|
'',
|
|
5170
|
-
'云端 sandbox 应在进程环境中注入 COZE_API_TOKEN
|
|
5187
|
+
'云端 sandbox 应在进程环境中注入 COZELOOP_API_TOKEN(或 COZE_API_TOKEN)。',
|
|
5171
5188
|
'未检测到该变量,无法配置 trace 上报。',
|
|
5172
5189
|
]);
|
|
5173
5190
|
}
|
|
5174
|
-
ok('已从环境变量读取
|
|
5191
|
+
ok('已从环境变量读取 COZELOOP_API_TOKEN');
|
|
5175
5192
|
} else {
|
|
5176
5193
|
info('Step 1/5: 检查授权状态...');
|
|
5177
5194
|
token = await getValidToken();
|