@@ -39,15 +39,16 @@ function slackResult(value: unknown) {
3939/** Results one Real-time Search call returns at most. */
4040const SLACK_PAGE_SIZE = 20
4141/**
42- * Real-time Search pages a search aimed at Slack reads to fill a limit above one page . Each page
43- * counts against the member's RTS rate limit of about 10 calls a minute.
42+ * Real-time Search pages a search aimed at Slack reads to fill its limit. Each page counts
43+ * against the member's RTS rate limit of about 10 calls a minute.
4444 */
4545const MAX_SLACK_SEARCH_PAGES = 3
4646
4747/**
4848 * A search across every source reads one page, so Slack shares the result list with the other
4949 * sources. A Slack-scoped or native Slack search follows the cursor until it fills its limit.
50- * A later page that fails keeps the earlier pages and returns the cursor it could not read.
50+ * A later page that fails keeps the earlier pages and returns the cursor it could not read,
51+ * unless the caller cancelled the search.
5152 */
5253export async function searchSlack (
5354 client : NativeClient ,
@@ -58,10 +59,7 @@ export async function searchSlack(
5859 'reconnect' ,
5960 'Reconnect your Slack account to grant permission to search.'
6061 )
61- const pages =
62- input . native || input . filters ?. source === 'slack'
63- ? Math . min ( Math . ceil ( input . limit / SLACK_PAGE_SIZE ) , MAX_SLACK_SEARCH_PAGES )
64- : 1
62+ const pages = input . native || input . filters ?. source === 'slack' ? MAX_SLACK_SEARCH_PAGES : 1
6563 const first = await searchSlackPage ( client , input , input . native ?. cursor , input . limit )
6664 const documents = [ ...first . documents ]
6765 let nextCursor = first . nextCursor
@@ -71,12 +69,18 @@ export async function searchSlack(
7169 documents . push ( ...more . documents )
7270 nextCursor = more . nextCursor
7371 } catch ( error ) {
74- if ( ! ( error instanceof NativeSearchError ) ) throw error
72+ if ( input . signal ?. aborted ) throw error
7573 return {
7674 documents,
7775 nextCursor,
7876 partial : true ,
79- message : joinMessages ( [ first . message , error . message , 'Continue with nextCursor for more.' ] ) ,
77+ message : joinMessages ( [
78+ first . message ,
79+ error instanceof NativeSearchError
80+ ? error . message
81+ : 'Slack could not return more results.' ,
82+ 'Continue with nextCursor for more.' ,
83+ ] ) ,
8084 }
8185 }
8286 }
0 commit comments