@llblab/pi-kit 0.6.0 → 0.7.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 (123) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +4 -4
  3. package/node_modules/@llblab/pi-actors/AGENTS.md +1 -1
  4. package/node_modules/@llblab/pi-actors/CHANGELOG.md +6 -0
  5. package/node_modules/@llblab/pi-actors/README.md +1 -1
  6. package/node_modules/@llblab/pi-actors/dist/lib/async-runs.d.ts +3 -0
  7. package/node_modules/@llblab/pi-actors/dist/lib/async-runs.js +14 -1
  8. package/node_modules/@llblab/pi-actors/dist/lib/command-templates.js +45 -3
  9. package/node_modules/@llblab/pi-actors/dist/lib/extension-runtime.js +1 -1
  10. package/node_modules/@llblab/pi-actors/dist/lib/observability.d.ts +16 -3
  11. package/node_modules/@llblab/pi-actors/dist/lib/observability.js +92 -7
  12. package/node_modules/@llblab/pi-actors/dist/lib/pi.d.ts +0 -1
  13. package/node_modules/@llblab/pi-actors/dist/lib/pi.js +15 -24
  14. package/node_modules/@llblab/pi-actors/dist/lib/run-delivery-lineage.d.ts +17 -0
  15. package/node_modules/@llblab/pi-actors/dist/lib/run-delivery-lineage.js +44 -0
  16. package/node_modules/@llblab/pi-actors/dist/lib/run-delivery.d.ts +4 -0
  17. package/node_modules/@llblab/pi-actors/dist/lib/run-delivery.js +102 -4
  18. package/node_modules/@llblab/pi-actors/dist/lib/run-ui-runtime.js +58 -39
  19. package/node_modules/@llblab/pi-actors/dist/lib/runtime.js +14 -6
  20. package/node_modules/@llblab/pi-actors/dist/skills/actors/SKILL.md +1 -1
  21. package/node_modules/@llblab/pi-actors/docs/async-runs.md +1 -1
  22. package/node_modules/@llblab/pi-actors/docs/coordinator-delivery.md +18 -23
  23. package/node_modules/@llblab/pi-actors/lib/async-runs.ts +18 -1
  24. package/node_modules/@llblab/pi-actors/lib/command-templates.ts +41 -3
  25. package/node_modules/@llblab/pi-actors/lib/extension-runtime.ts +1 -1
  26. package/node_modules/@llblab/pi-actors/lib/observability.ts +119 -5
  27. package/node_modules/@llblab/pi-actors/lib/pi.ts +15 -28
  28. package/node_modules/@llblab/pi-actors/lib/run-delivery-lineage.ts +68 -0
  29. package/node_modules/@llblab/pi-actors/lib/run-delivery.ts +120 -4
  30. package/node_modules/@llblab/pi-actors/lib/run-ui-runtime.ts +69 -44
  31. package/node_modules/@llblab/pi-actors/lib/runtime.ts +17 -6
  32. package/node_modules/@llblab/pi-actors/package.json +1 -1
  33. package/node_modules/@llblab/pi-actors/skills/actors/SKILL.md +1 -1
  34. package/node_modules/@llblab/pi-state-flow/AGENTS.md +33 -12
  35. package/node_modules/@llblab/pi-state-flow/BACKLOG.md +125 -2
  36. package/node_modules/@llblab/pi-state-flow/CHANGELOG.md +87 -45
  37. package/node_modules/@llblab/pi-state-flow/README.md +203 -107
  38. package/node_modules/@llblab/pi-state-flow/docs/README.md +4 -0
  39. package/node_modules/@llblab/pi-state-flow/docs/architecture.md +188 -0
  40. package/node_modules/@llblab/pi-state-flow/docs/temporal-acceptance.md +42 -0
  41. package/node_modules/@llblab/pi-state-flow/index.ts +164 -2
  42. package/node_modules/@llblab/pi-state-flow/lib/acquisition.ts +138 -0
  43. package/node_modules/@llblab/pi-state-flow/lib/artifact.ts +273 -0
  44. package/node_modules/@llblab/pi-state-flow/lib/config.ts +48 -0
  45. package/node_modules/@llblab/pi-state-flow/lib/context.ts +18 -5
  46. package/node_modules/@llblab/pi-state-flow/lib/continuation.ts +268 -0
  47. package/node_modules/@llblab/pi-state-flow/lib/discovery.ts +117 -0
  48. package/node_modules/@llblab/pi-state-flow/lib/durable.ts +562 -0
  49. package/node_modules/@llblab/pi-state-flow/lib/episode.ts +24 -12
  50. package/node_modules/@llblab/pi-state-flow/lib/extension.ts +606 -70
  51. package/node_modules/@llblab/pi-state-flow/lib/git.ts +666 -0
  52. package/node_modules/@llblab/pi-state-flow/lib/history.ts +95 -0
  53. package/node_modules/@llblab/pi-state-flow/lib/json.ts +24 -0
  54. package/node_modules/@llblab/pi-state-flow/lib/maintenance.ts +141 -0
  55. package/node_modules/@llblab/pi-state-flow/lib/memory.ts +52 -0
  56. package/node_modules/@llblab/pi-state-flow/lib/migration.ts +88 -0
  57. package/node_modules/@llblab/pi-state-flow/lib/publication.ts +296 -0
  58. package/node_modules/@llblab/pi-state-flow/lib/recovery.ts +23 -7
  59. package/node_modules/@llblab/pi-state-flow/lib/rehydration.ts +79 -0
  60. package/node_modules/@llblab/pi-state-flow/lib/runtime.ts +264 -0
  61. package/node_modules/@llblab/pi-state-flow/lib/session.ts +6 -0
  62. package/node_modules/@llblab/pi-state-flow/lib/skills.ts +99 -7
  63. package/node_modules/@llblab/pi-state-flow/lib/snapshot.ts +305 -48
  64. package/node_modules/@llblab/pi-state-flow/lib/state.ts +74 -7
  65. package/node_modules/@llblab/pi-state-flow/lib/status.ts +125 -6
  66. package/node_modules/@llblab/pi-state-flow/lib/storage.ts +196 -0
  67. package/node_modules/@llblab/pi-state-flow/lib/temporal.ts +233 -0
  68. package/node_modules/@llblab/pi-state-flow/lib/terminal.ts +70 -24
  69. package/node_modules/@llblab/pi-state-flow/lib/transition.ts +254 -29
  70. package/node_modules/@llblab/pi-state-flow/package.json +8 -2
  71. package/node_modules/@llblab/pi-state-flow/skills/state-flow-memory/SKILL.md +128 -0
  72. package/node_modules/@llblab/pi-telegram/AGENTS.md +13 -8
  73. package/node_modules/@llblab/pi-telegram/BACKLOG.md +20 -3
  74. package/node_modules/@llblab/pi-telegram/CHANGELOG.md +13 -0
  75. package/node_modules/@llblab/pi-telegram/README.md +12 -8
  76. package/node_modules/@llblab/pi-telegram/docs/README.md +1 -0
  77. package/node_modules/@llblab/pi-telegram/docs/architecture.md +220 -18
  78. package/node_modules/@llblab/pi-telegram/docs/generative-apps.md +1 -1
  79. package/node_modules/@llblab/pi-telegram/docs/multi-instance-bus.md +70 -19
  80. package/node_modules/@llblab/pi-telegram/docs/outbound.md +6 -6
  81. package/node_modules/@llblab/pi-telegram/docs/public-api.md +12 -5
  82. package/node_modules/@llblab/pi-telegram/docs/ui-style.md +3 -1
  83. package/node_modules/@llblab/pi-telegram/index.ts +4 -1418
  84. package/node_modules/@llblab/pi-telegram/lib/agent-messages.ts +6 -3
  85. package/node_modules/@llblab/pi-telegram/lib/bindings.ts +28 -1
  86. package/node_modules/@llblab/pi-telegram/lib/bus-follower.ts +600 -135
  87. package/node_modules/@llblab/pi-telegram/lib/bus-leader.ts +962 -55
  88. package/node_modules/@llblab/pi-telegram/lib/bus.ts +350 -26
  89. package/node_modules/@llblab/pi-telegram/lib/channel-posts.ts +544 -0
  90. package/node_modules/@llblab/pi-telegram/lib/commands.ts +234 -11
  91. package/node_modules/@llblab/pi-telegram/lib/config.ts +177 -24
  92. package/node_modules/@llblab/pi-telegram/lib/extension.ts +1792 -0
  93. package/node_modules/@llblab/pi-telegram/lib/generative-apps.ts +20 -2
  94. package/node_modules/@llblab/pi-telegram/lib/journal.ts +2184 -126
  95. package/node_modules/@llblab/pi-telegram/lib/locks.ts +38 -1
  96. package/node_modules/@llblab/pi-telegram/lib/menu-settings.ts +152 -13
  97. package/node_modules/@llblab/pi-telegram/lib/outbound-attachments.ts +51 -10
  98. package/node_modules/@llblab/pi-telegram/lib/paths.ts +29 -0
  99. package/node_modules/@llblab/pi-telegram/lib/polling.ts +85 -17
  100. package/node_modules/@llblab/pi-telegram/lib/prompts.ts +5 -2
  101. package/node_modules/@llblab/pi-telegram/lib/queue.ts +52 -18
  102. package/node_modules/@llblab/pi-telegram/lib/replies.ts +2 -2
  103. package/node_modules/@llblab/pi-telegram/lib/routing.ts +305 -112
  104. package/node_modules/@llblab/pi-telegram/lib/status.ts +10 -0
  105. package/node_modules/@llblab/pi-telegram/lib/sync.ts +308 -39
  106. package/node_modules/@llblab/pi-telegram/lib/telegram-api.ts +279 -4
  107. package/node_modules/@llblab/pi-telegram/lib/thread-cleanup-manager.ts +664 -0
  108. package/node_modules/@llblab/pi-telegram/lib/thread-display.ts +226 -0
  109. package/node_modules/@llblab/pi-telegram/lib/thread-naming.ts +118 -0
  110. package/node_modules/@llblab/pi-telegram/lib/threads.ts +1686 -129
  111. package/node_modules/@llblab/pi-telegram/lib/updates.ts +1319 -97
  112. package/node_modules/@llblab/pi-telegram/lib/workspace-admission.ts +1643 -0
  113. package/node_modules/@llblab/pi-telegram/lib/workspace-retirement.ts +968 -0
  114. package/node_modules/@llblab/pi-telegram/lib/workspace-slots.ts +84 -0
  115. package/node_modules/@llblab/pi-telegram/package.json +1 -1
  116. package/node_modules/@llblab/pi-telegram/screenshot.png +0 -0
  117. package/node_modules/@llblab/pi-telegram/scripts/measure-bus.mjs +83 -0
  118. package/node_modules/@llblab/pi-telegram/scripts/measure-workspace.mjs +101 -0
  119. package/node_modules/@llblab/{skills → pi-telegram/skills}/show-me/SKILL.md +28 -6
  120. package/node_modules/@llblab/pi-telegram/skills/show-me/references/telegram-surfaces.md +43 -0
  121. package/node_modules/@llblab/pi-telegram/skills/telegram-bridge/references/delivery-and-threads.md +1 -1
  122. package/node_modules/@llblab/skills/package.json +2 -3
  123. package/package.json +6 -5
@@ -18,6 +18,7 @@ export interface TelegramAgentMessageRuntimeDeps<TContext, TUpdate> {
18
18
  getAllowedChatId: () => number | undefined;
19
19
  getLeaderTarget: () => TelegramTarget | undefined;
20
20
  getLeaderThreadName: () => string | undefined;
21
+ getDisplayTitle?: (target: TelegramTarget) => string | undefined;
21
22
  followerRegistry: TelegramBusFollowerRegistry;
22
23
  getContext: () => TContext | undefined;
23
24
  handleUpdate: (update: TUpdate, ctx: TContext) => Promise<void>;
@@ -39,7 +40,7 @@ export function createTelegramAgentMessageRuntime<TContext, TUpdate>(
39
40
  if (leaderTarget?.threadId) {
40
41
  targets.push({
41
42
  target: { chatId: leaderTarget.chatId, threadId: leaderTarget.threadId },
42
- threadName: deps.getLeaderThreadName(),
43
+ threadName: deps.getDisplayTitle?.(leaderTarget) ?? deps.getLeaderThreadName(),
43
44
  });
44
45
  }
45
46
  for (const follower of deps.followerRegistry.list()) {
@@ -49,7 +50,7 @@ export function createTelegramAgentMessageRuntime<TContext, TUpdate>(
49
50
  chatId: follower.target.chatId,
50
51
  threadId: follower.target.threadId,
51
52
  },
52
- threadName: follower.threadName,
53
+ threadName: deps.getDisplayTitle?.(follower.target) ?? follower.threadName,
53
54
  });
54
55
  }
55
56
  return targets;
@@ -98,8 +99,10 @@ export function createTelegramAgentMessageRuntime<TContext, TUpdate>(
98
99
  if (allowedChatId === undefined || !ctx) {
99
100
  throw new Error("Telegram agent turn routing is unavailable.");
100
101
  }
102
+ const sourceTitle = (input.sourceTarget ? deps.getDisplayTitle?.(input.sourceTarget) : undefined)
103
+ ?? input.sourceThreadName;
101
104
  const sourceLabel =
102
- input.sourceThreadName
105
+ sourceTitle
103
106
  ?.replace(/[\r\n\[\]]+/g, " ")
104
107
  .trim()
105
108
  .slice(0, 64) || "Pi";
@@ -6,6 +6,7 @@
6
6
 
7
7
  import * as Activity from "./activity.ts";
8
8
  import * as ActivityVerbosity from "./activity-verbosity.ts";
9
+ import * as ChannelPosts from "./channel-posts.ts";
9
10
  import * as CommandTemplates from "./command-templates.ts";
10
11
  import * as Commands from "./commands.ts";
11
12
  import * as Config from "./config.ts";
@@ -498,6 +499,10 @@ interface TelegramCommandsAndToolsBindingDeps {
498
499
  stopPolling?: () => Promise<void | string>;
499
500
  recoverPollingStart?: Commands.TelegramBridgeCommandRegistrationDeps["recoverPollingStart"];
500
501
  getDisconnectThreadName?: () => string | undefined;
502
+ setRequestedThreadNameForPollingStart?: (
503
+ threadName: string | undefined,
504
+ ) => void;
505
+ validateThreadName?: Commands.TelegramBridgeCommandRegistrationDeps["validateThreadName"];
501
506
  onTransportChanged?: () => Promise<void> | void;
502
507
  getStatusLines: (
503
508
  options?: Status.TelegramBridgeStatusLineOptions,
@@ -512,6 +517,12 @@ interface TelegramCommandsAndToolsBindingDeps {
512
517
  target?: { chatId: number; threadId?: number };
513
518
  },
514
519
  ) => Promise<number | undefined>;
520
+ sendChannelMarkdownMessage: NonNullable<
521
+ OutboundAttachments.TelegramOutboundMessageToolRegistrationDeps["sendChannelMarkdownMessage"]
522
+ >;
523
+ listChannelPosts: ChannelPosts.TelegramChannelPostJournalStore["list"];
524
+ mutateChannelPost(input: { action: "edit" | "delete"; operationId: string;
525
+ mutationId: string; markdown?: string }): Promise<ChannelPosts.TelegramChannelPostRecord>;
515
526
  callMultipart: OutboundHandlers.TelegramVoiceReplySenderDeps["sendMultipart"];
516
527
  getDefaultChatId: () => number | undefined;
517
528
  getDefaultTarget?: () => OutboundAttachments.TelegramQueuedOutboundAttachmentTurnView["target"];
@@ -533,10 +544,15 @@ export function registerTelegramCommandsAndTools({
533
544
  stopPolling,
534
545
  recoverPollingStart,
535
546
  getDisconnectThreadName,
547
+ setRequestedThreadNameForPollingStart,
548
+ validateThreadName,
536
549
  onTransportChanged,
537
550
  getStatusLines,
538
551
  buttonActionStore,
539
552
  sendMarkdownReply,
553
+ sendChannelMarkdownMessage,
554
+ listChannelPosts,
555
+ mutateChannelPost,
540
556
  callMultipart,
541
557
  getDefaultChatId,
542
558
  getDefaultTarget,
@@ -556,6 +572,8 @@ export function registerTelegramCommandsAndTools({
556
572
  sendMarkdownReply,
557
573
  recordRuntimeEvent,
558
574
  });
575
+ ChannelPosts.registerTelegramChannelPostMutationTool(pi, { mutate: mutateChannelPost });
576
+ ChannelPosts.registerTelegramChannelPostListTool(pi, { list: listChannelPosts });
559
577
  OutboundAttachments.registerTelegramOutboundAttachmentTool(pi, {
560
578
  getActiveTurn: activeTurnRuntime.get,
561
579
  getDefaultChatId,
@@ -578,6 +596,7 @@ export function registerTelegramCommandsAndTools({
578
596
  ),
579
597
  sendMarkdownMessage: (chatId, markdown, options) =>
580
598
  sendMarkdownReply(chatId, undefined, markdown, options),
599
+ sendChannelMarkdownMessage,
581
600
  recordRuntimeEvent,
582
601
  });
583
602
  const queueAgentConnectionContext = (connected: boolean): void => {
@@ -636,7 +655,11 @@ export function registerTelegramCommandsAndTools({
636
655
  );
637
656
  }
638
657
  await configStore.load();
639
- configStore.setProfile(profileName, profile);
658
+ const latestProfile = configStore.getStoredConfig().profiles?.[profileName];
659
+ configStore.setProfile(profileName, {
660
+ ...profile,
661
+ threadDisplayMode: latestProfile?.threadDisplayMode,
662
+ });
640
663
  configStore.activateProfile(profileName);
641
664
  await onTransportChanged?.();
642
665
  await persistConfig(configStore.get());
@@ -670,16 +693,20 @@ export function registerTelegramCommandsAndTools({
670
693
  reloadConfig: configStore.load,
671
694
  hasBotToken: configStore.hasBotToken,
672
695
  startPolling: async (ctx, options) => {
696
+ setRequestedThreadNameForPollingStart?.(options?.requestedThreadName);
673
697
  try {
674
698
  return await lockedPollingRuntime.start(ctx, options);
675
699
  } catch (error) {
676
700
  recordRuntimeEvent("recovery", error, { phase: "polling-start" });
677
701
  throw error;
702
+ } finally {
703
+ setRequestedThreadNameForPollingStart?.(undefined);
678
704
  }
679
705
  },
680
706
  stopPolling: stopPolling ?? lockedPollingRuntime.stop,
681
707
  recoverPollingStart,
682
708
  getDisconnectThreadName,
709
+ validateThreadName,
683
710
  queueAgentConnectionContext,
684
711
  updateStatus,
685
712
  getProfileNames: () =>