feat: AK optional

This commit is contained in:
Simon
2026-03-19 19:50:05 +08:00
parent bdf79b7c10
commit fe82b11285
14 changed files with 30 additions and 102 deletions

View File

@@ -50,7 +50,7 @@ export class OpenAIClient implements LLMClient {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.config.apiKey}`,
...(this.config.apiKey && { Authorization: `Bearer ${this.config.apiKey}` }),
},
body: JSON.stringify(requestBody),
signal: abortSignal,

View File

@@ -8,17 +8,17 @@ export type { InvokeOptions, InvokeResult, LLMClient, LLMConfig, Message, Tool }
export function parseLLMConfig(config: LLMConfig): Required<LLMConfig> {
// Runtime validation as defensive programming (types already guarantee these)
if (!config.baseURL || !config.apiKey || !config.model) {
if (!config.baseURL || !config.model) {
throw new Error(
'[PageAgent] LLM configuration required. Please provide: baseURL, apiKey, model. ' +
'[PageAgent] LLM configuration required. Please provide: baseURL, model. ' +
'See: https://alibaba.github.io/page-agent/docs/features/models'
)
}
return {
baseURL: config.baseURL,
apiKey: config.apiKey,
model: config.model,
apiKey: config.apiKey || '',
temperature: config.temperature ?? DEFAULT_TEMPERATURE,
maxRetries: config.maxRetries ?? LLM_MAX_RETRIES,
customFetch: (config.customFetch ?? fetch).bind(globalThis), // fetch will be illegal unless bound

View File

@@ -89,8 +89,8 @@ export interface InvokeResult<TResult = unknown> {
*/
export interface LLMConfig {
baseURL: string
apiKey: string
model: string
apiKey?: string
temperature?: number
maxRetries?: number