@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.
@@ -35,9 +35,18 @@ const getCachedProvidedServer = cache(async (): Promise<ProvidedServer> => {
35
35
  const headersList = await headers();
36
36
  const requestHost = headersList.get('host');
37
37
  const xPromptbookServer = headersList.get('x-promptbook-server');
38
+
39
+ if (isLocalDevelopmentHost(requestHost)) {
40
+ return {
41
+ id: null,
42
+ publicUrl: resolveFallbackPublicUrl(requestHost),
43
+ tablePrefix: SUPABASE_TABLE_PREFIX,
44
+ };
45
+ }
46
+
38
47
  const registeredServers = await listRegisteredServersUsingServiceRole();
39
48
 
40
- if (registeredServers.length === 0 || isLocalDevelopmentHost(requestHost)) {
49
+ if (registeredServers.length === 0) {
41
50
  return {
42
51
  id: null,
43
52
  publicUrl: resolveFallbackPublicUrl(requestHost),
@@ -100,5 +109,14 @@ function isLocalDevelopmentHost(host: string | null): boolean {
100
109
  return false;
101
110
  }
102
111
 
103
- return host.startsWith('127.0.0.1') || host.startsWith('localhost');
112
+ const normalizedHost = host.trim().toLowerCase();
113
+
114
+ return (
115
+ normalizedHost === 'localhost' ||
116
+ normalizedHost.startsWith('localhost:') ||
117
+ normalizedHost === '127.0.0.1' ||
118
+ normalizedHost.startsWith('127.0.0.1:') ||
119
+ normalizedHost === '[::1]' ||
120
+ normalizedHost.startsWith('[::1]:')
121
+ );
104
122
  }
package/esm/index.es.js CHANGED
@@ -58,7 +58,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
58
58
  * @generated
59
59
  * @see https://github.com/webgptorg/promptbook
60
60
  */
61
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-81';
61
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-82';
62
62
  /**
63
63
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
64
64
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -35830,6 +35830,18 @@ async function withCurrentWorkingDirectory(directoryPath, callback) {
35830
35830
  * @private internal constant of `ptbk agents-server`
35831
35831
  */
35832
35832
  const USER_CHAT_JOB_WORKER_POLL_INTERVAL_MS = 2000;
35833
+ /**
35834
+ * Number of identical worker failures suppressed before logging a repeated summary.
35835
+ *
35836
+ * @private internal constant of `ptbk agents-server`
35837
+ */
35838
+ const USER_CHAT_JOB_WORKER_REPEATED_ERROR_LOG_INTERVAL = 10;
35839
+ /**
35840
+ * Maximum worker response body length shown in foreground diagnostics.
35841
+ *
35842
+ * @private internal constant of `ptbk agents-server`
35843
+ */
35844
+ const USER_CHAT_JOB_WORKER_ERROR_BODY_MAX_LENGTH = 2000;
35833
35845
  /**
35834
35846
  * HTTP status used by an idle internal worker tick with no job to process.
35835
35847
  *
@@ -36062,10 +36074,16 @@ function startUserChatJobWorkerPump(options) {
36062
36074
  }
36063
36075
  isTickRunning = true;
36064
36076
  triggerUserChatJobWorkerTick(options)
36077
+ .then(() => {
36078
+ clearUserChatJobWorkerError(options.state);
36079
+ })
36065
36080
  .catch((error) => {
36066
36081
  const message = error instanceof Error ? error.message : String(error);
36067
- logRunnerEvent(options.logStreams.runner, `User chat worker tick failed: ${message}`);
36068
- addUiError(options.state, message);
36082
+ reportUserChatJobWorkerError({
36083
+ logStream: options.logStreams.runner,
36084
+ message,
36085
+ state: options.state,
36086
+ });
36069
36087
  })
36070
36088
  .finally(() => {
36071
36089
  isTickRunning = false;
@@ -36087,8 +36105,87 @@ async function triggerUserChatJobWorkerTick(options) {
36087
36105
  body: '{}',
36088
36106
  });
36089
36107
  if (!response.ok && response.status !== HTTP_NO_CONTENT_STATUS_CODE) {
36090
- throw new Error(`Internal user chat worker returned ${response.status} ${response.statusText}.`);
36108
+ const details = await readUserChatJobWorkerErrorDetails(response);
36109
+ throw new Error(createUserChatJobWorkerErrorMessage(response, details));
36110
+ }
36111
+ }
36112
+ /**
36113
+ * Reports worker failures while suppressing identical repeated foreground noise.
36114
+ */
36115
+ function reportUserChatJobWorkerError(options) {
36116
+ const previousError = options.state.lastUserChatJobWorkerError;
36117
+ if ((previousError === null || previousError === void 0 ? void 0 : previousError.message) === options.message) {
36118
+ const repeatCount = previousError.repeatCount + 1;
36119
+ options.state.lastUserChatJobWorkerError = {
36120
+ message: options.message,
36121
+ repeatCount,
36122
+ };
36123
+ if (repeatCount % USER_CHAT_JOB_WORKER_REPEATED_ERROR_LOG_INTERVAL !== 0) {
36124
+ return;
36125
+ }
36126
+ const repeatedMessage = `User chat worker tick is still failing after ${repeatCount} attempts: ${options.message}`;
36127
+ logRunnerEvent(options.logStream, repeatedMessage);
36128
+ addUiError(options.state, repeatedMessage);
36129
+ return;
36130
+ }
36131
+ options.state.lastUserChatJobWorkerError = {
36132
+ message: options.message,
36133
+ repeatCount: 1,
36134
+ };
36135
+ logRunnerEvent(options.logStream, `User chat worker tick failed: ${options.message}`);
36136
+ addUiError(options.state, options.message);
36137
+ }
36138
+ /**
36139
+ * Resets repeated-error suppression after a successful worker tick.
36140
+ */
36141
+ function clearUserChatJobWorkerError(state) {
36142
+ state.lastUserChatJobWorkerError = undefined;
36143
+ }
36144
+ /**
36145
+ * Reads a worker error payload so foreground logs show the route-level reason.
36146
+ */
36147
+ async function readUserChatJobWorkerErrorDetails(response) {
36148
+ const body = await response.text().catch(() => '');
36149
+ const trimmedBody = body.trim();
36150
+ if (!trimmedBody) {
36151
+ return null;
36152
+ }
36153
+ const parsedMessage = parseUserChatJobWorkerErrorMessage(trimmedBody);
36154
+ return truncateUserChatJobWorkerErrorDetails(parsedMessage || trimmedBody);
36155
+ }
36156
+ /**
36157
+ * Extracts a readable error message from the worker route JSON response.
36158
+ */
36159
+ function parseUserChatJobWorkerErrorMessage(body) {
36160
+ try {
36161
+ const parsedBody = JSON.parse(body);
36162
+ const errorMessage = typeof parsedBody.error === 'string' ? parsedBody.error : undefined;
36163
+ const fallbackMessage = typeof parsedBody.message === 'string' ? parsedBody.message : undefined;
36164
+ return errorMessage || fallbackMessage || null;
36165
+ }
36166
+ catch (_a) {
36167
+ return null;
36168
+ }
36169
+ }
36170
+ /**
36171
+ * Builds the foreground worker failure message from HTTP status and route details.
36172
+ */
36173
+ function createUserChatJobWorkerErrorMessage(response, details) {
36174
+ const statusText = response.statusText ? ` ${response.statusText}` : '';
36175
+ const statusMessage = `${response.status}${statusText}`;
36176
+ if (!details) {
36177
+ return `Internal user chat worker returned ${statusMessage}.`;
36178
+ }
36179
+ return `Internal user chat worker returned ${statusMessage}: ${details}`;
36180
+ }
36181
+ /**
36182
+ * Keeps foreground worker diagnostics bounded when a route returns a large payload.
36183
+ */
36184
+ function truncateUserChatJobWorkerErrorDetails(details) {
36185
+ if (details.length <= USER_CHAT_JOB_WORKER_ERROR_BODY_MAX_LENGTH) {
36186
+ return details;
36091
36187
  }
36188
+ return `${details.slice(0, USER_CHAT_JOB_WORKER_ERROR_BODY_MAX_LENGTH)}...`;
36092
36189
  }
36093
36190
  /**
36094
36191
  * Creates file streams for service output persisted below `./logs`.