@guren/server 2.35.0 → 2.36.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-BVPZjwQp.js → DocsViewerServiceProvider-DzrxQoYh.js} +15 -4
- package/dist/Event-COT3f5Xd.js +28 -0
- package/dist/{McpServiceProvider-CXOokGax.js → McpServiceProvider-BOeQyt7u.js} +2 -0
- package/dist/PrivateChannel-1krGz028.js +187 -0
- package/dist/{Resource-y-7zzZSB.js → Resource-PhnO_wNO.js} +113 -12
- package/dist/agent/derive.d.ts +23 -1
- package/dist/agent/dispatch.d.ts +12 -1
- package/dist/agent/pipeline.d.ts +6 -0
- package/dist/agent/public.d.ts +1 -1
- package/dist/agent/public.js +1 -1
- package/dist/{api-token-1-INqeVU.js → api-token-Cs1myxf6.js} +15 -1
- package/dist/auth/index.js +2 -2
- package/dist/{auth-CO9MlQNE.js → auth-DYWBlmpS.js} +1 -1
- package/dist/broadcasting/BroadcastManager.d.ts +19 -5
- package/dist/broadcasting/event-target.d.ts +9 -0
- package/dist/broadcasting/index.d.ts +3 -1
- package/dist/broadcasting/index.js +3 -2
- package/dist/broadcasting/sender-envelope.d.ts +26 -0
- package/dist/broadcasting/types.d.ts +27 -2
- package/dist/{broadcasting-D04a3R02.js → broadcasting-Bh6QoMpy.js} +50 -95
- package/dist/{contained-path-BkNSBljW.js → contained-path-DOVauNQC.js} +1 -22
- package/dist/{dev-banner-BUrHz-LF.js → dev-banner-DGxB3HGY.js} +3 -3
- package/dist/{dispatch-ENWpBxbE.js → dispatch-CDNqcB3Q.js} +51 -12
- package/dist/events/index.js +2 -1
- package/dist/{events-B6gfJkCH.js → events-DW197Nur.js} +2 -28
- package/dist/http/vite-dev-server.d.ts +18 -1
- package/dist/http/vite-manifest.d.ts +4 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +109 -22
- package/dist/internal/agent-principal.d.ts +8 -0
- package/dist/internal/testing.d.ts +1 -0
- package/dist/internal/testing.js +2 -2
- package/dist/mcp/index.js +1 -1
- package/dist/mvc/Router.d.ts +13 -0
- package/dist/mvc/inertia/InertiaEngine.d.ts +3 -0
- package/dist/mvc/inertia/props.d.ts +54 -3
- package/dist/runtime/index.js +5 -3
- package/dist/storage/index.js +1 -1
- package/dist/{storage-YPbsV9ju.js → storage-ziIKgHON.js} +2 -1
- package/dist/trim-slashes-BLY9hKAa.js +22 -0
- package/dist/vite/index.d.ts +2 -0
- package/dist/vite/index.js +283 -1
- package/dist/vite/mcp-app.d.ts +59 -0
- package/dist/vite/plugin.d.ts +12 -0
- package/dist/{vite-manifest-DO0pU1vm.js → vite-dev-server-Ag90otai.js} +25 -114
- package/dist/vite-manifest-BdXRybeq.js +129 -0
- package/package.json +1 -1
- package/dist/host-port-t6wQFaRu.js +0 -15
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BroadcastDriver, BroadcastDriverFactory, BroadcastManagerOptions, ChannelAuthorizer, PresenceChannelAuthorizer, ChannelRegistration, SSEMiddlewareOptions, WebSocketMiddlewareOptions, AuthMiddlewareOptions, SSEClient, WebSocketClient, BroadcastEvent } from './types.js';
|
|
1
|
+
import type { BroadcastDriver, BroadcastDriverFactory, BroadcastManagerOptions, ChannelAuthorizer, PresenceChannelAuthorizer, ChannelRegistration, SSEMiddlewareOptions, WebSocketMiddlewareOptions, AuthMiddlewareOptions, SSEClient, WebSocketClient, BroadcastEvent, BroadcastEventOptions, BroadcastableEvent } from './types.js';
|
|
2
2
|
import { Channel, PrivateChannel, PresenceChannel } from './channels/index.js';
|
|
3
3
|
import type { Middleware } from '../http/middleware/index.js';
|
|
4
4
|
/** Broadcast manager for real-time event broadcasting. */
|
|
@@ -23,6 +23,20 @@ export declare class BroadcastManager {
|
|
|
23
23
|
privateChannel(pattern: string, authorizer: ChannelAuthorizer): this;
|
|
24
24
|
presenceChannel(pattern: string, authorizer: PresenceChannelAuthorizer): this;
|
|
25
25
|
broadcast(channelName: string, event: string, data: unknown): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Publishes `broadcastWith()` (else `{}`) as `broadcastNameOf(event)` on every
|
|
28
|
+
* channel `broadcastOn()` names: the name a `live()` prop listening for this
|
|
29
|
+
* event subscribes to.
|
|
30
|
+
*/
|
|
31
|
+
broadcastEvent(event: BroadcastableEvent, options?: BroadcastEventOptions): Promise<void>;
|
|
32
|
+
/** A sender is only worth marking with a socket id this manager could have issued and a user to bind it to. */
|
|
33
|
+
private resolveSender;
|
|
34
|
+
/**
|
|
35
|
+
* What one client receives of a delivered event: nothing when it is the
|
|
36
|
+
* sender's own socket, else the payload without the reserved fields. The ids
|
|
37
|
+
* compare strictly, as `authMiddleware()` compares an owner: `7` is not `'7'`.
|
|
38
|
+
*/
|
|
39
|
+
private deliveryFor;
|
|
26
40
|
toChannel(name: string): Channel;
|
|
27
41
|
toPrivate(name: string): PrivateChannel;
|
|
28
42
|
toPresence(name: string): PresenceChannel;
|
|
@@ -37,9 +51,9 @@ export declare class BroadcastManager {
|
|
|
37
51
|
/**
|
|
38
52
|
* A route that upgrades to a WebSocket carrying broadcast events, the socket
|
|
39
53
|
* counterpart of `sseMiddleware()`; it needs `Application.listen()` on Bun.
|
|
40
|
-
*
|
|
41
|
-
* `{ clientId, channels }
|
|
42
|
-
* channel }`, answered by
|
|
54
|
+
* JSON frames: an event `{ event, channel, data }`, the server's own `{ event, data }`
|
|
55
|
+
* (first `connected` with `{ clientId, socketId, channels }`). The client sends
|
|
56
|
+
* `{ action: 'subscribe' | 'unsubscribe', channel }`, answered by `subscription`.
|
|
43
57
|
*/
|
|
44
58
|
webSocketMiddleware(options?: WebSocketMiddlewareOptions): Middleware;
|
|
45
59
|
private handleWebSocketMessage;
|
|
@@ -64,7 +78,7 @@ export declare class BroadcastManager {
|
|
|
64
78
|
*/
|
|
65
79
|
protected releaseDriverSubscriptions(clientId: string): void;
|
|
66
80
|
/** Returns the generated client ID. */
|
|
67
|
-
registerWebSocketClient(client: Omit<WebSocketClient, 'id' | 'channels'> & {
|
|
81
|
+
registerWebSocketClient(client: Omit<WebSocketClient, 'id' | 'channels' | 'socketId'> & {
|
|
68
82
|
userId?: string | number;
|
|
69
83
|
}): string;
|
|
70
84
|
removeWebSocketClient(clientId: string): boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BroadcastableEvent } from './types.js';
|
|
2
|
+
/** An event as `live()` and `broadcastEvent()` read it. `eventName` is `Event`'s own getter. */
|
|
3
|
+
export type BroadcastTarget = Pick<BroadcastableEvent, 'broadcastOn' | 'broadcastAs'> & {
|
|
4
|
+
readonly eventName?: string;
|
|
5
|
+
};
|
|
6
|
+
/** `broadcastAs()`, else the event's `eventName`, else its class name. */
|
|
7
|
+
export declare function broadcastNameOf(event: BroadcastTarget): string;
|
|
8
|
+
/** The wire names `broadcastOn()` returns, prefix included, verbatim. */
|
|
9
|
+
export declare function broadcastChannelsOf(event: BroadcastTarget): string[];
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export type { BroadcastEvent, BroadcastDriver, PresenceBroadcastDriver, ChannelAuthorizer, PresenceChannelAuthorizer, PresenceMember, SSEClient, WebSocketClient, BroadcastManagerOptions, BroadcastDriverFactory, ChannelRegistration, SSEMiddlewareOptions, WebSocketMiddlewareOptions, AuthMiddlewareOptions, BroadcastableEvent, } from './types.js';
|
|
1
|
+
export type { BroadcastEvent, BroadcastDriver, PresenceBroadcastDriver, ChannelAuthorizer, PresenceChannelAuthorizer, PresenceMember, SSEClient, WebSocketClient, BroadcastManagerOptions, BroadcastDriverFactory, ChannelRegistration, SSEMiddlewareOptions, WebSocketMiddlewareOptions, AuthMiddlewareOptions, BroadcastableEvent, BroadcastEventOptions, BroadcastSender, } from './types.js';
|
|
2
2
|
export { BroadcastManager, setBroadcastManager, getBroadcastManager, createBroadcastManager, } from './BroadcastManager.js';
|
|
3
3
|
export { createTypedBroadcaster, } from './typed.js';
|
|
4
|
+
export { broadcastChannelsOf, broadcastNameOf } from './event-target.js';
|
|
5
|
+
export type { BroadcastTarget } from './event-target.js';
|
|
4
6
|
export type { TypedBroadcaster, TypedChannelHandle, TypedPrivateChannelHandle, TypedPresenceChannelHandle, } from './typed.js';
|
|
5
7
|
export { Channel, PrivateChannel, PresenceChannel } from './channels/index.js';
|
|
6
8
|
export { MemoryDriver, RedisDriver, type MemoryDriverOptions, type RedisClient, type RedisDriverOptions, } from './drivers/index.js';
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { l as broadcastChannelsOf, n as PresenceChannel, r as Channel, t as PrivateChannel, u as broadcastNameOf } from "../PrivateChannel-1krGz028.js";
|
|
2
|
+
import { a as setBroadcastManager, i as getBroadcastManager, n as BroadcastManager, o as RedisDriver, r as createBroadcastManager, s as MemoryDriver, t as createTypedBroadcaster } from "../broadcasting-Bh6QoMpy.js";
|
|
3
|
+
export { BroadcastManager, Channel, MemoryDriver, PresenceChannel, PrivateChannel, RedisDriver, broadcastChannelsOf, broadcastNameOf, createBroadcastManager, createTypedBroadcaster, getBroadcastManager, setBroadcastManager };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sender of a broadcast, carried inside its payload (RFC 0037 §4) so every
|
|
3
|
+
* driver passes it across instances. `__inertia.socketId` and `__inertia.userId`
|
|
4
|
+
* are reserved: every manager publish path strips them from what the app passes
|
|
5
|
+
* before marking, so a relayed payload cannot forge a mark, and delivery strips
|
|
6
|
+
* them before any client sees the payload.
|
|
7
|
+
*/
|
|
8
|
+
export interface BroadcastSenderMark {
|
|
9
|
+
readonly socketId: string;
|
|
10
|
+
readonly userId: string | number;
|
|
11
|
+
}
|
|
12
|
+
export declare function isSocketId(value: unknown): value is string;
|
|
13
|
+
/** A user id that survives JSON as itself: `NaN` and the infinities become `null` on the Redis driver. */
|
|
14
|
+
export declare function isSenderUserId(value: unknown): value is string | number;
|
|
15
|
+
/**
|
|
16
|
+
* The payload with the sender added. An object that is not plain (a class
|
|
17
|
+
* instance, one with `toJSON()`) is marked as the JSON a client would receive;
|
|
18
|
+
* an array or a primitive cannot carry a mark.
|
|
19
|
+
*/
|
|
20
|
+
export declare function markSender(data: unknown, sender: BroadcastSenderMark): unknown;
|
|
21
|
+
export declare function readSender(data: unknown): BroadcastSenderMark | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* The payload without the reserved fields, valid or not, and without the
|
|
24
|
+
* envelope once nothing else is in it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function stripSender(data: unknown): unknown;
|
|
@@ -31,16 +31,41 @@ export interface SSEClient {
|
|
|
31
31
|
id: string;
|
|
32
32
|
userId?: string | number;
|
|
33
33
|
channels: Set<string>;
|
|
34
|
-
|
|
34
|
+
/** `channel` is the one an event arrived on; absent on control events (`connected`, `ping`). */
|
|
35
|
+
send(event: string, data: unknown, channel?: string): void;
|
|
35
36
|
close(): void;
|
|
36
37
|
}
|
|
37
38
|
export interface WebSocketClient {
|
|
38
39
|
id: string;
|
|
39
40
|
userId?: string | number;
|
|
41
|
+
/**
|
|
42
|
+
* Issued by `registerWebSocketClient()` and sent in `connected`: the value a
|
|
43
|
+
* request names as `X-Socket-Id` to skip its own broadcast (RFC 0037 §4).
|
|
44
|
+
*/
|
|
45
|
+
socketId?: string;
|
|
40
46
|
channels: Set<string>;
|
|
41
|
-
|
|
47
|
+
/** `channel` is the one an event arrived on; absent on control events (`connected`, `subscription`). */
|
|
48
|
+
send(event: string, data: unknown, channel?: string): void | Promise<void>;
|
|
42
49
|
close(): void;
|
|
43
50
|
}
|
|
51
|
+
/** Who sent a broadcast, so their own sockets can be skipped. */
|
|
52
|
+
export interface BroadcastSender {
|
|
53
|
+
/** The `X-Socket-Id` the request carried. */
|
|
54
|
+
readonly socketId?: string | null;
|
|
55
|
+
readonly user?: unknown;
|
|
56
|
+
}
|
|
57
|
+
export interface BroadcastEventOptions {
|
|
58
|
+
/**
|
|
59
|
+
* Skip the sender's own socket: the request's context (its `X-Socket-Id`
|
|
60
|
+
* header and signed-in user), or the two given by hand. Only a socket owned
|
|
61
|
+
* by that same user is skipped.
|
|
62
|
+
*/
|
|
63
|
+
readonly except?: BroadcastSender | {
|
|
64
|
+
readonly req: {
|
|
65
|
+
header(name: string): string | undefined;
|
|
66
|
+
};
|
|
67
|
+
} | null;
|
|
68
|
+
}
|
|
44
69
|
export interface BroadcastManagerOptions {
|
|
45
70
|
default?: string;
|
|
46
71
|
drivers?: Record<string, BroadcastDriverFactory>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { a as parseRequestPayload, t as asRecord } from "./request-CLOYytGP.js";
|
|
2
2
|
import { g as warnDeprecatedSetter, h as warnDeprecatedGetter, i as bindAmbient, n as ambientBinding } from "./default-application-s9SE-Er7.js";
|
|
3
|
+
import { a as isSocketId, c as stripSender, i as isSenderUserId, l as broadcastChannelsOf, n as PresenceChannel, o as markSender, r as Channel, s as readSender, t as PrivateChannel, u as broadcastNameOf } from "./PrivateChannel-1krGz028.js";
|
|
3
4
|
import { r as getAuthContext } from "./context--l2HdOhy.js";
|
|
4
5
|
import { t as redactQueryParams } from "./redact-query-params-Ba-sAfcP.js";
|
|
5
6
|
import { n as isHotReloadRuntime, t as claimHotDisposable } from "./hot-disposables-W2fH-GID.js";
|
|
@@ -43,93 +44,6 @@ function createWebSocketOriginGuard(options = {}) {
|
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
46
|
//#endregion
|
|
46
|
-
//#region src/broadcasting/channels/Channel.ts
|
|
47
|
-
var Channel = class {
|
|
48
|
-
name;
|
|
49
|
-
driver;
|
|
50
|
-
constructor(name, driver) {
|
|
51
|
-
this.name = name;
|
|
52
|
-
this.driver = driver;
|
|
53
|
-
}
|
|
54
|
-
async broadcast(event, data) {
|
|
55
|
-
await this.driver.publish(this.name, event, data);
|
|
56
|
-
}
|
|
57
|
-
/** Returns an unsubscribe function. */
|
|
58
|
-
subscribe(callback) {
|
|
59
|
-
return this.driver.subscribe(this.name, (e) => {
|
|
60
|
-
callback(e.event, e.data);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
getChannelName() {
|
|
64
|
-
return this.name;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
//#endregion
|
|
68
|
-
//#region src/broadcasting/channels/PrivateChannel.ts
|
|
69
|
-
/** Broadcast channel that requires authentication to subscribe. */
|
|
70
|
-
var PrivateChannel = class PrivateChannel extends Channel {
|
|
71
|
-
static PREFIX = "private-";
|
|
72
|
-
constructor(name, driver) {
|
|
73
|
-
const channelName = name.startsWith(PrivateChannel.PREFIX) ? name : `${PrivateChannel.PREFIX}${name}`;
|
|
74
|
-
super(channelName, driver);
|
|
75
|
-
}
|
|
76
|
-
getBaseName() {
|
|
77
|
-
return this.name.startsWith(PrivateChannel.PREFIX) ? this.name.slice(PrivateChannel.PREFIX.length) : this.name;
|
|
78
|
-
}
|
|
79
|
-
static isPrivateChannel(name) {
|
|
80
|
-
return name.startsWith(PrivateChannel.PREFIX);
|
|
81
|
-
}
|
|
82
|
-
static normalize(name) {
|
|
83
|
-
return name.startsWith(PrivateChannel.PREFIX) ? name : `${PrivateChannel.PREFIX}${name}`;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
//#endregion
|
|
87
|
-
//#region src/broadcasting/channels/PresenceChannel.ts
|
|
88
|
-
/** Broadcast channel that tracks the members who have joined it. */
|
|
89
|
-
var PresenceChannel = class PresenceChannel extends Channel {
|
|
90
|
-
static PREFIX = "presence-";
|
|
91
|
-
presenceDriver;
|
|
92
|
-
constructor(name, driver) {
|
|
93
|
-
const channelName = name.startsWith(PresenceChannel.PREFIX) ? name : `${PresenceChannel.PREFIX}${name}`;
|
|
94
|
-
super(channelName, driver);
|
|
95
|
-
if (this.isPresenceDriver(driver)) this.presenceDriver = driver;
|
|
96
|
-
else throw new Error("Driver does not support presence channels. Ensure the driver implements PresenceBroadcastDriver interface.");
|
|
97
|
-
}
|
|
98
|
-
isPresenceDriver(driver) {
|
|
99
|
-
return "getMembers" in driver && "addMember" in driver && "removeMember" in driver;
|
|
100
|
-
}
|
|
101
|
-
members() {
|
|
102
|
-
return this.presenceDriver.getMembers(this.name);
|
|
103
|
-
}
|
|
104
|
-
async join(member) {
|
|
105
|
-
this.presenceDriver.addMember(this.name, member);
|
|
106
|
-
await this.broadcast("presence:joining", { member });
|
|
107
|
-
}
|
|
108
|
-
async leave(memberId) {
|
|
109
|
-
const member = this.members().find((m) => m.id === memberId);
|
|
110
|
-
this.presenceDriver.removeMember(this.name, memberId);
|
|
111
|
-
if (member) await this.broadcast("presence:leaving", { member });
|
|
112
|
-
}
|
|
113
|
-
hasMember(memberId) {
|
|
114
|
-
return this.members().some((m) => m.id === memberId);
|
|
115
|
-
}
|
|
116
|
-
getMember(memberId) {
|
|
117
|
-
return this.members().find((m) => m.id === memberId);
|
|
118
|
-
}
|
|
119
|
-
count() {
|
|
120
|
-
return this.members().length;
|
|
121
|
-
}
|
|
122
|
-
getBaseName() {
|
|
123
|
-
return this.name.startsWith(PresenceChannel.PREFIX) ? this.name.slice(PresenceChannel.PREFIX.length) : this.name;
|
|
124
|
-
}
|
|
125
|
-
static isPresenceChannel(name) {
|
|
126
|
-
return name.startsWith(PresenceChannel.PREFIX);
|
|
127
|
-
}
|
|
128
|
-
static normalize(name) {
|
|
129
|
-
return name.startsWith(PresenceChannel.PREFIX) ? name : `${PresenceChannel.PREFIX}${name}`;
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
//#endregion
|
|
133
47
|
//#region src/broadcasting/drivers/MemoryDriver.ts
|
|
134
48
|
/**
|
|
135
49
|
* Keeps subscriptions and presence data in memory — for testing and
|
|
@@ -465,7 +379,39 @@ var BroadcastManager = class {
|
|
|
465
379
|
return this;
|
|
466
380
|
}
|
|
467
381
|
async broadcast(channelName, event, data) {
|
|
468
|
-
await this.driver().publish(channelName, event, data);
|
|
382
|
+
await this.driver().publish(channelName, event, stripSender(data));
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Publishes `broadcastWith()` (else `{}`) as `broadcastNameOf(event)` on every
|
|
386
|
+
* channel `broadcastOn()` names: the name a `live()` prop listening for this
|
|
387
|
+
* event subscribes to.
|
|
388
|
+
*/
|
|
389
|
+
async broadcastEvent(event, options = {}) {
|
|
390
|
+
const name = broadcastNameOf(event);
|
|
391
|
+
const payload = stripSender(event.broadcastWith?.() ?? {});
|
|
392
|
+
const sender = options.except ? await this.resolveSender(options.except) : void 0;
|
|
393
|
+
const data = sender ? markSender(payload, sender) : payload;
|
|
394
|
+
for (const channel of broadcastChannelsOf(event)) await this.driver().publish(channel, name, data);
|
|
395
|
+
}
|
|
396
|
+
/** A sender is only worth marking with a socket id this manager could have issued and a user to bind it to. */
|
|
397
|
+
async resolveSender(except) {
|
|
398
|
+
const fromContext = "req" in except;
|
|
399
|
+
const socketId = fromContext ? except.req.header("X-Socket-Id") : except.socketId;
|
|
400
|
+
if (!isSocketId(socketId)) return void 0;
|
|
401
|
+
const userId = resolveClientUserId(fromContext ? await resolveRequestUser(except, void 0) : except.user);
|
|
402
|
+
return isSenderUserId(userId) ? {
|
|
403
|
+
socketId,
|
|
404
|
+
userId
|
|
405
|
+
} : void 0;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* What one client receives of a delivered event: nothing when it is the
|
|
409
|
+
* sender's own socket, else the payload without the reserved fields. The ids
|
|
410
|
+
* compare strictly, as `authMiddleware()` compares an owner: `7` is not `'7'`.
|
|
411
|
+
*/
|
|
412
|
+
deliveryFor(client, data) {
|
|
413
|
+
const sender = readSender(data);
|
|
414
|
+
return sender !== void 0 && "socketId" in client && client.socketId === sender.socketId && client.userId !== void 0 && client.userId === sender.userId ? void 0 : { data: stripSender(data) };
|
|
469
415
|
}
|
|
470
416
|
toChannel(name) {
|
|
471
417
|
return new Channel(name, this.driver());
|
|
@@ -577,9 +523,9 @@ var BroadcastManager = class {
|
|
|
577
523
|
/**
|
|
578
524
|
* A route that upgrades to a WebSocket carrying broadcast events, the socket
|
|
579
525
|
* counterpart of `sseMiddleware()`; it needs `Application.listen()` on Bun.
|
|
580
|
-
*
|
|
581
|
-
* `{ clientId, channels }
|
|
582
|
-
* channel }`, answered by
|
|
526
|
+
* JSON frames: an event `{ event, channel, data }`, the server's own `{ event, data }`
|
|
527
|
+
* (first `connected` with `{ clientId, socketId, channels }`). The client sends
|
|
528
|
+
* `{ action: 'subscribe' | 'unsubscribe', channel }`, answered by `subscription`.
|
|
583
529
|
*/
|
|
584
530
|
webSocketMiddleware(options = {}) {
|
|
585
531
|
const isAllowedOrigin = webSocketOriginCheck(options.allowedOrigins);
|
|
@@ -597,8 +543,12 @@ var BroadcastManager = class {
|
|
|
597
543
|
const { upgradeWebSocket } = await import("hono/bun");
|
|
598
544
|
return await upgradeWebSocket(() => ({
|
|
599
545
|
onOpen: (_event, ws) => {
|
|
600
|
-
const send = (event, data) => ws.send(JSON.stringify({
|
|
546
|
+
const send = (event, data, channel) => ws.send(JSON.stringify(channel === void 0 ? {
|
|
547
|
+
event,
|
|
548
|
+
data
|
|
549
|
+
} : {
|
|
601
550
|
event,
|
|
551
|
+
channel,
|
|
602
552
|
data
|
|
603
553
|
}));
|
|
604
554
|
clientId = this.registerWebSocketClient({
|
|
@@ -606,8 +556,10 @@ var BroadcastManager = class {
|
|
|
606
556
|
send,
|
|
607
557
|
close: () => ws.close()
|
|
608
558
|
});
|
|
559
|
+
const { socketId } = this.wsClients.get(clientId);
|
|
609
560
|
send("connected", {
|
|
610
561
|
clientId,
|
|
562
|
+
socketId,
|
|
611
563
|
channels: authorizedChannels
|
|
612
564
|
});
|
|
613
565
|
for (const channelName of authorizedChannels) this.subscribeWebSocketClient(clientId, channelName);
|
|
@@ -689,7 +641,8 @@ var BroadcastManager = class {
|
|
|
689
641
|
if (!client) return false;
|
|
690
642
|
client.channels.add(channel);
|
|
691
643
|
this.openDriverSubscription(clientId, channel, (event) => {
|
|
692
|
-
|
|
644
|
+
const delivery = client.channels.has(channel) ? this.deliveryFor(client, event.data) : void 0;
|
|
645
|
+
if (delivery) client.send(event.event, delivery.data, channel);
|
|
693
646
|
});
|
|
694
647
|
return true;
|
|
695
648
|
}
|
|
@@ -735,6 +688,7 @@ var BroadcastManager = class {
|
|
|
735
688
|
this.wsClients.set(clientId, {
|
|
736
689
|
...client,
|
|
737
690
|
id: clientId,
|
|
691
|
+
socketId: `s_${randomHex(16)}`,
|
|
738
692
|
channels: /* @__PURE__ */ new Set()
|
|
739
693
|
});
|
|
740
694
|
return clientId;
|
|
@@ -757,7 +711,8 @@ var BroadcastManager = class {
|
|
|
757
711
|
if (!client) return false;
|
|
758
712
|
client.channels.add(channel);
|
|
759
713
|
this.openDriverSubscription(clientId, channel, async (event) => {
|
|
760
|
-
|
|
714
|
+
const delivery = client.channels.has(channel) ? this.deliveryFor(client, event.data) : void 0;
|
|
715
|
+
if (delivery) await client.send(event.event, delivery.data, channel);
|
|
761
716
|
});
|
|
762
717
|
return true;
|
|
763
718
|
}
|
|
@@ -868,4 +823,4 @@ function wrapChannel(name, channel) {
|
|
|
868
823
|
};
|
|
869
824
|
}
|
|
870
825
|
//#endregion
|
|
871
|
-
export { setBroadcastManager as a,
|
|
826
|
+
export { setBroadcastManager as a, createWebSocketOriginGuard as c, getBroadcastManager as i, BroadcastManager as n, RedisDriver as o, createBroadcastManager as r, MemoryDriver as s, createTypedBroadcaster as t };
|
|
@@ -1,26 +1,5 @@
|
|
|
1
1
|
import { basename, dirname, join, sep } from "node:path";
|
|
2
2
|
import { realpath } from "node:fs/promises";
|
|
3
|
-
//#region src/support/trim-slashes.ts
|
|
4
|
-
/**
|
|
5
|
-
* No regex: patterns like `/\/+$/` backtrack quadratically on long slash runs
|
|
6
|
-
* mid-string, and several call sites feed request-derived paths.
|
|
7
|
-
*
|
|
8
|
-
* Twins that cannot import this module: `@guren/cli` (`src/utils.ts`) and
|
|
9
|
-
* `@guren/plugin-cloudflare` (`src/storage/R2Driver.ts`) — keep them in step.
|
|
10
|
-
*/
|
|
11
|
-
function trimTrailingSlashes(value) {
|
|
12
|
-
let end = value.length;
|
|
13
|
-
while (end > 0 && value[end - 1] === "/") end--;
|
|
14
|
-
return value.slice(0, end);
|
|
15
|
-
}
|
|
16
|
-
function trimSlashes(value) {
|
|
17
|
-
let start = 0;
|
|
18
|
-
let end = value.length;
|
|
19
|
-
while (start < end && value[start] === "/") start++;
|
|
20
|
-
while (end > start && value[end - 1] === "/") end--;
|
|
21
|
-
return value.slice(start, end);
|
|
22
|
-
}
|
|
23
|
-
//#endregion
|
|
24
3
|
//#region src/support/contained-path.ts
|
|
25
4
|
/**
|
|
26
5
|
* Lexical containment. The trailing separator keeps out a sibling whose name
|
|
@@ -75,4 +54,4 @@ async function realPathOfNearestExisting(path) {
|
|
|
75
54
|
}
|
|
76
55
|
}
|
|
77
56
|
//#endregion
|
|
78
|
-
export {
|
|
57
|
+
export { isRealPathWithin as n, realPathOfNearestExisting as r, isPathWithin as t };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-B4FMCO8f.js";
|
|
2
|
-
import {
|
|
2
|
+
import { d as formatHostPort, f as isWildcardHost, t as DEFAULT_DEV_SERVER_URL } from "./vite-manifest-BdXRybeq.js";
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import figlet from "figlet";
|
|
5
5
|
import standard from "figlet/importable-fonts/Standard.js";
|
|
6
6
|
//#region package.json
|
|
7
|
-
var version = "2.
|
|
7
|
+
var version = "2.36.0";
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region src/http/dev-banner.ts
|
|
10
10
|
var dev_banner_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -30,7 +30,7 @@ const ASSET_SERVER_LABELS = {
|
|
|
30
30
|
managed: "Vite, started by Guren",
|
|
31
31
|
external: "not started by Guren, run it yourself"
|
|
32
32
|
};
|
|
33
|
-
function logDevServerBanner({ hostname, port, assetsUrl =
|
|
33
|
+
function logDevServerBanner({ hostname, port, assetsUrl = DEFAULT_DEV_SERVER_URL, assetServer }) {
|
|
34
34
|
const localUrl = `http://localhost:${port}`;
|
|
35
35
|
const boundUrl = `http://${formatHostPort(hostname, port)}`;
|
|
36
36
|
const boundLabel = isWildcardHost(hostname) ? " (all interfaces)" : "";
|
|
@@ -168,30 +168,39 @@ function advertisesStructuredOutput(tool) {
|
|
|
168
168
|
* with the handler's body; other → capped text. An object-`outputSchema` success
|
|
169
169
|
* lacking an object becomes `isError`: the SDK client rejects it after the route ran.
|
|
170
170
|
*/
|
|
171
|
-
async function mapToolResponse(tool, response) {
|
|
171
|
+
async function mapToolResponse(tool, response, requestUrl) {
|
|
172
172
|
const status = response.status;
|
|
173
173
|
const structured = advertisesStructuredOutput(tool);
|
|
174
174
|
if (status === 204 || status >= 300 && status < 400) {
|
|
175
175
|
const location = response.headers.get("Location");
|
|
176
176
|
const text = location ? `HTTP ${status} (Location: ${location})` : `HTTP ${status}`;
|
|
177
|
-
|
|
177
|
+
const facts = location ? { location: resolveLocation(location, requestUrl) } : {};
|
|
178
|
+
if (structured) return {
|
|
179
|
+
...inconsistentOutput(tool, text, status),
|
|
180
|
+
...facts
|
|
181
|
+
};
|
|
178
182
|
return {
|
|
179
183
|
content: [{
|
|
180
184
|
type: "text",
|
|
181
185
|
text
|
|
182
186
|
}],
|
|
183
|
-
status
|
|
187
|
+
status,
|
|
188
|
+
...facts
|
|
184
189
|
};
|
|
185
190
|
}
|
|
186
191
|
const raw = await response.text();
|
|
187
|
-
if (status >= 400)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
192
|
+
if (status >= 400) {
|
|
193
|
+
const errors = status === 422 ? readValidationErrors(response, raw) : void 0;
|
|
194
|
+
return {
|
|
195
|
+
content: [{
|
|
196
|
+
type: "text",
|
|
197
|
+
text: raw || `HTTP ${status}`
|
|
198
|
+
}],
|
|
199
|
+
isError: true,
|
|
200
|
+
status,
|
|
201
|
+
...errors ? { errors } : {}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
195
204
|
const parsed = parseJsonBody(response, raw);
|
|
196
205
|
if (parsed === void 0) {
|
|
197
206
|
const text = raw.length > TEXT_RESPONSE_CAP ? `${raw.slice(0, TEXT_RESPONSE_CAP)}… [truncated ${raw.length - TEXT_RESPONSE_CAP} characters]` : raw;
|
|
@@ -213,13 +222,15 @@ async function mapToolResponse(tool, response) {
|
|
|
213
222
|
preflightVerdict: true
|
|
214
223
|
};
|
|
215
224
|
const payload = unwrapInertiaProps(tool, response, parsed);
|
|
225
|
+
const inertiaPage = tool.ui?.page === void 0 ? void 0 : readInertiaPage(response, parsed);
|
|
216
226
|
if (structured && !isRecord(payload)) return inconsistentOutput(tool, `a ${Array.isArray(payload) ? "JSON array" : typeof payload} body`, status);
|
|
217
227
|
const outcome = {
|
|
218
228
|
content: [{
|
|
219
229
|
type: "text",
|
|
220
230
|
text: JSON.stringify(payload)
|
|
221
231
|
}],
|
|
222
|
-
status
|
|
232
|
+
status,
|
|
233
|
+
...inertiaPage ? { inertiaPage } : {}
|
|
223
234
|
};
|
|
224
235
|
if (structured && isRecord(payload)) outcome.structuredContent = payload;
|
|
225
236
|
return outcome;
|
|
@@ -247,6 +258,34 @@ function parseJsonBody(response, raw) {
|
|
|
247
258
|
return;
|
|
248
259
|
}
|
|
249
260
|
}
|
|
261
|
+
function resolveLocation(location, requestUrl) {
|
|
262
|
+
if (!requestUrl) return location;
|
|
263
|
+
try {
|
|
264
|
+
return new URL(location, requestUrl).href;
|
|
265
|
+
} catch {
|
|
266
|
+
return location;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/** `{ errors: { field: string[] } }`, the body a non-Inertia request's `ValidationException` renders. */
|
|
270
|
+
function readValidationErrors(response, raw) {
|
|
271
|
+
const parsed = parseJsonBody(response, raw);
|
|
272
|
+
if (!isRecord(parsed) || !isRecord(parsed.errors)) return void 0;
|
|
273
|
+
const errors = {};
|
|
274
|
+
for (const [field, messages] of Object.entries(parsed.errors)) if (Array.isArray(messages)) errors[field] = messages.map((message) => String(message));
|
|
275
|
+
else if (typeof messages === "string") errors[field] = [messages];
|
|
276
|
+
return errors;
|
|
277
|
+
}
|
|
278
|
+
function readInertiaPage(response, parsed) {
|
|
279
|
+
if (response.headers.get("X-Inertia") !== "true" || !isRecord(parsed)) return void 0;
|
|
280
|
+
const { component, props, url, version } = parsed;
|
|
281
|
+
if (typeof component !== "string" || !isRecord(props) || typeof url !== "string") return void 0;
|
|
282
|
+
return {
|
|
283
|
+
component,
|
|
284
|
+
props,
|
|
285
|
+
url,
|
|
286
|
+
...typeof version === "string" ? { version } : {}
|
|
287
|
+
};
|
|
288
|
+
}
|
|
250
289
|
function unwrapInertiaProps(tool, response, parsed) {
|
|
251
290
|
if (tool.outputSchema) return parsed;
|
|
252
291
|
if (response.headers.get("X-Inertia") !== "true") return parsed;
|
package/dist/events/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as Event } from "../Event-COT3f5Xd.js";
|
|
2
|
+
import { a as RequestFinished, c as UserLoggedOut, d as EventManager, f as createEventManager, i as JobProcessed, l as createQueueEventDispatcher, n as ApplicationStarted, o as RequestReceived, r as JobFailed, s as UserAuthenticated, t as ApplicationShutdown, u as Listener } from "../events-DW197Nur.js";
|
|
2
3
|
export { ApplicationShutdown, ApplicationStarted, Event, EventManager, JobFailed, JobProcessed, Listener, RequestFinished, RequestReceived, UserAuthenticated, UserLoggedOut, createEventManager, createQueueEventDispatcher };
|
|
@@ -1,32 +1,6 @@
|
|
|
1
1
|
import { t as warnOnce } from "./warn-once-p-IlMjra.js";
|
|
2
|
+
import { n as resolveEventName, t as Event } from "./Event-COT3f5Xd.js";
|
|
2
3
|
import { d as resolveQueueDriver, l as registerJob, p as reportRegistryCollision, t as Job } from "./Job-0Prk8k0z.js";
|
|
3
|
-
//#region src/events/Event.ts
|
|
4
|
-
/** Base class for all application events. */
|
|
5
|
-
var Event = class {
|
|
6
|
-
timestamp = /* @__PURE__ */ new Date();
|
|
7
|
-
/**
|
|
8
|
-
* Stable wire name: queued emits record it and the worker resolves the class
|
|
9
|
-
* back from it. Declare it as a static field to pin the name against a
|
|
10
|
-
* rename or identifier mangling.
|
|
11
|
-
* @default the class name
|
|
12
|
-
*/
|
|
13
|
-
static get eventName() {
|
|
14
|
-
return this.name;
|
|
15
|
-
}
|
|
16
|
-
get eventName() {
|
|
17
|
-
return resolveEventName(this.constructor);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Only an *own* `eventName` counts: statics are inherited, so reading the
|
|
22
|
-
* prototype chain would make every subclass of a pinned event claim its
|
|
23
|
-
* parent's name and take over its listeners. The base class's own entry is the
|
|
24
|
-
* accessor, which answers with the class name.
|
|
25
|
-
*/
|
|
26
|
-
function resolveEventName(eventClass) {
|
|
27
|
-
return (Object.prototype.hasOwnProperty.call(eventClass, "eventName") ? eventClass.eventName : void 0) ?? eventClass.name;
|
|
28
|
-
}
|
|
29
|
-
//#endregion
|
|
30
4
|
//#region src/events/serialize.ts
|
|
31
5
|
/**
|
|
32
6
|
* Marks a `Date` inside a queued event's fields. A driver that JSON-encodes the
|
|
@@ -438,4 +412,4 @@ var ApplicationShutdown = class extends Event {
|
|
|
438
412
|
}
|
|
439
413
|
};
|
|
440
414
|
//#endregion
|
|
441
|
-
export { RequestFinished as a, UserLoggedOut as c, EventManager as d, createEventManager as f, JobProcessed as i, createQueueEventDispatcher as l, ApplicationStarted as n, RequestReceived as o,
|
|
415
|
+
export { RequestFinished as a, UserLoggedOut as c, EventManager as d, createEventManager as f, JobProcessed as i, createQueueEventDispatcher as l, ApplicationStarted as n, RequestReceived as o, JobFailed as r, UserAuthenticated as s, ApplicationShutdown as t, Listener as u };
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { InlineConfig, ViteDevServer } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* The port `listen()` starts its managed Vite dev server on. `guren browser:serve`
|
|
4
|
+
* restates the name in packages/cli/src/browser-serve.ts; tests/browser-serve.test.ts pins the two.
|
|
5
|
+
*/
|
|
6
|
+
export declare const VITE_PORT_ENV = "GUREN_VITE_PORT";
|
|
2
7
|
export interface StartViteDevServerOptions {
|
|
3
8
|
root?: string;
|
|
4
9
|
config?: InlineConfig;
|
|
@@ -8,17 +13,29 @@ export interface StartViteDevServerOptions {
|
|
|
8
13
|
* the project root, unauthenticated. Pass `true` to expose it on the network.
|
|
9
14
|
*/
|
|
10
15
|
host?: boolean | string;
|
|
16
|
+
/**
|
|
17
|
+
* The port Vite tries first, moving to the next free one when it is busy unless
|
|
18
|
+
* the project sets `server.strictPort`. `listen()` falls back to `GUREN_VITE_PORT`,
|
|
19
|
+
* then to the project's Vite config (5173 with the Guren plugin).
|
|
20
|
+
*/
|
|
11
21
|
port?: number;
|
|
12
22
|
}
|
|
13
23
|
export interface StartedViteDevServer {
|
|
14
24
|
server: ViteDevServer;
|
|
25
|
+
/** Names the port Vite bound, which is not the one asked for after a walk. */
|
|
15
26
|
localUrl: string;
|
|
16
27
|
networkUrls: string[];
|
|
17
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* `GUREN_VITE_PORT` as a port, or `undefined` when it is unset or blank, so the
|
|
31
|
+
* project's Vite config decides. Throws on anything else: a typo silently
|
|
32
|
+
* ignored would put two apps back on the same port.
|
|
33
|
+
*/
|
|
34
|
+
export declare function readViteDevServerPort(value?: string | undefined): number | undefined;
|
|
18
35
|
/**
|
|
19
36
|
* Build the inline config the managed dev server starts with. `server.host` is
|
|
20
37
|
* left undefined unless asked for, so Vite's config merge drops it and the
|
|
21
|
-
* project's own `vite.config.ts` decides.
|
|
38
|
+
* project's own `vite.config.ts` decides; `server.port` likewise.
|
|
22
39
|
*/
|
|
23
40
|
export declare function resolveViteDevServerConfig(options?: StartViteDevServerOptions): InlineConfig;
|
|
24
41
|
export declare function startViteDevServer(options?: StartViteDevServerOptions): Promise<StartedViteDevServer>;
|
|
@@ -11,7 +11,10 @@
|
|
|
11
11
|
* internal/deploy-build.ts; tests/http/vite-manifest.test.ts pins the two equal.
|
|
12
12
|
*/
|
|
13
13
|
export declare const PUBLIC_ASSETS_URL_PREFIX = "/public/assets/";
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* The Vite default the framework assumes when no dev-server URL is set. Not
|
|
16
|
+
* `GUREN_VITE_PORT`: a managed start publishes the URL Vite bound instead.
|
|
17
|
+
*/
|
|
15
18
|
export declare const DEFAULT_DEV_SERVER_URL = "http://localhost:5173";
|
|
16
19
|
/**
|
|
17
20
|
* Production for *asset* purposes: `NODE_ENV` says so and no dev server is
|