Skip to content

Commit 7a6520b

Browse files
committed
Add proper TypeScript types and AI SDK dependency
- Add AIChatMachineContext type to task_write_tool.ts (replaces any) - Add ModelMessage type to state-machine-types.ts (replaces any[]) - Add AI SDK v5.0.101 dependency to ballerina-core for ModelMessage type - Add TODO comments for localStorage migration to state machine
1 parent 6b15e63 commit 7a6520b

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

workspaces/ballerina/ballerina-core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"tree-kill": "^1.2.2",
2828
"vscode-uri": "^3.0.8",
2929
"@types/mousetrap": "~1.6.11",
30-
"@types/ws": "^8.2.1"
30+
"@types/ws": "^8.2.1",
31+
"ai": "^5.0.101"
3132
},
3233
"devDependencies": {
3334
"@types/node": "^22.15.21",

workspaces/ballerina/ballerina-core/src/state-machine-types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import { NotificationType, RequestType } from "vscode-messenger-common";
2020
import { NodePosition, STNode } from "@wso2/syntax-tree";
21+
import { ModelMessage } from "ai";
2122
import { Command } from "./interfaces/ai-panel";
2223
import { LinePosition } from "./interfaces/common";
2324
import { Type } from "./interfaces/extended-lang-client";
@@ -434,7 +435,7 @@ export interface ChatMessage {
434435
id: string;
435436
content: string;
436437
uiResponse: string;
437-
modelMessages: any[];
438+
modelMessages: ModelMessage[];
438439
timestamp: number;
439440
checkpointId?: string;
440441
}

workspaces/ballerina/ballerina-extension/src/features/ai/service/libs/task_write_tool.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { tool } from 'ai';
1818
import { z } from 'zod';
1919
import { CopilotEventHandler } from '../event';
20-
import { Task, TaskStatus, TaskTypes, Plan, AIChatMachineEventType, SourceFiles } from '@wso2/ballerina-core';
20+
import { Task, TaskStatus, TaskTypes, Plan, AIChatMachineEventType, SourceFiles, AIChatMachineContext } from '@wso2/ballerina-core';
2121
import { AIChatStateMachine } from '../../../../views/ai-panel/aiChatMachine';
2222
import { integrateCodeToWorkspace } from '../design/utils';
2323
import { checkCompilationErrors } from './diagnostics_utils';
@@ -136,11 +136,11 @@ Rules:
136136

137137
const taskCategories = categorizeTasks(allTasks);
138138

139-
// TODO: Fix issue where agent updates to existing plan trigger new approval
140-
// Problem: When agent continues chat with plan updates, currentPlan state is empty
141-
// causing it to be identified as new plan and triggering approval unnecessarily.
142-
// Need to preserve plan state across chat continuations or use chat history to
143-
// detect if this is a continuation of an existing conversation with a plan.
139+
// TODO: Add tests for plan modification detection in the middle of execution
140+
// Fixed: Plan state is now preserved in the state machine across chat continuations,
141+
// preventing unnecessary approval requests when agent continues with existing plan.
142+
// Still need comprehensive tests for: mid-execution plan modifications, task reordering,
143+
// task additions/removals, and edge cases where plan changes should trigger re-approval.
144144
const isNewPlan = !existingPlan || existingPlan.tasks.length === 0;
145145
const isPlanRemodification = existingPlan && (
146146
allTasks.length !== existingPlan.tasks.length ||
@@ -306,7 +306,7 @@ async function handlePlanApproval(
306306
async function handleTaskCompletion(
307307
allTasks: Task[],
308308
newlyCompletedTasks: Task[],
309-
currentContext: any,
309+
currentContext: AIChatMachineContext,
310310
eventHandler: CopilotEventHandler,
311311
tempProjectPath?: string,
312312
modifiedFiles?: string[]

workspaces/ballerina/ballerina-visualizer/src/views/AIPanel/components/AIChat/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ const convertToUIMessages = (messages: UIChatHistoryMessage[]) => {
121121
};
122122

123123
// Helper function to load chat history from localStorage
124+
// TODO: Need to be removed and move chat history to statemachine fully
124125
const loadFromLocalStorage = (projectUuid: string, setMessages: React.Dispatch<React.SetStateAction<any[]>>, chatArray: ChatEntry[]) => {
125126
const localStorageFile = `chatArray-AIGenerationChat-${projectUuid}`;
126127
const storedChatArray = localStorage.getItem(localStorageFile);
@@ -315,6 +316,7 @@ const AIChat: React.FC = () => {
315316
setMessages(uiMessages);
316317

317318
chatArray = chatArray.slice(0, updatedMessages.length);
319+
// TODO: Need to be removed and move chat history to statemachine fully
318320
localStorage.setItem(`chatArray-AIGenerationChat-${projectUuid}`, JSON.stringify(chatArray));
319321

320322
setIsLoading(false);
@@ -1367,6 +1369,7 @@ const AIChat: React.FC = () => {
13671369
filepath: chatLocation,
13681370
});
13691371
integratedChatIndex = previouslyIntegratedChatIndex;
1372+
// TODO: Need to be removed and move chat history to statemachine fully
13701373
localStorage.setItem(
13711374
`chatArray-AIGenerationChat-${projectUuid}-developer-index`,
13721375
JSON.stringify({ integratedChatIndex, previouslyIntegratedChatIndex })

0 commit comments

Comments
 (0)