Changesets · Branches · Tags · Compare
| Changeset | 2b8d1c29d506a9c1fb23b9f08e6181d9ad24a4448ad215fe49b4b5806cc87e9b |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-09-22 14:41 -07:00 |
| Committer | Dallin Romney <dallinromney@gmail.com> · 2025-09-22 14:41 -07:00 |
| Parents | 0c0253914415, 89cedaf513f2 |
21 files changed
modified .github/workflows/main.yaml +17 −17
| @@ -26,8 +26,24 @@ | ||
| 26 | 26 | echo "should_run=false" >> $GITHUB_OUTPUT |
| 27 | 27 | fi |
| 28 | 28 | |
| 29 | + check-version: | |
| 30 | + runs-on: ubuntu-latest | |
| 31 | + steps: | |
| 32 | + - name: Checkout | |
| 33 | + uses: actions/checkout@v5 | |
| 34 | + with: | |
| 35 | + fetch-depth: 0 # This ensures all tags are fetched | |
| 36 | + | |
| 37 | + - name: Checkout tag | |
| 38 | + run: git checkout ${GITHUB_REF#refs/tags/} | |
| 39 | + | |
| 40 | + - name: Make sure version isn't odd | |
| 41 | + run: | | |
| 42 | + cd extensions/vscode | |
| 43 | + node scripts/versionCheck.js | |
| 44 | + | |
| 29 | 45 | build: |
| 30 | - needs: check_release_name | |
| 46 | + needs: [check_release_name, check-version] | |
| 31 | 47 | if: needs.check_release_name.outputs.should_run == 'true' || github.event_name == 'workflow_dispatch' |
| 32 | 48 | runs-on: ${{ matrix.os }} |
| 33 | 49 | strategy: |
| @@ -88,22 +104,6 @@ | ||
| 88 | 104 | name: ${{ matrix.platform }}-${{ matrix.arch }}-vsix |
| 89 | 105 | path: "extensions/vscode/*.vsix" |
| 90 | 106 | |
| 91 | - check-version: | |
| 92 | - runs-on: ubuntu-latest | |
| 93 | - steps: | |
| 94 | - - name: Checkout | |
| 95 | - uses: actions/checkout@v5 | |
| 96 | - with: | |
| 97 | - fetch-depth: 0 # This ensures all tags are fetched | |
| 98 | - | |
| 99 | - - name: Checkout tag | |
| 100 | - run: git checkout ${GITHUB_REF#refs/tags/} | |
| 101 | - | |
| 102 | - - name: Make sure version isn't odd | |
| 103 | - run: | | |
| 104 | - cd extensions/vscode | |
| 105 | - node scripts/versionCheck.js | |
| 106 | - | |
| 107 | 107 | release: |
| 108 | 108 | permissions: |
| 109 | 109 | contents: write |
modified core/context/mcp/MCPOauth.vitest.ts +3 −0
| @@ -240,6 +240,7 @@ | ||
| 240 | 240 | transport: { type: "sse" as const, url: "https://server1.com" }, |
| 241 | 241 | status: "connected" as const, |
| 242 | 242 | errors: [], |
| 243 | + infos: [], | |
| 243 | 244 | isProtectedResource: false, |
| 244 | 245 | prompts: [], |
| 245 | 246 | tools: [], |
| @@ -252,6 +253,7 @@ | ||
| 252 | 253 | transport: { type: "sse" as const, url: "https://server2.com" }, |
| 253 | 254 | status: "connected" as const, |
| 254 | 255 | errors: [], |
| 256 | + infos: [], | |
| 255 | 257 | isProtectedResource: false, |
| 256 | 258 | prompts: [], |
| 257 | 259 | tools: [], |
| @@ -309,6 +311,7 @@ | ||
| 309 | 311 | transport: { type: "sse" as const, url: "" }, |
| 310 | 312 | status: "connected" as const, |
| 311 | 313 | errors: [], |
| 314 | + infos: [], | |
| 312 | 315 | isProtectedResource: false, |
| 313 | 316 | prompts: [], |
| 314 | 317 | tools: [], |
modified core/llm/llms/SambaNova.ts +4 −5
| @@ -9,17 +9,16 @@ | ||
| 9 | 9 | }; |
| 10 | 10 | |
| 11 | 11 | private static MODEL_IDS: { [name: string]: string } = { |
| 12 | - "llama4-scout": "Llama-4-Scout-17B-16E-Instruct", | |
| 13 | 12 | "llama4-maverick": "Llama-4-Maverick-17B-128E-Instruct", |
| 14 | 13 | "llama3.3-70b": "Meta-Llama-3.3-70B-Instruct", |
| 14 | + "llama3.3-swalllow-70b": "Llama-3.3-Swallow-70B-Instruct-v0.4", | |
| 15 | 15 | "llama3.1-8b": "Meta-Llama-3.1-8B-Instruct", |
| 16 | - "llama3.1-405b": "Meta-Llama-3.1-405B-Instruct", | |
| 17 | - "llama3.2-1b": "Meta-Llama-3.2-1B-Instruct", | |
| 18 | - "llama3.2-3b": "Meta-Llama-3.2-3B-Instruct", | |
| 19 | - "qwq-32b": "QwQ-32B", | |
| 20 | 16 | "deepseek-r1-distill-llama-70b": "DeepSeek-R1-Distill-Llama-70B", |
| 21 | 17 | "deepseek-r1": "DeepSeek-R1", |
| 22 | 18 | "deepseek-v3": "DeepSeek-V3-0324", |
| 19 | + "deepseek-v3.1": "DeepSeek-V3-0324", | |
| 20 | + "gpt-oss-120b": "gpt-oss-120b", | |
| 21 | + "qwen3-32b": "Qwen3-32B", | |
| 23 | 22 | }; |
| 24 | 23 | |
| 25 | 24 | protected _convertModelName(model: string) { |
modified core/llm/toolSupport.ts +3 −1
| @@ -203,7 +203,9 @@ | ||
| 203 | 203 | if ( |
| 204 | 204 | model.toLowerCase().startsWith("meta-llama-3") || |
| 205 | 205 | model.toLowerCase().includes("llama-4") || |
| 206 | - model.toLowerCase().includes("deepseek") | |
| 206 | + model.toLowerCase().includes("deepseek") || | |
| 207 | + model.toLowerCase().includes("gpt") || | |
| 208 | + model.toLowerCase().includes("qwen") | |
| 207 | 209 | ) { |
| 208 | 210 | return true; |
| 209 | 211 | } |
modified docs/customize/model-providers/more/SambaNova.mdx +5 −5
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | --- |
| 2 | 2 | title: "SambaNova" |
| 3 | -description: "Configure SambaNova Cloud with Continue to access their high-performance platform for running large AI models, including Llama 4 Scout with world record open source model performance" | |
| 3 | +description: "Configure SambaCloud with Continue to access their high-performance platform for running large AI models, including Llama 4 Scout with world record open source model performance" | |
| 4 | 4 | --- |
| 5 | 5 | |
| 6 | 6 | The SambaNova Cloud is a cloud platform for running large AI models with the world record open source models performance. You can follow the instructions in [this blog post](https://sambanova.ai/blog/accelerating-coding-with-sambanova-cloud?ref=blog.continue.dev) to configure your setup. |
| @@ -9,9 +9,9 @@ | ||
| 9 | 9 | <Tab title="YAML"> |
| 10 | 10 | ```yaml title="config.yaml" |
| 11 | 11 | models: |
| 12 | - - name: SambaNova Llama 4 Scout | |
| 12 | + - name: GPT OSS 120B | |
| 13 | 13 | provider: sambanova |
| 14 | - model: Llama-4-Scout-17B-16E-Instruct | |
| 14 | + model: gpt-oss-120b | |
| 15 | 15 | apiKey: <YOUR_SAMBANOVA_API_KEY> |
| 16 | 16 | ``` |
| 17 | 17 | </Tab> |
| @@ -20,9 +20,9 @@ | ||
| 20 | 20 | { |
| 21 | 21 | "models": [ |
| 22 | 22 | { |
| 23 | - "title": "SambaNova Llama 4 Scout", | |
| 23 | + "title": "GPT OSS 120B", | |
| 24 | 24 | "provider": "sambanova", |
| 25 | - "model": "Llama-4-Scout-17B-16E-Instruct", | |
| 25 | + "model": "gpt-oss-120b", | |
| 26 | 26 | "apiKey": "<YOUR_SAMBANOVA_API_KEY>" |
| 27 | 27 | } |
| 28 | 28 | ] |
modified extensions/cli/package-lock.json +0 −0
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
modified extensions/cli/package.json +0 −2
| @@ -77,7 +77,6 @@ | ||
| 77 | 77 | "@types/jszip": "^3.4.0", |
| 78 | 78 | "@types/nock": "^10.0.3", |
| 79 | 79 | "@types/react": "^19.1.8", |
| 80 | - "@types/readline-sync": "^1.4.8", | |
| 81 | 80 | "@types/shell-quote": "^1.7.5", |
| 82 | 81 | "@types/supertest": "^6.0.3", |
| 83 | 82 | "@types/turndown": "^5.0.5", |
| @@ -122,7 +121,6 @@ | ||
| 122 | 121 | "prettier": "^3.6.2", |
| 123 | 122 | "prettier-plugin-tailwindcss": "^0.6.14", |
| 124 | 123 | "react": "^19.1.0", |
| 125 | - "readline-sync": "^1.4.10", | |
| 126 | 124 | "semantic-release": "^24.2.7", |
| 127 | 125 | "shell-quote": "^1.8.3", |
| 128 | 126 | "supertest": "^7.1.3", |
modified extensions/cli/src/commands/chat.ts +3 −3
| @@ -1,8 +1,7 @@ | ||
| 1 | 1 | import { ModelConfig } from "@continuedev/config-yaml"; |
| 2 | 2 | import chalk from "chalk"; |
| 3 | -import type { ChatHistoryItem, Session } from "core/index.js"; | |
| 3 | +import { ChatHistoryItem, Session } from "core"; | |
| 4 | 4 | import { ChatDescriber } from "core/util/chatDescriber.js"; |
| 5 | -import * as readlineSync from "readline-sync"; | |
| 6 | 5 | |
| 7 | 6 | import { compactChatHistory, findCompactionIndex } from "../compaction.js"; |
| 8 | 7 | import { processCommandFlags } from "../flags/flagProcessor.js"; |
| @@ -25,6 +24,7 @@ | ||
| 25 | 24 | import { gracefulExit } from "../util/exit.js"; |
| 26 | 25 | import { formatAnthropicError, formatError } from "../util/formatError.js"; |
| 27 | 26 | import { logger } from "../util/logger.js"; |
| 27 | +import { question } from "../util/prompt.js"; | |
| 28 | 28 | import { |
| 29 | 29 | calculateContextUsagePercentage, |
| 30 | 30 | countChatHistoryTokens, |
| @@ -454,7 +454,7 @@ | ||
| 454 | 454 | const userInput = |
| 455 | 455 | isFirstMessage && initialUserInput |
| 456 | 456 | ? initialUserInput |
| 457 | - : readlineSync.question(`\n${chalk.bold.green("You:")} `); | |
| 457 | + : await question(`\n${chalk.bold.green("You:")} `); | |
| 458 | 458 | |
| 459 | 459 | isFirstMessage = false; |
| 460 | 460 |
modified extensions/cli/src/freeTrialTransition.ts +10 −11
| @@ -4,14 +4,14 @@ | ||
| 4 | 4 | |
| 5 | 5 | import chalk from "chalk"; |
| 6 | 6 | import open from "open"; |
| 7 | -import * as readlineSync from "readline-sync"; | |
| 8 | 7 | |
| 9 | 8 | import { env } from "./env.js"; |
| 10 | 9 | import { |
| 11 | - isValidAnthropicApiKey, | |
| 12 | 10 | getApiKeyValidationError, |
| 11 | + isValidAnthropicApiKey, | |
| 13 | 12 | } from "./util/apiKeyValidation.js"; |
| 14 | 13 | import { gracefulExit } from "./util/exit.js"; |
| 14 | +import { question, questionWithChoices } from "./util/prompt.js"; | |
| 15 | 15 | import { updateAnthropicModelInYaml } from "./util/yamlConfigUpdater.js"; |
| 16 | 16 | |
| 17 | 17 | const CONFIG_PATH = path.join(env.continueHome, "config.yaml"); |
| @@ -52,10 +52,12 @@ | ||
| 52 | 52 | console.log(chalk.white("1. 💳 Sign up for models add-on")); |
| 53 | 53 | console.log(chalk.white("2. 🔑 Enter your Anthropic API key")); |
| 54 | 54 | |
| 55 | - const choice = readlineSync.question(chalk.yellow("\nEnter choice (1): "), { | |
| 56 | - limit: ["1", "2", ""], | |
| 57 | - limitMessage: chalk.dim("Please enter 1 or 2"), | |
| 58 | - }); | |
| 55 | + const choice = await questionWithChoices( | |
| 56 | + chalk.yellow("\nEnter choice (1): "), | |
| 57 | + ["1", "2", ""], | |
| 58 | + "1", | |
| 59 | + chalk.dim("Please enter 1 or 2"), | |
| 60 | + ); | |
| 59 | 61 | |
| 60 | 62 | if (choice === "1" || choice === "") { |
| 61 | 63 | // Option 1: Open models setup page |
| @@ -81,15 +83,12 @@ | ||
| 81 | 83 | } |
| 82 | 84 | |
| 83 | 85 | // Wait for user to acknowledge |
| 84 | - readlineSync.question(chalk.dim("\nPress Enter to exit...")); | |
| 86 | + await question(chalk.dim("\nPress Enter to exit...")); | |
| 85 | 87 | await gracefulExit(0); |
| 86 | 88 | } else if (choice === "2") { |
| 87 | 89 | // Option 2: Enter Anthropic API key |
| 88 | - const apiKey = readlineSync.question( | |
| 90 | + const apiKey = await question( | |
| 89 | 91 | chalk.white("\nEnter your Anthropic API key: "), |
| 90 | - { | |
| 91 | - hideEchoBack: true, | |
| 92 | - }, | |
| 93 | 92 | ); |
| 94 | 93 | |
| 95 | 94 | if (!isValidAnthropicApiKey(apiKey)) { |
modified extensions/cli/src/onboarding.ts +8 −9
| @@ -5,7 +5,6 @@ | ||
| 5 | 5 | import { BaseLlmApi } from "@continuedev/openai-adapters"; |
| 6 | 6 | import { DefaultApiInterface } from "@continuedev/sdk/dist/api/dist/index.js"; |
| 7 | 7 | import chalk from "chalk"; |
| 8 | -import * as readlineSync from "readline-sync"; | |
| 9 | 8 | |
| 10 | 9 | import { processPromptOrRule } from "./args.js"; |
| 11 | 10 | import { AuthConfig, isAuthenticated, login } from "./auth/workos.js"; |
| @@ -16,6 +15,7 @@ | ||
| 16 | 15 | getApiKeyValidationError, |
| 17 | 16 | isValidAnthropicApiKey, |
| 18 | 17 | } from "./util/apiKeyValidation.js"; |
| 18 | +import { question, questionWithChoices } from "./util/prompt.js"; | |
| 19 | 19 | import { updateAnthropicModelInYaml } from "./util/yamlConfigUpdater.js"; |
| 20 | 20 | |
| 21 | 21 | const CONFIG_PATH = path.join(env.continueHome, "config.yaml"); |
| @@ -97,10 +97,12 @@ | ||
| 97 | 97 | console.log(chalk.white("1. ⏩ Log in with Continue")); |
| 98 | 98 | console.log(chalk.white("2. 🔑 Enter your Anthropic API key")); |
| 99 | 99 | |
| 100 | - const choice = readlineSync.question(chalk.yellow("\nEnter choice (1): "), { | |
| 101 | - limit: ["1", "2", ""], | |
| 102 | - limitMessage: chalk.dim("Please enter 1 or 2"), | |
| 103 | - }); | |
| 100 | + const choice = await questionWithChoices( | |
| 101 | + chalk.yellow("\nEnter choice (1): "), | |
| 102 | + ["1", "2", ""], | |
| 103 | + "1", | |
| 104 | + chalk.dim("Please enter 1 or 2"), | |
| 105 | + ); | |
| 104 | 106 | |
| 105 | 107 | if (choice === "1" || choice === "") { |
| 106 | 108 | const newAuthConfig = await login(); |
| @@ -111,11 +113,8 @@ | ||
| 111 | 113 | const result = await initialize(finalAuthConfig, undefined); |
| 112 | 114 | return { ...result, wasOnboarded: true }; |
| 113 | 115 | } else if (choice === "2") { |
| 114 | - const apiKey = readlineSync.question( | |
| 116 | + const apiKey = await question( | |
| 115 | 117 | chalk.white("\nEnter your Anthropic API key: "), |
| 116 | - { | |
| 117 | - hideEchoBack: true, | |
| 118 | - }, | |
| 119 | 118 | ); |
| 120 | 119 | |
| 121 | 120 | if (!isValidAnthropicApiKey(apiKey)) { |
added extensions/cli/src/util/prompt.test.ts +277 −0
| @@ -0,0 +1,277 @@ | ||
| 1 | +import * as readline from "readline"; | |
| 2 | + | |
| 3 | +import { | |
| 4 | + describe, | |
| 5 | + expect, | |
| 6 | + it, | |
| 7 | + vi, | |
| 8 | + beforeEach, | |
| 9 | + afterEach, | |
| 10 | + MockInstance, | |
| 11 | +} from "vitest"; | |
| 12 | + | |
| 13 | +// Mock readline module | |
| 14 | +vi.mock("readline", () => ({ | |
| 15 | + createInterface: vi.fn(), | |
| 16 | +})); | |
| 17 | + | |
| 18 | +import { question, questionWithChoices } from "./prompt.js"; | |
| 19 | + | |
| 20 | +describe("prompt utilities", () => { | |
| 21 | + let mockInterface: any; | |
| 22 | + let consoleLogSpy: MockInstance<typeof console.log>; | |
| 23 | + let processExitSpy: MockInstance<typeof process.exit>; | |
| 24 | + | |
| 25 | + beforeEach(() => { | |
| 26 | + // Create a mock readline interface | |
| 27 | + mockInterface = { | |
| 28 | + question: vi.fn(), | |
| 29 | + close: vi.fn(), | |
| 30 | + on: vi.fn(), | |
| 31 | + }; | |
| 32 | + | |
| 33 | + // Mock readline.createInterface to return our mock interface | |
| 34 | + (readline.createInterface as any).mockReturnValue(mockInterface); | |
| 35 | + | |
| 36 | + // Mock console.log for limit messages | |
| 37 | + consoleLogSpy = vi.spyOn(console, "log").mockImplementation(() => {}); | |
| 38 | + | |
| 39 | + // Mock process.exit | |
| 40 | + processExitSpy = vi.spyOn(process, "exit").mockImplementation((() => { | |
| 41 | + throw new Error("Process exit"); | |
| 42 | + }) as any); | |
| 43 | + }); | |
| 44 | + | |
| 45 | + afterEach(() => { | |
| 46 | + vi.clearAllMocks(); | |
| 47 | + consoleLogSpy.mockRestore(); | |
| 48 | + processExitSpy.mockRestore(); | |
| 49 | + }); | |
| 50 | + | |
| 51 | + describe("question", () => { | |
| 52 | + it("should return user input", async () => { | |
| 53 | + const promptText = "What is your name? "; | |
| 54 | + const userInput = "John Doe"; | |
| 55 | + | |
| 56 | + // Setup mock to call the callback with user input | |
| 57 | + mockInterface.question.mockImplementation( | |
| 58 | + (prompt: string, callback: (answer: string) => void) => { | |
| 59 | + setTimeout(() => callback(userInput), 0); | |
| 60 | + }, | |
| 61 | + ); | |
| 62 | + | |
| 63 | + const result = await question(promptText); | |
| 64 | + | |
| 65 | + expect(mockInterface.question).toHaveBeenCalledWith( | |
| 66 | + promptText, | |
| 67 | + expect.any(Function), | |
| 68 | + ); | |
| 69 | + expect(mockInterface.close).toHaveBeenCalled(); | |
| 70 | + expect(result).toBe(userInput); | |
| 71 | + }); | |
| 72 | + | |
| 73 | + it("should handle empty input", async () => { | |
| 74 | + const promptText = "Enter something: "; | |
| 75 | + | |
| 76 | + mockInterface.question.mockImplementation( | |
| 77 | + (prompt: string, callback: (answer: string) => void) => { | |
| 78 | + setTimeout(() => callback(""), 0); | |
| 79 | + }, | |
| 80 | + ); | |
| 81 | + | |
| 82 | + const result = await question(promptText); | |
| 83 | + | |
| 84 | + expect(result).toBe(""); | |
| 85 | + }); | |
| 86 | + | |
| 87 | + it("should handle special characters in input", async () => { | |
| 88 | + const promptText = "Enter special chars: "; | |
| 89 | + const userInput = "!@#$%^&*()_+-=[]{}|;':\",./<>?"; | |
| 90 | + | |
| 91 | + mockInterface.question.mockImplementation( | |
| 92 | + (prompt: string, callback: (answer: string) => void) => { | |
| 93 | + setTimeout(() => callback(userInput), 0); | |
| 94 | + }, | |
| 95 | + ); | |
| 96 | + | |
| 97 | + const result = await question(promptText); | |
| 98 | + | |
| 99 | + expect(result).toBe(userInput); | |
| 100 | + }); | |
| 101 | + | |
| 102 | + it.skip("should handle SIGINT (Ctrl+C) by exiting process", async () => { | |
| 103 | + const promptText = "Enter something: "; | |
| 104 | + let sigintHandler: (() => void) | null = null; | |
| 105 | + | |
| 106 | + // Setup mock to capture SIGINT handler | |
| 107 | + mockInterface.on.mockImplementation( | |
| 108 | + (event: string, handler: () => void) => { | |
| 109 | + if (event === "SIGINT") { | |
| 110 | + sigintHandler = handler; | |
| 111 | + } | |
| 112 | + return mockInterface; | |
| 113 | + }, | |
| 114 | + ); | |
| 115 | + | |
| 116 | + // Setup question mock that doesn't resolve immediately | |
| 117 | + mockInterface.question.mockImplementation(() => { | |
| 118 | + // Trigger SIGINT after question is called | |
| 119 | + setTimeout(() => { | |
| 120 | + if (sigintHandler) { | |
| 121 | + sigintHandler(); | |
| 122 | + } | |
| 123 | + }, 10); | |
| 124 | + }); | |
| 125 | + | |
| 126 | + // The promise should reject when SIGINT is triggered | |
| 127 | + await expect(question(promptText)).rejects.toThrow("Process exit"); | |
| 128 | + expect(processExitSpy).toHaveBeenCalledWith(0); | |
| 129 | + }); | |
| 130 | + }); | |
| 131 | + | |
| 132 | + describe("questionWithChoices", () => { | |
| 133 | + it("should accept valid choice", async () => { | |
| 134 | + const promptText = "Choose (1): "; | |
| 135 | + const choices = ["1", "2", "3"]; | |
| 136 | + const userChoice = "2"; | |
| 137 | + | |
| 138 | + mockInterface.question.mockImplementationOnce( | |
| 139 | + (prompt: string, callback: (answer: string) => void) => { | |
| 140 | + setTimeout(() => callback(userChoice), 0); | |
| 141 | + }, | |
| 142 | + ); | |
| 143 | + | |
| 144 | + const result = await questionWithChoices(promptText, choices); | |
| 145 | + expect(result).toBe(userChoice); | |
| 146 | + }); | |
| 147 | + | |
| 148 | + it("should use default choice when empty input is provided", async () => { | |
| 149 | + const promptText = "Choose (1): "; | |
| 150 | + const choices = ["1", "2", "3"]; | |
| 151 | + const defaultChoice = "1"; | |
| 152 | + | |
| 153 | + mockInterface.question.mockImplementationOnce( | |
| 154 | + (prompt: string, callback: (answer: string) => void) => { | |
| 155 | + setTimeout(() => callback(""), 0); | |
| 156 | + }, | |
| 157 | + ); | |
| 158 | + | |
| 159 | + const result = await questionWithChoices( | |
| 160 | + promptText, | |
| 161 | + choices, | |
| 162 | + defaultChoice, | |
| 163 | + ); | |
| 164 | + expect(result).toBe(defaultChoice); | |
| 165 | + }); | |
| 166 | + | |
| 167 | + it("should reject invalid choice and ask again", async () => { | |
| 168 | + const promptText = "Choose (1 or 2): "; | |
| 169 | + const choices = ["1", "2"]; | |
| 170 | + const limitMessage = "Please enter 1 or 2"; | |
| 171 | + | |
| 172 | + let callCount = 0; | |
| 173 | + mockInterface.question.mockImplementation( | |
| 174 | + (prompt: string, callback: (answer: string) => void) => { | |
| 175 | + setTimeout(() => { | |
| 176 | + if (callCount === 0) { | |
| 177 | + callCount++; | |
| 178 | + callback("3"); // Invalid choice | |
| 179 | + } else { | |
| 180 | + callback("1"); // Valid choice | |
| 181 | + } | |
| 182 | + }, 0); | |
| 183 | + }, | |
| 184 | + ); | |
| 185 | + | |
| 186 | + const result = await questionWithChoices( | |
| 187 | + promptText, | |
| 188 | + choices, | |
| 189 | + undefined, | |
| 190 | + limitMessage, | |
| 191 | + ); | |
| 192 | + expect(result).toBe("1"); | |
| 193 | + expect(consoleLogSpy).toHaveBeenCalledWith(limitMessage); | |
| 194 | + }); | |
| 195 | + | |
| 196 | + it("should handle multiple invalid attempts before valid choice", async () => { | |
| 197 | + const promptText = "Choose: "; | |
| 198 | + const choices = ["yes", "no"]; | |
| 199 | + const limitMessage = "Invalid choice"; | |
| 200 | + | |
| 201 | + let callCount = 0; | |
| 202 | + const invalidAnswers = ["maybe", "perhaps"]; | |
| 203 | + mockInterface.question.mockImplementation( | |
| 204 | + (prompt: string, callback: (answer: string) => void) => { | |
| 205 | + setTimeout(() => { | |
| 206 | + if (callCount < invalidAnswers.length) { | |
| 207 | + callback(invalidAnswers[callCount++]); | |
| 208 | + } else { | |
| 209 | + callback("yes"); | |
| 210 | + } | |
| 211 | + }, 0); | |
| 212 | + }, | |
| 213 | + ); | |
| 214 | + | |
| 215 | + const result = await questionWithChoices( | |
| 216 | + promptText, | |
| 217 | + choices, | |
| 218 | + undefined, | |
| 219 | + limitMessage, | |
| 220 | + ); | |
| 221 | + expect(result).toBe("yes"); | |
| 222 | + expect(consoleLogSpy).toHaveBeenCalledTimes(2); | |
| 223 | + }); | |
| 224 | + | |
| 225 | + it("should not show limit message when none provided", async () => { | |
| 226 | + const promptText = "Choose: "; | |
| 227 | + const choices = ["a", "b"]; | |
| 228 | + | |
| 229 | + let callCount = 0; | |
| 230 | + mockInterface.question.mockImplementation( | |
| 231 | + (prompt: string, callback: (answer: string) => void) => { | |
| 232 | + setTimeout(() => { | |
| 233 | + if (callCount === 0) { | |
| 234 | + callCount++; | |
| 235 | + callback("c"); // Invalid | |
| 236 | + } else { | |
| 237 | + callback("a"); // Valid | |
| 238 | + } | |
| 239 | + }, 0); | |
| 240 | + }, | |
| 241 | + ); | |
| 242 | + | |
| 243 | + const result = await questionWithChoices(promptText, choices); | |
| 244 | + expect(result).toBe("a"); | |
| 245 | + expect(consoleLogSpy).not.toHaveBeenCalled(); | |
| 246 | + }); | |
| 247 | + | |
| 248 | + it("should handle empty string as valid choice", async () => { | |
| 249 | + const promptText = "Press Enter to continue or type 'cancel': "; | |
| 250 | + const choices = ["", "cancel"]; | |
| 251 | + | |
| 252 | + mockInterface.question.mockImplementationOnce( | |
| 253 | + (prompt: string, callback: (answer: string) => void) => { | |
| 254 | + setTimeout(() => callback(""), 0); | |
| 255 | + }, | |
| 256 | + ); | |
| 257 | + | |
| 258 | + const result = await questionWithChoices(promptText, choices); | |
| 259 | + expect(result).toBe(""); | |
| 260 | + }); | |
| 261 | + | |
| 262 | + it("should handle choice with spaces", async () => { | |
| 263 | + const promptText = "Choose an option: "; | |
| 264 | + const choices = ["option one", "option two", "option three"]; | |
| 265 | + const userChoice = "option two"; | |
| 266 | + | |
| 267 | + mockInterface.question.mockImplementationOnce( | |
| 268 | + (prompt: string, callback: (answer: string) => void) => { | |
| 269 | + setTimeout(() => callback(userChoice), 0); | |
| 270 | + }, | |
| 271 | + ); | |
| 272 | + | |
| 273 | + const result = await questionWithChoices(promptText, choices); | |
| 274 | + expect(result).toBe(userChoice); | |
| 275 | + }); | |
| 276 | + }); | |
| 277 | +}); |
added extensions/cli/src/util/prompt.ts +60 −0
| @@ -0,0 +1,60 @@ | ||
| 1 | +import * as readline from "readline"; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Creates a promise-based question prompt using readline | |
| 5 | + * Properly handles backspace and Ctrl+C | |
| 6 | + */ | |
| 7 | +export function question(prompt: string): Promise<string> { | |
| 8 | + return new Promise((resolve) => { | |
| 9 | + const rl = readline.createInterface({ | |
| 10 | + input: process.stdin, | |
| 11 | + output: process.stdout, | |
| 12 | + terminal: true, | |
| 13 | + }); | |
| 14 | + | |
| 15 | + // Handle Ctrl+C properly | |
| 16 | + rl.on("SIGINT", () => { | |
| 17 | + console.log("\n"); | |
| 18 | + rl.close(); | |
| 19 | + process.exit(0); | |
| 20 | + }); | |
| 21 | + | |
| 22 | + rl.question(prompt, (answer) => { | |
| 23 | + rl.close(); | |
| 24 | + resolve(answer); | |
| 25 | + }); | |
| 26 | + }); | |
| 27 | +} | |
| 28 | + | |
| 29 | +/** | |
| 30 | + * Creates a prompt with limited choices | |
| 31 | + * @param prompt The prompt to display | |
| 32 | + * @param choices Array of valid choices | |
| 33 | + * @param defaultChoice Default choice if user presses enter | |
| 34 | + * @param limitMessage Message to show when invalid choice is entered | |
| 35 | + */ | |
| 36 | +export async function questionWithChoices( | |
| 37 | + prompt: string, | |
| 38 | + choices: string[], | |
| 39 | + defaultChoice?: string, | |
| 40 | + limitMessage?: string, | |
| 41 | +): Promise<string> { | |
| 42 | + while (true) { | |
| 43 | + const answer = await question(prompt); | |
| 44 | + | |
| 45 | + // Handle default choice | |
| 46 | + if (answer === "" && defaultChoice !== undefined) { | |
| 47 | + return defaultChoice; | |
| 48 | + } | |
| 49 | + | |
| 50 | + // Check if answer is valid | |
| 51 | + if (choices.includes(answer)) { | |
| 52 | + return answer; | |
| 53 | + } | |
| 54 | + | |
| 55 | + // Show limit message if provided | |
| 56 | + if (limitMessage) { | |
| 57 | + console.log(limitMessage); | |
| 58 | + } | |
| 59 | + } | |
| 60 | +} |
modified extensions/vscode/package.json +1 −1
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | "name": "continue", |
| 3 | 3 | "icon": "media/icon.png", |
| 4 | 4 | "author": "Continue Dev, Inc", |
| 5 | - "version": "1.3.11", | |
| 5 | + "version": "1.3.12", | |
| 6 | 6 | "repository": { |
| 7 | 7 | "type": "git", |
| 8 | 8 | "url": "https://github.com/continuedev/continue" |
modified gui/src/pages/AddNewModel/configs/models.ts +50 −66
| @@ -592,7 +592,7 @@ | ||
| 592 | 592 | contextLength: 8192, |
| 593 | 593 | }, |
| 594 | 594 | icon: "meta.png", |
| 595 | - providerOptions: ["ollama", "groq", "llama.cpp", "sambanova", "nebius"], | |
| 595 | + providerOptions: ["ollama", "groq", "llama.cpp", "nebius"], | |
| 596 | 596 | isOpenSource: false, |
| 597 | 597 | }, |
| 598 | 598 | llama323bChat: { |
| @@ -605,7 +605,7 @@ | ||
| 605 | 605 | contextLength: 8192, |
| 606 | 606 | }, |
| 607 | 607 | icon: "meta.png", |
| 608 | - providerOptions: ["ollama", "groq", "llama.cpp", "sambanova", "together"], | |
| 608 | + providerOptions: ["ollama", "groq", "llama.cpp", "together"], | |
| 609 | 609 | isOpenSource: false, |
| 610 | 610 | }, |
| 611 | 611 | llama3211bChat: { |
| @@ -1705,25 +1705,13 @@ | ||
| 1705 | 1705 | providerOptions: ["siliconflow"], |
| 1706 | 1706 | isOpenSource: true, |
| 1707 | 1707 | }, |
| 1708 | - llama4Scout: { | |
| 1709 | - title: "Llama 4 Scout Instruct", | |
| 1710 | - description: "A model from Meta, fine-tuned for chat", | |
| 1711 | - params: { | |
| 1712 | - title: "Llama 4 Scout Instruct", | |
| 1713 | - model: "Llama-4-Scout-17B-16E-Instruct", | |
| 1714 | - contextLength: 16_000, | |
| 1715 | - }, | |
| 1716 | - icon: "meta.png", | |
| 1717 | - providerOptions: ["sambanova"], | |
| 1718 | - isOpenSource: true, | |
| 1719 | - }, | |
| 1720 | 1708 | llama4Maverick: { |
| 1721 | 1709 | title: "Llama 4 Maverick Instruct", |
| 1722 | 1710 | description: "A model from Meta, fine-tuned for chat", |
| 1723 | 1711 | params: { |
| 1724 | 1712 | title: "Llama 4 Maverick Instruct", |
| 1725 | 1713 | model: "Llama-4-Maverick-17B-128E-Instruct", |
| 1726 | - contextLength: 16_000, | |
| 1714 | + contextLength: 128_000, | |
| 1727 | 1715 | }, |
| 1728 | 1716 | icon: "meta.png", |
| 1729 | 1717 | providerOptions: ["sambanova"], |
| @@ -1741,71 +1729,31 @@ | ||
| 1741 | 1729 | providerOptions: ["sambanova"], |
| 1742 | 1730 | isOpenSource: true, |
| 1743 | 1731 | }, |
| 1744 | - llama318BInstruct: { | |
| 1745 | - title: "Llama3.1 8B", | |
| 1746 | - description: "A model from Meta, fine-tuned for chat", | |
| 1747 | - refUrl: "", | |
| 1748 | - params: { | |
| 1749 | - title: "Llama 3.1 8B Instruct", | |
| 1750 | - model: "Meta-Llama-3.1-8B-Instruct", | |
| 1751 | - contextLength: 16_000, | |
| 1752 | - }, | |
| 1753 | - icon: "meta.png", | |
| 1754 | - providerOptions: ["sambanova"], | |
| 1755 | - isOpenSource: true, | |
| 1756 | - }, | |
| 1757 | - llama31405BInstruct: { | |
| 1758 | - title: "Llama3.1 405B", | |
| 1759 | - description: "A model from Meta, fine-tuned for chat", | |
| 1760 | - refUrl: "", | |
| 1732 | + llama33Swallow70BInstruct: { | |
| 1733 | + title: "Llama 3.3 Swallow 70B Instruct", | |
| 1734 | + description: "A model from TokyoTech, fine-tuned for chat", | |
| 1761 | 1735 | params: { |
| 1762 | - title: "Llama 3.1 405B Instruct", | |
| 1763 | - model: "Meta-Llama-3.1-405B-Instruct", | |
| 1764 | - contextLength: 16_000, | |
| 1736 | + title: "Llama 3.3 70B instruct", | |
| 1737 | + model: "Llama-3.3-Swallow-70B-Instruct-v0.4", | |
| 1738 | + contextLength: 128_000, | |
| 1765 | 1739 | }, |
| 1766 | 1740 | icon: "meta.png", |
| 1767 | 1741 | providerOptions: ["sambanova"], |
| 1768 | 1742 | isOpenSource: true, |
| 1769 | 1743 | }, |
| 1770 | - llama321BInstruct: { | |
| 1771 | - title: "Llama3.2 1B", | |
| 1744 | + llama318BInstruct: { | |
| 1745 | + title: "Llama3.1 8B", | |
| 1772 | 1746 | description: "A model from Meta, fine-tuned for chat", |
| 1773 | 1747 | refUrl: "", |
| 1774 | 1748 | params: { |
| 1775 | - title: "Llama 3.2 1B Instruct", | |
| 1776 | - model: "Meta-Llama-3.2-1B-Instruct", | |
| 1749 | + title: "Llama 3.1 8B Instruct", | |
| 1750 | + model: "Meta-Llama-3.1-8B-Instruct", | |
| 1777 | 1751 | contextLength: 16_000, |
| 1778 | 1752 | }, |
| 1779 | 1753 | icon: "meta.png", |
| 1780 | 1754 | providerOptions: ["sambanova"], |
| 1781 | 1755 | isOpenSource: true, |
| 1782 | 1756 | }, |
| 1783 | - llama323BInstruct: { | |
| 1784 | - title: "Llama3.2 3B", | |
| 1785 | - description: "A model from Meta, fine-tuned for chat", | |
| 1786 | - refUrl: "", | |
| 1787 | - params: { | |
| 1788 | - title: "Llama 3.2 3B Instruct", | |
| 1789 | - model: "Meta-Llama-3.2-3B-Instruct", | |
| 1790 | - contextLength: 8192, | |
| 1791 | - }, | |
| 1792 | - icon: "meta.png", | |
| 1793 | - providerOptions: ["sambanova"], | |
| 1794 | - isOpenSource: true, | |
| 1795 | - }, | |
| 1796 | - qwq32B: { | |
| 1797 | - title: "QwQ 32B", | |
| 1798 | - description: | |
| 1799 | - "QwQ-32B is Qwen's latest experimental research model, focusing on improving AI reasoning capabilities.", | |
| 1800 | - params: { | |
| 1801 | - title: "QwQ 32B", | |
| 1802 | - model: "QwQ-32B", | |
| 1803 | - contextLength: 16_000, | |
| 1804 | - }, | |
| 1805 | - icon: "qwen.png", | |
| 1806 | - providerOptions: ["sambanova"], | |
| 1807 | - isOpenSource: true, | |
| 1808 | - }, | |
| 1809 | 1757 | deepseekR1DistillLlama70B: { |
| 1810 | 1758 | title: "DeepSeek R1 Distill Llama 70B", |
| 1811 | 1759 | description: "A llama 3.1 70 model distilled from deekseek R1", |
| @@ -1824,7 +1772,7 @@ | ||
| 1824 | 1772 | params: { |
| 1825 | 1773 | title: "DeepSeek R1", |
| 1826 | 1774 | model: "DeepSeek-R1", |
| 1827 | - contextLength: 8192, | |
| 1775 | + contextLength: 32_000, | |
| 1828 | 1776 | }, |
| 1829 | 1777 | icon: "deepseek.png", |
| 1830 | 1778 | providerOptions: ["sambanova"], |
| @@ -1842,6 +1790,42 @@ | ||
| 1842 | 1790 | providerOptions: ["sambanova"], |
| 1843 | 1791 | isOpenSource: true, |
| 1844 | 1792 | }, |
| 1793 | + deepseekV31: { | |
| 1794 | + title: "DeepSeek V3.1", | |
| 1795 | + description: "DeekSeek V3.1 reasoning model from DeepSeek", | |
| 1796 | + params: { | |
| 1797 | + title: "DeepSeek V3.1", | |
| 1798 | + model: "DeepSeek-V3.1", | |
| 1799 | + contextLength: 32_000, | |
| 1800 | + }, | |
| 1801 | + icon: "deepseek.png", | |
| 1802 | + providerOptions: ["sambanova"], | |
| 1803 | + isOpenSource: true, | |
| 1804 | + }, | |
| 1805 | + qwen332B: { | |
| 1806 | + title: "Qwen 3 32B", | |
| 1807 | + description: "Qwen 3 32B model from Alibaba", | |
| 1808 | + params: { | |
| 1809 | + title: "Qwen 3 32B", | |
| 1810 | + model: "Qwen3-32B", | |
| 1811 | + contextLength: 8192, | |
| 1812 | + }, | |
| 1813 | + icon: "qwen.png", | |
| 1814 | + providerOptions: ["sambanova"], | |
| 1815 | + isOpenSource: true, | |
| 1816 | + }, | |
| 1817 | + gptOss120b: { | |
| 1818 | + title: "GPT OSS 120B", | |
| 1819 | + description: "GPT oss 120b reasoning model from OpenAI", | |
| 1820 | + params: { | |
| 1821 | + title: "GPT OSS 120B", | |
| 1822 | + model: "gpt-oss-120b", | |
| 1823 | + contextLength: 128_000, | |
| 1824 | + }, | |
| 1825 | + icon: "openai.png", | |
| 1826 | + providerOptions: ["sambanova"], | |
| 1827 | + isOpenSource: true, | |
| 1828 | + }, | |
| 1845 | 1829 | AUTODETECT: { |
| 1846 | 1830 | title: "Autodetect", |
| 1847 | 1831 | description: |
modified gui/src/pages/AddNewModel/configs/providers.ts +4 −5
| @@ -809,17 +809,16 @@ | ||
| 809 | 809 | ...completionParamsInputsConfigs, |
| 810 | 810 | ], |
| 811 | 811 | packages: [ |
| 812 | - models.llama4Scout, | |
| 813 | 812 | models.llama4Maverick, |
| 814 | 813 | models.llama3370BInstruct, |
| 814 | + models.llama33Swallow70BInstruct, | |
| 815 | 815 | models.llama318BInstruct, |
| 816 | - models.llama31405BInstruct, | |
| 817 | - models.llama321BInstruct, | |
| 818 | - models.llama323BInstruct, | |
| 819 | - models.qwq32B, | |
| 820 | 816 | models.deepseekR1DistillLlama70B, |
| 821 | 817 | models.deepseekR1, |
| 822 | 818 | models.deepseekV3, |
| 819 | + models.deepseekV31, | |
| 820 | + models.qwen332B, | |
| 821 | + models.gptOss120b, | |
| 823 | 822 | ], |
| 824 | 823 | apiKeyUrl: "https://cloud.sambanova.ai/apis", |
| 825 | 824 | }, |
modified gui/src/redux/selectors/selectToolCalls.ts +3 −1
| @@ -50,7 +50,9 @@ | ||
| 50 | 50 | (_store: RootState, toolCallId: string) => toolCallId, |
| 51 | 51 | ], |
| 52 | 52 | (applyStates, toolCallId) => { |
| 53 | - return applyStates.states.find((state) => state.toolCallId === toolCallId); | |
| 53 | + return applyStates.states.findLast( | |
| 54 | + (state) => state.toolCallId === toolCallId, | |
| 55 | + ); | |
| 54 | 56 | }, |
| 55 | 57 | ); |
| 56 | 58 |
modified gui/src/redux/thunks/streamResponseAfterToolCall.ts +1 −1
| @@ -69,7 +69,7 @@ | ||
| 69 | 69 | |
| 70 | 70 | // Check if we should continue streaming based on tool call completion |
| 71 | 71 | const history = getState().session.history; |
| 72 | - const assistantMessage = history.find( | |
| 72 | + const assistantMessage = history.findLast( | |
| 73 | 73 | (item) => |
| 74 | 74 | item.message.role === "assistant" && |
| 75 | 75 | item.toolCallStates?.some((tc) => tc.toolCallId === toolCallId), |
modified gui/src/redux/util/index.ts +3 −2
| @@ -66,7 +66,8 @@ | ||
| 66 | 66 | chatHistory: RootState["session"]["history"], |
| 67 | 67 | toolCallId: string, |
| 68 | 68 | ): ToolCallState | undefined { |
| 69 | - for (const item of chatHistory) { | |
| 69 | + for (let i = chatHistory.length - 1; i >= 0; i--) { | |
| 70 | + const item = chatHistory[i]; | |
| 70 | 71 | if (item.toolCallStates) { |
| 71 | 72 | const toolCallState = item.toolCallStates.find( |
| 72 | 73 | (state) => state.toolCallId === toolCallId, |
| @@ -84,7 +85,7 @@ | ||
| 84 | 85 | chatHistory: RootState["session"]["history"], |
| 85 | 86 | toolCallId: string, |
| 86 | 87 | ): ChatHistoryItemWithMessageId | undefined { |
| 87 | - return chatHistory.find( | |
| 88 | + return chatHistory.findLast( | |
| 88 | 89 | (item) => |
| 89 | 90 | item.message.role === "tool" && item.message.toolCallId === toolCallId, |
| 90 | 91 | ); |
modified packages/openai-adapters/src/index.ts +5 −0
| @@ -18,6 +18,7 @@ | ||
| 18 | 18 | import { WatsonXApi } from "./apis/WatsonX.js"; |
| 19 | 19 | import { BaseLlmApi } from "./apis/base.js"; |
| 20 | 20 | import { LLMConfig, OpenAIConfigSchema } from "./types.js"; |
| 21 | +import { appendPathToUrlIfNotPresent } from "./util/appendPathToUrl.js"; | |
| 21 | 22 | |
| 22 | 23 | dotenv.config(); |
| 23 | 24 | |
| @@ -141,6 +142,10 @@ | ||
| 141 | 142 | case "lmstudio": |
| 142 | 143 | return openAICompatible("http://localhost:1234/", config); |
| 143 | 144 | case "ollama": |
| 145 | + // for openai compaitability, we need to add /v1 to the end of the url | |
| 146 | + // this is required for cli (for core, endpoints are overriden by core/llm/llms/Ollama.ts) | |
| 147 | + if (config.apiBase) | |
| 148 | + config.apiBase = appendPathToUrlIfNotPresent(config.apiBase, "v1"); | |
| 144 | 149 | return openAICompatible("http://localhost:11434/v1/", config); |
| 145 | 150 | case "mock": |
| 146 | 151 | return new MockApi(); |
modified packages/openai-adapters/src/test/main.test.ts +48 −0
| @@ -311,4 +311,52 @@ | ||
| 311 | 311 | ); |
| 312 | 312 | expect((azure as OpenAIApi).openai.apiKey).toBe("sk-xxx"); |
| 313 | 313 | }); |
| 314 | + | |
| 315 | + describe("ollama api base", () => { | |
| 316 | + it('should have correct default API base for "ollama"', () => { | |
| 317 | + const ollama = constructLlmApi({ | |
| 318 | + provider: "ollama", | |
| 319 | + }); | |
| 320 | + | |
| 321 | + expect((ollama as OpenAIApi).openai.baseURL).toBe( | |
| 322 | + "http://localhost:11434/v1/", | |
| 323 | + ); | |
| 324 | + }); | |
| 325 | + it('should append /v1 to apiBase for "ollama"', () => { | |
| 326 | + const ollama = constructLlmApi({ | |
| 327 | + provider: "ollama", | |
| 328 | + apiBase: "http://localhost:123", | |
| 329 | + }); | |
| 330 | + | |
| 331 | + expect((ollama as OpenAIApi).openai.baseURL).toBe( | |
| 332 | + "http://localhost:123/v1/", | |
| 333 | + ); | |
| 334 | + }); | |
| 335 | + it("should not reappend /v1 to apibase for ollama if it is already present", () => { | |
| 336 | + const ollama = constructLlmApi({ | |
| 337 | + provider: "ollama", | |
| 338 | + apiBase: "http://localhost:123/v1/", | |
| 339 | + }); | |
| 340 | + | |
| 341 | + expect((ollama as OpenAIApi).openai.baseURL).toBe( | |
| 342 | + "http://localhost:123/v1/", | |
| 343 | + ); | |
| 344 | + }); | |
| 345 | + it("should append v1 if apiBase is like myhostv1/", () => { | |
| 346 | + const ollama = constructLlmApi({ | |
| 347 | + provider: "ollama", | |
| 348 | + apiBase: "https://myhostv1/", | |
| 349 | + }); | |
| 350 | + expect((ollama as OpenAIApi).openai.baseURL).toBe("https://myhostv1/v1/"); | |
| 351 | + }); | |
| 352 | + it("should preserve query params and append v1 in apibase", () => { | |
| 353 | + const ollama = constructLlmApi({ | |
| 354 | + provider: "ollama", | |
| 355 | + apiBase: "https://test.com:123/ollama-server?x=1", | |
| 356 | + }); | |
| 357 | + expect((ollama as OpenAIApi).openai.baseURL).toBe( | |
| 358 | + "https://test.com:123/ollama-server/v1/?x=1", | |
| 359 | + ); | |
| 360 | + }); | |
| 361 | + }); | |
| 314 | 362 | }); |
added packages/openai-adapters/src/util/appendPathToUrl.ts +17 −0
| @@ -0,0 +1,17 @@ | ||
| 1 | +export function appendPathToUrlIfNotPresent( | |
| 2 | + urlString: string, | |
| 3 | + pathWithoutSlash: string, | |
| 4 | +) { | |
| 5 | + const url = new URL(urlString); | |
| 6 | + if (!url.pathname.endsWith("/")) { | |
| 7 | + url.pathname += "/"; | |
| 8 | + } | |
| 9 | + if (!url.pathname.endsWith(pathWithoutSlash + "/")) { | |
| 10 | + url.pathname += pathWithoutSlash + "/"; | |
| 11 | + } | |
| 12 | + if (url.search) { | |
| 13 | + return url.toString(); | |
| 14 | + } | |
| 15 | + // append slash at the end | |
| 16 | + return url.toString(); | |
| 17 | +} |