File tree Expand file tree Collapse file tree 6 files changed +20
-12
lines changed Expand file tree Collapse file tree 6 files changed +20
-12
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import {
10
10
UnifiedResponse ,
11
11
} from './types' ;
12
12
import { AI21EnvConfig } from './EnvConfig' ;
13
- import { createFetchInstance } from 'envFetch ' ;
13
+ import { createFetchInstance } from './runtime ' ;
14
14
import { Fetch } from 'fetch' ;
15
15
16
16
const validatePositiveInteger = ( name : string , n : unknown ) : number => {
Original file line number Diff line number Diff line change 1
1
export { Stream } from './Stream' ;
2
+ export { BrowserSSEDecoder , NodeSSEDecoder , SSEDecoder } from './SSEDecoder' ;
Original file line number Diff line number Diff line change 1
- import { AI21Error } from 'errors' ;
2
- import { Stream } from 'Streaming' ;
3
- import { FinalRequestOptions , UnifiedResponse } from 'types' ;
4
- import { APIResponseProps } from 'types/API' ;
1
+ import { AI21Error } from '../ errors' ;
2
+ import { Stream } from '../ Streaming' ;
3
+ import { FinalRequestOptions , UnifiedResponse } from '../ types' ;
4
+ import { APIResponseProps } from '../ types/API' ;
5
5
6
6
export type APIResponse < T > = {
7
7
data ?: T ;
Original file line number Diff line number Diff line change 1
1
import { FinalRequestOptions , UnifiedResponse } from 'types' ;
2
2
import { Fetch } from './BaseFetch' ;
3
- import { Stream } from 'Streaming' ;
4
- import { BrowserSSEDecoder } from 'Streaming/SSEDecoder' ;
3
+ import { Stream , BrowserSSEDecoder } from '../Streaming' ;
5
4
6
5
export class BrowserFetch extends Fetch {
7
6
call ( url : string , options : FinalRequestOptions ) : Promise < UnifiedResponse > {
Original file line number Diff line number Diff line change 1
1
import { FinalRequestOptions , UnifiedResponse } from 'types' ;
2
2
import { Fetch } from './BaseFetch' ;
3
- import { NodeSSEDecoder } from 'Streaming/SSEDecoder' ;
4
- import { Stream } from 'Streaming' ;
3
+ import { Stream , NodeSSEDecoder } from '../Streaming' ;
5
4
6
5
export class NodeFetch extends Fetch {
7
6
async call ( url : string , options : FinalRequestOptions ) : Promise < UnifiedResponse > {
Original file line number Diff line number Diff line change 1
- import { BrowserFetch , Fetch , NodeFetch } from 'fetch' ;
1
+ import { BrowserFetch , Fetch , NodeFetch } from './fetch' ;
2
+
2
3
3
4
export const isBrowser = typeof window !== 'undefined' && typeof window . document !== 'undefined' ;
5
+
6
+ /**
7
+ * A Web Worker is a background thread that runs JavaScript code separate from the main thread.
8
+ * Web Workers enable concurrent processing by:
9
+ * - Running CPU-intensive tasks without blocking the UI
10
+ * - Performing background operations like data fetching and processing
11
+ * - Operating independently from the main window context
12
+ */
4
13
export const isWebWorker =
5
14
typeof self === 'object' &&
6
15
typeof self ?. importScripts === 'function' &&
@@ -14,7 +23,7 @@ export const isNode =
14
23
export function createFetchInstance ( ) : Fetch {
15
24
if ( isBrowser || isWebWorker ) {
16
25
return new BrowserFetch ( ) ;
17
- } else {
18
- return new NodeFetch ( ) ;
19
26
}
27
+
28
+ return new NodeFetch ( ) ;
20
29
}
You can’t perform that action at this time.
0 commit comments