@promptbook/openai 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.
- package/esm/index.es.js +116 -13
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +6 -0
- package/esm/typings/src/_packages/types.index.d.ts +2 -0
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +7 -3
- package/esm/typings/src/book-2.0/agent-source/AgentSourceParseResult.d.ts +2 -1
- 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/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/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +57 -32
- package/esm/typings/src/llm-providers/_common/utils/assertUniqueModels.d.ts +12 -0
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +7 -2
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +4 -0
- package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +2 -2
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +24 -3
- 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/transpilers/openai-sdk/register.d.ts +1 -1
- package/esm/typings/src/types/typeAliases.d.ts +6 -0
- 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/version.d.ts +1 -1
- package/package.json +3 -4
- package/umd/index.umd.js +121 -17
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import colors from 'colors';
|
|
2
|
-
import { forEver } from 'waitasecond';
|
|
3
2
|
import spaceTrim$1, { spaceTrim } from 'spacetrim';
|
|
4
3
|
import { randomBytes } from 'crypto';
|
|
5
4
|
import Bottleneck from 'bottleneck';
|
|
@@ -20,7 +19,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
20
19
|
* @generated
|
|
21
20
|
* @see https://github.com/webgptorg/promptbook
|
|
22
21
|
*/
|
|
23
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-
|
|
22
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-48';
|
|
24
23
|
/**
|
|
25
24
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
26
25
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -2361,17 +2360,17 @@ const OPENAI_MODELS = exportJson({
|
|
|
2361
2360
|
},
|
|
2362
2361
|
/**/
|
|
2363
2362
|
/*/
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2363
|
+
{
|
|
2364
|
+
modelTitle: 'tts-1-hd-1106',
|
|
2365
|
+
modelName: 'tts-1-hd-1106',
|
|
2366
|
+
},
|
|
2367
|
+
/**/
|
|
2369
2368
|
/*/
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2369
|
+
{
|
|
2370
|
+
modelTitle: 'tts-1-hd',
|
|
2371
|
+
modelName: 'tts-1-hd',
|
|
2372
|
+
},
|
|
2373
|
+
/**/
|
|
2375
2374
|
/**/
|
|
2376
2375
|
{
|
|
2377
2376
|
modelVariant: 'CHAT',
|
|
@@ -3732,15 +3731,19 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
3732
3731
|
},
|
|
3733
3732
|
});
|
|
3734
3733
|
}
|
|
3735
|
-
|
|
3734
|
+
/*
|
|
3735
|
+
public async playground() {
|
|
3736
3736
|
const client = await this.getClient();
|
|
3737
|
+
|
|
3737
3738
|
// List all assistants
|
|
3738
3739
|
const assistants = await client.beta.assistants.list();
|
|
3739
3740
|
console.log('!!! Assistants:', assistants);
|
|
3741
|
+
|
|
3740
3742
|
// Get details of a specific assistant
|
|
3741
3743
|
const assistantId = 'asst_MO8fhZf4dGloCfXSHeLcIik0';
|
|
3742
3744
|
const assistant = await client.beta.assistants.retrieve(assistantId);
|
|
3743
3745
|
console.log('!!! Assistant Details:', assistant);
|
|
3746
|
+
|
|
3744
3747
|
// Update an assistant
|
|
3745
3748
|
const updatedAssistant = await client.beta.assistants.update(assistantId, {
|
|
3746
3749
|
name: assistant.name + '(M)',
|
|
@@ -3750,8 +3753,19 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
3750
3753
|
},
|
|
3751
3754
|
});
|
|
3752
3755
|
console.log('!!! Updated Assistant:', updatedAssistant);
|
|
3756
|
+
|
|
3753
3757
|
await forEver();
|
|
3754
3758
|
}
|
|
3759
|
+
*/
|
|
3760
|
+
/**
|
|
3761
|
+
* Get an existing assistant tool wrapper
|
|
3762
|
+
*/
|
|
3763
|
+
getAssistant(assistantId) {
|
|
3764
|
+
return new OpenAiAssistantExecutionTools({
|
|
3765
|
+
...this.options,
|
|
3766
|
+
assistantId,
|
|
3767
|
+
});
|
|
3768
|
+
}
|
|
3755
3769
|
async createNewAssistant(options) {
|
|
3756
3770
|
if (!this.isCreatingNewAssistantsAllowed) {
|
|
3757
3771
|
throw new NotAllowed(`Creating new assistants is not allowed. Set \`isCreatingNewAssistantsAllowed: true\` in options to enable this feature.`);
|
|
@@ -3846,6 +3860,95 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
3846
3860
|
assistantId: assistant.id,
|
|
3847
3861
|
});
|
|
3848
3862
|
}
|
|
3863
|
+
async updateAssistant(options) {
|
|
3864
|
+
if (!this.isCreatingNewAssistantsAllowed) {
|
|
3865
|
+
throw new NotAllowed(`Updating assistants is not allowed. Set \`isCreatingNewAssistantsAllowed: true\` in options to enable this feature.`);
|
|
3866
|
+
}
|
|
3867
|
+
const { assistantId, name, instructions, knowledgeSources } = options;
|
|
3868
|
+
const client = await this.getClient();
|
|
3869
|
+
let vectorStoreId;
|
|
3870
|
+
// If knowledge sources are provided, create a vector store with them
|
|
3871
|
+
// TODO: [🧠] Reuse vector store creation logic from createNewAssistant
|
|
3872
|
+
if (knowledgeSources && knowledgeSources.length > 0) {
|
|
3873
|
+
if (this.options.isVerbose) {
|
|
3874
|
+
console.info(`📚 Creating vector store for update with ${knowledgeSources.length} knowledge sources...`);
|
|
3875
|
+
}
|
|
3876
|
+
// Create a vector store
|
|
3877
|
+
const vectorStore = await client.beta.vectorStores.create({
|
|
3878
|
+
name: `${name} Knowledge Base`,
|
|
3879
|
+
});
|
|
3880
|
+
vectorStoreId = vectorStore.id;
|
|
3881
|
+
if (this.options.isVerbose) {
|
|
3882
|
+
console.info(`✅ Vector store created: ${vectorStoreId}`);
|
|
3883
|
+
}
|
|
3884
|
+
// Upload files from knowledge sources to the vector store
|
|
3885
|
+
const fileStreams = [];
|
|
3886
|
+
for (const source of knowledgeSources) {
|
|
3887
|
+
try {
|
|
3888
|
+
// Check if it's a URL
|
|
3889
|
+
if (source.startsWith('http://') || source.startsWith('https://')) {
|
|
3890
|
+
// Download the file
|
|
3891
|
+
const response = await fetch(source);
|
|
3892
|
+
if (!response.ok) {
|
|
3893
|
+
console.error(`Failed to download ${source}: ${response.statusText}`);
|
|
3894
|
+
continue;
|
|
3895
|
+
}
|
|
3896
|
+
const buffer = await response.arrayBuffer();
|
|
3897
|
+
const filename = source.split('/').pop() || 'downloaded-file';
|
|
3898
|
+
const blob = new Blob([buffer]);
|
|
3899
|
+
const file = new File([blob], filename);
|
|
3900
|
+
fileStreams.push(file);
|
|
3901
|
+
}
|
|
3902
|
+
else {
|
|
3903
|
+
// Assume it's a local file path
|
|
3904
|
+
// Note: This will work in Node.js environment
|
|
3905
|
+
// For browser environments, this would need different handling
|
|
3906
|
+
const fs = await import('fs');
|
|
3907
|
+
const fileStream = fs.createReadStream(source);
|
|
3908
|
+
fileStreams.push(fileStream);
|
|
3909
|
+
}
|
|
3910
|
+
}
|
|
3911
|
+
catch (error) {
|
|
3912
|
+
console.error(`Error processing knowledge source ${source}:`, error);
|
|
3913
|
+
}
|
|
3914
|
+
}
|
|
3915
|
+
// Batch upload files to the vector store
|
|
3916
|
+
if (fileStreams.length > 0) {
|
|
3917
|
+
try {
|
|
3918
|
+
await client.beta.vectorStores.fileBatches.uploadAndPoll(vectorStoreId, {
|
|
3919
|
+
files: fileStreams,
|
|
3920
|
+
});
|
|
3921
|
+
if (this.options.isVerbose) {
|
|
3922
|
+
console.info(`✅ Uploaded ${fileStreams.length} files to vector store`);
|
|
3923
|
+
}
|
|
3924
|
+
}
|
|
3925
|
+
catch (error) {
|
|
3926
|
+
console.error('Error uploading files to vector store:', error);
|
|
3927
|
+
}
|
|
3928
|
+
}
|
|
3929
|
+
}
|
|
3930
|
+
const assistantUpdate = {
|
|
3931
|
+
name,
|
|
3932
|
+
instructions,
|
|
3933
|
+
tools: [/* TODO: [🧠] Maybe add { type: 'code_interpreter' }, */ { type: 'file_search' }],
|
|
3934
|
+
};
|
|
3935
|
+
if (vectorStoreId) {
|
|
3936
|
+
assistantUpdate.tool_resources = {
|
|
3937
|
+
file_search: {
|
|
3938
|
+
vector_store_ids: [vectorStoreId],
|
|
3939
|
+
},
|
|
3940
|
+
};
|
|
3941
|
+
}
|
|
3942
|
+
const assistant = await client.beta.assistants.update(assistantId, assistantUpdate);
|
|
3943
|
+
if (this.options.isVerbose) {
|
|
3944
|
+
console.log(`✅ Assistant updated: ${assistant.id}`);
|
|
3945
|
+
}
|
|
3946
|
+
return new OpenAiAssistantExecutionTools({
|
|
3947
|
+
...this.options,
|
|
3948
|
+
isCreatingNewAssistantsAllowed: false,
|
|
3949
|
+
assistantId: assistant.id,
|
|
3950
|
+
});
|
|
3951
|
+
}
|
|
3849
3952
|
/**
|
|
3850
3953
|
* Discriminant for type guards
|
|
3851
3954
|
*/
|