@takara-ai/miru-code 0.1.2 → 0.1.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.
- package/package.json +1 -1
- package/src/embeddings/openai.ts +12 -3
package/package.json
CHANGED
package/src/embeddings/openai.ts
CHANGED
|
@@ -63,14 +63,23 @@ function splitIntoWindows(text: string, maxChars: number): string[] {
|
|
|
63
63
|
return out;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
/** Unpaired UTF-16 surrogates are invalid in JSON and break strict API parsers. */
|
|
67
|
+
function stripLoneSurrogates(text: string): string {
|
|
68
|
+
return text.replace(
|
|
69
|
+
/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g,
|
|
70
|
+
"\uFFFD",
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function sanitizeEmbeddingInput(text: string): string {
|
|
75
|
+
let out = stripLoneSurrogates(text);
|
|
67
76
|
// Some OpenAI-compatible gateways mis-handle backslash escapes in JSON text
|
|
68
77
|
// payloads. Keep a benchmark fallback mode to forcefully neutralize them.
|
|
69
78
|
const mode = process.env.MIRU_EMBED_ESCAPE_MODE ?? process.env.SEMBLE_EMBED_ESCAPE_MODE ?? "quad";
|
|
70
79
|
if (mode === "strip") {
|
|
71
|
-
return
|
|
80
|
+
return out.replaceAll("\\", "/");
|
|
72
81
|
}
|
|
73
|
-
return
|
|
82
|
+
return out.replaceAll("\\", "\\\\\\\\");
|
|
74
83
|
}
|
|
75
84
|
|
|
76
85
|
function isPayloadTooLargeError(err: unknown): boolean {
|