@phpsandbox/sdk 0.1.1 → 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 +59 -22
- package/dist/browser/phpsandbox-sdk.esm.js +465 -239
- package/dist/browser/phpsandbox-sdk.esm.min.js +24 -24
- package/dist/browser/phpsandbox-sdk.iife.js +465 -239
- package/dist/browser/phpsandbox-sdk.iife.min.js +24 -24
- 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 -18
- package/dist/filesystem.js +148 -63
- package/dist/index.d.ts +18 -9
- package/dist/index.js +21 -8
- 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/runtime/rest.js +1 -4
- package/dist/runtime-telemetry.d.ts +15 -0
- package/dist/runtime-telemetry.js +111 -0
- package/dist/schemas/publications.d.ts +10 -10
- package/dist/services.d.ts +2 -9
- package/dist/services.js +3 -10
- package/dist/shell.d.ts +9 -0
- package/dist/shell.js +4 -4
- package/dist/terminal.d.ts +17 -11
- package/dist/terminal.js +27 -44
- package/docs/api-summary.md +28 -23
- package/docs/cdn-usage.md +2 -2
- package/docs/getting-started.md +13 -13
- package/examples/basic.ts +1 -1
- package/examples/git-merge-smoke.ts +1 -4
- package/examples/laravel-load-test.ts +67 -80
- package/examples/notebook-readonly-smoke.ts +30 -33
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11,12 +11,15 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
11
11
|
};
|
|
12
12
|
var _NotebookInstance_instances, _NotebookInstance_initPromise, _NotebookInstance_init;
|
|
13
13
|
import { Filesystem } from './filesystem.js';
|
|
14
|
-
import
|
|
14
|
+
import Terminals from './terminal.js';
|
|
15
15
|
import Container from './container.js';
|
|
16
16
|
import Auth from './auth.js';
|
|
17
17
|
import Lsp from './lsp.js';
|
|
18
18
|
import Composer from './composer.js';
|
|
19
|
-
import
|
|
19
|
+
import Logs from './log.js';
|
|
20
|
+
import Metrics from './metrics.js';
|
|
21
|
+
import Ports from './ports.js';
|
|
22
|
+
import { RuntimeTelemetry } from './runtime-telemetry.js';
|
|
20
23
|
import Repl from './repl.js';
|
|
21
24
|
import Shell from './shell.js';
|
|
22
25
|
import Services from './services.js';
|
|
@@ -32,6 +35,10 @@ export * from './types.js';
|
|
|
32
35
|
export * from './lsp.js';
|
|
33
36
|
export * from './filesystem.js';
|
|
34
37
|
export * from './container.js';
|
|
38
|
+
export * from './log.js';
|
|
39
|
+
export * from './metrics.js';
|
|
40
|
+
export * from './ports.js';
|
|
41
|
+
export * from './runtime-telemetry.js';
|
|
35
42
|
export * from './shell.js';
|
|
36
43
|
export * from './terminal.js';
|
|
37
44
|
export * from './git.js';
|
|
@@ -367,12 +374,15 @@ export class NotebookInstance {
|
|
|
367
374
|
this.watchConnection();
|
|
368
375
|
__classPrivateFieldSet(this, _NotebookInstance_initPromise, __classPrivateFieldGet(this, _NotebookInstance_instances, "m", _NotebookInstance_init).call(this), "f");
|
|
369
376
|
}
|
|
370
|
-
this.
|
|
371
|
-
this.
|
|
377
|
+
this.files = new Filesystem(this, this.socket === null ? null : (handler) => this.onDidConnect(handler));
|
|
378
|
+
this.terminals = new Terminals(this);
|
|
372
379
|
this.auth = new Auth(this);
|
|
373
380
|
this.lsp = new Lsp(this);
|
|
374
381
|
this.composer = new Composer(this, client);
|
|
375
|
-
|
|
382
|
+
const telemetry = new RuntimeTelemetry(this);
|
|
383
|
+
this.logs = new Logs(this, telemetry);
|
|
384
|
+
this.metrics = new Metrics(this, telemetry);
|
|
385
|
+
this.ports = new Ports(this, telemetry);
|
|
376
386
|
this.repl = new Repl(this);
|
|
377
387
|
this.container = new Container(this);
|
|
378
388
|
this.shell = new Shell(this);
|
|
@@ -421,6 +431,12 @@ export class NotebookInstance {
|
|
|
421
431
|
}
|
|
422
432
|
return this.shell.run(command, argsOrOpts);
|
|
423
433
|
}
|
|
434
|
+
exec(command, argsOrOpts = [], opts) {
|
|
435
|
+
if (Array.isArray(argsOrOpts)) {
|
|
436
|
+
return this.run(command, argsOrOpts, opts).wait();
|
|
437
|
+
}
|
|
438
|
+
return this.run(command, argsOrOpts).wait();
|
|
439
|
+
}
|
|
424
440
|
gitCredentials() {
|
|
425
441
|
return this.client.notebook.gitCredentials(this.data.id);
|
|
426
442
|
}
|
|
@@ -512,9 +528,6 @@ export class NotebookInstance {
|
|
|
512
528
|
const socket = this.realtimeSocket();
|
|
513
529
|
socket.onDidConnect(() => {
|
|
514
530
|
socket.emit('okra.connected');
|
|
515
|
-
if (this.client.options.telemetry) {
|
|
516
|
-
this.container.enableTelemetry(this.client.options.telemetry);
|
|
517
|
-
}
|
|
518
531
|
});
|
|
519
532
|
socket.onDidClose(() => {
|
|
520
533
|
socket.emit('okra.disconnected');
|
package/dist/log.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { NotebookInstance } from './index.js';
|
|
2
|
+
import { RuntimeTelemetry, type RuntimeWatchOptions } from './runtime-telemetry.js';
|
|
2
3
|
export interface LogEvents {
|
|
3
4
|
'notebook.log': string;
|
|
4
5
|
}
|
|
5
6
|
export interface LogActions {
|
|
6
7
|
}
|
|
7
|
-
export
|
|
8
|
+
export interface RuntimeLogEntry {
|
|
9
|
+
timestamp: string;
|
|
10
|
+
source: 'runtime';
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
export default class Logs {
|
|
8
14
|
protected okra: NotebookInstance;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
private readonly telemetry;
|
|
16
|
+
constructor(okra: NotebookInstance, telemetry: RuntimeTelemetry);
|
|
17
|
+
follow(options?: RuntimeWatchOptions): ReadableStream<RuntimeLogEntry>;
|
|
12
18
|
}
|
package/dist/log.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { watchRuntimeTelemetry } from './runtime-telemetry.js';
|
|
2
|
+
export default class Logs {
|
|
3
|
+
constructor(okra, telemetry) {
|
|
3
4
|
this.okra = okra;
|
|
5
|
+
this.telemetry = telemetry;
|
|
4
6
|
}
|
|
5
|
-
|
|
6
|
-
return this.okra.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
follow(options = {}) {
|
|
8
|
+
return watchRuntimeTelemetry(this.okra, this.telemetry, 'logs', 'notebook.log', (message) => ({
|
|
9
|
+
timestamp: new Date().toISOString(),
|
|
10
|
+
source: 'runtime',
|
|
11
|
+
message,
|
|
12
|
+
}), options);
|
|
10
13
|
}
|
|
11
14
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { NotebookInstance } from './index.js';
|
|
2
|
+
import type { ContainerStats } from './container.js';
|
|
3
|
+
import { RuntimeTelemetry, type RuntimeWatchOptions } from './runtime-telemetry.js';
|
|
4
|
+
export default class Metrics {
|
|
5
|
+
private readonly okra;
|
|
6
|
+
private readonly telemetry;
|
|
7
|
+
constructor(okra: NotebookInstance, telemetry: RuntimeTelemetry);
|
|
8
|
+
current(): Promise<ContainerStats | null>;
|
|
9
|
+
watch(options?: RuntimeWatchOptions): ReadableStream<ContainerStats>;
|
|
10
|
+
}
|
package/dist/metrics.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { watchRuntimeTelemetry } from './runtime-telemetry.js';
|
|
2
|
+
export default class Metrics {
|
|
3
|
+
constructor(okra, telemetry) {
|
|
4
|
+
this.okra = okra;
|
|
5
|
+
this.telemetry = telemetry;
|
|
6
|
+
}
|
|
7
|
+
current() {
|
|
8
|
+
return this.okra.invoke('container.stats');
|
|
9
|
+
}
|
|
10
|
+
watch(options = {}) {
|
|
11
|
+
return watchRuntimeTelemetry(this.okra, this.telemetry, 'stats', 'container.stats', (stats) => stats, options);
|
|
12
|
+
}
|
|
13
|
+
}
|
package/dist/ports.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { NotebookInstance } from './index.js';
|
|
2
|
+
import type { PortInfo } from './container.js';
|
|
3
|
+
import { RuntimeTelemetry, type RuntimeWatchOptions } from './runtime-telemetry.js';
|
|
4
|
+
export default class Ports {
|
|
5
|
+
private readonly okra;
|
|
6
|
+
private readonly telemetry;
|
|
7
|
+
constructor(okra: NotebookInstance, telemetry: RuntimeTelemetry);
|
|
8
|
+
list(): Promise<PortInfo[]>;
|
|
9
|
+
watch(options?: RuntimeWatchOptions): ReadableStream<PortInfo[]>;
|
|
10
|
+
}
|
package/dist/ports.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { watchRuntimeTelemetry } from './runtime-telemetry.js';
|
|
2
|
+
export default class Ports {
|
|
3
|
+
constructor(okra, telemetry) {
|
|
4
|
+
this.okra = okra;
|
|
5
|
+
this.telemetry = telemetry;
|
|
6
|
+
}
|
|
7
|
+
list() {
|
|
8
|
+
return this.okra.invoke('container.opened-ports');
|
|
9
|
+
}
|
|
10
|
+
watch(options = {}) {
|
|
11
|
+
return watchRuntimeTelemetry(this.okra, this.telemetry, 'ports', 'container.ports', (ports) => ports, options);
|
|
12
|
+
}
|
|
13
|
+
}
|
package/dist/runtime/rest.js
CHANGED
|
@@ -12,6 +12,7 @@ const restActionRoutes = {
|
|
|
12
12
|
'container.stop': { method: 'POST', path: '/runtime/container/stop' },
|
|
13
13
|
'container.set-php': { method: 'PUT', path: '/runtime/container/php' },
|
|
14
14
|
'container.opened-ports': { method: 'GET', path: '/runtime/container/ports' },
|
|
15
|
+
'container.stats': { method: 'GET', path: '/runtime/container/stats' },
|
|
15
16
|
'terminal.list': { method: 'GET', path: '/runtime/terminals' },
|
|
16
17
|
'shell.exec': { method: 'POST', path: '/runtime/executions' },
|
|
17
18
|
'fs.info': { method: 'POST', path: '/runtime/files/info' },
|
|
@@ -37,10 +38,6 @@ const restActionRoutes = {
|
|
|
37
38
|
'service.logs': { method: 'POST', path: '/runtime/services/logs' },
|
|
38
39
|
'composer.invoke': { method: 'POST', path: '/runtime/composer/executions' },
|
|
39
40
|
'composer.packages': { method: 'GET', path: '/runtime/composer/packages' },
|
|
40
|
-
'composer.dump-autoload': {
|
|
41
|
-
method: 'POST',
|
|
42
|
-
path: '/runtime/composer/autoload',
|
|
43
|
-
},
|
|
44
41
|
'git.checkpoint': { method: 'POST', path: '/runtime/git/checkpoints' },
|
|
45
42
|
'git.checkout': { method: 'POST', path: '/runtime/git/checkouts' },
|
|
46
43
|
'git.log': { method: 'POST', path: '/runtime/git/log' },
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { NotebookInstance } from './index.js';
|
|
2
|
+
export type RuntimeTelemetryFeature = 'stats' | 'logs' | 'ports';
|
|
3
|
+
export interface RuntimeWatchOptions {
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
}
|
|
6
|
+
export declare class RuntimeTelemetry {
|
|
7
|
+
private readonly okra;
|
|
8
|
+
private readonly references;
|
|
9
|
+
private synchronization;
|
|
10
|
+
constructor(okra: NotebookInstance);
|
|
11
|
+
acquire(feature: RuntimeTelemetryFeature): Promise<() => Promise<void>>;
|
|
12
|
+
private removeReference;
|
|
13
|
+
private synchronize;
|
|
14
|
+
}
|
|
15
|
+
export declare function watchRuntimeTelemetry<T>(okra: NotebookInstance, telemetry: RuntimeTelemetry, feature: RuntimeTelemetryFeature, event: 'container.stats' | 'container.ports' | 'notebook.log', transform: (data: any) => T, options?: RuntimeWatchOptions): ReadableStream<T>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
export class RuntimeTelemetry {
|
|
2
|
+
constructor(okra) {
|
|
3
|
+
this.okra = okra;
|
|
4
|
+
this.references = new Map();
|
|
5
|
+
this.synchronization = Promise.resolve();
|
|
6
|
+
if (okra.runtimeTransport === 'realtime') {
|
|
7
|
+
okra.onDidConnect(() => {
|
|
8
|
+
if (this.references.size > 0) {
|
|
9
|
+
void this.synchronize();
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
async acquire(feature) {
|
|
15
|
+
this.references.set(feature, (this.references.get(feature) ?? 0) + 1);
|
|
16
|
+
try {
|
|
17
|
+
await this.synchronize();
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
this.removeReference(feature);
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
let released = false;
|
|
24
|
+
return async () => {
|
|
25
|
+
if (released) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
released = true;
|
|
29
|
+
this.removeReference(feature);
|
|
30
|
+
await this.synchronize();
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
removeReference(feature) {
|
|
34
|
+
const references = this.references.get(feature) ?? 0;
|
|
35
|
+
if (references <= 1) {
|
|
36
|
+
this.references.delete(feature);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.references.set(feature, references - 1);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
synchronize() {
|
|
43
|
+
this.synchronization = this.synchronization.catch(() => { }).then(async () => {
|
|
44
|
+
const features = Array.from(this.references.keys());
|
|
45
|
+
if (features.length === 0) {
|
|
46
|
+
await this.okra.invoke('container.stop-telemetry');
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
await this.okra.invoke('container.stream-telemetry', { features });
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return this.synchronization;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function watchRuntimeTelemetry(okra, telemetry, feature, event, transform, options = {}) {
|
|
56
|
+
let subscription = null;
|
|
57
|
+
let release = null;
|
|
58
|
+
let closed = false;
|
|
59
|
+
let abort = null;
|
|
60
|
+
const stop = async () => {
|
|
61
|
+
if (closed) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
closed = true;
|
|
65
|
+
subscription?.dispose();
|
|
66
|
+
subscription = null;
|
|
67
|
+
if (abort && options.signal) {
|
|
68
|
+
options.signal.removeEventListener('abort', abort);
|
|
69
|
+
}
|
|
70
|
+
abort = null;
|
|
71
|
+
await release?.();
|
|
72
|
+
release = null;
|
|
73
|
+
};
|
|
74
|
+
return new ReadableStream({
|
|
75
|
+
start(controller) {
|
|
76
|
+
subscription = okra.listen(event, (data) => {
|
|
77
|
+
if (!closed) {
|
|
78
|
+
controller.enqueue(transform(data));
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
if (options.signal) {
|
|
82
|
+
abort = () => {
|
|
83
|
+
void stop().finally(() => controller.error(options.signal?.reason ?? new Error('Aborted')));
|
|
84
|
+
};
|
|
85
|
+
if (options.signal.aborted) {
|
|
86
|
+
abort();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
options.signal.addEventListener('abort', abort, { once: true });
|
|
90
|
+
}
|
|
91
|
+
void telemetry.acquire(feature).then(async (releaseTelemetry) => {
|
|
92
|
+
if (closed) {
|
|
93
|
+
await releaseTelemetry();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
release = releaseTelemetry;
|
|
97
|
+
}).catch((error) => {
|
|
98
|
+
if (!closed) {
|
|
99
|
+
closed = true;
|
|
100
|
+
subscription?.dispose();
|
|
101
|
+
if (abort && options.signal) {
|
|
102
|
+
options.signal.removeEventListener('abort', abort);
|
|
103
|
+
}
|
|
104
|
+
abort = null;
|
|
105
|
+
controller.error(error);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
cancel: stop,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
@@ -64,12 +64,12 @@ export declare const PublicationProtectionModeSchema: z.ZodEnum<{
|
|
|
64
64
|
password: "password";
|
|
65
65
|
}>;
|
|
66
66
|
export declare const PublicationLogStreamSchema: z.ZodEnum<{
|
|
67
|
-
build: "build";
|
|
68
67
|
runtime: "runtime";
|
|
68
|
+
build: "build";
|
|
69
69
|
}>;
|
|
70
70
|
export declare const PublishStreamLogStreamSchema: z.ZodEnum<{
|
|
71
|
-
build: "build";
|
|
72
71
|
runtime: "runtime";
|
|
72
|
+
build: "build";
|
|
73
73
|
publish: "publish";
|
|
74
74
|
}>;
|
|
75
75
|
export declare const PublicationEventDataSchema: z.ZodObject<{
|
|
@@ -82,8 +82,8 @@ export declare const PublicationEventDataSchema: z.ZodObject<{
|
|
|
82
82
|
export declare const PublicationLogChunkDataSchema: z.ZodObject<{
|
|
83
83
|
sequence: z.ZodNumber;
|
|
84
84
|
stream: z.ZodEnum<{
|
|
85
|
-
build: "build";
|
|
86
85
|
runtime: "runtime";
|
|
86
|
+
build: "build";
|
|
87
87
|
}>;
|
|
88
88
|
content: z.ZodString;
|
|
89
89
|
createdAt: z.ZodNullable<z.ZodString>;
|
|
@@ -99,8 +99,8 @@ export declare const PublishStreamPhaseSchema: z.ZodObject<{
|
|
|
99
99
|
}, z.core.$strict>;
|
|
100
100
|
export declare const PublishStreamLogSchema: z.ZodObject<{
|
|
101
101
|
stream: z.ZodEnum<{
|
|
102
|
-
build: "build";
|
|
103
102
|
runtime: "runtime";
|
|
103
|
+
build: "build";
|
|
104
104
|
publish: "publish";
|
|
105
105
|
}>;
|
|
106
106
|
content: z.ZodString;
|
|
@@ -135,8 +135,8 @@ export declare const PublishStreamPhaseEventSchema: z.ZodObject<{
|
|
|
135
135
|
}, z.core.$strict>;
|
|
136
136
|
export declare const PublishStreamLogEventSchema: z.ZodObject<{
|
|
137
137
|
stream: z.ZodEnum<{
|
|
138
|
-
build: "build";
|
|
139
138
|
runtime: "runtime";
|
|
139
|
+
build: "build";
|
|
140
140
|
publish: "publish";
|
|
141
141
|
}>;
|
|
142
142
|
content: z.ZodString;
|
|
@@ -172,8 +172,8 @@ export declare const PublishStreamEventSchema: z.ZodDiscriminatedUnion<[z.ZodObj
|
|
|
172
172
|
type: z.ZodLiteral<"phase">;
|
|
173
173
|
}, z.core.$strict>, z.ZodObject<{
|
|
174
174
|
stream: z.ZodEnum<{
|
|
175
|
-
build: "build";
|
|
176
175
|
runtime: "runtime";
|
|
176
|
+
build: "build";
|
|
177
177
|
publish: "publish";
|
|
178
178
|
}>;
|
|
179
179
|
content: z.ZodString;
|
|
@@ -223,8 +223,8 @@ export declare const PublishStreamSseLogEventSchema: z.ZodObject<{
|
|
|
223
223
|
event: z.ZodLiteral<"log">;
|
|
224
224
|
data: z.ZodObject<{
|
|
225
225
|
stream: z.ZodEnum<{
|
|
226
|
-
build: "build";
|
|
227
226
|
runtime: "runtime";
|
|
227
|
+
build: "build";
|
|
228
228
|
publish: "publish";
|
|
229
229
|
}>;
|
|
230
230
|
content: z.ZodString;
|
|
@@ -293,8 +293,8 @@ export declare const PublishStreamSseEventSchema: z.ZodPipe<z.ZodDiscriminatedUn
|
|
|
293
293
|
event: z.ZodLiteral<"log">;
|
|
294
294
|
data: z.ZodObject<{
|
|
295
295
|
stream: z.ZodEnum<{
|
|
296
|
-
build: "build";
|
|
297
296
|
runtime: "runtime";
|
|
297
|
+
build: "build";
|
|
298
298
|
publish: "publish";
|
|
299
299
|
}>;
|
|
300
300
|
content: z.ZodString;
|
|
@@ -350,7 +350,7 @@ export declare const PublishStreamSseEventSchema: z.ZodPipe<z.ZodDiscriminatedUn
|
|
|
350
350
|
status?: "running" | "failed" | "completed";
|
|
351
351
|
data?: Record<string, unknown>;
|
|
352
352
|
} | {
|
|
353
|
-
stream: "
|
|
353
|
+
stream: "runtime" | "build" | "publish";
|
|
354
354
|
content: string;
|
|
355
355
|
type: "log";
|
|
356
356
|
} | {
|
|
@@ -370,7 +370,7 @@ export declare const PublishStreamSseEventSchema: z.ZodPipe<z.ZodDiscriminatedUn
|
|
|
370
370
|
} | {
|
|
371
371
|
event: "log";
|
|
372
372
|
data: {
|
|
373
|
-
stream: "
|
|
373
|
+
stream: "runtime" | "build" | "publish";
|
|
374
374
|
content: string;
|
|
375
375
|
};
|
|
376
376
|
} | {
|
package/dist/services.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Action,
|
|
1
|
+
import { Action, NotebookInstance } from './index.js';
|
|
2
2
|
export type NotebookServiceKind = 'app' | 'web' | 'cache' | 'task';
|
|
3
3
|
export type NotebookServiceSource = 'built_in' | 'setup_task';
|
|
4
4
|
export type NotebookServiceState = 'running' | 'starting' | 'stopping' | 'backoff' | 'exited' | 'fatal' | 'stopped' | 'unknown';
|
|
@@ -64,20 +64,13 @@ export interface ServiceLogOptions {
|
|
|
64
64
|
tail?: number;
|
|
65
65
|
follow?: false;
|
|
66
66
|
}
|
|
67
|
-
export interface ServiceLogStream {
|
|
68
|
-
id: string;
|
|
69
|
-
output: ReadableStream<string>;
|
|
70
|
-
stop(): Promise<boolean>;
|
|
71
|
-
}
|
|
72
67
|
export default class Services {
|
|
73
68
|
protected okra: NotebookInstance;
|
|
74
69
|
constructor(okra: NotebookInstance);
|
|
75
70
|
list(): Promise<NotebookServiceStatus[]>;
|
|
76
71
|
run(name: NotebookServiceName, command?: NotebookServiceCommand): Promise<NotebookServiceStatus>;
|
|
77
72
|
stop(name: NotebookServiceName): Promise<NotebookServiceStatus>;
|
|
78
|
-
|
|
79
|
-
listen<T extends keyof ServiceEvents>(event: T, handler: (data: ServiceEvents[T]) => void): Disposable;
|
|
80
|
-
logs(name: NotebookServiceName, options: ServiceLogStreamOptions): ServiceLogStream;
|
|
73
|
+
logs(name: NotebookServiceName, options: ServiceLogStreamOptions): ReadableStream<string>;
|
|
81
74
|
logs(name: NotebookServiceName, options?: ServiceLogOptions): Promise<string>;
|
|
82
75
|
private followLogs;
|
|
83
76
|
}
|
package/dist/services.js
CHANGED
|
@@ -18,12 +18,6 @@ export default class Services {
|
|
|
18
18
|
stop(name) {
|
|
19
19
|
return this.okra.invoke('service.stop', { name });
|
|
20
20
|
}
|
|
21
|
-
onLog(id, handler) {
|
|
22
|
-
return this.okra.listen(`service.log.${id}`, handler);
|
|
23
|
-
}
|
|
24
|
-
listen(event, handler) {
|
|
25
|
-
return this.okra.listen(event, handler);
|
|
26
|
-
}
|
|
27
21
|
logs(name, options = {}) {
|
|
28
22
|
if (options.follow) {
|
|
29
23
|
return this.followLogs(name, options);
|
|
@@ -80,10 +74,10 @@ export default class Services {
|
|
|
80
74
|
close();
|
|
81
75
|
return this.okra.invoke('service.stop-logs', { id });
|
|
82
76
|
});
|
|
83
|
-
|
|
77
|
+
return new ReadableStream({
|
|
84
78
|
start: (_controller) => {
|
|
85
79
|
controller = _controller;
|
|
86
|
-
disposables.add(this.
|
|
80
|
+
disposables.add(this.okra.listen(`service.log.${id}`, (data) => {
|
|
87
81
|
controller?.enqueue(data.output);
|
|
88
82
|
}));
|
|
89
83
|
void this.okra
|
|
@@ -98,9 +92,8 @@ export default class Services {
|
|
|
98
92
|
});
|
|
99
93
|
},
|
|
100
94
|
cancel: () => {
|
|
101
|
-
|
|
95
|
+
return stop().then(() => undefined);
|
|
102
96
|
},
|
|
103
97
|
});
|
|
104
|
-
return { id, output, stop };
|
|
105
98
|
}
|
|
106
99
|
}
|
package/dist/shell.d.ts
CHANGED
|
@@ -49,6 +49,15 @@ export declare class ProcessResult implements ProcessResultData {
|
|
|
49
49
|
constructor(output: string, stdout: string, stderr: string, exitCode: number);
|
|
50
50
|
throw(): this;
|
|
51
51
|
}
|
|
52
|
+
export declare class ProcessReadable<T> {
|
|
53
|
+
readonly stream: ReadableStream<T>;
|
|
54
|
+
private controller;
|
|
55
|
+
private closed;
|
|
56
|
+
constructor();
|
|
57
|
+
enqueue(value: T): void;
|
|
58
|
+
close(): void;
|
|
59
|
+
fail(error: unknown): void;
|
|
60
|
+
}
|
|
52
61
|
export declare class ShellProcess {
|
|
53
62
|
readonly id: string;
|
|
54
63
|
private readonly okra;
|
package/dist/shell.js
CHANGED
|
@@ -27,7 +27,7 @@ export class ProcessResult {
|
|
|
27
27
|
return this;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
class
|
|
30
|
+
export class ProcessReadable {
|
|
31
31
|
constructor() {
|
|
32
32
|
this.controller = null;
|
|
33
33
|
this.closed = false;
|
|
@@ -67,9 +67,9 @@ export class ShellProcess {
|
|
|
67
67
|
constructor(id, okra, command, opts) {
|
|
68
68
|
this.id = id;
|
|
69
69
|
this.okra = okra;
|
|
70
|
-
const output = new
|
|
71
|
-
const stdout = new
|
|
72
|
-
const stderr = new
|
|
70
|
+
const output = new ProcessReadable();
|
|
71
|
+
const stdout = new ProcessReadable();
|
|
72
|
+
const stderr = new ProcessReadable();
|
|
73
73
|
this.output = output.stream;
|
|
74
74
|
this.stdout = stdout.stream;
|
|
75
75
|
this.stderr = stderr.stream;
|
package/dist/terminal.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Action,
|
|
1
|
+
import { Action, NotebookInstance } from './index.js';
|
|
2
2
|
export interface Task {
|
|
3
3
|
id: string;
|
|
4
4
|
command: string | string[];
|
|
@@ -14,7 +14,7 @@ export interface TerminalCreateInput {
|
|
|
14
14
|
kind: string;
|
|
15
15
|
size: [number, number];
|
|
16
16
|
command?: string | string[];
|
|
17
|
-
env?: Record<string, string>;
|
|
17
|
+
env?: Record<string, string | number | boolean>;
|
|
18
18
|
cwd?: string;
|
|
19
19
|
}
|
|
20
20
|
export interface TerminalSpawnInput {
|
|
@@ -66,7 +66,7 @@ export interface TerminalActions {
|
|
|
66
66
|
}
|
|
67
67
|
export interface SandboxProcess {
|
|
68
68
|
wait(): Promise<number>;
|
|
69
|
-
input: WritableStream<string>;
|
|
69
|
+
input: WritableStream<string | Uint8Array>;
|
|
70
70
|
output: ReadableStream<string>;
|
|
71
71
|
kill(): Promise<boolean>;
|
|
72
72
|
resize(dimensions: {
|
|
@@ -87,21 +87,27 @@ export interface SpawnOptions {
|
|
|
87
87
|
tty?: boolean;
|
|
88
88
|
abortSignal?: AbortSignal;
|
|
89
89
|
}
|
|
90
|
-
export
|
|
90
|
+
export interface TerminalOptions {
|
|
91
|
+
command?: string | string[];
|
|
92
|
+
args?: string[];
|
|
93
|
+
kind?: string;
|
|
94
|
+
size?: [number, number];
|
|
95
|
+
cwd?: string;
|
|
96
|
+
env?: Record<string, string | number | boolean>;
|
|
97
|
+
id?: string;
|
|
98
|
+
osc?: boolean;
|
|
99
|
+
tty?: boolean;
|
|
100
|
+
abortSignal?: AbortSignal;
|
|
101
|
+
}
|
|
102
|
+
export default class Terminals {
|
|
91
103
|
protected okra: NotebookInstance;
|
|
92
104
|
constructor(okra: NotebookInstance);
|
|
93
105
|
list(): Promise<Task[]>;
|
|
94
|
-
create(
|
|
95
|
-
onStarted(handler: (t: Task) => void): Disposable;
|
|
96
|
-
resize(id: string, size: [number, number]): Promise<boolean>;
|
|
97
|
-
onOutput(id: string, handler: (data: TerminalEvents['terminal.output']) => void): Disposable;
|
|
98
|
-
input(id: string, input: string): Promise<boolean>;
|
|
99
|
-
listen<T extends keyof TerminalEvents>(event: T, handler: (data: TerminalEvents[T]) => void): Disposable;
|
|
106
|
+
create(options?: TerminalOptions): Promise<SandboxProcess & Task>;
|
|
100
107
|
attach(id: string, opts?: {
|
|
101
108
|
replayHistory?: boolean;
|
|
102
109
|
abortSignal?: AbortSignal;
|
|
103
110
|
}): Promise<(SandboxProcess & Task) | false>;
|
|
104
|
-
spawn(command: string, args: string[], opts?: SpawnOptions): Promise<SandboxProcess & Task>;
|
|
105
111
|
private processHandle;
|
|
106
112
|
}
|
|
107
113
|
export {};
|