feat: add actions to FeedSource interface

Add listActions() and executeAction() to FeedSource for write
operations back to external services. Actions use arktype schemas
for input validation via StandardSchemaV1.

- ActionDefinition type with optional input schema
- FeedEngine routes actions with existence and ID validation
- Source IDs use reverse-domain format (aris.location, aris.tfl)
- LocationSource: update-location action with schema validation
- TflSource: set-lines-of-interest action with lineId validation
- No-op implementations for sources without actions

Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
2026-02-15 12:26:23 +00:00
parent 4d6cac7ec8
commit 699155e0d8
29 changed files with 1169 additions and 116 deletions

View File

@@ -1,7 +1,8 @@
import type { Context, FeedSource } from "@aris/core"
import type { ActionDefinition, Context, FeedSource } from "@aris/core"
import { contextValue } from "@aris/core"
import { UnknownActionError, contextValue } from "@aris/core"
import { LocationKey } from "@aris/source-location"
import { type } from "arktype"
import type {
ITflApi,
@@ -13,7 +14,9 @@ import type {
TflSourceOptions,
} from "./types.ts"
import { TflApi } from "./tfl-api.ts"
import { TflApi, lineId } from "./tfl-api.ts"
const setLinesInput = lineId.array()
const SEVERITY_PRIORITY: Record<TflAlertSeverity, number> = {
closure: 1.0,
@@ -63,8 +66,8 @@ export class TflSource implements FeedSource<TflAlertFeedItem> {
"elizabeth",
]
readonly id = "tfl"
readonly dependencies = ["location"]
readonly id = "aris.tfl"
readonly dependencies = ["aris.location"]
private readonly client: ITflApi
private lines: TflLineId[]
@@ -77,6 +80,31 @@ export class TflSource implements FeedSource<TflAlertFeedItem> {
this.lines = options.lines ?? [...TflSource.DEFAULT_LINES_OF_INTEREST]
}
async listActions(): Promise<Record<string, ActionDefinition>> {
return {
"set-lines-of-interest": {
id: "set-lines-of-interest",
description: "Update the set of monitored TfL lines",
input: setLinesInput,
},
}
}
async executeAction(actionId: string, params: unknown): Promise<void> {
switch (actionId) {
case "set-lines-of-interest": {
const result = setLinesInput(params)
if (result instanceof type.errors) {
throw new Error(result.summary)
}
this.setLinesOfInterest(result)
return
}
default:
throw new UnknownActionError(actionId)
}
}
async fetchContext(): Promise<null> {
return null
}