@inkeep/agents-manage-mcp 0.0.0-dev-20251222193909 → 0.0.0-dev-20251222215156

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
@@ -1,4 +1,8 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import "@modelcontextprotocol/sdk/server/zod-compat.js";
3
+ import "@modelcontextprotocol/sdk/shared/protocol.js";
4
+ import "@modelcontextprotocol/sdk/types.js";
5
+ import "@modelcontextprotocol/sdk/shared/uriTemplate.js";
2
6
 
3
7
  //#region ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
4
8
  var util;
@@ -3598,6 +3602,418 @@ const coerce = {
3598
3602
  }))
3599
3603
  };
3600
3604
 
3605
+ //#endregion
3606
+ //#region src/lib/http.ts
3607
+ const DEFAULT_FETCHER = (input, init) => {
3608
+ if (init == null) return fetch(input);
3609
+ else return fetch(input, init);
3610
+ };
3611
+ var HTTPClient = class HTTPClient {
3612
+ fetcher;
3613
+ requestHooks = [];
3614
+ requestErrorHooks = [];
3615
+ responseHooks = [];
3616
+ constructor(options = {}) {
3617
+ this.options = options;
3618
+ this.fetcher = options.fetcher || DEFAULT_FETCHER;
3619
+ }
3620
+ async request(request) {
3621
+ let req = request;
3622
+ for (const hook of this.requestHooks) {
3623
+ const nextRequest = await hook(req);
3624
+ if (nextRequest) req = nextRequest;
3625
+ }
3626
+ try {
3627
+ const res = await this.fetcher(req);
3628
+ for (const hook of this.responseHooks) await hook(res, req);
3629
+ return res;
3630
+ } catch (err) {
3631
+ for (const hook of this.requestErrorHooks) await hook(err, req);
3632
+ throw err;
3633
+ }
3634
+ }
3635
+ addHook(...args$113) {
3636
+ if (args$113[0] === "beforeRequest") this.requestHooks.push(args$113[1]);
3637
+ else if (args$113[0] === "requestError") this.requestErrorHooks.push(args$113[1]);
3638
+ else if (args$113[0] === "response") this.responseHooks.push(args$113[1]);
3639
+ else throw new Error(`Invalid hook type: ${args$113[0]}`);
3640
+ return this;
3641
+ }
3642
+ removeHook(...args$113) {
3643
+ let target;
3644
+ if (args$113[0] === "beforeRequest") target = this.requestHooks;
3645
+ else if (args$113[0] === "requestError") target = this.requestErrorHooks;
3646
+ else if (args$113[0] === "response") target = this.responseHooks;
3647
+ else throw new Error(`Invalid hook type: ${args$113[0]}`);
3648
+ const index = target.findIndex((v) => v === args$113[1]);
3649
+ if (index >= 0) target.splice(index, 1);
3650
+ return this;
3651
+ }
3652
+ clone() {
3653
+ const child = new HTTPClient(this.options);
3654
+ child.requestHooks = this.requestHooks.slice();
3655
+ child.requestErrorHooks = this.requestErrorHooks.slice();
3656
+ child.responseHooks = this.responseHooks.slice();
3657
+ return child;
3658
+ }
3659
+ };
3660
+ const mediaParamSeparator = /\s*;\s*/g;
3661
+ function matchContentType(response, pattern) {
3662
+ if (pattern === "*") return true;
3663
+ let contentType = response.headers.get("content-type")?.trim() || "application/octet-stream";
3664
+ contentType = contentType.toLowerCase();
3665
+ const [wantType = "", ...wantParams] = pattern.toLowerCase().trim().split(mediaParamSeparator);
3666
+ if (wantType.split("/").length !== 2) return false;
3667
+ const [gotType = "", ...gotParams] = contentType.split(mediaParamSeparator);
3668
+ const [type = "", subtype = ""] = gotType.split("/");
3669
+ if (!type || !subtype) return false;
3670
+ if (wantType !== "*/*" && gotType !== wantType && `${type}/*` !== wantType && `*/${subtype}` !== wantType) return false;
3671
+ if (gotParams.length < wantParams.length) return false;
3672
+ const params = new Set(gotParams);
3673
+ for (const wantParam of wantParams) if (!params.has(wantParam)) return false;
3674
+ return true;
3675
+ }
3676
+ const codeRangeRE$1 = new RegExp("^[0-9]xx$", "i");
3677
+ function matchStatusCode(response, codes) {
3678
+ const actual = `${response.status}`;
3679
+ const expectedCodes = Array.isArray(codes) ? codes : [codes];
3680
+ if (!expectedCodes.length) return false;
3681
+ return expectedCodes.some((ec) => {
3682
+ const code = `${ec}`;
3683
+ if (code === "default") return true;
3684
+ if (!codeRangeRE$1.test(`${code}`)) return code === actual;
3685
+ const expectFamily = code.charAt(0);
3686
+ if (!expectFamily) throw new Error("Invalid status code range");
3687
+ const actualFamily = actual.charAt(0);
3688
+ if (!actualFamily) throw new Error(`Invalid response status code: ${actual}`);
3689
+ return actualFamily === expectFamily;
3690
+ });
3691
+ }
3692
+ function matchResponse(response, code, contentTypePattern) {
3693
+ return matchStatusCode(response, code) && matchContentType(response, contentTypePattern);
3694
+ }
3695
+ /**
3696
+ * Uses various heurisitics to determine if an error is a connection error.
3697
+ */
3698
+ function isConnectionError(err) {
3699
+ if (typeof err !== "object" || err == null) return false;
3700
+ const isBrowserErr = err instanceof TypeError && err.message.toLowerCase().startsWith("failed to fetch");
3701
+ const isNodeErr = err instanceof TypeError && err.message.toLowerCase().startsWith("fetch failed");
3702
+ const isBunErr = "name" in err && err.name === "ConnectionError";
3703
+ const isGenericErr = "code" in err && typeof err.code === "string" && err.code.toLowerCase() === "econnreset";
3704
+ return isBrowserErr || isNodeErr || isGenericErr || isBunErr;
3705
+ }
3706
+ /**
3707
+ * Uses various heurisitics to determine if an error is a timeout error.
3708
+ */
3709
+ function isTimeoutError(err) {
3710
+ if (typeof err !== "object" || err == null) return false;
3711
+ const isNative = "name" in err && err.name === "TimeoutError";
3712
+ const isLegacyNative = "code" in err && err.code === 23;
3713
+ const isGenericErr = "code" in err && typeof err.code === "string" && err.code.toLowerCase() === "econnaborted";
3714
+ return isNative || isLegacyNative || isGenericErr;
3715
+ }
3716
+ /**
3717
+ * Uses various heurisitics to determine if an error is a abort error.
3718
+ */
3719
+ function isAbortError(err) {
3720
+ if (typeof err !== "object" || err == null) return false;
3721
+ const isNative = "name" in err && err.name === "AbortError";
3722
+ const isLegacyNative = "code" in err && err.code === 20;
3723
+ const isGenericErr = "code" in err && typeof err.code === "string" && err.code.toLowerCase() === "econnaborted";
3724
+ return isNative || isLegacyNative || isGenericErr;
3725
+ }
3726
+
3727
+ //#endregion
3728
+ //#region src/lib/retries.ts
3729
+ const defaultBackoff = {
3730
+ initialInterval: 500,
3731
+ maxInterval: 6e4,
3732
+ exponent: 1.5,
3733
+ maxElapsedTime: 36e5
3734
+ };
3735
+ /**
3736
+ * PermanentError is an error that is not recoverable. Throwing this error will
3737
+ * cause a retry loop to terminate.
3738
+ */
3739
+ var PermanentError = class PermanentError extends Error {
3740
+ /** The underlying cause of the error. */
3741
+ cause;
3742
+ constructor(message, options) {
3743
+ let msg = message;
3744
+ if (options?.cause) msg += `: ${options.cause}`;
3745
+ super(msg, options);
3746
+ this.name = "PermanentError";
3747
+ if (typeof this.cause === "undefined") this.cause = options?.cause;
3748
+ Object.setPrototypeOf(this, PermanentError.prototype);
3749
+ }
3750
+ };
3751
+ /**
3752
+ * TemporaryError is an error is used to signal that an HTTP request can be
3753
+ * retried as part of a retry loop. If retry attempts are exhausted and this
3754
+ * error is thrown, the response will be returned to the caller.
3755
+ */
3756
+ var TemporaryError = class TemporaryError extends Error {
3757
+ response;
3758
+ constructor(message, response) {
3759
+ super(message);
3760
+ this.response = response;
3761
+ this.name = "TemporaryError";
3762
+ Object.setPrototypeOf(this, TemporaryError.prototype);
3763
+ }
3764
+ };
3765
+ async function retry(fetchFn, options) {
3766
+ switch (options.config.strategy) {
3767
+ case "backoff": return retryBackoff(wrapFetcher(fetchFn, {
3768
+ statusCodes: options.statusCodes,
3769
+ retryConnectionErrors: !!options.config.retryConnectionErrors
3770
+ }), options.config.backoff ?? defaultBackoff);
3771
+ default: return await fetchFn();
3772
+ }
3773
+ }
3774
+ function wrapFetcher(fn, options) {
3775
+ return async () => {
3776
+ try {
3777
+ const res = await fn();
3778
+ if (isRetryableResponse(res, options.statusCodes)) throw new TemporaryError("Response failed with retryable status code", res);
3779
+ return res;
3780
+ } catch (err) {
3781
+ if (err instanceof TemporaryError) throw err;
3782
+ if (options.retryConnectionErrors && (isTimeoutError(err) || isConnectionError(err))) throw err;
3783
+ throw new PermanentError("Permanent error", { cause: err });
3784
+ }
3785
+ };
3786
+ }
3787
+ const codeRangeRE = new RegExp("^[0-9]xx$", "i");
3788
+ function isRetryableResponse(res, statusCodes) {
3789
+ const actual = `${res.status}`;
3790
+ return statusCodes.some((code) => {
3791
+ if (!codeRangeRE.test(code)) return code === actual;
3792
+ const expectFamily = code.charAt(0);
3793
+ if (!expectFamily) throw new Error("Invalid status code range");
3794
+ const actualFamily = actual.charAt(0);
3795
+ if (!actualFamily) throw new Error(`Invalid response status code: ${actual}`);
3796
+ return actualFamily === expectFamily;
3797
+ });
3798
+ }
3799
+ async function retryBackoff(fn, strategy) {
3800
+ const { maxElapsedTime, initialInterval, exponent, maxInterval } = strategy;
3801
+ const start = Date.now();
3802
+ let x = 0;
3803
+ while (true) try {
3804
+ return await fn();
3805
+ } catch (err) {
3806
+ if (err instanceof PermanentError) throw err.cause;
3807
+ if (Date.now() - start > maxElapsedTime) {
3808
+ if (err instanceof TemporaryError) return err.response;
3809
+ throw err;
3810
+ }
3811
+ let retryInterval = 0;
3812
+ if (err instanceof TemporaryError) retryInterval = retryIntervalFromResponse(err.response);
3813
+ if (retryInterval <= 0) retryInterval = initialInterval * Math.pow(x, exponent) + Math.random() * 1e3;
3814
+ await delay(Math.min(retryInterval, maxInterval));
3815
+ x++;
3816
+ }
3817
+ }
3818
+ function retryIntervalFromResponse(res) {
3819
+ const retryVal = res.headers.get("retry-after") || "";
3820
+ if (!retryVal) return 0;
3821
+ const parsedNumber = Number(retryVal);
3822
+ if (Number.isInteger(parsedNumber)) return parsedNumber * 1e3;
3823
+ const parsedDate = Date.parse(retryVal);
3824
+ if (Number.isInteger(parsedDate)) {
3825
+ const deltaMS = parsedDate - Date.now();
3826
+ return deltaMS > 0 ? Math.ceil(deltaMS) : 0;
3827
+ }
3828
+ return 0;
3829
+ }
3830
+ async function delay(delay$1) {
3831
+ return new Promise((resolve) => setTimeout(resolve, delay$1));
3832
+ }
3833
+
3834
+ //#endregion
3835
+ //#region src/lib/url.ts
3836
+ const hasOwn = Object.prototype.hasOwnProperty;
3837
+ function pathToFunc(pathPattern, options) {
3838
+ const paramRE = /\{([a-zA-Z0-9_]+?)\}/g;
3839
+ return function buildURLPath(params = {}) {
3840
+ return pathPattern.replace(paramRE, function(_, placeholder) {
3841
+ if (!hasOwn.call(params, placeholder)) throw new Error(`Parameter '${placeholder}' is required`);
3842
+ const value = params[placeholder];
3843
+ if (typeof value !== "string" && typeof value !== "number") throw new Error(`Parameter '${placeholder}' must be a string or number`);
3844
+ return options?.charEncoding === "percent" ? encodeURIComponent(`${value}`) : `${value}`;
3845
+ });
3846
+ };
3847
+ }
3848
+
3849
+ //#endregion
3850
+ //#region src/lib/config.ts
3851
+ /**
3852
+ * Contains the list of servers available to the SDK
3853
+ */
3854
+ const ServerList = ["http://localhost:3002"];
3855
+ function serverURLFromOptions(options) {
3856
+ let serverURL = options.serverURL;
3857
+ const params = {};
3858
+ if (!serverURL) {
3859
+ const serverIdx = options.serverIdx ?? 0;
3860
+ if (serverIdx < 0 || serverIdx >= ServerList.length) throw new Error(`Invalid server index ${serverIdx}`);
3861
+ serverURL = ServerList[serverIdx] || "";
3862
+ }
3863
+ const u = pathToFunc(serverURL)(params);
3864
+ return new URL(u);
3865
+ }
3866
+ const SDK_METADATA = {
3867
+ language: "typescript",
3868
+ openapiDocVersion: "1.0.0",
3869
+ sdkVersion: "0.0.6",
3870
+ genVersion: "2.788.5",
3871
+ userAgent: "speakeasy-sdk/mcp-typescript 0.0.6 2.788.5 1.0.0 @inkeep/agents-manage-mcp"
3872
+ };
3873
+
3874
+ //#endregion
3875
+ //#region src/lib/dlv.ts
3876
+ /**
3877
+ * @param obj The object to walk
3878
+ * @param key The key path to walk the object with
3879
+ * @param def A default value to return if the result is undefined
3880
+ *
3881
+ * @example
3882
+ * dlv(obj, "a.b.c.d")
3883
+ * @example
3884
+ * dlv(object, ["a", "b", "c", "d"])
3885
+ * @example
3886
+ * dlv(object, "foo.bar.baz", "Hello, default value!")
3887
+ */
3888
+ function dlv(obj, key, def, p, undef) {
3889
+ key = Array.isArray(key) ? key : key.split(".");
3890
+ for (p = 0; p < key.length; p++) {
3891
+ const k = key[p];
3892
+ obj = k != null && obj ? obj[k] : undef;
3893
+ }
3894
+ return obj === undef ? def : obj;
3895
+ }
3896
+
3897
+ //#endregion
3898
+ //#region src/lib/env.ts
3899
+ const envSchema = objectType({
3900
+ INKEEPAGENTSMANAGE_COOKIE_AUTH: stringType().optional(),
3901
+ INKEEPAGENTSMANAGE_BEARER_AUTH: stringType().optional(),
3902
+ INKEEPAGENTSMANAGE_DEBUG: coerce.boolean().optional()
3903
+ });
3904
+ let envMemo = void 0;
3905
+ /**
3906
+ * Reads and validates environment variables.
3907
+ */
3908
+ function env() {
3909
+ if (envMemo) return envMemo;
3910
+ envMemo = envSchema.parse(dlv(globalThis, "process.env") ?? dlv(globalThis, "Deno.env") ?? {});
3911
+ return envMemo;
3912
+ }
3913
+
3914
+ //#endregion
3915
+ //#region src/lib/security.ts
3916
+ let SecurityErrorCode = /* @__PURE__ */ function(SecurityErrorCode$1) {
3917
+ SecurityErrorCode$1["Incomplete"] = "incomplete";
3918
+ SecurityErrorCode$1["UnrecognisedSecurityType"] = "unrecognized_security_type";
3919
+ return SecurityErrorCode$1;
3920
+ }({});
3921
+ var SecurityError = class SecurityError extends Error {
3922
+ constructor(code, message) {
3923
+ super(message);
3924
+ this.code = code;
3925
+ this.name = "SecurityError";
3926
+ }
3927
+ static incomplete() {
3928
+ return new SecurityError(SecurityErrorCode.Incomplete, "Security requirements not met in order to perform the operation");
3929
+ }
3930
+ static unrecognizedType(type) {
3931
+ return new SecurityError(SecurityErrorCode.UnrecognisedSecurityType, `Unrecognised security type: ${type}`);
3932
+ }
3933
+ };
3934
+ function resolveSecurity(...options) {
3935
+ const state = {
3936
+ basic: {},
3937
+ headers: {},
3938
+ queryParams: {},
3939
+ cookies: {},
3940
+ oauth2: { type: "none" }
3941
+ };
3942
+ const option = options.find((opts) => {
3943
+ return opts.every((o) => {
3944
+ if (o.value == null) return false;
3945
+ else if (o.type === "http:basic") return o.value.username != null || o.value.password != null;
3946
+ else if (o.type === "http:custom") return null;
3947
+ else if (o.type === "oauth2:password") return typeof o.value === "string" && !!o.value;
3948
+ else if (o.type === "oauth2:client_credentials") {
3949
+ if (typeof o.value == "string") return !!o.value;
3950
+ return o.value.clientID != null || o.value.clientSecret != null;
3951
+ } else if (typeof o.value === "string") return !!o.value;
3952
+ else throw new Error(`Unrecognized security type: ${o.type} (value type: ${typeof o.value})`);
3953
+ });
3954
+ });
3955
+ if (option == null) return null;
3956
+ option.forEach((spec) => {
3957
+ if (spec.value == null) return;
3958
+ const { type } = spec;
3959
+ switch (type) {
3960
+ case "apiKey:header":
3961
+ state.headers[spec.fieldName] = spec.value;
3962
+ break;
3963
+ case "apiKey:query":
3964
+ state.queryParams[spec.fieldName] = spec.value;
3965
+ break;
3966
+ case "apiKey:cookie":
3967
+ state.cookies[spec.fieldName] = spec.value;
3968
+ break;
3969
+ case "http:basic":
3970
+ applyBasic(state, spec);
3971
+ break;
3972
+ case "http:custom": break;
3973
+ case "http:bearer":
3974
+ applyBearer(state, spec);
3975
+ break;
3976
+ case "oauth2":
3977
+ applyBearer(state, spec);
3978
+ break;
3979
+ case "oauth2:password":
3980
+ applyBearer(state, spec);
3981
+ break;
3982
+ case "oauth2:client_credentials": break;
3983
+ case "openIdConnect":
3984
+ applyBearer(state, spec);
3985
+ break;
3986
+ default: throw SecurityError.unrecognizedType(type);
3987
+ }
3988
+ });
3989
+ return state;
3990
+ }
3991
+ function applyBasic(state, spec) {
3992
+ if (spec.value == null) return;
3993
+ state.basic = spec.value;
3994
+ }
3995
+ function applyBearer(state, spec) {
3996
+ if (typeof spec.value !== "string" || !spec.value) return;
3997
+ let value = spec.value;
3998
+ if (value.slice(0, 7).toLowerCase() !== "bearer ") value = `Bearer ${value}`;
3999
+ if (spec.fieldName !== void 0) state.headers[spec.fieldName] = value;
4000
+ }
4001
+ function resolveGlobalSecurity(security) {
4002
+ return resolveSecurity([{
4003
+ fieldName: "better-auth.session_token",
4004
+ type: "apiKey:cookie",
4005
+ value: security?.cookieAuth ?? env().INKEEPAGENTSMANAGE_COOKIE_AUTH
4006
+ }, {
4007
+ fieldName: "Authorization",
4008
+ type: "http:bearer",
4009
+ value: security?.bearerAuth ?? env().INKEEPAGENTSMANAGE_BEARER_AUTH
4010
+ }]);
4011
+ }
4012
+ async function extractSecurity(sec) {
4013
+ if (sec == null) return;
4014
+ return typeof sec === "function" ? sec() : sec;
4015
+ }
4016
+
3601
4017
  //#endregion
3602
4018
  //#region src/hooks/registration.ts
3603
4019
  function initHooks(hooks) {}
@@ -3734,46 +4150,6 @@ function stringToBase64(str) {
3734
4150
  const zodOutbound = custom((x) => x instanceof Uint8Array).or(stringType().transform(stringToBytes));
3735
4151
  const zodInbound = custom((x) => x instanceof Uint8Array).or(stringType().transform(bytesFromBase64));
3736
4152
 
3737
- //#endregion
3738
- //#region src/lib/url.ts
3739
- const hasOwn = Object.prototype.hasOwnProperty;
3740
- function pathToFunc(pathPattern, options) {
3741
- const paramRE = /\{([a-zA-Z0-9_]+?)\}/g;
3742
- return function buildURLPath(params = {}) {
3743
- return pathPattern.replace(paramRE, function(_, placeholder) {
3744
- if (!hasOwn.call(params, placeholder)) throw new Error(`Parameter '${placeholder}' is required`);
3745
- const value = params[placeholder];
3746
- if (typeof value !== "string" && typeof value !== "number") throw new Error(`Parameter '${placeholder}' must be a string or number`);
3747
- return options?.charEncoding === "percent" ? encodeURIComponent(`${value}`) : `${value}`;
3748
- });
3749
- };
3750
- }
3751
-
3752
- //#endregion
3753
- //#region src/lib/config.ts
3754
- /**
3755
- * Contains the list of servers available to the SDK
3756
- */
3757
- const ServerList = ["http://localhost:3002"];
3758
- function serverURLFromOptions(options) {
3759
- let serverURL = options.serverURL;
3760
- const params = {};
3761
- if (!serverURL) {
3762
- const serverIdx = options.serverIdx ?? 0;
3763
- if (serverIdx < 0 || serverIdx >= ServerList.length) throw new Error(`Invalid server index ${serverIdx}`);
3764
- serverURL = ServerList[serverIdx] || "";
3765
- }
3766
- const u = pathToFunc(serverURL)(params);
3767
- return new URL(u);
3768
- }
3769
- const SDK_METADATA = {
3770
- language: "typescript",
3771
- openapiDocVersion: "1.0.0",
3772
- sdkVersion: "0.0.6",
3773
- genVersion: "2.788.5",
3774
- userAgent: "speakeasy-sdk/mcp-typescript 0.0.6 2.788.5 1.0.0 @inkeep/agents-manage-mcp"
3775
- };
3776
-
3777
4153
  //#endregion
3778
4154
  //#region src/lib/is-plain-object.ts
3779
4155
  function isPlainObject(value) {
@@ -3907,199 +4283,37 @@ function mapDefined(inp, mapper) {
3907
4283
  }, []);
3908
4284
  return res.length ? res : null;
3909
4285
  }
3910
- function mapDefinedEntries(inp, mapper) {
3911
- const acc = [];
3912
- for (const [k, v] of inp) {
3913
- if (v == null) continue;
3914
- const m = mapper([k, v]);
3915
- if (m == null) continue;
3916
- acc.push(m);
3917
- }
3918
- return acc.length ? acc : null;
3919
- }
3920
- function queryJoin(...args$113) {
3921
- return args$113.filter(Boolean).join("&");
3922
- }
3923
- function queryEncoder(f) {
3924
- const bulkEncode = function(values, options) {
3925
- const opts = {
3926
- ...options,
3927
- explode: options?.explode ?? true,
3928
- charEncoding: options?.charEncoding ?? "percent"
3929
- };
3930
- return queryJoin(...Object.entries(values).map(([key, value]) => {
3931
- return f(key, value, opts);
3932
- }));
3933
- };
3934
- return bulkEncode;
3935
- }
3936
- const encodeJSONQuery = queryEncoder(encodeJSON);
3937
- const encodeFormQuery = queryEncoder(encodeForm);
3938
- const encodeSpaceDelimitedQuery = queryEncoder(encodeSpaceDelimited);
3939
- const encodePipeDelimitedQuery = queryEncoder(encodePipeDelimited);
3940
- const encodeDeepObjectQuery = queryEncoder(encodeDeepObject);
3941
-
3942
- //#endregion
3943
- //#region src/lib/dlv.ts
3944
- /**
3945
- * @param obj The object to walk
3946
- * @param key The key path to walk the object with
3947
- * @param def A default value to return if the result is undefined
3948
- *
3949
- * @example
3950
- * dlv(obj, "a.b.c.d")
3951
- * @example
3952
- * dlv(object, ["a", "b", "c", "d"])
3953
- * @example
3954
- * dlv(object, "foo.bar.baz", "Hello, default value!")
3955
- */
3956
- function dlv(obj, key, def, p, undef) {
3957
- key = Array.isArray(key) ? key : key.split(".");
3958
- for (p = 0; p < key.length; p++) {
3959
- const k = key[p];
3960
- obj = k != null && obj ? obj[k] : undef;
3961
- }
3962
- return obj === undef ? def : obj;
3963
- }
3964
-
3965
- //#endregion
3966
- //#region src/lib/env.ts
3967
- const envSchema = objectType({
3968
- INKEEPAGENTSMANAGE_COOKIE_AUTH: stringType().optional(),
3969
- INKEEPAGENTSMANAGE_BEARER_AUTH: stringType().optional(),
3970
- INKEEPAGENTSMANAGE_DEBUG: coerce.boolean().optional()
3971
- });
3972
- let envMemo = void 0;
3973
- /**
3974
- * Reads and validates environment variables.
3975
- */
3976
- function env() {
3977
- if (envMemo) return envMemo;
3978
- envMemo = envSchema.parse(dlv(globalThis, "process.env") ?? dlv(globalThis, "Deno.env") ?? {});
3979
- return envMemo;
3980
- }
3981
-
3982
- //#endregion
3983
- //#region src/lib/http.ts
3984
- const DEFAULT_FETCHER = (input, init) => {
3985
- if (init == null) return fetch(input);
3986
- else return fetch(input, init);
3987
- };
3988
- var HTTPClient = class HTTPClient {
3989
- fetcher;
3990
- requestHooks = [];
3991
- requestErrorHooks = [];
3992
- responseHooks = [];
3993
- constructor(options = {}) {
3994
- this.options = options;
3995
- this.fetcher = options.fetcher || DEFAULT_FETCHER;
3996
- }
3997
- async request(request) {
3998
- let req = request;
3999
- for (const hook of this.requestHooks) {
4000
- const nextRequest = await hook(req);
4001
- if (nextRequest) req = nextRequest;
4002
- }
4003
- try {
4004
- const res = await this.fetcher(req);
4005
- for (const hook of this.responseHooks) await hook(res, req);
4006
- return res;
4007
- } catch (err) {
4008
- for (const hook of this.requestErrorHooks) await hook(err, req);
4009
- throw err;
4010
- }
4011
- }
4012
- addHook(...args$113) {
4013
- if (args$113[0] === "beforeRequest") this.requestHooks.push(args$113[1]);
4014
- else if (args$113[0] === "requestError") this.requestErrorHooks.push(args$113[1]);
4015
- else if (args$113[0] === "response") this.responseHooks.push(args$113[1]);
4016
- else throw new Error(`Invalid hook type: ${args$113[0]}`);
4017
- return this;
4018
- }
4019
- removeHook(...args$113) {
4020
- let target;
4021
- if (args$113[0] === "beforeRequest") target = this.requestHooks;
4022
- else if (args$113[0] === "requestError") target = this.requestErrorHooks;
4023
- else if (args$113[0] === "response") target = this.responseHooks;
4024
- else throw new Error(`Invalid hook type: ${args$113[0]}`);
4025
- const index = target.findIndex((v) => v === args$113[1]);
4026
- if (index >= 0) target.splice(index, 1);
4027
- return this;
4028
- }
4029
- clone() {
4030
- const child = new HTTPClient(this.options);
4031
- child.requestHooks = this.requestHooks.slice();
4032
- child.requestErrorHooks = this.requestErrorHooks.slice();
4033
- child.responseHooks = this.responseHooks.slice();
4034
- return child;
4035
- }
4036
- };
4037
- const mediaParamSeparator = /\s*;\s*/g;
4038
- function matchContentType(response, pattern) {
4039
- if (pattern === "*") return true;
4040
- let contentType = response.headers.get("content-type")?.trim() || "application/octet-stream";
4041
- contentType = contentType.toLowerCase();
4042
- const [wantType = "", ...wantParams] = pattern.toLowerCase().trim().split(mediaParamSeparator);
4043
- if (wantType.split("/").length !== 2) return false;
4044
- const [gotType = "", ...gotParams] = contentType.split(mediaParamSeparator);
4045
- const [type = "", subtype = ""] = gotType.split("/");
4046
- if (!type || !subtype) return false;
4047
- if (wantType !== "*/*" && gotType !== wantType && `${type}/*` !== wantType && `*/${subtype}` !== wantType) return false;
4048
- if (gotParams.length < wantParams.length) return false;
4049
- const params = new Set(gotParams);
4050
- for (const wantParam of wantParams) if (!params.has(wantParam)) return false;
4051
- return true;
4052
- }
4053
- const codeRangeRE$1 = new RegExp("^[0-9]xx$", "i");
4054
- function matchStatusCode(response, codes) {
4055
- const actual = `${response.status}`;
4056
- const expectedCodes = Array.isArray(codes) ? codes : [codes];
4057
- if (!expectedCodes.length) return false;
4058
- return expectedCodes.some((ec) => {
4059
- const code = `${ec}`;
4060
- if (code === "default") return true;
4061
- if (!codeRangeRE$1.test(`${code}`)) return code === actual;
4062
- const expectFamily = code.charAt(0);
4063
- if (!expectFamily) throw new Error("Invalid status code range");
4064
- const actualFamily = actual.charAt(0);
4065
- if (!actualFamily) throw new Error(`Invalid response status code: ${actual}`);
4066
- return actualFamily === expectFamily;
4067
- });
4068
- }
4069
- function matchResponse(response, code, contentTypePattern) {
4070
- return matchStatusCode(response, code) && matchContentType(response, contentTypePattern);
4071
- }
4072
- /**
4073
- * Uses various heurisitics to determine if an error is a connection error.
4074
- */
4075
- function isConnectionError(err) {
4076
- if (typeof err !== "object" || err == null) return false;
4077
- const isBrowserErr = err instanceof TypeError && err.message.toLowerCase().startsWith("failed to fetch");
4078
- const isNodeErr = err instanceof TypeError && err.message.toLowerCase().startsWith("fetch failed");
4079
- const isBunErr = "name" in err && err.name === "ConnectionError";
4080
- const isGenericErr = "code" in err && typeof err.code === "string" && err.code.toLowerCase() === "econnreset";
4081
- return isBrowserErr || isNodeErr || isGenericErr || isBunErr;
4286
+ function mapDefinedEntries(inp, mapper) {
4287
+ const acc = [];
4288
+ for (const [k, v] of inp) {
4289
+ if (v == null) continue;
4290
+ const m = mapper([k, v]);
4291
+ if (m == null) continue;
4292
+ acc.push(m);
4293
+ }
4294
+ return acc.length ? acc : null;
4082
4295
  }
4083
- /**
4084
- * Uses various heurisitics to determine if an error is a timeout error.
4085
- */
4086
- function isTimeoutError(err) {
4087
- if (typeof err !== "object" || err == null) return false;
4088
- const isNative = "name" in err && err.name === "TimeoutError";
4089
- const isLegacyNative = "code" in err && err.code === 23;
4090
- const isGenericErr = "code" in err && typeof err.code === "string" && err.code.toLowerCase() === "econnaborted";
4091
- return isNative || isLegacyNative || isGenericErr;
4296
+ function queryJoin(...args$113) {
4297
+ return args$113.filter(Boolean).join("&");
4092
4298
  }
4093
- /**
4094
- * Uses various heurisitics to determine if an error is a abort error.
4095
- */
4096
- function isAbortError(err) {
4097
- if (typeof err !== "object" || err == null) return false;
4098
- const isNative = "name" in err && err.name === "AbortError";
4099
- const isLegacyNative = "code" in err && err.code === 20;
4100
- const isGenericErr = "code" in err && typeof err.code === "string" && err.code.toLowerCase() === "econnaborted";
4101
- return isNative || isLegacyNative || isGenericErr;
4299
+ function queryEncoder(f) {
4300
+ const bulkEncode = function(values, options) {
4301
+ const opts = {
4302
+ ...options,
4303
+ explode: options?.explode ?? true,
4304
+ charEncoding: options?.charEncoding ?? "percent"
4305
+ };
4306
+ return queryJoin(...Object.entries(values).map(([key, value]) => {
4307
+ return f(key, value, opts);
4308
+ }));
4309
+ };
4310
+ return bulkEncode;
4102
4311
  }
4312
+ const encodeJSONQuery = queryEncoder(encodeJSON);
4313
+ const encodeFormQuery = queryEncoder(encodeForm);
4314
+ const encodeSpaceDelimitedQuery = queryEncoder(encodeSpaceDelimited);
4315
+ const encodePipeDelimitedQuery = queryEncoder(encodePipeDelimited);
4316
+ const encodeDeepObjectQuery = queryEncoder(encodeDeepObject);
4103
4317
 
4104
4318
  //#endregion
4105
4319
  //#region src/lib/result.ts
@@ -4116,113 +4330,6 @@ function ERR$1(error) {
4116
4330
  };
4117
4331
  }
4118
4332
 
4119
- //#endregion
4120
- //#region src/lib/retries.ts
4121
- const defaultBackoff = {
4122
- initialInterval: 500,
4123
- maxInterval: 6e4,
4124
- exponent: 1.5,
4125
- maxElapsedTime: 36e5
4126
- };
4127
- /**
4128
- * PermanentError is an error that is not recoverable. Throwing this error will
4129
- * cause a retry loop to terminate.
4130
- */
4131
- var PermanentError = class PermanentError extends Error {
4132
- /** The underlying cause of the error. */
4133
- cause;
4134
- constructor(message, options) {
4135
- let msg = message;
4136
- if (options?.cause) msg += `: ${options.cause}`;
4137
- super(msg, options);
4138
- this.name = "PermanentError";
4139
- if (typeof this.cause === "undefined") this.cause = options?.cause;
4140
- Object.setPrototypeOf(this, PermanentError.prototype);
4141
- }
4142
- };
4143
- /**
4144
- * TemporaryError is an error is used to signal that an HTTP request can be
4145
- * retried as part of a retry loop. If retry attempts are exhausted and this
4146
- * error is thrown, the response will be returned to the caller.
4147
- */
4148
- var TemporaryError = class TemporaryError extends Error {
4149
- response;
4150
- constructor(message, response) {
4151
- super(message);
4152
- this.response = response;
4153
- this.name = "TemporaryError";
4154
- Object.setPrototypeOf(this, TemporaryError.prototype);
4155
- }
4156
- };
4157
- async function retry(fetchFn, options) {
4158
- switch (options.config.strategy) {
4159
- case "backoff": return retryBackoff(wrapFetcher(fetchFn, {
4160
- statusCodes: options.statusCodes,
4161
- retryConnectionErrors: !!options.config.retryConnectionErrors
4162
- }), options.config.backoff ?? defaultBackoff);
4163
- default: return await fetchFn();
4164
- }
4165
- }
4166
- function wrapFetcher(fn, options) {
4167
- return async () => {
4168
- try {
4169
- const res = await fn();
4170
- if (isRetryableResponse(res, options.statusCodes)) throw new TemporaryError("Response failed with retryable status code", res);
4171
- return res;
4172
- } catch (err) {
4173
- if (err instanceof TemporaryError) throw err;
4174
- if (options.retryConnectionErrors && (isTimeoutError(err) || isConnectionError(err))) throw err;
4175
- throw new PermanentError("Permanent error", { cause: err });
4176
- }
4177
- };
4178
- }
4179
- const codeRangeRE = new RegExp("^[0-9]xx$", "i");
4180
- function isRetryableResponse(res, statusCodes) {
4181
- const actual = `${res.status}`;
4182
- return statusCodes.some((code) => {
4183
- if (!codeRangeRE.test(code)) return code === actual;
4184
- const expectFamily = code.charAt(0);
4185
- if (!expectFamily) throw new Error("Invalid status code range");
4186
- const actualFamily = actual.charAt(0);
4187
- if (!actualFamily) throw new Error(`Invalid response status code: ${actual}`);
4188
- return actualFamily === expectFamily;
4189
- });
4190
- }
4191
- async function retryBackoff(fn, strategy) {
4192
- const { maxElapsedTime, initialInterval, exponent, maxInterval } = strategy;
4193
- const start = Date.now();
4194
- let x = 0;
4195
- while (true) try {
4196
- return await fn();
4197
- } catch (err) {
4198
- if (err instanceof PermanentError) throw err.cause;
4199
- if (Date.now() - start > maxElapsedTime) {
4200
- if (err instanceof TemporaryError) return err.response;
4201
- throw err;
4202
- }
4203
- let retryInterval = 0;
4204
- if (err instanceof TemporaryError) retryInterval = retryIntervalFromResponse(err.response);
4205
- if (retryInterval <= 0) retryInterval = initialInterval * Math.pow(x, exponent) + Math.random() * 1e3;
4206
- await delay(Math.min(retryInterval, maxInterval));
4207
- x++;
4208
- }
4209
- }
4210
- function retryIntervalFromResponse(res) {
4211
- const retryVal = res.headers.get("retry-after") || "";
4212
- if (!retryVal) return 0;
4213
- const parsedNumber = Number(retryVal);
4214
- if (Number.isInteger(parsedNumber)) return parsedNumber * 1e3;
4215
- const parsedDate = Date.parse(retryVal);
4216
- if (Number.isInteger(parsedDate)) {
4217
- const deltaMS = parsedDate - Date.now();
4218
- return deltaMS > 0 ? Math.ceil(deltaMS) : 0;
4219
- }
4220
- return 0;
4221
- }
4222
- async function delay(delay$1) {
4223
- return new Promise((resolve) => setTimeout(resolve, delay$1));
4224
- }
4225
-
4226
4333
  //#endregion
4227
4334
  //#region src/lib/sdks.ts
4228
4335
  const gt = typeof globalThis === "undefined" ? null : globalThis;
@@ -4794,109 +4901,6 @@ function compactMap(values) {
4794
4901
  return out;
4795
4902
  }
4796
4903
 
4797
- //#endregion
4798
- //#region src/lib/security.ts
4799
- let SecurityErrorCode = /* @__PURE__ */ function(SecurityErrorCode$1) {
4800
- SecurityErrorCode$1["Incomplete"] = "incomplete";
4801
- SecurityErrorCode$1["UnrecognisedSecurityType"] = "unrecognized_security_type";
4802
- return SecurityErrorCode$1;
4803
- }({});
4804
- var SecurityError = class SecurityError extends Error {
4805
- constructor(code, message) {
4806
- super(message);
4807
- this.code = code;
4808
- this.name = "SecurityError";
4809
- }
4810
- static incomplete() {
4811
- return new SecurityError(SecurityErrorCode.Incomplete, "Security requirements not met in order to perform the operation");
4812
- }
4813
- static unrecognizedType(type) {
4814
- return new SecurityError(SecurityErrorCode.UnrecognisedSecurityType, `Unrecognised security type: ${type}`);
4815
- }
4816
- };
4817
- function resolveSecurity(...options) {
4818
- const state = {
4819
- basic: {},
4820
- headers: {},
4821
- queryParams: {},
4822
- cookies: {},
4823
- oauth2: { type: "none" }
4824
- };
4825
- const option = options.find((opts) => {
4826
- return opts.every((o) => {
4827
- if (o.value == null) return false;
4828
- else if (o.type === "http:basic") return o.value.username != null || o.value.password != null;
4829
- else if (o.type === "http:custom") return null;
4830
- else if (o.type === "oauth2:password") return typeof o.value === "string" && !!o.value;
4831
- else if (o.type === "oauth2:client_credentials") {
4832
- if (typeof o.value == "string") return !!o.value;
4833
- return o.value.clientID != null || o.value.clientSecret != null;
4834
- } else if (typeof o.value === "string") return !!o.value;
4835
- else throw new Error(`Unrecognized security type: ${o.type} (value type: ${typeof o.value})`);
4836
- });
4837
- });
4838
- if (option == null) return null;
4839
- option.forEach((spec) => {
4840
- if (spec.value == null) return;
4841
- const { type } = spec;
4842
- switch (type) {
4843
- case "apiKey:header":
4844
- state.headers[spec.fieldName] = spec.value;
4845
- break;
4846
- case "apiKey:query":
4847
- state.queryParams[spec.fieldName] = spec.value;
4848
- break;
4849
- case "apiKey:cookie":
4850
- state.cookies[spec.fieldName] = spec.value;
4851
- break;
4852
- case "http:basic":
4853
- applyBasic(state, spec);
4854
- break;
4855
- case "http:custom": break;
4856
- case "http:bearer":
4857
- applyBearer(state, spec);
4858
- break;
4859
- case "oauth2":
4860
- applyBearer(state, spec);
4861
- break;
4862
- case "oauth2:password":
4863
- applyBearer(state, spec);
4864
- break;
4865
- case "oauth2:client_credentials": break;
4866
- case "openIdConnect":
4867
- applyBearer(state, spec);
4868
- break;
4869
- default: throw SecurityError.unrecognizedType(type);
4870
- }
4871
- });
4872
- return state;
4873
- }
4874
- function applyBasic(state, spec) {
4875
- if (spec.value == null) return;
4876
- state.basic = spec.value;
4877
- }
4878
- function applyBearer(state, spec) {
4879
- if (typeof spec.value !== "string" || !spec.value) return;
4880
- let value = spec.value;
4881
- if (value.slice(0, 7).toLowerCase() !== "bearer ") value = `Bearer ${value}`;
4882
- if (spec.fieldName !== void 0) state.headers[spec.fieldName] = value;
4883
- }
4884
- function resolveGlobalSecurity(security) {
4885
- return resolveSecurity([{
4886
- fieldName: "better-auth.session_token",
4887
- type: "apiKey:cookie",
4888
- value: security?.cookieAuth ?? env().INKEEPAGENTSMANAGE_COOKIE_AUTH
4889
- }, {
4890
- fieldName: "Authorization",
4891
- type: "http:bearer",
4892
- value: security?.bearerAuth ?? env().INKEEPAGENTSMANAGE_BEARER_AUTH
4893
- }]);
4894
- }
4895
- async function extractSecurity(sec) {
4896
- if (sec == null) return;
4897
- return typeof sec === "function" ? sec() : sec;
4898
- }
4899
-
4900
4904
  //#endregion
4901
4905
  //#region src/models/badrequest.ts
4902
4906
  const BadRequestCode1$zodSchema = enumType(["bad_request"]).describe("A short code indicating the error code returned.");