@4djs/assistant 0.0.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/README.md +322 -0
- package/package.json +41 -0
- package/src/core/chat-activity.ts +107 -0
- package/src/core/chat-commands.ts +173 -0
- package/src/core/chat-history.ts +113 -0
- package/src/core/chat-reply-suggestions-parse.ts +119 -0
- package/src/core/code-highlight.ts +20 -0
- package/src/core/create-assistant-store.ts +639 -0
- package/src/core/fetch-suggested-prompts.ts +53 -0
- package/src/core/index.ts +125 -0
- package/src/core/interactive-tools/choices.ts +155 -0
- package/src/core/interactive-tools/confirmation.ts +63 -0
- package/src/core/interactive-tools/constants.ts +22 -0
- package/src/core/interactive-tools/execute.ts +70 -0
- package/src/core/interactive-tools/index.ts +41 -0
- package/src/core/interactive-tools/suggestions.ts +87 -0
- package/src/core/interactive-tools/waiters.ts +55 -0
- package/src/core/llm-chat.ts +686 -0
- package/src/core/llm-config.ts +101 -0
- package/src/core/llm-models.ts +96 -0
- package/src/core/llm-provider.ts +99 -0
- package/src/core/llm-settings-storage.ts +331 -0
- package/src/core/llm-sse.ts +166 -0
- package/src/core/llm-types.ts +52 -0
- package/src/core/markdown-utils.ts +11 -0
- package/src/core/prepare-markdown.ts +38 -0
- package/src/core/types.ts +86 -0
- package/src/css.d.ts +1 -0
- package/src/react/Assistant.tsx +358 -0
- package/src/react/components/HighlightedJsonCode.tsx +24 -0
- package/src/react/components/MarkdownContent.tsx +98 -0
- package/src/react/components/MarkdownEditor.tsx +60 -0
- package/src/react/components/MermaidDiagram.tsx +139 -0
- package/src/react/components/ModelSelector.tsx +243 -0
- package/src/react/components/chat/AssistantErrorCallout.tsx +79 -0
- package/src/react/components/chat/ChatActivity.tsx +274 -0
- package/src/react/components/chat/ChatComposer.tsx +189 -0
- package/src/react/components/chat/ChatEmptyState.tsx +145 -0
- package/src/react/components/chat/ChatInteractivePrompt/choices-prompt.tsx +262 -0
- package/src/react/components/chat/ChatInteractivePrompt/confirmation-prompt.tsx +97 -0
- package/src/react/components/chat/ChatInteractivePrompt/index.tsx +60 -0
- package/src/react/components/chat/ChatInteractivePrompt/shell.tsx +60 -0
- package/src/react/components/chat/ChatInteractivePrompt/utils.ts +14 -0
- package/src/react/components/chat/ChatMessage.tsx +150 -0
- package/src/react/components/chat/ChatMessageScroll.tsx +116 -0
- package/src/react/components/chat/ChatReplySuggestions.tsx +231 -0
- package/src/react/components/chat/ComposerCommandMenu.tsx +69 -0
- package/src/react/components/chat/LlmSettingsStrip.tsx +348 -0
- package/src/react/components/chat/LlmSetupPrompt.tsx +58 -0
- package/src/react/components/chat/LlmUnavailableBanner.tsx +11 -0
- package/src/react/components/chat/SuggestedPromptsList.tsx +121 -0
- package/src/react/components/chat/SuggestedPromptsStrip.tsx +72 -0
- package/src/react/components/chat/SystemPromptField.tsx +107 -0
- package/src/react/components/highlighted-code.tsx +107 -0
- package/src/react/context.tsx +72 -0
- package/src/react/hooks/use-composer-commands.ts +129 -0
- package/src/react/hooks/use-suggested-prompts.ts +128 -0
- package/src/react/index.ts +39 -0
- package/src/react/lib/parse-assistant-error.ts +96 -0
- package/src/react/lib/prompt-icons.ts +40 -0
- package/src/react/types.ts +83 -0
- package/src/react/utils/cn.ts +5 -0
- package/src/styles/assistant.css +3009 -0
- package/test/buildLlmHistory.test.ts +95 -0
- package/test/llm-config.test.ts +72 -0
- package/test/llmSettingsStorage.test.ts +121 -0
- package/test/parse-assistant-error.test.ts +24 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { LucideIcon } from "lucide-react";
|
|
2
|
+
import {
|
|
3
|
+
Code,
|
|
4
|
+
Database,
|
|
5
|
+
Layers,
|
|
6
|
+
Search,
|
|
7
|
+
Sparkles,
|
|
8
|
+
Table,
|
|
9
|
+
Terminal,
|
|
10
|
+
Wrench,
|
|
11
|
+
Zap,
|
|
12
|
+
} from "lucide-react";
|
|
13
|
+
|
|
14
|
+
const PROMPT_ICONS: Record<string, LucideIcon> = {
|
|
15
|
+
database: Database,
|
|
16
|
+
db: Database,
|
|
17
|
+
search: Search,
|
|
18
|
+
find: Search,
|
|
19
|
+
terminal: Terminal,
|
|
20
|
+
shell: Terminal,
|
|
21
|
+
wrench: Wrench,
|
|
22
|
+
tool: Wrench,
|
|
23
|
+
sparkles: Sparkles,
|
|
24
|
+
magic: Sparkles,
|
|
25
|
+
table: Table,
|
|
26
|
+
grid: Table,
|
|
27
|
+
code: Code,
|
|
28
|
+
layers: Layers,
|
|
29
|
+
stack: Layers,
|
|
30
|
+
zap: Zap,
|
|
31
|
+
lightning: Zap,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export function resolvePromptIcon(name?: string): LucideIcon | undefined {
|
|
35
|
+
if (!name) return undefined;
|
|
36
|
+
const key = name.trim().toLowerCase();
|
|
37
|
+
return PROMPT_ICONS[key];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { Sparkles as DEFAULT_PROMPT_ICON };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { LucideIcon } from "lucide-react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import type { AssistantStore } from "../core/create-assistant-store.ts";
|
|
4
|
+
import type {
|
|
5
|
+
AssistantStoreDependencies,
|
|
6
|
+
AssistantSuggestedPrompt,
|
|
7
|
+
AssistantToolDefinition,
|
|
8
|
+
} from "../core/types.ts";
|
|
9
|
+
|
|
10
|
+
export interface AssistantSuggestedPromptWithIcon
|
|
11
|
+
extends Omit<AssistantSuggestedPrompt, "icon"> {
|
|
12
|
+
icon?: LucideIcon;
|
|
13
|
+
hint?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface AssistantEmptyStateConfig {
|
|
17
|
+
title: string;
|
|
18
|
+
description: string;
|
|
19
|
+
/** Static fallback prompts when LLM is disabled or fetch fails */
|
|
20
|
+
suggestedPrompts?: AssistantSuggestedPromptWithIcon[];
|
|
21
|
+
/** Allow fetching contextual prompts via LLM (manual trigger; default: true) */
|
|
22
|
+
dynamicSuggestedPrompts?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface AssistantHeaderConfig {
|
|
26
|
+
title?: string;
|
|
27
|
+
subtitle?: string;
|
|
28
|
+
icon?: LucideIcon;
|
|
29
|
+
showClearButton?: boolean;
|
|
30
|
+
/** Show button to generate LLM suggested prompts (default: true when fetchSuggestedPrompts is set) */
|
|
31
|
+
showSuggestionsButton?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface AssistantUiConfig {
|
|
35
|
+
composerPlaceholder?: string;
|
|
36
|
+
showModelSelector?: boolean;
|
|
37
|
+
/** Show LLM settings button in the composer footer (default: true) */
|
|
38
|
+
showLlmSettings?: boolean;
|
|
39
|
+
maxWidth?: string;
|
|
40
|
+
className?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface AssistantConfig extends AssistantStoreDependencies {
|
|
44
|
+
emptyState?: AssistantEmptyStateConfig;
|
|
45
|
+
header?: AssistantHeaderConfig;
|
|
46
|
+
ui?: AssistantUiConfig;
|
|
47
|
+
/** Load LLM config on mount (default: true) */
|
|
48
|
+
autoLoadLlmStatus?: boolean;
|
|
49
|
+
/** Optional hook to fetch contextual empty-state prompts via the configured LLM */
|
|
50
|
+
fetchSuggestedPrompts?: (ctx: {
|
|
51
|
+
llmEnabled: boolean;
|
|
52
|
+
model: string | null;
|
|
53
|
+
tools: AssistantToolDefinition[];
|
|
54
|
+
}) => Promise<
|
|
55
|
+
Array<{
|
|
56
|
+
id: string;
|
|
57
|
+
label: string;
|
|
58
|
+
description?: string;
|
|
59
|
+
prompt: string;
|
|
60
|
+
icon?: string;
|
|
61
|
+
}>
|
|
62
|
+
>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface AssistantContextValue {
|
|
66
|
+
store: AssistantStore;
|
|
67
|
+
config: AssistantConfig;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface AssistantProviderProps {
|
|
71
|
+
config: AssistantConfig;
|
|
72
|
+
children: ReactNode;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface AssistantProps {
|
|
76
|
+
className?: string;
|
|
77
|
+
/** Override header from provider config */
|
|
78
|
+
header?: AssistantHeaderConfig;
|
|
79
|
+
/** Override empty state from provider config */
|
|
80
|
+
emptyState?: AssistantEmptyStateConfig;
|
|
81
|
+
/** Override UI options from provider config */
|
|
82
|
+
ui?: AssistantUiConfig;
|
|
83
|
+
}
|