feat: 添加监控请求ID临时存储功能到各AI服务提供商
在各AI服务提供商的核心API方法中添加monitorRequestId临时存储逻辑,用于跟踪请求链路。当请求体中包含_monitorRequestId字段时,将其存储到配置对象中并从请求体中删除,避免干扰API调用。 修改涉及以下提供商: - Claude (claude-core.js, claude-kiro.js) - OpenAI (openai-core.js, openai-responses-core.js, iflow-core.js, codex-core.js, qwen-core.js) - Forward (forward-core.js) - Gemini (gemini-core.js, antigravity-core.js) 统一处理模式:检查请求体中的_monitorRequestId字段,存储到this.config._monitorRequestId,然后从请求体中删除该字段。
This commit is contained in:
parent
2c758db714
commit
de3f6a5f21
10 changed files with 104 additions and 0 deletions
|
|
@ -226,6 +226,12 @@ export class ClaudeApiService {
|
|||
* @returns {Promise<object>} Claude API response (Claude compatible format).
|
||||
*/
|
||||
async generateContent(model, requestBody) {
|
||||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
const response = await this.callApi('/messages', requestBody);
|
||||
return response;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1669,6 +1669,7 @@ async saveCredentialsToFile(filePath, newData) {
|
|||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
// 检查 token 是否即将过期,如果是则推送到刷新队列
|
||||
|
|
@ -2031,6 +2032,7 @@ async saveCredentialsToFile(filePath, newData) {
|
|||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
// 检查 token 是否即将过期,如果是则推送到刷新队列
|
||||
|
|
|
|||
|
|
@ -144,12 +144,24 @@ export class ForwardApiService {
|
|||
}
|
||||
|
||||
async generateContent(model, requestBody) {
|
||||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
// Transparently pass the endpoint if provided in requestBody, otherwise use default
|
||||
const endpoint = requestBody.endpoint || '';
|
||||
return this.callApi(endpoint, requestBody);
|
||||
}
|
||||
|
||||
async *generateContentStream(model, requestBody) {
|
||||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
const endpoint = requestBody.endpoint || '';
|
||||
yield* this.streamApi(endpoint, requestBody);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1305,6 +1305,12 @@ export class AntigravityApiService {
|
|||
async generateContent(model, requestBody) {
|
||||
logger.info(`[Antigravity Auth Token] Time until expiry: ${formatExpiryTime(this.authClient.credentials.expiry_date)}`);
|
||||
|
||||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
// 检查 token 是否即将过期,如果是则推送到刷新队列
|
||||
if (this.isExpiryDateNear()) {
|
||||
const poolManager = getProviderPoolManager();
|
||||
|
|
@ -1372,6 +1378,12 @@ export class AntigravityApiService {
|
|||
async * generateContentStream(model, requestBody) {
|
||||
logger.info(`[Antigravity Auth Token] Time until expiry: ${formatExpiryTime(this.authClient.credentials.expiry_date)}`);
|
||||
|
||||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
// 检查 token 是否即将过期,如果是则推送到刷新队列
|
||||
if (this.isExpiryDateNear()) {
|
||||
const poolManager = getProviderPoolManager();
|
||||
|
|
|
|||
|
|
@ -640,6 +640,12 @@ export class GeminiApiService {
|
|||
async generateContent(model, requestBody) {
|
||||
logger.info(`[Auth Token] Time until expiry: ${formatExpiryTime(this.authClient.credentials.expiry_date)}`);
|
||||
|
||||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
// 检查 token 是否即将过期,如果是则推送到刷新队列
|
||||
if (this.isExpiryDateNear()) {
|
||||
const poolManager = getProviderPoolManager();
|
||||
|
|
@ -665,6 +671,12 @@ export class GeminiApiService {
|
|||
async * generateContentStream(model, requestBody) {
|
||||
logger.info(`[Auth Token] Time until expiry: ${formatExpiryTime(this.authClient.credentials.expiry_date)}`);
|
||||
|
||||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
// 检查 token 是否即将过期,如果是则推送到刷新队列
|
||||
if (this.isExpiryDateNear()) {
|
||||
const poolManager = getProviderPoolManager();
|
||||
|
|
|
|||
|
|
@ -129,6 +129,12 @@ export class CodexApiService {
|
|||
await this.initialize();
|
||||
}
|
||||
|
||||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
// 检查 token 是否即将过期,如果是则推送到刷新队列
|
||||
if (this.isExpiryDateNear()) {
|
||||
const poolManager = getProviderPoolManager();
|
||||
|
|
@ -191,6 +197,12 @@ export class CodexApiService {
|
|||
await this.initialize();
|
||||
}
|
||||
|
||||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
// 检查 token 是否即将过期,如果是则推送到刷新队列
|
||||
if (this.isExpiryDateNear()) {
|
||||
const poolManager = getProviderPoolManager();
|
||||
|
|
|
|||
|
|
@ -997,6 +997,12 @@ export class IFlowApiService {
|
|||
if (!this.isInitialized) {
|
||||
await this.initialize();
|
||||
}
|
||||
|
||||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
// 检查 token 是否即将过期,如果是则推送到刷新队列
|
||||
if (this.isExpiryDateNear()) {
|
||||
|
|
@ -1019,6 +1025,12 @@ export class IFlowApiService {
|
|||
if (!this.isInitialized) {
|
||||
await this.initialize();
|
||||
}
|
||||
|
||||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
// 检查 token 是否即将过期,如果是则推送到刷新队列
|
||||
if (this.isExpiryDateNear()) {
|
||||
|
|
|
|||
|
|
@ -189,10 +189,22 @@ export class OpenAIApiService {
|
|||
}
|
||||
|
||||
async generateContent(model, requestBody) {
|
||||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
return this.callApi('/chat/completions', requestBody);
|
||||
}
|
||||
|
||||
async *generateContentStream(model, requestBody) {
|
||||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
yield* this.streamApi('/chat/completions', requestBody);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -157,10 +157,22 @@ export class OpenAIResponsesApiService {
|
|||
}
|
||||
|
||||
async generateContent(model, requestBody) {
|
||||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
return this.callApi('/responses', requestBody);
|
||||
}
|
||||
|
||||
async *generateContentStream(model, requestBody) {
|
||||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
yield* this.streamApi('/responses', requestBody);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -651,6 +651,12 @@ export class QwenApiService {
|
|||
}
|
||||
|
||||
async generateContent(model, requestBody) {
|
||||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
// 检查 token 是否即将过期,如果是则推送到刷新队列
|
||||
if (this.isExpiryDateNear()) {
|
||||
const poolManager = getProviderPoolManager();
|
||||
|
|
@ -666,6 +672,12 @@ export class QwenApiService {
|
|||
}
|
||||
|
||||
async *generateContentStream(model, requestBody) {
|
||||
// 临时存储 monitorRequestId
|
||||
if (requestBody._monitorRequestId) {
|
||||
this.config._monitorRequestId = requestBody._monitorRequestId;
|
||||
delete requestBody._monitorRequestId;
|
||||
}
|
||||
|
||||
// 检查 token 是否即将过期,如果是则推送到刷新队列
|
||||
if (this.isExpiryDateNear()) {
|
||||
const poolManager = getProviderPoolManager();
|
||||
|
|
|
|||
Loading…
Reference in a new issue