Skip to content

Commit 1f6dba8

Browse files
Code Cleanup & Better System Design
1 parent c9a6554 commit 1f6dba8

File tree

131 files changed

+15670
-14652
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+15670
-14652
lines changed

.npmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

AdaptiveDeepthink/AdaptiveDeepthinkCore.ts

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ export interface AdaptiveDeepthinkState {
3535
question: string;
3636
status: 'idle' | 'processing' | 'completed' | 'error';
3737
error?: string;
38-
38+
3939
// Data stores with unique IDs
4040
strategies: Map<string, { text: string }>;
4141
hypotheses: Map<string, { text: string }>;
4242
hypothesisTestings: Map<string, { hypothesis: string; testing: string }>;
4343
executions: Map<string, { strategy: string; execution: string }>;
4444
critiques: Map<string, { critique: string }>;
4545
correctedSolutions: Map<string, { strategy: string; correctedSolution: string }>;
46-
46+
4747
// Final result
4848
selectedSolution?: string;
4949
}
@@ -87,11 +87,11 @@ export class AdaptiveDeepthinkConversationManager {
8787

8888
async buildPrompt(): Promise<string> {
8989
const history = await this.getConversationHistory();
90-
90+
9191
if (!history || history.trim().length === 0) {
9292
return `Core Challenge: ${this.question}`;
9393
}
94-
94+
9595
return history;
9696
}
9797

@@ -214,8 +214,7 @@ export async function executeAdaptiveDeepthinkTool(
214214
state: AdaptiveDeepthinkState,
215215
context: AgentExecutionContext,
216216
deepthinkPrompts: any,
217-
imageBase64?: string | null,
218-
imageMimeType?: string | null
217+
images: Array<{ base64: string, mimeType: string }> = []
219218
): Promise<string> {
220219
try {
221220
switch (toolCall.type) {
@@ -227,8 +226,7 @@ export async function executeAdaptiveDeepthinkTool(
227226
deepthinkPrompts.sys_deepthink_initialStrategy,
228227
deepthinkPrompts.user_deepthink_initialStrategy,
229228
context,
230-
imageBase64,
231-
imageMimeType
229+
images
232230
);
233231

234232
if (!response.success || !response.data) {
@@ -254,8 +252,7 @@ export async function executeAdaptiveDeepthinkTool(
254252
deepthinkPrompts.sys_deepthink_hypothesisGeneration,
255253
deepthinkPrompts.user_deepthink_hypothesisGeneration,
256254
context,
257-
imageBase64,
258-
imageMimeType
255+
images
259256
);
260257

261258
if (!response.success || !response.data) {
@@ -282,8 +279,7 @@ export async function executeAdaptiveDeepthinkTool(
282279
deepthinkPrompts.sys_deepthink_hypothesisTester,
283280
deepthinkPrompts.user_deepthink_hypothesisTester,
284281
context,
285-
imageBase64,
286-
imageMimeType
282+
images
287283
);
288284

289285
if (!response.success || !response.data) {
@@ -318,8 +314,7 @@ export async function executeAdaptiveDeepthinkTool(
318314
deepthinkPrompts.sys_deepthink_solutionAttempt,
319315
deepthinkPrompts.user_deepthink_solutionAttempt,
320316
context,
321-
imageBase64,
322-
imageMimeType
317+
images
323318
);
324319

325320
if (!response.success || !response.data) {
@@ -351,8 +346,7 @@ export async function executeAdaptiveDeepthinkTool(
351346
deepthinkPrompts.sys_deepthink_solutionCritique,
352347
deepthinkPrompts.user_deepthink_solutionCritique,
353348
context,
354-
imageBase64,
355-
imageMimeType
349+
images
356350
);
357351

358352
if (!response.success || !response.data) {
@@ -380,8 +374,7 @@ export async function executeAdaptiveDeepthinkTool(
380374
deepthinkPrompts.sys_deepthink_selfImprovement,
381375
deepthinkPrompts.user_deepthink_selfImprovement,
382376
context,
383-
imageBase64,
384-
imageMimeType
377+
images
385378
);
386379

387380
if (!response.success || !response.data) {
@@ -415,8 +408,7 @@ export async function executeAdaptiveDeepthinkTool(
415408
deepthinkPrompts.sys_deepthink_finalJudge,
416409
'Evaluate all provided solutions and select the best one. Provide your reasoning and the selected solution.\n\nCore Challenge: {{originalProblemText}}\n\n{{allSolutions}}',
417410
context,
418-
imageBase64,
419-
imageMimeType
411+
images
420412
);
421413

422414
if (!response.success || !response.data) {

AdaptiveDeepthink/AdaptiveDeepthinkMode.tsx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ReactDOM from 'react-dom/client';
1111
import { flushSync } from 'react-dom';
1212
import { AgenticState, AgenticMessage, SystemBlock } from '../Agentic/AgenticCore';
1313
import { AgentActivityPanel } from '../Agentic/AgenticUI';
14-
import { renderMathContent } from '../Components/RenderMathMarkdown';
14+
import { renderMathContent } from '../Styles/Components/RenderMathMarkdown';
1515
import {
1616
AdaptiveDeepthinkState,
1717
AdaptiveDeepthinkConversationManager,
@@ -838,9 +838,12 @@ export function renderAdaptiveDeepthinkMode() {
838838
export async function startAdaptiveDeepthinkProcess(
839839
question: string,
840840
customPrompts: CustomizablePromptsAdaptiveDeepthink,
841-
imageBase64?: string | null,
842-
imageMimeType?: string | null
841+
images: Array<{ base64: string, mimeType: string }> = []
843842
) {
843+
// Stop any existing process
844+
if (activeAdaptiveDeepthinkState) {
845+
stopAdaptiveDeepthinkProcess();
846+
}
844847
if (!question || globalState.isAdaptiveDeepthinkRunning) return;
845848

846849
// Create state
@@ -881,15 +884,17 @@ export async function startAdaptiveDeepthinkProcess(
881884
// Render initial UI
882885
renderAdaptiveDeepthinkMode();
883886

884-
// Start the orchestration loop
885-
await runAdaptiveDeepthinkLoop(customPrompts, imageBase64, imageMimeType);
887+
// Start the process in the background
888+
startAdaptiveDeepthinkSession(question, customPrompts, images).catch(err => {
889+
console.error("Adaptive Deepthink Error:", err);
890+
});
886891
}
887892

888893
// Main orchestration loop
889-
async function runAdaptiveDeepthinkLoop(
894+
async function startAdaptiveDeepthinkSession(
895+
question: string,
890896
customPrompts: CustomizablePromptsAdaptiveDeepthink,
891-
imageBase64?: string | null,
892-
imageMimeType?: string | null
897+
images: Array<{ base64: string, mimeType: string }> = []
893898
) {
894899
if (!activeAdaptiveDeepthinkState || !globalState.isAdaptiveDeepthinkRunning) return;
895900

@@ -978,12 +983,12 @@ async function runAdaptiveDeepthinkLoop(
978983
await new Promise(resolve => setTimeout(resolve, delay));
979984
}
980985

981-
const promptParts: any[] = [{ text: prompt }];
982-
if (imageBase64 && imageMimeType) {
986+
const promptParts: any[] = [{ text: prompt }]; // Using any[] to match Gemini expectations broadly or fix type mismatch
987+
images.slice().reverse().forEach(img => {
983988
promptParts.unshift({
984-
inlineData: { mimeType: imageMimeType, data: imageBase64 }
989+
inlineData: { mimeType: img.mimeType, data: img.base64 }
985990
});
986-
}
991+
});
987992

988993
const response = await callAI(
989994
promptParts,
@@ -1106,8 +1111,7 @@ async function runAdaptiveDeepthinkLoop(
11061111
activeAdaptiveDeepthinkState.coreState,
11071112
agentContext,
11081113
deepthinkPrompts,
1109-
imageBase64,
1110-
imageMimeType
1114+
images
11111115
);
11121116

11131117
// Parse tool result and update Deepthink state IMMEDIATELY

Agentic/AgenticUI.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import React from 'react';
77
import ReactDOM from 'react-dom/client';
88
import { flushSync } from 'react-dom';
99
import { AgenticState, AgenticMessage } from './AgenticCore';
10-
import { renderMathContent } from '../Components/RenderMathMarkdown';
10+
import { renderMathContent } from '../Styles/Components/RenderMathMarkdown';
1111
import { FaRobot, FaUser, FaCheckCircle, FaExclamationTriangle, FaStop, FaCalendarAlt, FaTag, FaFilePdf, FaExternalLinkAlt, FaChevronDown, FaChevronRight } from 'react-icons/fa';
1212
import { MdVerifiedUser } from 'react-icons/md';
1313
import { IoMdPaper } from 'react-icons/io';
@@ -709,7 +709,7 @@ export const CurrentTextPanel: React.FC<{ content: string; originalContent: stri
709709
<button
710710
className="action-btn"
711711
onClick={async () => {
712-
const { openEvolutionViewerFromHistory } = await import("../Components/DiffModal/EvolutionViewer");
712+
const { openEvolutionViewerFromHistory } = await import("../Styles/Components/DiffModal/EvolutionViewer");
713713
openEvolutionViewerFromHistory(state.contentHistory, state.id);
714714
}}
715715
title="View content evolution timeline (updates live)"
@@ -755,7 +755,7 @@ export const AgenticUI: React.FC<AgenticUIProps> = ({ state, onStop }) => {
755755
// Update evolution viewer when content history changes
756756
React.useEffect(() => {
757757
const updateViewer = async () => {
758-
const { updateEvolutionViewerIfOpen } = await import('../Components/DiffModal/EvolutionViewer');
758+
const { updateEvolutionViewerIfOpen } = await import('../Styles/Components/DiffModal/EvolutionViewer');
759759
updateEvolutionViewerIfOpen(state.id, state.contentHistory);
760760
};
761761
updateViewer();

0 commit comments

Comments
 (0)