@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/umd/index.umd.js CHANGED
@@ -56,7 +56,7 @@
56
56
  * @generated
57
57
  * @see https://github.com/webgptorg/promptbook
58
58
  */
59
- const PROMPTBOOK_ENGINE_VERSION = '0.103.0-47';
59
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-48';
60
60
  /**
61
61
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
62
62
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2947,6 +2947,8 @@
2947
2947
  /**
2948
2948
  * Converts a given text to kebab-case format.
2949
2949
  *
2950
+ * Note: [🔂] This function is idempotent.
2951
+ *
2950
2952
  * @param text The text to be converted.
2951
2953
  * @returns The kebab-case formatted string.
2952
2954
  * @example 'hello-world'
@@ -3016,6 +3018,8 @@
3016
3018
  /**
3017
3019
  * Converts a title string into a normalized name.
3018
3020
  *
3021
+ * Note: [🔂] This function is idempotent.
3022
+ *
3019
3023
  * @param value The title string to be converted to a name.
3020
3024
  * @returns A normalized name derived from the input title.
3021
3025
  * @example 'Hello World!' -> 'hello-world'
@@ -10026,6 +10030,8 @@
10026
10030
  /**
10027
10031
  * Normalizes a given text to camelCase format.
10028
10032
  *
10033
+ * Note: [🔂] This function is idempotent.
10034
+ *
10029
10035
  * @param text The text to be normalized.
10030
10036
  * @param _isFirstLetterCapital Whether the first letter should be capitalized.
10031
10037
  * @returns The camelCase formatted string.
@@ -13034,6 +13040,9 @@
13034
13040
  }
13035
13041
 
13036
13042
  /**
13043
+ * Normalizes a given text to PascalCase format.
13044
+ *
13045
+ * Note: [🔂] This function is idempotent.
13037
13046
  *
13038
13047
  * @param text @public exported from `@promptbook/utils`
13039
13048
  * @returns
@@ -15091,7 +15100,7 @@
15091
15100
  *
15092
15101
  * @see https://github.com/webgptorg/promptbook#remote-server
15093
15102
  * @public exported from `@promptbook/remote-server`
15094
- * <- TODO: !!!! Maybe change to `@promptbook/agent-server`
15103
+ * <- TODO: !!!! Change to `@promptbook/agent-server`
15095
15104
  */
15096
15105
  async function startAgentServer(options) {
15097
15106
  const { port = 4440 } = options;
@@ -16403,8 +16412,7 @@
16403
16412
  };
16404
16413
  }
16405
16414
  /**
16406
- * TODO !!!! Add agent
16407
- * TODO: !!!! Allow to chat with agents directly via remote server
16415
+
16408
16416
  * TODO: [🕋] Use here `aboutPromptbookInformation`
16409
16417
  * TODO: [🌡] Add CORS and security - probably via `helmet`
16410
16418
  * TODO: Split this file into multiple functions - handler for each request
@@ -17525,17 +17533,17 @@
17525
17533
  },
17526
17534
  /**/
17527
17535
  /*/
17528
- {
17529
- modelTitle: 'tts-1-hd-1106',
17530
- modelName: 'tts-1-hd-1106',
17531
- },
17532
- /**/
17536
+ {
17537
+ modelTitle: 'tts-1-hd-1106',
17538
+ modelName: 'tts-1-hd-1106',
17539
+ },
17540
+ /**/
17533
17541
  /*/
17534
- {
17535
- modelTitle: 'tts-1-hd',
17536
- modelName: 'tts-1-hd',
17537
- },
17538
- /**/
17542
+ {
17543
+ modelTitle: 'tts-1-hd',
17544
+ modelName: 'tts-1-hd',
17545
+ },
17546
+ /**/
17539
17547
  /**/
17540
17548
  {
17541
17549
  modelVariant: 'CHAT',
@@ -20566,15 +20574,19 @@
20566
20574
  },
20567
20575
  });
20568
20576
  }
20569
- async playground() {
20577
+ /*
20578
+ public async playground() {
20570
20579
  const client = await this.getClient();
20580
+
20571
20581
  // List all assistants
20572
20582
  const assistants = await client.beta.assistants.list();
20573
20583
  console.log('!!! Assistants:', assistants);
20584
+
20574
20585
  // Get details of a specific assistant
20575
20586
  const assistantId = 'asst_MO8fhZf4dGloCfXSHeLcIik0';
20576
20587
  const assistant = await client.beta.assistants.retrieve(assistantId);
20577
20588
  console.log('!!! Assistant Details:', assistant);
20589
+
20578
20590
  // Update an assistant
20579
20591
  const updatedAssistant = await client.beta.assistants.update(assistantId, {
20580
20592
  name: assistant.name + '(M)',
@@ -20584,7 +20596,18 @@
20584
20596
  },
20585
20597
  });
20586
20598
  console.log('!!! Updated Assistant:', updatedAssistant);
20587
- await waitasecond.forEver();
20599
+
20600
+ await forEver();
20601
+ }
20602
+ */
20603
+ /**
20604
+ * Get an existing assistant tool wrapper
20605
+ */
20606
+ getAssistant(assistantId) {
20607
+ return new OpenAiAssistantExecutionTools({
20608
+ ...this.options,
20609
+ assistantId,
20610
+ });
20588
20611
  }
20589
20612
  async createNewAssistant(options) {
20590
20613
  if (!this.isCreatingNewAssistantsAllowed) {
@@ -20680,6 +20703,95 @@
20680
20703
  assistantId: assistant.id,
20681
20704
  });
20682
20705
  }
20706
+ async updateAssistant(options) {
20707
+ if (!this.isCreatingNewAssistantsAllowed) {
20708
+ throw new NotAllowed(`Updating assistants is not allowed. Set \`isCreatingNewAssistantsAllowed: true\` in options to enable this feature.`);
20709
+ }
20710
+ const { assistantId, name, instructions, knowledgeSources } = options;
20711
+ const client = await this.getClient();
20712
+ let vectorStoreId;
20713
+ // If knowledge sources are provided, create a vector store with them
20714
+ // TODO: [🧠] Reuse vector store creation logic from createNewAssistant
20715
+ if (knowledgeSources && knowledgeSources.length > 0) {
20716
+ if (this.options.isVerbose) {
20717
+ console.info(`📚 Creating vector store for update with ${knowledgeSources.length} knowledge sources...`);
20718
+ }
20719
+ // Create a vector store
20720
+ const vectorStore = await client.beta.vectorStores.create({
20721
+ name: `${name} Knowledge Base`,
20722
+ });
20723
+ vectorStoreId = vectorStore.id;
20724
+ if (this.options.isVerbose) {
20725
+ console.info(`✅ Vector store created: ${vectorStoreId}`);
20726
+ }
20727
+ // Upload files from knowledge sources to the vector store
20728
+ const fileStreams = [];
20729
+ for (const source of knowledgeSources) {
20730
+ try {
20731
+ // Check if it's a URL
20732
+ if (source.startsWith('http://') || source.startsWith('https://')) {
20733
+ // Download the file
20734
+ const response = await fetch(source);
20735
+ if (!response.ok) {
20736
+ console.error(`Failed to download ${source}: ${response.statusText}`);
20737
+ continue;
20738
+ }
20739
+ const buffer = await response.arrayBuffer();
20740
+ const filename = source.split('/').pop() || 'downloaded-file';
20741
+ const blob = new Blob([buffer]);
20742
+ const file = new File([blob], filename);
20743
+ fileStreams.push(file);
20744
+ }
20745
+ else {
20746
+ // Assume it's a local file path
20747
+ // Note: This will work in Node.js environment
20748
+ // For browser environments, this would need different handling
20749
+ const fs = await import('fs');
20750
+ const fileStream = fs.createReadStream(source);
20751
+ fileStreams.push(fileStream);
20752
+ }
20753
+ }
20754
+ catch (error) {
20755
+ console.error(`Error processing knowledge source ${source}:`, error);
20756
+ }
20757
+ }
20758
+ // Batch upload files to the vector store
20759
+ if (fileStreams.length > 0) {
20760
+ try {
20761
+ await client.beta.vectorStores.fileBatches.uploadAndPoll(vectorStoreId, {
20762
+ files: fileStreams,
20763
+ });
20764
+ if (this.options.isVerbose) {
20765
+ console.info(`✅ Uploaded ${fileStreams.length} files to vector store`);
20766
+ }
20767
+ }
20768
+ catch (error) {
20769
+ console.error('Error uploading files to vector store:', error);
20770
+ }
20771
+ }
20772
+ }
20773
+ const assistantUpdate = {
20774
+ name,
20775
+ instructions,
20776
+ tools: [/* TODO: [🧠] Maybe add { type: 'code_interpreter' }, */ { type: 'file_search' }],
20777
+ };
20778
+ if (vectorStoreId) {
20779
+ assistantUpdate.tool_resources = {
20780
+ file_search: {
20781
+ vector_store_ids: [vectorStoreId],
20782
+ },
20783
+ };
20784
+ }
20785
+ const assistant = await client.beta.assistants.update(assistantId, assistantUpdate);
20786
+ if (this.options.isVerbose) {
20787
+ console.log(`✅ Assistant updated: ${assistant.id}`);
20788
+ }
20789
+ return new OpenAiAssistantExecutionTools({
20790
+ ...this.options,
20791
+ isCreatingNewAssistantsAllowed: false,
20792
+ assistantId: assistant.id,
20793
+ });
20794
+ }
20683
20795
  /**
20684
20796
  * Discriminant for type guards
20685
20797
  */
@@ -23610,6 +23722,7 @@
23610
23722
  // Keep everything after the PERSONA section
23611
23723
  cleanedMessage = lines.slice(personaEndIndex).join('\n').trim();
23612
23724
  }
23725
+ // TODO: [🕛] There should be `agentFullname` not `agentName`
23613
23726
  // Create new system message with persona at the beginning
23614
23727
  // Format: "You are {agentName}\n{personaContent}"
23615
23728
  // The # PERSONA comment will be removed later by removeCommentsFromSystemMessage
@@ -24438,6 +24551,36 @@
24438
24551
  * TODO: [🤹] Figure out best placeholder image generator https://i.pravatar.cc/1000?u=568
24439
24552
  */
24440
24553
 
24554
+ /**
24555
+ * Computes SHA-256 hash of the agent source
24556
+ *
24557
+ * @public exported from `@promptbook/core`
24558
+ */
24559
+ function computeAgentHash(agentSource) {
24560
+ return cryptoJs.SHA256(hexEncoder__default["default"].parse(agentSource /* <- TODO: !!!!! spaceTrim */)).toString( /* hex */);
24561
+ }
24562
+
24563
+ /**
24564
+ * Normalizes agent name from arbitrary string to valid agent name
24565
+ *
24566
+ * Note: [🔂] This function is idempotent.
24567
+ *
24568
+ * @public exported from `@promptbook/core`
24569
+ */
24570
+ function normalizeAgentName(rawAgentName) {
24571
+ return titleToName(spaceTrim__default["default"](rawAgentName));
24572
+ }
24573
+
24574
+ /**
24575
+ * Creates temporary default agent name based on agent source hash
24576
+ *
24577
+ * @public exported from `@promptbook/core`
24578
+ */
24579
+ function createDefaultAgentName(agentSource) {
24580
+ const agentHash = computeAgentHash(agentSource);
24581
+ return normalizeAgentName(`Agent ${agentHash.substring(0, 6)}`);
24582
+ }
24583
+
24441
24584
  /**
24442
24585
  * Parses basic information from agent source
24443
24586
  *
@@ -24480,8 +24623,10 @@
24480
24623
  // Parse parameters using unified approach - both @Parameter and {parameter} notations
24481
24624
  // are treated as the same syntax feature with unified representation
24482
24625
  const parameters = parseParameters(agentSource);
24626
+ const agentHash = computeAgentHash(agentSource);
24483
24627
  return {
24484
- agentName: parseResult.agentName,
24628
+ agentName: normalizeAgentName(parseResult.agentName || createDefaultAgentName(agentSource)),
24629
+ agentHash,
24485
24630
  personaDescription,
24486
24631
  meta,
24487
24632
  parameters,
@@ -24701,7 +24846,7 @@
24701
24846
  });
24702
24847
 
24703
24848
  const answer = response.choices[0].message.content;
24704
- console.log('\\n🧠 ${agentName}:', answer, '\\n');
24849
+ console.log('\\n🧠 ${agentName /* <- TODO: [🕛] There should be `agentFullname` not `agentName` */}:', answer, '\\n');
24705
24850
 
24706
24851
  chatHistory.push({ role: 'assistant', content: answer });
24707
24852
  promptUser();
@@ -24720,7 +24865,7 @@
24720
24865
 
24721
24866
  (async () => {
24722
24867
  await setupKnowledge();
24723
- console.log("🤖 Chat with ${agentName} (type 'exit' to quit)\\n");
24868
+ console.log("🤖 Chat with ${agentName /* <- TODO: [🕛] There should be `agentFullname` not `agentName` */} (type 'exit' to quit)\\n");
24724
24869
  promptUser();
24725
24870
  })();
24726
24871
  `);
@@ -24767,7 +24912,7 @@
24767
24912
  });
24768
24913
 
24769
24914
  const answer = response.choices[0].message.content;
24770
- console.log('\\n🧠 ${agentName}:', answer, '\\n');
24915
+ console.log('\\n🧠 ${agentName /* <- TODO: [🕛] There should be `agentFullname` not `agentName` */}:', answer, '\\n');
24771
24916
 
24772
24917
  chatHistory.push({ role: 'assistant', content: answer });
24773
24918
  promptUser();
@@ -24784,7 +24929,7 @@
24784
24929
  });
24785
24930
  }
24786
24931
 
24787
- console.log("🤖 Chat with ${agentName} (type 'exit' to quit)\\n");
24932
+ console.log("🤖 Chat with ${agentName /* <- TODO: [🕛] There should be `agentFullname` not `agentName` */} (type 'exit' to quit)\\n");
24788
24933
  promptUser();
24789
24934
 
24790
24935
  `);
@@ -24800,7 +24945,7 @@
24800
24945
  * @public exported from `@promptbook/wizard`
24801
24946
  * @public exported from `@promptbook/cli`
24802
24947
  *
24803
- * TODO: !!!! Which package should export this?
24948
+ * TODO: [🧠] Which package should export this?
24804
24949
  */
24805
24950
  const _OpenAiSdkTranspilerRegistration = $bookTranspilersRegister.register(OpenAiSdkTranspiler);
24806
24951
  /**