@sympoies/dsh-telegram 0.0.0-bootstrap.0 → 0.6.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/LICENSE +1 -2
- package/NOTICE +19 -0
- package/README.md +589 -2
- package/cordis.patch.yml +14 -0
- package/lib/access.d.ts +76 -0
- package/lib/access.d.ts.map +1 -0
- package/lib/access.js +137 -0
- package/lib/access.js.map +1 -0
- package/lib/client.js +835 -0
- package/lib/commands.d.ts +51 -0
- package/lib/commands.d.ts.map +1 -0
- package/lib/commands.js +83 -0
- package/lib/commands.js.map +1 -0
- package/lib/config.d.ts +125 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +97 -0
- package/lib/config.js.map +1 -0
- package/lib/diagnostics.d.ts +58 -0
- package/lib/diagnostics.d.ts.map +1 -0
- package/lib/diagnostics.js +59 -0
- package/lib/diagnostics.js.map +1 -0
- package/lib/failures.d.ts +71 -0
- package/lib/failures.d.ts.map +1 -0
- package/lib/failures.js +139 -0
- package/lib/failures.js.map +1 -0
- package/lib/harness/host.d.ts +106 -0
- package/lib/harness/host.d.ts.map +1 -0
- package/lib/harness/host.js +142 -0
- package/lib/harness/host.js.map +1 -0
- package/lib/harness/message.d.ts +45 -0
- package/lib/harness/message.d.ts.map +1 -0
- package/lib/harness/message.js +28 -0
- package/lib/harness/message.js.map +1 -0
- package/lib/harness/model-selection.d.ts +82 -0
- package/lib/harness/model-selection.d.ts.map +1 -0
- package/lib/harness/model-selection.js +103 -0
- package/lib/harness/model-selection.js.map +1 -0
- package/lib/harness/questions-seam.d.ts +34 -0
- package/lib/harness/questions-seam.d.ts.map +1 -0
- package/lib/harness/questions-seam.js +45 -0
- package/lib/harness/questions-seam.js.map +1 -0
- package/lib/harness/types.d.ts +108 -0
- package/lib/harness/types.d.ts.map +1 -0
- package/lib/harness/types.js +23 -0
- package/lib/harness/types.js.map +1 -0
- package/lib/index.d.ts +65 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +977 -0
- package/lib/index.js.map +1 -0
- package/lib/interact/approvals.d.ts +59 -0
- package/lib/interact/approvals.d.ts.map +1 -0
- package/lib/interact/approvals.js +132 -0
- package/lib/interact/approvals.js.map +1 -0
- package/lib/interact/pending.d.ts +56 -0
- package/lib/interact/pending.d.ts.map +1 -0
- package/lib/interact/pending.js +89 -0
- package/lib/interact/pending.js.map +1 -0
- package/lib/interact/questions.d.ts +100 -0
- package/lib/interact/questions.d.ts.map +1 -0
- package/lib/interact/questions.js +255 -0
- package/lib/interact/questions.js.map +1 -0
- package/lib/interact/surface.d.ts +33 -0
- package/lib/interact/surface.d.ts.map +1 -0
- package/lib/interact/surface.js +39 -0
- package/lib/interact/surface.js.map +1 -0
- package/lib/interact/text-capture.d.ts +38 -0
- package/lib/interact/text-capture.d.ts.map +1 -0
- package/lib/interact/text-capture.js +75 -0
- package/lib/interact/text-capture.js.map +1 -0
- package/lib/media/collect.d.ts +157 -0
- package/lib/media/collect.d.ts.map +1 -0
- package/lib/media/collect.js +235 -0
- package/lib/media/collect.js.map +1 -0
- package/lib/media/extractor.d.ts +117 -0
- package/lib/media/extractor.d.ts.map +1 -0
- package/lib/media/extractor.js +207 -0
- package/lib/media/extractor.js.map +1 -0
- package/lib/media/intake.d.ts +57 -0
- package/lib/media/intake.d.ts.map +1 -0
- package/lib/media/intake.js +115 -0
- package/lib/media/intake.js.map +1 -0
- package/lib/media/limits.d.ts +69 -0
- package/lib/media/limits.d.ts.map +1 -0
- package/lib/media/limits.js +97 -0
- package/lib/media/limits.js.map +1 -0
- package/lib/media/ocr.d.ts +66 -0
- package/lib/media/ocr.d.ts.map +1 -0
- package/lib/media/ocr.js +131 -0
- package/lib/media/ocr.js.map +1 -0
- package/lib/media/screenshot.d.ts +57 -0
- package/lib/media/screenshot.d.ts.map +1 -0
- package/lib/media/screenshot.js +101 -0
- package/lib/media/screenshot.js.map +1 -0
- package/lib/media/vision.d.ts +60 -0
- package/lib/media/vision.d.ts.map +1 -0
- package/lib/media/vision.js +74 -0
- package/lib/media/vision.js.map +1 -0
- package/lib/render/clamp.d.ts +34 -0
- package/lib/render/clamp.d.ts.map +1 -0
- package/lib/render/clamp.js +65 -0
- package/lib/render/clamp.js.map +1 -0
- package/lib/render/escape.d.ts +15 -0
- package/lib/render/escape.d.ts.map +1 -0
- package/lib/render/escape.js +17 -0
- package/lib/render/escape.js.map +1 -0
- package/lib/reply/activity.d.ts +31 -0
- package/lib/reply/activity.d.ts.map +1 -0
- package/lib/reply/activity.js +88 -0
- package/lib/reply/activity.js.map +1 -0
- package/lib/reply/rich-stream.d.ts +173 -0
- package/lib/reply/rich-stream.d.ts.map +1 -0
- package/lib/reply/rich-stream.js +286 -0
- package/lib/reply/rich-stream.js.map +1 -0
- package/lib/reply/split-markdown.d.ts +21 -0
- package/lib/reply/split-markdown.d.ts.map +1 -0
- package/lib/reply/split-markdown.js +87 -0
- package/lib/reply/split-markdown.js.map +1 -0
- package/lib/reply/turn-bridge.d.ts +143 -0
- package/lib/reply/turn-bridge.d.ts.map +1 -0
- package/lib/reply/turn-bridge.js +182 -0
- package/lib/reply/turn-bridge.js.map +1 -0
- package/lib/router.d.ts +415 -0
- package/lib/router.d.ts.map +1 -0
- package/lib/router.js +663 -0
- package/lib/router.js.map +1 -0
- package/lib/secrets.d.ts +30 -0
- package/lib/secrets.d.ts.map +1 -0
- package/lib/secrets.js +51 -0
- package/lib/secrets.js.map +1 -0
- package/lib/session/bindings.d.ts +81 -0
- package/lib/session/bindings.d.ts.map +1 -0
- package/lib/session/bindings.js +170 -0
- package/lib/session/bindings.js.map +1 -0
- package/lib/session/history.d.ts +50 -0
- package/lib/session/history.d.ts.map +1 -0
- package/lib/session/history.js +127 -0
- package/lib/session/history.js.map +1 -0
- package/lib/session/models.d.ts +99 -0
- package/lib/session/models.d.ts.map +1 -0
- package/lib/session/models.js +123 -0
- package/lib/session/models.js.map +1 -0
- package/lib/session/permission.d.ts +83 -0
- package/lib/session/permission.d.ts.map +1 -0
- package/lib/session/permission.js +107 -0
- package/lib/session/permission.js.map +1 -0
- package/lib/session/picker.d.ts +49 -0
- package/lib/session/picker.d.ts.map +1 -0
- package/lib/session/picker.js +107 -0
- package/lib/session/picker.js.map +1 -0
- package/lib/session/preferences.d.ts +55 -0
- package/lib/session/preferences.d.ts.map +1 -0
- package/lib/session/preferences.js +102 -0
- package/lib/session/preferences.js.map +1 -0
- package/lib/session/recovery.d.ts +66 -0
- package/lib/session/recovery.d.ts.map +1 -0
- package/lib/session/recovery.js +112 -0
- package/lib/session/recovery.js.map +1 -0
- package/lib/session/runner.d.ts +223 -0
- package/lib/session/runner.d.ts.map +1 -0
- package/lib/session/runner.js +260 -0
- package/lib/session/runner.js.map +1 -0
- package/lib/session/workspaces.d.ts +28 -0
- package/lib/session/workspaces.d.ts.map +1 -0
- package/lib/session/workspaces.js +53 -0
- package/lib/session/workspaces.js.map +1 -0
- package/lib/telegram/addressing.d.ts +39 -0
- package/lib/telegram/addressing.d.ts.map +1 -0
- package/lib/telegram/addressing.js +81 -0
- package/lib/telegram/addressing.js.map +1 -0
- package/lib/telegram/albums.d.ts +46 -0
- package/lib/telegram/albums.d.ts.map +1 -0
- package/lib/telegram/albums.js +104 -0
- package/lib/telegram/albums.js.map +1 -0
- package/lib/telegram/api.d.ts +238 -0
- package/lib/telegram/api.d.ts.map +1 -0
- package/lib/telegram/api.js +518 -0
- package/lib/telegram/api.js.map +1 -0
- package/lib/telegram/poller.d.ts +59 -0
- package/lib/telegram/poller.d.ts.map +1 -0
- package/lib/telegram/poller.js +94 -0
- package/lib/telegram/poller.js.map +1 -0
- package/lib/telegram/types.d.ts +130 -0
- package/lib/telegram/types.d.ts.map +1 -0
- package/lib/telegram/types.js +9 -0
- package/lib/telegram/types.js.map +1 -0
- package/lib/telegram/typing.d.ts +47 -0
- package/lib/telegram/typing.d.ts.map +1 -0
- package/lib/telegram/typing.js +91 -0
- package/lib/telegram/typing.js.map +1 -0
- package/lib/versions.d.ts +63 -0
- package/lib/versions.d.ts.map +1 -0
- package/lib/versions.js +135 -0
- package/lib/versions.js.map +1 -0
- package/package.json +94 -10
package/lib/router.d.ts
ADDED
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Routing one incoming Telegram update.
|
|
3
|
+
*
|
|
4
|
+
* Every update arrives here and leaves as exactly one of: a refusal, a
|
|
5
|
+
* command, an answer to a pending prompt, a button press, or a prompt for the
|
|
6
|
+
* agent. The order those are tried in is the whole design:
|
|
7
|
+
*
|
|
8
|
+
* 1. **Access first.** Nothing else runs for a user who is not allowed, so no
|
|
9
|
+
* unauthorised text ever reaches the agent, not even as a command.
|
|
10
|
+
* 2. **Pending prompts before commands.** If a question is waiting for typed
|
|
11
|
+
* input, that is what the user is answering — routing it to the agent as a
|
|
12
|
+
* new prompt would strand the question forever.
|
|
13
|
+
* 3. **Commands before prompts.** Otherwise `/new` would be a message asking
|
|
14
|
+
* the agent about the word "new".
|
|
15
|
+
*
|
|
16
|
+
* Failures are reported into the chat rather than thrown: an update handler
|
|
17
|
+
* that throws would abort the long-poll loop and take the bot offline.
|
|
18
|
+
*/
|
|
19
|
+
import type { AccessPolicy } from './access.js';
|
|
20
|
+
import type { ChatTarget } from './interact/surface.js';
|
|
21
|
+
import type { TextCapture } from './interact/text-capture.js';
|
|
22
|
+
import type { Logger } from './harness/types.js';
|
|
23
|
+
import type { MediaCollector, PromptPart } from './media/collect.js';
|
|
24
|
+
import type { TelegramUpdate } from './telegram/types.js';
|
|
25
|
+
import type { StatusRow } from './session/runner.js';
|
|
26
|
+
/** What the router needs to drive a conversation's agent. */
|
|
27
|
+
export interface AgentRunner {
|
|
28
|
+
/** Deliver a prompt, starting or resuming the chat's session as needed. */
|
|
29
|
+
prompt(target: ChatTarget, content: readonly PromptPart[]): Promise<void>;
|
|
30
|
+
/** Forget the current session so the next prompt opens a fresh one. */
|
|
31
|
+
reset(target: ChatTarget): Promise<void>;
|
|
32
|
+
/** Cancel the in-flight turn; resolves to whether anything was running. */
|
|
33
|
+
stop(target: ChatTarget): Promise<boolean>;
|
|
34
|
+
/** What this conversation is, as rows the caller renders. */
|
|
35
|
+
status(target: ChatTarget): Promise<StatusRow[]>;
|
|
36
|
+
}
|
|
37
|
+
/** The bits of the Bot API the router itself uses. */
|
|
38
|
+
export interface RouterChat {
|
|
39
|
+
sendMessage(options: {
|
|
40
|
+
chatId: string;
|
|
41
|
+
html: string;
|
|
42
|
+
threadId?: number;
|
|
43
|
+
}): Promise<unknown>;
|
|
44
|
+
answerCallbackQuery(id: string, text?: string): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Post markdown for Telegram to render. Absent on a deployment below Bot API
|
|
47
|
+
* 10.1, where a table would arrive as pipes and dashes.
|
|
48
|
+
*/
|
|
49
|
+
sendRichMessage?(options: {
|
|
50
|
+
chatId: string;
|
|
51
|
+
markdown: string;
|
|
52
|
+
threadId?: number;
|
|
53
|
+
}): Promise<{
|
|
54
|
+
messageId: number;
|
|
55
|
+
}>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The conversation's working directory, and how to change it.
|
|
59
|
+
*
|
|
60
|
+
* Narrowed to what the router needs so `/cd` is testable without a filesystem:
|
|
61
|
+
* `inspect` is the only call that touches disk.
|
|
62
|
+
*/
|
|
63
|
+
export interface WorkspaceControl {
|
|
64
|
+
/** The directory this conversation's next session will open in. */
|
|
65
|
+
current(target: ChatTarget): string;
|
|
66
|
+
/** Work out which directory an argument names; undefined when it names none. */
|
|
67
|
+
resolve(input: string, current: string): string | undefined;
|
|
68
|
+
/** What is actually at that path. */
|
|
69
|
+
inspect(directory: string): Promise<'directory' | 'file' | 'missing' | 'denied'>;
|
|
70
|
+
/** Remember it for this conversation. */
|
|
71
|
+
set(target: ChatTarget, directory: string): Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The conversation's model, and how to change it.
|
|
75
|
+
*
|
|
76
|
+
* Narrowed to what the router needs, so `/model` is testable without a
|
|
77
|
+
* provider catalog behind it.
|
|
78
|
+
*/
|
|
79
|
+
export interface ModelControl {
|
|
80
|
+
/**
|
|
81
|
+
* What lies underneath this conversation's choice, when it has made one.
|
|
82
|
+
*
|
|
83
|
+
* Two surfaces show related state — this command and the settings page —
|
|
84
|
+
* and neither used to admit the other existed. Saying which layer is
|
|
85
|
+
* answering is what stops the page looking like it is lying.
|
|
86
|
+
*/
|
|
87
|
+
origin?(target: ChatTarget): string | undefined;
|
|
88
|
+
/** The route in force, rendered the way it is typed back in. */
|
|
89
|
+
describe(target: ChatTarget): string;
|
|
90
|
+
/** Every configured provider and model, as Telegram HTML. */
|
|
91
|
+
list(): Promise<string>;
|
|
92
|
+
/** Take a user's words and, when they name one model, adopt it. */
|
|
93
|
+
choose(target: ChatTarget, input: string): Promise<{
|
|
94
|
+
kind: 'route';
|
|
95
|
+
route: string;
|
|
96
|
+
} | {
|
|
97
|
+
kind: 'ambiguous';
|
|
98
|
+
candidates: readonly string[];
|
|
99
|
+
} | {
|
|
100
|
+
kind: 'unknown';
|
|
101
|
+
}>;
|
|
102
|
+
/** Return the conversation to the deployment's own model. */
|
|
103
|
+
clear(target: ChatTarget): Promise<void>;
|
|
104
|
+
}
|
|
105
|
+
/** The conversation's reasoning effort, and how to change it. */
|
|
106
|
+
export interface EffortControl {
|
|
107
|
+
/**
|
|
108
|
+
* What lies underneath this conversation's choice, when it has made one.
|
|
109
|
+
*
|
|
110
|
+
* Two surfaces show related state — this command and the settings page —
|
|
111
|
+
* and neither used to admit the other existed. Saying which layer is
|
|
112
|
+
* answering is what stops the page looking like it is lying.
|
|
113
|
+
*/
|
|
114
|
+
origin?(target: ChatTarget): string | undefined;
|
|
115
|
+
/** The effort in force, in words. */
|
|
116
|
+
describe(target: ChatTarget): string;
|
|
117
|
+
/** The model it belongs to, for naming it in a refusal. */
|
|
118
|
+
model(target: ChatTarget): string;
|
|
119
|
+
/** What that model offers; empty when it offers no choice. */
|
|
120
|
+
options(target: ChatTarget): Promise<readonly string[]>;
|
|
121
|
+
/** Adopt one, or undefined when the words name none. */
|
|
122
|
+
choose(target: ChatTarget, input: string): Promise<string | undefined>;
|
|
123
|
+
/** Return the conversation to the model's own default. */
|
|
124
|
+
clear(target: ChatTarget): Promise<void>;
|
|
125
|
+
}
|
|
126
|
+
/** The model that reads images for this conversation, and how to change it. */
|
|
127
|
+
export interface VisionControl {
|
|
128
|
+
/**
|
|
129
|
+
* What lies underneath this conversation's choice, when it has made one.
|
|
130
|
+
*
|
|
131
|
+
* Two surfaces show related state — this command and the settings page —
|
|
132
|
+
* and neither used to admit the other existed. Saying which layer is
|
|
133
|
+
* answering is what stops the page looking like it is lying.
|
|
134
|
+
*/
|
|
135
|
+
origin?(target: ChatTarget): string | undefined;
|
|
136
|
+
/** The reader in force, in words. */
|
|
137
|
+
describe(target: ChatTarget): string;
|
|
138
|
+
/** Adopt one, or say why the words named none. */
|
|
139
|
+
choose(target: ChatTarget, input: string): Promise<{
|
|
140
|
+
kind: 'route';
|
|
141
|
+
route: string;
|
|
142
|
+
} | {
|
|
143
|
+
kind: 'ambiguous';
|
|
144
|
+
candidates: readonly string[];
|
|
145
|
+
} | {
|
|
146
|
+
kind: 'unknown';
|
|
147
|
+
}>;
|
|
148
|
+
/** Read images with nothing — the conversation's own model must cope. */
|
|
149
|
+
disable(target: ChatTarget): Promise<void>;
|
|
150
|
+
/** Return the conversation to whatever the deployment configured. */
|
|
151
|
+
clear(target: ChatTarget): Promise<void>;
|
|
152
|
+
}
|
|
153
|
+
/** What the agent may do here, and how to change it. */
|
|
154
|
+
export interface PermissionControlSeam {
|
|
155
|
+
/**
|
|
156
|
+
* What lies underneath this conversation's choice, when it has made one.
|
|
157
|
+
*
|
|
158
|
+
* Two surfaces show related state — this command and the settings page —
|
|
159
|
+
* and neither used to admit the other existed. Saying which layer is
|
|
160
|
+
* answering is what stops the page looking like it is lying.
|
|
161
|
+
*/
|
|
162
|
+
origin?(target: ChatTarget): string | undefined;
|
|
163
|
+
/** The preset in force, in words. */
|
|
164
|
+
describe(target: ChatTarget): string;
|
|
165
|
+
/** Every preset the deployment defines. */
|
|
166
|
+
options(): readonly string[];
|
|
167
|
+
/** Adopt one, or undefined when the words name none. */
|
|
168
|
+
choose(target: ChatTarget, input: string): Promise<string | undefined>;
|
|
169
|
+
/** Return the conversation to the deployment's own preset. */
|
|
170
|
+
clear(target: ChatTarget): Promise<void>;
|
|
171
|
+
}
|
|
172
|
+
/** What `/diag` reports. */
|
|
173
|
+
export interface DiagnosticsSource {
|
|
174
|
+
report(): Promise<{
|
|
175
|
+
/** Connection facts, as rows. */
|
|
176
|
+
readonly status: readonly StatusRow[];
|
|
177
|
+
/**
|
|
178
|
+
* Which harness services this deployment actually composed.
|
|
179
|
+
*
|
|
180
|
+
* The most useful line in the report: a seam that is absent explains a
|
|
181
|
+
* whole class of "why does it not do that" without anyone having to guess.
|
|
182
|
+
*/
|
|
183
|
+
readonly seams: readonly {
|
|
184
|
+
readonly name: string;
|
|
185
|
+
readonly present: boolean;
|
|
186
|
+
}[];
|
|
187
|
+
readonly failures: readonly {
|
|
188
|
+
at: string;
|
|
189
|
+
level: string;
|
|
190
|
+
message: string;
|
|
191
|
+
}[];
|
|
192
|
+
}>;
|
|
193
|
+
}
|
|
194
|
+
/** Capturing the screen and putting it in the chat. */
|
|
195
|
+
export interface ScreenControl {
|
|
196
|
+
/**
|
|
197
|
+
* Take one and send it.
|
|
198
|
+
*
|
|
199
|
+
* @returns undefined on success, or a sentence saying what went wrong.
|
|
200
|
+
*/
|
|
201
|
+
send(target: ChatTarget): Promise<string | undefined>;
|
|
202
|
+
}
|
|
203
|
+
/** Shows that a conversation is being worked on, until released. */
|
|
204
|
+
export interface TypingHold {
|
|
205
|
+
hold(target: ChatTarget): () => void;
|
|
206
|
+
}
|
|
207
|
+
/** Routes callback data to whichever feature owns it. */
|
|
208
|
+
export interface CallbackHandler {
|
|
209
|
+
handleCallback(data: string | undefined): boolean;
|
|
210
|
+
}
|
|
211
|
+
/** Construction options. */
|
|
212
|
+
export interface UpdateRouterOptions {
|
|
213
|
+
readonly chat: RouterChat;
|
|
214
|
+
readonly access: AccessPolicy;
|
|
215
|
+
readonly questions: CallbackHandler;
|
|
216
|
+
readonly approvals: CallbackHandler;
|
|
217
|
+
/** Owns the button that starts a fresh conversation after a stuck turn. */
|
|
218
|
+
readonly recovery?: CallbackHandler;
|
|
219
|
+
/**
|
|
220
|
+
* Keeps Telegram's own indicator alive while the bot works. Absent simply
|
|
221
|
+
* leaves the chat quiet until the reply arrives.
|
|
222
|
+
*/
|
|
223
|
+
readonly typing?: TypingHold;
|
|
224
|
+
/** Absent leaves every conversation in the configured directory. */
|
|
225
|
+
readonly workspace?: WorkspaceControl;
|
|
226
|
+
/** Absent leaves every conversation on the deployment's model. */
|
|
227
|
+
readonly models?: ModelControl;
|
|
228
|
+
/**
|
|
229
|
+
* Whether this conversation's model accepts images itself. Absent decides
|
|
230
|
+
* refusals the way they were decided before any model could see.
|
|
231
|
+
*/
|
|
232
|
+
readonly modelSees?: (target: ChatTarget) => Promise<boolean>;
|
|
233
|
+
/** Offers this chat's earlier conversations. Absent makes `/new` one-way. */
|
|
234
|
+
readonly sessions?: CallbackHandler & {
|
|
235
|
+
offer(target: ChatTarget): Promise<void>;
|
|
236
|
+
};
|
|
237
|
+
/** Absent leaves every conversation on the model's own reasoning effort. */
|
|
238
|
+
readonly effort?: EffortControl;
|
|
239
|
+
/** Absent leaves every conversation on the deployment's permission preset. */
|
|
240
|
+
readonly permission?: PermissionControlSeam;
|
|
241
|
+
/** Absent leaves every conversation on the deployment's image reader. */
|
|
242
|
+
readonly vision?: VisionControl;
|
|
243
|
+
/** Takes and sends a picture of the screen. Absent means screenshots are off. */
|
|
244
|
+
readonly screen?: ScreenControl;
|
|
245
|
+
/** What the plugin can see about itself, for `/diag`. */
|
|
246
|
+
readonly diagnostics?: DiagnosticsSource;
|
|
247
|
+
readonly textCapture: TextCapture;
|
|
248
|
+
readonly runner: AgentRunner;
|
|
249
|
+
/**
|
|
250
|
+
* How long to wait for the rest of an album. Injected so tests need no clock.
|
|
251
|
+
*/
|
|
252
|
+
readonly albumWindowMs?: number;
|
|
253
|
+
/**
|
|
254
|
+
* Turns a message's attachments into prompt content. Absent leaves the bot
|
|
255
|
+
* text-only, which is what it was before media was wired up.
|
|
256
|
+
*/
|
|
257
|
+
readonly media?: MediaCollector;
|
|
258
|
+
/**
|
|
259
|
+
* This bot's own user id, so a reply to something it said is recognised as
|
|
260
|
+
* addressing it. A group conversation continues that way rather than by
|
|
261
|
+
* @mentioning the bot on every line.
|
|
262
|
+
*/
|
|
263
|
+
readonly botId?: number;
|
|
264
|
+
/**
|
|
265
|
+
* Whether a group message must address the bot to be answered. Off makes the
|
|
266
|
+
* bot answer every allowlisted message in the room, which is the older
|
|
267
|
+
* behaviour and rarely what anyone wants.
|
|
268
|
+
*/
|
|
269
|
+
readonly requireAddressing?: boolean;
|
|
270
|
+
/** This bot's username, so `/cmd@other_bot` is left alone in groups. */
|
|
271
|
+
readonly botUsername?: string;
|
|
272
|
+
/**
|
|
273
|
+
* Strips secrets from anything posted back into a chat. Agent failures are
|
|
274
|
+
* reported to the user verbatim, and an error raised deep in a provider can
|
|
275
|
+
* quote a credential it was given.
|
|
276
|
+
*/
|
|
277
|
+
readonly redact?: (text: string) => string;
|
|
278
|
+
readonly logger?: Logger;
|
|
279
|
+
}
|
|
280
|
+
export declare class UpdateRouter {
|
|
281
|
+
private readonly options;
|
|
282
|
+
/**
|
|
283
|
+
* Albums still arriving, if this deployment reads attachments at all.
|
|
284
|
+
*
|
|
285
|
+
* Owned here rather than injected because its whole job is to defer part of
|
|
286
|
+
* this class's own work back to it.
|
|
287
|
+
*/
|
|
288
|
+
private readonly albums;
|
|
289
|
+
private readonly logger;
|
|
290
|
+
constructor(options: UpdateRouterOptions);
|
|
291
|
+
/** Stop waiting on albums still arriving — the plugin is unloading. */
|
|
292
|
+
dispose(): void;
|
|
293
|
+
/**
|
|
294
|
+
* Handle one update. Never throws: a thrown handler would stop the poll loop.
|
|
295
|
+
*
|
|
296
|
+
* @param update - one raw update from `getUpdates`.
|
|
297
|
+
*/
|
|
298
|
+
handle(update: TelegramUpdate): Promise<void>;
|
|
299
|
+
/** A button press: acknowledge first, then route it. */
|
|
300
|
+
private onCallback;
|
|
301
|
+
/** An incoming message: access, pending prompt, command, then prompt. */
|
|
302
|
+
private onMessage;
|
|
303
|
+
/**
|
|
304
|
+
* Handle a whole album as one message.
|
|
305
|
+
*
|
|
306
|
+
* Access and addressing were already decided for each part as it arrived, so
|
|
307
|
+
* what is left is the part a single photo would have taken.
|
|
308
|
+
*
|
|
309
|
+
* @param messages - the album's parts, in the order they were sent.
|
|
310
|
+
*/
|
|
311
|
+
private onAlbum;
|
|
312
|
+
/**
|
|
313
|
+
* A user who may not drive the agent. An unclaimed bot still accepts
|
|
314
|
+
* `/claim`, because that is the only way it ever becomes usable.
|
|
315
|
+
*/
|
|
316
|
+
private onUnauthorized;
|
|
317
|
+
/** Run one command. */
|
|
318
|
+
private onCommand;
|
|
319
|
+
/** Hand a prompt to the agent, reporting a failure into the chat. */
|
|
320
|
+
private runPrompt;
|
|
321
|
+
/**
|
|
322
|
+
* Report what this plugin can see about itself.
|
|
323
|
+
*
|
|
324
|
+
* Exists because several profiles compose no log sink at all, so a plugin
|
|
325
|
+
* that only logs its failures is silent about them. Every fault found here
|
|
326
|
+
* so far was found by someone noticing odd behaviour in a chat and asking —
|
|
327
|
+
* the seam list in particular would have shown at a glance that Telegram
|
|
328
|
+
* agents were joining no preset, and therefore had almost no tools.
|
|
329
|
+
*
|
|
330
|
+
* @param target - the conversation asking.
|
|
331
|
+
*/
|
|
332
|
+
private onDiagnostics;
|
|
333
|
+
/**
|
|
334
|
+
* Send a picture of the screen the harness is running on.
|
|
335
|
+
*
|
|
336
|
+
* @param target - the conversation to send it to.
|
|
337
|
+
*/
|
|
338
|
+
private onScreenshot;
|
|
339
|
+
/**
|
|
340
|
+
* Everything about this conversation worth knowing in one message.
|
|
341
|
+
*
|
|
342
|
+
* The settings live behind four commands, and having to run all four to
|
|
343
|
+
* answer "what am I actually talking to right now" is four commands too
|
|
344
|
+
* many — especially the permission line, which is the one worth being sure
|
|
345
|
+
* about before asking for something destructive.
|
|
346
|
+
*
|
|
347
|
+
* @param target - the conversation.
|
|
348
|
+
*/
|
|
349
|
+
private describeConversation;
|
|
350
|
+
/**
|
|
351
|
+
* Show or change how hard the model thinks before answering.
|
|
352
|
+
*
|
|
353
|
+
* The options come from the model itself: `low`/`medium`/`high` is one
|
|
354
|
+
* provider's vocabulary rather than everyone's, and offering an effort a
|
|
355
|
+
* model does not have would fail the turn instead of the command.
|
|
356
|
+
*
|
|
357
|
+
* @param target - the conversation.
|
|
358
|
+
* @param args - what followed `/effort`.
|
|
359
|
+
*/
|
|
360
|
+
private onEffort;
|
|
361
|
+
/**
|
|
362
|
+
* Show or change which model reads images for this conversation.
|
|
363
|
+
*
|
|
364
|
+
* `off` is a real answer rather than the absence of one: a conversation
|
|
365
|
+
* whose own model can see wants no reader at all, and saying so has to
|
|
366
|
+
* outrank whatever the deployment configured.
|
|
367
|
+
*
|
|
368
|
+
* @param target - the conversation.
|
|
369
|
+
* @param args - what followed `/vision`.
|
|
370
|
+
*/
|
|
371
|
+
private onVision;
|
|
372
|
+
/**
|
|
373
|
+
* Show or change what the agent is allowed to do here.
|
|
374
|
+
*
|
|
375
|
+
* Applied to the conversation in flight as well as recorded, because the
|
|
376
|
+
* point of tightening it is usually the turn about to run.
|
|
377
|
+
*
|
|
378
|
+
* @param target - the conversation.
|
|
379
|
+
* @param args - what followed `/permission`.
|
|
380
|
+
*/
|
|
381
|
+
private onPermission;
|
|
382
|
+
/**
|
|
383
|
+
* Show, list, or change the model this conversation talks to.
|
|
384
|
+
*
|
|
385
|
+
* No reset here, unlike `/cd`: the harness reads a mutable selection while
|
|
386
|
+
* assembling each step, so a model change lands on the very next message and
|
|
387
|
+
* the conversation carries on.
|
|
388
|
+
*
|
|
389
|
+
* @param target - the conversation.
|
|
390
|
+
* @param args - what followed `/model`.
|
|
391
|
+
*/
|
|
392
|
+
private onModel;
|
|
393
|
+
/**
|
|
394
|
+
* Show or change the conversation's working directory.
|
|
395
|
+
*
|
|
396
|
+
* Changing it necessarily starts a fresh conversation: the sandbox derives
|
|
397
|
+
* its writable root from the session's cwd, and that root is fixed when the
|
|
398
|
+
* session opens. Rather than fail a move the user reasonably expects to
|
|
399
|
+
* work, the reset is done for them and said out loud.
|
|
400
|
+
*
|
|
401
|
+
* @param target - the conversation.
|
|
402
|
+
* @param args - what followed `/cd`; empty means "tell me where I am".
|
|
403
|
+
*/
|
|
404
|
+
private onChangeDirectory;
|
|
405
|
+
/**
|
|
406
|
+
* Whether this conversation's own model reads images.
|
|
407
|
+
*
|
|
408
|
+
* Never fatal: an unanswerable question here means the refusal is decided
|
|
409
|
+
* the way it was before there was a model that could see.
|
|
410
|
+
*/
|
|
411
|
+
private modelSees;
|
|
412
|
+
/** Send one plain notice into a conversation, swallowing delivery failures. */
|
|
413
|
+
private say;
|
|
414
|
+
}
|
|
415
|
+
//# sourceMappingURL=router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpE,OAAO,KAAK,EAAmB,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAC1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,C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