@ourlu/assistant-sdk 0.2.0

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.
@@ -0,0 +1,71 @@
1
+ (function() {
2
+ "use strict";
3
+
4
+ var RUNTIME_NS = "__CompanionWidgetRuntimeV1";
5
+ var RUNTIME_FLAG = "__CompanionWidgetRuntimeLoadPromiseV1";
6
+
7
+ function resolveCurrentScript() {
8
+ if (document.currentScript) return document.currentScript;
9
+ var scripts = document.querySelectorAll("script[data-tenant-id]");
10
+ return scripts[scripts.length - 1];
11
+ }
12
+
13
+ function buildRuntimeAssetUrl(scriptTag, assetName) {
14
+ var src = scriptTag.getAttribute("src") || "";
15
+ var fallbackBase = window.location.origin;
16
+ try {
17
+ var url = new URL(src, window.location.href);
18
+ var lastSlash = url.pathname.lastIndexOf("/");
19
+ var basePath = lastSlash >= 0 ? url.pathname.slice(0, lastSlash + 1) : "/";
20
+ return url.origin + basePath + assetName;
21
+ } catch (_) {
22
+ return fallbackBase + "/" + assetName;
23
+ }
24
+ }
25
+
26
+ function buildApiRuntimeAssetUrl(scriptTag, assetName) {
27
+ var apiBaseUrl = (scriptTag.getAttribute("data-api-base-url") || "").replace(/\/$/, "");
28
+ if (!apiBaseUrl) return "";
29
+ return apiBaseUrl + "/v1/widget/runtime/" + assetName;
30
+ }
31
+
32
+ function loadScript(url) {
33
+ return new Promise(function(resolve, reject) {
34
+ var node = document.createElement("script");
35
+ node.src = url;
36
+ node.async = true;
37
+ node.onload = function() { resolve(); };
38
+ node.onerror = function() { reject(new Error("Failed loading " + url)); };
39
+ document.head.appendChild(node);
40
+ });
41
+ }
42
+
43
+ var scriptTag = resolveCurrentScript();
44
+ if (!scriptTag) {
45
+ console.error("[CompanionMairie] Loader: no script tag found.");
46
+ return;
47
+ }
48
+
49
+ if (!window[RUNTIME_FLAG]) {
50
+ var uiRuntimeUrl = scriptTag.getAttribute("data-runtime-ui-url") || buildApiRuntimeAssetUrl(scriptTag, "ui.v1.js") || buildRuntimeAssetUrl(scriptTag, "loader.runtime.ui.v1.js");
51
+ var audioRuntimeUrl = scriptTag.getAttribute("data-runtime-audio-url") || buildApiRuntimeAssetUrl(scriptTag, "audio.v1.js") || buildRuntimeAssetUrl(scriptTag, "loader.runtime.audio.v1.js");
52
+ var engineRuntimeUrl = scriptTag.getAttribute("data-runtime-engine-url") || buildApiRuntimeAssetUrl(scriptTag, "engine.v1.js") || buildRuntimeAssetUrl(scriptTag, "loader.runtime.engine.v1.js");
53
+ window[RUNTIME_FLAG] = loadScript(uiRuntimeUrl).then(function() {
54
+ return loadScript(audioRuntimeUrl);
55
+ }).then(function() {
56
+ return loadScript(engineRuntimeUrl);
57
+ });
58
+ }
59
+
60
+ window[RUNTIME_FLAG]
61
+ .then(function() {
62
+ var runtime = window[RUNTIME_NS];
63
+ if (!runtime || typeof runtime.mountFromScript !== "function") {
64
+ throw new Error("Widget runtime entrypoint missing.");
65
+ }
66
+ runtime.mountFromScript(scriptTag);
67
+ })
68
+ .catch(function(error) {
69
+ console.error("[CompanionMairie] Loader runtime error:", error);
70
+ });
71
+ })();