-
Notifications
You must be signed in to change notification settings - Fork 0
Refracting #72
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
Refracting #72
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "semi": true, | ||
| "singleQuote": true | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -40,29 +40,25 @@ export default function BaseNode({ id, type, data }: BaseNodeProps) { | |||
| onClick={onConfigure} | ||||
| className=" | ||||
| group | ||||
| w-[240px] | ||||
| w-[140px] | ||||
| px-4 py-6 | ||||
| bg-gray-800/40 | ||||
| bg-white | ||||
| border-2 border-dashed border-gray-600 | ||||
| rounded-lg | ||||
| cursor-pointer | ||||
| transition-all duration-200 | ||||
| hover:border-blue-500 | ||||
| hover:bg-gray-800/60 | ||||
| hover:bg-white | ||||
| hover:shadow-lg hover:shadow-blue-500/20 | ||||
| flex flex-col items-center gap-3 | ||||
| " | ||||
| > | ||||
| {/* Icon */} | ||||
| <div | ||||
| className=" | ||||
| w-12 h-12 | ||||
| rounded-full | ||||
| bg-gray-700/50 | ||||
| border border-gray-600 | ||||
| flex items-center justify-center | ||||
| w-7 h-7 flex items-center justify-center | ||||
| bg-white | ||||
| text-2xl | ||||
| group-hover:bg-blue-500/20 | ||||
| group-hover:border-blue-500 | ||||
|
||||
| group-hover:border-blue-500 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { ExecuteParams, ExecuteResult } from "./types.js"; | ||
| export declare class AgentExecution { | ||
| private llmClinet; | ||
| constructor(); | ||
| Execute(paramas: ExecuteParams): Promise<ExecuteResult | undefined>; | ||
| } | ||
| //# sourceMappingURL=executor.d.ts.map |
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,51 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import LLMClient from "../LlmClient.js"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export class AgentExecution { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constructor() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.llmClinet = new LLMClient(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async Execute(paramas) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!paramas) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+2
to
+8
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const prompt = paramas.task; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const context = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| task: prompt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model: paramas.model, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| maxIterations: paramas.maxIterations, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| systemPrompt: paramas.systemPrompt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| messages: [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| iterationCount: 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| totalTokens: 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| context.messages.push({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| role: "system", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: context.systemPrompt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| role: "user", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: prompt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while (context.iterationCount < context.maxIterations) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+11
to
+27
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const input = context.messages; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = await this.llmClinet.call(input); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // if(!stopReason.){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // success: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // result: result.text, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // iterations: context.iterationCount + 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // tokensUsed: result.inputTokens + result.outputTokens, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // stopReason: "completed" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| catch (e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.warn("Internal Server Error"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| catch (e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.warn("Internal Server Error"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+31
to
+47
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // if(!stopReason.){ | |
| // return { | |
| // success: true, | |
| // result: result.text, | |
| // iterations: context.iterationCount + 1, | |
| // tokensUsed: result.inputTokens + result.outputTokens, | |
| // stopReason: "completed" | |
| // } | |
| // } | |
| } | |
| catch (e) { | |
| console.warn("Internal Server Error"); | |
| } | |
| } | |
| } | |
| catch (e) { | |
| console.warn("Internal Server Error"); | |
| // increment iteration count on successful call | |
| context.iterationCount++; | |
| // on success, return a structured response | |
| return { | |
| success: true, | |
| result: result && typeof result.text !== "undefined" ? result.text : result, | |
| iterations: context.iterationCount, | |
| tokensUsed: (result && typeof result.inputTokens === "number" ? result.inputTokens : 0) + | |
| (result && typeof result.outputTokens === "number" ? result.outputTokens : 0), | |
| stopReason: "completed" | |
| }; | |
| } | |
| catch (e) { | |
| // increment iteration count on error | |
| context.iterationCount++; | |
| console.warn("Internal Server Error", e); | |
| // if we've exhausted the maximum number of iterations, abort and return failure | |
| if (context.iterationCount >= context.maxIterations) { | |
| return { | |
| success: false, | |
| error: e && e.message ? e.message : "Internal Server Error", | |
| iterations: context.iterationCount, | |
| stopReason: "error" | |
| }; | |
| } | |
| // simple backoff before retrying to avoid a tight loop on repeated errors | |
| const backoffMs = 100 * context.iterationCount; | |
| await new Promise(resolve => setTimeout(resolve, backoffMs)); | |
| } | |
| } | |
| } | |
| catch (e) { | |
| console.warn("Internal Server Error", e); |
Copilot
AI
Mar 1, 2026
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.
Execute is declared (via typings) to return an ExecuteResult | undefined, but the current implementation always returns undefined and ignores result from the LLM call. Please either implement the ExecuteResult return path (success/error/stopReason, token accounting, etc.) or change the method signature to match the actual behavior.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| export interface SystemMessage { | ||
| role: "system"; | ||
| content: string; | ||
| } | ||
| export interface UserMessage { | ||
| role: "user"; | ||
| content: string; | ||
| } | ||
| export interface ToolCall { | ||
| id: string; | ||
| type: "function"; | ||
| function: { | ||
| name: string; | ||
| arguments: string; | ||
| }; | ||
| } | ||
| export interface AssistantMessage { | ||
| role: "assistant"; | ||
| content: string | null; | ||
| tool_calls?: ToolCall[]; | ||
| } | ||
| export interface ToolMessage { | ||
| role: "tool"; | ||
| tool_call_id: string; | ||
| content: string; | ||
| } | ||
| export type Message = SystemMessage | UserMessage | AssistantMessage | ToolMessage; | ||
| export interface ExecuteParams { | ||
| task: string; | ||
| toolNames: string[]; | ||
| model: string; | ||
| systemPrompt?: string; | ||
| maxIterations?: number; | ||
| } | ||
| export interface ExecuteResult { | ||
| success: boolean; | ||
| result: string; | ||
| iterations: number; | ||
| tokensUsed: number; | ||
| stopReason: "completed" | "max_iterations" | "error"; | ||
| } | ||
| export interface AgentContext { | ||
| task: string; | ||
| model: string; | ||
| maxIterations: number; | ||
| systemPrompt: string; | ||
| messages: Message[]; | ||
| iterationCount: number; | ||
| totalTokens: number; | ||
| } | ||
| export interface StopCheck { | ||
| shouldStop: boolean; | ||
| reason: "completed" | "max_iterations" | "error" | "continue"; | ||
| } | ||
| //# sourceMappingURL=types.d.ts.map |
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 | ||
|---|---|---|---|---|
| @@ -0,0 +1,2 @@ | ||||
| // apps/worker/src/agent/types.ts | ||||
|
||||
| // apps/worker/src/agent/types.ts |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| declare class LLMClient { | ||
| call(prompt: any[], options?: { | ||
| temperature: number; | ||
| maxOutputTokens: number; | ||
| }): Promise<{ | ||
| text: string; | ||
| inputTokens: number; | ||
| outputTokens: number; | ||
| totalCount: number; | ||
| }>; | ||
| } | ||
| export default LLMClient; | ||
| //# sourceMappingURL=LlmClient.d.ts.map |
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 | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,64 @@ | ||||||||||||||||||||||||||||||||||||||
| import axios from "axios"; | ||||||||||||||||||||||||||||||||||||||
| import dotenv from "dotenv"; | ||||||||||||||||||||||||||||||||||||||
| dotenv.config(); | ||||||||||||||||||||||||||||||||||||||
| class LLMClient { | ||||||||||||||||||||||||||||||||||||||
| async call(prompt, options) { | ||||||||||||||||||||||||||||||||||||||
| const GEMINI_URL = process.env.GEMINI_URL || | ||||||||||||||||||||||||||||||||||||||
| "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-flash-preview:generateContent"; | ||||||||||||||||||||||||||||||||||||||
| const GEMINI_API_KEY = process.env.GEMINI_API_KEY; | ||||||||||||||||||||||||||||||||||||||
| if (!GEMINI_API_KEY) | ||||||||||||||||||||||||||||||||||||||
| throw new Error("GEMINI API KEY not specified (why env is not working?)"); | ||||||||||||||||||||||||||||||||||||||
| if (!GEMINI_URL) | ||||||||||||||||||||||||||||||||||||||
| throw new Error("GEMINI URL not specified (why env is not working?)"); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+10
to
+12
|
||||||||||||||||||||||||||||||||||||||
| throw new Error("GEMINI API KEY not specified (why env is not working?)"); | |
| if (!GEMINI_URL) | |
| throw new Error("GEMINI URL not specified (why env is not working?)"); | |
| throw new Error("Environment variable GEMINI_API_KEY is not set. Please configure GEMINI_API_KEY in your environment or .env file."); | |
| if (!GEMINI_URL) | |
| throw new Error("Environment variable GEMINI_URL is not set. Please configure GEMINI_URL in your environment or .env file."); |
Copilot
AI
Mar 1, 2026
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.
call(prompt, ...) builds the Gemini payload with text: prompt, but the only call site passes an array of message objects (context.messages). That will serialize incorrectly (e.g., [object Object]) and won't produce the intended prompt. Either change LLMClient.call to accept a string, or convert the messages array into Gemini contents format before sending.
Copilot
AI
Mar 1, 2026
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.
options is treated as required (options.temperature, options.maxOutputTokens), but the only call site (AgentExecution) calls call(input) without passing options. This will throw a TypeError at runtime. Please make options truly optional by supplying defaults (or using optional chaining) and/or updating the call site to always pass a complete options object.
Copilot
AI
Mar 1, 2026
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.
console.log("LLM Response:", response.data) logs the full model response (and likely includes user prompt/PII and token usage). This can leak sensitive data into logs in production. Consider removing this log or gating it behind a debug flag/logger with redaction.
| console.log("LLM Response:", response.data); | |
| const actuaResponse = response.data.candidates[0].content.parts[0]; | |
| // console.log("THe outpusssst is ", actuaResponse.text); | |
| if (process.env.LLM_DEBUG === "true") { | |
| console.log("LLM response metadata:", { | |
| candidateCount: response.data?.candidates?.length, | |
| usageMetadata: response.data?.usageMetadata, | |
| }); | |
| } | |
| const actuaResponse = response.data.candidates[0].content.parts[0]; | |
| // Use actuaResponse.text as needed in callers. |
Copilot
AI
Mar 1, 2026
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.
Several identifiers here look misspelled (actuaResponse, inputToknes, outputTOkens), which makes the code harder to read and maintain. Please rename them to correctly spelled names to avoid confusion and reduce the chance of propagating typos into the API.
| const actuaResponse = response.data.candidates[0].content.parts[0]; | |
| // console.log("THe outpusssst is ", actuaResponse.text); | |
| const inputToknes = response.data.usageMetadata.promptTokenCount; | |
| const outputTOkens = response.data.usageMetadata.candidatesTokenCount; | |
| const totalTokenCount = response.data.usageMetadata.totalTokenCount; | |
| return { | |
| text: actuaResponse.text, | |
| inputTokens: inputToknes, | |
| outputTokens: outputTOkens, | |
| const actualResponse = response.data.candidates[0].content.parts[0]; | |
| // console.log("THe outpusssst is ", actualResponse.text); | |
| const inputTokens = response.data.usageMetadata.promptTokenCount; | |
| const outputTokens = response.data.usageMetadata.candidatesTokenCount; | |
| const totalTokenCount = response.data.usageMetadata.totalTokenCount; | |
| return { | |
| text: actualResponse.text, | |
| inputTokens: inputTokens, | |
| outputTokens: outputTokens, |
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.
This repo currently uses double quotes broadly (e.g.,
apps/web/app/components/nodes/BaseNode.tsx:1,packages/LLM/src/LlmClient.js:1). Setting PrettiersingleQuote: truewill either force widespread reformatting or leave the codebase inconsistent. Please align the Prettier config with the existing quote style (or reformat the repo consistently in the same PR).