@promptbook/openai 0.103.0-37 → 0.103.0-40

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 (44) hide show
  1. package/README.md +7 -9
  2. package/esm/index.es.js +39 -11
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/books/index.d.ts +0 -81
  5. package/esm/typings/src/_packages/core.index.d.ts +12 -10
  6. package/esm/typings/src/_packages/node.index.d.ts +4 -2
  7. package/esm/typings/src/_packages/types.index.d.ts +3 -1
  8. package/esm/typings/src/book-components/_common/Modal/Modal.d.ts +1 -1
  9. package/esm/typings/src/cli/cli-commands/start-agents-server.d.ts +14 -0
  10. package/esm/typings/src/cli/cli-commands/{start-server.d.ts → start-pipelines-server.d.ts} +2 -2
  11. package/esm/typings/src/collection/agent-collection/AgentCollection.d.ts +36 -0
  12. package/esm/typings/src/collection/agent-collection/constructors/AgentCollectionInDirectory.d.ts +88 -0
  13. package/esm/typings/src/collection/{PipelineCollection.d.ts → pipeline-collection/PipelineCollection.d.ts} +7 -3
  14. package/esm/typings/src/collection/{SimplePipelineCollection.d.ts → pipeline-collection/SimplePipelineCollection.d.ts} +5 -5
  15. package/esm/typings/src/collection/{constructors/createCollectionFromDirectory.d.ts → pipeline-collection/constructors/createPipelineCollectionFromDirectory.d.ts} +8 -10
  16. package/esm/typings/src/collection/pipeline-collection/constructors/createPipelineCollectionFromJson.d.ts +13 -0
  17. package/esm/typings/src/collection/{constructors/createCollectionFromPromise.d.ts → pipeline-collection/constructors/createPipelineCollectionFromPromise.d.ts} +6 -5
  18. package/esm/typings/src/collection/pipeline-collection/constructors/createPipelineCollectionFromPromise.test.d.ts +1 -0
  19. package/esm/typings/src/collection/{constructors/createCollectionFromUrl.d.ts → pipeline-collection/constructors/createPipelineCollectionFromUrl.d.ts} +3 -3
  20. package/esm/typings/src/collection/{constructors/createSubcollection.d.ts → pipeline-collection/constructors/createPipelineSubcollection.d.ts} +3 -3
  21. package/esm/typings/src/collection/pipeline-collection/pipelineCollectionToJson.d.ts +13 -0
  22. package/esm/typings/src/config.d.ts +8 -1
  23. package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
  24. package/esm/typings/src/execution/LlmExecutionTools.d.ts +6 -0
  25. package/esm/typings/src/llm-providers/agent/Agent.d.ts +6 -1
  26. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +9 -4
  27. package/esm/typings/src/llm-providers/agent/createAgentLlmExecutionTools.d.ts +0 -4
  28. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +17 -1
  29. package/esm/typings/src/other/templates/getTemplatesPipelineCollection.d.ts +1 -1
  30. package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -1
  31. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +22 -8
  32. package/esm/typings/src/transpilers/formatted-book-in-markdown/register.d.ts +1 -1
  33. package/esm/typings/src/utils/files/listAllFiles.d.ts +2 -3
  34. package/esm/typings/src/version.d.ts +1 -1
  35. package/esm/typings/src/wizard/$getCompiledBook.d.ts +1 -2
  36. package/package.json +4 -3
  37. package/umd/index.umd.js +42 -15
  38. package/umd/index.umd.js.map +1 -1
  39. package/esm/typings/src/collection/collectionToJson.d.ts +0 -13
  40. package/esm/typings/src/collection/constructors/createCollectionFromJson.d.ts +0 -13
  41. /package/esm/typings/src/collection/{constructors/createCollectionFromDirectory.test.d.ts → agent-collection/constructors/AgentCollectionInDirectory.test.d.ts} +0 -0
  42. /package/esm/typings/src/collection/{constructors/createCollectionFromJson.test.d.ts → pipeline-collection/constructors/createPipelineCollectionFromDirectory.test.d.ts} +0 -0
  43. /package/esm/typings/src/collection/{constructors/createCollectionFromPromise.test.d.ts → pipeline-collection/constructors/createPipelineCollectionFromJson.test.d.ts} +0 -0
  44. /package/esm/typings/src/collection/{collectionToJson.test.d.ts → pipeline-collection/pipelineCollectionToJson.test.d.ts} +0 -0
@@ -1,17 +1,13 @@
1
1
  import type { Request, Response } from 'express';
2
2
  import type { Promisable } from 'type-fest';
3
- import type { PipelineCollection } from '../../collection/PipelineCollection';
3
+ import { really_any } from '../../_packages/types.index';
4
+ import type { PipelineCollection } from '../../collection/pipeline-collection/PipelineCollection';
4
5
  import { AuthenticationError } from '../../errors/AuthenticationError';
5
6
  import type { CommonToolsOptions } from '../../execution/CommonToolsOptions';
6
7
  import type { ExecutionTools } from '../../execution/ExecutionTools';
7
8
  import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
8
- import type { string_app_id } from '../../types/typeAliases';
9
- import type { string_email } from '../../types/typeAliases';
10
- import type { string_password } from '../../types/typeAliases';
11
- import type { string_token } from '../../types/typeAliases';
12
- import type { string_user_id } from '../../types/typeAliases';
13
- import type { ApplicationModeIdentification } from '../socket-types/_subtypes/Identification';
14
- import type { Identification } from '../socket-types/_subtypes/Identification';
9
+ import type { string_app_id, string_email, string_password, string_token, string_user_id } from '../../types/typeAliases';
10
+ import type { ApplicationModeIdentification, Identification } from '../socket-types/_subtypes/Identification';
15
11
  /**
16
12
  * Options for configuring the Promptbook remote server.
17
13
  *
@@ -31,6 +27,24 @@ export type RemoteServerOptions<TCustomOptions> = CommonToolsOptions & {
31
27
  * @property {number} port The port number the server will listen on.
32
28
  */
33
29
  readonly port: number;
30
+ /**
31
+ * CORS options to apply to all endpoints (REST, UI, socket.io, etc.).
32
+ * Accepts the same options as the `cors` npm package and socket.io's CORS config.
33
+ * If not provided, defaults to permissive CORS (origin: '*').
34
+ * @see https://www.npmjs.com/package/cors
35
+ * @see https://socket.io/docs/v4/server-options/#cors
36
+ */
37
+ readonly cors?: {
38
+ origin?: string | string[] | boolean;
39
+ methods?: string | string[];
40
+ allowedHeaders?: string | string[];
41
+ exposedHeaders?: string | string[];
42
+ credentials?: boolean;
43
+ maxAge?: number;
44
+ preflightContinue?: boolean;
45
+ optionsSuccessStatus?: number;
46
+ [key: string]: really_any;
47
+ };
34
48
  /**
35
49
  * Enable rich UI (React + Tailwind) at `/` path.
36
50
  * Default: true
@@ -7,7 +7,7 @@ import { Registration } from '../../_packages/types.index';
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 _FormattedBookInMarkdownTranspilerRegistration: Registration;
13
13
  /**
@@ -1,13 +1,12 @@
1
1
  import type { FilesystemTools } from '../../execution/FilesystemTools';
2
- import type { string_dirname } from '../../types/typeAliases';
3
- import type { string_filename } from '../../types/typeAliases';
2
+ import type { string_dirname, string_filename } from '../../types/typeAliases';
4
3
  /**
5
4
  * Reads all files in the directory
6
5
  *
7
6
  * @param path
8
7
  * @param isRecursive
9
8
  * @returns List of all files in the directory
10
- * @private internal function of `createCollectionFromDirectory`
9
+ * @private internal function of `AgentCollectionInDirectory` and `createPipelineCollectionFromDirectory`
11
10
  */
12
11
  export declare function listAllFiles(path: string_dirname, isRecursive: boolean, fs: FilesystemTools): Promise<Array<string_filename>>;
13
12
  /**
@@ -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-36`).
18
+ * It follows semantic versioning (e.g., `0.103.0-39`).
19
19
  *
20
20
  * @generated
21
21
  */
@@ -2,8 +2,7 @@ import type { ExecutionTools } from '../execution/ExecutionTools';
2
2
  import type { PipelineJson } from '../pipeline/PipelineJson/PipelineJson';
3
3
  import type { PipelineString } from '../pipeline/PipelineString';
4
4
  import type { PrepareAndScrapeOptions } from '../prepare/PrepareAndScrapeOptions';
5
- import type { string_filename } from '../types/typeAliases';
6
- import type { string_pipeline_url } from '../types/typeAliases';
5
+ import type { string_filename, string_pipeline_url } from '../types/typeAliases';
7
6
  /**
8
7
  * @see ./wizard.ts `getPipeline` method
9
8
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/openai",
3
- "version": "0.103.0-37",
3
+ "version": "0.103.0-40",
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-37"
105
+ "@promptbook/core": "0.103.0-40"
106
106
  },
107
107
  "dependencies": {
108
108
  "bottleneck": "2.19.5",
@@ -110,6 +110,7 @@
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"
113
+ "spacetrim": "0.11.60",
114
+ "waitasecond": "1.11.160"
114
115
  }
115
116
  }
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('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';
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';
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-37';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-40';
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
@@ -3632,6 +3632,12 @@
3632
3632
  *
3633
3633
  * This is useful for calling OpenAI API with a single assistant, for more wide usage use `OpenAiExecutionTools`.
3634
3634
  *
3635
+ * Note: [🦖] There are several different things in Promptbook:
3636
+ * - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
3637
+ * - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
3638
+ * - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
3639
+ * - `OpenAiAssistantExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities, recommended for usage in `Agent` or `AgentLlmExecutionTools`
3640
+ *
3635
3641
  * @public exported from `@promptbook/openai`
3636
3642
  */
3637
3643
  class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
@@ -3797,10 +3803,32 @@
3797
3803
  },
3798
3804
  });
3799
3805
  }
3800
- async createNewAssistant() {
3806
+ async playground() {
3807
+ const client = await this.getClient();
3808
+ // List all assistants
3809
+ const assistants = await client.beta.assistants.list();
3810
+ console.log('!!! Assistants:', assistants);
3811
+ // Get details of a specific assistant
3812
+ const assistantId = 'asst_MO8fhZf4dGloCfXSHeLcIik0';
3813
+ const assistant = await client.beta.assistants.retrieve(assistantId);
3814
+ console.log('!!! Assistant Details:', assistant);
3815
+ // Update an assistant
3816
+ const updatedAssistant = await client.beta.assistants.update(assistantId, {
3817
+ name: assistant.name + '(M)',
3818
+ description: 'Updated description via Promptbook',
3819
+ metadata: {
3820
+ [Math.random().toString(36).substring(2, 15)]: new Date().toISOString(),
3821
+ },
3822
+ });
3823
+ console.log('!!! Updated Assistant:', updatedAssistant);
3824
+ await waitasecond.forEver();
3825
+ }
3826
+ async createNewAssistant(options) {
3801
3827
  if (!this.isCreatingNewAssistantsAllowed) {
3802
3828
  throw new NotAllowed(`Creating new assistants is not allowed. Set \`isCreatingNewAssistantsAllowed: true\` in options to enable this feature.`);
3803
3829
  }
3830
+ await this.playground();
3831
+ const { name, instructions } = options;
3804
3832
  const client = await this.getClient();
3805
3833
  /*
3806
3834
  TODO: !!!
@@ -3848,21 +3876,20 @@
3848
3876
  uploadedFiles.push(file.id);
3849
3877
  }
3850
3878
  */
3879
+ alert('!!!! Creating new OpenAI assistant');
3851
3880
  // 3️⃣ Create assistant with uploaded files
3852
3881
  const assistant = await client.beta.assistants.create({
3853
- name: 'Next.js documentation assistant',
3854
- description: 'Assistant that can answer questions about Next.js and working with APIs.',
3882
+ name,
3883
+ description: 'Assistant created via Promptbook',
3855
3884
  model: 'gpt-4o',
3856
- instructions: spaceTrim__default["default"](`
3857
- Answer clearly and comprehensively.
3858
- Quote parts from uploaded files if needed.
3859
- `),
3860
- // <- TODO: !!!! Generate the `instructions` from passed `agentSource` (generate outside of this class)
3861
- tools: [{ type: 'code_interpreter' }, { type: 'file_search' }],
3885
+ instructions,
3886
+ tools: [/* TODO: [🧠] Maybe add { type: 'code_interpreter' }, */ { type: 'file_search' }],
3862
3887
  // !!!! file_ids: uploadedFiles,
3863
3888
  });
3864
- // TODO: !!!! Change Czech to English
3865
3889
  console.log(`✅ Assistant created: ${assistant.id}`);
3890
+ // TODO: !!!! Try listing existing assistants
3891
+ // TODO: !!!! Try marking existing assistants by DISCRIMINANT
3892
+ // TODO: !!!! Allow to update and reconnect to existing assistants
3866
3893
  return new OpenAiAssistantExecutionTools({
3867
3894
  ...this.options,
3868
3895
  isCreatingNewAssistantsAllowed: false,