@truefoundry/trueforge 0.2.0-rc.13 → 0.2.0-rc.14

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/main.js CHANGED
@@ -8711,9 +8711,14 @@ var GetSessionUserSchema = z8.object({
8711
8711
  roles: z8.array(z8.string()),
8712
8712
  subject: SessionSubjectSchema
8713
8713
  });
8714
- var GetSessionWireSchema = z8.object({
8715
- user: GetSessionUserSchema.nullable()
8714
+ var GetSessionUnauthenticatedSchema = z8.object({
8715
+ user: z8.null()
8716
8716
  });
8717
+ var GetSessionAuthenticatedSchema = z8.object({
8718
+ user: GetSessionUserSchema,
8719
+ controlPlaneURL: z8.url()
8720
+ }).transform(({ user, controlPlaneURL: public_base_url }) => ({ user, public_base_url }));
8721
+ var GetSessionWireSchema = z8.union([GetSessionUnauthenticatedSchema, GetSessionAuthenticatedSchema]);
8717
8722
  var ListResponseSchema = z8.union([
8718
8723
  z8.array(z8.unknown()),
8719
8724
  z8.object({
@@ -9029,8 +9034,8 @@ var TrueFoundryServiceFoundryServerClient = class {
9029
9034
  });
9030
9035
  }
9031
9036
  /**
9032
- * `GET v1/session` for RequestContext mapping.
9033
- * `user: null` (invalid/missing auth on a 200) → 401; all other failures → 500.
9037
+ * `GET v1/session` for RequestContext mapping (always called with a bearer token).
9038
+ * SFY optional-auth soft failure (`user: null` on 200) → 401; malformed → 500.
9034
9039
  */
9035
9040
  async getSession(accessToken) {
9036
9041
  let payload;
@@ -9059,7 +9064,7 @@ var TrueFoundryServiceFoundryServerClient = class {
9059
9064
  if (parsed.data.user === null) {
9060
9065
  throw new HTTPException(401, { message: "Authentication required" });
9061
9066
  }
9062
- return { user: parsed.data.user };
9067
+ return parsed.data;
9063
9068
  }
9064
9069
  async getAgentPermissions(input) {
9065
9070
  const payload = await this.#requestJson({
@@ -17143,7 +17148,8 @@ var TrueFoundryAuthenticator = class {
17143
17148
  display_name: subject.subjectDisplayName ?? subject.subjectSlug ?? subject.subjectId
17144
17149
  },
17145
17150
  roles: session.user.roles,
17146
- user_credential: token
17151
+ user_credential: token,
17152
+ public_base_url: session.public_base_url
17147
17153
  });
17148
17154
  }
17149
17155
  };
@@ -18417,9 +18423,11 @@ function withoutAuthorization(headers) {
18417
18423
  }
18418
18424
  function resolveAuthorizeRedirectURL(input) {
18419
18425
  try {
18420
- return new URL(safeReturnTo(input.returnTo), `${new URL(getPublicBaseUrl()).origin}/`).href;
18426
+ const origin = new URL(input.publicBaseUrl).origin;
18427
+ const publicBase = new URL(getPublicUiBasePath(), `${origin}/`);
18428
+ return new URL(safeReturnTo(input.returnTo), publicBase).href;
18421
18429
  } catch (error) {
18422
- throw new McpConnectionError6("PUBLIC_BASE_URL is required for TrueFoundry MCP OAuth but was empty", 500, {
18430
+ throw new McpConnectionError6("Tenant public base URL from session is required for TrueFoundry MCP OAuth", 500, {
18423
18431
  cause: error
18424
18432
  });
18425
18433
  }
@@ -18429,19 +18437,22 @@ var TrueFoundryMcpServerStore = class {
18429
18437
  #asAgent;
18430
18438
  #asUser;
18431
18439
  #subject;
18440
+ #publicBaseUrl;
18432
18441
  #perServerHeaders;
18433
18442
  #gatewayUrl;
18434
18443
  constructor(input) {
18435
18444
  this.#client = input.client;
18445
+ const requestContext = asTrueFoundryRequestContext(input.requestContext);
18436
18446
  const tokens = accessTokenForRequest({
18437
18447
  client: input.client,
18438
- requestContext: asTrueFoundryRequestContext(input.requestContext),
18448
+ requestContext,
18439
18449
  agent: input.agent,
18440
18450
  logger: input.logger
18441
18451
  });
18442
18452
  this.#asAgent = tokens.asAgent;
18443
18453
  this.#asUser = tokens.asUser;
18444
- this.#subject = input.requestContext.subject;
18454
+ this.#subject = requestContext.subject;
18455
+ this.#publicBaseUrl = requestContext.public_base_url;
18445
18456
  this.#perServerHeaders = input.perServerHeaders ?? {};
18446
18457
  }
18447
18458
  /** Gateway Bearer (+ optional per-server overrides); SFY authorize first, else authRequired. */
@@ -18558,10 +18569,15 @@ var TrueFoundryMcpServerStore = class {
18558
18569
  if (record === void 0) {
18559
18570
  throw new McpServerNotFoundError(input.name);
18560
18571
  }
18572
+ const publicBaseUrl = this.#publicBaseUrl;
18573
+ if (publicBaseUrl === void 0 || publicBaseUrl.trim() === "") {
18574
+ throw new McpConnectionError6("Tenant public base URL from session is required for TrueFoundry MCP OAuth", 500);
18575
+ }
18561
18576
  return this.#client.getMcpAuthorize({
18562
18577
  accessToken: await this.#asUser(),
18563
18578
  mcpServerId: record.id,
18564
18579
  redirectURL: resolveAuthorizeRedirectURL({
18580
+ publicBaseUrl,
18565
18581
  ...input.returnTo !== void 0 ? { returnTo: input.returnTo } : {}
18566
18582
  })
18567
18583
  });