Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions instrumentation.ts

This file was deleted.

8 changes: 1 addition & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,11 @@
"@mantine/notifications": "^9.4.1",
"@mdx-js/loader": "^3.1.0",
"@next/mdx": "^16.0.10",
"@opentelemetry/api-logs": "^0.221.0",
"@opentelemetry/exporter-logs-otlp-http": "^0.221.0",
"@opentelemetry/resources": "^2.10.0",
"@opentelemetry/sdk-logs": "^0.221.0",
"@tabler/icons-react": "^3.44.0",
"@upstash/redis": "^1.38.1",
"@vercel/analytics": "^2.0.1",
"@vercel/speed-insights": "^2.0.0",
"ai": "^7.0.15",
"classnames": "^2.5.1",
"cookie": "^1.0.2",
"gray-matter": "^4.0.3",
"next": "^16.0.10",
Expand All @@ -66,8 +61,7 @@
"remark-parse": "^11.0.0",
"remark-stringify": "^11.0.0",
"sass": "^1.86.3",
"transliteration": "^2.3.5",
"use-debounce": "^10.1.1"
"transliteration": "^2.3.5"
},
"devDependencies": {
"@axe-core/playwright": "^4.11.3",
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const zen = (sessionId: string) =>
},
});

const MODEL_ID = 'glm-5.3-flash';
const MODEL_ID = 'gpt-6-luna';

const model = (sessionId: string) => zen(sessionId).chatModel(MODEL_ID);

Expand Down
67 changes: 2 additions & 65 deletions src/components/layout/SocialStats.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
import { Anchor } from "@mantine/core";
import { baseURL, sameAs } from "@/config";
import { person } from "@/content";
import { sameAs } from "@/config";
import { logger } from "@/lib/logger";

export const getDevToStats = async (): Promise<{ articles: number } | null> => {
try {
const devtoUrl = sameAs.devto;
if (!devtoUrl) return null;
const username = new URL(devtoUrl).pathname.split("/").filter(Boolean).pop();
if (!username) return null;
const res = await fetch(`https://dev.to/api/articles?username=${username}&per_page=1000`, {
next: { revalidate: 3600 },
});
if (!res.ok) return null;
const data = await res.json();
return { articles: data.length };
} catch (err) {
logger.warn(err, "failed to fetch Dev.to stats");
return null;
}
};

export const getGitHubStats = async (): Promise<{ repos: number } | null> => {
try {
const username = new URL(sameAs.github || "").pathname.split("/").filter(Boolean).pop();
Expand All @@ -37,56 +18,12 @@ export const getGitHubStats = async (): Promise<{ repos: number } | null> => {
}
};

export const getStackOverflowStats = async (): Promise<{ reputation: number } | null> => {
try {
if (!sameAs.stackoverflow) return null;
const id = sameAs.stackoverflow.split("/").filter(Boolean).pop();
if (!id || isNaN(Number(id))) return null;
const res = await fetch(
`https://api.stackexchange.com/2.3/users/${id}?order=desc&sort=reputation&site=stackoverflow&filter=total`,
{ next: { revalidate: 86400 } },
);
if (!res.ok) return null;
const data = await res.json();
return { reputation: data.items?.[0]?.reputation ?? 0 };
} catch (err) {
logger.warn(err, "failed to fetch Stack Overflow stats");
return null;
}
};

export const getNpmStats = async (): Promise<{ packages: number } | null> => {
try {
if (!sameAs.npm) return null;
const username = sameAs.npm.split("/").filter(Boolean).pop();
if (!username) return null;
const res = await fetch(
`https://registry.npmjs.org/-/v1/search?text=maintainer:${username}&size=0`,
{ next: { revalidate: 86400 } },
);
if (!res.ok) return null;
const data = await res.json();
return { packages: data.total ?? 0 };
} catch (err) {
logger.warn(err, "failed to fetch npm stats");
return null;
}
};

export async function SocialStats() {
const [devto, github, stackoverflow, npm] = await Promise.all([
getDevToStats(),
getGitHubStats(),
getStackOverflowStats(),
getNpmStats(),
]);
const github = await getGitHubStats();

const items = [];

if (github && sameAs.github) items.push({ platform: "github", label: "GitHub repos", value: github.repos, url: sameAs.github });
if (devto && sameAs.devto) items.push({ platform: "devto", label: "Dev.to articles", value: devto.articles, url: sameAs.devto });
if (stackoverflow && sameAs.stackoverflow) items.push({ platform: "stackoverflow", label: "Stack Overflow rep", value: stackoverflow.reputation.toLocaleString("en-US"), url: sameAs.stackoverflow });
if (npm && sameAs.npm) items.push({ platform: "npm", label: "npm packages", value: npm.packages, url: sameAs.npm });

if (items.length === 0) return null;

Expand Down
40 changes: 3 additions & 37 deletions src/components/layout/__tests__/SocialStats.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,13 @@ vi.mock("@/config", () => ({
baseURL: "https://flabs.tech",
sameAs: {
github: "https://github.com/fabio",
devto: "https://dev.to/fabio",
stackoverflow: "https://stackoverflow.com/users/12345/fabio",
npm: "https://www.npmjs.com/~fabio",
},
}));

vi.mock("@/lib/logger", () => ({
logger: { warn: vi.fn() },
}));

// SocialStats is an async Server Component — not renderable in jsdom.
// The data-fetching helpers are exported and tested here directly;
// rendering is covered by the Playwright e2e suite.

beforeEach(() => {
vi.resetModules();
vi.stubGlobal(
Expand All @@ -27,15 +20,6 @@ beforeEach(() => {
});

describe("SocialStats data helpers", () => {
it(
"getDevToStats returns null when the API call fails",
{ timeout: 15000 },
async () => {
const { getDevToStats } = await import("@/components/layout/SocialStats");
await expect(getDevToStats()).resolves.toBeNull();
},
);

it(
"getGitHubStats returns null when the API call fails",
{ timeout: 15000 },
Expand All @@ -45,24 +29,6 @@ describe("SocialStats data helpers", () => {
},
);

it(
"getStackOverflowStats returns null when the API call fails",
{ timeout: 15000 },
async () => {
const { getStackOverflowStats } = await import("@/components/layout/SocialStats");
await expect(getStackOverflowStats()).resolves.toBeNull();
},
);

it(
"getNpmStats returns null when the API call fails",
{ timeout: 15000 },
async () => {
const { getNpmStats } = await import("@/components/layout/SocialStats");
await expect(getNpmStats()).resolves.toBeNull();
},
);

it(
"parses data when the API responds",
{ timeout: 15000 },
Expand All @@ -72,12 +38,12 @@ describe("SocialStats data helpers", () => {
vi.fn(() =>
Promise.resolve({
ok: true,
json: () => Promise.resolve([{ id: 1 }, { id: 2 }, { id: 3 }]),
json: () => Promise.resolve({ public_repos: 42 }),
} as Response),
),
);
const { getDevToStats } = await import("@/components/layout/SocialStats");
await expect(getDevToStats()).resolves.toEqual({ articles: 3 });
const { getGitHubStats } = await import("@/components/layout/SocialStats");
await expect(getGitHubStats()).resolves.toEqual({ repos: 42 });
},
);
});
23 changes: 5 additions & 18 deletions src/config/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ const fonts: FontsConfig = {
const sameAs: SameAsConfig = {
github: "https://github.com/fworks-tech",
linkedin: "https://www.linkedin.com/in/fabiorborges/",
devto: undefined,
stackoverflow: undefined,
npm: undefined,
hashnode: undefined,
};

const socialSharing = {
Expand All @@ -89,13 +85,6 @@ const socialSharing = {

const mailchimp = {
action: "",
effects: {
mask: { x: 0, y: 0, radius: 0, cursor: true },
gradient: { display: false, opacity: 100, x: 0, y: 0, width: 0, height: 0, tilt: 0, colorStart: "", colorEnd: "" },
dots: { display: false, opacity: 100, size: 0, color: "" },
grid: { display: false, opacity: 100, color: "", width: 0, height: 0 },
lines: { display: false, opacity: 100, size: 0, thickness: 0, angle: 0, color: "" },
},
};

/**
Expand All @@ -104,13 +93,11 @@ const mailchimp = {
* deploy; `display: false` hides the card entirely.
*/
const referral = {
default: {
url: process.env.NEXT_PUBLIC_REFERRAL_URL || "https://example.com",
headline: "Score 80%+? Put your skills to work.",
body: "You've proven your JS fundamentals. Create a free account and get matched with top companies.",
cta: "Get started",
display: false,
},
url: process.env.NEXT_PUBLIC_REFERRAL_URL || "https://example.com",
headline: "Score 80%+? Put your skills to work.",
body: "You've proven your JS fundamentals. Create a free account and get matched with top companies.",
cta: "Get started",
display: false,
};

export {
Expand Down
2 changes: 1 addition & 1 deletion src/features/quiz/components/ReferralCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function ReferralCard({ score, accuracy }: ReferralCardProps) {
return window.localStorage.getItem(DISMISS_KEY) === "1";
});

const config = referral.default;
const config = referral;

useEffect(() => {
if (config.display && !dismissed) {
Expand Down
12 changes: 6 additions & 6 deletions src/lib/abuse/__tests__/cost.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ describe('estimateTokens', () => {

describe('calculateCost', () => {
it('scales tokens to USD', () => {
expect(calculateCost(1_000_000)).toBeCloseTo(0.28);
expect(calculateCost(500_000)).toBeCloseTo(0.14);
expect(calculateCost(1_000_000)).toBeCloseTo(0.5);
expect(calculateCost(500_000)).toBeCloseTo(0.25);
});
});

Expand All @@ -31,7 +31,7 @@ describe('checkCostLimit', () => {
vi.useFakeTimers();
vi.setSystemTime(new Date('2026-01-01T00:00:00Z'));
for (let i = 0; i < 6; i++) {
checkCostLimit('u1', 300_000); // ~$0.084 each
checkCostLimit('u1', 300_000); // ~$0.15 each
}
const result = checkCostLimit('u1', 300_000);
expect(result.allowed).toBe(false);
Expand All @@ -52,9 +52,9 @@ describe('recordActualUsage', () => {
it('corrects the last estimate with actual usage', () => {
checkCostLimit('u1', 40_000);
recordActualUsage('u1', 10_000);
// Exhausting the budget now: ~$0.0589 spent (actual) + next estimate must
// still fit — verifies the estimate was replaced, not appended.
const result = checkCostLimit('u1', 1_000_000);
// ~$0.005 spent (actual) + next estimate must still fit — verifies the
// estimate was replaced, not appended.
const result = checkCostLimit('u1', 900_000);
expect(result.allowed).toBe(true);
});

Expand Down
2 changes: 1 addition & 1 deletion src/lib/abuse/cost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

export const MAX_TOKENS_PER_REQUEST = 4000;
const MAX_COST_PER_HOUR_USD = 0.5; // ~$0.50/hour budget
const TOKEN_COST_PER_1M = 0.28; // glm-5.3-flash on OpenCode Go (conservative upper bound)
const TOKEN_COST_PER_1M = 0.5; // gpt-6-luna on OpenCode Zen (output upper bound)
const USAGE_WINDOW_MS = 60 * 60 * 1000; // 1 hour
const CLEANUP_INTERVAL_MS = 300_000; // 5 min

Expand Down
Loading