ai-sdk-provider-claude-code 2.0.4 → 2.0.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.
- package/dist/index.cjs +12 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +12 -56
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -710,80 +710,36 @@ function getLogger(logger) {
|
|
|
710
710
|
|
|
711
711
|
// src/claude-code-language-model.ts
|
|
712
712
|
var import_claude_agent_sdk = require("@anthropic-ai/claude-agent-sdk");
|
|
713
|
-
var CLAUDE_CODE_TRUNCATION_WARNING = "Claude Code
|
|
714
|
-
var MIN_TRUNCATION_LENGTH =
|
|
715
|
-
var POSITION_PATTERN = /position\s+(\d+)/i;
|
|
716
|
-
function hasUnclosedJsonStructure(text) {
|
|
717
|
-
let depth = 0;
|
|
718
|
-
let inString = false;
|
|
719
|
-
let escapeNext = false;
|
|
720
|
-
for (let i = 0; i < text.length; i++) {
|
|
721
|
-
const char = text[i];
|
|
722
|
-
if (escapeNext) {
|
|
723
|
-
escapeNext = false;
|
|
724
|
-
continue;
|
|
725
|
-
}
|
|
726
|
-
if (inString) {
|
|
727
|
-
if (char === "\\") {
|
|
728
|
-
escapeNext = true;
|
|
729
|
-
continue;
|
|
730
|
-
}
|
|
731
|
-
if (char === '"') {
|
|
732
|
-
inString = false;
|
|
733
|
-
}
|
|
734
|
-
continue;
|
|
735
|
-
}
|
|
736
|
-
if (char === '"') {
|
|
737
|
-
inString = true;
|
|
738
|
-
continue;
|
|
739
|
-
}
|
|
740
|
-
if (char === "{" || char === "[") {
|
|
741
|
-
depth++;
|
|
742
|
-
continue;
|
|
743
|
-
}
|
|
744
|
-
if (char === "}" || char === "]") {
|
|
745
|
-
if (depth > 0) {
|
|
746
|
-
depth--;
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
return depth > 0 || inString;
|
|
751
|
-
}
|
|
713
|
+
var CLAUDE_CODE_TRUNCATION_WARNING = "Claude Code SDK output ended unexpectedly; returning truncated response from buffered text. Await upstream fix to avoid data loss.";
|
|
714
|
+
var MIN_TRUNCATION_LENGTH = 512;
|
|
752
715
|
function isClaudeCodeTruncationError(error, bufferedText) {
|
|
753
|
-
|
|
716
|
+
const isSyntaxError = error instanceof SyntaxError || // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
717
|
+
typeof error?.name === "string" && // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
718
|
+
error.name.toLowerCase() === "syntaxerror";
|
|
719
|
+
if (!isSyntaxError) {
|
|
754
720
|
return false;
|
|
755
721
|
}
|
|
756
722
|
if (!bufferedText) {
|
|
757
723
|
return false;
|
|
758
724
|
}
|
|
759
|
-
const rawMessage = typeof error
|
|
725
|
+
const rawMessage = typeof error?.message === "string" ? error.message : "";
|
|
760
726
|
const message = rawMessage.toLowerCase();
|
|
761
727
|
const truncationIndicators = [
|
|
762
728
|
"unexpected end of json input",
|
|
763
729
|
"unexpected end of input",
|
|
764
730
|
"unexpected end of string",
|
|
765
|
-
"
|
|
731
|
+
"unexpected eof",
|
|
732
|
+
"end of file",
|
|
733
|
+
"unterminated string",
|
|
734
|
+
"unterminated string constant"
|
|
766
735
|
];
|
|
767
736
|
if (!truncationIndicators.some((indicator) => message.includes(indicator))) {
|
|
768
737
|
return false;
|
|
769
738
|
}
|
|
770
|
-
const positionMatch = rawMessage.match(POSITION_PATTERN);
|
|
771
|
-
if (positionMatch) {
|
|
772
|
-
const position = Number.parseInt(positionMatch[1], 10);
|
|
773
|
-
if (Number.isFinite(position)) {
|
|
774
|
-
const isNearBufferEnd = Math.abs(position - bufferedText.length) <= 16;
|
|
775
|
-
if (isNearBufferEnd && position >= MIN_TRUNCATION_LENGTH) {
|
|
776
|
-
return true;
|
|
777
|
-
}
|
|
778
|
-
if (!isNearBufferEnd) {
|
|
779
|
-
return false;
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
739
|
if (bufferedText.length < MIN_TRUNCATION_LENGTH) {
|
|
784
740
|
return false;
|
|
785
741
|
}
|
|
786
|
-
return
|
|
742
|
+
return true;
|
|
787
743
|
}
|
|
788
744
|
function isAbortError(err) {
|
|
789
745
|
if (err && typeof err === "object") {
|