stitchkit 0.123.4 → 0.123.5

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/CHANGELOG.md CHANGED
@@ -15,6 +15,20 @@ additive**; the first breaking change landed in 0.10.0. Grep the file for
15
15
 
16
16
  ## [Unreleased]
17
17
 
18
+ ## [0.123.5] - 2026-11-13
19
+
20
+ ### Fixed
21
+
22
+ - `stitchkit/telegram` — **Widget sends and message widget data edits spend the outbound
23
+ budget.** `sendWidget`, `sendSharedWidget` and `editMessageWidgetData` each cost one message
24
+ under `telegramOutboundBudget().run`, share the send schedule and apply the existing 429
25
+ pause policy. An inline widget edit without a chat pauses the token on 429. `answerWidgetQuery`
26
+ and `editSharedWidgetData` remain free; the budget never retries a call.
27
+ **Affects:** `stitchkit/telegram` telegramOutboundBudget, TelegramOutboundBudget(run)
28
+
29
+ - Tests — settle the manual clock's rejected advance before asserting its callback error,
30
+ and verify that a subsequent advance runs the remaining timer after the failure.
31
+
18
32
  ## [0.123.4] - 2026-11-12
19
33
 
20
34
  ### Added
@@ -940,6 +940,9 @@ var SEND_METHODS = new Set([
940
940
  "sendGiveaway",
941
941
  "sendLivePhoto",
942
942
  "sendRichMessage",
943
+ "sendWidget",
944
+ "sendSharedWidget",
945
+ "editMessageWidgetData",
943
946
  "copyMessage",
944
947
  "copyMessages",
945
948
  "forwardMessage",
@@ -11,7 +11,8 @@
11
11
  * another budget. The unit is a Telegram message: `sendMediaGroup` and
12
12
  * `sendPaidMedia` cost their media length, `copyMessages` and
13
13
  * `forwardMessages` cost their message ids, and the follow-up call to action
14
- * after an album is one more message.
14
+ * after an album is one more message. `sendWidget`, `sendSharedWidget` and
15
+ * `editMessageWidgetData` each cost one, including an inline widget edit.
15
16
  *
16
17
  * Two lanes share that one rate. An `interactive` call is granted before any
17
18
  * `bulk` call that is waiting, so a person's reply never queues behind a
@@ -23,8 +24,8 @@
23
24
  * words a group's limit, a chat's pace and the bot's own limit alike, and only
24
25
  * the addressee differs, so one chat's refusal is read as that chat's. Refusals
25
26
  * from several chats inside a short window are read as the bot's own limit and
26
- * pause the token, as does a 429 with no chat to blame. A 429 on an edit or a
27
- * read concerns that call and pauses nothing. A network failure or a 5xx is
27
+ * pause the token, as does a 429 with no chat to blame. A 429 on a call that
28
+ * spends no message concerns that call and pauses nothing. A network failure or a 5xx is
28
29
  * returned to the caller unchanged: repeating a send whose external outcome is
29
30
  * unknown is the caller's decision, and a primitive that retried it would turn
30
31
  * one unknown message into two.
@@ -134,8 +135,8 @@ export interface TelegramOutboundBudget {
134
135
  pauseAfter(error: unknown, options?: TelegramOutboundChatOptions): void;
135
136
  /**
136
137
  * Wait out the current pause without spending a token, and that chat's own
137
- * with `chatId`. For a retry path that is not a send (edit, delete) and does
138
- * not go through `acquire`.
138
+ * with `chatId`. For a retry path that spends no message (`editMessageText`,
139
+ * delete) and does not go through `acquire`.
139
140
  */
140
141
  waitUntilResumed(signal?: AbortSignal, options?: TelegramOutboundChatOptions): Promise<void>;
141
142
  /** Measured counters. It never contains the token. */
@@ -1 +1 @@
1
- {"version":3,"file":"outbound-budget.d.ts","sourceRoot":"","sources":["../../src/telegram/outbound-budget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AA8BH,oFAAoF;AACpF,MAAM,MAAM,oBAAoB,GAAG,aAAa,GAAG,MAAM,CAAC;AAE1D,MAAM,WAAW,4BAA4B;IAC3C,mFAAmF;IACnF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IACvC;;;OAGG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,mEAAmE;IACnE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC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C,EACH,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACtB,OAAO,CAAC,EAAE,2BAA2B,GACpC,OAAO,CAAC,CAAC,CAAC,CAAC;IACd;;;;OAIG;IACH,OAAO,CACL,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,2BAA2B,GACpC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,sGAAsG;IACtG,KAAK,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC;;;;OAIG;IACH,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,IAAI,CAAC;IACxE;;;;OAIG;IACH,gBAAgB,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7F,sDAAsD;IACtD,KAAK,IAAI,2BAA2B,CAAC;CACtC;AAkGD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,4BAA4B,GACnC,sBAAsB,CA+CxB"}
@@ -1,4 +1,4 @@
1
- /** One message-producing call costs one; an empty or malformed array still costs one. */
1
+ /** One counted call costs one; an empty or malformed weighted array still costs one. */
2
2
  export declare function sendCost(method: string, payload: unknown): number;
3
3
  /** The chat a call addresses; a Bot API `chat_id` is a number or an `@username`. */
4
4
  export declare function chatOf(payload: unknown): string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"outbound-cost.d.ts","sourceRoot":"","sources":["../../src/telegram/outbound-cost.ts"],"names":[],"mappings":"AA2CA,yFAAyF;AACzF,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAMjE;AAED,oFAAoF;AACpF,wBAAgB,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAI3D"}
1
+ {"version":3,"file":"outbound-cost.d.ts","sourceRoot":"","sources":["../../src/telegram/outbound-cost.ts"],"names":[],"mappings":"AA8CA,wFAAwF;AACxF,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAMjE;AAED,oFAAoF;AACpF,wBAAgB,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAI3D"}
package/llms/telegram.txt CHANGED
@@ -123,9 +123,13 @@ cast, and a send cancelled in the queue then waits for its slot and fails as
123
123
  128-bit identity, never the credential, and `stats()` contains no token.
124
124
  - **A message is the unit.** `sendMediaGroup` and `sendPaidMedia` cost their
125
125
  media length, `copyMessages` and `forwardMessages` cost their message ids, and
126
- a follow-up call to action after an album costs one more. Reads and edits
127
- (`getMe`, `getFile`, `editMessage*`, `deleteMessage`, `sendChatAction`) do not
128
- spend the budget.
126
+ a follow-up call to action after an album costs one more. `sendWidget`,
127
+ `sendSharedWidget` and `editMessageWidgetData` each cost one; Telegram counts
128
+ [a widget data edit as a sent message](https://core.telegram.org/bots/widgets#changing-the-state),
129
+ including an inline edit without `chat_id`. `answerWidgetQuery` and
130
+ `editSharedWidgetData` cost zero, as do reads and ordinary edits
131
+ (`getMe`, `getFile`, `editMessageText`, `deleteMessage`, `sendChatAction`).
132
+ The shared widget's own edit limit is separate from this token budget.
129
133
  - **Two lanes share one rate.** A call is `interactive` by default; a campaign passes
130
134
  `{ lane: 'bulk' }` to `run` or `acquire`, or installs
131
135
  `telegramBudgetTransformer(budget, { lane: 'bulk' })` on its own `Api`. A waiting
@@ -163,7 +167,7 @@ cast, and a send cancelled in the queue then waits for its slot and fails as
163
167
  The refusal may be thrown or returned: a client transformer sits below the
164
168
  place where grammY turns Telegram's `{ ok: false, error_code: 429, … }` body into
165
169
  a `GrammyError`, so `run` reads that body too and hands it back unchanged.
166
- A 429 from an edit or a read concerns that call and pauses nothing;
170
+ A 429 from a zero-cost call concerns that call and pauses nothing;
167
171
  `budget.pauseAfter(error, { chatId })` remains for a caller who decides otherwise, and pauses
168
172
  the token when it names no chat. A network failure is rethrown unchanged and stays `unknown`; a 5xx
169
173
  is rethrown unchanged and stays `server-error`. Neither is retried by the
@@ -176,10 +180,11 @@ cast, and a send cancelled in the queue then waits for its slot and fails as
176
180
  `not-dispatched`, safe to repeat); a send cancelled after it was handed on is
177
181
  the client's own error — not evidence that Telegram did not accept it — so
178
182
  keep the outcome unknown rather than retrying it as a definite failure.
179
- - **Non-send retries wait without spending.** An edit or delete retry that got
183
+ - **Non-send retries wait without spending.** An ordinary edit or delete retry that got
180
184
  a 429 records the pause with `budget.pauseAfter(error, { chatId })`, then uses
181
185
  `await budget.waitUntilResumed(signal, { chatId })`; it shares that chat's pause
182
186
  and the token's, and takes no message slot. Without `chatId` it pauses the token.
187
+ An `editMessageWidgetData` retry uses `run` instead: it costs another message.
183
188
 
184
189
  `telegramBroadcastSender` and `telegramOperatorSender` still send through
185
190
  `callTelegramBotApi`; they are not a second budget. Their returned function does
package/llms-full.txt CHANGED
@@ -16653,9 +16653,13 @@ cast, and a send cancelled in the queue then waits for its slot and fails as
16653
16653
  128-bit identity, never the credential, and `stats()` contains no token.
16654
16654
  - **A message is the unit.** `sendMediaGroup` and `sendPaidMedia` cost their
16655
16655
  media length, `copyMessages` and `forwardMessages` cost their message ids, and
16656
- a follow-up call to action after an album costs one more. Reads and edits
16657
- (`getMe`, `getFile`, `editMessage*`, `deleteMessage`, `sendChatAction`) do not
16658
- spend the budget.
16656
+ a follow-up call to action after an album costs one more. `sendWidget`,
16657
+ `sendSharedWidget` and `editMessageWidgetData` each cost one; Telegram counts
16658
+ [a widget data edit as a sent message](https://core.telegram.org/bots/widgets#changing-the-state),
16659
+ including an inline edit without `chat_id`. `answerWidgetQuery` and
16660
+ `editSharedWidgetData` cost zero, as do reads and ordinary edits
16661
+ (`getMe`, `getFile`, `editMessageText`, `deleteMessage`, `sendChatAction`).
16662
+ The shared widget's own edit limit is separate from this token budget.
16659
16663
  - **Two lanes share one rate.** A call is `interactive` by default; a campaign passes
16660
16664
  `{ lane: 'bulk' }` to `run` or `acquire`, or installs
16661
16665
  `telegramBudgetTransformer(budget, { lane: 'bulk' })` on its own `Api`. A waiting
@@ -16693,7 +16697,7 @@ cast, and a send cancelled in the queue then waits for its slot and fails as
16693
16697
  The refusal may be thrown or returned: a client transformer sits below the
16694
16698
  place where grammY turns Telegram's `{ ok: false, error_code: 429, … }` body into
16695
16699
  a `GrammyError`, so `run` reads that body too and hands it back unchanged.
16696
- A 429 from an edit or a read concerns that call and pauses nothing;
16700
+ A 429 from a zero-cost call concerns that call and pauses nothing;
16697
16701
  `budget.pauseAfter(error, { chatId })` remains for a caller who decides otherwise, and pauses
16698
16702
  the token when it names no chat. A network failure is rethrown unchanged and stays `unknown`; a 5xx
16699
16703
  is rethrown unchanged and stays `server-error`. Neither is retried by the
@@ -16706,10 +16710,11 @@ cast, and a send cancelled in the queue then waits for its slot and fails as
16706
16710
  `not-dispatched`, safe to repeat); a send cancelled after it was handed on is
16707
16711
  the client's own error — not evidence that Telegram did not accept it — so
16708
16712
  keep the outcome unknown rather than retrying it as a definite failure.
16709
- - **Non-send retries wait without spending.** An edit or delete retry that got
16713
+ - **Non-send retries wait without spending.** An ordinary edit or delete retry that got
16710
16714
  a 429 records the pause with `budget.pauseAfter(error, { chatId })`, then uses
16711
16715
  `await budget.waitUntilResumed(signal, { chatId })`; it shares that chat's pause
16712
16716
  and the token's, and takes no message slot. Without `chatId` it pauses the token.
16717
+ An `editMessageWidgetData` retry uses `run` instead: it costs another message.
16713
16718
 
16714
16719
  `telegramBroadcastSender` and `telegramOperatorSender` still send through
16715
16720
  `callTelegramBotApi`; they are not a second budget. Their returned function does
package/llms.txt CHANGED
@@ -45,7 +45,7 @@ Load the slice for each entrypoint your code imports — `import … from 'stitc
45
45
  - **stitchkit/testing**: [llms/testing.txt](llms/testing.txt) 33.7 KB
46
46
  - **stitchkit/agent-runtime/sandbox**: [llms/agent-runtime-sandbox.txt](llms/agent-runtime-sandbox.txt) 8.3 KB
47
47
  - **stitchkit/files**: [llms/files.txt](llms/files.txt) 6.2 KB
48
- - **stitchkit/telegram**: [llms/telegram.txt](llms/telegram.txt) 34.3 KB → [llms/telegram.2.txt](llms/telegram.2.txt) 13.8 KB
48
+ - **stitchkit/telegram**: [llms/telegram.txt](llms/telegram.txt) 34.7 KB → [llms/telegram.2.txt](llms/telegram.2.txt) 13.8 KB
49
49
  - **stitchkit/telegram/grammy**: [llms/telegram-grammy.txt](llms/telegram-grammy.txt) 1.2 KB
50
50
  - **stitchkit/telegram/html**: [llms/telegram-html.txt](llms/telegram-html.txt) 2.7 KB
51
51
  - **stitchkit/telegram/voice**: [llms/telegram-voice.txt](llms/telegram-voice.txt) 1.9 KB
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stitchkit",
3
- "version": "0.123.4",
3
+ "version": "0.123.5",
4
4
  "description": "Contract-first backend framework — one defineContract() into an HTTP API, MCP tools, AI-agent tools and a typed client. Bun and Node.",
5
5
  "keywords": [
6
6
  "bun",