@bytespell/amux-client 0.0.19 → 0.0.22
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/dist/react/context.d.ts.map +1 -1
- package/dist/react/context.js +22 -0
- package/dist/react/context.js.map +1 -1
- package/dist/react/hooks.d.ts.map +1 -1
- package/dist/react/hooks.js +67 -4
- package/dist/react/hooks.js.map +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +5 -4
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
- package/src/react/context.tsx +33 -6
- package/src/react/hooks.ts +81 -4
- package/src/react/index.ts +11 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/accumulator.d.ts +0 -77
- package/dist/client.d.ts +0 -155
- package/dist/connection.d.ts +0 -81
- package/dist/index.d.ts +0 -35
- package/dist/react/context.d.ts +0 -60
- package/dist/react/hooks.d.ts +0 -153
- package/dist/react/index.d.ts +0 -29
- package/dist/types.d.ts +0 -166
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/react/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAiE,MAAM,OAAO,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,iBAAiB,EAAoB,gBAAgB,EAAE,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/react/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAiE,MAAM,OAAO,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,iBAAiB,EAAoB,gBAAgB,EAAE,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC9H,OAAO,KAAK,EAAE,SAAS,EAAE,e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JvE;AAED;;;GAGG;AACH,wBAAgB,cAAc,IAAI,gBAAgB,CAMjD"}
|
package/dist/react/context.js
CHANGED
|
@@ -30,10 +30,14 @@ export function AmuxProvider({ children, ...options }) {
|
|
|
30
30
|
const [sessionId, setSessionId] = useState(client.sessionId);
|
|
31
31
|
const [agent, setAgent] = useState(client.agent);
|
|
32
32
|
const [availableAgents, setAvailableAgents] = useState(client.availableAgents);
|
|
33
|
+
const [availableModels, setAvailableModels] = useState(client.availableModels);
|
|
34
|
+
const [currentModelId, setCurrentModelId] = useState(client.currentModelId);
|
|
35
|
+
const [sessions, setSessions] = useState([]);
|
|
33
36
|
const [isProcessing, setIsProcessing] = useState(client.isProcessing);
|
|
34
37
|
const [pendingPermission, setPendingPermission] = useState(client.pendingPermission);
|
|
35
38
|
const [messages, setMessages] = useState([]);
|
|
36
39
|
const [turns, setTurns] = useState([]);
|
|
40
|
+
const [error, setError] = useState(null);
|
|
37
41
|
// Subscribe to client events
|
|
38
42
|
useEffect(() => {
|
|
39
43
|
const handleConnectionStatus = ({ status }) => {
|
|
@@ -45,6 +49,10 @@ export function AmuxProvider({ children, ...options }) {
|
|
|
45
49
|
setSessionId(data.sessionId);
|
|
46
50
|
setAgent(data.agent);
|
|
47
51
|
setAvailableAgents(data.availableAgents);
|
|
52
|
+
setAvailableModels(data.availableModels ?? []);
|
|
53
|
+
setCurrentModelId(data.currentModelId ?? null);
|
|
54
|
+
// Clear error on successful connection
|
|
55
|
+
setError(null);
|
|
48
56
|
};
|
|
49
57
|
const handleConnecting = () => {
|
|
50
58
|
setIsReady(false);
|
|
@@ -64,12 +72,18 @@ export function AmuxProvider({ children, ...options }) {
|
|
|
64
72
|
const handleSessionSwitched = (data) => {
|
|
65
73
|
setSessionId(data.sessionId);
|
|
66
74
|
};
|
|
75
|
+
const handleSessions = (data) => {
|
|
76
|
+
setSessions(data.sessions);
|
|
77
|
+
};
|
|
67
78
|
const handleMessagesUpdated = ({ messages: msgs }) => {
|
|
68
79
|
setMessages([...msgs]);
|
|
69
80
|
};
|
|
70
81
|
const handleTurnsUpdated = ({ turns: t }) => {
|
|
71
82
|
setTurns([...t]);
|
|
72
83
|
};
|
|
84
|
+
const handleError = (data) => {
|
|
85
|
+
setError(data.message);
|
|
86
|
+
};
|
|
73
87
|
const handleAgentExit = () => {
|
|
74
88
|
setIsReady(false);
|
|
75
89
|
setIsProcessing(false);
|
|
@@ -82,8 +96,10 @@ export function AmuxProvider({ children, ...options }) {
|
|
|
82
96
|
client.on('permission_request', handlePermissionRequest);
|
|
83
97
|
client.on('session_created', handleSessionCreated);
|
|
84
98
|
client.on('session_switched', handleSessionSwitched);
|
|
99
|
+
client.on('sessions', handleSessions);
|
|
85
100
|
client.on('messages_updated', handleMessagesUpdated);
|
|
86
101
|
client.on('turns_updated', handleTurnsUpdated);
|
|
102
|
+
client.on('error', handleError);
|
|
87
103
|
client.on('agent_exit', handleAgentExit);
|
|
88
104
|
return () => {
|
|
89
105
|
client.off('connection_status', handleConnectionStatus);
|
|
@@ -94,8 +110,10 @@ export function AmuxProvider({ children, ...options }) {
|
|
|
94
110
|
client.off('permission_request', handlePermissionRequest);
|
|
95
111
|
client.off('session_created', handleSessionCreated);
|
|
96
112
|
client.off('session_switched', handleSessionSwitched);
|
|
113
|
+
client.off('sessions', handleSessions);
|
|
97
114
|
client.off('messages_updated', handleMessagesUpdated);
|
|
98
115
|
client.off('turns_updated', handleTurnsUpdated);
|
|
116
|
+
client.off('error', handleError);
|
|
99
117
|
client.off('agent_exit', handleAgentExit);
|
|
100
118
|
};
|
|
101
119
|
}, [client]);
|
|
@@ -114,6 +132,9 @@ export function AmuxProvider({ children, ...options }) {
|
|
|
114
132
|
sessionId,
|
|
115
133
|
agent,
|
|
116
134
|
availableAgents,
|
|
135
|
+
availableModels,
|
|
136
|
+
currentModelId,
|
|
137
|
+
sessions,
|
|
117
138
|
isProcessing,
|
|
118
139
|
isStreaming: client.isStreaming,
|
|
119
140
|
isAwaitingPermission: pendingPermission !== null,
|
|
@@ -121,6 +142,7 @@ export function AmuxProvider({ children, ...options }) {
|
|
|
121
142
|
messages,
|
|
122
143
|
turns,
|
|
123
144
|
currentTurn: client.currentTurn,
|
|
145
|
+
error,
|
|
124
146
|
};
|
|
125
147
|
return _jsx(AmuxContext.Provider, { value: value, children: children });
|
|
126
148
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/react/context.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/react/context.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAwC1C,MAAM,WAAW,GAAG,aAAa,CAA0B,IAAI,CAAC,CAAC;AASjE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,YAAY,CAAC,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAqB;IACtE,MAAM,SAAS,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IAElD,yBAAyB;IACzB,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QACvB,SAAS,CAAC,OAAO,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC;IAEjC,iCAAiC;IACjC,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,QAAQ,CAAmB,MAAM,CAAC,gBAAgB,CAAC,CAAC;IACpG,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,C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AAC,CAAC;IAEb,MAAM,KAAK,GAAqB;QAC9B,MAAM;QACN,gBAAgB;QAChB,WAAW,EAAE,gBAAgB,KAAK,WAAW,IAAI,gBAAgB,KAAK,OAAO;QAC7E,OAAO;QACP,GAAG;QACH,SAAS;QACT,KAAK;QACL,eAAe;QACf,eAAe;QACf,cAAc;QACd,QAAQ;QACR,YAAY;QACZ,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,oBAAoB,EAAE,iBAAiB,KAAK,IAAI;QAChD,iBAAiB;QACjB,QAAQ;QACR,KAAK;QACL,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,KAAK;KACN,CAAC;IAEF,OAAO,KAAC,WAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAwB,CAAC;AAC/E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IACxC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/react/hooks.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC3G,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/react/hooks.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC3G,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM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YG;AACH,wBAAgB,aAAa,IAAI,UAAU,CAS1C;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,WAAW,EAAE,IAAI,GAAG,IAAI,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAQ9C;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,gBAAgB,EAC3D,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,IAAI,GAC3C,IAAI,CAYN;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,IAAI,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAGzD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,IAAI,CAO9C"}
|
package/dist/react/hooks.js
CHANGED
|
@@ -26,7 +26,9 @@ export function useAmux() {
|
|
|
26
26
|
* @example
|
|
27
27
|
* ```tsx
|
|
28
28
|
* function StatusBar() {
|
|
29
|
-
* const { isConnected, isReady, cwd, agent } = useAmuxState();
|
|
29
|
+
* const { isConnected, isReady, cwd, agent, error } = useAmuxState();
|
|
30
|
+
*
|
|
31
|
+
* if (error) return <div className="error">{error}</div>;
|
|
30
32
|
*
|
|
31
33
|
* return (
|
|
32
34
|
* <div>
|
|
@@ -37,7 +39,7 @@ export function useAmux() {
|
|
|
37
39
|
* ```
|
|
38
40
|
*/
|
|
39
41
|
export function useAmuxState() {
|
|
40
|
-
const { connectionStatus, isConnected, isReady, cwd, sessionId, agent, availableAgents } = useAmuxContext();
|
|
42
|
+
const { connectionStatus, isConnected, isReady, cwd, sessionId, agent, availableAgents, sessions, error } = useAmuxContext();
|
|
41
43
|
return {
|
|
42
44
|
connectionStatus,
|
|
43
45
|
isConnected,
|
|
@@ -46,6 +48,37 @@ export function useAmuxState() {
|
|
|
46
48
|
sessionId,
|
|
47
49
|
agent,
|
|
48
50
|
availableAgents,
|
|
51
|
+
sessions,
|
|
52
|
+
error,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get reactive model state
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```tsx
|
|
60
|
+
* function ModelPicker() {
|
|
61
|
+
* const { availableModels, currentModelId } = useAmuxModels();
|
|
62
|
+
* const client = useAmux();
|
|
63
|
+
*
|
|
64
|
+
* return (
|
|
65
|
+
* <select
|
|
66
|
+
* value={currentModelId ?? ''}
|
|
67
|
+
* onChange={e => client.setModel(e.target.value)}
|
|
68
|
+
* >
|
|
69
|
+
* {availableModels.map(m => (
|
|
70
|
+
* <option key={m.id} value={m.id}>{m.name}</option>
|
|
71
|
+
* ))}
|
|
72
|
+
* </select>
|
|
73
|
+
* );
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export function useAmuxModels() {
|
|
78
|
+
const { availableModels, currentModelId } = useAmuxContext();
|
|
79
|
+
return {
|
|
80
|
+
availableModels,
|
|
81
|
+
currentModelId,
|
|
49
82
|
};
|
|
50
83
|
}
|
|
51
84
|
/**
|
|
@@ -76,11 +109,13 @@ export function useAmuxStatus() {
|
|
|
76
109
|
* @example
|
|
77
110
|
* ```tsx
|
|
78
111
|
* function MessageList() {
|
|
79
|
-
* const {
|
|
112
|
+
* const { turns, currentTurn } = useAmuxMessages();
|
|
80
113
|
*
|
|
81
114
|
* return (
|
|
82
115
|
* <>
|
|
83
|
-
* {
|
|
116
|
+
* {turns.map(turn => (
|
|
117
|
+
* <Turn key={turn.id} turn={turn} />
|
|
118
|
+
* ))}
|
|
84
119
|
* {currentTurn?.status === 'streaming' && <StreamingIndicator />}
|
|
85
120
|
* </>
|
|
86
121
|
* );
|
|
@@ -153,4 +188,32 @@ export function useAmuxPrompt() {
|
|
|
153
188
|
const { client } = useAmuxContext();
|
|
154
189
|
return useCallback((message) => client.prompt(message), [client]);
|
|
155
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Clear the current error
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```tsx
|
|
196
|
+
* function ErrorBanner() {
|
|
197
|
+
* const { error } = useAmuxState();
|
|
198
|
+
* const clearError = useAmuxClearError();
|
|
199
|
+
*
|
|
200
|
+
* if (!error) return null;
|
|
201
|
+
*
|
|
202
|
+
* return (
|
|
203
|
+
* <div className="error">
|
|
204
|
+
* {error}
|
|
205
|
+
* <button onClick={clearError}>Dismiss</button>
|
|
206
|
+
* </div>
|
|
207
|
+
* );
|
|
208
|
+
* }
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
export function useAmuxClearError() {
|
|
212
|
+
// Note: This requires the context to expose a clearError function
|
|
213
|
+
// For now, errors auto-clear on successful connection
|
|
214
|
+
// This hook is a placeholder for future enhancement
|
|
215
|
+
return useCallback(() => {
|
|
216
|
+
// No-op for now - errors clear on successful ready event
|
|
217
|
+
}, []);
|
|
218
|
+
}
|
|
156
219
|
//# sourceMappingURL=hooks.js.map
|
package/dist/react/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/react/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/react/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAK9C;;;;;;;;;;;;;;;GAeG;A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;IAEpC,2DAA2D;IAC3D,MAAM,aAAa,GAAG,WAAW,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEtD,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;QAChC,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;QACnC,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,CAAC;IACpC,OAAO,WAAW,CAAC,CAAC,OAAe,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,iBAAiB;IAC/B,kEAAkE;IAClE,sDAAsD;IACtD,oDAAoD;IACpD,OAAO,WAAW,CAAC,GAAG,EAAE;QACtB,yDAAyD;IAC3D,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC5D,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAExE,OAAO,EACL,OAAO,EACP,YAAY,EACZ,aAAa,EACb,eAAe,EACf,aAAa,EACb,YAAY,EACZ,aAAa,EACb,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGlF,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/react/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @example
|
|
5
5
|
* ```tsx
|
|
6
|
-
* import { AmuxProvider, useAmux, useAmuxState, useAmuxMessages } from '@bytespell/amux-client/react';
|
|
6
|
+
* import { AmuxProvider, useAmux, useAmuxState, useAmuxMessages, useAmuxModels } from '@bytespell/amux-client/react';
|
|
7
7
|
*
|
|
8
8
|
* function App() {
|
|
9
9
|
* return (
|
|
@@ -15,13 +15,14 @@
|
|
|
15
15
|
*
|
|
16
16
|
* function Chat() {
|
|
17
17
|
* const client = useAmux();
|
|
18
|
-
* const { isReady, cwd, agent } = useAmuxState();
|
|
19
|
-
* const {
|
|
18
|
+
* const { isReady, cwd, agent, error } = useAmuxState();
|
|
19
|
+
* const { turns, currentTurn } = useAmuxMessages();
|
|
20
|
+
* const { availableModels, currentModelId } = useAmuxModels();
|
|
20
21
|
*
|
|
21
22
|
* // ...
|
|
22
23
|
* }
|
|
23
24
|
* ```
|
|
24
25
|
*/
|
|
25
26
|
export { AmuxProvider, useAmuxContext } from './context.js';
|
|
26
|
-
export { useAmux, useAmuxState, useAmuxStatus, useAmuxMessages, useAmuxEvent, useAmuxPrompt, } from './hooks.js';
|
|
27
|
+
export { useAmux, useAmuxState, useAmuxStatus, useAmuxMessages, useAmuxModels, useAmuxEvent, useAmuxPrompt, useAmuxClearError, } from './hooks.js';
|
|
27
28
|
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG5D,OAAO,EACL,OAAO,EACP,YAAY,EACZ,aAAa,EACb,eAAe,EACf,aAAa,EACb,YAAY,EACZ,aAAa,EACb,iBAAiB,GAClB,MAAM,YAAY,CAAC"}
|
package/package.json
CHANGED
package/src/react/context.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { createContext, useContext, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { AmuxClient } from '../client.js';
|
|
3
3
|
import type { AmuxClientOptions, AmuxClientEvents, ConnectionStatus, Message, Turn, PermissionOptionData } from '../types.js';
|
|
4
|
+
import type { ModelInfo, SessionMetadata } from '@bytespell/amux-types';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Amux context value
|
|
@@ -16,6 +17,11 @@ export interface AmuxContextValue {
|
|
|
16
17
|
sessionId: string | null;
|
|
17
18
|
agent: { type: string; name: string } | null;
|
|
18
19
|
availableAgents: Array<{ id: string; name: string }>;
|
|
20
|
+
// Model state
|
|
21
|
+
availableModels: ModelInfo[];
|
|
22
|
+
currentModelId: string | null;
|
|
23
|
+
// Session management
|
|
24
|
+
sessions: SessionMetadata[];
|
|
19
25
|
// Processing state
|
|
20
26
|
isProcessing: boolean;
|
|
21
27
|
isStreaming: boolean;
|
|
@@ -29,6 +35,8 @@ export interface AmuxContextValue {
|
|
|
29
35
|
messages: Message[];
|
|
30
36
|
turns: Turn[];
|
|
31
37
|
currentTurn: Turn | null;
|
|
38
|
+
// Error state
|
|
39
|
+
error: string | null;
|
|
32
40
|
}
|
|
33
41
|
|
|
34
42
|
const AmuxContext = createContext<AmuxContextValue | null>(null);
|
|
@@ -71,10 +79,14 @@ export function AmuxProvider({ children, ...options }: AmuxProviderProps) {
|
|
|
71
79
|
const [sessionId, setSessionId] = useState(client.sessionId);
|
|
72
80
|
const [agent, setAgent] = useState(client.agent);
|
|
73
81
|
const [availableAgents, setAvailableAgents] = useState(client.availableAgents);
|
|
82
|
+
const [availableModels, setAvailableModels] = useState<ModelInfo[]>(client.availableModels);
|
|
83
|
+
const [currentModelId, setCurrentModelId] = useState<string | null>(client.currentModelId);
|
|
84
|
+
const [sessions, setSessions] = useState<SessionMetadata[]>([]);
|
|
74
85
|
const [isProcessing, setIsProcessing] = useState(client.isProcessing);
|
|
75
86
|
const [pendingPermission, setPendingPermission] = useState(client.pendingPermission);
|
|
76
87
|
const [messages, setMessages] = useState<Message[]>([]);
|
|
77
88
|
const [turns, setTurns] = useState<Turn[]>([]);
|
|
89
|
+
const [error, setError] = useState<string | null>(null);
|
|
78
90
|
|
|
79
91
|
// Subscribe to client events
|
|
80
92
|
useEffect(() => {
|
|
@@ -82,17 +94,16 @@ export function AmuxProvider({ children, ...options }: AmuxProviderProps) {
|
|
|
82
94
|
setConnectionStatus(status);
|
|
83
95
|
};
|
|
84
96
|
|
|
85
|
-
const handleReady = (data: {
|
|
86
|
-
cwd: string;
|
|
87
|
-
sessionId: string | null;
|
|
88
|
-
agent: { type: string; name: string };
|
|
89
|
-
availableAgents: Array<{ id: string; name: string }>;
|
|
90
|
-
}) => {
|
|
97
|
+
const handleReady = (data: AmuxClientEvents['ready']) => {
|
|
91
98
|
setIsReady(true);
|
|
92
99
|
setCwd(data.cwd);
|
|
93
100
|
setSessionId(data.sessionId);
|
|
94
101
|
setAgent(data.agent);
|
|
95
102
|
setAvailableAgents(data.availableAgents);
|
|
103
|
+
setAvailableModels(data.availableModels ?? []);
|
|
104
|
+
setCurrentModelId(data.currentModelId ?? null);
|
|
105
|
+
// Clear error on successful connection
|
|
106
|
+
setError(null);
|
|
96
107
|
};
|
|
97
108
|
|
|
98
109
|
const handleConnecting = () => {
|
|
@@ -119,6 +130,10 @@ export function AmuxProvider({ children, ...options }: AmuxProviderProps) {
|
|
|
119
130
|
setSessionId(data.sessionId);
|
|
120
131
|
};
|
|
121
132
|
|
|
133
|
+
const handleSessions = (data: AmuxClientEvents['sessions']) => {
|
|
134
|
+
setSessions(data.sessions as SessionMetadata[]);
|
|
135
|
+
};
|
|
136
|
+
|
|
122
137
|
const handleMessagesUpdated = ({ messages: msgs }: { messages: Message[] }) => {
|
|
123
138
|
setMessages([...msgs]);
|
|
124
139
|
};
|
|
@@ -127,6 +142,10 @@ export function AmuxProvider({ children, ...options }: AmuxProviderProps) {
|
|
|
127
142
|
setTurns([...t]);
|
|
128
143
|
};
|
|
129
144
|
|
|
145
|
+
const handleError = (data: AmuxClientEvents['error']) => {
|
|
146
|
+
setError(data.message);
|
|
147
|
+
};
|
|
148
|
+
|
|
130
149
|
const handleAgentExit = () => {
|
|
131
150
|
setIsReady(false);
|
|
132
151
|
setIsProcessing(false);
|
|
@@ -140,8 +159,10 @@ export function AmuxProvider({ children, ...options }: AmuxProviderProps) {
|
|
|
140
159
|
client.on('permission_request', handlePermissionRequest);
|
|
141
160
|
client.on('session_created', handleSessionCreated);
|
|
142
161
|
client.on('session_switched', handleSessionSwitched);
|
|
162
|
+
client.on('sessions', handleSessions);
|
|
143
163
|
client.on('messages_updated', handleMessagesUpdated);
|
|
144
164
|
client.on('turns_updated', handleTurnsUpdated);
|
|
165
|
+
client.on('error', handleError);
|
|
145
166
|
client.on('agent_exit', handleAgentExit);
|
|
146
167
|
|
|
147
168
|
return () => {
|
|
@@ -153,8 +174,10 @@ export function AmuxProvider({ children, ...options }: AmuxProviderProps) {
|
|
|
153
174
|
client.off('permission_request', handlePermissionRequest);
|
|
154
175
|
client.off('session_created', handleSessionCreated);
|
|
155
176
|
client.off('session_switched', handleSessionSwitched);
|
|
177
|
+
client.off('sessions', handleSessions);
|
|
156
178
|
client.off('messages_updated', handleMessagesUpdated);
|
|
157
179
|
client.off('turns_updated', handleTurnsUpdated);
|
|
180
|
+
client.off('error', handleError);
|
|
158
181
|
client.off('agent_exit', handleAgentExit);
|
|
159
182
|
};
|
|
160
183
|
}, [client]);
|
|
@@ -175,6 +198,9 @@ export function AmuxProvider({ children, ...options }: AmuxProviderProps) {
|
|
|
175
198
|
sessionId,
|
|
176
199
|
agent,
|
|
177
200
|
availableAgents,
|
|
201
|
+
availableModels,
|
|
202
|
+
currentModelId,
|
|
203
|
+
sessions,
|
|
178
204
|
isProcessing,
|
|
179
205
|
isStreaming: client.isStreaming,
|
|
180
206
|
isAwaitingPermission: pendingPermission !== null,
|
|
@@ -182,6 +208,7 @@ export function AmuxProvider({ children, ...options }: AmuxProviderProps) {
|
|
|
182
208
|
messages,
|
|
183
209
|
turns,
|
|
184
210
|
currentTurn: client.currentTurn,
|
|
211
|
+
error,
|
|
185
212
|
};
|
|
186
213
|
|
|
187
214
|
return <AmuxContext.Provider value={value}>{children}</AmuxContext.Provider>;
|
package/src/react/hooks.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { useEffect, useCallback } from 'react';
|
|
|
2
2
|
import { useAmuxContext } from './context.js';
|
|
3
3
|
import type { AmuxClientEvents, ConnectionStatus, Message, Turn, PermissionOptionData } from '../types.js';
|
|
4
4
|
import type { AmuxClient } from '../client.js';
|
|
5
|
+
import type { ModelInfo, SessionMetadata } from '@bytespell/amux-types';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Get the AmuxClient instance
|
|
@@ -35,6 +36,8 @@ export interface AmuxState {
|
|
|
35
36
|
sessionId: string | null;
|
|
36
37
|
agent: { type: string; name: string } | null;
|
|
37
38
|
availableAgents: Array<{ id: string; name: string }>;
|
|
39
|
+
sessions: SessionMetadata[];
|
|
40
|
+
error: string | null;
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
/**
|
|
@@ -43,7 +46,9 @@ export interface AmuxState {
|
|
|
43
46
|
* @example
|
|
44
47
|
* ```tsx
|
|
45
48
|
* function StatusBar() {
|
|
46
|
-
* const { isConnected, isReady, cwd, agent } = useAmuxState();
|
|
49
|
+
* const { isConnected, isReady, cwd, agent, error } = useAmuxState();
|
|
50
|
+
*
|
|
51
|
+
* if (error) return <div className="error">{error}</div>;
|
|
47
52
|
*
|
|
48
53
|
* return (
|
|
49
54
|
* <div>
|
|
@@ -54,7 +59,7 @@ export interface AmuxState {
|
|
|
54
59
|
* ```
|
|
55
60
|
*/
|
|
56
61
|
export function useAmuxState(): AmuxState {
|
|
57
|
-
const { connectionStatus, isConnected, isReady, cwd, sessionId, agent, availableAgents } =
|
|
62
|
+
const { connectionStatus, isConnected, isReady, cwd, sessionId, agent, availableAgents, sessions, error } =
|
|
58
63
|
useAmuxContext();
|
|
59
64
|
|
|
60
65
|
return {
|
|
@@ -65,6 +70,47 @@ export function useAmuxState(): AmuxState {
|
|
|
65
70
|
sessionId,
|
|
66
71
|
agent,
|
|
67
72
|
availableAgents,
|
|
73
|
+
sessions,
|
|
74
|
+
error,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Model state returned by useAmuxModels
|
|
80
|
+
*/
|
|
81
|
+
export interface AmuxModels {
|
|
82
|
+
availableModels: ModelInfo[];
|
|
83
|
+
currentModelId: string | null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Get reactive model state
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```tsx
|
|
91
|
+
* function ModelPicker() {
|
|
92
|
+
* const { availableModels, currentModelId } = useAmuxModels();
|
|
93
|
+
* const client = useAmux();
|
|
94
|
+
*
|
|
95
|
+
* return (
|
|
96
|
+
* <select
|
|
97
|
+
* value={currentModelId ?? ''}
|
|
98
|
+
* onChange={e => client.setModel(e.target.value)}
|
|
99
|
+
* >
|
|
100
|
+
* {availableModels.map(m => (
|
|
101
|
+
* <option key={m.id} value={m.id}>{m.name}</option>
|
|
102
|
+
* ))}
|
|
103
|
+
* </select>
|
|
104
|
+
* );
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export function useAmuxModels(): AmuxModels {
|
|
109
|
+
const { availableModels, currentModelId } = useAmuxContext();
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
availableModels,
|
|
113
|
+
currentModelId,
|
|
68
114
|
};
|
|
69
115
|
}
|
|
70
116
|
|
|
@@ -121,11 +167,13 @@ export interface AmuxMessages {
|
|
|
121
167
|
* @example
|
|
122
168
|
* ```tsx
|
|
123
169
|
* function MessageList() {
|
|
124
|
-
* const {
|
|
170
|
+
* const { turns, currentTurn } = useAmuxMessages();
|
|
125
171
|
*
|
|
126
172
|
* return (
|
|
127
173
|
* <>
|
|
128
|
-
* {
|
|
174
|
+
* {turns.map(turn => (
|
|
175
|
+
* <Turn key={turn.id} turn={turn} />
|
|
176
|
+
* ))}
|
|
129
177
|
* {currentTurn?.status === 'streaming' && <StreamingIndicator />}
|
|
130
178
|
* </>
|
|
131
179
|
* );
|
|
@@ -206,3 +254,32 @@ export function useAmuxPrompt(): (message: string) => void {
|
|
|
206
254
|
const { client } = useAmuxContext();
|
|
207
255
|
return useCallback((message: string) => client.prompt(message), [client]);
|
|
208
256
|
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Clear the current error
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```tsx
|
|
263
|
+
* function ErrorBanner() {
|
|
264
|
+
* const { error } = useAmuxState();
|
|
265
|
+
* const clearError = useAmuxClearError();
|
|
266
|
+
*
|
|
267
|
+
* if (!error) return null;
|
|
268
|
+
*
|
|
269
|
+
* return (
|
|
270
|
+
* <div className="error">
|
|
271
|
+
* {error}
|
|
272
|
+
* <button onClick={clearError}>Dismiss</button>
|
|
273
|
+
* </div>
|
|
274
|
+
* );
|
|
275
|
+
* }
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
export function useAmuxClearError(): () => void {
|
|
279
|
+
// Note: This requires the context to expose a clearError function
|
|
280
|
+
// For now, errors auto-clear on successful connection
|
|
281
|
+
// This hook is a placeholder for future enhancement
|
|
282
|
+
return useCallback(() => {
|
|
283
|
+
// No-op for now - errors clear on successful ready event
|
|
284
|
+
}, []);
|
|
285
|
+
}
|
package/src/react/index.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @example
|
|
5
5
|
* ```tsx
|
|
6
|
-
* import { AmuxProvider, useAmux, useAmuxState, useAmuxMessages } from '@bytespell/amux-client/react';
|
|
6
|
+
* import { AmuxProvider, useAmux, useAmuxState, useAmuxMessages, useAmuxModels } from '@bytespell/amux-client/react';
|
|
7
7
|
*
|
|
8
8
|
* function App() {
|
|
9
9
|
* return (
|
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
*
|
|
16
16
|
* function Chat() {
|
|
17
17
|
* const client = useAmux();
|
|
18
|
-
* const { isReady, cwd, agent } = useAmuxState();
|
|
19
|
-
* const {
|
|
18
|
+
* const { isReady, cwd, agent, error } = useAmuxState();
|
|
19
|
+
* const { turns, currentTurn } = useAmuxMessages();
|
|
20
|
+
* const { availableModels, currentModelId } = useAmuxModels();
|
|
20
21
|
*
|
|
21
22
|
* // ...
|
|
22
23
|
* }
|
|
@@ -31,7 +32,13 @@ export {
|
|
|
31
32
|
useAmuxState,
|
|
32
33
|
useAmuxStatus,
|
|
33
34
|
useAmuxMessages,
|
|
35
|
+
useAmuxModels,
|
|
34
36
|
useAmuxEvent,
|
|
35
37
|
useAmuxPrompt,
|
|
38
|
+
useAmuxClearError,
|
|
36
39
|
} from './hooks.js';
|
|
37
|
-
export type { AmuxState, AmuxStatus, AmuxMessages } from './hooks.js';
|
|
40
|
+
export type { AmuxState, AmuxStatus, AmuxMessages, AmuxModels } from './hooks.js';
|
|
41
|
+
|
|
42
|
+
// Re-export types that consumers commonly need
|
|
43
|
+
export type { ModelInfo, SessionMetadata } from '@bytespell/amux-types';
|
|
44
|
+
export type { Turn, Message, ContentBlock, ToolCallState, ConnectionStatus } from '../types.js';
|