Skip to content

Commit de77175

Browse files
committed
fix: Naming of Response
1 parent e7af4ec commit de77175

File tree

10 files changed

+29
-25
lines changed

10 files changed

+29
-25
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,5 @@ dist/
123123
node_modules/
124124
.cursorrules
125125
.vscode/
126-
coverage/
126+
coverage/
127+
.env*

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ For detailed information about the available methods and their parameters, pleas
7272

7373
## Contributing
7474

75-
If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on the [GitHub repository](https://github.com/ai21-labs/api-client).
75+
If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on the [GitHub repository](https://github.com/AI21Labs/ai21-typescript).
7676

7777
## License
7878

src/APIClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
APIResponseProps,
88
HTTPMethod,
99
Headers,
10-
UnifiedResponse,
10+
CrossPlatformResponse,
1111
} from './types';
1212
import { AI21EnvConfig } from './EnvConfig';
1313
import { createFetchInstance } from './runtime';
@@ -108,7 +108,7 @@ export abstract class APIClient {
108108
throw new AI21Error(`Request failed with status ${response.status}. ${await response.text()}`);
109109
}
110110

111-
return { response: response as UnifiedResponse, options };
111+
return { response: response as CrossPlatformResponse, options };
112112
}
113113

114114
protected isRunningInBrowser(): boolean {

src/Streaming/SSEDecoder.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { SSE_DATA_PREFIX } from './Consts';
22
import { StreamingDecodeError } from '../errors';
3-
import { UnifiedResponse } from 'types';
3+
import { CrossPlatformResponse } from 'types';
44

55
export interface SSEDecoder {
66
decode(line: string): string | null;
7-
iterLines(response: UnifiedResponse): AsyncIterableIterator<string>;
7+
iterLines(response: CrossPlatformResponse): AsyncIterableIterator<string>;
88
}
99

1010
abstract class BaseSSEDecoder implements SSEDecoder {
@@ -18,7 +18,7 @@ abstract class BaseSSEDecoder implements SSEDecoder {
1818
throw new StreamingDecodeError(`Invalid SSE line: ${line}`);
1919
}
2020

21-
abstract iterLines(response: UnifiedResponse): AsyncIterableIterator<string>;
21+
abstract iterLines(response: CrossPlatformResponse): AsyncIterableIterator<string>;
2222

2323
async *_iterLines(reader: ReadableStreamDefaultReader<Uint8Array>): AsyncIterableIterator<string> {
2424
let buffer = '';
@@ -51,7 +51,7 @@ abstract class BaseSSEDecoder implements SSEDecoder {
5151
}
5252

5353
export class BrowserSSEDecoder extends BaseSSEDecoder {
54-
async *iterLines(response: UnifiedResponse): AsyncIterableIterator<string> {
54+
async *iterLines(response: CrossPlatformResponse): AsyncIterableIterator<string> {
5555
if (!response.body) {
5656
throw new Error('Response body is null');
5757
}
@@ -62,7 +62,7 @@ export class BrowserSSEDecoder extends BaseSSEDecoder {
6262
}
6363

6464
export class NodeSSEDecoder extends BaseSSEDecoder {
65-
async *iterLines(response: UnifiedResponse): AsyncIterableIterator<string> {
65+
async *iterLines(response: CrossPlatformResponse): AsyncIterableIterator<string> {
6666
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6767
const readerStream = (await import('stream/web')).ReadableStream as any;
6868
const reader = readerStream.from(response.body).getReader();

src/Streaming/Stream.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { BrowserSSEDecoder } from './SSEDecoder';
2-
import { SSEDecoder } from './SSEDecoder';
1+
import { SSEDecoder, BrowserSSEDecoder } from './SSEDecoder';
32
import { SSE_DONE_MSG } from './Consts';
43
import { StreamingDecodeError } from '../errors';
5-
import { UnifiedResponse } from '../types';
4+
import { CrossPlatformResponse } from '../types';
65

76
function getStreamMessage<T>(chunk: string): T {
87
try {
@@ -17,7 +16,7 @@ export class Stream<T> implements AsyncIterableIterator<T> {
1716
private iterator: AsyncIterableIterator<T>;
1817

1918
constructor(
20-
private response: UnifiedResponse,
19+
private response: CrossPlatformResponse,
2120
decoder?: SSEDecoder,
2221
) {
2322
this.decoder = decoder || new BrowserSSEDecoder();

src/Streaming/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
export { Stream } from './Stream';
2-
export { BrowserSSEDecoder, NodeSSEDecoder, SSEDecoder } from './SSEDecoder';
2+
export {
3+
BrowserSSEDecoder,
4+
NodeSSEDecoder,
5+
type SSEDecoder,
6+
} from './SSEDecoder';

src/fetch/BaseFetch.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { AI21Error } from '../errors';
22
import { Stream } from '../Streaming';
3-
import { FinalRequestOptions, UnifiedResponse } from '../types';
3+
import { FinalRequestOptions, CrossPlatformResponse } from '../types';
44
import { APIResponseProps } from '../types/API';
55

66
export type APIResponse<T> = {
77
data?: T;
8-
response: UnifiedResponse;
8+
response: CrossPlatformResponse;
99
};
1010
export abstract class Fetch {
11-
abstract call(url: string, options: FinalRequestOptions): Promise<UnifiedResponse>;
11+
abstract call(url: string, options: FinalRequestOptions): Promise<CrossPlatformResponse>;
1212
async handleResponse<T>({ response, options }: APIResponseProps) {
1313
if (options.stream) {
1414
if (!response.body) {
@@ -21,5 +21,5 @@ export abstract class Fetch {
2121
const contentType = response.headers.get('content-type');
2222
return contentType?.includes('application/json') ? await response.json() : null;
2323
}
24-
abstract handleStream<T>(response: UnifiedResponse): Stream<T>;
24+
abstract handleStream<T>(response: CrossPlatformResponse): Stream<T>;
2525
}

src/fetch/BrowserFetch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { FinalRequestOptions, UnifiedResponse } from 'types';
1+
import { FinalRequestOptions, CrossPlatformResponse } from 'types';
22
import { Fetch } from './BaseFetch';
33
import { Stream, BrowserSSEDecoder } from '../Streaming';
44

55
export class BrowserFetch extends Fetch {
6-
call(url: string, options: FinalRequestOptions): Promise<UnifiedResponse> {
6+
call(url: string, options: FinalRequestOptions): Promise<CrossPlatformResponse> {
77
const controller = new AbortController();
88

99
return fetch(url, {
@@ -14,7 +14,7 @@ export class BrowserFetch extends Fetch {
1414
});
1515
}
1616

17-
handleStream<T>(response: UnifiedResponse): Stream<T> {
17+
handleStream<T>(response: CrossPlatformResponse): Stream<T> {
1818
return new Stream<T>(response as Response, new BrowserSSEDecoder());
1919
}
2020
}

src/fetch/NodeFetch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { FinalRequestOptions, UnifiedResponse } from 'types';
1+
import { FinalRequestOptions, CrossPlatformResponse } from 'types';
22
import { Fetch } from './BaseFetch';
33
import { Stream, NodeSSEDecoder } from '../Streaming';
44

55
export class NodeFetch extends Fetch {
6-
async call(url: string, options: FinalRequestOptions): Promise<UnifiedResponse> {
6+
async call(url: string, options: FinalRequestOptions): Promise<CrossPlatformResponse> {
77
const nodeFetchModule = await import('node-fetch');
88
const nodeFetch = nodeFetchModule.default;
99

@@ -14,7 +14,7 @@ export class NodeFetch extends Fetch {
1414
});
1515
}
1616

17-
handleStream<T>(response: UnifiedResponse): Stream<T> {
17+
handleStream<T>(response: CrossPlatformResponse): Stream<T> {
1818
type NodeRespose = import('node-fetch').Response;
1919
return new Stream<T>(response as NodeRespose, new NodeSSEDecoder());
2020
}

src/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export {
3434
type HTTPMethod,
3535
type DefaultQuery,
3636
type Headers,
37-
type CrossPlatformResponse as UnifiedResponse,
37+
type CrossPlatformResponse,
3838
} from './API';
3939

4040
export {

0 commit comments

Comments
 (0)