@downcity/sandbox-microsandbox 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,183 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ https://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form,
34
+ made available under the License, as indicated by a copyright notice that is
35
+ included in or attached to the work (an example is provided in the Appendix
36
+ below).
37
+
38
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
39
+ is based on (or derived from) the Work and for which the editorial revisions,
40
+ annotations, elaborations, or other modifications represent, as a whole, an
41
+ original work of authorship. For the purposes of this License, Derivative Works
42
+ shall not include works that remain separable from, or merely link (or bind by
43
+ name) to the interfaces of, the Work and Derivative Works thereof.
44
+
45
+ "Contribution" shall mean any work of authorship, including the original version
46
+ of the Work and any modifications or additions to that Work or Derivative Works
47
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
48
+ by the copyright owner or by an individual or Legal Entity authorized to submit
49
+ on behalf of the copyright owner. For the purposes of this definition,
50
+ "submitted" means any form of electronic, verbal, or written communication sent
51
+ to the Licensor or its representatives, including but not limited to
52
+ communication on electronic mailing lists, source code control systems, and
53
+ issue tracking systems that are managed by, or on behalf of, the Licensor for
54
+ the purpose of discussing and improving the Work, but excluding communication
55
+ that is conspicuously marked or otherwise designated in writing by the copyright
56
+ owner as "Not a Contribution."
57
+
58
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
59
+ of whom a Contribution has been received by Licensor and subsequently
60
+ incorporated within the Work.
61
+
62
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
63
+ License, each Contributor hereby grants to You a perpetual, worldwide,
64
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
65
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
66
+ sublicense, and distribute the Work and such Derivative Works in Source or
67
+ Object form.
68
+
69
+ 3. Grant of Patent License. Subject to the terms and conditions of this License,
70
+ each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
71
+ no-charge, royalty-free, irrevocable (except as stated in this section) patent
72
+ license to make, have made, use, offer to sell, sell, import, and otherwise
73
+ transfer the Work, where such license applies only to those patent claims
74
+ licensable by such Contributor that are necessarily infringed by their
75
+ Contribution(s) alone or by combination of their Contribution(s) with the Work
76
+ to which such Contribution(s) was submitted. If You institute patent litigation
77
+ against any entity (including a cross-claim or counterclaim in a lawsuit)
78
+ alleging that the Work or a Contribution incorporated within the Work
79
+ constitutes direct or contributory patent infringement, then any patent licenses
80
+ granted to You under this License for that Work shall terminate as of the date
81
+ such litigation is filed.
82
+
83
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
84
+ Derivative Works thereof in any medium, with or without modifications, and in
85
+ Source or Object form, provided that You meet the following conditions:
86
+
87
+ (a) You must give any other recipients of the Work or Derivative Works a copy of
88
+ this License; and
89
+
90
+ (b) You must cause any modified files to carry prominent notices stating that
91
+ You changed the files; and
92
+
93
+ (c) You must retain, in the Source form of any Derivative Works that You
94
+ distribute, all copyright, patent, trademark, and attribution notices from the
95
+ Source form of the Work, excluding those notices that do not pertain to any part
96
+ of the Derivative Works; and
97
+
98
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then
99
+ any Derivative Works that You distribute must include a readable copy of the
100
+ attribution notices contained within such NOTICE file, excluding those notices
101
+ that do not pertain to any part of the Derivative Works, in at least one of the
102
+ following places: within a NOTICE text file distributed as part of the
103
+ Derivative Works; within the Source form or documentation, if provided along
104
+ with the Derivative Works; or, within a display generated by the Derivative
105
+ Works, if and wherever such third-party notices normally appear. The contents of
106
+ the NOTICE file are for informational purposes only and do not modify the
107
+ License. You may add Your own attribution notices within Derivative Works that
108
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
109
+ provided that such additional attribution notices cannot be construed as
110
+ modifying the License.
111
+
112
+ You may add Your own copyright statement to Your modifications and may provide
113
+ additional or different license terms and conditions for use, reproduction, or
114
+ distribution of Your modifications, or for any such Derivative Works as a whole,
115
+ provided Your use, reproduction, and distribution of the Work otherwise complies
116
+ with the conditions stated in this License.
117
+
118
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
119
+ Contribution intentionally submitted for inclusion in the Work by You to the
120
+ Licensor shall be under the terms and conditions of this License, without any
121
+ additional terms or conditions. Notwithstanding the above, nothing herein shall
122
+ supersede or modify the terms of any separate license agreement you may have
123
+ executed with Licensor regarding such Contributions.
124
+
125
+ 6. Trademarks. This License does not grant permission to use the trade names,
126
+ trademarks, service marks, or product names of the Licensor, except as required
127
+ for reasonable and customary use in describing the origin of the Work and
128
+ reproducing the content of the NOTICE file.
129
+
130
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
131
+ writing, Licensor provides the Work (and each Contributor provides its
132
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
133
+ KIND, either express or implied, including, without limitation, any warranties or
134
+ conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
135
+ PARTICULAR PURPOSE. You are solely responsible for determining the
136
+ appropriateness of using or redistributing the Work and assume any risks
137
+ associated with Your exercise of permissions under this License.
138
+
139
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
140
+ tort (including negligence), contract, or otherwise, unless required by
141
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
142
+ writing, shall any Contributor be liable to You for damages, including any
143
+ direct, indirect, special, incidental, or consequential damages of any character
144
+ arising as a result of this License or out of the use or inability to use the
145
+ Work (including but not limited to damages for loss of goodwill, work stoppage,
146
+ computer failure or malfunction, or any and all other commercial damages or
147
+ losses), even if such Contributor has been advised of the possibility of such
148
+ damages.
149
+
150
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
151
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
152
+ acceptance of support, warranty, indemnity, or other liability obligations
153
+ and/or rights consistent with this License. However, in accepting such
154
+ obligations, You may act only on Your own behalf and on Your sole
155
+ responsibility, not on behalf of any other Contributor, and only if You agree to
156
+ indemnify, defend, and hold each Contributor harmless for any liability incurred
157
+ by, or claims asserted against, such Contributor by reason of your accepting any
158
+ such warranty or additional liability.
159
+
160
+ END OF TERMS AND CONDITIONS
161
+
162
+ APPENDIX: How to apply the Apache License to your work.
163
+
164
+ To apply the Apache License to your work, attach the following boilerplate
165
+ notice, with the fields enclosed by brackets "[]" replaced with your own
166
+ identifying information. (Do not include the brackets!) The text should be
167
+ enclosed in the appropriate comment syntax for the file format. We also
168
+ recommend that a file or class name and description of purpose be included on
169
+ the same "printed page" as the copyright notice for easier identification within
170
+ third-party archives.
171
+
172
+ Copyright [yyyy] [name of copyright owner]
173
+
174
+ Licensed under the Apache License, Version 2.0 (the "License");
175
+ you may not use this file except in compliance with the License.
176
+ You may obtain a copy of the License at
177
+
178
+ https://www.apache.org/licenses/LICENSE-2.0
179
+
180
+ Unless required by applicable law or agreed to in writing, software distributed
181
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
182
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
183
+ specific language governing permissions and limitations under the License.
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Microsandbox 流式命令句柄适配。
3
+ *
4
+ * 关键点(中文)
5
+ * - microsandbox 通过异步事件流提供进程输出,Downcity Shell 使用回调协议。
6
+ * - 终态和早到输出都会缓存,避免短命令在监听器注册前结束而丢失事件。
7
+ */
8
+ import type { ShellProcessHandle } from "@downcity/type/shell";
9
+ import type { ExecHandle } from "microsandbox";
10
+ /** Microsandbox ExecHandle 的 Downcity 适配器。 */
11
+ export declare class MicrosandboxProcessHandle implements ShellProcessHandle {
12
+ private readonly handle;
13
+ /** 当前进程在 guest 内的 PID。 */
14
+ pid?: number;
15
+ /** stdin sink 的唯一获取流程。 */
16
+ private readonly stdin_promise;
17
+ /** 尚未交给首个输出监听器的早到输出。 */
18
+ private readonly pending_data;
19
+ /** 当前输出监听器集合。 */
20
+ private readonly data_callbacks;
21
+ /** 当前退出监听器集合。 */
22
+ private readonly exit_callbacks;
23
+ /** 当前错误监听器集合。 */
24
+ private readonly error_callbacks;
25
+ /** 当前句柄的唯一终态。 */
26
+ private terminal_event;
27
+ /** stdin 是否仍允许写入。 */
28
+ private stdin_writable;
29
+ constructor(handle: ExecHandle);
30
+ /** 当前 stdin 是否仍允许写入。 */
31
+ get writable(): boolean;
32
+ /** 注册输出监听器,并补发监听前到达的输出。 */
33
+ on_data(callback: (chunk: string | Buffer) => void): void;
34
+ /** 注册退出监听器。 */
35
+ on_exit(callback: (exit_code: number) => void): void;
36
+ /** 注册错误监听器。 */
37
+ on_error(callback: (error: Error) => void): void;
38
+ /** 向 guest 进程 stdin 写入原始字符。 */
39
+ write(chars: string): Promise<void>;
40
+ /** 关闭非交互进程 stdin。 */
41
+ close_stdin(): void;
42
+ /** 向 guest 进程发送终止信号。 */
43
+ kill(signal?: NodeJS.Signals): void;
44
+ /** 持续消费 microsandbox 事件流。 */
45
+ private pump_events;
46
+ /** 发布一段进程输出。 */
47
+ private publish_data;
48
+ /** 隔离单个输出观察者异常,避免破坏底层事件流。 */
49
+ private invoke_data_callback;
50
+ /** 提交唯一终态并通知当前监听器。 */
51
+ private settle;
52
+ }
53
+ //# sourceMappingURL=MicrosandboxProcessHandle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MicrosandboxProcessHandle.d.ts","sourceRoot":"","sources":["../src/MicrosandboxProcessHandle.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,cAAc,CAAC;AA2BzD,8CAA8C;AAC9C,qBAAa,yBAA0B,YAAW,kBAAkB;IAyBtD,OAAO,CAAC,QAAQ,CAAC,MAAM;IAxBnC,0BAA0B;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,0BAA0B;IAC1B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA2B;IAEzD,wBAAwB;IACxB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA8B;IAE3D,iBAAiB;IACjB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA+C;IAE9E,iBAAiB;IACjB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA0C;IAEzE,iBAAiB;IACjB,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAqC;IAErE,iBAAiB;IACjB,OAAO,CAAC,cAAc,CAA8B;IAEpD,qBAAqB;IACrB,OAAO,CAAC,cAAc,CAAQ;gBAED,MAAM,EAAE,UAAU;IAK/C,wBAAwB;IACxB,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,2BAA2B;IAC3B,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,KAAK,IAAI,GAAG,IAAI;IASzD,eAAe;IACf,OAAO,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IASpD,eAAe;IACf,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,IAAI;IAShD,+BAA+B;IACzB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOzC,qBAAqB;IACrB,WAAW,IAAI,IAAI;IAQnB,wBAAwB;IACxB,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI;IASnC,6BAA6B;YACf,WAAW;IA2BzB,gBAAgB;IAChB,OAAO,CAAC,YAAY;IAQpB,6BAA6B;IAC7B,OAAO,CAAC,oBAAoB;IAW5B,sBAAsB;IACtB,OAAO,CAAC,MAAM;CAYf"}
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Microsandbox 流式命令句柄适配。
3
+ *
4
+ * 关键点(中文)
5
+ * - microsandbox 通过异步事件流提供进程输出,Downcity Shell 使用回调协议。
6
+ * - 终态和早到输出都会缓存,避免短命令在监听器注册前结束而丢失事件。
7
+ */
8
+ import { constants as os_constants } from "node:os";
9
+ /** 把任意抛出值归一化为 Error。 */
10
+ function normalize_error(error) {
11
+ return error instanceof Error ? error : new Error(String(error));
12
+ }
13
+ /** 将 Node signal 名称映射为 Linux guest 使用的 signal number。 */
14
+ function resolve_signal_number(signal) {
15
+ const signal_name = signal || "SIGTERM";
16
+ return os_constants.signals[signal_name] || 15;
17
+ }
18
+ /** Microsandbox ExecHandle 的 Downcity 适配器。 */
19
+ export class MicrosandboxProcessHandle {
20
+ handle;
21
+ /** 当前进程在 guest 内的 PID。 */
22
+ pid;
23
+ /** stdin sink 的唯一获取流程。 */
24
+ stdin_promise;
25
+ /** 尚未交给首个输出监听器的早到输出。 */
26
+ pending_data = [];
27
+ /** 当前输出监听器集合。 */
28
+ data_callbacks = new Set();
29
+ /** 当前退出监听器集合。 */
30
+ exit_callbacks = new Set();
31
+ /** 当前错误监听器集合。 */
32
+ error_callbacks = new Set();
33
+ /** 当前句柄的唯一终态。 */
34
+ terminal_event = null;
35
+ /** stdin 是否仍允许写入。 */
36
+ stdin_writable = true;
37
+ constructor(handle) {
38
+ this.handle = handle;
39
+ this.stdin_promise = handle.takeStdin();
40
+ void this.pump_events();
41
+ }
42
+ /** 当前 stdin 是否仍允许写入。 */
43
+ get writable() {
44
+ return this.stdin_writable && !this.terminal_event;
45
+ }
46
+ /** 注册输出监听器,并补发监听前到达的输出。 */
47
+ on_data(callback) {
48
+ this.data_callbacks.add(callback);
49
+ if (this.pending_data.length === 0)
50
+ return;
51
+ const pending_data = this.pending_data.splice(0);
52
+ queueMicrotask(() => {
53
+ for (const chunk of pending_data)
54
+ this.invoke_data_callback(callback, chunk);
55
+ });
56
+ }
57
+ /** 注册退出监听器。 */
58
+ on_exit(callback) {
59
+ if (this.terminal_event?.kind === "exit") {
60
+ const exit_code = this.terminal_event.exit_code;
61
+ queueMicrotask(() => callback(exit_code));
62
+ return;
63
+ }
64
+ if (!this.terminal_event)
65
+ this.exit_callbacks.add(callback);
66
+ }
67
+ /** 注册错误监听器。 */
68
+ on_error(callback) {
69
+ if (this.terminal_event?.kind === "error") {
70
+ const error = this.terminal_event.error;
71
+ queueMicrotask(() => callback(error));
72
+ return;
73
+ }
74
+ if (!this.terminal_event)
75
+ this.error_callbacks.add(callback);
76
+ }
77
+ /** 向 guest 进程 stdin 写入原始字符。 */
78
+ async write(chars) {
79
+ if (!this.writable)
80
+ throw new Error("Microsandbox process stdin is closed");
81
+ const stdin = await this.stdin_promise;
82
+ if (!stdin)
83
+ throw new Error("Microsandbox process stdin is unavailable");
84
+ await stdin.write(chars);
85
+ }
86
+ /** 关闭非交互进程 stdin。 */
87
+ close_stdin() {
88
+ if (!this.stdin_writable)
89
+ return;
90
+ this.stdin_writable = false;
91
+ void this.stdin_promise
92
+ .then(async (stdin) => await stdin?.close())
93
+ .catch((error) => this.settle({ kind: "error", error: normalize_error(error) }));
94
+ }
95
+ /** 向 guest 进程发送终止信号。 */
96
+ kill(signal) {
97
+ const operation = signal === "SIGKILL"
98
+ ? this.handle.kill()
99
+ : this.handle.signal(resolve_signal_number(signal));
100
+ void operation.catch((error) => {
101
+ this.settle({ kind: "error", error: normalize_error(error) });
102
+ });
103
+ }
104
+ /** 持续消费 microsandbox 事件流。 */
105
+ async pump_events() {
106
+ try {
107
+ for await (const event of this.handle) {
108
+ if (event.kind === "started") {
109
+ this.pid = event.pid;
110
+ continue;
111
+ }
112
+ if (event.kind === "stdout" || event.kind === "stderr") {
113
+ this.publish_data(Buffer.from(event.data));
114
+ continue;
115
+ }
116
+ if (event.kind === "exited") {
117
+ this.settle({ kind: "exit", exit_code: event.code });
118
+ return;
119
+ }
120
+ }
121
+ if (!this.terminal_event) {
122
+ this.settle({
123
+ kind: "error",
124
+ error: new Error("Microsandbox process event stream ended before exit"),
125
+ });
126
+ }
127
+ }
128
+ catch (error) {
129
+ this.settle({ kind: "error", error: normalize_error(error) });
130
+ }
131
+ }
132
+ /** 发布一段进程输出。 */
133
+ publish_data(chunk) {
134
+ if (this.data_callbacks.size === 0) {
135
+ this.pending_data.push(chunk);
136
+ return;
137
+ }
138
+ for (const callback of this.data_callbacks)
139
+ this.invoke_data_callback(callback, chunk);
140
+ }
141
+ /** 隔离单个输出观察者异常,避免破坏底层事件流。 */
142
+ invoke_data_callback(callback, chunk) {
143
+ try {
144
+ callback(chunk);
145
+ }
146
+ catch {
147
+ // 输出观察者不拥有 guest 进程,失败不能中断事件流。
148
+ }
149
+ }
150
+ /** 提交唯一终态并通知当前监听器。 */
151
+ settle(event) {
152
+ if (this.terminal_event)
153
+ return;
154
+ this.terminal_event = event;
155
+ this.stdin_writable = false;
156
+ if (event.kind === "exit") {
157
+ for (const callback of this.exit_callbacks)
158
+ callback(event.exit_code);
159
+ }
160
+ else {
161
+ for (const callback of this.error_callbacks)
162
+ callback(event.error);
163
+ }
164
+ this.exit_callbacks.clear();
165
+ this.error_callbacks.clear();
166
+ }
167
+ }
168
+ //# sourceMappingURL=MicrosandboxProcessHandle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MicrosandboxProcessHandle.js","sourceRoot":"","sources":["../src/MicrosandboxProcessHandle.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,SAAS,CAAC;AAkBpD,wBAAwB;AACxB,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACnE,CAAC;AAED,yDAAyD;AACzD,SAAS,qBAAqB,CAAC,MAAkC;IAC/D,MAAM,WAAW,GAAG,MAAM,IAAI,SAAS,CAAC;IACxC,OAAO,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;AACjD,CAAC;AAED,8CAA8C;AAC9C,MAAM,OAAO,yBAAyB;IAyBP;IAxB7B,0BAA0B;IAC1B,GAAG,CAAU;IAEb,0BAA0B;IACT,aAAa,CAA2B;IAEzD,wBAAwB;IACP,YAAY,GAA2B,EAAE,CAAC;IAE3D,iBAAiB;IACA,cAAc,GAAG,IAAI,GAAG,EAAoC,CAAC;IAE9E,iBAAiB;IACA,cAAc,GAAG,IAAI,GAAG,EAA+B,CAAC;IAEzE,iBAAiB;IACA,eAAe,GAAG,IAAI,GAAG,EAA0B,CAAC;IAErE,iBAAiB;IACT,cAAc,GAAyB,IAAI,CAAC;IAEpD,qBAAqB;IACb,cAAc,GAAG,IAAI,CAAC;IAE9B,YAA6B,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAC7C,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;QACxC,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC;IAC1B,CAAC;IAED,wBAAwB;IACxB,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,c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QAAQ,EAAE,KAAK,CAAC,CAAC;IACzF,CAAC;IAED,6BAA6B;IACrB,oBAAoB,CAC1B,QAA0C,EAC1C,KAAsB;QAEtB,IAAI,CAAC;YACH,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;QAAC,MAAM,CAAC;YACP,+BAA+B;QACjC,CAAC;IACH,CAAC;IAED,sBAAsB;IACd,MAAM,CAAC,KAAoB;QACjC,IAAI,IAAI,CAAC,cAAc;YAAE,OAAO;QAChC,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;QAC5B,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;QAC5B,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC1B,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,cAAc;gBAAE,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACxE,CAAC;aAAM,CAAC;YACN,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,eAAe;gBAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrE,CAAC;QACD,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;QAC5B,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;CACF"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Downcity microsandbox Provider。
3
+ *
4
+ * Shell 显式持有此 Provider,并用它为绑定的 Workspace 创建独立、稳定命名且可恢复的
5
+ * microVM 文件系统。microsandbox daemon、镜像缓存等属于外部基础设施,不归 Provider 生命周期所有。
6
+ */
7
+ import type { SandboxProvider, SandboxProviderStatus, WorkspaceSandbox, WorkspaceSandboxBinding } from "@downcity/type/shell";
8
+ import type { MicrosandboxProviderOptions } from "./types/MicrosandboxProvider.js";
9
+ /** 基于 microsandbox 的默认 Workspace Sandbox Provider。 */
10
+ export declare class MicrosandboxProvider implements SandboxProvider {
11
+ /** Provider 稳定后端标识。 */
12
+ readonly backend = "microsandbox";
13
+ /** 新建 Sandbox 使用的 OCI 镜像。 */
14
+ private readonly image;
15
+ /** 新建 Sandbox 使用的虚拟 CPU 数量。 */
16
+ private readonly cpus;
17
+ /** 新建 Sandbox 使用的内存,单位 MiB。 */
18
+ private readonly memory_mib;
19
+ constructor(options?: MicrosandboxProviderOptions);
20
+ /** 检查本机平台与 microsandbox runtime 是否可用。 */
21
+ check(): Promise<SandboxProviderStatus>;
22
+ /** 为 Workspace 创建延迟连接的持久 Sandbox。 */
23
+ create_workspace(binding: WorkspaceSandboxBinding): WorkspaceSandbox;
24
+ }
25
+ //# sourceMappingURL=MicrosandboxProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MicrosandboxProvider.d.ts","sourceRoot":"","sources":["../src/MicrosandboxProvider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EACV,eAAe,EAEf,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACxB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAoCnF,sDAAsD;AACtD,qBAAa,oBAAqB,YAAW,eAAe;IAC1D,uBAAuB;IACvB,QAAQ,CAAC,OAAO,kBAAkB;IAElC,6BAA6B;IAC7B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAE/B,+BAA+B;IAC/B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAE9B,+BAA+B;IAC/B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAExB,OAAO,GAAE,2BAAgC;IAMrD,yCAAyC;IACnC,KAAK,IAAI,OAAO,CAAC,qBAAqB,CAAC;IAsB7C,qCAAqC;IACrC,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,gBAAgB;CAsBrE"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Downcity microsandbox Provider。
3
+ *
4
+ * Shell 显式持有此 Provider,并用它为绑定的 Workspace 创建独立、稳定命名且可恢复的
5
+ * microVM 文件系统。microsandbox daemon、镜像缓存等属于外部基础设施,不归 Provider 生命周期所有。
6
+ */
7
+ import { createHash } from "node:crypto";
8
+ import path from "node:path";
9
+ import { isInstalled } from "microsandbox";
10
+ import { MicrosandboxWorkspace } from "./MicrosandboxWorkspace.js";
11
+ const DEFAULT_IMAGE = "node:22-bookworm";
12
+ const DEFAULT_CPUS = 2;
13
+ const DEFAULT_MEMORY_MIB = 2048;
14
+ /** 判断当前操作系统与架构是否由 microsandbox npm 包支持。 */
15
+ function is_supported_platform() {
16
+ if (process.platform === "darwin")
17
+ return process.arch === "arm64";
18
+ if (process.platform === "linux")
19
+ return process.arch === "x64" || process.arch === "arm64";
20
+ if (process.platform === "win32")
21
+ return process.arch === "x64" || process.arch === "arm64";
22
+ return false;
23
+ }
24
+ /** 归一化正整数资源参数。 */
25
+ function resolve_positive_integer(value, fallback) {
26
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0)
27
+ return fallback;
28
+ return Math.floor(value);
29
+ }
30
+ /** 生成可读且满足 microsandbox 命名约束的片段。 */
31
+ function normalize_name_segment(value) {
32
+ const normalized = value
33
+ .toLowerCase()
34
+ .replace(/[^a-z0-9_-]+/g, "-")
35
+ .replace(/^-+|-+$/g, "");
36
+ return normalized.slice(0, 48) || "workspace";
37
+ }
38
+ /** 根据 Workspace 身份和 Shell 运行目录生成跨进程稳定名称。 */
39
+ function create_sandbox_name(binding) {
40
+ const identity = `${path.resolve(binding.runtime_path)}\0${binding.workspace_id}`;
41
+ const digest = createHash("sha256").update(identity).digest("hex").slice(0, 20);
42
+ return `downcity-${normalize_name_segment(binding.workspace_id)}-${digest}`;
43
+ }
44
+ /** 基于 microsandbox 的默认 Workspace Sandbox Provider。 */
45
+ export class MicrosandboxProvider {
46
+ /** Provider 稳定后端标识。 */
47
+ backend = "microsandbox";
48
+ /** 新建 Sandbox 使用的 OCI 镜像。 */
49
+ image;
50
+ /** 新建 Sandbox 使用的虚拟 CPU 数量。 */
51
+ cpus;
52
+ /** 新建 Sandbox 使用的内存,单位 MiB。 */
53
+ memory_mib;
54
+ constructor(options = {}) {
55
+ this.image = String(options.image || DEFAULT_IMAGE).trim() || DEFAULT_IMAGE;
56
+ this.cpus = resolve_positive_integer(options.cpus, DEFAULT_CPUS);
57
+ this.memory_mib = resolve_positive_integer(options.memory_mib, DEFAULT_MEMORY_MIB);
58
+ }
59
+ /** 检查本机平台与 microsandbox runtime 是否可用。 */
60
+ async check() {
61
+ const issues = [];
62
+ if (!is_supported_platform()) {
63
+ issues.push({
64
+ code: "unsupported_platform",
65
+ message: `microsandbox does not support ${process.platform}/${process.arch}`,
66
+ fixes: ["Use a supported macOS ARM64, Linux x64/ARM64, or Windows x64/ARM64 host."],
67
+ });
68
+ }
69
+ else if (!isInstalled()) {
70
+ issues.push({
71
+ code: "runtime_not_installed",
72
+ message: "microsandbox runtime is not installed or is not runnable",
73
+ fixes: ["Run `npx microsandbox setup` and retry."],
74
+ });
75
+ }
76
+ return {
77
+ ok: issues.length === 0,
78
+ backend: this.backend,
79
+ issues,
80
+ };
81
+ }
82
+ /** 为 Workspace 创建延迟连接的持久 Sandbox。 */
83
+ create_workspace(binding) {
84
+ const workspace_id = String(binding.workspace_id || "").trim();
85
+ const workspace_path = String(binding.workspace_path || "").trim();
86
+ const runtime_path = String(binding.runtime_path || "").trim();
87
+ if (!workspace_id || !workspace_path || !runtime_path) {
88
+ throw new Error("MicrosandboxProvider.create_workspace requires workspace_id, workspace_path and runtime_path");
89
+ }
90
+ const normalized_binding = {
91
+ workspace_id,
92
+ workspace_path: path.resolve(workspace_path),
93
+ runtime_path: path.resolve(runtime_path),
94
+ };
95
+ return new MicrosandboxWorkspace({
96
+ binding: normalized_binding,
97
+ name: create_sandbox_name(normalized_binding),
98
+ image: this.image,
99
+ cpus: this.cpus,
100
+ memory_mib: this.memory_mib,
101
+ });
102
+ }
103
+ }
104
+ //# sourceMappingURL=MicrosandboxProvider.js.map
@@ -0,0 +1 @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,EAAE,IAAI,CAAC,KAAK;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * 单个 Workspace 的 microsandbox 隔离环境。
3
+ *
4
+ * 关键点(中文)
5
+ * - 稳定名称用于跨进程恢复同一个可写 rootfs 与 HOME。
6
+ * - 宿主项目只通过固定 guest `/workspace` bind mount 显式进入 microVM。
7
+ * - 普通 stop 只释放计算资源;reset 才删除持久状态。
8
+ */
9
+ import type { SandboxProcessRequest, ShellProcessResult, WorkspaceSandbox, WorkspaceSandboxBinding } from "@downcity/type/shell";
10
+ /** Microsandbox Workspace 创建参数。 */
11
+ export interface MicrosandboxWorkspaceOptions {
12
+ /** Workspace 与宿主运行目录绑定。 */
13
+ binding: WorkspaceSandboxBinding;
14
+ /** microsandbox 数据库中的稳定 Sandbox 名称。 */
15
+ name: string;
16
+ /** 新建 Sandbox 时使用的 OCI 镜像。 */
17
+ image: string;
18
+ /** 新建 Sandbox 时分配的虚拟 CPU 数量。 */
19
+ cpus: number;
20
+ /** 新建 Sandbox 时分配的内存,单位 MiB。 */
21
+ memory_mib: number;
22
+ }
23
+ /** 当前 Workspace 独享的 microsandbox。 */
24
+ export declare class MicrosandboxWorkspace implements WorkspaceSandbox {
25
+ private readonly options;
26
+ /** Provider 后端稳定标识。 */
27
+ readonly backend = "microsandbox";
28
+ /** Workspace 在 guest 中的固定挂载路径。 */
29
+ readonly workspace_path = "/workspace";
30
+ /** Downcity 暴露的稳定 Sandbox 身份。 */
31
+ readonly id: string;
32
+ /** 首次连接或创建的唯一并发流程。 */
33
+ private connect_promise?;
34
+ /** 当前进程持有的 Sandbox 句柄。 */
35
+ private sandbox?;
36
+ constructor(options: MicrosandboxWorkspaceOptions);
37
+ /** 在 Workspace Sandbox 内启动命令。 */
38
+ spawn(request: SandboxProcessRequest): Promise<ShellProcessResult>;
39
+ /** 停止 microVM 计算资源但保留可写 rootfs 与 HOME。 */
40
+ stop(): Promise<void>;
41
+ /** 显式删除当前 Workspace Sandbox 的全部持久状态。 */
42
+ reset(): Promise<void>;
43
+ /** 连接或首次创建稳定命名的 Workspace Sandbox。 */
44
+ private connect;
45
+ /** 创建 builder,并校验已有同名 Sandbox 的绑定没有漂移。 */
46
+ private connect_or_create;
47
+ /** 拒绝把路径变化后的 Workspace 静默连接到旧挂载。 */
48
+ private assert_binding;
49
+ }
50
+ //# sourceMappingURL=MicrosandboxWorkspace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MicrosandboxWorkspace.d.ts","sourceRoot":"","sources":["../src/MicrosandboxWorkspace.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,EAChB,uBAAuB,EACxB,MAAM,sBAAsB,CAAC;AAU9B,mCAAmC;AACnC,MAAM,WAAW,4BAA4B;IAC3C,2BAA2B;IAC3B,OAAO,EAAE,uBAAuB,CAAC;IACjC,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,UAAU,EAAE,MAAM,CAAC;CACpB;AAkBD,qCAAqC;AACrC,qBAAa,qBAAsB,YAAW,gBAAgB;IAgBhD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAfpC,uBAAuB;IACvB,QAAQ,CAAC,OAAO,kBAAkB;IAElC,kCAAkC;IAClC,QAAQ,CAAC,cAAc,gBAAwB;IAE/C,iCAAiC;IACjC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB,sBAAsB;IACtB,OAAO,CAAC,eAAe,CAAC,CAAmB;IAE3C,0BAA0B;IAC1B,OAAO,CAAC,OAAO,CAAC,CAAU;gBAEG,OAAO,EAAE,4BAA4B;IAIlE,iCAAiC;IAC3B,KAAK,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAwBxE,0CAA0C;IACpC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAO3B,wCAAwC;IAClC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B,sCAAsC;YACxB,OAAO;IAYrB,0CAA0C;YAC5B,iBAAiB;IA0B/B,oCAAoC;IACpC,OAAO,CAAC,cAAc;CAgBvB"}
@@ -0,0 +1,136 @@
1
+ /**
2
+ * 单个 Workspace 的 microsandbox 隔离环境。
3
+ *
4
+ * 关键点(中文)
5
+ * - 稳定名称用于跨进程恢复同一个可写 rootfs 与 HOME。
6
+ * - 宿主项目只通过固定 guest `/workspace` bind mount 显式进入 microVM。
7
+ * - 普通 stop 只释放计算资源;reset 才删除持久状态。
8
+ */
9
+ import path from "node:path";
10
+ import { Sandbox } from "microsandbox";
11
+ import { MicrosandboxProcessHandle } from "./MicrosandboxProcessHandle.js";
12
+ const GUEST_WORKSPACE_PATH = "/workspace";
13
+ const LABEL_PROTOCOL = "downcity.protocol";
14
+ const LABEL_WORKSPACE_ID = "downcity.workspace-id";
15
+ const LABEL_WORKSPACE_PATH = "downcity.workspace-path";
16
+ const LABEL_RUNTIME_PATH = "downcity.runtime-path";
17
+ /** 判断未知值是否为普通对象。 */
18
+ function is_record(value) {
19
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
20
+ }
21
+ /** 从 microsandbox 配置中读取标签。 */
22
+ function read_labels(config) {
23
+ const labels = config.labels;
24
+ if (!is_record(labels))
25
+ return {};
26
+ return Object.fromEntries(Object.entries(labels).flatMap(([key, value]) => typeof value === "string" ? [[key, value]] : []));
27
+ }
28
+ /** 当前 Workspace 独享的 microsandbox。 */
29
+ export class MicrosandboxWorkspace {
30
+ options;
31
+ /** Provider 后端稳定标识。 */
32
+ backend = "microsandbox";
33
+ /** Workspace 在 guest 中的固定挂载路径。 */
34
+ workspace_path = GUEST_WORKSPACE_PATH;
35
+ /** Downcity 暴露的稳定 Sandbox 身份。 */
36
+ id;
37
+ /** 首次连接或创建的唯一并发流程。 */
38
+ connect_promise;
39
+ /** 当前进程持有的 Sandbox 句柄。 */
40
+ sandbox;
41
+ constructor(options) {
42
+ this.options = options;
43
+ this.id = options.name;
44
+ }
45
+ /** 在 Workspace Sandbox 内启动命令。 */
46
+ async spawn(request) {
47
+ const sandbox = await this.connect();
48
+ const args = request.login
49
+ ? ["-l", "-c", request.cmd]
50
+ : ["-c", request.cmd];
51
+ const handle = await sandbox.execStreamWith(request.shell_path, (builder) => builder
52
+ .args(args)
53
+ .cwd(request.cwd)
54
+ .envs({ ...request.env })
55
+ .stdinPipe()
56
+ .tty(request.terminal === true));
57
+ if (request.terminal === true) {
58
+ await handle.resize(request.rows || 40, request.cols || 120);
59
+ }
60
+ return {
61
+ child: new MicrosandboxProcessHandle(handle),
62
+ cwd: request.cwd,
63
+ sandbox_id: sandbox.id,
64
+ backend: this.backend,
65
+ };
66
+ }
67
+ /** 停止 microVM 计算资源但保留可写 rootfs 与 HOME。 */
68
+ async stop() {
69
+ const sandbox = this.sandbox;
70
+ this.sandbox = undefined;
71
+ this.connect_promise = undefined;
72
+ if (sandbox)
73
+ await sandbox.stop();
74
+ }
75
+ /** 显式删除当前 Workspace Sandbox 的全部持久状态。 */
76
+ async reset() {
77
+ const sandbox = await this.connect();
78
+ this.sandbox = undefined;
79
+ this.connect_promise = undefined;
80
+ await sandbox.destroy();
81
+ }
82
+ /** 连接或首次创建稳定命名的 Workspace Sandbox。 */
83
+ async connect() {
84
+ if (this.sandbox)
85
+ return this.sandbox;
86
+ this.connect_promise ??= this.connect_or_create();
87
+ try {
88
+ this.sandbox = await this.connect_promise;
89
+ return this.sandbox;
90
+ }
91
+ catch (error) {
92
+ this.connect_promise = undefined;
93
+ throw error;
94
+ }
95
+ }
96
+ /** 创建 builder,并校验已有同名 Sandbox 的绑定没有漂移。 */
97
+ async connect_or_create() {
98
+ const workspace_path = path.resolve(this.options.binding.workspace_path);
99
+ const runtime_path = path.resolve(this.options.binding.runtime_path);
100
+ const sandbox = await Sandbox.builder(this.options.name)
101
+ .image(this.options.image)
102
+ .cpus(this.options.cpus)
103
+ .memory(this.options.memory_mib)
104
+ .workdir(GUEST_WORKSPACE_PATH)
105
+ .shell("/bin/sh")
106
+ .labels({
107
+ [LABEL_PROTOCOL]: "1",
108
+ [LABEL_WORKSPACE_ID]: this.options.binding.workspace_id,
109
+ [LABEL_WORKSPACE_PATH]: workspace_path,
110
+ [LABEL_RUNTIME_PATH]: runtime_path,
111
+ })
112
+ .volume(GUEST_WORKSPACE_PATH, (mount) => mount.bind(workspace_path))
113
+ .connectOrCreate();
114
+ try {
115
+ this.assert_binding(await sandbox.config(), workspace_path, runtime_path);
116
+ return sandbox;
117
+ }
118
+ catch (error) {
119
+ await sandbox.stop().catch(() => undefined);
120
+ throw error;
121
+ }
122
+ }
123
+ /** 拒绝把路径变化后的 Workspace 静默连接到旧挂载。 */
124
+ assert_binding(config, workspace_path, runtime_path) {
125
+ const labels = read_labels(config);
126
+ const matches = labels[LABEL_PROTOCOL] === "1"
127
+ && labels[LABEL_WORKSPACE_ID] === this.options.binding.workspace_id
128
+ && labels[LABEL_WORKSPACE_PATH] === workspace_path
129
+ && labels[LABEL_RUNTIME_PATH] === runtime_path;
130
+ if (matches)
131
+ return;
132
+ throw new Error(`Microsandbox binding changed for Workspace ${this.options.binding.workspace_id}; `
133
+ + "reset the Workspace Sandbox explicitly before reconnecting");
134
+ }
135
+ }
136
+ //# sourceMappingURL=MicrosandboxWorkspace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MicrosandboxWorkspace.js","sourceRoot":"","sources":["../src/MicrosandboxWorkspace.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAO7B,OAAO,EAAE,OAAO,EAAsB,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,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。 */
2
+ export { MicrosandboxProvider } from "./MicrosandboxProvider.js";
3
+ export type { MicrosandboxProviderOptions } from "./types/MicrosandboxProvider.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAE3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,YAAY,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC"}
package/bin/index.js ADDED
@@ -0,0 +1,3 @@
1
+ /** @downcity/sandbox-microsandbox 公开入口。 */
2
+ export { MicrosandboxProvider } from "./MicrosandboxProvider.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAE3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Microsandbox Provider 公开配置类型。
3
+ *
4
+ * 这些参数只描述隔离环境的基础资源,不暴露 microsandbox 的底层构建器,避免
5
+ * Downcity 的公开 API 与单一实现细节绑定。
6
+ */
7
+ /** Microsandbox Provider 构造参数。 */
8
+ export interface MicrosandboxProviderOptions {
9
+ /** Workspace Sandbox 使用的 OCI 镜像;默认包含 Node.js 22 与常用开发工具。 */
10
+ image?: string;
11
+ /** 每个 Workspace Sandbox 初始分配的虚拟 CPU 数量。 */
12
+ cpus?: number;
13
+ /** 每个 Workspace Sandbox 初始分配的内存,单位 MiB。 */
14
+ memory_mib?: number;
15
+ }
16
+ //# sourceMappingURL=MicrosandboxProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MicrosandboxProvider.d.ts","sourceRoot":"","sources":["../../src/types/MicrosandboxProvider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,kCAAkC;AAClC,MAAM,WAAW,2BAA2B;IAC1C,4DAA4D;IAC5D,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,2CAA2C;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Microsandbox Provider 公开配置类型。
3
+ *
4
+ * 这些参数只描述隔离环境的基础资源,不暴露 microsandbox 的底层构建器,避免
5
+ * Downcity 的公开 API 与单一实现细节绑定。
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=MicrosandboxProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MicrosandboxProvider.js","sourceRoot":"","sources":["../../src/types/MicrosandboxProvider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@downcity/sandbox-microsandbox",
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "description": "Downcity persistent microVM sandbox provider powered by microsandbox",
6
+ "main": "./bin/index.js",
7
+ "types": "./bin/index.d.ts",
8
+ "files": [
9
+ "bin"
10
+ ],
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "exports": {
15
+ ".": {
16
+ "types": "./bin/index.d.ts",
17
+ "import": "./bin/index.js"
18
+ }
19
+ },
20
+ "license": "MIT",
21
+ "dependencies": {
22
+ "@downcity/type": "0.1.210",
23
+ "microsandbox": "^0.6.17"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^25.9.1",
27
+ "typescript": "^6.0.3"
28
+ },
29
+ "engines": {
30
+ "node": ">=22"
31
+ },
32
+ "scripts": {
33
+ "build": "node ../../../../scripts/clean-package.mjs && tsc",
34
+ "typecheck": "tsc --noEmit",
35
+ "test": "pnpm build && node --test scripts/*.test.mjs",
36
+ "version:patch": "node ../../../../scripts/bump-package-version.mjs ./package.json"
37
+ }
38
+ }