@leitwerk-dev/telegram 0.2.0 → 0.3.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/dist/index.js CHANGED
@@ -332,9 +332,6 @@ function currentLaunchField(session, launcher) {
332
332
  const fieldId = session.fieldOrder[session.fieldIndex];
333
333
  return fieldId ? launcher.launchConfigSchema.fields.find((field) => field.id === fieldId) ?? null : null;
334
334
  }
335
- function isLaunchSessionComplete(session) {
336
- return session.fieldIndex >= session.fieldOrder.length;
337
- }
338
335
  function getLaunchFieldOptions(field, dynamicOptionsById) {
339
336
  if (field.kind !== "select") return [];
340
337
  return dynamicOptionsById[field.id] ?? field.options ?? [];
@@ -1124,12 +1121,14 @@ function threadKey(chatId, messageThreadId) {
1124
1121
  return `${chatId}:${messageThreadId ?? 0}`;
1125
1122
  }
1126
1123
  var ProcessThreadStore = class {
1124
+ /** @internal */
1127
1125
  constructor(deps) {
1128
1126
  this.deps = deps;
1129
1127
  }
1130
1128
  deps;
1131
1129
  byInstanceId = /* @__PURE__ */ new Map();
1132
1130
  byThreadKey = /* @__PURE__ */ new Map();
1131
+ /** @internal */
1133
1132
  rebuildFromEvents() {
1134
1133
  this.byInstanceId.clear();
1135
1134
  this.byThreadKey.clear();
@@ -1143,12 +1142,15 @@ var ProcessThreadStore = class {
1143
1142
  }
1144
1143
  return mappedInstanceIds;
1145
1144
  }
1145
+ /** @internal */
1146
1146
  getByInstanceId(instanceId) {
1147
1147
  return this.byInstanceId.get(instanceId) ?? null;
1148
1148
  }
1149
+ /** @internal */
1149
1150
  getInstanceIdForThread(chatId, messageThreadId) {
1150
1151
  return this.byThreadKey.get(threadKey(chatId, messageThreadId)) ?? null;
1151
1152
  }
1153
+ /** @internal */
1152
1154
  record(process2, thread) {
1153
1155
  this.deps.events.create({
1154
1156
  instanceId: process2.id,
@@ -1297,6 +1299,7 @@ function createActionFormSessionId() {
1297
1299
  return randomBytes(4).toString("hex");
1298
1300
  }
1299
1301
  var TelegramBridge = class {
1302
+ /** @internal */
1300
1303
  constructor(input) {
1301
1304
  this.input = input;
1302
1305
  this.store = new ProcessThreadStore(input.deps);
@@ -1320,6 +1323,7 @@ var TelegramBridge = class {
1320
1323
  deferredCompletedLifecycleProcesses = /* @__PURE__ */ new Map();
1321
1324
  queues = /* @__PURE__ */ new Map();
1322
1325
  lastTurnInfo = /* @__PURE__ */ new Map();
1326
+ /** @internal */
1323
1327
  async start() {
1324
1328
  for (const instanceId of this.store.rebuildFromEvents()) {
1325
1329
  this.threadEligibleInstanceIds.add(instanceId);
@@ -1352,11 +1356,13 @@ var TelegramBridge = class {
1352
1356
  }
1353
1357
  }
1354
1358
  }
1359
+ /** @internal */
1355
1360
  async stop() {
1356
1361
  await this.input.client.stop();
1357
1362
  }
1363
+ /** @internal */
1358
1364
  register(events) {
1359
- const on = (event, handler) => events.on(event, (payload) => void this.enqueue(payload.instanceId, () => handler(payload)));
1365
+ const on = (event, handler) => events.on(event, (payload) => this.enqueue(payload.instanceId, () => handler(payload)));
1360
1366
  on("process_created", (payload) => this.onProcessCreated(payload));
1361
1367
  on("process_updated", (payload) => this.onProcessUpdated(payload));
1362
1368
  on("turn_started", (payload) => this.onTurnStarted(payload.turnRecord));
@@ -3315,19 +3321,27 @@ import { Bot, InputFile } from "grammy";
3315
3321
 
3316
3322
  // src/types.ts
3317
3323
  var BaseTelegramClientEventRegistrar = class {
3324
+ /** @internal */
3318
3325
  textHandlers = /* @__PURE__ */ new Set();
3326
+ /** @internal */
3319
3327
  callbackHandlers = /* @__PURE__ */ new Set();
3328
+ /** @internal */
3320
3329
  forumTopicCreatedHandlers = /* @__PURE__ */ new Set();
3330
+ /** @internal */
3321
3331
  forumTopicClosedHandlers = /* @__PURE__ */ new Set();
3332
+ /** @internal */
3322
3333
  onText(handler) {
3323
3334
  this.textHandlers.add(handler);
3324
3335
  }
3336
+ /** @internal */
3325
3337
  onCallback(handler) {
3326
3338
  this.callbackHandlers.add(handler);
3327
3339
  }
3340
+ /** @internal */
3328
3341
  onForumTopicCreated(handler) {
3329
3342
  this.forumTopicCreatedHandlers.add(handler);
3330
3343
  }
3344
+ /** @internal */
3331
3345
  onForumTopicClosed(handler) {
3332
3346
  this.forumTopicClosedHandlers.add(handler);
3333
3347
  }
@@ -3519,115 +3533,12 @@ var GrammyTelegramClient = class extends BaseTelegramClientEventRegistrar {
3519
3533
  }
3520
3534
  };
3521
3535
 
3522
- // src/fake-telegram-client.ts
3523
- var FakeTelegramClient = class extends BaseTelegramClientEventRegistrar {
3524
- operations = [];
3525
- createdTopics = [];
3526
- editedTopics = [];
3527
- closedTopics = [];
3528
- sentMessages = [];
3529
- sentPhotos = [];
3530
- sentDocuments = [];
3531
- answeredCallbacks = [];
3532
- nextThreadId = 100;
3533
- nextMessageId = 1;
3534
- createForumTopicFailures = [];
3535
- sendPhotoFailures = [];
3536
- sendDocumentFailures = [];
3537
- sendMessageFailure = null;
3538
- started = false;
3539
- async start() {
3540
- this.started = true;
3541
- }
3542
- async stop() {
3543
- this.started = false;
3544
- }
3545
- failNextCreateForumTopic(error = new Error("createForumTopic failed")) {
3546
- this.createForumTopicFailures.push(error);
3547
- }
3548
- failSendMessageAfter(successfulSends, error = new Error("sendMessage failed")) {
3549
- this.sendMessageFailure = {
3550
- remainingSuccessfulSends: Math.max(0, successfulSends),
3551
- error
3552
- };
3553
- }
3554
- failNextSendPhoto(error = new Error("sendPhoto failed")) {
3555
- this.sendPhotoFailures.push(error);
3556
- }
3557
- failNextSendDocument(error = new Error("sendDocument failed")) {
3558
- this.sendDocumentFailures.push(error);
3559
- }
3560
- async createForumTopic(input) {
3561
- const failure = this.createForumTopicFailures.shift();
3562
- if (failure) {
3563
- throw failure;
3564
- }
3565
- const topic = {
3566
- chatId: input.chatId,
3567
- name: input.name,
3568
- messageThreadId: this.nextThreadId++
3569
- };
3570
- this.operations.push({ kind: "createForumTopic", input: topic });
3571
- this.createdTopics.push(topic);
3572
- return { messageThreadId: topic.messageThreadId };
3573
- }
3574
- async editForumTopic(input) {
3575
- this.operations.push({ kind: "editForumTopic", input });
3576
- this.editedTopics.push(input);
3577
- }
3578
- async closeForumTopic(input) {
3579
- this.operations.push({ kind: "closeForumTopic", input });
3580
- this.closedTopics.push(input);
3581
- }
3582
- async sendMessage(input) {
3583
- const failure = this.sendMessageFailure;
3584
- if (failure) {
3585
- if (failure.remainingSuccessfulSends <= 0) {
3586
- this.sendMessageFailure = null;
3587
- throw failure.error;
3588
- }
3589
- failure.remainingSuccessfulSends -= 1;
3590
- }
3591
- this.operations.push({ kind: "sendMessage", input });
3592
- this.sentMessages.push(input);
3593
- return { messageId: this.nextMessageId++ };
3594
- }
3595
- async sendPhoto(input) {
3596
- const failure = this.sendPhotoFailures.shift();
3597
- if (failure) throw failure;
3598
- this.operations.push({ kind: "sendPhoto", input });
3599
- this.sentPhotos.push(input);
3600
- return { messageId: this.nextMessageId++ };
3601
- }
3602
- async sendDocument(input) {
3603
- const failure = this.sendDocumentFailures.shift();
3604
- if (failure) throw failure;
3605
- this.operations.push({ kind: "sendDocument", input });
3606
- this.sentDocuments.push(input);
3607
- return { messageId: this.nextMessageId++ };
3608
- }
3609
- async answerCallbackQuery(input) {
3610
- this.operations.push({ kind: "answerCallbackQuery", input });
3611
- this.answeredCallbacks.push(input);
3612
- }
3613
- async simulateText(update) {
3614
- await Promise.all([...this.textHandlers].map((handler) => handler(update)));
3615
- }
3616
- async simulateCallback(update) {
3617
- await Promise.all([...this.callbackHandlers].map((handler) => handler(update)));
3618
- }
3619
- async simulateForumTopicCreated(update) {
3620
- await Promise.all([...this.forumTopicCreatedHandlers].map((handler) => handler(update)));
3621
- }
3622
- async simulateForumTopicClosed(update) {
3623
- await Promise.all([...this.forumTopicClosedHandlers].map((handler) => handler(update)));
3624
- }
3625
- };
3626
-
3627
3536
  // src/index.ts
3628
3537
  var telegramClientToken = createCapabilityToken("telegram:client");
3629
3538
  var manifest = {
3539
+ /** @internal */
3630
3540
  id: "telegram",
3541
+ /** @internal */
3631
3542
  version: "0.1.0"
3632
3543
  };
3633
3544
  var telegramExtension = {
@@ -3668,59 +3579,6 @@ ${configResult.errors.join("\n")}`);
3668
3579
  };
3669
3580
  var index_default = telegramExtension;
3670
3581
  export {
3671
- FakeTelegramClient,
3672
- ProcessThreadStore,
3673
- TELEGRAM_ACTOR,
3674
- TELEGRAM_THREAD_LINKED_EVENT,
3675
- TelegramBridge,
3676
- applyFormSkip,
3677
- applyFormText,
3678
- applyLaunchFieldText,
3679
- applyLaunchFieldValue,
3680
- applyLaunchModelStepAction,
3681
- applyLaunchModelStepText,
3682
- applyQuestionText,
3683
- beginLaunchModelEdit,
3684
- buildActionFormSession,
3685
- buildActionModelPrompt,
3686
- buildActionModelSession,
3687
- buildActionModelSwitchWarning,
3688
- buildContinueSession,
3689
- buildFieldPrompt,
3690
- buildLaunchFieldPrompt,
3691
- buildLaunchInput,
3692
- buildLaunchModelConfig,
3693
- buildLaunchModelStepPrompt,
3694
- buildLaunchModelSummary,
3695
- buildLaunchReview,
3696
- buildQuestionPrompt,
3697
- buildQuestionSession,
3698
- buildRecoveryModelPrompt,
3699
- buildRecoveryModelSession,
3700
- buildTopicTitle,
3701
- canSkipActionFormField,
3702
- createLaunchSession,
3703
- currentField,
3704
- currentLaunchField,
3705
- currentLaunchModelStep,
3706
- index_default as default,
3707
- escapeTelegramAttribute,
3708
- escapeTelegramHtml,
3709
- finishLaunchModelEdit,
3710
- getLaunchFieldOptions,
3711
- getProcessTopicBaseTitle,
3712
- hasLaunchModelControls,
3713
- isLaunchSessionComplete,
3714
- manifest,
3715
- moveLaunchSessionToValidationField,
3716
- normalizeTelegramConfig,
3717
- renderMarkdownToTelegramHtml,
3718
- renderResultMarkdownForTelegram,
3719
- seedLaunchModelConfigFromPlan,
3720
- splitPlainTelegramText,
3721
- splitTelegramHtml,
3722
- telegramClientToken,
3723
- telegramHtmlToPlainText,
3724
- threadKey
3582
+ index_default as default
3725
3583
  };
3726
3584
  //# sourceMappingURL=index.js.map