@kontext-dev/js-sdk 0.3.0 → 1.0.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/index.cjs CHANGED
@@ -711,7 +711,22 @@ var KontextMcp = class {
711
711
  const url = typeof item.url === "string" ? item.url : "";
712
712
  if (!id || !url) return null;
713
713
  const category = item.category === "internal_mcp_credentials" ? "internal_mcp_credentials" : "gateway_remote_mcp";
714
- const connectType = item.connectType === "credentials" || item.connectType === "oauth" || item.connectType === "none" ? item.connectType : category === "internal_mcp_credentials" ? "credentials" : item.authMode === "oauth" ? "oauth" : "none";
714
+ const rawConnectType = item.connectType;
715
+ if (typeof rawConnectType !== "string") {
716
+ throw new KontextError(
717
+ "Runtime integration connectType is required in API response.",
718
+ "kontext_runtime_integrations_invalid_response",
719
+ { meta: { integrationId: id, connectType: rawConnectType } }
720
+ );
721
+ }
722
+ const connectType = rawConnectType === "credentials" || rawConnectType === "oauth" || rawConnectType === "user_token" || rawConnectType === "none" ? rawConnectType : null;
723
+ if (!connectType) {
724
+ throw new KontextError(
725
+ `Unknown runtime integration connectType "${rawConnectType}".`,
726
+ "kontext_runtime_integrations_invalid_response",
727
+ { meta: { integrationId: id, connectType: rawConnectType } }
728
+ );
729
+ }
715
730
  const rawConnection = item.connection && typeof item.connection === "object" ? item.connection : void 0;
716
731
  const connected = rawConnection && typeof rawConnection.connected === "boolean" ? rawConnection.connected : false;
717
732
  const status = rawConnection?.status === "connected" ? "connected" : "disconnected";
@@ -722,6 +737,9 @@ var KontextMcp = class {
722
737
  category,
723
738
  connectType,
724
739
  authMode: item.authMode === "oauth" || item.authMode === "user_token" || item.authMode === "server_token" || item.authMode === "none" ? item.authMode : void 0,
740
+ tokenLabel: typeof item.tokenLabel === "string" ? item.tokenLabel : void 0,
741
+ tokenHelpUrl: typeof item.tokenHelpUrl === "string" ? item.tokenHelpUrl : void 0,
742
+ tokenPlaceholder: typeof item.tokenPlaceholder === "string" ? item.tokenPlaceholder : void 0,
725
743
  credentialSchema: item.credentialSchema,
726
744
  requiresOauth: typeof item.requiresOauth === "boolean" ? item.requiresOauth : void 0,
727
745
  connection: rawConnection ? {
@@ -3680,6 +3698,12 @@ var Kontext = class _Kontext {
3680
3698
  // ===========================================================================
3681
3699
  createAgentSession(userToken, mcpSessionId, metadata) {
3682
3700
  if (!this.clientSecret || !userToken) return;
3701
+ if (!metadata?.authenticatedUserId) {
3702
+ console.warn(
3703
+ "[kontext:sessions] create skipped: missing authenticated user id"
3704
+ );
3705
+ return;
3706
+ }
3683
3707
  const tokenIdentifier = crypto$1.createHash("sha256").update(userToken).digest("hex");
3684
3708
  this.getServiceToken().then(
3685
3709
  (token) => fetch(`${this.apiUrl}/api/v1/agent-sessions`, {
@@ -3690,6 +3714,7 @@ var Kontext = class _Kontext {
3690
3714
  },
3691
3715
  body: JSON.stringify({
3692
3716
  tokenIdentifier,
3717
+ authenticatedUserId: metadata.authenticatedUserId,
3693
3718
  clientSessionId: mcpSessionId,
3694
3719
  hostname: metadata?.hostname,
3695
3720
  userAgent: metadata?.userAgent,
@@ -3911,6 +3936,7 @@ var Kontext = class _Kontext {
3911
3936
  status: "ok"
3912
3937
  });
3913
3938
  this.createAgentSession(authInfo?.token, sid, {
3939
+ authenticatedUserId: typeof authInfo?.extra?.sub === "string" ? authInfo.extra.sub : void 0,
3914
3940
  hostname: req.headers["x-forwarded-for"],
3915
3941
  userAgent: req.headers["user-agent"],
3916
3942
  tokenExpiresAt: authInfo?.expiresAt