@promptbook/cli 0.112.0-81 → 0.112.0-84
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.
- package/apps/agents-server/README.md +7 -1
- package/apps/agents-server/src/database/$provideSupabaseForServer.ts +6 -0
- package/apps/agents-server/src/database/agentsServerDatabaseMode.ts +34 -0
- package/apps/agents-server/src/database/sqlite/$provideLocalSqliteSupabase.ts +1445 -0
- package/apps/agents-server/src/database/sqlite/resolveAgentsServerSqliteDatabasePath.ts +13 -0
- package/apps/agents-server/src/tools/$provideServer.ts +29 -2
- package/apps/agents-server/src/utils/serverRegistry.ts +13 -0
- package/apps/agents-server/src/utils/userChat/finalizeUserChatJob.ts +42 -0
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/claimNextDueUserChatTimeout.ts +63 -0
- package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/recoverExpiredRunningUserChatTimeouts.ts +47 -0
- package/apps/agents-server/src/utils/validateApiKey.ts +2 -18
- package/esm/apps/agents-server/src/database/agentsServerDatabaseMode.d.ts +20 -0
- package/esm/index.es.js +120 -5
- package/esm/index.es.js.map +1 -1
- package/esm/src/version.d.ts +1 -1
- package/package.json +2 -1
- package/src/book-components/Chat/save/pdf/buildChatPdf.ts +3 -26
- package/src/cli/cli-commands/agents-server/ensureAgentsServerEnvFile.ts +3 -1
- package/src/cli/cli-commands/agents-server/startAgentsServer.ts +148 -3
- package/src/other/templates/getTemplatesPipelineCollection.ts +844 -694
- package/src/version.ts +2 -2
- package/src/versions.txt +2 -0
- package/umd/apps/agents-server/src/database/agentsServerDatabaseMode.d.ts +20 -0
- package/umd/index.umd.js +120 -5
- package/umd/index.umd.js.map +1 -1
- package/umd/src/version.d.ts +1 -1
package/src/version.ts
CHANGED
|
@@ -16,11 +16,11 @@ export const BOOK_LANGUAGE_VERSION: string_semantic_version = '2.0.0';
|
|
|
16
16
|
* @generated
|
|
17
17
|
* @see https://github.com/webgptorg/promptbook
|
|
18
18
|
*/
|
|
19
|
-
export const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version = '0.112.0-
|
|
19
|
+
export const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version = '0.112.0-84';
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Represents the version string of the Promptbook engine.
|
|
23
|
-
* It follows semantic versioning (e.g., `0.112.0-
|
|
23
|
+
* It follows semantic versioning (e.g., `0.112.0-82`).
|
|
24
24
|
*
|
|
25
25
|
* @generated
|
|
26
26
|
*/
|
package/src/versions.txt
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment variable selecting the Agents Server database backend.
|
|
3
|
+
*/
|
|
4
|
+
export declare const AGENTS_SERVER_DATABASE_ENV_NAME = "PTBK_AGENTS_SERVER_DATABASE";
|
|
5
|
+
/**
|
|
6
|
+
* Environment variable pointing to the standalone SQLite database file.
|
|
7
|
+
*/
|
|
8
|
+
export declare const AGENTS_SERVER_SQLITE_PATH_ENV_NAME = "PTBK_AGENTS_SERVER_SQLITE_PATH";
|
|
9
|
+
/**
|
|
10
|
+
* Supported Agents Server database backends.
|
|
11
|
+
*/
|
|
12
|
+
export type AgentsServerDatabaseMode = 'supabase' | 'sqlite';
|
|
13
|
+
/**
|
|
14
|
+
* Resolves the configured Agents Server database backend.
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveAgentsServerDatabaseMode(): AgentsServerDatabaseMode;
|
|
17
|
+
/**
|
|
18
|
+
* Returns whether the Agents Server is using the local SQLite backend.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isAgentsServerSqliteMode(): boolean;
|
package/umd/index.umd.js
CHANGED
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
* @generated
|
|
61
61
|
* @see https://github.com/webgptorg/promptbook
|
|
62
62
|
*/
|
|
63
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
63
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-84';
|
|
64
64
|
/**
|
|
65
65
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
66
66
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -2471,9 +2471,11 @@
|
|
|
2471
2471
|
*/
|
|
2472
2472
|
const AGENTS_SERVER_ENV_CREATED_COMMENT = '# Created by `ptbk agents-server init` command';
|
|
2473
2473
|
/**
|
|
2474
|
-
* Variables required for a local Agents Server backed by
|
|
2474
|
+
* Variables required for a local Agents Server backed by Supabase or standalone SQLite.
|
|
2475
2475
|
*/
|
|
2476
2476
|
const REQUIRED_AGENTS_SERVER_ENV_VARIABLES = [
|
|
2477
|
+
createAgentsServerEnvVariable('PTBK_AGENTS_SERVER_DATABASE', 'supabase'),
|
|
2478
|
+
createAgentsServerEnvVariable('PTBK_AGENTS_SERVER_SQLITE_PATH', '.promptbook/agents-server.sqlite'),
|
|
2477
2479
|
createAgentsServerEnvVariable('OPENAI_API_KEY', ''),
|
|
2478
2480
|
createAgentsServerEnvVariable('POSTGRES_URL', ''),
|
|
2479
2481
|
createAgentsServerEnvVariable('NEXT_PUBLIC_SUPABASE_URL', ''),
|
|
@@ -35832,6 +35834,18 @@
|
|
|
35832
35834
|
* @private internal constant of `ptbk agents-server`
|
|
35833
35835
|
*/
|
|
35834
35836
|
const USER_CHAT_JOB_WORKER_POLL_INTERVAL_MS = 2000;
|
|
35837
|
+
/**
|
|
35838
|
+
* Number of identical worker failures suppressed before logging a repeated summary.
|
|
35839
|
+
*
|
|
35840
|
+
* @private internal constant of `ptbk agents-server`
|
|
35841
|
+
*/
|
|
35842
|
+
const USER_CHAT_JOB_WORKER_REPEATED_ERROR_LOG_INTERVAL = 10;
|
|
35843
|
+
/**
|
|
35844
|
+
* Maximum worker response body length shown in foreground diagnostics.
|
|
35845
|
+
*
|
|
35846
|
+
* @private internal constant of `ptbk agents-server`
|
|
35847
|
+
*/
|
|
35848
|
+
const USER_CHAT_JOB_WORKER_ERROR_BODY_MAX_LENGTH = 2000;
|
|
35835
35849
|
/**
|
|
35836
35850
|
* HTTP status used by an idle internal worker tick with no job to process.
|
|
35837
35851
|
*
|
|
@@ -35856,6 +35870,18 @@
|
|
|
35856
35870
|
* @private internal constant of `ptbk agents-server`
|
|
35857
35871
|
*/
|
|
35858
35872
|
const PTBK_AGENTS_SERVER_AGENT_ROOT_ENV = 'PTBK_AGENTS_SERVER_AGENT_ROOT';
|
|
35873
|
+
/**
|
|
35874
|
+
* Public database mode environment name consumed by the Agents Server app.
|
|
35875
|
+
*
|
|
35876
|
+
* @private internal constant of `ptbk agents-server`
|
|
35877
|
+
*/
|
|
35878
|
+
const PTBK_AGENTS_SERVER_DATABASE_ENV = 'PTBK_AGENTS_SERVER_DATABASE';
|
|
35879
|
+
/**
|
|
35880
|
+
* Local SQLite file environment name consumed by the Agents Server app.
|
|
35881
|
+
*
|
|
35882
|
+
* @private internal constant of `ptbk agents-server`
|
|
35883
|
+
*/
|
|
35884
|
+
const PTBK_AGENTS_SERVER_SQLITE_PATH_ENV = 'PTBK_AGENTS_SERVER_SQLITE_PATH';
|
|
35859
35885
|
/**
|
|
35860
35886
|
* Entropy size for the local-only token shared by the CLI pump and the Next app.
|
|
35861
35887
|
*
|
|
@@ -36025,11 +36051,15 @@
|
|
|
36025
36051
|
* Creates the subprocess environment for Next and its internal local runner bridge.
|
|
36026
36052
|
*/
|
|
36027
36053
|
function createAgentsServerChildEnvironment(port, agentRootPath) {
|
|
36054
|
+
const launchWorkingDirectory = process.cwd();
|
|
36028
36055
|
return {
|
|
36029
36056
|
...process.env,
|
|
36030
36057
|
PORT: String(port),
|
|
36031
36058
|
NEXT_PUBLIC_SITE_URL: process.env.NEXT_PUBLIC_SITE_URL || `http://localhost:${port}`,
|
|
36032
36059
|
[PTBK_AGENTS_SERVER_AGENT_ROOT_ENV]: agentRootPath,
|
|
36060
|
+
[PTBK_AGENTS_SERVER_SQLITE_PATH_ENV]: process.env[PTBK_AGENTS_SERVER_SQLITE_PATH_ENV] ||
|
|
36061
|
+
path.join(launchWorkingDirectory, '.promptbook', 'agents-server.sqlite'),
|
|
36062
|
+
[PTBK_AGENTS_SERVER_DATABASE_ENV]: process.env[PTBK_AGENTS_SERVER_DATABASE_ENV] || 'supabase',
|
|
36033
36063
|
// Next loads app-local `.env` values after the CLI has prepared this bridge environment.
|
|
36034
36064
|
PTBK_AGENTS_SERVER_USER_CHAT_WORKER_TOKEN: process.env.PTBK_AGENTS_SERVER_USER_CHAT_WORKER_TOKEN ||
|
|
36035
36065
|
crypto.randomBytes(LOCAL_USER_CHAT_WORKER_TOKEN_BYTE_LENGTH).toString('hex'),
|
|
@@ -36064,10 +36094,16 @@
|
|
|
36064
36094
|
}
|
|
36065
36095
|
isTickRunning = true;
|
|
36066
36096
|
triggerUserChatJobWorkerTick(options)
|
|
36097
|
+
.then(() => {
|
|
36098
|
+
clearUserChatJobWorkerError(options.state);
|
|
36099
|
+
})
|
|
36067
36100
|
.catch((error) => {
|
|
36068
36101
|
const message = error instanceof Error ? error.message : String(error);
|
|
36069
|
-
|
|
36070
|
-
|
|
36102
|
+
reportUserChatJobWorkerError({
|
|
36103
|
+
logStream: options.logStreams.runner,
|
|
36104
|
+
message,
|
|
36105
|
+
state: options.state,
|
|
36106
|
+
});
|
|
36071
36107
|
})
|
|
36072
36108
|
.finally(() => {
|
|
36073
36109
|
isTickRunning = false;
|
|
@@ -36089,8 +36125,87 @@
|
|
|
36089
36125
|
body: '{}',
|
|
36090
36126
|
});
|
|
36091
36127
|
if (!response.ok && response.status !== HTTP_NO_CONTENT_STATUS_CODE) {
|
|
36092
|
-
|
|
36128
|
+
const details = await readUserChatJobWorkerErrorDetails(response);
|
|
36129
|
+
throw new Error(createUserChatJobWorkerErrorMessage(response, details));
|
|
36130
|
+
}
|
|
36131
|
+
}
|
|
36132
|
+
/**
|
|
36133
|
+
* Reports worker failures while suppressing identical repeated foreground noise.
|
|
36134
|
+
*/
|
|
36135
|
+
function reportUserChatJobWorkerError(options) {
|
|
36136
|
+
const previousError = options.state.lastUserChatJobWorkerError;
|
|
36137
|
+
if ((previousError === null || previousError === void 0 ? void 0 : previousError.message) === options.message) {
|
|
36138
|
+
const repeatCount = previousError.repeatCount + 1;
|
|
36139
|
+
options.state.lastUserChatJobWorkerError = {
|
|
36140
|
+
message: options.message,
|
|
36141
|
+
repeatCount,
|
|
36142
|
+
};
|
|
36143
|
+
if (repeatCount % USER_CHAT_JOB_WORKER_REPEATED_ERROR_LOG_INTERVAL !== 0) {
|
|
36144
|
+
return;
|
|
36145
|
+
}
|
|
36146
|
+
const repeatedMessage = `User chat worker tick is still failing after ${repeatCount} attempts: ${options.message}`;
|
|
36147
|
+
logRunnerEvent(options.logStream, repeatedMessage);
|
|
36148
|
+
addUiError(options.state, repeatedMessage);
|
|
36149
|
+
return;
|
|
36150
|
+
}
|
|
36151
|
+
options.state.lastUserChatJobWorkerError = {
|
|
36152
|
+
message: options.message,
|
|
36153
|
+
repeatCount: 1,
|
|
36154
|
+
};
|
|
36155
|
+
logRunnerEvent(options.logStream, `User chat worker tick failed: ${options.message}`);
|
|
36156
|
+
addUiError(options.state, options.message);
|
|
36157
|
+
}
|
|
36158
|
+
/**
|
|
36159
|
+
* Resets repeated-error suppression after a successful worker tick.
|
|
36160
|
+
*/
|
|
36161
|
+
function clearUserChatJobWorkerError(state) {
|
|
36162
|
+
state.lastUserChatJobWorkerError = undefined;
|
|
36163
|
+
}
|
|
36164
|
+
/**
|
|
36165
|
+
* Reads a worker error payload so foreground logs show the route-level reason.
|
|
36166
|
+
*/
|
|
36167
|
+
async function readUserChatJobWorkerErrorDetails(response) {
|
|
36168
|
+
const body = await response.text().catch(() => '');
|
|
36169
|
+
const trimmedBody = body.trim();
|
|
36170
|
+
if (!trimmedBody) {
|
|
36171
|
+
return null;
|
|
36172
|
+
}
|
|
36173
|
+
const parsedMessage = parseUserChatJobWorkerErrorMessage(trimmedBody);
|
|
36174
|
+
return truncateUserChatJobWorkerErrorDetails(parsedMessage || trimmedBody);
|
|
36175
|
+
}
|
|
36176
|
+
/**
|
|
36177
|
+
* Extracts a readable error message from the worker route JSON response.
|
|
36178
|
+
*/
|
|
36179
|
+
function parseUserChatJobWorkerErrorMessage(body) {
|
|
36180
|
+
try {
|
|
36181
|
+
const parsedBody = JSON.parse(body);
|
|
36182
|
+
const errorMessage = typeof parsedBody.error === 'string' ? parsedBody.error : undefined;
|
|
36183
|
+
const fallbackMessage = typeof parsedBody.message === 'string' ? parsedBody.message : undefined;
|
|
36184
|
+
return errorMessage || fallbackMessage || null;
|
|
36185
|
+
}
|
|
36186
|
+
catch (_a) {
|
|
36187
|
+
return null;
|
|
36188
|
+
}
|
|
36189
|
+
}
|
|
36190
|
+
/**
|
|
36191
|
+
* Builds the foreground worker failure message from HTTP status and route details.
|
|
36192
|
+
*/
|
|
36193
|
+
function createUserChatJobWorkerErrorMessage(response, details) {
|
|
36194
|
+
const statusText = response.statusText ? ` ${response.statusText}` : '';
|
|
36195
|
+
const statusMessage = `${response.status}${statusText}`;
|
|
36196
|
+
if (!details) {
|
|
36197
|
+
return `Internal user chat worker returned ${statusMessage}.`;
|
|
36198
|
+
}
|
|
36199
|
+
return `Internal user chat worker returned ${statusMessage}: ${details}`;
|
|
36200
|
+
}
|
|
36201
|
+
/**
|
|
36202
|
+
* Keeps foreground worker diagnostics bounded when a route returns a large payload.
|
|
36203
|
+
*/
|
|
36204
|
+
function truncateUserChatJobWorkerErrorDetails(details) {
|
|
36205
|
+
if (details.length <= USER_CHAT_JOB_WORKER_ERROR_BODY_MAX_LENGTH) {
|
|
36206
|
+
return details;
|
|
36093
36207
|
}
|
|
36208
|
+
return `${details.slice(0, USER_CHAT_JOB_WORKER_ERROR_BODY_MAX_LENGTH)}...`;
|
|
36094
36209
|
}
|
|
36095
36210
|
/**
|
|
36096
36211
|
* Creates file streams for service output persisted below `./logs`.
|