claudish 3.0.2 → 3.0.4
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/dist/index.js +144 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -38305,19 +38305,105 @@ 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+(?:if|that|the|this|I\s+(?:need|should|will|have|already))/i,
|
|
38315
|
+
/^Wait[.!]?\s*$/i,
|
|
38316
|
+
/^Let\s+me\s+(think|check|verify|see|look|analyze|consider|first|start)/i,
|
|
38317
|
+
/^Let's\s+(check|see|look|start|first|try|think|verify|examine|analyze)/i,
|
|
38318
|
+
/^I\s+need\s+to\s+/i,
|
|
38319
|
+
/^O[kK](?:ay)?[.,!]?\s*(?:so|let|I|now|first)?/i,
|
|
38320
|
+
/^[Hh]mm+/,
|
|
38321
|
+
/^So[,.]?\s+(?:I|let|first|now|the)/i,
|
|
38322
|
+
/^(?:First|Next|Then|Now)[,.]?\s+(?:I|let|we)/i,
|
|
38323
|
+
/^(?:Thinking\s+about|Considering)/i,
|
|
38324
|
+
/^I(?:'ll|\s+will)\s+(?:first|now|start|begin|try|check|fix|look|examine|modify|create|update|read|investigate|adjust|improve|integrate|mark|also|verify|need|rethink|add|help|use|run|search|find|explore|analyze|review|test|implement|write|make|set|get|see|open|close|save|load|fetch|call|send|build|compile|execute|process|handle|parse|format|validate|clean|clear|remove|delete|move|copy|rename|install|configure|setup|initialize|prepare|work|continue|proceed|ensure|confirm)/i,
|
|
38325
|
+
/^I\s+should\s+/i,
|
|
38326
|
+
/^I\s+will\s+(?:first|now|start|verify|check|create|modify|look|need|also|add|help|use|run|search|find|explore|analyze|review|test|implement|write)/i,
|
|
38327
|
+
/^(?:Debug|Checking|Verifying|Looking\s+at):/i,
|
|
38328
|
+
/^I\s+also\s+(?:notice|need|see|want)/i,
|
|
38329
|
+
/^The\s+(?:goal|issue|problem|idea|plan)\s+is/i,
|
|
38330
|
+
/^In\s+the\s+(?:old|current|previous|new|existing)\s+/i,
|
|
38331
|
+
/^`[^`]+`\s+(?:is|has|does|needs|should|will|doesn't|hasn't)/i
|
|
38332
|
+
];
|
|
38333
|
+
REASONING_CONTINUATION_PATTERNS = [
|
|
38334
|
+
/^And\s+(?:then|I|now|so)/i,
|
|
38335
|
+
/^And\s+I(?:'ll|\s+will)/i,
|
|
38336
|
+
/^But\s+(?:I|first|wait|actually|the|if)/i,
|
|
38337
|
+
/^Actually[,.]?\s+/i,
|
|
38338
|
+
/^Also[,.]?\s+(?:I|the|check|note)/i,
|
|
38339
|
+
/^\d+\.\s+(?:I|First|Check|Run|Create|Update|Read|Modify|Add|Fix|Look)/i,
|
|
38340
|
+
/^-\s+(?:I|First|Check|Run|Create|Update|Read|Modify|Add|Fix)/i,
|
|
38341
|
+
/^Or\s+(?:I|just|we|maybe|perhaps)/i,
|
|
38342
|
+
/^Since\s+(?:I|the|this|we|it)/i,
|
|
38343
|
+
/^Because\s+(?:I|the|this|we|it)/i,
|
|
38344
|
+
/^If\s+(?:I|the|this|we|it)\s+/i,
|
|
38345
|
+
/^This\s+(?:is|means|requires|should|will|confirms|suggests)/i,
|
|
38346
|
+
/^That\s+(?:means|is|should|will|explains|confirms)/i,
|
|
38347
|
+
/^Lines?\s+\d+/i,
|
|
38348
|
+
/^The\s+`[^`]+`\s+(?:is|has|contains|needs|should)/i
|
|
38349
|
+
];
|
|
38312
38350
|
GeminiAdapter = class GeminiAdapter extends BaseModelAdapter {
|
|
38313
38351
|
thoughtSignatures = new Map;
|
|
38352
|
+
reasoningBuffer = [];
|
|
38353
|
+
inReasoningBlock = false;
|
|
38354
|
+
reasoningBlockDepth = 0;
|
|
38314
38355
|
processTextContent(textContent, accumulatedText) {
|
|
38356
|
+
if (!textContent || textContent.trim() === "") {
|
|
38357
|
+
return { cleanedText: textContent, extractedToolCalls: [], wasTransformed: false };
|
|
38358
|
+
}
|
|
38359
|
+
const lines = textContent.split(`
|
|
38360
|
+
`);
|
|
38361
|
+
const cleanedLines = [];
|
|
38362
|
+
let wasFiltered = false;
|
|
38363
|
+
for (const line of lines) {
|
|
38364
|
+
const trimmed = line.trim();
|
|
38365
|
+
if (!trimmed) {
|
|
38366
|
+
cleanedLines.push(line);
|
|
38367
|
+
continue;
|
|
38368
|
+
}
|
|
38369
|
+
const isReasoning = this.isReasoningLine(trimmed);
|
|
38370
|
+
if (isReasoning) {
|
|
38371
|
+
log(`[GeminiAdapter] Filtered reasoning: "${trimmed.substring(0, 50)}..."`);
|
|
38372
|
+
wasFiltered = true;
|
|
38373
|
+
this.inReasoningBlock = true;
|
|
38374
|
+
this.reasoningBlockDepth++;
|
|
38375
|
+
continue;
|
|
38376
|
+
}
|
|
38377
|
+
if (this.inReasoningBlock && this.isReasoningContinuation(trimmed)) {
|
|
38378
|
+
log(`[GeminiAdapter] Filtered reasoning continuation: "${trimmed.substring(0, 50)}..."`);
|
|
38379
|
+
wasFiltered = true;
|
|
38380
|
+
continue;
|
|
38381
|
+
}
|
|
38382
|
+
if (this.inReasoningBlock && trimmed.length > 20 && !this.isReasoningContinuation(trimmed)) {
|
|
38383
|
+
this.inReasoningBlock = false;
|
|
38384
|
+
this.reasoningBlockDepth = 0;
|
|
38385
|
+
}
|
|
38386
|
+
cleanedLines.push(line);
|
|
38387
|
+
}
|
|
38388
|
+
const cleanedText = cleanedLines.join(`
|
|
38389
|
+
`);
|
|
38315
38390
|
return {
|
|
38316
|
-
cleanedText: textContent,
|
|
38391
|
+
cleanedText: wasFiltered ? cleanedText : textContent,
|
|
38317
38392
|
extractedToolCalls: [],
|
|
38318
|
-
wasTransformed:
|
|
38393
|
+
wasTransformed: wasFiltered
|
|
38319
38394
|
};
|
|
38320
38395
|
}
|
|
38396
|
+
isReasoningLine(line) {
|
|
38397
|
+
return REASONING_PATTERNS.some((pattern) => pattern.test(line));
|
|
38398
|
+
}
|
|
38399
|
+
isReasoningContinuation(line) {
|
|
38400
|
+
return REASONING_CONTINUATION_PATTERNS.some((pattern) => pattern.test(line));
|
|
38401
|
+
}
|
|
38402
|
+
resetReasoningState() {
|
|
38403
|
+
this.reasoningBuffer = [];
|
|
38404
|
+
this.inReasoningBlock = false;
|
|
38405
|
+
this.reasoningBlockDepth = 0;
|
|
38406
|
+
}
|
|
38321
38407
|
prepareRequest(request, originalRequest) {
|
|
38322
38408
|
if (originalRequest.thinking) {
|
|
38323
38409
|
const { budget_tokens } = originalRequest.thinking;
|
|
@@ -38362,6 +38448,7 @@ var init_gemini_adapter = __esm(() => {
|
|
|
38362
38448
|
}
|
|
38363
38449
|
reset() {
|
|
38364
38450
|
this.thoughtSignatures.clear();
|
|
38451
|
+
this.resetReasoningState();
|
|
38365
38452
|
}
|
|
38366
38453
|
shouldHandle(modelId) {
|
|
38367
38454
|
return modelId.includes("gemini") || modelId.includes("google/");
|
|
@@ -39953,6 +40040,21 @@ class OpenRouterHandler {
|
|
|
39953
40040
|
else
|
|
39954
40041
|
messages.unshift({ role: "system", content: msg });
|
|
39955
40042
|
}
|
|
40043
|
+
if (modelId.includes("gemini") || modelId.includes("google/")) {
|
|
40044
|
+
const geminiMsg = `CRITICAL INSTRUCTION FOR OUTPUT FORMAT:
|
|
40045
|
+
1. Keep ALL internal reasoning INTERNAL. Never output your thought process as visible text.
|
|
40046
|
+
2. Do NOT start responses with phrases like "Wait, I'm...", "Let me think...", "Okay, so...", "First, I need to..."
|
|
40047
|
+
3. Do NOT output numbered planning steps or internal debugging statements.
|
|
40048
|
+
4. Only output: final responses, tool calls, and code. Nothing else.
|
|
40049
|
+
5. When calling tools, proceed directly without announcing your intentions.
|
|
40050
|
+
6. Your internal thinking should use the reasoning/thinking API, not visible text output.`;
|
|
40051
|
+
if (messages.length > 0 && messages[0].role === "system")
|
|
40052
|
+
messages[0].content += `
|
|
40053
|
+
|
|
40054
|
+
` + geminiMsg;
|
|
40055
|
+
else
|
|
40056
|
+
messages.unshift({ role: "system", content: geminiMsg });
|
|
40057
|
+
}
|
|
39956
40058
|
if (req.messages) {
|
|
39957
40059
|
for (const msg of req.messages) {
|
|
39958
40060
|
if (msg.role === "user")
|
|
@@ -40055,13 +40157,14 @@ data: ${JSON.stringify(d)}
|
|
|
40055
40157
|
let finalized = false;
|
|
40056
40158
|
let textStarted = false;
|
|
40057
40159
|
let textIdx = -1;
|
|
40058
|
-
let
|
|
40059
|
-
let
|
|
40160
|
+
let thinkingStarted = false;
|
|
40161
|
+
let thinkingIdx = -1;
|
|
40060
40162
|
let curIdx = 0;
|
|
40061
40163
|
const tools = new Map;
|
|
40062
40164
|
const toolIds = new Set;
|
|
40063
40165
|
let accTxt = 0;
|
|
40064
40166
|
let lastActivity = Date.now();
|
|
40167
|
+
let accumulatedThinking = "";
|
|
40065
40168
|
send("message_start", {
|
|
40066
40169
|
type: "message_start",
|
|
40067
40170
|
message: {
|
|
@@ -40084,9 +40187,9 @@ data: ${JSON.stringify(d)}
|
|
|
40084
40187
|
if (finalized)
|
|
40085
40188
|
return;
|
|
40086
40189
|
finalized = true;
|
|
40087
|
-
if (
|
|
40088
|
-
send("content_block_stop", { type: "content_block_stop", index:
|
|
40089
|
-
|
|
40190
|
+
if (thinkingStarted) {
|
|
40191
|
+
send("content_block_stop", { type: "content_block_stop", index: thinkingIdx });
|
|
40192
|
+
thinkingStarted = false;
|
|
40090
40193
|
}
|
|
40091
40194
|
if (textStarted) {
|
|
40092
40195
|
send("content_block_stop", { type: "content_block_stop", index: textIdx });
|
|
@@ -40160,9 +40263,38 @@ data: ${JSON.stringify(d)}
|
|
|
40160
40263
|
delta,
|
|
40161
40264
|
metadata: streamMetadata
|
|
40162
40265
|
});
|
|
40266
|
+
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
40267
|
+
for (const detail of delta.reasoning_details) {
|
|
40268
|
+
if (detail.type === "reasoning.text" || detail.type === "reasoning.summary") {
|
|
40269
|
+
const thinkingContent = detail.content || detail.text || detail.summary || "";
|
|
40270
|
+
if (thinkingContent) {
|
|
40271
|
+
lastActivity = Date.now();
|
|
40272
|
+
if (!thinkingStarted) {
|
|
40273
|
+
thinkingIdx = curIdx++;
|
|
40274
|
+
send("content_block_start", {
|
|
40275
|
+
type: "content_block_start",
|
|
40276
|
+
index: thinkingIdx,
|
|
40277
|
+
content_block: { type: "thinking", thinking: "" }
|
|
40278
|
+
});
|
|
40279
|
+
thinkingStarted = true;
|
|
40280
|
+
}
|
|
40281
|
+
send("content_block_delta", {
|
|
40282
|
+
type: "content_block_delta",
|
|
40283
|
+
index: thinkingIdx,
|
|
40284
|
+
delta: { type: "thinking_delta", thinking: thinkingContent }
|
|
40285
|
+
});
|
|
40286
|
+
accumulatedThinking += thinkingContent;
|
|
40287
|
+
}
|
|
40288
|
+
}
|
|
40289
|
+
}
|
|
40290
|
+
}
|
|
40163
40291
|
const txt = delta.content || "";
|
|
40164
40292
|
if (txt) {
|
|
40165
40293
|
lastActivity = Date.now();
|
|
40294
|
+
if (thinkingStarted) {
|
|
40295
|
+
send("content_block_stop", { type: "content_block_stop", index: thinkingIdx });
|
|
40296
|
+
thinkingStarted = false;
|
|
40297
|
+
}
|
|
40166
40298
|
if (!textStarted) {
|
|
40167
40299
|
textIdx = curIdx++;
|
|
40168
40300
|
send("content_block_start", { type: "content_block_start", index: textIdx, content_block: { type: "text", text: "" } });
|
|
@@ -40178,6 +40310,10 @@ data: ${JSON.stringify(d)}
|
|
|
40178
40310
|
let t = tools.get(idx);
|
|
40179
40311
|
if (tc.function?.name) {
|
|
40180
40312
|
if (!t) {
|
|
40313
|
+
if (thinkingStarted) {
|
|
40314
|
+
send("content_block_stop", { type: "content_block_stop", index: thinkingIdx });
|
|
40315
|
+
thinkingStarted = false;
|
|
40316
|
+
}
|
|
40181
40317
|
if (textStarted) {
|
|
40182
40318
|
send("content_block_stop", { type: "content_block_stop", index: textIdx });
|
|
40183
40319
|
textStarted = false;
|