telepact-console 1.0.0-alpha.270 → 1.0.0-alpha.289

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/README.md CHANGED
@@ -18,11 +18,15 @@ npx telepact-console -p 8080
18
18
 
19
19
  Then you can access the UI in your browser at http://localhost:8080.
20
20
 
21
+ When launched through the npm CLI, the Console proxies absolute live HTTP and
22
+ WebSocket URLs through its own localhost server first. This avoids browser CORS
23
+ limits while keeping the self-hosted build unchanged for same-domain embeds.
24
+
21
25
  ## Docker
22
26
 
23
- The Console is also available as a docker image, which can be installed directly from
24
- [Releases](https://github.com/Telepact/telepact/releases). You can copy the link
25
- for the Console from the release assets.
27
+ The Console is also available as a docker image, which can be installed directly
28
+ from [Releases](https://github.com/Telepact/telepact/releases). You can copy the
29
+ link for the Console from the release assets.
26
30
 
27
31
  Example:
28
32
 
@@ -39,4 +43,3 @@ docker run -p 8080:8080 telepact-console:{version}
39
43
 
40
44
  For a more concrete usage example, see
41
45
  [self-hosting example](https://github.com/Telepact/telepact/blob/main/test/console-self-hosted/).
42
-
@@ -350,4 +350,4 @@ $1 $2
350
350
  $1 $2
351
351
  `);e=e.replace(JW,``).trimEnd();let n=Object.create(null),r=UW(0,e,XW,``).replace(JW,``).trimEnd(),i;for(;i=XW.exec(e);){let e=UW(0,i[2],qW,``);if(typeof n[i[1]]==`string`||Array.isArray(n[i[1]])){let t=n[i[1]];n[i[1]]=[...QW,...Array.isArray(t)?t:[t],e]}else n[i[1]]=e}return{comments:r,pragmas:n}}var tG=[`noformat`,`noprettier`],nG=[`format`,`prettier`];function rG(e){let t=tW(e);t&&(e=e.slice(t.length+1));let{pragmas:n,comments:r}=eG($W(e));return{shebang:t,text:e,pragmas:n,comments:r}}function iG(e){let{pragmas:t}=rG(e);return nG.some(e=>Object.prototype.hasOwnProperty.call(t,e))}function aG(e){let{pragmas:t}=rG(e);return tG.some(e=>Object.prototype.hasOwnProperty.call(t,e))}function oG(e){return e=typeof e==`function`?{parse:e}:e,{astFormat:`estree`,hasPragma:iG,hasIgnorePragma:aG,locStart:sW,locEnd:cW,...e}}var sG=oG,cG=`module`,lG=`commonjs`;function uG(e){if(typeof e==`string`){if(e=e.toLowerCase(),/\.(?:mjs|mts)$/iu.test(e))return cG;if(/\.(?:cjs|cts)$/iu.test(e))return lG}}function dG(e,t){let{type:n=`JsExpressionRoot`,rootMarker:r,text:i}=t,{tokens:a,comments:o}=e;return delete e.tokens,delete e.comments,{tokens:a,comments:o,type:n,node:e,range:[0,i.length],rootMarker:r}}var fG=dG,pG=e=>sG(xG(e)),mG={sourceType:cG,allowImportExportEverywhere:!0,allowReturnOutsideFunction:!0,allowNewTargetOutsideFunction:!0,allowSuperOutsideMethod:!0,allowUndeclaredExports:!0,errorRecovery:!0,createParenthesizedExpressions:!0,attachComment:!1,plugins:[`doExpressions`,`exportDefaultFrom`,`functionBind`,`functionSent`,`throwExpressions`,`partialApplication`,`decorators`,`moduleBlocks`,`asyncDoExpressions`,`destructuringPrivate`,`decoratorAutoAccessors`,`sourcePhaseImports`,`deferredImportEvaluation`,[`optionalChainingAssign`,{version:`2023-07`}],[`discardBinding`,{syntaxType:`void`}]],tokens:!1,ranges:!1},hG=`v8intrinsic`,gG=[[`pipelineOperator`,{proposal:`hack`,topicToken:`%`}],[`pipelineOperator`,{proposal:`fsharp`}]],_G=(e,t=mG)=>({...t,plugins:[...t.plugins,...e]}),vG=/@(?:no)?flow\b/u;function yG(e,t){if(t?.endsWith(`.js.flow`))return!0;let n=tW(e);n&&(e=e.slice(n.length));let r=QU(e,0);return r!==!1&&(e=e.slice(0,r)),vG.test(e)}function bG(e,t,n){let r=e(t,n),i=r.errors.find(e=>!SG.has(e.reasonCode));if(i)throw i;return r}function xG({isExpression:e=!1,optionsCombinations:t}){return(n,r={})=>{let{filepath:i}=r;if(typeof i!=`string`&&(i=void 0),(r.parser===`babel`||r.parser===`__babel_estree`)&&yG(n,i))return r.parser=`babel-flow`,OG.parse(n,r);let a=t,o=r.__babelSourceType??uG(i);o&&o!==cG&&(a=a.map(e=>({...e,sourceType:o,...o===lG?{allowReturnOutsideFunction:void 0,allowNewTargetOutsideFunction:void 0}:void 0})));let s=/%[A-Z]/u.test(n);n.includes(`|>`)?a=(s?[...gG,hG]:gG).flatMap(e=>a.map(t=>_G([e],t))):s&&(a=a.map(e=>_G([hG],e)));let c=e?IU:FU,l;try{l=$U(a.map(e=>()=>bG(c,n,e)))}catch({errors:[e]}){throw VW(e)}return e&&(l=fG(l,{text:n,rootMarker:r.rootMarker})),IW(l,{text:n})}}var SG=new Set(`StrictNumericEscape.StrictWith.StrictOctalLiteral.StrictDelete.StrictEvalArguments.StrictEvalArgumentsBinding.StrictFunction.ForInOfLoopInitializer.ConstructorHasTypeParameters.UnsupportedParameterPropertyKind.DecoratorExportClass.ParamDupe.InvalidDecimal.RestTrailingComma.UnsupportedParameterDecorator.UnterminatedJsxContent.UnexpectedReservedWord.ModuleAttributesWithDuplicateKeys.InvalidEscapeSequenceTemplate.NonAbstractClassHasAbstractMethod.OptionalTypeBeforeRequired.PatternIsOptional.DeclareClassFieldHasInitializer.TypeImportCannotSpecifyDefaultAndNamed.VarRedeclaration.InvalidPrivateFieldResolution.DuplicateExport.ImportAttributesUseAssert.DeclarationMissingInitializer`.split(`.`)),CG=[_G([`jsx`])],wG=pG({optionsCombinations:CG}),TG=pG({optionsCombinations:[_G([`jsx`,`typescript`]),_G([`typescript`])]}),EG=pG({isExpression:!0,optionsCombinations:[_G([`jsx`])]}),DG=pG({isExpression:!0,optionsCombinations:[_G([`typescript`])]}),OG=pG({optionsCombinations:[_G([`jsx`,[`flow`,{all:!0}],`flowComments`])]}),kG=pG({optionsCombinations:CG.map(e=>_G([`estree`],e))}),AG={};vB(AG,{json:()=>RG,"json-stringify":()=>VG,json5:()=>zG,jsonc:()=>BG});function jG(e){return Array.isArray(e)&&e.length>0}var MG=jG,NG={tokens:!1,ranges:!1,attachComment:!1,createParenthesizedExpressions:!0};function PG(e){let t=FU(e,NG),{program:n}=t;if(n.body.length===0&&n.directives.length===0&&!n.interpreter)return t}function FG(e,t={}){let{allowComments:n=!0,allowEmpty:r=!1}=t,i;try{i=IU(e,NG)}catch(t){if(r&&t.code===`BABEL_PARSER_SYNTAX_ERROR`&&t.reasonCode===`ParseExpressionEmptyInput`)try{i=PG(e)}catch{}if(!i)throw VW(t)}if(!n&&MG(i.comments))throw IG(i.comments[0],`Comment`);return i=fG(i,{type:`JsonRoot`,text:e}),i.node.type===`File`?delete i.node:LG(i.node),i}function IG(e,t){let[n,r]=[e.loc.start,e.loc.end].map(({line:e,column:t})=>({line:e,column:t+1}));return RW(`${t} is not allowed in JSON.`,{loc:{start:n,end:r}})}function LG(e){switch(e.type){case`ArrayExpression`:for(let t of e.elements)t!==null&&LG(t);return;case`ObjectExpression`:for(let t of e.properties)LG(t);return;case`ObjectProperty`:if(e.computed)throw IG(e.key,`Computed key`);if(e.shorthand)throw IG(e.key,`Shorthand property`);e.key.type!==`Identifier`&&LG(e.key),LG(e.value);return;case`UnaryExpression`:{let{operator:t,argument:n}=e;if(t!==`+`&&t!==`-`)throw IG(e,`Operator '${e.operator}'`);if(n.type===`NumericLiteral`||n.type===`Identifier`&&(n.name===`Infinity`||n.name===`NaN`))return;throw IG(n,`Operator '${t}' before '${n.type}'`)}case`Identifier`:if(e.name!==`Infinity`&&e.name!==`NaN`&&e.name!==`undefined`)throw IG(e,`Identifier '${e.name}'`);return;case`TemplateLiteral`:if(MG(e.expressions))throw IG(e.expressions[0],`'TemplateLiteral' with expression`);for(let t of e.quasis)LG(t);return;case`NullLiteral`:case`BooleanLiteral`:case`NumericLiteral`:case`StringLiteral`:case`TemplateElement`:return;default:throw IG(e,`'${e.type}'`)}}var RG=sG({parse:e=>FG(e),hasPragma:()=>!0,hasIgnorePragma:()=>!1}),zG=sG(e=>FG(e)),BG=sG(e=>FG(e,{allowEmpty:!0})),VG=sG({parse:e=>FG(e,{allowComments:!1}),astFormat:`estree-json`}),HG={...bB,...AG};function UG(e){return e.map(e=>{let t=Math.max(0,80-e.length);return` `+e.padEnd(e.length+t)})}async function WG(e){if(Array.isArray(e)){let t=[];for(let n of e){let e=await WG(n);t.push(e)}return t}else if(typeof e==`object`&&e){let t={};for(let[n,r]of Object.entries(e))if(n===`///`){let e;e=typeof r==`string`?r:r.map(e=>e.trim()).join(`
352
352
  `);let i=(await lx(e,{parser:`markdown`,printWidth:78,proseWrap:`always`,plugins:[lC]})).split(`
353
- `);i.pop(),i.length===1?t[n]=` `+i[0]+` `:t[n]=UG(i)}else t[n]=await WG(r);return t}else return e}async function GG(e){let t=await WG(JSON.parse(e));return JSON.stringify(t,null,4)}var{group:KG,line:qG,softline:JG,hardline:YG,join:XG,indent:ZG}=Cb.builders;function QG(e,t,n){let r=e.getValue();if(r.type===`JsonRoot`)return e.call(n,`node`);if(r.type===`ArrayExpression`){let t=e.getParentNode(),r=t.type===`JsonRoot`,i=t&&t.type===`ObjectProperty`&&t.key.value===`///`,a=t&&t.type===`ObjectProperty`&&(t.key.value.includes(`union.`)||t.key.value.includes(`errors.`)||t.key.value===`->`);return r||i||a?[`[`,ZG(KG([YG,XG(KG([`,`,YG]),e.map(n,`elements`))])),YG,`]`]:KG([`[`,XG(`, `,e.map(n,`elements`)),`]`])}if(r.type===`ObjectExpression`){let t=()=>{let t=e.stack,n=t[t.length-1];n.loc&&n.loc.start.line,n.loc&&n.loc.start.column;for(let e=t.length-2;e>=0;e--){let n=t[e];if(n.type===`ObjectProperty`){let e=n.key.value;if(/^@[a-z][a-zA-Z0-9_]*$/.test(e)||/^([a-z][a-zA-Z0-9_]*)(!)?$/.test(e))return!0}}return!1},i=e.map(n,`properties`);return r.properties.length===0||t()?[`{`,XG(`, `,i),`}`]:[`{`,ZG(KG([YG,XG(KG([`,`,YG]),i)])),YG,`}`]}return r.type===`StringLiteral`||r.type===`NumericLiteral`?JSON.stringify(r.value):r.type===`BooleanLiteral`?r.value?`true`:`false`:r.type===`NullLiteral`?`null`:r.type===`ObjectProperty`?KG([e.call(n,`key`),`: `,e.call(n,`value`)]):``}var $G=HG[`json-stringify`],eK={print:QG},{parse:tK}=$G,nK={languages:[{name:`telepact`,parsers:[`telepact-parse`],extensions:[`.telepact.json`]}],parsers:{"telepact-parse":{...$G,parse:async(e,t)=>tK(await GG(e),t),astFormat:`telepact-ast`}},printers:{"telepact-ast":eK}};async function rK(e){let t=(e.searchParams.get(`s`)??``).trim(),n=e.searchParams.get(`i`)===`1`,r=e.searchParams.get(`p`),i=r===`http`||r===`ws`?r:void 0,a=t.toLowerCase(),o=a.startsWith(`ws://`)||a.startsWith(`wss://`)?`ws`:a.startsWith(`http://`)||a.startsWith(`https://`)?`http`:void 0,s=i??o,c=typeof window.overrideAuthHeader==`function`,l,u=`unknown`,d=!0;if(t===``){let t=typeof window.overrideDefaultSchema==`function`?window.overrideDefaultSchema():'[{"///": "No schema loaded.\\n\\nTry [editing the schema](/?v=ds), or loading a schema from a live running Telepact server by entering a URL in the `Live URL` text box.", "info.Example":{}}]',n=e.searchParams.get(`sd`)??t,r=zp.fromJson(n),i=new Fp;i.generatedCollectionLengthMin=2,i.randomizeOptionalFieldGeneration=!1,i.onError=e=>console.log(e);let a=new Pp(r,i);l=new Go(async(e,t)=>{let n=t.serialize(e),r=await a.process(n);return t.deserialize(r.bytes)},new Ko),u=`draft`,d=!1}else if(s===`http`)l=new Go(async(e,n)=>{let r=async(t,n)=>(t!==void 0&&(e.headers[`@auth_`]=t),n()),i=async()=>{let r=n.serialize(e),i=await(await fetch(t,{method:`POST`,body:r})).arrayBuffer(),a=new Uint8Array(i);return n.deserialize(a)};return e.getBodyTarget().endsWith(`_`)||window.overrideAuthHeader===void 0?r(void 0,i):window.overrideAuthHeader(t,e=>r(e,i))},new Ko),u=`http`;else if(s===`ws`){let e=[],n=null,r=null,i=t=>{for(;e.length>0;)e.shift()?.reject(t)},a=async e=>{if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Blob)return new Uint8Array(await e.arrayBuffer());if(typeof e==`string`)return new TextEncoder().encode(e);if(ArrayBuffer.isView(e)){let t=e;return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}throw Error(`Unsupported WebSocket payload type`)},o=async()=>{if(n&&n.readyState===WebSocket.OPEN)return;if(r)return r;let o=new WebSocket(t);o.binaryType=`arraybuffer`,n=o;let s=!1,c=async t=>{if(o!==n)return;let r=e.shift();if(!r){console.warn(`Received unexpected WebSocket message with no pending Telepact request.`);return}try{let e=await a(t.data),n=r.serializer.deserialize(e);r.resolve(n)}catch(e){r.reject(e)}},l=e=>{if(o!==n)return;o.removeEventListener(`message`,c),o.removeEventListener(`close`,l),o.removeEventListener(`error`,u),n=null;let t=e.reason?` ${e.reason}`:``,r=Error(`WebSocket closed with code ${e.code}.${t}`);s&&i(r)},u=()=>{o===n&&i(Error(`WebSocket error`))};return o.addEventListener(`message`,c),o.addEventListener(`close`,l),o.addEventListener(`error`,u),r=new Promise((e,t)=>{let r=()=>{o.removeEventListener(`open`,a),o.removeEventListener(`error`,d),o.removeEventListener(`close`,f)},a=()=>{r(),s=!0,e()},d=()=>{r(),o===n&&(o.removeEventListener(`message`,c),o.removeEventListener(`close`,l),o.removeEventListener(`error`,u),n=null);let e=Error(`Failed to establish WebSocket connection`);t(e),i(e)},f=e=>{r(),o===n&&(o.removeEventListener(`message`,c),o.removeEventListener(`close`,l),o.removeEventListener(`error`,u),n=null);let a=e.reason?`: ${e.reason}`:``,s=Error(`WebSocket closed before ready (code ${e.code}${a})`);t(s),i(s)};o.addEventListener(`open`,a,{once:!0}),o.addEventListener(`error`,d,{once:!0}),o.addEventListener(`close`,f,{once:!0})}).finally(()=>{r=null}),r},s=async(t,r)=>{await o();let i=n;if(!i||i.readyState!==WebSocket.OPEN)throw Error(`WebSocket is not open`);let a=r.serialize(t);return new Promise((t,n)=>{let o={resolve:t,reject:n,serializer:r};e.push(o);try{i.send(a)}catch(t){e.pop(),n(t instanceof Error?t:Error(`Failed to send message over WebSocket`))}})};l=new Go(async(e,n)=>{let r=async(t,n)=>(t!==void 0&&(e.headers[`@auth_`]=t),n()),i=()=>s(e,n);return e.getBodyTarget().endsWith(`_`)||window.overrideAuthHeader===void 0?r(void 0,i):window.overrideAuthHeader(t,e=>r(e,i))},new Ko),u=`ws`}else return{schemaSource:`unknown`,showInternalApi:n,readonlyEditor:!0,authManaged:c};if(!l)return{schemaSource:`unknown`,showInternalApi:n,readonlyEditor:!0,authManaged:c};let f=n?{"includeInternal!":!0}:{},p=(await l.request(new Ja({},{"fn.api_":f})))?.body?.Ok_?.api;if(!Array.isArray(p))throw Error(`Failed to get schema from server.`);let m=Op.fromJson(JSON.stringify(p,null,2)),h=p.filter(e=>n?!0:!(typeof e==`object`&&Object.keys(e).find(e=>e.endsWith(`_`))!==void 0)),g=JSON.stringify(h,null,2),_=(await km.format(g,{parser:`telepact-parse`,printWidth:78,proseWrap:`always`,plugins:[yB,TD,lC,nK]})).trimEnd();return{client:l,schemaSource:u,schemaProtocol:u===`http`||u===`ws`?u:void 0,showInternalApi:n,readonlyEditor:d,filteredSchemaPseudoJson:h,telepactSchema:m,schemaDraft:_,authManaged:c}}function iK(e,t){let n=JSON.parse(t),r=new Ja(n[0],n[1]),i=Date.now();return new Promise((t,n)=>{setTimeout(async()=>{try{let n=await e.request(r);t(JSON.stringify([n.headers,n.body],null,2))}catch(e){n(e)}},Math.max(0,500-(Date.now()-i)))})}function aK(e){let t=e.toLowerCase();return t.startsWith(`ws://`)||t.startsWith(`wss://`)?`ws`:`http`}function oK(e,t){let n=e.trim();if(n===``)return null;if(/%(?![0-9A-Fa-f]{2})/.test(n))return`Enter a valid URL or relative path`;let r=t===`ws`?[`ws:`,`wss:`]:[`http:`,`https:`];try{let e=new URL(n);return r.includes(e.protocol.toLowerCase())?null:t===`ws`?`URL must match selected scheme (ws:// or wss:// or a relative path)`:`URL must match selected scheme (http:// or https:// or a relative path)`}catch{try{return new URL(n,`http://placeholder.local`),null}catch{return`Enter a valid URL or relative path`}}}function sK(e,t,n){let r=n===1?`w-full`:`w-1/2`;return t===`s`?`justify-start `+r:e.includes(`s`)?`justify-end `+r:t===`d`?`justify-start `+r:e.includes(`d`)||t===`r`?`justify-end `+r:e.includes(`r`)?`justify-start `+r:t===`t`&&e.includes(`m`)?`justify-end `+r:t===`m`&&e.includes(`t`)?`justify-start `+r:`justify-end `+r}function cK(){let[e,t]=(0,T.useState)(()=>new URL(window.location.href)),n=e=>{let n=new URL(e,window.location.href);if(window.history.pushState({},``,n),t(n),n.hash){let e=n.hash.replace(`#`,``);setTimeout(()=>{document.getElementById(e)?.scrollIntoView()},0)}},[r,i]=(0,T.useState)(null),[a,o]=(0,T.useState)({status:`idle`});(0,T.useEffect)(()=>{let e=()=>{t(new URL(window.location.href)),i(null)},n=()=>t(new URL(window.location.href));return window.addEventListener(`popstate`,e),window.addEventListener(`hashchange`,n),()=>{window.removeEventListener(`popstate`,e),window.removeEventListener(`hashchange`,n)}},[]),(0,T.useEffect)(()=>{if(!r){o({status:`idle`});return}let e=!1;return o({status:`loading`}),r.then(t=>{e||o({status:`ready`,value:t})},t=>{e||o({status:`error`,error:t})}),()=>{e=!0}},[r]);let s=(e.searchParams.get(`s`)??``).trim(),c=e.searchParams.get(`p`)??``,l=`${s}|${c}|${e.searchParams.get(`i`)??``}|${e.searchParams.get(`sd`)??``}`,[u,d]=(0,T.useState)({status:`loading`});(0,T.useEffect)(()=>{let t=!1;return d({status:`loading`}),rK(e).then(e=>{t||d({status:`ready`,value:e})}).catch(e=>{t||d({status:`error`,error:e})}),()=>{t=!0}},[l]);let f=u.status===`ready`?u.value:null,p=f?.telepactSchema,m=f?.filteredSchemaPseudoJson??[],h=f?.schemaDraft??``,g=f?.authManaged??!1,_=f?.readonlyEditor??!0,v=f?.schemaSource??`unknown`;(0,T.useEffect)(()=>(_m(),gm(t=>{let r=JSON.stringify([{},t],null,2),a=new URLSearchParams(e.searchParams.toString());a.set(`r`,Gp(r,!0)),n(`?${a.toString()}`),i(null)}),()=>gm(null)),[e.search]),(0,T.useEffect)(()=>{if(!p)return;let e=pm(p);ve.setDiagnosticsOptions({schemas:[{uri:`internal://server/jsonschema-telepact.json`,fileMatch:[`schema.telepact.json`],schema:Bp},{uri:`internal://server/jsonschema-request.json`,fileMatch:[`request.json`],schema:e}]})},[p]);let y=e.searchParams.get(`v`)??`d`,b=y.substring(0,2),x=e.searchParams.get(`az`)===`1`,S=e.searchParams.get(`mf`)??`fn.ping_`,C=(e.searchParams.get(`mh`)??``).split(`,`).map(e=>e.trim()).filter(e=>e!==``),w=e.searchParams.get(`r`),[E,D]=(0,T.useState)(s);(0,T.useEffect)(()=>{D(s)},[s]);let[O,ee]=(0,T.useState)(()=>c===`http`||c===`ws`?c:aK(s)),k=(0,T.useMemo)(()=>oK(E,O),[E,O]),te=v===`draft`?`Submit (mock)`:`Submit (live)`,[A,ne]=(0,T.useState)(!1),[re,ie]=(0,T.useState)(!1),j=t=>{t.preventDefault();let r=E.trim();if(D(r),oK(r,O)!==null)return;let i=new URLSearchParams(e.searchParams.toString());i.get(`s`)!==r&&(i.delete(`mf`),i.delete(`mh`),i.delete(`r`),i.set(`v`,`d`)),r===``?(i.delete(`s`),i.delete(`p`)):(i.set(`s`,r),i.set(`p`,O)),ne(!1),n(`?${i.toString()}`)},M=t=>{let r;r=y.substring(0,2).includes(t)?y.replace(t,``):y.includes(t)?t+y.replace(t,``):t+y;let i=new URLSearchParams(e.searchParams.toString());i.set(`v`,r),n(`?${i.toString()}`)},ae=()=>{let t=new URLSearchParams(e.searchParams.toString());t.get(`i`)===`1`?t.delete(`i`):t.set(`i`,`1`),n(`?${t.toString()}`)},oe=(0,T.useRef)(null),se=(0,T.useRef)(null),ce=()=>{let t=oe.current?.getContent();if(!t)return;let r=Gp(t),i=new URLSearchParams(e.searchParams.toString());i.set(`s`,``),i.set(`sd`,r),i.set(`v`,`sd`),n(`?${i.toString()}`)},le=()=>{if((v===`http`||v===`ws`)&&!sessionStorage.getItem(`telepact-console:live-request-acknowledge`)){if(!confirm(`You are about to submit a request to a live server.`))return;sessionStorage.setItem(`telepact-console:live-request-acknowledge`,`true`)}let t=se.current?.getContent();if(!t)return;let r=new URLSearchParams(e.searchParams.toString());r.set(`v`,`tr`),r.set(`r`,Gp(t,!0)),n(`?${r.toString()}`),f?.client&&i(iK(f.client,t))},[ue,de]=(0,T.useState)(1),[fe,pe]=(0,T.useState)({status:`idle`});(0,T.useEffect)(()=>{if(!p||!b.includes(`m`)){pe({status:`idle`});return}let e=!1;return pe({status:`loading`}),em(S,C,p).then(t=>{e||pe({status:`ready`,value:t})},t=>{e||pe({status:`error`,error:t})}),()=>{e=!0}},[p,b,S,C.join(`,`),ue]);let me=f?.showInternalApi??!1,he=(0,T.useMemo)(()=>{if(!p)return[];let e=nm(m,p,x,me);return me?e:e.filter(e=>!(e.name.split(`.`)[1]??``).endsWith(`_`))},[m,x,me,p]),ge=`${ue}:${S}:${C.join(`,`)}`,_e=e=>{e.key===`Escape`&&(e.stopPropagation(),ne(!1))};return(0,I.jsxs)(`div`,{className:`text-gray-800 dark:text-gray-200`,children:[(0,I.jsx)(`nav`,{className:`fixed top-0 z-10 h-16 w-full border-y border-slate-300 bg-slate-100 dark:border-slate-600 dark:bg-slate-800`,children:(0,I.jsxs)(`div`,{className:`flex h-full items-center px-4`,children:[(0,I.jsx)(`div`,{className:`flex items-center ${re?`shrink-0 pr-4`:`flex-1 min-w-0`}`,children:(0,I.jsxs)(`div`,{className:`flex items-center rounded-md py-2`,children:[(0,I.jsx)(`div`,{className:`text-sky-400`,children:(0,I.jsx)(`img`,{src:`/favicon.svg`,alt:`Telepact logo`,className:`h-8 w-8`})}),(0,I.jsx)(`h1`,{className:`px-2 text-lg font-semibold text-gray-900 dark:text-gray-100`,children:`Telepact`})]})}),(0,I.jsxs)(`div`,{id:`view-select`,className:`flex shrink-0 content-center space-x-2 ${re?`ml-4 mr-auto justify-start`:`mx-auto justify-center`}`,children:[(0,I.jsxs)(`div`,{className:`inline-flex rounded-md`,children:[(0,I.jsx)(dm,{text:`Schema`,children:(0,I.jsx)(`button`,{"aria-label":`Toggle Schema`,"aria-pressed":b.includes(`s`),onClick:()=>M(`s`),className:`rounded-s-md p-2 ${b.includes(`s`)?`bg-sky-700 text-cyan-300`:`bg-slate-200 text-gray-800 dark:bg-slate-700 dark:text-gray-200`}`,children:(0,I.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1`,stroke:`currentColor`,className:`h-6 w-6`,children:(0,I.jsx)(`path`,{d:`M 2 22 L 5 16 L 19 2 L 22 5 L 8 19 L 2 22 M 5 16 L 8 19 M 19 8 L 16 5 M 17 4 L 20 7`})})})}),(0,I.jsx)(dm,{text:`Documentation`,children:(0,I.jsx)(`button`,{"aria-label":`Toggle Documentation`,"aria-pressed":b.includes(`d`),onClick:()=>M(`d`),className:`p-2 ${b.includes(`d`)?`bg-sky-700 text-cyan-300`:`bg-slate-200 text-gray-800 dark:bg-slate-700 dark:text-gray-200`}`,children:(0,I.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`h-6 w-6`,children:(0,I.jsx)(`path`,{d:`M 20 19 L 20 5 M 20 5 L 14 5 L 12 6 L 10 5 L 4 5 L 4 19 L 10 19 L 12 20 L 14 19 L 20 19 M 20 7 L 22 7 L 22 21 L 14 21 L 12 22 L 10 21 L 2 21 L 2 7 L 4 7 M 12 6 L 12 20 M 7 9 L 9 9 M 7 12 L 9 12 M 7 15 L 9 15 M 15 9 L 17 9 M 15 12 L 17 12 M 15 15 L 17 15`})})})}),(0,I.jsx)(dm,{text:`Example`,children:(0,I.jsx)(`button`,{"aria-label":`Toggle Simulation`,"aria-pressed":b.includes(`m`),onClick:()=>M(`m`),className:`rounded-e-md p-2 ${b.includes(`m`)?`bg-sky-700 text-cyan-300`:`bg-slate-200 text-gray-800 dark:bg-slate-700 dark:text-gray-200`}`,children:(0,I.jsx)(lm,{})})})]}),(0,I.jsxs)(`div`,{className:`inline-flex rounded-md`,children:[(0,I.jsx)(dm,{text:`Terminal`,children:(0,I.jsx)(`button`,{"aria-label":`Toggle Terminal`,"aria-pressed":b.includes(`t`),onClick:()=>M(`t`),className:`rounded-s-md p-2 ${b.includes(`t`)?`bg-emerald-900 text-green-300`:`bg-slate-200 text-gray-800 dark:bg-slate-700 dark:text-gray-200`}`,children:(0,I.jsx)(fm,{})})}),(0,I.jsx)(dm,{text:`Results`,children:(0,I.jsx)(`button`,{"aria-label":`Toggle Results`,"aria-pressed":b.includes(`r`),onClick:()=>M(`r`),className:`rounded-e-md p-2 ${b.includes(`r`)?`bg-emerald-900 text-green-300`:`bg-slate-200 text-gray-800 dark:bg-slate-700 dark:text-gray-200`}`,children:(0,I.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`h-6 w-6`,children:(0,I.jsx)(`path`,{d:`M 22 15 L 22 6 M 22 6 L 2 6 L 2 15 M 5 12 L 19 12 M 17 12 L 17 22 L 7 22 L 7 12 M 2 15 L 7 15 M 17 15 L 22 15 M 7 6 L 7 2 L 17 2 L 17 6 M 20 8 L 19 8 L 19 9 L 20 9 M 10 15 L 14 15 M 10 18 L 14 18 Z`})})})})]})]}),(0,I.jsx)(`div`,{className:`flex flex-1 min-w-0 items-center justify-end`,children:(0,I.jsxs)(`form`,{className:`flex items-center space-x-2 ml-4 ${re?`w-full`:``}`,onSubmit:j,children:[(0,I.jsxs)(`div`,{className:`flex items-stretch rounded-md border focus-within:ring-1 focus-within:ring-inset ${k?`border-red-500 focus-within:ring-red-500 ring-1 ring-inset ring-red-500 dark:border-red-400 dark:focus-within:ring-red-400`:`border-gray-300 focus-within:ring-gray-500 dark:border-gray-500 dark:focus-within:ring-gray-400`} ${re?`flex-1 min-w-0`:`w-80`}`,children:[(0,I.jsx)(`label`,{htmlFor:`url`,className:`content-center rounded-l-md px-2 py-2 text-sm font-medium whitespace-nowrap ${k?`bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300`:`bg-zinc-200 text-gray-700 dark:bg-zinc-600 dark:text-gray-200`}`,children:`Live URL`}),(0,I.jsxs)(`div`,{className:`relative flex content-center`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`content-center border-l border-gray-300 dark:border-gray-500 flex items-center gap-1 px-2 py-2 text-sm font-medium lowercase focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-sky-500 ${k?`bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300`:`bg-zinc-200 text-gray-700 dark:bg-zinc-600 dark:text-gray-200`}`,"aria-haspopup":`listbox`,"aria-label":`Select protocol`,"aria-expanded":A?`true`:`false`,onClick:()=>ne(e=>!e),onKeyDown:_e,children:[(0,I.jsx)(`span`,{children:O}),(0,I.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 20 20`,fill:`currentColor`,className:`h-4 w-4`,children:(0,I.jsx)(`path`,{fillRule:`evenodd`,d:`M5.23 7.21a.75.75 0 0 1 1.06.02L10 10.94l3.71-3.71a.75.75 0 1 1 1.06 1.06l-4.24 4.24a.75.75 0 0 1-1.06 0L5.21 8.29a.75.75 0 0 1 .02-1.08z`,clipRule:`evenodd`})})]}),A?(0,I.jsxs)(`div`,{className:`absolute left-0 top-full z-20 mt-1 w-28 overflow-hidden rounded-md border border-gray-200 bg-white shadow-lg dark:border-zinc-600 dark:bg-zinc-700`,role:`listbox`,"aria-label":`Select protocol`,onKeyDown:_e,tabIndex:-1,children:[(0,I.jsx)(`button`,{type:`button`,onClick:()=>{ee(`http`),ne(!1)},className:`block w-full px-3 py-2 text-left text-sm lowercase ${O===`http`?`bg-sky-600 text-white`:`text-gray-700 hover:bg-sky-100 dark:text-gray-100 dark:hover:bg-zinc-600`}`,role:`option`,"aria-selected":O===`http`?`true`:`false`,children:`http`}),(0,I.jsx)(`button`,{type:`button`,onClick:()=>{ee(`ws`),ne(!1)},className:`block w-full px-3 py-2 text-left text-sm lowercase ${O===`ws`?`bg-sky-600 text-white`:`text-gray-700 hover:bg-sky-100 dark:text-gray-100 dark:hover:bg-zinc-600`}`,role:`option`,"aria-selected":O===`ws`?`true`:`false`,children:`ws`})]}):null]}),(0,I.jsxs)(`div`,{className:`${re?`flex-1 min-w-0`:``}`,onFocus:()=>ie(!0),onBlur:e=>{let t=e.currentTarget,n=e.relatedTarget;(!t||!n||!t.contains(n))&&(ie(!1),ne(!1))},children:[(0,I.jsx)(dm,{text:k??``,children:(0,I.jsx)(`input`,{type:`text`,name:`url`,id:`url`,placeholder:`None (draft mode)`,value:E,onChange:e=>D(e.target.value),className:`w-full rounded-r-md border-0 pl-2 py-2 placeholder:text-gray-400 focus:ring-1 focus:ring-inset ${k?`bg-red-50 text-red-800 focus:ring-red-500 dark:bg-red-900/30 dark:text-red-200 dark:focus:ring-red-400`:`bg-zinc-100 focus:ring-gray-500 dark:bg-zinc-700 dark:focus:ring-gray-400`}`,"aria-invalid":k?`true`:`false`,"aria-describedby":k?`live-url-error`:void 0})}),k?(0,I.jsx)(`p`,{id:`live-url-error`,className:`sr-only`,children:k}):null]})]}),(0,I.jsx)(`button`,{type:`submit`,className:`shrink-0 rounded-md bg-sky-700 px-3 py-2 text-sm font-semibold text-white active:bg-sky-800`,children:`Load`})]})})]})}),(0,I.jsxs)(`main`,{className:`mt-16 flex h-[calc(100vh-4em)] bg-zinc-50 dark:bg-zinc-800`,children:[u.status===`loading`?(0,I.jsx)(`span`,{children:`loading schema`}):null,u.status===`error`?(0,I.jsx)(`span`,{children:`failed to get schema`}):null,u.status===`ready`?(0,I.jsxs)(I.Fragment,{children:[b.includes(`s`)?(0,I.jsx)(`div`,{className:`flex h-[calc(100vh-4em)] ${sK(b,`s`,b.length)}`,children:(0,I.jsxs)(`div`,{className:`flex w-full flex-col p-6`,children:[(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(`h1`,{className:`pb-4 text-xl font-semibold text-gray-900 dark:text-gray-100`,children:`Schema (JSON)`}),_?null:(0,I.jsxs)(`div`,{className:`flex space-x-2`,children:[(0,I.jsx)(`a`,{href:`https://github.com/Telepact/telepact/blob/main/doc/02-design-apis/01-schema-guide.md`,children:(0,I.jsxs)(`button`,{className:`flex items-center rounded-md bg-gray-200 px-3 py-2 text-sm font-semibold text-gray-900 hover:bg-gray-300 hover:underline dark:bg-gray-700 dark:text-white dark:hover:bg-gray-600`,children:[(0,I.jsx)(`span`,{children:`Writing Guide`}),(0,I.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`3`,stroke:`currentColor`,className:`ml-2 h-4 w-4`,children:(0,I.jsx)(`path`,{d:`M 14 2 L 4 2 A 4 4 0 0 0 0 6 L 0 20 A 4 4 0 0 0 4 24 L 18 24 A 4 4 0 0 0 22 20 L 22 10 M 11 13 L 24 0 L 18 0 M 24 0 L 24 6`})})]})}),(0,I.jsx)(`div`,{children:(0,I.jsx)(`button`,{onClick:ce,className:`rounded-md bg-sky-700 px-3 py-2 text-sm font-semibold text-white hover:bg-sky-600 active:bg-sky-700`,children:(0,I.jsx)(`span`,{children:`Save`})})})]})]}),(0,I.jsx)(`div`,{className:`grow border border-zinc-300 dark:border-zinc-600`,children:(0,I.jsx)(sm,{id:`schema`,readOnly:_,json:h,ctrlEnter:ce,filename:`schema.telepact.json`,ariaLabel:`schema`,ref:oe},h)})]})}):null,b.includes(`d`)?(0,I.jsx)(`div`,{className:`flex overflow-scroll ${sK(b,`d`,b.length)}`,children:(0,I.jsxs)(`div`,{className:`flex w-full flex-col p-6`,children:[(0,I.jsx)(`div`,{children:(0,I.jsx)(`h1`,{className:`pb-4 text-xl font-semibold text-gray-900 dark:text-gray-100`,children:`Schema`})}),he.map(e=>(0,I.jsx)(um,{entry:e,telepactSchema:p,navigate:n},e.name)),(0,I.jsx)(`div`,{className:`flex justify-center pb-4`,children:(0,I.jsx)(`button`,{onClick:ae,className:`mt-4 rounded-md bg-sky-700 px-3 py-2 text-sm font-semibold text-white hover:bg-sky-600`,children:me?`Hide Internal API`:`Show Internal API`})})]})}):null,b.includes(`m`)?(0,I.jsx)(`div`,{className:`flex overflow-scroll ${sK(b,`m`,b.length)}`,children:(0,I.jsxs)(`div`,{className:`flex w-full flex-col p-6`,children:[(0,I.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,I.jsx)(`h1`,{className:`pb-4 text-xl font-semibold text-gray-900 dark:text-gray-100`,children:`Mocked Example`}),(0,I.jsx)(`button`,{onClick:()=>de(e=>e+1),className:`rounded-md bg-sky-700 px-3 py-2 text-sm font-semibold text-white hover:bg-sky-600`,children:`Regenerate`})]}),fe.status===`loading`?(0,I.jsx)(`div`,{className:`mb-4`,children:(0,I.jsxs)(`span`,{children:[`Loading...`,(0,I.jsx)(`span`,{children:` `})]})}):null,fe.status===`ready`?(0,I.jsxs)(`div`,{className:`flex h-full flex-col space-y-2`,children:[(0,I.jsx)(`div`,{className:`h-1/2 grow border border-zinc-300 dark:border-zinc-600`,children:(0,I.jsx)(sm,{id:`requestExample`,readOnly:!0,json:fe.value.request,allowLinks:!1,filename:`requestExample.json`,ariaLabel:`requestExample`,minimap:!1},`${ge}:request`)}),(0,I.jsx)(`div`,{className:`ml-4 shrink`,children:(0,I.jsx)(`span`,{className:`text-3xl text-emerald-500`,children:`→`})}),(0,I.jsx)(`div`,{className:`h-1/2 grow border border-zinc-300 dark:border-zinc-600`,children:(0,I.jsx)(sm,{id:`responseExample`,readOnly:!0,json:fe.value.response,allowLinks:!1,filename:`responseExample.json`,ariaLabel:`responseExample`,lineNumbers:!1,minimap:!1},`${ge}:response`)})]}):null]})}):null,b.includes(`t`)?(0,I.jsx)(`div`,{className:`flex h-[calc(100vh-4em)] ${sK(b,`t`,b.length)}`,children:(0,I.jsxs)(`div`,{className:`flex w-full flex-col bg-zinc-100 p-6 dark:bg-zinc-700`,children:[(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(`h1`,{className:`pb-4 text-xl font-semibold text-gray-900 dark:text-gray-100`,children:`Request`}),(0,I.jsx)(`div`,{children:(0,I.jsx)(`button`,{onClick:le,disabled:a.status===`loading`,className:`rounded-md px-3 py-2 text-sm font-semibold ${a.status===`loading`?`cursor-not-allowed bg-sky-600/40 text-gray-500 dark:text-gray-300`:`bg-sky-700 text-white active:bg-sky-800`}`,children:te})})]}),(0,I.jsx)(`div`,{className:`grow border border-zinc-300 dark:border-zinc-600`,children:(0,I.jsx)(sm,{id:`request`,readOnly:!1,json:Kp(w,g),ctrlEnter:le,filename:`request.json`,ariaLabel:`request`,ref:se},w??``)})]})}):null,b.includes(`r`)?(0,I.jsx)(`div`,{className:`flex h-[calc(100vh-4em)] ${sK(b,`r`,b.length)}`,children:r?(0,I.jsxs)(`div`,{className:`flex w-full flex-col bg-zinc-100 p-6 dark:bg-zinc-700`,children:[(0,I.jsx)(`h1`,{className:`mb-4 text-xl font-semibold text-gray-900 dark:text-gray-100`,children:`Response`}),a.status===`loading`?(0,I.jsx)(`div`,{className:`grid h-full w-full place-content-center`,children:(0,I.jsx)(`div`,{children:(0,I.jsxs)(`span`,{children:[`Loading...`,(0,I.jsx)(`span`,{children:` `})]})})}):null,a.status===`ready`?(0,I.jsx)(`div`,{className:`grow border border-zinc-300 dark:border-zinc-600`,children:(0,I.jsx)(sm,{id:`response`,readOnly:!0,json:a.value,allowLinks:!0,filename:`response.json`,ariaLabel:`response`},a.value)}):null,a.status===`error`?(0,I.jsx)(`div`,{className:`h-full rounded-md border border-red-300 bg-red-100 p-4 text-red-700 dark:border-red-700 dark:bg-red-500/20 dark:text-red-500`,children:(0,I.jsx)(`div`,{className:`overflow-scroll`,children:(0,I.jsx)(`span`,{children:String(a.error)})})}):null]}):(0,I.jsx)(`div`,{className:`grid h-full w-full place-content-center`,children:(0,I.jsx)(`div`,{children:(0,I.jsx)(`span`,{children:`Click "Submit" on Request pane to fetch response.`})})})}):null]}):null]})]})}var lK=document.getElementById(`app-root`);if(!lK)throw Error(`Missing #app-root`);E.createRoot(lK).render((0,I.jsx)(T.StrictMode,{children:(0,I.jsx)(cK,{})}));
353
+ `);i.pop(),i.length===1?t[n]=` `+i[0]+` `:t[n]=UG(i)}else t[n]=await WG(r);return t}else return e}async function GG(e){let t=await WG(JSON.parse(e));return JSON.stringify(t,null,4)}var{group:KG,line:qG,softline:JG,hardline:YG,join:XG,indent:ZG}=Cb.builders;function QG(e,t,n){let r=e.getValue();if(r.type===`JsonRoot`)return e.call(n,`node`);if(r.type===`ArrayExpression`){let t=e.getParentNode(),r=t.type===`JsonRoot`,i=t&&t.type===`ObjectProperty`&&t.key.value===`///`,a=t&&t.type===`ObjectProperty`&&(t.key.value.includes(`union.`)||t.key.value.includes(`errors.`)||t.key.value===`->`);return r||i||a?[`[`,ZG(KG([YG,XG(KG([`,`,YG]),e.map(n,`elements`))])),YG,`]`]:KG([`[`,XG(`, `,e.map(n,`elements`)),`]`])}if(r.type===`ObjectExpression`){let t=()=>{let t=e.stack,n=t[t.length-1];n.loc&&n.loc.start.line,n.loc&&n.loc.start.column;for(let e=t.length-2;e>=0;e--){let n=t[e];if(n.type===`ObjectProperty`){let e=n.key.value;if(/^@[a-z][a-zA-Z0-9_]*$/.test(e)||/^([a-z][a-zA-Z0-9_]*)(!)?$/.test(e))return!0}}return!1},i=e.map(n,`properties`);return r.properties.length===0||t()?[`{`,XG(`, `,i),`}`]:[`{`,ZG(KG([YG,XG(KG([`,`,YG]),i)])),YG,`}`]}return r.type===`StringLiteral`||r.type===`NumericLiteral`?JSON.stringify(r.value):r.type===`BooleanLiteral`?r.value?`true`:`false`:r.type===`NullLiteral`?`null`:r.type===`ObjectProperty`?KG([e.call(n,`key`),`: `,e.call(n,`value`)]):``}var $G=HG[`json-stringify`],eK={print:QG},{parse:tK}=$G,nK={languages:[{name:`telepact`,parsers:[`telepact-parse`],extensions:[`.telepact.json`]}],parsers:{"telepact-parse":{...$G,parse:async(e,t)=>tK(await GG(e),t),astFormat:`telepact-ast`}},printers:{"telepact-ast":eK}};function rK(e){if(window.telepactConsoleProxy===void 0)return e;let t=e.toLowerCase();if(!t.startsWith(`http://`)&&!t.startsWith(`https://`))return e;let n=new URL(window.telepactConsoleProxy.httpPath,window.location.href);return n.searchParams.set(`target`,e),n.toString()}function iK(e){if(window.telepactConsoleProxy===void 0)return e;let t=e.toLowerCase();if(!t.startsWith(`ws://`)&&!t.startsWith(`wss://`))return e;let n=new URL(window.telepactConsoleProxy.wsPath,window.location.href);return n.protocol===`https:`?n.protocol=`wss:`:n.protocol===`http:`&&(n.protocol=`ws:`),n.searchParams.set(`target`,e),n.toString()}async function aK(e){let t=(e.searchParams.get(`s`)??``).trim(),n=e.searchParams.get(`i`)===`1`,r=e.searchParams.get(`p`),i=r===`http`||r===`ws`?r:void 0,a=t.toLowerCase(),o=a.startsWith(`ws://`)||a.startsWith(`wss://`)?`ws`:a.startsWith(`http://`)||a.startsWith(`https://`)?`http`:void 0,s=i??o,c=typeof window.overrideAuthHeader==`function`,l,u=`unknown`,d=!0;if(t===``){let t=typeof window.overrideDefaultSchema==`function`?window.overrideDefaultSchema():'[{"///": "No schema loaded.\\n\\nTry [editing the schema](/?v=ds), or loading a schema from a live running Telepact server by entering a URL in the `Live URL` text box.", "info.Example":{}}]',n=e.searchParams.get(`sd`)??t,r=zp.fromJson(n),i=new Fp;i.generatedCollectionLengthMin=2,i.randomizeOptionalFieldGeneration=!1,i.onError=e=>console.log(e);let a=new Pp(r,i);l=new Go(async(e,t)=>{let n=t.serialize(e),r=await a.process(n);return t.deserialize(r.bytes)},new Ko),u=`draft`,d=!1}else if(s===`http`)l=new Go(async(e,n)=>{let r=async(t,n)=>(t!==void 0&&(e.headers[`@auth_`]=t),n()),i=async()=>{let r=n.serialize(e),i=await(await fetch(rK(t),{method:`POST`,body:r})).arrayBuffer(),a=new Uint8Array(i);return n.deserialize(a)};return e.getBodyTarget().endsWith(`_`)||window.overrideAuthHeader===void 0?r(void 0,i):window.overrideAuthHeader(t,e=>r(e,i))},new Ko),u=`http`;else if(s===`ws`){let e=[],n=null,r=null,i=t=>{for(;e.length>0;)e.shift()?.reject(t)},a=async e=>{if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Blob)return new Uint8Array(await e.arrayBuffer());if(typeof e==`string`)return new TextEncoder().encode(e);if(ArrayBuffer.isView(e)){let t=e;return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}throw Error(`Unsupported WebSocket payload type`)},o=async()=>{if(n&&n.readyState===WebSocket.OPEN)return;if(r)return r;let o=new WebSocket(iK(t));o.binaryType=`arraybuffer`,n=o;let s=!1,c=async t=>{if(o!==n)return;let r=e.shift();if(!r){console.warn(`Received unexpected WebSocket message with no pending Telepact request.`);return}try{let e=await a(t.data),n=r.serializer.deserialize(e);r.resolve(n)}catch(e){r.reject(e)}},l=e=>{if(o!==n)return;o.removeEventListener(`message`,c),o.removeEventListener(`close`,l),o.removeEventListener(`error`,u),n=null;let t=e.reason?` ${e.reason}`:``,r=Error(`WebSocket closed with code ${e.code}.${t}`);s&&i(r)},u=()=>{o===n&&i(Error(`WebSocket error`))};return o.addEventListener(`message`,c),o.addEventListener(`close`,l),o.addEventListener(`error`,u),r=new Promise((e,t)=>{let r=()=>{o.removeEventListener(`open`,a),o.removeEventListener(`error`,d),o.removeEventListener(`close`,f)},a=()=>{r(),s=!0,e()},d=()=>{r(),o===n&&(o.removeEventListener(`message`,c),o.removeEventListener(`close`,l),o.removeEventListener(`error`,u),n=null);let e=Error(`Failed to establish WebSocket connection`);t(e),i(e)},f=e=>{r(),o===n&&(o.removeEventListener(`message`,c),o.removeEventListener(`close`,l),o.removeEventListener(`error`,u),n=null);let a=e.reason?`: ${e.reason}`:``,s=Error(`WebSocket closed before ready (code ${e.code}${a})`);t(s),i(s)};o.addEventListener(`open`,a,{once:!0}),o.addEventListener(`error`,d,{once:!0}),o.addEventListener(`close`,f,{once:!0})}).finally(()=>{r=null}),r},s=async(t,r)=>{await o();let i=n;if(!i||i.readyState!==WebSocket.OPEN)throw Error(`WebSocket is not open`);let a=r.serialize(t);return new Promise((t,n)=>{let o={resolve:t,reject:n,serializer:r};e.push(o);try{i.send(a)}catch(t){e.pop(),n(t instanceof Error?t:Error(`Failed to send message over WebSocket`))}})};l=new Go(async(e,n)=>{let r=async(t,n)=>(t!==void 0&&(e.headers[`@auth_`]=t),n()),i=()=>s(e,n);return e.getBodyTarget().endsWith(`_`)||window.overrideAuthHeader===void 0?r(void 0,i):window.overrideAuthHeader(t,e=>r(e,i))},new Ko),u=`ws`}else return{schemaSource:`unknown`,showInternalApi:n,readonlyEditor:!0,authManaged:c};if(!l)return{schemaSource:`unknown`,showInternalApi:n,readonlyEditor:!0,authManaged:c};let f=n?{"includeInternal!":!0}:{},p=(await l.request(new Ja({},{"fn.api_":f})))?.body?.Ok_?.api;if(!Array.isArray(p))throw Error(`Failed to get schema from server.`);let m=Op.fromJson(JSON.stringify(p,null,2)),h=p.filter(e=>n?!0:!(typeof e==`object`&&Object.keys(e).find(e=>e.endsWith(`_`))!==void 0)),g=JSON.stringify(h,null,2),_=(await km.format(g,{parser:`telepact-parse`,printWidth:78,proseWrap:`always`,plugins:[yB,TD,lC,nK]})).trimEnd();return{client:l,schemaSource:u,schemaProtocol:u===`http`||u===`ws`?u:void 0,showInternalApi:n,readonlyEditor:d,filteredSchemaPseudoJson:h,telepactSchema:m,schemaDraft:_,authManaged:c}}function oK(e,t){let n=JSON.parse(t),r=new Ja(n[0],n[1]),i=Date.now();return new Promise((t,n)=>{setTimeout(async()=>{try{let n=await e.request(r);t(JSON.stringify([n.headers,n.body],null,2))}catch(e){n(e)}},Math.max(0,500-(Date.now()-i)))})}function sK(e){let t=e.toLowerCase();return t.startsWith(`ws://`)||t.startsWith(`wss://`)?`ws`:`http`}function cK(e,t){let n=e.trim();if(n===``)return null;if(/%(?![0-9A-Fa-f]{2})/.test(n))return`Enter a valid URL or relative path`;let r=t===`ws`?[`ws:`,`wss:`]:[`http:`,`https:`];try{let e=new URL(n);return r.includes(e.protocol.toLowerCase())?null:t===`ws`?`URL must match selected scheme (ws:// or wss:// or a relative path)`:`URL must match selected scheme (http:// or https:// or a relative path)`}catch{try{return new URL(n,`http://placeholder.local`),null}catch{return`Enter a valid URL or relative path`}}}function lK(e,t,n){let r=n===1?`w-full`:`w-1/2`;return t===`s`?`justify-start `+r:e.includes(`s`)?`justify-end `+r:t===`d`?`justify-start `+r:e.includes(`d`)||t===`r`?`justify-end `+r:e.includes(`r`)?`justify-start `+r:t===`t`&&e.includes(`m`)?`justify-end `+r:t===`m`&&e.includes(`t`)?`justify-start `+r:`justify-end `+r}function uK(){let[e,t]=(0,T.useState)(()=>new URL(window.location.href)),n=e=>{let n=new URL(e,window.location.href);if(window.history.pushState({},``,n),t(n),n.hash){let e=n.hash.replace(`#`,``);setTimeout(()=>{document.getElementById(e)?.scrollIntoView()},0)}},[r,i]=(0,T.useState)(null),[a,o]=(0,T.useState)({status:`idle`});(0,T.useEffect)(()=>{let e=()=>{t(new URL(window.location.href)),i(null)},n=()=>t(new URL(window.location.href));return window.addEventListener(`popstate`,e),window.addEventListener(`hashchange`,n),()=>{window.removeEventListener(`popstate`,e),window.removeEventListener(`hashchange`,n)}},[]),(0,T.useEffect)(()=>{if(!r){o({status:`idle`});return}let e=!1;return o({status:`loading`}),r.then(t=>{e||o({status:`ready`,value:t})},t=>{e||o({status:`error`,error:t})}),()=>{e=!0}},[r]);let s=(e.searchParams.get(`s`)??``).trim(),c=e.searchParams.get(`p`)??``,l=`${s}|${c}|${e.searchParams.get(`i`)??``}|${e.searchParams.get(`sd`)??``}`,[u,d]=(0,T.useState)({status:`loading`});(0,T.useEffect)(()=>{let t=!1;return d({status:`loading`}),aK(e).then(e=>{t||d({status:`ready`,value:e})}).catch(e=>{t||d({status:`error`,error:e})}),()=>{t=!0}},[l]);let f=u.status===`ready`?u.value:null,p=f?.telepactSchema,m=f?.filteredSchemaPseudoJson??[],h=f?.schemaDraft??``,g=f?.authManaged??!1,_=f?.readonlyEditor??!0,v=f?.schemaSource??`unknown`;(0,T.useEffect)(()=>(_m(),gm(t=>{let r=JSON.stringify([{},t],null,2),a=new URLSearchParams(e.searchParams.toString());a.set(`r`,Gp(r,!0)),n(`?${a.toString()}`),i(null)}),()=>gm(null)),[e.search]),(0,T.useEffect)(()=>{if(!p)return;let e=pm(p);ve.setDiagnosticsOptions({schemas:[{uri:`internal://server/jsonschema-telepact.json`,fileMatch:[`schema.telepact.json`],schema:Bp},{uri:`internal://server/jsonschema-request.json`,fileMatch:[`request.json`],schema:e}]})},[p]);let y=e.searchParams.get(`v`)??`d`,b=y.substring(0,2),x=e.searchParams.get(`az`)===`1`,S=e.searchParams.get(`mf`)??`fn.ping_`,C=(e.searchParams.get(`mh`)??``).split(`,`).map(e=>e.trim()).filter(e=>e!==``),w=e.searchParams.get(`r`),[E,D]=(0,T.useState)(s);(0,T.useEffect)(()=>{D(s)},[s]);let[O,ee]=(0,T.useState)(()=>c===`http`||c===`ws`?c:sK(s)),k=(0,T.useMemo)(()=>cK(E,O),[E,O]),te=v===`draft`?`Submit (mock)`:`Submit (live)`,[A,ne]=(0,T.useState)(!1),[re,ie]=(0,T.useState)(!1),j=t=>{t.preventDefault();let r=E.trim();if(D(r),cK(r,O)!==null)return;let i=new URLSearchParams(e.searchParams.toString());i.get(`s`)!==r&&(i.delete(`mf`),i.delete(`mh`),i.delete(`r`),i.set(`v`,`d`)),r===``?(i.delete(`s`),i.delete(`p`)):(i.set(`s`,r),i.set(`p`,O)),ne(!1),n(`?${i.toString()}`)},M=t=>{let r;r=y.substring(0,2).includes(t)?y.replace(t,``):y.includes(t)?t+y.replace(t,``):t+y;let i=new URLSearchParams(e.searchParams.toString());i.set(`v`,r),n(`?${i.toString()}`)},ae=()=>{let t=new URLSearchParams(e.searchParams.toString());t.get(`i`)===`1`?t.delete(`i`):t.set(`i`,`1`),n(`?${t.toString()}`)},oe=(0,T.useRef)(null),se=(0,T.useRef)(null),ce=()=>{let t=oe.current?.getContent();if(!t)return;let r=Gp(t),i=new URLSearchParams(e.searchParams.toString());i.set(`s`,``),i.set(`sd`,r),i.set(`v`,`sd`),n(`?${i.toString()}`)},le=()=>{if((v===`http`||v===`ws`)&&!sessionStorage.getItem(`telepact-console:live-request-acknowledge`)){if(!confirm(`You are about to submit a request to a live server.`))return;sessionStorage.setItem(`telepact-console:live-request-acknowledge`,`true`)}let t=se.current?.getContent();if(!t)return;let r=new URLSearchParams(e.searchParams.toString());r.set(`v`,`tr`),r.set(`r`,Gp(t,!0)),n(`?${r.toString()}`),f?.client&&i(oK(f.client,t))},[ue,de]=(0,T.useState)(1),[fe,pe]=(0,T.useState)({status:`idle`});(0,T.useEffect)(()=>{if(!p||!b.includes(`m`)){pe({status:`idle`});return}let e=!1;return pe({status:`loading`}),em(S,C,p).then(t=>{e||pe({status:`ready`,value:t})},t=>{e||pe({status:`error`,error:t})}),()=>{e=!0}},[p,b,S,C.join(`,`),ue]);let me=f?.showInternalApi??!1,he=(0,T.useMemo)(()=>{if(!p)return[];let e=nm(m,p,x,me);return me?e:e.filter(e=>!(e.name.split(`.`)[1]??``).endsWith(`_`))},[m,x,me,p]),ge=`${ue}:${S}:${C.join(`,`)}`,_e=e=>{e.key===`Escape`&&(e.stopPropagation(),ne(!1))};return(0,I.jsxs)(`div`,{className:`text-gray-800 dark:text-gray-200`,children:[(0,I.jsx)(`nav`,{className:`fixed top-0 z-10 h-16 w-full border-y border-slate-300 bg-slate-100 dark:border-slate-600 dark:bg-slate-800`,children:(0,I.jsxs)(`div`,{className:`flex h-full items-center px-4`,children:[(0,I.jsx)(`div`,{className:`flex items-center ${re?`shrink-0 pr-4`:`flex-1 min-w-0`}`,children:(0,I.jsxs)(`div`,{className:`flex items-center rounded-md py-2`,children:[(0,I.jsx)(`div`,{className:`text-sky-400`,children:(0,I.jsx)(`img`,{src:`/favicon.svg`,alt:`Telepact logo`,className:`h-8 w-8`})}),(0,I.jsx)(`h1`,{className:`px-2 text-lg font-semibold text-gray-900 dark:text-gray-100`,children:`Telepact`})]})}),(0,I.jsxs)(`div`,{id:`view-select`,className:`flex shrink-0 content-center space-x-2 ${re?`ml-4 mr-auto justify-start`:`mx-auto justify-center`}`,children:[(0,I.jsxs)(`div`,{className:`inline-flex rounded-md`,children:[(0,I.jsx)(dm,{text:`Schema`,children:(0,I.jsx)(`button`,{"aria-label":`Toggle Schema`,"aria-pressed":b.includes(`s`),onClick:()=>M(`s`),className:`rounded-s-md p-2 ${b.includes(`s`)?`bg-sky-700 text-cyan-300`:`bg-slate-200 text-gray-800 dark:bg-slate-700 dark:text-gray-200`}`,children:(0,I.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1`,stroke:`currentColor`,className:`h-6 w-6`,children:(0,I.jsx)(`path`,{d:`M 2 22 L 5 16 L 19 2 L 22 5 L 8 19 L 2 22 M 5 16 L 8 19 M 19 8 L 16 5 M 17 4 L 20 7`})})})}),(0,I.jsx)(dm,{text:`Documentation`,children:(0,I.jsx)(`button`,{"aria-label":`Toggle Documentation`,"aria-pressed":b.includes(`d`),onClick:()=>M(`d`),className:`p-2 ${b.includes(`d`)?`bg-sky-700 text-cyan-300`:`bg-slate-200 text-gray-800 dark:bg-slate-700 dark:text-gray-200`}`,children:(0,I.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`h-6 w-6`,children:(0,I.jsx)(`path`,{d:`M 20 19 L 20 5 M 20 5 L 14 5 L 12 6 L 10 5 L 4 5 L 4 19 L 10 19 L 12 20 L 14 19 L 20 19 M 20 7 L 22 7 L 22 21 L 14 21 L 12 22 L 10 21 L 2 21 L 2 7 L 4 7 M 12 6 L 12 20 M 7 9 L 9 9 M 7 12 L 9 12 M 7 15 L 9 15 M 15 9 L 17 9 M 15 12 L 17 12 M 15 15 L 17 15`})})})}),(0,I.jsx)(dm,{text:`Example`,children:(0,I.jsx)(`button`,{"aria-label":`Toggle Simulation`,"aria-pressed":b.includes(`m`),onClick:()=>M(`m`),className:`rounded-e-md p-2 ${b.includes(`m`)?`bg-sky-700 text-cyan-300`:`bg-slate-200 text-gray-800 dark:bg-slate-700 dark:text-gray-200`}`,children:(0,I.jsx)(lm,{})})})]}),(0,I.jsxs)(`div`,{className:`inline-flex rounded-md`,children:[(0,I.jsx)(dm,{text:`Terminal`,children:(0,I.jsx)(`button`,{"aria-label":`Toggle Terminal`,"aria-pressed":b.includes(`t`),onClick:()=>M(`t`),className:`rounded-s-md p-2 ${b.includes(`t`)?`bg-emerald-900 text-green-300`:`bg-slate-200 text-gray-800 dark:bg-slate-700 dark:text-gray-200`}`,children:(0,I.jsx)(fm,{})})}),(0,I.jsx)(dm,{text:`Results`,children:(0,I.jsx)(`button`,{"aria-label":`Toggle Results`,"aria-pressed":b.includes(`r`),onClick:()=>M(`r`),className:`rounded-e-md p-2 ${b.includes(`r`)?`bg-emerald-900 text-green-300`:`bg-slate-200 text-gray-800 dark:bg-slate-700 dark:text-gray-200`}`,children:(0,I.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`h-6 w-6`,children:(0,I.jsx)(`path`,{d:`M 22 15 L 22 6 M 22 6 L 2 6 L 2 15 M 5 12 L 19 12 M 17 12 L 17 22 L 7 22 L 7 12 M 2 15 L 7 15 M 17 15 L 22 15 M 7 6 L 7 2 L 17 2 L 17 6 M 20 8 L 19 8 L 19 9 L 20 9 M 10 15 L 14 15 M 10 18 L 14 18 Z`})})})})]})]}),(0,I.jsx)(`div`,{className:`flex flex-1 min-w-0 items-center justify-end`,children:(0,I.jsxs)(`form`,{className:`flex items-center space-x-2 ml-4 ${re?`w-full`:``}`,onSubmit:j,children:[(0,I.jsxs)(`div`,{className:`flex items-stretch rounded-md border focus-within:ring-1 focus-within:ring-inset ${k?`border-red-500 focus-within:ring-red-500 ring-1 ring-inset ring-red-500 dark:border-red-400 dark:focus-within:ring-red-400`:`border-gray-300 focus-within:ring-gray-500 dark:border-gray-500 dark:focus-within:ring-gray-400`} ${re?`flex-1 min-w-0`:`w-80`}`,children:[(0,I.jsx)(`label`,{htmlFor:`url`,className:`content-center rounded-l-md px-2 py-2 text-sm font-medium whitespace-nowrap ${k?`bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300`:`bg-zinc-200 text-gray-700 dark:bg-zinc-600 dark:text-gray-200`}`,children:`Live URL`}),(0,I.jsxs)(`div`,{className:`relative flex content-center`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`content-center border-l border-gray-300 dark:border-gray-500 flex items-center gap-1 px-2 py-2 text-sm font-medium lowercase focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-sky-500 ${k?`bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300`:`bg-zinc-200 text-gray-700 dark:bg-zinc-600 dark:text-gray-200`}`,"aria-haspopup":`listbox`,"aria-label":`Select protocol`,"aria-expanded":A?`true`:`false`,onClick:()=>ne(e=>!e),onKeyDown:_e,children:[(0,I.jsx)(`span`,{children:O}),(0,I.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 20 20`,fill:`currentColor`,className:`h-4 w-4`,children:(0,I.jsx)(`path`,{fillRule:`evenodd`,d:`M5.23 7.21a.75.75 0 0 1 1.06.02L10 10.94l3.71-3.71a.75.75 0 1 1 1.06 1.06l-4.24 4.24a.75.75 0 0 1-1.06 0L5.21 8.29a.75.75 0 0 1 .02-1.08z`,clipRule:`evenodd`})})]}),A?(0,I.jsxs)(`div`,{className:`absolute left-0 top-full z-20 mt-1 w-28 overflow-hidden rounded-md border border-gray-200 bg-white shadow-lg dark:border-zinc-600 dark:bg-zinc-700`,role:`listbox`,"aria-label":`Select protocol`,onKeyDown:_e,tabIndex:-1,children:[(0,I.jsx)(`button`,{type:`button`,onClick:()=>{ee(`http`),ne(!1)},className:`block w-full px-3 py-2 text-left text-sm lowercase ${O===`http`?`bg-sky-600 text-white`:`text-gray-700 hover:bg-sky-100 dark:text-gray-100 dark:hover:bg-zinc-600`}`,role:`option`,"aria-selected":O===`http`?`true`:`false`,children:`http`}),(0,I.jsx)(`button`,{type:`button`,onClick:()=>{ee(`ws`),ne(!1)},className:`block w-full px-3 py-2 text-left text-sm lowercase ${O===`ws`?`bg-sky-600 text-white`:`text-gray-700 hover:bg-sky-100 dark:text-gray-100 dark:hover:bg-zinc-600`}`,role:`option`,"aria-selected":O===`ws`?`true`:`false`,children:`ws`})]}):null]}),(0,I.jsxs)(`div`,{className:`${re?`flex-1 min-w-0`:``}`,onFocus:()=>ie(!0),onBlur:e=>{let t=e.currentTarget,n=e.relatedTarget;(!t||!n||!t.contains(n))&&(ie(!1),ne(!1))},children:[(0,I.jsx)(dm,{text:k??``,children:(0,I.jsx)(`input`,{type:`text`,name:`url`,id:`url`,placeholder:`None (draft mode)`,value:E,onChange:e=>D(e.target.value),className:`w-full rounded-r-md border-0 pl-2 py-2 placeholder:text-gray-400 focus:ring-1 focus:ring-inset ${k?`bg-red-50 text-red-800 focus:ring-red-500 dark:bg-red-900/30 dark:text-red-200 dark:focus:ring-red-400`:`bg-zinc-100 focus:ring-gray-500 dark:bg-zinc-700 dark:focus:ring-gray-400`}`,"aria-invalid":k?`true`:`false`,"aria-describedby":k?`live-url-error`:void 0})}),k?(0,I.jsx)(`p`,{id:`live-url-error`,className:`sr-only`,children:k}):null]})]}),(0,I.jsx)(`button`,{type:`submit`,className:`shrink-0 rounded-md bg-sky-700 px-3 py-2 text-sm font-semibold text-white active:bg-sky-800`,children:`Load`})]})})]})}),(0,I.jsxs)(`main`,{className:`mt-16 flex h-[calc(100vh-4em)] bg-zinc-50 dark:bg-zinc-800`,children:[u.status===`loading`?(0,I.jsx)(`span`,{children:`loading schema`}):null,u.status===`error`?(0,I.jsx)(`span`,{children:`failed to get schema`}):null,u.status===`ready`?(0,I.jsxs)(I.Fragment,{children:[b.includes(`s`)?(0,I.jsx)(`div`,{className:`flex h-[calc(100vh-4em)] ${lK(b,`s`,b.length)}`,children:(0,I.jsxs)(`div`,{className:`flex w-full flex-col p-6`,children:[(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(`h1`,{className:`pb-4 text-xl font-semibold text-gray-900 dark:text-gray-100`,children:`Schema (JSON)`}),_?null:(0,I.jsxs)(`div`,{className:`flex space-x-2`,children:[(0,I.jsx)(`a`,{href:`https://github.com/Telepact/telepact/blob/main/doc/02-design-apis/01-schema-guide.md`,children:(0,I.jsxs)(`button`,{className:`flex items-center rounded-md bg-gray-200 px-3 py-2 text-sm font-semibold text-gray-900 hover:bg-gray-300 hover:underline dark:bg-gray-700 dark:text-white dark:hover:bg-gray-600`,children:[(0,I.jsx)(`span`,{children:`Writing Guide`}),(0,I.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`3`,stroke:`currentColor`,className:`ml-2 h-4 w-4`,children:(0,I.jsx)(`path`,{d:`M 14 2 L 4 2 A 4 4 0 0 0 0 6 L 0 20 A 4 4 0 0 0 4 24 L 18 24 A 4 4 0 0 0 22 20 L 22 10 M 11 13 L 24 0 L 18 0 M 24 0 L 24 6`})})]})}),(0,I.jsx)(`div`,{children:(0,I.jsx)(`button`,{onClick:ce,className:`rounded-md bg-sky-700 px-3 py-2 text-sm font-semibold text-white hover:bg-sky-600 active:bg-sky-700`,children:(0,I.jsx)(`span`,{children:`Save`})})})]})]}),(0,I.jsx)(`div`,{className:`grow border border-zinc-300 dark:border-zinc-600`,children:(0,I.jsx)(sm,{id:`schema`,readOnly:_,json:h,ctrlEnter:ce,filename:`schema.telepact.json`,ariaLabel:`schema`,ref:oe},h)})]})}):null,b.includes(`d`)?(0,I.jsx)(`div`,{className:`flex overflow-scroll ${lK(b,`d`,b.length)}`,children:(0,I.jsxs)(`div`,{className:`flex w-full flex-col p-6`,children:[(0,I.jsx)(`div`,{children:(0,I.jsx)(`h1`,{className:`pb-4 text-xl font-semibold text-gray-900 dark:text-gray-100`,children:`Schema`})}),he.map(e=>(0,I.jsx)(um,{entry:e,telepactSchema:p,navigate:n},e.name)),(0,I.jsx)(`div`,{className:`flex justify-center pb-4`,children:(0,I.jsx)(`button`,{onClick:ae,className:`mt-4 rounded-md bg-sky-700 px-3 py-2 text-sm font-semibold text-white hover:bg-sky-600`,children:me?`Hide Internal API`:`Show Internal API`})})]})}):null,b.includes(`m`)?(0,I.jsx)(`div`,{className:`flex overflow-scroll ${lK(b,`m`,b.length)}`,children:(0,I.jsxs)(`div`,{className:`flex w-full flex-col p-6`,children:[(0,I.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,I.jsx)(`h1`,{className:`pb-4 text-xl font-semibold text-gray-900 dark:text-gray-100`,children:`Mocked Example`}),(0,I.jsx)(`button`,{onClick:()=>de(e=>e+1),className:`rounded-md bg-sky-700 px-3 py-2 text-sm font-semibold text-white hover:bg-sky-600`,children:`Regenerate`})]}),fe.status===`loading`?(0,I.jsx)(`div`,{className:`mb-4`,children:(0,I.jsxs)(`span`,{children:[`Loading...`,(0,I.jsx)(`span`,{children:` `})]})}):null,fe.status===`ready`?(0,I.jsxs)(`div`,{className:`flex h-full flex-col space-y-2`,children:[(0,I.jsx)(`div`,{className:`h-1/2 grow border border-zinc-300 dark:border-zinc-600`,children:(0,I.jsx)(sm,{id:`requestExample`,readOnly:!0,json:fe.value.request,allowLinks:!1,filename:`requestExample.json`,ariaLabel:`requestExample`,minimap:!1},`${ge}:request`)}),(0,I.jsx)(`div`,{className:`ml-4 shrink`,children:(0,I.jsx)(`span`,{className:`text-3xl text-emerald-500`,children:`→`})}),(0,I.jsx)(`div`,{className:`h-1/2 grow border border-zinc-300 dark:border-zinc-600`,children:(0,I.jsx)(sm,{id:`responseExample`,readOnly:!0,json:fe.value.response,allowLinks:!1,filename:`responseExample.json`,ariaLabel:`responseExample`,lineNumbers:!1,minimap:!1},`${ge}:response`)})]}):null]})}):null,b.includes(`t`)?(0,I.jsx)(`div`,{className:`flex h-[calc(100vh-4em)] ${lK(b,`t`,b.length)}`,children:(0,I.jsxs)(`div`,{className:`flex w-full flex-col bg-zinc-100 p-6 dark:bg-zinc-700`,children:[(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(`h1`,{className:`pb-4 text-xl font-semibold text-gray-900 dark:text-gray-100`,children:`Request`}),(0,I.jsx)(`div`,{children:(0,I.jsx)(`button`,{onClick:le,disabled:a.status===`loading`,className:`rounded-md px-3 py-2 text-sm font-semibold ${a.status===`loading`?`cursor-not-allowed bg-sky-600/40 text-gray-500 dark:text-gray-300`:`bg-sky-700 text-white active:bg-sky-800`}`,children:te})})]}),(0,I.jsx)(`div`,{className:`grow border border-zinc-300 dark:border-zinc-600`,children:(0,I.jsx)(sm,{id:`request`,readOnly:!1,json:Kp(w,g),ctrlEnter:le,filename:`request.json`,ariaLabel:`request`,ref:se},w??``)})]})}):null,b.includes(`r`)?(0,I.jsx)(`div`,{className:`flex h-[calc(100vh-4em)] ${lK(b,`r`,b.length)}`,children:r?(0,I.jsxs)(`div`,{className:`flex w-full flex-col bg-zinc-100 p-6 dark:bg-zinc-700`,children:[(0,I.jsx)(`h1`,{className:`mb-4 text-xl font-semibold text-gray-900 dark:text-gray-100`,children:`Response`}),a.status===`loading`?(0,I.jsx)(`div`,{className:`grid h-full w-full place-content-center`,children:(0,I.jsx)(`div`,{children:(0,I.jsxs)(`span`,{children:[`Loading...`,(0,I.jsx)(`span`,{children:` `})]})})}):null,a.status===`ready`?(0,I.jsx)(`div`,{className:`grow border border-zinc-300 dark:border-zinc-600`,children:(0,I.jsx)(sm,{id:`response`,readOnly:!0,json:a.value,allowLinks:!0,filename:`response.json`,ariaLabel:`response`},a.value)}):null,a.status===`error`?(0,I.jsx)(`div`,{className:`h-full rounded-md border border-red-300 bg-red-100 p-4 text-red-700 dark:border-red-700 dark:bg-red-500/20 dark:text-red-500`,children:(0,I.jsx)(`div`,{className:`overflow-scroll`,children:(0,I.jsx)(`span`,{children:String(a.error)})})}):null]}):(0,I.jsx)(`div`,{className:`grid h-full w-full place-content-center`,children:(0,I.jsx)(`div`,{children:(0,I.jsx)(`span`,{children:`Click "Submit" on Request pane to fetch response.`})})})}):null]}):null]})]})}var dK=document.getElementById(`app-root`);if(!dK)throw Error(`Missing #app-root`);E.createRoot(dK).render((0,I.jsx)(T.StrictMode,{children:(0,I.jsx)(uK,{})}));
package/build/index.html CHANGED
@@ -23,7 +23,7 @@
23
23
  <meta name="viewport" content="width=device-width, initial-scale=1" />
24
24
  <script src="./theme-bootstrap.js"></script>
25
25
  <script type="module" src="./override.js"></script>
26
- <script type="module" crossorigin src="./assets/index-DOD1AP_F.js"></script>
26
+ <script type="module" crossorigin src="./assets/index-BKx4rM__.js"></script>
27
27
  <link rel="modulepreload" crossorigin href="./assets/editor.api2-lTxZTfFP.js">
28
28
  <link rel="modulepreload" crossorigin href="./assets/monaco.contribution-CHTVlZuL.js">
29
29
  <link rel="modulepreload" crossorigin href="./assets/workers-BeqnF4UC.js">
package/cli.js CHANGED
@@ -17,17 +17,21 @@
17
17
  //|
18
18
 
19
19
  import express from 'express';
20
+ import http from 'http';
20
21
  import { fileURLToPath } from 'url';
21
22
  import { dirname, resolve } from 'path';
22
23
  import { Command } from 'commander';
24
+ import { createProxyMiddleware } from 'http-proxy-middleware';
23
25
 
24
26
  const program = new Command();
25
27
 
26
28
  program
27
- .description('The Telepact Console is a web-based interface for inspecting and testing Telepact APIs.')
28
- .option('-p, --port <number>', 'port number', process.env.PORT || '4173')
29
- .option('-d, --debug', 'enable additional logging', false)
30
- .parse(process.argv);
29
+ .description(
30
+ 'The Telepact Console is a web-based interface for inspecting and testing Telepact APIs.'
31
+ )
32
+ .option('-p, --port <number>', 'port number', process.env.PORT || '4173')
33
+ .option('-d, --debug', 'enable additional logging', false)
34
+ .parse(process.argv);
31
35
 
32
36
  const options = program.opts();
33
37
  const port = parseInt(options.port, 10);
@@ -37,24 +41,161 @@ const __dirname = dirname(__filename);
37
41
 
38
42
  const PORT = port;
39
43
  const BUILD_DIR = resolve(__dirname, 'build');
44
+ const PROXY_HTTP_PATH = '/__telepact_proxy/http';
45
+ const PROXY_WS_PATH = '/__telepact_proxy/ws';
46
+ const proxyTargetSymbol = Symbol('telepactProxyTarget');
40
47
 
41
48
  const app = express();
42
49
 
43
- app.use('/', express.static(BUILD_DIR, {
44
- fallthrough: false
45
- }));
50
+ function parseTargetUrl(rawValue, protocols) {
51
+ if (typeof rawValue !== 'string') {
52
+ return null;
53
+ }
54
+
55
+ const value = rawValue.trim();
56
+ if (value === '') {
57
+ return null;
58
+ }
59
+
60
+ try {
61
+ const targetUrl = new URL(value);
62
+ if (!protocols.includes(targetUrl.protocol)) {
63
+ return null;
64
+ }
65
+ return targetUrl;
66
+ } catch {
67
+ return null;
68
+ }
69
+ }
70
+
71
+ function getTargetUrl(req, protocols) {
72
+ return parseTargetUrl(req.query.target, protocols);
73
+ }
74
+
75
+ function getProxyPath(req) {
76
+ const targetUrl = req[proxyTargetSymbol];
77
+ const path = `${targetUrl.pathname}${targetUrl.search}`;
78
+ return path || '/';
79
+ }
80
+
81
+ function setProxyTarget(req, res, next, protocols) {
82
+ const targetUrl = getTargetUrl(req, protocols);
83
+
84
+ if (!targetUrl) {
85
+ res.status(400).send('Invalid target URL');
86
+ return;
87
+ }
88
+
89
+ req[proxyTargetSymbol] = targetUrl;
90
+
91
+ if (options.debug) {
92
+ console.log(`Proxying ${req.method} ${req.originalUrl} -> ${targetUrl.toString()}`);
93
+ }
94
+
95
+ next();
96
+ }
97
+
98
+ function writeUpgradeError(socket, statusCode, reasonPhrase, message) {
99
+ socket.write(
100
+ `HTTP/1.1 ${statusCode} ${reasonPhrase}\r\n` +
101
+ 'Connection: close\r\n' +
102
+ 'Content-Type: text/plain\r\n' +
103
+ `\r\n${message}`
104
+ );
105
+ socket.destroy();
106
+ }
107
+
108
+ const httpProxy = createProxyMiddleware({
109
+ target: 'http://127.0.0.1',
110
+ changeOrigin: true,
111
+ router: (req) => req[proxyTargetSymbol].origin,
112
+ pathRewrite: (_, req) => getProxyPath(req),
113
+ on: {
114
+ error(err, req, res) {
115
+ if (options.debug) {
116
+ console.error('HTTP proxy failed:', err);
117
+ }
118
+ if (!res.headersSent) {
119
+ res.writeHead(502, { 'Content-Type': 'text/plain' });
120
+ }
121
+ res.end(`Proxy request failed: ${err.message}`);
122
+ }
123
+ }
124
+ });
125
+
126
+ const wsProxy = createProxyMiddleware({
127
+ target: 'ws://127.0.0.1',
128
+ changeOrigin: true,
129
+ ws: true,
130
+ router: (req) => req[proxyTargetSymbol].origin,
131
+ pathRewrite: (_, req) => getProxyPath(req),
132
+ on: {
133
+ error(err) {
134
+ if (options.debug) {
135
+ console.error('WebSocket proxy failed:', err);
136
+ }
137
+ }
138
+ }
139
+ });
140
+
141
+ app.get('/override.js', (_req, res) => {
142
+ res.type('application/javascript');
143
+ res.setHeader('Cache-Control', 'no-store');
144
+ res.send(
145
+ `window.telepactConsoleProxy = ${JSON.stringify({
146
+ httpPath: PROXY_HTTP_PATH,
147
+ wsPath: PROXY_WS_PATH
148
+ })};\n`
149
+ );
150
+ });
151
+
152
+ app.use(PROXY_HTTP_PATH, (req, res, next) => setProxyTarget(req, res, next, ['http:', 'https:']));
153
+ app.use(PROXY_HTTP_PATH, httpProxy);
154
+
155
+ app.use(
156
+ '/',
157
+ express.static(BUILD_DIR, {
158
+ fallthrough: false
159
+ })
160
+ );
46
161
 
47
162
  app.use((err, req, res, next) => {
48
- if (err.code === 'ENOENT') {
49
- if (options.debug) {
50
- console.error(`File not found: ${req.path}`);
51
- }
52
- res.status(404).send('Not Found');
53
- } else {
54
- next(err);
55
- }
163
+ if (err.code === 'ENOENT') {
164
+ if (options.debug) {
165
+ console.error(`File not found: ${req.path}`);
166
+ }
167
+ res.status(404).send('Not Found');
168
+ } else {
169
+ next(err);
170
+ }
171
+ });
172
+
173
+ const server = http.createServer(app);
174
+
175
+ server.on('upgrade', (req, socket, head) => {
176
+ const requestUrl = req.url ?? '';
177
+ if (!requestUrl.startsWith(PROXY_WS_PATH)) {
178
+ return;
179
+ }
180
+
181
+ const host = req.headers.host ?? `localhost:${PORT}`;
182
+ const parsedUrl = new URL(requestUrl, `http://${host}`);
183
+ const targetUrl = parseTargetUrl(parsedUrl.searchParams.get('target'), ['ws:', 'wss:']);
184
+
185
+ if (!targetUrl) {
186
+ writeUpgradeError(socket, 400, 'Bad Request', 'Invalid target URL');
187
+ return;
188
+ }
189
+
190
+ req[proxyTargetSymbol] = targetUrl;
191
+
192
+ if (options.debug) {
193
+ console.log(`Proxying WS ${requestUrl} -> ${targetUrl.toString()}`);
194
+ }
195
+
196
+ wsProxy.upgrade(req, socket, head);
56
197
  });
57
198
 
58
- app.listen(PORT, () => {
59
- console.log(`Server running. Access at http://localhost:${PORT}`);
199
+ server.listen(PORT, () => {
200
+ console.log(`Server running. Access at http://localhost:${PORT}`);
60
201
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "telepact-console",
3
- "version": "1.0.0-alpha.270",
3
+ "version": "1.0.0-alpha.289",
4
4
  "description": "A web-based interface for inspecting and testing Telepact APIs.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -44,7 +44,6 @@
44
44
  "@types/react-dom": "^19.0.5",
45
45
  "@vitejs/plugin-react": "^6.0.1",
46
46
  "autoprefixer": "^10.4.17",
47
- "http-proxy-middleware": "^3.0.3",
48
47
  "jsdom": "^29.0.0",
49
48
  "postcss": "^8.5.6",
50
49
  "prettier-plugin-tailwindcss": "^0.7.1",
@@ -60,6 +59,7 @@
60
59
  "crc-32": "^1.2.2",
61
60
  "dompurify": "^3.2.7",
62
61
  "express": "^5.1.0",
62
+ "http-proxy-middleware": "^3.0.3",
63
63
  "marked": "^17.0.0",
64
64
  "monaco-editor": "^0.55.1",
65
65
  "msgpackr": "^1.11.5",