@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.
Files changed (31) hide show
  1. package/esm/index.es.js +116 -13
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/core.index.d.ts +6 -0
  4. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  5. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +7 -3
  6. package/esm/typings/src/book-2.0/agent-source/AgentSourceParseResult.d.ts +2 -1
  7. package/esm/typings/src/book-2.0/agent-source/computeAgentHash.d.ts +8 -0
  8. package/esm/typings/src/book-2.0/agent-source/computeAgentHash.test.d.ts +1 -0
  9. package/esm/typings/src/book-2.0/agent-source/createDefaultAgentName.d.ts +8 -0
  10. package/esm/typings/src/book-2.0/agent-source/normalizeAgentName.d.ts +9 -0
  11. package/esm/typings/src/book-2.0/agent-source/normalizeAgentName.test.d.ts +1 -0
  12. package/esm/typings/src/book-2.0/agent-source/parseAgentSourceWithCommitments.d.ts +1 -1
  13. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +57 -32
  14. package/esm/typings/src/llm-providers/_common/utils/assertUniqueModels.d.ts +12 -0
  15. package/esm/typings/src/llm-providers/agent/Agent.d.ts +7 -2
  16. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +4 -0
  17. package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +2 -2
  18. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +24 -3
  19. package/esm/typings/src/llm-providers/openai/openai-models.test.d.ts +4 -0
  20. package/esm/typings/src/remote-server/startAgentServer.d.ts +1 -1
  21. package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -2
  22. package/esm/typings/src/transpilers/openai-sdk/register.d.ts +1 -1
  23. package/esm/typings/src/types/typeAliases.d.ts +6 -0
  24. package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +2 -0
  25. package/esm/typings/src/utils/normalization/normalizeTo_PascalCase.d.ts +3 -0
  26. package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +2 -0
  27. package/esm/typings/src/utils/normalization/titleToName.d.ts +2 -0
  28. package/esm/typings/src/version.d.ts +1 -1
  29. package/package.json +3 -4
  30. package/umd/index.umd.js +121 -17
  31. package/umd/index.umd.js.map +1 -1
@@ -0,0 +1,8 @@
1
+ import { string_agent_hash } from '../../types/typeAliases';
2
+ import { string_book } from './string_book';
3
+ /**
4
+ * Computes SHA-256 hash of the agent source
5
+ *
6
+ * @public exported from `@promptbook/core`
7
+ */
8
+ export declare function computeAgentHash(agentSource: string_book): string_agent_hash;
@@ -0,0 +1,8 @@
1
+ import { string_agent_name } from '../../types/typeAliases';
2
+ import { string_book } from './string_book';
3
+ /**
4
+ * Creates temporary default agent name based on agent source hash
5
+ *
6
+ * @public exported from `@promptbook/core`
7
+ */
8
+ export declare function createDefaultAgentName(agentSource: string_book): string_agent_name;
@@ -0,0 +1,9 @@
1
+ import { string_agent_name } from '../../types/typeAliases';
2
+ /**
3
+ * Normalizes agent name from arbitrary string to valid agent name
4
+ *
5
+ * Note: [🔂] This function is idempotent.
6
+ *
7
+ * @public exported from `@promptbook/core`
8
+ */
9
+ export declare function normalizeAgentName(rawAgentName: string): string_agent_name;
@@ -6,4 +6,4 @@ import type { string_book } from './string_book';
6
6
  *
7
7
  * @private internal utility of `parseAgentSource`
8
8
  */
9
- export declare function parseAgentSourceWithCommitments(agentSource: string_book): AgentSourceParseResult;
9
+ export declare function parseAgentSourceWithCommitments(agentSource: string_book): Omit<AgentSourceParseResult, 'agentHash'>;
@@ -1,65 +1,90 @@
1
+ /**
2
+ * AUTO-GENERATED SUBSET TYPES FROM `/apps/agents-server/src/database/schema.ts`
3
+ * Source of truth: `/apps/agents-server/src/database/schema.sql` *(do not edit table structure here manually)*
4
+ *
5
+ * [💽] Prompt:
6
+ * Re-generate this sub-schema
7
+ * Generate Supabase TypeScript schema which is a subset of `AgentsServerDatabase`
8
+ * containing only tables `Agent` and `AgentHistory`
9
+ *
10
+ * NOTE: This file intentionally omits all other tables (EnvironmentVariable, ChatHistory, ChatFeedback)
11
+ * and any extra schemas (e.g. `graphql_public`) to remain a strict subset.
12
+ */
1
13
  export type Json = string | number | boolean | null | {
2
14
  [key: string]: Json | undefined;
3
15
  } | Json[];
4
16
  export type AgentsDatabaseSchema = {
5
- graphql_public: {
6
- Tables: {
7
- [_ in never]: never;
8
- };
9
- Views: {
10
- [_ in never]: never;
11
- };
12
- Functions: {
13
- graphql: {
14
- Args: {
15
- operationName?: string;
16
- query?: string;
17
- variables?: Json;
18
- extensions?: Json;
19
- };
20
- Returns: Json;
21
- };
22
- };
23
- Enums: {
24
- [_ in never]: never;
25
- };
26
- CompositeTypes: {
27
- [_ in never]: never;
28
- };
29
- };
30
17
  public: {
31
18
  Tables: {
32
- AgentCollection: {
19
+ Agent: {
33
20
  Row: {
34
21
  id: number;
35
22
  agentName: string;
36
- agentProfile: Json;
37
23
  createdAt: string;
38
24
  updatedAt: string | null;
39
- agentVersion: number;
25
+ agentHash: string;
26
+ agentSource: string;
27
+ agentProfile: Json;
40
28
  promptbookEngineVersion: string;
41
29
  usage: Json | null;
42
- agentSource: string;
30
+ preparedModelRequirements: Json | null;
31
+ preparedExternals: Json | null;
43
32
  };
44
33
  Insert: {
45
34
  id?: number;
46
35
  agentName: string;
47
36
  createdAt: string;
48
37
  updatedAt?: string | null;
49
- agentVersion: number;
38
+ agentHash: string;
39
+ agentSource: string;
40
+ agentProfile: Json;
50
41
  promptbookEngineVersion: string;
51
42
  usage?: Json | null;
52
- agentSource: string;
43
+ preparedModelRequirements?: Json | null;
44
+ preparedExternals?: Json | null;
53
45
  };
54
46
  Update: {
55
47
  id?: number;
56
48
  agentName?: string;
57
49
  createdAt?: string;
58
50
  updatedAt?: string | null;
59
- agentVersion?: number;
51
+ agentHash?: string;
52
+ agentSource?: string;
53
+ agentProfile?: Json;
60
54
  promptbookEngineVersion?: string;
61
55
  usage?: Json | null;
56
+ preparedModelRequirements?: Json | null;
57
+ preparedExternals?: Json | null;
58
+ };
59
+ Relationships: [];
60
+ };
61
+ AgentHistory: {
62
+ Row: {
63
+ id: number;
64
+ createdAt: string;
65
+ agentName: string;
66
+ agentHash: string;
67
+ previousAgentHash: string | null;
68
+ agentSource: string;
69
+ promptbookEngineVersion: string;
70
+ };
71
+ Insert: {
72
+ id?: number;
73
+ createdAt: string;
74
+ agentName: string;
75
+ agentHash: string;
76
+ previousAgentHash?: string | null;
77
+ agentSource: string;
78
+ promptbookEngineVersion: string;
79
+ };
80
+ Update: {
81
+ id?: number;
82
+ createdAt?: string;
83
+ agentName?: string;
84
+ agentHash?: string;
85
+ previousAgentHash?: string | null;
62
86
  agentSource?: string;
87
+ promptbookEngineVersion?: string;
63
88
  };
64
89
  Relationships: [];
65
90
  };
@@ -0,0 +1,12 @@
1
+ import { AvailableModel } from '../../../execution/AvailableModel';
2
+ /**
3
+ * Utility to assert that all models in the provided array have unique `modelName` values.
4
+ *
5
+ * This is internal utility for unit tests to ensure no duplicate model names exist.
6
+ *
7
+ * @private internal utility of unit tests
8
+ */
9
+ export declare function assertUniqueModels(models: ReadonlyArray<AvailableModel>): void;
10
+ /**
11
+ * Note: [⚪] This should never be in any released package
12
+ */
@@ -2,7 +2,7 @@ import { BehaviorSubject } from 'rxjs';
2
2
  import type { AgentBasicInformation, BookParameter } from '../../book-2.0/agent-source/AgentBasicInformation';
3
3
  import type { string_book } from '../../book-2.0/agent-source/string_book';
4
4
  import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
5
- import type { string_agent_name, string_url_image } from '../../types/typeAliases';
5
+ import type { string_agent_hash, string_agent_name, string_url_image } from '../../types/typeAliases';
6
6
  import { AgentLlmExecutionTools } from './AgentLlmExecutionTools';
7
7
  import type { AgentOptions } from './AgentOptions';
8
8
  /**
@@ -17,14 +17,19 @@ import type { AgentOptions } from './AgentOptions';
17
17
  * @public exported from `@promptbook/core`
18
18
  */
19
19
  export declare class Agent extends AgentLlmExecutionTools implements LlmExecutionTools, AgentBasicInformation {
20
+ private _agentName;
20
21
  /**
21
22
  * Name of the agent
22
23
  */
23
- agentName: string_agent_name | null;
24
+ get agentName(): string_agent_name;
24
25
  /**
25
26
  * Description of the agent
26
27
  */
27
28
  personaDescription: string | null;
29
+ /**
30
+ * Computed hash of the agent source for integrity verification
31
+ */
32
+ get agentHash(): string_agent_hash;
28
33
  /**
29
34
  * Metadata like image or color
30
35
  */
@@ -20,6 +20,10 @@ import type { CreateAgentLlmExecutionToolsOptions } from './CreateAgentLlmExecut
20
20
  */
21
21
  export declare class AgentLlmExecutionTools implements LlmExecutionTools {
22
22
  private readonly options;
23
+ /**
24
+ * Cache of OpenAI assistants to avoid creating duplicates
25
+ */
26
+ private static assistantCache;
23
27
  /**
24
28
  * Cached model requirements to avoid re-parsing the agent source
25
29
  */
@@ -5,9 +5,9 @@ import type { RemoteAgentOptions } from './RemoteAgentOptions';
5
5
  /**
6
6
  * Represents one AI Agent
7
7
  *
8
- * !!! Note: [🦖] There are several different things in Promptbook:
8
+ * !!!!!! Note: [🦖] There are several different things in Promptbook:
9
9
  * - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
10
- * !!!! `RemoteAgent`
10
+ * !!!!!! `RemoteAgent`
11
11
  * - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
12
12
  * - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
13
13
  * - `OpenAiAssistantExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities, recommended for usage in `Agent` or `AgentLlmExecutionTools`
@@ -1,7 +1,7 @@
1
1
  import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
2
2
  import type { ChatPromptResult } from '../../execution/PromptResult';
3
3
  import type { Prompt } from '../../types/Prompt';
4
- import type { string_markdown, string_markdown_text, string_title } from '../../types/typeAliases';
4
+ import type { string_markdown, string_markdown_text, string_title, string_token } from '../../types/typeAliases';
5
5
  import type { OpenAiAssistantExecutionToolsOptions } from './OpenAiAssistantExecutionToolsOptions';
6
6
  import { OpenAiExecutionTools } from './OpenAiExecutionTools';
7
7
  /**
@@ -18,7 +18,7 @@ import { OpenAiExecutionTools } from './OpenAiExecutionTools';
18
18
  * @public exported from `@promptbook/openai`
19
19
  */
20
20
  export declare class OpenAiAssistantExecutionTools extends OpenAiExecutionTools implements LlmExecutionTools {
21
- private readonly assistantId;
21
+ readonly assistantId: string_token;
22
22
  private readonly isCreatingNewAssistantsAllowed;
23
23
  /**
24
24
  * Creates OpenAI Execution Tools.
@@ -32,7 +32,10 @@ export declare class OpenAiAssistantExecutionTools extends OpenAiExecutionTools
32
32
  * Calls OpenAI API to use a chat model.
33
33
  */
34
34
  callChatModel(prompt: Pick<Prompt, 'content' | 'parameters' | 'modelRequirements' | 'format'>): Promise<ChatPromptResult>;
35
- playground(): Promise<void>;
35
+ /**
36
+ * Get an existing assistant tool wrapper
37
+ */
38
+ getAssistant(assistantId: string_token): OpenAiAssistantExecutionTools;
36
39
  createNewAssistant(options: {
37
40
  /**
38
41
  * Name of the new assistant
@@ -47,6 +50,24 @@ export declare class OpenAiAssistantExecutionTools extends OpenAiExecutionTools
47
50
  */
48
51
  readonly knowledgeSources?: ReadonlyArray<string>;
49
52
  }): Promise<OpenAiAssistantExecutionTools>;
53
+ updateAssistant(options: {
54
+ /**
55
+ * ID of the assistant to update
56
+ */
57
+ readonly assistantId: string_token;
58
+ /**
59
+ * Name of the assistant
60
+ */
61
+ readonly name?: string_title;
62
+ /**
63
+ * Instructions for the assistant
64
+ */
65
+ readonly instructions?: string_markdown;
66
+ /**
67
+ * Optional list of knowledge source links (URLs or file paths) to attach to the assistant via vector store
68
+ */
69
+ readonly knowledgeSources?: ReadonlyArray<string>;
70
+ }): Promise<OpenAiAssistantExecutionTools>;
50
71
  /**
51
72
  * Discriminant for type guards
52
73
  */
@@ -0,0 +1,4 @@
1
+ export {};
2
+ /**
3
+ * TODO: [🧠] Maybe do this test for all model providers + boilerplate
4
+ */
@@ -17,7 +17,7 @@ type AgentsServerOptions = {
17
17
  *
18
18
  * @see https://github.com/webgptorg/promptbook#remote-server
19
19
  * @public exported from `@promptbook/remote-server`
20
- * <- TODO: !!!! Maybe change to `@promptbook/agent-server`
20
+ * <- TODO: !!!! Change to `@promptbook/agent-server`
21
21
  */
22
22
  export declare function startAgentServer(options: AgentsServerOptions): Promise<TODO_any>;
23
23
  export {};
@@ -11,8 +11,7 @@ import type { RemoteServerOptions } from './types/RemoteServerOptions';
11
11
  */
12
12
  export declare function startRemoteServer<TCustomOptions = undefined>(options: RemoteServerOptions<TCustomOptions>): RemoteServer;
13
13
  /**
14
- * TODO !!!! Add agent
15
- * TODO: !!!! Allow to chat with agents directly via remote server
14
+
16
15
  * TODO: [🕋] Use here `aboutPromptbookInformation`
17
16
  * TODO: [🌡] Add CORS and security - probably via `helmet`
18
17
  * TODO: Split this file into multiple functions - handler for each request
@@ -7,7 +7,7 @@ import type { Registration } from '../../utils/misc/$Register';
7
7
  * @public exported from `@promptbook/wizard`
8
8
  * @public exported from `@promptbook/cli`
9
9
  *
10
- * TODO: !!!! Which package should export this?
10
+ * TODO: [🧠] Which package should export this?
11
11
  */
12
12
  export declare const _OpenAiSdkTranspilerRegistration: Registration;
13
13
  /**
@@ -148,6 +148,12 @@ export type string_agent_name = string;
148
148
  * For example `"My AI Assistant"`
149
149
  */
150
150
  export type string_agent_name_in_book = string;
151
+ /**
152
+ * Semantic helper
153
+ *
154
+ * For example `"b126926439c5fcb83609888a11283723c1ef137c0ad599a77a1be81812bd221d"`
155
+ */
156
+ export type string_agent_hash = string_sha256;
151
157
  /**
152
158
  * Unstructured description of the persona
153
159
  *
@@ -9,6 +9,8 @@ export type string_kebab_case = string;
9
9
  /**
10
10
  * Converts a given text to kebab-case format.
11
11
  *
12
+ * Note: [🔂] This function is idempotent.
13
+ *
12
14
  * @param text The text to be converted.
13
15
  * @returns The kebab-case formatted string.
14
16
  * @example 'hello-world'
@@ -7,6 +7,9 @@
7
7
  */
8
8
  export type string_PascalCase = string;
9
9
  /**
10
+ * Normalizes a given text to PascalCase format.
11
+ *
12
+ * Note: [🔂] This function is idempotent.
10
13
  *
11
14
  * @param text @public exported from `@promptbook/utils`
12
15
  * @returns
@@ -9,6 +9,8 @@ export type string_camelCase = string;
9
9
  /**
10
10
  * Normalizes a given text to camelCase format.
11
11
  *
12
+ * Note: [🔂] This function is idempotent.
13
+ *
12
14
  * @param text The text to be normalized.
13
15
  * @param _isFirstLetterCapital Whether the first letter should be capitalized.
14
16
  * @returns The camelCase formatted string.
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * Converts a title string into a normalized name.
3
3
  *
4
+ * Note: [🔂] This function is idempotent.
5
+ *
4
6
  * @param value The title string to be converted to a name.
5
7
  * @returns A normalized name derived from the input title.
6
8
  * @example 'Hello World!' -> 'hello-world'
@@ -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-46`).
18
+ * It follows semantic versioning (e.g., `0.103.0-47`).
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-47",
3
+ "version": "0.103.0-48",
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-47"
105
+ "@promptbook/core": "0.103.0-48"
106
106
  },
107
107
  "dependencies": {
108
108
  "bottleneck": "2.19.5",
@@ -110,7 +110,6 @@
110
110
  "crypto": "1.0.1",
111
111
  "openai": "4.63.0",
112
112
  "socket.io-client": "4.7.5",
113
- "spacetrim": "0.11.60",
114
- "waitasecond": "1.11.160"
113
+ "spacetrim": "0.11.60"
115
114
  }
116
115
  }
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('waitasecond'), require('spacetrim'), require('crypto'), require('bottleneck'), require('openai'), require('socket.io-client')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'colors', 'waitasecond', 'spacetrim', 'crypto', 'bottleneck', 'openai', 'socket.io-client'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-openai"] = {}, global.colors, global.waitasecond, global.spaceTrim, global.crypto, global.Bottleneck, global.OpenAI, global.socket_ioClient));
5
- })(this, (function (exports, colors, waitasecond, spaceTrim, crypto, Bottleneck, OpenAI, socket_ioClient) { 'use strict';
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-47';
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
@@ -2366,17 +2366,17 @@
2366
2366
  },
2367
2367
  /**/
2368
2368
  /*/
2369
- {
2370
- modelTitle: 'tts-1-hd-1106',
2371
- modelName: 'tts-1-hd-1106',
2372
- },
2373
- /**/
2369
+ {
2370
+ modelTitle: 'tts-1-hd-1106',
2371
+ modelName: 'tts-1-hd-1106',
2372
+ },
2373
+ /**/
2374
2374
  /*/
2375
- {
2376
- modelTitle: 'tts-1-hd',
2377
- modelName: 'tts-1-hd',
2378
- },
2379
- /**/
2375
+ {
2376
+ modelTitle: 'tts-1-hd',
2377
+ modelName: 'tts-1-hd',
2378
+ },
2379
+ /**/
2380
2380
  /**/
2381
2381
  {
2382
2382
  modelVariant: 'CHAT',
@@ -3737,15 +3737,19 @@
3737
3737
  },
3738
3738
  });
3739
3739
  }
3740
- async playground() {
3740
+ /*
3741
+ public async playground() {
3741
3742
  const client = await this.getClient();
3743
+
3742
3744
  // List all assistants
3743
3745
  const assistants = await client.beta.assistants.list();
3744
3746
  console.log('!!! Assistants:', assistants);
3747
+
3745
3748
  // Get details of a specific assistant
3746
3749
  const assistantId = 'asst_MO8fhZf4dGloCfXSHeLcIik0';
3747
3750
  const assistant = await client.beta.assistants.retrieve(assistantId);
3748
3751
  console.log('!!! Assistant Details:', assistant);
3752
+
3749
3753
  // Update an assistant
3750
3754
  const updatedAssistant = await client.beta.assistants.update(assistantId, {
3751
3755
  name: assistant.name + '(M)',
@@ -3755,7 +3759,18 @@
3755
3759
  },
3756
3760
  });
3757
3761
  console.log('!!! Updated Assistant:', updatedAssistant);
3758
- await waitasecond.forEver();
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
+ });
3759
3774
  }
3760
3775
  async createNewAssistant(options) {
3761
3776
  if (!this.isCreatingNewAssistantsAllowed) {
@@ -3851,6 +3866,95 @@
3851
3866
  assistantId: assistant.id,
3852
3867
  });
3853
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
+ }
3854
3958
  /**
3855
3959
  * Discriminant for type guards
3856
3960
  */