Skip to content
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

Example asset and transform for async content streaming #575

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

cehan-Chloe
Copy link
Contributor

@cehan-Chloe cehan-Chloe commented Jan 16, 2025

Change Type (required)

Indicate the type of change your pull request is:

  • patch
  • minor
  • major
  • N/A

Does your PR have any documentation updates?

  • Updated docs
  • No Update needed
  • Unable to update docs

Release Notes

Player streaming enhancement

  1. Changes
  • Added new chat-message asset in ReferenceAssetsPlugin as async streaming example
  • Added generic function in AsyncNodePlugin to generate async asset transform
  1. New functionality
    Instead of adding {async: true} in content, replace it with a special type of asset, eg. chat-message and write a transform function.

@cehan-Chloe
Copy link
Contributor Author

/canary


expect(result.type).toBe(NodeType.Value);
expect(result.children?.[0]?.value.type).toBe("asset");
expect(result.children?.[0]?.value.value.id).toBe("asset");
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: change the id so failure is more clear

@@ -36,7 +43,7 @@ export class Builder {
* @param values - the value or applicability nodes to put in the multinode
Copy link
Contributor

Choose a reason for hiding this comment

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

doc update

@@ -36,7 +43,7 @@ export class Builder {
* @param values - the value or applicability nodes to put in the multinode
*/
static multiNode(
...values: (Node.Value | Node.Applicability)[]
...values: (Node.Value | Node.Applicability | Node.Asset | Node.Async)[]
Copy link
Contributor

Choose a reason for hiding this comment

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

is this builder tested

@@ -116,6 +116,10 @@ export declare namespace Node {
id: string;
/** The value representing the node */
value: Node;
/**
* Should this list be flattened in resolver
Copy link
Contributor

Choose a reason for hiding this comment

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

don't think async always guaranteed to be a list

Copy link
Contributor Author

@cehan-Chloe cehan-Chloe Feb 19, 2025

Choose a reason for hiding this comment

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

changed it to Should the new content streamed in be flattened during resolving?


# ChatMessage Asset

The `ChatMessage` asset is used as an example of async node.
Copy link
Contributor

Choose a reason for hiding this comment

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

semantics, the ChatMessage itself isn't an async node, but it's an example of an asset that supports further async loading of future assets

@@ -17,7 +17,7 @@ export function runTransform<
TransformedAssetType extends Asset = BaseAssetType,
>(
type: string,
transform: TransformFunction<BaseAssetType, TransformedAssetType>,
transform: TransformFunctions,
Copy link
Contributor

Choose a reason for hiding this comment

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

i might be missing something, what's this change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

before, this util was only testing TransformFunction which is afterResolve. but in chat-message we test beforeResolve as well and it's the same way to register it in AssetTransformPlugin so i changed to TransformFunctions interface for both before and after resolve

let updateNumber = 0;

const player = new Player({
plugins: [plugin, new ReferenceAssetsPlugin()],
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: just group this together with the async one, pass in an array

let view = (player.getState() as InProgressState).controllers.view
.currentView?.lastUpdate;

expect(view).toBeDefined();
Copy link
Contributor

Choose a reason for hiding this comment

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

hmmm where's the first textview

Copy link
Contributor Author

Choose a reason for hiding this comment

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

here checked the length of view values is 1 which is the first textview. line 647 tested the type. i can move it here to make it more clear.

let view = (player.getState() as InProgressState).controllers.view
.currentView?.lastUpdate;

expect(view).toBeDefined();
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, how are we suddenly jumping from nothing to 2 texts

expect(view?.values[0].asset.value).toBe("Hello World!");
expect(view?.values[1].asset.type).toBe("text");
expect(view?.values[1].asset.value).toBe("async content");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

are you able to add a test that builds on top of this, that resolves the second chat-message async content as well

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.

2 participants