@promptbook/components 0.103.0-45 → 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.
- package/esm/index.es.js +174 -109
- package/esm/index.es.js.map +1 -1
- package/esm/typings/servers.d.ts +1 -7
- package/esm/typings/src/_packages/components.index.d.ts +4 -0
- package/esm/typings/src/_packages/core.index.d.ts +16 -14
- package/esm/typings/src/_packages/types.index.d.ts +12 -6
- package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +6 -1
- package/esm/typings/src/book-2.0/agent-source/AgentSourceParseResult.d.ts +1 -1
- package/esm/typings/src/book-2.0/agent-source/createCommitmentRegex.d.ts +1 -1
- package/esm/typings/src/book-2.0/agent-source/padBook.d.ts +2 -0
- package/esm/typings/src/book-2.0/agent-source/string_book.d.ts +2 -0
- package/esm/typings/src/book-components/Chat/AgentChat/AgentChat.d.ts +14 -0
- package/esm/typings/src/book-components/Chat/AgentChat/AgentChat.test.d.ts +1 -0
- package/esm/typings/src/book-components/Chat/AgentChat/AgentChatProps.d.ts +13 -0
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +5 -60
- package/esm/typings/src/{book-2.0/commitments → commitments}/ACTION/ACTION.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/DELETE/DELETE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/FORMAT/FORMAT.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/GOAL/GOAL.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/KNOWLEDGE/KNOWLEDGE.d.ts +1 -5
- package/esm/typings/src/{book-2.0/commitments → commitments}/MEMORY/MEMORY.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/MESSAGE/MESSAGE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/META/META.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/META_IMAGE/META_IMAGE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/META_LINK/META_LINK.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/MODEL/MODEL.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/NOTE/NOTE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/PERSONA/PERSONA.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/RULE/RULE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/SAMPLE/SAMPLE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/SCENARIO/SCENARIO.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/STYLE/STYLE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/_base/BaseCommitmentDefinition.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/_base/CommitmentDefinition.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/_base/NotYetImplementedCommitmentDefinition.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/_base/createEmptyAgentModelRequirements.d.ts +1 -1
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +2 -0
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/execution/utils/validatePromptResult.d.ts +2 -0
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +3 -7
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/CreateAgentLlmExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +32 -0
- package/esm/typings/src/llm-providers/agent/RemoteAgentOptions.d.ts +11 -0
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +5 -1
- package/esm/typings/src/pipeline/validatePipelineString.d.ts +2 -0
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -0
- package/esm/typings/src/types/typeAliases.d.ts +6 -0
- package/esm/typings/src/utils/color/internal-utils/checkChannelValue.d.ts +0 -3
- package/esm/typings/src/utils/random/$generateBookBoilerplate.d.ts +2 -2
- package/esm/typings/src/utils/random/$randomFullnameWithColor.d.ts +1 -1
- package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +2 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -1
- package/umd/index.umd.js +177 -112
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/{book-2.0/commitments → commitments}/_base/BookCommitment.d.ts +0 -0
- /package/esm/typings/src/{book-2.0/commitments → commitments}/_base/ParsedCommitment.d.ts +0 -0
- /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-
|
|
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 (
|
|
778
|
+
if (isValidUrl(trimmedContent)) {
|
|
749
779
|
// Store the URL for later async processing
|
|
750
780
|
const updatedRequirements = {
|
|
751
781
|
...requirements,
|
|
752
|
-
|
|
753
|
-
...requirements.
|
|
754
|
-
|
|
755
|
-
|
|
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
|
|
@@ -2323,6 +2338,8 @@ const PADDING_LINES = 11;
|
|
|
2323
2338
|
/**
|
|
2324
2339
|
* A function that adds padding to the book content
|
|
2325
2340
|
*
|
|
2341
|
+
* Note: [🔂] This function is idempotent.
|
|
2342
|
+
*
|
|
2326
2343
|
* @public exported from `@promptbook/core`
|
|
2327
2344
|
*/
|
|
2328
2345
|
function padBook(content) {
|
|
@@ -2368,6 +2385,8 @@ function isValidBook(value) {
|
|
|
2368
2385
|
* This function should be used when you have a string that you know represents agent source
|
|
2369
2386
|
* but need to convert it to the branded type for type safety
|
|
2370
2387
|
*
|
|
2388
|
+
* Note: [🔂] This function is idempotent.
|
|
2389
|
+
*
|
|
2371
2390
|
* @public exported from `@promptbook/core`
|
|
2372
2391
|
*/
|
|
2373
2392
|
function validateBook(source) {
|
|
@@ -2399,15 +2418,20 @@ const DEFAULT_BOOK = padBook(validateBook(spaceTrim$1(`
|
|
|
2399
2418
|
*/
|
|
2400
2419
|
const REMOTE_SERVER_URLS = [
|
|
2401
2420
|
{
|
|
2402
|
-
title: 'Promptbook',
|
|
2403
|
-
description: `
|
|
2421
|
+
title: 'Promptbook.Studio',
|
|
2422
|
+
description: `Server of Promptbook.studio`,
|
|
2404
2423
|
owner: 'AI Web, LLC <legal@ptbk.io> (https://www.ptbk.io/)',
|
|
2405
|
-
isAnonymousModeAllowed: true,
|
|
2406
2424
|
urls: [
|
|
2407
2425
|
'https://promptbook.s5.ptbk.io/',
|
|
2408
2426
|
// Note: Servers 1-4 are not running
|
|
2409
2427
|
],
|
|
2410
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
|
+
},
|
|
2411
2435
|
/*
|
|
2412
2436
|
Note: Working on older version of Promptbook and not supported anymore
|
|
2413
2437
|
{
|
|
@@ -2652,9 +2676,6 @@ function checkChannelValue(channelName, value) {
|
|
|
2652
2676
|
throw new Error(`${channelName} channel is greater than 255, it is ${value}`);
|
|
2653
2677
|
}
|
|
2654
2678
|
}
|
|
2655
|
-
/**
|
|
2656
|
-
* TODO: [🧠][🚓] Is/which combination it better to use asserts/check, validate or is utility function?
|
|
2657
|
-
*/
|
|
2658
2679
|
|
|
2659
2680
|
/**
|
|
2660
2681
|
* Color object represents an RGB color with alpha channel
|
|
@@ -3502,36 +3523,6 @@ function isValidFilePath(filename) {
|
|
|
3502
3523
|
* TODO: [🍏] Implement for MacOs
|
|
3503
3524
|
*/
|
|
3504
3525
|
|
|
3505
|
-
/**
|
|
3506
|
-
* Tests if given string is valid URL.
|
|
3507
|
-
*
|
|
3508
|
-
* Note: [🔂] This function is idempotent.
|
|
3509
|
-
* Note: Dataurl are considered perfectly valid.
|
|
3510
|
-
* Note: There are two similar functions:
|
|
3511
|
-
* - `isValidUrl` which tests any URL
|
|
3512
|
-
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
3513
|
-
*
|
|
3514
|
-
* @public exported from `@promptbook/utils`
|
|
3515
|
-
*/
|
|
3516
|
-
function isValidUrl(url) {
|
|
3517
|
-
if (typeof url !== 'string') {
|
|
3518
|
-
return false;
|
|
3519
|
-
}
|
|
3520
|
-
try {
|
|
3521
|
-
if (url.startsWith('blob:')) {
|
|
3522
|
-
url = url.replace(/^blob:/, '');
|
|
3523
|
-
}
|
|
3524
|
-
const urlObject = new URL(url /* because fail is handled */);
|
|
3525
|
-
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
3526
|
-
return false;
|
|
3527
|
-
}
|
|
3528
|
-
return true;
|
|
3529
|
-
}
|
|
3530
|
-
catch (error) {
|
|
3531
|
-
return false;
|
|
3532
|
-
}
|
|
3533
|
-
}
|
|
3534
|
-
|
|
3535
3526
|
const defaultDiacriticsRemovalMap = [
|
|
3536
3527
|
{
|
|
3537
3528
|
base: 'A',
|
|
@@ -4504,8 +4495,7 @@ function aboutPromptbookInformation(options) {
|
|
|
4504
4495
|
|
|
4505
4496
|
## Servers
|
|
4506
4497
|
|
|
4507
|
-
${block(REMOTE_SERVER_URLS.map(({ title, urls,
|
|
4508
|
-
${isAnonymousModeAllowed ? '🐱💻 ' : ''} ${urls.join(', ')}
|
|
4498
|
+
${block(REMOTE_SERVER_URLS.map(({ title, urls, description }, index) => `${index + 1}. ${title} ${description} ${urls.join(', ')}
|
|
4509
4499
|
`).join('\n'))}
|
|
4510
4500
|
`);
|
|
4511
4501
|
fullInfoPieces.push(serversInfo);
|
|
@@ -4925,7 +4915,7 @@ function BookEditorMonaco(props) {
|
|
|
4925
4915
|
const uploadResults = await Promise.all(uploadPromises);
|
|
4926
4916
|
// Note: This is a simplified implementation. A more robust solution would
|
|
4927
4917
|
// determine the drop position in the editor and insert the text there.
|
|
4928
|
-
const newText = uploadResults.map((fileSrc) => `KNOWLEDGE
|
|
4918
|
+
const newText = uploadResults.map((fileSrc) => `KNOWLEDGE ${fileSrc}`).join('\n');
|
|
4929
4919
|
const currentValue = value || '';
|
|
4930
4920
|
const newValue = currentValue + '\n' + newText;
|
|
4931
4921
|
onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
@@ -5085,6 +5075,38 @@ function AvatarProfileFromSource(props) {
|
|
|
5085
5075
|
return jsx(AvatarProfile, { ...rest, agent: agent, agentSource: agentSource });
|
|
5086
5076
|
}
|
|
5087
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
|
+
|
|
5088
5110
|
/**
|
|
5089
5111
|
* Calculates distance between two colors
|
|
5090
5112
|
*
|
|
@@ -6544,53 +6566,6 @@ function Chat(props) {
|
|
|
6544
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" })] })] }) }))] }));
|
|
6545
6567
|
}
|
|
6546
6568
|
|
|
6547
|
-
/**
|
|
6548
|
-
* Hook to create a sendMessage function for an <LlmChat/> component WITHOUT needing any React Context.
|
|
6549
|
-
*
|
|
6550
|
-
* Usage pattern:
|
|
6551
|
-
* ```tsx
|
|
6552
|
-
* const sendMessage = useSendMessageToLlmChat();
|
|
6553
|
-
* return (
|
|
6554
|
-
* <>
|
|
6555
|
-
* <button onClick={() => sendMessage('Hello!')}>Hello</button>
|
|
6556
|
-
* <LlmChat llmTools={llmTools} sendMessage={sendMessage} />
|
|
6557
|
-
* </>
|
|
6558
|
-
* );
|
|
6559
|
-
* ```
|
|
6560
|
-
*
|
|
6561
|
-
* - No provider wrapping needed.
|
|
6562
|
-
* - Safe to call before the <LlmChat/> mounts (messages will be queued).
|
|
6563
|
-
* - Keeps DRY by letting <LlmChat/> reuse its internal `handleMessage` logic.
|
|
6564
|
-
*
|
|
6565
|
-
* @public exported from `@promptbook/components`
|
|
6566
|
-
*/
|
|
6567
|
-
function useSendMessageToLlmChat() {
|
|
6568
|
-
const ref = useRef(null);
|
|
6569
|
-
if (!ref.current) {
|
|
6570
|
-
let handler = null;
|
|
6571
|
-
const queue = [];
|
|
6572
|
-
const sendMessage = (message) => {
|
|
6573
|
-
if (handler) {
|
|
6574
|
-
// Fire and forget
|
|
6575
|
-
void handler(message);
|
|
6576
|
-
}
|
|
6577
|
-
else {
|
|
6578
|
-
queue.push(message);
|
|
6579
|
-
}
|
|
6580
|
-
};
|
|
6581
|
-
sendMessage._attach = (attachedHandler) => {
|
|
6582
|
-
handler = attachedHandler;
|
|
6583
|
-
// Flush queued messages
|
|
6584
|
-
while (queue.length > 0) {
|
|
6585
|
-
const next = queue.shift();
|
|
6586
|
-
void handler(next);
|
|
6587
|
-
}
|
|
6588
|
-
};
|
|
6589
|
-
ref.current = sendMessage;
|
|
6590
|
-
}
|
|
6591
|
-
return ref.current;
|
|
6592
|
-
}
|
|
6593
|
-
|
|
6594
6569
|
/**
|
|
6595
6570
|
* Utility functions for persisting chat conversations in localStorage
|
|
6596
6571
|
*
|
|
@@ -6844,6 +6819,96 @@ function LlmChat(props) {
|
|
|
6844
6819
|
return (jsx(Chat, { ...restProps, messages, onReset, tasksProgress, participants, onMessage: handleMessage, onReset: handleReset }));
|
|
6845
6820
|
}
|
|
6846
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
|
+
|
|
6847
6912
|
/**
|
|
6848
6913
|
* Normal flow of messages in the `MockedChat` component
|
|
6849
6914
|
*
|
|
@@ -7453,5 +7518,5 @@ function injectCssModuleIntoShadowRoot(options) {
|
|
|
7453
7518
|
}
|
|
7454
7519
|
}
|
|
7455
7520
|
|
|
7456
|
-
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 };
|
|
7457
7522
|
//# sourceMappingURL=index.es.js.map
|