@promptbook/openai 0.103.0-45 → 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.
- package/esm/index.es.js +81 -59
- package/esm/index.es.js.map +1 -1
- package/esm/typings/servers.d.ts +1 -7
- package/esm/typings/src/_packages/components.index.d.ts +4 -0
- package/esm/typings/src/_packages/core.index.d.ts +16 -14
- package/esm/typings/src/_packages/types.index.d.ts +12 -6
- package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +6 -1
- package/esm/typings/src/book-2.0/agent-source/AgentSourceParseResult.d.ts +1 -1
- package/esm/typings/src/book-2.0/agent-source/createCommitmentRegex.d.ts +1 -1
- package/esm/typings/src/book-2.0/agent-source/padBook.d.ts +2 -0
- package/esm/typings/src/book-2.0/agent-source/string_book.d.ts +2 -0
- package/esm/typings/src/book-components/Chat/AgentChat/AgentChat.d.ts +14 -0
- package/esm/typings/src/book-components/Chat/AgentChat/AgentChat.test.d.ts +1 -0
- package/esm/typings/src/book-components/Chat/AgentChat/AgentChatProps.d.ts +13 -0
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +5 -60
- package/esm/typings/src/{book-2.0/commitments → commitments}/ACTION/ACTION.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/DELETE/DELETE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/FORMAT/FORMAT.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/GOAL/GOAL.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/KNOWLEDGE/KNOWLEDGE.d.ts +1 -5
- package/esm/typings/src/{book-2.0/commitments → commitments}/MEMORY/MEMORY.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/MESSAGE/MESSAGE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/META/META.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/META_IMAGE/META_IMAGE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/META_LINK/META_LINK.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/MODEL/MODEL.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/NOTE/NOTE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/PERSONA/PERSONA.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/RULE/RULE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/SAMPLE/SAMPLE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/SCENARIO/SCENARIO.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/STYLE/STYLE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/_base/BaseCommitmentDefinition.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/_base/CommitmentDefinition.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/_base/NotYetImplementedCommitmentDefinition.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/_base/createEmptyAgentModelRequirements.d.ts +1 -1
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +2 -0
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/execution/utils/validatePromptResult.d.ts +2 -0
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +3 -7
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/CreateAgentLlmExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +32 -0
- package/esm/typings/src/llm-providers/agent/RemoteAgentOptions.d.ts +11 -0
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +5 -1
- package/esm/typings/src/pipeline/validatePipelineString.d.ts +2 -0
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -0
- package/esm/typings/src/types/typeAliases.d.ts +6 -0
- package/esm/typings/src/utils/color/internal-utils/checkChannelValue.d.ts +0 -3
- package/esm/typings/src/utils/random/$generateBookBoilerplate.d.ts +2 -2
- package/esm/typings/src/utils/random/$randomFullnameWithColor.d.ts +1 -1
- package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +2 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +81 -59
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/{book-2.0/commitments → commitments}/_base/BookCommitment.d.ts +0 -0
- /package/esm/typings/src/{book-2.0/commitments → commitments}/_base/ParsedCommitment.d.ts +0 -0
- /package/esm/typings/src/{book-2.0/commitments → commitments}/index.d.ts +0 -0
package/esm/index.es.js
CHANGED
|
@@ -20,7 +20,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
20
20
|
* @generated
|
|
21
21
|
* @see https://github.com/webgptorg/promptbook
|
|
22
22
|
*/
|
|
23
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-
|
|
23
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-47';
|
|
24
24
|
/**
|
|
25
25
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
26
26
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -474,9 +474,6 @@ function checkChannelValue(channelName, value) {
|
|
|
474
474
|
throw new Error(`${channelName} channel is greater than 255, it is ${value}`);
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
|
-
/**
|
|
478
|
-
* TODO: [🧠][🚓] Is/which combination it better to use asserts/check, validate or is utility function?
|
|
479
|
-
*/
|
|
480
477
|
|
|
481
478
|
/**
|
|
482
479
|
* Color object represents an RGB color with alpha channel
|
|
@@ -3560,7 +3557,7 @@ class OpenAiExecutionTools extends OpenAiCompatibleExecutionTools {
|
|
|
3560
3557
|
*
|
|
3561
3558
|
* This is useful for calling OpenAI API with a single assistant, for more wide usage use `OpenAiExecutionTools`.
|
|
3562
3559
|
*
|
|
3563
|
-
* Note: [🦖] There are several different things in Promptbook:
|
|
3560
|
+
* !!! Note: [🦖] There are several different things in Promptbook:
|
|
3564
3561
|
* - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
|
|
3565
3562
|
* - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
|
|
3566
3563
|
* - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
|
|
@@ -3666,17 +3663,21 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
3666
3663
|
console.info('connect', stream.currentEvent);
|
|
3667
3664
|
}
|
|
3668
3665
|
});
|
|
3666
|
+
/*
|
|
3669
3667
|
stream.on('messageDelta', (messageDelta) => {
|
|
3670
|
-
|
|
3671
|
-
|
|
3668
|
+
if (
|
|
3669
|
+
this.options.isVerbose &&
|
|
3672
3670
|
messageDelta &&
|
|
3673
3671
|
messageDelta.content &&
|
|
3674
3672
|
messageDelta.content[0] &&
|
|
3675
|
-
messageDelta.content[0].type === 'text'
|
|
3676
|
-
|
|
3673
|
+
messageDelta.content[0].type === 'text'
|
|
3674
|
+
) {
|
|
3675
|
+
console.info('messageDelta', messageDelta.content[0].text?.value);
|
|
3677
3676
|
}
|
|
3677
|
+
|
|
3678
3678
|
// <- TODO: [🐚] Make streaming and running tasks working
|
|
3679
3679
|
});
|
|
3680
|
+
*/
|
|
3680
3681
|
stream.on('messageCreated', (message) => {
|
|
3681
3682
|
if (this.options.isVerbose) {
|
|
3682
3683
|
console.info('messageCreated', message);
|
|
@@ -3756,64 +3757,85 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
3756
3757
|
throw new NotAllowed(`Creating new assistants is not allowed. Set \`isCreatingNewAssistantsAllowed: true\` in options to enable this feature.`);
|
|
3757
3758
|
}
|
|
3758
3759
|
// await this.playground();
|
|
3759
|
-
const { name, instructions } = options;
|
|
3760
|
+
const { name, instructions, knowledgeSources } = options;
|
|
3760
3761
|
const client = await this.getClient();
|
|
3761
|
-
|
|
3762
|
-
//
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
if (!res.ok) throw new Error(`Download error: ${url}`);
|
|
3771
|
-
const buffer = await res.arrayBuffer();
|
|
3772
|
-
fs.writeFileSync(filepath, Buffer.from(buffer));
|
|
3773
|
-
console.log(`📥 File downloaded: ${filename}`);
|
|
3774
|
-
|
|
3775
|
-
return filepath;
|
|
3776
|
-
}
|
|
3777
|
-
|
|
3778
|
-
async function uploadFileToOpenAI(filepath: string) {
|
|
3779
|
-
const file = await client.files.create({
|
|
3780
|
-
file: fs.createReadStream(filepath),
|
|
3781
|
-
purpose: 'assistants',
|
|
3762
|
+
let vectorStoreId;
|
|
3763
|
+
// If knowledge sources are provided, create a vector store with them
|
|
3764
|
+
if (knowledgeSources && knowledgeSources.length > 0) {
|
|
3765
|
+
if (this.options.isVerbose) {
|
|
3766
|
+
console.info(`📚 Creating vector store with ${knowledgeSources.length} knowledge sources...`);
|
|
3767
|
+
}
|
|
3768
|
+
// Create a vector store
|
|
3769
|
+
const vectorStore = await client.beta.vectorStores.create({
|
|
3770
|
+
name: `${name} Knowledge Base`,
|
|
3782
3771
|
});
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3772
|
+
vectorStoreId = vectorStore.id;
|
|
3773
|
+
if (this.options.isVerbose) {
|
|
3774
|
+
console.info(`✅ Vector store created: ${vectorStoreId}`);
|
|
3775
|
+
}
|
|
3776
|
+
// Upload files from knowledge sources to the vector store
|
|
3777
|
+
const fileStreams = [];
|
|
3778
|
+
for (const source of knowledgeSources) {
|
|
3779
|
+
try {
|
|
3780
|
+
// Check if it's a URL
|
|
3781
|
+
if (source.startsWith('http://') || source.startsWith('https://')) {
|
|
3782
|
+
// Download the file
|
|
3783
|
+
const response = await fetch(source);
|
|
3784
|
+
if (!response.ok) {
|
|
3785
|
+
console.error(`Failed to download ${source}: ${response.statusText}`);
|
|
3786
|
+
continue;
|
|
3787
|
+
}
|
|
3788
|
+
const buffer = await response.arrayBuffer();
|
|
3789
|
+
const filename = source.split('/').pop() || 'downloaded-file';
|
|
3790
|
+
const blob = new Blob([buffer]);
|
|
3791
|
+
const file = new File([blob], filename);
|
|
3792
|
+
fileStreams.push(file);
|
|
3793
|
+
}
|
|
3794
|
+
else {
|
|
3795
|
+
// Assume it's a local file path
|
|
3796
|
+
// Note: This will work in Node.js environment
|
|
3797
|
+
// For browser environments, this would need different handling
|
|
3798
|
+
const fs = await import('fs');
|
|
3799
|
+
const fileStream = fs.createReadStream(source);
|
|
3800
|
+
fileStreams.push(fileStream);
|
|
3801
|
+
}
|
|
3802
|
+
}
|
|
3803
|
+
catch (error) {
|
|
3804
|
+
console.error(`Error processing knowledge source ${source}:`, error);
|
|
3805
|
+
}
|
|
3806
|
+
}
|
|
3807
|
+
// Batch upload files to the vector store
|
|
3808
|
+
if (fileStreams.length > 0) {
|
|
3809
|
+
try {
|
|
3810
|
+
await client.beta.vectorStores.fileBatches.uploadAndPoll(vectorStoreId, {
|
|
3811
|
+
files: fileStreams,
|
|
3812
|
+
});
|
|
3813
|
+
if (this.options.isVerbose) {
|
|
3814
|
+
console.info(`✅ Uploaded ${fileStreams.length} files to vector store`);
|
|
3815
|
+
}
|
|
3816
|
+
}
|
|
3817
|
+
catch (error) {
|
|
3818
|
+
console.error('Error uploading files to vector store:', error);
|
|
3819
|
+
}
|
|
3820
|
+
}
|
|
3805
3821
|
}
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
// 3️⃣ Create assistant with uploaded files
|
|
3809
|
-
const assistant = await client.beta.assistants.create({
|
|
3822
|
+
// Create assistant with vector store attached
|
|
3823
|
+
const assistantConfig = {
|
|
3810
3824
|
name,
|
|
3811
3825
|
description: 'Assistant created via Promptbook',
|
|
3812
3826
|
model: 'gpt-4o',
|
|
3813
3827
|
instructions,
|
|
3814
3828
|
tools: [/* TODO: [🧠] Maybe add { type: 'code_interpreter' }, */ { type: 'file_search' }],
|
|
3815
|
-
|
|
3816
|
-
|
|
3829
|
+
};
|
|
3830
|
+
// Attach vector store if created
|
|
3831
|
+
if (vectorStoreId) {
|
|
3832
|
+
assistantConfig.tool_resources = {
|
|
3833
|
+
file_search: {
|
|
3834
|
+
vector_store_ids: [vectorStoreId],
|
|
3835
|
+
},
|
|
3836
|
+
};
|
|
3837
|
+
}
|
|
3838
|
+
const assistant = await client.beta.assistants.create(assistantConfig);
|
|
3817
3839
|
console.log(`✅ Assistant created: ${assistant.id}`);
|
|
3818
3840
|
// TODO: !!!! Try listing existing assistants
|
|
3819
3841
|
// TODO: !!!! Try marking existing assistants by DISCRIMINANT
|