feat(cli): add elysia + aisdk support and fix fastify ai example

This commit is contained in:
Aman Varshney
2025-09-09 23:39:35 +05:30
parent d0a9a5d223
commit e5ba83fe3b
7 changed files with 112 additions and 130 deletions

View File

@@ -92,7 +92,7 @@ export const dependencyVersionMap = {
"@elysiajs/cors": "^1.3.3",
"@elysiajs/trpc": "^1.1.0",
elysia: "^1.3.20",
"elysia": "^1.3.21",
"@hono/node-server": "^1.14.4",
"@hono/trpc-server": "^0.4.0",
@@ -108,12 +108,12 @@ export const dependencyVersionMap = {
turbo: "^2.5.4",
ai: "^5.0.9",
"@ai-sdk/google": "^2.0.3",
"@ai-sdk/vue": "^2.0.9",
"@ai-sdk/svelte": "^3.0.9",
"@ai-sdk/react": "^2.0.9",
streamdown: "^1.1.6",
"ai": "^5.0.39",
"@ai-sdk/google": "^2.0.13",
"@ai-sdk/vue": "^2.0.39",
"@ai-sdk/svelte": "^3.0.39",
"@ai-sdk/react": "^2.0.39",
streamdown: "^1.2.0",
"@orpc/server": "^1.8.6",
"@orpc/client": "^1.8.6",

View File

@@ -33,10 +33,6 @@ export async function getExamplesChoice(
if (database === "none") return [];
const noFrontendSelected = !frontends || frontends.length === 0;
if (noFrontendSelected) return [];
let response: Examples[] | symbol = [];
const options: { value: Examples; label: string; hint: string }[] = [];

View File

@@ -157,11 +157,10 @@ export function isExampleTodoAllowed(
}
export function isExampleAIAllowed(
backend?: ProjectConfig["backend"],
_backend?: ProjectConfig["backend"],
frontends: Frontend[] = [],
) {
const includesSolid = frontends.includes("solid");
if (backend === "elysia") return false;
if (includesSolid) return false;
return true;
}
@@ -226,11 +225,6 @@ export function validateExamplesCompatibility(
"The 'todo' example requires a database if a backend (other than Convex) is present. Cannot use --examples todo when database is 'none' and a backend is selected.",
);
}
if (examplesArr.includes("ai") && backend === "elysia") {
exitWithError(
"The 'ai' example is not compatible with the Elysia backend.",
);
}
if (examplesArr.includes("ai") && (frontend ?? []).includes("solid")) {
exitWithError(
"The 'ai' example is not compatible with the Solid frontend.",

View File

@@ -4,6 +4,10 @@ import { node } from "@elysiajs/node";
{{/if}}
import { Elysia } from "elysia";
import { cors } from "@elysiajs/cors";
{{#if (includes examples "ai")}}
import { google } from "@ai-sdk/google";
import { convertToModelMessages, streamText } from "ai";
{{/if}}
{{#if (eq api "trpc")}}
import { createContext } from "./lib/context";
import { appRouter } from "./routers/index";
@@ -94,6 +98,18 @@ const app = new Elysia()
});
return res;
})
{{/if}}
{{#if (includes examples "ai")}}
.post("/ai", async (context) => {
const body = await context.request.json();
const uiMessages = body.messages || [];
const result = streamText({
model: google("gemini-2.0-flash"),
messages: convertToModelMessages(uiMessages)
});
return result.toUIMessageStreamResponse();
})
{{/if}}
.get("/", () => "OK")
.listen(3000, () => {

View File

@@ -158,15 +158,14 @@ interface AiRequestBody {
messages: UIMessage[];
}
fastify.post('/ai', async function (request, reply) {
// there are some issues with the ai sdk and fastify, docs: https://ai-sdk.dev/cookbook/api-servers/fastify
fastify.post('/ai', async function (request) {
const { messages } = request.body as AiRequestBody;
const result = streamText({
model: google('gemini-1.5-flash'),
messages: convertToModelMessages(messages),
});
return result.pipeUIMessageStreamToResponse(reply.raw);
return result.toUIMessageStreamResponse();
});
{{/if}}

View File

@@ -912,13 +912,6 @@ export const analyzeStackCompatibility = (
"Todo example removed (requires a database but 'None' was selected)",
});
}
if (nextStack.backend === "elysia" && nextStack.examples.includes("ai")) {
incompatibleExamples.push("ai");
changes.push({
category: "examples",
message: "AI example removed (not compatible with Elysia backend)",
});
}
if (isSolid && nextStack.examples.includes("ai")) {
incompatibleExamples.push("ai");
changes.push({
@@ -942,19 +935,6 @@ export const analyzeStackCompatibility = (
notes.database.hasIssue = true;
notes.examples.hasIssue = true;
}
if (
nextStack.backend === "elysia" &&
uniqueIncompatibleExamples.includes("ai")
) {
notes.backend.notes.push(
"AI example is not compatible with Elysia. It will be removed.",
);
notes.examples.notes.push(
"AI example is not compatible with Elysia. It will be removed.",
);
notes.backend.hasIssue = true;
notes.examples.hasIssue = true;
}
if (isSolid && uniqueIncompatibleExamples.includes("ai")) {
notes.webFrontend.notes.push(
"AI example is not compatible with Solid. It will be removed.",
@@ -1551,9 +1531,6 @@ export const getDisabledReason = (
}
if (category === "examples" && optionId === "ai") {
if (finalStack.backend === "elysia") {
return "AI example is not compatible with Elysia backend. Try Hono, Express, or Fastify.";
}
if (finalStack.webFrontend.includes("solid")) {
return "AI example is not compatible with Solid frontend. Try React-based frontends.";
}