@corbat-tech/coco 2.25.12 → 2.25.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +98 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +85 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -21541,6 +21541,8 @@ var init_http = __esm({
|
|
|
21541
21541
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
21542
21542
|
oauthToken;
|
|
21543
21543
|
oauthInFlight = null;
|
|
21544
|
+
sessionId;
|
|
21545
|
+
protocolVersion = "2024-11-05";
|
|
21544
21546
|
/**
|
|
21545
21547
|
* Get authentication token
|
|
21546
21548
|
*/
|
|
@@ -21560,12 +21562,20 @@ var init_http = __esm({
|
|
|
21560
21562
|
/**
|
|
21561
21563
|
* Build request headers
|
|
21562
21564
|
*/
|
|
21563
|
-
buildHeaders() {
|
|
21565
|
+
buildHeaders(method) {
|
|
21564
21566
|
const headers = {
|
|
21565
|
-
"
|
|
21566
|
-
|
|
21567
|
+
...method === "POST" ? {
|
|
21568
|
+
"Content-Type": "application/json",
|
|
21569
|
+
Accept: "application/json, text/event-stream"
|
|
21570
|
+
} : {
|
|
21571
|
+
Accept: "text/event-stream"
|
|
21572
|
+
},
|
|
21573
|
+
...this.protocolVersion ? { "MCP-Protocol-Version": this.protocolVersion } : {},
|
|
21567
21574
|
...this.config.headers
|
|
21568
21575
|
};
|
|
21576
|
+
if (this.sessionId) {
|
|
21577
|
+
headers["Mcp-Session-Id"] = this.sessionId;
|
|
21578
|
+
}
|
|
21569
21579
|
if (this.oauthToken) {
|
|
21570
21580
|
headers["Authorization"] = `Bearer ${this.oauthToken}`;
|
|
21571
21581
|
return headers;
|
|
@@ -21616,7 +21626,7 @@ var init_http = __esm({
|
|
|
21616
21626
|
async sendRequestWithOAuthRetry(method, body, signal) {
|
|
21617
21627
|
const doFetch = async () => fetch(this.config.url, {
|
|
21618
21628
|
method,
|
|
21619
|
-
headers: this.buildHeaders(),
|
|
21629
|
+
headers: this.buildHeaders(method),
|
|
21620
21630
|
...body ? { body } : {},
|
|
21621
21631
|
signal
|
|
21622
21632
|
});
|
|
@@ -21645,6 +21655,53 @@ var init_http = __esm({
|
|
|
21645
21655
|
if (!payload.error) return false;
|
|
21646
21656
|
return this.looksLikeAuthErrorMessage(payload.error.message);
|
|
21647
21657
|
}
|
|
21658
|
+
captureResponseSession(response) {
|
|
21659
|
+
const sessionId = response.headers.get("mcp-session-id");
|
|
21660
|
+
if (sessionId) {
|
|
21661
|
+
this.sessionId = sessionId;
|
|
21662
|
+
}
|
|
21663
|
+
}
|
|
21664
|
+
async parseSseResponse(response) {
|
|
21665
|
+
if (!response.body) {
|
|
21666
|
+
throw new MCPTransportError("SSE response has no body");
|
|
21667
|
+
}
|
|
21668
|
+
const reader = response.body.getReader();
|
|
21669
|
+
const decoder = new TextDecoder();
|
|
21670
|
+
let buffer = "";
|
|
21671
|
+
let eventData = "";
|
|
21672
|
+
const flushEvent = () => {
|
|
21673
|
+
if (!eventData) return;
|
|
21674
|
+
const payload = eventData.trim();
|
|
21675
|
+
eventData = "";
|
|
21676
|
+
if (!payload) return;
|
|
21677
|
+
const parsed = JSON.parse(payload);
|
|
21678
|
+
if (parsed.result && typeof parsed.result === "object" && parsed.result !== null && "protocolVersion" in parsed.result && typeof parsed.result.protocolVersion === "string") {
|
|
21679
|
+
this.protocolVersion = parsed.result.protocolVersion;
|
|
21680
|
+
}
|
|
21681
|
+
this.messageCallback?.(parsed);
|
|
21682
|
+
};
|
|
21683
|
+
while (true) {
|
|
21684
|
+
const { done, value } = await reader.read();
|
|
21685
|
+
if (done) break;
|
|
21686
|
+
buffer += decoder.decode(value, { stream: true });
|
|
21687
|
+
const lines = buffer.split(/\r?\n/);
|
|
21688
|
+
buffer = lines.pop() ?? "";
|
|
21689
|
+
for (const line of lines) {
|
|
21690
|
+
if (line === "") {
|
|
21691
|
+
flushEvent();
|
|
21692
|
+
continue;
|
|
21693
|
+
}
|
|
21694
|
+
if (line.startsWith(":")) continue;
|
|
21695
|
+
if (line.startsWith("data:")) {
|
|
21696
|
+
eventData += (eventData ? "\n" : "") + line.slice(5).trimStart();
|
|
21697
|
+
}
|
|
21698
|
+
}
|
|
21699
|
+
}
|
|
21700
|
+
if (buffer.length > 0 && buffer.startsWith("data:")) {
|
|
21701
|
+
eventData += (eventData ? "\n" : "") + buffer.slice(5).trimStart();
|
|
21702
|
+
}
|
|
21703
|
+
flushEvent();
|
|
21704
|
+
}
|
|
21648
21705
|
/**
|
|
21649
21706
|
* Connect to the HTTP transport
|
|
21650
21707
|
*/
|
|
@@ -21696,10 +21753,22 @@ var init_http = __esm({
|
|
|
21696
21753
|
abortController.signal
|
|
21697
21754
|
);
|
|
21698
21755
|
clearTimeout(timeoutId);
|
|
21756
|
+
this.captureResponseSession(response);
|
|
21699
21757
|
if (!response.ok) {
|
|
21700
21758
|
throw new MCPTransportError(`HTTP error ${response.status}: ${response.statusText}`);
|
|
21701
21759
|
}
|
|
21760
|
+
if (response.status === 202) {
|
|
21761
|
+
return;
|
|
21762
|
+
}
|
|
21763
|
+
const contentType = response.headers.get("content-type")?.toLowerCase() ?? "";
|
|
21764
|
+
if (contentType.includes("text/event-stream")) {
|
|
21765
|
+
await this.parseSseResponse(response);
|
|
21766
|
+
return;
|
|
21767
|
+
}
|
|
21702
21768
|
const data = await response.json();
|
|
21769
|
+
if (data.result && typeof data.result === "object" && data.result !== null && "protocolVersion" in data.result && typeof data.result.protocolVersion === "string") {
|
|
21770
|
+
this.protocolVersion = data.result.protocolVersion;
|
|
21771
|
+
}
|
|
21703
21772
|
if (this.shouldAttemptOAuth() && this.isJsonRpcAuthError(data)) {
|
|
21704
21773
|
await this.ensureOAuthToken(response.headers.get("www-authenticate"), {
|
|
21705
21774
|
forceRefresh: true
|
|
@@ -21709,12 +21778,24 @@ var init_http = __esm({
|
|
|
21709
21778
|
JSON.stringify(message),
|
|
21710
21779
|
abortController.signal
|
|
21711
21780
|
);
|
|
21781
|
+
this.captureResponseSession(retryResponse);
|
|
21712
21782
|
if (!retryResponse.ok) {
|
|
21713
21783
|
throw new MCPTransportError(
|
|
21714
21784
|
`HTTP error ${retryResponse.status}: ${retryResponse.statusText}`
|
|
21715
21785
|
);
|
|
21716
21786
|
}
|
|
21787
|
+
if (retryResponse.status === 202) {
|
|
21788
|
+
return;
|
|
21789
|
+
}
|
|
21790
|
+
const retryContentType = retryResponse.headers.get("content-type")?.toLowerCase() ?? "";
|
|
21791
|
+
if (retryContentType.includes("text/event-stream")) {
|
|
21792
|
+
await this.parseSseResponse(retryResponse);
|
|
21793
|
+
return;
|
|
21794
|
+
}
|
|
21717
21795
|
const retryData = await retryResponse.json();
|
|
21796
|
+
if (retryData.result && typeof retryData.result === "object" && retryData.result !== null && "protocolVersion" in retryData.result && typeof retryData.result.protocolVersion === "string") {
|
|
21797
|
+
this.protocolVersion = retryData.result.protocolVersion;
|
|
21798
|
+
}
|
|
21718
21799
|
this.messageCallback?.(retryData);
|
|
21719
21800
|
return;
|
|
21720
21801
|
}
|
|
@@ -53080,6 +53161,9 @@ function formatGitShort(ctx) {
|
|
|
53080
53161
|
const dirty = ctx.isDirty ? chalk.yellow(" \u25CF") : "";
|
|
53081
53162
|
return chalk.dim("\u{1F33F} ") + branch + dirty;
|
|
53082
53163
|
}
|
|
53164
|
+
|
|
53165
|
+
// src/cli/repl/status-bar.ts
|
|
53166
|
+
init_env();
|
|
53083
53167
|
init_full_access_mode();
|
|
53084
53168
|
function formatContextUsage(percent) {
|
|
53085
53169
|
const label = `ctx ${percent.toFixed(0)}%`;
|
|
@@ -53087,12 +53171,19 @@ function formatContextUsage(percent) {
|
|
|
53087
53171
|
if (percent >= 75) return chalk.yellow(label);
|
|
53088
53172
|
return chalk.dim(label);
|
|
53089
53173
|
}
|
|
53174
|
+
function getDisplayModel(config) {
|
|
53175
|
+
const model = config.provider.model?.trim();
|
|
53176
|
+
if (!model || ["default", "none", "null", "undefined"].includes(model.toLowerCase())) {
|
|
53177
|
+
return getDefaultModel(config.provider.type);
|
|
53178
|
+
}
|
|
53179
|
+
return model;
|
|
53180
|
+
}
|
|
53090
53181
|
function formatStatusBar(projectPath, config, gitCtx, contextUsagePercent) {
|
|
53091
53182
|
const parts = [];
|
|
53092
53183
|
const projectName = path39__default.basename(projectPath);
|
|
53093
53184
|
parts.push(chalk.dim("\u{1F4C1} ") + chalk.magenta(projectName));
|
|
53094
53185
|
const providerName = config.provider.type;
|
|
53095
|
-
const modelName = config
|
|
53186
|
+
const modelName = getDisplayModel(config);
|
|
53096
53187
|
parts.push(chalk.dim(`${providerName}/`) + chalk.cyan(modelName));
|
|
53097
53188
|
if (isQualityLoop()) {
|
|
53098
53189
|
parts.push(chalk.green("\u{1F504} quality loop"));
|
|
@@ -54208,7 +54299,8 @@ async function printWelcome(session, gitCtx, mcpManager) {
|
|
|
54208
54299
|
const parentPath = lastSep > 0 ? displayPath.slice(0, lastSep + 1) : "";
|
|
54209
54300
|
const projectName = lastSep > 0 ? displayPath.slice(lastSep + 1) : displayPath;
|
|
54210
54301
|
const providerName = session.config.provider.type;
|
|
54211
|
-
const
|
|
54302
|
+
const configuredModel = session.config.provider.model?.trim();
|
|
54303
|
+
const modelName = configuredModel && !["default", "none", "null", "undefined"].includes(configuredModel.toLowerCase()) ? configuredModel : getDefaultModel(session.config.provider.type);
|
|
54212
54304
|
const trustText = trustLevel === "full" ? "full" : trustLevel === "write" ? "write" : trustLevel === "read" ? "read" : "";
|
|
54213
54305
|
console.log();
|
|
54214
54306
|
console.log(chalk.dim(` \u{1F4C1} ${parentPath}`) + chalk.magenta.bold(projectName));
|