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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poe-code",
3
- "version": "3.0.430",
3
+ "version": "3.0.431",
4
4
  "description": "CLI tool to configure Poe API for developer workflows.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -119,6 +119,7 @@ export declare class StreamableHttpTransport {
119
119
  private readOrigin;
120
120
  private readToolName;
121
121
  private getActiveSession;
122
+ private readAuthSubject;
122
123
  private touchSession;
123
124
  private isExpired;
124
125
  private purgeExpiredSessions;
@@ -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
- const session = this.getActiveSession(headerSessionId);
216
- if (session === undefined) {
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 (session?.protocolVersion !== undefined &&
223
- !this.acceptsProtocolVersion(req, session.protocolVersion)) {
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, session);
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 = sessionId === undefined ? undefined : this.sessionStore.get(sessionId);
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?.protocolVersion !== undefined &&
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) {
@@ -1,6 +1,7 @@
1
1
  export interface Session {
2
2
  id: string;
3
3
  initialized: boolean;
4
+ authSubject?: string;
4
5
  protocolVersion?: string;
5
6
  createdAt: Date;
6
7
  lastSeenAt: Date;