Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018BAUeCFpDkRD6tU5wGsc1C
49 lines
1.8 KiB
TypeScript
49 lines
1.8 KiB
TypeScript
import { SubscriptionService } from '../../services/subscription.service';
|
|
import { actorPlan } from '@domain/services/capability-access';
|
|
import { Capability } from '../capability';
|
|
|
|
/**
|
|
* Compte et abonnement.
|
|
*
|
|
* `whoami` n'est pas un gadget : c'est ce qui permet a un agent d'annoncer
|
|
* honnetement ce qu'il peut faire, au lieu de proposer une action puis de se
|
|
* heurter a un refus.
|
|
*/
|
|
export function accountCapabilities(subscriptions: SubscriptionService): Capability[] {
|
|
return [
|
|
{
|
|
policy: { name: 'whoami', scope: 'read' },
|
|
description:
|
|
"Identité de l'appelant : identifiant, organisation, rôle et offre effective. À appeler en premier pour savoir ce qui est permis.",
|
|
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
handler: async (_input, actor) => ({
|
|
userId: actor.id,
|
|
organizationId: actor.organizationId,
|
|
role: actor.role,
|
|
plan: actorPlan(actor),
|
|
}),
|
|
},
|
|
|
|
{
|
|
policy: { name: 'get_subscription', scope: 'read', roles: ['ADMIN', 'MANAGER'] },
|
|
description:
|
|
"Abonnement de l'organisation : offre, statut, licences utilisées et disponibles. Réservé aux rôles ADMIN et MANAGER.",
|
|
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
handler: async (_input, actor) => {
|
|
const overview = await subscriptions.getSubscriptionOverview(
|
|
actor.organizationId,
|
|
actor.role
|
|
);
|
|
return {
|
|
plan: overview.plan,
|
|
status: overview.status,
|
|
usedLicenses: overview.usedLicenses,
|
|
maxLicenses: overview.maxLicenses,
|
|
availableLicenses: overview.availableLicenses,
|
|
currentPeriodEnd: overview.currentPeriodEnd,
|
|
};
|
|
},
|
|
},
|
|
];
|
|
}
|