mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-20 00:51:20 +00:00
Each FeedSource implementation now sets sourceId on items it produces, allowing consumers to trace items back to their originating source. Co-authored-by: Ona <no-reply@ona.com>
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import type { Context } from "./context"
|
|
import type { FeedItem } from "./feed"
|
|
|
|
/**
|
|
* Produces feed items from an external source.
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* type WeatherItem = FeedItem<"weather", { temp: number }>
|
|
*
|
|
* class WeatherDataSource implements DataSource<WeatherItem> {
|
|
* readonly type = "weather"
|
|
*
|
|
* async query(context: Context): Promise<WeatherItem[]> {
|
|
* const location = context.get(LocationKey)
|
|
* if (!location) return []
|
|
* const data = await fetchWeather(location)
|
|
* return [{
|
|
* id: `weather-${Date.now()}`,
|
|
* sourceId: "aelis.weather",
|
|
* type: this.type,
|
|
* timestamp: context.time,
|
|
* data: { temp: data.temperature },
|
|
* signals: { urgency: 0.5, timeRelevance: "ambient" },
|
|
* }]
|
|
* }
|
|
* }
|
|
* ```
|
|
*/
|
|
export interface DataSource<TItem extends FeedItem = FeedItem, TConfig = unknown> {
|
|
/** Unique identifier for this source type */
|
|
readonly type: TItem["type"]
|
|
|
|
/** Queries the source and returns feed items */
|
|
query(context: Context, config: TConfig): Promise<TItem[]>
|
|
}
|