@eum-agent/channel-feishu 0.0.0-stage → 1.0.0

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 (4) hide show
  1. package/dist/index.js +3621 -0
  2. package/package.json +52 -3
  3. package/ui/ui.js +2045 -0
  4. package/README.md +0 -3
package/ui/ui.js ADDED
@@ -0,0 +1,2045 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ //#region src/ui/shared.ts
4
+ /** Returns feature failures; the global dialog owns gateway connectivity and authentication. */
5
+ function failureText(_ctx, error) {
6
+ const failure = error?.failure;
7
+ if (failure === "offline" || failure === "authentication") return null;
8
+ return error instanceof Error ? error.message : String(error);
9
+ }
10
+ /** Shows a failure outside a form as a toast. An offline failure says
11
+ * nothing: the host's connection dialog owns the outage. */
12
+ function useFailureToast(ctx) {
13
+ const toast = ctx.ui.useToast();
14
+ return useCallback((error) => {
15
+ const text = failureText(ctx, error);
16
+ if (text === null) return;
17
+ toast.add({
18
+ id: `failure::${text}`,
19
+ tone: "destructive",
20
+ title: text
21
+ });
22
+ }, [ctx, toast]);
23
+ }
24
+ /** One in-flight read and one follow-up for a burst of owner change notifications. */
25
+ function coalesceReads(read) {
26
+ let flight;
27
+ let again = false;
28
+ return () => {
29
+ again = true;
30
+ if (flight) return flight;
31
+ flight = (async () => {
32
+ while (again) {
33
+ again = false;
34
+ await read();
35
+ }
36
+ })().finally(() => {
37
+ flight = void 0;
38
+ });
39
+ return flight;
40
+ };
41
+ }
42
+ /** Refreshes mounted feature data after the host restores its gateway connection. */
43
+ function useGatewayRefresh(ctx, refresh) {
44
+ useEffect(() => {
45
+ let previous = ctx.host.get().connection;
46
+ return ctx.host.subscribe(() => {
47
+ const connection = ctx.host.get().connection;
48
+ const restored = connection === "online" && previous !== "online";
49
+ previous = connection;
50
+ if (restored) refresh();
51
+ });
52
+ }, [ctx, refresh]);
53
+ }
54
+ //#endregion
55
+ //#region src/ui/wire.ts
56
+ /** The plugin's methods and frames, by local name. */
57
+ var METHOD = {
58
+ listBots: "listBots",
59
+ listDefaults: "listDefaults",
60
+ retryGroup: "retryGroup",
61
+ recoverGroup: "recoverGroup",
62
+ saveBot: "saveBot",
63
+ removeBot: "removeBot",
64
+ testBot: "testBot",
65
+ startPairing: "startPairing",
66
+ listMembers: "listMembers",
67
+ setMemberPolicy: "setMemberPolicy",
68
+ removeMember: "removeMember",
69
+ listBindings: "listBindings",
70
+ getBinding: "getBinding",
71
+ bind: "bind",
72
+ unbind: "unbind"
73
+ };
74
+ var FRAME = {
75
+ botsChanged: "botsChanged",
76
+ membersChanged: "membersChanged",
77
+ bindingChanged: "bindingChanged"
78
+ };
79
+ /** The credential the AppSecret is written to, scoped by bot id. */
80
+ var APP_SECRET = "appSecret";
81
+ //#endregion
82
+ //#region src/ui/add.tsx
83
+ /** Builds the add form, which reports an id after both bot and secret are saved. */
84
+ function addFor(ctx) {
85
+ const t = ctx.i18n.t;
86
+ const { Button, Field, Input, SecretInput } = ctx.ui;
87
+ return function FeishuAdd({ onAdded, onLeaveGuard }) {
88
+ const [name, setName] = useState("");
89
+ const [appId, setAppId] = useState("");
90
+ const [secret, setSecret] = useState("");
91
+ const [error, setError] = useState(null);
92
+ const [busy, setBusy] = useState(false);
93
+ const busyRef = useRef(false);
94
+ const savedId = useRef(null);
95
+ useEffect(() => {
96
+ onLeaveGuard?.(() => Promise.resolve(!busyRef.current));
97
+ return () => onLeaveGuard?.(null);
98
+ }, [onLeaveGuard]);
99
+ async function save() {
100
+ if (busyRef.current) return;
101
+ busyRef.current = true;
102
+ setBusy(true);
103
+ setError(null);
104
+ try {
105
+ if (savedId.current === null) {
106
+ const saved = await ctx.invoke(METHOD.saveBot, {
107
+ name,
108
+ appId,
109
+ enabled: true
110
+ });
111
+ savedId.current = saved.id;
112
+ }
113
+ if (secret.trim() !== "") await ctx.credentials.set(savedId.current, APP_SECRET, secret);
114
+ onAdded(savedId.current);
115
+ } catch (failure) {
116
+ setError(failureText(ctx, failure));
117
+ } finally {
118
+ busyRef.current = false;
119
+ setBusy(false);
120
+ }
121
+ }
122
+ return /* @__PURE__ */ jsxs("div", {
123
+ className: "feishu-form",
124
+ children: [
125
+ /* @__PURE__ */ jsx(Field, {
126
+ className: "settings-field-row",
127
+ label: t("feishu.name"),
128
+ required: true,
129
+ inline: true,
130
+ children: (field) => /* @__PURE__ */ jsx(Input, {
131
+ ...field,
132
+ value: name,
133
+ maxLength: 40,
134
+ disabled: busy || savedId.current !== null,
135
+ onChange: (event) => setName(event.target.value)
136
+ })
137
+ }),
138
+ /* @__PURE__ */ jsx(Field, {
139
+ className: "settings-field-row",
140
+ label: t("feishu.appId"),
141
+ required: true,
142
+ inline: true,
143
+ children: (field) => /* @__PURE__ */ jsx(Input, {
144
+ ...field,
145
+ value: appId,
146
+ disabled: busy || savedId.current !== null,
147
+ onChange: (event) => setAppId(event.target.value),
148
+ placeholder: "cli_xxxxxxxxxxxxxxxx"
149
+ })
150
+ }),
151
+ /* @__PURE__ */ jsx(Field, {
152
+ className: "settings-field-row",
153
+ label: t("feishu.appSecret"),
154
+ required: true,
155
+ inline: true,
156
+ children: (field) => /* @__PURE__ */ jsx(SecretInput, {
157
+ ...field,
158
+ label: t("feishu.appSecret"),
159
+ value: secret,
160
+ disabled: busy,
161
+ onValueChange: setSecret
162
+ })
163
+ }),
164
+ error === null ? null : /* @__PURE__ */ jsx("p", {
165
+ className: "feishu-error",
166
+ children: error
167
+ }),
168
+ /* @__PURE__ */ jsx("div", {
169
+ className: "feishu-actions",
170
+ children: /* @__PURE__ */ jsx(Button, {
171
+ variant: "primary",
172
+ disabled: busy || name.trim() === "" || appId.trim() === "" || secret.trim() === "",
173
+ onClick: () => void save(),
174
+ children: t("feishu.save")
175
+ })
176
+ })
177
+ ]
178
+ });
179
+ };
180
+ }
181
+ /** Feishu's bundled logo, usable without an external image request. */
182
+ var FEISHU_LOGO = `data:image/svg+xml,${encodeURIComponent("<svg width=\"256\" height=\"256\" viewBox=\"0 0 256 256\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><g clip-path=\"url(#clip0_501_38)\"><rect width=\"256\" height=\"256\" fill=\"white\"/><path d=\"M135.837 130.957L136.315 130.48C136.625 130.17 136.959 129.835 137.293 129.525L137.962 128.88L139.943 126.923L142.665 124.273L144.981 121.981L147.153 119.832L149.421 117.588L151.498 115.535L154.411 112.67C154.96 112.121 155.533 111.596 156.106 111.071C157.156 110.116 158.255 109.184 159.353 108.277C160.379 107.466 161.43 106.678 162.504 105.914C164.008 104.839 165.56 103.861 167.136 102.906C168.688 101.998 170.287 101.139 171.91 100.327C173.438 99.5872 175.014 98.8948 176.614 98.2741C177.497 97.916 178.404 97.6056 179.311 97.2953C179.765 97.152 180.219 96.9849 180.696 96.8417C176.661 80.9656 169.284 66.1638 159.042 53.3912C157.061 50.9322 154.053 49.4998 150.901 49.4998H67.2235C66.3641 49.4998 65.6479 50.1921 65.6479 51.0755C65.6479 51.5768 65.8866 52.0304 66.2925 52.3408C94.8456 73.2782 118.528 100.184 135.646 131.172L135.837 130.957Z\" fill=\"#00D6B9\"/><path d=\"M102.581 204.609C145.793 204.609 183.442 180.759 203.066 145.521C203.759 144.279 204.427 143.038 205.072 141.773C204.093 143.659 202.995 145.473 201.777 147.192C201.347 147.789 200.918 148.386 200.464 148.983C199.891 149.723 199.318 150.415 198.721 151.107C198.244 151.656 197.766 152.182 197.265 152.707C196.262 153.757 195.212 154.76 194.114 155.691C193.493 156.216 192.896 156.718 192.252 157.195C191.511 157.768 190.747 158.317 189.983 158.819C189.506 159.153 189.005 159.463 188.503 159.774C188.002 160.084 187.477 160.394 186.928 160.705C185.853 161.302 184.731 161.874 183.609 162.376C182.63 162.806 181.628 163.211 180.625 163.593C179.527 163.999 178.428 164.357 177.283 164.668C175.587 165.145 173.892 165.503 172.15 165.766C170.908 165.957 169.619 166.1 168.354 166.196C167.017 166.291 165.656 166.315 164.295 166.315C162.791 166.291 161.287 166.196 159.759 166.029C158.637 165.909 157.515 165.742 156.393 165.551C155.414 165.384 154.435 165.169 153.456 164.93C152.931 164.811 152.43 164.668 151.905 164.525C150.472 164.143 149.04 163.737 147.607 163.331C146.891 163.116 146.175 162.925 145.482 162.71C144.408 162.4 143.358 162.065 142.307 161.731C141.448 161.469 140.588 161.182 139.729 160.896C138.917 160.633 138.082 160.37 137.27 160.084L135.599 159.511C134.93 159.272 134.238 159.033 133.569 158.795L132.137 158.27C131.182 157.935 130.227 157.577 129.296 157.219C128.747 157.004 128.198 156.813 127.649 156.598C126.909 156.312 126.192 156.025 125.452 155.739C124.688 155.429 123.9 155.118 123.136 154.808L121.632 154.187L119.77 153.423L118.338 152.826L116.858 152.182L115.568 151.609L114.399 151.083L113.205 150.534L111.987 149.961L110.435 149.245L108.812 148.481C108.239 148.195 107.666 147.932 107.093 147.646L105.637 146.929C79.9484 134.109 56.7668 116.824 37.1425 95.863C36.5456 95.2423 35.5668 95.1945 34.9222 95.7914C34.6118 96.0779 34.4208 96.5076 34.4208 96.9373L34.4686 170.779V176.772C34.4686 180.257 36.1875 183.504 39.0762 185.438C57.865 197.996 79.9723 204.657 102.581 204.609Z\" fill=\"#3370FF\"/><path d=\"M229.566 100.517C214.98 93.379 198.292 91.8511 182.654 96.2439C181.986 96.4348 181.341 96.6258 180.697 96.8168C180.243 96.9601 179.789 97.1033 179.312 97.2704C178.405 97.5808 177.498 97.915 176.614 98.2493C175.015 98.87 173.463 99.5623 171.911 100.302C170.288 101.09 168.688 101.95 167.136 102.857C165.537 103.788 164.009 104.791 162.505 105.865C161.43 106.629 160.38 107.417 159.353 108.229C158.231 109.136 157.157 110.043 156.107 111.022C155.534 111.547 154.985 112.072 154.412 112.621L151.499 115.486L149.422 117.539L147.154 119.783L144.981 121.932L142.666 124.224L139.968 126.898L137.986 128.856L137.318 129.5C137.007 129.811 136.673 130.145 136.339 130.455L135.862 130.933L135.121 131.625C134.835 131.888 134.572 132.126 134.286 132.389C127.1 139.002 119.078 144.66 110.46 149.268L112.012 149.984L113.229 150.557L114.423 151.106L115.593 151.631L116.882 152.204L118.362 152.849L119.794 153.446L121.657 154.21L123.161 154.83C123.925 155.141 124.712 155.451 125.476 155.761C126.193 156.048 126.933 156.334 127.673 156.621C128.222 156.836 128.771 157.027 129.32 157.242C130.275 157.6 131.23 157.934 132.161 158.292L133.594 158.817C134.262 159.056 134.93 159.295 135.623 159.533L137.294 160.106C138.106 160.369 138.917 160.656 139.753 160.918C140.612 161.205 141.472 161.467 142.331 161.754C143.382 162.088 144.456 162.398 145.507 162.733C146.223 162.947 146.939 163.162 147.631 163.353C149.064 163.759 150.496 164.165 151.929 164.547C152.454 164.69 152.955 164.81 153.48 164.953C154.459 165.192 155.438 165.383 156.417 165.574C157.539 165.765 158.661 165.932 159.783 166.051C161.311 166.218 162.815 166.314 164.319 166.338C165.68 166.361 167.041 166.314 168.378 166.218C169.667 166.123 170.932 165.979 172.174 165.788C173.893 165.526 175.612 165.144 177.307 164.69C178.429 164.38 179.551 164.022 180.649 163.616C181.652 163.258 182.654 162.852 183.633 162.398C184.755 161.897 185.877 161.324 186.952 160.727C187.477 160.441 188.002 160.13 188.527 159.796C189.053 159.486 189.53 159.152 190.007 158.841C190.771 158.316 191.535 157.791 192.275 157.218C192.92 156.74 193.541 156.239 194.138 155.714C195.212 154.783 196.262 153.78 197.265 152.729C197.766 152.204 198.244 151.679 198.721 151.13C199.318 150.438 199.915 149.721 200.464 149.005C200.918 148.432 201.348 147.835 201.777 147.215C202.971 145.496 204.069 143.705 205.048 141.843L206.17 139.623L216.149 119.736L216.269 119.497C219.563 112.383 224.052 105.984 229.566 100.517Z\" fill=\"#133C9A\"/></g><defs><clipPath id=\"clip0_501_38\"><rect width=\"256\" height=\"256\" rx=\"60\" fill=\"white\"/></clipPath></defs></svg>")}`;
183
+ //#endregion
184
+ //#region src/ui/members.tsx
185
+ /** Builds the member list embedded in a session's channel dialog. */
186
+ function membersFor(ctx) {
187
+ const { Segmented, Button, Avatar, Badge } = ctx.ui;
188
+ const t = ctx.i18n.t;
189
+ return function Members({ binding }) {
190
+ const [members, setMembers] = useState([]);
191
+ const [error, setError] = useState(null);
192
+ const [syncError, setSyncError] = useState(null);
193
+ const [busy, setBusy] = useState(null);
194
+ const [loading, setLoading] = useState(true);
195
+ const generation = useRef(0);
196
+ const saving = useRef(false);
197
+ const load = useMemo(() => coalesceReads(async () => {
198
+ const request = ++generation.current;
199
+ setLoading(true);
200
+ try {
201
+ const result = await ctx.invoke(METHOD.listMembers, {
202
+ botId: binding.botId,
203
+ sessionId: binding.sessionId
204
+ });
205
+ if (request !== generation.current) return;
206
+ setError(null);
207
+ setMembers(result.members);
208
+ setSyncError(result.memberError);
209
+ } catch (failure) {
210
+ if (request === generation.current) setError(failureText(ctx, failure));
211
+ } finally {
212
+ if (request === generation.current) setLoading(false);
213
+ }
214
+ }), [binding.botId, binding.sessionId]);
215
+ useGatewayRefresh(ctx, load);
216
+ useEffect(() => {
217
+ load();
218
+ const off = ctx.on(FRAME.membersChanged, ({ payload }) => {
219
+ if (payload.sessionId === binding.sessionId) load();
220
+ });
221
+ return () => {
222
+ generation.current++;
223
+ off();
224
+ };
225
+ }, [load, binding.sessionId]);
226
+ async function save(one, policy) {
227
+ if (saving.current) return;
228
+ saving.current = true;
229
+ generation.current++;
230
+ setLoading(false);
231
+ setBusy(one.openId);
232
+ setError(null);
233
+ try {
234
+ const updated = await ctx.invoke(METHOD.setMemberPolicy, {
235
+ botId: binding.botId,
236
+ sessionId: binding.sessionId,
237
+ openId: one.openId,
238
+ policy
239
+ });
240
+ setMembers((list) => list.map((row) => row.openId === updated.openId ? updated : row));
241
+ } catch (failure) {
242
+ setError(failureText(ctx, failure));
243
+ } finally {
244
+ saving.current = false;
245
+ setBusy(null);
246
+ }
247
+ }
248
+ return /* @__PURE__ */ jsxs("section", {
249
+ className: "feishu-form feishu-sync-members",
250
+ children: [
251
+ /* @__PURE__ */ jsxs("div", {
252
+ className: "feishu-topic-heading",
253
+ children: [
254
+ /* @__PURE__ */ jsx("strong", { children: t("feishu.sessionMembers") }),
255
+ !loading && !error && /* @__PURE__ */ jsx(Badge, {
256
+ size: "sm",
257
+ shape: "pill",
258
+ tone: "neutral",
259
+ children: members.length
260
+ }),
261
+ /* @__PURE__ */ jsx(Button, {
262
+ variant: "ghost",
263
+ icon: "refresh",
264
+ className: "feishu-sync-icon",
265
+ "aria-label": t("feishu.refresh"),
266
+ title: t("feishu.refresh"),
267
+ disabled: loading || busy !== null,
268
+ onClick: () => void load()
269
+ })
270
+ ]
271
+ }),
272
+ /* @__PURE__ */ jsx("p", {
273
+ className: "feishu-muted feishu-sync-members-hint",
274
+ children: t("feishu.memberScope")
275
+ }),
276
+ (error || syncError) && /* @__PURE__ */ jsx("p", {
277
+ role: "alert",
278
+ className: "feishu-error",
279
+ children: error || syncError
280
+ }),
281
+ loading && members.length === 0 && /* @__PURE__ */ jsx("p", {
282
+ className: "feishu-muted",
283
+ children: t("feishu.loading")
284
+ }),
285
+ !loading && !error && members.length === 0 && /* @__PURE__ */ jsx("p", {
286
+ className: "feishu-muted",
287
+ children: t("feishu.noMembers")
288
+ }),
289
+ /* @__PURE__ */ jsx("ul", {
290
+ className: "feishu-topics",
291
+ children: members.map((one) => /* @__PURE__ */ jsxs("li", {
292
+ className: "feishu-topic-heading feishu-member-row",
293
+ children: [
294
+ /* @__PURE__ */ jsx(Avatar, {
295
+ name: one.name || one.openId,
296
+ seed: one.openId,
297
+ alt: "",
298
+ size: "sm",
299
+ shape: "circle"
300
+ }),
301
+ /* @__PURE__ */ jsxs("div", {
302
+ className: "feishu-member-name",
303
+ title: one.openId,
304
+ children: [/* @__PURE__ */ jsx("span", { children: one.name || one.openId }), one.isOwner && /* @__PURE__ */ jsx(Badge, {
305
+ size: "sm",
306
+ tone: "neutral",
307
+ children: t("feishu.owner")
308
+ })]
309
+ }),
310
+ /* @__PURE__ */ jsx(Segmented, {
311
+ label: `${one.name || one.openId} ${t("feishu.permission")}`,
312
+ value: one.policy,
313
+ disabled: one.isOwner || busy !== null || binding.state !== "active",
314
+ onSelect: (value) => void save(one, value),
315
+ options: [
316
+ {
317
+ value: "reject",
318
+ label: t("feishu.reject")
319
+ },
320
+ {
321
+ value: "ask",
322
+ label: t("feishu.ask")
323
+ },
324
+ {
325
+ value: "accept",
326
+ label: t("feishu.allow")
327
+ }
328
+ ]
329
+ })
330
+ ]
331
+ }, one.openId))
332
+ })
333
+ ]
334
+ });
335
+ };
336
+ }
337
+ //#endregion
338
+ //#region src/ui/binding.tsx
339
+ /** Mounts the selected bot's confirmation or its existing session binding. */
340
+ function bindingDialogFor(ctx) {
341
+ const t = ctx.i18n.t;
342
+ const Members = membersFor(ctx);
343
+ const { Button, AlertDialog } = ctx.ui;
344
+ return function FeishuBinding({ sessionId, instanceId, replacing, beforeBind, changeChannel }) {
345
+ const [binding, setBinding] = useState(void 0);
346
+ const [bot, setBot] = useState(null);
347
+ const [busy, setBusy] = useState(false);
348
+ const [removing, setRemoving] = useState(false);
349
+ const [error, setError] = useState(null);
350
+ const [replaced, setReplaced] = useState(false);
351
+ const version = useRef(0);
352
+ const submitting = useRef(false);
353
+ const load = useMemo(() => coalesceReads(async () => {
354
+ const request = ++version.current;
355
+ try {
356
+ const [one, bots] = await Promise.all([ctx.invoke(METHOD.getBinding, { sessionId }), ctx.invoke(METHOD.listBots, {})]);
357
+ if (version.current !== request) return;
358
+ setBinding(one?.botId === instanceId ? one : null);
359
+ setBot(bots.find((one) => one.id === instanceId) ?? null);
360
+ } catch (failure) {
361
+ if (version.current === request) setError(failureText(ctx, failure));
362
+ }
363
+ }), [sessionId, instanceId]);
364
+ useGatewayRefresh(ctx, load);
365
+ useEffect(() => {
366
+ load();
367
+ const off = ctx.on(FRAME.bindingChanged, ({ payload }) => {
368
+ if (payload.sessionId === sessionId) load();
369
+ });
370
+ const offBots = ctx.on(FRAME.botsChanged, () => void load());
371
+ return () => {
372
+ version.current++;
373
+ off();
374
+ offBots();
375
+ };
376
+ }, [load, sessionId]);
377
+ async function run(work) {
378
+ if (submitting.current) return;
379
+ submitting.current = true;
380
+ setBusy(true);
381
+ setError(null);
382
+ try {
383
+ await work();
384
+ await load();
385
+ } catch (failure) {
386
+ setError(failureText(ctx, failure));
387
+ } finally {
388
+ submitting.current = false;
389
+ setBusy(false);
390
+ }
391
+ }
392
+ async function bind() {
393
+ await beforeBind();
394
+ if (replacing) setReplaced(true);
395
+ await ctx.invoke(METHOD.bind, {
396
+ sessionId,
397
+ botId: instanceId
398
+ });
399
+ }
400
+ if (binding === void 0) return /* @__PURE__ */ jsxs("div", {
401
+ className: "feishu-form",
402
+ children: [/* @__PURE__ */ jsx("p", {
403
+ className: error ? "feishu-error" : "feishu-muted",
404
+ role: error ? "alert" : "status",
405
+ children: error ?? t("feishu.loading")
406
+ }), error && /* @__PURE__ */ jsx(Button, {
407
+ variant: "outline",
408
+ onClick: () => {
409
+ setError(null);
410
+ load();
411
+ },
412
+ children: t("feishu.retry")
413
+ })]
414
+ });
415
+ return /* @__PURE__ */ jsxs("div", {
416
+ className: "feishu-form feishu-sync",
417
+ children: [
418
+ binding ? /* @__PURE__ */ jsxs(Fragment, { children: [
419
+ /* @__PURE__ */ jsxs("div", {
420
+ className: "feishu-sync-heading",
421
+ children: [
422
+ /* @__PURE__ */ jsx("span", {
423
+ className: "feishu-sync-avatar",
424
+ children: /* @__PURE__ */ jsxs("svg", {
425
+ viewBox: "0 0 24 24",
426
+ fill: "none",
427
+ stroke: "currentColor",
428
+ strokeWidth: "1.75",
429
+ strokeLinecap: "round",
430
+ strokeLinejoin: "round",
431
+ "aria-hidden": "true",
432
+ children: [/* @__PURE__ */ jsx("path", { d: "M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2m20 0v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75" }), /* @__PURE__ */ jsx("circle", {
433
+ cx: "9",
434
+ cy: "7",
435
+ r: "4"
436
+ })]
437
+ })
438
+ }),
439
+ /* @__PURE__ */ jsxs("div", {
440
+ className: "feishu-grow",
441
+ children: [/* @__PURE__ */ jsxs("div", {
442
+ className: "feishu-sync-name-line",
443
+ children: [/* @__PURE__ */ jsx("strong", {
444
+ title: binding.chatName,
445
+ children: binding.chatName
446
+ }), /* @__PURE__ */ jsx("small", {
447
+ title: `${t("feishu.groupId")}: ${binding.chatId}`,
448
+ children: binding.chatId
449
+ })]
450
+ }), /* @__PURE__ */ jsxs("div", {
451
+ className: "feishu-sync-name-line feishu-sync-secondary",
452
+ children: [/* @__PURE__ */ jsx("span", {
453
+ title: binding.botName,
454
+ children: binding.botName
455
+ }), /* @__PURE__ */ jsx("small", {
456
+ title: `${t("feishu.session")}: ${binding.sessionId}`,
457
+ children: binding.sessionId
458
+ })]
459
+ })]
460
+ }),
461
+ /* @__PURE__ */ jsxs("div", {
462
+ className: "feishu-sync-status-actions",
463
+ children: [/* @__PURE__ */ jsxs("span", {
464
+ className: "feishu-group-status",
465
+ "data-state": binding.state,
466
+ children: [/* @__PURE__ */ jsxs("svg", {
467
+ viewBox: "0 0 24 24",
468
+ fill: "none",
469
+ stroke: "currentColor",
470
+ strokeWidth: "1.75",
471
+ strokeLinecap: "round",
472
+ strokeLinejoin: "round",
473
+ "aria-hidden": "true",
474
+ children: [/* @__PURE__ */ jsx("path", { d: "M20 16.2A4.5 4.5 0 0 0 18 7.5h-1.3A7 7 0 1 0 4 16.25" }), binding.state === "active" ? /* @__PURE__ */ jsx("path", { d: "m9 18 2 2 4-4" }) : binding.state === "broken" ? /* @__PURE__ */ jsx("path", { d: "M12 13v4m0 3h.01" }) : /* @__PURE__ */ jsx("path", { d: "M10 14v6m4-6v6" })]
475
+ }), t(`feishu.topic.${binding.state}`)]
476
+ }), /* @__PURE__ */ jsx(Button, {
477
+ variant: "ghost",
478
+ className: "feishu-sync-icon",
479
+ disabled: busy,
480
+ title: t("feishu.unbind"),
481
+ "aria-label": t("feishu.unbind"),
482
+ onClick: () => setRemoving(true),
483
+ children: /* @__PURE__ */ jsx("svg", {
484
+ viewBox: "0 0 24 24",
485
+ fill: "none",
486
+ stroke: "currentColor",
487
+ strokeWidth: "1.75",
488
+ strokeLinecap: "round",
489
+ strokeLinejoin: "round",
490
+ "aria-hidden": "true",
491
+ children: /* @__PURE__ */ jsx("path", { d: "m18.84 12.25 1.41-1.41a5 5 0 0 0-7.07-7.07l-1.41 1.41M5.16 11.75l-1.41 1.41a5 5 0 0 0 7.07 7.07l1.41-1.41M8 2v3M2 8h3m11 13v-3m6-2h-3" })
492
+ })
493
+ })]
494
+ })
495
+ ]
496
+ }),
497
+ binding.reason && /* @__PURE__ */ jsx("p", {
498
+ className: "feishu-error",
499
+ children: binding.reason
500
+ }),
501
+ binding.state === "broken" && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Button, {
502
+ variant: "outline",
503
+ disabled: busy,
504
+ onClick: () => void run(() => ctx.invoke(METHOD.bind, {
505
+ sessionId,
506
+ botId: instanceId
507
+ })),
508
+ children: t("feishu.retry")
509
+ }) }),
510
+ /* @__PURE__ */ jsx(Members, { binding }, binding.chatId)
511
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
512
+ /* @__PURE__ */ jsxs("div", {
513
+ className: "feishu-sync-heading",
514
+ children: [/* @__PURE__ */ jsx("img", {
515
+ src: FEISHU_LOGO,
516
+ alt: "",
517
+ className: "feishu-sync-logo"
518
+ }), /* @__PURE__ */ jsxs("div", {
519
+ className: "feishu-grow",
520
+ children: [/* @__PURE__ */ jsx("strong", { children: bot?.name ?? t("feishu.unavailable") }), /* @__PURE__ */ jsx("span", {
521
+ className: "feishu-muted",
522
+ children: t("feishu.title")
523
+ })]
524
+ })]
525
+ }),
526
+ /* @__PURE__ */ jsx("p", { children: t(replacing ? "feishu.replaceHint" : "feishu.createHint") }),
527
+ !bot?.enabled || !bot.owner ? /* @__PURE__ */ jsx("p", {
528
+ className: "feishu-error",
529
+ children: t("feishu.botNotReady")
530
+ }) : null
531
+ ] }),
532
+ /* @__PURE__ */ jsxs("div", {
533
+ className: "feishu-sync-notice",
534
+ children: [/* @__PURE__ */ jsxs("svg", {
535
+ viewBox: "0 0 24 24",
536
+ fill: "none",
537
+ stroke: "currentColor",
538
+ strokeWidth: "1.75",
539
+ strokeLinecap: "round",
540
+ strokeLinejoin: "round",
541
+ "aria-hidden": "true",
542
+ children: [/* @__PURE__ */ jsx("circle", {
543
+ cx: "12",
544
+ cy: "12",
545
+ r: "9"
546
+ }), /* @__PURE__ */ jsx("path", { d: "M12 11v6m0-10h.01" })]
547
+ }), /* @__PURE__ */ jsxs("p", { children: [
548
+ /* @__PURE__ */ jsx("strong", { children: t("feishu.exposureTitle") }),
549
+ /* @__PURE__ */ jsx("br", {}),
550
+ t("feishu.exposureDetails")
551
+ ] })]
552
+ }),
553
+ error && /* @__PURE__ */ jsxs("div", {
554
+ role: "alert",
555
+ className: "feishu-error",
556
+ children: [replaced && !binding && /* @__PURE__ */ jsx("p", { children: t("feishu.replaceFailed") }), error]
557
+ }),
558
+ /* @__PURE__ */ jsxs("div", {
559
+ className: "feishu-sync-footer",
560
+ children: [/* @__PURE__ */ jsx(Button, {
561
+ variant: "ghost",
562
+ className: "feishu-sync-change",
563
+ disabled: busy,
564
+ onClick: changeChannel,
565
+ children: t("feishu.changeChannel")
566
+ }), !binding && /* @__PURE__ */ jsx(Button, {
567
+ variant: "primary",
568
+ disabled: busy || !bot?.enabled || !bot.owner,
569
+ onClick: () => void run(bind),
570
+ children: busy ? t("feishu.binding") : t(replacing ? "feishu.replaceCreate" : "feishu.createBind")
571
+ })]
572
+ }),
573
+ /* @__PURE__ */ jsxs(AlertDialog, {
574
+ open: removing,
575
+ onOpenChange: (open) => {
576
+ if (!busy) setRemoving(open);
577
+ },
578
+ title: t("feishu.unbindTitle"),
579
+ actions: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
580
+ variant: "outline",
581
+ disabled: busy,
582
+ onClick: () => setRemoving(false),
583
+ children: t("feishu.cancel")
584
+ }), /* @__PURE__ */ jsx(Button, {
585
+ variant: "destructive",
586
+ disabled: busy,
587
+ onClick: () => void run(async () => {
588
+ await ctx.invoke(METHOD.unbind, { sessionId });
589
+ setRemoving(false);
590
+ }),
591
+ children: t("feishu.unbind")
592
+ })] }),
593
+ children: [/* @__PURE__ */ jsx("p", { children: t("feishu.unbindBody") }), error && /* @__PURE__ */ jsx("p", {
594
+ role: "alert",
595
+ className: "feishu-error",
596
+ children: error
597
+ })]
598
+ })
599
+ ]
600
+ });
601
+ };
602
+ }
603
+ /** Browser translations keyed by the product's supported language-region IDs. */
604
+ var CATALOGUES = {
605
+ "zh-CN": {
606
+ "feishu.disabled": "已停用",
607
+ "feishu.ownerUnpaired": "尚未配对所有者",
608
+ "feishu.bindingDetails": "绑定详情",
609
+ "feishu.groupId": "群 ID",
610
+ "feishu.changeChannel": "更换 IM 通道",
611
+ "feishu.createBind": "创建群并绑定",
612
+ "feishu.createHint": "将为当前会话创建一个飞书普通群,并邀请机器人所有者加入。",
613
+ "feishu.replaceHint": "确认后将解除当前绑定,再创建新的飞书群。旧群和历史消息会保留。",
614
+ "feishu.replaceCreate": "确认更换并创建群",
615
+ "feishu.replaceFailed": "原绑定已解除,新群尚未绑定成功。",
616
+ "feishu.botNotReady": "此机器人不可用,请在 IM 通道设置中启用并配对所有者。",
617
+ "feishu.recoveryChat": "核实后填写已创建群的群 ID",
618
+ "feishu.defaultsHint": "机器人加入已有群时,使用以下归属创建工作会话。修改只影响后续新建会话。",
619
+ "feishu.defaultAgent": "默认智能体",
620
+ "feishu.defaultWorkspace": "默认工作空间",
621
+ "feishu.unconfigured": "未配置",
622
+ "feishu.unavailable": "不可用",
623
+ "feishu.saved": "已保存",
624
+ "feishu.sessionMembers": "成员管理",
625
+ "feishu.memberScope": "授权仅对当前会话生效,新成员默认需确认。",
626
+ "feishu.exposureTitle": "群内成员均可阅读同步内容。",
627
+ "feishu.exposureDetails": "包括回复、思考摘要、工具调用摘要和交互请求;成员授权仅控制发言与操作。",
628
+ "feishu.noMembers": "暂无已确认的群成员",
629
+ "feishu.permission": "权限",
630
+ "feishu.allow": "允许",
631
+ "feishu.ask": "需确认",
632
+ "feishu.reject": "拒绝",
633
+ "feishu.refresh": "刷新",
634
+ "feishu.openSession": "打开会话",
635
+ "feishu.pendingGroups": "待处理的群",
636
+ "feishu.ownerPaired": "已配对",
637
+ "feishu.pairWaiting": "等待配对",
638
+ "feishu.pairStarting": "正在获取…",
639
+ "feishu.pairAgain": "重新获取配对码",
640
+ "feishu.pairCopy": "复制配对码",
641
+ "feishu.pairCopyFailed": "复制失败,请手动选择配对码复制。",
642
+ "feishu.pairRemaining": "剩余 {{time}}",
643
+ "feishu.pairExpired": "配对码已过期,请重新获取。",
644
+ "feishu.management": "管理配置",
645
+ "feishu.authorization": "授权管理",
646
+ "feishu.managementHint": "配对所有者后,即可将瑶光会话绑定到这个机器人。",
647
+ "feishu.pairOffline": "请先在应用凭证中启用机器人,待连接在线后再配对。",
648
+ "feishu.topicsHint": "管理此机器人的群绑定。在会话菜单中选择「IM 同步设置」,可创建新的绑定。",
649
+ "feishu.session": "会话",
650
+ "feishu.topic.active": "同步中",
651
+ "feishu.topic.paused": "已暂停",
652
+ "feishu.topic.broken": "已失效",
653
+ "feishu.unbindTitle": "解除群绑定?",
654
+ "feishu.unbindBody": "解除后停止同步此会话,飞书中的历史消息会保留。",
655
+ "feishu.setup.title": "机器人配置指南",
656
+ "feishu.setup.intro": "按以下步骤完成飞书后台配置,再配对所有者并绑定会话。",
657
+ "feishu.setup.console": "打开飞书开发者后台",
658
+ "feishu.setup.createTitle": "1. 创建应用并启用机器人",
659
+ "feishu.setup.create": "创建企业自建应用,在「添加应用能力」中添加「机器人」。在「基础信息 › 凭证与基础信息」找到 App ID 和 App Secret。",
660
+ "feishu.setup.permissionsTitle": "2. 导入应用权限",
661
+ "feishu.setup.permissions": "进入「开发配置 › 权限管理 › 批量导入/导出权限」,粘贴下方 JSON,确认导入并申请开通权限。",
662
+ "feishu.setup.scopeNote": "这些权限用于消息收发、普通群及成员管理、卡片更新和成员姓名读取。群消息权限让机器人收到所在群内无需 @ 的消息;通讯录数据权限范围需覆盖参与成员。",
663
+ "feishu.setup.copy": "复制权限 JSON",
664
+ "feishu.setup.copied": "已复制",
665
+ "feishu.setup.copyFailed": "复制失败,请手动选择并复制下方 JSON。",
666
+ "feishu.setup.connectTitle": "3. 保存凭证并建立连接",
667
+ "feishu.setup.connect": "在「应用凭证」中填入 App ID 和 App Secret,开启「启用」并保存。保持瑶光网关运行;若飞书提示「应用未建立长连接」,先检查凭证与连接状态,再保存订阅方式。",
668
+ "feishu.setup.eventsTitle": "4. 配置事件订阅",
669
+ "feishu.setup.events": "进入「开发配置 › 事件与回调 › 事件配置」,选择「使用长连接接收事件」并保存,再添加下列事件。无需填写公网回调地址。",
670
+ "feishu.setup.callbackTitle": "5. 配置卡片交互回调",
671
+ "feishu.setup.callback": "切换到「回调配置」,同样选择长连接并保存,在「添加回调」中选择「卡片回传交互」。这用于接收审批按钮和表单提交:",
672
+ "feishu.setup.publishTitle": "6. 发布并配对",
673
+ "feishu.setup.publish": "进入「应用发布 › 版本管理与发布」,创建版本并发布,按租户要求完成管理员审核;应用可用范围需包含所有者和参与成员。回到瑶光,机器人在线后进入「管理配置」,点击「配对所有者」,在飞书私聊机器人发送配对码,再从会话菜单绑定飞书。以后修改权限或订阅后,也要重新发布。",
674
+ "feishu.title": "飞书",
675
+ "feishu.connection": "应用凭证",
676
+ "feishu.channelSummary": "{{count}} 个会话",
677
+ "feishu.groupsEmpty": "还没有绑定的群",
678
+ "feishu.discardChanges": "放弃未保存的修改?",
679
+ "feishu.keepEditing": "继续编辑",
680
+ "feishu.discard": "放弃修改",
681
+ "feishu.unknownError": "操作失败,请重试",
682
+ "feishu.hint": "把会话绑定到飞书话题:回复以卡片出现,群成员在话题里说话、审批。每个机器人需要先配对所有者。",
683
+ "feishu.bots": "机器人",
684
+ "feishu.add": "添加机器人",
685
+ "feishu.emptyTitle": "还没有飞书机器人",
686
+ "feishu.emptyBody": "在飞书开发者后台创建自建应用、开启机器人能力与长连接事件订阅,再把 AppID 与 AppSecret 填到这里。",
687
+ "feishu.loading": "正在加载…",
688
+ "feishu.saving": "正在保存…",
689
+ "feishu.retry": "重试",
690
+ "feishu.state.off": "未连接",
691
+ "feishu.state.connecting": "连接中",
692
+ "feishu.state.online": "在线",
693
+ "feishu.state.reconnecting": "重连中",
694
+ "feishu.state.failed": "失败",
695
+ "feishu.owner": "所有者",
696
+ "feishu.ownerNone": "未配对",
697
+ "feishu.ownerUnnamed": "已配对",
698
+ "feishu.bindings": "{{count}} 个会话已绑定",
699
+ "feishu.edit": "编辑",
700
+ "feishu.remove": "删除",
701
+ "feishu.removeTitle": "删除机器人“{{name}}”?",
702
+ "feishu.removeBody": "它的所有绑定会一起解除,飞书里的群保留。",
703
+ "feishu.enable": "启用 {{name}}",
704
+ "feishu.turnOn": "开启",
705
+ "feishu.turnOff": "关闭",
706
+ "feishu.test": "测试连接",
707
+ "feishu.testOk": "连接正常",
708
+ "feishu.pair": "配对所有者",
709
+ "feishu.pairTitle": "配对所有者",
710
+ "feishu.pairBody": "在飞书里找到这个机器人,单聊发送下面的配对码。5 分钟内有效。",
711
+ "feishu.pairReplace": "配对后将更换所有者,原所有者留在各群里。",
712
+ "feishu.pairDone": "配对成功:{{name}} 已是所有者",
713
+ "feishu.missing": "最近的调用缺少权限:{{scopes}}。请在开发者后台开通后重新发布应用。",
714
+ "feishu.groups": "群管理",
715
+ "feishu.groupMembers": "{{count}} 位成员",
716
+ "feishu.groupBroken": "已失效",
717
+ "feishu.members": "成员名单",
718
+ "feishu.membersHint": "名单与飞书群成员同步。Accept:消息直接进入会话,可回答请求与使用命令;Ask:每条消息先经 Accept 成员放行;Reject:消息被忽略。",
719
+ "feishu.membersEmpty": "群里还没有其他人",
720
+ "feishu.policy": "{{name}} 的权限",
721
+ "feishu.memberRemove": "移出群",
722
+ "feishu.memberRemoveTitle": "把 {{name}} 移出飞书群?",
723
+ "feishu.memberRemoveBody": "他会从飞书群里被移出,也从名单上删除。",
724
+ "feishu.editorTitle": "飞书机器人",
725
+ "feishu.name": "名称",
726
+ "feishu.appId": "AppID",
727
+ "feishu.appSecret": "AppSecret",
728
+ "feishu.enabled": "启用",
729
+ "feishu.save": "保存",
730
+ "feishu.cancel": "取消",
731
+ "feishu.menu": "飞书",
732
+ "feishu.menu.none": "未绑定",
733
+ "feishu.menu.paused": "已暂停",
734
+ "feishu.menu.broken": "已失效",
735
+ "feishu.bindTitle": "绑定到飞书",
736
+ "feishu.bindPick": "机器人",
737
+ "feishu.bindNoBots": "还没有可用的机器人。先在设置 › IM 通道里添加飞书机器人并配对所有者。",
738
+ "feishu.bindUnpaired": "{{name}}(未配对)",
739
+ "feishu.bindExposure": "绑定后,这个会话的回复、思考摘要、工具调用摘要与请求会发送到飞书租户,群里的成员都能看到。",
740
+ "feishu.bind": "绑定",
741
+ "feishu.binding": "正在绑定…",
742
+ "feishu.bound": "已绑定到“{{bot}}”的普通群“{{chat}}”",
743
+ "feishu.state.active": "同步中",
744
+ "feishu.state.paused": "已暂停(会话已归档)",
745
+ "feishu.state.broken": "已失效:{{reason}}",
746
+ "feishu.openTopic": "在飞书打开",
747
+ "feishu.rebind": "换绑",
748
+ "feishu.unbind": "解绑",
749
+ "feishu.close": "关闭"
750
+ },
751
+ "en-US": {
752
+ "feishu.disabled": "Disabled",
753
+ "feishu.ownerUnpaired": "Owner not paired",
754
+ "feishu.bindingDetails": "Binding details",
755
+ "feishu.groupId": "Group ID",
756
+ "feishu.changeChannel": "Change IM channel",
757
+ "feishu.createBind": "Create group and bind",
758
+ "feishu.createHint": "Create a Feishu group for this session and invite the bot owner.",
759
+ "feishu.replaceHint": "Confirmation removes the current binding, then creates a new Feishu group. The old group and its messages remain.",
760
+ "feishu.replaceCreate": "Replace and create group",
761
+ "feishu.replaceFailed": "The previous binding was removed. The new group has not been bound.",
762
+ "feishu.botNotReady": "Enable this bot and pair its owner in IM channel settings.",
763
+ "feishu.recoveryChat": "Verified ID of the group already created",
764
+ "feishu.defaultsHint": "When the bot joins an existing group, new work sessions use these defaults. Changes affect future sessions only.",
765
+ "feishu.defaultAgent": "Default agent",
766
+ "feishu.defaultWorkspace": "Default workspace",
767
+ "feishu.unconfigured": "Not configured",
768
+ "feishu.unavailable": "Unavailable",
769
+ "feishu.saved": "Saved",
770
+ "feishu.sessionMembers": "Member management",
771
+ "feishu.memberScope": "Permissions apply only to this session. New members require confirmation by default.",
772
+ "feishu.exposureTitle": "Everyone in the group can read synchronized content.",
773
+ "feishu.exposureDetails": "This includes replies, reasoning summaries, tool-call summaries and interaction requests. Permissions control speaking and actions only.",
774
+ "feishu.noMembers": "No confirmed group members",
775
+ "feishu.permission": "Permission",
776
+ "feishu.allow": "Allow",
777
+ "feishu.ask": "Ask",
778
+ "feishu.reject": "Reject",
779
+ "feishu.refresh": "Refresh",
780
+ "feishu.openSession": "Open session",
781
+ "feishu.pendingGroups": "Pending groups",
782
+ "feishu.ownerPaired": "Paired",
783
+ "feishu.pairWaiting": "Waiting for pairing",
784
+ "feishu.pairStarting": "Getting code…",
785
+ "feishu.pairAgain": "Get a new code",
786
+ "feishu.pairCopy": "Copy code",
787
+ "feishu.pairCopyFailed": "Copy failed. Select and copy the code manually.",
788
+ "feishu.pairRemaining": "Expires in {{time}}",
789
+ "feishu.pairExpired": "This code has expired. Get a new code to continue.",
790
+ "feishu.management": "Management",
791
+ "feishu.authorization": "Authorization",
792
+ "feishu.managementHint": "Pair an owner to bind YaoGuang sessions to this bot.",
793
+ "feishu.pairOffline": "Enable the bot in App credentials and wait until it is online before pairing.",
794
+ "feishu.topicsHint": "Manage this bot’s topic bindings. Choose Feishu in a session menu to create a binding.",
795
+ "feishu.session": "Session",
796
+ "feishu.topic.active": "Syncing",
797
+ "feishu.topic.paused": "Paused",
798
+ "feishu.topic.broken": "Unavailable",
799
+ "feishu.unbindTitle": "Unbind this topic?",
800
+ "feishu.unbindBody": "This stops synchronization for the session. Existing messages in Feishu are kept.",
801
+ "feishu.setup.title": "Bot setup guide",
802
+ "feishu.setup.intro": "Configure the Feishu app, then pair its owner and bind a session.",
803
+ "feishu.setup.console": "Open Feishu developer console",
804
+ "feishu.setup.createTitle": "1. Create an app and enable the bot",
805
+ "feishu.setup.create": "Create an enterprise custom app and add the Bot capability under Add features. Find App ID and App Secret under Basic information › Credentials & basic info.",
806
+ "feishu.setup.permissionsTitle": "2. Import app permissions",
807
+ "feishu.setup.permissions": "Open Development configuration › Permissions › Batch import/export permissions. Paste the JSON below, confirm the import, and request the permissions.",
808
+ "feishu.setup.scopeNote": "These scopes cover messages, ordinary groups and members, card updates, and member names. Group message access receives messages without an @ mention in groups containing the bot. Include participating members in the contact data access range.",
809
+ "feishu.setup.copy": "Copy permissions JSON",
810
+ "feishu.setup.copied": "Copied",
811
+ "feishu.setup.copyFailed": "Copy failed. Select and copy the JSON below manually.",
812
+ "feishu.setup.connectTitle": "3. Save credentials and connect",
813
+ "feishu.setup.connect": "Enter App ID and App Secret in App credentials, turn on Enabled, and save. Keep the gateway running. If Feishu reports that no long connection exists, check the credentials and connection before saving the subscription mode.",
814
+ "feishu.setup.eventsTitle": "4. Subscribe to events",
815
+ "feishu.setup.events": "Open Development configuration › Events & callbacks › Event configuration. Select long connection mode, save, and add the events below. No public callback URL is needed.",
816
+ "feishu.setup.callbackTitle": "5. Subscribe to card interactions",
817
+ "feishu.setup.callback": "Switch to Callback configuration, select long connection mode, and save. Under Add callbacks, select Card action trigger to receive approval buttons and form submissions:",
818
+ "feishu.setup.publishTitle": "6. Publish and pair",
819
+ "feishu.setup.publish": "Open App release › Version management & release, create a version, and publish it with administrator approval where required. Include the owner and participating members in app availability. Once the bot is online in YaoGuang, open Management, click Pair owner, and send the code in a direct message to the bot. Then bind Feishu from the session menu. Publish again after changing permissions or subscriptions.",
820
+ "feishu.title": "Feishu",
821
+ "feishu.connection": "App credentials",
822
+ "feishu.channelSummary": "{{count}} sessions",
823
+ "feishu.groupsEmpty": "No ordinary groups yet",
824
+ "feishu.discardChanges": "Discard unsaved changes?",
825
+ "feishu.keepEditing": "Keep editing",
826
+ "feishu.discard": "Discard changes",
827
+ "feishu.unknownError": "Something went wrong. Try again.",
828
+ "feishu.hint": "Bind sessions to Feishu topics: replies appear as cards, and group members talk and approve in the topic. Pair each bot with its owner first.",
829
+ "feishu.bots": "Bots",
830
+ "feishu.add": "Add bot",
831
+ "feishu.emptyTitle": "No Feishu bot yet",
832
+ "feishu.emptyBody": "Create a custom app in the Feishu developer console, turn on the bot and long-connection events, then enter its App ID and App Secret here.",
833
+ "feishu.loading": "Loading…",
834
+ "feishu.saving": "Saving…",
835
+ "feishu.retry": "Retry",
836
+ "feishu.state.off": "Off",
837
+ "feishu.state.connecting": "Connecting",
838
+ "feishu.state.online": "Online",
839
+ "feishu.state.reconnecting": "Reconnecting",
840
+ "feishu.state.failed": "Failed",
841
+ "feishu.owner": "Owner",
842
+ "feishu.ownerNone": "Not paired",
843
+ "feishu.ownerUnnamed": "Paired",
844
+ "feishu.bindings": "{{count}} sessions bound",
845
+ "feishu.edit": "Edit",
846
+ "feishu.remove": "Delete",
847
+ "feishu.removeTitle": "Delete bot “{{name}}”?",
848
+ "feishu.removeBody": "All its bindings end with it; the groups stay in Feishu.",
849
+ "feishu.enable": "Enable {{name}}",
850
+ "feishu.turnOn": "Turn on",
851
+ "feishu.turnOff": "Turn off",
852
+ "feishu.test": "Test connection",
853
+ "feishu.testOk": "Connected",
854
+ "feishu.pair": "Pair owner",
855
+ "feishu.pairTitle": "Pair owner",
856
+ "feishu.pairBody": "Find this bot in Feishu and send it the code below in a direct chat. It is good for 5 minutes.",
857
+ "feishu.pairReplace": "Pairing replaces the owner; the old owner stays in the groups.",
858
+ "feishu.pairDone": "Paired: {{name}} is the owner",
859
+ "feishu.missing": "Recent calls lacked scopes: {{scopes}}. Turn them on in the developer console and publish the app again.",
860
+ "feishu.groups": "Groups",
861
+ "feishu.groupMembers": "{{count}} members",
862
+ "feishu.groupBroken": "Gone",
863
+ "feishu.members": "Members",
864
+ "feishu.membersHint": "The list follows the Feishu group. Accept: messages go straight in, and they may answer requests and use commands. Ask: every message waits for an Accept member to let it in. Reject: messages are ignored.",
865
+ "feishu.membersEmpty": "Nobody else is in the group yet",
866
+ "feishu.policy": "Permission of {{name}}",
867
+ "feishu.memberRemove": "Remove from group",
868
+ "feishu.memberRemoveTitle": "Remove {{name}} from the Feishu group?",
869
+ "feishu.memberRemoveBody": "They are taken out of the Feishu group and off the list.",
870
+ "feishu.editorTitle": "Feishu bot",
871
+ "feishu.name": "Name",
872
+ "feishu.appId": "App ID",
873
+ "feishu.appSecret": "App Secret",
874
+ "feishu.enabled": "Enabled",
875
+ "feishu.save": "Save",
876
+ "feishu.cancel": "Cancel",
877
+ "feishu.menu": "Feishu",
878
+ "feishu.menu.none": "Not bound",
879
+ "feishu.menu.paused": "Paused",
880
+ "feishu.menu.broken": "Broken",
881
+ "feishu.bindTitle": "Bind to Feishu",
882
+ "feishu.bindPick": "Bot",
883
+ "feishu.bindNoBots": "No bot is ready. Add a Feishu bot in Settings › IM channels and pair its owner first.",
884
+ "feishu.bindUnpaired": "{{name}} (not paired)",
885
+ "feishu.bindExposure": "Once bound, this session’s replies, thinking and tool summaries and requests are sent to the Feishu tenant, where everyone in the group can see them.",
886
+ "feishu.bind": "Bind",
887
+ "feishu.binding": "Binding…",
888
+ "feishu.bound": "Bound to “{{chat}}” of “{{bot}}”",
889
+ "feishu.state.active": "Syncing",
890
+ "feishu.state.paused": "Paused (session archived)",
891
+ "feishu.state.broken": "Broken: {{reason}}",
892
+ "feishu.openTopic": "Open in Feishu",
893
+ "feishu.rebind": "Move",
894
+ "feishu.unbind": "Unbind",
895
+ "feishu.close": "Close"
896
+ }
897
+ };
898
+ /** A catalogue string with `{{name}}` placeholders filled. */
899
+ function fill(text, values) {
900
+ return text.replace(/\{\{(\w+)\}\}/g, (_, key) => String(values[key] ?? ""));
901
+ }
902
+ //#endregion
903
+ //#region src/ui/channel.ts
904
+ function asInstance(ctx, bot) {
905
+ return {
906
+ id: bot.id,
907
+ name: bot.name,
908
+ summary: fill(ctx.i18n.t("feishu.channelSummary"), { count: bot.bindings }),
909
+ state: bot.status === "reconnecting" ? "connecting" : bot.status,
910
+ reason: bot.status === "failed" ? bot.reason ?? void 0 : void 0,
911
+ counts: { groups: bot.bindings },
912
+ bindingUnavailable: !bot.enabled ? ctx.i18n.t("feishu.disabled") : bot.owner === null ? ctx.i18n.t("feishu.ownerUnpaired") : void 0
913
+ };
914
+ }
915
+ /** Creates the Feishu channel's host operations without storing bot state. */
916
+ function channelOperations(ctx) {
917
+ return {
918
+ async list() {
919
+ return (await ctx.invoke(METHOD.listBots, {})).map((bot) => asInstance(ctx, bot));
920
+ },
921
+ watch(onChange) {
922
+ return ctx.on(FRAME.botsChanged, onChange);
923
+ },
924
+ async remove(id) {
925
+ await ctx.invoke(METHOD.removeBot, { id });
926
+ },
927
+ async test(id) {
928
+ await ctx.invoke(METHOD.testBot, { id });
929
+ }
930
+ };
931
+ }
932
+ //#endregion
933
+ //#region src/ui/connection-tab.tsx
934
+ /** Builds the connection tab for one stored Feishu bot. */
935
+ function connectionTabFor(ctx) {
936
+ const t = ctx.i18n.t;
937
+ const { AlertDialog, Button, Field, Input, SecretInput, Switch } = ctx.ui;
938
+ return function ConnectionTab({ instanceId, onLeaveGuard }) {
939
+ const [bot, setBot] = useState(null);
940
+ const [loadError, setLoadError] = useState(null);
941
+ const [name, setName] = useState("");
942
+ const [appId, setAppId] = useState("");
943
+ const [secret, setSecret] = useState("");
944
+ const [enabled, setEnabled] = useState(true);
945
+ const [error, setError] = useState(null);
946
+ const [busy, setBusy] = useState(false);
947
+ const [leavePrompt, setLeavePrompt] = useState(false);
948
+ const busyRef = useRef(false);
949
+ const dirtyRef = useRef(false);
950
+ const leaveResolve = useRef(null);
951
+ const fail = useFailureToast(ctx);
952
+ const load = useMemo(() => coalesceReads(async () => {
953
+ setLoadError(null);
954
+ try {
955
+ const next = (await ctx.invoke(METHOD.listBots, {})).find((one) => one.id === instanceId) ?? null;
956
+ setBot(next);
957
+ if (next !== null && !dirtyRef.current) {
958
+ setName(next.name);
959
+ setAppId(next.appId);
960
+ setEnabled(next.enabled);
961
+ }
962
+ } catch (failure) {
963
+ setLoadError(failureText(ctx, failure));
964
+ fail(failure);
965
+ }
966
+ }), [instanceId, fail]);
967
+ useGatewayRefresh(ctx, load);
968
+ useEffect(() => {
969
+ load();
970
+ return ctx.on(FRAME.botsChanged, () => void load());
971
+ }, [load]);
972
+ useEffect(() => {
973
+ onLeaveGuard?.(() => {
974
+ if (busyRef.current || leaveResolve.current) return Promise.resolve(false);
975
+ if (!dirtyRef.current) return Promise.resolve(true);
976
+ setLeavePrompt(true);
977
+ return new Promise((resolve) => {
978
+ leaveResolve.current = resolve;
979
+ });
980
+ });
981
+ return () => {
982
+ onLeaveGuard?.(null);
983
+ leaveResolve.current?.(false);
984
+ leaveResolve.current = null;
985
+ };
986
+ }, [onLeaveGuard]);
987
+ function resolveLeave(answer) {
988
+ setLeavePrompt(false);
989
+ const resolve = leaveResolve.current;
990
+ leaveResolve.current = null;
991
+ resolve?.(answer);
992
+ }
993
+ async function save() {
994
+ if (!bot || busyRef.current) return;
995
+ busyRef.current = true;
996
+ setBusy(true);
997
+ setError(null);
998
+ try {
999
+ const saved = await ctx.invoke(METHOD.saveBot, {
1000
+ id: bot.id,
1001
+ name,
1002
+ appId,
1003
+ enabled
1004
+ });
1005
+ if (secret.trim() !== "") await ctx.credentials.set(saved.id, APP_SECRET, secret);
1006
+ dirtyRef.current = false;
1007
+ setSecret("");
1008
+ setBot(saved);
1009
+ } catch (failure) {
1010
+ setError(failureText(ctx, failure));
1011
+ } finally {
1012
+ busyRef.current = false;
1013
+ setBusy(false);
1014
+ }
1015
+ }
1016
+ if (!bot) return loadError ? /* @__PURE__ */ jsxs("div", {
1017
+ className: "feishu-form",
1018
+ children: [/* @__PURE__ */ jsx("p", {
1019
+ role: "alert",
1020
+ children: loadError
1021
+ }), /* @__PURE__ */ jsx(Button, {
1022
+ onClick: () => void load(),
1023
+ children: t("feishu.retry")
1024
+ })]
1025
+ }) : /* @__PURE__ */ jsx("p", {
1026
+ role: "status",
1027
+ className: "feishu-muted",
1028
+ children: t("feishu.loading")
1029
+ });
1030
+ return /* @__PURE__ */ jsxs("div", {
1031
+ className: "feishu-form feishu-tab",
1032
+ children: [
1033
+ /* @__PURE__ */ jsx(Field, {
1034
+ className: "settings-field-row",
1035
+ label: t("feishu.enabled"),
1036
+ inline: true,
1037
+ children: () => /* @__PURE__ */ jsx(Switch, {
1038
+ checked: enabled,
1039
+ disabled: busy,
1040
+ onCheckedChange: (value) => {
1041
+ dirtyRef.current = true;
1042
+ setEnabled(value);
1043
+ },
1044
+ "aria-label": t("feishu.enabled")
1045
+ })
1046
+ }),
1047
+ /* @__PURE__ */ jsx(Field, {
1048
+ className: "settings-field-row",
1049
+ label: t("feishu.name"),
1050
+ required: true,
1051
+ inline: true,
1052
+ children: (field) => /* @__PURE__ */ jsx(Input, {
1053
+ ...field,
1054
+ value: name,
1055
+ maxLength: 40,
1056
+ disabled: busy,
1057
+ onChange: (event) => {
1058
+ dirtyRef.current = true;
1059
+ setName(event.target.value);
1060
+ }
1061
+ })
1062
+ }),
1063
+ /* @__PURE__ */ jsx(Field, {
1064
+ className: "settings-field-row",
1065
+ label: t("feishu.appId"),
1066
+ required: true,
1067
+ inline: true,
1068
+ children: (field) => /* @__PURE__ */ jsx(Input, {
1069
+ ...field,
1070
+ value: appId,
1071
+ disabled: busy,
1072
+ onChange: (event) => {
1073
+ dirtyRef.current = true;
1074
+ setAppId(event.target.value);
1075
+ }
1076
+ })
1077
+ }),
1078
+ /* @__PURE__ */ jsx(Field, {
1079
+ className: "settings-field-row",
1080
+ label: t("feishu.appSecret"),
1081
+ inline: true,
1082
+ children: (field) => /* @__PURE__ */ jsx(SecretInput, {
1083
+ ...field,
1084
+ label: t("feishu.appSecret"),
1085
+ value: secret,
1086
+ disabled: busy,
1087
+ stored: bot.secret.set,
1088
+ ...bot.secret.hint ? { hint: bot.secret.hint } : {},
1089
+ onValueChange: (value) => {
1090
+ dirtyRef.current = true;
1091
+ setSecret(value);
1092
+ }
1093
+ })
1094
+ }),
1095
+ bot.missingScopes.length === 0 ? null : /* @__PURE__ */ jsx("p", {
1096
+ className: "feishu-error",
1097
+ children: fill(t("feishu.missing"), { scopes: bot.missingScopes.join("、") })
1098
+ }),
1099
+ error === null ? null : /* @__PURE__ */ jsx("p", {
1100
+ className: "feishu-error",
1101
+ children: error
1102
+ }),
1103
+ /* @__PURE__ */ jsx("div", {
1104
+ className: "feishu-actions",
1105
+ children: /* @__PURE__ */ jsx(Button, {
1106
+ variant: "primary",
1107
+ disabled: busy || name.trim() === "" || appId.trim() === "",
1108
+ onClick: () => void save(),
1109
+ children: t("feishu.save")
1110
+ })
1111
+ }),
1112
+ /* @__PURE__ */ jsx(AlertDialog, {
1113
+ open: leavePrompt,
1114
+ onOpenChange: (open) => !open && resolveLeave(false),
1115
+ title: t("feishu.discardChanges"),
1116
+ actions: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
1117
+ variant: "ghost",
1118
+ onClick: () => resolveLeave(false),
1119
+ children: t("feishu.keepEditing")
1120
+ }), /* @__PURE__ */ jsx(Button, {
1121
+ variant: "destructive",
1122
+ onClick: () => resolveLeave(true),
1123
+ children: t("feishu.discard")
1124
+ })] }),
1125
+ children: /* @__PURE__ */ jsx("p", { children: t("feishu.discardChanges") })
1126
+ })
1127
+ ]
1128
+ });
1129
+ };
1130
+ }
1131
+ //#endregion
1132
+ //#region src/ui/groups-tab.tsx
1133
+ /** Lists the bot's bound groups and confirms each request to stop synchronization. */
1134
+ function groupsTabFor(ctx) {
1135
+ const t = ctx.i18n.t;
1136
+ const { AlertDialog, Button, Tooltip } = ctx.ui;
1137
+ return function GroupsTab({ instanceId }) {
1138
+ const [pending, setPending] = useState([]);
1139
+ const [recoverChat, setRecoverChat] = useState({});
1140
+ const [bindings, setBindings] = useState(null);
1141
+ const [removing, setRemoving] = useState(null);
1142
+ const [busy, setBusy] = useState(false);
1143
+ const running = useRef(false);
1144
+ const [error, setError] = useState(null);
1145
+ const load = useMemo(() => coalesceReads(async () => {
1146
+ try {
1147
+ const [all, bots] = await Promise.all([ctx.invoke(METHOD.listBindings, {}), ctx.invoke(METHOD.listBots, {})]);
1148
+ setPending(bots.find((one) => one.id === instanceId)?.pending ?? []);
1149
+ setBindings(all.filter((one) => one.botId === instanceId));
1150
+ setError(null);
1151
+ } catch (failure) {
1152
+ setError(failureText(ctx, failure));
1153
+ }
1154
+ }), [instanceId]);
1155
+ useGatewayRefresh(ctx, load);
1156
+ useEffect(() => {
1157
+ load();
1158
+ const offBinding = ctx.on(FRAME.bindingChanged, () => void load());
1159
+ const offBots = ctx.on(FRAME.botsChanged, () => void load());
1160
+ return () => {
1161
+ offBinding();
1162
+ offBots();
1163
+ };
1164
+ }, [load]);
1165
+ async function retry(item) {
1166
+ if (running.current) return;
1167
+ running.current = true;
1168
+ setBusy(true);
1169
+ setError(null);
1170
+ try {
1171
+ if (item.key.startsWith("outgoing:")) {
1172
+ if (item.chatId === null) await ctx.invoke(METHOD.recoverGroup, {
1173
+ botId: instanceId,
1174
+ sessionId: item.sessionId,
1175
+ chatId: recoverChat[item.key] ?? ""
1176
+ });
1177
+ else await ctx.invoke(METHOD.bind, {
1178
+ botId: instanceId,
1179
+ sessionId: item.sessionId
1180
+ });
1181
+ } else await ctx.invoke(METHOD.retryGroup, {
1182
+ botId: instanceId,
1183
+ chatId: item.chatId
1184
+ });
1185
+ await load();
1186
+ } catch (failure) {
1187
+ setError(failureText(ctx, failure));
1188
+ } finally {
1189
+ running.current = false;
1190
+ setBusy(false);
1191
+ }
1192
+ }
1193
+ async function unbind() {
1194
+ if (!removing || running.current) return;
1195
+ running.current = true;
1196
+ setBusy(true);
1197
+ setError(null);
1198
+ try {
1199
+ await ctx.invoke(METHOD.unbind, { sessionId: removing.sessionId });
1200
+ setRemoving(null);
1201
+ await load();
1202
+ } catch (failure) {
1203
+ setError(failureText(ctx, failure));
1204
+ } finally {
1205
+ running.current = false;
1206
+ setBusy(false);
1207
+ }
1208
+ }
1209
+ return /* @__PURE__ */ jsxs("div", {
1210
+ className: "feishu-form feishu-tab",
1211
+ children: [
1212
+ /* @__PURE__ */ jsx("p", {
1213
+ className: "feishu-muted",
1214
+ children: t("feishu.topicsHint")
1215
+ }),
1216
+ error && /* @__PURE__ */ jsx("p", {
1217
+ className: "feishu-error",
1218
+ role: "alert",
1219
+ children: error
1220
+ }),
1221
+ bindings === null && !error ? /* @__PURE__ */ jsx("p", {
1222
+ className: "feishu-muted",
1223
+ children: t("feishu.loading")
1224
+ }) : bindings?.length === 0 ? /* @__PURE__ */ jsx("p", {
1225
+ className: "feishu-muted",
1226
+ children: t("feishu.groupsEmpty")
1227
+ }) : /* @__PURE__ */ jsx("ul", {
1228
+ className: "feishu-topics",
1229
+ children: bindings?.map((binding) => /* @__PURE__ */ jsx("li", {
1230
+ className: "feishu-topic",
1231
+ children: /* @__PURE__ */ jsxs("div", {
1232
+ className: "feishu-topic-heading",
1233
+ children: [
1234
+ /* @__PURE__ */ jsx(Tooltip, {
1235
+ content: t(`feishu.topic.${binding.state}`),
1236
+ children: /* @__PURE__ */ jsx("span", {
1237
+ className: "feishu-group-status",
1238
+ "data-state": binding.state,
1239
+ role: "img",
1240
+ "aria-label": t(`feishu.topic.${binding.state}`),
1241
+ children: /* @__PURE__ */ jsxs("svg", {
1242
+ viewBox: "0 0 24 24",
1243
+ fill: "none",
1244
+ stroke: "currentColor",
1245
+ strokeWidth: "1.75",
1246
+ strokeLinecap: "round",
1247
+ strokeLinejoin: "round",
1248
+ "aria-hidden": "true",
1249
+ children: [/* @__PURE__ */ jsx("path", { d: "M20 16.2A4.5 4.5 0 0 0 18 7.5h-1.3A7 7 0 1 0 4 16.25" }), binding.state === "active" ? /* @__PURE__ */ jsx("path", { d: "m9 18 2 2 4-4" }) : binding.state === "broken" ? /* @__PURE__ */ jsx("path", { d: "M12 13v4m0 3h.01" }) : /* @__PURE__ */ jsx("path", { d: "M10 14v6m4-6v6" })]
1250
+ })
1251
+ })
1252
+ }),
1253
+ /* @__PURE__ */ jsxs("div", {
1254
+ className: "feishu-grow",
1255
+ children: [
1256
+ /* @__PURE__ */ jsx("strong", { children: binding.chatName }),
1257
+ /* @__PURE__ */ jsxs("small", {
1258
+ className: "feishu-muted",
1259
+ children: [
1260
+ t("feishu.session"),
1261
+ " · ",
1262
+ binding.sessionId,
1263
+ " · ",
1264
+ binding.chatId
1265
+ ]
1266
+ }),
1267
+ binding.reason && /* @__PURE__ */ jsx("p", {
1268
+ className: "feishu-error",
1269
+ children: binding.reason
1270
+ })
1271
+ ]
1272
+ }),
1273
+ /* @__PURE__ */ jsx(Button, {
1274
+ className: "feishu-group-unbind",
1275
+ variant: "ghost",
1276
+ size: "sm",
1277
+ title: t("feishu.unbind"),
1278
+ "aria-label": t("feishu.unbind"),
1279
+ disabled: busy,
1280
+ loading: busy,
1281
+ onClick: () => setRemoving(binding),
1282
+ children: /* @__PURE__ */ jsx("svg", {
1283
+ viewBox: "0 0 24 24",
1284
+ fill: "none",
1285
+ stroke: "currentColor",
1286
+ strokeWidth: "1.75",
1287
+ strokeLinecap: "round",
1288
+ strokeLinejoin: "round",
1289
+ "aria-hidden": "true",
1290
+ children: /* @__PURE__ */ jsx("path", { d: "m18.84 12.25 1.41-1.41a5 5 0 0 0-7.07-7.07l-1.41 1.41M5.16 11.75l-1.41 1.41a5 5 0 0 0 7.07 7.07l1.41-1.41M8 2v3M2 8h3m11 13v-3m6-2h-3" })
1291
+ })
1292
+ })
1293
+ ]
1294
+ })
1295
+ }, binding.sessionId))
1296
+ }),
1297
+ pending.length > 0 && /* @__PURE__ */ jsxs("section", {
1298
+ className: "feishu-form",
1299
+ children: [/* @__PURE__ */ jsx("strong", { children: t("feishu.pendingGroups") }), pending.map((item) => /* @__PURE__ */ jsxs("div", {
1300
+ className: "feishu-topic",
1301
+ children: [
1302
+ /* @__PURE__ */ jsx("p", {
1303
+ className: "feishu-error",
1304
+ children: item.error
1305
+ }),
1306
+ /* @__PURE__ */ jsx("small", {
1307
+ className: "feishu-muted",
1308
+ children: item.chatId ?? item.sessionId
1309
+ }),
1310
+ item.chatId === null && /* @__PURE__ */ jsx(ctx.ui.Input, {
1311
+ "aria-label": t("feishu.recoveryChat"),
1312
+ placeholder: "oc_…",
1313
+ value: recoverChat[item.key] ?? "",
1314
+ onChange: (event) => setRecoverChat((current) => ({
1315
+ ...current,
1316
+ [item.key]: event.target.value
1317
+ }))
1318
+ }),
1319
+ /* @__PURE__ */ jsx(Button, {
1320
+ variant: "outline",
1321
+ size: "sm",
1322
+ disabled: busy || item.chatId === null && !recoverChat[item.key]?.trim(),
1323
+ onClick: () => void retry(item),
1324
+ children: t("feishu.retry")
1325
+ })
1326
+ ]
1327
+ }, item.key))]
1328
+ }),
1329
+ /* @__PURE__ */ jsxs(AlertDialog, {
1330
+ open: removing !== null,
1331
+ onOpenChange: (open) => {
1332
+ if (!open && !busy) setRemoving(null);
1333
+ },
1334
+ title: t("feishu.unbindTitle"),
1335
+ actions: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
1336
+ variant: "ghost",
1337
+ disabled: busy,
1338
+ loading: busy,
1339
+ onClick: () => setRemoving(null),
1340
+ children: t("feishu.cancel")
1341
+ }), /* @__PURE__ */ jsx(Button, {
1342
+ variant: "destructive",
1343
+ disabled: busy,
1344
+ loading: busy,
1345
+ onClick: () => void unbind(),
1346
+ children: t("feishu.unbind")
1347
+ })] }),
1348
+ children: [/* @__PURE__ */ jsx("p", { children: t("feishu.unbindBody") }), error && /* @__PURE__ */ jsx("p", {
1349
+ className: "feishu-error",
1350
+ role: "alert",
1351
+ children: error
1352
+ })]
1353
+ })
1354
+ ]
1355
+ });
1356
+ };
1357
+ }
1358
+ //#endregion
1359
+ //#region src/ui/defaults.tsx
1360
+ /** Builds the default agent and workspace editor. */
1361
+ function defaultsFor(ctx) {
1362
+ const { Avatar, Field, Select } = ctx.ui;
1363
+ const t = ctx.i18n.t;
1364
+ return function Defaults({ bot }) {
1365
+ const connection = useSyncExternalStore(ctx.host.subscribe, () => ctx.host.get().connection);
1366
+ const [choices, setChoices] = useState({
1367
+ agents: [],
1368
+ workspaces: []
1369
+ });
1370
+ const [pictures, setPictures] = useState({});
1371
+ const [agent, setAgent] = useState(bot.defaultAgentId ?? "");
1372
+ const [workspace, setWorkspace] = useState(bot.defaultWorkspaceId ?? "");
1373
+ const [busy, setBusy] = useState(null);
1374
+ const [loading, setLoading] = useState(true);
1375
+ const [loaded, setLoaded] = useState(false);
1376
+ const [error, setError] = useState(null);
1377
+ const saving = useRef(false);
1378
+ useEffect(() => {
1379
+ setAgent(bot.defaultAgentId ?? "");
1380
+ setWorkspace(bot.defaultWorkspaceId ?? "");
1381
+ }, [
1382
+ bot.id,
1383
+ bot.defaultAgentId,
1384
+ bot.defaultWorkspaceId
1385
+ ]);
1386
+ useEffect(() => {
1387
+ let active = true;
1388
+ if (connection !== "online") return;
1389
+ setLoading(true);
1390
+ setError(null);
1391
+ ctx.invoke(METHOD.listDefaults, {}).then((result) => {
1392
+ if (!active) return;
1393
+ setChoices(result);
1394
+ setLoaded(true);
1395
+ for (const [kind, items] of [["agent", result.agents], ["workspace", result.workspaces]]) for (const item of items) ctx.call(`config.${kind}.avatar`, { [`${kind}Id`]: item.id }).then((picture) => {
1396
+ if (!active || picture === null) return;
1397
+ setPictures((current) => ({
1398
+ ...current,
1399
+ [`${kind}:${item.id}`]: `data:${picture.mediaType};base64,${picture.data}`
1400
+ }));
1401
+ }).catch(() => {});
1402
+ }, (failure) => {
1403
+ if (active) setError(failureText(ctx, failure));
1404
+ }).finally(() => {
1405
+ if (active) setLoading(false);
1406
+ });
1407
+ return () => {
1408
+ active = false;
1409
+ };
1410
+ }, [connection]);
1411
+ function optionLabel(kind, id, name) {
1412
+ const initial = [...new Intl.Segmenter("und", { granularity: "grapheme" }).segment(name.trim())][0]?.segment ?? "";
1413
+ return /* @__PURE__ */ jsxs("span", {
1414
+ className: "inline-flex max-w-full items-center gap-2 align-middle",
1415
+ children: [/* @__PURE__ */ jsx(Avatar, {
1416
+ alt: name,
1417
+ name: kind === "workspace" ? initial : name,
1418
+ seed: kind === "workspace" ? name.trim() : id,
1419
+ src: pictures[`${kind}:${id}`],
1420
+ shape: kind === "workspace" ? "rounded" : "circle",
1421
+ size: "sm",
1422
+ style: {
1423
+ width: 20,
1424
+ height: 20,
1425
+ fontSize: 10
1426
+ },
1427
+ "aria-hidden": "true"
1428
+ }), /* @__PURE__ */ jsx("span", {
1429
+ className: "truncate",
1430
+ children: name
1431
+ })]
1432
+ });
1433
+ }
1434
+ async function save(field, value) {
1435
+ if (saving.current) return;
1436
+ const previous = field === "defaultAgentId" ? agent : workspace;
1437
+ if (value === previous) return;
1438
+ const setValue = field === "defaultAgentId" ? setAgent : setWorkspace;
1439
+ saving.current = true;
1440
+ setBusy(field);
1441
+ setValue(value);
1442
+ setError(null);
1443
+ try {
1444
+ const saved = await ctx.invoke(METHOD.saveBot, {
1445
+ id: bot.id,
1446
+ name: bot.name,
1447
+ appId: bot.appId,
1448
+ enabled: bot.enabled,
1449
+ [field]: value || null
1450
+ });
1451
+ setAgent(saved.defaultAgentId ?? "");
1452
+ setWorkspace(saved.defaultWorkspaceId ?? "");
1453
+ } catch (failure) {
1454
+ setValue(previous);
1455
+ setError(failureText(ctx, failure));
1456
+ } finally {
1457
+ saving.current = false;
1458
+ setBusy(null);
1459
+ }
1460
+ }
1461
+ return /* @__PURE__ */ jsxs("section", {
1462
+ className: "feishu-form",
1463
+ children: [
1464
+ loading && !loaded && /* @__PURE__ */ jsx("p", {
1465
+ role: "status",
1466
+ className: "feishu-muted",
1467
+ children: t("feishu.loading")
1468
+ }),
1469
+ /* @__PURE__ */ jsx(Field, {
1470
+ className: "settings-field-row",
1471
+ label: t("feishu.defaultWorkspace"),
1472
+ inline: true,
1473
+ children: (field) => /* @__PURE__ */ jsxs("div", {
1474
+ className: "flex min-w-0 items-center gap-2",
1475
+ children: [/* @__PURE__ */ jsxs(Select, {
1476
+ ...field,
1477
+ className: "min-w-0 flex-1",
1478
+ value: workspace,
1479
+ onValueChange: (value) => void save("defaultWorkspaceId", value),
1480
+ disabled: busy !== null || loading && !loaded,
1481
+ children: [
1482
+ /* @__PURE__ */ jsx("option", {
1483
+ value: "",
1484
+ children: t("feishu.unconfigured")
1485
+ }),
1486
+ workspace && !choices.workspaces.some((one) => one.id === workspace) && /* @__PURE__ */ jsx("option", {
1487
+ value: workspace,
1488
+ children: optionLabel("workspace", workspace, `${workspace} · ${t("feishu.unavailable")}`)
1489
+ }),
1490
+ choices.workspaces.map((one) => /* @__PURE__ */ jsx("option", {
1491
+ value: one.id,
1492
+ children: optionLabel("workspace", one.id, one.name)
1493
+ }, one.id))
1494
+ ]
1495
+ }), /* @__PURE__ */ jsx("span", {
1496
+ className: "inline-flex w-3 shrink-0",
1497
+ children: busy === "defaultWorkspaceId" && /* @__PURE__ */ jsx(ctx.ui.Spinner, {
1498
+ size: "sm",
1499
+ label: t("feishu.saving")
1500
+ })
1501
+ })]
1502
+ })
1503
+ }),
1504
+ /* @__PURE__ */ jsx(Field, {
1505
+ className: "settings-field-row",
1506
+ label: t("feishu.defaultAgent"),
1507
+ inline: true,
1508
+ children: (field) => /* @__PURE__ */ jsxs("div", {
1509
+ className: "flex min-w-0 items-center gap-2",
1510
+ children: [/* @__PURE__ */ jsxs(Select, {
1511
+ ...field,
1512
+ className: "min-w-0 flex-1",
1513
+ value: agent,
1514
+ onValueChange: (value) => void save("defaultAgentId", value),
1515
+ disabled: busy !== null || loading && !loaded,
1516
+ children: [
1517
+ /* @__PURE__ */ jsx("option", {
1518
+ value: "",
1519
+ children: t("feishu.unconfigured")
1520
+ }),
1521
+ agent && !choices.agents.some((one) => one.id === agent) && /* @__PURE__ */ jsx("option", {
1522
+ value: agent,
1523
+ children: optionLabel("agent", agent, `${agent} · ${t("feishu.unavailable")}`)
1524
+ }),
1525
+ choices.agents.map((one) => /* @__PURE__ */ jsx("option", {
1526
+ value: one.id,
1527
+ children: optionLabel("agent", one.id, one.name)
1528
+ }, one.id))
1529
+ ]
1530
+ }), /* @__PURE__ */ jsx("span", {
1531
+ className: "inline-flex w-3 shrink-0",
1532
+ children: busy === "defaultAgentId" && /* @__PURE__ */ jsx(ctx.ui.Spinner, {
1533
+ size: "sm",
1534
+ label: t("feishu.saving")
1535
+ })
1536
+ })]
1537
+ })
1538
+ }),
1539
+ error && /* @__PURE__ */ jsx("p", {
1540
+ role: "alert",
1541
+ className: "feishu-error",
1542
+ children: error
1543
+ })
1544
+ ]
1545
+ });
1546
+ };
1547
+ }
1548
+ //#endregion
1549
+ //#region src/ui/management-tab.tsx
1550
+ /** Builds the owner pairing tab and follows pairing completion from bot updates. */
1551
+ function managementTabFor(ctx) {
1552
+ const Defaults = defaultsFor(ctx);
1553
+ const t = ctx.i18n.t;
1554
+ const { Button, Field } = ctx.ui;
1555
+ return function ManagementTab({ instanceId }) {
1556
+ const [bot, setBot] = useState(null);
1557
+ const [pairing, setPairing] = useState(false);
1558
+ const [code, setCode] = useState(null);
1559
+ const [expiresAt, setExpiresAt] = useState(null);
1560
+ const [now, setNow] = useState(Date.now);
1561
+ const [copied, setCopied] = useState(false);
1562
+ const [error, setError] = useState(null);
1563
+ const attempt = useRef(0);
1564
+ const issuing = useRef(false);
1565
+ const [loadError, setLoadError] = useState(null);
1566
+ const fail = useFailureToast(ctx);
1567
+ const toast = ctx.ui.useToast();
1568
+ const load = useMemo(() => coalesceReads(async () => {
1569
+ setLoadError(null);
1570
+ try {
1571
+ const bots = await ctx.invoke(METHOD.listBots, {});
1572
+ setBot(bots.find((one) => one.id === instanceId) ?? null);
1573
+ } catch (failure) {
1574
+ setLoadError(failureText(ctx, failure));
1575
+ fail(failure);
1576
+ }
1577
+ }), [instanceId, fail]);
1578
+ useGatewayRefresh(ctx, load);
1579
+ useEffect(() => {
1580
+ load();
1581
+ return () => {
1582
+ attempt.current++;
1583
+ };
1584
+ }, [load]);
1585
+ useEffect(() => ctx.on(FRAME.botsChanged, ({ payload }) => {
1586
+ const update = payload;
1587
+ const next = update.bots?.find((one) => one.id === instanceId);
1588
+ if (!next) return;
1589
+ if (pairing && next.owner && update.pairedBotId === instanceId) {
1590
+ attempt.current++;
1591
+ setPairing(false);
1592
+ toast.add({
1593
+ tone: "success",
1594
+ title: fill(t("feishu.pairDone"), { name: next.owner.name ?? t("feishu.owner") })
1595
+ });
1596
+ }
1597
+ setBot(next);
1598
+ }), [
1599
+ instanceId,
1600
+ pairing,
1601
+ toast
1602
+ ]);
1603
+ useEffect(() => {
1604
+ if (!pairing || expiresAt === null) return;
1605
+ const timer = setInterval(() => setNow(Date.now()), 1e3);
1606
+ return () => clearInterval(timer);
1607
+ }, [pairing, expiresAt]);
1608
+ useEffect(() => {
1609
+ if (!copied) return;
1610
+ const timer = setTimeout(() => setCopied(false), 2e3);
1611
+ return () => clearTimeout(timer);
1612
+ }, [copied]);
1613
+ async function copyCode() {
1614
+ if (!code) return;
1615
+ try {
1616
+ await navigator.clipboard.writeText(code);
1617
+ setCopied(true);
1618
+ } catch {
1619
+ toast.add({
1620
+ tone: "destructive",
1621
+ title: t("feishu.pairCopyFailed")
1622
+ });
1623
+ }
1624
+ }
1625
+ async function pair() {
1626
+ if (issuing.current) return;
1627
+ issuing.current = true;
1628
+ const current = ++attempt.current;
1629
+ setPairing(true);
1630
+ setCode(null);
1631
+ setExpiresAt(null);
1632
+ setCopied(false);
1633
+ setError(null);
1634
+ try {
1635
+ const issued = await ctx.invoke(METHOD.startPairing, { botId: instanceId });
1636
+ if (current === attempt.current) {
1637
+ setCode(issued.code);
1638
+ setExpiresAt(issued.expiresAt);
1639
+ setNow(Date.now());
1640
+ }
1641
+ } catch (failure) {
1642
+ if (current === attempt.current) setError(failureText(ctx, failure));
1643
+ } finally {
1644
+ issuing.current = false;
1645
+ }
1646
+ }
1647
+ if (!bot) return loadError ? /* @__PURE__ */ jsxs("div", {
1648
+ className: "feishu-form",
1649
+ children: [/* @__PURE__ */ jsx("p", {
1650
+ role: "alert",
1651
+ children: loadError
1652
+ }), /* @__PURE__ */ jsx(Button, {
1653
+ onClick: () => void load(),
1654
+ children: t("feishu.retry")
1655
+ })]
1656
+ }) : /* @__PURE__ */ jsx("p", {
1657
+ role: "status",
1658
+ className: "feishu-muted",
1659
+ children: t("feishu.loading")
1660
+ });
1661
+ const starting = pairing && code === null && error === null;
1662
+ const expired = expiresAt !== null && now >= expiresAt;
1663
+ const seconds = Math.max(0, Math.ceil(((expiresAt ?? now) - now) / 1e3));
1664
+ const remaining = `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`;
1665
+ return /* @__PURE__ */ jsxs("div", {
1666
+ className: "feishu-form feishu-tab",
1667
+ children: [/* @__PURE__ */ jsx(Defaults, { bot }, bot.id), /* @__PURE__ */ jsxs("section", {
1668
+ className: "feishu-pair",
1669
+ "aria-label": t("feishu.pairTitle"),
1670
+ children: [
1671
+ /* @__PURE__ */ jsx(Field, {
1672
+ className: "settings-field-row",
1673
+ label: t("feishu.owner"),
1674
+ inline: true,
1675
+ children: (field) => /* @__PURE__ */ jsxs("div", {
1676
+ className: "feishu-pair-header",
1677
+ children: [/* @__PURE__ */ jsxs("div", {
1678
+ className: "feishu-pair-status",
1679
+ role: "status",
1680
+ children: [/* @__PURE__ */ jsxs("span", {
1681
+ className: bot.owner ? "feishu-pair-signed-in" : "feishu-pair-muted",
1682
+ children: [/* @__PURE__ */ jsx("span", {
1683
+ className: "feishu-pair-dot",
1684
+ "aria-hidden": "true"
1685
+ }), t(bot.owner ? "feishu.ownerPaired" : "feishu.ownerNone")]
1686
+ }), bot.owner && /* @__PURE__ */ jsx("span", {
1687
+ className: "feishu-pair-account",
1688
+ title: bot.owner.name ?? t("feishu.ownerUnnamed"),
1689
+ children: bot.owner.name ?? t("feishu.ownerUnnamed")
1690
+ })]
1691
+ }), /* @__PURE__ */ jsx("div", {
1692
+ className: "feishu-pair-actions",
1693
+ children: /* @__PURE__ */ jsx(Button, {
1694
+ id: field.id,
1695
+ variant: bot.owner ? "secondary" : "primary",
1696
+ disabled: bot.status !== "online" || starting,
1697
+ onClick: () => void pair(),
1698
+ children: t(starting ? "feishu.pairStarting" : pairing ? "feishu.pairAgain" : "feishu.pair")
1699
+ })
1700
+ })]
1701
+ })
1702
+ }),
1703
+ bot.status !== "online" && /* @__PURE__ */ jsx("p", {
1704
+ className: "feishu-pair-hint",
1705
+ children: t("feishu.pairOffline")
1706
+ }),
1707
+ pairing && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
1708
+ className: `feishu-pair-flow${expired || error ? " feishu-pair-warning" : ""}`,
1709
+ children: [
1710
+ starting && /* @__PURE__ */ jsx("p", {
1711
+ className: "feishu-pair-hint",
1712
+ children: t("feishu.pairStarting")
1713
+ }),
1714
+ code && !expired && /* @__PURE__ */ jsxs(Fragment, { children: [
1715
+ /* @__PURE__ */ jsx("strong", { children: t("feishu.pairBody") }),
1716
+ /* @__PURE__ */ jsxs("div", {
1717
+ className: "feishu-pair-code-row",
1718
+ children: [/* @__PURE__ */ jsx("strong", {
1719
+ className: "feishu-pair-code",
1720
+ children: code
1721
+ }), /* @__PURE__ */ jsx(Button, {
1722
+ variant: "plain",
1723
+ className: "feishu-pair-copy",
1724
+ "aria-label": t(copied ? "feishu.setup.copied" : "feishu.pairCopy"),
1725
+ title: t(copied ? "feishu.setup.copied" : "feishu.pairCopy"),
1726
+ onClick: () => void copyCode(),
1727
+ children: /* @__PURE__ */ jsx("svg", {
1728
+ width: "14",
1729
+ height: "14",
1730
+ viewBox: "0 0 16 16",
1731
+ fill: "none",
1732
+ stroke: "currentColor",
1733
+ strokeWidth: "1.5",
1734
+ "aria-hidden": "true",
1735
+ children: copied ? /* @__PURE__ */ jsx("path", { d: "m3 8 3 3 7-7" }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("rect", {
1736
+ x: "5",
1737
+ y: "5",
1738
+ width: "9",
1739
+ height: "9",
1740
+ rx: "2"
1741
+ }), /* @__PURE__ */ jsx("path", { d: "M10 5V3a1 1 0 0 0-1-1H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2" })] })
1742
+ })
1743
+ })]
1744
+ }),
1745
+ /* @__PURE__ */ jsxs("div", {
1746
+ className: "feishu-pair-footer",
1747
+ children: [/* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("span", {
1748
+ className: "feishu-pair-dot",
1749
+ "aria-hidden": "true"
1750
+ }), t("feishu.pairWaiting")] }), /* @__PURE__ */ jsx("small", {
1751
+ className: "feishu-pair-remaining",
1752
+ children: fill(t("feishu.pairRemaining"), { time: remaining })
1753
+ })]
1754
+ })
1755
+ ] }),
1756
+ expired && /* @__PURE__ */ jsx("p", {
1757
+ className: "feishu-pair-hint feishu-pair-reason",
1758
+ role: "status",
1759
+ children: t("feishu.pairExpired")
1760
+ }),
1761
+ error && /* @__PURE__ */ jsx("p", {
1762
+ className: "feishu-error",
1763
+ role: "alert",
1764
+ children: error
1765
+ })
1766
+ ]
1767
+ }), bot.owner && /* @__PURE__ */ jsx("p", {
1768
+ className: "feishu-pair-note",
1769
+ children: t("feishu.pairReplace")
1770
+ })] })
1771
+ ]
1772
+ })]
1773
+ });
1774
+ };
1775
+ }
1776
+ //#endregion
1777
+ //#region src/ui/setup-guide.tsx
1778
+ var PERMISSIONS = JSON.stringify({ scopes: {
1779
+ tenant: [
1780
+ "im:chat:create",
1781
+ "im:chat:read",
1782
+ "im:chat.members:read",
1783
+ "im:chat.members:write_only",
1784
+ "im:message.p2p_msg:readonly",
1785
+ "im:message.group_msg",
1786
+ "im:message:send_as_bot",
1787
+ "cardkit:card:write",
1788
+ "contact:user.base:readonly"
1789
+ ],
1790
+ user: []
1791
+ } }, null, 2);
1792
+ var EVENTS = [
1793
+ "im.message.receive_v1",
1794
+ "im.chat.member.user.added_v1",
1795
+ "im.chat.member.user.deleted_v1",
1796
+ "im.chat.member.user.withdrawn_v1",
1797
+ "im.chat.disbanded_v1",
1798
+ "im.chat.member.bot.deleted_v1",
1799
+ "im.chat.member.bot.added_v1"
1800
+ ];
1801
+ /** Builds an authorization guide with an importable permission list and copy feedback. */
1802
+ function setupGuideFor(ctx) {
1803
+ const { Button } = ctx.ui;
1804
+ const t = ctx.i18n.t;
1805
+ return function SetupGuide() {
1806
+ const [copied, setCopied] = useState(false);
1807
+ const [copyFailed, setCopyFailed] = useState(false);
1808
+ async function copy() {
1809
+ setCopied(false);
1810
+ setCopyFailed(false);
1811
+ try {
1812
+ await navigator.clipboard.writeText(PERMISSIONS);
1813
+ setCopied(true);
1814
+ } catch {
1815
+ setCopyFailed(true);
1816
+ }
1817
+ }
1818
+ return /* @__PURE__ */ jsxs("div", {
1819
+ className: "feishu-tab feishu-setup-body",
1820
+ children: [
1821
+ /* @__PURE__ */ jsx("p", {
1822
+ className: "feishu-muted",
1823
+ children: t("feishu.setup.intro")
1824
+ }),
1825
+ /* @__PURE__ */ jsx("a", {
1826
+ href: "https://open.feishu.cn/app",
1827
+ target: "_blank",
1828
+ rel: "noreferrer",
1829
+ children: t("feishu.setup.console")
1830
+ }),
1831
+ /* @__PURE__ */ jsxs("ol", {
1832
+ className: "feishu-setup-steps",
1833
+ children: [
1834
+ /* @__PURE__ */ jsxs("li", { children: [/* @__PURE__ */ jsx("strong", { children: t("feishu.setup.createTitle") }), /* @__PURE__ */ jsx("p", { children: t("feishu.setup.create") })] }),
1835
+ /* @__PURE__ */ jsxs("li", { children: [
1836
+ /* @__PURE__ */ jsx("strong", { children: t("feishu.setup.permissionsTitle") }),
1837
+ /* @__PURE__ */ jsx("p", { children: t("feishu.setup.permissions") }),
1838
+ /* @__PURE__ */ jsx("p", {
1839
+ className: "feishu-muted",
1840
+ children: t("feishu.setup.scopeNote")
1841
+ }),
1842
+ /* @__PURE__ */ jsx(Button, {
1843
+ type: "button",
1844
+ size: "sm",
1845
+ variant: "outline",
1846
+ onClick: () => void copy(),
1847
+ children: t("feishu.setup.copy")
1848
+ }),
1849
+ copied && /* @__PURE__ */ jsx("p", {
1850
+ role: "status",
1851
+ children: t("feishu.setup.copied")
1852
+ }),
1853
+ copyFailed && /* @__PURE__ */ jsx("p", {
1854
+ role: "alert",
1855
+ className: "feishu-error",
1856
+ children: t("feishu.setup.copyFailed")
1857
+ }),
1858
+ /* @__PURE__ */ jsx("pre", {
1859
+ className: "feishu-setup-code",
1860
+ children: /* @__PURE__ */ jsx("code", { children: PERMISSIONS })
1861
+ })
1862
+ ] }),
1863
+ /* @__PURE__ */ jsxs("li", { children: [/* @__PURE__ */ jsx("strong", { children: t("feishu.setup.connectTitle") }), /* @__PURE__ */ jsx("p", { children: t("feishu.setup.connect") })] }),
1864
+ /* @__PURE__ */ jsxs("li", { children: [
1865
+ /* @__PURE__ */ jsx("strong", { children: t("feishu.setup.eventsTitle") }),
1866
+ /* @__PURE__ */ jsx("p", { children: t("feishu.setup.events") }),
1867
+ /* @__PURE__ */ jsx("ul", {
1868
+ className: "feishu-setup-events",
1869
+ children: EVENTS.map((event) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("code", { children: event }) }, event))
1870
+ })
1871
+ ] }),
1872
+ /* @__PURE__ */ jsxs("li", { children: [
1873
+ /* @__PURE__ */ jsx("strong", { children: t("feishu.setup.callbackTitle") }),
1874
+ /* @__PURE__ */ jsx("p", { children: t("feishu.setup.callback") }),
1875
+ /* @__PURE__ */ jsx("code", { children: "card.action.trigger" })
1876
+ ] }),
1877
+ /* @__PURE__ */ jsxs("li", { children: [/* @__PURE__ */ jsx("strong", { children: t("feishu.setup.publishTitle") }), /* @__PURE__ */ jsx("p", { children: t("feishu.setup.publish") })] })
1878
+ ]
1879
+ })
1880
+ ]
1881
+ });
1882
+ };
1883
+ }
1884
+ //#endregion
1885
+ //#region src/ui/index.tsx
1886
+ var runtimeVersion = 5;
1887
+ var STYLES = `
1888
+
1889
+ .feishu-sync { gap: 1rem; }
1890
+ .feishu-sync-heading { display: flex; align-items: center; gap: .75rem; min-width: 0; }
1891
+ .feishu-sync-heading strong { font-size: .875rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1892
+ .feishu-sync-avatar { display: grid; place-items: center; width: 2rem; height: 2rem; flex: 0 0 auto; border-radius: var(--radius-control); background: color-mix(in srgb, var(--primary) 8%, transparent); color: var(--primary); }
1893
+ .feishu-sync-avatar svg { width: 1.25rem; height: 1.25rem; }
1894
+ .feishu-sync-logo { width: 2rem; height: 2rem; object-fit: contain; flex: 0 0 auto; }
1895
+ .feishu-sync-name-line { display: flex; align-items: baseline; gap: .5rem; min-width: 0; white-space: nowrap; }
1896
+ .feishu-sync-name-line > :first-child { flex: 0 1 auto; max-width: 55%; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
1897
+ .feishu-sync-name-line > small { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--muted-foreground); font-size: .75rem; }
1898
+ .feishu-sync-secondary { color: var(--muted-foreground); font-size: .75rem; }
1899
+ .feishu-sync-status-actions { display: flex; align-items: center; gap: .75rem; flex: 0 0 auto; white-space: nowrap; }
1900
+ .feishu-sync-status-actions .feishu-group-status { align-items: center; gap: .375rem; font-size: .75rem; }
1901
+ .feishu-sync-icon { width: var(--form-control-height); padding: 0; flex: 0 0 auto; }
1902
+ .feishu-sync-icon svg { width: 1rem; height: 1rem; }
1903
+ .feishu-sync-notice { display: flex; align-items: flex-start; gap: .625rem; margin: 0; padding-top: .75rem; border-top: 1px solid var(--border); color: var(--muted-foreground); font-size: .75rem; line-height: 1.7; }
1904
+ .feishu-sync-notice > svg { width: 1.125rem; height: 1.125rem; flex: 0 0 auto; margin-top: .125rem; }
1905
+ .feishu-sync-notice p { margin: 0; }
1906
+ .feishu-sync-notice strong { font-weight: 500; }
1907
+ .feishu-sync-footer { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
1908
+ .feishu-sync-change { color: var(--muted-foreground); }
1909
+ .feishu-sync .feishu-sync-members { border-top: 1px solid var(--border); padding-top: .75rem; gap: 0; }
1910
+ .feishu-sync-members .feishu-topic-heading { gap: .5rem; }
1911
+ .feishu-sync-members .feishu-topic-heading > strong { font-weight: 500; }
1912
+ .feishu-sync-members .feishu-topic-heading > .feishu-sync-icon { margin-left: auto; }
1913
+ .feishu-sync .feishu-sync-members-hint { margin: .1875rem 0 .5rem; line-height: 1.6; }
1914
+ .feishu-sync .feishu-member-row { min-height: 3.25rem; padding: 0; gap: .625rem; border-bottom-color: color-mix(in srgb, var(--border) 50%, transparent); }
1915
+ .feishu-sync .feishu-member-row:last-child { border-bottom: 0; }
1916
+ .feishu-member-name { display: flex; flex: 1; align-items: center; min-width: 0; gap: .375rem; }
1917
+ .feishu-member-name > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1918
+ .feishu-member-name > :last-child:not(:first-child) { flex: 0 0 auto; }
1919
+ .feishu-sync .feishu-member-row > :last-child { flex-shrink: 0; }
1920
+ @container (max-width: 30rem) {
1921
+ .feishu-sync .feishu-member-row { flex-wrap: wrap; padding: .5rem 0; }
1922
+ .feishu-sync .feishu-member-row .feishu-member-name { min-width: calc(100% - 3rem); }
1923
+ .feishu-sync .feishu-member-row > :last-child { margin-left: auto; }
1924
+ }
1925
+ .feishu-tab { box-sizing: border-box; min-width: 0; }
1926
+ .feishu-pair { display: flex; min-width: 0; flex-direction: column; gap: .5rem; }
1927
+ .feishu-pair p { margin: 0; }
1928
+ .feishu-pair-header { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: .75rem; min-height: var(--form-control-height); }
1929
+ .feishu-pair-status, .feishu-pair-actions, .feishu-pair-code-row { display: flex; align-items: center; gap: .5rem; min-width: 0; }
1930
+ .feishu-pair-status { min-height: var(--form-control-height); }
1931
+ .feishu-pair-status > span:first-child { display: inline-flex; align-items: center; gap: .375rem; flex-shrink: 0; font-size: .75rem; }
1932
+ .feishu-pair-muted { color: var(--muted-foreground); }
1933
+ .feishu-pair-signed-in { color: var(--success); }
1934
+ .feishu-pair-account { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .75rem; }
1935
+ .feishu-pair-actions { justify-content: flex-end; }
1936
+ .feishu-pair-dot { display: inline-block; flex-shrink: 0; width: .375rem; height: .375rem; border-radius: var(--radius-pill); background: currentColor; }
1937
+ .feishu-pair-flow { display: flex; flex-direction: column; gap: .875rem; margin-top: .5rem; padding: 1.125rem; border: 1px solid var(--border); border-radius: var(--radius-control); background: color-mix(in srgb, var(--success) 4%, var(--background)); min-width: 0; }
1938
+ .feishu-pair-flow > strong { font-size: .8125rem; font-weight: 600; }
1939
+ .feishu-pair-warning { background: color-mix(in srgb, var(--warning) 5%, var(--background)); }
1940
+ .feishu-pair-code { font-family: var(--font-mono); font-size: 1.375rem; letter-spacing: .05em; white-space: nowrap; }
1941
+ .feishu-pair-copy { display: inline-flex; flex-shrink: 0; min-height: var(--form-control-height); align-items: center; justify-content: center; padding: .375rem; border-radius: var(--radius-control); color: var(--muted-foreground); }
1942
+ .feishu-pair-copy:hover:not(:disabled) { background: var(--solid-hover); color: var(--foreground); }
1943
+ .feishu-pair-footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .75rem; border-top: 1px solid var(--border); padding-top: .75rem; font-size: var(--text-2xs); color: var(--muted-foreground); }
1944
+ .feishu-pair-footer > span { display: inline-flex; align-items: center; gap: .375rem; }
1945
+ .feishu-pair-footer .feishu-pair-dot { color: var(--success); }
1946
+ .feishu-pair-remaining { margin-inline-start: auto; color: var(--muted-foreground); font-size: var(--text-2xs); font-variant-numeric: tabular-nums; white-space: nowrap; }
1947
+ .feishu-pair-hint, .feishu-pair-note { color: var(--muted-foreground); font-size: .75rem; line-height: 1.7; }
1948
+ .feishu-pair-reason { color: var(--warning); }
1949
+ @container (max-width: 27.999rem) {
1950
+ .feishu-pair-header { gap: .5rem; }
1951
+ .feishu-pair-actions button { padding-inline: .5rem; }
1952
+ .feishu-pair-flow { padding: .75rem; }
1953
+ .feishu-pair-code { font-size: 1.125rem; letter-spacing: 0; }
1954
+ }
1955
+ .feishu-inline-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .75rem; }
1956
+ .feishu-inline-actions a { color: var(--primary); font-size: .8125rem; text-decoration: underline; text-underline-offset: .2em; }
1957
+ .feishu-topics { display: flex; flex-direction: column; list-style: none; padding: 0; margin: 0; }
1958
+ .feishu-topic { display: flex; flex-direction: column; gap: .75rem; padding: 1rem 0; border-bottom: 1px solid var(--border); }
1959
+ .feishu-member-row { padding: .625rem 0; border-bottom: 1px solid var(--border); }
1960
+ .feishu-member-row strong, .feishu-member-row small { overflow-wrap: anywhere; }
1961
+ .feishu-member-row select { flex: 0 0 auto; min-width: 7rem; }
1962
+ .feishu-topic:first-child { padding-top: 0; }
1963
+ .feishu-topic-heading { display: flex; align-items: center; gap: .75rem; }
1964
+ .feishu-group-status { display: flex; flex: 0 0 auto; color: var(--muted-foreground); }
1965
+ .feishu-group-status svg { width: 1.25rem; height: 1.25rem; }
1966
+ .feishu-group-status[data-state="active"] { color: var(--primary); }
1967
+ .feishu-group-status[data-state="broken"] { color: var(--destructive); }
1968
+ .feishu-group-unbind { flex: 0 0 auto; width: 2rem; height: 2rem; padding: 0; opacity: 0; pointer-events: none; transition: opacity 150ms; color: var(--muted-foreground); }
1969
+ .feishu-group-unbind svg { width: 1rem; height: 1rem; }
1970
+ .feishu-topic:hover .feishu-group-unbind, .feishu-topic:focus-within .feishu-group-unbind { opacity: 1; pointer-events: auto; }
1971
+ @media (hover: none) { .feishu-group-unbind { opacity: 1; pointer-events: auto; } }
1972
+ @media (prefers-reduced-motion: reduce) { .feishu-group-unbind { transition: none; } }
1973
+ .feishu-topic strong { font-weight: 500; overflow-wrap: anywhere; }
1974
+ .feishu-topic small { overflow-wrap: anywhere; }
1975
+
1976
+ .feishu-setup-body { display: flex; flex-direction: column; gap: .75rem; line-height: 1.65; overflow-wrap: anywhere; }
1977
+ .feishu-setup-body a { color: var(--primary); text-decoration: underline; text-underline-offset: .2em; }
1978
+ .feishu-setup-steps { display: flex; flex-direction: column; gap: 1rem; list-style: none; padding: 0; margin: 0; }
1979
+ .feishu-setup-steps > li { display: flex; min-width: 0; flex-direction: column; align-items: flex-start; gap: .5rem; }
1980
+ .feishu-setup-steps p { margin: 0; }
1981
+ .feishu-setup-code { width: 100%; box-sizing: border-box; max-height: 18rem; overflow: auto; margin: 0; padding: .75rem; border-radius: .375rem; background: var(--muted); font-size: .75rem; white-space: pre-wrap; overflow-wrap: anywhere; }
1982
+ .feishu-setup-events { padding-left: 1.25rem; margin: 0; font-size: .75rem; list-style: disc; }
1983
+
1984
+ .feishu-form { display: flex; flex-direction: column; gap: 1rem; font-size: .875rem; }
1985
+ .feishu-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; }
1986
+ .feishu-muted { margin: 0; color: var(--muted-foreground); font-size: .75rem; }
1987
+ .feishu-error { margin: 0; color: var(--destructive); font-size: .75rem; overflow-wrap: anywhere; }
1988
+ .feishu-grow { display: flex; flex: 1; min-width: 0; flex-direction: column; gap: .125rem; }
1989
+ .feishu-code { margin: 0; font-family: var(--font-mono, ui-monospace, monospace); font-size: 2rem; letter-spacing: .3em; text-align: center; }
1990
+ `;
1991
+ /** Registers Feishu's channel and chat binding surfaces. */
1992
+ var register = (ctx) => {
1993
+ ctx.i18n.register(CATALOGUES, "en-US");
1994
+ ctx.styles.add(STYLES);
1995
+ ctx.slots.register("shell.settings.channel", {
1996
+ id: "feishu-channel",
1997
+ type: "feishu",
1998
+ logo: FEISHU_LOGO,
1999
+ label: () => ctx.i18n.t("feishu.title"),
2000
+ icon: "message-square-text",
2001
+ removeNote: () => ctx.i18n.t("feishu.removeBody"),
2002
+ ...channelOperations(ctx),
2003
+ add: addFor(ctx),
2004
+ tabs: [
2005
+ {
2006
+ id: "credentials",
2007
+ title: () => ctx.i18n.t("feishu.connection"),
2008
+ component: connectionTabFor(ctx)
2009
+ },
2010
+ {
2011
+ id: "management",
2012
+ title: () => ctx.i18n.t("feishu.management"),
2013
+ component: managementTabFor(ctx)
2014
+ },
2015
+ {
2016
+ id: "groups",
2017
+ title: () => ctx.i18n.t("feishu.groups"),
2018
+ component: groupsTabFor(ctx)
2019
+ },
2020
+ {
2021
+ id: "authorization",
2022
+ title: () => ctx.i18n.t("feishu.authorization"),
2023
+ component: setupGuideFor(ctx)
2024
+ }
2025
+ ]
2026
+ });
2027
+ ctx.slots.register("chat.session.channel", {
2028
+ id: "feishu-binding",
2029
+ type: "feishu",
2030
+ async binding({ sessionId }) {
2031
+ return (await ctx.invoke(METHOD.getBinding, { sessionId }))?.botId ?? null;
2032
+ },
2033
+ watch({ sessionId }, changed) {
2034
+ return ctx.on(FRAME.bindingChanged, ({ payload }) => {
2035
+ if (payload.sessionId === sessionId) changed();
2036
+ });
2037
+ },
2038
+ async unbind({ sessionId }) {
2039
+ await ctx.invoke(METHOD.unbind, { sessionId });
2040
+ },
2041
+ component: bindingDialogFor(ctx)
2042
+ });
2043
+ };
2044
+ //#endregion
2045
+ export { register, runtimeVersion };