mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-12-05 16:04:03 +00: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
52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
package jsplugin
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCloneMetaDeepCopiesSupports(t *testing.T) {
|
|
registry := NewRegistry()
|
|
_, err := registry.Register(protocolPluginSource(
|
|
"acme",
|
|
`["model"]`,
|
|
`[{name: "openai_responses", supports: ["stream", "sync", "background"]}]`,
|
|
responsesDecodeBoth,
|
|
), Options{})
|
|
require.NoError(t, err)
|
|
|
|
snapshot := registry.Snapshot()
|
|
require.Len(t, snapshot.Override, 1)
|
|
require.Len(t, snapshot.Override[0].Protocols, 1)
|
|
snapshot.Override[0].Protocols[0].Supports[0] = "mutated"
|
|
|
|
plugin, ok := registry.Get("acme")
|
|
require.True(t, ok)
|
|
assert.Equal(t, []string{"stream", "sync", "background"}, plugin.Meta.Protocols[0].Supports)
|
|
}
|
|
|
|
const responsesDecodeBoth = `export const protocols = {openai_responses: {
|
|
decodeRequest: function(ctx) { return ctx; },
|
|
renderEvents: function() { return {events: [], state: null, done: false}; },
|
|
renderFinal: function(ctx, task) { return task; }
|
|
}};`
|
|
|
|
func protocolPluginSource(key, models, protocols, exports string) string {
|
|
return fmt.Sprintf(`
|
|
export const meta = {
|
|
apiVersion: 1, key: %q, name: %q, version: "1.0.0",
|
|
author: {name: "Test"},
|
|
models: %s, fetchMode: "per_task",
|
|
protocols: %s,
|
|
};
|
|
export function buildSubmitRequest() { return {}; }
|
|
export function parseSubmitResponse() { return {}; }
|
|
export function buildQueryRequest() { return {}; }
|
|
export function parseTaskResult() { return {}; }
|
|
%s
|
|
`, key, key, models, protocols, exports)
|
|
}
|