telegram-agent-kit 0.3.0 → 0.3.1
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 +5 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.js +15 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -151,8 +151,9 @@ You implement these; the kit drives them.
|
|
|
151
151
|
| `Checkpointer` | `{ snapshot(threadId), rollback(threadId, id) }` | Per-thread snapshot/rollback for clean recovery on a failed turn. |
|
|
152
152
|
| `ThreadStore` | `{ resolve(chatKey, now), touch(chatKey, now) }` | Maps `{ chatId, agentId }` to a thread id (so two bots over one chat id don't collide). |
|
|
153
153
|
|
|
154
|
-
A `RenderEvent` is
|
|
155
|
-
|
|
154
|
+
A `RenderEvent` is either `token` or `error`: `token` text is appended to the live draft,
|
|
155
|
+
an `error` rolls the turn back, logs the message, and — if you pass `errorNotice` — tells
|
|
156
|
+
the user in the chat instead of going silent.
|
|
156
157
|
|
|
157
158
|
## API reference
|
|
158
159
|
|
|
@@ -177,6 +178,8 @@ appends `token` text to the live draft and treats an `error` event as a rollback
|
|
|
177
178
|
- `runTelegramTurn(opts)` — orchestrate one turn. Never throws out; every failure is caught and logged.
|
|
178
179
|
Accepts an optional `configurable` bag forwarded to your `AgentStream` as `context.configurable`,
|
|
179
180
|
for passing per-turn data (e.g. `pendingImages`) to the agent without widening the core input type.
|
|
181
|
+
Pass `errorNotice` (plain text, your language) to have a failed turn say so in the chat —
|
|
182
|
+
omit it and the user just sees the draft stop, which reads as being ignored.
|
|
180
183
|
- `sendReply(client, chatId, reply, opts, signal?)` / `sendText(...)` — the send path on its own.
|
|
181
184
|
- Types: `BotClient`, `AgentStream`, `Checkpointer`, `ThreadStore`, `RenderEvent`, `ChatKey`, `Logger`.
|
|
182
185
|
|
package/dist/index.d.ts
CHANGED
|
@@ -78,6 +78,10 @@ type RunTelegramTurnOpts = {
|
|
|
78
78
|
};
|
|
79
79
|
draftConstants?: Partial<DraftConstants>;
|
|
80
80
|
configurable?: Record<string, unknown>;
|
|
81
|
+
/** Plain-text line sent to the chat when the stream errors out (model chain
|
|
82
|
+
* exhausted, graph threw). Without it the turn returns silently and the user
|
|
83
|
+
* sees only a draft that stops moving — indistinguishable from being ignored. */
|
|
84
|
+
errorNotice?: string;
|
|
81
85
|
};
|
|
82
86
|
declare function runTelegramTurn(opts: RunTelegramTurnOpts): Promise<void>;
|
|
83
87
|
|
package/dist/index.js
CHANGED
|
@@ -724,7 +724,7 @@ async function runTelegramTurn(opts) {
|
|
|
724
724
|
});
|
|
725
725
|
draft.start();
|
|
726
726
|
let reply = "";
|
|
727
|
-
let
|
|
727
|
+
let errorMessage;
|
|
728
728
|
for await (const ev of opts.agentStream(
|
|
729
729
|
{ messages: [{ role: "user", content: opts.userText }] },
|
|
730
730
|
{ threadId, signal: opts.signal, configurable: opts.configurable }
|
|
@@ -732,15 +732,27 @@ async function runTelegramTurn(opts) {
|
|
|
732
732
|
if (ev.type === "token") {
|
|
733
733
|
reply += ev.text;
|
|
734
734
|
draft.push(reply);
|
|
735
|
-
} else if (ev.type === "error")
|
|
735
|
+
} else if (ev.type === "error") errorMessage = ev.message;
|
|
736
736
|
}
|
|
737
|
-
if (
|
|
737
|
+
if (errorMessage !== void 0) {
|
|
738
|
+
log.error("telegram turn errored", {
|
|
739
|
+
chatId: opts.chatKey.chatId,
|
|
740
|
+
err: errorMessage
|
|
741
|
+
});
|
|
738
742
|
draftTornDown = true;
|
|
739
743
|
await draft.abort().catch(() => {
|
|
740
744
|
});
|
|
741
745
|
await opts.checkpointer.rollback(rollback.threadId, rollback.checkpointId).catch(
|
|
742
746
|
(e) => log.error("telegram rollback failed", { err: String(e) })
|
|
743
747
|
);
|
|
748
|
+
if (opts.errorNotice && !opts.signal?.aborted) {
|
|
749
|
+
await opts.client.sendMessage(
|
|
750
|
+
{ chatId: opts.chatKey.chatId, text: opts.errorNotice },
|
|
751
|
+
opts.signal
|
|
752
|
+
).catch(
|
|
753
|
+
(e) => log.error("telegram error notice failed", { err: String(e) })
|
|
754
|
+
);
|
|
755
|
+
}
|
|
744
756
|
return;
|
|
745
757
|
}
|
|
746
758
|
draftTornDown = true;
|
package/package.json
CHANGED