@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.
Files changed (83) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +154 -0
  3. package/css/chat.css +552 -0
  4. package/dist/Chat.d.ts +73 -0
  5. package/dist/Chat.d.ts.map +1 -0
  6. package/dist/Chat.js +50 -0
  7. package/dist/api.d.ts +68 -0
  8. package/dist/api.d.ts.map +1 -0
  9. package/dist/api.js +93 -0
  10. package/dist/components/AvailabilityGate.d.ts +19 -0
  11. package/dist/components/AvailabilityGate.d.ts.map +1 -0
  12. package/dist/components/AvailabilityGate.js +32 -0
  13. package/dist/components/ChatInput.d.ts +21 -0
  14. package/dist/components/ChatInput.d.ts.map +1 -0
  15. package/dist/components/ChatInput.js +52 -0
  16. package/dist/components/ChatMessage.d.ts +23 -0
  17. package/dist/components/ChatMessage.d.ts.map +1 -0
  18. package/dist/components/ChatMessage.js +34 -0
  19. package/dist/components/ChatMessages.d.ts +28 -0
  20. package/dist/components/ChatMessages.d.ts.map +1 -0
  21. package/dist/components/ChatMessages.js +121 -0
  22. package/dist/components/ErrorBoundary.d.ts +27 -0
  23. package/dist/components/ErrorBoundary.d.ts.map +1 -0
  24. package/dist/components/ErrorBoundary.js +34 -0
  25. package/dist/components/SessionSwitcher.d.ts +25 -0
  26. package/dist/components/SessionSwitcher.d.ts.map +1 -0
  27. package/dist/components/SessionSwitcher.js +44 -0
  28. package/dist/components/ToolMessage.d.ts +34 -0
  29. package/dist/components/ToolMessage.d.ts.map +1 -0
  30. package/dist/components/ToolMessage.js +39 -0
  31. package/dist/components/TypingIndicator.d.ts +16 -0
  32. package/dist/components/TypingIndicator.d.ts.map +1 -0
  33. package/dist/components/TypingIndicator.js +14 -0
  34. package/dist/components/index.d.ts +9 -0
  35. package/dist/components/index.d.ts.map +1 -0
  36. package/dist/components/index.js +8 -0
  37. package/dist/hooks/index.d.ts +2 -0
  38. package/dist/hooks/index.d.ts.map +1 -0
  39. package/dist/hooks/index.js +1 -0
  40. package/dist/hooks/useChat.d.ts +102 -0
  41. package/dist/hooks/useChat.d.ts.map +1 -0
  42. package/dist/hooks/useChat.js +192 -0
  43. package/dist/index.d.ts +15 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +16 -0
  46. package/dist/normalizer.d.ts +24 -0
  47. package/dist/normalizer.d.ts.map +1 -0
  48. package/dist/normalizer.js +96 -0
  49. package/dist/types/adapter.d.ts +151 -0
  50. package/dist/types/adapter.d.ts.map +1 -0
  51. package/dist/types/adapter.js +11 -0
  52. package/dist/types/api.d.ts +137 -0
  53. package/dist/types/api.d.ts.map +1 -0
  54. package/dist/types/api.js +8 -0
  55. package/dist/types/index.d.ts +4 -0
  56. package/dist/types/index.d.ts.map +1 -0
  57. package/dist/types/index.js +1 -0
  58. package/dist/types/message.d.ts +62 -0
  59. package/dist/types/message.d.ts.map +1 -0
  60. package/dist/types/message.js +7 -0
  61. package/dist/types/session.d.ts +59 -0
  62. package/dist/types/session.d.ts.map +1 -0
  63. package/dist/types/session.js +7 -0
  64. package/package.json +61 -0
  65. package/src/Chat.tsx +157 -0
  66. package/src/api.ts +173 -0
  67. package/src/components/AvailabilityGate.tsx +85 -0
  68. package/src/components/ChatInput.tsx +114 -0
  69. package/src/components/ChatMessage.tsx +85 -0
  70. package/src/components/ChatMessages.tsx +193 -0
  71. package/src/components/ErrorBoundary.tsx +66 -0
  72. package/src/components/SessionSwitcher.tsx +129 -0
  73. package/src/components/ToolMessage.tsx +112 -0
  74. package/src/components/TypingIndicator.tsx +36 -0
  75. package/src/components/index.ts +8 -0
  76. package/src/hooks/index.ts +1 -0
  77. package/src/hooks/useChat.ts +310 -0
  78. package/src/index.ts +79 -0
  79. package/src/normalizer.ts +112 -0
  80. package/src/types/api.ts +146 -0
  81. package/src/types/index.ts +26 -0
  82. package/src/types/message.ts +66 -0
  83. package/src/types/session.ts +50 -0
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Normalize raw backend messages into the ChatMessage format
3
+ * used by the UI components.
4
+ *
5
+ * The backend stores tool calls and results as regular messages
6
+ * with metadata.type = 'tool_call' | 'tool_result'. This normalizer
7
+ * maps them into the package's role-based message model.
8
+ */
9
+ import type { ChatMessage } from './types/message.ts';
10
+ import type { ChatSession } from './types/session.ts';
11
+ import type { RawMessage, RawSession } from './types/api.ts';
12
+ /**
13
+ * Normalize a raw backend message into a ChatMessage.
14
+ */
15
+ export declare function normalizeMessage(raw: RawMessage, index: number): ChatMessage;
16
+ /**
17
+ * Normalize a full conversation array.
18
+ */
19
+ export declare function normalizeConversation(raw: RawMessage[]): ChatMessage[];
20
+ /**
21
+ * Normalize a raw session into a ChatSession.
22
+ */
23
+ export declare function normalizeSession(raw: RawSession): ChatSession;
24
+ //# sourceMappingURL=normalizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizer.d.ts","sourceRoot":"","sources":["../src/normalizer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAY,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAO7D;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,CAsE5E;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,WAAW,EAAE,CAEtE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,UAAU,GAAG,WAAW,CAQ7D"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Normalize raw backend messages into the ChatMessage format
3
+ * used by the UI components.
4
+ *
5
+ * The backend stores tool calls and results as regular messages
6
+ * with metadata.type = 'tool_call' | 'tool_result'. This normalizer
7
+ * maps them into the package's role-based message model.
8
+ */
9
+ let idCounter = 0;
10
+ function generateId() {
11
+ return `msg_${Date.now()}_${++idCounter}`;
12
+ }
13
+ /**
14
+ * Normalize a raw backend message into a ChatMessage.
15
+ */
16
+ export function normalizeMessage(raw, index) {
17
+ const type = raw.metadata?.type ?? 'text';
18
+ const timestamp = raw.metadata?.timestamp ?? new Date().toISOString();
19
+ if (type === 'tool_call') {
20
+ const toolCalls = [];
21
+ // Extract from metadata (single tool call)
22
+ if (raw.metadata?.tool_name) {
23
+ toolCalls.push({
24
+ id: `tc_${index}_${raw.metadata.tool_name}`,
25
+ name: raw.metadata.tool_name,
26
+ parameters: raw.metadata.parameters ?? {},
27
+ });
28
+ }
29
+ // Also check top-level tool_calls array
30
+ if (raw.tool_calls?.length) {
31
+ for (const tc of raw.tool_calls) {
32
+ // Avoid duplicates
33
+ if (!toolCalls.some((t) => t.name === tc.tool_name)) {
34
+ toolCalls.push({
35
+ id: `tc_${index}_${tc.tool_name}`,
36
+ name: tc.tool_name,
37
+ parameters: tc.parameters ?? {},
38
+ });
39
+ }
40
+ }
41
+ }
42
+ return {
43
+ id: generateId(),
44
+ role: 'tool_call',
45
+ content: raw.content,
46
+ timestamp,
47
+ toolCalls,
48
+ };
49
+ }
50
+ if (type === 'tool_result') {
51
+ return {
52
+ id: generateId(),
53
+ role: 'tool_result',
54
+ content: raw.content,
55
+ timestamp,
56
+ toolResult: {
57
+ toolName: raw.metadata?.tool_name ?? 'unknown',
58
+ success: raw.metadata?.success ?? false,
59
+ },
60
+ };
61
+ }
62
+ // Regular text message (user or assistant)
63
+ const message = {
64
+ id: generateId(),
65
+ role: raw.role === 'user' ? 'user' : 'assistant',
66
+ content: raw.content,
67
+ timestamp,
68
+ };
69
+ // Assistant messages may carry tool_calls at the top level
70
+ if (raw.role === 'assistant' && raw.tool_calls?.length) {
71
+ message.toolCalls = raw.tool_calls.map((tc, i) => ({
72
+ id: `tc_${index}_${i}_${tc.tool_name}`,
73
+ name: tc.tool_name,
74
+ parameters: tc.parameters ?? {},
75
+ }));
76
+ }
77
+ return message;
78
+ }
79
+ /**
80
+ * Normalize a full conversation array.
81
+ */
82
+ export function normalizeConversation(raw) {
83
+ return raw.map(normalizeMessage);
84
+ }
85
+ /**
86
+ * Normalize a raw session into a ChatSession.
87
+ */
88
+ export function normalizeSession(raw) {
89
+ return {
90
+ id: raw.session_id,
91
+ title: raw.title ?? raw.first_message ?? undefined,
92
+ createdAt: raw.created_at,
93
+ updatedAt: raw.updated_at,
94
+ messageCount: raw.message_count,
95
+ };
96
+ }
@@ -0,0 +1,151 @@
1
+ /**
2
+ * The adapter contract.
3
+ *
4
+ * This is the main abstraction boundary. The shared chat UI calls
5
+ * adapter methods — it never knows about REST endpoints, auth tokens,
6
+ * WebSocket connections, or billing logic.
7
+ *
8
+ * Adapters declare their capabilities so the UI can conditionally
9
+ * render features like session switching or tool display.
10
+ */
11
+ import type { ChatMessage } from './message.ts';
12
+ import type { ChatSession, ChatInitialState } from './session.ts';
13
+ /**
14
+ * Capability flags. The UI uses these to conditionally render features.
15
+ */
16
+ export interface ChatCapabilities {
17
+ /** Adapter supports multiple named sessions. */
18
+ sessions: boolean;
19
+ /** Adapter can load historical messages for a session. */
20
+ history: boolean;
21
+ /** Adapter supports real-time streaming of responses. */
22
+ streaming: boolean;
23
+ /** Adapter exposes tool call/result messages. */
24
+ tools: boolean;
25
+ /** Adapter surfaces availability states (login, provisioning, etc.). */
26
+ availabilityStates: boolean;
27
+ }
28
+ /**
29
+ * Input to the sendMessage method.
30
+ */
31
+ export interface SendMessageInput {
32
+ /** The user's message text. */
33
+ content: string;
34
+ /** Session to send to (undefined = create new or use default). */
35
+ sessionId?: string;
36
+ }
37
+ /**
38
+ * Result from a sendMessage call.
39
+ *
40
+ * The response can include multiple messages (e.g. tool calls + final answer).
41
+ * If `completed` is false, the UI should call `continueResponse` to get more.
42
+ */
43
+ export interface SendMessageResult {
44
+ /** The session this message belongs to (may be newly created). */
45
+ sessionId: string;
46
+ /** New messages to append to the conversation. */
47
+ messages: ChatMessage[];
48
+ /** Whether the response is fully complete. */
49
+ completed: boolean;
50
+ }
51
+ /**
52
+ * Result from a continueResponse call.
53
+ */
54
+ export interface ContinueResult {
55
+ /** New messages from this turn. */
56
+ messages: ChatMessage[];
57
+ /** Whether the response is now fully complete. */
58
+ completed: boolean;
59
+ }
60
+ /**
61
+ * Callback for streaming chunks.
62
+ */
63
+ export interface StreamChunk {
64
+ /** Partial content delta. */
65
+ content: string;
66
+ /** Whether this is the final chunk. */
67
+ done: boolean;
68
+ }
69
+ /**
70
+ * The adapter contract.
71
+ *
72
+ * Only `sendMessage` and `capabilities` are required. Everything else
73
+ * is optional — the UI degrades gracefully based on capabilities.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * const adapter: ChatAdapter = {
78
+ * capabilities: {
79
+ * sessions: false,
80
+ * history: false,
81
+ * streaming: false,
82
+ * tools: false,
83
+ * availabilityStates: false,
84
+ * },
85
+ * async sendMessage(input) {
86
+ * const res = await fetch('/api/chat', {
87
+ * method: 'POST',
88
+ * body: JSON.stringify({ message: input.content }),
89
+ * });
90
+ * const data = await res.json();
91
+ * return {
92
+ * sessionId: 'default',
93
+ * messages: [{ id: data.id, role: 'assistant', content: data.reply, timestamp: new Date().toISOString() }],
94
+ * completed: true,
95
+ * };
96
+ * },
97
+ * };
98
+ * ```
99
+ */
100
+ export interface ChatAdapter {
101
+ /** Declare what this adapter supports. */
102
+ capabilities: ChatCapabilities;
103
+ /**
104
+ * Load initial state on mount.
105
+ * Returns availability, optional active session, and messages.
106
+ * If not provided, the UI assumes `{ availability: { status: 'ready' } }`.
107
+ */
108
+ loadInitialState?(): Promise<ChatInitialState>;
109
+ /**
110
+ * Send a user message and get the response.
111
+ * This is the only required async method.
112
+ */
113
+ sendMessage(input: SendMessageInput): Promise<SendMessageResult>;
114
+ /**
115
+ * Continue a multi-turn response (tool calling, etc.).
116
+ * Called when `sendMessage` returns `completed: false`.
117
+ * If not provided, multi-turn is not supported.
118
+ */
119
+ continueResponse?(sessionId: string): Promise<ContinueResult>;
120
+ /**
121
+ * Subscribe to streaming response chunks.
122
+ * Called instead of polling when `capabilities.streaming` is true.
123
+ * Returns an unsubscribe function.
124
+ */
125
+ onStream?(sessionId: string, callback: (chunk: StreamChunk) => void): () => void;
126
+ /**
127
+ * List available sessions.
128
+ * Only called when `capabilities.sessions` is true.
129
+ */
130
+ listSessions?(limit?: number): Promise<ChatSession[]>;
131
+ /**
132
+ * Load messages for a specific session.
133
+ * Only called when `capabilities.history` is true.
134
+ */
135
+ loadMessages?(sessionId: string): Promise<ChatMessage[]>;
136
+ /**
137
+ * Create a new empty session.
138
+ * Only called when `capabilities.sessions` is true.
139
+ */
140
+ createSession?(): Promise<ChatSession>;
141
+ /**
142
+ * Delete a session.
143
+ * Only called when `capabilities.sessions` is true.
144
+ */
145
+ deleteSession?(sessionId: string): Promise<void>;
146
+ /**
147
+ * Clear all messages in a session (without deleting it).
148
+ */
149
+ clearSession?(sessionId: string): Promise<void>;
150
+ }
151
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/types/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAElE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,gDAAgD;IAChD,QAAQ,EAAE,OAAO,CAAC;IAClB,0DAA0D;IAC1D,OAAO,EAAE,OAAO,CAAC;IACjB,yDAAyD;IACzD,SAAS,EAAE,OAAO,CAAC;IACnB,iDAAiD;IACjD,KAAK,EAAE,OAAO,CAAC;IACf,wEAAwE;IACxE,kBAAkB,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;I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E,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAEzD;;;OAGG;IACH,aAAa,CAAC,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IAEvC;;;OAGG;IACH,aAAa,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjD;;OAEG;IACH,YAAY,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The adapter contract.
3
+ *
4
+ * This is the main abstraction boundary. The shared chat UI calls
5
+ * adapter methods — it never knows about REST endpoints, auth tokens,
6
+ * WebSocket connections, or billing logic.
7
+ *
8
+ * Adapters declare their capabilities so the UI can conditionally
9
+ * render features like session switching or tool display.
10
+ */
11
+ export {};
@@ -0,0 +1,137 @@
1
+ /**
2
+ * REST API contract types.
3
+ *
4
+ * These describe the expected shape of the chat REST endpoints.
5
+ * Any backend that wants to work with this package implements
6
+ * these same endpoints and response shapes.
7
+ */
8
+ /**
9
+ * A raw message as stored/returned by the backend.
10
+ * The package normalizes these into ChatMessage before rendering.
11
+ */
12
+ export interface RawMessage {
13
+ role: 'user' | 'assistant';
14
+ content: string;
15
+ metadata?: {
16
+ timestamp?: string;
17
+ type?: 'text' | 'tool_call' | 'tool_result';
18
+ tool_name?: string;
19
+ parameters?: Record<string, unknown>;
20
+ success?: boolean;
21
+ error?: string;
22
+ turn?: number;
23
+ tool_data?: Record<string, unknown>;
24
+ };
25
+ tool_calls?: Array<{
26
+ tool_name: string;
27
+ parameters: Record<string, unknown>;
28
+ }>;
29
+ }
30
+ /**
31
+ * POST /chat — Send a message.
32
+ */
33
+ export interface SendRequest {
34
+ message: string;
35
+ session_id?: string;
36
+ agent_id?: number;
37
+ }
38
+ export interface SendResponse {
39
+ success: boolean;
40
+ data: {
41
+ session_id: string;
42
+ response: string;
43
+ tool_calls: Array<{
44
+ tool_name: string;
45
+ parameters: Record<string, unknown>;
46
+ }>;
47
+ conversation: RawMessage[];
48
+ metadata: SessionMetadata;
49
+ completed: boolean;
50
+ max_turns: number;
51
+ turn_number: number;
52
+ max_turns_reached: boolean;
53
+ warning?: string;
54
+ };
55
+ }
56
+ /**
57
+ * POST /chat/continue — Continue a multi-turn response.
58
+ */
59
+ export interface ContinueRequest {
60
+ session_id: string;
61
+ }
62
+ export interface ContinueResponse {
63
+ success: boolean;
64
+ data: {
65
+ session_id: string;
66
+ new_messages: RawMessage[];
67
+ final_content: string;
68
+ tool_calls: Array<{
69
+ tool_name: string;
70
+ parameters: Record<string, unknown>;
71
+ }>;
72
+ completed: boolean;
73
+ turn_number: number;
74
+ max_turns: number;
75
+ max_turns_reached: boolean;
76
+ };
77
+ }
78
+ /**
79
+ * GET /chat/sessions — List sessions.
80
+ */
81
+ export interface ListSessionsResponse {
82
+ success: boolean;
83
+ data: {
84
+ sessions: RawSession[];
85
+ total: number;
86
+ limit: number;
87
+ offset: number;
88
+ };
89
+ }
90
+ export interface RawSession {
91
+ session_id: string;
92
+ title: string | null;
93
+ context: string;
94
+ first_message: string | null;
95
+ message_count: number;
96
+ created_at: string;
97
+ updated_at: string;
98
+ }
99
+ /**
100
+ * GET /chat/{session_id} — Get a single session.
101
+ */
102
+ export interface GetSessionResponse {
103
+ success: boolean;
104
+ data: {
105
+ session_id: string;
106
+ conversation: RawMessage[];
107
+ metadata: SessionMetadata;
108
+ };
109
+ }
110
+ /**
111
+ * DELETE /chat/{session_id} — Delete a session.
112
+ */
113
+ export interface DeleteSessionResponse {
114
+ success: boolean;
115
+ data: {
116
+ session_id: string;
117
+ deleted: boolean;
118
+ };
119
+ }
120
+ /**
121
+ * Session metadata shape from the backend.
122
+ */
123
+ export interface SessionMetadata {
124
+ status?: 'pending' | 'processing' | 'completed' | 'error';
125
+ started_at?: string;
126
+ last_activity?: string;
127
+ message_count?: number;
128
+ current_turn?: number;
129
+ has_pending_tools?: boolean;
130
+ token_usage?: {
131
+ prompt_tokens: number;
132
+ completion_tokens: number;
133
+ total_tokens: number;
134
+ };
135
+ error_message?: string;
136
+ }
137
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/types/api.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;GAGG;AACH,MAAM,WAAW,UAAU;IAC1B,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE;QACV,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,aAAa,CAAC;QAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACrC,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC,CAAC;IACF,UAAU,CAAC,EAAE,KAAK,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC,CAAC,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE;QACL,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,KAAK,CAAC;YACjB,SAAS,EAAE,MAAM,CAAC;YAClB,UAAU,EAAE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,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE;QACL,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAAE,UAAU,EAAE,CAAC;QAC3B,QAAQ,EAAE,eAAe,CAAC;KAC1B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE;QACL,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,OAAO,CAAC;KACjB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,MAAM,CAAC,EAAE,SAAS,GAAG,YAAY,GAAG,WAAW,GAAG,OAAO,CAAC;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,WAAW,CAAC,EAAE;QACb,aAAa,EAAE,MAAM,CAAC;QACtB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,YAAY,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * REST API contract types.
3
+ *
4
+ * These describe the expected shape of the chat REST endpoints.
5
+ * Any backend that wants to work with this package implements
6
+ * these same endpoints and response shapes.
7
+ */
8
+ export {};
@@ -0,0 +1,4 @@
1
+ export type { MessageRole, ToolCall, ToolResultMeta, ChatMessage, ContentFormat, } from './message.ts';
2
+ export type { ChatSession, ChatAvailability, ChatInitialState, } from './session.ts';
3
+ export type { RawMessage, RawSession, SendRequest, SendResponse, ContinueRequest, ContinueResponse, ListSessionsResponse, GetSessionResponse, DeleteSessionResponse, SessionMetadata, } from './api.ts';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,WAAW,EACX,QAAQ,EACR,cAAc,EACd,WAAW,EACX,aAAa,GACb,MAAM,cAAc,CAAC;AAEtB,YAAY,EACX,WAAW,EACX,gBAAgB,EAChB,gBAAgB,GAChB,MAAM,cAAc,CAAC;AAEtB,YAAY,EACX,UAAU,EACV,UAAU,EACV,WAAW,EACX,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,GACf,MAAM,UAAU,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,62 @@
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
+ * The role that produced a message.
9
+ *
10
+ * - `user` — sent by the human
11
+ * - `assistant` — sent by the AI / bot
12
+ * - `system` — system-level context (usually hidden from UI)
13
+ * - `tool_call` — the assistant requesting a tool execution
14
+ * - `tool_result` — the result of a tool execution
15
+ */
16
+ export type MessageRole = 'user' | 'assistant' | 'system' | 'tool_call' | 'tool_result';
17
+ /**
18
+ * A single tool call requested by the assistant.
19
+ */
20
+ export interface ToolCall {
21
+ /** Unique ID for this tool call (used to pair with result). */
22
+ id: string;
23
+ /** Tool function name. */
24
+ name: string;
25
+ /** Arguments passed to the tool. */
26
+ parameters: Record<string, unknown>;
27
+ }
28
+ /**
29
+ * Metadata for a tool result message.
30
+ */
31
+ export interface ToolResultMeta {
32
+ /** The tool that produced this result. */
33
+ toolName: string;
34
+ /** Whether the tool call succeeded. */
35
+ success: boolean;
36
+ }
37
+ /**
38
+ * A single message in a chat conversation.
39
+ */
40
+ export interface ChatMessage {
41
+ /** Unique message ID. */
42
+ id: string;
43
+ /** Who produced this message. */
44
+ role: MessageRole;
45
+ /** Text content (may be markdown, HTML, or plain text depending on adapter). */
46
+ content: string;
47
+ /** ISO 8601 timestamp. */
48
+ timestamp: string;
49
+ /** Tool calls requested by the assistant (only on assistant messages). */
50
+ toolCalls?: ToolCall[];
51
+ /** Tool result metadata (only on tool_result messages). */
52
+ toolResult?: ToolResultMeta;
53
+ }
54
+ /**
55
+ * Content format hint for how message content should be rendered.
56
+ *
57
+ * - `markdown` — render with a markdown renderer (default)
58
+ * - `html` — render as raw HTML (dangerouslySetInnerHTML)
59
+ * - `text` — render as plain text
60
+ */
61
+ export type ContentFormat = 'markdown' | 'html' | 'text';
62
+ //# sourceMappingURL=message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/types/message.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,aAAa,CAAC;AAExF;;GAEG;AACH,MAAM,WAAW,QAAQ;IACxB,+DAA+D;IAC/D,EAAE,EAAE,MAAM,CAAC;IACX,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,OAAO,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,yBAAyB;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,IAAI,EAAE,WAAW,CAAC;IAClB,gFAAgF;IAChF,OAAO,EAAE,MAAM,CAAC;IAChB,0BAA0B;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IACvB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,cAAc,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC"}
@@ -0,0 +1,7 @@
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
+ export {};
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Chat session types.
3
+ *
4
+ * Sessions are optional — adapters that don't support sessions
5
+ * operate in single-conversation mode.
6
+ */
7
+ import type { ChatMessage } from './message.ts';
8
+ /**
9
+ * A chat session — a distinct conversation thread.
10
+ */
11
+ export interface ChatSession {
12
+ /** Unique session identifier. */
13
+ id: string;
14
+ /** Human-readable title (may be auto-generated from first message). */
15
+ title?: string;
16
+ /** ISO 8601 timestamp of session creation. */
17
+ createdAt: string;
18
+ /** ISO 8601 timestamp of last activity. */
19
+ updatedAt: string;
20
+ /** Number of messages in the session (optional, for display). */
21
+ messageCount?: number;
22
+ }
23
+ /**
24
+ * Availability state of the chat service.
25
+ *
26
+ * Adapters surface this so the UI can render appropriate states
27
+ * without knowing the business logic behind them.
28
+ */
29
+ export type ChatAvailability = {
30
+ status: 'ready';
31
+ } | {
32
+ status: 'login-required';
33
+ loginUrl?: string;
34
+ } | {
35
+ status: 'unavailable';
36
+ reason?: string;
37
+ } | {
38
+ status: 'provisioning';
39
+ message?: string;
40
+ } | {
41
+ status: 'upgrade-required';
42
+ upgradeUrl?: string;
43
+ message?: string;
44
+ } | {
45
+ status: 'error';
46
+ message: string;
47
+ };
48
+ /**
49
+ * The initial state returned by an adapter on mount.
50
+ */
51
+ export interface ChatInitialState {
52
+ /** Current availability of the chat service. */
53
+ availability: ChatAvailability;
54
+ /** Active session (if resuming). */
55
+ session?: ChatSession;
56
+ /** Messages for the active session (if resuming). */
57
+ messages?: ChatMessage[];
58
+ }
59
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/types/session.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,SAAS,EAAE,MAAM,CAAC;IAClB,2CAA2C;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,iEAAiE;IACjE,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GACzB;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,GACnB;IAAE,MAAM,EAAE,gBAAgB,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/C;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1C;IAAE,MAAM,EAAE,cAAc,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5C;IAAE,MAAM,EAAE,kBAAkB,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GACrE;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,gDAAgD;IAChD,YAAY,EAAE,gBAAgB,CAAC;IAC/B,oCAAoC;IACpC,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;CACzB"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Chat session types.
3
+ *
4
+ * Sessions are optional — adapters that don't support sessions
5
+ * operate in single-conversation mode.
6
+ */
7
+ export {};
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@extrachill/chat",
3
+ "version": "0.2.0",
4
+ "description": "Chat UI components with built-in REST API client. Speaks the standard chat message format natively.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./css": "./css/chat.css",
15
+ "./src": {
16
+ "types": "./src/index.ts",
17
+ "default": "./src/index.ts"
18
+ },
19
+ "./src/*": {
20
+ "types": "./src/*.tsx",
21
+ "default": "./src/*.tsx"
22
+ }
23
+ },
24
+ "files": [
25
+ "src",
26
+ "dist",
27
+ "css",
28
+ "README.md",
29
+ "CHANGELOG.md"
30
+ ],
31
+ "scripts": {
32
+ "build": "tsc",
33
+ "prepublishOnly": "npm run build"
34
+ },
35
+ "keywords": [
36
+ "chat",
37
+ "react",
38
+ "wordpress",
39
+ "gutenberg",
40
+ "ai",
41
+ "components"
42
+ ],
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "https://github.com/Extra-Chill/chat.git"
46
+ },
47
+ "homepage": "https://github.com/Extra-Chill/chat",
48
+ "bugs": "https://github.com/Extra-Chill/chat/issues",
49
+ "license": "GPL-2.0-or-later",
50
+ "peerDependencies": {
51
+ "react": ">=18.0.0",
52
+ "react-dom": ">=18.0.0"
53
+ },
54
+ "devDependencies": {
55
+ "typescript": "^5.7.0",
56
+ "@types/react": "^18.0.0",
57
+ "@types/react-dom": "^18.0.0",
58
+ "react": "^18.0.0",
59
+ "react-dom": "^18.0.0"
60
+ }
61
+ }