@promptbook/cli 0.104.0-2 → 0.104.0-4

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 (66) hide show
  1. package/apps/agents-server/package.json +3 -4
  2. package/apps/agents-server/public/swagger.json +115 -0
  3. package/apps/agents-server/scripts/generate-reserved-paths/generate-reserved-paths.ts +11 -7
  4. package/apps/agents-server/src/app/AddAgentButton.tsx +1 -2
  5. package/apps/agents-server/src/app/admin/chat-feedback/ChatFeedbackClient.tsx +221 -274
  6. package/apps/agents-server/src/app/admin/chat-history/ChatHistoryClient.tsx +94 -137
  7. package/apps/agents-server/src/app/admin/metadata/MetadataClient.tsx +8 -8
  8. package/apps/agents-server/src/app/agents/[agentName]/AgentChatWrapper.tsx +15 -1
  9. package/apps/agents-server/src/app/agents/[agentName]/AgentOptionsMenu.tsx +1 -3
  10. package/apps/agents-server/src/app/agents/[agentName]/AgentProfileChat.tsx +29 -16
  11. package/apps/agents-server/src/app/agents/[agentName]/api/chat/route.ts +3 -0
  12. package/apps/agents-server/src/app/agents/[agentName]/api/mcp/route.ts +6 -11
  13. package/apps/agents-server/src/app/agents/[agentName]/api/voice/route.ts +4 -1
  14. package/apps/agents-server/src/app/agents/[agentName]/code/api/route.ts +8 -6
  15. package/apps/agents-server/src/app/agents/[agentName]/code/page.tsx +33 -30
  16. package/apps/agents-server/src/app/api/agents/[agentName]/clone/route.ts +10 -12
  17. package/apps/agents-server/src/app/api/agents/[agentName]/route.ts +1 -2
  18. package/apps/agents-server/src/app/api/agents/route.ts +1 -1
  19. package/apps/agents-server/src/app/api/api-tokens/route.ts +6 -7
  20. package/apps/agents-server/src/app/api/docs/book.md/route.ts +3 -0
  21. package/apps/agents-server/src/app/api/metadata/route.ts +5 -6
  22. package/apps/agents-server/src/app/api/upload/route.ts +9 -0
  23. package/apps/agents-server/src/app/page.tsx +1 -1
  24. package/apps/agents-server/src/app/swagger/page.tsx +14 -0
  25. package/apps/agents-server/src/components/AgentProfile/AgentProfile.tsx +4 -2
  26. package/apps/agents-server/src/components/AgentProfile/QrCodeModal.tsx +0 -1
  27. package/apps/agents-server/src/components/Auth/AuthControls.tsx +5 -4
  28. package/apps/agents-server/src/components/Header/Header.tsx +27 -5
  29. package/apps/agents-server/src/components/Homepage/AgentCard.tsx +22 -3
  30. package/apps/agents-server/src/components/_utils/headlessParam.tsx +7 -3
  31. package/apps/agents-server/src/database/migrate.ts +34 -1
  32. package/apps/agents-server/src/database/migrations/2025-12-0402-message-table.sql +42 -0
  33. package/apps/agents-server/src/generated/reservedPaths.ts +6 -1
  34. package/apps/agents-server/src/message-providers/email/_common/Email.ts +73 -0
  35. package/apps/agents-server/src/message-providers/email/_common/utils/TODO.txt +1 -0
  36. package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddress.test.ts.todo +108 -0
  37. package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddress.ts +62 -0
  38. package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddresses.test.ts.todo +117 -0
  39. package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddresses.ts +19 -0
  40. package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddress.test.ts.todo +119 -0
  41. package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddress.ts +19 -0
  42. package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddresses.test.ts.todo +74 -0
  43. package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddresses.ts +14 -0
  44. package/apps/agents-server/src/message-providers/email/sendgrid/SendgridMessageProvider.ts +44 -0
  45. package/apps/agents-server/src/message-providers/email/zeptomail/ZeptomailMessageProvider.ts +43 -0
  46. package/apps/agents-server/src/message-providers/index.ts +13 -0
  47. package/apps/agents-server/src/message-providers/interfaces/MessageProvider.ts +11 -0
  48. package/apps/agents-server/src/middleware.ts +12 -3
  49. package/apps/agents-server/src/utils/auth.ts +117 -17
  50. package/apps/agents-server/src/utils/getUserIdFromRequest.ts +3 -1
  51. package/apps/agents-server/src/utils/handleChatCompletion.ts +9 -5
  52. package/apps/agents-server/src/utils/messages/sendMessage.ts +91 -0
  53. package/apps/agents-server/src/utils/normalization/filenameToPrompt.test.ts +36 -0
  54. package/apps/agents-server/src/utils/normalization/filenameToPrompt.ts +6 -2
  55. package/apps/agents-server/src/utils/validateApiKey.ts +5 -10
  56. package/esm/index.es.js +86 -9
  57. package/esm/index.es.js.map +1 -1
  58. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  59. package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +7 -11
  60. package/esm/typings/src/llm-providers/_multiple/MultipleLlmExecutionTools.d.ts +6 -2
  61. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -0
  62. package/esm/typings/src/types/Message.d.ts +49 -0
  63. package/esm/typings/src/version.d.ts +1 -1
  64. package/package.json +1 -1
  65. package/umd/index.umd.js +86 -9
  66. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -47,7 +47,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
47
47
  * @generated
48
48
  * @see https://github.com/webgptorg/promptbook
49
49
  */
50
- const PROMPTBOOK_ENGINE_VERSION = '0.104.0-2';
50
+ const PROMPTBOOK_ENGINE_VERSION = '0.104.0-4';
51
51
  /**
52
52
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
53
53
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -3721,6 +3721,7 @@ class RemoteLlmExecutionTools {
3721
3721
  }
3722
3722
  }
3723
3723
  /**
3724
+ * TODO: !!!! Deprecate pipeline server and all of its components
3724
3725
  * TODO: Maybe use `$exportJson`
3725
3726
  * TODO: [🧠][🛍] Maybe not `isAnonymous: boolean` BUT `mode: 'ANONYMOUS'|'COLLECTION'`
3726
3727
  * TODO: [🍓] Allow to list compatible models with each variant
@@ -4249,6 +4250,9 @@ function cacheLlmTools(llmTools, options = {}) {
4249
4250
  case 'EMBEDDING':
4250
4251
  promptResult = await llmTools.callEmbeddingModel(prompt);
4251
4252
  break variant;
4253
+ case 'IMAGE_GENERATION':
4254
+ promptResult = await llmTools.callImageGenerationModel(prompt);
4255
+ break variant;
4252
4256
  // <- case [🤖]:
4253
4257
  default:
4254
4258
  throw new PipelineExecutionError(`Unknown model variant "${prompt.modelRequirements.modelVariant}"`);
@@ -4336,6 +4340,11 @@ function cacheLlmTools(llmTools, options = {}) {
4336
4340
  return /* not await */ callCommonModel(prompt);
4337
4341
  };
4338
4342
  }
4343
+ if (llmTools.callImageGenerationModel !== undefined) {
4344
+ proxyTools.callImageGenerationModel = async (prompt) => {
4345
+ return /* not await */ callCommonModel(prompt);
4346
+ };
4347
+ }
4339
4348
  // <- Note: [🤖]
4340
4349
  return proxyTools;
4341
4350
  }
@@ -4524,6 +4533,15 @@ function countUsage(llmTools) {
4524
4533
  return promptResult;
4525
4534
  };
4526
4535
  }
4536
+ if (llmTools.callImageGenerationModel !== undefined) {
4537
+ proxyTools.callImageGenerationModel = async (prompt) => {
4538
+ // console.info('[🚕] callImageGenerationModel through countTotalUsage');
4539
+ const promptResult = await llmTools.callImageGenerationModel(prompt);
4540
+ totalUsage = addUsage(totalUsage, promptResult.usage);
4541
+ spending.next(promptResult.usage);
4542
+ return promptResult;
4543
+ };
4544
+ }
4527
4545
  // <- Note: [🤖]
4528
4546
  return proxyTools;
4529
4547
  }
@@ -4646,6 +4664,12 @@ class MultipleLlmExecutionTools {
4646
4664
  callEmbeddingModel(prompt) {
4647
4665
  return this.callCommonModel(prompt);
4648
4666
  }
4667
+ /**
4668
+ * Calls the best available embedding model
4669
+ */
4670
+ callImageGenerationModel(prompt) {
4671
+ return this.callCommonModel(prompt);
4672
+ }
4649
4673
  // <- Note: [🤖]
4650
4674
  /**
4651
4675
  * Calls the best available model
@@ -4672,6 +4696,11 @@ class MultipleLlmExecutionTools {
4672
4696
  continue llm;
4673
4697
  }
4674
4698
  return await llmExecutionTools.callEmbeddingModel(prompt);
4699
+ case 'IMAGE_GENERATION':
4700
+ if (llmExecutionTools.callImageGenerationModel === undefined) {
4701
+ continue llm;
4702
+ }
4703
+ return await llmExecutionTools.callImageGenerationModel(prompt);
4675
4704
  // <- case [🤖]:
4676
4705
  default:
4677
4706
  throw new UnexpectedError(`Unknown model variant "${prompt.modelRequirements.modelVariant}" in ${llmExecutionTools.title}`);
@@ -7594,8 +7623,9 @@ async function executeAttempts(options) {
7594
7623
  $ongoingTaskResult.$resultString = $ongoingTaskResult.$completionResult.content;
7595
7624
  break variant;
7596
7625
  case 'EMBEDDING':
7626
+ case 'IMAGE_GENERATION':
7597
7627
  throw new PipelineExecutionError(spaceTrim$1((block) => `
7598
- Embedding model can not be used in pipeline
7628
+ ${modelRequirements.modelVariant} model can not be used in pipeline
7599
7629
 
7600
7630
  This should be catched during parsing
7601
7631
 
@@ -19448,7 +19478,7 @@ class OpenAiCompatibleExecutionTools {
19448
19478
  let threadMessages = [];
19449
19479
  if ('thread' in prompt && Array.isArray(prompt.thread)) {
19450
19480
  threadMessages = prompt.thread.map((msg) => ({
19451
- role: msg.role === 'assistant' ? 'assistant' : 'user',
19481
+ role: msg.sender === 'assistant' ? 'assistant' : 'user',
19452
19482
  content: msg.content,
19453
19483
  }));
19454
19484
  }
@@ -26114,17 +26144,64 @@ function parseAgentSourceWithCommitments(agentSource) {
26114
26144
  };
26115
26145
  }
26116
26146
  const lines = agentSource.split('\n');
26117
- const agentName = (((_a = lines[0]) === null || _a === void 0 ? void 0 : _a.trim()) || null);
26147
+ let agentName = null;
26148
+ let agentNameLineIndex = -1;
26149
+ // Find the agent name: first non-empty line that is not a commitment and not a horizontal line
26150
+ for (let i = 0; i < lines.length; i++) {
26151
+ const line = lines[i];
26152
+ if (line === undefined) {
26153
+ continue;
26154
+ }
26155
+ const trimmed = line.trim();
26156
+ if (!trimmed) {
26157
+ continue;
26158
+ }
26159
+ const isHorizontal = HORIZONTAL_LINE_PATTERN.test(line);
26160
+ if (isHorizontal) {
26161
+ continue;
26162
+ }
26163
+ let isCommitment = false;
26164
+ for (const definition of COMMITMENT_REGISTRY) {
26165
+ const typeRegex = definition.createTypeRegex();
26166
+ const match = typeRegex.exec(trimmed);
26167
+ if (match && ((_a = match.groups) === null || _a === void 0 ? void 0 : _a.type)) {
26168
+ isCommitment = true;
26169
+ break;
26170
+ }
26171
+ }
26172
+ if (!isCommitment) {
26173
+ agentName = trimmed;
26174
+ agentNameLineIndex = i;
26175
+ break;
26176
+ }
26177
+ }
26118
26178
  const commitments = [];
26119
26179
  const nonCommitmentLines = [];
26120
- // Always add the first line (agent name) to non-commitment lines
26121
- if (lines[0] !== undefined) {
26122
- nonCommitmentLines.push(lines[0]);
26180
+ // Add lines before agentName that are horizontal lines (they are non-commitment)
26181
+ for (let i = 0; i < agentNameLineIndex; i++) {
26182
+ const line = lines[i];
26183
+ if (line === undefined) {
26184
+ continue;
26185
+ }
26186
+ const trimmed = line.trim();
26187
+ if (!trimmed) {
26188
+ continue;
26189
+ }
26190
+ const isHorizontal = HORIZONTAL_LINE_PATTERN.test(line);
26191
+ if (isHorizontal) {
26192
+ nonCommitmentLines.push(line);
26193
+ }
26194
+ // Note: Commitments before agentName are not added to nonCommitmentLines
26195
+ }
26196
+ // Add the agent name line to non-commitment lines
26197
+ if (agentNameLineIndex >= 0) {
26198
+ nonCommitmentLines.push(lines[agentNameLineIndex]);
26123
26199
  }
26124
26200
  // Parse commitments with multiline support
26125
26201
  let currentCommitment = null;
26126
- // Process lines starting from the second line (skip agent name)
26127
- for (let i = 1; i < lines.length; i++) {
26202
+ // Process lines starting from after the agent name line
26203
+ const startIndex = agentNameLineIndex >= 0 ? agentNameLineIndex + 1 : 0;
26204
+ for (let i = startIndex; i < lines.length; i++) {
26128
26205
  const line = lines[i];
26129
26206
  if (line === undefined) {
26130
26207
  continue;