@blastlauncher/runtime 3.0.0-alpha.0 → 3.0.0-alpha.10
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/api/ai-browser.d.ts +24 -4
- package/dist/api/diagnostics.js +14 -4
- package/dist/api/enums.generated.d.ts +12 -2
- package/dist/api/enums.generated.js +12 -2
- package/dist/api/index.d.ts +24 -4
- package/dist/api/navigation.js +1 -1
- package/dist/api/unsupported.generated.d.ts +12 -2
- package/dist/api/window.js +1 -1
- package/dist/browser.d.ts +19 -0
- package/dist/browser.js +32 -0
- package/dist/core.d.ts +18 -0
- package/dist/core.js +261 -0
- package/dist/main.js +51 -287
- package/dist/reconciler/index.d.ts +2 -2
- package/dist/reconciler/index.js +405 -27
- package/dist/reconciler/serialize.js +65 -25
- package/dist/reconciler/types.d.ts +5 -2
- package/package.json +13 -2
package/dist/core.js
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { parseHostMessage, PROTOCOL_VERSION, } from "@blastlauncher/protocol";
|
|
2
|
+
import { createElement, Suspense } from "react";
|
|
3
|
+
import { createModelProvider } from "./provider.js";
|
|
4
|
+
import { setCapabilityRequester } from "./api/capability.js";
|
|
5
|
+
import { setRuntimeLogSink } from "./api/diagnostics.js";
|
|
6
|
+
import { setEnvironment } from "./api/environment.js";
|
|
7
|
+
import { setFeedbackMount } from "./api/feedback.js";
|
|
8
|
+
import { decodeFormValues, flushFormPersistence, setFormDraftValues } from "./api/form.js";
|
|
9
|
+
import { LaunchType } from "./api/launch.js";
|
|
10
|
+
import { NavigationProvider } from "./api/navigation.js";
|
|
11
|
+
import { setPreferenceValues } from "./api/preferences.js";
|
|
12
|
+
import { setRenderMount } from "./api/legacy.js";
|
|
13
|
+
import { UnsupportedApiError } from "./api/unsupported.js";
|
|
14
|
+
import { createSceneRoot } from "./reconciler/index.js";
|
|
15
|
+
/* oxlint-disable unicorn/consistent-function-scoping */
|
|
16
|
+
export function startRuntime(options) {
|
|
17
|
+
let provider;
|
|
18
|
+
let providerLoad;
|
|
19
|
+
let stopping = false;
|
|
20
|
+
let initialized = false;
|
|
21
|
+
let loaded = false;
|
|
22
|
+
let nextRequest = 1;
|
|
23
|
+
const pending = new Map();
|
|
24
|
+
const send = (message) => {
|
|
25
|
+
if (!stopping)
|
|
26
|
+
options.send(message);
|
|
27
|
+
};
|
|
28
|
+
const errorMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
29
|
+
const log = (level, args) => {
|
|
30
|
+
if (options.log)
|
|
31
|
+
options.log(level, args);
|
|
32
|
+
else
|
|
33
|
+
send({ type: "log", level, message: args.map(String).join(" ") });
|
|
34
|
+
};
|
|
35
|
+
const finish = (code) => {
|
|
36
|
+
if (stopping)
|
|
37
|
+
return;
|
|
38
|
+
stopping = true;
|
|
39
|
+
setCapabilityRequester(undefined);
|
|
40
|
+
pending.clear();
|
|
41
|
+
options.exit(code);
|
|
42
|
+
};
|
|
43
|
+
const fatal = (error, code = "RUNTIME_ERROR") => {
|
|
44
|
+
send({
|
|
45
|
+
type: "error",
|
|
46
|
+
code: error instanceof UnsupportedApiError ? error.code : code,
|
|
47
|
+
message: errorMessage(error),
|
|
48
|
+
fatal: true,
|
|
49
|
+
});
|
|
50
|
+
finish(1);
|
|
51
|
+
};
|
|
52
|
+
const root = createSceneRoot({
|
|
53
|
+
publish: (scene) => send({ type: "scene", ...scene }),
|
|
54
|
+
publishPatch: (patch) => send({ type: "scene.patch", ...patch }),
|
|
55
|
+
onWarning: (message) => log("warn", [message]),
|
|
56
|
+
onError: fatal,
|
|
57
|
+
});
|
|
58
|
+
setCapabilityRequester((name, params, requestOptions = {}) => {
|
|
59
|
+
if (requestOptions.signal?.aborted)
|
|
60
|
+
return Promise.reject(new DOMException("The operation was aborted", "AbortError"));
|
|
61
|
+
const id = String(nextRequest++);
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
const abort = () => {
|
|
64
|
+
reject(new DOMException("The operation was aborted", "AbortError"));
|
|
65
|
+
send({ type: "capability.cancel", id });
|
|
66
|
+
};
|
|
67
|
+
pending.set(id, {
|
|
68
|
+
resolve,
|
|
69
|
+
reject,
|
|
70
|
+
progress: (value) => {
|
|
71
|
+
if (!requestOptions.signal?.aborted)
|
|
72
|
+
requestOptions.onProgress?.(value);
|
|
73
|
+
},
|
|
74
|
+
cleanup: () => requestOptions.signal?.removeEventListener("abort", abort),
|
|
75
|
+
});
|
|
76
|
+
requestOptions.signal?.addEventListener("abort", abort, { once: true });
|
|
77
|
+
send({ type: "capability.request", id, name, params });
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
setRuntimeLogSink((level, message) => log(level, [message]));
|
|
81
|
+
function loadingFallback(mode) {
|
|
82
|
+
return mode === "menu-bar"
|
|
83
|
+
? createElement("MenuBarExtra", { isLoading: true })
|
|
84
|
+
: createElement("List", { isLoading: true });
|
|
85
|
+
}
|
|
86
|
+
function withSuspense(element, mode) {
|
|
87
|
+
return createElement(Suspense, { fallback: loadingFallback(mode) }, element);
|
|
88
|
+
}
|
|
89
|
+
function launchProps(command) {
|
|
90
|
+
return {
|
|
91
|
+
arguments: command.arguments ?? {},
|
|
92
|
+
launchType: LaunchType.UserInitiated,
|
|
93
|
+
...(command.draftValues === undefined
|
|
94
|
+
? {}
|
|
95
|
+
: { draftValues: decodeFormValues(command.draftValues) }),
|
|
96
|
+
...(command.fallbackText === undefined ? {} : { fallbackText: command.fallbackText }),
|
|
97
|
+
...(command.launchContext === undefined ? {} : { launchContext: command.launchContext }),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
async function load(message) {
|
|
101
|
+
setEnvironment(message.environment, message.command);
|
|
102
|
+
setPreferenceValues(message.preferences);
|
|
103
|
+
const props = launchProps(message.command);
|
|
104
|
+
setFormDraftValues(props.draftValues);
|
|
105
|
+
let rendered = false;
|
|
106
|
+
setRenderMount((element) => {
|
|
107
|
+
if (rendered)
|
|
108
|
+
return;
|
|
109
|
+
rendered = true;
|
|
110
|
+
root.render(createElement(NavigationProvider, {
|
|
111
|
+
children: withSuspense(element, message.command.mode),
|
|
112
|
+
}));
|
|
113
|
+
loaded = true;
|
|
114
|
+
});
|
|
115
|
+
const command = await options.loadCommand(message.command);
|
|
116
|
+
setRenderMount(undefined);
|
|
117
|
+
if (stopping)
|
|
118
|
+
return;
|
|
119
|
+
if (rendered)
|
|
120
|
+
return;
|
|
121
|
+
if (message.command.mode === "model-provider") {
|
|
122
|
+
provider = createModelProvider(command, send);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (message.command.mode === "no-view") {
|
|
126
|
+
setFeedbackMount(() => {
|
|
127
|
+
if (!loaded) {
|
|
128
|
+
loaded = true;
|
|
129
|
+
root.render(createElement(NavigationProvider, { children: null }));
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
await command.default(props);
|
|
133
|
+
if (stopping)
|
|
134
|
+
return;
|
|
135
|
+
finish(0);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
let running = false;
|
|
139
|
+
function Command() {
|
|
140
|
+
if (running)
|
|
141
|
+
return null;
|
|
142
|
+
const result = command.default?.(props);
|
|
143
|
+
if (result !== null &&
|
|
144
|
+
(typeof result === "object" || typeof result === "function") &&
|
|
145
|
+
"then" in result &&
|
|
146
|
+
typeof result.then === "function") {
|
|
147
|
+
running = true;
|
|
148
|
+
void Promise.resolve(result).then(() => finish(0), fatal);
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
const wrap = message.command.mode === "view" &&
|
|
154
|
+
typeof command.default === "function" &&
|
|
155
|
+
!command.default.prototype?.isReactComponent;
|
|
156
|
+
const element = createElement(wrap ? Command : command.default, props);
|
|
157
|
+
const suspended = withSuspense(element, message.command.mode);
|
|
158
|
+
// Every loaded command gets the provider, menu-bar included: it is the
|
|
159
|
+
// only scene home for feedback (HUD, toast, alert) and window requests.
|
|
160
|
+
root.render(createElement(NavigationProvider, { children: suspended }));
|
|
161
|
+
loaded = true;
|
|
162
|
+
}
|
|
163
|
+
function shutdown() {
|
|
164
|
+
if (stopping)
|
|
165
|
+
return;
|
|
166
|
+
try {
|
|
167
|
+
root.unmount();
|
|
168
|
+
void flushFormPersistence().then(() => finish(0), fatal);
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
fatal(error);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function handle(value) {
|
|
175
|
+
if (stopping)
|
|
176
|
+
return;
|
|
177
|
+
const parsed = parseHostMessage(value);
|
|
178
|
+
if (!parsed.ok)
|
|
179
|
+
return fatal(parsed.error, "PROTOCOL_ERROR");
|
|
180
|
+
const message = parsed.message;
|
|
181
|
+
if (!initialized) {
|
|
182
|
+
if (message.type !== "init" || message.protocol !== PROTOCOL_VERSION)
|
|
183
|
+
return fatal(`Expected init with protocol ${PROTOCOL_VERSION}`, "PROTOCOL_ERROR");
|
|
184
|
+
initialized = true;
|
|
185
|
+
send({ type: "ready", protocol: PROTOCOL_VERSION });
|
|
186
|
+
providerLoad = load(message);
|
|
187
|
+
void providerLoad.catch(fatal);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
switch (message.type) {
|
|
191
|
+
case "provider.getModels":
|
|
192
|
+
case "provider.stream":
|
|
193
|
+
case "provider.abort":
|
|
194
|
+
void providerLoad
|
|
195
|
+
?.then(() => {
|
|
196
|
+
if (!provider)
|
|
197
|
+
return fatal("Provider request in command session", "PROTOCOL_ERROR");
|
|
198
|
+
provider.handle(message);
|
|
199
|
+
})
|
|
200
|
+
.catch(fatal);
|
|
201
|
+
return;
|
|
202
|
+
case "init":
|
|
203
|
+
return fatal("Duplicate init", "PROTOCOL_ERROR");
|
|
204
|
+
case "shutdown":
|
|
205
|
+
return shutdown();
|
|
206
|
+
case "capability.progress": {
|
|
207
|
+
const request = pending.get(message.id);
|
|
208
|
+
if (!request)
|
|
209
|
+
return fatal(`Unknown capability id: ${message.id}`, "PROTOCOL_ERROR");
|
|
210
|
+
request.progress?.(message.value);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
case "capability.result": {
|
|
214
|
+
const request = pending.get(message.id);
|
|
215
|
+
if (!request)
|
|
216
|
+
return fatal(`Unknown capability id: ${message.id}`, "PROTOCOL_ERROR");
|
|
217
|
+
pending.delete(message.id);
|
|
218
|
+
request.cleanup();
|
|
219
|
+
if (message.ok)
|
|
220
|
+
request.resolve(message.value);
|
|
221
|
+
else
|
|
222
|
+
request.reject(Object.assign(new Error(message.error.message), { code: message.error.code }));
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
case "event": {
|
|
226
|
+
if (!loaded)
|
|
227
|
+
return fatal("Event before command loaded", "PROTOCOL_ERROR");
|
|
228
|
+
const failed = (error) => {
|
|
229
|
+
if (error instanceof UnsupportedApiError)
|
|
230
|
+
fatal(error);
|
|
231
|
+
else
|
|
232
|
+
send({
|
|
233
|
+
type: "error",
|
|
234
|
+
code: "EVENT_ERROR",
|
|
235
|
+
message: errorMessage(error),
|
|
236
|
+
fatal: false,
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
try {
|
|
240
|
+
void Promise.resolve(root.dispatch(message.node, message.handler, message.args)).catch(failed);
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
failed(error);
|
|
244
|
+
}
|
|
245
|
+
try {
|
|
246
|
+
root.flush();
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
fatal(error);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const remove = options.onMessage(handle);
|
|
255
|
+
const controller = (() => {
|
|
256
|
+
remove();
|
|
257
|
+
shutdown();
|
|
258
|
+
});
|
|
259
|
+
controller.fatal = fatal;
|
|
260
|
+
return controller;
|
|
261
|
+
}
|
package/dist/main.js
CHANGED
|
@@ -6,77 +6,18 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
6
6
|
}
|
|
7
7
|
return path;
|
|
8
8
|
};
|
|
9
|
-
import { createLineDecoder, encodeMessage
|
|
10
|
-
import { createModelProvider } from "./provider.js";
|
|
9
|
+
import { createLineDecoder, encodeMessage } from "@blastlauncher/protocol";
|
|
11
10
|
import { Console } from "node:console";
|
|
12
11
|
import { registerHooks } from "node:module";
|
|
13
12
|
import { Writable } from "node:stream";
|
|
14
13
|
import { pathToFileURL } from "node:url";
|
|
15
14
|
import { format } from "node:util";
|
|
16
|
-
import {
|
|
17
|
-
import { setCapabilityRequester } from "./api/capability.js";
|
|
18
|
-
import { setRuntimeLogSink } from "./api/diagnostics.js";
|
|
19
|
-
import { setEnvironment } from "./api/environment.js";
|
|
20
|
-
import { setFeedbackMount } from "./api/feedback.js";
|
|
21
|
-
import { decodeFormValues, flushFormPersistence, setFormDraftValues } from "./api/form.js";
|
|
22
|
-
import { LaunchType } from "./api/launch.js";
|
|
23
|
-
import { NavigationProvider } from "./api/navigation.js";
|
|
24
|
-
import { setPreferenceValues } from "./api/preferences.js";
|
|
25
|
-
import { setRenderMount } from "./api/legacy.js";
|
|
26
|
-
import { UnsupportedApiError } from "./api/unsupported.js";
|
|
27
|
-
import { createSceneRoot } from "./reconciler/index.js";
|
|
28
|
-
let provider;
|
|
29
|
-
let providerLoad;
|
|
15
|
+
import { startRuntime } from "./core.js";
|
|
30
16
|
let stopping = false;
|
|
31
|
-
|
|
32
|
-
let loaded = false;
|
|
33
|
-
let nextRequest = 1;
|
|
34
|
-
const pending = new Map();
|
|
35
|
-
// Protocol output owns the real stdout stream. Extension code that writes to
|
|
36
|
-
// `process.stdout` (or a library doing it for them) must not corrupt the NDJSON
|
|
37
|
-
// framing, so those writes become log messages instead. The protocol keeps its
|
|
38
|
-
// own reference to the original writer.
|
|
39
|
-
process.stdout.on("error", (error) => {
|
|
40
|
-
if (error.code === "EPIPE")
|
|
41
|
-
process.exit(0);
|
|
42
|
-
throw error;
|
|
43
|
-
});
|
|
44
|
-
const writeToStdout = process.stdout.write.bind(process.stdout);
|
|
45
|
-
process.stdout.write = ((chunk, encoding, callback) => {
|
|
46
|
-
const done = typeof encoding === "function" ? encoding : callback;
|
|
47
|
-
log("info", [String(chunk).replace(/\n$/, "")]);
|
|
48
|
-
if (typeof done === "function")
|
|
49
|
-
queueMicrotask(done);
|
|
50
|
-
return true;
|
|
51
|
-
});
|
|
52
|
-
function send(message) {
|
|
53
|
-
if (!stopping)
|
|
54
|
-
writeToStdout(encodeMessage(message));
|
|
55
|
-
}
|
|
56
|
-
function errorMessage(error) {
|
|
57
|
-
return error instanceof Error ? error.message : String(error);
|
|
58
|
-
}
|
|
59
|
-
function finish(code) {
|
|
60
|
-
if (stopping)
|
|
61
|
-
return;
|
|
62
|
-
stopping = true;
|
|
63
|
-
process.stdin.pause();
|
|
64
|
-
setCapabilityRequester(undefined);
|
|
65
|
-
pending.clear();
|
|
66
|
-
// Explicit exit also stops extension timers; wait for protocol output to drain.
|
|
67
|
-
process.stdout.end(() => process.exit(code));
|
|
68
|
-
}
|
|
69
|
-
function fatal(error, code = "RUNTIME_ERROR") {
|
|
70
|
-
send({
|
|
71
|
-
type: "error",
|
|
72
|
-
code: error instanceof UnsupportedApiError ? error.code : code,
|
|
73
|
-
message: errorMessage(error),
|
|
74
|
-
fatal: true,
|
|
75
|
-
});
|
|
76
|
-
finish(1);
|
|
77
|
-
}
|
|
17
|
+
const protocolWrite = process.stdout.write.bind(process.stdout);
|
|
78
18
|
function log(level, args) {
|
|
79
|
-
|
|
19
|
+
if (!stopping)
|
|
20
|
+
protocolWrite(encodeMessage({ type: "log", level, message: format(...args) }));
|
|
80
21
|
}
|
|
81
22
|
function logStream(level) {
|
|
82
23
|
return new Writable({
|
|
@@ -86,7 +27,14 @@ function logStream(level) {
|
|
|
86
27
|
},
|
|
87
28
|
});
|
|
88
29
|
}
|
|
89
|
-
|
|
30
|
+
const writeToStdout = protocolWrite;
|
|
31
|
+
process.stdout.write = ((chunk, encoding, callback) => {
|
|
32
|
+
const done = typeof encoding === "function" ? encoding : callback;
|
|
33
|
+
log("info", [String(chunk).replace(/\n$/, "")]);
|
|
34
|
+
if (typeof done === "function")
|
|
35
|
+
queueMicrotask(done);
|
|
36
|
+
return true;
|
|
37
|
+
});
|
|
90
38
|
Object.assign(console, new Console({ stdout: logStream("info"), stderr: logStream("error") }));
|
|
91
39
|
console.timeStamp = () => { };
|
|
92
40
|
for (const [method, level] of [
|
|
@@ -98,10 +46,6 @@ for (const [method, level] of [
|
|
|
98
46
|
]) {
|
|
99
47
|
console[method] = (...args) => log(level, args);
|
|
100
48
|
}
|
|
101
|
-
process.on("uncaughtException", (error) => fatal(error));
|
|
102
|
-
process.on("unhandledRejection", (error) => fatal(error));
|
|
103
|
-
process.stdout.on("error", () => process.exit(1));
|
|
104
|
-
process.stdin.on("error", fatal);
|
|
105
49
|
const modules = new Map([
|
|
106
50
|
["@raycast/api", import.meta.resolve("@blastlauncher/runtime/api")],
|
|
107
51
|
...["react", "react/jsx-runtime", "react/jsx-dev-runtime"].map((name) => [
|
|
@@ -115,225 +59,45 @@ registerHooks({
|
|
|
115
59
|
return url ? { url, shortCircuit: true } : nextResolve(specifier, context);
|
|
116
60
|
},
|
|
117
61
|
});
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
reject(new DOMException("The operation was aborted", "AbortError"));
|
|
130
|
-
send({ type: "capability.cancel", id });
|
|
131
|
-
};
|
|
132
|
-
pending.set(id, {
|
|
133
|
-
resolve,
|
|
134
|
-
reject,
|
|
135
|
-
progress: (value) => {
|
|
136
|
-
if (!options.signal?.aborted)
|
|
137
|
-
options.onProgress?.(value);
|
|
138
|
-
},
|
|
139
|
-
cleanup: () => options.signal?.removeEventListener("abort", abort),
|
|
62
|
+
// `runtime` is only read from stdin callbacks, after this assignment.
|
|
63
|
+
const runtime = startRuntime({
|
|
64
|
+
send(message) {
|
|
65
|
+
writeToStdout(encodeMessage(message));
|
|
66
|
+
},
|
|
67
|
+
onMessage(listener) {
|
|
68
|
+
// The protocol decoder enforces the 8 MiB line cap (0001), strict UTF-8 and
|
|
69
|
+
// the malformed/unterminated-line rules; do not hand-roll framing here.
|
|
70
|
+
const decoder = createLineDecoder({
|
|
71
|
+
onLine: listener,
|
|
72
|
+
onError: (error) => runtime.fatal(error, "PROTOCOL_ERROR"),
|
|
140
73
|
});
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
// protocol's log channel; the runtime owns no other reporter.
|
|
147
|
-
setRuntimeLogSink((level, message) => log(level, [message]));
|
|
148
|
-
function loadingFallback(mode) {
|
|
149
|
-
return mode === "menu-bar"
|
|
150
|
-
? createElement("MenuBarExtra", { isLoading: true })
|
|
151
|
-
: createElement("List", { isLoading: true });
|
|
152
|
-
}
|
|
153
|
-
function withSuspense(element, mode) {
|
|
154
|
-
return createElement(Suspense, { fallback: loadingFallback(mode) }, element);
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Launch props for this command: the manifest arguments the host resolved and,
|
|
158
|
-
* when another command started it, the `launchCommand` context. Blast only
|
|
159
|
-
* launches user initiated commands (background launch is out of scope).
|
|
160
|
-
*/
|
|
161
|
-
function launchProps(command) {
|
|
162
|
-
return {
|
|
163
|
-
arguments: command.arguments ?? {},
|
|
164
|
-
launchType: LaunchType.UserInitiated,
|
|
165
|
-
...(command.draftValues === undefined
|
|
166
|
-
? {}
|
|
167
|
-
: { draftValues: decodeFormValues(command.draftValues) }),
|
|
168
|
-
...(command.fallbackText === undefined ? {} : { fallbackText: command.fallbackText }),
|
|
169
|
-
...(command.launchContext === undefined ? {} : { launchContext: command.launchContext }),
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
async function load(message) {
|
|
173
|
-
setEnvironment(message.environment, message.command);
|
|
174
|
-
setPreferenceValues(message.preferences);
|
|
175
|
-
const props = launchProps(message.command);
|
|
176
|
-
setFormDraftValues(props.draftValues);
|
|
177
|
-
// Legacy commands call `render(element)` while the module is being imported;
|
|
178
|
-
// that element becomes the command root instead of a default export.
|
|
179
|
-
let rendered = false;
|
|
180
|
-
setRenderMount((element) => {
|
|
181
|
-
if (rendered)
|
|
182
|
-
return;
|
|
183
|
-
rendered = true;
|
|
184
|
-
root.render(message.command.mode === "menu-bar"
|
|
185
|
-
? withSuspense(element, message.command.mode)
|
|
186
|
-
: createElement(NavigationProvider, {
|
|
187
|
-
children: withSuspense(element, message.command.mode),
|
|
188
|
-
}));
|
|
189
|
-
loaded = true;
|
|
190
|
-
});
|
|
191
|
-
const command = await import(__rewriteRelativeImportExtension(pathToFileURL(message.command.entry).href));
|
|
192
|
-
setRenderMount(undefined);
|
|
193
|
-
if (stopping)
|
|
194
|
-
return;
|
|
195
|
-
if (rendered)
|
|
196
|
-
return;
|
|
197
|
-
if (message.command.mode === "model-provider") {
|
|
198
|
-
provider = createModelProvider(command, send);
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
if (message.command.mode === "no-view") {
|
|
202
|
-
setFeedbackMount(() => {
|
|
203
|
-
if (!loaded) {
|
|
204
|
-
loaded = true;
|
|
205
|
-
root.render(createElement(NavigationProvider, { children: null }));
|
|
206
|
-
}
|
|
74
|
+
const onData = (chunk) => decoder.push(chunk);
|
|
75
|
+
process.stdin.on("data", onData);
|
|
76
|
+
process.stdin.on("end", () => {
|
|
77
|
+
decoder.end();
|
|
78
|
+
runtime();
|
|
207
79
|
});
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
// A thenable is a command body, never a suspending React component (0004).
|
|
218
|
-
let running = false;
|
|
219
|
-
function Command() {
|
|
220
|
-
if (running)
|
|
221
|
-
return null;
|
|
222
|
-
const result = command.default(props);
|
|
223
|
-
if (result !== null &&
|
|
224
|
-
(typeof result === "object" || typeof result === "function") &&
|
|
225
|
-
"then" in result &&
|
|
226
|
-
typeof result.then === "function") {
|
|
227
|
-
running = true;
|
|
228
|
-
void Promise.resolve(result).then(() => finish(0), fatal);
|
|
229
|
-
return null;
|
|
230
|
-
}
|
|
231
|
-
return result;
|
|
232
|
-
}
|
|
233
|
-
const wrap = message.command.mode === "view" &&
|
|
234
|
-
typeof command.default === "function" &&
|
|
235
|
-
!command.default.prototype?.isReactComponent;
|
|
236
|
-
const element = createElement(wrap ? Command : command.default, props);
|
|
237
|
-
const suspended = withSuspense(element, message.command.mode);
|
|
238
|
-
root.render(message.command.mode === "menu-bar"
|
|
239
|
-
? suspended
|
|
240
|
-
: createElement(NavigationProvider, { children: suspended }));
|
|
241
|
-
loaded = true;
|
|
242
|
-
}
|
|
243
|
-
function shutdown() {
|
|
244
|
-
if (stopping)
|
|
245
|
-
return;
|
|
246
|
-
try {
|
|
247
|
-
root.unmount();
|
|
248
|
-
void flushFormPersistence().then(() => finish(0), fatal);
|
|
249
|
-
}
|
|
250
|
-
catch (error) {
|
|
251
|
-
fatal(error);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
function handle(value) {
|
|
255
|
-
if (stopping)
|
|
256
|
-
return;
|
|
257
|
-
const parsed = parseHostMessage(value);
|
|
258
|
-
if (!parsed.ok)
|
|
259
|
-
return fatal(parsed.error, "PROTOCOL_ERROR");
|
|
260
|
-
const message = parsed.message;
|
|
261
|
-
if (!initialized) {
|
|
262
|
-
if (message.type !== "init" || message.protocol !== PROTOCOL_VERSION) {
|
|
263
|
-
return fatal(`Expected init with protocol ${PROTOCOL_VERSION}`, "PROTOCOL_ERROR");
|
|
264
|
-
}
|
|
265
|
-
initialized = true;
|
|
266
|
-
send({ type: "ready", protocol: PROTOCOL_VERSION });
|
|
267
|
-
providerLoad = load(message);
|
|
268
|
-
void providerLoad.catch(fatal);
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
switch (message.type) {
|
|
272
|
-
case "provider.getModels":
|
|
273
|
-
case "provider.stream":
|
|
274
|
-
case "provider.abort":
|
|
275
|
-
void providerLoad
|
|
276
|
-
?.then(() => {
|
|
277
|
-
if (!provider)
|
|
278
|
-
return fatal("Provider request in command session", "PROTOCOL_ERROR");
|
|
279
|
-
provider.handle(message);
|
|
280
|
-
})
|
|
281
|
-
.catch(fatal);
|
|
282
|
-
return;
|
|
283
|
-
case "init":
|
|
284
|
-
return fatal("Duplicate init", "PROTOCOL_ERROR");
|
|
285
|
-
case "shutdown":
|
|
286
|
-
return shutdown();
|
|
287
|
-
case "capability.progress": {
|
|
288
|
-
const request = pending.get(message.id);
|
|
289
|
-
if (!request)
|
|
290
|
-
return fatal(`Unknown capability id: ${message.id}`, "PROTOCOL_ERROR");
|
|
291
|
-
request.progress?.(message.value);
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
case "capability.result": {
|
|
295
|
-
const request = pending.get(message.id);
|
|
296
|
-
if (!request)
|
|
297
|
-
return fatal(`Unknown capability id: ${message.id}`, "PROTOCOL_ERROR");
|
|
298
|
-
pending.delete(message.id);
|
|
299
|
-
request.cleanup();
|
|
300
|
-
if (message.ok)
|
|
301
|
-
request.resolve(message.value);
|
|
302
|
-
else
|
|
303
|
-
request.reject(Object.assign(new Error(message.error.message), { code: message.error.code }));
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
case "event": {
|
|
307
|
-
if (!loaded)
|
|
308
|
-
return fatal("Event before command loaded", "PROTOCOL_ERROR");
|
|
309
|
-
const failed = (error) => {
|
|
310
|
-
if (error instanceof UnsupportedApiError)
|
|
311
|
-
fatal(error);
|
|
312
|
-
else
|
|
313
|
-
send({ type: "error", code: "EVENT_ERROR", message: errorMessage(error), fatal: false });
|
|
314
|
-
};
|
|
315
|
-
try {
|
|
316
|
-
// Do not await: a handler can be waiting for a capability.result on stdin.
|
|
317
|
-
void Promise.resolve(root.dispatch(message.node, message.handler, message.args)).catch(failed);
|
|
318
|
-
}
|
|
319
|
-
catch (error) {
|
|
320
|
-
failed(error);
|
|
321
|
-
}
|
|
322
|
-
try {
|
|
323
|
-
root.flush();
|
|
324
|
-
}
|
|
325
|
-
catch (error) {
|
|
326
|
-
fatal(error);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
const decoder = createLineDecoder({
|
|
332
|
-
onLine: handle,
|
|
333
|
-
onError: (error) => fatal(error, "PROTOCOL_ERROR"),
|
|
80
|
+
return () => process.stdin.off("data", onData);
|
|
81
|
+
},
|
|
82
|
+
exit(code) {
|
|
83
|
+
stopping = true;
|
|
84
|
+
process.stdin.pause();
|
|
85
|
+
process.stdout.end(() => process.exit(code));
|
|
86
|
+
},
|
|
87
|
+
log,
|
|
88
|
+
loadCommand: (command) => import(__rewriteRelativeImportExtension(pathToFileURL(command.entry).href)),
|
|
334
89
|
});
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
90
|
+
// Standby workers spawned by the host pass `--prewarm` so the `@raycast/api`
|
|
91
|
+
// shim finishes loading while idle before `init` arrives.
|
|
92
|
+
if (process.argv.includes("--prewarm")) {
|
|
93
|
+
void import("@blastlauncher/runtime/api").catch((error) => runtime.fatal(error));
|
|
94
|
+
}
|
|
95
|
+
process.on("uncaughtException", (error) => runtime.fatal(error));
|
|
96
|
+
process.on("unhandledRejection", (error) => runtime.fatal(error));
|
|
97
|
+
process.stdin.on("error", (error) => runtime.fatal(error));
|
|
98
|
+
// EPIPE means the host closed our stdout: a normal shutdown, not a crash.
|
|
99
|
+
process.stdout.on("error", (error) => {
|
|
100
|
+
if (error.code === "EPIPE")
|
|
101
|
+
process.exit(0);
|
|
102
|
+
process.exit(1);
|
|
339
103
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import type { SceneRootOptions } from "./types.js";
|
|
3
|
-
export type { JsonValue, SceneNode, SceneRootOptions, SceneSnapshot } from "./types.js";
|
|
4
|
-
export declare function createSceneRoot({ publish, onWarning, onError }: SceneRootOptions): {
|
|
3
|
+
export type { JsonValue, SceneNode, ScenePatch, ScenePatchOp, SceneRootOptions, SceneSnapshot, } from "./types.js";
|
|
4
|
+
export declare function createSceneRoot({ publish, publishPatch, onWarning, onError, }: SceneRootOptions): {
|
|
5
5
|
render: (element: ReactNode) => void;
|
|
6
6
|
unmount(): void;
|
|
7
7
|
dispatch(nodeId: string, handler: string, args: unknown[]): unknown;
|