@blade-hq/agent-react 2612.0.0-beta.6 → 2612.0.0-beta.61

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 (112) hide show
  1. package/README.md +30 -1
  2. package/dist/chat/AgentLoopBlock.d.ts +0 -2
  3. package/dist/chat/AskUserQuestionBlock.d.ts +3 -20
  4. package/dist/chat/AssistantTurnBlock.d.ts +1 -9
  5. package/dist/chat/AttachmentPreviewDialog.d.ts +0 -1
  6. package/dist/chat/ChatLoadingIndicator.d.ts +7 -0
  7. package/dist/chat/ContextAttachmentPills.d.ts +4 -0
  8. package/dist/chat/CurrentPlanPanel.d.ts +0 -3
  9. package/dist/chat/FileDeliveryCards.d.ts +0 -4
  10. package/dist/chat/FinalArtifactCards.d.ts +0 -1
  11. package/dist/chat/ImageLightbox.d.ts +1 -1
  12. package/dist/chat/LiteMessageList.d.ts +1 -3
  13. package/dist/chat/MessageFileAttachmentList.d.ts +0 -5
  14. package/dist/chat/QuestionnaireQuestionBlock.d.ts +11 -0
  15. package/dist/chat/SessionReplayBar.d.ts +0 -1
  16. package/dist/chat/TextAttachmentPills.d.ts +0 -3
  17. package/dist/chat/TurnNavRail.d.ts +0 -3
  18. package/dist/chat/WorkflowRunBlock.d.ts +21 -4
  19. package/dist/chat/ai-elements/shimmer.d.ts +0 -4
  20. package/dist/chat/customization.d.ts +1 -1
  21. package/dist/chat/index.d.ts +1 -4
  22. package/dist/chat/lib/citations.d.ts +2 -23
  23. package/dist/chat/markdown/ExternalAnchor.d.ts +2 -2
  24. package/dist/chat/markdown/MarkdownContent.d.ts +3 -0
  25. package/dist/chat/message-list-blocks.d.ts +0 -1
  26. package/dist/chat/runtime/actions.d.ts +2 -3
  27. package/dist/chat/runtime/background-task-dismissals.d.ts +0 -1
  28. package/dist/chat/runtime/composer-channels.d.ts +0 -3
  29. package/dist/chat/runtime/input-cache-reset.d.ts +0 -5
  30. package/dist/chat/runtime/input-services.d.ts +10 -6
  31. package/dist/chat/runtime/session-source.d.ts +0 -5
  32. package/dist/chat/runtime/use-chat-actions.d.ts +0 -4
  33. package/dist/{chat-OCLOVB3H.css → chat-IHPRU35X.css} +5 -18
  34. package/dist/chat.css +5 -18
  35. package/dist/chunk-2E6DQCXM.js +602 -0
  36. package/dist/chunk-2E6DQCXM.js.map +1 -0
  37. package/dist/chunk-ARX4JV5T.js +1988 -0
  38. package/dist/chunk-ARX4JV5T.js.map +1 -0
  39. package/dist/chunk-HBMFIJG2.js +13622 -0
  40. package/dist/chunk-HBMFIJG2.js.map +1 -0
  41. package/dist/chunk-HS5G33FO.js +6894 -0
  42. package/dist/chunk-HS5G33FO.js.map +1 -0
  43. package/dist/{chunk-UKQFSXGC.js → chunk-MAFNMG2O.js} +2419 -13726
  44. package/dist/chunk-MAFNMG2O.js.map +1 -0
  45. package/dist/{chunk-XJLFFRQP.js → chunk-UC7SY3G5.js} +3744 -25994
  46. package/dist/chunk-UC7SY3G5.js.map +1 -0
  47. package/dist/chunk-VSIUEXGV.js +4981 -0
  48. package/dist/chunk-VSIUEXGV.js.map +1 -0
  49. package/dist/chunk-XV6AO37F.js +9480 -0
  50. package/dist/chunk-XV6AO37F.js.map +1 -0
  51. package/dist/components/AccountConnectors.d.ts +13 -0
  52. package/dist/components/BrowserConnectionDialog.d.ts +7 -0
  53. package/dist/components/ChatInput.d.ts +1 -15
  54. package/dist/components/ConnectorAuthorizationProgress.d.ts +6 -0
  55. package/dist/components/ConnectorPanel.d.ts +3 -1
  56. package/dist/components/ConnectorRuntimeDiagnostics.d.ts +5 -0
  57. package/dist/components/DeviceConnection.d.ts +15 -0
  58. package/dist/components/FeishuCapabilitySelection.d.ts +14 -0
  59. package/dist/components/FeishuPermissionStatus.d.ts +5 -0
  60. package/dist/components/LlmAdvancedSettings.d.ts +0 -1
  61. package/dist/components/PlanUpdateBlock.d.ts +0 -1
  62. package/dist/components/SessionPluginConfigForm.d.ts +3 -1
  63. package/dist/components/plugin-connector.d.ts +1 -0
  64. package/dist/connectors.d.ts +1 -0
  65. package/dist/connectors.js +9 -0
  66. package/dist/connectors.js.map +1 -0
  67. package/dist/embed/blade-chat-element.d.ts +0 -8
  68. package/dist/embed/entry.d.ts +8 -19
  69. package/dist/hooks/use-message-pin.d.ts +1 -1
  70. package/dist/host.d.ts +0 -4
  71. package/dist/index.d.ts +1 -0
  72. package/dist/index.js +12 -3
  73. package/dist/internal.d.ts +4 -2
  74. package/dist/internal.js +45 -70
  75. package/dist/internal.js.map +1 -1
  76. package/dist/lib/message-shortcuts.d.ts +5 -0
  77. package/dist/questions.d.ts +7 -0
  78. package/dist/questions.js +909 -0
  79. package/dist/questions.js.map +1 -0
  80. package/dist/rich-input/ConnectButton.d.ts +7 -5
  81. package/dist/rich-input/FileCompletionMenu.d.ts +5 -11
  82. package/dist/rich-input/InputActionSubmenu.d.ts +10 -0
  83. package/dist/rich-input/SkillActionMenu.d.ts +10 -0
  84. package/dist/rich-input/SkillStatusBar.d.ts +0 -6
  85. package/dist/rich-input/extensions/skill-mention.d.ts +3 -20
  86. package/dist/rich-input/index.d.ts +3 -4
  87. package/dist/rich-input/lib/composer-content.d.ts +7 -22
  88. package/dist/rich-input/lib/plugin-suggestions.d.ts +5 -5
  89. package/dist/rich-input/lib/reference-candidates.d.ts +0 -4
  90. package/dist/rich-input/lib/skill-suggestions.d.ts +1 -1
  91. package/dist/rich-input/lib/user-home.d.ts +0 -17
  92. package/dist/rich-input/services.d.ts +2 -3
  93. package/dist/rich-input/voice/VoiceWaveform.d.ts +0 -3
  94. package/dist/rich-input.js +786 -1300
  95. package/dist/rich-input.js.map +1 -1
  96. package/dist/style.css +16 -55
  97. package/dist/style.full.css +23 -77
  98. package/dist/tool-details.d.ts +8 -0
  99. package/dist/tool-details.js +24 -0
  100. package/dist/tool-details.js.map +1 -0
  101. package/package.json +15 -3
  102. package/public-api.md +10 -5
  103. package/dist/chat/tool-renderers/KbSearchRenderer.d.ts +0 -2
  104. package/dist/chat/tool-renderers/kb-search-result.d.ts +0 -19
  105. package/dist/chunk-IRBOKMF5.js +0 -258
  106. package/dist/chunk-IRBOKMF5.js.map +0 -1
  107. package/dist/chunk-UKQFSXGC.js.map +0 -1
  108. package/dist/chunk-XJLFFRQP.js.map +0 -1
  109. package/dist/lib/agent-computer-command.d.ts +0 -32
  110. package/dist/rich-input/extensions/kb-mention.d.ts +0 -18
  111. package/dist/rich-input/extensions/workflow-mention.d.ts +0 -10
  112. package/dist/rich-input/lib/kb-suggestions.d.ts +0 -37
@@ -0,0 +1,1988 @@
1
+ import {
2
+ Button,
3
+ cn,
4
+ dist_exports3 as dist_exports,
5
+ loopTabInShadowRoot,
6
+ useOverlayRoot
7
+ } from "./chunk-HS5G33FO.js";
8
+
9
+ // src/components/DeviceConnection.tsx
10
+ import { useEffect, useRef, useState } from "react";
11
+
12
+ // ../../node_modules/.pnpm/qrcode.react@4.2.0_react@19.2.4/node_modules/qrcode.react/lib/esm/index.js
13
+ import React from "react";
14
+ var __defProp = Object.defineProperty;
15
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
16
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
17
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
18
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
19
+ var __spreadValues = (a, b) => {
20
+ for (var prop in b || (b = {}))
21
+ if (__hasOwnProp.call(b, prop))
22
+ __defNormalProp(a, prop, b[prop]);
23
+ if (__getOwnPropSymbols)
24
+ for (var prop of __getOwnPropSymbols(b)) {
25
+ if (__propIsEnum.call(b, prop))
26
+ __defNormalProp(a, prop, b[prop]);
27
+ }
28
+ return a;
29
+ };
30
+ var __objRest = (source, exclude) => {
31
+ var target = {};
32
+ for (var prop in source)
33
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
34
+ target[prop] = source[prop];
35
+ if (source != null && __getOwnPropSymbols)
36
+ for (var prop of __getOwnPropSymbols(source)) {
37
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
38
+ target[prop] = source[prop];
39
+ }
40
+ return target;
41
+ };
42
+ var qrcodegen;
43
+ ((qrcodegen2) => {
44
+ const _QrCode = class _QrCode2 {
45
+ /*-- Constructor (low level) and fields --*/
46
+ // Creates a new QR Code with the given version number,
47
+ // error correction level, data codeword bytes, and mask number.
48
+ // This is a low-level API that most users should not use directly.
49
+ // A mid-level API is the encodeSegments() function.
50
+ constructor(version, errorCorrectionLevel, dataCodewords, msk) {
51
+ this.version = version;
52
+ this.errorCorrectionLevel = errorCorrectionLevel;
53
+ this.modules = [];
54
+ this.isFunction = [];
55
+ if (version < _QrCode2.MIN_VERSION || version > _QrCode2.MAX_VERSION)
56
+ throw new RangeError("Version value out of range");
57
+ if (msk < -1 || msk > 7)
58
+ throw new RangeError("Mask value out of range");
59
+ this.size = version * 4 + 17;
60
+ let row = [];
61
+ for (let i = 0; i < this.size; i++)
62
+ row.push(false);
63
+ for (let i = 0; i < this.size; i++) {
64
+ this.modules.push(row.slice());
65
+ this.isFunction.push(row.slice());
66
+ }
67
+ this.drawFunctionPatterns();
68
+ const allCodewords = this.addEccAndInterleave(dataCodewords);
69
+ this.drawCodewords(allCodewords);
70
+ if (msk == -1) {
71
+ let minPenalty = 1e9;
72
+ for (let i = 0; i < 8; i++) {
73
+ this.applyMask(i);
74
+ this.drawFormatBits(i);
75
+ const penalty = this.getPenaltyScore();
76
+ if (penalty < minPenalty) {
77
+ msk = i;
78
+ minPenalty = penalty;
79
+ }
80
+ this.applyMask(i);
81
+ }
82
+ }
83
+ assert(0 <= msk && msk <= 7);
84
+ this.mask = msk;
85
+ this.applyMask(msk);
86
+ this.drawFormatBits(msk);
87
+ this.isFunction = [];
88
+ }
89
+ /*-- Static factory functions (high level) --*/
90
+ // Returns a QR Code representing the given Unicode text string at the given error correction level.
91
+ // As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer
92
+ // Unicode code points (not UTF-16 code units) if the low error correction level is used. The smallest possible
93
+ // QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the
94
+ // ecl argument if it can be done without increasing the version.
95
+ static encodeText(text, ecl) {
96
+ const segs = qrcodegen2.QrSegment.makeSegments(text);
97
+ return _QrCode2.encodeSegments(segs, ecl);
98
+ }
99
+ // Returns a QR Code representing the given binary data at the given error correction level.
100
+ // This function always encodes using the binary segment mode, not any text mode. The maximum number of
101
+ // bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
102
+ // The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
103
+ static encodeBinary(data, ecl) {
104
+ const seg = qrcodegen2.QrSegment.makeBytes(data);
105
+ return _QrCode2.encodeSegments([seg], ecl);
106
+ }
107
+ /*-- Static factory functions (mid level) --*/
108
+ // Returns a QR Code representing the given segments with the given encoding parameters.
109
+ // The smallest possible QR Code version within the given range is automatically
110
+ // chosen for the output. Iff boostEcl is true, then the ECC level of the result
111
+ // may be higher than the ecl argument if it can be done without increasing the
112
+ // version. The mask number is either between 0 to 7 (inclusive) to force that
113
+ // mask, or -1 to automatically choose an appropriate mask (which may be slow).
114
+ // This function allows the user to create a custom sequence of segments that switches
115
+ // between modes (such as alphanumeric and byte) to encode text in less space.
116
+ // This is a mid-level API; the high-level API is encodeText() and encodeBinary().
117
+ static encodeSegments(segs, ecl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
118
+ if (!(_QrCode2.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= _QrCode2.MAX_VERSION) || mask < -1 || mask > 7)
119
+ throw new RangeError("Invalid value");
120
+ let version;
121
+ let dataUsedBits;
122
+ for (version = minVersion; ; version++) {
123
+ const dataCapacityBits2 = _QrCode2.getNumDataCodewords(version, ecl) * 8;
124
+ const usedBits = QrSegment.getTotalBits(segs, version);
125
+ if (usedBits <= dataCapacityBits2) {
126
+ dataUsedBits = usedBits;
127
+ break;
128
+ }
129
+ if (version >= maxVersion)
130
+ throw new RangeError("Data too long");
131
+ }
132
+ for (const newEcl of [_QrCode2.Ecc.MEDIUM, _QrCode2.Ecc.QUARTILE, _QrCode2.Ecc.HIGH]) {
133
+ if (boostEcl && dataUsedBits <= _QrCode2.getNumDataCodewords(version, newEcl) * 8)
134
+ ecl = newEcl;
135
+ }
136
+ let bb = [];
137
+ for (const seg of segs) {
138
+ appendBits(seg.mode.modeBits, 4, bb);
139
+ appendBits(seg.numChars, seg.mode.numCharCountBits(version), bb);
140
+ for (const b of seg.getData())
141
+ bb.push(b);
142
+ }
143
+ assert(bb.length == dataUsedBits);
144
+ const dataCapacityBits = _QrCode2.getNumDataCodewords(version, ecl) * 8;
145
+ assert(bb.length <= dataCapacityBits);
146
+ appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
147
+ appendBits(0, (8 - bb.length % 8) % 8, bb);
148
+ assert(bb.length % 8 == 0);
149
+ for (let padByte = 236; bb.length < dataCapacityBits; padByte ^= 236 ^ 17)
150
+ appendBits(padByte, 8, bb);
151
+ let dataCodewords = [];
152
+ while (dataCodewords.length * 8 < bb.length)
153
+ dataCodewords.push(0);
154
+ bb.forEach((b, i) => dataCodewords[i >>> 3] |= b << 7 - (i & 7));
155
+ return new _QrCode2(version, ecl, dataCodewords, mask);
156
+ }
157
+ /*-- Accessor methods --*/
158
+ // Returns the color of the module (pixel) at the given coordinates, which is false
159
+ // for light or true for dark. The top left corner has the coordinates (x=0, y=0).
160
+ // If the given coordinates are out of bounds, then false (light) is returned.
161
+ getModule(x, y) {
162
+ return 0 <= x && x < this.size && 0 <= y && y < this.size && this.modules[y][x];
163
+ }
164
+ // Modified to expose modules for easy access
165
+ getModules() {
166
+ return this.modules;
167
+ }
168
+ /*-- Private helper methods for constructor: Drawing function modules --*/
169
+ // Reads this object's version field, and draws and marks all function modules.
170
+ drawFunctionPatterns() {
171
+ for (let i = 0; i < this.size; i++) {
172
+ this.setFunctionModule(6, i, i % 2 == 0);
173
+ this.setFunctionModule(i, 6, i % 2 == 0);
174
+ }
175
+ this.drawFinderPattern(3, 3);
176
+ this.drawFinderPattern(this.size - 4, 3);
177
+ this.drawFinderPattern(3, this.size - 4);
178
+ const alignPatPos = this.getAlignmentPatternPositions();
179
+ const numAlign = alignPatPos.length;
180
+ for (let i = 0; i < numAlign; i++) {
181
+ for (let j = 0; j < numAlign; j++) {
182
+ if (!(i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0))
183
+ this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
184
+ }
185
+ }
186
+ this.drawFormatBits(0);
187
+ this.drawVersion();
188
+ }
189
+ // Draws two copies of the format bits (with its own error correction code)
190
+ // based on the given mask and this object's error correction level field.
191
+ drawFormatBits(mask) {
192
+ const data = this.errorCorrectionLevel.formatBits << 3 | mask;
193
+ let rem = data;
194
+ for (let i = 0; i < 10; i++)
195
+ rem = rem << 1 ^ (rem >>> 9) * 1335;
196
+ const bits = (data << 10 | rem) ^ 21522;
197
+ assert(bits >>> 15 == 0);
198
+ for (let i = 0; i <= 5; i++)
199
+ this.setFunctionModule(8, i, getBit(bits, i));
200
+ this.setFunctionModule(8, 7, getBit(bits, 6));
201
+ this.setFunctionModule(8, 8, getBit(bits, 7));
202
+ this.setFunctionModule(7, 8, getBit(bits, 8));
203
+ for (let i = 9; i < 15; i++)
204
+ this.setFunctionModule(14 - i, 8, getBit(bits, i));
205
+ for (let i = 0; i < 8; i++)
206
+ this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
207
+ for (let i = 8; i < 15; i++)
208
+ this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
209
+ this.setFunctionModule(8, this.size - 8, true);
210
+ }
211
+ // Draws two copies of the version bits (with its own error correction code),
212
+ // based on this object's version field, iff 7 <= version <= 40.
213
+ drawVersion() {
214
+ if (this.version < 7)
215
+ return;
216
+ let rem = this.version;
217
+ for (let i = 0; i < 12; i++)
218
+ rem = rem << 1 ^ (rem >>> 11) * 7973;
219
+ const bits = this.version << 12 | rem;
220
+ assert(bits >>> 18 == 0);
221
+ for (let i = 0; i < 18; i++) {
222
+ const color = getBit(bits, i);
223
+ const a = this.size - 11 + i % 3;
224
+ const b = Math.floor(i / 3);
225
+ this.setFunctionModule(a, b, color);
226
+ this.setFunctionModule(b, a, color);
227
+ }
228
+ }
229
+ // Draws a 9*9 finder pattern including the border separator,
230
+ // with the center module at (x, y). Modules can be out of bounds.
231
+ drawFinderPattern(x, y) {
232
+ for (let dy = -4; dy <= 4; dy++) {
233
+ for (let dx = -4; dx <= 4; dx++) {
234
+ const dist = Math.max(Math.abs(dx), Math.abs(dy));
235
+ const xx = x + dx;
236
+ const yy = y + dy;
237
+ if (0 <= xx && xx < this.size && 0 <= yy && yy < this.size)
238
+ this.setFunctionModule(xx, yy, dist != 2 && dist != 4);
239
+ }
240
+ }
241
+ }
242
+ // Draws a 5*5 alignment pattern, with the center module
243
+ // at (x, y). All modules must be in bounds.
244
+ drawAlignmentPattern(x, y) {
245
+ for (let dy = -2; dy <= 2; dy++) {
246
+ for (let dx = -2; dx <= 2; dx++)
247
+ this.setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1);
248
+ }
249
+ }
250
+ // Sets the color of a module and marks it as a function module.
251
+ // Only used by the constructor. Coordinates must be in bounds.
252
+ setFunctionModule(x, y, isDark) {
253
+ this.modules[y][x] = isDark;
254
+ this.isFunction[y][x] = true;
255
+ }
256
+ /*-- Private helper methods for constructor: Codewords and masking --*/
257
+ // Returns a new byte string representing the given data with the appropriate error correction
258
+ // codewords appended to it, based on this object's version and error correction level.
259
+ addEccAndInterleave(data) {
260
+ const ver = this.version;
261
+ const ecl = this.errorCorrectionLevel;
262
+ if (data.length != _QrCode2.getNumDataCodewords(ver, ecl))
263
+ throw new RangeError("Invalid argument");
264
+ const numBlocks = _QrCode2.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
265
+ const blockEccLen = _QrCode2.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver];
266
+ const rawCodewords = Math.floor(_QrCode2.getNumRawDataModules(ver) / 8);
267
+ const numShortBlocks = numBlocks - rawCodewords % numBlocks;
268
+ const shortBlockLen = Math.floor(rawCodewords / numBlocks);
269
+ let blocks = [];
270
+ const rsDiv = _QrCode2.reedSolomonComputeDivisor(blockEccLen);
271
+ for (let i = 0, k = 0; i < numBlocks; i++) {
272
+ let dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
273
+ k += dat.length;
274
+ const ecc = _QrCode2.reedSolomonComputeRemainder(dat, rsDiv);
275
+ if (i < numShortBlocks)
276
+ dat.push(0);
277
+ blocks.push(dat.concat(ecc));
278
+ }
279
+ let result = [];
280
+ for (let i = 0; i < blocks[0].length; i++) {
281
+ blocks.forEach((block, j) => {
282
+ if (i != shortBlockLen - blockEccLen || j >= numShortBlocks)
283
+ result.push(block[i]);
284
+ });
285
+ }
286
+ assert(result.length == rawCodewords);
287
+ return result;
288
+ }
289
+ // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
290
+ // data area of this QR Code. Function modules need to be marked off before this is called.
291
+ drawCodewords(data) {
292
+ if (data.length != Math.floor(_QrCode2.getNumRawDataModules(this.version) / 8))
293
+ throw new RangeError("Invalid argument");
294
+ let i = 0;
295
+ for (let right = this.size - 1; right >= 1; right -= 2) {
296
+ if (right == 6)
297
+ right = 5;
298
+ for (let vert = 0; vert < this.size; vert++) {
299
+ for (let j = 0; j < 2; j++) {
300
+ const x = right - j;
301
+ const upward = (right + 1 & 2) == 0;
302
+ const y = upward ? this.size - 1 - vert : vert;
303
+ if (!this.isFunction[y][x] && i < data.length * 8) {
304
+ this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
305
+ i++;
306
+ }
307
+ }
308
+ }
309
+ }
310
+ assert(i == data.length * 8);
311
+ }
312
+ // XORs the codeword modules in this QR Code with the given mask pattern.
313
+ // The function modules must be marked and the codeword bits must be drawn
314
+ // before masking. Due to the arithmetic of XOR, calling applyMask() with
315
+ // the same mask value a second time will undo the mask. A final well-formed
316
+ // QR Code needs exactly one (not zero, two, etc.) mask applied.
317
+ applyMask(mask) {
318
+ if (mask < 0 || mask > 7)
319
+ throw new RangeError("Mask value out of range");
320
+ for (let y = 0; y < this.size; y++) {
321
+ for (let x = 0; x < this.size; x++) {
322
+ let invert;
323
+ switch (mask) {
324
+ case 0:
325
+ invert = (x + y) % 2 == 0;
326
+ break;
327
+ case 1:
328
+ invert = y % 2 == 0;
329
+ break;
330
+ case 2:
331
+ invert = x % 3 == 0;
332
+ break;
333
+ case 3:
334
+ invert = (x + y) % 3 == 0;
335
+ break;
336
+ case 4:
337
+ invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 == 0;
338
+ break;
339
+ case 5:
340
+ invert = x * y % 2 + x * y % 3 == 0;
341
+ break;
342
+ case 6:
343
+ invert = (x * y % 2 + x * y % 3) % 2 == 0;
344
+ break;
345
+ case 7:
346
+ invert = ((x + y) % 2 + x * y % 3) % 2 == 0;
347
+ break;
348
+ default:
349
+ throw new Error("Unreachable");
350
+ }
351
+ if (!this.isFunction[y][x] && invert)
352
+ this.modules[y][x] = !this.modules[y][x];
353
+ }
354
+ }
355
+ }
356
+ // Calculates and returns the penalty score based on state of this QR Code's current modules.
357
+ // This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
358
+ getPenaltyScore() {
359
+ let result = 0;
360
+ for (let y = 0; y < this.size; y++) {
361
+ let runColor = false;
362
+ let runX = 0;
363
+ let runHistory = [0, 0, 0, 0, 0, 0, 0];
364
+ for (let x = 0; x < this.size; x++) {
365
+ if (this.modules[y][x] == runColor) {
366
+ runX++;
367
+ if (runX == 5)
368
+ result += _QrCode2.PENALTY_N1;
369
+ else if (runX > 5)
370
+ result++;
371
+ } else {
372
+ this.finderPenaltyAddHistory(runX, runHistory);
373
+ if (!runColor)
374
+ result += this.finderPenaltyCountPatterns(runHistory) * _QrCode2.PENALTY_N3;
375
+ runColor = this.modules[y][x];
376
+ runX = 1;
377
+ }
378
+ }
379
+ result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * _QrCode2.PENALTY_N3;
380
+ }
381
+ for (let x = 0; x < this.size; x++) {
382
+ let runColor = false;
383
+ let runY = 0;
384
+ let runHistory = [0, 0, 0, 0, 0, 0, 0];
385
+ for (let y = 0; y < this.size; y++) {
386
+ if (this.modules[y][x] == runColor) {
387
+ runY++;
388
+ if (runY == 5)
389
+ result += _QrCode2.PENALTY_N1;
390
+ else if (runY > 5)
391
+ result++;
392
+ } else {
393
+ this.finderPenaltyAddHistory(runY, runHistory);
394
+ if (!runColor)
395
+ result += this.finderPenaltyCountPatterns(runHistory) * _QrCode2.PENALTY_N3;
396
+ runColor = this.modules[y][x];
397
+ runY = 1;
398
+ }
399
+ }
400
+ result += this.finderPenaltyTerminateAndCount(runColor, runY, runHistory) * _QrCode2.PENALTY_N3;
401
+ }
402
+ for (let y = 0; y < this.size - 1; y++) {
403
+ for (let x = 0; x < this.size - 1; x++) {
404
+ const color = this.modules[y][x];
405
+ if (color == this.modules[y][x + 1] && color == this.modules[y + 1][x] && color == this.modules[y + 1][x + 1])
406
+ result += _QrCode2.PENALTY_N2;
407
+ }
408
+ }
409
+ let dark = 0;
410
+ for (const row of this.modules)
411
+ dark = row.reduce((sum, color) => sum + (color ? 1 : 0), dark);
412
+ const total = this.size * this.size;
413
+ const k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
414
+ assert(0 <= k && k <= 9);
415
+ result += k * _QrCode2.PENALTY_N4;
416
+ assert(0 <= result && result <= 2568888);
417
+ return result;
418
+ }
419
+ /*-- Private helper functions --*/
420
+ // Returns an ascending list of positions of alignment patterns for this version number.
421
+ // Each position is in the range [0,177), and are used on both the x and y axes.
422
+ // This could be implemented as lookup table of 40 variable-length lists of integers.
423
+ getAlignmentPatternPositions() {
424
+ if (this.version == 1)
425
+ return [];
426
+ else {
427
+ const numAlign = Math.floor(this.version / 7) + 2;
428
+ const step = this.version == 32 ? 26 : Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
429
+ let result = [6];
430
+ for (let pos = this.size - 7; result.length < numAlign; pos -= step)
431
+ result.splice(1, 0, pos);
432
+ return result;
433
+ }
434
+ }
435
+ // Returns the number of data bits that can be stored in a QR Code of the given version number, after
436
+ // all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
437
+ // The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
438
+ static getNumRawDataModules(ver) {
439
+ if (ver < _QrCode2.MIN_VERSION || ver > _QrCode2.MAX_VERSION)
440
+ throw new RangeError("Version number out of range");
441
+ let result = (16 * ver + 128) * ver + 64;
442
+ if (ver >= 2) {
443
+ const numAlign = Math.floor(ver / 7) + 2;
444
+ result -= (25 * numAlign - 10) * numAlign - 55;
445
+ if (ver >= 7)
446
+ result -= 36;
447
+ }
448
+ assert(208 <= result && result <= 29648);
449
+ return result;
450
+ }
451
+ // Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
452
+ // QR Code of the given version number and error correction level, with remainder bits discarded.
453
+ // This stateless pure function could be implemented as a (40*4)-cell lookup table.
454
+ static getNumDataCodewords(ver, ecl) {
455
+ return Math.floor(_QrCode2.getNumRawDataModules(ver) / 8) - _QrCode2.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] * _QrCode2.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
456
+ }
457
+ // Returns a Reed-Solomon ECC generator polynomial for the given degree. This could be
458
+ // implemented as a lookup table over all possible parameter values, instead of as an algorithm.
459
+ static reedSolomonComputeDivisor(degree) {
460
+ if (degree < 1 || degree > 255)
461
+ throw new RangeError("Degree out of range");
462
+ let result = [];
463
+ for (let i = 0; i < degree - 1; i++)
464
+ result.push(0);
465
+ result.push(1);
466
+ let root = 1;
467
+ for (let i = 0; i < degree; i++) {
468
+ for (let j = 0; j < result.length; j++) {
469
+ result[j] = _QrCode2.reedSolomonMultiply(result[j], root);
470
+ if (j + 1 < result.length)
471
+ result[j] ^= result[j + 1];
472
+ }
473
+ root = _QrCode2.reedSolomonMultiply(root, 2);
474
+ }
475
+ return result;
476
+ }
477
+ // Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials.
478
+ static reedSolomonComputeRemainder(data, divisor) {
479
+ let result = divisor.map((_) => 0);
480
+ for (const b of data) {
481
+ const factor = b ^ result.shift();
482
+ result.push(0);
483
+ divisor.forEach((coef, i) => result[i] ^= _QrCode2.reedSolomonMultiply(coef, factor));
484
+ }
485
+ return result;
486
+ }
487
+ // Returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and result
488
+ // are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8.
489
+ static reedSolomonMultiply(x, y) {
490
+ if (x >>> 8 != 0 || y >>> 8 != 0)
491
+ throw new RangeError("Byte out of range");
492
+ let z = 0;
493
+ for (let i = 7; i >= 0; i--) {
494
+ z = z << 1 ^ (z >>> 7) * 285;
495
+ z ^= (y >>> i & 1) * x;
496
+ }
497
+ assert(z >>> 8 == 0);
498
+ return z;
499
+ }
500
+ // Can only be called immediately after a light run is added, and
501
+ // returns either 0, 1, or 2. A helper function for getPenaltyScore().
502
+ finderPenaltyCountPatterns(runHistory) {
503
+ const n = runHistory[1];
504
+ assert(n <= this.size * 3);
505
+ const core = n > 0 && runHistory[2] == n && runHistory[3] == n * 3 && runHistory[4] == n && runHistory[5] == n;
506
+ return (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0) + (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0);
507
+ }
508
+ // Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
509
+ finderPenaltyTerminateAndCount(currentRunColor, currentRunLength, runHistory) {
510
+ if (currentRunColor) {
511
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
512
+ currentRunLength = 0;
513
+ }
514
+ currentRunLength += this.size;
515
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
516
+ return this.finderPenaltyCountPatterns(runHistory);
517
+ }
518
+ // Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
519
+ finderPenaltyAddHistory(currentRunLength, runHistory) {
520
+ if (runHistory[0] == 0)
521
+ currentRunLength += this.size;
522
+ runHistory.pop();
523
+ runHistory.unshift(currentRunLength);
524
+ }
525
+ };
526
+ _QrCode.MIN_VERSION = 1;
527
+ _QrCode.MAX_VERSION = 40;
528
+ _QrCode.PENALTY_N1 = 3;
529
+ _QrCode.PENALTY_N2 = 3;
530
+ _QrCode.PENALTY_N3 = 40;
531
+ _QrCode.PENALTY_N4 = 10;
532
+ _QrCode.ECC_CODEWORDS_PER_BLOCK = [
533
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
534
+ //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
535
+ [-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
536
+ // Low
537
+ [-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28],
538
+ // Medium
539
+ [-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
540
+ // Quartile
541
+ [-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]
542
+ // High
543
+ ];
544
+ _QrCode.NUM_ERROR_CORRECTION_BLOCKS = [
545
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
546
+ //0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
547
+ [-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25],
548
+ // Low
549
+ [-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49],
550
+ // Medium
551
+ [-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68],
552
+ // Quartile
553
+ [-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81]
554
+ // High
555
+ ];
556
+ let QrCode = _QrCode;
557
+ qrcodegen2.QrCode = _QrCode;
558
+ function appendBits(val, len, bb) {
559
+ if (len < 0 || len > 31 || val >>> len != 0)
560
+ throw new RangeError("Value out of range");
561
+ for (let i = len - 1; i >= 0; i--)
562
+ bb.push(val >>> i & 1);
563
+ }
564
+ function getBit(x, i) {
565
+ return (x >>> i & 1) != 0;
566
+ }
567
+ function assert(cond) {
568
+ if (!cond)
569
+ throw new Error("Assertion error");
570
+ }
571
+ const _QrSegment = class _QrSegment2 {
572
+ /*-- Constructor (low level) and fields --*/
573
+ // Creates a new QR Code segment with the given attributes and data.
574
+ // The character count (numChars) must agree with the mode and the bit buffer length,
575
+ // but the constraint isn't checked. The given bit buffer is cloned and stored.
576
+ constructor(mode, numChars, bitData) {
577
+ this.mode = mode;
578
+ this.numChars = numChars;
579
+ this.bitData = bitData;
580
+ if (numChars < 0)
581
+ throw new RangeError("Invalid argument");
582
+ this.bitData = bitData.slice();
583
+ }
584
+ /*-- Static factory functions (mid level) --*/
585
+ // Returns a segment representing the given binary data encoded in
586
+ // byte mode. All input byte arrays are acceptable. Any text string
587
+ // can be converted to UTF-8 bytes and encoded as a byte mode segment.
588
+ static makeBytes(data) {
589
+ let bb = [];
590
+ for (const b of data)
591
+ appendBits(b, 8, bb);
592
+ return new _QrSegment2(_QrSegment2.Mode.BYTE, data.length, bb);
593
+ }
594
+ // Returns a segment representing the given string of decimal digits encoded in numeric mode.
595
+ static makeNumeric(digits) {
596
+ if (!_QrSegment2.isNumeric(digits))
597
+ throw new RangeError("String contains non-numeric characters");
598
+ let bb = [];
599
+ for (let i = 0; i < digits.length; ) {
600
+ const n = Math.min(digits.length - i, 3);
601
+ appendBits(parseInt(digits.substring(i, i + n), 10), n * 3 + 1, bb);
602
+ i += n;
603
+ }
604
+ return new _QrSegment2(_QrSegment2.Mode.NUMERIC, digits.length, bb);
605
+ }
606
+ // Returns a segment representing the given text string encoded in alphanumeric mode.
607
+ // The characters allowed are: 0 to 9, A to Z (uppercase only), space,
608
+ // dollar, percent, asterisk, plus, hyphen, period, slash, colon.
609
+ static makeAlphanumeric(text) {
610
+ if (!_QrSegment2.isAlphanumeric(text))
611
+ throw new RangeError("String contains unencodable characters in alphanumeric mode");
612
+ let bb = [];
613
+ let i;
614
+ for (i = 0; i + 2 <= text.length; i += 2) {
615
+ let temp = _QrSegment2.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
616
+ temp += _QrSegment2.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
617
+ appendBits(temp, 11, bb);
618
+ }
619
+ if (i < text.length)
620
+ appendBits(_QrSegment2.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
621
+ return new _QrSegment2(_QrSegment2.Mode.ALPHANUMERIC, text.length, bb);
622
+ }
623
+ // Returns a new mutable list of zero or more segments to represent the given Unicode text string.
624
+ // The result may use various segment modes and switch modes to optimize the length of the bit stream.
625
+ static makeSegments(text) {
626
+ if (text == "")
627
+ return [];
628
+ else if (_QrSegment2.isNumeric(text))
629
+ return [_QrSegment2.makeNumeric(text)];
630
+ else if (_QrSegment2.isAlphanumeric(text))
631
+ return [_QrSegment2.makeAlphanumeric(text)];
632
+ else
633
+ return [_QrSegment2.makeBytes(_QrSegment2.toUtf8ByteArray(text))];
634
+ }
635
+ // Returns a segment representing an Extended Channel Interpretation
636
+ // (ECI) designator with the given assignment value.
637
+ static makeEci(assignVal) {
638
+ let bb = [];
639
+ if (assignVal < 0)
640
+ throw new RangeError("ECI assignment value out of range");
641
+ else if (assignVal < 1 << 7)
642
+ appendBits(assignVal, 8, bb);
643
+ else if (assignVal < 1 << 14) {
644
+ appendBits(2, 2, bb);
645
+ appendBits(assignVal, 14, bb);
646
+ } else if (assignVal < 1e6) {
647
+ appendBits(6, 3, bb);
648
+ appendBits(assignVal, 21, bb);
649
+ } else
650
+ throw new RangeError("ECI assignment value out of range");
651
+ return new _QrSegment2(_QrSegment2.Mode.ECI, 0, bb);
652
+ }
653
+ // Tests whether the given string can be encoded as a segment in numeric mode.
654
+ // A string is encodable iff each character is in the range 0 to 9.
655
+ static isNumeric(text) {
656
+ return _QrSegment2.NUMERIC_REGEX.test(text);
657
+ }
658
+ // Tests whether the given string can be encoded as a segment in alphanumeric mode.
659
+ // A string is encodable iff each character is in the following set: 0 to 9, A to Z
660
+ // (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
661
+ static isAlphanumeric(text) {
662
+ return _QrSegment2.ALPHANUMERIC_REGEX.test(text);
663
+ }
664
+ /*-- Methods --*/
665
+ // Returns a new copy of the data bits of this segment.
666
+ getData() {
667
+ return this.bitData.slice();
668
+ }
669
+ // (Package-private) Calculates and returns the number of bits needed to encode the given segments at
670
+ // the given version. The result is infinity if a segment has too many characters to fit its length field.
671
+ static getTotalBits(segs, version) {
672
+ let result = 0;
673
+ for (const seg of segs) {
674
+ const ccbits = seg.mode.numCharCountBits(version);
675
+ if (seg.numChars >= 1 << ccbits)
676
+ return Infinity;
677
+ result += 4 + ccbits + seg.bitData.length;
678
+ }
679
+ return result;
680
+ }
681
+ // Returns a new array of bytes representing the given string encoded in UTF-8.
682
+ static toUtf8ByteArray(str) {
683
+ str = encodeURI(str);
684
+ let result = [];
685
+ for (let i = 0; i < str.length; i++) {
686
+ if (str.charAt(i) != "%")
687
+ result.push(str.charCodeAt(i));
688
+ else {
689
+ result.push(parseInt(str.substring(i + 1, i + 3), 16));
690
+ i += 2;
691
+ }
692
+ }
693
+ return result;
694
+ }
695
+ };
696
+ _QrSegment.NUMERIC_REGEX = /^[0-9]*$/;
697
+ _QrSegment.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
698
+ _QrSegment.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
699
+ let QrSegment = _QrSegment;
700
+ qrcodegen2.QrSegment = _QrSegment;
701
+ })(qrcodegen || (qrcodegen = {}));
702
+ ((qrcodegen2) => {
703
+ let QrCode;
704
+ ((QrCode2) => {
705
+ const _Ecc = class _Ecc {
706
+ // The QR Code can tolerate about 30% erroneous codewords
707
+ /*-- Constructor and fields --*/
708
+ constructor(ordinal, formatBits) {
709
+ this.ordinal = ordinal;
710
+ this.formatBits = formatBits;
711
+ }
712
+ };
713
+ _Ecc.LOW = new _Ecc(0, 1);
714
+ _Ecc.MEDIUM = new _Ecc(1, 0);
715
+ _Ecc.QUARTILE = new _Ecc(2, 3);
716
+ _Ecc.HIGH = new _Ecc(3, 2);
717
+ let Ecc = _Ecc;
718
+ QrCode2.Ecc = _Ecc;
719
+ })(QrCode = qrcodegen2.QrCode || (qrcodegen2.QrCode = {}));
720
+ })(qrcodegen || (qrcodegen = {}));
721
+ ((qrcodegen2) => {
722
+ let QrSegment;
723
+ ((QrSegment2) => {
724
+ const _Mode = class _Mode {
725
+ /*-- Constructor and fields --*/
726
+ constructor(modeBits, numBitsCharCount) {
727
+ this.modeBits = modeBits;
728
+ this.numBitsCharCount = numBitsCharCount;
729
+ }
730
+ /*-- Method --*/
731
+ // (Package-private) Returns the bit width of the character count field for a segment in
732
+ // this mode in a QR Code at the given version number. The result is in the range [0, 16].
733
+ numCharCountBits(ver) {
734
+ return this.numBitsCharCount[Math.floor((ver + 7) / 17)];
735
+ }
736
+ };
737
+ _Mode.NUMERIC = new _Mode(1, [10, 12, 14]);
738
+ _Mode.ALPHANUMERIC = new _Mode(2, [9, 11, 13]);
739
+ _Mode.BYTE = new _Mode(4, [8, 16, 16]);
740
+ _Mode.KANJI = new _Mode(8, [8, 10, 12]);
741
+ _Mode.ECI = new _Mode(7, [0, 0, 0]);
742
+ let Mode = _Mode;
743
+ QrSegment2.Mode = _Mode;
744
+ })(QrSegment = qrcodegen2.QrSegment || (qrcodegen2.QrSegment = {}));
745
+ })(qrcodegen || (qrcodegen = {}));
746
+ var qrcodegen_default = qrcodegen;
747
+ var ERROR_LEVEL_MAP = {
748
+ L: qrcodegen_default.QrCode.Ecc.LOW,
749
+ M: qrcodegen_default.QrCode.Ecc.MEDIUM,
750
+ Q: qrcodegen_default.QrCode.Ecc.QUARTILE,
751
+ H: qrcodegen_default.QrCode.Ecc.HIGH
752
+ };
753
+ var DEFAULT_SIZE = 128;
754
+ var DEFAULT_LEVEL = "L";
755
+ var DEFAULT_BGCOLOR = "#FFFFFF";
756
+ var DEFAULT_FGCOLOR = "#000000";
757
+ var DEFAULT_INCLUDEMARGIN = false;
758
+ var DEFAULT_MINVERSION = 1;
759
+ var SPEC_MARGIN_SIZE = 4;
760
+ var DEFAULT_MARGIN_SIZE = 0;
761
+ var DEFAULT_IMG_SCALE = 0.1;
762
+ function generatePath(modules, margin = 0) {
763
+ const ops = [];
764
+ modules.forEach(function(row, y) {
765
+ let start = null;
766
+ row.forEach(function(cell, x) {
767
+ if (!cell && start !== null) {
768
+ ops.push(
769
+ `M${start + margin} ${y + margin}h${x - start}v1H${start + margin}z`
770
+ );
771
+ start = null;
772
+ return;
773
+ }
774
+ if (x === row.length - 1) {
775
+ if (!cell) {
776
+ return;
777
+ }
778
+ if (start === null) {
779
+ ops.push(`M${x + margin},${y + margin} h1v1H${x + margin}z`);
780
+ } else {
781
+ ops.push(
782
+ `M${start + margin},${y + margin} h${x + 1 - start}v1H${start + margin}z`
783
+ );
784
+ }
785
+ return;
786
+ }
787
+ if (cell && start === null) {
788
+ start = x;
789
+ }
790
+ });
791
+ });
792
+ return ops.join("");
793
+ }
794
+ function excavateModules(modules, excavation) {
795
+ return modules.slice().map((row, y) => {
796
+ if (y < excavation.y || y >= excavation.y + excavation.h) {
797
+ return row;
798
+ }
799
+ return row.map((cell, x) => {
800
+ if (x < excavation.x || x >= excavation.x + excavation.w) {
801
+ return cell;
802
+ }
803
+ return false;
804
+ });
805
+ });
806
+ }
807
+ function getImageSettings(cells, size, margin, imageSettings) {
808
+ if (imageSettings == null) {
809
+ return null;
810
+ }
811
+ const numCells = cells.length + margin * 2;
812
+ const defaultSize = Math.floor(size * DEFAULT_IMG_SCALE);
813
+ const scale = numCells / size;
814
+ const w = (imageSettings.width || defaultSize) * scale;
815
+ const h = (imageSettings.height || defaultSize) * scale;
816
+ const x = imageSettings.x == null ? cells.length / 2 - w / 2 : imageSettings.x * scale;
817
+ const y = imageSettings.y == null ? cells.length / 2 - h / 2 : imageSettings.y * scale;
818
+ const opacity = imageSettings.opacity == null ? 1 : imageSettings.opacity;
819
+ let excavation = null;
820
+ if (imageSettings.excavate) {
821
+ let floorX = Math.floor(x);
822
+ let floorY = Math.floor(y);
823
+ let ceilW = Math.ceil(w + x - floorX);
824
+ let ceilH = Math.ceil(h + y - floorY);
825
+ excavation = { x: floorX, y: floorY, w: ceilW, h: ceilH };
826
+ }
827
+ const crossOrigin = imageSettings.crossOrigin;
828
+ return { x, y, h, w, excavation, opacity, crossOrigin };
829
+ }
830
+ function getMarginSize(includeMargin, marginSize) {
831
+ if (marginSize != null) {
832
+ return Math.max(Math.floor(marginSize), 0);
833
+ }
834
+ return includeMargin ? SPEC_MARGIN_SIZE : DEFAULT_MARGIN_SIZE;
835
+ }
836
+ function useQRCode({
837
+ value,
838
+ level,
839
+ minVersion,
840
+ includeMargin,
841
+ marginSize,
842
+ imageSettings,
843
+ size,
844
+ boostLevel
845
+ }) {
846
+ let qrcode = React.useMemo(() => {
847
+ const values = Array.isArray(value) ? value : [value];
848
+ const segments = values.reduce((accum, v) => {
849
+ accum.push(...qrcodegen_default.QrSegment.makeSegments(v));
850
+ return accum;
851
+ }, []);
852
+ return qrcodegen_default.QrCode.encodeSegments(
853
+ segments,
854
+ ERROR_LEVEL_MAP[level],
855
+ minVersion,
856
+ void 0,
857
+ void 0,
858
+ boostLevel
859
+ );
860
+ }, [value, level, minVersion, boostLevel]);
861
+ const { cells, margin, numCells, calculatedImageSettings } = React.useMemo(() => {
862
+ let cells2 = qrcode.getModules();
863
+ const margin2 = getMarginSize(includeMargin, marginSize);
864
+ const numCells2 = cells2.length + margin2 * 2;
865
+ const calculatedImageSettings2 = getImageSettings(
866
+ cells2,
867
+ size,
868
+ margin2,
869
+ imageSettings
870
+ );
871
+ return {
872
+ cells: cells2,
873
+ margin: margin2,
874
+ numCells: numCells2,
875
+ calculatedImageSettings: calculatedImageSettings2
876
+ };
877
+ }, [qrcode, size, imageSettings, includeMargin, marginSize]);
878
+ return {
879
+ qrcode,
880
+ margin,
881
+ cells,
882
+ numCells,
883
+ calculatedImageSettings
884
+ };
885
+ }
886
+ var SUPPORTS_PATH2D = (function() {
887
+ try {
888
+ new Path2D().addPath(new Path2D());
889
+ } catch (e) {
890
+ return false;
891
+ }
892
+ return true;
893
+ })();
894
+ var QRCodeCanvas = React.forwardRef(
895
+ function QRCodeCanvas2(props, forwardedRef) {
896
+ const _a = props, {
897
+ value,
898
+ size = DEFAULT_SIZE,
899
+ level = DEFAULT_LEVEL,
900
+ bgColor = DEFAULT_BGCOLOR,
901
+ fgColor = DEFAULT_FGCOLOR,
902
+ includeMargin = DEFAULT_INCLUDEMARGIN,
903
+ minVersion = DEFAULT_MINVERSION,
904
+ boostLevel,
905
+ marginSize,
906
+ imageSettings
907
+ } = _a, extraProps = __objRest(_a, [
908
+ "value",
909
+ "size",
910
+ "level",
911
+ "bgColor",
912
+ "fgColor",
913
+ "includeMargin",
914
+ "minVersion",
915
+ "boostLevel",
916
+ "marginSize",
917
+ "imageSettings"
918
+ ]);
919
+ const _b = extraProps, { style } = _b, otherProps = __objRest(_b, ["style"]);
920
+ const imgSrc = imageSettings == null ? void 0 : imageSettings.src;
921
+ const _canvas = React.useRef(null);
922
+ const _image = React.useRef(null);
923
+ const setCanvasRef = React.useCallback(
924
+ (node) => {
925
+ _canvas.current = node;
926
+ if (typeof forwardedRef === "function") {
927
+ forwardedRef(node);
928
+ } else if (forwardedRef) {
929
+ forwardedRef.current = node;
930
+ }
931
+ },
932
+ [forwardedRef]
933
+ );
934
+ const [isImgLoaded, setIsImageLoaded] = React.useState(false);
935
+ const { margin, cells, numCells, calculatedImageSettings } = useQRCode({
936
+ value,
937
+ level,
938
+ minVersion,
939
+ boostLevel,
940
+ includeMargin,
941
+ marginSize,
942
+ imageSettings,
943
+ size
944
+ });
945
+ React.useEffect(() => {
946
+ if (_canvas.current != null) {
947
+ const canvas = _canvas.current;
948
+ const ctx = canvas.getContext("2d");
949
+ if (!ctx) {
950
+ return;
951
+ }
952
+ let cellsToDraw = cells;
953
+ const image = _image.current;
954
+ const haveImageToRender = calculatedImageSettings != null && image !== null && image.complete && image.naturalHeight !== 0 && image.naturalWidth !== 0;
955
+ if (haveImageToRender) {
956
+ if (calculatedImageSettings.excavation != null) {
957
+ cellsToDraw = excavateModules(
958
+ cells,
959
+ calculatedImageSettings.excavation
960
+ );
961
+ }
962
+ }
963
+ const pixelRatio = window.devicePixelRatio || 1;
964
+ canvas.height = canvas.width = size * pixelRatio;
965
+ const scale = size / numCells * pixelRatio;
966
+ ctx.scale(scale, scale);
967
+ ctx.fillStyle = bgColor;
968
+ ctx.fillRect(0, 0, numCells, numCells);
969
+ ctx.fillStyle = fgColor;
970
+ if (SUPPORTS_PATH2D) {
971
+ ctx.fill(new Path2D(generatePath(cellsToDraw, margin)));
972
+ } else {
973
+ cells.forEach(function(row, rdx) {
974
+ row.forEach(function(cell, cdx) {
975
+ if (cell) {
976
+ ctx.fillRect(cdx + margin, rdx + margin, 1, 1);
977
+ }
978
+ });
979
+ });
980
+ }
981
+ if (calculatedImageSettings) {
982
+ ctx.globalAlpha = calculatedImageSettings.opacity;
983
+ }
984
+ if (haveImageToRender) {
985
+ ctx.drawImage(
986
+ image,
987
+ calculatedImageSettings.x + margin,
988
+ calculatedImageSettings.y + margin,
989
+ calculatedImageSettings.w,
990
+ calculatedImageSettings.h
991
+ );
992
+ }
993
+ }
994
+ });
995
+ React.useEffect(() => {
996
+ setIsImageLoaded(false);
997
+ }, [imgSrc]);
998
+ const canvasStyle = __spreadValues({ height: size, width: size }, style);
999
+ let img = null;
1000
+ if (imgSrc != null) {
1001
+ img = /* @__PURE__ */ React.createElement(
1002
+ "img",
1003
+ {
1004
+ src: imgSrc,
1005
+ key: imgSrc,
1006
+ style: { display: "none" },
1007
+ onLoad: () => {
1008
+ setIsImageLoaded(true);
1009
+ },
1010
+ ref: _image,
1011
+ crossOrigin: calculatedImageSettings == null ? void 0 : calculatedImageSettings.crossOrigin
1012
+ }
1013
+ );
1014
+ }
1015
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
1016
+ "canvas",
1017
+ __spreadValues({
1018
+ style: canvasStyle,
1019
+ height: size,
1020
+ width: size,
1021
+ ref: setCanvasRef,
1022
+ role: "img"
1023
+ }, otherProps)
1024
+ ), img);
1025
+ }
1026
+ );
1027
+ QRCodeCanvas.displayName = "QRCodeCanvas";
1028
+ var QRCodeSVG = React.forwardRef(
1029
+ function QRCodeSVG2(props, forwardedRef) {
1030
+ const _a = props, {
1031
+ value,
1032
+ size = DEFAULT_SIZE,
1033
+ level = DEFAULT_LEVEL,
1034
+ bgColor = DEFAULT_BGCOLOR,
1035
+ fgColor = DEFAULT_FGCOLOR,
1036
+ includeMargin = DEFAULT_INCLUDEMARGIN,
1037
+ minVersion = DEFAULT_MINVERSION,
1038
+ boostLevel,
1039
+ title,
1040
+ marginSize,
1041
+ imageSettings
1042
+ } = _a, otherProps = __objRest(_a, [
1043
+ "value",
1044
+ "size",
1045
+ "level",
1046
+ "bgColor",
1047
+ "fgColor",
1048
+ "includeMargin",
1049
+ "minVersion",
1050
+ "boostLevel",
1051
+ "title",
1052
+ "marginSize",
1053
+ "imageSettings"
1054
+ ]);
1055
+ const { margin, cells, numCells, calculatedImageSettings } = useQRCode({
1056
+ value,
1057
+ level,
1058
+ minVersion,
1059
+ boostLevel,
1060
+ includeMargin,
1061
+ marginSize,
1062
+ imageSettings,
1063
+ size
1064
+ });
1065
+ let cellsToDraw = cells;
1066
+ let image = null;
1067
+ if (imageSettings != null && calculatedImageSettings != null) {
1068
+ if (calculatedImageSettings.excavation != null) {
1069
+ cellsToDraw = excavateModules(
1070
+ cells,
1071
+ calculatedImageSettings.excavation
1072
+ );
1073
+ }
1074
+ image = /* @__PURE__ */ React.createElement(
1075
+ "image",
1076
+ {
1077
+ href: imageSettings.src,
1078
+ height: calculatedImageSettings.h,
1079
+ width: calculatedImageSettings.w,
1080
+ x: calculatedImageSettings.x + margin,
1081
+ y: calculatedImageSettings.y + margin,
1082
+ preserveAspectRatio: "none",
1083
+ opacity: calculatedImageSettings.opacity,
1084
+ crossOrigin: calculatedImageSettings.crossOrigin
1085
+ }
1086
+ );
1087
+ }
1088
+ const fgPath = generatePath(cellsToDraw, margin);
1089
+ return /* @__PURE__ */ React.createElement(
1090
+ "svg",
1091
+ __spreadValues({
1092
+ height: size,
1093
+ width: size,
1094
+ viewBox: `0 0 ${numCells} ${numCells}`,
1095
+ ref: forwardedRef,
1096
+ role: "img"
1097
+ }, otherProps),
1098
+ !!title && /* @__PURE__ */ React.createElement("title", null, title),
1099
+ /* @__PURE__ */ React.createElement(
1100
+ "path",
1101
+ {
1102
+ fill: bgColor,
1103
+ d: `M0,0 h${numCells}v${numCells}H0z`,
1104
+ shapeRendering: "crispEdges"
1105
+ }
1106
+ ),
1107
+ /* @__PURE__ */ React.createElement("path", { fill: fgColor, d: fgPath, shapeRendering: "crispEdges" }),
1108
+ image
1109
+ );
1110
+ }
1111
+ );
1112
+ QRCodeSVG.displayName = "QRCodeSVG";
1113
+
1114
+ // ../ui/src/components/alert-dialog.tsx
1115
+ import { jsx, jsxs } from "react/jsx-runtime";
1116
+ function AlertDialog({
1117
+ ...props
1118
+ }) {
1119
+ return /* @__PURE__ */ jsx(dist_exports.Root, { "data-slot": "alert-dialog", ...props });
1120
+ }
1121
+ function AlertDialogTrigger({
1122
+ ...props
1123
+ }) {
1124
+ return /* @__PURE__ */ jsx(dist_exports.Trigger, { "data-slot": "alert-dialog-trigger", ...props });
1125
+ }
1126
+ function AlertDialogOverlay({
1127
+ className,
1128
+ ...props
1129
+ }) {
1130
+ return /* @__PURE__ */ jsx(
1131
+ dist_exports.Overlay,
1132
+ {
1133
+ "data-slot": "alert-dialog-overlay",
1134
+ className: cn(
1135
+ "fixed inset-0 z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
1136
+ className
1137
+ ),
1138
+ ...props
1139
+ }
1140
+ );
1141
+ }
1142
+ function AlertDialogTitle({
1143
+ className,
1144
+ ...props
1145
+ }) {
1146
+ return /* @__PURE__ */ jsx(
1147
+ dist_exports.Title,
1148
+ {
1149
+ "data-slot": "alert-dialog-title",
1150
+ className: cn(
1151
+ "text-base font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",
1152
+ className
1153
+ ),
1154
+ ...props
1155
+ }
1156
+ );
1157
+ }
1158
+ function AlertDialogDescription({
1159
+ className,
1160
+ ...props
1161
+ }) {
1162
+ return /* @__PURE__ */ jsx(
1163
+ dist_exports.Description,
1164
+ {
1165
+ "data-slot": "alert-dialog-description",
1166
+ className: cn(
1167
+ "text-sm text-balance text-muted-foreground md:text-pretty *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",
1168
+ className
1169
+ ),
1170
+ ...props
1171
+ }
1172
+ );
1173
+ }
1174
+ function AlertDialogAction({
1175
+ className,
1176
+ variant = "default",
1177
+ size = "default",
1178
+ ...props
1179
+ }) {
1180
+ return /* @__PURE__ */ jsx(Button, { variant, size, asChild: true, children: /* @__PURE__ */ jsx(
1181
+ dist_exports.Action,
1182
+ {
1183
+ "data-slot": "alert-dialog-action",
1184
+ className: cn(className),
1185
+ ...props
1186
+ }
1187
+ ) });
1188
+ }
1189
+ function AlertDialogCancel({
1190
+ className,
1191
+ variant = "outline",
1192
+ size = "default",
1193
+ ...props
1194
+ }) {
1195
+ return /* @__PURE__ */ jsx(Button, { variant, size, asChild: true, children: /* @__PURE__ */ jsx(
1196
+ dist_exports.Cancel,
1197
+ {
1198
+ "data-slot": "alert-dialog-cancel",
1199
+ className: cn(className),
1200
+ ...props
1201
+ }
1202
+ ) });
1203
+ }
1204
+
1205
+ // ../ui/src/composites/alert-dialog.tsx
1206
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
1207
+ function AlertDialogContent({
1208
+ className,
1209
+ overlayClassName,
1210
+ size = "default",
1211
+ onKeyDown,
1212
+ ...props
1213
+ }) {
1214
+ const overlayRoot = useOverlayRoot();
1215
+ return /* @__PURE__ */ jsxs2(dist_exports.Portal, { "data-slot": "alert-dialog-portal", container: overlayRoot, children: [
1216
+ /* @__PURE__ */ jsx2(AlertDialogOverlay, { className: overlayClassName }),
1217
+ /* @__PURE__ */ jsx2(
1218
+ dist_exports.Content,
1219
+ {
1220
+ onKeyDown: (event) => {
1221
+ onKeyDown?.(event);
1222
+ loopTabInShadowRoot(event);
1223
+ },
1224
+ "data-slot": "alert-dialog-content",
1225
+ "data-size": size,
1226
+ className: cn(
1227
+ "group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
1228
+ className
1229
+ ),
1230
+ ...props
1231
+ }
1232
+ )
1233
+ ] });
1234
+ }
1235
+
1236
+ // src/components/FeishuCapabilitySelection.tsx
1237
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
1238
+ var capabilityStatus = {
1239
+ available: "\u53EF\u4F7F\u7528",
1240
+ not_selected: "\u5C1A\u672A\u5F00\u901A",
1241
+ permission_required: "\u5F85\u5E94\u7528\u5F00\u901A",
1242
+ user_auth_required: "\u5F85\u672C\u4EBA\u6388\u6743",
1243
+ app_required: "\u5F85\u5173\u8054\u5E94\u7528",
1244
+ unsupported: "\u6682\u672A\u652F\u6301",
1245
+ unknown: "\u5F85\u6838\u9A8C",
1246
+ temporarily_unavailable: "\u6682\u65F6\u4E0D\u53EF\u7528"
1247
+ };
1248
+ function selectableCapabilities(capabilities) {
1249
+ return capabilities.filter((item) => item.status !== "unsupported" && item.executable === true && item.id !== "user_send" && !item.scopes.includes("im:message.send_as_user"));
1250
+ }
1251
+ function defaultCapabilities(capabilities) {
1252
+ return selectableCapabilities(capabilities).map((item) => item.id);
1253
+ }
1254
+ function FeishuCapabilitySelection({ capabilities, permissions = [], domains = [] }) {
1255
+ const groups = /* @__PURE__ */ new Map();
1256
+ for (const item of selectableCapabilities(capabilities)) {
1257
+ const key = item.category || "other";
1258
+ groups.set(key, [...groups.get(key) ?? [], item]);
1259
+ }
1260
+ return /* @__PURE__ */ jsxs3("div", { className: "space-y-4", children: [
1261
+ /* @__PURE__ */ jsx3("p", { className: "text-sm", children: "\u521D\u6B21\u8FDE\u63A5\u91C7\u7528\u98DE\u4E66\u5E73\u53F0\u9ED8\u8BA4\u6A21\u677F\u53CA\u5B98\u65B9\u63A8\u8350\u6743\u9650\u3002\u5728\u98DE\u4E66\u9875\u9762\u786E\u8BA4\uFF0C\u514D\u5BA1\u548C\u5BA1\u6838\u8981\u6C42\u4EE5\u6240\u5728\u4F01\u4E1A\u89C4\u5219\u4E3A\u51C6\u3002" }),
1262
+ /* @__PURE__ */ jsx3("p", { className: "text-xs opacity-70", children: "\u9996\u6B21\u53EF\u80FD\u9700\u8981\u4E24\u6B21\u626B\u7801\uFF1A\u5148\u5173\u8054\u5E94\u7528\uFF0C\u518D\u786E\u8BA4\u672C\u4EBA\u6388\u6743\u3002\u90E8\u5206\u6743\u9650\u672A\u5F00\u901A\u65F6\uFF0C\u5DF2\u5F00\u901A\u6743\u9650\u4ECD\u53EF\u4F7F\u7528\u3002" }),
1263
+ /* @__PURE__ */ jsxs3("details", { className: "rounded-xl border border-[color-mix(in_srgb,currentColor_18%,transparent)] p-4 text-sm", children: [
1264
+ /* @__PURE__ */ jsx3("summary", { className: "cursor-pointer", children: "\u67E5\u770B\u5F53\u524D\u53EF\u7528\u7684\u5DE5\u4F5C\u80FD\u529B" }),
1265
+ /* @__PURE__ */ jsx3("div", { className: "mt-3 grid gap-3 sm:grid-cols-2", children: [...groups].map(([id, items]) => /* @__PURE__ */ jsxs3("section", { className: "space-y-2", children: [
1266
+ /* @__PURE__ */ jsx3("h4", { className: "font-medium", children: domains.find((domain) => domain.id === id)?.name || items[0]?.category_name || "\u5176\u4ED6\u5DE5\u4F5C\u80FD\u529B" }),
1267
+ items.map((item) => /* @__PURE__ */ jsxs3("details", { className: "text-xs", children: [
1268
+ /* @__PURE__ */ jsxs3("summary", { className: "cursor-pointer", children: [
1269
+ item.name,
1270
+ " \xB7 ",
1271
+ capabilityStatus[item.status] || "\u5F85\u6838\u9A8C"
1272
+ ] }),
1273
+ /* @__PURE__ */ jsx3("p", { className: "mt-1", children: item.description }),
1274
+ item.reason && /* @__PURE__ */ jsx3("p", { children: item.reason }),
1275
+ item.next_action && /* @__PURE__ */ jsx3("p", { children: item.next_action }),
1276
+ /* @__PURE__ */ jsx3("p", { children: item.identity === "bot" ? "\u673A\u5668\u4EBA\u8EAB\u4EFD" : "\u672C\u4EBA\u8EAB\u4EFD" }),
1277
+ item.scopes.map((scope) => /* @__PURE__ */ jsx3("p", { className: "break-all", children: permissions.find((p) => p.scope === scope && p.identity === item.identity)?.name || scope }, scope)),
1278
+ /* @__PURE__ */ jsx3("p", { children: "\u5BA1\u6838\u8981\u6C42\u4EE5\u98DE\u4E66\u5B98\u65B9\u9875\u9762\u548C\u4F01\u4E1A\u89C4\u5219\u4E3A\u51C6\u3002" })
1279
+ ] }, item.id))
1280
+ ] }, id)) })
1281
+ ] })
1282
+ ] });
1283
+ }
1284
+
1285
+ // src/components/ConnectorAuthorizationProgress.tsx
1286
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
1287
+ function ConnectorAuthorizationProgress({ result, onCheck, busy }) {
1288
+ if (!result || result.status === "complete" || result.status === "waiting") return null;
1289
+ let manualURL;
1290
+ try {
1291
+ const url = new URL(result.manual_url || "");
1292
+ if (url.protocol === "https:" && url.hostname === "open.feishu.cn" && !url.username && !url.password && !url.port && /^\/app(?:\/[^/]+\/auth)?$/.test(url.pathname)) manualURL = url.href;
1293
+ } catch {
1294
+ }
1295
+ return /* @__PURE__ */ jsxs4("output", { className: "block space-y-2 rounded-lg border p-4 text-sm", children: [
1296
+ /* @__PURE__ */ jsx4("span", { className: "block", children: result.status === "partial" ? "\u90E8\u5206\u6743\u9650\u5DF2\u751F\u6548\uFF0C\u672C\u6B21\u64CD\u4F5C\u6240\u9700\u6743\u9650\u5C1A\u672A\u8865\u9F50" : "\u672C\u6B21\u64CD\u4F5C\u6240\u9700\u6743\u9650\u5C1A\u672A\u751F\u6548" }),
1297
+ /* @__PURE__ */ jsx4("span", { className: "block", children: result.next_action }),
1298
+ result.missing_permissions.map((item) => /* @__PURE__ */ jsxs4("span", { className: "block break-all text-xs", children: [
1299
+ item.identity === "bot" ? "\u5E94\u7528\u8EAB\u4EFD" : "\u672C\u4EBA\u8EAB\u4EFD",
1300
+ " \xB7 ",
1301
+ item.scope
1302
+ ] }, `${item.identity}:${item.scope}`)),
1303
+ result.mode === "manual" && manualURL && /* @__PURE__ */ jsx4("a", { className: "block underline", href: manualURL, target: "_blank", rel: "noopener noreferrer", children: "\u6253\u5F00\u98DE\u4E66\u6743\u9650\u7BA1\u7406" }),
1304
+ /* @__PURE__ */ jsx4("button", { type: "button", className: "underline disabled:opacity-50", disabled: busy, onClick: onCheck, children: "\u6211\u5DF2\u5904\u7406\uFF0C\u91CD\u65B0\u6838\u9A8C" })
1305
+ ] });
1306
+ }
1307
+
1308
+ // src/components/FeishuPermissionStatus.tsx
1309
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
1310
+ function FeishuPermissionStatus({ permissions, template }) {
1311
+ if (!template && !permissions.some((item) => item.app_status)) return null;
1312
+ const listed = template ? permissions.filter((item) => item.template) : permissions;
1313
+ const missingApp = listed.filter((item) => item.app_status === "missing");
1314
+ const missingUser = listed.filter((item) => item.identity === "user" && item.app_status === "granted" && item.user_status === "not_granted");
1315
+ const unknown = listed.filter((item) => !item.app_status || item.app_status === "unknown");
1316
+ return /* @__PURE__ */ jsxs5("details", { className: "rounded-xl border border-[color-mix(in_srgb,currentColor_18%,transparent)] p-4 text-sm", children: [
1317
+ /* @__PURE__ */ jsxs5("summary", { className: "cursor-pointer", children: [
1318
+ template ? "\u98DE\u4E66\u5B98\u65B9\u63A8\u8350\u6743\u9650" : "\u98DE\u4E66\u6743\u9650\u72B6\u6001",
1319
+ " \xB7 ",
1320
+ missingApp.length,
1321
+ " \u9879\u5E94\u7528\u672A\u5F00\u901A \xB7 ",
1322
+ missingUser.length,
1323
+ " \u9879\u5F85\u672C\u4EBA\u6388\u6743",
1324
+ unknown.length ? ` \xB7 ${unknown.length} \u9879\u5F85\u6838\u9A8C` : ""
1325
+ ] }),
1326
+ /* @__PURE__ */ jsx5("p", { className: "mt-3 text-xs opacity-70", children: "\u4F01\u4E1A\u51B3\u5B9A\u54EA\u4E9B\u6743\u9650\u514D\u5BA1\u3001\u54EA\u4E9B\u9700\u8981\u5BA1\u6279\u3002\u5E94\u7528\u5DF2\u5F00\u901A\u548C\u672C\u4EBA\u5DF2\u6388\u6743\u5206\u522B\u6838\u9A8C\uFF1B\u5F85\u6838\u9A8C\u4E0D\u4EE3\u8868\u4F01\u4E1A\u62D2\u7EDD\u3002\u672A\u5F00\u901A\u9879\u76EE\u4E0D\u5F71\u54CD\u5176\u4ED6\u5DF2\u83B7\u6388\u6743\u7684\u64CD\u4F5C\u3002" }),
1327
+ /* @__PURE__ */ jsx5("div", { className: "mt-3 max-h-72 space-y-3 overflow-y-auto", children: listed.map((item) => /* @__PURE__ */ jsxs5("div", { className: "text-xs", children: [
1328
+ /* @__PURE__ */ jsxs5("p", { children: [
1329
+ item.category_name ? `${item.category_name} \xB7 ` : "",
1330
+ item.name
1331
+ ] }),
1332
+ item.name !== item.scope && /* @__PURE__ */ jsx5("p", { className: "break-all opacity-70", children: item.scope }),
1333
+ /* @__PURE__ */ jsxs5("p", { children: [
1334
+ item.app_status === "granted" ? "\u5E94\u7528\u5DF2\u5F00\u901A" : item.app_status === "missing" ? "\u5E94\u7528\u672A\u5F00\u901A\uFF0C\u8BF7\u5728\u98DE\u4E66\u786E\u8BA4\u4F01\u4E1A\u5BA1\u6279\u6216\u53D1\u5E03\u8981\u6C42" : "\u5E94\u7528\u5F00\u901A\u60C5\u51B5\u5F85\u6838\u9A8C",
1335
+ item.identity === "user" ? item.user_status === "granted" ? "\uFF1B\u672C\u4EBA\u5DF2\u6388\u6743" : "\uFF1B\u672C\u4EBA\u5C1A\u672A\u6388\u6743" : ""
1336
+ ] })
1337
+ ] }, `${item.identity}:${item.scope}`)) })
1338
+ ] });
1339
+ }
1340
+
1341
+ // src/components/ConnectorRuntimeDiagnostics.tsx
1342
+ import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
1343
+ var channelLabels = {
1344
+ "channel.connecting": "\u5F00\u59CB\u8FDE\u63A5\u98DE\u4E66",
1345
+ "channel.connected": "\u98DE\u4E66\u8FDE\u63A5\u5DF2\u5EFA\u7ACB",
1346
+ "channel.reconnecting": "\u6B63\u5728\u91CD\u65B0\u8FDE\u63A5\u98DE\u4E66",
1347
+ "channel.disconnected": "\u98DE\u4E66\u8FDE\u63A5\u5DF2\u65AD\u5F00",
1348
+ "channel.receiver_error": "\u6D88\u606F\u63A5\u6536\u53D1\u751F\u9519\u8BEF",
1349
+ "channel.warning": "\u63A5\u6536\u901A\u9053\u4EA7\u751F\u8B66\u544A",
1350
+ "channel.error": "\u63A5\u6536\u901A\u9053\u53D1\u751F\u9519\u8BEF",
1351
+ "message.received": "\u5DF2\u8BB0\u5F55\u6536\u5230\u98DE\u4E66\u6D88\u606F"
1352
+ };
1353
+ var deliveryLabels = {
1354
+ ready: "\u7B49\u5F85\u6295\u9012",
1355
+ delivering: "\u6B63\u5728\u6295\u9012",
1356
+ retry_wait: "\u7B49\u5F85\u91CD\u8BD5",
1357
+ accepted: "\u63A5\u6536\u7AEF\u5DF2\u786E\u8BA4",
1358
+ dead_letter: "\u5DF2\u505C\u6B62\u91CD\u8BD5\uFF0C\u9700\u8981\u5904\u7406",
1359
+ cancelled: "\u5DF2\u53D6\u6D88",
1360
+ waiting_condition: "\u7B49\u5F85\u6295\u9012\u6761\u4EF6",
1361
+ expired_unknown: "\u5DF2\u8FC7\u671F\uFF0C\u7ED3\u679C\u672A\u77E5",
1362
+ leased: "\u6B63\u5728\u5904\u7406"
1363
+ };
1364
+ var time = (value) => value > 0 ? new Date(value).toLocaleString() : "\u6682\u65E0\u8BB0\u5F55";
1365
+ var channelLabel = (value) => channelLabels[value] ?? (value ? "\u5C1A\u672A\u8BC6\u522B\u7684\u901A\u9053\u8BB0\u5F55" : "\u5C1A\u65E0\u901A\u9053\u8BB0\u5F55");
1366
+ var deliveryLabel = (value) => deliveryLabels[value] ?? "\u5C1A\u672A\u8BC6\u522B\u7684\u6295\u9012\u72B6\u6001";
1367
+ function ConnectorRuntimeDiagnostics({ runtime }) {
1368
+ return /* @__PURE__ */ jsxs6("section", { "aria-label": "\u6D88\u606F\u63A5\u6536\u4E0E\u6295\u9012\u8BB0\u5F55", className: "space-y-3 rounded-lg border p-3 text-xs", children: [
1369
+ /* @__PURE__ */ jsx6("p", { className: "font-medium", children: "\u6D88\u606F\u63A5\u6536\u4E0E\u6295\u9012\u8BB0\u5F55" }),
1370
+ /* @__PURE__ */ jsxs6("p", { children: [
1371
+ "\u901A\u9053\u6700\u8FD1\u8BB0\u5F55\uFF1A",
1372
+ channelLabel(runtime.channel_state)
1373
+ ] }),
1374
+ /* @__PURE__ */ jsxs6("p", { children: [
1375
+ "\u6700\u8FD1\u6536\u5230\u4E8B\u4EF6\uFF1A",
1376
+ time(runtime.last_event_at_ms)
1377
+ ] }),
1378
+ /* @__PURE__ */ jsx6("p", { children: "\u4EE5\u4E0B\u662F SuperWork \u4FDD\u5B58\u7684\u8BB0\u5F55\uFF1B\u6CA1\u6709\u6295\u9012\u8BB0\u5F55\u65F6\uFF0C\u5C1A\u4E0D\u80FD\u786E\u8BA4\u6D88\u606F\u5DF2\u9001\u8FBE\u52A9\u624B\u3002" }),
1379
+ /* @__PURE__ */ jsxs6("details", { children: [
1380
+ /* @__PURE__ */ jsxs6("summary", { className: "cursor-pointer", children: [
1381
+ "\u63A5\u6536\u901A\u9053\u8BB0\u5F55\uFF08",
1382
+ runtime.channel_events.length,
1383
+ "\uFF09"
1384
+ ] }),
1385
+ runtime.channel_events.length ? /* @__PURE__ */ jsx6("ol", { className: "space-y-2 pt-2", children: runtime.channel_events.map((event) => /* @__PURE__ */ jsxs6("li", { className: "space-y-1", children: [
1386
+ /* @__PURE__ */ jsxs6("p", { children: [
1387
+ channelLabel(event.type),
1388
+ " \xB7 ",
1389
+ time(event.at_ms)
1390
+ ] }),
1391
+ /* @__PURE__ */ jsxs6("p", { className: "break-all", children: [
1392
+ "\u6392\u67E5\u7F16\u53F7\uFF1A",
1393
+ event.trace_id
1394
+ ] })
1395
+ ] }, event.trace_id)) }) : /* @__PURE__ */ jsx6("p", { children: "\u6682\u65E0\u63A5\u6536\u901A\u9053\u8BB0\u5F55\u3002" })
1396
+ ] }),
1397
+ /* @__PURE__ */ jsxs6("details", { children: [
1398
+ /* @__PURE__ */ jsxs6("summary", { className: "cursor-pointer", children: [
1399
+ "\u6D88\u606F\u6295\u9012\u8BB0\u5F55\uFF08",
1400
+ runtime.deliveries.length,
1401
+ "\uFF09"
1402
+ ] }),
1403
+ runtime.deliveries.length ? /* @__PURE__ */ jsx6("ol", { className: "space-y-2 pt-2", children: runtime.deliveries.map((delivery) => /* @__PURE__ */ jsxs6("li", { className: "space-y-1", children: [
1404
+ /* @__PURE__ */ jsxs6("p", { children: [
1405
+ deliveryLabel(delivery.status),
1406
+ " \xB7 \u5DF2\u5C1D\u8BD5 ",
1407
+ delivery.attempt,
1408
+ " \u6B21"
1409
+ ] }),
1410
+ /* @__PURE__ */ jsxs6("p", { className: "break-all", children: [
1411
+ "\u6295\u9012\u7F16\u53F7\uFF1A",
1412
+ delivery.delivery_id
1413
+ ] }),
1414
+ /* @__PURE__ */ jsxs6("p", { children: [
1415
+ "\u521B\u5EFA\u65F6\u95F4\uFF1A",
1416
+ time(delivery.created_at_ms)
1417
+ ] }),
1418
+ ["ready", "retry_wait", "waiting_condition"].includes(delivery.status) && delivery.next_at_ms > 0 && /* @__PURE__ */ jsxs6("p", { children: [
1419
+ "\u4E0B\u6B21\u5904\u7406\u65F6\u95F4\uFF1A",
1420
+ time(delivery.next_at_ms)
1421
+ ] })
1422
+ ] }, delivery.delivery_id)) }) : /* @__PURE__ */ jsx6("p", { children: "\u6682\u65E0\u6D88\u606F\u6295\u9012\u8BB0\u5F55\u3002" })
1423
+ ] }),
1424
+ /* @__PURE__ */ jsxs6("details", { children: [
1425
+ /* @__PURE__ */ jsxs6("summary", { className: "cursor-pointer", children: [
1426
+ "\u9010\u6B21\u6295\u9012\u5C1D\u8BD5\uFF08",
1427
+ runtime.delivery_attempts.length,
1428
+ "\uFF09"
1429
+ ] }),
1430
+ runtime.delivery_attempts.length ? /* @__PURE__ */ jsx6("ol", { className: "space-y-2 pt-2", children: runtime.delivery_attempts.map((attempt) => /* @__PURE__ */ jsxs6("li", { className: "space-y-1", children: [
1431
+ /* @__PURE__ */ jsxs6("p", { children: [
1432
+ "\u7B2C ",
1433
+ attempt.attempt,
1434
+ " \u6B21 \xB7 ",
1435
+ deliveryLabel(attempt.status)
1436
+ ] }),
1437
+ /* @__PURE__ */ jsxs6("p", { className: "break-all", children: [
1438
+ "\u6295\u9012\u7F16\u53F7\uFF1A",
1439
+ attempt.delivery_id
1440
+ ] }),
1441
+ /* @__PURE__ */ jsxs6("p", { children: [
1442
+ "\u5F00\u59CB\uFF1A",
1443
+ time(attempt.started_at_ms),
1444
+ "\uFF1B\u7ED3\u675F\uFF1A",
1445
+ time(attempt.finished_at_ms)
1446
+ ] })
1447
+ ] }, attempt.id)) }) : /* @__PURE__ */ jsx6("p", { children: "\u6682\u65E0\u6295\u9012\u5C1D\u8BD5\u8BB0\u5F55\u3002" })
1448
+ ] })
1449
+ ] });
1450
+ }
1451
+
1452
+ // src/components/DeviceConnection.tsx
1453
+ import { Fragment, jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
1454
+ var statusLabels = {
1455
+ available: "\u53EF\u7528",
1456
+ not_selected: "\u672A\u9009\u62E9",
1457
+ permission_required: "\u5E94\u7528\u6743\u9650\u672A\u751F\u6548",
1458
+ user_auth_required: "\u9700\u8981\u672C\u4EBA\u6388\u6743",
1459
+ app_required: "\u9700\u8981\u8FDE\u63A5\u5E94\u7528",
1460
+ unsupported: "\u6682\u4E0D\u652F\u6301",
1461
+ unknown: "\u5F85\u6838\u9A8C",
1462
+ temporarily_unavailable: "\u6682\u65F6\u4E0D\u53EF\u7528"
1463
+ };
1464
+ var stateLabels = {
1465
+ running: "\u8FDB\u884C\u4E2D",
1466
+ waiting: "\u7B49\u5F85\u5904\u7406",
1467
+ succeeded: "\u5DF2\u5B8C\u6210",
1468
+ failed: "\u672A\u5B8C\u6210",
1469
+ cancelled: "\u5DF2\u53D6\u6D88",
1470
+ completed: "\u5DF2\u5B8C\u6210",
1471
+ partial: "\u90E8\u5206\u5B8C\u6210",
1472
+ expired: "\u5DF2\u8FC7\u671F"
1473
+ };
1474
+ var auditLabels = {
1475
+ "connection.created": "\u521B\u5EFA\u8FDE\u63A5",
1476
+ "authorization.step": "\u6267\u884C\u6388\u6743\u6B65\u9AA4",
1477
+ "authorization.failed": "\u5F53\u524D\u6388\u6743\u6B65\u9AA4\u672A\u5B8C\u6210",
1478
+ "authorization.granted": "\u672C\u4EBA\u6388\u6743\u5DF2\u4FDD\u5B58",
1479
+ "permissions.check_unknown": "\u5E94\u7528\u6743\u9650\u5C1A\u65E0\u6CD5\u6838\u5B9E",
1480
+ "credential.refreshed": "\u672C\u4EBA\u6388\u6743\u5DF2\u7EED\u671F",
1481
+ "subscription.bound": "\u52A9\u624B\u6D88\u606F\u8BA2\u9605\u5DF2\u63A5\u5165",
1482
+ "subscription.updated": "\u52A9\u624B\u6D88\u606F\u8BA2\u9605\u5DF2\u66F4\u65B0",
1483
+ "connection.disconnected": "SuperWork \u8FDE\u63A5\u5DF2\u65AD\u5F00",
1484
+ "tool.started": "\u5F00\u59CB\u5904\u7406\u98DE\u4E66\u64CD\u4F5C",
1485
+ "tool.failed": "\u98DE\u4E66\u64CD\u4F5C\u672A\u5B8C\u6210",
1486
+ "tool.completed": "\u98DE\u4E66\u64CD\u4F5C\u5DF2\u5B8C\u6210",
1487
+ "send.unknown": "\u53D1\u9001\u7ED3\u679C\u5F85\u786E\u8BA4"
1488
+ };
1489
+ var button = "rounded-lg border border-[color-mix(in_srgb,currentColor_18%,transparent)] px-3 py-2 text-sm disabled:opacity-50";
1490
+ function authorizationURL(value) {
1491
+ if (!value) return null;
1492
+ try {
1493
+ const url = new URL(value);
1494
+ const official = ["feishu.cn", "larksuite.com", "larkoffice.com"].some((domain) => url.hostname === domain || url.hostname.endsWith(`.${domain}`));
1495
+ return official && url.protocol === "https:" && !url.username && !url.password && !url.port ? url.href : null;
1496
+ } catch {
1497
+ return null;
1498
+ }
1499
+ }
1500
+ function DeviceConnection({ read, act, diagnostics, onChanged, bindDelivery = false, onDisable, initialPage = "connection", authorizationCapabilities, autoAuthorize = false }) {
1501
+ const [view, setView] = useState(null);
1502
+ const [selected, setSelected] = useState([]);
1503
+ const [page, setPage] = useState(initialPage);
1504
+ const [diagnosticView, setDiagnosticView] = useState(null);
1505
+ const [error, setError] = useState("");
1506
+ const [notice, setNotice] = useState("");
1507
+ const [busy, setBusy] = useState(false);
1508
+ const [removingConnectionID, setRemovingConnectionID] = useState(null);
1509
+ const callbacks = useRef({ read, act, diagnostics, onChanged, onDisable });
1510
+ callbacks.current = { read, act, diagnostics, onChanged, onDisable };
1511
+ const live = useRef(false);
1512
+ const inFlight = useRef(false);
1513
+ const initialized = useRef(false);
1514
+ const flow = useRef(null);
1515
+ const linking = useRef(false);
1516
+ const newConnection = useRef(false);
1517
+ function accept(value) {
1518
+ setView(value);
1519
+ const activationKnown = typeof value.activation_pending === "boolean";
1520
+ if (activationKnown) {
1521
+ newConnection.current = value.activation_pending === true;
1522
+ if (flow.current) flow.current.enable = newConnection.current || value.enabled !== false;
1523
+ }
1524
+ if (!initialized.current) {
1525
+ initialized.current = true;
1526
+ setSelected(value.app_id ? value.selected_capabilities ?? [] : defaultCapabilities(value.capabilities ?? []));
1527
+ if (!activationKnown) newConnection.current = !value.app_id;
1528
+ linking.current = value.phase === "app";
1529
+ if (["app", "user", "permissions"].includes(value.phase) && value.authorization_url || value.current_step?.state === "verifying" && value.current_step.action === "poll") flow.current = { enable: newConnection.current || value.enabled !== false, capabilities: value.selected_capabilities ?? [], focus: value.selected_capabilities ?? [] };
1530
+ if (!flow.current && matchesRequestedAuthorization(value) && value.app_id && value.authorization_result && value.authorization_result.status !== "complete" && value.authorization_result.capabilities.length) {
1531
+ const focus = value.authorization_result.capabilities;
1532
+ flow.current = { enable: newConnection.current || value.enabled !== false, capabilities: [.../* @__PURE__ */ new Set([...value.selected_capabilities ?? [], ...focus])], focus };
1533
+ }
1534
+ if (!value.app_id) setPage("select");
1535
+ }
1536
+ }
1537
+ useEffect(() => {
1538
+ live.current = true;
1539
+ void callbacks.current.read().then((value) => {
1540
+ if (live.current) accept(value);
1541
+ }).catch(() => {
1542
+ if (live.current) setError("\u8BFB\u53D6\u8FDE\u63A5\u72B6\u6001\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002");
1543
+ });
1544
+ return () => {
1545
+ live.current = false;
1546
+ };
1547
+ }, []);
1548
+ const matchesRequestedAuthorization = (value) => !authorizationCapabilities?.length || !!value.authorization_result && [...value.authorization_result.capabilities].sort().join(" ") === [...authorizationCapabilities].sort().join(" ");
1549
+ const canCompleteInitial = (value) => value.activation_pending === true && !authorizationCapabilities?.length && !!value.app_id && !value.error && (value.capabilities ?? []).some((item) => (value.selected_capabilities ?? []).includes(item.id) && item.status === "available");
1550
+ const canReceive = (value) => (value.capabilities ?? []).some((item) => (value.selected_capabilities ?? selected).includes(item.id) && item.id.startsWith("bot_receive_") && (item.status === "available" || item.status === "unknown" && item.evidence === "platform_scope_query"));
1551
+ const isWaiting = (value) => matchesRequestedAuthorization(value) && (["app", "user", "permissions"].includes(value.phase) && Boolean(value.authorization_url) || value.current_step?.state === "verifying" && value.current_step.action === "poll");
1552
+ async function changed() {
1553
+ try {
1554
+ await callbacks.current.onChanged();
1555
+ } catch {
1556
+ if (live.current) setNotice("\u8FDE\u63A5\u72B6\u6001\u5DF2\u4FDD\u5B58\uFF0C\u5217\u8868\u5237\u65B0\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u5237\u65B0\u3002");
1557
+ }
1558
+ }
1559
+ async function run(action, options = {}) {
1560
+ if (inFlight.current) return;
1561
+ inFlight.current = true;
1562
+ setBusy(true);
1563
+ setError("");
1564
+ setNotice("");
1565
+ try {
1566
+ if (action === "cancel") {
1567
+ flow.current = null;
1568
+ linking.current = false;
1569
+ }
1570
+ let value = await callbacks.current.act(action, options);
1571
+ if (!live.current) return;
1572
+ if (action === "finish" && !value.error) newConnection.current = false;
1573
+ accept(value);
1574
+ if (!value.error && action === "poll" && !isWaiting(value) && value.app_id && linking.current) {
1575
+ linking.current = false;
1576
+ setSelected(defaultCapabilities(value.capabilities ?? []));
1577
+ setPage("select");
1578
+ }
1579
+ if (!value.error && ((action === "authorize" || action === "poll" || action === "check" && (value.authorization_result?.status === "complete" || canCompleteInitial(value))) && !isWaiting(value) || action === "finish") && value.app_id && flow.current) {
1580
+ const target = flow.current;
1581
+ if (!matchesRequestedAuthorization(value)) {
1582
+ setError("\u65E0\u6CD5\u6838\u5B9E\u5F53\u524D\u6388\u6743\u5BF9\u5E94\u7684\u6743\u9650\uFF0C\u6682\u4E0D\u5C55\u793A\u4E8C\u7EF4\u7801\u3002\u8BF7\u91CD\u65B0\u68C0\u67E5\u672C\u6B21\u64CD\u4F5C\u3002");
1583
+ await changed();
1584
+ return;
1585
+ }
1586
+ if (action !== "finish" && value.authorization_result && value.authorization_result.status !== "complete" && !canCompleteInitial(value)) {
1587
+ setPage("connection");
1588
+ await changed();
1589
+ return;
1590
+ }
1591
+ if (action !== "finish") value = await callbacks.current.act("finish", { capabilities: target.capabilities, enable: target.enable });
1592
+ if (!live.current) return;
1593
+ accept(value);
1594
+ if (value.error) {
1595
+ await changed();
1596
+ return;
1597
+ }
1598
+ newConnection.current = false;
1599
+ flow.current = null;
1600
+ if (bindDelivery && canReceive(value) && value.subscription_state !== "paused") {
1601
+ try {
1602
+ value = await callbacks.current.act("bind");
1603
+ if (!live.current) return;
1604
+ accept(value);
1605
+ } catch {
1606
+ setNotice("\u98DE\u4E66\u80FD\u529B\u5DF2\u4FDD\u5B58\uFF0C\u63A5\u5165\u52A9\u624B\u6D88\u606F\u672A\u5B8C\u6210\u3002\u53EF\u5728\u7BA1\u7406\u8FDE\u63A5\u4E2D\u91CD\u8BD5\uFF0C\u4E0D\u9700\u8981\u91CD\u65B0\u626B\u7801\u3002");
1607
+ }
1608
+ }
1609
+ setPage("connection");
1610
+ }
1611
+ if (action === "cancel") {
1612
+ setNotice("\u5DF2\u53D6\u6D88\u672C\u6B21\u6388\u6743\uFF0C\u5DF2\u7ECF\u5F00\u901A\u7684\u80FD\u529B\u7EE7\u7EED\u4FDD\u7559\u3002");
1613
+ setPage("connection");
1614
+ }
1615
+ await changed();
1616
+ } catch {
1617
+ if (live.current) setError("\u672C\u6B21\u64CD\u4F5C\u672A\u5B8C\u6210\uFF0C\u5DF2\u6709\u6388\u6743\u7EE7\u7EED\u4FDD\u7559\u3002\u8BF7\u91CD\u8BD5\u5F53\u524D\u9879\u76EE\uFF0C\u6216\u67E5\u770B\u8FDE\u63A5\u5E2E\u52A9\u3002");
1618
+ try {
1619
+ const current = await callbacks.current.read();
1620
+ if (live.current) accept(current);
1621
+ } catch {
1622
+ }
1623
+ } finally {
1624
+ inFlight.current = false;
1625
+ if (live.current) setBusy(false);
1626
+ }
1627
+ }
1628
+ const start = (retryIDs) => {
1629
+ let focus = retryIDs ?? defaultCapabilities(view?.capabilities ?? []);
1630
+ if (!view?.app_id && !focus.length) focus = view?.selected_capabilities?.length ? view.selected_capabilities : capabilities.filter((item) => item.default && item.status !== "unsupported").map((item) => item.id);
1631
+ const target = [.../* @__PURE__ */ new Set([...view?.selected_capabilities ?? [], ...focus])];
1632
+ if (!view?.app_id) {
1633
+ linking.current = false;
1634
+ flow.current = { enable: true, capabilities: target, focus };
1635
+ void run("authorize", { capabilities: focus });
1636
+ return;
1637
+ }
1638
+ flow.current = { enable: newConnection.current || view.enabled !== false, capabilities: target, focus: [...focus] };
1639
+ void run("authorize", { capabilities: focus });
1640
+ };
1641
+ const retryCurrent = () => {
1642
+ if (flow.current) {
1643
+ flow.current.enable = newConnection.current || view?.enabled !== false;
1644
+ void run("authorize", { capabilities: flow.current.focus });
1645
+ } else start(failedUser.length ? failedUser.map((item) => item.id) : selected);
1646
+ };
1647
+ const automaticStarted = useRef(false);
1648
+ useEffect(() => {
1649
+ if (!authorizationCapabilities?.length && !autoAuthorize || !view || automaticStarted.current) return;
1650
+ automaticStarted.current = true;
1651
+ if (!isWaiting(view) && !(matchesRequestedAuthorization(view) && view.authorization_result?.mode === "manual")) start(authorizationCapabilities);
1652
+ }, [view, authorizationCapabilities, autoAuthorize]);
1653
+ const initialCompletionStarted = useRef(false);
1654
+ useEffect(() => {
1655
+ if (!view || !view.authorization_result || isWaiting(view) || busy || error || initialCompletionStarted.current || !canCompleteInitial(view)) return;
1656
+ initialCompletionStarted.current = true;
1657
+ automaticStarted.current = true;
1658
+ const capabilities2 = view.selected_capabilities ?? [];
1659
+ flow.current = { enable: true, capabilities: capabilities2, focus: capabilities2 };
1660
+ void run("finish", { capabilities: capabilities2, enable: true });
1661
+ }, [view, busy, error, authorizationCapabilities]);
1662
+ async function addCapabilities() {
1663
+ start();
1664
+ }
1665
+ async function refresh() {
1666
+ if (inFlight.current) return;
1667
+ inFlight.current = true;
1668
+ setBusy(true);
1669
+ setError("");
1670
+ try {
1671
+ const value = await callbacks.current.read();
1672
+ if (live.current) {
1673
+ if (view?.catalog_unavailable && !value.app_id) initialized.current = false;
1674
+ accept(value);
1675
+ }
1676
+ } catch {
1677
+ if (live.current) setError("\u8BFB\u53D6\u8FDE\u63A5\u72B6\u6001\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002");
1678
+ } finally {
1679
+ inFlight.current = false;
1680
+ if (live.current) setBusy(false);
1681
+ }
1682
+ }
1683
+ async function removeConnection(connectionID) {
1684
+ if (inFlight.current) return;
1685
+ inFlight.current = true;
1686
+ setBusy(true);
1687
+ setError("");
1688
+ setNotice("");
1689
+ try {
1690
+ const value = await callbacks.current.act("remove", { expected_connection_id: connectionID });
1691
+ if (!live.current) return;
1692
+ if (value.error) {
1693
+ setError(value.error.message);
1694
+ return;
1695
+ }
1696
+ flow.current = null;
1697
+ linking.current = false;
1698
+ newConnection.current = true;
1699
+ initialized.current = false;
1700
+ setSelected([]);
1701
+ setDiagnosticView(null);
1702
+ setRemovingConnectionID(null);
1703
+ accept(value);
1704
+ setPage("select");
1705
+ setNotice(value.catalog_unavailable ? "\u65E7\u8FDE\u63A5\u5DF2\u79FB\u9664\uFF0C\u80FD\u529B\u76EE\u5F55\u6682\u65F6\u65E0\u6CD5\u8BFB\u53D6\u3002\u53EF\u4EE5\u91CD\u65B0\u8BFB\u53D6\u5DE5\u4F5C\u80FD\u529B\uFF0C\u6216\u70B9\u51FB\u8FDE\u63A5\u98DE\u4E66\u7EE7\u7EED\u3002" : "\u65E7\u8FDE\u63A5\u5DF2\u79FB\u9664\uFF0C\u5386\u53F2\u6D88\u606F\u548C\u6392\u67E5\u65E5\u5FD7\u4FDD\u7559\u3002\u70B9\u51FB\u8FDE\u63A5\u98DE\u4E66\uFF0C\u91CD\u65B0\u9009\u62E9\u6216\u521B\u5EFA\u5E94\u7528\u3002");
1706
+ await changed();
1707
+ } catch {
1708
+ if (live.current) setError("\u79FB\u9664\u8FDE\u63A5\u672A\u5B8C\u6210\uFF0C\u5F53\u524D\u8FDE\u63A5\u4FE1\u606F\u5DF2\u4FDD\u7559\u3002\u8BF7\u91CD\u8BD5\uFF1B\u5982\u4ECD\u5931\u8D25\uFF0C\u53EF\u5728\u8FDE\u63A5\u5E2E\u52A9\u4E2D\u67E5\u770B\u8BB0\u5F55\u3002");
1709
+ } finally {
1710
+ inFlight.current = false;
1711
+ if (live.current) setBusy(false);
1712
+ }
1713
+ }
1714
+ async function inspect() {
1715
+ if (inFlight.current || !callbacks.current.diagnostics) return;
1716
+ inFlight.current = true;
1717
+ setBusy(true);
1718
+ setError("");
1719
+ try {
1720
+ const value = await callbacks.current.diagnostics();
1721
+ if (live.current) {
1722
+ setDiagnosticView(value);
1723
+ accept(value.connection);
1724
+ }
1725
+ } catch {
1726
+ if (live.current) setError("\u6392\u67E5\u8BB0\u5F55\u6682\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002");
1727
+ } finally {
1728
+ inFlight.current = false;
1729
+ if (live.current) setBusy(false);
1730
+ }
1731
+ }
1732
+ const waiting = view ? isWaiting(view) : false;
1733
+ const verifying = view?.current_step?.state === "verifying" && view.current_step.action === "poll";
1734
+ useEffect(() => {
1735
+ if (!waiting || busy || error || view?.error) return;
1736
+ const timer = setTimeout(() => {
1737
+ void run("poll", view?.attempt_id ? { attempt_id: view.attempt_id } : {});
1738
+ }, 5e3);
1739
+ return () => clearTimeout(timer);
1740
+ }, [view, busy, error, waiting]);
1741
+ const capabilities = view?.capabilities ?? [];
1742
+ const active = capabilities.filter((item) => item.status === "available");
1743
+ const pending = capabilities.filter((item) => (view?.selected_capabilities ?? []).includes(item.id) && item.status !== "available" && item.status !== "unsupported");
1744
+ const pendingPermissions = pending.filter((item) => item.status === "permission_required" || item.status === "unknown" && item.evidence !== "platform_scope_query");
1745
+ const failedUser = pending.filter((item) => item.identity === "user" && item.status === "user_auth_required");
1746
+ const categories = [...new Set(active.map((item) => item.category_name || item.category || "\u5176\u4ED6\u5DE5\u4F5C\u80FD\u529B"))];
1747
+ const subscription = view?.subscription_state ?? (view?.delivery_bound ? "enabled" : "not_bound");
1748
+ const url = waiting && !(view?.expires_at && view.expires_at <= Date.now() / 1e3) ? authorizationURL(view?.authorization_url) : null;
1749
+ const receptionNeedsTest = capabilities.some((item) => item.id.startsWith("bot_receive_") && item.status === "unknown" && item.evidence === "platform_scope_query");
1750
+ const finishExisting = () => {
1751
+ const target = flow.current ?? { enable: view?.enabled === true, capabilities: view?.selected_capabilities ?? selected, focus: view?.selected_capabilities ?? selected };
1752
+ target.enable = newConnection.current || view?.enabled !== false;
1753
+ flow.current = target;
1754
+ void run("finish", { capabilities: target.capabilities, enable: target.enable });
1755
+ };
1756
+ const preserveDisabled = Boolean(view?.app_id && view.enabled === false && !newConnection.current);
1757
+ const back = /* @__PURE__ */ jsx7("button", { type: "button", className: "text-xs underline opacity-70", disabled: busy, onClick: () => setPage(view?.app_id ? "connection" : "select"), children: "\u8FD4\u56DE\u98DE\u4E66" });
1758
+ return /* @__PURE__ */ jsxs7("section", { "aria-label": "\u98DE\u4E66\u6388\u6743", "aria-busy": busy, className: "space-y-5 py-3 text-left", children: [
1759
+ /* @__PURE__ */ jsxs7("div", { children: [
1760
+ /* @__PURE__ */ jsx7("h3", { className: "text-lg font-medium", children: page === "manage" ? "\u7BA1\u7406\u98DE\u4E66\u8FDE\u63A5" : page === "help" ? "\u8FDE\u63A5\u5E2E\u52A9" : page === "select" ? "\u8FDE\u63A5\u98DE\u4E66" : "\u98DE\u4E66" }),
1761
+ /* @__PURE__ */ jsx7("p", { className: "mt-1 text-xs opacity-70", children: "\u6309\u98DE\u4E66\u5B98\u65B9\u63A8\u8350\u6743\u9650\u8FDE\u63A5\uFF0C\u5177\u4F53\u5F00\u901A\u7ED3\u679C\u7531\u4F01\u4E1A\u89C4\u5219\u548C\u672C\u4EBA\u6388\u6743\u51B3\u5B9A\u3002" })
1762
+ ] }),
1763
+ notice && /* @__PURE__ */ jsx7("output", { className: "block rounded-lg border border-[color-mix(in_srgb,currentColor_18%,transparent)] p-3 text-sm", children: notice }),
1764
+ error && /* @__PURE__ */ jsx7("p", { role: "alert", className: "rounded-lg border border-[color-mix(in_srgb,currentColor_18%,transparent)] p-3 text-sm", children: error }),
1765
+ view?.error && /* @__PURE__ */ jsxs7("div", { role: "alert", className: "space-y-1 rounded-lg border border-[color-mix(in_srgb,currentColor_18%,transparent)] p-3 text-sm", children: [
1766
+ /* @__PURE__ */ jsx7("p", { children: view.error.message }),
1767
+ view.error.next_action && /* @__PURE__ */ jsx7("p", { children: view.error.next_action }),
1768
+ !waiting && view.app_id && /* @__PURE__ */ jsxs7("div", { className: "flex flex-wrap gap-3", children: [
1769
+ /* @__PURE__ */ jsx7("button", { type: "button", className: "text-xs underline", disabled: busy, onClick: retryCurrent, children: "\u91CD\u8BD5\u5F53\u524D\u6388\u6743" }),
1770
+ /* @__PURE__ */ jsx7("button", { type: "button", className: "text-xs underline", disabled: busy, onClick: finishExisting, children: "\u5148\u4F7F\u7528\u5DF2\u5F00\u901A\u80FD\u529B\uFF0C\u5176\u4ED6\u7A0D\u540E\u5904\u7406" })
1771
+ ] })
1772
+ ] }),
1773
+ view && !waiting && matchesRequestedAuthorization(view) && /* @__PURE__ */ jsx7(ConnectorAuthorizationProgress, { result: view.authorization_result, onCheck: () => void run("check"), busy }),
1774
+ view && !waiting && page !== "help" && /* @__PURE__ */ jsx7(FeishuPermissionStatus, { permissions: view.permissions ?? [], template: view.permission_template }),
1775
+ !view && !error && /* @__PURE__ */ jsx7("output", { className: "block text-sm", children: "\u6B63\u5728\u8BFB\u53D6\u98DE\u4E66\u8FDE\u63A5\u2026" }),
1776
+ !view && error && /* @__PURE__ */ jsx7("button", { type: "button", className: button, disabled: busy, onClick: () => void refresh(), children: "\u91CD\u65B0\u8BFB\u53D6\u8FDE\u63A5" }),
1777
+ (autoAuthorize || authorizationCapabilities?.length) && busy && !waiting && !error && !view?.error ? /* @__PURE__ */ jsx7("output", { className: "block text-sm", children: "\u6B63\u5728\u5904\u7406\u98DE\u4E66\u6388\u6743\u2026" }) : waiting ? /* @__PURE__ */ jsxs7("div", { className: "space-y-4 rounded-xl border border-[color-mix(in_srgb,currentColor_18%,transparent)] p-5 text-center", children: [
1778
+ /* @__PURE__ */ jsx7("h4", { className: "font-medium", children: view?.phase === "app" ? "\u5728\u98DE\u4E66\u9009\u62E9\u6216\u521B\u5EFA\u5E94\u7528" : view?.phase === "permissions" ? "\u5728\u98DE\u4E66\u786E\u8BA4\u5E76\u5F00\u901A\u6743\u9650" : "\u8BF7\u5728\u98DE\u4E66\u786E\u8BA4\u672C\u6B21\u6388\u6743" }),
1779
+ /* @__PURE__ */ jsx7("p", { className: "text-xs opacity-70", children: view?.current_step?.message || "\u5B8C\u6210\u5F53\u524D\u6B65\u9AA4\u540E\u81EA\u52A8\u7EE7\u7EED\uFF0C\u5DF2\u6709\u80FD\u529B\u59CB\u7EC8\u4FDD\u7559\u3002" }),
1780
+ url ? /* @__PURE__ */ jsxs7(Fragment, { children: [
1781
+ new TextEncoder().encode(url).length <= 2200 ? /* @__PURE__ */ jsx7(QRCodeSVG, { value: url, size: 180, marginSize: 4, title: "\u98DE\u4E66\u6388\u6743\u4E8C\u7EF4\u7801", className: "mx-auto rounded-lg bg-white" }) : /* @__PURE__ */ jsx7("p", { className: "text-xs opacity-70", children: "\u6388\u6743\u9879\u76EE\u8F83\u591A\uFF0C\u8BF7\u6253\u5F00\u98DE\u4E66\u6388\u6743\u9875\u9762\u7EE7\u7EED\u3002" }),
1782
+ /* @__PURE__ */ jsx7("a", { href: url, target: "_blank", rel: "noopener noreferrer", className: "block text-sm underline", children: "\u6253\u5F00\u98DE\u4E66\u6388\u6743\u9875\u9762" })
1783
+ ] }) : verifying ? /* @__PURE__ */ jsx7("output", { className: "block text-sm", children: view?.error ? "\u6838\u9A8C\u6682\u672A\u5B8C\u6210\uFF0C\u8BF7\u70B9\u51FB\u201C\u6211\u5DF2\u5B8C\u6210\u6388\u6743\u201D\u91CD\u8BD5\u3002" : "\u6B63\u5728\u6838\u9A8C\u6388\u6743\u7ED3\u679C\uFF0C\u8BF7\u7A0D\u5019\u3002" }) : /* @__PURE__ */ jsx7("p", { role: "alert", className: "text-sm", children: "\u5F53\u524D\u4E8C\u7EF4\u7801\u5DF2\u8FC7\u671F\u6216\u65E0\u6CD5\u9A8C\u8BC1\uFF0C\u8BF7\u91CD\u8BD5\u672C\u6B21\u6388\u6743\u3002" }),
1784
+ view?.expires_at && /* @__PURE__ */ jsxs7("p", { className: "text-xs opacity-70", children: [
1785
+ "\u6709\u6548\u81F3 ",
1786
+ new Date(view.expires_at * 1e3).toLocaleTimeString()
1787
+ ] }),
1788
+ /* @__PURE__ */ jsxs7("div", { className: "flex flex-wrap justify-center gap-3", children: [
1789
+ /* @__PURE__ */ jsx7("button", { type: "button", className: button, disabled: busy, onClick: () => void run("poll", view?.attempt_id ? { attempt_id: view.attempt_id } : {}), children: busy ? "\u6B63\u5728\u786E\u8BA4\u2026" : "\u6211\u5DF2\u5B8C\u6210\u6388\u6743" }),
1790
+ /* @__PURE__ */ jsx7("button", { type: "button", className: button, disabled: busy, onClick: () => void run("cancel", view?.attempt_id ? { attempt_id: view.attempt_id } : {}), children: "\u6682\u65F6\u53D6\u6D88" }),
1791
+ !url && !verifying && /* @__PURE__ */ jsx7("button", { type: "button", className: button, disabled: busy, onClick: retryCurrent, children: "\u91CD\u8BD5\u672C\u6B21\u6388\u6743" })
1792
+ ] }),
1793
+ view?.phase === "permissions" && /* @__PURE__ */ jsx7("button", { type: "button", className: "text-xs underline", disabled: busy, onClick: finishExisting, children: "\u5148\u4F7F\u7528\u5DF2\u5F00\u901A\u80FD\u529B\uFF0C\u5176\u4ED6\u7A0D\u540E\u5904\u7406" })
1794
+ ] }) : view && page === "select" ? /* @__PURE__ */ jsxs7(Fragment, { children: [
1795
+ view.app_id ? back : /* @__PURE__ */ jsx7("p", { className: "text-sm", children: "\u626B\u7801\u5173\u8054\u98DE\u4E66\u5E94\u7528\uFF0C\u5728\u98DE\u4E66\u5B98\u65B9\u9875\u9762\u786E\u8BA4\u6743\u9650\u3002" }),
1796
+ /* @__PURE__ */ jsx7(FeishuCapabilitySelection, { capabilities, permissions: view.permissions, operations: view.operations, domains: view.domains, selected, onChange: setSelected, disabled: busy }),
1797
+ view.catalog_unavailable && /* @__PURE__ */ jsx7("button", { type: "button", className: button, disabled: busy, onClick: () => void refresh(), children: "\u91CD\u65B0\u8BFB\u53D6\u5DE5\u4F5C\u80FD\u529B" }),
1798
+ /* @__PURE__ */ jsxs7("div", { className: "flex items-center justify-between gap-3 border-t border-[color-mix(in_srgb,currentColor_18%,transparent)] pt-4", children: [
1799
+ /* @__PURE__ */ jsx7("p", { className: "text-xs opacity-70", children: "\u6743\u9650\u7531\u98DE\u4E66\u5B98\u65B9\u9875\u9762\u7EDF\u4E00\u9009\u62E9\uFF0C\u5DF2\u6709\u6388\u6743\u7EE7\u7EED\u4FDD\u7559\u3002" }),
1800
+ /* @__PURE__ */ jsx7("button", { type: "button", className: `${button} border-blue-600 bg-blue-600 text-white`, disabled: busy || Boolean(view.app_id) && !selected.length, onClick: () => start(), children: busy ? "\u6B63\u5728\u51C6\u5907\u6388\u6743\u2026" : view.app_id ? preserveDisabled ? "\u8865\u5145\u6388\u6743\u5E76\u4FDD\u5B58" : "\u524D\u5F80\u98DE\u4E66\u6388\u6743" : "\u8FDE\u63A5\u98DE\u4E66" })
1801
+ ] }),
1802
+ preserveDisabled && /* @__PURE__ */ jsx7("p", { className: "text-xs", children: "\u6B64\u52A9\u624B\u5F53\u524D\u505C\u7528\uFF0C\u65B0\u589E\u6388\u6743\u4E0D\u4F1A\u81EA\u52A8\u542F\u7528\u3002\u9700\u8981\u65F6\u53EF\u5728\u7BA1\u7406\u8FDE\u63A5\u4E2D\u91CD\u65B0\u542F\u7528\u3002" })
1803
+ ] }) : view && page === "connection" ? /* @__PURE__ */ jsxs7(Fragment, { children: [
1804
+ /* @__PURE__ */ jsxs7("div", { className: "rounded-xl border border-[color-mix(in_srgb,currentColor_18%,transparent)] p-4", children: [
1805
+ /* @__PURE__ */ jsxs7("p", { className: "font-medium", children: [
1806
+ view.activation_pending === true ? "\u8FDE\u63A5\u5C1A\u672A\u5B8C\u6210" : view.enabled === false && view.app_id ? "\u5DF2\u5728\u6B64\u52A9\u624B\u4E2D\u505C\u7528" : active.length ? "\u98DE\u4E66\u5DF2\u53EF\u4EE5\u4F7F\u7528" : "\u8FD8\u6709\u9879\u76EE\u9700\u8981\u5904\u7406",
1807
+ view.label ? ` \xB7 ${view.label}` : ""
1808
+ ] }),
1809
+ /* @__PURE__ */ jsx7("p", { className: "mt-1 text-xs opacity-70", children: view.activation_pending === true ? "\u5B8C\u6210\u6388\u6743\u540E\u5373\u53EF\u5F00\u59CB\u4F7F\u7528" : view.enabled === false ? "\u5DF2\u6709\u6388\u6743\u4E0E SuperWork \u63A5\u6536\u8BBE\u7F6E\u4FDD\u7559\u3002" : "\u53EF\u4EE5\u8BA9\u52A9\u624B\u5904\u7406\u5DF2\u5F00\u901A\u7684\u98DE\u4E66\u5DE5\u4F5C\u3002" })
1810
+ ] }),
1811
+ view.activation_pending === true && active.length > 0 && /* @__PURE__ */ jsx7("button", { type: "button", className: button, disabled: busy, onClick: finishExisting, children: "\u5148\u4F7F\u7528\u5DF2\u5F00\u901A\u80FD\u529B\uFF0C\u5176\u4ED6\u7A0D\u540E\u5904\u7406" }),
1812
+ pending.length > 0 && /* @__PURE__ */ jsxs7("div", { className: "space-y-2 rounded-xl border border-[color-mix(in_srgb,currentColor_18%,transparent)] p-4 text-sm", children: [
1813
+ /* @__PURE__ */ jsxs7("p", { children: [
1814
+ pending.length,
1815
+ " \u9879\u5C1A\u672A\u5B8C\u6210\uFF0C\u5176\u4ED6\u5DF2\u5F00\u901A\u80FD\u529B\u7EE7\u7EED\u4FDD\u7559\u3002"
1816
+ ] }),
1817
+ /* @__PURE__ */ jsxs7("details", { className: "text-xs", children: [
1818
+ /* @__PURE__ */ jsx7("summary", { className: "cursor-pointer", children: "\u67E5\u770B\u672A\u5B8C\u6210\u9879\u76EE" }),
1819
+ /* @__PURE__ */ jsx7("div", { className: "mt-2 max-h-60 space-y-2 overflow-y-auto", children: pending.map((item) => /* @__PURE__ */ jsxs7("p", { children: [
1820
+ item.name,
1821
+ "\uFF1A",
1822
+ item.reason || item.next_action || statusLabels[item.status]
1823
+ ] }, item.id)) })
1824
+ ] }),
1825
+ receptionNeedsTest && /* @__PURE__ */ jsx7("p", { className: "text-xs", children: "\u63A5\u6536\u6743\u9650\u5DF2\u7ECF\u751F\u6548\uFF0C\u4ECD\u9700\u5411\u673A\u5668\u4EBA\u53D1\u9001\u6D4B\u8BD5\u6D88\u606F\u4EE5\u786E\u8BA4\u5B9E\u9645\u63A5\u6536\u3002" }),
1826
+ pendingPermissions.length > 0 && /* @__PURE__ */ jsx7("button", { type: "button", className: "text-xs underline", disabled: busy, onClick: () => start(pendingPermissions.map((item) => item.id)), children: "\u7EE7\u7EED\u5F00\u901A\u672A\u5B8C\u6210\u7684\u6743\u9650" }),
1827
+ failedUser.length > 0 && /* @__PURE__ */ jsx7("button", { type: "button", className: "text-xs underline", disabled: busy, onClick: () => start(failedUser.map((item) => item.id)), children: "\u4EC5\u8865\u5145\u672A\u5B8C\u6210\u7684\u672C\u4EBA\u6388\u6743" })
1828
+ ] }),
1829
+ /* @__PURE__ */ jsxs7("dl", { className: "divide-y divide-[color-mix(in_srgb,currentColor_18%,transparent)] rounded-xl border border-[color-mix(in_srgb,currentColor_18%,transparent)] px-4 text-sm", children: [
1830
+ /* @__PURE__ */ jsxs7("div", { className: "flex justify-between gap-3 py-4", children: [
1831
+ /* @__PURE__ */ jsx7("dt", { children: "\u53D1\u9001\u6D88\u606F" }),
1832
+ /* @__PURE__ */ jsx7("dd", { children: "\u673A\u5668\u4EBA\u8EAB\u4EFD" })
1833
+ ] }),
1834
+ /* @__PURE__ */ jsxs7("div", { className: "flex justify-between gap-3 py-4", children: [
1835
+ /* @__PURE__ */ jsx7("dt", { children: "\u63A5\u6536\u98DE\u4E66\u6D88\u606F" }),
1836
+ /* @__PURE__ */ jsx7("dd", { children: subscription === "enabled" ? "\u5DF2\u63A5\u5165\u52A9\u624B" : subscription === "paused" ? "\u5411\u52A9\u624B\u63A8\u9001\u5DF2\u6682\u505C" : "\u5C1A\u672A\u63A5\u5165\u52A9\u624B" })
1837
+ ] }),
1838
+ /* @__PURE__ */ jsxs7("div", { className: "flex justify-between gap-3 py-4", children: [
1839
+ /* @__PURE__ */ jsx7("dt", { children: "\u5DF2\u5F00\u901A\u7684\u5DE5\u4F5C\u80FD\u529B" }),
1840
+ /* @__PURE__ */ jsxs7("dd", { children: [
1841
+ categories.length,
1842
+ " \u7C7B \xB7 ",
1843
+ active.length,
1844
+ " \u9879\u64CD\u4F5C"
1845
+ ] })
1846
+ ] })
1847
+ ] }),
1848
+ /* @__PURE__ */ jsx7("div", { className: "flex flex-wrap gap-2", children: categories.map((name) => /* @__PURE__ */ jsx7("span", { className: "rounded-md border border-[color-mix(in_srgb,currentColor_18%,transparent)] px-2 py-1 text-xs", children: name }, name)) }),
1849
+ /* @__PURE__ */ jsxs7("details", { className: "text-sm", children: [
1850
+ /* @__PURE__ */ jsx7("summary", { className: "cursor-pointer", children: "\u67E5\u770B\u6743\u9650\u4E0E\u80FD\u529B\u72B6\u6001" }),
1851
+ /* @__PURE__ */ jsx7(FeishuCapabilitySelection, { capabilities, permissions: view.permissions, operations: view.operations, domains: view.domains, selected, onChange: setSelected, disabled: busy })
1852
+ ] }),
1853
+ /* @__PURE__ */ jsxs7("div", { className: "flex flex-wrap gap-3 border-t border-[color-mix(in_srgb,currentColor_18%,transparent)] pt-4", children: [
1854
+ /* @__PURE__ */ jsx7("button", { type: "button", className: `${button} bg-blue-600 text-white`, disabled: busy, onClick: () => void addCapabilities(), children: busy ? "\u6B63\u5728\u68C0\u67E5\u2026" : "\u8865\u5145\u6388\u6743" }),
1855
+ /* @__PURE__ */ jsx7("button", { type: "button", className: button, disabled: busy, onClick: () => setPage("manage"), children: "\u7BA1\u7406\u8FDE\u63A5" })
1856
+ ] })
1857
+ ] }) : view && page === "manage" ? /* @__PURE__ */ jsxs7(Fragment, { children: [
1858
+ back,
1859
+ /* @__PURE__ */ jsxs7("div", { className: "space-y-5 divide-y divide-[color-mix(in_srgb,currentColor_18%,transparent)] rounded-xl border border-[color-mix(in_srgb,currentColor_18%,transparent)] p-4 text-sm", children: [
1860
+ /* @__PURE__ */ jsxs7("div", { className: "flex items-center justify-between gap-4", children: [
1861
+ /* @__PURE__ */ jsxs7("div", { children: [
1862
+ /* @__PURE__ */ jsx7("p", { children: "\u5728\u6B64\u52A9\u624B\u4E2D\u4F7F\u7528\u98DE\u4E66" }),
1863
+ /* @__PURE__ */ jsx7("p", { className: "mt-1 text-xs opacity-70", children: "\u505C\u7528\u53EA\u5F71\u54CD\u6B64\u52A9\u624B\uFF0CSuperWork \u6388\u6743\u548C\u6D88\u606F\u63A5\u6536\u4FDD\u7559\u3002" })
1864
+ ] }),
1865
+ view.enabled === false ? /* @__PURE__ */ jsx7("button", { type: "button", className: button, disabled: busy, onClick: () => void run("finish", { capabilities: view.selected_capabilities ?? selected, enable: true }), children: "\u91CD\u65B0\u542F\u7528" }) : onDisable ? /* @__PURE__ */ jsx7("button", { type: "button", className: button, disabled: busy, onClick: async () => {
1866
+ if (inFlight.current) return;
1867
+ inFlight.current = true;
1868
+ setBusy(true);
1869
+ try {
1870
+ await callbacks.current.onDisable?.();
1871
+ const value = await callbacks.current.read();
1872
+ if (live.current) accept(value);
1873
+ await changed();
1874
+ } catch {
1875
+ if (live.current) setError("\u505C\u7528\u672A\u5B8C\u6210\uFF0C\u8BF7\u91CD\u8BD5\u3002");
1876
+ } finally {
1877
+ inFlight.current = false;
1878
+ if (live.current) setBusy(false);
1879
+ }
1880
+ }, children: "\u505C\u7528\u6B64\u52A9\u624B\u8FDE\u63A5" }) : /* @__PURE__ */ jsx7("span", { className: "text-xs", children: "\u5DF2\u542F\u7528" })
1881
+ ] }),
1882
+ /* @__PURE__ */ jsxs7("div", { className: "space-y-2 pt-4", children: [
1883
+ /* @__PURE__ */ jsx7("p", { children: "\u5411\u52A9\u624B\u63A8\u9001\u98DE\u4E66\u6D88\u606F" }),
1884
+ /* @__PURE__ */ jsx7("p", { className: "text-xs opacity-70", children: "\u4E0E\u6B64\u52A9\u624B\u4F7F\u7528\u6743\u9650\u5206\u522B\u7BA1\u7406\uFF1B\u6682\u505C\u63A8\u9001\u4ECD\u4FDD\u7559 SuperWork \u4E2D\u7684\u6388\u6743\u548C\u6D88\u606F\u63A5\u6536\u3002" }),
1885
+ ["enabled", "paused"].includes(subscription) && /* @__PURE__ */ jsx7("button", { type: "button", className: button, disabled: busy, onClick: () => void run(subscription === "paused" ? "resume" : "pause"), children: subscription === "paused" ? "\u6062\u590D\u5411\u52A9\u624B\u63A8\u9001" : "\u6682\u505C\u5411\u52A9\u624B\u63A8\u9001" }),
1886
+ bindDelivery && canReceive(view) && subscription !== "paused" && /* @__PURE__ */ jsx7("button", { type: "button", className: button, disabled: busy, onClick: () => void run("bind"), children: subscription === "enabled" ? "\u66F4\u65B0\u52A9\u624B\u63A5\u6536\u5730\u5740" : "\u91CD\u65B0\u63A5\u5165\u52A9\u624B\u6D88\u606F" }),
1887
+ receptionNeedsTest && /* @__PURE__ */ jsx7("p", { className: "text-xs", children: "\u63A5\u6536\u6743\u9650\u5DF2\u6838\u9A8C\uFF0C\u4E8B\u4EF6\u8BA2\u9605\u5C1A\u5F85\u6D4B\u8BD5\u3002\u8BF7\u5411\u673A\u5668\u4EBA\u53D1\u9001\u6D4B\u8BD5\u6D88\u606F\u540E\u5728\u8FDE\u63A5\u5E2E\u52A9\u4E2D\u67E5\u770B\u8BB0\u5F55\u3002" })
1888
+ ] }),
1889
+ /* @__PURE__ */ jsxs7("div", { className: "pt-4", children: [
1890
+ /* @__PURE__ */ jsx7("p", { children: view.label || "\u98DE\u4E66\u8D26\u53F7" }),
1891
+ /* @__PURE__ */ jsx7("p", { className: "text-xs opacity-70", children: "\u5DF2\u5F00\u901A\u80FD\u529B\u4E0E\u65B0\u589E\u6388\u6743\u5747\u53D7\u98DE\u4E66\u5E94\u7528\u53EF\u7528\u8303\u56F4\u548C\u6570\u636E\u6743\u9650\u9650\u5236\u3002" }),
1892
+ /* @__PURE__ */ jsx7("button", { type: "button", className: "mt-2 text-xs underline", disabled: busy, onClick: () => void addCapabilities(), children: "\u67E5\u770B\u4E0E\u6DFB\u52A0\u5DE5\u4F5C\u80FD\u529B" })
1893
+ ] })
1894
+ ] }),
1895
+ view.connection_id && /* @__PURE__ */ jsxs7("div", { className: "space-y-3 rounded-xl border border-red-600/30 p-4 text-sm", children: [
1896
+ /* @__PURE__ */ jsx7("p", { className: "font-medium", children: "\u79FB\u9664\u65E7\u8FDE\u63A5\uFF0C\u91CD\u65B0\u5F00\u59CB" }),
1897
+ /* @__PURE__ */ jsx7("p", { className: "text-xs opacity-70", children: "\u8FD9\u4F1A\u79FB\u9664 SuperWork \u4E2D\u6B64\u8FDE\u63A5\u7684\u51ED\u636E\u5E76\u505C\u6B62\u63A5\u6536\u548C\u8F6C\u53D1\u6D88\u606F\uFF0C\u5176\u4ED6\u4F9D\u8D56\u6B64\u8FDE\u63A5\u7684\u52A9\u624B\u4E5F\u4F1A\u53D7\u5230\u5F71\u54CD\u3002\u5386\u53F2\u6D88\u606F\u4E0E\u6392\u67E5\u65E5\u5FD7\u4FDD\u7559\uFF0C\u98DE\u4E66\u540E\u53F0\u5E94\u7528\u4E0D\u4F1A\u5220\u9664\u3002" }),
1898
+ /* @__PURE__ */ jsxs7(AlertDialog, { open: removingConnectionID !== null, onOpenChange: (open) => {
1899
+ if (!open) setRemovingConnectionID(null);
1900
+ }, children: [
1901
+ /* @__PURE__ */ jsx7(AlertDialogTrigger, { asChild: true, children: /* @__PURE__ */ jsx7("button", { type: "button", className: `${button} border-red-600/40 text-red-600`, disabled: busy, onClick: () => setRemovingConnectionID(view.connection_id ?? null), children: "\u79FB\u9664\u8FDE\u63A5\u5E76\u91CD\u65B0\u8FDE\u63A5" }) }),
1902
+ /* @__PURE__ */ jsxs7(AlertDialogContent, { className: "z-[60] w-[calc(100%_-_32px)] max-w-md p-5 sm:max-w-md", overlayClassName: "z-[60] bg-black/40", style: { backgroundColor: "var(--color-canvas, hsl(var(--popover, 0 0% 100%)))", color: "var(--color-copy, hsl(var(--foreground, 0 0% 10%)))" }, children: [
1903
+ /* @__PURE__ */ jsx7(AlertDialogTitle, { children: "\u786E\u8BA4\u79FB\u9664\u5F53\u524D\u98DE\u4E66\u8FDE\u63A5\uFF1F" }),
1904
+ /* @__PURE__ */ jsx7(AlertDialogDescription, { children: "SuperWork \u4E2D\u6B64\u8FDE\u63A5\u7684\u51ED\u636E\u5C06\u88AB\u79FB\u9664\uFF0C\u6D88\u606F\u63A5\u6536\u548C\u8F6C\u53D1\u5C06\u505C\u6B62\uFF0C\u5176\u4ED6\u4F9D\u8D56\u6B64\u8FDE\u63A5\u7684\u52A9\u624B\u4E5F\u4F1A\u53D7\u5F71\u54CD\u3002\u5386\u53F2\u6D88\u606F\u4E0E\u6392\u67E5\u65E5\u5FD7\u4F1A\u4FDD\u7559\uFF0C\u98DE\u4E66\u540E\u53F0\u5E94\u7528\u4E0D\u4F1A\u5220\u9664\u3002\u79FB\u9664\u540E\uFF0C\u7531\u4F60\u518D\u6B21\u70B9\u51FB\u201C\u8FDE\u63A5\u98DE\u4E66\u201D\u83B7\u53D6\u65B0\u4E8C\u7EF4\u7801\u3002" }),
1905
+ /* @__PURE__ */ jsxs7("div", { className: "flex flex-wrap justify-end gap-3", children: [
1906
+ /* @__PURE__ */ jsx7(AlertDialogCancel, { asChild: true, children: /* @__PURE__ */ jsx7("button", { type: "button", className: button, children: "\u53D6\u6D88" }) }),
1907
+ /* @__PURE__ */ jsx7(AlertDialogAction, { asChild: true, children: /* @__PURE__ */ jsx7("button", { type: "button", className: `${button} border-red-600 bg-red-600 text-white`, onClick: () => {
1908
+ if (removingConnectionID) void removeConnection(removingConnectionID);
1909
+ }, children: "\u786E\u8BA4\u79FB\u9664\u8FDE\u63A5" }) })
1910
+ ] })
1911
+ ] })
1912
+ ] })
1913
+ ] })
1914
+ ] }) : view && page === "help" ? /* @__PURE__ */ jsxs7(Fragment, { children: [
1915
+ back,
1916
+ /* @__PURE__ */ jsx7("p", { className: "text-sm", children: "\u53EA\u5904\u7406\u672A\u5B8C\u6210\u7684\u9879\u76EE\uFF0C\u5DF2\u7ECF\u5F00\u901A\u7684\u80FD\u529B\u4E0D\u9700\u8981\u91CD\u65B0\u7533\u8BF7\u3002" }),
1917
+ pending.map((item) => /* @__PURE__ */ jsxs7("div", { className: "rounded-lg border border-[color-mix(in_srgb,currentColor_18%,transparent)] p-3 text-sm", children: [
1918
+ /* @__PURE__ */ jsx7("p", { children: item.name }),
1919
+ /* @__PURE__ */ jsxs7("p", { className: "text-xs", children: [
1920
+ item.reason || item.next_action || statusLabels[item.status],
1921
+ item.actor ? ` \xB7 \u7531${item.actor}\u5904\u7406` : ""
1922
+ ] })
1923
+ ] }, item.id)),
1924
+ /* @__PURE__ */ jsx7("button", { type: "button", className: button, disabled: busy, onClick: () => void run("check"), children: "\u91CD\u65B0\u68C0\u67E5\u8FDE\u63A5" }),
1925
+ view.app_id && /* @__PURE__ */ jsx7("a", { className: "block text-xs underline", href: `https://open.feishu.cn/app/${encodeURIComponent(view.app_id)}/auth`, target: "_blank", rel: "noopener noreferrer", children: "\u5728\u98DE\u4E66\u67E5\u770B\u6743\u9650\u3001\u53D1\u5E03\u4E0E\u53EF\u7528\u8303\u56F4" }),
1926
+ /* @__PURE__ */ jsxs7("details", { className: "rounded-lg border border-[color-mix(in_srgb,currentColor_18%,transparent)] p-3 text-xs", children: [
1927
+ /* @__PURE__ */ jsx7("summary", { className: "cursor-pointer", children: "\u9AD8\u7EA7\u6392\u67E5\u4FE1\u606F" }),
1928
+ /* @__PURE__ */ jsxs7("div", { className: "space-y-3 pt-3", children: [
1929
+ /* @__PURE__ */ jsxs7("p", { children: [
1930
+ "\u8FDE\u63A5\u7F16\u53F7\uFF1A",
1931
+ view.connection_id || "\u5C1A\u672A\u521B\u5EFA"
1932
+ ] }),
1933
+ /* @__PURE__ */ jsxs7("p", { children: [
1934
+ "\u6392\u67E5\u7F16\u53F7\uFF1A",
1935
+ view.error?.trace_id || view.trace_id || "\u6682\u65E0\u8BB0\u5F55"
1936
+ ] }),
1937
+ /* @__PURE__ */ jsx7("p", { children: "\u8BB0\u5F55\u4E0D\u5305\u542B\u51ED\u636E\u4E0E\u6D88\u606F\u6B63\u6587\u3002" }),
1938
+ view.steps?.length ? /* @__PURE__ */ jsx7("ol", { className: "space-y-2", children: view.steps.map((step, index) => /* @__PURE__ */ jsxs7("li", { children: [
1939
+ stateLabels[step.state] ?? step.state,
1940
+ "\uFF1A",
1941
+ step.message
1942
+ ] }, `${step.id}:${index}`)) }) : null,
1943
+ diagnostics && /* @__PURE__ */ jsx7("button", { type: "button", className: button, disabled: busy, onClick: () => void inspect(), children: "\u8BFB\u53D6\u6392\u67E5\u8BB0\u5F55" }),
1944
+ diagnosticView?.runtime && /* @__PURE__ */ jsx7(ConnectorRuntimeDiagnostics, { runtime: diagnosticView.runtime }),
1945
+ diagnosticView && /* @__PURE__ */ jsx7("ol", { className: "space-y-3", children: diagnosticView.audit_events.map((event, index) => /* @__PURE__ */ jsxs7("li", { children: [
1946
+ event.message ?? auditLabels[event.type ?? ""] ?? "\u8FDE\u63A5\u72B6\u6001\u8BB0\u5F55",
1947
+ event.code && /* @__PURE__ */ jsxs7("p", { children: [
1948
+ "\u539F\u56E0\u7F16\u53F7\uFF1A",
1949
+ event.code
1950
+ ] }),
1951
+ event.platform_code && /* @__PURE__ */ jsxs7("p", { children: [
1952
+ "\u98DE\u4E66\u9519\u8BEF\u7801\uFF1A",
1953
+ event.platform_code
1954
+ ] }),
1955
+ event.platform_request_id && /* @__PURE__ */ jsxs7("p", { children: [
1956
+ "\u98DE\u4E66\u8BF7\u6C42\u7F16\u53F7\uFF1A",
1957
+ event.platform_request_id
1958
+ ] }),
1959
+ event.trace_id && /* @__PURE__ */ jsxs7("p", { children: [
1960
+ "\u6392\u67E5\u7F16\u53F7\uFF1A",
1961
+ event.trace_id
1962
+ ] })
1963
+ ] }, event.id ?? index)) })
1964
+ ] })
1965
+ ] })
1966
+ ] }) : null,
1967
+ !waiting && page !== "help" && /* @__PURE__ */ jsx7("button", { type: "button", className: "text-xs underline opacity-70", disabled: busy, onClick: () => setPage("help"), children: "\u9047\u5230\u95EE\u9898\uFF1F" })
1968
+ ] });
1969
+ }
1970
+
1971
+ export {
1972
+ DeviceConnection
1973
+ };
1974
+ /*! Bundled license information:
1975
+
1976
+ qrcode.react/lib/esm/index.js:
1977
+ (**
1978
+ * @license QR Code generator library (TypeScript)
1979
+ * Copyright (c) Project Nayuki.
1980
+ * SPDX-License-Identifier: MIT
1981
+ *)
1982
+ (**
1983
+ * @license qrcode.react
1984
+ * Copyright (c) Paul O'Shannessy
1985
+ * SPDX-License-Identifier: ISC
1986
+ *)
1987
+ */
1988
+ //# sourceMappingURL=chunk-ARX4JV5T.js.map