hosting23-mcp 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,626 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { z } from 'zod';
3
+ import { quoted, seg, shown, tool } from './types.js';
4
+ // Task 81.6: manage what the customer already has. FR-163: anything that spends money, ends or
5
+ // deletes something, sends mail or web traffic somewhere else (DNS, nameservers, forwarders,
6
+ // catch-all), or makes the account less private asks the customer in a confirmation box first.
7
+ // The box shows every value the AI chose, flattened to one line (`quoted`), so a prompt hidden in
8
+ // a ticket or a DNS record cannot dress up what is being agreed to. A client that cannot show a
9
+ // box is refused and sent to the website. Not here on purpose: mailbox passwords, transfer codes,
10
+ // unlocking a domain, handing a domain to someone else (all website only).
11
+ const uuid = z.string().uuid();
12
+ const id = z.string().min(1).max(100);
13
+ const domainName = z.string().min(3).max(253);
14
+ const emailService = uuid
15
+ .optional()
16
+ .describe('Which email plan, when the account has more than one (from hosting23_email_overview). Leave out for the newest.');
17
+ /** Asks the customer. Null means go ahead; anything else is the tool's answer. */
18
+ async function confirmed(ctx, message, website) {
19
+ const answer = await ctx.confirm(message);
20
+ if (answer === 'yes')
21
+ return null;
22
+ if (answer === 'no')
23
+ return { done: false, reason: 'The customer did not confirm.' };
24
+ return {
25
+ done: false,
26
+ reason: "This chat app can't show a confirmation box, so the customer does this on the website.",
27
+ website,
28
+ };
29
+ }
30
+ const page = (api, path) => `${api.siteUrl}${path}`;
31
+ const emailHeaders = (svc) => svc === undefined ? {} : { 'x-email-service': svc };
32
+ async function serviceName(api, serviceId) {
33
+ const s = await api.get(`/me/services/${seg(serviceId)}`);
34
+ return shown(s.name ?? 'this service', 80);
35
+ }
36
+ async function domainNameOf(api, domainId) {
37
+ const d = await api.get(`/me/domains/${seg(domainId)}`);
38
+ return shown(d.name ?? 'this domain', 80);
39
+ }
40
+ const showRecord = (r) => `${shown(r.type, 8)} ${quoted(r.name)} -> ${quoted(r.value)}${r.priority === undefined || r.priority === null ? '' : ` priority ${String(r.priority)}`} (TTL ${String(r.ttl)})`;
41
+ const done = (result) => ({ done: true, result });
42
+ // ------------------------------------------------------------------------------------ services
43
+ export const serviceManageTools = [
44
+ tool({
45
+ name: 'hosting23_service_request',
46
+ description: 'Ask hosting23 to pause (suspend), cancel, or move the plan of a service (plan_change with targetProductId, or targetDiskGb for a storage plan; see hosting23_service_options). Staff handle the request. The customer confirms in a box first.',
47
+ inputSchema: {
48
+ serviceId: uuid,
49
+ kind: z.enum(['suspend', 'cancel', 'plan_change']),
50
+ targetProductId: uuid.optional(),
51
+ targetDiskGb: z.number().int().min(1).max(1000).optional(),
52
+ note: z.string().max(1000).optional(),
53
+ },
54
+ handler: async (a, api, ctx) => {
55
+ const name = await serviceName(api, a.serviceId);
56
+ const what = a.kind === 'cancel'
57
+ ? `CANCEL ${name}`
58
+ : a.kind === 'suspend'
59
+ ? `pause ${name}`
60
+ : `move ${name} to another plan${a.targetDiskGb === undefined ? '' : ` (${String(a.targetDiskGb)} GB)`}`;
61
+ const stop = await confirmed(ctx, `Ask hosting23 to ${what}?${a.note === undefined ? '' : `\n\nNote to staff: ${quoted(a.note)}`}\n\nStaff will review the request.`, page(api, `/services/${seg(a.serviceId)}`));
62
+ if (stop !== null)
63
+ return stop;
64
+ return done(await api.request('POST', `/me/services/${seg(a.serviceId)}/requests`, {
65
+ body: {
66
+ kind: a.kind,
67
+ targetProductId: a.targetProductId,
68
+ targetDiskGb: a.targetDiskGb,
69
+ note: a.note,
70
+ },
71
+ }));
72
+ },
73
+ }),
74
+ tool({
75
+ name: 'hosting23_withdraw_service_request',
76
+ description: 'Take back a service request nobody has decided yet.',
77
+ inputSchema: { serviceId: uuid, requestId: uuid },
78
+ handler: async (a, api) => done(await api.request('POST', `/me/services/${seg(a.serviceId)}/requests/${seg(a.requestId)}/withdraw`)),
79
+ }),
80
+ tool({
81
+ name: 'hosting23_hosting_set_domain',
82
+ description: 'Set the main domain of a hosting service. source "owned" = a domain on this hosting23 account (its DNS is pointed here automatically); "external" = registered elsewhere (returns the DNS records the customer must set there). The customer confirms in a box first.',
83
+ inputSchema: { serviceId: uuid, domain: domainName, source: z.enum(['owned', 'external']) },
84
+ handler: async (a, api, ctx) => {
85
+ const name = await serviceName(api, a.serviceId);
86
+ const stop = await confirmed(ctx, `Use ${quoted(a.domain)} as the domain of ${name}?` +
87
+ (a.source === 'owned'
88
+ ? "\n\nIts DNS will be changed to point at this hosting. A website or mail already using this domain's current records may stop working."
89
+ : '\n\nYou will then point the domain here at the company where it is registered.'), page(api, `/services/${seg(a.serviceId)}`));
90
+ if (stop !== null)
91
+ return stop;
92
+ return done(await api.request('POST', `/me/services/${seg(a.serviceId)}/domain`, {
93
+ body: { domain: a.domain, source: a.source },
94
+ }));
95
+ },
96
+ }),
97
+ tool({
98
+ name: 'hosting23_hosting_check_domain',
99
+ description: 'For a hosting service waiting on its domain: check whether the domain points here yet (changes nothing), or with `activate: true` check and switch the hosting on if it does.',
100
+ inputSchema: { serviceId: uuid, activate: z.boolean().optional() },
101
+ handler: async (a, api) => api.request('POST', `/me/services/${seg(a.serviceId)}/${a.activate === true ? 'verify' : 'check-dns'}`),
102
+ }),
103
+ ];
104
+ // ------------------------------------------------------------------------------------- domains
105
+ export const domainManageTools = [
106
+ tool({
107
+ name: 'hosting23_set_auto_renew',
108
+ description: 'Turn auto-renew on or off for a domain. Turning it off asks the customer first (the domain can expire).',
109
+ inputSchema: { domainId: id, autoRenew: z.boolean() },
110
+ handler: async (a, api, ctx) => {
111
+ if (!a.autoRenew) {
112
+ const name = await domainNameOf(api, a.domainId);
113
+ const stop = await confirmed(ctx, `Turn OFF auto-renew for ${name}?\n\nIf it is not renewed by hand, the domain will expire and its website and email will stop.`, page(api, '/domains'));
114
+ if (stop !== null)
115
+ return stop;
116
+ }
117
+ return done(await api.request('PATCH', `/me/domains/${seg(a.domainId)}`, {
118
+ body: { autoRenew: a.autoRenew },
119
+ }));
120
+ },
121
+ }),
122
+ tool({
123
+ name: 'hosting23_lock_domain',
124
+ description: 'Switch the transfer lock ON (stops the domain being moved away). Unlocking is only possible on the website.',
125
+ inputSchema: { domainId: id },
126
+ handler: async (a, api) => done(await api.request('PUT', `/me/domains/${seg(a.domainId)}/lock`, {
127
+ body: { locked: true },
128
+ })),
129
+ }),
130
+ tool({
131
+ name: 'hosting23_domain_verification_help',
132
+ description: 'Ask hosting23 staff to resend the registrant verification email for a domain that is waiting to be verified.',
133
+ inputSchema: { domainId: id },
134
+ handler: async (a, api) => done(await api.request('POST', `/me/domains/${seg(a.domainId)}/verification-help`)),
135
+ }),
136
+ tool({
137
+ name: 'hosting23_set_nameservers',
138
+ description: 'Switch a domain between hosting23 DNS ("basic") and custom nameservers ("custom" with 2 to 13 hosts). With custom nameservers the DNS records here stop being used. The customer confirms in a box first.',
139
+ inputSchema: {
140
+ domainId: id,
141
+ provider: z.enum(['basic', 'custom']),
142
+ hosts: z.array(domainName).min(2).max(13).optional(),
143
+ },
144
+ handler: async (a, api, ctx) => {
145
+ const name = await domainNameOf(api, a.domainId);
146
+ const stop = await confirmed(ctx, a.provider === 'custom'
147
+ ? `Hand DNS for ${name} to these nameservers?\n\n${(a.hosts ?? []).map((h) => `- ${quoted(h)}`).join('\n')}\n\nThe website and email will then follow whatever those servers say.`
148
+ : `Switch ${name} back to hosting23 DNS?\n\nThe records kept at hosting23 will be used again.`, page(api, `/domains/${seg(a.domainId)}/dns`));
149
+ if (stop !== null)
150
+ return stop;
151
+ return done(await api.request('PUT', `/me/domains/${seg(a.domainId)}/nameservers`, {
152
+ body: { provider: a.provider, ...(a.hosts === undefined ? {} : { hosts: a.hosts }) },
153
+ }));
154
+ },
155
+ }),
156
+ tool({
157
+ name: 'hosting23_set_domain_privacy',
158
+ description: 'WHOIS privacy for a domain: `level` "high" hides the owner, "public" shows it; `contactForm` true masks the WHOIS email behind a contact form. Making anything public asks the customer first.',
159
+ inputSchema: {
160
+ domainId: id,
161
+ level: z.enum(['high', 'public']).optional(),
162
+ contactForm: z.boolean().optional(),
163
+ },
164
+ handler: async (a, api, ctx) => {
165
+ if (a.level === 'public' || a.contactForm === false) {
166
+ const name = await domainNameOf(api, a.domainId);
167
+ const parts = [
168
+ ...(a.level === 'public' ? ['show the owner details in the public WHOIS'] : []),
169
+ ...(a.contactForm === false ? ['show the owner email address in the public WHOIS'] : []),
170
+ ];
171
+ const stop = await confirmed(ctx, `For ${name}: ${parts.join(' and ')}?\n\nAnyone can read WHOIS, including spammers.`, page(api, '/domains'));
172
+ if (stop !== null)
173
+ return stop;
174
+ }
175
+ const base = `/me/domains/${seg(a.domainId)}`;
176
+ const results = {};
177
+ if (a.level !== undefined) {
178
+ results['privacy'] = await api.request('PUT', `${base}/privacy`, {
179
+ body: { level: a.level },
180
+ });
181
+ }
182
+ if (a.contactForm !== undefined) {
183
+ results['emailProtection'] = await api.request('PUT', `${base}/email-protection`, {
184
+ body: { contactFormEnabled: a.contactForm },
185
+ });
186
+ }
187
+ return done(results);
188
+ },
189
+ }),
190
+ tool({
191
+ name: 'hosting23_add_dns_record',
192
+ description: 'Add a DNS record to a domain registered with hosting23 (types A, AAAA, CNAME, MX, TXT, NS, SRV). The customer confirms in a box first, because DNS decides where the website and email go.',
193
+ inputSchema: {
194
+ domainId: id,
195
+ type: z.enum(['A', 'AAAA', 'CNAME', 'MX', 'TXT', 'NS', 'SRV']),
196
+ name: z
197
+ .string()
198
+ .min(1)
199
+ .max(253)
200
+ .describe('"@" for the domain itself, or a host such as "www".'),
201
+ value: z.string().min(1).max(4000),
202
+ ttl: z.number().int().min(60).max(86400).optional(),
203
+ priority: z.number().int().min(0).max(65535).optional(),
204
+ },
205
+ handler: async (a, api, ctx) => {
206
+ const name = await domainNameOf(api, a.domainId);
207
+ const rec = {
208
+ type: a.type,
209
+ name: a.name,
210
+ value: a.value,
211
+ ttl: a.ttl ?? 3600,
212
+ priority: a.priority,
213
+ };
214
+ const stop = await confirmed(ctx, `Add this DNS record to ${name}?\n\n${showRecord(rec)}`, page(api, `/domains/${seg(a.domainId)}/dns`));
215
+ if (stop !== null)
216
+ return stop;
217
+ return done(await api.request('POST', `/me/domains/${seg(a.domainId)}/dns`, { body: rec }));
218
+ },
219
+ }),
220
+ tool({
221
+ name: 'hosting23_update_dns_record',
222
+ description: 'Change one DNS record (recordId from hosting23_get_dns). Fields left out keep their value. The customer sees the old and new record in a box first.',
223
+ inputSchema: {
224
+ domainId: id,
225
+ recordId: z.string().min(1).max(200),
226
+ name: z.string().min(1).max(253).optional(),
227
+ value: z.string().min(1).max(4000).optional(),
228
+ ttl: z.number().int().min(60).max(86400).optional(),
229
+ priority: z.number().int().min(0).max(65535).optional(),
230
+ },
231
+ handler: async (a, api, ctx) => {
232
+ const base = `/me/domains/${seg(a.domainId)}`;
233
+ const [name, zone] = await Promise.all([
234
+ domainNameOf(api, a.domainId),
235
+ api.get(`${base}/dns`),
236
+ ]);
237
+ const old = zone.find((r) => r.id === a.recordId);
238
+ if (old === undefined)
239
+ return { done: false, reason: 'That record is not in the zone any more.' };
240
+ const next = {
241
+ type: old.type,
242
+ name: a.name ?? old.name,
243
+ value: a.value ?? old.value,
244
+ ttl: a.ttl ?? old.ttl,
245
+ priority: a.priority ?? old.priority ?? undefined,
246
+ };
247
+ const stop = await confirmed(ctx, `Change this DNS record on ${name}?\n\nNow: ${showRecord(old)}\nNew: ${showRecord(next)}`, page(api, `/domains/${seg(a.domainId)}/dns`));
248
+ if (stop !== null)
249
+ return stop;
250
+ return done(await api.request('PATCH', `${base}/dns/${seg(a.recordId)}`, {
251
+ body: { ...next, ...(next.priority === undefined ? {} : { priority: next.priority }) },
252
+ }));
253
+ },
254
+ }),
255
+ tool({
256
+ name: 'hosting23_delete_dns_record',
257
+ description: 'Delete one DNS record (recordId from hosting23_get_dns). The customer sees the record in a box first.',
258
+ inputSchema: { domainId: id, recordId: z.string().min(1).max(200) },
259
+ handler: async (a, api, ctx) => {
260
+ const base = `/me/domains/${seg(a.domainId)}`;
261
+ const [name, zone] = await Promise.all([
262
+ domainNameOf(api, a.domainId),
263
+ api.get(`${base}/dns`),
264
+ ]);
265
+ const old = zone.find((r) => r.id === a.recordId);
266
+ if (old === undefined)
267
+ return { done: false, reason: 'That record is not in the zone any more.' };
268
+ const stop = await confirmed(ctx, `Delete this DNS record from ${name}?\n\n${showRecord(old)}`, page(api, `/domains/${seg(a.domainId)}/dns`));
269
+ if (stop !== null)
270
+ return stop;
271
+ return done(await api.request('DELETE', `${base}/dns/${seg(a.recordId)}`));
272
+ },
273
+ }),
274
+ tool({
275
+ name: 'hosting23_add_mail_dns_records',
276
+ description: "Add the mail DNS records hosting23 business email needs that are missing from a domain's zone. Only hosting23's own records are added.",
277
+ inputSchema: { domainId: id },
278
+ handler: async (a, api) => done(await api.request('POST', `/me/domains/${seg(a.domainId)}/dns/mail-records`)),
279
+ }),
280
+ tool({
281
+ name: 'hosting23_cancel_domain_transfer',
282
+ description: 'Cancel an incoming domain transfer that is waiting on the customer; it is refunded. The customer confirms in a box first.',
283
+ inputSchema: { transferId: uuid },
284
+ handler: async (a, api, ctx) => {
285
+ const stop = await confirmed(ctx, 'Cancel this domain transfer?\n\nThe domain stays where it is now, and the transfer is refunded.', page(api, '/domains'));
286
+ if (stop !== null)
287
+ return stop;
288
+ return done(await api.request('POST', `/me/domain-transfers/${seg(a.transferId)}/cancel`));
289
+ },
290
+ }),
291
+ tool({
292
+ name: 'hosting23_domain_handover',
293
+ description: 'Answer a domain handover invite (from hosting23_list_domains): "accept" (this account becomes the owner) or "decline" an invite received, or "cancel" one this account sent. Accept and decline ask the customer first. Sending a domain to someone else is only possible on the website.',
294
+ inputSchema: { handoverId: uuid, action: z.enum(['accept', 'decline', 'cancel']) },
295
+ handler: async (a, api, ctx) => {
296
+ if (a.action !== 'cancel') {
297
+ const stop = await confirmed(ctx, a.action === 'accept'
298
+ ? 'Accept this domain into your hosting23 account?\n\nYou become its owner and are responsible for renewing it.'
299
+ : 'Turn down this domain handover?\n\nThe domain stays with the account that offered it.', page(api, '/domains'));
300
+ if (stop !== null)
301
+ return stop;
302
+ }
303
+ return done(await api.request('POST', `/me/domain-handovers/${seg(a.handoverId)}/${a.action}`));
304
+ },
305
+ }),
306
+ ];
307
+ // --------------------------------------------------------------------------------------- email
308
+ export const emailManageTools = [
309
+ tool({
310
+ name: 'hosting23_email_add_domain',
311
+ description: 'Add a domain to the business email plan. source "owned" = on this hosting23 account (mail DNS is set up automatically, so the customer confirms in a box first); "external" = registered elsewhere (returns the records to set there).',
312
+ inputSchema: {
313
+ domain: domainName,
314
+ source: z.enum(['owned', 'external']),
315
+ emailServiceId: emailService,
316
+ },
317
+ handler: async (a, api, ctx) => {
318
+ if (a.source === 'owned') {
319
+ const stop = await confirmed(ctx, `Use ${quoted(a.domain)} for business email?\n\nIts mail DNS records (MX and the sending records) will be changed to hosting23 email. Mail now going elsewhere for this domain will start arriving here instead.`, page(api, '/email'));
320
+ if (stop !== null)
321
+ return stop;
322
+ }
323
+ return done(await api.request('POST', '/me/email/domains', {
324
+ body: { domain: a.domain, source: a.source },
325
+ headers: emailHeaders(a.emailServiceId),
326
+ }));
327
+ },
328
+ }),
329
+ tool({
330
+ name: 'hosting23_email_remove_domain',
331
+ description: 'Remove a domain from the business email plan, with all its mailboxes and their mail. The customer confirms in a box first.',
332
+ inputSchema: { domain: domainName, emailServiceId: emailService },
333
+ handler: async (a, api, ctx) => {
334
+ const stop = await confirmed(ctx, `Remove ${quoted(a.domain)} from business email?\n\nIts mailboxes and the mail in them are deleted. This cannot be undone.`, page(api, '/email'));
335
+ if (stop !== null)
336
+ return stop;
337
+ return done(await api.request('DELETE', '/me/email/domains', {
338
+ query: { domain: a.domain },
339
+ headers: emailHeaders(a.emailServiceId),
340
+ }));
341
+ },
342
+ }),
343
+ tool({
344
+ name: 'hosting23_create_mailbox',
345
+ description: 'Create a mailbox. It is made with a long random password that is never shown in the chat; the customer then sets their own password for it on the hosting23 website before using it.',
346
+ inputSchema: {
347
+ domain: domainName,
348
+ localPart: z
349
+ .string()
350
+ .regex(/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/)
351
+ .describe('The part before @.'),
352
+ quotaMb: z.number().int().min(1).max(1_000_000).optional(),
353
+ sendLimitPerDay: z.number().int().min(1).max(100_000).optional(),
354
+ emailServiceId: emailService,
355
+ },
356
+ handler: async (a, api) => {
357
+ // Made here and dropped straight after: never returned, logged or saved.
358
+ const password = `${randomBytes(24).toString('base64url')}aA1!`;
359
+ const result = await api.request('POST', '/me/email/mailboxes', {
360
+ body: {
361
+ domain: a.domain,
362
+ localPart: a.localPart,
363
+ password,
364
+ ...(a.quotaMb === undefined ? {} : { quotaMb: a.quotaMb }),
365
+ ...(a.sendLimitPerDay === undefined ? {} : { sendLimitPerDay: a.sendLimitPerDay }),
366
+ },
367
+ headers: emailHeaders(a.emailServiceId),
368
+ });
369
+ return {
370
+ done: true,
371
+ result,
372
+ next: `The mailbox has a random password nobody knows. Ask the customer to set their own on the website: ${page(api, '/email')}`,
373
+ };
374
+ },
375
+ }),
376
+ tool({
377
+ name: 'hosting23_update_mailbox',
378
+ description: "Change a mailbox's size (quotaMb) or daily send limit. Passwords are changed on the website only.",
379
+ inputSchema: {
380
+ domain: domainName,
381
+ localPart: z.string().min(1).max(64),
382
+ quotaMb: z.number().int().min(1).max(1_000_000).optional(),
383
+ sendLimitPerDay: z.number().int().min(1).max(100_000).optional(),
384
+ emailServiceId: emailService,
385
+ },
386
+ handler: async (a, api) => done(await api.request('POST', '/me/email/mailboxes/update', {
387
+ body: {
388
+ domain: a.domain,
389
+ localPart: a.localPart,
390
+ ...(a.quotaMb === undefined ? {} : { quotaMb: a.quotaMb }),
391
+ ...(a.sendLimitPerDay === undefined ? {} : { sendLimitPerDay: a.sendLimitPerDay }),
392
+ },
393
+ headers: emailHeaders(a.emailServiceId),
394
+ })),
395
+ }),
396
+ tool({
397
+ name: 'hosting23_delete_mailbox',
398
+ description: 'Delete a mailbox and all its mail. The customer confirms in a box first.',
399
+ inputSchema: { address: z.string().email().max(254), emailServiceId: emailService },
400
+ handler: async (a, api, ctx) => {
401
+ const stop = await confirmed(ctx, `Delete the mailbox ${quoted(a.address)} and all its mail?\n\nThis cannot be undone.`, page(api, '/email'));
402
+ if (stop !== null)
403
+ return stop;
404
+ return done(await api.request('DELETE', '/me/email/mailboxes', {
405
+ query: { address: a.address },
406
+ headers: emailHeaders(a.emailServiceId),
407
+ }));
408
+ },
409
+ }),
410
+ tool({
411
+ name: 'hosting23_add_forwarder',
412
+ description: 'Forward mail for alias@domain to one or more addresses. The customer sees every destination in a box first, because forwarding sends their mail somewhere else.',
413
+ inputSchema: {
414
+ domain: domainName,
415
+ alias: z.string().min(1).max(64),
416
+ destinations: z.array(z.string().email().max(254)).min(1).max(20),
417
+ emailServiceId: emailService,
418
+ },
419
+ handler: async (a, api, ctx) => {
420
+ const stop = await confirmed(ctx, `Forward mail sent to ${quoted(`${a.alias}@${a.domain}`)} to:\n\n${a.destinations.map((d) => `- ${quoted(d)}`).join('\n')}\n\nEveryone listed will receive that mail.`, page(api, '/email'));
421
+ if (stop !== null)
422
+ return stop;
423
+ return done(await api.request('POST', '/me/email/forwarders', {
424
+ body: { domain: a.domain, alias: a.alias, destinations: a.destinations },
425
+ headers: emailHeaders(a.emailServiceId),
426
+ }));
427
+ },
428
+ }),
429
+ tool({
430
+ name: 'hosting23_delete_forwarder',
431
+ description: 'Delete a forwarder. The customer confirms in a box first.',
432
+ inputSchema: {
433
+ domain: domainName,
434
+ alias: z.string().min(1).max(64),
435
+ emailServiceId: emailService,
436
+ },
437
+ handler: async (a, api, ctx) => {
438
+ const stop = await confirmed(ctx, `Delete the forwarder for ${quoted(`${a.alias}@${a.domain}`)}?\n\nMail to that address will no longer be forwarded.`, page(api, '/email'));
439
+ if (stop !== null)
440
+ return stop;
441
+ return done(await api.request('DELETE', '/me/email/forwarders', {
442
+ query: { domain: a.domain, alias: a.alias },
443
+ headers: emailHeaders(a.emailServiceId),
444
+ }));
445
+ },
446
+ }),
447
+ tool({
448
+ name: 'hosting23_set_catch_all',
449
+ description: 'What happens to mail for addresses that do not exist on a domain: "reject" it, drop it silently ("blackhole"), or deliver it to one `address`. The customer confirms in a box first.',
450
+ inputSchema: {
451
+ domain: domainName,
452
+ mode: z.enum(['reject', 'blackhole', 'address']),
453
+ address: z.string().email().max(254).optional(),
454
+ emailServiceId: emailService,
455
+ },
456
+ handler: async (a, api, ctx) => {
457
+ const what = a.mode === 'address'
458
+ ? `deliver it to ${quoted(a.address ?? '')}`
459
+ : a.mode === 'blackhole'
460
+ ? 'drop it without telling the sender'
461
+ : 'send it back to the sender';
462
+ const stop = await confirmed(ctx, `For ${quoted(a.domain)}: mail to addresses that do not exist will ${what}. Go ahead?`, page(api, '/email'));
463
+ if (stop !== null)
464
+ return stop;
465
+ return done(await api.request('POST', '/me/email/catch-all', {
466
+ body: {
467
+ domain: a.domain,
468
+ mode: a.mode,
469
+ ...(a.address === undefined ? {} : { address: a.address }),
470
+ },
471
+ headers: emailHeaders(a.emailServiceId),
472
+ }));
473
+ },
474
+ }),
475
+ tool({
476
+ name: 'hosting23_set_mail_delivery',
477
+ description: 'Pause or resume mail delivery for a domain without deleting anything. Pausing asks the customer first.',
478
+ inputSchema: { domain: domainName, enabled: z.boolean(), emailServiceId: emailService },
479
+ handler: async (a, api, ctx) => {
480
+ if (!a.enabled) {
481
+ const stop = await confirmed(ctx, `Pause mail for ${quoted(a.domain)}?\n\nNo mail is delivered to its mailboxes until it is resumed.`, page(api, '/email'));
482
+ if (stop !== null)
483
+ return stop;
484
+ }
485
+ return done(await api.request('POST', '/me/email/mail-status', {
486
+ body: { domain: a.domain, enabled: a.enabled },
487
+ headers: emailHeaders(a.emailServiceId),
488
+ }));
489
+ },
490
+ }),
491
+ tool({
492
+ name: 'hosting23_email_spam',
493
+ description: 'Spam filter for a domain: set `highScore` (the score above which mail counts as spam), or add/remove an `entry` (address or domain) on the allow ("whitelist") or block ("blacklist") list. Adding to the allow list asks the customer first.',
494
+ inputSchema: {
495
+ domain: domainName,
496
+ highScore: z.number().min(1).max(100).optional(),
497
+ list: z.enum(['whitelist', 'blacklist']).optional(),
498
+ entry: z.string().min(1).max(254).optional(),
499
+ remove: z.boolean().optional(),
500
+ emailServiceId: emailService,
501
+ },
502
+ handler: async (a, api, ctx) => {
503
+ const headers = emailHeaders(a.emailServiceId);
504
+ const out = {};
505
+ if (a.highScore !== undefined) {
506
+ out['settings'] = await api.request('POST', '/me/email/spam/settings', {
507
+ body: { domain: a.domain, highScore: a.highScore },
508
+ headers,
509
+ });
510
+ }
511
+ if (a.list !== undefined && a.entry !== undefined) {
512
+ if (a.list === 'whitelist' && a.remove !== true) {
513
+ // An allowed sender skips the spam filter: a favourite of phishing instructions.
514
+ const stop = await confirmed(ctx, `Let all mail from ${quoted(a.entry)} skip the spam filter for ${quoted(a.domain)}?`, page(api, '/email'));
515
+ if (stop !== null)
516
+ return stop;
517
+ }
518
+ out['entry'] =
519
+ a.remove === true
520
+ ? await api.request('DELETE', '/me/email/spam/entries', {
521
+ query: { domain: a.domain, list: a.list, entry: a.entry },
522
+ headers,
523
+ })
524
+ : await api.request('POST', '/me/email/spam/entries', {
525
+ body: { domain: a.domain, list: a.list, entry: a.entry },
526
+ headers,
527
+ });
528
+ }
529
+ if (Object.keys(out).length === 0)
530
+ return { done: false, reason: 'Nothing to change: give highScore, or list and entry.' };
531
+ return done(out);
532
+ },
533
+ }),
534
+ tool({
535
+ name: 'hosting23_email_pointer',
536
+ description: 'Point another domain at an email domain (mail to the pointer domain lands in the same mailboxes), or with `remove: true` take a pointer away. Both ask the customer first.',
537
+ inputSchema: {
538
+ domain: domainName,
539
+ pointer: domainName,
540
+ isAlias: z.boolean().optional(),
541
+ remove: z.boolean().optional(),
542
+ emailServiceId: emailService,
543
+ },
544
+ handler: async (a, api, ctx) => {
545
+ const headers = emailHeaders(a.emailServiceId);
546
+ if (a.remove === true) {
547
+ const stop = await confirmed(ctx, `Stop pointing ${quoted(a.pointer)} at ${quoted(a.domain)}?\n\nMail to ${quoted(a.pointer)} will no longer arrive in these mailboxes.`, page(api, '/email'));
548
+ if (stop !== null)
549
+ return stop;
550
+ return done(await api.request('DELETE', '/me/email/pointers', {
551
+ query: { domain: a.domain, pointer: a.pointer },
552
+ headers,
553
+ }));
554
+ }
555
+ const stop = await confirmed(ctx, `Point ${quoted(a.pointer)} at ${quoted(a.domain)}?\n\nMail sent to ${quoted(a.pointer)} will arrive in the mailboxes of ${quoted(a.domain)}.`, page(api, '/email'));
556
+ if (stop !== null)
557
+ return stop;
558
+ return done(await api.request('POST', '/me/email/pointers', {
559
+ body: {
560
+ domain: a.domain,
561
+ pointer: a.pointer,
562
+ ...(a.isAlias === undefined ? {} : { isAlias: a.isAlias }),
563
+ },
564
+ headers,
565
+ }));
566
+ },
567
+ }),
568
+ tool({
569
+ name: 'hosting23_email_certificate',
570
+ description: "For an email domain using its own mail names (mail.example.com): check them now, or with `request: true` ask for Let's Encrypt certificates for them.",
571
+ inputSchema: {
572
+ domain: domainName,
573
+ request: z.boolean().optional(),
574
+ emailServiceId: emailService,
575
+ },
576
+ handler: async (a, api) => done(await api.request('POST', a.request === true
577
+ ? `/me/email/domains/${seg(a.domain)}/ssl`
578
+ : `/me/email/own-names/${seg(a.domain)}/check`, { headers: emailHeaders(a.emailServiceId) })),
579
+ }),
580
+ ];
581
+ // ------------------------------------------------------------------------------------- support
582
+ export const supportManageTools = [
583
+ tool({
584
+ name: 'hosting23_open_ticket',
585
+ description: 'Open a support ticket (department from hosting23_ticket_departments). Write it as the customer would, and never put passwords, codes or keys in it.',
586
+ inputSchema: {
587
+ departmentId: uuid,
588
+ subject: z.string().min(1).max(200),
589
+ body: z.string().min(1).max(20_000),
590
+ priority: z.enum(['low', 'normal', 'high']).optional(),
591
+ relatedServiceId: uuid.optional(),
592
+ relatedInvoiceId: uuid.optional(),
593
+ },
594
+ handler: async (a, api) => done(await api.request('POST', '/me/tickets', {
595
+ body: {
596
+ departmentId: a.departmentId,
597
+ subject: a.subject,
598
+ body: a.body,
599
+ ...(a.priority === undefined ? {} : { priority: a.priority }),
600
+ ...(a.relatedServiceId === undefined ? {} : { relatedServiceId: a.relatedServiceId }),
601
+ ...(a.relatedInvoiceId === undefined ? {} : { relatedInvoiceId: a.relatedInvoiceId }),
602
+ },
603
+ })),
604
+ }),
605
+ tool({
606
+ name: 'hosting23_reply_ticket',
607
+ description: 'Reply to a support ticket. Never put passwords, codes or keys in it.',
608
+ inputSchema: { ticketId: uuid, body: z.string().min(1).max(20_000) },
609
+ handler: async (a, api) => done(await api.request('POST', `/me/tickets/${seg(a.ticketId)}/replies`, {
610
+ body: { body: a.body },
611
+ })),
612
+ }),
613
+ tool({
614
+ name: 'hosting23_close_ticket',
615
+ description: 'Close a support ticket the customer no longer needs.',
616
+ inputSchema: { ticketId: uuid },
617
+ handler: async (a, api) => done(await api.request('POST', `/me/tickets/${seg(a.ticketId)}/close`)),
618
+ }),
619
+ ];
620
+ export const manageTools = [
621
+ ...serviceManageTools,
622
+ ...domainManageTools,
623
+ ...emailManageTools,
624
+ ...supportManageTools,
625
+ ];
626
+ //# sourceMappingURL=manage-tools.js.map