@adriangalilea/utils 2.0.1 → 2.2.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 +1 -1
- package/dist/bot/draft.d.ts +88 -0
- package/dist/bot/draft.d.ts.map +1 -0
- package/dist/bot/draft.js +186 -0
- package/dist/bot/draft.js.map +1 -0
- package/dist/bot/index.d.ts +1 -0
- package/dist/bot/index.d.ts.map +1 -1
- package/dist/bot/index.js +1 -0
- package/dist/bot/index.js.map +1 -1
- package/dist/bot/llm.d.ts +10 -2
- package/dist/bot/llm.d.ts.map +1 -1
- package/dist/bot/llm.js +52 -85
- package/dist/bot/llm.js.map +1 -1
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -449,7 +449,7 @@ Then `pnpm install`. Every `ctx.send` / `ctx.sendDocument` / `ctx.reply` / etc.
|
|
|
449
449
|
| `@adriangalilea/utils/bot/user` | `userLabel(u)` — the conditional "[name] [@username] [id]" line every bot re-rolls for admin DMs and logs: `Ada Lovelace (@ada · 42)` / `Ada (42)` / `@ada (42)` / `id 42`, missing pieces drop instead of padding. Reads both gramio spellings (`firstName` / `first_name`); plain text by design. |
|
|
450
450
|
| `@adriangalilea/utils/bot/coalesce` | Joins client-split inbound messages back into one. When a user pastes >4096 chars, Telegram clients fragment it into separate `message` updates with no marker. Middleware detects the burst and emits one combined event. |
|
|
451
451
|
| `@adriangalilea/utils/llm` | Multi-provider LLM caller on the Vercel AI SDK — the policy layer the SDK doesn't ship. `createLlm({ providers, health? })` → `.stream(req)` (typed events: `delta` / `reasoning` / `reset` / `tool-call` / `end`) and `.complete(req)`. **Failover:** priority-ordered across OpenAI-compatible, Anthropic-compatible, and OpenRouter endpoints; multiple keys per provider (health tracked per key fingerprint); per-key circuit breaker with exponential cool-down persisted in any KV-shaped `HealthStore`; an attempt that dies after emitting yields `reset` (discard, next candidate regenerates); empty completions count as failures. **Accounting:** tokens summed across billed attempts; `costUsd` is the ACTUAL charge (OpenRouter usage accounting via `providerMetadata`, or a `cost` field on the raw usage frame) — never a price-table estimate. **Knobs:** per-model temperature, maxTokens caps, `disableThinking` mapped to each dialect. **Tools:** AI SDK `tool()` + `toolChoice` pass through (re-exported). Worker-safe; peers: `ai`, `@ai-sdk/openai-compatible`, `@ai-sdk/anthropic`, `@openrouter/ai-sdk-provider`. |
|
|
452
|
-
| `@adriangalilea/utils/bot/llm` | The Telegram side of an LLM chatbot; the model side is `@adriangalilea/utils/llm`. **Output:** `streamChatReply(ctx, events, opts?)` consumes an `AsyncIterable<LlmStreamEvent>` and paints it with Telegram's native message-draft streaming (`sendMessageDraft` full-frame repaints, throttled ~1/s, keepalive under the ~30s draft TTL), then persists the finished markdown via `ctx.send`, entity-split across 4096 by `@gramio/split`. Reasoning models get a thinking phase — streams into the ephemeral draft and evaporates (`reasoning: 'preview'`, default), persists as an expandable blockquote (`'message'`), or never renders (`'hidden'`). Upstream `reset` (provider failover) repaints the draft from scratch. Drafts are private-chat-only (+ BotFather forum-topic mode); elsewhere the preview phase is skipped and only the final send happens. Returns `{ content, reasoning, toolCalls, usage, messages }`. **History:** `llmHistory({...})` returns `.plugin` (decorates `ctx.llm` with `.add() / .get() / .clear() / .all() / .clearAll()`, per-(user, thread) OpenAI `ChatMessage` shape, persisted in the shared session record so the menu's 🗑 Forget wipes it automatically) AND `.menuItem` (drop-in "🗑 Delete this thread" for `botMenu` — wipes the LLM history AND calls `deleteForumTopic` so the Telegram thread + all its messages disappear from the chat; falls back to history-only clear when no `threadId` is present). |
|
|
452
|
+
| `@adriangalilea/utils/bot/llm` | The Telegram side of an LLM chatbot; the model side is `@adriangalilea/utils/llm`. **Output:** `streamChatReply(ctx, events, opts?)` consumes an `AsyncIterable<LlmStreamEvent>` and paints it with Telegram's native message-draft streaming (`sendMessageDraft` full-frame repaints, throttled ~1/s, keepalive under the ~30s draft TTL), then persists the finished markdown via `ctx.send`, entity-split across 4096 by `@gramio/split`. Reasoning models get a thinking phase — streams into the ephemeral draft and evaporates (`reasoning: 'preview'`, default), persists as an expandable blockquote (`'message'`), or never renders (`'hidden'`). Upstream `reset` (provider failover) repaints the draft from scratch. Drafts are private-chat-only (+ BotFather forum-topic mode); elsewhere the preview phase is skipped and only the final send happens. Returns `{ content, reasoning, toolCalls, usage, messages }`. The painter underneath is `@adriangalilea/utils/bot/draft` (`createDraftPreview(ctx, { render, throttleMs? })`): dependency-light (no markdown machinery), for producers that push deltas or own their per-frame rendering (plain or rich-message frames) and persist path, with `streamForensics` (render-regression + reset warnings) built in and exported standalone. **History:** `llmHistory({...})` returns `.plugin` (decorates `ctx.llm` with `.add() / .get() / .clear() / .all() / .clearAll()`, per-(user, thread) OpenAI `ChatMessage` shape, persisted in the shared session record so the menu's 🗑 Forget wipes it automatically) AND `.menuItem` (drop-in "🗑 Delete this thread" for `botMenu` — wipes the LLM history AND calls `deleteForumTopic` so the Telegram thread + all its messages disappear from the chat; falls back to history-only clear when no `threadId` is present). |
|
|
453
453
|
| `@adriangalilea/utils/bot/menu` | `botMenu({ command, description, items, privacy?, personalData?, adminContact })` — `/settings` command + InlineKeyboard router. Root view always renders a `🛡️ Privacy & data` submenu button that wraps the privacy policy link plus (if `personalData: { storage }`) 🗑 Forget + 📥 Export buttons. Items take `keepRow` (render on the same row as the next item — e.g. a two-per-row language picker) and `rootExtra` (render at the bottom of the root menu, below Privacy & data). `label` / `header` / `style` / `visible` resolvers may be **async** (read your db at render time — never cache render strings in the session); `parseMode: 'HTML'` renders the header formatted (you own escaping); `personalData.onForget(ctx, userId)` wipes YOUR tables inside the same try as the session delete, so Forget either forgets everything or reports failure. `toggleMenuItem({ id, read, write, label: { off, on }, toast? })` — convenience factory for boolean-toggle items with dynamic label + optional toast, storage-agnostic via `read`/`write` closures. |
|
|
454
454
|
| `@adriangalilea/utils/bot/payments` | `botPayments({ session, storage, paysupport, paysupportHint?, legal, waiver, vip?, credits?, perks? })` — Telegram Stars monetization in one drop-in plugin. **Three axes, all optional:** `vip` (positional tier ladder — single rung in v1 is just `vip: [{...}]`, ladder is `vip: [{...}, {...}]`; ids are `vip.1`, `vip.2`, …), `credits` (consumable balance + top-up packs `credits.1`, `credits.2`, …), `perks` (orthogonal one-shot unlocks `perks.<key>`). **Surface:** `ctx.payments.atLeast('vip')` / `atLeast('vip.2')` (typed rank check), `ctx.payments.tier()` / `.tier.level()` / `.tier.label()`, `ctx.payments.credits.{balance, consume, tryConsume}` (throws `InsufficientCredits`), `ctx.payments.has(perkId)`, `await ctx.payments.require('vip', { feature? })` (gate that sends a localized upgrade prompt deep-linked to `/settings → 💎 VIP`), `await ctx.payments.invoice(productKey)` (threads Art. 103(m) TRLGDCU consent inline before `sendInvoice`). **Owns:** waiver consent flow (versioned text → forces re-consent on bump, snapshotted on every charge for audit), `/paysupport` slash command (Telegram ToS §6.5; `paysupportHint` overrides the where-to-manage-charges line when your menu isn't `/settings`), idempotent `successful_payment` fulfillment via `pay:idempotency:{chargeId}` sentinel, lazy subscription expiry (no cron needed), tier upgrade auto-cancel of the lower rung's renewal, and admin-DM refund approval (mirror of `accessControl`'s [✅ Aprobar][❌ Denegar] pattern). **Returns:** `{ plugin, menuItem, payouts, onFulfilled }` — `menuItem` is the drop-in `💎 VIP` entry for `botMenu`; `payouts.{record, list, export, exportForUsers}` is the Fragment payout ledger (you receive TON, log the EUR conversion, export time-windowed CSV/JSON for your gestor); `onFulfilled(productKey \| '*', handler)` / `onRefunded(...)` register fire-and-forget hooks (purchase applied / admin-approved refund — a revenue ledger writes on one, reverses on the other). **Stars-only by design** — Telegram ToS §6.2 forbids third-party payment providers for digital goods. Crypto Pay deferred (MiCA risk); Stripe-outside-Telegram is a future v2 channel. Full compliance memo (Spanish-autónomo seller-of-record analysis, Verifactu vs Crea y Crece, MiCA, Art. 103(m) waiver text, GDPR retention) in `src/bot/payments/CLAUDE.md`. |
|
|
455
455
|
| `@adriangalilea/utils/bot/create` | `createBot<S>({ token?, storage?, initial?, admins?, language?, menu?, access?, payments?, handlers?, worker? })` — the composer (see "One bot file, ideation → production" above). Returns `{ build, session, poll, isMain, fetch }`: `poll()` long-polls, `export default app` is a complete Worker, `app.session(ctx)` / the `handlers` callback's `session(ctx)` is the TYPED accessor for your `S` fields. Owns storage+session wiring; resolves storage per environment (D1 binding → `bot/storage-d1`; `BOT_PERSIST` path → sqlite, `redis://` → redis, lazily-imported optional peers; else announced-ephemeral memory) — or pass `storage: (env) => Storage` when the choice is env-dependent (e.g. a D1 binding not named `DB`). Boot NARRATES the composition (`session: memory …`, `features: language(en,es) · menu(/settings)`) so every implicit decision is visible where you're looking. Runnable demo: `pnpm demo:bot`. |
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram message-draft painter — the lifecycle primitive under
|
|
3
|
+
* `bot/llm`'s `streamChatReply`, dependency-light on purpose (gramio types +
|
|
4
|
+
* `@gramio/format` types only) so a bot with its own rendering pipeline pulls
|
|
5
|
+
* no markdown machinery into its bundle.
|
|
6
|
+
*
|
|
7
|
+
* `createDraftPreview(ctx, { render, throttleMs? })` owns the whole draft
|
|
8
|
+
* lifecycle: throttled FULL-FRAME repaints (drafts replace, never append),
|
|
9
|
+
* the anti-expiry keepalive under Telegram's ~30s draft TTL, serialized
|
|
10
|
+
* sends, reset, quiesce, and {@link streamForensics} (render-regression +
|
|
11
|
+
* upstream-reset warnings, also exported standalone for edit-based viewers).
|
|
12
|
+
* `render` is required: a painter doesn't know markdown — it paints whatever
|
|
13
|
+
* frame you render, plain (`sendMessageDraft`) or rich (`sendRichMessageDraft`).
|
|
14
|
+
* Previews exist in PRIVATE chats only; elsewhere every method no-ops.
|
|
15
|
+
*/
|
|
16
|
+
import type { FormattableString } from "@gramio/format";
|
|
17
|
+
import type { Bot, MessageContext } from "gramio";
|
|
18
|
+
/**
|
|
19
|
+
* Jitter forensics for a streamed preview: a healthy stream only GROWS. A
|
|
20
|
+
* render that shrinks while the accumulated markdown grew means the
|
|
21
|
+
* partial-markdown tail parsed differently between frames (the renderer);
|
|
22
|
+
* accumulated text shrinking is an upstream provider reset. Neither warning
|
|
23
|
+
* firing while a user still sees back-and-forth points at their CLIENT's own
|
|
24
|
+
* draft rendering. Built into {@link createDraftPreview}; exported standalone
|
|
25
|
+
* for edit-based viewers that repaint outside the painter.
|
|
26
|
+
*/
|
|
27
|
+
export declare function streamForensics(label: string): {
|
|
28
|
+
/** Call per outgoing frame with the accumulated-markdown and rendered lengths. */
|
|
29
|
+
frame(accLen: number, renderedLen: number): void;
|
|
30
|
+
/** Call from the upstream reset path with the length being dropped. */
|
|
31
|
+
reset(droppedChars: number): void;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* One rendered preview frame. `text` goes out via `sendMessageDraft` (a
|
|
35
|
+
* FormattableString carries entities; a raw string may carry `parseMode`);
|
|
36
|
+
* `rich` goes out via `sendRichMessageDraft` (Telegram's rich-message HTML).
|
|
37
|
+
*/
|
|
38
|
+
export type DraftFrame = {
|
|
39
|
+
kind: "text";
|
|
40
|
+
text: string | FormattableString;
|
|
41
|
+
parseMode?: "HTML" | "MarkdownV2" | "Markdown";
|
|
42
|
+
} | {
|
|
43
|
+
kind: "rich";
|
|
44
|
+
html: string;
|
|
45
|
+
};
|
|
46
|
+
export interface DraftPreviewOptions {
|
|
47
|
+
/** Ms between repaints. Default 1000. */
|
|
48
|
+
throttleMs?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Render one FULL frame from the accumulated markdown — drafts replace,
|
|
51
|
+
* never append, which is what makes resets and phase switches one cheap
|
|
52
|
+
* frame. Return null to skip (nothing renderable yet).
|
|
53
|
+
*/
|
|
54
|
+
render: (markdown: string) => DraftFrame | null;
|
|
55
|
+
/** Forensics label. Default `draft <id>`. */
|
|
56
|
+
label?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A live message-draft preview: the push-driven primitive under
|
|
60
|
+
* {@link streamChatReply}, exposed for callers whose producer pushes deltas
|
|
61
|
+
* (rather than handing over an event iterable) or whose render/persist paths
|
|
62
|
+
* are their own. Owns the whole draft lifecycle: throttled full-frame
|
|
63
|
+
* repaints, the anti-expiry keepalive, serialized sends, reset, and quiesce.
|
|
64
|
+
* Previews exist in PRIVATE chats only — elsewhere every method no-ops and
|
|
65
|
+
* the caller's persist path is all that happens.
|
|
66
|
+
*/
|
|
67
|
+
export interface DraftPreview {
|
|
68
|
+
/** Accumulated markdown of the current attempt. */
|
|
69
|
+
readonly text: string;
|
|
70
|
+
/** Append a delta and schedule a repaint. */
|
|
71
|
+
append(text: string): void;
|
|
72
|
+
/** Replace the buffer (phase switches); schedules a repaint. */
|
|
73
|
+
set(markdown: string): void;
|
|
74
|
+
/** Upstream failover: drop the buffer with a forensics note; the next tokens repaint from scratch. */
|
|
75
|
+
reset(): void;
|
|
76
|
+
/** Force a repaint of the current frame (render inputs changed, e.g. a cover arrived). */
|
|
77
|
+
repaint(): void;
|
|
78
|
+
/**
|
|
79
|
+
* Paint one last complete frame and stop. Call right before persisting:
|
|
80
|
+
* the preview shows the finished text (not a throttle-stale partial) and
|
|
81
|
+
* its ~30s TTL resets, so the handoff to the real message can't blank.
|
|
82
|
+
*/
|
|
83
|
+
finish(markdown?: string): Promise<void>;
|
|
84
|
+
/** Stop painting without a final frame; the ephemeral draft expires on its own. */
|
|
85
|
+
abort(): Promise<void>;
|
|
86
|
+
}
|
|
87
|
+
export declare function createDraftPreview(ctx: MessageContext<Bot>, opts: DraftPreviewOptions): DraftPreview;
|
|
88
|
+
//# sourceMappingURL=draft.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draft.d.ts","sourceRoot":"","sources":["../../src/bot/draft.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAelD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,KA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
+
* Telegram message-draft painter — the lifecycle primitive under
|
|
3
|
+
* `bot/llm`'s `streamChatReply`, dependency-light on purpose (gramio types +
|
|
4
|
+
* `@gramio/format` types only) so a bot with its own rendering pipeline pulls
|
|
5
|
+
* no markdown machinery into its bundle.
|
|
6
|
+
*
|
|
7
|
+
* `createDraftPreview(ctx, { render, throttleMs? })` owns the whole draft
|
|
8
|
+
* lifecycle: throttled FULL-FRAME repaints (drafts replace, never append),
|
|
9
|
+
* the anti-expiry keepalive under Telegram's ~30s draft TTL, serialized
|
|
10
|
+
* sends, reset, quiesce, and {@link streamForensics} (render-regression +
|
|
11
|
+
* upstream-reset warnings, also exported standalone for edit-based viewers).
|
|
12
|
+
* `render` is required: a painter doesn't know markdown — it paints whatever
|
|
13
|
+
* frame you render, plain (`sendMessageDraft`) or rich (`sendRichMessageDraft`).
|
|
14
|
+
* Previews exist in PRIVATE chats only; elsewhere every method no-ops.
|
|
15
|
+
*/
|
|
16
|
+
// Telegram animates draft repaints; one frame per second is smooth and stays
|
|
17
|
+
// clear of rate limits.
|
|
18
|
+
const THROTTLE_MS = 1000;
|
|
19
|
+
// A streamed draft is ephemeral: Telegram drops it after ~30s. A quiet stretch
|
|
20
|
+
// (LLM latency, an upstream failover) sends no frames, so the preview would
|
|
21
|
+
// age out mid-generation. Re-emit the current frame comfortably under the TTL.
|
|
22
|
+
const KEEPALIVE_MS = 20_000;
|
|
23
|
+
// Non-zero, ever-incrementing draft id per stream so a chat's concurrent /
|
|
24
|
+
// sequential previews don't share an animation timeline. Per-isolate;
|
|
25
|
+
// collisions across isolates are harmless (draft ids are chat-scoped).
|
|
26
|
+
let draftSeq = 0;
|
|
27
|
+
/**
|
|
28
|
+
* Jitter forensics for a streamed preview: a healthy stream only GROWS. A
|
|
29
|
+
* render that shrinks while the accumulated markdown grew means the
|
|
30
|
+
* partial-markdown tail parsed differently between frames (the renderer);
|
|
31
|
+
* accumulated text shrinking is an upstream provider reset. Neither warning
|
|
32
|
+
* firing while a user still sees back-and-forth points at their CLIENT's own
|
|
33
|
+
* draft rendering. Built into {@link createDraftPreview}; exported standalone
|
|
34
|
+
* for edit-based viewers that repaint outside the painter.
|
|
35
|
+
*/
|
|
36
|
+
export function streamForensics(label) {
|
|
37
|
+
let lastAccLen = 0;
|
|
38
|
+
let lastRenderedLen = 0;
|
|
39
|
+
return {
|
|
40
|
+
/** Call per outgoing frame with the accumulated-markdown and rendered lengths. */
|
|
41
|
+
frame(accLen, renderedLen) {
|
|
42
|
+
if (renderedLen < lastRenderedLen && accLen >= lastAccLen)
|
|
43
|
+
console.warn(`[bot/llm] ${label} render regressed · rendered ${lastRenderedLen}→${renderedLen} · acc ${accLen}`);
|
|
44
|
+
lastAccLen = accLen;
|
|
45
|
+
lastRenderedLen = renderedLen;
|
|
46
|
+
},
|
|
47
|
+
/** Call from the upstream reset path with the length being dropped. */
|
|
48
|
+
reset(droppedChars) {
|
|
49
|
+
console.warn(`[bot/llm] ${label} reset (provider failover) · dropped ${droppedChars} chars`);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function createDraftPreview(ctx, opts) {
|
|
54
|
+
const active = ctx.chat.type === "private";
|
|
55
|
+
const chatId = ctx.chat.id;
|
|
56
|
+
const threadId = ctx.threadId;
|
|
57
|
+
const draftId = ++draftSeq;
|
|
58
|
+
const throttle = opts.throttleMs ?? THROTTLE_MS;
|
|
59
|
+
const render = opts.render;
|
|
60
|
+
const forensics = streamForensics(opts.label ?? `draft ${draftId}`);
|
|
61
|
+
let acc = "";
|
|
62
|
+
let dirty = false;
|
|
63
|
+
let stopped = !active;
|
|
64
|
+
let lastFlushAt = 0;
|
|
65
|
+
let timer;
|
|
66
|
+
let flushing;
|
|
67
|
+
let keepalive;
|
|
68
|
+
// Send the current accumulated markdown as one full frame. Best-effort: a
|
|
69
|
+
// rejected preview (rate limit, empty render) is swallowed — the caller's
|
|
70
|
+
// persist path is what matters.
|
|
71
|
+
const sendFrame = async () => {
|
|
72
|
+
const frame = render(acc);
|
|
73
|
+
if (frame === null)
|
|
74
|
+
return;
|
|
75
|
+
if (frame.kind === "rich") {
|
|
76
|
+
forensics.frame(acc.length, frame.html.length);
|
|
77
|
+
await ctx.bot.api
|
|
78
|
+
.sendRichMessageDraft({
|
|
79
|
+
chat_id: chatId,
|
|
80
|
+
draft_id: draftId,
|
|
81
|
+
rich_message: { html: frame.html },
|
|
82
|
+
...(threadId !== undefined ? { message_thread_id: threadId } : {}),
|
|
83
|
+
})
|
|
84
|
+
.catch(() => { });
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const rendered = typeof frame.text === "string" ? frame.text : frame.text.text;
|
|
88
|
+
forensics.frame(acc.length, rendered.length);
|
|
89
|
+
await ctx.bot.api
|
|
90
|
+
.sendMessageDraft({
|
|
91
|
+
chat_id: chatId,
|
|
92
|
+
draft_id: draftId,
|
|
93
|
+
text: frame.text,
|
|
94
|
+
...(frame.parseMode ? { parse_mode: frame.parseMode } : {}),
|
|
95
|
+
...(threadId !== undefined ? { message_thread_id: threadId } : {}),
|
|
96
|
+
})
|
|
97
|
+
.catch(() => { });
|
|
98
|
+
};
|
|
99
|
+
const flush = async () => {
|
|
100
|
+
if (!dirty || stopped)
|
|
101
|
+
return;
|
|
102
|
+
if (flushing)
|
|
103
|
+
await flushing.catch(() => { });
|
|
104
|
+
if (!dirty || stopped)
|
|
105
|
+
return;
|
|
106
|
+
dirty = false;
|
|
107
|
+
lastFlushAt = Date.now();
|
|
108
|
+
flushing = sendFrame();
|
|
109
|
+
await flushing.catch(() => { });
|
|
110
|
+
flushing = undefined;
|
|
111
|
+
if (dirty && !stopped)
|
|
112
|
+
schedule();
|
|
113
|
+
};
|
|
114
|
+
const schedule = () => {
|
|
115
|
+
dirty = true;
|
|
116
|
+
if (stopped || timer)
|
|
117
|
+
return;
|
|
118
|
+
const wait = Math.max(0, throttle - (Date.now() - lastFlushAt));
|
|
119
|
+
timer = setTimeout(() => {
|
|
120
|
+
timer = undefined;
|
|
121
|
+
void flush();
|
|
122
|
+
}, wait);
|
|
123
|
+
};
|
|
124
|
+
// Start the anti-expiry heartbeat once streaming has actually begun. Each
|
|
125
|
+
// tick reuses the normal flush path to re-paint the current frame, but only
|
|
126
|
+
// when the stream has gone quiet — an in-flight or pending flush already
|
|
127
|
+
// refreshes the draft.
|
|
128
|
+
const ensureKeepalive = () => {
|
|
129
|
+
if (keepalive || stopped)
|
|
130
|
+
return;
|
|
131
|
+
keepalive = setInterval(() => {
|
|
132
|
+
if (stopped || dirty || timer || flushing || !acc.trim())
|
|
133
|
+
return;
|
|
134
|
+
schedule();
|
|
135
|
+
}, KEEPALIVE_MS);
|
|
136
|
+
};
|
|
137
|
+
// Stop scheduling and let any in-flight frame settle. Shared by finish and abort.
|
|
138
|
+
const quiesce = async () => {
|
|
139
|
+
stopped = true;
|
|
140
|
+
if (timer) {
|
|
141
|
+
clearTimeout(timer);
|
|
142
|
+
timer = undefined;
|
|
143
|
+
}
|
|
144
|
+
if (keepalive) {
|
|
145
|
+
clearInterval(keepalive);
|
|
146
|
+
keepalive = undefined;
|
|
147
|
+
}
|
|
148
|
+
if (flushing)
|
|
149
|
+
await flushing.catch(() => { });
|
|
150
|
+
};
|
|
151
|
+
return {
|
|
152
|
+
get text() {
|
|
153
|
+
return acc;
|
|
154
|
+
},
|
|
155
|
+
append(text) {
|
|
156
|
+
if (stopped)
|
|
157
|
+
return;
|
|
158
|
+
acc += text;
|
|
159
|
+
ensureKeepalive();
|
|
160
|
+
schedule();
|
|
161
|
+
},
|
|
162
|
+
set(markdown) {
|
|
163
|
+
acc = markdown;
|
|
164
|
+
if (!stopped)
|
|
165
|
+
schedule();
|
|
166
|
+
},
|
|
167
|
+
reset() {
|
|
168
|
+
forensics.reset(acc.length);
|
|
169
|
+
acc = "";
|
|
170
|
+
},
|
|
171
|
+
repaint() {
|
|
172
|
+
if (!stopped && acc.trim())
|
|
173
|
+
schedule();
|
|
174
|
+
},
|
|
175
|
+
async finish(markdown) {
|
|
176
|
+
if (markdown !== undefined)
|
|
177
|
+
acc = markdown;
|
|
178
|
+
const wasActive = !stopped;
|
|
179
|
+
await quiesce();
|
|
180
|
+
if (wasActive)
|
|
181
|
+
await sendFrame().catch(() => { });
|
|
182
|
+
},
|
|
183
|
+
abort: quiesce,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=draft.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draft.js","sourceRoot":"","sources":["../../src/bot/draft.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,6EAA6E;AAC7E,wBAAwB;AACxB,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,+EAA+E;AAC/E,4EAA4E;AAC5E,+EAA+E;AAC/E,MAAM,YAAY,GAAG,MAAM,CAAC;AAE5B,2EAA2E;AAC3E,sEAAsE;AACtE,uEAAuE;AACvE,IAAI,QAAQ,GAAG,CAAC,CAAC;AAEjB;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa;IAC5C,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,eAAe,GAAG,CAAC,CAAC;IACxB,OAAO;QACN,kFAAkF;QAClF,KAAK,CAAC,MAAc,EAAE,WAAmB;YACxC,IAAI,WAAW,GAAG,eAAe,IAAI,MAAM,IAAI,UAAU;gBACxD,OAAO,CAAC,IAAI,CACX,aAAa,KAAK,gCAAgC,eAAe,IAAI,WAAW,UAAU,MAAM,EAAE,CAClG,CAAC;YACH,UAAU,GAAG,MAAM,CAAC;YACpB,eAAe,GAAG,WAAW,CAAC;QAC/B,CAAC;QACD,uEAAuE;QACvE,KAAK,CAAC,YAAoB;YACzB,OAAO,CAAC,IAAI,CACX,aAAa,KAAK,wCAAwC,YAAY,QAAQ,CAC9E,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC;AA0DD,MAAM,UAAU,kBAAkB,CACjC,GAAwB,EACxB,IAAyB;IAEzB,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AC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bot/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
|
package/dist/bot/index.js
CHANGED
package/dist/bot/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bot/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bot/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
|
package/dist/bot/llm.d.ts
CHANGED
|
@@ -17,6 +17,13 @@
|
|
|
17
17
|
* mode enabled in BotFather); elsewhere the preview phase is skipped and
|
|
18
18
|
* only the final send happens.
|
|
19
19
|
*
|
|
20
|
+
* The draft LIFECYCLE (throttle, anti-expiry keepalive, serialized
|
|
21
|
+
* full-frame sends, reset, quiesce, forensics) is `bot/draft`'s
|
|
22
|
+
* `createDraftPreview` — dependency-light on purpose; import it from
|
|
23
|
+
* there when your producer pushes deltas or your rendering / persist
|
|
24
|
+
* paths are your own. This module supplies the markdown render and the
|
|
25
|
+
* split-send persist on top.
|
|
26
|
+
*
|
|
20
27
|
* `ctx.llm.add / .get / …` — HISTORY. Per-(user, thread) conversation
|
|
21
28
|
* buffer in OpenAI `ChatMessage` shape, persisted in the shared
|
|
22
29
|
* `@gramio/session` record under the `llm` field, so the `botMenu`
|
|
@@ -77,8 +84,9 @@ export interface ChatReplyResult {
|
|
|
77
84
|
}
|
|
78
85
|
/**
|
|
79
86
|
* Render an LLM event stream into the chat: live draft previews while
|
|
80
|
-
* generating, entity-split persisted
|
|
81
|
-
*
|
|
87
|
+
* generating (via {@link createDraftPreview}), entity-split persisted
|
|
88
|
+
* message(s) when done. See the module doc for the full contract. Returns the
|
|
89
|
+
* transcript pieces plus the sent messages.
|
|
82
90
|
*/
|
|
83
91
|
export declare function streamChatReply(ctx: MessageContext<Bot>, events: AsyncIterable<LlmStreamEvent>, opts?: StreamChatReplyOptions): Promise<ChatReplyResult>;
|
|
84
92
|
/**
|
package/dist/bot/llm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../../src/bot/llm.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../../src/bot/llm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EACN,KAAK,GAAG,EACR,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,MAAM,EACN,MAAM,QAAQ,CAAC;AAEhB,OAAO,KAAK,EACX,cAAc,EACd,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAI1C,MAAM,WAAW,sBAAsB;IACtC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;IAC7C,+CAA+C;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,aAAa,CAAC,EAAE,UAAU,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,MAA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AAE,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,CAAC,WAAW,CAAC,CAAA;KAAE,CAAC,CAAC;IACzE,sCAAsC;IACtC,QAAQ,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,KAAK,iBAAiB,GAAG;IAAE,GAAG,EAAE,aAAa,CAAA;CAAE,CAAC;AAoChD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,UAAU,GAAI,MAAM,iBAAiB,KAAG,iBA4GpD,CAAC;AAEF,QAAA,MAAM,kBAAkB,GAAI,MAAM;IACjC,aAAa,EAAE,mBAAmB,CAAC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;CACtB;YAK+B,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA4ChD,CAAC"}
|
package/dist/bot/llm.js
CHANGED
|
@@ -17,6 +17,13 @@
|
|
|
17
17
|
* mode enabled in BotFather); elsewhere the preview phase is skipped and
|
|
18
18
|
* only the final send happens.
|
|
19
19
|
*
|
|
20
|
+
* The draft LIFECYCLE (throttle, anti-expiry keepalive, serialized
|
|
21
|
+
* full-frame sends, reset, quiesce, forensics) is `bot/draft`'s
|
|
22
|
+
* `createDraftPreview` — dependency-light on purpose; import it from
|
|
23
|
+
* there when your producer pushes deltas or your rendering / persist
|
|
24
|
+
* paths are your own. This module supplies the markdown render and the
|
|
25
|
+
* split-send persist on top.
|
|
26
|
+
*
|
|
20
27
|
* `ctx.llm.add / .get / …` — HISTORY. Per-(user, thread) conversation
|
|
21
28
|
* buffer in OpenAI `ChatMessage` shape, persisted in the shared
|
|
22
29
|
* `@gramio/session` record under the `llm` field, so the `botMenu`
|
|
@@ -45,93 +52,50 @@ import { expandableBlockquote } from "@gramio/format";
|
|
|
45
52
|
import { markdownToFormattable } from "@gramio/format/markdown";
|
|
46
53
|
import { splitMessage } from "@gramio/split";
|
|
47
54
|
import { Plugin, } from "gramio";
|
|
48
|
-
|
|
49
|
-
// Telegram animates draft repaints; one frame per second is smooth and stays
|
|
50
|
-
// clear of rate limits.
|
|
51
|
-
const THROTTLE_MS = 1000;
|
|
52
|
-
// A streamed draft is ephemeral: Telegram drops it after ~30s. A quiet stretch
|
|
53
|
-
// (LLM latency, an upstream failover) sends no frames, so the preview would
|
|
54
|
-
// age out mid-generation. Re-emit the current frame comfortably under the TTL.
|
|
55
|
-
const KEEPALIVE_MS = 20_000;
|
|
56
|
-
// Non-zero, ever-incrementing draft id per stream so a chat's concurrent /
|
|
57
|
-
// sequential previews don't share an animation timeline. Per-isolate;
|
|
58
|
-
// collisions across isolates are harmless (draft ids are chat-scoped).
|
|
59
|
-
let draftSeq = 0;
|
|
55
|
+
import { createDraftPreview } from "./draft.js";
|
|
60
56
|
/**
|
|
61
57
|
* Render an LLM event stream into the chat: live draft previews while
|
|
62
|
-
* generating, entity-split persisted
|
|
63
|
-
*
|
|
58
|
+
* generating (via {@link createDraftPreview}), entity-split persisted
|
|
59
|
+
* message(s) when done. See the module doc for the full contract. Returns the
|
|
60
|
+
* transcript pieces plus the sent messages.
|
|
64
61
|
*/
|
|
65
62
|
export async function streamChatReply(ctx, events, opts = {}) {
|
|
66
63
|
const reasoningMode = opts.reasoning ?? "preview";
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
const preview = createDraftPreview(ctx, {
|
|
65
|
+
throttleMs: opts.throttleMs,
|
|
66
|
+
render: (markdown) => ({
|
|
67
|
+
kind: "text",
|
|
68
|
+
text: markdownToFormattable(markdown),
|
|
69
|
+
}),
|
|
70
|
+
});
|
|
72
71
|
let content = "";
|
|
73
72
|
let reasoning = "";
|
|
74
73
|
const toolCalls = [];
|
|
75
74
|
let usage = null;
|
|
76
|
-
let lastFrameAt = 0;
|
|
77
|
-
let keepalive;
|
|
78
|
-
let painting = Promise.resolve();
|
|
79
|
-
// Full-frame repaint: drafts replace, never append — which is what makes
|
|
80
|
-
// resets and phase switches (thinking → answer) one cheap frame.
|
|
81
|
-
const paint = (formattable) => {
|
|
82
|
-
lastFrameAt = Date.now();
|
|
83
|
-
// Serialize frames; a rejected send must not kill the stream loop, and
|
|
84
|
-
// the next frame repaints fully anyway.
|
|
85
|
-
painting = painting.then(() => ctx.bot.api
|
|
86
|
-
.sendMessageDraft({
|
|
87
|
-
chat_id: ctx.chat.id,
|
|
88
|
-
draft_id: draftId,
|
|
89
|
-
...(ctx.threadId !== undefined
|
|
90
|
-
? { message_thread_id: ctx.threadId }
|
|
91
|
-
: {}),
|
|
92
|
-
text: formattable,
|
|
93
|
-
})
|
|
94
|
-
.catch(() => { }));
|
|
95
|
-
};
|
|
96
|
-
const frame = () => {
|
|
97
|
-
// The answer owns the preview as soon as it exists; before that, the
|
|
98
|
-
// thinking phase does (unless hidden).
|
|
99
|
-
if (content)
|
|
100
|
-
paint(markdownToFormattable(content));
|
|
101
|
-
else if (reasoning && reasoningMode !== "hidden")
|
|
102
|
-
paint(markdownToFormattable(reasoning));
|
|
103
|
-
};
|
|
104
|
-
if (drafts) {
|
|
105
|
-
keepalive = setInterval(() => {
|
|
106
|
-
if (Date.now() - lastFrameAt >= KEEPALIVE_MS)
|
|
107
|
-
frame();
|
|
108
|
-
}, KEEPALIVE_MS);
|
|
109
|
-
}
|
|
110
75
|
try {
|
|
111
76
|
for await (const event of events) {
|
|
112
77
|
if (event.kind === "delta") {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (first && reasoning && reasoningMode === "message") {
|
|
78
|
+
// Answer taking over from thinking: persist the blockquote first so
|
|
79
|
+
// it lands ABOVE the final answer message, then the answer owns the
|
|
80
|
+
// preview (a phase switch is one cheap full-frame repaint).
|
|
81
|
+
if (content === "") {
|
|
82
|
+
if (reasoning && reasoningMode === "message")
|
|
119
83
|
await persistReasoning(ctx, reasoning);
|
|
120
|
-
|
|
121
|
-
frame();
|
|
84
|
+
preview.set("");
|
|
122
85
|
}
|
|
86
|
+
content += event.text;
|
|
87
|
+
preview.append(event.text);
|
|
123
88
|
}
|
|
124
89
|
else if (event.kind === "reasoning") {
|
|
125
90
|
reasoning += event.text;
|
|
126
|
-
if (
|
|
127
|
-
|
|
91
|
+
if (!content && reasoningMode !== "hidden")
|
|
92
|
+
preview.append(event.text);
|
|
128
93
|
}
|
|
129
94
|
else if (event.kind === "reset") {
|
|
130
95
|
content = "";
|
|
131
96
|
reasoning = "";
|
|
132
97
|
toolCalls.length = 0;
|
|
133
|
-
|
|
134
|
-
paint(""); // empty text = Telegram's "Thinking…" placeholder
|
|
98
|
+
preview.reset();
|
|
135
99
|
}
|
|
136
100
|
else if (event.kind === "tool-call") {
|
|
137
101
|
toolCalls.push({ toolName: event.toolName, input: event.input });
|
|
@@ -141,31 +105,34 @@ export async function streamChatReply(ctx, events, opts = {}) {
|
|
|
141
105
|
}
|
|
142
106
|
}
|
|
143
107
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
await painting.catch(() => { });
|
|
108
|
+
catch (err) {
|
|
109
|
+
await preview.abort();
|
|
110
|
+
throw err;
|
|
148
111
|
}
|
|
149
112
|
content = content.trim();
|
|
150
113
|
reasoning = reasoning.trim();
|
|
151
114
|
// A reasoning-only or tool-call-only turn persists nothing; the ephemeral
|
|
152
115
|
// draft expires on its own.
|
|
153
|
-
if (
|
|
154
|
-
await
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
116
|
+
if (content === "") {
|
|
117
|
+
await preview.abort();
|
|
118
|
+
if (reasoning && reasoningMode === "message")
|
|
119
|
+
await persistReasoning(ctx, reasoning);
|
|
120
|
+
return { content, reasoning, toolCalls, usage, messages: [] };
|
|
121
|
+
}
|
|
122
|
+
// One last complete frame (TTL reset right before the persist), then the
|
|
123
|
+
// real, notifying send(s) consume the ephemeral draft in place.
|
|
124
|
+
await preview.finish(content);
|
|
125
|
+
// Collect the entity-correct parts first, then send with params on the
|
|
126
|
+
// last one — splitMessage's sequential action callback stays the sender
|
|
127
|
+
// so ordering is preserved.
|
|
128
|
+
const parts = [];
|
|
129
|
+
await splitMessage(markdownToFormattable(content), (part) => {
|
|
130
|
+
parts.push(part);
|
|
131
|
+
});
|
|
132
|
+
const messages = [];
|
|
133
|
+
for (let i = 0; i < parts.length; i++) {
|
|
134
|
+
const isLast = i === parts.length - 1;
|
|
135
|
+
messages.push(await ctx.send(parts[i], isLast ? opts.messageParams : undefined));
|
|
169
136
|
}
|
|
170
137
|
return { content, reasoning, toolCalls, usage, messages };
|
|
171
138
|
}
|
package/dist/bot/llm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm.js","sourceRoot":"","sources":["../../src/bot/llm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,OAAO,EAAE,oBAAoB,EAA0B,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAIN,MAAM,GACN,MAAM,QAAQ,CAAC;AAWhB,sEAAsE;AAEtE,6EAA6E;AAC7E,wBAAwB;AACxB,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,+EAA+E;AAC/E,4EAA4E;AAC5E,+EAA+E;AAC/E,MAAM,YAAY,GAAG,MAAM,CAAC;AAE5B,2EAA2E;AAC3E,sEAAsE;AACtE,uEAAuE;AACvE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CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adriangalilea/utils",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.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",
|
|
@@ -64,6 +64,10 @@
|
|
|
64
64
|
"types": "./dist/bot/coalesce.d.ts",
|
|
65
65
|
"default": "./dist/bot/coalesce.js"
|
|
66
66
|
},
|
|
67
|
+
"./bot/draft": {
|
|
68
|
+
"types": "./dist/bot/draft.d.ts",
|
|
69
|
+
"default": "./dist/bot/draft.js"
|
|
70
|
+
},
|
|
67
71
|
"./bot/language": {
|
|
68
72
|
"types": "./dist/bot/language.d.ts",
|
|
69
73
|
"default": "./dist/bot/language.js"
|
|
@@ -166,7 +170,8 @@
|
|
|
166
170
|
"test:flags": "tsx tests/flags-test.ts",
|
|
167
171
|
"test:groups": "tsx tests/groups-test.ts",
|
|
168
172
|
"test:user": "tsx tests/user-test.ts",
|
|
169
|
-
"test:language-picker": "tsx tests/language-picker-test.ts"
|
|
173
|
+
"test:language-picker": "tsx tests/language-picker-test.ts",
|
|
174
|
+
"test:llm": "tsx tests/llm-live-test.ts"
|
|
170
175
|
},
|
|
171
176
|
"keywords": [
|
|
172
177
|
"typescript",
|