@mostra/sdk 0.0.0-stage → 0.2.0

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,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,38 @@
1
- # Temporary Holding Version
1
+ # @mostra/sdk
2
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.
3
+ Embed Mostra in a JavaScript host. `createMostra` starts your own Mostra instance for a home you
4
+ choose, serves the ports you implement, and gives you the calls a host makes: publish, verify,
5
+ wait, results, artifact state, live values, links and events.
6
+
7
+ ```ts
8
+ import { createMostra } from "@mostra/sdk";
9
+
10
+ const mostra = await createMostra({
11
+ home: "/var/lib/inbox/mostra",
12
+ client: { name: "inbox-app", version: "1.4.0" },
13
+ ports: {
14
+ submissions: {
15
+ async deliver(envelope) {
16
+ await db.saveOnce(envelope.submissionId, envelope.results);
17
+ return { accepted: true };
18
+ },
19
+ },
20
+ },
21
+ });
22
+
23
+ const receipt = await mostra.publish("/work/inbox");
24
+ console.log(receipt.url);
25
+ const outcome = await mostra.wait(receipt.artifactId, "submitted");
26
+ const results = await mostra.results(receipt.artifactId);
27
+ await mostra.close();
28
+ ```
29
+
30
+ The first call downloads the runtime bundle this release pins (Node.js, Mostra's runtime and the
31
+ packages artifacts use), checks every file against its SHA-256, fetches the browser `verify` uses
32
+ and caches it all by digest. Later calls start at once, offline too. `MOSTRA_CACHE_DIR` moves the
33
+ cache, `MOSTRA_BUNDLE_MIRROR` fetches from a mirror, and `MOSTRA_BUNDLE` uses a bundle you
34
+ extracted yourself.
35
+
36
+ Embedded use never sends telemetry. Node.js 22.19 or later; macOS and Linux on x64 and arm64.
37
+
38
+ Part of [Mostra](https://github.com/mostra-dev/mostra), the agent artifact runtime. Apache-2.0.
@@ -0,0 +1,31 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "version": "0.2.0",
4
+ "release": "https://github.com/mostra-dev/mostra/releases/download/v0.2.0",
5
+ "assets": {
6
+ "darwin-arm64": {
7
+ "file": "mostra-0.2.0-darwin-arm64.tar.gz",
8
+ "sha256": "bf39299276a1b47aaf7f9e3b89cba64ccec6a9df354dcfd1448ea09967103fce",
9
+ "size": 198701927,
10
+ "unpackedSize": 781901193
11
+ },
12
+ "darwin-x64": {
13
+ "file": "mostra-0.2.0-darwin-x64.tar.gz",
14
+ "sha256": "201799fc7086076bed51b5e2e7eaa177416c417a12f0636b395a8207f6a81dde",
15
+ "size": 201773269,
16
+ "unpackedSize": 789999057
17
+ },
18
+ "linux-x64": {
19
+ "file": "mostra-0.2.0-linux-x64.tar.gz",
20
+ "sha256": "dd110f1b04fc6ff07da9f2c6d125b95f58775b5136b8d5f05da10d6865c85ea9",
21
+ "size": 205998068,
22
+ "unpackedSize": 792857549
23
+ },
24
+ "linux-arm64": {
25
+ "file": "mostra-0.2.0-linux-arm64.tar.gz",
26
+ "sha256": "2b24b16b84fa464467274f705c34efb527d3abb7e68cd0bfa7b8befb88e99186",
27
+ "size": 204102795,
28
+ "unpackedSize": 783165502
29
+ }
30
+ }
31
+ }
@@ -0,0 +1,374 @@
1
+ import { ArtifactRef, ArtifactSummary, BundleFiles, BundleInfo, BundlePins, BundlePlatform, BundleSetup, CapabilityLink, ControlsPolicy, DependencyPolicy, Diagnostic, DraftMirror, EventFilter, EventRecord, InstanceCapabilities, InstanceInfo, LivePushParams, LivePushResult, MethodDefinition, PortIdentityResolveParams, PortSecretsGetParams, PortTrustedControlsActivatedParams, PublishReceipt, Results, ResultsMarkdown, SourceRef, StateGetResult, StatePatchParams, StatePatchResult, SubmissionEnvelope, SubmissionPolicy, SubmissionsDeliverResult, SubmitChannel, VerifyVerdict, ViewUrlParams, ViewerSpec, WaitCondition, WaitResult } from "@mostra/protocol";
2
+ //#region src/bundle/download.d.ts
3
+ /** Progress of one download, in bytes. */
4
+ interface DownloadProgress {
5
+ /** Bytes received so far. */
6
+ readonly received: number;
7
+ /** Bytes the pin says the archive has. */
8
+ readonly total: number;
9
+ }
10
+ /** A URL without credentials or a query, safe to print. */
11
+ export declare function redactUrl(url: string): string;
12
+ //#endregion
13
+ //#region src/bundle/setup.d.ts
14
+ /** The environment setup reads. */
15
+ type Environment = Readonly<Record<string, string | undefined>>;
16
+ /** An extracted bundle and what its `bundle.json` says. */
17
+ interface Bundle {
18
+ /** Its root directory, holding `bundle.json`. */
19
+ readonly root: string;
20
+ /** Its parsed `bundle.json`. */
21
+ readonly info: BundleInfo;
22
+ }
23
+ /** One step of setup, for progress reports. */
24
+ type SetupStep = "files" | "browser";
25
+ /** Options of {@link setupBundle}. */
26
+ interface SetupOptions {
27
+ /** The environment: `MOSTRA_OFFLINE`, proxies, Playwright's download mirror. */
28
+ readonly env?: Environment | undefined;
29
+ /** Gives up the browser's download. */
30
+ readonly signal?: AbortSignal | undefined;
31
+ /** Each step as it starts. */
32
+ readonly onStep?: ((step: SetupStep) => void) | undefined;
33
+ /** Skip checking the files, for a tree the caller checked a moment ago. */
34
+ readonly filesChecked?: boolean | undefined;
35
+ }
36
+ /** The directory Playwright's browsers live in, inside a bundle. */
37
+ export declare function browsersDir(root: string): string;
38
+ /** Whether `MOSTRA_OFFLINE` says Mostra is offline: any value but empty, `0`, `false` or `no`. */
39
+ export declare function offline(env: Environment): boolean;
40
+ /** Reads `bundle.json` at `root`. Throws `MOSTRA_ENV_BUNDLE_INVALID` when it isn't a bundle's. */
41
+ export declare function readBundle(root: string): Promise<Bundle>;
42
+ /** The setup marker, when it describes exactly this bundle. */
43
+ export declare function readSetup(bundle: Bundle): Promise<BundleSetup | undefined>;
44
+ /** What `checkTree` may find besides the listed files: the bundle's own records and browsers. */
45
+ export declare function setupExtras(path: string): boolean;
46
+ /** Checks the bundle's files; throws `MOSTRA_ENV_BUNDLE_INVALID` naming what differs. */
47
+ export declare function checkFiles(bundle: Bundle): Promise<void>;
48
+ /** The browser files that differ from the pin, relative to `browsers/`. */
49
+ export declare function checkBrowser(bundle: Bundle): Promise<readonly string[]>;
50
+ /**
51
+ * Makes the bundle at `root` ready: checks its files, fetches and checks the browser when it is
52
+ * missing or differs, and writes `.mostra-setup.json`. Idempotent: a ready bundle returns its
53
+ * marker after the checks. Throws `MOSTRA_ENV_BUNDLE_INVALID`, `MOSTRA_ENV_BUNDLE_UNAVAILABLE`
54
+ * (offline with no browser) or `MOSTRA_ENV_BUNDLE_DOWNLOAD_FAILED`.
55
+ */
56
+ export declare function setupBundle(root: string, options?: SetupOptions): Promise<BundleSetup>;
57
+ //#endregion
58
+ //#region src/bundle/cache.d.ts
59
+ /** Where the cache is: `MOSTRA_CACHE_DIR`, else the platform's per-user cache directory. */
60
+ export declare function cacheRoot(env: Environment, platform?: string): string;
61
+ /** The directory a bundle with this archive digest lives in. */
62
+ export declare function bundleDir(env: Environment, sha256: string): string;
63
+ /** What an install reports while it works. */
64
+ type InstallProgress = ({
65
+ readonly step: "download";
66
+ } & DownloadProgress) | {
67
+ readonly step: "extract" | "lock";
68
+ } | {
69
+ readonly step: SetupStep;
70
+ };
71
+ /** Options of {@link installPinned}. */
72
+ interface InstallOptions {
73
+ /** The environment: the cache, mirror and offline variables, proxies. */
74
+ readonly env: Environment;
75
+ /** The platform whose archive to install. */
76
+ readonly platform: BundlePlatform;
77
+ /** Gives up the install; nothing partial is kept. */
78
+ readonly signal?: AbortSignal | undefined;
79
+ /** Each step, and the bytes received while downloading. */
80
+ readonly onProgress?: ((progress: InstallProgress) => void) | undefined;
81
+ }
82
+ /**
83
+ * The pinned bundle for this platform, ready to run: from the cache when it is there and ready,
84
+ * else installed. `MOSTRA_BUNDLE_MIRROR` replaces the release URL (files keep their names).
85
+ */
86
+ export declare function installPinned(pins: BundlePins, options: InstallOptions): Promise<Bundle>;
87
+ //#endregion
88
+ //#region src/bundle/tree.d.ts
89
+ /** The SHA-256 and size of one file, read as a stream. */
90
+ export declare function hashFile(path: string): Promise<{
91
+ sha256: string;
92
+ size: number;
93
+ }>;
94
+ /** Whether a link's target is relative and resolves inside `root`. */
95
+ export declare function linkStaysInside(root: string, path: string, target: string): boolean;
96
+ /** Whether a manifest path is a plain relative path: no absolute start, no `.` or `..` segment. */
97
+ export declare function safeRelative(path: string): boolean;
98
+ /**
99
+ * The manifest of the tree under `root`: every regular file with its SHA-256, size and execute
100
+ * bit, every link with its target. Throws on anything else (a device, a socket, a link leaving
101
+ * the tree), which a bundle must never contain.
102
+ */
103
+ export declare function describeTree(root: string, exclude?: (path: string) => boolean): Promise<BundleFiles>;
104
+ /** What a check found: an empty list means the tree matches. Paths are relative to the root. */
105
+ type TreeProblems = readonly string[];
106
+ /**
107
+ * Checks the tree under `root` against `manifest`: each listed file present, regular, with its
108
+ * size, SHA-256 and execute bit; each link present with its target, staying inside; and nothing
109
+ * else besides what `allowExtra` accepts. Reports at most `limit` problems.
110
+ */
111
+ export declare function checkTree(root: string, manifest: BundleFiles, options?: {
112
+ readonly allowExtra?: (path: string) => boolean;
113
+ readonly limit?: number;
114
+ }): Promise<TreeProblems>;
115
+ //#endregion
116
+ //#region src/events.d.ts
117
+ /** One page of events. */
118
+ interface EventPage {
119
+ /** The events, in cursor order. */
120
+ readonly events: readonly EventRecord[];
121
+ /** Everything up to this cursor was examined: the cursor to resume after. */
122
+ readonly cursor: string;
123
+ /** Set when compaction removed events in this range (`MOSTRA_HOST_CURSOR_COMPACTED`). */
124
+ readonly compacted?: Diagnostic;
125
+ }
126
+ /** Options of a stream. */
127
+ interface EventStreamOptions {
128
+ /** Which events: artifacts and type patterns. Default: every event. */
129
+ readonly filter?: EventFilter;
130
+ /** Start after this cursor. Default: a named stream's acknowledged cursor, else now. */
131
+ readonly after?: string;
132
+ /** A durable subscriber name: pages are acknowledged under it as they are handled. */
133
+ readonly name?: string;
134
+ /** Pages held before the subscription pauses. Default 16. */
135
+ readonly highWaterMark?: number;
136
+ /** Ends the stream. */
137
+ readonly signal?: AbortSignal;
138
+ }
139
+ //#endregion
140
+ //#region src/runtime.d.ts
141
+ /** A runtime to spawn: the Node.js to run it with and its entry points. */
142
+ interface Runtime {
143
+ /** How it was found. */
144
+ readonly source: "bundle" | "override" | "development";
145
+ /** The Node.js executable: the bundle's own, or this process's for the others. */
146
+ readonly node: string;
147
+ /** `mostra-runtime`'s entry (`host`, `daemon`, `service`). */
148
+ readonly runtimeEntry: string;
149
+ /** The `mostra` CLI's entry, when this runtime has one. */
150
+ readonly cliEntry?: string;
151
+ /** The bundle, when the runtime is one. */
152
+ readonly bundle?: Bundle;
153
+ }
154
+ /** Options of {@link resolveRuntime}. */
155
+ interface RuntimeOptions {
156
+ /** An extracted bundle to use, ahead of everything else. */
157
+ readonly bundle?: string | undefined;
158
+ /** The environment: `MOSTRA_BUNDLE`, `MOSTRA_RUNTIME_BIN`, the cache's variables. */
159
+ readonly env?: Environment | undefined;
160
+ /** Gives up a download or setup. */
161
+ readonly signal?: AbortSignal | undefined;
162
+ /** Progress of a download or setup, for a person waiting (the CLI prints it on stderr). */
163
+ readonly onProgress?: ((progress: InstallProgress) => void) | undefined;
164
+ }
165
+ /** The pins this build carries: `dist/bundles.json` (a test override applies only in a development checkout). */
166
+ export declare function readPins(env: Environment): BundlePins | undefined;
167
+ /** The bundle this package was installed into, if any: `<root>/lib/node_modules/@mostra/sdk`. */
168
+ export declare function enclosingBundle(): string | undefined;
169
+ /** A bundle's entry points as a runtime. */
170
+ export declare function runtimeOf(bundle: Bundle): Runtime;
171
+ /**
172
+ * Finds the runtime to spawn, downloading and setting up the pinned bundle when nothing nearer
173
+ * exists. Throws `MOSTRA_PLATFORM_UNSUPPORTED`, `MOSTRA_ENV_RUNTIME_MISSING` (a
174
+ * `MOSTRA_RUNTIME_BIN` that doesn't exist), `MOSTRA_ENV_BUNDLE_UNAVAILABLE`,
175
+ * `MOSTRA_ENV_BUNDLE_INVALID` or `MOSTRA_ENV_BUNDLE_DOWNLOAD_FAILED`.
176
+ */
177
+ export declare function resolveRuntime(options?: RuntimeOptions): Promise<Runtime>;
178
+ //#endregion
179
+ //#region src/mostra.d.ts
180
+ /**
181
+ * The ports a host may serve (INTERFACES §7). Each is optional and has a standalone default;
182
+ * Mostra calls a port only on the instance this handle spawned, and every call is idempotent by
183
+ * its stable ID, so a port may see the same call again after a crash.
184
+ */
185
+ interface Ports {
186
+ /**
187
+ * Names the person behind a link minted without a viewer, from the request's headers (D143):
188
+ * `{ ref, name? }` (one viewer per `ref`), or `null` for the home's local user. Answer within
189
+ * 5 s; a failure refuses the link rather than guess.
190
+ */
191
+ readonly identity?: {
192
+ resolve(request: PortIdentityResolveParams): ViewerSpec | null | Promise<ViewerSpec | null>;
193
+ };
194
+ /** Receives each submission once it is durable (D58, D105). Answer within 30 s. */
195
+ readonly submissions?: {
196
+ deliver(envelope: SubmissionEnvelope): SubmissionsDeliverResult | Promise<SubmissionsDeliverResult>;
197
+ };
198
+ /** Receives each viewer draft's latest revision, best effort, never retried (IN-06). */
199
+ readonly drafts?: {
200
+ mirror(draft: DraftMirror): void | Promise<void>;
201
+ };
202
+ /** Answers `secret()` first, before the home's store (D131); `null` falls back. */
203
+ readonly secrets?: {
204
+ get(request: PortSecretsGetParams): string | null | Promise<string | null>;
205
+ };
206
+ /** Decides each view's submit channels and trusted controls (D108). Answer within 5 s. */
207
+ readonly trustedControls?: {
208
+ policy(artifact: ArtifactSummary): ControlsPolicy | Promise<ControlsPolicy>;
209
+ activated?(event: PortTrustedControlsActivatedParams): void | Promise<void>;
210
+ };
211
+ }
212
+ /** Home settings a host chooses (INTERFACES §6 `HomeConfig`), kept in the home's `config.json`. */
213
+ interface HomeSettings {
214
+ /** The submission policy for artifacts whose publish names none (D102). */
215
+ readonly submission?: SubmissionPolicy;
216
+ /** The channels that may submit (D40, D108); absent, both. */
217
+ readonly submitChannels?: readonly SubmitChannel[];
218
+ /** How packages enter an artifact's lockfile (D43, D95). */
219
+ readonly dependencies?: DependencyPolicy;
220
+ }
221
+ /** Options of {@link createMostra}. */
222
+ interface MostraOptions {
223
+ /** The home this host owns (D45). Created 0700 when missing. */
224
+ readonly home: string;
225
+ /**
226
+ * Who the host is. The name owns the host's deliveries across restarts (D105), so keep it
227
+ * stable; it defaults to `mostra-sdk`.
228
+ */
229
+ readonly client?: {
230
+ readonly name: string;
231
+ readonly version?: string;
232
+ };
233
+ /** The ports this host serves. */
234
+ readonly ports?: Ports;
235
+ /**
236
+ * Whether submissions made while this host is away wait for it (D105): the registered ports
237
+ * are recorded as ports this host always provides. Default `true`; `false` leaves the home's
238
+ * record as it is.
239
+ */
240
+ readonly expectPorts?: boolean;
241
+ /** Home settings, kept in the home's `config.json` for every later client. */
242
+ readonly settings?: HomeSettings;
243
+ /** An extracted runtime bundle to use instead of the pinned one. */
244
+ readonly bundle?: string;
245
+ /** The gateway's bind address and URL host (D99); loopback by default. */
246
+ readonly bind?: string;
247
+ /** The host name URLs use, which a wildcard `bind` needs (D99). */
248
+ readonly urlHost?: string;
249
+ /** The instance's environment. Default: this process's. */
250
+ readonly env?: Environment;
251
+ /** Each line the instance logs (JSON, on its stderr). A callback that throws is ignored. */
252
+ readonly onLog?: (line: string) => void;
253
+ /** Progress of the first download or setup of the runtime bundle. A throw is ignored. */
254
+ readonly onProgress?: (progress: InstallProgress) => void;
255
+ /**
256
+ * An exception a port threw; the instance got `MOSTRA_HOST_INTERNAL_ERROR` and will retry. A
257
+ * callback that throws is ignored, and the instance is answered all the same.
258
+ */
259
+ readonly onPortError?: (error: unknown, method: string) => void;
260
+ /** Gives up finding the runtime and starting the instance. */
261
+ readonly signal?: AbortSignal;
262
+ }
263
+ /** How the instance ended. */
264
+ interface InstanceExit {
265
+ /** Its exit code: 0 after a clean stop. */
266
+ readonly code: number | null;
267
+ /** The signal that ended it, if one did. */
268
+ readonly signal: NodeJS.Signals | null;
269
+ }
270
+ /** An artifact by ID (`art_…`), by source path, or as the protocol's reference. */
271
+ type ArtifactInput = string | ArtifactRef;
272
+ /** A host's handle on its instance. */
273
+ interface Mostra {
274
+ /** The instance: release, home, platform, PID and mode. */
275
+ readonly instance: InstanceInfo;
276
+ /** What the instance serves. */
277
+ readonly capabilities: InstanceCapabilities;
278
+ /** The negotiated host protocol revision. */
279
+ readonly revision: string;
280
+ /** The session's warnings (an unsupported port, for example). */
281
+ readonly warnings: readonly Diagnostic[];
282
+ /** The runtime it runs on. */
283
+ readonly runtime: Runtime;
284
+ /** Resolves when the instance has exited, for whatever reason. */
285
+ readonly closed: Promise<InstanceExit>;
286
+ /** Calls any host protocol method by its definition from `@mostra/protocol`. */
287
+ call<P, R>(method: MethodDefinition<P, R>, params: P, options?: CallOptions): Promise<R>;
288
+ /** `artifact/publish`: verifies (D41) and publishes; durable before it resolves (H-07). */
289
+ publish(source: ArtifactInput, options?: {
290
+ readonly force?: boolean;
291
+ readonly policy?: SubmissionPolicy;
292
+ readonly requestId?: string;
293
+ }): Promise<PublishReceipt>;
294
+ /** `artifact/verify`: one verdict, never a publish (D138). */
295
+ verify(source: ArtifactInput, options?: {
296
+ readonly screenshots?: "on-failure" | "always" | "never";
297
+ }): Promise<VerifyVerdict>;
298
+ /**
299
+ * `wait` (IN-10, D103): until the condition holds or `timeoutMs` passes (default: the longest
300
+ * timer, about 24.8 days). `still_waiting` carries the cursor to wait from next; an aborted wait
301
+ * rejects with the signal's reason and loses nothing.
302
+ */
303
+ wait(artifact: ArtifactInput, until: WaitCondition, options?: {
304
+ readonly after?: string;
305
+ readonly timeoutMs?: number;
306
+ readonly signal?: AbortSignal;
307
+ }): Promise<WaitResult>;
308
+ /** `results/get`: a submission as JSON (the default) or Markdown (INTERFACES §8). */
309
+ results(artifact: ArtifactInput, options?: {
310
+ readonly submission?: string;
311
+ readonly format?: "json";
312
+ }): Promise<Results>;
313
+ /** `results/get` as Markdown, for an agent to read. */
314
+ results(artifact: ArtifactInput, options: {
315
+ readonly submission?: string;
316
+ readonly format: "md";
317
+ }): Promise<ResultsMarkdown>;
318
+ /** `state/get`: artifact-scoped fields (D63). */
319
+ getState(artifact: ArtifactInput, ids?: readonly string[]): Promise<StateGetResult>;
320
+ /** `state/patch`: writes artifact-scoped fields through compare-and-set (D63). */
321
+ patchState(artifact: ArtifactInput, patch: Omit<StatePatchParams, "artifact">): Promise<StatePatchResult>;
322
+ /** `live/push`: a live source's next value (D56). */
323
+ pushLive(artifact: ArtifactInput, push: Omit<LivePushParams, "artifact">): Promise<LivePushResult>;
324
+ /** `view/url`: a new capability link (D97). */
325
+ viewUrl(artifact: ArtifactInput, options?: Omit<ViewUrlParams, "artifact">): Promise<CapabilityLink>;
326
+ /**
327
+ * The events matching `options.filter`, page by page, in cursor order, with no gap across a
328
+ * pause (`events/subscribe`). With a `name`, each page is acknowledged when the next one is
329
+ * asked for, so a later stream of that name resumes after the last page handled.
330
+ */
331
+ events(options?: EventStreamOptions): AsyncIterable<EventPage>;
332
+ /** Ends the instance: its stdio closes, and it is stopped if it doesn't exit within 10 s. */
333
+ close(): Promise<InstanceExit>;
334
+ }
335
+ /** Options of one call. */
336
+ interface CallOptions {
337
+ /** Gives up after this many milliseconds with `MOSTRA_HOST_TIMEOUT`. Default: none. */
338
+ readonly timeoutMs?: number;
339
+ }
340
+ /** The client name of an SDK host that names none. */
341
+ export declare const SDK_CLIENT_NAME = "mostra-sdk";
342
+ /** `art_…` is an artifact ID; anything else a source path, resolved against the working directory. */
343
+ export declare function artifactRef(input: ArtifactInput): ArtifactRef & SourceRef;
344
+ /**
345
+ * Spawns an instance for `home` and opens its session. Rejects with the instance's own diagnostic
346
+ * when it can't start (`MOSTRA_HOME_LOCKED`, `MOSTRA_PLATFORM_UNSUPPORTED` …), or with the
347
+ * runtime's (`MOSTRA_ENV_BUNDLE_*`) when no verified runtime can be found.
348
+ */
349
+ export declare function createMostra(options: MostraOptions): Promise<Mostra>;
350
+ //#endregion
351
+ //#region src/platform.d.ts
352
+ /** What the platform check reads: the running process by default. */
353
+ interface PlatformFacts {
354
+ /** `process.platform`. */
355
+ readonly platform: string;
356
+ /** `process.arch`. */
357
+ readonly arch: string;
358
+ /** The glibc release on Linux, `undefined` on musl or elsewhere. */
359
+ readonly glibc?: string | undefined;
360
+ }
361
+ /** The facts of the running process, read once. */
362
+ export declare function currentPlatform(): PlatformFacts;
363
+ /**
364
+ * The bundle platform for these facts. Throws `MOSTRA_PLATFORM_UNSUPPORTED` for Windows, other
365
+ * architectures and Linux without glibc, whose libraries the bundle's Node.js and browser need.
366
+ */
367
+ export declare function bundlePlatform(facts?: PlatformFacts): BundlePlatform;
368
+ //#endregion
369
+ //#region src/version.d.ts
370
+ /** This SDK's release: the client version an SDK host reports by default. */
371
+ export declare function sdkVersion(): string;
372
+ //#endregion
373
+ export type { ArtifactInput, Bundle, CallOptions, DownloadProgress, Environment, EventPage, EventStreamOptions, HomeSettings, InstallOptions, InstallProgress, InstanceExit, Mostra, MostraOptions, PlatformFacts, Ports, Runtime, RuntimeOptions, SetupOptions, SetupStep, TreeProblems };
374
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/bundle/download.ts","../src/bundle/setup.ts","../src/bundle/cache.ts","../src/bundle/tree.ts","../src/events.ts","../src/runtime.ts","../src/mostra.ts","../src/platform.ts","../src/version.ts"],"mappings":";;;UAqBiB;;WAEN;;WAEA;;;wBAmMK,UAAU;;;;KCtMd,cAAc,SAAS;;UAGlB;;WAEN;;WAEA,MAAM;;;KAIL;;UAGK;;WAEN,MAAM;;WAEN,SAAS;;WAET,WAAW,MAAM;;WAEjB;;;wBAIK,YAAY;;wBAKZ,QAAQ,KAAK;;wBAYP,WAAW,eAAe,QAAQ;;wBA4BlC,UAAU,QAAQ,SAAS,QAAQ;;wBAkBzC,YAAY;;wBAYN,WAAW,QAAQ,SAAS;;wBAkB5B,aAAa,QAAQ,SAAS;;;;;;;wBAiG9B,YAAY,cAAc,UAAS,eAAoB,QAAQ;;;;wBChMrE,UAAU,KAAK,aAAa;;wBAU5B,UAAU,KAAK,aAAa;;KAKhC;W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