claw-subagent-service 0.0.74 → 0.0.76

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.74",
3
+ "version": "0.0.76",
4
4
  "description": "虾说智能助手",
5
5
  "main": "cli.js",
6
6
  "bin": {
@@ -20,7 +20,8 @@ class SystemConfigManager {
20
20
  */
21
21
  async fetchConfig(configKey) {
22
22
  try {
23
- const url = `${this.serverUrl}/api/system/config/${configKey}`;
23
+ const url = `${this.serverUrl}/im/api/system/config/${configKey}`;
24
+ this.log?.info(`[SystemConfig] 正在请求配置: ${configKey}, URL=${url}`);
24
25
  const response = await axios.get(url, { timeout: 10000 });
25
26
 
26
27
  if (response.data?.code === 200 && response.data?.data?.value) {
@@ -33,7 +34,7 @@ class SystemConfigManager {
33
34
  this.log?.warn(`[SystemConfig] 获取配置失败: ${configKey}, code=${response.data?.code}`);
34
35
  return null;
35
36
  } catch (err) {
36
- this.log?.error(`[SystemConfig] 获取配置异常: ${configKey}, ${err.message}`);
37
+ this.log?.error(`[SystemConfig] 获取配置异常: ${configKey}, URL=${this.serverUrl}/im/api/system/config/${configKey}, ${err.message}`);
37
38
  return null;
38
39
  }
39
40
  }
@@ -63,11 +63,22 @@ class RongCloudServerAPI {
63
63
  };
64
64
  }
65
65
 
66
+ _getFormHeaders(appKey, appSecret) {
67
+ const sign = this._generateSignature(appSecret);
68
+ return {
69
+ 'App-Key': appKey,
70
+ 'Nonce': sign.nonce,
71
+ 'Timestamp': String(sign.timestamp),
72
+ 'Signature': sign.signature,
73
+ 'Content-Type': 'application/x-www-form-urlencoded'
74
+ };
75
+ }
76
+
66
77
  async request(path, data, appKey, appSecret, retry = true) {
67
78
  const url = `https://${this.currentHost}${path}`;
68
79
  const headers = this._getHeaders(appKey, appSecret);
69
80
 
70
- this.log?.info(`[RongCloudServerAPI] 请求: POST ${url}`);
81
+ this.log?.info(`[RongCloudServerAPI] 请求: POST ${url} (JSON)`);
71
82
 
72
83
  try {
73
84
  const response = await axios.post(url, data, {
@@ -99,6 +110,50 @@ class RongCloudServerAPI {
99
110
  }
100
111
  }
101
112
 
113
+ async requestForm(path, data, appKey, appSecret, retry = true) {
114
+ const url = `https://${this.currentHost}${path}`;
115
+ const headers = this._getFormHeaders(appKey, appSecret);
116
+
117
+ // 将对象转换为 URLSearchParams (form-urlencoded)
118
+ const params = new URLSearchParams();
119
+ for (const [key, value] of Object.entries(data)) {
120
+ if (value !== undefined && value !== null) {
121
+ params.append(key, typeof value === 'object' ? JSON.stringify(value) : String(value));
122
+ }
123
+ }
124
+
125
+ this.log?.info(`[RongCloudServerAPI] 请求: POST ${url} (Form)`);
126
+
127
+ try {
128
+ const response = await axios.post(url, params.toString(), {
129
+ headers,
130
+ timeout: this.timeout,
131
+ responseType: 'json'
132
+ });
133
+
134
+ const result = response.data;
135
+
136
+ if (result.code && result.code !== 200) {
137
+ throw new Error(`[${result.code}] ${result.errorMessage || 'Unknown error'}`);
138
+ }
139
+
140
+ return result;
141
+ } catch (err) {
142
+ if (err.response?.status === 401) {
143
+ this.log?.error('[RongCloudServerAPI] 签名验证失败,请检查 App Key 和 App Secret');
144
+ throw err;
145
+ }
146
+
147
+ if (retry && this._switchHost()) {
148
+ this.log?.warn(`[RongCloudServerAPI] 请求失败,使用备用域名重试: ${err.message}`);
149
+ return this.requestForm(path, data, appKey, appSecret, false);
150
+ }
151
+
152
+ this.log?.error(`[RongCloudServerAPI] 请求失败: ${err.message}`);
153
+ throw err;
154
+ }
155
+ }
156
+
102
157
  /**
103
158
  * 获取融云配置
104
159
  */
@@ -227,9 +282,9 @@ class RongCloudServerAPI {
227
282
  this.log?.info(`[RongCloudServerAPI] 发送 typing 状态: ${fromUserId} -> ${toUserId}`);
228
283
 
229
284
  if (conversationType === 3) {
230
- return this.request('/message/group/publish.json', data, appKey, appSecret);
285
+ return this.requestForm('/message/group/publish.json', data, appKey, appSecret);
231
286
  }
232
- return this.request('/message/private/publish.json', data, appKey, appSecret);
287
+ return this.requestForm('/message/private/publish.json', data, appKey, appSecret);
233
288
  }
234
289
  }
235
290