@adriangalilea/utils 0.11.0 → 0.12.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.
@@ -1,34 +1,44 @@
1
1
  /**
2
- * LLM streaming output for GramIO bots.
2
+ * LLM streaming for GramIO bots — both halves of the pipeline:
3
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.
4
+ * `streamChat(response)` INPUT: parse OpenAI-compatible SSE
5
+ * (OpenAI, vllm, mlx-lm, llama.cpp, Together,
6
+ * Groq, …) into a typed `AsyncGenerator` of
7
+ * `{ type: 'content' | 'reasoning', text }`.
8
+ *
9
+ * `ctx.startStream()` — OUTPUT: debounced `editMessageText` to
10
+ * Telegram. Local Markdown parse via
11
+ * `@gramio/format` so malformed mid-stream
12
+ * markup degrades to plain text instead of
13
+ * failing. Splits at 4000 chars on
14
+ * paragraph / line / word boundary.
15
+ *
16
+ * The two compose into the canonical bot pipeline:
17
+ *
18
+ * fetch(...) ──streamChat──> {content, reasoning} chunks ──ctx.startStream──> Telegram
10
19
  *
11
20
  * Peer deps: `gramio`, `@gramio/format`, `marked`.
12
21
  *
13
22
  * @example
14
23
  * import { Bot } from 'gramio'
15
- * import { llmStream } from '@adriangalilea/utils/bot/llm-stream'
16
- * import Anthropic from '@anthropic-ai/sdk'
24
+ * import { llmStream, streamChat } from '@adriangalilea/utils/bot/llm-stream'
17
25
  *
18
- * const claude = new Anthropic()
19
26
  * const bot = new Bot(process.env.BOT_TOKEN!)
20
27
  * .extend(llmStream())
21
28
  * .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 ?? '' }],
29
+ * const response = await fetch(process.env.LLM_URL!, {
30
+ * method: 'POST',
31
+ * headers: { 'Content-Type': 'application/json' },
32
+ * body: JSON.stringify({
33
+ * model: process.env.LLM_MODEL,
34
+ * messages: [{ role: 'user', content: ctx.text ?? '' }],
35
+ * stream: true,
36
+ * }),
27
37
  * })
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
- * }
38
+ * const stream = ctx.startStream()
39
+ * for await (const chunk of streamChat(response)) {
40
+ * if (chunk.type === 'content') await stream.append(chunk.text)
41
+ * // chunk.type === 'reasoning' is also yielded for thinking models
32
42
  * }
33
43
  * await stream.end()
34
44
  * })
@@ -36,6 +46,52 @@
36
46
  * bot.start()
37
47
  */
38
48
  import { Plugin } from 'gramio';
49
+ /**
50
+ * A single chunk yielded by `streamChat`. Two kinds:
51
+ *
52
+ * - `content` — the visible reply text the user should see
53
+ * - `reasoning` — chain-of-thought / "thinking" text from reasoning
54
+ * models. Empty unless the model emits it.
55
+ *
56
+ * Most callers care about `content` only. Render `reasoning` separately
57
+ * (collapsed, italicized) if you want to surface thinking.
58
+ */
59
+ export type LLMChunk = {
60
+ type: 'content';
61
+ text: string;
62
+ } | {
63
+ type: 'reasoning';
64
+ text: string;
65
+ };
66
+ /**
67
+ * Parse an OpenAI-compatible chat-completions SSE response into a
68
+ * typed `AsyncGenerator<LLMChunk>`. Reads `response.body` once.
69
+ *
70
+ * Recognised reasoning aliases (as of 2026): `reasoning_content`
71
+ * (vllm, qwen3, DeepSeek-R1, gpt-oss harmony) and `reasoning` (some
72
+ * mlx-lm forks, gemma builds). If a model surfaces a new key, add it
73
+ * here — single source of truth for the field.
74
+ *
75
+ * Constrained-SSE assumption: lines are `\n`-delimited and each event
76
+ * is `data: <json>` or `data: [DONE]`. This matches every OpenAI-compat
77
+ * server in the wild but is NOT the full SSE spec (no comments, no
78
+ * multi-line `data:`, no `retry`/`id` fields). Swap to
79
+ * `eventsource-parser` if you hit a producer that needs them.
80
+ *
81
+ * Malformed JSON lines are silently skipped; the generator ends when
82
+ * the stream closes.
83
+ *
84
+ * @param response the `fetch` `Response` from a `stream: true` chat
85
+ * completion call. Must not be already consumed.
86
+ * @throws if `response.body` is null (non-streaming response).
87
+ *
88
+ * @example framework-agnostic — parser doesn't know about Telegram
89
+ * const res = await fetch(url, { method: 'POST', body })
90
+ * for await (const chunk of streamChat(res)) {
91
+ * if (chunk.type === 'content') process.stdout.write(chunk.text)
92
+ * }
93
+ */
94
+ export declare function streamChat(response: Response): AsyncGenerator<LLMChunk>;
39
95
  export type StreamOptions = {
40
96
  /** Debounce window between edits, in ms. Default 800. */
41
97
  debounceMs?: number;
@@ -1 +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,M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E,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;IACtB,OAAO,CAAC,QAAQ,CAAC,CAAQ;IAIzB,OAAO,CAAC,GAAG,CAaV;IACD,OAAO,CAAC,IAAI,CAAyB;gBAGnC,GAAG,EAAE;QACH,IAAI,EAAE;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE,CAAA;QACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,GAAG,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAA;KAC7B,EACD,IAAI,EAAE,aAAa;IAgBrB,kDAAkD;IAC5C,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA+CzC,+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"}
@@ -1,34 +1,44 @@
1
1
  /**
2
- * LLM streaming output for GramIO bots.
2
+ * LLM streaming for GramIO bots — both halves of the pipeline:
3
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.
4
+ * `streamChat(response)` INPUT: parse OpenAI-compatible SSE
5
+ * (OpenAI, vllm, mlx-lm, llama.cpp, Together,
6
+ * Groq, …) into a typed `AsyncGenerator` of
7
+ * `{ type: 'content' | 'reasoning', text }`.
8
+ *
9
+ * `ctx.startStream()` — OUTPUT: debounced `editMessageText` to
10
+ * Telegram. Local Markdown parse via
11
+ * `@gramio/format` so malformed mid-stream
12
+ * markup degrades to plain text instead of
13
+ * failing. Splits at 4000 chars on
14
+ * paragraph / line / word boundary.
15
+ *
16
+ * The two compose into the canonical bot pipeline:
17
+ *
18
+ * fetch(...) ──streamChat──> {content, reasoning} chunks ──ctx.startStream──> Telegram
10
19
  *
11
20
  * Peer deps: `gramio`, `@gramio/format`, `marked`.
12
21
  *
13
22
  * @example
14
23
  * import { Bot } from 'gramio'
15
- * import { llmStream } from '@adriangalilea/utils/bot/llm-stream'
16
- * import Anthropic from '@anthropic-ai/sdk'
24
+ * import { llmStream, streamChat } from '@adriangalilea/utils/bot/llm-stream'
17
25
  *
18
- * const claude = new Anthropic()
19
26
  * const bot = new Bot(process.env.BOT_TOKEN!)
20
27
  * .extend(llmStream())
21
28
  * .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 ?? '' }],
29
+ * const response = await fetch(process.env.LLM_URL!, {
30
+ * method: 'POST',
31
+ * headers: { 'Content-Type': 'application/json' },
32
+ * body: JSON.stringify({
33
+ * model: process.env.LLM_MODEL,
34
+ * messages: [{ role: 'user', content: ctx.text ?? '' }],
35
+ * stream: true,
36
+ * }),
27
37
  * })
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
- * }
38
+ * const stream = ctx.startStream()
39
+ * for await (const chunk of streamChat(response)) {
40
+ * if (chunk.type === 'content') await stream.append(chunk.text)
41
+ * // chunk.type === 'reasoning' is also yielded for thinking models
32
42
  * }
33
43
  * await stream.end()
34
44
  * })
@@ -37,6 +47,74 @@
37
47
  */
38
48
  import { Plugin } from 'gramio';
39
49
  import { markdownToFormattable } from '@gramio/format/markdown';
50
+ /**
51
+ * Parse an OpenAI-compatible chat-completions SSE response into a
52
+ * typed `AsyncGenerator<LLMChunk>`. Reads `response.body` once.
53
+ *
54
+ * Recognised reasoning aliases (as of 2026): `reasoning_content`
55
+ * (vllm, qwen3, DeepSeek-R1, gpt-oss harmony) and `reasoning` (some
56
+ * mlx-lm forks, gemma builds). If a model surfaces a new key, add it
57
+ * here — single source of truth for the field.
58
+ *
59
+ * Constrained-SSE assumption: lines are `\n`-delimited and each event
60
+ * is `data: <json>` or `data: [DONE]`. This matches every OpenAI-compat
61
+ * server in the wild but is NOT the full SSE spec (no comments, no
62
+ * multi-line `data:`, no `retry`/`id` fields). Swap to
63
+ * `eventsource-parser` if you hit a producer that needs them.
64
+ *
65
+ * Malformed JSON lines are silently skipped; the generator ends when
66
+ * the stream closes.
67
+ *
68
+ * @param response the `fetch` `Response` from a `stream: true` chat
69
+ * completion call. Must not be already consumed.
70
+ * @throws if `response.body` is null (non-streaming response).
71
+ *
72
+ * @example framework-agnostic — parser doesn't know about Telegram
73
+ * const res = await fetch(url, { method: 'POST', body })
74
+ * for await (const chunk of streamChat(res)) {
75
+ * if (chunk.type === 'content') process.stdout.write(chunk.text)
76
+ * }
77
+ */
78
+ export async function* streamChat(response) {
79
+ if (!response.body)
80
+ throw new Error('streamChat: response.body is null');
81
+ const reader = response.body.getReader();
82
+ const decoder = new TextDecoder();
83
+ let buffer = '';
84
+ while (true) {
85
+ const { done, value } = await reader.read();
86
+ if (done)
87
+ break;
88
+ buffer += decoder.decode(value, { stream: true });
89
+ const lines = buffer.split('\n');
90
+ buffer = lines.pop() ?? '';
91
+ for (const line of lines) {
92
+ if (!line.startsWith('data: '))
93
+ continue;
94
+ const data = line.slice(6).trim();
95
+ if (data === '[DONE]')
96
+ continue;
97
+ let parsed;
98
+ try {
99
+ parsed = JSON.parse(data);
100
+ }
101
+ catch {
102
+ continue;
103
+ }
104
+ const delta = parsed.choices?.[0]?.delta;
105
+ if (!delta)
106
+ continue;
107
+ const reasoning = delta.reasoning_content ?? delta.reasoning;
108
+ if (typeof reasoning === 'string' && reasoning.length > 0) {
109
+ yield { type: 'reasoning', text: reasoning };
110
+ }
111
+ if (typeof delta.content === 'string' && delta.content.length > 0) {
112
+ yield { type: 'content', text: delta.content };
113
+ }
114
+ }
115
+ }
116
+ }
117
+ // ─── OUTPUT: Telegram streamer ─────────────────────────────────────
40
118
  const MAX_LEN = 4000; // Telegram caps at 4096; leave headroom for entity offsets
41
119
  const DEFAULT_DEBOUNCE_MS = 800;
42
120
  export class MarkdownStreamer {
@@ -1 +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,mBAAmB,GAAG,GAAG,CAAA;AAa/B,MAAM,OAAO,gBAAgB;IACnB,MAAM,GAAG,EAAE,CAAA;IACX,gBAAgB,CAAS;IACzB,gBAAgB,CAAgB;IAChC,aAAa,CAAgC;IAC7C,QAAQ,GAAG,KAAK,CAAA;IAChB,KAAK,GAAG,KAAK,CAAA;IACb,KAAK,GAAG,KAAK,CAAA;IAEb,MAAM,CAAQ;IACd,QAAQ,CAAS;IACzB,4EAA4E;IAC5E,0EAA0E;IAC1E,4EAA4E;IACpE,GAAG,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 +1,6 @@
1
1
  {
2
2
  "name": "@adriangalilea/utils",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
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",