@stainless-api/docs-ai-chat 0.1.0-beta.40 → 0.1.0-beta.43

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,6 +1,28 @@
1
1
  # @stainless-api/docs-ai-chat
2
2
 
3
- ## 1.0.0-beta.40
3
+ ## 0.1.0-beta.43
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [21e50d3]
8
+ - @stainless-api/docs-ui@0.1.0-beta.77
9
+
10
+ ## 0.1.0-beta.42
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [95fe66c]
15
+ - Updated dependencies [5701494]
16
+ - @stainless-api/docs-ui@0.1.0-beta.76
17
+ - @stainless-api/ai-chat@0.1.0-beta.6
18
+
19
+ ## 0.1.0-beta.41
20
+
21
+ ### Patch Changes
22
+
23
+ - 6e762e2: fix steelie for multi-turn conversations
24
+
25
+ ## 0.1.0-beta.40
4
26
 
5
27
  ### Patch Changes
6
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stainless-api/docs-ai-chat",
3
- "version": "0.1.0-beta.40",
3
+ "version": "0.1.0-beta.43",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -8,12 +8,12 @@
8
8
  "peerDependencies": {
9
9
  "react": ">=19.0.0",
10
10
  "react-dom": ">=19.0.0",
11
- "@stainless-api/docs-ui": "0.1.0-beta.75"
11
+ "@stainless-api/docs-ui": "0.1.0-beta.77"
12
12
  },
13
13
  "dependencies": {
14
14
  "@streamparser/json-whatwg": "^0.0.22",
15
15
  "zod": "^4.3.5",
16
- "@stainless-api/ai-chat": "0.1.0-beta.5"
16
+ "@stainless-api/ai-chat": "0.1.0-beta.6"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/react": "19.2.10",
package/src/api/index.ts CHANGED
@@ -41,13 +41,13 @@ export async function* getChatResponse(
41
41
  query,
42
42
  project,
43
43
  language,
44
- sessionId,
44
+ priorMessages,
45
45
  siteTitle,
46
46
  }: {
47
47
  query: string;
48
48
  project: string;
49
49
  language: DocsLanguage;
50
- sessionId: string | undefined;
50
+ priorMessages: NonNullable<RequestBody['additionalContext']>['prior_messages'];
51
51
  siteTitle: string | undefined;
52
52
  },
53
53
  abortSignal: AbortSignal,
@@ -61,8 +61,8 @@ export async function* getChatResponse(
61
61
  query,
62
62
  sdk: { project, language },
63
63
  stream: true,
64
- session_id: sessionId,
65
64
  additionalContext: {
65
+ prior_messages: priorMessages,
66
66
  intent: getPageContext({ siteTitle }),
67
67
  },
68
68
  browser_id: getClientId(),
@@ -17,6 +17,12 @@ export const requestBody = z.object({
17
17
  session_id: z.string().optional(),
18
18
  additionalContext: z
19
19
  .object({
20
+ prior_messages: z.array(
21
+ z.object({
22
+ role: z.enum(['user', 'assistant']),
23
+ content: z.string(),
24
+ }),
25
+ ),
20
26
  code: z.string().optional(),
21
27
  intent: z.string().optional(),
22
28
  lsp: z.string().optional(),
package/src/hook.ts CHANGED
@@ -130,7 +130,6 @@ export function useChat({
130
130
  return () => ac.abort('Component unmounted');
131
131
  }, []);
132
132
 
133
- const sessionId = useRef<string | undefined>(undefined);
134
133
  const [chatMessages, dispatch] = useReducer(chatReducer, []);
135
134
 
136
135
  /** Send a message and stream back the response in chat */
@@ -143,23 +142,21 @@ export function useChat({
143
142
  let lastChunkType: ResponseChunk['type'] | undefined = undefined;
144
143
 
145
144
  try {
146
- for await (const chunk of getChatResponse(
145
+ let chunk: ResponseChunk | undefined = undefined;
146
+ for await (chunk of getChatResponse(
147
147
  {
148
148
  query: question,
149
149
  project: projectId,
150
150
  language,
151
- sessionId: sessionId.current,
151
+ priorMessages: chatMessages.filter(
152
+ (msg) => msg.role === 'user' || (msg.role === 'assistant' && msg.messageType === 'text'),
153
+ ),
152
154
  siteTitle,
153
155
  },
154
156
  abortController.current.signal,
155
157
  )) {
156
158
  if (abortController.current.signal.aborted) break;
157
159
 
158
- // store session id at start of session
159
- if (chunk.type === 'start_session') {
160
- sessionId.current = chunk.session_id;
161
- }
162
-
163
160
  // mark complete when text messages finish streaming
164
161
  if (lastChunkType === 'text' && chunk.type !== 'text') {
165
162
  dispatch({ type: 'completeMessage', id: currentResponseId });
@@ -204,6 +201,13 @@ export function useChat({
204
201
 
205
202
  lastChunkType = chunk.type;
206
203
  }
204
+ if (!chunk) {
205
+ dispatch({
206
+ type: 'addError',
207
+ respondingTo: userMessageId,
208
+ errorMessage: 'No response received. Please try again.',
209
+ });
210
+ }
207
211
  } catch {
208
212
  dispatch({
209
213
  type: 'addError',
@@ -212,7 +216,7 @@ export function useChat({
212
216
  });
213
217
  }
214
218
  },
215
- [language, projectId, siteTitle],
219
+ [language, projectId, siteTitle, chatMessages],
216
220
  );
217
221
 
218
222
  return { chatMessages, sendMessage };