@radnine/storybook-addon-claude 0.1.1 → 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/dist/Panel.js +4 -3
- package/dist/WebSocketClient.js +4 -8
- package/dist/useClaudeSession.js +14 -3
- package/package.json +1 -1
package/dist/Panel.js
CHANGED
|
@@ -37,12 +37,13 @@ function ClaudePanel({
|
|
|
37
37
|
// Story context
|
|
38
38
|
const storyContext = (0, _useStoryContext.useStoryContext)();
|
|
39
39
|
|
|
40
|
-
// Claude session
|
|
40
|
+
// Claude session — connects automatically (no token needed on localhost)
|
|
41
41
|
const {
|
|
42
42
|
connectionState,
|
|
43
43
|
messages,
|
|
44
44
|
sessionId,
|
|
45
45
|
isProcessing,
|
|
46
|
+
authFailed,
|
|
46
47
|
sendMessage,
|
|
47
48
|
startSession,
|
|
48
49
|
disconnect,
|
|
@@ -84,8 +85,8 @@ function ClaudePanel({
|
|
|
84
85
|
// Don't render if panel is not active
|
|
85
86
|
if (!active) return null;
|
|
86
87
|
|
|
87
|
-
//
|
|
88
|
-
if (!token) {
|
|
88
|
+
// Show token input only if auth was explicitly rejected (non-localhost connection)
|
|
89
|
+
if (authFailed && !token) {
|
|
89
90
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
90
91
|
style: styles.panel,
|
|
91
92
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_TokenInput.TokenInput, {
|
package/dist/WebSocketClient.js
CHANGED
|
@@ -53,20 +53,16 @@ class WebSocketClient {
|
|
|
53
53
|
if (this._ws) {
|
|
54
54
|
this._ws.close();
|
|
55
55
|
}
|
|
56
|
-
if (!this._token) {
|
|
57
|
-
this._emit('error', {
|
|
58
|
-
code: 'NO_TOKEN',
|
|
59
|
-
message: 'Auth token is required'
|
|
60
|
-
});
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
56
|
|
|
64
57
|
// Preserve RECONNECTING state so failed reconnect attempts still trigger
|
|
65
58
|
// _scheduleReconnect in the onclose handler.
|
|
66
59
|
if (this._state !== _constants.CONNECTION_STATES.RECONNECTING) {
|
|
67
60
|
this._setState(_constants.CONNECTION_STATES.CONNECTING);
|
|
68
61
|
}
|
|
69
|
-
|
|
62
|
+
|
|
63
|
+
// Connect without token for localhost (daemon allows it), or with token if provided
|
|
64
|
+
const params = this._token ? `?token=${encodeURIComponent(this._token)}` : '';
|
|
65
|
+
const url = `ws://${this._host}:${this._port}/${params}`;
|
|
70
66
|
try {
|
|
71
67
|
this._ws = new WebSocket(url);
|
|
72
68
|
} catch (err) {
|
package/dist/useClaudeSession.js
CHANGED
|
@@ -24,6 +24,7 @@ function useClaudeSession(options = {}) {
|
|
|
24
24
|
const [messages, setMessages] = (0, _react.useState)([]);
|
|
25
25
|
const [sessionId, setSessionId] = (0, _react.useState)(initialSessionId || null);
|
|
26
26
|
const [isProcessing, setIsProcessing] = (0, _react.useState)(false);
|
|
27
|
+
const [authFailed, setAuthFailed] = (0, _react.useState)(false);
|
|
27
28
|
const clientRef = (0, _react.useRef)(null);
|
|
28
29
|
const sessionIdRef = (0, _react.useRef)(sessionId);
|
|
29
30
|
sessionIdRef.current = sessionId;
|
|
@@ -56,6 +57,11 @@ function useClaudeSession(options = {}) {
|
|
|
56
57
|
}]);
|
|
57
58
|
setIsProcessing(false);
|
|
58
59
|
}), client.on('error', msg => {
|
|
60
|
+
// Track auth failures so the UI can show token input
|
|
61
|
+
if (msg.code === 'AUTH_FAILED') {
|
|
62
|
+
setAuthFailed(true);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
59
65
|
setMessages(prev => [...prev, {
|
|
60
66
|
type: 'error',
|
|
61
67
|
...msg,
|
|
@@ -70,11 +76,15 @@ function useClaudeSession(options = {}) {
|
|
|
70
76
|
};
|
|
71
77
|
}, [host, port, token]);
|
|
72
78
|
|
|
73
|
-
//
|
|
79
|
+
// Auto-connect immediately (works without token on localhost)
|
|
80
|
+
// or reconnect when token changes
|
|
74
81
|
(0, _react.useEffect)(() => {
|
|
75
82
|
const client = clientRef.current;
|
|
76
|
-
if (!client
|
|
77
|
-
|
|
83
|
+
if (!client) return;
|
|
84
|
+
if (token) {
|
|
85
|
+
client.setToken(token);
|
|
86
|
+
}
|
|
87
|
+
setAuthFailed(false);
|
|
78
88
|
client.connect();
|
|
79
89
|
return () => client.disconnect();
|
|
80
90
|
}, [token]);
|
|
@@ -130,6 +140,7 @@ function useClaudeSession(options = {}) {
|
|
|
130
140
|
messages,
|
|
131
141
|
sessionId,
|
|
132
142
|
isProcessing,
|
|
143
|
+
authFailed,
|
|
133
144
|
sendMessage,
|
|
134
145
|
startSession,
|
|
135
146
|
clearMessages,
|
package/package.json
CHANGED