@kontext-dev/js-sdk 0.1.1 → 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/adapters/ai/index.cjs +135 -58
- package/dist/adapters/ai/index.cjs.map +1 -1
- package/dist/adapters/ai/index.js +135 -58
- package/dist/adapters/ai/index.js.map +1 -1
- package/dist/adapters/cloudflare/index.cjs +28 -70
- package/dist/adapters/cloudflare/index.cjs.map +1 -1
- package/dist/adapters/cloudflare/index.js +28 -70
- package/dist/adapters/cloudflare/index.js.map +1 -1
- package/dist/client/index.cjs +33 -9
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.js +33 -9
- package/dist/client/index.js.map +1 -1
- package/dist/index.cjs +42 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +42 -9
- package/dist/index.js.map +1 -1
- package/dist/management/index.cjs.map +1 -1
- package/dist/management/index.d.cts +2 -2
- package/dist/management/index.d.ts +2 -2
- package/dist/management/index.js.map +1 -1
- package/dist/mcp/index.cjs +28 -8
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.d.cts +5 -1
- package/dist/mcp/index.d.ts +5 -1
- package/dist/mcp/index.js +28 -8
- package/dist/mcp/index.js.map +1 -1
- package/dist/oauth/index.cjs.map +1 -1
- package/dist/oauth/index.d.cts +1 -1
- package/dist/oauth/index.d.ts +1 -1
- package/dist/oauth/index.js.map +1 -1
- package/dist/server/index.cjs +9 -0
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +9 -0
- package/dist/server/index.js.map +1 -1
- package/dist/{types-CzhnlJHW.d.cts → types-C6ep5fVw.d.cts} +2 -0
- package/dist/{types-CzhnlJHW.d.ts → types-C6ep5fVw.d.ts} +2 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -539,6 +539,7 @@ var KontextMcp = class {
|
|
|
539
539
|
config;
|
|
540
540
|
storage;
|
|
541
541
|
oauthProvider;
|
|
542
|
+
clientSessionId = typeof globalThis.crypto?.randomUUID === "function" ? globalThis.crypto.randomUUID() : `kontext-sdk-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
542
543
|
transport = null;
|
|
543
544
|
client = null;
|
|
544
545
|
_isConnected = false;
|
|
@@ -710,7 +711,22 @@ var KontextMcp = class {
|
|
|
710
711
|
const url = typeof item.url === "string" ? item.url : "";
|
|
711
712
|
if (!id || !url) return null;
|
|
712
713
|
const category = item.category === "internal_mcp_credentials" ? "internal_mcp_credentials" : "gateway_remote_mcp";
|
|
713
|
-
const
|
|
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
|
+
}
|
|
714
730
|
const rawConnection = item.connection && typeof item.connection === "object" ? item.connection : void 0;
|
|
715
731
|
const connected = rawConnection && typeof rawConnection.connected === "boolean" ? rawConnection.connected : false;
|
|
716
732
|
const status = rawConnection?.status === "connected" ? "connected" : "disconnected";
|
|
@@ -721,6 +737,9 @@ var KontextMcp = class {
|
|
|
721
737
|
category,
|
|
722
738
|
connectType,
|
|
723
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,
|
|
724
743
|
credentialSchema: item.credentialSchema,
|
|
725
744
|
requiresOauth: typeof item.requiresOauth === "boolean" ? item.requiresOauth : void 0,
|
|
726
745
|
connection: rawConnection ? {
|
|
@@ -858,13 +877,14 @@ var KontextMcp = class {
|
|
|
858
877
|
if (this.config.onElicitationUrl) {
|
|
859
878
|
capabilities.elicitation = { url: {} };
|
|
860
879
|
}
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
880
|
+
const clientInfo = {
|
|
881
|
+
name: this.config.clientName ?? "kontext-sdk",
|
|
882
|
+
version: this.config.clientVersion ?? "0.0.1",
|
|
883
|
+
sessionId: this.clientSessionId
|
|
884
|
+
};
|
|
885
|
+
this.client = new index_js.Client(clientInfo, {
|
|
886
|
+
capabilities
|
|
887
|
+
});
|
|
868
888
|
if (this.config.onElicitationUrl) {
|
|
869
889
|
const onElicitationUrl = this.config.onElicitationUrl;
|
|
870
890
|
this.client.setRequestHandler(types_js.ElicitRequestSchema, async (request) => {
|
|
@@ -2118,7 +2138,11 @@ function createKontextOrchestrator(config) {
|
|
|
2118
2138
|
}
|
|
2119
2139
|
|
|
2120
2140
|
// src/client/index.ts
|
|
2121
|
-
var META_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
2141
|
+
var META_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
2142
|
+
"SEARCH_TOOLS",
|
|
2143
|
+
"EXECUTE_TOOL",
|
|
2144
|
+
"REQUEST_CAPABILITY"
|
|
2145
|
+
]);
|
|
2122
2146
|
function hasMetaTools(tools) {
|
|
2123
2147
|
let hasSearch = false;
|
|
2124
2148
|
let hasExecute = false;
|
|
@@ -3674,6 +3698,12 @@ var Kontext = class _Kontext {
|
|
|
3674
3698
|
// ===========================================================================
|
|
3675
3699
|
createAgentSession(userToken, mcpSessionId, metadata) {
|
|
3676
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
|
+
}
|
|
3677
3707
|
const tokenIdentifier = crypto$1.createHash("sha256").update(userToken).digest("hex");
|
|
3678
3708
|
this.getServiceToken().then(
|
|
3679
3709
|
(token) => fetch(`${this.apiUrl}/api/v1/agent-sessions`, {
|
|
@@ -3684,6 +3714,8 @@ var Kontext = class _Kontext {
|
|
|
3684
3714
|
},
|
|
3685
3715
|
body: JSON.stringify({
|
|
3686
3716
|
tokenIdentifier,
|
|
3717
|
+
authenticatedUserId: metadata.authenticatedUserId,
|
|
3718
|
+
clientSessionId: mcpSessionId,
|
|
3687
3719
|
hostname: metadata?.hostname,
|
|
3688
3720
|
userAgent: metadata?.userAgent,
|
|
3689
3721
|
clientInfo: metadata?.clientInfo,
|
|
@@ -3904,6 +3936,7 @@ var Kontext = class _Kontext {
|
|
|
3904
3936
|
status: "ok"
|
|
3905
3937
|
});
|
|
3906
3938
|
this.createAgentSession(authInfo?.token, sid, {
|
|
3939
|
+
authenticatedUserId: typeof authInfo?.extra?.sub === "string" ? authInfo.extra.sub : void 0,
|
|
3907
3940
|
hostname: req.headers["x-forwarded-for"],
|
|
3908
3941
|
userAgent: req.headers["user-agent"],
|
|
3909
3942
|
tokenExpiresAt: authInfo?.expiresAt
|