mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 18:14:51 +00:00
fix: droid转发增加runtimeAddon调试插件
This commit is contained in:
@@ -7,8 +7,10 @@ const apiKeyService = require('./apiKeyService')
|
||||
const redis = require('../models/redis')
|
||||
const { updateRateLimitCounters } = require('../utils/rateLimitHelper')
|
||||
const logger = require('../utils/logger')
|
||||
const runtimeAddon = require('../utils/runtimeAddon')
|
||||
|
||||
const SYSTEM_PROMPT = 'You are Droid, an AI software engineering agent built by Factory.'
|
||||
const RUNTIME_EVENT_FMT_PAYLOAD = 'fmtPayload'
|
||||
|
||||
/**
|
||||
* Droid API 转发服务
|
||||
@@ -246,11 +248,34 @@ class DroidRelayService {
|
||||
// 处理请求体(注入 system prompt 等)
|
||||
const streamRequested = !disableStreaming && this._isStreamRequested(normalizedRequestBody)
|
||||
|
||||
const processedBody = this._processRequestBody(normalizedRequestBody, normalizedEndpoint, {
|
||||
let processedBody = this._processRequestBody(normalizedRequestBody, normalizedEndpoint, {
|
||||
disableStreaming,
|
||||
streamRequested
|
||||
})
|
||||
|
||||
const extensionPayload = {
|
||||
body: processedBody,
|
||||
endpoint: normalizedEndpoint,
|
||||
rawRequest: normalizedRequestBody,
|
||||
originalRequest: requestBody
|
||||
}
|
||||
|
||||
const extensionResult = runtimeAddon.emitSync(RUNTIME_EVENT_FMT_PAYLOAD, extensionPayload)
|
||||
const resolvedPayload =
|
||||
extensionResult && typeof extensionResult === 'object' ? extensionResult : extensionPayload
|
||||
|
||||
if (resolvedPayload && typeof resolvedPayload === 'object') {
|
||||
if (resolvedPayload.abortResponse && typeof resolvedPayload.abortResponse === 'object') {
|
||||
return resolvedPayload.abortResponse
|
||||
}
|
||||
|
||||
if (resolvedPayload.body && typeof resolvedPayload.body === 'object') {
|
||||
processedBody = resolvedPayload.body
|
||||
} else if (resolvedPayload !== extensionPayload) {
|
||||
processedBody = resolvedPayload
|
||||
}
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
const isStreaming = streamRequested
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ class DroidScheduler {
|
||||
|
||||
if (filtered.length === 0) {
|
||||
throw new Error(
|
||||
`No available Droid accounts for endpoint ${normalizedEndpoint}${apiKeyData?.droidAccountId ? ' (respecting binding)' : ''}`
|
||||
`No available accounts for endpoint ${normalizedEndpoint}${apiKeyData?.droidAccountId ? ' (respecting binding)' : ''}`
|
||||
)
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ class DroidScheduler {
|
||||
|
||||
if (!selected) {
|
||||
throw new Error(
|
||||
`No schedulable Droid account available after sorting (${normalizedEndpoint})`
|
||||
`No schedulable account available after sorting (${normalizedEndpoint})`
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user