Skip to content

Commit 8bf412b

Browse files
authored
Merge pull request #992 from RNViththagan/copilot-agent-checkpoint-mechanism
Implement checkpoint mechanism for AI copilot chat
2 parents 06023a6 + 0be430a commit 8bf412b

File tree

11 files changed

+648
-146
lines changed

11 files changed

+648
-146
lines changed

common/config/rush/pnpm-lock.yaml

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

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ export enum AIChatMachineEventType {
421421
DISABLE_AUTO_APPROVE = 'DISABLE_AUTO_APPROVE',
422422
REJECT_TASK = 'REJECT_TASK',
423423
RESTORE_STATE = 'RESTORE_STATE',
424+
RESTORE_CHECKPOINT = 'RESTORE_CHECKPOINT',
424425
ERROR = 'ERROR',
425426
RETRY = 'RETRY',
426427
CONNECTOR_GENERATION_REQUESTED = 'CONNECTOR_GENERATION_REQUESTED',
@@ -434,6 +435,16 @@ export interface ChatMessage {
434435
uiResponse: string;
435436
modelMessages: any[];
436437
timestamp: number;
438+
checkpointId?: string;
439+
}
440+
441+
export interface Checkpoint {
442+
id: string;
443+
messageId: string;
444+
timestamp: number;
445+
workspaceSnapshot: { [filePath: string]: string };
446+
fileList: string[];
447+
snapshotSize: number;
437448
}
438449

439450
/**
@@ -497,6 +508,7 @@ export interface AIChatMachineContext {
497508
comment?: string;
498509
};
499510
previousState?: AIChatMachineStateValue;
511+
checkpoints?: Checkpoint[];
500512
}
501513

502514
export type AIChatMachineSendableEvent =
@@ -515,6 +527,7 @@ export type AIChatMachineSendableEvent =
515527
| { type: AIChatMachineEventType.REJECT_TASK; payload: { comment?: string } }
516528
| { type: AIChatMachineEventType.RESET }
517529
| { type: AIChatMachineEventType.RESTORE_STATE; payload: { state: AIChatMachineContext } }
530+
| { type: AIChatMachineEventType.RESTORE_CHECKPOINT; payload: { checkpointId: string } }
518531
| { type: AIChatMachineEventType.ERROR; payload: { message: string } }
519532
| { type: AIChatMachineEventType.RETRY }
520533
| { type: AIChatMachineEventType.CONNECTOR_GENERATION_REQUESTED; payload: { requestId: string; serviceName?: string; serviceDescription?: string; fromState?: AIChatMachineStateValue } }
@@ -577,6 +590,8 @@ export enum ColorThemeKind {
577590
export interface UIChatHistoryMessage {
578591
role: "user" | "assistant";
579592
content: string;
593+
checkpointId?: string;
594+
messageId?: string;
580595
}
581596

582597
export const aiStateChanged: NotificationType<AIMachineStateValue> = { method: 'aiStateChanged' };
@@ -588,6 +603,12 @@ export const sendAIChatStateEvent: RequestType<AIChatMachineEventType | AIChatMa
588603
export const getAIChatContext: RequestType<void, AIChatMachineContext> = { method: 'getAIChatContext' };
589604
export const getAIChatUIHistory: RequestType<void, UIChatHistoryMessage[]> = { method: 'getAIChatUIHistory' };
590605

606+
export interface CheckpointCapturedPayload {
607+
messageId: string;
608+
checkpointId: string;
609+
}
610+
export const checkpointCaptured: NotificationType<CheckpointCapturedPayload> = { method: 'checkpointCaptured' };
611+
591612
// Connector Generator RPC methods
592613
export interface ConnectorGeneratorResponsePayload {
593614
requestId: string;

workspaces/ballerina/ballerina-extension/package.json

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,33 @@
233233
"Trace request/response messages only",
234234
"Trace request/response messages with parameters and content"
235235
]
236+
},
237+
"ballerina.copilot.checkpoints.enabled": {
238+
"type": "boolean",
239+
"default": true,
240+
"description": "Enable checkpoint mechanism for copilot chat to restore previous states."
241+
},
242+
"ballerina.copilot.checkpoints.maxCount": {
243+
"type": "number",
244+
"default": 20,
245+
"description": "Maximum number of checkpoints to keep."
246+
},
247+
"ballerina.copilot.checkpoints.ignorePatterns": {
248+
"type": "array",
249+
"default": [
250+
".git/**",
251+
"target/**",
252+
"build/**",
253+
"dist/**",
254+
".vscode/**",
255+
"*.log"
256+
],
257+
"description": "File patterns to ignore when creating checkpoints."
258+
},
259+
"ballerina.copilot.checkpoints.maxSnapshotSize": {
260+
"type": "number",
261+
"default": 52428800,
262+
"description": "Maximum snapshot size in bytes (default: 50MB)."
236263
}
237264
}
238265
},
@@ -1198,8 +1225,8 @@
11981225
"copyJSLibs": "copyfiles -f ../ballerina-visualizer/build/*.js resources/jslibs && copyfiles -f ../trace-visualizer/build/*.js resources/jslibs"
11991226
},
12001227
"dependencies": {
1201-
"@ai-sdk/amazon-bedrock": "^3.0.25",
1202-
"@ai-sdk/anthropic": "^2.0.20",
1228+
"@ai-sdk/amazon-bedrock": "^3.0.57",
1229+
"@ai-sdk/anthropic": "^2.0.45",
12031230
"@opentelemetry/auto-instrumentations-node": "^0.67.0",
12041231
"@opentelemetry/sdk-node": "^0.208.0",
12051232
"@types/lodash": "^4.14.200",
@@ -1211,7 +1238,7 @@
12111238
"@wso2/syntax-tree": "workspace:*",
12121239
"@wso2/trace-visualizer": "workspace:*",
12131240
"@wso2/wso2-platform-core": "workspace:*",
1214-
"ai": "^5.0.56",
1241+
"ai": "^5.0.101",
12151242
"cors-anywhere": "^0.4.4",
12161243
"del-cli": "^5.1.0",
12171244
"dotenv": "~16.5.0",

workspaces/ballerina/ballerina-extension/src/RPCLayer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import { WebviewView, WebviewPanel, window } from 'vscode';
2020
import { Messenger } from 'vscode-messenger';
2121
import { StateMachine } from './stateMachine';
22-
import { stateChanged, getVisualizerLocation, VisualizerLocation, projectContentUpdated, aiStateChanged, sendAIStateEvent, popupStateChanged, getPopupVisualizerState, PopupVisualizerLocation, breakpointChanged, AIMachineEventType, ArtifactData, onArtifactUpdatedNotification, onArtifactUpdatedRequest, currentThemeChanged, AIMachineSendableEvent, aiChatStateChanged, sendAIChatStateEvent, getAIChatContext, getAIChatUIHistory, AIChatMachineEventType, AIChatMachineSendableEvent } from '@wso2/ballerina-core';
22+
import { stateChanged, getVisualizerLocation, VisualizerLocation, projectContentUpdated, aiStateChanged, sendAIStateEvent, popupStateChanged, getPopupVisualizerState, PopupVisualizerLocation, breakpointChanged, AIMachineEventType, ArtifactData, onArtifactUpdatedNotification, onArtifactUpdatedRequest, currentThemeChanged, AIMachineSendableEvent, aiChatStateChanged, sendAIChatStateEvent, getAIChatContext, getAIChatUIHistory, AIChatMachineEventType, AIChatMachineSendableEvent, checkpointCaptured, CheckpointCapturedPayload } from '@wso2/ballerina-core';
2323
import { VisualizerWebview } from './views/visualizer/webview';
2424
import { registerVisualizerRpcHandlers } from './rpc-managers/visualizer/rpc-handler';
2525
import { registerLangClientRpcHandlers } from './rpc-managers/lang-client/rpc-handler';
@@ -190,3 +190,7 @@ export function notifyAiWebview() {
190190
export function notifyBreakpointChange() {
191191
RPCLayer._messenger.sendNotification(breakpointChanged, { type: 'webview', webviewType: VisualizerWebview.viewType }, true);
192192
}
193+
194+
export function notifyCheckpointCaptured(payload: CheckpointCapturedPayload) {
195+
RPCLayer._messenger.sendNotification(checkpointCaptured, { type: 'webview', webviewType: AiPanelWebview.viewType }, payload);
196+
}

0 commit comments

Comments
 (0)