@guren/server 2.26.0 → 2.27.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/{DocsViewerServiceProvider-CIRNHQ2I.js → DocsViewerServiceProvider-BMbcTYVw.js} +1 -1
- package/dist/{McpServiceProvider-B-LioPSz.js → McpServiceProvider-PGFPlYTy.js} +1 -1
- package/dist/{Resource-gki0_2B6.js → Resource-q3tJpJ0K.js} +22 -17
- package/dist/{ServiceProvider-DDW3MqQJ.js → ServiceProvider-G0YclITd.js} +60 -8
- package/dist/agent/dispatch.d.ts +4 -4
- package/dist/agent/public.js +1 -1
- package/dist/agent-request-Caj6bnbj.js +18 -0
- package/dist/auth/AuthManager.d.ts +4 -0
- package/dist/auth/email-verification.d.ts +2 -1
- package/dist/auth/index.js +1 -1
- package/dist/auth/password/describe-hasher.d.ts +11 -0
- package/dist/{auth-DiyWALZT.js → auth-DIugW0O-.js} +70 -4
- package/dist/authorization/index.js +1 -1
- package/dist/authorization/middleware.d.ts +8 -0
- package/dist/{authorization-E6X6Y-B6.js → authorization-Daa6CxCg.js} +16 -1
- package/dist/broadcasting/BroadcastManager.d.ts +23 -6
- package/dist/broadcasting/index.d.ts +1 -1
- package/dist/broadcasting/index.js +1 -1
- package/dist/broadcasting/types.d.ts +13 -1
- package/dist/{broadcasting-D0vMkKcq.js → broadcasting-N4cRV42s.js} +204 -33
- package/dist/cache/CacheManager.d.ts +5 -0
- package/dist/cache/TaggedCache.d.ts +2 -0
- package/dist/cache/index.js +1 -1
- package/dist/cache/pending-computations.d.ts +22 -0
- package/dist/cache/stores/FileStore.d.ts +1 -1
- package/dist/cache/stores/file-lock.d.ts +1 -0
- package/dist/{cache-DcnRufMe.js → cache-BlXopnH1.js} +179 -39
- package/dist/container/ServiceProvider.d.ts +27 -2
- package/dist/container/defineModule.d.ts +4 -5
- package/dist/container/definePlugin.d.ts +2 -0
- package/dist/dev-banner-CfQDnkfQ.js +51 -0
- package/dist/{dispatch-BAwzftws.js → dispatch-ENWpBxbE.js} +26 -4
- package/dist/driver-map-CkQc52j-.js +12 -0
- package/dist/host-port-t6wQFaRu.js +15 -0
- package/dist/hot-reload/testing.d.ts +2 -1
- package/dist/http/Application.d.ts +19 -1
- package/dist/http/dev-banner.d.ts +0 -8
- package/dist/http/host-port.d.ts +8 -0
- package/dist/http/middleware/force-https.d.ts +2 -1
- package/dist/http/middleware/index.d.ts +1 -0
- package/dist/http/middleware/session-manager.d.ts +5 -0
- package/dist/http/middleware/websocket-origin.d.ts +22 -0
- package/dist/http/public-assets.d.ts +6 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +694 -234
- package/dist/internal/agent-request.d.ts +18 -0
- package/dist/internal/dispatched-request.d.ts +4 -0
- package/dist/internal/testing.js +2 -2
- package/dist/internal/zod-json-schema.js +1 -1
- package/dist/introspection/driver-map.d.ts +3 -0
- package/dist/introspection/flag.d.ts +12 -0
- package/dist/introspection/manifest.d.ts +17 -0
- package/dist/introspection/plain-json.d.ts +7 -0
- package/dist/introspection/types.d.ts +167 -0
- package/dist/mcp/index.js +1 -1
- package/dist/mvc/Router.d.ts +33 -0
- package/dist/providers/ConfigServiceProvider.d.ts +7 -0
- package/dist/queue/QueueManager.d.ts +3 -0
- package/dist/queue/index.js +1 -1
- package/dist/{queue-Bo4Q857L.js → queue-C8s3buYz.js} +5 -0
- package/dist/runtime/index.js +15 -2
- package/dist/storage/StorageManager.d.ts +5 -0
- package/dist/storage/index.js +1 -1
- package/dist/{storage-wFsUJHZW.js → storage-IlUesK2t.js} +13 -1
- package/dist/{vite-manifest-DlU94f3Z.js → vite-manifest-wPxfAzjW.js} +1 -57
- package/package.json +2 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { r as isPromiseLike } from "./Logger-DWXdtLSJ.js";
|
|
2
2
|
import { n as isHotReloadRuntime, t as claimHotDisposable } from "./hot-disposables-W2fH-GID.js";
|
|
3
|
+
import { t as describeDriverMap } from "./driver-map-CkQc52j-.js";
|
|
3
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
5
|
import { dirname, join } from "node:path";
|
|
5
6
|
import { mkdir, readFile, readdir, rename, rm, rmdir, unlink, writeFile } from "node:fs/promises";
|
|
@@ -253,11 +254,80 @@ var RedisStore = class {
|
|
|
253
254
|
}
|
|
254
255
|
};
|
|
255
256
|
//#endregion
|
|
257
|
+
//#region src/cache/stores/file-lock.ts
|
|
258
|
+
const POLL_MS = 5;
|
|
259
|
+
function hasCode(error, code) {
|
|
260
|
+
return error.code === code;
|
|
261
|
+
}
|
|
262
|
+
async function entriesOf(lockPath) {
|
|
263
|
+
try {
|
|
264
|
+
return await readdir(lockPath);
|
|
265
|
+
} catch (error) {
|
|
266
|
+
if (hasCode(error, "ENOENT")) return void 0;
|
|
267
|
+
throw error;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function ignoreRaced(error) {
|
|
271
|
+
if (![
|
|
272
|
+
"ENOENT",
|
|
273
|
+
"ENOTEMPTY",
|
|
274
|
+
"EEXIST"
|
|
275
|
+
].some((code) => hasCode(error, code))) throw error;
|
|
276
|
+
}
|
|
277
|
+
async function remove(lockPath, names) {
|
|
278
|
+
for (const name of names) await unlink(join(lockPath, name)).catch(ignoreRaced);
|
|
279
|
+
await rmdir(lockPath).catch(ignoreRaced);
|
|
280
|
+
}
|
|
281
|
+
async function tryAcquire(lockPath) {
|
|
282
|
+
try {
|
|
283
|
+
await mkdir(lockPath);
|
|
284
|
+
} catch (error) {
|
|
285
|
+
if (hasCode(error, "EEXIST")) return void 0;
|
|
286
|
+
if (!hasCode(error, "ENOENT")) throw error;
|
|
287
|
+
await mkdir(dirname(lockPath), { recursive: true });
|
|
288
|
+
return tryAcquire(lockPath);
|
|
289
|
+
}
|
|
290
|
+
const token = randomUUID();
|
|
291
|
+
let held = false;
|
|
292
|
+
try {
|
|
293
|
+
await writeFile(join(lockPath, token), "");
|
|
294
|
+
const entries = await readdir(lockPath);
|
|
295
|
+
held = entries.length === 1 && entries[0] === token;
|
|
296
|
+
} catch (error) {
|
|
297
|
+
if (!hasCode(error, "ENOENT")) throw error;
|
|
298
|
+
} finally {
|
|
299
|
+
if (!held) await remove(lockPath, [token]);
|
|
300
|
+
}
|
|
301
|
+
return held ? token : void 0;
|
|
302
|
+
}
|
|
303
|
+
async function withFileLock(lockPath, timeoutMs, callback) {
|
|
304
|
+
let seen;
|
|
305
|
+
let takeOverAt = 0;
|
|
306
|
+
for (;;) {
|
|
307
|
+
const token = await tryAcquire(lockPath);
|
|
308
|
+
if (token !== void 0) try {
|
|
309
|
+
return await callback();
|
|
310
|
+
} finally {
|
|
311
|
+
await remove(lockPath, [token]).catch(() => void 0);
|
|
312
|
+
}
|
|
313
|
+
if (performance.now() >= takeOverAt) {
|
|
314
|
+
const entries = await entriesOf(lockPath);
|
|
315
|
+
if (entries === void 0) continue;
|
|
316
|
+
const current = entries.sort().join("/");
|
|
317
|
+
if (current === seen) {
|
|
318
|
+
await remove(lockPath, entries);
|
|
319
|
+
seen = void 0;
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
seen = current;
|
|
323
|
+
takeOverAt = performance.now() + timeoutMs;
|
|
324
|
+
}
|
|
325
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_MS));
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
//#endregion
|
|
256
329
|
//#region src/cache/stores/FileStore.ts
|
|
257
330
|
const LOCK_TIMEOUT_MS = 5e3;
|
|
258
|
-
function ignoreMissing(error) {
|
|
259
|
-
if (error.code !== "ENOENT") throw error;
|
|
260
|
-
}
|
|
261
331
|
/** File-based cache store. */
|
|
262
332
|
var FileStore = class {
|
|
263
333
|
basePath;
|
|
@@ -296,27 +366,8 @@ var FileStore = class {
|
|
|
296
366
|
throw error;
|
|
297
367
|
}
|
|
298
368
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
const lockPath = `${filePath}.lock`;
|
|
302
|
-
let deadline = Date.now() + LOCK_TIMEOUT_MS;
|
|
303
|
-
for (;;) try {
|
|
304
|
-
await mkdir(lockPath);
|
|
305
|
-
break;
|
|
306
|
-
} catch (error) {
|
|
307
|
-
if (error.code !== "EEXIST") throw error;
|
|
308
|
-
if (Date.now() >= deadline) {
|
|
309
|
-
await rmdir(lockPath).catch(ignoreMissing);
|
|
310
|
-
deadline = Date.now() + LOCK_TIMEOUT_MS;
|
|
311
|
-
continue;
|
|
312
|
-
}
|
|
313
|
-
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
314
|
-
}
|
|
315
|
-
try {
|
|
316
|
-
return await callback();
|
|
317
|
-
} finally {
|
|
318
|
-
await rmdir(lockPath).catch(ignoreMissing);
|
|
319
|
-
}
|
|
369
|
+
locked(filePath, callback) {
|
|
370
|
+
return withFileLock(`${filePath}.lock`, LOCK_TIMEOUT_MS, callback);
|
|
320
371
|
}
|
|
321
372
|
async deleteCacheFile(filePath) {
|
|
322
373
|
try {
|
|
@@ -349,7 +400,7 @@ var FileStore = class {
|
|
|
349
400
|
}
|
|
350
401
|
async add(key, value) {
|
|
351
402
|
const filePath = this.getFilePath(key);
|
|
352
|
-
return this.
|
|
403
|
+
return this.locked(filePath, async () => {
|
|
353
404
|
const item = await this.readCacheFile(filePath);
|
|
354
405
|
if (item && !this.isExpired(item)) return false;
|
|
355
406
|
await this.writeCacheFile(filePath, {
|
|
@@ -376,7 +427,7 @@ var FileStore = class {
|
|
|
376
427
|
}
|
|
377
428
|
async increment(key, value = 1) {
|
|
378
429
|
const filePath = this.getFilePath(key);
|
|
379
|
-
return this.
|
|
430
|
+
return this.locked(filePath, async () => {
|
|
380
431
|
const item = await this.readCacheFile(filePath);
|
|
381
432
|
const active = item && !this.isExpired(item) ? item : null;
|
|
382
433
|
const newValue = (active?.value ?? 0) + value;
|
|
@@ -456,6 +507,58 @@ var FileStore = class {
|
|
|
456
507
|
return this.basePath;
|
|
457
508
|
}
|
|
458
509
|
};
|
|
510
|
+
/**
|
|
511
|
+
* One running computation per key and TTL, shared by the callers that ask
|
|
512
|
+
* while it runs. The TTL is part of the match because it is what the
|
|
513
|
+
* computation stores: a caller asking for 60 seconds must not get a forever entry.
|
|
514
|
+
*/
|
|
515
|
+
var PendingComputations = class {
|
|
516
|
+
now;
|
|
517
|
+
pending = /* @__PURE__ */ new Map();
|
|
518
|
+
constructor(now = Date.now) {
|
|
519
|
+
this.now = now;
|
|
520
|
+
}
|
|
521
|
+
run(key, ttl, compute) {
|
|
522
|
+
const now = this.now();
|
|
523
|
+
const current = this.pending.get(key)?.get(ttl);
|
|
524
|
+
return (current && now - current.startedAt < 1e4 ? current : this.start(key, ttl, compute, now)).promise.then();
|
|
525
|
+
}
|
|
526
|
+
start(key, ttl, compute, now) {
|
|
527
|
+
const entry = {
|
|
528
|
+
promise: new Promise((resolve) => resolve(compute())),
|
|
529
|
+
startedAt: now
|
|
530
|
+
};
|
|
531
|
+
let byTtl = this.pending.get(key);
|
|
532
|
+
if (!byTtl) {
|
|
533
|
+
byTtl = /* @__PURE__ */ new Map();
|
|
534
|
+
this.pending.set(key, byTtl);
|
|
535
|
+
}
|
|
536
|
+
byTtl.set(ttl, entry);
|
|
537
|
+
const settle = () => {
|
|
538
|
+
const current = this.pending.get(key);
|
|
539
|
+
if (current?.get(ttl) !== entry) return;
|
|
540
|
+
current.delete(ttl);
|
|
541
|
+
if (current.size === 0) this.pending.delete(key);
|
|
542
|
+
};
|
|
543
|
+
entry.promise.then(settle, settle);
|
|
544
|
+
return entry;
|
|
545
|
+
}
|
|
546
|
+
forget(key) {
|
|
547
|
+
this.pending.delete(key);
|
|
548
|
+
}
|
|
549
|
+
forgetAll() {
|
|
550
|
+
this.pending.clear();
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
const byStore = /* @__PURE__ */ new WeakMap();
|
|
554
|
+
function pendingComputationsFor(store) {
|
|
555
|
+
let computations = byStore.get(store);
|
|
556
|
+
if (!computations) {
|
|
557
|
+
computations = new PendingComputations();
|
|
558
|
+
byStore.set(store, computations);
|
|
559
|
+
}
|
|
560
|
+
return computations;
|
|
561
|
+
}
|
|
459
562
|
//#endregion
|
|
460
563
|
//#region src/cache/TaggedCache.ts
|
|
461
564
|
/** Groups cache items by tags for bulk invalidation. */
|
|
@@ -463,10 +566,12 @@ var TaggedCache = class {
|
|
|
463
566
|
store;
|
|
464
567
|
tags;
|
|
465
568
|
tagSetPrefix;
|
|
569
|
+
pending;
|
|
466
570
|
constructor(store, tags, tagSetPrefix = "tag:") {
|
|
467
571
|
this.store = store;
|
|
468
572
|
this.tags = tags;
|
|
469
573
|
this.tagSetPrefix = tagSetPrefix;
|
|
574
|
+
this.pending = pendingComputationsFor(store);
|
|
470
575
|
}
|
|
471
576
|
async getTagNamespace() {
|
|
472
577
|
const namespaces = [];
|
|
@@ -509,6 +614,7 @@ var TaggedCache = class {
|
|
|
509
614
|
}
|
|
510
615
|
async set(key, value, ttl) {
|
|
511
616
|
const taggedKey = await this.taggedKey(key);
|
|
617
|
+
this.pending.forget(taggedKey);
|
|
512
618
|
await this.store.set(taggedKey, value, ttl);
|
|
513
619
|
await this.trackKey(taggedKey);
|
|
514
620
|
}
|
|
@@ -518,6 +624,7 @@ var TaggedCache = class {
|
|
|
518
624
|
}
|
|
519
625
|
async delete(key) {
|
|
520
626
|
const taggedKey = await this.taggedKey(key);
|
|
627
|
+
this.pending.forget(taggedKey);
|
|
521
628
|
return this.store.delete(taggedKey);
|
|
522
629
|
}
|
|
523
630
|
async clear() {
|
|
@@ -534,18 +641,22 @@ var TaggedCache = class {
|
|
|
534
641
|
return this.store.decrement(taggedKey, value);
|
|
535
642
|
}
|
|
536
643
|
async remember(key, ttl, callback) {
|
|
537
|
-
|
|
538
|
-
if (cached !== null) return cached;
|
|
539
|
-
const value = await callback();
|
|
540
|
-
await this.set(key, value, ttl);
|
|
541
|
-
return value;
|
|
644
|
+
return this.rememberAt(await this.taggedKey(key), ttl, callback);
|
|
542
645
|
}
|
|
543
646
|
async rememberForever(key, callback) {
|
|
544
|
-
|
|
647
|
+
return this.rememberAt(await this.taggedKey(key), void 0, callback);
|
|
648
|
+
}
|
|
649
|
+
async rememberAt(taggedKey, ttl, callback) {
|
|
650
|
+
const cached = await this.store.get(taggedKey);
|
|
545
651
|
if (cached !== null) return cached;
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
652
|
+
return this.pending.run(taggedKey, ttl, async () => {
|
|
653
|
+
const stored = await this.store.get(taggedKey);
|
|
654
|
+
if (stored !== null) return stored;
|
|
655
|
+
const value = await callback();
|
|
656
|
+
await this.store.set(taggedKey, value, ttl);
|
|
657
|
+
await this.trackKey(taggedKey);
|
|
658
|
+
return value;
|
|
659
|
+
});
|
|
549
660
|
}
|
|
550
661
|
async getMany(keys) {
|
|
551
662
|
const result = /* @__PURE__ */ new Map();
|
|
@@ -584,25 +695,36 @@ var TaggedCache = class {
|
|
|
584
695
|
};
|
|
585
696
|
//#endregion
|
|
586
697
|
//#region src/cache/CacheManager.ts
|
|
587
|
-
/**
|
|
698
|
+
/**
|
|
699
|
+
* Adds tag support to any cache store, and shares one `remember` callback
|
|
700
|
+
* between the callers that miss the same key with the same TTL at once. A hit
|
|
701
|
+
* is read on its own, so hits get what `get` returns. A write to a key forgets
|
|
702
|
+
* its running computation, so a later miss does not join one that started
|
|
703
|
+
* before the write.
|
|
704
|
+
*/
|
|
588
705
|
var TaggableCacheStoreWrapper = class {
|
|
589
706
|
store;
|
|
707
|
+
pending;
|
|
590
708
|
constructor(store) {
|
|
591
709
|
this.store = store;
|
|
710
|
+
this.pending = pendingComputationsFor(store);
|
|
592
711
|
}
|
|
593
712
|
get(key) {
|
|
594
713
|
return this.store.get(key);
|
|
595
714
|
}
|
|
596
715
|
set(key, value, ttl) {
|
|
716
|
+
this.pending.forget(key);
|
|
597
717
|
return this.store.set(key, value, ttl);
|
|
598
718
|
}
|
|
599
719
|
has(key) {
|
|
600
720
|
return this.store.has(key);
|
|
601
721
|
}
|
|
602
722
|
delete(key) {
|
|
723
|
+
this.pending.forget(key);
|
|
603
724
|
return this.store.delete(key);
|
|
604
725
|
}
|
|
605
726
|
clear() {
|
|
727
|
+
this.pending.forgetAll();
|
|
606
728
|
return this.store.clear();
|
|
607
729
|
}
|
|
608
730
|
increment(key, value) {
|
|
@@ -612,18 +734,25 @@ var TaggableCacheStoreWrapper = class {
|
|
|
612
734
|
return this.store.decrement(key, value);
|
|
613
735
|
}
|
|
614
736
|
remember(key, ttl, callback) {
|
|
615
|
-
return this.store.remember(key, ttl, callback);
|
|
737
|
+
return this.rememberOnMiss(key, ttl, () => this.store.remember(key, ttl, callback));
|
|
616
738
|
}
|
|
617
739
|
rememberForever(key, callback) {
|
|
618
|
-
return this.store.rememberForever(key, callback);
|
|
740
|
+
return this.rememberOnMiss(key, void 0, () => this.store.rememberForever(key, callback));
|
|
741
|
+
}
|
|
742
|
+
async rememberOnMiss(key, ttl, remember) {
|
|
743
|
+
const cached = await this.store.get(key);
|
|
744
|
+
if (cached !== null) return cached;
|
|
745
|
+
return this.pending.run(key, ttl, remember);
|
|
619
746
|
}
|
|
620
747
|
getMany(keys) {
|
|
621
748
|
return this.store.getMany(keys);
|
|
622
749
|
}
|
|
623
750
|
setMany(items, ttl) {
|
|
751
|
+
for (const key of items.keys()) this.pending.forget(key);
|
|
624
752
|
return this.store.setMany(items, ttl);
|
|
625
753
|
}
|
|
626
754
|
deleteMany(keys) {
|
|
755
|
+
for (const key of keys) this.pending.forget(key);
|
|
627
756
|
return this.store.deleteMany(keys);
|
|
628
757
|
}
|
|
629
758
|
ttl(key) {
|
|
@@ -638,6 +767,8 @@ var CacheManager = class {
|
|
|
638
767
|
defaultStoreName;
|
|
639
768
|
storeFactories = /* @__PURE__ */ new Map();
|
|
640
769
|
resolvedStores = /* @__PURE__ */ new Map();
|
|
770
|
+
/** The configured driver per store, keyed like `storeFactories`; null for a bare `registerStore()` factory. */
|
|
771
|
+
storeDrivers = /* @__PURE__ */ new Map();
|
|
641
772
|
/**
|
|
642
773
|
* Where this manager was built, for identifying its stores across hot reloads.
|
|
643
774
|
* Captured here rather than in `store()` because stores resolve lazily, from
|
|
@@ -650,7 +781,10 @@ var CacheManager = class {
|
|
|
650
781
|
this.defaultStoreName = config.default ?? "memory";
|
|
651
782
|
this.registerBuiltinDrivers();
|
|
652
783
|
if (config.stores) for (const [name, storeConfig] of Object.entries(config.stores)) this.registerStoreFromConfig(name, storeConfig);
|
|
653
|
-
if (!this.storeFactories.has(this.defaultStoreName) && this.defaultStoreName === "memory")
|
|
784
|
+
if (!this.storeFactories.has(this.defaultStoreName) && this.defaultStoreName === "memory") {
|
|
785
|
+
this.storeFactories.set("memory", () => new MemoryStore());
|
|
786
|
+
this.storeDrivers.set("memory", "memory");
|
|
787
|
+
}
|
|
654
788
|
}
|
|
655
789
|
driverFactories = /* @__PURE__ */ new Map();
|
|
656
790
|
registerBuiltinDrivers() {
|
|
@@ -669,6 +803,7 @@ var CacheManager = class {
|
|
|
669
803
|
const factory = this.driverFactories.get(driver);
|
|
670
804
|
if (!factory) throw new Error(`Unknown cache driver: ${driver}`);
|
|
671
805
|
this.storeFactories.set(name, () => factory(options));
|
|
806
|
+
this.storeDrivers.set(name, driver);
|
|
672
807
|
}
|
|
673
808
|
/** Returns the default store if no name is given. */
|
|
674
809
|
store(name) {
|
|
@@ -695,6 +830,7 @@ var CacheManager = class {
|
|
|
695
830
|
}
|
|
696
831
|
registerStore(name, factory) {
|
|
697
832
|
this.storeFactories.set(name, factory);
|
|
833
|
+
this.storeDrivers.set(name, null);
|
|
698
834
|
this.resolvedStores.delete(name);
|
|
699
835
|
}
|
|
700
836
|
registerDriver(name, factory) {
|
|
@@ -709,6 +845,10 @@ var CacheManager = class {
|
|
|
709
845
|
getStoreNames() {
|
|
710
846
|
return Array.from(this.storeFactories.keys());
|
|
711
847
|
}
|
|
848
|
+
/** The declared stores and the default, building none of them (RFC 0026 §1). */
|
|
849
|
+
describe() {
|
|
850
|
+
return describeDriverMap(this.defaultStoreName, this.storeDrivers);
|
|
851
|
+
}
|
|
712
852
|
};
|
|
713
853
|
function createCacheManager(config) {
|
|
714
854
|
return new CacheManager(config);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Container } from './Container.js';
|
|
2
2
|
import type { Provider } from './types.js';
|
|
3
|
+
import type { ManifestWarning, ProviderEntry, ProviderSource } from '../introspection/types.js';
|
|
3
4
|
/**
|
|
4
5
|
* Constructor shape accepted wherever a provider class can be registered.
|
|
5
6
|
*/
|
|
@@ -20,6 +21,12 @@ export declare abstract class ServiceProvider implements Provider {
|
|
|
20
21
|
abstract register(): void | Promise<void>;
|
|
21
22
|
/** Runs after all providers have registered. */
|
|
22
23
|
boot?(): void | Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Runs in place of `register()` under introspection (RFC 0026 §2). Bind only
|
|
26
|
+
* what the manifest describes; leave anything that connects or reads a runtime
|
|
27
|
+
* binding to `register()`. Absent, introspection runs `register()` unchanged.
|
|
28
|
+
*/
|
|
29
|
+
introspect?(): void | Promise<void>;
|
|
23
30
|
provides(): string[];
|
|
24
31
|
isDeferred(): boolean;
|
|
25
32
|
}
|
|
@@ -28,6 +35,11 @@ export interface OwnedBinding {
|
|
|
28
35
|
readonly binding: unknown;
|
|
29
36
|
readonly source: string;
|
|
30
37
|
}
|
|
38
|
+
/** @internal Where a provider came from, for the manifest's `providers[].source`. */
|
|
39
|
+
export interface ProviderOrigin {
|
|
40
|
+
readonly source: ProviderSource;
|
|
41
|
+
readonly module?: string;
|
|
42
|
+
}
|
|
31
43
|
/**
|
|
32
44
|
* Provider manager for registering and booting providers.
|
|
33
45
|
*/
|
|
@@ -41,10 +53,23 @@ export declare class ProviderManager {
|
|
|
41
53
|
private deferredActivations;
|
|
42
54
|
private bindingOwners;
|
|
43
55
|
private allBooted;
|
|
56
|
+
/** Every provider in registration order, deferred ones included, with where it came from. */
|
|
57
|
+
private readonly origins;
|
|
44
58
|
constructor(container: Container);
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
/** `origin` is internal: `Application` passes it for the manifest (RFC 0026). */
|
|
60
|
+
register(providerOrClass: ServiceProvider | ServiceProviderConstructor, origin?: ProviderOrigin): this;
|
|
61
|
+
/** `origin` is internal, as on {@link register}. */
|
|
62
|
+
registerMany(providers: Array<ServiceProvider | ServiceProviderConstructor>, origin?: ProviderOrigin): this;
|
|
47
63
|
registerAll(): Promise<void>;
|
|
64
|
+
private registerOne;
|
|
65
|
+
/**
|
|
66
|
+
* @internal `registerAll()` for introspection (RFC 0026 §2): `introspect()` where a
|
|
67
|
+
* provider has one, and a throw is recorded rather than stopping the rest.
|
|
68
|
+
* Deferred providers are reported `skipped`; they register only after boot.
|
|
69
|
+
*/
|
|
70
|
+
registerAllForIntrospection(): Promise<ProviderEntry[]>;
|
|
71
|
+
/** @internal Findings registered providers hold for the manifest, each named after its provider. */
|
|
72
|
+
manifestWarnings(): ManifestWarning[];
|
|
48
73
|
private assertOwnedBindingsKept;
|
|
49
74
|
bootAll(): Promise<void>;
|
|
50
75
|
/**
|
|
@@ -51,10 +51,9 @@ export interface GurenModule {
|
|
|
51
51
|
/** Define a Guren application module without boilerplate. */
|
|
52
52
|
export declare function defineModule(definition: ModuleDefinition): GurenModule;
|
|
53
53
|
/**
|
|
54
|
-
* Runs a module's route registrar
|
|
55
|
-
* Shared by `Application.mountRoutes()` and the CLI's route loader, so both see
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* inside an async prefixed registrar run with the prefix already popped.
|
|
54
|
+
* Runs a module's route registrar under its `prefix` and names the module on each route it added.
|
|
55
|
+
* Shared by `Application.mountRoutes()` and the CLI's route loader, so both see the same route set.
|
|
56
|
+
* `router.group()`'s callback is synchronous, so route calls made after an `await` inside an
|
|
57
|
+
* async prefixed registrar run with the prefix already popped (and still carry the module).
|
|
59
58
|
*/
|
|
60
59
|
export declare function mountModuleRoutes(router: Router, gurenModule: GurenModule): Promise<void>;
|
|
@@ -11,6 +11,8 @@ export interface PluginDefinition<TConfig = void> {
|
|
|
11
11
|
register(container: Container, config: TConfig): void | Promise<void>;
|
|
12
12
|
/** Called after all providers have registered. */
|
|
13
13
|
boot?(container: Container, config: TConfig): void | Promise<void>;
|
|
14
|
+
/** Called in place of `register` under introspection (RFC 0026 §2); see `ServiceProvider.introspect`. */
|
|
15
|
+
introspect?(container: Container, config: TConfig): void | Promise<void>;
|
|
14
16
|
/** Defer instantiation until one of `provides` is resolved. */
|
|
15
17
|
deferred?: boolean;
|
|
16
18
|
/** Services bound by this plugin; required when `deferred` is true. */
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-B4FMCO8f.js";
|
|
2
|
+
import { n as isWildcardHost, t as formatHostPort } from "./host-port-t6wQFaRu.js";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import figlet from "figlet";
|
|
5
|
+
import standard from "figlet/importable-fonts/Standard.js";
|
|
6
|
+
//#region package.json
|
|
7
|
+
var version = "2.27.0";
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/http/dev-banner.ts
|
|
10
|
+
var dev_banner_exports = /* @__PURE__ */ __exportAll({
|
|
11
|
+
GUREN_ASCII_ART: () => GUREN_ASCII_ART,
|
|
12
|
+
logDevServerBanner: () => logDevServerBanner
|
|
13
|
+
});
|
|
14
|
+
figlet.parseFont("Standard", standard);
|
|
15
|
+
function generateAsciiArt(text) {
|
|
16
|
+
try {
|
|
17
|
+
return figlet.textSync(text, {
|
|
18
|
+
font: "Standard",
|
|
19
|
+
horizontalLayout: "default",
|
|
20
|
+
verticalLayout: "default"
|
|
21
|
+
});
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error("Failed to generate FIGlet banner, falling back to plain text:", error);
|
|
24
|
+
return text.toUpperCase();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const GUREN_ASCII_ART = chalk.redBright.bold(generateAsciiArt("GUREN"));
|
|
28
|
+
const GUREN_VERSION = version;
|
|
29
|
+
function logDevServerBanner({ hostname, port, assetsUrl = "http://localhost:5173" }) {
|
|
30
|
+
const localUrl = `http://localhost:${port}`;
|
|
31
|
+
const boundUrl = `http://${formatHostPort(hostname, port)}`;
|
|
32
|
+
const boundLabel = isWildcardHost(hostname) ? " (all interfaces)" : "";
|
|
33
|
+
const header = [
|
|
34
|
+
GUREN_ASCII_ART,
|
|
35
|
+
chalk.magentaBright.bold(`Guren v${GUREN_VERSION} ignites — burning bright like a crimson lotus.`),
|
|
36
|
+
""
|
|
37
|
+
];
|
|
38
|
+
const detail = (label, value) => `${chalk.magentaBright(" •")} ${chalk.bold(label.padEnd(14))}: ${chalk.cyanBright(value)}`;
|
|
39
|
+
const banner = [
|
|
40
|
+
...header,
|
|
41
|
+
detail("App URL", localUrl),
|
|
42
|
+
detail("Bound address", `${boundUrl}${boundLabel}`),
|
|
43
|
+
detail("Asset server", `${assetsUrl} (Vite)`),
|
|
44
|
+
"",
|
|
45
|
+
chalk.yellowBright("Press Ctrl+C to douse the flames."),
|
|
46
|
+
""
|
|
47
|
+
].join("\n");
|
|
48
|
+
console.log(banner);
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { dev_banner_exports as n, logDevServerBanner as r, GUREN_ASCII_ART as t };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PATH_PARAM_PATTERN } from "./internal/route-path.js";
|
|
2
|
+
import { t as AGENT_SURFACE_HEADER } from "./agent-request-Caj6bnbj.js";
|
|
2
3
|
//#region src/internal/agent-preflight.ts
|
|
3
4
|
/**
|
|
4
5
|
* The wire protocol of an agent preflight (RFC 0016 §5.4), in a leaf module so
|
|
@@ -17,6 +18,27 @@ const AGENT_PREFLIGHT_HEADER = "X-Guren-Agent-Preflight";
|
|
|
17
18
|
*/
|
|
18
19
|
const AGENT_PREFLIGHT_VERDICT_HEADER = "X-Guren-Agent-Preflight-Verdict";
|
|
19
20
|
//#endregion
|
|
21
|
+
//#region src/internal/dispatched-request.ts
|
|
22
|
+
/**
|
|
23
|
+
* Which `Request` objects the agent dispatcher built (RFC 0016 §3), keyed on
|
|
24
|
+
* **object identity** like the principal seam in `agent-principal.ts`: a
|
|
25
|
+
* request that crosses a socket arrives as a new object and carries nothing,
|
|
26
|
+
* so seeing the mark means the request was handed to `app.fetch` in this
|
|
27
|
+
* process. Not `isAgentToolRequest()` in `agent-request.ts`, whose header any
|
|
28
|
+
* client can send: that one only picks the shape of a refusal.
|
|
29
|
+
* Not exported from the package index.
|
|
30
|
+
*/
|
|
31
|
+
const dispatched = /* @__PURE__ */ new WeakSet();
|
|
32
|
+
/** Mark `request` as built by `buildToolRequest`, returning that same object. */
|
|
33
|
+
function markDispatchedToolRequest(request) {
|
|
34
|
+
dispatched.add(request);
|
|
35
|
+
return request;
|
|
36
|
+
}
|
|
37
|
+
/** Whether this exact object was built by the dispatcher in this process. */
|
|
38
|
+
function isDispatchedToolRequest(request) {
|
|
39
|
+
return dispatched.has(request);
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
20
42
|
//#region src/agent/dispatch.ts
|
|
21
43
|
/** How many characters of a non-JSON response body survive into the result. */
|
|
22
44
|
const TEXT_RESPONSE_CAP = 5e4;
|
|
@@ -79,7 +101,7 @@ function buildToolRequest(tool, args, options = {}) {
|
|
|
79
101
|
}
|
|
80
102
|
const headers = new Headers({
|
|
81
103
|
Accept: "application/json",
|
|
82
|
-
|
|
104
|
+
[AGENT_SURFACE_HEADER]: options.surface ?? "mcp"
|
|
83
105
|
});
|
|
84
106
|
if (options.authorization) headers.set("Authorization", options.authorization);
|
|
85
107
|
if (options.preflight) headers.set(AGENT_PREFLIGHT_HEADER, "1");
|
|
@@ -92,11 +114,11 @@ function buildToolRequest(tool, args, options = {}) {
|
|
|
92
114
|
if (body !== void 0) headers.set("Content-Type", "application/json");
|
|
93
115
|
const qs = query.toString();
|
|
94
116
|
const url = `${origin}${path}${qs ? `?${qs}` : ""}`;
|
|
95
|
-
return { request: new Request(url, {
|
|
117
|
+
return { request: markDispatchedToolRequest(new Request(url, {
|
|
96
118
|
method,
|
|
97
119
|
headers,
|
|
98
120
|
body
|
|
99
|
-
}) };
|
|
121
|
+
})) };
|
|
100
122
|
}
|
|
101
123
|
/**
|
|
102
124
|
* The contract a property was declared under, or undefined if the derivation
|
|
@@ -235,4 +257,4 @@ function isRecord(value) {
|
|
|
235
257
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
236
258
|
}
|
|
237
259
|
//#endregion
|
|
238
|
-
export { mapToolResponse as a, describeBuildFailure as i, advertisesStructuredOutput as n,
|
|
260
|
+
export { mapToolResponse as a, AGENT_PREFLIGHT_VERDICT_HEADER as c, describeBuildFailure as i, advertisesStructuredOutput as n, isDispatchedToolRequest as o, buildToolRequest as r, AGENT_PREFLIGHT_HEADER as s, PREFLIGHT_ARGUMENT as t };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/introspection/driver-map.ts
|
|
2
|
+
/** `DriverMapEntry` from a manager's entries, each with the driver it was configured with or null. */
|
|
3
|
+
function describeDriverMap(defaultName, drivers) {
|
|
4
|
+
const entries = {};
|
|
5
|
+
for (const [name, driver] of drivers) entries[name] = { driver };
|
|
6
|
+
return {
|
|
7
|
+
default: defaultName,
|
|
8
|
+
entries
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { describeDriverMap as t };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/http/host-port.ts
|
|
2
|
+
/**
|
|
3
|
+
* A wildcard bind answers on every interface but is not itself dialable on
|
|
4
|
+
* every platform. The dev banner and `Application.listen()`'s returned address
|
|
5
|
+
* both render this fact.
|
|
6
|
+
*/
|
|
7
|
+
function isWildcardHost(hostname) {
|
|
8
|
+
return hostname === "0.0.0.0" || hostname === "::";
|
|
9
|
+
}
|
|
10
|
+
/** `host:port`, bracketing an IPv6 literal so the result is dialable. */
|
|
11
|
+
function formatHostPort(hostname, port) {
|
|
12
|
+
return `${hostname.includes(":") ? `[${hostname}]` : hostname}:${port}`;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { isWildcardHost as n, formatHostPort as t };
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* Runs `callback` with the registry's `--hot` guard satisfied. The guard reads
|
|
7
|
-
* `process.execArgv`, which is also how the real thing detects `bun --hot`.
|
|
7
|
+
* `process.execArgv`, which is also how the real thing detects `bun --hot`. A
|
|
8
|
+
* callback returning a promise keeps the flag until that promise settles.
|
|
8
9
|
*/
|
|
9
10
|
export declare function withHotRuntime<T>(callback: () => T): T;
|
|
@@ -11,12 +11,13 @@ import type { DetectLocaleOptions } from './middleware/detect-locale.js';
|
|
|
11
11
|
import type { TranslationLoader } from '../i18n/index.js';
|
|
12
12
|
import { type SecurityHeadersOptions } from './middleware/security-headers.js';
|
|
13
13
|
import { type HostAuthorizationOptions } from './middleware/host-authorization.js';
|
|
14
|
-
import {
|
|
14
|
+
import type { DevBannerOptions } from './dev-banner.js';
|
|
15
15
|
import { startViteDevServer, type StartViteDevServerOptions } from './vite-dev-server.js';
|
|
16
16
|
import type { InertiaDocumentOptions, InertiaSsrRenderer } from '../mvc/inertia/InertiaEngine.js';
|
|
17
17
|
import { type SharedInertiaPropsResolver } from '../mvc/inertia/shared.js';
|
|
18
18
|
import type { EnvSchema } from '../config/env.js';
|
|
19
19
|
import type { ConfigDefinition } from '../config/define.js';
|
|
20
|
+
import type { AppManifest } from '../introspection/types.js';
|
|
20
21
|
type BunServer = {
|
|
21
22
|
stop?: (closeConnections?: boolean) => void | Promise<void>;
|
|
22
23
|
requestIP?: (request: Request) => {
|
|
@@ -195,6 +196,8 @@ export declare class Application {
|
|
|
195
196
|
readonly configEntries: ReadonlyArray<ConfiguredDefinition>;
|
|
196
197
|
private routesRegistered;
|
|
197
198
|
private bootPromise?;
|
|
199
|
+
private manifestPromise?;
|
|
200
|
+
private bootAttempted;
|
|
198
201
|
constructor(options?: ApplicationOptions);
|
|
199
202
|
get auth(): AuthManager;
|
|
200
203
|
get authOptions(): AuthPluginOptions | undefined;
|
|
@@ -217,6 +220,8 @@ export declare class Application {
|
|
|
217
220
|
/** Matched by exact path — see {@link declareCookielessAuthPath}. */
|
|
218
221
|
getCookielessAuthPaths(): ReadonlySet<string>;
|
|
219
222
|
mountRoutes(): Promise<void>;
|
|
223
|
+
/** Runs the registrars once; `introspect()` stops here, since mounting refuses an unregistered alias it reports. */
|
|
224
|
+
private registerRoutes;
|
|
220
225
|
/**
|
|
221
226
|
* Every failure here is one a request would otherwise surface as a 500:
|
|
222
227
|
* an unnamed prototype route cannot be looked up, a named one the fixture
|
|
@@ -241,6 +246,13 @@ export declare class Application {
|
|
|
241
246
|
* unbooted. Never await it from a provider's own `boot`: it waits on itself.
|
|
242
247
|
*/
|
|
243
248
|
booted(): Promise<void>;
|
|
249
|
+
/**
|
|
250
|
+
* Registers providers and routes, then describes the result (RFC 0026 §1).
|
|
251
|
+
* Never mounts on Hono or runs `createApp({ boot })`, a provider's `boot()`
|
|
252
|
+
* or `listen()`. Memoised; the application cannot boot afterwards.
|
|
253
|
+
*/
|
|
254
|
+
introspect(): Promise<AppManifest>;
|
|
255
|
+
private introspectOnce;
|
|
244
256
|
private bootOnce;
|
|
245
257
|
/**
|
|
246
258
|
* After every provider has booted: `auth` was asked for, yet the default
|
|
@@ -286,6 +298,12 @@ export declare class Application {
|
|
|
286
298
|
stop(closeActiveConnections?: boolean): Promise<void>;
|
|
287
299
|
register(provider: ServiceProviderConstructor): this;
|
|
288
300
|
registerMany(providers: Array<ServiceProviderConstructor>): this;
|
|
301
|
+
/**
|
|
302
|
+
* Prints the dev server banner. `listen()` loads the banner module first, so it
|
|
303
|
+
* prints there at once; a call before anything has loaded it prints once the
|
|
304
|
+
* import settles. The module is never loaded under `NODE_ENV=production`, which
|
|
305
|
+
* keeps it out of deploy bundles, so a call there prints nothing.
|
|
306
|
+
*/
|
|
289
307
|
logDevServerBanner(options: DevBannerOptions): void;
|
|
290
308
|
/**
|
|
291
309
|
* Closes the managed Vite dev server, but only while this application still
|
|
@@ -4,12 +4,4 @@ export interface DevBannerOptions {
|
|
|
4
4
|
port: number;
|
|
5
5
|
assetsUrl?: string;
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
8
|
-
* A wildcard bind answers on every interface but is not itself dialable on
|
|
9
|
-
* every platform. Shared with `Application.listen()`'s returned address, which
|
|
10
|
-
* is the same fact rendered twice.
|
|
11
|
-
*/
|
|
12
|
-
export declare function isWildcardHost(hostname: string): boolean;
|
|
13
|
-
/** `host:port`, bracketing an IPv6 literal so the result is dialable. */
|
|
14
|
-
export declare function formatHostPort(hostname: string, port: number): string;
|
|
15
7
|
export declare function logDevServerBanner({ hostname, port, assetsUrl, }: DevBannerOptions): void;
|