@promptbook/cli 0.103.0-47 → 0.103.0-48

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 (48) hide show
  1. package/apps/agents-server/TODO.txt +2 -2
  2. package/apps/agents-server/config.ts.todo +5 -279
  3. package/apps/agents-server/src/app/agents/[agentName]/api/chat/route.ts +7 -1
  4. package/apps/agents-server/src/app/agents/[agentName]/book/BookEditorWrapper.tsx +2 -2
  5. package/apps/agents-server/src/app/agents/[agentName]/book+chat/AgentBookAndChatComponent.tsx +2 -4
  6. package/apps/agents-server/src/app/agents/[agentName]/page.tsx +2 -2
  7. package/apps/agents-server/src/app/api/upload/route.ts +0 -4
  8. package/apps/agents-server/src/{supabase/getSupabase.ts → database/$provideSupabase.ts} +11 -7
  9. package/apps/agents-server/src/{supabase/getSupabaseForBrowser.ts → database/$provideSupabaseForBrowser.ts} +9 -5
  10. package/apps/agents-server/src/{supabase/getSupabaseForServer.ts → database/$provideSupabaseForServer.ts} +4 -4
  11. package/apps/agents-server/src/{supabase/getSupabaseForWorker.ts → database/$provideSupabaseForWorker.ts} +5 -4
  12. package/apps/agents-server/src/database/schema.sql +131 -0
  13. package/apps/agents-server/src/database/schema.ts +217 -0
  14. package/apps/agents-server/src/tools/$provideAgentCollectionForServer.ts +3 -3
  15. package/apps/agents-server/src/tools/$provideOpenAiAssistantExecutionToolsForServer.ts +1 -1
  16. package/apps/agents-server/src/utils/cdn/utils/getUserFileCdnKey.ts +2 -1
  17. package/esm/index.es.js +166 -21
  18. package/esm/index.es.js.map +1 -1
  19. package/esm/typings/src/_packages/core.index.d.ts +6 -0
  20. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  21. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +7 -3
  22. package/esm/typings/src/book-2.0/agent-source/AgentSourceParseResult.d.ts +2 -1
  23. package/esm/typings/src/book-2.0/agent-source/computeAgentHash.d.ts +8 -0
  24. package/esm/typings/src/book-2.0/agent-source/computeAgentHash.test.d.ts +1 -0
  25. package/esm/typings/src/book-2.0/agent-source/createDefaultAgentName.d.ts +8 -0
  26. package/esm/typings/src/book-2.0/agent-source/normalizeAgentName.d.ts +9 -0
  27. package/esm/typings/src/book-2.0/agent-source/normalizeAgentName.test.d.ts +1 -0
  28. package/esm/typings/src/book-2.0/agent-source/parseAgentSourceWithCommitments.d.ts +1 -1
  29. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +57 -32
  30. package/esm/typings/src/llm-providers/_common/utils/assertUniqueModels.d.ts +12 -0
  31. package/esm/typings/src/llm-providers/agent/Agent.d.ts +7 -2
  32. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +4 -0
  33. package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +2 -2
  34. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +24 -3
  35. package/esm/typings/src/llm-providers/openai/openai-models.test.d.ts +4 -0
  36. package/esm/typings/src/remote-server/startAgentServer.d.ts +1 -1
  37. package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -2
  38. package/esm/typings/src/transpilers/openai-sdk/register.d.ts +1 -1
  39. package/esm/typings/src/types/typeAliases.d.ts +6 -0
  40. package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +2 -0
  41. package/esm/typings/src/utils/normalization/normalizeTo_PascalCase.d.ts +3 -0
  42. package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +2 -0
  43. package/esm/typings/src/utils/normalization/titleToName.d.ts +2 -0
  44. package/esm/typings/src/version.d.ts +1 -1
  45. package/package.json +1 -1
  46. package/umd/index.umd.js +167 -22
  47. package/umd/index.umd.js.map +1 -1
  48. package/apps/agents-server/src/supabase/TODO.txt +0 -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.103.0-47';
50
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-48';
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
@@ -2938,6 +2938,8 @@ function removeDiacritics(input) {
2938
2938
  /**
2939
2939
  * Converts a given text to kebab-case format.
2940
2940
  *
2941
+ * Note: [🔂] This function is idempotent.
2942
+ *
2941
2943
  * @param text The text to be converted.
2942
2944
  * @returns The kebab-case formatted string.
2943
2945
  * @example 'hello-world'
@@ -3007,6 +3009,8 @@ function removeEmojis(text) {
3007
3009
  /**
3008
3010
  * Converts a title string into a normalized name.
3009
3011
  *
3012
+ * Note: [🔂] This function is idempotent.
3013
+ *
3010
3014
  * @param value The title string to be converted to a name.
3011
3015
  * @returns A normalized name derived from the input title.
3012
3016
  * @example 'Hello World!' -> 'hello-world'
@@ -10017,6 +10021,8 @@ const expectCommandParser = {
10017
10021
  /**
10018
10022
  * Normalizes a given text to camelCase format.
10019
10023
  *
10024
+ * Note: [🔂] This function is idempotent.
10025
+ *
10020
10026
  * @param text The text to be normalized.
10021
10027
  * @param _isFirstLetterCapital Whether the first letter should be capitalized.
10022
10028
  * @returns The camelCase formatted string.
@@ -13025,6 +13031,9 @@ function nameToUriParts(name) {
13025
13031
  }
13026
13032
 
13027
13033
  /**
13034
+ * Normalizes a given text to PascalCase format.
13035
+ *
13036
+ * Note: [🔂] This function is idempotent.
13028
13037
  *
13029
13038
  * @param text @public exported from `@promptbook/utils`
13030
13039
  * @returns
@@ -15082,7 +15091,7 @@ function $initializeRunCommand(program) {
15082
15091
  *
15083
15092
  * @see https://github.com/webgptorg/promptbook#remote-server
15084
15093
  * @public exported from `@promptbook/remote-server`
15085
- * <- TODO: !!!! Maybe change to `@promptbook/agent-server`
15094
+ * <- TODO: !!!! Change to `@promptbook/agent-server`
15086
15095
  */
15087
15096
  async function startAgentServer(options) {
15088
15097
  const { port = 4440 } = options;
@@ -16394,8 +16403,7 @@ function startRemoteServer(options) {
16394
16403
  };
16395
16404
  }
16396
16405
  /**
16397
- * TODO !!!! Add agent
16398
- * TODO: !!!! Allow to chat with agents directly via remote server
16406
+
16399
16407
  * TODO: [🕋] Use here `aboutPromptbookInformation`
16400
16408
  * TODO: [🌡] Add CORS and security - probably via `helmet`
16401
16409
  * TODO: Split this file into multiple functions - handler for each request
@@ -17516,17 +17524,17 @@ const OPENAI_MODELS = exportJson({
17516
17524
  },
17517
17525
  /**/
17518
17526
  /*/
17519
- {
17520
- modelTitle: 'tts-1-hd-1106',
17521
- modelName: 'tts-1-hd-1106',
17522
- },
17523
- /**/
17527
+ {
17528
+ modelTitle: 'tts-1-hd-1106',
17529
+ modelName: 'tts-1-hd-1106',
17530
+ },
17531
+ /**/
17524
17532
  /*/
17525
- {
17526
- modelTitle: 'tts-1-hd',
17527
- modelName: 'tts-1-hd',
17528
- },
17529
- /**/
17533
+ {
17534
+ modelTitle: 'tts-1-hd',
17535
+ modelName: 'tts-1-hd',
17536
+ },
17537
+ /**/
17530
17538
  /**/
17531
17539
  {
17532
17540
  modelVariant: 'CHAT',
@@ -20557,15 +20565,19 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
20557
20565
  },
20558
20566
  });
20559
20567
  }
20560
- async playground() {
20568
+ /*
20569
+ public async playground() {
20561
20570
  const client = await this.getClient();
20571
+
20562
20572
  // List all assistants
20563
20573
  const assistants = await client.beta.assistants.list();
20564
20574
  console.log('!!! Assistants:', assistants);
20575
+
20565
20576
  // Get details of a specific assistant
20566
20577
  const assistantId = 'asst_MO8fhZf4dGloCfXSHeLcIik0';
20567
20578
  const assistant = await client.beta.assistants.retrieve(assistantId);
20568
20579
  console.log('!!! Assistant Details:', assistant);
20580
+
20569
20581
  // Update an assistant
20570
20582
  const updatedAssistant = await client.beta.assistants.update(assistantId, {
20571
20583
  name: assistant.name + '(M)',
@@ -20575,8 +20587,19 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
20575
20587
  },
20576
20588
  });
20577
20589
  console.log('!!! Updated Assistant:', updatedAssistant);
20590
+
20578
20591
  await forEver();
20579
20592
  }
20593
+ */
20594
+ /**
20595
+ * Get an existing assistant tool wrapper
20596
+ */
20597
+ getAssistant(assistantId) {
20598
+ return new OpenAiAssistantExecutionTools({
20599
+ ...this.options,
20600
+ assistantId,
20601
+ });
20602
+ }
20580
20603
  async createNewAssistant(options) {
20581
20604
  if (!this.isCreatingNewAssistantsAllowed) {
20582
20605
  throw new NotAllowed(`Creating new assistants is not allowed. Set \`isCreatingNewAssistantsAllowed: true\` in options to enable this feature.`);
@@ -20671,6 +20694,95 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
20671
20694
  assistantId: assistant.id,
20672
20695
  });
20673
20696
  }
20697
+ async updateAssistant(options) {
20698
+ if (!this.isCreatingNewAssistantsAllowed) {
20699
+ throw new NotAllowed(`Updating assistants is not allowed. Set \`isCreatingNewAssistantsAllowed: true\` in options to enable this feature.`);
20700
+ }
20701
+ const { assistantId, name, instructions, knowledgeSources } = options;
20702
+ const client = await this.getClient();
20703
+ let vectorStoreId;
20704
+ // If knowledge sources are provided, create a vector store with them
20705
+ // TODO: [🧠] Reuse vector store creation logic from createNewAssistant
20706
+ if (knowledgeSources && knowledgeSources.length > 0) {
20707
+ if (this.options.isVerbose) {
20708
+ console.info(`📚 Creating vector store for update with ${knowledgeSources.length} knowledge sources...`);
20709
+ }
20710
+ // Create a vector store
20711
+ const vectorStore = await client.beta.vectorStores.create({
20712
+ name: `${name} Knowledge Base`,
20713
+ });
20714
+ vectorStoreId = vectorStore.id;
20715
+ if (this.options.isVerbose) {
20716
+ console.info(`✅ Vector store created: ${vectorStoreId}`);
20717
+ }
20718
+ // Upload files from knowledge sources to the vector store
20719
+ const fileStreams = [];
20720
+ for (const source of knowledgeSources) {
20721
+ try {
20722
+ // Check if it's a URL
20723
+ if (source.startsWith('http://') || source.startsWith('https://')) {
20724
+ // Download the file
20725
+ const response = await fetch(source);
20726
+ if (!response.ok) {
20727
+ console.error(`Failed to download ${source}: ${response.statusText}`);
20728
+ continue;
20729
+ }
20730
+ const buffer = await response.arrayBuffer();
20731
+ const filename = source.split('/').pop() || 'downloaded-file';
20732
+ const blob = new Blob([buffer]);
20733
+ const file = new File([blob], filename);
20734
+ fileStreams.push(file);
20735
+ }
20736
+ else {
20737
+ // Assume it's a local file path
20738
+ // Note: This will work in Node.js environment
20739
+ // For browser environments, this would need different handling
20740
+ const fs = await import('fs');
20741
+ const fileStream = fs.createReadStream(source);
20742
+ fileStreams.push(fileStream);
20743
+ }
20744
+ }
20745
+ catch (error) {
20746
+ console.error(`Error processing knowledge source ${source}:`, error);
20747
+ }
20748
+ }
20749
+ // Batch upload files to the vector store
20750
+ if (fileStreams.length > 0) {
20751
+ try {
20752
+ await client.beta.vectorStores.fileBatches.uploadAndPoll(vectorStoreId, {
20753
+ files: fileStreams,
20754
+ });
20755
+ if (this.options.isVerbose) {
20756
+ console.info(`✅ Uploaded ${fileStreams.length} files to vector store`);
20757
+ }
20758
+ }
20759
+ catch (error) {
20760
+ console.error('Error uploading files to vector store:', error);
20761
+ }
20762
+ }
20763
+ }
20764
+ const assistantUpdate = {
20765
+ name,
20766
+ instructions,
20767
+ tools: [/* TODO: [🧠] Maybe add { type: 'code_interpreter' }, */ { type: 'file_search' }],
20768
+ };
20769
+ if (vectorStoreId) {
20770
+ assistantUpdate.tool_resources = {
20771
+ file_search: {
20772
+ vector_store_ids: [vectorStoreId],
20773
+ },
20774
+ };
20775
+ }
20776
+ const assistant = await client.beta.assistants.update(assistantId, assistantUpdate);
20777
+ if (this.options.isVerbose) {
20778
+ console.log(`✅ Assistant updated: ${assistant.id}`);
20779
+ }
20780
+ return new OpenAiAssistantExecutionTools({
20781
+ ...this.options,
20782
+ isCreatingNewAssistantsAllowed: false,
20783
+ assistantId: assistant.id,
20784
+ });
20785
+ }
20674
20786
  /**
20675
20787
  * Discriminant for type guards
20676
20788
  */
@@ -23601,6 +23713,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
23601
23713
  // Keep everything after the PERSONA section
23602
23714
  cleanedMessage = lines.slice(personaEndIndex).join('\n').trim();
23603
23715
  }
23716
+ // TODO: [🕛] There should be `agentFullname` not `agentName`
23604
23717
  // Create new system message with persona at the beginning
23605
23718
  // Format: "You are {agentName}\n{personaContent}"
23606
23719
  // The # PERSONA comment will be removed later by removeCommentsFromSystemMessage
@@ -24429,6 +24542,36 @@ function generatePlaceholderAgentProfileImageUrl(agentName) {
24429
24542
  * TODO: [🤹] Figure out best placeholder image generator https://i.pravatar.cc/1000?u=568
24430
24543
  */
24431
24544
 
24545
+ /**
24546
+ * Computes SHA-256 hash of the agent source
24547
+ *
24548
+ * @public exported from `@promptbook/core`
24549
+ */
24550
+ function computeAgentHash(agentSource) {
24551
+ return SHA256(hexEncoder.parse(agentSource /* <- TODO: !!!!! spaceTrim */)).toString( /* hex */);
24552
+ }
24553
+
24554
+ /**
24555
+ * Normalizes agent name from arbitrary string to valid agent name
24556
+ *
24557
+ * Note: [🔂] This function is idempotent.
24558
+ *
24559
+ * @public exported from `@promptbook/core`
24560
+ */
24561
+ function normalizeAgentName(rawAgentName) {
24562
+ return titleToName(spaceTrim(rawAgentName));
24563
+ }
24564
+
24565
+ /**
24566
+ * Creates temporary default agent name based on agent source hash
24567
+ *
24568
+ * @public exported from `@promptbook/core`
24569
+ */
24570
+ function createDefaultAgentName(agentSource) {
24571
+ const agentHash = computeAgentHash(agentSource);
24572
+ return normalizeAgentName(`Agent ${agentHash.substring(0, 6)}`);
24573
+ }
24574
+
24432
24575
  /**
24433
24576
  * Parses basic information from agent source
24434
24577
  *
@@ -24471,8 +24614,10 @@ function parseAgentSource(agentSource) {
24471
24614
  // Parse parameters using unified approach - both @Parameter and {parameter} notations
24472
24615
  // are treated as the same syntax feature with unified representation
24473
24616
  const parameters = parseParameters(agentSource);
24617
+ const agentHash = computeAgentHash(agentSource);
24474
24618
  return {
24475
- agentName: parseResult.agentName,
24619
+ agentName: normalizeAgentName(parseResult.agentName || createDefaultAgentName(agentSource)),
24620
+ agentHash,
24476
24621
  personaDescription,
24477
24622
  meta,
24478
24623
  parameters,
@@ -24692,7 +24837,7 @@ const OpenAiSdkTranspiler = {
24692
24837
  });
24693
24838
 
24694
24839
  const answer = response.choices[0].message.content;
24695
- console.log('\\n🧠 ${agentName}:', answer, '\\n');
24840
+ console.log('\\n🧠 ${agentName /* <- TODO: [🕛] There should be `agentFullname` not `agentName` */}:', answer, '\\n');
24696
24841
 
24697
24842
  chatHistory.push({ role: 'assistant', content: answer });
24698
24843
  promptUser();
@@ -24711,7 +24856,7 @@ const OpenAiSdkTranspiler = {
24711
24856
 
24712
24857
  (async () => {
24713
24858
  await setupKnowledge();
24714
- console.log("🤖 Chat with ${agentName} (type 'exit' to quit)\\n");
24859
+ console.log("🤖 Chat with ${agentName /* <- TODO: [🕛] There should be `agentFullname` not `agentName` */} (type 'exit' to quit)\\n");
24715
24860
  promptUser();
24716
24861
  })();
24717
24862
  `);
@@ -24758,7 +24903,7 @@ const OpenAiSdkTranspiler = {
24758
24903
  });
24759
24904
 
24760
24905
  const answer = response.choices[0].message.content;
24761
- console.log('\\n🧠 ${agentName}:', answer, '\\n');
24906
+ console.log('\\n🧠 ${agentName /* <- TODO: [🕛] There should be `agentFullname` not `agentName` */}:', answer, '\\n');
24762
24907
 
24763
24908
  chatHistory.push({ role: 'assistant', content: answer });
24764
24909
  promptUser();
@@ -24775,7 +24920,7 @@ const OpenAiSdkTranspiler = {
24775
24920
  });
24776
24921
  }
24777
24922
 
24778
- console.log("🤖 Chat with ${agentName} (type 'exit' to quit)\\n");
24923
+ console.log("🤖 Chat with ${agentName /* <- TODO: [🕛] There should be `agentFullname` not `agentName` */} (type 'exit' to quit)\\n");
24779
24924
  promptUser();
24780
24925
 
24781
24926
  `);
@@ -24791,7 +24936,7 @@ const OpenAiSdkTranspiler = {
24791
24936
  * @public exported from `@promptbook/wizard`
24792
24937
  * @public exported from `@promptbook/cli`
24793
24938
  *
24794
- * TODO: !!!! Which package should export this?
24939
+ * TODO: [🧠] Which package should export this?
24795
24940
  */
24796
24941
  const _OpenAiSdkTranspilerRegistration = $bookTranspilersRegister.register(OpenAiSdkTranspiler);
24797
24942
  /**