obi-sdk 0.1.7 → 0.1.9

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.
@@ -1,12 +1,12 @@
1
- import { A, E, O, S } from "./chunks/obi-widget-0d63936f.js";
2
- import { ObiSession } from "./chunks/session-88fd0dca.js";
3
- import { a, O as O2 } from "./chunks/assistant-5a47c1b4.js";
1
+ import { A, E, O, S } from "./chunks/obi-widget-ff350828.js";
2
+ import { ObiSession } from "./chunks/session-c3b70ffb.js";
3
+ import { ObiAssistant, ObiSDK } from "./index.js";
4
4
  import "./chunks/mitt-3c1f932d.js";
5
5
  export {
6
6
  A as API_BASE_URL,
7
7
  E as EventType,
8
- a as ObiAssistant,
9
- O2 as ObiSDK,
8
+ ObiAssistant,
9
+ ObiSDK,
10
10
  O as ObiSDKConfigSchema,
11
11
  ObiSession,
12
12
  S as SDKState
@@ -1,147 +1,237 @@
1
- import { E, a, S } from "./chunks/obi-widget-0d63936f.js";
2
- import { a as a2, O } from "./chunks/assistant-5a47c1b4.js";
3
- import "./chunks/mitt-3c1f932d.js";
4
- const NPM_REGISTRY_URL = "https://registry.npmjs.org/obi-sdk/latest";
5
- const UNPKG_BASE_URL = "https://unpkg.com/obi-sdk";
6
- const w = window;
7
- w.__obiSDKLoading = w.__obiSDKLoading || false;
8
- const initObi = async (config) => {
9
- w.obiWidgetConfig = config;
10
- return new Promise((resolve, reject) => {
11
- if (w.ObiAssistant) {
12
- try {
13
- const widget = createWidget(config);
14
- resolve(widget);
15
- return;
16
- } catch (error) {
17
- reject(new Error(`Error creating widget: ${error}`));
18
- return;
1
+ import { S as SDKState, O as ObiSDKConfigSchema, E as EventType, b as ObiWidget } from "./chunks/obi-widget-ff350828.js";
2
+ import { m as mitt } from "./chunks/mitt-3c1f932d.js";
3
+ class ObiSDK {
4
+ constructor(config = {}) {
5
+ this.state = SDKState.READY;
6
+ this.emitter = mitt();
7
+ this.voiceEnabled = false;
8
+ this.screenCaptureEnabled = false;
9
+ this.config = ObiSDKConfigSchema.parse(config);
10
+ if (this.config.debug) {
11
+ console.log("ObiSDK initialized with config:", this.config);
12
+ }
13
+ }
14
+ async init() {
15
+ try {
16
+ if (this.config.enableVoice) {
17
+ await this.initVoice();
18
+ }
19
+ if (this.config.enableScreenCapture) {
20
+ await this.initScreenCapture();
21
+ }
22
+ this.setState(SDKState.READY);
23
+ this.emitter.emit(EventType.READY);
24
+ if (this.config.debug) {
25
+ console.log("ObiSDK ready");
26
+ }
27
+ } catch (error) {
28
+ const sdkError = {
29
+ code: "init_failed",
30
+ message: "Failed to initialize SDK",
31
+ details: error
32
+ };
33
+ this.handleError(sdkError);
34
+ }
35
+ }
36
+ async initVoice() {
37
+ if (!window.navigator.mediaDevices || !window.navigator.mediaDevices.getUserMedia) {
38
+ throw new Error("Voice recording not supported in this browser");
39
+ }
40
+ try {
41
+ await window.navigator.mediaDevices.getUserMedia({ audio: true });
42
+ this.voiceEnabled = true;
43
+ if (this.config.debug) {
44
+ console.log("Voice capabilities initialized");
19
45
  }
46
+ } catch (error) {
47
+ throw new Error(`Microphone access denied: ${error}`);
48
+ }
49
+ }
50
+ async initScreenCapture() {
51
+ if (!window.navigator.mediaDevices || !window.navigator.mediaDevices.getDisplayMedia) {
52
+ throw new Error("Screen capture not supported in this browser");
53
+ }
54
+ this.screenCaptureEnabled = true;
55
+ if (this.config.debug) {
56
+ console.log("Screen capture capabilities initialized");
20
57
  }
21
- if (w.__obiSDKLoading) {
22
- checkSDKLoaded(() => {
23
- try {
24
- const widget = createWidget(config);
25
- resolve(widget);
26
- } catch (error) {
27
- reject(new Error(`Error creating widget after waiting: ${error}`));
28
- }
58
+ }
59
+ /**
60
+ * Set the SDK state and emit state change event
61
+ */
62
+ setState(newState) {
63
+ this.state = newState;
64
+ this.emitter.emit(EventType.STATE_CHANGE, newState);
65
+ }
66
+ /**
67
+ * Handle SDK errors
68
+ */
69
+ handleError(error) {
70
+ this.setState(SDKState.ERROR);
71
+ this.emitter.emit(EventType.ERROR, error);
72
+ if (this.config.debug) {
73
+ console.error("ObiSDK error:", error);
74
+ }
75
+ }
76
+ /**
77
+ * Start voice recording
78
+ */
79
+ async startVoiceRecording() {
80
+ if (!this.voiceEnabled) {
81
+ this.handleError({
82
+ code: "voice_disabled",
83
+ message: "Voice recording is not enabled or available"
29
84
  });
30
85
  return;
31
86
  }
32
- fetchManifestVersion().then((version) => {
33
- loadSDKScript(
34
- version,
35
- () => {
36
- w.__obiSDKLoading = false;
37
- try {
38
- const widget = createWidget(config);
39
- resolve(widget);
40
- } catch (error) {
41
- reject(new Error(`Error creating widget after loading SDK: ${error}`));
42
- }
43
- },
44
- reject
45
- );
46
- }).catch(() => {
47
- loadSDKScript(
48
- null,
49
- () => {
50
- w.__obiSDKLoading = false;
51
- try {
52
- const widget = createWidget(config);
53
- resolve(widget);
54
- } catch (error) {
55
- reject(new Error(`Error creating widget with latest version: ${error}`));
56
- }
57
- },
58
- reject
59
- );
60
- });
61
- });
62
- };
63
- function checkSDKLoaded(callback) {
64
- const checkInterval = setInterval(() => {
65
- if (typeof w.ObiAssistant === "function" || typeof w.ObiAssistant === "object") {
66
- clearInterval(checkInterval);
67
- callback();
87
+ try {
88
+ this.setState(SDKState.AGENT_SPEAKING);
89
+ this.emitter.emit(EventType.VOICE_START);
90
+ if (this.config.debug) {
91
+ console.log("Voice recording started");
92
+ }
93
+ } catch (error) {
94
+ this.handleError({
95
+ code: "voice_start_failed",
96
+ message: "Failed to start voice recording",
97
+ details: error
98
+ });
99
+ }
100
+ }
101
+ /**
102
+ * Stop voice recording
103
+ */
104
+ async stopVoiceRecording() {
105
+ if (this.state === SDKState.READY) {
106
+ return { transcript: void 0 };
68
107
  }
69
- }, 100);
70
- }
71
- async function fetchManifestVersion() {
72
- return new Promise((resolve) => {
73
108
  try {
74
- const xhr = new XMLHttpRequest();
75
- xhr.open("GET", NPM_REGISTRY_URL);
76
- xhr.onload = () => {
77
- if (xhr.status === 200) {
78
- try {
79
- const response = JSON.parse(xhr.responseText);
80
- resolve(response.version);
81
- } catch (e) {
82
- resolve(null);
83
- }
84
- } else {
85
- resolve(null);
86
- }
87
- };
88
- xhr.onerror = () => resolve(null);
89
- xhr.send();
90
- } catch (e) {
91
- resolve(null);
109
+ const result = { transcript: "Sample transcript" };
110
+ this.setState(SDKState.READY);
111
+ this.emitter.emit(EventType.VOICE_STOP, result);
112
+ if (this.config.debug) {
113
+ console.log("Voice recording stopped:", result);
114
+ }
115
+ return result;
116
+ } catch (error) {
117
+ this.handleError({
118
+ code: "voice_stop_failed",
119
+ message: "Failed to stop voice recording",
120
+ details: error
121
+ });
122
+ return { transcript: void 0 };
92
123
  }
93
- });
94
- }
95
- function loadSDKScript(version, onSuccess, onError) {
96
- w.__obiSDKLoading = true;
97
- const script = document.createElement("script");
98
- script.type = "text/javascript";
99
- script.async = true;
100
- const versionToUse = version || "latest";
101
- script.src = `${UNPKG_BASE_URL}@${versionToUse}/dist/obi-sdk.standalone.iife.js`;
102
- script.onload = onSuccess;
103
- script.onerror = () => {
104
- if (versionToUse !== "latest") {
105
- console.warn("Failed to load specific version, falling back to latest");
106
- script.src = `${UNPKG_BASE_URL}@latest/dist/obi-sdk.standalone.iife.js`;
107
- script.onload = onSuccess;
108
- } else {
109
- w.__obiSDKLoading = false;
110
- onError(new Error("Failed to load Obi SDK from CDN"));
111
- }
112
- };
113
- document.head.appendChild(script);
114
- }
115
- function createWidget(config) {
116
- const d = document;
117
- const existingWidget = d.querySelector("obi-widget");
118
- if (existingWidget) {
119
- console.log("Obi Widget already exists on the page");
120
- return existingWidget;
121
124
  }
122
- if (!customElements.get("obi-widget")) {
123
- throw new Error("Obi Widget component not registered - SDK may not have loaded properly");
125
+ /**
126
+ * Start screen capture
127
+ */
128
+ async startScreenCapture() {
129
+ if (!this.screenCaptureEnabled) {
130
+ this.handleError({
131
+ code: "screen_capture_disabled",
132
+ message: "Screen capture is not enabled or available"
133
+ });
134
+ return;
135
+ }
136
+ try {
137
+ this.setState(SDKState.AGENT_SPEAKING);
138
+ this.emitter.emit(EventType.SCREEN_CAPTURE_START);
139
+ if (this.config.debug) {
140
+ console.log("Screen capture started");
141
+ }
142
+ } catch (error) {
143
+ this.handleError({
144
+ code: "screen_capture_start_failed",
145
+ message: "Failed to start screen capture",
146
+ details: error
147
+ });
148
+ }
124
149
  }
125
- const widget = d.createElement("obi-widget");
126
- if (config.apiKey) {
127
- widget.setAttribute("api-key", config.apiKey);
150
+ /**
151
+ * Stop screen capture
152
+ */
153
+ async stopScreenCapture() {
154
+ if (this.state === SDKState.READY) {
155
+ return { screenshot: void 0 };
156
+ }
157
+ try {
158
+ const result = { screenshot: "data:image/png;base64,..." };
159
+ this.setState(SDKState.READY);
160
+ this.emitter.emit(EventType.SCREEN_CAPTURE_STOP, result);
161
+ if (this.config.debug) {
162
+ console.log("Screen capture stopped");
163
+ }
164
+ return result;
165
+ } catch (error) {
166
+ this.handleError({
167
+ code: "screen_capture_stop_failed",
168
+ message: "Failed to stop screen capture",
169
+ details: error
170
+ });
171
+ return { screenshot: void 0 };
172
+ }
173
+ }
174
+ /**
175
+ * Subscribe to SDK events
176
+ */
177
+ on(event, handler) {
178
+ this.emitter.on(event, handler);
179
+ }
180
+ /**
181
+ * Unsubscribe from SDK events
182
+ */
183
+ off(event, handler) {
184
+ this.emitter.off(event, handler);
128
185
  }
129
- if (config.position) {
130
- widget.setAttribute("position", config.position);
186
+ /**
187
+ * Get current SDK state
188
+ */
189
+ getState() {
190
+ return this.state;
131
191
  }
132
- if (config.user) {
133
- widget.setAttribute("user", JSON.stringify(config.user));
192
+ /**
193
+ * Cleanup and dispose SDK resources
194
+ */
195
+ dispose() {
196
+ this.emitter.all.clear();
197
+ if (this.config.debug) {
198
+ console.log("ObiSDK disposed");
199
+ }
200
+ }
201
+ }
202
+ const registerWidget = () => {
203
+ if (!customElements.get("obi-widget")) {
204
+ customElements.define("obi-widget", ObiWidget);
205
+ }
206
+ };
207
+ class ObiAssistant {
208
+ /**
209
+ * Initialize the Obi Widget with the provided configuration
210
+ * This creates and mounts the widget to the page
211
+ */
212
+ static init(config) {
213
+ registerWidget();
214
+ const widget = document.createElement("obi-widget");
215
+ if (config.apiKey) {
216
+ widget.apiKey = config.apiKey;
217
+ }
218
+ if (config.position) {
219
+ widget.position = config.position;
220
+ }
221
+ if (config.user) {
222
+ widget.user = config.user;
223
+ }
224
+ window.obiWidgetConfig = config;
225
+ document.body.appendChild(widget);
226
+ console.log("Obi Widget initialized and mounted");
227
+ return widget;
134
228
  }
135
- d.body.appendChild(widget);
136
- console.log("Obi Widget added to page");
137
- return widget;
138
229
  }
139
230
  export {
140
- E as EventType,
141
- a2 as ObiAssistant,
142
- O as ObiSDK,
143
- a as ObiWidget,
144
- S as SDKState,
145
- initObi
231
+ EventType,
232
+ ObiAssistant,
233
+ ObiSDK,
234
+ ObiWidget,
235
+ SDKState
146
236
  };
147
237
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/loader/index.ts"],"sourcesContent":["import type { ObiAssistantConfig } from \"../core/assistant\"\n// Constants for SDK loading\nconst NPM_REGISTRY_URL = \"https://registry.npmjs.org/obi-sdk/latest\"\nconst UNPKG_BASE_URL = \"https://unpkg.com/obi-sdk\"\n\n// Global flag for SDK loading to prevent multiple simultaneous loads\nconst w = window as any\nw.__obiSDKLoading = w.__obiSDKLoading || false\n\n/**\n * Initialize the Obi Assistant widget by loading the latest version from CDN\n * This ensures users always get the latest features and bug fixes\n */\nexport const initObi = async (config: ObiAssistantConfig): Promise<HTMLElement> => {\n // Store the config in window for use by the CDN script\n w.obiWidgetConfig = config\n\n return new Promise((resolve, reject) => {\n // If Obi is already in the window, use it directly\n if (w.ObiAssistant) {\n try {\n const widget = createWidget(config)\n resolve(widget)\n return\n } catch (error) {\n reject(new Error(`Error creating widget: ${error}`))\n return\n }\n }\n\n // Check if another instance is already loading the SDK\n if (w.__obiSDKLoading) {\n // Wait for SDK to load then create widget\n checkSDKLoaded(() => {\n try {\n const widget = createWidget(config)\n resolve(widget)\n } catch (error) {\n reject(new Error(`Error creating widget after waiting: ${error}`))\n }\n })\n return\n }\n\n // First check for manifest with latest version info\n fetchManifestVersion()\n .then((version) => {\n // Load the SDK with the specific version\n loadSDKScript(\n version,\n () => {\n w.__obiSDKLoading = false\n try {\n const widget = createWidget(config)\n resolve(widget)\n } catch (error) {\n reject(new Error(`Error creating widget after loading SDK: ${error}`))\n }\n },\n reject\n )\n })\n .catch(() => {\n // If version fetch fails, try loading latest\n loadSDKScript(\n null,\n () => {\n w.__obiSDKLoading = false\n try {\n const widget = createWidget(config)\n resolve(widget)\n } catch (error) {\n reject(new Error(`Error creating widget with latest version: ${error}`))\n }\n },\n reject\n )\n })\n })\n}\n\n/**\n * Poll for SDK loading completion\n */\nfunction checkSDKLoaded(callback: () => void): void {\n const checkInterval = setInterval(() => {\n if (typeof w.ObiAssistant === \"function\" || typeof w.ObiAssistant === \"object\") {\n clearInterval(checkInterval)\n callback()\n }\n }, 100)\n}\n\n/**\n * Fetch the latest version from NPM registry\n */\nasync function fetchManifestVersion(): Promise<string | null> {\n return new Promise((resolve) => {\n try {\n const xhr = new XMLHttpRequest()\n xhr.open(\"GET\", NPM_REGISTRY_URL)\n xhr.onload = () => {\n if (xhr.status === 200) {\n try {\n const response = JSON.parse(xhr.responseText)\n resolve(response.version)\n } catch (e) {\n resolve(null)\n }\n } else {\n resolve(null)\n }\n }\n xhr.onerror = () => resolve(null)\n xhr.send()\n } catch (e) {\n resolve(null)\n }\n })\n}\n\n/**\n * Load the SDK script from CDN\n */\nfunction loadSDKScript(\n version: string | null,\n onSuccess: () => void,\n onError: (error: Error) => void\n): void {\n // Set loading flag\n w.__obiSDKLoading = true\n\n const script = document.createElement(\"script\")\n script.type = \"text/javascript\"\n script.async = true\n\n // Use the specific version for better caching, or fall back to latest\n const versionToUse = version || \"latest\"\n script.src = `${UNPKG_BASE_URL}@${versionToUse}/dist/obi-sdk.standalone.iife.js`\n\n // Set up onload handler\n script.onload = onSuccess\n\n // Handle errors\n script.onerror = () => {\n // If specific version fails, try falling back to latest\n if (versionToUse !== \"latest\") {\n console.warn(\"Failed to load specific version, falling back to latest\")\n script.src = `${UNPKG_BASE_URL}@latest/dist/obi-sdk.standalone.iife.js`\n script.onload = onSuccess\n } else {\n w.__obiSDKLoading = false\n onError(new Error(\"Failed to load Obi SDK from CDN\"))\n }\n }\n\n // Add the script to the document\n document.head.appendChild(script)\n}\n\n/**\n * Create the widget element\n */\nfunction createWidget(config: ObiAssistantConfig): HTMLElement {\n const d = document\n\n // Don't create multiple widgets\n const existingWidget = d.querySelector(\"obi-widget\")\n if (existingWidget) {\n console.log(\"Obi Widget already exists on the page\")\n return existingWidget as HTMLElement\n }\n\n // Check if the component is registered\n if (!customElements.get(\"obi-widget\")) {\n throw new Error(\"Obi Widget component not registered - SDK may not have loaded properly\")\n }\n\n // Create the widget element\n const widget = d.createElement(\"obi-widget\") as HTMLElement\n\n // Pass API key if provided\n if (config.apiKey) {\n widget.setAttribute(\"api-key\", config.apiKey)\n }\n\n // Set position attribute if provided\n if (config.position) {\n widget.setAttribute(\"position\", config.position)\n }\n\n // Set user information if provided\n if (config.user) {\n widget.setAttribute(\"user\", JSON.stringify(config.user))\n }\n\n // Add to page\n d.body.appendChild(widget)\n console.log(\"Obi Widget added to page\")\n\n return widget\n}\n\n/**\n * Get the latest SDK instance for advanced usage\n */\nexport const getLatestSDK = async () => {\n throw new Error(\"getLatestSDK() is not implemented in this version\")\n}\n\n/**\n * Create a session using the latest SDK\n */\nexport const createLatestSession = async () => {\n throw new Error(\"createLatestSession() is not implemented in this version\")\n}\n"],"names":[],"mappings":";;;AAEA,MAAM,mBAAmB;AACzB,MAAM,iBAAiB;AAGvB,MAAM,IAAI;AACV,EAAE,kBAAkB,EAAE,mBAAmB;AAM5B,MAAA,UAAU,OAAO,WAAqD;AAEjF,IAAE,kBAAkB;AAEpB,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AAEtC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A,EAC9C;AAGA,MAAI,OAAO,UAAU;AACZ,WAAA,aAAa,YAAY,OAAO,QAAQ;AAAA,EACjD;AAGA,MAAI,OAAO,MAAM;AACf,WAAO,aAAa,QAAQ,KAAK,UAAU,OAAO,IAAI,CAAC;AAAA,EACzD;AAGE,IAAA,KAAK,YAAY,MAAM;AACzB,UAAQ,IAAI,0BAA0B;AAE/B,SAAA;AACT;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/core/sdk.ts","../../src/core/assistant.ts"],"sourcesContent":["import mitt from \"mitt\"\n\nimport { EventType, ObiError, ObiSDKConfig, ObiSDKConfigSchema, SDKState } from \"./types\"\n\ntype Events = {\n [EventType.READY]: void\n [EventType.ERROR]: ObiError\n [EventType.VOICE_START]: void\n [EventType.VOICE_STOP]: { transcript?: string }\n [EventType.SCREEN_CAPTURE_START]: void\n [EventType.SCREEN_CAPTURE_STOP]: { screenshot?: string }\n [EventType.STATE_CHANGE]: SDKState\n}\n\nexport class ObiSDK {\n private config: ObiSDKConfig\n private state: SDKState = SDKState.READY\n private emitter = mitt<Events>()\n private voiceEnabled = false\n private screenCaptureEnabled = false\n\n constructor(config: Partial<ObiSDKConfig> = {}) {\n this.config = ObiSDKConfigSchema.parse(config)\n\n if (this.config.debug) {\n console.log(\"ObiSDK initialized with config:\", this.config)\n }\n }\n\n async init(): Promise<void> {\n try {\n if (this.config.enableVoice) {\n await this.initVoice()\n }\n\n if (this.config.enableScreenCapture) {\n await this.initScreenCapture()\n }\n\n this.setState(SDKState.READY)\n this.emitter.emit(EventType.READY)\n\n if (this.config.debug) {\n console.log(\"ObiSDK ready\")\n }\n } catch (error) {\n const sdkError: ObiError = {\n code: \"init_failed\",\n message: \"Failed to initialize SDK\",\n details: error,\n }\n this.handleError(sdkError)\n }\n }\n\n private async initVoice(): Promise<void> {\n // Check if browser supports required voice APIs\n if (!window.navigator.mediaDevices || !window.navigator.mediaDevices.getUserMedia) {\n throw new Error(\"Voice recording not supported in this browser\")\n }\n\n try {\n // Request microphone permissions\n await window.navigator.mediaDevices.getUserMedia({ audio: true })\n this.voiceEnabled = true\n\n if (this.config.debug) {\n console.log(\"Voice capabilities initialized\")\n }\n } catch (error) {\n throw new Error(`Microphone access denied: ${error}`)\n }\n }\n\n private async initScreenCapture(): Promise<void> {\n // Check if browser supports required screen capture APIs\n if (!window.navigator.mediaDevices || !window.navigator.mediaDevices.getDisplayMedia) {\n throw new Error(\"Screen capture not supported in this browser\")\n }\n\n this.screenCaptureEnabled = true\n\n if (this.config.debug) {\n console.log(\"Screen capture capabilities initialized\")\n }\n }\n\n /**\n * Set the SDK state and emit state change event\n */\n private setState(newState: SDKState): void {\n this.state = newState\n this.emitter.emit(EventType.STATE_CHANGE, newState)\n }\n\n /**\n * Handle SDK errors\n */\n private handleError(error: ObiError): void {\n this.setState(SDKState.ERROR)\n this.emitter.emit(EventType.ERROR, error)\n\n if (this.config.debug) {\n console.error(\"ObiSDK error:\", error)\n }\n }\n\n /**\n * Start voice recording\n */\n async startVoiceRecording(): Promise<void> {\n if (!this.voiceEnabled) {\n this.handleError({\n code: \"voice_disabled\",\n message: \"Voice recording is not enabled or available\",\n })\n return\n }\n\n try {\n this.setState(SDKState.AGENT_SPEAKING)\n this.emitter.emit(EventType.VOICE_START)\n\n if (this.config.debug) {\n console.log(\"Voice recording started\")\n }\n } catch (error) {\n this.handleError({\n code: \"voice_start_failed\",\n message: \"Failed to start voice recording\",\n details: error,\n })\n }\n }\n\n /**\n * Stop voice recording\n */\n async stopVoiceRecording(): Promise<{ transcript?: string }> {\n if (this.state === SDKState.READY) {\n return { transcript: undefined }\n }\n\n try {\n const result = { transcript: \"Sample transcript\" } // Placeholder for real implementation\n\n this.setState(SDKState.READY)\n this.emitter.emit(EventType.VOICE_STOP, result)\n\n if (this.config.debug) {\n console.log(\"Voice recording stopped:\", result)\n }\n\n return result\n } catch (error) {\n this.handleError({\n code: \"voice_stop_failed\",\n message: \"Failed to stop voice recording\",\n details: error,\n })\n return { transcript: undefined }\n }\n }\n\n /**\n * Start screen capture\n */\n async startScreenCapture(): Promise<void> {\n if (!this.screenCaptureEnabled) {\n this.handleError({\n code: \"screen_capture_disabled\",\n message: \"Screen capture is not enabled or available\",\n })\n return\n }\n\n try {\n this.setState(SDKState.AGENT_SPEAKING)\n this.emitter.emit(EventType.SCREEN_CAPTURE_START)\n\n if (this.config.debug) {\n console.log(\"Screen capture started\")\n }\n } catch (error) {\n this.handleError({\n code: \"screen_capture_start_failed\",\n message: \"Failed to start screen capture\",\n details: error,\n })\n }\n }\n\n /**\n * Stop screen capture\n */\n async stopScreenCapture(): Promise<{ screenshot?: string }> {\n if (this.state === SDKState.READY) {\n return { screenshot: undefined }\n }\n\n try {\n const result = { screenshot: \"data:image/png;base64,...\" } // Placeholder for real implementation\n\n this.setState(SDKState.READY)\n this.emitter.emit(EventType.SCREEN_CAPTURE_STOP, result)\n\n if (this.config.debug) {\n console.log(\"Screen capture stopped\")\n }\n\n return result\n } catch (error) {\n this.handleError({\n code: \"screen_capture_stop_failed\",\n message: \"Failed to stop screen capture\",\n details: error,\n })\n return { screenshot: undefined }\n }\n }\n\n /**\n * Subscribe to SDK events\n */\n on<E extends EventType>(event: E, handler: (data: Events[E]) => void): void {\n this.emitter.on(event, handler as any)\n }\n\n /**\n * Unsubscribe from SDK events\n */\n off<E extends EventType>(event: E, handler: (data: Events[E]) => void): void {\n this.emitter.off(event, handler as any)\n }\n\n /**\n * Get current SDK state\n */\n getState(): SDKState {\n return this.state\n }\n\n /**\n * Cleanup and dispose SDK resources\n */\n dispose(): void {\n this.emitter.all.clear()\n\n if (this.config.debug) {\n console.log(\"ObiSDK disposed\")\n }\n }\n}\n","/**\n * ObiAssistant provides a simple way to initialize the Obi Widget\n * with a single method call.\n */\n\nimport { ObiWidget } from \"../ui/components/obi-widget\"\n\n// Define the configuration interface\nexport interface ObiAssistantConfig {\n apiKey: string\n position?: \"bottom-right\" | \"bottom-left\" | \"top-right\" | \"top-left\"\n user?: {\n id: string\n email?: string\n metadata?: Record<string, any>\n }\n}\n\n// Register the custom element if it hasn't been registered yet\nconst registerWidget = () => {\n if (!customElements.get(\"obi-widget\")) {\n customElements.define(\"obi-widget\", ObiWidget)\n }\n}\n\n/**\n * ObiAssistant class with static init method for easier initialization\n */\nexport class ObiAssistant {\n /**\n * Initialize the Obi Widget with the provided configuration\n * This creates and mounts the widget to the page\n */\n static init(config: ObiAssistantConfig): HTMLElement {\n // Make sure the widget is defined\n registerWidget()\n\n // Create widget instance\n const widget = document.createElement(\"obi-widget\") as ObiWidget\n\n // Set API key\n if (config.apiKey) {\n widget.apiKey = config.apiKey\n }\n\n // Set position if provided\n if (config.position) {\n widget.position = config.position\n }\n\n // Set user information if provided\n if (config.user) {\n widget.user = config.user\n }\n\n // Save config for access from anywhere\n window.obiWidgetConfig = config\n\n // Add the widget to the document body\n document.body.appendChild(widget)\n\n console.log(\"Obi Widget initialized and mounted\")\n\n return widget\n }\n}\n"],"names":[],"mappings":";;AAcO,MAAM,OAAO;AAAA,EAOlB,YAAY,SAAgC,IAAI;AALhD,SAAQ,QAAkB,SAAS;AACnC,SAAQ,UAAU;AAClB,SAAQ,eAAe;AACvB,SAAQ,uBAAuB;AAGxB,SAAA,SAAS,mBAAmB,MAAM,MAAM;AAEzC,QAAA,KAAK,OAAO,OAAO;AACb,cAAA,IAAI,mCAAmC,KAAK,MAAM;AAAA,IAC5D;AAAA,EACF;AAAA,EAEA,MAAM,OAAsB;AACtB,QAAA;AACE,UAAA,KAAK,OAAO,aAAa;AAC3B,cAAM,KAAK;MACb;AAEI,UAAA,KAAK,OAAO,qBAAqB;AACnC,cAAM,KAAK;MACb;AAEK,WAAA,SAAS,SAAS,KAAK;AACvB,WAAA,QAAQ,KAAK,UAAU,KAAK;AAE7B,UAAA,KAAK,OAAO,OAAO;AACrB,gBAAQ,IAAI,cAAc;AAAA,MAC5B;AAAA,aACO,OAAO;AACd,YAAM,WAAqB;AAAA,QACzB,MAAM;AAAA,QACN,SAAS;AAAA,QACT,SA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,IAAI,oCAAoC;AAEzC,WAAA;AAAA,EACT;AACF;"}
@@ -1,5 +1,5 @@
1
- import { i, n, b as i$1, S as SDKState, x } from "./chunks/obi-widget-0d63936f.js";
2
- import { c, C, f, g, D, N, d, a, e } from "./chunks/obi-widget-0d63936f.js";
1
+ import { i, n, a as i$1, S as SDKState, x } from "./chunks/obi-widget-ff350828.js";
2
+ import { c, C, f, g, D, N, d, b, e } from "./chunks/obi-widget-ff350828.js";
3
3
  var __defProp$1 = Object.defineProperty;
4
4
  var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
5
5
  var __decorateClass$1 = (decorators, target, key, kind) => {
@@ -226,14 +226,14 @@ const controlPanel = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.define
226
226
  function defineCustomElements() {
227
227
  Promise.resolve().then(() => statusWidget);
228
228
  Promise.resolve().then(() => controlPanel);
229
- import("./chunks/obi-widget-0d63936f.js").then((n2) => n2.p);
230
- import("./chunks/obi-widget-0d63936f.js").then((n2) => n2.m);
231
- import("./chunks/obi-widget-0d63936f.js").then((n2) => n2.o);
232
- import("./chunks/obi-widget-0d63936f.js").then((n2) => n2.h);
233
- import("./chunks/obi-widget-0d63936f.js").then((n2) => n2.j);
234
- import("./chunks/obi-widget-0d63936f.js").then((n2) => n2.s);
235
- import("./chunks/obi-widget-0d63936f.js").then((n2) => n2.k);
236
- import("./chunks/obi-widget-0d63936f.js").then((n2) => n2.l);
229
+ import("./chunks/obi-widget-ff350828.js").then((n2) => n2.p);
230
+ import("./chunks/obi-widget-ff350828.js").then((n2) => n2.m);
231
+ import("./chunks/obi-widget-ff350828.js").then((n2) => n2.o);
232
+ import("./chunks/obi-widget-ff350828.js").then((n2) => n2.h);
233
+ import("./chunks/obi-widget-ff350828.js").then((n2) => n2.j);
234
+ import("./chunks/obi-widget-ff350828.js").then((n2) => n2.s);
235
+ import("./chunks/obi-widget-ff350828.js").then((n2) => n2.k);
236
+ import("./chunks/obi-widget-ff350828.js").then((n2) => n2.l);
237
237
  }
238
238
  export {
239
239
  c as AudioEqualizer,
@@ -245,7 +245,7 @@ export {
245
245
  d as NavigationBar,
246
246
  ObiControlPanel,
247
247
  ObiStatusWidget,
248
- a as ObiWidget,
248
+ b as ObiWidget,
249
249
  e as SearchingLoader,
250
250
  defineCustomElements
251
251
  };
@@ -1,86 +1,8 @@
1
- const s = "https://www.iamobi.ai/api/", a = {
2
- position: "bottom-right",
3
- autoInit: !0
1
+ const e = () => {
2
+ throw console.error(
3
+ "The initObi function has been moved to a separate package. Please install the 'obi-loader' package: npm install obi-loader"
4
+ ), new Error("initObi function has moved to 'obi-loader' package");
4
5
  };
5
- class c {
6
- constructor(t = {}) {
7
- this.config = { ...a, ...t }, this.widget = null, this.config.autoInit !== !1 && this.init();
8
- }
9
- async init() {
10
- try {
11
- await this.loadScript(), this.createWidget(), this.initializeSDK();
12
- } catch (t) {
13
- console.error("Failed to initialize Obi Widget:", t);
14
- }
15
- }
16
- async loadScript() {
17
- return new Promise((t, e) => {
18
- if (document.querySelector("script[data-obi-sdk]")) {
19
- t();
20
- return;
21
- }
22
- this.fetchLatestVersion().then((i) => {
23
- const o = document.createElement("script");
24
- o.type = "text/javascript";
25
- const r = `https://unpkg.com/obi-sdk@${i || "latest"}/dist/obi-sdk.standalone.iife.js`;
26
- o.src = r, o.dataset.obiSdk = "true", o.onload = () => t(), o.onerror = () => e(new Error("Failed to load Obi SDK script")), document.head.appendChild(o);
27
- }).catch(() => {
28
- const i = document.createElement("script");
29
- i.type = "text/javascript", i.src = "https://unpkg.com/obi-sdk@latest/dist/obi-sdk.standalone.iife.js", i.dataset.obiSdk = "true", i.onload = () => t(), i.onerror = () => e(new Error("Failed to load Obi SDK script")), document.head.appendChild(i);
30
- });
31
- });
32
- }
33
- // Fetch the latest version from npm registry
34
- async fetchLatestVersion() {
35
- try {
36
- const t = await fetch("https://registry.npmjs.org/obi-sdk/latest");
37
- return t.ok ? (await t.json()).version : null;
38
- } catch (t) {
39
- return console.warn("Failed to fetch latest version:", t), null;
40
- }
41
- }
42
- createWidget() {
43
- if (document.querySelector("obi-widget")) {
44
- this.widget = document.querySelector("obi-widget");
45
- return;
46
- }
47
- if (!customElements.get("obi-widget")) {
48
- console.warn(
49
- "Obi Widget component not registered - import the component before using the loader"
50
- );
51
- return;
52
- }
53
- const t = document.createElement("obi-widget");
54
- this.config.apiKey && t.setAttribute("api-key", this.config.apiKey), t.setAttribute("api-base-url", s), this.config.position && t.setAttribute("position", this.config.position), this.config.user && t.setAttribute("user", JSON.stringify(this.config.user)), document.body.appendChild(t), this.widget = t, console.log("Widget created and added to DOM");
55
- }
56
- initializeSDK() {
57
- if (typeof window.ObiSDK < "u") {
58
- const t = {
59
- apiKey: this.config.apiKey,
60
- apiBaseUrl: s
61
- };
62
- try {
63
- const e = new window.ObiSDK(t);
64
- window.obiSDKInstance = e;
65
- } catch (e) {
66
- console.error("Failed to initialize SDK:", e);
67
- }
68
- }
69
- }
70
- // Public method to manually initialize the widget
71
- initialize() {
72
- this.init();
73
- }
74
- // Add a public method to get the widget element
75
- getWidget() {
76
- return this.widget;
77
- }
78
- }
79
- document.addEventListener("DOMContentLoaded", () => {
80
- const n = window.obiWidgetConfig || {};
81
- new c(n);
82
- });
83
6
  export {
84
- c as ObiWidgetLoader
7
+ e as initObi
85
8
  };
86
- //# sourceMappingURL=obi-loader.js.map
@@ -1,10 +1,9 @@
1
- import { E as t, b, a as e, O, S, i as n } from "./index-d9a81606.js";
1
+ import { E as i, b as e, a as b, O, S } from "./index-719ec57d.js";
2
2
  import "lit";
3
3
  export {
4
- t as EventType,
5
- b as ObiAssistant,
6
- e as ObiSDK,
4
+ i as EventType,
5
+ e as ObiAssistant,
6
+ b as ObiSDK,
7
7
  O as ObiWidget,
8
- S as SDKState,
9
- n as initObi
8
+ S as SDKState
10
9
  };