@4djs/assistant 0.0.0 → 0.0.1
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/core/chat-activity.d.ts +19 -0
- package/dist/core/chat-activity.d.ts.map +1 -0
- package/dist/core/chat-commands.d.ts +33 -0
- package/dist/core/chat-commands.d.ts.map +1 -0
- package/dist/core/chat-history.d.ts +14 -0
- package/dist/core/chat-history.d.ts.map +1 -0
- package/dist/core/chat-reply-suggestions-parse.d.ts +20 -0
- package/dist/core/chat-reply-suggestions-parse.d.ts.map +1 -0
- package/dist/core/code-highlight.d.ts +3 -0
- package/dist/core/code-highlight.d.ts.map +1 -0
- package/dist/core/create-assistant-store.d.ts +33 -0
- package/dist/core/create-assistant-store.d.ts.map +1 -0
- package/dist/core/fetch-suggested-prompts.d.ts +11 -0
- package/dist/core/fetch-suggested-prompts.d.ts.map +1 -0
- package/dist/core/index.d.ts +19 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +2876 -0
- package/dist/core/interactive-tools/choices.d.ts +22 -0
- package/dist/core/interactive-tools/choices.d.ts.map +1 -0
- package/dist/core/interactive-tools/confirmation.d.ts +15 -0
- package/dist/core/interactive-tools/confirmation.d.ts.map +1 -0
- package/dist/core/interactive-tools/constants.d.ts +6 -0
- package/dist/core/interactive-tools/constants.d.ts.map +1 -0
- package/dist/core/interactive-tools/execute.d.ts +11 -0
- package/dist/core/interactive-tools/execute.d.ts.map +1 -0
- package/dist/core/interactive-tools/index.d.ts +7 -0
- package/dist/core/interactive-tools/index.d.ts.map +1 -0
- package/dist/core/interactive-tools/suggestions.d.ts +13 -0
- package/dist/core/interactive-tools/suggestions.d.ts.map +1 -0
- package/dist/core/interactive-tools/waiters.d.ts +4 -0
- package/dist/core/interactive-tools/waiters.d.ts.map +1 -0
- package/dist/core/llm-chat.d.ts +96 -0
- package/dist/core/llm-chat.d.ts.map +1 -0
- package/dist/core/llm-config.d.ts +24 -0
- package/dist/core/llm-config.d.ts.map +1 -0
- package/dist/core/llm-models.d.ts +14 -0
- package/dist/core/llm-models.d.ts.map +1 -0
- package/dist/core/llm-provider.d.ts +13 -0
- package/dist/core/llm-provider.d.ts.map +1 -0
- package/dist/core/llm-settings-storage.d.ts +47 -0
- package/dist/core/llm-settings-storage.d.ts.map +1 -0
- package/dist/core/llm-sse.d.ts +13 -0
- package/dist/core/llm-sse.d.ts.map +1 -0
- package/dist/core/llm-types.d.ts +49 -0
- package/dist/core/llm-types.d.ts.map +1 -0
- package/dist/core/markdown-utils.d.ts +3 -0
- package/dist/core/markdown-utils.d.ts.map +1 -0
- package/dist/core/prepare-markdown.d.ts +7 -0
- package/dist/core/prepare-markdown.d.ts.map +1 -0
- package/dist/core/types.d.ts +74 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/index.css +1195 -0
- package/dist/index.js +184948 -0
- package/dist/react/Assistant.d.ts +10 -0
- package/dist/react/Assistant.d.ts.map +1 -0
- package/dist/react/components/HighlightedJsonCode.d.ts +6 -0
- package/dist/react/components/HighlightedJsonCode.d.ts.map +1 -0
- package/dist/react/components/MarkdownContent.d.ts +10 -0
- package/dist/react/components/MarkdownContent.d.ts.map +1 -0
- package/dist/react/components/MarkdownEditor.d.ts +11 -0
- package/dist/react/components/MarkdownEditor.d.ts.map +1 -0
- package/dist/react/components/MermaidDiagram.d.ts +8 -0
- package/dist/react/components/MermaidDiagram.d.ts.map +1 -0
- package/dist/react/components/ModelSelector.d.ts +8 -0
- package/dist/react/components/ModelSelector.d.ts.map +1 -0
- package/dist/react/components/chat/AssistantErrorCallout.d.ts +11 -0
- package/dist/react/components/chat/AssistantErrorCallout.d.ts.map +1 -0
- package/dist/react/components/chat/ChatActivity.d.ts +8 -0
- package/dist/react/components/chat/ChatActivity.d.ts.map +1 -0
- package/dist/react/components/chat/ChatComposer.d.ts +36 -0
- package/dist/react/components/chat/ChatComposer.d.ts.map +1 -0
- package/dist/react/components/chat/ChatEmptyState.d.ts +10 -0
- package/dist/react/components/chat/ChatEmptyState.d.ts.map +1 -0
- package/dist/react/components/chat/ChatInteractivePrompt/choices-prompt.d.ts +7 -0
- package/dist/react/components/chat/ChatInteractivePrompt/choices-prompt.d.ts.map +1 -0
- package/dist/react/components/chat/ChatInteractivePrompt/confirmation-prompt.d.ts +7 -0
- package/dist/react/components/chat/ChatInteractivePrompt/confirmation-prompt.d.ts.map +1 -0
- package/dist/react/components/chat/ChatInteractivePrompt/index.d.ts +7 -0
- package/dist/react/components/chat/ChatInteractivePrompt/index.d.ts.map +1 -0
- package/dist/react/components/chat/ChatInteractivePrompt/shell.d.ts +13 -0
- package/dist/react/components/chat/ChatInteractivePrompt/shell.d.ts.map +1 -0
- package/dist/react/components/chat/ChatInteractivePrompt/utils.d.ts +4 -0
- package/dist/react/components/chat/ChatInteractivePrompt/utils.d.ts.map +1 -0
- package/dist/react/components/chat/ChatMessage.d.ts +11 -0
- package/dist/react/components/chat/ChatMessage.d.ts.map +1 -0
- package/dist/react/components/chat/ChatMessageScroll.d.ts +8 -0
- package/dist/react/components/chat/ChatMessageScroll.d.ts.map +1 -0
- package/dist/react/components/chat/ChatReplySuggestions.d.ts +9 -0
- package/dist/react/components/chat/ChatReplySuggestions.d.ts.map +1 -0
- package/dist/react/components/chat/ComposerCommandMenu.d.ts +10 -0
- package/dist/react/components/chat/ComposerCommandMenu.d.ts.map +1 -0
- package/dist/react/components/chat/LlmSettingsStrip.d.ts +7 -0
- package/dist/react/components/chat/LlmSettingsStrip.d.ts.map +1 -0
- package/dist/react/components/chat/LlmSetupPrompt.d.ts +7 -0
- package/dist/react/components/chat/LlmSetupPrompt.d.ts.map +1 -0
- package/dist/react/components/chat/LlmUnavailableBanner.d.ts +6 -0
- package/dist/react/components/chat/LlmUnavailableBanner.d.ts.map +1 -0
- package/dist/react/components/chat/SuggestedPromptsList.d.ts +14 -0
- package/dist/react/components/chat/SuggestedPromptsList.d.ts.map +1 -0
- package/dist/react/components/chat/SuggestedPromptsStrip.d.ts +11 -0
- package/dist/react/components/chat/SuggestedPromptsStrip.d.ts.map +1 -0
- package/dist/react/components/chat/SystemPromptField.d.ts +10 -0
- package/dist/react/components/chat/SystemPromptField.d.ts.map +1 -0
- package/dist/react/components/highlighted-code.d.ts +8 -0
- package/dist/react/components/highlighted-code.d.ts.map +1 -0
- package/dist/react/context.d.ts +11 -0
- package/dist/react/context.d.ts.map +1 -0
- package/dist/react/hooks/use-composer-commands.d.ts +21 -0
- package/dist/react/hooks/use-composer-commands.d.ts.map +1 -0
- package/dist/react/hooks/use-suggested-prompts.d.ts +29 -0
- package/dist/react/hooks/use-suggested-prompts.d.ts.map +1 -0
- package/dist/react/index.d.ts +17 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/lib/parse-assistant-error.d.ts +9 -0
- package/dist/react/lib/parse-assistant-error.d.ts.map +1 -0
- package/dist/react/lib/prompt-icons.d.ts +5 -0
- package/dist/react/lib/prompt-icons.d.ts.map +1 -0
- package/dist/react/types.d.ts +69 -0
- package/dist/react/types.d.ts.map +1 -0
- package/dist/react/utils/cn.d.ts +2 -0
- package/dist/react/utils/cn.d.ts.map +1 -0
- package/package.json +16 -5
- package/src/core/chat-activity.ts +0 -107
- package/src/core/chat-commands.ts +0 -173
- package/src/core/chat-history.ts +0 -113
- package/src/core/chat-reply-suggestions-parse.ts +0 -119
- package/src/core/code-highlight.ts +0 -20
- package/src/core/create-assistant-store.ts +0 -639
- package/src/core/fetch-suggested-prompts.ts +0 -53
- package/src/core/index.ts +0 -125
- package/src/core/interactive-tools/choices.ts +0 -155
- package/src/core/interactive-tools/confirmation.ts +0 -63
- package/src/core/interactive-tools/constants.ts +0 -22
- package/src/core/interactive-tools/execute.ts +0 -70
- package/src/core/interactive-tools/index.ts +0 -41
- package/src/core/interactive-tools/suggestions.ts +0 -87
- package/src/core/interactive-tools/waiters.ts +0 -55
- package/src/core/llm-chat.ts +0 -686
- package/src/core/llm-config.ts +0 -101
- package/src/core/llm-models.ts +0 -96
- package/src/core/llm-provider.ts +0 -99
- package/src/core/llm-settings-storage.ts +0 -331
- package/src/core/llm-sse.ts +0 -166
- package/src/core/llm-types.ts +0 -52
- package/src/core/markdown-utils.ts +0 -11
- package/src/core/prepare-markdown.ts +0 -38
- package/src/core/types.ts +0 -86
- package/src/css.d.ts +0 -1
- package/src/react/Assistant.tsx +0 -358
- package/src/react/components/HighlightedJsonCode.tsx +0 -24
- package/src/react/components/MarkdownContent.tsx +0 -98
- package/src/react/components/MarkdownEditor.tsx +0 -60
- package/src/react/components/MermaidDiagram.tsx +0 -139
- package/src/react/components/ModelSelector.tsx +0 -243
- package/src/react/components/chat/AssistantErrorCallout.tsx +0 -79
- package/src/react/components/chat/ChatActivity.tsx +0 -274
- package/src/react/components/chat/ChatComposer.tsx +0 -189
- package/src/react/components/chat/ChatEmptyState.tsx +0 -145
- package/src/react/components/chat/ChatInteractivePrompt/choices-prompt.tsx +0 -262
- package/src/react/components/chat/ChatInteractivePrompt/confirmation-prompt.tsx +0 -97
- package/src/react/components/chat/ChatInteractivePrompt/index.tsx +0 -60
- package/src/react/components/chat/ChatInteractivePrompt/shell.tsx +0 -60
- package/src/react/components/chat/ChatInteractivePrompt/utils.ts +0 -14
- package/src/react/components/chat/ChatMessage.tsx +0 -150
- package/src/react/components/chat/ChatMessageScroll.tsx +0 -116
- package/src/react/components/chat/ChatReplySuggestions.tsx +0 -231
- package/src/react/components/chat/ComposerCommandMenu.tsx +0 -69
- package/src/react/components/chat/LlmSettingsStrip.tsx +0 -348
- package/src/react/components/chat/LlmSetupPrompt.tsx +0 -58
- package/src/react/components/chat/LlmUnavailableBanner.tsx +0 -11
- package/src/react/components/chat/SuggestedPromptsList.tsx +0 -121
- package/src/react/components/chat/SuggestedPromptsStrip.tsx +0 -72
- package/src/react/components/chat/SystemPromptField.tsx +0 -107
- package/src/react/components/highlighted-code.tsx +0 -107
- package/src/react/context.tsx +0 -72
- package/src/react/hooks/use-composer-commands.ts +0 -129
- package/src/react/hooks/use-suggested-prompts.ts +0 -128
- package/src/react/index.ts +0 -39
- package/src/react/lib/parse-assistant-error.ts +0 -96
- package/src/react/lib/prompt-icons.ts +0 -40
- package/src/react/types.ts +0 -83
- package/src/react/utils/cn.ts +0 -5
- package/test/buildLlmHistory.test.ts +0 -95
- package/test/llm-config.test.ts +0 -72
- package/test/llmSettingsStorage.test.ts +0 -121
- package/test/parse-assistant-error.test.ts +0 -24
- package/tsconfig.json +0 -8
- /package/{src/styles/assistant.css → dist/styles.css} +0 -0
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
import { Check, ListChecks } from "lucide-react";
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
3
|
-
import type {
|
|
4
|
-
ChoiceOption,
|
|
5
|
-
ChoicesToolArgs,
|
|
6
|
-
ChoicesToolResult,
|
|
7
|
-
} from "../../../../core/interactive-tools/index.ts";
|
|
8
|
-
import { useAssistantActions } from "../../../context.tsx";
|
|
9
|
-
import { cn } from "../../../utils/cn.ts";
|
|
10
|
-
import { InteractivePromptShell } from "./shell.tsx";
|
|
11
|
-
import { isCompactTokenLabel, optionKeyLabel } from "./utils.ts";
|
|
12
|
-
|
|
13
|
-
function ChoiceOptionCard({
|
|
14
|
-
option,
|
|
15
|
-
index,
|
|
16
|
-
checked,
|
|
17
|
-
inputType,
|
|
18
|
-
name,
|
|
19
|
-
disabled,
|
|
20
|
-
onSelect,
|
|
21
|
-
}: {
|
|
22
|
-
option: ChoiceOption;
|
|
23
|
-
index: number;
|
|
24
|
-
checked: boolean;
|
|
25
|
-
inputType: "radio" | "checkbox";
|
|
26
|
-
name: string;
|
|
27
|
-
disabled: boolean;
|
|
28
|
-
onSelect: (checked: boolean) => void;
|
|
29
|
-
}) {
|
|
30
|
-
const inputId = `${name}-${option.id}`;
|
|
31
|
-
const keyLabel = optionKeyLabel(index);
|
|
32
|
-
const compactLabel = isCompactTokenLabel(option.label);
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<label
|
|
36
|
-
htmlFor={inputId}
|
|
37
|
-
className={cn(
|
|
38
|
-
"assistant-interactive-choice group",
|
|
39
|
-
checked && "assistant-interactive-choice--selected",
|
|
40
|
-
disabled && "assistant-interactive-choice--disabled",
|
|
41
|
-
)}
|
|
42
|
-
>
|
|
43
|
-
<input
|
|
44
|
-
id={inputId}
|
|
45
|
-
type={inputType}
|
|
46
|
-
name={inputType === "radio" ? name : undefined}
|
|
47
|
-
checked={checked}
|
|
48
|
-
disabled={disabled}
|
|
49
|
-
onChange={(event) =>
|
|
50
|
-
onSelect(inputType === "radio" ? true : event.target.checked)
|
|
51
|
-
}
|
|
52
|
-
className="peer sr-only"
|
|
53
|
-
/>
|
|
54
|
-
|
|
55
|
-
<span
|
|
56
|
-
aria-hidden
|
|
57
|
-
className={cn(
|
|
58
|
-
"assistant-interactive-choice__check",
|
|
59
|
-
checked && "assistant-interactive-choice__check--on",
|
|
60
|
-
)}
|
|
61
|
-
>
|
|
62
|
-
{checked ? <Check className="size-2.5 stroke-[3]" /> : null}
|
|
63
|
-
</span>
|
|
64
|
-
|
|
65
|
-
<span className="assistant-interactive-choice__content">
|
|
66
|
-
<span
|
|
67
|
-
className={cn(
|
|
68
|
-
"assistant-interactive-choice__label",
|
|
69
|
-
compactLabel && "assistant-interactive-choice__label--mono",
|
|
70
|
-
)}
|
|
71
|
-
>
|
|
72
|
-
{option.label}
|
|
73
|
-
</span>
|
|
74
|
-
{option.description ? (
|
|
75
|
-
<span className="assistant-interactive-choice__description">
|
|
76
|
-
{option.description}
|
|
77
|
-
</span>
|
|
78
|
-
) : null}
|
|
79
|
-
</span>
|
|
80
|
-
|
|
81
|
-
<kbd className="assistant-interactive-kbd">{keyLabel}</kbd>
|
|
82
|
-
</label>
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function ChoicesPrompt({
|
|
87
|
-
args,
|
|
88
|
-
callId,
|
|
89
|
-
disabled,
|
|
90
|
-
}: {
|
|
91
|
-
args: ChoicesToolArgs;
|
|
92
|
-
callId: string;
|
|
93
|
-
disabled: boolean;
|
|
94
|
-
}) {
|
|
95
|
-
const { submitInteractiveToolResult, cancelInteractiveToolResult } =
|
|
96
|
-
useAssistantActions();
|
|
97
|
-
const [selectedIds, setSelectedIds] = useState<string[]>([]);
|
|
98
|
-
|
|
99
|
-
const selectionCount = selectedIds.length;
|
|
100
|
-
const meetsMinimum = selectionCount >= args.minSelections;
|
|
101
|
-
const meetsMaximum =
|
|
102
|
-
args.maxSelections === undefined
|
|
103
|
-
? true
|
|
104
|
-
: selectionCount <= args.maxSelections;
|
|
105
|
-
|
|
106
|
-
function submitSelection(ids: string[]) {
|
|
107
|
-
const result: ChoicesToolResult = { selected: ids };
|
|
108
|
-
submitInteractiveToolResult(callId, result);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function toggleOption(optionId: string, checked: boolean) {
|
|
112
|
-
if (args.allowMultiple) {
|
|
113
|
-
setSelectedIds((current) => {
|
|
114
|
-
if (checked) {
|
|
115
|
-
if (
|
|
116
|
-
args.maxSelections !== undefined &&
|
|
117
|
-
current.length >= args.maxSelections
|
|
118
|
-
) {
|
|
119
|
-
return current;
|
|
120
|
-
}
|
|
121
|
-
return [...new Set([...current, optionId])];
|
|
122
|
-
}
|
|
123
|
-
return current.filter((id) => id !== optionId);
|
|
124
|
-
});
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const next = checked ? [optionId] : [];
|
|
129
|
-
setSelectedIds(next);
|
|
130
|
-
if (checked && !disabled) {
|
|
131
|
-
submitSelection(next);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function handleSubmit() {
|
|
136
|
-
if (!meetsMinimum || !meetsMaximum) return;
|
|
137
|
-
submitSelection(selectedIds);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
useEffect(() => {
|
|
141
|
-
if (disabled) return;
|
|
142
|
-
|
|
143
|
-
function onKeyDown(event: KeyboardEvent) {
|
|
144
|
-
if (event.key === "Escape") {
|
|
145
|
-
event.preventDefault();
|
|
146
|
-
cancelInteractiveToolResult(callId);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (
|
|
151
|
-
event.key === "Enter" &&
|
|
152
|
-
args.allowMultiple &&
|
|
153
|
-
meetsMinimum &&
|
|
154
|
-
meetsMaximum
|
|
155
|
-
) {
|
|
156
|
-
event.preventDefault();
|
|
157
|
-
submitInteractiveToolResult(callId, { selected: selectedIds });
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (!/^[1-9]$/.test(event.key)) return;
|
|
162
|
-
|
|
163
|
-
const index = Number(event.key) - 1;
|
|
164
|
-
const option = args.options[index];
|
|
165
|
-
if (!option) return;
|
|
166
|
-
|
|
167
|
-
event.preventDefault();
|
|
168
|
-
if (args.allowMultiple) {
|
|
169
|
-
setSelectedIds((current) => {
|
|
170
|
-
const isSelected = current.includes(option.id);
|
|
171
|
-
if (isSelected) {
|
|
172
|
-
return current.filter((id) => id !== option.id);
|
|
173
|
-
}
|
|
174
|
-
if (
|
|
175
|
-
args.maxSelections !== undefined &&
|
|
176
|
-
current.length >= args.maxSelections
|
|
177
|
-
) {
|
|
178
|
-
return current;
|
|
179
|
-
}
|
|
180
|
-
return [...new Set([...current, option.id])];
|
|
181
|
-
});
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const next = [option.id];
|
|
186
|
-
setSelectedIds(next);
|
|
187
|
-
submitInteractiveToolResult(callId, { selected: next });
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
window.addEventListener("keydown", onKeyDown);
|
|
191
|
-
return () => window.removeEventListener("keydown", onKeyDown);
|
|
192
|
-
}, [
|
|
193
|
-
disabled,
|
|
194
|
-
callId,
|
|
195
|
-
args.options,
|
|
196
|
-
args.allowMultiple,
|
|
197
|
-
args.maxSelections,
|
|
198
|
-
selectedIds,
|
|
199
|
-
meetsMinimum,
|
|
200
|
-
meetsMaximum,
|
|
201
|
-
cancelInteractiveToolResult,
|
|
202
|
-
submitInteractiveToolResult,
|
|
203
|
-
]);
|
|
204
|
-
|
|
205
|
-
const title = args.allowMultiple ? "Choose options" : "Choose one";
|
|
206
|
-
|
|
207
|
-
return (
|
|
208
|
-
<InteractivePromptShell
|
|
209
|
-
icon={ListChecks}
|
|
210
|
-
title={title}
|
|
211
|
-
keyboardHint={disabled ? undefined : "1–9 · Enter · Esc"}
|
|
212
|
-
actions={
|
|
213
|
-
args.allowMultiple ? (
|
|
214
|
-
<>
|
|
215
|
-
<button
|
|
216
|
-
type="button"
|
|
217
|
-
className="btn btn-secondary btn-compact"
|
|
218
|
-
disabled={disabled}
|
|
219
|
-
onClick={() => cancelInteractiveToolResult(callId)}
|
|
220
|
-
>
|
|
221
|
-
Cancel
|
|
222
|
-
</button>
|
|
223
|
-
<button
|
|
224
|
-
type="button"
|
|
225
|
-
className="btn btn-primary btn-compact"
|
|
226
|
-
disabled={disabled || !meetsMinimum || !meetsMaximum}
|
|
227
|
-
onClick={handleSubmit}
|
|
228
|
-
>
|
|
229
|
-
{args.submitLabel}
|
|
230
|
-
{selectionCount > 0 ? ` (${selectionCount})` : ""}
|
|
231
|
-
</button>
|
|
232
|
-
</>
|
|
233
|
-
) : (
|
|
234
|
-
<button
|
|
235
|
-
type="button"
|
|
236
|
-
className="btn btn-secondary btn-compact"
|
|
237
|
-
disabled={disabled}
|
|
238
|
-
onClick={() => cancelInteractiveToolResult(callId)}
|
|
239
|
-
>
|
|
240
|
-
Cancel
|
|
241
|
-
</button>
|
|
242
|
-
)
|
|
243
|
-
}
|
|
244
|
-
>
|
|
245
|
-
<p className="assistant-interactive-prompt__message">{args.message}</p>
|
|
246
|
-
<div className="assistant-interactive-choice-list">
|
|
247
|
-
{args.options.map((option, index) => (
|
|
248
|
-
<ChoiceOptionCard
|
|
249
|
-
key={option.id}
|
|
250
|
-
option={option}
|
|
251
|
-
index={index}
|
|
252
|
-
checked={selectedIds.includes(option.id)}
|
|
253
|
-
inputType={args.allowMultiple ? "checkbox" : "radio"}
|
|
254
|
-
name={`chat-choice-${callId}`}
|
|
255
|
-
disabled={disabled}
|
|
256
|
-
onSelect={(checked) => toggleOption(option.id, checked)}
|
|
257
|
-
/>
|
|
258
|
-
))}
|
|
259
|
-
</div>
|
|
260
|
-
</InteractivePromptShell>
|
|
261
|
-
);
|
|
262
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { AlertTriangle, ShieldCheck } from "lucide-react";
|
|
2
|
-
import { useEffect } from "react";
|
|
3
|
-
import type { ConfirmationToolArgs } from "../../../../core/interactive-tools/index.ts";
|
|
4
|
-
import { useAssistantActions } from "../../../context.tsx";
|
|
5
|
-
import { cn } from "../../../utils/cn.ts";
|
|
6
|
-
import { InteractivePromptShell } from "./shell.tsx";
|
|
7
|
-
import { isDestructiveAction } from "./utils.ts";
|
|
8
|
-
|
|
9
|
-
export function ConfirmationPrompt({
|
|
10
|
-
args,
|
|
11
|
-
callId,
|
|
12
|
-
disabled,
|
|
13
|
-
}: {
|
|
14
|
-
args: ConfirmationToolArgs;
|
|
15
|
-
callId: string;
|
|
16
|
-
disabled: boolean;
|
|
17
|
-
}) {
|
|
18
|
-
const { submitInteractiveToolResult, cancelInteractiveToolResult } =
|
|
19
|
-
useAssistantActions();
|
|
20
|
-
|
|
21
|
-
const destructive = isDestructiveAction(args.action);
|
|
22
|
-
|
|
23
|
-
function handleConfirm() {
|
|
24
|
-
submitInteractiveToolResult(callId, { confirmed: true });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function handleCancel() {
|
|
28
|
-
cancelInteractiveToolResult(callId);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
if (disabled) return;
|
|
33
|
-
|
|
34
|
-
function onKeyDown(event: KeyboardEvent) {
|
|
35
|
-
if (event.key === "Enter" && !event.shiftKey) {
|
|
36
|
-
event.preventDefault();
|
|
37
|
-
submitInteractiveToolResult(callId, { confirmed: true });
|
|
38
|
-
}
|
|
39
|
-
if (event.key === "Escape") {
|
|
40
|
-
event.preventDefault();
|
|
41
|
-
cancelInteractiveToolResult(callId);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
window.addEventListener("keydown", onKeyDown);
|
|
46
|
-
return () => window.removeEventListener("keydown", onKeyDown);
|
|
47
|
-
}, [
|
|
48
|
-
disabled,
|
|
49
|
-
callId,
|
|
50
|
-
submitInteractiveToolResult,
|
|
51
|
-
cancelInteractiveToolResult,
|
|
52
|
-
]);
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<InteractivePromptShell
|
|
56
|
-
icon={destructive ? AlertTriangle : ShieldCheck}
|
|
57
|
-
title={destructive ? "Confirm deletion" : "Confirm"}
|
|
58
|
-
tone={destructive ? "caution" : "default"}
|
|
59
|
-
keyboardHint={disabled ? undefined : "Enter · Esc"}
|
|
60
|
-
actions={
|
|
61
|
-
<>
|
|
62
|
-
<button
|
|
63
|
-
type="button"
|
|
64
|
-
className="btn btn-secondary btn-compact"
|
|
65
|
-
disabled={disabled}
|
|
66
|
-
onClick={handleCancel}
|
|
67
|
-
>
|
|
68
|
-
{args.cancelLabel}
|
|
69
|
-
</button>
|
|
70
|
-
<button
|
|
71
|
-
type="button"
|
|
72
|
-
className={cn(
|
|
73
|
-
"btn btn-compact",
|
|
74
|
-
destructive ? "btn-danger btn-danger--solid" : "btn-primary",
|
|
75
|
-
)}
|
|
76
|
-
disabled={disabled}
|
|
77
|
-
onClick={handleConfirm}
|
|
78
|
-
>
|
|
79
|
-
{args.confirmLabel}
|
|
80
|
-
</button>
|
|
81
|
-
</>
|
|
82
|
-
}
|
|
83
|
-
>
|
|
84
|
-
<p className="assistant-interactive-prompt__message">{args.message}</p>
|
|
85
|
-
{args.action ? (
|
|
86
|
-
<p
|
|
87
|
-
className={cn(
|
|
88
|
-
"assistant-interactive-prompt__action",
|
|
89
|
-
destructive && "assistant-interactive-prompt__action--caution",
|
|
90
|
-
)}
|
|
91
|
-
>
|
|
92
|
-
{args.action}
|
|
93
|
-
</p>
|
|
94
|
-
) : null}
|
|
95
|
-
</InteractivePromptShell>
|
|
96
|
-
);
|
|
97
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
parseChoicesArgs,
|
|
3
|
-
parseConfirmationArgs,
|
|
4
|
-
REQUEST_CHOICES_TOOL,
|
|
5
|
-
REQUEST_CONFIRMATION_TOOL,
|
|
6
|
-
} from "../../../../core/interactive-tools/index.ts";
|
|
7
|
-
import { useAssistant } from "../../../context.tsx";
|
|
8
|
-
import { ChoicesPrompt } from "./choices-prompt.tsx";
|
|
9
|
-
import { ConfirmationPrompt } from "./confirmation-prompt.tsx";
|
|
10
|
-
|
|
11
|
-
export function ChatInteractivePrompt({
|
|
12
|
-
toolName,
|
|
13
|
-
args,
|
|
14
|
-
callId,
|
|
15
|
-
active,
|
|
16
|
-
}: {
|
|
17
|
-
toolName: string;
|
|
18
|
-
args: Record<string, unknown>;
|
|
19
|
-
callId?: string;
|
|
20
|
-
active: boolean;
|
|
21
|
-
}) {
|
|
22
|
-
const chatLoading = useAssistant((state) => state.chatLoading);
|
|
23
|
-
const disabled = !chatLoading;
|
|
24
|
-
|
|
25
|
-
if (!active || !callId) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
if (toolName === REQUEST_CONFIRMATION_TOOL) {
|
|
31
|
-
return (
|
|
32
|
-
<ConfirmationPrompt
|
|
33
|
-
args={parseConfirmationArgs(args)}
|
|
34
|
-
callId={callId}
|
|
35
|
-
disabled={disabled}
|
|
36
|
-
/>
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (toolName === REQUEST_CHOICES_TOOL) {
|
|
41
|
-
return (
|
|
42
|
-
<ChoicesPrompt
|
|
43
|
-
args={parseChoicesArgs(args)}
|
|
44
|
-
callId={callId}
|
|
45
|
-
disabled={disabled}
|
|
46
|
-
/>
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
} catch (error) {
|
|
50
|
-
return (
|
|
51
|
-
<p className="text-[11px] text-[var(--text-danger)]">
|
|
52
|
-
{error instanceof Error
|
|
53
|
-
? error.message
|
|
54
|
-
: "Invalid interactive tool arguments"}
|
|
55
|
-
</p>
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { LucideIcon } from "lucide-react";
|
|
2
|
-
import type { ReactNode } from "react";
|
|
3
|
-
import { cn } from "../../../utils/cn.ts";
|
|
4
|
-
|
|
5
|
-
type InteractivePromptShellProps = {
|
|
6
|
-
icon: LucideIcon;
|
|
7
|
-
title: string;
|
|
8
|
-
tone?: "default" | "caution";
|
|
9
|
-
children: ReactNode;
|
|
10
|
-
actions?: ReactNode;
|
|
11
|
-
keyboardHint?: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export function InteractivePromptShell({
|
|
15
|
-
icon: Icon,
|
|
16
|
-
title,
|
|
17
|
-
tone = "default",
|
|
18
|
-
children,
|
|
19
|
-
actions,
|
|
20
|
-
keyboardHint,
|
|
21
|
-
}: InteractivePromptShellProps) {
|
|
22
|
-
return (
|
|
23
|
-
<div
|
|
24
|
-
className={cn(
|
|
25
|
-
"assistant-interactive-prompt",
|
|
26
|
-
tone === "caution" && "assistant-interactive-prompt--caution",
|
|
27
|
-
)}
|
|
28
|
-
>
|
|
29
|
-
<div className="assistant-interactive-prompt__main">
|
|
30
|
-
<span
|
|
31
|
-
className={cn(
|
|
32
|
-
"assistant-interactive-prompt__icon",
|
|
33
|
-
tone === "caution" && "assistant-interactive-prompt__icon--caution",
|
|
34
|
-
)}
|
|
35
|
-
aria-hidden
|
|
36
|
-
>
|
|
37
|
-
<Icon size={13} strokeWidth={2.25} />
|
|
38
|
-
</span>
|
|
39
|
-
|
|
40
|
-
<div className="assistant-interactive-prompt__content min-w-0 flex-1">
|
|
41
|
-
<p className="assistant-interactive-prompt__title">{title}</p>
|
|
42
|
-
{children ? (
|
|
43
|
-
<div className="assistant-interactive-prompt__body">{children}</div>
|
|
44
|
-
) : null}
|
|
45
|
-
</div>
|
|
46
|
-
</div>
|
|
47
|
-
|
|
48
|
-
{actions ? (
|
|
49
|
-
<div className="assistant-interactive-prompt__bar">
|
|
50
|
-
{keyboardHint ? (
|
|
51
|
-
<p className="assistant-interactive-prompt__hint">{keyboardHint}</p>
|
|
52
|
-
) : (
|
|
53
|
-
<span aria-hidden />
|
|
54
|
-
)}
|
|
55
|
-
<div className="assistant-interactive-prompt__actions">{actions}</div>
|
|
56
|
-
</div>
|
|
57
|
-
) : null}
|
|
58
|
-
</div>
|
|
59
|
-
);
|
|
60
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export function isDestructiveAction(action?: string): boolean {
|
|
2
|
-
if (!action) return false;
|
|
3
|
-
return /\b(delete|remove|disable|destroy|clear|reset|drop|purge|unlink|permanently)\b/i.test(
|
|
4
|
-
action,
|
|
5
|
-
);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function optionKeyLabel(index: number): string {
|
|
9
|
-
return String(index + 1);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function isCompactTokenLabel(label: string): boolean {
|
|
13
|
-
return label.length >= 16 && !/\s/.test(label);
|
|
14
|
-
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { Bot, User } from "lucide-react";
|
|
2
|
-
import { SUGGEST_REPLIES_TOOL } from "../../../core/interactive-tools/index.ts";
|
|
3
|
-
import { isLlmUnavailableMessage } from "../../../core/llm-config.ts";
|
|
4
|
-
import type { AssistantMessage } from "../../../core/types.ts";
|
|
5
|
-
import { MarkdownContent } from "../MarkdownContent.tsx";
|
|
6
|
-
import { AssistantErrorCallout } from "./AssistantErrorCallout.tsx";
|
|
7
|
-
import { ChatActivity } from "./ChatActivity.tsx";
|
|
8
|
-
import { ChatReplySuggestions } from "./ChatReplySuggestions.tsx";
|
|
9
|
-
import { LlmSetupPrompt } from "./LlmSetupPrompt.tsx";
|
|
10
|
-
|
|
11
|
-
function TypingIndicator() {
|
|
12
|
-
return (
|
|
13
|
-
<output className="assistant-typing" aria-live="polite">
|
|
14
|
-
{[0, 1, 2].map((index) => (
|
|
15
|
-
<span
|
|
16
|
-
key={index}
|
|
17
|
-
className="assistant-typing-dot"
|
|
18
|
-
style={{ animationDelay: `${index * 160}ms` }}
|
|
19
|
-
/>
|
|
20
|
-
))}
|
|
21
|
-
<span className="sr-only">Assistant is thinking</span>
|
|
22
|
-
</output>
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface ChatMessageViewProps {
|
|
27
|
-
message: AssistantMessage;
|
|
28
|
-
onSuggestionSelect?: (reply: string) => void;
|
|
29
|
-
onOpenLlmSettings?: () => void;
|
|
30
|
-
onRetryError?: () => void;
|
|
31
|
-
retryErrorLoading?: boolean;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function ChatMessageView({
|
|
35
|
-
message,
|
|
36
|
-
onSuggestionSelect,
|
|
37
|
-
onOpenLlmSettings,
|
|
38
|
-
onRetryError,
|
|
39
|
-
retryErrorLoading,
|
|
40
|
-
}: ChatMessageViewProps) {
|
|
41
|
-
const isUser = message.role === "user";
|
|
42
|
-
const streaming = Boolean(message.streaming);
|
|
43
|
-
const activity = message.activity ?? [];
|
|
44
|
-
const visibleActivity =
|
|
45
|
-
message.replySuggestions && !streaming
|
|
46
|
-
? activity.filter((step) => step.name !== SUGGEST_REPLIES_TOOL)
|
|
47
|
-
: activity;
|
|
48
|
-
const hasActivity = visibleActivity.length > 0;
|
|
49
|
-
const hasActiveStep = visibleActivity.some(
|
|
50
|
-
(step) => step.status === "active",
|
|
51
|
-
);
|
|
52
|
-
const showTyping =
|
|
53
|
-
!isUser &&
|
|
54
|
-
streaming &&
|
|
55
|
-
!message.content.trim() &&
|
|
56
|
-
!hasActivity &&
|
|
57
|
-
!message.isError;
|
|
58
|
-
const showCard =
|
|
59
|
-
!isUser &&
|
|
60
|
-
(Boolean(message.content.trim()) ||
|
|
61
|
-
showTyping ||
|
|
62
|
-
hasActivity ||
|
|
63
|
-
message.isError ||
|
|
64
|
-
Boolean(message.replySuggestions));
|
|
65
|
-
|
|
66
|
-
if (isUser) {
|
|
67
|
-
return (
|
|
68
|
-
<article className="assistant-message assistant-message--user">
|
|
69
|
-
<div className="assistant-user-row">
|
|
70
|
-
<div className="assistant-user-bubble">
|
|
71
|
-
<p className="assistant-user-bubble__text">{message.content}</p>
|
|
72
|
-
</div>
|
|
73
|
-
<div className="assistant-user-avatar" aria-hidden>
|
|
74
|
-
<User size={14} strokeWidth={2.25} />
|
|
75
|
-
</div>
|
|
76
|
-
</div>
|
|
77
|
-
</article>
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (isLlmUnavailableMessage(message) && onOpenLlmSettings) {
|
|
82
|
-
return (
|
|
83
|
-
<article className="assistant-message assistant-message--assistant">
|
|
84
|
-
<div className="assistant-assistant-row">
|
|
85
|
-
<div className="assistant-bot-avatar" aria-hidden>
|
|
86
|
-
<Bot size={14} strokeWidth={2.25} />
|
|
87
|
-
</div>
|
|
88
|
-
<LlmSetupPrompt variant="inline" onConfigure={onOpenLlmSettings} />
|
|
89
|
-
</div>
|
|
90
|
-
</article>
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return (
|
|
95
|
-
<article className="assistant-message assistant-message--assistant">
|
|
96
|
-
<div className="assistant-assistant-row">
|
|
97
|
-
<div className="assistant-bot-avatar" aria-hidden>
|
|
98
|
-
<Bot size={14} strokeWidth={2.25} />
|
|
99
|
-
</div>
|
|
100
|
-
{showCard ? (
|
|
101
|
-
<div
|
|
102
|
-
className={`assistant-assistant-card${message.isError ? " assistant-assistant-card--error" : ""}`}
|
|
103
|
-
>
|
|
104
|
-
<header className="assistant-assistant-card__meta">
|
|
105
|
-
<span className="assistant-role-label">Assistant</span>
|
|
106
|
-
</header>
|
|
107
|
-
|
|
108
|
-
{message.isError ? (
|
|
109
|
-
<div className="assistant-assistant-card__error">
|
|
110
|
-
<AssistantErrorCallout
|
|
111
|
-
error={message.content}
|
|
112
|
-
context="chat"
|
|
113
|
-
variant="embedded"
|
|
114
|
-
onRetry={onRetryError}
|
|
115
|
-
retryLoading={retryErrorLoading}
|
|
116
|
-
/>
|
|
117
|
-
</div>
|
|
118
|
-
) : message.content.trim() ? (
|
|
119
|
-
<div className="assistant-markdown">
|
|
120
|
-
<MarkdownContent
|
|
121
|
-
content={message.content}
|
|
122
|
-
streaming={streaming}
|
|
123
|
-
/>
|
|
124
|
-
{streaming && !hasActiveStep ? (
|
|
125
|
-
<span className="assistant-markdown__cursor" aria-hidden />
|
|
126
|
-
) : null}
|
|
127
|
-
</div>
|
|
128
|
-
) : showTyping ? (
|
|
129
|
-
<div className="assistant-assistant-card__typing">
|
|
130
|
-
<TypingIndicator />
|
|
131
|
-
</div>
|
|
132
|
-
) : null}
|
|
133
|
-
|
|
134
|
-
{hasActivity ? (
|
|
135
|
-
<ChatActivity steps={visibleActivity} streaming={streaming} />
|
|
136
|
-
) : null}
|
|
137
|
-
|
|
138
|
-
{message.replySuggestions && !streaming && onSuggestionSelect ? (
|
|
139
|
-
<ChatReplySuggestions
|
|
140
|
-
suggestions={message.replySuggestions}
|
|
141
|
-
disabled={streaming}
|
|
142
|
-
onSelect={onSuggestionSelect}
|
|
143
|
-
/>
|
|
144
|
-
) : null}
|
|
145
|
-
</div>
|
|
146
|
-
) : null}
|
|
147
|
-
</div>
|
|
148
|
-
</article>
|
|
149
|
-
);
|
|
150
|
-
}
|