engine7 7.1.57 → 7.1.58

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/cli.mjs CHANGED
@@ -3120,10 +3120,26 @@ var init_anthropic_provider = __esm({
3120
3120
  }
3121
3121
  }
3122
3122
  }
3123
+ if (process.env.ENGINE_DUMP_REQUEST === "1") {
3124
+ try {
3125
+ const ts = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
3126
+ const dumpPath = __require("node:path").join(process.env.ENGINE_STATE_DIR || ".", "logs", `req-${params.model.replace(/[\/:]/g, "_")}-${ts}.json`);
3127
+ __require("node:fs").writeFileSync(dumpPath, JSON.stringify({ url, headers, body }, null, 1));
3128
+ console.log(`[anthropic] \u{1F4F8} request dumped \u2192 ${__require("node:path").basename(dumpPath)} (${(JSON.stringify(body).length / 1024).toFixed(0)}KB)`);
3129
+ } catch {
3130
+ }
3131
+ }
3132
+ let bodyStr = JSON.stringify(body);
3133
+ if (this.config.wafSingleQuoteWorkaround) {
3134
+ const before = bodyStr.length;
3135
+ bodyStr = bodyStr.replace(/'/g, "\u2019");
3136
+ if (bodyStr.length !== before) {
3137
+ }
3138
+ }
3123
3139
  const retryGen = fetchWithRetry(url, {
3124
3140
  method: "POST",
3125
3141
  headers,
3126
- body: JSON.stringify(body),
3142
+ body: bodyStr,
3127
3143
  signal: params.signal
3128
3144
  }, "anthropic", this.config.proxy);
3129
3145
  let response;
@@ -3638,7 +3654,9 @@ function createProvider(config) {
3638
3654
  baseUrl: config.baseUrl,
3639
3655
  apiKey: config.apiKey,
3640
3656
  thinking: config.thinking,
3641
- proxy
3657
+ proxy,
3658
+ wafSingleQuoteWorkaround: config.wafSingleQuoteWorkaround
3659
+ // 0902 agentrouter WAF 引号规避
3642
3660
  });
3643
3661
  case "gemini":
3644
3662
  return new GeminiProvider({
@@ -18707,11 +18725,15 @@ var init_autoDream = __esm({
18707
18725
  var handle_query_exports = {};
18708
18726
  __export(handle_query_exports, {
18709
18727
  handleQuery: () => handleQuery,
18710
- resetSessionStartInjection: () => resetSessionStartInjection
18728
+ resetSessionStartInjection: () => resetSessionStartInjection,
18729
+ resolveSystemPrompt: () => resolveSystemPrompt
18711
18730
  });
18712
18731
  import { readFileSync as readFileSync25, existsSync as existsSync22 } from "node:fs";
18713
18732
  import { join as join33, resolve as resolve8 } from "node:path";
18714
18733
  import * as path27 from "node:path";
18734
+ function resolveSystemPrompt(v) {
18735
+ return typeof v === "function" ? v() : v || "";
18736
+ }
18715
18737
  function resetSessionStartInjection(sessionId) {
18716
18738
  sessionStartDone.delete(sessionId);
18717
18739
  }
@@ -19028,8 +19050,8 @@ ${text}` : text });
19028
19050
  model,
19029
19051
  parentMessages: messages,
19030
19052
  // 对齐 CC: fork subagent 继承父对话历史
19031
- parentSystemPrompt: deps.systemPrompt,
19032
- // 对齐 CC: fork 共享 prompt cache
19053
+ parentSystemPrompt: resolveSystemPrompt(deps.systemPrompt),
19054
+ // 对齐 CC: fork 共享 prompt cache(0902 每消息现取)
19033
19055
  features: liveConfig.get("agents.defaults.features"),
19034
19056
  // engine config features(AgentTool 读 agentTool.showProgress)
19035
19057
  channelTarget: channelTarget ?? "",
@@ -13570,10 +13570,26 @@ var AnthropicProvider = class {
13570
13570
  }
13571
13571
  }
13572
13572
  }
13573
+ if (process.env.ENGINE_DUMP_REQUEST === "1") {
13574
+ try {
13575
+ const ts = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
13576
+ const dumpPath = __require("node:path").join(process.env.ENGINE_STATE_DIR || ".", "logs", `req-${params.model.replace(/[\/:]/g, "_")}-${ts}.json`);
13577
+ __require("node:fs").writeFileSync(dumpPath, JSON.stringify({ url, headers, body }, null, 1));
13578
+ console.log(`[anthropic] \u{1F4F8} request dumped \u2192 ${__require("node:path").basename(dumpPath)} (${(JSON.stringify(body).length / 1024).toFixed(0)}KB)`);
13579
+ } catch {
13580
+ }
13581
+ }
13582
+ let bodyStr = JSON.stringify(body);
13583
+ if (this.config.wafSingleQuoteWorkaround) {
13584
+ const before = bodyStr.length;
13585
+ bodyStr = bodyStr.replace(/'/g, "\u2019");
13586
+ if (bodyStr.length !== before) {
13587
+ }
13588
+ }
13573
13589
  const retryGen = fetchWithRetry(url, {
13574
13590
  method: "POST",
13575
13591
  headers,
13576
- body: JSON.stringify(body),
13592
+ body: bodyStr,
13577
13593
  signal: params.signal
13578
13594
  }, "anthropic", this.config.proxy);
13579
13595
  let response;
@@ -14076,7 +14092,9 @@ function createProvider(config) {
14076
14092
  baseUrl: config.baseUrl,
14077
14093
  apiKey: config.apiKey,
14078
14094
  thinking: config.thinking,
14079
- proxy
14095
+ proxy,
14096
+ wafSingleQuoteWorkaround: config.wafSingleQuoteWorkaround
14097
+ // 0902 agentrouter WAF 引号规避
14080
14098
  });
14081
14099
  case "gemini":
14082
14100
  return new GeminiProvider({
@@ -20180,6 +20198,9 @@ function buildConversationAnchor(inboundMeta, channelName, source, workspace) {
20180
20198
 
20181
20199
  // src/handle-query.ts
20182
20200
  var sessionStartDone = /* @__PURE__ */ new Set();
20201
+ function resolveSystemPrompt(v) {
20202
+ return typeof v === "function" ? v() : v || "";
20203
+ }
20183
20204
  function resetSessionStartInjection(sessionId) {
20184
20205
  sessionStartDone.delete(sessionId);
20185
20206
  }
@@ -20497,8 +20518,8 @@ ${text}` : text });
20497
20518
  model,
20498
20519
  parentMessages: messages,
20499
20520
  // 对齐 CC: fork subagent 继承父对话历史
20500
- parentSystemPrompt: deps.systemPrompt,
20501
- // 对齐 CC: fork 共享 prompt cache
20521
+ parentSystemPrompt: resolveSystemPrompt(deps.systemPrompt),
20522
+ // 对齐 CC: fork 共享 prompt cache(0902 每消息现取)
20502
20523
  features: liveConfig.get("agents.defaults.features"),
20503
20524
  // engine config features(AgentTool 读 agentTool.showProgress)
20504
20525
  channelTarget: channelTarget ?? "",
@@ -25271,7 +25292,7 @@ var VoiceChatPlugin = class _VoiceChatPlugin {
25271
25292
  - \u5982\u679C\u5B9E\u5728\u9700\u8981\u67E5\uFF1A\u5148\u8BF4"\u7B49\u6211\u67E5\u4E0B"\u5E76\u6781\u7B80\u8C03\u7528\uFF0C\u67E5\u5B8C\u7ACB\u523B\u603B\u7ED3\u6210\u4E00\u53E5\u8BDD`;
25272
25293
  const engine = new QueryEngine(llmProvider, {
25273
25294
  model: modelId,
25274
- systemPrompt: (ctx.deps.systemPrompt || "") + voiceChatRules,
25295
+ systemPrompt: resolveSystemPrompt(ctx.deps.systemPrompt) + voiceChatRules,
25275
25296
  maxTokens: 4096,
25276
25297
  temperature: 0.7,
25277
25298
  disableThinking: !this.config.thinking,
@@ -29771,8 +29792,8 @@ registerCommand({
29771
29792
  sessionManager: deps.sessions,
29772
29793
  sessionId: sid,
29773
29794
  model: deps.config.model,
29774
- contextWindow: deps.compactConfig.contextWindow || 2e5,
29775
- systemPrompt: deps.systemPrompt,
29795
+ contextWindow: (typeof deps.compactConfig === "function" ? deps.compactConfig() : deps.compactConfig).contextWindow || 2e5,
29796
+ systemPrompt: resolveSystemPrompt(deps.systemPrompt),
29776
29797
  toolDefs: registry.definitions(),
29777
29798
  workspace: deps.config.workspace
29778
29799
  });
@@ -29820,7 +29841,7 @@ ${question}`;
29820
29841
  const stream = deps.provider.streamChat({
29821
29842
  model: deps.config.model,
29822
29843
  messages: [{ role: "user", content: wrappedQuestion }],
29823
- systemPrompt: deps.systemPrompt,
29844
+ systemPrompt: resolveSystemPrompt(deps.systemPrompt),
29824
29845
  maxTokens: 2048,
29825
29846
  signal: void 0
29826
29847
  });
package/dist/main.mjs CHANGED
@@ -13944,10 +13944,26 @@ var AnthropicProvider = class {
13944
13944
  }
13945
13945
  }
13946
13946
  }
13947
+ if (process.env.ENGINE_DUMP_REQUEST === "1") {
13948
+ try {
13949
+ const ts = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
13950
+ const dumpPath = __require("node:path").join(process.env.ENGINE_STATE_DIR || ".", "logs", `req-${params.model.replace(/[\/:]/g, "_")}-${ts}.json`);
13951
+ __require("node:fs").writeFileSync(dumpPath, JSON.stringify({ url, headers, body }, null, 1));
13952
+ console.log(`[anthropic] \u{1F4F8} request dumped \u2192 ${__require("node:path").basename(dumpPath)} (${(JSON.stringify(body).length / 1024).toFixed(0)}KB)`);
13953
+ } catch {
13954
+ }
13955
+ }
13956
+ let bodyStr = JSON.stringify(body);
13957
+ if (this.config.wafSingleQuoteWorkaround) {
13958
+ const before = bodyStr.length;
13959
+ bodyStr = bodyStr.replace(/'/g, "\u2019");
13960
+ if (bodyStr.length !== before) {
13961
+ }
13962
+ }
13947
13963
  const retryGen = fetchWithRetry(url, {
13948
13964
  method: "POST",
13949
13965
  headers,
13950
- body: JSON.stringify(body),
13966
+ body: bodyStr,
13951
13967
  signal: params.signal
13952
13968
  }, "anthropic", this.config.proxy);
13953
13969
  let response;
@@ -14450,7 +14466,9 @@ function createProvider(config2) {
14450
14466
  baseUrl: config2.baseUrl,
14451
14467
  apiKey: config2.apiKey,
14452
14468
  thinking: config2.thinking,
14453
- proxy
14469
+ proxy,
14470
+ wafSingleQuoteWorkaround: config2.wafSingleQuoteWorkaround
14471
+ // 0902 agentrouter WAF 引号规避
14454
14472
  });
14455
14473
  case "gemini":
14456
14474
  return new GeminiProvider({
@@ -20554,6 +20572,9 @@ function buildConversationAnchor(inboundMeta, channelName, source, workspace) {
20554
20572
 
20555
20573
  // src/handle-query.ts
20556
20574
  var sessionStartDone = /* @__PURE__ */ new Set();
20575
+ function resolveSystemPrompt(v) {
20576
+ return typeof v === "function" ? v() : v || "";
20577
+ }
20557
20578
  function resetSessionStartInjection(sessionId) {
20558
20579
  sessionStartDone.delete(sessionId);
20559
20580
  }
@@ -20871,8 +20892,8 @@ ${text}` : text });
20871
20892
  model,
20872
20893
  parentMessages: messages,
20873
20894
  // 对齐 CC: fork subagent 继承父对话历史
20874
- parentSystemPrompt: deps.systemPrompt,
20875
- // 对齐 CC: fork 共享 prompt cache
20895
+ parentSystemPrompt: resolveSystemPrompt(deps.systemPrompt),
20896
+ // 对齐 CC: fork 共享 prompt cache(0902 每消息现取)
20876
20897
  features: liveConfig.get("agents.defaults.features"),
20877
20898
  // engine config features(AgentTool 读 agentTool.showProgress)
20878
20899
  channelTarget: channelTarget ?? "",
@@ -25645,7 +25666,7 @@ var VoiceChatPlugin = class _VoiceChatPlugin {
25645
25666
  - \u5982\u679C\u5B9E\u5728\u9700\u8981\u67E5\uFF1A\u5148\u8BF4"\u7B49\u6211\u67E5\u4E0B"\u5E76\u6781\u7B80\u8C03\u7528\uFF0C\u67E5\u5B8C\u7ACB\u523B\u603B\u7ED3\u6210\u4E00\u53E5\u8BDD`;
25646
25667
  const engine = new QueryEngine(llmProvider, {
25647
25668
  model: modelId,
25648
- systemPrompt: (ctx.deps.systemPrompt || "") + voiceChatRules,
25669
+ systemPrompt: resolveSystemPrompt(ctx.deps.systemPrompt) + voiceChatRules,
25649
25670
  maxTokens: 4096,
25650
25671
  temperature: 0.7,
25651
25672
  disableThinking: !this.config.thinking,
@@ -29855,8 +29876,8 @@ registerCommand({
29855
29876
  sessionManager: deps.sessions,
29856
29877
  sessionId: sid,
29857
29878
  model: deps.config.model,
29858
- contextWindow: deps.compactConfig.contextWindow || 2e5,
29859
- systemPrompt: deps.systemPrompt,
29879
+ contextWindow: (typeof deps.compactConfig === "function" ? deps.compactConfig() : deps.compactConfig).contextWindow || 2e5,
29880
+ systemPrompt: resolveSystemPrompt(deps.systemPrompt),
29860
29881
  toolDefs: registry.definitions(),
29861
29882
  workspace: deps.config.workspace
29862
29883
  });
@@ -29904,7 +29925,7 @@ ${question}`;
29904
29925
  const stream = deps.provider.streamChat({
29905
29926
  model: deps.config.model,
29906
29927
  messages: [{ role: "user", content: wrappedQuestion }],
29907
- systemPrompt: deps.systemPrompt,
29928
+ systemPrompt: resolveSystemPrompt(deps.systemPrompt),
29908
29929
  maxTokens: 2048,
29909
29930
  signal: void 0
29910
29931
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "engine7",
3
- "version": "7.1.57",
3
+ "version": "7.1.58",
4
4
  "type": "module",
5
5
  "description": "Engine 7 — 给助手一个家 / A home for your AI assistant",
6
6
  "main": "dist/main.mjs",