@stainless-api/docs-ai-chat 0.1.0-beta.46 → 0.1.0-beta.48

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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @stainless-api/docs-ai-chat
2
2
 
3
+ ## 0.1.0-beta.48
4
+
5
+ ### Patch Changes
6
+
7
+ - 8838d9f: remember presentation when window shrinks
8
+ - Updated dependencies [8838d9f]
9
+ - @stainless-api/ai-chat@0.1.0-beta.10
10
+
11
+ ## 0.1.0-beta.47
12
+
13
+ ### Minor Changes
14
+
15
+ - a8ed299: Adds the ability for AI chat to move into a sidebar “panel” position.
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [5b3b798]
20
+ - Updated dependencies [a8ed299]
21
+ - @stainless-api/ai-chat@0.1.0-beta.9
22
+
3
23
  ## 0.1.0-beta.46
4
24
 
5
25
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stainless-api/docs-ai-chat",
3
- "version": "0.1.0-beta.46",
3
+ "version": "0.1.0-beta.48",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -13,7 +13,7 @@
13
13
  "dependencies": {
14
14
  "@streamparser/json-whatwg": "^0.0.22",
15
15
  "zod": "^4.3.6",
16
- "@stainless-api/ai-chat": "0.1.0-beta.8"
16
+ "@stainless-api/ai-chat": "0.1.0-beta.10"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/react": "19.2.14",
package/src/DocsChat.tsx CHANGED
@@ -1,6 +1,7 @@
1
1
  import AiChat from '@stainless-api/ai-chat/src/AiChat.tsx';
2
2
  import type { DocsLanguage } from '@stainless-api/docs-ui/routing';
3
3
  import { setResponseMetadata, submitResponseFeedback } from './api';
4
+ import { useSyncExternalStore } from 'react';
4
5
  import { useChat } from './hook';
5
6
 
6
7
  function onCopyMessage(spanId: string) {
@@ -31,12 +32,23 @@ export default function DocsChat({
31
32
  siteTitle,
32
33
  });
33
34
 
35
+ // panel mode is supported only on larger viewports
36
+ const supportsPanel = useSyncExternalStore(
37
+ (cb) => {
38
+ window.addEventListener('resize', cb);
39
+ return () => window.removeEventListener('resize', cb);
40
+ },
41
+ () => window.innerWidth >= 968,
42
+ () => false,
43
+ );
44
+
34
45
  return (
35
46
  <AiChat
36
47
  chatMessages={chatMessages}
37
48
  sendMessage={sendMessage}
38
49
  rateMessage={rateMessage}
39
50
  onCopyMessage={onCopyMessage}
51
+ supportsPanel={supportsPanel}
40
52
  />
41
53
  );
42
54
  }
package/src/hook.ts CHANGED
@@ -121,12 +121,12 @@ export function useChat({
121
121
  siteTitle: string | undefined;
122
122
  }) {
123
123
  // Used to clean up stray streaming requests on unmount (prevent setState on unmounted component)
124
- const abortController = useRef(new AbortController());
124
+ const abortControllerRef = useRef(new AbortController());
125
125
  useEffect(() => {
126
- abortController.current = abortController.current.signal.aborted
126
+ abortControllerRef.current = abortControllerRef.current.signal.aborted
127
127
  ? new AbortController()
128
- : abortController.current;
129
- const ac = abortController.current;
128
+ : abortControllerRef.current;
129
+ const ac = abortControllerRef.current;
130
130
  return () => ac.abort('Component unmounted');
131
131
  }, []);
132
132
 
@@ -153,9 +153,9 @@ export function useChat({
153
153
  ),
154
154
  siteTitle,
155
155
  },
156
- abortController.current.signal,
156
+ abortControllerRef.current.signal,
157
157
  )) {
158
- if (abortController.current.signal.aborted) break;
158
+ if (abortControllerRef.current.signal.aborted) break;
159
159
 
160
160
  // mark complete when text messages finish streaming
161
161
  if (lastChunkType === 'text' && chunk.type !== 'text') {
@@ -201,7 +201,7 @@ export function useChat({
201
201
 
202
202
  lastChunkType = chunk.type;
203
203
  }
204
- if (!chunk) {
204
+ if (!chunk || lastChunkType === 'start_session') {
205
205
  dispatch({
206
206
  type: 'addError',
207
207
  respondingTo: userMessageId,