mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-20 00:51:20 +00:00
Compare commits
1 Commits
feat/rende
...
e6ca1763ef
| Author | SHA1 | Date | |
|---|---|---|---|
|
e6ca1763ef
|
@@ -61,7 +61,7 @@ export async function getSessionFromHeaders(
|
||||
}
|
||||
|
||||
/**
|
||||
* Dev/test middleware that injects a fake user and session.
|
||||
* Test-only middleware that injects a fake user and session.
|
||||
* Pass userId to simulate an authenticated request, or omit to get 401.
|
||||
*/
|
||||
export function mockAuthSessionMiddleware(userId?: string): AuthSessionMiddleware {
|
||||
@@ -69,34 +69,8 @@ export function mockAuthSessionMiddleware(userId?: string): AuthSessionMiddlewar
|
||||
if (!userId) {
|
||||
return c.json({ error: "Unauthorized" }, 401)
|
||||
}
|
||||
|
||||
const now = new Date()
|
||||
const expiresAt = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000)
|
||||
|
||||
const user: AuthUser = {
|
||||
id: "k7Gx2mPqRvNwYs9TdLfA4bHcJeUo1iZn",
|
||||
name: "Dev User",
|
||||
email: "dev@aelis.local",
|
||||
emailVerified: true,
|
||||
image: null,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
}
|
||||
|
||||
const session: AuthSession = {
|
||||
id: "Wt3FvBpXaQrMhD8sKjE6LcYn0gUz5iRo",
|
||||
userId: "k7Gx2mPqRvNwYs9TdLfA4bHcJeUo1iZn",
|
||||
token: "Vb9CxNfRm2KwQs7TjPeA5dLhYg0UoZi4",
|
||||
expiresAt,
|
||||
ipAddress: "127.0.0.1",
|
||||
userAgent: "aelis-dev",
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
}
|
||||
|
||||
c.set("user", user)
|
||||
c.set("session", session)
|
||||
|
||||
c.set("user", { id: userId } as AuthUser)
|
||||
c.set("session", { id: "mock-session" } as AuthSession)
|
||||
await next()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { LocationSource } from "@aelis/source-location"
|
||||
import { Hono } from "hono"
|
||||
|
||||
import { registerAuthHandlers } from "./auth/http.ts"
|
||||
import { mockAuthSessionMiddleware, requireSession } from "./auth/session-middleware.ts"
|
||||
import { requireSession } from "./auth/session-middleware.ts"
|
||||
import { createFeedEnhancer } from "./enhancement/enhance-feed.ts"
|
||||
import { createLlmClient } from "./enhancement/llm-client.ts"
|
||||
import { registerFeedHttpHandlers } from "./feed/http.ts"
|
||||
@@ -43,16 +43,10 @@ function main() {
|
||||
|
||||
app.get("/health", (c) => c.json({ status: "ok" }))
|
||||
|
||||
const isDev = process.env.NODE_ENV !== "production"
|
||||
const authSessionMiddleware = isDev ? mockAuthSessionMiddleware("dev-user") : requireSession
|
||||
|
||||
if (!isDev) {
|
||||
registerAuthHandlers(app)
|
||||
}
|
||||
|
||||
registerAuthHandlers(app)
|
||||
registerFeedHttpHandlers(app, {
|
||||
sessionManager,
|
||||
authSessionMiddleware,
|
||||
authSessionMiddleware: requireSession,
|
||||
})
|
||||
registerLocationHttpHandlers(app, { sessionManager })
|
||||
|
||||
|
||||
18
bun.lock
18
bun.lock
@@ -5,8 +5,6 @@
|
||||
"": {
|
||||
"name": "aelis",
|
||||
"devDependencies": {
|
||||
"@json-render/core": "^0.12.1",
|
||||
"@nym.sh/jrx": "^0.1.0",
|
||||
"@types/bun": "latest",
|
||||
"oxfmt": "^0.24.0",
|
||||
"oxlint": "^1.39.0",
|
||||
@@ -114,10 +112,6 @@
|
||||
"dependencies": {
|
||||
"@standard-schema/spec": "^1.1.0",
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@json-render/core": "*",
|
||||
"@nym.sh/jrx": "*",
|
||||
},
|
||||
},
|
||||
"packages/aelis-data-source-weatherkit": {
|
||||
"name": "@aelis/data-source-weatherkit",
|
||||
@@ -655,8 +649,6 @@
|
||||
|
||||
"@jridgewell/trace-mapping": ["@jridgewell/trace-mapping@0.3.31", "", { "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" } }, "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw=="],
|
||||
|
||||
"@json-render/core": ["@json-render/core@0.12.1", "", { "dependencies": { "zod": "^4.3.6" } }, "sha512-1tV/481GPHmIRd6lXfWcTaIslQusmDg5lzcSBzWLkSXjF9sjjyOQL090in7uHT4tOMWkdmlEJOW5H9C72PsUEQ=="],
|
||||
|
||||
"@mjackson/node-fetch-server": ["@mjackson/node-fetch-server@0.2.0", "", {}, "sha512-EMlH1e30yzmTpGLQjlFmaDAjyOeZhng1/XCd7DExR8PNAnG/G1tyruZxEoUe11ClnwGhGrtsdnyyUx1frSzjng=="],
|
||||
|
||||
"@mongodb-js/saslprep": ["@mongodb-js/saslprep@1.4.6", "", { "dependencies": { "sparse-bitfield": "^3.0.3" } }, "sha512-y+x3H1xBZd38n10NZF/rEBlvDOOMQ6LKUTHqr8R9VkJ+mmQOYtJFxIlkkK8fZrtOiL6VixbOBWMbZGBdal3Z1g=="],
|
||||
@@ -677,8 +669,6 @@
|
||||
|
||||
"@nolyfill/is-core-module": ["@nolyfill/is-core-module@1.0.39", "", {}, "sha512-nn5ozdjYQpUCZlWGuxcJY/KpxkWQs4DcbMCmKojjyrYDEAGy4Ce19NN4v5MduafTwJlbKc99UA8YhSVqq9yPZA=="],
|
||||
|
||||
"@nym.sh/jrx": ["@nym.sh/jrx@0.1.0", "", { "peerDependencies": { "@json-render/core": ">=0.10.0" } }, "sha512-mu6fkAP/TI9FuP8A4WMCrcucpUtWF5xBTcETnrjOtvEED9i+7sQKuoOyhJeF6QaSuUkAA/8t3Xx3kYUjcAPFbw=="],
|
||||
|
||||
"@oclif/core": ["@oclif/core@4.8.4", "", { "dependencies": { "ansi-escapes": "^4.3.2", "ansis": "^3.17.0", "clean-stack": "^3.0.1", "cli-spinners": "^2.9.2", "debug": "^4.4.3", "ejs": "^3.1.10", "get-package-type": "^0.1.0", "indent-string": "^4.0.0", "is-wsl": "^2.2.0", "lilconfig": "^3.1.3", "minimatch": "^10.2.4", "semver": "^7.7.3", "string-width": "^4.2.3", "supports-color": "^8", "tinyglobby": "^0.2.14", "widest-line": "^3.1.0", "wordwrap": "^1.0.0", "wrap-ansi": "^7.0.0" } }, "sha512-UTAqwXJJyRvLBvosL+1uPZYSpr8lEHgUb/EVGbPXo5WZqUIBHfJ0sR2bkBEsrj00/ar4IegKxx4YK0wn2c8SQg=="],
|
||||
|
||||
"@oclif/plugin-autocomplete": ["@oclif/plugin-autocomplete@3.2.40", "", { "dependencies": { "@oclif/core": "^4", "ansis": "^3.16.0", "debug": "^4.4.1", "ejs": "^3.1.10" } }, "sha512-HCfDuUV3l5F5Wz7SKkaoFb+OMQ5vKul8zvsPNgI0QbZcQuGHmn3svk+392wSfXboyA1gq8kzEmKPAoQK6r6UNw=="],
|
||||
@@ -2037,7 +2027,7 @@
|
||||
|
||||
"ical.js": ["ical.js@2.2.1", "", {}, "sha512-yK/UlPbEs316igb/tjRgbFA8ZV75rCsBJp/hWOatpyaPNlgw0dGDmU+FoicOcwX4xXkeXOkYiOmCqNPFpNPkQg=="],
|
||||
|
||||
"iconv-lite": ["iconv-lite@0.7.2", "", { "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" } }, "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw=="],
|
||||
"iconv-lite": ["iconv-lite@0.4.24", "", { "dependencies": { "safer-buffer": ">= 2.1.2 < 3" } }, "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA=="],
|
||||
|
||||
"ieee754": ["ieee754@1.2.1", "", {}, "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA=="],
|
||||
|
||||
@@ -3533,8 +3523,6 @@
|
||||
|
||||
"body-parser/debug": ["debug@2.6.9", "", { "dependencies": { "ms": "2.0.0" } }, "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA=="],
|
||||
|
||||
"body-parser/iconv-lite": ["iconv-lite@0.4.24", "", { "dependencies": { "safer-buffer": ">= 2.1.2 < 3" } }, "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA=="],
|
||||
|
||||
"c12/dotenv": ["dotenv@16.6.1", "", {}, "sha512-uBq4egWHTcTt33a72vpSG0z3HnPuIl6NqYcTrKEg2azoEyl2hpW0zqlxysq2pK9HlDIHyHyakeYaYnSAwd8bow=="],
|
||||
|
||||
"c12/jiti": ["jiti@2.6.1", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-ekilCSN1jwRvIbgeg/57YFh8qQDNbwDb9xT/qu2DAHbFFZUicIl4ygVaAvzveMhMVr3LnpSKTNnwt8PoOfmKhQ=="],
|
||||
@@ -3685,6 +3673,8 @@
|
||||
|
||||
"mv/rimraf": ["rimraf@2.4.5", "", { "dependencies": { "glob": "^6.0.1" }, "bin": { "rimraf": "./bin.js" } }, "sha512-J5xnxTyqaiw06JjMftq7L9ouA448dw/E7dKghkP9WpKNuwmARNNg+Gk8/u5ryb9N/Yo2+z3MCwuqFK/+qPOPfQ=="],
|
||||
|
||||
"mysql2/iconv-lite": ["iconv-lite@0.7.2", "", { "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" } }, "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw=="],
|
||||
|
||||
"node-exports-info/semver": ["semver@6.3.1", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA=="],
|
||||
|
||||
"npm-package-arg/semver": ["semver@7.7.4", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA=="],
|
||||
@@ -3719,8 +3709,6 @@
|
||||
|
||||
"prop-types/react-is": ["react-is@16.13.1", "", {}, "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ=="],
|
||||
|
||||
"raw-body/iconv-lite": ["iconv-lite@0.4.24", "", { "dependencies": { "safer-buffer": ">= 2.1.2 < 3" } }, "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA=="],
|
||||
|
||||
"rc/strip-json-comments": ["strip-json-comments@2.0.1", "", {}, "sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ=="],
|
||||
|
||||
"react-devtools-core/ws": ["ws@7.5.10", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ=="],
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
"format:check": "oxfmt --check ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@json-render/core": "^0.12.1",
|
||||
"@nym.sh/jrx": "^0.1.0",
|
||||
"@types/bun": "latest",
|
||||
"oxfmt": "^0.24.0",
|
||||
"oxlint": "^1.39.0"
|
||||
|
||||
@@ -7,10 +7,6 @@
|
||||
"scripts": {
|
||||
"test": "bun test ."
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@nym.sh/jrx": "*",
|
||||
"@json-render/core": "*"
|
||||
},
|
||||
"dependencies": {
|
||||
"@standard-schema/spec": "^1.1.0"
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import type { JrxNode } from "@nym.sh/jrx"
|
||||
|
||||
/**
|
||||
* Source-provided hints for post-processors.
|
||||
*
|
||||
@@ -78,12 +76,3 @@ export interface FeedItem<
|
||||
/** Named slots for LLM-fillable content. Keys are slot names. */
|
||||
slots?: Record<string, Slot>
|
||||
}
|
||||
|
||||
/** A FeedItem with a JRX UI tree attached for client-side rendering. */
|
||||
export interface RenderedFeedItem<
|
||||
TType extends string = string,
|
||||
TData extends Record<string, unknown> = Record<string, unknown>,
|
||||
> extends FeedItem<TType, TData> {
|
||||
/** JRX node tree describing how to render this item */
|
||||
ui: JrxNode
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ export type { ActionDefinition } from "./action"
|
||||
export { UnknownActionError } from "./action"
|
||||
|
||||
// Feed
|
||||
export type { FeedItem, FeedItemSignals, RenderedFeedItem, Slot } from "./feed"
|
||||
export type { FeedItem, FeedItemSignals, Slot } from "./feed"
|
||||
export { TimeRelevance } from "./feed"
|
||||
|
||||
// Feed Source
|
||||
|
||||
@@ -534,68 +534,4 @@ describe("computeSignals", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("CalDavSource feed item slots", () => {
|
||||
const EXPECTED_SLOT_NAMES = ["insight", "preparation", "crossSource"]
|
||||
|
||||
test("timed event has all three slots with null content", async () => {
|
||||
const objects: Record<string, CalDavDAVObject[]> = {
|
||||
"/cal/work": [{ url: "/cal/work/event1.ics", data: loadFixture("single-event.ics") }],
|
||||
}
|
||||
const client = new MockDAVClient([{ url: "/cal/work", displayName: "Work" }], objects)
|
||||
const source = createSource(client)
|
||||
|
||||
const items = await source.fetchItems(createContext(new Date("2026-01-15T12:00:00Z")))
|
||||
|
||||
expect(items).toHaveLength(1)
|
||||
const item = items[0]!
|
||||
expect(item.slots).toBeDefined()
|
||||
expect(Object.keys(item.slots!).sort()).toEqual([...EXPECTED_SLOT_NAMES].sort())
|
||||
|
||||
for (const name of EXPECTED_SLOT_NAMES) {
|
||||
const slot = item.slots![name]!
|
||||
expect(slot.content).toBeNull()
|
||||
expect(typeof slot.description).toBe("string")
|
||||
expect(slot.description.length).toBeGreaterThan(0)
|
||||
}
|
||||
})
|
||||
|
||||
test("all-day event has all three slots with null content", async () => {
|
||||
const objects: Record<string, CalDavDAVObject[]> = {
|
||||
"/cal/work": [{ url: "/cal/work/allday.ics", data: loadFixture("all-day-event.ics") }],
|
||||
}
|
||||
const client = new MockDAVClient([{ url: "/cal/work", displayName: "Work" }], objects)
|
||||
const source = createSource(client)
|
||||
|
||||
const items = await source.fetchItems(createContext(new Date("2026-01-15T12:00:00Z")))
|
||||
|
||||
expect(items).toHaveLength(1)
|
||||
const item = items[0]!
|
||||
expect(item.data.isAllDay).toBe(true)
|
||||
expect(item.slots).toBeDefined()
|
||||
expect(Object.keys(item.slots!).sort()).toEqual([...EXPECTED_SLOT_NAMES].sort())
|
||||
|
||||
for (const name of EXPECTED_SLOT_NAMES) {
|
||||
expect(item.slots![name]!.content).toBeNull()
|
||||
}
|
||||
})
|
||||
|
||||
test("cancelled event has all three slots with null content", async () => {
|
||||
const objects: Record<string, CalDavDAVObject[]> = {
|
||||
"/cal/work": [{ url: "/cal/work/cancelled.ics", data: loadFixture("cancelled-event.ics") }],
|
||||
}
|
||||
const client = new MockDAVClient([{ url: "/cal/work", displayName: "Work" }], objects)
|
||||
const source = createSource(client)
|
||||
|
||||
const items = await source.fetchItems(createContext(new Date("2026-01-15T12:00:00Z")))
|
||||
|
||||
expect(items).toHaveLength(1)
|
||||
const item = items[0]!
|
||||
expect(item.data.status).toBe("cancelled")
|
||||
expect(item.slots).toBeDefined()
|
||||
expect(Object.keys(item.slots!).sort()).toEqual([...EXPECTED_SLOT_NAMES].sort())
|
||||
|
||||
for (const name of EXPECTED_SLOT_NAMES) {
|
||||
expect(item.slots![name]!.content).toBeNull()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ActionDefinition, ContextEntry, FeedItemSignals, FeedSource, Slot } from "@aelis/core"
|
||||
import type { ActionDefinition, ContextEntry, FeedItemSignals, FeedSource } from "@aelis/core"
|
||||
|
||||
import { Context, TimeRelevance, UnknownActionError } from "@aelis/core"
|
||||
import { DAVClient } from "tsdav"
|
||||
@@ -7,9 +7,6 @@ import type { CalDavDAVClient, CalDavEventData, CalDavFeedItem } from "./types.t
|
||||
|
||||
import { CalDavCalendarKey, type CalendarContext } from "./calendar-context.ts"
|
||||
import { parseICalEvents } from "./ical-parser.ts"
|
||||
import crossSourcePrompt from "./prompts/cross-source.txt"
|
||||
import insightPrompt from "./prompts/insight.txt"
|
||||
import preparationPrompt from "./prompts/preparation.txt"
|
||||
import { CalDavEventStatus, CalDavFeedItemType } from "./types.ts"
|
||||
|
||||
// -- Source options --
|
||||
@@ -343,14 +340,6 @@ export function computeSignals(
|
||||
return { urgency: 0.2, timeRelevance: TimeRelevance.Ambient }
|
||||
}
|
||||
|
||||
function createEventSlots(): Record<string, Slot> {
|
||||
return {
|
||||
insight: { description: insightPrompt, content: null },
|
||||
preparation: { description: preparationPrompt, content: null },
|
||||
crossSource: { description: crossSourcePrompt, content: null },
|
||||
}
|
||||
}
|
||||
|
||||
function createFeedItem(event: CalDavEventData, now: Date, timeZone?: string): CalDavFeedItem {
|
||||
return {
|
||||
id: `caldav-event-${event.uid}${event.recurrenceId ? `-${event.recurrenceId}` : ""}`,
|
||||
@@ -358,6 +347,5 @@ function createFeedItem(event: CalDavEventData, now: Date, timeZone?: string): C
|
||||
timestamp: now,
|
||||
data: event,
|
||||
signals: computeSignals(event, now, timeZone),
|
||||
slots: createEventSlots(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
If other feed data (weather, transit, nearby events) would disrupt or materially affect this event, state the connection in one sentence. Infer whether the event is indoor/outdoor/virtual from the title and location. Weather is only relevant if it affects getting to the event or the activity itself (e.g., rain for outdoor events, extreme conditions for physical activities). Return null for indoor or virtual events where weather has no impact. Do not fabricate information you don't have — only reference data present in the feed.
|
||||
|
||||
Examples:
|
||||
- "rain expected at 5pm — bring an umbrella for the walk to Tooley Street"
|
||||
- "Northern line has delays — leave 15 minutes early"
|
||||
- "your next event is across town — the 40 min gap may not be enough"
|
||||
- null (indoor guitar class with wind outside — weather doesn't affect the event)
|
||||
- null
|
||||
@@ -1,7 +0,0 @@
|
||||
One sentence of actionable insight the user can't already see from the event title, time, and location. Do not restate event details. Do not fabricate information you don't have. Return null if there's nothing non-obvious to say.
|
||||
|
||||
Examples:
|
||||
- "you have 2 hours free before this starts"
|
||||
- "all 8 attendees accepted — expect a full room"
|
||||
- "third time this has been rescheduled"
|
||||
- null
|
||||
@@ -1,6 +0,0 @@
|
||||
A concrete preparation step — something the user should do, bring, or review before this event. Infer only from available event and feed data. Do not restate event details. Do not fabricate information you don't have. Return null if no useful preparation comes to mind.
|
||||
|
||||
Examples:
|
||||
- "different building from your previous meeting — allow travel time"
|
||||
- "recurring meeting you declined last week — check if you need to attend"
|
||||
- null
|
||||
4
packages/aelis-source-caldav/src/text.d.ts
vendored
4
packages/aelis-source-caldav/src/text.d.ts
vendored
@@ -1,4 +0,0 @@
|
||||
declare module "*.txt" {
|
||||
const content: string
|
||||
export default content
|
||||
}
|
||||
Reference in New Issue
Block a user