Skip to content

Commit

Permalink
packages/react: create separate server component bundle for Tokens (#240
Browse files Browse the repository at this point in the history
)
  • Loading branch information
MaxLeiter committed Jun 29, 2023
1 parent 4198b95 commit b7b93e5
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-stingrays-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ai': major
---

Add <Tokens> RSC to ai/react
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"vue/dist/**/*"
],
"scripts": {
"build": "tsup",
"build": "tsup && cat react/dist/index.server.d.ts >> react/dist/index.d.ts",
"clean": "rm -rf dist && rm -rf react/dist && rm -rf svelte/dist && rm -rf vue/dist",
"dev": "tsup --watch",
"lint": "eslint \"./**/*.ts*\"",
Expand All @@ -31,6 +31,7 @@
},
"./react": {
"types": "./react/dist/index.d.ts",
"react-server": "./react/dist/index.server.mjs",
"import": "./react/dist/index.mjs",
"module": "./react/dist/index.mjs",
"require": "./react/dist/index.js"
Expand Down
1 change: 1 addition & 0 deletions packages/core/react/index.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './tokens'
1 change: 0 additions & 1 deletion packages/core/react/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './use-chat'
export * from './use-completion'
export * from './tokens'
1 change: 1 addition & 0 deletions packages/core/react/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './tokens'
3 changes: 2 additions & 1 deletion packages/core/react/tokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Props = {

/**
* A React Server Component that recursively renders a stream of tokens.
* Can only be used inside of server components.
*/
export async function Tokens(props: Props) {
const { stream } = props
Expand All @@ -24,7 +25,7 @@ export async function Tokens(props: Props) {

type InternalProps = {
reader: ReadableStreamDefaultReader
} & Omit<Props, 'stream'>
}

async function RecursiveTokens({ reader }: InternalProps) {
const { done, value } = await reader.read()
Expand Down
7 changes: 7 additions & 0 deletions packages/core/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export default defineConfig([
external: ['react', 'svelte', 'vue'],
dts: true
},
{
entry: ['react/index.server.ts'],
outDir: 'react/dist',
format: ['cjs', 'esm'],
external: ['react', 'svelte', 'vue'],
dts: true
},
// Svelte APIs
{
entry: ['svelte/index.ts'],
Expand Down

0 comments on commit b7b93e5

Please sign in to comment.