@promptbook/openai 0.103.0-46 → 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.
- package/esm/index.es.js +196 -71
- 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 +22 -14
- package/esm/typings/src/_packages/types.index.d.ts +14 -6
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +7 -3
- 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 +3 -2
- package/esm/typings/src/book-2.0/agent-source/computeAgentHash.d.ts +8 -0
- package/esm/typings/src/book-2.0/agent-source/computeAgentHash.test.d.ts +1 -0
- package/esm/typings/src/book-2.0/agent-source/createCommitmentRegex.d.ts +1 -1
- package/esm/typings/src/book-2.0/agent-source/createDefaultAgentName.d.ts +8 -0
- package/esm/typings/src/book-2.0/agent-source/normalizeAgentName.d.ts +9 -0
- package/esm/typings/src/book-2.0/agent-source/normalizeAgentName.test.d.ts +1 -0
- package/esm/typings/src/book-2.0/agent-source/parseAgentSourceWithCommitments.d.ts +1 -1
- 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 +1 -60
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +57 -32
- 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/execution/LlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/utils/assertUniqueModels.d.ts +12 -0
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +10 -9
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +5 -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 +29 -4
- package/esm/typings/src/llm-providers/openai/openai-models.test.d.ts +4 -0
- package/esm/typings/src/remote-server/startAgentServer.d.ts +1 -1
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -2
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -0
- package/esm/typings/src/transpilers/openai-sdk/register.d.ts +1 -1
- package/esm/typings/src/types/typeAliases.d.ts +12 -0
- package/esm/typings/src/utils/color/internal-utils/checkChannelValue.d.ts +0 -3
- package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +2 -0
- package/esm/typings/src/utils/normalization/normalizeTo_PascalCase.d.ts +3 -0
- package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +2 -0
- package/esm/typings/src/utils/normalization/titleToName.d.ts +2 -0
- 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/version.d.ts +1 -1
- package/package.json +3 -4
- package/umd/index.umd.js +201 -75
- 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/umd/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'colors', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-openai"] = {}, global.colors, global.
|
|
5
|
-
})(this, (function (exports, colors,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('spacetrim'), require('crypto'), require('bottleneck'), require('openai'), require('socket.io-client')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'colors', 'spacetrim', 'crypto', 'bottleneck', 'openai', 'socket.io-client'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-openai"] = {}, global.colors, global.spaceTrim, global.crypto, global.Bottleneck, global.OpenAI, global.socket_ioClient));
|
|
5
|
+
})(this, (function (exports, colors, spaceTrim, crypto, Bottleneck, OpenAI, socket_ioClient) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -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-
|
|
28
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-48';
|
|
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
|
|
@@ -2369,17 +2366,17 @@
|
|
|
2369
2366
|
},
|
|
2370
2367
|
/**/
|
|
2371
2368
|
/*/
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2369
|
+
{
|
|
2370
|
+
modelTitle: 'tts-1-hd-1106',
|
|
2371
|
+
modelName: 'tts-1-hd-1106',
|
|
2372
|
+
},
|
|
2373
|
+
/**/
|
|
2377
2374
|
/*/
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2375
|
+
{
|
|
2376
|
+
modelTitle: 'tts-1-hd',
|
|
2377
|
+
modelName: 'tts-1-hd',
|
|
2378
|
+
},
|
|
2379
|
+
/**/
|
|
2383
2380
|
/**/
|
|
2384
2381
|
{
|
|
2385
2382
|
modelVariant: 'CHAT',
|
|
@@ -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
|
-
|
|
3676
|
-
|
|
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
|
-
|
|
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);
|
|
@@ -3736,15 +3737,19 @@
|
|
|
3736
3737
|
},
|
|
3737
3738
|
});
|
|
3738
3739
|
}
|
|
3739
|
-
|
|
3740
|
+
/*
|
|
3741
|
+
public async playground() {
|
|
3740
3742
|
const client = await this.getClient();
|
|
3743
|
+
|
|
3741
3744
|
// List all assistants
|
|
3742
3745
|
const assistants = await client.beta.assistants.list();
|
|
3743
3746
|
console.log('!!! Assistants:', assistants);
|
|
3747
|
+
|
|
3744
3748
|
// Get details of a specific assistant
|
|
3745
3749
|
const assistantId = 'asst_MO8fhZf4dGloCfXSHeLcIik0';
|
|
3746
3750
|
const assistant = await client.beta.assistants.retrieve(assistantId);
|
|
3747
3751
|
console.log('!!! Assistant Details:', assistant);
|
|
3752
|
+
|
|
3748
3753
|
// Update an assistant
|
|
3749
3754
|
const updatedAssistant = await client.beta.assistants.update(assistantId, {
|
|
3750
3755
|
name: assistant.name + '(M)',
|
|
@@ -3754,71 +3759,103 @@
|
|
|
3754
3759
|
},
|
|
3755
3760
|
});
|
|
3756
3761
|
console.log('!!! Updated Assistant:', updatedAssistant);
|
|
3757
|
-
|
|
3762
|
+
|
|
3763
|
+
await forEver();
|
|
3764
|
+
}
|
|
3765
|
+
*/
|
|
3766
|
+
/**
|
|
3767
|
+
* Get an existing assistant tool wrapper
|
|
3768
|
+
*/
|
|
3769
|
+
getAssistant(assistantId) {
|
|
3770
|
+
return new OpenAiAssistantExecutionTools({
|
|
3771
|
+
...this.options,
|
|
3772
|
+
assistantId,
|
|
3773
|
+
});
|
|
3758
3774
|
}
|
|
3759
3775
|
async createNewAssistant(options) {
|
|
3760
3776
|
if (!this.isCreatingNewAssistantsAllowed) {
|
|
3761
3777
|
throw new NotAllowed(`Creating new assistants is not allowed. Set \`isCreatingNewAssistantsAllowed: true\` in options to enable this feature.`);
|
|
3762
3778
|
}
|
|
3763
3779
|
// await this.playground();
|
|
3764
|
-
const { name, instructions } = options;
|
|
3780
|
+
const { name, instructions, knowledgeSources } = options;
|
|
3765
3781
|
const client = await this.getClient();
|
|
3766
|
-
|
|
3767
|
-
//
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
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',
|
|
3782
|
+
let vectorStoreId;
|
|
3783
|
+
// If knowledge sources are provided, create a vector store with them
|
|
3784
|
+
if (knowledgeSources && knowledgeSources.length > 0) {
|
|
3785
|
+
if (this.options.isVerbose) {
|
|
3786
|
+
console.info(`📚 Creating vector store with ${knowledgeSources.length} knowledge sources...`);
|
|
3787
|
+
}
|
|
3788
|
+
// Create a vector store
|
|
3789
|
+
const vectorStore = await client.beta.vectorStores.create({
|
|
3790
|
+
name: `${name} Knowledge Base`,
|
|
3787
3791
|
});
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3792
|
+
vectorStoreId = vectorStore.id;
|
|
3793
|
+
if (this.options.isVerbose) {
|
|
3794
|
+
console.info(`✅ Vector store created: ${vectorStoreId}`);
|
|
3795
|
+
}
|
|
3796
|
+
// Upload files from knowledge sources to the vector store
|
|
3797
|
+
const fileStreams = [];
|
|
3798
|
+
for (const source of knowledgeSources) {
|
|
3799
|
+
try {
|
|
3800
|
+
// Check if it's a URL
|
|
3801
|
+
if (source.startsWith('http://') || source.startsWith('https://')) {
|
|
3802
|
+
// Download the file
|
|
3803
|
+
const response = await fetch(source);
|
|
3804
|
+
if (!response.ok) {
|
|
3805
|
+
console.error(`Failed to download ${source}: ${response.statusText}`);
|
|
3806
|
+
continue;
|
|
3807
|
+
}
|
|
3808
|
+
const buffer = await response.arrayBuffer();
|
|
3809
|
+
const filename = source.split('/').pop() || 'downloaded-file';
|
|
3810
|
+
const blob = new Blob([buffer]);
|
|
3811
|
+
const file = new File([blob], filename);
|
|
3812
|
+
fileStreams.push(file);
|
|
3813
|
+
}
|
|
3814
|
+
else {
|
|
3815
|
+
// Assume it's a local file path
|
|
3816
|
+
// Note: This will work in Node.js environment
|
|
3817
|
+
// For browser environments, this would need different handling
|
|
3818
|
+
const fs = await import('fs');
|
|
3819
|
+
const fileStream = fs.createReadStream(source);
|
|
3820
|
+
fileStreams.push(fileStream);
|
|
3821
|
+
}
|
|
3822
|
+
}
|
|
3823
|
+
catch (error) {
|
|
3824
|
+
console.error(`Error processing knowledge source ${source}:`, error);
|
|
3825
|
+
}
|
|
3826
|
+
}
|
|
3827
|
+
// Batch upload files to the vector store
|
|
3828
|
+
if (fileStreams.length > 0) {
|
|
3829
|
+
try {
|
|
3830
|
+
await client.beta.vectorStores.fileBatches.uploadAndPoll(vectorStoreId, {
|
|
3831
|
+
files: fileStreams,
|
|
3832
|
+
});
|
|
3833
|
+
if (this.options.isVerbose) {
|
|
3834
|
+
console.info(`✅ Uploaded ${fileStreams.length} files to vector store`);
|
|
3835
|
+
}
|
|
3836
|
+
}
|
|
3837
|
+
catch (error) {
|
|
3838
|
+
console.error('Error uploading files to vector store:', error);
|
|
3839
|
+
}
|
|
3840
|
+
}
|
|
3810
3841
|
}
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
// 3️⃣ Create assistant with uploaded files
|
|
3814
|
-
const assistant = await client.beta.assistants.create({
|
|
3842
|
+
// Create assistant with vector store attached
|
|
3843
|
+
const assistantConfig = {
|
|
3815
3844
|
name,
|
|
3816
3845
|
description: 'Assistant created via Promptbook',
|
|
3817
3846
|
model: 'gpt-4o',
|
|
3818
3847
|
instructions,
|
|
3819
3848
|
tools: [/* TODO: [🧠] Maybe add { type: 'code_interpreter' }, */ { type: 'file_search' }],
|
|
3820
|
-
|
|
3821
|
-
|
|
3849
|
+
};
|
|
3850
|
+
// Attach vector store if created
|
|
3851
|
+
if (vectorStoreId) {
|
|
3852
|
+
assistantConfig.tool_resources = {
|
|
3853
|
+
file_search: {
|
|
3854
|
+
vector_store_ids: [vectorStoreId],
|
|
3855
|
+
},
|
|
3856
|
+
};
|
|
3857
|
+
}
|
|
3858
|
+
const assistant = await client.beta.assistants.create(assistantConfig);
|
|
3822
3859
|
console.log(`✅ Assistant created: ${assistant.id}`);
|
|
3823
3860
|
// TODO: !!!! Try listing existing assistants
|
|
3824
3861
|
// TODO: !!!! Try marking existing assistants by DISCRIMINANT
|
|
@@ -3829,6 +3866,95 @@
|
|
|
3829
3866
|
assistantId: assistant.id,
|
|
3830
3867
|
});
|
|
3831
3868
|
}
|
|
3869
|
+
async updateAssistant(options) {
|
|
3870
|
+
if (!this.isCreatingNewAssistantsAllowed) {
|
|
3871
|
+
throw new NotAllowed(`Updating assistants is not allowed. Set \`isCreatingNewAssistantsAllowed: true\` in options to enable this feature.`);
|
|
3872
|
+
}
|
|
3873
|
+
const { assistantId, name, instructions, knowledgeSources } = options;
|
|
3874
|
+
const client = await this.getClient();
|
|
3875
|
+
let vectorStoreId;
|
|
3876
|
+
// If knowledge sources are provided, create a vector store with them
|
|
3877
|
+
// TODO: [🧠] Reuse vector store creation logic from createNewAssistant
|
|
3878
|
+
if (knowledgeSources && knowledgeSources.length > 0) {
|
|
3879
|
+
if (this.options.isVerbose) {
|
|
3880
|
+
console.info(`📚 Creating vector store for update with ${knowledgeSources.length} knowledge sources...`);
|
|
3881
|
+
}
|
|
3882
|
+
// Create a vector store
|
|
3883
|
+
const vectorStore = await client.beta.vectorStores.create({
|
|
3884
|
+
name: `${name} Knowledge Base`,
|
|
3885
|
+
});
|
|
3886
|
+
vectorStoreId = vectorStore.id;
|
|
3887
|
+
if (this.options.isVerbose) {
|
|
3888
|
+
console.info(`✅ Vector store created: ${vectorStoreId}`);
|
|
3889
|
+
}
|
|
3890
|
+
// Upload files from knowledge sources to the vector store
|
|
3891
|
+
const fileStreams = [];
|
|
3892
|
+
for (const source of knowledgeSources) {
|
|
3893
|
+
try {
|
|
3894
|
+
// Check if it's a URL
|
|
3895
|
+
if (source.startsWith('http://') || source.startsWith('https://')) {
|
|
3896
|
+
// Download the file
|
|
3897
|
+
const response = await fetch(source);
|
|
3898
|
+
if (!response.ok) {
|
|
3899
|
+
console.error(`Failed to download ${source}: ${response.statusText}`);
|
|
3900
|
+
continue;
|
|
3901
|
+
}
|
|
3902
|
+
const buffer = await response.arrayBuffer();
|
|
3903
|
+
const filename = source.split('/').pop() || 'downloaded-file';
|
|
3904
|
+
const blob = new Blob([buffer]);
|
|
3905
|
+
const file = new File([blob], filename);
|
|
3906
|
+
fileStreams.push(file);
|
|
3907
|
+
}
|
|
3908
|
+
else {
|
|
3909
|
+
// Assume it's a local file path
|
|
3910
|
+
// Note: This will work in Node.js environment
|
|
3911
|
+
// For browser environments, this would need different handling
|
|
3912
|
+
const fs = await import('fs');
|
|
3913
|
+
const fileStream = fs.createReadStream(source);
|
|
3914
|
+
fileStreams.push(fileStream);
|
|
3915
|
+
}
|
|
3916
|
+
}
|
|
3917
|
+
catch (error) {
|
|
3918
|
+
console.error(`Error processing knowledge source ${source}:`, error);
|
|
3919
|
+
}
|
|
3920
|
+
}
|
|
3921
|
+
// Batch upload files to the vector store
|
|
3922
|
+
if (fileStreams.length > 0) {
|
|
3923
|
+
try {
|
|
3924
|
+
await client.beta.vectorStores.fileBatches.uploadAndPoll(vectorStoreId, {
|
|
3925
|
+
files: fileStreams,
|
|
3926
|
+
});
|
|
3927
|
+
if (this.options.isVerbose) {
|
|
3928
|
+
console.info(`✅ Uploaded ${fileStreams.length} files to vector store`);
|
|
3929
|
+
}
|
|
3930
|
+
}
|
|
3931
|
+
catch (error) {
|
|
3932
|
+
console.error('Error uploading files to vector store:', error);
|
|
3933
|
+
}
|
|
3934
|
+
}
|
|
3935
|
+
}
|
|
3936
|
+
const assistantUpdate = {
|
|
3937
|
+
name,
|
|
3938
|
+
instructions,
|
|
3939
|
+
tools: [/* TODO: [🧠] Maybe add { type: 'code_interpreter' }, */ { type: 'file_search' }],
|
|
3940
|
+
};
|
|
3941
|
+
if (vectorStoreId) {
|
|
3942
|
+
assistantUpdate.tool_resources = {
|
|
3943
|
+
file_search: {
|
|
3944
|
+
vector_store_ids: [vectorStoreId],
|
|
3945
|
+
},
|
|
3946
|
+
};
|
|
3947
|
+
}
|
|
3948
|
+
const assistant = await client.beta.assistants.update(assistantId, assistantUpdate);
|
|
3949
|
+
if (this.options.isVerbose) {
|
|
3950
|
+
console.log(`✅ Assistant updated: ${assistant.id}`);
|
|
3951
|
+
}
|
|
3952
|
+
return new OpenAiAssistantExecutionTools({
|
|
3953
|
+
...this.options,
|
|
3954
|
+
isCreatingNewAssistantsAllowed: false,
|
|
3955
|
+
assistantId: assistant.id,
|
|
3956
|
+
});
|
|
3957
|
+
}
|
|
3832
3958
|
/**
|
|
3833
3959
|
* Discriminant for type guards
|
|
3834
3960
|
*/
|