feat(ai): add AI stream types - #81
Conversation
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.
cb5eb78 to
7199016
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The PR is small and additive, with only minor consistency/alignment nits noted that do not affect correctness.
Pull request overview
Adds foundational AI streaming type definitions to @hawk.so/types so downstream code can model AI-generated responses as an async sequence of discriminated “parts”.
Changes:
- Introduces
AiStreamTextDeltaPart,AiStreamErrorPart,AiStreamPart, andAiStreamtypes undersrc/ai/stream.ts. - Exports the new AI stream types from the root
index.ts(and corresponding build outputs). - Updates TypeScript compilation target to
es2018and bumps package version to0.7.0.
File summaries
| File | Description |
|---|---|
| tsconfig.json | Updates TS target to es2018 to support async-iterable typing during build. |
| src/ai/stream.ts | Adds the new AI stream part and stream type definitions. |
| index.ts | Re-exports AI stream types from the package entrypoint. |
| package.json | Bumps package version to 0.7.0. |
| build/src/ai/stream.js | Generated JS stub for the new module. |
| build/src/ai/stream.d.ts | Generated type declarations for AI stream types. |
| build/index.js | Re-exports the new build module at runtime entrypoint. |
| build/index.d.ts | Re-exports the new type module at types entrypoint. |
Review details
Suppressed comments (1)
src/ai/stream.ts:19
- This object-shaped export is declared as a type alias, but the codebase overwhelmingly uses
export interfacefor object types (e.g. src/auth/tokensPair.ts, src/dbScheme/promoCode.ts). Using an interface here improves consistency and makes future extension/augmentation easier.
export type AiStreamErrorPart = {
- Files reviewed: 5/8 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| export type AiStreamTextDeltaPart = { | ||
| /** | ||
| * Discriminant of a text-carrying part. | ||
| */ | ||
| type: 'text-delta'; | ||
|
|
||
| /** | ||
| * Text generated for this part. | ||
| */ | ||
| delta: string; | ||
| }; |
There was a problem hiding this comment.
These stay type because they're members of a discriminated union that gets exhaustively matched on .type – an interface can be reopened and merged into by any importer, so a variant's shape would no longer be fixed by its declaration, while interface still fits standalone, extendable shapes elsewhere in the package.
AiStreamPartcarries an answer received by model and converted for further rendering.Currently it unites following types:
AiStreamTextDeltaPart(text increments) andAiStreamErrorPart(failure description).AiStreamcarries part sequence asynchronously.Tsconfig target moves from es6 to es2024 because
AsyncIterabletype is delivered only since es2018.