mirror of
https://github.com/kennethnym/aris.git
synced 2026-02-02 05:01:17 +00:00
feat: add @aris/source-weatherkit package
Implements FeedSource for WeatherKit API. Depends on location source, provides weather context for downstream sources, and produces weather feed items. Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
101
packages/aris-source-weatherkit/README.md
Normal file
101
packages/aris-source-weatherkit/README.md
Normal file
@@ -0,0 +1,101 @@
|
||||
# @aris/source-weatherkit
|
||||
|
||||
Weather feed source using Apple WeatherKit API.
|
||||
|
||||
## Usage
|
||||
|
||||
### Basic Setup
|
||||
|
||||
```ts
|
||||
import { WeatherSource, Units } from "@aris/source-weatherkit"
|
||||
|
||||
const weatherSource = new WeatherSource({
|
||||
credentials: {
|
||||
privateKey: process.env.WEATHERKIT_PRIVATE_KEY!,
|
||||
keyId: process.env.WEATHERKIT_KEY_ID!,
|
||||
teamId: process.env.WEATHERKIT_TEAM_ID!,
|
||||
serviceId: process.env.WEATHERKIT_SERVICE_ID!,
|
||||
},
|
||||
units: Units.metric,
|
||||
})
|
||||
```
|
||||
|
||||
### With Feed Source Graph
|
||||
|
||||
```ts
|
||||
import { LocationSource } from "@aris/source-location"
|
||||
import { WeatherSource } from "@aris/source-weatherkit"
|
||||
|
||||
const locationSource = new LocationSource()
|
||||
const weatherSource = new WeatherSource({ credentials })
|
||||
|
||||
// Weather depends on location - graph handles ordering
|
||||
const sources = [locationSource, weatherSource]
|
||||
```
|
||||
|
||||
### Reading Weather Context
|
||||
|
||||
Downstream sources can access weather data:
|
||||
|
||||
```ts
|
||||
import { contextValue } from "@aris/core"
|
||||
import { WeatherKey } from "@aris/source-weatherkit"
|
||||
|
||||
async function fetchContext(context: Context) {
|
||||
const weather = contextValue(context, WeatherKey)
|
||||
|
||||
if (weather?.condition === "Rain") {
|
||||
// Suggest umbrella, indoor activities, etc.
|
||||
}
|
||||
|
||||
if (weather && weather.uvIndex > 7) {
|
||||
// Suggest sunscreen
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Exports
|
||||
|
||||
| Export | Description |
|
||||
| --------------- | --------------------------------------- |
|
||||
| `WeatherSource` | FeedSource implementation |
|
||||
| `WeatherKey` | Context key for simplified weather data |
|
||||
| `Weather` | Type for weather context |
|
||||
| `Units` | `metric` or `imperial` |
|
||||
|
||||
## Options
|
||||
|
||||
| Option | Default | Description |
|
||||
| ------------- | -------- | -------------------------- |
|
||||
| `credentials` | - | WeatherKit API credentials |
|
||||
| `client` | - | Custom WeatherKit client |
|
||||
| `hourlyLimit` | `12` | Max hourly forecasts |
|
||||
| `dailyLimit` | `7` | Max daily forecasts |
|
||||
| `units` | `metric` | Temperature/speed units |
|
||||
|
||||
## Context
|
||||
|
||||
Provides simplified weather context for downstream sources:
|
||||
|
||||
```ts
|
||||
interface Weather {
|
||||
temperature: number
|
||||
temperatureApparent: number
|
||||
condition: ConditionCode
|
||||
humidity: number
|
||||
uvIndex: number
|
||||
windSpeed: number
|
||||
daylight: boolean
|
||||
}
|
||||
```
|
||||
|
||||
## Feed Items
|
||||
|
||||
Produces feed items:
|
||||
|
||||
- `weather-current` - Current conditions
|
||||
- `weather-hourly` - Hourly forecasts (up to `hourlyLimit`)
|
||||
- `weather-daily` - Daily forecasts (up to `dailyLimit`)
|
||||
- `weather-alert` - Weather alerts when present
|
||||
|
||||
Priority is adjusted based on weather severity (storms, extreme temperatures).
|
||||
Reference in New Issue
Block a user