@wingmanjs/react 0.1.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/LICENSE +21 -0
- package/dist/components/chat-input.d.ts +9 -0
- package/dist/components/chat-input.d.ts.map +1 -0
- package/dist/components/chat-input.js +36 -0
- package/dist/components/chat-input.js.map +1 -0
- package/dist/components/chat-message.d.ts +10 -0
- package/dist/components/chat-message.d.ts.map +1 -0
- package/dist/components/chat-message.js +9 -0
- package/dist/components/chat-message.js.map +1 -0
- package/dist/components/debug-panel.d.ts +20 -0
- package/dist/components/debug-panel.d.ts.map +1 -0
- package/dist/components/debug-panel.js +29 -0
- package/dist/components/debug-panel.js.map +1 -0
- package/dist/components/markdown-renderer.d.ts +9 -0
- package/dist/components/markdown-renderer.d.ts.map +1 -0
- package/dist/components/markdown-renderer.js +9 -0
- package/dist/components/markdown-renderer.js.map +1 -0
- package/dist/components/mode-switcher.d.ts +18 -0
- package/dist/components/mode-switcher.d.ts.map +1 -0
- package/dist/components/mode-switcher.js +38 -0
- package/dist/components/mode-switcher.js.map +1 -0
- package/dist/components/model-picker.d.ts +19 -0
- package/dist/components/model-picker.d.ts.map +1 -0
- package/dist/components/model-picker.js +50 -0
- package/dist/components/model-picker.js.map +1 -0
- package/dist/components/thinking-block.d.ts +10 -0
- package/dist/components/thinking-block.d.ts.map +1 -0
- package/dist/components/thinking-block.js +12 -0
- package/dist/components/thinking-block.js.map +1 -0
- package/dist/components/token-usage.d.ts +12 -0
- package/dist/components/token-usage.d.ts.map +1 -0
- package/dist/components/token-usage.js +14 -0
- package/dist/components/token-usage.js.map +1 -0
- package/dist/components/tool-status.d.ts +12 -0
- package/dist/components/tool-status.d.ts.map +1 -0
- package/dist/components/tool-status.js +20 -0
- package/dist/components/tool-status.js.map +1 -0
- package/dist/components/welcome-screen.d.ts +12 -0
- package/dist/components/welcome-screen.d.ts.map +1 -0
- package/dist/components/welcome-screen.js +5 -0
- package/dist/components/welcome-screen.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/chat-provider.d.ts +102 -0
- package/dist/providers/chat-provider.d.ts.map +1 -0
- package/dist/providers/chat-provider.js +388 -0
- package/dist/providers/chat-provider.js.map +1 -0
- package/dist/providers/theme-provider.d.ts +72 -0
- package/dist/providers/theme-provider.d.ts.map +1 -0
- package/dist/providers/theme-provider.js +87 -0
- package/dist/providers/theme-provider.js.map +1 -0
- package/package.json +57 -0
- package/src/styles/wingman.css +686 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChatProvider — React context for Wingman chat state.
|
|
3
|
+
*
|
|
4
|
+
* Wraps the entire chat UI and provides shared state for messages,
|
|
5
|
+
* tools, sessions, connection status, and streaming.
|
|
6
|
+
*/
|
|
7
|
+
import React, { type ReactNode } from 'react';
|
|
8
|
+
import type { ChatMessage, ToolExecution, UsageData } from '@wingmanjs/core';
|
|
9
|
+
import { type WingmanTheme, type WingmanThemeColors } from './theme-provider.js';
|
|
10
|
+
export interface ChatState {
|
|
11
|
+
messages: ChatMessage[];
|
|
12
|
+
isStreaming: boolean;
|
|
13
|
+
sessionId: string | null;
|
|
14
|
+
activeTools: Map<string, ToolExecution>;
|
|
15
|
+
currentReasoning: string;
|
|
16
|
+
isReasoningVisible: boolean;
|
|
17
|
+
usage: UsageData | null;
|
|
18
|
+
error: string | null;
|
|
19
|
+
title: string | null;
|
|
20
|
+
model: string | null;
|
|
21
|
+
mode: string | null;
|
|
22
|
+
}
|
|
23
|
+
type ChatAction = {
|
|
24
|
+
type: 'ADD_USER_MESSAGE';
|
|
25
|
+
content: string;
|
|
26
|
+
} | {
|
|
27
|
+
type: 'START_STREAMING';
|
|
28
|
+
} | {
|
|
29
|
+
type: 'STOP_STREAMING';
|
|
30
|
+
} | {
|
|
31
|
+
type: 'APPEND_DELTA';
|
|
32
|
+
content: string;
|
|
33
|
+
} | {
|
|
34
|
+
type: 'APPEND_REASONING';
|
|
35
|
+
content: string;
|
|
36
|
+
} | {
|
|
37
|
+
type: 'SET_REASONING_VISIBLE';
|
|
38
|
+
visible: boolean;
|
|
39
|
+
} | {
|
|
40
|
+
type: 'TOOL_START';
|
|
41
|
+
tool: Pick<ToolExecution, 'toolCallId' | 'toolName' | 'arguments'>;
|
|
42
|
+
} | {
|
|
43
|
+
type: 'TOOL_COMPLETE';
|
|
44
|
+
toolCallId: string;
|
|
45
|
+
toolName: string;
|
|
46
|
+
result: string;
|
|
47
|
+
} | {
|
|
48
|
+
type: 'SET_USAGE';
|
|
49
|
+
usage: UsageData;
|
|
50
|
+
} | {
|
|
51
|
+
type: 'FINISH_STREAMING';
|
|
52
|
+
sessionId: string;
|
|
53
|
+
} | {
|
|
54
|
+
type: 'SET_ERROR';
|
|
55
|
+
message: string;
|
|
56
|
+
} | {
|
|
57
|
+
type: 'CLEAR_ERROR';
|
|
58
|
+
} | {
|
|
59
|
+
type: 'SET_TITLE';
|
|
60
|
+
title: string;
|
|
61
|
+
} | {
|
|
62
|
+
type: 'SET_MODEL';
|
|
63
|
+
model: string;
|
|
64
|
+
} | {
|
|
65
|
+
type: 'SET_MODE';
|
|
66
|
+
mode: string;
|
|
67
|
+
} | {
|
|
68
|
+
type: 'SET_SESSION_ID';
|
|
69
|
+
sessionId: string;
|
|
70
|
+
} | {
|
|
71
|
+
type: 'CLEAR_MESSAGES';
|
|
72
|
+
} | {
|
|
73
|
+
type: 'LOAD_MESSAGES';
|
|
74
|
+
messages: ChatMessage[];
|
|
75
|
+
};
|
|
76
|
+
export interface ChatContextValue {
|
|
77
|
+
state: ChatState;
|
|
78
|
+
dispatch: React.Dispatch<ChatAction>;
|
|
79
|
+
/** Send a message to the agent via SSE. */
|
|
80
|
+
sendMessage: (message: string) => void;
|
|
81
|
+
/** Clear the current conversation and start fresh. */
|
|
82
|
+
newChat: () => void;
|
|
83
|
+
/** Switch the model for the current session. */
|
|
84
|
+
switchModel: (model: string) => Promise<void>;
|
|
85
|
+
/** Set the agent mode for the current session. */
|
|
86
|
+
setMode: (mode: string) => Promise<void>;
|
|
87
|
+
}
|
|
88
|
+
export interface ChatProviderProps {
|
|
89
|
+
children: ReactNode;
|
|
90
|
+
/** Base URL for the Wingman API. Default: '' (same origin). */
|
|
91
|
+
apiUrl?: string;
|
|
92
|
+
/** Color scheme: 'light', 'dark', or 'system'. Default: 'system'. */
|
|
93
|
+
theme?: WingmanTheme;
|
|
94
|
+
/** Override design token colors. */
|
|
95
|
+
colors?: WingmanThemeColors;
|
|
96
|
+
/** Additional CSS class on the theme root container. */
|
|
97
|
+
className?: string;
|
|
98
|
+
}
|
|
99
|
+
export declare function ChatProvider({ children, apiUrl, theme, colors, className }: ChatProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
100
|
+
export declare function useChat(): ChatContextValue;
|
|
101
|
+
export {};
|
|
102
|
+
//# sourceMappingURL=chat-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-provider.d.ts","sourceRoot":"","sources":["../../src/providers/chat-provider.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EAA8D,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC1G,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAiB,KAAK,YAAY,EAAE,KAAK,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAMhG,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACxC,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,K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|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* ChatProvider — React context for Wingman chat state.
|
|
4
|
+
*
|
|
5
|
+
* Wraps the entire chat UI and provides shared state for messages,
|
|
6
|
+
* tools, sessions, connection status, and streaming.
|
|
7
|
+
*/
|
|
8
|
+
import { createContext, useContext, useReducer, useCallback, useRef } from 'react';
|
|
9
|
+
import { ThemeProvider } from './theme-provider.js';
|
|
10
|
+
const initialState = {
|
|
11
|
+
messages: [],
|
|
12
|
+
isStreaming: false,
|
|
13
|
+
sessionId: null,
|
|
14
|
+
activeTools: new Map(),
|
|
15
|
+
currentReasoning: '',
|
|
16
|
+
isReasoningVisible: false,
|
|
17
|
+
usage: null,
|
|
18
|
+
error: null,
|
|
19
|
+
title: null,
|
|
20
|
+
model: null,
|
|
21
|
+
mode: null,
|
|
22
|
+
};
|
|
23
|
+
function chatReducer(state, action) {
|
|
24
|
+
switch (action.type) {
|
|
25
|
+
case 'ADD_USER_MESSAGE':
|
|
26
|
+
return {
|
|
27
|
+
...state,
|
|
28
|
+
messages: [
|
|
29
|
+
...state.messages,
|
|
30
|
+
{
|
|
31
|
+
id: `user-${Date.now()}`,
|
|
32
|
+
role: 'user',
|
|
33
|
+
content: action.content,
|
|
34
|
+
timestamp: Date.now(),
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
error: null,
|
|
38
|
+
};
|
|
39
|
+
case 'START_STREAMING':
|
|
40
|
+
return {
|
|
41
|
+
...state,
|
|
42
|
+
isStreaming: true,
|
|
43
|
+
currentReasoning: '',
|
|
44
|
+
messages: [
|
|
45
|
+
...state.messages,
|
|
46
|
+
{
|
|
47
|
+
id: `assistant-${Date.now()}`,
|
|
48
|
+
role: 'assistant',
|
|
49
|
+
content: '',
|
|
50
|
+
timestamp: Date.now(),
|
|
51
|
+
tools: [],
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
};
|
|
55
|
+
case 'APPEND_DELTA': {
|
|
56
|
+
const msgs = [...state.messages];
|
|
57
|
+
const last = msgs[msgs.length - 1];
|
|
58
|
+
if (last?.role === 'assistant') {
|
|
59
|
+
msgs[msgs.length - 1] = { ...last, content: last.content + action.content };
|
|
60
|
+
}
|
|
61
|
+
return { ...state, messages: msgs };
|
|
62
|
+
}
|
|
63
|
+
case 'APPEND_REASONING':
|
|
64
|
+
return {
|
|
65
|
+
...state,
|
|
66
|
+
currentReasoning: state.currentReasoning + action.content,
|
|
67
|
+
isReasoningVisible: true,
|
|
68
|
+
};
|
|
69
|
+
case 'SET_REASONING_VISIBLE':
|
|
70
|
+
return { ...state, isReasoningVisible: action.visible };
|
|
71
|
+
case 'TOOL_START': {
|
|
72
|
+
const tools = new Map(state.activeTools);
|
|
73
|
+
tools.set(action.tool.toolCallId, {
|
|
74
|
+
toolCallId: action.tool.toolCallId,
|
|
75
|
+
toolName: action.tool.toolName,
|
|
76
|
+
arguments: action.tool.arguments,
|
|
77
|
+
status: 'running',
|
|
78
|
+
startedAt: Date.now(),
|
|
79
|
+
});
|
|
80
|
+
// Also add to the current assistant message's tools array
|
|
81
|
+
const msgs = [...state.messages];
|
|
82
|
+
const last = msgs[msgs.length - 1];
|
|
83
|
+
if (last?.role === 'assistant') {
|
|
84
|
+
msgs[msgs.length - 1] = {
|
|
85
|
+
...last,
|
|
86
|
+
tools: [
|
|
87
|
+
...(last.tools ?? []),
|
|
88
|
+
{
|
|
89
|
+
toolCallId: action.tool.toolCallId,
|
|
90
|
+
toolName: action.tool.toolName,
|
|
91
|
+
arguments: action.tool.arguments,
|
|
92
|
+
status: 'running',
|
|
93
|
+
startedAt: Date.now(),
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return { ...state, activeTools: tools, messages: msgs };
|
|
99
|
+
}
|
|
100
|
+
case 'TOOL_COMPLETE': {
|
|
101
|
+
const tools = new Map(state.activeTools);
|
|
102
|
+
const existing = tools.get(action.toolCallId);
|
|
103
|
+
if (existing) {
|
|
104
|
+
tools.set(action.toolCallId, {
|
|
105
|
+
...existing,
|
|
106
|
+
status: 'complete',
|
|
107
|
+
result: action.result,
|
|
108
|
+
completedAt: Date.now(),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
// Update in messages too
|
|
112
|
+
const msgs = [...state.messages];
|
|
113
|
+
const last = msgs[msgs.length - 1];
|
|
114
|
+
if (last?.role === 'assistant' && last.tools) {
|
|
115
|
+
msgs[msgs.length - 1] = {
|
|
116
|
+
...last,
|
|
117
|
+
tools: last.tools.map((t) => t.toolCallId === action.toolCallId
|
|
118
|
+
? { ...t, status: 'complete', result: action.result, completedAt: Date.now() }
|
|
119
|
+
: t),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return { ...state, activeTools: tools, messages: msgs };
|
|
123
|
+
}
|
|
124
|
+
case 'SET_USAGE': {
|
|
125
|
+
const msgs = [...state.messages];
|
|
126
|
+
const last = msgs[msgs.length - 1];
|
|
127
|
+
if (last?.role === 'assistant') {
|
|
128
|
+
msgs[msgs.length - 1] = { ...last, usage: action.usage };
|
|
129
|
+
}
|
|
130
|
+
return { ...state, usage: action.usage, messages: msgs };
|
|
131
|
+
}
|
|
132
|
+
case 'FINISH_STREAMING': {
|
|
133
|
+
const tools = new Map(state.activeTools);
|
|
134
|
+
// Mark remaining running tools as complete
|
|
135
|
+
for (const [id, tool] of tools) {
|
|
136
|
+
if (tool.status === 'running') {
|
|
137
|
+
tools.set(id, { ...tool, status: 'complete', completedAt: Date.now() });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Attach reasoning to the assistant message
|
|
141
|
+
const msgs = [...state.messages];
|
|
142
|
+
const last = msgs[msgs.length - 1];
|
|
143
|
+
if (last?.role === 'assistant' && state.currentReasoning) {
|
|
144
|
+
msgs[msgs.length - 1] = { ...last, reasoning: state.currentReasoning };
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
...state,
|
|
148
|
+
isStreaming: false,
|
|
149
|
+
sessionId: action.sessionId,
|
|
150
|
+
activeTools: tools,
|
|
151
|
+
currentReasoning: '',
|
|
152
|
+
isReasoningVisible: state.currentReasoning.length > 0,
|
|
153
|
+
messages: msgs,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
case 'SET_ERROR':
|
|
157
|
+
return { ...state, error: action.message, isStreaming: false };
|
|
158
|
+
case 'STOP_STREAMING':
|
|
159
|
+
return { ...state, isStreaming: false };
|
|
160
|
+
case 'CLEAR_ERROR':
|
|
161
|
+
return { ...state, error: null };
|
|
162
|
+
case 'SET_TITLE':
|
|
163
|
+
return { ...state, title: action.title };
|
|
164
|
+
case 'SET_MODEL':
|
|
165
|
+
return { ...state, model: action.model };
|
|
166
|
+
case 'SET_MODE':
|
|
167
|
+
return { ...state, mode: action.mode };
|
|
168
|
+
case 'SET_SESSION_ID':
|
|
169
|
+
return { ...state, sessionId: action.sessionId };
|
|
170
|
+
case 'CLEAR_MESSAGES':
|
|
171
|
+
return { ...initialState };
|
|
172
|
+
case 'LOAD_MESSAGES':
|
|
173
|
+
return { ...state, messages: action.messages };
|
|
174
|
+
default:
|
|
175
|
+
return state;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const ChatContext = createContext(null);
|
|
179
|
+
export function ChatProvider({ children, apiUrl = '', theme, colors, className }) {
|
|
180
|
+
const [state, dispatch] = useReducer(chatReducer, initialState);
|
|
181
|
+
const abortRef = useRef(null);
|
|
182
|
+
const sendMessage = useCallback(async (message) => {
|
|
183
|
+
if (!message.trim() || state.isStreaming)
|
|
184
|
+
return;
|
|
185
|
+
// Abort any in-flight request
|
|
186
|
+
abortRef.current?.abort();
|
|
187
|
+
abortRef.current = new AbortController();
|
|
188
|
+
dispatch({ type: 'CLEAR_ERROR' });
|
|
189
|
+
dispatch({ type: 'ADD_USER_MESSAGE', content: message });
|
|
190
|
+
dispatch({ type: 'START_STREAMING' });
|
|
191
|
+
try {
|
|
192
|
+
const response = await fetch(`${apiUrl}/api/chat`, {
|
|
193
|
+
method: 'POST',
|
|
194
|
+
headers: { 'Content-Type': 'application/json' },
|
|
195
|
+
body: JSON.stringify({
|
|
196
|
+
message,
|
|
197
|
+
sessionId: state.sessionId,
|
|
198
|
+
}),
|
|
199
|
+
signal: abortRef.current.signal,
|
|
200
|
+
});
|
|
201
|
+
if (!response.ok) {
|
|
202
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
203
|
+
}
|
|
204
|
+
const reader = response.body?.getReader();
|
|
205
|
+
if (!reader)
|
|
206
|
+
throw new Error('No response body');
|
|
207
|
+
const decoder = new TextDecoder();
|
|
208
|
+
let buffer = '';
|
|
209
|
+
while (true) {
|
|
210
|
+
const { done, value } = await reader.read();
|
|
211
|
+
if (done)
|
|
212
|
+
break;
|
|
213
|
+
buffer += decoder.decode(value, { stream: true });
|
|
214
|
+
// Parse SSE events from buffer
|
|
215
|
+
const lines = buffer.split('\n');
|
|
216
|
+
buffer = lines.pop() ?? '';
|
|
217
|
+
let currentEvent = '';
|
|
218
|
+
for (const line of lines) {
|
|
219
|
+
if (line.startsWith('event: ')) {
|
|
220
|
+
currentEvent = line.slice(7);
|
|
221
|
+
}
|
|
222
|
+
else if (line.startsWith('data: ') && currentEvent) {
|
|
223
|
+
try {
|
|
224
|
+
const data = JSON.parse(line.slice(6));
|
|
225
|
+
handleSSEEvent(currentEvent, data, dispatch);
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
// Ignore malformed JSON
|
|
229
|
+
}
|
|
230
|
+
currentEvent = '';
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
catch (err) {
|
|
236
|
+
if (err instanceof Error && err.name === 'AbortError')
|
|
237
|
+
return;
|
|
238
|
+
dispatch({
|
|
239
|
+
type: 'SET_ERROR',
|
|
240
|
+
message: err instanceof Error ? err.message : String(err),
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
finally {
|
|
244
|
+
// Always exit streaming state, even if the SSE stream ends
|
|
245
|
+
// without a 'done' event (network drop, server crash, etc.)
|
|
246
|
+
dispatch({ type: 'STOP_STREAMING' });
|
|
247
|
+
}
|
|
248
|
+
}, [apiUrl, state.sessionId, state.isStreaming]);
|
|
249
|
+
const newChat = useCallback(() => {
|
|
250
|
+
abortRef.current?.abort();
|
|
251
|
+
dispatch({ type: 'CLEAR_MESSAGES' });
|
|
252
|
+
}, []);
|
|
253
|
+
const switchModel = useCallback(async (model) => {
|
|
254
|
+
if (!state.sessionId)
|
|
255
|
+
return;
|
|
256
|
+
try {
|
|
257
|
+
const res = await fetch(`${apiUrl}/api/session/${state.sessionId}/model`, {
|
|
258
|
+
method: 'POST',
|
|
259
|
+
headers: { 'Content-Type': 'application/json' },
|
|
260
|
+
body: JSON.stringify({ model }),
|
|
261
|
+
});
|
|
262
|
+
if (res.ok) {
|
|
263
|
+
dispatch({ type: 'SET_MODEL', model });
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
const data = await res.json().catch(() => ({}));
|
|
267
|
+
dispatch({ type: 'SET_ERROR', message: data.error ?? `Failed to switch model (${res.status})` });
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
catch (err) {
|
|
271
|
+
dispatch({ type: 'SET_ERROR', message: err instanceof Error ? err.message : 'Failed to switch model' });
|
|
272
|
+
}
|
|
273
|
+
}, [apiUrl, state.sessionId]);
|
|
274
|
+
const setMode = useCallback(async (mode) => {
|
|
275
|
+
if (!state.sessionId)
|
|
276
|
+
return;
|
|
277
|
+
try {
|
|
278
|
+
const res = await fetch(`${apiUrl}/api/session/${state.sessionId}/mode`, {
|
|
279
|
+
method: 'POST',
|
|
280
|
+
headers: { 'Content-Type': 'application/json' },
|
|
281
|
+
body: JSON.stringify({ mode }),
|
|
282
|
+
});
|
|
283
|
+
if (res.ok) {
|
|
284
|
+
dispatch({ type: 'SET_MODE', mode });
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
const data = await res.json().catch(() => ({}));
|
|
288
|
+
dispatch({ type: 'SET_ERROR', message: data.error ?? `Failed to set mode (${res.status})` });
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
catch (err) {
|
|
292
|
+
dispatch({ type: 'SET_ERROR', message: err instanceof Error ? err.message : 'Failed to set mode' });
|
|
293
|
+
}
|
|
294
|
+
}, [apiUrl, state.sessionId]);
|
|
295
|
+
return (_jsx(ThemeProvider, { theme: theme, colors: colors, className: className, children: _jsx(ChatContext.Provider, { value: { state, dispatch, sendMessage, newChat, switchModel, setMode }, children: children }) }));
|
|
296
|
+
}
|
|
297
|
+
// ---------------------------------------------------------------------------
|
|
298
|
+
// Hook
|
|
299
|
+
// ---------------------------------------------------------------------------
|
|
300
|
+
export function useChat() {
|
|
301
|
+
const context = useContext(ChatContext);
|
|
302
|
+
if (!context) {
|
|
303
|
+
throw new Error('useChat must be used within a <ChatProvider>');
|
|
304
|
+
}
|
|
305
|
+
return context;
|
|
306
|
+
}
|
|
307
|
+
// ---------------------------------------------------------------------------
|
|
308
|
+
// SSE event handler
|
|
309
|
+
// ---------------------------------------------------------------------------
|
|
310
|
+
function handleSSEEvent(event, data, dispatch) {
|
|
311
|
+
switch (event) {
|
|
312
|
+
case 'delta':
|
|
313
|
+
dispatch({ type: 'APPEND_DELTA', content: data.content });
|
|
314
|
+
break;
|
|
315
|
+
case 'reasoning_delta':
|
|
316
|
+
dispatch({ type: 'APPEND_REASONING', content: data.content });
|
|
317
|
+
break;
|
|
318
|
+
case 'tool_start':
|
|
319
|
+
dispatch({
|
|
320
|
+
type: 'TOOL_START',
|
|
321
|
+
tool: {
|
|
322
|
+
toolCallId: data.toolCallId,
|
|
323
|
+
toolName: data.toolName,
|
|
324
|
+
arguments: data.arguments,
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
break;
|
|
328
|
+
case 'tool_complete':
|
|
329
|
+
dispatch({
|
|
330
|
+
type: 'TOOL_COMPLETE',
|
|
331
|
+
toolCallId: data.toolCallId,
|
|
332
|
+
toolName: data.toolName,
|
|
333
|
+
result: data.result,
|
|
334
|
+
});
|
|
335
|
+
break;
|
|
336
|
+
case 'usage':
|
|
337
|
+
dispatch({
|
|
338
|
+
type: 'SET_USAGE',
|
|
339
|
+
usage: {
|
|
340
|
+
inputTokens: data.inputTokens,
|
|
341
|
+
outputTokens: data.outputTokens,
|
|
342
|
+
cacheReadTokens: data.cacheReadTokens,
|
|
343
|
+
cacheWriteTokens: data.cacheWriteTokens,
|
|
344
|
+
model: data.model,
|
|
345
|
+
},
|
|
346
|
+
});
|
|
347
|
+
break;
|
|
348
|
+
case 'done':
|
|
349
|
+
dispatch({ type: 'FINISH_STREAMING', sessionId: data.sessionId });
|
|
350
|
+
break;
|
|
351
|
+
case 'error':
|
|
352
|
+
dispatch({ type: 'SET_ERROR', message: data.message });
|
|
353
|
+
break;
|
|
354
|
+
case 'title_changed':
|
|
355
|
+
dispatch({ type: 'SET_TITLE', title: data.title });
|
|
356
|
+
break;
|
|
357
|
+
case 'model_change':
|
|
358
|
+
dispatch({ type: 'SET_MODEL', model: data.model });
|
|
359
|
+
break;
|
|
360
|
+
case 'mode_changed':
|
|
361
|
+
dispatch({ type: 'SET_MODE', mode: data.mode });
|
|
362
|
+
break;
|
|
363
|
+
case 'heartbeat':
|
|
364
|
+
case 'turn_start':
|
|
365
|
+
case 'turn_end':
|
|
366
|
+
case 'intent':
|
|
367
|
+
case 'tool_progress':
|
|
368
|
+
case 'info':
|
|
369
|
+
case 'warning':
|
|
370
|
+
case 'reasoning':
|
|
371
|
+
case 'skill_invoked':
|
|
372
|
+
case 'subagent_started':
|
|
373
|
+
case 'subagent_completed':
|
|
374
|
+
case 'subagent_failed':
|
|
375
|
+
case 'truncation':
|
|
376
|
+
case 'compaction_start':
|
|
377
|
+
case 'compaction_complete':
|
|
378
|
+
// These are handled but don't need state updates in Phase 0.
|
|
379
|
+
// Phase 1 will add dedicated UI for each.
|
|
380
|
+
break;
|
|
381
|
+
default:
|
|
382
|
+
if (process.env.NODE_ENV === 'development') {
|
|
383
|
+
console.debug(`[wingman] Unhandled SSE event: ${event}`, data);
|
|
384
|
+
}
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
//# sourceMappingURL=chat-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-provider.js","sourceRoot":"","sources":["../../src/providers/chat-provider.tsx"],"names":[],"mappings":";AAAA;;;;;GAKG;AAEH,OAAc,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAkB,MAAM,OAAO,CAAC;AAE1G,OAAO,EAAE,aAAa,EAA8C,MAAM,qBAAqB,CAAC;AAoBhG,MAAM,YAAY,GAAc;IAC9B,QAAQ,EAAE,EAAE;IACZ,WAAW,EAAE,KAAK;IAClB,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,IAAI,GAAG,EAAE;IACtB,gBAAgB,EAAE,EAAE;IACpB,kBAAkB,EAAE,KAAK;IACzB,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,IAAI,EAAE,IAAI;CACX,CAAC;AA0BF,SAAS,WAAW,CAAC,KAAgB,EAAE,MAAkB;IACvD,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,kBAAkB;YACrB,OAAO;gBACL,GAAG,KAAK;gBACR,QAAQ,EAAE;oBACR,GAAG,KAAK,CAAC,QAAQ;oBACjB;wBACE,EAAE,EAAE,QAAQ,IAAI,CAAC,GAAG,EAAE,EAAE;wBACxB,IAAI,EAAE,MAAM;wBACZ,OAAO,EAAE,MAAM,CAAC,OAAO;wBACvB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;qBACtB;iBACF;gBACD,KAAK,EAAE,IAAI;aACZ,CAAC;QAEJ,KAAK,iBAAiB;YACpB,OAAO;gBACL,GAAG,KAA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D,MAAM;QACR,KAAK,WAAW,CAAC;QACjB,KAAK,YAAY,CAAC;QAClB,KAAK,UAAU,CAAC;QAChB,KAAK,QAAQ,CAAC;QACd,KAAK,eAAe,CAAC;QACrB,KAAK,MAAM,CAAC;QACZ,KAAK,SAAS,CAAC;QACf,KAAK,WAAW,CAAC;QACjB,KAAK,eAAe,CAAC;QACrB,KAAK,kBAAkB,CAAC;QACxB,KAAK,oBAAoB,CAAC;QAC1B,KAAK,iBAAiB,CAAC;QACvB,KAAK,YAAY,CAAC;QAClB,KAAK,kBAAkB,CAAC;QACxB,KAAK,qBAAqB;YACxB,6DAA6D;YAC7D,0CAA0C;YAC1C,MAAM;QACR;YACE,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE,CAAC;gBAC3C,OAAO,CAAC,KAAK,CAAC,kCAAkC,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;YACjE,CAAC;YACD,MAAM;IACV,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ThemeProvider — Applies Wingman theme via CSS custom properties.
|
|
3
|
+
*
|
|
4
|
+
* Wraps children in a `.wingman-root` container that carries the
|
|
5
|
+
* `data-wingman-theme` attribute for light/dark/system mode and
|
|
6
|
+
* injects any color overrides as inline CSS custom properties.
|
|
7
|
+
*/
|
|
8
|
+
import { type ReactNode } from 'react';
|
|
9
|
+
export type WingmanTheme = 'light' | 'dark' | 'system';
|
|
10
|
+
export interface WingmanThemeColors {
|
|
11
|
+
/** Primary accent (buttons, links, highlights). */
|
|
12
|
+
primary?: string;
|
|
13
|
+
/** Primary accent hover state. */
|
|
14
|
+
primaryHover?: string;
|
|
15
|
+
/** Primary accent subtle (focus rings, badges). */
|
|
16
|
+
primarySubtle?: string;
|
|
17
|
+
/** Main background. */
|
|
18
|
+
bg?: string;
|
|
19
|
+
/** Secondary background (cards, sidebars). */
|
|
20
|
+
bgSecondary?: string;
|
|
21
|
+
/** Tertiary background (code blocks, inputs). */
|
|
22
|
+
bgTertiary?: string;
|
|
23
|
+
/** Hover background. */
|
|
24
|
+
bgHover?: string;
|
|
25
|
+
/** Primary text. */
|
|
26
|
+
text?: string;
|
|
27
|
+
/** Secondary text. */
|
|
28
|
+
textSecondary?: string;
|
|
29
|
+
/** Tertiary text (placeholders). */
|
|
30
|
+
textTertiary?: string;
|
|
31
|
+
/** Inverse text (on primary-colored surfaces). */
|
|
32
|
+
textInverse?: string;
|
|
33
|
+
/** Border. */
|
|
34
|
+
border?: string;
|
|
35
|
+
/** Subtle border. */
|
|
36
|
+
borderSubtle?: string;
|
|
37
|
+
/** Success color. */
|
|
38
|
+
success?: string;
|
|
39
|
+
/** Error color. */
|
|
40
|
+
error?: string;
|
|
41
|
+
/** Warning color. */
|
|
42
|
+
warning?: string;
|
|
43
|
+
/** User message background. */
|
|
44
|
+
userBg?: string;
|
|
45
|
+
/** User message text. */
|
|
46
|
+
userText?: string;
|
|
47
|
+
/** Assistant message background. */
|
|
48
|
+
assistantBg?: string;
|
|
49
|
+
/** Assistant message text. */
|
|
50
|
+
assistantText?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface ThemeProviderProps {
|
|
53
|
+
children: ReactNode;
|
|
54
|
+
/** Color scheme: 'light', 'dark', or 'system' (OS preference). Default: 'system'. */
|
|
55
|
+
theme?: WingmanTheme;
|
|
56
|
+
/** Override any design token color. Mapped to --wm-* CSS custom properties. */
|
|
57
|
+
colors?: WingmanThemeColors;
|
|
58
|
+
/** Additional CSS class on the root container. */
|
|
59
|
+
className?: string;
|
|
60
|
+
}
|
|
61
|
+
export interface ThemeContextValue {
|
|
62
|
+
/** The resolved theme ('light' or 'dark' — never 'system'). */
|
|
63
|
+
resolvedTheme: 'light' | 'dark';
|
|
64
|
+
/** The raw theme prop value. */
|
|
65
|
+
theme: WingmanTheme;
|
|
66
|
+
/** Active color overrides. */
|
|
67
|
+
colors: WingmanThemeColors;
|
|
68
|
+
}
|
|
69
|
+
/** Access the current Wingman theme. Must be used inside <ThemeProvider>. */
|
|
70
|
+
export declare function useTheme(): ThemeContextValue;
|
|
71
|
+
export declare function ThemeProvider({ children, theme, colors, className, }: ThemeProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
72
|
+
//# sourceMappingURL=theme-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-provider.d.ts","sourceRoot":"","sources":["../../src/providers/theme-provider.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAc,EAMZ,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AAMf,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEvD,MAAM,WAAW,kBAAkB;IACjC,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kCAAkC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mDAAmD;IACnD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,uBAAuB;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iDAAiD;IACjD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wBAAwB;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sBAAsB;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oCAAoC;IACpC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qBAAqB;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qBAAqB;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mBAAmB;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IAC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