mirror of
https://github.com/kennethnym/aris.git
synced 2026-04-01 23:51:17 +01:00
Compare commits
1 Commits
feat/defau
...
feat/backe
| Author | SHA1 | Date | |
|---|---|---|---|
|
710a6b348d
|
@@ -4,7 +4,7 @@ import type { EnhancementResult } from "./schema.ts"
|
||||
|
||||
import { enhancementResultJsonSchema, parseEnhancementResult } from "./schema.ts"
|
||||
|
||||
const DEFAULT_MODEL = "z-ai/glm-4.7-flash"
|
||||
const DEFAULT_MODEL = "openai/gpt-4.1-mini"
|
||||
const DEFAULT_TIMEOUT_MS = 30_000
|
||||
|
||||
export interface LlmClientConfig {
|
||||
|
||||
@@ -69,7 +69,7 @@ export class TflApi {
|
||||
}
|
||||
|
||||
async fetchLineStatuses(lines?: TflLineId[]): Promise<TflLineStatus[]> {
|
||||
const lineIds = lines?.length ? lines : ALL_LINE_IDS
|
||||
const lineIds = lines ?? ALL_LINE_IDS
|
||||
const data = await this.fetch<unknown>(`/Line/${lineIds.join(",")}/Status`)
|
||||
|
||||
const parsed = lineResponseArray(data)
|
||||
@@ -101,8 +101,8 @@ export class TflApi {
|
||||
return this.stationsCache
|
||||
}
|
||||
|
||||
// Fetch stations for all lines in parallel, tolerating individual failures
|
||||
const results = await Promise.allSettled(
|
||||
// Fetch stations for all lines in parallel
|
||||
const responses = await Promise.all(
|
||||
ALL_LINE_IDS.map(async (id) => {
|
||||
const data = await this.fetch<unknown>(`/Line/${id}/StopPoints`)
|
||||
const parsed = lineStopPointsArray(data)
|
||||
@@ -116,12 +116,7 @@ export class TflApi {
|
||||
// Merge stations, combining lines for shared stations
|
||||
const stationMap = new Map<string, StationLocation>()
|
||||
|
||||
for (const result of results) {
|
||||
if (result.status === "rejected") {
|
||||
continue
|
||||
}
|
||||
|
||||
const { lineId: currentLineId, stops } = result.value
|
||||
for (const { lineId: currentLineId, stops } of responses) {
|
||||
for (const stop of stops) {
|
||||
const existing = stationMap.get(stop.naptanId)
|
||||
if (existing) {
|
||||
@@ -140,15 +135,8 @@ export class TflApi {
|
||||
}
|
||||
}
|
||||
|
||||
// Only cache if all requests succeeded — partial results shouldn't persist
|
||||
const allSucceeded = results.every((r) => r.status === "fulfilled")
|
||||
const stations = Array.from(stationMap.values())
|
||||
|
||||
if (allSucceeded) {
|
||||
this.stationsCache = stations
|
||||
}
|
||||
|
||||
return stations
|
||||
this.stationsCache = Array.from(stationMap.values())
|
||||
return this.stationsCache
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ export class TflSource implements FeedSource<TflAlertFeedItem> {
|
||||
throw new Error("Either client or apiKey must be provided")
|
||||
}
|
||||
this.client = options.client ?? new TflApi(options.apiKey!)
|
||||
this.lines = options.lines?.length ? options.lines : [...TflSource.DEFAULT_LINES_OF_INTEREST]
|
||||
this.lines = options.lines ?? [...TflSource.DEFAULT_LINES_OF_INTEREST]
|
||||
}
|
||||
|
||||
async listActions(): Promise<Record<string, ActionDefinition>> {
|
||||
|
||||
Reference in New Issue
Block a user