mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-11-30 19:21:36 +08:00
插件 API v1 的元数据校验、utils、moejs 执行层和任务钩子的结果解析搬到 嵌套模块 github.com/QuantumNous/new-api/pluginkit,按 pluginkit/vX.Y.Z 打标签发布,其他宿主可以直接引用同一份实现。 - pkg/jsplugin 只留注册表、路由和 CLI,现有导出名通过别名保留,行为不变 - 文档 v1.md、v1.d.ts、v1.schema.json 移到 pluginkit/,schema 和类型由模块内嵌 - 请求处理钩子新增宿主专有的 ctx.client、ctx.session,new-api 不提供 - 导出 MaxPluginKeyLength、NewAPIReservedKeys 和 CallPathJSONInto - CI、Makefile、Dockerfile 和 AGENTS.md 按 relaykit 的方式加上 pluginkit
79 lines
1.9 KiB
Go
79 lines
1.9 KiB
Go
package jsplugin
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/QuantumNous/new-api/constant"
|
|
"github.com/QuantumNous/new-api/logger"
|
|
"github.com/QuantumNous/new-api/pluginkit"
|
|
)
|
|
|
|
// reservedRouteNamespaces are host paths a plugin route may never enter:
|
|
// console pages, assets and the generic task routes. The other host
|
|
// namespaces, such as /api, follow the outer router's static routes and are
|
|
// decided at admission.
|
|
var reservedRouteNamespaces = []string{
|
|
"/assets",
|
|
"/setup",
|
|
"/v1/tasks",
|
|
"/console",
|
|
"/login",
|
|
"/forbidden",
|
|
"/sign-in",
|
|
"/sign-up",
|
|
"/forgot-password",
|
|
"/oauth",
|
|
"/otp",
|
|
"/register",
|
|
"/reset",
|
|
"/privacy-policy",
|
|
"/user-agreement",
|
|
"/about",
|
|
"/pricing",
|
|
"/rankings",
|
|
"/user",
|
|
"/401",
|
|
"/403",
|
|
"/404",
|
|
"/500",
|
|
"/503",
|
|
"/chat2link",
|
|
"/system-settings",
|
|
"/channels",
|
|
"/chat",
|
|
"/dashboard",
|
|
"/errors",
|
|
"/keys",
|
|
"/models",
|
|
"/playground",
|
|
"/profile",
|
|
"/redemption-codes",
|
|
"/request-processing",
|
|
"/security",
|
|
"/subscriptions",
|
|
"/system-info",
|
|
"/task-plugins",
|
|
"/usage-logs",
|
|
"/users",
|
|
"/wallet",
|
|
}
|
|
|
|
// The settings are read on every use, so values loaded from the environment
|
|
// after this runs still apply.
|
|
func init() {
|
|
pluginkit.Configure(pluginkit.Host{
|
|
MemoryLimit: func() int64 { return int64(max(constant.PluginMemoryLimitMB, 0)) << 20 },
|
|
MaxRequestBodyBytes: func() int { return constant.MaxRequestBodyMB << 20 },
|
|
MaxStreamEventBytes: func() int { return constant.StreamScannerMaxBufferMB << 20 },
|
|
ReservedRouteNamespaces: reservedRouteNamespaces,
|
|
ReservedKeys: []string{"api"},
|
|
Debug: logger.LogDebug,
|
|
})
|
|
}
|
|
|
|
// ReplayFixture compiles a plugin, admits its routes as the registry does, and
|
|
// runs every fixture case in declaration order (pluginkit.ReplayFixture).
|
|
func ReplayFixture(ctx context.Context, source string, data []byte) (FixtureReport, error) {
|
|
return pluginkit.ReplayFixtureWith(ctx, NewRegistry().Register, source, data)
|
|
}
|