The plugin asked `ctx.llm.providerCredential()` for each route's credential, read `DEEPSEEK_API_KEY` and the account service itself when a route was not mounted, ordered those sources by billing, and rendered the request headers in its transport. It now names the kinds the two APIs accept and the capability's billing, and `ctx.deepseekAuth` returns the ordered credentials, each bound to its endpoint. The plugin keeps the wording of its failures; the transport sends the headers it is given. Behavior is unchanged except in two places. A key that is blank or cannot travel in an HTTP header is reported with the error name `DeepSeekAuthError` where it named `LlmError`. A capability's own base URL that embeds credentials now leaves the provider unavailable, as one that does not parse already did; `fetch` refused such a URL before. The package no longer depends on `dsh-llm`, `dsh-launch-environment`, or the account service. The transport's `apiKeyHeaders` request option, which only tests set, is gone, and the tests of adapters that publish the other credential kind under a DeepSeek route id went with that publication.
21 lines
1013 B
TypeScript
21 lines
1013 B
TypeScript
/** Credential sources for provider tests that construct a provider or a request directly. */
|
|
import { credentialRef } from '@deepseek-ai/dsh-credentials'
|
|
import type { DeepSeekAuthCandidate } from '@deepseek-ai/dsh-deepseek-auth'
|
|
|
|
/**
|
|
* An API-key candidate bound to `endpoint`, as `ctx.deepseekAuth` binds one: it releases `key` as a bearer token and
|
|
* releases nothing for an empty key.
|
|
* @param endpoint - absolute URL the operation dispatches to.
|
|
* @param key - the key; empty means none is configured.
|
|
* @param reference - the credential reference the candidate names.
|
|
* @returns the candidate.
|
|
*/
|
|
export function keyCandidate(endpoint: string, key: string, reference = 'TEST_KEY'): DeepSeekAuthCandidate {
|
|
const ref = credentialRef(reference)
|
|
return {
|
|
kind: 'api-key', endpoint, reference: ref,
|
|
configured: async () => key.length > 0,
|
|
resolve: async () => key.length > 0 ? { kind: 'api-key', endpoint, reference: ref, headers: { authorization: `Bearer ${key}` } } : undefined,
|
|
}
|
|
}
|