WIP 2.0.0: the five AI helpers' API
src/ai/helpers.ts: instructions, schemas and inputs for draft event, summarise report (people-free reports only), draft message, summarise feedback (no names, access-logged) and improve text. Contact details are swapped for placeholders before sending and restored after; every helper gets today's date; weekday clashes and break-even over capacity are checked in code. v2 routes /ai/draft-event and friends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
+594
@@ -6994,6 +6994,116 @@ export interface paths {
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/ai/draft-event": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
get?: never;
|
||||
put?: never;
|
||||
/**
|
||||
* Draft an event from a description
|
||||
* @description Fills in the event form from the organiser's notes. `warnings` are checked in code (a weekday that doesn't match its date, costs that a full event can't cover); `draft.checks` are the AI's own. Goes through the Cross Events Hub, which counts it against the site's monthly AI allowance. Errors carry a `reason`: AI_OFF, AI_HELPER_OFF, AI_CAP_REACHED, AI_DAILY_LIMIT, AI_REFUSED, AI_INCOMPLETE, AI_UNAVAILABLE.
|
||||
*
|
||||
* **Who:** Supervisors and admins.
|
||||
*/
|
||||
post: operations["postAiDraft-event"];
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/ai/summarise-report": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
get?: never;
|
||||
put?: never;
|
||||
/**
|
||||
* Summarise a report
|
||||
* @description A few plain-language insights on a report as it is on screen. Only reports without people in them: seriesComparison, regTypes, usage, revenue, regStatus, donations, funnel, discounts, cashup, financeReport, profitReport. Goes through the Cross Events Hub, which counts it against the site's monthly AI allowance. Errors carry a `reason`: AI_OFF, AI_HELPER_OFF, AI_CAP_REACHED, AI_DAILY_LIMIT, AI_REFUSED, AI_INCOMPLETE, AI_UNAVAILABLE.
|
||||
*
|
||||
* **Who:** Supervisors and admins.
|
||||
*/
|
||||
post: operations["postAiSummarise-report"];
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/ai/draft-message": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
get?: never;
|
||||
put?: never;
|
||||
/**
|
||||
* Draft an email or WhatsApp message
|
||||
* @description Turns a short note into a message, using {{name}} and the event placeholders. With `eventId`, the event's title, start and place are given to the AI as facts. Goes through the Cross Events Hub, which counts it against the site's monthly AI allowance. Errors carry a `reason`: AI_OFF, AI_HELPER_OFF, AI_CAP_REACHED, AI_DAILY_LIMIT, AI_REFUSED, AI_INCOMPLETE, AI_UNAVAILABLE.
|
||||
*
|
||||
* **Who:** Supervisors and admins.
|
||||
*/
|
||||
post: operations["postAiDraft-message"];
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/ai/summarise-feedback": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
get?: never;
|
||||
put?: never;
|
||||
/**
|
||||
* Summarise an event's feedback
|
||||
* @description Themes, what people liked, what to improve and suggestions, from the event's feedback. Sent without who answered; contact details in comments are kept back. Recorded in the access log. Goes through the Cross Events Hub, which counts it against the site's monthly AI allowance. Errors carry a `reason`: AI_OFF, AI_HELPER_OFF, AI_CAP_REACHED, AI_DAILY_LIMIT, AI_REFUSED, AI_INCOMPLETE, AI_UNAVAILABLE.
|
||||
*
|
||||
* **Who:** Supervisors and admins.
|
||||
*/
|
||||
post: operations["postAiSummarise-feedback"];
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/ai/improve-text": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
get?: never;
|
||||
put?: never;
|
||||
/**
|
||||
* Improve a piece of text
|
||||
* @description Fixes spelling and grammar and makes it clearer (`improve`), shorter (`shorter`) or only fixes mistakes (`fix`), keeping every fact. Goes through the Cross Events Hub, which counts it against the site's monthly AI allowance. Errors carry a `reason`: AI_OFF, AI_HELPER_OFF, AI_CAP_REACHED, AI_DAILY_LIMIT, AI_REFUSED, AI_INCOMPLETE, AI_UNAVAILABLE.
|
||||
*
|
||||
* **Who:** Supervisors and admins.
|
||||
*/
|
||||
post: operations["postAiImprove-text"];
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
}
|
||||
export type webhooks = Record<string, never>;
|
||||
export interface components {
|
||||
@@ -30010,4 +30120,488 @@ export interface operations {
|
||||
};
|
||||
};
|
||||
};
|
||||
"postAiDraft-event": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody: {
|
||||
content: {
|
||||
"application/json": {
|
||||
notes: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** @description OK */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": {
|
||||
data: {
|
||||
output: {
|
||||
draft: {
|
||||
title: string;
|
||||
summary: string;
|
||||
description: string;
|
||||
startDate: string;
|
||||
startTime: string;
|
||||
endDate: string;
|
||||
endTime: string;
|
||||
location: string;
|
||||
capacity: number;
|
||||
needsParentalConsent: boolean;
|
||||
ageGroup: string;
|
||||
ticketOptions: {
|
||||
name: string;
|
||||
priceRand: number;
|
||||
description: string;
|
||||
earlyBirdPriceRand: number;
|
||||
earlyBirdUntil: string;
|
||||
}[];
|
||||
sessions: {
|
||||
date: string;
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
label: string;
|
||||
}[];
|
||||
costs: {
|
||||
item: string;
|
||||
basis: string;
|
||||
amountRand: number;
|
||||
}[];
|
||||
checks: string[];
|
||||
};
|
||||
warnings: string[];
|
||||
totalCostRand: number;
|
||||
breakEvenPlaces: number | null;
|
||||
};
|
||||
status: {
|
||||
/** @description false: hide the AI buttons (the licence has no AI, or the site isn't connected to the Hub) */
|
||||
enabled: boolean;
|
||||
/** @description true: show the buttons disabled until `renewsOn` */
|
||||
capReached: boolean;
|
||||
/** @description false: the Hub couldn't be reached just now */
|
||||
available: boolean;
|
||||
/** @description The monthly allowance, in cents */
|
||||
capCents: number;
|
||||
/** @description Used this month, in cents (fractions of a cent) */
|
||||
usedCents: number;
|
||||
usedPercent: number;
|
||||
/** @description YYYY-MM-DD */
|
||||
renewsOn: string | null;
|
||||
/** @description Each helper switched on or off in Site settings → AI */
|
||||
helpers: {
|
||||
draft_event: boolean;
|
||||
summarise_report: boolean;
|
||||
draft_message: boolean;
|
||||
summarise_feedback: boolean;
|
||||
improve_text: boolean;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
/** @description Validation failed (VALIDATION_FAILED) */
|
||||
400: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
/** @description Not signed in (UNAUTHENTICATED) */
|
||||
401: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
/** @description Not allowed for this role (FORBIDDEN) */
|
||||
403: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
"postAiSummarise-report": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody: {
|
||||
content: {
|
||||
"application/json": {
|
||||
/** @enum {string} */
|
||||
reportKey: "seriesComparison" | "regTypes" | "usage" | "revenue" | "regStatus" | "donations" | "funnel" | "discounts" | "cashup" | "financeReport" | "profitReport";
|
||||
title: string;
|
||||
subtitle?: string;
|
||||
stats?: {
|
||||
label: string;
|
||||
value: string | number;
|
||||
}[];
|
||||
columns: string[];
|
||||
rows: (string | number | null)[][];
|
||||
};
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** @description OK */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": {
|
||||
data: {
|
||||
output: {
|
||||
headline: string;
|
||||
insights: {
|
||||
title: string;
|
||||
detail: string;
|
||||
}[];
|
||||
watchOut: string[];
|
||||
};
|
||||
status: {
|
||||
/** @description false: hide the AI buttons (the licence has no AI, or the site isn't connected to the Hub) */
|
||||
enabled: boolean;
|
||||
/** @description true: show the buttons disabled until `renewsOn` */
|
||||
capReached: boolean;
|
||||
/** @description false: the Hub couldn't be reached just now */
|
||||
available: boolean;
|
||||
/** @description The monthly allowance, in cents */
|
||||
capCents: number;
|
||||
/** @description Used this month, in cents (fractions of a cent) */
|
||||
usedCents: number;
|
||||
usedPercent: number;
|
||||
/** @description YYYY-MM-DD */
|
||||
renewsOn: string | null;
|
||||
/** @description Each helper switched on or off in Site settings → AI */
|
||||
helpers: {
|
||||
draft_event: boolean;
|
||||
summarise_report: boolean;
|
||||
draft_message: boolean;
|
||||
summarise_feedback: boolean;
|
||||
improve_text: boolean;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
/** @description Validation failed (VALIDATION_FAILED) */
|
||||
400: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
/** @description Not signed in (UNAUTHENTICATED) */
|
||||
401: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
/** @description Not allowed for this role (FORBIDDEN) */
|
||||
403: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
"postAiDraft-message": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody: {
|
||||
content: {
|
||||
"application/json": {
|
||||
/** @enum {string} */
|
||||
channel: "email" | "whatsapp";
|
||||
note: string;
|
||||
eventId?: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** @description OK */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": {
|
||||
data: {
|
||||
output: {
|
||||
subject: string;
|
||||
body: string;
|
||||
};
|
||||
status: {
|
||||
/** @description false: hide the AI buttons (the licence has no AI, or the site isn't connected to the Hub) */
|
||||
enabled: boolean;
|
||||
/** @description true: show the buttons disabled until `renewsOn` */
|
||||
capReached: boolean;
|
||||
/** @description false: the Hub couldn't be reached just now */
|
||||
available: boolean;
|
||||
/** @description The monthly allowance, in cents */
|
||||
capCents: number;
|
||||
/** @description Used this month, in cents (fractions of a cent) */
|
||||
usedCents: number;
|
||||
usedPercent: number;
|
||||
/** @description YYYY-MM-DD */
|
||||
renewsOn: string | null;
|
||||
/** @description Each helper switched on or off in Site settings → AI */
|
||||
helpers: {
|
||||
draft_event: boolean;
|
||||
summarise_report: boolean;
|
||||
draft_message: boolean;
|
||||
summarise_feedback: boolean;
|
||||
improve_text: boolean;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
/** @description Validation failed (VALIDATION_FAILED) */
|
||||
400: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
/** @description Not signed in (UNAUTHENTICATED) */
|
||||
401: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
/** @description Not allowed for this role (FORBIDDEN) */
|
||||
403: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
"postAiSummarise-feedback": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody: {
|
||||
content: {
|
||||
"application/json": {
|
||||
eventId: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** @description OK */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": {
|
||||
data: {
|
||||
output: {
|
||||
overall: string;
|
||||
liked: {
|
||||
theme: string;
|
||||
mentions: number;
|
||||
}[];
|
||||
improve: {
|
||||
theme: string;
|
||||
mentions: number;
|
||||
}[];
|
||||
quotes: string[];
|
||||
nextTime: string[];
|
||||
responses: number;
|
||||
};
|
||||
status: {
|
||||
/** @description false: hide the AI buttons (the licence has no AI, or the site isn't connected to the Hub) */
|
||||
enabled: boolean;
|
||||
/** @description true: show the buttons disabled until `renewsOn` */
|
||||
capReached: boolean;
|
||||
/** @description false: the Hub couldn't be reached just now */
|
||||
available: boolean;
|
||||
/** @description The monthly allowance, in cents */
|
||||
capCents: number;
|
||||
/** @description Used this month, in cents (fractions of a cent) */
|
||||
usedCents: number;
|
||||
usedPercent: number;
|
||||
/** @description YYYY-MM-DD */
|
||||
renewsOn: string | null;
|
||||
/** @description Each helper switched on or off in Site settings → AI */
|
||||
helpers: {
|
||||
draft_event: boolean;
|
||||
summarise_report: boolean;
|
||||
draft_message: boolean;
|
||||
summarise_feedback: boolean;
|
||||
improve_text: boolean;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
/** @description Validation failed (VALIDATION_FAILED) */
|
||||
400: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
/** @description Not signed in (UNAUTHENTICATED) */
|
||||
401: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
/** @description Not allowed for this role (FORBIDDEN) */
|
||||
403: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
"postAiImprove-text": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody: {
|
||||
content: {
|
||||
"application/json": {
|
||||
text: string;
|
||||
/**
|
||||
* @default improve
|
||||
* @enum {string}
|
||||
*/
|
||||
mode?: "improve" | "shorter" | "fix";
|
||||
/**
|
||||
* @default description
|
||||
* @enum {string}
|
||||
*/
|
||||
where?: "description" | "banner" | "message";
|
||||
};
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** @description OK */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": {
|
||||
data: {
|
||||
output: {
|
||||
text: string;
|
||||
changes: string[];
|
||||
};
|
||||
status: {
|
||||
/** @description false: hide the AI buttons (the licence has no AI, or the site isn't connected to the Hub) */
|
||||
enabled: boolean;
|
||||
/** @description true: show the buttons disabled until `renewsOn` */
|
||||
capReached: boolean;
|
||||
/** @description false: the Hub couldn't be reached just now */
|
||||
available: boolean;
|
||||
/** @description The monthly allowance, in cents */
|
||||
capCents: number;
|
||||
/** @description Used this month, in cents (fractions of a cent) */
|
||||
usedCents: number;
|
||||
usedPercent: number;
|
||||
/** @description YYYY-MM-DD */
|
||||
renewsOn: string | null;
|
||||
/** @description Each helper switched on or off in Site settings → AI */
|
||||
helpers: {
|
||||
draft_event: boolean;
|
||||
summarise_report: boolean;
|
||||
draft_message: boolean;
|
||||
summarise_feedback: boolean;
|
||||
improve_text: boolean;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
/** @description Validation failed (VALIDATION_FAILED) */
|
||||
400: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
/** @description Not signed in (UNAUTHENTICATED) */
|
||||
401: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
/** @description Not allowed for this role (FORBIDDEN) */
|
||||
403: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user