refactor: rename aris to aelis

Rename all references across the codebase: package names,
imports, source IDs, directory names, docs, and configs.

Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
2026-03-05 01:28:17 +00:00
parent 230116d9f7
commit e6ca1763ef
201 changed files with 891 additions and 647 deletions

View File

@@ -0,0 +1,112 @@
# @aelis/source-location
A FeedSource that provides location context to the AELIS feed graph.
## Overview
This source accepts external location pushes and does not query location itself. It provides location context to downstream sources (e.g., weather, transit) but does not produce feed items.
## Installation
```bash
bun add @aelis/source-location
```
## Usage
```ts
import { LocationSource, LocationKey, type Location } from "@aelis/source-location"
import { contextValue } from "@aelis/core"
// Create source with default history size (1)
const locationSource = new LocationSource()
// Or keep last 10 locations
const locationSource = new LocationSource({ historySize: 10 })
// Push location from external provider (GPS, network, etc.)
locationSource.pushLocation({
lat: 37.7749,
lng: -122.4194,
accuracy: 10,
timestamp: new Date(),
})
// Access current location
locationSource.lastLocation // { lat, lng, accuracy, timestamp } | null
// Access location history (oldest first)
locationSource.locationHistory // readonly Location[]
```
### With FeedController
```ts
import { FeedController } from "@aelis/core"
import { LocationSource } from "@aelis/source-location"
const locationSource = new LocationSource()
const controller = new FeedController({
sources: [locationSource, weatherSource, transitSource],
})
// Push location updates - downstream sources will re-fetch
locationSource.pushLocation({
lat: 37.7749,
lng: -122.4194,
accuracy: 10,
timestamp: new Date(),
})
```
### Reading Location in Downstream Sources
```ts
import { contextValue, type FeedSource } from "@aelis/core"
import { LocationKey } from "@aelis/source-location"
const weatherSource: FeedSource = {
id: "weather",
dependencies: ["location"],
async fetchContext(context) {
const location = contextValue(context, LocationKey)
if (!location) return {}
const weather = await fetchWeather(location.lat, location.lng)
return { [WeatherKey]: weather }
},
}
```
## API
### `LocationSource`
| Member | Type | Description |
| ------------------------ | --------------------- | ------------------------------------- |
| `id` | `"location"` | Source identifier |
| `constructor(options?)` | | Create with optional `historySize` |
| `pushLocation(location)` | `void` | Push new location, notifies listeners |
| `lastLocation` | `Location \| null` | Most recent location |
| `locationHistory` | `readonly Location[]` | All retained locations, oldest first |
### `Location`
```ts
interface Location {
lat: number
lng: number
accuracy: number // meters
timestamp: Date
}
```
### `LocationKey`
Typed context key for accessing location in downstream sources:
```ts
const location = contextValue(context, LocationKey)
```

View File

@@ -0,0 +1,14 @@
{
"name": "@aelis/source-location",
"version": "0.0.0",
"type": "module",
"main": "src/index.ts",
"types": "src/index.ts",
"scripts": {
"test": "bun test src/"
},
"dependencies": {
"@aelis/core": "workspace:*",
"arktype": "^2.1.0"
}
}

View File

@@ -0,0 +1,2 @@
export { LocationSource, LocationKey } from "./location-source.ts"
export { Location, type LocationSourceOptions } from "./types.ts"

View File

@@ -0,0 +1,188 @@
import { describe, expect, mock, test } from "bun:test"
import type { Location } from "./types.ts"
import { LocationKey, LocationSource } from "./location-source.ts"
function createLocation(overrides: Partial<Location> = {}): Location {
return {
lat: 37.7749,
lng: -122.4194,
accuracy: 10,
timestamp: new Date(),
...overrides,
}
}
describe("LocationSource", () => {
describe("FeedSource interface", () => {
test("has correct id", () => {
const source = new LocationSource()
expect(source.id).toBe("aelis.location")
})
test("fetchItems always returns empty array", async () => {
const source = new LocationSource()
source.pushLocation(createLocation())
const items = await source.fetchItems()
expect(items).toEqual([])
})
test("fetchContext returns null when no location", async () => {
const source = new LocationSource()
const context = await source.fetchContext()
expect(context).toBeNull()
})
test("fetchContext returns location when available", async () => {
const source = new LocationSource()
const location = createLocation()
source.pushLocation(location)
const entries = await source.fetchContext()
expect(entries).toEqual([[LocationKey, location]])
})
})
describe("pushLocation", () => {
test("updates lastLocation", () => {
const source = new LocationSource()
expect(source.lastLocation).toBeNull()
const location = createLocation()
source.pushLocation(location)
expect(source.lastLocation).toEqual(location)
})
test("notifies listeners", () => {
const source = new LocationSource()
const listener = mock()
source.onContextUpdate(listener)
const location = createLocation()
source.pushLocation(location)
expect(listener).toHaveBeenCalledTimes(1)
expect(listener).toHaveBeenCalledWith([[LocationKey, location]])
})
})
describe("history", () => {
test("default historySize is 1", () => {
const source = new LocationSource()
source.pushLocation(createLocation({ lat: 1 }))
source.pushLocation(createLocation({ lat: 2 }))
expect(source.locationHistory).toHaveLength(1)
expect(source.lastLocation?.lat).toBe(2)
})
test("respects configured historySize", () => {
const source = new LocationSource({ historySize: 3 })
const loc1 = createLocation({ lat: 1 })
const loc2 = createLocation({ lat: 2 })
const loc3 = createLocation({ lat: 3 })
source.pushLocation(loc1)
source.pushLocation(loc2)
source.pushLocation(loc3)
expect(source.locationHistory).toEqual([loc1, loc2, loc3])
})
test("evicts oldest when exceeding historySize", () => {
const source = new LocationSource({ historySize: 2 })
const loc1 = createLocation({ lat: 1 })
const loc2 = createLocation({ lat: 2 })
const loc3 = createLocation({ lat: 3 })
source.pushLocation(loc1)
source.pushLocation(loc2)
source.pushLocation(loc3)
expect(source.locationHistory).toEqual([loc2, loc3])
})
test("locationHistory is readonly", () => {
const source = new LocationSource({ historySize: 3 })
source.pushLocation(createLocation())
const history = source.locationHistory
expect(Array.isArray(history)).toBe(true)
})
})
describe("onContextUpdate", () => {
test("returns cleanup function", () => {
const source = new LocationSource()
const listener = mock()
const cleanup = source.onContextUpdate(listener)
source.pushLocation(createLocation({ lat: 1 }))
expect(listener).toHaveBeenCalledTimes(1)
cleanup()
source.pushLocation(createLocation({ lat: 2 }))
expect(listener).toHaveBeenCalledTimes(1)
})
test("supports multiple listeners", () => {
const source = new LocationSource()
const listener1 = mock()
const listener2 = mock()
source.onContextUpdate(listener1)
source.onContextUpdate(listener2)
source.pushLocation(createLocation())
expect(listener1).toHaveBeenCalledTimes(1)
expect(listener2).toHaveBeenCalledTimes(1)
})
})
describe("actions", () => {
test("listActions returns update-location action", async () => {
const source = new LocationSource()
const actions = await source.listActions()
expect(actions["update-location"]).toBeDefined()
expect(actions["update-location"]!.id).toBe("update-location")
expect(actions["update-location"]!.input).toBeDefined()
})
test("executeAction update-location pushes location", async () => {
const source = new LocationSource()
expect(source.lastLocation).toBeNull()
const location = createLocation({ lat: 40.7128, lng: -74.006 })
await source.executeAction("update-location", location)
expect(source.lastLocation).toEqual(location)
})
test("executeAction throws on invalid input", async () => {
const source = new LocationSource()
await expect(
source.executeAction("update-location", { lat: "not a number" }),
).rejects.toThrow()
})
test("executeAction throws for unknown action", async () => {
const source = new LocationSource()
await expect(source.executeAction("nonexistent", {})).rejects.toThrow("Unknown action")
})
})
})

View File

@@ -0,0 +1,99 @@
import type { ActionDefinition, ContextEntry, FeedSource } from "@aelis/core"
import { Context, UnknownActionError, contextKey, type ContextKey } from "@aelis/core"
import { type } from "arktype"
import { Location, type LocationSourceOptions } from "./types.ts"
export const LocationKey: ContextKey<Location> = contextKey("aelis.location", "location")
/**
* A FeedSource that provides location context.
*
* This source accepts external location pushes and does not query location itself.
* Use `pushLocation` to update the location from an external provider (e.g., GPS, network).
*
* Does not produce feed items - always returns empty array from `fetchItems`.
*/
export class LocationSource implements FeedSource {
readonly id = "aelis.location"
private readonly historySize: number
private locations: Location[] = []
private listeners = new Set<(entries: readonly ContextEntry[]) => void>()
constructor(options: LocationSourceOptions = {}) {
this.historySize = options.historySize ?? 1
}
async listActions(): Promise<Record<string, ActionDefinition>> {
return {
"update-location": {
id: "update-location",
description: "Push a new location update",
input: Location,
},
}
}
async executeAction(actionId: string, params: unknown): Promise<void> {
switch (actionId) {
case "update-location": {
const result = Location(params)
if (result instanceof type.errors) {
throw new Error(result.summary)
}
this.pushLocation(result)
return
}
default:
throw new UnknownActionError(actionId)
}
}
/**
* Push a new location update. Notifies all context listeners.
*/
pushLocation(location: Location): void {
this.locations.push(location)
if (this.locations.length > this.historySize) {
this.locations.shift()
}
const entries: readonly ContextEntry[] = [[LocationKey, location]]
this.listeners.forEach((listener) => {
listener(entries)
})
}
/**
* Most recent location, or null if none pushed.
*/
get lastLocation(): Location | null {
return this.locations[this.locations.length - 1] ?? null
}
/**
* Location history, oldest first. Length limited by `historySize`.
*/
get locationHistory(): readonly Location[] {
return this.locations
}
onContextUpdate(callback: (entries: readonly ContextEntry[]) => void): () => void {
this.listeners.add(callback)
return () => {
this.listeners.delete(callback)
}
}
async fetchContext(): Promise<readonly ContextEntry[] | null> {
if (this.lastLocation) {
return [[LocationKey, this.lastLocation]]
}
return null
}
async fetchItems(): Promise<[]> {
return []
}
}

View File

@@ -0,0 +1,17 @@
import { type } from "arktype"
/** Geographic coordinates with accuracy and timestamp. */
export const Location = type({
lat: "number",
lng: "number",
/** Accuracy in meters */
accuracy: "number",
timestamp: "Date",
})
export type Location = typeof Location.infer
export interface LocationSourceOptions {
/** Number of locations to retain in history. Defaults to 1. */
historySize?: number
}