@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takara-ai/miru-code",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Miru (見る) — hybrid code search for agents. Bun, TypeScript, Takara embeddings.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -63,14 +63,23 @@ function splitIntoWindows(text: string, maxChars: number): string[] {
63
63
  return out;
64
64
  }
65
65
 
66
- function sanitizeEmbeddingInput(text: string): string {
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 text.replaceAll("\\", "/");
80
+ return out.replaceAll("\\", "/");
72
81
  }
73
- return text.replaceAll("\\", "\\\\\\\\");
82
+ return out.replaceAll("\\", "\\\\\\\\");
74
83
  }
75
84
 
76
85
  function isPayloadTooLargeError(err: unknown): boolean {