MCPcopy Index your code
hub / github.com/TanStack/ai / AppComponent

Class AppComponent

examples/ts-angular-chat/src/app.component.ts:158–235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156 `,
157})
158export class AppComponent {
159 draft = ''
160 scroller = viewChild<ElementRef<HTMLElement>>('scroller')
161
162 suggestions = [
163 'What time is it right now?',
164 'Roll two dice',
165 "What's the weather in Tokyo?",
166 'What is 42 × 7?',
167 ]
168
169 chat = injectChat({
170 connection: fetchServerSentEvents('/api/chat'),
171 tools: clientTools(...chatTools),
172 })
173
174 constructor() {
175 // Auto-scroll to the latest message as the conversation streams in.
176 effect(() => {
177 this.chat.messages()
178 this.chat.isLoading()
179 const el = this.scroller()?.nativeElement
180 if (el) {
181 queueMicrotask(() => {
182 el.scrollTop = el.scrollHeight
183 })
184 }
185 })
186 }
187
188 /** A message is worth rendering if it has visible text or a tool call. */
189 isRenderable(message: {
190 parts: ReadonlyArray<{ type: string; content?: string }>
191 }): boolean {
192 return message.parts.some(
193 (part) =>
194 (part.type === 'text' && !!part.content) || part.type === 'tool-call',
195 )
196 }
197
198 /** Compact, readable tool arguments — hides empty `{}`. */
199 formatArgs(args: string): string {
200 try {
201 const parsed: unknown = JSON.parse(args)
202 const compact = JSON.stringify(parsed)
203 return compact === '{}' ? '' : compact
204 } catch {
205 return ''
206 }
207 }
208
209 hasOutput(output: unknown): boolean {
210 return output !== undefined && output !== null && output !== ''
211 }
212
213 /** Render a tool's output as a compact string. */
214 formatOutput(output: unknown): string {
215 if (typeof output === 'string') return output

Callers

nothing calls this directly

Calls 3

injectChatFunction · 0.90
clientToolsFunction · 0.90
fetchServerSentEventsFunction · 0.85

Tested by

no test coverage detected