@harnessio/ui3-ai-chat 0.0.0-stage → 0.2.0
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/dist/chat-constants.d.ts +14 -0
- package/dist/chat-constants.d.ts.map +1 -0
- package/dist/chat-constants.js +13 -0
- package/dist/chat-drawer-layout.d.ts +10 -0
- package/dist/chat-drawer-layout.d.ts.map +1 -0
- package/dist/chat-drawer-layout.js +66 -0
- package/dist/chat-header.d.ts +13 -0
- package/dist/chat-header.d.ts.map +1 -0
- package/dist/chat-header.js +45 -0
- package/dist/chat-history.d.ts +6 -0
- package/dist/chat-history.d.ts.map +1 -0
- package/dist/chat-history.js +119 -0
- package/dist/chat-homepage-body.d.ts +5 -0
- package/dist/chat-homepage-body.d.ts.map +1 -0
- package/dist/chat-homepage-body.js +17 -0
- package/dist/chat-input-plus-menu.d.ts +2 -0
- package/dist/chat-input-plus-menu.d.ts.map +1 -0
- package/dist/chat-input-plus-menu.js +15 -0
- package/dist/chat-input.d.ts +2 -0
- package/dist/chat-input.d.ts.map +1 -0
- package/dist/chat-input.js +65 -0
- package/dist/chat-layout.d.ts +14 -0
- package/dist/chat-layout.d.ts.map +1 -0
- package/dist/chat-layout.js +16 -0
- package/dist/chat-message-list.d.ts +13 -0
- package/dist/chat-message-list.d.ts.map +1 -0
- package/dist/chat-message-list.js +13 -0
- package/dist/chat-panel-body.d.ts +5 -0
- package/dist/chat-panel-body.d.ts.map +1 -0
- package/dist/chat-panel-body.js +17 -0
- package/dist/chat-scroll-fade.d.ts +9 -0
- package/dist/chat-scroll-fade.d.ts.map +1 -0
- package/dist/chat-scroll-fade.js +22 -0
- package/dist/chat-speech-button.d.ts +7 -0
- package/dist/chat-speech-button.d.ts.map +1 -0
- package/dist/chat-speech-button.js +12 -0
- package/dist/chat.d.ts +5 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +18 -0
- package/dist/context/chat-event-context.d.ts +10 -0
- package/dist/context/chat-event-context.d.ts.map +1 -0
- package/dist/context/chat-event-context.js +9 -0
- package/dist/context/chat-host-context.d.ts +22 -0
- package/dist/context/chat-host-context.d.ts.map +1 -0
- package/dist/context/chat-host-context.js +27 -0
- package/dist/context/chat-position-context.d.ts +14 -0
- package/dist/context/chat-position-context.d.ts.map +1 -0
- package/dist/context/chat-position-context.js +17 -0
- package/dist/default-chat-welcome.d.ts +7 -0
- package/dist/default-chat-welcome.d.ts.map +1 -0
- package/dist/default-chat-welcome.js +37 -0
- package/dist/error-boundaries/chat-error-boundary.d.ts +15 -0
- package/dist/error-boundaries/chat-error-boundary.d.ts.map +1 -0
- package/dist/error-boundaries/chat-error-boundary.js +18 -0
- package/dist/error-boundaries/index.d.ts +3 -0
- package/dist/error-boundaries/index.d.ts.map +1 -0
- package/dist/error-boundaries/index.js +2 -0
- package/dist/error-boundaries/message-error-boundary.d.ts +15 -0
- package/dist/error-boundaries/message-error-boundary.d.ts.map +1 -0
- package/dist/error-boundaries/message-error-boundary.js +18 -0
- package/dist/harness-loader/harness-loader-blades.d.ts +21 -0
- package/dist/harness-loader/harness-loader-blades.d.ts.map +1 -0
- package/dist/harness-loader/harness-loader-blades.js +25 -0
- package/dist/harness-loader/harness-loader.css +335 -0
- package/dist/harness-loader/harness-loader.d.ts +8 -0
- package/dist/harness-loader/harness-loader.d.ts.map +1 -0
- package/dist/harness-loader/harness-loader.js +9 -0
- package/dist/hooks/use-chat-content-state.d.ts +23 -0
- package/dist/hooks/use-chat-content-state.d.ts.map +1 -0
- package/dist/hooks/use-chat-content-state.js +97 -0
- package/dist/hooks/use-chat-mcp-connectors.d.ts +4 -0
- package/dist/hooks/use-chat-mcp-connectors.d.ts.map +1 -0
- package/dist/hooks/use-chat-mcp-connectors.js +5 -0
- package/dist/hooks/use-chat-tracking.d.ts +19 -0
- package/dist/hooks/use-chat-tracking.d.ts.map +1 -0
- package/dist/hooks/use-chat-tracking.js +84 -0
- package/dist/hooks/use-idle-session-prompt.d.ts +13 -0
- package/dist/hooks/use-idle-session-prompt.d.ts.map +1 -0
- package/dist/hooks/use-idle-session-prompt.js +147 -0
- package/dist/hooks/use-speech-to-text.d.ts +49 -0
- package/dist/hooks/use-speech-to-text.d.ts.map +1 -0
- package/dist/hooks/use-speech-to-text.js +117 -0
- package/dist/idle-session-banner.d.ts +6 -0
- package/dist/idle-session-banner.d.ts.map +1 -0
- package/dist/idle-session-banner.js +13 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/plugins/core-plugin.d.ts +3 -0
- package/dist/plugins/core-plugin.d.ts.map +1 -0
- package/dist/plugins/core-plugin.js +47 -0
- package/dist/providers/chat-runtime-provider.d.ts +10 -0
- package/dist/providers/chat-runtime-provider.d.ts.map +1 -0
- package/dist/providers/chat-runtime-provider.js +15 -0
- package/dist/renderers/elicitation/confirm-renderer.d.ts +4 -0
- package/dist/renderers/elicitation/confirm-renderer.d.ts.map +1 -0
- package/dist/renderers/elicitation/confirm-renderer.js +16 -0
- package/dist/renderers/elicitation/free-text-renderer.d.ts +4 -0
- package/dist/renderers/elicitation/free-text-renderer.d.ts.map +1 -0
- package/dist/renderers/elicitation/free-text-renderer.js +25 -0
- package/dist/renderers/elicitation/index.d.ts +5 -0
- package/dist/renderers/elicitation/index.d.ts.map +1 -0
- package/dist/renderers/elicitation/index.js +4 -0
- package/dist/renderers/elicitation/multi-select-renderer.d.ts +4 -0
- package/dist/renderers/elicitation/multi-select-renderer.d.ts.map +1 -0
- package/dist/renderers/elicitation/multi-select-renderer.js +47 -0
- package/dist/renderers/elicitation/select-renderer.d.ts +4 -0
- package/dist/renderers/elicitation/select-renderer.d.ts.map +1 -0
- package/dist/renderers/elicitation/select-renderer.js +32 -0
- package/dist/renderers/elicitation/shared.d.ts +146 -0
- package/dist/renderers/elicitation/shared.d.ts.map +1 -0
- package/dist/renderers/elicitation/shared.js +237 -0
- package/dist/renderers/error-renderer.d.ts +3 -0
- package/dist/renderers/error-renderer.d.ts.map +1 -0
- package/dist/renderers/error-renderer.js +11 -0
- package/dist/renderers/file-renderer.d.ts +12 -0
- package/dist/renderers/file-renderer.d.ts.map +1 -0
- package/dist/renderers/file-renderer.js +35 -0
- package/dist/renderers/follow-up-prompts-renderer.d.ts +3 -0
- package/dist/renderers/follow-up-prompts-renderer.d.ts.map +1 -0
- package/dist/renderers/follow-up-prompts-renderer.js +55 -0
- package/dist/renderers/prompts-renderer.d.ts +14 -0
- package/dist/renderers/prompts-renderer.d.ts.map +1 -0
- package/dist/renderers/prompts-renderer.js +5 -0
- package/dist/renderers/suggestions-renderer.d.ts +3 -0
- package/dist/renderers/suggestions-renderer.d.ts.map +1 -0
- package/dist/renderers/suggestions-renderer.js +24 -0
- package/dist/renderers/table-renderer.d.ts +22 -0
- package/dist/renderers/table-renderer.d.ts.map +1 -0
- package/dist/renderers/table-renderer.js +49 -0
- package/dist/renderers/text-renderer.d.ts +10 -0
- package/dist/renderers/text-renderer.d.ts.map +1 -0
- package/dist/renderers/text-renderer.js +10 -0
- package/dist/renderers/thought-process.d.ts +10 -0
- package/dist/renderers/thought-process.d.ts.map +1 -0
- package/dist/renderers/thought-process.js +8 -0
- package/dist/renderers/tool-call-renderer.d.ts +12 -0
- package/dist/renderers/tool-call-renderer.d.ts.map +1 -0
- package/dist/renderers/tool-call-renderer.js +37 -0
- package/dist/stores/chat-input-options-store.d.ts +9 -0
- package/dist/stores/chat-input-options-store.d.ts.map +1 -0
- package/dist/stores/chat-input-options-store.js +6 -0
- package/dist/stores/chat-settings-store.d.ts +11 -0
- package/dist/stores/chat-settings-store.d.ts.map +1 -0
- package/dist/stores/chat-settings-store.js +8 -0
- package/dist/stores/idle-session-prompt-store.d.ts +21 -0
- package/dist/stores/idle-session-prompt-store.d.ts.map +1 -0
- package/dist/stores/idle-session-prompt-store.js +34 -0
- package/dist/styles.css +129 -0
- package/dist/thread-actions-menu.d.ts +11 -0
- package/dist/thread-actions-menu.d.ts.map +1 -0
- package/dist/thread-actions-menu.js +55 -0
- package/dist/truncated-chip-label.d.ts +12 -0
- package/dist/truncated-chip-label.d.ts.map +1 -0
- package/dist/truncated-chip-label.js +11 -0
- package/dist/types/chat-events.d.ts +18 -0
- package/dist/types/chat-events.d.ts.map +1 -0
- package/dist/types/chat-events.js +1 -0
- package/dist/types/chat-layout.d.ts +9 -0
- package/dist/types/chat-layout.d.ts.map +1 -0
- package/dist/types/chat-layout.js +8 -0
- package/dist/utils/sentence-case.d.ts +2 -0
- package/dist/utils/sentence-case.d.ts.map +1 -0
- package/dist/utils/sentence-case.js +14 -0
- package/dist/utils/time-utils.d.ts +7 -0
- package/dist/utils/time-utils.d.ts.map +1 -0
- package/dist/utils/time-utils.js +27 -0
- package/package.json +51 -3
- package/README.md +0 -3
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
import { useAssistantRuntime, useCurrentThread, useMessages, useThreadList } from '@harnessio/ai-chat-core';
|
|
3
|
+
import { CHAT_IDLE_NEW_SESSION_MS } from '../chat-constants';
|
|
4
|
+
import { useIdleSessionPromptStore } from '../stores/idle-session-prompt-store';
|
|
5
|
+
import { useChatTracking } from './use-chat-tracking';
|
|
6
|
+
function getLastActivityAt(messages) {
|
|
7
|
+
if (messages.length === 0)
|
|
8
|
+
return null;
|
|
9
|
+
let latest = 0;
|
|
10
|
+
for (const message of messages) {
|
|
11
|
+
if (message.timestamp > latest) {
|
|
12
|
+
latest = message.timestamp;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return latest || null;
|
|
16
|
+
}
|
|
17
|
+
function hasPendingElicitation(messages) {
|
|
18
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
19
|
+
const message = messages[i];
|
|
20
|
+
if (message.role !== 'assistant')
|
|
21
|
+
continue;
|
|
22
|
+
return message.content.some(content => {
|
|
23
|
+
if (!content.type?.startsWith('elicitation_'))
|
|
24
|
+
return false;
|
|
25
|
+
const data = content.data;
|
|
26
|
+
return !data?.resolved;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
function getIdleMinutes(lastAccessAt) {
|
|
32
|
+
if (lastAccessAt == null)
|
|
33
|
+
return undefined;
|
|
34
|
+
return Math.floor((Date.now() - lastAccessAt) / 60000);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Soft idle prompt: never auto-shows. On send, compare now to the conversation's
|
|
38
|
+
* last access time (History select / successful send). If idle > 30 minutes,
|
|
39
|
+
* intercept and ask whether to start a new chat.
|
|
40
|
+
*/
|
|
41
|
+
export function useIdleSessionPrompt() {
|
|
42
|
+
const messages = useMessages();
|
|
43
|
+
const thread = useCurrentThread();
|
|
44
|
+
const threadList = useThreadList();
|
|
45
|
+
const runtime = useAssistantRuntime();
|
|
46
|
+
const { trackIdlePromptShown, trackIdlePromptAccepted, trackIdlePromptContinued, trackMessageSent } = useChatTracking();
|
|
47
|
+
const pendingMessage = useIdleSessionPromptStore(state => state.pendingMessage);
|
|
48
|
+
const offerPrompt = useIdleSessionPromptStore(state => state.offerPrompt);
|
|
49
|
+
const clearPrompt = useIdleSessionPromptStore(state => state.clearPrompt);
|
|
50
|
+
const lastMessageAt = useMemo(() => getLastActivityAt(messages), [messages]);
|
|
51
|
+
const pendingElicitation = useMemo(() => hasPendingElicitation(messages), [messages]);
|
|
52
|
+
const showPrompt = pendingMessage != null;
|
|
53
|
+
const getLastAccessAt = useCallback((conversationId) => {
|
|
54
|
+
if (!conversationId)
|
|
55
|
+
return lastMessageAt;
|
|
56
|
+
return useIdleSessionPromptStore.getState().getConversationLastAccessAt(conversationId) ?? lastMessageAt;
|
|
57
|
+
}, [lastMessageAt]);
|
|
58
|
+
const interceptSendIfIdle = useCallback((message) => {
|
|
59
|
+
const trimmed = message.trim();
|
|
60
|
+
if (!trimmed || showPrompt)
|
|
61
|
+
return false;
|
|
62
|
+
const conversationId = thread.conversationId;
|
|
63
|
+
const lastAccessAt = getLastAccessAt(conversationId);
|
|
64
|
+
if (!conversationId ||
|
|
65
|
+
conversationId.startsWith('temp') ||
|
|
66
|
+
lastAccessAt == null ||
|
|
67
|
+
thread.isRunning ||
|
|
68
|
+
pendingElicitation) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
if (Date.now() - lastAccessAt <= CHAT_IDLE_NEW_SESSION_MS) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
offerPrompt(trimmed);
|
|
75
|
+
trackIdlePromptShown({
|
|
76
|
+
conversationId,
|
|
77
|
+
idleMinutes: getIdleMinutes(lastAccessAt),
|
|
78
|
+
promptLength: trimmed.length
|
|
79
|
+
});
|
|
80
|
+
return true;
|
|
81
|
+
}, [
|
|
82
|
+
getLastAccessAt,
|
|
83
|
+
offerPrompt,
|
|
84
|
+
pendingElicitation,
|
|
85
|
+
showPrompt,
|
|
86
|
+
thread.conversationId,
|
|
87
|
+
thread.isRunning,
|
|
88
|
+
trackIdlePromptShown
|
|
89
|
+
]);
|
|
90
|
+
const startNewChatWithMessage = useCallback(async () => {
|
|
91
|
+
const message = useIdleSessionPromptStore.getState().pendingMessage?.trim();
|
|
92
|
+
if (!message)
|
|
93
|
+
return;
|
|
94
|
+
const conversationId = thread.conversationId;
|
|
95
|
+
const lastAccessAt = getLastAccessAt(conversationId);
|
|
96
|
+
clearPrompt();
|
|
97
|
+
trackIdlePromptAccepted({
|
|
98
|
+
conversationId,
|
|
99
|
+
idleMinutes: getIdleMinutes(lastAccessAt),
|
|
100
|
+
promptLength: message.length
|
|
101
|
+
});
|
|
102
|
+
await threadList.switchToNewThread();
|
|
103
|
+
const newThread = runtime.threads.getMainThread();
|
|
104
|
+
await newThread.send(message);
|
|
105
|
+
useIdleSessionPromptStore.getState().markConversationAccessed(newThread.conversationId);
|
|
106
|
+
trackMessageSent({
|
|
107
|
+
prompt: message,
|
|
108
|
+
fromIdlePrompt: true,
|
|
109
|
+
idlePromptChoice: 'new_chat'
|
|
110
|
+
});
|
|
111
|
+
}, [
|
|
112
|
+
clearPrompt,
|
|
113
|
+
getLastAccessAt,
|
|
114
|
+
runtime.threads,
|
|
115
|
+
thread.conversationId,
|
|
116
|
+
threadList,
|
|
117
|
+
trackIdlePromptAccepted,
|
|
118
|
+
trackMessageSent
|
|
119
|
+
]);
|
|
120
|
+
const continueInCurrentChat = useCallback(async () => {
|
|
121
|
+
const message = useIdleSessionPromptStore.getState().pendingMessage?.trim();
|
|
122
|
+
if (!message)
|
|
123
|
+
return;
|
|
124
|
+
const conversationId = thread.conversationId;
|
|
125
|
+
const lastAccessAt = getLastAccessAt(conversationId);
|
|
126
|
+
clearPrompt();
|
|
127
|
+
trackIdlePromptContinued({
|
|
128
|
+
conversationId,
|
|
129
|
+
idleMinutes: getIdleMinutes(lastAccessAt),
|
|
130
|
+
promptLength: message.length
|
|
131
|
+
});
|
|
132
|
+
await thread.send(message);
|
|
133
|
+
useIdleSessionPromptStore.getState().markConversationAccessed(conversationId);
|
|
134
|
+
trackMessageSent({
|
|
135
|
+
prompt: message,
|
|
136
|
+
fromIdlePrompt: true,
|
|
137
|
+
idlePromptChoice: 'continue'
|
|
138
|
+
});
|
|
139
|
+
}, [clearPrompt, getLastAccessAt, thread, trackIdlePromptContinued, trackMessageSent]);
|
|
140
|
+
return {
|
|
141
|
+
showPrompt,
|
|
142
|
+
pendingMessage,
|
|
143
|
+
interceptSendIfIdle,
|
|
144
|
+
startNewChatWithMessage,
|
|
145
|
+
continueInCurrentChat
|
|
146
|
+
};
|
|
147
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
type SpeechRecognitionConstructor = new () => BrowserSpeechRecognition;
|
|
2
|
+
interface BrowserSpeechRecognition extends EventTarget {
|
|
3
|
+
continuous: boolean;
|
|
4
|
+
interimResults: boolean;
|
|
5
|
+
lang: string;
|
|
6
|
+
start: () => void;
|
|
7
|
+
stop: () => void;
|
|
8
|
+
abort: () => void;
|
|
9
|
+
onresult: ((event: BrowserSpeechRecognitionEvent) => void) | null;
|
|
10
|
+
onerror: ((event: BrowserSpeechRecognitionErrorEvent) => void) | null;
|
|
11
|
+
onend: (() => void) | null;
|
|
12
|
+
}
|
|
13
|
+
interface BrowserSpeechRecognitionEvent {
|
|
14
|
+
resultIndex: number;
|
|
15
|
+
results: {
|
|
16
|
+
length: number;
|
|
17
|
+
[index: number]: {
|
|
18
|
+
isFinal: boolean;
|
|
19
|
+
0: {
|
|
20
|
+
transcript: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
interface BrowserSpeechRecognitionErrorEvent {
|
|
26
|
+
error: string;
|
|
27
|
+
}
|
|
28
|
+
declare global {
|
|
29
|
+
interface Window {
|
|
30
|
+
SpeechRecognition?: SpeechRecognitionConstructor;
|
|
31
|
+
webkitSpeechRecognition?: SpeechRecognitionConstructor;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export declare function getSpeechRecognitionConstructor(): SpeechRecognitionConstructor | undefined;
|
|
35
|
+
export interface UseSpeechToTextOptions {
|
|
36
|
+
lang?: string;
|
|
37
|
+
maxLength?: number;
|
|
38
|
+
onTranscript: (text: string) => void;
|
|
39
|
+
}
|
|
40
|
+
export declare function useSpeechToText({ lang, maxLength, onTranscript }: UseSpeechToTextOptions): {
|
|
41
|
+
supported: boolean;
|
|
42
|
+
listening: boolean;
|
|
43
|
+
error: string | null;
|
|
44
|
+
start: (currentText: string) => void;
|
|
45
|
+
stop: () => void;
|
|
46
|
+
toggle: (currentText: string) => void;
|
|
47
|
+
};
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=use-speech-to-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-speech-to-text.d.ts","sourceRoot":"","sources":["../../src/hooks/use-speech-to-text.ts"],"names":[],"mappings":"AAEA,KAAK,4BAA4B,GAAG,UAAU,wBAAwB,CAAA;AAEtE,UAAU,wBAAyB,SAA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BvB"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
export function getSpeechRecognitionConstructor() {
|
|
3
|
+
if (typeof window === 'undefined')
|
|
4
|
+
return undefined;
|
|
5
|
+
return window.SpeechRecognition || window.webkitSpeechRecognition;
|
|
6
|
+
}
|
|
7
|
+
function joinPrompt(base, spoken) {
|
|
8
|
+
const next = spoken.replace(/\s+/g, ' ').trim();
|
|
9
|
+
if (!next)
|
|
10
|
+
return base;
|
|
11
|
+
if (!base)
|
|
12
|
+
return next;
|
|
13
|
+
return /\s$/.test(base) ? `${base}${next}` : `${base} ${next}`;
|
|
14
|
+
}
|
|
15
|
+
function truncate(value, maxLength) {
|
|
16
|
+
if (!maxLength || value.length <= maxLength)
|
|
17
|
+
return value;
|
|
18
|
+
return value.slice(0, maxLength);
|
|
19
|
+
}
|
|
20
|
+
export function useSpeechToText({ lang = 'en-US', maxLength, onTranscript }) {
|
|
21
|
+
const [listening, setListening] = useState(false);
|
|
22
|
+
const [error, setError] = useState(null);
|
|
23
|
+
const recognitionRef = useRef(null);
|
|
24
|
+
const baseTextRef = useRef('');
|
|
25
|
+
const onTranscriptRef = useRef(onTranscript);
|
|
26
|
+
const supported = Boolean(getSpeechRecognitionConstructor());
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
onTranscriptRef.current = onTranscript;
|
|
29
|
+
}, [onTranscript]);
|
|
30
|
+
const stop = useCallback(() => {
|
|
31
|
+
const recognition = recognitionRef.current;
|
|
32
|
+
recognitionRef.current = null;
|
|
33
|
+
if (recognition) {
|
|
34
|
+
recognition.onresult = null;
|
|
35
|
+
recognition.onerror = null;
|
|
36
|
+
recognition.onend = null;
|
|
37
|
+
try {
|
|
38
|
+
recognition.stop();
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// already stopped
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
setListening(false);
|
|
45
|
+
}, []);
|
|
46
|
+
useEffect(() => () => stop(), [stop]);
|
|
47
|
+
const start = useCallback((currentText) => {
|
|
48
|
+
const Ctor = getSpeechRecognitionConstructor();
|
|
49
|
+
if (!Ctor) {
|
|
50
|
+
setError('Voice input is not supported in this browser.');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
stop();
|
|
54
|
+
setError(null);
|
|
55
|
+
baseTextRef.current = currentText;
|
|
56
|
+
const recognition = new Ctor();
|
|
57
|
+
recognition.continuous = true;
|
|
58
|
+
recognition.interimResults = true;
|
|
59
|
+
recognition.lang = lang;
|
|
60
|
+
recognition.onresult = event => {
|
|
61
|
+
let finals = '';
|
|
62
|
+
let interim = '';
|
|
63
|
+
for (let i = 0; i < event.results.length; i++) {
|
|
64
|
+
const result = event.results[i];
|
|
65
|
+
const transcript = result[0]?.transcript ?? '';
|
|
66
|
+
if (result.isFinal) {
|
|
67
|
+
finals += transcript;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
interim += transcript;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
onTranscriptRef.current(truncate(joinPrompt(baseTextRef.current, `${finals} ${interim}`), maxLength));
|
|
74
|
+
};
|
|
75
|
+
recognition.onerror = event => {
|
|
76
|
+
if (event.error === 'aborted' || event.error === 'no-speech')
|
|
77
|
+
return;
|
|
78
|
+
if (event.error === 'not-allowed') {
|
|
79
|
+
setError('Microphone access was blocked.');
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
setError('Could not capture voice input. Try again.');
|
|
83
|
+
}
|
|
84
|
+
setListening(false);
|
|
85
|
+
};
|
|
86
|
+
recognition.onend = () => {
|
|
87
|
+
if (recognitionRef.current === recognition) {
|
|
88
|
+
recognitionRef.current = null;
|
|
89
|
+
setListening(false);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
recognitionRef.current = recognition;
|
|
93
|
+
try {
|
|
94
|
+
recognition.start();
|
|
95
|
+
setListening(true);
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
setError('Could not start voice input. Try again.');
|
|
99
|
+
recognitionRef.current = null;
|
|
100
|
+
}
|
|
101
|
+
}, [lang, maxLength, stop]);
|
|
102
|
+
const toggle = useCallback((currentText) => {
|
|
103
|
+
if (listening) {
|
|
104
|
+
stop();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
start(currentText);
|
|
108
|
+
}, [listening, start, stop]);
|
|
109
|
+
return {
|
|
110
|
+
supported,
|
|
111
|
+
listening,
|
|
112
|
+
error,
|
|
113
|
+
start,
|
|
114
|
+
stop,
|
|
115
|
+
toggle
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-chat card (canary Card + primary Button) shown only after the user tries
|
|
3
|
+
* to send while the session has been idle for more than 30 minutes.
|
|
4
|
+
*/
|
|
5
|
+
export declare const IdleSessionBanner: () => import("react/jsx-runtime").JSX.Element | null;
|
|
6
|
+
//# sourceMappingURL=idle-session-banner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idle-session-banner.d.ts","sourceRoot":"","sources":["../src/idle-session-banner.tsx"],"names":[],"mappings":"AAIA;;;GAGG;AACH,eAAO,MAAM,iBAAiB,sDAiD7B,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, Card, IconV2, Layout, Text } from '@harnessio/ui/components';
|
|
3
|
+
import { useIdleSessionPrompt } from './hooks/use-idle-session-prompt';
|
|
4
|
+
/**
|
|
5
|
+
* In-chat card (canary Card + primary Button) shown only after the user tries
|
|
6
|
+
* to send while the session has been idle for more than 30 minutes.
|
|
7
|
+
*/
|
|
8
|
+
export const IdleSessionBanner = () => {
|
|
9
|
+
const { showPrompt, startNewChatWithMessage, continueInCurrentChat } = useIdleSessionPrompt();
|
|
10
|
+
if (!showPrompt)
|
|
11
|
+
return null;
|
|
12
|
+
return (_jsx("div", { className: "mb-cn-sm", "data-testid": "idle-session-banner", children: _jsx(Card.Root, { size: "sm", interactive: false, children: _jsx(Card.Content, { children: _jsxs(Layout.Vertical, { gap: "sm", children: [_jsx(Layout.Horizontal, { align: "center", gap: "sm", children: _jsxs(Layout.Horizontal, { align: "center", gap: "sm", className: "min-w-0", children: [_jsx("div", { className: "bg-cn-blue-3 rounded-cn-md flex size-8 shrink-0 items-center justify-center", children: _jsx(IconV2, { name: "info-circle", size: "sm", className: "text-cn-blue-8" }) }), _jsx(Text, { variant: "body-strong", color: "foreground-1", lineClamp: 1, children: "Start a new chat?" })] }) }), _jsx(Text, { variant: "body-normal", color: "foreground-2", children: "It's been over 30 minutes since your last message here. Starting a new chat is usually faster and gives clearer context. Your message hasn't been sent yet, choose where you'd like it delivered." }), _jsxs(Layout.Horizontal, { gap: "xs", className: "flex-wrap", children: [_jsx(Button, { variant: "primary", size: "sm", onClick: () => void startNewChatWithMessage(), "data-testid": "idle-session-banner-cta", children: "Start new chat" }), _jsx(Button, { variant: "outline", size: "sm", onClick: () => void continueInCurrentChat(), "data-testid": "idle-session-banner-continue", children: "Keep this chat" })] })] }) }) }) }));
|
|
13
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export { default as Chat } from './chat';
|
|
2
|
+
export { ChatInput } from './chat-input';
|
|
3
|
+
export { ChatSpeechButton } from './chat-speech-button';
|
|
4
|
+
export type { ChatSpeechButtonProps } from './chat-speech-button';
|
|
5
|
+
export { ChatHeader } from './chat-header';
|
|
6
|
+
export { ChatLayout } from './chat-layout';
|
|
7
|
+
export { ChatDrawerLayout } from './chat-drawer-layout';
|
|
8
|
+
export type { ChatDrawerLayoutProps } from './chat-drawer-layout';
|
|
9
|
+
export { ChatPanelBody } from './chat-panel-body';
|
|
10
|
+
export { ChatHomepageBody } from './chat-homepage-body';
|
|
11
|
+
export { ChatMessageList } from './chat-message-list';
|
|
12
|
+
export { ChatHistory } from './chat-history';
|
|
13
|
+
export { DefaultChatWelcome } from './default-chat-welcome';
|
|
14
|
+
export { ChatInputPlusMenu } from './chat-input-plus-menu';
|
|
15
|
+
export { ThreadActionsMenu } from './thread-actions-menu';
|
|
16
|
+
export { TruncatedChipLabel } from './truncated-chip-label';
|
|
17
|
+
export { IdleSessionBanner } from './idle-session-banner';
|
|
18
|
+
export { ChatErrorBoundary, MessageErrorBoundary } from './error-boundaries';
|
|
19
|
+
export { ChatHostProvider, useChatHost } from './context/chat-host-context';
|
|
20
|
+
export type { ChatHostValue } from './context/chat-host-context';
|
|
21
|
+
export { ChatPositionProvider, useChatPosition, useChatPositionOptional } from './context/chat-position-context';
|
|
22
|
+
export { ChatEventProvider, useChatEvent } from './context/chat-event-context';
|
|
23
|
+
export { ChatRuntimeProvider } from './providers/chat-runtime-provider';
|
|
24
|
+
export type { ChatRuntimeProviderProps } from './providers/chat-runtime-provider';
|
|
25
|
+
export { corePlugin } from './plugins/core-plugin';
|
|
26
|
+
export { ThoughtProcessRenderer } from './renderers/thought-process';
|
|
27
|
+
export { tableRenderer } from './renderers/table-renderer';
|
|
28
|
+
export { errorRenderer } from './renderers/error-renderer';
|
|
29
|
+
export { fileRenderer } from './renderers/file-renderer';
|
|
30
|
+
export { suggestionsRenderer } from './renderers/suggestions-renderer';
|
|
31
|
+
export { followUpPromptsRenderer } from './renderers/follow-up-prompts-renderer';
|
|
32
|
+
export { toolCallRenderer } from './renderers/tool-call-renderer';
|
|
33
|
+
export { PromptsRenderer } from './renderers/prompts-renderer';
|
|
34
|
+
export { useChatContentState } from './hooks/use-chat-content-state';
|
|
35
|
+
export type { ChatContentState } from './hooks/use-chat-content-state';
|
|
36
|
+
export { useChatTracking, generateSegmentEvent } from './hooks/use-chat-tracking';
|
|
37
|
+
export { useIdleSessionPrompt } from './hooks/use-idle-session-prompt';
|
|
38
|
+
export { useChatMcpConnectors } from './hooks/use-chat-mcp-connectors';
|
|
39
|
+
export { useSpeechToText } from './hooks/use-speech-to-text';
|
|
40
|
+
export { useChatSettingsStore, type ChatSettingsTab } from './stores/chat-settings-store';
|
|
41
|
+
export { useChatInputOptionsStore } from './stores/chat-input-options-store';
|
|
42
|
+
export { useIdleSessionPromptStore } from './stores/idle-session-prompt-store';
|
|
43
|
+
export { MAX_CHAT_INPUT_CHARACTERS, CHAT_IDLE_NEW_SESSION_MS } from './chat-constants';
|
|
44
|
+
export { CHAT_FULLSCREEN_WIDTH_PX, CHAT_PANEL_COLLAPSED_WIDTH_PX, CHAT_PANEL_MIN_WIDTH_PX, CHAT_PANEL_MIN_SIZE_PERCENT, CHAT_PANEL_MAX_SIZE_PERCENT, CHAT_PANEL_DEFAULT_SIZE_PERCENT, type ChatVariant, type ChatLayoutPosition } from './types/chat-layout';
|
|
45
|
+
export type { ChatEvent } from './types/chat-events';
|
|
46
|
+
export { toSentenceCase } from './utils/sentence-case';
|
|
47
|
+
export { getFormattedTimeInfo } from './utils/time-utils';
|
|
48
|
+
export { selectRenderer, multiSelectRenderer, freeTextRenderer, confirmRenderer } from './renderers/elicitation/index';
|
|
49
|
+
export { ActionButtons, ElicitationCard, ResolvedCard, useElicitationAction } from './renderers/elicitation/shared';
|
|
50
|
+
export type { ElicitationContent, ElicitationData, FormField } from './renderers/elicitation/shared';
|
|
51
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,YAAY,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE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,eAAe,EAAE,MAAM,+BAA+B,CAAA;AACtH,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAA;AACnH,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export { default as Chat } from './chat';
|
|
2
|
+
export { ChatInput } from './chat-input';
|
|
3
|
+
export { ChatSpeechButton } from './chat-speech-button';
|
|
4
|
+
export { ChatHeader } from './chat-header';
|
|
5
|
+
export { ChatLayout } from './chat-layout';
|
|
6
|
+
export { ChatDrawerLayout } from './chat-drawer-layout';
|
|
7
|
+
export { ChatPanelBody } from './chat-panel-body';
|
|
8
|
+
export { ChatHomepageBody } from './chat-homepage-body';
|
|
9
|
+
export { ChatMessageList } from './chat-message-list';
|
|
10
|
+
export { ChatHistory } from './chat-history';
|
|
11
|
+
export { DefaultChatWelcome } from './default-chat-welcome';
|
|
12
|
+
export { ChatInputPlusMenu } from './chat-input-plus-menu';
|
|
13
|
+
export { ThreadActionsMenu } from './thread-actions-menu';
|
|
14
|
+
export { TruncatedChipLabel } from './truncated-chip-label';
|
|
15
|
+
export { IdleSessionBanner } from './idle-session-banner';
|
|
16
|
+
export { ChatErrorBoundary, MessageErrorBoundary } from './error-boundaries';
|
|
17
|
+
export { ChatHostProvider, useChatHost } from './context/chat-host-context';
|
|
18
|
+
export { ChatPositionProvider, useChatPosition, useChatPositionOptional } from './context/chat-position-context';
|
|
19
|
+
export { ChatEventProvider, useChatEvent } from './context/chat-event-context';
|
|
20
|
+
export { ChatRuntimeProvider } from './providers/chat-runtime-provider';
|
|
21
|
+
export { corePlugin } from './plugins/core-plugin';
|
|
22
|
+
export { ThoughtProcessRenderer } from './renderers/thought-process';
|
|
23
|
+
export { tableRenderer } from './renderers/table-renderer';
|
|
24
|
+
export { errorRenderer } from './renderers/error-renderer';
|
|
25
|
+
export { fileRenderer } from './renderers/file-renderer';
|
|
26
|
+
export { suggestionsRenderer } from './renderers/suggestions-renderer';
|
|
27
|
+
export { followUpPromptsRenderer } from './renderers/follow-up-prompts-renderer';
|
|
28
|
+
export { toolCallRenderer } from './renderers/tool-call-renderer';
|
|
29
|
+
export { PromptsRenderer } from './renderers/prompts-renderer';
|
|
30
|
+
export { useChatContentState } from './hooks/use-chat-content-state';
|
|
31
|
+
export { useChatTracking, generateSegmentEvent } from './hooks/use-chat-tracking';
|
|
32
|
+
export { useIdleSessionPrompt } from './hooks/use-idle-session-prompt';
|
|
33
|
+
export { useChatMcpConnectors } from './hooks/use-chat-mcp-connectors';
|
|
34
|
+
export { useSpeechToText } from './hooks/use-speech-to-text';
|
|
35
|
+
export { useChatSettingsStore } from './stores/chat-settings-store';
|
|
36
|
+
export { useChatInputOptionsStore } from './stores/chat-input-options-store';
|
|
37
|
+
export { useIdleSessionPromptStore } from './stores/idle-session-prompt-store';
|
|
38
|
+
export { MAX_CHAT_INPUT_CHARACTERS, CHAT_IDLE_NEW_SESSION_MS } from './chat-constants';
|
|
39
|
+
export { CHAT_FULLSCREEN_WIDTH_PX, CHAT_PANEL_COLLAPSED_WIDTH_PX, CHAT_PANEL_MIN_WIDTH_PX, CHAT_PANEL_MIN_SIZE_PERCENT, CHAT_PANEL_MAX_SIZE_PERCENT, CHAT_PANEL_DEFAULT_SIZE_PERCENT } from './types/chat-layout';
|
|
40
|
+
export { toSentenceCase } from './utils/sentence-case';
|
|
41
|
+
export { getFormattedTimeInfo } from './utils/time-utils';
|
|
42
|
+
export { selectRenderer, multiSelectRenderer, freeTextRenderer, confirmRenderer } from './renderers/elicitation/index';
|
|
43
|
+
export { ActionButtons, ElicitationCard, ResolvedCard, useElicitationAction } from './renderers/elicitation/shared';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/core-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,yBAAyB,CAAA;AAkCrE,eAAO,MAAM,UAAU,EAAE,UAkBxB,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { confirmRenderer } from '../renderers/elicitation/confirm-renderer';
|
|
2
|
+
import { freeTextRenderer } from '../renderers/elicitation/free-text-renderer';
|
|
3
|
+
import { multiSelectRenderer } from '../renderers/elicitation/multi-select-renderer';
|
|
4
|
+
import { selectRenderer } from '../renderers/elicitation/select-renderer';
|
|
5
|
+
import { errorRenderer } from '../renderers/error-renderer';
|
|
6
|
+
import { fileRenderer } from '../renderers/file-renderer';
|
|
7
|
+
import { followUpPromptsRenderer } from '../renderers/follow-up-prompts-renderer';
|
|
8
|
+
import { PromptsRenderer } from '../renderers/prompts-renderer';
|
|
9
|
+
import { suggestionsRenderer } from '../renderers/suggestions-renderer';
|
|
10
|
+
import { tableRenderer } from '../renderers/table-renderer';
|
|
11
|
+
import TextRenderer from '../renderers/text-renderer';
|
|
12
|
+
import { ThoughtProcessRenderer } from '../renderers/thought-process';
|
|
13
|
+
import { toolCallRenderer } from '../renderers/tool-call-renderer';
|
|
14
|
+
const textRenderer = {
|
|
15
|
+
type: 'text',
|
|
16
|
+
component: TextRenderer,
|
|
17
|
+
priority: 0
|
|
18
|
+
};
|
|
19
|
+
const thoughtProcessRenderer = {
|
|
20
|
+
type: 'assistant_thought',
|
|
21
|
+
component: ThoughtProcessRenderer,
|
|
22
|
+
priority: 1
|
|
23
|
+
};
|
|
24
|
+
const promptsRenderer = {
|
|
25
|
+
type: 'prompts',
|
|
26
|
+
component: PromptsRenderer,
|
|
27
|
+
priority: 1
|
|
28
|
+
};
|
|
29
|
+
export const corePlugin = {
|
|
30
|
+
id: 'core',
|
|
31
|
+
name: 'Core Plugin',
|
|
32
|
+
renderers: [
|
|
33
|
+
textRenderer,
|
|
34
|
+
thoughtProcessRenderer,
|
|
35
|
+
promptsRenderer,
|
|
36
|
+
suggestionsRenderer,
|
|
37
|
+
followUpPromptsRenderer,
|
|
38
|
+
errorRenderer,
|
|
39
|
+
toolCallRenderer,
|
|
40
|
+
tableRenderer,
|
|
41
|
+
fileRenderer,
|
|
42
|
+
selectRenderer,
|
|
43
|
+
multiSelectRenderer,
|
|
44
|
+
freeTextRenderer,
|
|
45
|
+
confirmRenderer
|
|
46
|
+
]
|
|
47
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { ChatPlugin, StreamAdapter, ThreadListAdapter } from '@harnessio/ai-chat-core';
|
|
3
|
+
export interface ChatRuntimeProviderProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
streamAdapter: StreamAdapter;
|
|
6
|
+
threadListAdapter?: ThreadListAdapter;
|
|
7
|
+
plugins?: ChatPlugin[];
|
|
8
|
+
}
|
|
9
|
+
export declare function ChatRuntimeProvider({ children, streamAdapter, threadListAdapter, plugins }: ChatRuntimeProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
//# sourceMappingURL=chat-runtime-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-runtime-provider.d.ts","sourceRoot":"","sources":["../../src/providers/chat-runtime-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAU,MAAM,OAAO,CAAA;AAEzC,OAAO,EAIL,UAAU,EACV,aAAa,EACb,iBAAiB,EAClB,MAAM,yBAAyB,CAAA;AAIhC,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,SAAS,CAAA;IACnB,aAAa,EAAE,aAAa,CAAA;IAC5B,iBAAiB,CAAC,EAAE,iBAAiB,CAAA;IACrC,OAAO,CAAC,EAAE,UAAU,EAAE,CAAA;CACvB;AAED,wBAAgB,mBAAmB,CAAC,EAAE,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,OAAO,EAAE,EAAE,wBAAwB,2CAgBpH"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
import { AssistantRuntime, AssistantRuntimeProvider, ChatContextProvider } from '@harnessio/ai-chat-core';
|
|
4
|
+
import { corePlugin } from '../plugins/core-plugin';
|
|
5
|
+
export function ChatRuntimeProvider({ children, streamAdapter, threadListAdapter, plugins }) {
|
|
6
|
+
const runtimeRef = useRef(null);
|
|
7
|
+
if (!runtimeRef.current) {
|
|
8
|
+
runtimeRef.current = new AssistantRuntime({
|
|
9
|
+
streamAdapter,
|
|
10
|
+
threadListAdapter,
|
|
11
|
+
plugins: [corePlugin, ...(plugins ?? [])]
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return (_jsx(ChatContextProvider, { children: _jsx(AssistantRuntimeProvider, { runtime: runtimeRef.current, children: children }) }));
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirm-renderer.d.ts","sourceRoot":"","sources":["../../../src/renderers/elicitation/confirm-renderer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAW,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAGlE,OAAO,EAAkC,kBAAkB,EAAyC,MAAM,UAAU,CAAA;AA6CpH,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,kBAAkB,CAI/D,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CopyButton, Layout, Text } from '@harnessio/ui/components';
|
|
3
|
+
import { ActionButtons, ElicitationCard, useElicitationAction } from './shared';
|
|
4
|
+
function ConfirmInlineRenderer({ message, content }) {
|
|
5
|
+
const data = content.data;
|
|
6
|
+
const { state, actingId, submittedValues, handleAction } = useElicitationAction(data, message);
|
|
7
|
+
const details = data?.content.details || [];
|
|
8
|
+
if (!data)
|
|
9
|
+
return null;
|
|
10
|
+
return (_jsxs(ElicitationCard, { data: data, icon: "shield", state: state, actingId: actingId, submittedValues: submittedValues, children: [data.content.summary && (_jsx(Text, { variant: "body-normal", color: "foreground-2", children: data.content.summary })), details.length > 0 && (_jsxs(Layout.Horizontal, { align: "start", gap: "sm", className: "rounded-cn-3 border border-cn-3 bg-cn-selected p-cn-sm", children: [_jsx(Layout.Vertical, { gap: "xs", className: "flex-1", children: details.map(detail => (_jsxs(Layout.Horizontal, { align: "center", gap: "sm", children: [_jsx(Text, { variant: "caption-normal", color: "foreground-3", className: "min-w-[80px]", children: detail.label }), _jsx(Text, { variant: "body-normal", color: "foreground-1", children: detail.value })] }, detail.label))) }), _jsx(CopyButton, { name: () => details.map(d => `${d.label}: ${d.value}`).join('\n'), buttonVariant: "ghost", size: "sm", iconSize: "xs" })] })), _jsx(ActionButtons, { actions: data.actions, state: state, actingId: actingId, onAction: id => handleAction(id) })] }));
|
|
11
|
+
}
|
|
12
|
+
export const confirmRenderer = {
|
|
13
|
+
type: 'elicitation_confirm',
|
|
14
|
+
component: ConfirmInlineRenderer,
|
|
15
|
+
priority: 2
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"free-text-renderer.d.ts","sourceRoot":"","sources":["../../../src/renderers/elicitation/free-text-renderer.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAW,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAGlE,OAAO,EAAmB,kBAAkB,EAAyC,MAAM,UAAU,CAAA;AAuDrG,eAAO,MAAM,gBAAgB,EAAE,eAAe,CAAC,kBAAkB,CAIhE,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Button, Layout, Text, TextInput } from '@harnessio/ui/components';
|
|
4
|
+
import { ElicitationCard, useElicitationAction } from './shared';
|
|
5
|
+
function FreeTextInlineRenderer({ message, content }) {
|
|
6
|
+
const data = content.data;
|
|
7
|
+
const { state, actingId, submittedValues, handleAction } = useElicitationAction(data, message);
|
|
8
|
+
const question = data?.content.question || data?.title || '';
|
|
9
|
+
const placeholder = data?.content.placeholder || 'Type your answer...';
|
|
10
|
+
const maxLength = data?.content.max_length || 500;
|
|
11
|
+
const disabled = state !== 'pending';
|
|
12
|
+
const [text, setText] = useState('');
|
|
13
|
+
if (!data)
|
|
14
|
+
return null;
|
|
15
|
+
return (_jsxs(ElicitationCard, { data: data, icon: "edit", state: state, actingId: actingId, submittedValues: submittedValues, children: [question && question !== data.title && (_jsx(Text, { variant: "body-normal", color: "foreground-1", children: question })), _jsxs(Layout.Vertical, { gap: "xs", children: [_jsxs(Layout.Horizontal, { gap: "xs", align: "center", children: [_jsx("div", { className: "min-w-0 flex-1", children: _jsx(TextInput, { value: text, onChange: e => setText(e.target.value.slice(0, maxLength)), disabled: disabled, placeholder: placeholder, onKeyDown: e => {
|
|
16
|
+
if (e.key === 'Enter' && text.trim()) {
|
|
17
|
+
handleAction('respond', { free_text: text.trim() });
|
|
18
|
+
}
|
|
19
|
+
} }) }), _jsx(Button, { variant: "outline", size: "sm", disabled: disabled || !text.trim(), onClick: () => handleAction('respond', { free_text: text.trim() }), children: "Submit" })] }), maxLength < 1000 && (_jsxs(Text, { variant: "caption-normal", color: "foreground-4", className: "text-right text-[11px]", children: [text.length, "/", maxLength] }))] })] }));
|
|
20
|
+
}
|
|
21
|
+
export const freeTextRenderer = {
|
|
22
|
+
type: 'elicitation_free_text',
|
|
23
|
+
component: FreeTextInlineRenderer,
|
|
24
|
+
priority: 2
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/renderers/elicitation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-select-renderer.d.ts","sourceRoot":"","sources":["../../../src/renderers/elicitation/multi-select-renderer.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAW,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAGlE,OAAO,EAAmB,kBAAkB,EAAyC,MAAM,UAAU,CAAA;AA0FrG,eAAO,MAAM,mBAAmB,EAAE,eAAe,CAAC,kBAAkB,CAInE,CAAA"}
|