@promptbook/cli 0.112.0-110 → 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.
Files changed (44) hide show
  1. package/apps/agents-server/src/app/admin/servers/CreateServerDialog.tsx +16 -0
  2. package/apps/agents-server/src/app/admin/servers/useCreateServerWizard.ts +31 -5
  3. package/apps/agents-server/src/app/agents/[agentName]/_utils.ts +7 -5
  4. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/stream/route.ts +4 -86
  5. package/apps/agents-server/src/app/api/admin/servers/route.ts +5 -0
  6. package/apps/agents-server/src/app/api/metadata/route.ts +4 -0
  7. package/apps/agents-server/src/components/ApplicationErrorPage/ApplicationErrorPage.tsx +118 -12
  8. package/apps/agents-server/src/database/customJavascript.ts +62 -1
  9. package/apps/agents-server/src/database/customStylesheet.ts +60 -1
  10. package/apps/agents-server/src/database/getMetadata.ts +84 -3
  11. package/apps/agents-server/src/instrumentation.ts +3 -0
  12. package/apps/agents-server/src/utils/agentRouting/resolveAgentRouteTarget.ts +27 -62
  13. package/apps/agents-server/src/utils/errorReporting/applicationErrorHandling.ts +45 -0
  14. package/apps/agents-server/src/utils/errorReporting/refreshApplicationDocument.ts +10 -0
  15. package/apps/agents-server/src/utils/errorReporting/registerServerErrorSentryLogging.ts +331 -0
  16. package/apps/agents-server/src/utils/errorReporting/sendApplicationErrorReportToSentry.ts +8 -153
  17. package/apps/agents-server/src/utils/errorReporting/sentryStore.ts +177 -0
  18. package/apps/agents-server/src/utils/importAgent.ts +1 -57
  19. package/apps/agents-server/src/utils/importAgentWithFallback.ts +0 -10
  20. package/apps/agents-server/src/utils/serverManagement/createManagedServer/bootstrapManagedServer.ts +3 -1
  21. package/apps/agents-server/src/utils/serverManagement/createManagedServer/normalizeCreateServerInput.ts +6 -0
  22. package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerDefaultAgents.ts +7 -3
  23. package/apps/agents-server/src/utils/serverManagement/createManagedServer.ts +5 -0
  24. package/apps/agents-server/src/utils/userChat/listUserChats.ts +109 -0
  25. package/apps/agents-server/src/utils/userChat.ts +0 -1
  26. package/esm/index.es.js +39 -13
  27. package/esm/index.es.js.map +1 -1
  28. package/esm/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +2 -1
  29. package/esm/src/cli/cli-commands/agents-server/startAgentsServer.test.d.ts +1 -0
  30. package/esm/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +22 -0
  31. package/esm/src/version.d.ts +1 -1
  32. package/package.json +1 -1
  33. package/src/cli/cli-commands/agents-server/startAgentsServer.ts +23 -2
  34. package/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.ts +91 -14
  35. package/src/other/templates/getTemplatesPipelineCollection.ts +801 -652
  36. package/src/version.ts +2 -2
  37. package/src/versions.txt +2 -0
  38. package/umd/index.umd.js +39 -13
  39. package/umd/index.umd.js.map +1 -1
  40. package/umd/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +2 -1
  41. package/umd/src/cli/cli-commands/agents-server/startAgentsServer.test.d.ts +1 -0
  42. package/umd/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +22 -0
  43. package/umd/src/version.d.ts +1 -1
  44. package/apps/agents-server/src/utils/userChat/getUserChatRevision.ts +0 -145
@@ -29,7 +29,8 @@ export type StartAgentsServerOptions = {
29
29
  */
30
30
  export declare function startAgentsServer(options: StartAgentsServerOptions): Promise<void>;
31
31
  /**
32
- * Loads launch-directory `.env` values without overriding explicit process environment.
32
+ * Loads Agents Server runtime environment from the installed `.env` file when explicitly configured and falls back
33
+ * to the launch-directory `.env`.
33
34
  *
34
35
  * @private internal utility of `ptbk agents-server`
35
36
  */
@@ -60,6 +60,28 @@ export declare class AgentCollectionInSupabase {
60
60
  * Gets all agents in the collection
61
61
  */
62
62
  listAgents(): Promise<ReadonlyArray<AgentBasicInformation>>;
63
+ /**
64
+ * Finds one active agent profile by its human-readable name or permanent id.
65
+ *
66
+ * This keeps route-level lookups from loading the whole agent collection when only
67
+ * one canonical route identifier is needed.
68
+ *
69
+ * @param agentNameOrPermanentId - Agent name or stable permanent identifier.
70
+ * @returns Matching active agent profile or `null` when not found.
71
+ *
72
+ * @public exported from `@promptbook/core`
73
+ */
74
+ findAgentBasicInformation(agentNameOrPermanentId: string_agent_name | string_agent_permanent_id): Promise<AgentBasicInformation | null>;
75
+ /**
76
+ * Converts one database row into public agent information.
77
+ *
78
+ * @param row - Database row carrying the persisted profile snapshot.
79
+ * @param isVerbose - Whether profile-name mismatches should be logged.
80
+ * @returns Agent profile with canonical database name and permanent id.
81
+ *
82
+ * @private internal helper of `AgentCollectionInSupabase`
83
+ */
84
+ private mapAgentBasicInformationRow;
63
85
  /**
64
86
  * Retrieves the permanent ID of an agent by its name or permanent ID.
65
87
  */
@@ -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-109`).
18
+ * It follows semantic versioning (e.g., `0.112.0-111`).
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-110",
3
+ "version": "0.112.0-112",
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,
@@ -107,6 +107,13 @@ const PTBK_AGENTS_SERVER_SQLITE_PATH_ENV = 'PTBK_AGENTS_SERVER_SQLITE_PATH';
107
107
  */
108
108
  const PTBK_HOSTNAME_ENV = 'PTBK_HOSTNAME';
109
109
 
110
+ /**
111
+ * Explicit installed `.env` file passed by standalone VPS pm2/runtime launchers.
112
+ *
113
+ * @private internal constant of `ptbk agents-server`
114
+ */
115
+ const PTBK_AGENTS_SERVER_ENV_FILE_ENV = 'PTBK_AGENTS_SERVER_ENV_FILE';
116
+
110
117
  /**
111
118
  * Entropy size for the local-only token shared by the CLI pump and the Next app.
112
119
  *
@@ -355,11 +362,20 @@ async function prepareAgentsServerDevelopmentRuntime(
355
362
  }
356
363
 
357
364
  /**
358
- * Loads launch-directory `.env` values without overriding explicit process environment.
365
+ * Loads Agents Server runtime environment from the installed `.env` file when explicitly configured and falls back
366
+ * to the launch-directory `.env`.
359
367
  *
360
368
  * @private internal utility of `ptbk agents-server`
361
369
  */
362
370
  export function loadAgentsServerProjectEnvironment(launchWorkingDirectory: string): void {
371
+ const explicitEnvFilePath = process.env[PTBK_AGENTS_SERVER_ENV_FILE_ENV]?.trim();
372
+ if (explicitEnvFilePath) {
373
+ const explicitLoadResult = dotenv.config({ path: explicitEnvFilePath, override: true });
374
+ if (!explicitLoadResult.error) {
375
+ return;
376
+ }
377
+ }
378
+
363
379
  dotenv.config({ path: join(launchWorkingDirectory, AGENTS_SERVER_PROJECT_ENV_FILE_NAME) });
364
380
  }
365
381
 
@@ -398,7 +414,12 @@ function startNextServer(options: {
398
414
  options.logStreams.runner,
399
415
  `Starting the Agents Server Next process in ${nextRuntimeModeLabel} mode.`,
400
416
  );
401
- const nextArguments = [options.nextCliPath, options.options.nextRuntimeMode, '--port', String(options.options.port)];
417
+ const nextArguments = [
418
+ options.nextCliPath,
419
+ options.options.nextRuntimeMode,
420
+ '--port',
421
+ String(options.options.port),
422
+ ];
402
423
  const hostname = options.childEnvironment[PTBK_HOSTNAME_ENV]?.trim();
403
424
 
404
425
  if (hostname) {
@@ -49,6 +49,19 @@ function normalizeHistoryVersionName(versionName: string | null | undefined): st
49
49
  return normalizedVersionName.length > 0 ? normalizedVersionName : null;
50
50
  }
51
51
 
52
+ /**
53
+ * Builds a Supabase `.or()` filter for agent name or permanent id lookups.
54
+ *
55
+ * @param agentNameOrPermanentId - Agent name or stable permanent identifier to match.
56
+ * @returns `.or()` filter string safe to pass to Supabase.
57
+ *
58
+ * @private internal helper of `AgentCollectionInSupabase`
59
+ */
60
+ function buildAgentNameOrPermanentIdFilter(agentNameOrPermanentId: string): string {
61
+ const encodedAgentIdentifier = encodeURIComponent(agentNameOrPermanentId);
62
+ return `agentName.eq.${encodedAgentIdentifier},permanentId.eq.${encodedAgentIdentifier}`;
63
+ }
64
+
52
65
  /**
53
66
  * One saved Agent history row without the full source payload.
54
67
  */
@@ -69,6 +82,16 @@ type AgentHistorySnapshot = AgentHistoryMetadata & {
69
82
  readonly agentSource: string;
70
83
  };
71
84
 
85
+ /**
86
+ * Minimal database row used to build public agent information.
87
+ *
88
+ * @private internal type of `AgentCollectionInSupabase`
89
+ */
90
+ type AgentBasicInformationRow = Pick<
91
+ AgentsDatabaseSchema['public']['Tables']['Agent']['Row'],
92
+ 'agentName' | 'agentProfile' | 'permanentId'
93
+ >;
94
+
72
95
  /**
73
96
  * Agent collection stored in a Supabase table.
74
97
  *
@@ -127,24 +150,78 @@ export class AgentCollectionInSupabase /* TODO: [🌈][🐱‍🚀] implements A
127
150
  console.info(`Found ${selectResult.data.length} agents in directory`);
128
151
  }
129
152
 
130
- return selectResult.data.map(({ agentName, agentProfile, permanentId }) => {
131
- if (isVerbose && (agentProfile as AgentBasicInformation).agentName !== agentName) {
132
- console.warn(
133
- spaceTrim(`
153
+ return selectResult.data.map((row) => this.mapAgentBasicInformationRow(row, isVerbose));
154
+ }
155
+
156
+ /**
157
+ * Finds one active agent profile by its human-readable name or permanent id.
158
+ *
159
+ * This keeps route-level lookups from loading the whole agent collection when only
160
+ * one canonical route identifier is needed.
161
+ *
162
+ * @param agentNameOrPermanentId - Agent name or stable permanent identifier.
163
+ * @returns Matching active agent profile or `null` when not found.
164
+ *
165
+ * @public exported from `@promptbook/core`
166
+ */
167
+ public async findAgentBasicInformation(
168
+ agentNameOrPermanentId: string_agent_name | string_agent_permanent_id,
169
+ ): Promise<AgentBasicInformation | null> {
170
+ const { isVerbose = DEFAULT_IS_VERBOSE } = this.options || {};
171
+ const selectResult = await this.supabaseClient
172
+ .from(this.getTableName('Agent'))
173
+ .select('agentName,agentProfile,permanentId')
174
+ .or(buildAgentNameOrPermanentIdFilter(agentNameOrPermanentId))
175
+ .is('deletedAt', null)
176
+ .order('createdAt', { ascending: true })
177
+ .limit(1);
178
+
179
+ if (selectResult.error) {
180
+ throw new DatabaseError(
181
+ spaceTrim(
182
+ (block) => `
183
+
184
+ Error fetching agent "${agentNameOrPermanentId}" from Supabase:
185
+
186
+ ${block(selectResult.error.message)}
187
+ `,
188
+ ),
189
+ );
190
+ }
191
+
192
+ const row = selectResult.data?.[0];
193
+ return row ? this.mapAgentBasicInformationRow(row, isVerbose) : null;
194
+ }
195
+
196
+ /**
197
+ * Converts one database row into public agent information.
198
+ *
199
+ * @param row - Database row carrying the persisted profile snapshot.
200
+ * @param isVerbose - Whether profile-name mismatches should be logged.
201
+ * @returns Agent profile with canonical database name and permanent id.
202
+ *
203
+ * @private internal helper of `AgentCollectionInSupabase`
204
+ */
205
+ private mapAgentBasicInformationRow(
206
+ { agentName, agentProfile, permanentId }: AgentBasicInformationRow,
207
+ isVerbose: boolean,
208
+ ): AgentBasicInformation {
209
+ if (isVerbose && (agentProfile as AgentBasicInformation).agentName !== agentName) {
210
+ console.warn(
211
+ spaceTrim(`
134
212
  Agent name mismatch for agent "${agentName}". Using name from database.
135
213
 
136
214
  agentName: "${agentName}"
137
215
  agentProfile.agentName: "${(agentProfile as AgentBasicInformation).agentName}"
138
216
  `),
139
- );
140
- }
217
+ );
218
+ }
141
219
 
142
- return {
143
- ...(agentProfile as AgentBasicInformation),
144
- agentName,
145
- permanentId: permanentId || (agentProfile as AgentBasicInformation).permanentId,
146
- };
147
- });
220
+ return {
221
+ ...(agentProfile as AgentBasicInformation),
222
+ agentName,
223
+ permanentId: permanentId || (agentProfile as AgentBasicInformation).permanentId,
224
+ };
148
225
  }
149
226
 
150
227
  /**
@@ -156,7 +233,7 @@ export class AgentCollectionInSupabase /* TODO: [🌈][🐱‍🚀] implements A
156
233
  const selectResult = await this.supabaseClient
157
234
  .from(this.getTableName('Agent'))
158
235
  .select('permanentId')
159
- .or(`agentName.eq.${agentNameOrPermanentId},permanentId.eq.${agentNameOrPermanentId}`)
236
+ .or(buildAgentNameOrPermanentIdFilter(agentNameOrPermanentId))
160
237
  .order('createdAt', { ascending: true }) // Pick oldest if multiple match by name
161
238
  .limit(1);
162
239
 
@@ -175,7 +252,7 @@ export class AgentCollectionInSupabase /* TODO: [🌈][🐱‍🚀] implements A
175
252
  const selectResult = await this.supabaseClient
176
253
  .from(this.getTableName('Agent'))
177
254
  .select('agentSource')
178
- .or(`agentName.eq.${agentNameOrPermanentId},permanentId.eq.${agentNameOrPermanentId}`)
255
+ .or(buildAgentNameOrPermanentIdFilter(agentNameOrPermanentId))
179
256
  .is('deletedAt', null)
180
257
  .order('createdAt', { ascending: true }) // Pick oldest if multiple match by name
181
258
  .limit(1);