injectAgent
Retrieves the agent provided in the current injection context.
Pass the ref given to provideAgent(ref, …) to receive that agent with its
session's type. Without a ref the result is typed by the core contract; a
backend's own fields and commands are then reached by naming the session
type, injectAgent<MySession>(), which is not checked against the provider.
import { injectAgent } from '@threadplane/angular';Declaration · overload 1
export declare function injectAgent<TSession extends AgentSessionLike = AgentSession>(): Agent<TSession>;Type parameters
TSessionAgentSessionLikeDefault:AgentSession
Returns
Agent<TSession>Examples
readonly agent = injectAgent(TRIP);
readonly count = computed(() => this.agent.messages().length);
send(text: string) {
void this.agent.submit(text);
}Declaration · overload 2
export declare function injectAgent<TSession extends AgentSessionLike>(ref: AgentRef<TSession>): Agent<TSession>;Type parameters
TSessionAgentSessionLike
Parameters
ref· requiredAgentRef<TSession>
Returns
Agent<TSession>