8000 TamboStreamProvider (Proof of Concept) by armfuldev · Pull Request #654 · tambo-ai/tambo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

TamboStreamProvider (Proof of Concept) #654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

armfuldev
Copy link
@armfuldev armfuldev 10000 commented Jul 10, 2025

Here's the TamboStreamProvider proof of concept you asked for. It provides per-key state management with compound components (Loading, Empty, Content) that work with both streaming and static data, offering a more declarative alternative to manual prop status checking.

This was ported from another provider I wrote for Prisma Pulse, but I haven't been able to do proper testing yet. Would love to chat with someone about testing strategies so we can ensure we cover the edge cases you encounter in real usage.

Example usage:

<TamboStreamProvider data={{ title, content, createdAt }}>
  <div>
    <h3>{title}</h3>
    <p>{content}</p>
    
    <TamboStreamProvider.Loading key="createdAt">
      <p>Loading creation date...</p>
    </TamboStreamProvider.Loading>
    
    <TamboStreamProvider.Content key="createdAt">
      <p>Created: {createdAt}</p>
    </TamboStreamProvider.Content>
    
    <TamboStreamProvider.Empty key="createdAt">
      <p>No creation date available</p>
    </TamboStreamProvider.Empty>
  </div>
</TamboStreamProvider>

This is just a POC to see if this pattern feels good and could be useful. The idea is to replace stuff like propStatus["createdAt"]?.isSuccess && <p>{createdAt}</p> with something more declarative.

Would love to get your thoughts on whether this direction feels right! 🤔

Copy link
vercel bot commented Jul 10, 2025

@armfuldev is attempting to deploy a commit to the tambo ai Team on Vercel.

A member of the Team first needs to authorize it.

@MichaelMilstead
Copy link
Collaborator

Nice, looks like Content will render when the field is done streaming in, can we change the name to Complete or something similar?

Overall looks good!


export interface LoadingProps {
/** The key to identify this loading state */
key?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a very practical level, you can't use key here

  1. I'm pretty sure that the value passed for key will not actually show up in your props, as it is reserved for react's reconciliation algorithm
  2. Your sample code passes multiple children with the same key prop, which is definitely not allowed.

At the very lease this needs a new name, like propKey or something
https://legacy.reactjs.org/docs/lists-and-keys.html#keys-must-only-be-unique-among-siblings

Copy link
Author
@armfuldev armfuldev Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally, this was a very quick proof of concept for the team.

i missed that oversight while making the example.

i'm expecting a lot to change according to Tambo requirements

Copy link
Contributor
@alecf alecf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I do like this approach! I'm a little wary of the generic name TamboStreamContext etc - I feel like this is very specifically for streaming in props and there are other aspects to streaming.

What about TamboStreamPropsProvider or something? I know it is kind of a mouthful...

@armfuldev
Copy link
Author

Nice, looks like Content will render when the field is done streaming in, can we change the name to Complete or something similar?

Overall looks good!

Complete makes sense as well!

Overall I do like this approach! I'm a little wary of the generic name TamboStreamContext etc - I feel like this is very specifically for streaming in props and there are other aspects to streaming.

What about TamboStreamPropsProvider or something? I know it is kind of a mouthful...

i understand your concern, we can tweak this to make more sense. this was mostly to get the idea across to Michael as i showed him a quick example during todays stream.

@michaelmagan
Copy link
Collaborator
michaelmagan commented Jul 10, 2025

@alecf this is good feedback on naming.

I like TamboPropStreamProvider.

My feedback is mainly around naming. I think we should keep naming to closely match the hook.

I'm also wondering if we then provide a flexible When for when you want to show something during multiple state.

Gate/Wrapper Renders when status matches… Typical “OR” combos
Pending isPending
Streaming isStreaming
Success isSuccess and data present
Empty not isPending, isStreaming, isSuccess, isError and data empty
Error isError
When any={[…]} Current state ∈ passed array e.g. ["streaming","success"], ["pending","streaming","success"]

I no longer like this:

import { TamboPropStreamProvider } from "@tambo/react";

export default function Note({ title, content, createdAt }) {
  return (
    <TamboPropStreamProvider data={{ title, content, createdAt }}>
      <h3>{title}</h3>
      <p>{content}</p>

      {/* single-state helper */}
      <TamboPropStreamProvider.Pending   prop="createdAt">
        <p>Thinking…</p>
      </TamboPropStream.Pending>

      <TamboPropStreamProvider.Streaming prop="createdAt">
        <p>⏳ streaming …</p>
      </TamboPropStreamProvider.Streaming>
      
      {/* multi-state gate */}
      <TamboPropStreamProvider.When prop="createdAt" any={["pending","streaming","success"]}>
        Show while pending through success: {createdAt}
      </TamboPropStreamProvider.When>

      <TamboPropStreamProvider.Success   prop="createdAt">
        <p>Only Show after Finished Streaming: {createdAt}</p>
      </TamboPropStreamProvider.Success>

      <TamboPropStreamProvider.Empty     prop="createdAt">
        <p>No creation date.</p>
      </TamboPropStreamProvider.Empty>

      <TamboPropStreamProvider.Error     prop="createdAt">
        <p>⚠️ failed to generate date.</p>
      </TamboPropStreamProvider.Error>


    </TamboPropStreamProvider>
  );
}

On the flip side When is a little word but it gives you very clear granular control.

@michaelmagan
Copy link
Collaborator
michaelmagan commented Jul 10, 2025

i actually kind of like this:

// Note.tsx – gates one prop, streams the rest inline
import {
  TamboPropStreamProvider as Stream,
  StreamStatus,
} from "@tambo/react";

export default function Note({ title, content, createdAt }: NoteProps) {

  return (
    <Stream data={{ title, content, createdAt }}>
      <h3>{title}</h3>
      <p>{content}</p>

      {/* gate createdAt with OR logic */}
      <Stream.When
        prop="createdAt"
        is={[StreamStatus.Pending, StreamStatus.Streaming]}
      >
        <p>⏳ fetching date…</p>
      </Stream.When>

      <Stream.When prop="createdAt" is={StreamStatus.Success}>
        <p>Created: {createdAt}</p>
      </Stream.When>

      <Stream.When prop="createdAt" is={StreamStatus.Empty}>
        <p>No creation date.</p>
      </Stream.When>

      <Stream.When prop="createdAt" is={StreamStatus.Error}>
        <p>⚠️ failed to generate date.</p>
      </Stream.When>
    </Stream>
  );
}

@michaelmagan
Copy link
Collaborator

Hey we synced and this is all we decided on:

TamboPropStreamProvider

content renamed to complete.

Then we can merge.

Thanks @armfuldev!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0