| import crypto from "crypto"; |
|
|
| |
| |
| |
|
|
| export async function marketResearchAgent({ input, provider, model }) { |
| if (!input?.keyword) { |
| throw new Error("keyword is required"); |
| } |
|
|
| const keyword = normalizeKeyword(input.keyword); |
| const normalizedTitle = `Global ${keyword} Market and Forecast 2026-2033`; |
|
|
| |
| |
| |
|
|
| |
| |
| |
| const baseMarket2023 = randomFloat(0.5, 5.0); |
| const cagr = randomFloat(8, 22); |
| const market2025 = round(baseMarket2023 * Math.pow(1 + cagr / 100, 2)); |
| const market2033 = round(baseMarket2023 * Math.pow(1 + cagr / 100, 10)); |
|
|
| |
| |
| |
|
|
| const dashboard_view = { |
| marketTitle: normalizedTitle, |
|
|
| marketSummary: { |
| past2023: baseMarket2023, |
| current2025: market2025, |
| forecast2033: market2033, |
| cagr |
| }, |
|
|
| forecast: [ |
| { year: "2023", value: baseMarket2023 }, |
| { year: "2025", value: market2025 }, |
| { year: "2033", value: market2033 } |
| ], |
|
|
| regional: buildRegions(), |
|
|
| competitive: buildTopPlayers(), |
|
|
| segments: buildSegments(), |
|
|
| drivers: [ |
| { driver: "Technology adoption", impact: 92 }, |
| { driver: "Rising healthcare demand", impact: 88 }, |
| { driver: "Digital transformation", impact: 85 } |
| ], |
|
|
| insights: { |
| largestSegment2025: "Primary Segment", |
| fastestGrowingSegment: "AI-Enabled Solutions", |
| keyOpportunities: [ |
| "Emerging markets", |
| "AI integration", |
| "Cost-efficient platforms" |
| ], |
| majorChallenges: [ |
| "Regulatory approvals", |
| "High initial investment", |
| "Skilled workforce shortage" |
| ] |
| }, |
|
|
| citation: "iHealthcareAnalyst, Inc. Internal Data Analysis", |
| citationUrl: "https://www.ihealthcareanalyst.com" |
| }; |
|
|
| |
| |
| |
|
|
| const report_view = { |
| marketTitle: keyword, |
|
|
| marketSizing: { |
| pastYear_2023: baseMarket2023, |
| currentYear_2025: market2025, |
| forecastYear_2033: market2033, |
| global_cagr_Forecast: cagr |
| }, |
|
|
| executiveOverview: |
| `The ${keyword} market is experiencing accelerated growth driven by technological innovation, increasing healthcare demand, and expanding adoption across developed and emerging economies.`, |
|
|
| marketSegments: [ |
| { |
| segmentName: "Primary Segment", |
| subSegments: [ |
| { |
| subSegmentName: "Core Products", |
| segmet_marketShare_2023: 40, |
| segment_marketShare_2025: 45, |
| segment_marketShare_2033: 50, |
| segmentName_cagr_Forecast: round(cagr + 2) |
| } |
| ] |
| } |
| ], |
|
|
| marketDrivers: [ |
| "Growing demand for advanced healthcare solutions", |
| "Increased investment in digital health", |
| "Favorable government initiatives" |
| ], |
|
|
| emergingTrends: [ |
| "AI-driven diagnostics", |
| "Cloud-based healthcare platforms", |
| "Personalized medicine" |
| ], |
|
|
| competitiveLandscape: [ |
| { |
| company: "Company A", |
| player_markerShare_2025: 18, |
| positioning: "Market leader with diversified portfolio" |
| }, |
| { |
| company: "Company B", |
| player_markerShare_2025: 14, |
| positioning: "Strong innovation focus" |
| } |
| ], |
|
|
| regulatoryEnvironment: |
| "The market is regulated by stringent healthcare and data protection regulations, with increasing emphasis on patient safety and clinical validation.", |
|
|
| geographicAnalysis: |
| "North America leads the market due to early adoption, while Asia-Pacific is expected to witness the fastest growth driven by expanding healthcare infrastructure.", |
|
|
| futureOutlook: |
| "The market is projected to grow steadily through 2033, supported by innovation, demographic trends, and increased healthcare spending.", |
|
|
| strategicRecommendations: [ |
| "Invest in AI-enabled platforms", |
| "Expand presence in emerging markets", |
| "Strengthen regulatory compliance capabilities" |
| ] |
| }; |
|
|
| |
| |
| |
|
|
| const result = { |
| meta: { |
| job_id: input.job_id || `job_${crypto.randomUUID()}`, |
| keyword, |
| normalized_title: normalizedTitle, |
| status: "completed", |
| timestamp: new Date().toISOString(), |
| provider_used: provider || "auto", |
| model_used: model || "auto", |
| confidence: "medium" |
| }, |
| dashboard_view, |
| report_view |
| }; |
|
|
| |
| |
| |
|
|
| validateDashboard(result.dashboard_view); |
| validateReport(result.report_view); |
|
|
| return result; |
| } |
|
|
| |
| |
| |
|
|
| function validateDashboard(d) { |
| if (!d.marketTitle) throw new Error("dashboard_view.marketTitle missing"); |
| if (!d.marketSummary) throw new Error("dashboard_view.marketSummary missing"); |
|
|
| const ms = d.marketSummary; |
| requireNumber(ms.past2023, "past2023"); |
| requireNumber(ms.current2025, "current2025"); |
| requireNumber(ms.forecast2033, "forecast2033"); |
| requireNumber(ms.cagr, "cagr"); |
|
|
| if (!Array.isArray(d.forecast)) throw new Error("forecast must be array"); |
| if (!Array.isArray(d.segments)) throw new Error("segments must be array"); |
| } |
|
|
| function validateReport(r) { |
| if (!r.marketTitle) throw new Error("report_view.marketTitle missing"); |
| if (!r.marketSizing) throw new Error("marketSizing missing"); |
|
|
| const ms = r.marketSizing; |
| requireNumber(ms.pastYear_2023, "pastYear_2023"); |
| requireNumber(ms.currentYear_2025, "currentYear_2025"); |
| requireNumber(ms.forecastYear_2033, "forecastYear_2033"); |
| requireNumber(ms.global_cagr_Forecast, "global_cagr_Forecast"); |
|
|
| if (!Array.isArray(r.marketSegments)) { |
| throw new Error("marketSegments must be array"); |
| } |
| } |
|
|
| |
| |
| |
|
|
| function normalizeKeyword(k) { |
| return k.replace(/market/gi, "").trim(); |
| } |
|
|
| function round(n) { |
| return Math.round(n * 100) / 100; |
| } |
|
|
| function randomFloat(min, max) { |
| return round(min + Math.random() * (max - min)); |
| } |
|
|
| function requireNumber(v, name) { |
| if (typeof v !== "number" || Number.isNaN(v)) { |
| throw new Error(`${name} must be a number`); |
| } |
| } |
|
|
| function buildRegions() { |
| return [ |
| { region: "North America", share: 42, cagr: 14.2 }, |
| { region: "Europe", share: 28, cagr: 12.8 }, |
| { region: "Asia Pacific", share: 22, cagr: 18.6 }, |
| { region: "Latin America", share: 5, cagr: 11.3 }, |
| { region: "Middle East & Africa", share: 3, cagr: 10.9 } |
| ]; |
| } |
|
|
| function buildTopPlayers() { |
| return [ |
| { company: "Company A", share: 18 }, |
| { company: "Company B", share: 15 }, |
| { company: "Company C", share: 12 }, |
| { company: "Company D", share: 10 }, |
| { company: "Company E", share: 8 } |
| ]; |
| } |
|
|
| function buildSegments() { |
| return [ |
| { |
| segment: "Primary Segment", |
| subSegments: [ |
| { name: "Core Products", share2025: 45, cagr: 16.5 }, |
| { name: "AI Solutions", share2025: 35, cagr: 19.2 }, |
| { name: "Services", share2025: 20, cagr: 13.1 } |
| ] |
| } |
| ]; |
| } |
|
|