@llblab/pi-telegram 0.54.3 → 0.55.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.
Files changed (80) hide show
  1. package/AGENTS.md +4 -2
  2. package/BACKLOG.md +1 -1
  3. package/CHANGELOG.md +21 -0
  4. package/README.md +5 -3
  5. package/dist/lib/activity.d.ts +5 -1
  6. package/dist/lib/activity.js +31 -2
  7. package/dist/lib/bindings.d.ts +5 -1
  8. package/dist/lib/bindings.js +9 -2
  9. package/dist/lib/bus-api.d.ts +2 -2
  10. package/dist/lib/bus-api.js +7 -2
  11. package/dist/lib/bus-follower.d.ts +49 -3
  12. package/dist/lib/bus-follower.js +313 -146
  13. package/dist/lib/bus-leader.d.ts +3 -0
  14. package/dist/lib/bus-leader.js +99 -18
  15. package/dist/lib/bus.d.ts +5 -3
  16. package/dist/lib/bus.js +13 -10
  17. package/dist/lib/delivery.d.ts +4 -0
  18. package/dist/lib/delivery.js +48 -15
  19. package/dist/lib/extension.js +56 -6
  20. package/dist/lib/lifecycle.d.ts +68 -0
  21. package/dist/lib/lifecycle.js +178 -58
  22. package/dist/lib/machine.d.ts +23 -0
  23. package/dist/lib/machine.js +37 -0
  24. package/dist/lib/media.d.ts +114 -28
  25. package/dist/lib/media.js +292 -119
  26. package/dist/lib/model.d.ts +54 -15
  27. package/dist/lib/model.js +98 -53
  28. package/dist/lib/polling.js +2 -0
  29. package/dist/lib/preview.d.ts +128 -113
  30. package/dist/lib/preview.js +448 -366
  31. package/dist/lib/queue.d.ts +2 -2
  32. package/dist/lib/queue.js +3 -3
  33. package/dist/lib/routing.d.ts +14 -2
  34. package/dist/lib/routing.js +546 -207
  35. package/dist/lib/runtime.d.ts +77 -11
  36. package/dist/lib/runtime.js +174 -92
  37. package/dist/lib/sections.js +0 -1
  38. package/dist/lib/telegram-api.d.ts +11 -9
  39. package/dist/lib/telegram-api.js +53 -4
  40. package/dist/lib/text-groups.d.ts +0 -26
  41. package/dist/lib/text-groups.js +51 -98
  42. package/dist/lib/thread-display.js +14 -6
  43. package/dist/lib/threads.d.ts +20 -5
  44. package/dist/lib/threads.js +111 -32
  45. package/dist/lib/turns.d.ts +2 -0
  46. package/dist/lib/turns.js +6 -1
  47. package/dist/lib/updates.d.ts +11 -4
  48. package/dist/lib/updates.js +54 -19
  49. package/dist/package.json +1 -1
  50. package/docs/activity.md +1 -1
  51. package/docs/architecture.md +16 -15
  52. package/docs/delivery.md +7 -5
  53. package/docs/multi-instance-bus.md +18 -8
  54. package/docs/public-api.md +2 -2
  55. package/docs/ui-style.md +8 -6
  56. package/lib/activity.ts +29 -5
  57. package/lib/bindings.ts +13 -1
  58. package/lib/bus-api.ts +11 -3
  59. package/lib/bus-follower.ts +417 -203
  60. package/lib/bus-leader.ts +88 -14
  61. package/lib/bus.ts +17 -15
  62. package/lib/delivery.ts +47 -19
  63. package/lib/extension.ts +59 -9
  64. package/lib/lifecycle.ts +229 -55
  65. package/lib/machine.ts +60 -0
  66. package/lib/media.ts +438 -172
  67. package/lib/model.ts +169 -74
  68. package/lib/polling.ts +2 -0
  69. package/lib/preview.ts +715 -566
  70. package/lib/queue.ts +5 -5
  71. package/lib/routing.ts +644 -283
  72. package/lib/runtime.ts +260 -104
  73. package/lib/sections.ts +0 -2
  74. package/lib/telegram-api.ts +61 -8
  75. package/lib/text-groups.ts +75 -136
  76. package/lib/thread-display.ts +15 -4
  77. package/lib/threads.ts +130 -38
  78. package/lib/turns.ts +8 -1
  79. package/lib/updates.ts +58 -21
  80. package/package.json +1 -1
@@ -726,7 +726,7 @@ export interface TelegramDispatchRuntimeDeps<TContext = unknown> {
726
726
  executeControlItem: (item: Extract<TelegramQueueDispatchAction<TContext>, {
727
727
  kind: "control";
728
728
  }>["item"]) => void;
729
- onPromptDispatchStart: (chatId: number) => void;
729
+ onPromptDispatchStart: (chatId: number, target?: TelegramQueueTarget) => void;
730
730
  commitPromptDispatch?: (item: Extract<TelegramQueueDispatchAction<TContext>, {
731
731
  kind: "prompt";
732
732
  }>["item"]) => boolean;
@@ -745,7 +745,7 @@ export interface TelegramQueueDispatchControllerDeps<TContext = unknown> extends
745
745
  isDispatchGenerationActive?: (generation: number) => boolean;
746
746
  updateStatus: (ctx: TContext, error?: string) => void;
747
747
  sendTextReply: TelegramControlRuntimeDeps<TContext>["sendTextReply"];
748
- onPromptDispatchStart: (ctx: TContext, chatId: number) => void;
748
+ onPromptDispatchStart: (ctx: TContext, chatId: number, target?: TelegramQueueTarget) => void;
749
749
  commitPromptDispatch?: (item: Extract<TelegramQueueDispatchAction<TContext>, {
750
750
  kind: "prompt";
751
751
  }>["item"], ctx: TContext) => boolean;
package/dist/lib/queue.js CHANGED
@@ -1957,7 +1957,7 @@ export function executeTelegramQueueDispatchPlan(plan, deps) {
1957
1957
  deps.executeControlItem(plan.item);
1958
1958
  return;
1959
1959
  }
1960
- deps.onPromptDispatchStart(plan.item.chatId);
1960
+ deps.onPromptDispatchStart(plan.item.chatId, plan.item.target);
1961
1961
  try {
1962
1962
  if (deps.commitPromptDispatch && !deps.commitPromptDispatch(plan.item)) {
1963
1963
  throw new Error("Telegram prompt dispatch could not be committed durably.");
@@ -2188,8 +2188,8 @@ export function createTelegramQueueDispatchController(deps) {
2188
2188
  },
2189
2189
  });
2190
2190
  },
2191
- onPromptDispatchStart: (chatId) => {
2192
- deps.onPromptDispatchStart(ctx, chatId);
2191
+ onPromptDispatchStart: (chatId, target) => {
2192
+ deps.onPromptDispatchStart(ctx, chatId, target);
2193
2193
  },
2194
2194
  commitPromptDispatch: deps.commitPromptDispatch
2195
2195
  ? (item) => deps.commitPromptDispatch(item, ctx)
@@ -57,7 +57,10 @@ export type TelegramLiveRebindCleanupIssue = {
57
57
  cleanup: ThreadReconciler.TelegramLiveRebindCleanupOutcome;
58
58
  recorded: boolean;
59
59
  };
60
- /** Default live-rebind cleanup pacing: quick early attempts, then minutely, within a 15-minute window. */
60
+ /**
61
+ * Default live-rebind cleanup pacing: quick early attempts, then minutely, within a 15-minute window. The first
62
+ * delay is not cosmetic: a leader's detached command reply still needs the released, cleanup-free row.
63
+ */
61
64
  export declare const TELEGRAM_LIVE_REBIND_CLEANUP_SCHEDULE: Readonly<{
62
65
  delaysMs: readonly number[];
63
66
  intervalMs: 60000;
@@ -69,7 +72,7 @@ type TelegramLiveRebindSelectedCommandReference = {
69
72
  preparedSource: Bus.TelegramBusPreparedCommandSource;
70
73
  selectedCommand: Bus.TelegramBusSelectedCommandInput;
71
74
  };
72
- /** One warm live attempt with exact post-release peer donor settlement; no startup recovery, Restore ACK or cleanup. */
75
+ /** One warm live attempt with independent leader input/cleanup grants and exact peer donor settlement; no startup recovery or legacy Restore ACK. */
73
76
  export declare function createTelegramLiveRebindCoordinator(input: {
74
77
  request: Threads.TelegramWorkspaceRestoreRequest;
75
78
  /** Captures caller source/reference, admission, profile, transport and Pi lifetime. */
@@ -100,6 +103,10 @@ export declare function createTelegramLiveRebindCoordinator(input: {
100
103
  /** Explicit staged singleton command branch; absence preserves ordinary live input behavior. */
101
104
  selectedCommand?: Bus.TelegramBusSelectedCommandInput;
102
105
  };
106
+ /** Existing profile admission spans the applied recipient, fresh cleanup decision and one native input grant. */
107
+ cleanupBeforeRelease?(intent: Threads.TelegramWorkspaceLiveRebindIntent, isCurrent: () => boolean): Promise<boolean>;
108
+ /** Restore moves the tab to its new owner: once applied, show that owner's title (best-effort, never blocking). */
109
+ retitle?: (isCurrent: () => boolean) => Promise<void>;
103
110
  recordRuntimeEvent?: (category: string, error: unknown, details: Record<string, unknown>) => void;
104
111
  }): {
105
112
  /** Correlation only; a later cleanup attempt rereads and revalidates the canonical row itself. */
@@ -199,6 +206,7 @@ export interface TelegramInboundRouteRuntimeDeps<TMessage extends TelegramRouted
199
206
  hasWorkspaceRestoreAuthority?: () => boolean;
200
207
  /** Exact live root authority; capability advertisement alone cannot replace owned profile/session/recipient fences. */
201
208
  hasWorkspaceLiveRebindAuthority?: () => boolean;
209
+ canUsePreDispatchRebind?: (recipient?: Threads.TelegramWorkspaceRestoreRecipient) => boolean;
202
210
  /** Strict complete namespace plus exact current/historical references; only an empty result clears journal protection. */
203
211
  inspectTemporaryThreadSources?: (target: Queue.TelegramQueueTarget, requiredJournalBindingKeys: readonly string[], ownInputs?: readonly Threads.TelegramTemporaryThreadInput[]) => readonly number[] | undefined;
204
212
  /** Quiet period after the last cancelled input before one cleanup attempt; defaults to 1000 ms. */
@@ -346,6 +354,10 @@ export declare function createTelegramInboundRouteRuntime<TUpdate extends Update
346
354
  /** Commands-owned registry port for dormant scoped recipient assembly, not ordinary update replay. */
347
355
  prepareHeldCommand: ReturnType<typeof Commands.createTelegramCommandHandlerTargetRuntime<TMessage, TContext>>["prepareHeldCommand"];
348
356
  canPrepareHeldCommand: ReturnType<typeof Commands.createTelegramCommandHandlerTargetRuntime<TMessage, TContext>>["canPrepareHeldCommand"];
357
+ /** Agent-settled hint: wakes waiting leader cleanup retries early; every readiness gate is still sampled fresh. */
358
+ onSessionSettled(ctx: TContext): void;
359
+ /** Lifetime-fenced hint from drained publication/activity/delivery/API owners; never a cleanup grant. */
360
+ onDeliverySettled(ctx: TContext): void;
349
361
  /** Fresh body-free recipient observation only; never reconstructs an attempt or grants cleanup. */
350
362
  observeLiveRebindLeaderWork(intent: Threads.TelegramWorkspaceLiveRebindIntent, ctx: TContext): Promise<Bus.TelegramBusLiveRebindWorkObservation | undefined>;
351
363
  /** Fresh non-destructive candidate only; no retained idle, cleanup action or deletion grant. */