@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.js
CHANGED
|
@@ -536,6 +536,7 @@ var KontextMcp = class {
|
|
|
536
536
|
config;
|
|
537
537
|
storage;
|
|
538
538
|
oauthProvider;
|
|
539
|
+
clientSessionId = typeof globalThis.crypto?.randomUUID === "function" ? globalThis.crypto.randomUUID() : `kontext-sdk-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
539
540
|
transport = null;
|
|
540
541
|
client = null;
|
|
541
542
|
_isConnected = false;
|
|
@@ -707,7 +708,22 @@ var KontextMcp = class {
|
|
|
707
708
|
const url = typeof item.url === "string" ? item.url : "";
|
|
708
709
|
if (!id || !url) return null;
|
|
709
710
|
const category = item.category === "internal_mcp_credentials" ? "internal_mcp_credentials" : "gateway_remote_mcp";
|
|
710
|
-
const
|
|
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
|
+
}
|
|
711
727
|
const rawConnection = item.connection && typeof item.connection === "object" ? item.connection : void 0;
|
|
712
728
|
const connected = rawConnection && typeof rawConnection.connected === "boolean" ? rawConnection.connected : false;
|
|
713
729
|
const status = rawConnection?.status === "connected" ? "connected" : "disconnected";
|
|
@@ -718,6 +734,9 @@ var KontextMcp = class {
|
|
|
718
734
|
category,
|
|
719
735
|
connectType,
|
|
720
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,
|
|
721
740
|
credentialSchema: item.credentialSchema,
|
|
722
741
|
requiresOauth: typeof item.requiresOauth === "boolean" ? item.requiresOauth : void 0,
|
|
723
742
|
connection: rawConnection ? {
|
|
@@ -855,13 +874,14 @@ var KontextMcp = class {
|
|
|
855
874
|
if (this.config.onElicitationUrl) {
|
|
856
875
|
capabilities.elicitation = { url: {} };
|
|
857
876
|
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
877
|
+
const clientInfo = {
|
|
878
|
+
name: this.config.clientName ?? "kontext-sdk",
|
|
879
|
+
version: this.config.clientVersion ?? "0.0.1",
|
|
880
|
+
sessionId: this.clientSessionId
|
|
881
|
+
};
|
|
882
|
+
this.client = new Client(clientInfo, {
|
|
883
|
+
capabilities
|
|
884
|
+
});
|
|
865
885
|
if (this.config.onElicitationUrl) {
|
|
866
886
|
const onElicitationUrl = this.config.onElicitationUrl;
|
|
867
887
|
this.client.setRequestHandler(ElicitRequestSchema, async (request) => {
|
|
@@ -2115,7 +2135,11 @@ function createKontextOrchestrator(config) {
|
|
|
2115
2135
|
}
|
|
2116
2136
|
|
|
2117
2137
|
// src/client/index.ts
|
|
2118
|
-
var META_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
2138
|
+
var META_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
2139
|
+
"SEARCH_TOOLS",
|
|
2140
|
+
"EXECUTE_TOOL",
|
|
2141
|
+
"REQUEST_CAPABILITY"
|
|
2142
|
+
]);
|
|
2119
2143
|
function hasMetaTools(tools) {
|
|
2120
2144
|
let hasSearch = false;
|
|
2121
2145
|
let hasExecute = false;
|
|
@@ -3671,6 +3695,12 @@ var Kontext = class _Kontext {
|
|
|
3671
3695
|
// ===========================================================================
|
|
3672
3696
|
createAgentSession(userToken, mcpSessionId, metadata) {
|
|
3673
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
|
+
}
|
|
3674
3704
|
const tokenIdentifier = createHash("sha256").update(userToken).digest("hex");
|
|
3675
3705
|
this.getServiceToken().then(
|
|
3676
3706
|
(token) => fetch(`${this.apiUrl}/api/v1/agent-sessions`, {
|
|
@@ -3681,6 +3711,8 @@ var Kontext = class _Kontext {
|
|
|
3681
3711
|
},
|
|
3682
3712
|
body: JSON.stringify({
|
|
3683
3713
|
tokenIdentifier,
|
|
3714
|
+
authenticatedUserId: metadata.authenticatedUserId,
|
|
3715
|
+
clientSessionId: mcpSessionId,
|
|
3684
3716
|
hostname: metadata?.hostname,
|
|
3685
3717
|
userAgent: metadata?.userAgent,
|
|
3686
3718
|
clientInfo: metadata?.clientInfo,
|
|
@@ -3901,6 +3933,7 @@ var Kontext = class _Kontext {
|
|
|
3901
3933
|
status: "ok"
|
|
3902
3934
|
});
|
|
3903
3935
|
this.createAgentSession(authInfo?.token, sid, {
|
|
3936
|
+
authenticatedUserId: typeof authInfo?.extra?.sub === "string" ? authInfo.extra.sub : void 0,
|
|
3904
3937
|
hostname: req.headers["x-forwarded-for"],
|
|
3905
3938
|
userAgent: req.headers["user-agent"],
|
|
3906
3939
|
tokenExpiresAt: authInfo?.expiresAt
|