@promptbook/node 0.101.0-16 → 0.101.0-18
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 +1 -1
- package/esm/typings/src/_packages/components.index.d.ts +6 -0
- package/esm/typings/src/_packages/types.index.d.ts +4 -0
- package/esm/typings/src/book-components/AvatarProfile/AvatarChip/AvatarChip.d.ts +2 -2
- package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +13 -0
- package/esm/typings/src/book-components/Chat/hooks/index.d.ts +2 -0
- package/esm/typings/src/book-components/Chat/hooks/useChatAutoScroll.d.ts +41 -0
- package/esm/typings/src/book-components/Chat/hooks/useSendMessageToLlmChat.d.ts +44 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +1 -1
- package/esm/typings/src/book-2.0/utils/extractAgentMetadata.d.ts +0 -17
- package/esm/typings/src/book-2.0/utils/extractProfileImageFromSystemMessage.d.ts +0 -12
package/esm/index.es.js
CHANGED
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
28
28
|
* @generated
|
29
29
|
* @see https://github.com/webgptorg/promptbook
|
30
30
|
*/
|
31
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.101.0-
|
31
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.101.0-18';
|
32
32
|
/**
|
33
33
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
34
34
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
@@ -15,6 +15,9 @@ import { BookEditor } from '../book-components/BookEditor/BookEditor';
|
|
15
15
|
import { DEFAULT_BOOK_FONT_CLASS } from '../book-components/BookEditor/config';
|
16
16
|
import { Chat } from '../book-components/Chat/Chat/Chat';
|
17
17
|
import type { ChatProps } from '../book-components/Chat/Chat/ChatProps';
|
18
|
+
import { useChatAutoScroll } from '../book-components/Chat/hooks/useChatAutoScroll';
|
19
|
+
import type { SendMessageToLlmChatFunction } from '../book-components/Chat/hooks/useSendMessageToLlmChat';
|
20
|
+
import { useSendMessageToLlmChat } from '../book-components/Chat/hooks/useSendMessageToLlmChat';
|
18
21
|
import { LlmChat } from '../book-components/Chat/LlmChat/LlmChat';
|
19
22
|
import type { LlmChatProps } from '../book-components/Chat/LlmChat/LlmChatProps';
|
20
23
|
import type { ChatMessage } from '../book-components/Chat/types/ChatMessage';
|
@@ -44,6 +47,9 @@ export { BookEditor };
|
|
44
47
|
export { DEFAULT_BOOK_FONT_CLASS };
|
45
48
|
export { Chat };
|
46
49
|
export type { ChatProps };
|
50
|
+
export { useChatAutoScroll };
|
51
|
+
export type { SendMessageToLlmChatFunction };
|
52
|
+
export { useSendMessageToLlmChat };
|
47
53
|
export { LlmChat };
|
48
54
|
export type { LlmChatProps };
|
49
55
|
export type { ChatMessage };
|
@@ -13,6 +13,8 @@ import type { MockedChatDelayConfig } from '../book-components/AvatarProfile/Ava
|
|
13
13
|
import type { MockedChatProps } from '../book-components/AvatarProfile/AvatarProfile/MockedChat';
|
14
14
|
import type { BookEditorProps } from '../book-components/BookEditor/BookEditor';
|
15
15
|
import type { ChatProps } from '../book-components/Chat/Chat/ChatProps';
|
16
|
+
import type { ChatAutoScrollConfig } from '../book-components/Chat/hooks/useChatAutoScroll';
|
17
|
+
import type { SendMessageToLlmChatFunction } from '../book-components/Chat/hooks/useSendMessageToLlmChat';
|
16
18
|
import type { LlmChatProps } from '../book-components/Chat/LlmChat/LlmChatProps';
|
17
19
|
import type { ChatMessage } from '../book-components/Chat/types/ChatMessage';
|
18
20
|
import type { ChatParticipant } from '../book-components/Chat/types/ChatParticipant';
|
@@ -340,6 +342,8 @@ export type { MockedChatDelayConfig };
|
|
340
342
|
export type { MockedChatProps };
|
341
343
|
export type { BookEditorProps };
|
342
344
|
export type { ChatProps };
|
345
|
+
export type { ChatAutoScrollConfig };
|
346
|
+
export type { SendMessageToLlmChatFunction };
|
343
347
|
export type { LlmChatProps };
|
344
348
|
export type { ChatMessage };
|
345
349
|
export type { ChatParticipant };
|
@@ -9,7 +9,7 @@ export type AvatarChipProps = {
|
|
9
9
|
/**
|
10
10
|
* Avatar to be shown
|
11
11
|
*/
|
12
|
-
readonly avatarBasicInformation: AgentBasicInformation
|
12
|
+
readonly avatarBasicInformation: Omit<AgentBasicInformation, 'parameters'>;
|
13
13
|
/**
|
14
14
|
* Whether this chip is a template avatar
|
15
15
|
*/
|
@@ -21,7 +21,7 @@ export type AvatarChipProps = {
|
|
21
21
|
/**
|
22
22
|
* Called when chip is clicked
|
23
23
|
*/
|
24
|
-
readonly onSelect?: (avatar: AgentBasicInformation) => void;
|
24
|
+
readonly onSelect?: (avatar: Omit<AgentBasicInformation, 'parameters'>) => void;
|
25
25
|
/**
|
26
26
|
* Whether this chip is selected
|
27
27
|
*/
|
@@ -2,6 +2,7 @@ import type { LlmExecutionTools } from '../../../execution/LlmExecutionTools';
|
|
2
2
|
import type { ChatProps } from '../Chat/ChatProps';
|
3
3
|
import type { ChatMessage } from '../types/ChatMessage';
|
4
4
|
import type { ChatParticipant } from '../types/ChatParticipant';
|
5
|
+
import type { SendMessageToLlmChatFunction } from '../hooks/useSendMessageToLlmChat';
|
5
6
|
/**
|
6
7
|
* Props for LlmChat component, derived from ChatProps but with LLM-specific modifications
|
7
8
|
*
|
@@ -17,8 +18,20 @@ export type LlmChatProps = Omit<ChatProps, 'messages' | 'onMessage' | 'onChange'
|
|
17
18
|
* When provided, the conversation will be saved and restored from localStorage
|
18
19
|
*/
|
19
20
|
readonly persistenceKey?: string;
|
21
|
+
/**
|
22
|
+
* Optional initial messages to pre-populate the chat.
|
23
|
+
* - They can include both USER and ASSISTANT messages.
|
24
|
+
* - They are only used when there is no persisted conversation (persistence takes precedence).
|
25
|
+
* - They are not automatically persisted until the user sends a new message.
|
26
|
+
*/
|
27
|
+
readonly initialMessages?: ReadonlyArray<ChatMessage>;
|
20
28
|
/**
|
21
29
|
* Called when the chat state changes (messages, participants, etc.)
|
22
30
|
*/
|
23
31
|
onChange?(messages: ReadonlyArray<ChatMessage>, participants: ReadonlyArray<ChatParticipant>): void;
|
32
|
+
/**
|
33
|
+
* Optional external sendMessage function produced by useSendMessageToLlmChat hook.
|
34
|
+
* When provided, LlmChat will attach its internal handler to it (no React context needed).
|
35
|
+
*/
|
36
|
+
readonly sendMessage?: SendMessageToLlmChatFunction;
|
24
37
|
};
|
@@ -0,0 +1,41 @@
|
|
1
|
+
/**
|
2
|
+
* Configuration for the auto-scroll behavior
|
3
|
+
*/
|
4
|
+
export type ChatAutoScrollConfig = {
|
5
|
+
/**
|
6
|
+
* Threshold in pixels from bottom to consider as "at bottom"
|
7
|
+
* @default 100
|
8
|
+
*/
|
9
|
+
bottomThreshold?: number;
|
10
|
+
/**
|
11
|
+
* Whether to use smooth scrolling
|
12
|
+
* @default true
|
13
|
+
*/
|
14
|
+
smoothScroll?: boolean;
|
15
|
+
/**
|
16
|
+
* Delay before checking scroll position after new messages (in milliseconds)
|
17
|
+
* @default 100
|
18
|
+
*/
|
19
|
+
scrollCheckDelay?: number;
|
20
|
+
};
|
21
|
+
/**
|
22
|
+
* Hook for managing auto-scroll behavior in chat components
|
23
|
+
*
|
24
|
+
* This hook provides:
|
25
|
+
* - Automatic scrolling to bottom when new messages arrive (if user is already at bottom)
|
26
|
+
* - Detection of when user scrolls away from bottom
|
27
|
+
* - Scroll-to-bottom functionality with smooth animation
|
28
|
+
* - Mobile-optimized scrolling behavior
|
29
|
+
*
|
30
|
+
* @public exported from `@promptbook/components`
|
31
|
+
*/
|
32
|
+
export declare function useChatAutoScroll(config?: ChatAutoScrollConfig): {
|
33
|
+
isAutoScrolling: boolean;
|
34
|
+
chatMessagesRef: (element: HTMLDivElement | null) => void;
|
35
|
+
handleScroll: (event: React.UIEvent<HTMLDivElement>) => void;
|
36
|
+
handleMessagesChange: () => void;
|
37
|
+
scrollToBottom: () => void;
|
38
|
+
enableAutoScroll: () => void;
|
39
|
+
disableAutoScroll: () => void;
|
40
|
+
isMobile: boolean;
|
41
|
+
};
|
@@ -0,0 +1,44 @@
|
|
1
|
+
/**
|
2
|
+
* Function type for sending a message to LlmChat.
|
3
|
+
*
|
4
|
+
* Implementation detail: The returned function is "attachable".
|
5
|
+
* LlmChat will call the internal `_attach` method (if present) to bind
|
6
|
+
* its real message handler. Messages sent before attachment are queued
|
7
|
+
* and flushed after attachment.
|
8
|
+
*
|
9
|
+
* @public exported from `@promptbook/components`
|
10
|
+
*/
|
11
|
+
export type SendMessageToLlmChatFunction = {
|
12
|
+
/**
|
13
|
+
* Send a message to the bound LlmChat instance (or queue it until attached).
|
14
|
+
*/
|
15
|
+
(message: string): void;
|
16
|
+
/**
|
17
|
+
* Internal method used by the <LlmChat/> component to attach its handler.
|
18
|
+
* Not intended for consumer usage.
|
19
|
+
*
|
20
|
+
* @internal
|
21
|
+
*/
|
22
|
+
_attach?: (handler: (message: string) => Promise<void> | void) => void;
|
23
|
+
};
|
24
|
+
/**
|
25
|
+
* Hook to create a sendMessage function for an <LlmChat/> component WITHOUT needing any React Context.
|
26
|
+
*
|
27
|
+
* Usage pattern:
|
28
|
+
* ```tsx
|
29
|
+
* const sendMessage = useSendMessageToLlmChat();
|
30
|
+
* return (
|
31
|
+
* <>
|
32
|
+
* <button onClick={() => sendMessage('Hello!')}>Hello</button>
|
33
|
+
* <LlmChat llmTools={llmTools} sendMessage={sendMessage} />
|
34
|
+
* </>
|
35
|
+
* );
|
36
|
+
* ```
|
37
|
+
*
|
38
|
+
* - No provider wrapping needed.
|
39
|
+
* - Safe to call before the <LlmChat/> mounts (messages will be queued).
|
40
|
+
* - Keeps DRY by letting <LlmChat/> reuse its internal `handleMessage` logic.
|
41
|
+
*
|
42
|
+
* @public exported from `@promptbook/components`
|
43
|
+
*/
|
44
|
+
export declare function useSendMessageToLlmChat(): SendMessageToLlmChatFunction;
|
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
|
|
15
15
|
export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
|
16
16
|
/**
|
17
17
|
* Represents the version string of the Promptbook engine.
|
18
|
-
* It follows semantic versioning (e.g., `0.101.0-
|
18
|
+
* It follows semantic versioning (e.g., `0.101.0-17`).
|
19
19
|
*
|
20
20
|
* @generated
|
21
21
|
*/
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@promptbook/node",
|
3
|
-
"version": "0.101.0-
|
3
|
+
"version": "0.101.0-18",
|
4
4
|
"description": "Promptbook: Run AI apps in plain human language across multiple models and platforms",
|
5
5
|
"private": false,
|
6
6
|
"sideEffects": false,
|
@@ -93,7 +93,7 @@
|
|
93
93
|
"module": "./esm/index.es.js",
|
94
94
|
"typings": "./esm/typings/src/_packages/node.index.d.ts",
|
95
95
|
"peerDependencies": {
|
96
|
-
"@promptbook/core": "0.101.0-
|
96
|
+
"@promptbook/core": "0.101.0-18"
|
97
97
|
},
|
98
98
|
"dependencies": {
|
99
99
|
"colors": "1.4.0",
|
package/umd/index.umd.js
CHANGED
@@ -45,7 +45,7 @@
|
|
45
45
|
* @generated
|
46
46
|
* @see https://github.com/webgptorg/promptbook
|
47
47
|
*/
|
48
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.101.0-
|
48
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.101.0-18';
|
49
49
|
/**
|
50
50
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
51
51
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
@@ -1,17 +0,0 @@
|
|
1
|
-
import type { string_url_image } from '../../types/typeAliases';
|
2
|
-
/**
|
3
|
-
* Extracts persona, examples, and profile image from agent definition text
|
4
|
-
* @param systemMessage The original system message that may contain PERSONA, EXAMPLE, and META IMAGE lines
|
5
|
-
* @returns Object with extracted information and cleaned system message
|
6
|
-
*
|
7
|
-
* @private - TODO: [🧠] Maybe should be public?
|
8
|
-
*/
|
9
|
-
export declare function extractAgentMetadata(systemMessage: string): {
|
10
|
-
persona?: {
|
11
|
-
name: string;
|
12
|
-
description?: string;
|
13
|
-
};
|
14
|
-
examples: string[];
|
15
|
-
profileImageUrl?: string_url_image;
|
16
|
-
cleanedSystemMessage: string;
|
17
|
-
};
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import type { string_url_image } from '../../types/typeAliases';
|
2
|
-
/**
|
3
|
-
* Extracts profile image URL from agent definition text and returns cleaned system message
|
4
|
-
* @param systemMessage The original system message that may contain META IMAGE line
|
5
|
-
* @returns Object with profileImageUrl (if found) and cleanedSystemMessage (without META IMAGE line)
|
6
|
-
*
|
7
|
-
* @private - TODO: [🧠] Maybe should be public?
|
8
|
-
*/
|
9
|
-
export declare function extractProfileImageFromSystemMessage(systemMessage: string): {
|
10
|
-
profileImageUrl?: string_url_image;
|
11
|
-
cleanedSystemMessage: string;
|
12
|
-
};
|