dsh-message-gateway 0.1.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.
- package/LICENSE +21 -0
- package/README.en.md +74 -0
- package/README.es.md +74 -0
- package/README.md +77 -0
- package/cordis.patch.yml +5 -0
- package/docs/architecture.md +131 -0
- package/docs/webhooks.md +81 -0
- package/docs/wechaty-gateway.md +66 -0
- package/lib/client.js +660 -0
- package/lib/client.js.map +7 -0
- package/lib/index.js +2768 -0
- package/lib/index.js.map +7 -0
- package/package.json +99 -0
package/lib/client.js
ADDED
|
@@ -0,0 +1,660 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "dsh-message-gateway",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
+
|
|
8
|
+
"use strict";
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
12
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
|
+
|
|
27
|
+
// src/client/index.ts
|
|
28
|
+
var index_exports = {};
|
|
29
|
+
__export(index_exports, {
|
|
30
|
+
apply: () => apply,
|
|
31
|
+
default: () => index_default,
|
|
32
|
+
inject: () => inject
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(index_exports);
|
|
35
|
+
var import_react3 = require("react");
|
|
36
|
+
var import_client = require("react-dom/client");
|
|
37
|
+
|
|
38
|
+
// src/client/api.ts
|
|
39
|
+
var GatewayApi = class {
|
|
40
|
+
async post(path, payload) {
|
|
41
|
+
let response;
|
|
42
|
+
try {
|
|
43
|
+
response = await fetch(path, {
|
|
44
|
+
method: "POST",
|
|
45
|
+
headers: { "content-type": "application/json" },
|
|
46
|
+
body: JSON.stringify(payload ?? {})
|
|
47
|
+
});
|
|
48
|
+
} catch (error) {
|
|
49
|
+
return { ok: false, error: { code: "network", message: error instanceof Error ? error.message : "network error" } };
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
return await response.json();
|
|
53
|
+
} catch {
|
|
54
|
+
return { ok: false, error: { code: "internal", message: `bad response (${response.status})` } };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
list() {
|
|
58
|
+
return this.post("/gateway/list", {});
|
|
59
|
+
}
|
|
60
|
+
save(platform, credentials) {
|
|
61
|
+
return this.post("/gateway/save", { platform, ...credentials });
|
|
62
|
+
}
|
|
63
|
+
delete(platform) {
|
|
64
|
+
return this.post("/gateway/delete", { platform });
|
|
65
|
+
}
|
|
66
|
+
test(platform, credentials) {
|
|
67
|
+
return this.post("/gateway/test", { platform, ...credentials });
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/client/i18n.ts
|
|
72
|
+
var import_react = require("react");
|
|
73
|
+
var DICTS = {
|
|
74
|
+
zh: {
|
|
75
|
+
"gateway.title": "\u6D88\u606F\u5E73\u53F0",
|
|
76
|
+
"gateway.open": "\u6253\u5F00\u6D88\u606F\u5E73\u53F0",
|
|
77
|
+
"gateway.close": "\u5173\u95ED",
|
|
78
|
+
"gateway.save": "\u4FDD\u5B58",
|
|
79
|
+
"gateway.test": "\u6D4B\u8BD5\u8FDE\u63A5",
|
|
80
|
+
"gateway.testing": "\u6D4B\u8BD5\u4E2D\u2026",
|
|
81
|
+
"gateway.delete": "\u5220\u9664\u914D\u7F6E",
|
|
82
|
+
"gateway.saved": "\u5DF2\u4FDD\u5B58",
|
|
83
|
+
"gateway.deleted": "\u5DF2\u5220\u9664",
|
|
84
|
+
"gateway.testing.result": "\u6D4B\u8BD5\u7ED3\u679C",
|
|
85
|
+
"gateway.status.connected": "\u5DF2\u8FDE\u63A5",
|
|
86
|
+
"gateway.status.error": "\u8FDE\u63A5\u5931\u8D25",
|
|
87
|
+
"gateway.status.none": "\u672A\u914D\u7F6E",
|
|
88
|
+
"gateway.status.manual": "\u624B\u52A8\u6A21\u5F0F",
|
|
89
|
+
"gateway.updatedAt": "\u6700\u8FD1\u6D4B\u8BD5",
|
|
90
|
+
"platform.telegram": "Telegram",
|
|
91
|
+
"platform.discord": "Discord",
|
|
92
|
+
"platform.qq": "QQ \u673A\u5668\u4EBA",
|
|
93
|
+
"platform.wecom": "\u4F01\u4E1A\u5FAE\u4FE1",
|
|
94
|
+
"platform.wecom.hint": "\u56DE\u8C03\u5F0F\u63A5\u5165\uFF1A\u5728\u4F01\u4E1A\u5FAE\u4FE1\u7BA1\u7406\u540E\u53F0\u300C\u5E94\u7528 \u2192 \u63A5\u6536\u6D88\u606F\u300D\u914D\u7F6E\u56DE\u8C03 URL\uFF08\u9700\u516C\u7F51\u53EF\u8BBF\u95EE\uFF0C\u6307\u5411 /gateway/wecom/callback\uFF09\u5E76\u586B\u5165 Token \u4E0E EncodingAESKey\uFF0C\u7528\u6237\u7ED9\u5E94\u7528\u53D1\u6D88\u606F\u5373\u53EF\u81EA\u52A8\u5BF9\u8BDD\u3002",
|
|
95
|
+
"platform.wecomAibot": "\u4F01\u4E1A\u5FAE\u4FE1 \xB7 \u667A\u80FD\u673A\u5668\u4EBA",
|
|
96
|
+
"platform.wecomAibot.hint": "\u4F7F\u7528\u5B98\u65B9 SDK \u957F\u8FDE\u63A5\uFF08WebSocket\uFF09\uFF0C\u914D\u7F6E Bot ID \u4E0E Secret \u5373\u53EF\u8FDE\u63A5\u667A\u80FD\u673A\u5668\u4EBA\u3002",
|
|
97
|
+
"field.botId": "Bot ID",
|
|
98
|
+
"platform.wechat": "\u5FAE\u4FE1",
|
|
99
|
+
"platform.wechatMp": "\u5FAE\u4FE1\u516C\u4F17\u53F7",
|
|
100
|
+
"platform.wechatMp.hint": "\u56DE\u8C03\u5F0F\u63A5\u5165\uFF1A\u5728\u516C\u4F17\u53F7\u540E\u53F0\u300C\u8BBE\u7F6E\u4E0E\u5F00\u53D1 \u2192 \u57FA\u672C\u914D\u7F6E\u300D\u914D\u7F6E\u670D\u52A1\u5668 URL\uFF08\u9700\u516C\u7F51\u53EF\u8BBF\u95EE\uFF0C\u6307\u5411 /gateway/wechat-mp/callback\uFF09\u5E76\u586B\u5165 Token\uFF0C\u5173\u6CE8\u7528\u6237\u53D1\u6D88\u606F\u5373\u53EF\u81EA\u52A8\u5BF9\u8BDD\u3002",
|
|
101
|
+
"platform.whatsapp": "WhatsApp",
|
|
102
|
+
"platform.whatsapp.hint": "Webhook \u63A5\u5165\uFF1A\u5728 Meta WhatsApp \u5F00\u53D1\u8005\u540E\u53F0\u628A Webhook \u6307\u5411 /gateway/whatsapp/webhook\uFF0C\u9A8C\u8BC1 Token \u586B\u6B64\u5904\u7684 Token\uFF1B\u7528\u6237\u53D1\u6D88\u606F\u5373\u81EA\u52A8\u5BF9\u8BDD\u3002",
|
|
103
|
+
"platform.email": "Email",
|
|
104
|
+
"platform.email.hint": "IMAP \u8F6E\u8BE2\u6536\u4EF6\uFF08993 \u9690\u5F0F TLS / 143 STARTTLS\uFF09+ SMTP \u56DE\u590D\uFF08465 \u9690\u5F0F TLS / 587\u300125 STARTTLS\uFF09\u3002\u6309\u90AE\u4EF6\u7EBF\u7A0B\u81EA\u52A8\u5F52\u7C7B\u4F1A\u8BDD\uFF0C\u56DE\u590D\u7528 Re: \u539F\u4E3B\u9898\uFF1BSMTP \u7559\u7A7A\u65F6\u590D\u7528 IMAP \u670D\u52A1\u5668\u4E0E\u8D26\u53F7\u3002",
|
|
105
|
+
"platform.webhooks": "Webhooks",
|
|
106
|
+
"platform.wechat.hint": "\u5FAE\u4FE1\u4E2A\u4EBA\u53F7\u9700\u7B2C\u4E09\u65B9\u6846\u67B6\uFF08\u5982 Wechaty\uFF09\u626B\u7801\u767B\u5F55\uFF0C\u672C\u63D2\u4EF6\u6682\u672A\u5185\u7F6E\u8FDE\u63A5\u5668\u3002",
|
|
107
|
+
"platform.webhooks.hint": 'Webhook \u65E0\u9700\u51ED\u636E\u5373\u53EF\u542F\u7528\uFF1B\u53EF\u8BBE\u7F6E\u7B7E\u540D\u5BC6\u94A5\u7528\u4E8E\u6821\u9A8C\u8BF7\u6C42\u3002\u63A5\u6536\u7AEF\u70B9\uFF1APOST /gateway/webhook/in\uFF0C\u8BF7\u6C42\u4F53 {"text": "..."}\uFF08text / content / message \u4EFB\u4E00\u5B57\u6BB5\uFF09\u3002',
|
|
108
|
+
"field.token": "Bot Token",
|
|
109
|
+
"field.token.ph": "\u7C98\u8D34\u673A\u5668\u4EBA Token",
|
|
110
|
+
"field.secret": "\u5BC6\u94A5",
|
|
111
|
+
"field.secret.ph": "\u7C98\u8D34\u5BC6\u94A5",
|
|
112
|
+
"field.appId": "App ID",
|
|
113
|
+
"field.callbackToken": "\u56DE\u8C03 Token",
|
|
114
|
+
"field.encodingAESKey": "EncodingAESKey",
|
|
115
|
+
"field.corpId": "\u4F01\u4E1A ID (CorpID)",
|
|
116
|
+
"field.agentId": "\u5E94\u7528 ID (AgentID)",
|
|
117
|
+
"field.phoneId": "Phone Number ID",
|
|
118
|
+
"field.imapHost": "IMAP \u670D\u52A1\u5668",
|
|
119
|
+
"field.imapPort": "IMAP \u7AEF\u53E3",
|
|
120
|
+
"field.imapUser": "\u90AE\u7BB1\u8D26\u53F7",
|
|
121
|
+
"field.imapPass": "\u90AE\u7BB1\u5BC6\u7801 / \u6388\u6743\u7801",
|
|
122
|
+
"field.smtpHost": "SMTP \u670D\u52A1\u5668\uFF08\u53EF\u7559\u7A7A\u590D\u7528 IMAP\uFF09",
|
|
123
|
+
"field.smtpPort": "SMTP \u7AEF\u53E3",
|
|
124
|
+
"field.smtpUser": "SMTP \u8D26\u53F7",
|
|
125
|
+
"field.smtpPass": "SMTP \u5BC6\u7801 / \u6388\u6743\u7801",
|
|
126
|
+
"field.webhookSecret": "\u7B7E\u540D\u5BC6\u94A5\uFF08\u53EF\u9009\uFF09"
|
|
127
|
+
},
|
|
128
|
+
en: {
|
|
129
|
+
"gateway.title": "Message platforms",
|
|
130
|
+
"gateway.open": "Open message platforms",
|
|
131
|
+
"gateway.close": "Close",
|
|
132
|
+
"gateway.save": "Save",
|
|
133
|
+
"gateway.test": "Test connection",
|
|
134
|
+
"gateway.testing": "Testing\u2026",
|
|
135
|
+
"gateway.delete": "Delete config",
|
|
136
|
+
"gateway.saved": "Saved",
|
|
137
|
+
"gateway.deleted": "Deleted",
|
|
138
|
+
"gateway.testing.result": "Test result",
|
|
139
|
+
"gateway.status.connected": "Connected",
|
|
140
|
+
"gateway.status.error": "Connection failed",
|
|
141
|
+
"gateway.status.none": "Not configured",
|
|
142
|
+
"gateway.status.manual": "Manual mode",
|
|
143
|
+
"gateway.updatedAt": "Last test",
|
|
144
|
+
"platform.telegram": "Telegram",
|
|
145
|
+
"platform.discord": "Discord",
|
|
146
|
+
"platform.qq": "QQ Bot",
|
|
147
|
+
"platform.wecom": "WeCom",
|
|
148
|
+
"platform.wecom.hint": "Callback style: in the WeCom admin console (App \u2192 Receive messages) point the callback URL (publicly reachable) at /gateway/wecom/callback and fill in the Token and EncodingAESKey; users who message the app get auto replies.",
|
|
149
|
+
"platform.wecomAibot": "WeCom \xB7 AI Bot",
|
|
150
|
+
"platform.wecomAibot.hint": "Uses the official SDK long connection (WebSocket): configure Bot ID and Secret to connect the AI bot.",
|
|
151
|
+
"field.botId": "Bot ID",
|
|
152
|
+
"platform.wechat": "WeChat",
|
|
153
|
+
"platform.wechatMp": "WeChat Official Account",
|
|
154
|
+
"platform.wechatMp.hint": "Callback style: in the Official Account console (Settings & Development \u2192 Basic config) point the server URL (publicly reachable) at /gateway/wechat-mp/callback and fill in the Token; followers who message get auto replies.",
|
|
155
|
+
"platform.whatsapp": "WhatsApp",
|
|
156
|
+
"platform.whatsapp.hint": "Webhook style: in the Meta WhatsApp developer console point the webhook at /gateway/whatsapp/webhook and use this Token as the verify token; users who message get auto replies.",
|
|
157
|
+
"platform.email": "Email",
|
|
158
|
+
"platform.email.hint": "Receives via IMAP polling (993 implicit TLS / 143 STARTTLS) and replies via SMTP (465 implicit TLS / 587, 25 STARTTLS). Messages are grouped into per-thread sessions; replies use Re: original subject; leave SMTP empty to reuse the IMAP server and account.",
|
|
159
|
+
"platform.webhooks": "Webhooks",
|
|
160
|
+
"platform.wechat.hint": "WeChat personal accounts need a third-party framework (e.g. Wechaty) with QR login; this plugin does not bundle a connector yet.",
|
|
161
|
+
"platform.webhooks.hint": 'Webhooks work without credentials; an optional signing secret validates incoming requests. Receive endpoint: POST /gateway/webhook/in with body {"text": "..."} (any of text / content / message).',
|
|
162
|
+
"field.token": "Bot token",
|
|
163
|
+
"field.token.ph": "Paste the bot token",
|
|
164
|
+
"field.secret": "Secret",
|
|
165
|
+
"field.secret.ph": "Paste the secret",
|
|
166
|
+
"field.appId": "App ID",
|
|
167
|
+
"field.callbackToken": "Callback token",
|
|
168
|
+
"field.encodingAESKey": "EncodingAESKey",
|
|
169
|
+
"field.corpId": "Corp ID",
|
|
170
|
+
"field.agentId": "Agent ID",
|
|
171
|
+
"field.phoneId": "Phone number ID",
|
|
172
|
+
"field.imapHost": "IMAP host",
|
|
173
|
+
"field.imapPort": "IMAP port",
|
|
174
|
+
"field.imapUser": "Email account",
|
|
175
|
+
"field.imapPass": "Email password / app password",
|
|
176
|
+
"field.smtpHost": "SMTP host (empty = reuse IMAP)",
|
|
177
|
+
"field.smtpPort": "SMTP port",
|
|
178
|
+
"field.smtpUser": "SMTP account",
|
|
179
|
+
"field.smtpPass": "SMTP password / app password",
|
|
180
|
+
"field.webhookSecret": "Signing secret (optional)"
|
|
181
|
+
},
|
|
182
|
+
es: {
|
|
183
|
+
"gateway.title": "Plataformas de mensajer\xEDa",
|
|
184
|
+
"gateway.open": "Abrir plataformas de mensajer\xEDa",
|
|
185
|
+
"gateway.close": "Cerrar",
|
|
186
|
+
"gateway.save": "Guardar",
|
|
187
|
+
"gateway.test": "Probar conexi\xF3n",
|
|
188
|
+
"gateway.testing": "Probando\u2026",
|
|
189
|
+
"gateway.delete": "Eliminar configuraci\xF3n",
|
|
190
|
+
"gateway.saved": "Guardado",
|
|
191
|
+
"gateway.deleted": "Eliminado",
|
|
192
|
+
"gateway.testing.result": "Resultado de la prueba",
|
|
193
|
+
"gateway.status.connected": "Conectado",
|
|
194
|
+
"gateway.status.error": "Error de conexi\xF3n",
|
|
195
|
+
"gateway.status.none": "No configurado",
|
|
196
|
+
"gateway.status.manual": "Modo manual",
|
|
197
|
+
"gateway.updatedAt": "\xDAltima prueba",
|
|
198
|
+
"platform.telegram": "Telegram",
|
|
199
|
+
"platform.discord": "Discord",
|
|
200
|
+
"platform.qq": "Bot de QQ",
|
|
201
|
+
"platform.wecom": "WeCom",
|
|
202
|
+
"platform.wecom.hint": "Estilo callback: en la consola de WeCom (App \u2192 Recibir mensajes) apunte la URL de callback (accesible p\xFAblicamente) a /gateway/wecom/callback y rellene el Token y el EncodingAESKey; los usuarios que escriban al app reciben respuestas autom\xE1ticas.",
|
|
203
|
+
"platform.wecomAibot": "WeCom \xB7 Bot de IA",
|
|
204
|
+
"platform.wecomAibot.hint": "Usa la conexi\xF3n larga del SDK oficial (WebSocket): configura el Bot ID y el Secret para conectar el bot de IA.",
|
|
205
|
+
"field.botId": "Bot ID",
|
|
206
|
+
"platform.wechat": "WeChat",
|
|
207
|
+
"platform.wechatMp": "Cuenta oficial de WeChat",
|
|
208
|
+
"platform.wechatMp.hint": "Estilo callback: en la consola de la Cuenta oficial (Configuraci\xF3n y desarrollo \u2192 Configuraci\xF3n b\xE1sica) apunte la URL del servidor (accesible p\xFAblicamente) a /gateway/wechat-mp/callback y rellene el Token; los seguidores que escriban reciben respuestas autom\xE1ticas.",
|
|
209
|
+
"platform.whatsapp": "WhatsApp",
|
|
210
|
+
"platform.whatsapp.hint": "Estilo webhook: en la consola de Meta WhatsApp apunte el webhook a /gateway/whatsapp/webhook y use este Token como token de verificaci\xF3n; los usuarios que escriban reciben respuestas autom\xE1ticas.",
|
|
211
|
+
"platform.email": "Email",
|
|
212
|
+
"platform.email.hint": "Recibe por sondeo IMAP (993 TLS impl\xEDcito / 143 STARTTLS) y responde por SMTP (465 TLS impl\xEDcito / 587, 25 STARTTLS). Los mensajes se agrupan en sesiones por hilo; las respuestas usan Re: asunto original; deje SMTP vac\xEDo para reutilizar el servidor y la cuenta IMAP.",
|
|
213
|
+
"platform.webhooks": "Webhooks",
|
|
214
|
+
"platform.wechat.hint": "Las cuentas personales de WeChat necesitan un framework de terceros (p. ej. Wechaty) con inicio de sesi\xF3n por QR; este plugin a\xFAn no incluye un conector.",
|
|
215
|
+
"platform.webhooks.hint": 'Los webhooks funcionan sin credenciales; un secreto de firma opcional valida las peticiones entrantes. Endpoint de recepci\xF3n: POST /gateway/webhook/in con cuerpo {"text": "..."} (cualquiera de text / content / message).',
|
|
216
|
+
"field.token": "Token del bot",
|
|
217
|
+
"field.token.ph": "Pega el token del bot",
|
|
218
|
+
"field.secret": "Secreto",
|
|
219
|
+
"field.secret.ph": "Pega el secreto",
|
|
220
|
+
"field.appId": "App ID",
|
|
221
|
+
"field.callbackToken": "Token de callback",
|
|
222
|
+
"field.encodingAESKey": "EncodingAESKey",
|
|
223
|
+
"field.corpId": "Corp ID",
|
|
224
|
+
"field.agentId": "Agent ID",
|
|
225
|
+
"field.phoneId": "Phone number ID",
|
|
226
|
+
"field.imapHost": "Servidor IMAP",
|
|
227
|
+
"field.imapPort": "Puerto IMAP",
|
|
228
|
+
"field.imapUser": "Cuenta de correo",
|
|
229
|
+
"field.imapPass": "Contrase\xF1a / contrase\xF1a de aplicaci\xF3n",
|
|
230
|
+
"field.smtpHost": "Servidor SMTP (vac\xEDo = reutilizar IMAP)",
|
|
231
|
+
"field.smtpPort": "Puerto SMTP",
|
|
232
|
+
"field.smtpUser": "Cuenta SMTP",
|
|
233
|
+
"field.smtpPass": "Contrase\xF1a SMTP / contrase\xF1a de aplicaci\xF3n",
|
|
234
|
+
"field.webhookSecret": "Secreto de firma (opcional)"
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
var locale = null;
|
|
238
|
+
var lang = "zh";
|
|
239
|
+
var revision = 0;
|
|
240
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
241
|
+
function notify() {
|
|
242
|
+
revision += 1;
|
|
243
|
+
for (const fn of listeners) fn();
|
|
244
|
+
}
|
|
245
|
+
function detectLang() {
|
|
246
|
+
const active = locale?.getLocale().active;
|
|
247
|
+
if (active === "zh") return "zh";
|
|
248
|
+
const nav = (navigator.language || "").toLowerCase();
|
|
249
|
+
if (nav.startsWith("es")) return "es";
|
|
250
|
+
if (active === "en") return "en";
|
|
251
|
+
if (nav.startsWith("zh")) return "zh";
|
|
252
|
+
return "zh";
|
|
253
|
+
}
|
|
254
|
+
function initI18n(service) {
|
|
255
|
+
if (locale === service) return;
|
|
256
|
+
locale = service;
|
|
257
|
+
lang = detectLang();
|
|
258
|
+
service.subscribe(() => {
|
|
259
|
+
const next = detectLang();
|
|
260
|
+
if (next !== lang) {
|
|
261
|
+
lang = next;
|
|
262
|
+
notify();
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
var subscribe = (fn) => {
|
|
267
|
+
listeners.add(fn);
|
|
268
|
+
return () => {
|
|
269
|
+
listeners.delete(fn);
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
var getSnapshot = () => revision;
|
|
273
|
+
function t(key) {
|
|
274
|
+
return DICTS[lang][key] ?? DICTS.zh[key] ?? key;
|
|
275
|
+
}
|
|
276
|
+
function useT() {
|
|
277
|
+
(0, import_react.useSyncExternalStore)(subscribe, getSnapshot);
|
|
278
|
+
return t;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// src/client/Page.tsx
|
|
282
|
+
var import_react2 = require("react");
|
|
283
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
284
|
+
var STYLE = `
|
|
285
|
+
.dsh-gw { --gw-fg:#24292f; --gw-muted:#6e7781; --gw-border:rgba(128,128,128,0.25);
|
|
286
|
+
--gw-hover:rgba(0,0,0,0.06); --gw-bg:#ffffff; --gw-panel:#f6f8fa; --gw-accent:#1976d2;
|
|
287
|
+
--gw-ok:#1a7f37; --gw-err:#cf222e; --gw-warn:#9a6700; position:fixed; inset:0; z-index:1200;
|
|
288
|
+
background:rgba(0,0,0,0.45); display:flex; align-items:center; justify-content:center;
|
|
289
|
+
color:var(--gw-fg); font-size:13px; font-family:-apple-system,BlinkMacSystemFont,
|
|
290
|
+
"Segoe UI","PingFang SC","Hiragino Sans GB","Microsoft YaHei",sans-serif; }
|
|
291
|
+
[data-ds-dark-theme] .dsh-gw { --gw-fg:#d1d9e0; --gw-muted:#9198a1; --gw-border:rgba(255,255,255,0.14);
|
|
292
|
+
--gw-hover:rgba(255,255,255,0.08); --gw-bg:#1f2328; --gw-panel:#161b22; --gw-accent:#58a6ff;
|
|
293
|
+
--gw-ok:#3fb950; --gw-err:#f85149; --gw-warn:#d4a72c; }
|
|
294
|
+
.dsh-gw * { box-sizing:border-box; }
|
|
295
|
+
.dsh-gw-page { width:min(1000px, 94vw); height:min(680px, 88vh); background:var(--gw-bg);
|
|
296
|
+
border:1px solid var(--gw-border); border-radius:14px; box-shadow:0 20px 60px rgba(0,0,0,0.35);
|
|
297
|
+
display:flex; flex-direction:column; overflow:hidden; }
|
|
298
|
+
.dsh-gw-head { display:flex; align-items:center; gap:8px; padding:14px 18px;
|
|
299
|
+
border-bottom:1px solid var(--gw-border); font-weight:600; font-size:15px; }
|
|
300
|
+
.dsh-gw-head .spacer { flex:1; }
|
|
301
|
+
.dsh-gw-close { border:none; background:transparent; color:var(--gw-muted); cursor:pointer;
|
|
302
|
+
width:30px; height:30px; border-radius:8px; display:flex; align-items:center;
|
|
303
|
+
justify-content:center; padding:0; }
|
|
304
|
+
.dsh-gw-close:hover { background:var(--gw-hover); color:var(--gw-fg); }
|
|
305
|
+
.dsh-gw-body { flex:1; display:flex; min-height:0; }
|
|
306
|
+
.dsh-gw-list { width:230px; flex:none; border-right:1px solid var(--gw-border);
|
|
307
|
+
overflow-y:auto; padding:8px; }
|
|
308
|
+
.dsh-gw-item { display:flex; align-items:center; gap:10px; padding:9px 10px; border-radius:8px;
|
|
309
|
+
cursor:pointer; }
|
|
310
|
+
.dsh-gw-item:hover { background:var(--gw-hover); }
|
|
311
|
+
.dsh-gw-item.active { background:var(--gw-hover); box-shadow:inset 0 0 0 1px var(--gw-border); }
|
|
312
|
+
.dsh-gw-item .icon { font-size:18px; flex:none; }
|
|
313
|
+
.dsh-gw-item .name { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis;
|
|
314
|
+
white-space:nowrap; }
|
|
315
|
+
.dsh-gw-item .dot { flex:none; width:8px; height:8px; border-radius:50%; }
|
|
316
|
+
.dsh-gw-item .dot.connected { background:var(--gw-ok); }
|
|
317
|
+
.dsh-gw-item .dot.error { background:var(--gw-err); }
|
|
318
|
+
.dsh-gw-item .dot.none { background:#8b949e; }
|
|
319
|
+
.dsh-gw-item .dot.manual { background:var(--gw-warn); }
|
|
320
|
+
.dsh-gw-item .st { font-size:10px; color:var(--gw-muted); flex:none; width:56px;
|
|
321
|
+
text-align:right; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
|
322
|
+
.dsh-gw-detail { flex:1; min-width:0; overflow-y:auto; padding:18px 22px; }
|
|
323
|
+
.dsh-gw-detail h3 { margin:0 0 4px; font-size:15px; display:flex; align-items:center; gap:8px; }
|
|
324
|
+
.dsh-gw-detail .hint { color:var(--gw-muted); font-size:12px; line-height:1.6; margin:4px 0 14px; }
|
|
325
|
+
.dsh-gw-status { display:inline-flex; align-items:center; gap:6px; padding:3px 10px;
|
|
326
|
+
border-radius:999px; font-size:11px; margin-bottom:14px; }
|
|
327
|
+
.dsh-gw-status.connected { background:rgba(26,127,55,0.12); color:var(--gw-ok); }
|
|
328
|
+
.dsh-gw-status.error { background:rgba(207,34,46,0.12); color:var(--gw-err); }
|
|
329
|
+
.dsh-gw-status.none { background:var(--gw-panel); color:var(--gw-muted); }
|
|
330
|
+
.dsh-gw-status.manual { background:rgba(154,103,0,0.12); color:var(--gw-warn); }
|
|
331
|
+
.dsh-gw-field { margin-bottom:12px; }
|
|
332
|
+
.dsh-gw-field label { display:block; font-size:12px; color:var(--gw-muted); margin-bottom:4px; }
|
|
333
|
+
.dsh-gw-input { width:100%; padding:8px 10px; font-size:13px; color:var(--gw-fg);
|
|
334
|
+
background:var(--gw-bg); border:1px solid var(--gw-border); border-radius:8px; outline:none; }
|
|
335
|
+
.dsh-gw-input:focus { border-color:var(--gw-accent); }
|
|
336
|
+
.dsh-gw-input.mono { font-family:ui-monospace,SFMono-Regular,Menlo,monospace; }
|
|
337
|
+
.dsh-gw-actions { display:flex; gap:8px; margin-top:16px; align-items:center; }
|
|
338
|
+
.dsh-gw-btn { border:1px solid var(--gw-border); background:transparent; color:var(--gw-fg);
|
|
339
|
+
border-radius:8px; padding:7px 14px; font-size:13px; cursor:pointer; }
|
|
340
|
+
.dsh-gw-btn:hover { background:var(--gw-hover); }
|
|
341
|
+
.dsh-gw-btn.primary { background:var(--gw-accent); border-color:var(--gw-accent); color:#fff; }
|
|
342
|
+
.dsh-gw-btn.danger { color:var(--gw-err); }
|
|
343
|
+
.dsh-gw-btn:disabled { opacity:0.5; cursor:default; }
|
|
344
|
+
.dsh-gw-msg { flex:1; font-size:12px; text-align:right; white-space:pre-wrap; word-break:break-all; }
|
|
345
|
+
.dsh-gw-msg.ok { color:var(--gw-ok); }
|
|
346
|
+
.dsh-gw-msg.err { color:var(--gw-err); }
|
|
347
|
+
.dsh-gw-detail-empty { color:var(--gw-muted); padding:40px; text-align:center; }
|
|
348
|
+
`;
|
|
349
|
+
var styleInjected = false;
|
|
350
|
+
function ensureStyle() {
|
|
351
|
+
if (styleInjected) return;
|
|
352
|
+
styleInjected = true;
|
|
353
|
+
const tag = document.createElement("style");
|
|
354
|
+
tag.dataset.plugin = "dsh-message-gateway";
|
|
355
|
+
tag.textContent = STYLE;
|
|
356
|
+
document.head.appendChild(tag);
|
|
357
|
+
}
|
|
358
|
+
function GatewayPage(props) {
|
|
359
|
+
const { api, onClose } = props;
|
|
360
|
+
const t2 = useT();
|
|
361
|
+
const [view, setView] = (0, import_react2.useState)(null);
|
|
362
|
+
const [selected, setSelected] = (0, import_react2.useState)("telegram");
|
|
363
|
+
const [form, setForm] = (0, import_react2.useState)({});
|
|
364
|
+
const [busy, setBusy] = (0, import_react2.useState)(false);
|
|
365
|
+
const [message, setMessage] = (0, import_react2.useState)(null);
|
|
366
|
+
const [testing, setTesting] = (0, import_react2.useState)(false);
|
|
367
|
+
const [testResult, setTestResult] = (0, import_react2.useState)(null);
|
|
368
|
+
const load = (0, import_react2.useCallback)(async () => {
|
|
369
|
+
const result = await api.list();
|
|
370
|
+
if (result.ok) {
|
|
371
|
+
setView(result.value);
|
|
372
|
+
} else {
|
|
373
|
+
setMessage({ text: result.error.message, kind: "err" });
|
|
374
|
+
}
|
|
375
|
+
}, [api]);
|
|
376
|
+
(0, import_react2.useEffect)(() => {
|
|
377
|
+
void load();
|
|
378
|
+
}, [load]);
|
|
379
|
+
(0, import_react2.useEffect)(() => {
|
|
380
|
+
const onKey = (event) => {
|
|
381
|
+
if (event.key === "Escape") onClose();
|
|
382
|
+
};
|
|
383
|
+
window.addEventListener("keydown", onKey);
|
|
384
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
385
|
+
}, [onClose]);
|
|
386
|
+
ensureStyle();
|
|
387
|
+
const statusOf = (id) => view?.status[id];
|
|
388
|
+
const defOf = (id) => view?.platforms.find((p) => p.id === id);
|
|
389
|
+
const select = (id) => {
|
|
390
|
+
setSelected(id);
|
|
391
|
+
setForm({});
|
|
392
|
+
setMessage(null);
|
|
393
|
+
setTestResult(null);
|
|
394
|
+
};
|
|
395
|
+
const save = async () => {
|
|
396
|
+
const def = defOf(selected);
|
|
397
|
+
if (def === void 0) return;
|
|
398
|
+
if (def.fields.length > 0 && def.fields.every((f) => (form[f.key] ?? "").trim() === "")) {
|
|
399
|
+
setMessage({ text: t2("field.token.ph"), kind: "err" });
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
setBusy(true);
|
|
403
|
+
setMessage(null);
|
|
404
|
+
const result = await api.save(selected, form);
|
|
405
|
+
setBusy(false);
|
|
406
|
+
if (result.ok) {
|
|
407
|
+
setView(result.value);
|
|
408
|
+
setMessage({ text: t2("gateway.saved"), kind: "ok" });
|
|
409
|
+
void runTest();
|
|
410
|
+
} else {
|
|
411
|
+
setMessage({ text: result.error.message, kind: "err" });
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
const runTest = async () => {
|
|
415
|
+
setTesting(true);
|
|
416
|
+
setTestResult(null);
|
|
417
|
+
const def = defOf(selected);
|
|
418
|
+
const result = await api.test(selected, def !== void 0 && def.fields.length > 0 ? form : void 0);
|
|
419
|
+
setTesting(false);
|
|
420
|
+
if (result.ok) {
|
|
421
|
+
setTestResult(result.value);
|
|
422
|
+
void load();
|
|
423
|
+
} else {
|
|
424
|
+
setTestResult({ ok: false, detail: result.error.message });
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
const remove = async () => {
|
|
428
|
+
setBusy(true);
|
|
429
|
+
setMessage(null);
|
|
430
|
+
const result = await api.delete(selected);
|
|
431
|
+
setBusy(false);
|
|
432
|
+
if (result.ok) {
|
|
433
|
+
setView(result.value);
|
|
434
|
+
setForm({});
|
|
435
|
+
setTestResult(null);
|
|
436
|
+
setMessage({ text: t2("gateway.deleted"), kind: "ok" });
|
|
437
|
+
} else {
|
|
438
|
+
setMessage({ text: result.error.message, kind: "err" });
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
const selectedDef = defOf(selected);
|
|
442
|
+
const selectedStatus = statusOf(selected);
|
|
443
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-gw", onClick: onClose, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-gw-page", onClick: (event) => event.stopPropagation(), children: [
|
|
444
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-gw-head", children: [
|
|
445
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
|
|
446
|
+
"\u{1F4EE} ",
|
|
447
|
+
t2("gateway.title")
|
|
448
|
+
] }),
|
|
449
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "spacer" }),
|
|
450
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "dsh-gw-close", title: t2("gateway.close"), onClick: onClose, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
451
|
+
"svg",
|
|
452
|
+
{
|
|
453
|
+
viewBox: "0 0 16 16",
|
|
454
|
+
width: "15",
|
|
455
|
+
height: "15",
|
|
456
|
+
fill: "none",
|
|
457
|
+
stroke: "currentColor",
|
|
458
|
+
strokeWidth: "1.6",
|
|
459
|
+
strokeLinecap: "round",
|
|
460
|
+
"aria-hidden": "true",
|
|
461
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3 3l10 10M13 3L3 13" })
|
|
462
|
+
}
|
|
463
|
+
) })
|
|
464
|
+
] }),
|
|
465
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-gw-body", children: [
|
|
466
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-gw-list", children: view === null ? null : view.platforms.map((def) => {
|
|
467
|
+
const st = view.status[def.id];
|
|
468
|
+
const state = st?.state ?? "none";
|
|
469
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
470
|
+
"div",
|
|
471
|
+
{
|
|
472
|
+
className: `dsh-gw-item${def.id === selected ? " active" : ""}`,
|
|
473
|
+
onClick: () => select(def.id),
|
|
474
|
+
children: [
|
|
475
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "icon", children: def.icon }),
|
|
476
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "name", children: t2(def.nameKey) }),
|
|
477
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: `dot ${state}` }),
|
|
478
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "st", children: t2(`gateway.status.${state}`) })
|
|
479
|
+
]
|
|
480
|
+
},
|
|
481
|
+
def.id
|
|
482
|
+
);
|
|
483
|
+
}) }),
|
|
484
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-gw-detail", children: selectedDef === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-gw-detail-empty", children: "\u2026" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
485
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("h3", { children: [
|
|
486
|
+
selectedDef.icon,
|
|
487
|
+
" ",
|
|
488
|
+
t2(selectedDef.nameKey)
|
|
489
|
+
] }),
|
|
490
|
+
selectedDef.hintKey !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "hint", children: t2(selectedDef.hintKey) }) : null,
|
|
491
|
+
selectedStatus !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: `dsh-gw-status ${selectedStatus.state}`, children: [
|
|
492
|
+
t2(`gateway.status.${selectedStatus.state}`),
|
|
493
|
+
selectedStatus.state === "connected" && selectedStatus.detail !== "" ? ` \xB7 ${selectedStatus.detail}` : "",
|
|
494
|
+
selectedStatus.state === "error" && selectedStatus.detail !== "" ? ` \xB7 ${selectedStatus.detail}` : ""
|
|
495
|
+
] }) : null,
|
|
496
|
+
selectedDef.fields.map((field) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-gw-field", children: [
|
|
497
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { children: t2(field.labelKey) }),
|
|
498
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
499
|
+
"input",
|
|
500
|
+
{
|
|
501
|
+
className: `dsh-gw-input mono`,
|
|
502
|
+
type: field.kind === "secret" ? "password" : field.kind === "number" ? "number" : "text",
|
|
503
|
+
value: form[field.key] ?? "",
|
|
504
|
+
placeholder: field.placeholderKey !== void 0 ? t2(field.placeholderKey) : "",
|
|
505
|
+
autoComplete: "off",
|
|
506
|
+
spellCheck: false,
|
|
507
|
+
onChange: (event) => setForm((prev) => ({ ...prev, [field.key]: event.target.value }))
|
|
508
|
+
}
|
|
509
|
+
)
|
|
510
|
+
] }, field.key)),
|
|
511
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-gw-actions", children: [
|
|
512
|
+
selectedDef.fields.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
513
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
514
|
+
"button",
|
|
515
|
+
{
|
|
516
|
+
type: "button",
|
|
517
|
+
className: "dsh-gw-btn primary",
|
|
518
|
+
disabled: busy,
|
|
519
|
+
onClick: () => void save(),
|
|
520
|
+
children: t2("gateway.save")
|
|
521
|
+
}
|
|
522
|
+
),
|
|
523
|
+
selectedDef.testable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
524
|
+
"button",
|
|
525
|
+
{
|
|
526
|
+
type: "button",
|
|
527
|
+
className: "dsh-gw-btn",
|
|
528
|
+
disabled: busy || testing,
|
|
529
|
+
onClick: () => void runTest(),
|
|
530
|
+
children: testing ? t2("gateway.testing") : t2("gateway.test")
|
|
531
|
+
}
|
|
532
|
+
) : null,
|
|
533
|
+
selectedStatus?.configured === true ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
534
|
+
"button",
|
|
535
|
+
{
|
|
536
|
+
type: "button",
|
|
537
|
+
className: "dsh-gw-btn danger",
|
|
538
|
+
disabled: busy,
|
|
539
|
+
onClick: () => void remove(),
|
|
540
|
+
children: t2("gateway.delete")
|
|
541
|
+
}
|
|
542
|
+
) : null
|
|
543
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "hint", children: t2(selectedDef.hintKey ?? "") }),
|
|
544
|
+
message !== null ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: `dsh-gw-msg ${message.kind}`, children: message.text }) : null
|
|
545
|
+
] }),
|
|
546
|
+
testResult !== null ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-gw-field", style: { marginTop: 14 }, children: [
|
|
547
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { children: t2("gateway.testing.result") }),
|
|
548
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
549
|
+
"div",
|
|
550
|
+
{
|
|
551
|
+
className: `dsh-gw-msg ${testResult.ok ? "ok" : "err"}`,
|
|
552
|
+
style: { textAlign: "left" },
|
|
553
|
+
children: testResult.detail
|
|
554
|
+
}
|
|
555
|
+
)
|
|
556
|
+
] }) : null
|
|
557
|
+
] }) })
|
|
558
|
+
] })
|
|
559
|
+
] }) });
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// src/client/index.ts
|
|
563
|
+
var inject = ["locale"];
|
|
564
|
+
var NEW_SESSION_SELECTOR = '[class*="newSession"]';
|
|
565
|
+
var BUTTON_STYLE = `
|
|
566
|
+
.dsh-gw-open { display:flex; align-items:center; gap:8px; width:100%; padding:8px 12px;
|
|
567
|
+
border:none; background:transparent; color:var(--dsh-git-panel-fg, #24292f); cursor:pointer;
|
|
568
|
+
font-size:12px; font-weight:500; border-radius:8px; }
|
|
569
|
+
.dsh-gw-open:hover { background:rgba(128,128,128,0.1); }
|
|
570
|
+
.dsh-gw-open .icon { font-size:15px; flex:none; }
|
|
571
|
+
.dsh-gw-open .label { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis;
|
|
572
|
+
white-space:nowrap; text-align:left; }
|
|
573
|
+
`;
|
|
574
|
+
var styleInjected2 = false;
|
|
575
|
+
function ensureButtonStyle() {
|
|
576
|
+
if (styleInjected2) return;
|
|
577
|
+
styleInjected2 = true;
|
|
578
|
+
const tag = document.createElement("style");
|
|
579
|
+
tag.dataset.plugin = "dsh-message-gateway-btn";
|
|
580
|
+
tag.textContent = BUTTON_STYLE;
|
|
581
|
+
document.head.appendChild(tag);
|
|
582
|
+
}
|
|
583
|
+
function GatewayApp(props) {
|
|
584
|
+
const { api } = props;
|
|
585
|
+
const t2 = useT();
|
|
586
|
+
const [open, setOpen] = (0, import_react3.useState)(false);
|
|
587
|
+
const close = (0, import_react3.useCallback)(() => setOpen(false), []);
|
|
588
|
+
ensureButtonStyle();
|
|
589
|
+
return (0, import_react3.createElement)(
|
|
590
|
+
"div",
|
|
591
|
+
null,
|
|
592
|
+
(0, import_react3.createElement)(
|
|
593
|
+
"button",
|
|
594
|
+
{ type: "button", className: "dsh-gw-open", title: t2("gateway.open"), onClick: () => setOpen(true) },
|
|
595
|
+
(0, import_react3.createElement)("span", { className: "icon" }, "\u{1F4EE}"),
|
|
596
|
+
(0, import_react3.createElement)("span", { className: "label" }, t2("gateway.title"))
|
|
597
|
+
),
|
|
598
|
+
open ? (0, import_react3.createElement)(GatewayPage, { api, onClose: close }) : null
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
function apply(ctx) {
|
|
602
|
+
try {
|
|
603
|
+
initI18n(ctx.locale);
|
|
604
|
+
} catch (error) {
|
|
605
|
+
console.error("dsh-message-gateway: i18n init failed (falling back to Chinese)", error);
|
|
606
|
+
}
|
|
607
|
+
ctx.effect(() => {
|
|
608
|
+
const host = document.createElement("div");
|
|
609
|
+
host.dataset.gatewayHost = "";
|
|
610
|
+
const root = (0, import_client.createRoot)(host);
|
|
611
|
+
const api = new GatewayApi();
|
|
612
|
+
let disposed = false;
|
|
613
|
+
const render = () => {
|
|
614
|
+
if (disposed) return;
|
|
615
|
+
root.render((0, import_react3.createElement)(GatewayApp, { api }));
|
|
616
|
+
};
|
|
617
|
+
let raf = 0;
|
|
618
|
+
let polling = true;
|
|
619
|
+
const poll = () => {
|
|
620
|
+
if (disposed || !polling) return;
|
|
621
|
+
if (!host.isConnected) {
|
|
622
|
+
const btn = document.querySelector(NEW_SESSION_SELECTOR);
|
|
623
|
+
if (btn !== null && btn.parentElement !== null) {
|
|
624
|
+
btn.after(host);
|
|
625
|
+
render();
|
|
626
|
+
polling = false;
|
|
627
|
+
console.debug("[dsh-message-gateway] mounted after newSession");
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
} else {
|
|
631
|
+
polling = false;
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
raf = requestAnimationFrame(poll);
|
|
635
|
+
};
|
|
636
|
+
raf = requestAnimationFrame(poll);
|
|
637
|
+
const fallback = window.setInterval(() => {
|
|
638
|
+
if (disposed) return;
|
|
639
|
+
if (!host.isConnected) {
|
|
640
|
+
polling = true;
|
|
641
|
+
raf = requestAnimationFrame(poll);
|
|
642
|
+
}
|
|
643
|
+
}, 5e3);
|
|
644
|
+
return () => {
|
|
645
|
+
disposed = true;
|
|
646
|
+
cancelAnimationFrame(raf);
|
|
647
|
+
window.clearInterval(fallback);
|
|
648
|
+
try {
|
|
649
|
+
root.unmount();
|
|
650
|
+
} catch {
|
|
651
|
+
}
|
|
652
|
+
host.remove();
|
|
653
|
+
};
|
|
654
|
+
}, "dsh-message-gateway: mount");
|
|
655
|
+
}
|
|
656
|
+
var index_default = { apply, inject };
|
|
657
|
+
return module.exports;
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
//# sourceMappingURL=client.js.map
|