Skip to content

Commit

Permalink
fix(ai/rsc): Improve typings for StreamableValue (#1225)
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Mar 26, 2024
1 parent 6a1b2c7 commit 8088de8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/eight-points-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ai': patch
---

fix(ai/rsc): improve typings for `StreamableValue`
4 changes: 3 additions & 1 deletion packages/core/rsc/streamable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ export function createStreamableValue<T = any, E = any>(initialValue?: T) {

return {
/**
* The value of the streamable. This can be returned from a Server Action and received by the client.
* The value of the streamable. This can be returned from a Server Action and
* received by the client. To read the streamed values, use the
* `readStreamableValue` API.
*/
get value() {
return createWrapped(true);
Expand Down
19 changes: 19 additions & 0 deletions packages/core/rsc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,29 @@ export type MutableAIState<AIState> = {

export type StreamablePatch = undefined | [0, string]; // Append string.

/**
* StreamableValue is a value that can be streamed over the network via AI Actions.
* To read the streamed values, use the `readStreamableValue` API.
*/
export type StreamableValue<T = any, E = any> = {
/**
* @internal Use `readStreamableValue` to read the values.
*/
type?: typeof STREAMABLE_VALUE_TYPE;
/**
* @internal Use `readStreamableValue` to read the values.
*/
curr?: T;
/**
* @internal Use `readStreamableValue` to read the values.
*/
error?: E;
/**
* @internal Use `readStreamableValue` to read the values.
*/
diff?: StreamablePatch;
/**
* @internal Use `readStreamableValue` to read the values.
*/
next?: Promise<StreamableValue<T, E>>;
};
3 changes: 2 additions & 1 deletion packages/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "./node_modules/@vercel/ai-tsconfig/react-library.json",
"compilerOptions": {
"target": "ES2018"
"target": "ES2018",
"stripInternal": true
},
"include": ["."],
"exclude": ["dist", "build", "node_modules"]
Expand Down

0 comments on commit 8088de8

Please sign in to comment.