streaming-api

Implements Server-Side Streaming RPCs with polling fallbacks in KHI.

2.1k|97|Updated Jan 22, 2025
One-click install
npx skills add https://github.com/GoogleCloudPlatform/khi --skill streaming-api-googlecloudplatform
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: streaming-api
Source: https://github.com/GoogleCloudPlatform/khi/tree/main/.agents/skills/streaming_api
Command: npx skills add https://github.com/GoogleCloudPlatform/khi --skill streaming-api-googlecloudplatform

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Designing streaming APIs that also work in hosting environments without streaming support (like Google App Engine Standard) requires careful naming conventions, backend lifecycle management, and client-side adapters. This Skill provides the guidelines and patterns to build Server-Side Streaming RPCs in KHI with transparent polling fallbacks. ## Core Features & Use Cases - API Naming Conventions: Defines Watch/Pull patterns for state observation and Action/ActionSync/CancelActionSync patterns for long-running jobs. - Backend Utilities: Covers StateObserver for atomic state snapshots and AsyncJobManager for background jobs with abandonment timeouts, TTL eviction, and superseded-job cancellation. - Frontend Interceptor: Explains the Connect interceptor that transparently adapts streaming calls into polling unary calls, including safe iterator extraction and automatic cancellation on client abort. - Use Case: When adding a new RPC like FilterTimeline to KHI, follow this Skill to define the protobuf pair, implement the backend job manager, and wire the legacy polling interceptor so the feature works in both streaming and non-streaming deployments. ## Quick Start Use the streaming-api skill to design a new streaming RPC with a polling fallback for the KHI backend and frontend.

Frequently Asked Questions about streaming-api

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement server-side streaming with a polling fallback?▼

Define paired RPCs in protobuf: a streaming RPC and a polling unary RPC. On the client, use a Connect interceptor that detects streaming requests and transparently wraps polling unary calls into an AsyncIterable, so call-sites need no changes.

What naming convention should streaming and polling RPCs follow?▼

For state observation, use Watch<Resource> for streaming and Pull<Resource> for polling. For long-running jobs, use <Action> for streaming, <Action>Sync for polling, and Cancel<Action>Sync for cancellation.

How do I prevent resource leaks from abandoned polling jobs?▼

Use AsyncJobManager, which cancels a job's context after an abandonment timeout (default 15 seconds) when the client stops polling. Completed job results are evicted via a TTL cleaner after one minute to free memory.

Why does extracting the request message with for-await throw a TypeError?▼

Returning early from for-await triggers the iterator return() protocol, which Connect's unary input wrapper does not implement, causing TypeError: obj[k] is not a function. Use direct Symbol.asyncIterator access with iterator.next() instead.

Can streaming APIs work on Google App Engine Standard?▼

Server-Side Streaming is unavailable on App Engine Standard, so KHI falls back to unary polling. Activate legacy polling mode with the ?pollLegacy=true URL parameter or the environment.usePollingLegacy flag.