@promptbook/browser 0.103.0-48 → 0.103.0-49

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 (37) hide show
  1. package/esm/index.es.js +211 -4
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/servers.d.ts +1 -0
  4. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  5. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  6. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +12 -2
  7. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +14 -8
  8. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabaseOptions.d.ts +10 -0
  9. package/esm/typings/src/commitments/MESSAGE/InitialMessageCommitmentDefinition.d.ts +28 -0
  10. package/esm/typings/src/commitments/index.d.ts +2 -1
  11. package/esm/typings/src/config.d.ts +1 -0
  12. package/esm/typings/src/errors/DatabaseError.d.ts +2 -2
  13. package/esm/typings/src/errors/WrappedError.d.ts +2 -2
  14. package/esm/typings/src/execution/ExecutionTask.d.ts +2 -2
  15. package/esm/typings/src/execution/LlmExecutionTools.d.ts +6 -1
  16. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizardOrCli.d.ts +2 -2
  17. package/esm/typings/src/llm-providers/agent/Agent.d.ts +11 -3
  18. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +6 -1
  19. package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +6 -2
  20. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +6 -1
  21. package/esm/typings/src/remote-server/startAgentServer.d.ts +2 -2
  22. package/esm/typings/src/utils/color/Color.d.ts +7 -0
  23. package/esm/typings/src/utils/color/Color.test.d.ts +1 -0
  24. package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +2 -2
  25. package/esm/typings/src/utils/misc/computeHash.d.ts +11 -0
  26. package/esm/typings/src/utils/misc/computeHash.test.d.ts +1 -0
  27. package/esm/typings/src/utils/organization/$sideEffect.d.ts +2 -2
  28. package/esm/typings/src/utils/organization/$side_effect.d.ts +2 -2
  29. package/esm/typings/src/utils/organization/TODO_USE.d.ts +2 -2
  30. package/esm/typings/src/utils/organization/keepUnused.d.ts +2 -2
  31. package/esm/typings/src/utils/organization/preserve.d.ts +3 -3
  32. package/esm/typings/src/utils/organization/really_any.d.ts +7 -0
  33. package/esm/typings/src/utils/serialization/asSerializable.d.ts +2 -2
  34. package/esm/typings/src/version.d.ts +1 -1
  35. package/package.json +2 -2
  36. package/umd/index.umd.js +211 -4
  37. 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-49';
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
@@ -481,6 +481,9 @@ class Color {
481
481
  if (hex.length === 3) {
482
482
  return Color.fromHex3(hex);
483
483
  }
484
+ if (hex.length === 4) {
485
+ return Color.fromHex4(hex);
486
+ }
484
487
  if (hex.length === 6) {
485
488
  return Color.fromHex6(hex);
486
489
  }
@@ -501,6 +504,19 @@ class Color {
501
504
  const b = parseInt(hex.substr(2, 1), 16) * 16;
502
505
  return take(new Color(r, g, b));
503
506
  }
507
+ /**
508
+ * Creates a new Color instance from color in hex format with 4 digits (with alpha channel)
509
+ *
510
+ * @param color in hex for example `09df`
511
+ * @returns Color object
512
+ */
513
+ static fromHex4(hex) {
514
+ const r = parseInt(hex.substr(0, 1), 16) * 16;
515
+ const g = parseInt(hex.substr(1, 1), 16) * 16;
516
+ const b = parseInt(hex.substr(2, 1), 16) * 16;
517
+ const a = parseInt(hex.substr(3, 1), 16) * 16;
518
+ return take(new Color(r, g, b, a));
519
+ }
504
520
  /**
505
521
  * Creates a new Color instance from color in hex format with 6 color digits (without alpha channel)
506
522
  *
@@ -691,7 +707,8 @@ class Color {
691
707
  * @returns true if the value is a valid hex color string (e.g., `#009edd`, `#fff`, etc.)
692
708
  */
693
709
  static isHexColorString(value) {
694
- return typeof value === 'string' && /^#(?:[0-9a-fA-F]{3}){1,2}$/.test(value);
710
+ return (typeof value === 'string' &&
711
+ /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(value));
695
712
  }
696
713
  /**
697
714
  * Creates new Color object
@@ -998,6 +1015,7 @@ const PROMPTBOOK_COLOR = Color.fromHex('#79EAFD');
998
1015
  ({
999
1016
  TITLE: Color.fromHex('#244EA8'),
1000
1017
  LINE: Color.fromHex('#eeeeee'),
1018
+ SEPARATOR: Color.fromHex('#cccccc'),
1001
1019
  COMMITMENT: Color.fromHex('#DA0F78'),
1002
1020
  PARAMETER: Color.fromHex('#8e44ad'),
1003
1021
  });
@@ -1026,6 +1044,27 @@ Color.fromHex('#1D4ED8');
1026
1044
  * @private within the repository - too low-level in comparison with other `MAX_...`
1027
1045
  */
1028
1046
  const LOOP_LIMIT = 1000;
1047
+ /**
1048
+ * Strings to represent various values in the context of parameter values
1049
+ *
1050
+ * @public exported from `@promptbook/utils`
1051
+ */
1052
+ const VALUE_STRINGS = {
1053
+ empty: '(nothing; empty string)',
1054
+ null: '(no value; null)',
1055
+ undefined: '(unknown value; undefined)',
1056
+ nan: '(not a number; NaN)',
1057
+ infinity: '(infinity; ∞)',
1058
+ negativeInfinity: '(negative infinity; -∞)',
1059
+ unserializable: '(unserializable value)',
1060
+ circular: '(circular JSON)',
1061
+ };
1062
+ /**
1063
+ * Small number limit
1064
+ *
1065
+ * @public exported from `@promptbook/utils`
1066
+ */
1067
+ const SMALL_NUMBER = 0.001;
1029
1068
  // <- TODO: [🧜‍♂️]
1030
1069
  /**
1031
1070
  * Default settings for parsing and generating CSV files in Promptbook.
@@ -1672,7 +1711,7 @@ function deepClone(objectValue) {
1672
1711
  TODO: [🧠] Is there a better implementation?
1673
1712
  > const propertyNames = Object.getOwnPropertyNames(objectValue);
1674
1713
  > for (const propertyName of propertyNames) {
1675
- > const value = (objectValue as really_any)[propertyName];
1714
+ > const value = (objectValue as chococake)[propertyName];
1676
1715
  > if (value && typeof value === 'object') {
1677
1716
  > deepClone(value);
1678
1717
  > }
@@ -1991,13 +2030,106 @@ function generatePlaceholderAgentProfileImageUrl(agentName) {
1991
2030
  * TODO: [🤹] Figure out best placeholder image generator https://i.pravatar.cc/1000?u=568
1992
2031
  */
1993
2032
 
2033
+ /**
2034
+ * Format either small or big number
2035
+ *
2036
+ * @public exported from `@promptbook/utils`
2037
+ */
2038
+ function numberToString(value) {
2039
+ if (value === 0) {
2040
+ return '0';
2041
+ }
2042
+ else if (Number.isNaN(value)) {
2043
+ return VALUE_STRINGS.nan;
2044
+ }
2045
+ else if (value === Infinity) {
2046
+ return VALUE_STRINGS.infinity;
2047
+ }
2048
+ else if (value === -Infinity) {
2049
+ return VALUE_STRINGS.negativeInfinity;
2050
+ }
2051
+ for (let exponent = 0; exponent < 15; exponent++) {
2052
+ const factor = 10 ** exponent;
2053
+ const valueRounded = Math.round(value * factor) / factor;
2054
+ if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
2055
+ return valueRounded.toFixed(exponent);
2056
+ }
2057
+ }
2058
+ return value.toString();
2059
+ }
2060
+
2061
+ /**
2062
+ * Function `valueToString` will convert the given value to string
2063
+ * This is useful and used in the `templateParameters` function
2064
+ *
2065
+ * Note: This function is not just calling `toString` method
2066
+ * It's more complex and can handle this conversion specifically for LLM models
2067
+ * See `VALUE_STRINGS`
2068
+ *
2069
+ * Note: There are 2 similar functions
2070
+ * - `valueToString` converts value to string for LLM models as human-readable string
2071
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
2072
+ *
2073
+ * @public exported from `@promptbook/utils`
2074
+ */
2075
+ function valueToString(value) {
2076
+ try {
2077
+ if (value === '') {
2078
+ return VALUE_STRINGS.empty;
2079
+ }
2080
+ else if (value === null) {
2081
+ return VALUE_STRINGS.null;
2082
+ }
2083
+ else if (value === undefined) {
2084
+ return VALUE_STRINGS.undefined;
2085
+ }
2086
+ else if (typeof value === 'string') {
2087
+ return value;
2088
+ }
2089
+ else if (typeof value === 'number') {
2090
+ return numberToString(value);
2091
+ }
2092
+ else if (value instanceof Date) {
2093
+ return value.toISOString();
2094
+ }
2095
+ else {
2096
+ try {
2097
+ return JSON.stringify(value);
2098
+ }
2099
+ catch (error) {
2100
+ if (error instanceof TypeError && error.message.includes('circular structure')) {
2101
+ return VALUE_STRINGS.circular;
2102
+ }
2103
+ throw error;
2104
+ }
2105
+ }
2106
+ }
2107
+ catch (error) {
2108
+ assertsError(error);
2109
+ console.error(error);
2110
+ return VALUE_STRINGS.unserializable;
2111
+ }
2112
+ }
2113
+
2114
+ /**
2115
+ * Computes SHA-256 hash of the given object
2116
+ *
2117
+ * @public exported from `@promptbook/utils`
2118
+ */
2119
+ function computeHash(value) {
2120
+ return SHA256(hexEncoder.parse(spaceTrim$1(valueToString(value)))).toString( /* hex */);
2121
+ }
2122
+ /**
2123
+ * TODO: [🥬][🥬] Use this ACRY
2124
+ */
2125
+
1994
2126
  /**
1995
2127
  * Computes SHA-256 hash of the agent source
1996
2128
  *
1997
2129
  * @public exported from `@promptbook/core`
1998
2130
  */
1999
2131
  function computeAgentHash(agentSource) {
2000
- return SHA256(hexEncoder.parse(agentSource /* <- TODO: !!!!! spaceTrim */)).toString( /* hex */);
2132
+ return computeHash(agentSource);
2001
2133
  }
2002
2134
 
2003
2135
  /**
@@ -3183,6 +3315,60 @@ class MemoryCommitmentDefinition extends BaseCommitmentDefinition {
3183
3315
  * Note: [💞] Ignore a discrepancy between file name and entity name
3184
3316
  */
3185
3317
 
3318
+ /**
3319
+ * INITIAL MESSAGE commitment definition
3320
+ *
3321
+ * The INITIAL MESSAGE commitment defines the first message that the user sees when opening the chat.
3322
+ * It is used to greet the user and set the tone of the conversation.
3323
+ *
3324
+ * Example usage in agent source:
3325
+ *
3326
+ * ```book
3327
+ * INITIAL MESSAGE Hello! I am ready to help you with your tasks.
3328
+ * ```
3329
+ *
3330
+ * @private [🪔] Maybe export the commitments through some package
3331
+ */
3332
+ class InitialMessageCommitmentDefinition extends BaseCommitmentDefinition {
3333
+ constructor() {
3334
+ super('INITIAL MESSAGE');
3335
+ }
3336
+ /**
3337
+ * Short one-line description of INITIAL MESSAGE.
3338
+ */
3339
+ get description() {
3340
+ return 'Defines the **initial message** shown to the user when the chat starts.';
3341
+ }
3342
+ /**
3343
+ * Markdown documentation for INITIAL MESSAGE commitment.
3344
+ */
3345
+ get documentation() {
3346
+ return spaceTrim(`
3347
+ # ${this.type}
3348
+
3349
+ Defines the first message that the user sees when opening the chat. This message is purely for display purposes in the UI and does not inherently become part of the LLM's system prompt context (unless also included via other means).
3350
+
3351
+ ## Key aspects
3352
+
3353
+ - Used to greet the user.
3354
+ - Sets the tone of the conversation.
3355
+ - Displayed immediately when the chat interface loads.
3356
+
3357
+ ## Examples
3358
+
3359
+ \`\`\`book
3360
+ Support Agent
3361
+
3362
+ PERSONA You are a helpful support agent.
3363
+ INITIAL MESSAGE Hi there! How can I assist you today?
3364
+ \`\`\`
3365
+ `);
3366
+ }
3367
+ applyToAgentModelRequirements(requirements, content) {
3368
+ return requirements;
3369
+ }
3370
+ }
3371
+
3186
3372
  /**
3187
3373
  * MESSAGE commitment definition
3188
3374
  *
@@ -4344,6 +4530,7 @@ const COMMITMENT_REGISTRY = [
4344
4530
  new NoteCommitmentDefinition('NONCE'),
4345
4531
  new GoalCommitmentDefinition('GOAL'),
4346
4532
  new GoalCommitmentDefinition('GOALS'),
4533
+ new InitialMessageCommitmentDefinition(),
4347
4534
  new MessageCommitmentDefinition('MESSAGE'),
4348
4535
  new MessageCommitmentDefinition('MESSAGES'),
4349
4536
  new ScenarioCommitmentDefinition('SCENARIO'),
@@ -4548,13 +4735,31 @@ function parseAgentSource(agentSource) {
4548
4735
  }
4549
4736
  personaDescription += commitment.content;
4550
4737
  }
4738
+ let initialMessage = null;
4739
+ for (const commitment of parseResult.commitments) {
4740
+ if (commitment.type !== 'INITIAL MESSAGE') {
4741
+ continue;
4742
+ }
4743
+ // Note: Initial message override logic - later overrides earlier
4744
+ // Or should it append? Usually initial message is just one block.
4745
+ // Let's stick to "later overrides earlier" for simplicity, or just take the last one.
4746
+ initialMessage = commitment.content;
4747
+ }
4551
4748
  const meta = {};
4749
+ const links = [];
4552
4750
  for (const commitment of parseResult.commitments) {
4751
+ if (commitment.type === 'META LINK') {
4752
+ links.push(spaceTrim$1(commitment.content));
4753
+ continue;
4754
+ }
4553
4755
  if (commitment.type !== 'META') {
4554
4756
  continue;
4555
4757
  }
4556
4758
  // Parse META commitments - format is "META TYPE content"
4557
4759
  const metaTypeRaw = commitment.content.split(' ')[0] || 'NONE';
4760
+ if (metaTypeRaw === 'LINK') {
4761
+ links.push(spaceTrim$1(commitment.content.substring(metaTypeRaw.length)));
4762
+ }
4558
4763
  const metaType = normalizeTo_camelCase(metaTypeRaw);
4559
4764
  meta[metaType] = spaceTrim$1(commitment.content.substring(metaTypeRaw.length));
4560
4765
  }
@@ -4570,7 +4775,9 @@ function parseAgentSource(agentSource) {
4570
4775
  agentName: normalizeAgentName(parseResult.agentName || createDefaultAgentName(agentSource)),
4571
4776
  agentHash,
4572
4777
  personaDescription,
4778
+ initialMessage,
4573
4779
  meta,
4780
+ links,
4574
4781
  parameters,
4575
4782
  };
4576
4783
  }