@shliamb/dsh-telegram-bot 0.0.0-stage → 0.2.1

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/lib/client.js ADDED
@@ -0,0 +1,275 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "@shliamb/dsh-telegram-bot",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
+ let react = require("react");
8
+ let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
9
+ let react_jsx_runtime = require("react/jsx-runtime");
10
+ // src/client/locales.ts
11
+ /** Settings-page copy for the Telegram bridge bundle. */
12
+ const NS = "settings.telegramBot";
13
+ const ru = {
14
+ intro: "Токен бота хранится в защищённом хранилище DSH и никогда не показывается на странице. ID администратора — в настройках плагина.",
15
+ token: "Токен бота",
16
+ tokenHint: "Вставь новый токен, чтобы заменить сохранённый. Пустое поле оставляет текущий.",
17
+ tokenConfigured: "настроен",
18
+ tokenMissing: "не настроен",
19
+ admin: "Твой Telegram ID",
20
+ adminHint: "Числовой ID аккаунта Telegram, с которого можно управлять ботом.",
21
+ adminPlaceholder: "например, 123456789",
22
+ configure: "Настроить",
23
+ save: "Сохранить",
24
+ saving: "Сохраняю…",
25
+ saved: "Сохранено. Бот перезапускает подключение.",
26
+ invalidAdmin: "ID должен быть положительным целым числом.",
27
+ saveFailed: "Не удалось сохранить. Попробуй ещё раз.",
28
+ unavailable: "Настройки плагина сейчас недоступны.",
29
+ loading: "Загружаю настройки…"
30
+ };
31
+ const en = {
32
+ intro: "The bot token is stored in credentials and is never shown on this page. The admin Telegram ID is part of the plugin settings.",
33
+ token: "Bot token",
34
+ tokenHint: "Paste a new token to replace the stored one. An empty field keeps the current token.",
35
+ tokenConfigured: "configured",
36
+ tokenMissing: "not configured",
37
+ admin: "Your Telegram ID",
38
+ adminHint: "Numeric Telegram account ID allowed to control the bot.",
39
+ adminPlaceholder: "for example, 123456789",
40
+ configure: "Configure",
41
+ save: "Save",
42
+ saving: "Saving…",
43
+ saved: "Saved. The bot is reconnecting.",
44
+ invalidAdmin: "The ID must be a positive integer.",
45
+ saveFailed: "Could not save. Please retry.",
46
+ unavailable: "Plugin settings are unavailable right now.",
47
+ loading: "Loading settings…"
48
+ };
49
+ // src/client/index.tsx
50
+ /** Browser settings page for the Telegram bridge bundle. */
51
+ const TOKEN_REF = "DSH_TELEGRAM_BOT_TOKEN";
52
+ const CONFIG_NS = "telegram-bot";
53
+ /** Head action on the bundle page: jump to the configuration block at its bottom. */
54
+ function TelegramConfigureAction(props) {
55
+ if (props.subject?.kind !== "bundle" || props.subject.pkg?.name !== "@shliamb/dsh-telegram-bot") return null;
56
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
57
+ variant: "outline",
58
+ onClick: () => {
59
+ document.querySelector("[data-plugin-config]")?.scrollIntoView({
60
+ behavior: "smooth",
61
+ block: "start"
62
+ });
63
+ },
64
+ children: props.t("configure")
65
+ });
66
+ }
67
+ /** Render the token + admin ID form inside the plugin's Plugins-tab detail page. */
68
+ function TelegramSettings(props) {
69
+ const { ctx, configForm, t } = props;
70
+ if (props.view !== void 0 && props.view !== "page") return null;
71
+ const tokenId = (0, react.useId)();
72
+ const adminId = (0, react.useId)();
73
+ const snapshot = (0, react.useSyncExternalStore)((listener) => configForm.subscribe(listener), () => configForm.getSnapshot());
74
+ const currentAdmin = snapshot.value?.adminUserId;
75
+ const [adminDraft, setAdminDraft] = (0, react.useState)(currentAdmin === void 0 ? "" : String(currentAdmin));
76
+ const [tokenDraft, setTokenDraft] = (0, react.useState)("");
77
+ const [credential, setCredential] = (0, react.useState)(void 0);
78
+ const [busy, setBusy] = (0, react.useState)(false);
79
+ const [notice, setNotice] = (0, react.useState)(void 0);
80
+ (0, react.useEffect)(() => {
81
+ setAdminDraft(currentAdmin === void 0 ? "" : String(currentAdmin));
82
+ }, [currentAdmin]);
83
+ (0, react.useEffect)(() => {
84
+ let disposed = false;
85
+ let sequence = 0;
86
+ const refresh = async () => {
87
+ const current = ++sequence;
88
+ try {
89
+ const result = await ctx.remote.credentials.describe([TOKEN_REF]);
90
+ if (disposed || current !== sequence) return;
91
+ if (result.ok) setCredential(result.value[TOKEN_REF]);
92
+ else setNotice(t("saveFailed"));
93
+ } catch {
94
+ if (!disposed && current === sequence) setNotice(t("saveFailed"));
95
+ }
96
+ };
97
+ refresh();
98
+ const off = ctx.remote.$on("credentials/reference-updated", (ref) => {
99
+ if (ref === TOKEN_REF) refresh();
100
+ });
101
+ return () => {
102
+ disposed = true;
103
+ off();
104
+ };
105
+ }, [ctx, t]);
106
+ const unavailable = snapshot.status === "unavailable";
107
+ const loading = snapshot.status === "loading";
108
+ const tokenWritable = credential?.writable !== false;
109
+ const adminWritable = snapshot.writable !== false;
110
+ const tokenDisabled = busy || !tokenWritable;
111
+ const adminDisabled = busy || loading || unavailable || !adminWritable;
112
+ const save = async () => {
113
+ const adminText = adminDraft.trim();
114
+ let admin;
115
+ if (adminText.length > 0) {
116
+ admin = Number(adminText);
117
+ if (!Number.isSafeInteger(admin) || admin <= 0) {
118
+ setNotice(t("invalidAdmin"));
119
+ return;
120
+ }
121
+ }
122
+ const token = tokenDraft.trim();
123
+ setBusy(true);
124
+ setNotice(void 0);
125
+ try {
126
+ if (token.length > 0 && tokenWritable) {
127
+ if (!(await ctx.remote.credentials.set(TOKEN_REF, token)).ok) {
128
+ setNotice(t("saveFailed"));
129
+ return;
130
+ }
131
+ setTokenDraft("");
132
+ setCredential({
133
+ configured: true,
134
+ writable: true
135
+ });
136
+ }
137
+ if (admin !== void 0 && admin !== currentAdmin) {
138
+ if (!await configForm.set("adminUserId", admin)) {
139
+ setNotice(t("saveFailed"));
140
+ return;
141
+ }
142
+ }
143
+ setNotice(t("saved"));
144
+ } catch (error) {
145
+ ctx.logger.warn(`telegram-bot settings save failed: ${String(error)}`);
146
+ setNotice(t("saveFailed"));
147
+ } finally {
148
+ setBusy(false);
149
+ }
150
+ };
151
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
152
+ style: {
153
+ display: "grid",
154
+ gap: "16px",
155
+ maxWidth: "640px"
156
+ },
157
+ children: [
158
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
159
+ style: {
160
+ margin: 0,
161
+ opacity: .78
162
+ },
163
+ children: t("intro")
164
+ }),
165
+ loading ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
166
+ style: {
167
+ margin: 0,
168
+ opacity: .7
169
+ },
170
+ children: t("loading")
171
+ }) : null,
172
+ unavailable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
173
+ style: {
174
+ margin: 0,
175
+ color: "var(--dsh-color-danger, #d9534f)"
176
+ },
177
+ children: t("unavailable")
178
+ }) : null,
179
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.SettingsSecretField, {
180
+ id: tokenId,
181
+ label: t("token"),
182
+ hint: t("tokenHint"),
183
+ text: tokenDraft,
184
+ configured: credential?.configured === true,
185
+ stateLabel: credential?.configured === true ? t("tokenConfigured") : t("tokenMissing"),
186
+ disabled: tokenDisabled,
187
+ onEdit: setTokenDraft
188
+ }),
189
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.SettingsValueField, {
190
+ id: adminId,
191
+ label: t("admin"),
192
+ hint: t("adminHint"),
193
+ placeholder: t("adminPlaceholder"),
194
+ numeric: true,
195
+ text: adminDraft,
196
+ overridden: false,
197
+ invalid: false,
198
+ overriddenLabel: "",
199
+ resetLabel: "",
200
+ invalidLabel: t("invalidAdmin"),
201
+ disabled: adminDisabled,
202
+ onEdit: setAdminDraft,
203
+ onReset: () => {
204
+ setAdminDraft("");
205
+ }
206
+ }),
207
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
208
+ variant: "primary",
209
+ disabled: busy,
210
+ onClick: () => {
211
+ save();
212
+ },
213
+ children: busy ? t("saving") : t("save")
214
+ }) }),
215
+ notice === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
216
+ role: "status",
217
+ style: {
218
+ margin: 0,
219
+ opacity: .85
220
+ },
221
+ children: notice
222
+ })
223
+ ]
224
+ });
225
+ }
226
+ /** Client plugin name. */
227
+ const name = "telegram-bot-settings";
228
+ /** Services needed to mount the Plugins-tab configuration page. */
229
+ const inject = [
230
+ "slots",
231
+ "locale",
232
+ "remote",
233
+ "remote.credentials",
234
+ "configForms"
235
+ ];
236
+ /** Register the browser page for the bundle's Plugins-tab detail view. */
237
+ function apply(ctx) {
238
+ const t = ctx.locale.bind(NS);
239
+ ctx.effect(() => ctx.locale.register(NS, {
240
+ ru,
241
+ en
242
+ }), "telegram-bot settings locale");
243
+ const form = ctx.configForms.get(CONFIG_NS);
244
+ const inject = () => ({
245
+ ctx,
246
+ configForm: form,
247
+ t
248
+ });
249
+ ctx.effect(() => ctx.slots.inject("plugins.bundle.config", () => ctx.slots.register({
250
+ name: "plugins.bundle.config",
251
+ key: "@shliamb/dsh-telegram-bot",
252
+ locale: NS,
253
+ inject
254
+ }, TelegramSettings)), "telegram-bot bundle settings");
255
+ ctx.effect(() => ctx.slots.inject("plugins.row.config", () => ctx.slots.register({
256
+ name: "plugins.row.config",
257
+ key: "@shliamb/dsh-telegram-bot#telegram-bot",
258
+ locale: NS,
259
+ inject
260
+ }, TelegramSettings)), "telegram-bot row settings");
261
+ ctx.effect(() => ctx.slots.inject("plugins.detail.actions", () => ctx.slots.register({
262
+ name: "plugins.detail.actions",
263
+ id: "telegram-bot-configure",
264
+ order: 10,
265
+ locale: NS
266
+ }, TelegramConfigureAction)), "telegram-bot configure action");
267
+ }
268
+ exports.apply = apply;
269
+ exports.inject = inject;
270
+ exports.name = name;
271
+ return module.exports;
272
+ }
273
+ });
274
+
275
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","names":["Button","useId","useSyncExternalStore","useState","SettingsSecretField","SettingsValueField"],"sources":["../src/client/locales.ts","../src/client/index.tsx"],"sourcesContent":["/** Settings-page copy for the Telegram bridge bundle. */\n\nexport const NS = 'settings.telegramBot'\n\nexport const ru = {\n intro: 'Токен бота хранится в защищённом хранилище DSH и никогда не показывается на странице. ID администратора — в настройках плагина.',\n token: 'Токен бота',\n tokenHint: 'Вставь новый токен, чтобы заменить сохранённый. Пустое поле оставляет текущий.',\n tokenConfigured: 'настроен',\n tokenMissing: 'не настроен',\n admin: 'Твой Telegram ID',\n adminHint: 'Числовой ID аккаунта Telegram, с которого можно управлять ботом.',\n adminPlaceholder: 'например, 123456789',\n configure: 'Настроить',\n save: 'Сохранить',\n saving: 'Сохраняю…',\n saved: 'Сохранено. Бот перезапускает подключение.',\n invalidAdmin: 'ID должен быть положительным целым числом.',\n saveFailed: 'Не удалось сохранить. Попробуй ещё раз.',\n unavailable: 'Настройки плагина сейчас недоступны.',\n loading: 'Загружаю настройки…',\n} as const\n\nexport const en = {\n intro: 'The bot token is stored in credentials and is never shown on this page. The admin Telegram ID is part of the plugin settings.',\n token: 'Bot token',\n tokenHint: 'Paste a new token to replace the stored one. An empty field keeps the current token.',\n tokenConfigured: 'configured',\n tokenMissing: 'not configured',\n admin: 'Your Telegram ID',\n adminHint: 'Numeric Telegram account ID allowed to control the bot.',\n adminPlaceholder: 'for example, 123456789',\n configure: 'Configure',\n save: 'Save',\n saving: 'Saving…',\n saved: 'Saved. The bot is reconnecting.',\n invalidAdmin: 'The ID must be a positive integer.',\n saveFailed: 'Could not save. Please retry.',\n unavailable: 'Plugin settings are unavailable right now.',\n loading: 'Loading settings…',\n} as const\n\nexport type TelegramSettingsLocaleKey = keyof typeof ru\n","/** Browser settings page for the Telegram bridge bundle. */\nimport { useEffect, useId, useState, useSyncExternalStore, type ReactElement } from 'react'\nimport { Button, SettingsSecretField, SettingsValueField } from '@deepseek-ai/dsh-client-ui-primitives'\nimport { NS, en, ru } from './locales.ts'\n\nconst TOKEN_REF = 'DSH_TELEGRAM_BOT_TOKEN'\nconst CONFIG_NS = 'telegram-bot'\n\ninterface RemoteFailure {\n readonly message?: string\n}\n\ntype RemoteResult<T> = { readonly ok: true; readonly value: T } | { readonly ok: false; readonly error?: RemoteFailure }\n\ninterface CredentialView {\n readonly configured: boolean\n readonly writable: boolean\n}\n\ninterface CredentialsRemote {\n describe(refs: string[]): Promise<RemoteResult<Record<string, CredentialView>>>\n set(ref: string, value: string): Promise<RemoteResult<void>>\n unset(ref: string): Promise<RemoteResult<void>>\n}\n\ninterface TelegramConfig {\n readonly adminUserId?: number\n}\n\ninterface ConfigSnapshot<T> {\n readonly status: 'loading' | 'ready' | 'unavailable'\n readonly value: T | undefined\n readonly writable: boolean\n}\n\ninterface ConfigForm<T> {\n getSnapshot(): ConfigSnapshot<T>\n subscribe(listener: () => void): () => void\n set(field: string, value: unknown): Promise<boolean>\n unset(field: string): Promise<boolean>\n}\n\ninterface ClientContext {\n readonly slots: {\n inject(name: string, register: () => () => void): () => void\n register(\n options: Record<string, unknown>,\n component: (props: any) => ReactElement | null,\n ): () => void\n }\n readonly locale: {\n register(namespace: string, dictionaries: Record<string, Record<string, string>>): () => void\n bind(namespace: string): (key: string) => string\n }\n readonly remote: {\n readonly credentials: CredentialsRemote\n $on(event: 'credentials/reference-updated', listener: (ref: string) => void): () => void\n }\n readonly configForms: {\n get<T>(namespace: string): ConfigForm<T>\n }\n effect(create: () => void | (() => void), label?: string): unknown\n readonly logger: {\n warn(message: string): void\n }\n}\n\nexport interface TelegramSettingsProps {\n readonly view?: 'summary' | 'page'\n readonly ctx: ClientContext\n readonly configForm: ConfigForm<TelegramConfig>\n readonly t: (key: string) => string\n}\n\ninterface PluginDetailSubject {\n readonly kind?: string\n readonly pkg?: { readonly name?: string }\n}\n\ninterface TelegramConfigureActionProps {\n readonly subject?: PluginDetailSubject\n readonly t: (key: string) => string\n}\n\n/** Head action on the bundle page: jump to the configuration block at its bottom. */\nfunction TelegramConfigureAction(props: TelegramConfigureActionProps): ReactElement | null {\n if (props.subject?.kind !== 'bundle' || props.subject.pkg?.name !== '@shliamb/dsh-telegram-bot') return null\n return (\n <Button\n variant=\"outline\"\n onClick={() => {\n document.querySelector('[data-plugin-config]')?.scrollIntoView({ behavior: 'smooth', block: 'start' })\n }}\n >\n {props.t('configure')}\n </Button>\n )\n}\n\n/** Render the token + admin ID form inside the plugin's Plugins-tab detail page. */\nfunction TelegramSettings(props: TelegramSettingsProps): ReactElement | null {\n const { ctx, configForm, t } = props\n if (props.view !== undefined && props.view !== 'page') return null\n const tokenId = useId()\n const adminId = useId()\n const snapshot = useSyncExternalStore(\n listener => configForm.subscribe(listener),\n () => configForm.getSnapshot(),\n )\n const currentAdmin = snapshot.value?.adminUserId\n const [adminDraft, setAdminDraft] = useState(currentAdmin === undefined ? '' : String(currentAdmin))\n const [tokenDraft, setTokenDraft] = useState('')\n const [credential, setCredential] = useState<CredentialView | undefined>(undefined)\n const [busy, setBusy] = useState(false)\n const [notice, setNotice] = useState<string | undefined>(undefined)\n\n useEffect(() => {\n setAdminDraft(currentAdmin === undefined ? '' : String(currentAdmin))\n }, [currentAdmin])\n\n useEffect(() => {\n let disposed = false\n let sequence = 0\n const refresh = async (): Promise<void> => {\n const current = ++sequence\n try {\n const result = await ctx.remote.credentials.describe([TOKEN_REF])\n if (disposed || current !== sequence) return\n if (result.ok) setCredential(result.value[TOKEN_REF])\n else setNotice(t('saveFailed'))\n } catch {\n if (!disposed && current === sequence) setNotice(t('saveFailed'))\n }\n }\n void refresh()\n const off = ctx.remote.$on('credentials/reference-updated', ref => {\n if (ref === TOKEN_REF) void refresh()\n })\n return () => {\n disposed = true\n off()\n }\n }, [ctx, t])\n\n const unavailable = snapshot.status === 'unavailable'\n const loading = snapshot.status === 'loading'\n const tokenWritable = credential?.writable !== false\n const adminWritable = snapshot.writable !== false\n const tokenDisabled = busy || !tokenWritable\n const adminDisabled = busy || loading || unavailable || !adminWritable\n\n const save = async (): Promise<void> => {\n const adminText = adminDraft.trim()\n let admin: number | undefined\n if (adminText.length > 0) {\n admin = Number(adminText)\n if (!Number.isSafeInteger(admin) || admin <= 0) {\n setNotice(t('invalidAdmin'))\n return\n }\n }\n const token = tokenDraft.trim()\n setBusy(true)\n setNotice(undefined)\n try {\n if (token.length > 0 && tokenWritable) {\n const result = await ctx.remote.credentials.set(TOKEN_REF, token)\n if (!result.ok) {\n setNotice(t('saveFailed'))\n return\n }\n setTokenDraft('')\n setCredential({ configured: true, writable: true })\n }\n if (admin !== undefined && admin !== currentAdmin) {\n if (!await configForm.set('adminUserId', admin)) {\n setNotice(t('saveFailed'))\n return\n }\n }\n setNotice(t('saved'))\n } catch (error) {\n ctx.logger.warn(`telegram-bot settings save failed: ${String(error)}`)\n setNotice(t('saveFailed'))\n } finally {\n setBusy(false)\n }\n }\n\n return (\n <div style={{ display: 'grid', gap: '16px', maxWidth: '640px' }}>\n <p style={{ margin: 0, opacity: 0.78 }}>{t('intro')}</p>\n {loading ? <p style={{ margin: 0, opacity: 0.7 }}>{t('loading')}</p> : null}\n {unavailable ? <p style={{ margin: 0, color: 'var(--dsh-color-danger, #d9534f)' }}>{t('unavailable')}</p> : null}\n <SettingsSecretField\n id={tokenId}\n label={t('token')}\n hint={t('tokenHint')}\n text={tokenDraft}\n configured={credential?.configured === true}\n stateLabel={credential?.configured === true ? t('tokenConfigured') : t('tokenMissing')}\n disabled={tokenDisabled}\n onEdit={setTokenDraft}\n />\n <SettingsValueField\n id={adminId}\n label={t('admin')}\n hint={t('adminHint')}\n placeholder={t('adminPlaceholder')}\n numeric\n text={adminDraft}\n overridden={false}\n invalid={false}\n overriddenLabel=\"\"\n resetLabel=\"\"\n invalidLabel={t('invalidAdmin')}\n disabled={adminDisabled}\n onEdit={setAdminDraft}\n onReset={() => { setAdminDraft('') }}\n />\n <div>\n <Button variant=\"primary\" disabled={busy} onClick={() => { void save() }}>\n {busy ? t('saving') : t('save')}\n </Button>\n </div>\n {notice === undefined ? null : <p role=\"status\" style={{ margin: 0, opacity: 0.85 }}>{notice}</p>}\n </div>\n )\n}\n\n/** Client plugin name. */\nexport const name = 'telegram-bot-settings'\n\n/** Services needed to mount the Plugins-tab configuration page. */\nexport const inject = ['slots', 'locale', 'remote', 'remote.credentials', 'configForms']\n\n/** Register the browser page for the bundle's Plugins-tab detail view. */\nexport function apply(ctx: ClientContext): void {\n const t = ctx.locale.bind(NS)\n ctx.effect(() => ctx.locale.register(NS, { ru, en }), 'telegram-bot settings locale')\n const form = ctx.configForms.get<TelegramConfig>(CONFIG_NS)\n const inject = (): { ctx: ClientContext; configForm: ConfigForm<TelegramConfig>; t: (key: string) => string } => ({ ctx, configForm: form, t })\n // Bundle-level section plus a row-level configure page: the latter is the\n // discoverable gear on the `telegram-bot` row and opens the form alone,\n // without the README above it.\n ctx.effect(() => ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({\n name: 'plugins.bundle.config',\n key: '@shliamb/dsh-telegram-bot',\n locale: NS,\n inject,\n }, TelegramSettings)), 'telegram-bot bundle settings')\n ctx.effect(() => ctx.slots.inject('plugins.row.config', () => ctx.slots.register({\n name: 'plugins.row.config',\n key: '@shliamb/dsh-telegram-bot#telegram-bot',\n locale: NS,\n inject,\n }, TelegramSettings)), 'telegram-bot row settings')\n ctx.effect(() => ctx.slots.inject('plugins.detail.actions', () => ctx.slots.register({\n name: 'plugins.detail.actions',\n id: 'telegram-bot-configure',\n order: 10,\n locale: NS,\n }, TelegramConfigureAction)), 'telegram-bot configure action')\n}\n"],"mappings":";;;;;;;;;;;EAEA,MAAa,KAAK;EAElB,MAAa,KAAK;GAChB,OAAO;GACP,OAAO;GACP,WAAW;GACX,iBAAiB;GACjB,cAAc;GACd,OAAO;GACP,WAAW;GACX,kBAAkB;GAClB,WAAW;GACX,MAA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+BAA+B,IAAI,MAAM,SAAS;IAClF,MAAM;IACN,KAAK;IACL,QAAQ;IACR;GACF,GAAG,gBAAgB,CAAC,GAAG,8BAA8B;GACrD,IAAI,aAAa,IAAI,MAAM,OAAO,4BAA4B,IAAI,MAAM,SAAS;IAC/E,MAAM;IACN,KAAK;IACL,QAAQ;IACR;GACF,GAAG,gBAAgB,CAAC,GAAG,2BAA2B;GAClD,IAAI,aAAa,IAAI,MAAM,OAAO,gCAAgC,IAAI,MAAM,SAAS;IACnF,MAAM;IACN,IAAI;IACJ,OAAO;IACP,QAAQ;GACV,GAAG,uBAAuB,CAAC,GAAG,+BAA+B;EAC/D"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,106 @@
1
+ /**
2
+ * @shliamb/dsh-telegram-bot — Telegram bridge for DeepSeek Harness.
3
+ *
4
+ * Telegram workspace picker, text prompts into the selected DSH Session, one
5
+ * edited progress message per Turn, and plain final text. All Host services
6
+ * are described locally; no DSH package is imported at runtime.
7
+ */
8
+ import z from '@deepseek-ai/schemastery';
9
+ export declare const name = "telegram-bot";
10
+ export declare const inject: string[];
11
+ interface Agent {
12
+ readonly status: 'idle' | 'running';
13
+ readonly session: {
14
+ readonly id: string;
15
+ };
16
+ readonly ctx: {
17
+ get(name: string): unknown;
18
+ };
19
+ cancel(cause: {
20
+ kind: 'user';
21
+ }): void;
22
+ }
23
+ type ApprovalOutcome = 'allowed-once' | 'rejected' | 'cancelled' | 'unavailable';
24
+ interface ApprovalRequest {
25
+ readonly agent: Agent;
26
+ readonly toolName: string;
27
+ readonly callId?: string;
28
+ readonly reason?: string;
29
+ readonly signal?: AbortSignal;
30
+ }
31
+ interface AskQuestionOption {
32
+ readonly label: string;
33
+ readonly description?: string;
34
+ }
35
+ interface AskQuestionItem {
36
+ readonly id: string;
37
+ readonly question: string;
38
+ readonly detail?: string;
39
+ readonly header?: string;
40
+ readonly options?: readonly AskQuestionOption[];
41
+ readonly multiSelect?: boolean;
42
+ }
43
+ interface AskQuestionRequest {
44
+ readonly questions: readonly AskQuestionItem[];
45
+ readonly agent?: Agent;
46
+ readonly signal?: AbortSignal;
47
+ readonly wait?: unknown;
48
+ }
49
+ interface AskQuestionAnswerItem {
50
+ readonly id: string;
51
+ readonly selected: string[];
52
+ readonly custom?: string;
53
+ }
54
+ interface AskQuestionAnswer {
55
+ readonly answers: AskQuestionAnswerItem[];
56
+ }
57
+ interface Logger {
58
+ info(message: string): void;
59
+ warn(message: string): void;
60
+ error(message: string): void;
61
+ }
62
+ interface DshSession {
63
+ readonly id: string;
64
+ readonly header: {
65
+ readonly origin?: 'subagent';
66
+ readonly cwd?: string;
67
+ };
68
+ }
69
+ interface DshSessionEvent {
70
+ readonly type: string;
71
+ readonly data: Record<string, unknown>;
72
+ }
73
+ interface HarnessContext {
74
+ readonly logger: Logger;
75
+ get(name: string): unknown;
76
+ effect(create: () => void | (() => void | Promise<void>)): unknown;
77
+ on(event: 'session/event', listener: (session: DshSession, event: DshSessionEvent) => void): () => void;
78
+ on(event: 'credentials/reference-updated', listener: (ref: string) => void): () => void;
79
+ on(event: 'settings/document-updated', listener: (namespace: string, revision: number) => void): () => void;
80
+ on(event: 'approval/request', listener: (request: ApprovalRequest, next: () => Promise<ApprovalOutcome>) => Promise<ApprovalOutcome>): () => void;
81
+ on(event: 'user-questions/request', listener: (request: AskQuestionRequest, next: () => Promise<AskQuestionAnswer>) => Promise<AskQuestionAnswer>): () => void;
82
+ }
83
+ /**
84
+ * Loader/settings schema. Only `adminUserId` is volatile: it is the one field
85
+ * the Telegram settings page reads back. The bot token lives in credentials and
86
+ * never rides a settings response.
87
+ */
88
+ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
89
+ adminUserId: z<number, number, "volatile">;
90
+ allowedUserIds: z<number[], number[], "defined">;
91
+ botTokenRef: z<string, string, "defined">;
92
+ botToken: z<string, string, "plain">;
93
+ apiRoot: z<string, string, "plain">;
94
+ lowBalanceUsd: z<number, number, "defined">;
95
+ rich: z<boolean, boolean, "defined">;
96
+ }>>, Schemastery.ObjectT<NoInfer<{
97
+ adminUserId: z<number, number, "volatile">;
98
+ allowedUserIds: z<number[], number[], "defined">;
99
+ botTokenRef: z<string, string, "defined">;
100
+ botToken: z<string, string, "plain">;
101
+ apiRoot: z<string, string, "plain">;
102
+ lowBalanceUsd: z<number, number, "defined">;
103
+ rich: z<boolean, boolean, "defined">;
104
+ }>>, "plain">;
105
+ export declare function apply(ctx: HarnessContext, rawConfig: unknown): void;
106
+ export {};