diff --git a/package.json b/package.json index f6bbeb0f..b39f5467 100644 --- a/package.json +++ b/package.json @@ -369,7 +369,7 @@ }, "twinny.ollamaApiPort": { "order": 15, - "type": "number", + "type": ["number", "null"], "default": 11434, "markdownDescription": "Sets the port number for the Ollama API. The default is `11434`, but you can change it if your Ollama instance uses a different port.", "required": false diff --git a/src/common/types.ts b/src/common/types.ts index 338ade9f..d1ece7c8 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -160,7 +160,7 @@ export type Bracket = (typeof ALL_BRACKETS)[number] export interface StreamRequestOptions { hostname: string path: string - port: string | number + port?: string | number protocol: string method: string headers: Record diff --git a/src/extension/api.ts b/src/extension/api.ts index 9bf4627b..108dcf08 100644 --- a/src/extension/api.ts +++ b/src/extension/api.ts @@ -9,7 +9,7 @@ export async function streamResponse(request: StreamRequest) { const { signal } = controller try { - const url = `${options.protocol}://${options.hostname}:${options.port}${options.path}` + const url = `${options.protocol}://${options.hostname}${options.port ? `:${options.port}` : ""}${options.path}` const fetchOptions = { method: options.method, headers: options.headers, @@ -94,7 +94,7 @@ export async function fetchEmbedding(request: StreamRequest) { try { - const url = `${options.protocol}://${options.hostname}:${options.port}${options.path}` + const url = `${options.protocol}://${options.hostname}${options.port ? `:${options.port}` : ""}${options.path}` const fetchOptions = { method: options.method, headers: options.headers, diff --git a/src/extension/chat-service.ts b/src/extension/chat-service.ts index a05ab950..d45b667a 100644 --- a/src/extension/chat-service.ts +++ b/src/extension/chat-service.ts @@ -312,7 +312,7 @@ export class ChatService { const requestOptions: StreamRequestOptions = { hostname: provider.apiHostname, - port: Number(provider.apiPort), + port: provider.apiPort ? Number(provider.apiPort) : undefined, path: provider.apiPath, protocol: provider.apiProtocol, method: "POST", diff --git a/src/extension/conversation-history.ts b/src/extension/conversation-history.ts index fc187872..3a3e606e 100644 --- a/src/extension/conversation-history.ts +++ b/src/extension/conversation-history.ts @@ -124,7 +124,7 @@ export class ConversationHistory { private getRequestOptions(provider: TwinnyProvider) { return { hostname: provider.apiHostname, - port: Number(provider.apiPort), + port: provider.apiPort ? Number(provider.apiPort) : undefined, path: provider.apiPath, protocol: provider.apiProtocol, method: "POST", diff --git a/src/extension/provider-manager.ts b/src/extension/provider-manager.ts index f5052ece..092f8099 100644 --- a/src/extension/provider-manager.ts +++ b/src/extension/provider-manager.ts @@ -15,7 +15,7 @@ import { apiProviders, ClientMessage, ServerMessage } from "../common/types" export interface TwinnyProvider { apiHostname: string apiPath: string - apiPort: number + apiPort?: number apiProtocol: string id: string label: string diff --git a/src/extension/providers/completion.ts b/src/extension/providers/completion.ts index 0adaeb3b..0288269b 100644 --- a/src/extension/providers/completion.ts +++ b/src/extension/providers/completion.ts @@ -254,7 +254,7 @@ export class CompletionProvider implements InlineCompletionItemProvider { const options: StreamRequestOptions = { hostname: provider.apiHostname, - port: Number(provider.apiPort), + port: provider.apiPort ? Number(provider.apiPort) : undefined, path: provider.apiPath, protocol: provider.apiProtocol, method: "POST", diff --git a/src/extension/utils.ts b/src/extension/utils.ts index eb10bf5f..a1be37f1 100644 --- a/src/extension/utils.ts +++ b/src/extension/utils.ts @@ -732,7 +732,7 @@ export function readGitIgnoreFile(): string[] | undefined { // eslint-disable-next-line @typescript-eslint/no-explicit-any export const logStreamOptions = (opts: any) => { const hostname = opts.options?.hostname ?? "unknown" - const port = opts.options?.port ?? "unknown" + const port = opts.options?.port ?? undefined const body = opts.body ?? {} const options = opts.options ?? {} @@ -740,7 +740,7 @@ export const logStreamOptions = (opts: any) => { const logMessage = ` ***Twinny Stream Debug*** - Streaming response from ${hostname}:${port}. + Streaming response from ${hostname}${port ? `:${port}` : ""}. Request body: ${JSON.stringify(body, null, 2)} diff --git a/src/webview/providers.tsx b/src/webview/providers.tsx index d57f00a6..b539d613 100644 --- a/src/webview/providers.tsx +++ b/src/webview/providers.tsx @@ -373,13 +373,12 @@ function ProviderForm({ onClose, provider }: ProviderFormProps) {
- +