nuxt-ai-ready 2.5.2 → 2.5.3
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/dist/module.json +1 -1
- package/dist/runtime/server/middleware/markdown.js +3 -3
- package/dist/runtime/server/utils/negotiation-response.d.ts +1 -1
- package/dist/runtime/server/utils/negotiation-response.js +17 -2
- package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/LICENSE +21 -0
- package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/README.md +203 -0
- package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +236 -0
- package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +1086 -0
- package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/package.json +35 -0
- package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/rollup.config.js +6 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +4 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +48 -16
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/package.json +1 -1
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs.js +3339 -4021
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/package.json +1 -1
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -128,13 +128,13 @@ ${contentPage.markdown}`);
|
|
|
128
128
|
if (!response.ok && response.status !== 404)
|
|
129
129
|
return response;
|
|
130
130
|
if (response.status === 404) {
|
|
131
|
-
setMarkdownHeaders(event, ctx);
|
|
131
|
+
setMarkdownHeaders(event, ctx, response.headers);
|
|
132
132
|
setResponseStatus(event, 404);
|
|
133
133
|
return notFoundMarkdown(ctx, canonicalUrl, buildFrontmatter);
|
|
134
134
|
}
|
|
135
135
|
const contentType = response.headers.get("content-type") || "";
|
|
136
136
|
if (!contentType.includes("text/html")) {
|
|
137
|
-
setMarkdownHeaders(event, ctx);
|
|
137
|
+
setMarkdownHeaders(event, ctx, response.headers);
|
|
138
138
|
setResponseStatus(event, 404);
|
|
139
139
|
return notFoundMarkdown(ctx, canonicalUrl, buildFrontmatter);
|
|
140
140
|
}
|
|
@@ -169,6 +169,6 @@ ${contentPage.markdown}`);
|
|
|
169
169
|
additionalFrontmatter
|
|
170
170
|
}
|
|
171
171
|
);
|
|
172
|
-
setMarkdownHeaders(event, ctx);
|
|
172
|
+
setMarkdownHeaders(event, ctx, response.headers);
|
|
173
173
|
return finalizeMarkdown(result.markdown);
|
|
174
174
|
});
|
|
@@ -17,7 +17,7 @@ type NegotiationResponse = Awaited<ReturnType<typeof sendRedirect>> | undefined;
|
|
|
17
17
|
export declare function setLinkHeader(event: H3Event, ctx: NegotiationContext, variant: 'html' | 'markdown'): void;
|
|
18
18
|
export declare function setStatusAwareHeader(event: H3Event, ctx: NegotiationContext, variant: 'html' | 'markdown'): void;
|
|
19
19
|
export declare function setUncacheableHeaders(event: H3Event): void;
|
|
20
|
-
export declare function setMarkdownHeaders(event: H3Event, ctx: NegotiationContext): void;
|
|
20
|
+
export declare function setMarkdownHeaders(event: H3Event, ctx: NegotiationContext, sourceHeaders?: Headers): void;
|
|
21
21
|
/**
|
|
22
22
|
* Site config is set up by a Nitro middleware. The early negotiation handler
|
|
23
23
|
* runs in front of that middleware, so it must run the setup itself before it
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createNitroRouteRuleMatcher } from "nuxtseo-shared/server";
|
|
2
2
|
import { localAgentSkillArtifacts } from "#ai-ready-virtual/agent-skills.mjs";
|
|
3
|
-
import { appendHeader, createError, getRequestHost, getResponseHeader, sendRedirect, setHeader } from "#nuxtseo/h3";
|
|
3
|
+
import { appendHeader, createError, getHeader, getRequestHost, getResponseHeader, sendRedirect, setHeader } from "#nuxtseo/h3";
|
|
4
4
|
import { useRuntimeConfig } from "#nuxtseo/nitro";
|
|
5
5
|
import { withSiteUrl } from "#site-config/server/composables/utils";
|
|
6
6
|
import initSiteConfig from "#site-config/server/middleware/init";
|
|
@@ -42,9 +42,24 @@ export function setUncacheableHeaders(event) {
|
|
|
42
42
|
setHeader(event, header, "no-store");
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
export function setMarkdownHeaders(event, ctx) {
|
|
45
|
+
export function setMarkdownHeaders(event, ctx, sourceHeaders) {
|
|
46
46
|
setHeader(event, "content-type", "text/markdown; charset=utf-8");
|
|
47
47
|
setLinkHeader(event, ctx, "markdown");
|
|
48
|
+
const privateResponse = [
|
|
49
|
+
"cache-control",
|
|
50
|
+
"cdn-cache-control",
|
|
51
|
+
"cloudflare-cdn-cache-control",
|
|
52
|
+
"netlify-cdn-cache-control",
|
|
53
|
+
"vercel-cdn-cache-control",
|
|
54
|
+
"surrogate-control"
|
|
55
|
+
].some((header) => {
|
|
56
|
+
const value = `${getResponseHeader(event, header) || ""},${sourceHeaders?.get(header) || ""}`;
|
|
57
|
+
return /(?:^|,)\s*(?:private|no-store|no-cache)\s*(?:,|=|$)/i.test(value);
|
|
58
|
+
});
|
|
59
|
+
if (getHeader(event, "cookie") || getHeader(event, "authorization") || getResponseHeader(event, "set-cookie") || sourceHeaders?.has("set-cookie") || privateResponse) {
|
|
60
|
+
setUncacheableHeaders(event);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
48
63
|
const cacheHeaders = ctx.config.markdownCacheHeaders;
|
|
49
64
|
if (cacheHeaders) {
|
|
50
65
|
const { maxAge, swr } = cacheHeaders;
|
package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Toyobayashi
|
|
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.
|
package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/README.md
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# @emnapi/wasi-threads
|
|
2
|
+
|
|
3
|
+
This package makes [wasi-threads proposal](https://github.com/WebAssembly/wasi-threads) based WASI modules work in Node.js and browser.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
`index.html`
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<script src="./node_modules/@tybys/wasm-util/dist/wasm-util.js"></script>
|
|
11
|
+
<script src="./node_modules/@emnapi/wasi-threads/dist/wasi-threads.js"></script>
|
|
12
|
+
<script src="./index.js"></script>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
If your application will block browser main thread (for example `pthread_join`), please run it in worker instead.
|
|
16
|
+
|
|
17
|
+
```html
|
|
18
|
+
<script>
|
|
19
|
+
// pthread_join (Atomics.wait) cannot be called in browser main thread
|
|
20
|
+
new Worker('./index.js')
|
|
21
|
+
</script>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
`index.js`
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
const ENVIRONMENT_IS_NODE =
|
|
28
|
+
typeof process === 'object' && process !== null &&
|
|
29
|
+
typeof process.versions === 'object' && process.versions !== null &&
|
|
30
|
+
typeof process.versions.node === 'string';
|
|
31
|
+
|
|
32
|
+
(function (main) {
|
|
33
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
34
|
+
main(require)
|
|
35
|
+
} else {
|
|
36
|
+
if (typeof importScripts === 'function') {
|
|
37
|
+
importScripts('./node_modules/@tybys/wasm-util/dist/wasm-util.js')
|
|
38
|
+
importScripts('./node_modules/@emnapi/wasi-threads/dist/wasi-threads.js')
|
|
39
|
+
}
|
|
40
|
+
const nodeWasi = { WASI: globalThis.wasmUtil.WASI }
|
|
41
|
+
const nodeWorkerThreads = {
|
|
42
|
+
Worker: globalThis.Worker
|
|
43
|
+
}
|
|
44
|
+
const _require = function (request) {
|
|
45
|
+
if (request === 'node:wasi' || request === 'wasi') return nodeWasi
|
|
46
|
+
if (request === 'node:worker_threads' || request === 'worker_threads') return nodeWorkerThreads
|
|
47
|
+
if (request === '@emnapi/wasi-threads') return globalThis.wasiThreads
|
|
48
|
+
throw new Error('Can not find module: ' + request)
|
|
49
|
+
}
|
|
50
|
+
main(_require)
|
|
51
|
+
}
|
|
52
|
+
})(async function (require) {
|
|
53
|
+
const { WASI } = require('wasi')
|
|
54
|
+
const { Worker } = require('worker_threads')
|
|
55
|
+
const { WASIThreads } = require('@emnapi/wasi-threads')
|
|
56
|
+
|
|
57
|
+
const wasi = new WASI({
|
|
58
|
+
version: 'preview1'
|
|
59
|
+
})
|
|
60
|
+
const wasiThreads = new WASIThreads({
|
|
61
|
+
wasi,
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* avoid Atomics.wait() deadlock during thread creation in browser
|
|
65
|
+
* see https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size
|
|
66
|
+
*/
|
|
67
|
+
reuseWorker: ENVIRONMENT_IS_NODE
|
|
68
|
+
? false
|
|
69
|
+
: {
|
|
70
|
+
size: 4 /** greater than actual needs (2) */,
|
|
71
|
+
strict: true
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Synchronous thread creation
|
|
76
|
+
* pthread_create will not return until thread worker actually starts
|
|
77
|
+
*/
|
|
78
|
+
waitThreadStart: typeof window === 'undefined' ? 1000 : false,
|
|
79
|
+
|
|
80
|
+
onCreateWorker: () => {
|
|
81
|
+
return new Worker('./worker.js', {
|
|
82
|
+
execArgv: ['--experimental-wasi-unstable-preview1']
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
const memory = new WebAssembly.Memory({
|
|
87
|
+
initial: 16777216 / 65536,
|
|
88
|
+
maximum: 2147483648 / 65536,
|
|
89
|
+
shared: true
|
|
90
|
+
})
|
|
91
|
+
let input
|
|
92
|
+
const file = 'path/to/your/wasi-module.wasm'
|
|
93
|
+
try {
|
|
94
|
+
input = require('fs').readFileSync(require('path').join(__dirname, file))
|
|
95
|
+
} catch (err) {
|
|
96
|
+
const response = await fetch(file)
|
|
97
|
+
input = await response.arrayBuffer()
|
|
98
|
+
}
|
|
99
|
+
let { module, instance } = await WebAssembly.instantiate(input, {
|
|
100
|
+
env: { memory },
|
|
101
|
+
wasi_snapshot_preview1: wasi.wasiImport,
|
|
102
|
+
...wasiThreads.getImportObject()
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
wasiThreads.setup(instance, module, memory)
|
|
106
|
+
await wasiThreads.preloadWorkers()
|
|
107
|
+
|
|
108
|
+
if (typeof instance.exports._start === 'function') {
|
|
109
|
+
return wasi.start(instance)
|
|
110
|
+
} else {
|
|
111
|
+
wasi.initialize(instance)
|
|
112
|
+
// instance.exports.exported_wasm_function()
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`worker.js`
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
(function (main) {
|
|
121
|
+
const ENVIRONMENT_IS_NODE =
|
|
122
|
+
typeof process === 'object' && process !== null &&
|
|
123
|
+
typeof process.versions === 'object' && process.versions !== null &&
|
|
124
|
+
typeof process.versions.node === 'string'
|
|
125
|
+
|
|
126
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
127
|
+
const _require = function (request) {
|
|
128
|
+
return require(request)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const _init = function () {
|
|
132
|
+
const nodeWorkerThreads = require('worker_threads')
|
|
133
|
+
const parentPort = nodeWorkerThreads.parentPort
|
|
134
|
+
|
|
135
|
+
parentPort.on('message', (data) => {
|
|
136
|
+
globalThis.onmessage({ data })
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
Object.assign(globalThis, {
|
|
140
|
+
self: globalThis,
|
|
141
|
+
require,
|
|
142
|
+
Worker: nodeWorkerThreads.Worker,
|
|
143
|
+
importScripts: function (f) {
|
|
144
|
+
(0, eval)(require('fs').readFileSync(f, 'utf8') + '//# sourceURL=' + f)
|
|
145
|
+
},
|
|
146
|
+
postMessage: function (msg) {
|
|
147
|
+
parentPort.postMessage(msg)
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
main(_require, _init)
|
|
153
|
+
} else {
|
|
154
|
+
importScripts('./node_modules/@tybys/wasm-util/dist/wasm-util.js')
|
|
155
|
+
importScripts('./node_modules/@emnapi/wasi-threads/dist/wasi-threads.js')
|
|
156
|
+
|
|
157
|
+
const nodeWasi = { WASI: globalThis.wasmUtil.WASI }
|
|
158
|
+
const _require = function (request) {
|
|
159
|
+
if (request === '@emnapi/wasi-threads') return globalThis.wasiThreads
|
|
160
|
+
if (request === 'node:wasi' || request === 'wasi') return nodeWasi
|
|
161
|
+
throw new Error('Can not find module: ' + request)
|
|
162
|
+
}
|
|
163
|
+
const _init = function () {}
|
|
164
|
+
main(_require, _init)
|
|
165
|
+
}
|
|
166
|
+
})(function main (require, init) {
|
|
167
|
+
init()
|
|
168
|
+
|
|
169
|
+
const { WASI } = require('wasi')
|
|
170
|
+
const { ThreadMessageHandler, WASIThreads } = require('@emnapi/wasi-threads')
|
|
171
|
+
|
|
172
|
+
const handler = new ThreadMessageHandler({
|
|
173
|
+
async onLoad ({ wasmModule, wasmMemory }) {
|
|
174
|
+
const wasi = new WASI({
|
|
175
|
+
version: 'preview1'
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
const wasiThreads = new WASIThreads({
|
|
179
|
+
wasi,
|
|
180
|
+
childThread: true
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
const originalInstance = await WebAssembly.instantiate(wasmModule, {
|
|
184
|
+
env: {
|
|
185
|
+
memory: wasmMemory,
|
|
186
|
+
},
|
|
187
|
+
wasi_snapshot_preview1: wasi.wasiImport,
|
|
188
|
+
...wasiThreads.getImportObject()
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
// must call `initialize` instead of `start` in child thread
|
|
192
|
+
const instance = wasiThreads.initialize(originalInstance, wasmModule, wasmMemory)
|
|
193
|
+
|
|
194
|
+
return { module: wasmModule, instance }
|
|
195
|
+
}
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
globalThis.onmessage = function (e) {
|
|
199
|
+
handler.handle(e)
|
|
200
|
+
// handle other messages
|
|
201
|
+
}
|
|
202
|
+
})
|
|
203
|
+
```
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import type { Worker as Worker_2 } from 'worker_threads';
|
|
2
|
+
|
|
3
|
+
export declare interface BaseOptions {
|
|
4
|
+
wasi: WASIInstance;
|
|
5
|
+
version?: 'preview1';
|
|
6
|
+
wasm64?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export declare interface ChildThreadOptions extends BaseOptions {
|
|
10
|
+
childThread: true;
|
|
11
|
+
postMessage?: (data: any) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export declare interface CleanupThreadPayload {
|
|
15
|
+
tid: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export declare interface CommandInfo<T extends CommandType> {
|
|
19
|
+
type: T;
|
|
20
|
+
payload: CommandPayloadMap[T];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export declare interface CommandPayloadMap {
|
|
24
|
+
load: LoadPayload;
|
|
25
|
+
loaded: LoadedPayload;
|
|
26
|
+
start: StartPayload;
|
|
27
|
+
'cleanup-thread': CleanupThreadPayload;
|
|
28
|
+
'terminate-all-threads': TerminateAllThreadsPayload;
|
|
29
|
+
'spawn-thread': SpawnThreadPayload;
|
|
30
|
+
'thread-error': ThreadErrorPayload;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export declare type CommandType = keyof CommandPayloadMap;
|
|
34
|
+
|
|
35
|
+
export declare function createInstanceProxy(instance: WebAssembly.Instance, memory?: WebAssembly.Memory | (() => WebAssembly.Memory)): WebAssembly.Instance;
|
|
36
|
+
|
|
37
|
+
export declare function isSharedArrayBuffer(value: any): value is SharedArrayBuffer;
|
|
38
|
+
|
|
39
|
+
export declare function isTrapError(e: Error): e is WebAssembly.RuntimeError;
|
|
40
|
+
|
|
41
|
+
export declare interface LoadedPayload {
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export declare interface LoadPayload {
|
|
45
|
+
wasmModule: WebAssembly.Module;
|
|
46
|
+
wasmMemory: WebAssembly.Memory;
|
|
47
|
+
sab?: Int32Array;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export declare interface MainThreadBaseOptions extends BaseOptions {
|
|
51
|
+
waitThreadStart?: boolean | number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export declare type MainThreadOptions = MainThreadOptionsWithThreadManager | MainThreadOptionsCreateThreadManager;
|
|
55
|
+
|
|
56
|
+
export declare interface MainThreadOptionsCreateThreadManager extends MainThreadBaseOptions, ThreadManagerOptionsMain {
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export declare interface MainThreadOptionsWithThreadManager extends MainThreadBaseOptions {
|
|
60
|
+
threadManager?: ThreadManager | (() => ThreadManager);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export declare interface MessageEventData<T extends CommandType> {
|
|
64
|
+
__emnapi__: CommandInfo<T>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export declare interface ReuseWorkerOptions {
|
|
68
|
+
size: number;
|
|
69
|
+
strict?: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export declare interface SerializedError {
|
|
73
|
+
name: string;
|
|
74
|
+
message: string;
|
|
75
|
+
stack?: string;
|
|
76
|
+
cause?: unknown;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export declare interface SpawnThreadPayload {
|
|
80
|
+
startArg: number;
|
|
81
|
+
errorOrTid: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export declare interface StartPayload {
|
|
85
|
+
tid: number;
|
|
86
|
+
arg: number;
|
|
87
|
+
sab?: Int32Array;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export declare interface StartResult {
|
|
91
|
+
exitCode: number;
|
|
92
|
+
instance: WebAssembly.Instance;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export declare interface TerminateAllThreadsPayload {
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export declare interface ThreadErrorPayload {
|
|
99
|
+
error: SerializedError;
|
|
100
|
+
phase: ThreadFailurePhase;
|
|
101
|
+
tid?: number;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export declare type ThreadFailurePhase = 'load' | 'start' | 'async-work' | 'message' | 'messageerror' | 'exit';
|
|
105
|
+
|
|
106
|
+
export declare class ThreadManager {
|
|
107
|
+
unusedWorkers: WorkerLike[];
|
|
108
|
+
pthreads: Record<number, WorkerLike>;
|
|
109
|
+
get nextWorkerID(): number;
|
|
110
|
+
wasmModule: WebAssembly.Module | null;
|
|
111
|
+
wasmMemory: WebAssembly.Memory | null;
|
|
112
|
+
private readonly messageEvents;
|
|
113
|
+
private readonly registeredWorkers;
|
|
114
|
+
private readonly expectedTerminations;
|
|
115
|
+
private readonly loadRejects;
|
|
116
|
+
private _fatalError;
|
|
117
|
+
private readonly _childThread;
|
|
118
|
+
private readonly _onCreateWorker;
|
|
119
|
+
private readonly _reuseWorker;
|
|
120
|
+
private readonly _beforeLoad?;
|
|
121
|
+
readonly printErr: (message: string) => void;
|
|
122
|
+
threadSpawn?: ((startArg: number, errorOrTid?: number) => number);
|
|
123
|
+
constructor(options: ThreadManagerOptions);
|
|
124
|
+
init(): void;
|
|
125
|
+
initMainThread(): void;
|
|
126
|
+
private preparePool;
|
|
127
|
+
shouldPreloadWorkers(): boolean;
|
|
128
|
+
loadWasmModuleToAllWorkers(): Promise<WorkerLike[]>;
|
|
129
|
+
preloadWorkers(): Promise<WorkerLike[]>;
|
|
130
|
+
setup(wasmModule: WebAssembly.Module, wasmMemory: WebAssembly.Memory): void;
|
|
131
|
+
private assertRunning;
|
|
132
|
+
private fail;
|
|
133
|
+
markId(worker: WorkerLike): number;
|
|
134
|
+
returnWorkerToPool(worker: WorkerLike): void;
|
|
135
|
+
loadWasmModuleToWorker(worker: WorkerLike, sab?: Int32Array): Promise<WorkerLike>;
|
|
136
|
+
allocateUnusedWorker(): WorkerLike;
|
|
137
|
+
getNewWorker(sab?: Int32Array): WorkerLike | undefined;
|
|
138
|
+
cleanThread(worker: WorkerLike, tid: number, force?: boolean): void;
|
|
139
|
+
terminateWorker(worker: WorkerLike): void;
|
|
140
|
+
terminateAllThreads(): void;
|
|
141
|
+
private shutdownAllWorkers;
|
|
142
|
+
addMessageEventListener(worker: WorkerLike, onMessage: (e: WorkerMessageEvent) => void): () => void;
|
|
143
|
+
fireMessageEvent(worker: WorkerLike, e: WorkerMessageEvent): void;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export declare type ThreadManagerOptions = ThreadManagerOptionsMain | ThreadManagerOptionsChild;
|
|
147
|
+
|
|
148
|
+
export declare interface ThreadManagerOptionsBase {
|
|
149
|
+
printErr?: (message: string) => void;
|
|
150
|
+
threadSpawn?: (startArg: number, errorOrTid?: number) => number;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export declare interface ThreadManagerOptionsChild extends ThreadManagerOptionsBase {
|
|
154
|
+
childThread: true;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export declare interface ThreadManagerOptionsMain extends ThreadManagerOptionsBase {
|
|
158
|
+
beforeLoad?: (worker: WorkerLike) => any;
|
|
159
|
+
reuseWorker?: boolean | number | ReuseWorkerOptions;
|
|
160
|
+
onCreateWorker: WorkerFactory;
|
|
161
|
+
childThread?: false;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export declare class ThreadMessageHandler {
|
|
165
|
+
protected instance: WebAssembly.Instance | undefined;
|
|
166
|
+
private messagesBeforeLoad;
|
|
167
|
+
protected postMessage: (message: any) => void;
|
|
168
|
+
protected onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
|
|
169
|
+
protected onError: (error: Error, type: WorkerMessageType) => void;
|
|
170
|
+
constructor(options?: ThreadMessageHandlerOptions);
|
|
171
|
+
instantiate(data: LoadPayload): WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
|
|
172
|
+
handle(e: WorkerMessageEvent<MessageEventData<WorkerMessageType>>): void;
|
|
173
|
+
private _load;
|
|
174
|
+
private _start;
|
|
175
|
+
protected _loaded(err: Error | null, source: WebAssembly.WebAssemblyInstantiatedSource | null, payload: LoadPayload): void;
|
|
176
|
+
protected handleAfterLoad<E extends WorkerMessageEvent>(e: E, f: (e: E) => void): void;
|
|
177
|
+
protected beforeReportError(_error: Error, _type: WorkerMessageType | 'async-worker-init', _tid?: number): void;
|
|
178
|
+
protected reportError(value: unknown, type: WorkerMessageType | 'async-worker-init', tid?: number): void;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export declare interface ThreadMessageHandlerOptions {
|
|
182
|
+
onLoad?: (data: LoadPayload) => WebAssembly.WebAssemblyInstantiatedSource | PromiseLike<WebAssembly.WebAssemblyInstantiatedSource>;
|
|
183
|
+
onError?: (error: Error, type: WorkerMessageType) => void;
|
|
184
|
+
postMessage?: (message: any) => void;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export declare interface WASIInstance {
|
|
188
|
+
readonly wasiImport?: Record<string, any>;
|
|
189
|
+
initialize(instance: object): void;
|
|
190
|
+
start(instance: object): number;
|
|
191
|
+
getImportObject?(): any;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export declare class WASIThreads {
|
|
195
|
+
PThread: ThreadManager | undefined;
|
|
196
|
+
private wasmMemory;
|
|
197
|
+
private wasmInstance;
|
|
198
|
+
private readonly threadSpawn;
|
|
199
|
+
readonly childThread: boolean;
|
|
200
|
+
private readonly postMessage;
|
|
201
|
+
readonly wasi: WASIInstance;
|
|
202
|
+
constructor(options: WASIThreadsOptions);
|
|
203
|
+
getImportObject(): {
|
|
204
|
+
wasi: WASIThreadsImports;
|
|
205
|
+
};
|
|
206
|
+
setup(wasmInstance: WebAssembly.Instance, wasmModule: WebAssembly.Module, wasmMemory?: WebAssembly.Memory): void;
|
|
207
|
+
preloadWorkers(): Promise<WorkerLike[]>;
|
|
208
|
+
initialize(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): WebAssembly.Instance;
|
|
209
|
+
start(instance: WebAssembly.Instance, module: WebAssembly.Module, memory?: WebAssembly.Memory): StartResult;
|
|
210
|
+
terminateAllThreads(): void;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export declare interface WASIThreadsImports {
|
|
214
|
+
'thread-spawn': (startArg: number, errorOrTid?: number) => number;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export declare type WASIThreadsOptions = MainThreadOptions | ChildThreadOptions;
|
|
218
|
+
|
|
219
|
+
export declare type WorkerFactory = (ctx: {
|
|
220
|
+
type: string;
|
|
221
|
+
name: string;
|
|
222
|
+
}) => WorkerLike;
|
|
223
|
+
|
|
224
|
+
export declare type WorkerLike = (Worker | Worker_2) & {
|
|
225
|
+
whenLoaded?: Promise<WorkerLike>;
|
|
226
|
+
loaded?: boolean;
|
|
227
|
+
__emnapi_tid?: number;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
export declare interface WorkerMessageEvent<T = any> {
|
|
231
|
+
data: T;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export declare type WorkerMessageType = 'load' | 'start';
|
|
235
|
+
|
|
236
|
+
export { }
|