Commit graph

6 commits

Author SHA1 Message Date
Zero Liu
8658282aa9
chore(lint): enable 4 type-aware quick-win rules and fix violations (#2424)
Turns on no-unsafe-enum-comparison, no-base-to-string,
no-redundant-type-constituents, and restrict-template-expressions.
Fixes all 24 violations across 13 source files.
2026-05-13 21:57:33 -07:00
Zero Liu
6331631dd0
chore(popout): window-global API swaps — timers, globalThis, base64 (W3/9) (#2401)
Fourth of nine workspaces splitting #2397. Mechanical swaps to
window-namespaced globals for Obsidian popout window compatibility.
No semantic behavior change beyond "works correctly in a popout."

- setTimeout / clearTimeout / setInterval / clearInterval /
  requestAnimationFrame → window.* across all callsites
- globalThis → window (BedrockChatModel fetch.bind, scattered sites)
- atob / btoa → Buffer.from(..., 'base64') / Buffer.from(...).toString('base64')
  - src/encryptionService.ts (drops Node 'buffer' import; Buffer is global)
  - src/utils.ts safeFetch arrayBuffer() branch
  - src/LLMProviders/BedrockChatModel.ts decodeBase64ToUint8Array

Builds on top of #2398 (W0 — deps bump).

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-12 22:24:17 -07:00
Zero Liu
e470b5c70c
chore(types): tighten types and replace TFile/TFolder casts (W1/9) (#2403) 2026-05-12 16:18:22 -07:00
Emt-lin
11f3878244
feat: refactor GitHubCopilotChatModel to support tool calling (#2242)
* feat: refactor GitHubCopilotChatModel to support tool calling

Refactored GitHubCopilotChatModel from BaseChatModel to ChatOpenAICompletions
to enable bindTools() for Agent Mode tool calling support.

Key changes:
- Extend ChatOpenAICompletions instead of BaseChatModel for native tool support
- Override _streamResponseChunks to fix Copilot-specific streaming issues:
  1. Missing delta.role when proxying Claude models (defaults to "assistant")
  2. Non-string delta.content arrays from Claude (normalized to string)
- Use public convertCompletionsDeltaToBaseMessageChunk API (not deprecated method)
- Inject Copilot auth via configuration.fetch wrapper with 401/403 retry
- Export COPILOT_API_BASE and add public token management wrappers

* fix: improve type safety and retry logic in GitHubCopilotChatModel

- Replace loose `[key: string]: any` params interface with type derived
  from ChatOpenAICompletions constructor fields for proper type checking
- Limit auth retry to 401 only (not 403) to match GitHubCopilotProvider
  behavior and avoid useless token refresh on permanent permission errors
- Replace 80-line _streamResponseChunks fork with minimal
  _convertCompletionsDeltaToBaseMessageChunk override
- Remove unused imports (BaseChatModelParams, AIMessageChunk, etc.)

* refactor: remove dead code from GitHubCopilotProvider after ChatOpenAICompletions migration

Chat completions are now handled by GitHubCopilotChatModel (extends
ChatOpenAICompletions) with auth injected via configuration.fetch.
The old Provider-level request methods and their supporting types
are no longer referenced anywhere.

Removed:
- sendChatMessage, sendChatMessageStream, executeWithTokenRetry methods
- CopilotChatResponse, CopilotStreamChunk, CopilotRequestOptions interfaces
- CHAT_COMPLETIONS_URL, HTTP_STATUS_MESSAGES constants
- Unused imports: createParser, ParsedEvent, ReconnectInterval, FetchImplementation

* feat: add model policy terms UI, update Copilot headers, and fix review issues

- Update Copilot request headers to latest VSCode versions
- Cache model policy terms and surface activation guidance on 400 errors
- Extend GitHubCopilotModel interface with billing/policy/endpoint fields
- Show verification error with parsed Markdown links in ModelImporter
- Fix unused logInfo import, guard Request instanceof check,
  case-insensitive "not supported" match, clear policy cache on resetAuth
2026-03-05 09:46:53 -08:00
Logan Yang
308c88332d
Address quick ask (#2146)
* chore: translate Chinese comments to English and apply formatting

- Translate all Chinese comments in replaceGuard.ts to English for consistency
- Apply Prettier formatting to 33 files

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* test: add unit tests for Quick Ask core modules

Add comprehensive tests for:
- replaceGuard.ts: validation logic, error messages, MapPos and Highlight strategies
- persistentHighlight.ts: CM6 state field, range mapping, show/hide behavior
- quickCommandPrompts.ts: placeholder appending logic

64 new test cases covering edge cases like:
- Leaf/editor/file change detection
- Document bounds validation
- Content change detection
- Range mapping through document changes
- Case-insensitive placeholder detection

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 20:04:10 -08:00
Emt-lin
7f8b94311f
feat: add GitHub Copilot integration with improved robustness (#2110)
* feat: add GitHub Copilot integration with improved robustness

- Add GitHub Copilot as new LLM provider with OAuth device flow
- Implement GitHubCopilotProvider for token management and API calls
- Implement GitHubCopilotChatModel as LangChain BaseChatModel adapter
- Add GitHubCopilotAuth UI component for OAuth authentication
- Extract reusable ModelImporter component from ApiKeyDialog

Improvements:
- Use authGeneration counter to prevent race conditions on reset
- Add token validation and expires_at type handling (s/ms/string)
- Add MAX_REFRESH_ATTEMPTS to prevent infinite refresh loops
- Add try/catch/finally for robust error handling in ModelImporter
- Clean up AbortController lifecycle in polling operations

* fix: reset model list when provider credentials change

- Add credentialVersion prop to ModelImporter for detecting key changes
- Clear cached models when credentialVersion changes (not just isReady)
- Pass API key/token as credentialVersion in ApiKeyDialog and GitHubCopilotAuth
- This ensures model list refreshes when rotating keys (non-empty to non-empty)

* fix: treat Copilot access token as valid credential

Check both githubCopilotToken and githubCopilotAccessToken when
validating credentials. This allows the model to work when OAuth
succeeds but fetchCopilotToken fails, since getValidCopilotToken()
can still refresh using the access token.
2026-01-14 15:01:47 -08:00