@promptbook/openai 0.103.0-48 → 0.103.0-50

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 (39) hide show
  1. package/esm/index.es.js +50 -22
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/servers.d.ts +1 -0
  4. package/esm/typings/src/_packages/components.index.d.ts +2 -0
  5. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  6. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  7. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +12 -2
  8. package/esm/typings/src/book-components/PromptbookAgent/PromptbookAgent.d.ts +20 -0
  9. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +14 -8
  10. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabaseOptions.d.ts +10 -0
  11. package/esm/typings/src/commitments/MESSAGE/InitialMessageCommitmentDefinition.d.ts +28 -0
  12. package/esm/typings/src/commitments/index.d.ts +2 -1
  13. package/esm/typings/src/config.d.ts +1 -0
  14. package/esm/typings/src/errors/DatabaseError.d.ts +2 -2
  15. package/esm/typings/src/errors/WrappedError.d.ts +2 -2
  16. package/esm/typings/src/execution/ExecutionTask.d.ts +2 -2
  17. package/esm/typings/src/execution/LlmExecutionTools.d.ts +6 -1
  18. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizardOrCli.d.ts +2 -2
  19. package/esm/typings/src/llm-providers/agent/Agent.d.ts +19 -3
  20. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +13 -1
  21. package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +11 -2
  22. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +6 -1
  23. package/esm/typings/src/remote-server/startAgentServer.d.ts +2 -2
  24. package/esm/typings/src/utils/color/Color.d.ts +7 -0
  25. package/esm/typings/src/utils/color/Color.test.d.ts +1 -0
  26. package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +2 -2
  27. package/esm/typings/src/utils/misc/computeHash.d.ts +11 -0
  28. package/esm/typings/src/utils/misc/computeHash.test.d.ts +1 -0
  29. package/esm/typings/src/utils/organization/$sideEffect.d.ts +2 -2
  30. package/esm/typings/src/utils/organization/$side_effect.d.ts +2 -2
  31. package/esm/typings/src/utils/organization/TODO_USE.d.ts +2 -2
  32. package/esm/typings/src/utils/organization/keepUnused.d.ts +2 -2
  33. package/esm/typings/src/utils/organization/preserve.d.ts +3 -3
  34. package/esm/typings/src/utils/organization/really_any.d.ts +7 -0
  35. package/esm/typings/src/utils/serialization/asSerializable.d.ts +2 -2
  36. package/esm/typings/src/version.d.ts +1 -1
  37. package/package.json +2 -2
  38. package/umd/index.umd.js +50 -22
  39. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -19,7 +19,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
19
19
  * @generated
20
20
  * @see https://github.com/webgptorg/promptbook
21
21
  */
22
- const PROMPTBOOK_ENGINE_VERSION = '0.103.0-48';
22
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-50';
23
23
  /**
24
24
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
25
25
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -574,6 +574,9 @@ class Color {
574
574
  if (hex.length === 3) {
575
575
  return Color.fromHex3(hex);
576
576
  }
577
+ if (hex.length === 4) {
578
+ return Color.fromHex4(hex);
579
+ }
577
580
  if (hex.length === 6) {
578
581
  return Color.fromHex6(hex);
579
582
  }
@@ -594,6 +597,19 @@ class Color {
594
597
  const b = parseInt(hex.substr(2, 1), 16) * 16;
595
598
  return take(new Color(r, g, b));
596
599
  }
600
+ /**
601
+ * Creates a new Color instance from color in hex format with 4 digits (with alpha channel)
602
+ *
603
+ * @param color in hex for example `09df`
604
+ * @returns Color object
605
+ */
606
+ static fromHex4(hex) {
607
+ const r = parseInt(hex.substr(0, 1), 16) * 16;
608
+ const g = parseInt(hex.substr(1, 1), 16) * 16;
609
+ const b = parseInt(hex.substr(2, 1), 16) * 16;
610
+ const a = parseInt(hex.substr(3, 1), 16) * 16;
611
+ return take(new Color(r, g, b, a));
612
+ }
597
613
  /**
598
614
  * Creates a new Color instance from color in hex format with 6 color digits (without alpha channel)
599
615
  *
@@ -784,7 +800,8 @@ class Color {
784
800
  * @returns true if the value is a valid hex color string (e.g., `#009edd`, `#fff`, etc.)
785
801
  */
786
802
  static isHexColorString(value) {
787
- return typeof value === 'string' && /^#(?:[0-9a-fA-F]{3}){1,2}$/.test(value);
803
+ return (typeof value === 'string' &&
804
+ /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(value));
788
805
  }
789
806
  /**
790
807
  * Creates new Color object
@@ -1091,6 +1108,7 @@ const PROMPTBOOK_COLOR = Color.fromHex('#79EAFD');
1091
1108
  ({
1092
1109
  TITLE: Color.fromHex('#244EA8'),
1093
1110
  LINE: Color.fromHex('#eeeeee'),
1111
+ SEPARATOR: Color.fromHex('#cccccc'),
1094
1112
  COMMITMENT: Color.fromHex('#DA0F78'),
1095
1113
  PARAMETER: Color.fromHex('#8e44ad'),
1096
1114
  });
@@ -1470,7 +1488,7 @@ function deepClone(objectValue) {
1470
1488
  TODO: [🧠] Is there a better implementation?
1471
1489
  > const propertyNames = Object.getOwnPropertyNames(objectValue);
1472
1490
  > for (const propertyName of propertyNames) {
1473
- > const value = (objectValue as really_any)[propertyName];
1491
+ > const value = (objectValue as chococake)[propertyName];
1474
1492
  > if (value && typeof value === 'object') {
1475
1493
  > deepClone(value);
1476
1494
  > }
@@ -3556,11 +3574,12 @@ class OpenAiExecutionTools extends OpenAiCompatibleExecutionTools {
3556
3574
  *
3557
3575
  * This is useful for calling OpenAI API with a single assistant, for more wide usage use `OpenAiExecutionTools`.
3558
3576
  *
3559
- * !!! Note: [🦖] There are several different things in Promptbook:
3577
+ * Note: [🦖] There are several different things in Promptbook:
3560
3578
  * - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
3561
3579
  * - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
3562
3580
  * - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
3563
3581
  * - `OpenAiAssistantExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities, recommended for usage in `Agent` or `AgentLlmExecutionTools`
3582
+ * - `RemoteAgent` - which is an `Agent` that connects to a Promptbook Agents Server
3564
3583
  *
3565
3584
  * @public exported from `@promptbook/openai`
3566
3585
  */
@@ -3595,6 +3614,12 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
3595
3614
  * Calls OpenAI API to use a chat model.
3596
3615
  */
3597
3616
  async callChatModel(prompt) {
3617
+ return this.callChatModelStream(prompt, () => { });
3618
+ }
3619
+ /**
3620
+ * Calls OpenAI API to use a chat model with streaming.
3621
+ */
3622
+ async callChatModelStream(prompt, onProgress) {
3598
3623
  var _a, _b, _c;
3599
3624
  if (this.options.isVerbose) {
3600
3625
  console.info('💬 OpenAI callChatModel call', { prompt });
@@ -3662,21 +3687,24 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
3662
3687
  console.info('connect', stream.currentEvent);
3663
3688
  }
3664
3689
  });
3665
- /*
3666
- stream.on('messageDelta', (messageDelta) => {
3667
- if (
3668
- this.options.isVerbose &&
3669
- messageDelta &&
3670
- messageDelta.content &&
3671
- messageDelta.content[0] &&
3672
- messageDelta.content[0].type === 'text'
3673
- ) {
3674
- console.info('messageDelta', messageDelta.content[0].text?.value);
3690
+ stream.on('textDelta', (textDelta, snapshot) => {
3691
+ if (this.options.isVerbose && textDelta.value) {
3692
+ console.info('textDelta', textDelta.value);
3675
3693
  }
3676
-
3677
- // <- TODO: [🐚] Make streaming and running tasks working
3694
+ const chunk = {
3695
+ content: textDelta.value || '',
3696
+ modelName: 'assistant',
3697
+ timing: {
3698
+ start,
3699
+ complete: $getCurrentDate(),
3700
+ },
3701
+ usage: UNCERTAIN_USAGE,
3702
+ rawPromptContent,
3703
+ rawRequest,
3704
+ rawResponse: snapshot,
3705
+ };
3706
+ onProgress(chunk);
3678
3707
  });
3679
- */
3680
3708
  stream.on('messageCreated', (message) => {
3681
3709
  if (this.options.isVerbose) {
3682
3710
  console.info('messageCreated', message);
@@ -3712,7 +3740,7 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
3712
3740
  }
3713
3741
  return exportJson({
3714
3742
  name: 'promptResult',
3715
- message: `Result of \`OpenAiAssistantExecutionTools.callChatModel\``,
3743
+ message: `Result of \`OpenAiAssistantExecutionTools.callChatModelStream\``,
3716
3744
  order: [],
3717
3745
  value: {
3718
3746
  content: resultContent,
@@ -3851,9 +3879,9 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
3851
3879
  }
3852
3880
  const assistant = await client.beta.assistants.create(assistantConfig);
3853
3881
  console.log(`✅ Assistant created: ${assistant.id}`);
3854
- // TODO: !!!! Try listing existing assistants
3855
- // TODO: !!!! Try marking existing assistants by DISCRIMINANT
3856
- // TODO: !!!! Allow to update and reconnect to existing assistants
3882
+ // TODO: [🐱‍🚀] Try listing existing assistants
3883
+ // TODO: [🐱‍🚀] Try marking existing assistants by DISCRIMINANT
3884
+ // TODO: [🐱‍🚀] Allow to update and reconnect to existing assistants
3857
3885
  return new OpenAiAssistantExecutionTools({
3858
3886
  ...this.options,
3859
3887
  isCreatingNewAssistantsAllowed: false,
@@ -4066,7 +4094,7 @@ class DatabaseError extends Error {
4066
4094
  }
4067
4095
  }
4068
4096
  /**
4069
- * TODO: !!!! Explain that NotFoundError (!!! and other specific errors) has priority over DatabaseError in some contexts
4097
+ * TODO: [🐱‍🚀] Explain that NotFoundError ([🐱‍🚀] and other specific errors) has priority over DatabaseError in some contexts
4070
4098
  */
4071
4099
 
4072
4100
  /**