@@ -10,13 +10,12 @@ import {
10
10
SearchParams ,
11
11
SearchResults ,
12
12
SourcedAnswer ,
13
- StructuredOutputSchema ,
14
13
} from './types' ;
15
14
import { refineError } from './utils/refine-error.utils' ;
16
15
import { isZodObject } from './utils/schema.utils' ;
17
16
18
17
export class LinkupClient {
19
- private readonly USER_AGENT = 'Linkup-JS-SDK/2.0.0 ' ;
18
+ private readonly USER_AGENT = 'Linkup-JS-SDK/2.1.1 ' ;
20
19
private readonly client : AxiosInstance ;
21
20
22
21
constructor ( config : ApiConfig ) {
@@ -41,24 +40,16 @@ export class LinkupClient {
41
40
) ;
42
41
}
43
42
44
- async search < T extends 'sourcedAnswer' | 'searchResults' | 'structured' > (
43
+ async search < T extends SearchOutputType > (
45
44
params : SearchParams < T > ,
46
- ) : Promise <
47
- T extends 'sourcedAnswer'
48
- ? SourcedAnswer
49
- : T extends 'searchResults'
50
- ? SearchResults
51
- : T extends 'structured'
52
- ? StructuredOutputSchema
53
- : never
54
- > {
45
+ ) : Promise < LinkupSearchResponse < T > > {
55
46
return this . client
56
47
. post ( '/search' , this . sanitizeParams ( params ) )
57
- . then ( response => this . formatResponse < T > ( response . data , params . outputType ) ) ;
48
+ . then ( response => this . formatResponse ( response . data , params . outputType ) ) ;
58
49
}
59
50
60
- async fetch ( params : FetchParams ) : Promise < LinkupFetchResponse > {
61
- return this . client . post < LinkupFetchResponse > ( '/fetch' , params ) . then ( response => response . data ) ;
51
+ async fetch < T extends FetchParams > ( params : T ) : Promise < LinkupFetchResponse < T > > {
52
+ return this . client . post ( '/fetch' , params ) . then ( response => response . data ) ;
62
53
}
63
54
64
55
private sanitizeParams < T extends SearchOutputType > ( {
@@ -91,9 +82,9 @@ export class LinkupClient {
91
82
} ;
92
83
}
93
84
94
- private formatResponse < T > (
85
+ private formatResponse < T extends SearchOutputType > (
95
86
searchResponse : unknown ,
96
- outputType : SearchOutputType ,
87
+ outputType : T ,
97
88
) : LinkupSearchResponse < T > {
98
89
switch ( outputType ) {
99
90
case 'sourcedAnswer' :
0 commit comments