@stainless-api/docs-ai-chat 0.1.0-beta.12 → 0.1.0-beta.14

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,21 @@
1
1
  # @stainless-api/docs-ai-chat
2
2
 
3
+ ## 0.1.0-beta.14
4
+
5
+ ### Patch Changes
6
+
7
+ - @stainless-api/docs@0.1.0-beta.71
8
+
9
+ ## 0.1.0-beta.13
10
+
11
+ ### Patch Changes
12
+
13
+ - fc06954: migrate steelie to new session_id api
14
+ - Updated dependencies [750c348]
15
+ - @stainless-api/ui-primitives@0.1.0-beta.41
16
+ - @stainless-api/docs-ui@0.1.0-beta.55
17
+ - @stainless-api/docs@0.1.0-beta.70
18
+
3
19
  ## 0.1.0-beta.12
4
20
 
5
21
  ### Patch 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.12",
3
+ "version": "0.1.0-beta.14",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -8,9 +8,9 @@
8
8
  "peerDependencies": {
9
9
  "react": ">=19.0.0",
10
10
  "react-dom": ">=19.0.0",
11
- "@stainless-api/docs": "0.1.0-beta.69",
12
- "@stainless-api/docs-ui": "0.1.0-beta.54",
13
- "@stainless-api/ui-primitives": "0.1.0-beta.40"
11
+ "@stainless-api/docs": "0.1.0-beta.71",
12
+ "@stainless-api/docs-ui": "0.1.0-beta.55",
13
+ "@stainless-api/ui-primitives": "0.1.0-beta.41"
14
14
  },
15
15
  "dependencies": {
16
16
  "@streamparser/json-whatwg": "^0.0.22",
package/src/api/index.ts CHANGED
@@ -41,13 +41,13 @@ export async function* getChatResponse(
41
41
  query,
42
42
  project,
43
43
  language,
44
- priorMessages,
44
+ sessionId,
45
45
  siteTitle,
46
46
  }: {
47
47
  query: string;
48
48
  project: string;
49
49
  language: DocsLanguage;
50
- priorMessages: NonNullable<RequestBody['additionalContext']>['prior_messages'];
50
+ sessionId: string | undefined;
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,
64
65
  additionalContext: {
65
- prior_messages: priorMessages,
66
66
  intent: getPageContext({ siteTitle }),
67
67
  },
68
68
  browser_id: getClientId(),
@@ -14,14 +14,9 @@ export const requestBody = z.object({
14
14
  maxTokens: z.number().optional(),
15
15
  })
16
16
  .optional(),
17
+ session_id: z.string().optional(),
17
18
  additionalContext: z
18
19
  .object({
19
- prior_messages: z.array(
20
- z.object({
21
- role: z.enum(['user', 'assistant']),
22
- content: z.string(),
23
- }),
24
- ),
25
20
  code: z.string().optional(),
26
21
  intent: z.string().optional(),
27
22
  lsp: z.string().optional(),
@@ -51,6 +46,10 @@ export const responseChunk = z.discriminatedUnion('type', [
51
46
  type: z.literal('done'),
52
47
  span_id: z.string(),
53
48
  }),
49
+ z.object({
50
+ type: z.literal('start_session'),
51
+ session_id: z.string(),
52
+ }),
54
53
  ]);
55
54
  export type ResponseChunk = z.infer<typeof responseChunk>;
56
55
 
package/src/hook.ts CHANGED
@@ -144,6 +144,7 @@ export function useChat({
144
144
  return () => ac.abort('Component unmounted');
145
145
  }, []);
146
146
 
147
+ const sessionId = useRef<string | undefined>(undefined);
147
148
  const [chatMessages, dispatch] = useReducer(chatReducer, []);
148
149
 
149
150
  /** Send a message and stream back the response in chat */
@@ -160,15 +161,18 @@ export function useChat({
160
161
  query: question,
161
162
  project: projectId,
162
163
  language,
163
- priorMessages: chatMessages.filter(
164
- (msg) => msg.role === 'user' || (msg.role === 'assistant' && msg.messageType === 'text'),
165
- ),
164
+ sessionId: sessionId.current,
166
165
  siteTitle,
167
166
  },
168
167
  abortController.current.signal,
169
168
  )) {
170
169
  if (abortController.current.signal.aborted) break;
171
170
 
171
+ // store session id at start of session
172
+ if (chunk.type === 'start_session') {
173
+ sessionId.current = chunk.session_id;
174
+ }
175
+
172
176
  // mark complete when text messages finish streaming
173
177
  if (lastChunkType === 'text' && chunk.type !== 'text') {
174
178
  dispatch({ type: 'completeMessage', id: currentResponseId });
@@ -214,7 +218,7 @@ export function useChat({
214
218
  lastChunkType = chunk.type;
215
219
  }
216
220
  },
217
- [language, projectId, siteTitle, chatMessages],
221
+ [language, projectId, siteTitle],
218
222
  );
219
223
 
220
224
  // TODO: error handling