@difizen/libro-kernel 0.1.18 → 0.1.19
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.
|
@@ -5,6 +5,7 @@ import { ServerManager } from '../server/index.js';
|
|
|
5
5
|
import type { KernelId, IKernelConnection, KernelStatus, KernelConnectionOptions, IKernelModel, KernelMeta } from './libro-kernel-protocol.js';
|
|
6
6
|
import { LibroKernelFactory, LibroKernelConnectionFactory } from './libro-kernel-protocol.js';
|
|
7
7
|
import type { LibroKernel } from './libro-kernel.js';
|
|
8
|
+
import type { IKernelOptions } from './restapi.js';
|
|
8
9
|
import { KernelRestAPI } from './restapi.js';
|
|
9
10
|
export declare class LibroKernelManager {
|
|
10
11
|
kernelfactory: LibroKernelFactory;
|
|
@@ -30,6 +31,19 @@ export declare class LibroKernelManager {
|
|
|
30
31
|
* A promise that fulfills when the manager is ready.
|
|
31
32
|
*/
|
|
32
33
|
get ready(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Start a new kernel.
|
|
36
|
+
*
|
|
37
|
+
* @param createOptions - The kernel creation options
|
|
38
|
+
*
|
|
39
|
+
* @param connectOptions - The kernel connection options
|
|
40
|
+
*
|
|
41
|
+
* @returns A promise that resolves with the kernel connection.
|
|
42
|
+
*
|
|
43
|
+
* #### Notes
|
|
44
|
+
* The manager `serverSettings` will be always be used.
|
|
45
|
+
*/
|
|
46
|
+
startNew(createOptions?: IKernelOptions, connectOptions?: Omit<KernelConnectionOptions, 'model' | 'serverSettings'>): Promise<IKernelConnection>;
|
|
33
47
|
/**
|
|
34
48
|
* A signal emitted when the running kernels change.
|
|
35
49
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libro-kernel-manager.d.ts","sourceRoot":"","sources":["../../src/kernel/libro-kernel-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,KAAK,EAAE,KAAK,I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uB,EAAE,OAAO,GAAG,gBAAgB,CAAM,GAC7E,OAAO,CAAC,iBAAiB,CAAC;IAQ7B;;OAEG;IACH,IAAI,cAAc,IAAI,SAAS,CAAC,YAAY,EAAE,CAAC,CAE9C;IAED;;OAEG;IACH,IAAI,iBAAiB,IAAI,SAAS,CAAC,KAAK,CAAC,CAExC;IAED;;;;;;OAMG;IACG,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKzC;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAa5B,eAAe,CAAC,OAAO,EAAE,uBAAuB;IAQhD,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAS3C,WAAW,CAAC,gBAAgB,EAAE,iBAAiB;IAKrD,SAAS,CAAC,WAAW,CAAC,gBAAgB,EAAE,iBAAiB;IAYzD,SAAS,CAAC,gBAAgB,CAAC,MAAM,EAAE,YAAY;IAW/C;;;;;;;;OAQG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAKrC,SAAS,CAAC,wBAAwB,iBAAwB;IAC1D,SAAS,CAAC,qBAAqB,0BAAiC;IAEhE;;OAEG;cACa,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;CA2ChD"}
|
|
@@ -6,6 +6,9 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
6
6
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
7
7
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
8
8
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
9
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
12
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
10
13
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
11
14
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
@@ -61,13 +64,16 @@ export var LibroKernelManager = (_dec = singleton(), _dec2 = inject(LibroKernelF
|
|
|
61
64
|
while (1) switch (_context.prev = _context.next) {
|
|
62
65
|
case 0:
|
|
63
66
|
_context.next = 2;
|
|
64
|
-
return
|
|
67
|
+
return _this.serverManager.ready;
|
|
65
68
|
case 2:
|
|
66
69
|
_context.next = 4;
|
|
67
|
-
return getOrigin(_this._pollModels).
|
|
70
|
+
return getOrigin(_this._pollModels).start();
|
|
68
71
|
case 4:
|
|
72
|
+
_context.next = 6;
|
|
73
|
+
return getOrigin(_this._pollModels).tick;
|
|
74
|
+
case 6:
|
|
69
75
|
_this._isReady = true;
|
|
70
|
-
case
|
|
76
|
+
case 7:
|
|
71
77
|
case "end":
|
|
72
78
|
return _context.stop();
|
|
73
79
|
}
|
|
@@ -114,9 +120,53 @@ export var LibroKernelManager = (_dec = singleton(), _dec2 = inject(LibroKernelF
|
|
|
114
120
|
return this._ready;
|
|
115
121
|
}
|
|
116
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Start a new kernel.
|
|
125
|
+
*
|
|
126
|
+
* @param createOptions - The kernel creation options
|
|
127
|
+
*
|
|
128
|
+
* @param connectOptions - The kernel connection options
|
|
129
|
+
*
|
|
130
|
+
* @returns A promise that resolves with the kernel connection.
|
|
131
|
+
*
|
|
132
|
+
* #### Notes
|
|
133
|
+
* The manager `serverSettings` will be always be used.
|
|
134
|
+
*/
|
|
135
|
+
}, {
|
|
136
|
+
key: "startNew",
|
|
137
|
+
value: (function () {
|
|
138
|
+
var _startNew = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
139
|
+
var createOptions,
|
|
140
|
+
connectOptions,
|
|
141
|
+
model,
|
|
142
|
+
_args2 = arguments;
|
|
143
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
144
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
145
|
+
case 0:
|
|
146
|
+
createOptions = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
|
|
147
|
+
connectOptions = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {};
|
|
148
|
+
_context2.next = 4;
|
|
149
|
+
return this.kernelRestAPI.startNew(createOptions);
|
|
150
|
+
case 4:
|
|
151
|
+
model = _context2.sent;
|
|
152
|
+
return _context2.abrupt("return", this.connectToKernel(_objectSpread(_objectSpread({}, connectOptions), {}, {
|
|
153
|
+
model: model
|
|
154
|
+
})));
|
|
155
|
+
case 6:
|
|
156
|
+
case "end":
|
|
157
|
+
return _context2.stop();
|
|
158
|
+
}
|
|
159
|
+
}, _callee2, this);
|
|
160
|
+
}));
|
|
161
|
+
function startNew() {
|
|
162
|
+
return _startNew.apply(this, arguments);
|
|
163
|
+
}
|
|
164
|
+
return startNew;
|
|
165
|
+
}()
|
|
117
166
|
/**
|
|
118
167
|
* A signal emitted when the running kernels change.
|
|
119
168
|
*/
|
|
169
|
+
)
|
|
120
170
|
}, {
|
|
121
171
|
key: "runningChanged",
|
|
122
172
|
get: function get() {
|
|
@@ -142,20 +192,20 @@ export var LibroKernelManager = (_dec = singleton(), _dec2 = inject(LibroKernelF
|
|
|
142
192
|
}, {
|
|
143
193
|
key: "shutdown",
|
|
144
194
|
value: (function () {
|
|
145
|
-
var _shutdown = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
146
|
-
return _regeneratorRuntime().wrap(function
|
|
147
|
-
while (1) switch (
|
|
195
|
+
var _shutdown = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(id) {
|
|
196
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
197
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
148
198
|
case 0:
|
|
149
|
-
|
|
199
|
+
_context3.next = 2;
|
|
150
200
|
return this.kernelRestAPI.shutdownKernel(id);
|
|
151
201
|
case 2:
|
|
152
|
-
|
|
202
|
+
_context3.next = 4;
|
|
153
203
|
return this.refreshRunning();
|
|
154
204
|
case 4:
|
|
155
205
|
case "end":
|
|
156
|
-
return
|
|
206
|
+
return _context3.stop();
|
|
157
207
|
}
|
|
158
|
-
},
|
|
208
|
+
}, _callee3, this);
|
|
159
209
|
}));
|
|
160
210
|
function shutdown(_x) {
|
|
161
211
|
return _shutdown.apply(this, arguments);
|
|
@@ -169,26 +219,26 @@ export var LibroKernelManager = (_dec = singleton(), _dec2 = inject(LibroKernelF
|
|
|
169
219
|
}, {
|
|
170
220
|
key: "shutdownAll",
|
|
171
221
|
value: (function () {
|
|
172
|
-
var _shutdownAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
222
|
+
var _shutdownAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
173
223
|
var _this2 = this;
|
|
174
|
-
return _regeneratorRuntime().wrap(function
|
|
175
|
-
while (1) switch (
|
|
224
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
225
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
176
226
|
case 0:
|
|
177
|
-
|
|
227
|
+
_context4.next = 2;
|
|
178
228
|
return this.refreshRunning();
|
|
179
229
|
case 2:
|
|
180
|
-
|
|
230
|
+
_context4.next = 4;
|
|
181
231
|
return Promise.all(_toConsumableArray(this._models.keys()).map(function (id) {
|
|
182
232
|
return _this2.kernelRestAPI.shutdownKernel(id);
|
|
183
233
|
}));
|
|
184
234
|
case 4:
|
|
185
|
-
|
|
235
|
+
_context4.next = 6;
|
|
186
236
|
return this.refreshRunning();
|
|
187
237
|
case 6:
|
|
188
238
|
case "end":
|
|
189
|
-
return
|
|
239
|
+
return _context4.stop();
|
|
190
240
|
}
|
|
191
|
-
},
|
|
241
|
+
}, _callee4, this);
|
|
192
242
|
}));
|
|
193
243
|
function shutdownAll() {
|
|
194
244
|
return _shutdownAll.apply(this, arguments);
|
|
@@ -198,20 +248,20 @@ export var LibroKernelManager = (_dec = singleton(), _dec2 = inject(LibroKernelF
|
|
|
198
248
|
}, {
|
|
199
249
|
key: "connectToKernel",
|
|
200
250
|
value: function () {
|
|
201
|
-
var _connectToKernel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
251
|
+
var _connectToKernel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(options) {
|
|
202
252
|
var kernelConnection;
|
|
203
|
-
return _regeneratorRuntime().wrap(function
|
|
204
|
-
while (1) switch (
|
|
253
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
254
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
205
255
|
case 0:
|
|
206
256
|
kernelConnection = this.kernelConnectionFactory(options);
|
|
207
257
|
this.startKernel(kernelConnection);
|
|
208
258
|
this.connectToKernelEmitter.fire(kernelConnection);
|
|
209
|
-
return
|
|
259
|
+
return _context5.abrupt("return", kernelConnection);
|
|
210
260
|
case 4:
|
|
211
261
|
case "end":
|
|
212
|
-
return
|
|
262
|
+
return _context5.stop();
|
|
213
263
|
}
|
|
214
|
-
},
|
|
264
|
+
}, _callee5, this);
|
|
215
265
|
}));
|
|
216
266
|
function connectToKernel(_x2) {
|
|
217
267
|
return _connectToKernel.apply(this, arguments);
|
|
@@ -221,26 +271,26 @@ export var LibroKernelManager = (_dec = singleton(), _dec2 = inject(LibroKernelF
|
|
|
221
271
|
}, {
|
|
222
272
|
key: "isKernelAlive",
|
|
223
273
|
value: function () {
|
|
224
|
-
var _isKernelAlive = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
274
|
+
var _isKernelAlive = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(id) {
|
|
225
275
|
var data;
|
|
226
|
-
return _regeneratorRuntime().wrap(function
|
|
227
|
-
while (1) switch (
|
|
276
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
277
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
228
278
|
case 0:
|
|
229
|
-
|
|
230
|
-
|
|
279
|
+
_context6.prev = 0;
|
|
280
|
+
_context6.next = 3;
|
|
231
281
|
return this.kernelRestAPI.getKernelModel(id);
|
|
232
282
|
case 3:
|
|
233
|
-
data =
|
|
234
|
-
return
|
|
283
|
+
data = _context6.sent;
|
|
284
|
+
return _context6.abrupt("return", !!data);
|
|
235
285
|
case 7:
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return
|
|
286
|
+
_context6.prev = 7;
|
|
287
|
+
_context6.t0 = _context6["catch"](0);
|
|
288
|
+
return _context6.abrupt("return", false);
|
|
239
289
|
case 10:
|
|
240
290
|
case "end":
|
|
241
|
-
return
|
|
291
|
+
return _context6.stop();
|
|
242
292
|
}
|
|
243
|
-
},
|
|
293
|
+
}, _callee6, this, [[0, 7]]);
|
|
244
294
|
}));
|
|
245
295
|
function isKernelAlive(_x3) {
|
|
246
296
|
return _isKernelAlive.apply(this, arguments);
|
|
@@ -250,10 +300,10 @@ export var LibroKernelManager = (_dec = singleton(), _dec2 = inject(LibroKernelF
|
|
|
250
300
|
}, {
|
|
251
301
|
key: "startKernel",
|
|
252
302
|
value: function () {
|
|
253
|
-
var _startKernel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
303
|
+
var _startKernel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(kernelConnection) {
|
|
254
304
|
var _this3 = this;
|
|
255
|
-
return _regeneratorRuntime().wrap(function
|
|
256
|
-
while (1) switch (
|
|
305
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
306
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
257
307
|
case 0:
|
|
258
308
|
kernelConnection.statusChanged(this._onStatusChanged.bind(this));
|
|
259
309
|
kernelConnection.onDisposed(function () {
|
|
@@ -261,9 +311,9 @@ export var LibroKernelManager = (_dec = singleton(), _dec2 = inject(LibroKernelF
|
|
|
261
311
|
});
|
|
262
312
|
case 2:
|
|
263
313
|
case "end":
|
|
264
|
-
return
|
|
314
|
+
return _context7.stop();
|
|
265
315
|
}
|
|
266
|
-
},
|
|
316
|
+
}, _callee7, this);
|
|
267
317
|
}));
|
|
268
318
|
function startKernel(_x4) {
|
|
269
319
|
return _startKernel.apply(this, arguments);
|
|
@@ -308,20 +358,20 @@ export var LibroKernelManager = (_dec = singleton(), _dec2 = inject(LibroKernelF
|
|
|
308
358
|
}, {
|
|
309
359
|
key: "refreshRunning",
|
|
310
360
|
value: (function () {
|
|
311
|
-
var _refreshRunning = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
312
|
-
return _regeneratorRuntime().wrap(function
|
|
313
|
-
while (1) switch (
|
|
361
|
+
var _refreshRunning = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
362
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
363
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
314
364
|
case 0:
|
|
315
|
-
|
|
365
|
+
_context8.next = 2;
|
|
316
366
|
return getOrigin(this._pollModels).refresh();
|
|
317
367
|
case 2:
|
|
318
|
-
|
|
368
|
+
_context8.next = 4;
|
|
319
369
|
return getOrigin(this._pollModels).tick;
|
|
320
370
|
case 4:
|
|
321
371
|
case "end":
|
|
322
|
-
return
|
|
372
|
+
return _context8.stop();
|
|
323
373
|
}
|
|
324
|
-
},
|
|
374
|
+
}, _callee8, this);
|
|
325
375
|
}));
|
|
326
376
|
function refreshRunning() {
|
|
327
377
|
return _refreshRunning.apply(this, arguments);
|
|
@@ -335,29 +385,29 @@ export var LibroKernelManager = (_dec = singleton(), _dec2 = inject(LibroKernelF
|
|
|
335
385
|
* Execute a request to the server to poll running kernels and update state.
|
|
336
386
|
*/
|
|
337
387
|
function () {
|
|
338
|
-
var _requestRunning = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
388
|
+
var _requestRunning = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
339
389
|
var _this4 = this;
|
|
340
390
|
var models, _err$response, _err$response2;
|
|
341
|
-
return _regeneratorRuntime().wrap(function
|
|
342
|
-
while (1) switch (
|
|
391
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
392
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
343
393
|
case 0:
|
|
344
|
-
|
|
345
|
-
|
|
394
|
+
_context9.prev = 0;
|
|
395
|
+
_context9.next = 3;
|
|
346
396
|
return this.kernelRestAPI.listRunning();
|
|
347
397
|
case 3:
|
|
348
|
-
models =
|
|
349
|
-
|
|
398
|
+
models = _context9.sent;
|
|
399
|
+
_context9.next = 10;
|
|
350
400
|
break;
|
|
351
401
|
case 6:
|
|
352
|
-
|
|
353
|
-
|
|
402
|
+
_context9.prev = 6;
|
|
403
|
+
_context9.t0 = _context9["catch"](0);
|
|
354
404
|
// Handle network errors, as well as cases where we are on a
|
|
355
405
|
// JupyterHub and the server is not running. JupyterHub returns a
|
|
356
406
|
// 503 (<2.0) or 424 (>2.0) in that case.
|
|
357
|
-
if (
|
|
358
|
-
this.connectionFailureEmmiter.fire(
|
|
407
|
+
if (_context9.t0 instanceof NetworkError || ((_err$response = _context9.t0.response) === null || _err$response === void 0 ? void 0 : _err$response.status) === 503 || ((_err$response2 = _context9.t0.response) === null || _err$response2 === void 0 ? void 0 : _err$response2.status) === 424) {
|
|
408
|
+
this.connectionFailureEmmiter.fire(_context9.t0);
|
|
359
409
|
}
|
|
360
|
-
throw
|
|
410
|
+
throw _context9.t0;
|
|
361
411
|
case 10:
|
|
362
412
|
if (!(this._models.size === models.length && models.every(function (model) {
|
|
363
413
|
var existing = _this4._models.get(model.id);
|
|
@@ -366,19 +416,19 @@ export var LibroKernelManager = (_dec = singleton(), _dec2 = inject(LibroKernelF
|
|
|
366
416
|
}
|
|
367
417
|
return existing.connections === model.connections && existing.execution_state === model.execution_state && existing.last_activity === model.last_activity && existing.name === model.name && existing.reason === model.reason && existing.traceback === model.traceback;
|
|
368
418
|
}))) {
|
|
369
|
-
|
|
419
|
+
_context9.next = 12;
|
|
370
420
|
break;
|
|
371
421
|
}
|
|
372
|
-
return
|
|
422
|
+
return _context9.abrupt("return");
|
|
373
423
|
case 12:
|
|
374
424
|
this._models = new Map(models.map(function (x) {
|
|
375
425
|
return [x.id, x];
|
|
376
426
|
}));
|
|
377
427
|
case 13:
|
|
378
428
|
case "end":
|
|
379
|
-
return
|
|
429
|
+
return _context9.stop();
|
|
380
430
|
}
|
|
381
|
-
},
|
|
431
|
+
}, _callee9, this, [[0, 6]]);
|
|
382
432
|
}));
|
|
383
433
|
function requestRunning() {
|
|
384
434
|
return _requestRunning.apply(this, arguments);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@difizen/libro-kernel",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-infra",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"src"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@difizen/libro-common": "^0.1.
|
|
36
|
-
"@difizen/libro-core": "^0.1.
|
|
35
|
+
"@difizen/libro-common": "^0.1.19",
|
|
36
|
+
"@difizen/libro-core": "^0.1.19",
|
|
37
37
|
"@difizen/mana-app": "latest",
|
|
38
38
|
"minimist": "^1.2.8",
|
|
39
39
|
"query-string": "^8.1.0",
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
LibroKernelConnectionFactory,
|
|
20
20
|
} from './libro-kernel-protocol.js';
|
|
21
21
|
import type { LibroKernel } from './libro-kernel.js';
|
|
22
|
+
import type { IKernelOptions } from './restapi.js';
|
|
22
23
|
import { KernelRestAPI } from './restapi.js';
|
|
23
24
|
|
|
24
25
|
@singleton()
|
|
@@ -76,6 +77,7 @@ export class LibroKernelManager {
|
|
|
76
77
|
|
|
77
78
|
// Initialize internal data.
|
|
78
79
|
this._ready = (async () => {
|
|
80
|
+
await this.serverManager.ready;
|
|
79
81
|
await getOrigin(this._pollModels).start();
|
|
80
82
|
await getOrigin(this._pollModels).tick;
|
|
81
83
|
this._isReady = true;
|
|
@@ -96,6 +98,29 @@ export class LibroKernelManager {
|
|
|
96
98
|
return this._ready;
|
|
97
99
|
}
|
|
98
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Start a new kernel.
|
|
103
|
+
*
|
|
104
|
+
* @param createOptions - The kernel creation options
|
|
105
|
+
*
|
|
106
|
+
* @param connectOptions - The kernel connection options
|
|
107
|
+
*
|
|
108
|
+
* @returns A promise that resolves with the kernel connection.
|
|
109
|
+
*
|
|
110
|
+
* #### Notes
|
|
111
|
+
* The manager `serverSettings` will be always be used.
|
|
112
|
+
*/
|
|
113
|
+
async startNew(
|
|
114
|
+
createOptions: IKernelOptions = {},
|
|
115
|
+
connectOptions: Omit<KernelConnectionOptions, 'model' | 'serverSettings'> = {},
|
|
116
|
+
): Promise<IKernelConnection> {
|
|
117
|
+
const model = await this.kernelRestAPI.startNew(createOptions);
|
|
118
|
+
return this.connectToKernel({
|
|
119
|
+
...connectOptions,
|
|
120
|
+
model,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
99
124
|
/**
|
|
100
125
|
* A signal emitted when the running kernels change.
|
|
101
126
|
*/
|