@extrachill/chat 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/CHANGELOG.md +24 -0
- package/README.md +154 -0
- package/css/chat.css +552 -0
- package/dist/Chat.d.ts +73 -0
- package/dist/Chat.d.ts.map +1 -0
- package/dist/Chat.js +50 -0
- package/dist/api.d.ts +68 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +93 -0
- package/dist/components/AvailabilityGate.d.ts +19 -0
- package/dist/components/AvailabilityGate.d.ts.map +1 -0
- package/dist/components/AvailabilityGate.js +32 -0
- package/dist/components/ChatInput.d.ts +21 -0
- package/dist/components/ChatInput.d.ts.map +1 -0
- package/dist/components/ChatInput.js +52 -0
- package/dist/components/ChatMessage.d.ts +23 -0
- package/dist/components/ChatMessage.d.ts.map +1 -0
- package/dist/components/ChatMessage.js +34 -0
- package/dist/components/ChatMessages.d.ts +28 -0
- package/dist/components/ChatMessages.d.ts.map +1 -0
- package/dist/components/ChatMessages.js +121 -0
- package/dist/components/ErrorBoundary.d.ts +27 -0
- package/dist/components/ErrorBoundary.d.ts.map +1 -0
- package/dist/components/ErrorBoundary.js +34 -0
- package/dist/components/SessionSwitcher.d.ts +25 -0
- package/dist/components/SessionSwitcher.d.ts.map +1 -0
- package/dist/components/SessionSwitcher.js +44 -0
- package/dist/components/ToolMessage.d.ts +34 -0
- package/dist/components/ToolMessage.d.ts.map +1 -0
- package/dist/components/ToolMessage.js +39 -0
- package/dist/components/TypingIndicator.d.ts +16 -0
- package/dist/components/TypingIndicator.d.ts.map +1 -0
- package/dist/components/TypingIndicator.js +14 -0
- package/dist/components/index.d.ts +9 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +8 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useChat.d.ts +102 -0
- package/dist/hooks/useChat.d.ts.map +1 -0
- package/dist/hooks/useChat.js +192 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/normalizer.d.ts +24 -0
- package/dist/normalizer.d.ts.map +1 -0
- package/dist/normalizer.js +96 -0
- package/dist/types/adapter.d.ts +151 -0
- package/dist/types/adapter.d.ts.map +1 -0
- package/dist/types/adapter.js +11 -0
- package/dist/types/api.d.ts +137 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +8 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/message.d.ts +62 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/message.js +7 -0
- package/dist/types/session.d.ts +59 -0
- package/dist/types/session.d.ts.map +1 -0
- package/dist/types/session.js +7 -0
- package/package.json +61 -0
- package/src/Chat.tsx +157 -0
- package/src/api.ts +173 -0
- package/src/components/AvailabilityGate.tsx +85 -0
- package/src/components/ChatInput.tsx +114 -0
- package/src/components/ChatMessage.tsx +85 -0
- package/src/components/ChatMessages.tsx +193 -0
- package/src/components/ErrorBoundary.tsx +66 -0
- package/src/components/SessionSwitcher.tsx +129 -0
- package/src/components/ToolMessage.tsx +112 -0
- package/src/components/TypingIndicator.tsx +36 -0
- package/src/components/index.ts +8 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useChat.ts +310 -0
- package/src/index.ts +79 -0
- package/src/normalizer.ts +112 -0
- package/src/types/api.ts +146 -0
- package/src/types/index.ts +26 -0
- package/src/types/message.ts +66 -0
- package/src/types/session.ts +50 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalized message model for the chat package.
|
|
3
|
+
*
|
|
4
|
+
* This model is backend-agnostic. Adapters map their native message
|
|
5
|
+
* format into these types before the UI sees them.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The role that produced a message.
|
|
10
|
+
*
|
|
11
|
+
* - `user` — sent by the human
|
|
12
|
+
* - `assistant` — sent by the AI / bot
|
|
13
|
+
* - `system` — system-level context (usually hidden from UI)
|
|
14
|
+
* - `tool_call` — the assistant requesting a tool execution
|
|
15
|
+
* - `tool_result` — the result of a tool execution
|
|
16
|
+
*/
|
|
17
|
+
export type MessageRole = 'user' | 'assistant' | 'system' | 'tool_call' | 'tool_result';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A single tool call requested by the assistant.
|
|
21
|
+
*/
|
|
22
|
+
export interface ToolCall {
|
|
23
|
+
/** Unique ID for this tool call (used to pair with result). */
|
|
24
|
+
id: string;
|
|
25
|
+
/** Tool function name. */
|
|
26
|
+
name: string;
|
|
27
|
+
/** Arguments passed to the tool. */
|
|
28
|
+
parameters: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Metadata for a tool result message.
|
|
33
|
+
*/
|
|
34
|
+
export interface ToolResultMeta {
|
|
35
|
+
/** The tool that produced this result. */
|
|
36
|
+
toolName: string;
|
|
37
|
+
/** Whether the tool call succeeded. */
|
|
38
|
+
success: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A single message in a chat conversation.
|
|
43
|
+
*/
|
|
44
|
+
export interface ChatMessage {
|
|
45
|
+
/** Unique message ID. */
|
|
46
|
+
id: string;
|
|
47
|
+
/** Who produced this message. */
|
|
48
|
+
role: MessageRole;
|
|
49
|
+
/** Text content (may be markdown, HTML, or plain text depending on adapter). */
|
|
50
|
+
content: string;
|
|
51
|
+
/** ISO 8601 timestamp. */
|
|
52
|
+
timestamp: string;
|
|
53
|
+
/** Tool calls requested by the assistant (only on assistant messages). */
|
|
54
|
+
toolCalls?: ToolCall[];
|
|
55
|
+
/** Tool result metadata (only on tool_result messages). */
|
|
56
|
+
toolResult?: ToolResultMeta;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Content format hint for how message content should be rendered.
|
|
61
|
+
*
|
|
62
|
+
* - `markdown` — render with a markdown renderer (default)
|
|
63
|
+
* - `html` — render as raw HTML (dangerouslySetInnerHTML)
|
|
64
|
+
* - `text` — render as plain text
|
|
65
|
+
*/
|
|
66
|
+
export type ContentFormat = 'markdown' | 'html' | 'text';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chat session types.
|
|
3
|
+
*
|
|
4
|
+
* Sessions are optional — adapters that don't support sessions
|
|
5
|
+
* operate in single-conversation mode.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ChatMessage } from './message.ts';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A chat session — a distinct conversation thread.
|
|
12
|
+
*/
|
|
13
|
+
export interface ChatSession {
|
|
14
|
+
/** Unique session identifier. */
|
|
15
|
+
id: string;
|
|
16
|
+
/** Human-readable title (may be auto-generated from first message). */
|
|
17
|
+
title?: string;
|
|
18
|
+
/** ISO 8601 timestamp of session creation. */
|
|
19
|
+
createdAt: string;
|
|
20
|
+
/** ISO 8601 timestamp of last activity. */
|
|
21
|
+
updatedAt: string;
|
|
22
|
+
/** Number of messages in the session (optional, for display). */
|
|
23
|
+
messageCount?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Availability state of the chat service.
|
|
28
|
+
*
|
|
29
|
+
* Adapters surface this so the UI can render appropriate states
|
|
30
|
+
* without knowing the business logic behind them.
|
|
31
|
+
*/
|
|
32
|
+
export type ChatAvailability =
|
|
33
|
+
| { status: 'ready' }
|
|
34
|
+
| { status: 'login-required'; loginUrl?: string }
|
|
35
|
+
| { status: 'unavailable'; reason?: string }
|
|
36
|
+
| { status: 'provisioning'; message?: string }
|
|
37
|
+
| { status: 'upgrade-required'; upgradeUrl?: string; message?: string }
|
|
38
|
+
| { status: 'error'; message: string };
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The initial state returned by an adapter on mount.
|
|
42
|
+
*/
|
|
43
|
+
export interface ChatInitialState {
|
|
44
|
+
/** Current availability of the chat service. */
|
|
45
|
+
availability: ChatAvailability;
|
|
46
|
+
/** Active session (if resuming). */
|
|
47
|
+
session?: ChatSession;
|
|
48
|
+
/** Messages for the active session (if resuming). */
|
|
49
|
+
messages?: ChatMessage[];
|
|
50
|
+
}
|