forked from evanp/inference-coop-copilot
Compare commits
6
Commits
e9a060af0f
..
v0.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
892151ef92 | ||
|
|
503273f17d | ||
|
|
bbf1b56a76 | ||
|
|
9b6e78e9f5 | ||
|
|
4e50c28def | ||
|
|
8f1d71d913 |
No files matched your search
+22
-6
@@ -8,7 +8,22 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
and this project adheres to
|
||||
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
## [0.3.0] - 2026-11-08
|
||||
|
||||
### Changed
|
||||
|
||||
- Removed the "(unofficial)" disclaimer from the package description and
|
||||
NOTICE, and the README; the project is now official, maintained in the
|
||||
co-op's Git at `code/inference-coop-copilot`.
|
||||
- Updated the repository URL to `https://git.inference.coop/code/inference-coop-copilot.git`
|
||||
in package.json and CHANGELOG links.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Abort in-flight chat requests on cancellation: an `AbortController` wired
|
||||
to `token.onCancellationRequested` closes the SSE connection as soon as
|
||||
the user stops the request, instead of the server continuing to generate
|
||||
until the response ends.
|
||||
|
||||
## [0.2.2] - 2026-11-06
|
||||
|
||||
@@ -70,8 +85,9 @@ First release usable for chat.
|
||||
|
||||
Initial development release. Not functional for chat.
|
||||
|
||||
[Unreleased]: https://git.inference.coop/evanp/inference-coop-copilot/compare/v0.2.2...HEAD
|
||||
[0.2.2]: https://git.inference.coop/evanp/inference-coop-copilot/compare/v0.2.1...v0.2.2
|
||||
[0.2.1]: https://git.inference.coop/evanp/inference-coop-copilot/compare/v0.2.0...v0.2.1
|
||||
[0.2.0]: https://git.inference.coop/evanp/inference-coop-copilot/compare/v0.1.0...v0.2.0
|
||||
[0.1.0]: https://git.inference.coop/evanp/inference-coop-copilot/releases/tag/v0.1.0
|
||||
[Unreleased]: https://git.inference.coop/code/inference-coop-copilot/compare/v0.3.0...HEAD
|
||||
[0.3.0]: https://git.inference.coop/code/inference-coop-copilot/compare/v0.2.2...v0.3.0
|
||||
[0.2.2]: https://git.inference.coop/code/inference-coop-copilot/compare/v0.2.1...v0.2.2
|
||||
[0.2.1]: https://git.inference.coop/code/inference-coop-copilot/compare/v0.2.0...v0.2.1
|
||||
[0.2.0]: https://git.inference.coop/code/inference-coop-copilot/compare/v0.1.0...v0.2.0
|
||||
[0.1.0]: https://git.inference.coop/code/inference-coop-copilot/releases/tag/v0.1.0
|
||||
@@ -1,4 +1,4 @@
|
||||
Inference Coop Copilot (unofficial)
|
||||
Inference Coop Copilot
|
||||
Copyright 2026 Evan Prodromou
|
||||
|
||||
Licensed under the Apache License, Version 2.0.
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "inference-coop-copilot",
|
||||
"version": "0.2.2",
|
||||
"version": "0.3.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "inference-coop-copilot",
|
||||
"version": "0.2.2",
|
||||
"version": "0.3.0",
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^10.0.10",
|
||||
"@types/node": "24.x",
|
||||
|
||||
+3
-3
@@ -1,15 +1,15 @@
|
||||
{
|
||||
"name": "inference-coop-copilot",
|
||||
"displayName": "inference-coop-copilot",
|
||||
"description": "Inference.coop models for Copilot Chat (unofficial)",
|
||||
"version": "0.2.2",
|
||||
"description": "Inference.coop models for Copilot Chat",
|
||||
"version": "0.3.0",
|
||||
"engines": {
|
||||
"vscode": "^1.145.0"
|
||||
},
|
||||
"publisher": "evanp",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.inference.coop/evanp/inference-coop-copilot.git"
|
||||
"url": "https://git.inference.coop/code/inference-coop-copilot.git"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"categories": [
|
||||
|
||||
+127
-94
@@ -109,118 +109,151 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
body.tool_choice = "auto";
|
||||
}
|
||||
|
||||
const res = await fetch(`${BASE_URL}/chat/completions`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${key}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
signal: token.isCancellationRequested ? AbortSignal.abort() : undefined,
|
||||
});
|
||||
out.appendLine(` /chat/completions status: ${res.status}`);
|
||||
if (!res.ok || !res.body) {
|
||||
throw new Error(
|
||||
`Inference Coop: HTTP ${res.status} — ${await res.text()}`,
|
||||
);
|
||||
if (token.isCancellationRequested) {
|
||||
out.appendLine(" request cancelled before it started");
|
||||
return;
|
||||
}
|
||||
|
||||
const reader = res.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let buf = "";
|
||||
let textChunks = 0;
|
||||
const pending = new Map<
|
||||
number,
|
||||
{ id?: string; name: string; args: string }
|
||||
>();
|
||||
// Abort the request as soon as the user cancels, so a cancelled chat
|
||||
// stops generating (and stops billing) server-side.
|
||||
const abort = new AbortController();
|
||||
const cancelSubscription = token.onCancellationRequested(() =>
|
||||
abort.abort(),
|
||||
);
|
||||
|
||||
const flushTools = () => {
|
||||
for (const call of pending.values()) {
|
||||
let input: object = {};
|
||||
try {
|
||||
input = JSON.parse(call.args || "{}");
|
||||
} catch {
|
||||
out.appendLine(
|
||||
` WARN bad tool args for ${call.name}: ${call.args}`,
|
||||
);
|
||||
}
|
||||
out.appendLine(` tool call: ${call.name} ${JSON.stringify(input)}`);
|
||||
progress.report(
|
||||
new vscode.LanguageModelToolCallPart(
|
||||
call.id ?? `call_${Math.random().toString(36).slice(2)}`,
|
||||
call.name,
|
||||
input,
|
||||
),
|
||||
try {
|
||||
const res = await fetch(`${BASE_URL}/chat/completions`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${key}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
signal: abort.signal,
|
||||
});
|
||||
out.appendLine(` /chat/completions status: ${res.status}`);
|
||||
if (!res.ok || !res.body) {
|
||||
throw new Error(
|
||||
`Inference Coop: HTTP ${res.status} — ${await res.text()}`,
|
||||
);
|
||||
}
|
||||
pending.clear();
|
||||
};
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) {
|
||||
break;
|
||||
}
|
||||
buf += decoder.decode(value, { stream: true });
|
||||
const frames = buf.split("\n\n");
|
||||
buf = frames.pop() ?? "";
|
||||
const reader = res.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let buf = "";
|
||||
let textChunks = 0;
|
||||
const pending = new Map<
|
||||
number,
|
||||
{ id?: string; name: string; args: string }
|
||||
>();
|
||||
|
||||
for (const frame of frames) {
|
||||
for (const line of frame.split("\n")) {
|
||||
if (!line.startsWith("data:")) {
|
||||
continue;
|
||||
}
|
||||
const data = line.slice(5).trim();
|
||||
if (data === "[DONE]") {
|
||||
if (pending.size) {
|
||||
flushTools();
|
||||
}
|
||||
out.appendLine(` done, ${textChunks} text chunks`);
|
||||
return;
|
||||
}
|
||||
let json: any;
|
||||
const flushTools = () => {
|
||||
for (const call of pending.values()) {
|
||||
let input: object = {};
|
||||
try {
|
||||
json = JSON.parse(data);
|
||||
input = JSON.parse(call.args || "{}");
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
const choice = json.choices?.[0];
|
||||
const delta = choice?.delta;
|
||||
if (!delta) {
|
||||
continue;
|
||||
out.appendLine(
|
||||
` WARN bad tool args for ${call.name}: ${call.args}`,
|
||||
);
|
||||
}
|
||||
out.appendLine(` tool call: ${call.name} ${JSON.stringify(input)}`);
|
||||
progress.report(
|
||||
new vscode.LanguageModelToolCallPart(
|
||||
call.id ?? `call_${Math.random().toString(36).slice(2)}`,
|
||||
call.name,
|
||||
input,
|
||||
),
|
||||
);
|
||||
}
|
||||
pending.clear();
|
||||
};
|
||||
|
||||
if (typeof delta.content === "string" && delta.content) {
|
||||
textChunks++;
|
||||
progress.report(new vscode.LanguageModelTextPart(delta.content));
|
||||
}
|
||||
while (true) {
|
||||
if (token.isCancellationRequested) {
|
||||
out.appendLine(" cancelled mid-stream; aborting request");
|
||||
abort.abort(); // close the connection so the gateway stops generating
|
||||
return;
|
||||
}
|
||||
const { done, value } = await reader.read();
|
||||
if (done) {
|
||||
break;
|
||||
}
|
||||
buf += decoder.decode(value, { stream: true });
|
||||
const frames = buf.split("\n\n");
|
||||
buf = frames.pop() ?? "";
|
||||
|
||||
for (const tc of delta.tool_calls ?? []) {
|
||||
const i = tc.index ?? 0;
|
||||
const acc = pending.get(i) ?? {
|
||||
id: undefined,
|
||||
name: "",
|
||||
args: "",
|
||||
};
|
||||
acc.id = tc.id ?? acc.id;
|
||||
acc.name = tc.function?.name ?? acc.name;
|
||||
acc.args += tc.function?.arguments ?? "";
|
||||
pending.set(i, acc);
|
||||
}
|
||||
for (const frame of frames) {
|
||||
for (const line of frame.split("\n")) {
|
||||
if (!line.startsWith("data:")) {
|
||||
continue;
|
||||
}
|
||||
const data = line.slice(5).trim();
|
||||
if (data === "[DONE]") {
|
||||
if (pending.size) {
|
||||
flushTools();
|
||||
}
|
||||
out.appendLine(` done, ${textChunks} text chunks`);
|
||||
return;
|
||||
}
|
||||
let json: any;
|
||||
try {
|
||||
json = JSON.parse(data);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
const choice = json.choices?.[0];
|
||||
const delta = choice?.delta;
|
||||
if (!delta) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (choice?.finish_reason) {
|
||||
out.appendLine(` finish_reason: ${choice.finish_reason}`);
|
||||
if (pending.size) {
|
||||
flushTools();
|
||||
if (typeof delta.content === "string" && delta.content) {
|
||||
textChunks++;
|
||||
progress.report(new vscode.LanguageModelTextPart(delta.content));
|
||||
}
|
||||
|
||||
for (const tc of delta.tool_calls ?? []) {
|
||||
const i = tc.index ?? 0;
|
||||
const acc = pending.get(i) ?? {
|
||||
id: undefined,
|
||||
name: "",
|
||||
args: "",
|
||||
};
|
||||
acc.id = tc.id ?? acc.id;
|
||||
acc.name = tc.function?.name ?? acc.name;
|
||||
acc.args += tc.function?.arguments ?? "";
|
||||
pending.set(i, acc);
|
||||
}
|
||||
|
||||
if (choice?.finish_reason) {
|
||||
out.appendLine(` finish_reason: ${choice.finish_reason}`);
|
||||
if (pending.size) {
|
||||
flushTools();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pending.size) {
|
||||
flushTools();
|
||||
}
|
||||
out.appendLine(` stream ended, ${textChunks} text chunks`);
|
||||
} catch (e) {
|
||||
// A cancellation aborts fetch (before headers) or the pending stream
|
||||
// read (mid-response) - both surface as AbortError. That is the user
|
||||
// pressing stop, not a failure: stop quietly instead of erroring.
|
||||
if (
|
||||
token.isCancellationRequested ||
|
||||
(e instanceof Error && e.name === "AbortError")
|
||||
) {
|
||||
out.appendLine(" stream aborted after cancellation");
|
||||
return;
|
||||
}
|
||||
throw e;
|
||||
} finally {
|
||||
cancelSubscription.dispose();
|
||||
}
|
||||
if (pending.size) {
|
||||
flushTools();
|
||||
}
|
||||
out.appendLine(` stream ended, ${textChunks} text chunks`);
|
||||
},
|
||||
|
||||
async provideTokenCount() {
|
||||
|
||||
Reference in new issue
Block a user