mirror of
https://github.com/larsbaunwall/vscode-copilot-bridge.git
synced 2025-10-05 22:22:59 +00:00
Refactor implementation with focus on performance improvement
This commit is contained in:
parent
7e10f69d5f
commit
2dc54a0ea6
16 changed files with 492 additions and 606 deletions
29
.github/copilot-instructions.md
vendored
29
.github/copilot-instructions.md
vendored
|
|
@ -1,5 +1,28 @@
|
|||
Copilot instructions
|
||||
## Copilot Usage Notes
|
||||
|
||||
Look carefully through [AGENTS.md](../AGENTS.md) for a description of the project and how to contribute.
|
||||
Always skim [AGENTS.md](../AGENTS.md) before making changes—the document is the single source of truth for architecture, performance targets, and workflow expectations.
|
||||
|
||||
Follow instructions carefully.
|
||||
### Hot-path rules
|
||||
|
||||
- Reuse the helpers in `src/http/utils.ts` (`writeUnauthorized`, `writeNotFound`, `writeRateLimit`, `writeErrorResponse`) instead of hand-written JSON responses.
|
||||
- Preserve the SSE contract in `src/http/routes/chat.ts`: emit role chunk first, follow with `data: { ... }` payloads, and terminate with `data: [DONE]`.
|
||||
- When streaming, keep `socket.setNoDelay(true)` on the response socket to avoid latency regressions.
|
||||
- Honor `state.activeRequests` concurrency guard and return early 429s via `writeRateLimit`.
|
||||
|
||||
### Tool calling compatibility
|
||||
|
||||
- `mergeTools` already merges deprecated `functions`; prefer extending it over new code paths.
|
||||
- The bridge treats `tool_choice: "required"` like `"auto"` and ignores `parallel_tool_calls`—reflect this limitation in docs if behavior changes.
|
||||
- Stream tool call deltas using `delta.tool_calls` chunks containing JSON-encoded argument strings. Downstream clients should replace, not append, argument fragments.
|
||||
|
||||
### Scope & contracts
|
||||
|
||||
- Public endpoints are `/health`, `/v1/models`, `/v1/chat/completions`. Changing contracts requires README updates and a version bump.
|
||||
- Keep the bridge loopback-only unless a new configuration knob is explicitly approved.
|
||||
- Update configuration docs when introducing new `bridge.*` settings and run `npm run compile` before handing off changes.
|
||||
|
||||
### Workflow
|
||||
|
||||
- Plan with the todo-list tool, keep diffs minimal, and avoid formatting unrelated regions.
|
||||
- Capture limitations or behavior differences (e.g., missing OpenAI response fields) in comments or docs so clients aren’t surprised.
|
||||
- Summarize reality after each change: what was touched, how it was verified, and any follow-ups.
|
||||
9
.github/instructions/ts.instructions.md
vendored
9
.github/instructions/ts.instructions.md
vendored
|
|
@ -13,6 +13,7 @@ applyTo: '**/*.ts'
|
|||
- Prefer readable, explicit solutions over clever shortcuts.
|
||||
- Extend current abstractions before inventing new ones.
|
||||
- Prioritize maintainability and clarity, short methods and classes, clean code.
|
||||
- Keep edits aligned with [AGENTS.md](../../AGENTS.md) and `.github/copilot-instructions.md`.
|
||||
|
||||
## Programming Language: TypeScript
|
||||
|
||||
|
|
@ -40,6 +41,11 @@ applyTo: '**/*.ts'
|
|||
- Use pure ES modules; never emit `require`, `module.exports`, or CommonJS helpers.
|
||||
- Rely on the project's build, lint, and test scripts unless asked otherwise.
|
||||
- Note design trade-offs when intent is not obvious.
|
||||
- Reuse the HTTP helpers in `src/http/utils.ts` (`writeUnauthorized`, `writeNotFound`, `writeRateLimit`, `writeErrorResponse`) instead of writing ad-hoc JSON responses.
|
||||
- Preserve the SSE contract in `src/http/routes/chat.ts`: send the role chunk first, follow with `data: { ... }` payloads, and always terminate with `data: [DONE]`.
|
||||
- When streaming, call `res.socket?.setNoDelay(true)` before emitting chunks to avoid latency regressions.
|
||||
- Honor the concurrency guard (`state.activeRequests`) and return early 429 responses via `writeRateLimit` when limits are exceeded.
|
||||
- Communicate limitations of the VS Code LM API, e.g., `tool_choice: "required"` behaving like `"auto"` and lack of `parallel_tool_calls` support.
|
||||
|
||||
## Project Organization
|
||||
|
||||
|
|
@ -75,6 +81,7 @@ applyTo: '**/*.ts'
|
|||
- Send errors through the project's logging/telemetry utilities.
|
||||
- Surface user-facing errors via the repository's notification pattern.
|
||||
- Debounce configuration-driven updates and dispose resources deterministically.
|
||||
- Prefer the pre-serialized error helpers for fast paths and document any new reason codes in README + status handlers.
|
||||
|
||||
## Architecture & Patterns
|
||||
|
||||
|
|
@ -126,6 +133,8 @@ applyTo: '**/*.ts'
|
|||
- Defer expensive work until users need it.
|
||||
- Batch or debounce high-frequency events to reduce thrash.
|
||||
- Track resource lifetimes to prevent leaks.
|
||||
- Avoid repeated configuration reads in hot paths; cache settings when practical.
|
||||
- Maintain streaming code paths without buffering entire responses; only accumulate when `stream: false`.
|
||||
|
||||
## Documentation & Comments
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue