coze_lab 0.1.23 → 0.1.24
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/README.md +4 -5
- package/index.js +10 -29
- package/package.json +1 -1
- package/scripts/claude-code/cozeloop_hook.py +2 -2
- package/scripts/codex/cozeloop_hook.py +2 -2
package/README.md
CHANGED
|
@@ -70,11 +70,10 @@ created after a new Codex turn, Codex did not load or execute the hook.
|
|
|
70
70
|
|
|
71
71
|
OAuth tokens are stored in `~/.cozeloop/credentials.json` (mode 600).
|
|
72
72
|
|
|
73
|
-
In cloud mode, trace verification and hook uploads
|
|
74
|
-
`COZELOOP_API_TOKEN
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
configuration but reports `verify=fail` with `token_source=COZE_API_TOKEN`.
|
|
73
|
+
In cloud mode, trace verification and hook uploads prefer
|
|
74
|
+
`COZELOOP_API_TOKEN` and fall back to `COZE_API_TOKEN`. The selfcheck result is
|
|
75
|
+
authoritative: if the token does not have trace ingest permission, onboard still
|
|
76
|
+
writes the hook configuration but reports `verify=fail` with `token_source`.
|
|
78
77
|
|
|
79
78
|
**At hook execution time** (Claude Code / Codex), the Python hook script automatically:
|
|
80
79
|
1. Reads `~/.cozeloop/credentials.json`
|
package/index.js
CHANGED
|
@@ -51,7 +51,7 @@ function getCloudTokenInfo() {
|
|
|
51
51
|
}
|
|
52
52
|
const cozeToken = readEnv('COZE_API_TOKEN');
|
|
53
53
|
if (cozeToken) {
|
|
54
|
-
return { token: cozeToken, source: 'COZE_API_TOKEN', traceUsable:
|
|
54
|
+
return { token: cozeToken, source: 'COZE_API_TOKEN', traceUsable: true };
|
|
55
55
|
}
|
|
56
56
|
return { token: '', source: '', traceUsable: false };
|
|
57
57
|
}
|
|
@@ -5420,32 +5420,28 @@ async function main() {
|
|
|
5420
5420
|
|
|
5421
5421
|
// Step 1: Authorize.
|
|
5422
5422
|
// 云端(--cloud):token 取自 sandbox 注入的环境变量,跳过 OAuth / credentials.json。
|
|
5423
|
-
//
|
|
5424
|
-
// onboard 会写入 hook,但自检会明确标记它不是 CozeLoop ingest token。
|
|
5423
|
+
// 优先使用 COZELOOP_API_TOKEN;兼容使用 COZE_API_TOKEN,并以真实 selfcheck 为准。
|
|
5425
5424
|
// 本地:load cached → refresh → device code。
|
|
5426
5425
|
// 注意:workspace_id 始终用写死的 WORKSPACE_ID(团队固定上报 workspace),不读环境。
|
|
5427
5426
|
let token;
|
|
5428
5427
|
let tokenSource = '';
|
|
5429
|
-
let cloudTraceUsableToken = true;
|
|
5430
5428
|
if (args.cloud) {
|
|
5431
5429
|
info('Step 1/5: 云端模式,从环境变量读取 trace token...');
|
|
5432
5430
|
const tokenInfo = getCloudTokenInfo();
|
|
5433
5431
|
token = tokenInfo.token;
|
|
5434
5432
|
tokenSource = tokenInfo.source;
|
|
5435
|
-
cloudTraceUsableToken = tokenInfo.traceUsable;
|
|
5436
5433
|
if (!token) {
|
|
5437
5434
|
errorBox([
|
|
5438
|
-
'ERROR: --cloud 模式要求环境变量 COZELOOP_API_TOKEN',
|
|
5435
|
+
'ERROR: --cloud 模式要求环境变量 COZELOOP_API_TOKEN 或 COZE_API_TOKEN',
|
|
5439
5436
|
'',
|
|
5440
|
-
'云端 sandbox
|
|
5437
|
+
'云端 sandbox 应在进程环境中注入可用于 trace ingest 的 token。',
|
|
5441
5438
|
'未检测到该变量,无法配置 trace 上报。',
|
|
5442
5439
|
]);
|
|
5443
5440
|
}
|
|
5444
5441
|
cloudResult.token_source = tokenSource;
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
warn('仅检测到 COZE_API_TOKEN;它不是 CozeLoop SDK trace ingest token,自检预计会失败。');
|
|
5442
|
+
ok(`已从环境变量读取 ${tokenSource}`);
|
|
5443
|
+
if (tokenSource === 'COZE_API_TOKEN') {
|
|
5444
|
+
info('将兼容使用 COZE_API_TOKEN 作为 trace token,并通过 selfcheck 验证实际可用性。');
|
|
5449
5445
|
}
|
|
5450
5446
|
} else {
|
|
5451
5447
|
info('Step 1/5: 检查授权状态...');
|
|
@@ -5534,24 +5530,9 @@ async function main() {
|
|
|
5534
5530
|
|
|
5535
5531
|
// Step 5: Verify trace reporting end-to-end
|
|
5536
5532
|
info('Step 5/5: 验证 trace 上报链路...');
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
success: false,
|
|
5541
|
-
status: 0,
|
|
5542
|
-
body: '云端仅提供 COZE_API_TOKEN。Coze API token 不能作为 CozeLoop Python SDK 的 COZELOOP_API_TOKEN 上报 trace;请注入具备 CozeLoop trace ingest 权限的 COZELOOP_API_TOKEN。',
|
|
5543
|
-
traceId: '',
|
|
5544
|
-
pairCode: args.pairCode || '',
|
|
5545
|
-
tokenSource,
|
|
5546
|
-
apiBaseUrl: getCozeloopApiBaseUrl(true),
|
|
5547
|
-
};
|
|
5548
|
-
warn('trace 上报跳过:缺少 COZELOOP_API_TOKEN。');
|
|
5549
|
-
console.log(verifyResult.body);
|
|
5550
|
-
} else {
|
|
5551
|
-
verifyResult = args.cloud
|
|
5552
|
-
? await verifyTraceReportViaSdk(token, WORKSPACE_ID, args.pairCode, pythonCmd || 'python3', tokenSource)
|
|
5553
|
-
: await verifyTraceReport(token, WORKSPACE_ID, args.pairCode, getOtelTracesUrl(false));
|
|
5554
|
-
}
|
|
5533
|
+
const verifyResult = args.cloud
|
|
5534
|
+
? await verifyTraceReportViaSdk(token, WORKSPACE_ID, args.pairCode, pythonCmd || 'python3', tokenSource)
|
|
5535
|
+
: await verifyTraceReport(token, WORKSPACE_ID, args.pairCode, getOtelTracesUrl(false));
|
|
5555
5536
|
if (verifyResult.success) {
|
|
5556
5537
|
cloudResult.verify = 'ok';
|
|
5557
5538
|
} else if (CLOUD_MODE) {
|
package/package.json
CHANGED
|
@@ -273,6 +273,8 @@ def get_fresh_token() -> Optional[str]:
|
|
|
273
273
|
env_coze_token = os.environ.get("COZE_API_TOKEN")
|
|
274
274
|
if env_token:
|
|
275
275
|
return env_token
|
|
276
|
+
if env_coze_token:
|
|
277
|
+
return env_coze_token
|
|
276
278
|
creds = _load_credentials()
|
|
277
279
|
if creds:
|
|
278
280
|
expires_at_sec = creds.get("expires_at", 0) / 1000
|
|
@@ -286,8 +288,6 @@ def get_fresh_token() -> Optional[str]:
|
|
|
286
288
|
if new_token:
|
|
287
289
|
return new_token
|
|
288
290
|
debug_log("Refresh failed, falling back to env var.")
|
|
289
|
-
if env_coze_token:
|
|
290
|
-
debug_log("COZE_API_TOKEN present but ignored; CozeLoop trace upload requires COZELOOP_API_TOKEN")
|
|
291
291
|
return None
|
|
292
292
|
|
|
293
293
|
# -------------------------------------------------------------------------
|
|
@@ -234,6 +234,8 @@ def get_fresh_token():
|
|
|
234
234
|
env_coze_token = os.environ.get("COZE_API_TOKEN")
|
|
235
235
|
if env_token:
|
|
236
236
|
return env_token
|
|
237
|
+
if env_coze_token:
|
|
238
|
+
return env_coze_token
|
|
237
239
|
creds = _load_credentials()
|
|
238
240
|
if creds:
|
|
239
241
|
remaining = creds.get("expires_at", 0) / 1000 - time.time()
|
|
@@ -243,8 +245,6 @@ def get_fresh_token():
|
|
|
243
245
|
new_token = _refresh_token(creds["refresh_token"])
|
|
244
246
|
if new_token:
|
|
245
247
|
return new_token
|
|
246
|
-
if env_coze_token:
|
|
247
|
-
hook_log("COZE_API_TOKEN present but ignored; CozeLoop trace upload requires COZELOOP_API_TOKEN")
|
|
248
248
|
return None
|
|
249
249
|
# -------------------------------------------------------------------------
|
|
250
250
|
|