cascade-ai 0.2.11 → 0.2.12

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.cjs CHANGED
@@ -165,7 +165,7 @@ var require_keytar2 = __commonJS({
165
165
  });
166
166
 
167
167
  // src/constants.ts
168
- var CASCADE_VERSION = "0.2.11";
168
+ var CASCADE_VERSION = "0.2.12";
169
169
  var CASCADE_CONFIG_DIR = ".cascade";
170
170
  var CASCADE_MD_FILE = "CASCADE.md";
171
171
  var CASCADE_IGNORE_FILE = ".cascadeignore";
@@ -547,17 +547,38 @@ var AnthropicProvider = class extends BaseProvider {
547
547
  messages,
548
548
  tools: tools?.length ? tools : void 0
549
549
  });
550
+ let isThinking = false;
550
551
  for await (const event of stream) {
551
- if (event.type === "content_block_delta" && event.delta.type === "text_delta") {
552
- const text = event.delta.text;
553
- fullContent += text;
554
- onChunk({ text, finishReason: null });
552
+ if (event.type === "content_block_delta") {
553
+ if (event.delta.type === "thinking_delta") {
554
+ if (!isThinking) {
555
+ isThinking = true;
556
+ fullContent += "<think>\n";
557
+ onChunk({ text: "<think>\n", finishReason: null });
558
+ }
559
+ const text = event.delta.thinking;
560
+ fullContent += text;
561
+ onChunk({ text, finishReason: null });
562
+ } else if (event.delta.type === "text_delta") {
563
+ if (isThinking) {
564
+ isThinking = false;
565
+ fullContent += "\n</think>\n\n";
566
+ onChunk({ text: "\n</think>\n\n", finishReason: null });
567
+ }
568
+ const text = event.delta.text;
569
+ fullContent += text;
570
+ onChunk({ text, finishReason: null });
571
+ }
555
572
  } else if (event.type === "message_delta" && event.usage) {
556
573
  outputTokens = event.usage.output_tokens;
557
574
  } else if (event.type === "message_start" && event.message.usage) {
558
575
  inputTokens = event.message.usage.input_tokens;
559
576
  }
560
577
  }
578
+ if (isThinking) {
579
+ fullContent += "\n</think>\n\n";
580
+ onChunk({ text: "\n</think>\n\n", finishReason: null });
581
+ }
561
582
  const finalMessage = await stream.finalMessage();
562
583
  const toolCalls = finalMessage.content.filter((b) => b.type === "tool_use").map((b) => ({
563
584
  id: b.id,
@@ -728,9 +749,25 @@ var OpenAIProvider = class extends BaseProvider {
728
749
  }
729
750
  }
730
751
  const toolCallsMap = {};
752
+ let isThinking = false;
731
753
  for await (const chunk of stream) {
732
754
  const delta = chunk.choices[0]?.delta;
755
+ const reasoningContent = delta?.reasoning_content;
756
+ if (reasoningContent) {
757
+ if (!isThinking) {
758
+ isThinking = true;
759
+ fullContent += "<think>\n";
760
+ onChunk({ text: "<think>\n", finishReason: null });
761
+ }
762
+ fullContent += reasoningContent;
763
+ onChunk({ text: reasoningContent, finishReason: null });
764
+ }
733
765
  if (delta?.content) {
766
+ if (isThinking) {
767
+ isThinking = false;
768
+ fullContent += "\n</think>\n\n";
769
+ onChunk({ text: "\n</think>\n\n", finishReason: null });
770
+ }
734
771
  fullContent += delta.content;
735
772
  onChunk({ text: delta.content, finishReason: null });
736
773
  }
@@ -753,6 +790,10 @@ var OpenAIProvider = class extends BaseProvider {
753
790
  outputTokens = chunk.usage.completion_tokens;
754
791
  }
755
792
  }
793
+ if (isThinking) {
794
+ fullContent += "\n</think>\n\n";
795
+ onChunk({ text: "\n</think>\n\n", finishReason: null });
796
+ }
756
797
  const toolCalls = Object.values(toolCallsMap).map((tc) => {
757
798
  let input = {};
758
799
  try {
@@ -7429,6 +7470,7 @@ var ConfigManager = class {
7429
7470
  }
7430
7471
  }
7431
7472
  async injectEnvKeys() {
7473
+ const isFirstRun = this.config.providers.length === 0;
7432
7474
  const envProviders = [
7433
7475
  { env: "ANTHROPIC_API_KEY", type: "anthropic" },
7434
7476
  { env: "OPENAI_API_KEY", type: "openai" },
@@ -7439,10 +7481,13 @@ var ConfigManager = class {
7439
7481
  const key = process.env[env];
7440
7482
  if (!key) continue;
7441
7483
  const existing = this.config.providers.find((p) => p.type === type);
7442
- if (!existing) this.config.providers.push({ type, apiKey: key });
7443
- else if (!existing.apiKey) existing.apiKey = key;
7484
+ if (!existing && isFirstRun) {
7485
+ this.config.providers.push({ type, apiKey: key });
7486
+ } else if (existing && !existing.apiKey) {
7487
+ existing.apiKey = key;
7488
+ }
7444
7489
  }
7445
- if (!this.config.providers.find((p) => p.type === "ollama")) {
7490
+ if (isFirstRun && !this.config.providers.find((p) => p.type === "ollama")) {
7446
7491
  this.config.providers.push({ type: "ollama" });
7447
7492
  }
7448
7493
  }