poe-code 3.0.430 → 3.0.431
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
|
@@ -190,6 +190,7 @@ export class StreamableHttpTransport {
|
|
|
190
190
|
}
|
|
191
191
|
const initMessage = classified.messages.find((message) => this.isRequest(message) && message.method === "initialize");
|
|
192
192
|
let sessionId;
|
|
193
|
+
let activeSession;
|
|
193
194
|
if (this.sessionIdGenerator !== undefined) {
|
|
194
195
|
const headerSessionId = this.readSessionId(req);
|
|
195
196
|
if (headerSessionId === undefined) {
|
|
@@ -207,24 +208,28 @@ export class StreamableHttpTransport {
|
|
|
207
208
|
return;
|
|
208
209
|
}
|
|
209
210
|
sessionId = newSessionId;
|
|
210
|
-
this.sessionStore.create(newSessionId);
|
|
211
|
+
activeSession = this.sessionStore.create(newSessionId);
|
|
212
|
+
const authSubject = this.readAuthSubject(req);
|
|
213
|
+
if (authSubject !== undefined) {
|
|
214
|
+
activeSession.authSubject = authSubject;
|
|
215
|
+
}
|
|
211
216
|
this.emit({ type: "session.created", sessionId: newSessionId });
|
|
212
217
|
this.createLocalMessageSession(newSessionId);
|
|
213
218
|
}
|
|
214
219
|
else {
|
|
215
|
-
|
|
216
|
-
if (
|
|
220
|
+
activeSession = this.getActiveSession(headerSessionId, req);
|
|
221
|
+
if (activeSession === undefined) {
|
|
217
222
|
this.respondWithStatus(res, 404);
|
|
218
223
|
return;
|
|
219
224
|
}
|
|
220
225
|
sessionId = headerSessionId;
|
|
221
226
|
this.touchSession(sessionId);
|
|
222
|
-
if (
|
|
223
|
-
!this.acceptsProtocolVersion(req,
|
|
227
|
+
if (activeSession.protocolVersion !== undefined &&
|
|
228
|
+
!this.acceptsProtocolVersion(req, activeSession.protocolVersion)) {
|
|
224
229
|
this.respondWithStatus(res, 400);
|
|
225
230
|
return;
|
|
226
231
|
}
|
|
227
|
-
await this.ensureLocalMessageSession(sessionId,
|
|
232
|
+
await this.ensureLocalMessageSession(sessionId, activeSession);
|
|
228
233
|
}
|
|
229
234
|
}
|
|
230
235
|
const formattedResponses = await this.runWithRequestContext(req, async () => {
|
|
@@ -240,7 +245,7 @@ export class StreamableHttpTransport {
|
|
|
240
245
|
if (!("method" in message)) {
|
|
241
246
|
continue;
|
|
242
247
|
}
|
|
243
|
-
const session =
|
|
248
|
+
const session = activeSession;
|
|
244
249
|
if (session !== undefined &&
|
|
245
250
|
message.method !== "initialize" &&
|
|
246
251
|
message.method !== "notifications/initialized" &&
|
|
@@ -359,7 +364,7 @@ export class StreamableHttpTransport {
|
|
|
359
364
|
this.respondWithStatus(res, 400);
|
|
360
365
|
return;
|
|
361
366
|
}
|
|
362
|
-
const session = this.getActiveSession(sessionId);
|
|
367
|
+
const session = this.getActiveSession(sessionId, req);
|
|
363
368
|
if (session === undefined) {
|
|
364
369
|
this.respondWithStatus(res, 404);
|
|
365
370
|
return;
|
|
@@ -426,8 +431,12 @@ export class StreamableHttpTransport {
|
|
|
426
431
|
this.respondWithStatus(res, 400);
|
|
427
432
|
return;
|
|
428
433
|
}
|
|
429
|
-
const session = this.getActiveSession(sessionId);
|
|
430
|
-
if (session
|
|
434
|
+
const session = this.getActiveSession(sessionId, req);
|
|
435
|
+
if (session === undefined) {
|
|
436
|
+
this.respondWithStatus(res, 404);
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
if (session.protocolVersion !== undefined &&
|
|
431
440
|
!this.acceptsProtocolVersion(req, session.protocolVersion)) {
|
|
432
441
|
this.respondWithStatus(res, 400);
|
|
433
442
|
return;
|
|
@@ -487,7 +496,7 @@ export class StreamableHttpTransport {
|
|
|
487
496
|
const name = params.name;
|
|
488
497
|
return typeof name === "string" ? name : undefined;
|
|
489
498
|
}
|
|
490
|
-
getActiveSession(sessionId) {
|
|
499
|
+
getActiveSession(sessionId, req) {
|
|
491
500
|
const session = this.sessionStore.get(sessionId);
|
|
492
501
|
if (session === undefined) {
|
|
493
502
|
return undefined;
|
|
@@ -496,8 +505,16 @@ export class StreamableHttpTransport {
|
|
|
496
505
|
this.deleteSession(sessionId, "expired");
|
|
497
506
|
return undefined;
|
|
498
507
|
}
|
|
508
|
+
if (session.authSubject !== undefined && session.authSubject !== this.readAuthSubject(req)) {
|
|
509
|
+
return undefined;
|
|
510
|
+
}
|
|
499
511
|
return session;
|
|
500
512
|
}
|
|
513
|
+
readAuthSubject(req) {
|
|
514
|
+
const auth = req.auth;
|
|
515
|
+
const authSubject = auth?.subject ?? auth?.clientId;
|
|
516
|
+
return authSubject !== undefined && authSubject.length > 0 ? authSubject : undefined;
|
|
517
|
+
}
|
|
501
518
|
touchSession(sessionId) {
|
|
502
519
|
const session = this.sessionStore.get(sessionId);
|
|
503
520
|
if (session === undefined) {
|