Skip to content

refactor(open-sse): JS → TS migration + v0.8.5 - #62

Merged
diegosouzapw merged 4 commits into
mainfrom
refactor/open-sse-js-to-ts
Feb 17, 2026
Merged

diegosouzapw merged 4 commits into
mainfrom
refactor/open-sse-js-to-ts

Conversation

@diegosouzapw

Copy link
Copy Markdown
Owner

Summary

  • 94 .js files migrated to TypeScript (.ts)
  • 0 TSC errors, 0 @ts-ignore comments
  • Version bumped from 0.8.0 → 0.8.5

Commits

  1. Initial migration: 94 .js → .ts
  2. Phase 6: reduce @ts-ignore from 231 → 186
  3. Phase 7: eliminate all @ts-ignore (186 → 0) and all errors (237 → 0)
  4. Version bump to 0.8.5

Verification

npx tsc -p open-sse/tsconfig.json --noEmit → 0 errors
grep -rc @ts-ignore open-sse/ → 0 occurrences

- Rename all 94 .js files to .ts across config/, utils/, services/,
  handlers/, executors/, translator/, transformer/, and root index
- Add proper TypeScript interfaces: RegistryEntry, AudioProvider, FetchOptions
- Add class property declarations to BaseExecutor
- Type key function parameters in utils layer (tlsClient, stream,
  logger, error, proxyFetch, proxyDispatcher, etc.)
- Add @ts-ignore annotations for remaining TS2339 errors (gradual migration)
- Zero TypeScript errors in open-sse/tsconfig.json
- Zero .js files remaining in open-sse/
- Remove 209 standalone @ts-ignore annotations
- Fix 11 root-cause object literals with Record<string, any> typing
- Properly type message objects in responseTranslator, kiro executor
- Re-insert 164 targeted @ts-ignore for remaining complex patterns
- Net reduction: 231 → 186 @ts-ignore (-20%)
- Zero TypeScript errors maintained
- Remove ALL 231 @ts-ignore annotations (231 → 0)
- Fix 237 TypeScript errors with proper typings:
  - Type 30+ variable declarations as Record<string, any>
  - Add optional params: model?, provider?, retryAfter?, retryAfterHuman?
  - Replace @ts-ignore with 'as any' casts for custom Error/Array properties
  - Add EdgeRuntime global declaration for edge runtime compat
  - Import fs/path in responsesTransformer.ts
  - Fix function argument mismatches (resolveComboConfig, unavailableResponse)
- Build: tsc --noEmit passes with 0 errors
- Update package.json version to 0.8.5
- Update package-lock.json version to 0.8.5
- Update version references in docs/new-features
Copilot AI review requested due to automatic review settings February 17, 2026 11:39
@github-actions

Copy link
Copy Markdown
Contributor

@codex review

@diegosouzapw
diegosouzapw merged commit 7d67f5d into main Feb 17, 2026
3 checks passed
@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@diegosouzapw
diegosouzapw deleted the refactor/open-sse-js-to-ts branch February 17, 2026 11:39
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @diegosouzapw, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request undertakes a substantial refactoring effort to transition the open-sse module from JavaScript to TypeScript. The primary goal was to introduce strong typing throughout the codebase, which involved converting numerous files and meticulously resolving all type-related issues. This migration significantly improves the project's reliability, makes the code easier to understand, and streamlines future development by leveraging TypeScript's static analysis capabilities.

Highlights

  • TypeScript Migration: Migrated 94 JavaScript files to TypeScript, enhancing type safety and code maintainability across the open-sse module.
  • Zero Type Errors: Successfully eliminated all TypeScript compilation errors and removed all @ts-ignore comments, ensuring a clean and robust codebase.
  • Version Update: Bumped the project version from 0.8.0 to 0.8.5, reflecting the significant refactoring and improvements.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • open-sse/config/audioRegistry.ts
    • Renamed from .js to .ts
    • Added AudioModel and AudioProvider interfaces
    • Applied type annotations to AUDIO_TRANSCRIPTION_PROVIDERS, AUDIO_SPEECH_PROVIDERS, and related functions
  • open-sse/config/codexInstructions.ts
    • Renamed from .js to .ts
  • open-sse/config/constants.ts
    • Renamed from .js to .ts
  • open-sse/config/credentialLoader.ts
    • Renamed from .js to .ts
  • open-sse/config/defaultThinkingSignature.ts
    • Renamed from .js to .ts
  • open-sse/config/embeddingRegistry.ts
    • Renamed from .js to .ts
  • open-sse/config/imageRegistry.ts
    • Renamed from .js to .ts
  • open-sse/config/moderationRegistry.ts
    • Renamed from .js to .ts
  • open-sse/config/ollamaModels.ts
    • Renamed from .js to .ts
  • open-sse/config/providerModels.ts
    • Renamed from .js to .ts
  • open-sse/config/providerRegistry.ts
    • Renamed from .js to .ts
    • Introduced RegistryModel, RegistryOAuth, and RegistryEntry interfaces
    • Added type annotations to REGISTRY and associated utility functions
  • open-sse/config/rerankRegistry.ts
    • Renamed from .js to .ts
  • open-sse/executors/antigravity.ts
    • Renamed from .js to .ts
  • open-sse/executors/base.ts
    • Renamed from .js to .ts
    • Added type annotations to BaseExecutor class properties, constructor, and fetchOptions
  • open-sse/executors/codex.ts
    • Renamed from .js to .ts
  • open-sse/executors/cursor.ts
    • Renamed from .js to .ts
    • Added declare var EdgeRuntime: any;
    • Applied type assertions for response.headers and response
    • Added type annotation for message object
  • open-sse/executors/default.ts
    • Renamed from .js to .ts
  • open-sse/executors/gemini-cli.ts
    • Renamed from .js to .ts
  • open-sse/executors/github.ts
    • Renamed from .js to .ts
  • open-sse/executors/index.ts
    • Renamed from .js to .ts
  • open-sse/executors/kiro.ts
    • Renamed from .js to .ts
    • Added type annotations to state and chunk objects
  • open-sse/handlers/audioSpeech.ts
    • Renamed from .js to .ts
    • Updated errorResponse calls to new signature
    • Added JSDoc type annotation for handleAudioSpeech return type
  • open-sse/handlers/audioTranscription.ts
    • Renamed from .js to .ts
    • Updated errorResponse calls to new signature
    • Added JSDoc type annotation for handleAudioTranscription return type
    • Applied type assertions for file and val in upstreamForm.append
  • open-sse/handlers/chatCore.ts
    • Renamed from .js to .ts
    • Added JSDoc type annotation for handleChatCore options
  • open-sse/handlers/embeddings.ts
    • Renamed from .js to .ts
    • Added type annotation for upstreamBody object
  • open-sse/handlers/imageGeneration.ts
    • Renamed from .js to .ts
    • Added type annotation for upstreamBody object
  • open-sse/handlers/moderations.ts
    • Renamed from .js to .ts
    • Updated errorResponse calls to new signature
    • Added JSDoc type annotation for handleModeration return type
  • open-sse/handlers/rerank.ts
    • Renamed from .js to .ts
    • Updated errorResponse calls to new signature
    • Added JSDoc type annotation for handleRerank return type
  • open-sse/handlers/responseTranslator.ts
    • Renamed from .js to .ts
    • Added type annotations to message and result objects
  • open-sse/handlers/responsesHandler.ts
    • Renamed from .js to .ts
    • Added type assertion for createStreamController options
  • open-sse/handlers/sseParser.ts
    • Renamed from .js to .ts
    • Added type annotations to message and result objects
  • open-sse/handlers/usageExtractor.ts
    • Renamed from .js to .ts
  • open-sse/index.ts
    • Renamed from .js to .ts
  • open-sse/services/accountFallback.ts
    • Renamed from .js to .ts
    • Added optional model parameter and type annotation to getAccountHealth
  • open-sse/services/accountSelector.ts
    • Renamed from .js to .ts
    • Added type annotation for state parameter in selectAccount
  • open-sse/services/combo.ts
    • Renamed from .js to .ts
    • Added JSDoc type annotation for handleComboChat options
  • open-sse/services/comboConfig.ts
    • Renamed from .js to .ts
    • Added optional provider parameter type annotation to resolveComboConfig
  • open-sse/services/comboMetrics.ts
    • Renamed from .js to .ts
    • Added type annotations to combo and result objects
    • Applied type annotations to Object.entries map function
  • open-sse/services/contextManager.ts
    • Renamed from .js to .ts
    • Added type annotation for options parameter in compressContext
  • open-sse/services/ipFilter.ts
    • Renamed from .js to .ts
  • open-sse/services/model.ts
    • Renamed from .js to .ts
  • open-sse/services/provider.ts
    • Renamed from .js to .ts
    • Added type annotation for options parameter in buildProviderUrl
  • open-sse/services/rateLimitManager.ts
    • Renamed from .js to .ts
    • Added type annotations to updates and result objects
  • open-sse/services/rateLimitSemaphore.ts
    • Renamed from .js to .ts
    • Added type assertion for err.code
  • open-sse/services/sessionManager.ts
    • Renamed from .js to .ts
    • Added type annotation for options parameter in generateSessionId
  • open-sse/services/signatureCache.ts
    • Renamed from .js to .ts
    • Added type annotations for context parameters in getSignatures, addSignature, and detectAndLearn
  • open-sse/services/systemPrompt.ts
    • Renamed from .js to .ts
  • open-sse/services/thinkingBudget.ts
    • Renamed from .js to .ts
  • open-sse/services/tokenRefresh.ts
    • Renamed from .js to .ts
  • open-sse/services/usage.ts
    • Renamed from .js to .ts
    • Added JSDoc type annotation for getUsageForProvider return type
    • Added undefined argument to getAntigravityUsage call
    • Added type annotations to quotas and Object.entries map function
  • open-sse/services/wildcardRouter.ts
    • Renamed from .js to .ts
  • open-sse/transformer/responsesTransformer.ts
    • Renamed from .js to .ts
    • Added fs and path imports
  • open-sse/translator/formats.ts
    • Renamed from .js to .ts
  • open-sse/translator/helpers/claudeHelper.ts
    • Renamed from .js to .ts
  • open-sse/translator/helpers/geminiHelper.ts
    • Renamed from .js to .ts
    • Added type annotation for merged object
  • open-sse/translator/helpers/maxTokensHelper.ts
    • Renamed from .js to .ts
  • open-sse/translator/helpers/openaiHelper.ts
    • Renamed from .js to .ts
  • open-sse/translator/helpers/responsesApiHelper.ts
    • Renamed from .js to .ts
  • open-sse/translator/helpers/toolCallHelper.ts
    • Renamed from .js to .ts
  • open-sse/translator/index.ts
    • Renamed from .js to .ts
    • Added type assertion for results._openaiIntermediate
  • open-sse/translator/request/antigravity-to-openai.ts
    • Renamed from .js to .ts
    • Added type annotations to result and msg objects
  • open-sse/translator/request/claude-to-gemini.ts
    • Renamed from .js to .ts
    • Added type annotation for result object
  • open-sse/translator/request/claude-to-openai.ts
    • Renamed from .js to .ts
    • Added type annotations to result and result objects
  • open-sse/translator/request/gemini-to-openai.ts
    • Renamed from .js to .ts
    • Added type annotations to result and result objects
  • open-sse/translator/request/openai-responses.ts
    • Renamed from .js to .ts
    • Added type assertions for error.statusCode and error.errorType
    • Added type annotation for result object
  • open-sse/translator/request/openai-to-claude.ts
    • Renamed from .js to .ts
    • Added type annotation for result object
  • open-sse/translator/request/openai-to-cursor.ts
    • Renamed from .js to .ts
    • Added type annotations to assistantMsg and msgObj objects
  • open-sse/translator/request/openai-to-gemini.ts
    • Renamed from .js to .ts
    • Added type annotations to result, envelope, and defaultPart objects
  • open-sse/translator/request/openai-to-kiro.ts
    • Renamed from .js to .ts
    • Added type annotations to userMsg and payload objects
  • open-sse/translator/response/claude-to-openai.ts
    • Renamed from .js to .ts
    • Added type annotation for finalChunk object
  • open-sse/translator/response/cursor-to-openai.ts
    • Renamed from .js to .ts
  • open-sse/translator/response/gemini-to-claude.ts
    • Renamed from .js to .ts
  • open-sse/translator/response/gemini-to-openai.ts
    • Renamed from .js to .ts
    • Added type annotation for finalChunk object
  • open-sse/translator/response/kiro-to-openai.ts
    • Renamed from .js to .ts
    • Added type annotation for openaiChunk object
  • open-sse/translator/response/openai-responses.ts
    • Renamed from .js to .ts
    • Added type annotation for finalChunk object
  • open-sse/translator/response/openai-to-antigravity.ts
    • Renamed from .js to .ts
    • Added type annotations to candidate and response objects
  • open-sse/translator/response/openai-to-claude.ts
    • Renamed from .js to .ts
  • open-sse/tsconfig.json
    • Added new TypeScript configuration file
    • Configured compiler options for ES2022 target, ESNext module resolution, and enabled allowJs and checkJs
    • Set noEmit to true for type checking without outputting JavaScript files
    • Defined path aliases for @omniroute/open-sse
  • open-sse/utils/bypassHandler.ts
    • Renamed from .js to .ts
  • open-sse/utils/cursorChecksum.ts
    • Renamed from .js to .ts
  • open-sse/utils/cursorProtobuf.ts
    • Renamed from .js to .ts
  • open-sse/utils/error.ts
    • Renamed from .js to .ts
    • Added type annotations to createErrorResult parameters and return object
    • Added type annotations to unavailableResponse parameters
  • open-sse/utils/logger.ts
    • Renamed from .js to .ts
    • Added type annotations to entry objects
  • open-sse/utils/networkProxy.ts
    • Renamed from .js to .ts
    • Added JSDoc type annotation for resolveProxy return type
  • open-sse/utils/ollamaTransform.ts
    • Renamed from .js to .ts
    • Added type annotations to pendingToolCalls and formattedCalls
  • open-sse/utils/progressTracker.ts
    • Renamed from .js to .ts
    • Added type annotations to createProgressTransform options
  • open-sse/utils/proxyDispatcher.ts
    • Renamed from .js to .ts
    • Added type annotations to socksOptions and type assertion for socksDispatcher
  • open-sse/utils/proxyFetch.ts
    • Renamed from .js to .ts
    • Added type annotations to patchedFetch parameters and type assertions for store
  • open-sse/utils/requestLogger.ts
    • Renamed from .js to .ts
  • open-sse/utils/stream.ts
    • Renamed from .js to .ts
    • Added JSDoc type annotation for createSSEStream options
    • Applied type assertions for translated._openaiIntermediate
  • open-sse/utils/streamHandler.ts
    • Renamed from .js to .ts
    • Added JSDoc type annotation for createStreamController options
  • open-sse/utils/streamHelpers.ts
    • Renamed from .js to .ts
  • open-sse/utils/thinkTagParser.ts
    • Renamed from .js to .ts
  • open-sse/utils/tlsClient.ts
    • Renamed from .js to .ts
    • Added type annotations to createSession, getProxyFromEnv return type, FetchOptions interface, TlsClient class properties, sessionOpts, fetch parameters, and wreqOptions
  • open-sse/utils/usageTracking.ts
    • Renamed from .js to .ts
  • package-lock.json
    • Updated project version from 0.8.0 to 0.8.5
  • package.json
    • Updated project version from 0.8.0 to 0.8.5
Activity
  • The pull request author initiated the migration of 94 JavaScript files to TypeScript.
  • The author systematically reduced @ts-ignore comments from 231 to 186 in an intermediate phase.
  • All remaining @ts-ignore comments and TypeScript errors were eliminated in a subsequent phase.
  • Verification steps included running npx tsc -p open-sse/tsconfig.json --noEmit to confirm zero errors and grep -rc @ts-ignore open-sse/ to confirm zero occurrences.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates 94 JavaScript files to TypeScript in the open-sse package and bumps the version from 0.8.0 to 0.8.5. The migration achieves 0 TypeScript compilation errors without using @ts-ignore comments. However, this is largely accomplished by disabling strict mode and extensively using the any type, which significantly reduces the type safety benefits that TypeScript provides.

Changes:

  • Version bump from 0.8.0 to 0.8.5 across package.json and package-lock.json
  • Addition of TypeScript configuration (tsconfig.json) with strict mode disabled
  • Migration of 94 .js files to .ts with type annotations (many using any)
  • Breaking API change to errorResponse function parameter order

Reviewed changes

Copilot reviewed 56 out of 97 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
package.json Version bump to 0.8.5
package-lock.json Lockfile version update to 0.8.5
open-sse/tsconfig.json New TypeScript configuration with strict mode disabled
open-sse/**/*.ts Migrated files with type annotations, extensive use of any type
open-sse/handlers/rerank.ts Breaking change: errorResponse parameter order reversed
open-sse/handlers/moderations.ts Same errorResponse parameter order change
open-sse/handlers/audioTranscription.ts Same errorResponse parameter order change
open-sse/handlers/audioSpeech.ts Same errorResponse parameter order change
open-sse/executors/cursor.ts Global EdgeRuntime declaration without proper typing
open-sse/transformer/responsesTransformer.ts Unused imports added
Comments suppressed due to low confidence (4)

open-sse/handlers/rerank.ts:84

  • The function signature for errorResponse appears to have changed parameter order from (message, statusCode) to (statusCode, message) based on the usage changes in rerank.ts, moderations.ts, and audioTranscription.ts. This is a breaking API change that could cause runtime errors if not updated consistently across all callers. Verify all call sites have been updated.
    open-sse/transformer/responsesTransformer.ts:2
  • Unused imports added at the top of this file. The fs and path imports are not used anywhere in the visible code and should be removed.
    open-sse/executors/cursor.ts:1
  • The global declaration declare var EdgeRuntime: any; at the top of the file is concerning. This appears to be a workaround for a missing type definition. Consider:
  1. Installing the proper type definitions package if available
  2. Creating a proper type definition file (e.g., edge-runtime.d.ts)
  3. Adding a comment explaining why this declaration is needed
    open-sse/handlers/chatCore.ts:55
  • Using @ts-ignore successor patterns like JSDoc @param {any} annotations alongside TypeScript defeats the purpose of migration. These files should either have proper TypeScript types or remain as JavaScript. This pattern appears in multiple files (chatCore.ts, combo.ts, rerank.ts, etc.).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread open-sse/tsconfig.json
Comment on lines +1 to +25
{
"compilerOptions": {
"target": "ES2022",
"module": "esnext",
"moduleResolution": "bundler",
"allowJs": true,
"checkJs": true,
"noEmit": true,
"skipLibCheck": true,
"esModuleInterop": true,
"strict": false,
"jsx": "react-jsx",
"lib": ["dom", "esnext"],
"baseUrl": "..",
"paths": {
"@/*": ["./src/*"],
"@omniroute/open-sse": ["./open-sse"],
"@omniroute/open-sse/*": ["./open-sse/*"]
}
},
"include": [
"**/*.ts",
"**/*.js"
]
}

Copilot AI Feb 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The any type is used extensively throughout this migration (over 100+ occurrences in the diff), which defeats the purpose of TypeScript's type safety. Consider defining proper interfaces or types instead of using any, especially for:

  • Function parameters (e.g., options: any, context: any, credentials: any)
  • Object properties (e.g., Record<string, any>)
  • Type assertions (e.g., as any)

While this may require more upfront work, it will provide actual type safety benefits and catch potential bugs at compile time.

Copilot uses AI. Check for mistakes.
Comment thread open-sse/tsconfig.json
"noEmit": true,
"skipLibCheck": true,
"esModuleInterop": true,
"strict": false,

Copilot AI Feb 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strict: false in tsconfig.json disables all strict type checking options. This significantly reduces the benefits of TypeScript migration. Consider enabling strict mode gradually by enabling individual strict flags (strictNullChecks, strictFunctionTypes, etc.) to improve type safety.

Copilot uses AI. Check for mistakes.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request primarily focuses on enhancing type safety across the codebase by introducing explicit TypeScript interfaces and type annotations to various functions, variables, and object properties. Key changes include defining interfaces for AudioModel, AudioProvider, RegistryModel, RegistryOAuth, and RegistryEntry to provide structured typing for configuration objects. Many functions, such as those in audioRegistry.ts, providerRegistry.ts, and various handlers and services files, received explicit parameter and return type annotations. The tsconfig.json file was also added to enable TypeScript compilation. Review comments highlight concerns about the widespread use of any types, suggesting that while it aids migration, it undermines type safety. Specific feedback recommends defining custom error classes instead of casting properties to any on generic Error objects, using type guards for FormDataEntryValue to safely access properties, and defining proper interfaces for function parameters and return types to avoid any and improve code maintainability and readability. There's also a suggestion to enable strict mode in TypeScript for better error detection.

Comment thread open-sse/tsconfig.json
"noEmit": true,
"skipLibCheck": true,
"esModuleInterop": true,
"strict": false,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Setting "strict": false significantly reduces the benefits of using TypeScript. While it can make the initial migration easier, the long-term goal should be to enable strict mode ("strict": true) to catch a wide range of potential errors at compile time, such as implicit any types, null/undefined handling, and more. I recommend creating a follow-up task to enable strict mode and fix the resulting type errors.

* @returns {number} score 0 = unhealthy, 100 = perfectly healthy
*/
export function getAccountHealth(account) {
export function getAccountHealth(account, model?: any) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The model parameter was added to the function signature but is not used within the function body. If it's intended for future use, consider adding a comment explaining why. Otherwise, it should be removed to avoid confusion. Also, using any should be avoided; if the model parameter is needed, it should have a proper type.


try {
const response = http2
const response: any = http2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using any for the response variable defeats the purpose of TypeScript. It seems makeHttp2Request and makeFetchRequest return a similar object structure. It would be beneficial to define an interface for this response shape and use it here to ensure type safety.

For example:

interface CustomResponse {
  status: number;
  headers: Record<string, string | number | string[]>;
  body: Buffer;
}

// ...

const response: CustomResponse = http2
  ? await this.makeHttp2Request(url, headers, transformedBody, signal)
  : await this.makeFetchRequest(url, headers, transformedBody, signal);

// Default: OpenAI/Groq-compatible multipart proxy
const upstreamForm = new FormData();
upstreamForm.append("file", file, file.name || "audio.wav");
upstreamForm.append("file", /** @type {Blob} */ (file), /** @type {any} */ (file).name || "audio.wav");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using /** @type {any} */ to access the .name property bypasses type checking. Since file is of type FormDataEntryValue (string | File), a type guard would be safer to ensure you only access .name when file is a File object.

Suggested change
upstreamForm.append("file", /** @type {Blob} */ (file), /** @type {any} */ (file).name || "audio.wav");
upstreamForm.append("file", /** @type {Blob} */ (file), file instanceof File ? (file.name || "audio.wav") : "audio.wav");

const val = formData.get(key);
if (val !== null && val !== undefined) {
upstreamForm.append(key, val);
upstreamForm.append(key, /** @type {string} */ (val));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The val from formData.get(key) can be a File object, not just a string. Casting to string is not type-safe. FormData.append can handle Blob (which File is) or string values, so you can pass val directly without a cast after checking for null/undefined.

Suggested change
upstreamForm.append(key, /** @type {string} */ (val));
upstreamForm.append(key, val);

Comment on lines 119 to +120
const err = new Error(`Semaphore timeout after ${timeoutMs}ms for ${modelStr}`);
err.code = "SEMAPHORE_TIMEOUT";
(err as any).code = "SEMAPHORE_TIMEOUT";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Adding properties to a generic Error object using as any is not type-safe. A better approach is to create a custom error class that includes the code property. This makes error handling more robust and predictable.

      class SemaphoreTimeoutError extends Error {
        code = "SEMAPHORE_TIMEOUT";
      }
      const err = new SemaphoreTimeoutError(`Semaphore timeout after ${timeoutMs}ms for ${modelStr}`);

];

for (const [modelKey, info] of Object.entries(data.models)) {
for (const [modelKey, info] of Object.entries(data.models) as [string, any][]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Casting to [string, any][] is a sign that the type of data.models is not well-defined. It would be better to define an interface for the info object to avoid using any and improve type safety when accessing its properties like info.quotaInfo.

// Attach OpenAI intermediate results for logging
if (openaiResults && sourceFormat !== FORMATS.OPENAI && targetFormat !== FORMATS.OPENAI) {
results._openaiIntermediate = openaiResults;
(results as any)._openaiIntermediate = openaiResults;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Attaching a property to an array using as any is not type-safe and can be brittle. A better approach would be to return a structured object that contains both the results and the intermediate data, for example: { results: results, openaiIntermediate: openaiResults }. The caller would then need to be updated to handle this new structure.

return {
status: response.status,
headers: Object.fromEntries(response.headers.entries()),
headers: Object.fromEntries((response.headers as any).entries()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The as any cast here hides potential type issues. The Headers object is iterable, and Object.fromEntries accepts an iterable of key-value pairs. This should work without any in modern environments. If you are facing type compatibility issues between different environments (Node vs. Edge), you could create a helper function to convert headers to an object in a type-safe way, but simply removing the cast is preferable if it works.

      headers: Object.fromEntries(response.headers.entries()),

}

async function patchedFetch(input, options = {}) {
async function patchedFetch(input: any, options: any = {}) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The parameters input and options are typed as any. To align with the standard fetch signature, they should be typed as RequestInfo | URL and RequestInit respectively. These types are available because you have "lib": ["dom", ...] in your tsconfig.json.

Suggested change
async function patchedFetch(input: any, options: any = {}) {
async function patchedFetch(input: RequestInfo | URL, options: RequestInit = {}) {

diegosouzapw pushed a commit that referenced this pull request Sep 29, 2026
Native Claude quota scope is honored end to end (claudeQuota normalizer, modelQuotas separation, effort/context-aware model matching). Maintainer rework: merged the release tip twice, reconciling markAccountUnavailable with the OAuth 401 backoff (#14917: the Claude-scope cooldown feeds resolvedCooldownMs, the backoff still overrides it, and a Claude resetAt is only used when the backoff did not apply) and carrying the claudeQuota/modelQuotas fields into the new quotaCacheState.ts leaf (#14820, type-only import). Validated on the tip: 70 related test files 683 pass; the only reds (chat-cooldown-aware-retry #6, false-terminal-401-quota #1, sse-auth #62-66) fail identically on the pure tip. typecheck:core and ESLint clean. File-size ceiling growth is reconciled in the wave follow-up. Thank you @riez!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants