2026-03-10 19:19:23 +00:00
|
|
|
import { LocationSource } from "@aelis/source-location"
|
2026-01-25 14:54:08 +00:00
|
|
|
import { Hono } from "hono"
|
|
|
|
|
|
2026-01-25 16:21:00 +00:00
|
|
|
import { registerAuthHandlers } from "./auth/http.ts"
|
2026-03-11 00:21:34 +00:00
|
|
|
import { mockAuthSessionMiddleware, requireSession } from "./auth/session-middleware.ts"
|
2026-03-05 02:01:30 +00:00
|
|
|
import { createFeedEnhancer } from "./enhancement/enhance-feed.ts"
|
|
|
|
|
import { createLlmClient } from "./enhancement/llm-client.ts"
|
2026-02-24 22:30:13 +00:00
|
|
|
import { registerFeedHttpHandlers } from "./feed/http.ts"
|
2026-02-22 20:59:19 +00:00
|
|
|
import { registerLocationHttpHandlers } from "./location/http.ts"
|
2026-02-18 00:41:20 +00:00
|
|
|
import { UserSessionManager } from "./session/index.ts"
|
|
|
|
|
import { WeatherSourceProvider } from "./weather/provider.ts"
|
2026-01-25 16:21:00 +00:00
|
|
|
|
2026-01-25 22:47:53 +00:00
|
|
|
function main() {
|
2026-03-05 02:01:30 +00:00
|
|
|
const openrouterApiKey = process.env.OPENROUTER_API_KEY
|
|
|
|
|
const feedEnhancer = openrouterApiKey
|
|
|
|
|
? createFeedEnhancer({
|
|
|
|
|
client: createLlmClient({
|
|
|
|
|
apiKey: openrouterApiKey,
|
|
|
|
|
model: process.env.OPENROUTER_MODEL || undefined,
|
|
|
|
|
}),
|
|
|
|
|
})
|
|
|
|
|
: null
|
|
|
|
|
if (!feedEnhancer) {
|
|
|
|
|
console.warn("[enhancement] OPENROUTER_API_KEY not set — feed enhancement disabled")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const sessionManager = new UserSessionManager({
|
|
|
|
|
providers: [
|
|
|
|
|
() => new LocationSource(),
|
|
|
|
|
new WeatherSourceProvider({
|
|
|
|
|
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!,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
feedEnhancer,
|
|
|
|
|
})
|
2026-02-18 00:41:20 +00:00
|
|
|
|
2026-01-25 22:47:53 +00:00
|
|
|
const app = new Hono()
|
2026-01-25 16:21:00 +00:00
|
|
|
|
2026-01-25 22:47:53 +00:00
|
|
|
app.get("/health", (c) => c.json({ status: "ok" }))
|
|
|
|
|
|
2026-03-11 00:21:34 +00:00
|
|
|
const isDev = process.env.NODE_ENV !== "production"
|
|
|
|
|
const authSessionMiddleware = isDev ? mockAuthSessionMiddleware("dev-user") : requireSession
|
|
|
|
|
|
|
|
|
|
if (!isDev) {
|
|
|
|
|
registerAuthHandlers(app)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-05 02:01:30 +00:00
|
|
|
registerFeedHttpHandlers(app, {
|
|
|
|
|
sessionManager,
|
2026-03-11 00:21:34 +00:00
|
|
|
authSessionMiddleware,
|
2026-03-05 02:01:30 +00:00
|
|
|
})
|
2026-02-22 20:59:19 +00:00
|
|
|
registerLocationHttpHandlers(app, { sessionManager })
|
2026-01-25 22:47:53 +00:00
|
|
|
|
|
|
|
|
return app
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const app = main()
|
2026-01-25 22:19:05 +00:00
|
|
|
|
2026-01-25 14:54:08 +00:00
|
|
|
export default {
|
|
|
|
|
port: 3000,
|
|
|
|
|
fetch: app.fetch,
|
|
|
|
|
}
|