@promptbook/wizard 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 +139 -23
  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 +139 -23
  39. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -36,7 +36,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
36
36
  * @generated
37
37
  * @see https://github.com/webgptorg/promptbook
38
38
  */
39
- const PROMPTBOOK_ENGINE_VERSION = '0.103.0-48';
39
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-50';
40
40
  /**
41
41
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
42
42
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -75,6 +75,7 @@ const REMOTE_SERVER_URLS = [
75
75
  */
76
76
  ];
77
77
  /**
78
+ * TODO: [๐Ÿฑโ€๐Ÿš€] Auto-federated server from url in here
78
79
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
79
80
  */
80
81
 
@@ -421,6 +422,9 @@ class Color {
421
422
  if (hex.length === 3) {
422
423
  return Color.fromHex3(hex);
423
424
  }
425
+ if (hex.length === 4) {
426
+ return Color.fromHex4(hex);
427
+ }
424
428
  if (hex.length === 6) {
425
429
  return Color.fromHex6(hex);
426
430
  }
@@ -441,6 +445,19 @@ class Color {
441
445
  const b = parseInt(hex.substr(2, 1), 16) * 16;
442
446
  return take(new Color(r, g, b));
443
447
  }
448
+ /**
449
+ * Creates a new Color instance from color in hex format with 4 digits (with alpha channel)
450
+ *
451
+ * @param color in hex for example `09df`
452
+ * @returns Color object
453
+ */
454
+ static fromHex4(hex) {
455
+ const r = parseInt(hex.substr(0, 1), 16) * 16;
456
+ const g = parseInt(hex.substr(1, 1), 16) * 16;
457
+ const b = parseInt(hex.substr(2, 1), 16) * 16;
458
+ const a = parseInt(hex.substr(3, 1), 16) * 16;
459
+ return take(new Color(r, g, b, a));
460
+ }
444
461
  /**
445
462
  * Creates a new Color instance from color in hex format with 6 color digits (without alpha channel)
446
463
  *
@@ -631,7 +648,8 @@ class Color {
631
648
  * @returns true if the value is a valid hex color string (e.g., `#009edd`, `#fff`, etc.)
632
649
  */
633
650
  static isHexColorString(value) {
634
- return typeof value === 'string' && /^#(?:[0-9a-fA-F]{3}){1,2}$/.test(value);
651
+ return (typeof value === 'string' &&
652
+ /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(value));
635
653
  }
636
654
  /**
637
655
  * Creates new Color object
@@ -958,6 +976,7 @@ const PROMPTBOOK_COLOR = Color.fromHex('#79EAFD');
958
976
  ({
959
977
  TITLE: Color.fromHex('#244EA8'),
960
978
  LINE: Color.fromHex('#eeeeee'),
979
+ SEPARATOR: Color.fromHex('#cccccc'),
961
980
  COMMITMENT: Color.fromHex('#DA0F78'),
962
981
  PARAMETER: Color.fromHex('#8e44ad'),
963
982
  });
@@ -1523,7 +1542,7 @@ function deepClone(objectValue) {
1523
1542
  TODO: [๐Ÿง ] Is there a better implementation?
1524
1543
  > const propertyNames = Object.getOwnPropertyNames(objectValue);
1525
1544
  > for (const propertyName of propertyNames) {
1526
- > const value = (objectValue as really_any)[propertyName];
1545
+ > const value = (objectValue as chococake)[propertyName];
1527
1546
  > if (value && typeof value === 'object') {
1528
1547
  > deepClone(value);
1529
1548
  > }
@@ -1953,7 +1972,7 @@ class DatabaseError extends Error {
1953
1972
  }
1954
1973
  }
1955
1974
  /**
1956
- * TODO: !!!! Explain that NotFoundError (!!! and other specific errors) has priority over DatabaseError in some contexts
1975
+ * TODO: [๐Ÿฑโ€๐Ÿš€] Explain that NotFoundError ([๐Ÿฑโ€๐Ÿš€] and other specific errors) has priority over DatabaseError in some contexts
1957
1976
  */
1958
1977
 
1959
1978
  /**
@@ -6783,11 +6802,12 @@ class OpenAiExecutionTools extends OpenAiCompatibleExecutionTools {
6783
6802
  *
6784
6803
  * This is useful for calling OpenAI API with a single assistant, for more wide usage use `OpenAiExecutionTools`.
6785
6804
  *
6786
- * !!! Note: [๐Ÿฆ–] There are several different things in Promptbook:
6805
+ * Note: [๐Ÿฆ–] There are several different things in Promptbook:
6787
6806
  * - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
6788
6807
  * - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
6789
6808
  * - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
6790
6809
  * - `OpenAiAssistantExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities, recommended for usage in `Agent` or `AgentLlmExecutionTools`
6810
+ * - `RemoteAgent` - which is an `Agent` that connects to a Promptbook Agents Server
6791
6811
  *
6792
6812
  * @public exported from `@promptbook/openai`
6793
6813
  */
@@ -6822,6 +6842,12 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
6822
6842
  * Calls OpenAI API to use a chat model.
6823
6843
  */
6824
6844
  async callChatModel(prompt) {
6845
+ return this.callChatModelStream(prompt, () => { });
6846
+ }
6847
+ /**
6848
+ * Calls OpenAI API to use a chat model with streaming.
6849
+ */
6850
+ async callChatModelStream(prompt, onProgress) {
6825
6851
  var _a, _b, _c;
6826
6852
  if (this.options.isVerbose) {
6827
6853
  console.info('๐Ÿ’ฌ OpenAI callChatModel call', { prompt });
@@ -6889,21 +6915,24 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
6889
6915
  console.info('connect', stream.currentEvent);
6890
6916
  }
6891
6917
  });
6892
- /*
6893
- stream.on('messageDelta', (messageDelta) => {
6894
- if (
6895
- this.options.isVerbose &&
6896
- messageDelta &&
6897
- messageDelta.content &&
6898
- messageDelta.content[0] &&
6899
- messageDelta.content[0].type === 'text'
6900
- ) {
6901
- console.info('messageDelta', messageDelta.content[0].text?.value);
6918
+ stream.on('textDelta', (textDelta, snapshot) => {
6919
+ if (this.options.isVerbose && textDelta.value) {
6920
+ console.info('textDelta', textDelta.value);
6902
6921
  }
6903
-
6904
- // <- TODO: [๐Ÿš] Make streaming and running tasks working
6922
+ const chunk = {
6923
+ content: textDelta.value || '',
6924
+ modelName: 'assistant',
6925
+ timing: {
6926
+ start,
6927
+ complete: $getCurrentDate(),
6928
+ },
6929
+ usage: UNCERTAIN_USAGE,
6930
+ rawPromptContent,
6931
+ rawRequest,
6932
+ rawResponse: snapshot,
6933
+ };
6934
+ onProgress(chunk);
6905
6935
  });
6906
- */
6907
6936
  stream.on('messageCreated', (message) => {
6908
6937
  if (this.options.isVerbose) {
6909
6938
  console.info('messageCreated', message);
@@ -6939,7 +6968,7 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
6939
6968
  }
6940
6969
  return exportJson({
6941
6970
  name: 'promptResult',
6942
- message: `Result of \`OpenAiAssistantExecutionTools.callChatModel\``,
6971
+ message: `Result of \`OpenAiAssistantExecutionTools.callChatModelStream\``,
6943
6972
  order: [],
6944
6973
  value: {
6945
6974
  content: resultContent,
@@ -7078,9 +7107,9 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
7078
7107
  }
7079
7108
  const assistant = await client.beta.assistants.create(assistantConfig);
7080
7109
  console.log(`โœ… Assistant created: ${assistant.id}`);
7081
- // TODO: !!!! Try listing existing assistants
7082
- // TODO: !!!! Try marking existing assistants by DISCRIMINANT
7083
- // TODO: !!!! Allow to update and reconnect to existing assistants
7110
+ // TODO: [๐Ÿฑโ€๐Ÿš€] Try listing existing assistants
7111
+ // TODO: [๐Ÿฑโ€๐Ÿš€] Try marking existing assistants by DISCRIMINANT
7112
+ // TODO: [๐Ÿฑโ€๐Ÿš€] Allow to update and reconnect to existing assistants
7084
7113
  return new OpenAiAssistantExecutionTools({
7085
7114
  ...this.options,
7086
7115
  isCreatingNewAssistantsAllowed: false,
@@ -14044,6 +14073,60 @@ class MemoryCommitmentDefinition extends BaseCommitmentDefinition {
14044
14073
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
14045
14074
  */
14046
14075
 
14076
+ /**
14077
+ * INITIAL MESSAGE commitment definition
14078
+ *
14079
+ * The INITIAL MESSAGE commitment defines the first message that the user sees when opening the chat.
14080
+ * It is used to greet the user and set the tone of the conversation.
14081
+ *
14082
+ * Example usage in agent source:
14083
+ *
14084
+ * ```book
14085
+ * INITIAL MESSAGE Hello! I am ready to help you with your tasks.
14086
+ * ```
14087
+ *
14088
+ * @private [๐Ÿช”] Maybe export the commitments through some package
14089
+ */
14090
+ class InitialMessageCommitmentDefinition extends BaseCommitmentDefinition {
14091
+ constructor() {
14092
+ super('INITIAL MESSAGE');
14093
+ }
14094
+ /**
14095
+ * Short one-line description of INITIAL MESSAGE.
14096
+ */
14097
+ get description() {
14098
+ return 'Defines the **initial message** shown to the user when the chat starts.';
14099
+ }
14100
+ /**
14101
+ * Markdown documentation for INITIAL MESSAGE commitment.
14102
+ */
14103
+ get documentation() {
14104
+ return spaceTrim$1(`
14105
+ # ${this.type}
14106
+
14107
+ 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).
14108
+
14109
+ ## Key aspects
14110
+
14111
+ - Used to greet the user.
14112
+ - Sets the tone of the conversation.
14113
+ - Displayed immediately when the chat interface loads.
14114
+
14115
+ ## Examples
14116
+
14117
+ \`\`\`book
14118
+ Support Agent
14119
+
14120
+ PERSONA You are a helpful support agent.
14121
+ INITIAL MESSAGE Hi there! How can I assist you today?
14122
+ \`\`\`
14123
+ `);
14124
+ }
14125
+ applyToAgentModelRequirements(requirements, content) {
14126
+ return requirements;
14127
+ }
14128
+ }
14129
+
14047
14130
  /**
14048
14131
  * MESSAGE commitment definition
14049
14132
  *
@@ -15205,6 +15288,7 @@ const COMMITMENT_REGISTRY = [
15205
15288
  new NoteCommitmentDefinition('NONCE'),
15206
15289
  new GoalCommitmentDefinition('GOAL'),
15207
15290
  new GoalCommitmentDefinition('GOALS'),
15291
+ new InitialMessageCommitmentDefinition(),
15208
15292
  new MessageCommitmentDefinition('MESSAGE'),
15209
15293
  new MessageCommitmentDefinition('MESSAGES'),
15210
15294
  new ScenarioCommitmentDefinition('SCENARIO'),
@@ -15631,13 +15715,25 @@ function generatePlaceholderAgentProfileImageUrl(agentName) {
15631
15715
  * TODO: [๐Ÿคน] Figure out best placeholder image generator https://i.pravatar.cc/1000?u=568
15632
15716
  */
15633
15717
 
15718
+ /**
15719
+ * Computes SHA-256 hash of the given object
15720
+ *
15721
+ * @public exported from `@promptbook/utils`
15722
+ */
15723
+ function computeHash(value) {
15724
+ return SHA256(hexEncoder.parse(spaceTrim(valueToString(value)))).toString( /* hex */);
15725
+ }
15726
+ /**
15727
+ * TODO: [๐Ÿฅฌ][๐Ÿฅฌ] Use this ACRY
15728
+ */
15729
+
15634
15730
  /**
15635
15731
  * Computes SHA-256 hash of the agent source
15636
15732
  *
15637
15733
  * @public exported from `@promptbook/core`
15638
15734
  */
15639
15735
  function computeAgentHash(agentSource) {
15640
- return SHA256(hexEncoder.parse(agentSource /* <- TODO: !!!!! spaceTrim */)).toString( /* hex */);
15736
+ return computeHash(agentSource);
15641
15737
  }
15642
15738
 
15643
15739
  /**
@@ -16001,13 +16097,31 @@ function parseAgentSource(agentSource) {
16001
16097
  }
16002
16098
  personaDescription += commitment.content;
16003
16099
  }
16100
+ let initialMessage = null;
16101
+ for (const commitment of parseResult.commitments) {
16102
+ if (commitment.type !== 'INITIAL MESSAGE') {
16103
+ continue;
16104
+ }
16105
+ // Note: Initial message override logic - later overrides earlier
16106
+ // Or should it append? Usually initial message is just one block.
16107
+ // Let's stick to "later overrides earlier" for simplicity, or just take the last one.
16108
+ initialMessage = commitment.content;
16109
+ }
16004
16110
  const meta = {};
16111
+ const links = [];
16005
16112
  for (const commitment of parseResult.commitments) {
16113
+ if (commitment.type === 'META LINK') {
16114
+ links.push(spaceTrim(commitment.content));
16115
+ continue;
16116
+ }
16006
16117
  if (commitment.type !== 'META') {
16007
16118
  continue;
16008
16119
  }
16009
16120
  // Parse META commitments - format is "META TYPE content"
16010
16121
  const metaTypeRaw = commitment.content.split(' ')[0] || 'NONE';
16122
+ if (metaTypeRaw === 'LINK') {
16123
+ links.push(spaceTrim(commitment.content.substring(metaTypeRaw.length)));
16124
+ }
16011
16125
  const metaType = normalizeTo_camelCase(metaTypeRaw);
16012
16126
  meta[metaType] = spaceTrim(commitment.content.substring(metaTypeRaw.length));
16013
16127
  }
@@ -16023,7 +16137,9 @@ function parseAgentSource(agentSource) {
16023
16137
  agentName: normalizeAgentName(parseResult.agentName || createDefaultAgentName(agentSource)),
16024
16138
  agentHash,
16025
16139
  personaDescription,
16140
+ initialMessage,
16026
16141
  meta,
16142
+ links,
16027
16143
  parameters,
16028
16144
  };
16029
16145
  }