claudish 7.12.3 → 7.12.5

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/dist/index.js +125 -52
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -581,7 +581,7 @@ var init_onepassword_config = __esm(() => {
581
581
  });
582
582
 
583
583
  // src/version.ts
584
- var VERSION = "7.12.3";
584
+ var VERSION = "7.12.5";
585
585
 
586
586
  // src/logger.ts
587
587
  var exports_logger = {};
@@ -30918,11 +30918,18 @@ ${msg}`;
30918
30918
  }
30919
30919
  return messages;
30920
30920
  }
30921
+ function imageBlockToUrlPart(block) {
30922
+ return {
30923
+ type: "image_url",
30924
+ image_url: { url: `data:${block.source.media_type};base64,${block.source.data}` }
30925
+ };
30926
+ }
30921
30927
  function processUserMessage(msg, messages, simpleFormat = false) {
30922
30928
  if (Array.isArray(msg.content)) {
30923
30929
  const textParts = [];
30924
30930
  const contentParts = [];
30925
30931
  const toolResults = [];
30932
+ const toolResultImages = [];
30926
30933
  const seen = new Set;
30927
30934
  for (const block of msg.content) {
30928
30935
  if (block.type === "text") {
@@ -30932,22 +30939,45 @@ function processUserMessage(msg, messages, simpleFormat = false) {
30932
30939
  }
30933
30940
  } else if (block.type === "image") {
30934
30941
  if (!simpleFormat) {
30935
- contentParts.push({
30936
- type: "image_url",
30937
- image_url: { url: `data:${block.source.media_type};base64,${block.source.data}` }
30938
- });
30942
+ contentParts.push(imageBlockToUrlPart(block));
30939
30943
  }
30940
30944
  } else if (block.type === "tool_result") {
30941
30945
  if (seen.has(block.tool_use_id))
30942
30946
  continue;
30943
30947
  seen.add(block.tool_use_id);
30944
- const resultContent = typeof block.content === "string" ? block.content : JSON.stringify(block.content);
30948
+ let resultText;
30949
+ if (typeof block.content === "string") {
30950
+ resultText = block.content;
30951
+ } else if (Array.isArray(block.content)) {
30952
+ const texts = [];
30953
+ const others = [];
30954
+ for (const inner of block.content) {
30955
+ if (inner.type === "text") {
30956
+ texts.push(inner.text);
30957
+ } else if (inner.type === "image" && inner.source) {
30958
+ if (!simpleFormat)
30959
+ toolResultImages.push(imageBlockToUrlPart(inner));
30960
+ } else {
30961
+ others.push(inner);
30962
+ }
30963
+ }
30964
+ resultText = texts.join(`
30965
+ `);
30966
+ if (others.length)
30967
+ resultText += (resultText ? `
30968
+ ` : "") + JSON.stringify(others);
30969
+ if (!resultText) {
30970
+ resultText = toolResultImages.length ? "[image returned; see following message]" : "";
30971
+ }
30972
+ } else {
30973
+ resultText = JSON.stringify(block.content);
30974
+ }
30945
30975
  if (simpleFormat) {
30946
- textParts.push(`[Tool Result]: ${resultContent}`);
30976
+ textParts.push(`[Tool Result]: ${resultText}`);
30947
30977
  } else {
30948
30978
  toolResults.push({
30949
30979
  role: "tool",
30950
- content: resultContent,
30980
+ content: resultText,
30951
30981
  tool_call_id: block.tool_use_id
30952
30982
  });
30953
30983
  }
@@ -30962,6 +30992,8 @@ function processUserMessage(msg, messages, simpleFormat = false) {
30962
30992
  } else {
30963
30993
  if (toolResults.length)
30964
30994
  messages.push(...toolResults);
30995
+ if (toolResultImages.length)
30996
+ messages.push({ role: "user", content: toolResultImages });
30965
30997
  if (contentParts.length)
30966
30998
  messages.push({ role: "user", content: contentParts });
30967
30999
  }
@@ -38113,15 +38145,18 @@ function createResponsesStreamHandler(c, response, opts) {
38113
38145
  const encoder = new TextEncoder;
38114
38146
  const decoder = new TextDecoder;
38115
38147
  let buffer = "";
38116
- let blockIndex = 0;
38148
+ let curIdx = 0;
38149
+ let textIdx = -1;
38150
+ let reasoningIdx = -1;
38151
+ let lastSummaryIndex = -1;
38117
38152
  let inputTokens = 0;
38118
38153
  let outputTokens = 0;
38119
- let hasTextContent = false;
38120
38154
  let hasToolUse = false;
38121
38155
  let lastActivity = Date.now();
38122
38156
  let pingInterval = null;
38123
38157
  let isClosed = false;
38124
38158
  const functionCalls = new Map;
38159
+ const openToolBlocks = new Set;
38125
38160
  const stream = new ReadableStream({
38126
38161
  start: async (controller) => {
38127
38162
  const send = (event, data) => {
@@ -38132,6 +38167,24 @@ data: ${JSON.stringify(data)}
38132
38167
  `));
38133
38168
  }
38134
38169
  };
38170
+ const closeReasoning = () => {
38171
+ if (reasoningIdx >= 0) {
38172
+ send("content_block_stop", { type: "content_block_stop", index: reasoningIdx });
38173
+ reasoningIdx = -1;
38174
+ }
38175
+ };
38176
+ const closeText = () => {
38177
+ if (textIdx >= 0) {
38178
+ send("content_block_stop", { type: "content_block_stop", index: textIdx });
38179
+ textIdx = -1;
38180
+ }
38181
+ };
38182
+ const closeTools = () => {
38183
+ for (const fnCall of openToolBlocks) {
38184
+ send("content_block_stop", { type: "content_block_stop", index: fnCall.index });
38185
+ }
38186
+ openToolBlocks.clear();
38187
+ };
38135
38188
  send("message_start", {
38136
38189
  type: "message_start",
38137
38190
  message: {
@@ -38169,23 +38222,27 @@ data: ${JSON.stringify(data)}
38169
38222
  const data = line.slice(6);
38170
38223
  if (data === "[DONE]")
38171
38224
  continue;
38225
+ if (getLogLevel() === "debug") {
38226
+ log(`[SSE:responses] ${data.substring(0, 300)}`);
38227
+ }
38172
38228
  try {
38173
38229
  const event = JSON.parse(data);
38174
38230
  if (getLogLevel() === "debug" && event.type) {
38175
38231
  log(`[ResponsesSSE] Event: ${event.type}`);
38176
38232
  }
38177
38233
  if (event.type === "response.output_text.delta") {
38178
- if (!hasTextContent) {
38234
+ closeReasoning();
38235
+ if (textIdx < 0) {
38236
+ textIdx = curIdx++;
38179
38237
  send("content_block_start", {
38180
38238
  type: "content_block_start",
38181
- index: blockIndex,
38239
+ index: textIdx,
38182
38240
  content_block: { type: "text", text: "" }
38183
38241
  });
38184
- hasTextContent = true;
38185
38242
  }
38186
38243
  send("content_block_delta", {
38187
38244
  type: "content_block_delta",
38188
- index: blockIndex,
38245
+ index: textIdx,
38189
38246
  delta: { type: "text_delta", text: event.delta || "" }
38190
38247
  });
38191
38248
  } else if (event.type === "response.output_item.added") {
@@ -38195,41 +38252,51 @@ data: ${JSON.stringify(data)}
38195
38252
  const callId = openaiCallId.startsWith("toolu_") ? openaiCallId : `toolu_${openaiCallId.replace(/^fc_/, "")}`;
38196
38253
  const rawFnName = event.item.name || "";
38197
38254
  const fnName = opts.toolNameMap?.get(rawFnName) || rawFnName;
38198
- const fnIndex = blockIndex + functionCalls.size + (hasTextContent ? 1 : 0);
38255
+ closeReasoning();
38256
+ closeText();
38199
38257
  const fnCallData = {
38200
38258
  name: fnName,
38201
38259
  arguments: "",
38202
- index: fnIndex,
38260
+ index: curIdx++,
38203
38261
  claudeId: callId
38204
38262
  };
38205
38263
  functionCalls.set(openaiCallId, fnCallData);
38206
38264
  if (itemId && itemId !== openaiCallId) {
38207
38265
  functionCalls.set(itemId, fnCallData);
38208
38266
  }
38209
- if (hasTextContent && !hasToolUse) {
38210
- send("content_block_stop", { type: "content_block_stop", index: blockIndex });
38211
- blockIndex++;
38212
- }
38267
+ openToolBlocks.add(fnCallData);
38213
38268
  send("content_block_start", {
38214
38269
  type: "content_block_start",
38215
- index: fnIndex,
38270
+ index: fnCallData.index,
38216
38271
  content_block: { type: "tool_use", id: callId, name: fnName, input: {} }
38217
38272
  });
38218
38273
  hasToolUse = true;
38219
38274
  }
38220
38275
  } else if (event.type === "response.reasoning_summary_text.delta") {
38221
- if (!hasTextContent) {
38276
+ const summaryIndex = typeof event.summary_index === "number" ? event.summary_index : 0;
38277
+ if (reasoningIdx < 0) {
38278
+ closeText();
38279
+ reasoningIdx = curIdx++;
38280
+ lastSummaryIndex = summaryIndex;
38222
38281
  send("content_block_start", {
38223
38282
  type: "content_block_start",
38224
- index: blockIndex,
38225
- content_block: { type: "text", text: "" }
38283
+ index: reasoningIdx,
38284
+ content_block: { type: "thinking", thinking: "" }
38285
+ });
38286
+ } else if (summaryIndex !== lastSummaryIndex) {
38287
+ lastSummaryIndex = summaryIndex;
38288
+ send("content_block_delta", {
38289
+ type: "content_block_delta",
38290
+ index: reasoningIdx,
38291
+ delta: { type: "thinking_delta", thinking: `
38292
+
38293
+ ` }
38226
38294
  });
38227
- hasTextContent = true;
38228
38295
  }
38229
38296
  send("content_block_delta", {
38230
38297
  type: "content_block_delta",
38231
- index: blockIndex,
38232
- delta: { type: "text_delta", text: event.delta || "" }
38298
+ index: reasoningIdx,
38299
+ delta: { type: "thinking_delta", thinking: event.delta || "" }
38233
38300
  });
38234
38301
  } else if (event.type === "response.function_call_arguments.delta") {
38235
38302
  const callId = event.call_id || event.item_id;
@@ -38246,8 +38313,9 @@ data: ${JSON.stringify(data)}
38246
38313
  if (event.item?.type === "function_call") {
38247
38314
  const callId = event.item.call_id || event.item.id;
38248
38315
  const fnCall = functionCalls.get(callId) || functionCalls.get(event.item.id);
38249
- if (fnCall) {
38316
+ if (fnCall && openToolBlocks.has(fnCall)) {
38250
38317
  send("content_block_stop", { type: "content_block_stop", index: fnCall.index });
38318
+ openToolBlocks.delete(fnCall);
38251
38319
  }
38252
38320
  }
38253
38321
  } else if (event.type === "response.incomplete") {
@@ -38269,14 +38337,10 @@ data: ${JSON.stringify(data)}
38269
38337
  const errMsg = err.message || event.message || "Unknown API error";
38270
38338
  const errCode = err.code || event.code || "";
38271
38339
  log(`[ResponsesSSE] API error: ${errCode} - ${errMsg}`);
38272
- if (hasTextContent) {
38273
- send("content_block_stop", { type: "content_block_stop", index: blockIndex });
38274
- hasTextContent = false;
38275
- }
38276
- for (const [, fnCall] of functionCalls) {
38277
- send("content_block_stop", { type: "content_block_stop", index: fnCall.index });
38278
- }
38279
- const errorIdx = blockIndex + functionCalls.size + (hasToolUse ? 1 : 0);
38340
+ closeReasoning();
38341
+ closeText();
38342
+ closeTools();
38343
+ const errorIdx = curIdx++;
38280
38344
  send("content_block_start", {
38281
38345
  type: "content_block_start",
38282
38346
  index: errorIdx,
@@ -38315,9 +38379,9 @@ data: ${JSON.stringify(data)}
38315
38379
  clearInterval(pingInterval);
38316
38380
  pingInterval = null;
38317
38381
  }
38318
- if (hasTextContent) {
38319
- send("content_block_stop", { type: "content_block_stop", index: blockIndex });
38320
- }
38382
+ closeReasoning();
38383
+ closeText();
38384
+ closeTools();
38321
38385
  const stopReason = hasToolUse ? "tool_use" : "end_turn";
38322
38386
  send("message_delta", {
38323
38387
  type: "message_delta",
@@ -38337,13 +38401,10 @@ data: ${JSON.stringify(data)}
38337
38401
  log(`[ResponsesSSE] Stream error: ${error46}`);
38338
38402
  if (!isClosed) {
38339
38403
  try {
38340
- if (hasTextContent) {
38341
- send("content_block_stop", { type: "content_block_stop", index: blockIndex });
38342
- }
38343
- for (const [, fnCall] of functionCalls) {
38344
- send("content_block_stop", { type: "content_block_stop", index: fnCall.index });
38345
- }
38346
- const errorIdx = blockIndex + functionCalls.size + (hasToolUse ? 1 : 0);
38404
+ closeReasoning();
38405
+ closeText();
38406
+ closeTools();
38407
+ const errorIdx = curIdx++;
38347
38408
  send("content_block_start", {
38348
38409
  type: "content_block_start",
38349
38410
  index: errorIdx,
@@ -62374,6 +62435,7 @@ async function parseArgs(args) {
62374
62435
  config3.quiet = true;
62375
62436
  } else if (arg === "--verbose" || arg === "-v") {
62376
62437
  config3.quiet = false;
62438
+ config3._sawVerbose = true;
62377
62439
  } else if (arg === "--json") {
62378
62440
  config3.jsonOutput = true;
62379
62441
  } else if (arg === "--monitor") {
@@ -62572,6 +62634,9 @@ Usage: claudish --models --provider <slug>`);
62572
62634
  if (!config3._hasPositionalPrompt && !config3.stdin && !config3._hasPrintFlag) {
62573
62635
  config3.interactive = true;
62574
62636
  }
62637
+ if (config3._sawVerbose && !config3.interactive && !config3.claudeArgs.includes("--verbose") && !config3.claudeArgs.includes("-v")) {
62638
+ config3.claudeArgs.push("--verbose");
62639
+ }
62575
62640
  if (config3.monitor) {
62576
62641
  if (process.env.ANTHROPIC_API_KEY?.includes("placeholder")) {
62577
62642
  delete process.env.ANTHROPIC_API_KEY;
@@ -71331,7 +71396,9 @@ async function runClaudeWithProxy(config3, proxyUrl, onCleanup) {
71331
71396
  }
71332
71397
  claudeArgs.push(...config3.claudeArgs);
71333
71398
  } else {
71334
- claudeArgs.push("-p");
71399
+ if (!config3.claudeArgs.includes("-p") && !config3.claudeArgs.includes("--print")) {
71400
+ claudeArgs.push("-p");
71401
+ }
71335
71402
  if (config3.autoApprove) {
71336
71403
  claudeArgs.push("--dangerously-skip-permissions");
71337
71404
  }
@@ -71371,7 +71438,11 @@ async function runClaudeWithProxy(config3, proxyUrl, onCleanup) {
71371
71438
  }
71372
71439
  const log2 = (message) => {
71373
71440
  if (!config3.quiet) {
71374
- console.log(message);
71441
+ if (config3.interactive) {
71442
+ console.log(message);
71443
+ } else {
71444
+ console.error(message);
71445
+ }
71375
71446
  }
71376
71447
  };
71377
71448
  if (!config3.monitor && hasNativeAnthropicMapping(config3)) {
@@ -71448,7 +71519,7 @@ function setupSignalHandlers(proc, tempSettingsPath, quiet, onCleanup) {
71448
71519
  for (const signal of signals2) {
71449
71520
  process.on(signal, () => {
71450
71521
  if (!quiet) {
71451
- console.log(`
71522
+ console.error(`
71452
71523
  [claudish] Received ${signal}, shutting down...`);
71453
71524
  }
71454
71525
  proc.kill();
@@ -72336,7 +72407,7 @@ Team Status`);
72336
72407
  }
72337
72408
  const rawArgs = process.argv.slice(2);
72338
72409
  const explicitNoAutoApprove = rawArgs.includes("--no-auto-approve");
72339
- if (cliConfig.autoApprove && !explicitNoAutoApprove && !cliConfig.stdin) {
72410
+ if (cliConfig.autoApprove && !explicitNoAutoApprove && !cliConfig.stdin && cliConfig.interactive) {
72340
72411
  const { loadConfig: loadConfig2, saveConfig: saveConfig2 } = await Promise.resolve().then(() => (init_profile_config(), exports_profile_config));
72341
72412
  try {
72342
72413
  const cfg = loadConfig2();
@@ -72503,13 +72574,15 @@ Team Status`);
72503
72574
  setDiagOutput2(null);
72504
72575
  diag.cleanup();
72505
72576
  if (!cliConfig.quiet) {
72506
- console.log(`
72577
+ const write = cliConfig.interactive ? console.log : console.error;
72578
+ write(`
72507
72579
  [claudish] Shutting down proxy server...`);
72508
72580
  }
72509
72581
  await proxy.shutdown();
72510
72582
  }
72511
72583
  if (!cliConfig.quiet) {
72512
- console.log(`[claudish] Done
72584
+ const write = cliConfig.interactive ? console.log : console.error;
72585
+ write(`[claudish] Done
72513
72586
  `);
72514
72587
  }
72515
72588
  const sessionLogPath = getAlwaysOnLogPath2();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claudish",
3
- "version": "7.12.3",
3
+ "version": "7.12.5",
4
4
  "description": "Run Claude Code with any model - OpenRouter, Ollama, LM Studio & local models",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -60,10 +60,10 @@
60
60
  "ai"
61
61
  ],
62
62
  "optionalDependencies": {
63
- "@claudish/magmux-darwin-arm64": "7.12.3",
64
- "@claudish/magmux-darwin-x64": "7.12.3",
65
- "@claudish/magmux-linux-arm64": "7.12.3",
66
- "@claudish/magmux-linux-x64": "7.12.3"
63
+ "@claudish/magmux-darwin-arm64": "7.12.5",
64
+ "@claudish/magmux-darwin-x64": "7.12.5",
65
+ "@claudish/magmux-linux-arm64": "7.12.5",
66
+ "@claudish/magmux-linux-x64": "7.12.5"
67
67
  },
68
68
  "author": "Jack Rudenko <i@madappgang.com>",
69
69
  "license": "MIT",