Creates a provider for a shared useStream instance at the component level.
Add the returned provider to a component's providers array so that all
child components can access the same stream via injectStream().
provideStream<
T = Record<string, unknown>,
Bag extends BagTemplate = BagTemplate
>(
options:| Name | Type | Description |
|---|---|---|
options* | ResolveStreamOptions<T, InferBag<T, Bag>> | UseStreamCustomOptions<InferStateType<T>, InferBag<T, Bag>> |
import { Component } from "@angular/core";
import { provideStream, injectStream } from "@langchain/angular";
@Component({
providers: [provideStream({ assistantId: "agent" })],
template: `
<app-message-list />
<app-message-input />
`,
})
export class ChatContainer {}
// In child components:
@Component({
template: `
@for (msg of stream.messages(); track msg.id) {
<div>{{ msg.content }}</div>
}
`,
})
export class MessageListComponent {
stream = injectStream();
}