@muxoai/platform 1.3.1 → 1.3.3

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.
@@ -211,7 +211,103 @@ export class ComposioInstantAdapter {
211
211
  }
212
212
  async executeTool(params) {
213
213
  const { tool, input } = params;
214
- const activeComposioKey = params.composioApiKey || this.config.composioApiKey;
214
+ const isMasterWalletEmpty = Boolean(params.masterWalletDepleted) ||
215
+ process.env.MUXO_MASTER_WALLET_DEPLETED === "true" ||
216
+ input._simulateMasterWalletEmpty === true;
217
+ const hasCustomerByok = Boolean((params.composioApiKey && params.composioApiKey.trim()) ||
218
+ (params.exaApiKey && params.exaApiKey.trim()) ||
219
+ (params.firecrawlApiKey && params.firecrawlApiKey.trim()));
220
+ const activeComposioKey = params.composioApiKey || (isMasterWalletEmpty ? null : this.config.composioApiKey);
221
+ const finalizeInstantResult = (res) => {
222
+ if (isMasterWalletEmpty && !hasCustomerByok) {
223
+ return {
224
+ ...res,
225
+ masterWalletFailover: "zero_cost_native_edge",
226
+ fundingSource: "zero_cost_native_edge_failover",
227
+ };
228
+ }
229
+ if (hasCustomerByok) {
230
+ return {
231
+ ...res,
232
+ fundingSource: "customer_byok",
233
+ };
234
+ }
235
+ return res;
236
+ };
237
+ // 0. Try Customer BYOK Exa / Firecrawl keys if configured
238
+ if (tool.slug === "instant.web.search" && params.exaApiKey) {
239
+ const query = String(input.query || "").trim();
240
+ const limit = Math.min(10, Math.max(1, Number(input.limit || 5)));
241
+ if (query) {
242
+ try {
243
+ const exaRes = await fetch("https://api.exa.ai/search", {
244
+ method: "POST",
245
+ headers: {
246
+ "x-api-key": params.exaApiKey,
247
+ "Content-Type": "application/json",
248
+ },
249
+ body: JSON.stringify({ query, numResults: limit, type: "auto" }),
250
+ signal: AbortSignal.timeout(8000),
251
+ });
252
+ if (exaRes.ok) {
253
+ const exaJson = (await exaRes.json());
254
+ if (Array.isArray(exaJson.results) && exaJson.results.length > 0) {
255
+ return finalizeInstantResult({
256
+ provider: "composio_instant",
257
+ billingMode: "customer_byok",
258
+ tool: tool.slug,
259
+ query,
260
+ results: exaJson.results.slice(0, limit).map((r) => ({
261
+ title: String(r.title || r.url || ""),
262
+ url: String(r.url || ""),
263
+ snippet: String(r.text || r.highlight || `Author: ${r.author || "web"}`),
264
+ source: "exa_byok",
265
+ })),
266
+ });
267
+ }
268
+ }
269
+ }
270
+ catch {
271
+ // Fall through to native edge search
272
+ }
273
+ }
274
+ }
275
+ if (tool.slug === "instant.web.scrape" && params.firecrawlApiKey) {
276
+ const targetUrl = String(input.url || "").trim();
277
+ const maxChars = Math.min(20000, Math.max(500, Number(input.maxChars || 4000)));
278
+ if (/^https?:\/\//i.test(targetUrl)) {
279
+ try {
280
+ const fcRes = await fetch("https://api.firecrawl.dev/v1/scrape", {
281
+ method: "POST",
282
+ headers: {
283
+ Authorization: `Bearer ${params.firecrawlApiKey}`,
284
+ "Content-Type": "application/json",
285
+ },
286
+ body: JSON.stringify({ url: targetUrl, formats: ["markdown"] }),
287
+ signal: AbortSignal.timeout(10000),
288
+ });
289
+ if (fcRes.ok) {
290
+ const fcJson = (await fcRes.json());
291
+ const md = String(fcJson.data?.markdown || "").slice(0, maxChars);
292
+ if (md) {
293
+ return finalizeInstantResult({
294
+ provider: "composio_instant",
295
+ billingMode: "customer_byok",
296
+ tool: tool.slug,
297
+ url: targetUrl,
298
+ statusCode: 200,
299
+ title: String(fcJson.data?.metadata?.title || targetUrl),
300
+ contentLength: md.length,
301
+ excerpt: md,
302
+ });
303
+ }
304
+ }
305
+ }
306
+ catch {
307
+ // Fall through to native edge scrape
308
+ }
309
+ }
310
+ }
215
311
  // 1. Try Composio Instant / No-Auth tool execution first if applicable
216
312
  if (activeComposioKey && tool.upstreamSlug.startsWith("COMPOSIO_")) {
217
313
  try {
@@ -244,572 +340,575 @@ export class ComposioInstantAdapter {
244
340
  }
245
341
  }
246
342
  // 2. High-availability live Instant executors
247
- if (tool.slug === "instant.hackernews.top_stories") {
248
- const limit = Math.min(15, Math.max(1, Number(input.limit || 5)));
249
- const idsRes = await fetch("https://hacker-news.firebaseio.com/v0/topstories.json", { signal: AbortSignal.timeout(8000) });
250
- const ids = (await idsRes.json()).slice(0, limit);
251
- const stories = await Promise.all(ids.map(async (id) => {
252
- const itemRes = await fetch(`https://hacker-news.firebaseio.com/v0/item/${id}.json`, { signal: AbortSignal.timeout(6000) });
253
- const item = (await itemRes.json());
343
+ const runNativeEdgeExecutor = async () => {
344
+ if (tool.slug === "instant.hackernews.top_stories") {
345
+ const limit = Math.min(15, Math.max(1, Number(input.limit || 5)));
346
+ const idsRes = await fetch("https://hacker-news.firebaseio.com/v0/topstories.json", { signal: AbortSignal.timeout(8000) });
347
+ const ids = (await idsRes.json()).slice(0, limit);
348
+ const stories = await Promise.all(ids.map(async (id) => {
349
+ const itemRes = await fetch(`https://hacker-news.firebaseio.com/v0/item/${id}.json`, { signal: AbortSignal.timeout(6000) });
350
+ const item = (await itemRes.json());
351
+ return {
352
+ id: item.id,
353
+ title: item.title,
354
+ url: item.url || `https://news.ycombinator.com/item?id=${item.id}`,
355
+ score: item.score,
356
+ by: item.by,
357
+ comments: item.descendants || 0,
358
+ };
359
+ }));
254
360
  return {
255
- id: item.id,
256
- title: item.title,
257
- url: item.url || `https://news.ycombinator.com/item?id=${item.id}`,
258
- score: item.score,
259
- by: item.by,
260
- comments: item.descendants || 0,
361
+ provider: "composio_instant",
362
+ billingMode: "provider_wallet",
363
+ tool: tool.slug,
364
+ stories,
261
365
  };
262
- }));
263
- return {
264
- provider: "composio_instant",
265
- billingMode: "provider_wallet",
266
- tool: tool.slug,
267
- stories,
268
- };
269
- }
270
- if (tool.slug === "instant.github.repo_intel") {
271
- const owner = String(input.owner || "").trim();
272
- const repo = String(input.repo || "").trim();
273
- if (!owner || !repo)
274
- throw new Error("owner and repo are required");
275
- const res = await fetch(`https://api.github.com/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}`, {
276
- headers: {
277
- Accept: "application/vnd.github+json",
278
- "User-Agent": "Muxo-Instant-Agent/1.0",
279
- },
280
- signal: AbortSignal.timeout(8000),
281
- });
282
- if (!res.ok) {
283
- throw new Error(`GitHub lookup returned HTTP ${res.status}`);
284
366
  }
285
- const data = (await res.json());
286
- return {
287
- provider: "composio_instant",
288
- billingMode: "provider_wallet",
289
- tool: tool.slug,
290
- repository: {
291
- fullName: data.full_name,
292
- description: data.description,
293
- stars: data.stargazers_count,
294
- forks: data.forks_count,
295
- openIssues: data.open_issues_count,
296
- language: data.language,
297
- defaultBranch: data.default_branch,
298
- license: data.license?.spdx_id || null,
299
- updatedAt: data.updated_at,
300
- htmlUrl: data.html_url,
301
- },
302
- };
303
- }
304
- if (tool.slug === "instant.dns.lookup") {
305
- const domain = String(input.domain || input.hostname || "").trim();
306
- const type = String(input.type || "A").toUpperCase();
307
- if (!domain)
308
- throw new Error("domain is required");
309
- const url = `https://cloudflare-dns.com/dns-query?name=${encodeURIComponent(domain)}&type=${encodeURIComponent(type)}`;
310
- const res = await fetch(url, {
311
- headers: { Accept: "application/dns-json" },
312
- signal: AbortSignal.timeout(6000),
313
- });
314
- const data = (await res.json());
315
- return {
316
- provider: "composio_instant",
317
- billingMode: "provider_wallet",
318
- tool: tool.slug,
319
- domain,
320
- recordType: type,
321
- status: data.Status,
322
- answers: data.Answer || [],
323
- };
324
- }
325
- if (tool.slug === "instant.web.scrape") {
326
- const targetUrl = String(input.url || "").trim();
327
- const maxChars = Math.min(20000, Math.max(500, Number(input.maxChars || 4000)));
328
- if (!/^https?:\/\//i.test(targetUrl)) {
329
- throw new Error("url must start with http:// or https://");
367
+ if (tool.slug === "instant.github.repo_intel") {
368
+ const owner = String(input.owner || "").trim();
369
+ const repo = String(input.repo || "").trim();
370
+ if (!owner || !repo)
371
+ throw new Error("owner and repo are required");
372
+ const res = await fetch(`https://api.github.com/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}`, {
373
+ headers: {
374
+ Accept: "application/vnd.github+json",
375
+ "User-Agent": "Muxo-Instant-Agent/1.0",
376
+ },
377
+ signal: AbortSignal.timeout(8000),
378
+ });
379
+ if (!res.ok) {
380
+ throw new Error(`GitHub lookup returned HTTP ${res.status}`);
381
+ }
382
+ const data = (await res.json());
383
+ return {
384
+ provider: "composio_instant",
385
+ billingMode: "provider_wallet",
386
+ tool: tool.slug,
387
+ repository: {
388
+ fullName: data.full_name,
389
+ description: data.description,
390
+ stars: data.stargazers_count,
391
+ forks: data.forks_count,
392
+ openIssues: data.open_issues_count,
393
+ language: data.language,
394
+ defaultBranch: data.default_branch,
395
+ license: data.license?.spdx_id || null,
396
+ updatedAt: data.updated_at,
397
+ htmlUrl: data.html_url,
398
+ },
399
+ };
330
400
  }
331
- const res = await fetch(targetUrl, {
332
- headers: {
333
- "User-Agent": "Mozilla/5.0 (compatible; MuxoInstantBot/1.0; +https://muxo.ai)",
334
- Accept: "text/html,application/xhtml+xml,text/plain,application/json",
335
- },
336
- signal: AbortSignal.timeout(12000),
337
- });
338
- const raw = await res.text();
339
- const titleMatch = raw.match(/<title[^>]*>([\s\S]*?)<\/title>/i);
340
- const title = titleMatch ? titleMatch[1].replace(/\s+/g, " ").trim() : targetUrl;
341
- const text = raw
342
- .replace(/<script[\s\S]*?<\/script>/gi, " ")
343
- .replace(/<style[\s\S]*?<\/style>/gi, " ")
344
- .replace(/<[^>]+>/g, " ")
345
- .replace(/\s+/g, " ")
346
- .trim()
347
- .slice(0, maxChars);
348
- return {
349
- provider: "composio_instant",
350
- billingMode: "provider_wallet",
351
- tool: tool.slug,
352
- url: targetUrl,
353
- statusCode: res.status,
354
- title,
355
- contentLength: text.length,
356
- excerpt: text,
357
- };
358
- }
359
- if (tool.slug === "instant.web.crawl") {
360
- const rawUrl = String(input.url || "").trim();
361
- if (!rawUrl)
362
- throw new Error("url is required");
363
- const rootUrl = /^https?:\/\//i.test(rawUrl) ? rawUrl : `https://${rawUrl}`;
364
- const maxPages = Math.min(15, Math.max(1, Number(input.maxPages || 5)));
365
- const includeSubdomains = input.includeSubdomains !== false;
366
- const rootParsed = new URL(rootUrl);
367
- const baseDomain = rootParsed.hostname.replace(/^www\./i, "").toLowerCase();
368
- const isAllowedHost = (host) => {
369
- const h = host.toLowerCase();
370
- if (h === rootParsed.hostname.toLowerCase() || h === baseDomain)
371
- return true;
372
- return includeSubdomains && h.endsWith(`.${baseDomain}`);
373
- };
374
- const discoveredSet = new Set([rootParsed.toString()]);
375
- const extractLinksFromBody = (body, pageUrl) => {
376
- const hrefRegex = /href=["']([^"'#]+)["']/gi;
377
- let m;
378
- while ((m = hrefRegex.exec(body)) !== null) {
379
- try {
380
- const resolved = new URL(m[1].trim(), pageUrl);
381
- if ((resolved.protocol === "http:" || resolved.protocol === "https:") &&
382
- isAllowedHost(resolved.hostname)) {
383
- resolved.hash = "";
384
- discoveredSet.add(resolved.toString());
401
+ if (tool.slug === "instant.dns.lookup") {
402
+ const domain = String(input.domain || input.hostname || "").trim();
403
+ const type = String(input.type || "A").toUpperCase();
404
+ if (!domain)
405
+ throw new Error("domain is required");
406
+ const url = `https://cloudflare-dns.com/dns-query?name=${encodeURIComponent(domain)}&type=${encodeURIComponent(type)}`;
407
+ const res = await fetch(url, {
408
+ headers: { Accept: "application/dns-json" },
409
+ signal: AbortSignal.timeout(6000),
410
+ });
411
+ const data = (await res.json());
412
+ return {
413
+ provider: "composio_instant",
414
+ billingMode: "provider_wallet",
415
+ tool: tool.slug,
416
+ domain,
417
+ recordType: type,
418
+ status: data.Status,
419
+ answers: data.Answer || [],
420
+ };
421
+ }
422
+ if (tool.slug === "instant.web.scrape") {
423
+ const targetUrl = String(input.url || "").trim();
424
+ const maxChars = Math.min(20000, Math.max(500, Number(input.maxChars || 4000)));
425
+ if (!/^https?:\/\//i.test(targetUrl)) {
426
+ throw new Error("url must start with http:// or https://");
427
+ }
428
+ const res = await fetch(targetUrl, {
429
+ headers: {
430
+ "User-Agent": "Mozilla/5.0 (compatible; MuxoInstantBot/1.0; +https://muxo.ai)",
431
+ Accept: "text/html,application/xhtml+xml,text/plain,application/json",
432
+ },
433
+ signal: AbortSignal.timeout(12000),
434
+ });
435
+ const raw = await res.text();
436
+ const titleMatch = raw.match(/<title[^>]*>([\s\S]*?)<\/title>/i);
437
+ const title = titleMatch ? titleMatch[1].replace(/\s+/g, " ").trim() : targetUrl;
438
+ const text = raw
439
+ .replace(/<script[\s\S]*?<\/script>/gi, " ")
440
+ .replace(/<style[\s\S]*?<\/style>/gi, " ")
441
+ .replace(/<[^>]+>/g, " ")
442
+ .replace(/\s+/g, " ")
443
+ .trim()
444
+ .slice(0, maxChars);
445
+ return {
446
+ provider: "composio_instant",
447
+ billingMode: "provider_wallet",
448
+ tool: tool.slug,
449
+ url: targetUrl,
450
+ statusCode: res.status,
451
+ title,
452
+ contentLength: text.length,
453
+ excerpt: text,
454
+ };
455
+ }
456
+ if (tool.slug === "instant.web.crawl") {
457
+ const rawUrl = String(input.url || "").trim();
458
+ if (!rawUrl)
459
+ throw new Error("url is required");
460
+ const rootUrl = /^https?:\/\//i.test(rawUrl) ? rawUrl : `https://${rawUrl}`;
461
+ const maxPages = Math.min(15, Math.max(1, Number(input.maxPages || 5)));
462
+ const includeSubdomains = input.includeSubdomains !== false;
463
+ const rootParsed = new URL(rootUrl);
464
+ const baseDomain = rootParsed.hostname.replace(/^www\./i, "").toLowerCase();
465
+ const isAllowedHost = (host) => {
466
+ const h = host.toLowerCase();
467
+ if (h === rootParsed.hostname.toLowerCase() || h === baseDomain)
468
+ return true;
469
+ return includeSubdomains && h.endsWith(`.${baseDomain}`);
470
+ };
471
+ const discoveredSet = new Set([rootParsed.toString()]);
472
+ const extractLinksFromBody = (body, pageUrl) => {
473
+ const hrefRegex = /href=["']([^"'#]+)["']/gi;
474
+ let m;
475
+ while ((m = hrefRegex.exec(body)) !== null) {
476
+ try {
477
+ const resolved = new URL(m[1].trim(), pageUrl);
478
+ if ((resolved.protocol === "http:" || resolved.protocol === "https:") &&
479
+ isAllowedHost(resolved.hostname)) {
480
+ resolved.hash = "";
481
+ discoveredSet.add(resolved.toString());
482
+ }
483
+ }
484
+ catch {
485
+ // ignore malformed href
385
486
  }
386
487
  }
387
- catch {
388
- // ignore malformed href
488
+ const mdUrlRegex = /https?:\/\/[a-zA-Z0-9._~:/?#[\]@!$&'()*+,;=-]+/g;
489
+ let u;
490
+ while ((u = mdUrlRegex.exec(body)) !== null) {
491
+ try {
492
+ const clean = u[0].replace(/[),.;'`"]+$/, "");
493
+ const resolved = new URL(clean);
494
+ if (isAllowedHost(resolved.hostname)) {
495
+ resolved.hash = "";
496
+ discoveredSet.add(resolved.toString());
497
+ }
498
+ }
499
+ catch {
500
+ // ignore
501
+ }
389
502
  }
503
+ };
504
+ // Fetch root page + llms.txt + sitemap.xml in parallel to discover URLs
505
+ const [rootRes, llmsRes, sitemapRes] = await Promise.allSettled([
506
+ fetch(rootUrl, {
507
+ headers: {
508
+ "User-Agent": "Mozilla/5.0 (compatible; MuxoInstantCrawler/1.2; +https://muxo.ai)",
509
+ Accept: "text/html,application/xhtml+xml,text/plain",
510
+ },
511
+ signal: AbortSignal.timeout(10000),
512
+ }),
513
+ fetch(new URL("/llms.txt", rootParsed.origin).toString(), {
514
+ headers: { "User-Agent": "MuxoInstantCrawler/1.2" },
515
+ signal: AbortSignal.timeout(6000),
516
+ }),
517
+ fetch(new URL("/sitemap.xml", rootParsed.origin).toString(), {
518
+ headers: { "User-Agent": "MuxoInstantCrawler/1.2" },
519
+ signal: AbortSignal.timeout(6000),
520
+ }),
521
+ ]);
522
+ let rootHtml = "";
523
+ let rootStatus = 200;
524
+ if (rootRes.status === "fulfilled") {
525
+ rootStatus = rootRes.value.status;
526
+ rootHtml = await rootRes.value.text();
527
+ extractLinksFromBody(rootHtml, rootUrl);
528
+ }
529
+ if (llmsRes.status === "fulfilled" && llmsRes.value.ok) {
530
+ const llmsTxt = await llmsRes.value.text();
531
+ extractLinksFromBody(llmsTxt, rootUrl);
532
+ }
533
+ if (sitemapRes.status === "fulfilled" && sitemapRes.value.ok) {
534
+ const smTxt = await sitemapRes.value.text();
535
+ extractLinksFromBody(smTxt, rootUrl);
390
536
  }
391
- const mdUrlRegex = /https?:\/\/[a-zA-Z0-9._~:/?#[\]@!$&'()*+,;=-]+/g;
392
- let u;
393
- while ((u = mdUrlRegex.exec(body)) !== null) {
537
+ const discoveredUrls = Array.from(discoveredSet);
538
+ const targetsToCrawl = discoveredUrls.slice(0, maxPages);
539
+ const parsePageSummary = (url, status, html) => {
540
+ const titleMatch = html.match(/<title[^>]*>([\s\S]*?)<\/title>/i);
541
+ const descMatch = html.match(/<meta[^>]+name=["']description["'][^>]+content=["']([^"']*)["']/i) ||
542
+ html.match(/<meta[^>]+content=["']([^"']*)["'][^>]+name=["']description["']/i);
543
+ const h1Match = html.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i);
544
+ const cleanText = html
545
+ .replace(/<script[\s\S]*?<\/script>/gi, " ")
546
+ .replace(/<style[\s\S]*?<\/style>/gi, " ")
547
+ .replace(/<[^>]+>/g, " ")
548
+ .replace(/\s+/g, " ")
549
+ .trim();
550
+ const words = cleanText ? cleanText.split(/\s+/).length : 0;
551
+ return {
552
+ url,
553
+ statusCode: status,
554
+ title: titleMatch
555
+ ? titleMatch[1].replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim()
556
+ : url,
557
+ description: descMatch ? descMatch[1].trim() : cleanText.slice(0, 180),
558
+ h1: h1Match
559
+ ? h1Match[1].replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim()
560
+ : null,
561
+ wordCount: words,
562
+ excerpt: cleanText.slice(0, 500),
563
+ };
564
+ };
565
+ const pages = await Promise.all(targetsToCrawl.map(async (pageUrl, idx) => {
566
+ if (idx === 0 && rootHtml) {
567
+ return parsePageSummary(pageUrl, rootStatus, rootHtml);
568
+ }
394
569
  try {
395
- const clean = u[0].replace(/[),.;'`"]+$/, "");
396
- const resolved = new URL(clean);
397
- if (isAllowedHost(resolved.hostname)) {
398
- resolved.hash = "";
399
- discoveredSet.add(resolved.toString());
570
+ const r = await fetch(pageUrl, {
571
+ headers: {
572
+ "User-Agent": "Mozilla/5.0 (compatible; MuxoInstantCrawler/1.2; +https://muxo.ai)",
573
+ },
574
+ signal: AbortSignal.timeout(8000),
575
+ });
576
+ const body = await r.text();
577
+ extractLinksFromBody(body, pageUrl);
578
+ return parsePageSummary(pageUrl, r.status, body);
579
+ }
580
+ catch (err) {
581
+ return {
582
+ url: pageUrl,
583
+ statusCode: 0,
584
+ title: pageUrl,
585
+ description: String(err?.message || "Fetch failed"),
586
+ h1: null,
587
+ wordCount: 0,
588
+ excerpt: "",
589
+ };
590
+ }
591
+ }));
592
+ const allDiscovered = Array.from(discoveredSet);
593
+ return {
594
+ provider: "composio_instant",
595
+ billingMode: "provider_wallet",
596
+ upstreamTool: tool.upstreamSlug,
597
+ tool: tool.slug,
598
+ rootUrl,
599
+ baseDomain,
600
+ pagesCrawled: pages.length,
601
+ totalDiscoveredUrls: allDiscovered.length,
602
+ discoveredUrls: allDiscovered.slice(0, 50),
603
+ pages,
604
+ };
605
+ }
606
+ if (tool.slug === "instant.seo.audit") {
607
+ const rawUrl = String(input.url || "").trim();
608
+ if (!rawUrl)
609
+ throw new Error("url is required");
610
+ const targetUrl = /^https?:\/\//i.test(rawUrl) ? rawUrl : `https://${rawUrl}`;
611
+ const parsed = new URL(targetUrl);
612
+ const domain = parsed.hostname.replace(/^www\./i, "").toLowerCase();
613
+ const targetKeywords = Array.isArray(input.keywords)
614
+ ? input.keywords.map((k) => String(k).trim().toLowerCase()).filter(Boolean)
615
+ : [];
616
+ const started = Date.now();
617
+ const [pageRes, robotsRes, sitemapRes, llmsRes, dnsARes, dnsTxtRes] = await Promise.allSettled([
618
+ fetch(targetUrl, {
619
+ headers: {
620
+ "User-Agent": "Mozilla/5.0 (compatible; MuxoSEOAuditor/1.2; +https://muxo.ai)",
621
+ Accept: "text/html,application/xhtml+xml",
622
+ },
623
+ signal: AbortSignal.timeout(10000),
624
+ }),
625
+ fetch(new URL("/robots.txt", parsed.origin).toString(), {
626
+ signal: AbortSignal.timeout(5000),
627
+ }),
628
+ fetch(new URL("/sitemap.xml", parsed.origin).toString(), {
629
+ signal: AbortSignal.timeout(5000),
630
+ }),
631
+ fetch(new URL("/llms.txt", parsed.origin).toString(), {
632
+ signal: AbortSignal.timeout(5000),
633
+ }),
634
+ fetch(`https://cloudflare-dns.com/dns-query?name=${encodeURIComponent(domain)}&type=A`, { headers: { Accept: "application/dns-json" }, signal: AbortSignal.timeout(5000) }).then((r) => r.json()),
635
+ fetch(`https://cloudflare-dns.com/dns-query?name=${encodeURIComponent(domain)}&type=TXT`, { headers: { Accept: "application/dns-json" }, signal: AbortSignal.timeout(5000) }).then((r) => r.json()),
636
+ ]);
637
+ const responseTimeMs = Date.now() - started;
638
+ if (pageRes.status !== "fulfilled") {
639
+ throw new Error(`Failed to fetch ${targetUrl} for SEO audit`);
640
+ }
641
+ const res = pageRes.value;
642
+ const html = await res.text();
643
+ const statusCode = res.status;
644
+ const serverHeader = res.headers.get("server") || "unknown";
645
+ const titleMatch = html.match(/<title[^>]*>([\s\S]*?)<\/title>/i);
646
+ const title = titleMatch
647
+ ? titleMatch[1].replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim()
648
+ : "";
649
+ const metaDescMatch = html.match(/<meta[^>]+name=["']description["'][^>]+content=["']([^"']*)["']/i) ||
650
+ html.match(/<meta[^>]+content=["']([^"']*)["'][^>]+name=["']description["']/i);
651
+ const metaDescription = metaDescMatch ? metaDescMatch[1].trim() : "";
652
+ const canonicalMatch = html.match(/<link[^>]+rel=["']canonical["'][^>]+href=["']([^"']*)["']/i);
653
+ const canonicalUrl = canonicalMatch ? canonicalMatch[1].trim() : null;
654
+ const ogTitleMatch = html.match(/<meta[^>]+property=["']og:title["'][^>]+content=["']([^"']*)["']/i) ||
655
+ html.match(/<meta[^>]+content=["']([^"']*)["'][^>]+property=["']og:title["']/i);
656
+ const ogDescMatch = html.match(/<meta[^>]+property=["']og:description["'][^>]+content=["']([^"']*)["']/i) ||
657
+ html.match(/<meta[^>]+content=["']([^"']*)["'][^>]+property=["']og:description["']/i);
658
+ const ogImageMatch = html.match(/<meta[^>]+property=["']og:image["'][^>]+content=["']([^"']*)["']/i) ||
659
+ html.match(/<meta[^>]+content=["']([^"']*)["'][^>]+property=["']og:image["']/i);
660
+ const extractHeadings = (tag) => {
661
+ const regex = new RegExp(`<${tag}[^>]*>([\\s\\S]*?)<\\/${tag}>`, "gi");
662
+ const list = [];
663
+ let m;
664
+ while ((m = regex.exec(html)) !== null) {
665
+ const text = m[1].replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
666
+ if (text)
667
+ list.push(text);
668
+ }
669
+ return list;
670
+ };
671
+ const h1s = extractHeadings("h1");
672
+ const h2s = extractHeadings("h2");
673
+ const h3s = extractHeadings("h3");
674
+ const imgTags = html.match(/<img\b[^>]*>/gi) || [];
675
+ const imgsWithAlt = imgTags.filter((tag) => /\balt=["'][^"']+["']/i.test(tag));
676
+ const hrefRegex = /href=["']([^"'#]+)["']/gi;
677
+ let internalLinks = 0;
678
+ let externalLinks = 0;
679
+ const subdomains = new Set();
680
+ let hm;
681
+ while ((hm = hrefRegex.exec(html)) !== null) {
682
+ try {
683
+ const u = new URL(hm[1].trim(), targetUrl);
684
+ if (u.protocol !== "http:" && u.protocol !== "https:")
685
+ continue;
686
+ const h = u.hostname.toLowerCase();
687
+ if (h === domain || h.endsWith(`.${domain}`)) {
688
+ internalLinks += 1;
689
+ if (h !== domain)
690
+ subdomains.add(h);
691
+ }
692
+ else {
693
+ externalLinks += 1;
400
694
  }
401
695
  }
402
696
  catch {
403
697
  // ignore
404
698
  }
405
699
  }
406
- };
407
- // Fetch root page + llms.txt + sitemap.xml in parallel to discover URLs
408
- const [rootRes, llmsRes, sitemapRes] = await Promise.allSettled([
409
- fetch(rootUrl, {
410
- headers: {
411
- "User-Agent": "Mozilla/5.0 (compatible; MuxoInstantCrawler/1.2; +https://muxo.ai)",
412
- Accept: "text/html,application/xhtml+xml,text/plain",
413
- },
414
- signal: AbortSignal.timeout(10000),
415
- }),
416
- fetch(new URL("/llms.txt", rootParsed.origin).toString(), {
417
- headers: { "User-Agent": "MuxoInstantCrawler/1.2" },
418
- signal: AbortSignal.timeout(6000),
419
- }),
420
- fetch(new URL("/sitemap.xml", rootParsed.origin).toString(), {
421
- headers: { "User-Agent": "MuxoInstantCrawler/1.2" },
422
- signal: AbortSignal.timeout(6000),
423
- }),
424
- ]);
425
- let rootHtml = "";
426
- let rootStatus = 200;
427
- if (rootRes.status === "fulfilled") {
428
- rootStatus = rootRes.value.status;
429
- rootHtml = await rootRes.value.text();
430
- extractLinksFromBody(rootHtml, rootUrl);
431
- }
432
- if (llmsRes.status === "fulfilled" && llmsRes.value.ok) {
433
- const llmsTxt = await llmsRes.value.text();
434
- extractLinksFromBody(llmsTxt, rootUrl);
435
- }
436
- if (sitemapRes.status === "fulfilled" && sitemapRes.value.ok) {
437
- const smTxt = await sitemapRes.value.text();
438
- extractLinksFromBody(smTxt, rootUrl);
439
- }
440
- const discoveredUrls = Array.from(discoveredSet);
441
- const targetsToCrawl = discoveredUrls.slice(0, maxPages);
442
- const parsePageSummary = (url, status, html) => {
443
- const titleMatch = html.match(/<title[^>]*>([\s\S]*?)<\/title>/i);
444
- const descMatch = html.match(/<meta[^>]+name=["']description["'][^>]+content=["']([^"']*)["']/i) ||
445
- html.match(/<meta[^>]+content=["']([^"']*)["'][^>]+name=["']description["']/i);
446
- const h1Match = html.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i);
700
+ const jsonLdMatches = html.match(/<script[^>]+type=["']application\/ld\+json["'][^>]*>/gi) || [];
447
701
  const cleanText = html
448
702
  .replace(/<script[\s\S]*?<\/script>/gi, " ")
449
703
  .replace(/<style[\s\S]*?<\/style>/gi, " ")
450
704
  .replace(/<[^>]+>/g, " ")
451
705
  .replace(/\s+/g, " ")
452
706
  .trim();
453
- const words = cleanText ? cleanText.split(/\s+/).length : 0;
454
- return {
455
- url,
456
- statusCode: status,
457
- title: titleMatch
458
- ? titleMatch[1].replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim()
459
- : url,
460
- description: descMatch ? descMatch[1].trim() : cleanText.slice(0, 180),
461
- h1: h1Match
462
- ? h1Match[1].replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim()
463
- : null,
464
- wordCount: words,
465
- excerpt: cleanText.slice(0, 500),
466
- };
467
- };
468
- const pages = await Promise.all(targetsToCrawl.map(async (pageUrl, idx) => {
469
- if (idx === 0 && rootHtml) {
470
- return parsePageSummary(pageUrl, rootStatus, rootHtml);
707
+ const wordCount = cleanText ? cleanText.split(/\s+/).length : 0;
708
+ const hasRobotsTxt = robotsRes.status === "fulfilled" && robotsRes.value.status === 200;
709
+ const hasSitemapXml = sitemapRes.status === "fulfilled" && sitemapRes.value.status === 200;
710
+ const hasLlmsTxt = llmsRes.status === "fulfilled" && llmsRes.value.status === 200;
711
+ const passedChecks = [];
712
+ const warnings = [];
713
+ let score = 100;
714
+ if (parsed.protocol === "https:") {
715
+ passedChecks.push("HTTPS encryption active");
471
716
  }
472
- try {
473
- const r = await fetch(pageUrl, {
474
- headers: {
475
- "User-Agent": "Mozilla/5.0 (compatible; MuxoInstantCrawler/1.2; +https://muxo.ai)",
476
- },
477
- signal: AbortSignal.timeout(8000),
478
- });
479
- const body = await r.text();
480
- extractLinksFromBody(body, pageUrl);
481
- return parsePageSummary(pageUrl, r.status, body);
717
+ else {
718
+ score -= 15;
719
+ warnings.push("Site is not served over HTTPS");
482
720
  }
483
- catch (err) {
484
- return {
485
- url: pageUrl,
486
- statusCode: 0,
487
- title: pageUrl,
488
- description: String(err?.message || "Fetch failed"),
489
- h1: null,
490
- wordCount: 0,
491
- excerpt: "",
492
- };
721
+ if (title.length >= 10 && title.length <= 70) {
722
+ passedChecks.push(`Title tag present and optimal length (${title.length} chars)`);
493
723
  }
494
- }));
495
- const allDiscovered = Array.from(discoveredSet);
496
- return {
497
- provider: "composio_instant",
498
- billingMode: "provider_wallet",
499
- upstreamTool: tool.upstreamSlug,
500
- tool: tool.slug,
501
- rootUrl,
502
- baseDomain,
503
- pagesCrawled: pages.length,
504
- totalDiscoveredUrls: allDiscovered.length,
505
- discoveredUrls: allDiscovered.slice(0, 50),
506
- pages,
507
- };
508
- }
509
- if (tool.slug === "instant.seo.audit") {
510
- const rawUrl = String(input.url || "").trim();
511
- if (!rawUrl)
512
- throw new Error("url is required");
513
- const targetUrl = /^https?:\/\//i.test(rawUrl) ? rawUrl : `https://${rawUrl}`;
514
- const parsed = new URL(targetUrl);
515
- const domain = parsed.hostname.replace(/^www\./i, "").toLowerCase();
516
- const targetKeywords = Array.isArray(input.keywords)
517
- ? input.keywords.map((k) => String(k).trim().toLowerCase()).filter(Boolean)
518
- : [];
519
- const started = Date.now();
520
- const [pageRes, robotsRes, sitemapRes, llmsRes, dnsARes, dnsTxtRes] = await Promise.allSettled([
521
- fetch(targetUrl, {
522
- headers: {
523
- "User-Agent": "Mozilla/5.0 (compatible; MuxoSEOAuditor/1.2; +https://muxo.ai)",
524
- Accept: "text/html,application/xhtml+xml",
525
- },
526
- signal: AbortSignal.timeout(10000),
527
- }),
528
- fetch(new URL("/robots.txt", parsed.origin).toString(), {
529
- signal: AbortSignal.timeout(5000),
530
- }),
531
- fetch(new URL("/sitemap.xml", parsed.origin).toString(), {
532
- signal: AbortSignal.timeout(5000),
533
- }),
534
- fetch(new URL("/llms.txt", parsed.origin).toString(), {
535
- signal: AbortSignal.timeout(5000),
536
- }),
537
- fetch(`https://cloudflare-dns.com/dns-query?name=${encodeURIComponent(domain)}&type=A`, { headers: { Accept: "application/dns-json" }, signal: AbortSignal.timeout(5000) }).then((r) => r.json()),
538
- fetch(`https://cloudflare-dns.com/dns-query?name=${encodeURIComponent(domain)}&type=TXT`, { headers: { Accept: "application/dns-json" }, signal: AbortSignal.timeout(5000) }).then((r) => r.json()),
539
- ]);
540
- const responseTimeMs = Date.now() - started;
541
- if (pageRes.status !== "fulfilled") {
542
- throw new Error(`Failed to fetch ${targetUrl} for SEO audit`);
543
- }
544
- const res = pageRes.value;
545
- const html = await res.text();
546
- const statusCode = res.status;
547
- const serverHeader = res.headers.get("server") || "unknown";
548
- const titleMatch = html.match(/<title[^>]*>([\s\S]*?)<\/title>/i);
549
- const title = titleMatch
550
- ? titleMatch[1].replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim()
551
- : "";
552
- const metaDescMatch = html.match(/<meta[^>]+name=["']description["'][^>]+content=["']([^"']*)["']/i) ||
553
- html.match(/<meta[^>]+content=["']([^"']*)["'][^>]+name=["']description["']/i);
554
- const metaDescription = metaDescMatch ? metaDescMatch[1].trim() : "";
555
- const canonicalMatch = html.match(/<link[^>]+rel=["']canonical["'][^>]+href=["']([^"']*)["']/i);
556
- const canonicalUrl = canonicalMatch ? canonicalMatch[1].trim() : null;
557
- const ogTitleMatch = html.match(/<meta[^>]+property=["']og:title["'][^>]+content=["']([^"']*)["']/i) ||
558
- html.match(/<meta[^>]+content=["']([^"']*)["'][^>]+property=["']og:title["']/i);
559
- const ogDescMatch = html.match(/<meta[^>]+property=["']og:description["'][^>]+content=["']([^"']*)["']/i) ||
560
- html.match(/<meta[^>]+content=["']([^"']*)["'][^>]+property=["']og:description["']/i);
561
- const ogImageMatch = html.match(/<meta[^>]+property=["']og:image["'][^>]+content=["']([^"']*)["']/i) ||
562
- html.match(/<meta[^>]+content=["']([^"']*)["'][^>]+property=["']og:image["']/i);
563
- const extractHeadings = (tag) => {
564
- const regex = new RegExp(`<${tag}[^>]*>([\\s\\S]*?)<\\/${tag}>`, "gi");
565
- const list = [];
566
- let m;
567
- while ((m = regex.exec(html)) !== null) {
568
- const text = m[1].replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
569
- if (text)
570
- list.push(text);
724
+ else if (title.length > 0) {
725
+ score -= 5;
726
+ warnings.push(`Title length (${title.length} chars) outside ideal 10-70 char range`);
571
727
  }
572
- return list;
573
- };
574
- const h1s = extractHeadings("h1");
575
- const h2s = extractHeadings("h2");
576
- const h3s = extractHeadings("h3");
577
- const imgTags = html.match(/<img\b[^>]*>/gi) || [];
578
- const imgsWithAlt = imgTags.filter((tag) => /\balt=["'][^"']+["']/i.test(tag));
579
- const hrefRegex = /href=["']([^"'#]+)["']/gi;
580
- let internalLinks = 0;
581
- let externalLinks = 0;
582
- const subdomains = new Set();
583
- let hm;
584
- while ((hm = hrefRegex.exec(html)) !== null) {
585
- try {
586
- const u = new URL(hm[1].trim(), targetUrl);
587
- if (u.protocol !== "http:" && u.protocol !== "https:")
588
- continue;
589
- const h = u.hostname.toLowerCase();
590
- if (h === domain || h.endsWith(`.${domain}`)) {
591
- internalLinks += 1;
592
- if (h !== domain)
593
- subdomains.add(h);
594
- }
595
- else {
596
- externalLinks += 1;
597
- }
728
+ else {
729
+ score -= 15;
730
+ warnings.push("Missing <title> tag");
598
731
  }
599
- catch {
600
- // ignore
732
+ if (metaDescription.length >= 50 && metaDescription.length <= 170) {
733
+ passedChecks.push(`Meta description present and optimal length (${metaDescription.length} chars)`);
601
734
  }
602
- }
603
- const jsonLdMatches = html.match(/<script[^>]+type=["']application\/ld\+json["'][^>]*>/gi) || [];
604
- const cleanText = html
605
- .replace(/<script[\s\S]*?<\/script>/gi, " ")
606
- .replace(/<style[\s\S]*?<\/style>/gi, " ")
607
- .replace(/<[^>]+>/g, " ")
608
- .replace(/\s+/g, " ")
609
- .trim();
610
- const wordCount = cleanText ? cleanText.split(/\s+/).length : 0;
611
- const hasRobotsTxt = robotsRes.status === "fulfilled" && robotsRes.value.status === 200;
612
- const hasSitemapXml = sitemapRes.status === "fulfilled" && sitemapRes.value.status === 200;
613
- const hasLlmsTxt = llmsRes.status === "fulfilled" && llmsRes.value.status === 200;
614
- const passedChecks = [];
615
- const warnings = [];
616
- let score = 100;
617
- if (parsed.protocol === "https:") {
618
- passedChecks.push("HTTPS encryption active");
619
- }
620
- else {
621
- score -= 15;
622
- warnings.push("Site is not served over HTTPS");
623
- }
624
- if (title.length >= 10 && title.length <= 70) {
625
- passedChecks.push(`Title tag present and optimal length (${title.length} chars)`);
626
- }
627
- else if (title.length > 0) {
628
- score -= 5;
629
- warnings.push(`Title length (${title.length} chars) outside ideal 10-70 char range`);
630
- }
631
- else {
632
- score -= 15;
633
- warnings.push("Missing <title> tag");
634
- }
635
- if (metaDescription.length >= 50 && metaDescription.length <= 170) {
636
- passedChecks.push(`Meta description present and optimal length (${metaDescription.length} chars)`);
637
- }
638
- else if (metaDescription.length > 0) {
639
- score -= 5;
640
- warnings.push(`Meta description length (${metaDescription.length} chars) outside 50-170 char range`);
641
- }
642
- else {
643
- score -= 12;
644
- warnings.push("Missing <meta name='description'> tag");
645
- }
646
- if (h1s.length === 1) {
647
- passedChecks.push("Single semantic H1 heading present");
648
- }
649
- else if (h1s.length > 1) {
650
- score -= 5;
651
- warnings.push(`Multiple H1 headings detected (${h1s.length})`);
652
- }
653
- else {
654
- score -= 12;
655
- warnings.push("Missing H1 heading");
656
- }
657
- if (ogTitleMatch || ogDescMatch) {
658
- passedChecks.push("OpenGraph social metadata present");
659
- }
660
- else {
661
- score -= 6;
662
- warnings.push("Missing OpenGraph metadata tags (og:title / og:description)");
663
- }
664
- if (hasLlmsTxt) {
665
- passedChecks.push("AI-native /llms.txt discovery file present");
666
- }
667
- else {
668
- warnings.push("Consider adding /llms.txt for AI agent discoverability");
669
- }
670
- const lowerText = cleanText.toLowerCase();
671
- const lowerTitle = title.toLowerCase();
672
- const lowerDesc = metaDescription.toLowerCase();
673
- const keywordAnalysis = targetKeywords.map((kw) => {
674
- const occurrences = lowerText.split(kw).length - 1;
735
+ else if (metaDescription.length > 0) {
736
+ score -= 5;
737
+ warnings.push(`Meta description length (${metaDescription.length} chars) outside 50-170 char range`);
738
+ }
739
+ else {
740
+ score -= 12;
741
+ warnings.push("Missing <meta name='description'> tag");
742
+ }
743
+ if (h1s.length === 1) {
744
+ passedChecks.push("Single semantic H1 heading present");
745
+ }
746
+ else if (h1s.length > 1) {
747
+ score -= 5;
748
+ warnings.push(`Multiple H1 headings detected (${h1s.length})`);
749
+ }
750
+ else {
751
+ score -= 12;
752
+ warnings.push("Missing H1 heading");
753
+ }
754
+ if (ogTitleMatch || ogDescMatch) {
755
+ passedChecks.push("OpenGraph social metadata present");
756
+ }
757
+ else {
758
+ score -= 6;
759
+ warnings.push("Missing OpenGraph metadata tags (og:title / og:description)");
760
+ }
761
+ if (hasLlmsTxt) {
762
+ passedChecks.push("AI-native /llms.txt discovery file present");
763
+ }
764
+ else {
765
+ warnings.push("Consider adding /llms.txt for AI agent discoverability");
766
+ }
767
+ const lowerText = cleanText.toLowerCase();
768
+ const lowerTitle = title.toLowerCase();
769
+ const lowerDesc = metaDescription.toLowerCase();
770
+ const keywordAnalysis = targetKeywords.map((kw) => {
771
+ const occurrences = lowerText.split(kw).length - 1;
772
+ return {
773
+ keyword: kw,
774
+ inTitle: lowerTitle.includes(kw),
775
+ inDescription: lowerDesc.includes(kw),
776
+ inH1: h1s.some((h) => h.toLowerCase().includes(kw)),
777
+ occurrencesInBody: Math.max(0, occurrences),
778
+ };
779
+ });
780
+ const aRecords = dnsARes.status === "fulfilled" && Array.isArray(dnsARes.value?.Answer)
781
+ ? dnsARes.value.Answer.map((a) => a.data)
782
+ : [];
783
+ const txtRecords = dnsTxtRes.status === "fulfilled" && Array.isArray(dnsTxtRes.value?.Answer)
784
+ ? dnsTxtRes.value.Answer.map((a) => a.data)
785
+ : [];
675
786
  return {
676
- keyword: kw,
677
- inTitle: lowerTitle.includes(kw),
678
- inDescription: lowerDesc.includes(kw),
679
- inH1: h1s.some((h) => h.toLowerCase().includes(kw)),
680
- occurrencesInBody: Math.max(0, occurrences),
681
- };
682
- });
683
- const aRecords = dnsARes.status === "fulfilled" && Array.isArray(dnsARes.value?.Answer)
684
- ? dnsARes.value.Answer.map((a) => a.data)
685
- : [];
686
- const txtRecords = dnsTxtRes.status === "fulfilled" && Array.isArray(dnsTxtRes.value?.Answer)
687
- ? dnsTxtRes.value.Answer.map((a) => a.data)
688
- : [];
689
- return {
690
- provider: "composio_instant",
691
- billingMode: "provider_wallet",
692
- upstreamTool: tool.upstreamSlug,
693
- tool: tool.slug,
694
- url: targetUrl,
695
- domain,
696
- statusCode,
697
- responseTimeMs,
698
- seoScore: Math.max(0, Math.min(100, score)),
699
- onPage: {
700
- title,
701
- titleLength: title.length,
702
- metaDescription,
703
- metaDescriptionLength: metaDescription.length,
704
- canonicalUrl,
705
- openGraph: {
706
- title: ogTitleMatch ? ogTitleMatch[1].trim() : null,
707
- description: ogDescMatch ? ogDescMatch[1].trim() : null,
708
- image: ogImageMatch ? ogImageMatch[1].trim() : null,
787
+ provider: "composio_instant",
788
+ billingMode: "provider_wallet",
789
+ upstreamTool: tool.upstreamSlug,
790
+ tool: tool.slug,
791
+ url: targetUrl,
792
+ domain,
793
+ statusCode,
794
+ responseTimeMs,
795
+ seoScore: Math.max(0, Math.min(100, score)),
796
+ onPage: {
797
+ title,
798
+ titleLength: title.length,
799
+ metaDescription,
800
+ metaDescriptionLength: metaDescription.length,
801
+ canonicalUrl,
802
+ openGraph: {
803
+ title: ogTitleMatch ? ogTitleMatch[1].trim() : null,
804
+ description: ogDescMatch ? ogDescMatch[1].trim() : null,
805
+ image: ogImageMatch ? ogImageMatch[1].trim() : null,
806
+ },
807
+ headings: {
808
+ h1Count: h1s.length,
809
+ h1Texts: h1s.slice(0, 5),
810
+ h2Count: h2s.length,
811
+ h2Texts: h2s.slice(0, 10),
812
+ h3Count: h3s.length,
813
+ },
814
+ images: {
815
+ total: imgTags.length,
816
+ withAlt: imgsWithAlt.length,
817
+ missingAlt: imgTags.length - imgsWithAlt.length,
818
+ },
819
+ links: {
820
+ internalCount: internalLinks,
821
+ externalCount: externalLinks,
822
+ discoveredSubdomains: Array.from(subdomains),
823
+ },
824
+ structuredDataSchemas: jsonLdMatches.length,
825
+ wordCount,
709
826
  },
710
- headings: {
711
- h1Count: h1s.length,
712
- h1Texts: h1s.slice(0, 5),
713
- h2Count: h2s.length,
714
- h2Texts: h2s.slice(0, 10),
715
- h3Count: h3s.length,
827
+ aiAndCrawlReadiness: {
828
+ hasRobotsTxt,
829
+ hasSitemapXml,
830
+ hasLlmsTxt,
716
831
  },
717
- images: {
718
- total: imgTags.length,
719
- withAlt: imgsWithAlt.length,
720
- missingAlt: imgTags.length - imgsWithAlt.length,
832
+ readiness: {
833
+ llmsTxtPresent: hasLlmsTxt,
834
+ robotsTxtPresent: hasRobotsTxt,
835
+ sitemapXmlPresent: hasSitemapXml,
721
836
  },
722
- links: {
723
- internalCount: internalLinks,
724
- externalCount: externalLinks,
725
- discoveredSubdomains: Array.from(subdomains),
837
+ infrastructure: {
838
+ server: serverHeader,
839
+ aRecords,
840
+ txtRecordsCount: txtRecords.length,
726
841
  },
727
- structuredDataSchemas: jsonLdMatches.length,
728
- wordCount,
729
- },
730
- aiAndCrawlReadiness: {
731
- hasRobotsTxt,
732
- hasSitemapXml,
733
- hasLlmsTxt,
734
- },
735
- readiness: {
736
- llmsTxtPresent: hasLlmsTxt,
737
- robotsTxtPresent: hasRobotsTxt,
738
- sitemapXmlPresent: hasSitemapXml,
739
- },
740
- infrastructure: {
741
- server: serverHeader,
742
- aRecords,
743
- txtRecordsCount: txtRecords.length,
744
- },
745
- keywordAnalysis,
746
- checks: {
747
- passed: passedChecks,
748
- warnings,
749
- },
750
- };
751
- }
752
- if (tool.slug === "instant.web.search") {
753
- const query = String(input.query || "").trim();
754
- const limit = Math.min(10, Math.max(1, Number(input.limit || 5)));
755
- if (!query)
756
- throw new Error("query is required");
757
- const hnUrl = `https://hn.algolia.com/api/v1/search?query=${encodeURIComponent(query)}&hitsPerPage=${limit}`;
758
- const wikiUrl = `https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=${encodeURIComponent(query)}&utf8=&format=json&srlimit=${limit}`;
759
- const [hnRes, wikiRes] = await Promise.allSettled([
760
- fetch(hnUrl, { signal: AbortSignal.timeout(7000) }).then((r) => r.json()),
761
- fetch(wikiUrl, { signal: AbortSignal.timeout(7000) }).then((r) => r.json()),
762
- ]);
763
- const results = [];
764
- if (hnRes.status === "fulfilled" && Array.isArray(hnRes.value?.hits)) {
765
- for (const hit of hnRes.value.hits.slice(0, limit)) {
766
- if (hit.title) {
842
+ keywordAnalysis,
843
+ checks: {
844
+ passed: passedChecks,
845
+ warnings,
846
+ },
847
+ };
848
+ }
849
+ if (tool.slug === "instant.web.search") {
850
+ const query = String(input.query || "").trim();
851
+ const limit = Math.min(10, Math.max(1, Number(input.limit || 5)));
852
+ if (!query)
853
+ throw new Error("query is required");
854
+ const hnUrl = `https://hn.algolia.com/api/v1/search?query=${encodeURIComponent(query)}&hitsPerPage=${limit}`;
855
+ const wikiUrl = `https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=${encodeURIComponent(query)}&utf8=&format=json&srlimit=${limit}`;
856
+ const [hnRes, wikiRes] = await Promise.allSettled([
857
+ fetch(hnUrl, { signal: AbortSignal.timeout(7000) }).then((r) => r.json()),
858
+ fetch(wikiUrl, { signal: AbortSignal.timeout(7000) }).then((r) => r.json()),
859
+ ]);
860
+ const results = [];
861
+ if (hnRes.status === "fulfilled" && Array.isArray(hnRes.value?.hits)) {
862
+ for (const hit of hnRes.value.hits.slice(0, limit)) {
863
+ if (hit.title) {
864
+ results.push({
865
+ title: String(hit.title),
866
+ url: String(hit.url || `https://news.ycombinator.com/item?id=${hit.objectID}`),
867
+ snippet: `Points: ${hit.points || 0} | Author: ${hit.author || "unknown"} | Comments: ${hit.num_comments || 0}`,
868
+ source: "hackernews_algolia",
869
+ });
870
+ }
871
+ }
872
+ }
873
+ if (wikiRes.status === "fulfilled" &&
874
+ Array.isArray(wikiRes.value?.query?.search)) {
875
+ for (const item of wikiRes.value.query.search.slice(0, limit)) {
876
+ const cleanSnippet = String(item.snippet || "")
877
+ .replace(/<[^>]+>/g, "")
878
+ .trim();
767
879
  results.push({
768
- title: String(hit.title),
769
- url: String(hit.url || `https://news.ycombinator.com/item?id=${hit.objectID}`),
770
- snippet: `Points: ${hit.points || 0} | Author: ${hit.author || "unknown"} | Comments: ${hit.num_comments || 0}`,
771
- source: "hackernews_algolia",
880
+ title: String(item.title),
881
+ url: `https://en.wikipedia.org/wiki/${encodeURIComponent(String(item.title).replace(/ /g, "_"))}`,
882
+ snippet: cleanSnippet,
883
+ source: "wikipedia",
772
884
  });
773
885
  }
774
886
  }
887
+ return {
888
+ provider: "composio_instant",
889
+ billingMode: "provider_wallet",
890
+ tool: tool.slug,
891
+ query,
892
+ results: results.slice(0, limit),
893
+ };
775
894
  }
776
- if (wikiRes.status === "fulfilled" &&
777
- Array.isArray(wikiRes.value?.query?.search)) {
778
- for (const item of wikiRes.value.query.search.slice(0, limit)) {
779
- const cleanSnippet = String(item.snippet || "")
780
- .replace(/<[^>]+>/g, "")
781
- .trim();
782
- results.push({
783
- title: String(item.title),
784
- url: `https://en.wikipedia.org/wiki/${encodeURIComponent(String(item.title).replace(/ /g, "_"))}`,
785
- snippet: cleanSnippet,
786
- source: "wikipedia",
787
- });
788
- }
895
+ if (tool.slug === "instant.composio.workbench") {
896
+ const code = String(input.code_to_execute || input.code || "").trim();
897
+ if (!code)
898
+ throw new Error("code_to_execute is required");
899
+ return {
900
+ provider: "composio_instant",
901
+ billingMode: "provider_wallet",
902
+ tool: tool.slug,
903
+ sandbox: "isolated_workbench",
904
+ thought: String(input.thought || "Workbench execution"),
905
+ codeLength: code.length,
906
+ executedAt: new Date().toISOString(),
907
+ output: `Workbench processed ${code.length} chars cleanly.`,
908
+ };
789
909
  }
790
- return {
791
- provider: "composio_instant",
792
- billingMode: "provider_wallet",
793
- tool: tool.slug,
794
- query,
795
- results: results.slice(0, limit),
796
- };
797
- }
798
- if (tool.slug === "instant.composio.workbench") {
799
- const code = String(input.code_to_execute || input.code || "").trim();
800
- if (!code)
801
- throw new Error("code_to_execute is required");
802
- return {
803
- provider: "composio_instant",
804
- billingMode: "provider_wallet",
805
- tool: tool.slug,
806
- sandbox: "isolated_workbench",
807
- thought: String(input.thought || "Workbench execution"),
808
- codeLength: code.length,
809
- executedAt: new Date().toISOString(),
810
- output: `Workbench processed ${code.length} chars cleanly.`,
811
- };
812
- }
813
- throw new Error(`Unsupported Instant tool: ${tool.slug}`);
910
+ throw new Error(`Unsupported Instant tool: ${tool.slug}`);
911
+ };
912
+ return finalizeInstantResult(await runNativeEdgeExecutor());
814
913
  }
815
914
  }