feat(jsplugin): run task plugins on moejs

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.
This commit is contained in:
CaIon committed 2026-09-30 17:24:19 +08:00
1 parent 335ebcff71
commit 2ffc595901
24 files changed
+1206 -611

No files matched your search

+6 -14
View File
@@ -527,13 +527,7 @@ func streamTaskPluginProtocol(
}
args := []any{rendererContext, viewValue}
if previous.Present {
previousValue, stateErr := previous.PluginValue()
if stateErr != nil {
logger.LogError(c, "decode task protocol state failed: "+stateErr.Error())
writeTaskPluginProtocolFailure(c, machine, lastStatus)
return
}
args = append(args, previousValue)
args = append(args, previous.PluginValue())
}
value, callErr := pinned.Plugin.Engine.CallPathWithAdmissionTimeout(observationContext, deps.admissionTimeout, "protocols", []string{pinned.Protocol, "renderEvents"}, args...)
hookElapsed := deps.now().Sub(hookStarted)
@@ -1166,16 +1160,14 @@ func writeTaskPluginProtocolTimeoutResponse(
c.JSON(http.StatusOK, response)
}
func taskPluginProtocolJSONValue(value any) (any, error) {
encoded, err := common.Marshal(value)
// taskPluginProtocolJSONValue encodes a task view for a hook, which receives
// it parsed from the text.
func taskPluginProtocolJSONValue(view dto.TaskView) (any, error) {
encoded, err := common.Marshal(view)
if err != nil {
return nil, err
}
var decoded any
if err = common.Unmarshal(encoded, &decoded); err != nil {
return nil, err
}
return decoded, nil
return pluginruntime.RawJSON(encoded), nil
}
func taskPluginProtocolRendererContext(