pi-anthropic-oauth 0.2.3 → 0.2.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/prompt.ts +9 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-anthropic-oauth",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Claude Pro/Max OAuth extension for Pi",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/prompt.ts CHANGED
@@ -32,7 +32,15 @@ type MessageContentBlock = {
32
32
  };
33
33
 
34
34
  export function sanitizeSurrogates(text: string): string {
35
- return text.replace(/[\uD800-\uDFFF]/g, "\uFFFD");
35
+ // Replace only *unpaired* surrogates: a high surrogate not followed by a low
36
+ // surrogate, or a low surrogate not preceded by a high surrogate. Valid
37
+ // surrogate pairs (non-BMP characters such as emoji) must pass through
38
+ // untouched. Equivalent to String.prototype.toWellFormed(), which requires
39
+ // Node 20+ while this package supports Node >=18.
40
+ return text.replace(
41
+ /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g,
42
+ "\uFFFD",
43
+ );
36
44
  }
37
45
 
38
46
  export function buildAnthropicSystemPrompt(