@townco/ui 0.1.119 → 0.1.121

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.
@@ -2,6 +2,7 @@ import { createLogger } from "@townco/core";
2
2
  import { useCallback, useRef } from "react";
3
3
  import { generateMessageId } from "../schemas/index.js";
4
4
  import { useChatStore } from "../store/chat-store.js";
5
+ import { safeUpdateUrl } from "./use-chat-session.js";
5
6
  const logger = createLogger("use-chat-messages", "debug");
6
7
  /**
7
8
  * Hook for managing chat messages
@@ -85,6 +86,11 @@ export function useChatMessages(client, startSession) {
85
86
  : {}),
86
87
  };
87
88
  addMessage(userMessage);
89
+ // Update URL with session ID on first message (if not already in URL)
90
+ if (typeof window !== "undefined" &&
91
+ !new URL(window.location.href).searchParams.has("session")) {
92
+ safeUpdateUrl(activeSessionId, false);
93
+ }
88
94
  // Create placeholder for assistant message BEFORE sending
89
95
  const assistantMessage = {
90
96
  id: assistantMessageId,
@@ -1,4 +1,10 @@
1
1
  import type { AcpClient } from "../../sdk/client/index.js";
2
+ /**
3
+ * Safely update URL with session ID.
4
+ * This can fail when the page is loaded with HTTP Basic Auth credentials in the URL,
5
+ * as the browser won't allow changing the URL to remove/modify credentials.
6
+ */
7
+ export declare function safeUpdateUrl(sessionId: string, useReplace?: boolean): void;
2
8
  /**
3
9
  * Hook for managing chat session lifecycle
4
10
  */
@@ -2,6 +2,33 @@ import { createLogger } from "@townco/core";
2
2
  import { useCallback, useEffect } from "react";
3
3
  import { useChatStore } from "../store/chat-store.js";
4
4
  const logger = createLogger("use-chat-session", "debug");
5
+ /**
6
+ * Safely update URL with session ID.
7
+ * This can fail when the page is loaded with HTTP Basic Auth credentials in the URL,
8
+ * as the browser won't allow changing the URL to remove/modify credentials.
9
+ */
10
+ export function safeUpdateUrl(sessionId, useReplace = false) {
11
+ if (typeof window === "undefined")
12
+ return;
13
+ try {
14
+ const url = new URL(window.location.href);
15
+ url.searchParams.set("session", sessionId);
16
+ if (useReplace) {
17
+ window.history.replaceState({}, "", url.toString());
18
+ }
19
+ else {
20
+ window.history.pushState({}, "", url.toString());
21
+ }
22
+ }
23
+ catch (error) {
24
+ // URL update can fail with HTTP Basic Auth credentials in the URL
25
+ // This is not critical - the session still works, just won't be in the URL
26
+ logger.warn("Failed to update URL with session ID", {
27
+ sessionId,
28
+ error: error instanceof Error ? error.message : String(error),
29
+ });
30
+ }
31
+ }
5
32
  /**
6
33
  * Hook for managing chat session lifecycle
7
34
  */
@@ -137,12 +164,7 @@ export function useChatSession(client, initialSessionId) {
137
164
  const currentSession = client.getCurrentSession();
138
165
  if (currentSession?.id) {
139
166
  setSessionId(currentSession.id);
140
- // Update URL with session ID
141
- if (typeof window !== "undefined") {
142
- const url = new URL(window.location.href);
143
- url.searchParams.set("session", currentSession.id);
144
- window.history.replaceState({}, "", url.toString());
145
- }
167
+ // Don't update URL here - wait until first message is sent
146
168
  }
147
169
  setConnectionStatus("connected");
148
170
  }
@@ -190,12 +212,7 @@ export function useChatSession(client, initialSessionId) {
190
212
  setSessionId(newId);
191
213
  clearMessages();
192
214
  resetTokens();
193
- // Update URL with new session ID
194
- if (typeof window !== "undefined") {
195
- const url = new URL(window.location.href);
196
- url.searchParams.set("session", newId);
197
- window.history.replaceState({}, "", url.toString());
198
- }
215
+ safeUpdateUrl(newId, true);
199
216
  logger.info("Created new session after failed load", {
200
217
  sessionId: newId,
201
218
  });
@@ -236,12 +253,7 @@ export function useChatSession(client, initialSessionId) {
236
253
  clearMessages();
237
254
  resetTokens();
238
255
  }
239
- // Update URL with new session ID
240
- if (typeof window !== "undefined") {
241
- const url = new URL(window.location.href);
242
- url.searchParams.set("session", id);
243
- window.history.pushState({}, "", url.toString());
244
- }
256
+ safeUpdateUrl(id, false);
245
257
  return id;
246
258
  }
247
259
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@townco/ui",
3
- "version": "0.1.119",
3
+ "version": "0.1.121",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -49,7 +49,7 @@
49
49
  "@radix-ui/react-slot": "^1.2.4",
50
50
  "@radix-ui/react-tabs": "^1.1.13",
51
51
  "@radix-ui/react-tooltip": "^1.2.8",
52
- "@townco/core": "0.0.97",
52
+ "@townco/core": "0.0.99",
53
53
  "@types/mdast": "^4.0.4",
54
54
  "@uiw/react-json-view": "^2.0.0-alpha.39",
55
55
  "class-variance-authority": "^0.7.1",
@@ -67,7 +67,7 @@
67
67
  "zustand": "^5.0.8"
68
68
  },
69
69
  "devDependencies": {
70
- "@townco/tsconfig": "0.1.116",
70
+ "@townco/tsconfig": "0.1.118",
71
71
  "@types/node": "^24.10.0",
72
72
  "@types/react": "^19.2.2",
73
73
  "@types/unist": "^3.0.3",