@@ -56,12 +56,15 @@ let defaultDevices;
5656let ONNX ;
5757const ORT_SYMBOL = Symbol . for ( 'onnxruntime' ) ;
5858
59+ /** @type {"custom"|"node"|"web" } */
60+ let ort ;
5961if ( ORT_SYMBOL in globalThis ) {
6062 // If the JS runtime exposes their own ONNX runtime, use it
6163 ONNX = globalThis [ ORT_SYMBOL ] ;
64+ ort = 'custom' ;
6265
63- } else if ( apis . IS_NODE_ENV ) {
64- ONNX = ONNX_NODE . default ?? ONNX_NODE ;
66+ } else if ( apis . IS_NODE_ENV && ( ONNX = ONNX_NODE . default ?? ONNX_NODE ) ?. InferenceSession ) {
67+ ort = 'node' ;
6568
6669 // Updated as of ONNX Runtime 1.20.1
6770 // The following table lists the supported versions of ONNX Runtime Node.js binding provided with pre-built binaries.
@@ -87,6 +90,7 @@ if (ORT_SYMBOL in globalThis) {
8790 defaultDevices = [ 'cpu' ] ;
8891} else {
8992 ONNX = ONNX_WEB ;
93+ ort = 'web' ;
9094
9195 if ( apis . IS_WEBNN_AVAILABLE ) {
9296 // TODO: Only push supported providers (depending on available hardware)
@@ -169,6 +173,14 @@ export function isONNXTensor(x) {
169173 return x instanceof ONNX . Tensor ;
170174}
171175
176+ /**
177+ * The type of ONNX runtime being used.
178+ * - 'node' for `onnxruntime-node`
179+ * - 'web' for `onnxruntime-web`
180+ * - 'custom' for a custom ONNX runtime
181+ */
182+ export const runtime = ort ;
183+
172184/** @type {import('onnxruntime-common').Env } */
173185// @ts -ignore
174186const ONNX_ENV = ONNX ?. env ;
0 commit comments