@agentdomain/sdk 0.5.0 → 0.6.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.
package/dist/index.js CHANGED
@@ -1,33 +1,33 @@
1
- import { keccak256, toHex, getAddress, } from 'viem';
2
- import { base, baseSepolia } from 'viem/chains';
3
- import { x402Client, x402HTTPClient } from '@x402/core/client';
4
- import { registerExactEvmScheme } from '@x402/evm/exact/client';
5
- import { AGENTDOMAIN_API_BASE_URL, X402_NETWORK } from '@agentdomain/shared/constants';
1
+ import { keccak256, toHex, getAddress, } from "viem";
2
+ import { base, baseSepolia } from "viem/chains";
3
+ import { x402Client, x402HTTPClient } from "@x402/core/client";
4
+ import { registerExactEvmScheme } from "@x402/evm/exact/client";
5
+ import { AGENTDOMAIN_API_BASE_URL, X402_NETWORK, } from "@agentdomain/shared/constants";
6
6
  const EIP3009_TYPES = {
7
7
  TransferWithAuthorization: [
8
- { name: 'from', type: 'address' },
9
- { name: 'to', type: 'address' },
10
- { name: 'value', type: 'uint256' },
11
- { name: 'validAfter', type: 'uint256' },
12
- { name: 'validBefore', type: 'uint256' },
13
- { name: 'nonce', type: 'bytes32' },
8
+ { name: "from", type: "address" },
9
+ { name: "to", type: "address" },
10
+ { name: "value", type: "uint256" },
11
+ { name: "validAfter", type: "uint256" },
12
+ { name: "validBefore", type: "uint256" },
13
+ { name: "nonce", type: "bytes32" },
14
14
  ],
15
15
  };
16
16
  const RENEWAL_VAULT_ABI = [
17
17
  {
18
- type: 'function',
19
- name: 'setAutoRenew',
20
- stateMutability: 'nonpayable',
18
+ type: "function",
19
+ name: "setAutoRenew",
20
+ stateMutability: "nonpayable",
21
21
  inputs: [
22
- { name: 'tokenId', type: 'uint256' },
23
- { name: 'enabled', type: 'bool' },
22
+ { name: "tokenId", type: "uint256" },
23
+ { name: "enabled", type: "bool" },
24
24
  ],
25
25
  outputs: [],
26
26
  },
27
27
  ];
28
28
  export async function createX402PaymentHeaders(response, walletClient) {
29
29
  if (!walletClient.account) {
30
- throw new Error('A connected wallet account is required for x402 payment.');
30
+ throw new Error("A connected wallet account is required for x402 payment.");
31
31
  }
32
32
  const signer = {
33
33
  address: walletClient.account.address,
@@ -65,7 +65,7 @@ export class AgentDomain {
65
65
  this.apiKey = opts?.apiKey;
66
66
  this.walletClient = opts?.walletClient;
67
67
  this.publicClient = opts?.publicClient;
68
- this.network = opts?.network ?? 'base';
68
+ this.network = opts?.network ?? "base";
69
69
  this.renewalVaultAddress = opts?.renewalVaultAddress;
70
70
  }
71
71
  async checkAvailability(name, opts) {
@@ -77,26 +77,26 @@ export class AgentDomain {
77
77
  }
78
78
  async quote(args) {
79
79
  const params = new URLSearchParams();
80
- params.set('preferredName', args.preferredName);
81
- params.set('tld', args.tld);
80
+ params.set("preferredName", args.preferredName);
81
+ params.set("tld", args.tld);
82
82
  if (args.registerBasename !== undefined)
83
- params.set('registerBasename', String(args.registerBasename));
83
+ params.set("registerBasename", String(args.registerBasename));
84
84
  if (args.basenameLabel)
85
- params.set('basenameLabel', args.basenameLabel);
85
+ params.set("basenameLabel", args.basenameLabel);
86
86
  if (args.registerEns !== undefined)
87
- params.set('registerEns', String(args.registerEns));
87
+ params.set("registerEns", String(args.registerEns));
88
88
  if (args.ensLabel)
89
- params.set('ensLabel', args.ensLabel);
89
+ params.set("ensLabel", args.ensLabel);
90
90
  if (args.emailEnabled !== undefined)
91
- params.set('emailEnabled', String(args.emailEnabled));
91
+ params.set("emailEnabled", String(args.emailEnabled));
92
92
  if (args.emailUsername)
93
- params.set('emailUsername', args.emailUsername);
93
+ params.set("emailUsername", args.emailUsername);
94
94
  if (args.premiumPlan)
95
- params.set('premiumPlan', args.premiumPlan);
95
+ params.set("premiumPlan", args.premiumPlan);
96
96
  if (args.premiumPlanSku)
97
- params.set('premiumPlanSku', args.premiumPlanSku);
97
+ params.set("premiumPlanSku", args.premiumPlanSku);
98
98
  if (args.years)
99
- params.set('years', String(args.years));
99
+ params.set("years", String(args.years));
100
100
  const url = `${this.apiUrl}/agents/quote?${params.toString()}`;
101
101
  const res = await fetch(url);
102
102
  if (!res.ok)
@@ -104,47 +104,48 @@ export class AgentDomain {
104
104
  return res.json();
105
105
  }
106
106
  async register(args) {
107
- const walletAddress = (args.wallet || this.walletClient?.account?.address);
107
+ const walletAddress = (args.wallet ||
108
+ this.walletClient?.account?.address);
108
109
  if (!walletAddress) {
109
- throw new Error('Registration requires a wallet address. Pass args.wallet or provide a walletClient with an account.');
110
+ throw new Error("Registration requires a wallet address. Pass args.wallet or provide a walletClient with an account.");
110
111
  }
111
112
  const url = `${this.apiUrl}/agents/register`;
112
113
  const body = JSON.stringify({
113
114
  ...args,
114
115
  wallet: walletAddress,
115
- tld: args.tld ?? 'xyz',
116
+ tld: args.tld ?? "xyz",
116
117
  registerBasename: args.registerBasename ?? true,
117
118
  registerEns: args.registerEns ?? false,
118
119
  emailEnabled: true,
119
- emailUsername: args.emailUsername ?? 'agent',
120
- premiumPlan: args.premiumPlan ?? 'included',
120
+ emailUsername: args.emailUsername ?? "agent",
121
+ premiumPlan: args.premiumPlan ?? "included",
121
122
  years: args.years ?? 1,
122
123
  autoRenew: args.autoRenew ?? false,
123
124
  });
124
125
  let res = await fetch(url, {
125
- method: 'POST',
126
- headers: await this.authHeaders({ 'Content-Type': 'application/json' }),
126
+ method: "POST",
127
+ headers: await this.authHeaders({ "Content-Type": "application/json" }),
127
128
  body,
128
129
  });
129
130
  if (res.status === 402) {
130
131
  if (!this.walletClient || !walletAddress) {
131
- throw new Error('Registration requires x402 payment. Provide a walletClient in AgentDomain constructor so the SDK can sign the USDC authorization.');
132
+ throw new Error("Registration requires x402 payment. Provide a walletClient in AgentDomain constructor so the SDK can sign the USDC authorization.");
132
133
  }
133
- if (this.network !== 'base') {
134
- throw new Error('AgentDomain x402 payments are supported only on Base mainnet.');
134
+ if (this.network !== "base") {
135
+ throw new Error("AgentDomain x402 payments are supported only on Base mainnet.");
135
136
  }
136
137
  const paymentHeaders = await createX402PaymentHeaders(res, this.walletClient);
137
138
  res = await fetch(url, {
138
- method: 'POST',
139
+ method: "POST",
139
140
  headers: await this.authHeaders({
140
- 'Content-Type': 'application/json',
141
+ "Content-Type": "application/json",
141
142
  ...paymentHeaders,
142
143
  }),
143
144
  body,
144
145
  });
145
146
  }
146
147
  if (!res.ok) {
147
- let detail = '';
148
+ let detail = "";
148
149
  try {
149
150
  const errBody = await res.json();
150
151
  detail = `: ${errBody.message ?? JSON.stringify(errBody)}`;
@@ -157,7 +158,7 @@ export class AgentDomain {
157
158
  return res.json();
158
159
  }
159
160
  async buildEip3009Authorization(requirement, from) {
160
- const chain = this.network === 'base-sepolia' ? baseSepolia : base;
161
+ const chain = this.network === "base-sepolia" ? baseSepolia : base;
161
162
  const now = BigInt(Math.floor(Date.now() / 1000));
162
163
  const validBefore = now + BigInt(requirement.maxTimeoutSeconds || 300);
163
164
  const nonce = keccak256(toHex(`${from}:${Date.now()}:${Math.floor(Math.random() * 1e15)}`));
@@ -171,13 +172,13 @@ export class AgentDomain {
171
172
  };
172
173
  const signature = await this.walletClient.signTypedData({
173
174
  domain: {
174
- name: 'USD Coin',
175
- version: '2',
175
+ name: "USD Coin",
176
+ version: "2",
176
177
  chainId: requirement.chainId ?? chain.id,
177
178
  verifyingContract: requirement.asset,
178
179
  },
179
180
  types: EIP3009_TYPES,
180
- primaryType: 'TransferWithAuthorization',
181
+ primaryType: "TransferWithAuthorization",
181
182
  message,
182
183
  });
183
184
  return {
@@ -186,7 +187,7 @@ export class AgentDomain {
186
187
  from,
187
188
  to: requirement.payTo,
188
189
  value: requirement.maxAmountRequired,
189
- validAfter: '0',
190
+ validAfter: "0",
190
191
  validBefore: validBefore.toString(),
191
192
  nonce,
192
193
  },
@@ -216,13 +217,13 @@ export class AgentDomain {
216
217
  async search(args) {
217
218
  const params = new URLSearchParams();
218
219
  if (args.q)
219
- params.set('q', args.q);
220
+ params.set("q", args.q);
220
221
  if (args.framework)
221
- params.set('framework', args.framework);
222
+ params.set("framework", args.framework);
222
223
  if (args.capability)
223
- params.set('capability', args.capability);
224
+ params.set("capability", args.capability);
224
225
  if (args.limit)
225
- params.set('limit', String(args.limit));
226
+ params.set("limit", String(args.limit));
226
227
  const url = `${this.apiUrl}/agents/search?${params.toString()}`;
227
228
  const res = await fetch(url);
228
229
  if (!res.ok)
@@ -232,10 +233,12 @@ export class AgentDomain {
232
233
  async sendEmail(agentId, args) {
233
234
  const url = `${this.apiUrl}/agents/${agentId}/email/send`;
234
235
  const res = await fetch(url, {
235
- method: 'POST',
236
+ method: "POST",
236
237
  headers: await this.authHeaders({
237
- 'Content-Type': 'application/json',
238
- ...(args.idempotencyKey ? { 'Idempotency-Key': args.idempotencyKey } : {}),
238
+ "Content-Type": "application/json",
239
+ ...(args.idempotencyKey
240
+ ? { "Idempotency-Key": args.idempotencyKey }
241
+ : {}),
239
242
  }),
240
243
  body: JSON.stringify(args),
241
244
  });
@@ -245,14 +248,16 @@ export class AgentDomain {
245
248
  }
246
249
  async sendEmailBatch(agentId, args) {
247
250
  const res = await fetch(`${this.apiUrl}/agents/${agentId}/email/batch`, {
248
- method: 'POST',
251
+ method: "POST",
249
252
  headers: await this.authHeaders({
250
- 'Content-Type': 'application/json',
251
- ...(args.idempotencyKey ? { 'Idempotency-Key': args.idempotencyKey } : {}),
253
+ "Content-Type": "application/json",
254
+ ...(args.idempotencyKey
255
+ ? { "Idempotency-Key": args.idempotencyKey }
256
+ : {}),
252
257
  }),
253
258
  body: JSON.stringify({
254
259
  messages: args.messages,
255
- validationMode: args.validationMode ?? 'strict',
260
+ validationMode: args.validationMode ?? "strict",
256
261
  }),
257
262
  });
258
263
  if (!res.ok)
@@ -277,8 +282,8 @@ export class AgentDomain {
277
282
  }
278
283
  async setEmailWebhook(agentId, args) {
279
284
  const res = await fetch(`${this.apiUrl}/agents/${agentId}/email/webhook`, {
280
- method: 'PUT',
281
- headers: await this.authHeaders({ 'Content-Type': 'application/json' }),
285
+ method: "PUT",
286
+ headers: await this.authHeaders({ "Content-Type": "application/json" }),
282
287
  body: JSON.stringify(args),
283
288
  });
284
289
  if (!res.ok)
@@ -287,7 +292,7 @@ export class AgentDomain {
287
292
  }
288
293
  async rotateEmailWebhookSecret(agentId) {
289
294
  const res = await fetch(`${this.apiUrl}/agents/${agentId}/email/webhook`, {
290
- method: 'PATCH',
295
+ method: "PATCH",
291
296
  headers: await this.authHeaders(),
292
297
  });
293
298
  if (!res.ok)
@@ -296,8 +301,8 @@ export class AgentDomain {
296
301
  }
297
302
  async updatePrimaryEmail(agentId, username) {
298
303
  const res = await fetch(`${this.apiUrl}/agents/${agentId}/email`, {
299
- method: 'PATCH',
300
- headers: await this.authHeaders({ 'Content-Type': 'application/json' }),
304
+ method: "PATCH",
305
+ headers: await this.authHeaders({ "Content-Type": "application/json" }),
301
306
  body: JSON.stringify({ username, confirmReplace: true }),
302
307
  });
303
308
  if (!res.ok)
@@ -306,8 +311,8 @@ export class AgentDomain {
306
311
  }
307
312
  async createEmailAlias(agentId, username) {
308
313
  const res = await fetch(`${this.apiUrl}/agents/${agentId}/email/aliases`, {
309
- method: 'POST',
310
- headers: await this.authHeaders({ 'Content-Type': 'application/json' }),
314
+ method: "POST",
315
+ headers: await this.authHeaders({ "Content-Type": "application/json" }),
311
316
  body: JSON.stringify({ username }),
312
317
  });
313
318
  if (!res.ok)
@@ -317,7 +322,7 @@ export class AgentDomain {
317
322
  async deleteEmailAlias(agentId, emailAddress) {
318
323
  const params = new URLSearchParams({ emailAddress });
319
324
  const res = await fetch(`${this.apiUrl}/agents/${agentId}/email/aliases?${params}`, {
320
- method: 'DELETE',
325
+ method: "DELETE",
321
326
  headers: await this.authHeaders(),
322
327
  });
323
328
  if (!res.ok)
@@ -327,9 +332,9 @@ export class AgentDomain {
327
332
  async listEmail(agentId, args = {}) {
328
333
  const params = new URLSearchParams();
329
334
  if (args.limit)
330
- params.set('limit', String(args.limit));
335
+ params.set("limit", String(args.limit));
331
336
  if (args.unreadOnly)
332
- params.set('unreadOnly', 'true');
337
+ params.set("unreadOnly", "true");
333
338
  const url = `${this.apiUrl}/agents/${agentId}/email?${params.toString()}`;
334
339
  const res = await fetch(url, { headers: await this.authHeaders() });
335
340
  if (!res.ok)
@@ -338,7 +343,7 @@ export class AgentDomain {
338
343
  }
339
344
  async deleteEmailMessage(agentId, messageId) {
340
345
  const res = await fetch(`${this.apiUrl}/agents/${agentId}/email/${messageId}`, {
341
- method: 'DELETE',
346
+ method: "DELETE",
342
347
  headers: await this.authHeaders(),
343
348
  });
344
349
  if (!res.ok)
@@ -353,10 +358,18 @@ export class AgentDomain {
353
358
  throw new Error(await responseError(res));
354
359
  return res.json();
355
360
  }
361
+ async getDnsCapabilities(agentId) {
362
+ const res = await fetch(`${this.apiUrl}/agents/${agentId}/dns/capabilities`, {
363
+ headers: await this.authHeaders(),
364
+ });
365
+ if (!res.ok)
366
+ throw new Error(await responseError(res));
367
+ return res.json();
368
+ }
356
369
  async createDnsRecord(agentId, record) {
357
370
  const res = await fetch(`${this.apiUrl}/agents/${agentId}/dns`, {
358
- method: 'POST',
359
- headers: await this.authHeaders({ 'Content-Type': 'application/json' }),
371
+ method: "POST",
372
+ headers: await this.authHeaders({ "Content-Type": "application/json" }),
360
373
  body: JSON.stringify(record),
361
374
  });
362
375
  if (!res.ok)
@@ -365,8 +378,8 @@ export class AgentDomain {
365
378
  }
366
379
  async updateDnsRecord(agentId, recordId, record) {
367
380
  const res = await fetch(`${this.apiUrl}/agents/${agentId}/dns/${recordId}`, {
368
- method: 'PATCH',
369
- headers: await this.authHeaders({ 'Content-Type': 'application/json' }),
381
+ method: "PATCH",
382
+ headers: await this.authHeaders({ "Content-Type": "application/json" }),
370
383
  body: JSON.stringify(record),
371
384
  });
372
385
  if (!res.ok)
@@ -375,9 +388,61 @@ export class AgentDomain {
375
388
  }
376
389
  async deleteDnsRecord(agentId, recordId) {
377
390
  const res = await fetch(`${this.apiUrl}/agents/${agentId}/dns/${recordId}`, {
378
- method: 'DELETE',
391
+ method: "DELETE",
392
+ headers: await this.authHeaders(),
393
+ });
394
+ if (!res.ok)
395
+ throw new Error(await responseError(res));
396
+ return res.json();
397
+ }
398
+ async previewDnsBatch(agentId, records, mode = "merge") {
399
+ return this.sendDnsBatch(agentId, { records, mode, dryRun: true });
400
+ }
401
+ async applyDnsBatch(agentId, records, baseRevision, mode = "merge") {
402
+ assertDnsRevision(baseRevision);
403
+ return this.sendDnsBatch(agentId, {
404
+ records,
405
+ mode,
406
+ dryRun: false,
407
+ baseRevision,
408
+ });
409
+ }
410
+ async previewDnsImport(agentId, zoneFile, mode = "merge") {
411
+ return this.sendDnsImport(agentId, { zoneFile, mode, dryRun: true });
412
+ }
413
+ async applyDnsImport(agentId, zoneFile, baseRevision, mode = "merge") {
414
+ assertDnsRevision(baseRevision);
415
+ return this.sendDnsImport(agentId, {
416
+ zoneFile,
417
+ mode,
418
+ dryRun: false,
419
+ baseRevision,
420
+ });
421
+ }
422
+ async exportDnsZone(agentId, scope = "user") {
423
+ const res = await fetch(`${this.apiUrl}/agents/${agentId}/dns/export?scope=${scope}`, {
379
424
  headers: await this.authHeaders(),
380
425
  });
426
+ if (!res.ok)
427
+ throw new Error(await responseError(res));
428
+ return res.text();
429
+ }
430
+ async sendDnsBatch(agentId, payload) {
431
+ const res = await fetch(`${this.apiUrl}/agents/${agentId}/dns/batch`, {
432
+ method: "POST",
433
+ headers: await this.authHeaders({ "Content-Type": "application/json" }),
434
+ body: JSON.stringify(payload),
435
+ });
436
+ if (!res.ok)
437
+ throw new Error(await responseError(res));
438
+ return res.json();
439
+ }
440
+ async sendDnsImport(agentId, payload) {
441
+ const res = await fetch(`${this.apiUrl}/agents/${agentId}/dns/import`, {
442
+ method: "POST",
443
+ headers: await this.authHeaders({ "Content-Type": "application/json" }),
444
+ body: JSON.stringify(payload),
445
+ });
381
446
  if (!res.ok)
382
447
  throw new Error(await responseError(res));
383
448
  return res.json();
@@ -385,20 +450,20 @@ export class AgentDomain {
385
450
  async fundRenewalVault(agentId, amountUsdc) {
386
451
  const walletAddress = this.walletClient?.account?.address;
387
452
  if (!this.walletClient || !walletAddress) {
388
- throw new Error('Funding the renewal vault requires a walletClient so the SDK can sign a USDC authorization.');
453
+ throw new Error("Funding the renewal vault requires a walletClient so the SDK can sign a USDC authorization.");
389
454
  }
390
455
  const url = `${this.apiUrl}/agents/${agentId}/renewal/fund`;
391
456
  let res = await fetch(url, {
392
- method: 'POST',
393
- headers: await this.authHeaders({ 'Content-Type': 'application/json' }),
457
+ method: "POST",
458
+ headers: await this.authHeaders({ "Content-Type": "application/json" }),
394
459
  body: JSON.stringify({ amount: amountUsdc }),
395
460
  });
396
461
  if (res.status === 402) {
397
462
  const challenge = (await res.json());
398
463
  const authorization = await this.buildEip3009Authorization(challenge, walletAddress);
399
464
  res = await fetch(url, {
400
- method: 'POST',
401
- headers: await this.authHeaders({ 'Content-Type': 'application/json' }),
465
+ method: "POST",
466
+ headers: await this.authHeaders({ "Content-Type": "application/json" }),
402
467
  body: JSON.stringify({
403
468
  amount: amountUsdc,
404
469
  signature: authorization.signature,
@@ -420,17 +485,18 @@ export class AgentDomain {
420
485
  async setAutoRenew(agentId, enabled, opts = {}) {
421
486
  const walletAddress = this.walletClient?.account?.address;
422
487
  if (!this.walletClient || !walletAddress) {
423
- throw new Error('Auto-renew requires a walletClient for the AgentID NFT owner wallet. Any wallet can fund RenewalVault, but only the owner wallet can change auto-renew.');
488
+ throw new Error("Auto-renew requires a walletClient for the AgentID NFT owner wallet. Any wallet can fund RenewalVault, but only the owner wallet can change auto-renew.");
424
489
  }
425
490
  const renewalVaultAddress = opts.renewalVaultAddress ?? this.renewalVaultAddress;
426
491
  if (!renewalVaultAddress) {
427
- throw new Error('renewalVaultAddress is required to enable auto-renew. Pass it to the AgentDomain constructor or setAutoRenew options.');
492
+ throw new Error("renewalVaultAddress is required to enable auto-renew. Pass it to the AgentDomain constructor or setAutoRenew options.");
428
493
  }
429
494
  const status = await this.getRenewalStatus(agentId);
430
495
  if (!status.tokenId) {
431
- throw new Error('Auto-renew cannot be changed before the AgentID NFT is minted.');
496
+ throw new Error("Auto-renew cannot be changed before the AgentID NFT is minted.");
432
497
  }
433
- if (status.ownerAddress && !sameAddress(walletAddress, status.ownerAddress)) {
498
+ if (status.ownerAddress &&
499
+ !sameAddress(walletAddress, status.ownerAddress)) {
434
500
  throw new Error(`Auto-renew can only be changed by the AgentID NFT owner wallet (${status.ownerAddress}).`);
435
501
  }
436
502
  if (status.autoRenewEnabled === enabled) {
@@ -443,13 +509,13 @@ export class AgentDomain {
443
509
  };
444
510
  }
445
511
  if (opts.waitForReceipt && !this.publicClient) {
446
- throw new Error('waitForReceipt requires a publicClient in the AgentDomain constructor.');
512
+ throw new Error("waitForReceipt requires a publicClient in the AgentDomain constructor.");
447
513
  }
448
- const chain = this.network === 'base-sepolia' ? baseSepolia : base;
514
+ const chain = this.network === "base-sepolia" ? baseSepolia : base;
449
515
  const txHash = (await this.walletClient.writeContract({
450
516
  address: renewalVaultAddress,
451
517
  abi: RENEWAL_VAULT_ABI,
452
- functionName: 'setAutoRenew',
518
+ functionName: "setAutoRenew",
453
519
  args: [BigInt(status.tokenId), enabled],
454
520
  account: this.walletClient.account,
455
521
  chain,
@@ -468,8 +534,8 @@ export class AgentDomain {
468
534
  async withdrawFromVault(agentId, amountUsdc) {
469
535
  const url = `${this.apiUrl}/agents/${agentId}/renewal/withdraw`;
470
536
  const res = await fetch(url, {
471
- method: 'POST',
472
- headers: await this.authHeaders({ 'Content-Type': 'application/json' }),
537
+ method: "POST",
538
+ headers: await this.authHeaders({ "Content-Type": "application/json" }),
473
539
  body: JSON.stringify({ amount: amountUsdc }),
474
540
  });
475
541
  if (!res.ok)
@@ -479,7 +545,7 @@ export class AgentDomain {
479
545
  async reconfigureSsl(agentId) {
480
546
  const url = `${this.apiUrl}/agents/${agentId}/ssl`;
481
547
  const res = await fetch(url, {
482
- method: 'POST',
548
+ method: "POST",
483
549
  headers: await this.authHeaders(),
484
550
  });
485
551
  if (!res.ok)
@@ -496,7 +562,7 @@ export class AgentDomain {
496
562
  async purchaseServicePlan(args) {
497
563
  const walletAddress = this.walletClient?.account?.address;
498
564
  if (!this.walletClient || !walletAddress) {
499
- throw new Error('Premium Plan purchase requires a walletClient so the SDK can sign the USDC x402 payment.');
565
+ throw new Error("Premium Plan purchase requires a walletClient so the SDK can sign the USDC x402 payment.");
500
566
  }
501
567
  const url = `${this.apiUrl}/agents/${args.agentId}/plan`;
502
568
  const body = JSON.stringify({
@@ -504,19 +570,19 @@ export class AgentDomain {
504
570
  planSku: args.planSku,
505
571
  });
506
572
  let res = await fetch(url, {
507
- method: 'POST',
508
- headers: await this.authHeaders({ 'Content-Type': 'application/json' }),
573
+ method: "POST",
574
+ headers: await this.authHeaders({ "Content-Type": "application/json" }),
509
575
  body,
510
576
  });
511
577
  if (res.status === 402) {
512
- if (this.network !== 'base') {
513
- throw new Error('AgentDomain x402 payments are supported only on Base mainnet.');
578
+ if (this.network !== "base") {
579
+ throw new Error("AgentDomain x402 payments are supported only on Base mainnet.");
514
580
  }
515
581
  const paymentHeaders = await createX402PaymentHeaders(res, this.walletClient);
516
582
  res = await fetch(url, {
517
- method: 'POST',
583
+ method: "POST",
518
584
  headers: await this.authHeaders({
519
- 'Content-Type': 'application/json',
585
+ "Content-Type": "application/json",
520
586
  ...paymentHeaders,
521
587
  }),
522
588
  body,
@@ -529,8 +595,8 @@ export class AgentDomain {
529
595
  async setRegistryVisibility(agentId, registryHidden) {
530
596
  const url = `${this.apiUrl}/agents/${agentId}/plan`;
531
597
  const res = await fetch(url, {
532
- method: 'PATCH',
533
- headers: await this.authHeaders({ 'Content-Type': 'application/json' }),
598
+ method: "PATCH",
599
+ headers: await this.authHeaders({ "Content-Type": "application/json" }),
534
600
  body: JSON.stringify({ registryHidden }),
535
601
  });
536
602
  if (!res.ok)
@@ -540,8 +606,8 @@ export class AgentDomain {
540
606
  async scheduleServicePlanRenewal(agentId, args) {
541
607
  const planSku = args.planSku ?? args.plan;
542
608
  const res = await fetch(`${this.apiUrl}/agents/${agentId}/plan`, {
543
- method: 'PATCH',
544
- headers: await this.authHeaders({ 'Content-Type': 'application/json' }),
609
+ method: "PATCH",
610
+ headers: await this.authHeaders({ "Content-Type": "application/json" }),
545
611
  body: JSON.stringify({ renewalPlan: args.plan, renewalPlanSku: planSku }),
546
612
  });
547
613
  if (!res.ok)
@@ -560,8 +626,8 @@ export class AgentDomain {
560
626
  }
561
627
  async createApiKey(agentId, name) {
562
628
  const res = await fetch(`${this.apiUrl}/keys`, {
563
- method: 'POST',
564
- headers: await this.authHeaders({ 'Content-Type': 'application/json' }, { useApiKey: false }),
629
+ method: "POST",
630
+ headers: await this.authHeaders({ "Content-Type": "application/json" }, { useApiKey: false }),
565
631
  body: JSON.stringify({ agentId, name }),
566
632
  });
567
633
  if (!res.ok)
@@ -570,7 +636,7 @@ export class AgentDomain {
570
636
  }
571
637
  async revokeApiKey(keyId) {
572
638
  const res = await fetch(`${this.apiUrl}/keys/${keyId}`, {
573
- method: 'DELETE',
639
+ method: "DELETE",
574
640
  headers: await this.authHeaders(undefined, { useApiKey: false }),
575
641
  });
576
642
  if (!res.ok)
@@ -583,7 +649,7 @@ export class AgentDomain {
583
649
  headers.Authorization = `Bearer ${this.apiKey}`;
584
650
  return headers;
585
651
  }
586
- if (!headers['X-Agent-Signature'] && this.walletClient?.account) {
652
+ if (!headers["X-Agent-Signature"] && this.walletClient?.account) {
587
653
  try {
588
654
  const timestamp = Date.now();
589
655
  const message = `agentdomain.app api auth ${timestamp}`;
@@ -591,7 +657,7 @@ export class AgentDomain {
591
657
  account: this.walletClient.account,
592
658
  message,
593
659
  });
594
- headers['X-Agent-Signature'] =
660
+ headers["X-Agent-Signature"] =
595
661
  `${this.walletClient.account.address}:${timestamp}:${signature}`;
596
662
  }
597
663
  catch {
@@ -605,336 +671,399 @@ export class AgentDomain {
605
671
  export function createOpenAITools() {
606
672
  return [
607
673
  {
608
- type: 'function',
674
+ type: "function",
609
675
  function: {
610
- name: 'check_domain_availability',
611
- description: 'Check if a domain name is available for registration',
676
+ name: "check_domain_availability",
677
+ description: "Check if a domain name is available for registration",
612
678
  parameters: {
613
- type: 'object',
679
+ type: "object",
614
680
  properties: {
615
- name: { type: 'string', description: 'Domain name to check' },
616
- tld: { type: 'string', description: 'TLD (e.g. xyz, com, ai)', default: 'xyz' },
681
+ name: { type: "string", description: "Domain name to check" },
682
+ tld: {
683
+ type: "string",
684
+ description: "TLD (e.g. xyz, com, ai)",
685
+ default: "xyz",
686
+ },
617
687
  },
618
- required: ['name'],
688
+ required: ["name"],
619
689
  },
620
690
  },
621
691
  },
622
692
  {
623
- type: 'function',
693
+ type: "function",
624
694
  function: {
625
- name: 'quote_registration',
626
- description: 'Get pricing quote for registering an AI agent identity. Domain, DNS, email, SSL certification, AgentID NFT orchestration, and platform fee are included by default. Basename and ENS are optional.',
695
+ name: "quote_registration",
696
+ description: "Get pricing quote for registering an AI agent identity. Domain, DNS, email, SSL certification, AgentID NFT orchestration, and platform fee are included by default. Basename and ENS are optional.",
627
697
  parameters: {
628
- type: 'object',
698
+ type: "object",
629
699
  properties: {
630
- preferredName: { type: 'string', description: 'Preferred domain name' },
631
- tld: { type: 'string', description: 'TLD', default: 'xyz' },
700
+ preferredName: {
701
+ type: "string",
702
+ description: "Preferred domain name",
703
+ },
704
+ tld: { type: "string", description: "TLD", default: "xyz" },
632
705
  registerBasename: {
633
- type: 'boolean',
634
- description: 'Also register Basename. Set false to skip Basename cost.',
706
+ type: "boolean",
707
+ description: "Also register Basename. Set false to skip Basename cost.",
635
708
  default: true,
636
709
  },
637
710
  basenameLabel: {
638
- type: 'string',
639
- description: 'Optional alternate Basename label. Omit to use preferredName.',
711
+ type: "string",
712
+ description: "Optional alternate Basename label. Omit to use preferredName.",
640
713
  },
641
714
  registerEns: {
642
- type: 'boolean',
643
- description: 'Also register ENS name. Set false to skip ENS cost.',
715
+ type: "boolean",
716
+ description: "Also register ENS name. Set false to skip ENS cost.",
644
717
  default: false,
645
718
  },
646
719
  ensLabel: {
647
- type: 'string',
648
- description: 'Optional alternate ENS label. Omit to use preferredName.',
720
+ type: "string",
721
+ description: "Optional alternate ENS label. Omit to use preferredName.",
649
722
  },
650
723
  emailEnabled: {
651
- type: 'boolean',
652
- description: 'Deprecated compatibility flag. Email is now always included.',
724
+ type: "boolean",
725
+ description: "Deprecated compatibility flag. Email is now always included.",
653
726
  default: true,
654
727
  },
655
728
  emailUsername: {
656
- type: 'string',
657
- description: 'Primary email username. Defaults to agent, producing agent@domain.',
658
- default: 'agent',
729
+ type: "string",
730
+ description: "Primary email username. Defaults to agent, producing agent@domain.",
731
+ default: "agent",
659
732
  },
660
733
  premiumPlan: {
661
- type: 'string',
662
- enum: ['included', 'starter', 'pro', 'enterprise'],
663
- description: 'Premium Plan to buy with registration. Defaults to included.',
664
- default: 'included',
734
+ type: "string",
735
+ enum: ["included", "starter", "pro", "enterprise"],
736
+ description: "Premium Plan to buy with registration. Defaults to included.",
737
+ default: "included",
738
+ },
739
+ years: {
740
+ type: "number",
741
+ description: "Registration years",
742
+ default: 1,
665
743
  },
666
- years: { type: 'number', description: 'Registration years', default: 1 },
667
744
  },
668
- required: ['preferredName'],
745
+ required: ["preferredName"],
669
746
  },
670
747
  },
671
748
  },
672
749
  {
673
- type: 'function',
750
+ type: "function",
674
751
  function: {
675
- name: 'register_agent_identity',
676
- description: 'Register a new AI agent identity. Domain, DNS, email, SSL certification, AgentID NFT orchestration, and platform fee are included by default. Basename and ENS are optional.',
752
+ name: "register_agent_identity",
753
+ description: "Register a new AI agent identity. Domain, DNS, email, SSL certification, AgentID NFT orchestration, and platform fee are included by default. Basename and ENS are optional.",
677
754
  parameters: {
678
- type: 'object',
755
+ type: "object",
679
756
  properties: {
680
- preferredName: { type: 'string', description: 'Domain name' },
681
- tld: { type: 'string', description: 'TLD', default: 'xyz' },
757
+ preferredName: { type: "string", description: "Domain name" },
758
+ tld: { type: "string", description: "TLD", default: "xyz" },
682
759
  registerBasename: {
683
- type: 'boolean',
684
- description: 'Register Basename. Set false to skip Basename cost.',
760
+ type: "boolean",
761
+ description: "Register Basename. Set false to skip Basename cost.",
685
762
  default: true,
686
763
  },
687
764
  basenameLabel: {
688
- type: 'string',
689
- description: 'Optional alternate Basename label. Omit to use preferredName.',
765
+ type: "string",
766
+ description: "Optional alternate Basename label. Omit to use preferredName.",
690
767
  },
691
768
  registerEns: {
692
- type: 'boolean',
693
- description: 'Register ENS. Set false to skip ENS cost.',
769
+ type: "boolean",
770
+ description: "Register ENS. Set false to skip ENS cost.",
694
771
  default: false,
695
772
  },
696
773
  ensLabel: {
697
- type: 'string',
698
- description: 'Optional alternate ENS label. Omit to use preferredName.',
774
+ type: "string",
775
+ description: "Optional alternate ENS label. Omit to use preferredName.",
699
776
  },
700
777
  ownerAddress: {
701
- type: 'string',
702
- description: 'Optional EVM address that receives the AgentID NFT. Omit to use the paying wallet.',
778
+ type: "string",
779
+ description: "Optional EVM address that receives the AgentID NFT. Omit to use the paying wallet.",
703
780
  },
704
781
  emailEnabled: {
705
- type: 'boolean',
706
- description: 'Deprecated compatibility flag. Email is now always included.',
782
+ type: "boolean",
783
+ description: "Deprecated compatibility flag. Email is now always included.",
707
784
  default: true,
708
785
  },
709
786
  emailUsername: {
710
- type: 'string',
711
- description: 'Primary email username. Defaults to agent, producing agent@domain.',
712
- default: 'agent',
787
+ type: "string",
788
+ description: "Primary email username. Defaults to agent, producing agent@domain.",
789
+ default: "agent",
713
790
  },
714
791
  dnsTarget: {
715
- type: 'string',
716
- description: 'Optional initial endpoint URL or IP to point the domain at.',
792
+ type: "string",
793
+ description: "Optional initial endpoint URL or IP to point the domain at.",
717
794
  },
718
795
  premiumPlan: {
719
- type: 'string',
720
- enum: ['included', 'starter', 'pro', 'enterprise'],
721
- description: 'Premium Plan to buy with registration. Defaults to included.',
722
- default: 'included',
796
+ type: "string",
797
+ enum: ["included", "starter", "pro", "enterprise"],
798
+ description: "Premium Plan to buy with registration. Defaults to included.",
799
+ default: "included",
800
+ },
801
+ years: {
802
+ type: "number",
803
+ description: "Registration years",
804
+ default: 1,
723
805
  },
724
- years: { type: 'number', description: 'Registration years', default: 1 },
725
806
  },
726
- required: ['preferredName'],
807
+ required: ["preferredName"],
727
808
  },
728
809
  },
729
810
  },
730
811
  {
731
- type: 'function',
812
+ type: "function",
732
813
  function: {
733
- name: 'search_agents',
734
- description: 'Search for registered AI agents',
814
+ name: "search_agents",
815
+ description: "Search for registered AI agents",
735
816
  parameters: {
736
- type: 'object',
817
+ type: "object",
737
818
  properties: {
738
- q: { type: 'string', description: 'Search query' },
739
- framework: { type: 'string', description: 'Filter by framework' },
740
- limit: { type: 'number', description: 'Max results', default: 20 },
819
+ q: { type: "string", description: "Search query" },
820
+ framework: { type: "string", description: "Filter by framework" },
821
+ limit: { type: "number", description: "Max results", default: 20 },
741
822
  },
742
823
  },
743
824
  },
744
825
  },
745
826
  {
746
- type: 'function',
827
+ type: "function",
747
828
  function: {
748
- name: 'send_agent_email',
749
- description: 'Send text-only email from an agent primary email or active alias',
829
+ name: "send_agent_email",
830
+ description: "Send text-only email from an agent primary email or active alias",
750
831
  parameters: {
751
- type: 'object',
832
+ type: "object",
752
833
  properties: {
753
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
754
- to: { type: 'string', description: 'Recipient email address' },
755
- subject: { type: 'string', description: 'Email subject' },
756
- text: { type: 'string', description: 'Plain-text email body' },
834
+ agentId: {
835
+ type: "string",
836
+ description: "AgentDomain agent ID (UUID)",
837
+ },
838
+ to: { type: "string", description: "Recipient email address" },
839
+ subject: { type: "string", description: "Email subject" },
840
+ text: { type: "string", description: "Plain-text email body" },
757
841
  fromAddress: {
758
- type: 'string',
759
- description: 'Optional primary email or active alias to send from',
842
+ type: "string",
843
+ description: "Optional primary email or active alias to send from",
760
844
  },
761
845
  },
762
- required: ['agentId', 'to', 'subject', 'text'],
846
+ required: ["agentId", "to", "subject", "text"],
763
847
  },
764
848
  },
765
849
  },
766
850
  {
767
- type: 'function',
851
+ type: "function",
768
852
  function: {
769
- name: 'list_agent_email',
770
- description: 'List an agent email messages and active primary/alias addresses',
853
+ name: "list_agent_email",
854
+ description: "List an agent email messages and active primary/alias addresses",
771
855
  parameters: {
772
- type: 'object',
856
+ type: "object",
773
857
  properties: {
774
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
775
- limit: { type: 'number', description: 'Max messages', default: 20 },
858
+ agentId: {
859
+ type: "string",
860
+ description: "AgentDomain agent ID (UUID)",
861
+ },
862
+ limit: { type: "number", description: "Max messages", default: 20 },
776
863
  },
777
- required: ['agentId'],
864
+ required: ["agentId"],
778
865
  },
779
866
  },
780
867
  },
781
868
  {
782
- type: 'function',
869
+ type: "function",
783
870
  function: {
784
- name: 'delete_agent_email',
785
- description: 'Permanently delete one email message from an agent inbox',
871
+ name: "delete_agent_email",
872
+ description: "Permanently delete one email message from an agent inbox",
786
873
  parameters: {
787
- type: 'object',
874
+ type: "object",
788
875
  properties: {
789
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
790
- messageId: { type: 'string', description: 'Email message ID (UUID)' },
876
+ agentId: {
877
+ type: "string",
878
+ description: "AgentDomain agent ID (UUID)",
879
+ },
880
+ messageId: {
881
+ type: "string",
882
+ description: "Email message ID (UUID)",
883
+ },
791
884
  },
792
- required: ['agentId', 'messageId'],
885
+ required: ["agentId", "messageId"],
793
886
  },
794
887
  },
795
888
  },
796
889
  {
797
- type: 'function',
890
+ type: "function",
798
891
  function: {
799
- name: 'update_primary_email',
800
- description: 'Change one agent primary email username. The old primary address stops receiving new mail.',
892
+ name: "update_primary_email",
893
+ description: "Change one agent primary email username. The old primary address stops receiving new mail.",
801
894
  parameters: {
802
- type: 'object',
895
+ type: "object",
803
896
  properties: {
804
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
805
- username: { type: 'string', description: 'New local-part, e.g. agent or support' },
897
+ agentId: {
898
+ type: "string",
899
+ description: "AgentDomain agent ID (UUID)",
900
+ },
901
+ username: {
902
+ type: "string",
903
+ description: "New local-part, e.g. agent or support",
904
+ },
806
905
  },
807
- required: ['agentId', 'username'],
906
+ required: ["agentId", "username"],
808
907
  },
809
908
  },
810
909
  },
811
910
  {
812
- type: 'function',
911
+ type: "function",
813
912
  function: {
814
- name: 'create_email_alias',
815
- description: 'Create an extra receive-and-send email alias. Requires available paid-plan alias capacity.',
913
+ name: "create_email_alias",
914
+ description: "Create an extra receive-and-send email alias. Requires available paid-plan alias capacity.",
816
915
  parameters: {
817
- type: 'object',
916
+ type: "object",
818
917
  properties: {
819
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
820
- username: { type: 'string', description: 'Alias local-part, e.g. billing' },
918
+ agentId: {
919
+ type: "string",
920
+ description: "AgentDomain agent ID (UUID)",
921
+ },
922
+ username: {
923
+ type: "string",
924
+ description: "Alias local-part, e.g. billing",
925
+ },
821
926
  },
822
- required: ['agentId', 'username'],
927
+ required: ["agentId", "username"],
823
928
  },
824
929
  },
825
930
  },
826
931
  {
827
- type: 'function',
932
+ type: "function",
828
933
  function: {
829
- name: 'delete_email_alias',
830
- description: 'Delete one active email alias from an agent',
934
+ name: "delete_email_alias",
935
+ description: "Delete one active email alias from an agent",
831
936
  parameters: {
832
- type: 'object',
937
+ type: "object",
833
938
  properties: {
834
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
835
- emailAddress: { type: 'string', description: 'Full alias address to delete' },
939
+ agentId: {
940
+ type: "string",
941
+ description: "AgentDomain agent ID (UUID)",
942
+ },
943
+ emailAddress: {
944
+ type: "string",
945
+ description: "Full alias address to delete",
946
+ },
836
947
  },
837
- required: ['agentId', 'emailAddress'],
948
+ required: ["agentId", "emailAddress"],
838
949
  },
839
950
  },
840
951
  },
841
952
  {
842
- type: 'function',
953
+ type: "function",
843
954
  function: {
844
- name: 'get_renewal_status',
845
- description: 'Get renewal vault status for an agent, including exact next renewal amount, purchase snapshot, vault balance, shortfall, renewal date, and auto-renew state',
955
+ name: "get_renewal_status",
956
+ description: "Get renewal vault status for an agent, including exact next renewal amount, purchase snapshot, vault balance, shortfall, renewal date, and auto-renew state",
846
957
  parameters: {
847
- type: 'object',
958
+ type: "object",
848
959
  properties: {
849
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
960
+ agentId: {
961
+ type: "string",
962
+ description: "AgentDomain agent ID (UUID)",
963
+ },
850
964
  },
851
- required: ['agentId'],
965
+ required: ["agentId"],
852
966
  },
853
967
  },
854
968
  },
855
969
  {
856
- type: 'function',
970
+ type: "function",
857
971
  function: {
858
- name: 'fund_renewal_vault',
859
- description: 'Deposit USDC from the connected wallet into one AgentID renewal vault. Anyone can fund; only the owner can withdraw or enable auto-renew. Call get_renewal_status first and normally use its shortfallUsdc value.',
972
+ name: "fund_renewal_vault",
973
+ description: "Deposit USDC from the connected wallet into one AgentID renewal vault. Anyone can fund; only the owner can withdraw or enable auto-renew. Call get_renewal_status first and normally use its shortfallUsdc value.",
860
974
  parameters: {
861
- type: 'object',
975
+ type: "object",
862
976
  properties: {
863
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
977
+ agentId: {
978
+ type: "string",
979
+ description: "AgentDomain agent ID (UUID)",
980
+ },
864
981
  amountUsdc: {
865
- type: 'string',
866
- description: 'USDC amount to deposit, with up to 6 decimals.',
982
+ type: "string",
983
+ description: "USDC amount to deposit, with up to 6 decimals.",
867
984
  },
868
985
  },
869
- required: ['agentId', 'amountUsdc'],
986
+ required: ["agentId", "amountUsdc"],
870
987
  },
871
988
  },
872
989
  },
873
990
  {
874
- type: 'function',
991
+ type: "function",
875
992
  function: {
876
- name: 'enable_auto_renew',
877
- description: 'Enable RenewalVault auto-renew for an agent. Requires the walletClient to be the AgentID NFT owner wallet.',
993
+ name: "enable_auto_renew",
994
+ description: "Enable RenewalVault auto-renew for an agent. Requires the walletClient to be the AgentID NFT owner wallet.",
878
995
  parameters: {
879
- type: 'object',
996
+ type: "object",
880
997
  properties: {
881
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
998
+ agentId: {
999
+ type: "string",
1000
+ description: "AgentDomain agent ID (UUID)",
1001
+ },
882
1002
  },
883
- required: ['agentId'],
1003
+ required: ["agentId"],
884
1004
  },
885
1005
  },
886
1006
  },
887
1007
  {
888
- type: 'function',
1008
+ type: "function",
889
1009
  function: {
890
- name: 'reconfigure_ssl',
891
- description: 'Rebuild the Cloudflare SaaS SSL hostname and sync the required Spaceship DNS validation records for an existing agent. Use this if SSL is pending, failed, or needs a refresh.',
1010
+ name: "reconfigure_ssl",
1011
+ description: "Rebuild the Cloudflare SaaS SSL hostname and sync the required Spaceship DNS validation records for an existing agent. Use this if SSL is pending, failed, or needs a refresh.",
892
1012
  parameters: {
893
- type: 'object',
1013
+ type: "object",
894
1014
  properties: {
895
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
1015
+ agentId: {
1016
+ type: "string",
1017
+ description: "AgentDomain agent ID (UUID)",
1018
+ },
896
1019
  },
897
- required: ['agentId'],
1020
+ required: ["agentId"],
898
1021
  },
899
1022
  },
900
1023
  },
901
1024
  {
902
- type: 'function',
1025
+ type: "function",
903
1026
  function: {
904
- name: 'set_registry_visibility',
905
- description: 'Hide or show an agent in the public AgentDomain registry. Hiding requires an active paid Premium Plan.',
1027
+ name: "set_registry_visibility",
1028
+ description: "Hide or show an agent in the public AgentDomain registry. Hiding requires an active paid Premium Plan.",
906
1029
  parameters: {
907
- type: 'object',
1030
+ type: "object",
908
1031
  properties: {
909
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
1032
+ agentId: {
1033
+ type: "string",
1034
+ description: "AgentDomain agent ID (UUID)",
1035
+ },
910
1036
  registryHidden: {
911
- type: 'boolean',
912
- description: 'true hides the agent from public registry/search; false makes it public',
1037
+ type: "boolean",
1038
+ description: "true hides the agent from public registry/search; false makes it public",
913
1039
  },
914
1040
  },
915
- required: ['agentId', 'registryHidden'],
1041
+ required: ["agentId", "registryHidden"],
916
1042
  },
917
1043
  },
918
1044
  },
919
1045
  {
920
- type: 'function',
1046
+ type: "function",
921
1047
  function: {
922
- name: 'schedule_service_plan_renewal',
923
- description: 'Choose the exact Premium Plan SKU for the next identity renewal',
1048
+ name: "schedule_service_plan_renewal",
1049
+ description: "Choose the exact Premium Plan SKU for the next identity renewal",
924
1050
  parameters: {
925
- type: 'object',
1051
+ type: "object",
926
1052
  properties: {
927
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
1053
+ agentId: {
1054
+ type: "string",
1055
+ description: "AgentDomain agent ID (UUID)",
1056
+ },
928
1057
  plan: {
929
- type: 'string',
930
- enum: ['included', 'starter', 'pro', 'enterprise'],
1058
+ type: "string",
1059
+ enum: ["included", "starter", "pro", "enterprise"],
931
1060
  },
932
1061
  planSku: {
933
- type: 'string',
934
- description: 'Exact SKU, including Enterprise email volume tier',
1062
+ type: "string",
1063
+ description: "Exact SKU, including Enterprise email volume tier",
935
1064
  },
936
1065
  },
937
- required: ['agentId', 'plan', 'planSku'],
1066
+ required: ["agentId", "plan", "planSku"],
938
1067
  },
939
1068
  },
940
1069
  },
@@ -943,301 +1072,363 @@ export function createOpenAITools() {
943
1072
  export function createAnthropicTools() {
944
1073
  return [
945
1074
  {
946
- name: 'check_domain_availability',
947
- description: 'Check if a domain name is available for registration',
1075
+ name: "check_domain_availability",
1076
+ description: "Check if a domain name is available for registration",
948
1077
  input_schema: {
949
- type: 'object',
1078
+ type: "object",
950
1079
  properties: {
951
- name: { type: 'string', description: 'Domain name to check' },
952
- tld: { type: 'string', description: 'TLD (e.g. xyz, com, ai)', default: 'xyz' },
1080
+ name: { type: "string", description: "Domain name to check" },
1081
+ tld: {
1082
+ type: "string",
1083
+ description: "TLD (e.g. xyz, com, ai)",
1084
+ default: "xyz",
1085
+ },
953
1086
  },
954
- required: ['name'],
1087
+ required: ["name"],
955
1088
  },
956
1089
  },
957
1090
  {
958
- name: 'quote_registration',
959
- description: 'Get pricing quote for registering an AI agent identity. Domain, DNS, email, SSL certification, AgentID NFT orchestration, and platform fee are included by default. Basename and ENS are optional.',
1091
+ name: "quote_registration",
1092
+ description: "Get pricing quote for registering an AI agent identity. Domain, DNS, email, SSL certification, AgentID NFT orchestration, and platform fee are included by default. Basename and ENS are optional.",
960
1093
  input_schema: {
961
- type: 'object',
1094
+ type: "object",
962
1095
  properties: {
963
- preferredName: { type: 'string', description: 'Preferred domain name' },
964
- tld: { type: 'string', description: 'TLD', default: 'xyz' },
1096
+ preferredName: {
1097
+ type: "string",
1098
+ description: "Preferred domain name",
1099
+ },
1100
+ tld: { type: "string", description: "TLD", default: "xyz" },
965
1101
  registerBasename: {
966
- type: 'boolean',
967
- description: 'Also register Basename. Set false to skip Basename cost.',
1102
+ type: "boolean",
1103
+ description: "Also register Basename. Set false to skip Basename cost.",
968
1104
  default: true,
969
1105
  },
970
1106
  basenameLabel: {
971
- type: 'string',
972
- description: 'Optional alternate Basename label. Omit to use preferredName.',
1107
+ type: "string",
1108
+ description: "Optional alternate Basename label. Omit to use preferredName.",
973
1109
  },
974
1110
  registerEns: {
975
- type: 'boolean',
976
- description: 'Also register ENS name. Set false to skip ENS cost.',
1111
+ type: "boolean",
1112
+ description: "Also register ENS name. Set false to skip ENS cost.",
977
1113
  default: false,
978
1114
  },
979
1115
  ensLabel: {
980
- type: 'string',
981
- description: 'Optional alternate ENS label. Omit to use preferredName.',
1116
+ type: "string",
1117
+ description: "Optional alternate ENS label. Omit to use preferredName.",
982
1118
  },
983
1119
  emailEnabled: {
984
- type: 'boolean',
985
- description: 'Deprecated compatibility flag. Email is now always included.',
1120
+ type: "boolean",
1121
+ description: "Deprecated compatibility flag. Email is now always included.",
986
1122
  default: true,
987
1123
  },
988
1124
  emailUsername: {
989
- type: 'string',
990
- description: 'Primary email username. Defaults to agent, producing agent@domain.',
991
- default: 'agent',
1125
+ type: "string",
1126
+ description: "Primary email username. Defaults to agent, producing agent@domain.",
1127
+ default: "agent",
992
1128
  },
993
1129
  premiumPlan: {
994
- type: 'string',
995
- enum: ['included', 'starter', 'pro', 'enterprise'],
996
- description: 'Premium Plan to buy with registration. Defaults to included.',
997
- default: 'included',
1130
+ type: "string",
1131
+ enum: ["included", "starter", "pro", "enterprise"],
1132
+ description: "Premium Plan to buy with registration. Defaults to included.",
1133
+ default: "included",
1134
+ },
1135
+ years: {
1136
+ type: "number",
1137
+ description: "Registration years",
1138
+ default: 1,
998
1139
  },
999
- years: { type: 'number', description: 'Registration years', default: 1 },
1000
1140
  },
1001
- required: ['preferredName'],
1141
+ required: ["preferredName"],
1002
1142
  },
1003
1143
  },
1004
1144
  {
1005
- name: 'register_agent_identity',
1006
- description: 'Register a new AI agent identity. Domain, DNS, email, SSL certification, AgentID NFT orchestration, and platform fee are included by default. Basename and ENS are optional.',
1145
+ name: "register_agent_identity",
1146
+ description: "Register a new AI agent identity. Domain, DNS, email, SSL certification, AgentID NFT orchestration, and platform fee are included by default. Basename and ENS are optional.",
1007
1147
  input_schema: {
1008
- type: 'object',
1148
+ type: "object",
1009
1149
  properties: {
1010
- preferredName: { type: 'string', description: 'Domain name' },
1011
- tld: { type: 'string', description: 'TLD', default: 'xyz' },
1150
+ preferredName: { type: "string", description: "Domain name" },
1151
+ tld: { type: "string", description: "TLD", default: "xyz" },
1012
1152
  registerBasename: {
1013
- type: 'boolean',
1014
- description: 'Register Basename. Set false to skip Basename cost.',
1153
+ type: "boolean",
1154
+ description: "Register Basename. Set false to skip Basename cost.",
1015
1155
  default: true,
1016
1156
  },
1017
1157
  basenameLabel: {
1018
- type: 'string',
1019
- description: 'Optional alternate Basename label. Omit to use preferredName.',
1158
+ type: "string",
1159
+ description: "Optional alternate Basename label. Omit to use preferredName.",
1020
1160
  },
1021
1161
  registerEns: {
1022
- type: 'boolean',
1023
- description: 'Register ENS. Set false to skip ENS cost.',
1162
+ type: "boolean",
1163
+ description: "Register ENS. Set false to skip ENS cost.",
1024
1164
  default: false,
1025
1165
  },
1026
1166
  ensLabel: {
1027
- type: 'string',
1028
- description: 'Optional alternate ENS label. Omit to use preferredName.',
1167
+ type: "string",
1168
+ description: "Optional alternate ENS label. Omit to use preferredName.",
1029
1169
  },
1030
1170
  ownerAddress: {
1031
- type: 'string',
1032
- description: 'Optional EVM address that receives the AgentID NFT. Omit to use the paying wallet.',
1171
+ type: "string",
1172
+ description: "Optional EVM address that receives the AgentID NFT. Omit to use the paying wallet.",
1033
1173
  },
1034
1174
  emailEnabled: {
1035
- type: 'boolean',
1036
- description: 'Deprecated compatibility flag. Email is now always included.',
1175
+ type: "boolean",
1176
+ description: "Deprecated compatibility flag. Email is now always included.",
1037
1177
  default: true,
1038
1178
  },
1039
1179
  emailUsername: {
1040
- type: 'string',
1041
- description: 'Primary email username. Defaults to agent, producing agent@domain.',
1042
- default: 'agent',
1180
+ type: "string",
1181
+ description: "Primary email username. Defaults to agent, producing agent@domain.",
1182
+ default: "agent",
1043
1183
  },
1044
1184
  dnsTarget: {
1045
- type: 'string',
1046
- description: 'Optional initial endpoint URL or IP to point the domain at.',
1185
+ type: "string",
1186
+ description: "Optional initial endpoint URL or IP to point the domain at.",
1047
1187
  },
1048
1188
  premiumPlan: {
1049
- type: 'string',
1050
- enum: ['included', 'starter', 'pro', 'enterprise'],
1051
- description: 'Premium Plan to buy with registration. Defaults to included.',
1052
- default: 'included',
1189
+ type: "string",
1190
+ enum: ["included", "starter", "pro", "enterprise"],
1191
+ description: "Premium Plan to buy with registration. Defaults to included.",
1192
+ default: "included",
1193
+ },
1194
+ years: {
1195
+ type: "number",
1196
+ description: "Registration years",
1197
+ default: 1,
1053
1198
  },
1054
- years: { type: 'number', description: 'Registration years', default: 1 },
1055
1199
  },
1056
- required: ['preferredName'],
1200
+ required: ["preferredName"],
1057
1201
  },
1058
1202
  },
1059
1203
  {
1060
- name: 'search_agents',
1061
- description: 'Search for registered AI agents',
1204
+ name: "search_agents",
1205
+ description: "Search for registered AI agents",
1062
1206
  input_schema: {
1063
- type: 'object',
1207
+ type: "object",
1064
1208
  properties: {
1065
- q: { type: 'string', description: 'Search query' },
1066
- framework: { type: 'string', description: 'Filter by framework' },
1067
- limit: { type: 'number', description: 'Max results', default: 20 },
1209
+ q: { type: "string", description: "Search query" },
1210
+ framework: { type: "string", description: "Filter by framework" },
1211
+ limit: { type: "number", description: "Max results", default: 20 },
1068
1212
  },
1069
1213
  },
1070
1214
  },
1071
1215
  {
1072
- name: 'send_agent_email',
1073
- description: 'Send text-only email from an agent primary email or active alias',
1216
+ name: "send_agent_email",
1217
+ description: "Send text-only email from an agent primary email or active alias",
1074
1218
  input_schema: {
1075
- type: 'object',
1219
+ type: "object",
1076
1220
  properties: {
1077
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
1078
- to: { type: 'string', description: 'Recipient email address' },
1079
- subject: { type: 'string', description: 'Email subject' },
1080
- text: { type: 'string', description: 'Plain-text email body' },
1221
+ agentId: {
1222
+ type: "string",
1223
+ description: "AgentDomain agent ID (UUID)",
1224
+ },
1225
+ to: { type: "string", description: "Recipient email address" },
1226
+ subject: { type: "string", description: "Email subject" },
1227
+ text: { type: "string", description: "Plain-text email body" },
1081
1228
  fromAddress: {
1082
- type: 'string',
1083
- description: 'Optional primary email or active alias to send from',
1229
+ type: "string",
1230
+ description: "Optional primary email or active alias to send from",
1084
1231
  },
1085
1232
  },
1086
- required: ['agentId', 'to', 'subject', 'text'],
1233
+ required: ["agentId", "to", "subject", "text"],
1087
1234
  },
1088
1235
  },
1089
1236
  {
1090
- name: 'list_agent_email',
1091
- description: 'List an agent email messages and active primary/alias addresses',
1237
+ name: "list_agent_email",
1238
+ description: "List an agent email messages and active primary/alias addresses",
1092
1239
  input_schema: {
1093
- type: 'object',
1240
+ type: "object",
1094
1241
  properties: {
1095
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
1096
- limit: { type: 'number', description: 'Max messages', default: 20 },
1242
+ agentId: {
1243
+ type: "string",
1244
+ description: "AgentDomain agent ID (UUID)",
1245
+ },
1246
+ limit: { type: "number", description: "Max messages", default: 20 },
1097
1247
  },
1098
- required: ['agentId'],
1248
+ required: ["agentId"],
1099
1249
  },
1100
1250
  },
1101
1251
  {
1102
- name: 'delete_agent_email',
1103
- description: 'Permanently delete one email message from an agent inbox',
1252
+ name: "delete_agent_email",
1253
+ description: "Permanently delete one email message from an agent inbox",
1104
1254
  input_schema: {
1105
- type: 'object',
1255
+ type: "object",
1106
1256
  properties: {
1107
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
1108
- messageId: { type: 'string', description: 'Email message ID (UUID)' },
1257
+ agentId: {
1258
+ type: "string",
1259
+ description: "AgentDomain agent ID (UUID)",
1260
+ },
1261
+ messageId: { type: "string", description: "Email message ID (UUID)" },
1109
1262
  },
1110
- required: ['agentId', 'messageId'],
1263
+ required: ["agentId", "messageId"],
1111
1264
  },
1112
1265
  },
1113
1266
  {
1114
- name: 'update_primary_email',
1115
- description: 'Change one agent primary email username. The old primary address stops receiving new mail.',
1267
+ name: "update_primary_email",
1268
+ description: "Change one agent primary email username. The old primary address stops receiving new mail.",
1116
1269
  input_schema: {
1117
- type: 'object',
1270
+ type: "object",
1118
1271
  properties: {
1119
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
1120
- username: { type: 'string', description: 'New local-part, e.g. agent or support' },
1272
+ agentId: {
1273
+ type: "string",
1274
+ description: "AgentDomain agent ID (UUID)",
1275
+ },
1276
+ username: {
1277
+ type: "string",
1278
+ description: "New local-part, e.g. agent or support",
1279
+ },
1121
1280
  },
1122
- required: ['agentId', 'username'],
1281
+ required: ["agentId", "username"],
1123
1282
  },
1124
1283
  },
1125
1284
  {
1126
- name: 'create_email_alias',
1127
- description: 'Create an extra receive-and-send email alias. Requires available paid-plan alias capacity.',
1285
+ name: "create_email_alias",
1286
+ description: "Create an extra receive-and-send email alias. Requires available paid-plan alias capacity.",
1128
1287
  input_schema: {
1129
- type: 'object',
1288
+ type: "object",
1130
1289
  properties: {
1131
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
1132
- username: { type: 'string', description: 'Alias local-part, e.g. billing' },
1290
+ agentId: {
1291
+ type: "string",
1292
+ description: "AgentDomain agent ID (UUID)",
1293
+ },
1294
+ username: {
1295
+ type: "string",
1296
+ description: "Alias local-part, e.g. billing",
1297
+ },
1133
1298
  },
1134
- required: ['agentId', 'username'],
1299
+ required: ["agentId", "username"],
1135
1300
  },
1136
1301
  },
1137
1302
  {
1138
- name: 'delete_email_alias',
1139
- description: 'Delete one active email alias from an agent',
1303
+ name: "delete_email_alias",
1304
+ description: "Delete one active email alias from an agent",
1140
1305
  input_schema: {
1141
- type: 'object',
1306
+ type: "object",
1142
1307
  properties: {
1143
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
1144
- emailAddress: { type: 'string', description: 'Full alias address to delete' },
1308
+ agentId: {
1309
+ type: "string",
1310
+ description: "AgentDomain agent ID (UUID)",
1311
+ },
1312
+ emailAddress: {
1313
+ type: "string",
1314
+ description: "Full alias address to delete",
1315
+ },
1145
1316
  },
1146
- required: ['agentId', 'emailAddress'],
1317
+ required: ["agentId", "emailAddress"],
1147
1318
  },
1148
1319
  },
1149
1320
  {
1150
- name: 'get_renewal_status',
1151
- description: 'Get renewal vault status for an agent, including exact next renewal amount, purchase snapshot, vault balance, shortfall, renewal date, and auto-renew state',
1321
+ name: "get_renewal_status",
1322
+ description: "Get renewal vault status for an agent, including exact next renewal amount, purchase snapshot, vault balance, shortfall, renewal date, and auto-renew state",
1152
1323
  input_schema: {
1153
- type: 'object',
1324
+ type: "object",
1154
1325
  properties: {
1155
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
1326
+ agentId: {
1327
+ type: "string",
1328
+ description: "AgentDomain agent ID (UUID)",
1329
+ },
1156
1330
  },
1157
- required: ['agentId'],
1331
+ required: ["agentId"],
1158
1332
  },
1159
1333
  },
1160
1334
  {
1161
- name: 'fund_renewal_vault',
1162
- description: 'Deposit USDC from the connected wallet into one AgentID renewal vault. Anyone can fund; only the owner can withdraw or enable auto-renew. Call get_renewal_status first and normally use its shortfallUsdc value.',
1335
+ name: "fund_renewal_vault",
1336
+ description: "Deposit USDC from the connected wallet into one AgentID renewal vault. Anyone can fund; only the owner can withdraw or enable auto-renew. Call get_renewal_status first and normally use its shortfallUsdc value.",
1163
1337
  input_schema: {
1164
- type: 'object',
1338
+ type: "object",
1165
1339
  properties: {
1166
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
1340
+ agentId: {
1341
+ type: "string",
1342
+ description: "AgentDomain agent ID (UUID)",
1343
+ },
1167
1344
  amountUsdc: {
1168
- type: 'string',
1169
- description: 'USDC amount to deposit, with up to 6 decimals.',
1345
+ type: "string",
1346
+ description: "USDC amount to deposit, with up to 6 decimals.",
1170
1347
  },
1171
1348
  },
1172
- required: ['agentId', 'amountUsdc'],
1349
+ required: ["agentId", "amountUsdc"],
1173
1350
  },
1174
1351
  },
1175
1352
  {
1176
- name: 'enable_auto_renew',
1177
- description: 'Enable RenewalVault auto-renew for an agent. Requires the walletClient to be the AgentID NFT owner wallet.',
1353
+ name: "enable_auto_renew",
1354
+ description: "Enable RenewalVault auto-renew for an agent. Requires the walletClient to be the AgentID NFT owner wallet.",
1178
1355
  input_schema: {
1179
- type: 'object',
1356
+ type: "object",
1180
1357
  properties: {
1181
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
1358
+ agentId: {
1359
+ type: "string",
1360
+ description: "AgentDomain agent ID (UUID)",
1361
+ },
1182
1362
  },
1183
- required: ['agentId'],
1363
+ required: ["agentId"],
1184
1364
  },
1185
1365
  },
1186
1366
  {
1187
- name: 'reconfigure_ssl',
1188
- description: 'Rebuild the Cloudflare SaaS SSL hostname and sync the required Spaceship DNS validation records for an existing agent. Use this if SSL is pending, failed, or needs a refresh.',
1367
+ name: "reconfigure_ssl",
1368
+ description: "Rebuild the Cloudflare SaaS SSL hostname and sync the required Spaceship DNS validation records for an existing agent. Use this if SSL is pending, failed, or needs a refresh.",
1189
1369
  input_schema: {
1190
- type: 'object',
1370
+ type: "object",
1191
1371
  properties: {
1192
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
1372
+ agentId: {
1373
+ type: "string",
1374
+ description: "AgentDomain agent ID (UUID)",
1375
+ },
1193
1376
  },
1194
- required: ['agentId'],
1377
+ required: ["agentId"],
1195
1378
  },
1196
1379
  },
1197
1380
  {
1198
- name: 'set_registry_visibility',
1199
- description: 'Hide or show an agent in the public AgentDomain registry. Hiding requires an active paid Premium Plan.',
1381
+ name: "set_registry_visibility",
1382
+ description: "Hide or show an agent in the public AgentDomain registry. Hiding requires an active paid Premium Plan.",
1200
1383
  input_schema: {
1201
- type: 'object',
1384
+ type: "object",
1202
1385
  properties: {
1203
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
1386
+ agentId: {
1387
+ type: "string",
1388
+ description: "AgentDomain agent ID (UUID)",
1389
+ },
1204
1390
  registryHidden: {
1205
- type: 'boolean',
1206
- description: 'true hides the agent from public registry/search; false makes it public',
1391
+ type: "boolean",
1392
+ description: "true hides the agent from public registry/search; false makes it public",
1207
1393
  },
1208
1394
  },
1209
- required: ['agentId', 'registryHidden'],
1395
+ required: ["agentId", "registryHidden"],
1210
1396
  },
1211
1397
  },
1212
1398
  {
1213
- name: 'schedule_service_plan_renewal',
1214
- description: 'Choose the exact Premium Plan SKU for the next identity renewal',
1399
+ name: "schedule_service_plan_renewal",
1400
+ description: "Choose the exact Premium Plan SKU for the next identity renewal",
1215
1401
  input_schema: {
1216
- type: 'object',
1402
+ type: "object",
1217
1403
  properties: {
1218
- agentId: { type: 'string', description: 'AgentDomain agent ID (UUID)' },
1404
+ agentId: {
1405
+ type: "string",
1406
+ description: "AgentDomain agent ID (UUID)",
1407
+ },
1219
1408
  plan: {
1220
- type: 'string',
1221
- enum: ['included', 'starter', 'pro', 'enterprise'],
1409
+ type: "string",
1410
+ enum: ["included", "starter", "pro", "enterprise"],
1222
1411
  },
1223
1412
  planSku: {
1224
- type: 'string',
1225
- description: 'Exact SKU, including Enterprise email volume tier',
1413
+ type: "string",
1414
+ description: "Exact SKU, including Enterprise email volume tier",
1226
1415
  },
1227
1416
  },
1228
- required: ['agentId', 'plan', 'planSku'],
1417
+ required: ["agentId", "plan", "planSku"],
1229
1418
  },
1230
1419
  },
1231
1420
  ];
1232
1421
  }
1233
1422
  export async function runAgentDomainTool(ad, name, args) {
1234
1423
  switch (name) {
1235
- case 'check_domain_availability':
1236
- return ad.checkAvailability(args.name, { tld: args.tld ?? 'xyz' });
1237
- case 'quote_registration':
1424
+ case "check_domain_availability":
1425
+ return ad.checkAvailability(args.name, {
1426
+ tld: args.tld ?? "xyz",
1427
+ });
1428
+ case "quote_registration":
1238
1429
  return ad.quote({
1239
1430
  preferredName: args.preferredName,
1240
- tld: args.tld ?? 'xyz',
1431
+ tld: args.tld ?? "xyz",
1241
1432
  registerBasename: args.registerBasename ?? true,
1242
1433
  basenameLabel: args.basenameLabel,
1243
1434
  registerEns: args.registerEns ?? false,
@@ -1247,10 +1438,11 @@ export async function runAgentDomainTool(ad, name, args) {
1247
1438
  premiumPlan: args.premiumPlan,
1248
1439
  years: args.years ?? 1,
1249
1440
  });
1250
- case 'register_agent_identity':
1441
+ case "register_agent_identity":
1251
1442
  return ad.register({
1252
1443
  preferredName: args.preferredName,
1253
- tld: (args.tld ?? 'xyz'),
1444
+ tld: (args.tld ??
1445
+ "xyz"),
1254
1446
  registerBasename: args.registerBasename ?? true,
1255
1447
  basenameLabel: args.basenameLabel,
1256
1448
  registerEns: args.registerEns ?? false,
@@ -1264,14 +1456,14 @@ export async function runAgentDomainTool(ad, name, args) {
1264
1456
  ownerAddress: args.ownerAddress,
1265
1457
  wallet: args.wallet,
1266
1458
  });
1267
- case 'search_agents':
1459
+ case "search_agents":
1268
1460
  return ad.search({
1269
1461
  q: args.q,
1270
1462
  framework: args.framework,
1271
1463
  capability: args.capability,
1272
1464
  limit: args.limit ?? 20,
1273
1465
  });
1274
- case 'send_agent_email':
1466
+ case "send_agent_email":
1275
1467
  return ad.sendEmail(args.agentId, {
1276
1468
  to: args.to,
1277
1469
  fromAddress: args.fromAddress,
@@ -1279,44 +1471,46 @@ export async function runAgentDomainTool(ad, name, args) {
1279
1471
  text: args.text,
1280
1472
  replyTo: args.replyTo,
1281
1473
  });
1282
- case 'list_agent_email':
1283
- return ad.listEmail(args.agentId, { limit: args.limit ?? 20 });
1284
- case 'delete_agent_email':
1474
+ case "list_agent_email":
1475
+ return ad.listEmail(args.agentId, {
1476
+ limit: args.limit ?? 20,
1477
+ });
1478
+ case "delete_agent_email":
1285
1479
  return ad.deleteEmailMessage(args.agentId, args.messageId);
1286
- case 'update_primary_email':
1480
+ case "update_primary_email":
1287
1481
  return ad.updatePrimaryEmail(args.agentId, args.username);
1288
- case 'create_email_alias':
1482
+ case "create_email_alias":
1289
1483
  return ad.createEmailAlias(args.agentId, args.username);
1290
- case 'delete_email_alias':
1484
+ case "delete_email_alias":
1291
1485
  return ad.deleteEmailAlias(args.agentId, args.emailAddress);
1292
- case 'list_dns_records':
1486
+ case "list_dns_records":
1293
1487
  return ad.listDnsRecords(args.agentId);
1294
- case 'create_dns_record':
1488
+ case "create_dns_record":
1295
1489
  return ad.createDnsRecord(args.agentId, readDnsRecordArgs(args));
1296
- case 'update_dns_record':
1490
+ case "update_dns_record":
1297
1491
  return ad.updateDnsRecord(args.agentId, args.recordId, readDnsRecordArgs(args));
1298
- case 'delete_dns_record':
1492
+ case "delete_dns_record":
1299
1493
  return ad.deleteDnsRecord(args.agentId, args.recordId);
1300
- case 'get_renewal_status':
1494
+ case "get_renewal_status":
1301
1495
  return ad.getRenewalStatus(args.agentId);
1302
- case 'fund_renewal_vault':
1496
+ case "fund_renewal_vault":
1303
1497
  return ad.fundRenewalVault(args.agentId, args.amountUsdc);
1304
- case 'withdraw_renewal_vault':
1498
+ case "withdraw_renewal_vault":
1305
1499
  return ad.withdrawFromVault(args.agentId, args.amountUsdc);
1306
- case 'enable_auto_renew':
1500
+ case "enable_auto_renew":
1307
1501
  return ad.setAutoRenew(args.agentId, true);
1308
- case 'reconfigure_ssl':
1502
+ case "reconfigure_ssl":
1309
1503
  return ad.reconfigureSsl(args.agentId);
1310
- case 'get_service_plan':
1504
+ case "get_service_plan":
1311
1505
  return ad.getServicePlan(args.agentId);
1312
- case 'purchase_service_plan':
1506
+ case "purchase_service_plan":
1313
1507
  return ad.purchaseServicePlan({
1314
1508
  agentId: args.agentId,
1315
1509
  plan: args.plan,
1316
1510
  });
1317
- case 'set_registry_visibility':
1511
+ case "set_registry_visibility":
1318
1512
  return ad.setRegistryVisibility(args.agentId, Boolean(args.registryHidden ?? args.hidden));
1319
- case 'schedule_service_plan_renewal':
1513
+ case "schedule_service_plan_renewal":
1320
1514
  return ad.scheduleServicePlanRenewal(args.agentId, {
1321
1515
  plan: args.plan,
1322
1516
  planSku: args.planSku,
@@ -1326,26 +1520,32 @@ export async function runAgentDomainTool(ad, name, args) {
1326
1520
  }
1327
1521
  }
1328
1522
  function readDnsRecordArgs(args) {
1329
- const record = args.record && typeof args.record === 'object'
1523
+ const record = args.record && typeof args.record === "object"
1330
1524
  ? args.record
1331
1525
  : args;
1332
1526
  return {
1333
1527
  type: record.type,
1334
1528
  name: record.name,
1335
1529
  value: record.value,
1530
+ data: record.data,
1336
1531
  ttl: record.ttl,
1337
1532
  priority: record.priority,
1338
1533
  };
1339
1534
  }
1535
+ function assertDnsRevision(value) {
1536
+ if (!/^[a-f0-9]{64}$/i.test(value)) {
1537
+ throw new Error("DNS apply requires the 64-character baseRevision returned by a fresh preview.");
1538
+ }
1539
+ }
1340
1540
  export function formatAgentDomainToolResult(result) {
1341
- return typeof result === 'string' ? result : JSON.stringify(result, null, 2);
1541
+ return typeof result === "string" ? result : JSON.stringify(result, null, 2);
1342
1542
  }
1343
1543
  async function responseError(res) {
1344
1544
  try {
1345
1545
  const body = (await res.json());
1346
1546
  const detail = body.message ?? body.error;
1347
1547
  const code = body.code ?? body.error;
1348
- const retryAfter = body.details && typeof body.details === 'object'
1548
+ const retryAfter = body.details && typeof body.details === "object"
1349
1549
  ? body.details.retryAfterSeconds
1350
1550
  : undefined;
1351
1551
  const detailsMessage = detailsToMessage(body.details);
@@ -1358,7 +1558,7 @@ async function responseError(res) {
1358
1558
  parts.push(`: ${detailsMessage}`);
1359
1559
  if (retryAfter)
1360
1560
  parts.push(`(retry after ${retryAfter}s)`);
1361
- return parts.join('');
1561
+ return parts.join("");
1362
1562
  }
1363
1563
  catch {
1364
1564
  return `HTTP ${res.status}`;
@@ -1367,14 +1567,14 @@ async function responseError(res) {
1367
1567
  function detailsToMessage(details) {
1368
1568
  if (!details)
1369
1569
  return null;
1370
- if (typeof details === 'string')
1570
+ if (typeof details === "string")
1371
1571
  return details;
1372
- if (typeof details !== 'object')
1572
+ if (typeof details !== "object")
1373
1573
  return String(details);
1374
1574
  const record = details;
1375
- if (typeof record.message === 'string')
1575
+ if (typeof record.message === "string")
1376
1576
  return record.message;
1377
- if (typeof record.error === 'string')
1577
+ if (typeof record.error === "string")
1378
1578
  return record.error;
1379
1579
  try {
1380
1580
  return JSON.stringify(details);