@fusilier/calendarai
v0.2.2
Published
Production-grade Calendar AI orchestration for Next.js (App Router) with pluggable calendar providers (Zimbra/CalDAV), OpenAI Responses model calls, strict plan schemas, idempotency, audit/outbox, and RBAC.
Maintainers
Readme
@fusilier/calendarai
Production-grade Calendar AI orchestration for Next.js (App Router): sessions → objective → snapshot → resolution → plan → validate/explain/approve → execute → verify/finalize.
Open-core note: this package is typically used as the “orchestration layer”. In an open-core strategy, you may expose
calendarai-corepublicly and keep enterprise connectors/agents private.
Key Features
- Deterministic, confirmation-based workflow (objective approval + plan approval).
- Strict JSON Schema validation for LLM outputs (server-side validation).
- Pluggable architecture:
- Calendar Provider (Mock, Zimbra/CalDAV, etc.)
- Repository (In-memory, Postgres, custom)
- Model Calls (OpenAI Responses API adapter, custom)
- Idempotency for create operations (prevents duplicate event creation).
- Audit trail + outbox hooks for enterprise workflows.
- Next.js App Router integration via a single catch-all route handler.
Requirements
- Node.js: 18+ (recommended 20+)
- Next.js: App Router (Node runtime required for server-side API handlers)
- An OpenAI API key (if using the built-in OpenAI adapter)
Installation
npm install @fusilier/calendarai
# or
pnpm add @fusilier/calendarai
# or
yarn add @fusilier/calendaraiQuickstart (Next.js App Router)
Create the catch-all route:
app/api/calendar-ai/[...path]/route.ts
import {
createCalendarAIRouteHandlers,
InMemoryCalendarAIRepository,
MockCalendarProvider,
OpenAIResponsesModelCalls,
} from "@fusilier/calendarai";
const repo = new InMemoryCalendarAIRepository();
const calendarProvider = new MockCalendarProvider();
const modelCalls = new OpenAIResponsesModelCalls({
apiKey: process.env.OPENAI_API_KEY!,
model: process.env.OPENAI_MODEL ?? "gpt-4o-mini",
});
export const { GET, POST } = createCalendarAIRouteHandlers({
basePath: "/api/calendar-ai",
repo,
calendarProvider,
modelCalls,
auth: async () => ({
userId: "demo-user",
tenantId: "demo-tenant",
calId: "primary",
timezone: "Europe/Paris",
scopes: ["calendar_ai:write"],
}),
});
// IMPORTANT: Next.js must run this route in Node runtime.
export const runtime = "nodejs";Set environment variables:
OPENAI_API_KEY=...
OPENAI_MODEL=gpt-4o-miniAPI Surface (Default Routes)
Base path: /api/calendar-ai
GET /healthPOST /sessionsPOST /sessions/:sessionId/objectives:interpretPOST /sessions/:sessionId/objectives/:objectiveId:approvePOST /sessions/:sessionId/context-snapshotsPOST /sessions/:sessionId/resolutionsPOST /sessions/:sessionId/plansPOST /sessions/:sessionId/plans/:planId:validatePOST /sessions/:sessionId/plans/:planId:explainPOST /sessions/:sessionId/plans/:planId:approvePOST /sessions/:sessionId/plans/:planId:executeGET /executions/:executionIdPOST /executions/:executionId:verifyPOST /executions/:executionId:finalize
Typical Workflow
- Create a session
- Interpret objective from free text
- Approve objective (locks intent)
- Create snapshot (pull calendar window)
- Create resolution (select relevant events)
- Create plan (strict JSON operations)
- Validate plan (schema + risk policy)
- Explain plan (UI-friendly summaries)
- Approve plan
- Execute plan (provider calls + idempotency)
- Verify + finalize
Configuration
Auth
You must provide an auth(req) resolver returning an AuthContext:
userId,tenantId,calId,timezonescopes[](RBAC)- optional
providerAuth(opaque credentials/token used by the calendar provider)
RBAC
Non-GET endpoints require calendar_ai:write by default.
Repository
You can swap persistence by implementing the repository interface and passing it into the factory:
InMemoryCalendarAIRepositoryis recommended for development only.- For production, use Postgres or your own durable backend.
Calendar Provider
MockCalendarProvideris included for development/testing.- Production providers should implement optimistic concurrency (ETag / If-Match) and robust error mapping.
Model Calls
OpenAIResponsesModelCallsuses the OpenAI Responses API with structured outputs.- You may implement your own model adapter to use different models/vendors or stricter internal prompt policies.
Security Considerations
- Treat all calendar operations as high-impact: always require explicit approvals.
- Use server-side schema validation and reject malformed LLM outputs.
- Store secrets only in server environment variables; never expose provider credentials to the browser.
- Ensure audit logs do not leak sensitive content (PII, private event notes) unless required by business needs.
Development
npm install
npm run build
npm testVersioning
This project follows Semantic Versioning (SemVer) where possible.
License
Copyright (c) Fusilier International Group (FIG).
- If this package is part of your commercial/private distribution: use
UNLICENSEDorSEE LICENSE IN LICENSE. - If this package is part of your open-core public distribution: use a standard OSI license (e.g., Apache-2.0) and keep enterprise modules private.
Support
For commercial licensing, enterprise connectors, and integration support:
- Email: [email protected] (placeholder)
- Website: https://fusilier.group (placeholder)
