mirror of
https://github.com/larsbaunwall/vscode-copilot-bridge.git
synced 2025-10-05 22:22:59 +00:00
Type shim: add minimal VS Code Chat API declarations to compile against proposed API
Co-Authored-By: Lars Baunwall <larslb@thinkability.dk>
This commit is contained in:
parent
e0bca1d50c
commit
5261239628
4 changed files with 82 additions and 6 deletions
58
package-lock.json
generated
Normal file
58
package-lock.json
generated
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
{
|
||||
"name": "copilot-bridge",
|
||||
"version": "0.1.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "copilot-bridge",
|
||||
"version": "0.1.0",
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.10.0",
|
||||
"@types/vscode": "^1.90.0",
|
||||
"typescript": "^5.4.0"
|
||||
},
|
||||
"engines": {
|
||||
"vscode": "^1.90.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "20.19.10",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.10.tgz",
|
||||
"integrity": "sha512-iAFpG6DokED3roLSP0K+ybeDdIX6Bc0Vd3mLW5uDqThPWtNos3E+EqOM11mPQHKzfWHqEBuLjIlsBQQ8CsISmQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~6.21.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/vscode": {
|
||||
"version": "1.102.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.102.0.tgz",
|
||||
"integrity": "sha512-V9sFXmcXz03FtYTSUsYsu5K0Q9wH9w9V25slddcxrh5JgORD14LpnOA7ov0L9ALi+6HrTjskLJ/tY5zeRF3TFA==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.9.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.2.tgz",
|
||||
"integrity": "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.17"
|
||||
}
|
||||
},
|
||||
"node_modules/undici-types": {
|
||||
"version": "6.21.0",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
|
||||
"integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.10.0",
|
||||
"typescript": "^5.4.0",
|
||||
"vscode": "^1.1.40"
|
||||
"@types/vscode": "^1.90.0",
|
||||
"typescript": "^5.4.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ async function startBridge() {
|
|||
access = undefined;
|
||||
}
|
||||
|
||||
server = http.createServer(async (req, res) => {
|
||||
server = http.createServer(async (req: http.IncomingMessage, res: http.ServerResponse) => {
|
||||
try {
|
||||
if (verbose) output?.appendLine(`HTTP ${req.method} ${req.url}`);
|
||||
if (token && req.headers.authorization !== `Bearer ${token}`) {
|
||||
|
|
@ -117,7 +117,7 @@ async function startBridge() {
|
|||
});
|
||||
const id = `cmp_${Math.random().toString(36).slice(2)}`;
|
||||
if (verbose) output?.appendLine(`SSE start id=${id}`);
|
||||
const h1 = chatStream.onDidProduceContent((chunk) => {
|
||||
const h1 = chatStream.onDidProduceContent((chunk: string) => {
|
||||
const payload = {
|
||||
id,
|
||||
object: 'chat.completion.chunk',
|
||||
|
|
@ -137,7 +137,7 @@ async function startBridge() {
|
|||
return;
|
||||
} else {
|
||||
let buf = '';
|
||||
const h1 = chatStream.onDidProduceContent((chunk) => { buf += chunk; });
|
||||
const h1 = chatStream.onDidProduceContent((chunk: string) => { buf += chunk; });
|
||||
await new Promise<void>((resolve) => {
|
||||
const h2 = chatStream.onDidEnd(() => {
|
||||
h1.dispose();
|
||||
|
|
@ -220,7 +220,7 @@ function normalizeMessages(messages: any[], histWindow: number): string {
|
|||
function readJson(req: http.IncomingMessage): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
let data = '';
|
||||
req.on('data', (c) => { data += c; });
|
||||
req.on('data', (c: Buffer) => { data += c.toString(); });
|
||||
req.on('end', () => {
|
||||
if (!data) return resolve({});
|
||||
try { resolve(JSON.parse(data)); } catch (e) { reject(e); }
|
||||
|
|
|
|||
18
src/vscode-chat-shim.d.ts
vendored
Normal file
18
src/vscode-chat-shim.d.ts
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
declare module 'vscode' {
|
||||
namespace chat {
|
||||
function requestChatAccess(providerId: string): Promise<ChatAccess>;
|
||||
}
|
||||
|
||||
interface ChatAccess {
|
||||
startSession(): Promise<ChatSession>;
|
||||
}
|
||||
|
||||
interface ChatSession {
|
||||
sendRequest(options: { prompt: string; attachments: any[] }): Promise<ChatResponseStream>;
|
||||
}
|
||||
|
||||
interface ChatResponseStream {
|
||||
onDidProduceContent(handler: (chunk: string) => void): { dispose(): void };
|
||||
onDidEnd(handler: () => void): { dispose(): void };
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue