@promptbook/components 0.103.0-46 → 0.103.0-47

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 (53) hide show
  1. package/esm/index.es.js +170 -109
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/servers.d.ts +1 -7
  4. package/esm/typings/src/_packages/components.index.d.ts +4 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +16 -14
  6. package/esm/typings/src/_packages/types.index.d.ts +12 -6
  7. package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +6 -1
  8. package/esm/typings/src/book-2.0/agent-source/AgentSourceParseResult.d.ts +1 -1
  9. package/esm/typings/src/book-2.0/agent-source/createCommitmentRegex.d.ts +1 -1
  10. package/esm/typings/src/book-components/Chat/AgentChat/AgentChat.d.ts +14 -0
  11. package/esm/typings/src/book-components/Chat/AgentChat/AgentChat.test.d.ts +1 -0
  12. package/esm/typings/src/book-components/Chat/AgentChat/AgentChatProps.d.ts +13 -0
  13. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +1 -60
  14. package/esm/typings/src/{book-2.0/commitments → commitments}/ACTION/ACTION.d.ts +1 -1
  15. package/esm/typings/src/{book-2.0/commitments → commitments}/DELETE/DELETE.d.ts +1 -1
  16. package/esm/typings/src/{book-2.0/commitments → commitments}/FORMAT/FORMAT.d.ts +1 -1
  17. package/esm/typings/src/{book-2.0/commitments → commitments}/GOAL/GOAL.d.ts +1 -1
  18. package/esm/typings/src/{book-2.0/commitments → commitments}/KNOWLEDGE/KNOWLEDGE.d.ts +1 -5
  19. package/esm/typings/src/{book-2.0/commitments → commitments}/MEMORY/MEMORY.d.ts +1 -1
  20. package/esm/typings/src/{book-2.0/commitments → commitments}/MESSAGE/MESSAGE.d.ts +1 -1
  21. package/esm/typings/src/{book-2.0/commitments → commitments}/META/META.d.ts +1 -1
  22. package/esm/typings/src/{book-2.0/commitments → commitments}/META_IMAGE/META_IMAGE.d.ts +1 -1
  23. package/esm/typings/src/{book-2.0/commitments → commitments}/META_LINK/META_LINK.d.ts +1 -1
  24. package/esm/typings/src/{book-2.0/commitments → commitments}/MODEL/MODEL.d.ts +1 -1
  25. package/esm/typings/src/{book-2.0/commitments → commitments}/NOTE/NOTE.d.ts +1 -1
  26. package/esm/typings/src/{book-2.0/commitments → commitments}/PERSONA/PERSONA.d.ts +1 -1
  27. package/esm/typings/src/{book-2.0/commitments → commitments}/RULE/RULE.d.ts +1 -1
  28. package/esm/typings/src/{book-2.0/commitments → commitments}/SAMPLE/SAMPLE.d.ts +1 -1
  29. package/esm/typings/src/{book-2.0/commitments → commitments}/SCENARIO/SCENARIO.d.ts +1 -1
  30. package/esm/typings/src/{book-2.0/commitments → commitments}/STYLE/STYLE.d.ts +1 -1
  31. package/esm/typings/src/{book-2.0/commitments → commitments}/_base/BaseCommitmentDefinition.d.ts +1 -1
  32. package/esm/typings/src/{book-2.0/commitments → commitments}/_base/CommitmentDefinition.d.ts +1 -1
  33. package/esm/typings/src/{book-2.0/commitments → commitments}/_base/NotYetImplementedCommitmentDefinition.d.ts +1 -1
  34. package/esm/typings/src/{book-2.0/commitments → commitments}/_base/createEmptyAgentModelRequirements.d.ts +1 -1
  35. package/esm/typings/src/execution/LlmExecutionTools.d.ts +1 -1
  36. package/esm/typings/src/llm-providers/agent/Agent.d.ts +3 -7
  37. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +1 -1
  38. package/esm/typings/src/llm-providers/agent/CreateAgentLlmExecutionToolsOptions.d.ts +1 -1
  39. package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +32 -0
  40. package/esm/typings/src/llm-providers/agent/RemoteAgentOptions.d.ts +11 -0
  41. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +5 -1
  42. package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -0
  43. package/esm/typings/src/types/typeAliases.d.ts +6 -0
  44. package/esm/typings/src/utils/color/internal-utils/checkChannelValue.d.ts +0 -3
  45. package/esm/typings/src/utils/random/$generateBookBoilerplate.d.ts +2 -2
  46. package/esm/typings/src/utils/random/$randomFullnameWithColor.d.ts +1 -1
  47. package/esm/typings/src/version.d.ts +1 -1
  48. package/package.json +2 -1
  49. package/umd/index.umd.js +173 -112
  50. package/umd/index.umd.js.map +1 -1
  51. /package/esm/typings/src/{book-2.0/commitments → commitments}/_base/BookCommitment.d.ts +0 -0
  52. /package/esm/typings/src/{book-2.0/commitments → commitments}/_base/ParsedCommitment.d.ts +0 -0
  53. /package/esm/typings/src/{book-2.0/commitments → commitments}/index.d.ts +0 -0
package/esm/index.es.js CHANGED
@@ -8,6 +8,7 @@ import { Registration } from 'destroyable';
8
8
  import hljs from 'highlight.js';
9
9
  import katex from 'katex';
10
10
  import { Converter } from 'showdown';
11
+ import { BehaviorSubject } from 'rxjs';
11
12
  import { forTime } from 'waitasecond';
12
13
  import QRCode from 'qrcode';
13
14
 
@@ -25,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
25
26
  * @generated
26
27
  * @see https://github.com/webgptorg/promptbook
27
28
  */
28
- const PROMPTBOOK_ENGINE_VERSION = '0.103.0-46';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-47';
29
30
  /**
30
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
32
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -666,6 +667,36 @@ class GoalCommitmentDefinition extends BaseCommitmentDefinition {
666
667
  * Note: [💞] Ignore a discrepancy between file name and entity name
667
668
  */
668
669
 
670
+ /**
671
+ * Tests if given string is valid URL.
672
+ *
673
+ * Note: [🔂] This function is idempotent.
674
+ * Note: Dataurl are considered perfectly valid.
675
+ * Note: There are two similar functions:
676
+ * - `isValidUrl` which tests any URL
677
+ * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
678
+ *
679
+ * @public exported from `@promptbook/utils`
680
+ */
681
+ function isValidUrl(url) {
682
+ if (typeof url !== 'string') {
683
+ return false;
684
+ }
685
+ try {
686
+ if (url.startsWith('blob:')) {
687
+ url = url.replace(/^blob:/, '');
688
+ }
689
+ const urlObject = new URL(url /* because fail is handled */);
690
+ if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
691
+ return false;
692
+ }
693
+ return true;
694
+ }
695
+ catch (error) {
696
+ return false;
697
+ }
698
+ }
699
+
669
700
  /**
670
701
  * KNOWLEDGE commitment definition
671
702
  *
@@ -739,23 +770,19 @@ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
739
770
  `);
740
771
  }
741
772
  applyToAgentModelRequirements(requirements, content) {
742
- var _a;
743
773
  const trimmedContent = content.trim();
744
774
  if (!trimmedContent) {
745
775
  return requirements;
746
776
  }
747
777
  // Check if content is a URL (external knowledge source)
748
- if (this.isUrl(trimmedContent)) {
778
+ if (isValidUrl(trimmedContent)) {
749
779
  // Store the URL for later async processing
750
780
  const updatedRequirements = {
751
781
  ...requirements,
752
- metadata: {
753
- ...requirements.metadata,
754
- knowledgeSources: [
755
- ...(((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.knowledgeSources) || []),
756
- trimmedContent,
757
- ],
758
- },
782
+ knowledgeSources: [
783
+ ...(requirements.knowledgeSources || []),
784
+ trimmedContent,
785
+ ],
759
786
  };
760
787
  // Add placeholder information about knowledge sources to system message
761
788
  const knowledgeInfo = `Knowledge Source URL: ${trimmedContent} (will be processed for retrieval during chat)`;
@@ -767,18 +794,6 @@ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
767
794
  return this.appendToSystemMessage(requirements, knowledgeSection, '\n\n');
768
795
  }
769
796
  }
770
- /**
771
- * Check if content is a URL
772
- */
773
- isUrl(content) {
774
- try {
775
- new URL(content);
776
- return true;
777
- }
778
- catch (_a) {
779
- return false;
780
- }
781
- }
782
797
  }
783
798
  /**
784
799
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2403,15 +2418,20 @@ const DEFAULT_BOOK = padBook(validateBook(spaceTrim$1(`
2403
2418
  */
2404
2419
  const REMOTE_SERVER_URLS = [
2405
2420
  {
2406
- title: 'Promptbook',
2407
- description: `Servers of Promptbook.studio`,
2421
+ title: 'Promptbook.Studio',
2422
+ description: `Server of Promptbook.studio`,
2408
2423
  owner: 'AI Web, LLC <legal@ptbk.io> (https://www.ptbk.io/)',
2409
- isAnonymousModeAllowed: true,
2410
2424
  urls: [
2411
2425
  'https://promptbook.s5.ptbk.io/',
2412
2426
  // Note: Servers 1-4 are not running
2413
2427
  ],
2414
2428
  },
2429
+ {
2430
+ title: 'Testing Agents',
2431
+ description: `Testing Agents server on Vercel`,
2432
+ owner: 'AI Web, LLC <legal@ptbk.io> (https://www.ptbk.io/)',
2433
+ urls: ['https://s6.ptbk.io/'],
2434
+ },
2415
2435
  /*
2416
2436
  Note: Working on older version of Promptbook and not supported anymore
2417
2437
  {
@@ -2656,9 +2676,6 @@ function checkChannelValue(channelName, value) {
2656
2676
  throw new Error(`${channelName} channel is greater than 255, it is ${value}`);
2657
2677
  }
2658
2678
  }
2659
- /**
2660
- * TODO: [🧠][🚓] Is/which combination it better to use asserts/check, validate or is utility function?
2661
- */
2662
2679
 
2663
2680
  /**
2664
2681
  * Color object represents an RGB color with alpha channel
@@ -3506,36 +3523,6 @@ function isValidFilePath(filename) {
3506
3523
  * TODO: [🍏] Implement for MacOs
3507
3524
  */
3508
3525
 
3509
- /**
3510
- * Tests if given string is valid URL.
3511
- *
3512
- * Note: [🔂] This function is idempotent.
3513
- * Note: Dataurl are considered perfectly valid.
3514
- * Note: There are two similar functions:
3515
- * - `isValidUrl` which tests any URL
3516
- * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
3517
- *
3518
- * @public exported from `@promptbook/utils`
3519
- */
3520
- function isValidUrl(url) {
3521
- if (typeof url !== 'string') {
3522
- return false;
3523
- }
3524
- try {
3525
- if (url.startsWith('blob:')) {
3526
- url = url.replace(/^blob:/, '');
3527
- }
3528
- const urlObject = new URL(url /* because fail is handled */);
3529
- if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
3530
- return false;
3531
- }
3532
- return true;
3533
- }
3534
- catch (error) {
3535
- return false;
3536
- }
3537
- }
3538
-
3539
3526
  const defaultDiacriticsRemovalMap = [
3540
3527
  {
3541
3528
  base: 'A',
@@ -4508,8 +4495,7 @@ function aboutPromptbookInformation(options) {
4508
4495
 
4509
4496
  ## Servers
4510
4497
 
4511
- ${block(REMOTE_SERVER_URLS.map(({ title, urls, isAnonymousModeAllowed, description }, index) => `${index + 1}. ${title} ${description}
4512
- ${isAnonymousModeAllowed ? '🐱‍💻 ' : ''} ${urls.join(', ')}
4498
+ ${block(REMOTE_SERVER_URLS.map(({ title, urls, description }, index) => `${index + 1}. ${title} ${description} ${urls.join(', ')}
4513
4499
  `).join('\n'))}
4514
4500
  `);
4515
4501
  fullInfoPieces.push(serversInfo);
@@ -4929,7 +4915,7 @@ function BookEditorMonaco(props) {
4929
4915
  const uploadResults = await Promise.all(uploadPromises);
4930
4916
  // Note: This is a simplified implementation. A more robust solution would
4931
4917
  // determine the drop position in the editor and insert the text there.
4932
- const newText = uploadResults.map((fileSrc) => `KNOWLEDGE { ${fileSrc} }`).join('\n');
4918
+ const newText = uploadResults.map((fileSrc) => `KNOWLEDGE ${fileSrc}`).join('\n');
4933
4919
  const currentValue = value || '';
4934
4920
  const newValue = currentValue + '\n' + newText;
4935
4921
  onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
@@ -5089,6 +5075,38 @@ function AvatarProfileFromSource(props) {
5089
5075
  return jsx(AvatarProfile, { ...rest, agent: agent, agentSource: agentSource });
5090
5076
  }
5091
5077
 
5078
+ /**
5079
+ * Restricts an Updatable to a (2) BehaviorSubject variant
5080
+ *
5081
+ * @see Updatable
5082
+ * @private internal utility <- TODO: [🧠] Maybe export from `@promptbook/types`
5083
+ */
5084
+ function asUpdatableSubject(value) {
5085
+ if (value instanceof BehaviorSubject) {
5086
+ return value;
5087
+ }
5088
+ else if (Array.isArray(value)) {
5089
+ if (value.length !== 2) {
5090
+ throw new TypeError('`asUpdatableSubject`: Invalid tuple length, expected 2 elements');
5091
+ }
5092
+ if (typeof value[1] !== 'function') {
5093
+ throw new TypeError('`asUpdatableSubject`: Invalid tuple, expected second element to be a function');
5094
+ }
5095
+ const [theValue, setValue] = value;
5096
+ const subject = new BehaviorSubject(theValue);
5097
+ subject.subscribe((newValue) => {
5098
+ setValue(newValue);
5099
+ });
5100
+ return subject;
5101
+ }
5102
+ else {
5103
+ return new BehaviorSubject(value);
5104
+ }
5105
+ }
5106
+ /**
5107
+ * TODO: [🧠] Maybe `BehaviorSubject` is too heavy for this use case, maybe just tuple `[value,setValue]` is enough
5108
+ */
5109
+
5092
5110
  /**
5093
5111
  * Calculates distance between two colors
5094
5112
  *
@@ -6548,53 +6566,6 @@ function Chat(props) {
6548
6566
  placeholder: "Add a note (optional)", defaultValue: textRating, onChange: (e) => setTextRating(e.target.value), className: chatStyles.ratingInput }), jsxs("div", { className: chatStyles.ratingActions, children: [jsx("button", { onClick: () => setRatingModalOpen(false), children: "Cancel" }), jsx("button", { onClick: submitRating, children: "Submit" })] })] }) }))] }));
6549
6567
  }
6550
6568
 
6551
- /**
6552
- * Hook to create a sendMessage function for an <LlmChat/> component WITHOUT needing any React Context.
6553
- *
6554
- * Usage pattern:
6555
- * ```tsx
6556
- * const sendMessage = useSendMessageToLlmChat();
6557
- * return (
6558
- * <>
6559
- * <button onClick={() => sendMessage('Hello!')}>Hello</button>
6560
- * <LlmChat llmTools={llmTools} sendMessage={sendMessage} />
6561
- * </>
6562
- * );
6563
- * ```
6564
- *
6565
- * - No provider wrapping needed.
6566
- * - Safe to call before the <LlmChat/> mounts (messages will be queued).
6567
- * - Keeps DRY by letting <LlmChat/> reuse its internal `handleMessage` logic.
6568
- *
6569
- * @public exported from `@promptbook/components`
6570
- */
6571
- function useSendMessageToLlmChat() {
6572
- const ref = useRef(null);
6573
- if (!ref.current) {
6574
- let handler = null;
6575
- const queue = [];
6576
- const sendMessage = (message) => {
6577
- if (handler) {
6578
- // Fire and forget
6579
- void handler(message);
6580
- }
6581
- else {
6582
- queue.push(message);
6583
- }
6584
- };
6585
- sendMessage._attach = (attachedHandler) => {
6586
- handler = attachedHandler;
6587
- // Flush queued messages
6588
- while (queue.length > 0) {
6589
- const next = queue.shift();
6590
- void handler(next);
6591
- }
6592
- };
6593
- ref.current = sendMessage;
6594
- }
6595
- return ref.current;
6596
- }
6597
-
6598
6569
  /**
6599
6570
  * Utility functions for persisting chat conversations in localStorage
6600
6571
  *
@@ -6848,6 +6819,96 @@ function LlmChat(props) {
6848
6819
  return (jsx(Chat, { ...restProps, messages, onReset, tasksProgress, participants, onMessage: handleMessage, onReset: handleReset }));
6849
6820
  }
6850
6821
 
6822
+ /**
6823
+ * AgentChat component that provides chat functionality with LLM integration
6824
+ *
6825
+ * This component internally manages messages, participants, and task progress,
6826
+ * and uses the provided LLM tools to generate responses via `LlmExecutionTools.callChatModel`.
6827
+ *
6828
+ * Note: There are multiple chat components:
6829
+ * - `<Chat/>` renders chat as it is without any logic
6830
+ * - `<AgentChat/>` connected to LLM Execution Tools of Promptbook
6831
+ *
6832
+ * @public exported from `@promptbook/components`
6833
+ */
6834
+ function AgentChat(props) {
6835
+ const { agent, title, persistenceKey, onChange, sendMessage, ...restProps } = props;
6836
+ return (jsx(LlmChat, { title: title || `Chat with ${agent.agentName || 'Agent'}`, persistenceKey: persistenceKey || `agent-chat-${agent.agentName || '!!!!!remove'}`, userParticipantName: "USER", llmParticipantName: "AGENT" // <- TODO: [🧠] Maybe dynamic agent id
6837
+ , initialMessages: [
6838
+ {
6839
+ from: 'AGENT',
6840
+ content: spaceTrim$1(`
6841
+
6842
+ Hello! I am ${agent.agentName || 'an AI Agent'}.
6843
+
6844
+ [Hello](?message=Hello, can you tell me about yourself?)
6845
+ `),
6846
+ },
6847
+ ], participants: [
6848
+ {
6849
+ name: 'AGENT',
6850
+ fullname: agent.agentName || 'Agent',
6851
+ avatarSrc: agent.meta.image,
6852
+ color: agent.meta.color,
6853
+ isMe: false,
6854
+ agentSource: asUpdatableSubject(agent.agentSource).getValue() /* <- TODO: !!!!! asValue */,
6855
+ },
6856
+ {
6857
+ name: 'USER',
6858
+ fullname: 'User',
6859
+ color: '#115EB6',
6860
+ isMe: true,
6861
+ },
6862
+ ], llmTools: agent, onChange, sendMessage, ...restProps }));
6863
+ }
6864
+
6865
+ /**
6866
+ * Hook to create a sendMessage function for an <LlmChat/> component WITHOUT needing any React Context.
6867
+ *
6868
+ * Usage pattern:
6869
+ * ```tsx
6870
+ * const sendMessage = useSendMessageToLlmChat();
6871
+ * return (
6872
+ * <>
6873
+ * <button onClick={() => sendMessage('Hello!')}>Hello</button>
6874
+ * <LlmChat llmTools={llmTools} sendMessage={sendMessage} />
6875
+ * </>
6876
+ * );
6877
+ * ```
6878
+ *
6879
+ * - No provider wrapping needed.
6880
+ * - Safe to call before the <LlmChat/> mounts (messages will be queued).
6881
+ * - Keeps DRY by letting <LlmChat/> reuse its internal `handleMessage` logic.
6882
+ *
6883
+ * @public exported from `@promptbook/components`
6884
+ */
6885
+ function useSendMessageToLlmChat() {
6886
+ const ref = useRef(null);
6887
+ if (!ref.current) {
6888
+ let handler = null;
6889
+ const queue = [];
6890
+ const sendMessage = (message) => {
6891
+ if (handler) {
6892
+ // Fire and forget
6893
+ void handler(message);
6894
+ }
6895
+ else {
6896
+ queue.push(message);
6897
+ }
6898
+ };
6899
+ sendMessage._attach = (attachedHandler) => {
6900
+ handler = attachedHandler;
6901
+ // Flush queued messages
6902
+ while (queue.length > 0) {
6903
+ const next = queue.shift();
6904
+ void handler(next);
6905
+ }
6906
+ };
6907
+ ref.current = sendMessage;
6908
+ }
6909
+ return ref.current;
6910
+ }
6911
+
6851
6912
  /**
6852
6913
  * Normal flow of messages in the `MockedChat` component
6853
6914
  *
@@ -7457,5 +7518,5 @@ function injectCssModuleIntoShadowRoot(options) {
7457
7518
  }
7458
7519
  }
7459
7520
 
7460
- export { AboutPromptbookInformation, ArrowIcon, AttachmentIcon, AvatarChip, AvatarChipFromSource, AvatarProfile, AvatarProfileFromSource, BLOCKY_FLOW, BOOK_LANGUAGE_VERSION, BookEditor, BrandedQrCode, CHAT_SAVE_FORMATS, Chat, DEFAULT_BOOK_EDITOR_HEIGHT, FAST_FLOW, GenericQrCode, LlmChat, MOCKED_CHAT_DELAY_CONFIGS, MarkdownContent, MockedChat, NORMAL_FLOW, PROMPTBOOK_ENGINE_VERSION, PauseIcon, PlayIcon, PromptbookQrCode, RANDOM_FLOW, ResetIcon, SLOW_FLOW, SaveIcon, SendIcon, TemplateIcon, getChatSaveFormatDefinitions, htmlSaveFormatDefinition, injectCssModuleIntoShadowRoot, jsonSaveFormatDefinition, mdSaveFormatDefinition, parseMessageButtons, pdfSaveFormatDefinition, reactSaveFormatDefinition, txtSaveFormatDefinition, useChatAutoScroll, useSendMessageToLlmChat };
7521
+ export { AboutPromptbookInformation, AgentChat, ArrowIcon, AttachmentIcon, AvatarChip, AvatarChipFromSource, AvatarProfile, AvatarProfileFromSource, BLOCKY_FLOW, BOOK_LANGUAGE_VERSION, BookEditor, BrandedQrCode, CHAT_SAVE_FORMATS, Chat, DEFAULT_BOOK_EDITOR_HEIGHT, FAST_FLOW, GenericQrCode, LlmChat, MOCKED_CHAT_DELAY_CONFIGS, MarkdownContent, MockedChat, NORMAL_FLOW, PROMPTBOOK_ENGINE_VERSION, PauseIcon, PlayIcon, PromptbookQrCode, RANDOM_FLOW, ResetIcon, SLOW_FLOW, SaveIcon, SendIcon, TemplateIcon, getChatSaveFormatDefinitions, htmlSaveFormatDefinition, injectCssModuleIntoShadowRoot, jsonSaveFormatDefinition, mdSaveFormatDefinition, parseMessageButtons, pdfSaveFormatDefinition, reactSaveFormatDefinition, txtSaveFormatDefinition, useChatAutoScroll, useSendMessageToLlmChat };
7461
7522
  //# sourceMappingURL=index.es.js.map