@promptbook/cli 0.112.0-111 → 0.112.0-112
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/src/app/admin/servers/CreateServerDialog.tsx +16 -0
- package/apps/agents-server/src/app/admin/servers/useCreateServerWizard.ts +31 -5
- package/apps/agents-server/src/app/api/admin/servers/route.ts +5 -0
- package/apps/agents-server/src/app/api/metadata/route.ts +4 -0
- package/apps/agents-server/src/database/customJavascript.ts +62 -1
- package/apps/agents-server/src/database/customStylesheet.ts +60 -1
- package/apps/agents-server/src/database/getMetadata.ts +84 -3
- package/apps/agents-server/src/instrumentation.ts +3 -0
- package/apps/agents-server/src/utils/errorReporting/registerServerErrorSentryLogging.ts +331 -0
- package/apps/agents-server/src/utils/errorReporting/sendApplicationErrorReportToSentry.ts +8 -153
- package/apps/agents-server/src/utils/errorReporting/sentryStore.ts +177 -0
- package/apps/agents-server/src/utils/serverManagement/createManagedServer/bootstrapManagedServer.ts +3 -1
- package/apps/agents-server/src/utils/serverManagement/createManagedServer/normalizeCreateServerInput.ts +6 -0
- package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerDefaultAgents.ts +7 -3
- package/apps/agents-server/src/utils/serverManagement/createManagedServer.ts +5 -0
- package/apps/agents-server/src/utils/userChat/listUserChats.ts +109 -0
- package/esm/index.es.js +23 -4
- package/esm/index.es.js.map +1 -1
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +2 -1
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer.test.d.ts +1 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/cli/cli-commands/agents-server/startAgentsServer.ts +17 -1
- package/src/other/templates/getTemplatesPipelineCollection.ts +724 -878
- package/src/version.ts +2 -2
- package/src/versions.txt +1 -0
- package/umd/index.umd.js +23 -4
- package/umd/index.umd.js.map +1 -1
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +2 -1
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer.test.d.ts +1 -0
- package/umd/src/version.d.ts +1 -1
|
@@ -51,6 +51,11 @@ export type NormalizedCreateServerInput = {
|
|
|
51
51
|
* Initial metadata rows inserted during bootstrap.
|
|
52
52
|
*/
|
|
53
53
|
readonly metadataEntries: ReadonlyArray<ServerMetadataSeedEntry>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Whether bundled default agents from `agents/default` should be created during bootstrap.
|
|
57
|
+
*/
|
|
58
|
+
readonly isDefaultAgentsInstalled: boolean;
|
|
54
59
|
};
|
|
55
60
|
|
|
56
61
|
/**
|
|
@@ -103,5 +108,6 @@ export function normalizeCreateServerInput(input: CreateServerInput): Normalized
|
|
|
103
108
|
iconUrl,
|
|
104
109
|
initialSettings: input.initialSettings,
|
|
105
110
|
}),
|
|
111
|
+
isDefaultAgentsInstalled: input.isDefaultAgentsInstalled !== false,
|
|
106
112
|
};
|
|
107
113
|
}
|
package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerDefaultAgents.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createAgentPersistenceRecords } from '../../../../../../src/collection/agent-collection/constructors/agent-collection-in-supabase/createAgentPersistenceRecords';
|
|
2
2
|
import type { Client } from 'pg';
|
|
3
|
+
import { DEFAULT_AGENT_VISIBILITY } from '../../agentVisibility';
|
|
3
4
|
import { loadDefaultAgentBooks } from '../../defaultAgents/loadDefaultAgentBooks';
|
|
4
5
|
import { createInsertStatement, quoteIdentifier, type SqlRecorder } from './createSqlRecorder';
|
|
5
6
|
import type { NormalizedCreateServerInput } from './normalizeCreateServerInput';
|
|
@@ -28,7 +29,7 @@ export async function seedServerDefaultAgents(
|
|
|
28
29
|
const createdAt = new Date().toISOString();
|
|
29
30
|
const { agentInsertRecord, agentHistoryInsertRecord } = createAgentPersistenceRecords(
|
|
30
31
|
defaultAgentBook,
|
|
31
|
-
{ sortOrder: index },
|
|
32
|
+
{ sortOrder: index, visibility: DEFAULT_AGENT_VISIBILITY },
|
|
32
33
|
createdAt,
|
|
33
34
|
);
|
|
34
35
|
|
|
@@ -45,9 +46,10 @@ export async function seedServerDefaultAgents(
|
|
|
45
46
|
"promptbookEngineVersion",
|
|
46
47
|
"usage",
|
|
47
48
|
"folderId",
|
|
48
|
-
"sortOrder"
|
|
49
|
+
"sortOrder",
|
|
50
|
+
"visibility"
|
|
49
51
|
)
|
|
50
|
-
VALUES ($1, $2, $3, $4, $5, $6, $7::jsonb, $8, $9::jsonb, $10, $11)
|
|
52
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7::jsonb, $8, $9::jsonb, $10, $11, $12)
|
|
51
53
|
`,
|
|
52
54
|
[
|
|
53
55
|
agentInsertRecord.agentName,
|
|
@@ -61,6 +63,7 @@ export async function seedServerDefaultAgents(
|
|
|
61
63
|
JSON.stringify(agentInsertRecord.usage),
|
|
62
64
|
agentInsertRecord.folderId ?? null,
|
|
63
65
|
agentInsertRecord.sortOrder ?? index,
|
|
66
|
+
agentInsertRecord.visibility ?? DEFAULT_AGENT_VISIBILITY,
|
|
64
67
|
],
|
|
65
68
|
);
|
|
66
69
|
sqlRecorder.addStatement(
|
|
@@ -70,6 +73,7 @@ export async function seedServerDefaultAgents(
|
|
|
70
73
|
usage: JSON.stringify(agentInsertRecord.usage),
|
|
71
74
|
folderId: agentInsertRecord.folderId ?? null,
|
|
72
75
|
sortOrder: agentInsertRecord.sortOrder ?? index,
|
|
76
|
+
visibility: agentInsertRecord.visibility ?? DEFAULT_AGENT_VISIBILITY,
|
|
73
77
|
}),
|
|
74
78
|
);
|
|
75
79
|
|
|
@@ -108,6 +108,11 @@ export type CreateServerInput = {
|
|
|
108
108
|
*/
|
|
109
109
|
readonly additionalUsers?: ReadonlyArray<ServerSeedUserInput>;
|
|
110
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Whether bundled default agents from `agents/default` should be created during bootstrap.
|
|
113
|
+
*/
|
|
114
|
+
readonly isDefaultAgentsInstalled?: boolean;
|
|
115
|
+
|
|
111
116
|
/**
|
|
112
117
|
* Initial metadata values for the new server.
|
|
113
118
|
*/
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { $getTableName } from '@/src/database/$getTableName';
|
|
2
2
|
import { $provideClientSql } from '@/src/database/$provideClientSql';
|
|
3
|
+
import { isAgentsServerSqliteMode } from '@/src/database/agentsServerDatabaseMode';
|
|
4
|
+
import { $provideAgentsServerSqliteDatabase } from '@/src/database/sqlite/$provideAgentsServerSqliteDatabase';
|
|
3
5
|
import type { ListUserChatsOptions, UserChatRecord } from './UserChatRecord';
|
|
4
6
|
import type { UserChatSource } from './UserChatSource';
|
|
5
7
|
import type { UserChatRow } from './UserChatRow';
|
|
@@ -30,6 +32,13 @@ const POSTGRES_UNDEFINED_COLUMN_ERROR_CODE = '42703';
|
|
|
30
32
|
const CLIENT_SQL_MISSING_CONNECTION_MESSAGE_FRAGMENT =
|
|
31
33
|
'Environment variable `POSTGRES_URL` or `DATABASE_URL` must be defined.';
|
|
32
34
|
|
|
35
|
+
/**
|
|
36
|
+
* SQLite expression that safely exposes chat messages as a JSON array.
|
|
37
|
+
*
|
|
38
|
+
* @private function of `userChat`
|
|
39
|
+
*/
|
|
40
|
+
const SQLITE_CHAT_MESSAGES_JSON_EXPRESSION = `CASE WHEN json_valid(chat."messages") THEN chat."messages" ELSE '[]' END`;
|
|
41
|
+
|
|
33
42
|
/**
|
|
34
43
|
* Lists all user chats for one agent ordered by last activity.
|
|
35
44
|
*/
|
|
@@ -69,6 +78,10 @@ export async function listUserChats(options: ListUserChatsOptions): Promise<Arra
|
|
|
69
78
|
* @private function of `userChat`
|
|
70
79
|
*/
|
|
71
80
|
export async function listUserChatSummarySeeds(options: ListUserChatsOptions): Promise<Array<UserChatSummarySeed>> {
|
|
81
|
+
if (isAgentsServerSqliteMode()) {
|
|
82
|
+
return listUserChatSummarySeedsViaSqlite(options);
|
|
83
|
+
}
|
|
84
|
+
|
|
72
85
|
if (!isDirectSqlConnectionConfigured()) {
|
|
73
86
|
return listUserChatSummarySeedsViaSupabase(options);
|
|
74
87
|
}
|
|
@@ -151,6 +164,92 @@ export async function listUserChatSummarySeeds(options: ListUserChatsOptions): P
|
|
|
151
164
|
}
|
|
152
165
|
}
|
|
153
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Lists lightweight chat-summary seeds through direct SQLite JSON queries.
|
|
169
|
+
*
|
|
170
|
+
* @private function of `userChat`
|
|
171
|
+
*/
|
|
172
|
+
async function listUserChatSummarySeedsViaSqlite(options: ListUserChatsOptions): Promise<Array<UserChatSummarySeed>> {
|
|
173
|
+
const userChatTableName = quoteIdentifier(await $getTableName('UserChat'));
|
|
174
|
+
const shouldLoadExternalChats = options.viewerIsAdmin && options.includeExternalChats;
|
|
175
|
+
const whereClause = shouldLoadExternalChats
|
|
176
|
+
? `
|
|
177
|
+
chat."agentPermanentId" = ?
|
|
178
|
+
AND (chat."source" <> ? OR chat."userId" = ?)
|
|
179
|
+
`
|
|
180
|
+
: `
|
|
181
|
+
chat."userId" = ?
|
|
182
|
+
AND chat."agentPermanentId" = ?
|
|
183
|
+
AND chat."source" = ?
|
|
184
|
+
`;
|
|
185
|
+
const queryValues = shouldLoadExternalChats
|
|
186
|
+
? [options.agentPermanentId, USER_CHAT_SOURCES.WEB_UI, options.userId]
|
|
187
|
+
: [options.userId, options.agentPermanentId, USER_CHAT_SOURCES.WEB_UI];
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
const database = $provideAgentsServerSqliteDatabase();
|
|
191
|
+
const summaryRows = database
|
|
192
|
+
.prepare(
|
|
193
|
+
`
|
|
194
|
+
SELECT
|
|
195
|
+
chat."id",
|
|
196
|
+
chat."createdAt",
|
|
197
|
+
chat."updatedAt",
|
|
198
|
+
chat."lastMessageAt",
|
|
199
|
+
chat."title",
|
|
200
|
+
chat."source",
|
|
201
|
+
COALESCE(json_array_length(${SQLITE_CHAT_MESSAGES_JSON_EXPRESSION}), 0) AS "messagesCount",
|
|
202
|
+
COALESCE(
|
|
203
|
+
(
|
|
204
|
+
SELECT CAST(json_extract(message.value, '$.content') AS TEXT)
|
|
205
|
+
FROM json_each(${SQLITE_CHAT_MESSAGES_JSON_EXPRESSION}) AS message
|
|
206
|
+
WHERE UPPER(CAST(COALESCE(json_extract(message.value, '$.sender'), '') AS TEXT)) = 'USER'
|
|
207
|
+
ORDER BY CAST(message.key AS INTEGER) ASC
|
|
208
|
+
LIMIT 1
|
|
209
|
+
),
|
|
210
|
+
''
|
|
211
|
+
) AS "firstUserMessageContent",
|
|
212
|
+
COALESCE(
|
|
213
|
+
(
|
|
214
|
+
SELECT CAST(json_extract(message.value, '$.content') AS TEXT)
|
|
215
|
+
FROM json_each(${SQLITE_CHAT_MESSAGES_JSON_EXPRESSION}) AS message
|
|
216
|
+
WHERE LENGTH(TRIM(CAST(COALESCE(json_extract(message.value, '$.content'), '') AS TEXT))) > 0
|
|
217
|
+
ORDER BY CAST(message.key AS INTEGER) DESC
|
|
218
|
+
LIMIT 1
|
|
219
|
+
),
|
|
220
|
+
''
|
|
221
|
+
) AS "lastPreviewMessageContent",
|
|
222
|
+
COALESCE(
|
|
223
|
+
(
|
|
224
|
+
SELECT COUNT(*)
|
|
225
|
+
FROM json_each(${SQLITE_CHAT_MESSAGES_JSON_EXPRESSION}) AS message
|
|
226
|
+
WHERE
|
|
227
|
+
UPPER(CAST(COALESCE(json_extract(message.value, '$.sender'), '') AS TEXT)) IN ('AGENT', 'MODEL')
|
|
228
|
+
AND (
|
|
229
|
+
json_extract(message.value, '$.isComplete') = 0
|
|
230
|
+
OR LOWER(CAST(COALESCE(json_extract(message.value, '$.isComplete'), '') AS TEXT)) = 'false'
|
|
231
|
+
OR LOWER(CAST(COALESCE(json_extract(message.value, '$.lifecycleState'), '') AS TEXT)) IN ('queued', 'running')
|
|
232
|
+
)
|
|
233
|
+
),
|
|
234
|
+
0
|
|
235
|
+
) AS "pendingAssistantMessageCount"
|
|
236
|
+
FROM ${userChatTableName} AS chat
|
|
237
|
+
WHERE ${whereClause}
|
|
238
|
+
ORDER BY chat."lastMessageAt" IS NULL ASC, chat."lastMessageAt" DESC, chat."updatedAt" DESC
|
|
239
|
+
`,
|
|
240
|
+
)
|
|
241
|
+
.all(...queryValues) as Array<UserChatSummarySeedSqlRow>;
|
|
242
|
+
|
|
243
|
+
return summaryRows.map(mapUserChatSummarySeedSqlRow);
|
|
244
|
+
} catch (error) {
|
|
245
|
+
if (!isUserChatSummarySeedSqliteFallbackError(error)) {
|
|
246
|
+
throw error;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return listUserChatSummarySeedsViaSupabase(options);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
154
253
|
/**
|
|
155
254
|
* Raw SQL row shape loaded for lightweight chat summary seeds.
|
|
156
255
|
*
|
|
@@ -260,6 +359,16 @@ function isUserChatSummarySeedSqlFallbackError(error: unknown): boolean {
|
|
|
260
359
|
return /relation .* does not exist|column .* does not exist/i.test(errorMessage);
|
|
261
360
|
}
|
|
262
361
|
|
|
362
|
+
/**
|
|
363
|
+
* Returns true when SQLite summary optimization should gracefully fallback to Supabase-shaped reads.
|
|
364
|
+
*
|
|
365
|
+
* @private function of `userChat`
|
|
366
|
+
*/
|
|
367
|
+
function isUserChatSummarySeedSqliteFallbackError(error: unknown): boolean {
|
|
368
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
369
|
+
return /no such table|no such column|no such function: json_|malformed JSON/i.test(errorMessage);
|
|
370
|
+
}
|
|
371
|
+
|
|
263
372
|
/**
|
|
264
373
|
* Loads chat-summary seeds using standard Supabase reads when SQL optimization is unavailable.
|
|
265
374
|
*
|
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-
|
|
61
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-112';
|
|
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
|
|
@@ -34202,7 +34202,11 @@ function buildCodexScript(options) {
|
|
|
34202
34202
|
const projectPath = toPosixPath(options.projectPath);
|
|
34203
34203
|
const loginMethodConfig = spaceTrim(`
|
|
34204
34204
|
${options.allowCredits ? 'CODEX_LOGIN_METHOD_ARGUMENTS=()' : 'CODEX_LOGIN_METHOD_ARGUMENTS=(-c forced_login_method=chatgpt)'}
|
|
34205
|
-
|
|
34205
|
+
CODEX_USE_API_KEY="\${PTBK_OPENAI_CODEX_USE_API_KEY:-}"
|
|
34206
|
+
if [ -z "\$CODEX_USE_API_KEY" ] && [ -n "\${OPENAI_API_KEY:-}" ]; then
|
|
34207
|
+
CODEX_USE_API_KEY=1
|
|
34208
|
+
fi
|
|
34209
|
+
if [ "\$CODEX_USE_API_KEY" = "1" ] && [ -n "\${OPENAI_API_KEY:-}" ]; then
|
|
34206
34210
|
CODEX_LOGIN_METHOD_ARGUMENTS=(-c forced_login_method=api)
|
|
34207
34211
|
fi
|
|
34208
34212
|
`);
|
|
@@ -34220,7 +34224,7 @@ function buildCodexScript(options) {
|
|
|
34220
34224
|
'',
|
|
34221
34225
|
loginMethodConfig,
|
|
34222
34226
|
'',
|
|
34223
|
-
'if [ "${
|
|
34227
|
+
'if [ "${CODEX_USE_API_KEY:-0}" != "1" ] || [ -z "${OPENAI_API_KEY:-}" ]; then',
|
|
34224
34228
|
'unset OPENAI_API_KEY',
|
|
34225
34229
|
'unset OPENAI_BASE_URL',
|
|
34226
34230
|
'fi',
|
|
@@ -37274,6 +37278,12 @@ const PTBK_AGENTS_SERVER_SQLITE_PATH_ENV = 'PTBK_AGENTS_SERVER_SQLITE_PATH';
|
|
|
37274
37278
|
* @private internal constant of `ptbk agents-server`
|
|
37275
37279
|
*/
|
|
37276
37280
|
const PTBK_HOSTNAME_ENV = 'PTBK_HOSTNAME';
|
|
37281
|
+
/**
|
|
37282
|
+
* Explicit installed `.env` file passed by standalone VPS pm2/runtime launchers.
|
|
37283
|
+
*
|
|
37284
|
+
* @private internal constant of `ptbk agents-server`
|
|
37285
|
+
*/
|
|
37286
|
+
const PTBK_AGENTS_SERVER_ENV_FILE_ENV = 'PTBK_AGENTS_SERVER_ENV_FILE';
|
|
37277
37287
|
/**
|
|
37278
37288
|
* Entropy size for the local-only token shared by the CLI pump and the Next app.
|
|
37279
37289
|
*
|
|
@@ -37399,11 +37409,20 @@ async function prepareAgentsServerDevelopmentRuntime(appPath, runnerLogStream) {
|
|
|
37399
37409
|
});
|
|
37400
37410
|
}
|
|
37401
37411
|
/**
|
|
37402
|
-
* Loads
|
|
37412
|
+
* Loads Agents Server runtime environment from the installed `.env` file when explicitly configured and falls back
|
|
37413
|
+
* to the launch-directory `.env`.
|
|
37403
37414
|
*
|
|
37404
37415
|
* @private internal utility of `ptbk agents-server`
|
|
37405
37416
|
*/
|
|
37406
37417
|
function loadAgentsServerProjectEnvironment(launchWorkingDirectory) {
|
|
37418
|
+
var _a;
|
|
37419
|
+
const explicitEnvFilePath = (_a = process.env[PTBK_AGENTS_SERVER_ENV_FILE_ENV]) === null || _a === void 0 ? void 0 : _a.trim();
|
|
37420
|
+
if (explicitEnvFilePath) {
|
|
37421
|
+
const explicitLoadResult = dotenv.config({ path: explicitEnvFilePath, override: true });
|
|
37422
|
+
if (!explicitLoadResult.error) {
|
|
37423
|
+
return;
|
|
37424
|
+
}
|
|
37425
|
+
}
|
|
37407
37426
|
dotenv.config({ path: join(launchWorkingDirectory, AGENTS_SERVER_PROJECT_ENV_FILE_NAME) });
|
|
37408
37427
|
}
|
|
37409
37428
|
/**
|