mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-10-28 16:46:57 +08:00
Task plugins now run on github.com/Calcium-Ion/moejs v0.1.0-alpha.3 instead of Sobek, and the host utils are ported to it. The plugin API is unchanged. Code compiled from strings is no longer allowed: eval and the Function constructors throw an EvalError. Hooks receive host values without defensive copies. The engine converts an object or array when the hook first reads it and never writes JavaScript changes back to the host value. Stored protocol state and task views are passed as raw JSON and parsed inside the runtime instead of being decoded into Go maps first. An idle runtime drops its references to the last call's arguments. Whether an optional hook is exported is decided once when the plugin loads, so checking for it no longer takes an execution slot. Usage validation returns the normalized facts in a new map instead of writing into the hook result, so a hook that returns the request body no longer changes it. The request descriptor is copied instead of being round-tripped through JSON.
26 lines
900 B
Go
26 lines
900 B
Go
package dto
|
|
|
|
type TaskPluginError struct {
|
|
Code string `json:"code"`
|
|
Message string `json:"message"`
|
|
HTTPStatus int `json:"httpStatus"`
|
|
Retryable bool `json:"retryable"`
|
|
}
|
|
|
|
// TaskView is the only persisted-task shape exposed to JavaScript plugins.
|
|
// It deliberately excludes ownership, channel, quota, properties, and private
|
|
// upstream identifiers. Fields are sorted by JSON name so the encoded view
|
|
// orders its keys as an encoded map does; hooks receive it parsed from that
|
|
// text.
|
|
type TaskView struct {
|
|
CreatedAt int64 `json:"created_at"`
|
|
Data any `json:"data,omitempty"`
|
|
FailReason string `json:"fail_reason"`
|
|
FinishedAt int64 `json:"finished_at,omitempty"`
|
|
Platform string `json:"platform"`
|
|
Progress string `json:"progress"`
|
|
Status string `json:"status"`
|
|
TaskID string `json:"task_id"`
|
|
UpdatedAt int64 `json:"updated_at,omitempty"`
|
|
}
|