@dream_engine/server 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CodingWithBashir
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ {"fileNames":["../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2021.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2023.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2016.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.date.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.date.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.number.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2021.promise.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2021.string.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2021.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.array.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.error.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.object.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.string.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2023.array.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2023.collection.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2023.intl.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.decorators.d.ts","../../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../core/dist/errors.d.ts","../../core/dist/events.d.ts","../../core/dist/logger.d.ts","../../core/dist/redact.d.ts","../../core/dist/url.d.ts","../../core/dist/async.d.ts","../../core/dist/text.d.ts","../../core/dist/ids.d.ts","../../core/dist/schema.d.ts","../../core/dist/config.d.ts","../../core/dist/index.d.ts","../src/http.ts","../src/queue.ts","../src/util.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/compatibility/disposable.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/compatibility/indexable.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/compatibility/iterators.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/compatibility/index.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/globals.typedarray.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/buffer.buffer.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/globals.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/web-globals/abortcontroller.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/web-globals/domexception.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/web-globals/events.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/header.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/readable.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/file.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/fetch.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/formdata.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/connector.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/client.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/errors.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/dispatcher.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/global-dispatcher.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/global-origin.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/pool-stats.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/pool.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/handlers.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/balanced-pool.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/agent.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/mock-interceptor.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/mock-agent.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/mock-client.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/mock-pool.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/mock-errors.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/proxy-agent.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/env-http-proxy-agent.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/retry-handler.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/retry-agent.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/api.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/interceptors.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/util.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/cookies.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/patch.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/websocket.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/eventsource.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/filereader.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/diagnostics-channel.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/content-type.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/cache.d.ts","../../../node_modules/.pnpm/undici-types@6.21.0/node_modules/undici-types/index.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/web-globals/fetch.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/web-globals/navigator.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/web-globals/storage.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/web-globals/streams.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/assert.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/assert/strict.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/async_hooks.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/buffer.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/child_process.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/cluster.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/console.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/constants.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/crypto.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/dgram.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/diagnostics_channel.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/dns.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/dns/promises.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/domain.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/events.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/fs.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/fs/promises.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/http.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/http2.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/https.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/inspector.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/inspector.generated.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/module.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/net.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/os.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/path.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/perf_hooks.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/process.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/punycode.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/querystring.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/readline.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/readline/promises.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/repl.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/sea.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/sqlite.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/stream.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/stream/promises.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/stream/consumers.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/stream/web.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/string_decoder.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/test.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/timers.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/timers/promises.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/tls.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/trace_events.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/tty.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/url.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/util.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/v8.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/vm.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/wasi.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/worker_threads.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/zlib.d.ts","../../../node_modules/.pnpm/@types+node@22.20.7/node_modules/@types/node/index.d.ts","../../../node_modules/.pnpm/@types+ws@8.18.2/node_modules/@types/ws/index.d.mts","../src/ws.ts","../src/server.ts","../src/index.ts"],"fileIdsList":[[83,129,130,132,149,150],[83,131,132,149,150],[132,149,150],[83,132,137,149,150,167],[83,132,133,138,143,149,150,152,164,175],[83,132,133,134,143,149,150,152],[83,132,149,150],[78,79,80,83,132,149,150],[83,132,135,149,150,176],[83,132,136,137,144,149,150,153],[83,132,137,149,150,164,172],[83,132,138,140,143,149,150,152],[83,131,132,139,149,150],[83,132,140,141,149,150],[83,132,142,143,149,150],[83,131,132,143,149,150],[83,132,143,144,145,149,150,164,175],[83,132,143,144,145,149,150,159,164,167],[83,124,132,140,143,146,149,150,152,164,175],[83,132,143,144,146,147,149,150,152,164,172,175],[83,132,146,148,149,150,164,172,175],[81,82,83,84,85,86,87,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181],[83,132,143,149,150],[83,132,149,150,151,175],[83,132,140,143,149,150,152,164],[83,132,149,150,153],[83,132,149,150,154],[83,131,132,149,150,155],[83,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181],[83,132,149,150,157],[83,132,149,150,158],[83,132,143,149,150,159,160],[83,132,149,150,159,161,176,178],[83,132,144,149,150],[83,132,143,149,150,164,165,167],[83,132,149,150,166,167],[83,132,149,150,164,165],[83,132,149,150,167],[83,132,149,150,168],[83,129,132,149,150,164,169,175],[83,132,143,149,150,170,171],[83,132,149,150,170,171],[83,132,137,149,150,152,164,172],[83,132,149,150,173],[83,132,149,150,152,174],[83,132,146,149,150,158,175],[83,132,137,149,150,176],[83,132,149,150,164,177],[83,132,149,150,151,178],[83,132,149,150,179],[83,124,132,149,150],[83,124,132,143,145,149,150,155,164,167,175,177,178,180],[83,132,149,150,164,181],[83,132,143,146,148,149,150,152,164,172,175,181,182],[83,96,100,132,149,150,175],[83,96,132,149,150,164,175],[83,91,132,149,150],[83,93,96,132,149,150,172,175],[83,132,149,150,152,172],[83,132,149,150,182],[83,91,132,149,150,182],[83,93,96,132,149,150,152,175],[83,88,89,92,95,132,143,149,150,164,175],[83,96,103,132,149,150],[83,88,94,132,149,150],[83,96,117,118,132,149,150],[83,92,96,132,149,150,167,175,182],[83,117,132,149,150,182],[83,90,91,132,149,150,182],[83,96,132,149,150],[83,90,91,92,93,94,95,96,97,98,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,118,119,120,121,122,123,132,149,150],[83,96,111,132,149,150],[83,96,103,104,132,149,150],[83,94,96,104,105,132,149,150],[83,95,132,149,150],[83,88,91,96,132,149,150],[83,96,100,104,105,132,149,150],[83,100,132,149,150],[83,94,96,99,132,149,150,175],[83,88,93,96,103,132,149,150],[83,132,149,150,164],[83,91,96,117,132,149,150,180,182],[64,83,132,149,150],[72,83,132,149,150],[64,65,66,67,68,69,70,71,72,73,83,132,149,150],[74,83,132,137,146,149,150],[75,76,77,83,132,149,150,184,185],[74,83,132,149,150],[74,75,76,77,83,132,146,149,150,152,184],[83,132,149,150,152],[75,76,83,132,146,149,150,183]],"fileInfos":[{"version":"c430d44666289dae81f30fa7b2edebf186ecc91a2d4c71266ea6ae76388792e1","affectsGlobalScope":true,"impliedFormat":1},{"version":"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","impliedFormat":1},{"version":"3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","impliedFormat":1},{"version":"e44bb8bbac7f10ecc786703fe0a6a4b952189f908707980ba8f3c8975a760962","impliedFormat":1},{"version":"5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","impliedFormat":1},{"version":"68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","impliedFormat":1},{"version":"5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","impliedFormat":1},{"version":"feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","impliedFormat":1},{"version":"ee7bad0c15b58988daa84371e0b89d313b762ab83cb5b31b8a2d1162e8eb41c2","impliedFormat":1},{"version":"27bdc30a0e32783366a5abeda841bc22757c1797de8681bbe81fbc735eeb1c10","impliedFormat":1},{"version":"080941d9f9ff9307f7e27a83bcd888b7c8270716c39af943532438932ec1d0b9","affectsGlobalScope":true,"impliedFormat":1},{"version":"2e80ee7a49e8ac312cc11b77f1475804bee36b3b2bc896bead8b6e1266befb43","affectsGlobalScope":true,"impliedFormat":1},{"version":"c57796738e7f83dbc4b8e65132f11a377649c00dd3eee333f672b8f0a6bea671","affectsGlobalScope":true,"impliedFormat":1},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true,"impliedFormat":1},{"version":"515d0b7b9bea2e31ea4ec968e9edd2c39d3eebf4a2d5cbd04e88639819ae3b71","affectsGlobalScope":true,"impliedFormat":1},{"version":"0559b1f683ac7505ae451f9a96ce4c3c92bdc71411651ca6ddb0e88baaaad6a3","affectsGlobalScope":true,"impliedFormat":1},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true,"impliedFormat":1},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true,"impliedFormat":1},{"version":"fb0f136d372979348d59b3f5020b4cdb81b5504192b1cacff5d1fbba29378aa1","affectsGlobalScope":true,"impliedFormat":1},{"version":"d15bea3d62cbbdb9797079416b8ac375ae99162a7fba5de2c6c505446486ac0a","affectsGlobalScope":true,"impliedFormat":1},{"version":"68d18b664c9d32a7336a70235958b8997ebc1c3b8505f4f1ae2b7e7753b87618","affectsGlobalScope":true,"impliedFormat":1},{"version":"eb3d66c8327153d8fa7dd03f9c58d351107fe824c79e9b56b462935176cdf12a","affectsGlobalScope":true,"impliedFormat":1},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true,"impliedFormat":1},{"version":"69ab18c3b76cd9b1be3d188eaf8bba06112ebbe2f47f6c322b5105a6fbc45a2e","affectsGlobalScope":true,"impliedFormat":1},{"version":"a680117f487a4d2f30ea46f1b4b7f58bef1480456e18ba53ee85c2746eeca012","affectsGlobalScope":true,"impliedFormat":1},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true,"impliedFormat":1},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true,"impliedFormat":1},{"version":"954296b30da6d508a104a3a0b5d96b76495c709785c1d11610908e63481ee667","affectsGlobalScope":true,"impliedFormat":1},{"version":"ac9538681b19688c8eae65811b329d3744af679e0bdfa5d842d0e32524c73e1c","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a969edff4bd52585473d24995c5ef223f6652d6ef46193309b3921d65dd4376","affectsGlobalScope":true,"impliedFormat":1},{"version":"9e9fbd7030c440b33d021da145d3232984c8bb7916f277e8ffd3dc2e3eae2bdb","affectsGlobalScope":true,"impliedFormat":1},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true,"impliedFormat":1},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true,"impliedFormat":1},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true,"impliedFormat":1},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true,"impliedFormat":1},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true,"impliedFormat":1},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true,"impliedFormat":1},{"version":"74f7fa2d027d5b33eb0471c8e82a6c87216223181ec31247c357a3e8e2fddc5b","affectsGlobalScope":true,"impliedFormat":1},{"version":"d6d7ae4d1f1f3772e2a3cde568ed08991a8ae34a080ff1151af28b7f798e22ca","affectsGlobalScope":true,"impliedFormat":1},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true,"impliedFormat":1},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true,"impliedFormat":1},{"version":"52ada8e0b6e0482b728070b7639ee42e83a9b1c22d205992756fe020fd9f4a47","affectsGlobalScope":true,"impliedFormat":1},{"version":"3bdefe1bfd4d6dee0e26f928f93ccc128f1b64d5d501ff4a8cf3c6371200e5e6","affectsGlobalScope":true,"impliedFormat":1},{"version":"59fb2c069260b4ba00b5643b907ef5d5341b167e7d1dbf58dfd895658bda2867","affectsGlobalScope":true,"impliedFormat":1},{"version":"639e512c0dfc3fad96a84caad71b8834d66329a1f28dc95e3946c9b58176c73a","affectsGlobalScope":true,"impliedFormat":1},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true,"impliedFormat":1},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true,"impliedFormat":1},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true,"impliedFormat":1},{"version":"959d36cddf5e7d572a65045b876f2956c973a586da58e5d26cde519184fd9b8a","affectsGlobalScope":true,"impliedFormat":1},{"version":"965f36eae237dd74e6cca203a43e9ca801ce38824ead814728a2807b1910117d","affectsGlobalScope":true,"impliedFormat":1},{"version":"3925a6c820dcb1a06506c90b1577db1fdbf7705d65b62b99dce4be75c637e26b","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a3d63ef2b853447ec4f749d3f368ce642264246e02911fcb1590d8c161b8005","affectsGlobalScope":true,"impliedFormat":1},{"version":"8cdf8847677ac7d20486e54dd3fcf09eda95812ac8ace44b4418da1bbbab6eb8","affectsGlobalScope":true,"impliedFormat":1},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true,"impliedFormat":1},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true,"impliedFormat":1},{"version":"b4b67b1a91182421f5df999988c690f14d813b9850b40acd06ed44691f6727ad","affectsGlobalScope":true,"impliedFormat":1},{"version":"df83c2a6c73228b625b0beb6669c7ee2a09c914637e2d35170723ad49c0f5cd4","affectsGlobalScope":true,"impliedFormat":1},{"version":"436aaf437562f276ec2ddbee2f2cdedac7664c1e4c1d2c36839ddd582eeb3d0a","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e3c06ea092138bf9fa5e874a1fdbc9d54805d074bee1de31b99a11e2fec239d","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea","affectsGlobalScope":true,"impliedFormat":1},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true,"impliedFormat":1},{"version":"2cd394618cdb4d16e0edc972f2ea83ecdd4f3a3f87807eb787d4659bc0b3ce50","impliedFormat":99},{"version":"7c36b560a10efd5a07449c959ef482b06c82a1b940f86bd9017303a02959a84f","impliedFormat":99},{"version":"ab85dd6c839ffaf796c6d1eb9d005c7b6e19a1c9dd6194ac9e28899f09400f59","impliedFormat":99},{"version":"1709904caba5a0995e696d79b0a397ac008a5b94839fa220657dedcfef725219","impliedFormat":99},{"version":"dca02cdbfea21cc04242e29c1ffe6585346b995a36f85f36284110ca3a8692dd","impliedFormat":99},{"version":"99fa96241066465ffcb013cf5d4f7cf2506d901cad368f75169254d384885498","impliedFormat":99},{"version":"2982305a090c8721d65e3a6ac76e18d8ecc508d570c2f404d734e72171b4fe6e","impliedFormat":99},{"version":"4ce051f4e765562370d3eea0511d8f169f66648a2032fb1f006ea5367401646b","impliedFormat":99},{"version":"62f4e7012819e61f5bf8f0da46576876cc04a2ab3adb5c39de55f0e217123b81","impliedFormat":99},{"version":"0fe8f6548895a15bc3e43972c1b4f6b3bbc6e42c88ff737bae4c5ccf529dde77","impliedFormat":99},{"version":"1d14b2d995a2eb2cbbba52bd719b67a59599967dcee4157b7ef374133ae03569","impliedFormat":99},{"version":"7bfbc18a91ddba36b959950fe897bf276bf99c70fa878a3965788df66a3fdb17","signature":"975d85e3dccc6e6d101467cef5b95868fc046f421706d30bf883c35c547ebb6c","impliedFormat":99},{"version":"222379dc7d6fd1090d9db6568bc81f67c4cf188332e671f0de353f45fb959f9a","signature":"53b4843216f948d1d61c0576aed73c3c775bc4c97db3f9719f508863bc2727d2","impliedFormat":99},{"version":"82cd6cb98237f36a3252454f2d019405e880725a894d3dad6404356245be22be","signature":"c6736cf54fc9e26d9b89e866061b4d7fbcf132f7541ebdf0efb2020e868db75d","impliedFormat":99},{"version":"6c7176368037af28cb72f2392010fa1cef295d6d6744bca8cfb54985f3a18c3e","affectsGlobalScope":true,"impliedFormat":1},{"version":"ab41ef1f2cdafb8df48be20cd969d875602483859dc194e9c97c8a576892c052","affectsGlobalScope":true,"impliedFormat":1},{"version":"437e20f2ba32abaeb7985e0afe0002de1917bc74e949ba585e49feba65da6ca1","affectsGlobalScope":true,"impliedFormat":1},{"version":"21d819c173c0cf7cc3ce57c3276e77fd9a8a01d35a06ad87158781515c9a438a","impliedFormat":1},{"version":"98cffbf06d6bab333473c70a893770dbe990783904002c4f1a960447b4b53dca","affectsGlobalScope":true,"impliedFormat":1},{"version":"3af97acf03cc97de58a3a4bc91f8f616408099bc4233f6d0852e72a8ffb91ac9","affectsGlobalScope":true,"impliedFormat":1},{"version":"808069bba06b6768b62fd22429b53362e7af342da4a236ed2d2e1c89fcca3b4a","affectsGlobalScope":true,"impliedFormat":1},{"version":"1db0b7dca579049ca4193d034d835f6bfe73096c73663e5ef9a0b5779939f3d0","affectsGlobalScope":true,"impliedFormat":1},{"version":"9798340ffb0d067d69b1ae5b32faa17ab31b82466a3fc00d8f2f2df0c8554aaa","affectsGlobalScope":true,"impliedFormat":1},{"version":"f26b11d8d8e4b8028f1c7d618b22274c892e4b0ef5b3678a8ccbad85419aef43","affectsGlobalScope":true,"impliedFormat":1},{"version":"5929864ce17fba74232584d90cb721a89b7ad277220627cc97054ba15a98ea8f","impliedFormat":1},{"version":"763fe0f42b3d79b440a9b6e51e9ba3f3f91352469c1e4b3b67bfa4ff6352f3f4","impliedFormat":1},{"version":"25c8056edf4314820382a5fdb4bb7816999acdcb929c8f75e3f39473b87e85bc","impliedFormat":1},{"version":"c464d66b20788266e5353b48dc4aa6bc0dc4a707276df1e7152ab0c9ae21fad8","impliedFormat":1},{"version":"78d0d27c130d35c60b5e5566c9f1e5be77caf39804636bc1a40133919a949f21","impliedFormat":1},{"version":"c6fd2c5a395f2432786c9cb8deb870b9b0e8ff7e22c029954fabdd692bff6195","impliedFormat":1},{"version":"1d6e127068ea8e104a912e42fc0a110e2aa5a66a356a917a163e8cf9a65e4a75","impliedFormat":1},{"version":"5ded6427296cdf3b9542de4471d2aa8d3983671d4cac0f4bf9c637208d1ced43","impliedFormat":1},{"version":"7f182617db458e98fc18dfb272d40aa2fff3a353c44a89b2c0ccb3937709bfb5","impliedFormat":1},{"version":"cadc8aced301244057c4e7e73fbcae534b0f5b12a37b150d80e5a45aa4bebcbd","impliedFormat":1},{"version":"385aab901643aa54e1c36f5ef3107913b10d1b5bb8cbcd933d4263b80a0d7f20","impliedFormat":1},{"version":"9670d44354bab9d9982eca21945686b5c24a3f893db73c0dae0fd74217a4c219","impliedFormat":1},{"version":"0b8a9268adaf4da35e7fa830c8981cfa22adbbe5b3f6f5ab91f6658899e657a7","impliedFormat":1},{"version":"11396ed8a44c02ab9798b7dca436009f866e8dae3c9c25e8c1fbc396880bf1bb","impliedFormat":1},{"version":"ba7bc87d01492633cb5a0e5da8a4a42a1c86270e7b3d2dea5d156828a84e4882","impliedFormat":1},{"version":"4893a895ea92c85345017a04ed427cbd6a1710453338df26881a6019432febdd","impliedFormat":1},{"version":"c21dc52e277bcfc75fac0436ccb75c204f9e1b3fa5e12729670910639f27343e","impliedFormat":1},{"version":"13f6f39e12b1518c6650bbb220c8985999020fe0f21d818e28f512b7771d00f9","impliedFormat":1},{"version":"9b5369969f6e7175740bf51223112ff209f94ba43ecd3bb09eefff9fd675624a","impliedFormat":1},{"version":"4fe9e626e7164748e8769bbf74b538e09607f07ed17c2f20af8d680ee49fc1da","impliedFormat":1},{"version":"24515859bc0b836719105bb6cc3d68255042a9f02a6022b3187948b204946bd2","impliedFormat":1},{"version":"ea0148f897b45a76544ae179784c95af1bd6721b8610af9ffa467a518a086a43","impliedFormat":1},{"version":"24c6a117721e606c9984335f71711877293a9651e44f59f3d21c1ea0856f9cc9","impliedFormat":1},{"version":"dd3273ead9fbde62a72949c97dbec2247ea08e0c6952e701a483d74ef92d6a17","impliedFormat":1},{"version":"405822be75ad3e4d162e07439bac80c6bcc6dbae1929e179cf467ec0b9ee4e2e","impliedFormat":1},{"version":"0db18c6e78ea846316c012478888f33c11ffadab9efd1cc8bcc12daded7a60b6","impliedFormat":1},{"version":"e61be3f894b41b7baa1fbd6a66893f2579bfad01d208b4ff61daef21493ef0a8","impliedFormat":1},{"version":"bd0532fd6556073727d28da0edfd1736417a3f9f394877b6d5ef6ad88fba1d1a","impliedFormat":1},{"version":"89167d696a849fce5ca508032aabfe901c0868f833a8625d5a9c6e861ef935d2","impliedFormat":1},{"version":"615ba88d0128ed16bf83ef8ccbb6aff05c3ee2db1cc0f89ab50a4939bfc1943f","impliedFormat":1},{"version":"a4d551dbf8746780194d550c88f26cf937caf8d56f102969a110cfaed4b06656","impliedFormat":1},{"version":"8bd86b8e8f6a6aa6c49b71e14c4ffe1211a0e97c80f08d2c8cc98838006e4b88","impliedFormat":1},{"version":"317e63deeb21ac07f3992f5b50cdca8338f10acd4fbb7257ebf56735bf52ab00","impliedFormat":1},{"version":"4732aec92b20fb28c5fe9ad99521fb59974289ed1e45aecb282616202184064f","impliedFormat":1},{"version":"2e85db9e6fd73cfa3d7f28e0ab6b55417ea18931423bd47b409a96e4a169e8e6","impliedFormat":1},{"version":"c46e079fe54c76f95c67fb89081b3e399da2c7d109e7dca8e4b58d83e332e605","impliedFormat":1},{"version":"bf67d53d168abc1298888693338cb82854bdb2e69ef83f8a0092093c2d562107","impliedFormat":1},{"version":"b52476feb4a0cbcb25e5931b930fc73cb6643fb1a5060bf8a3dda0eeae5b4b68","affectsGlobalScope":true,"impliedFormat":1},{"version":"f9501cc13ce624c72b61f12b3963e84fad210fbdf0ffbc4590e08460a3f04eba","affectsGlobalScope":true,"impliedFormat":1},{"version":"e7721c4f69f93c91360c26a0a84ee885997d748237ef78ef665b153e622b36c1","affectsGlobalScope":true,"impliedFormat":1},{"version":"d97fb21da858fb18b8ae72c314e9743fd52f73ebe2764e12af1db32fc03f853f","affectsGlobalScope":true,"impliedFormat":1},{"version":"0fa06ada475b910e2106c98c68b10483dc8811d0c14a8a8dd36efb2672485b29","impliedFormat":1},{"version":"33e5e9aba62c3193d10d1d33ae1fa75c46a1171cf76fef750777377d53b0303f","impliedFormat":1},{"version":"2b06b93fd01bcd49d1a6bd1f9b65ddcae6480b9a86e9061634d6f8e354c1468f","impliedFormat":1},{"version":"6a0cd27e5dc2cfbe039e731cf879d12b0e2dded06d1b1dedad07f7712de0d7f4","affectsGlobalScope":true,"impliedFormat":1},{"version":"913be43dad2a40e500104700aa26cfb5c51a976114bedf19624de43fdae7474f","impliedFormat":1},{"version":"e60477649d6ad21542bd2dc7e3d9ff6853d0797ba9f689ba2f6653818999c264","impliedFormat":1},{"version":"c2510f124c0293ab80b1777c44d80f812b75612f297b9857406468c0f4dafe29","affectsGlobalScope":true,"impliedFormat":1},{"version":"5524481e56c48ff486f42926778c0a3cce1cc85dc46683b92b1271865bcf015a","impliedFormat":1},{"version":"4c829ab315f57c5442c6667b53769975acbf92003a66aef19bce151987675bd1","affectsGlobalScope":true,"impliedFormat":1},{"version":"b2ade7657e2db96d18315694789eff2ddd3d8aea7215b181f8a0b303277cc579","impliedFormat":1},{"version":"78dbea00e90d2df8ea3dbef0cc379d95b8be9b71cd6bde4c28728f306811803b","impliedFormat":1},{"version":"4d631b81fa2f07a0e63a9a143d6a82c25c5f051298651a9b69176ba28930756d","impliedFormat":1},{"version":"836a356aae992ff3c28a0212e3eabcb76dd4b0cc06bcb9607aeef560661b860d","impliedFormat":1},{"version":"1e0d1f8b0adfa0b0330e028c7941b5a98c08b600efe7f14d2d2a00854fb2f393","impliedFormat":1},{"version":"41670ee38943d9cbb4924e436f56fc19ee94232bc96108562de1a734af20dc2c","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e1e46d0a9837ee058c100501080c920fa98081ea3956af0374308ba6f22a33e","impliedFormat":1},{"version":"272ca407e0c9068bdc5152552d876e68037ceae3de62e529306403e973dec8e1","impliedFormat":1},{"version":"fa7834c715d5357e4540cee40ce96c3250ddb67a7b879a6b7fa0e86d6696f121","impliedFormat":1},{"version":"22dfb07a7ab15b66ac043829056fe70124844636ae719551812ac631ba04985b","impliedFormat":1},{"version":"a10f0e1854f3316d7ee437b79649e5a6ae3ae14ffe6322b02d4987071a95362e","impliedFormat":1},{"version":"e208f73ef6a980104304b0d2ca5f6bf1b85de6009d2c7e404028b875020fa8f2","impliedFormat":1},{"version":"d163b6bc2372b4f07260747cbc6c0a6405ab3fbcea3852305e98ac43ca59f5bc","impliedFormat":1},{"version":"e6fa9ad47c5f71ff733744a029d1dc472c618de53804eae08ffc243b936f87ff","affectsGlobalScope":true,"impliedFormat":1},{"version":"a6f137d651076822d4fe884287e68fd61785a0d3d1fdb250a5059b691fa897db","impliedFormat":1},{"version":"24826ed94a78d5c64bd857570fdbd96229ad41b5cb654c08d75a9845e3ab7dde","impliedFormat":1},{"version":"8b479a130ccb62e98f11f136d3ac80f2984fdc07616516d29881f3061f2dd472","impliedFormat":1},{"version":"928af3d90454bf656a52a48679f199f64c1435247d6189d1caf4c68f2eaf921f","affectsGlobalScope":true,"impliedFormat":1},{"version":"e7fcccb7463007c1a6e877709650c26cd297ef1b2679d0173157ee874bf16517","affectsGlobalScope":true,"impliedFormat":1},{"version":"3f16a7e4deafa527ed9995a772bb380eb7d3c2c0fd4ae178c5263ed18394db2c","impliedFormat":1},{"version":"933921f0bb0ec12ef45d1062a1fc0f27635318f4d294e4d99de9a5493e618ca2","impliedFormat":1},{"version":"71a0f3ad612c123b57239a7749770017ecfe6b66411488000aba83e4546fde25","impliedFormat":1},{"version":"77fbe5eecb6fac4b6242bbf6eebfc43e98ce5ccba8fa44e0ef6a95c945ff4d98","impliedFormat":1},{"version":"4f9d8ca0c417b67b69eeb54c7ca1bedd7b56034bb9bfd27c5d4f3bc4692daca7","impliedFormat":1},{"version":"0cb167c371eaa8c869f8a7656a7296f2e4fae43b4d8b803a680236b24794e5f9","impliedFormat":1},{"version":"0a839dba0287cc0481ad4beedd48a1c64acf1e212ae865d1315f7007ca215161","impliedFormat":1},{"version":"38dc4655376cd1a4bd6bb3763d92949233e33d38d3dd3cbea7bbf218175a38ef","impliedFormat":1},{"version":"37ba7b45141a45ce6e80e66f2a96c8a5ab1bcef0fc2d0f56bb58df96ec67e972","impliedFormat":1},{"version":"45650f47bfb376c8a8ed39d4bcda5902ab899a3150029684ee4c10676d9fbaee","impliedFormat":1},{"version":"208a6a0bfb227bdf8fb964799d0a206c75cf03ccd72e63bf5495c9331354c6d6","affectsGlobalScope":true,"impliedFormat":1},{"version":"18fd40412d102c5564136f29735e5d1c3b455b8a37f920da79561f1fde068208","impliedFormat":1},{"version":"48a679952eefe4cb776d5a0e1ccba2d3eb53b57448bbb7abc1fcebcbd5440188","impliedFormat":1},{"version":"f0be1b8078cd549d91f37c30c222c2a187ac1cf981d994fb476a1adc61387b14","affectsGlobalScope":true,"impliedFormat":1},{"version":"0aaed1d72199b01234152f7a60046bc947f1f37d78d182e9ae09c4289e06a592","impliedFormat":1},{"version":"2d14da6ecb49bf828d83948765ec2d3a579d476bbb9645e749610baa6ec880ca","impliedFormat":1},{"version":"66ba1b2c3e3a3644a1011cd530fb444a96b1b2dfe2f5e837a002d41a1a799e60","impliedFormat":1},{"version":"7e514f5b852fdbc166b539fdd1f4e9114f29911592a5eb10a94bb3a13ccac3c4","impliedFormat":1},{"version":"5b7aa3c4c1a5d81b411e8cb302b45507fea9358d3569196b27eb1a27ae3a90ef","affectsGlobalScope":true,"impliedFormat":1},{"version":"33f03c0429f2c638069fc1186e2eccd96370c91fb9d8d7a69c5241bb31fc3d46","affectsGlobalScope":true,"impliedFormat":1},{"version":"ea08a0345023ade2b47fbff5a76d0d0ed8bff10bc9d22b83f40858a8e941501c","impliedFormat":1},{"version":"0aef708fb4c7a6b915e8305cbfac40cd207b032dbaabe9a01889a5fff3254681","impliedFormat":1},{"version":"ae062ce7d9510060c5d7e7952ae379224fb3f8f2dd74e88959878af2057c143b","impliedFormat":1},{"version":"ad9bdafb4e7abf14cc53ce7970486a84c87831e62891e5dfe798ddcd55e84701","affectsGlobalScope":true,"impliedFormat":1},{"version":"45479f65af737a3e5c26d8772bd8ab1aa8bebbd09c1a808c2b3faddb9b84afbb","impliedFormat":1},{"version":"71d3ae6a5e73ca4130762560425e00984ebaff64d5353a3333d1bb7eb86ef336","impliedFormat":1},{"version":"41b2a25018200d1deef82999c2f44a23bd4b8618aa788fff90292ce25366fa68","impliedFormat":99},{"version":"2286c190b214eab14e288551bc92b68364a39c34575fc4785f2ec04ef517d1ee","signature":"0f1fc3726ef5342c86b7f5fd2295d0ba09986e031d161980bbbbfffe5de0e4fc","impliedFormat":99},{"version":"6bd0e7f727c3f5bf464ef519aa45aecd30277195466d7cf5f94dbb1b615fd4d2","signature":"555d71ec9c15fa313a5031a6bbc564cc0b3176b4e0b4c8476b46cd25be40806b","impliedFormat":99},{"version":"e6e3f1c288ffd7ef7d65fa0f7b6dc1ee4d0d50c670cf922157fffbb997f5accb","impliedFormat":99}],"root":[[75,77],[184,186]],"options":{"composite":true,"declaration":true,"declarationMap":true,"esModuleInterop":true,"exactOptionalPropertyTypes":false,"module":199,"noFallthroughCasesInSwitch":true,"noImplicitOverride":true,"noUncheckedIndexedAccess":true,"outDir":"./","rootDir":"../src","skipLibCheck":true,"sourceMap":true,"strict":true,"target":9,"tsBuildInfoFile":"./.tsbuildinfo","verbatimModuleSyntax":true},"referencedMap":[[129,1],[130,1],[131,2],[83,3],[132,4],[133,5],[134,6],[78,7],[81,8],[79,7],[80,7],[135,9],[136,10],[137,11],[138,12],[139,13],[140,14],[141,14],[142,15],[143,16],[144,17],[145,18],[84,7],[82,7],[146,19],[147,20],[148,21],[182,22],[149,23],[150,7],[151,24],[152,25],[153,26],[154,27],[155,28],[156,29],[157,30],[158,31],[159,32],[160,32],[161,33],[162,7],[163,34],[164,35],[166,36],[165,37],[167,38],[168,39],[169,40],[170,41],[171,42],[172,43],[173,44],[174,45],[175,46],[176,47],[177,48],[178,49],[179,50],[85,7],[86,7],[87,7],[125,51],[126,7],[127,7],[128,38],[180,52],[181,53],[183,54],[62,7],[63,7],[11,7],[12,7],[14,7],[13,7],[2,7],[15,7],[16,7],[17,7],[18,7],[19,7],[20,7],[21,7],[22,7],[3,7],[23,7],[24,7],[4,7],[25,7],[29,7],[26,7],[27,7],[28,7],[30,7],[31,7],[32,7],[5,7],[33,7],[34,7],[35,7],[36,7],[6,7],[40,7],[37,7],[38,7],[39,7],[41,7],[7,7],[42,7],[47,7],[48,7],[43,7],[44,7],[45,7],[46,7],[8,7],[52,7],[49,7],[50,7],[51,7],[53,7],[9,7],[54,7],[55,7],[56,7],[58,7],[57,7],[59,7],[60,7],[10,7],[61,7],[1,7],[103,55],[113,56],[102,55],[123,57],[94,58],[93,59],[122,60],[116,61],[121,62],[96,63],[110,64],[95,65],[119,66],[91,67],[90,60],[120,68],[92,69],[97,70],[98,7],[101,70],[88,7],[124,71],[114,72],[105,73],[106,74],[108,75],[104,76],[107,77],[117,60],[99,78],[100,79],[109,80],[89,81],[112,72],[111,70],[115,7],[118,82],[69,83],[73,84],[64,7],[65,7],[71,7],[74,85],[66,7],[67,7],[72,7],[70,7],[68,7],[75,86],[186,87],[76,88],[185,89],[77,90],[184,91]],"latestChangedDtsFile":"./index.d.ts","version":"5.9.3"}
package/dist/http.d.ts ADDED
@@ -0,0 +1,47 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ import { type BashirWebError, type ErrorCode } from '@dream_engine/core';
3
+ export declare const STATUS_BY_CODE: Record<ErrorCode, number>;
4
+ export declare function statusFor(error: BashirWebError): number;
5
+ /** Reads a JSON body with a size limit. */
6
+ export declare function readJson(req: IncomingMessage, limit?: number): Promise<unknown>;
7
+ export declare function sendJson(res: ServerResponse, status: number, body: unknown, headers?: Record<string, string>): void;
8
+ /** Constant-time token check. Returns the owner id (hash prefix) of the matching token, or null. */
9
+ export declare function authenticate(header: string | undefined, tokens: string[]): string | null;
10
+ /** Sliding-window rate limiter keyed by caller. */
11
+ export declare class RateLimiter {
12
+ private readonly windowMs;
13
+ private readonly max;
14
+ private readonly hits;
15
+ constructor(windowMs: number, max: number);
16
+ check(key: string, now?: number): {
17
+ allowed: boolean;
18
+ remaining: number;
19
+ resetMs: number;
20
+ };
21
+ }
22
+ export interface Route {
23
+ method: string;
24
+ pattern: RegExp;
25
+ keys: string[];
26
+ auth: boolean;
27
+ handler: (ctx: RequestContext) => Promise<unknown>;
28
+ /** Status for successful responses (default 200). */
29
+ status?: number;
30
+ }
31
+ export interface RequestContext {
32
+ req: IncomingMessage;
33
+ params: Record<string, string>;
34
+ query: URLSearchParams;
35
+ body: unknown;
36
+ owner: string;
37
+ /** True when a valid token was presented, or when the server runs without tokens (loopback only). */
38
+ authenticated: boolean;
39
+ signal: AbortSignal;
40
+ requestId: string;
41
+ }
42
+ /** Compiles `/v1/sessions/:id` style paths. */
43
+ export declare function route(method: string, path: string, handler: Route['handler'], options?: {
44
+ auth?: boolean;
45
+ status?: number;
46
+ }): Route;
47
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,W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AAC;IACnD,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,eAAe,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,KAAK,EAAE,eAAe,CAAC;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,qGAAqG;IACrG,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,EAAE,WAAW,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,+CAA+C;AAC/C,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,KAAK,CAIvI"}
package/dist/http.js ADDED
@@ -0,0 +1,105 @@
1
+ import { createHash, timingSafeEqual } from 'node:crypto';
2
+ import { ValidationError } from '@dream_engine/core';
3
+ export const STATUS_BY_CODE = {
4
+ VALIDATION: 400,
5
+ CONFIGURATION: 400,
6
+ SESSION: 404,
7
+ ELEMENT_NOT_FOUND: 422,
8
+ AMBIGUOUS_ELEMENT: 409,
9
+ INTERACTION: 422,
10
+ APPROVAL_REQUIRED: 403,
11
+ SECURITY: 403,
12
+ TIMEOUT: 504,
13
+ NAVIGATION: 502,
14
+ BROWSER_LAUNCH: 503,
15
+ BROWSER_CONNECTION: 503,
16
+ SEARCH: 502,
17
+ CRAWL: 502,
18
+ EXTRACTION: 500,
19
+ WORKFLOW: 422,
20
+ CANCELLED: 409,
21
+ RUNTIME: 500,
22
+ ASSERT: 422,
23
+ TEST: 500,
24
+ };
25
+ export function statusFor(error) {
26
+ if (error.code === 'RUNTIME' && /quota|rate limit/i.test(error.message))
27
+ return 429;
28
+ if (error.code === 'RUNTIME' && /not found/i.test(error.message))
29
+ return 404;
30
+ return STATUS_BY_CODE[error.code] ?? 500;
31
+ }
32
+ /** Reads a JSON body with a size limit. */
33
+ export async function readJson(req, limit = 1024 * 1024) {
34
+ const chunks = [];
35
+ let size = 0;
36
+ for await (const chunk of req) {
37
+ size += chunk.length;
38
+ if (size > limit)
39
+ throw new ValidationError(`Request body exceeds ${limit} bytes`);
40
+ chunks.push(chunk);
41
+ }
42
+ if (size === 0)
43
+ return {};
44
+ const ct = req.headers['content-type'] ?? '';
45
+ if (!ct.includes('application/json'))
46
+ throw new ValidationError('Content-Type must be application/json');
47
+ try {
48
+ return JSON.parse(Buffer.concat(chunks).toString('utf8'));
49
+ }
50
+ catch {
51
+ throw new ValidationError('Request body is not valid JSON');
52
+ }
53
+ }
54
+ export function sendJson(res, status, body, headers = {}) {
55
+ const payload = JSON.stringify(body);
56
+ res.writeHead(status, {
57
+ 'content-type': 'application/json; charset=utf-8',
58
+ 'content-length': Buffer.byteLength(payload),
59
+ 'cache-control': 'no-store',
60
+ 'x-content-type-options': 'nosniff',
61
+ ...headers,
62
+ });
63
+ res.end(payload);
64
+ }
65
+ /** Constant-time token check. Returns the owner id (hash prefix) of the matching token, or null. */
66
+ export function authenticate(header, tokens) {
67
+ if (!header?.startsWith('Bearer '))
68
+ return null;
69
+ const given = createHash('sha256').update(header.slice(7).trim()).digest();
70
+ for (const t of tokens) {
71
+ const expected = createHash('sha256').update(t).digest();
72
+ if (timingSafeEqual(given, expected))
73
+ return `tok_${expected.toString('hex').slice(0, 16)}`;
74
+ }
75
+ return null;
76
+ }
77
+ /** Sliding-window rate limiter keyed by caller. */
78
+ export class RateLimiter {
79
+ windowMs;
80
+ max;
81
+ hits = new Map();
82
+ constructor(windowMs, max) {
83
+ this.windowMs = windowMs;
84
+ this.max = max;
85
+ }
86
+ check(key, now = Date.now()) {
87
+ const list = (this.hits.get(key) ?? []).filter((t) => now - t < this.windowMs);
88
+ const allowed = list.length < this.max;
89
+ if (allowed)
90
+ list.push(now);
91
+ this.hits.set(key, list);
92
+ if (this.hits.size > 10_000)
93
+ for (const [k, v] of this.hits)
94
+ if (!v.some((t) => now - t < this.windowMs))
95
+ this.hits.delete(k);
96
+ return { allowed, remaining: Math.max(0, this.max - list.length), resetMs: list.length ? this.windowMs - (now - list[0]) : 0 };
97
+ }
98
+ }
99
+ /** Compiles `/v1/sessions/:id` style paths. */
100
+ export function route(method, path, handler, options = {}) {
101
+ const keys = [];
102
+ const pattern = new RegExp(`^${path.replace(/:([a-zA-Z]+)/g, (_, k) => (keys.push(k), '([^/]+)'))}$`);
103
+ return { method, pattern, keys, handler, auth: options.auth ?? true, ...(options.status ? { status: options.status } : {}) };
104
+ }
105
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,EAAE,eAAe,EAAuC,MAAM,oBAAoB,CAAC;AAE1F,MAAM,CAAC,MAAM,cAAc,GAA8B;IACvD,UAAU,EAAE,GAAG;IACf,aAAa,EAAE,GAAG;IAClB,OAAO,EAAE,GAAG;IACZ,iBAAiB,EAAE,GAAG;IACtB,iBAAiB,EAAE,GAAG;IACtB,WAAW,EAAE,GAAG;IAChB,iBAAiB,EAAE,GAAG;IACtB,QAAQ,EAAE,GAAG;IACb,OAAO,EAAE,GAAG;IACZ,UAAU,EAAE,GAAG;IACf,cAAc,EAAE,GAAG;IACnB,kBAAkB,EAAE,GAAG;IACvB,MAAM,EAAE,GAAG;IACX,KAAK,EAAE,GAAG;IACV,UAAU,EAAE,GAAG;IACf,QAAQ,EAAE,GAAG;IACb,SAAS,EAAE,GAAG;IACd,OAAO,EAAE,GAAG;IACZ,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,GAAG;CACV,CAAC;AAEF,MAAM,UAAU,SAAS,CAAC,KA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,UAA+C,EAAE;IAC9H,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC;IAC9G,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AAC/H,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from './queue.js';
2
+ export * from './http.js';
3
+ export * from './server.js';
4
+ export * from './util.js';
5
+ export * from './ws.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from './queue.js';
2
+ export * from './http.js';
3
+ export * from './server.js';
4
+ export * from './util.js';
5
+ export * from './ws.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
@@ -0,0 +1,71 @@
1
+ import { type SerializedError } from '@dream_engine/core';
2
+ export type JobStatus = 'queued' | 'running' | 'completed' | 'failed' | 'cancelled';
3
+ /** Events emitted for job lifecycle changes (used by the WebSocket progress stream). */
4
+ export interface JobEvent {
5
+ jobId: string;
6
+ owner: string;
7
+ type: string;
8
+ status: JobStatus;
9
+ progress: Record<string, unknown> | null;
10
+ result: unknown;
11
+ error: SerializedError | null;
12
+ timestamp: string;
13
+ }
14
+ /** A listener for {@link JobQueue} lifecycle events. */
15
+ export type JobEventListener = (event: JobEvent) => void;
16
+ export interface JobRecord {
17
+ id: string;
18
+ owner: string;
19
+ type: string;
20
+ status: JobStatus;
21
+ createdAt: string;
22
+ startedAt: string | null;
23
+ finishedAt: string | null;
24
+ progress: Record<string, unknown> | null;
25
+ result: unknown;
26
+ error: SerializedError | null;
27
+ }
28
+ export type JobHandler = (ctx: {
29
+ signal: AbortSignal;
30
+ progress: (p: Record<string, unknown>) => void;
31
+ jobId: string;
32
+ }) => Promise<unknown>;
33
+ /**
34
+ * In-process job queue with bounded worker concurrency, per-owner quotas, cancellation and result retention.
35
+ */
36
+ export declare class JobQueue {
37
+ private readonly options;
38
+ private readonly jobs;
39
+ private readonly waiting;
40
+ private readonly listeners;
41
+ private running;
42
+ private closed;
43
+ constructor(options: {
44
+ concurrency: number;
45
+ maxJobsPerOwner: number;
46
+ retentionMs?: number;
47
+ maxRetained?: number;
48
+ });
49
+ /** Subscribes to job lifecycle events. Returns an unsubscribe function. */
50
+ subscribe(listener: JobEventListener): () => void;
51
+ private emit;
52
+ /** Number of queued + running jobs for an owner. */
53
+ activeCount(owner: string): number;
54
+ enqueue(owner: string, type: string, handler: JobHandler): JobRecord;
55
+ get(id: string, owner?: string): JobRecord | null;
56
+ list(owner?: string): JobRecord[];
57
+ wait(id: string): Promise<JobRecord> | null;
58
+ cancel(id: string, owner?: string): boolean;
59
+ stats(): {
60
+ queued: number;
61
+ running: number;
62
+ total: number;
63
+ concurrency: number;
64
+ };
65
+ private finish;
66
+ private pump;
67
+ private prune;
68
+ /** Cancels everything and waits for running jobs to settle. */
69
+ close(): Promise<void>;
70
+ }
71
+ //# sourceMappingURL=queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0D,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAElH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEpF,wFAAwF;AACxF,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACzC,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,eAAe,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wDAAwD;AACxD,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;AAEzD,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACzC,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,eAAe,GAAG,IAAI,CAAC;CAC/B;AAED,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE;IAAE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AAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE;IAIhF,OAAO,CAAC,MAAM;IASd,OAAO,CAAC,IAAI;IAwBZ,OAAO,CAAC,KAAK;IAUb,+DAA+D;IACzD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAO7B"}
package/dist/queue.js ADDED
@@ -0,0 +1,168 @@
1
+ import { CancelledError, RuntimeError, createId, serializeError } from '@dream_engine/core';
2
+ /**
3
+ * In-process job queue with bounded worker concurrency, per-owner quotas, cancellation and result retention.
4
+ */
5
+ export class JobQueue {
6
+ options;
7
+ jobs = new Map();
8
+ waiting = [];
9
+ listeners = new Set();
10
+ running = 0;
11
+ closed = false;
12
+ constructor(options) {
13
+ this.options = options;
14
+ }
15
+ /** Subscribes to job lifecycle events. Returns an unsubscribe function. */
16
+ subscribe(listener) {
17
+ this.listeners.add(listener);
18
+ return () => {
19
+ this.listeners.delete(listener);
20
+ };
21
+ }
22
+ emit(j) {
23
+ const event = {
24
+ jobId: j.record.id,
25
+ owner: j.record.owner,
26
+ type: j.record.type,
27
+ status: j.record.status,
28
+ progress: j.record.progress,
29
+ result: j.record.result,
30
+ error: j.record.error,
31
+ timestamp: new Date().toISOString(),
32
+ };
33
+ for (const listener of this.listeners) {
34
+ try {
35
+ listener(event);
36
+ }
37
+ catch {
38
+ // A listener error must never break the job.
39
+ }
40
+ }
41
+ }
42
+ /** Number of queued + running jobs for an owner. */
43
+ activeCount(owner) {
44
+ let n = 0;
45
+ for (const j of this.jobs.values())
46
+ if (j.record.owner === owner && (j.record.status === 'queued' || j.record.status === 'running'))
47
+ n++;
48
+ return n;
49
+ }
50
+ enqueue(owner, type, handler) {
51
+ if (this.closed)
52
+ throw new RuntimeError('Job queue is shutting down');
53
+ if (this.activeCount(owner) >= this.options.maxJobsPerOwner)
54
+ throw new RuntimeError(`Job quota exceeded (max ${this.options.maxJobsPerOwner} active jobs)`, { details: { quota: this.options.maxJobsPerOwner } });
55
+ this.prune();
56
+ let resolve;
57
+ const done = new Promise((r) => (resolve = r));
58
+ const job = {
59
+ record: {
60
+ id: createId('job'),
61
+ owner,
62
+ type,
63
+ status: 'queued',
64
+ createdAt: new Date().toISOString(),
65
+ startedAt: null,
66
+ finishedAt: null,
67
+ progress: null,
68
+ result: null,
69
+ error: null,
70
+ },
71
+ handler,
72
+ controller: new AbortController(),
73
+ done,
74
+ resolve,
75
+ };
76
+ this.jobs.set(job.record.id, job);
77
+ this.waiting.push(job);
78
+ this.pump();
79
+ return job.record;
80
+ }
81
+ get(id, owner) {
82
+ const j = this.jobs.get(id);
83
+ if (!j || (owner !== undefined && j.record.owner !== owner))
84
+ return null;
85
+ return j.record;
86
+ }
87
+ list(owner) {
88
+ return [...this.jobs.values()].filter((j) => owner === undefined || j.record.owner === owner).map((j) => j.record);
89
+ }
90
+ wait(id) {
91
+ return this.jobs.get(id)?.done ?? null;
92
+ }
93
+ cancel(id, owner) {
94
+ const j = this.jobs.get(id);
95
+ if (!j || (owner !== undefined && j.record.owner !== owner))
96
+ return false;
97
+ if (j.record.status === 'queued') {
98
+ const idx = this.waiting.indexOf(j);
99
+ if (idx >= 0)
100
+ this.waiting.splice(idx, 1);
101
+ this.finish(j, 'cancelled', null, serializeError(new CancelledError('Job cancelled before it started')));
102
+ return true;
103
+ }
104
+ if (j.record.status === 'running') {
105
+ j.controller.abort(new CancelledError('Job cancelled'));
106
+ return true;
107
+ }
108
+ return false;
109
+ }
110
+ stats() {
111
+ return { queued: this.waiting.length, running: this.running, total: this.jobs.size, concurrency: this.options.concurrency };
112
+ }
113
+ finish(j, status, result, error) {
114
+ j.record.status = status;
115
+ j.record.result = result;
116
+ j.record.error = error;
117
+ j.record.finishedAt = new Date().toISOString();
118
+ j.resolve(j.record);
119
+ this.emit(j);
120
+ }
121
+ pump() {
122
+ while (this.running < this.options.concurrency && this.waiting.length) {
123
+ const j = this.waiting.shift();
124
+ this.running++;
125
+ j.record.status = 'running';
126
+ j.record.startedAt = new Date().toISOString();
127
+ this.emit(j);
128
+ j.handler({
129
+ signal: j.controller.signal,
130
+ jobId: j.record.id,
131
+ progress: (p) => {
132
+ j.record.progress = p;
133
+ this.emit(j);
134
+ },
135
+ })
136
+ .then((result) => this.finish(j, j.controller.signal.aborted ? 'cancelled' : 'completed', result, null))
137
+ .catch((error) => this.finish(j, j.controller.signal.aborted ? 'cancelled' : 'failed', null, serializeError(error)))
138
+ .finally(() => {
139
+ this.running--;
140
+ this.pump();
141
+ });
142
+ }
143
+ }
144
+ prune() {
145
+ const retention = this.options.retentionMs ?? 3600_000;
146
+ const max = this.options.maxRetained ?? 1000;
147
+ const now = Date.now();
148
+ const finished = [...this.jobs.values()].filter((j) => j.record.finishedAt);
149
+ for (const j of finished)
150
+ if (now - Date.parse(j.record.finishedAt) > retention)
151
+ this.jobs.delete(j.record.id);
152
+ const remaining = [...this.jobs.values()].filter((j) => j.record.finishedAt);
153
+ if (remaining.length > max)
154
+ for (const j of remaining.slice(0, remaining.length - max))
155
+ this.jobs.delete(j.record.id);
156
+ }
157
+ /** Cancels everything and waits for running jobs to settle. */
158
+ async close() {
159
+ this.closed = true;
160
+ for (const j of [...this.waiting])
161
+ this.cancel(j.record.id);
162
+ const running = [...this.jobs.values()].filter((j) => j.record.status === 'running');
163
+ for (const j of running)
164
+ j.controller.abort(new CancelledError('Server shutting down'));
165
+ await Promise.allSettled(running.map((j) => j.done));
166
+ }
167
+ }
168
+ //# sourceMappingURL=queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.js","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAwB,MAAM,oBAAoB,CAAC;AA0ClH;;GAEG;AACH,MAAM,OAAO,QAAQ;IAOU;IANZ,IAAI,GAAG,IAAI,GAAG,EAAuB,CAAC;IACtC,OAAO,GAAkB,EAAE,CA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,CAAC,CAAC;QAC5D,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC;QACrF,KAAK,MAAM,CAAC,IAAI,OAAO;YAAE,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,cAAc,CAAC,sBAAsB,CAAC,CAAC,CAAC;QACxF,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACvD,CAAC;CACF"}
@@ -0,0 +1,64 @@
1
+ import { type IncomingMessage, type ServerResponse } from 'node:http';
2
+ import { type BashirWebConfig, type Logger } from '@dream_engine/core';
3
+ import { JobQueue, type JobHandler } from './queue.js';
4
+ /** Operations the server exposes. The `bashirweb` package implements this with the local runtime. */
5
+ export interface ServerBackend {
6
+ info(): Promise<Record<string, unknown>>;
7
+ health(): Promise<{
8
+ status: 'ok' | 'degraded' | 'error';
9
+ checks: Record<string, unknown>;
10
+ }>;
11
+ search(owner: string, body: Record<string, unknown>, signal: AbortSignal): Promise<unknown>;
12
+ searchSuggest(owner: string, body: Record<string, unknown>): Promise<unknown>;
13
+ searchHistory(owner: string, body: Record<string, unknown>): Promise<unknown>;
14
+ extract(owner: string, body: Record<string, unknown>, signal: AbortSignal): Promise<unknown>;
15
+ crawlJob(owner: string, body: Record<string, unknown>): JobHandler;
16
+ workflowJob(owner: string, body: Record<string, unknown>): JobHandler;
17
+ createSession(owner: string, body: Record<string, unknown>): Promise<unknown>;
18
+ listSessions(owner: string): Promise<unknown[]>;
19
+ getSession(owner: string, id: string): Promise<unknown>;
20
+ destroySession(owner: string, id: string): Promise<void>;
21
+ newPage(owner: string, sessionId: string, body: Record<string, unknown>, signal: AbortSignal): Promise<unknown>;
22
+ closePage(owner: string, sessionId: string, pageId: string): Promise<void>;
23
+ pageAction(owner: string, sessionId: string, pageId: string, action: string, args: Record<string, unknown>, signal: AbortSignal): Promise<unknown>;
24
+ /** Search index statistics (document, duplicate and domain counts; backend). */
25
+ indexStats(owner: string): Promise<unknown>;
26
+ listTools(): unknown[];
27
+ callTool(owner: string, name: string, args: Record<string, unknown>, signal: AbortSignal): Promise<unknown>;
28
+ close(): Promise<void>;
29
+ }
30
+ export interface ServerOptions {
31
+ config: BashirWebConfig;
32
+ backend: ServerBackend;
33
+ logger?: Logger;
34
+ /** Optional handler for non-API paths (e.g. the dashboard's static files). Return true when handled. */
35
+ staticHandler?: (req: IncomingMessage, res: ServerResponse) => Promise<boolean>;
36
+ }
37
+ /** Hosted BashirWeb HTTP API. */
38
+ export declare class BashirWebServer {
39
+ private readonly options;
40
+ readonly queue: JobQueue;
41
+ private readonly server;
42
+ private readonly limiter;
43
+ private readonly routes;
44
+ private readonly logger;
45
+ private readonly startedAt;
46
+ private readonly stream;
47
+ private requests;
48
+ constructor(options: ServerOptions);
49
+ private buildRoutes;
50
+ private cors;
51
+ private dispatch;
52
+ listen(): Promise<{
53
+ host: string;
54
+ port: number;
55
+ url: string;
56
+ }>;
57
+ stats(): {
58
+ uptimeMs: number;
59
+ requests: number;
60
+ queue: ReturnType<JobQueue['stats']>;
61
+ };
62
+ close(): Promise<void>;
63
+ }
64
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,eAAe,EAAe,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAEjG,OAAO,EAWL,KAAK,eAAe,EACpB,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAIvD,qGAAqG;AACrG,MAAM,WAAW,a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AG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACjF;AAOD,iCAAiC;AACjC,qBAAa,eAAe;IAUd,OAAO,CAAC,QAAQ,CAAC,OAAO;IATpC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAc;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoB;IAC3C,OAAO,CAAC,QAAQ,CAAK;gBAEQ,OAAO,EAAE,aAAa;IAiBnD,OAAO,CAAC,WAAW;IA0FnB,OAAO,CAAC,IAAI;YAYE,QAAQ;IA4EhB,MAAM,IAAI,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IAgBpE,KAAK,IAAI;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAA;KAAE;IAI/E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAY7B"}
package/dist/server.js ADDED
@@ -0,0 +1,232 @@
1
+ import { createServer } from 'node:http';
2
+ import { ConfigurationError, RuntimeError, VERSION, ValidationError, createId, isPlainObject, redactUrl, serializeError, silentLogger, toBashirWebError, } from '@dream_engine/core';
3
+ import { isLoopbackHost } from './util.js';
4
+ import { JobQueue } from './queue.js';
5
+ import { RateLimiter, authenticate, readJson, route, sendJson, statusFor } from './http.js';
6
+ import { JobProgressStream } from './ws.js';
7
+ function obj(v) {
8
+ if (!isPlainObject(v))
9
+ throw new ValidationError('Request body must be a JSON object');
10
+ return v;
11
+ }
12
+ /** Hosted BashirWeb HTTP API. */
13
+ export class BashirWebServer {
14
+ options;
15
+ queue;
16
+ server;
17
+ limiter;
18
+ routes;
19
+ logger;
20
+ startedAt = Date.now();
21
+ stream;
22
+ requests = 0;
23
+ constructor(options) {
24
+ this.options = options;
25
+ const s = options.config.server;
26
+ this.logger = options.logger ?? silentLogger;
27
+ if (s.tokens.length === 0 && !isLoopbackHost(s.host)) {
28
+ throw new ConfigurationError(`Refusing to bind ${s.host} without authentication tokens`, {
29
+ hint: 'Set server.tokens (or BASHIRWEB_SERVER_TOKENS) or bind to 127.0.0.1.',
30
+ });
31
+ }
32
+ this.queue = new JobQueue({ concurrency: s.workerConcurrency, maxJobsPerOwner: s.maxJobsPerToken });
33
+ this.limiter = new RateLimiter(s.rateLimit.windowMs, s.rateLimit.max);
34
+ this.routes = this.buildRoutes();
35
+ this.server = createServer((req, res) => void this.dispatch(req, res));
36
+ this.server.requestTimeout = 15 * 60_000;
37
+ this.server.headersTimeout = 30_000;
38
+ this.stream = new JobProgressStream(this.server, { tokens: s.tokens, logger: this.logger }, this.queue);
39
+ }
40
+ buildRoutes() {
41
+ const b = this.options.backend;
42
+ const q = this.queue;
43
+ return [
44
+ route('GET', '/health', async (c) => {
45
+ const h = await b.health();
46
+ const base = { status: h.status, version: VERSION, uptimeMs: Date.now() - this.startedAt };
47
+ // Liveness is public (for load balancers); internals such as paths are only shown to authenticated callers.
48
+ if (!c.authenticated)
49
+ return base;
50
+ return { ...base, checks: h.checks, queue: q.stats() };
51
+ }, { auth: false }),
52
+ route('GET', '/v1/info', async () => ({ ...(await b.info()), version: VERSION })),
53
+ route('POST', '/v1/search', async (c) => b.search(c.owner, obj(c.body), c.signal)),
54
+ route('GET', '/v1/search/suggest', async (c) => b.searchSuggest(c.owner, { prefix: c.query.get('prefix') ?? '', limit: Number(c.query.get('limit') ?? 8) || 8 })),
55
+ route('GET', '/v1/search/history', async (c) => b.searchHistory(c.owner, { limit: Number(c.query.get('limit') ?? 20) || 20 })),
56
+ route('POST', '/v1/extract', async (c) => b.extract(c.owner, obj(c.body), c.signal)),
57
+ route('POST', '/v1/crawl', async (c) => q.enqueue(c.owner, 'crawl', b.crawlJob(c.owner, obj(c.body))), { status: 202 }),
58
+ route('POST', '/v1/workflows/run', async (c) => q.enqueue(c.owner, 'workflow', b.workflowJob(c.owner, obj(c.body))), { status: 202 }),
59
+ route('GET', '/v1/jobs', async (c) => ({ jobs: q.list(c.owner) })),
60
+ route('GET', '/v1/jobs/:id', async (c) => {
61
+ const wait = Math.min(Number(c.query.get('wait') ?? 0) || 0, 60_000);
62
+ let job = q.get(c.params['id'], c.owner);
63
+ if (!job)
64
+ throw new RuntimeError('Job not found');
65
+ if (wait > 0 && (job.status === 'queued' || job.status === 'running')) {
66
+ // Long-poll: resolve when the job finishes, the wait elapses or the client disconnects.
67
+ // The timer is always cleared so finished polls never keep the process alive.
68
+ let timer;
69
+ let onAbort;
70
+ try {
71
+ await Promise.race([
72
+ q.wait(job.id),
73
+ new Promise((resolve) => {
74
+ timer = setTimeout(resolve, wait);
75
+ onAbort = () => resolve();
76
+ c.signal.addEventListener('abort', onAbort, { once: true });
77
+ }),
78
+ ]);
79
+ }
80
+ finally {
81
+ clearTimeout(timer);
82
+ if (onAbort)
83
+ c.signal.removeEventListener('abort', onAbort);
84
+ }
85
+ job = q.get(job.id, c.owner);
86
+ }
87
+ return job;
88
+ }),
89
+ route('DELETE', '/v1/jobs/:id', async (c) => {
90
+ if (!q.cancel(c.params['id'], c.owner))
91
+ throw new RuntimeError('Job not found or already finished');
92
+ return { cancelled: true };
93
+ }),
94
+ route('POST', '/v1/sessions', async (c) => {
95
+ const list = await b.listSessions(c.owner);
96
+ if (list.length >= this.options.config.server.maxSessionsPerToken)
97
+ throw new RuntimeError(`Session quota exceeded (max ${this.options.config.server.maxSessionsPerToken})`);
98
+ return b.createSession(c.owner, obj(c.body));
99
+ }, { status: 201 }),
100
+ route('GET', '/v1/sessions', async (c) => ({ sessions: await b.listSessions(c.owner) })),
101
+ route('GET', '/v1/sessions/:id', async (c) => b.getSession(c.owner, c.params['id'])),
102
+ route('DELETE', '/v1/sessions/:id', async (c) => {
103
+ await b.destroySession(c.owner, c.params['id']);
104
+ return { destroyed: true };
105
+ }),
106
+ route('POST', '/v1/sessions/:id/pages', async (c) => b.newPage(c.owner, c.params['id'], obj(c.body), c.signal), { status: 201 }),
107
+ route('DELETE', '/v1/sessions/:id/pages/:pageId', async (c) => {
108
+ await b.closePage(c.owner, c.params['id'], c.params['pageId']);
109
+ return { closed: true };
110
+ }),
111
+ route('POST', '/v1/sessions/:id/pages/:pageId/actions', async (c) => {
112
+ const body = obj(c.body);
113
+ if (typeof body['action'] !== 'string')
114
+ throw new ValidationError('action is required');
115
+ const args = body['args'] === undefined ? {} : obj(body['args']);
116
+ return { result: await b.pageAction(c.owner, c.params['id'], c.params['pageId'], body['action'], args, c.signal) };
117
+ }),
118
+ route('GET', '/v1/index/stats', async (c) => b.indexStats(c.owner)),
119
+ route('GET', '/v1/tools', async () => ({ tools: b.listTools() })),
120
+ route('POST', '/v1/tools/:name', async (c) => b.callTool(c.owner, c.params['name'], obj(c.body), c.signal)),
121
+ ];
122
+ }
123
+ cors(req) {
124
+ const origin = req.headers.origin;
125
+ const allowed = this.options.config.server.corsOrigins;
126
+ if (!origin || !(allowed.includes('*') || allowed.includes(origin)))
127
+ return {};
128
+ return {
129
+ 'access-control-allow-origin': allowed.includes('*') ? '*' : origin,
130
+ 'access-control-allow-headers': 'authorization, content-type',
131
+ 'access-control-allow-methods': 'GET, POST, DELETE, OPTIONS',
132
+ vary: 'Origin',
133
+ };
134
+ }
135
+ async dispatch(req, res) {
136
+ this.requests++;
137
+ const requestId = createId('req');
138
+ const started = Date.now();
139
+ const cors = this.cors(req);
140
+ const headers = { 'x-request-id': requestId, ...cors };
141
+ const url = new URL(req.url ?? '/', 'http://localhost');
142
+ const controller = new AbortController();
143
+ res.on('close', () => {
144
+ if (!res.writableFinished)
145
+ controller.abort();
146
+ });
147
+ try {
148
+ if (req.method === 'OPTIONS') {
149
+ res.writeHead(204, headers).end();
150
+ return;
151
+ }
152
+ const match = this.routes.find((r) => r.method === req.method && r.pattern.test(url.pathname));
153
+ if (!match) {
154
+ if (req.method === 'GET' && this.options.staticHandler && (await this.options.staticHandler(req, res)))
155
+ return;
156
+ const exists = this.routes.some((r) => r.pattern.test(url.pathname));
157
+ sendJson(res, exists ? 405 : 404, { error: { name: 'NotFound', code: 'VALIDATION', message: exists ? 'Method not allowed' : 'Not found', retryable: false } }, headers);
158
+ return;
159
+ }
160
+ let owner = 'local';
161
+ const tokens = this.options.config.server.tokens;
162
+ const presented = tokens.length > 0 ? authenticate(req.headers.authorization, tokens) : null;
163
+ const authenticated = tokens.length === 0 || presented !== null;
164
+ if (match.auth && tokens.length > 0) {
165
+ const o = presented;
166
+ if (!o) {
167
+ sendJson(res, 401, { error: { name: 'Unauthorized', code: 'SECURITY', message: 'Missing or invalid bearer token', retryable: false } }, { ...headers, 'www-authenticate': 'Bearer' });
168
+ return;
169
+ }
170
+ owner = o;
171
+ }
172
+ if (match.auth) {
173
+ const key = tokens.length ? owner : (req.socket.remoteAddress ?? 'unknown');
174
+ const rl = this.limiter.check(key);
175
+ Object.assign(headers, { 'x-ratelimit-remaining': String(rl.remaining) });
176
+ if (!rl.allowed) {
177
+ sendJson(res, 429, { error: { name: 'RateLimited', code: 'RUNTIME', message: 'Rate limit exceeded', retryable: true } }, { ...headers, 'retry-after': String(Math.ceil(rl.resetMs / 1000)) });
178
+ return;
179
+ }
180
+ }
181
+ const m = match.pattern.exec(url.pathname);
182
+ const params = {};
183
+ match.keys.forEach((k, i) => (params[k] = decodeURIComponent(m[i + 1] ?? '')));
184
+ const body = req.method === 'POST' ? await readJson(req) : {};
185
+ const ctx = { req, params, query: url.searchParams, body, owner, authenticated, signal: controller.signal, requestId };
186
+ const result = await match.handler(ctx);
187
+ sendJson(res, match.status ?? 200, result, headers);
188
+ this.logger.debug('request', { requestId, method: req.method, path: redactUrl(url.pathname), status: match.status ?? 200, ms: Date.now() - started });
189
+ }
190
+ catch (error) {
191
+ const e = toBashirWebError(error);
192
+ const status = statusFor(e);
193
+ if (status >= 500)
194
+ this.logger.warn('request failed', { requestId, path: url.pathname, error: e.message });
195
+ if (!res.headersSent)
196
+ sendJson(res, status, { error: serializeError(e) }, headers);
197
+ else
198
+ res.end();
199
+ }
200
+ }
201
+ async listen() {
202
+ const { host, port } = this.options.config.server;
203
+ await new Promise((resolve, reject) => {
204
+ this.server.once('error', reject);
205
+ this.server.listen(port, host, () => {
206
+ this.server.off('error', reject);
207
+ resolve();
208
+ });
209
+ });
210
+ const addr = this.server.address();
211
+ const shownHost = addr.address.includes(':') ? `[${addr.address}]` : addr.address;
212
+ if (this.options.config.server.tokens.length === 0)
213
+ this.logger.warn('Server running WITHOUT authentication (loopback only). Configure server.tokens for any shared use.');
214
+ return { host: addr.address, port: addr.port, url: `http://${shownHost}:${addr.port}` };
215
+ }
216
+ stats() {
217
+ return { uptimeMs: Date.now() - this.startedAt, requests: this.requests, queue: this.queue.stats() };
218
+ }
219
+ async close() {
220
+ await this.stream.close();
221
+ await this.queue.close();
222
+ await new Promise((resolve) => {
223
+ this.server.closeIdleConnections();
224
+ this.server.close(() => resolve());
225
+ setTimeout(() => {
226
+ this.server.closeAllConnections();
227
+ }, 5000).unref();
228
+ });
229
+ await this.options.backend.close();
230
+ }
231
+ }
232
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0D,MAAM,WAAW,CAAC;AAEjG,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,OAAO,EACP,eAAe,EACf,QAAQ,EACR,aAAa,EACb,SAAS,EACT,cAAc,EACd,YAAY,EACZ,gBAAgB,GAGjB,MAAM,oBAA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OAAO,EAAE,EAAE;YAClC,IAAI,CAAC,MAAM,CAAC,oBAAoB,EAAE,CAAC;YACnC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;YACnC,UAAU,CAAC,GAAG,EAAE;gBACd,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAC;YACpC,CAAC,EAAE,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;QACnB,CAAC,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACrC,CAAC;CACF"}
package/dist/util.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ /** True for hosts that only accept local connections. */
2
+ export declare function isLoopbackHost(host: string): boolean;
3
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAEA,yDAAyD;AACzD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIpD"}
package/dist/util.js ADDED
@@ -0,0 +1,9 @@
1
+ import { isIP } from 'node:net';
2
+ /** True for hosts that only accept local connections. */
3
+ export function isLoopbackHost(host) {
4
+ const h = host.replace(/^\[|\]$/g, '').toLowerCase();
5
+ if (h === 'localhost' || h === '::1')
6
+ return true;
7
+ return isIP(h) === 4 && h.startsWith('127.');
8
+ }
9
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,yDAAyD;AACzD,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IACrD,IAAI,CAAC,KAAK,WAAW,IAAI,CAAC,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IAClD,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AAC/C,CAAC"}
package/dist/ws.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ import type { Server } from 'node:http';
2
+ import type { JobEvent, JobQueue } from './queue.js';
3
+ /** Default WebSocket path for the job-progress stream. */
4
+ export declare const WS_PATH = "/v1/ws";
5
+ /** A parsed client-to-server frame on the job-progress stream. */
6
+ export interface ClientFrame {
7
+ type: string;
8
+ /** Job id to filter on (for `subscribe`). */
9
+ jobId?: string;
10
+ }
11
+ /** Shape of the JSON frames the server sends back to a client. */
12
+ export interface ServerFrame {
13
+ type: 'hello' | 'event' | 'error' | 'pong';
14
+ event?: JobEvent;
15
+ error?: {
16
+ name: string;
17
+ code: string;
18
+ message: string;
19
+ };
20
+ info?: {
21
+ server: string;
22
+ subscribed?: string | null;
23
+ };
24
+ }
25
+ /**
26
+ * Attaches a WebSocket job-progress stream to an HTTP server.
27
+ *
28
+ * Clients connect to {@link WS_PATH}, authenticate with a bearer token (via the
29
+ * `?token=` query param, since browser WebSocket APIs cannot set headers), and
30
+ * then receive live {@link import('./queue.js').JobEvent} frames for job lifecycle
31
+ * changes. A client can optionally filter to a single job via a `subscribe` frame.
32
+ */
33
+ export declare class JobProgressStream {
34
+ private readonly options;
35
+ private readonly wss;
36
+ private readonly clients;
37
+ private readonly unsubscribe;
38
+ constructor(server: Server, options: {
39
+ /** Server-side bearer tokens for authentication. */
40
+ tokens: string[];
41
+ logger?: {
42
+ debug?: (msg: string, fields?: Record<string, unknown>) => void;
43
+ };
44
+ }, queue: JobQueue);
45
+ /** Number of currently connected clients. */
46
+ get clientCount(): number;
47
+ /** Closes all connections and stops the server. */
48
+ close(): Promise<void>;
49
+ private onEvent;
50
+ private handleConnection;
51
+ private handleMessage;
52
+ private send;
53
+ }
54
+ //# sourceMappingUR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AK,IAAI,CAAA;SAAE,CAAC;KAC9E,EACD,KAAK,EAAE,QAAQ;IAYjB,6CAA6C;IAC7C,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,mDAAmD;IAC7C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAa5B,OAAO,CAAC,OAAO;IAUf,OAAO,CAAC,gBAAgB;IA8BxB,OAAO,CAAC,aAAa;IA4CrB,OAAO,CAAC,IAAI;CAQb"}
package/dist/ws.js ADDED
@@ -0,0 +1,140 @@
1
+ import { WebSocketServer, WebSocket } from 'ws';
2
+ import { authenticate } from './http.js';
3
+ /** Default WebSocket path for the job-progress stream. */
4
+ export const WS_PATH = '/v1/ws';
5
+ /**
6
+ * Attaches a WebSocket job-progress stream to an HTTP server.
7
+ *
8
+ * Clients connect to {@link WS_PATH}, authenticate with a bearer token (via the
9
+ * `?token=` query param, since browser WebSocket APIs cannot set headers), and
10
+ * then receive live {@link import('./queue.js').JobEvent} frames for job lifecycle
11
+ * changes. A client can optionally filter to a single job via a `subscribe` frame.
12
+ */
13
+ export class JobProgressStream {
14
+ options;
15
+ wss;
16
+ clients = new Map();
17
+ unsubscribe;
18
+ constructor(server, options, queue) {
19
+ this.options = options;
20
+ this.unsubscribe = queue.subscribe((event) => this.onEvent(event));
21
+ this.wss = new WebSocketServer({ server, path: WS_PATH, maxPayload: 1024 * 1024 });
22
+ this.wss.on('connection', (ws, req) => {
23
+ this.handleConnection(ws, req);
24
+ });
25
+ this.wss.on('error', (err) => {
26
+ this.options.logger?.debug?.('websocket server error', { error: err.message });
27
+ });
28
+ }
29
+ /** Number of currently connected clients. */
30
+ get clientCount() {
31
+ return this.clients.size;
32
+ }
33
+ /** Closes all connections and stops the server. */
34
+ async close() {
35
+ this.unsubscribe();
36
+ for (const ws of this.clients.keys()) {
37
+ try {
38
+ ws.close();
39
+ }
40
+ catch {
41
+ // ignore
42
+ }
43
+ }
44
+ this.clients.clear();
45
+ await new Promise((resolve) => this.wss.close(() => resolve()));
46
+ }
47
+ onEvent(event) {
48
+ for (const [ws, state] of this.clients) {
49
+ if (state.jobId && state.jobId !== event.jobId)
50
+ continue;
51
+ // A token-less (loopback) server sends to everyone; a token-bearing server
52
+ // only streams the owner's own jobs.
53
+ if (this.options.tokens.length > 0 && event.owner !== state.owner)
54
+ continue;
55
+ this.send(ws, { type: 'event', event });
56
+ }
57
+ }
58
+ handleConnection(ws, req) {
59
+ const url = new URL(req.url ?? '/', 'http://localhost');
60
+ const tokens = this.options.tokens;
61
+ let owner = 'local';
62
+ if (tokens.length > 0) {
63
+ // Browser WebSocket cannot set headers; accept a bearer token via query param.
64
+ const presented = authenticate(url.searchParams.get('token') ? `Bearer ${url.searchParams.get('token')}` : undefined, tokens);
65
+ if (!presented) {
66
+ this.send(ws, { type: 'error', error: { name: 'Unauthorized', code: 'SECURITY', message: 'Missing or invalid bearer token' } });
67
+ ws.close(4001, 'Unauthorized');
68
+ return;
69
+ }
70
+ owner = presented;
71
+ }
72
+ this.clients.set(ws, { owner });
73
+ this.send(ws, { type: 'hello', info: { server: 'bashirweb' } });
74
+ ws.on('message', (data, isBinary) => {
75
+ this.handleMessage(ws, data, isBinary);
76
+ });
77
+ ws.on('close', () => {
78
+ this.clients.delete(ws);
79
+ });
80
+ ws.on('error', () => {
81
+ this.clients.delete(ws);
82
+ });
83
+ }
84
+ handleMessage(ws, data, isBinary) {
85
+ if (isBinary) {
86
+ this.send(ws, { type: 'error', error: { name: 'ValidationError', code: 'VALIDATION', message: 'Binary frames are not supported' } });
87
+ return;
88
+ }
89
+ let frame;
90
+ try {
91
+ const parsed = JSON.parse(data.toString());
92
+ if (!parsed || typeof parsed !== 'object')
93
+ throw new Error('not an object');
94
+ frame = parsed;
95
+ if (typeof frame.type !== 'string')
96
+ throw new Error('missing type');
97
+ }
98
+ catch {
99
+ this.send(ws, { type: 'error', error: { name: 'ValidationError', code: 'VALIDATION', message: 'Invalid JSON frame' } });
100
+ return;
101
+ }
102
+ const state = this.clients.get(ws);
103
+ if (!state)
104
+ return;
105
+ switch (frame.type) {
106
+ case 'subscribe': {
107
+ if (typeof frame.jobId !== 'string' || frame.jobId.length === 0) {
108
+ this.send(ws, { type: 'error', error: { name: 'ValidationError', code: 'VALIDATION', message: 'subscribe requires a jobId' } });
109
+ return;
110
+ }
111
+ state.jobId = frame.jobId;
112
+ this.send(ws, { type: 'hello', info: { server: 'bashirweb', subscribed: frame.jobId } });
113
+ break;
114
+ }
115
+ case 'unsubscribe': {
116
+ state.jobId = undefined;
117
+ this.send(ws, { type: 'hello', info: { server: 'bashirweb', subscribed: null } });
118
+ break;
119
+ }
120
+ case 'ping': {
121
+ this.send(ws, { type: 'pong' });
122
+ break;
123
+ }
124
+ default: {
125
+ this.send(ws, { type: 'error', error: { name: 'ValidationError', code: 'VALIDATION', message: `Unknown frame type: ${frame.type}` } });
126
+ }
127
+ }
128
+ }
129
+ send(ws, frame) {
130
+ if (ws.readyState !== WebSocket.OPEN)
131
+ return;
132
+ try {
133
+ ws.send(JSON.stringify(frame));
134
+ }
135
+ catch {
136
+ // ignore send failures
137
+ }
138
+ }
139
+ }
140
+ //# sourceMappingURL=ws.js.map
package/dist/ws.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ws.js","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAgB,MAAM,IAAI,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,0DAA0D;AAC1D,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC;AAwBhC;;;;;;;GAOG;AACH,MAAM,OAAO,iBAAiB;IAOT;IANF,GAAG,CAAkB;IACrB,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC5C,WAAW,CAAa;IAEzC,YACE,MAAc,EACG,OAIhB,EACD,KAAe;QALE,YAAO,GAAP,OAAO,CAIvB;QAGD,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,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nB,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC;gBACxB,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;gBAClF,MAAM;YACR,CAAC;YACD,KAAK,MAAM,CAAC,CAAC,CAAC;gBACZ,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;gBAChC,MAAM;YACR,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,uBAAuB,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;YACzI,CAAC;QACH,CAAC;IACH,CAAC;IAEO,IAAI,CAAC,EAAa,EAAE,KAAkB;QAC5C,IAAI,EAAE,CAAC,UAAU,KAAK,SAAS,CAAC,IAAI;YAAE,OAAO;QAC7C,IAAI,CAAC;YACH,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;QACjC,CAAC;QAAC,MAAM,CAAC;YACP,uBAAuB;QACzB,CAAC;IACH,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@dream_engine/server",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Hosted runtime for BashirWeb: HTTP API, authentication, rate limiting, browser workers, job queue and session isolation.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/CodingWithBashir/BashirWeb.git",
10
+ "directory": "packages/server"
11
+ },
12
+ "engines": {
13
+ "node": ">=22.16.0 <23 || >=24"
14
+ },
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "README.md"
27
+ ],
28
+ "sideEffects": false,
29
+ "dependencies": {
30
+ "ws": "^8.18.0",
31
+ "@dream_engine/core": "0.1.1",
32
+ "@dream_engine/security": "0.1.1"
33
+ },
34
+ "devDependencies": {
35
+ "@types/ws": "^8.5.13"
36
+ },
37
+ "scripts": {
38
+ "build": "tsc -b"
39
+ }
6
40
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.