@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.cjs
CHANGED
|
@@ -69,8 +69,6 @@ var StorageKeys = {
|
|
|
69
69
|
function resourceTokenKey(resource) {
|
|
70
70
|
return `${StorageKeys.RESOURCE_TOKENS}:${resource}`;
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
// src/errors.ts
|
|
74
72
|
var KontextError = class extends Error {
|
|
75
73
|
/** Brand field for type narrowing without instanceof */
|
|
76
74
|
kontextError = true;
|
|
@@ -190,15 +188,90 @@ function isNetworkError(err) {
|
|
|
190
188
|
if (typeof causeCode === "string" && NETWORK_ERROR_CODES.has(causeCode))
|
|
191
189
|
return true;
|
|
192
190
|
}
|
|
191
|
+
if (err.name === "TypeError") {
|
|
192
|
+
const msg = err.message.toLowerCase();
|
|
193
|
+
if (msg === "failed to fetch" || msg === "load failed" || msg.includes("networkerror")) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
193
197
|
return false;
|
|
194
198
|
}
|
|
195
199
|
function isUnauthorizedError(err) {
|
|
196
200
|
const props = errorProps(err);
|
|
197
201
|
if (props.statusCode === 401 || props.status === 401) return true;
|
|
202
|
+
if (props.code === 401) return true;
|
|
198
203
|
if (err.name === "UnauthorizedError") return true;
|
|
204
|
+
if (err.constructor?.name === "UnauthorizedError") return true;
|
|
199
205
|
if (err.message === "Unauthorized") return true;
|
|
200
206
|
return false;
|
|
201
207
|
}
|
|
208
|
+
var MCP_CODE_MAP = {
|
|
209
|
+
[types_js.ErrorCode.ParseError]: { code: "kontext_mcp_parse_error" },
|
|
210
|
+
[types_js.ErrorCode.InvalidRequest]: { code: "kontext_mcp_invalid_request" },
|
|
211
|
+
[types_js.ErrorCode.MethodNotFound]: { code: "kontext_mcp_method_not_found" },
|
|
212
|
+
[types_js.ErrorCode.InvalidParams]: { code: "kontext_mcp_invalid_params" },
|
|
213
|
+
[types_js.ErrorCode.InternalError]: {
|
|
214
|
+
code: "kontext_mcp_internal_error",
|
|
215
|
+
statusCode: 500
|
|
216
|
+
},
|
|
217
|
+
[types_js.ErrorCode.RequestTimeout]: {
|
|
218
|
+
code: "kontext_mcp_session_expired",
|
|
219
|
+
statusCode: 401
|
|
220
|
+
},
|
|
221
|
+
[types_js.ErrorCode.ConnectionClosed]: { code: "kontext_mcp_session_error" }
|
|
222
|
+
};
|
|
223
|
+
function translateError(err) {
|
|
224
|
+
if (isKontextError(err)) return err;
|
|
225
|
+
if (!(err instanceof Error)) {
|
|
226
|
+
return new KontextError(String(err), "kontext_unknown_error");
|
|
227
|
+
}
|
|
228
|
+
const props = err;
|
|
229
|
+
if (props.code === types_js.ErrorCode.UrlElicitationRequired) {
|
|
230
|
+
const elicitations = props.elicitations ?? props.data?.elicitations;
|
|
231
|
+
const elicitation = elicitations?.[0];
|
|
232
|
+
return new IntegrationConnectionRequiredError(
|
|
233
|
+
elicitation?.integrationId ?? "unknown",
|
|
234
|
+
{
|
|
235
|
+
integrationName: elicitation?.integrationName,
|
|
236
|
+
connectUrl: elicitation?.url,
|
|
237
|
+
message: elicitation?.message,
|
|
238
|
+
cause: err
|
|
239
|
+
}
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
if (typeof props.code === "number" && props.code < 0) {
|
|
243
|
+
const entry = MCP_CODE_MAP[props.code];
|
|
244
|
+
if (entry) {
|
|
245
|
+
return new KontextError(err.message, entry.code, {
|
|
246
|
+
statusCode: entry.statusCode,
|
|
247
|
+
cause: err
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
return new KontextError(err.message, "kontext_mcp_error", {
|
|
251
|
+
cause: err,
|
|
252
|
+
meta: { mcpCode: props.code }
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
const statusCode = props.statusCode ?? props.status ?? (typeof props.code === "number" && props.code >= 400 && props.code < 600 ? props.code : void 0);
|
|
256
|
+
if (typeof statusCode === "number" && statusCode >= 400) {
|
|
257
|
+
if (statusCode === 401) {
|
|
258
|
+
return new AuthorizationRequiredError(err.message, { cause: err });
|
|
259
|
+
}
|
|
260
|
+
return new KontextError(err.message, "kontext_server_error", {
|
|
261
|
+
statusCode,
|
|
262
|
+
cause: err
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
if (isUnauthorizedError(err)) {
|
|
266
|
+
return new AuthorizationRequiredError(err.message, { cause: err });
|
|
267
|
+
}
|
|
268
|
+
if (isNetworkError(err)) {
|
|
269
|
+
return new NetworkError(err.message, { cause: err });
|
|
270
|
+
}
|
|
271
|
+
return new KontextError(err.message, "kontext_unknown_error", {
|
|
272
|
+
cause: err
|
|
273
|
+
});
|
|
274
|
+
}
|
|
202
275
|
|
|
203
276
|
// src/oauth/provider.ts
|
|
204
277
|
var KontextOAuthProvider = class {
|
|
@@ -1366,35 +1439,21 @@ async function withTransientRetry(operation, maxRetries = 1) {
|
|
|
1366
1439
|
function toKontextError(err, context) {
|
|
1367
1440
|
const contextMeta = context ? { ...context } : void 0;
|
|
1368
1441
|
const mergeMeta = (base) => contextMeta ? { ...base ?? {}, ...contextMeta } : base ?? {};
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
}
|
|
1373
|
-
const cloned = Object.create(Object.getPrototypeOf(err));
|
|
1374
|
-
Object.defineProperties(cloned, Object.getOwnPropertyDescriptors(err));
|
|
1375
|
-
Object.defineProperty(cloned, "meta", {
|
|
1376
|
-
value: mergeMeta(err.meta),
|
|
1377
|
-
enumerable: true,
|
|
1378
|
-
writable: true,
|
|
1379
|
-
configurable: true
|
|
1380
|
-
});
|
|
1381
|
-
return cloned;
|
|
1382
|
-
}
|
|
1383
|
-
if (err instanceof Error) {
|
|
1384
|
-
if (isUnauthorizedError(err)) {
|
|
1385
|
-
return new AuthorizationRequiredError(err.message, {
|
|
1386
|
-
meta: mergeMeta(),
|
|
1387
|
-
cause: err
|
|
1388
|
-
});
|
|
1389
|
-
}
|
|
1390
|
-
return new KontextError(err.message, "kontext_unknown_error", {
|
|
1391
|
-
meta: mergeMeta(),
|
|
1392
|
-
cause: err
|
|
1393
|
-
});
|
|
1442
|
+
const translated = translateError(err);
|
|
1443
|
+
if (!contextMeta) {
|
|
1444
|
+
return translated;
|
|
1394
1445
|
}
|
|
1395
|
-
|
|
1396
|
-
|
|
1446
|
+
const cloned = Object.create(
|
|
1447
|
+
Object.getPrototypeOf(translated)
|
|
1448
|
+
);
|
|
1449
|
+
Object.defineProperties(cloned, Object.getOwnPropertyDescriptors(translated));
|
|
1450
|
+
Object.defineProperty(cloned, "meta", {
|
|
1451
|
+
value: mergeMeta(translated.meta),
|
|
1452
|
+
enumerable: true,
|
|
1453
|
+
writable: true,
|
|
1454
|
+
configurable: true
|
|
1397
1455
|
});
|
|
1456
|
+
return cloned;
|
|
1398
1457
|
}
|
|
1399
1458
|
function isAuthorizationRequired(err) {
|
|
1400
1459
|
if (err instanceof AuthorizationRequiredError) return true;
|
|
@@ -2108,45 +2167,6 @@ function extractTextContent(result) {
|
|
|
2108
2167
|
}
|
|
2109
2168
|
return JSON.stringify(result);
|
|
2110
2169
|
}
|
|
2111
|
-
function translateError(err) {
|
|
2112
|
-
if (isKontextError(err)) return err;
|
|
2113
|
-
if (!(err instanceof Error)) {
|
|
2114
|
-
return new KontextError(String(err), "kontext_unknown_error");
|
|
2115
|
-
}
|
|
2116
|
-
const props = err;
|
|
2117
|
-
if (props.code === -32042) {
|
|
2118
|
-
const elicitations = props.elicitations ?? props.data?.elicitations;
|
|
2119
|
-
const elicitation = elicitations?.[0];
|
|
2120
|
-
return new IntegrationConnectionRequiredError(
|
|
2121
|
-
elicitation?.integrationId ?? "unknown",
|
|
2122
|
-
{
|
|
2123
|
-
integrationName: elicitation?.integrationName,
|
|
2124
|
-
connectUrl: elicitation?.url,
|
|
2125
|
-
message: elicitation?.message,
|
|
2126
|
-
cause: err
|
|
2127
|
-
}
|
|
2128
|
-
);
|
|
2129
|
-
}
|
|
2130
|
-
const statusCode = props.statusCode ?? props.status;
|
|
2131
|
-
if (typeof statusCode === "number" && statusCode >= 400) {
|
|
2132
|
-
if (statusCode === 401) {
|
|
2133
|
-
return new AuthorizationRequiredError(err.message, { cause: err });
|
|
2134
|
-
}
|
|
2135
|
-
return new KontextError(err.message, "kontext_server_error", {
|
|
2136
|
-
statusCode,
|
|
2137
|
-
cause: err
|
|
2138
|
-
});
|
|
2139
|
-
}
|
|
2140
|
-
if (isUnauthorizedError(err)) {
|
|
2141
|
-
return new AuthorizationRequiredError(err.message, { cause: err });
|
|
2142
|
-
}
|
|
2143
|
-
if (isNetworkError(err)) {
|
|
2144
|
-
return new NetworkError(err.message, { cause: err });
|
|
2145
|
-
}
|
|
2146
|
-
return new KontextError(err.message, "kontext_unknown_error", {
|
|
2147
|
-
cause: err
|
|
2148
|
-
});
|
|
2149
|
-
}
|
|
2150
2170
|
function createSingleEndpointKontextClient(config) {
|
|
2151
2171
|
if (!config.clientId) {
|
|
2152
2172
|
throw new ConfigError(
|
|
@@ -2435,5 +2455,6 @@ function createKontextClient(config) {
|
|
|
2435
2455
|
|
|
2436
2456
|
exports.createKontextClient = createKontextClient;
|
|
2437
2457
|
exports.createSingleEndpointKontextClient = createSingleEndpointKontextClient;
|
|
2458
|
+
exports.translateError = translateError;
|
|
2438
2459
|
//# sourceMappingURL=index.cjs.map
|
|
2439
2460
|
//# sourceMappingURL=index.cjs.map
|