@leitwerk-dev/telegram 0.1.0 → 0.1.2

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.
Files changed (57) hide show
  1. package/dist/index.d.ts +654 -15
  2. package/dist/index.js +3838 -51
  3. package/dist/index.js.map +1 -1
  4. package/package.json +6 -6
  5. package/dist/actions.d.ts +0 -9
  6. package/dist/actions.d.ts.map +0 -1
  7. package/dist/actions.js +0 -32
  8. package/dist/actions.js.map +0 -1
  9. package/dist/bridge.d.ts +0 -132
  10. package/dist/bridge.d.ts.map +0 -1
  11. package/dist/bridge.js +0 -2032
  12. package/dist/bridge.js.map +0 -1
  13. package/dist/config.d.ts +0 -25
  14. package/dist/config.d.ts.map +0 -1
  15. package/dist/config.js +0 -70
  16. package/dist/config.js.map +0 -1
  17. package/dist/fake-telegram-client.d.ts +0 -82
  18. package/dist/fake-telegram-client.d.ts.map +0 -1
  19. package/dist/fake-telegram-client.js +0 -107
  20. package/dist/fake-telegram-client.js.map +0 -1
  21. package/dist/form-session.d.ts +0 -143
  22. package/dist/form-session.d.ts.map +0 -1
  23. package/dist/form-session.js +0 -218
  24. package/dist/form-session.js.map +0 -1
  25. package/dist/grammy-telegram-client.d.ts +0 -131
  26. package/dist/grammy-telegram-client.d.ts.map +0 -1
  27. package/dist/grammy-telegram-client.js +0 -151
  28. package/dist/grammy-telegram-client.js.map +0 -1
  29. package/dist/index.d.ts.map +0 -1
  30. package/dist/launch-session.d.ts +0 -103
  31. package/dist/launch-session.d.ts.map +0 -1
  32. package/dist/launch-session.js +0 -435
  33. package/dist/launch-session.js.map +0 -1
  34. package/dist/markdown-html.d.ts +0 -29
  35. package/dist/markdown-html.d.ts.map +0 -1
  36. package/dist/markdown-html.js +0 -259
  37. package/dist/markdown-html.js.map +0 -1
  38. package/dist/mermaid-image.d.ts +0 -2
  39. package/dist/mermaid-image.d.ts.map +0 -1
  40. package/dist/mermaid-image.js +0 -99
  41. package/dist/mermaid-image.js.map +0 -1
  42. package/dist/process-feed.d.ts +0 -58
  43. package/dist/process-feed.d.ts.map +0 -1
  44. package/dist/process-feed.js +0 -165
  45. package/dist/process-feed.js.map +0 -1
  46. package/dist/process-thread-store.d.ts +0 -18
  47. package/dist/process-thread-store.d.ts.map +0 -1
  48. package/dist/process-thread-store.js +0 -74
  49. package/dist/process-thread-store.js.map +0 -1
  50. package/dist/topic-title.d.ts +0 -7
  51. package/dist/topic-title.d.ts.map +0 -1
  52. package/dist/topic-title.js +0 -29
  53. package/dist/topic-title.js.map +0 -1
  54. package/dist/types.d.ts +0 -118
  55. package/dist/types.d.ts.map +0 -1
  56. package/dist/types.js +0 -19
  57. package/dist/types.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,19 +1,658 @@
1
- import { type LeitwerkExtensionModule } from "@leitwerk-dev/process-sdk";
2
- import type { TelegramClient } from "./types.js";
3
- export declare const telegramClientToken: import("@leitwerk-dev/process-sdk").CapabilityToken<TelegramClient>;
4
- export declare const manifest: {
1
+ import * as _leitwerk_dev_process_sdk from '@leitwerk-dev/process-sdk';
2
+ import { CoreServerSetupDeps, ServerExtensionLogger, ServerExtensionEventMap, FormDefinition, ProcessActionModelPreviewLike, ModelProfileOptionSummaryLike, FormFieldDefinition, LauncherFieldOptionDefinition, LauncherFieldDefinition, LaunchModelConfigInputLike, UiLauncherSummary, LauncherModelConfigSchemaLike, LauncherModelConfigPreviewLike, LauncherValidationError, ProcessLaunchPlan, LeitwerkExtensionModule } from '@leitwerk-dev/process-sdk';
3
+ import { ProcessQuestionRequest, QuestionAnswerDraft, ProcessInstance } from '@leitwerk-dev/domain';
4
+
5
+ type TelegramParseMode = "HTML";
6
+ interface TelegramInlineKeyboardButton {
7
+ text: string;
8
+ callbackData: string;
9
+ }
10
+ interface TelegramReplyMarkupBase {
11
+ inlineKeyboard?: readonly (readonly TelegramInlineKeyboardButton[])[];
12
+ forceReply?: true;
13
+ inputFieldPlaceholder?: string;
14
+ selective?: boolean;
15
+ }
16
+ interface TelegramInlineKeyboard extends TelegramReplyMarkupBase {
17
+ inlineKeyboard: readonly (readonly TelegramInlineKeyboardButton[])[];
18
+ }
19
+ interface TelegramForceReply extends TelegramReplyMarkupBase {
20
+ forceReply: true;
21
+ }
22
+ type TelegramReplyMarkup = TelegramInlineKeyboard | TelegramForceReply;
23
+ interface TelegramUserRef {
24
+ id: number;
25
+ username?: string;
26
+ }
27
+ interface TelegramTextUpdate {
28
+ messageId: number;
29
+ chatId: string;
30
+ messageThreadId?: number;
31
+ from: TelegramUserRef | null;
32
+ text: string;
33
+ }
34
+ interface TelegramCallbackUpdate {
35
+ id: string;
36
+ chatId: string;
37
+ messageThreadId?: number;
38
+ from: TelegramUserRef | null;
39
+ data: string;
40
+ }
41
+ interface TelegramForumTopicCreatedUpdate {
42
+ messageId: number;
43
+ chatId: string;
44
+ messageThreadId: number;
45
+ from: TelegramUserRef | null;
46
+ }
47
+ interface TelegramForumTopicClosedUpdate {
48
+ messageId: number;
49
+ chatId: string;
50
+ messageThreadId: number;
51
+ from: TelegramUserRef | null;
52
+ }
53
+ type TelegramTextHandler = (update: TelegramTextUpdate) => void | Promise<void>;
54
+ type TelegramCallbackHandler = (update: TelegramCallbackUpdate) => void | Promise<void>;
55
+ type TelegramForumTopicCreatedHandler = (update: TelegramForumTopicCreatedUpdate) => void | Promise<void>;
56
+ type TelegramForumTopicClosedHandler = (update: TelegramForumTopicClosedUpdate) => void | Promise<void>;
57
+ interface TelegramSendMessageInput {
58
+ chatId: string;
59
+ messageThreadId?: number;
60
+ text: string;
61
+ parseMode?: TelegramParseMode;
62
+ replyMarkup?: TelegramReplyMarkup;
63
+ }
64
+ interface TelegramSendFileInput {
65
+ chatId: string;
66
+ messageThreadId?: number;
67
+ bytes: Uint8Array;
68
+ filename: string;
69
+ caption?: string;
70
+ parseMode?: TelegramParseMode;
71
+ }
72
+ interface TelegramSentMessage {
73
+ messageId: number;
74
+ }
75
+ interface TelegramClient {
76
+ start(): Promise<void>;
77
+ stop(): Promise<void>;
78
+ createForumTopic(input: {
79
+ chatId: string;
80
+ name: string;
81
+ }): Promise<{
82
+ messageThreadId: number;
83
+ }>;
84
+ editForumTopic(input: {
85
+ chatId: string;
86
+ messageThreadId: number;
87
+ name: string;
88
+ }): Promise<void>;
89
+ closeForumTopic(input: {
90
+ chatId: string;
91
+ messageThreadId: number;
92
+ }): Promise<void>;
93
+ sendMessage(input: TelegramSendMessageInput): Promise<TelegramSentMessage>;
94
+ sendPhoto(input: TelegramSendFileInput): Promise<TelegramSentMessage>;
95
+ sendDocument(input: TelegramSendFileInput): Promise<TelegramSentMessage>;
96
+ answerCallbackQuery(input: {
97
+ callbackQueryId: string;
98
+ text?: string;
99
+ showAlert?: boolean;
100
+ }): Promise<void>;
101
+ onText(handler: TelegramTextHandler): void;
102
+ onCallback(handler: TelegramCallbackHandler): void;
103
+ onForumTopicCreated(handler: TelegramForumTopicCreatedHandler): void;
104
+ onForumTopicClosed(handler: TelegramForumTopicClosedHandler): void;
105
+ }
106
+ declare abstract class BaseTelegramClientEventRegistrar {
107
+ protected textHandlers: Set<TelegramTextHandler>;
108
+ protected callbackHandlers: Set<TelegramCallbackHandler>;
109
+ protected forumTopicCreatedHandlers: Set<TelegramForumTopicCreatedHandler>;
110
+ protected forumTopicClosedHandlers: Set<TelegramForumTopicClosedHandler>;
111
+ onText(handler: TelegramTextHandler): void;
112
+ onCallback(handler: TelegramCallbackHandler): void;
113
+ onForumTopicCreated(handler: TelegramForumTopicCreatedHandler): void;
114
+ onForumTopicClosed(handler: TelegramForumTopicClosedHandler): void;
115
+ }
116
+ interface TelegramProcessThread {
117
+ mode: "forum_topic";
118
+ chatId: string;
119
+ messageThreadId: number;
120
+ topicName: string;
121
+ }
122
+
123
+ interface TelegramExtensionConfig {
124
+ enabled: boolean;
125
+ botToken: string;
126
+ allowUserIds: readonly number[];
127
+ delivery: {
128
+ forumChatId: string;
129
+ };
130
+ markdown: {
131
+ maxChars: number;
132
+ };
133
+ topicTitleTemplate: string;
134
+ actionModelSelection: {
135
+ enabled: boolean;
136
+ };
137
+ allowedModelProfileIds: readonly string[];
138
+ }
139
+ type TelegramConfigResult = {
140
+ ok: true;
141
+ config: TelegramExtensionConfig;
142
+ } | {
143
+ ok: false;
144
+ errors: readonly string[];
145
+ };
146
+ declare function normalizeTelegramConfig(rawValue: unknown): TelegramConfigResult;
147
+
148
+ declare class TelegramBridge {
149
+ private readonly input;
150
+ private readonly store;
151
+ private readonly sessions;
152
+ private readonly launchSessions;
153
+ private readonly launchCallbacks;
154
+ private nextLaunchCallbackId;
155
+ private readonly processModelSelection;
156
+ private readonly threadEligibleInstanceIds;
157
+ private readonly introSentInstanceIds;
158
+ private readonly closedThreadKeys;
159
+ private readonly sentResultTurnRecordKeys;
160
+ private readonly deferredCompletedLifecycleProcesses;
161
+ private readonly queues;
162
+ private readonly lastTurnInfo;
163
+ constructor(input: {
164
+ config: TelegramExtensionConfig;
165
+ deps: CoreServerSetupDeps;
166
+ client: TelegramClient;
167
+ logger?: ServerExtensionLogger;
168
+ });
169
+ start(): Promise<void>;
170
+ /**
171
+ * After a server restart the in-memory lastTurnInfo map is empty.
172
+ * Rebuild it from the most recent turn_started event for every non-terminal
173
+ * process that already has a Telegram thread, so that /status and actions
174
+ * prompts show the correct path label without waiting for the next turn.
175
+ */
176
+ private seedLastTurnInfoFromEvents;
177
+ stop(): Promise<void>;
178
+ register(events: {
179
+ on<K extends keyof ServerExtensionEventMap & string>(event: K, handler: (payload: ServerExtensionEventMap[K]) => void | Promise<void>): void;
180
+ }): void;
181
+ private enqueue;
182
+ private onProcessCreated;
183
+ private onProcessUpdated;
184
+ private onTurnStarted;
185
+ private onQuestionRequested;
186
+ private resolveTurnModelLabel;
187
+ private filterProfiles;
188
+ private listSelectableProfiles;
189
+ private filterLaunchSchemaAvailableProfiles;
190
+ private onTurnFailed;
191
+ private sendPublishedResult;
192
+ private onLeafOutcome;
193
+ private onTurnOutcome;
194
+ private ensureThread;
195
+ private getThread;
196
+ private sendProcessIntro;
197
+ private closeThread;
198
+ private syncThreadTitle;
199
+ private sendActionsForProcess;
200
+ private handleForumTopicCreated;
201
+ private handleForumTopicClosed;
202
+ private abortProcessForClosedTopic;
203
+ private handleText;
204
+ private handleUnmappedTopicText;
205
+ private handleProcessText;
206
+ private handleCallback;
207
+ private resolveCallbackInstance;
208
+ private answerCallback;
209
+ private getLauncher;
210
+ private sendUnmappedTopicHelp;
211
+ private sendLauncherList;
212
+ private startLaunchSession;
213
+ private handleLaunchSessionText;
214
+ private executeLaunchCallbackCommand;
215
+ private getLaunchModelSchema;
216
+ private getLaunchModelPreview;
217
+ private getActiveLaunchSession;
218
+ private getLaunchContext;
219
+ private sendLaunchReviewForSession;
220
+ private finishLaunchModelEditAndReview;
221
+ private startLaunchModelEdit;
222
+ private executeLaunchModelCallbackCommand;
223
+ private finishLaunchModelEdit;
224
+ private handleLaunchModelText;
225
+ private continueAfterLaunchModelResult;
226
+ private resolveLaunchRecentValues;
227
+ private recordLaunchRecentValuesBestEffort;
228
+ private resolveLaunchOptions;
229
+ private sendNextLaunchModelPrompt;
230
+ private sendNextLaunchPrompt;
231
+ private sendLaunchReview;
232
+ private prepareLaunchSession;
233
+ private executeLaunchSession;
234
+ private createLaunchCallbackCommand;
235
+ private readLaunchCallbackCommand;
236
+ private buildLauncherListKeyboard;
237
+ private buildLaunchConfirmationKeyboard;
238
+ private buildLaunchModelReplyMarkup;
239
+ private buildLaunchFieldReplyMarkup;
240
+ private formatRecentValueButtonText;
241
+ private buildActionFormFieldReplyMarkup;
242
+ private sendActionFormFieldPrompt;
243
+ private executeCallbackCommand;
244
+ private sendCurrentSessionPrompt;
245
+ private maybeSelectActionModel;
246
+ private resolveActionModelSession;
247
+ private executeActionModelSession;
248
+ private sendActionModelSwitchWarning;
249
+ private handleActionModelSelect;
250
+ private handleActionModelSkip;
251
+ private sendActionModelPrompt;
252
+ private buildActionModelReplyMarkup;
253
+ private applyActionFormStep;
254
+ private applyActionFormText;
255
+ private applyActionFormSkip;
256
+ private skipCurrentActionFormField;
257
+ private handleSessionText;
258
+ private handleActionModelText;
259
+ private maybeSelectRecoveryModel;
260
+ private handleRecoveryModelSelect;
261
+ private handleRecoveryModelSkip;
262
+ private handleRecoveryModelText;
263
+ private executeRecoveryModelSession;
264
+ private sendRecoveryModelPrompt;
265
+ private buildRecoveryModelReplyMarkup;
266
+ private executeProcessAction;
267
+ private sendCommandResult;
268
+ private isAllowed;
269
+ private sendHtml;
270
+ private sendResultParts;
271
+ private sendPhotoWithDocumentFallback;
272
+ private sendPlainToChat;
273
+ private sendHtmlToChat;
274
+ private logError;
275
+ }
276
+
277
+ interface FakeTelegramTopic {
278
+ chatId: string;
279
+ name: string;
280
+ messageThreadId: number;
281
+ }
282
+ interface FakeTelegramTopicEdit {
283
+ chatId: string;
284
+ messageThreadId: number;
285
+ name: string;
286
+ }
287
+ interface FakeTelegramTopicClose {
288
+ chatId: string;
289
+ messageThreadId: number;
290
+ }
291
+ interface FakeTelegramAnswerCallback {
292
+ callbackQueryId: string;
293
+ text?: string;
294
+ showAlert?: boolean;
295
+ }
296
+ type FakeTelegramOperation = {
297
+ kind: "createForumTopic";
298
+ input: FakeTelegramTopic;
299
+ } | {
300
+ kind: "editForumTopic";
301
+ input: FakeTelegramTopicEdit;
302
+ } | {
303
+ kind: "closeForumTopic";
304
+ input: FakeTelegramTopicClose;
305
+ } | {
306
+ kind: "sendMessage";
307
+ input: TelegramSendMessageInput;
308
+ } | {
309
+ kind: "sendPhoto";
310
+ input: TelegramSendFileInput;
311
+ } | {
312
+ kind: "sendDocument";
313
+ input: TelegramSendFileInput;
314
+ } | {
315
+ kind: "answerCallbackQuery";
316
+ input: FakeTelegramAnswerCallback;
317
+ };
318
+ declare class FakeTelegramClient extends BaseTelegramClientEventRegistrar implements TelegramClient {
319
+ readonly operations: FakeTelegramOperation[];
320
+ readonly createdTopics: FakeTelegramTopic[];
321
+ readonly editedTopics: FakeTelegramTopicEdit[];
322
+ readonly closedTopics: FakeTelegramTopicClose[];
323
+ readonly sentMessages: TelegramSendMessageInput[];
324
+ readonly sentPhotos: TelegramSendFileInput[];
325
+ readonly sentDocuments: TelegramSendFileInput[];
326
+ readonly answeredCallbacks: FakeTelegramAnswerCallback[];
327
+ private nextThreadId;
328
+ private nextMessageId;
329
+ private createForumTopicFailures;
330
+ private sendPhotoFailures;
331
+ private sendDocumentFailures;
332
+ private sendMessageFailure;
333
+ started: boolean;
334
+ start(): Promise<void>;
335
+ stop(): Promise<void>;
336
+ failNextCreateForumTopic(error?: Error): void;
337
+ failSendMessageAfter(successfulSends: number, error?: Error): void;
338
+ failNextSendPhoto(error?: Error): void;
339
+ failNextSendDocument(error?: Error): void;
340
+ createForumTopic(input: {
341
+ chatId: string;
342
+ name: string;
343
+ }): Promise<{
344
+ messageThreadId: number;
345
+ }>;
346
+ editForumTopic(input: FakeTelegramTopicEdit): Promise<void>;
347
+ closeForumTopic(input: FakeTelegramTopicClose): Promise<void>;
348
+ sendMessage(input: TelegramSendMessageInput): Promise<TelegramSentMessage>;
349
+ sendPhoto(input: TelegramSendFileInput): Promise<TelegramSentMessage>;
350
+ sendDocument(input: TelegramSendFileInput): Promise<TelegramSentMessage>;
351
+ answerCallbackQuery(input: FakeTelegramAnswerCallback): Promise<void>;
352
+ simulateText(update: TelegramTextUpdate): Promise<void>;
353
+ simulateCallback(update: TelegramCallbackUpdate): Promise<void>;
354
+ simulateForumTopicCreated(update: TelegramForumTopicCreatedUpdate): Promise<void>;
355
+ simulateForumTopicClosed(update: TelegramForumTopicClosedUpdate): Promise<void>;
356
+ }
357
+
358
+ interface ActionPreviewLike {
359
+ kind?: string;
360
+ turnId?: string;
361
+ lifecycleStatus?: string;
362
+ }
363
+ type PendingTelegramSession = {
364
+ kind: "action_form";
365
+ instanceId: string;
366
+ actionId: string;
367
+ actionLabel: string;
368
+ actionPreview?: ActionPreviewLike | null;
369
+ sessionId: string;
370
+ form: FormDefinition;
371
+ fieldIndex: number;
372
+ values: Record<string, unknown>;
373
+ expiresAt: number;
374
+ } | {
375
+ kind: "action_model";
376
+ instanceId: string;
377
+ actionId: string;
378
+ actionLabel: string;
379
+ actionPreview?: ActionPreviewLike | null;
380
+ sessionId: string;
381
+ formValues: Record<string, unknown>;
382
+ preview: ProcessActionModelPreviewLike;
383
+ profiles: readonly ModelProfileOptionSummaryLike[];
384
+ expiresAt: number;
385
+ } | {
386
+ kind: "recovery_model";
387
+ instanceId: string;
388
+ recoveryKind: "retry" | "continue";
389
+ turnRecordId?: string;
390
+ sessionId: string;
391
+ profiles: readonly ModelProfileOptionSummaryLike[];
392
+ selectedModelProfileId?: string | null;
393
+ expiresAt: number;
394
+ } | {
395
+ kind: "continue";
396
+ instanceId: string;
397
+ turnRecordId: string;
398
+ nextTurnModelProfileId?: string | null;
399
+ expiresAt: number;
400
+ } | {
401
+ kind: "question";
402
+ instanceId: string;
403
+ request: ProcessQuestionRequest;
404
+ questionIndex: number;
405
+ draft: QuestionAnswerDraft[];
406
+ expiresAt: number;
407
+ };
408
+ type PendingActionFormSession = Extract<PendingTelegramSession, {
409
+ kind: "action_form";
410
+ }>;
411
+ type PendingActionModelSession = Extract<PendingTelegramSession, {
412
+ kind: "action_model";
413
+ }>;
414
+ type PendingQuestionSession = Extract<PendingTelegramSession, {
415
+ kind: "question";
416
+ }>;
417
+ type FormStepResult = {
418
+ ok: true;
419
+ done: false;
420
+ prompt: string;
421
+ } | {
422
+ ok: true;
423
+ done: true;
424
+ values: Record<string, unknown>;
425
+ } | {
426
+ ok: false;
427
+ prompt: string;
428
+ };
429
+ declare function buildActionFormSession(input: {
430
+ instanceId: string;
431
+ actionId: string;
432
+ actionLabel?: string;
433
+ actionPreview?: ActionPreviewLike | null;
434
+ sessionId: string;
435
+ form: FormDefinition;
436
+ now?: number;
437
+ ttlMs?: number;
438
+ }): PendingActionFormSession;
439
+ declare function buildQuestionSession(input: {
440
+ instanceId: string;
441
+ request: ProcessQuestionRequest;
442
+ }): PendingQuestionSession;
443
+ declare function buildQuestionPrompt(session: PendingQuestionSession): string;
444
+ declare function applyQuestionText(session: PendingQuestionSession, text: string): {
445
+ done: boolean;
446
+ draft: QuestionAnswerDraft[];
447
+ prompt?: string;
448
+ };
449
+ declare function buildContinueSession(input: {
450
+ instanceId: string;
451
+ turnRecordId: string;
452
+ nextTurnModelProfileId?: string | null;
453
+ now?: number;
454
+ ttlMs?: number;
455
+ }): Extract<PendingTelegramSession, {
456
+ kind: "continue";
457
+ }>;
458
+ declare function currentField(session: PendingActionFormSession): FormFieldDefinition | null;
459
+ declare function buildFieldPrompt(field: FormFieldDefinition): string;
460
+ declare function canSkipActionFormField(field: FormFieldDefinition | null | undefined): boolean;
461
+ declare function applyFormSkip(session: PendingActionFormSession): FormStepResult;
462
+ declare function applyFormText(session: PendingActionFormSession, text: string): FormStepResult;
463
+ declare function buildActionModelSession(input: {
464
+ instanceId: string;
465
+ actionId: string;
466
+ actionLabel: string;
467
+ actionPreview?: ActionPreviewLike | null;
468
+ sessionId: string;
469
+ formValues: Record<string, unknown>;
470
+ preview: ProcessActionModelPreviewLike;
471
+ profiles: readonly ModelProfileOptionSummaryLike[];
472
+ now?: number;
473
+ ttlMs?: number;
474
+ }): PendingActionModelSession;
475
+ declare function buildActionModelSwitchWarning(input: {
476
+ session: PendingActionModelSession;
477
+ effectiveModelProfileId: string;
478
+ now?: number;
479
+ }): string | null;
480
+ declare function buildActionModelPrompt(input: {
481
+ session: PendingActionModelSession;
482
+ }): string;
483
+ type PendingRecoveryModelSession = Extract<PendingTelegramSession, {
484
+ kind: "recovery_model";
485
+ }>;
486
+ declare function buildRecoveryModelSession(input: {
487
+ instanceId: string;
488
+ recoveryKind: "retry" | "continue";
489
+ turnRecordId?: string;
490
+ sessionId: string;
491
+ profiles: readonly ModelProfileOptionSummaryLike[];
492
+ now?: number;
493
+ ttlMs?: number;
494
+ }): PendingRecoveryModelSession;
495
+ declare function buildRecoveryModelPrompt(input: {
496
+ session: PendingRecoveryModelSession;
497
+ }): string;
498
+
499
+ type LaunchFieldValue = string | number | boolean;
500
+ type LaunchModelStep = {
501
+ kind: "default";
502
+ key: "default";
503
+ label: string;
504
+ } | {
505
+ kind: "turn";
506
+ key: string;
507
+ turnId: string;
508
+ label: string;
509
+ };
510
+ interface PendingLaunchModelEdit {
511
+ stepIndex: number;
512
+ }
513
+ interface PendingLaunchSession {
514
+ kind: "launch";
515
+ launcherId: string;
516
+ fieldIndex: number;
517
+ fieldOrder: readonly string[];
518
+ values: Record<string, LaunchFieldValue>;
519
+ modelConfig: LaunchModelConfigInputLike;
520
+ modelConfigTouched: boolean;
521
+ modelEdit: PendingLaunchModelEdit | null;
522
+ expiresAt: number;
523
+ }
524
+ type LaunchFieldStepResult = {
525
+ ok: true;
526
+ done: false;
527
+ field: LauncherFieldDefinition;
528
+ } | {
529
+ ok: true;
530
+ done: true;
531
+ values: Record<string, LaunchFieldValue>;
532
+ } | {
533
+ ok: false;
534
+ prompt: string;
535
+ };
536
+ type LaunchModelStepResult = {
537
+ ok: true;
538
+ done: false;
539
+ step: LaunchModelStep;
540
+ } | {
541
+ ok: true;
542
+ done: true;
543
+ } | {
544
+ ok: false;
545
+ prompt: string;
546
+ };
547
+ type LaunchModelStepAction = {
548
+ action: "set";
549
+ value: string;
550
+ } | {
551
+ action: "inherit";
552
+ } | {
553
+ action: "skip";
554
+ };
555
+ type LaunchFieldOptionsById = Record<string, readonly LauncherFieldOptionDefinition[] | undefined>;
556
+ declare function createLaunchSession(input: {
557
+ launcher: UiLauncherSummary;
558
+ defaults?: Record<string, unknown>;
559
+ now?: number;
560
+ ttlMs?: number;
561
+ }): PendingLaunchSession;
562
+ declare function buildLaunchInput(session: PendingLaunchSession): Record<string, unknown>;
563
+ declare function buildLaunchModelConfig(session: PendingLaunchSession): LaunchModelConfigInputLike;
564
+ declare function seedLaunchModelConfigFromPlan(session: PendingLaunchSession, launchPlan: ProcessLaunchPlan): void;
565
+ declare function hasLaunchModelControls(schema: LauncherModelConfigSchemaLike | null | undefined): schema is LauncherModelConfigSchemaLike;
566
+ declare function beginLaunchModelEdit(session: PendingLaunchSession, schema: LauncherModelConfigSchemaLike): LaunchModelStepResult;
567
+ declare function currentLaunchModelStep(session: PendingLaunchSession, schema: LauncherModelConfigSchemaLike): LaunchModelStep | null;
568
+ declare function finishLaunchModelEdit(session: PendingLaunchSession): void;
569
+ declare function currentLaunchField(session: PendingLaunchSession, launcher: UiLauncherSummary): LauncherFieldDefinition | null;
570
+ declare function isLaunchSessionComplete(session: PendingLaunchSession): boolean;
571
+ declare function getLaunchFieldOptions(field: LauncherFieldDefinition, dynamicOptionsById: LaunchFieldOptionsById): readonly LauncherFieldOptionDefinition[];
572
+ declare function buildLaunchFieldPrompt(input: {
573
+ field: LauncherFieldDefinition;
574
+ currentValue?: LaunchFieldValue;
575
+ options?: readonly LauncherFieldOptionDefinition[];
576
+ recentValues?: readonly string[];
577
+ maxOptionsInPrompt?: number;
578
+ }): string;
579
+ declare function buildLaunchModelSummary(input: {
580
+ schema: LauncherModelConfigSchemaLike;
581
+ session: PendingLaunchSession;
582
+ preview?: LauncherModelConfigPreviewLike | null;
583
+ }): string;
584
+ declare function buildLaunchModelStepPrompt(input: {
585
+ step: LaunchModelStep;
586
+ schema: LauncherModelConfigSchemaLike;
587
+ session: PendingLaunchSession;
588
+ preview?: LauncherModelConfigPreviewLike | null;
589
+ maxOptionsInPrompt?: number;
590
+ }): string;
591
+ declare function applyLaunchModelStepText(session: PendingLaunchSession, schema: LauncherModelConfigSchemaLike, text: string): LaunchModelStepResult;
592
+ declare function applyLaunchModelStepAction(session: PendingLaunchSession, schema: LauncherModelConfigSchemaLike, action: LaunchModelStepAction): LaunchModelStepResult;
593
+ declare function applyLaunchFieldText(session: PendingLaunchSession, launcher: UiLauncherSummary, text: string, dynamicOptionsById?: LaunchFieldOptionsById): LaunchFieldStepResult;
594
+ declare function applyLaunchFieldValue(session: PendingLaunchSession, launcher: UiLauncherSummary, value: unknown, dynamicOptionsById?: LaunchFieldOptionsById): LaunchFieldStepResult;
595
+ declare function moveLaunchSessionToValidationField(session: PendingLaunchSession, launcher: UiLauncherSummary, errors: readonly LauncherValidationError[]): LauncherFieldDefinition | null;
596
+ declare function buildLaunchReview(input: {
597
+ launcher: UiLauncherSummary;
598
+ session: PendingLaunchSession;
599
+ }): string;
600
+
601
+ type TelegramResultVisual = {
602
+ kind: "image";
603
+ imageId: string;
604
+ alt: string;
605
+ } | {
606
+ kind: "mermaid";
607
+ source: string;
608
+ };
609
+ type TelegramResultPart = {
610
+ kind: "html";
611
+ html: string;
612
+ } | TelegramResultVisual;
613
+ declare function escapeTelegramHtml(value: string): string;
614
+ declare function escapeTelegramAttribute(value: string): string;
615
+ declare function telegramHtmlToPlainText(html: string): string;
616
+ declare function splitPlainTelegramText(value: string, maxChars?: number): string[];
617
+ declare function splitTelegramHtml(value: string, maxChars?: number): string[];
618
+ declare function renderMarkdownToTelegramHtml(markdownText: string): string;
619
+ /**
620
+ * Extracts only top-level visual blocks. Inline and list-nested images remain
621
+ * ordinary rendered Markdown so media delivery never has to reconstruct open
622
+ * formatting containers around Telegram uploads.
623
+ */
624
+ declare function renderResultMarkdownForTelegram(input: {
625
+ markdown: string;
626
+ instanceId: string;
627
+ turnRecordId: string;
628
+ }): TelegramResultPart[];
629
+
630
+ declare const TELEGRAM_THREAD_LINKED_EVENT = "telegram.thread_linked";
631
+ declare function threadKey(chatId: string, messageThreadId: number | undefined): string;
632
+ declare class ProcessThreadStore {
633
+ private readonly deps;
634
+ private readonly byInstanceId;
635
+ private readonly byThreadKey;
636
+ constructor(deps: Pick<CoreServerSetupDeps, "events" | "processes">);
637
+ rebuildFromEvents(): readonly string[];
638
+ getByInstanceId(instanceId: string): TelegramProcessThread | null;
639
+ getInstanceIdForThread(chatId: string, messageThreadId: number | undefined): string | null;
640
+ record(process: Pick<ProcessInstance, "id">, thread: TelegramProcessThread): void;
641
+ private listThreadEvents;
642
+ private remember;
643
+ }
644
+
645
+ declare function getProcessTopicBaseTitle(process: ProcessInstance): string;
646
+ declare function buildTopicTitle(input: {
647
+ process: ProcessInstance;
648
+ template: string;
649
+ }): string;
650
+
651
+ declare const telegramClientToken: _leitwerk_dev_process_sdk.CapabilityToken<TelegramClient>;
652
+ declare const manifest: {
5
653
  readonly id: "telegram";
6
654
  readonly version: "0.1.0";
7
655
  };
8
656
  declare const telegramExtension: LeitwerkExtensionModule;
9
- export default telegramExtension;
10
- export * from "./bridge.js";
11
- export * from "./config.js";
12
- export * from "./fake-telegram-client.js";
13
- export * from "./form-session.js";
14
- export * from "./launch-session.js";
15
- export * from "./markdown-html.js";
16
- export * from "./process-thread-store.js";
17
- export * from "./topic-title.js";
18
- export type * from "./types.js";
19
- //# sourceMappingURL=index.d.ts.map
657
+
658
+ export { type ActionPreviewLike, BaseTelegramClientEventRegistrar, type FakeTelegramAnswerCallback, FakeTelegramClient, type FakeTelegramOperation, type FakeTelegramTopic, type FakeTelegramTopicClose, type FakeTelegramTopicEdit, type FormStepResult, type LaunchFieldOptionsById, type LaunchFieldStepResult, type LaunchFieldValue, type LaunchModelStep, type LaunchModelStepAction, type LaunchModelStepResult, type PendingActionFormSession, type PendingActionModelSession, type PendingLaunchModelEdit, type PendingLaunchSession, type PendingQuestionSession, type PendingRecoveryModelSession, type PendingTelegramSession, ProcessThreadStore, TELEGRAM_THREAD_LINKED_EVENT, TelegramBridge, type TelegramCallbackHandler, type TelegramCallbackUpdate, type TelegramClient, type TelegramConfigResult, type TelegramExtensionConfig, type TelegramForceReply, type TelegramForumTopicClosedHandler, type TelegramForumTopicClosedUpdate, type TelegramForumTopicCreatedHandler, type TelegramForumTopicCreatedUpdate, type TelegramInlineKeyboard, type TelegramInlineKeyboardButton, type TelegramParseMode, type TelegramProcessThread, type TelegramReplyMarkup, type TelegramReplyMarkupBase, type TelegramResultPart, type TelegramResultVisual, type TelegramSendFileInput, type TelegramSendMessageInput, type TelegramSentMessage, type TelegramTextHandler, type TelegramTextUpdate, type TelegramUserRef, applyFormSkip, applyFormText, applyLaunchFieldText, applyLaunchFieldValue, applyLaunchModelStepAction, applyLaunchModelStepText, applyQuestionText, beginLaunchModelEdit, buildActionFormSession, buildActionModelPrompt, buildActionModelSession, buildActionModelSwitchWarning, buildContinueSession, buildFieldPrompt, buildLaunchFieldPrompt, buildLaunchInput, buildLaunchModelConfig, buildLaunchModelStepPrompt, buildLaunchModelSummary, buildLaunchReview, buildQuestionPrompt, buildQuestionSession, buildRecoveryModelPrompt, buildRecoveryModelSession, buildTopicTitle, canSkipActionFormField, createLaunchSession, currentField, currentLaunchField, currentLaunchModelStep, telegramExtension as default, escapeTelegramAttribute, escapeTelegramHtml, finishLaunchModelEdit, getLaunchFieldOptions, getProcessTopicBaseTitle, hasLaunchModelControls, isLaunchSessionComplete, manifest, moveLaunchSessionToValidationField, normalizeTelegramConfig, renderMarkdownToTelegramHtml, renderResultMarkdownForTelegram, seedLaunchModelConfigFromPlan, splitPlainTelegramText, splitTelegramHtml, telegramClientToken, telegramHtmlToPlainText, threadKey };