From 60520ddb3bfd8e24cce792d0448859c8707721cc Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 28 Oct 2026 14:36:17 +0800 Subject: [PATCH] moejs: v0.1.0-alpha.11, at its new module path github.com/MoeForge/moejs Gateway middleware and agent plugins run on moejs. alpha.11 moves the module to github.com/MoeForge/moejs; every other API change since alpha.4 is an addition. What magpie gets: faster calls, loops, property lookups and JSON.parse, allocation-free await, a bytecode verifier, a correct default.pgo, and Intl / toLocaleString in plugin code. Checked against both tags' source: every name magpie uses (NewRuntime, Options, Compile, Link, Hook, Value, Arg, Undefined, NativeFunc, Referrer, the Promise results, Exception) has the same signature, and Options' defaults (shared frozen builtins, no timers) are unchanged. fetch, Streams, URL, node:fs and node:buffer live in the separate webapi and node packages, installed only on request; magpie installs neither, so a plugin still reaches no network or file. Intl's CLDR, Unicode, ICU and V8 material is compiled into every build, and moejs asks a program that includes it to carry sections 1 to 4 of its notices. THIRD_PARTY_NOTICES holds them verbatim. Release archives ship no LICENSE today either; that is not changed here. Doc and site links (docs/, site/public/docs/{,zh/,ja/}plugins.html) point at the new repo. Run on mote at this tree: gofmt; go build -trimpath -s -w (60,670,658 bytes on origin/main 58fb3a778, 62,329,250 now, +1.66MB); go vet of middleware, jsmod, agentplug for darwin, linux and windows; go test ./internal/middleware/... ./internal/jsmod/... ./internal/agentplug/... ok; go test -run 'Middleware|Strateg|OnUsage|JSPlugin|Agentplug|AgentPlug' ./internal/gateway ./internal/provider ./internal/plugin ./internal/gui ok. Not run: the full suite, the GUI suite, a real request through a middleware in a running gateway. --- THIRD_PARTY_NOTICES | 391 ++++++++++++++++++++++++++ docs/reference.md | 2 +- docs/subsystems/gateway-middleware.md | 2 +- go.mod | 2 +- go.sum | 4 +- internal/agentplug/agentplug.go | 2 +- internal/jsmod/jsmod.go | 2 +- internal/middleware/middleware.go | 2 +- internal/middleware/points.go | 2 +- internal/middleware/run.go | 2 +- site/public/docs/ja/plugins.html | 2 +- site/public/docs/plugins.html | 2 +- site/public/docs/zh/plugins.html | 2 +- 13 files changed, 404 insertions(+), 13 deletions(-) create mode 100644 THIRD_PARTY_NOTICES diff --git a/THIRD_PARTY_NOTICES b/THIRD_PARTY_NOTICES new file mode 100644 index 000000000..67db0dcc6 --- /dev/null +++ b/THIRD_PARTY_NOTICES @@ -0,0 +1,391 @@ +magpie third-party notices +========================== + +magpie is built with moejs (https://github.com/MoeForge/moejs, +Apache License 2.0), a JavaScript engine that runs gateway plugins. moejs +compiles the material below into every magpie binary, and its notices, +sections 1 to 4 of moejs's THIRD_PARTY_NOTICES at v0.1.0-alpha.11, +follow verbatim. + +------------------------------------------------------------------------ +1. Unicode CLDR 48.0 +------------------------------------------------------------------------ + +What: The Unicode Common Locale Data Repository: locale data such as + names, date, time and number patterns and symbols, plural rules, + time zone names, locale aliases, likely subtags and supplemental + data, as Intl uses them. +Upstream: Unicode CLDR 48.0, https://cldr.unicode.org/ + https://unicode.org/Public/cldr/48/cldr-common-48.zip + https://github.com/unicode-org/cldr, tag release-48 +License: Unicode License v3 (SPDX: Unicode-3.0) + +Files: + engine/intl_locale_tables.go generated by internal/gen/cldr from + engine/intl_date_tables.go CLDR 48.0 + engine/intl_number_tables.go + engine/intl_supp_tables.go + engine/intl_tz_tables.go generated by internal/gen/cldr from + CLDR 48.0 and tzdata 2026c (section 7) + engine/collate.go lists in the CLDR root collation order + engine/builtin_intl_locale_info.go CLDR's collation types + engine/testdata/intl_plurals.xml.gz + engine/testdata/intl_ordinals.xml.gz + CLDR's common/supplemental/plurals.xml + and ordinals.xml + engine/testdata/intl_date_node.json.gz + engine/testdata/intl_number_node.json.gz + engine/testdata/intl_tz_icu.json.gz + engine/testdata/langtag_icu.json.gz + engine/testdata/intl_probe.node.txt + expected outputs recorded from Node.js + 24 (ICU 78.3 with CLDR 48.0), which + contain CLDR data + +The text below is the LICENSE file of https://github.com/unicode-org/cldr at +tag release-48. + +UNICODE LICENSE V3 + +COPYRIGHT AND PERMISSION NOTICE + +Copyright © 2004-2025 Unicode, Inc. + +NOTICE TO USER: Carefully read the following legal agreement. BY +DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR +SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE +TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT +DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of data files and any associated documentation (the "Data Files") or +software and any associated documentation (the "Software") to deal in the +Data Files or Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, and/or sell +copies of the Data Files or Software, and to permit persons to whom the +Data Files or Software are furnished to do so, provided that either (a) +this copyright and permission notice appear with all copies of the Data +Files or Software, or (b) this copyright and permission notice appear in +associated Documentation. + +THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF +THIRD PARTY RIGHTS. + +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE +BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, +OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA +FILES OR SOFTWARE. + +Except as contained in this notice, the name of a copyright holder shall +not be used in advertising or otherwise to promote the sale, use or other +dealings in these Data Files or Software without prior written +authorization of the copyright holder. + +SPDX-License-Identifier: Unicode-3.0 + +------------------------------------------------------------------------ +2. Unicode Character Database and IDNA data, Unicode 17.0.0 +------------------------------------------------------------------------ + +What: Unicode character properties (general categories, scripts, + binary properties, case mappings and foldings, emoji data), + normalization and decomposition data, the UAX #29 segmentation + properties and break tests, the normalization test, and the + UTS #46 IDNA mapping table. +Upstream: The Unicode Standard 17.0.0, https://www.unicode.org/Public/17.0.0/ + (ucd/, ucd/auxiliary/, ucd/emoji/, ucd/extracted/, emoji/, idna/) +License: Unicode License v3 (SPDX: Unicode-3.0). The files say + "© 2025 Unicode®, Inc." and refer to + https://www.unicode.org/terms_of_use.html, which puts them under + the license below. + +Files: + internal/regexpsyntax/unicode_tables.go generated by internal/gen/ucd + engine/unicode_norm_tables.go generated by internal/gen/ucd -norm + engine/unicode_seg_tables.go generated by internal/gen/ucd -seg + engine/decomp_tables.go generated by internal/gen/decomp + webapi/internal/whatwgurl/idna_tables.go generated by internal/gen/idna + engine/testdata/grapheme_break_test.txt.gz + engine/testdata/word_break_test.txt.gz + engine/testdata/sentence_break_test.txt.gz + engine/testdata/normalization_test.txt.gz + GraphemeBreakTest.txt, WordBreakTest.txt, + SentenceBreakTest.txt and + NormalizationTest.txt, trimmed + webapi/internal/whatwgurl/testdata/IdnaTestV2.json.gz + webapi/internal/whatwgurl/testdata/IdnaTestV2-removed.json + web-platform-tests' conversion of + IdnaTestV2.txt (see also section 5) + +The text below is https://www.unicode.org/license.txt as published on +2026-10-24. + +UNICODE LICENSE V3 + +COPYRIGHT AND PERMISSION NOTICE + +Copyright © 1991-2026 Unicode, Inc. + +NOTICE TO USER: Carefully read the following legal agreement. BY +DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR +SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE +TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT +DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of data files and any associated documentation (the "Data Files") or +software and any associated documentation (the "Software") to deal in the +Data Files or Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, and/or sell +copies of the Data Files or Software, and to permit persons to whom the +Data Files or Software are furnished to do so, provided that either (a) +this copyright and permission notice appear with all copies of the Data +Files or Software, or (b) this copyright and permission notice appear in +associated Documentation. + +THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF +THIRD PARTY RIGHTS. + +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE +BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, +OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA +FILES OR SOFTWARE. + +Except as contained in this notice, the name of a copyright holder shall +not be used in advertising or otherwise to promote the sale, use or other +dealings in these Data Files or Software without prior written +authorization of the copyright holder. + +------------------------------------------------------------------------ +3. ICU 78.3 (ported code) +------------------------------------------------------------------------ + +What: International Components for Unicode. moejs ports parts of + ICU4C's date, time zone and number formatting to Go, so that Intl + formats as V8 with ICU does. +Upstream: ICU 78.3, https://icu.unicode.org/ + https://github.com/unicode-org/icu, tag release-78.3 +License: Unicode License v3 (SPDX: Unicode-3.0). Parts of the ported ICU + files are also "Copyright (C) 1997-2016, International Business + Machines Corporation and others" under the ICU License for ICU + 1.8.1 to ICU 57.1. + +Files: + engine/intl_date_pattern.go DateTimePatternGenerator (i18n/dtptngen.cpp) + engine/intl_date_range.go DateIntervalFormat and DateIntervalInfo + (i18n/dtitvfmt.cpp, dtitvinf.cpp) + engine/intl_date_format.go SimpleDateFormat (i18n/smpdtfmt.cpp) + engine/intl_tz.go TimeZoneFormat, TimeZoneNames and + TimeZoneGenericNames (i18n/tzfmt.cpp, + tznames_impl.cpp, tzgnames.cpp) + engine/intl_number_format.go the number formatter and + NumberRangeFormatter (i18n/number_*.cpp, + numrange_impl.cpp) + engine/intl_number_pattern.go number patterns + (i18n/number_patternstring.cpp, + number_affixutils.cpp, + number_patternmodifier.cpp) + engine/builtin_intl_datetimeformat.go + the style patterns of SimpleDateFormat + internal/gen/cldr/date.go ICU's reading of CLDR's calendar data + (DateFormatSymbols, DayPeriodRules) + internal/gen/cldr/tz.go ICU's reading of CLDR's time zone data + (getCanonicalCountry, getReferenceZoneID, + the offset patterns) and the spans in which + ICU's DST flag differs from tzdata's + engine/segment.go the word-like status of a segment, after + internal/gen/ucd/seg.go ICU's word break rules + (data/brkitr/rules/word.txt) + +The texts below are the first two parts of the LICENSE file of +https://github.com/unicode-org/icu at tag release-78.3: the Unicode License +v3 and the ICU License for ICU 1.8.1 to ICU 57.1. The rest of that file +covers third-party components of ICU (dictionaries, Google double-conversion, +build scripts and others) that moejs does not use. + +UNICODE LICENSE V3 + +COPYRIGHT AND PERMISSION NOTICE + +Copyright © 2016-2025 Unicode, Inc. + +NOTICE TO USER: Carefully read the following legal agreement. BY +DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR +SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE +TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT +DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of data files and any associated documentation (the "Data Files") or +software and any associated documentation (the "Software") to deal in the +Data Files or Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, and/or sell +copies of the Data Files or Software, and to permit persons to whom the +Data Files or Software are furnished to do so, provided that either (a) +this copyright and permission notice appear with all copies of the Data +Files or Software, or (b) this copyright and permission notice appear in +associated Documentation. + +THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF +THIRD PARTY RIGHTS. + +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE +BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, +OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA +FILES OR SOFTWARE. + +Except as contained in this notice, the name of a copyright holder shall +not be used in advertising or otherwise to promote the sale, use or other +dealings in these Data Files or Software without prior written +authorization of the copyright holder. + +SPDX-License-Identifier: Unicode-3.0 + +---------------------------------------------------------------------- + +ICU License - ICU 1.8.1 to ICU 57.1 + +COPYRIGHT AND PERMISSION NOTICE + +Copyright (c) 1995-2016 International Business Machines Corporation and others +All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, and/or sell copies of the Software, and to permit persons +to whom the Software is furnished to do so, provided that the above +copyright notice(s) and this permission notice appear in all copies of +the Software and that both the above copyright notice(s) and this +permission notice appear in supporting documentation. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY +SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER +RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF +CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +Except as contained in this notice, the name of a copyright holder +shall not be used in advertising or otherwise to promote the sale, use +or other dealings in this Software without prior written authorization +of the copyright holder. + +All trademarks and registered trademarks mentioned herein are the +property of their respective owners. + +------------------------------------------------------------------------ +4. V8 (ported code) +------------------------------------------------------------------------ + +What: Google's JavaScript engine. moejs ports V8's date string parser + and the code behind V8's stack traces and error messages, so that + Date.parse, Error.prototype.stack and TypeError messages match + Node.js. +Upstream: V8, https://v8.dev/ + https://chromium.googlesource.com/v8/v8 (mirror + https://github.com/v8/v8), branch-heads/13.6 (the V8 of Node.js 24) +License: BSD-3-Clause. The ported files carry "Copyright the V8 + project authors. All rights reserved.": 2011 for + src/date/dateparser* and src/execution/messages.cc, 2012 for + src/ast/prettyprinter.cc, 2018 for + src/objects/js-date-time-format.cc and 2019 for + src/objects/call-site-info.cc. + +Files: + engine/date_parse.go DateParser (src/date/dateparser.h, + dateparser-inl.h, dateparser.cc) + engine/interp_stack.go stack trace serialization + (src/objects/call-site-info.cc: + SerializeJSStackFrame, AppendMethodCall, + AppendFileLocation and the functions they + call) + engine/builtin_error.go Error.captureStackTrace + (ErrorUtils::CaptureStackTrace, + src/execution/messages.cc) + compiler/callee.go CallPrinter (src/ast/prettyprinter.cc) + engine/builtin_intl_datetimeformat.go + ReplaceSkeleton, HourCycleFromPattern and + ReplaceHourCycleInPattern + (src/objects/js-date-time-format.cc) + +The text below is the LICENSE file of V8 at branch-heads/13.6. + +This license applies to all parts of V8 that are not externally +maintained libraries. The externally maintained libraries used by V8 +are: + + - PCRE test suite, located in + test/mjsunit/third_party/regexp-pcre/regexp-pcre.js. This is based on the + test suite from PCRE-7.3, which is copyrighted by the University + of Cambridge and Google, Inc. The copyright notice and license + are embedded in regexp-pcre.js. + + - Layout tests, located in test/mjsunit/third_party/object-keys. These are + based on layout tests from webkit.org which are copyrighted by + Apple Computer, Inc. and released under a 3-clause BSD license. + + - Strongtalk assembler, the basis of the files assembler-arm-inl.h, + assembler-arm.cc, assembler-arm.h, assembler-ia32-inl.h, + assembler-ia32.cc, assembler-ia32.h, assembler-x64-inl.h, + assembler-x64.cc, assembler-x64.h, assembler.cc and assembler.h. + This code is copyrighted by Sun Microsystems Inc. and released + under a 3-clause BSD license. + + - Valgrind client API header, located at third_party/valgrind/valgrind.h + This is released under the BSD license. + + - The Wasm C/C++ API headers, located at third_party/wasm-api/wasm.{h,hh} + This is released under the Apache license. The API's upstream prototype + implementation also formed the basis of V8's implementation in + src/wasm/c-api.cc. + +These libraries have their own licenses; we recommend you read them, +as their terms may differ from the terms below. + +Further license information can be found in LICENSE files located in +sub-directories. + +Copyright 2014, the V8 project authors. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/docs/reference.md b/docs/reference.md index c513889fd..6ec9a036d 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -1076,7 +1076,7 @@ export function onEvent(ev, ctx) { } ``` -Middleware runs inside the gateway in [moejs](https://github.com/Calcium-Ion/moejs), +Middleware runs inside the gateway in [moejs](https://github.com/MoeForge/moejs), a JavaScript engine written in Go (about a microsecond a streamed event), not on Bun: no timers, `fetch` or Node APIs, and imports only of files beside it. A hook that throws or takes too long (250 ms a request, 50 ms an diff --git a/docs/subsystems/gateway-middleware.md b/docs/subsystems/gateway-middleware.md index 713870ab0..87fbb9b3f 100644 --- a/docs/subsystems/gateway-middleware.md +++ b/docs/subsystems/gateway-middleware.md @@ -1,6 +1,6 @@ # Gateway middleware -A plugin can be a JS gateway plugin: JavaScript that magpie runs inside its gateway on the requests agents send and the replies they get back (middleware), on the order a pool's accounts or keys are tried in (`strategies`), and on each usage row (`onUsage`), whatever provider serves them. It is separate from the provider plugins in [Provider and plugin ownership](provider-plugins.md), which run on Bun in the plugin host. Middleware runs in the gateway's own process on [moejs](https://github.com/Calcium-Ion/moejs), a JavaScript engine written in Go, because it sits on every request and every streamed event. +A plugin can be a JS gateway plugin: JavaScript that magpie runs inside its gateway on the requests agents send and the replies they get back (middleware), on the order a pool's accounts or keys are tried in (`strategies`), and on each usage row (`onUsage`), whatever provider serves them. It is separate from the provider plugins in [Provider and plugin ownership](provider-plugins.md), which run on Bun in the plugin host. Middleware runs in the gateway's own process on [moejs](https://github.com/MoeForge/moejs), a JavaScript engine written in Go, because it sits on every request and every streamed event. ## Responsibilities and sources of truth diff --git a/go.mod b/go.mod index 47912812e..c2d4adb5a 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/yetone/magpie go 1.26.8 require ( - github.com/Calcium-Ion/moejs v0.1.0-alpha.4 + github.com/MoeForge/moejs v0.1.0-alpha.11 github.com/charmbracelet/bubbles v0.21.1 github.com/charmbracelet/bubbletea v1.3.10 github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834 diff --git a/go.sum b/go.sum index 81a58133a..cc6b4dea9 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3 h1:N3IGoHHp9pb6mj1cbXbuaSXV/UMKwmbKLf53nQmtqMA= git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3/go.mod h1:QtOLZGz8olr4qH2vWK0QH0w0O4T9fEIjMuWpKUsH7nc= -github.com/Calcium-Ion/moejs v0.1.0-alpha.4 h1:SQOx8HsTzfW8fZgSnR3KQ5IPa49P0klo6pRGCsfYVC4= -github.com/Calcium-Ion/moejs v0.1.0-alpha.4/go.mod h1:9YqHj36EV7pzV/vlEYSw49f3oggeJFdmqcjM9TmDpHs= +github.com/MoeForge/moejs v0.1.0-alpha.11 h1:VVDuqn14Dzlhcs17gDp3X43uvKkxi7OK7SZvkd0moEc= +github.com/MoeForge/moejs v0.1.0-alpha.11/go.mod h1:YG2Y3bZuThN7hkSBext9MHPUPSrAIdpiE+6v+QO+LX0= github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78= github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ= github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= diff --git a/internal/agentplug/agentplug.go b/internal/agentplug/agentplug.go index 0e3a2ad8e..45fa8d711 100644 --- a/internal/agentplug/agentplug.go +++ b/internal/agentplug/agentplug.go @@ -49,7 +49,7 @@ import ( "sync/atomic" "time" - "github.com/Calcium-Ion/moejs" + "github.com/MoeForge/moejs" "github.com/yetone/magpie/internal/jsmod" "github.com/yetone/magpie/internal/plugin" ) diff --git a/internal/jsmod/jsmod.go b/internal/jsmod/jsmod.go index eea4e97df..f4fcf67ec 100644 --- a/internal/jsmod/jsmod.go +++ b/internal/jsmod/jsmod.go @@ -10,7 +10,7 @@ import ( "path/filepath" "strings" - "github.com/Calcium-Ion/moejs" + "github.com/MoeForge/moejs" ) // Compile compiles the module in file and the modules it imports, which diff --git a/internal/middleware/middleware.go b/internal/middleware/middleware.go index 2830edc81..3f6734b60 100644 --- a/internal/middleware/middleware.go +++ b/internal/middleware/middleware.go @@ -24,7 +24,7 @@ import ( "sync/atomic" "time" - "github.com/Calcium-Ion/moejs" + "github.com/MoeForge/moejs" "github.com/yetone/magpie/internal/filememo" "github.com/yetone/magpie/internal/jsmod" "github.com/yetone/magpie/internal/plugin" diff --git a/internal/middleware/points.go b/internal/middleware/points.go index d9e7b02a1..41b3dac49 100644 --- a/internal/middleware/points.go +++ b/internal/middleware/points.go @@ -33,7 +33,7 @@ import ( "sync/atomic" "time" - "github.com/Calcium-Ion/moejs" + "github.com/MoeForge/moejs" "github.com/yetone/magpie/internal/beat" "github.com/yetone/magpie/internal/filememo" diff --git a/internal/middleware/run.go b/internal/middleware/run.go index e923a09d4..6ef57b2ba 100644 --- a/internal/middleware/run.go +++ b/internal/middleware/run.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/Calcium-Ion/moejs" + "github.com/MoeForge/moejs" "github.com/yetone/magpie/internal/gwmw" ) diff --git a/site/public/docs/ja/plugins.html b/site/public/docs/ja/plugins.html index 0f209f0fc..f721b90d2 100644 --- a/site/public/docs/ja/plugins.html +++ b/site/public/docs/ja/plugins.html @@ -692,7 +692,7 @@ magpie plugin options model-map '{"mapping": {"fast": "deepseek/deepseek-chat"}}

オプション

ミドルウェアは設定を ctx.options から読みます。これは plugins.json のそのエントリの options です。プラグイン → インストール済み でミドルウェアの オプション ボタンを押すとその行で JSON として編集でき、magpie plugin options <名前> '<json>' でも設定できます(off で消去)。名前はパッケージ名、spec、短い名前のどれでもかまいません:@magpie-community/middleware-model-map なら model-map です。次のリクエストから反映されます。パッケージは package.json の "magpie": { "options": { … } } でオプションの例を示せます。未設定のときエディタはそれから始まりますが、保存するまでミドルウェアはオプションなしで動きます。

動き方

-

ミドルウェアは Bun では動きません。ゲートウェイ自身のプロセスの中で、Go で書かれた JavaScript エンジン moejs によって動きます。応答は数千のイベントとしてストリームされ、各イベントがミドルウェアの処理を待つからです。1 イベントでのフック呼び出しは約 1 マイクロ秒で済みますが、Bun との往復だと数十マイクロ秒かかります。各ミドルウェアのコンパイルは一度だけで、リクエストごとに専用のランタイムを使います。そのためリクエストは並行に処理され、同じリクエストのフック同士は ctx.state を共有します。

+

ミドルウェアは Bun では動きません。ゲートウェイ自身のプロセスの中で、Go で書かれた JavaScript エンジン moejs によって動きます。応答は数千のイベントとしてストリームされ、各イベントがミドルウェアの処理を待つからです。1 イベントでのフック呼び出しは約 1 マイクロ秒で済みますが、Bun との往復だと数十マイクロ秒かかります。各ミドルウェアのコンパイルは一度だけで、リクエストごとに専用のランタイムを使います。そのためリクエストは並行に処理され、同じリクエストのフック同士は ctx.state を共有します。