@jeik/dingtalk-connector 0.8.21-fix1

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.
Files changed (154) hide show
  1. package/CHANGELOG.md +686 -0
  2. package/LICENSE +21 -0
  3. package/README.en.md +181 -0
  4. package/README.md +221 -0
  5. package/bin/dingtalk-connector.js +858 -0
  6. package/bin/wizard-config.mjs +110 -0
  7. package/dist/accounts-BAzdqkAV.mjs +268 -0
  8. package/dist/accounts-BQptOmgB.mjs +2 -0
  9. package/dist/chunk-upload-BBQgGtcZ.mjs +193 -0
  10. package/dist/chunk-upload-DaLXXZH3.mjs +2 -0
  11. package/dist/common-C8pYKU_y.mjs +2 -0
  12. package/dist/common-Dt9n6fQN.mjs +101 -0
  13. package/dist/connection-DHHFFNQJ.mjs +423 -0
  14. package/dist/entry-bundled.d.mts +16 -0
  15. package/dist/entry-bundled.mjs +31 -0
  16. package/dist/game-xiyou-CqHt-6Q1.mjs +4271 -0
  17. package/dist/gateway-methods-C4tcgI7P.mjs +771 -0
  18. package/dist/gateway-methods-Ci31A3vg.mjs +2 -0
  19. package/dist/http-client-CpnJHB89.mjs +2 -0
  20. package/dist/http-client-DFWZgO1n.mjs +33 -0
  21. package/dist/index.d.mts +193 -0
  22. package/dist/index.mjs +45 -0
  23. package/dist/logger-BmJkQkm1.mjs +2 -0
  24. package/dist/logger-mZ9OSbmD.mjs +58 -0
  25. package/dist/media-C_SVin7s.mjs +2 -0
  26. package/dist/media-cz72EVS3.mjs +509 -0
  27. package/dist/message-handler-DESzFFDc.mjs +1971 -0
  28. package/dist/messaging-B6l1sRvX.mjs +1044 -0
  29. package/dist/runtime-DUgpo5zC.mjs +1422 -0
  30. package/dist/session-DJ4jYqPv.mjs +114 -0
  31. package/dist/utils-Bjh4r_qS.mjs +4 -0
  32. package/dist/utils-CIfI_3Jh.mjs +63 -0
  33. package/dist/utils-legacy-CALCPP1t.mjs +230 -0
  34. package/dist/utils-legacy-CFYDBM4r.mjs +3 -0
  35. package/docs/DEAP_AGENT_GUIDE.en.md +115 -0
  36. package/docs/DEAP_AGENT_GUIDE.md +115 -0
  37. package/docs/DINGTALK_MANUAL_SETUP.md +50 -0
  38. package/docs/MULTI_AGENT_SETUP.md +306 -0
  39. package/docs/RELEASE_NOTES_V0.7.10.md +40 -0
  40. package/docs/RELEASE_NOTES_V0.7.2.md +143 -0
  41. package/docs/RELEASE_NOTES_V0.7.3.md +149 -0
  42. package/docs/RELEASE_NOTES_V0.7.4.md +206 -0
  43. package/docs/RELEASE_NOTES_V0.7.5.md +267 -0
  44. package/docs/RELEASE_NOTES_V0.7.6.md +219 -0
  45. package/docs/RELEASE_NOTES_V0.7.7.md +122 -0
  46. package/docs/RELEASE_NOTES_V0.7.8.md +101 -0
  47. package/docs/RELEASE_NOTES_V0.7.9.md +65 -0
  48. package/docs/RELEASE_NOTES_V0.8.0.md +53 -0
  49. package/docs/RELEASE_NOTES_V0.8.1.md +47 -0
  50. package/docs/RELEASE_NOTES_V0.8.10.md +49 -0
  51. package/docs/RELEASE_NOTES_V0.8.11.md +51 -0
  52. package/docs/RELEASE_NOTES_V0.8.12.md +63 -0
  53. package/docs/RELEASE_NOTES_V0.8.13-beta.0.md +69 -0
  54. package/docs/RELEASE_NOTES_V0.8.13.md +62 -0
  55. package/docs/RELEASE_NOTES_V0.8.14.md +86 -0
  56. package/docs/RELEASE_NOTES_V0.8.16.md +40 -0
  57. package/docs/RELEASE_NOTES_V0.8.17.md +87 -0
  58. package/docs/RELEASE_NOTES_V0.8.18.md +64 -0
  59. package/docs/RELEASE_NOTES_V0.8.19.md +62 -0
  60. package/docs/RELEASE_NOTES_V0.8.2.md +55 -0
  61. package/docs/RELEASE_NOTES_V0.8.20.md +49 -0
  62. package/docs/RELEASE_NOTES_V0.8.3.md +63 -0
  63. package/docs/RELEASE_NOTES_V0.8.4.md +45 -0
  64. package/docs/RELEASE_NOTES_V0.8.7.md +49 -0
  65. package/docs/RELEASE_NOTES_V0.8.8.md +63 -0
  66. package/docs/RELEASE_NOTES_V0.8.9.md +81 -0
  67. package/docs/RELEASE_NOTES_v0.7.0.md +142 -0
  68. package/docs/RELEASE_NOTES_v0.7.1.md +74 -0
  69. package/docs/TROUBLESHOOTING.md +122 -0
  70. package/index.ts +77 -0
  71. package/openclaw.plugin.json +551 -0
  72. package/package.json +147 -0
  73. package/skills/dingtalk-channel-rules/SKILL.md +91 -0
  74. package/skills/dingtalk-troubleshoot/SKILL.md +93 -0
  75. package/skills/dws-cli/SKILL.md +129 -0
  76. package/skills/dws-cli/references/error-codes.md +95 -0
  77. package/skills/dws-cli/references/field-rules.md +105 -0
  78. package/skills/dws-cli/references/global-reference.md +104 -0
  79. package/skills/dws-cli/references/intent-guide.md +114 -0
  80. package/skills/dws-cli/references/products/aitable.md +452 -0
  81. package/skills/dws-cli/references/products/attendance.md +93 -0
  82. package/skills/dws-cli/references/products/calendar.md +217 -0
  83. package/skills/dws-cli/references/products/chat.md +292 -0
  84. package/skills/dws-cli/references/products/contact.md +108 -0
  85. package/skills/dws-cli/references/products/ding.md +57 -0
  86. package/skills/dws-cli/references/products/report.md +162 -0
  87. package/skills/dws-cli/references/products/simple.md +128 -0
  88. package/skills/dws-cli/references/products/todo.md +138 -0
  89. package/skills/dws-cli/references/products/workbench.md +39 -0
  90. package/skills/dws-cli/references/recovery-guide.md +94 -0
  91. package/src/channel.ts +588 -0
  92. package/src/config/accounts.ts +242 -0
  93. package/src/config/schema.ts +180 -0
  94. package/src/core/connection.ts +741 -0
  95. package/src/core/message-handler.ts +1788 -0
  96. package/src/core/provider.ts +111 -0
  97. package/src/core/state.ts +54 -0
  98. package/src/device-auth-config.ts +14 -0
  99. package/src/device-auth.ts +197 -0
  100. package/src/directory.ts +95 -0
  101. package/src/docs.ts +293 -0
  102. package/src/game-xiyou/achievement-engine.ts +252 -0
  103. package/src/game-xiyou/bounty-system.ts +315 -0
  104. package/src/game-xiyou/commands.ts +223 -0
  105. package/src/game-xiyou/drop-engine.ts +241 -0
  106. package/src/game-xiyou/encounter-system.ts +135 -0
  107. package/src/game-xiyou/escape-engine.ts +164 -0
  108. package/src/game-xiyou/exp-calculator.ts +139 -0
  109. package/src/game-xiyou/index.ts +479 -0
  110. package/src/game-xiyou/level-system.ts +91 -0
  111. package/src/game-xiyou/monster-pool.ts +180 -0
  112. package/src/game-xiyou/pity-counter.ts +114 -0
  113. package/src/game-xiyou/random-event-engine.ts +648 -0
  114. package/src/game-xiyou/renderer.ts +679 -0
  115. package/src/game-xiyou/storage.ts +218 -0
  116. package/src/game-xiyou/treasure-system.ts +105 -0
  117. package/src/game-xiyou/types.ts +582 -0
  118. package/src/game-xiyou/uid-resolver.ts +49 -0
  119. package/src/gateway-methods.ts +740 -0
  120. package/src/onboarding.ts +553 -0
  121. package/src/policy.ts +32 -0
  122. package/src/probe.ts +210 -0
  123. package/src/reply-dispatcher.ts +874 -0
  124. package/src/runtime.ts +32 -0
  125. package/src/sdk/helpers.ts +322 -0
  126. package/src/sdk/types.ts +519 -0
  127. package/src/secret-input.ts +19 -0
  128. package/src/services/media/audio.ts +54 -0
  129. package/src/services/media/chunk-upload.ts +296 -0
  130. package/src/services/media/common.ts +155 -0
  131. package/src/services/media/file.ts +75 -0
  132. package/src/services/media/image.ts +81 -0
  133. package/src/services/media/index.ts +10 -0
  134. package/src/services/media/video.ts +162 -0
  135. package/src/services/media.ts +1143 -0
  136. package/src/services/messaging/card.ts +604 -0
  137. package/src/services/messaging/index.ts +18 -0
  138. package/src/services/messaging/mentions.ts +267 -0
  139. package/src/services/messaging/send.ts +141 -0
  140. package/src/services/messaging.ts +1191 -0
  141. package/src/services/reply-markers.ts +55 -0
  142. package/src/targets.ts +45 -0
  143. package/src/types/index.ts +59 -0
  144. package/src/types/pdf-parse.d.ts +3 -0
  145. package/src/utils/agent.ts +63 -0
  146. package/src/utils/async.ts +51 -0
  147. package/src/utils/constants.ts +27 -0
  148. package/src/utils/http-client.ts +38 -0
  149. package/src/utils/index.ts +8 -0
  150. package/src/utils/logger.ts +78 -0
  151. package/src/utils/session.ts +147 -0
  152. package/src/utils/token.ts +93 -0
  153. package/src/utils/utils-legacy.ts +454 -0
  154. package/tsconfig.json +20 -0
package/src/probe.ts ADDED
@@ -0,0 +1,210 @@
1
+ import { raceWithTimeoutAndAbort } from "./utils/async.ts";
2
+ import { dingtalkHttp } from "./utils/http-client.ts";
3
+ import type { DingtalkProbeResult } from "./types/index.ts";
4
+
5
+ /** LRU Cache for probe results to reduce repeated health-check calls. */
6
+ class LRUCache<K, V> {
7
+ private cache = new Map<K, V>();
8
+ private maxSize: number;
9
+
10
+ constructor(maxSize: number) {
11
+ this.maxSize = maxSize;
12
+ }
13
+
14
+ get(key: K): V | undefined {
15
+ const value = this.cache.get(key);
16
+ if (value !== undefined) {
17
+ // 重新插入以更新访问顺序
18
+ this.cache.delete(key);
19
+ this.cache.set(key, value);
20
+ }
21
+ return value;
22
+ }
23
+
24
+ set(key: K, value: V): void {
25
+ // 如果已存在,先删除(更新顺序)
26
+ if (this.cache.has(key)) {
27
+ this.cache.delete(key);
28
+ }
29
+
30
+ this.cache.set(key, value);
31
+
32
+ // 超过大小限制时删除最旧的(最少使用的)
33
+ if (this.cache.size > this.maxSize) {
34
+ const oldest = this.cache.keys().next().value;
35
+ if (oldest !== undefined) {
36
+ this.cache.delete(oldest);
37
+ }
38
+ }
39
+ }
40
+
41
+ clear(): void {
42
+ this.cache.clear();
43
+ }
44
+ }
45
+
46
+ const probeCache = new LRUCache<string, { result: DingtalkProbeResult; expiresAt: number }>(64);
47
+ const PROBE_SUCCESS_TTL_MS = 10 * 60 * 1000; // 10 minutes
48
+ const PROBE_ERROR_TTL_MS = 60 * 1000; // 1 minute
49
+ export const DINGTALK_PROBE_REQUEST_TIMEOUT_MS = 10_000;
50
+ export type ProbeDingtalkOptions = {
51
+ timeoutMs?: number;
52
+ abortSignal?: AbortSignal;
53
+ };
54
+
55
+ type DingtalkBotInfoResponse = {
56
+ errcode?: number;
57
+ errmsg?: string;
58
+ nick?: string;
59
+ unionid?: string;
60
+ };
61
+
62
+ function setCachedProbeResult(
63
+ cacheKey: string,
64
+ result: DingtalkProbeResult,
65
+ ttlMs: number,
66
+ ): DingtalkProbeResult {
67
+ probeCache.set(cacheKey, { result, expiresAt: Date.now() + ttlMs });
68
+ return result;
69
+ }
70
+
71
+ export async function probeDingtalk(
72
+ creds?: { clientId: string; clientSecret: string; accountId?: string },
73
+ options: ProbeDingtalkOptions = {},
74
+ ): Promise<DingtalkProbeResult> {
75
+ if (!creds?.clientId || !creds?.clientSecret) {
76
+ return {
77
+ ok: false,
78
+ error: "missing credentials (clientId, clientSecret)",
79
+ };
80
+ }
81
+ if (options.abortSignal?.aborted) {
82
+ return {
83
+ ok: false,
84
+ clientId: creds.clientId,
85
+ error: "probe aborted",
86
+ };
87
+ }
88
+
89
+ const timeoutMs = options.timeoutMs ?? DINGTALK_PROBE_REQUEST_TIMEOUT_MS;
90
+
91
+ // Return cached result if still valid.
92
+ const cacheKey = creds.accountId ?? `${creds.clientId}:${creds.clientSecret.slice(0, 8)}`;
93
+ const cached = probeCache.get(cacheKey);
94
+ if (cached && cached.expiresAt > Date.now()) {
95
+ return cached.result;
96
+ }
97
+
98
+ try {
99
+ // Get access token
100
+ const tokenResponse = await raceWithTimeoutAndAbort(
101
+ dingtalkHttp.post<{ accessToken?: string }>(
102
+ "https://api.dingtalk.com/v1.0/oauth2/accessToken",
103
+ { appKey: creds.clientId, appSecret: creds.clientSecret },
104
+ ),
105
+ { timeoutMs, abortSignal: options.abortSignal },
106
+ );
107
+
108
+ if (tokenResponse.status === "aborted") {
109
+ return {
110
+ ok: false,
111
+ clientId: creds.clientId,
112
+ error: "probe aborted",
113
+ };
114
+ }
115
+ if (tokenResponse.status === "timeout") {
116
+ return setCachedProbeResult(
117
+ cacheKey,
118
+ {
119
+ ok: false,
120
+ clientId: creds.clientId,
121
+ error: `probe timed out after ${timeoutMs}ms`,
122
+ },
123
+ PROBE_ERROR_TTL_MS,
124
+ );
125
+ }
126
+
127
+ const tokenData = tokenResponse.value.data;
128
+ if (!tokenData.accessToken) {
129
+ return setCachedProbeResult(
130
+ cacheKey,
131
+ {
132
+ ok: false,
133
+ clientId: creds.clientId,
134
+ error: "failed to get access token",
135
+ },
136
+ PROBE_ERROR_TTL_MS,
137
+ );
138
+ }
139
+
140
+ // Get bot info
141
+ const botResponse = await raceWithTimeoutAndAbort(
142
+ dingtalkHttp.get<DingtalkBotInfoResponse>(
143
+ "https://api.dingtalk.com/v1.0/contact/users/me",
144
+ {
145
+ headers: {
146
+ "x-acs-dingtalk-access-token": tokenData.accessToken,
147
+ },
148
+ },
149
+ ),
150
+ { timeoutMs, abortSignal: options.abortSignal },
151
+ );
152
+
153
+ if (botResponse.status === "aborted") {
154
+ return {
155
+ ok: false,
156
+ clientId: creds.clientId,
157
+ error: "probe aborted",
158
+ };
159
+ }
160
+ if (botResponse.status === "timeout") {
161
+ return setCachedProbeResult(
162
+ cacheKey,
163
+ {
164
+ ok: false,
165
+ clientId: creds.clientId,
166
+ error: `probe timed out after ${timeoutMs}ms`,
167
+ },
168
+ PROBE_ERROR_TTL_MS,
169
+ );
170
+ }
171
+
172
+ const botData = botResponse.value.data;
173
+ if (botData.errcode && botData.errcode !== 0) {
174
+ return setCachedProbeResult(
175
+ cacheKey,
176
+ {
177
+ ok: false,
178
+ clientId: creds.clientId,
179
+ error: `API error: ${botData.errmsg || `code ${botData.errcode}`}`,
180
+ },
181
+ PROBE_ERROR_TTL_MS,
182
+ );
183
+ }
184
+
185
+ return setCachedProbeResult(
186
+ cacheKey,
187
+ {
188
+ ok: true,
189
+ clientId: creds.clientId,
190
+ botName: botData.nick,
191
+ },
192
+ PROBE_SUCCESS_TTL_MS,
193
+ );
194
+ } catch (err) {
195
+ return setCachedProbeResult(
196
+ cacheKey,
197
+ {
198
+ ok: false,
199
+ clientId: creds.clientId,
200
+ error: err instanceof Error ? err.message : String(err),
201
+ },
202
+ PROBE_ERROR_TTL_MS,
203
+ );
204
+ }
205
+ }
206
+
207
+ /** Clear the probe cache (for testing). */
208
+ export function clearProbeCache(): void {
209
+ probeCache.clear();
210
+ }