@elsium-ai/app 0.8.0 → 0.9.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 +84 -42
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -2284,6 +2284,38 @@ function gateway(config) {
2284
2284
  });
2285
2285
  }
2286
2286
  return { data: result.data, response };
2287
+ },
2288
+ async extract(schema, input, options) {
2289
+ const maxRetries = options?.maxRetries ?? 3;
2290
+ const messages = [{ role: "user", content: input }];
2291
+ let lastError;
2292
+ for (let attempt = 0;attempt <= maxRetries; attempt++) {
2293
+ try {
2294
+ const result = await this.generate({
2295
+ messages: [...messages],
2296
+ schema,
2297
+ model: options?.model,
2298
+ system: options?.system,
2299
+ temperature: options?.temperature
2300
+ });
2301
+ return result.data;
2302
+ } catch (e) {
2303
+ if (e instanceof ElsiumError && e.code === "VALIDATION_ERROR") {
2304
+ lastError = e;
2305
+ messages.push({
2306
+ role: "assistant",
2307
+ content: "Invalid output"
2308
+ });
2309
+ messages.push({
2310
+ role: "user",
2311
+ content: `The previous response failed validation: ${e.message}. Please try again and return valid JSON matching the schema.`
2312
+ });
2313
+ continue;
2314
+ }
2315
+ throw e;
2316
+ }
2317
+ }
2318
+ throw lastError;
2287
2319
  }
2288
2320
  };
2289
2321
  }
@@ -2531,10 +2563,10 @@ function createProviderMesh(config) {
2531
2563
  };
2532
2564
  }());
2533
2565
  }
2534
- function logStreamFailover(provider, error) {
2566
+ function logStreamFailover(provider, toProvider, error) {
2535
2567
  audit?.log("provider_failover", {
2536
2568
  fromProvider: provider,
2537
- toProvider: "next",
2569
+ toProvider,
2538
2570
  strategy: config.strategy,
2539
2571
  reason: error?.message
2540
2572
  });
@@ -2560,7 +2592,9 @@ function createProviderMesh(config) {
2560
2592
  async function runStreamFallbackLoop(available, request, emit) {
2561
2593
  let lastError = null;
2562
2594
  let failedProvider = null;
2563
- for (const entry of available) {
2595
+ for (let i = 0;i < available.length; i++) {
2596
+ const entry = available[i];
2597
+ const nextProvider = i + 1 < available.length ? available[i + 1].name : "none";
2564
2598
  try {
2565
2599
  const result = await tryStreamProvider(entry, request, emit);
2566
2600
  if (result.success) {
@@ -2570,11 +2604,11 @@ function createProviderMesh(config) {
2570
2604
  }
2571
2605
  lastError = result.error ?? null;
2572
2606
  failedProvider = entry.name;
2573
- logStreamFailover(entry.name, result.error);
2607
+ logStreamFailover(entry.name, nextProvider, result.error);
2574
2608
  } catch (err2) {
2575
2609
  failedProvider = entry.name;
2576
2610
  lastError = toError2(err2);
2577
- logStreamFailover(entry.name, lastError);
2611
+ logStreamFailover(entry.name, nextProvider, lastError);
2578
2612
  }
2579
2613
  }
2580
2614
  emit({
@@ -2900,12 +2934,17 @@ function createNoopSpan(name, kind) {
2900
2934
  }
2901
2935
  };
2902
2936
  }
2937
+ // ../observe/src/audit-sink.ts
2938
+ var log8 = createLogger();
2939
+
2903
2940
  // ../observe/src/audit.ts
2904
2941
  var ZERO_HASH = "0".repeat(64);
2905
2942
  // ../observe/src/experiment.ts
2906
- var log8 = createLogger();
2907
- // ../observe/src/otel.ts
2908
2943
  var log9 = createLogger();
2944
+ // ../observe/src/studio-exporter.ts
2945
+ var log10 = createLogger();
2946
+ // ../observe/src/otel.ts
2947
+ var log11 = createLogger();
2909
2948
  // ../../node_modules/.bun/@hono+node-server@1.19.10/node_modules/@hono/node-server/dist/index.mjs
2910
2949
  import { createServer as createServerHTTP } from "http";
2911
2950
  import { Http2ServerRequest as Http2ServerRequest2 } from "http2";
@@ -3440,7 +3479,7 @@ var serve = (options, listeningListener) => {
3440
3479
  return server;
3441
3480
  };
3442
3481
 
3443
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/compose.js
3482
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/compose.js
3444
3483
  var compose = (middleware, onError, onNotFound) => {
3445
3484
  return (context, next) => {
3446
3485
  let index = -1;
@@ -3484,10 +3523,10 @@ var compose = (middleware, onError, onNotFound) => {
3484
3523
  };
3485
3524
  };
3486
3525
 
3487
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/request/constants.js
3526
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/request/constants.js
3488
3527
  var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
3489
3528
 
3490
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/utils/body.js
3529
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/body.js
3491
3530
  var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
3492
3531
  const { all = false, dot = false } = options;
3493
3532
  const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
@@ -3541,6 +3580,9 @@ var handleParsingAllValues = (form, key, value) => {
3541
3580
  }
3542
3581
  };
3543
3582
  var handleParsingNestedValues = (form, key, value) => {
3583
+ if (/(?:^|\.)__proto__\./.test(key)) {
3584
+ return;
3585
+ }
3544
3586
  let nestedForm = form;
3545
3587
  const keys = key.split(".");
3546
3588
  keys.forEach((key2, index) => {
@@ -3555,7 +3597,7 @@ var handleParsingNestedValues = (form, key, value) => {
3555
3597
  });
3556
3598
  };
3557
3599
 
3558
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/utils/url.js
3600
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/url.js
3559
3601
  var splitPath = (path) => {
3560
3602
  const paths = path.split("/");
3561
3603
  if (paths[0] === "") {
@@ -3755,7 +3797,7 @@ var getQueryParams = (url, key) => {
3755
3797
  };
3756
3798
  var decodeURIComponent_ = decodeURIComponent;
3757
3799
 
3758
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/request.js
3800
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/request.js
3759
3801
  var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
3760
3802
  var HonoRequest = class {
3761
3803
  raw;
@@ -3866,7 +3908,7 @@ var HonoRequest = class {
3866
3908
  }
3867
3909
  };
3868
3910
 
3869
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/utils/html.js
3911
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/html.js
3870
3912
  var HtmlEscapedCallbackPhase = {
3871
3913
  Stringify: 1,
3872
3914
  BeforeStream: 2,
@@ -3904,7 +3946,7 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
3904
3946
  }
3905
3947
  };
3906
3948
 
3907
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/context.js
3949
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/context.js
3908
3950
  var TEXT_PLAIN = "text/plain; charset=UTF-8";
3909
3951
  var setDefaultContentType = (contentType, headers) => {
3910
3952
  return {
@@ -4071,7 +4113,7 @@ var Context = class {
4071
4113
  };
4072
4114
  };
4073
4115
 
4074
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/router.js
4116
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router.js
4075
4117
  var METHOD_NAME_ALL = "ALL";
4076
4118
  var METHOD_NAME_ALL_LOWERCASE = "all";
4077
4119
  var METHODS = ["get", "post", "put", "delete", "options", "patch"];
@@ -4079,10 +4121,10 @@ var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is
4079
4121
  var UnsupportedPathError = class extends Error {
4080
4122
  };
4081
4123
 
4082
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/utils/constants.js
4124
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/constants.js
4083
4125
  var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
4084
4126
 
4085
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/hono-base.js
4127
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/hono-base.js
4086
4128
  var notFoundHandler = (c) => {
4087
4129
  return c.text("404 Not Found", 404);
4088
4130
  };
@@ -4301,7 +4343,7 @@ var Hono = class _Hono {
4301
4343
  };
4302
4344
  };
4303
4345
 
4304
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/router/reg-exp-router/matcher.js
4346
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/matcher.js
4305
4347
  var emptyParam = [];
4306
4348
  function match(method, path) {
4307
4349
  const matchers = this.buildAllMatchers();
@@ -4322,7 +4364,7 @@ function match(method, path) {
4322
4364
  return match2(method, path);
4323
4365
  }
4324
4366
 
4325
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/router/reg-exp-router/node.js
4367
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/node.js
4326
4368
  var LABEL_REG_EXP_STR = "[^/]+";
4327
4369
  var ONLY_WILDCARD_REG_EXP_STR = ".*";
4328
4370
  var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
@@ -4426,7 +4468,7 @@ var Node = class _Node {
4426
4468
  }
4427
4469
  };
4428
4470
 
4429
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/router/reg-exp-router/trie.js
4471
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/trie.js
4430
4472
  var Trie = class {
4431
4473
  #context = { varIndex: 0 };
4432
4474
  #root = new Node;
@@ -4482,7 +4524,7 @@ var Trie = class {
4482
4524
  }
4483
4525
  };
4484
4526
 
4485
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/router/reg-exp-router/router.js
4527
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/router.js
4486
4528
  var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
4487
4529
  var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
4488
4530
  function buildWildcardRegExp(path) {
@@ -4647,7 +4689,7 @@ var RegExpRouter = class {
4647
4689
  }
4648
4690
  };
4649
4691
 
4650
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/router/reg-exp-router/prepared-router.js
4692
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/reg-exp-router/prepared-router.js
4651
4693
  var PreparedRegExpRouter = class {
4652
4694
  name = "PreparedRegExpRouter";
4653
4695
  #matchers;
@@ -4719,7 +4761,7 @@ var PreparedRegExpRouter = class {
4719
4761
  match = match;
4720
4762
  };
4721
4763
 
4722
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/router/smart-router/router.js
4764
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/smart-router/router.js
4723
4765
  var SmartRouter = class {
4724
4766
  name = "SmartRouter";
4725
4767
  #routers = [];
@@ -4774,7 +4816,7 @@ var SmartRouter = class {
4774
4816
  }
4775
4817
  };
4776
4818
 
4777
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/router/trie-router/node.js
4819
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/trie-router/node.js
4778
4820
  var emptyParams = /* @__PURE__ */ Object.create(null);
4779
4821
  var hasChildren = (children) => {
4780
4822
  for (const _ in children) {
@@ -4943,7 +4985,7 @@ var Node2 = class _Node2 {
4943
4985
  }
4944
4986
  };
4945
4987
 
4946
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/router/trie-router/router.js
4988
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/router/trie-router/router.js
4947
4989
  var TrieRouter = class {
4948
4990
  name = "TrieRouter";
4949
4991
  #node;
@@ -4965,7 +5007,7 @@ var TrieRouter = class {
4965
5007
  }
4966
5008
  };
4967
5009
 
4968
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/hono.js
5010
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/hono.js
4969
5011
  var Hono2 = class extends Hono {
4970
5012
  constructor(options = {}) {
4971
5013
  super(options);
@@ -5065,12 +5107,12 @@ function requestIdMiddleware() {
5065
5107
  };
5066
5108
  }
5067
5109
  function requestLoggerMiddleware(logger) {
5068
- const log10 = logger ?? createLogger();
5110
+ const log12 = logger ?? createLogger();
5069
5111
  return async (c, next) => {
5070
5112
  const start = Date.now();
5071
5113
  await next();
5072
5114
  const duration = Date.now() - start;
5073
- log10.info(`${c.req.method} ${c.req.path}`, {
5115
+ log12.info(`${c.req.method} ${c.req.path}`, {
5074
5116
  method: c.req.method,
5075
5117
  path: c.req.path,
5076
5118
  status: c.res.status,
@@ -5080,7 +5122,7 @@ function requestLoggerMiddleware(logger) {
5080
5122
  };
5081
5123
  }
5082
5124
 
5083
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/utils/stream.js
5125
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/utils/stream.js
5084
5126
  var StreamingApi = class {
5085
5127
  writer;
5086
5128
  encoder;
@@ -5146,7 +5188,7 @@ var StreamingApi = class {
5146
5188
  }
5147
5189
  };
5148
5190
 
5149
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/helper/streaming/utils.js
5191
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/helper/streaming/utils.js
5150
5192
  var isOldBunVersion = () => {
5151
5193
  const version = typeof Bun !== "undefined" ? Bun.version : undefined;
5152
5194
  if (version === undefined) {
@@ -5157,7 +5199,7 @@ var isOldBunVersion = () => {
5157
5199
  return result;
5158
5200
  };
5159
5201
 
5160
- // ../../node_modules/.bun/hono@4.12.5/node_modules/hono/dist/helper/streaming/stream.js
5202
+ // ../../node_modules/.bun/hono@4.12.8/node_modules/hono/dist/helper/streaming/stream.js
5161
5203
  var contextStash = /* @__PURE__ */ new WeakMap;
5162
5204
  var stream = (c, cb, onError) => {
5163
5205
  const { readable, writable } = new TransformStream;
@@ -5413,13 +5455,13 @@ function createRoutes(deps) {
5413
5455
  }
5414
5456
 
5415
5457
  // src/app.ts
5416
- var log10 = createLogger();
5458
+ var log12 = createLogger();
5417
5459
  function createApp(config) {
5418
5460
  const app = new Hono2;
5419
5461
  app.onError((err2, c) => {
5420
5462
  const statusCode = err2 instanceof ElsiumError ? err2.statusCode ?? 500 : 500;
5421
5463
  const code = err2 instanceof ElsiumError ? err2.code : "UNKNOWN";
5422
- log10.error("Unhandled error", { error: err2.message, code, path: c.req.path });
5464
+ log12.error("Unhandled error", { error: err2.message, code, path: c.req.path });
5423
5465
  return c.json({ error: err2.message, code }, statusCode);
5424
5466
  });
5425
5467
  app.notFound((c) => {
@@ -5465,7 +5507,7 @@ function createApp(config) {
5465
5507
  });
5466
5508
  const serverConfig = config.server ?? {};
5467
5509
  app.use("*", requestIdMiddleware());
5468
- app.use("*", requestLoggerMiddleware(log10));
5510
+ app.use("*", requestLoggerMiddleware(log12));
5469
5511
  if (serverConfig.cors) {
5470
5512
  app.use("*", corsMiddleware(serverConfig.cors));
5471
5513
  }
@@ -5511,11 +5553,11 @@ function createApp(config) {
5511
5553
  const drainTimeoutMs = typeof serverConfig.gracefulShutdown === "object" ? serverConfig.gracefulShutdown.drainTimeoutMs : undefined;
5512
5554
  shutdownManager = createShutdownManager({
5513
5555
  drainTimeoutMs,
5514
- onDrainStart: () => log10.info("Draining connections..."),
5515
- onDrainComplete: () => log10.info("Drain complete")
5556
+ onDrainStart: () => log12.info("Draining connections..."),
5557
+ onDrainComplete: () => log12.info("Drain complete")
5516
5558
  });
5517
5559
  }
5518
- log10.info("ElsiumAI server started", {
5560
+ log12.info("ElsiumAI server started", {
5519
5561
  url: `http://${hostname}:${listenPort}`,
5520
5562
  routes: ["POST /chat", "POST /complete", "GET /health", "GET /metrics", "GET /agents"]
5521
5563
  });
@@ -5532,7 +5574,7 @@ function createApp(config) {
5532
5574
  };
5533
5575
  }
5534
5576
  // src/rbac.ts
5535
- var log11 = createLogger();
5577
+ var log13 = createLogger();
5536
5578
  var BUILT_IN_ROLES = [
5537
5579
  {
5538
5580
  name: "admin",
@@ -5570,7 +5612,7 @@ function matchPermission(granted, required) {
5570
5612
  }
5571
5613
  function createRBAC(config) {
5572
5614
  if (config.trustRoleHeader === true) {
5573
- log11.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.");
5615
+ log13.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.");
5574
5616
  }
5575
5617
  const roleMap = new Map;
5576
5618
  for (const role of BUILT_IN_ROLES) {
@@ -5627,7 +5669,7 @@ function createRBAC(config) {
5627
5669
  };
5628
5670
  }
5629
5671
  // src/tenant.ts
5630
- var log12 = createLogger();
5672
+ var log14 = createLogger();
5631
5673
  var tenantUsage = new Map;
5632
5674
  function tenantMiddleware(config) {
5633
5675
  const { extractTenant, onUnknownTenant = "reject", defaultTenant } = config;
@@ -5636,13 +5678,13 @@ function tenantMiddleware(config) {
5636
5678
  if (!tenant) {
5637
5679
  if (onUnknownTenant === "default" && defaultTenant) {
5638
5680
  c.set("tenant", defaultTenant);
5639
- log12.debug("Using default tenant", { tenantId: defaultTenant.tenantId });
5681
+ log14.debug("Using default tenant", { tenantId: defaultTenant.tenantId });
5640
5682
  } else {
5641
5683
  return c.json({ error: "Tenant identification required" }, 401);
5642
5684
  }
5643
5685
  } else {
5644
5686
  c.set("tenant", tenant);
5645
- log12.debug("Tenant identified", { tenantId: tenant.tenantId });
5687
+ log14.debug("Tenant identified", { tenantId: tenant.tenantId });
5646
5688
  }
5647
5689
  await next();
5648
5690
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elsium-ai/app",
3
- "version": "0.8.0",
3
+ "version": "0.9.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,13 +26,13 @@
26
26
  "dev": "bun --watch src/index.ts"
27
27
  },
28
28
  "dependencies": {
29
- "@elsium-ai/core": "^0.8.0",
30
- "@elsium-ai/gateway": "^0.8.0",
31
- "@elsium-ai/agents": "^0.8.0",
32
- "@elsium-ai/tools": "^0.8.0",
33
- "@elsium-ai/observe": "^0.8.0",
34
- "@elsium-ai/rag": "^0.8.0",
35
- "@elsium-ai/workflows": "^0.8.0",
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
36
  "@hono/node-server": "^1.19.10",
37
37
  "hono": "^4.12.4",
38
38
  "zod": "^3.24.0"