@myassis/gateway 1.0.108 → 1.0.109

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.
@@ -146,7 +146,7 @@ exports.appConfig = {
146
146
  * 必定压缩,与内容多少无关 —— 这是「没聊几句就压缩」最直接的原因。
147
147
  * 条数只作为体积估算失真时的兜底,阈值应远高于正常对话轮数。
148
148
  */
149
- summaryThreshold: parseInt(process.env.SUMMARY_THRESHOLD || '60', 10),
149
+ summaryThreshold: parseInt(process.env.SUMMARY_THRESHOLD || '10', 10),
150
150
  appName: '我的助手'
151
151
  };
152
152
  /**
@@ -12,7 +12,7 @@ const logger = (0, shared_1.getLogger)('LLMClient');
12
12
  /** 历史工具输出在上下文中的最大保留长度 */
13
13
  const HISTORY_TOOL_OUTPUT_LIMIT = index_js_2.appConfig.oldToolContentLimit;
14
14
  /** 请求体字符硬上限,超过则视为上下文超限 */
15
- const HARD_MAX_CHARS = 200000;
15
+ const HARD_MAX_CHARS = index_js_2.appConfig.contextMaxChars;
16
16
  /**
17
17
  * 规范化工具调用参数。
18
18
  *
@@ -371,30 +371,16 @@ class LLMClient {
371
371
  */
372
372
  async buildRequest(stream, model) {
373
373
  // 系统模式:转发到 Server LLM 代理
374
- if (this.systemMode) {
375
- const { mapped } = this.mapMessages(this.messages);
376
- return {
377
- url: `${this.serverUrl}/api/v1/llm/${stream ? 'chat' : 'invoke'}`,
378
- headers: {
379
- 'Content-Type': 'application/json',
380
- 'Authorization': `Bearer ${this.authToken}`,
381
- },
382
- body: {
383
- modelId: model.modelId,
384
- messages: mapped,
385
- temperature: 0.7,
386
- tools: this.tools,
387
- },
388
- isSystemMode: true,
389
- };
390
- }
391
374
  // 自定义模式:直接调用 LLM API
392
375
  if (!model) {
393
376
  throw new Error('No available model');
394
377
  }
395
- const apiKey = index_js_1.persistStore.getModelApiKey(model.id);
396
- if (!apiKey) {
397
- throw new Error('No API Key');
378
+ var apiKey;
379
+ if (!this.systemMode) {
380
+ apiKey = index_js_1.persistStore.getModelApiKey(model.id);
381
+ if (!apiKey) {
382
+ throw new Error('No API Key');
383
+ }
398
384
  }
399
385
  // 使用统一的消息映射
400
386
  const { mapped: mappedMessages, existAttachments, existScreenShot } = this.mapMessages(this.messages);
@@ -410,17 +396,17 @@ class LLMClient {
410
396
  const bodyChars = JSON.stringify(body).length;
411
397
  logger.debug('context chars', bodyChars);
412
398
  // 附件/截图场景 base64 体积大但不可裁剪,跳过硬上限检查
413
- if (bodyChars > HARD_MAX_CHARS && !existAttachments && !existScreenShot) {
414
- throw Error('exceed max message tokens');
415
- }
399
+ // if (bodyChars > HARD_MAX_CHARS && !existAttachments && !existScreenShot) {
400
+ // throw Error('exceed max message tokens')
401
+ // }
416
402
  return {
417
- url: `${model.baseUrl}/chat/completions`,
403
+ url: this.systemMode ? `${this.serverUrl}/api/v1/llm/${stream ? 'chat' : 'invoke'}` : `${model.baseUrl}/chat/completions`,
418
404
  headers: {
419
405
  'Content-Type': 'application/json',
420
- 'Authorization': `Bearer ${apiKey}`,
406
+ 'Authorization': `Bearer ${this.systemMode ? this.authToken : apiKey}`,
421
407
  },
422
408
  body,
423
- isSystemMode: false,
409
+ isSystemMode: this.systemMode,
424
410
  };
425
411
  }
426
412
  /**
@@ -1031,6 +1031,7 @@ class Session {
1031
1031
  if (built.trimmed) {
1032
1032
  logger.debug(`上下文裁剪: level=${built.level} chars=${built.chars}`);
1033
1033
  }
1034
+ logger.debug(`调用模型${this.selectModelId},messages:`, built.messages);
1034
1035
  // 收尾阶段不再下发工具定义:只要工具还在,模型大概率继续调用而不收尾
1035
1036
  const llmClient = new LLMClient_js_1.LLMClient(models, built.messages, this.abortController.signal, forceFinalize ? [] : tools);
1036
1037
  llmClient.setPreferredModel(this.selectModelId);
@@ -1370,12 +1371,6 @@ class Session {
1370
1371
  };
1371
1372
  await Promise.all(llmResult.toolCalls.map(x => startToolCall(x)));
1372
1373
  toolCalls.push(toolCall);
1373
- // 重置 toolCall:下一轮工具调用必须开启新的分组。
1374
- // 否则模型连续多轮只返回工具调用(无正文)时,所有轮次的结果会
1375
- // 累积进同一个 toolCall 对象,并被重复 push 到 toolCalls 数组,
1376
- // 导致持久化消息出现重复的工具调用组,历史回放时模型看到重复
1377
- // 的 tool_calls/tool 结果对,进而重复执行工具。
1378
- toolCall = null;
1379
1374
  // 本轮工具已执行完,增量落库一次。工具轮次可能很多且每轮都耗时,
1380
1375
  // 这里保存能让崩溃后仍保留已完成的工具调用记录。
1381
1376
  if (!childAgent) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myassis/gateway",
3
- "version": "1.0.108",
3
+ "version": "1.0.109",
4
4
  "description": "我的助手 Gateway Service - 本地 AI 网关服务,支持认证、WebSocket 实时通信和任务调度",
5
5
  "main": "dist/index.js",
6
6
  "bin": {