Skip to content

Commit 3ae6ecf

Browse files
DonJayamanneCopilotrebornix
authored
Update github/copilot package with changes to load history (#1378)
* Reapply "Update @github/copilot package (#1372)" (#1376) This reverts commit 1ec7602. * Update version of github copilot * Update src/extension/agents/copilotcli/node/copilotcliSessionService.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * include copilotCLIShim --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Peng Lyu <penn.lv@gmail.com>
1 parent 2656f02 commit 3ae6ecf

File tree

9 files changed

+55
-45
lines changed

9 files changed

+55
-45
lines changed

.vscodeignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ assets/walkthroughs/**
1515
!dist/diffWorker.js
1616
!dist/webview.js
1717
!dist/copilotDebugCommand.js
18+
!dist/copilotCLIShim.js
1819
!dist/cli.js
1920
!node_modules/@vscode/copilot-typescript-server-plugin/package.json
2021
!node_modules/@vscode/copilot-typescript-server-plugin/dist/*.js

package-lock.json

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

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4236,6 +4236,7 @@
42364236
"@types/tar": "^6.1.13",
42374237
"@types/vinyl": "^2.0.12",
42384238
"@types/vscode": "^1.102.0",
4239+
"@types/yargs": "^17.0.24",
42394240
"@typescript-eslint/eslint-plugin": "^8.35.0",
42404241
"@typescript-eslint/parser": "^8.32.0",
42414242
"@typescript-eslint/typescript-estree": "^8.26.1",
@@ -4285,6 +4286,7 @@
42854286
"react-dom": "17.0.2",
42864287
"rimraf": "^6.0.1",
42874288
"run-script-os": "^1.1.6",
4289+
"shiki": "~1.15.0",
42884290
"sinon": "^21.0.0",
42894291
"source-map-support": "^0.5.21",
42904292
"tar": "^7.4.3",
@@ -4300,14 +4302,12 @@
43004302
"vscode-languageserver-textdocument": "^1.0.12",
43014303
"vscode-languageserver-types": "^3.17.5",
43024304
"yaml": "^2.8.0",
4303-
"yargs": "^17.7.2",
4304-
"@types/yargs": "^17.0.24",
4305-
"shiki": "~1.15.0"
4305+
"yargs": "^17.7.2"
43064306
},
43074307
"dependencies": {
43084308
"@anthropic-ai/claude-code": "^1.0.120",
43094309
"@anthropic-ai/sdk": "^0.63.0",
4310-
"@github/copilot": "^0.0.338",
4310+
"@github/copilot": "^0.0.342",
43114311
"@google/genai": "^1.22.0",
43124312
"@humanwhocodes/gitignore-to-minimatch": "1.0.2",
43134313
"@microsoft/tiktokenizer": "^1.0.10",

src/extension/agents/copilotcli/node/copilotcliSessionService.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ export class CopilotCLISessionService implements ICopilotCLISessionService {
7676
// @github/copilot has hardcoded: import{spawn}from"node-pty"
7777
await ensureNodePtyShim(this.extensionContext.extensionPath, this.envService.appRoot);
7878

79-
const { SessionManager } = await import('@github/copilot/sdk');
80-
this._sessionManager = new SessionManager({
79+
const { internal } = await import('@github/copilot/sdk');
80+
this._sessionManager = new internal.CLISessionManager({
8181
logger: {
8282
isDebug: () => false,
8383
debug: (msg: string) => this.logService.debug(msg),
@@ -209,6 +209,7 @@ export class CopilotCLISessionService implements ICopilotCLISessionService {
209209
// Clean up local caches
210210
this._sessions.delete(sessionId);
211211
this._sessionWrappers.deleteAndDispose(sessionId);
212+
this._onDidChangeSessions.fire();
212213

213214
return true;
214215
} catch (error) {
@@ -219,7 +220,7 @@ export class CopilotCLISessionService implements ICopilotCLISessionService {
219220

220221
private async _generateSessionLabel(sdkSession: Session, prompt: string | undefined): Promise<string> {
221222
try {
222-
const chatMessages = sdkSession.chatMessages;
223+
const chatMessages = await sdkSession.getChatMessages();
223224

224225
// Find the first user message
225226
const firstUserMessage = chatMessages.find(msg => msg.role === 'user');

src/extension/agents/copilotcli/node/copilotcliToolInvocationFormatter.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,34 @@
55

66
import type { SDKEvent } from '@github/copilot/sdk';
77
import * as l10n from '@vscode/l10n';
8-
import type { ChatCompletionMessageParam } from 'openai/resources/chat/completions';
98
import type { ExtendedChatResponsePart } from 'vscode';
109
import { URI } from '../../../../util/vs/base/common/uri';
1110
import { ChatRequestTurn2, ChatResponseMarkdownPart, ChatResponseThinkingProgressPart, ChatResponseTurn2, ChatToolInvocationPart, MarkdownString } from '../../../../vscodeTypes';
1211

12+
type ChatCompletionRole = 'system' | 'user' | 'assistant' | 'tool' | (string & {});
13+
14+
interface ChatCompletionMessageFunctionCall {
15+
name: string;
16+
arguments?: string;
17+
}
18+
19+
interface ChatCompletionMessageToolCallLike {
20+
id?: string;
21+
type?: string;
22+
function?: ChatCompletionMessageFunctionCall;
23+
}
24+
25+
interface ChatCompletionMessageParamLike {
26+
role: ChatCompletionRole;
27+
content?: unknown;
28+
tool_calls?: readonly ChatCompletionMessageToolCallLike[];
29+
tool_call_id?: string;
30+
}
31+
32+
function isUserOrAssistantRole(role: ChatCompletionRole): role is 'user' | 'assistant' {
33+
return role === 'user' || role === 'assistant';
34+
}
35+
1336
/**
1437
* CopilotCLI tool names
1538
*/
@@ -51,12 +74,12 @@ function resolveContentToString(content: unknown): string {
5174
* Parse chat messages from the CopilotCLI SDK into SDKEvent format
5275
* Used when loading session history from disk
5376
*/
54-
export function parseChatMessagesToEvents(chatMessages: readonly ChatCompletionMessageParam[]): SDKEvent[] {
77+
export function parseChatMessagesToEvents(chatMessages: readonly ChatCompletionMessageParamLike[]): SDKEvent[] {
5578
const events: SDKEvent[] = [];
5679

5780
for (const msg of chatMessages) {
5881
// Handle regular messages (user or assistant)
59-
if (msg.role === 'user' || msg.role === 'assistant') {
82+
if (isUserOrAssistantRole(msg.role)) {
6083
if (msg.content) {
6184
events.push({
6285
type: 'message' as const,

src/extension/agents/copilotcli/node/nodePtyShim.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { promises as fs } from 'fs';
77
import * as path from 'path';
88

9-
let shimCreated = false;
9+
let shimCreated: Promise<void> | undefined = undefined;
1010

1111
/**
1212
* Creates a node-pty ESM shim that @github/copilot can import.
@@ -21,9 +21,14 @@ let shimCreated = false;
2121
*/
2222
export async function ensureNodePtyShim(extensionPath: string, vscodeAppRoot: string): Promise<void> {
2323
if (shimCreated) {
24-
return;
24+
return shimCreated;
2525
}
2626

27+
shimCreated = _ensureNodePtyShim(extensionPath, vscodeAppRoot);
28+
return shimCreated;
29+
}
30+
31+
async function _ensureNodePtyShim(extensionPath: string, vscodeAppRoot: string): Promise<void> {
2732
const nodePtyDir = path.join(extensionPath, 'node_modules', 'node-pty');
2833
const vscodeNodePtyPath = path.join(vscodeAppRoot, 'node_modules', 'node-pty', 'lib', 'index.js');
2934

@@ -70,7 +75,6 @@ export default nodePty;
7075
`;
7176
await fs.writeFile(path.join(nodePtyDir, 'index.mjs'), indexMjs);
7277

73-
shimCreated = true;
7478
} catch (error) {
7579
console.warn('Failed to create node-pty shim:', error);
7680
throw error;

src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7-
import { ChatExtendedRequestHandler } from 'vscode';
7+
import { ChatExtendedRequestHandler, l10n } from 'vscode';
88
import { isLocation } from '../../../util/common/types';
99
import { Emitter, Event } from '../../../util/vs/base/common/event';
1010
import { Disposable, DisposableStore, IDisposable } from '../../../util/vs/base/common/lifecycle';
@@ -78,7 +78,7 @@ export class CopilotCLIChatSessionContentProvider implements vscode.ChatSessionC
7878
async provideChatSessionContent(copilotcliSessionId: string, token: vscode.CancellationToken): Promise<vscode.ChatSession> {
7979
const existingSession = copilotcliSessionId && await this.sessionService.getSession(copilotcliSessionId, token);
8080
const sdkSession = existingSession ? existingSession.sdkSession : undefined;
81-
const chatMessages = sdkSession?.chatMessages || [];
81+
const chatMessages = sdkSession ? await sdkSession.getChatMessages() : [];
8282
const events = parseChatMessagesToEvents(chatMessages);
8383

8484
const history = existingSession ? buildChatHistoryFromEvents(events) : [];
@@ -214,15 +214,16 @@ export function registerCLIChatCommands(copilotcliSessionItemProvider: CopilotCL
214214
}));
215215
disposableStore.add(vscode.commands.registerCommand('github.copilot.cli.sessions.delete', async (sessionItem?: vscode.ChatSessionItem) => {
216216
if (sessionItem?.id) {
217+
const deleteLabel = l10n.t('Delete');
217218
const result = await vscode.window.showWarningMessage(
218-
`Are you sure you want to delete the session?`,
219+
l10n.t('Are you sure you want to delete the session?'),
219220
{ modal: true },
220-
'Delete',
221-
'Cancel'
221+
deleteLabel
222222
);
223223

224-
if (result === 'Delete') {
224+
if (result === deleteLabel) {
225225
await copilotCLISessionService.deleteSession(sessionItem.id);
226+
copilotcliSessionItemProvider.refresh();
226227
}
227228
}
228229
}));

src/extension/chatSessions/vscode-node/copilotCLIShim.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# NOTE: This file intentionally keeps logic self‑contained (no external deps) so it can be dropped into PATH directly.
1414

1515
# Minimum required Copilot CLI version
16-
$RequiredVersion = "0.0.339"
16+
$RequiredVersion = "0.0.342"
1717

1818
function Find-RealCopilot {
1919
# Find the real copilot binary, avoiding this script if it's in PATH

src/extension/chatSessions/vscode-node/copilotCLIShim.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import * as path from '../../../util/vs/base/common/path';
2929
* NOTE: This file intentionally keeps logic self‑contained (no external deps) so it can be dropped into PATH directly.
3030
*/
3131

32-
const REQUIRED_VERSION = '0.0.339';
32+
const REQUIRED_VERSION = '0.0.342';
3333
const PACKAGE_NAME = '@github/copilot';
3434
const env = { ...process.env, PATH: (process.env.PATH || '').replaceAll(`${__dirname}${path.delimiter}`, '').replaceAll(`${path.delimiter}${__dirname}`, '') };
3535

0 commit comments

Comments
 (0)