@myassis/gateway 1.0.37 → 1.0.39

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.
@@ -474,9 +474,23 @@ class Session {
474
474
  const sendSSE = (res, data) => {
475
475
  if (!res)
476
476
  return;
477
- res.write(`data: ${JSON.stringify(data)}\n\n`);
478
- res.flush?.();
477
+ try {
478
+ res.write(`data: ${JSON.stringify(data)}\n\n`);
479
+ res.flush?.();
480
+ }
481
+ catch (error) {
482
+ logger.error('SSE write error:', error);
483
+ }
479
484
  };
485
+ // 心跳机制:每 15 秒发送一次心跳,防止连接超时
486
+ const heartbeatInterval = setInterval(() => {
487
+ if (res && !res.destroyed) {
488
+ sendSSE(res, { type: 'heartbeat' });
489
+ }
490
+ else {
491
+ clearInterval(heartbeatInterval);
492
+ }
493
+ }, 15000);
480
494
  // Send message start event
481
495
  sendSSE(res, { type: 'message_start' });
482
496
  // Build messages for API call (保留 tool_call_id 等必要字段)
@@ -918,17 +932,29 @@ class Session {
918
932
  this.addAssistantMessage('', toolCalls, [...new Set(modelNames)].join(','), this.currentMessageId);
919
933
  }
920
934
  if (error.message !== 'aborted') {
921
- sendSSE(res, { type: 'error', error: error.message });
935
+ try {
936
+ sendSSE(res, { type: 'error', error: error.message });
937
+ }
938
+ catch (e) {
939
+ logger.error('Failed to send error event:', e);
940
+ }
922
941
  }
923
942
  }
924
943
  return { success: false, error: error.message };
925
944
  }
926
945
  finally {
946
+ // 清理心跳定时器
947
+ clearInterval(heartbeatInterval);
927
948
  if (!childAgent) {
928
949
  this.isGenerating = false;
929
950
  this.abortController = null;
930
- if (res) {
931
- res.end();
951
+ if (res && !res.destroyed) {
952
+ try {
953
+ res.end();
954
+ }
955
+ catch (e) {
956
+ logger.error('Error closing SSE connection:', e);
957
+ }
932
958
  }
933
959
  // 非当前查看的 session,助手回复完成后增加未读计数
934
960
  (0, SessionManager_js_1.getSessionManager)(this.userId).onMessageComplete(this.id);
@@ -153,7 +153,8 @@ async function getSystemPromptAsync(agent, customPrompt) {
153
153
  ## 3 修改已经存在的代码文件
154
154
  1)修改Bug,找到Bug后精确替换,不要调整架构
155
155
  2)修改业务功能,删除旧的业务功能,重新添加新的,不要在旧的上面做修改,直接删除旧功能,然后添加新功能
156
- 【代码提交】务必类型检查通过
156
+ 【代码提交】务必类型检查通过
157
+ 【任务完成过程中】不能独白
157
158
  ${skillPrompts}`;
158
159
  // 如果有自定义提示词,追加
159
160
  if (customPrompt) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myassis/gateway",
3
- "version": "1.0.37",
3
+ "version": "1.0.39",
4
4
  "description": "我的助手 Gateway Service - 本地 AI 网关服务,支持认证、WebSocket 实时通信和任务调度",
5
5
  "main": "dist/index.js",
6
6
  "bin": {