-
Notifications
You must be signed in to change notification settings - Fork 0
feat: OpenCode provider fix + API key validation & model discovery #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f704a79
647432a
56f1542
8c97099
a685ae5
9ad3b83
12c9161
c551f00
c44e827
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| /// <reference types="next" /> | ||
| /// <reference types="next/image-types/global" /> | ||
| import "./.next/types/routes.d.ts"; | ||
| import "./.next/dev/types/routes.d.ts"; | ||
|
|
||
| // NOTE: This file should not be edited | ||
| // see https://nextjs.org/docs/app/api-reference/config/typescript for more information. | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import { | |
| import { withCodeflowGovernance } from "@/lib/blueprint/prompt-governance"; | ||
| import { blueprintGraphSchema } from "@/lib/blueprint/schema"; | ||
| import { getNvidiaKeySource, requestNvidiaChatCompletion, resolveNvidiaApiKey } from "@/lib/blueprint/nvidia"; | ||
| import { isOpencodeAvailable, sendToOpencode } from "@/lib/opencode/agent"; | ||
|
|
||
| const requestSchema = z.object({ | ||
| graph: blueprintGraphSchema, | ||
|
|
@@ -18,7 +19,8 @@ const requestSchema = z.object({ | |
| instruction: z.string().trim().optional(), | ||
| retrievalQuery: z.string().trim().min(1).optional(), | ||
| retrievalDepth: z.number().int().min(1).max(6).optional(), | ||
| nvidiaApiKey: z.string().optional() | ||
| nvidiaApiKey: z.string().optional(), | ||
| useOpencode: z.boolean().optional().default(false) | ||
| }); | ||
|
|
||
| const responseSchema = z.object({ | ||
|
|
@@ -50,8 +52,9 @@ export async function POST(request: Request) { | |
|
|
||
| try { | ||
| const body = requestSchema.parse(await request.json()); | ||
| const apiKey = resolveNvidiaApiKey(body.nvidiaApiKey); | ||
| const keySource = getNvidiaKeySource(body.nvidiaApiKey); | ||
| const useOpencode = body.useOpencode && isOpencodeAvailable(); | ||
| const apiKey = useOpencode ? null : resolveNvidiaApiKey(body.nvidiaApiKey); | ||
| const keySource = useOpencode ? "opencode" : getNvidiaKeySource(body.nvidiaApiKey); | ||
| const context = getNodeAssistanceContext(body.graph, body.nodeId); | ||
|
|
||
| if (!context) { | ||
|
|
@@ -67,11 +70,16 @@ export async function POST(request: Request) { | |
| keySource | ||
| }); | ||
|
|
||
| if (!apiKey) { | ||
| return NextResponse.json( | ||
| { error: "NVIDIA API key is required. Provide it in the UI or set NVIDIA_API_KEY environment variable." }, | ||
| { status: 400 } | ||
| ); | ||
| if (!useOpencode && !apiKey) { | ||
| // Check if OpenCode is available as fallback | ||
| if (isOpencodeAvailable()) { | ||
| body.useOpencode = true; | ||
| } else { | ||
| return NextResponse.json( | ||
| { error: "No AI backend available. Either start OpenCode server or provide NVIDIA API key." }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
| } | ||
|
Comment on lines
+73
to
83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mutating the parsed |
||
|
|
||
| const retrievalContext = await resolveAgentRetrievalContext({ | ||
|
|
@@ -132,16 +140,31 @@ Return the JSON suggestion now.`; | |
| "implementation" | ||
| ); | ||
|
|
||
| const content = await requestNvidiaChatCompletion({ | ||
| apiKey, | ||
| messages: [ | ||
| { role: "system", content: governedSystemPrompt }, | ||
| { role: "user", content: userPrompt } | ||
| ], | ||
| temperature: 0.2, | ||
| topP: 0.7, | ||
| maxTokens: 4096 | ||
| }); | ||
| let content: string; | ||
|
|
||
| if (useOpencode || body.useOpencode) { | ||
| const result = await sendToOpencode({ | ||
| systemPrompt: governedSystemPrompt, | ||
| prompt: userPrompt, | ||
| }); | ||
|
|
||
| if (!result.success) { | ||
| throw new Error(result.error ?? "OpenCode request failed"); | ||
| } | ||
|
|
||
| content = result.content ?? ""; | ||
| } else { | ||
| content = await requestNvidiaChatCompletion({ | ||
| apiKey: apiKey!, | ||
| messages: [ | ||
| { role: "system", content: governedSystemPrompt }, | ||
| { role: "user", content: userPrompt } | ||
| ], | ||
| temperature: 0.2, | ||
| topP: 0.7, | ||
| maxTokens: 4096 | ||
| }); | ||
| } | ||
|
|
||
| const jsonMatch = content.match(/\{[\s\S]*\}/); | ||
| const jsonString = jsonMatch ? jsonMatch[0] : content; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: nehraa/CodeFlow
Length of output: 499
🏁 Script executed:
# See the git diff for this file in the current commit git diff HEAD -- next-env.d.tsRepository: nehraa/CodeFlow
Length of output: 41
🏁 Script executed:
# Check the file content cat -n next-env.d.tsRepository: nehraa/CodeFlow
Length of output: 351
🏁 Script executed:
Repository: nehraa/CodeFlow
Length of output: 975
🏁 Script executed:
Repository: nehraa/CodeFlow
Length of output: 86
🏁 Script executed:
# Check git history to see what changed git log --oneline -10 -- next-env.d.tsRepository: nehraa/CodeFlow
Length of output: 124
🏁 Script executed:
Repository: nehraa/CodeFlow
Length of output: 84
🏁 Script executed:
Repository: nehraa/CodeFlow
Length of output: 207
🏁 Script executed:
Repository: nehraa/CodeFlow
Length of output: 497
🏁 Script executed:
Repository: nehraa/CodeFlow
Length of output: 173
🏁 Script executed:
Repository: nehraa/CodeFlow
Length of output: 155
🏁 Script executed:
Repository: nehraa/CodeFlow
Length of output: 41
🌐 Web query:
Next.js typedRoutes routes.d.ts .next/dev/types path generation💡 Result:
Next.js generates the routes.d.ts file for typedRoutes as part of its type generation process when the typedRoutes option is enabled in next.config.js. This provides type-safe routes, including a Route type and global helpers like PageProps and LayoutProps. To enable: In next.config.js: const nextConfig = { typedRoutes: true, } module.exports = nextConfig The routes.d.ts file is automatically generated: - In development: .next/dev/types/routes.d.ts - In production/build: .next/types/routes.d.ts Generation occurs during: - next dev - next build - Or manually via next typegen (generates types without full build, useful for CI/type-checking) The next-env.d.ts file (in project root) imports the appropriate routes.d.ts path and should be gitignored as it toggles between dev/prod paths. Ensure tsconfig.json includes: "include": [ "next-env.d.ts", ".next/types//.ts", "/.ts", "/*.tsx" ] Usage example for typed routes: const route: Route<'/blog/[slug]'> = '/blog/my-post'; // Provides autocomplete, validation for Link href, navigation methods (push, redirect, etc.), supports dynamic segments. This feature requires TypeScript and works with App Router (and some Pages Router support). For full route tree scanning from app/ directory, parallel routes (
@slot), redirects/rewrites.Citations:
🏁 Script executed:
Repository: nehraa/CodeFlow
Length of output: 64
🏁 Script executed:
Repository: nehraa/CodeFlow
Length of output: 81
🏁 Script executed:
Repository: nehraa/CodeFlow
Length of output: 313
🏁 Script executed:
# Check the actual commit to see if next-env.d.ts was added or modified git show --stat c44e827Repository: nehraa/CodeFlow
Length of output: 21096
🏁 Script executed:
Repository: nehraa/CodeFlow
Length of output: 78
🏁 Script executed:
Repository: nehraa/CodeFlow
Length of output: 127
🏁 Script executed:
Repository: nehraa/CodeFlow
Length of output: 263
🏁 Script executed:
Repository: nehraa/CodeFlow
Length of output: 177
Remove next-env.d.ts from version control; it should be auto-generated per environment.
This file should not be committed to git. Per Next.js conventions, next-env.d.ts is auto-generated during
next devandnext buildwith environment-specific paths:.next/dev/types/routes.d.ts.next/types/routes.d.tsBy committing it with a hardcoded dev path, production builds will fail when Next.js generates
.next/types/routes.d.tsbut the committed file tries to import from.next/dev/types/routes.d.ts(which doesn't exist in that build).Fix: Remove next-env.d.ts from git history and add it to .gitignore. Let Next.js auto-generate it with the correct paths for each environment. The tsconfig.json already correctly includes both possible paths.
🤖 Prompt for AI Agents