"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.flags = exports.wasmBackend = void 0;
const onnxruntime_common_1 = require("onnxruntime-common");
const wasm_1 = require("./wasm");
class OnnxruntimeWebAssemblyBackend {
    async init() {
        await wasm_1.init();
    }
    async createSessionHandler(pathOrBuffer, _options) {
        let buffer;
        if (typeof pathOrBuffer === 'string') {
            const response = await fetch(pathOrBuffer);
            const arrayBuffer = await response.arrayBuffer();
            buffer = new Uint8Array(arrayBuffer);
        }
        else {
            buffer = pathOrBuffer;
        }
        const handler = new wasm_1.OnnxruntimeWebAssemblySessionHandler();
        // TODO: support SessionOptions
        handler.loadModel(buffer);
        return Promise.resolve(handler);
    }
}
exports.wasmBackend = new OnnxruntimeWebAssemblyBackend();
/**
 * Represent a set of flags for WebAssembly backend.
 */
exports.flags = onnxruntime_common_1.env.wasm = onnxruntime_common_1.env.wasm || {};
//# sourceMappingURL=backend-wasm.js.map