Open History to see the last commit
1import {
2 DestroyRef,
3 assertInInjectionContext,
4 inject,
5 signal,
6} from '@angular/core'
7import type { Signal } from '@angular/core'
8import type { ByokClient, ByokSnapshot } from '@tanstack/ai-client/byok'
9
10export function injectByok(client: ByokClient): Signal<ByokSnapshot> {
11 assertInInjectionContext(injectByok)
12 const destroyRef = inject(DestroyRef)
13 const snapshot = signal(client.getSnapshot())
14 const unsubscribe = client.subscribe(() => {
15 snapshot.set(client.getSnapshot())
16 })
17 destroyRef.onDestroy(unsubscribe)
18 return snapshot.asReadonly()
19}