ai-lab-bridge 0.1.5 → 0.1.6

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.
Files changed (2) hide show
  1. package/index.js +21 -5
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -270,8 +270,22 @@ class Session {
270
270
  /** 归一化后缓存 + 回传 usage:各家 CLI 字段名不同(input_tokens/input/prompt_tokens...),统一为平台口径 */
271
271
  emitUsage(usage) {
272
272
  const num = (v) => (typeof v === "number" && isFinite(v) ? v : undefined);
273
- const raw = usage && typeof usage === "object" ? usage : null;
273
+ let raw = usage && typeof usage === "object" ? usage : null;
274
274
  if (!raw) return;
275
+ // gemini 家族(qwen/iflow 同源)stats 为嵌套结构:
276
+ // {models: {"<模型名>": {tokens: {prompt, candidates, total, cached, thoughts}}}}
277
+ if (raw.models && typeof raw.models === "object") {
278
+ const first = Object.values(raw.models).find((m) => m && m.tokens && typeof m.tokens === "object");
279
+ const tk = first && first.tokens;
280
+ if (tk) {
281
+ raw = {
282
+ ...raw,
283
+ input: num(tk.prompt) ?? num(raw.input),
284
+ output: num(tk.candidates) ?? num(raw.output),
285
+ cache: { read: num(tk.cached) },
286
+ };
287
+ }
288
+ }
275
289
  // opencode 系: {input, output, cache:{read}} / claude: {input_tokens, output_tokens, cache_read_input_tokens}
276
290
  // codex: {input_tokens, output_tokens, total_tokens} / gemini: {inputTokenCount, outputTokenCount, ...}
277
291
  const input = num(raw.input_tokens) ?? num(raw.input) ?? num(raw.prompt_tokens) ?? num(raw.inputTokenCount);
@@ -773,8 +787,10 @@ function startSession(message) {
773
787
 
774
788
  let promptViaStdin = true;
775
789
  let launch = null;
776
- if (cli === "claude") {
777
- argv = ["claude", ["-p", "--output-format", "stream-json", "--verbose"]];
790
+ if (cli === "claude" || cli === "qwen") {
791
+ // Qwen CLI 0.24+ 已重构为 Claude Code 同构架构(result 事件带 subtype/session_id/usage,
792
+ // 实测 0.24.6),stream-json 输出与 Claude Code 兼容,复用同一启动参数与解析器
793
+ argv = [cli, ["-p", "--output-format", "stream-json", "--verbose"]];
778
794
  if (sessionRef) argv[1].push("--resume", sessionRef);
779
795
  if (options.permission_mode) argv[1].push("--permission-mode", String(options.permission_mode));
780
796
  if (options.model) argv[1].push("--model", String(options.model));
@@ -845,10 +861,10 @@ function startSession(message) {
845
861
  session.child = child;
846
862
 
847
863
  const opencodeLike = cli === "opencode" || cli === "codefree-o";
848
- const handler = cli === "claude" ? handleClaudeLine
864
+ const handler = (cli === "claude" || cli === "qwen") ? handleClaudeLine
849
865
  : cli === "codex" ? handleCodexLine
850
866
  : cli === "cursor" ? handleCursorLine
851
- : (cli === "gemini" || cli === "qwen" || cli === "iflow") ? handleGeminiLine
867
+ : (cli === "gemini" || cli === "iflow") ? handleGeminiLine
852
868
  : (session, obj, rawLine) => {
853
869
  // OpenCode / codefree-o:JSON 事件宽松解析;非 JSON 行按纯文本兜底(不支持 --format json 的版本)。
854
870
  if (obj) handleOpencodeLine(session, obj);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-lab-bridge",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "AI 开发平台设备桥接进程:反连平台 WebSocket,驱动本地 Claude Code / Codex CLI 执行任务并回传事件流",
5
5
  "license": "MIT",
6
6
  "files": [