@promptbook/cli 0.112.0-112 → 0.112.0-114

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 (94) hide show
  1. package/README.md +7 -7
  2. package/apps/agents-server/README.md +1 -1
  3. package/apps/agents-server/next.config.ts +20 -1
  4. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/stream/route.ts +85 -56
  5. package/apps/agents-server/src/app/agents/[agentName]/chat/useAgentChatHistorySyncEffects.ts +7 -13
  6. package/apps/agents-server/src/app/api/admin/code-runners/route.ts +1 -1
  7. package/apps/agents-server/src/app/api/internal/user-chat-jobs/run/route.ts +1 -1
  8. package/apps/agents-server/src/database/migrations/2026-06-1300-user-chat-active-read-indexes.sql +7 -0
  9. package/apps/agents-server/src/instrumentation-client.ts +28 -0
  10. package/apps/agents-server/src/instrumentation.ts +16 -0
  11. package/apps/agents-server/src/sentry.edge.config.ts +18 -0
  12. package/apps/agents-server/src/sentry.server.config.ts +19 -0
  13. package/apps/agents-server/src/utils/agentRouting/resolveAgentRouteTarget.ts +38 -0
  14. package/apps/agents-server/src/utils/codeRunnerConfiguration.ts +1 -1
  15. package/apps/agents-server/src/utils/errorReporting/agentsServerSentryContext.ts +203 -0
  16. package/apps/agents-server/src/utils/errorReporting/registerServerErrorSentryLogging.ts +59 -9
  17. package/apps/agents-server/src/utils/errorReporting/sendApplicationErrorReportToSentry.ts +39 -3
  18. package/apps/agents-server/src/utils/errorReporting/sentrySdkConfig.ts +237 -0
  19. package/apps/agents-server/src/utils/errorReporting/sentryStore.ts +10 -0
  20. package/apps/agents-server/src/utils/externalChatRunner/createExternalAgentRepositoryFiles.ts +2 -2
  21. package/apps/agents-server/src/utils/userChat/createImmediateUserChatAnswerModelRequirements.ts +15 -12
  22. package/apps/agents-server/src/utils/userChat/createUserChatDetailPayload.ts +33 -18
  23. package/apps/agents-server/src/utils/userChat/hasPotentiallyPendingAssistantMessages.ts +26 -0
  24. package/apps/agents-server/src/utils/userChat/runImmediateUserChatAnswer.ts +1 -1
  25. package/apps/agents-server/src/utils/userChat/triggerUserChatJobWorker.ts +54 -19
  26. package/apps/agents-server/src/utils/vpsConfiguration.ts +1 -1
  27. package/esm/index.es.js +9285 -8807
  28. package/esm/index.es.js.map +1 -1
  29. package/esm/scripts/run-agent-chat/executeAgentChatTurn.d.ts +28 -0
  30. package/esm/scripts/run-agent-chat/runAgentChat.d.ts +5 -0
  31. package/esm/scripts/run-agent-chat/runAgentExec.d.ts +11 -0
  32. package/esm/scripts/run-agent-messages/messages/createAgentRunnerSystemMessage.d.ts +10 -0
  33. package/esm/scripts/run-codex-prompts/common/resolveInlineOrFileText.d.ts +14 -0
  34. package/esm/scripts/run-codex-prompts/common/runGoScript/printLiveScriptChunk.d.ts +4 -0
  35. package/esm/src/_packages/node.index.d.ts +20 -0
  36. package/esm/src/_packages/types.index.d.ts +16 -0
  37. package/esm/src/book-3.0/BookNodeAgentSource.d.ts +38 -0
  38. package/esm/src/book-3.0/CliAgent.d.ts +68 -0
  39. package/esm/src/book-3.0/LiteAgent.d.ts +68 -0
  40. package/esm/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.d.ts +12 -0
  41. package/esm/src/cli/cli-commands/agent/agentCliOptions.d.ts +38 -0
  42. package/esm/src/cli/cli-commands/agent/chat.d.ts +10 -0
  43. package/esm/src/cli/cli-commands/agent/exec.d.ts +10 -0
  44. package/esm/src/cli/cli-commands/agent/run.test.d.ts +1 -0
  45. package/esm/src/cli/cli-commands/agent.d.ts +14 -0
  46. package/esm/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +3 -4
  47. package/esm/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +9 -9
  48. package/esm/src/version.d.ts +1 -1
  49. package/package.json +2 -1
  50. package/src/_packages/node.index.ts +20 -0
  51. package/src/_packages/types.index.ts +16 -0
  52. package/src/book-3.0/BookNodeAgentSource.ts +135 -0
  53. package/src/book-3.0/CliAgent.ts +236 -0
  54. package/src/book-3.0/LiteAgent.ts +468 -0
  55. package/src/book-components/BookEditor/BookEditor.module.css +61 -0
  56. package/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.tsx +74 -0
  57. package/src/book-components/BookEditor/BookEditorActionbar.tsx +3 -3
  58. package/src/cli/cli-commands/agent/agentCliOptions.ts +92 -0
  59. package/src/cli/cli-commands/agent/chat.ts +54 -0
  60. package/src/cli/cli-commands/agent/exec.ts +60 -0
  61. package/src/cli/cli-commands/agent.ts +44 -0
  62. package/src/cli/cli-commands/agents-server/startAgentsServer.ts +3 -19
  63. package/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.ts +1 -1
  64. package/src/cli/cli-commands/common/promptRunnerCliOptions.ts +27 -23
  65. package/src/cli/promptbookCli.ts +2 -0
  66. package/src/other/templates/getTemplatesPipelineCollection.ts +747 -771
  67. package/src/version.ts +2 -2
  68. package/src/versions.txt +2 -0
  69. package/umd/index.umd.js +9285 -8807
  70. package/umd/index.umd.js.map +1 -1
  71. package/umd/scripts/run-agent-chat/executeAgentChatTurn.d.ts +28 -0
  72. package/umd/scripts/run-agent-chat/runAgentChat.d.ts +5 -0
  73. package/umd/scripts/run-agent-chat/runAgentExec.d.ts +11 -0
  74. package/umd/scripts/run-agent-messages/messages/createAgentRunnerSystemMessage.d.ts +10 -0
  75. package/umd/scripts/run-codex-prompts/common/resolveInlineOrFileText.d.ts +14 -0
  76. package/umd/scripts/run-codex-prompts/common/runGoScript/printLiveScriptChunk.d.ts +4 -0
  77. package/umd/src/_packages/node.index.d.ts +20 -0
  78. package/umd/src/_packages/types.index.d.ts +16 -0
  79. package/umd/src/book-3.0/BookNodeAgentSource.d.ts +38 -0
  80. package/umd/src/book-3.0/CliAgent.d.ts +68 -0
  81. package/umd/src/book-3.0/CliAgent.test.d.ts +1 -0
  82. package/umd/src/book-3.0/LiteAgent.d.ts +68 -0
  83. package/umd/src/book-3.0/LiteAgent.test.d.ts +1 -0
  84. package/umd/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.d.ts +12 -0
  85. package/umd/src/cli/cli-commands/agent/agentCliOptions.d.ts +38 -0
  86. package/umd/src/cli/cli-commands/agent/chat.d.ts +10 -0
  87. package/umd/src/cli/cli-commands/agent/exec.d.ts +10 -0
  88. package/umd/src/cli/cli-commands/agent/run.test.d.ts +1 -0
  89. package/umd/src/cli/cli-commands/agent.d.ts +14 -0
  90. package/umd/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +3 -4
  91. package/umd/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +9 -9
  92. package/umd/src/version.d.ts +1 -1
  93. /package/esm/src/{cli/cli-commands/agents-server/startAgentsServer.test.d.ts → book-3.0/CliAgent.test.d.ts} +0 -0
  94. /package/{umd/src/cli/cli-commands/agents-server/startAgentsServer.test.d.ts → esm/src/book-3.0/LiteAgent.test.d.ts} +0 -0
@@ -5,7 +5,7 @@ import { parseAgentSourceWithCommitments } from '../../../../../src/book-2.0/age
5
5
  import type { string_book } from '../../../../../src/book-2.0/agent-source/string_book';
6
6
 
7
7
  /**
8
- * Commitments safe to use in the immediate answer without triggering slow tools, knowledge, imports, or memory.
8
+ * Commitments safe to use in the immediate pre-answer without triggering slow tools, knowledge, imports, or memory.
9
9
  */
10
10
  const IMMEDIATE_USER_CHAT_ANSWER_INSTRUCTION_COMMITMENTS = new Set<string>([
11
11
  'PERSONA',
@@ -26,27 +26,30 @@ const IMMEDIATE_USER_CHAT_ANSWER_INSTRUCTION_COMMITMENTS = new Set<string>([
26
26
  ]);
27
27
 
28
28
  /**
29
- * Prefix added to the immediate answer system message.
29
+ * Prefix added to the immediate pre-answer system message.
30
30
  */
31
31
  const IMMEDIATE_USER_CHAT_ANSWER_SYSTEM_PREAMBLE = spaceTrim(`
32
- You are preparing a fast draft answer for the user while a slower full agent run continues separately.
33
- This response is not the final answer.
34
- These immediate-answer rules override any agent instruction below that would make the answer sound final.
32
+ You are preparing a short in-progress confirmation for the user while a slower full agent run continues separately.
33
+ This response is not the final answer. It is only a confirmation that the task is being handled.
34
+ These immediate-answer rules override any agent instruction below that would make the answer sound final or complete.
35
35
 
36
36
  At the start of every response, clearly say in the user's language:
37
- - This is only a draft or preliminary answer, not the final answer.
38
- - The final answer will arrive in several minutes after the external service finishes processing.
39
- - The final answer can change or correct this draft, so the user should not treat this draft as final.
37
+ - You understood what the user wants.
38
+ - You are working on it now or the job has already started.
39
+ - The final answer will arrive after the background processing finishes.
40
40
 
41
- After that notice, give a brief useful draft of what is happening or the likely answer.
41
+ Keep the whole response short, preferably one or two sentences.
42
+ Do not provide any part of the final answer yet.
43
+ Do not include code snippets, detailed steps, calculations, drafted content, likely conclusions, or partial deliverables.
44
+ If helpful, briefly name the kind of work being done, such as writing code, checking something, preparing an answer, or generating an image.
42
45
  Answer directly and use only the instructions, conversation, attachments, and general model knowledge available in this request.
43
46
  Do not use or claim to have used external tools, memory, knowledge bases, web browsing, search, calendar, email, projects, or teammate agents.
44
- Never present this draft as complete or definitive.
45
- If the user asks for something that clearly requires those unavailable capabilities, explain that the checked final answer is still being prepared.
47
+ Never present this message as complete, definitive, or ready to use.
48
+ If the user asks for something that clearly requires unavailable capabilities, simply say the checked final answer is still being prepared.
46
49
  `);
47
50
 
48
51
  /**
49
- * Creates the lightweight model requirements used by the immediate answer path.
52
+ * Creates the lightweight model requirements used by the immediate pre-answer path.
50
53
  */
51
54
  export function createImmediateUserChatAnswerModelRequirements(
52
55
  agentSource: string_book,
@@ -1,5 +1,6 @@
1
1
  import type { UserChatRecord } from './UserChatRecord';
2
2
  import { synchronizeLocalUserChatJobsForChat } from '../localChatRunner/synchronizeLocalUserChatJobs';
3
+ import { hasPotentiallyPendingAssistantMessages } from './hasPotentiallyPendingAssistantMessages';
3
4
  import { createUserChatTimeoutActivity } from '../userChatTimeout/createUserChatTimeoutActivity';
4
5
  import { listUserChatTimeouts } from '../userChatTimeout/userChatTimeoutStore';
5
6
  import { createUserChatSummary } from './createUserChatSummary';
@@ -18,31 +19,45 @@ export async function createUserChatDetailPayload(chat: UserChatRecord): Promise
18
19
  activeTimeouts: Awaited<ReturnType<typeof listUserChatTimeouts>>;
19
20
  }> {
20
21
  let currentChat = chat;
21
- const hasSynchronizedLocalJobs = await synchronizeLocalUserChatJobsForChat(currentChat);
22
-
23
- if (hasSynchronizedLocalJobs) {
24
- const refreshedChat = await getUserChat({
25
- userId: currentChat.userId,
26
- agentPermanentId: currentChat.agentPermanentId,
27
- chatId: currentChat.id,
28
- });
29
-
30
- if (refreshedChat) {
31
- currentChat = refreshedChat;
32
- }
33
- }
34
-
35
22
  let activeJobs = await listUserChatJobs({
36
23
  userId: currentChat.userId,
37
24
  agentPermanentId: currentChat.agentPermanentId,
38
25
  chatId: currentChat.id,
39
26
  onlyActive: true,
40
27
  });
28
+ const shouldInspectJobState =
29
+ activeJobs.length > 0 || hasPotentiallyPendingAssistantMessages(currentChat.messages);
41
30
 
42
- const hasReconciledJobs = await reconcileUserChatActiveJobs({
43
- chat: currentChat,
44
- activeJobs,
45
- });
31
+ if (shouldInspectJobState) {
32
+ const hasSynchronizedLocalJobs = await synchronizeLocalUserChatJobsForChat(currentChat);
33
+
34
+ if (hasSynchronizedLocalJobs) {
35
+ const refreshedChat = await getUserChat({
36
+ userId: currentChat.userId,
37
+ agentPermanentId: currentChat.agentPermanentId,
38
+ chatId: currentChat.id,
39
+ });
40
+
41
+ if (refreshedChat) {
42
+ currentChat = refreshedChat;
43
+ }
44
+
45
+ activeJobs = await listUserChatJobs({
46
+ userId: currentChat.userId,
47
+ agentPermanentId: currentChat.agentPermanentId,
48
+ chatId: currentChat.id,
49
+ onlyActive: true,
50
+ });
51
+ }
52
+ }
53
+
54
+ const hasReconciledJobs =
55
+ activeJobs.length > 0
56
+ ? await reconcileUserChatActiveJobs({
57
+ chat: currentChat,
58
+ activeJobs,
59
+ })
60
+ : false;
46
61
 
47
62
  if (hasReconciledJobs) {
48
63
  const refreshedChat = await getUserChat({
@@ -0,0 +1,26 @@
1
+ import type { ChatMessage } from '@promptbook-local/types';
2
+
3
+ /**
4
+ * Returns `true` when the current transcript still suggests unfinished assistant work.
5
+ *
6
+ * This is intentionally message-based so readers can avoid heavier reconciliation work for
7
+ * settled chats while still inspecting threads that contain incomplete placeholders.
8
+ *
9
+ * @param messages - Current persisted chat transcript.
10
+ * @returns Whether the transcript still looks unfinished from the UI perspective.
11
+ * @private internal utility of `userChat`
12
+ */
13
+ export function hasPotentiallyPendingAssistantMessages(messages: ReadonlyArray<ChatMessage>): boolean {
14
+ return messages.some((message) => {
15
+ const sender = String(message.sender || '').toUpperCase();
16
+ if (sender !== 'AGENT' && sender !== 'MODEL') {
17
+ return false;
18
+ }
19
+
20
+ return (
21
+ message.isComplete === false ||
22
+ message.lifecycleState === 'queued' ||
23
+ message.lifecycleState === 'running'
24
+ );
25
+ });
26
+ }
@@ -44,7 +44,7 @@ type RunImmediateUserChatAnswerOptions = {
44
44
  };
45
45
 
46
46
  /**
47
- * Runs a fast local LLM answer into the incomplete assistant placeholder while the external runner is still working.
47
+ * Runs a fast local LLM pre-answer into the incomplete assistant placeholder while the external runner is still working.
48
48
  */
49
49
  export async function runImmediateUserChatAnswer(
50
50
  job: UserChatJobRecord,
@@ -1,28 +1,63 @@
1
1
  import { resolveUserChatWorkerInternalToken } from './resolveUserChatWorkerInternalToken';
2
+ import { retryWithBackoff } from '../retryWithBackoff';
3
+
4
+ /**
5
+ * Number of retries for transient transport failures while waking the durable chat worker.
6
+ */
7
+ const USER_CHAT_WORKER_TRIGGER_FETCH_RETRIES = 2;
8
+
9
+ /**
10
+ * Initial wait before retrying a failed worker wake-up request.
11
+ */
12
+ const USER_CHAT_WORKER_TRIGGER_FETCH_INITIAL_DELAY_MS = 250;
13
+
14
+ /**
15
+ * Maximum wait before retrying a failed worker wake-up request.
16
+ */
17
+ const USER_CHAT_WORKER_TRIGGER_FETCH_MAX_DELAY_MS = 1_000;
18
+
19
+ /**
20
+ * Multiplier used between worker wake-up retry waits.
21
+ */
22
+ const USER_CHAT_WORKER_TRIGGER_FETCH_BACKOFF_FACTOR = 2;
23
+
24
+ /**
25
+ * Randomized extra delay ratio for worker wake-up retry waits.
26
+ */
27
+ const USER_CHAT_WORKER_TRIGGER_FETCH_JITTER_RATIO = 0.2;
2
28
 
3
29
  /**
4
30
  * Schedules one best-effort internal worker invocation for durable chat jobs.
5
31
  */
6
- export async function triggerUserChatJobWorker(options: {
7
- origin: string;
8
- preferredJobId?: string;
9
- }): Promise<void> {
32
+ export async function triggerUserChatJobWorker(options: { origin: string; preferredJobId?: string }): Promise<void> {
10
33
  const workerUrl = new URL('/api/internal/user-chat-jobs/run', ensureTrailingSlashlessOrigin(options.origin));
11
- const response = await fetch(workerUrl, {
12
- method: 'POST',
13
- cache: 'no-store',
14
- headers: {
15
- 'Content-Type': 'application/json',
16
- 'x-user-chat-worker-token': resolveUserChatWorkerInternalToken(),
17
- },
18
- body: JSON.stringify(
19
- options.preferredJobId
20
- ? {
21
- preferredJobId: options.preferredJobId,
22
- }
23
- : {},
24
- ),
25
- });
34
+ const response = (
35
+ await retryWithBackoff(
36
+ async () =>
37
+ await fetch(workerUrl, {
38
+ method: 'POST',
39
+ cache: 'no-store',
40
+ headers: {
41
+ 'Content-Type': 'application/json',
42
+ 'x-user-chat-worker-token': resolveUserChatWorkerInternalToken(),
43
+ },
44
+ body: JSON.stringify(
45
+ options.preferredJobId
46
+ ? {
47
+ preferredJobId: options.preferredJobId,
48
+ }
49
+ : {},
50
+ ),
51
+ }),
52
+ {
53
+ retries: USER_CHAT_WORKER_TRIGGER_FETCH_RETRIES,
54
+ initialDelayMs: USER_CHAT_WORKER_TRIGGER_FETCH_INITIAL_DELAY_MS,
55
+ maxDelayMs: USER_CHAT_WORKER_TRIGGER_FETCH_MAX_DELAY_MS,
56
+ backoffFactor: USER_CHAT_WORKER_TRIGGER_FETCH_BACKOFF_FACTOR,
57
+ jitterRatio: USER_CHAT_WORKER_TRIGGER_FETCH_JITTER_RATIO,
58
+ },
59
+ )
60
+ ).value;
26
61
 
27
62
  if (!response.ok && response.status !== 204) {
28
63
  throw new Error(`Failed to trigger user chat worker: ${response.status} ${response.statusText}`);
@@ -23,7 +23,7 @@ export const VPS_ENVIRONMENT_VARIABLE_KEYS = [
23
23
  'NEXT_PUBLIC_SITE_URL',
24
24
  'ADMIN_PASSWORD',
25
25
  'OPENAI_API_KEY',
26
- 'PTBK_AGENT',
26
+ 'PTBK_HARNESS',
27
27
  'PTBK_MODEL',
28
28
  'PTBK_THINKING_LEVEL',
29
29
  'PORT',