Task 03 — Service-layer token threading
Depends on: 02
Unblocks: 04, 07, 08, 09, 10
Goal
All upstream-calling helpers receive an Account instead of reading from a
global. After this task, the proxy still works exactly as before because
handlers will pass state.pool.acquire() once and forward the result — the
real load balancing happens in task 04.
Scope
Change signatures in src/lib/api-config.ts:
copilotBaseUrl(account)
copilotHeaders(account, vision?)
githubHeaders(account)
Change signatures in:
src/services/copilot/create-chat-completions.ts
src/services/copilot/create-embeddings.ts
src/services/copilot/get-models.ts
src/services/github/get-copilot-token.ts
src/services/github/get-copilot-usage.ts
src/services/github/get-user.ts
Each function takes account as its first arg (or as part of an options bag).
Handlers are updated to acquire an account inline (interim placeholder before
task 04):
const account = await state.pool.acquire()
try {
return await createChatCompletions(account, payload)
} finally {
state.pool.release(account)
}
Definition of Done
Task 03 — Service-layer token threading
Depends on: 02
Unblocks: 04, 07, 08, 09, 10
Goal
All upstream-calling helpers receive an
Accountinstead of reading from aglobal. After this task, the proxy still works exactly as before because
handlers will pass
state.pool.acquire()once and forward the result — thereal load balancing happens in task 04.
Scope
Change signatures in
src/lib/api-config.ts:Change signatures in:
src/services/copilot/create-chat-completions.tssrc/services/copilot/create-embeddings.tssrc/services/copilot/get-models.tssrc/services/github/get-copilot-token.tssrc/services/github/get-copilot-usage.tssrc/services/github/get-user.tsEach function takes
accountas its first arg (or as part of an options bag).Handlers are updated to acquire an account inline (interim placeholder before
task 04):
Definition of Done
tscpasses; no remaining references tostate.copilotTokenorstate.githubToken.endpoints still pass.
cacheModels()/cacheVSCodeVersion()updated to call the per-accountvariant (use the first available account; these are startup-time concerns).
docs/tasks/03-service-token-threading.mddocs/design/