1// Check remaining seats for a licensed SaaS app and open a procurement
2// ticket when availability drops below a threshold.
3//
4// Before publishing: point the `domains` export and the `http.get` URL at
5// your vendor's licensing endpoint, and set the LICENSE_API_KEY config value.
6
7export const input = z.object({
8 app_name: z
9 .string()
10 .min(1)
11 .describe("The licensed application to check, e.g. Figma"),
12 minimum_available_seats: z
13 .number()
14 .int()
15 .min(0)
16 .default(5)
17 .describe("Open a procurement ticket when fewer seats than this remain"),
18});
19
20// Every host the script calls must be declared here; "read" allows GET only.
21export const domains = { "api.example.com": "read" };
22
23export default async function run(params: z.infer<typeof input>) {
24 // **Fetch license usage**
25 // env.LICENSE_API_KEY becomes a config field on the instantiated tool; the
26 // secret is substituted only when the request leaves the sandbox.
27 const response = await http.get("https://api.example.com/v1/licenses", {
28 query: { app: params.app_name },
29 auth: { type: "bearer", token: env.LICENSE_API_KEY },
30 });
31 if (response.status_code === 404) {
32 fail(`No license record for "${params.app_name}" — check the app name.`);
33 }
34 if (response.status_code !== 200) {
35 fail(`License API returned ${response.status_code} — try again later.`);
36 }
37
38 // **Compute availability**
39 const total: number = response.body.total_seats;
40 const used: number = response.body.used_seats;
41 const available = total - used;
42
43 // **Open a ticket when seats run low**
44 if (available >= params.minimum_available_seats) {
45 return `${params.app_name}: ${available} of ${total} seats available — no action needed.`;
46 }
47 const ticket = await risotto.create_ticket({
48 title: `Low license availability: ${params.app_name}`,
49 description:
50 `${params.app_name} has ${available} of ${total} seats left ` +
51 `(threshold: ${params.minimum_available_seats}). ` +
52 `Purchase additional seats or reclaim unused ones.`,
53 });
54 return (
55 `${params.app_name} is low on seats (${available} of ${total} left) — ` +
56 `opened procurement ticket ${ticket.ticket_id}.`
57 );
58}
24 // **Fetch license usage**
25 // env.LICENSE_API_KEY becomes a config field on the instantiated tool; the
26 // secret is substituted only when the request leaves the sandbox.
27 const response = await http.get("https://api.example.com/v1/licenses", {
28 query: { app: params.app_name },
29 auth: { type: "bearer", token: env.LICENSE_API_KEY },
30 });
31 if (response.status_code === 404) {
32 fail(`No license record for "${params.app_name}" — check the app name.`);
33 }
34 if (response.status_code !== 200) {
35 fail(`License API returned ${response.status_code} — try again later.`);
36 }
38 // **Compute availability**
39 const total: number = response.body.total_seats;
40 const used: number = response.body.used_seats;
41 const available = total - used;
43 // **Open a ticket when seats run low**
44 if (available >= params.minimum_available_seats) {
45 return `${params.app_name}: ${available} of ${total} seats available — no action needed.`;
46 }
47 const ticket = await risotto.create_ticket({
48 title: `Low license availability: ${params.app_name}`,
49 description:
50 `${params.app_name} has ${available} of ${total} seats left ` +
51 `(threshold: ${params.minimum_available_seats}). ` +
52 `Purchase additional seats or reclaim unused ones.`,
53 });
54 return (
55 `${params.app_name} is low on seats (${available} of ${total} left) — ` +
56 `opened procurement ticket ${ticket.ticket_id}.`
57 );