claudish 3.0.2 → 3.0.3

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 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -38305,19 +38305,86 @@ var init_grok_adapter = __esm(() => {
38305
38305
  });
38306
38306
 
38307
38307
  // src/adapters/gemini-adapter.ts
38308
- var GeminiAdapter;
38308
+ var REASONING_PATTERNS, REASONING_CONTINUATION_PATTERNS, GeminiAdapter;
38309
38309
  var init_gemini_adapter = __esm(() => {
38310
38310
  init_base_adapter();
38311
38311
  init_logger();
38312
+ REASONING_PATTERNS = [
38313
+ /^Wait,?\s+I(?:'m|\s+am)\s+\w+ing\b/i,
38314
+ /^Wait[.!]?\s*$/i,
38315
+ /^Let\s+me\s+(think|check|verify|see|look|analyze|consider)/i,
38316
+ /^I\s+need\s+to\s+/i,
38317
+ /^O[kK](?:ay)?[.,!]?\s*(?:so|let|I|now|first)?/i,
38318
+ /^[Hh]mm+/,
38319
+ /^So[,.]?\s+(?:I|let|first|now|the)/i,
38320
+ /^(?:First|Next|Then|Now)[,.]?\s+(?:I|let|we)/i,
38321
+ /^(?:Thinking\s+about|Considering)/i,
38322
+ /^I(?:'ll|\s+will|\s+should)\s+(?:first|now|start|begin|try)/i,
38323
+ /^(?:Debug|Checking|Verifying|Looking\s+at):/i
38324
+ ];
38325
+ REASONING_CONTINUATION_PATTERNS = [
38326
+ /^And\s+(?:then|I|now|so)/i,
38327
+ /^But\s+(?:I|first|wait|actually)/i,
38328
+ /^Actually[,.]?\s+/i,
38329
+ /^\d+\.\s+(?:I|First|Check|Run|Create|Update|Read)/i
38330
+ ];
38312
38331
  GeminiAdapter = class GeminiAdapter extends BaseModelAdapter {
38313
38332
  thoughtSignatures = new Map;
38333
+ reasoningBuffer = [];
38334
+ inReasoningBlock = false;
38335
+ reasoningBlockDepth = 0;
38314
38336
  processTextContent(textContent, accumulatedText) {
38337
+ if (!textContent || textContent.trim() === "") {
38338
+ return { cleanedText: textContent, extractedToolCalls: [], wasTransformed: false };
38339
+ }
38340
+ const lines = textContent.split(`
38341
+ `);
38342
+ const cleanedLines = [];
38343
+ let wasFiltered = false;
38344
+ for (const line of lines) {
38345
+ const trimmed = line.trim();
38346
+ if (!trimmed) {
38347
+ cleanedLines.push(line);
38348
+ continue;
38349
+ }
38350
+ const isReasoning = this.isReasoningLine(trimmed);
38351
+ if (isReasoning) {
38352
+ log(`[GeminiAdapter] Filtered reasoning: "${trimmed.substring(0, 50)}..."`);
38353
+ wasFiltered = true;
38354
+ this.inReasoningBlock = true;
38355
+ this.reasoningBlockDepth++;
38356
+ continue;
38357
+ }
38358
+ if (this.inReasoningBlock && this.isReasoningContinuation(trimmed)) {
38359
+ log(`[GeminiAdapter] Filtered reasoning continuation: "${trimmed.substring(0, 50)}..."`);
38360
+ wasFiltered = true;
38361
+ continue;
38362
+ }
38363
+ if (this.inReasoningBlock && trimmed.length > 20 && !this.isReasoningContinuation(trimmed)) {
38364
+ this.inReasoningBlock = false;
38365
+ this.reasoningBlockDepth = 0;
38366
+ }
38367
+ cleanedLines.push(line);
38368
+ }
38369
+ const cleanedText = cleanedLines.join(`
38370
+ `);
38315
38371
  return {
38316
- cleanedText: textContent,
38372
+ cleanedText: wasFiltered ? cleanedText : textContent,
38317
38373
  extractedToolCalls: [],
38318
- wasTransformed: false
38374
+ wasTransformed: wasFiltered
38319
38375
  };
38320
38376
  }
38377
+ isReasoningLine(line) {
38378
+ return REASONING_PATTERNS.some((pattern) => pattern.test(line));
38379
+ }
38380
+ isReasoningContinuation(line) {
38381
+ return REASONING_CONTINUATION_PATTERNS.some((pattern) => pattern.test(line));
38382
+ }
38383
+ resetReasoningState() {
38384
+ this.reasoningBuffer = [];
38385
+ this.inReasoningBlock = false;
38386
+ this.reasoningBlockDepth = 0;
38387
+ }
38321
38388
  prepareRequest(request, originalRequest) {
38322
38389
  if (originalRequest.thinking) {
38323
38390
  const { budget_tokens } = originalRequest.thinking;
@@ -38362,6 +38429,7 @@ var init_gemini_adapter = __esm(() => {
38362
38429
  }
38363
38430
  reset() {
38364
38431
  this.thoughtSignatures.clear();
38432
+ this.resetReasoningState();
38365
38433
  }
38366
38434
  shouldHandle(modelId) {
38367
38435
  return modelId.includes("gemini") || modelId.includes("google/");
@@ -39953,6 +40021,21 @@ class OpenRouterHandler {
39953
40021
  else
39954
40022
  messages.unshift({ role: "system", content: msg });
39955
40023
  }
40024
+ if (modelId.includes("gemini") || modelId.includes("google/")) {
40025
+ const geminiMsg = `CRITICAL INSTRUCTION FOR OUTPUT FORMAT:
40026
+ 1. Keep ALL internal reasoning INTERNAL. Never output your thought process as visible text.
40027
+ 2. Do NOT start responses with phrases like "Wait, I'm...", "Let me think...", "Okay, so...", "First, I need to..."
40028
+ 3. Do NOT output numbered planning steps or internal debugging statements.
40029
+ 4. Only output: final responses, tool calls, and code. Nothing else.
40030
+ 5. When calling tools, proceed directly without announcing your intentions.
40031
+ 6. Your internal thinking should use the reasoning/thinking API, not visible text output.`;
40032
+ if (messages.length > 0 && messages[0].role === "system")
40033
+ messages[0].content += `
40034
+
40035
+ ` + geminiMsg;
40036
+ else
40037
+ messages.unshift({ role: "system", content: geminiMsg });
40038
+ }
39956
40039
  if (req.messages) {
39957
40040
  for (const msg of req.messages) {
39958
40041
  if (msg.role === "user")
@@ -40055,13 +40138,14 @@ data: ${JSON.stringify(d)}
40055
40138
  let finalized = false;
40056
40139
  let textStarted = false;
40057
40140
  let textIdx = -1;
40058
- let reasoningStarted = false;
40059
- let reasoningIdx = -1;
40141
+ let thinkingStarted = false;
40142
+ let thinkingIdx = -1;
40060
40143
  let curIdx = 0;
40061
40144
  const tools = new Map;
40062
40145
  const toolIds = new Set;
40063
40146
  let accTxt = 0;
40064
40147
  let lastActivity = Date.now();
40148
+ let accumulatedThinking = "";
40065
40149
  send("message_start", {
40066
40150
  type: "message_start",
40067
40151
  message: {
@@ -40084,9 +40168,9 @@ data: ${JSON.stringify(d)}
40084
40168
  if (finalized)
40085
40169
  return;
40086
40170
  finalized = true;
40087
- if (reasoningStarted) {
40088
- send("content_block_stop", { type: "content_block_stop", index: reasoningIdx });
40089
- reasoningStarted = false;
40171
+ if (thinkingStarted) {
40172
+ send("content_block_stop", { type: "content_block_stop", index: thinkingIdx });
40173
+ thinkingStarted = false;
40090
40174
  }
40091
40175
  if (textStarted) {
40092
40176
  send("content_block_stop", { type: "content_block_stop", index: textIdx });
@@ -40160,9 +40244,38 @@ data: ${JSON.stringify(d)}
40160
40244
  delta,
40161
40245
  metadata: streamMetadata
40162
40246
  });
40247
+ if (delta.reasoning_details && delta.reasoning_details.length > 0) {
40248
+ for (const detail of delta.reasoning_details) {
40249
+ if (detail.type === "reasoning.text" || detail.type === "reasoning.summary") {
40250
+ const thinkingContent = detail.content || detail.text || detail.summary || "";
40251
+ if (thinkingContent) {
40252
+ lastActivity = Date.now();
40253
+ if (!thinkingStarted) {
40254
+ thinkingIdx = curIdx++;
40255
+ send("content_block_start", {
40256
+ type: "content_block_start",
40257
+ index: thinkingIdx,
40258
+ content_block: { type: "thinking", thinking: "" }
40259
+ });
40260
+ thinkingStarted = true;
40261
+ }
40262
+ send("content_block_delta", {
40263
+ type: "content_block_delta",
40264
+ index: thinkingIdx,
40265
+ delta: { type: "thinking_delta", thinking: thinkingContent }
40266
+ });
40267
+ accumulatedThinking += thinkingContent;
40268
+ }
40269
+ }
40270
+ }
40271
+ }
40163
40272
  const txt = delta.content || "";
40164
40273
  if (txt) {
40165
40274
  lastActivity = Date.now();
40275
+ if (thinkingStarted) {
40276
+ send("content_block_stop", { type: "content_block_stop", index: thinkingIdx });
40277
+ thinkingStarted = false;
40278
+ }
40166
40279
  if (!textStarted) {
40167
40280
  textIdx = curIdx++;
40168
40281
  send("content_block_start", { type: "content_block_start", index: textIdx, content_block: { type: "text", text: "" } });
@@ -40178,6 +40291,10 @@ data: ${JSON.stringify(d)}
40178
40291
  let t = tools.get(idx);
40179
40292
  if (tc.function?.name) {
40180
40293
  if (!t) {
40294
+ if (thinkingStarted) {
40295
+ send("content_block_stop", { type: "content_block_stop", index: thinkingIdx });
40296
+ thinkingStarted = false;
40297
+ }
40181
40298
  if (textStarted) {
40182
40299
  send("content_block_stop", { type: "content_block_stop", index: textIdx });
40183
40300
  textStarted = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claudish",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
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",