@promptbook/cli 0.112.0-81 → 0.112.0-82

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.
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
15
15
  export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
16
16
  /**
17
17
  * Represents the version string of the Promptbook engine.
18
- * It follows semantic versioning (e.g., `0.112.0-79`).
18
+ * It follows semantic versioning (e.g., `0.112.0-81`).
19
19
  *
20
20
  * @generated
21
21
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/cli",
3
- "version": "0.112.0-81",
3
+ "version": "0.112.0-82",
4
4
  "description": "Promptbook: Create persistent AI agents that turn your company's scattered knowledge into action",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -23,6 +23,20 @@ import { ensureAgentsServerBuild, resolveAgentsServerAppPath } from './buildAgen
23
23
  */
24
24
  const USER_CHAT_JOB_WORKER_POLL_INTERVAL_MS = 2_000;
25
25
 
26
+ /**
27
+ * Number of identical worker failures suppressed before logging a repeated summary.
28
+ *
29
+ * @private internal constant of `ptbk agents-server`
30
+ */
31
+ const USER_CHAT_JOB_WORKER_REPEATED_ERROR_LOG_INTERVAL = 10;
32
+
33
+ /**
34
+ * Maximum worker response body length shown in foreground diagnostics.
35
+ *
36
+ * @private internal constant of `ptbk agents-server`
37
+ */
38
+ const USER_CHAT_JOB_WORKER_ERROR_BODY_MAX_LENGTH = 2_000;
39
+
26
40
  /**
27
41
  * HTTP status used by an idle internal worker tick with no job to process.
28
42
  *
@@ -114,6 +128,10 @@ type AgentsServerChildEnvironment = NodeJS.ProcessEnv & {
114
128
  type AgentsServerSupervisorState = {
115
129
  isContinuing: boolean;
116
130
  uiHandle?: CoderRunUiHandle;
131
+ lastUserChatJobWorkerError?: {
132
+ message: string;
133
+ repeatCount: number;
134
+ };
117
135
  nextExit?: {
118
136
  code: number | null;
119
137
  signal: NodeJS.Signals | null;
@@ -380,10 +398,16 @@ function startUserChatJobWorkerPump(options: {
380
398
 
381
399
  isTickRunning = true;
382
400
  triggerUserChatJobWorkerTick(options)
401
+ .then(() => {
402
+ clearUserChatJobWorkerError(options.state);
403
+ })
383
404
  .catch((error) => {
384
405
  const message = error instanceof Error ? error.message : String(error);
385
- logRunnerEvent(options.logStreams.runner, `User chat worker tick failed: ${message}`);
386
- addUiError(options.state, message);
406
+ reportUserChatJobWorkerError({
407
+ logStream: options.logStreams.runner,
408
+ message,
409
+ state: options.state,
410
+ });
387
411
  })
388
412
  .finally(() => {
389
413
  isTickRunning = false;
@@ -411,10 +435,111 @@ async function triggerUserChatJobWorkerTick(options: {
411
435
  });
412
436
 
413
437
  if (!response.ok && response.status !== HTTP_NO_CONTENT_STATUS_CODE) {
414
- throw new Error(`Internal user chat worker returned ${response.status} ${response.statusText}.`);
438
+ const details = await readUserChatJobWorkerErrorDetails(response);
439
+ throw new Error(createUserChatJobWorkerErrorMessage(response, details));
415
440
  }
416
441
  }
417
442
 
443
+ /**
444
+ * Reports worker failures while suppressing identical repeated foreground noise.
445
+ */
446
+ function reportUserChatJobWorkerError(options: {
447
+ readonly logStream: WriteStream;
448
+ readonly message: string;
449
+ readonly state: AgentsServerSupervisorState;
450
+ }): void {
451
+ const previousError = options.state.lastUserChatJobWorkerError;
452
+
453
+ if (previousError?.message === options.message) {
454
+ const repeatCount = previousError.repeatCount + 1;
455
+ options.state.lastUserChatJobWorkerError = {
456
+ message: options.message,
457
+ repeatCount,
458
+ };
459
+
460
+ if (repeatCount % USER_CHAT_JOB_WORKER_REPEATED_ERROR_LOG_INTERVAL !== 0) {
461
+ return;
462
+ }
463
+
464
+ const repeatedMessage = `User chat worker tick is still failing after ${repeatCount} attempts: ${options.message}`;
465
+ logRunnerEvent(options.logStream, repeatedMessage);
466
+ addUiError(options.state, repeatedMessage);
467
+ return;
468
+ }
469
+
470
+ options.state.lastUserChatJobWorkerError = {
471
+ message: options.message,
472
+ repeatCount: 1,
473
+ };
474
+ logRunnerEvent(options.logStream, `User chat worker tick failed: ${options.message}`);
475
+ addUiError(options.state, options.message);
476
+ }
477
+
478
+ /**
479
+ * Resets repeated-error suppression after a successful worker tick.
480
+ */
481
+ function clearUserChatJobWorkerError(state: AgentsServerSupervisorState): void {
482
+ state.lastUserChatJobWorkerError = undefined;
483
+ }
484
+
485
+ /**
486
+ * Reads a worker error payload so foreground logs show the route-level reason.
487
+ */
488
+ async function readUserChatJobWorkerErrorDetails(response: Response): Promise<string | null> {
489
+ const body = await response.text().catch(() => '');
490
+ const trimmedBody = body.trim();
491
+
492
+ if (!trimmedBody) {
493
+ return null;
494
+ }
495
+
496
+ const parsedMessage = parseUserChatJobWorkerErrorMessage(trimmedBody);
497
+ return truncateUserChatJobWorkerErrorDetails(parsedMessage || trimmedBody);
498
+ }
499
+
500
+ /**
501
+ * Extracts a readable error message from the worker route JSON response.
502
+ */
503
+ function parseUserChatJobWorkerErrorMessage(body: string): string | null {
504
+ try {
505
+ const parsedBody = JSON.parse(body) as {
506
+ error?: unknown;
507
+ message?: unknown;
508
+ };
509
+ const errorMessage = typeof parsedBody.error === 'string' ? parsedBody.error : undefined;
510
+ const fallbackMessage = typeof parsedBody.message === 'string' ? parsedBody.message : undefined;
511
+
512
+ return errorMessage || fallbackMessage || null;
513
+ } catch {
514
+ return null;
515
+ }
516
+ }
517
+
518
+ /**
519
+ * Builds the foreground worker failure message from HTTP status and route details.
520
+ */
521
+ function createUserChatJobWorkerErrorMessage(response: Response, details: string | null): string {
522
+ const statusText = response.statusText ? ` ${response.statusText}` : '';
523
+ const statusMessage = `${response.status}${statusText}`;
524
+
525
+ if (!details) {
526
+ return `Internal user chat worker returned ${statusMessage}.`;
527
+ }
528
+
529
+ return `Internal user chat worker returned ${statusMessage}: ${details}`;
530
+ }
531
+
532
+ /**
533
+ * Keeps foreground worker diagnostics bounded when a route returns a large payload.
534
+ */
535
+ function truncateUserChatJobWorkerErrorDetails(details: string): string {
536
+ if (details.length <= USER_CHAT_JOB_WORKER_ERROR_BODY_MAX_LENGTH) {
537
+ return details;
538
+ }
539
+
540
+ return `${details.slice(0, USER_CHAT_JOB_WORKER_ERROR_BODY_MAX_LENGTH)}...`;
541
+ }
542
+
418
543
  /**
419
544
  * Creates file streams for service output persisted below `./logs`.
420
545
  */