@adriangalilea/utils 0.13.0 → 0.15.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/README.md +6 -13
- package/dist/bot/access-control.d.ts.map +1 -1
- package/dist/bot/access-control.js +10 -6
- package/dist/bot/access-control.js.map +1 -1
- package/dist/bot/language.d.ts.map +1 -1
- package/dist/bot/language.js +26 -13
- package/dist/bot/language.js.map +1 -1
- package/dist/bot/llm.d.ts +116 -22
- package/dist/bot/llm.d.ts.map +1 -1
- package/dist/bot/llm.js +220 -24
- package/dist/bot/llm.js.map +1 -1
- package/dist/bot/menu.d.ts +144 -2
- package/dist/bot/menu.d.ts.map +1 -1
- package/dist/bot/menu.js +112 -8
- package/dist/bot/menu.js.map +1 -1
- package/package.json +1 -1
package/dist/bot/llm.js
CHANGED
|
@@ -8,10 +8,21 @@
|
|
|
8
8
|
* `AsyncGenerator` of `{type, text}` with
|
|
9
9
|
* `content` / `reasoning` separation.
|
|
10
10
|
*
|
|
11
|
-
* `ctx.startStream()` — OUTPUT. Debounced
|
|
12
|
-
* Telegram, local
|
|
13
|
-
* `@gramio/format`,
|
|
14
|
-
* paragraph / line /
|
|
11
|
+
* `ctx.startStream()` — OUTPUT (low-level). Debounced
|
|
12
|
+
* `editMessageText` to Telegram, local
|
|
13
|
+
* Markdown parse via `@gramio/format`,
|
|
14
|
+
* 4000-char split on paragraph / line /
|
|
15
|
+
* word boundary.
|
|
16
|
+
*
|
|
17
|
+
* `ctx.startChatStream()` — OUTPUT (high-level). Consumes a fetch
|
|
18
|
+
* `Response` (or any `AsyncIterable<LLMChunk>`)
|
|
19
|
+
* and renders BOTH phases of a thinking
|
|
20
|
+
* model: `reasoning` chunks go into one
|
|
21
|
+
* `<blockquote expandable>` message;
|
|
22
|
+
* `content` chunks go into a streamed
|
|
23
|
+
* markdown message below it. Returns
|
|
24
|
+
* `{ content, reasoning }` once the
|
|
25
|
+
* source generator ends.
|
|
15
26
|
*
|
|
16
27
|
* `ctx.llm.add / .get / …` — HISTORY. Per-(user, thread) conversation
|
|
17
28
|
* buffer in OpenAI `ChatMessage` shape.
|
|
@@ -30,12 +41,10 @@
|
|
|
30
41
|
*
|
|
31
42
|
* Peer deps: `gramio`, `@gramio/session`, `@gramio/format`, `marked`.
|
|
32
43
|
*
|
|
33
|
-
* @example
|
|
44
|
+
* @example high-level — thinking model in ~10 LOC
|
|
34
45
|
* import { Bot } from 'gramio'
|
|
35
46
|
* import { session } from '@gramio/session'
|
|
36
|
-
* import {
|
|
37
|
-
* llmStream, llmHistory, streamChat,
|
|
38
|
-
* } from '@adriangalilea/utils/bot/llm'
|
|
47
|
+
* import { llmStream, llmHistory } from '@adriangalilea/utils/bot/llm'
|
|
39
48
|
*
|
|
40
49
|
* const userSession = session({ storage, key: 'session', initial: () => ({}) })
|
|
41
50
|
* const chat = llmHistory({ session: userSession, maxTurns: 20, retentionDays: 7 })
|
|
@@ -46,33 +55,33 @@
|
|
|
46
55
|
* .extend(chat.plugin)
|
|
47
56
|
* .on('message', async (ctx) => {
|
|
48
57
|
* ctx.llm.add({ role: 'user', content: ctx.text ?? '' })
|
|
49
|
-
* const messages = ctx.llm.get()
|
|
50
|
-
*
|
|
51
58
|
* const response = await fetch(process.env.LLM_URL!, {
|
|
52
59
|
* method: 'POST',
|
|
53
60
|
* headers: { 'Content-Type': 'application/json' },
|
|
54
61
|
* body: JSON.stringify({
|
|
55
62
|
* model: process.env.LLM_MODEL,
|
|
56
|
-
* messages: [{ role: 'system', content: 'You are helpful.' }, ...
|
|
63
|
+
* messages: [{ role: 'system', content: 'You are helpful.' }, ...ctx.llm.get()],
|
|
57
64
|
* stream: true,
|
|
58
65
|
* }),
|
|
59
66
|
* })
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* let assistant = ''
|
|
63
|
-
* for await (const chunk of streamChat(response)) {
|
|
64
|
-
* if (chunk.type === 'content') {
|
|
65
|
-
* assistant += chunk.text
|
|
66
|
-
* await stream.append(chunk.text)
|
|
67
|
-
* }
|
|
68
|
-
* }
|
|
69
|
-
* await stream.end()
|
|
70
|
-
* ctx.llm.add({ role: 'assistant', content: assistant })
|
|
67
|
+
* const { content } = await ctx.startChatStream(response)
|
|
68
|
+
* ctx.llm.add({ role: 'assistant', content })
|
|
71
69
|
* })
|
|
72
70
|
*
|
|
73
71
|
* bot.start()
|
|
72
|
+
*
|
|
73
|
+
* @example low-level — manual loop when you need to map/filter chunks
|
|
74
|
+
* import { streamChat } from '@adriangalilea/utils/bot/llm'
|
|
75
|
+
*
|
|
76
|
+
* const stream = ctx.startStream()
|
|
77
|
+
* for await (const chunk of streamChat(response)) {
|
|
78
|
+
* if (chunk.type === 'content') await stream.append(chunk.text)
|
|
79
|
+
* // reasoning chunks dropped here
|
|
80
|
+
* }
|
|
81
|
+
* await stream.end()
|
|
74
82
|
*/
|
|
75
83
|
import { Plugin } from 'gramio';
|
|
84
|
+
import { expandableBlockquote } from '@gramio/format';
|
|
76
85
|
import { markdownToFormattable } from '@gramio/format/markdown';
|
|
77
86
|
/**
|
|
78
87
|
* Parse an OpenAI-compatible chat-completions SSE response into a
|
|
@@ -152,6 +161,18 @@ export class MarkdownStreamer {
|
|
|
152
161
|
inFlight = false;
|
|
153
162
|
dirty = false;
|
|
154
163
|
ended = false;
|
|
164
|
+
/**
|
|
165
|
+
* `true` after `.end()` returns if the stream finished with un-flushed
|
|
166
|
+
* buffer or an outstanding error that the streamer couldn't recover
|
|
167
|
+
* from. Useful for partial-response diagnostics in catch blocks:
|
|
168
|
+
*
|
|
169
|
+
* try { for await (...) await stream.append(...) }
|
|
170
|
+
* finally {
|
|
171
|
+
* await stream.end()
|
|
172
|
+
* if (stream.wasPartial) logger.warn('LLM stream cut off')
|
|
173
|
+
* }
|
|
174
|
+
*/
|
|
175
|
+
wasPartial = false;
|
|
155
176
|
chatId;
|
|
156
177
|
threadId;
|
|
157
178
|
// Match gramio's `bot.api` shape structurally. `text` accepts string or any
|
|
@@ -229,8 +250,14 @@ export class MarkdownStreamer {
|
|
|
229
250
|
}
|
|
230
251
|
while (this.inFlight)
|
|
231
252
|
await sleep(50);
|
|
232
|
-
if (this.dirty)
|
|
253
|
+
if (this.dirty) {
|
|
233
254
|
await this.flushNow();
|
|
255
|
+
// If `dirty` is still set after the final flush, an edit error
|
|
256
|
+
// re-armed it and there's nothing more we'll do. Mark partial
|
|
257
|
+
// so the caller can log / fall back.
|
|
258
|
+
if (this.dirty)
|
|
259
|
+
this.wasPartial = true;
|
|
260
|
+
}
|
|
234
261
|
}
|
|
235
262
|
scheduleFlush() {
|
|
236
263
|
if (this.debounceTimer)
|
|
@@ -297,6 +324,13 @@ export const llmStream = (defaults = {}) => new Plugin('@adriangalilea/utils/bot
|
|
|
297
324
|
// gramio's `message` scope guarantees `ctx.chat`. `ctx.bot.api` is on
|
|
298
325
|
// every Context. Structural compat → no cast needed.
|
|
299
326
|
startStream: (opts = {}) => new MarkdownStreamer(ctx, { ...defaults, ...opts }),
|
|
327
|
+
/**
|
|
328
|
+
* One-call helper for chat completions: consumes a `Response`
|
|
329
|
+
* (or any `AsyncIterable<LLMChunk>`), renders reasoning to an
|
|
330
|
+
* expandable blockquote message + content to a streamed markdown
|
|
331
|
+
* message, returns `{ content, reasoning }` when the stream ends.
|
|
332
|
+
*/
|
|
333
|
+
startChatStream: (source, opts = {}) => consumeChatStream(ctx, source, { ...defaults, ...opts }),
|
|
300
334
|
}));
|
|
301
335
|
function findSplit(text, maxLen) {
|
|
302
336
|
// Prefer paragraph break, then line, then space. Reject splits in the
|
|
@@ -309,6 +343,144 @@ function findSplit(text, maxLen) {
|
|
|
309
343
|
return maxLen;
|
|
310
344
|
}
|
|
311
345
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
346
|
+
/**
|
|
347
|
+
* One-shot helper that consumes an LLM stream and renders BOTH phases
|
|
348
|
+
* (reasoning, content) to Telegram with the canonical pattern:
|
|
349
|
+
*
|
|
350
|
+
* - reasoning chunks → one message containing a single
|
|
351
|
+
* `<blockquote expandable>…</blockquote>` (HTML), debounced edits,
|
|
352
|
+
* stays expanded after the stream ends so the user can review it
|
|
353
|
+
* collapsed/uncollapsed at will
|
|
354
|
+
* - content chunks → a fresh `MarkdownStreamer` message below the
|
|
355
|
+
* reasoning one (auto-threaded via SendMixin)
|
|
356
|
+
*
|
|
357
|
+
* Returns when the source generator ends. Equivalent to (and replaces)
|
|
358
|
+
* the ~50 LOC of bookkeeping every thinking-model bot would otherwise
|
|
359
|
+
* write by hand around `streamChat` + `ctx.startStream`.
|
|
360
|
+
*
|
|
361
|
+
* Accepts either a raw `fetch` `Response` (wrapped with `streamChat`
|
|
362
|
+
* internally) or an `AsyncIterable<LLMChunk>` (when you want to map /
|
|
363
|
+
* filter chunks before the stream hits Telegram).
|
|
364
|
+
*
|
|
365
|
+
* @example via ctx.startChatStream from the llmStream plugin
|
|
366
|
+
* const response = await fetch(LLM_URL, { method: 'POST', body })
|
|
367
|
+
* const { content } = await ctx.startChatStream(response)
|
|
368
|
+
* ctx.llm.add({ role: 'assistant', content })
|
|
369
|
+
*
|
|
370
|
+
* @example standalone, framework-agnostic
|
|
371
|
+
* const { content, reasoning } = await consumeChatStream(ctx, response)
|
|
372
|
+
*/
|
|
373
|
+
export const consumeChatStream = async (ctx, source, opts = {}) => {
|
|
374
|
+
const chatId = ctx.chat.id;
|
|
375
|
+
const threadId = ctx.threadId;
|
|
376
|
+
const bot = ctx.bot;
|
|
377
|
+
const debounceMs = opts.debounceMs ?? DEFAULT_DEBOUNCE_MS;
|
|
378
|
+
const gen = source instanceof Response ? streamChat(source) : source;
|
|
379
|
+
// ─── reasoning state ────────────────────────────────────────────
|
|
380
|
+
let reasoning = '';
|
|
381
|
+
let reasoningMessageId;
|
|
382
|
+
let reasoningTimer;
|
|
383
|
+
let reasoningDirty = false;
|
|
384
|
+
let reasoningInFlight = false;
|
|
385
|
+
// Same graceful-degradation pipeline as the content phase:
|
|
386
|
+
// markdownToFormattable parses the reasoning (lists, code blocks,
|
|
387
|
+
// bold — thinking models do emit markdown) into a FormattableString
|
|
388
|
+
// with native Telegram entities, and `expandableBlockquote` wraps
|
|
389
|
+
// the whole thing in a collapsed-by-default block quotation by
|
|
390
|
+
// adding the `expandable_blockquote` entity over the full text.
|
|
391
|
+
// Malformed mid-stream markdown degrades to plain text inside the
|
|
392
|
+
// blockquote instead of failing the message.
|
|
393
|
+
const renderReasoning = () => expandableBlockquote(markdownToFormattable(reasoning));
|
|
394
|
+
const sendReasoningMessage = async () => {
|
|
395
|
+
const params = {
|
|
396
|
+
chat_id: chatId,
|
|
397
|
+
...(threadId !== undefined && { message_thread_id: threadId }),
|
|
398
|
+
text: renderReasoning(),
|
|
399
|
+
};
|
|
400
|
+
const sent = await bot.api.sendMessage(params);
|
|
401
|
+
reasoningMessageId = sent.message_id;
|
|
402
|
+
};
|
|
403
|
+
const flushReasoning = async () => {
|
|
404
|
+
if (!reasoningDirty || reasoningMessageId === undefined)
|
|
405
|
+
return;
|
|
406
|
+
reasoningInFlight = true;
|
|
407
|
+
reasoningDirty = false;
|
|
408
|
+
try {
|
|
409
|
+
await bot.api.editMessageText({
|
|
410
|
+
chat_id: chatId,
|
|
411
|
+
message_id: reasoningMessageId,
|
|
412
|
+
text: renderReasoning(),
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
catch (e) {
|
|
416
|
+
const msg = String(e?.message ?? e);
|
|
417
|
+
// "message is not modified" is benign when reasoning chunks
|
|
418
|
+
// arrive faster than the debounce can render.
|
|
419
|
+
if (!msg.includes('message is not modified')) {
|
|
420
|
+
reasoningDirty = true;
|
|
421
|
+
opts.onError?.(e);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
finally {
|
|
425
|
+
reasoningInFlight = false;
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
const scheduleReasoningFlush = () => {
|
|
429
|
+
if (reasoningTimer)
|
|
430
|
+
return;
|
|
431
|
+
reasoningTimer = setTimeout(async () => {
|
|
432
|
+
reasoningTimer = undefined;
|
|
433
|
+
if (reasoningInFlight) {
|
|
434
|
+
scheduleReasoningFlush();
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
await flushReasoning();
|
|
438
|
+
if (reasoningDirty)
|
|
439
|
+
scheduleReasoningFlush();
|
|
440
|
+
}, debounceMs);
|
|
441
|
+
};
|
|
442
|
+
// ─── content state ──────────────────────────────────────────────
|
|
443
|
+
let contentStreamer;
|
|
444
|
+
let content = '';
|
|
445
|
+
// ─── main loop ──────────────────────────────────────────────────
|
|
446
|
+
for await (const chunk of gen) {
|
|
447
|
+
if (chunk.type === 'reasoning') {
|
|
448
|
+
reasoning += chunk.text;
|
|
449
|
+
if (reasoningMessageId === undefined) {
|
|
450
|
+
await sendReasoningMessage();
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
reasoningDirty = true;
|
|
454
|
+
scheduleReasoningFlush();
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
else if (chunk.type === 'content') {
|
|
458
|
+
if (!contentStreamer) {
|
|
459
|
+
// Close out reasoning cleanly before content starts: flush any
|
|
460
|
+
// pending edit, drop the debounce. The blockquote stays in
|
|
461
|
+
// the chat as a finished message.
|
|
462
|
+
if (reasoningTimer) {
|
|
463
|
+
clearTimeout(reasoningTimer);
|
|
464
|
+
reasoningTimer = undefined;
|
|
465
|
+
}
|
|
466
|
+
if (reasoningDirty)
|
|
467
|
+
await flushReasoning();
|
|
468
|
+
contentStreamer = new MarkdownStreamer({ chat: { id: chatId }, threadId, bot }, opts);
|
|
469
|
+
}
|
|
470
|
+
content += chunk.text;
|
|
471
|
+
await contentStreamer.append(chunk.text);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
// Trailing reasoning (model emitted reasoning but no content yet).
|
|
475
|
+
if (reasoningTimer) {
|
|
476
|
+
clearTimeout(reasoningTimer);
|
|
477
|
+
reasoningTimer = undefined;
|
|
478
|
+
}
|
|
479
|
+
if (reasoningDirty)
|
|
480
|
+
await flushReasoning();
|
|
481
|
+
await contentStreamer?.end();
|
|
482
|
+
return { content, reasoning };
|
|
483
|
+
};
|
|
312
484
|
const GENERAL_THREAD = 'general';
|
|
313
485
|
const threadKey = (ctx) => {
|
|
314
486
|
// Message events: ctx.threadId. Callback events: ctx.message.threadId.
|
|
@@ -355,7 +527,31 @@ export const llmHistory = (opts) => {
|
|
|
355
527
|
maxTurns: opts.maxTurns,
|
|
356
528
|
retentionDays: opts.retentionDays,
|
|
357
529
|
});
|
|
358
|
-
|
|
530
|
+
const itemLabel = opts.menuLabels?.item ?? {
|
|
531
|
+
en: '🧹 Clear this thread',
|
|
532
|
+
es: '🧹 Limpiar este hilo',
|
|
533
|
+
};
|
|
534
|
+
const clearedToast = opts.menuLabels?.cleared ?? {
|
|
535
|
+
en: '🧹 Cleared.',
|
|
536
|
+
es: '🧹 Limpio.',
|
|
537
|
+
};
|
|
538
|
+
const menuItem = {
|
|
539
|
+
id: 'llmClear',
|
|
540
|
+
label: itemLabel,
|
|
541
|
+
// Destructive action → red. Consistent with `botMenu`'s 🗑 Forget.
|
|
542
|
+
style: 'danger',
|
|
543
|
+
action: (ctx) => {
|
|
544
|
+
// The `llm` decoration comes from llmHistory's own plugin — not
|
|
545
|
+
// on MenuCtx's static shape, so we narrow here. Return the
|
|
546
|
+
// polyglot toast: the menu plugin owns the single
|
|
547
|
+
// answerCallbackQuery for this tap (calling ctx.answer here
|
|
548
|
+
// would be a double-answer → rejected → action throws).
|
|
549
|
+
const c = ctx;
|
|
550
|
+
c.llm?.clear();
|
|
551
|
+
return clearedToast;
|
|
552
|
+
},
|
|
553
|
+
};
|
|
554
|
+
return { plugin, menuItem };
|
|
359
555
|
};
|
|
360
556
|
const buildHistoryPlugin = (args) => {
|
|
361
557
|
const { sessionPlugin, maxTurns, retentionDays } = args;
|
package/dist/bot/llm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm.js","sourceRoot":"","sources":["../../src/b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;gBACJ,QAAQ,EAAE,GAAG,EAAE;oBACb,WAAW,CAAC,EAAE,CAAC,CAAA;gBACjB,CAAC;aACF;SACF,CAAA;IACH,CAAC,CAAC,CAAA;AACN,CAAC,CAAA"}
|
package/dist/bot/menu.d.ts
CHANGED
|
@@ -72,7 +72,21 @@
|
|
|
72
72
|
import { Plugin } from 'gramio';
|
|
73
73
|
import type { Storage } from '@gramio/storage';
|
|
74
74
|
import { type Polyglot } from '../say/index.js';
|
|
75
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Shape of the `ctx` an action / label / predicate sees.
|
|
77
|
+
*
|
|
78
|
+
* - Static fields (`bot`, `from`, `chat`, `session`, `threadId`,
|
|
79
|
+
* `message`) come from gramio's `CallbackQueryContext`.
|
|
80
|
+
* - Common reply methods (`send`, `reply`, `answer`, `editText`) are
|
|
81
|
+
* declared as optional so action callbacks can call them without
|
|
82
|
+
* `as unknown as` casts. They exist at runtime on every callback ctx
|
|
83
|
+
* gramio dispatches.
|
|
84
|
+
* - Plugin-decorated fields (`ctx.llm`, `ctx.say`, `ctx.lang`, …)
|
|
85
|
+
* live on the real gramio ctx but aren't declared here — narrow
|
|
86
|
+
* them via a local type assertion where you use them. The menu
|
|
87
|
+
* stays plugin-agnostic.
|
|
88
|
+
*/
|
|
89
|
+
export type MenuCtx = {
|
|
76
90
|
bot: unknown;
|
|
77
91
|
from?: {
|
|
78
92
|
id: number;
|
|
@@ -84,6 +98,20 @@ type MenuCtx = {
|
|
|
84
98
|
session?: {
|
|
85
99
|
language?: string;
|
|
86
100
|
};
|
|
101
|
+
threadId?: number;
|
|
102
|
+
message?: {
|
|
103
|
+
threadId?: number;
|
|
104
|
+
};
|
|
105
|
+
send?: (text: string | {
|
|
106
|
+
toString(): string;
|
|
107
|
+
}, params?: object) => Promise<unknown>;
|
|
108
|
+
reply?: (text: string | {
|
|
109
|
+
toString(): string;
|
|
110
|
+
}, params?: object) => Promise<unknown>;
|
|
111
|
+
answer?: (params: object) => Promise<unknown>;
|
|
112
|
+
editText?: (text: string | {
|
|
113
|
+
toString(): string;
|
|
114
|
+
}, params?: object) => Promise<unknown>;
|
|
87
115
|
};
|
|
88
116
|
/**
|
|
89
117
|
* Anything a button or header can render as. Authoring a polyglot
|
|
@@ -97,25 +125,77 @@ type MenuCtx = {
|
|
|
97
125
|
*/
|
|
98
126
|
type Label = string | Polyglot<string> | ((ctx: MenuCtx) => string | Polyglot<string>);
|
|
99
127
|
type Predicate = (ctx: MenuCtx) => boolean;
|
|
100
|
-
|
|
128
|
+
/**
|
|
129
|
+
* What a menu action's return value means:
|
|
130
|
+
*
|
|
131
|
+
* - `undefined` / `void` — menu sends an empty `answerCallbackQuery`
|
|
132
|
+
* (just clears the loading spinner).
|
|
133
|
+
* - `string` — menu sends `answerCallbackQuery({ text })`. The string
|
|
134
|
+
* pops as a toast on top of the chat.
|
|
135
|
+
* - `Polyglot<string>` — menu resolves at `ctx.session?.language` and
|
|
136
|
+
* sends as toast.
|
|
137
|
+
*
|
|
138
|
+
* DO NOT call `ctx.answer(...)` from inside an action — Telegram
|
|
139
|
+
* rejects the second answer ("query is too old"), the action throws,
|
|
140
|
+
* and `refresh: true` never runs. Return the toast instead; the menu
|
|
141
|
+
* sends the single answer.
|
|
142
|
+
*/
|
|
143
|
+
type ActionResult = void | string | Polyglot<string>;
|
|
144
|
+
type Action = (ctx: MenuCtx) => Promise<ActionResult> | ActionResult;
|
|
145
|
+
/**
|
|
146
|
+
* Telegram's inline-keyboard-button colour modes
|
|
147
|
+
* ([Bot API InlineKeyboardButton.style](https://core.telegram.org/bots/api#inlinekeyboardbutton)):
|
|
148
|
+
*
|
|
149
|
+
* - `primary` — blue, "selected / active / default action"
|
|
150
|
+
* - `success` — green, "positive / approve / confirm"
|
|
151
|
+
* - `danger` — red, "destructive / reject / forget"
|
|
152
|
+
*
|
|
153
|
+
* On clients that don't render the style (older Telegram releases),
|
|
154
|
+
* the button falls back to the app-default look — no breakage. Use
|
|
155
|
+
* `style` instead of emoji markers (●/○) to mark active state, which
|
|
156
|
+
* is consistent with how Telegram itself surfaces selection state.
|
|
157
|
+
*/
|
|
158
|
+
export type ButtonStyle = 'primary' | 'success' | 'danger';
|
|
159
|
+
type StyleResolver = ButtonStyle | ((ctx: MenuCtx) => ButtonStyle | undefined);
|
|
160
|
+
/**
|
|
161
|
+
* An entry in the menu. Three variants:
|
|
162
|
+
*
|
|
163
|
+
* - `action` — callback button; taps run `action(ctx)`. If
|
|
164
|
+
* `refresh: true`, the current menu message
|
|
165
|
+
* re-renders right after — useful for selections /
|
|
166
|
+
* toggles whose visible state depends on what the
|
|
167
|
+
* action mutated (typical: `style` based on session).
|
|
168
|
+
* - `url` — link button (Telegram opens it externally).
|
|
169
|
+
* - `submenu` — nested item tree, navigated to via callback.
|
|
170
|
+
*
|
|
171
|
+
* `style` (`primary` / `success` / `danger`) maps to Telegram's
|
|
172
|
+
* coloured inline-button modes; the resolver form `(ctx) => style`
|
|
173
|
+
* is for state-dependent colouring (e.g. blue on the currently-selected
|
|
174
|
+
* language).
|
|
175
|
+
*/
|
|
101
176
|
export type MenuItem = {
|
|
102
177
|
id: string;
|
|
103
178
|
label: Label;
|
|
104
179
|
action: Action;
|
|
105
180
|
order?: number;
|
|
106
181
|
visible?: Predicate;
|
|
182
|
+
style?: StyleResolver;
|
|
183
|
+
/** Re-render the menu message after the action runs. */
|
|
184
|
+
refresh?: boolean;
|
|
107
185
|
} | {
|
|
108
186
|
id: string;
|
|
109
187
|
label: Label;
|
|
110
188
|
url: string;
|
|
111
189
|
order?: number;
|
|
112
190
|
visible?: Predicate;
|
|
191
|
+
style?: StyleResolver;
|
|
113
192
|
} | {
|
|
114
193
|
id: string;
|
|
115
194
|
label: Label;
|
|
116
195
|
submenu: MenuItem[];
|
|
117
196
|
order?: number;
|
|
118
197
|
visible?: Predicate;
|
|
198
|
+
style?: StyleResolver;
|
|
119
199
|
};
|
|
120
200
|
export type PersonalDataOptions = {
|
|
121
201
|
/**
|
|
@@ -188,5 +268,67 @@ export declare class BotMenu {
|
|
|
188
268
|
get plugin(): Plugin<{}, import("gramio").DeriveDefinitions, {}>;
|
|
189
269
|
}
|
|
190
270
|
export declare const botMenu: (opts: BotMenuOptions) => BotMenu;
|
|
271
|
+
export type ToggleMenuItemOptions = {
|
|
272
|
+
/** Item id within the menu. Must be unique among siblings. */
|
|
273
|
+
id: string;
|
|
274
|
+
/**
|
|
275
|
+
* Reads the current boolean value. Typically `(ctx) =>
|
|
276
|
+
* ctx.session?.someField ?? false`. Storage-agnostic — return
|
|
277
|
+
* `false` by default so the toggle starts in the OFF state.
|
|
278
|
+
*/
|
|
279
|
+
read: (ctx: MenuCtx) => boolean;
|
|
280
|
+
/**
|
|
281
|
+
* Persists the new value. Typically `(ctx, v) => {
|
|
282
|
+
* (ctx.session as any).someField = v }`. The menu plugin does NOT
|
|
283
|
+
* own a session — write through whatever your bot already uses.
|
|
284
|
+
*/
|
|
285
|
+
write: (ctx: MenuCtx, value: boolean) => void | Promise<void>;
|
|
286
|
+
/**
|
|
287
|
+
* Button labels for each state. Polyglot literals resolve against
|
|
288
|
+
* `ctx.session?.language` (set by `bot/language`); strings render
|
|
289
|
+
* as-is. Use functions for runtime composition (e.g. emoji ✓/✗ +
|
|
290
|
+
* dynamic name).
|
|
291
|
+
*/
|
|
292
|
+
label: {
|
|
293
|
+
off: Label;
|
|
294
|
+
on: Label;
|
|
295
|
+
};
|
|
296
|
+
/**
|
|
297
|
+
* Optional toast shown via `ctx.answer({ text })` after a tap. Same
|
|
298
|
+
* polyglot resolution as `label`. Omit to stay silent.
|
|
299
|
+
*/
|
|
300
|
+
toast?: {
|
|
301
|
+
off?: Label;
|
|
302
|
+
on?: Label;
|
|
303
|
+
};
|
|
304
|
+
order?: number;
|
|
305
|
+
visible?: Predicate;
|
|
306
|
+
};
|
|
307
|
+
/**
|
|
308
|
+
* Convenience factory for a boolean-toggle `MenuItem`. The label
|
|
309
|
+
* tracks `read(ctx)` and the action flips it through `write(ctx, v)`.
|
|
310
|
+
* Storage is the caller's concern — pass closures that read/write the
|
|
311
|
+
* field wherever you keep it (typically `ctx.session.something`).
|
|
312
|
+
*
|
|
313
|
+
* The current menu message is NOT auto-re-rendered after a tap — the
|
|
314
|
+
* new label is visible the next time the user re-opens or navigates.
|
|
315
|
+
* The optional `toast` gives immediate feedback in the meantime.
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* toggleMenuItem({
|
|
319
|
+
* id: 'thinking',
|
|
320
|
+
* read: (ctx) => (ctx.session as { thinking?: boolean }).thinking ?? false,
|
|
321
|
+
* write: (ctx, v) => { (ctx.session as { thinking?: boolean }).thinking = v },
|
|
322
|
+
* label: {
|
|
323
|
+
* off: { en: '💭 Thinking: OFF', es: '💭 Razonamiento: OFF' },
|
|
324
|
+
* on: { en: '💭 Thinking: ON', es: '💭 Razonamiento: ON' },
|
|
325
|
+
* },
|
|
326
|
+
* toast: {
|
|
327
|
+
* off: { en: 'Thinking off.', es: 'Razonamiento off.' },
|
|
328
|
+
* on: { en: 'Thinking on.', es: 'Razonamiento on.' },
|
|
329
|
+
* },
|
|
330
|
+
* })
|
|
331
|
+
*/
|
|
332
|
+
export declare const toggleMenuItem: (opts: ToggleMenuItemOptions) => MenuItem;
|
|
191
333
|
export {};
|
|
192
334
|
//# sourceMappingURL=menu.d.ts.map
|
package/dist/bot/menu.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../src/bot/menu.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AACH,OAAO,EAGL,MAAM,EACP,MAAM,QAAQ,CAAA;AACf,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAE9C,OAAO,EAAO,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAIpD,
|
|
1
|
+
{"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