poe-code 3.0.432 → 3.0.433
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/package.json
CHANGED
|
@@ -105,6 +105,8 @@ export declare class StreamableHttpTransport {
|
|
|
105
105
|
private nextNotificationEventId;
|
|
106
106
|
private nextRequestId;
|
|
107
107
|
private activeToolCalls;
|
|
108
|
+
private closed;
|
|
109
|
+
private sessionExpiryInterval;
|
|
108
110
|
private sseKeepAliveInterval;
|
|
109
111
|
constructor(server: Server, options?: StreamableHttpTransportOptions, runWithRequestContext?: RequestContextRunner);
|
|
110
112
|
handleRequest(req: IncomingMessage, res: ServerResponse): Promise<void>;
|
|
@@ -45,6 +45,8 @@ export class StreamableHttpTransport {
|
|
|
45
45
|
nextNotificationEventId = 1;
|
|
46
46
|
nextRequestId = 1;
|
|
47
47
|
activeToolCalls = 0;
|
|
48
|
+
closed = false;
|
|
49
|
+
sessionExpiryInterval;
|
|
48
50
|
sseKeepAliveInterval;
|
|
49
51
|
constructor(server, options = {}, runWithRequestContext = async (_req, callback) => callback()) {
|
|
50
52
|
this.server = server;
|
|
@@ -73,6 +75,17 @@ export class StreamableHttpTransport {
|
|
|
73
75
|
this.requestIdGenerator = options.requestIdGenerator ?? (() => `req-${this.nextRequestId++}`);
|
|
74
76
|
this.observability = options.observability ?? {};
|
|
75
77
|
this.trustedProxy = options.trustedProxy ?? false;
|
|
78
|
+
if (this.sessionTtlMs !== undefined) {
|
|
79
|
+
this.sessionExpiryInterval = setInterval(() => {
|
|
80
|
+
try {
|
|
81
|
+
this.purgeExpiredSessions();
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
}, Math.min(this.sessionTtlMs, 60_000));
|
|
87
|
+
this.sessionExpiryInterval.unref();
|
|
88
|
+
}
|
|
76
89
|
}
|
|
77
90
|
async handleRequest(req, res) {
|
|
78
91
|
const startedAt = Date.now();
|
|
@@ -90,12 +103,10 @@ export class StreamableHttpTransport {
|
|
|
90
103
|
sessionId: this.readSessionId(req)
|
|
91
104
|
});
|
|
92
105
|
try {
|
|
93
|
-
this.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
try {
|
|
106
|
+
if (this.closed) {
|
|
107
|
+
this.respondWithStatus(res, 503);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
99
110
|
if (!this.acceptsHost(req) || !this.acceptsOrigin(req)) {
|
|
100
111
|
this.respondWithStatus(res, 403);
|
|
101
112
|
return;
|
|
@@ -148,6 +159,11 @@ export class StreamableHttpTransport {
|
|
|
148
159
|
}
|
|
149
160
|
}
|
|
150
161
|
async close() {
|
|
162
|
+
this.closed = true;
|
|
163
|
+
if (this.sessionExpiryInterval !== undefined) {
|
|
164
|
+
clearInterval(this.sessionExpiryInterval);
|
|
165
|
+
this.sessionExpiryInterval = undefined;
|
|
166
|
+
}
|
|
151
167
|
this.stopSseKeepAlive();
|
|
152
168
|
for (const sessionId of [...this.sseStreams.keys()]) {
|
|
153
169
|
this.closeStreamsForSession(sessionId);
|
|
@@ -739,7 +755,7 @@ export class StreamableHttpTransport {
|
|
|
739
755
|
if (host === undefined || host.length === 0) {
|
|
740
756
|
return true;
|
|
741
757
|
}
|
|
742
|
-
return this.allowedHosts.has(this.normalizeHost(
|
|
758
|
+
return this.allowedHosts.has(this.normalizeHost(this.readRequestHost(req)));
|
|
743
759
|
}
|
|
744
760
|
normalizeHost(host) {
|
|
745
761
|
const normalized = host.trim().toLowerCase();
|