UNPKG

@kya-os/mcp-i

Version:

The TypeScript MCP framework with identity features built-in

1 lines 15.7 kB
"use strict";exports.id=478,exports.ids=[478],exports.modules={22371:(e,t,r)=>{r.d(t,{k:()=>x});var s=r(96440),i=r(71407);const a="(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)(?:[ne|u?r]?s?day)?",n="(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)",o="(\\d?\\d):(\\d{2}):(\\d{2})(?:\\.(\\d+))?",c="(\\d?\\d)",d="(\\d{4})",l=new RegExp(/^(\d{4})-(\d\d)-(\d\d)[tT](\d\d):(\d\d):(\d\d)(\.(\d+))?(([-+]\d\d:\d\d)|[zZ])$/),u=new RegExp(`^${a}, ${c} ${n} ${d} ${o} GMT$`),h=new RegExp(`^${a}, ${c}-${n}-(\\d\\d) ${o} GMT$`),f=new RegExp(`^${a} ${n} ( [1-9]|\\d\\d) ${o} ${d}$`),p=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function m(e,t,r){const s=Number(e);if(s<t||s>r)throw new Error(`Value ${s} out of range [${t}, ${r}]`)}var g=r(74910),w=r(52123),b=r(12544),y=r(2914),S=r(79037),T=r(17735);class x extends S.f{settings;constructor(e){super(),this.settings=e}read(e,t){const r=s.l.of(e);if(r.isListSchema())return(0,i.G)(t).map(e=>this.read(r.getValueSchema(),e));if(r.isBlobSchema())return(this.serdeContext?.base64Decoder??b.E)(t);if(r.isTimestampSchema())switch((0,T.V)(r,this.settings)){case 5:return(e=>{if(null==e)return;if("string"!=typeof e)throw new TypeError("RFC3339 timestamps must be strings");const t=l.exec(e);if(!t)throw new TypeError(`Invalid RFC3339 timestamp format ${e}`);const[,r,s,i,a,n,o,,c,d]=t;m(s,1,12),m(i,1,31),m(a,0,23),m(n,0,59),m(o,0,60);const u=new Date(Date.UTC(Number(r),Number(s)-1,Number(i),Number(a),Number(n),Number(o),Number(c)?Math.round(1e3*parseFloat(`0.${c}`)):0));if(u.setUTCFullYear(Number(r)),"Z"!=d.toUpperCase()){const[,e,t,r]=/([+-])(\d\d):(\d\d)/.exec(d)||[void 0,"+",0,0],s="-"===e?1:-1;u.setTime(u.getTime()+s*(60*Number(t)*60*1e3+60*Number(r)*1e3))}return u})(t);case 6:return(e=>{if(null==e)return;if("string"!=typeof e)throw new TypeError("RFC7231 timestamps must be strings.");let t,r,s,i,a,n,o,c;if((c=u.exec(e))?[,t,r,s,i,a,n,o]=c:(c=h.exec(e))?([,t,r,s,i,a,n,o]=c,s=(Number(s)+1900).toString()):(c=f.exec(e))&&([,r,t,i,a,n,o,s]=c),s&&n){const e=Date.UTC(Number(s),p.indexOf(r),Number(t),Number(i),Number(a),Number(n),o?Math.round(1e3*parseFloat(`0.${o}`)):0);m(t,1,31),m(i,0,23),m(a,0,59),m(n,0,60);const c=new Date(e);return c.setUTCFullYear(Number(s)),c}throw new TypeError(`Invalid RFC7231 date-time value ${e}.`)})(t);case 7:return(e=>{if(null==e)return;let t=NaN;if("number"==typeof e)t=e;else if("string"==typeof e){if(!/^-?\d*\.?\d+$/.test(e))throw new TypeError("parseEpochTimestamp - numeric string invalid.");t=Number.parseFloat(e)}else"object"==typeof e&&1===e.tag&&(t=e.value);if(isNaN(t)||Math.abs(t)===1/0)throw new TypeError("Epoch timestamps must be valid finite numbers.");return new Date(Math.round(1e3*t))})(t);default:return console.warn("Missing timestamp format, parsing value with Date constructor:",t),new Date(t)}if(r.isStringSchema()){const e=r.getMergedTraits().mediaType;let s=t;if(e)return r.getMergedTraits().httpHeader&&(s=this.base64ToUtf8(s)),("application/json"===e||e.endsWith("+json"))&&(s=g.A.from(s)),s}return r.isNumericSchema()?Number(t):r.isBigIntegerSchema()?BigInt(t):r.isBigDecimalSchema()?new w.D(t,"bigDecimal"):r.isBooleanSchema()?"true"===String(t).toLowerCase():t}base64ToUtf8(e){return(this.serdeContext?.utf8Encoder??y.P)((this.serdeContext?.base64Decoder??b.E)(e))}}},27590:(e,t,r)=>{r.d(t,{m:()=>s});class s{async sign(e,t,r){return e}}},56826:(e,t,r)=>{r.d(t,{c:()=>m});var s=r(66391),i=r(25272),a=r(2203),n=r(12544);var o=r(39181),c=r(92278),d=r(2914);const l=e=>"function"==typeof ReadableStream&&(e?.constructor?.name===ReadableStream.name||e instanceof ReadableStream),u="The stream has already been transformed.",h=e=>{if(!f(e)&&!l(e))throw new Error(`Unexpected stream implementation, expect Blob or ReadableStream, got ${e?.__proto__?.constructor?.name||e}`);let t=!1;const r=async()=>{if(t)throw new Error(u);return t=!0,await(async e=>"function"==typeof Blob&&e instanceof Blob||"Blob"===e.constructor?.name?void 0!==Blob.prototype.arrayBuffer?new Uint8Array(await e.arrayBuffer()):async function(e){const t=await function(e){return new Promise((t,r)=>{const s=new FileReader;s.onloadend=()=>{if(2!==s.readyState)return r(new Error("Reader aborted too early"));const e=s.result??"",i=e.indexOf(","),a=i>-1?i+1:e.length;t(e.substring(a))},s.onabort=()=>r(new Error("Read aborted")),s.onerror=()=>r(s.error),s.readAsDataURL(e)})}(e),r=(0,n.E)(t);return new Uint8Array(r)}(e):async function(e){const t=[],r=e.getReader();let s=!1,i=0;for(;!s;){const{done:e,value:a}=await r.read();a&&(t.push(a),i+=a.length),s=e}const a=new Uint8Array(i);let n=0;for(const e of t)a.set(e,n),n+=e.length;return a}(e))(e)};return Object.assign(e,{transformToByteArray:r,transformToString:async e=>{const t=await r();if("base64"===e)return(0,o.n)(t);if("hex"===e)return(0,c.n)(t);if(void 0===e||"utf8"===e||"utf-8"===e)return(0,d.P)(t);if("function"==typeof TextDecoder)return new TextDecoder(e).decode(t);throw new Error("TextDecoder is not available, please make sure polyfill is provided.")},transformToWebStream:()=>{if(t)throw new Error(u);if(t=!0,f(e))return(e=>{if("function"!=typeof e.stream)throw new Error("Cannot transform payload Blob to web stream. Please make sure the Blob.stream() is polyfilled.\nIf you are using React Native, this API is not yet supported, see: https://react-native.canny.io/feature-requests/p/fetch-streaming-body");return e.stream()})(e);if(l(e))return e;throw new Error(`Cannot transform payload to web stream, got ${e}`)}})},f=e=>"function"==typeof Blob&&e instanceof Blob,p="The stream has already been transformed.",m=e=>{if(!(e instanceof a.Readable))try{return h(e)}catch(t){throw new Error(`Unexpected stream implementation, expect Stream.Readable instance, got ${e?.__proto__?.constructor?.name||e}`)}let t=!1;const r=async()=>{if(t)throw new Error(p);return t=!0,await(0,s.k)(e)};return Object.assign(e,{transformToByteArray:r,transformToString:async e=>{const t=await r();return void 0===e||Buffer.isEncoding(e)?(0,i.Q)(t.buffer,t.byteOffset,t.byteLength).toString(e):new TextDecoder(e).decode(t)},transformToWebStream:()=>{if(t)throw new Error(p);if(null!==e.readableFlowing)throw new Error("The stream has been consumed by other callbacks.");if("function"!=typeof a.Readable.toWeb)throw new Error("Readable.toWeb() is not supported. Please ensure a polyfill is available.");return t=!0,a.Readable.toWeb(e)}})}},61210:(e,t,r)=>{function s(e){return encodeURIComponent(e).replace(/[!'()*]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()})}r.d(t,{$:()=>s})},71407:(e,t,r)=>{r.d(t,{G:()=>s});const s=e=>{const t=e.length,r=[];let s,i=!1,a=0;for(let n=0;n<t;++n){const t=e[n];switch(t){case'"':"\\"!==s&&(i=!i);break;case",":i||(r.push(e.slice(a,n)),a=n+1)}s=t}return r.push(e.slice(a)),r.map(e=>{const t=(e=e.trim()).length;return t<2?e:('"'===e[0]&&'"'===e[t-1]&&(e=e.slice(1,t-1)),e.replace(/\\"/g,'"'))})}},76609:(e,t,r)=>{r.d(t,{Y:()=>D});var s=r(96440),i=r(83623);function a(e,t,r){if(r<=0||!Number.isInteger(r))throw new Error("Invalid number of delimiters ("+r+") for splitEvery.");const s=e.split(t);if(1===r)return s;const i=[];let a="";for(let e=0;e<s.length;e++)""===a?a=s[e]:a+=t+s[e],(e+1)%r===0&&(i.push(a),a="");return""!==a&&i.push(a),i}var n=r(71407),o=r(86880),c=r(56826),d=r(77337),l=r(61210),u=r(52445);class h extends u.t{async serializeRequest(e,t,r){const a={...t??{}},n=this.serializer,c={},d={},u=await r.endpoint(),h=s.l.of(e?.input),f=h.getSchema();let p,m=!1;const g=new o.K({protocol:"",hostname:"",port:void 0,path:"",fragment:void 0,query:c,headers:d,body:void 0});if(u){this.updateServiceEndpoint(g,u),this.setHostPrefix(g,e,a);const t=(0,i.c)(e.traits);if(t.http){g.method=t.http[0];const[e,r]=t.http[1].split("?");"/"==g.path?g.path=e:g.path+=e;const s=new URLSearchParams(r??"");Object.assign(c,Object.fromEntries(s))}}for(const[e,t]of h.structIterator()){const r=t.getMergedTraits()??{},s=a[e];if(null!=s||t.isIdempotencyToken())if(r.httpPayload)t.isStreaming()?t.isStructSchema()?a[e]&&(p=await this.serializeEventStream({eventStream:a[e],requestSchema:h})):p=s:(n.write(t,s),p=n.flush()),delete a[e];else if(r.httpLabel){n.write(t,s);const r=n.flush();g.path.includes(`{${e}+}`)?g.path=g.path.replace(`{${e}+}`,r.split("/").map(l.$).join("/")):g.path.includes(`{${e}}`)&&(g.path=g.path.replace(`{${e}}`,(0,l.$)(r))),delete a[e]}else if(r.httpHeader)n.write(t,s),d[r.httpHeader.toLowerCase()]=String(n.flush()),delete a[e];else if("string"==typeof r.httpPrefixHeaders){for(const[e,i]of Object.entries(s)){const s=r.httpPrefixHeaders+e;n.write([t.getValueSchema(),{httpHeader:s}],i),d[s.toLowerCase()]=n.flush()}delete a[e]}else r.httpQuery||r.httpQueryParams?(this.serializeQuery(t,s,c),delete a[e]):m=!0}return m&&a&&(n.write(f,a),p=n.flush()),g.headers=d,g.query=c,g.body=p,g}serializeQuery(e,t,r){const s=this.serializer,i=e.getMergedTraits();if(i.httpQueryParams){for(const[s,a]of Object.entries(t))if(!(s in r)){const t=e.getValueSchema();Object.assign(t.getMergedTraits(),{...i,httpQuery:s,httpQueryParams:void 0}),this.serializeQuery(t,a,r)}}else if(e.isListSchema()){const a=!!e.getMergedTraits().sparse,n=[];for(const r of t){s.write([e.getValueSchema(),i],r);const t=s.flush();(a||void 0!==t)&&n.push(t)}r[i.httpQuery]=n}else s.write([e,i],t),r[i.httpQuery]=s.flush()}async deserializeResponse(e,t,r){const i=this.deserializer,a=s.l.of(e.output),n={};if(r.statusCode>=300){const s=await(0,d.P)(r.body,t);throw s.byteLength>0&&Object.assign(n,await i.read(15,s)),await this.handleError(e,t,r,n,this.deserializeMetadata(r)),new Error("@smithy/core/protocols - HTTP Protocol error handler failed to throw.")}for(const e in r.headers){const t=r.headers[e];delete r.headers[e],r.headers[e.toLowerCase()]=t}const o=await this.deserializeHttpMessage(a,t,r,n);if(o.length){const e=await(0,d.P)(r.body,t);if(e.byteLength>0){const t=await i.read(a,e);for(const e of o)n[e]=t[e]}}else o.discardResponseBody&&await(0,d.P)(r.body,t);return n.$metadata=this.deserializeMetadata(r),n}async deserializeHttpMessage(e,t,r,i,o){let l;l=i instanceof Set?o:i;let u=!0;const h=this.deserializer,f=s.l.of(e),p=[];for(const[e,s]of f.structIterator()){const i=s.getMemberTraits();if(i.httpPayload){if(u=!1,s.isStreaming()){const t=s.isStructSchema();l[e]=t?await this.deserializeEventStream({response:r,responseSchema:f}):(0,c.c)(r.body)}else if(r.body){const i=await(0,d.P)(r.body,t);i.byteLength>0&&(l[e]=await h.read(s,i))}}else if(i.httpHeader){const t=String(i.httpHeader).toLowerCase(),o=r.headers[t];if(null!=o)if(s.isListSchema()){const r=s.getValueSchema();let i;r.getMergedTraits().httpHeader=t,i=r.isTimestampSchema()&&4===r.getSchema()?a(o,",",2):(0,n.G)(o);const c=[];for(const e of i)c.push(await h.read(r,e.trim()));l[e]=c}else l[e]=await h.read(s,o)}else if(void 0!==i.httpPrefixHeaders){l[e]={};for(const[t,a]of Object.entries(r.headers))if(t.startsWith(i.httpPrefixHeaders)){const r=s.getValueSchema();r.getMergedTraits().httpHeader=t,l[e][t.slice(i.httpPrefixHeaders.length)]=await h.read(r,a)}}else i.httpResponseCode?l[e]=r.statusCode:p.push(e)}return p.discardResponseBody=u,p}}var f=r(37882);function p(e){return(e.includes(",")||e.includes('"'))&&(e=`"${e.replace(/"/g,'\\"')}"`),e}var m=r(74910),g=r(34708),w=r(39181),b=r(79037),y=r(17735);class S extends b.f{settings;stringBuffer="";constructor(e){super(),this.settings=e}write(e,t){const r=s.l.of(e);switch(typeof t){case"object":if(null===t)return void(this.stringBuffer="null");if(r.isTimestampSchema()){if(!(t instanceof Date))throw new Error(`@smithy/core/protocols - received non-Date value ${t} when schema expected Date in ${r.getName(!0)}`);switch((0,y.V)(r,this.settings)){case 5:this.stringBuffer=t.toISOString().replace(".000Z","Z");break;case 6:this.stringBuffer=(0,f.JV)(t);break;case 7:this.stringBuffer=String(t.getTime()/1e3);break;default:console.warn("Missing timestamp format, using epoch seconds",t),this.stringBuffer=String(t.getTime()/1e3)}return}if(r.isBlobSchema()&&"byteLength"in t)return void(this.stringBuffer=(this.serdeContext?.base64Encoder??w.n)(t));if(r.isListSchema()&&Array.isArray(t)){let e="";for(const s of t){this.write([r.getValueSchema(),r.getMergedTraits()],s);const t=this.flush();""!==e&&(e+=", "),e+=r.getValueSchema().isTimestampSchema()?t:p(t)}return void(this.stringBuffer=e)}this.stringBuffer=JSON.stringify(t,null,2);break;case"string":const e=r.getMergedTraits().mediaType;let s=t;if(e&&(("application/json"===e||e.endsWith("+json"))&&(s=m.A.from(s)),r.getMergedTraits().httpHeader))return void(this.stringBuffer=(this.serdeContext?.base64Encoder??w.n)(s.toString()));this.stringBuffer=t;break;default:r.isIdempotencyToken()?this.stringBuffer=(0,g.v4)():this.stringBuffer=String(t)}}flush(){const e=this.stringBuffer;return this.stringBuffer="",e}}class T{codecSerializer;stringSerializer;buffer;constructor(e,t,r=new S(t)){this.codecSerializer=e,this.stringSerializer=r}setSerdeContext(e){this.codecSerializer.setSerdeContext(e),this.stringSerializer.setSerdeContext(e)}write(e,t){const r=s.l.of(e),i=r.getMergedTraits();return i.httpHeader||i.httpLabel||i.httpQuery?(this.stringSerializer.write(r,t),void(this.buffer=this.stringSerializer.flush())):this.codecSerializer.write(r,t)}flush(){if(void 0!==this.buffer){const e=this.buffer;return this.buffer=void 0,e}return this.codecSerializer.flush()}}var x=r(2914),v=r(40935),E=r(22371);class z extends b.f{codecDeserializer;stringDeserializer;constructor(e,t){super(),this.codecDeserializer=e,this.stringDeserializer=new E.k(t)}setSerdeContext(e){this.stringDeserializer.setSerdeContext(e),this.codecDeserializer.setSerdeContext(e),this.serdeContext=e}read(e,t){const r=s.l.of(e),i=r.getMergedTraits(),a=this.serdeContext?.utf8Encoder??x.P;if(i.httpHeader||i.httpResponseCode)return this.stringDeserializer.read(r,a(t));if(i.httpPayload){if(r.isBlobSchema()){const e=this.serdeContext?.utf8Decoder??v.a;return"string"==typeof t?e(t):t}if(r.isStringSchema())return"byteLength"in t?a(t):t}return this.codecDeserializer.read(r,t)}}var C=r(38796),B=r(51011),$=r(93501),M=r(22461);class D extends h{serializer;deserializer;codec;mixin=new B.U;constructor({defaultNamespace:e}){super({defaultNamespace:e});const t={timestampFormat:{useTrait:!0,default:7},httpBindings:!0,jsonName:!0};this.codec=new $.V(t),this.serializer=new T(this.codec.createSerializer(),t),this.deserializer=new z(this.codec.createDeserializer(),t)}getShapeId(){return"aws.protocols#restJson1"}getPayloadCodec(){return this.codec}setSerdeContext(e){this.codec.setSerdeContext(e),super.setSerdeContext(e)}async serializeRequest(e,t,r){const i=await super.serializeRequest(e,t,r),a=s.l.of(e.input);if(!i.headers["content-type"]){const e=this.mixin.resolveRestContentType(this.getDefaultContentType(),a);e&&(i.headers["content-type"]=e)}return null==i.body&&i.headers["content-type"]===this.getDefaultContentType()&&(i.body="{}"),i}async deserializeResponse(e,t,r){const i=await super.deserializeResponse(e,t,r),a=s.l.of(e.output);for(const[e,t]of a.structIterator())t.getMemberTraits().httpPayload&&!(e in i)&&(i[e]=null);return i}async handleError(e,t,r,i,a){const n=(0,M.cJ)(r,i)??"Unknown",{errorSchema:o,errorMetadata:c}=await this.mixin.getErrorSchemaOrThrowBaseException(n,this.options.defaultNamespace,r,i,a),d=s.l.of(o),l=i.message??i.Message??"Unknown",u=new(C.O.for(o[1]).getErrorCtor(o)??Error)(l);await this.deserializeHttpMessage(o,t,r,i);const h={};for(const[e,t]of d.structIterator()){const r=t.getMergedTraits().jsonName??e;h[e]=this.codec.createDeserializer().readObject(t,i[r])}throw this.mixin.decorateServiceException(Object.assign(u,c,{$fault:d.getMergedTraits().error,message:l},h),i)}getDefaultContentType(){return"application/json"}}}};