@promptbook/openai 0.103.0-46 → 0.103.0-47

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 (53) hide show
  1. package/esm/index.es.js +81 -59
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/servers.d.ts +1 -7
  4. package/esm/typings/src/_packages/components.index.d.ts +4 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +16 -14
  6. package/esm/typings/src/_packages/types.index.d.ts +12 -6
  7. package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +6 -1
  8. package/esm/typings/src/book-2.0/agent-source/AgentSourceParseResult.d.ts +1 -1
  9. package/esm/typings/src/book-2.0/agent-source/createCommitmentRegex.d.ts +1 -1
  10. package/esm/typings/src/book-components/Chat/AgentChat/AgentChat.d.ts +14 -0
  11. package/esm/typings/src/book-components/Chat/AgentChat/AgentChat.test.d.ts +1 -0
  12. package/esm/typings/src/book-components/Chat/AgentChat/AgentChatProps.d.ts +13 -0
  13. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +1 -60
  14. package/esm/typings/src/{book-2.0/commitments → commitments}/ACTION/ACTION.d.ts +1 -1
  15. package/esm/typings/src/{book-2.0/commitments → commitments}/DELETE/DELETE.d.ts +1 -1
  16. package/esm/typings/src/{book-2.0/commitments → commitments}/FORMAT/FORMAT.d.ts +1 -1
  17. package/esm/typings/src/{book-2.0/commitments → commitments}/GOAL/GOAL.d.ts +1 -1
  18. package/esm/typings/src/{book-2.0/commitments → commitments}/KNOWLEDGE/KNOWLEDGE.d.ts +1 -5
  19. package/esm/typings/src/{book-2.0/commitments → commitments}/MEMORY/MEMORY.d.ts +1 -1
  20. package/esm/typings/src/{book-2.0/commitments → commitments}/MESSAGE/MESSAGE.d.ts +1 -1
  21. package/esm/typings/src/{book-2.0/commitments → commitments}/META/META.d.ts +1 -1
  22. package/esm/typings/src/{book-2.0/commitments → commitments}/META_IMAGE/META_IMAGE.d.ts +1 -1
  23. package/esm/typings/src/{book-2.0/commitments → commitments}/META_LINK/META_LINK.d.ts +1 -1
  24. package/esm/typings/src/{book-2.0/commitments → commitments}/MODEL/MODEL.d.ts +1 -1
  25. package/esm/typings/src/{book-2.0/commitments → commitments}/NOTE/NOTE.d.ts +1 -1
  26. package/esm/typings/src/{book-2.0/commitments → commitments}/PERSONA/PERSONA.d.ts +1 -1
  27. package/esm/typings/src/{book-2.0/commitments → commitments}/RULE/RULE.d.ts +1 -1
  28. package/esm/typings/src/{book-2.0/commitments → commitments}/SAMPLE/SAMPLE.d.ts +1 -1
  29. package/esm/typings/src/{book-2.0/commitments → commitments}/SCENARIO/SCENARIO.d.ts +1 -1
  30. package/esm/typings/src/{book-2.0/commitments → commitments}/STYLE/STYLE.d.ts +1 -1
  31. package/esm/typings/src/{book-2.0/commitments → commitments}/_base/BaseCommitmentDefinition.d.ts +1 -1
  32. package/esm/typings/src/{book-2.0/commitments → commitments}/_base/CommitmentDefinition.d.ts +1 -1
  33. package/esm/typings/src/{book-2.0/commitments → commitments}/_base/NotYetImplementedCommitmentDefinition.d.ts +1 -1
  34. package/esm/typings/src/{book-2.0/commitments → commitments}/_base/createEmptyAgentModelRequirements.d.ts +1 -1
  35. package/esm/typings/src/execution/LlmExecutionTools.d.ts +1 -1
  36. package/esm/typings/src/llm-providers/agent/Agent.d.ts +3 -7
  37. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +1 -1
  38. package/esm/typings/src/llm-providers/agent/CreateAgentLlmExecutionToolsOptions.d.ts +1 -1
  39. package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +32 -0
  40. package/esm/typings/src/llm-providers/agent/RemoteAgentOptions.d.ts +11 -0
  41. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +5 -1
  42. package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -0
  43. package/esm/typings/src/types/typeAliases.d.ts +6 -0
  44. package/esm/typings/src/utils/color/internal-utils/checkChannelValue.d.ts +0 -3
  45. package/esm/typings/src/utils/random/$generateBookBoilerplate.d.ts +2 -2
  46. package/esm/typings/src/utils/random/$randomFullnameWithColor.d.ts +1 -1
  47. package/esm/typings/src/version.d.ts +1 -1
  48. package/package.json +2 -2
  49. package/umd/index.umd.js +81 -59
  50. package/umd/index.umd.js.map +1 -1
  51. /package/esm/typings/src/{book-2.0/commitments → commitments}/_base/BookCommitment.d.ts +0 -0
  52. /package/esm/typings/src/{book-2.0/commitments → commitments}/_base/ParsedCommitment.d.ts +0 -0
  53. /package/esm/typings/src/{book-2.0/commitments → commitments}/index.d.ts +0 -0
@@ -1,7 +1,7 @@
1
1
  import type { PartialDeep } from 'type-fest';
2
2
  import type { AgentBasicInformation } from '../../book-2.0/agent-source/AgentBasicInformation';
3
- import { string_book } from '../../book-2.0/agent-source/string_book';
4
- import { string_agent_name_in_book } from '../../types/typeAliases';
3
+ import type { string_book } from '../../book-2.0/agent-source/string_book';
4
+ import type { string_agent_name_in_book } from '../../types/typeAliases';
5
5
  type GenerateBookBoilerplateOptions = PartialDeep<Omit<AgentBasicInformation, 'parameters'>> & {
6
6
  /**
7
7
  * Name of the parent agent to inherit from
@@ -1,4 +1,4 @@
1
- import { string_color, string_person_fullname } from '../../types/typeAliases';
1
+ import type { string_color, string_person_fullname } from '../../types/typeAliases';
2
2
  export type RandomFullnameWithColorResult = {
3
3
  fullname: string_person_fullname;
4
4
  color: string_color;
@@ -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.103.0-45`).
18
+ * It follows semantic versioning (e.g., `0.103.0-46`).
19
19
  *
20
20
  * @generated
21
21
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/openai",
3
- "version": "0.103.0-46",
3
+ "version": "0.103.0-47",
4
4
  "description": "Promptbook: Turn your company's scattered knowledge into AI ready books",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -102,7 +102,7 @@
102
102
  "module": "./esm/index.es.js",
103
103
  "typings": "./esm/typings/src/_packages/openai.index.d.ts",
104
104
  "peerDependencies": {
105
- "@promptbook/core": "0.103.0-46"
105
+ "@promptbook/core": "0.103.0-47"
106
106
  },
107
107
  "dependencies": {
108
108
  "bottleneck": "2.19.5",
package/umd/index.umd.js CHANGED
@@ -25,7 +25,7 @@
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- const PROMPTBOOK_ENGINE_VERSION = '0.103.0-46';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-47';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -479,9 +479,6 @@
479
479
  throw new Error(`${channelName} channel is greater than 255, it is ${value}`);
480
480
  }
481
481
  }
482
- /**
483
- * TODO: [🧠][🚓] Is/which combination it better to use asserts/check, validate or is utility function?
484
- */
485
482
 
486
483
  /**
487
484
  * Color object represents an RGB color with alpha channel
@@ -3565,7 +3562,7 @@
3565
3562
  *
3566
3563
  * This is useful for calling OpenAI API with a single assistant, for more wide usage use `OpenAiExecutionTools`.
3567
3564
  *
3568
- * Note: [🦖] There are several different things in Promptbook:
3565
+ * !!! Note: [🦖] There are several different things in Promptbook:
3569
3566
  * - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
3570
3567
  * - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
3571
3568
  * - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
@@ -3671,17 +3668,21 @@
3671
3668
  console.info('connect', stream.currentEvent);
3672
3669
  }
3673
3670
  });
3671
+ /*
3674
3672
  stream.on('messageDelta', (messageDelta) => {
3675
- var _a;
3676
- if (this.options.isVerbose &&
3673
+ if (
3674
+ this.options.isVerbose &&
3677
3675
  messageDelta &&
3678
3676
  messageDelta.content &&
3679
3677
  messageDelta.content[0] &&
3680
- messageDelta.content[0].type === 'text') {
3681
- console.info('messageDelta', (_a = messageDelta.content[0].text) === null || _a === void 0 ? void 0 : _a.value);
3678
+ messageDelta.content[0].type === 'text'
3679
+ ) {
3680
+ console.info('messageDelta', messageDelta.content[0].text?.value);
3682
3681
  }
3682
+
3683
3683
  // <- TODO: [🐚] Make streaming and running tasks working
3684
3684
  });
3685
+ */
3685
3686
  stream.on('messageCreated', (message) => {
3686
3687
  if (this.options.isVerbose) {
3687
3688
  console.info('messageCreated', message);
@@ -3761,64 +3762,85 @@
3761
3762
  throw new NotAllowed(`Creating new assistants is not allowed. Set \`isCreatingNewAssistantsAllowed: true\` in options to enable this feature.`);
3762
3763
  }
3763
3764
  // await this.playground();
3764
- const { name, instructions } = options;
3765
+ const { name, instructions, knowledgeSources } = options;
3765
3766
  const client = await this.getClient();
3766
- /*/
3767
- //TODO: !!!
3768
- async function downloadFile(url: string, folder = './tmp'): Promise<string> {
3769
- const filename = path.basename(url.split('?')[0]);
3770
- const filepath = path.join(folder, filename);
3771
-
3772
- if (!fs.existsSync(folder)) fs.mkdirSync(folder);
3773
-
3774
- const res = await fetch(url);
3775
- if (!res.ok) throw new Error(`Download error: ${url}`);
3776
- const buffer = await res.arrayBuffer();
3777
- fs.writeFileSync(filepath, Buffer.from(buffer));
3778
- console.log(`📥 File downloaded: ${filename}`);
3779
-
3780
- return filepath;
3781
- }
3782
-
3783
- async function uploadFileToOpenAI(filepath: string) {
3784
- const file = await client.files.create({
3785
- file: fs.createReadStream(filepath),
3786
- purpose: 'assistants',
3767
+ let vectorStoreId;
3768
+ // If knowledge sources are provided, create a vector store with them
3769
+ if (knowledgeSources && knowledgeSources.length > 0) {
3770
+ if (this.options.isVerbose) {
3771
+ console.info(`📚 Creating vector store with ${knowledgeSources.length} knowledge sources...`);
3772
+ }
3773
+ // Create a vector store
3774
+ const vectorStore = await client.beta.vectorStores.create({
3775
+ name: `${name} Knowledge Base`,
3787
3776
  });
3788
- console.log(`⬆️ File uploaded to OpenAI: ${file.filename} (${file.id})`);
3789
- return file;
3790
- }
3791
-
3792
- // 🌐 URL addresses of files to upload
3793
- const fileUrls = [
3794
- 'https://raw.githubusercontent.com/vercel/next.js/canary/packages/next/README.md',
3795
- 'https://raw.githubusercontent.com/openai/openai-cookbook/main/examples/How_to_call_the_Assistants_API_with_Node.js.ipynb',
3796
- ];
3797
-
3798
- // 1️⃣ Download files from URL
3799
- const localFiles = [];
3800
- for (const url of fileUrls) {
3801
- const filepath = await downloadFile(url);
3802
- localFiles.push(filepath);
3803
- }
3804
-
3805
- // 2️⃣ Upload files to OpenAI
3806
- const uploadedFiles = [];
3807
- for (const filepath of localFiles) {
3808
- const file = await uploadFileToOpenAI(filepath);
3809
- uploadedFiles.push(file.id);
3777
+ vectorStoreId = vectorStore.id;
3778
+ if (this.options.isVerbose) {
3779
+ console.info(`✅ Vector store created: ${vectorStoreId}`);
3780
+ }
3781
+ // Upload files from knowledge sources to the vector store
3782
+ const fileStreams = [];
3783
+ for (const source of knowledgeSources) {
3784
+ try {
3785
+ // Check if it's a URL
3786
+ if (source.startsWith('http://') || source.startsWith('https://')) {
3787
+ // Download the file
3788
+ const response = await fetch(source);
3789
+ if (!response.ok) {
3790
+ console.error(`Failed to download ${source}: ${response.statusText}`);
3791
+ continue;
3792
+ }
3793
+ const buffer = await response.arrayBuffer();
3794
+ const filename = source.split('/').pop() || 'downloaded-file';
3795
+ const blob = new Blob([buffer]);
3796
+ const file = new File([blob], filename);
3797
+ fileStreams.push(file);
3798
+ }
3799
+ else {
3800
+ // Assume it's a local file path
3801
+ // Note: This will work in Node.js environment
3802
+ // For browser environments, this would need different handling
3803
+ const fs = await import('fs');
3804
+ const fileStream = fs.createReadStream(source);
3805
+ fileStreams.push(fileStream);
3806
+ }
3807
+ }
3808
+ catch (error) {
3809
+ console.error(`Error processing knowledge source ${source}:`, error);
3810
+ }
3811
+ }
3812
+ // Batch upload files to the vector store
3813
+ if (fileStreams.length > 0) {
3814
+ try {
3815
+ await client.beta.vectorStores.fileBatches.uploadAndPoll(vectorStoreId, {
3816
+ files: fileStreams,
3817
+ });
3818
+ if (this.options.isVerbose) {
3819
+ console.info(`✅ Uploaded ${fileStreams.length} files to vector store`);
3820
+ }
3821
+ }
3822
+ catch (error) {
3823
+ console.error('Error uploading files to vector store:', error);
3824
+ }
3825
+ }
3810
3826
  }
3811
- /**/
3812
- // alert('!!!! Creating new OpenAI assistant');
3813
- // 3️⃣ Create assistant with uploaded files
3814
- const assistant = await client.beta.assistants.create({
3827
+ // Create assistant with vector store attached
3828
+ const assistantConfig = {
3815
3829
  name,
3816
3830
  description: 'Assistant created via Promptbook',
3817
3831
  model: 'gpt-4o',
3818
3832
  instructions,
3819
3833
  tools: [/* TODO: [🧠] Maybe add { type: 'code_interpreter' }, */ { type: 'file_search' }],
3820
- // !!!! file_ids: uploadedFiles,
3821
- });
3834
+ };
3835
+ // Attach vector store if created
3836
+ if (vectorStoreId) {
3837
+ assistantConfig.tool_resources = {
3838
+ file_search: {
3839
+ vector_store_ids: [vectorStoreId],
3840
+ },
3841
+ };
3842
+ }
3843
+ const assistant = await client.beta.assistants.create(assistantConfig);
3822
3844
  console.log(`✅ Assistant created: ${assistant.id}`);
3823
3845
  // TODO: !!!! Try listing existing assistants
3824
3846
  // TODO: !!!! Try marking existing assistants by DISCRIMINANT