@olbrain/js-sdk 1.0.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,382 @@
1
+ import {
2
+ __commonJS,
3
+ __require,
4
+ init_esm_shims
5
+ } from "./chunk-QEZYOGUI.mjs";
6
+
7
+ // node_modules/eventsource/lib/eventsource.js
8
+ var require_eventsource = __commonJS({
9
+ "node_modules/eventsource/lib/eventsource.js"(exports, module) {
10
+ init_esm_shims();
11
+ var parse = __require("url").parse;
12
+ var events = __require("events");
13
+ var https = __require("https");
14
+ var http = __require("http");
15
+ var util = __require("util");
16
+ var httpsOptions = [
17
+ "pfx",
18
+ "key",
19
+ "passphrase",
20
+ "cert",
21
+ "ca",
22
+ "ciphers",
23
+ "rejectUnauthorized",
24
+ "secureProtocol",
25
+ "servername",
26
+ "checkServerIdentity"
27
+ ];
28
+ var bom = [239, 187, 191];
29
+ var colon = 58;
30
+ var space = 32;
31
+ var lineFeed = 10;
32
+ var carriageReturn = 13;
33
+ var maxBufferAheadAllocation = 1024 * 256;
34
+ var reUnsafeHeader = /^(cookie|authorization)$/i;
35
+ function hasBom(buf) {
36
+ return bom.every(function(charCode, index) {
37
+ return buf[index] === charCode;
38
+ });
39
+ }
40
+ function EventSource(url, eventSourceInitDict) {
41
+ var readyState = EventSource.CONNECTING;
42
+ var headers = eventSourceInitDict && eventSourceInitDict.headers;
43
+ var hasNewOrigin = false;
44
+ Object.defineProperty(this, "readyState", {
45
+ get: function() {
46
+ return readyState;
47
+ }
48
+ });
49
+ Object.defineProperty(this, "url", {
50
+ get: function() {
51
+ return url;
52
+ }
53
+ });
54
+ var self = this;
55
+ self.reconnectInterval = 1e3;
56
+ self.connectionInProgress = false;
57
+ function onConnectionClosed(message) {
58
+ if (readyState === EventSource.CLOSED) return;
59
+ readyState = EventSource.CONNECTING;
60
+ _emit("error", new Event("error", { message }));
61
+ if (reconnectUrl) {
62
+ url = reconnectUrl;
63
+ reconnectUrl = null;
64
+ hasNewOrigin = false;
65
+ }
66
+ setTimeout(function() {
67
+ if (readyState !== EventSource.CONNECTING || self.connectionInProgress) {
68
+ return;
69
+ }
70
+ self.connectionInProgress = true;
71
+ connect();
72
+ }, self.reconnectInterval);
73
+ }
74
+ var req;
75
+ var lastEventId = "";
76
+ if (headers && headers["Last-Event-ID"]) {
77
+ lastEventId = headers["Last-Event-ID"];
78
+ delete headers["Last-Event-ID"];
79
+ }
80
+ var discardTrailingNewline = false;
81
+ var data = "";
82
+ var eventName = "";
83
+ var reconnectUrl = null;
84
+ function connect() {
85
+ var options = parse(url);
86
+ var isSecure = options.protocol === "https:";
87
+ options.headers = { "Cache-Control": "no-cache", "Accept": "text/event-stream" };
88
+ if (lastEventId) options.headers["Last-Event-ID"] = lastEventId;
89
+ if (headers) {
90
+ var reqHeaders = hasNewOrigin ? removeUnsafeHeaders(headers) : headers;
91
+ for (var i in reqHeaders) {
92
+ var header = reqHeaders[i];
93
+ if (header) {
94
+ options.headers[i] = header;
95
+ }
96
+ }
97
+ }
98
+ options.rejectUnauthorized = !(eventSourceInitDict && !eventSourceInitDict.rejectUnauthorized);
99
+ if (eventSourceInitDict && eventSourceInitDict.createConnection !== void 0) {
100
+ options.createConnection = eventSourceInitDict.createConnection;
101
+ }
102
+ var useProxy = eventSourceInitDict && eventSourceInitDict.proxy;
103
+ if (useProxy) {
104
+ var proxy = parse(eventSourceInitDict.proxy);
105
+ isSecure = proxy.protocol === "https:";
106
+ options.protocol = isSecure ? "https:" : "http:";
107
+ options.path = url;
108
+ options.headers.Host = options.host;
109
+ options.hostname = proxy.hostname;
110
+ options.host = proxy.host;
111
+ options.port = proxy.port;
112
+ }
113
+ if (eventSourceInitDict && eventSourceInitDict.https) {
114
+ for (var optName in eventSourceInitDict.https) {
115
+ if (httpsOptions.indexOf(optName) === -1) {
116
+ continue;
117
+ }
118
+ var option = eventSourceInitDict.https[optName];
119
+ if (option !== void 0) {
120
+ options[optName] = option;
121
+ }
122
+ }
123
+ }
124
+ if (eventSourceInitDict && eventSourceInitDict.withCredentials !== void 0) {
125
+ options.withCredentials = eventSourceInitDict.withCredentials;
126
+ }
127
+ req = (isSecure ? https : http).request(options, function(res) {
128
+ self.connectionInProgress = false;
129
+ if (res.statusCode === 500 || res.statusCode === 502 || res.statusCode === 503 || res.statusCode === 504) {
130
+ _emit("error", new Event("error", { status: res.statusCode, message: res.statusMessage }));
131
+ onConnectionClosed();
132
+ return;
133
+ }
134
+ if (res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307) {
135
+ var location = res.headers.location;
136
+ if (!location) {
137
+ _emit("error", new Event("error", { status: res.statusCode, message: res.statusMessage }));
138
+ return;
139
+ }
140
+ var prevOrigin = new URL(url).origin;
141
+ var nextOrigin = new URL(location).origin;
142
+ hasNewOrigin = prevOrigin !== nextOrigin;
143
+ if (res.statusCode === 307) reconnectUrl = url;
144
+ url = location;
145
+ process.nextTick(connect);
146
+ return;
147
+ }
148
+ if (res.statusCode !== 200) {
149
+ _emit("error", new Event("error", { status: res.statusCode, message: res.statusMessage }));
150
+ return self.close();
151
+ }
152
+ readyState = EventSource.OPEN;
153
+ res.on("close", function() {
154
+ res.removeAllListeners("close");
155
+ res.removeAllListeners("end");
156
+ onConnectionClosed();
157
+ });
158
+ res.on("end", function() {
159
+ res.removeAllListeners("close");
160
+ res.removeAllListeners("end");
161
+ onConnectionClosed();
162
+ });
163
+ _emit("open", new Event("open"));
164
+ var buf;
165
+ var newBuffer;
166
+ var startingPos = 0;
167
+ var startingFieldLength = -1;
168
+ var newBufferSize = 0;
169
+ var bytesUsed = 0;
170
+ res.on("data", function(chunk) {
171
+ if (!buf) {
172
+ buf = chunk;
173
+ if (hasBom(buf)) {
174
+ buf = buf.slice(bom.length);
175
+ }
176
+ bytesUsed = buf.length;
177
+ } else {
178
+ if (chunk.length > buf.length - bytesUsed) {
179
+ newBufferSize = buf.length * 2 + chunk.length;
180
+ if (newBufferSize > maxBufferAheadAllocation) {
181
+ newBufferSize = buf.length + chunk.length + maxBufferAheadAllocation;
182
+ }
183
+ newBuffer = Buffer.alloc(newBufferSize);
184
+ buf.copy(newBuffer, 0, 0, bytesUsed);
185
+ buf = newBuffer;
186
+ }
187
+ chunk.copy(buf, bytesUsed);
188
+ bytesUsed += chunk.length;
189
+ }
190
+ var pos = 0;
191
+ var length = bytesUsed;
192
+ while (pos < length) {
193
+ if (discardTrailingNewline) {
194
+ if (buf[pos] === lineFeed) {
195
+ ++pos;
196
+ }
197
+ discardTrailingNewline = false;
198
+ }
199
+ var lineLength = -1;
200
+ var fieldLength = startingFieldLength;
201
+ var c;
202
+ for (var i2 = startingPos; lineLength < 0 && i2 < length; ++i2) {
203
+ c = buf[i2];
204
+ if (c === colon) {
205
+ if (fieldLength < 0) {
206
+ fieldLength = i2 - pos;
207
+ }
208
+ } else if (c === carriageReturn) {
209
+ discardTrailingNewline = true;
210
+ lineLength = i2 - pos;
211
+ } else if (c === lineFeed) {
212
+ lineLength = i2 - pos;
213
+ }
214
+ }
215
+ if (lineLength < 0) {
216
+ startingPos = length - pos;
217
+ startingFieldLength = fieldLength;
218
+ break;
219
+ } else {
220
+ startingPos = 0;
221
+ startingFieldLength = -1;
222
+ }
223
+ parseEventStreamLine(buf, pos, fieldLength, lineLength);
224
+ pos += lineLength + 1;
225
+ }
226
+ if (pos === length) {
227
+ buf = void 0;
228
+ bytesUsed = 0;
229
+ } else if (pos > 0) {
230
+ buf = buf.slice(pos, bytesUsed);
231
+ bytesUsed = buf.length;
232
+ }
233
+ });
234
+ });
235
+ req.on("error", function(err) {
236
+ self.connectionInProgress = false;
237
+ onConnectionClosed(err.message);
238
+ });
239
+ if (req.setNoDelay) req.setNoDelay(true);
240
+ req.end();
241
+ }
242
+ connect();
243
+ function _emit() {
244
+ if (self.listeners(arguments[0]).length > 0) {
245
+ self.emit.apply(self, arguments);
246
+ }
247
+ }
248
+ this._close = function() {
249
+ if (readyState === EventSource.CLOSED) return;
250
+ readyState = EventSource.CLOSED;
251
+ if (req.abort) req.abort();
252
+ if (req.xhr && req.xhr.abort) req.xhr.abort();
253
+ };
254
+ function parseEventStreamLine(buf, pos, fieldLength, lineLength) {
255
+ if (lineLength === 0) {
256
+ if (data.length > 0) {
257
+ var type = eventName || "message";
258
+ _emit(type, new MessageEvent(type, {
259
+ data: data.slice(0, -1),
260
+ // remove trailing newline
261
+ lastEventId,
262
+ origin: new URL(url).origin
263
+ }));
264
+ data = "";
265
+ }
266
+ eventName = void 0;
267
+ } else if (fieldLength > 0) {
268
+ var noValue = fieldLength < 0;
269
+ var step = 0;
270
+ var field = buf.slice(pos, pos + (noValue ? lineLength : fieldLength)).toString();
271
+ if (noValue) {
272
+ step = lineLength;
273
+ } else if (buf[pos + fieldLength + 1] !== space) {
274
+ step = fieldLength + 1;
275
+ } else {
276
+ step = fieldLength + 2;
277
+ }
278
+ pos += step;
279
+ var valueLength = lineLength - step;
280
+ var value = buf.slice(pos, pos + valueLength).toString();
281
+ if (field === "data") {
282
+ data += value + "\n";
283
+ } else if (field === "event") {
284
+ eventName = value;
285
+ } else if (field === "id") {
286
+ lastEventId = value;
287
+ } else if (field === "retry") {
288
+ var retry = parseInt(value, 10);
289
+ if (!Number.isNaN(retry)) {
290
+ self.reconnectInterval = retry;
291
+ }
292
+ }
293
+ }
294
+ }
295
+ }
296
+ module.exports = EventSource;
297
+ util.inherits(EventSource, events.EventEmitter);
298
+ EventSource.prototype.constructor = EventSource;
299
+ ["open", "error", "message"].forEach(function(method) {
300
+ Object.defineProperty(EventSource.prototype, "on" + method, {
301
+ /**
302
+ * Returns the current listener
303
+ *
304
+ * @return {Mixed} the set function or undefined
305
+ * @api private
306
+ */
307
+ get: function get() {
308
+ var listener = this.listeners(method)[0];
309
+ return listener ? listener._listener ? listener._listener : listener : void 0;
310
+ },
311
+ /**
312
+ * Start listening for events
313
+ *
314
+ * @param {Function} listener the listener
315
+ * @return {Mixed} the set function or undefined
316
+ * @api private
317
+ */
318
+ set: function set(listener) {
319
+ this.removeAllListeners(method);
320
+ this.addEventListener(method, listener);
321
+ }
322
+ });
323
+ });
324
+ Object.defineProperty(EventSource, "CONNECTING", { enumerable: true, value: 0 });
325
+ Object.defineProperty(EventSource, "OPEN", { enumerable: true, value: 1 });
326
+ Object.defineProperty(EventSource, "CLOSED", { enumerable: true, value: 2 });
327
+ EventSource.prototype.CONNECTING = 0;
328
+ EventSource.prototype.OPEN = 1;
329
+ EventSource.prototype.CLOSED = 2;
330
+ EventSource.prototype.close = function() {
331
+ this._close();
332
+ };
333
+ EventSource.prototype.addEventListener = function addEventListener(type, listener) {
334
+ if (typeof listener === "function") {
335
+ listener._listener = listener;
336
+ this.on(type, listener);
337
+ }
338
+ };
339
+ EventSource.prototype.dispatchEvent = function dispatchEvent(event) {
340
+ if (!event.type) {
341
+ throw new Error("UNSPECIFIED_EVENT_TYPE_ERR");
342
+ }
343
+ this.emit(event.type, event.detail);
344
+ };
345
+ EventSource.prototype.removeEventListener = function removeEventListener(type, listener) {
346
+ if (typeof listener === "function") {
347
+ listener._listener = void 0;
348
+ this.removeListener(type, listener);
349
+ }
350
+ };
351
+ function Event(type, optionalProperties) {
352
+ Object.defineProperty(this, "type", { writable: false, value: type, enumerable: true });
353
+ if (optionalProperties) {
354
+ for (var f in optionalProperties) {
355
+ if (optionalProperties.hasOwnProperty(f)) {
356
+ Object.defineProperty(this, f, { writable: false, value: optionalProperties[f], enumerable: true });
357
+ }
358
+ }
359
+ }
360
+ }
361
+ function MessageEvent(type, eventInitDict) {
362
+ Object.defineProperty(this, "type", { writable: false, value: type, enumerable: true });
363
+ for (var f in eventInitDict) {
364
+ if (eventInitDict.hasOwnProperty(f)) {
365
+ Object.defineProperty(this, f, { writable: false, value: eventInitDict[f], enumerable: true });
366
+ }
367
+ }
368
+ }
369
+ function removeUnsafeHeaders(headers) {
370
+ var safe = {};
371
+ for (var key in headers) {
372
+ if (reUnsafeHeader.test(key)) {
373
+ continue;
374
+ }
375
+ safe[key] = headers[key];
376
+ }
377
+ return safe;
378
+ }
379
+ }
380
+ });
381
+ export default require_eventsource();
382
+ //# sourceMappingURL=eventsource-TFSNWQMS.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../node_modules/eventsource/lib/eventsource.js"],"sourcesContent":["var parse = require('url').parse\nvar events = require('events')\nvar https = require('https')\nvar http = require('http')\nvar util = require('util')\n\nvar httpsOptions = [\n 'pfx', 'key', 'passphrase', 'cert', 'ca', 'ciphers',\n 'rejectUnauthorized', 'secureProtocol', 'servername', 'checkServerIdentity'\n]\n\nvar bom = [239, 187, 191]\nvar colon = 58\nvar space = 32\nvar lineFeed = 10\nvar carriageReturn = 13\n// Beyond 256KB we could not observe any gain in performance\nvar maxBufferAheadAllocation = 1024 * 256\n// Headers matching the pattern should be removed when redirecting to different origin\nvar reUnsafeHeader = /^(cookie|authorization)$/i\n\nfunction hasBom (buf) {\n return bom.every(function (charCode, index) {\n return buf[index] === charCode\n })\n}\n\n/**\n * Creates a new EventSource object\n *\n * @param {String} url the URL to which to connect\n * @param {Object} [eventSourceInitDict] extra init params. See README for details.\n * @api public\n **/\nfunction EventSource (url, eventSourceInitDict) {\n var readyState = EventSource.CONNECTING\n var headers = eventSourceInitDict && eventSourceInitDict.headers\n var hasNewOrigin = false\n Object.defineProperty(this, 'readyState', {\n get: function () {\n return readyState\n }\n })\n\n Object.defineProperty(this, 'url', {\n get: function () {\n return url\n }\n })\n\n var self = this\n self.reconnectInterval = 1000\n self.connectionInProgress = false\n\n function onConnectionClosed (message) {\n if (readyState === EventSource.CLOSED) return\n readyState = EventSource.CONNECTING\n _emit('error', new Event('error', {message: message}))\n\n // The url may have been changed by a temporary redirect. If that's the case,\n // revert it now, and flag that we are no longer pointing to a new origin\n if (reconnectUrl) {\n url = reconnectUrl\n reconnectUrl = null\n hasNewOrigin = false\n }\n setTimeout(function () {\n if (readyState !== EventSource.CONNECTING || self.connectionInProgress) {\n return\n }\n self.connectionInProgress = true\n connect()\n }, self.reconnectInterval)\n }\n\n var req\n var lastEventId = ''\n if (headers && headers['Last-Event-ID']) {\n lastEventId = headers['Last-Event-ID']\n delete headers['Last-Event-ID']\n }\n\n var discardTrailingNewline = false\n var data = ''\n var eventName = ''\n\n var reconnectUrl = null\n\n function connect () {\n var options = parse(url)\n var isSecure = options.protocol === 'https:'\n options.headers = { 'Cache-Control': 'no-cache', 'Accept': 'text/event-stream' }\n if (lastEventId) options.headers['Last-Event-ID'] = lastEventId\n if (headers) {\n var reqHeaders = hasNewOrigin ? removeUnsafeHeaders(headers) : headers\n for (var i in reqHeaders) {\n var header = reqHeaders[i]\n if (header) {\n options.headers[i] = header\n }\n }\n }\n\n // Legacy: this should be specified as `eventSourceInitDict.https.rejectUnauthorized`,\n // but for now exists as a backwards-compatibility layer\n options.rejectUnauthorized = !(eventSourceInitDict && !eventSourceInitDict.rejectUnauthorized)\n\n if (eventSourceInitDict && eventSourceInitDict.createConnection !== undefined) {\n options.createConnection = eventSourceInitDict.createConnection\n }\n\n // If specify http proxy, make the request to sent to the proxy server,\n // and include the original url in path and Host headers\n var useProxy = eventSourceInitDict && eventSourceInitDict.proxy\n if (useProxy) {\n var proxy = parse(eventSourceInitDict.proxy)\n isSecure = proxy.protocol === 'https:'\n\n options.protocol = isSecure ? 'https:' : 'http:'\n options.path = url\n options.headers.Host = options.host\n options.hostname = proxy.hostname\n options.host = proxy.host\n options.port = proxy.port\n }\n\n // If https options are specified, merge them into the request options\n if (eventSourceInitDict && eventSourceInitDict.https) {\n for (var optName in eventSourceInitDict.https) {\n if (httpsOptions.indexOf(optName) === -1) {\n continue\n }\n\n var option = eventSourceInitDict.https[optName]\n if (option !== undefined) {\n options[optName] = option\n }\n }\n }\n\n // Pass this on to the XHR\n if (eventSourceInitDict && eventSourceInitDict.withCredentials !== undefined) {\n options.withCredentials = eventSourceInitDict.withCredentials\n }\n\n req = (isSecure ? https : http).request(options, function (res) {\n self.connectionInProgress = false\n // Handle HTTP errors\n if (res.statusCode === 500 || res.statusCode === 502 || res.statusCode === 503 || res.statusCode === 504) {\n _emit('error', new Event('error', {status: res.statusCode, message: res.statusMessage}))\n onConnectionClosed()\n return\n }\n\n // Handle HTTP redirects\n if (res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307) {\n var location = res.headers.location\n if (!location) {\n // Server sent redirect response without Location header.\n _emit('error', new Event('error', {status: res.statusCode, message: res.statusMessage}))\n return\n }\n var prevOrigin = new URL(url).origin\n var nextOrigin = new URL(location).origin\n hasNewOrigin = prevOrigin !== nextOrigin\n if (res.statusCode === 307) reconnectUrl = url\n url = location\n process.nextTick(connect)\n return\n }\n\n if (res.statusCode !== 200) {\n _emit('error', new Event('error', {status: res.statusCode, message: res.statusMessage}))\n return self.close()\n }\n\n readyState = EventSource.OPEN\n res.on('close', function () {\n res.removeAllListeners('close')\n res.removeAllListeners('end')\n onConnectionClosed()\n })\n\n res.on('end', function () {\n res.removeAllListeners('close')\n res.removeAllListeners('end')\n onConnectionClosed()\n })\n _emit('open', new Event('open'))\n\n // text/event-stream parser adapted from webkit's\n // Source/WebCore/page/EventSource.cpp\n var buf\n var newBuffer\n var startingPos = 0\n var startingFieldLength = -1\n var newBufferSize = 0\n var bytesUsed = 0\n\n res.on('data', function (chunk) {\n if (!buf) {\n buf = chunk\n if (hasBom(buf)) {\n buf = buf.slice(bom.length)\n }\n bytesUsed = buf.length\n } else {\n if (chunk.length > buf.length - bytesUsed) {\n newBufferSize = (buf.length * 2) + chunk.length\n if (newBufferSize > maxBufferAheadAllocation) {\n newBufferSize = buf.length + chunk.length + maxBufferAheadAllocation\n }\n newBuffer = Buffer.alloc(newBufferSize)\n buf.copy(newBuffer, 0, 0, bytesUsed)\n buf = newBuffer\n }\n chunk.copy(buf, bytesUsed)\n bytesUsed += chunk.length\n }\n\n var pos = 0\n var length = bytesUsed\n\n while (pos < length) {\n if (discardTrailingNewline) {\n if (buf[pos] === lineFeed) {\n ++pos\n }\n discardTrailingNewline = false\n }\n\n var lineLength = -1\n var fieldLength = startingFieldLength\n var c\n\n for (var i = startingPos; lineLength < 0 && i < length; ++i) {\n c = buf[i]\n if (c === colon) {\n if (fieldLength < 0) {\n fieldLength = i - pos\n }\n } else if (c === carriageReturn) {\n discardTrailingNewline = true\n lineLength = i - pos\n } else if (c === lineFeed) {\n lineLength = i - pos\n }\n }\n\n if (lineLength < 0) {\n startingPos = length - pos\n startingFieldLength = fieldLength\n break\n } else {\n startingPos = 0\n startingFieldLength = -1\n }\n\n parseEventStreamLine(buf, pos, fieldLength, lineLength)\n\n pos += lineLength + 1\n }\n\n if (pos === length) {\n buf = void 0\n bytesUsed = 0\n } else if (pos > 0) {\n buf = buf.slice(pos, bytesUsed)\n bytesUsed = buf.length\n }\n })\n })\n\n req.on('error', function (err) {\n self.connectionInProgress = false\n onConnectionClosed(err.message)\n })\n\n if (req.setNoDelay) req.setNoDelay(true)\n req.end()\n }\n\n connect()\n\n function _emit () {\n if (self.listeners(arguments[0]).length > 0) {\n self.emit.apply(self, arguments)\n }\n }\n\n this._close = function () {\n if (readyState === EventSource.CLOSED) return\n readyState = EventSource.CLOSED\n if (req.abort) req.abort()\n if (req.xhr && req.xhr.abort) req.xhr.abort()\n }\n\n function parseEventStreamLine (buf, pos, fieldLength, lineLength) {\n if (lineLength === 0) {\n if (data.length > 0) {\n var type = eventName || 'message'\n _emit(type, new MessageEvent(type, {\n data: data.slice(0, -1), // remove trailing newline\n lastEventId: lastEventId,\n origin: new URL(url).origin\n }))\n data = ''\n }\n eventName = void 0\n } else if (fieldLength > 0) {\n var noValue = fieldLength < 0\n var step = 0\n var field = buf.slice(pos, pos + (noValue ? lineLength : fieldLength)).toString()\n\n if (noValue) {\n step = lineLength\n } else if (buf[pos + fieldLength + 1] !== space) {\n step = fieldLength + 1\n } else {\n step = fieldLength + 2\n }\n pos += step\n\n var valueLength = lineLength - step\n var value = buf.slice(pos, pos + valueLength).toString()\n\n if (field === 'data') {\n data += value + '\\n'\n } else if (field === 'event') {\n eventName = value\n } else if (field === 'id') {\n lastEventId = value\n } else if (field === 'retry') {\n var retry = parseInt(value, 10)\n if (!Number.isNaN(retry)) {\n self.reconnectInterval = retry\n }\n }\n }\n }\n}\n\nmodule.exports = EventSource\n\nutil.inherits(EventSource, events.EventEmitter)\nEventSource.prototype.constructor = EventSource; // make stacktraces readable\n\n['open', 'error', 'message'].forEach(function (method) {\n Object.defineProperty(EventSource.prototype, 'on' + method, {\n /**\n * Returns the current listener\n *\n * @return {Mixed} the set function or undefined\n * @api private\n */\n get: function get () {\n var listener = this.listeners(method)[0]\n return listener ? (listener._listener ? listener._listener : listener) : undefined\n },\n\n /**\n * Start listening for events\n *\n * @param {Function} listener the listener\n * @return {Mixed} the set function or undefined\n * @api private\n */\n set: function set (listener) {\n this.removeAllListeners(method)\n this.addEventListener(method, listener)\n }\n })\n})\n\n/**\n * Ready states\n */\nObject.defineProperty(EventSource, 'CONNECTING', {enumerable: true, value: 0})\nObject.defineProperty(EventSource, 'OPEN', {enumerable: true, value: 1})\nObject.defineProperty(EventSource, 'CLOSED', {enumerable: true, value: 2})\n\nEventSource.prototype.CONNECTING = 0\nEventSource.prototype.OPEN = 1\nEventSource.prototype.CLOSED = 2\n\n/**\n * Closes the connection, if one is made, and sets the readyState attribute to 2 (closed)\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/EventSource/close\n * @api public\n */\nEventSource.prototype.close = function () {\n this._close()\n}\n\n/**\n * Emulates the W3C Browser based WebSocket interface using addEventListener.\n *\n * @param {String} type A string representing the event type to listen out for\n * @param {Function} listener callback\n * @see https://developer.mozilla.org/en/DOM/element.addEventListener\n * @see http://dev.w3.org/html5/websockets/#the-websocket-interface\n * @api public\n */\nEventSource.prototype.addEventListener = function addEventListener (type, listener) {\n if (typeof listener === 'function') {\n // store a reference so we can return the original function again\n listener._listener = listener\n this.on(type, listener)\n }\n}\n\n/**\n * Emulates the W3C Browser based WebSocket interface using dispatchEvent.\n *\n * @param {Event} event An event to be dispatched\n * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent\n * @api public\n */\nEventSource.prototype.dispatchEvent = function dispatchEvent (event) {\n if (!event.type) {\n throw new Error('UNSPECIFIED_EVENT_TYPE_ERR')\n }\n // if event is instance of an CustomEvent (or has 'details' property),\n // send the detail object as the payload for the event\n this.emit(event.type, event.detail)\n}\n\n/**\n * Emulates the W3C Browser based WebSocket interface using removeEventListener.\n *\n * @param {String} type A string representing the event type to remove\n * @param {Function} listener callback\n * @see https://developer.mozilla.org/en/DOM/element.removeEventListener\n * @see http://dev.w3.org/html5/websockets/#the-websocket-interface\n * @api public\n */\nEventSource.prototype.removeEventListener = function removeEventListener (type, listener) {\n if (typeof listener === 'function') {\n listener._listener = undefined\n this.removeListener(type, listener)\n }\n}\n\n/**\n * W3C Event\n *\n * @see http://www.w3.org/TR/DOM-Level-3-Events/#interface-Event\n * @api private\n */\nfunction Event (type, optionalProperties) {\n Object.defineProperty(this, 'type', { writable: false, value: type, enumerable: true })\n if (optionalProperties) {\n for (var f in optionalProperties) {\n if (optionalProperties.hasOwnProperty(f)) {\n Object.defineProperty(this, f, { writable: false, value: optionalProperties[f], enumerable: true })\n }\n }\n }\n}\n\n/**\n * W3C MessageEvent\n *\n * @see http://www.w3.org/TR/webmessaging/#event-definitions\n * @api private\n */\nfunction MessageEvent (type, eventInitDict) {\n Object.defineProperty(this, 'type', { writable: false, value: type, enumerable: true })\n for (var f in eventInitDict) {\n if (eventInitDict.hasOwnProperty(f)) {\n Object.defineProperty(this, f, { writable: false, value: eventInitDict[f], enumerable: true })\n }\n }\n}\n\n/**\n * Returns a new object of headers that does not include any authorization and cookie headers\n *\n * @param {Object} headers An object of headers ({[headerName]: headerValue})\n * @return {Object} a new object of headers\n * @api private\n */\nfunction removeUnsafeHeaders (headers) {\n var safe = {}\n for (var key in headers) {\n if (reUnsafeHeader.test(key)) {\n continue\n }\n\n safe[key] = headers[key]\n }\n\n return safe\n}\n"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA,QAAI,QAAQ,UAAQ,KAAK,EA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AAG,YAAY,KAAK,CAAC;AAAA,UACpG;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAQA,aAAS,aAAc,MAAM,eAAe;AAC1C,aAAO,eAAe,MAAM,QAAQ,EAAE,UAAU,OAAO,OAAO,MAAM,YAAY,KAAK,CAAC;AACtF,eAAS,KAAK,eAAe;AAC3B,YAAI,cAAc,eAAe,CAAC,GAAG;AACnC,iBAAO,eAAe,MAAM,GAAG,EAAE,UAAU,OAAO,OAAO,cAAc,CAAC,GAAG,YAAY,KAAK,CAAC;AAAA,QAC/F;AAAA,MACF;AAAA,IACF;AASA,aAAS,oBAAqB,SAAS;AACrC,UAAI,OAAO,CAAC;AACZ,eAAS,OAAO,SAAS;AACvB,YAAI,eAAe,KAAK,GAAG,GAAG;AAC5B;AAAA,QACF;AAEA,aAAK,GAAG,IAAI,QAAQ,GAAG;AAAA,MACzB;AAEA,aAAO;AAAA,IACT;AAAA;AAAA;","names":["i"]}
@@ -0,0 +1,250 @@
1
+ /**
2
+ * Core Types for Olbrain JavaScript SDK
3
+ * Matches Python SDK data models for consistency
4
+ */
5
+ /**
6
+ * Configuration for AgentClient
7
+ */
8
+ interface AgentConfig {
9
+ agentId: string;
10
+ apiKey: string;
11
+ baseUrl?: string;
12
+ }
13
+ /**
14
+ * Options for creating a new session
15
+ */
16
+ interface CreateSessionOptions {
17
+ title?: string;
18
+ userId?: string;
19
+ metadata?: Record<string, any>;
20
+ }
21
+ /**
22
+ * Options for updating a session
23
+ */
24
+ interface SessionUpdates {
25
+ title?: string;
26
+ metadata?: Record<string, any>;
27
+ status?: 'active' | 'archived';
28
+ }
29
+ /**
30
+ * Options for sending messages
31
+ */
32
+ interface SendOptions {
33
+ metadata?: Record<string, any>;
34
+ timeout?: number;
35
+ }
36
+ /**
37
+ * Token usage statistics
38
+ */
39
+ interface TokenUsage {
40
+ promptTokens: number;
41
+ completionTokens: number;
42
+ totalTokens: number;
43
+ cost?: number;
44
+ }
45
+ /**
46
+ * Session information
47
+ */
48
+ interface SessionInfo {
49
+ sessionId: string;
50
+ title: string;
51
+ status: 'active' | 'archived';
52
+ createdAt: string;
53
+ messageCount: number;
54
+ userId?: string;
55
+ metadata: Record<string, any>;
56
+ }
57
+ /**
58
+ * Session statistics
59
+ */
60
+ interface SessionStats {
61
+ sessionId: string;
62
+ messageCount: number;
63
+ totalTokens: number;
64
+ createdAt: string;
65
+ lastMessageAt?: string;
66
+ }
67
+ /**
68
+ * Chat response from the agent
69
+ */
70
+ interface ChatResponse {
71
+ text: string;
72
+ sessionId: string;
73
+ success: boolean;
74
+ tokenUsage?: TokenUsage;
75
+ modelUsed?: string;
76
+ responseTimeMs?: number;
77
+ error?: string;
78
+ }
79
+ /**
80
+ * Message in a conversation
81
+ */
82
+ interface Message {
83
+ role: 'user' | 'assistant';
84
+ content: string;
85
+ timestamp: string;
86
+ metadata?: Record<string, any>;
87
+ }
88
+ /**
89
+ * Callback for message events
90
+ */
91
+ type MessageCallback = (message: Message) => void;
92
+ /**
93
+ * Callback for error events
94
+ */
95
+ type ErrorCallback = (error: Error) => void;
96
+ /**
97
+ * Configuration for streaming
98
+ */
99
+ interface StreamConfig {
100
+ sessionId: string;
101
+ apiKey: string;
102
+ agentId: string;
103
+ baseUrl: string;
104
+ }
105
+ /**
106
+ * Widget configuration
107
+ */
108
+ interface WidgetConfig {
109
+ agentId: string;
110
+ apiKey: string;
111
+ position?: 'bottom-right' | 'bottom-left' | 'custom';
112
+ theme?: 'light' | 'dark' | 'auto';
113
+ primaryColor?: string;
114
+ title?: string;
115
+ greeting?: string;
116
+ placeholder?: string;
117
+ autoOpen?: boolean;
118
+ persistSession?: boolean;
119
+ target?: string | HTMLElement;
120
+ onMessage?: MessageCallback;
121
+ baseUrl?: string;
122
+ }
123
+
124
+ /**
125
+ * Main AgentClient class for communicating with Olbrain agents
126
+ */
127
+
128
+ /**
129
+ * Main API client for interacting with Olbrain agents
130
+ */
131
+ declare class AgentClient {
132
+ private config;
133
+ private streamManager;
134
+ constructor(config: AgentConfig);
135
+ /**
136
+ * Create a new session
137
+ */
138
+ createSession(options?: CreateSessionOptions): Promise<string>;
139
+ /**
140
+ * Get session information
141
+ * @note May not be implemented on all backends
142
+ */
143
+ getSession(sessionId: string): Promise<SessionInfo>;
144
+ /**
145
+ * Update session information
146
+ * @note May not be implemented on all backends
147
+ */
148
+ updateSession(sessionId: string, updates: SessionUpdates): Promise<SessionInfo>;
149
+ /**
150
+ * Delete a session
151
+ * @note May not be implemented on all backends
152
+ */
153
+ deleteSession(sessionId: string): Promise<void>;
154
+ /**
155
+ * Get messages from a session
156
+ * @note May not be implemented on all backends
157
+ */
158
+ getMessages(sessionId: string, limit?: number): Promise<Message[]>;
159
+ /**
160
+ * Get session statistics
161
+ * @note May not be implemented on all backends
162
+ */
163
+ getSessionStats(sessionId: string): Promise<SessionStats>;
164
+ /**
165
+ * Send a message and wait for response
166
+ */
167
+ sendAndWait(sessionId: string, message: string, options?: SendOptions): Promise<ChatResponse>;
168
+ /**
169
+ * Send a message (fire and forget)
170
+ */
171
+ send(sessionId: string, message: string): Promise<void>;
172
+ /**
173
+ * Start listening for messages via SSE streaming
174
+ */
175
+ listen(sessionId: string, onMessage: MessageCallback, onError?: ErrorCallback): Promise<void>;
176
+ /**
177
+ * Stop listening for messages
178
+ */
179
+ stopListening(sessionId: string): void;
180
+ /**
181
+ * Close client and clean up resources
182
+ */
183
+ close(): void;
184
+ /**
185
+ * Helper method to make HTTP requests
186
+ */
187
+ private _request;
188
+ /**
189
+ * Helper to parse session info from response
190
+ */
191
+ private _parseSessionInfo;
192
+ }
193
+
194
+ /**
195
+ * Error classes for Olbrain SDK
196
+ */
197
+ /**
198
+ * Base error class for all Olbrain errors
199
+ */
200
+ declare class OlbrainError extends Error {
201
+ constructor(message: string);
202
+ }
203
+ /**
204
+ * Raised when authentication fails (invalid API key, missing auth header, etc.)
205
+ */
206
+ declare class AuthenticationError extends OlbrainError {
207
+ constructor(message?: string);
208
+ }
209
+ /**
210
+ * Raised when a session is not found
211
+ */
212
+ declare class SessionNotFoundError extends OlbrainError {
213
+ sessionId: string;
214
+ constructor(sessionId: string);
215
+ }
216
+ /**
217
+ * Raised when rate limit is exceeded
218
+ */
219
+ declare class RateLimitError extends OlbrainError {
220
+ retryAfter?: number;
221
+ constructor(message?: string, retryAfter?: number);
222
+ }
223
+ /**
224
+ * Raised when a network error occurs
225
+ */
226
+ declare class NetworkError extends OlbrainError {
227
+ statusCode?: number;
228
+ constructor(message?: string, statusCode?: number);
229
+ }
230
+ /**
231
+ * Raised when input validation fails
232
+ */
233
+ declare class ValidationError extends OlbrainError {
234
+ constructor(message?: string);
235
+ }
236
+ /**
237
+ * Raised when streaming connection fails
238
+ */
239
+ declare class StreamingError extends OlbrainError {
240
+ constructor(message?: string);
241
+ }
242
+
243
+ /**
244
+ * Olbrain JavaScript SDK
245
+ * Main entry point for core API exports
246
+ */
247
+
248
+ declare const VERSION = "1.0.0";
249
+
250
+ export { AgentClient, type AgentConfig, AuthenticationError, type ChatResponse, type CreateSessionOptions, type ErrorCallback, type Message, type MessageCallback, NetworkError, OlbrainError, RateLimitError, type SendOptions, type SessionInfo, SessionNotFoundError, type SessionStats, type SessionUpdates, type StreamConfig, StreamingError, type TokenUsage, VERSION, ValidationError, type WidgetConfig };