chore(lint): reduce warning debt across core adapters and model clients
This commit is contained in:
+23
-8
@@ -27,13 +27,22 @@ function toOpenAIContent(content: string | MessageContentPart[]): string | OpenA
|
||||
return { type: 'text', text: part.text };
|
||||
}
|
||||
if (part.type === 'image') {
|
||||
if (part.source.type === 'base64' && !part.source.data) {
|
||||
return { type: 'text', text: '[Image omitted: missing base64 data]' };
|
||||
}
|
||||
if (part.source.type !== 'base64' && !part.source.url) {
|
||||
return { type: 'text', text: '[Image omitted: missing URL]' };
|
||||
}
|
||||
// OpenAI accepts data URIs or regular URLs
|
||||
const url = part.source.type === 'base64'
|
||||
? `data:${part.source.media_type};base64,${part.source.data!}`
|
||||
: part.source.url!;
|
||||
? `data:${part.source.media_type};base64,${part.source.data}`
|
||||
: part.source.url;
|
||||
return { type: 'image_url', image_url: { url } };
|
||||
}
|
||||
if (part.type === 'audio') {
|
||||
if (!part.source.data) {
|
||||
return { type: 'text', text: '[Audio omitted: missing data]' };
|
||||
}
|
||||
// OpenAI native audio input via input_audio content part
|
||||
// Determine format from MIME type (OpenAI supports: wav, mp3, flac, opus, ogg, webm)
|
||||
const formatMap: Record<string, string> = {
|
||||
@@ -157,9 +166,13 @@ export class OpenAIClient implements ModelClient {
|
||||
}
|
||||
}
|
||||
if (!data) {return;}
|
||||
let obj: any;
|
||||
let obj: Record<string, unknown>;
|
||||
try {
|
||||
obj = JSON.parse(data);
|
||||
const parsed = JSON.parse(data) as unknown;
|
||||
if (!parsed || typeof parsed !== 'object') {
|
||||
return;
|
||||
}
|
||||
obj = parsed as Record<string, unknown>;
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
@@ -169,8 +182,9 @@ export class OpenAIClient implements ModelClient {
|
||||
}
|
||||
|
||||
if (obj.type === 'response.completed') {
|
||||
const u = obj.response?.usage;
|
||||
if (u) {
|
||||
const response = obj.response as { usage?: { input_tokens?: number; output_tokens?: number } } | undefined;
|
||||
const u = response?.usage;
|
||||
if (u && typeof u === 'object') {
|
||||
usage = {
|
||||
inputTokens: u.input_tokens ?? 0,
|
||||
outputTokens: u.output_tokens ?? 0,
|
||||
@@ -179,7 +193,8 @@ export class OpenAIClient implements ModelClient {
|
||||
}
|
||||
|
||||
if (obj.type === 'response.failed') {
|
||||
const detail = obj.response?.error?.message ?? 'OpenAI OAuth response failed';
|
||||
const response = obj.response as { error?: { message?: string } } | undefined;
|
||||
const detail = response?.error?.message ?? 'OpenAI OAuth response failed';
|
||||
throw new Error(detail);
|
||||
}
|
||||
};
|
||||
@@ -247,7 +262,7 @@ export class OpenAIClient implements ModelClient {
|
||||
|
||||
// Extended thinking/reasoning mode for o1/o3 models
|
||||
if (request.thinking) {
|
||||
(params as any).reasoning_effort = 'medium';
|
||||
(params as OpenAI.ChatCompletionCreateParamsNonStreaming & { reasoning_effort?: 'low' | 'medium' | 'high' }).reasoning_effort = 'medium';
|
||||
}
|
||||
|
||||
let response: OpenAI.ChatCompletion;
|
||||
|
||||
Reference in New Issue
Block a user