@arcote.tech/arc-chat 0.4.7 → 0.4.9

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arcote.tech/arc-chat",
3
3
  "type": "module",
4
- "version": "0.4.7",
4
+ "version": "0.4.9",
5
5
  "private": false,
6
6
  "description": "Chat module with AI integration for Arc framework",
7
7
  "main": "./src/index.ts",
@@ -10,11 +10,11 @@
10
10
  "type-check": "tsc --noEmit"
11
11
  },
12
12
  "peerDependencies": {
13
- "@arcote.tech/arc": "^0.4.7",
14
- "@arcote.tech/arc-ai": "^0.4.7",
15
- "@arcote.tech/arc-auth": "^0.4.7",
16
- "@arcote.tech/arc-ds": "^0.4.7",
17
- "@arcote.tech/platform": "^0.4.7",
13
+ "@arcote.tech/arc": "^0.4.9",
14
+ "@arcote.tech/arc-ai": "^0.4.9",
15
+ "@arcote.tech/arc-auth": "^0.4.9",
16
+ "@arcote.tech/arc-ds": "^0.4.9",
17
+ "@arcote.tech/platform": "^0.4.9",
18
18
  "lucide-react": ">=0.400.0",
19
19
  "react": ">=18.0.0",
20
20
  "typescript": "^5.0.0"
@@ -1,16 +1,11 @@
1
- // --- Components ---
2
- export { Chat } from "./chat";
3
- export { ChatMessage } from "./chat-message";
4
- export { ChatInput } from "./chat-input";
5
- export { QuestionTabs } from "./question-tabs";
6
- export { ToolUseBlock } from "./tool-use-block";
7
-
8
- // --- Types ---
1
+ // Re-export chat UI components from arc-ds
2
+ export { Chat, ChatMessage, ChatInput, QuestionTabs, ToolUseBlock } from "@arcote.tech/arc-ds";
9
3
  export type {
4
+ ChatProps,
10
5
  ChatMessageData,
11
6
  ChatModel,
12
7
  SendMessageOptions,
13
8
  ToolUse,
14
9
  Question,
15
10
  QuestionAnswers,
16
- } from "./types";
11
+ } from "@arcote.tech/arc-ds";
@@ -1,79 +0,0 @@
1
- import { Trans } from "@arcote.tech/platform";
2
- import { Box, Button, TextareaField, SearchSelect } from "@arcote.tech/arc-ds";
3
- import { Send, Globe } from "lucide-react";
4
- import { useState, type ReactNode } from "react";
5
- import type { ChatModel, SendMessageOptions } from "./types";
6
-
7
- interface ChatInputProps {
8
- onSend: (message: string, options: SendMessageOptions) => void;
9
- models: ChatModel[];
10
- defaultModel?: string;
11
- /** Extra toolbar content (e.g., attach menu) rendered after web search toggle */
12
- toolbar?: ReactNode;
13
- }
14
-
15
- export function ChatInput({
16
- onSend,
17
- models,
18
- defaultModel,
19
- toolbar,
20
- }: ChatInputProps) {
21
- const [message, setMessage] = useState("");
22
- const [model, setModel] = useState(defaultModel ?? models[0]?.value ?? "");
23
- const [webSearch, setWebSearch] = useState(false);
24
-
25
- const handleSend = () => {
26
- const text = message.trim();
27
- if (!text) return;
28
- onSend(text, { model, webSearch });
29
- setMessage("");
30
- };
31
-
32
- return (
33
- <Box className="p-3 space-y-2">
34
- {/* Input + send */}
35
- <div className="flex items-end gap-2">
36
- <div className="flex-1">
37
- <TextareaField
38
- value={message}
39
- onChange={(val) => setMessage(val ?? "")}
40
- placeholder="Napisz wiadomość..."
41
- rows={1}
42
- />
43
- </div>
44
- <Button
45
- size="sm"
46
- icon={Send}
47
- onClick={handleSend}
48
- disabled={!message.trim()}
49
- />
50
- </div>
51
-
52
- {/* Toolbar */}
53
- <div className="flex items-center gap-1.5">
54
- <div className="w-[130px]">
55
- <SearchSelect
56
- value={model}
57
- onChange={setModel}
58
- options={models}
59
- placeholder="Model..."
60
- position="absolute"
61
- direction="up"
62
- size="sm"
63
- allowClear={false}
64
- />
65
- </div>
66
-
67
- <Button
68
- variant={webSearch ? "default" : "ghost"}
69
- size="xs"
70
- icon={Globe}
71
- label={<Trans>Web</Trans>}
72
- onClick={() => setWebSearch((v) => !v)}
73
- />
74
-
75
- {toolbar}
76
- </div>
77
- </Box>
78
- );
79
- }
@@ -1,100 +0,0 @@
1
- import { Trans } from "@arcote.tech/platform";
2
- import { Button } from "@arcote.tech/arc-ds";
3
- import { Bot, User, MessageSquare } from "lucide-react";
4
- import type { ChatMessageData } from "./types";
5
- import { ToolUseBlock } from "./tool-use-block";
6
-
7
- interface ChatMessageProps {
8
- message: ChatMessageData;
9
- onAnswerQuestions?: () => void;
10
- onToolUseClick?: (link: string) => void;
11
- }
12
-
13
- export function ChatMessage({
14
- message,
15
- onAnswerQuestions,
16
- onToolUseClick,
17
- }: ChatMessageProps) {
18
- const isUser = message.role === "user";
19
- const hasUnansweredQuestions =
20
- message.questions && message.questions.length > 0;
21
-
22
- return (
23
- <div className={`flex gap-3 ${isUser ? "flex-row-reverse" : ""}`}>
24
- {/* Avatar */}
25
- <div
26
- className={`flex h-7 w-7 shrink-0 items-center justify-center rounded-full mt-0.5 ${
27
- isUser ? "bg-primary/10" : "bg-muted"
28
- }`}
29
- >
30
- {isUser ? (
31
- <User className="h-3.5 w-3.5 text-primary" />
32
- ) : (
33
- <Bot className="h-3.5 w-3.5 text-muted-foreground" />
34
- )}
35
- </div>
36
-
37
- {/* Content */}
38
- <div
39
- className={`flex-1 min-w-0 space-y-2 ${isUser ? "text-right" : ""}`}
40
- >
41
- <div
42
- className={`inline-block rounded-2xl px-4 py-2.5 text-sm leading-relaxed ${
43
- isUser
44
- ? "bg-primary/10 text-foreground rounded-tr-sm"
45
- : "bg-card border border-border rounded-tl-sm"
46
- }`}
47
- >
48
- {message.content.split("\n").map((line, i) => (
49
- <p key={i} className={i > 0 ? "mt-1.5" : ""}>
50
- {line.startsWith("• ") ? (
51
- <span className="flex items-start gap-1.5 text-left">
52
- <span className="text-primary mt-px">•</span>
53
- <span>{line.slice(2)}</span>
54
- </span>
55
- ) : (
56
- line
57
- )}
58
- </p>
59
- ))}
60
- {message.isStreaming && (
61
- <span className="inline-block w-1.5 h-4 bg-foreground/60 animate-pulse ml-0.5 -mb-0.5" />
62
- )}
63
- </div>
64
-
65
- {/* Tool uses */}
66
- {message.toolUses && message.toolUses.length > 0 && (
67
- <div className="space-y-1.5">
68
- {message.toolUses.map((tu, i) => (
69
- <ToolUseBlock
70
- key={i}
71
- toolUse={tu}
72
- onClick={
73
- tu.link && onToolUseClick
74
- ? () => onToolUseClick(tu.link!)
75
- : undefined
76
- }
77
- />
78
- ))}
79
- </div>
80
- )}
81
-
82
- {/* Questions indicator */}
83
- {hasUnansweredQuestions && onAnswerQuestions && (
84
- <div className="flex items-center gap-2">
85
- <span className="text-xs text-muted-foreground">
86
- {message.questions!.length}{" "}
87
- <Trans>pytań do odpowiedzenia</Trans>
88
- </span>
89
- <Button
90
- size="xs"
91
- icon={MessageSquare}
92
- label={<Trans>Odpowiedz</Trans>}
93
- onClick={onAnswerQuestions}
94
- />
95
- </div>
96
- )}
97
- </div>
98
- </div>
99
- );
100
- }
@@ -1,117 +0,0 @@
1
- import { useState, useRef, useEffect, type ReactNode } from "react";
2
- import type {
3
- ChatMessageData,
4
- ChatModel,
5
- QuestionAnswers,
6
- SendMessageOptions,
7
- } from "./types";
8
- import { ChatMessage } from "./chat-message";
9
- import { ChatInput } from "./chat-input";
10
- import { QuestionTabs } from "./question-tabs";
11
-
12
- interface ChatProps {
13
- /** Message history */
14
- messages: ChatMessageData[];
15
- /** Available AI models */
16
- models: ChatModel[];
17
- /** Default model to use */
18
- defaultModel?: string;
19
- /** Called when user sends a message */
20
- onSend: (message: string, options: SendMessageOptions) => void;
21
- /** Called when user submits answers to questions */
22
- onAnswerQuestions?: (
23
- messageId: string,
24
- answers: QuestionAnswers,
25
- ) => void;
26
- /** Called when user clicks a tool use link */
27
- onToolUseClick?: (link: string) => void;
28
- /** Header content (title, description) */
29
- header?: ReactNode;
30
- /** Sidebar content (consultation plan, etc.) */
31
- sidebar?: ReactNode;
32
- /** Extra toolbar content for ChatInput (attach menu, etc.) */
33
- toolbar?: ReactNode;
34
- /** Max width class for the message area */
35
- maxWidth?: string;
36
- }
37
-
38
- export function Chat({
39
- messages,
40
- models,
41
- defaultModel,
42
- onSend,
43
- onAnswerQuestions,
44
- onToolUseClick,
45
- header,
46
- sidebar,
47
- toolbar,
48
- maxWidth = "max-w-3xl",
49
- }: ChatProps) {
50
- const [answeringMessageId, setAnsweringMessageId] = useState<string | null>(
51
- null,
52
- );
53
- const messagesEndRef = useRef<HTMLDivElement>(null);
54
-
55
- const answeringMessage = answeringMessageId
56
- ? messages.find((m) => m.id === answeringMessageId)
57
- : null;
58
-
59
- // Auto-scroll on new messages
60
- useEffect(() => {
61
- messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
62
- }, [messages.length]);
63
-
64
- return (
65
- <div className="flex gap-6">
66
- {/* Sidebar */}
67
- {sidebar && (
68
- <div className="hidden lg:block w-64 shrink-0 sticky top-24 self-start">
69
- {sidebar}
70
- </div>
71
- )}
72
-
73
- {/* Main chat area */}
74
- <div className="flex-1 min-w-0 space-y-4">
75
- {/* Header */}
76
- {header}
77
-
78
- {/* Messages */}
79
- <div className={`${maxWidth} mx-auto space-y-4`}>
80
- {messages.map((msg) => (
81
- <ChatMessage
82
- key={msg.id}
83
- message={msg}
84
- onAnswerQuestions={
85
- msg.questions?.length
86
- ? () => setAnsweringMessageId(msg.id)
87
- : undefined
88
- }
89
- onToolUseClick={onToolUseClick}
90
- />
91
- ))}
92
- <div ref={messagesEndRef} />
93
- </div>
94
-
95
- {/* Input area — sticky at bottom */}
96
- <div className={`sticky bottom-0 ${maxWidth} mx-auto w-full pb-4`}>
97
- {answeringMessage?.questions ? (
98
- <QuestionTabs
99
- questions={answeringMessage.questions}
100
- onSubmit={(answers) => {
101
- onAnswerQuestions?.(answeringMessageId!, answers);
102
- setAnsweringMessageId(null);
103
- }}
104
- />
105
- ) : (
106
- <ChatInput
107
- onSend={onSend}
108
- models={models}
109
- defaultModel={defaultModel}
110
- toolbar={toolbar}
111
- />
112
- )}
113
- </div>
114
- </div>
115
- </div>
116
- );
117
- }
@@ -1,157 +0,0 @@
1
- import { Trans } from "@arcote.tech/platform";
2
- import { Box, Button, TextareaField } from "@arcote.tech/arc-ds";
3
- import { Send, Check } from "lucide-react";
4
- import { useState } from "react";
5
- import type { Question, QuestionAnswers } from "./types";
6
-
7
- interface QuestionTabsProps {
8
- questions: Question[];
9
- onSubmit: (answers: QuestionAnswers) => void;
10
- }
11
-
12
- export function QuestionTabs({ questions, onSubmit }: QuestionTabsProps) {
13
- const [activeTab, setActiveTab] = useState(0);
14
- const [answers, setAnswers] = useState<QuestionAnswers>(
15
- () =>
16
- Object.fromEntries(
17
- questions.map((q) => [q.id, { selected: [], text: "" }]),
18
- ),
19
- );
20
-
21
- const current = questions[activeTab];
22
- const currentAnswer = answers[current.id] ?? { selected: [], text: "" };
23
-
24
- const toggleOption = (option: string) => {
25
- const selected = currentAnswer.selected.includes(option)
26
- ? currentAnswer.selected.filter((o) => o !== option)
27
- : [...currentAnswer.selected, option];
28
- setAnswers((prev) => ({
29
- ...prev,
30
- [current.id]: { ...prev[current.id], selected },
31
- }));
32
- };
33
-
34
- const setText = (text: string) => {
35
- setAnswers((prev) => ({
36
- ...prev,
37
- [current.id]: { ...prev[current.id], text },
38
- }));
39
- };
40
-
41
- const hasCustomText = currentAnswer.text.trim().length > 0;
42
-
43
- const totalAnswered = questions.filter(
44
- (q) =>
45
- (answers[q.id]?.selected.length ?? 0) > 0 ||
46
- (answers[q.id]?.text ?? "").trim().length > 0,
47
- ).length;
48
-
49
- return (
50
- <Box className="p-0 overflow-hidden">
51
- {/* Tabs */}
52
- <div className="flex border-b border-border overflow-x-auto">
53
- {questions.map((q, i) => {
54
- const hasAnswer =
55
- (answers[q.id]?.selected.length ?? 0) > 0 ||
56
- (answers[q.id]?.text ?? "").trim().length > 0;
57
- return (
58
- <button
59
- key={q.id}
60
- type="button"
61
- onClick={() => setActiveTab(i)}
62
- className={`flex items-center gap-1.5 px-3 py-2 text-xs font-medium whitespace-nowrap transition-colors border-b-2 -mb-px ${
63
- i === activeTab
64
- ? "border-primary text-primary"
65
- : "border-transparent text-muted-foreground hover:text-foreground"
66
- }`}
67
- >
68
- {hasAnswer && (
69
- <span className="h-1.5 w-1.5 rounded-full bg-primary shrink-0" />
70
- )}
71
- {q.label}
72
- </button>
73
- );
74
- })}
75
- </div>
76
-
77
- {/* Content */}
78
- <div className="p-3 space-y-1.5">
79
- <p className="text-xs text-muted-foreground mb-2">
80
- {current.description}
81
- </p>
82
-
83
- {/* Options */}
84
- {current.options.map((option) => {
85
- const isSelected = currentAnswer.selected.includes(option);
86
- return (
87
- <button
88
- key={option}
89
- type="button"
90
- onClick={() => toggleOption(option)}
91
- className={`flex items-center gap-2.5 w-full rounded-lg px-3 py-2.5 text-left transition-colors ${
92
- isSelected
93
- ? "bg-primary/10 border border-primary/20"
94
- : "bg-muted/50 border border-transparent hover:bg-muted"
95
- }`}
96
- >
97
- <div
98
- className={`flex h-4 w-4 shrink-0 items-center justify-center rounded border transition-colors ${
99
- isSelected
100
- ? "border-primary bg-primary"
101
- : "border-input bg-transparent"
102
- }`}
103
- >
104
- {isSelected && (
105
- <Check className="h-3 w-3 text-primary-foreground" />
106
- )}
107
- </div>
108
- <span className="text-sm">{option}</span>
109
- </button>
110
- );
111
- })}
112
-
113
- {/* Custom option */}
114
- <div
115
- className={`flex items-start gap-2.5 w-full rounded-lg px-3 py-2.5 transition-colors ${
116
- hasCustomText
117
- ? "bg-primary/10 border border-primary/20"
118
- : "bg-muted/50 border border-transparent"
119
- }`}
120
- >
121
- <div
122
- className={`flex h-4 w-4 shrink-0 items-center justify-center rounded border transition-colors mt-0.5 ${
123
- hasCustomText
124
- ? "border-primary bg-primary"
125
- : "border-input bg-transparent"
126
- }`}
127
- >
128
- {hasCustomText && (
129
- <Check className="h-3 w-3 text-primary-foreground" />
130
- )}
131
- </div>
132
- <div className="flex-1">
133
- <TextareaField
134
- value={currentAnswer.text}
135
- onChange={(val) => setText(val ?? "")}
136
- placeholder="Własna odpowiedź..."
137
- rows={1}
138
- />
139
- </div>
140
- </div>
141
- </div>
142
-
143
- {/* Footer */}
144
- <div className="flex items-center justify-between border-t border-border px-3 py-2">
145
- <span className="text-[10px] text-muted-foreground">
146
- {totalAnswered}/{questions.length} <Trans>uzupełnione</Trans>
147
- </span>
148
- <Button
149
- size="sm"
150
- icon={Send}
151
- label={<Trans>Wyślij</Trans>}
152
- onClick={() => onSubmit(answers)}
153
- />
154
- </div>
155
- </Box>
156
- );
157
- }
@@ -1,34 +0,0 @@
1
- import { CheckCircle2, ArrowRight } from "lucide-react";
2
- import type { ToolUse } from "./types";
3
-
4
- interface ToolUseBlockProps {
5
- toolUse: ToolUse;
6
- onClick?: () => void;
7
- }
8
-
9
- export function ToolUseBlock({ toolUse, onClick }: ToolUseBlockProps) {
10
- const Component = onClick ? "button" : "div";
11
-
12
- return (
13
- <Component
14
- type={onClick ? "button" : undefined}
15
- onClick={onClick}
16
- className={`flex items-start gap-3 w-full rounded-xl border border-green-500/20 bg-green-500/5 p-3 text-left transition-colors ${
17
- onClick ? "hover:bg-green-500/10 cursor-pointer" : ""
18
- }`}
19
- >
20
- <CheckCircle2 className="h-4 w-4 text-green-500 mt-0.5 shrink-0" />
21
- <div className="flex-1 min-w-0">
22
- <p className="text-xs font-medium text-green-700 dark:text-green-400">
23
- {toolUse.action}
24
- </p>
25
- <p className="text-xs text-muted-foreground mt-0.5 line-clamp-1">
26
- {toolUse.value}
27
- </p>
28
- </div>
29
- {onClick && (
30
- <ArrowRight className="h-3.5 w-3.5 text-muted-foreground mt-0.5 shrink-0" />
31
- )}
32
- </Component>
33
- );
34
- }
@@ -1,36 +0,0 @@
1
- export interface ToolUse {
2
- action: string;
3
- value: string;
4
- link?: string;
5
- }
6
-
7
- export interface Question {
8
- id: string;
9
- label: string;
10
- description: string;
11
- options: string[];
12
- }
13
-
14
- export interface QuestionAnswers {
15
- [questionId: string]: { selected: string[]; text: string };
16
- }
17
-
18
- export interface ChatMessageData {
19
- id: string;
20
- role: "user" | "assistant" | "system" | "tool";
21
- content: string;
22
- toolUses?: ToolUse[];
23
- questions?: Question[];
24
- isStreaming?: boolean;
25
- }
26
-
27
- export interface ChatModel {
28
- value: string;
29
- label: string;
30
- }
31
-
32
- export interface SendMessageOptions {
33
- model: string;
34
- webSearch: boolean;
35
- attachments?: string[];
36
- }