@kontext-dev/js-sdk 1.0.0 → 1.1.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 +12 -2
- package/dist/adapters/ai/index.cjs.map +1 -1
- package/dist/adapters/ai/index.js +12 -2
- package/dist/adapters/ai/index.js.map +1 -1
- package/dist/adapters/cloudflare/index.cjs +13 -0
- package/dist/adapters/cloudflare/index.cjs.map +1 -1
- package/dist/adapters/cloudflare/index.js +13 -0
- package/dist/adapters/cloudflare/index.js.map +1 -1
- package/dist/adapters/cloudflare/react.cjs +12 -2
- package/dist/adapters/cloudflare/react.cjs.map +1 -1
- package/dist/adapters/cloudflare/react.js +12 -2
- package/dist/adapters/cloudflare/react.js.map +1 -1
- package/dist/adapters/react/index.cjs +12 -2
- package/dist/adapters/react/index.cjs.map +1 -1
- package/dist/adapters/react/index.js +12 -2
- package/dist/adapters/react/index.js.map +1 -1
- package/dist/client/index.cjs +89 -68
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +2 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +90 -70
- package/dist/client/index.js.map +1 -1
- package/dist/errors.cjs +78 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +7 -1
- package/dist/errors.d.ts +7 -1
- package/dist/errors.js +78 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.cjs +124 -86
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +125 -87
- package/dist/index.js.map +1 -1
- package/dist/{kontext-CgIBANFo.d.cts → kontext-CBPuE-hq.d.cts} +3 -0
- package/dist/{kontext-CgIBANFo.d.ts → kontext-CBPuE-hq.d.ts} +3 -0
- package/dist/management/index.cjs +15 -0
- 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 +15 -1
- package/dist/management/index.js.map +1 -1
- package/dist/mcp/index.cjs +13 -2
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.d.cts +3 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.js +14 -3
- package/dist/mcp/index.js.map +1 -1
- package/dist/oauth/index.cjs +12 -2
- 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 +12 -2
- package/dist/oauth/index.js.map +1 -1
- package/dist/server/index.cjs +47 -20
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +2 -2
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +48 -21
- package/dist/server/index.js.map +1 -1
- package/dist/{types-C6ep5fVw.d.cts → types-DicGI7ix.d.cts} +21 -1
- package/dist/{types-C6ep5fVw.d.ts → types-DicGI7ix.d.ts} +21 -1
- package/package.json +1 -1
package/dist/client/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { KontextMcp } from '../mcp/index.cjs';
|
|
2
2
|
import { K as KontextStorage } from '../types-RIzHnRpk.cjs';
|
|
3
3
|
import { KontextError } from '../errors.cjs';
|
|
4
|
+
export { translateError } from '../errors.cjs';
|
|
4
5
|
import '@modelcontextprotocol/sdk/client/index.js';
|
|
5
6
|
import '@modelcontextprotocol/sdk/types.js';
|
|
6
7
|
|
|
@@ -108,6 +109,7 @@ interface KontextClient {
|
|
|
108
109
|
*/
|
|
109
110
|
readonly mcp: KontextMcp;
|
|
110
111
|
}
|
|
112
|
+
|
|
111
113
|
declare function createSingleEndpointKontextClient(config: KontextClientConfig): KontextClient;
|
|
112
114
|
/**
|
|
113
115
|
* Primary SDK client entrypoint.
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { KontextMcp } from '../mcp/index.js';
|
|
2
2
|
import { K as KontextStorage } from '../types-RIzHnRpk.js';
|
|
3
3
|
import { KontextError } from '../errors.js';
|
|
4
|
+
export { translateError } from '../errors.js';
|
|
4
5
|
import '@modelcontextprotocol/sdk/client/index.js';
|
|
5
6
|
import '@modelcontextprotocol/sdk/types.js';
|
|
6
7
|
|
|
@@ -108,6 +109,7 @@ interface KontextClient {
|
|
|
108
109
|
*/
|
|
109
110
|
readonly mcp: KontextMcp;
|
|
110
111
|
}
|
|
112
|
+
|
|
111
113
|
declare function createSingleEndpointKontextClient(config: KontextClientConfig): KontextClient;
|
|
112
114
|
/**
|
|
113
115
|
* Primary SDK client entrypoint.
|
package/dist/client/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
2
2
|
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
3
|
-
import { UrlElicitationRequiredError, ElicitRequestSchema, ElicitationCompleteNotificationSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
import { ErrorCode, UrlElicitationRequiredError, ElicitRequestSchema, ElicitationCompleteNotificationSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
4
4
|
import { randomBytes } from 'crypto';
|
|
5
5
|
|
|
6
6
|
// src/mcp/client.ts
|
|
@@ -67,8 +67,6 @@ var StorageKeys = {
|
|
|
67
67
|
function resourceTokenKey(resource) {
|
|
68
68
|
return `${StorageKeys.RESOURCE_TOKENS}:${resource}`;
|
|
69
69
|
}
|
|
70
|
-
|
|
71
|
-
// src/errors.ts
|
|
72
70
|
var KontextError = class extends Error {
|
|
73
71
|
/** Brand field for type narrowing without instanceof */
|
|
74
72
|
kontextError = true;
|
|
@@ -188,15 +186,90 @@ function isNetworkError(err) {
|
|
|
188
186
|
if (typeof causeCode === "string" && NETWORK_ERROR_CODES.has(causeCode))
|
|
189
187
|
return true;
|
|
190
188
|
}
|
|
189
|
+
if (err.name === "TypeError") {
|
|
190
|
+
const msg = err.message.toLowerCase();
|
|
191
|
+
if (msg === "failed to fetch" || msg === "load failed" || msg.includes("networkerror")) {
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
191
195
|
return false;
|
|
192
196
|
}
|
|
193
197
|
function isUnauthorizedError(err) {
|
|
194
198
|
const props = errorProps(err);
|
|
195
199
|
if (props.statusCode === 401 || props.status === 401) return true;
|
|
200
|
+
if (props.code === 401) return true;
|
|
196
201
|
if (err.name === "UnauthorizedError") return true;
|
|
202
|
+
if (err.constructor?.name === "UnauthorizedError") return true;
|
|
197
203
|
if (err.message === "Unauthorized") return true;
|
|
198
204
|
return false;
|
|
199
205
|
}
|
|
206
|
+
var MCP_CODE_MAP = {
|
|
207
|
+
[ErrorCode.ParseError]: { code: "kontext_mcp_parse_error" },
|
|
208
|
+
[ErrorCode.InvalidRequest]: { code: "kontext_mcp_invalid_request" },
|
|
209
|
+
[ErrorCode.MethodNotFound]: { code: "kontext_mcp_method_not_found" },
|
|
210
|
+
[ErrorCode.InvalidParams]: { code: "kontext_mcp_invalid_params" },
|
|
211
|
+
[ErrorCode.InternalError]: {
|
|
212
|
+
code: "kontext_mcp_internal_error",
|
|
213
|
+
statusCode: 500
|
|
214
|
+
},
|
|
215
|
+
[ErrorCode.RequestTimeout]: {
|
|
216
|
+
code: "kontext_mcp_session_expired",
|
|
217
|
+
statusCode: 401
|
|
218
|
+
},
|
|
219
|
+
[ErrorCode.ConnectionClosed]: { code: "kontext_mcp_session_error" }
|
|
220
|
+
};
|
|
221
|
+
function translateError(err) {
|
|
222
|
+
if (isKontextError(err)) return err;
|
|
223
|
+
if (!(err instanceof Error)) {
|
|
224
|
+
return new KontextError(String(err), "kontext_unknown_error");
|
|
225
|
+
}
|
|
226
|
+
const props = err;
|
|
227
|
+
if (props.code === ErrorCode.UrlElicitationRequired) {
|
|
228
|
+
const elicitations = props.elicitations ?? props.data?.elicitations;
|
|
229
|
+
const elicitation = elicitations?.[0];
|
|
230
|
+
return new IntegrationConnectionRequiredError(
|
|
231
|
+
elicitation?.integrationId ?? "unknown",
|
|
232
|
+
{
|
|
233
|
+
integrationName: elicitation?.integrationName,
|
|
234
|
+
connectUrl: elicitation?.url,
|
|
235
|
+
message: elicitation?.message,
|
|
236
|
+
cause: err
|
|
237
|
+
}
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
if (typeof props.code === "number" && props.code < 0) {
|
|
241
|
+
const entry = MCP_CODE_MAP[props.code];
|
|
242
|
+
if (entry) {
|
|
243
|
+
return new KontextError(err.message, entry.code, {
|
|
244
|
+
statusCode: entry.statusCode,
|
|
245
|
+
cause: err
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
return new KontextError(err.message, "kontext_mcp_error", {
|
|
249
|
+
cause: err,
|
|
250
|
+
meta: { mcpCode: props.code }
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
const statusCode = props.statusCode ?? props.status ?? (typeof props.code === "number" && props.code >= 400 && props.code < 600 ? props.code : void 0);
|
|
254
|
+
if (typeof statusCode === "number" && statusCode >= 400) {
|
|
255
|
+
if (statusCode === 401) {
|
|
256
|
+
return new AuthorizationRequiredError(err.message, { cause: err });
|
|
257
|
+
}
|
|
258
|
+
return new KontextError(err.message, "kontext_server_error", {
|
|
259
|
+
statusCode,
|
|
260
|
+
cause: err
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
if (isUnauthorizedError(err)) {
|
|
264
|
+
return new AuthorizationRequiredError(err.message, { cause: err });
|
|
265
|
+
}
|
|
266
|
+
if (isNetworkError(err)) {
|
|
267
|
+
return new NetworkError(err.message, { cause: err });
|
|
268
|
+
}
|
|
269
|
+
return new KontextError(err.message, "kontext_unknown_error", {
|
|
270
|
+
cause: err
|
|
271
|
+
});
|
|
272
|
+
}
|
|
200
273
|
|
|
201
274
|
// src/oauth/provider.ts
|
|
202
275
|
var KontextOAuthProvider = class {
|
|
@@ -1364,35 +1437,21 @@ async function withTransientRetry(operation, maxRetries = 1) {
|
|
|
1364
1437
|
function toKontextError(err, context) {
|
|
1365
1438
|
const contextMeta = context ? { ...context } : void 0;
|
|
1366
1439
|
const mergeMeta = (base) => contextMeta ? { ...base ?? {}, ...contextMeta } : base ?? {};
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
}
|
|
1371
|
-
const cloned = Object.create(Object.getPrototypeOf(err));
|
|
1372
|
-
Object.defineProperties(cloned, Object.getOwnPropertyDescriptors(err));
|
|
1373
|
-
Object.defineProperty(cloned, "meta", {
|
|
1374
|
-
value: mergeMeta(err.meta),
|
|
1375
|
-
enumerable: true,
|
|
1376
|
-
writable: true,
|
|
1377
|
-
configurable: true
|
|
1378
|
-
});
|
|
1379
|
-
return cloned;
|
|
1380
|
-
}
|
|
1381
|
-
if (err instanceof Error) {
|
|
1382
|
-
if (isUnauthorizedError(err)) {
|
|
1383
|
-
return new AuthorizationRequiredError(err.message, {
|
|
1384
|
-
meta: mergeMeta(),
|
|
1385
|
-
cause: err
|
|
1386
|
-
});
|
|
1387
|
-
}
|
|
1388
|
-
return new KontextError(err.message, "kontext_unknown_error", {
|
|
1389
|
-
meta: mergeMeta(),
|
|
1390
|
-
cause: err
|
|
1391
|
-
});
|
|
1440
|
+
const translated = translateError(err);
|
|
1441
|
+
if (!contextMeta) {
|
|
1442
|
+
return translated;
|
|
1392
1443
|
}
|
|
1393
|
-
|
|
1394
|
-
|
|
1444
|
+
const cloned = Object.create(
|
|
1445
|
+
Object.getPrototypeOf(translated)
|
|
1446
|
+
);
|
|
1447
|
+
Object.defineProperties(cloned, Object.getOwnPropertyDescriptors(translated));
|
|
1448
|
+
Object.defineProperty(cloned, "meta", {
|
|
1449
|
+
value: mergeMeta(translated.meta),
|
|
1450
|
+
enumerable: true,
|
|
1451
|
+
writable: true,
|
|
1452
|
+
configurable: true
|
|
1395
1453
|
});
|
|
1454
|
+
return cloned;
|
|
1396
1455
|
}
|
|
1397
1456
|
function isAuthorizationRequired(err) {
|
|
1398
1457
|
if (err instanceof AuthorizationRequiredError) return true;
|
|
@@ -2106,45 +2165,6 @@ function extractTextContent(result) {
|
|
|
2106
2165
|
}
|
|
2107
2166
|
return JSON.stringify(result);
|
|
2108
2167
|
}
|
|
2109
|
-
function translateError(err) {
|
|
2110
|
-
if (isKontextError(err)) return err;
|
|
2111
|
-
if (!(err instanceof Error)) {
|
|
2112
|
-
return new KontextError(String(err), "kontext_unknown_error");
|
|
2113
|
-
}
|
|
2114
|
-
const props = err;
|
|
2115
|
-
if (props.code === -32042) {
|
|
2116
|
-
const elicitations = props.elicitations ?? props.data?.elicitations;
|
|
2117
|
-
const elicitation = elicitations?.[0];
|
|
2118
|
-
return new IntegrationConnectionRequiredError(
|
|
2119
|
-
elicitation?.integrationId ?? "unknown",
|
|
2120
|
-
{
|
|
2121
|
-
integrationName: elicitation?.integrationName,
|
|
2122
|
-
connectUrl: elicitation?.url,
|
|
2123
|
-
message: elicitation?.message,
|
|
2124
|
-
cause: err
|
|
2125
|
-
}
|
|
2126
|
-
);
|
|
2127
|
-
}
|
|
2128
|
-
const statusCode = props.statusCode ?? props.status;
|
|
2129
|
-
if (typeof statusCode === "number" && statusCode >= 400) {
|
|
2130
|
-
if (statusCode === 401) {
|
|
2131
|
-
return new AuthorizationRequiredError(err.message, { cause: err });
|
|
2132
|
-
}
|
|
2133
|
-
return new KontextError(err.message, "kontext_server_error", {
|
|
2134
|
-
statusCode,
|
|
2135
|
-
cause: err
|
|
2136
|
-
});
|
|
2137
|
-
}
|
|
2138
|
-
if (isUnauthorizedError(err)) {
|
|
2139
|
-
return new AuthorizationRequiredError(err.message, { cause: err });
|
|
2140
|
-
}
|
|
2141
|
-
if (isNetworkError(err)) {
|
|
2142
|
-
return new NetworkError(err.message, { cause: err });
|
|
2143
|
-
}
|
|
2144
|
-
return new KontextError(err.message, "kontext_unknown_error", {
|
|
2145
|
-
cause: err
|
|
2146
|
-
});
|
|
2147
|
-
}
|
|
2148
2168
|
function createSingleEndpointKontextClient(config) {
|
|
2149
2169
|
if (!config.clientId) {
|
|
2150
2170
|
throw new ConfigError(
|
|
@@ -2431,6 +2451,6 @@ function createKontextClient(config) {
|
|
|
2431
2451
|
return createKontextOrchestrator(config);
|
|
2432
2452
|
}
|
|
2433
2453
|
|
|
2434
|
-
export { createKontextClient, createSingleEndpointKontextClient };
|
|
2454
|
+
export { createKontextClient, createSingleEndpointKontextClient, translateError };
|
|
2435
2455
|
//# sourceMappingURL=index.js.map
|
|
2436
2456
|
//# sourceMappingURL=index.js.map
|