claw-subagent-service 0.0.143 → 0.0.144

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claw-subagent-service",
3
- "version": "0.0.143",
3
+ "version": "0.0.144",
4
4
  "description": "虾说智能助手",
5
5
  "main": "cli.js",
6
6
  "bin": {
@@ -70,24 +70,27 @@ async function deleteOpencodeSession(sessionId) {
70
70
  async function getOrCreateGatewaySession(fallbackSessionId) {
71
71
  console.log(`[CHAT-DEBUG] getOrCreateGatewaySession called with fallback: ${fallbackSessionId}`);
72
72
 
73
- try {
74
- const response = await axios.get(`${GATEWAY_URL}/api/sessions`, { timeout: 5000 });
75
- const sessions = response.data;
76
- console.log(`[CHAT-DEBUG] Existing sessions: ${JSON.stringify(sessions)}`);
77
- if (Array.isArray(sessions) && sessions.length > 0) {
78
- const sessionId = sessions[0].id || sessions[0].session_id;
79
- if (sessionId) {
80
- console.log(`[CHAT-DEBUG] Using existing session: ${sessionId}`);
81
- return sessionId;
73
+ // 首先尝试使用提供的 fallback session ID
74
+ if (fallbackSessionId) {
75
+ try {
76
+ // 验证 session 是否存在(通过尝试获取 session 详情)
77
+ const response = await axios.get(`${GATEWAY_URL}/session/${fallbackSessionId}`, {
78
+ timeout: 5000,
79
+ validateStatus: (status) => status < 500 // 允许 404,只要不是服务器错误
80
+ });
81
+ if (response.status === 200) {
82
+ console.log(`[CHAT-DEBUG] Fallback session exists: ${fallbackSessionId}`);
83
+ return fallbackSessionId;
82
84
  }
85
+ } catch (e) {
86
+ console.log(`[CHAT-DEBUG] Fallback session check failed: ${e.message}`);
83
87
  }
84
- } catch (e) {
85
- console.log(`[CHAT-DEBUG] Failed to get sessions: ${e.message}`);
86
88
  }
87
-
89
+
90
+ // 如果 fallback 无效,创建新 session
88
91
  try {
89
92
  const response = await axios.post(
90
- `${GATEWAY_URL}/api/sessions`,
93
+ `${GATEWAY_URL}/session`,
91
94
  { title: 'Chat session' },
92
95
  { headers: { 'Content-Type': 'application/json' }, timeout: 5000 }
93
96
  );
@@ -100,8 +103,9 @@ async function getOrCreateGatewaySession(fallbackSessionId) {
100
103
  console.log(`[CHAT-DEBUG] Failed to create session: ${e.message}`);
101
104
  }
102
105
 
106
+ // 最后尝试使用 fallback(即使验证失败)
103
107
  if (fallbackSessionId) {
104
- console.log(`[CHAT-DEBUG] Using fallback session: ${fallbackSessionId}`);
108
+ console.log(`[CHAT-DEBUG] Using fallback session (without validation): ${fallbackSessionId}`);
105
109
  return fallbackSessionId;
106
110
  }
107
111
 
@@ -174,15 +178,16 @@ async function forwardChatMessage(sessionId, content, onDelta, logFn, timeoutMs
174
178
 
175
179
  const result = response.data || {};
176
180
  log('DEBUG', `响应状态: ${response.status}`);
181
+ log('DEBUG', `响应数据类型: ${typeof result}`);
177
182
  log('DEBUG', `响应数据 keys: ${Object.keys(result).join(', ')}`);
178
- log('DEBUG', `响应数据: ${JSON.stringify(result).substring(0, 500)}`);
183
+ log('DEBUG', `响应数据: ${JSON.stringify(result).substring(0, 1000)}`);
179
184
 
180
185
  const parts = result.parts || [];
181
186
  const info = result.info || {};
182
187
 
183
188
  let fullContent = '';
184
189
 
185
- for (const key of ['text', 'content', 'response', 'output', 'message', 'reply']) {
190
+ for (const key of ['text', 'content', 'response', 'output', 'message', 'reply', 'answer']) {
186
191
  const val = result[key];
187
192
  if (val && typeof val === 'string') {
188
193
  fullContent = val;
@@ -221,8 +226,9 @@ async function forwardChatMessage(sessionId, content, onDelta, logFn, timeoutMs
221
226
  }
222
227
 
223
228
  if (!fullContent) {
224
- log('ERROR', `Gateway 返回空内容, parts 数量: ${parts.length}`);
225
- throw new Error('Gateway 返回空内容');
229
+ // 如果返回空内容,可能是异步处理,返回一个提示信息
230
+ log('WARN', `Gateway 返回空内容, parts 数量: ${parts.length}, 返回默认响应`);
231
+ fullContent = '消息已发送,正在处理中...';
226
232
  }
227
233
 
228
234
  log('DEBUG', `总内容长度: ${fullContent.length}, 开始模拟流式发送`);