@elsium-ai/app 0.9.0 → 0.10.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.
Files changed (2) hide show
  1. package/dist/index.js +142 -52
  2. package/package.json +10 -10
package/dist/index.js CHANGED
@@ -2589,27 +2589,33 @@ function createProviderMesh(config) {
2589
2589
  }
2590
2590
  return { success: true };
2591
2591
  }
2592
+ async function attemptStreamProvider(entry, nextProvider, request, emit) {
2593
+ try {
2594
+ const result = await tryStreamProvider(entry, request, emit);
2595
+ if (result.success)
2596
+ return { success: true };
2597
+ logStreamFailover(entry.name, nextProvider, result.error);
2598
+ return { success: false, error: result.error };
2599
+ } catch (err2) {
2600
+ const error = toError2(err2);
2601
+ logStreamFailover(entry.name, nextProvider, error);
2602
+ return { success: false, error };
2603
+ }
2604
+ }
2592
2605
  async function runStreamFallbackLoop(available, request, emit) {
2593
2606
  let lastError = null;
2594
2607
  let failedProvider = null;
2595
2608
  for (let i = 0;i < available.length; i++) {
2596
2609
  const entry = available[i];
2597
2610
  const nextProvider = i + 1 < available.length ? available[i + 1].name : "none";
2598
- try {
2599
- const result = await tryStreamProvider(entry, request, emit);
2600
- if (result.success) {
2601
- if (failedProvider)
2602
- logFailover(failedProvider, entry.name, lastError?.message);
2603
- return;
2604
- }
2605
- lastError = result.error ?? null;
2606
- failedProvider = entry.name;
2607
- logStreamFailover(entry.name, nextProvider, result.error);
2608
- } catch (err2) {
2609
- failedProvider = entry.name;
2610
- lastError = toError2(err2);
2611
- logStreamFailover(entry.name, nextProvider, lastError);
2611
+ const attempt = await attemptStreamProvider(entry, nextProvider, request, emit);
2612
+ if (attempt.success) {
2613
+ if (failedProvider)
2614
+ logFailover(failedProvider, entry.name, lastError?.message);
2615
+ return;
2612
2616
  }
2617
+ lastError = attempt.error ?? null;
2618
+ failedProvider = entry.name;
2613
2619
  }
2614
2620
  emit({
2615
2621
  type: "error",
@@ -2945,9 +2951,9 @@ var log9 = createLogger();
2945
2951
  var log10 = createLogger();
2946
2952
  // ../observe/src/otel.ts
2947
2953
  var log11 = createLogger();
2948
- // ../../node_modules/.bun/@hono+node-server@1.19.10/node_modules/@hono/node-server/dist/index.mjs
2954
+ // ../../node_modules/.bun/@hono+node-server@1.19.14/node_modules/@hono/node-server/dist/index.mjs
2949
2955
  import { createServer as createServerHTTP } from "http";
2950
- import { Http2ServerRequest as Http2ServerRequest2 } from "http2";
2956
+ import { Http2ServerRequest as Http2ServerRequest2, constants as h2constants } from "http2";
2951
2957
  import { Http2ServerRequest } from "http2";
2952
2958
  import { Readable } from "stream";
2953
2959
  import crypto from "crypto";
@@ -3087,6 +3093,17 @@ var requestPrototype = {
3087
3093
  }
3088
3094
  });
3089
3095
  });
3096
+ Object.defineProperty(requestPrototype, Symbol.for("nodejs.util.inspect.custom"), {
3097
+ value: function(depth, options, inspectFn) {
3098
+ const props = {
3099
+ method: this.method,
3100
+ url: this.url,
3101
+ headers: this.headers,
3102
+ nativeRequest: this[requestCache]
3103
+ };
3104
+ return `Request (lightweight) ${inspectFn(props, { ...options, depth: depth == null ? null : depth - 1 })}`;
3105
+ }
3106
+ });
3090
3107
  Object.setPrototypeOf(requestPrototype, Request2.prototype);
3091
3108
  var newRequest = (incoming, defaultHostname) => {
3092
3109
  const req = Object.create(requestPrototype);
@@ -3152,15 +3169,14 @@ var Response2 = class _Response {
3152
3169
  this.#init = init;
3153
3170
  }
3154
3171
  if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
3155
- headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
3156
- this[cacheKey] = [init?.status || 200, body, headers];
3172
+ this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
3157
3173
  }
3158
3174
  }
3159
3175
  get headers() {
3160
3176
  const cache = this[cacheKey];
3161
3177
  if (cache) {
3162
3178
  if (!(cache[2] instanceof Headers)) {
3163
- cache[2] = new Headers(cache[2]);
3179
+ cache[2] = new Headers(cache[2] || { "content-type": "text/plain; charset=UTF-8" });
3164
3180
  }
3165
3181
  return cache[2];
3166
3182
  }
@@ -3188,6 +3204,17 @@ var Response2 = class _Response {
3188
3204
  }
3189
3205
  });
3190
3206
  });
3207
+ Object.defineProperty(Response2.prototype, Symbol.for("nodejs.util.inspect.custom"), {
3208
+ value: function(depth, options, inspectFn) {
3209
+ const props = {
3210
+ status: this.status,
3211
+ headers: this.headers,
3212
+ ok: this.ok,
3213
+ nativeResponse: this[responseCache]
3214
+ };
3215
+ return `Response (lightweight) ${inspectFn(props, { ...options, depth: depth == null ? null : depth - 1 })}`;
3216
+ }
3217
+ });
3191
3218
  Object.setPrototypeOf(Response2, GlobalResponse);
3192
3219
  Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
3193
3220
  async function readWithoutBlocking(readPromise) {
@@ -3258,6 +3285,48 @@ if (typeof global.crypto === "undefined") {
3258
3285
  global.crypto = crypto;
3259
3286
  }
3260
3287
  var outgoingEnded = Symbol("outgoingEnded");
3288
+ var incomingDraining = Symbol("incomingDraining");
3289
+ var DRAIN_TIMEOUT_MS = 500;
3290
+ var MAX_DRAIN_BYTES = 64 * 1024 * 1024;
3291
+ var drainIncoming = (incoming) => {
3292
+ const incomingWithDrainState = incoming;
3293
+ if (incoming.destroyed || incomingWithDrainState[incomingDraining]) {
3294
+ return;
3295
+ }
3296
+ incomingWithDrainState[incomingDraining] = true;
3297
+ if (incoming instanceof Http2ServerRequest2) {
3298
+ try {
3299
+ incoming.stream?.close?.(h2constants.NGHTTP2_NO_ERROR);
3300
+ } catch {}
3301
+ return;
3302
+ }
3303
+ let bytesRead = 0;
3304
+ const cleanup = () => {
3305
+ clearTimeout(timer);
3306
+ incoming.off("data", onData);
3307
+ incoming.off("end", cleanup);
3308
+ incoming.off("error", cleanup);
3309
+ };
3310
+ const forceClose = () => {
3311
+ cleanup();
3312
+ const socket = incoming.socket;
3313
+ if (socket && !socket.destroyed) {
3314
+ socket.destroySoon();
3315
+ }
3316
+ };
3317
+ const timer = setTimeout(forceClose, DRAIN_TIMEOUT_MS);
3318
+ timer.unref?.();
3319
+ const onData = (chunk) => {
3320
+ bytesRead += chunk.length;
3321
+ if (bytesRead > MAX_DRAIN_BYTES) {
3322
+ forceClose();
3323
+ }
3324
+ };
3325
+ incoming.on("data", onData);
3326
+ incoming.on("end", cleanup);
3327
+ incoming.on("error", cleanup);
3328
+ incoming.resume();
3329
+ };
3261
3330
  var handleRequestError = () => new Response(null, {
3262
3331
  status: 400
3263
3332
  });
@@ -3284,15 +3353,32 @@ var flushHeaders = (outgoing) => {
3284
3353
  };
3285
3354
  var responseViaCache = async (res, outgoing) => {
3286
3355
  let [status, body, header] = res[cacheKey];
3287
- if (header instanceof Headers) {
3356
+ let hasContentLength = false;
3357
+ if (!header) {
3358
+ header = { "content-type": "text/plain; charset=UTF-8" };
3359
+ } else if (header instanceof Headers) {
3360
+ hasContentLength = header.has("content-length");
3288
3361
  header = buildOutgoingHttpHeaders(header);
3362
+ } else if (Array.isArray(header)) {
3363
+ const headerObj = new Headers(header);
3364
+ hasContentLength = headerObj.has("content-length");
3365
+ header = buildOutgoingHttpHeaders(headerObj);
3366
+ } else {
3367
+ for (const key in header) {
3368
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
3369
+ hasContentLength = true;
3370
+ break;
3371
+ }
3372
+ }
3289
3373
  }
3290
- if (typeof body === "string") {
3291
- header["Content-Length"] = Buffer.byteLength(body);
3292
- } else if (body instanceof Uint8Array) {
3293
- header["Content-Length"] = body.byteLength;
3294
- } else if (body instanceof Blob) {
3295
- header["Content-Length"] = body.size;
3374
+ if (!hasContentLength) {
3375
+ if (typeof body === "string") {
3376
+ header["Content-Length"] = Buffer.byteLength(body);
3377
+ } else if (body instanceof Uint8Array) {
3378
+ header["Content-Length"] = body.byteLength;
3379
+ } else if (body instanceof Blob) {
3380
+ header["Content-Length"] = body.size;
3381
+ }
3296
3382
  }
3297
3383
  outgoing.writeHead(status, header);
3298
3384
  if (typeof body === "string" || body instanceof Uint8Array) {
@@ -3404,14 +3490,18 @@ var getRequestListener = (fetchCallback, options = {}) => {
3404
3490
  setTimeout(() => {
3405
3491
  if (!incomingEnded) {
3406
3492
  setTimeout(() => {
3407
- incoming.destroy();
3408
- outgoing.destroy();
3493
+ drainIncoming(incoming);
3409
3494
  });
3410
3495
  }
3411
3496
  });
3412
3497
  }
3413
3498
  };
3414
3499
  }
3500
+ outgoing.on("finish", () => {
3501
+ if (!incomingEnded) {
3502
+ drainIncoming(incoming);
3503
+ }
3504
+ });
3415
3505
  }
3416
3506
  outgoing.on("close", () => {
3417
3507
  const abortController = req[abortControllerKey];
@@ -3426,7 +3516,7 @@ var getRequestListener = (fetchCallback, options = {}) => {
3426
3516
  setTimeout(() => {
3427
3517
  if (!incomingEnded) {
3428
3518
  setTimeout(() => {
3429
- incoming.destroy();
3519
+ drainIncoming(incoming);
3430
3520
  });
3431
3521
  }
3432
3522
  });
@@ -3479,7 +3569,7 @@ var serve = (options, listeningListener) => {
3479
3569
  return server;
3480
3570
  };
3481
3571
 
3482
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/compose.js
3572
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/compose.js
3483
3573
  var compose = (middleware, onError, onNotFound) => {
3484
3574
  return (context, next) => {
3485
3575
  let index = -1;
@@ -3523,10 +3613,10 @@ var compose = (middleware, onError, onNotFound) => {
3523
3613
  };
3524
3614
  };
3525
3615
 
3526
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/request/constants.js
3616
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/request/constants.js
3527
3617
  var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
3528
3618
 
3529
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/body.js
3619
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/utils/body.js
3530
3620
  var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
3531
3621
  const { all = false, dot = false } = options;
3532
3622
  const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
@@ -3597,7 +3687,7 @@ var handleParsingNestedValues = (form, key, value) => {
3597
3687
  });
3598
3688
  };
3599
3689
 
3600
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/url.js
3690
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/utils/url.js
3601
3691
  var splitPath = (path) => {
3602
3692
  const paths = path.split("/");
3603
3693
  if (paths[0] === "") {
@@ -3797,7 +3887,7 @@ var getQueryParams = (url, key) => {
3797
3887
  };
3798
3888
  var decodeURIComponent_ = decodeURIComponent;
3799
3889
 
3800
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/request.js
3890
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/request.js
3801
3891
  var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
3802
3892
  var HonoRequest = class {
3803
3893
  raw;
@@ -3851,7 +3941,7 @@ var HonoRequest = class {
3851
3941
  return headerData;
3852
3942
  }
3853
3943
  async parseBody(options) {
3854
- return this.bodyCache.parsedBody ??= await parseBody(this, options);
3944
+ return parseBody(this, options);
3855
3945
  }
3856
3946
  #cachedBody = (key) => {
3857
3947
  const { bodyCache, raw } = this;
@@ -3908,7 +3998,7 @@ var HonoRequest = class {
3908
3998
  }
3909
3999
  };
3910
4000
 
3911
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/html.js
4001
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/utils/html.js
3912
4002
  var HtmlEscapedCallbackPhase = {
3913
4003
  Stringify: 1,
3914
4004
  BeforeStream: 2,
@@ -3946,7 +4036,7 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
3946
4036
  }
3947
4037
  };
3948
4038
 
3949
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/context.js
4039
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/context.js
3950
4040
  var TEXT_PLAIN = "text/plain; charset=UTF-8";
3951
4041
  var setDefaultContentType = (contentType, headers) => {
3952
4042
  return {
@@ -4113,7 +4203,7 @@ var Context = class {
4113
4203
  };
4114
4204
  };
4115
4205
 
4116
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router.js
4206
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/router.js
4117
4207
  var METHOD_NAME_ALL = "ALL";
4118
4208
  var METHOD_NAME_ALL_LOWERCASE = "all";
4119
4209
  var METHODS = ["get", "post", "put", "delete", "options", "patch"];
@@ -4121,10 +4211,10 @@ var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is
4121
4211
  var UnsupportedPathError = class extends Error {
4122
4212
  };
4123
4213
 
4124
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/constants.js
4214
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/utils/constants.js
4125
4215
  var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
4126
4216
 
4127
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/hono-base.js
4217
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/hono-base.js
4128
4218
  var notFoundHandler = (c) => {
4129
4219
  return c.text("404 Not Found", 404);
4130
4220
  };
@@ -4343,7 +4433,7 @@ var Hono = class _Hono {
4343
4433
  };
4344
4434
  };
4345
4435
 
4346
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/matcher.js
4436
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/router/reg-exp-router/matcher.js
4347
4437
  var emptyParam = [];
4348
4438
  function match(method, path) {
4349
4439
  const matchers = this.buildAllMatchers();
@@ -4364,7 +4454,7 @@ function match(method, path) {
4364
4454
  return match2(method, path);
4365
4455
  }
4366
4456
 
4367
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/node.js
4457
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/router/reg-exp-router/node.js
4368
4458
  var LABEL_REG_EXP_STR = "[^/]+";
4369
4459
  var ONLY_WILDCARD_REG_EXP_STR = ".*";
4370
4460
  var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
@@ -4468,7 +4558,7 @@ var Node = class _Node {
4468
4558
  }
4469
4559
  };
4470
4560
 
4471
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/trie.js
4561
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/router/reg-exp-router/trie.js
4472
4562
  var Trie = class {
4473
4563
  #context = { varIndex: 0 };
4474
4564
  #root = new Node;
@@ -4524,7 +4614,7 @@ var Trie = class {
4524
4614
  }
4525
4615
  };
4526
4616
 
4527
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/router.js
4617
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/router/reg-exp-router/router.js
4528
4618
  var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
4529
4619
  var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
4530
4620
  function buildWildcardRegExp(path) {
@@ -4689,7 +4779,7 @@ var RegExpRouter = class {
4689
4779
  }
4690
4780
  };
4691
4781
 
4692
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/prepared-router.js
4782
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/router/reg-exp-router/prepared-router.js
4693
4783
  var PreparedRegExpRouter = class {
4694
4784
  name = "PreparedRegExpRouter";
4695
4785
  #matchers;
@@ -4761,7 +4851,7 @@ var PreparedRegExpRouter = class {
4761
4851
  match = match;
4762
4852
  };
4763
4853
 
4764
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/smart-router/router.js
4854
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/router/smart-router/router.js
4765
4855
  var SmartRouter = class {
4766
4856
  name = "SmartRouter";
4767
4857
  #routers = [];
@@ -4816,7 +4906,7 @@ var SmartRouter = class {
4816
4906
  }
4817
4907
  };
4818
4908
 
4819
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/trie-router/node.js
4909
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/router/trie-router/node.js
4820
4910
  var emptyParams = /* @__PURE__ */ Object.create(null);
4821
4911
  var hasChildren = (children) => {
4822
4912
  for (const _ in children) {
@@ -4985,7 +5075,7 @@ var Node2 = class _Node2 {
4985
5075
  }
4986
5076
  };
4987
5077
 
4988
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/trie-router/router.js
5078
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/router/trie-router/router.js
4989
5079
  var TrieRouter = class {
4990
5080
  name = "TrieRouter";
4991
5081
  #node;
@@ -5007,7 +5097,7 @@ var TrieRouter = class {
5007
5097
  }
5008
5098
  };
5009
5099
 
5010
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/hono.js
5100
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/hono.js
5011
5101
  var Hono2 = class extends Hono {
5012
5102
  constructor(options = {}) {
5013
5103
  super(options);
@@ -5122,7 +5212,7 @@ function requestLoggerMiddleware(logger) {
5122
5212
  };
5123
5213
  }
5124
5214
 
5125
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/stream.js
5215
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/utils/stream.js
5126
5216
  var StreamingApi = class {
5127
5217
  writer;
5128
5218
  encoder;
@@ -5188,7 +5278,7 @@ var StreamingApi = class {
5188
5278
  }
5189
5279
  };
5190
5280
 
5191
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/helper/streaming/utils.js
5281
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/helper/streaming/utils.js
5192
5282
  var isOldBunVersion = () => {
5193
5283
  const version = typeof Bun !== "undefined" ? Bun.version : undefined;
5194
5284
  if (version === undefined) {
@@ -5199,7 +5289,7 @@ var isOldBunVersion = () => {
5199
5289
  return result;
5200
5290
  };
5201
5291
 
5202
- // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/helper/streaming/stream.js
5292
+ // ../../node_modules/.bun/hono@4.12.12/node_modules/hono/dist/helper/streaming/stream.js
5203
5293
  var contextStash = /* @__PURE__ */ new WeakMap;
5204
5294
  var stream = (c, cb, onError) => {
5205
5295
  const { readable, writable } = new TransformStream;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elsium-ai/app",
3
- "version": "0.9.0",
3
+ "version": "0.10.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>",
@@ -26,15 +26,15 @@
26
26
  "dev": "bun --watch src/index.ts"
27
27
  },
28
28
  "dependencies": {
29
- "@elsium-ai/core": "^0.9.0",
30
- "@elsium-ai/gateway": "^0.9.0",
31
- "@elsium-ai/agents": "^0.9.0",
32
- "@elsium-ai/tools": "^0.9.0",
33
- "@elsium-ai/observe": "^0.9.0",
34
- "@elsium-ai/rag": "^0.9.0",
35
- "@elsium-ai/workflows": "^0.9.0",
36
- "@hono/node-server": "^1.19.10",
37
- "hono": "^4.12.4",
29
+ "@elsium-ai/core": "^0.10.0",
30
+ "@elsium-ai/gateway": "^0.10.0",
31
+ "@elsium-ai/agents": "^0.10.0",
32
+ "@elsium-ai/tools": "^0.10.0",
33
+ "@elsium-ai/observe": "^0.10.0",
34
+ "@elsium-ai/rag": "^0.10.0",
35
+ "@elsium-ai/workflows": "^0.10.0",
36
+ "@hono/node-server": "^1.19.14",
37
+ "hono": "^4.12.12",
38
38
  "zod": "^3.24.0"
39
39
  },
40
40
  "devDependencies": {