Files
orca/src/shared/native-chat-stream-unsubscribe.ts
T
b916248294 Polish desktop native chat view (#6641)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Orca <help@stably.ai>
Co-authored-by: gsxdsm <gsxdsm@users.noreply.github.com>
2026-06-28 15:43:07 -07:00

28 lines
1.1 KiB
TypeScript

// Why: the runtime keys a native-chat transcript fs-watcher by the cleanup token
// `agent:sessionId`. A subscribing client must echo that exact token on
// `nativeChat.unsubscribe` so the watcher is closed when the chat view toggles
// off (not just on socket close) — otherwise watchers leak per session-switch.
// Both the web runtime client and mobile use this single key shape; centralizing
// it here keeps the token from drifting between the two surfaces.
export type NativeChatUnsubscribeRpc = {
method: 'nativeChat.unsubscribe'
params: { subscriptionId: string }
}
/** The cleanup token the server keys the transcript watcher under. */
export function buildNativeChatSubscriptionId(agent: string, sessionId: string): string {
return `${agent}:${sessionId}`
}
/** The unsubscribe RPC frame a client sends on teardown to close the watcher. */
export function buildNativeChatUnsubscribe(
agent: string,
sessionId: string
): NativeChatUnsubscribeRpc {
return {
method: 'nativeChat.unsubscribe',
params: { subscriptionId: buildNativeChatSubscriptionId(agent, sessionId) }
}
}