Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
4457d6c
feat(gamification): XP/level engine with polynomial curve
oyi77 May 19, 2026
5164b11
feat(gamification): DB migration and gamification module
oyi77 May 19, 2026
954c9eb
feat(gamification): badge system with 20+ definitions and streak tracker
oyi77 May 19, 2026
3fd342f
feat(gamification): leaderboard engine, SSE stream, and anti-cheat
oyi77 May 19, 2026
bccb7ae
feat(gamification): token sharing, invite tokens, and API routes
oyi77 May 19, 2026
9ef1ac1
feat(gamification): community server federation and connection manage…
oyi77 May 19, 2026
0ca87c3
feat(gamification): dashboard UI — leaderboard, profile, and tokens p…
oyi77 May 19, 2026
81d3522
test(gamification): unit tests for XP, badges, and streaks
oyi77 May 19, 2026
7c9334a
test(gamification): comprehensive tests for leaderboard, sharing, inv…
oyi77 May 19, 2026
5564e25
feat(gamification): wire pipeline events, MCP tools, and dashboard nav
oyi77 May 19, 2026
98ea8ae
fix(gamification): address all code review feedback
oyi77 May 19, 2026
4313ce5
docs(gamification): system design document
oyi77 May 19, 2026
0288024
feat(gamification): badge unlock notifications, admin anomaly dashboa…
oyi77 May 19, 2026
3fcf615
feat(gamification): badge unlock notifications, admin anomaly dashboa…
oyi77 May 19, 2026
f33aa36
fix(gamification): address all code review feedback
oyi77 May 19, 2026
af5f0ab
fix(triage): prefer currently checked-out release branch + sort by ve…
diegosouzapw May 19, 2026
409228a
chore(ideia): add YAML frontmatter to legacy idea files
diegosouzapw May 19, 2026
3e648d5
Merge branch 'release/v3.8.0' into feat/gamification-leaderboard
diegosouzapw May 19, 2026
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
28 changes: 28 additions & 0 deletions open-sse/handlers/chatCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4409,6 +4409,20 @@ export async function handleChatCore({
recordCost(apiKeyInfo.id, estimatedCost);
}

// ── Gamification event (fire-and-forget) ──
if (apiKeyInfo?.id) {
try {
const { emitGamificationEvent } = await import("@/lib/gamification/events");
emitGamificationEvent({
apiKeyId: apiKeyInfo.id,
action: "request",
metadata: { model, provider },
});
} catch (_) {
/* gamification optional */
}
}

return {
success: true,
response: new Response(JSON.stringify(translatedResponse), {
Expand Down Expand Up @@ -4728,6 +4742,20 @@ export async function handleChatCore({
})
);

// ── Gamification event (fire-and-forget) ──
if (apiKeyInfo?.id) {
try {
const { emitGamificationEvent } = await import("@/lib/gamification/events");
emitGamificationEvent({
apiKeyId: apiKeyInfo.id,
action: "request",
metadata: { model, provider },
});
} catch (_) {
/* gamification optional */
}
}

return {
success: true,
response: new Response(finalStream, {
Expand Down
29 changes: 28 additions & 1 deletion open-sse/mcp-server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import {
import { memoryTools } from "./tools/memoryTools.ts";
import { skillTools } from "./tools/skillTools.ts";
import { compressionTools } from "./tools/compressionTools.ts";
import { gamificationTools } from "./tools/gamificationTools.ts";
import { compressMcpRegistryMetadata } from "./descriptionCompressor.ts";
import { smartFilterText } from "../services/compression/engines/mcpAccessibility/index.ts";
import {
Expand All @@ -98,7 +99,10 @@ const MCP_ALLOWED_SCOPES = new Set(
.filter(Boolean)
);
const TOTAL_MCP_TOOL_COUNT =
MCP_TOOLS.length + Object.keys(memoryTools).length + Object.keys(skillTools).length;
MCP_TOOLS.length +
Object.keys(memoryTools).length +
Object.keys(skillTools).length +
gamificationTools.length;

type JsonRecord = Record<string, unknown>;

Expand Down Expand Up @@ -1022,6 +1026,29 @@ export function createMcpServer(): McpServer {
);
});

// ── Gamification Tools ────────────────────────
gamificationTools.forEach((toolDef) => {
server.registerTool(
toolDef.name,
{
description: toolDef.description,
// @ts-ignore: dynamic zod access
inputSchema: toolDef.inputSchema,
},
withScopeEnforcement(toolDef.name, async (args) => {
try {
const parsedArgs = toolDef.inputSchema.parse(args ?? {});
// @ts-ignore: handler expected specific object
const result = await toolDef.handler(parsedArgs);
return { content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }] };
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
return { content: [{ type: "text" as const, text: `Error: ${msg}` }], isError: true };
}
})
);
});

return server;
}

Expand Down
140 changes: 140 additions & 0 deletions open-sse/mcp-server/tools/gamificationTools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/**
* MCP Gamification Tools — leaderboard, badges, levels, sharing.
*
* @module mcp-server/tools/gamificationTools
*/

import { z } from "zod";

export const gamificationTools = [
{
name: "gamification_leaderboard",
description: "Get leaderboard rankings for a scope (global, weekly, monthly, tokens_shared).",
inputSchema: z.object({
scope: z.enum(["global", "weekly", "monthly", "tokens_shared"]).default("global"),
limit: z.number().min(1).max(100).default(50),
}),
handler: async (args: { scope: string; limit: number }) => {
const { getTopN } = await import("../../../src/lib/gamification/leaderboard");
const entries = await getTopN(args.scope as any, args.limit);
return { entries };
},
},
{
name: "gamification_rank",
description: "Get rank for an API key in a leaderboard scope.",
inputSchema: z.object({
apiKeyId: z.string(),
scope: z.enum(["global", "weekly", "monthly", "tokens_shared"]).default("global"),
}),
handler: async (args: { apiKeyId: string; scope: string }) => {
const { getRank } = await import("../../../src/lib/gamification/leaderboard");
const rank = await getRank(args.apiKeyId, args.scope as any);
return { rank };
},
},
{
name: "gamification_profile",
description: "Get XP, level, and badges for an API key.",
inputSchema: z.object({
apiKeyId: z.string(),
}),
handler: async (args: { apiKeyId: string }) => {
const { getXp, getBadges } = await import("../../../src/lib/db/gamification");
const { calculateLevel, getLevelTitle, getLevelTier } =
await import("../../../src/lib/gamification/xp");
const { getStreak } = await import("../../../src/lib/gamification/streaks");

const xp = getXp(args.apiKeyId);
const badges = getBadges(args.apiKeyId);
const streak = await getStreak(args.apiKeyId);
const level = xp ? calculateLevel(xp.totalXp) : 1;

return {
totalXp: xp?.totalXp || 0,
level,
title: getLevelTitle(level),
tier: getLevelTier(level),
streak: streak.currentStreak,
longestStreak: streak.longestStreak,
badges: badges.map((b) => ({ id: b.badgeId, unlockedAt: b.unlockedAt })),
};
},
},
{
name: "gamification_badges",
description: "List all badge definitions or earned badges for an API key.",
inputSchema: z.object({
apiKeyId: z.string().optional(),
category: z.string().optional(),
}),
handler: async (args: { apiKeyId?: string; category?: string }) => {
const { getBadgeDefinitions, getBadges } = await import("../../../src/lib/db/gamification");

if (args.apiKeyId) {
const badges = getBadges(args.apiKeyId);
return { earned: badges };
}

const definitions = getBadgeDefinitions(args.category);
return { definitions };
},
},
{
name: "gamification_transfer",
description: "Transfer tokens between API keys.",
inputSchema: z.object({
fromApiKeyId: z.string(),
toApiKeyId: z.string(),
amount: z.number().positive(),
reason: z.string().optional(),
}),
handler: async (args: {
fromApiKeyId: string;
toApiKeyId: string;
amount: number;
reason?: string;
}) => {
const { transferTokens } = await import("../../../src/lib/gamification/sharing");
const result = await transferTokens(
args.fromApiKeyId,
args.toApiKeyId,
args.amount,
args.reason
);
return result;
},
},
{
name: "gamification_invite",
description: "Create an invite token for server connection.",
inputSchema: z.object({
apiKeyId: z.string(),
serverUrl: z.string().optional(),
maxUses: z.number().positive().default(1),
}),
handler: async (args: { apiKeyId: string; serverUrl?: string; maxUses: number }) => {
const { createInvite } = await import("../../../src/lib/gamification/invites");
const result = await createInvite(args.apiKeyId, args.serverUrl, args.maxUses);
return result;
},
},
{
name: "gamification_servers",
description: "List connected community servers.",
inputSchema: z.object({}),
handler: async () => {
const { listServers } = await import("../../../src/lib/gamification/servers");
return { servers: await listServers() };
},
},
{
name: "gamification_anomalies",
description: "Get flagged anomalous XP activity (admin only).",
inputSchema: z.object({}),
handler: async () => {
const { getAnomalies } = await import("../../../src/lib/gamification/antiCheat");
return { anomalies: await getAnomalies() };
},
},
];
Loading