copilot-api-plus 1.2.47 → 1.2.48

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/README.en.md CHANGED
@@ -51,6 +51,7 @@ English | [简体中文](README.md)
51
51
  | ✂️ **Context Passthrough** | Full context passthrough to upstream API; clients (e.g. Claude Code) manage compression |
52
52
  | 🔍 **Smart Model Matching** | Handles model name format differences (date suffixes, dash/dot versions, etc.) |
53
53
  | 🧠 **Thinking Chain** | Automatically enables deep thinking for supported models, improving code quality |
54
+ | 🧹 **Reminder Stripping** | Strips client-injected reminder blocks before forwarding, avoiding upstream false-positive rejections |
54
55
 
55
56
  ---
56
57
 
package/README.md CHANGED
@@ -52,6 +52,7 @@
52
52
  | ✂️ **上下文透传** | 全量透传上下文至上游 API,由客户端(如 Claude Code)自行管理压缩 |
53
53
  | 🔍 **智能模型匹配** | 自动处理模型名格式差异(日期后缀、dash/dot 版本号等) |
54
54
  | 🧠 **Thinking 思维链** | 自动为支持的模型启用深度思考,提升代码质量 |
55
+ | 🧹 **Reminder 剥离** | 自动剥离客户端注入的提醒块,避免上游误判拒绝服务 |
55
56
 
56
57
  ---
57
58
 
package/dist/main.js CHANGED
@@ -2761,52 +2761,73 @@ function getAnthropicToolUseBlocks(toolCalls) {
2761
2761
  }
2762
2762
  //#endregion
2763
2763
  //#region src/routes/messages/strip-reminders.ts
2764
+ /** Matches `<system-reminder>…</system-reminder>` non-greedy, across lines. */
2764
2765
  const REMINDER_RE = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
2765
- function stripFromText(text) {
2766
- if (!text.includes("<system-reminder>")) return text;
2767
- return text.replaceAll(REMINDER_RE, "").replaceAll(/\n{3,}/g, "\n\n").trim();
2768
- }
2769
- function stripFromBlock(block) {
2770
- if (block.type !== "text") return block;
2771
- const text = block.text;
2772
- const stripped = stripFromText(text);
2773
- if (stripped === text) return block;
2774
- return {
2775
- ...block,
2776
- text: stripped
2777
- };
2766
+ /** Cheap sentinel that lets callers skip the regex scan. */
2767
+ const REMINDER_OPEN_TAG = "<system-reminder>";
2768
+ /**
2769
+ * Strip every `<system-reminder>` block from a plain string.
2770
+ *
2771
+ * Collapses runs of 3+ newlines left behind by the removal into a
2772
+ * single blank line, then trims leading/trailing whitespace. Returns
2773
+ * the same reference if no reminder was present (zero allocation).
2774
+ */
2775
+ function stripText(s) {
2776
+ if (!s.includes(REMINDER_OPEN_TAG)) return s;
2777
+ return s.replaceAll(REMINDER_RE, "").replaceAll(/\n{3,}/g, "\n\n").trim();
2778
2778
  }
2779
- function stripFromMessage(message) {
2779
+ /**
2780
+ * Strip reminders from a block array. Non-text blocks pass through.
2781
+ * Text blocks that become empty after stripping are filtered out.
2782
+ * Returns the same reference if nothing changed.
2783
+ */
2784
+ function stripBlocks(content) {
2785
+ if (!content.some((b) => b.type === "text" && b.text.includes(REMINDER_OPEN_TAG))) return content;
2786
+ const out = [];
2787
+ for (const b of content) {
2788
+ if (b.type !== "text") {
2789
+ out.push(b);
2790
+ continue;
2791
+ }
2792
+ const t = stripText(b.text);
2793
+ if (t.length === 0) continue;
2794
+ out.push(t === b.text ? b : {
2795
+ ...b,
2796
+ text: t
2797
+ });
2798
+ }
2799
+ return out;
2800
+ }
2801
+ /**
2802
+ * Strip reminders from a single message. Returns the same reference
2803
+ * if nothing changed.
2804
+ */
2805
+ function stripMessage(message) {
2780
2806
  if (typeof message.content === "string") {
2781
- const stripped = stripFromText(message.content);
2782
- if (stripped === message.content) return message;
2807
+ const next = stripText(message.content);
2808
+ if (next === message.content) return message;
2783
2809
  return {
2784
2810
  ...message,
2785
- content: stripped
2811
+ content: next
2786
2812
  };
2787
2813
  }
2788
- let changed = false;
2789
- const newBlocks = message.content.map((block) => {
2790
- const next = stripFromBlock(block);
2791
- if (next !== block) changed = true;
2792
- return next;
2793
- });
2794
- if (!changed) return message;
2814
+ const next = stripBlocks(message.content);
2815
+ if (next === message.content) return message;
2795
2816
  return {
2796
2817
  ...message,
2797
- content: newBlocks
2818
+ content: next
2798
2819
  };
2799
2820
  }
2800
2821
  /**
2801
- * Return a shallow-cloned payload with `<system-reminder>` blocks removed
2802
- * from every message's text content. The input payload is NOT mutated.
2803
- * If no reminders are present anywhere, the original payload is returned
2804
- * unchanged (no allocation).
2822
+ * Return a shallow-cloned payload with `<system-reminder>` blocks
2823
+ * removed from every message's text content. The input payload is
2824
+ * NOT mutated; if no reminders are present anywhere, the original
2825
+ * payload reference is returned unchanged (no allocation).
2805
2826
  */
2806
2827
  function stripSystemReminders(payload) {
2807
2828
  let changed = false;
2808
2829
  const newMessages = payload.messages.map((m) => {
2809
- const next = stripFromMessage(m);
2830
+ const next = stripMessage(m);
2810
2831
  if (next !== m) changed = true;
2811
2832
  return next;
2812
2833
  });