Skip to content

Commit f383130

Browse files
chore: Fixes the search functions
1 parent f4836dd commit f383130

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

src/clients/search-client.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,18 @@ type SearchConversationArgs = {
2929
}
3030

3131
type SearchResponse = {
32-
results: SearchResult[]
33-
cursor?: string
32+
items: SearchResult[]
33+
nextCursorMark?: string
3434
hasMore: boolean
35+
isPlanRestricted: boolean
36+
}
37+
38+
type SearchThreadResponse = {
39+
commentIds: number[]
40+
}
41+
42+
type SearchConversationResponse = {
43+
messageIds: number[]
3544
}
3645

3746
/**
@@ -94,7 +103,7 @@ export class SearchClient {
94103

95104
return {
96105
...response.data,
97-
results: response.data.results.map((result) => SearchResultSchema.parse(result)),
106+
items: response.data.items.map((result) => SearchResultSchema.parse(result)),
98107
}
99108
}
100109

@@ -106,7 +115,7 @@ export class SearchClient {
106115
* @param args.threadId - The thread ID to search in.
107116
* @param args.limit - Optional limit on number of results returned.
108117
* @param args.cursor - Optional cursor for pagination.
109-
* @returns Search results with pagination.
118+
* @returns Comment IDs that match the search query.
110119
*
111120
* @example
112121
* ```typescript
@@ -116,7 +125,7 @@ export class SearchClient {
116125
* })
117126
* ```
118127
*/
119-
async searchComments(args: SearchThreadArgs): Promise<SearchResponse> {
128+
async searchThread(args: SearchThreadArgs): Promise<SearchThreadResponse> {
120129
const params: Record<string, unknown> = {
121130
query: args.query,
122131
thread_id: args.threadId,
@@ -125,18 +134,15 @@ export class SearchClient {
125134
if (args.limit) params.limit = args.limit
126135
if (args.cursor) params.cursor = args.cursor
127136

128-
const response = await request<SearchResponse>(
137+
const response = await request<SearchThreadResponse>(
129138
'GET',
130139
this.getBaseUri(),
131-
`${ENDPOINT_SEARCH}/comments`,
140+
`${ENDPOINT_SEARCH}/thread`,
132141
this.apiToken,
133142
params,
134143
)
135144

136-
return {
137-
...response.data,
138-
results: response.data.results.map((result) => SearchResultSchema.parse(result)),
139-
}
145+
return response.data
140146
}
141147

142148
/**
@@ -147,7 +153,7 @@ export class SearchClient {
147153
* @param args.conversationId - The conversation ID to search in.
148154
* @param args.limit - Optional limit on number of results returned.
149155
* @param args.cursor - Optional cursor for pagination.
150-
* @returns Search results with pagination.
156+
* @returns Message IDs that match the search query.
151157
*
152158
* @example
153159
* ```typescript
@@ -157,7 +163,7 @@ export class SearchClient {
157163
* })
158164
* ```
159165
*/
160-
async searchMessages(args: SearchConversationArgs): Promise<SearchResponse> {
166+
async searchConversation(args: SearchConversationArgs): Promise<SearchConversationResponse> {
161167
const params: Record<string, unknown> = {
162168
query: args.query,
163169
conversation_id: args.conversationId,
@@ -166,17 +172,14 @@ export class SearchClient {
166172
if (args.limit) params.limit = args.limit
167173
if (args.cursor) params.cursor = args.cursor
168174

169-
const response = await request<SearchResponse>(
175+
const response = await request<SearchConversationResponse>(
170176
'GET',
171177
this.getBaseUri(),
172-
`${ENDPOINT_SEARCH}/messages`,
178+
`${ENDPOINT_SEARCH}/conversation`,
173179
this.apiToken,
174180
params,
175181
)
176182

177-
return {
178-
...response.data,
179-
results: response.data.results.map((result) => SearchResultSchema.parse(result)),
180-
}
183+
return response.data
181184
}
182185
}

src/types/entities.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,15 +383,19 @@ export type UnreadConversation = z.infer<typeof UnreadConversationSchema>
383383

384384
// SearchResult entity from API
385385
export const SearchResultSchema = z.object({
386-
id: z.number(),
386+
id: z.string(),
387387
type: z.enum(['thread', 'comment', 'message']),
388-
content: z.string(),
389-
creatorId: z.number(),
390-
created: z.date(),
388+
snippet: z.string(),
389+
snippetCreatorId: z.number(),
390+
snippetLastUpdated: z.date(),
391391
threadId: z.number().nullable().optional(),
392392
conversationId: z.number().nullable().optional(),
393+
commentId: z.number().nullable().optional(),
393394
channelId: z.number().nullable().optional(),
394-
workspaceId: z.number(),
395+
channelName: z.string().nullable().optional(),
396+
channelColor: z.number().nullable().optional(),
397+
title: z.string().nullable().optional(),
398+
closed: z.boolean().nullable().optional(),
395399
})
396400

397401
export type SearchResult = z.infer<typeof SearchResultSchema>

0 commit comments

Comments
 (0)