agent-context-tier.mjs
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠ breaking
1 day ago
| 1 | /** |
| 2 | * Agent context tier redaction for normalized calendar events. |
| 3 | * |
| 4 | * Calendar summaries and descriptions are untrusted prompt content. Retrieval |
| 5 | * must enforce tier caps server-side — never rely on client toggles alone. |
| 6 | * |
| 7 | * @see docs/CALENDAR-EVENTS-V0-SPEC.md — Agent Context Tiers |
| 8 | */ |
| 9 | |
| 10 | /** @typedef {import('./ics-normalizer.mjs').NormalizedCalendarEvent} NormalizedCalendarEvent */ |
| 11 | /** @typedef {import('./source-calendar-defaults.mjs').AgentContextTier} AgentContextTier */ |
| 12 | |
| 13 | /** |
| 14 | * @typedef {Object} AgentVisibleCalendarEvent |
| 15 | * @property {string} external_uid |
| 16 | * @property {string} start |
| 17 | * @property {string} end |
| 18 | * @property {string} timezone |
| 19 | * @property {boolean} busy |
| 20 | * @property {'confirmed'|'cancelled'|'tentative'} status |
| 21 | * @property {string|null} [summary] |
| 22 | * @property {string|null} [calendar_label] |
| 23 | * @property {string[]|null} [linked_note_paths] |
| 24 | * @property {string|null} [location] |
| 25 | * @property {string|null} [description] |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * Redact a normalized event to the fields visible at the given agent tier. |
| 30 | * |
| 31 | * @param {NormalizedCalendarEvent} event |
| 32 | * @param {AgentContextTier} tier |
| 33 | * @param {{ calendar_label?: string|null, linked_note_paths?: string[]|null, location?: string|null, description?: string|null }} [extras] |
| 34 | * @returns {AgentVisibleCalendarEvent | null} |
| 35 | */ |
| 36 | export function redactEventForAgentTier(event, tier, extras = {}) { |
| 37 | if (tier === 0) { |
| 38 | return null; |
| 39 | } |
| 40 | |
| 41 | /** @type {AgentVisibleCalendarEvent} */ |
| 42 | const base = { |
| 43 | external_uid: event.external_uid, |
| 44 | start: event.start, |
| 45 | end: event.end, |
| 46 | timezone: event.timezone, |
| 47 | busy: event.busy, |
| 48 | status: event.status, |
| 49 | }; |
| 50 | |
| 51 | if (tier === 1) { |
| 52 | return base; |
| 53 | } |
| 54 | |
| 55 | const withSummary = { |
| 56 | ...base, |
| 57 | summary: event.summary, |
| 58 | calendar_label: extras.calendar_label ?? null, |
| 59 | }; |
| 60 | |
| 61 | if (tier === 2) { |
| 62 | return withSummary; |
| 63 | } |
| 64 | |
| 65 | const withLinks = { |
| 66 | ...withSummary, |
| 67 | linked_note_paths: extras.linked_note_paths ?? null, |
| 68 | }; |
| 69 | |
| 70 | if (tier === 3) { |
| 71 | return withLinks; |
| 72 | } |
| 73 | |
| 74 | return { |
| 75 | ...withLinks, |
| 76 | location: extras.location ?? null, |
| 77 | description: extras.description ?? null, |
| 78 | }; |
| 79 | } |
File History
1 commit
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠
1 day ago