@elsium-ai/app 0.1.7 → 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.
package/dist/app.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,OAAO,EAAW,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EAAE,KAAK,MAAM,EAAW,MAAM,oBAAoB,CAAA;AAGzD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAG3B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExC,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;IACnB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,IAAI,CAAA;KAAE,CAAA;CACzD;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,CA8FtD"}
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,OAAO,EAAW,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EAAE,KAAK,MAAM,EAAW,MAAM,oBAAoB,CAAA;AAIzD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAG3B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExC,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;IACnB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,IAAI,CAAA;KAAE,CAAA;CACzD;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,CA8FtD"}
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
- // @bun
2
1
  // ../core/src/errors.ts
3
2
  class ElsiumError extends Error {
4
3
  code;
@@ -89,7 +88,7 @@ class ElsiumError extends Error {
89
88
  }
90
89
  }
91
90
  // ../core/src/utils.ts
92
- import { randomBytes } from "crypto";
91
+ import { randomBytes } from "node:crypto";
93
92
  function cryptoHex(bytes) {
94
93
  return randomBytes(bytes).toString("hex");
95
94
  }
@@ -559,7 +558,7 @@ function resolveModelName(model) {
559
558
  function calculateCost(model, usage) {
560
559
  const pricing = PRICING[resolveModelName(model)];
561
560
  if (!pricing) {
562
- log.warn(`Unknown model "${model}" \u2014 cost will be reported as $0. Register pricing with registerPricing().`);
561
+ log.warn(`Unknown model "${model}" cost will be reported as $0. Register pricing with registerPricing().`);
563
562
  return {
564
563
  inputCost: 0,
565
564
  outputCost: 0,
@@ -1978,6 +1977,540 @@ function createNoopSpan(name, kind) {
1978
1977
  }
1979
1978
  // ../observe/src/otel.ts
1980
1979
  var log3 = createLogger();
1980
+ // ../../node_modules/.bun/@hono+node-server@1.19.9/node_modules/@hono/node-server/dist/index.mjs
1981
+ import { createServer as createServerHTTP } from "http";
1982
+ import { Http2ServerRequest as Http2ServerRequest2 } from "http2";
1983
+ import { Http2ServerRequest } from "http2";
1984
+ import { Readable } from "stream";
1985
+ import crypto from "crypto";
1986
+ var RequestError = class extends Error {
1987
+ constructor(message, options) {
1988
+ super(message, options);
1989
+ this.name = "RequestError";
1990
+ }
1991
+ };
1992
+ var toRequestError = (e) => {
1993
+ if (e instanceof RequestError) {
1994
+ return e;
1995
+ }
1996
+ return new RequestError(e.message, { cause: e });
1997
+ };
1998
+ var GlobalRequest = global.Request;
1999
+ var Request2 = class extends GlobalRequest {
2000
+ constructor(input, options) {
2001
+ if (typeof input === "object" && getRequestCache in input) {
2002
+ input = input[getRequestCache]();
2003
+ }
2004
+ if (typeof options?.body?.getReader !== "undefined") {
2005
+ options.duplex ??= "half";
2006
+ }
2007
+ super(input, options);
2008
+ }
2009
+ };
2010
+ var newHeadersFromIncoming = (incoming) => {
2011
+ const headerRecord = [];
2012
+ const rawHeaders = incoming.rawHeaders;
2013
+ for (let i = 0;i < rawHeaders.length; i += 2) {
2014
+ const { [i]: key, [i + 1]: value } = rawHeaders;
2015
+ if (key.charCodeAt(0) !== 58) {
2016
+ headerRecord.push([key, value]);
2017
+ }
2018
+ }
2019
+ return new Headers(headerRecord);
2020
+ };
2021
+ var wrapBodyStream = Symbol("wrapBodyStream");
2022
+ var newRequestFromIncoming = (method, url, headers, incoming, abortController) => {
2023
+ const init = {
2024
+ method,
2025
+ headers,
2026
+ signal: abortController.signal
2027
+ };
2028
+ if (method === "TRACE") {
2029
+ init.method = "GET";
2030
+ const req = new Request2(url, init);
2031
+ Object.defineProperty(req, "method", {
2032
+ get() {
2033
+ return "TRACE";
2034
+ }
2035
+ });
2036
+ return req;
2037
+ }
2038
+ if (!(method === "GET" || method === "HEAD")) {
2039
+ if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) {
2040
+ init.body = new ReadableStream({
2041
+ start(controller) {
2042
+ controller.enqueue(incoming.rawBody);
2043
+ controller.close();
2044
+ }
2045
+ });
2046
+ } else if (incoming[wrapBodyStream]) {
2047
+ let reader;
2048
+ init.body = new ReadableStream({
2049
+ async pull(controller) {
2050
+ try {
2051
+ reader ||= Readable.toWeb(incoming).getReader();
2052
+ const { done, value } = await reader.read();
2053
+ if (done) {
2054
+ controller.close();
2055
+ } else {
2056
+ controller.enqueue(value);
2057
+ }
2058
+ } catch (error) {
2059
+ controller.error(error);
2060
+ }
2061
+ }
2062
+ });
2063
+ } else {
2064
+ init.body = Readable.toWeb(incoming);
2065
+ }
2066
+ }
2067
+ return new Request2(url, init);
2068
+ };
2069
+ var getRequestCache = Symbol("getRequestCache");
2070
+ var requestCache = Symbol("requestCache");
2071
+ var incomingKey = Symbol("incomingKey");
2072
+ var urlKey = Symbol("urlKey");
2073
+ var headersKey = Symbol("headersKey");
2074
+ var abortControllerKey = Symbol("abortControllerKey");
2075
+ var getAbortController = Symbol("getAbortController");
2076
+ var requestPrototype = {
2077
+ get method() {
2078
+ return this[incomingKey].method || "GET";
2079
+ },
2080
+ get url() {
2081
+ return this[urlKey];
2082
+ },
2083
+ get headers() {
2084
+ return this[headersKey] ||= newHeadersFromIncoming(this[incomingKey]);
2085
+ },
2086
+ [getAbortController]() {
2087
+ this[getRequestCache]();
2088
+ return this[abortControllerKey];
2089
+ },
2090
+ [getRequestCache]() {
2091
+ this[abortControllerKey] ||= new AbortController;
2092
+ return this[requestCache] ||= newRequestFromIncoming(this.method, this[urlKey], this.headers, this[incomingKey], this[abortControllerKey]);
2093
+ }
2094
+ };
2095
+ [
2096
+ "body",
2097
+ "bodyUsed",
2098
+ "cache",
2099
+ "credentials",
2100
+ "destination",
2101
+ "integrity",
2102
+ "mode",
2103
+ "redirect",
2104
+ "referrer",
2105
+ "referrerPolicy",
2106
+ "signal",
2107
+ "keepalive"
2108
+ ].forEach((k) => {
2109
+ Object.defineProperty(requestPrototype, k, {
2110
+ get() {
2111
+ return this[getRequestCache]()[k];
2112
+ }
2113
+ });
2114
+ });
2115
+ ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
2116
+ Object.defineProperty(requestPrototype, k, {
2117
+ value: function() {
2118
+ return this[getRequestCache]()[k]();
2119
+ }
2120
+ });
2121
+ });
2122
+ Object.setPrototypeOf(requestPrototype, Request2.prototype);
2123
+ var newRequest = (incoming, defaultHostname) => {
2124
+ const req = Object.create(requestPrototype);
2125
+ req[incomingKey] = incoming;
2126
+ const incomingUrl = incoming.url || "";
2127
+ if (incomingUrl[0] !== "/" && (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
2128
+ if (incoming instanceof Http2ServerRequest) {
2129
+ throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
2130
+ }
2131
+ try {
2132
+ const url2 = new URL(incomingUrl);
2133
+ req[urlKey] = url2.href;
2134
+ } catch (e) {
2135
+ throw new RequestError("Invalid absolute URL", { cause: e });
2136
+ }
2137
+ return req;
2138
+ }
2139
+ const host = (incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
2140
+ if (!host) {
2141
+ throw new RequestError("Missing host header");
2142
+ }
2143
+ let scheme;
2144
+ if (incoming instanceof Http2ServerRequest) {
2145
+ scheme = incoming.scheme;
2146
+ if (!(scheme === "http" || scheme === "https")) {
2147
+ throw new RequestError("Unsupported scheme");
2148
+ }
2149
+ } else {
2150
+ scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
2151
+ }
2152
+ const url = new URL(`${scheme}://${host}${incomingUrl}`);
2153
+ if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
2154
+ throw new RequestError("Invalid host header");
2155
+ }
2156
+ req[urlKey] = url.href;
2157
+ return req;
2158
+ };
2159
+ var responseCache = Symbol("responseCache");
2160
+ var getResponseCache = Symbol("getResponseCache");
2161
+ var cacheKey = Symbol("cache");
2162
+ var GlobalResponse = global.Response;
2163
+ var Response2 = class _Response {
2164
+ #body;
2165
+ #init;
2166
+ [getResponseCache]() {
2167
+ delete this[cacheKey];
2168
+ return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
2169
+ }
2170
+ constructor(body, init) {
2171
+ let headers;
2172
+ this.#body = body;
2173
+ if (init instanceof _Response) {
2174
+ const cachedGlobalResponse = init[responseCache];
2175
+ if (cachedGlobalResponse) {
2176
+ this.#init = cachedGlobalResponse;
2177
+ this[getResponseCache]();
2178
+ return;
2179
+ } else {
2180
+ this.#init = init.#init;
2181
+ headers = new Headers(init.#init.headers);
2182
+ }
2183
+ } else {
2184
+ this.#init = init;
2185
+ }
2186
+ if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
2187
+ headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
2188
+ this[cacheKey] = [init?.status || 200, body, headers];
2189
+ }
2190
+ }
2191
+ get headers() {
2192
+ const cache = this[cacheKey];
2193
+ if (cache) {
2194
+ if (!(cache[2] instanceof Headers)) {
2195
+ cache[2] = new Headers(cache[2]);
2196
+ }
2197
+ return cache[2];
2198
+ }
2199
+ return this[getResponseCache]().headers;
2200
+ }
2201
+ get status() {
2202
+ return this[cacheKey]?.[0] ?? this[getResponseCache]().status;
2203
+ }
2204
+ get ok() {
2205
+ const status = this.status;
2206
+ return status >= 200 && status < 300;
2207
+ }
2208
+ };
2209
+ ["body", "bodyUsed", "redirected", "statusText", "trailers", "type", "url"].forEach((k) => {
2210
+ Object.defineProperty(Response2.prototype, k, {
2211
+ get() {
2212
+ return this[getResponseCache]()[k];
2213
+ }
2214
+ });
2215
+ });
2216
+ ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
2217
+ Object.defineProperty(Response2.prototype, k, {
2218
+ value: function() {
2219
+ return this[getResponseCache]()[k]();
2220
+ }
2221
+ });
2222
+ });
2223
+ Object.setPrototypeOf(Response2, GlobalResponse);
2224
+ Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
2225
+ async function readWithoutBlocking(readPromise) {
2226
+ return Promise.race([readPromise, Promise.resolve().then(() => Promise.resolve(undefined))]);
2227
+ }
2228
+ function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromise) {
2229
+ const cancel = (error) => {
2230
+ reader.cancel(error).catch(() => {});
2231
+ };
2232
+ writable.on("close", cancel);
2233
+ writable.on("error", cancel);
2234
+ (currentReadPromise ?? reader.read()).then(flow, handleStreamError);
2235
+ return reader.closed.finally(() => {
2236
+ writable.off("close", cancel);
2237
+ writable.off("error", cancel);
2238
+ });
2239
+ function handleStreamError(error) {
2240
+ if (error) {
2241
+ writable.destroy(error);
2242
+ }
2243
+ }
2244
+ function onDrain() {
2245
+ reader.read().then(flow, handleStreamError);
2246
+ }
2247
+ function flow({ done, value }) {
2248
+ try {
2249
+ if (done) {
2250
+ writable.end();
2251
+ } else if (!writable.write(value)) {
2252
+ writable.once("drain", onDrain);
2253
+ } else {
2254
+ return reader.read().then(flow, handleStreamError);
2255
+ }
2256
+ } catch (e) {
2257
+ handleStreamError(e);
2258
+ }
2259
+ }
2260
+ }
2261
+ function writeFromReadableStream(stream, writable) {
2262
+ if (stream.locked) {
2263
+ throw new TypeError("ReadableStream is locked.");
2264
+ } else if (writable.destroyed) {
2265
+ return;
2266
+ }
2267
+ return writeFromReadableStreamDefaultReader(stream.getReader(), writable);
2268
+ }
2269
+ var buildOutgoingHttpHeaders = (headers) => {
2270
+ const res = {};
2271
+ if (!(headers instanceof Headers)) {
2272
+ headers = new Headers(headers ?? undefined);
2273
+ }
2274
+ const cookies = [];
2275
+ for (const [k, v] of headers) {
2276
+ if (k === "set-cookie") {
2277
+ cookies.push(v);
2278
+ } else {
2279
+ res[k] = v;
2280
+ }
2281
+ }
2282
+ if (cookies.length > 0) {
2283
+ res["set-cookie"] = cookies;
2284
+ }
2285
+ res["content-type"] ??= "text/plain; charset=UTF-8";
2286
+ return res;
2287
+ };
2288
+ var X_ALREADY_SENT = "x-hono-already-sent";
2289
+ if (typeof global.crypto === "undefined") {
2290
+ global.crypto = crypto;
2291
+ }
2292
+ var outgoingEnded = Symbol("outgoingEnded");
2293
+ var handleRequestError = () => new Response(null, {
2294
+ status: 400
2295
+ });
2296
+ var handleFetchError = (e) => new Response(null, {
2297
+ status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500
2298
+ });
2299
+ var handleResponseError = (e, outgoing) => {
2300
+ const err2 = e instanceof Error ? e : new Error("unknown error", { cause: e });
2301
+ if (err2.code === "ERR_STREAM_PREMATURE_CLOSE") {
2302
+ console.info("The user aborted a request.");
2303
+ } else {
2304
+ console.error(e);
2305
+ if (!outgoing.headersSent) {
2306
+ outgoing.writeHead(500, { "Content-Type": "text/plain" });
2307
+ }
2308
+ outgoing.end(`Error: ${err2.message}`);
2309
+ outgoing.destroy(err2);
2310
+ }
2311
+ };
2312
+ var flushHeaders = (outgoing) => {
2313
+ if ("flushHeaders" in outgoing && outgoing.writable) {
2314
+ outgoing.flushHeaders();
2315
+ }
2316
+ };
2317
+ var responseViaCache = async (res, outgoing) => {
2318
+ let [status, body, header] = res[cacheKey];
2319
+ if (header instanceof Headers) {
2320
+ header = buildOutgoingHttpHeaders(header);
2321
+ }
2322
+ if (typeof body === "string") {
2323
+ header["Content-Length"] = Buffer.byteLength(body);
2324
+ } else if (body instanceof Uint8Array) {
2325
+ header["Content-Length"] = body.byteLength;
2326
+ } else if (body instanceof Blob) {
2327
+ header["Content-Length"] = body.size;
2328
+ }
2329
+ outgoing.writeHead(status, header);
2330
+ if (typeof body === "string" || body instanceof Uint8Array) {
2331
+ outgoing.end(body);
2332
+ } else if (body instanceof Blob) {
2333
+ outgoing.end(new Uint8Array(await body.arrayBuffer()));
2334
+ } else {
2335
+ flushHeaders(outgoing);
2336
+ await writeFromReadableStream(body, outgoing)?.catch((e) => handleResponseError(e, outgoing));
2337
+ }
2338
+ outgoing[outgoingEnded]?.();
2339
+ };
2340
+ var isPromise = (res) => typeof res.then === "function";
2341
+ var responseViaResponseObject = async (res, outgoing, options = {}) => {
2342
+ if (isPromise(res)) {
2343
+ if (options.errorHandler) {
2344
+ try {
2345
+ res = await res;
2346
+ } catch (err2) {
2347
+ const errRes = await options.errorHandler(err2);
2348
+ if (!errRes) {
2349
+ return;
2350
+ }
2351
+ res = errRes;
2352
+ }
2353
+ } else {
2354
+ res = await res.catch(handleFetchError);
2355
+ }
2356
+ }
2357
+ if (cacheKey in res) {
2358
+ return responseViaCache(res, outgoing);
2359
+ }
2360
+ const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
2361
+ if (res.body) {
2362
+ const reader = res.body.getReader();
2363
+ const values = [];
2364
+ let done = false;
2365
+ let currentReadPromise = undefined;
2366
+ if (resHeaderRecord["transfer-encoding"] !== "chunked") {
2367
+ let maxReadCount = 2;
2368
+ for (let i = 0;i < maxReadCount; i++) {
2369
+ currentReadPromise ||= reader.read();
2370
+ const chunk = await readWithoutBlocking(currentReadPromise).catch((e) => {
2371
+ console.error(e);
2372
+ done = true;
2373
+ });
2374
+ if (!chunk) {
2375
+ if (i === 1) {
2376
+ await new Promise((resolve) => setTimeout(resolve));
2377
+ maxReadCount = 3;
2378
+ continue;
2379
+ }
2380
+ break;
2381
+ }
2382
+ currentReadPromise = undefined;
2383
+ if (chunk.value) {
2384
+ values.push(chunk.value);
2385
+ }
2386
+ if (chunk.done) {
2387
+ done = true;
2388
+ break;
2389
+ }
2390
+ }
2391
+ if (done && !("content-length" in resHeaderRecord)) {
2392
+ resHeaderRecord["content-length"] = values.reduce((acc, value) => acc + value.length, 0);
2393
+ }
2394
+ }
2395
+ outgoing.writeHead(res.status, resHeaderRecord);
2396
+ values.forEach((value) => {
2397
+ outgoing.write(value);
2398
+ });
2399
+ if (done) {
2400
+ outgoing.end();
2401
+ } else {
2402
+ if (values.length === 0) {
2403
+ flushHeaders(outgoing);
2404
+ }
2405
+ await writeFromReadableStreamDefaultReader(reader, outgoing, currentReadPromise);
2406
+ }
2407
+ } else if (resHeaderRecord[X_ALREADY_SENT]) {} else {
2408
+ outgoing.writeHead(res.status, resHeaderRecord);
2409
+ outgoing.end();
2410
+ }
2411
+ outgoing[outgoingEnded]?.();
2412
+ };
2413
+ var getRequestListener = (fetchCallback, options = {}) => {
2414
+ const autoCleanupIncoming = options.autoCleanupIncoming ?? true;
2415
+ if (options.overrideGlobalObjects !== false && global.Request !== Request2) {
2416
+ Object.defineProperty(global, "Request", {
2417
+ value: Request2
2418
+ });
2419
+ Object.defineProperty(global, "Response", {
2420
+ value: Response2
2421
+ });
2422
+ }
2423
+ return async (incoming, outgoing) => {
2424
+ let res, req;
2425
+ try {
2426
+ req = newRequest(incoming, options.hostname);
2427
+ let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD";
2428
+ if (!incomingEnded) {
2429
+ incoming[wrapBodyStream] = true;
2430
+ incoming.on("end", () => {
2431
+ incomingEnded = true;
2432
+ });
2433
+ if (incoming instanceof Http2ServerRequest2) {
2434
+ outgoing[outgoingEnded] = () => {
2435
+ if (!incomingEnded) {
2436
+ setTimeout(() => {
2437
+ if (!incomingEnded) {
2438
+ setTimeout(() => {
2439
+ incoming.destroy();
2440
+ outgoing.destroy();
2441
+ });
2442
+ }
2443
+ });
2444
+ }
2445
+ };
2446
+ }
2447
+ }
2448
+ outgoing.on("close", () => {
2449
+ const abortController = req[abortControllerKey];
2450
+ if (abortController) {
2451
+ if (incoming.errored) {
2452
+ req[abortControllerKey].abort(incoming.errored.toString());
2453
+ } else if (!outgoing.writableFinished) {
2454
+ req[abortControllerKey].abort("Client connection prematurely closed.");
2455
+ }
2456
+ }
2457
+ if (!incomingEnded) {
2458
+ setTimeout(() => {
2459
+ if (!incomingEnded) {
2460
+ setTimeout(() => {
2461
+ incoming.destroy();
2462
+ });
2463
+ }
2464
+ });
2465
+ }
2466
+ });
2467
+ res = fetchCallback(req, { incoming, outgoing });
2468
+ if (cacheKey in res) {
2469
+ return responseViaCache(res, outgoing);
2470
+ }
2471
+ } catch (e) {
2472
+ if (!res) {
2473
+ if (options.errorHandler) {
2474
+ res = await options.errorHandler(req ? e : toRequestError(e));
2475
+ if (!res) {
2476
+ return;
2477
+ }
2478
+ } else if (!req) {
2479
+ res = handleRequestError();
2480
+ } else {
2481
+ res = handleFetchError(e);
2482
+ }
2483
+ } else {
2484
+ return handleResponseError(e, outgoing);
2485
+ }
2486
+ }
2487
+ try {
2488
+ return await responseViaResponseObject(res, outgoing, options);
2489
+ } catch (e) {
2490
+ return handleResponseError(e, outgoing);
2491
+ }
2492
+ };
2493
+ };
2494
+ var createAdaptorServer = (options) => {
2495
+ const fetchCallback = options.fetch;
2496
+ const requestListener = getRequestListener(fetchCallback, {
2497
+ hostname: options.hostname,
2498
+ overrideGlobalObjects: options.overrideGlobalObjects,
2499
+ autoCleanupIncoming: options.autoCleanupIncoming
2500
+ });
2501
+ const createServer = options.createServer || createServerHTTP;
2502
+ const server = createServer(options.serverOptions || {}, requestListener);
2503
+ return server;
2504
+ };
2505
+ var serve = (options, listeningListener) => {
2506
+ const server = createAdaptorServer(options);
2507
+ server.listen(options?.port ?? 3000, options.hostname, () => {
2508
+ const serverInfo = server.address();
2509
+ listeningListener && listeningListener(serverInfo);
2510
+ });
2511
+ return server;
2512
+ };
2513
+
1981
2514
  // ../../node_modules/.bun/hono@4.12.3/node_modules/hono/dist/compose.js
1982
2515
  var compose = (middleware, onError, onNotFound) => {
1983
2516
  return (context, next) => {
@@ -2134,15 +2667,15 @@ var getPattern = (label, next) => {
2134
2667
  }
2135
2668
  const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
2136
2669
  if (match) {
2137
- const cacheKey = `${label}#${next}`;
2138
- if (!patternCache[cacheKey]) {
2670
+ const cacheKey2 = `${label}#${next}`;
2671
+ if (!patternCache[cacheKey2]) {
2139
2672
  if (match[2]) {
2140
- patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey, match[1], new RegExp(`^${match[2]}(?=/${next})`)] : [label, match[1], new RegExp(`^${match[2]}$`)];
2673
+ patternCache[cacheKey2] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey2, match[1], new RegExp(`^${match[2]}(?=/${next})`)] : [label, match[1], new RegExp(`^${match[2]}$`)];
2141
2674
  } else {
2142
- patternCache[cacheKey] = [label, match[1], true];
2675
+ patternCache[cacheKey2] = [label, match[1], true];
2143
2676
  }
2144
2677
  }
2145
- return patternCache[cacheKey];
2678
+ return patternCache[cacheKey2];
2146
2679
  }
2147
2680
  return null;
2148
2681
  };
@@ -3514,7 +4047,7 @@ var Hono2 = class extends Hono {
3514
4047
  };
3515
4048
 
3516
4049
  // src/middleware.ts
3517
- import { timingSafeEqual } from "crypto";
4050
+ import { timingSafeEqual } from "node:crypto";
3518
4051
  function corsMiddleware(config = true) {
3519
4052
  const opts = typeof config === "boolean" ? { origin: [], methods: ["GET", "POST", "OPTIONS"] } : config;
3520
4053
  return async (c, next) => {
@@ -3767,19 +4300,19 @@ function createApp(config) {
3767
4300
  listen(port) {
3768
4301
  const listenPort = port ?? serverConfig.port ?? 3000;
3769
4302
  const hostname = serverConfig.hostname ?? "0.0.0.0";
3770
- const server = Bun.serve({
4303
+ const server = serve({
4304
+ fetch: app.fetch,
3771
4305
  port: listenPort,
3772
- hostname,
3773
- fetch: app.fetch
4306
+ hostname
3774
4307
  });
3775
4308
  log4.info("ElsiumAI server started", {
3776
4309
  url: `http://${hostname}:${listenPort}`,
3777
4310
  routes: ["POST /chat", "POST /complete", "GET /health", "GET /metrics", "GET /agents"]
3778
4311
  });
3779
4312
  return {
3780
- port: server.port,
4313
+ port: listenPort,
3781
4314
  stop: () => {
3782
- server.stop();
4315
+ server.close();
3783
4316
  }
3784
4317
  };
3785
4318
  }
@@ -3824,7 +4357,7 @@ function matchPermission(granted, required) {
3824
4357
  }
3825
4358
  function createRBAC(config) {
3826
4359
  if (config.trustRoleHeader === true) {
3827
- log5.warn("RBAC: trustRoleHeader is enabled \u2014 any client can self-assign roles via the X-Role header. Only use this in development or behind a trusted reverse proxy.");
4360
+ log5.warn("RBAC: trustRoleHeader is enabled any client can self-assign roles via the X-Role header. Only use this in development or behind a trusted reverse proxy.");
3828
4361
  }
3829
4362
  const roleMap = new Map;
3830
4363
  for (const role of BUILT_IN_ROLES) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elsium-ai/app",
3
- "version": "0.1.7",
3
+ "version": "0.2.0",
4
4
  "description": "App bootstrap, HTTP server, and API routes for ElsiumAI",
5
5
  "license": "MIT",
6
6
  "author": "Eric Utrera <ebutrera9103@gmail.com>",
@@ -22,7 +22,7 @@
22
22
  "dist"
23
23
  ],
24
24
  "scripts": {
25
- "build": "bun build ./src/index.ts --outdir ./dist --target bun && bun x tsc -p tsconfig.build.json --emitDeclarationOnly",
25
+ "build": "bun build ./src/index.ts --outdir ./dist --target node && bun x tsc -p tsconfig.build.json --emitDeclarationOnly",
26
26
  "dev": "bun --watch src/index.ts"
27
27
  },
28
28
  "dependencies": {
@@ -33,11 +33,11 @@
33
33
  "@elsium-ai/observe": "workspace:*",
34
34
  "@elsium-ai/rag": "workspace:*",
35
35
  "@elsium-ai/workflows": "workspace:*",
36
+ "@hono/node-server": "^1.13.0",
36
37
  "hono": "^4.7.0",
37
38
  "zod": "^3.24.0"
38
39
  },
39
40
  "devDependencies": {
40
- "bun-types": "^1.3.0",
41
41
  "typescript": "^5.7.0"
42
42
  }
43
43
  }