Skip to content

Watsonx-vi #5889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ Icon?

*.notes.md
notes.md
*.notes.md

manual-testing-sandbox/.idea/**
manual-testing-sandbox/.continue/**
Expand Down
64 changes: 8 additions & 56 deletions core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@continuedev/config-yaml": "file:../packages/config-yaml",
"@continuedev/fetch": "^1.0.10",
"@continuedev/llm-info": "^1.0.8",
"@continuedev/openai-adapters": "^1.0.25",
"@continuedev/openai-adapters": "^1.0.32",
"@modelcontextprotocol/sdk": "^1.12.0",
"@mozilla/readability": "^0.5.0",
"@octokit/rest": "^20.1.1",
Expand Down
6 changes: 3 additions & 3 deletions extensions/vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/fetch/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/fetch/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@continuedev/fetch",
"version": "1.0.10",
"version": "1.0.11",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
91 changes: 89 additions & 2 deletions packages/fetch/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,81 @@ import { RequestOptions } from "@continuedev/config-types";
import * as followRedirects from "follow-redirects";
import { HttpProxyAgent } from "http-proxy-agent";
import { HttpsProxyAgent } from "https-proxy-agent";
import fetch, { RequestInit, Response } from "node-fetch";
import fetch, { BodyInit, RequestInit, Response } from "node-fetch";
import { getAgentOptions } from "./getAgentOptions.js";
import { getProxyFromEnv, shouldBypassProxy } from "./util.js";

const { http, https } = (followRedirects as any).default;

function logRequest(
method: string,
url: URL,
headers: { [key: string]: string },
body: BodyInit | null | undefined,
proxy?: string,
shouldBypass?: boolean,
) {
console.log("=== FETCH REQUEST ===");
console.log(`Method: ${method}`);
console.log(`URL: ${url.toString()}`);

// Log headers in curl format
console.log("Headers:");
for (const [key, value] of Object.entries(headers)) {
console.log(` -H '${key}: ${value}'`);
}

// Log proxy information
if (proxy && !shouldBypass) {
console.log(`Proxy: ${proxy}`);
}

// Log body
if (body) {
console.log(`Body: ${body}`);
}

// Generate equivalent curl command
let curlCommand = `curl -X ${method}`;
for (const [key, value] of Object.entries(headers)) {
curlCommand += ` -H '${key}: ${value}'`;
}
if (body) {
curlCommand += ` -d '${body}'`;
}
if (proxy && !shouldBypass) {
curlCommand += ` --proxy '${proxy}'`;
}
curlCommand += ` '${url.toString()}'`;
console.log(`Equivalent curl: ${curlCommand}`);
console.log("=====================");
}

async function logResponse(resp: Response) {
console.log("=== FETCH RESPONSE ===");
console.log(`Status: ${resp.status} ${resp.statusText}`);
console.log("Response Headers:");
resp.headers.forEach((value, key) => {
console.log(` ${key}: ${value}`);
});

// Clone response to read body without consuming it
const respClone = resp.clone();
try {
const responseText = await respClone.text();
console.log(`Response Body: ${responseText}`);
} catch (e) {
console.log("Could not read response body:", e);
}
console.log("======================");
}

function logError(error: unknown) {
console.log("=== FETCH ERROR ===");
console.log(`Error: ${error}`);
console.log("===================");
}

export async function fetchwithRequestOptions(
url_: URL | string,
init?: RequestInit,
Expand Down Expand Up @@ -68,15 +137,28 @@ export async function fetchwithRequestOptions(
console.log("Unable to parse HTTP request body: ", e);
}

const finalBody = updatedBody ?? init?.body;
const method = init?.method || "GET";

// Verbose logging for debugging - log request details
if (process.env.VERBOSE_FETCH) {
logRequest(method, url, headers, finalBody, proxy, shouldBypass);
}

// fetch the request with the provided options
try {
const resp = await fetch(url, {
...init,
body: updatedBody ?? init?.body,
body: finalBody,
headers: headers,
agent: agent,
});

// Verbose logging for debugging - log response details
if (process.env.VERBOSE_FETCH) {
await logResponse(resp);
}

if (!resp.ok) {
const requestId = resp.headers.get("x-request-id");
if (requestId) {
Expand All @@ -86,6 +168,11 @@ export async function fetchwithRequestOptions(

return resp;
} catch (error) {
// Verbose logging for errors
if (process.env.VERBOSE_FETCH) {
logError(error);
}

if (error instanceof Error && error.name === "AbortError") {
// Return a Response object that streamResponse etc can handle
return new Response(null, {
Expand Down
Loading