telegram-agent-kit 0.1.0 → 0.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
CHANGED
|
@@ -147,7 +147,7 @@ You implement these; the kit drives them.
|
|
|
147
147
|
| Interface | Shape | Role |
|
|
148
148
|
| -------------- | --------------------------------------------------------------------- | ---- |
|
|
149
149
|
| `BotClient` | `sendMessage`, `sendRichMessage`, `sendPhoto`, `sendChatAction`, `sendMessageDraft`, `sendRichMessageDraft` | Raw transport. Each throws `TelegramApiError` on a Bot API error. |
|
|
150
|
-
| `AgentStream` | `(input, { threadId, signal }) => AsyncIterable<RenderEvent>`
|
|
150
|
+
| `AgentStream` | `(input, { threadId, signal, configurable }) => AsyncIterable<RenderEvent>` | Your agent. `threadId` **must** reach it so the checkpointer writes to the snapshotted thread. `configurable` is an optional pass-through bag forwarded verbatim from `runTelegramTurn`'s `configurable` option. |
|
|
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
|
|
|
@@ -175,6 +175,8 @@ appends `token` text to the live draft and treats an `error` event as a rollback
|
|
|
175
175
|
**Bridge**
|
|
176
176
|
|
|
177
177
|
- `runTelegramTurn(opts)` — orchestrate one turn. Never throws out; every failure is caught and logged.
|
|
178
|
+
Accepts an optional `configurable` bag forwarded to your `AgentStream` as `context.configurable`,
|
|
179
|
+
for passing per-turn data (e.g. `pendingImages`) to the agent without widening the core input type.
|
|
178
180
|
- `sendReply(client, chatId, reply, opts, signal?)` / `sendText(...)` — the send path on its own.
|
|
179
181
|
- Types: `BotClient`, `AgentStream`, `Checkpointer`, `ThreadStore`, `RenderEvent`, `ChatKey`, `Logger`.
|
|
180
182
|
|
|
@@ -186,6 +188,10 @@ appends `token` text to the live draft and treats an `error` event as a rollback
|
|
|
186
188
|
### Optional entry — `telegram-agent-kit/deepagents`
|
|
187
189
|
|
|
188
190
|
- `toAgentStream(agent)` → `AgentStream` — adapts a deepagents/langgraph agent to the kit's contract.
|
|
191
|
+
The `context.configurable` bag is merged into the LangGraph `RunnableConfig`, but the reserved keys
|
|
192
|
+
`thread_id`, `thread_ts`, `checkpoint_id`, `checkpoint_ns`, `checkpoint_map`, and `run_id` — plus any
|
|
193
|
+
`__pregel_*` LangGraph internal-execution key — are stripped so the kit retains full control over
|
|
194
|
+
checkpoint routing and execution.
|
|
189
195
|
- `streamAgent(agent, input, config, signal?)` — lower-level event stream if you need direct control.
|
|
190
196
|
|
|
191
197
|
> `@langchain/core` and `deepagents` are **type-only, optional** peers. The built
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RenderEvent, A as AgentStream } from '../interfaces-
|
|
1
|
+
import { R as RenderEvent, A as AgentStream } from '../interfaces-FQIM1SDq.js';
|
|
2
2
|
import { RunnableConfig } from '@langchain/core/runnables';
|
|
3
3
|
import { createDeepAgent } from 'deepagents';
|
|
4
4
|
|
|
@@ -12,9 +12,11 @@ type StreamAgentInput = {
|
|
|
12
12
|
declare function streamAgent(agent: Agent$1, input: StreamAgentInput, config: RunnableConfig, signal?: AbortSignal): AsyncIterable<RenderEvent>;
|
|
13
13
|
|
|
14
14
|
type Agent = Parameters<typeof streamAgent>[0];
|
|
15
|
-
/** Adapt a deepagents agent to the kit's runtime-agnostic AgentStream:
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
/** Adapt a deepagents agent to the kit's runtime-agnostic AgentStream: merge the
|
|
16
|
+
* caller's `configurable` bag (with reserved checkpoint-routing keys stripped)
|
|
17
|
+
* under the kit-owned `thread_id`, and forward the signal. The kit's `thread_id`
|
|
18
|
+
* is spread last so it always wins, even if stripping ever misses a key. This is
|
|
19
|
+
* the ONLY place the langgraph config shape lives. */
|
|
18
20
|
declare function toAgentStream(agent: Agent): AgentStream;
|
|
19
21
|
|
|
20
22
|
export { RenderEvent, type StreamAgentInput, streamAgent, toAgentStream };
|
package/dist/deepagents/index.js
CHANGED
|
@@ -62,14 +62,38 @@ async function* streamAgent(agent, input, config, signal) {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
// src/deepagents/to-agent-stream.ts
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
var RESERVED = /* @__PURE__ */ new Set([
|
|
66
|
+
"thread_id",
|
|
67
|
+
// Legacy alias for `checkpoint_id`: the installed @langchain/langgraph-checkpoint
|
|
68
|
+
// still resolves it via getCheckpointId() (`checkpoint_id || thread_ts`), so a
|
|
69
|
+
// caller could resume from a hand-picked checkpoint through this key alone even
|
|
70
|
+
// with `checkpoint_id` stripped. Strip it too.
|
|
71
|
+
"thread_ts",
|
|
72
|
+
"checkpoint_id",
|
|
73
|
+
"checkpoint_ns",
|
|
74
|
+
"checkpoint_map",
|
|
75
|
+
"run_id"
|
|
76
|
+
]);
|
|
77
|
+
var RESERVED_PREFIX = "__pregel_";
|
|
78
|
+
function stripReservedKeys(configurable) {
|
|
79
|
+
return Object.fromEntries(
|
|
80
|
+
Object.entries(configurable).filter(
|
|
81
|
+
([k]) => !RESERVED.has(k) && !k.startsWith(RESERVED_PREFIX)
|
|
82
|
+
)
|
|
71
83
|
);
|
|
72
84
|
}
|
|
85
|
+
function toAgentStream(agent) {
|
|
86
|
+
return (input, context) => {
|
|
87
|
+
const extra = context.configurable ?? {};
|
|
88
|
+
const safe = stripReservedKeys(extra);
|
|
89
|
+
return streamAgent(
|
|
90
|
+
agent,
|
|
91
|
+
input,
|
|
92
|
+
{ configurable: { ...safe, thread_id: context.threadId } },
|
|
93
|
+
context.signal
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
73
97
|
export {
|
|
74
98
|
streamAgent,
|
|
75
99
|
toAgentStream
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as BotClient, L as Logger, C as ChatKey, A as AgentStream, a as Checkpointer, T as ThreadStore } from './interfaces-
|
|
2
|
-
export { b as AgentStreamContext, R as RenderEvent, S as StreamInput } from './interfaces-
|
|
1
|
+
import { B as BotClient, L as Logger, C as ChatKey, A as AgentStream, a as Checkpointer, T as ThreadStore } from './interfaces-FQIM1SDq.js';
|
|
2
|
+
export { b as AgentStreamContext, R as RenderEvent, S as StreamInput } from './interfaces-FQIM1SDq.js';
|
|
3
3
|
|
|
4
4
|
type SendOpts = {
|
|
5
5
|
rich: boolean;
|
|
@@ -78,6 +78,7 @@ type RunTelegramTurnOpts = {
|
|
|
78
78
|
};
|
|
79
79
|
makeDraftStreamer?: (deps: DraftStreamerDeps) => DraftStreamer;
|
|
80
80
|
draftConstants?: Partial<DraftConstants>;
|
|
81
|
+
configurable?: Record<string, unknown>;
|
|
81
82
|
};
|
|
82
83
|
declare function runTelegramTurn(opts: RunTelegramTurnOpts): Promise<void>;
|
|
83
84
|
|
package/dist/index.js
CHANGED
|
@@ -731,7 +731,7 @@ async function runTelegramTurn(opts) {
|
|
|
731
731
|
let errored = false;
|
|
732
732
|
for await (const ev of opts.agentStream(
|
|
733
733
|
{ messages: [{ role: "user", content: opts.userText }] },
|
|
734
|
-
{ threadId, signal: opts.signal }
|
|
734
|
+
{ threadId, signal: opts.signal, configurable: opts.configurable }
|
|
735
735
|
)) {
|
|
736
736
|
if (ev.type === "token") {
|
|
737
737
|
reply += ev.text;
|
|
@@ -67,6 +67,7 @@ type StreamInput = {
|
|
|
67
67
|
type AgentStreamContext = {
|
|
68
68
|
threadId: string;
|
|
69
69
|
signal?: AbortSignal;
|
|
70
|
+
configurable?: Record<string, unknown>;
|
|
70
71
|
};
|
|
71
72
|
type AgentStream = (input: StreamInput, context: AgentStreamContext) => AsyncIterable<RenderEvent>;
|
|
72
73
|
type Checkpointer = {
|
package/package.json
CHANGED