@promptbook/cli 0.114.0-12 → 0.114.0-13

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/apps/agents-server/src/app/agents/[agentName]/AgentChatWrapper.tsx +7 -4
  2. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentGoalChatPlannedMessages.tsx +23 -8
  3. package/apps/agents-server/src/app/agents/[agentName]/chat/CanonicalAgentChatSurface.tsx +14 -3
  4. package/apps/agents-server/src/app/agents/[agentName]/chat/page.tsx +2 -20
  5. package/apps/agents-server/src/app/agents/[agentName]/page.tsx +2 -1
  6. package/apps/agents-server/src/app/agents/[agentName]/projectReferenceActions.ts +61 -0
  7. package/apps/agents-server/src/components/AgentProjects/resolveLatestCompletedAgentMessageKey.ts +32 -0
  8. package/apps/agents-server/src/components/AgentProjects/useAgentProjectMarkdownReferences.ts +124 -2
  9. package/apps/agents-server/src/languages/ServerTranslationKeys.ts +3 -0
  10. package/apps/agents-server/src/languages/translations/czech.yaml +3 -0
  11. package/apps/agents-server/src/languages/translations/english.yaml +3 -0
  12. package/apps/agents-server/src/tools/agentGoalChatTimeoutToolFunctions.ts +24 -2
  13. package/apps/agents-server/src/tools/agentGoalChatTimeoutTools.ts +5 -4
  14. package/apps/agents-server/src/utils/agentGoalChat/agentGoalChatPlannedMessageActions.ts +38 -9
  15. package/apps/agents-server/src/utils/agentGoalChat/createAgentGoalChatNoteContent.ts +15 -6
  16. package/apps/agents-server/src/utils/agentProjects/listAgentProjectNames.ts +35 -0
  17. package/apps/agents-server/src/utils/agentProjects/listAgentProjects.ts +6 -23
  18. package/apps/agents-server/src/utils/agentProjects/resolveAgentChatProjectReferences.ts +25 -0
  19. package/apps/agents-server/src/utils/chatMessageChips/createAnsweredMessageChipToolCalls.ts +37 -0
  20. package/apps/agents-server/src/utils/chatMessageChips/createPlannedMessageChipToolCalls.ts +39 -0
  21. package/apps/agents-server/src/utils/chatMessageChips/createTouchedProjectChipToolCalls.ts +75 -0
  22. package/apps/agents-server/src/utils/localChatRunner/applyLocalAgentPlannedMessageCommands.ts +212 -0
  23. package/apps/agents-server/src/utils/localChatRunner/prepareLocalAgentPlannedMessagesSidecar.ts +66 -0
  24. package/apps/agents-server/src/utils/localChatRunner/processLocalUserChatJob.ts +110 -22
  25. package/apps/agents-server/src/utils/userChat/persistUserChatJobTerminalState.ts +5 -0
  26. package/apps/agents-server/src/utils/userChat/userChatJobRunReport.ts +30 -0
  27. package/apps/agents-server/src/utils/userChatTimeout/createTimeoutWakeUpMessage.ts +9 -1
  28. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/repeatFiredUserChatTimeout.ts +74 -0
  29. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore.ts +1 -0
  30. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutWorker.ts +63 -54
  31. package/esm/index.es.js +639 -80
  32. package/esm/index.es.js.map +1 -1
  33. package/esm/scripts/run-agent-messages/messages/buildAgentGoalChatPromptSection.d.ts +22 -4
  34. package/esm/scripts/run-agent-messages/messages/buildAgentMessagePrompt.d.ts +3 -3
  35. package/esm/scripts/run-agent-messages/messages/loadAgentPlannedMessagesSidecar.d.ts +10 -0
  36. package/esm/scripts/run-agent-messages/messages/resolveTouchedAgentProjects.d.ts +15 -0
  37. package/esm/src/book-3.0/AgentMessageRunReport.d.ts +28 -0
  38. package/esm/src/book-3.0/AgentPlannedMessagesSidecar.d.ts +94 -0
  39. package/esm/src/book-3.0/AgentPlannedMessagesSidecar.test.d.ts +1 -0
  40. package/esm/src/book-3.0/createAgentMessageSidecarBaseName.d.ts +13 -0
  41. package/esm/src/book-components/Chat/utils/agentProjectToolCall.d.ts +46 -0
  42. package/esm/src/book-components/Chat/utils/timeoutToolCallPresentation.d.ts +24 -0
  43. package/esm/src/utils/agent-message-runtime/parseAgentMessageRuntimeLogEvents.d.ts +59 -0
  44. package/esm/src/utils/agent-message-runtime/resolveAgentMessageTouchedProjectNames.d.ts +19 -0
  45. package/esm/src/utils/agent-message-runtime/resolveAgentMessageTouchedProjectNames.test.d.ts +1 -0
  46. package/esm/src/version.d.ts +1 -1
  47. package/package.json +1 -1
  48. package/src/book-3.0/AgentMessageRunReport.ts +76 -0
  49. package/src/book-3.0/AgentPlannedMessagesSidecar.ts +229 -0
  50. package/src/book-3.0/AgentTeamConversationWorkspace.ts +3 -5
  51. package/src/book-3.0/createAgentMessageSidecarBaseName.ts +20 -0
  52. package/src/book-components/Chat/Chat/Chat.module.css +6 -1
  53. package/src/book-components/Chat/Chat/renderToolCallDetails.tsx +1 -12
  54. package/src/book-components/Chat/utils/agentProjectToolCall.ts +74 -0
  55. package/src/book-components/Chat/utils/getToolCallChipletInfo.ts +28 -0
  56. package/src/book-components/Chat/utils/timeoutToolCallPresentation.ts +23 -3
  57. package/src/other/templates/getTemplatesPipelineCollection.ts +784 -738
  58. package/src/utils/agent-message-runtime/parseAgentMessageRuntimeLogEvents.ts +105 -0
  59. package/src/utils/agent-message-runtime/resolveAgentMessageRuntimeActivity.ts +6 -54
  60. package/src/utils/agent-message-runtime/resolveAgentMessageTouchedProjectNames.ts +147 -0
  61. package/src/version.ts +2 -2
  62. package/src/versions.txt +1 -0
  63. package/umd/index.umd.js +639 -80
  64. package/umd/index.umd.js.map +1 -1
  65. package/umd/scripts/run-agent-messages/messages/buildAgentGoalChatPromptSection.d.ts +22 -4
  66. package/umd/scripts/run-agent-messages/messages/buildAgentMessagePrompt.d.ts +3 -3
  67. package/umd/scripts/run-agent-messages/messages/loadAgentPlannedMessagesSidecar.d.ts +10 -0
  68. package/umd/scripts/run-agent-messages/messages/resolveTouchedAgentProjects.d.ts +15 -0
  69. package/umd/src/book-3.0/AgentMessageRunReport.d.ts +28 -0
  70. package/umd/src/book-3.0/AgentPlannedMessagesSidecar.d.ts +94 -0
  71. package/umd/src/book-3.0/AgentPlannedMessagesSidecar.test.d.ts +1 -0
  72. package/umd/src/book-3.0/createAgentMessageSidecarBaseName.d.ts +13 -0
  73. package/umd/src/book-components/Chat/utils/agentProjectToolCall.d.ts +46 -0
  74. package/umd/src/book-components/Chat/utils/timeoutToolCallPresentation.d.ts +24 -0
  75. package/umd/src/utils/agent-message-runtime/parseAgentMessageRuntimeLogEvents.d.ts +59 -0
  76. package/umd/src/utils/agent-message-runtime/resolveAgentMessageTouchedProjectNames.d.ts +19 -0
  77. package/umd/src/utils/agent-message-runtime/resolveAgentMessageTouchedProjectNames.test.d.ts +1 -0
  78. package/umd/src/version.d.ts +1 -1
  79. package/esm/apps/agents-server/src/utils/agentGoalChat/agentGoalChatConstants.d.ts +0 -12
  80. package/umd/apps/agents-server/src/utils/agentGoalChat/agentGoalChatConstants.d.ts +0 -12
@@ -30,6 +30,7 @@ import {
30
30
  markUserChatTimeoutCompleted,
31
31
  markUserChatTimeoutFailed,
32
32
  recoverExpiredRunningUserChatTimeouts,
33
+ repeatFiredUserChatTimeout,
33
34
  } from './userChatTimeoutStore';
34
35
 
35
36
  /**
@@ -172,6 +173,7 @@ async function recordAgentGoalChatPlannedMessageNote(timeout: UserChatTimeoutRec
172
173
  content: createAgentGoalChatPlannedMessageNoteContent({
173
174
  timeoutId: timeout.timeoutId,
174
175
  dueAt: timeout.dueAt,
176
+ intervalMs: timeout.recurrenceIntervalMs,
175
177
  message: timeout.message,
176
178
  }),
177
179
  }).catch((error) => {
@@ -331,7 +333,7 @@ async function processClaimedUserChatTimeout(timeout: UserChatTimeoutRecord): Pr
331
333
  return;
332
334
  }
333
335
 
334
- const timeoutClientMessageId = createTimeoutClientMessageId(latestTimeout.timeoutId);
336
+ const timeoutClientMessageId = createTimeoutClientMessageId(latestTimeout);
335
337
  let queuedJob = await getUserChatJobByClientMessageId({
336
338
  userId: latestTimeout.userId,
337
339
  agentPermanentId: latestTimeout.agentPermanentId,
@@ -349,6 +351,7 @@ async function processClaimedUserChatTimeout(timeout: UserChatTimeoutRecord): Pr
349
351
  messageContent: createTimeoutWakeUpMessage({
350
352
  timeoutId: latestTimeout.timeoutId,
351
353
  durationMs: latestTimeout.durationMs,
354
+ intervalMs: latestTimeout.recurrenceIntervalMs,
352
355
  message: latestTimeout.message,
353
356
  }),
354
357
  messageSender: isAgentGoalChatId(latestTimeout.chatId) ? 'AGENT' : 'USER',
@@ -391,42 +394,19 @@ async function processClaimedUserChatTimeout(timeout: UserChatTimeoutRecord): Pr
391
394
  return;
392
395
  }
393
396
 
394
- const completedTimeout = await markUserChatTimeoutCompleted(latestTimeout.timeoutId);
395
-
396
- if (!completedTimeout || completedTimeout.status !== 'COMPLETED') {
397
- console.info('[user-chat-timeout]', 'skip_recurrence_non_completed', {
398
- chatId: latestTimeout.chatId,
399
- timeoutId: latestTimeout.timeoutId,
400
- resultingStatus: completedTimeout?.status || null,
401
- });
402
- return;
403
- }
404
-
405
397
  try {
406
- const recurringTimeout = await scheduleRecurringUserChatTimeout(completedTimeout);
407
-
408
- if (recurringTimeout) {
409
- console.info('[user-chat-timeout]', 'rescheduled', {
410
- chatId: recurringTimeout.chatId,
411
- previousTimeoutId: latestTimeout.timeoutId,
412
- timeoutId: recurringTimeout.timeoutId,
413
- dueAt: recurringTimeout.dueAt,
414
- recurrenceIntervalMs: recurringTimeout.recurrenceIntervalMs,
415
- });
416
- }
417
- } catch (recurrenceError) {
418
- const recurrenceReason =
419
- recurrenceError instanceof Error
420
- ? recurrenceError.message
421
- : 'Failed to schedule recurring timeout.';
398
+ await finishFiredUserChatTimeout(latestTimeout);
399
+ } catch (repetitionError) {
400
+ const repetitionReason =
401
+ repetitionError instanceof Error ? repetitionError.message : 'Failed to repeat the planned message.';
422
402
  await appendUserChatTimeoutWarningMessage(
423
403
  latestTimeout,
424
- `Recurring schedule failed: ${recurrenceReason}`,
404
+ `Repeating schedule failed: ${repetitionReason}`,
425
405
  ).catch(() => undefined);
426
- console.error('[user-chat-timeout]', 'recurrence_schedule_failed', {
406
+ console.error('[user-chat-timeout]', 'repeat_failed', {
427
407
  chatId: latestTimeout.chatId,
428
408
  timeoutId: latestTimeout.timeoutId,
429
- error: serializeError(recurrenceError as Error),
409
+ error: serializeError(repetitionError as Error),
430
410
  });
431
411
  }
432
412
 
@@ -553,33 +533,50 @@ function clearUserChatTimeoutLocalWakeup(timeoutId: string): void {
553
533
  }
554
534
 
555
535
  /**
556
- * Creates the next queued row for recurring timeouts after one successful fire.
536
+ * Closes one fired timeout, keeping a repeating planned message armed for its next interval.
537
+ *
538
+ * A repeating timeout is the durable counterpart of `setInterval`, so it is re-armed in place
539
+ * instead of being completed: it keeps one row, one identity, and one cancellation point. A
540
+ * timeout that does not repeat, or one that was cancelled while it was firing, becomes terminal.
541
+ *
542
+ * @param firedTimeout - Timeout whose wake-up turn was just queued.
557
543
  *
558
544
  * @private internal utility of userChatTimeout
559
545
  */
560
- async function scheduleRecurringUserChatTimeout(
561
- completedTimeout: UserChatTimeoutRecord,
562
- ): Promise<UserChatTimeoutRecord | null> {
563
- const recurrenceIntervalMs = completedTimeout.recurrenceIntervalMs;
546
+ async function finishFiredUserChatTimeout(firedTimeout: UserChatTimeoutRecord): Promise<void> {
547
+ if (firedTimeout.recurrenceIntervalMs) {
548
+ const repeatedTimeout = await repeatFiredUserChatTimeout(firedTimeout.timeoutId);
549
+
550
+ if (repeatedTimeout?.status === 'QUEUED') {
551
+ console.info('[user-chat-timeout]', 'repeated', {
552
+ chatId: repeatedTimeout.chatId,
553
+ timeoutId: repeatedTimeout.timeoutId,
554
+ dueAt: repeatedTimeout.dueAt,
555
+ recurrenceIntervalMs: repeatedTimeout.recurrenceIntervalMs,
556
+ runCount: repeatedTimeout.runCount,
557
+ });
558
+ scheduleUserChatTimeoutLocalWakeup(repeatedTimeout);
559
+ return;
560
+ }
564
561
 
565
- if (typeof recurrenceIntervalMs !== 'number' || !Number.isFinite(recurrenceIntervalMs) || recurrenceIntervalMs <= 0) {
566
- return null;
562
+ // Note: A planned message that could not be re-armed, for example because it was cancelled while
563
+ // it was firing, stops repeating and is closed like a timeout that never repeated
564
+ console.info('[user-chat-timeout]', 'skip_repeat', {
565
+ chatId: firedTimeout.chatId,
566
+ timeoutId: firedTimeout.timeoutId,
567
+ resultingStatus: repeatedTimeout?.status || null,
568
+ });
567
569
  }
568
570
 
569
- const nextDueAtIso = new Date(Date.now() + Math.floor(recurrenceIntervalMs)).toISOString();
570
- const nextTimeout = await createUserChatTimeout({
571
- userId: completedTimeout.userId,
572
- agentPermanentId: completedTimeout.agentPermanentId,
573
- chatId: completedTimeout.chatId,
574
- durationMs: Math.floor(recurrenceIntervalMs),
575
- recurrenceIntervalMs: Math.floor(recurrenceIntervalMs),
576
- dueAt: nextDueAtIso,
577
- message: completedTimeout.message || undefined,
578
- parameters: completedTimeout.parameters,
579
- });
571
+ const completedTimeout = await markUserChatTimeoutCompleted(firedTimeout.timeoutId);
580
572
 
581
- scheduleUserChatTimeoutLocalWakeup(nextTimeout);
582
- return nextTimeout;
573
+ if (!completedTimeout || completedTimeout.status !== 'COMPLETED') {
574
+ console.info('[user-chat-timeout]', 'skip_completion_non_completed', {
575
+ chatId: firedTimeout.chatId,
576
+ timeoutId: firedTimeout.timeoutId,
577
+ resultingStatus: completedTimeout?.status || null,
578
+ });
579
+ }
583
580
  }
584
581
 
585
582
  /**
@@ -600,12 +597,24 @@ function shouldDisableBackgroundWorkerLoop(): boolean {
600
597
  }
601
598
 
602
599
  /**
603
- * Builds the synthetic client message id used for timeout wake-ups.
600
+ * Builds the synthetic client message id used for one timeout wake-up.
601
+ *
602
+ * A repeating timeout keeps its identity across firings, so the id also carries how many times it
603
+ * already fired: retrying the very same firing stays idempotent, while the next repetition still
604
+ * queues its own wake-up turn.
605
+ *
606
+ * @param timeout - Timeout that is firing.
607
+ * @returns Client message id of this wake-up.
604
608
  *
605
609
  * @private internal utility of userChatTimeout
606
610
  */
607
- function createTimeoutClientMessageId(timeoutId: string): string {
608
- return `${USER_CHAT_TIMEOUT_CLIENT_MESSAGE_ID_PREFIX}${timeoutId}`;
611
+ function createTimeoutClientMessageId(timeout: Pick<UserChatTimeoutRecord, 'timeoutId' | 'runCount'>): string {
612
+ // Note: The first firing keeps the historical id, so wake-ups queued before repeating support stay deduplicated
613
+ if (timeout.runCount === 0) {
614
+ return `${USER_CHAT_TIMEOUT_CLIENT_MESSAGE_ID_PREFIX}${timeout.timeoutId}`;
615
+ }
616
+
617
+ return `${USER_CHAT_TIMEOUT_CLIENT_MESSAGE_ID_PREFIX}${timeout.timeoutId}:${timeout.runCount}`;
609
618
  }
610
619
 
611
620
  /**