An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:recycle: Remove unused Go stream constructors https://github.com/siyuan-note/siyuan/issues/20235
Daniela340f15315f9
diff --git a/kernel/plugin/streams/doc.go b/kernel/plugin/streams/doc.goindex bc822f8e5b..bb91582d70 100644--- a/kernel/plugin/streams/doc.go+++ b/kernel/plugin/streams/doc.go@@ -23,10 +23,9 @@// Blob/FormData/AbortController 的既有写法一致:实例用 rt.NewDynamicObject 包装 Go 状态,方法与访问器// 定义在每个 Host 构造时新建的共享原型上,不依赖 goja 的结构体字段名反射映射。//-// Go 侧桥接(供 kernel/plugin 的 fetch 响应体、HTTP 服务流式响应等场景使用)见 Host.NewReadableStream/-// NewWritableStream/NewTransformStream:Go 驱动的数据源把 start/pull/write/close/cancel/abort 实现为普通-// Go 函数,返回值按与 JS 版本相同的方式经由 awaitResult 处理,真正跨线程的调度(开 goroutine 读取、通过-// 事件循环的 RunOnLoop 回到 VM 线程)由调用方自己完成,本包只提供"已经在 VM 线程内"可以安全调用的操作。+// Go 侧可读流桥接见 Host.NewReadableStream:数据源把 start/pull/cancel 实现为普通 Go 函数,返回值按与+// JS 版本相同的方式经由 awaitResult 处理。跨线程调度(开 goroutine 读取、通过事件循环的 RunOnLoop 回到+// VM 线程)由调用方完成,本包提供已在 VM 线程内可以安全调用的操作。可写流与转换流由插件脚本构造。//// # 参考//diff --git a/kernel/plugin/streams/promise.go b/kernel/plugin/streams/promise.goindex 17a62fa051..7a501a78c0 100644--- a/kernel/plugin/streams/promise.go+++ b/kernel/plugin/streams/promise.go@@ -97,11 +97,3 @@ func asPromise(value goja.Value) (*goja.Promise, bool) {p, ok := value.Export().(*goja.Promise)return p, ok}--// callOptional 调用可能为 nil 的 goja.Callable;fn 为 nil 时视为返回 undefined 的空操作,不调用 this/传参。-func callOptional(fn goja.Callable, this goja.Value, args ...goja.Value) (result goja.Value, err error) {- if fn == nil {- return goja.Undefined(), nil- }- return fn(this, args...)-}diff --git a/kernel/plugin/streams/transform.go b/kernel/plugin/streams/transform.goindex cb14651f09..040009b626 100644--- a/kernel/plugin/streams/transform.go+++ b/kernel/plugin/streams/transform.go@@ -266,13 +266,6 @@ func transformStreamDefaultSourcePullAlgorithm(stream *transformState) goja.Valureturn stream.backpressureChange.value(stream.host.rt)}-// setUpTransformStreamDefaultController 对应 SetUpTransformStreamDefaultController。-func setUpTransformStreamDefaultController(h *Host, stream *transformState,- transform func(chunk goja.Value) goja.Value, flush func() goja.Value, cancel func(reason goja.Value) goja.Value) {- controller := &transformController{host: h, stream: stream, transformAlgorithm: transform, flushAlgorithm: flush, cancelAlgorithm: cancel}- stream.controller = controller-}-// transformControllerDesiredSize 对应 controller.desiredSize:转发到 readable 侧 controller。func transformControllerDesiredSize(c *transformController) (float64, bool) {return readableControllerDesiredSize(c.stream.readable.controller)@@ -313,12 +306,3 @@ func transformControllerTerminate(h *Host, c *transformController) {readableControllerClose(h, stream.readable.controller)transformStreamErrorWritableAndUnblockWrite(h, stream, typeErrorf(h.rt, "TransformStream terminated"))}--// NewTransformStream 是 Go 侧构造默认 TransformStream 的入口,供 kernel/plugin 的 Go 桥接代码使用(如把编码/-// 压缩之类的转换实现为流)。transform/flush/cancel 对应规范同名算法,均可为 nil;transform 缺省时为恒等转换-// (直接把 chunk 原样 enqueue 到 readable 侧)。-func (h *Host) NewTransformStream(transform func(chunk, controller goja.Value) goja.Value, flush func(controller goja.Value) goja.Value,- cancel func(reason goja.Value) goja.Value, writableHWM, readableHWM float64,- writableSizeAlgorithm, readableSizeAlgorithm func(goja.Value) float64) *goja.Object {- return h.newTransformStreamObject(transform, flush, cancel, writableHWM, readableHWM, writableSizeAlgorithm, readableSizeAlgorithm, nil)-}diff --git a/kernel/plugin/streams/webidl.go b/kernel/plugin/streams/webidl.goindex 020bdcdf64..a16ab5b7d8 100644--- a/kernel/plugin/streams/webidl.go+++ b/kernel/plugin/streams/webidl.go@@ -97,14 +97,6 @@ func newInterfaceConstructor(rt *goja.Runtime, name string, length int, prototypreturn constructor}-// illegalConstructor 构造一个按 WebIDL 规范不可直接实例化的接口的构造函数:用 new 调用会抛出 TypeError,与-// kernel/plugin/abort 的 AbortSignal 构造函数一致(goja 以 ConstructorCall 签名注册的函数本就只能通过 new 调用)。-func illegalConstructor(rt *goja.Runtime, name string, prototype *goja.Object) *goja.Object {- return newInterfaceConstructor(rt, name, 0, prototype, func(goja.ConstructorCall) *goja.Object {- panic(rt.NewTypeError("Illegal constructor"))- })-}-// must 在 err 非 nil 时 panic;仅用于"失败说明调用方传参有编程错误"的内部断言场景(如重复定义同名属性),不用于// 可能来自脚本输入的失败路径。func must(err error) {diff --git a/kernel/plugin/streams/writable.go b/kernel/plugin/streams/writable.goindex bbb53443cf..9d8a5ad7ef 100644--- a/kernel/plugin/streams/writable.go+++ b/kernel/plugin/streams/writable.go@@ -196,21 +196,6 @@ func writableControllerGetChunkSize(h *Host, c *writableController, chunk goja.Vreturn c.sizeAlgorithm(chunk)}-// NewWritableStream 是 Go 侧构造默认 WritableStream 的入口,供 kernel/plugin 的 Go 桥接代码使用。start/write/-// close/abort 对应规范同名算法,均可为 nil(视为未提供);返回值可以是任意值或一个 Promise(经 awaitResult-// 等待)。sizeAlgorithm 为 nil 时使用默认的"每个 chunk 大小为 1"算法。调用方必须已经在 runtime 所在的事件-// 循环线程上。-func (h *Host) NewWritableStream(start, write func(arg goja.Value) goja.Value, close func() goja.Value,- abort func(reason goja.Value) goja.Value, highWaterMark float64, sizeAlgorithm func(goja.Value) float64) *goja.Object {- if sizeAlgorithm == nil {- sizeAlgorithm = defaultSizeAlgorithm- }- stream := &writableState{host: h, status: writableWritable}- object := h.newWritableStreamObject(stream)- setUpWritableStreamDefaultController(h, stream, orNoOp(start), orNoOp(write), close, orNoOp(abort), highWaterMark, sizeAlgorithm)- return object-}-// ──────────────────────────── WritableStreamDefaultController 内部算法 ────────────────────────────// setUpWritableStreamDefaultController 对应 SetUpWritableStreamDefaultController:本包不暴露 controller.signal