Skip to content

Commit 7199016

Browse files
committed
feat(ai): add AI stream types
AiStreamPart carries an answer received by model and converted for further rendering. Currently it unites following types: AiStreamTextDeltaPart (text increments) and AiStreamErrorPart (failure description). AiStream carries part sequence asynchronously. Tsconfig target moves from es6 to es2018 because AsyncIterable type is delivered only since es2018.
1 parent c1907bd commit 7199016

8 files changed

Lines changed: 81 additions & 2 deletions

File tree

build/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './src/ai/stream';
12
export * from './src/auth/tokensPair';
23
export * from './src/base/businessOperation/businessOperation';
34
export * from './src/billing/planProlongrationPayload';

build/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
1414
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1515
};
1616
Object.defineProperty(exports, "__esModule", { value: true });
17+
__exportStar(require("./src/ai/stream"), exports);
1718
__exportStar(require("./src/auth/tokensPair"), exports);
1819
__exportStar(require("./src/base/businessOperation/businessOperation"), exports);
1920
__exportStar(require("./src/billing/planProlongrationPayload"), exports);

build/src/ai/stream.d.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Stream part that carries generated text.
3+
*/
4+
export type AiStreamTextDeltaPart = {
5+
/**
6+
* Discriminant of a text-carrying part.
7+
*/
8+
type: 'text-delta';
9+
/**
10+
* Text generated for this part.
11+
*/
12+
delta: string;
13+
};
14+
/**
15+
* Stream part that carries a generation failure.
16+
*/
17+
export type AiStreamErrorPart = {
18+
/**
19+
* Discriminant of a failure-carrying part.
20+
*/
21+
type: 'error';
22+
/**
23+
* Description of the failure.
24+
*/
25+
errorText: string;
26+
};
27+
/**
28+
* Discriminated union of parts an AI stream consists of.
29+
*/
30+
export type AiStreamPart = AiStreamTextDeltaPart | AiStreamErrorPart;
31+
/**
32+
* Asynchronous sequence of parts forming an AI-generated answer.
33+
*/
34+
export type AiStream = AsyncIterable<AiStreamPart>;

build/src/ai/stream.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });

index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export * from './src/ai/stream';
2+
13
export * from './src/auth/tokensPair';
24

35
export * from './src/base/businessOperation/businessOperation';

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hawk.so/types",
3-
"version": "0.6.5",
3+
"version": "0.7.0",
44
"description": "TypeScript definitions for Hawk",
55
"types": "build/index.d.ts",
66
"main": "build/index.js",

src/ai/stream.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Stream part that carries generated text.
3+
*/
4+
export type AiStreamTextDeltaPart = {
5+
/**
6+
* Discriminant of a text-carrying part.
7+
*/
8+
type: 'text-delta';
9+
10+
/**
11+
* Text generated for this part.
12+
*/
13+
delta: string;
14+
};
15+
16+
/**
17+
* Stream part that carries a generation failure.
18+
*/
19+
export type AiStreamErrorPart = {
20+
/**
21+
* Discriminant of a failure-carrying part.
22+
*/
23+
type: 'error';
24+
25+
/**
26+
* Description of the failure.
27+
*/
28+
errorText: string;
29+
};
30+
31+
/**
32+
* Discriminated union of parts an AI stream consists of.
33+
*/
34+
export type AiStreamPart = AiStreamTextDeltaPart | AiStreamErrorPart;
35+
36+
/**
37+
* Asynchronous sequence of parts forming an AI-generated answer.
38+
*/
39+
export type AiStream = AsyncIterable<AiStreamPart>;

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
/* Basic Options */
44
// "incremental": true, /* Enable incremental compilation */
5-
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
5+
"target": "es2018", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', 'ES2022', 'ES2023', 'ES2024', or 'ESNEXT'. */
66
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
77
// "lib": [], /* Specify library files to be included in the compilation. */
88
// "allowJs": true, /* Allow javascript files to be compiled. */

0 commit comments

Comments
 (0)