WIP 2.0.0: AI helper plumbing (status, usage, Site settings -> AI)
The site calls AI through the Hub (protocol 3b, Hub 1.6.0): src/ai works out whether the AI buttons show (licence token first, then the Hub, cached a minute), runs a helper call with per-helper switches and a per-person daily limit, logs AiCall rows, and emails admins at 80%. v2 /ai/status, /ai/usage, /ai/settings; useAiStatus, AiButton, AiTab. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -97,6 +97,9 @@
|
||||
},
|
||||
{
|
||||
"name": "Webhooks"
|
||||
},
|
||||
{
|
||||
"name": "AI"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
@@ -39939,6 +39942,548 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/ai/status": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"AI"
|
||||
],
|
||||
"summary": "Whether to show the AI buttons",
|
||||
"description": "Hidden when `enabled` is false; shown but disabled when `capReached` (until `renewsOn`, or until the allowance is raised). Cached for a minute; every AI call refreshes it.\n\n**Who:** Supervisors and admins.",
|
||||
"operationId": "getAiStatus",
|
||||
"security": [
|
||||
{
|
||||
"bearerAuth": []
|
||||
}
|
||||
],
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"enabled": {
|
||||
"type": "boolean",
|
||||
"description": "false: hide the AI buttons (the licence has no AI, or the site isn't connected to the Hub)"
|
||||
},
|
||||
"capReached": {
|
||||
"type": "boolean",
|
||||
"description": "true: show the buttons disabled until `renewsOn`"
|
||||
},
|
||||
"available": {
|
||||
"type": "boolean",
|
||||
"description": "false: the Hub couldn't be reached just now"
|
||||
},
|
||||
"capCents": {
|
||||
"type": "number",
|
||||
"description": "The monthly allowance, in cents"
|
||||
},
|
||||
"usedCents": {
|
||||
"type": "number",
|
||||
"description": "Used this month, in cents (fractions of a cent)"
|
||||
},
|
||||
"usedPercent": {
|
||||
"type": "number"
|
||||
},
|
||||
"renewsOn": {
|
||||
"description": "YYYY-MM-DD",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"helpers": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"draft_event": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"summarise_report": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"draft_message": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"summarise_feedback": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"improve_text": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"draft_event",
|
||||
"summarise_report",
|
||||
"draft_message",
|
||||
"summarise_feedback",
|
||||
"improve_text"
|
||||
],
|
||||
"additionalProperties": false,
|
||||
"description": "Each helper switched on or off in Site settings → AI"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"enabled",
|
||||
"capReached",
|
||||
"available",
|
||||
"capCents",
|
||||
"usedCents",
|
||||
"usedPercent",
|
||||
"renewsOn",
|
||||
"helpers"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"data"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Not signed in (UNAUTHENTICATED)",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "Not allowed for this role (FORBIDDEN)",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/ai/usage": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"AI"
|
||||
],
|
||||
"summary": "AI use this month",
|
||||
"description": "For Site settings → AI: the allowance, this site's switches, and this month's use per person, per helper and per day.\n\n**Who:** Admins only.",
|
||||
"operationId": "getAiUsage",
|
||||
"security": [
|
||||
{
|
||||
"bearerAuth": []
|
||||
}
|
||||
],
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"status": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"enabled": {
|
||||
"type": "boolean",
|
||||
"description": "false: hide the AI buttons (the licence has no AI, or the site isn't connected to the Hub)"
|
||||
},
|
||||
"capReached": {
|
||||
"type": "boolean",
|
||||
"description": "true: show the buttons disabled until `renewsOn`"
|
||||
},
|
||||
"available": {
|
||||
"type": "boolean",
|
||||
"description": "false: the Hub couldn't be reached just now"
|
||||
},
|
||||
"capCents": {
|
||||
"type": "number",
|
||||
"description": "The monthly allowance, in cents"
|
||||
},
|
||||
"usedCents": {
|
||||
"type": "number",
|
||||
"description": "Used this month, in cents (fractions of a cent)"
|
||||
},
|
||||
"usedPercent": {
|
||||
"type": "number"
|
||||
},
|
||||
"renewsOn": {
|
||||
"description": "YYYY-MM-DD",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"helpers": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"draft_event": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"summarise_report": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"draft_message": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"summarise_feedback": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"improve_text": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"draft_event",
|
||||
"summarise_report",
|
||||
"draft_message",
|
||||
"summarise_feedback",
|
||||
"improve_text"
|
||||
],
|
||||
"additionalProperties": false,
|
||||
"description": "Each helper switched on or off in Site settings → AI"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"enabled",
|
||||
"capReached",
|
||||
"available",
|
||||
"capCents",
|
||||
"usedCents",
|
||||
"usedPercent",
|
||||
"renewsOn",
|
||||
"helpers"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"settings": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"helpers": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"draft_event": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"summarise_report": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"draft_message": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"summarise_feedback": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"improve_text": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"draft_event",
|
||||
"summarise_report",
|
||||
"draft_message",
|
||||
"summarise_feedback",
|
||||
"improve_text"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"dailyLimitPerPerson": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 1000,
|
||||
"description": "0 = no limit"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"helpers",
|
||||
"dailyLimitPerPerson"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"people": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"uses": {
|
||||
"type": "integer",
|
||||
"minimum": -9007199254740991,
|
||||
"maximum": 9007199254740991
|
||||
},
|
||||
"chargedCents": {
|
||||
"type": "number"
|
||||
},
|
||||
"userId": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"uses",
|
||||
"chargedCents",
|
||||
"userId",
|
||||
"name"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"helpers": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"uses": {
|
||||
"type": "integer",
|
||||
"minimum": -9007199254740991,
|
||||
"maximum": 9007199254740991
|
||||
},
|
||||
"chargedCents": {
|
||||
"type": "number"
|
||||
},
|
||||
"helper": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"uses",
|
||||
"chargedCents",
|
||||
"helper"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"days": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"uses": {
|
||||
"type": "integer",
|
||||
"minimum": -9007199254740991,
|
||||
"maximum": 9007199254740991
|
||||
},
|
||||
"chargedCents": {
|
||||
"type": "number"
|
||||
},
|
||||
"day": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"uses",
|
||||
"chargedCents",
|
||||
"day"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"status",
|
||||
"settings",
|
||||
"people",
|
||||
"helpers",
|
||||
"days"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"data"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Not signed in (UNAUTHENTICATED)",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "Not allowed for this role (FORBIDDEN)",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/ai/settings": {
|
||||
"put": {
|
||||
"tags": [
|
||||
"AI"
|
||||
],
|
||||
"summary": "Switch helpers on or off, and set a daily limit",
|
||||
"description": "**Who:** Admins only.",
|
||||
"operationId": "putAiSettings",
|
||||
"security": [
|
||||
{
|
||||
"bearerAuth": []
|
||||
}
|
||||
],
|
||||
"parameters": [],
|
||||
"requestBody": {
|
||||
"required": true,
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"helpers": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"draft_event": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"summarise_report": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"draft_message": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"summarise_feedback": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"improve_text": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dailyLimitPerPerson": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 1000
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"helpers": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"draft_event": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"summarise_report": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"draft_message": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"summarise_feedback": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"improve_text": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"draft_event",
|
||||
"summarise_report",
|
||||
"draft_message",
|
||||
"summarise_feedback",
|
||||
"improve_text"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"dailyLimitPerPerson": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 1000,
|
||||
"description": "0 = no limit"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"helpers",
|
||||
"dailyLimitPerPerson"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"data"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Validation failed (VALIDATION_FAILED)",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Not signed in (UNAUTHENTICATED)",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "Not allowed for this role (FORBIDDEN)",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
@@ -39973,6 +40518,7 @@
|
||||
"CONFLICT",
|
||||
"RATE_LIMITED",
|
||||
"READ_ONLY",
|
||||
"UNAVAILABLE",
|
||||
"INTERNAL"
|
||||
]
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user