@chen0825/aiapp-ability 0.1.2 → 0.1.3

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.
@@ -122,19 +122,38 @@ class DingTalkProvider {
122
122
  'x-acs-dingtalk-access-token': tokenResult.accessToken,
123
123
  },
124
124
  });
125
- if (!result.success) {
125
+ // 钉钉 API 成功时返回 { processQueryKey, flowControlledStaffIdList, invalidStaffIdList }
126
+ // 失败时 HttpClient 会返回 { success: false, message: ..., code: ... }
127
+ const errorResult = result;
128
+ if (errorResult.success === false) {
126
129
  return {
127
130
  success: false,
128
- message: result.message || '批量发送机器人消息失败',
129
- data: result.data,
131
+ message: errorResult.message || '批量发送机器人消息失败',
132
+ code: errorResult.code,
133
+ data: errorResult.data,
130
134
  };
131
135
  }
136
+ // API 调用成功,解析响应数据
137
+ const apiResponse = result;
138
+ // 检查是否有无效用户
139
+ const invalidCount = apiResponse.invalidStaffIdList?.length || 0;
140
+ const flowControlledCount = apiResponse.flowControlledStaffIdList?.length || 0;
141
+ const failCount = invalidCount + flowControlledCount;
142
+ const successCount = params.userIds.length - failCount;
143
+ // 合并失败用户列表
144
+ const failedUserIds = [
145
+ ...(apiResponse.invalidStaffIdList || []),
146
+ ...(apiResponse.flowControlledStaffIdList || []),
147
+ ];
132
148
  return {
133
- success: true,
134
- message: '批量发送成功',
135
- data: result.data,
136
- successCount: params.userIds.length,
137
- failCount: 0,
149
+ success: failCount === 0,
150
+ message: failCount === 0
151
+ ? '批量发送成功'
152
+ : `部分发送失败: ${invalidCount} 个无效用户, ${flowControlledCount} 个被限流`,
153
+ data: apiResponse,
154
+ successCount,
155
+ failCount,
156
+ failedUserIds: failedUserIds.length > 0 ? failedUserIds : undefined,
138
157
  };
139
158
  }
140
159
  catch (error) {
@@ -12,28 +12,51 @@ class HttpClient {
12
12
  * 发送 POST 请求
13
13
  */
14
14
  async post(endpoint, data, options) {
15
+ const url = `${this.baseUrl}${endpoint}`;
16
+ const headers = {
17
+ "Content-Type": "application/json",
18
+ ...options?.headers,
19
+ };
20
+ console.log(`[HttpClient] POST ${url}`);
21
+ console.log(`[HttpClient] Request headers:`, JSON.stringify(headers, null, 2));
22
+ console.log(`[HttpClient] Request body:`, JSON.stringify(data, null, 2));
15
23
  try {
16
- const response = await fetch(`${this.baseUrl}${endpoint}`, {
24
+ const response = await fetch(url, {
17
25
  method: "POST",
18
- headers: {
19
- "Content-Type": "application/json",
20
- ...options?.headers,
21
- },
26
+ headers,
22
27
  body: JSON.stringify(data),
23
- ...options,
24
28
  });
29
+ console.log(`[HttpClient] Response status: ${response.status} ${response.statusText}`);
25
30
  if (!response.ok) {
31
+ const errorText = await response.text();
32
+ console.error(`[HttpClient] Error response body:`, errorText);
33
+ // 尝试解析钉钉 API 的错误响应格式: { code, requestid, message }
34
+ let errorMessage = `请求异常: ${response.status} ${response.statusText}`;
35
+ let errorCode;
36
+ try {
37
+ const errorJson = JSON.parse(errorText);
38
+ if (errorJson.code && errorJson.message) {
39
+ errorCode = errorJson.code;
40
+ errorMessage = errorJson.message;
41
+ }
42
+ }
43
+ catch {
44
+ // 非 JSON 格式,使用原始错误文本
45
+ errorMessage = `${errorMessage} - ${errorText}`;
46
+ }
26
47
  return {
27
48
  success: false,
28
- message: "请求异常",
49
+ message: errorMessage,
50
+ code: errorCode,
29
51
  data: undefined,
30
52
  };
31
53
  }
32
54
  const result = await response.json();
55
+ console.log(`[HttpClient] Response data:`, JSON.stringify(result, null, 2));
33
56
  return result;
34
57
  }
35
58
  catch (error) {
36
- console.error("HTTP请求失败:", error);
59
+ console.error("[HttpClient] 请求失败:", error);
37
60
  return {
38
61
  success: false,
39
62
  message: error instanceof Error ? error.message : "请求失败",
@@ -47,6 +47,8 @@ export interface BatchSendRobotMsgResponse {
47
47
  processQueryKey?: string;
48
48
  /** 被限流的用户列表 */
49
49
  flowControlledStaffIdList?: string[];
50
+ /** 无效的用户列表 */
51
+ invalidStaffIdList?: string[];
50
52
  }
51
53
  /**
52
54
  * 批量发送结果
@@ -69,6 +71,8 @@ export interface BatchSendResponse {
69
71
  success: boolean;
70
72
  /** 消息 */
71
73
  message?: string;
74
+ /** 错误码(如钉钉 API 返回的 code) */
75
+ code?: string;
72
76
  /** 发送结果详情 */
73
77
  data?: BatchSendRobotMsgResponse;
74
78
  /** 失败的用户列表 */
@@ -8,6 +8,8 @@ export * from './dingtalk';
8
8
  export interface BaseResponse<T = any> {
9
9
  success: boolean;
10
10
  message?: string;
11
+ /** 错误码(如钉钉 API 返回的 code) */
12
+ code?: string;
11
13
  data?: T;
12
14
  }
13
15
  /**
package/package.json CHANGED
@@ -1,20 +1,13 @@
1
1
  {
2
2
  "name": "@chen0825/aiapp-ability",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "aiapp能力包",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "scripts": {
8
8
  "start": "tsc -w",
9
9
  "build": "tsc",
10
- "test": "jest",
11
- "release": "npm version patch && npm publish",
12
- "postinstall": "husky install"
13
- },
14
- "lint-staged": {
15
- "**/*.{js,jsx,ts,tsx,html,css,json}": [
16
- "npx prettier --write"
17
- ]
10
+ "release": "npm version patch --no-git-tag-version && npm publish"
18
11
  },
19
12
  "repository": {
20
13
  "type": "git",
@@ -27,12 +20,8 @@
27
20
  "dotenv": "^17.3.1"
28
21
  },
29
22
  "devDependencies": {
30
- "@types/jest": "^29.5.4",
31
- "husky": "^8.0.3",
32
- "jest": "^29.6.4",
33
- "lint-staged": "^13.2.3",
23
+ "@types/node": "^25.5.0",
34
24
  "prettier": "^3.0.2",
35
- "ts-jest": "^29.1.1",
36
25
  "typescript": "^5.2.2"
37
26
  },
38
27
  "publishConfig": {