@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.js CHANGED
@@ -708,7 +708,22 @@ var KontextMcp = class {
708
708
  const url = typeof item.url === "string" ? item.url : "";
709
709
  if (!id || !url) return null;
710
710
  const category = item.category === "internal_mcp_credentials" ? "internal_mcp_credentials" : "gateway_remote_mcp";
711
- const connectType = item.connectType === "credentials" || item.connectType === "oauth" || item.connectType === "none" ? item.connectType : category === "internal_mcp_credentials" ? "credentials" : item.authMode === "oauth" ? "oauth" : "none";
711
+ const rawConnectType = item.connectType;
712
+ if (typeof rawConnectType !== "string") {
713
+ throw new KontextError(
714
+ "Runtime integration connectType is required in API response.",
715
+ "kontext_runtime_integrations_invalid_response",
716
+ { meta: { integrationId: id, connectType: rawConnectType } }
717
+ );
718
+ }
719
+ const connectType = rawConnectType === "credentials" || rawConnectType === "oauth" || rawConnectType === "user_token" || rawConnectType === "none" ? rawConnectType : null;
720
+ if (!connectType) {
721
+ throw new KontextError(
722
+ `Unknown runtime integration connectType "${rawConnectType}".`,
723
+ "kontext_runtime_integrations_invalid_response",
724
+ { meta: { integrationId: id, connectType: rawConnectType } }
725
+ );
726
+ }
712
727
  const rawConnection = item.connection && typeof item.connection === "object" ? item.connection : void 0;
713
728
  const connected = rawConnection && typeof rawConnection.connected === "boolean" ? rawConnection.connected : false;
714
729
  const status = rawConnection?.status === "connected" ? "connected" : "disconnected";
@@ -719,6 +734,9 @@ var KontextMcp = class {
719
734
  category,
720
735
  connectType,
721
736
  authMode: item.authMode === "oauth" || item.authMode === "user_token" || item.authMode === "server_token" || item.authMode === "none" ? item.authMode : void 0,
737
+ tokenLabel: typeof item.tokenLabel === "string" ? item.tokenLabel : void 0,
738
+ tokenHelpUrl: typeof item.tokenHelpUrl === "string" ? item.tokenHelpUrl : void 0,
739
+ tokenPlaceholder: typeof item.tokenPlaceholder === "string" ? item.tokenPlaceholder : void 0,
722
740
  credentialSchema: item.credentialSchema,
723
741
  requiresOauth: typeof item.requiresOauth === "boolean" ? item.requiresOauth : void 0,
724
742
  connection: rawConnection ? {
@@ -3677,6 +3695,12 @@ var Kontext = class _Kontext {
3677
3695
  // ===========================================================================
3678
3696
  createAgentSession(userToken, mcpSessionId, metadata) {
3679
3697
  if (!this.clientSecret || !userToken) return;
3698
+ if (!metadata?.authenticatedUserId) {
3699
+ console.warn(
3700
+ "[kontext:sessions] create skipped: missing authenticated user id"
3701
+ );
3702
+ return;
3703
+ }
3680
3704
  const tokenIdentifier = createHash("sha256").update(userToken).digest("hex");
3681
3705
  this.getServiceToken().then(
3682
3706
  (token) => fetch(`${this.apiUrl}/api/v1/agent-sessions`, {
@@ -3687,6 +3711,7 @@ var Kontext = class _Kontext {
3687
3711
  },
3688
3712
  body: JSON.stringify({
3689
3713
  tokenIdentifier,
3714
+ authenticatedUserId: metadata.authenticatedUserId,
3690
3715
  clientSessionId: mcpSessionId,
3691
3716
  hostname: metadata?.hostname,
3692
3717
  userAgent: metadata?.userAgent,
@@ -3908,6 +3933,7 @@ var Kontext = class _Kontext {
3908
3933
  status: "ok"
3909
3934
  });
3910
3935
  this.createAgentSession(authInfo?.token, sid, {
3936
+ authenticatedUserId: typeof authInfo?.extra?.sub === "string" ? authInfo.extra.sub : void 0,
3911
3937
  hostname: req.headers["x-forwarded-for"],
3912
3938
  userAgent: req.headers["user-agent"],
3913
3939
  tokenExpiresAt: authInfo?.expiresAt