@radnine/storybook-addon-claude 0.2.2 → 0.2.4

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.
@@ -7,11 +7,32 @@ exports.useClaudeSession = useClaudeSession;
7
7
  var _react = require("react");
8
8
  var _WebSocketClient = require("./WebSocketClient");
9
9
  var _constants = require("./constants");
10
+ const SESSION_STORAGE_KEY = `${_constants.ADDON_ID}:sessionId`;
11
+ function loadPersistedSessionId() {
12
+ try {
13
+ return localStorage.getItem(SESSION_STORAGE_KEY) || null;
14
+ } catch {
15
+ return null;
16
+ }
17
+ }
18
+ function persistSessionId(id) {
19
+ try {
20
+ if (id) {
21
+ localStorage.setItem(SESSION_STORAGE_KEY, id);
22
+ } else {
23
+ localStorage.removeItem(SESSION_STORAGE_KEY);
24
+ }
25
+ } catch {
26
+ // localStorage may be unavailable
27
+ }
28
+ }
29
+
10
30
  /**
11
31
  * React hook that manages a Claude session via the standalone daemon.
12
32
  *
13
33
  * Handles WebSocket connection lifecycle, message accumulation,
14
- * session activation, and command sending.
34
+ * session activation, and command sending. Persists the session ID
35
+ * in localStorage so chat survives page refreshes.
15
36
  */
16
37
  function useClaudeSession(options = {}) {
17
38
  const {
@@ -22,7 +43,7 @@ function useClaudeSession(options = {}) {
22
43
  } = options;
23
44
  const [connectionState, setConnectionState] = (0, _react.useState)(_constants.CONNECTION_STATES.DISCONNECTED);
24
45
  const [messages, setMessages] = (0, _react.useState)([]);
25
- const [sessionId, setSessionId] = (0, _react.useState)(initialSessionId || null);
46
+ const [sessionId, setSessionId] = (0, _react.useState)(initialSessionId || loadPersistedSessionId());
26
47
  const [isProcessing, setIsProcessing] = (0, _react.useState)(false);
27
48
  const [authFailed, setAuthFailed] = (0, _react.useState)(false);
28
49
  const clientRef = (0, _react.useRef)(null);
@@ -43,6 +64,7 @@ function useClaudeSession(options = {}) {
43
64
  setConnectionState(newState);
44
65
  }), client.on('session_activated', msg => {
45
66
  setSessionId(msg.sessionId);
67
+ persistSessionId(msg.sessionId);
46
68
  }), client.on('output', msg => {
47
69
  if (msg.sessionId !== sessionIdRef.current) return;
48
70
  setMessages(prev => [...prev, {
@@ -116,6 +138,7 @@ function useClaudeSession(options = {}) {
116
138
  // Synchronously update the ref so sendMessage sees it immediately
117
139
  sessionIdRef.current = sid;
118
140
  setSessionId(sid);
141
+ persistSessionId(sid);
119
142
  setMessages([]);
120
143
  if (client && client.isConnected) {
121
144
  client.activate(sid, workingDir);
@@ -132,6 +155,7 @@ function useClaudeSession(options = {}) {
132
155
  }
133
156
  sessionIdRef.current = null;
134
157
  setSessionId(null);
158
+ persistSessionId(null);
135
159
  setMessages([]);
136
160
  setIsProcessing(false);
137
161
  }, []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radnine/storybook-addon-claude",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Storybook addon panel for chatting with Claude via the standalone daemon",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {