@adriangalilea/utils 0.5.0 → 0.6.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.
@@ -0,0 +1,52 @@
1
+ import { Plugin } from 'gramio';
2
+ import { kev } from '../platform/kev.js';
3
+ export const gracefulStart = async (bot, opts = {}) => {
4
+ const log = opts.log === false ? () => { } : (opts.log ?? ((m) => console.log(m)));
5
+ const forceMs = opts.forceExitAfterMs ?? 10_000;
6
+ let stopping = false;
7
+ const stop = async (signal) => {
8
+ if (stopping)
9
+ return;
10
+ stopping = true;
11
+ log(`[bot] ${signal} received, shutting down…`);
12
+ const force = setTimeout(() => {
13
+ console.error(`[bot] forced exit after ${forceMs}ms`);
14
+ process.exit(1);
15
+ }, forceMs);
16
+ force.unref?.();
17
+ try {
18
+ await bot.stop();
19
+ await opts.onShutdown?.();
20
+ log('[bot] shutdown clean');
21
+ }
22
+ catch (e) {
23
+ console.error('[bot] shutdown error', e);
24
+ }
25
+ finally {
26
+ clearTimeout(force);
27
+ process.exit(opts.exitCode ?? 0);
28
+ }
29
+ };
30
+ process.on('SIGINT', () => void stop('SIGINT'));
31
+ process.on('SIGTERM', () => void stop('SIGTERM'));
32
+ await bot.start();
33
+ };
34
+ export const adminContext = (opts = {}) => {
35
+ // KEV resolves: process.env → .env (project + monorepo, auto-discovered) → fallback.
36
+ // Cached after first read. `kev.int` panics on non-int strings, so a malformed
37
+ // env var screams immediately rather than producing NaN downstream.
38
+ const adminId = kev.int('TELEGRAM_ADMIN_ID', opts.adminId ?? 0);
39
+ if (!adminId) {
40
+ throw new Error('adminContext: TELEGRAM_ADMIN_ID not set and no adminId fallback. ' +
41
+ 'Get your Telegram id from @UserIDentifyBot.');
42
+ }
43
+ return new Plugin('@adriangalilea/utils/bot/admin')
44
+ .decorate({ adminId })
45
+ .derive((ctx) => ({
46
+ // `senderId` is provided by gramio's SenderMixin. It's `undefined` on
47
+ // service-style events without an actor; the strict equality below
48
+ // gives `false` in that case, which is the right answer.
49
+ isAdmin: 'senderId' in ctx && ctx.senderId === adminId,
50
+ }));
51
+ };
52
+ //# sourceMappingURL=kit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kit.js","sourceRoot":"","sources":["../../src/bot/kit.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAA;AAexC,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAChC,GAAW,EACX,OAA6B,EAAE,EAChB,EAAE;IACjB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACjF,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,IAAI,MAAM,CAAA;IAE/C,IAAI,QAAQ,GAAG,KAAK,CAAA;IAEpB,MAAM,IAAI,GAAG,KAAK,EAAE,MAAc,EAAE,EAAE;QACpC,IAAI,QAAQ;YAAE,OAAM;QACpB,QAAQ,GAAG,IAAI,CAAA;QACf,GAAG,CAAC,SAAS,MAAM,2BAA2B,CAAC,CAAA;QAE/C,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,OAAO,CAAC,KAAK,CAAC,2BAA2B,OAAO,IAAI,CAAC,CAAA;YACrD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACjB,CAAC,EAAE,OAAO,CAAC,CAAA;QACX,KAAK,CAAC,KAAK,EAAE,EAAE,CAAA;QAEf,IAAI,CAAC;YACH,MAAM,GAAG,CAAC,IAAI,EAAE,CAAA;YAChB,MAAM,IAAI,CAAC,UAAU,EAAE,EAAE,CAAA;YACzB,GAAG,C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for GramIO bots.
3
+ *
4
+ * Sends a placeholder, then debounces `editMessageText` calls as the
5
+ * LLM produces chunks. Markdown is parsed locally with
6
+ * `markdownToFormattable` — invalid markup degrades to plain text
7
+ * instead of failing (Telegram's `parse_mode` would reject the whole
8
+ * message). Splits at 4000 chars by promoting the next chunk to a
9
+ * fresh message at a paragraph/line/word boundary.
10
+ *
11
+ * Peer deps: `gramio`, `@gramio/format`, `marked`.
12
+ *
13
+ * @example
14
+ * import { Bot } from 'gramio'
15
+ * import { llmStream } from '@adriangalilea/utils/bot/llm-stream'
16
+ * import Anthropic from '@anthropic-ai/sdk'
17
+ *
18
+ * const claude = new Anthropic()
19
+ * const bot = new Bot(process.env.BOT_TOKEN!)
20
+ * .extend(llmStream())
21
+ * .on('message', async (ctx) => {
22
+ * const stream = ctx.startStream()
23
+ * const sse = await claude.messages.stream({
24
+ * model: 'claude-opus-4-5',
25
+ * max_tokens: 1024,
26
+ * messages: [{ role: 'user', content: ctx.text ?? '' }],
27
+ * })
28
+ * for await (const chunk of sse) {
29
+ * if (chunk.type === 'content_block_delta' && chunk.delta.type === 'text_delta') {
30
+ * await stream.append(chunk.delta.text)
31
+ * }
32
+ * }
33
+ * await stream.end()
34
+ * })
35
+ *
36
+ * bot.start()
37
+ */
38
+ import { Plugin } from 'gramio';
39
+ export type StreamOptions = {
40
+ /** Debounce window between edits, in ms. Default 800. */
41
+ debounceMs?: number;
42
+ /** Initial placeholder shown until the first chunk arrives. Default "…". */
43
+ placeholder?: string;
44
+ /** Parse buffer as markdown. Default true. Set false for plain text streaming. */
45
+ markdown?: boolean;
46
+ /** Called on edit/send errors after internal recovery (rate limits, etc.). */
47
+ onError?: (err: unknown) => void;
48
+ };
49
+ export declare class MarkdownStreamer {
50
+ private buffer;
51
+ private currentMessageId?;
52
+ private firstSendPromise?;
53
+ private debounceTimer?;
54
+ private inFlight;
55
+ private dirty;
56
+ private ended;
57
+ private chatId;
58
+ private bot;
59
+ private opts;
60
+ constructor(ctx: {
61
+ chat: {
62
+ id: number;
63
+ };
64
+ bot: MarkdownStreamer['bot'];
65
+ }, opts: StreamOptions);
66
+ /** Append a chunk. Schedules a debounced edit. */
67
+ append(text: string): Promise<void>;
68
+ /** Flush any pending edit and close the stream. Idempotent. */
69
+ end(): Promise<void>;
70
+ private scheduleFlush;
71
+ private flushNow;
72
+ }
73
+ /**
74
+ * GramIO plugin. Adds `ctx.startStream(opts?)` on every message context.
75
+ *
76
+ * Defaults set here apply to every stream; per-call options in
77
+ * `ctx.startStream({...})` override them.
78
+ */
79
+ export declare const llmStream: (defaults?: StreamOptions) => Plugin<{}, import("gramio").DeriveDefinitions & {
80
+ message: {
81
+ startStream: (opts?: StreamOptions) => MarkdownStreamer;
82
+ };
83
+ }, {}>;
84
+ //# sourceMappingURL=llm-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-stream.d.ts","sourceRoot":"","sources":["../../src/bot/llm-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAM/B,MAAM,MAAM,aAAa,GAAG;IAC1B,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,4EAA4E;IAC5E,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,kFAAkF;IAClF,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,8EAA8E;IAC9E,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAA;CACjC,CAAA;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,gBAAgB,CAAC,CAAQ;IACjC,OAAO,CAAC,gBAAgB,CAAC,CAAe;IACxC,OAAO,CAAC,aAAa,CAAC,CAA+B;IACrD,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,KAAK,CAAQ;IAErB,OAAO,CAAC,MAAM,CAAQ;IAItB,OAAO,CAAC,GAAG,CAYV;IACD,OAAO,CAAC,IAAI,CAAyB;gBAGnC,GAAG,EAAE;QAAE,IAAI,EAAE;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE,CAAC;QAAC,GAAG,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAA;KAAE,EAC3D,IAAI,EAAE,aAAa;IAYrB,kDAAkD;IAC5C,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA8CzC,+DAA+D;IACzD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAW1B,OAAO,CAAC,aAAa;YAaP,QAAQ;CAmCvB;AAED;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAI,WAAU,aAAkB;;6BAI9B,aAAa;;MAEhC,CAAA"}
@@ -0,0 +1,201 @@
1
+ /**
2
+ * LLM streaming output for GramIO bots.
3
+ *
4
+ * Sends a placeholder, then debounces `editMessageText` calls as the
5
+ * LLM produces chunks. Markdown is parsed locally with
6
+ * `markdownToFormattable` — invalid markup degrades to plain text
7
+ * instead of failing (Telegram's `parse_mode` would reject the whole
8
+ * message). Splits at 4000 chars by promoting the next chunk to a
9
+ * fresh message at a paragraph/line/word boundary.
10
+ *
11
+ * Peer deps: `gramio`, `@gramio/format`, `marked`.
12
+ *
13
+ * @example
14
+ * import { Bot } from 'gramio'
15
+ * import { llmStream } from '@adriangalilea/utils/bot/llm-stream'
16
+ * import Anthropic from '@anthropic-ai/sdk'
17
+ *
18
+ * const claude = new Anthropic()
19
+ * const bot = new Bot(process.env.BOT_TOKEN!)
20
+ * .extend(llmStream())
21
+ * .on('message', async (ctx) => {
22
+ * const stream = ctx.startStream()
23
+ * const sse = await claude.messages.stream({
24
+ * model: 'claude-opus-4-5',
25
+ * max_tokens: 1024,
26
+ * messages: [{ role: 'user', content: ctx.text ?? '' }],
27
+ * })
28
+ * for await (const chunk of sse) {
29
+ * if (chunk.type === 'content_block_delta' && chunk.delta.type === 'text_delta') {
30
+ * await stream.append(chunk.delta.text)
31
+ * }
32
+ * }
33
+ * await stream.end()
34
+ * })
35
+ *
36
+ * bot.start()
37
+ */
38
+ import { Plugin } from 'gramio';
39
+ import { markdownToFormattable } from '@gramio/format/markdown';
40
+ const MAX_LEN = 4000; // Telegram caps at 4096; leave headroom for entity offsets
41
+ const DEFAULT_DEBOUNCE_MS = 800;
42
+ export class MarkdownStreamer {
43
+ buffer = '';
44
+ currentMessageId;
45
+ firstSendPromise;
46
+ debounceTimer;
47
+ inFlight = false;
48
+ dirty = false;
49
+ ended = false;
50
+ chatId;
51
+ // Match gramio's `bot.api` shape structurally. `text` accepts string or any
52
+ // `Formattable` (from `@gramio/format`) — both stringify safely. We don't
53
+ // import gramio's full Bot type to keep the streamer testable in isolation.
54
+ bot;
55
+ opts;
56
+ constructor(ctx, opts) {
57
+ this.chatId = ctx.chat.id;
58
+ this.bot = ctx.bot;
59
+ this.opts = {
60
+ debounceMs: opts.debounceMs ?? DEFAULT_DEBOUNCE_MS,
61
+ placeholder: opts.placeholder ?? '…',
62
+ markdown: opts.markdown ?? true,
63
+ onError: opts.onError ?? ((e) => console.error('[llm-stream]', e)),
64
+ };
65
+ }
66
+ /** Append a chunk. Schedules a debounced edit. */
67
+ async append(text) {
68
+ if (this.ended)
69
+ throw new Error('stream already ended');
70
+ if (!text)
71
+ return;
72
+ // first chunk: send the placeholder so we have a message_id to edit.
73
+ // Serialized via firstSendPromise so concurrent appends don't double-send.
74
+ if (this.currentMessageId === undefined && !this.firstSendPromise) {
75
+ this.firstSendPromise = (async () => {
76
+ const sent = await this.bot.api.sendMessage({
77
+ chat_id: this.chatId,
78
+ text: this.opts.placeholder,
79
+ });
80
+ this.currentMessageId = sent.message_id;
81
+ })();
82
+ }
83
+ if (this.firstSendPromise)
84
+ await this.firstSendPromise;
85
+ // overflow: freeze current message at last good split, start a new one.
86
+ const next = this.buffer + text;
87
+ if (next.length > MAX_LEN) {
88
+ const splitAt = findSplit(next, MAX_LEN);
89
+ const head = next.slice(0, splitAt);
90
+ const tail = next.slice(splitAt).trimStart();
91
+ this.buffer = head;
92
+ this.dirty = true;
93
+ await this.flushNow(); // commits head into current message
94
+ this.buffer = '';
95
+ this.currentMessageId = undefined;
96
+ this.firstSendPromise = undefined;
97
+ this.dirty = false;
98
+ if (this.debounceTimer) {
99
+ clearTimeout(this.debounceTimer);
100
+ this.debounceTimer = undefined;
101
+ }
102
+ if (tail)
103
+ await this.append(tail);
104
+ return;
105
+ }
106
+ this.buffer = next;
107
+ this.dirty = true;
108
+ this.scheduleFlush();
109
+ }
110
+ /** Flush any pending edit and close the stream. Idempotent. */
111
+ async end() {
112
+ if (this.ended)
113
+ return;
114
+ this.ended = true;
115
+ if (this.debounceTimer) {
116
+ clearTimeout(this.debounceTimer);
117
+ this.debounceTimer = undefined;
118
+ }
119
+ while (this.inFlight)
120
+ await sleep(50);
121
+ if (this.dirty)
122
+ await this.flushNow();
123
+ }
124
+ scheduleFlush() {
125
+ if (this.debounceTimer)
126
+ return;
127
+ this.debounceTimer = setTimeout(async () => {
128
+ this.debounceTimer = undefined;
129
+ if (this.inFlight) {
130
+ this.scheduleFlush();
131
+ return;
132
+ }
133
+ await this.flushNow();
134
+ if (this.dirty && !this.ended)
135
+ this.scheduleFlush();
136
+ }, this.opts.debounceMs);
137
+ }
138
+ async flushNow() {
139
+ if (!this.dirty)
140
+ return;
141
+ if (this.currentMessageId === undefined) {
142
+ // No active message yet — likely the first send is still in flight
143
+ // or the recovery path cleared it. Caller's next append() will
144
+ // re-create one.
145
+ return;
146
+ }
147
+ this.inFlight = true;
148
+ this.dirty = false;
149
+ const snapshot = this.buffer;
150
+ try {
151
+ const payload = this.opts.markdown ? markdownToFormattable(snapshot) : snapshot;
152
+ await this.bot.api.editMessageText({
153
+ chat_id: this.chatId,
154
+ message_id: this.currentMessageId,
155
+ text: payload,
156
+ });
157
+ }
158
+ catch (e) {
159
+ const msg = String(e?.message ?? e);
160
+ if (msg.includes('message is not modified')) {
161
+ // identical content — fine
162
+ }
163
+ else if (msg.includes('message to edit not found')) {
164
+ // message gone (deleted by user, etc.) — restart with a fresh send
165
+ this.currentMessageId = undefined;
166
+ this.firstSendPromise = undefined;
167
+ this.dirty = true;
168
+ }
169
+ else {
170
+ this.dirty = true;
171
+ this.opts.onError(e);
172
+ }
173
+ }
174
+ finally {
175
+ this.inFlight = false;
176
+ }
177
+ }
178
+ }
179
+ /**
180
+ * GramIO plugin. Adds `ctx.startStream(opts?)` on every message context.
181
+ *
182
+ * Defaults set here apply to every stream; per-call options in
183
+ * `ctx.startStream({...})` override them.
184
+ */
185
+ export const llmStream = (defaults = {}) => new Plugin('@adriangalilea/utils/bot/llm-stream').derive('message', (ctx) => ({
186
+ // gramio's `message` scope guarantees `ctx.chat`. `ctx.bot.api` is on
187
+ // every Context. Structural compat → no cast needed.
188
+ startStream: (opts = {}) => new MarkdownStreamer(ctx, { ...defaults, ...opts }),
189
+ }));
190
+ function findSplit(text, maxLen) {
191
+ // Prefer paragraph break, then line, then space. Reject splits in the
192
+ // first half — better to truncate at maxLen than to leave a stub.
193
+ for (const sep of ['\n\n', '\n', ' ']) {
194
+ const idx = text.lastIndexOf(sep, maxLen);
195
+ if (idx > maxLen / 2)
196
+ return idx;
197
+ }
198
+ return maxLen;
199
+ }
200
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
201
+ //# sourceMappingURL=llm-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-stream.js","sourceRoot":"","sources":["../../src/bot/llm-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAE/D,MAAM,OAAO,GAAG,IAAI,CAAA,CAAC,2DAA2D;AAChF,MAAM,mBAA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CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAC5E,sEAAsE;IACtE,qDAAqD;IACrD,WAAW,EAAE,CAAC,OAAsB,EAAE,EAAE,EAAE,CACxC,IAAI,gBAAgB,CAAC,GAAG,EAAE,EAAE,GAAG,QAAQ,EAAE,GAAG,IAAI,EAAE,CAAC;CACtD,CAAC,CAAC,CAAA;AAEL,SAAS,SAAS,CAAC,IAAY,EAAE,MAAc;IAC7C,sEAAsE;IACtE,kEAAkE;IAClE,KAAK,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;QACtC,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QACzC,IAAI,GAAG,GAAG,MAAM,GAAG,CAAC;YAAE,OAAO,GAAG,CAAA;IAClC,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAO,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adriangalilea/utils",
3
- "version": "0.5.0",
4
- "description": "TypeScript utilities - logger, currency, formatter, and more",
3
+ "version": "0.6.0",
4
+ "description": "TypeScript utilities - logger, currency, formatter, GramIO bot plugins, and more",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "type": "module",
@@ -27,6 +27,22 @@
27
27
  "./currency": {
28
28
  "types": "./dist/universal/currency/index.d.ts",
29
29
  "default": "./dist/universal/currency/index.js"
30
+ },
31
+ "./bot": {
32
+ "types": "./dist/bot/index.d.ts",
33
+ "default": "./dist/bot/index.js"
34
+ },
35
+ "./bot/access-control": {
36
+ "types": "./dist/bot/access-control.d.ts",
37
+ "default": "./dist/bot/access-control.js"
38
+ },
39
+ "./bot/kit": {
40
+ "types": "./dist/bot/kit.d.ts",
41
+ "default": "./dist/bot/kit.js"
42
+ },
43
+ "./bot/llm-stream": {
44
+ "types": "./dist/bot/llm-stream.d.ts",
45
+ "default": "./dist/bot/llm-stream.js"
30
46
  }
31
47
  },
32
48
  "files": [
@@ -54,13 +70,42 @@
54
70
  "author": "Adrian Galilea <adriangalilea@gmail.com>",
55
71
  "license": "MIT",
56
72
  "devDependencies": {
73
+ "@gramio/format": "^0.8.0",
74
+ "@gramio/session": "^0.2.0",
75
+ "@gramio/storage": "^2.0.1",
57
76
  "@types/node": "^24.3.0",
77
+ "gramio": "^0.10.0",
78
+ "marked": "^15.0.11",
58
79
  "tsx": "^4.20.4",
59
80
  "typescript": "^5.9.2"
60
81
  },
61
82
  "dependencies": {
62
83
  "chalk": "^5.6.0"
63
84
  },
85
+ "peerDependencies": {
86
+ "@gramio/format": ">=0.8.0",
87
+ "@gramio/session": ">=0.2.0",
88
+ "@gramio/storage": ">=2.0.0",
89
+ "gramio": ">=0.10.0",
90
+ "marked": ">=12"
91
+ },
92
+ "peerDependenciesMeta": {
93
+ "@gramio/format": {
94
+ "optional": true
95
+ },
96
+ "@gramio/session": {
97
+ "optional": true
98
+ },
99
+ "@gramio/storage": {
100
+ "optional": true
101
+ },
102
+ "gramio": {
103
+ "optional": true
104
+ },
105
+ "marked": {
106
+ "optional": true
107
+ }
108
+ },
64
109
  "publishConfig": {
65
110
  "access": "public",
66
111
  "registry": "https://registry.npmjs.org/"