mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-06-23 13:15:54 +08:00
- Added `rpcPluginError` to encapsulate plugin errors with HTTP status codes. - Enhanced `decodeEnvelopeResult` to preserve and return detailed plugin errors with status codes. - Introduced `isPluginErrorEnvelope` to identify plugin error envelopes. - Updated plugin call logic in Unix and Windows loaders to differentiate plugin errors from system errors. - Added unit tests to verify error handling and status code preservation.
94 lines
3.5 KiB
Go
94 lines
3.5 KiB
Go
package pluginabi
|
|
|
|
import "encoding/json"
|
|
|
|
const (
|
|
// ABIVersion tracks the native C ABI shape (native plugin exports).
|
|
ABIVersion uint32 = 1
|
|
// SchemaVersion tracks the RPC JSON contract exchanged at plugin.register.
|
|
// Increment only for breaking RPC changes. New capabilities such as ModelRouter
|
|
// are gated by capability flags and method names while the version stays at 1.
|
|
SchemaVersion uint32 = 1
|
|
)
|
|
|
|
const (
|
|
MethodPluginRegister = "plugin.register"
|
|
MethodPluginReconfigure = "plugin.reconfigure"
|
|
MethodPluginShutdown = "plugin.shutdown"
|
|
|
|
MethodModelRegister = "model.register"
|
|
MethodModelStatic = "model.static"
|
|
MethodModelForAuth = "model.for_auth"
|
|
|
|
MethodAuthIdentifier = "auth.identifier"
|
|
MethodAuthParse = "auth.parse"
|
|
MethodAuthLoginStart = "auth.login.start"
|
|
MethodAuthLoginPoll = "auth.login.poll"
|
|
MethodAuthRefresh = "auth.refresh"
|
|
|
|
MethodFrontendAuthIdentifier = "frontend_auth.identifier"
|
|
MethodFrontendAuthAuthenticate = "frontend_auth.authenticate"
|
|
|
|
// MethodSchedulerPick asks a scheduler plugin to select an auth candidate.
|
|
MethodSchedulerPick = "scheduler.pick"
|
|
// MethodModelRoute asks a router plugin to select a plugin executor for a matching request.
|
|
MethodModelRoute = "model.route"
|
|
|
|
MethodExecutorIdentifier = "executor.identifier"
|
|
MethodExecutorExecute = "executor.execute"
|
|
MethodExecutorExecuteStream = "executor.execute_stream"
|
|
MethodExecutorCountTokens = "executor.count_tokens"
|
|
MethodExecutorHTTPRequest = "executor.http_request"
|
|
|
|
MethodRequestTranslate = "request.translate"
|
|
MethodRequestNormalize = "request.normalize"
|
|
MethodRequestInterceptBefore = "request.intercept_before"
|
|
MethodRequestInterceptAfter = "request.intercept_after"
|
|
|
|
MethodResponseTranslate = "response.translate"
|
|
MethodResponseNormalizeBefore = "response.normalize_before"
|
|
MethodResponseNormalizeAfter = "response.normalize_after"
|
|
MethodResponseInterceptAfter = "response.intercept_after"
|
|
MethodResponseInterceptStreamChunk = "response.intercept_stream_chunk"
|
|
|
|
MethodThinkingIdentifier = "thinking.identifier"
|
|
MethodThinkingApply = "thinking.apply"
|
|
|
|
MethodUsageHandle = "usage.handle"
|
|
|
|
MethodCommandLineRegister = "command_line.register"
|
|
MethodCommandLineExecute = "command_line.execute"
|
|
|
|
MethodManagementRegister = "management.register"
|
|
MethodManagementHandle = "management.handle"
|
|
|
|
MethodHostHTTPDo = "host.http.do"
|
|
MethodHostHTTPDoStream = "host.http.do_stream"
|
|
MethodHostHTTPStreamRead = "host.http.stream_read"
|
|
MethodHostHTTPStreamClose = "host.http.stream_close"
|
|
MethodHostModelExecute = "host.model.execute"
|
|
MethodHostModelExecuteStream = "host.model.execute_stream"
|
|
MethodHostModelStreamRead = "host.model.stream_read"
|
|
MethodHostModelStreamClose = "host.model.stream_close"
|
|
MethodHostStreamEmit = "host.stream.emit"
|
|
MethodHostStreamClose = "host.stream.close"
|
|
MethodHostLog = "host.log"
|
|
MethodHostAuthList = "host.auth.list"
|
|
MethodHostAuthGet = "host.auth.get"
|
|
MethodHostAuthGetRuntime = "host.auth.get_runtime"
|
|
MethodHostAuthSave = "host.auth.save"
|
|
)
|
|
|
|
type Envelope struct {
|
|
OK bool `json:"ok"`
|
|
Result json.RawMessage `json:"result,omitempty"`
|
|
Error *Error `json:"error,omitempty"`
|
|
}
|
|
|
|
type Error struct {
|
|
Code string `json:"code"`
|
|
Message string `json:"message"`
|
|
Retryable bool `json:"retryable,omitempty"`
|
|
HTTPStatus int `json:"http_status,omitempty"`
|
|
}
|