@phpsandbox/sdk 0.0.68 → 0.1.2
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/README.md +66 -32
- package/dist/auth.d.ts +0 -1
- package/dist/auth.js +0 -3
- package/dist/beacon/index.d.ts +2 -0
- package/dist/beacon/index.js +5 -0
- package/dist/browser/phpsandbox-sdk.esm.js +842 -1320
- package/dist/browser/phpsandbox-sdk.esm.min.js +24 -24
- package/dist/browser/phpsandbox-sdk.iife.js +842 -1320
- package/dist/browser/phpsandbox-sdk.iife.min.js +23 -23
- package/dist/composer.d.ts +36 -23
- package/dist/composer.js +61 -11
- package/dist/container.d.ts +2 -6
- package/dist/container.js +0 -28
- package/dist/filesystem.d.ts +58 -17
- package/dist/filesystem.js +169 -51
- package/dist/index.d.ts +30 -26
- package/dist/index.js +37 -32
- package/dist/log.d.ts +11 -5
- package/dist/log.js +10 -7
- package/dist/metrics.d.ts +10 -0
- package/dist/metrics.js +13 -0
- package/dist/ports.d.ts +10 -0
- package/dist/ports.js +13 -0
- package/dist/publications.d.ts +222 -0
- package/dist/{deployments.js → publications.js} +64 -69
- package/dist/repl.d.ts +0 -2
- package/dist/repl.js +0 -3
- package/dist/runtime/rest.js +1 -4
- package/dist/runtime-telemetry.d.ts +15 -0
- package/dist/runtime-telemetry.js +111 -0
- package/dist/schemas/{deployments.d.ts → publications.d.ts} +76 -76
- package/dist/schemas/publications.js +133 -0
- package/dist/services.d.ts +2 -9
- package/dist/services.js +3 -10
- package/dist/shell.d.ts +52 -22
- package/dist/shell.js +103 -75
- package/dist/terminal.d.ts +18 -14
- package/dist/terminal.js +29 -49
- package/docs/api-summary.md +37 -29
- package/docs/cdn-usage.md +4 -4
- package/docs/getting-started.md +17 -17
- package/examples/README.md +8 -9
- package/examples/basic.ts +2 -2
- package/examples/git-merge-smoke.ts +3 -6
- package/examples/laravel-load-test.ts +80 -98
- package/examples/notebook-readonly-smoke.ts +38 -41
- package/examples/publication-provider-label.ts +11 -0
- package/examples/{deploy-cloudflare-container.ts → publish-cloudflare-container.ts} +11 -11
- package/examples/{deploy-laravel-cloud.ts → publish-laravel-cloud.ts} +11 -11
- package/examples/{deploy-ssh-agent.ts → publish-ssh-agent.ts} +15 -16
- package/package.json +7 -2
- package/dist/deployments.d.ts +0 -251
- package/dist/laravel.d.ts +0 -22
- package/dist/laravel.js +0 -11
- package/dist/schemas/deployments.js +0 -133
- package/examples/deployment-provider-label.ts +0 -11
|
@@ -109,11 +109,122 @@ var Filesystem = class {
|
|
|
109
109
|
}
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
async write(path, contents, options = {}) {
|
|
113
|
+
const resolvedOptions = {
|
|
114
|
+
overwrite: true,
|
|
115
|
+
create: true,
|
|
116
|
+
unlock: false,
|
|
117
|
+
atomic: false,
|
|
118
|
+
...options
|
|
119
|
+
};
|
|
120
|
+
const source = typeof contents === "string" ? new TextEncoder().encode(contents) : contents;
|
|
121
|
+
if (this.okra.runtimeTransport === "rest") {
|
|
122
|
+
const bytes = source instanceof Uint8Array ? source : await collectBytes(source);
|
|
123
|
+
await this.okra.invoke("fs.writeFile", {
|
|
124
|
+
path,
|
|
125
|
+
contents: bytes,
|
|
126
|
+
options: resolvedOptions
|
|
127
|
+
}).catch((error51) => this.handleError(error51));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const id = nanoid();
|
|
131
|
+
const completion = this.okra.invoke("fs.writeStream", { id, path, options: resolvedOptions });
|
|
132
|
+
void completion.catch(() => {
|
|
133
|
+
});
|
|
134
|
+
try {
|
|
135
|
+
for await (const chunk of toAsyncIterable(source)) {
|
|
136
|
+
const written = await this.okra.invoke("fs.writeChunk", { id, contents: chunk });
|
|
137
|
+
if (!written) {
|
|
138
|
+
throw new Error(`File write stream ${id} is not available`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const ended = await this.okra.invoke("fs.endWrite", { id });
|
|
142
|
+
if (!ended) {
|
|
143
|
+
throw new Error(`File write stream ${id} could not be completed`);
|
|
144
|
+
}
|
|
145
|
+
await completion;
|
|
146
|
+
} catch (error51) {
|
|
147
|
+
await this.okra.invoke("fs.abortWrite", { id }).catch(() => false);
|
|
148
|
+
await completion.catch(() => false);
|
|
149
|
+
throw error51;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async read(path) {
|
|
153
|
+
try {
|
|
154
|
+
const content = await this.okra.invoke("fs.readFile", { path });
|
|
155
|
+
return content instanceof Uint8Array ? content : new TextEncoder().encode(content);
|
|
156
|
+
} catch (error51) {
|
|
157
|
+
this.handleError(error51);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async readText(path) {
|
|
161
|
+
return new TextDecoder().decode(await this.read(path));
|
|
162
|
+
}
|
|
163
|
+
async readLines(path, range) {
|
|
164
|
+
try {
|
|
165
|
+
const result = await this.okra.invoke("fs.readFile", {
|
|
166
|
+
path,
|
|
167
|
+
lineRange: {
|
|
168
|
+
lineStart: range.start,
|
|
169
|
+
lineEnd: range.end
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
if (typeof result === "string" || result instanceof Uint8Array) {
|
|
173
|
+
throw new Error(`Unexpected ranged file response for ${path}`);
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
start: result.lineStart,
|
|
177
|
+
end: result.lineEnd,
|
|
178
|
+
content: result.content,
|
|
179
|
+
...result.error === null ? {} : { warning: result.error }
|
|
180
|
+
};
|
|
181
|
+
} catch (error51) {
|
|
182
|
+
this.handleError(error51);
|
|
183
|
+
}
|
|
114
184
|
}
|
|
115
|
-
|
|
116
|
-
|
|
185
|
+
readStream(path) {
|
|
186
|
+
if (this.okra.runtimeTransport === "rest") {
|
|
187
|
+
return new ReadableStream({
|
|
188
|
+
start: async (controller) => {
|
|
189
|
+
try {
|
|
190
|
+
controller.enqueue(await this.read(path));
|
|
191
|
+
controller.close();
|
|
192
|
+
} catch (error51) {
|
|
193
|
+
controller.error(error51);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
const id = nanoid();
|
|
199
|
+
let disposable = null;
|
|
200
|
+
let closed = false;
|
|
201
|
+
return new ReadableStream({
|
|
202
|
+
start: (controller) => {
|
|
203
|
+
disposable = this.okra.listen(`fs.read.${id}`, (event) => {
|
|
204
|
+
controller.enqueue(event.data);
|
|
205
|
+
});
|
|
206
|
+
void this.okra.invoke("fs.readStream", { id, path }).then(() => {
|
|
207
|
+
if (!closed) {
|
|
208
|
+
closed = true;
|
|
209
|
+
disposable?.dispose();
|
|
210
|
+
controller.close();
|
|
211
|
+
}
|
|
212
|
+
}).catch((error51) => {
|
|
213
|
+
if (!closed) {
|
|
214
|
+
closed = true;
|
|
215
|
+
disposable?.dispose();
|
|
216
|
+
controller.error(error51);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
},
|
|
220
|
+
cancel: async () => {
|
|
221
|
+
if (!closed) {
|
|
222
|
+
closed = true;
|
|
223
|
+
disposable?.dispose();
|
|
224
|
+
await this.okra.invoke("fs.cancelRead", { id }).catch(() => false);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
});
|
|
117
228
|
}
|
|
118
229
|
find(query, options = {
|
|
119
230
|
useIgnoreFiles: false,
|
|
@@ -192,53 +303,38 @@ var Filesystem = class {
|
|
|
192
303
|
const disposable = this.okra.listen(`fs.text.search.${sid}`, localOnMatch);
|
|
193
304
|
return this.okra.invoke("fs.textSearch", { query, options: { ...defaultOptions, ...options } }).finally(() => disposable.dispose());
|
|
194
305
|
}
|
|
195
|
-
|
|
196
|
-
return this.okra.invoke("fs.
|
|
197
|
-
}
|
|
198
|
-
move(from, to) {
|
|
199
|
-
return this.okra.invoke("fs.move", { from, to });
|
|
200
|
-
}
|
|
201
|
-
remove(path, type) {
|
|
202
|
-
return this.okra.invoke("fs.remove", { path, type });
|
|
203
|
-
}
|
|
204
|
-
async readFile(path, lineRange) {
|
|
205
|
-
try {
|
|
206
|
-
const content = await this.okra.invoke("fs.readFile", { path, lineRange });
|
|
207
|
-
if (content instanceof Uint8Array) {
|
|
208
|
-
return content;
|
|
209
|
-
}
|
|
210
|
-
if (typeof content === "string") {
|
|
211
|
-
return new TextEncoder().encode(content);
|
|
212
|
-
}
|
|
213
|
-
return content;
|
|
214
|
-
} catch (e) {
|
|
215
|
-
this.handleError(e);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
tail(path, lines = 10) {
|
|
219
|
-
return this.okra.invoke("fs.tail", { path, lines }).catch((e) => this.handleError(e));
|
|
220
|
-
}
|
|
221
|
-
writeFile(path, contents, options) {
|
|
222
|
-
return this.okra.invoke("fs.writeFile", {
|
|
223
|
-
path,
|
|
224
|
-
contents,
|
|
225
|
-
options
|
|
226
|
-
}).catch((e) => this.handleError(e));
|
|
306
|
+
tail(path, options = {}) {
|
|
307
|
+
return this.okra.invoke("fs.tail", { path, lines: options.lines ?? 10 }).catch((e) => this.handleError(e));
|
|
227
308
|
}
|
|
228
309
|
stat(path) {
|
|
229
310
|
return this.okra.invoke("fs.stat", { path }).catch((e) => this.handleError(e));
|
|
230
311
|
}
|
|
231
|
-
|
|
232
|
-
return this.okra.invoke("fs.rename", {
|
|
312
|
+
move(from, to, options = {}) {
|
|
313
|
+
return this.okra.invoke("fs.rename", {
|
|
314
|
+
from,
|
|
315
|
+
to,
|
|
316
|
+
options: { overwrite: false, ...options }
|
|
317
|
+
}).catch((e) => this.handleError(e));
|
|
233
318
|
}
|
|
234
|
-
|
|
235
|
-
return this.okra.invoke("fs.delete", {
|
|
319
|
+
remove(path, options = {}) {
|
|
320
|
+
return this.okra.invoke("fs.delete", {
|
|
321
|
+
path,
|
|
322
|
+
options: { recursive: false, useTrash: false, atomic: false, ...options }
|
|
323
|
+
}).catch((e) => this.handleError(e));
|
|
236
324
|
}
|
|
237
|
-
copy(source, destination, options) {
|
|
238
|
-
return this.okra.invoke("fs.copy", {
|
|
325
|
+
copy(source, destination, options = {}) {
|
|
326
|
+
return this.okra.invoke("fs.copy", {
|
|
327
|
+
source,
|
|
328
|
+
destination,
|
|
329
|
+
options: { overwrite: false, ...options }
|
|
330
|
+
}).catch((e) => this.handleError(e));
|
|
239
331
|
}
|
|
240
|
-
|
|
241
|
-
return this.okra.invoke("fs.readDirectory", {
|
|
332
|
+
list(path, options = {}) {
|
|
333
|
+
return this.okra.invoke("fs.readDirectory", {
|
|
334
|
+
path,
|
|
335
|
+
include: options.include ?? [],
|
|
336
|
+
exclude: options.exclude ?? []
|
|
337
|
+
}).catch((e) => this.handleError(e));
|
|
242
338
|
}
|
|
243
339
|
createDirectory(path) {
|
|
244
340
|
return this.okra.invoke("fs.createDirectory", { path }).catch((e) => this.handleError(e));
|
|
@@ -267,17 +363,17 @@ var Filesystem = class {
|
|
|
267
363
|
exists(path) {
|
|
268
364
|
return this.stat(path).then(() => true).catch(() => false);
|
|
269
365
|
}
|
|
270
|
-
async download(
|
|
366
|
+
async download(options = {}) {
|
|
271
367
|
const id = nanoid();
|
|
272
|
-
const stream = !!
|
|
368
|
+
const stream = !!options.onChunk;
|
|
273
369
|
const chunks = [];
|
|
274
370
|
const disposable = this.okra.listen(
|
|
275
371
|
`fs.download.${id}`,
|
|
276
|
-
stream ?
|
|
372
|
+
stream ? options.onChunk : (data) => {
|
|
277
373
|
chunks.push(data);
|
|
278
374
|
}
|
|
279
375
|
);
|
|
280
|
-
return this.okra.invoke("fs.download", { id, exclude, include }).then(() => new Blob(chunks, { type: "application/octet-stream" })).finally(() => disposable.dispose());
|
|
376
|
+
return this.okra.invoke("fs.download", { id, exclude: options.exclude, include: options.include }).then(() => new Blob(chunks, { type: "application/octet-stream" })).finally(() => disposable.dispose());
|
|
281
377
|
}
|
|
282
378
|
tree(path = "/") {
|
|
283
379
|
return this.okra.invoke("fs.tree", { path });
|
|
@@ -289,6 +385,28 @@ var Filesystem = class {
|
|
|
289
385
|
throw e;
|
|
290
386
|
}
|
|
291
387
|
};
|
|
388
|
+
async function* toAsyncIterable(contents) {
|
|
389
|
+
if (contents instanceof Uint8Array) {
|
|
390
|
+
yield contents;
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
yield* contents;
|
|
394
|
+
}
|
|
395
|
+
async function collectBytes(stream) {
|
|
396
|
+
const chunks = [];
|
|
397
|
+
let length = 0;
|
|
398
|
+
for await (const chunk of stream) {
|
|
399
|
+
chunks.push(chunk);
|
|
400
|
+
length += chunk.byteLength;
|
|
401
|
+
}
|
|
402
|
+
const output = new Uint8Array(length);
|
|
403
|
+
let offset = 0;
|
|
404
|
+
for (const chunk of chunks) {
|
|
405
|
+
output.set(chunk, offset);
|
|
406
|
+
offset += chunk.byteLength;
|
|
407
|
+
}
|
|
408
|
+
return output;
|
|
409
|
+
}
|
|
292
410
|
|
|
293
411
|
// src/errors/index.ts
|
|
294
412
|
var PromiseTimeoutError = class extends Error {
|
|
@@ -334,33 +452,35 @@ var once = (fn) => {
|
|
|
334
452
|
// src/terminal.ts
|
|
335
453
|
var TERMINAL_INPUT_FLUSH_DELAY_MS = 8;
|
|
336
454
|
var terminalInputFlushPattern = /[\x00-\x1f\x7f]/;
|
|
337
|
-
var
|
|
455
|
+
var Terminals = class {
|
|
338
456
|
constructor(okra) {
|
|
339
457
|
this.okra = okra;
|
|
340
458
|
}
|
|
341
459
|
list() {
|
|
342
460
|
return this.okra.invoke("terminal.list");
|
|
343
461
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
462
|
+
async create(options = {}) {
|
|
463
|
+
const id = options.id ?? nanoid();
|
|
464
|
+
const handle = this.processHandle(id, options.abortSignal);
|
|
465
|
+
const command = typeof options.command === "string" && options.args?.length ? [options.command, ...options.args] : options.command;
|
|
466
|
+
const { abortSignal, args: _args, ...input } = options;
|
|
467
|
+
try {
|
|
468
|
+
const task = await this.okra.invoke(
|
|
469
|
+
"terminal.create",
|
|
470
|
+
{
|
|
471
|
+
...input,
|
|
472
|
+
id,
|
|
473
|
+
kind: options.kind ?? "bash",
|
|
474
|
+
size: options.size ?? [80, 24],
|
|
475
|
+
command
|
|
476
|
+
},
|
|
477
|
+
{ abortSignal }
|
|
478
|
+
);
|
|
479
|
+
return { ...handle.process, ...task };
|
|
480
|
+
} catch (error51) {
|
|
481
|
+
handle.dispose();
|
|
482
|
+
throw error51;
|
|
483
|
+
}
|
|
364
484
|
}
|
|
365
485
|
async attach(id, opts) {
|
|
366
486
|
const handle = this.processHandle(id, opts?.abortSignal);
|
|
@@ -386,31 +506,6 @@ var Terminal = class {
|
|
|
386
506
|
throw error51;
|
|
387
507
|
}
|
|
388
508
|
}
|
|
389
|
-
async spawn(command, args, opts) {
|
|
390
|
-
const id = opts?.id || nanoid();
|
|
391
|
-
const handle = this.processHandle(id, opts?.abortSignal);
|
|
392
|
-
const { abortSignal, ...otherOpts } = opts ?? {};
|
|
393
|
-
try {
|
|
394
|
-
const result = await this.okra.invoke(
|
|
395
|
-
"terminal.spawn",
|
|
396
|
-
{
|
|
397
|
-
command: [command, ...args],
|
|
398
|
-
opts: {
|
|
399
|
-
id,
|
|
400
|
-
...otherOpts
|
|
401
|
-
}
|
|
402
|
-
},
|
|
403
|
-
{ abortSignal }
|
|
404
|
-
);
|
|
405
|
-
return {
|
|
406
|
-
...handle.process,
|
|
407
|
-
...result
|
|
408
|
-
};
|
|
409
|
-
} catch (error51) {
|
|
410
|
-
handle.dispose();
|
|
411
|
-
throw error51;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
509
|
processHandle(id, abortSignal) {
|
|
415
510
|
const disposables = /* @__PURE__ */ new Set();
|
|
416
511
|
let abortHandler;
|
|
@@ -436,7 +531,7 @@ var Terminal = class {
|
|
|
436
531
|
}
|
|
437
532
|
const input2 = pendingInput;
|
|
438
533
|
pendingInput = "";
|
|
439
|
-
void this.input
|
|
534
|
+
void this.okra.send("terminal.input", { id, input: input2 });
|
|
440
535
|
};
|
|
441
536
|
const scheduleInputFlush = () => {
|
|
442
537
|
if (inputFlushTimer) {
|
|
@@ -444,7 +539,8 @@ var Terminal = class {
|
|
|
444
539
|
}
|
|
445
540
|
inputFlushTimer = setTimeout(flushInput, TERMINAL_INPUT_FLUSH_DELAY_MS);
|
|
446
541
|
};
|
|
447
|
-
const queueInput = (
|
|
542
|
+
const queueInput = (value) => {
|
|
543
|
+
const chunk = typeof value === "string" ? value : new TextDecoder().decode(value);
|
|
448
544
|
pendingInput += chunk;
|
|
449
545
|
if (terminalInputFlushPattern.test(chunk)) {
|
|
450
546
|
flushInput();
|
|
@@ -466,7 +562,7 @@ var Terminal = class {
|
|
|
466
562
|
start: (_controller) => {
|
|
467
563
|
controller = _controller;
|
|
468
564
|
disposables.add(
|
|
469
|
-
this.listen(`terminal.output.${id}`, (data) => {
|
|
565
|
+
this.okra.listen(`terminal.output.${id}`, (data) => {
|
|
470
566
|
controller?.enqueue(data.output);
|
|
471
567
|
})
|
|
472
568
|
);
|
|
@@ -476,9 +572,9 @@ var Terminal = class {
|
|
|
476
572
|
disposeInput();
|
|
477
573
|
}
|
|
478
574
|
});
|
|
479
|
-
const
|
|
575
|
+
const completion = new Promise((resolve) => {
|
|
480
576
|
disposables.add(
|
|
481
|
-
this.listen(`terminal.close.${id}`, (data) => {
|
|
577
|
+
this.okra.listen(`terminal.close.${id}`, (data) => {
|
|
482
578
|
if (controller) {
|
|
483
579
|
try {
|
|
484
580
|
controller.close();
|
|
@@ -505,7 +601,7 @@ var Terminal = class {
|
|
|
505
601
|
}
|
|
506
602
|
return {
|
|
507
603
|
process: {
|
|
508
|
-
|
|
604
|
+
wait: () => completion,
|
|
509
605
|
input,
|
|
510
606
|
output,
|
|
511
607
|
kill,
|
|
@@ -543,37 +639,9 @@ var Container = class {
|
|
|
543
639
|
state() {
|
|
544
640
|
return this.okra.invoke("container.state");
|
|
545
641
|
}
|
|
546
|
-
openedPorts() {
|
|
547
|
-
return this.okra.invoke("container.opened-ports");
|
|
548
|
-
}
|
|
549
642
|
setPhp(version2) {
|
|
550
643
|
return this.okra.invoke("container.set-php", { version: version2 });
|
|
551
644
|
}
|
|
552
|
-
enableTelemetry(features) {
|
|
553
|
-
return this.okra.invoke("container.stream-telemetry", { features: Array.from(features) });
|
|
554
|
-
}
|
|
555
|
-
stopTelemetry() {
|
|
556
|
-
return this.okra.invoke("container.stop-telemetry");
|
|
557
|
-
}
|
|
558
|
-
listen(event, handler) {
|
|
559
|
-
return this.okra.listen(event, handler);
|
|
560
|
-
}
|
|
561
|
-
onPort(handler) {
|
|
562
|
-
let ports = [];
|
|
563
|
-
return this.listen("container.ports", (newPorts) => {
|
|
564
|
-
for (const port of newPorts) {
|
|
565
|
-
if (!ports.some((p) => p.port === port.port)) {
|
|
566
|
-
handler(port, "open");
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
for (const port of ports) {
|
|
570
|
-
if (!newPorts.some((p) => p.port === port.port)) {
|
|
571
|
-
handler(port, "close");
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
ports = newPorts;
|
|
575
|
-
});
|
|
576
|
-
}
|
|
577
645
|
};
|
|
578
646
|
|
|
579
647
|
// src/auth.ts
|
|
@@ -581,9 +649,6 @@ var Auth = class {
|
|
|
581
649
|
constructor(okra) {
|
|
582
650
|
this.okra = okra;
|
|
583
651
|
}
|
|
584
|
-
logout() {
|
|
585
|
-
this.okra.dispose();
|
|
586
|
-
}
|
|
587
652
|
login(runtimeUrl) {
|
|
588
653
|
const runtimeTicket = new URL(runtimeUrl).searchParams.get("ticket");
|
|
589
654
|
if (runtimeTicket === null || runtimeTicket === "") {
|
|
@@ -663,61 +728,376 @@ var LspConnection = class _LspConnection {
|
|
|
663
728
|
}
|
|
664
729
|
};
|
|
665
730
|
|
|
731
|
+
// src/shell.ts
|
|
732
|
+
function resolveRunInput(command, argsOrOpts = [], opts) {
|
|
733
|
+
const args = Array.isArray(argsOrOpts) ? argsOrOpts : [];
|
|
734
|
+
const resolvedOpts = Array.isArray(argsOrOpts) ? opts : argsOrOpts;
|
|
735
|
+
return {
|
|
736
|
+
command: Array.isArray(command) ? command : args.length > 0 ? [command, ...args] : command,
|
|
737
|
+
opts: { tty: false, ...resolvedOpts }
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
var CommandError = class extends Error {
|
|
741
|
+
constructor(result) {
|
|
742
|
+
super(result.output);
|
|
743
|
+
this.result = result;
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
var ProcessResult = class {
|
|
747
|
+
constructor(output, stdout, stderr, exitCode) {
|
|
748
|
+
this.output = output;
|
|
749
|
+
this.stdout = stdout;
|
|
750
|
+
this.stderr = stderr;
|
|
751
|
+
this.exitCode = exitCode;
|
|
752
|
+
}
|
|
753
|
+
throw() {
|
|
754
|
+
if (this.exitCode !== 0) {
|
|
755
|
+
throw new CommandError(this);
|
|
756
|
+
}
|
|
757
|
+
return this;
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
var ProcessReadable = class {
|
|
761
|
+
constructor() {
|
|
762
|
+
this.controller = null;
|
|
763
|
+
this.closed = false;
|
|
764
|
+
this.stream = new ReadableStream({
|
|
765
|
+
start: (controller) => {
|
|
766
|
+
this.controller = controller;
|
|
767
|
+
},
|
|
768
|
+
cancel: () => {
|
|
769
|
+
this.closed = true;
|
|
770
|
+
this.controller = null;
|
|
771
|
+
}
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
enqueue(value) {
|
|
775
|
+
if (!this.closed) {
|
|
776
|
+
this.controller?.enqueue(value);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
close() {
|
|
780
|
+
if (this.closed) {
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
this.closed = true;
|
|
784
|
+
this.controller?.close();
|
|
785
|
+
this.controller = null;
|
|
786
|
+
}
|
|
787
|
+
fail(error51) {
|
|
788
|
+
if (this.closed) {
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
this.closed = true;
|
|
792
|
+
this.controller?.error(error51);
|
|
793
|
+
this.controller = null;
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
var ShellProcess = class {
|
|
797
|
+
constructor(id, okra, command, opts) {
|
|
798
|
+
this.id = id;
|
|
799
|
+
this.okra = okra;
|
|
800
|
+
const output = new ProcessReadable();
|
|
801
|
+
const stdout = new ProcessReadable();
|
|
802
|
+
const stderr = new ProcessReadable();
|
|
803
|
+
this.output = output.stream;
|
|
804
|
+
this.stdout = stdout.stream;
|
|
805
|
+
this.stderr = stderr.stream;
|
|
806
|
+
this.stdin = new WritableStream({
|
|
807
|
+
write: async (chunk) => {
|
|
808
|
+
const input = typeof chunk === "string" ? chunk : new TextDecoder().decode(chunk);
|
|
809
|
+
const written = await this.okra.invoke("shell.input", { id: this.id, input });
|
|
810
|
+
if (!written) {
|
|
811
|
+
throw new Error(`Process ${this.id} is not accepting input`);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
const encoder = new TextEncoder();
|
|
816
|
+
let subscription = this.okra.listen(`shell.output.${this.id}`, (event) => {
|
|
817
|
+
const data = encoder.encode(event.output);
|
|
818
|
+
const source = event.source ?? "output";
|
|
819
|
+
output.enqueue({ source, data });
|
|
820
|
+
if (source === "stderr") {
|
|
821
|
+
stderr.enqueue(data);
|
|
822
|
+
} else {
|
|
823
|
+
stdout.enqueue(data);
|
|
824
|
+
}
|
|
825
|
+
});
|
|
826
|
+
const finish = () => {
|
|
827
|
+
subscription?.dispose();
|
|
828
|
+
subscription = null;
|
|
829
|
+
output.close();
|
|
830
|
+
stdout.close();
|
|
831
|
+
stderr.close();
|
|
832
|
+
};
|
|
833
|
+
const fail = (error51) => {
|
|
834
|
+
subscription?.dispose();
|
|
835
|
+
subscription = null;
|
|
836
|
+
output.fail(error51);
|
|
837
|
+
stdout.fail(error51);
|
|
838
|
+
stderr.fail(error51);
|
|
839
|
+
};
|
|
840
|
+
const { abortSignal, ...payloadOpts } = opts;
|
|
841
|
+
this.completion = this.okra.invoke(
|
|
842
|
+
"shell.exec",
|
|
843
|
+
{ command, opts: { ...payloadOpts, id: this.id } },
|
|
844
|
+
{ abortSignal }
|
|
845
|
+
).then((result) => {
|
|
846
|
+
finish();
|
|
847
|
+
return new ProcessResult(result.output, result.stdout, result.stderr, result.exitCode);
|
|
848
|
+
}).catch((error51) => {
|
|
849
|
+
fail(error51);
|
|
850
|
+
throw error51;
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
wait() {
|
|
854
|
+
return this.completion;
|
|
855
|
+
}
|
|
856
|
+
async kill() {
|
|
857
|
+
await this.okra.invoke("shell.kill", { id: this.id });
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
var Shell = class {
|
|
861
|
+
constructor(okra) {
|
|
862
|
+
this.okra = okra;
|
|
863
|
+
}
|
|
864
|
+
run(command, argsOrOpts = [], opts) {
|
|
865
|
+
const input = resolveRunInput(command, argsOrOpts, opts);
|
|
866
|
+
const id = input.opts?.id ?? nanoid();
|
|
867
|
+
return new ShellProcess(id, this.okra, input.command, { ...input.opts, id });
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
|
|
666
871
|
// src/composer.ts
|
|
872
|
+
var ComposerProcess = class {
|
|
873
|
+
constructor(id, okra, command, args, options) {
|
|
874
|
+
this.id = id;
|
|
875
|
+
this.okra = okra;
|
|
876
|
+
const output = new ProcessReadable();
|
|
877
|
+
const stdout = new ProcessReadable();
|
|
878
|
+
const stderr = new ProcessReadable();
|
|
879
|
+
this.output = output.stream;
|
|
880
|
+
this.stdout = stdout.stream;
|
|
881
|
+
this.stderr = stderr.stream;
|
|
882
|
+
const encoder = new TextEncoder();
|
|
883
|
+
let subscription = this.okra.listen(`composer.output.${this.id}`, (event) => {
|
|
884
|
+
const data = encoder.encode(event.output);
|
|
885
|
+
const source = event.source ?? "output";
|
|
886
|
+
output.enqueue({ source, data });
|
|
887
|
+
if (source === "stderr") {
|
|
888
|
+
stderr.enqueue(data);
|
|
889
|
+
} else {
|
|
890
|
+
stdout.enqueue(data);
|
|
891
|
+
}
|
|
892
|
+
});
|
|
893
|
+
const finish = () => {
|
|
894
|
+
subscription?.dispose();
|
|
895
|
+
subscription = null;
|
|
896
|
+
output.close();
|
|
897
|
+
stdout.close();
|
|
898
|
+
stderr.close();
|
|
899
|
+
};
|
|
900
|
+
const fail = (error51) => {
|
|
901
|
+
subscription?.dispose();
|
|
902
|
+
subscription = null;
|
|
903
|
+
output.fail(error51);
|
|
904
|
+
stdout.fail(error51);
|
|
905
|
+
stderr.fail(error51);
|
|
906
|
+
};
|
|
907
|
+
this.completion = this.okra.invoke("composer.invoke", { id, command, args, options }).then((result) => {
|
|
908
|
+
finish();
|
|
909
|
+
return new ProcessResult(result.output, result.stdout, result.stderr, result.exitCode);
|
|
910
|
+
}).catch((error51) => {
|
|
911
|
+
fail(error51);
|
|
912
|
+
throw error51;
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
wait() {
|
|
916
|
+
return this.completion;
|
|
917
|
+
}
|
|
918
|
+
async kill() {
|
|
919
|
+
await this.okra.invoke("composer.kill", { id: this.id });
|
|
920
|
+
}
|
|
921
|
+
};
|
|
667
922
|
var Composer = class {
|
|
668
923
|
constructor(okra, client) {
|
|
669
924
|
this.okra = okra;
|
|
670
925
|
this.credentials = new ComposerCredentials(client, okra.data.id);
|
|
671
926
|
}
|
|
672
|
-
|
|
673
|
-
return this.okra
|
|
927
|
+
run(command, args = {}, options = {}) {
|
|
928
|
+
return new ComposerProcess(nanoid(), this.okra, command, args, options);
|
|
674
929
|
}
|
|
675
|
-
dumpAutoload() {
|
|
676
|
-
return this.
|
|
930
|
+
dumpAutoload(options = {}) {
|
|
931
|
+
return this.run("dump-autoload", {}, options);
|
|
677
932
|
}
|
|
678
933
|
install(options = {}) {
|
|
679
|
-
return this.
|
|
934
|
+
return this.run("install", {}, options);
|
|
680
935
|
}
|
|
681
936
|
update(args, options = {}) {
|
|
682
|
-
return this.
|
|
937
|
+
return this.run("update", args, options);
|
|
683
938
|
}
|
|
684
939
|
require(packages, options = {}) {
|
|
685
|
-
return this.
|
|
940
|
+
return this.run("require", packages, options);
|
|
686
941
|
}
|
|
687
942
|
remove(args, options = {}) {
|
|
688
|
-
return this.
|
|
689
|
-
}
|
|
690
|
-
stream(fn) {
|
|
691
|
-
return this.okra.listen("composer.log", fn);
|
|
943
|
+
return this.run("remove", args, options);
|
|
692
944
|
}
|
|
693
945
|
packages() {
|
|
694
946
|
return this.okra.invoke("composer.packages");
|
|
695
947
|
}
|
|
696
948
|
};
|
|
697
949
|
|
|
698
|
-
// src/
|
|
699
|
-
var
|
|
950
|
+
// src/runtime-telemetry.ts
|
|
951
|
+
var RuntimeTelemetry = class {
|
|
700
952
|
constructor(okra) {
|
|
701
953
|
this.okra = okra;
|
|
954
|
+
this.references = /* @__PURE__ */ new Map();
|
|
955
|
+
this.synchronization = Promise.resolve();
|
|
956
|
+
if (okra.runtimeTransport === "realtime") {
|
|
957
|
+
okra.onDidConnect(() => {
|
|
958
|
+
if (this.references.size > 0) {
|
|
959
|
+
void this.synchronize();
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
}
|
|
702
963
|
}
|
|
703
|
-
|
|
704
|
-
|
|
964
|
+
async acquire(feature) {
|
|
965
|
+
this.references.set(feature, (this.references.get(feature) ?? 0) + 1);
|
|
966
|
+
try {
|
|
967
|
+
await this.synchronize();
|
|
968
|
+
} catch (error51) {
|
|
969
|
+
this.removeReference(feature);
|
|
970
|
+
throw error51;
|
|
971
|
+
}
|
|
972
|
+
let released = false;
|
|
973
|
+
return async () => {
|
|
974
|
+
if (released) {
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
released = true;
|
|
978
|
+
this.removeReference(feature);
|
|
979
|
+
await this.synchronize();
|
|
980
|
+
};
|
|
705
981
|
}
|
|
706
|
-
|
|
707
|
-
|
|
982
|
+
removeReference(feature) {
|
|
983
|
+
const references = this.references.get(feature) ?? 0;
|
|
984
|
+
if (references <= 1) {
|
|
985
|
+
this.references.delete(feature);
|
|
986
|
+
} else {
|
|
987
|
+
this.references.set(feature, references - 1);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
synchronize() {
|
|
991
|
+
this.synchronization = this.synchronization.catch(() => {
|
|
992
|
+
}).then(async () => {
|
|
993
|
+
const features = Array.from(this.references.keys());
|
|
994
|
+
if (features.length === 0) {
|
|
995
|
+
await this.okra.invoke("container.stop-telemetry");
|
|
996
|
+
} else {
|
|
997
|
+
await this.okra.invoke("container.stream-telemetry", { features });
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
return this.synchronization;
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
function watchRuntimeTelemetry(okra, telemetry, feature, event, transform2, options = {}) {
|
|
1004
|
+
let subscription = null;
|
|
1005
|
+
let release = null;
|
|
1006
|
+
let closed = false;
|
|
1007
|
+
let abort = null;
|
|
1008
|
+
const stop = async () => {
|
|
1009
|
+
if (closed) {
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
closed = true;
|
|
1013
|
+
subscription?.dispose();
|
|
1014
|
+
subscription = null;
|
|
1015
|
+
if (abort && options.signal) {
|
|
1016
|
+
options.signal.removeEventListener("abort", abort);
|
|
1017
|
+
}
|
|
1018
|
+
abort = null;
|
|
1019
|
+
await release?.();
|
|
1020
|
+
release = null;
|
|
1021
|
+
};
|
|
1022
|
+
return new ReadableStream({
|
|
1023
|
+
start(controller) {
|
|
1024
|
+
subscription = okra.listen(event, (data) => {
|
|
1025
|
+
if (!closed) {
|
|
1026
|
+
controller.enqueue(transform2(data));
|
|
1027
|
+
}
|
|
1028
|
+
});
|
|
1029
|
+
if (options.signal) {
|
|
1030
|
+
abort = () => {
|
|
1031
|
+
void stop().finally(() => controller.error(options.signal?.reason ?? new Error("Aborted")));
|
|
1032
|
+
};
|
|
1033
|
+
if (options.signal.aborted) {
|
|
1034
|
+
abort();
|
|
1035
|
+
return;
|
|
1036
|
+
}
|
|
1037
|
+
options.signal.addEventListener("abort", abort, { once: true });
|
|
1038
|
+
}
|
|
1039
|
+
void telemetry.acquire(feature).then(async (releaseTelemetry) => {
|
|
1040
|
+
if (closed) {
|
|
1041
|
+
await releaseTelemetry();
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
1044
|
+
release = releaseTelemetry;
|
|
1045
|
+
}).catch((error51) => {
|
|
1046
|
+
if (!closed) {
|
|
1047
|
+
closed = true;
|
|
1048
|
+
subscription?.dispose();
|
|
1049
|
+
if (abort && options.signal) {
|
|
1050
|
+
options.signal.removeEventListener("abort", abort);
|
|
1051
|
+
}
|
|
1052
|
+
abort = null;
|
|
1053
|
+
controller.error(error51);
|
|
1054
|
+
}
|
|
1055
|
+
});
|
|
1056
|
+
},
|
|
1057
|
+
cancel: stop
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
// src/log.ts
|
|
1062
|
+
var Logs = class {
|
|
1063
|
+
constructor(okra, telemetry) {
|
|
1064
|
+
this.okra = okra;
|
|
1065
|
+
this.telemetry = telemetry;
|
|
1066
|
+
}
|
|
1067
|
+
follow(options = {}) {
|
|
1068
|
+
return watchRuntimeTelemetry(this.okra, this.telemetry, "logs", "notebook.log", (message) => ({
|
|
1069
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1070
|
+
source: "runtime",
|
|
1071
|
+
message
|
|
1072
|
+
}), options);
|
|
708
1073
|
}
|
|
709
1074
|
};
|
|
710
1075
|
|
|
711
|
-
// src/
|
|
712
|
-
var
|
|
713
|
-
constructor(okra) {
|
|
1076
|
+
// src/metrics.ts
|
|
1077
|
+
var Metrics = class {
|
|
1078
|
+
constructor(okra, telemetry) {
|
|
714
1079
|
this.okra = okra;
|
|
1080
|
+
this.telemetry = telemetry;
|
|
715
1081
|
}
|
|
716
|
-
|
|
717
|
-
return this.okra.invoke("
|
|
1082
|
+
current() {
|
|
1083
|
+
return this.okra.invoke("container.stats");
|
|
1084
|
+
}
|
|
1085
|
+
watch(options = {}) {
|
|
1086
|
+
return watchRuntimeTelemetry(this.okra, this.telemetry, "stats", "container.stats", (stats) => stats, options);
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
|
|
1090
|
+
// src/ports.ts
|
|
1091
|
+
var Ports = class {
|
|
1092
|
+
constructor(okra, telemetry) {
|
|
1093
|
+
this.okra = okra;
|
|
1094
|
+
this.telemetry = telemetry;
|
|
1095
|
+
}
|
|
1096
|
+
list() {
|
|
1097
|
+
return this.okra.invoke("container.opened-ports");
|
|
718
1098
|
}
|
|
719
|
-
|
|
720
|
-
return this.okra.
|
|
1099
|
+
watch(options = {}) {
|
|
1100
|
+
return watchRuntimeTelemetry(this.okra, this.telemetry, "ports", "container.ports", (ports) => ports, options);
|
|
721
1101
|
}
|
|
722
1102
|
};
|
|
723
1103
|
|
|
@@ -735,9 +1115,6 @@ var Repl = class {
|
|
|
735
1115
|
stop() {
|
|
736
1116
|
return this.okra.invoke("repl.stop");
|
|
737
1117
|
}
|
|
738
|
-
start() {
|
|
739
|
-
return this.okra.invoke("repl.start");
|
|
740
|
-
}
|
|
741
1118
|
resize(cols, rows) {
|
|
742
1119
|
return this.okra.invoke("repl.resize", { cols, rows });
|
|
743
1120
|
}
|
|
@@ -749,117 +1126,6 @@ var Repl = class {
|
|
|
749
1126
|
}
|
|
750
1127
|
};
|
|
751
1128
|
|
|
752
|
-
// src/shell.ts
|
|
753
|
-
function resolveExecInput(command, argsOrOpts = [], opts) {
|
|
754
|
-
const args = Array.isArray(argsOrOpts) ? argsOrOpts : [];
|
|
755
|
-
const resolvedOpts = Array.isArray(argsOrOpts) ? opts : argsOrOpts;
|
|
756
|
-
return {
|
|
757
|
-
command: Array.isArray(command) ? command : args.length > 0 ? [command, ...args] : command,
|
|
758
|
-
opts: resolvedOpts
|
|
759
|
-
};
|
|
760
|
-
}
|
|
761
|
-
var CommandError = class extends Error {
|
|
762
|
-
constructor(output, exitCode) {
|
|
763
|
-
super(output);
|
|
764
|
-
this.output = output;
|
|
765
|
-
this.exitCode = exitCode;
|
|
766
|
-
}
|
|
767
|
-
};
|
|
768
|
-
var Result = class {
|
|
769
|
-
constructor(output, exitCode) {
|
|
770
|
-
this.output = output;
|
|
771
|
-
this.exitCode = exitCode;
|
|
772
|
-
}
|
|
773
|
-
throw() {
|
|
774
|
-
if (this.exitCode !== 0) {
|
|
775
|
-
throw new CommandError(this.output, this.exitCode);
|
|
776
|
-
}
|
|
777
|
-
return this;
|
|
778
|
-
}
|
|
779
|
-
};
|
|
780
|
-
var Shell = class {
|
|
781
|
-
constructor(okra) {
|
|
782
|
-
this.okra = okra;
|
|
783
|
-
}
|
|
784
|
-
onOutput(id, handler) {
|
|
785
|
-
return this.okra.listen(`shell.output.${id}`, handler);
|
|
786
|
-
}
|
|
787
|
-
listen(event, handler) {
|
|
788
|
-
return this.okra.listen(event, handler);
|
|
789
|
-
}
|
|
790
|
-
async exec(command, argsOrOpts = [], opts) {
|
|
791
|
-
const input = resolveExecInput(command, argsOrOpts, opts);
|
|
792
|
-
const { abortSignal, ...payloadOpts } = input.opts ?? {};
|
|
793
|
-
const result = await this.okra.invoke(
|
|
794
|
-
"shell.exec",
|
|
795
|
-
{
|
|
796
|
-
command: input.command,
|
|
797
|
-
opts: Object.keys(payloadOpts).length > 0 ? payloadOpts : void 0
|
|
798
|
-
},
|
|
799
|
-
{ abortSignal }
|
|
800
|
-
);
|
|
801
|
-
return new Result(result.output, result.exitCode);
|
|
802
|
-
}
|
|
803
|
-
execStream(command, argsOrOpts = [], opts) {
|
|
804
|
-
const input = resolveExecInput(command, argsOrOpts, opts);
|
|
805
|
-
const id = input.opts?.id || nanoid();
|
|
806
|
-
const disposables = /* @__PURE__ */ new Set();
|
|
807
|
-
let controller = null;
|
|
808
|
-
let closed = false;
|
|
809
|
-
const dispose = () => {
|
|
810
|
-
for (const disposable of disposables) {
|
|
811
|
-
disposable.dispose();
|
|
812
|
-
}
|
|
813
|
-
disposables.clear();
|
|
814
|
-
};
|
|
815
|
-
const close = () => {
|
|
816
|
-
if (closed) {
|
|
817
|
-
return;
|
|
818
|
-
}
|
|
819
|
-
closed = true;
|
|
820
|
-
dispose();
|
|
821
|
-
if (controller) {
|
|
822
|
-
try {
|
|
823
|
-
controller.close();
|
|
824
|
-
} catch {
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
};
|
|
828
|
-
const fail = (error51) => {
|
|
829
|
-
if (closed) {
|
|
830
|
-
return;
|
|
831
|
-
}
|
|
832
|
-
closed = true;
|
|
833
|
-
dispose();
|
|
834
|
-
if (controller) {
|
|
835
|
-
controller.error(error51);
|
|
836
|
-
}
|
|
837
|
-
};
|
|
838
|
-
const output = new ReadableStream({
|
|
839
|
-
start: (_controller) => {
|
|
840
|
-
controller = _controller;
|
|
841
|
-
disposables.add(
|
|
842
|
-
this.listen(`shell.output.${id}`, (data) => {
|
|
843
|
-
controller?.enqueue(data.output);
|
|
844
|
-
})
|
|
845
|
-
);
|
|
846
|
-
},
|
|
847
|
-
cancel: () => {
|
|
848
|
-
closed = true;
|
|
849
|
-
dispose();
|
|
850
|
-
}
|
|
851
|
-
});
|
|
852
|
-
const result = this.exec(input.command, { ...input.opts, id }).then((response) => {
|
|
853
|
-
close();
|
|
854
|
-
return response;
|
|
855
|
-
}).catch((error51) => {
|
|
856
|
-
fail(error51);
|
|
857
|
-
throw error51;
|
|
858
|
-
});
|
|
859
|
-
return { output, result };
|
|
860
|
-
}
|
|
861
|
-
};
|
|
862
|
-
|
|
863
1129
|
// src/services.ts
|
|
864
1130
|
var notebookBuiltinServices = ["redis"];
|
|
865
1131
|
var notebookKnownServices = ["start", "nginx", ...notebookBuiltinServices];
|
|
@@ -879,12 +1145,6 @@ var Services = class {
|
|
|
879
1145
|
stop(name) {
|
|
880
1146
|
return this.okra.invoke("service.stop", { name });
|
|
881
1147
|
}
|
|
882
|
-
onLog(id, handler) {
|
|
883
|
-
return this.okra.listen(`service.log.${id}`, handler);
|
|
884
|
-
}
|
|
885
|
-
listen(event, handler) {
|
|
886
|
-
return this.okra.listen(event, handler);
|
|
887
|
-
}
|
|
888
1148
|
logs(name, options = {}) {
|
|
889
1149
|
if (options.follow) {
|
|
890
1150
|
return this.followLogs(name, options);
|
|
@@ -937,11 +1197,11 @@ var Services = class {
|
|
|
937
1197
|
close();
|
|
938
1198
|
return this.okra.invoke("service.stop-logs", { id });
|
|
939
1199
|
});
|
|
940
|
-
|
|
1200
|
+
return new ReadableStream({
|
|
941
1201
|
start: (_controller) => {
|
|
942
1202
|
controller = _controller;
|
|
943
1203
|
disposables.add(
|
|
944
|
-
this.
|
|
1204
|
+
this.okra.listen(`service.log.${id}`, (data) => {
|
|
945
1205
|
controller?.enqueue(data.output);
|
|
946
1206
|
})
|
|
947
1207
|
);
|
|
@@ -955,10 +1215,9 @@ var Services = class {
|
|
|
955
1215
|
});
|
|
956
1216
|
},
|
|
957
1217
|
cancel: () => {
|
|
958
|
-
|
|
1218
|
+
return stop().then(() => void 0);
|
|
959
1219
|
}
|
|
960
1220
|
});
|
|
961
|
-
return { id, output, stop };
|
|
962
1221
|
}
|
|
963
1222
|
};
|
|
964
1223
|
|
|
@@ -3780,878 +4039,152 @@ function mitt_default(n) {
|
|
|
3780
4039
|
}
|
|
3781
4040
|
|
|
3782
4041
|
// src/events/index.ts
|
|
3783
|
-
var createMitt = mitt_default ?? mitt_exports;
|
|
3784
|
-
function mittWithOnce(all) {
|
|
3785
|
-
const inst = createMitt(all);
|
|
3786
|
-
inst.once = (type, fn) => {
|
|
3787
|
-
const onceHandler = (event) => {
|
|
3788
|
-
inst.off(type, onceHandler);
|
|
3789
|
-
fn(event);
|
|
3790
|
-
};
|
|
3791
|
-
inst.on(type, onceHandler);
|
|
3792
|
-
return {
|
|
3793
|
-
dispose: () => {
|
|
3794
|
-
inst.off(type, onceHandler);
|
|
3795
|
-
}
|
|
3796
|
-
};
|
|
3797
|
-
};
|
|
3798
|
-
return inst;
|
|
3799
|
-
}
|
|
3800
|
-
var EventManager = class _EventManager {
|
|
3801
|
-
constructor() {
|
|
3802
|
-
this.emitter = mittWithOnce();
|
|
3803
|
-
}
|
|
3804
|
-
listen(event, callback) {
|
|
3805
|
-
const dispose = () => {
|
|
3806
|
-
this.removeListener(event, callback);
|
|
3807
|
-
};
|
|
3808
|
-
this.emitter.on(event, callback);
|
|
3809
|
-
return { dispose };
|
|
3810
|
-
}
|
|
3811
|
-
emit(event, ...data) {
|
|
3812
|
-
this.emitter.emit(event, data.length > 1 ? data : data[0]);
|
|
3813
|
-
}
|
|
3814
|
-
once(event, callback) {
|
|
3815
|
-
return this.emitter.once(event, callback);
|
|
3816
|
-
}
|
|
3817
|
-
static make() {
|
|
3818
|
-
return new _EventManager();
|
|
3819
|
-
}
|
|
3820
|
-
static refresh() {
|
|
3821
|
-
return new _EventManager();
|
|
3822
|
-
}
|
|
3823
|
-
removeListener(event, callbackSignature) {
|
|
3824
|
-
this.emitter.off(event, callbackSignature);
|
|
3825
|
-
}
|
|
3826
|
-
static createInstance() {
|
|
3827
|
-
return new _EventManager();
|
|
3828
|
-
}
|
|
3829
|
-
inspect() {
|
|
3830
|
-
return this.emitter.all;
|
|
3831
|
-
}
|
|
3832
|
-
};
|
|
3833
|
-
|
|
3834
|
-
// src/git.ts
|
|
3835
|
-
var Git = class {
|
|
3836
|
-
constructor(okra, client) {
|
|
3837
|
-
this.okra = okra;
|
|
3838
|
-
this.client = client;
|
|
3839
|
-
}
|
|
3840
|
-
checkpoint(author, message, branch = "main", allowEmpty = false) {
|
|
3841
|
-
return this.okra.invoke("git.checkpoint", { author, message, branch, allowEmpty });
|
|
3842
|
-
}
|
|
3843
|
-
checkout(branch, create = true) {
|
|
3844
|
-
return this.okra.invoke("git.checkout", { branch, create });
|
|
3845
|
-
}
|
|
3846
|
-
async sync(input) {
|
|
3847
|
-
const response = await this.client.post(
|
|
3848
|
-
`/notebook/${this.okra.data.id}/git/sync-targets`,
|
|
3849
|
-
this.omitUndefined({ ...input })
|
|
3850
|
-
);
|
|
3851
|
-
return response.data;
|
|
3852
|
-
}
|
|
3853
|
-
async syncTargets() {
|
|
3854
|
-
const response = await this.client.get(`/notebook/${this.okra.data.id}/git/sync-targets`);
|
|
3855
|
-
return response.data;
|
|
3856
|
-
}
|
|
3857
|
-
log(ref = "main") {
|
|
3858
|
-
return this.okra.invoke("git.log", { ref });
|
|
3859
|
-
}
|
|
3860
|
-
diff(input) {
|
|
3861
|
-
return this.okra.invoke("git.diff", this.normalizeRemoteInput(input));
|
|
3862
|
-
}
|
|
3863
|
-
merge(input) {
|
|
3864
|
-
return this.okra.invoke("git.merge", this.normalizeRemoteInput(input));
|
|
3865
|
-
}
|
|
3866
|
-
conflicts() {
|
|
3867
|
-
return this.okra.invoke("git.conflicts", {});
|
|
3868
|
-
}
|
|
3869
|
-
abortMerge() {
|
|
3870
|
-
return this.okra.invoke("git.resolve", { action: "abort" });
|
|
3871
|
-
}
|
|
3872
|
-
continueMerge(author, message) {
|
|
3873
|
-
return this.okra.invoke("git.resolve", { action: "continue", author, message });
|
|
3874
|
-
}
|
|
3875
|
-
review() {
|
|
3876
|
-
return this.okra.invoke("git.review", {});
|
|
3877
|
-
}
|
|
3878
|
-
stage(input = { all: true }) {
|
|
3879
|
-
return this.okra.invoke("git.stage", input);
|
|
3880
|
-
}
|
|
3881
|
-
unstage(input = { all: true }) {
|
|
3882
|
-
return this.okra.invoke("git.unstage", input);
|
|
3883
|
-
}
|
|
3884
|
-
revert(input) {
|
|
3885
|
-
return this.okra.invoke("git.revert", input);
|
|
3886
|
-
}
|
|
3887
|
-
credentials() {
|
|
3888
|
-
return this.okra.gitCredentials();
|
|
3889
|
-
}
|
|
3890
|
-
restore(ref) {
|
|
3891
|
-
return this.okra.invoke("git.restore", { ref });
|
|
3892
|
-
}
|
|
3893
|
-
status() {
|
|
3894
|
-
return this.okra.invoke("git.status", {});
|
|
3895
|
-
}
|
|
3896
|
-
normalizeRemoteInput(input) {
|
|
3897
|
-
if (input.notebookId === void 0) {
|
|
3898
|
-
return input;
|
|
3899
|
-
}
|
|
3900
|
-
const notebookId = input.notebookId.trim();
|
|
3901
|
-
if (!notebookId) {
|
|
3902
|
-
throw new Error("'notebookId' cannot be empty.");
|
|
3903
|
-
}
|
|
3904
|
-
if (input.url?.trim()) {
|
|
3905
|
-
throw new Error("Pass either 'url' or 'notebookId', not both.");
|
|
3906
|
-
}
|
|
3907
|
-
if (input.target?.trim()) {
|
|
3908
|
-
throw new Error("Pass either 'target' or 'notebookId', not both.");
|
|
3909
|
-
}
|
|
3910
|
-
const { notebookId: _notebookId, ...payload } = input;
|
|
3911
|
-
return {
|
|
3912
|
-
...payload,
|
|
3913
|
-
url: this.gitUrlForNotebook(notebookId)
|
|
3914
|
-
};
|
|
3915
|
-
}
|
|
3916
|
-
gitUrlForNotebook(notebookId) {
|
|
3917
|
-
const url2 = new URL(this.okra.data.gitUrl);
|
|
3918
|
-
url2.username = "";
|
|
3919
|
-
url2.password = "";
|
|
3920
|
-
url2.pathname = `/${encodeURIComponent(notebookId)}.git`;
|
|
3921
|
-
url2.search = "";
|
|
3922
|
-
url2.hash = "";
|
|
3923
|
-
return url2.toString();
|
|
3924
|
-
}
|
|
3925
|
-
omitUndefined(input) {
|
|
3926
|
-
return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
|
|
3927
|
-
}
|
|
3928
|
-
};
|
|
3929
|
-
|
|
3930
|
-
// src/beacon/navigator.ts
|
|
3931
|
-
var Navigator = class {
|
|
3932
|
-
constructor(onEvent, onceEvent, beacon) {
|
|
3933
|
-
this.onEvent = onEvent;
|
|
3934
|
-
this.onceEvent = onceEvent;
|
|
3935
|
-
this.beacon = beacon;
|
|
3936
|
-
this.urlHistory = [];
|
|
3937
|
-
this.currentIndex = 0;
|
|
3938
|
-
this._canGoBack = false;
|
|
3939
|
-
this._canGoForward = false;
|
|
3940
|
-
this.beacon = beacon;
|
|
3941
|
-
this.setupUrlChangeListener();
|
|
3942
|
-
this.urlHistory.push(beacon.iframe.src);
|
|
3943
|
-
this.updateNavigationState();
|
|
3944
|
-
}
|
|
3945
|
-
/**
|
|
3946
|
-
* Navigate to a URL using internal history management
|
|
3947
|
-
*/
|
|
3948
|
-
visit(url2) {
|
|
3949
|
-
if (!this.beacon) {
|
|
3950
|
-
throw new Error("Beacon reference not set");
|
|
3951
|
-
}
|
|
3952
|
-
this.beacon.navigate(url2);
|
|
3953
|
-
if (this.currentIndex < this.urlHistory.length - 1) {
|
|
3954
|
-
this.urlHistory = this.urlHistory.slice(0, this.currentIndex + 1);
|
|
3955
|
-
}
|
|
3956
|
-
this.urlHistory.push(url2);
|
|
3957
|
-
this.currentIndex = this.urlHistory.length - 1;
|
|
3958
|
-
this.updateNavigationState();
|
|
3959
|
-
this.emitHistoryChange(url2, "push");
|
|
3960
|
-
}
|
|
3961
|
-
/**
|
|
3962
|
-
* Set up listener for URL change events from the beacon
|
|
3963
|
-
*/
|
|
3964
|
-
setupUrlChangeListener() {
|
|
3965
|
-
this.beacon.on("urlChange", (payload) => {
|
|
3966
|
-
this.addToHistory(payload.newUrl);
|
|
3967
|
-
});
|
|
3968
|
-
}
|
|
3969
|
-
/**
|
|
3970
|
-
* Add URL to internal history
|
|
3971
|
-
*/
|
|
3972
|
-
addToHistory(url2) {
|
|
3973
|
-
if (this.currentIndex < this.urlHistory.length - 1) {
|
|
3974
|
-
this.urlHistory = this.urlHistory.slice(0, this.currentIndex + 1);
|
|
3975
|
-
}
|
|
3976
|
-
this.urlHistory.push(url2);
|
|
3977
|
-
this.currentIndex = this.urlHistory.length - 1;
|
|
3978
|
-
this.updateNavigationState();
|
|
3979
|
-
}
|
|
3980
|
-
/**
|
|
3981
|
-
* Update internal navigation state and emit changes
|
|
3982
|
-
*/
|
|
3983
|
-
updateNavigationState() {
|
|
3984
|
-
const previousCanGoBack = this._canGoBack;
|
|
3985
|
-
const previousCanGoForward = this._canGoForward;
|
|
3986
|
-
this._canGoBack = this.currentIndex > 0;
|
|
3987
|
-
this._canGoForward = this.currentIndex < this.urlHistory.length - 1;
|
|
3988
|
-
if (previousCanGoBack !== this._canGoBack || previousCanGoForward !== this._canGoForward) {
|
|
3989
|
-
this.emitNavigationStateChange();
|
|
3990
|
-
}
|
|
3991
|
-
}
|
|
3992
|
-
/**
|
|
3993
|
-
* Emit navigation state change event
|
|
3994
|
-
*/
|
|
3995
|
-
emitNavigationStateChange() {
|
|
3996
|
-
if (this.beacon && this.beacon.emit) {
|
|
3997
|
-
this.beacon.emit("navigationStateChange", {
|
|
3998
|
-
canGoBack: this._canGoBack,
|
|
3999
|
-
canGoForward: this._canGoForward,
|
|
4000
|
-
currentIndex: this.currentIndex,
|
|
4001
|
-
historyLength: this.urlHistory.length,
|
|
4002
|
-
timestamp: Date.now()
|
|
4003
|
-
});
|
|
4004
|
-
}
|
|
4005
|
-
}
|
|
4006
|
-
get canGoBack() {
|
|
4007
|
-
return this._canGoBack;
|
|
4008
|
-
}
|
|
4009
|
-
get canGoForward() {
|
|
4010
|
-
return this._canGoForward;
|
|
4011
|
-
}
|
|
4012
|
-
async goBack() {
|
|
4013
|
-
if (!this.canGoBack) {
|
|
4014
|
-
return { success: false, error: "Cannot go back - no previous history" };
|
|
4015
|
-
}
|
|
4016
|
-
this.currentIndex--;
|
|
4017
|
-
this.updateNavigationState();
|
|
4018
|
-
const url2 = this.urlHistory[this.currentIndex];
|
|
4019
|
-
if (!this.beacon) {
|
|
4020
|
-
return { success: false, error: "Beacon reference not set" };
|
|
4021
|
-
}
|
|
4022
|
-
this.beacon.navigate(url2);
|
|
4023
|
-
this.emitHistoryChange(url2, "back");
|
|
4024
|
-
return { success: true, url: url2 };
|
|
4025
|
-
}
|
|
4026
|
-
/**
|
|
4027
|
-
* Navigate forward in internal history
|
|
4028
|
-
*/
|
|
4029
|
-
async goForward() {
|
|
4030
|
-
if (!this.canGoForward) {
|
|
4031
|
-
return { success: false, error: "Cannot go forward - no forward history" };
|
|
4032
|
-
}
|
|
4033
|
-
this.currentIndex++;
|
|
4034
|
-
this.updateNavigationState();
|
|
4035
|
-
const url2 = this.urlHistory[this.currentIndex];
|
|
4036
|
-
if (!this.beacon) {
|
|
4037
|
-
return { success: false, error: "Beacon reference not set" };
|
|
4038
|
-
}
|
|
4039
|
-
this.beacon.navigate(url2);
|
|
4040
|
-
this.emitHistoryChange(url2, "forward");
|
|
4041
|
-
return { success: true, url: url2 };
|
|
4042
|
-
}
|
|
4043
|
-
/**
|
|
4044
|
-
* Reload the current page
|
|
4045
|
-
*/
|
|
4046
|
-
async reload() {
|
|
4047
|
-
if (this.currentIndex >= 0 && this.currentIndex < this.urlHistory.length) {
|
|
4048
|
-
const currentUrl = this.urlHistory[this.currentIndex];
|
|
4049
|
-
if (!this.beacon) {
|
|
4050
|
-
throw new Error("Beacon reference not set");
|
|
4051
|
-
}
|
|
4052
|
-
this.beacon.navigate(currentUrl);
|
|
4053
|
-
this.emitHistoryChange(currentUrl, "reload");
|
|
4054
|
-
}
|
|
4055
|
-
}
|
|
4056
|
-
/**
|
|
4057
|
-
* Get current URL from internal history
|
|
4058
|
-
*/
|
|
4059
|
-
getCurrentUrl() {
|
|
4060
|
-
if (this.currentIndex >= 0 && this.currentIndex < this.urlHistory.length) {
|
|
4061
|
-
return new URL(this.urlHistory[this.currentIndex]);
|
|
4062
|
-
}
|
|
4063
|
-
return new URL("about:blank");
|
|
4064
|
-
}
|
|
4065
|
-
/**
|
|
4066
|
-
* Get the complete history array
|
|
4067
|
-
*/
|
|
4068
|
-
getHistory() {
|
|
4069
|
-
return [...this.urlHistory];
|
|
4070
|
-
}
|
|
4071
|
-
/**
|
|
4072
|
-
* Get current history index
|
|
4073
|
-
*/
|
|
4074
|
-
getCurrentIndex() {
|
|
4075
|
-
return this.currentIndex;
|
|
4076
|
-
}
|
|
4077
|
-
/**
|
|
4078
|
-
* Check if can go back synchronously
|
|
4079
|
-
*/
|
|
4080
|
-
canGoBackSync() {
|
|
4081
|
-
return this.currentIndex > 0;
|
|
4082
|
-
}
|
|
4083
|
-
/**
|
|
4084
|
-
* Check if can go forward synchronously
|
|
4085
|
-
*/
|
|
4086
|
-
canGoForwardSync() {
|
|
4087
|
-
return this.currentIndex < this.urlHistory.length - 1;
|
|
4088
|
-
}
|
|
4089
|
-
/**
|
|
4090
|
-
* Emit history change event
|
|
4091
|
-
*/
|
|
4092
|
-
emitHistoryChange(url2, direction) {
|
|
4093
|
-
if (this.beacon && this.beacon.emit) {
|
|
4094
|
-
this.beacon.emit("historyChange", {
|
|
4095
|
-
url: url2,
|
|
4096
|
-
state: null,
|
|
4097
|
-
direction,
|
|
4098
|
-
timestamp: Date.now()
|
|
4099
|
-
});
|
|
4100
|
-
}
|
|
4101
|
-
}
|
|
4102
|
-
/**
|
|
4103
|
-
* Push a new state to internal history (legacy method for compatibility)
|
|
4104
|
-
*/
|
|
4105
|
-
async pushState(url2) {
|
|
4106
|
-
this.visit(url2);
|
|
4107
|
-
}
|
|
4108
|
-
/**
|
|
4109
|
-
* Replace current state in internal history (legacy method for compatibility)
|
|
4110
|
-
*/
|
|
4111
|
-
async replaceState(url2) {
|
|
4112
|
-
if (this.currentIndex >= 0 && this.currentIndex < this.urlHistory.length) {
|
|
4113
|
-
this.urlHistory[this.currentIndex] = url2;
|
|
4114
|
-
if (!this.beacon) {
|
|
4115
|
-
throw new Error("Beacon reference not set");
|
|
4116
|
-
}
|
|
4117
|
-
this.beacon.navigate(url2);
|
|
4118
|
-
this.emitHistoryChange(url2, "replace");
|
|
4119
|
-
} else {
|
|
4120
|
-
this.visit(url2);
|
|
4121
|
-
}
|
|
4122
|
-
}
|
|
4123
|
-
/**
|
|
4124
|
-
* Get the current history length
|
|
4125
|
-
*/
|
|
4126
|
-
async getHistoryLength() {
|
|
4127
|
-
return this.urlHistory.length;
|
|
4128
|
-
}
|
|
4129
|
-
/**
|
|
4130
|
-
* Get the current history state (always null since we don't store state)
|
|
4131
|
-
*/
|
|
4132
|
-
async getHistoryState() {
|
|
4133
|
-
return null;
|
|
4134
|
-
}
|
|
4135
|
-
/**
|
|
4136
|
-
* Get comprehensive history information
|
|
4137
|
-
*/
|
|
4138
|
-
async getHistoryInfo() {
|
|
4139
|
-
return {
|
|
4140
|
-
length: this.urlHistory.length,
|
|
4141
|
-
state: null,
|
|
4142
|
-
url: this.urlHistory[this.currentIndex] || "",
|
|
4143
|
-
canGoBack: this.canGoBack,
|
|
4144
|
-
canGoForward: this.canGoForward
|
|
4145
|
-
};
|
|
4146
|
-
}
|
|
4147
|
-
/**
|
|
4148
|
-
* Listen for navigator events
|
|
4149
|
-
*/
|
|
4150
|
-
on(event, handler) {
|
|
4151
|
-
return this.onEvent(event, handler);
|
|
4152
|
-
}
|
|
4153
|
-
/**
|
|
4154
|
-
* Listen for navigator events (once)
|
|
4155
|
-
*/
|
|
4156
|
-
once(event, handler) {
|
|
4157
|
-
this.onceEvent(event, handler);
|
|
4158
|
-
}
|
|
4159
|
-
};
|
|
4160
|
-
|
|
4161
|
-
// src/beacon/index.ts
|
|
4162
|
-
function ensureBrowserEnvironment() {
|
|
4163
|
-
if (typeof window === "undefined") {
|
|
4164
|
-
throw new Error("Beacon SDK can only be used in a browser environment");
|
|
4165
|
-
}
|
|
4166
|
-
}
|
|
4167
|
-
var BeaconError = class extends Error {
|
|
4168
|
-
constructor(message, code) {
|
|
4169
|
-
super(message);
|
|
4170
|
-
this.code = code;
|
|
4171
|
-
this.name = "BeaconError";
|
|
4172
|
-
}
|
|
4173
|
-
};
|
|
4174
|
-
var BeaconTimeoutError = class extends BeaconError {
|
|
4175
|
-
constructor(operation, timeoutMs) {
|
|
4176
|
-
super(`Beacon operation '${operation}' timed out after ${timeoutMs}ms`);
|
|
4177
|
-
this.code = "TIMEOUT";
|
|
4178
|
-
}
|
|
4179
|
-
};
|
|
4180
|
-
var BeaconConnectionError = class extends BeaconError {
|
|
4181
|
-
constructor(message) {
|
|
4182
|
-
super(`Beacon connection error: ${message}`);
|
|
4183
|
-
this.code = "CONNECTION_ERROR";
|
|
4184
|
-
}
|
|
4185
|
-
};
|
|
4186
|
-
var Beacon = class {
|
|
4187
|
-
constructor(iframe, options = {}) {
|
|
4188
|
-
this.messageHandlers = /* @__PURE__ */ new Map();
|
|
4189
|
-
this.isBeaconReady = false;
|
|
4190
|
-
this.readyPromise = null;
|
|
4191
|
-
this.isStarted = false;
|
|
4192
|
-
this.disposables = [];
|
|
4193
|
-
// MessagePort communication
|
|
4194
|
-
this.messageChannel = null;
|
|
4195
|
-
this.port = null;
|
|
4196
|
-
this.channelEstablished = false;
|
|
4197
|
-
ensureBrowserEnvironment();
|
|
4198
|
-
this.iframe = iframe;
|
|
4199
|
-
const defaultRetryOptions = {
|
|
4200
|
-
retries: 3,
|
|
4201
|
-
minTimeout: 1e3,
|
|
4202
|
-
maxTimeout: 5e3,
|
|
4203
|
-
factor: 2,
|
|
4204
|
-
randomize: true
|
|
4205
|
-
};
|
|
4206
|
-
this.options = {
|
|
4207
|
-
timeout: 1e4,
|
|
4208
|
-
targetOrigin: "*",
|
|
4209
|
-
debug: false,
|
|
4210
|
-
retry: {
|
|
4211
|
-
...defaultRetryOptions,
|
|
4212
|
-
...options.retry
|
|
4213
|
-
},
|
|
4214
|
-
...options
|
|
4215
|
-
};
|
|
4216
|
-
this.eventEmitter = EventManager.make();
|
|
4217
|
-
this.setupMessageChannel();
|
|
4218
|
-
this.navigator = new Navigator(
|
|
4219
|
-
this.eventEmitter.listen.bind(this.eventEmitter),
|
|
4220
|
-
this.eventEmitter.once.bind(this.eventEmitter),
|
|
4221
|
-
this
|
|
4222
|
-
);
|
|
4223
|
-
}
|
|
4224
|
-
/**
|
|
4225
|
-
* Setup communication channel using MessagePort
|
|
4226
|
-
*/
|
|
4227
|
-
setupMessageChannel() {
|
|
4228
|
-
const readyHandler = (event) => {
|
|
4229
|
-
try {
|
|
4230
|
-
if (event.source !== this.iframe.contentWindow) {
|
|
4231
|
-
return;
|
|
4232
|
-
}
|
|
4233
|
-
const message = event.data;
|
|
4234
|
-
if (!message || typeof message !== "object" || !message.type) {
|
|
4235
|
-
return;
|
|
4236
|
-
}
|
|
4237
|
-
if (message.type === "beacon:ready-for-channel") {
|
|
4238
|
-
this.establishChannel().catch((error51) => {
|
|
4239
|
-
if (this.options.debug) {
|
|
4240
|
-
console.error("[Beacon SDK] Channel establishment failed:", error51);
|
|
4241
|
-
}
|
|
4242
|
-
});
|
|
4243
|
-
}
|
|
4244
|
-
if (message.type === "beacon:channel-established") {
|
|
4245
|
-
this.channelEstablished = true;
|
|
4246
|
-
this.isBeaconReady = true;
|
|
4247
|
-
this.emit("ready", message.payload);
|
|
4248
|
-
if (this.options.debug) {
|
|
4249
|
-
console.log("[Beacon SDK] Channel established and beacon ready");
|
|
4250
|
-
}
|
|
4251
|
-
}
|
|
4252
|
-
} catch (error51) {
|
|
4253
|
-
if (this.options.debug) {
|
|
4254
|
-
console.error("[Beacon SDK] Message parsing error:", error51);
|
|
4255
|
-
}
|
|
4256
|
-
}
|
|
4257
|
-
};
|
|
4258
|
-
window.addEventListener("message", readyHandler);
|
|
4259
|
-
this.disposables.push({
|
|
4260
|
-
dispose: () => window.removeEventListener("message", readyHandler)
|
|
4261
|
-
});
|
|
4262
|
-
}
|
|
4263
|
-
/**
|
|
4264
|
-
* Establish MessagePort communication channel
|
|
4265
|
-
*/
|
|
4266
|
-
async establishChannel() {
|
|
4267
|
-
if (!this.iframe.contentWindow) {
|
|
4268
|
-
throw new BeaconConnectionError("Iframe contentWindow not available");
|
|
4269
|
-
}
|
|
4270
|
-
this.messageChannel = new MessageChannel();
|
|
4271
|
-
this.port = this.messageChannel.port1;
|
|
4272
|
-
this.port.onmessage = (event) => {
|
|
4273
|
-
this.handleBeaconMessage(event.data);
|
|
4042
|
+
var createMitt = mitt_default ?? mitt_exports;
|
|
4043
|
+
function mittWithOnce(all) {
|
|
4044
|
+
const inst = createMitt(all);
|
|
4045
|
+
inst.once = (type, fn) => {
|
|
4046
|
+
const onceHandler = (event) => {
|
|
4047
|
+
inst.off(type, onceHandler);
|
|
4048
|
+
fn(event);
|
|
4274
4049
|
};
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4050
|
+
inst.on(type, onceHandler);
|
|
4051
|
+
return {
|
|
4052
|
+
dispose: () => {
|
|
4053
|
+
inst.off(type, onceHandler);
|
|
4278
4054
|
}
|
|
4279
4055
|
};
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
this.iframe.contentWindow.postMessage(
|
|
4287
|
-
establishMessage,
|
|
4288
|
-
"*",
|
|
4289
|
-
// Safe for channel establishment
|
|
4290
|
-
[this.messageChannel.port2]
|
|
4291
|
-
// Transfer the port
|
|
4292
|
-
);
|
|
4293
|
-
if (this.options.debug) {
|
|
4294
|
-
console.log("[Beacon SDK] Channel establishment message sent");
|
|
4295
|
-
}
|
|
4296
|
-
return new Promise((resolve, reject) => {
|
|
4297
|
-
const timeoutId = setTimeout(() => {
|
|
4298
|
-
reject(new BeaconConnectionError("Channel establishment timeout"));
|
|
4299
|
-
}, this.options.timeout);
|
|
4300
|
-
const checkReady = () => {
|
|
4301
|
-
if (this.channelEstablished && this.isBeaconReady) {
|
|
4302
|
-
clearTimeout(timeoutId);
|
|
4303
|
-
resolve();
|
|
4304
|
-
} else {
|
|
4305
|
-
setTimeout(checkReady, 100);
|
|
4306
|
-
}
|
|
4307
|
-
};
|
|
4308
|
-
checkReady();
|
|
4309
|
-
});
|
|
4056
|
+
};
|
|
4057
|
+
return inst;
|
|
4058
|
+
}
|
|
4059
|
+
var EventManager = class _EventManager {
|
|
4060
|
+
constructor() {
|
|
4061
|
+
this.emitter = mittWithOnce();
|
|
4310
4062
|
}
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
}
|
|
4318
|
-
const eventType = message.type.replace("beacon:", "");
|
|
4319
|
-
this.emit(eventType, message.payload);
|
|
4320
|
-
const handlers = this.messageHandlers.get(message.type);
|
|
4321
|
-
if (handlers) {
|
|
4322
|
-
handlers.forEach((handler) => {
|
|
4323
|
-
try {
|
|
4324
|
-
handler(message.payload);
|
|
4325
|
-
} catch (error51) {
|
|
4326
|
-
if (this.options.debug) {
|
|
4327
|
-
console.error("[Beacon SDK] Message handler error:", error51);
|
|
4328
|
-
}
|
|
4329
|
-
}
|
|
4330
|
-
});
|
|
4331
|
-
}
|
|
4063
|
+
listen(event, callback) {
|
|
4064
|
+
const dispose = () => {
|
|
4065
|
+
this.removeListener(event, callback);
|
|
4066
|
+
};
|
|
4067
|
+
this.emitter.on(event, callback);
|
|
4068
|
+
return { dispose };
|
|
4332
4069
|
}
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
*/
|
|
4336
|
-
waitForBeaconReady() {
|
|
4337
|
-
return retry(
|
|
4338
|
-
async () => {
|
|
4339
|
-
return new Promise((resolve, reject) => {
|
|
4340
|
-
if (this.isBeaconReady && this.channelEstablished) {
|
|
4341
|
-
resolve();
|
|
4342
|
-
return;
|
|
4343
|
-
}
|
|
4344
|
-
const timeoutMs = this.options.timeout;
|
|
4345
|
-
const timeoutId = setTimeout(() => {
|
|
4346
|
-
reject(new BeaconTimeoutError("beacon ready", timeoutMs));
|
|
4347
|
-
}, timeoutMs);
|
|
4348
|
-
const unsubscribe = this.on("ready", () => {
|
|
4349
|
-
clearTimeout(timeoutId);
|
|
4350
|
-
unsubscribe.dispose();
|
|
4351
|
-
resolve();
|
|
4352
|
-
});
|
|
4353
|
-
});
|
|
4354
|
-
},
|
|
4355
|
-
{
|
|
4356
|
-
retries: this.options.retry?.retries ?? 3,
|
|
4357
|
-
minTimeout: this.options.retry?.minTimeout ?? 1e3,
|
|
4358
|
-
maxTimeout: this.options.retry?.maxTimeout ?? 5e3,
|
|
4359
|
-
factor: this.options.retry?.factor ?? 2,
|
|
4360
|
-
randomize: this.options.retry?.randomize ?? true,
|
|
4361
|
-
onRetry: (error51, attempt) => {
|
|
4362
|
-
if (this.options.debug) {
|
|
4363
|
-
const errorMessage = error51 instanceof Error ? error51.message : String(error51);
|
|
4364
|
-
console.warn(`[Beacon SDK] Beacon ready retry attempt ${attempt}:`, errorMessage);
|
|
4365
|
-
}
|
|
4366
|
-
this.isBeaconReady = false;
|
|
4367
|
-
this.channelEstablished = false;
|
|
4368
|
-
}
|
|
4369
|
-
}
|
|
4370
|
-
);
|
|
4070
|
+
emit(event, ...data) {
|
|
4071
|
+
this.emitter.emit(event, data.length > 1 ? data : data[0]);
|
|
4371
4072
|
}
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
*/
|
|
4375
|
-
sendMessage(type, payload = {}) {
|
|
4376
|
-
if (!this.port) {
|
|
4377
|
-
throw new BeaconConnectionError("MessagePort not available - channel not established");
|
|
4378
|
-
}
|
|
4379
|
-
const message = {
|
|
4380
|
-
type: `beacon:${type}`,
|
|
4381
|
-
payload,
|
|
4382
|
-
timestamp: Date.now(),
|
|
4383
|
-
source: "parent",
|
|
4384
|
-
id: this.generateId()
|
|
4385
|
-
};
|
|
4386
|
-
try {
|
|
4387
|
-
this.port.postMessage(message);
|
|
4388
|
-
if (this.options.debug) {
|
|
4389
|
-
console.log("[Beacon SDK] Sent message via port:", message.type, message.payload);
|
|
4390
|
-
}
|
|
4391
|
-
} catch (error51) {
|
|
4392
|
-
throw new BeaconConnectionError(
|
|
4393
|
-
`Failed to send message via port: ${error51 instanceof Error ? error51.message : String(error51)}`
|
|
4394
|
-
);
|
|
4395
|
-
}
|
|
4073
|
+
once(event, callback) {
|
|
4074
|
+
return this.emitter.once(event, callback);
|
|
4396
4075
|
}
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
*/
|
|
4400
|
-
async sendAndWaitFor(sendType, responseType, payload = {}, timeoutMs) {
|
|
4401
|
-
await this.ready();
|
|
4402
|
-
return retry(
|
|
4403
|
-
async (bail) => {
|
|
4404
|
-
return new Promise((resolve, reject) => {
|
|
4405
|
-
const actualTimeout = timeoutMs || this.options.timeout;
|
|
4406
|
-
const timeoutId = setTimeout(() => {
|
|
4407
|
-
unsubscribe.dispose();
|
|
4408
|
-
const error51 = new BeaconTimeoutError(sendType, actualTimeout);
|
|
4409
|
-
reject(error51);
|
|
4410
|
-
}, actualTimeout);
|
|
4411
|
-
const unsubscribe = this.eventEmitter.listen(responseType, (data) => {
|
|
4412
|
-
clearTimeout(timeoutId);
|
|
4413
|
-
unsubscribe.dispose();
|
|
4414
|
-
resolve(data);
|
|
4415
|
-
});
|
|
4416
|
-
try {
|
|
4417
|
-
this.sendMessage(sendType, payload);
|
|
4418
|
-
} catch (error51) {
|
|
4419
|
-
clearTimeout(timeoutId);
|
|
4420
|
-
unsubscribe.dispose();
|
|
4421
|
-
if (error51 instanceof BeaconConnectionError) {
|
|
4422
|
-
reject(error51);
|
|
4423
|
-
} else {
|
|
4424
|
-
bail(error51);
|
|
4425
|
-
}
|
|
4426
|
-
}
|
|
4427
|
-
});
|
|
4428
|
-
},
|
|
4429
|
-
{
|
|
4430
|
-
retries: this.options.retry?.retries ?? 3,
|
|
4431
|
-
minTimeout: this.options.retry?.minTimeout ?? 1e3,
|
|
4432
|
-
maxTimeout: this.options.retry?.maxTimeout ?? 5e3,
|
|
4433
|
-
factor: this.options.retry?.factor ?? 2,
|
|
4434
|
-
randomize: this.options.retry?.randomize ?? true,
|
|
4435
|
-
onRetry: (error51, attempt) => {
|
|
4436
|
-
if (this.options.debug) {
|
|
4437
|
-
const errorMessage = error51 instanceof Error ? error51.message : String(error51);
|
|
4438
|
-
console.warn(`[Beacon SDK] Retry attempt ${attempt} for ${sendType}:`, errorMessage);
|
|
4439
|
-
}
|
|
4440
|
-
}
|
|
4441
|
-
}
|
|
4442
|
-
);
|
|
4076
|
+
static make() {
|
|
4077
|
+
return new _EventManager();
|
|
4443
4078
|
}
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
*/
|
|
4447
|
-
generateId() {
|
|
4448
|
-
return `sdk_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
4079
|
+
static refresh() {
|
|
4080
|
+
return new _EventManager();
|
|
4449
4081
|
}
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
*/
|
|
4453
|
-
emit(event, payload) {
|
|
4454
|
-
this.eventEmitter.emit(event, payload);
|
|
4082
|
+
removeListener(event, callbackSignature) {
|
|
4083
|
+
this.emitter.off(event, callbackSignature);
|
|
4455
4084
|
}
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
*/
|
|
4459
|
-
start() {
|
|
4460
|
-
if (this.isStarted) {
|
|
4461
|
-
return this.readyPromise || Promise.resolve();
|
|
4462
|
-
}
|
|
4463
|
-
this.isStarted = true;
|
|
4464
|
-
this.readyPromise = this.waitForBeaconReady();
|
|
4465
|
-
return this.readyPromise;
|
|
4085
|
+
static createInstance() {
|
|
4086
|
+
return new _EventManager();
|
|
4466
4087
|
}
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
*/
|
|
4470
|
-
async ready() {
|
|
4471
|
-
if (!this.isStarted) {
|
|
4472
|
-
throw new BeaconError("Beacon has not been started. Call start() first.");
|
|
4473
|
-
}
|
|
4474
|
-
if (!this.readyPromise) {
|
|
4475
|
-
throw new BeaconError("Beacon ready promise is not available");
|
|
4476
|
-
}
|
|
4477
|
-
return timeout(this.readyPromise, this.options.timeout);
|
|
4088
|
+
inspect() {
|
|
4089
|
+
return this.emitter.all;
|
|
4478
4090
|
}
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4091
|
+
};
|
|
4092
|
+
|
|
4093
|
+
// src/git.ts
|
|
4094
|
+
var Git = class {
|
|
4095
|
+
constructor(okra, client) {
|
|
4096
|
+
this.okra = okra;
|
|
4097
|
+
this.client = client;
|
|
4484
4098
|
}
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
*/
|
|
4488
|
-
on(event, handler) {
|
|
4489
|
-
return this.eventEmitter.listen(event, handler);
|
|
4099
|
+
checkpoint(author, message, branch = "main", allowEmpty = false) {
|
|
4100
|
+
return this.okra.invoke("git.checkpoint", { author, message, branch, allowEmpty });
|
|
4490
4101
|
}
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
*/
|
|
4494
|
-
once(event, handler) {
|
|
4495
|
-
return this.eventEmitter.once(event, handler);
|
|
4102
|
+
checkout(branch, create = true) {
|
|
4103
|
+
return this.okra.invoke("git.checkout", { branch, create });
|
|
4496
4104
|
}
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
return true;
|
|
4504
|
-
} catch (error51) {
|
|
4505
|
-
if (this.options.debug) {
|
|
4506
|
-
console.warn("[Beacon SDK] Ping failed:", error51);
|
|
4507
|
-
}
|
|
4508
|
-
return false;
|
|
4509
|
-
}
|
|
4105
|
+
async sync(input) {
|
|
4106
|
+
const response = await this.client.post(
|
|
4107
|
+
`/notebook/${this.okra.data.id}/git/sync-targets`,
|
|
4108
|
+
this.omitUndefined({ ...input })
|
|
4109
|
+
);
|
|
4110
|
+
return response.data;
|
|
4510
4111
|
}
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
async getDebugInfo() {
|
|
4515
|
-
return this.sendAndWaitFor("getDebugInfo", "debugInfo");
|
|
4112
|
+
async syncTargets() {
|
|
4113
|
+
const response = await this.client.get(`/notebook/${this.okra.data.id}/git/sync-targets`);
|
|
4114
|
+
return response.data;
|
|
4516
4115
|
}
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
*/
|
|
4520
|
-
async getConsoleEvents() {
|
|
4521
|
-
return this.sendAndWaitFor("getConsoleEvents", "consoleEvents");
|
|
4116
|
+
log(ref = "main") {
|
|
4117
|
+
return this.okra.invoke("git.log", { ref });
|
|
4522
4118
|
}
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
*/
|
|
4526
|
-
async getErrorEvents() {
|
|
4527
|
-
return this.sendAndWaitFor("getErrorEvents", "errorEvents");
|
|
4119
|
+
diff(input) {
|
|
4120
|
+
return this.okra.invoke("git.diff", this.normalizeRemoteInput(input));
|
|
4528
4121
|
}
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
*/
|
|
4532
|
-
async clearConsole() {
|
|
4533
|
-
await this.ready();
|
|
4534
|
-
this.sendMessage("clearConsole");
|
|
4122
|
+
merge(input) {
|
|
4123
|
+
return this.okra.invoke("git.merge", this.normalizeRemoteInput(input));
|
|
4535
4124
|
}
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
*/
|
|
4539
|
-
async clearErrors() {
|
|
4540
|
-
await this.ready();
|
|
4541
|
-
this.sendMessage("clearErrors");
|
|
4125
|
+
conflicts() {
|
|
4126
|
+
return this.okra.invoke("git.conflicts", {});
|
|
4542
4127
|
}
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
*/
|
|
4546
|
-
async executeCode(code) {
|
|
4547
|
-
return this.sendAndWaitFor("executeCode", "codeExecutionResult", { code });
|
|
4128
|
+
abortMerge() {
|
|
4129
|
+
return this.okra.invoke("git.resolve", { action: "abort" });
|
|
4548
4130
|
}
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
*/
|
|
4552
|
-
async inspectElement(selector) {
|
|
4553
|
-
return this.sendAndWaitFor("inspectElement", "elementInspectionResult", { selector });
|
|
4131
|
+
continueMerge(author, message) {
|
|
4132
|
+
return this.okra.invoke("git.resolve", { action: "continue", author, message });
|
|
4554
4133
|
}
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
*/
|
|
4558
|
-
async fetch(request) {
|
|
4559
|
-
return this.sendAndWaitFor("fetch", "fetchResult", request);
|
|
4134
|
+
review() {
|
|
4135
|
+
return this.okra.invoke("git.review", {});
|
|
4560
4136
|
}
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
*/
|
|
4564
|
-
async captureScreenshot(request = {}) {
|
|
4565
|
-
const mediaTimeoutMs = request.mediaTimeoutMs ?? request.timeout ?? 3e4;
|
|
4566
|
-
const timeoutMs = request.transportTimeoutMs ?? mediaTimeoutMs + 5e3;
|
|
4567
|
-
return this.sendAndWaitFor("captureScreenshot", "screenshotResult", request, timeoutMs);
|
|
4137
|
+
stage(input = { all: true }) {
|
|
4138
|
+
return this.okra.invoke("git.stage", input);
|
|
4568
4139
|
}
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
* the page fresh in the IFRAME so that we can capture the latest state.
|
|
4572
|
-
*/
|
|
4573
|
-
async debug(request, waitSeconds) {
|
|
4574
|
-
const targetUrl = new URL(request.path, this.iframe.src || window.location.origin).href;
|
|
4575
|
-
if (this.iframe.src !== targetUrl) {
|
|
4576
|
-
this.navigator.visit(targetUrl);
|
|
4577
|
-
await this.ready();
|
|
4578
|
-
}
|
|
4579
|
-
waitSeconds && await this.wait(waitSeconds);
|
|
4580
|
-
const timeoutMs = (request.options?.timeout || 3e4) + 5e3;
|
|
4581
|
-
return this.sendAndWaitFor("debug", "debugResult", request, timeoutMs);
|
|
4140
|
+
unstage(input = { all: true }) {
|
|
4141
|
+
return this.okra.invoke("git.unstage", input);
|
|
4582
4142
|
}
|
|
4583
|
-
|
|
4584
|
-
return
|
|
4143
|
+
revert(input) {
|
|
4144
|
+
return this.okra.invoke("git.revert", input);
|
|
4585
4145
|
}
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
*/
|
|
4589
|
-
navigate(url2) {
|
|
4590
|
-
if (!this.iframe) {
|
|
4591
|
-
throw new BeaconConnectionError("Iframe not available");
|
|
4592
|
-
}
|
|
4593
|
-
try {
|
|
4594
|
-
const targetUrl = new URL(url2, this.iframe.src || window.location.origin);
|
|
4595
|
-
this.iframe.src = targetUrl.href;
|
|
4596
|
-
this.isBeaconReady = false;
|
|
4597
|
-
this.channelEstablished = false;
|
|
4598
|
-
if (this.port) {
|
|
4599
|
-
this.port.close();
|
|
4600
|
-
this.port = null;
|
|
4601
|
-
}
|
|
4602
|
-
if (this.messageChannel) {
|
|
4603
|
-
this.messageChannel = null;
|
|
4604
|
-
}
|
|
4605
|
-
if (this.isStarted) {
|
|
4606
|
-
this.readyPromise = this.waitForBeaconReady();
|
|
4607
|
-
}
|
|
4608
|
-
} catch (error51) {
|
|
4609
|
-
throw new BeaconConnectionError(`Invalid URL: ${url2}`);
|
|
4610
|
-
}
|
|
4146
|
+
credentials() {
|
|
4147
|
+
return this.okra.gitCredentials();
|
|
4611
4148
|
}
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
*/
|
|
4615
|
-
get url() {
|
|
4616
|
-
return this.iframe.src;
|
|
4149
|
+
restore(ref) {
|
|
4150
|
+
return this.okra.invoke("git.restore", { ref });
|
|
4617
4151
|
}
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
*/
|
|
4621
|
-
get element() {
|
|
4622
|
-
return this.iframe;
|
|
4152
|
+
status() {
|
|
4153
|
+
return this.okra.invoke("git.status", {});
|
|
4623
4154
|
}
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4155
|
+
normalizeRemoteInput(input) {
|
|
4156
|
+
if (input.notebookId === void 0) {
|
|
4157
|
+
return input;
|
|
4158
|
+
}
|
|
4159
|
+
const notebookId = input.notebookId.trim();
|
|
4160
|
+
if (!notebookId) {
|
|
4161
|
+
throw new Error("'notebookId' cannot be empty.");
|
|
4631
4162
|
}
|
|
4632
|
-
if (
|
|
4633
|
-
|
|
4163
|
+
if (input.url?.trim()) {
|
|
4164
|
+
throw new Error("Pass either 'url' or 'notebookId', not both.");
|
|
4634
4165
|
}
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4166
|
+
if (input.target?.trim()) {
|
|
4167
|
+
throw new Error("Pass either 'target' or 'notebookId', not both.");
|
|
4168
|
+
}
|
|
4169
|
+
const { notebookId: _notebookId, ...payload } = input;
|
|
4170
|
+
return {
|
|
4171
|
+
...payload,
|
|
4172
|
+
url: this.gitUrlForNotebook(notebookId)
|
|
4173
|
+
};
|
|
4642
4174
|
}
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
return
|
|
4651
|
-
} catch {
|
|
4652
|
-
return false;
|
|
4175
|
+
gitUrlForNotebook(notebookId) {
|
|
4176
|
+
const url2 = new URL(this.okra.data.gitUrl);
|
|
4177
|
+
url2.username = "";
|
|
4178
|
+
url2.password = "";
|
|
4179
|
+
url2.pathname = `/${encodeURIComponent(notebookId)}.git`;
|
|
4180
|
+
url2.search = "";
|
|
4181
|
+
url2.hash = "";
|
|
4182
|
+
return url2.toString();
|
|
4653
4183
|
}
|
|
4654
|
-
|
|
4184
|
+
omitUndefined(input) {
|
|
4185
|
+
return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
|
|
4186
|
+
}
|
|
4187
|
+
};
|
|
4655
4188
|
|
|
4656
4189
|
// node_modules/zod/v4/classic/external.js
|
|
4657
4190
|
var external_exports = {};
|
|
@@ -19167,13 +18700,13 @@ function date4(params) {
|
|
|
19167
18700
|
// node_modules/zod/v4/classic/external.js
|
|
19168
18701
|
config(en_default());
|
|
19169
18702
|
|
|
19170
|
-
// src/schemas/
|
|
19171
|
-
var
|
|
19172
|
-
"
|
|
19173
|
-
"
|
|
19174
|
-
"
|
|
18703
|
+
// src/schemas/publications.ts
|
|
18704
|
+
var PublicationProviderNameSchema = external_exports.enum([
|
|
18705
|
+
"cloudflare-containers",
|
|
18706
|
+
"ssh-server",
|
|
18707
|
+
"laravel-cloud"
|
|
19175
18708
|
]);
|
|
19176
|
-
var
|
|
18709
|
+
var PublicationStatusSchema = external_exports.enum([
|
|
19177
18710
|
"pending",
|
|
19178
18711
|
"queued",
|
|
19179
18712
|
"building",
|
|
@@ -19185,7 +18718,7 @@ var DeploymentStatusSchema = external_exports.enum([
|
|
|
19185
18718
|
"deleted",
|
|
19186
18719
|
"delete_failed"
|
|
19187
18720
|
]);
|
|
19188
|
-
var
|
|
18721
|
+
var PublicationBuildStatusSchema = external_exports.enum([
|
|
19189
18722
|
"pending",
|
|
19190
18723
|
"queued",
|
|
19191
18724
|
"running",
|
|
@@ -19193,8 +18726,8 @@ var DeploymentBuildStatusSchema = external_exports.enum([
|
|
|
19193
18726
|
"failed",
|
|
19194
18727
|
"cancelled"
|
|
19195
18728
|
]);
|
|
19196
|
-
var
|
|
19197
|
-
var
|
|
18729
|
+
var PublicationReleaseStatusSchema = external_exports.enum(["created", "ready", "deleted"]);
|
|
18730
|
+
var PublicationSizeSchema = external_exports.enum([
|
|
19198
18731
|
"nano",
|
|
19199
18732
|
"small",
|
|
19200
18733
|
"medium",
|
|
@@ -19204,7 +18737,7 @@ var DeploymentSizeSchema = external_exports.enum([
|
|
|
19204
18737
|
"standard-1",
|
|
19205
18738
|
"standard-2"
|
|
19206
18739
|
]);
|
|
19207
|
-
var
|
|
18740
|
+
var PublicationRegionSchema = external_exports.enum([
|
|
19208
18741
|
"ENAM",
|
|
19209
18742
|
"WNAM",
|
|
19210
18743
|
"EEUR",
|
|
@@ -19215,103 +18748,103 @@ var DeploymentRegionSchema = external_exports.enum([
|
|
|
19215
18748
|
"OC",
|
|
19216
18749
|
"AFR"
|
|
19217
18750
|
]);
|
|
19218
|
-
var
|
|
19219
|
-
var
|
|
19220
|
-
var
|
|
19221
|
-
var
|
|
19222
|
-
var
|
|
19223
|
-
var
|
|
18751
|
+
var PublicationJurisdictionSchema = external_exports.enum(["eu", "fedramp"]);
|
|
18752
|
+
var PublicationDomainDnsRecordTypeSchema = external_exports.enum(["CNAME", "ALIAS", "ANAME"]);
|
|
18753
|
+
var PublicationProtectionModeSchema = external_exports.enum(["none", "password"]);
|
|
18754
|
+
var PublicationLogStreamSchema = external_exports.enum(["build", "runtime"]);
|
|
18755
|
+
var PublishStreamLogStreamSchema = external_exports.enum(["build", "publish", "runtime"]);
|
|
18756
|
+
var PublicationEventDataSchema = external_exports.object({
|
|
19224
18757
|
id: external_exports.union([external_exports.number(), external_exports.string()]).optional(),
|
|
19225
18758
|
sequence: external_exports.number(),
|
|
19226
18759
|
type: external_exports.string(),
|
|
19227
18760
|
payload: external_exports.record(external_exports.string(), external_exports.unknown()),
|
|
19228
18761
|
createdAt: external_exports.string().nullable()
|
|
19229
18762
|
}).passthrough();
|
|
19230
|
-
var
|
|
18763
|
+
var PublicationLogChunkDataSchema = external_exports.object({
|
|
19231
18764
|
sequence: external_exports.number(),
|
|
19232
|
-
stream:
|
|
18765
|
+
stream: PublicationLogStreamSchema,
|
|
19233
18766
|
content: external_exports.string(),
|
|
19234
18767
|
createdAt: external_exports.string().nullable()
|
|
19235
18768
|
}).passthrough();
|
|
19236
|
-
var
|
|
18769
|
+
var PublishStreamPhaseSchema = external_exports.object({
|
|
19237
18770
|
name: external_exports.string(),
|
|
19238
18771
|
status: external_exports.enum(["running", "completed", "failed"]).optional(),
|
|
19239
18772
|
data: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
|
|
19240
18773
|
}).strict();
|
|
19241
|
-
var
|
|
19242
|
-
stream:
|
|
18774
|
+
var PublishStreamLogSchema = external_exports.object({
|
|
18775
|
+
stream: PublishStreamLogStreamSchema,
|
|
19243
18776
|
content: external_exports.string()
|
|
19244
18777
|
}).strict();
|
|
19245
|
-
var
|
|
18778
|
+
var PublishStreamResultSchema = external_exports.object({
|
|
19246
18779
|
success: external_exports.boolean(),
|
|
19247
|
-
|
|
18780
|
+
publicationId: external_exports.string(),
|
|
19248
18781
|
buildId: external_exports.string(),
|
|
19249
18782
|
releaseId: external_exports.string(),
|
|
19250
|
-
status:
|
|
18783
|
+
status: PublicationStatusSchema
|
|
19251
18784
|
}).strict();
|
|
19252
|
-
var
|
|
18785
|
+
var PublishStreamPhaseEventSchema = PublishStreamPhaseSchema.extend({
|
|
19253
18786
|
type: external_exports.literal("phase")
|
|
19254
18787
|
}).strict();
|
|
19255
|
-
var
|
|
18788
|
+
var PublishStreamLogEventSchema = PublishStreamLogSchema.extend({
|
|
19256
18789
|
type: external_exports.literal("log")
|
|
19257
18790
|
}).strict();
|
|
19258
|
-
var
|
|
18791
|
+
var PublishStreamResultEventSchema = PublishStreamResultSchema.extend({
|
|
19259
18792
|
type: external_exports.literal("result")
|
|
19260
18793
|
}).strict();
|
|
19261
|
-
var
|
|
19262
|
-
|
|
19263
|
-
|
|
19264
|
-
|
|
18794
|
+
var PublishStreamEventSchema = external_exports.discriminatedUnion("type", [
|
|
18795
|
+
PublishStreamPhaseEventSchema,
|
|
18796
|
+
PublishStreamLogEventSchema,
|
|
18797
|
+
PublishStreamResultEventSchema
|
|
19265
18798
|
]);
|
|
19266
|
-
var
|
|
18799
|
+
var PublishStreamErrorSchema = external_exports.object({
|
|
19267
18800
|
message: external_exports.string().optional()
|
|
19268
18801
|
}).passthrough();
|
|
19269
|
-
var
|
|
19270
|
-
var
|
|
18802
|
+
var PublishStreamSseEventNameSchema = external_exports.enum(["phase", "log", "done", "result", "error"]);
|
|
18803
|
+
var PublishStreamSsePhaseEventSchema = external_exports.object({
|
|
19271
18804
|
event: external_exports.literal("phase"),
|
|
19272
|
-
data:
|
|
18805
|
+
data: PublishStreamPhaseSchema
|
|
19273
18806
|
}).strict();
|
|
19274
|
-
var
|
|
18807
|
+
var PublishStreamSseLogEventSchema = external_exports.object({
|
|
19275
18808
|
event: external_exports.literal("log"),
|
|
19276
|
-
data:
|
|
18809
|
+
data: PublishStreamLogSchema
|
|
19277
18810
|
}).strict();
|
|
19278
|
-
var
|
|
18811
|
+
var PublishStreamSseDoneEventSchema = external_exports.object({
|
|
19279
18812
|
event: external_exports.literal("done"),
|
|
19280
|
-
data:
|
|
18813
|
+
data: PublishStreamResultSchema
|
|
19281
18814
|
}).strict();
|
|
19282
|
-
var
|
|
18815
|
+
var PublishStreamSseResultEventSchema = external_exports.object({
|
|
19283
18816
|
event: external_exports.literal("result"),
|
|
19284
|
-
data:
|
|
18817
|
+
data: PublishStreamResultSchema
|
|
19285
18818
|
}).strict();
|
|
19286
|
-
var
|
|
18819
|
+
var PublishStreamSseErrorEventSchema = external_exports.object({
|
|
19287
18820
|
event: external_exports.literal("error"),
|
|
19288
|
-
data:
|
|
18821
|
+
data: PublishStreamErrorSchema
|
|
19289
18822
|
}).strict();
|
|
19290
|
-
var
|
|
19291
|
-
|
|
19292
|
-
|
|
19293
|
-
|
|
19294
|
-
|
|
19295
|
-
|
|
18823
|
+
var PublishStreamSseEventSchema = external_exports.discriminatedUnion("event", [
|
|
18824
|
+
PublishStreamSsePhaseEventSchema,
|
|
18825
|
+
PublishStreamSseLogEventSchema,
|
|
18826
|
+
PublishStreamSseDoneEventSchema,
|
|
18827
|
+
PublishStreamSseResultEventSchema,
|
|
18828
|
+
PublishStreamSseErrorEventSchema
|
|
19296
18829
|
]).transform((event) => {
|
|
19297
18830
|
if (event.event === "error") {
|
|
19298
|
-
throw new Error(event.data.message ?? "
|
|
18831
|
+
throw new Error(event.data.message ?? "Publish failed");
|
|
19299
18832
|
}
|
|
19300
18833
|
const type = event.event === "done" ? "result" : event.event;
|
|
19301
|
-
return
|
|
18834
|
+
return PublishStreamEventSchema.parse({ type, ...event.data });
|
|
19302
18835
|
});
|
|
19303
18836
|
|
|
19304
|
-
// src/
|
|
19305
|
-
var
|
|
18837
|
+
// src/publications.ts
|
|
18838
|
+
var NotebookPublicationApi = class {
|
|
19306
18839
|
constructor(client) {
|
|
19307
18840
|
this.client = client;
|
|
19308
18841
|
}
|
|
19309
18842
|
async current(notebookId) {
|
|
19310
18843
|
try {
|
|
19311
18844
|
const response = await this.client.get(
|
|
19312
|
-
`/notebook/${notebookId}/
|
|
18845
|
+
`/notebook/${notebookId}/publication`
|
|
19313
18846
|
);
|
|
19314
|
-
return new
|
|
18847
|
+
return new PublicationInstance(response.data, this.client, notebookId);
|
|
19315
18848
|
} catch (error51) {
|
|
19316
18849
|
if (error51 instanceof ApiError && error51.status === 404) {
|
|
19317
18850
|
return null;
|
|
@@ -19321,89 +18854,82 @@ var NotebookDeploymentApi = class {
|
|
|
19321
18854
|
}
|
|
19322
18855
|
async publish(notebookId, input) {
|
|
19323
18856
|
const response = await this.client.post(
|
|
19324
|
-
`/notebook/${notebookId}/
|
|
18857
|
+
`/notebook/${notebookId}/publication`,
|
|
19325
18858
|
input
|
|
19326
18859
|
);
|
|
19327
|
-
const run = new
|
|
18860
|
+
const run = new PublicationRun(new PublicationInstance(response.data, this.client, notebookId), this.client);
|
|
19328
18861
|
run.start();
|
|
19329
18862
|
return run;
|
|
19330
18863
|
}
|
|
19331
|
-
async slugAvailability(id, slug) {
|
|
19332
|
-
const query = new URLSearchParams({ slug }).toString();
|
|
19333
|
-
const response = await this.client.get(
|
|
19334
|
-
`/notebook/${id}/deployment/slug-availability?${query}`
|
|
19335
|
-
);
|
|
19336
|
-
return response.data;
|
|
19337
|
-
}
|
|
19338
18864
|
};
|
|
19339
|
-
var
|
|
18865
|
+
var PublicationApi = class {
|
|
19340
18866
|
constructor(client) {
|
|
19341
18867
|
this.client = client;
|
|
19342
18868
|
}
|
|
19343
18869
|
async get(id) {
|
|
19344
|
-
const response = await this.client.get(`/
|
|
19345
|
-
return new
|
|
18870
|
+
const response = await this.client.get(`/publications/${id}`);
|
|
18871
|
+
return new PublicationInstance(response.data, this.client);
|
|
19346
18872
|
}
|
|
19347
|
-
async
|
|
19348
|
-
await this.client.delete(`/
|
|
18873
|
+
async destroy(id) {
|
|
18874
|
+
await this.client.delete(`/publications/${id}`);
|
|
19349
18875
|
}
|
|
19350
18876
|
async setProtection(id, input) {
|
|
19351
|
-
const response = await this.client.put(`/
|
|
19352
|
-
return new
|
|
18877
|
+
const response = await this.client.put(`/publications/${id}/protection`, input);
|
|
18878
|
+
return new PublicationInstance(response.data, this.client);
|
|
19353
18879
|
}
|
|
19354
18880
|
async protection(id) {
|
|
19355
|
-
const response = await this.client.get(`/
|
|
18881
|
+
const response = await this.client.get(`/publications/${id}/protection`);
|
|
19356
18882
|
return response.data;
|
|
19357
18883
|
}
|
|
19358
18884
|
async createProtectionSession(id) {
|
|
19359
|
-
const response = await this.client.post(`/
|
|
18885
|
+
const response = await this.client.post(`/publications/${id}/protection/session`);
|
|
19360
18886
|
return response.data;
|
|
19361
18887
|
}
|
|
19362
18888
|
async disableProtection(id) {
|
|
19363
|
-
const response = await this.client.delete(`/
|
|
19364
|
-
return new
|
|
18889
|
+
const response = await this.client.delete(`/publications/${id}/protection`);
|
|
18890
|
+
return new PublicationInstance(response.data, this.client);
|
|
19365
18891
|
}
|
|
19366
18892
|
async setFeedback(id, input) {
|
|
19367
|
-
const response = await this.client.put(`/
|
|
19368
|
-
return new
|
|
18893
|
+
const response = await this.client.put(`/publications/${id}/feedback`, input);
|
|
18894
|
+
return new PublicationInstance(response.data, this.client);
|
|
19369
18895
|
}
|
|
19370
18896
|
async listDomains(id) {
|
|
19371
18897
|
const response = await this.client.get(
|
|
19372
|
-
`/
|
|
18898
|
+
`/publications/${id}/domains`
|
|
19373
18899
|
);
|
|
19374
|
-
return
|
|
18900
|
+
return unwrapPublicationDomainCollection(response.data);
|
|
19375
18901
|
}
|
|
19376
18902
|
async createDomain(id, input) {
|
|
19377
|
-
const response = await this.client.post(`/
|
|
18903
|
+
const response = await this.client.post(`/publications/${id}/domains`, input);
|
|
19378
18904
|
return response.data;
|
|
19379
18905
|
}
|
|
19380
18906
|
async refreshDomain(id, domainId) {
|
|
19381
|
-
const response = await this.client.post(`/
|
|
18907
|
+
const response = await this.client.post(`/publications/${id}/domains/${domainId}/refresh`);
|
|
19382
18908
|
return response.data;
|
|
19383
18909
|
}
|
|
19384
18910
|
async deleteDomain(id, domainId) {
|
|
19385
|
-
await this.client.delete(`/
|
|
18911
|
+
await this.client.delete(`/publications/${id}/domains/${domainId}`);
|
|
19386
18912
|
}
|
|
19387
18913
|
async events(id) {
|
|
19388
18914
|
return parseNdjsonStream(
|
|
19389
|
-
await this.client.stream(`/
|
|
19390
|
-
|
|
18915
|
+
await this.client.stream(`/publications/${id}/events/stream`),
|
|
18916
|
+
PublicationEventDataSchema
|
|
19391
18917
|
);
|
|
19392
18918
|
}
|
|
19393
18919
|
async buildLogs(id, buildId) {
|
|
19394
18920
|
return parseNdjsonStream(
|
|
19395
|
-
await this.client.stream(`/
|
|
19396
|
-
|
|
18921
|
+
await this.client.stream(`/publications/${id}/builds/${buildId}/logs/stream`),
|
|
18922
|
+
PublicationLogChunkDataSchema
|
|
19397
18923
|
);
|
|
19398
18924
|
}
|
|
19399
18925
|
async logs(id) {
|
|
19400
18926
|
return parseNdjsonStream(
|
|
19401
|
-
await this.client.stream(`/
|
|
19402
|
-
|
|
18927
|
+
await this.client.stream(`/publications/${id}/logs/stream`),
|
|
18928
|
+
PublicationLogChunkDataSchema
|
|
19403
18929
|
);
|
|
19404
18930
|
}
|
|
19405
18931
|
};
|
|
19406
|
-
var
|
|
18932
|
+
var PublicationRun = class {
|
|
19407
18933
|
constructor(initial, client) {
|
|
19408
18934
|
this.initial = initial;
|
|
19409
18935
|
this.client = client;
|
|
@@ -19433,7 +18959,7 @@ var DeploymentRun = class {
|
|
|
19433
18959
|
this.start();
|
|
19434
18960
|
return this.resultPromise;
|
|
19435
18961
|
}
|
|
19436
|
-
async
|
|
18962
|
+
async publication() {
|
|
19437
18963
|
await this.result();
|
|
19438
18964
|
return this.initial.refresh();
|
|
19439
18965
|
}
|
|
@@ -19443,7 +18969,7 @@ var DeploymentRun = class {
|
|
|
19443
18969
|
}
|
|
19444
18970
|
const eventStreamUrl = this.initial.data.eventStreamUrl;
|
|
19445
18971
|
if (!eventStreamUrl) {
|
|
19446
|
-
throw new Error(`
|
|
18972
|
+
throw new Error(`Publication ${this.initial.data.id} has no eventStreamUrl for SSE streaming`);
|
|
19447
18973
|
}
|
|
19448
18974
|
this.started = true;
|
|
19449
18975
|
this.resultPromise = new Promise((resolve, reject) => {
|
|
@@ -19455,7 +18981,7 @@ var DeploymentRun = class {
|
|
|
19455
18981
|
return this;
|
|
19456
18982
|
}
|
|
19457
18983
|
subscribe() {
|
|
19458
|
-
const queue = new
|
|
18984
|
+
const queue = new AsyncPublishEventQueue();
|
|
19459
18985
|
for (const event of this.bufferedEvents) {
|
|
19460
18986
|
queue.push(event);
|
|
19461
18987
|
}
|
|
@@ -19471,7 +18997,7 @@ var DeploymentRun = class {
|
|
|
19471
18997
|
async consumeStream(eventStreamUrl) {
|
|
19472
18998
|
try {
|
|
19473
18999
|
const stream = await this.client.sse(eventStreamUrl);
|
|
19474
|
-
for await (const event of
|
|
19000
|
+
for await (const event of readPublishStreamEvents(stream)) {
|
|
19475
19001
|
this.publish(event);
|
|
19476
19002
|
if (event.type === "result") {
|
|
19477
19003
|
const { type: _, ...result } = event;
|
|
@@ -19480,7 +19006,7 @@ var DeploymentRun = class {
|
|
|
19480
19006
|
}
|
|
19481
19007
|
}
|
|
19482
19008
|
if (!this.finalResult) {
|
|
19483
|
-
throw new Error("
|
|
19009
|
+
throw new Error("Publish stream ended without result");
|
|
19484
19010
|
}
|
|
19485
19011
|
this.closeSubscribers();
|
|
19486
19012
|
} catch (err) {
|
|
@@ -19510,33 +19036,33 @@ var DeploymentRun = class {
|
|
|
19510
19036
|
this.subscribers.clear();
|
|
19511
19037
|
}
|
|
19512
19038
|
};
|
|
19513
|
-
var
|
|
19039
|
+
var PublicationInstance = class _PublicationInstance {
|
|
19514
19040
|
constructor(data, client, notebookId) {
|
|
19515
19041
|
this.data = data;
|
|
19516
19042
|
this.client = client;
|
|
19517
19043
|
this.notebookId = notebookId;
|
|
19518
19044
|
}
|
|
19519
19045
|
async refresh() {
|
|
19520
|
-
const response = await this.client.get(`/
|
|
19521
|
-
return new
|
|
19046
|
+
const response = await this.client.get(`/publications/${this.data.id}`);
|
|
19047
|
+
return new _PublicationInstance(response.data, this.client, this.notebookId);
|
|
19522
19048
|
}
|
|
19523
19049
|
publish() {
|
|
19524
19050
|
if (!this.notebookId) {
|
|
19525
|
-
return Promise.reject(new Error("
|
|
19051
|
+
return Promise.reject(new Error("Publishing requires a notebook-scoped publication instance."));
|
|
19526
19052
|
}
|
|
19527
|
-
return this.client.notebook.
|
|
19053
|
+
return this.client.notebook.publication.publish(this.notebookId);
|
|
19528
19054
|
}
|
|
19529
|
-
|
|
19530
|
-
return this.client.
|
|
19055
|
+
destroy() {
|
|
19056
|
+
return this.client.publications.destroy(this.data.id);
|
|
19531
19057
|
}
|
|
19532
19058
|
async wait(options = {}) {
|
|
19533
19059
|
const intervalMs = options.intervalMs ?? 1e3;
|
|
19534
19060
|
const timeoutMs = options.timeoutMs ?? 3e5;
|
|
19535
19061
|
const startedAt = Date.now();
|
|
19536
19062
|
let current = this;
|
|
19537
|
-
while (!
|
|
19063
|
+
while (!publicationStatusIsTerminal(current.data.status)) {
|
|
19538
19064
|
if (Date.now() - startedAt > timeoutMs) {
|
|
19539
|
-
throw new Error(`Timed out waiting for
|
|
19065
|
+
throw new Error(`Timed out waiting for publication ${this.data.id}`);
|
|
19540
19066
|
}
|
|
19541
19067
|
await delay(intervalMs);
|
|
19542
19068
|
current = await current.refresh();
|
|
@@ -19544,58 +19070,58 @@ var DeploymentInstance = class _DeploymentInstance {
|
|
|
19544
19070
|
return current;
|
|
19545
19071
|
}
|
|
19546
19072
|
events() {
|
|
19547
|
-
return this.client.
|
|
19073
|
+
return this.client.publications.events(this.data.id);
|
|
19548
19074
|
}
|
|
19549
19075
|
buildLogs(buildId = this.data.latestBuild?.id ?? "") {
|
|
19550
19076
|
if (buildId === "") {
|
|
19551
|
-
return Promise.reject(new Error("
|
|
19077
|
+
return Promise.reject(new Error("Publication has no latest build id"));
|
|
19552
19078
|
}
|
|
19553
|
-
return this.client.
|
|
19079
|
+
return this.client.publications.buildLogs(this.data.id, buildId);
|
|
19554
19080
|
}
|
|
19555
19081
|
logs() {
|
|
19556
|
-
return this.client.
|
|
19082
|
+
return this.client.publications.logs(this.data.id);
|
|
19557
19083
|
}
|
|
19558
19084
|
setProtection(input) {
|
|
19559
|
-
return this.client.
|
|
19085
|
+
return this.client.publications.setProtection(this.data.id, input);
|
|
19560
19086
|
}
|
|
19561
19087
|
protection() {
|
|
19562
|
-
return this.client.
|
|
19088
|
+
return this.client.publications.protection(this.data.id);
|
|
19563
19089
|
}
|
|
19564
19090
|
createProtectionSession() {
|
|
19565
|
-
return this.client.
|
|
19091
|
+
return this.client.publications.createProtectionSession(this.data.id);
|
|
19566
19092
|
}
|
|
19567
19093
|
disableProtection() {
|
|
19568
|
-
return this.client.
|
|
19094
|
+
return this.client.publications.disableProtection(this.data.id);
|
|
19569
19095
|
}
|
|
19570
19096
|
setFeedback(input) {
|
|
19571
|
-
return this.client.
|
|
19097
|
+
return this.client.publications.setFeedback(this.data.id, input);
|
|
19572
19098
|
}
|
|
19573
19099
|
domains() {
|
|
19574
|
-
return this.client.
|
|
19100
|
+
return this.client.publications.listDomains(this.data.id);
|
|
19575
19101
|
}
|
|
19576
19102
|
addDomain(input) {
|
|
19577
|
-
return this.client.
|
|
19103
|
+
return this.client.publications.createDomain(this.data.id, input);
|
|
19578
19104
|
}
|
|
19579
19105
|
refreshDomain(domainId) {
|
|
19580
|
-
return this.client.
|
|
19106
|
+
return this.client.publications.refreshDomain(this.data.id, domainId);
|
|
19581
19107
|
}
|
|
19582
19108
|
deleteDomain(domainId) {
|
|
19583
|
-
return this.client.
|
|
19109
|
+
return this.client.publications.deleteDomain(this.data.id, domainId);
|
|
19584
19110
|
}
|
|
19585
19111
|
};
|
|
19586
|
-
function
|
|
19112
|
+
function publicationStatusIsTerminal(status) {
|
|
19587
19113
|
return ["healthy", "failed", "stopped", "deleted", "delete_failed"].includes(status);
|
|
19588
19114
|
}
|
|
19589
19115
|
function delay(ms) {
|
|
19590
19116
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
19591
19117
|
}
|
|
19592
|
-
function
|
|
19118
|
+
function unwrapPublicationDomainCollection(input) {
|
|
19593
19119
|
if (Array.isArray(input)) {
|
|
19594
19120
|
return input;
|
|
19595
19121
|
}
|
|
19596
19122
|
return Array.isArray(input.data) ? input.data : [];
|
|
19597
19123
|
}
|
|
19598
|
-
var
|
|
19124
|
+
var AsyncPublishEventQueue = class {
|
|
19599
19125
|
constructor() {
|
|
19600
19126
|
this.values = [];
|
|
19601
19127
|
this.pending = [];
|
|
@@ -19657,7 +19183,7 @@ var AsyncDeployEventQueue = class {
|
|
|
19657
19183
|
});
|
|
19658
19184
|
}
|
|
19659
19185
|
};
|
|
19660
|
-
async function*
|
|
19186
|
+
async function* readPublishStreamEvents(stream) {
|
|
19661
19187
|
const reader = parseSSEStream(stream).getReader();
|
|
19662
19188
|
try {
|
|
19663
19189
|
while (true) {
|
|
@@ -19665,7 +19191,7 @@ async function* readDeployStreamEvents(stream) {
|
|
|
19665
19191
|
if (done) {
|
|
19666
19192
|
return;
|
|
19667
19193
|
}
|
|
19668
|
-
const event =
|
|
19194
|
+
const event = parsePublishStreamEvent(value);
|
|
19669
19195
|
if (event) {
|
|
19670
19196
|
yield event;
|
|
19671
19197
|
}
|
|
@@ -19674,11 +19200,11 @@ async function* readDeployStreamEvents(stream) {
|
|
|
19674
19200
|
reader.releaseLock();
|
|
19675
19201
|
}
|
|
19676
19202
|
}
|
|
19677
|
-
function
|
|
19678
|
-
if (!
|
|
19203
|
+
function parsePublishStreamEvent(event) {
|
|
19204
|
+
if (!PublishStreamSseEventNameSchema.safeParse(event.event).success) {
|
|
19679
19205
|
return null;
|
|
19680
19206
|
}
|
|
19681
|
-
return
|
|
19207
|
+
return PublishStreamSseEventSchema.parse(event);
|
|
19682
19208
|
}
|
|
19683
19209
|
function parseSSEStream(input) {
|
|
19684
19210
|
const decoder = new TextDecoder();
|
|
@@ -19819,6 +19345,7 @@ var restActionRoutes = {
|
|
|
19819
19345
|
"container.stop": { method: "POST", path: "/runtime/container/stop" },
|
|
19820
19346
|
"container.set-php": { method: "PUT", path: "/runtime/container/php" },
|
|
19821
19347
|
"container.opened-ports": { method: "GET", path: "/runtime/container/ports" },
|
|
19348
|
+
"container.stats": { method: "GET", path: "/runtime/container/stats" },
|
|
19822
19349
|
"terminal.list": { method: "GET", path: "/runtime/terminals" },
|
|
19823
19350
|
"shell.exec": { method: "POST", path: "/runtime/executions" },
|
|
19824
19351
|
"fs.info": { method: "POST", path: "/runtime/files/info" },
|
|
@@ -19844,10 +19371,6 @@ var restActionRoutes = {
|
|
|
19844
19371
|
"service.logs": { method: "POST", path: "/runtime/services/logs" },
|
|
19845
19372
|
"composer.invoke": { method: "POST", path: "/runtime/composer/executions" },
|
|
19846
19373
|
"composer.packages": { method: "GET", path: "/runtime/composer/packages" },
|
|
19847
|
-
"composer.dump-autoload": {
|
|
19848
|
-
method: "POST",
|
|
19849
|
-
path: "/runtime/composer/autoload"
|
|
19850
|
-
},
|
|
19851
19374
|
"git.checkpoint": { method: "POST", path: "/runtime/git/checkpoints" },
|
|
19852
19375
|
"git.checkout": { method: "POST", path: "/runtime/git/checkouts" },
|
|
19853
19376
|
"git.log": { method: "POST", path: "/runtime/git/log" },
|
|
@@ -20087,11 +19610,11 @@ var NotebookApi = class {
|
|
|
20087
19610
|
this.composerCredentials = new NotebookComposerCredentialApi(client);
|
|
20088
19611
|
this.preview = new NotebookPreviewApi(client);
|
|
20089
19612
|
this.mail = new NotebookMailApi(client);
|
|
20090
|
-
this.
|
|
19613
|
+
this.publication = new NotebookPublicationApi(client);
|
|
20091
19614
|
}
|
|
20092
19615
|
async create(template, input = {}, init = true) {
|
|
20093
19616
|
const response = await this.client.post("/notebook", { template, ...input });
|
|
20094
|
-
const instance = new
|
|
19617
|
+
const instance = new NotebookInstance(response.data, this.client);
|
|
20095
19618
|
if (!init) {
|
|
20096
19619
|
return instance;
|
|
20097
19620
|
}
|
|
@@ -20099,29 +19622,25 @@ var NotebookApi = class {
|
|
|
20099
19622
|
}
|
|
20100
19623
|
async get(id) {
|
|
20101
19624
|
const response = await this.client.get(`/notebook/${id}`);
|
|
20102
|
-
return new
|
|
19625
|
+
return new NotebookInstance(response.data, this.client);
|
|
20103
19626
|
}
|
|
20104
19627
|
async update(id, input = {}) {
|
|
20105
19628
|
const response = await this.client.put(`/notebook/${id}`, input);
|
|
20106
|
-
return new
|
|
19629
|
+
return new NotebookInstance(response.data, this.client);
|
|
20107
19630
|
}
|
|
20108
|
-
async
|
|
19631
|
+
async destroy(id) {
|
|
20109
19632
|
await this.client.delete(`/notebook/${id}`);
|
|
20110
19633
|
}
|
|
20111
19634
|
async fork(id, input = {}) {
|
|
20112
19635
|
const response = await this.client.post(`/notebook/${id}/fork`, input);
|
|
20113
|
-
return new
|
|
19636
|
+
return new NotebookInstance(response.data, this.client);
|
|
20114
19637
|
}
|
|
20115
19638
|
async gitCredentials(id) {
|
|
20116
19639
|
const response = await this.client.post(`/notebook/${id}/git/credentials`);
|
|
20117
19640
|
return response.data;
|
|
20118
19641
|
}
|
|
20119
|
-
async open(id) {
|
|
20120
|
-
const response = await this.client.get(`/notebook/${id}`);
|
|
20121
|
-
return new NotebookInstance2(response.data, this.client);
|
|
20122
|
-
}
|
|
20123
19642
|
openFromData(data) {
|
|
20124
|
-
return this.init(new
|
|
19643
|
+
return this.init(new NotebookInstance(data, this.client));
|
|
20125
19644
|
}
|
|
20126
19645
|
async init(instance) {
|
|
20127
19646
|
await instance.ready();
|
|
@@ -20136,11 +19655,11 @@ function normalizeApiBaseUrl(url2) {
|
|
|
20136
19655
|
baseUrl.hash = "";
|
|
20137
19656
|
return baseUrl.toString();
|
|
20138
19657
|
}
|
|
20139
|
-
var
|
|
19658
|
+
var Client = class {
|
|
20140
19659
|
constructor(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
|
|
20141
19660
|
this.runtimeTransportValue = "realtime";
|
|
20142
19661
|
this.fetch = globalThis.fetch;
|
|
20143
|
-
this.
|
|
19662
|
+
this.publications = new PublicationApi(this);
|
|
20144
19663
|
this.notebook = new NotebookApi(this);
|
|
20145
19664
|
this.servers = new ServerApi(this);
|
|
20146
19665
|
this.options = Object.assign({ startClosed: true }, options);
|
|
@@ -20220,7 +19739,7 @@ var Client2 = class {
|
|
|
20220
19739
|
return { data: body === "" ? void 0 : JSON.parse(body) };
|
|
20221
19740
|
}
|
|
20222
19741
|
};
|
|
20223
|
-
var PHPSandbox = class _PHPSandbox extends
|
|
19742
|
+
var PHPSandbox = class _PHPSandbox extends Client {
|
|
20224
19743
|
static realtime(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
|
|
20225
19744
|
return new _PHPSandbox(token, url2, options);
|
|
20226
19745
|
}
|
|
@@ -20328,7 +19847,7 @@ var NotebookMailApi = class {
|
|
|
20328
19847
|
}
|
|
20329
19848
|
};
|
|
20330
19849
|
var _initPromise, _NotebookInstance_instances, init_fn;
|
|
20331
|
-
var
|
|
19850
|
+
var NotebookInstance = class {
|
|
20332
19851
|
constructor(data, client) {
|
|
20333
19852
|
this.data = data;
|
|
20334
19853
|
this.client = client;
|
|
@@ -20363,18 +19882,20 @@ var NotebookInstance2 = class {
|
|
|
20363
19882
|
this.watchConnection();
|
|
20364
19883
|
__privateSet(this, _initPromise, __privateMethod(this, _NotebookInstance_instances, init_fn).call(this));
|
|
20365
19884
|
}
|
|
20366
|
-
this.
|
|
19885
|
+
this.files = new Filesystem(
|
|
20367
19886
|
this,
|
|
20368
19887
|
this.socket === null ? null : (handler) => this.onDidConnect(handler)
|
|
20369
19888
|
);
|
|
20370
|
-
this.
|
|
19889
|
+
this.terminals = new Terminals(this);
|
|
20371
19890
|
this.auth = new Auth(this);
|
|
20372
19891
|
this.lsp = new Lsp(this);
|
|
20373
19892
|
this.composer = new Composer(this, client);
|
|
20374
|
-
|
|
19893
|
+
const telemetry = new RuntimeTelemetry(this);
|
|
19894
|
+
this.logs = new Logs(this, telemetry);
|
|
19895
|
+
this.metrics = new Metrics(this, telemetry);
|
|
19896
|
+
this.ports = new Ports(this, telemetry);
|
|
20375
19897
|
this.repl = new Repl(this);
|
|
20376
19898
|
this.container = new Container(this);
|
|
20377
|
-
this.laravel = new Laravel(this);
|
|
20378
19899
|
this.shell = new Shell(this);
|
|
20379
19900
|
this.git = new Git(this, client);
|
|
20380
19901
|
this.services = new Services(this);
|
|
@@ -20406,17 +19927,29 @@ var NotebookInstance2 = class {
|
|
|
20406
19927
|
fork(input = {}) {
|
|
20407
19928
|
return this.client.notebook.fork(this.data.id, input);
|
|
20408
19929
|
}
|
|
20409
|
-
|
|
20410
|
-
return this.client.notebook.
|
|
19930
|
+
publication() {
|
|
19931
|
+
return this.client.notebook.publication.current(this.data.id);
|
|
20411
19932
|
}
|
|
20412
19933
|
publish(input) {
|
|
20413
|
-
return this.client.notebook.
|
|
19934
|
+
return this.client.notebook.publication.publish(this.data.id, input);
|
|
19935
|
+
}
|
|
19936
|
+
run(command, argsOrOpts = [], opts) {
|
|
19937
|
+
if (Array.isArray(argsOrOpts)) {
|
|
19938
|
+
return this.shell.run(command, argsOrOpts, opts);
|
|
19939
|
+
}
|
|
19940
|
+
return this.shell.run(command, argsOrOpts);
|
|
19941
|
+
}
|
|
19942
|
+
exec(command, argsOrOpts = [], opts) {
|
|
19943
|
+
if (Array.isArray(argsOrOpts)) {
|
|
19944
|
+
return this.run(command, argsOrOpts, opts).wait();
|
|
19945
|
+
}
|
|
19946
|
+
return this.run(command, argsOrOpts).wait();
|
|
20414
19947
|
}
|
|
20415
19948
|
gitCredentials() {
|
|
20416
19949
|
return this.client.notebook.gitCredentials(this.data.id);
|
|
20417
19950
|
}
|
|
20418
|
-
|
|
20419
|
-
return this.client.notebook.
|
|
19951
|
+
destroy() {
|
|
19952
|
+
return this.client.notebook.destroy(this.data.id).then(() => {
|
|
20420
19953
|
this.socket?.terminate(new NotebookUnavailableError("Notebook has been deleted.", { id: this.data.id }));
|
|
20421
19954
|
});
|
|
20422
19955
|
}
|
|
@@ -20502,9 +20035,6 @@ var NotebookInstance2 = class {
|
|
|
20502
20035
|
const socket = this.realtimeSocket();
|
|
20503
20036
|
socket.onDidConnect(() => {
|
|
20504
20037
|
socket.emit("okra.connected");
|
|
20505
|
-
if (this.client.options.telemetry) {
|
|
20506
|
-
this.container.enableTelemetry(this.client.options.telemetry);
|
|
20507
|
-
}
|
|
20508
20038
|
});
|
|
20509
20039
|
socket.onDidClose(() => {
|
|
20510
20040
|
socket.emit("okra.disconnected");
|
|
@@ -20563,11 +20093,6 @@ var NotebookInstance2 = class {
|
|
|
20563
20093
|
__privateMethod(this, _NotebookInstance_instances, init_fn).call(this);
|
|
20564
20094
|
return this.ready().then(() => this);
|
|
20565
20095
|
}
|
|
20566
|
-
async beacon(iframe, options) {
|
|
20567
|
-
const result = await this.ready();
|
|
20568
|
-
iframe.src = result.data.previewUrl;
|
|
20569
|
-
return createBeacon(iframe, options);
|
|
20570
|
-
}
|
|
20571
20096
|
realtimeSocket() {
|
|
20572
20097
|
if (this.socket === null) {
|
|
20573
20098
|
throw new UnsupportedRuntimeTransportError("This operation requires the realtime transport.");
|
|
@@ -20686,44 +20211,9 @@ function formatQueryString(params) {
|
|
|
20686
20211
|
}
|
|
20687
20212
|
export {
|
|
20688
20213
|
ApiError,
|
|
20689
|
-
|
|
20690
|
-
BeaconConnectionError,
|
|
20691
|
-
BeaconError,
|
|
20692
|
-
BeaconTimeoutError,
|
|
20693
|
-
Client2 as Client,
|
|
20214
|
+
Client,
|
|
20694
20215
|
CommandError,
|
|
20695
20216
|
ComposerCredentials,
|
|
20696
|
-
DeployStreamErrorSchema,
|
|
20697
|
-
DeployStreamEventSchema,
|
|
20698
|
-
DeployStreamLogEventSchema,
|
|
20699
|
-
DeployStreamLogSchema,
|
|
20700
|
-
DeployStreamLogStreamSchema,
|
|
20701
|
-
DeployStreamPhaseEventSchema,
|
|
20702
|
-
DeployStreamPhaseSchema,
|
|
20703
|
-
DeployStreamResultEventSchema,
|
|
20704
|
-
DeployStreamResultSchema,
|
|
20705
|
-
DeployStreamSseDoneEventSchema,
|
|
20706
|
-
DeployStreamSseErrorEventSchema,
|
|
20707
|
-
DeployStreamSseEventNameSchema,
|
|
20708
|
-
DeployStreamSseEventSchema,
|
|
20709
|
-
DeployStreamSseLogEventSchema,
|
|
20710
|
-
DeployStreamSsePhaseEventSchema,
|
|
20711
|
-
DeployStreamSseResultEventSchema,
|
|
20712
|
-
DeploymentApi,
|
|
20713
|
-
DeploymentBuildStatusSchema,
|
|
20714
|
-
DeploymentDomainDnsRecordTypeSchema,
|
|
20715
|
-
DeploymentEventDataSchema,
|
|
20716
|
-
DeploymentInstance,
|
|
20717
|
-
DeploymentJurisdictionSchema,
|
|
20718
|
-
DeploymentLogChunkDataSchema,
|
|
20719
|
-
DeploymentLogStreamSchema,
|
|
20720
|
-
DeploymentProtectionModeSchema,
|
|
20721
|
-
DeploymentRegionSchema,
|
|
20722
|
-
DeploymentReleaseStatusSchema,
|
|
20723
|
-
DeploymentRun,
|
|
20724
|
-
DeploymentSizeSchema,
|
|
20725
|
-
DeploymentStatusSchema,
|
|
20726
|
-
DeploymentTargetProviderSchema,
|
|
20727
20217
|
ErrorEvent,
|
|
20728
20218
|
FileChangeFilter,
|
|
20729
20219
|
FileChangeType,
|
|
@@ -20732,35 +20222,67 @@ export {
|
|
|
20732
20222
|
FilesystemError,
|
|
20733
20223
|
FilesystemErrorType,
|
|
20734
20224
|
LspConnection,
|
|
20735
|
-
Navigator,
|
|
20736
20225
|
NotebookApi,
|
|
20737
20226
|
NotebookComposerCredentialApi,
|
|
20738
|
-
NotebookDeploymentApi,
|
|
20739
20227
|
NotebookInitError,
|
|
20740
|
-
|
|
20228
|
+
NotebookInstance,
|
|
20741
20229
|
NotebookMail,
|
|
20742
20230
|
NotebookMailApi,
|
|
20743
20231
|
NotebookPreview,
|
|
20744
20232
|
NotebookPreviewApi,
|
|
20233
|
+
NotebookPublicationApi,
|
|
20745
20234
|
NotebookSecretApi,
|
|
20746
20235
|
NotebookSecrets,
|
|
20747
20236
|
NotebookState,
|
|
20748
20237
|
NotebookUnavailableError,
|
|
20749
20238
|
PHPSandbox,
|
|
20750
20239
|
PHPSandboxError,
|
|
20240
|
+
ProcessReadable,
|
|
20241
|
+
ProcessResult,
|
|
20751
20242
|
PromiseTimeoutError,
|
|
20243
|
+
PublicationApi,
|
|
20244
|
+
PublicationBuildStatusSchema,
|
|
20245
|
+
PublicationDomainDnsRecordTypeSchema,
|
|
20246
|
+
PublicationEventDataSchema,
|
|
20247
|
+
PublicationInstance,
|
|
20248
|
+
PublicationJurisdictionSchema,
|
|
20249
|
+
PublicationLogChunkDataSchema,
|
|
20250
|
+
PublicationLogStreamSchema,
|
|
20251
|
+
PublicationProtectionModeSchema,
|
|
20252
|
+
PublicationProviderNameSchema,
|
|
20253
|
+
PublicationRegionSchema,
|
|
20254
|
+
PublicationReleaseStatusSchema,
|
|
20255
|
+
PublicationRun,
|
|
20256
|
+
PublicationSizeSchema,
|
|
20257
|
+
PublicationStatusSchema,
|
|
20258
|
+
PublishStreamErrorSchema,
|
|
20259
|
+
PublishStreamEventSchema,
|
|
20260
|
+
PublishStreamLogEventSchema,
|
|
20261
|
+
PublishStreamLogSchema,
|
|
20262
|
+
PublishStreamLogStreamSchema,
|
|
20263
|
+
PublishStreamPhaseEventSchema,
|
|
20264
|
+
PublishStreamPhaseSchema,
|
|
20265
|
+
PublishStreamResultEventSchema,
|
|
20266
|
+
PublishStreamResultSchema,
|
|
20267
|
+
PublishStreamSseDoneEventSchema,
|
|
20268
|
+
PublishStreamSseErrorEventSchema,
|
|
20269
|
+
PublishStreamSseEventNameSchema,
|
|
20270
|
+
PublishStreamSseEventSchema,
|
|
20271
|
+
PublishStreamSseLogEventSchema,
|
|
20272
|
+
PublishStreamSsePhaseEventSchema,
|
|
20273
|
+
PublishStreamSseResultEventSchema,
|
|
20752
20274
|
RateLimitError,
|
|
20275
|
+
RuntimeTelemetry,
|
|
20753
20276
|
SendTimeoutError,
|
|
20754
20277
|
ServerApi,
|
|
20755
20278
|
ServerInstance,
|
|
20756
|
-
|
|
20279
|
+
ShellProcess,
|
|
20757
20280
|
UnsupportedRuntimeTransportError,
|
|
20758
|
-
createBeacon,
|
|
20759
|
-
isBeaconSupported,
|
|
20760
20281
|
notebookBuiltinServices,
|
|
20761
20282
|
notebookKnownServices,
|
|
20762
20283
|
once,
|
|
20763
|
-
timeout
|
|
20284
|
+
timeout,
|
|
20285
|
+
watchRuntimeTelemetry
|
|
20764
20286
|
};
|
|
20765
20287
|
/*! Bundled license information:
|
|
20766
20288
|
|