relay

package
v1.0.0-rc.30 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2026 License: AGPL-3.0 Imports: 75 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlphaSearchHelper

func AlphaSearchHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *types.NewAPIError)

func ApplyChannelPin

func ApplyChannelPin(c *gin.Context, info *relaycommon.RelayInfo) *dto.TaskError

ApplyChannelPin copies plugin-declared origin-task facts from the prepare context onto RelayInfo and, when the resolved pin retries on the same channel, writes LockedChannel. ResolveOriginTask is unchanged.

func ApplyOriginTaskAffinity

func ApplyOriginTaskAffinity(c *gin.Context, info *relaycommon.RelayInfo) *dto.TaskError

ApplyOriginTaskAffinity is the compatibility name for ApplyChannelPin.

func AudioHelper

func AudioHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *types.NewAPIError)

func ClaudeHelper

func ClaudeHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *types.NewAPIError)

func EmbeddingHelper

func EmbeddingHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *types.NewAPIError)

func GeminiEmbeddingHandler

func GeminiEmbeddingHandler(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *types.NewAPIError)

func GeminiHelper

func GeminiHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *types.NewAPIError)

func GetAdaptor

func GetAdaptor(apiType int) channel.Adaptor

func GetTaskAdaptor

func GetTaskAdaptor(platform constant.TaskPlatform) channel.TaskAdaptor

func GetTaskPlatform

func GetTaskPlatform(c *gin.Context) constant.TaskPlatform

func ImageHelper

func ImageHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *types.NewAPIError)

func RelayMidjourneyImage

func RelayMidjourneyImage(c *gin.Context)

func RelayMidjourneyNotify

func RelayMidjourneyNotify(c *gin.Context) *dto.MidjourneyResponse

func RelayMidjourneySubmit

func RelayMidjourneySubmit(c *gin.Context, relayInfo *relaycommon.RelayInfo) *dto.MidjourneyResponse

func RelayMidjourneyTask

func RelayMidjourneyTask(c *gin.Context, relayMode int) *dto.MidjourneyResponse

func RelayMidjourneyTaskImageSeed

func RelayMidjourneyTaskImageSeed(c *gin.Context) *dto.MidjourneyResponse

func RelaySwapFace

func RelaySwapFace(c *gin.Context, info *relaycommon.RelayInfo) *dto.MidjourneyResponse

func RelayTaskFetch

func RelayTaskFetch(c *gin.Context, relayMode int) (taskResp *dto.TaskError)

func RerankHelper

func RerankHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *types.NewAPIError)

func ResolveOriginTask added in v0.11.0

func ResolveOriginTask(c *gin.Context, info *relaycommon.RelayInfo) *dto.TaskError

ResolveOriginTask 处理基于已有任务的提交(remix / continuation): 查找原始任务、从中提取模型名称、将渠道锁定到原始任务的渠道 (通过 info.LockedChannel,重试时复用同一渠道并轮换 key), 以及提取 OtherRatios(时长、分辨率)。 该函数在控制器的重试循环之前调用一次,其结果通过 info 字段和上下文持久化。

func ResolveTaskPluginForPlatform

func ResolveTaskPluginForPlatform(generation *pluginruntime.RoutingGeneration, platform constant.TaskPlatform) (*pluginruntime.LoadedPlugin, bool)

func ResponsesHelper

func ResponsesHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *types.NewAPIError)

func TaskModel2Dto

func TaskModel2Dto(task *model.Task) *dto.TaskDto

func TaskPlatformUnavailableError

func TaskPlatformUnavailableError(platform constant.TaskPlatform) (string, string)

TaskPlatformUnavailableError explains why no adaptor serves the platform: the task-plugin system is switched off, the resolved plugin is disabled, or the platform simply names nothing. The distinction is user-actionable, so it must survive into the client-facing message.

func TextHelper

func TextHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *types.NewAPIError)

func WssHelper

func WssHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *types.NewAPIError)

Types

type PluginProtocolLimits

type PluginProtocolLimits struct {
	MaxEventsPerTick      int
	MaxEventsBytes        int
	MaxEventBytes         int
	MaxEventDepth         int
	MaxStateBytes         int
	MaxStateDepth         int
	MaxOutputs            int
	MaxTotalOutputBytes   int
	MaxMessageBytes       int
	MaxMetadataValueBytes int
	MaxCodeBytes          int
}

PluginProtocolLimits bounds untrusted semantic output before it reaches the host-owned Responses state machine.

func DefaultPluginProtocolLimits

func DefaultPluginProtocolLimits() PluginProtocolLimits

type PluginResponsesMachine

type PluginResponsesMachine struct {
	// contains filtered or unexported fields
}

PluginResponsesMachine owns the Responses wire state for one durable task. It contains no IO and is intentionally independent of plugin runtimes.

func NewPluginResponsesMachine

func NewPluginResponsesMachine(taskID, model string, createdAt int64, limits PluginProtocolLimits) *PluginResponsesMachine

func (*PluginResponsesMachine) ApplyTick

ApplyTick maps bounded plugin semantics onto host-owned Responses events. taskStatus is the current durable DB status (for example, IN_PROGRESS, SUCCESS, or FAILURE).

func (*PluginResponsesMachine) CreatedEvent

func (*PluginResponsesMachine) FailureEvent

func (m *PluginResponsesMachine) FailureEvent(taskStatus ...string) (dto.PluginResponsesStreamEvent, error)

FailureEvent terminates an already-started stream after a host observation, hook, or validation failure. It never accepts a detail string, preventing upstream and plugin internals from reaching clients.

func (*PluginResponsesMachine) FailureResponse

func (m *PluginResponsesMachine) FailureResponse(taskStatus ...string) (*dto.PluginResponsesResponse, error)

FailureResponse returns a sanitized non-stream failure for host-side protocol errors.

func (*PluginResponsesMachine) FinalFromEvents

func (m *PluginResponsesMachine) FinalFromEvents(result ProtocolEventResult, taskStatus string) (map[string]any, error)

FinalFromEvents synthesizes the retrieval Response for stream-only plugins from one renderEvents call at terminal task status. Synthesis runs on a scratch machine so a hook failure leaves the receiver untouched and the caller's failure-envelope path (which requires an unstarted machine) stays valid.

func (*PluginResponsesMachine) FinalResponse

func (m *PluginResponsesMachine) FinalResponse(payload any, taskStatus string) (map[string]any, error)

FinalResponse validates a plugin-authored complete Responses object and overwrites every host-owned identity and lifecycle field. Unknown protocol fields are retained so the unreleased v1 Record contract can represent response features beyond output_text.

func (*PluginResponsesMachine) PendingResponse

func (m *PluginResponsesMachine) PendingResponse(taskStatus string) map[string]any

PendingResponse is the host-synthesized non-terminal Responses snapshot. Callers must pass a non-terminal task status; completed/failed/incomplete inputs are mapped to in_progress so the wire status stays queued|in_progress.

func (*PluginResponsesMachine) SetBackground

func (m *PluginResponsesMachine) SetBackground(background bool)

func (*PluginResponsesMachine) TimeoutEvent

func (m *PluginResponsesMachine) TimeoutEvent(taskStatus ...string) (dto.PluginResponsesStreamEvent, error)

func (*PluginResponsesMachine) TimeoutResponse

func (m *PluginResponsesMachine) TimeoutResponse(taskStatus ...string) (*dto.PluginResponsesResponse, error)

TimeoutResponse is the documented non-stream polling timeout shape. Unlike a live stream timeout, its top-level state remains queued so clients know to use retrieval_path rather than treating observation timeout as task failure.

type ProtocolEventResult

type ProtocolEventResult struct {
	Events []ProtocolSemanticEvent
	State  ProtocolState
	Done   bool
}

func DecodePluginProtocolEventResult

func DecodePluginProtocolEventResult(value any, limits PluginProtocolLimits) (ProtocolEventResult, error)

DecodePluginProtocolEventResult converts an exported JS value into the deliberately small semantic event contract. Unknown fields are rejected so plugins cannot smuggle protocol-owned wire fields into the response.

type ProtocolSemanticEvent

type ProtocolSemanticEvent struct {
	Type     string
	Progress *float64
	Message  *string
	Data     json.RawMessage
	Code     *string
}

type ProtocolState

type ProtocolState struct {
	Present bool
	Null    bool
	Value   json.RawMessage
}

ProtocolState distinguishes an omitted state property from an explicit JSON null. Value is always a validated, detached JSON value when Present is true.

func (ProtocolState) PluginValue

func (s ProtocolState) PluginValue() (any, error)

type TaskSubmitResult added in v0.11.0

type TaskSubmitResult struct {
	UpstreamTaskID string
	TaskData       []byte
	ClientResponse any
	Platform       constant.TaskPlatform
	Quota          int
	Immediate      *relaycommon.TaskInfo
}

func RelayTaskSubmit

func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (*TaskSubmitResult, *dto.TaskError)

RelayTaskSubmit 完成 task 提交的全部流程(每次尝试调用一次): 刷新渠道元数据 → 确定 platform/adaptor → 验证请求 → 估算计费(EstimateBilling) → 计算价格 → 预扣费(仅首次)→ 构建/发送/解析上游请求 → 提交后计费调整(AdjustBillingOnSubmit)。 共享控制器编排负责未落库退款、最终额度预留、落库和结算。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL