vibe64 0.1.65 → 0.1.66
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/bin/run.js +823 -820
- package/bin/server.js +200 -197
- package/bin/upgrade-state.js +4181 -4054
- package/dist/assets/{GithubBrowserTabs-D21Nl3QI.js → GithubBrowserTabs-Bf5z_PiF.js} +1 -1
- package/dist/assets/{LocalDatabaseServer-POxY1K1U.js → LocalDatabaseServer-CcfGbn7H.js} +1 -1
- package/dist/assets/{SelectField-Dezd0B3y.js → SelectField-Df50ZFLj.js} +1 -1
- package/dist/assets/{ShellOutlet-DfF9vsWA.js → ShellOutlet-DPyl05um.js} +1 -1
- package/dist/assets/{Vibe64AuthSettingsButton-I3ufyScN.js → Vibe64AuthSettingsButton-CxJoeOhz.js} +1 -1
- package/dist/assets/{Vibe64ConversationLog-C04oOQ2g.js → Vibe64ConversationLog-jDb_ZvIF.js} +1 -1
- package/dist/assets/{Vibe64DashboardShell-BbrOUmRD.js → Vibe64DashboardShell-Ce1PNB37.js} +1 -1
- package/dist/assets/{Vibe64DatabaseWorkspace-VPEM2o1v.js → Vibe64DatabaseWorkspace-DiZDKEpx.js} +1 -1
- package/dist/assets/{Vibe64FileArea-C_nC2bPk.js → Vibe64FileArea-uRnIJ0Vp.js} +1 -1
- package/dist/assets/{Vibe64OutputControls-DTO3Fw3x.js → Vibe64OutputControls-BF5kh2_h.js} +1 -1
- package/dist/assets/{Vibe64RepositoryWorkspace-B8xcCOvL.js → Vibe64RepositoryWorkspace-D6uJCype.js} +1 -1
- package/dist/assets/{Vibe64SessionFiles-Cb9Mxsyq.js → Vibe64SessionFiles-CxgPB8RR.js} +1 -1
- package/dist/assets/{Vibe64SessionSourceEditor-CVQ3NRjh.js → Vibe64SessionSourceEditor-yaVu279S.js} +1 -1
- package/dist/assets/{Vibe64UiStoryboardView-BV4JFgcZ.js → Vibe64UiStoryboardView-DhbHkz8K.js} +1 -1
- package/dist/assets/{Vibe64UnavailableSessions-DGQAxYE-.js → Vibe64UnavailableSessions-MmPF-Db1.js} +1 -1
- package/dist/assets/{_pageId_-CkG15vv4.js → _pageId_-Zif-veil.js} +1 -1
- package/dist/assets/{_sessionId_-Bka3RUmK.js → _sessionId_-DOge-7SB.js} +1 -1
- package/dist/assets/_slug_-C71iAiR0.js +14 -0
- package/dist/assets/_slug_-CF1TPDUv.css +1 -0
- package/dist/assets/{access-Xo3unxGO.js → access-DQcblrWN.js} +1 -1
- package/dist/assets/{app-B0spNegd.js → app-CzApKPmq.js} +1 -1
- package/dist/assets/assistantRouting-CqIiQy21.js +3 -0
- package/dist/assets/{changes-DFv4tuoO.js → changes-cmlEyHug.js} +1 -1
- package/dist/assets/{client-CVuXqm4b.js → client-13v_yX07.js} +1 -1
- package/dist/assets/{client-BjMjS6lX.js → client-5JUUGxRd.js} +2 -2
- package/dist/assets/{client-4uCr4dYG.js → client-BJBzomgt.js} +1 -1
- package/dist/assets/{client-DR0w56e8.js → client-C8ZjqGdQ.js} +2 -2
- package/dist/assets/{client-Dlg1kjjO.js → client-Dl6I6IVb.js} +1 -1
- package/dist/assets/{client-CevjVK2b.js → client-Dv4scw6i.js} +1 -1
- package/dist/assets/{conversation-OkWbkHjm.js → conversation-CFJRkeTj.js} +3 -3
- package/dist/assets/{conversation-DReMq0MF.css → conversation-COcuIkcD.css} +1 -1
- package/dist/assets/conversation-CexAK3Qk.js +1 -0
- package/dist/assets/{dashboard-CAca9MQn.js → dashboard-Dm_xwwqU.js} +1 -1
- package/dist/assets/{english-definitions-BtX8KA5g.js → english-definitions-DwTf_alg.js} +1 -1
- package/dist/assets/{env-DrNyBVkB.js → env-B7wB5nBn.js} +1 -1
- package/dist/assets/{error-BQ7r64JO.js → error-CtOws2EC.js} +1 -1
- package/dist/assets/{error-BqMxhgpB.js → error-HfzrYwkQ.js} +1 -1
- package/dist/assets/{errorMessageHelpers-B49LyMJi.js → errorMessageHelpers-G32Hjqfm.js} +1 -1
- package/dist/assets/{health-B5yTW5Tt.js → health-DIkOkzPe.js} +1 -1
- package/dist/assets/{history-S3anp6xg.js → history-Ch597NiY.js} +1 -1
- package/dist/assets/{httpClient-Bwitq9Xf.js → httpClient-C71X5grL.js} +1 -1
- package/dist/assets/{i18n-BuXRXGaO.js → i18n-5EHeMSvt.js} +1 -1
- package/dist/assets/{i18n-DQPYjuW7.js → i18n-BSfPKqM3.js} +1 -1
- package/dist/assets/{i18n-Dm74yE_M.js → i18n-DcNQE3tT.js} +1 -1
- package/dist/assets/index-C-6c5Af1.css +1 -0
- package/dist/assets/{index-JBqyg0mr.js → index-DcKFCaBZ.js} +4 -4
- package/dist/assets/{integrations-C7dj7el_.js → integrations-CoNhnGvq.js} +1 -1
- package/dist/assets/{issues-OkV4v4GX.js → issues-Cem4Yt47.js} +1 -1
- package/dist/assets/{learning-lW9nBGjT.js → learning-CU2QyHrj.js} +1 -1
- package/dist/assets/{pages-shOT9IVe.js → pages-BzA58NoR.js} +1 -1
- package/dist/assets/{project-files-D_K1N0JF.js → project-files-BBKjl3wZ.js} +1 -1
- package/dist/assets/{publish-Bxe4ZCqe.js → publish-UFjblZA3.js} +1 -1
- package/dist/assets/{pull-requests-CQvk0TeH.js → pull-requests-DibGk1GB.js} +1 -1
- package/dist/assets/{repository-CI2CqDwF.js → repository-0EKOcyTL.js} +1 -1
- package/dist/assets/{settings-DIVrFrs4.js → settings-BjOnPYwD.js} +1 -1
- package/dist/assets/{studioGateApi-UqmdV50W.js → studioGateApi-B9EUTtMx.js} +1 -1
- package/dist/assets/{studioUrls-k_pQIuPs.js → studioUrls-BR4ZL-TN.js} +1 -1
- package/dist/assets/{useArchivedVibe64Sessions-BkWrTOzg.js → useArchivedVibe64Sessions-CXKRFR2f.js} +1 -1
- package/dist/assets/useAssistantAttachments-C9kAnWqw.js +2 -0
- package/dist/assets/useCommand-yOr3U8KF.js +1 -0
- package/dist/assets/{useEndpointResource-DZTjr9gg.js → useEndpointResource-BwGXpV2u.js} +1 -1
- package/dist/assets/{useUiFeedback-BU4NyMq8.js → useUiFeedback--0dLsslR.js} +1 -1
- package/dist/assets/{useVibe64ConversationLog-BADhWyNY.js → useVibe64ConversationLog-BB5tVtkt.js} +2 -2
- package/dist/assets/{useVibe64Learning-CbsI-XHB.js → useVibe64Learning-iAAH83uG.js} +1 -1
- package/dist/assets/{useVibe64SessionData-DvFvAJC-.js → useVibe64SessionData-BSYF_TgH.js} +1 -1
- package/dist/assets/{useVibe64SessionSelection-BukDTAxb.js → useVibe64SessionSelection-CxZ3uEAf.js} +1 -1
- package/dist/assets/{vibe64FileUpload-BDkcaUyk.js → vibe64FileUpload-D_rOa1R8.js} +1 -1
- package/dist/assets/{vibe64RepositoryRealtime-DX2DEqIz.js → vibe64RepositoryRealtime-CVGNqwxz.js} +1 -1
- package/dist/assets/{vibe64SessionFocus-CzuP3qPT.js → vibe64SessionFocus-DGSVXipO.js} +1 -1
- package/dist/index.html +23 -23
- package/docs/colleague-usage/ai-tasks.md +2 -1
- package/docs/colleague-usage/auto-workflow.md +6 -3
- package/docs/colleague-usage/coding-agent-goal-pause.md +34 -12
- package/docs/colleague-usage/coding-agent-goals.md +33 -16
- package/docs/colleague-usage/coding-agent-questions.md +7 -0
- package/docs/colleague-usage/connected-repositories.md +4 -1
- package/docs/colleague-usage/github-work.md +36 -3
- package/docs/colleague-usage/passes.md +86 -0
- package/docs/colleague-usage/ui-pass.md +4 -0
- package/docs/colleague-usage/workspace-preparation.md +51 -0
- package/node_modules/@jskit-ai/assistant-core/CHANGELOG.md +8 -0
- package/node_modules/@jskit-ai/assistant-core/locales/en.json +2 -0
- package/node_modules/@jskit-ai/assistant-core/package.json +1 -1
- package/node_modules/@jskit-ai/assistant-runtime/CHANGELOG.md +2 -0
- package/node_modules/@jskit-ai/assistant-runtime/package.json +1 -1
- package/node_modules/@jskit-ai/assistant-voice/package.json +1 -1
- package/node_modules/@jskit-ai/connector-google-calendar/package.json +1 -1
- package/node_modules/@jskit-ai/connectors-catalog/package.json +1 -1
- package/node_modules/@jskit-ai/connectors-core/package.json +1 -1
- package/node_modules/@jskit-ai/http-runtime/CHANGELOG.md +1 -0
- package/node_modules/@jskit-ai/http-runtime/package.json +1 -1
- package/node_modules/@jskit-ai/kernel/CHANGELOG.md +5 -0
- package/node_modules/@jskit-ai/kernel/package.json +1 -1
- package/node_modules/@jskit-ai/payments-core/package.json +1 -1
- package/node_modules/@jskit-ai/realtime/package.json +1 -1
- package/node_modules/@jskit-ai/resource-core/package.json +1 -1
- package/node_modules/@jskit-ai/uploads-runtime/package.json +1 -1
- package/node_modules/@local/vibe64-genesis/bin/vibe64-genesis-host-context +914 -773
- package/node_modules/@local/vibe64-genesis/src/server/agentSpecs.js +69 -63
- package/node_modules/@local/vibe64-genesis/src/server/index.js +450 -440
- package/node_modules/@local/vibe64-genesis/src/server/packaging.js +27 -28
- package/node_modules/@local/vibe64-genesis/src/server/promptContext.js +63 -55
- package/node_modules/@local/vibe64-runtime/src/server/codexAppServerProcess.js +1044 -901
- package/node_modules/@local/vibe64-terminals/src/server/opencodeSessionEnvironmentPlugin.js +560 -420
- package/node_modules/@local/vibe64-terminals/src/server/sessionWorkOperationCommand.js +453 -450
- package/package.json +15 -15
- package/server.bundle.mjs +42018 -41710
- package/dist/assets/_slug_-7Oo7pGKn.js +0 -14
- package/dist/assets/_slug_-BaxjtsgP.css +0 -1
- package/dist/assets/assistantRouting-B9cub38g.js +0 -3
- package/dist/assets/conversation-D7T_us2O.js +0 -1
- package/dist/assets/index-DSyb-mRJ.css +0 -1
- package/dist/assets/useAssistantAttachments-DqlNFiha.js +0 -2
- package/dist/assets/useCommand-D-MIMmhp.js +0 -1
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __vibe64CreateRequire } from 'node:module';const require=__vibe64CreateRequire(import.meta.url);
|
|
3
|
-
var
|
|
4
|
-
if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var
|
|
5
|
-
enumerable:!(r=
|
|
6
|
-
exports={BINARY_TYPES:
|
|
3
|
+
var Ka=Object.create;var To=Object.defineProperty;var Ja=Object.getOwnPropertyDescriptor;var Xa=Object.getOwnPropertyNames;var Ya=Object.getPrototypeOf,Za=Object.prototype.hasOwnProperty;var U=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){
|
|
4
|
+
if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var X=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(n){throw e=0,n}};var Qa=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Xa(e))!Za.call(t,o)&&o!==n&&To(t,o,{get:()=>e[o],
|
|
5
|
+
enumerable:!(r=Ja(e,o))||r.enumerable});return t};var me=(t,e,n)=>(n=t!=null?Ka(Ya(t)):{},Qa(e||!t||!t.__esModule?To(n,"default",{value:t,enumerable:!0}):n,t));var ae=X((Vh,Po)=>{"use strict";var Oo=["nodebuffer","arraybuffer","fragments"],Ro=typeof Blob<"u";Ro&&Oo.push("blob");Po.
|
|
6
|
+
exports={BINARY_TYPES:Oo,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:Ro,
|
|
7
7
|
kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol(
|
|
8
|
-
"websocket"),NOOP:()=>{}}});var
|
|
8
|
+
"websocket"),NOOP:()=>{}}});var ot=X((Gh,Mt)=>{"use strict";var{EMPTY_BUFFER:mc}=ae(),Er=Buffer[Symbol.species];function hc(t,e){if(t.length===0)return mc;
|
|
9
9
|
if(t.length===1)return t[0];let n=Buffer.allocUnsafe(e),r=0;for(let o=0;o<t.length;o++){let s=t[o];n.set(s,r),r+=s.length}
|
|
10
|
-
return r<e?new
|
|
11
|
-
for(let n=0;n<t.length;n++)t[n]^=e[n&3]}function
|
|
12
|
-
t.byteOffset+t.length)}function
|
|
13
|
-
e=new
|
|
14
|
-
{concat:
|
|
15
|
-
exports.mask=function(e,n,r,o,s){s<48?
|
|
16
|
-
n):t.unmask(e,n)}}catch{}});var
|
|
17
|
-
this[
|
|
18
|
-
this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[
|
|
19
|
-
from([0,0,255,255]),
|
|
20
|
-
|
|
10
|
+
return r<e?new Er(n.buffer,n.byteOffset,r):n}function ko(t,e,n,r,o){for(let s=0;s<o;s++)n[r+s]=t[s]^e[s&3]}function No(t,e){
|
|
11
|
+
for(let n=0;n<t.length;n++)t[n]^=e[n&3]}function gc(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,
|
|
12
|
+
t.byteOffset+t.length)}function Or(t){if(Or.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?
|
|
13
|
+
e=new Er(t):ArrayBuffer.isView(t)?e=new Er(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),Or.readOnly=!1),e}Mt.exports=
|
|
14
|
+
{concat:hc,mask:ko,toArrayBuffer:gc,toBuffer:Or,unmask:No};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=U("bufferutil");Mt.
|
|
15
|
+
exports.mask=function(e,n,r,o,s){s<48?ko(e,n,r,o,s):t.mask(e,n,r,o,s)},Mt.exports.unmask=function(e,n){e.length<32?No(e,
|
|
16
|
+
n):t.unmask(e,n)}}catch{}});var Do=X((Wh,jo)=>{"use strict";var Mo=Symbol("kDone"),Rr=Symbol("kRun"),Pr=class{constructor(e){this[Mo]=()=>{this.pending--,
|
|
17
|
+
this[Rr]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[Rr]()}[Rr](){if(this.pending!==
|
|
18
|
+
this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[Mo])}}};jo.exports=Pr});var De=X((Kh,Fo)=>{"use strict";var st=U("zlib"),zo=ot(),vc=Do(),{kStatusCode:Lo}=ae(),wc=Buffer[Symbol.species],yc=Buffer.
|
|
19
|
+
from([0,0,255,255]),Dt=Symbol("permessage-deflate"),ce=Symbol("total-length"),Me=Symbol("callback"),ge=Symbol("buffers"),
|
|
20
|
+
je=Symbol("error"),jt,kr=class{constructor(e){if(this._options=e||{},this._threshold=this._options.threshold!==void 0?this.
|
|
21
21
|
_options.threshold:1024,this._maxPayload=this._options.maxPayload|0,this._isServer=!!this._options.isServer,this._deflate=
|
|
22
|
-
null,this._inflate=null,this.params=null,!
|
|
23
|
-
10;
|
|
22
|
+
null,this._inflate=null,this.params=null,!jt){let n=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:
|
|
23
|
+
10;jt=new vc(n)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&
|
|
24
24
|
(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.
|
|
25
25
|
serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=
|
|
26
26
|
this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=
|
|
27
27
|
this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this.
|
|
28
|
-
_inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[
|
|
28
|
+
_inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[Me];this._deflate.close(),this._deflate=
|
|
29
29
|
null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let n=this._options,
|
|
30
30
|
r=e.find(o=>!(n.serverNoContextTakeover===!1&&o.server_no_context_takeover||o.server_max_window_bits&&(n.serverMaxWindowBits===
|
|
31
31
|
!1||typeof n.serverMaxWindowBits=="number"&&n.serverMaxWindowBits>o.server_max_window_bits)||typeof n.clientMaxWindowBits==
|
|
@@ -44,53 +44,53 @@ y a single value`);if(o=o[0],r==="client_max_window_bits"){if(o!==!0){let s=+o;i
|
|
|
44
44
|
"${r}": ${o}`)}else if(r==="server_max_window_bits"){let s=+o;if(!Number.isInteger(s)||s<8||s>15)throw new TypeError(`I\
|
|
45
45
|
nvalid value for parameter "${r}": ${o}`);o=s}else if(r==="client_no_context_takeover"||r==="server_no_context_takeover"){
|
|
46
46
|
if(o!==!0)throw new TypeError(`Invalid value for parameter "${r}": ${o}`)}else throw new Error(`Unknown parameter "${r}"`);
|
|
47
|
-
n[r]=o})}),e}decompress(e,n,r){
|
|
47
|
+
n[r]=o})}),e}decompress(e,n,r){jt.add(o=>{this._decompress(e,n,(s,i)=>{o(),r(s,i)})})}compress(e,n,r){jt.add(o=>{this._compress(
|
|
48
48
|
e,n,(s,i)=>{o(),r(s,i)})})}_decompress(e,n,r){let o=this._isServer?"client":"server";if(!this._inflate){let s=`${o}_max_\
|
|
49
|
-
window_bits`,i=typeof this.params[s]!="number"?
|
|
50
|
-
{...this._options.zlibInflateOptions,windowBits:i}),this._inflate[
|
|
51
|
-
_inflate.on("error",
|
|
52
|
-
this._inflate.flush(()=>{let s=this._inflate[
|
|
53
|
-
this._inflate[
|
|
54
|
-
(this._inflate[
|
|
49
|
+
window_bits`,i=typeof this.params[s]!="number"?st.Z_DEFAULT_WINDOWBITS:this.params[s];this._inflate=st.createInflateRaw(
|
|
50
|
+
{...this._options.zlibInflateOptions,windowBits:i}),this._inflate[Dt]=this,this._inflate[ce]=0,this._inflate[ge]=[],this.
|
|
51
|
+
_inflate.on("error",Sc),this._inflate.on("data",Uo)}this._inflate[Me]=r,this._inflate.write(e),n&&this._inflate.write(yc),
|
|
52
|
+
this._inflate.flush(()=>{let s=this._inflate[je];if(s){this._inflate.close(),this._inflate=null,r(s);return}let i=zo.concat(
|
|
53
|
+
this._inflate[ge],this._inflate[ce]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):
|
|
54
|
+
(this._inflate[ce]=0,this._inflate[ge]=[],n&&this.params[`${o}_no_context_takeover`]&&this._inflate.reset()),r(null,i)})}_compress(e,n,r){
|
|
55
55
|
let o=this._isServer?"server":"client";if(!this._deflate){let s=`${o}_max_window_bits`,i=typeof this.params[s]!="number"?
|
|
56
|
-
|
|
57
|
-
this._deflate[
|
|
58
|
-
flush(
|
|
59
|
-
buffer,s.byteOffset,s.length-4)),this._deflate[
|
|
60
|
-
_context_takeover`]&&this._deflate.reset(),r(null,s)})}};
|
|
61
|
-
function
|
|
62
|
-
new RangeError("Max payload size exceeded"),this[
|
|
63
|
-
"data",
|
|
64
|
-
t)}});var
|
|
56
|
+
st.Z_DEFAULT_WINDOWBITS:this.params[s];this._deflate=st.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:i}),
|
|
57
|
+
this._deflate[ce]=0,this._deflate[ge]=[],this._deflate.on("data",Ic)}this._deflate[Me]=r,this._deflate.write(e),this._deflate.
|
|
58
|
+
flush(st.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let s=zo.concat(this._deflate[ge],this._deflate[ce]);n&&(s=new wc(s.
|
|
59
|
+
buffer,s.byteOffset,s.length-4)),this._deflate[Me]=null,this._deflate[ce]=0,this._deflate[ge]=[],n&&this.params[`${o}_no\
|
|
60
|
+
_context_takeover`]&&this._deflate.reset(),r(null,s)})}};Fo.exports=kr;function Ic(t){this[ge].push(t),this[ce]+=t.length}
|
|
61
|
+
function Uo(t){if(this[ce]+=t.length,this[Dt]._maxPayload<1||this[ce]<=this[Dt]._maxPayload){this[ge].push(t);return}this[je]=
|
|
62
|
+
new RangeError("Max payload size exceeded"),this[je].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[je][Lo]=1009,this.removeListener(
|
|
63
|
+
"data",Uo),this.reset()}function Sc(t){if(this[Dt]._inflate=null,this[je]){this[Me](this[je]);return}t[Lo]=1007,this[Me](
|
|
64
|
+
t)}});var ze=X((Jh,zt)=>{"use strict";var{isUtf8:qo}=U("buffer"),{hasBlob:xc}=ae(),bc=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
65
65
|
0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
|
66
|
-
1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0];function
|
|
67
|
-
1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function
|
|
66
|
+
1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0];function Tc(t){return t>=
|
|
67
|
+
1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function Nr(t){let e=t.length,n=0;for(;n<e;)if((t[n]&128)===
|
|
68
68
|
0)n++;else if((t[n]&224)===192){if(n+1===e||(t[n+1]&192)!==128||(t[n]&254)===192)return!1;n+=2}else if((t[n]&240)===224){
|
|
69
69
|
if(n+2>=e||(t[n+1]&192)!==128||(t[n+2]&192)!==128||t[n]===224&&(t[n+1]&224)===128||t[n]===237&&(t[n+1]&224)===160)return!1;
|
|
70
70
|
n+=3}else if((t[n]&248)===240){if(n+3>=e||(t[n+1]&192)!==128||(t[n+2]&192)!==128||(t[n+3]&192)!==128||t[n]===240&&(t[n+1]&
|
|
71
|
-
240)===128||t[n]===244&&t[n+1]>143||t[n]>244)return!1;n+=4}else return!1;return!0}function
|
|
71
|
+
240)===128||t[n]===244&&t[n+1]>143||t[n]>244)return!1;n+=4}else return!1;return!0}function _c(t){return xc&&typeof t=="o\
|
|
72
72
|
bject"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]===
|
|
73
|
-
"Blob"||t[Symbol.toStringTag]==="File")}
|
|
74
|
-
exports.isValidUTF8=function(t){return t.length<24?
|
|
75
|
-
|
|
76
|
-
{concat:
|
|
77
|
-
|
|
78
|
-
void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||
|
|
73
|
+
"Blob"||t[Symbol.toStringTag]==="File")}zt.exports={isBlob:_c,isValidStatusCode:Tc,isValidUTF8:Nr,tokenChars:bc};if(qo)zt.
|
|
74
|
+
exports.isValidUTF8=function(t){return t.length<24?Nr(t):qo(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=U("utf-8-validate");
|
|
75
|
+
zt.exports.isValidUTF8=function(e){return e.length<32?Nr(e):t(e)}}catch{}});var Lr=X((Xh,Ko)=>{"use strict";var{Writable:Cc}=U("stream"),$o=De(),{BINARY_TYPES:Ac,EMPTY_BUFFER:Bo,kStatusCode:Ec,kWebSocket:Oc}=ae(),
|
|
76
|
+
{concat:Mr,toArrayBuffer:Rc,unmask:Pc}=ot(),{isValidStatusCode:kc,isValidUTF8:Ho}=ze(),Lt=Buffer[Symbol.species],Z=0,Vo=1,
|
|
77
|
+
Go=2,Wo=3,jr=4,Dr=5,Ut=6,zr=class extends Cc{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==
|
|
78
|
+
void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||Ac[0],this._extensions=e.extensions||{},this._isServer=
|
|
79
79
|
!!e.isServer,this._maxBufferedChunks=e.maxBufferedChunks|0,this._maxFragments=e.maxFragments|0,this._maxPayload=e.maxPayload|
|
|
80
|
-
0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[
|
|
80
|
+
0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[Oc]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=
|
|
81
81
|
!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=
|
|
82
|
-
0,this._messageLength=0,this._numFragments=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=
|
|
83
|
-
if(this._opcode===8&&this._state==
|
|
82
|
+
0,this._messageLength=0,this._numFragments=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=Z}_write(e,n,r){
|
|
83
|
+
if(this._opcode===8&&this._state==Z)return r();if(this._maxBufferedChunks>0&&this._buffers.length>=this._maxBufferedChunks){
|
|
84
84
|
r(this.createError(RangeError,"Too many buffered chunks",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS"));return}this._bufferedBytes+=
|
|
85
85
|
e.length,this._buffers.push(e),this.startLoop(r)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this.
|
|
86
|
-
_buffers.shift();if(e<this._buffers[0].length){let r=this._buffers[0];return this._buffers[0]=new
|
|
87
|
-
e,r.length-e),new
|
|
88
|
-
n.set(this._buffers.shift(),o):(n.set(new Uint8Array(r.buffer,r.byteOffset,e),o),this._buffers[0]=new
|
|
89
|
-
e,r.length-e)),e-=r.length}while(e>0);return n}startLoop(e){this._loop=!0;do switch(this._state){case
|
|
90
|
-
break;case
|
|
91
|
-
this.getData(e);break;case
|
|
86
|
+
_buffers.shift();if(e<this._buffers[0].length){let r=this._buffers[0];return this._buffers[0]=new Lt(r.buffer,r.byteOffset+
|
|
87
|
+
e,r.length-e),new Lt(r.buffer,r.byteOffset,e)}let n=Buffer.allocUnsafe(e);do{let r=this._buffers[0],o=n.length-e;e>=r.length?
|
|
88
|
+
n.set(this._buffers.shift(),o):(n.set(new Uint8Array(r.buffer,r.byteOffset,e),o),this._buffers[0]=new Lt(r.buffer,r.byteOffset+
|
|
89
|
+
e,r.length-e)),e-=r.length}while(e>0);return n}startLoop(e){this._loop=!0;do switch(this._state){case Z:this.getInfo(e);
|
|
90
|
+
break;case Vo:this.getPayloadLength16(e);break;case Go:this.getPayloadLength64(e);break;case Wo:this.getMask();break;case jr:
|
|
91
|
+
this.getData(e);break;case Dr:case Ut:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<
|
|
92
92
|
2){this._loop=!1;return}let n=this.consume(2);if((n[0]&48)!==0){let o=this.createError(RangeError,"RSV2 and RSV3 must be\
|
|
93
|
-
clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(o);return}let r=(n[0]&64)===64;if(r&&!this._extensions[
|
|
93
|
+
clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(o);return}let r=(n[0]&64)===64;if(r&&!this._extensions[$o.extensionName]){
|
|
94
94
|
let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(this._fin=(n[0]&
|
|
95
95
|
128)===128,this._opcode=n[0]&15,this._payloadLength=n[1]&127,this._opcode===0){if(r){let o=this.createError(RangeError,"\
|
|
96
96
|
RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(!this._fragmented){let o=this.createError(RangeError,
|
|
@@ -104,760 +104,761 @@ LOAD_LENGTH");e(o);return}}else{let o=this.createError(RangeError,`invalid opcod
|
|
|
104
104
|
ID_OPCODE");e(o);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(n[1]&128)===128,
|
|
105
105
|
this._isServer){if(!this._masked){let o=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(
|
|
106
106
|
o);return}}else if(this._masked){let o=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");
|
|
107
|
-
e(o);return}this._payloadLength===126?this._state=
|
|
107
|
+
e(o);return}this._payloadLength===126?this._state=Vo:this._payloadLength===127?this._state=Go:this.haveLength(e)}getPayloadLength16(e){
|
|
108
108
|
if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){
|
|
109
109
|
if(this._bufferedBytes<8){this._loop=!1;return}let n=this.consume(8),r=n.readUInt32BE(0);if(r>Math.pow(2,21)-1){let o=this.
|
|
110
110
|
createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD\
|
|
111
111
|
_LENGTH");e(o);return}this._payloadLength=r*Math.pow(2,32)+n.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&
|
|
112
112
|
this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>
|
|
113
113
|
0)){let n=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(n);return}
|
|
114
|
-
this._masked?this._state=
|
|
115
|
-
4),this._state=
|
|
114
|
+
this._masked?this._state=Wo:this._state=jr}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(
|
|
115
|
+
4),this._state=jr}getData(e){let n=Bo;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;
|
|
116
116
|
return}n=this.consume(this._payloadLength),this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0&&
|
|
117
|
-
|
|
117
|
+
Pc(n,this._mask)}if(this._opcode>7){this.controlMessage(n,e);return}if(this._maxFragments>0&&++this._numFragments>this._maxFragments){
|
|
118
118
|
let r=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");e(r);return}if(this.
|
|
119
|
-
_compressed){this._state=
|
|
120
|
-
push(n)),this.dataMessage(e)}decompress(e,n){this._extensions[
|
|
119
|
+
_compressed){this._state=Dr,this.decompress(n,e);return}n.length&&(this._messageLength=this._totalPayloadLength,this._fragments.
|
|
120
|
+
push(n)),this.dataMessage(e)}decompress(e,n){this._extensions[$o.extensionName].decompress(e,this._fin,(o,s)=>{if(o)return n(
|
|
121
121
|
o);if(s.length){if(this._messageLength+=s.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let i=this.createError(
|
|
122
122
|
RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");n(i);return}this._fragments.push(s)}
|
|
123
|
-
this.dataMessage(n),this._state===
|
|
123
|
+
this.dataMessage(n),this._state===Z&&this.startLoop(n)})}dataMessage(e){if(!this._fin){this._state=Z;return}let n=this._messageLength,
|
|
124
124
|
r=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._numFragments=0,this._fragments=
|
|
125
|
-
[],this._opcode===2){let o;this._binaryType==="nodebuffer"?o=
|
|
126
|
-
_binaryType==="blob"?o=new Blob(r):o=r,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=
|
|
127
|
-
|
|
128
|
-
!
|
|
129
|
-
this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=
|
|
130
|
-
age",o,!1),this._state=
|
|
131
|
-
emit("conclude",1005,
|
|
132
|
-
tatus code ${r}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");n(s);return}let o=new
|
|
133
|
-
_skipUTF8Validation&&!
|
|
134
|
-
this._loop=!1,this.emit("conclude",r,o),this.end()}this._state=
|
|
135
|
-
9?"ping":"pong",e),this._state=
|
|
136
|
-
|
|
137
|
-
n);return Error.captureStackTrace(i,this.createError),i.code=s,i[
|
|
138
|
-
|
|
139
|
-
"kByteLength")
|
|
125
|
+
[],this._opcode===2){let o;this._binaryType==="nodebuffer"?o=Mr(r,n):this._binaryType==="arraybuffer"?o=Rc(Mr(r,n)):this.
|
|
126
|
+
_binaryType==="blob"?o=new Blob(r):o=r,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=Z):(this._state=
|
|
127
|
+
Ut,setImmediate(()=>{this.emit("message",o,!0),this._state=Z,this.startLoop(e)}))}else{let o=Mr(r,n);if(!this._skipUTF8Validation&&
|
|
128
|
+
!Ho(o)){let s=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(s);return}this._state===Dr||
|
|
129
|
+
this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=Z):(this._state=Ut,setImmediate(()=>{this.emit("mess\
|
|
130
|
+
age",o,!1),this._state=Z,this.startLoop(e)}))}}controlMessage(e,n){if(this._opcode===8){if(e.length===0)this._loop=!1,this.
|
|
131
|
+
emit("conclude",1005,Bo),this.end();else{let r=e.readUInt16BE(0);if(!kc(r)){let s=this.createError(RangeError,`invalid s\
|
|
132
|
+
tatus code ${r}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");n(s);return}let o=new Lt(e.buffer,e.byteOffset+2,e.length-2);if(!this.
|
|
133
|
+
_skipUTF8Validation&&!Ho(o)){let s=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");n(s);return}
|
|
134
|
+
this._loop=!1,this.emit("conclude",r,o),this.end()}this._state=Z;return}this._allowSynchronousEvents?(this.emit(this._opcode===
|
|
135
|
+
9?"ping":"pong",e),this._state=Z):(this._state=Ut,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=
|
|
136
|
+
Z,this.startLoop(n)}))}createError(e,n,r,o,s){this._loop=!1,this._errored=!0;let i=new e(r?`Invalid WebSocket frame: ${n}`:
|
|
137
|
+
n);return Error.captureStackTrace(i,this.createError),i.code=s,i[Ec]=o,i}};Ko.exports=zr});var qr=X((Zh,Yo)=>{"use strict";var{Duplex:Yh}=U("stream"),{randomFillSync:Nc}=U("crypto"),{types:{isUint8Array:Mc}}=U("util"),
|
|
138
|
+
Jo=De(),{EMPTY_BUFFER:jc,kWebSocket:Dc,NOOP:zc}=ae(),{isBlob:Le,isValidStatusCode:Lc}=ze(),{mask:Xo,toBuffer:be}=ot(),Q=Symbol(
|
|
139
|
+
"kByteLength"),Uc=Buffer.alloc(4),Ft=8*1024,Te,Ue=Ft,ne=0,Fc=1,qc=2,Ur=class t{constructor(e,n,r){this._extensions=n||{},
|
|
140
140
|
r&&(this._generateMask=r,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this.
|
|
141
|
-
_bufferedBytes=0,this._queue=[],this._state=
|
|
142
|
-
(r=n.maskBuffer
|
|
143
|
-
|
|
144
|
-
i)&&n[
|
|
141
|
+
_bufferedBytes=0,this._queue=[],this._state=ne,this.onerror=zc,this[Dc]=void 0}static frame(e,n){let r,o=!1,s=2,i=!1;n.mask&&
|
|
142
|
+
(r=n.maskBuffer||Uc,n.generateMask?n.generateMask(r):(Ue===Ft&&(Te===void 0&&(Te=Buffer.alloc(Ft)),Nc(Te,0,Ft),Ue=0),r[0]=
|
|
143
|
+
Te[Ue++],r[1]=Te[Ue++],r[2]=Te[Ue++],r[3]=Te[Ue++]),i=(r[0]|r[1]|r[2]|r[3])===0,s=6);let a;typeof e=="string"?(!n.mask||
|
|
144
|
+
i)&&n[Q]!==void 0?a=n[Q]:(e=Buffer.from(e),a=e.length):(a=e.length,o=n.mask&&n.readOnly&&!i);let c=a;a>=65536?(s+=8,c=127):
|
|
145
145
|
a>125&&(s+=2,c=126);let d=Buffer.allocUnsafe(o?a+s:s);return d[0]=n.fin?n.opcode|128:n.opcode,n.rsv1&&(d[0]|=64),d[1]=c,
|
|
146
146
|
c===126?d.writeUInt16BE(a,2):c===127&&(d[2]=d[3]=0,d.writeUIntBE(a,4,6)),n.mask?(d[1]|=128,d[s-4]=r[0],d[s-3]=r[1],d[s-2]=
|
|
147
|
-
r[2],d[s-1]=r[3],i?[d,e]:o?(
|
|
148
|
-
if(typeof e!="number"||!
|
|
147
|
+
r[2],d[s-1]=r[3],i?[d,e]:o?(Xo(e,r,d,s,a),[d]):(Xo(e,r,e,0,a),[d,e])):[d,e]}close(e,n,r,o){let s;if(e===void 0)s=jc;else{
|
|
148
|
+
if(typeof e!="number"||!Lc(e))throw new TypeError("First argument must be a valid error code number");if(n===void 0||!n.
|
|
149
149
|
length)s=Buffer.allocUnsafe(2),s.writeUInt16BE(e,0);else{let a=Buffer.byteLength(n);if(a>123)throw new RangeError("The m\
|
|
150
150
|
essage must not be greater than 123 bytes");if(s=Buffer.allocUnsafe(2+a),s.writeUInt16BE(e,0),typeof n=="string")s.write(
|
|
151
|
-
n,2);else if(
|
|
151
|
+
n,2);else if(Mc(n))s.set(n,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let i={[Q]:s.
|
|
152
152
|
length,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==
|
|
153
|
-
|
|
154
|
-
byteLength(e),s=!1):
|
|
155
|
-
ust not be greater than 125 bytes");let i={[
|
|
156
|
-
opcode:9,readOnly:s,rsv1:!1};
|
|
157
|
-
this._state!==
|
|
158
|
-
string"?(o=Buffer.byteLength(e),s=!1):
|
|
159
|
-
"The data size must not be greater than 125 bytes");let i={[
|
|
160
|
-
_maskBuffer,opcode:10,readOnly:s,rsv1:!1};
|
|
161
|
-
e,!1,i,r):this._state!==
|
|
162
|
-
extensionName],s=n.binary?2:1,i=n.compress,a,c;typeof e=="string"?(a=Buffer.byteLength(e),c=!1):
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
_state!==
|
|
168
|
-
_bufferedBytes+=r[
|
|
169
|
-
closed while the blob was being read");process.nextTick(
|
|
170
|
-
dispatch(i,n,r,o):(this._state=
|
|
171
|
-
if(!n){this.sendFrame(t.frame(e,r),o);return}let s=this._extensions[
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
dequeue()})}dequeue(){for(;this._state===
|
|
175
|
-
Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][
|
|
176
|
-
2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],n),this._socket.uncork()):this._socket.
|
|
177
|
-
n)}};
|
|
178
|
-
length-1];typeof s=="function"&&s(e)}}function
|
|
179
|
-
"kError"),
|
|
180
|
-
this[
|
|
181
|
-
arget",{enumerable:!0});Object.defineProperty(
|
|
182
|
-
super(e),this[
|
|
183
|
-
return this[
|
|
184
|
-
{enumerable:!0});Object.defineProperty(
|
|
185
|
-
an",{enumerable:!0});var
|
|
186
|
-
n.message===void 0?"":n.message}get error(){return this[
|
|
187
|
-
"error",{enumerable:!0});Object.defineProperty(
|
|
188
|
-
super(e),this[
|
|
189
|
-
var
|
|
190
|
-
age")r=function(s,i){let a=new
|
|
191
|
-
let a=new
|
|
192
|
-
e,this,a)};else if(t==="error")r=function(s){let i=new
|
|
193
|
-
"open")r=function(){let s=new
|
|
194
|
-
this.on(t,r)},removeEventListener(t,e){for(let n of this.listeners(t))if(n[
|
|
195
|
-
|
|
196
|
-
t.handleEvent?t.handleEvent.call(t,n):t.call(e,n)}});var
|
|
197
|
-
let e=Object.create(null),n=Object.create(null),r=!1,o=!1,s=!1,i,a,c=-1,d=-1,
|
|
198
|
-
|
|
199
|
-
44){if(c===-1)throw new SyntaxError(`Unexpected character at index ${
|
|
200
|
-
|
|
201
|
-
if(
|
|
202
|
-
`Unexpected character at index ${
|
|
203
|
-
c=
|
|
204
|
-
if(
|
|
205
|
-
1)c===-1&&(c=
|
|
206
|
-
index ${
|
|
207
|
-
d===9))
|
|
208
|
-
(
|
|
209
|
-
void 0,c=
|
|
210
|
-
"Unexpected end of input");
|
|
211
|
-
l.replace(/\\/g,"")):
|
|
153
|
+
ne?this.enqueue([this.dispatch,s,!1,i,o]):this.sendFrame(t.frame(s,i),o)}ping(e,n,r){let o,s;if(typeof e=="string"?(o=Buffer.
|
|
154
|
+
byteLength(e),s=!1):Le(e)?(o=e.size,s=!1):(e=be(e),o=e.length,s=be.readOnly),o>125)throw new RangeError("The data size m\
|
|
155
|
+
ust not be greater than 125 bytes");let i={[Q]:o,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,
|
|
156
|
+
opcode:9,readOnly:s,rsv1:!1};Le(e)?this._state!==ne?this.enqueue([this.getBlobData,e,!1,i,r]):this.getBlobData(e,!1,i,r):
|
|
157
|
+
this._state!==ne?this.enqueue([this.dispatch,e,!1,i,r]):this.sendFrame(t.frame(e,i),r)}pong(e,n,r){let o,s;if(typeof e==
|
|
158
|
+
"string"?(o=Buffer.byteLength(e),s=!1):Le(e)?(o=e.size,s=!1):(e=be(e),o=e.length,s=be.readOnly),o>125)throw new RangeError(
|
|
159
|
+
"The data size must not be greater than 125 bytes");let i={[Q]:o,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this.
|
|
160
|
+
_maskBuffer,opcode:10,readOnly:s,rsv1:!1};Le(e)?this._state!==ne?this.enqueue([this.getBlobData,e,!1,i,r]):this.getBlobData(
|
|
161
|
+
e,!1,i,r):this._state!==ne?this.enqueue([this.dispatch,e,!1,i,r]):this.sendFrame(t.frame(e,i),r)}send(e,n,r){let o=this.
|
|
162
|
+
_extensions[Jo.extensionName],s=n.binary?2:1,i=n.compress,a,c;typeof e=="string"?(a=Buffer.byteLength(e),c=!1):Le(e)?(a=
|
|
163
|
+
e.size,c=!1):(e=be(e),a=e.length,c=be.readOnly),this._firstFragment?(this._firstFragment=!1,i&&o&&o.params[o._isServer?"\
|
|
164
|
+
server_no_context_takeover":"client_no_context_takeover"]&&(i=a>=o._threshold),this._compress=i):(i=!1,s=0),n.fin&&(this.
|
|
165
|
+
_firstFragment=!0);let d={[Q]:a,fin:n.fin,generateMask:this._generateMask,mask:n.mask,maskBuffer:this._maskBuffer,opcode:s,
|
|
166
|
+
readOnly:c,rsv1:i};Le(e)?this._state!==ne?this.enqueue([this.getBlobData,e,this._compress,d,r]):this.getBlobData(e,this.
|
|
167
|
+
_compress,d,r):this._state!==ne?this.enqueue([this.dispatch,e,this._compress,d,r]):this.dispatch(e,this._compress,d,r)}getBlobData(e,n,r,o){
|
|
168
|
+
this._bufferedBytes+=r[Q],this._state=qc,e.arrayBuffer().then(s=>{if(this._socket.destroyed){let a=new Error("The socket\
|
|
169
|
+
was closed while the blob was being read");process.nextTick(Fr,this,a,o);return}this._bufferedBytes-=r[Q];let i=be(s);n?
|
|
170
|
+
this.dispatch(i,n,r,o):(this._state=ne,this.sendFrame(t.frame(i,r),o),this.dequeue())}).catch(s=>{process.nextTick($c,this,
|
|
171
|
+
s,o)})}dispatch(e,n,r,o){if(!n){this.sendFrame(t.frame(e,r),o);return}let s=this._extensions[Jo.extensionName];this._bufferedBytes+=
|
|
172
|
+
r[Q],this._state=Fc,s.compress(e,r.fin,(i,a)=>{if(this._socket.destroyed){let c=new Error("The socket was closed while d\
|
|
173
|
+
ata was being compressed");Fr(this,c,o);return}this._bufferedBytes-=r[Q],this._state=ne,r.readOnly=!1,this.sendFrame(t.frame(
|
|
174
|
+
a,r),o),this.dequeue()})}dequeue(){for(;this._state===ne&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=
|
|
175
|
+
e[3][Q],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][Q],this._queue.push(e)}sendFrame(e,n){
|
|
176
|
+
e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],n),this._socket.uncork()):this._socket.
|
|
177
|
+
write(e[0],n)}};Yo.exports=Ur;function Fr(t,e,n){typeof n=="function"&&n(e);for(let r=0;r<t._queue.length;r++){let o=t._queue[r],
|
|
178
|
+
s=o[o.length-1];typeof s=="function"&&s(e)}}function $c(t,e,n){Fr(t,e,n),t.onerror(e)}});var is=X((Qh,ss)=>{"use strict";var{kForOnEventAttribute:it,kListener:$r}=ae(),Zo=Symbol("kCode"),Qo=Symbol("kData"),es=Symbol(
|
|
179
|
+
"kError"),ts=Symbol("kMessage"),rs=Symbol("kReason"),Fe=Symbol("kTarget"),ns=Symbol("kType"),os=Symbol("kWasClean"),de=class{constructor(e){
|
|
180
|
+
this[Fe]=null,this[ns]=e}get target(){return this[Fe]}get type(){return this[ns]}};Object.defineProperty(de.prototype,"t\
|
|
181
|
+
arget",{enumerable:!0});Object.defineProperty(de.prototype,"type",{enumerable:!0});var _e=class extends de{constructor(e,n={}){
|
|
182
|
+
super(e),this[Zo]=n.code===void 0?0:n.code,this[rs]=n.reason===void 0?"":n.reason,this[os]=n.wasClean===void 0?!1:n.wasClean}get code(){
|
|
183
|
+
return this[Zo]}get reason(){return this[rs]}get wasClean(){return this[os]}};Object.defineProperty(_e.prototype,"code",
|
|
184
|
+
{enumerable:!0});Object.defineProperty(_e.prototype,"reason",{enumerable:!0});Object.defineProperty(_e.prototype,"wasCle\
|
|
185
|
+
an",{enumerable:!0});var qe=class extends de{constructor(e,n={}){super(e),this[es]=n.error===void 0?null:n.error,this[ts]=
|
|
186
|
+
n.message===void 0?"":n.message}get error(){return this[es]}get message(){return this[ts]}};Object.defineProperty(qe.prototype,
|
|
187
|
+
"error",{enumerable:!0});Object.defineProperty(qe.prototype,"message",{enumerable:!0});var at=class extends de{constructor(e,n={}){
|
|
188
|
+
super(e),this[Qo]=n.data===void 0?null:n.data}get data(){return this[Qo]}};Object.defineProperty(at.prototype,"data",{enumerable:!0});
|
|
189
|
+
var Bc={addEventListener(t,e,n={}){for(let o of this.listeners(t))if(!n[it]&&o[$r]===e&&!o[it])return;let r;if(t==="mess\
|
|
190
|
+
age")r=function(s,i){let a=new at("message",{data:i?s:s.toString()});a[Fe]=this,qt(e,this,a)};else if(t==="close")r=function(s,i){
|
|
191
|
+
let a=new _e("close",{code:s,reason:i.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});a[Fe]=this,qt(
|
|
192
|
+
e,this,a)};else if(t==="error")r=function(s){let i=new qe("error",{error:s,message:s.message});i[Fe]=this,qt(e,this,i)};else if(t===
|
|
193
|
+
"open")r=function(){let s=new de("open");s[Fe]=this,qt(e,this,s)};else return;r[it]=!!n[it],r[$r]=e,n.once?this.once(t,r):
|
|
194
|
+
this.on(t,r)},removeEventListener(t,e){for(let n of this.listeners(t))if(n[$r]===e&&!n[it]){this.removeListener(t,n);break}}};
|
|
195
|
+
ss.exports={CloseEvent:_e,ErrorEvent:qe,Event:de,EventTarget:Bc,MessageEvent:at};function qt(t,e,n){typeof t=="object"&&
|
|
196
|
+
t.handleEvent?t.handleEvent.call(t,n):t.call(e,n)}});var $t=X((eg,as)=>{"use strict";var{tokenChars:ct}=ze();function ie(t,e,n){t[e]===void 0?t[e]=[n]:t[e].push(n)}function Hc(t){
|
|
197
|
+
let e=Object.create(null),n=Object.create(null),r=!1,o=!1,s=!1,i,a,c=-1,d=-1,u=-1,f=0;for(;f<t.length;f++)if(d=t.charCodeAt(
|
|
198
|
+
f),i===void 0)if(u===-1&&ct[d]===1)c===-1&&(c=f);else if(f!==0&&(d===32||d===9))u===-1&&c!==-1&&(u=f);else if(d===59||d===
|
|
199
|
+
44){if(c===-1)throw new SyntaxError(`Unexpected character at index ${f}`);u===-1&&(u=f);let g=t.slice(c,u);d===44?(ie(e,
|
|
200
|
+
g,n),n=Object.create(null)):i=g,c=u=-1}else throw new SyntaxError(`Unexpected character at index ${f}`);else if(a===void 0)
|
|
201
|
+
if(u===-1&&ct[d]===1)c===-1&&(c=f);else if(d===32||d===9)u===-1&&c!==-1&&(u=f);else if(d===59||d===44){if(c===-1)throw new SyntaxError(
|
|
202
|
+
`Unexpected character at index ${f}`);u===-1&&(u=f),ie(n,t.slice(c,u),!0),d===44&&(ie(e,i,n),n=Object.create(null),i=void 0),
|
|
203
|
+
c=u=-1}else if(d===61&&c!==-1&&u===-1)a=t.slice(c,f),c=u=-1;else throw new SyntaxError(`Unexpected character at index ${f}`);else if(o){
|
|
204
|
+
if(ct[d]!==1)throw new SyntaxError(`Unexpected character at index ${f}`);c===-1?c=f:r||(r=!0),o=!1}else if(s)if(ct[d]===
|
|
205
|
+
1)c===-1&&(c=f);else if(d===34&&c!==-1)s=!1,u=f;else if(d===92)o=!0;else throw new SyntaxError(`Unexpected character at \
|
|
206
|
+
index ${f}`);else if(d===34&&t.charCodeAt(f-1)===61)s=!0;else if(u===-1&&ct[d]===1)c===-1&&(c=f);else if(c!==-1&&(d===32||
|
|
207
|
+
d===9))u===-1&&(u=f);else if(d===59||d===44){if(c===-1)throw new SyntaxError(`Unexpected character at index ${f}`);u===-1&&
|
|
208
|
+
(u=f);let g=t.slice(c,u);r&&(g=g.replace(/\\/g,""),r=!1),ie(n,a,g),d===44&&(ie(e,i,n),n=Object.create(null),i=void 0),a=
|
|
209
|
+
void 0,c=u=-1}else throw new SyntaxError(`Unexpected character at index ${f}`);if(c===-1||s||d===32||d===9)throw new SyntaxError(
|
|
210
|
+
"Unexpected end of input");u===-1&&(u=f);let l=t.slice(c,u);return i===void 0?ie(e,l,n):(a===void 0?ie(n,l,!0):r?ie(n,a,
|
|
211
|
+
l.replace(/\\/g,"")):ie(n,a,l),ie(e,i,n)),e}function Vc(t){return Object.keys(t).map(e=>{let n=t[e];return Array.isArray(
|
|
212
212
|
n)||(n=[n]),n.map(r=>[e].concat(Object.keys(r).map(o=>{let s=r[o];return Array.isArray(s)||(s=[s]),s.map(i=>i===!0?o:`${o}\
|
|
213
|
-
=${i}`).join("; ")})).join("; ")).join(", ")}).join(", ")}
|
|
214
|
-
{Duplex:
|
|
215
|
-
EMPTY_BUFFER:
|
|
216
|
-
removeEventListener:
|
|
217
|
-
NG","OPEN","CLOSING","CLOSED"],
|
|
218
|
-
_binaryType=
|
|
213
|
+
=${i}`).join("; ")})).join("; ")).join(", ")}).join(", ")}as.exports={format:Vc,parse:Hc}});var Gt=X((ng,ys)=>{"use strict";var Gc=U("events"),Wc=U("https"),Kc=U("http"),us=U("net"),Jc=U("tls"),{randomBytes:Xc,createHash:Yc}=U("crypto"),
|
|
214
|
+
{Duplex:tg,Readable:rg}=U("stream"),{URL:Br}=U("url"),ve=De(),Zc=Lr(),Qc=qr(),{isBlob:ed}=ze(),{BINARY_TYPES:cs,CLOSE_TIMEOUT:td,
|
|
215
|
+
EMPTY_BUFFER:Bt,GUID:rd,kForOnEventAttribute:Hr,kListener:nd,kStatusCode:od,kWebSocket:B,NOOP:ls}=ae(),{EventTarget:{addEventListener:sd,
|
|
216
|
+
removeEventListener:id}}=is(),{format:ad,parse:cd}=$t(),{toBuffer:dd}=ot(),ps=Symbol("kAborted"),Vr=[8,13],ue=["CONNECTI\
|
|
217
|
+
NG","OPEN","CLOSING","CLOSED"],ud=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,j=class t extends Gc{constructor(e,n,r){super(),this.
|
|
218
|
+
_binaryType=cs[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Bt,this._closeTimer=
|
|
219
219
|
null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=
|
|
220
220
|
null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,n===void 0?
|
|
221
|
-
n=[]:Array.isArray(n)||(typeof n=="object"&&n!==null?(r=n,n=[]):n=[n])
|
|
222
|
-
r.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){
|
|
221
|
+
n=[]:Array.isArray(n)||(typeof n=="object"&&n!==null?(r=n,n=[]):n=[n]),fs(this,e,n,r)):(this._autoPong=r.autoPong,this._closeTimeout=
|
|
222
|
+
r.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){cs.includes(e)&&(this._binaryType=
|
|
223
223
|
e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+
|
|
224
224
|
this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){
|
|
225
225
|
return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){
|
|
226
|
-
return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,n,r){let o=new
|
|
226
|
+
return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,n,r){let o=new Zc(
|
|
227
227
|
{allowSynchronousEvents:r.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,
|
|
228
228
|
maxBufferedChunks:r.maxBufferedChunks,maxFragments:r.maxFragments,maxPayload:r.maxPayload,skipUTF8Validation:r.skipUTF8Validation}),
|
|
229
|
-
s=new
|
|
230
|
-
o.on("conclude",
|
|
231
|
-
setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),n.length>0&&e.unshift(n),e.on("close",
|
|
232
|
-
"end",
|
|
233
|
-
this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[
|
|
229
|
+
s=new Qc(e,this._extensions,r.generateMask);this._receiver=o,this._sender=s,this._socket=e,o[B]=this,s[B]=this,e[B]=this,
|
|
230
|
+
o.on("conclude",fd),o.on("drain",md),o.on("error",hd),o.on("message",gd),o.on("ping",vd),o.on("pong",wd),s.onerror=yd,e.
|
|
231
|
+
setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),n.length>0&&e.unshift(n),e.on("close",gs),e.on("data",Vt),e.on(
|
|
232
|
+
"end",vs),e.on("error",ws),this._readyState=t.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=t.CLOSED,
|
|
233
|
+
this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[ve.extensionName]&&this._extensions[ve.extensionName].
|
|
234
234
|
cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,n){
|
|
235
|
-
if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){
|
|
235
|
+
if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){Y(this,this._req,"WebSocket was closed before the conn\
|
|
236
236
|
ection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver.
|
|
237
237
|
_writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,n,!this._isServer,
|
|
238
238
|
r=>{r||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),
|
|
239
|
-
|
|
239
|
+
hs(this)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,n,r){
|
|
240
240
|
if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="func\
|
|
241
241
|
tion"?(r=e,e=n=void 0):typeof n=="function"&&(r=n,n=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){
|
|
242
|
-
|
|
242
|
+
Gr(this,e,r);return}n===void 0&&(n=!this._isServer),this._sender.ping(e||Bt,n,r)}pong(e,n,r){if(this.readyState===t.CONNECTING)
|
|
243
243
|
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(r=e,e=n=void 0):typeof n=="\
|
|
244
|
-
function"&&(r=n,n=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){
|
|
245
|
-
(n=!this._isServer),this._sender.pong(e||
|
|
244
|
+
function"&&(r=n,n=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Gr(this,e,r);return}n===void 0&&
|
|
245
|
+
(n=!this._isServer),this._sender.pong(e||Bt,n,r)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this.
|
|
246
246
|
_paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,n,r){if(this.readyState===t.CONNECTING)
|
|
247
247
|
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof n=="function"&&(r=n,n={}),typeof e=="numbe\
|
|
248
|
-
r"&&(e=e.toString()),this.readyState!==t.OPEN){
|
|
249
|
-
compress:!0,fin:!0,...n};this._extensions[
|
|
250
|
-
readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){
|
|
251
|
-
as established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(
|
|
252
|
-
NNECTING",{enumerable:!0,value:
|
|
253
|
-
value:
|
|
254
|
-
|
|
255
|
-
"CLOSING")});Object.defineProperty(
|
|
256
|
-
|
|
248
|
+
r"&&(e=e.toString()),this.readyState!==t.OPEN){Gr(this,e,r);return}let o={binary:typeof e!="string",mask:!this._isServer,
|
|
249
|
+
compress:!0,fin:!0,...n};this._extensions[ve.extensionName]||(o.compress=!1),this._sender.send(e||Bt,o,r)}terminate(){if(this.
|
|
250
|
+
readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){Y(this,this._req,"WebSocket was closed before the connection w\
|
|
251
|
+
as established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(j,"CO\
|
|
252
|
+
NNECTING",{enumerable:!0,value:ue.indexOf("CONNECTING")});Object.defineProperty(j.prototype,"CONNECTING",{enumerable:!0,
|
|
253
|
+
value:ue.indexOf("CONNECTING")});Object.defineProperty(j,"OPEN",{enumerable:!0,value:ue.indexOf("OPEN")});Object.defineProperty(
|
|
254
|
+
j.prototype,"OPEN",{enumerable:!0,value:ue.indexOf("OPEN")});Object.defineProperty(j,"CLOSING",{enumerable:!0,value:ue.indexOf(
|
|
255
|
+
"CLOSING")});Object.defineProperty(j.prototype,"CLOSING",{enumerable:!0,value:ue.indexOf("CLOSING")});Object.defineProperty(
|
|
256
|
+
j,"CLOSED",{enumerable:!0,value:ue.indexOf("CLOSED")});Object.defineProperty(j.prototype,"CLOSED",{enumerable:!0,value:ue.
|
|
257
257
|
indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.
|
|
258
|
-
defineProperty(
|
|
259
|
-
`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[
|
|
260
|
-
listeners(t))if(n[
|
|
261
|
-
prototype.addEventListener=
|
|
262
|
-
autoPong:!0,closeTimeout:
|
|
258
|
+
defineProperty(j.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(j.prototype,
|
|
259
|
+
`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Hr])return e[nd];return null},set(e){for(let n of this.
|
|
260
|
+
listeners(t))if(n[Hr]){this.removeListener(t,n);break}typeof e=="function"&&this.addEventListener(t,e,{[Hr]:!0})}})});j.
|
|
261
|
+
prototype.addEventListener=sd;j.prototype.removeEventListener=id;ys.exports=j;function fs(t,e,n,r){let o={allowSynchronousEvents:!0,
|
|
262
|
+
autoPong:!0,closeTimeout:td,protocolVersion:Vr[1],maxBufferedChunks:262144,maxFragments:16384,maxPayload:104857600,skipUTF8Validation:!1,
|
|
263
263
|
perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...r,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,
|
|
264
|
-
method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=o.autoPong,t._closeTimeout=o.closeTimeout,!
|
|
265
|
-
o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${
|
|
266
|
-
", ")})`);let s;if(e instanceof
|
|
264
|
+
method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=o.autoPong,t._closeTimeout=o.closeTimeout,!Vr.includes(
|
|
265
|
+
o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${Vr.join(
|
|
266
|
+
", ")})`);let s;if(e instanceof Br)s=e;else try{s=new Br(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}s.protocol===
|
|
267
267
|
"http:"?s.protocol="ws:":s.protocol==="https:"&&(s.protocol="wss:"),t._url=s.href;let i=s.protocol==="wss:",a=s.protocol===
|
|
268
268
|
"ws+unix:",c;if(s.protocol!=="ws:"&&!i&&!a?c=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws\
|
|
269
|
-
+unix:"`:a&&!s.pathname?c="The URL's pathname is empty":s.hash&&(c="The URL contains a fragment identifier"),c){let
|
|
270
|
-
c);if(t._redirects===0)throw
|
|
271
|
-
|
|
269
|
+
+unix:"`:a&&!s.pathname?c="The URL's pathname is empty":s.hash&&(c="The URL contains a fragment identifier"),c){let _=new SyntaxError(
|
|
270
|
+
c);if(t._redirects===0)throw _;Ht(t,_);return}let d=i?443:80,u=Xc(16).toString("base64"),f=i?Wc.request:Kc.request,l=new Set,
|
|
271
|
+
g;if(o.createConnection=o.createConnection||(i?pd:ld),o.defaultPort=o.defaultPort||d,o.port=s.port||d,o.host=s.hostname.
|
|
272
272
|
startsWith("[")?s.hostname.slice(1,-1):s.hostname,o.headers={...o.headers,"Sec-WebSocket-Version":o.protocolVersion,"Sec\
|
|
273
|
-
-WebSocket-Key":
|
|
274
|
-
(
|
|
275
|
-
offer()})),n.length){for(let
|
|
276
|
-
uplicated subprotocol was specified");l.add(
|
|
273
|
+
-WebSocket-Key":u,Connection:"Upgrade",Upgrade:"websocket"},o.path=s.pathname+s.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&
|
|
274
|
+
(g=new ve({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=ad({[ve.extensionName]:g.
|
|
275
|
+
offer()})),n.length){for(let _ of n){if(typeof _!="string"||!ud.test(_)||l.has(_))throw new SyntaxError("An invalid or d\
|
|
276
|
+
uplicated subprotocol was specified");l.add(_)}o.headers["Sec-WebSocket-Protocol"]=n.join(",")}if(o.origin&&(o.protocolVersion<
|
|
277
277
|
13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(s.username||s.password)&&(o.auth=`${s.username}\
|
|
278
|
-
:${s.password}`),a){let
|
|
279
|
-
0){t._originalIpc=a,t._originalSecure=i,t._originalHostOrSocketPath=a?o.socketPath:s.host;let
|
|
280
|
-
headers:{}},
|
|
281
|
-
t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:s.host===t._originalHostOrSocketPath;(!
|
|
282
|
-
t._originalSecure&&!i)&&(delete o.headers.authorization,delete o.headers.cookie,
|
|
283
|
-
o.auth&&!r.headers.authorization&&(r.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),
|
|
284
|
-
t._redirects&&t.emit("redirect",t.url,
|
|
285
|
-
timed out")}),
|
|
286
|
-
statusCode;if(
|
|
287
|
-
return}
|
|
288
|
-
t.emit("unexpected-response",
|
|
289
|
-
emit("upgrade",
|
|
290
|
-
"websocket"){
|
|
291
|
-
socket-accept"]!==
|
|
292
|
-
void 0?l.size?l.has(
|
|
293
|
-
size&&(
|
|
294
|
-
if(
|
|
295
|
-
try{
|
|
296
|
-
|
|
297
|
-
|
|
278
|
+
:${s.password}`),a){let _=o.path.split(":");o.socketPath=_[0],o.path=_[1]}let I;if(o.followRedirects){if(t._redirects===
|
|
279
|
+
0){t._originalIpc=a,t._originalSecure=i,t._originalHostOrSocketPath=a?o.socketPath:s.host;let _=r&&r.headers;if(r={...r,
|
|
280
|
+
headers:{}},_)for(let[P,N]of Object.entries(_))r.headers[P.toLowerCase()]=N}else if(t.listenerCount("redirect")===0){let _=a?
|
|
281
|
+
t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:s.host===t._originalHostOrSocketPath;(!_||
|
|
282
|
+
t._originalSecure&&!i)&&(delete o.headers.authorization,delete o.headers.cookie,_||delete o.headers.host,o.auth=void 0)}
|
|
283
|
+
o.auth&&!r.headers.authorization&&(r.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),I=t._req=f(o),
|
|
284
|
+
t._redirects&&t.emit("redirect",t.url,I)}else I=t._req=f(o);o.timeout&&I.on("timeout",()=>{Y(t,I,"Opening handshake has \
|
|
285
|
+
timed out")}),I.on("error",_=>{I===null||I[ps]||(I=t._req=null,Ht(t,_))}),I.on("response",_=>{let P=_.headers.location,N=_.
|
|
286
|
+
statusCode;if(P&&o.followRedirects&&N>=300&&N<400){if(++t._redirects>o.maxRedirects){Y(t,I,"Maximum redirects exceeded");
|
|
287
|
+
return}I.abort();let z;try{z=new Br(P,e)}catch{let q=new SyntaxError(`Invalid URL: ${P}`);Ht(t,q);return}fs(t,z,n,r)}else
|
|
288
|
+
t.emit("unexpected-response",I,_)||Y(t,I,`Unexpected server response: ${_.statusCode}`)}),I.on("upgrade",(_,P,N)=>{if(t.
|
|
289
|
+
emit("upgrade",_),t.readyState!==j.CONNECTING)return;I=t._req=null;let z=_.headers.upgrade;if(z===void 0||z.toLowerCase()!==
|
|
290
|
+
"websocket"){Y(t,P,"Invalid Upgrade header");return}let L=Yc("sha1").update(u+rd).digest("base64");if(_.headers["sec-web\
|
|
291
|
+
socket-accept"]!==L){Y(t,P,"Invalid Sec-WebSocket-Accept header");return}let q=_.headers["sec-websocket-protocol"],H;if(q!==
|
|
292
|
+
void 0?l.size?l.has(q)||(H="Server sent an invalid subprotocol"):H="Server sent a subprotocol but none was requested":l.
|
|
293
|
+
size&&(H="Server sent no subprotocol"),H){Y(t,P,H);return}q&&(t._protocol=q);let k=_.headers["sec-websocket-extensions"];
|
|
294
|
+
if(k!==void 0){if(!g){Y(t,P,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let R;
|
|
295
|
+
try{R=cd(k)}catch{Y(t,P,"Invalid Sec-WebSocket-Extensions header");return}let O=Object.keys(R);if(O.length!==1||O[0]!==ve.
|
|
296
|
+
extensionName){Y(t,P,"Server indicated an extension that was not requested");return}try{g.accept(R[ve.extensionName])}catch{
|
|
297
|
+
Y(t,P,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[ve.extensionName]=g}t.setSocket(P,N,{allowSynchronousEvents:o.
|
|
298
298
|
allowSynchronousEvents,generateMask:o.generateMask,maxBufferedChunks:o.maxBufferedChunks,maxFragments:o.maxFragments,maxPayload:o.
|
|
299
|
-
maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(
|
|
300
|
-
|
|
301
|
-
return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=
|
|
302
|
-
t._readyState=
|
|
303
|
-
destroyed&&e.socket.destroy(),process.nextTick(
|
|
304
|
-
se",t.emitClose.bind(t)))}function
|
|
305
|
-
t._bufferedAmount+=r}if(n){let r=new Error(`WebSocket is not open: readyState ${t.readyState} (${
|
|
306
|
-
nextTick(n,r)}}function
|
|
307
|
-
(n._socket.removeListener("data",
|
|
308
|
-
t.isPaused||t._socket.resume()}function
|
|
309
|
-
process.nextTick(
|
|
310
|
-
emitClose()}function
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
e.emit("error",t)))}function
|
|
314
|
-
let t=this[
|
|
315
|
-
|
|
316
|
-
length!==0){let e=this.read(this._readableState.length);t._receiver.write(e)}t._receiver.end(),this[
|
|
299
|
+
maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(I,t):I.end()}function Ht(t,e){t._readyState=
|
|
300
|
+
j.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function ld(t){return t.path=t.socketPath,us.connect(t)}function pd(t){
|
|
301
|
+
return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=us.isIP(t.host)?"":t.host),Jc.connect(t)}function Y(t,e,n){
|
|
302
|
+
t._readyState=j.CLOSING;let r=new Error(n);Error.captureStackTrace(r,Y),e.setHeader?(e[ps]=!0,e.abort(),e.socket&&!e.socket.
|
|
303
|
+
destroyed&&e.socket.destroy(),process.nextTick(Ht,t,r)):(e.destroy(r),e.once("error",t.emit.bind(t,"error")),e.once("clo\
|
|
304
|
+
se",t.emitClose.bind(t)))}function Gr(t,e,n){if(e){let r=ed(e)?e.size:dd(e).length;t._socket?t._sender._bufferedBytes+=r:
|
|
305
|
+
t._bufferedAmount+=r}if(n){let r=new Error(`WebSocket is not open: readyState ${t.readyState} (${ue[t.readyState]})`);process.
|
|
306
|
+
nextTick(n,r)}}function fd(t,e){let n=this[B];n._closeFrameReceived=!0,n._closeMessage=e,n._closeCode=t,n._socket[B]!==void 0&&
|
|
307
|
+
(n._socket.removeListener("data",Vt),process.nextTick(ms,n._socket),t===1005?n.close():n.close(t,e))}function md(){let t=this[B];
|
|
308
|
+
t.isPaused||t._socket.resume()}function hd(t){let e=this[B];e._socket[B]!==void 0&&(e._socket.removeListener("data",Vt),
|
|
309
|
+
process.nextTick(ms,e._socket),e.close(t[od])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function ds(){this[B].
|
|
310
|
+
emitClose()}function gd(t,e){this[B].emit("message",t,e)}function vd(t){let e=this[B];e._autoPong&&e.pong(t,!this._isServer,
|
|
311
|
+
ls),e.emit("ping",t)}function wd(t){this[B].emit("pong",t)}function ms(t){t.resume()}function yd(t){let e=this[B];e.readyState!==
|
|
312
|
+
j.CLOSED&&(e.readyState===j.OPEN&&(e._readyState=j.CLOSING,hs(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,
|
|
313
|
+
e.emit("error",t)))}function hs(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function gs(){
|
|
314
|
+
let t=this[B];if(this.removeListener("close",gs),this.removeListener("data",Vt),this.removeListener("end",vs),t._readyState=
|
|
315
|
+
j.CLOSING,!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&this._readableState.
|
|
316
|
+
length!==0){let e=this.read(this._readableState.length);t._receiver.write(e)}t._receiver.end(),this[B]=void 0,clearTimeout(
|
|
317
317
|
t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on(
|
|
318
|
-
"error",
|
|
319
|
-
t._readyState=
|
|
320
|
-
"error",
|
|
321
|
-
this._writableState.finished&&this.destroy()}function
|
|
322
|
-
"error")===0&&this.emit("error",t)}function
|
|
318
|
+
"error",ds),t._receiver.on("finish",ds))}function Vt(t){this[B]._receiver.write(t)||this.pause()}function vs(){let t=this[B];
|
|
319
|
+
t._readyState=j.CLOSING,t._receiver.end(),this.end()}function ws(){let t=this[B];this.removeListener("error",ws),this.on(
|
|
320
|
+
"error",ls),t&&(t._readyState=j.CLOSING,this.destroy())}});var bs=X((sg,xs)=>{"use strict";var og=Gt(),{Duplex:Id}=U("stream");function Is(t){t.emit("close")}function Sd(){!this.destroyed&&
|
|
321
|
+
this._writableState.finished&&this.destroy()}function Ss(t){this.removeListener("error",Ss),this.destroy(),this.listenerCount(
|
|
322
|
+
"error")===0&&this.emit("error",t)}function xd(t,e){let n=!0,r=new Id({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});
|
|
323
323
|
return t.on("message",function(s,i){let a=!i&&r._readableState.objectMode?s.toString():s;r.push(a)||t.pause()}),t.once("\
|
|
324
324
|
error",function(s){r.destroyed||(n=!1,r.destroy(s))}),t.once("close",function(){r.destroyed||r.push(null)}),r._destroy=function(o,s){
|
|
325
|
-
if(t.readyState===t.CLOSED){s(o),process.nextTick(
|
|
326
|
-
lose",function(){i||s(o),process.nextTick(
|
|
325
|
+
if(t.readyState===t.CLOSED){s(o),process.nextTick(Is,r);return}let i=!1;t.once("error",function(c){i=!0,s(c)}),t.once("c\
|
|
326
|
+
lose",function(){i||s(o),process.nextTick(Is,r)}),n&&t.terminate()},r._final=function(o){if(t.readyState===t.CONNECTING){
|
|
327
327
|
t.once("open",function(){r._final(o)});return}t._socket!==null&&(t._socket._writableState.finished?(o(),r._readableState.
|
|
328
328
|
endEmitted&&r.destroy()):(t._socket.once("finish",function(){o()}),t.close()))},r._read=function(){t.isPaused&&t.resume()},
|
|
329
329
|
r._write=function(o,s,i){if(t.readyState===t.CONNECTING){t.once("open",function(){r._write(o,s,i)});return}t.send(o,i)},
|
|
330
|
-
r.on("end",
|
|
331
|
-
let i=t.charCodeAt(o);if(r===-1&&
|
|
330
|
+
r.on("end",Sd),r.on("error",Ss),r}xs.exports=xd});var Wr=X((ig,Ts)=>{"use strict";var{tokenChars:bd}=ze();function Td(t){let e=new Set,n=-1,r=-1,o=0;for(o;o<t.length;o++){
|
|
331
|
+
let i=t.charCodeAt(o);if(r===-1&&bd[i]===1)n===-1&&(n=o);else if(o!==0&&(i===32||i===9))r===-1&&n!==-1&&(r=o);else if(i===
|
|
332
332
|
44){if(n===-1)throw new SyntaxError(`Unexpected character at index ${o}`);r===-1&&(r=o);let a=t.slice(n,r);if(e.has(a))throw new SyntaxError(
|
|
333
333
|
`The "${a}" subprotocol is duplicated`);e.add(a),n=r=-1}else throw new SyntaxError(`Unexpected character at index ${o}`)}
|
|
334
334
|
if(n===-1||r!==-1)throw new SyntaxError("Unexpected end of input");let s=t.slice(n,o);if(e.has(s))throw new SyntaxError(
|
|
335
|
-
`The "${s}" subprotocol is duplicated`);return e.add(s),e}
|
|
336
|
-
|
|
335
|
+
`The "${s}" subprotocol is duplicated`);return e.add(s),e}Ts.exports={parse:Td}});var Ps=X((cg,Rs)=>{"use strict";var _d=U("events"),Wt=U("http"),{Duplex:ag}=U("stream"),{createHash:Cd}=U("crypto"),_s=$t(),
|
|
336
|
+
Ce=De(),Ad=Wr(),Ed=Gt(),{CLOSE_TIMEOUT:Od,GUID:Rd,kWebSocket:Pd}=ae(),kd=/^[+/0-9A-Za-z]{22}==$/,Cs=0,As=1,Os=2,Kr=class extends _d{constructor(e,n){
|
|
337
337
|
if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxBufferedChunks:256*1024,maxFragments:16*1024,maxPayload:100*1024*
|
|
338
|
-
1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:
|
|
339
|
-
noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:
|
|
338
|
+
1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:Od,verifyClient:null,
|
|
339
|
+
noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:Ed,...e},e.port==null&&!e.server&&!e.noServer||
|
|
340
340
|
e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server"\
|
|
341
|
-
, or "noServer" options must be specified');if(e.port!=null?(this._server=
|
|
341
|
+
, or "noServer" options must be specified');if(e.port!=null?(this._server=Wt.createServer((r,o)=>{let s=Wt.STATUS_CODES[426];
|
|
342
342
|
o.writeHead(426,{"Content-Length":s.length,"Content-Type":"text/plain"}),o.end(s)}),this._server.listen(e.port,e.host,e.
|
|
343
343
|
backlog,n)):e.server&&(this._server=e.server),this._server){let r=this.emit.bind(this,"connection");this._removeListeners=
|
|
344
|
-
|
|
344
|
+
Nd(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(o,s,i)=>{this.handleUpgrade(
|
|
345
345
|
o,s,i,r)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=
|
|
346
|
-
!1),this.options=e,this._state=
|
|
347
|
-
er" mode');return this._server?this._server.address():null}close(e){if(this._state===
|
|
348
|
-
"The server is not running"))}),process.nextTick(
|
|
349
|
-
|
|
350
|
-
null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick(
|
|
351
|
-
_server;this._removeListeners(),this._removeListeners=this._server=null,n.close(()=>{
|
|
346
|
+
!1),this.options=e,this._state=Cs}address(){if(this.options.noServer)throw new Error('The server is operating in "noServ\
|
|
347
|
+
er" mode');return this._server?this._server.address():null}close(e){if(this._state===Os){e&&this.once("close",()=>{e(new Error(
|
|
348
|
+
"The server is not running"))}),process.nextTick(dt,this);return}if(e&&this.once("close",e),this._state!==As)if(this._state=
|
|
349
|
+
As,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=
|
|
350
|
+
null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick(dt,this):process.nextTick(dt,this);else{let n=this.
|
|
351
|
+
_server;this._removeListeners(),this._removeListeners=this._server=null,n.close(()=>{dt(this)})}}shouldHandle(e){if(this.
|
|
352
352
|
options.path){let n=e.url.indexOf("?");if((n!==-1?e.url.slice(0,n):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,n,r,o){
|
|
353
|
-
n.on("error",
|
|
354
|
-
"GET"){
|
|
355
|
-
lid Upgrade header");return}if(s===void 0||!
|
|
356
|
-
if(a!==13&&a!==8){
|
|
357
|
-
if(!this.shouldHandle(e)){
|
|
358
|
-
c)}catch{
|
|
359
|
-
if(this.options.perMessageDeflate&&
|
|
360
|
-
options.maxPayload});try{let
|
|
361
|
-
|
|
353
|
+
n.on("error",Es);let s=e.headers["sec-websocket-key"],i=e.headers.upgrade,a=+e.headers["sec-websocket-version"];if(e.method!==
|
|
354
|
+
"GET"){Ae(this,e,n,405,"Invalid HTTP method");return}if(i===void 0||i.toLowerCase()!=="websocket"){Ae(this,e,n,400,"Inva\
|
|
355
|
+
lid Upgrade header");return}if(s===void 0||!kd.test(s)){Ae(this,e,n,400,"Missing or invalid Sec-WebSocket-Key header");return}
|
|
356
|
+
if(a!==13&&a!==8){Ae(this,e,n,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}
|
|
357
|
+
if(!this.shouldHandle(e)){ut(n,400);return}let c=e.headers["sec-websocket-protocol"],d=new Set;if(c!==void 0)try{d=Ad.parse(
|
|
358
|
+
c)}catch{Ae(this,e,n,400,"Invalid Sec-WebSocket-Protocol header");return}let u=e.headers["sec-websocket-extensions"],f={};
|
|
359
|
+
if(this.options.perMessageDeflate&&u!==void 0){let l=new Ce({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.
|
|
360
|
+
options.maxPayload});try{let g=_s.parse(u);g[Ce.extensionName]&&(l.accept(g[Ce.extensionName]),f[Ce.extensionName]=l)}catch{
|
|
361
|
+
Ae(this,e,n,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let l={
|
|
362
362
|
origin:e.headers[`${a===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.
|
|
363
|
-
options.verifyClient.length===2){this.options.verifyClient(l,(
|
|
364
|
-
|
|
365
|
-
if(!s.readable||!s.writable)return s.destroy();if(s[
|
|
366
|
-
e with the same socket, possibly due to a misconfiguration");if(this._state>
|
|
367
|
-
tching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${
|
|
368
|
-
se64")}`],
|
|
369
|
-
handleProtocols(r,o):r.values().next().value;
|
|
370
|
-
let
|
|
363
|
+
options.verifyClient.length===2){this.options.verifyClient(l,(g,I,_,P)=>{if(!g)return ut(n,I||401,_,P);this.completeUpgrade(
|
|
364
|
+
f,s,d,e,n,r,o)});return}if(!this.options.verifyClient(l))return ut(n,401)}this.completeUpgrade(f,s,d,e,n,r,o)}completeUpgrade(e,n,r,o,s,i,a){
|
|
365
|
+
if(!s.readable||!s.writable)return s.destroy();if(s[Pd])throw new Error("server.handleUpgrade() was called more than onc\
|
|
366
|
+
e with the same socket, possibly due to a misconfiguration");if(this._state>Cs)return ut(s,503);let d=["HTTP/1.1 101 Swi\
|
|
367
|
+
tching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Cd("sha1").update(n+Rd).digest("ba\
|
|
368
|
+
se64")}`],u=new this.options.WebSocket(null,void 0,this.options);if(r.size){let f=this.options.handleProtocols?this.options.
|
|
369
|
+
handleProtocols(r,o):r.values().next().value;f&&(d.push(`Sec-WebSocket-Protocol: ${f}`),u._protocol=f)}if(e[Ce.extensionName]){
|
|
370
|
+
let f=e[Ce.extensionName].params,l=_s.format({[Ce.extensionName]:[f]});d.push(`Sec-WebSocket-Extensions: ${l}`),u._extensions=
|
|
371
371
|
e}this.emit("headers",d,o),s.write(d.concat(`\r
|
|
372
372
|
`).join(`\r
|
|
373
|
-
`)),s.removeListener("error",
|
|
373
|
+
`)),s.removeListener("error",Es),u.setSocket(s,i,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxBufferedChunks:this.
|
|
374
374
|
options.maxBufferedChunks,maxFragments:this.options.maxFragments,maxPayload:this.options.maxPayload,skipUTF8Validation:this.
|
|
375
|
-
options.skipUTF8Validation}),this.clients&&(this.clients.add(
|
|
376
|
-
!this.clients.size&&process.nextTick(
|
|
377
|
-
n,e[n]);return function(){for(let r of Object.keys(e))t.removeListener(r,e[r])}}function
|
|
378
|
-
function
|
|
379
|
-
l","Content-Length":Buffer.byteLength(n),...r},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${
|
|
375
|
+
options.skipUTF8Validation}),this.clients&&(this.clients.add(u),u.on("close",()=>{this.clients.delete(u),this._shouldEmitClose&&
|
|
376
|
+
!this.clients.size&&process.nextTick(dt,this)})),a(u,o)}};Rs.exports=Kr;function Nd(t,e){for(let n of Object.keys(e))t.on(
|
|
377
|
+
n,e[n]);return function(){for(let r of Object.keys(e))t.removeListener(r,e[r])}}function dt(t){t._state=Os,t.emit("close")}
|
|
378
|
+
function Es(){this.destroy()}function ut(t,e,n,r){n=n||Wt.STATUS_CODES[e],r={Connection:"close","Content-Type":"text/htm\
|
|
379
|
+
l","Content-Length":Buffer.byteLength(n),...r},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${Wt.STATUS_CODES[e]}\r
|
|
380
380
|
`+Object.keys(r).map(o=>`${o}: ${r[o]}`).join(`\r
|
|
381
381
|
`)+`\r
|
|
382
382
|
\r
|
|
383
|
-
`+n)}function
|
|
384
|
-
"wsClientError",i,n,e)}else
|
|
385
|
-
e===null}var
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
383
|
+
`+n)}function Ae(t,e,n,r,o,s){if(t.listenerCount("wsClientError")){let i=new Error(o);Error.captureStackTrace(i,Ae),t.emit(
|
|
384
|
+
"wsClientError",i,n,e)}else ut(n,r,o,s)}});function b(t){return String(t??"").trim()}function At(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;let e=Object.getPrototypeOf(t);return e===Object.prototype||
|
|
385
|
+
e===null}var vm=Object.freeze(["none","pending","committed","rolledBack","unknown"]);function w(t,{fallback:e=""}={}){return String(t||"").trim()||e}function se(t,{fallback:e=""}={}){return w(t,{fallback:e}).toLowerCase()}function K(t,{fallback:e={}}={}){return x(t)?t:{...e}}function x(t){return!!(t&&typeof t=="object"&&!Array.isArray(t))}function V(t,{fallback:e=0}={}){let n=Number(t);return!Number.isInteger(n)||n<1?e:n}function Et(t,{fallback:e=null}={}){return t==null?e:typeof t=="string"?t.trim()||e:typeof t=="number"?Number.isFinite(t)?
|
|
386
|
+
String(t):e:typeof t=="bigint"?String(t):e}var ym=Object.freeze({interrupted:Object.freeze({text:"Stopped.",messageCode:"assistant.turn.stopped"}),failed:Object.freeze(
|
|
387
|
+
{text:"Assistant stopped with an error.",messageCode:"assistant.turn.failed"})});function Ot(t){return x(t)?{...t}:{}}var F=class extends Error{constructor(e,n,r={}){super(n,r.cause===void 0?void 0:{cause:r.cause}),this.name="AppError",this.
|
|
388
|
+
status=Number(e)||500,this.statusCode=this.status,this.code=r.code||"APP_ERROR",this.params=Ot(r.params),r.messageCode&&
|
|
389
|
+
(this.messageCode=String(r.messageCode),this.messageParams=Ot(r.messageParams)),this.details=r.details,this.headers=r.headers||
|
|
390
|
+
{}}};var Km=new Set(["contextcompaction",...["context","thread","conversation"].flatMap(t=>["compact","compacted","compaction",
|
|
391
|
+
"truncate","truncated","truncation"].flatMap(e=>[`${t}_${e}`,`${e}_${t}`]))]);var G=Object.freeze({ACTIVE:"active",CANCELLED:"cancelled",COMPLETED:"completed",FAILED:"failed",FINALIZING:"finalizing",
|
|
392
|
+
INTERRUPTED:"interrupted",STARTING:"starting",TIMED_OUT:"timed_out"}),th=new Set(Object.values(G)),rh=new Set([G.CANCELLED,
|
|
393
|
+
G.COMPLETED,G.FAILED,G.INTERRUPTED,G.TIMED_OUT]),nh=new Set([G.ACTIVE,G.FINALIZING,G.STARTING]);import{execFile as tc}from"node:child_process";import{readFile as _r,readdir as rc}from"node:fs/promises";import{setTimeout as Co}from"node:timers/promises";import{promisify as nc}from"node:util";var oc=nc(tc);async function sc(t){
|
|
394
|
+
let{stdout:e}=await oc("ps",t,{env:{...process.env,LC_ALL:"C",TZ:"UTC"},maxBuffer:67108864});return e}function kt({runtimeTokenEnvironmentName:t="\
|
|
394
395
|
JSKIT_EXECUTION_RUNTIME_TOKEN",commandHashEnvironmentName:e="JSKIT_EXECUTION_COMMAND_HASH",label:n="Native",unavailableCode:r="\
|
|
395
|
-
native_process_identity_unavailable",platform:o=process.platform,ps:s=
|
|
396
|
-
{linux:"linux-proc",darwin:"darwin"}),
|
|
397
|
-
{ABSENT:"absent",AMBIGUOUS:"ambiguous",EXACT:"exact",INVALID:"invalid",MISMATCH:"mismatch"});function
|
|
398
|
-
isSafeInteger(Number(
|
|
399
|
-
let
|
|
400
|
-
let
|
|
401
|
-
kill(-
|
|
402
|
-
h,
|
|
403
|
-
""),
|
|
404
|
-
h[2]),
|
|
405
|
-
test(
|
|
406
|
-
|
|
407
|
-
version||0)}}function
|
|
408
|
-
test(
|
|
409
|
-
test(
|
|
410
|
-
let
|
|
411
|
-
continue;let h=Number(
|
|
412
|
-
let
|
|
413
|
-
|
|
414
|
-
let
|
|
415
|
-
exec(String(
|
|
416
|
-
h,
|
|
417
|
-
`)){let h=/^\s*(\d+) (.*)$/u.exec(
|
|
418
|
-
|
|
419
|
-
let
|
|
420
|
-
,pgid=,uid=,stat=,lstart="]),s(
|
|
421
|
-
`)){let E=/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\w{3}\s+\w{3}\s+\d{1,2}\s+[\d:]{8}\s+\d{4})\s*$/u.exec(
|
|
422
|
-
"Z"))continue;let
|
|
423
|
-
pid:
|
|
424
|
-
values(l).includes(
|
|
425
|
-
|
|
426
|
-
processGroupIds:[],status:l.INVALID};if(
|
|
427
|
-
|
|
428
|
-
let h=Number(
|
|
429
|
-
E.environmentReadable&&E.runtimeToken===
|
|
430
|
-
h);if(
|
|
431
|
-
status:l.AMBIGUOUS}:{processGroupIds:[],status:
|
|
432
|
-
for(let E of
|
|
433
|
-
processGroupIds:[],status:l.AMBIGUOUS};return
|
|
434
|
-
{processGroupIds:
|
|
435
|
-
async function
|
|
436
|
-
|
|
437
|
-
{fallback:a}),
|
|
438
|
-
Date.now()))),
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
l.MISMATCH)return{inspection:E,signaledProcessGroups:
|
|
442
|
-
E.processGroupIds.includes(
|
|
443
|
-
if(!
|
|
444
|
-
return{alreadyStopped:!0,identityStatus:l.ABSENT,processExitVerified:!0,stopped:!1};let
|
|
445
|
-
ABSENT||
|
|
446
|
-
identityStatus:
|
|
396
|
+
native_process_identity_unavailable",platform:o=process.platform,ps:s=sc}={}){let a=o==="darwin"?100:25,c=1,d=Object.freeze(
|
|
397
|
+
{linux:"linux-proc",darwin:"darwin"}),u=d[o]||"",f=Object.freeze({RUNNING:"running",STOPPED:"stopped"}),l=Object.freeze(
|
|
398
|
+
{ABSENT:"absent",AMBIGUOUS:"ambiguous",EXACT:"exact",INVALID:"invalid",MISMATCH:"mismatch"});function g(y={}){return!!(Number.
|
|
399
|
+
isSafeInteger(Number(y.pid))&&Number(y.pid)>0&&L(y.processIdentity)&&[f.RUNNING,f.STOPPED].includes(y.processState))}function I(y){
|
|
400
|
+
let p=Number(y);if(!Number.isSafeInteger(p)||p<=0)return!1;try{return process.kill(p,0),!0}catch{return!1}}function _(y){
|
|
401
|
+
let p=Number(y);if(!Number.isSafeInteger(p)||p<=0)return!1;if(process.platform==="win32")return I(p);try{return process.
|
|
402
|
+
kill(-p,0),!0}catch{return!1}}function P(y,p){let m=Number(y),h=process.platform==="win32"?m:-m;try{return process.kill(
|
|
403
|
+
h,p),!0}catch(v){if(!["ESRCH","EPERM"].includes(String(v?.code||"")))throw v;return!1}}function N(y=""){let p=String(y||
|
|
404
|
+
""),m=p.lastIndexOf(")");if(m<0)return null;let h=p.slice(m+1).trim().split(/\s+/u),v=String(h[0]||""),S=Number(h[1]),T=Number(
|
|
405
|
+
h[2]),C=String(h[19]||"");return!/^[A-Z]$/u.test(v)||!Number.isSafeInteger(S)||S<0||!Number.isSafeInteger(T)||T<=0||!/^\d+$/u.
|
|
406
|
+
test(C)?null:{parentPid:S,processGroupId:T,startTimeTicks:C,state:v}}function z(y={}){let p=x(y)?y:{};return{commandHash:b(
|
|
407
|
+
p.commandHash),platform:b(p.platform),runtimeToken:b(p.runtimeToken),startTimeTicks:b(p.startTimeTicks),version:Number(p.
|
|
408
|
+
version||0)}}function L(y={}){let p=z(y);return!!(p.version===c&&Object.values(d).includes(p.platform)&&/^[a-f0-9]{12}$/u.
|
|
409
|
+
test(p.commandHash)&&/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(p.runtimeToken)&&/^\d+$/u.
|
|
410
|
+
test(p.startTimeTicks))}function q(y=[],p=""){let m=y.find(h=>h.startsWith(`${p}=`));return m?m.slice(p.length+1):""}async function H(){
|
|
411
|
+
let y=[],p=await rc("/proc",{withFileTypes:!0}).catch(()=>[]);for(let m of p){if(!m.isDirectory()||!/^\d+$/u.test(m.name))
|
|
412
|
+
continue;let h=Number(m.name),v=await _r(`/proc/${m.name}/stat`,"utf8").catch(()=>""),S=N(v);if(!S||S.state==="Z")continue;
|
|
413
|
+
let T=null,C=!0;try{T=await _r(`/proc/${m.name}/environ`)}catch(E){if(String(E?.code||"")==="ENOENT")continue;C=!1}let M=C?
|
|
414
|
+
T.toString("utf8").split("\0"):[];y.push({...S,commandHash:q(M,e),environmentReadable:C,pid:h,runtimeToken:q(M,t)})}return y}
|
|
415
|
+
let k=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function R(y=""){let p=/^\w{3}\s+(\w{3})\s+(\d{1,2})\s+(\d{2}):(\d{2}):(\d{2})\s+(\d{4})$/u.
|
|
416
|
+
exec(String(y).trim()),m=p?k.indexOf(p[1]):-1;if(m<0)return"";let[,,h,v,S,T,C]=p.map(Number);return String(Date.UTC(C,m,
|
|
417
|
+
h,v,S,T)/1e3)}function O(y=""){let p=new Map;for(let m of String(y).split(`
|
|
418
|
+
`)){let h=/^\s*(\d+) (.*)$/u.exec(m);h&&p.set(Number(h[1]),h[2])}return p}function D(y,p){if(y===void 0||!p?.startsWith(
|
|
419
|
+
y))return null;let m=p.slice(y.length).split(/\s+/u).filter(h=>/^[^=\s]+=/u.test(h));return m.length?m:null}async function W(){
|
|
420
|
+
let y=process.getuid(),p=["-x","-U",String(y),"-ww","-o","pid=,command="],[m,h,v]=await Promise.all([s(["-ax","-o","pid=\
|
|
421
|
+
,pgid=,uid=,stat=,lstart="]),s(p),s(["-E",...p])]),S=O(h),T=O(v),C=[];for(let M of String(m).split(`
|
|
422
|
+
`)){let E=/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\w{3}\s+\w{3}\s+\d{1,2}\s+[\d:]{8}\s+\d{4})\s*$/u.exec(M);if(!E||E[4].startsWith(
|
|
423
|
+
"Z"))continue;let te=Number(E[1]),re=Number(E[3])===y?D(S.get(te),T.get(te)):null;C.push({commandHash:q(re||[],e),environmentReadable:!!re,
|
|
424
|
+
pid:te,processGroupId:Number(E[2]),runtimeToken:q(re||[],t),startTimeTicks:R(E[5])})}return C}function fe(y){let p=Object.
|
|
425
|
+
values(l).includes(y?.status)?y.status:l.AMBIGUOUS;return{processGroupIds:[...new Set((Array.isArray(y?.processGroupIds)?
|
|
426
|
+
y.processGroupIds:[]).map(Number).filter(m=>Number.isSafeInteger(m)&&m>0))],status:p}}async function Tt(y={}){if(!g(y))return{
|
|
427
|
+
processGroupIds:[],status:l.INVALID};if(y.processState===f.STOPPED)return{processGroupIds:[],status:l.ABSENT};let p=y.processIdentity,
|
|
428
|
+
m=p.platform!==u?null:o==="darwin"?await W().catch(()=>null):await H();if(!m)return{processGroupIds:[],status:l.AMBIGUOUS};
|
|
429
|
+
let h=Number(y.pid),v=m.filter(({processGroupId:E})=>E===h),S=[],T=v.some(({environmentReadable:E})=>!E);for(let E of m)
|
|
430
|
+
E.environmentReadable&&E.runtimeToken===p.runtimeToken&&E.commandHash===p.commandHash&&S.push(E);let C=S.find(({pid:E})=>E===
|
|
431
|
+
h);if(C&&C.startTimeTicks!==p.startTimeTicks)return{processGroupIds:[],status:l.AMBIGUOUS};if(S.length===0)return T?{processGroupIds:[],
|
|
432
|
+
status:l.AMBIGUOUS}:{processGroupIds:[],status:v.length>0||_(h)?l.MISMATCH:l.ABSENT};let M=[...new Set(S.map(({processGroupId:E})=>E))];
|
|
433
|
+
for(let E of M)if(m.filter(re=>re.processGroupId===E).some(re=>!re.environmentReadable||!S.some(({pid:Wa})=>Wa===re.pid)))
|
|
434
|
+
return{processGroupIds:[],status:l.AMBIGUOUS};return v.some(E=>!S.some(({pid:te})=>te===E.pid))?{processGroupIds:[],status:l.
|
|
435
|
+
AMBIGUOUS}:{processGroupIds:M,status:l.EXACT}}async function Se(y={},p={}){let m=p.processIdentityInspector??Tt;return fe(
|
|
436
|
+
await m(y))}async function _t(y={},p={},m=0){let h=Date.now()+m,v=await Se(y,p);for(;Date.now()<h&&v.status===l.EXACT;)await Co(
|
|
437
|
+
100),v=await Se(y,p);return v}async function ke(y={},p={}){let m=V(p.processIdentitySettleTimeoutMs,{fallback:1e3}),h=V(
|
|
438
|
+
p.processIdentitySettlePollMs,{fallback:a}),v=Date.now()+m,S=await Se(y,p);for(;S.status===l.AMBIGUOUS&&Date.now()<v;)await Co(
|
|
439
|
+
Math.min(h,Math.max(1,v-Date.now()))),S=await Se(y,p);return S}async function Ct(y={},p="SIGTERM",m={}){let h=m.signalProcessGroup??
|
|
440
|
+
P,v=await ke(y,m);if(v.status!==l.EXACT)return{inspection:v,signaledProcessGroups:[]};let S=Number(y.pid),T=[...v.processGroupIds.
|
|
441
|
+
filter(M=>M!==S),...v.processGroupIds.filter(M=>M===S)],C=[];for(let M of T){let E=await ke(y,m);if(E.status===l.ABSENT||
|
|
442
|
+
E.status===l.MISMATCH)return{inspection:E,signaledProcessGroups:C};if(E.status!==l.EXACT)return{inspection:E,signaledProcessGroups:C};
|
|
443
|
+
E.processGroupIds.includes(M)&&(h(M,p),C.push(M))}return{inspection:await ke(y,m),signaledProcessGroups:C}}async function yr(y={},p={}){
|
|
444
|
+
if(!g(y))return{identityStatus:l.INVALID,processExitVerified:!1,stopped:!1};if(y.processState===f.STOPPED&&y.processExitVerifiedAt)
|
|
445
|
+
return{alreadyStopped:!0,identityStatus:l.ABSENT,processExitVerified:!0,stopped:!1};let m=await ke(y,p);if(m.status===l.
|
|
446
|
+
ABSENT||m.status===l.MISMATCH)return{identityStatus:m.status,processExitVerified:!0,stopped:!1};if(m.status!==l.EXACT)return{
|
|
447
|
+
identityStatus:m.status,processExitVerified:!1,stopped:!1};let h=await Ct(y,"SIGTERM",p);if(h.inspection.status===l.AMBIGUOUS)
|
|
447
448
|
return{identityStatus:h.inspection.status,processExitVerified:!1,signaledProcessGroups:h.signaledProcessGroups,stopped:!1};
|
|
448
|
-
let
|
|
449
|
-
|
|
450
|
-
inspection.status,processExitVerified:!1,signaledProcessGroups:
|
|
451
|
-
let
|
|
452
|
-
status,pid:Number(
|
|
453
|
-
"darwin")return
|
|
454
|
-
|
|
455
|
-
async function
|
|
456
|
-
|
|
457
|
-
startTimeTicks||
|
|
458
|
-
commandHash:
|
|
459
|
-
normalizeInspection:
|
|
449
|
+
let v=await _t(y,p,V(p.termTimeoutMs,{fallback:3e3})),S=[...h.signaledProcessGroups];if(v.status===l.EXACT){let C=await Ct(
|
|
450
|
+
y,"SIGKILL",p);if(S=[...new Set([...S,...C.signaledProcessGroups])],C.inspection.status===l.AMBIGUOUS)return{identityStatus:C.
|
|
451
|
+
inspection.status,processExitVerified:!1,signaledProcessGroups:S,stopped:!1};v=await _t(y,p,V(p.killTimeoutMs,{fallback:1e3}))}
|
|
452
|
+
let T=[l.ABSENT,l.MISMATCH].includes(v.status);return{descendantProcessGroups:S.filter(C=>C!==Number(y.pid)),identityStatus:v.
|
|
453
|
+
status,pid:Number(y.pid),processExitVerified:T,signaledProcessGroups:S,stopped:T&&S.length>0}}async function Ir(y){if(o!==
|
|
454
|
+
"darwin")return N(await _r(`/proc/${y}/stat`,"utf8").catch(()=>""));let p=String(await s(["-o","pgid=,lstart=","-p",String(
|
|
455
|
+
y)]).catch(()=>"")),m=/^\s*(\d+)\s+(.+?)\s*$/u.exec(p);return m?{processGroupId:Number(m[1]),startTimeTicks:R(m[2])}:null}
|
|
456
|
+
async function Sr({commandHash:y="",pid:p=null,reportedIdentity:m=null,runtimeToken:h=""}={}){let v=b(y),S=b(h),T=z(m);if(L(
|
|
457
|
+
T)&&T.commandHash===v&&T.runtimeToken===S)return T;let C=Number(p),M=u&&Number.isSafeInteger(C)&&C>0?await Ir(C):null;if(!M?.
|
|
458
|
+
startTimeTicks||M.processGroupId!==C){let E=new Error(`${n} process identity could not be captured.`);throw E.code=r,E}return{
|
|
459
|
+
commandHash:v,platform:u,runtimeToken:S,startTimeTicks:M.startTimeTicks,version:c}}return Object.freeze({normalize:z,isValid:L,
|
|
460
|
+
normalizeInspection:fe,capture:Sr,inspect:Se,stop:yr,isProcessAlive:I})}import{execFile as ac}from"node:child_process";import{promisify as cc}from"node:util";var yh=Object.freeze(["plugins","apps","daemon_auto_start"]);var Ih=Object.freeze([[".tmp",/^(?:plugins(?:$|[.-])|git-|bundled-marketplaces$)/u],["cache",/^(?:remote_plugin_catalog|codex_apps_tools|codex_apps_server_info|codex_app_directory|bundled_plugin_exclusions)$/u]]);var Ch=cc(ac);function xe(t=""){return Array.from(String(t)).some(e=>{let n=e.codePointAt(0);return n<=31||n===127})}var Nt=(t,e,n,r={})=>Object.freeze({id:t,contextWindow:e,variants:Object.freeze(n),...r}),dc=Object.freeze([Object.freeze(
|
|
460
461
|
{id:"deepseek",baseUrl:"https://api.deepseek.com/",claudeBaseUrl:"https://api.deepseek.com/anthropic",claudeAutoCompactWindow:786432,
|
|
461
|
-
webSearch:!1,models:Object.freeze([
|
|
462
|
-
|
|
462
|
+
webSearch:!1,models:Object.freeze([Nt("deepseek-flash",1048576,["low","high","max"],{images:!0,freeformPatch:!0,codexHistoryRouting:!0}),
|
|
463
|
+
Nt("deepseek-v4-pro",1048576,["low","high","max"],{freeformPatch:!0,codexHistoryRouting:!0})])}),Object.freeze({id:"zai-\
|
|
463
464
|
coding-plan",baseUrl:"https://api.z.ai/api/v1",claudeBaseUrl:"https://api.z.ai/api/anthropic",claudeAutoCompactWindow:1e6,
|
|
464
|
-
webSearch:!1,models:Object.freeze([
|
|
465
|
+
webSearch:!1,models:Object.freeze([Nt("glm-5.3",1048576,["low","high","max"],{freeformPatch:!0,codexHistoryRouting:!0})])}),
|
|
465
466
|
Object.freeze({id:"zai",baseUrl:"https://api.z.ai/api/v1",claudeBaseUrl:"https://api.z.ai/api/anthropic",claudeAutoCompactWindow:1e6,
|
|
466
|
-
webSearch:!1,models:Object.freeze([
|
|
467
|
-
deepseek:
|
|
468
|
-
UNREACHABLE:"unreachable"}),
|
|
469
|
-
SUSPECT:"suspect"}),
|
|
470
|
-
ambiguous",EXACT:"exact",INVALID:"invalid",MISMATCH:"mismatch"});var
|
|
471
|
-
commandHash:"JSKIT_EXECUTION_COMMAND_HASH"});var
|
|
472
|
-
|
|
467
|
+
webSearch:!1,models:Object.freeze([Nt("glm-5.3",1048576,["low","high","max"],{freeformPatch:!0,codexHistoryRouting:!0})])})]);function rt(t){return dc.find(e=>e.id===t)||null}var kh=32*1024*1024,Nh=Object.freeze({chatgpt:"https://chatgpt.com/backend-api/codex",apiKey:"https://api.openai.com/v1",
|
|
468
|
+
deepseek:rt("deepseek").baseUrl.replace(/\/$/u,""),"zai-coding-plan":rt("zai-coding-plan").baseUrl,zai:rt("zai").baseUrl});var Cr=Object.freeze({HELPER:"helper",INTERACTIVE:"interactive"}),Bh=kt();var Ar=Object.freeze({UNIX:"unix"});var lc=process.platform==="linux"?107:103,Ao=Object.freeze({MISSING:"missing",RESPONSIVE:"responsive",TIMEOUT:"timeout",
|
|
469
|
+
UNREACHABLE:"unreachable"}),pc=Object.freeze({EXITED:"exited",INCOMPATIBLE:"incompatible",LIVE:"live",MISSING:"missing",
|
|
470
|
+
SUSPECT:"suspect"}),nt=Object.freeze({RUNNING:"running",STOPPED:"stopped"}),Eo=Object.freeze({ABSENT:"absent",AMBIGUOUS:"\
|
|
471
|
+
ambiguous",EXACT:"exact",INVALID:"invalid",MISMATCH:"mismatch"});var fc=Object.freeze({runtimeToken:"JSKIT_EXECUTION_RUNTIME_TOKEN",modelCatalogSource:"JSKIT_CODEX_MODEL_CATALOG_SOURCE",
|
|
472
|
+
commandHash:"JSKIT_EXECUTION_COMMAND_HASH"});var Md=me(bs(),1),jd=me($t(),1),Dd=me(De(),1),zd=me(Lr(),1),Ld=me(qr(),1),Ud=me(Wr(),1),Fd=me(Gt(),1),qd=me(Ps(),1);var dw=32*1024,uw=2*1024*1024;var tr=Object.freeze({ACTIVE:"active",CLEANUP_REQUIRED:"cleanup_required",READY:"ready",STARTING_TURN:"starting_turn"}),
|
|
473
|
+
kw=new Set(Object.values(tr)),Nw=Object.freeze(["createdAt","executionProfile","identity","lifecycle","ownershipId","pro\
|
|
473
474
|
jectContextRoot","projectRuntimeRoot","revision","schemaVersion","sessionId","threadId","turnId","updatedAt","workdir"]),
|
|
474
|
-
|
|
475
|
+
Mw=Object.freeze(["providerId","providerKeyFingerprint","runtime","server","transportId"]),jw=Object.freeze(["accountIde\
|
|
475
476
|
ntitySignature","authStateSignature","endpoint","executionMode","executionContextHash","provider","runtimeDir","runtimes\
|
|
476
|
-
Hash","terminalEnvHash","toolHomeSource","transport"]),
|
|
477
|
+
Hash","terminalEnvHash","toolHomeSource","transport"]),Dw=Object.freeze(["userAgent"]);import pu from"node:path";var fu=Object.freeze(["apps","artifact","browser_use","browser_use_external","browser_use_full_cdp_access","code_mode","\
|
|
477
478
|
code_mode_host","computer_use","default_mode_request_user_input","deferred_executor","goals","hooks","image_generation",
|
|
478
479
|
"in_app_browser","memories","multi_agent","multi_agent_v2","plugins","psp","recommended_plugins","request_permissions_to\
|
|
479
480
|
ol","shell_tool","skill_mcp_dependency_install","skill_search","tool_call_mcp_elicitation","tool_suggest","unified_exec",
|
|
480
|
-
"unified_exec_zsh_fork","view_image"]);function
|
|
481
|
-
values(t))
|
|
481
|
+
"unified_exec_zsh_fork","view_image"]);function Xs(t){if(!t||typeof t!="object"||Object.isFrozen(t))return t;for(let e of Object.
|
|
482
|
+
values(t))Xs(e);return Object.freeze(t)}function mu(t="",e={}){let n=new Error(b(t)||"Codex cannot prove the helper exec\
|
|
482
483
|
ution policy.");n.code="codex_policy_unenforceable",n.details=Object.freeze({...e});for(let[r,o]of Object.entries(n.details))
|
|
483
|
-
["code","details","message","name"].includes(r)||(n[r]=o);return n}function
|
|
484
|
-
.151.0",disabledFeatures:n=
|
|
485
|
-
1024,hookMaxCount:a=256,hookErrorMaxCount:c=256,hookFieldMaxLength:d=2048,hookFingerprintMaxLength:
|
|
486
|
-
1024}={},createError:l=
|
|
487
|
-
f8")}catch{throw l(`Codex helper execution received an invalid ${h}.`)}if(
|
|
488
|
-
n oversized ${h}.`)}function
|
|
489
|
-
annot verify the app-server connection generation.");let
|
|
490
|
-
|
|
491
|
-
currentHelperExecutionContext!="function")throw l("Codex helper execution requires its dedicated isolated provider.");let
|
|
492
|
-
currentHelperExecutionContext(),h=
|
|
493
|
-
h)||!/^sha256:[a-f0-9]{64}$/u.test(
|
|
494
|
-
{accountIdentitySignature:
|
|
495
|
-
if(!
|
|
496
|
-
let
|
|
497
|
-
/^((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*))(?:$|[ \t].*$)/u);return
|
|
484
|
+
["code","details","message","name"].includes(r)||(n[r]=o);return n}function hu({clientName:t="jskit",minimumVersion:e="0\
|
|
485
|
+
.151.0",disabledFeatures:n=fu,limits:{userAgentMaxLength:r=512,mcpServerMaxCount:o=128,mcpServerNameMaxLength:s=256,configResponseMaxBytes:i=256*
|
|
486
|
+
1024,hookMaxCount:a=256,hookErrorMaxCount:c=256,hookFieldMaxLength:d=2048,hookFingerprintMaxLength:u=256*1024,hookResponseMaxBytes:f=512*
|
|
487
|
+
1024}={},createError:l=mu}={}){let g=new WeakSet;function I(p,m,h){let v=0;try{v=Buffer.byteLength(JSON.stringify(p),"ut\
|
|
488
|
+
f8")}catch{throw l(`Codex helper execution received an invalid ${h}.`)}if(v>m)throw l(`Codex helper execution received a\
|
|
489
|
+
n oversized ${h}.`)}function _(p){if(typeof p?.currentConnectionGeneration!="function")throw l("Codex helper execution c\
|
|
490
|
+
annot verify the app-server connection generation.");let m=p.currentConnectionGeneration();if(!Number.isSafeInteger(m)||
|
|
491
|
+
m<=0)throw l("Codex helper execution found no active app-server connection.");return m}async function P(p){if(typeof p?.
|
|
492
|
+
currentHelperExecutionContext!="function")throw l("Codex helper execution requires its dedicated isolated provider.");let m=await p.
|
|
493
|
+
currentHelperExecutionContext(),h=b(m?.cwd),v=b(m?.accountIdentitySignature);if(m?.executionMode!=="helper"||!h||!pu.isAbsolute(
|
|
494
|
+
h)||!/^sha256:[a-f0-9]{64}$/u.test(v))throw l("Codex helper runtime isolation could not be verified.");return Object.freeze(
|
|
495
|
+
{accountIdentitySignature:v,cwd:h,executionMode:"helper"})}function N(p=""){let m=b(p).match(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/u);
|
|
496
|
+
if(!m)return null;let h=m.slice(1).map(v=>Number.parseInt(v,10));return h.every(Number.isSafeInteger)?h:null}function z(p=""){
|
|
497
|
+
let m=b(p);if(!m||m.length>r||xe(m))return null;let h=`${t}/`;if(!m.startsWith(h))return null;let v=m.slice(h.length).match(
|
|
498
|
+
/^((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*))(?:$|[ \t].*$)/u);return v?N(v[1]):null}function L(p){if(typeof p?.currentServerInfo!=
|
|
498
499
|
"function")throw l("Codex helper execution cannot verify the app-server version. Update Codex and retry.",{minimumVersion:e});
|
|
499
|
-
let
|
|
500
|
-
er version. Update Codex and retry.",{minimumVersion:e});let
|
|
501
|
-
-1&&h[
|
|
502
|
-
nd retry.`,{actualVersion:
|
|
503
|
-
|
|
504
|
-
if(
|
|
505
|
-
configuration.");let h=Object.keys(
|
|
506
|
-
ceived an oversized or invalid MCP server inventory.");return h.sort()}function
|
|
507
|
-
!Array.isArray(
|
|
508
|
-
"Codex helper execution received an unexpected hook inventory.");let h=
|
|
500
|
+
let m=b(p.currentServerInfo()?.userAgent),h=z(m);if(!h)throw l("Codex helper execution received an unrecognised app-serv\
|
|
501
|
+
er version. Update Codex and retry.",{minimumVersion:e});let v=h.join("."),S=N(e),T=h.findIndex((C,M)=>C!==S[M]);if(T!==
|
|
502
|
+
-1&&h[T]<S[T])throw l(`Codex helper execution requires app-server ${e} or newer; current version is ${v}. Update Codex a\
|
|
503
|
+
nd retry.`,{actualVersion:v,minimumVersion:e});return Object.freeze({minimumVersion:e,version:v})}function q(p=null){if(!At(
|
|
504
|
+
p?.config))throw l("Codex helper execution could not read the effective app-server configuration.");let m=p.config.mcp_servers;
|
|
505
|
+
if(m==null)return[];if(I(m,i,"MCP configuration"),!At(m))throw l("Codex helper execution received an invalid MCP server \
|
|
506
|
+
configuration.");let h=Object.keys(m);if(h.length>o||h.some(v=>!v||v.length>s||xe(v)))throw l("Codex helper execution re\
|
|
507
|
+
ceived an oversized or invalid MCP server inventory.");return h.sort()}function H(p=null,m=""){if(I(p,f,"hook inventory"),
|
|
508
|
+
!Array.isArray(p?.data))throw l("Codex helper execution could not enumerate app-server hooks.");if(p.data.length!==1)throw l(
|
|
509
|
+
"Codex helper execution received an unexpected hook inventory.");let h=p.data[0];if(b(h?.cwd)!==m||b(h?.cwd).length>d||!Array.
|
|
509
510
|
isArray(h.hooks)||!Array.isArray(h.errors)||h.hooks.length>a||h.errors.length>c)throw l("Codex helper execution received\
|
|
510
511
|
an incomplete hook inventory.");if(h.errors.length>0)throw l("Codex helper execution cannot continue while hook discove\
|
|
511
|
-
ry has errors.",{hookErrorCount:h.errors.length});let
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
currentHash:
|
|
515
|
-
localeCompare(
|
|
516
|
-
|
|
517
|
-
mcpServerNames:
|
|
518
|
-
|
|
519
|
-
include_permissions_instructions:!1,...
|
|
520
|
-
fromEntries(
|
|
512
|
+
ry has errors.",{hookErrorCount:h.errors.length});let v=h.hooks.map(T=>{let C=b(T?.key),M=b(T?.currentHash),E=b(T?.handlerType),
|
|
513
|
+
te=b(T?.sourcePath);if(!C||[C,M,E,te].some(re=>re.length>d||xe(re)))throw l("Codex helper execution found an invalid hoo\
|
|
514
|
+
k inventory entry.");if(T?.isManaged===!0&&T?.enabled===!0)throw l("Codex helper execution cannot disable a managed hook\
|
|
515
|
+
.");return{currentHash:M,enabled:T?.enabled===!0,handlerType:E,isManaged:T?.isManaged===!0,key:C,sourcePath:te}}).sort((T,C)=>T.
|
|
516
|
+
key.localeCompare(C.key)),S=JSON.stringify(v);if(S.length>u)throw l("Codex helper execution received an oversized hook i\
|
|
517
|
+
nventory.");return{fingerprint:S,hookKeys:v.filter(T=>!T.isManaged).map(T=>T.key)}}function k({effort:p="",summary:m="",
|
|
518
|
+
hookKeys:h=[],mcpServerNames:v=[]}={}){let S={features:Object.fromEntries(n.map(C=>[C,!1])),hooks:{state:Object.fromEntries(
|
|
519
|
+
h.map(C=>[C,{enabled:!1}]))},include_apps_instructions:!1,include_collaboration_mode_instructions:!1,include_environment_context:!1,
|
|
520
|
+
include_permissions_instructions:!1,...p?{model_reasoning_effort:p}:{},...m?{model_reasoning_summary:m}:{},mcp_servers:Object.
|
|
521
|
+
fromEntries(v.map(C=>[C,{enabled:!1}])),memories:{dedicated_tools:!1,generate_memories:!1,use_memories:!1},notify:[],orchestrator:{
|
|
521
522
|
mcp:{enabled:!1},skills:{enabled:!1}},project_doc_max_bytes:0,shell_environment_policy:{inherit:"none",set:{}},skills:{include_instructions:!1},
|
|
522
|
-
tools:{experimental_request_user_input:{enabled:!1},update_plan:{enabled:!1}},web_search:"disabled"},
|
|
523
|
-
|
|
524
|
-
summary:
|
|
525
|
-
"function"||typeof
|
|
526
|
-
let
|
|
527
|
-
cted during helper policy verification.");let
|
|
528
|
-
cted during helper policy verification.");let{mcpServerNames:
|
|
529
|
-
freeze({accountIdentitySignature:
|
|
530
|
-
fingerprint,hookKeys:Object.freeze([...E.hookKeys]),mcpServerNames:Object.freeze([...
|
|
531
|
-
accountIdentitySignature===
|
|
532
|
-
|
|
533
|
-
[])}function
|
|
534
|
-
|
|
535
|
-
codexAppServerHelperThreadCleanupRequired=!0,
|
|
536
|
-
threadId:h=""}={}){let
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
await
|
|
540
|
-
"function")throw l("Codex helper execution cannot own and clean up its app-server thread.");let h=await
|
|
541
|
-
h.settings),
|
|
542
|
-
|
|
543
|
-
"Codex helper execution cannot safely resume and clean up its app-server thread.");let
|
|
544
|
-
r resume requires a controller-owned thread id.");let
|
|
545
|
-
|
|
546
|
-
return
|
|
547
|
-
sandbox:
|
|
548
|
-
null,dynamicTools:[],environments:[],model:
|
|
549
|
-
return{...
|
|
550
|
-
baseInstructions,config:
|
|
551
|
-
sandbox:
|
|
552
|
-
environments:[],model:h.model,outputSchema:
|
|
553
|
-
none"};return h.request.reasoning&&(
|
|
554
|
-
inspect:
|
|
555
|
-
start:
|
|
523
|
+
tools:{experimental_request_user_input:{enabled:!1},update_plan:{enabled:!1}},web_search:"disabled"},T=Xs(S);return g.add(
|
|
524
|
+
T),T}function R(p,m,h,{effort:v="",summary:S=""}={}){let T=q(p),C=H(m,h);return{mcpServerNames:T,hookState:C,config:k({effort:v,
|
|
525
|
+
summary:S,hookKeys:C.hookKeys,mcpServerNames:T})}}async function O(p,{effort:m="",summary:h=""}={}){if(L(p),typeof p?.readConfig!=
|
|
526
|
+
"function"||typeof p?.listHooks!="function")throw l("Codex helper execution cannot inventory configuration and hooks.");
|
|
527
|
+
let v=await P(p),S=_(p),T=await p.readConfig({cwd:v.cwd,includeLayers:!1});if(_(p)!==S)throw l("Codex app-server reconne\
|
|
528
|
+
cted during helper policy verification.");let C=await p.listHooks([v.cwd]);if(_(p)!==S)throw l("Codex app-server reconne\
|
|
529
|
+
cted during helper policy verification.");let{mcpServerNames:M,hookState:E,config:te}=R(T,C,v.cwd,{effort:m,summary:h});
|
|
530
|
+
return Object.freeze({accountIdentitySignature:v.accountIdentitySignature,config:te,connectionGeneration:S,executionCwd:v.
|
|
531
|
+
cwd,hookFingerprint:E.fingerprint,hookKeys:Object.freeze([...E.hookKeys]),mcpServerNames:Object.freeze([...M])})}function D(p=null,m=null){
|
|
532
|
+
return p?.accountIdentitySignature===m?.accountIdentitySignature&&p?.connectionGeneration===m?.connectionGeneration&&p?.
|
|
533
|
+
executionCwd===m?.executionCwd&&p?.hookFingerprint===m?.hookFingerprint&&JSON.stringify(p?.mcpServerNames||[])===JSON.stringify(
|
|
534
|
+
m?.mcpServerNames||[])}function W(p,m,h=""){let v=b(h);if(!m)return p.codexAppServerHelperThreadId=v,p.codexAppServerHelperThreadRetired=
|
|
535
|
+
!0,p;let S=l("Codex could not retire a helper thread after policy verification failed.",{cleanupFailed:!0,threadId:v});return S.
|
|
536
|
+
codexAppServerHelperThreadCleanupRequired=!0,S.codexAppServerHelperThreadId=v,S}async function fe({error:p=null,provider:m=null,
|
|
537
|
+
threadId:h=""}={}){let v=null;try{await m.deleteThread(h)}catch(S){v=S}throw W(p,v,h)}async function Tt(p,m,h,v,S){try{let T=await O(
|
|
538
|
+
p,{effort:m.config.model_reasoning_effort,summary:m.config.model_reasoning_summary});if(!D(m,T))throw l(`Codex execution\
|
|
539
|
+
surfaces changed while the helper thread was ${S}.`);return Object.freeze({enforcement:T,thread:h,threadId:v})}catch(T){
|
|
540
|
+
await fe({error:T,provider:p,threadId:v})}}async function Se(p,m){if(typeof p?.startThread!="function"||typeof p?.deleteThread!=
|
|
541
|
+
"function")throw l("Codex helper execution cannot own and clean up its app-server thread.");let h=await m(),v=await p.startThread(
|
|
542
|
+
h.settings),S=b(v?.id);if(!S)throw l("Codex app-server did not return a helper thread id.");return Tt(p,h.enforcement,v,
|
|
543
|
+
S,"starting")}async function _t(p,m,h){if(typeof p?.resumeThread!="function"||typeof p?.deleteThread!="function")throw l(
|
|
544
|
+
"Codex helper execution cannot safely resume and clean up its app-server thread.");let v=b(m);if(!v)throw l("Codex helpe\
|
|
545
|
+
r resume requires a controller-owned thread id.");let S=await h(),T=S.enforcement,C=await p.resumeThread(v,S.settings);return Tt(
|
|
546
|
+
p,T,C,v,"resuming")}function ke(p){return g.has(p)}function Ct({configResult:p,hookResult:m,workdir:h,effort:v="",summary:S=""}){
|
|
547
|
+
return R(p,m,h,{effort:v,summary:S}).config}function yr({approvalPolicy:p,baseInstructions:m,config:h,cwd:v,effectiveSettings:S,
|
|
548
|
+
sandbox:T,systemPrompt:C}){return{allowProviderModelFallback:!1,approvalPolicy:p,baseInstructions:m,config:h,cwd:v,systemPrompt:C||
|
|
549
|
+
null,dynamicTools:[],environments:[],model:S.model,runtimeWorkspaceRoots:[],sandbox:T,selectedCapabilityRoots:[]}}function Ir(p,m){
|
|
550
|
+
return{...p,sessionStartSource:"startup",threadSource:m}}function Sr(p){return{approvalPolicy:p.approvalPolicy,baseInstructions:p.
|
|
551
|
+
baseInstructions,config:p.config,cwd:p.cwd,systemPrompt:p.systemPrompt,model:p.model,runtimeWorkspaceRoots:p.runtimeWorkspaceRoots,
|
|
552
|
+
sandbox:p.sandbox}}function y({approvalPolicy:p,cwd:m,effectiveSettings:h,outputSchema:v}){let S={approvalPolicy:p,cwd:m,
|
|
553
|
+
environments:[],model:h.model,outputSchema:v,runtimeWorkspaceRoots:[],sandboxPolicy:{networkAccess:!1,type:"readOnly"},summary:"\
|
|
554
|
+
none"};return h.request.reasoning&&(S.effort=h.thinking),S}return Object.freeze({assertCompatibility:L,executionContext:P,
|
|
555
|
+
inspect:O,configuration:Ct,hasConfiguration:ke,threadSettings:yr,threadStartSettings:Ir,threadResumeSettings:Sr,turnSettings:y,
|
|
556
|
+
start:Se,resume:_t})}var sy=hu();var AS=Object.freeze({PROVIDER_FAILURE:"provider_failure",RESPONSE_DELIVERY_FAILURE:"response_delivery_failure",SERVICE_RESTART:"\
|
|
556
557
|
service_restart",USER_CANCELLED:"user_cancelled",CONTROL_RECONFIGURATION:"control_reconfiguration",INTERRUPTED:"interrup\
|
|
557
|
-
ted"});var
|
|
558
|
+
ted"});var $S=Number.MAX_SAFE_INTEGER;var Mu=(Number(process.env.AGENT_REPLY_MINUTES)||15)*60*1e3;function fn(t){return{stoppedShort:`(Check from ${t}: your reply ended by saying what you'd do next, and then stopped, s\
|
|
558
559
|
o the person is left waiting. Carry on now with your tools and finish the job, then reply with the result. If you can't,\
|
|
559
560
|
say plainly why.)`,markup:`(Check from ${t}: your last message contained raw markup, such as a tool call written out as\
|
|
560
561
|
text or special tokens, so nothing in it ran and the person can't read it. Carry on now: call the tools properly to do \
|
|
561
562
|
what's left, then reply in plain words.)`,unsupported:e=>`(Check from ${t}: your reply says ${e.map(n=>`"${n}"`).join(",\
|
|
562
563
|
")}, but no tool in this reply did that, so it hasn't happened. Do it now with the right tool, or answer again without \
|
|
563
564
|
saying it's done.)`,resumed:"(This reply was interrupted part-way, when the server running it stopped. Your steps so far\
|
|
564
|
-
are above and what they did stays done. Carry on from where you got to, without redoing them, and finish the job.)"}}var
|
|
565
|
+
are above and what they did stays done. Carry on from where you got to, without redoing them, and finish the job.)"}}var ux=["You check an assistant's reply against a record of what its tools did while writing that reply.","List each sta\
|
|
565
566
|
tement in the reply that says something was done in this reply (made, saved, sent, attached, added, changed, deleted, bo\
|
|
566
567
|
oked, set up, fixed, run, tested) that the record doesn't support.","A claim is supported if a tool call and its answer \
|
|
567
568
|
in the record show it happened. Ignore plans, offers, questions, advice, facts about the person, things said to have hap\
|
|
568
569
|
pened earlier in the conversation, and descriptions of what a file or app contains.",'Reply with JSON only: {"unsupporte\
|
|
569
570
|
d": ["short quote of each unsupported claim"]}, with [] when every claim is supported.'].join(`
|
|
570
|
-
`);var
|
|
571
|
-
|
|
572
|
-
typeof t.toJsonSchema=="function"&&typeof t.cleanup=="function"}function
|
|
573
|
-
let{items:n}=e;if(
|
|
574
|
-
" must define items as either a Schema instance or a field definition object.`);return{kind:"definition",definition:n}}function
|
|
575
|
-
if(!Object.hasOwn(e,"values"))return null;let{values:n}=e;if(
|
|
571
|
+
`);var Dx=64*1024;var Xu="the app",Bx=fn(Xu);var Vx=16*1024*1024;function $(t){if(t===null||typeof t!="object")return!1;let e=Object.getPrototypeOf(t);return e===Object.prototype||e===null||
|
|
572
|
+
Yu(e)}function Yu(t){return t!==null&&typeof t=="object"&&Object.getPrototypeOf(t)===null&&Reflect.ownKeys(t).length===0}function vn(t){return t!==null&&typeof t=="object"&&$(t.structure)&&$(t.operations)&&typeof t.validateWith=="function"&&
|
|
573
|
+
typeof t.toJsonSchema=="function"&&typeof t.cleanup=="function"}function rr(t,e){if(!Object.hasOwn(e,"items"))return null;
|
|
574
|
+
let{items:n}=e;if(vn(n))return{kind:"schema",schema:n};if(!$(n)||typeof n.type!="string")throw new Error(`Array field "${t}\
|
|
575
|
+
" must define items as either a Schema instance or a field definition object.`);return{kind:"definition",definition:n}}function gt(t,e){
|
|
576
|
+
if(!Object.hasOwn(e,"values"))return null;let{values:n}=e;if(vn(n))return{kind:"schema",schema:n};if(!$(n)||typeof n.type!=
|
|
576
577
|
"string")throw new Error(`Object field "${t}" must define values as either a Schema instance or a field definition objec\
|
|
577
|
-
t.`);return{kind:"definition",definition:n}}function
|
|
578
|
+
t.`);return{kind:"definition",definition:n}}function nr(t,e){let n=Object.hasOwn(e,"schema"),r=Object.hasOwn(e,"values"),
|
|
578
579
|
o=Object.hasOwn(e,"additionalProperties");if(n&&r)throw new Error(`Object field "${t}" cannot define both schema and val\
|
|
579
580
|
ues.`);if(o&&e.additionalProperties!==!0)throw new Error(`Object field "${t}" only supports additionalProperties: true.`);
|
|
580
581
|
if(r&&e.additionalProperties===!0)throw new Error(`Object field "${t}" cannot define both values and additionalPropertie\
|
|
581
|
-
s: true.`);if(n){if(!
|
|
582
|
-
kind:"nested",schema:e.schema,allowAdditionalProperties:e.additionalProperties===!0}}return r?{kind:"map",valuesConfig:
|
|
583
|
-
t,e)}:e.additionalProperties===!0?{kind:"opaque"}:{kind:"plain"}}function
|
|
584
|
-
if(
|
|
582
|
+
s: true.`);if(n){if(!vn(e.schema))throw new Error(`Object field "${t}" must define schema as a Schema instance.`);return{
|
|
583
|
+
kind:"nested",schema:e.schema,allowAdditionalProperties:e.additionalProperties===!0}}return r?{kind:"map",valuesConfig:gt(
|
|
584
|
+
t,e)}:e.additionalProperties===!0?{kind:"opaque"}:{kind:"plain"}}function Ve(t){return t?.type==="number"||t?.type==="integer"||t?.type==="epochMilliseconds"||t?.type==="epochSeconds"}function wn(t,e=""){
|
|
585
|
+
if($(t))for(let[n,r]of Object.entries(t)){if(!$(r))continue;let o=e?`${e}.${n}`:n;for(let s of["minItems","maxItems"]){if(!Object.
|
|
585
586
|
hasOwn(r,s))continue;let i=r[s];if(r.type!=="array"||!Number.isInteger(i)||i<0)throw new Error(`Field "${o}" ${s} must b\
|
|
586
587
|
e a non-negative integer on an array field.`)}if(r.minItems>r.maxItems)throw new Error(`Field "${o}" minItems (${r.minItems}\
|
|
587
|
-
) is above its maxItems (${r.maxItems}).`);r.type==="array"
|
|
588
|
-
o)}}var
|
|
589
|
-
|
|
590
|
-
$`,
|
|
591
|
-
))?${
|
|
592
|
-
0)}function
|
|
593
|
-
1&&o<=12&&s>=1&&s<=
|
|
594
|
-
`temporalPrecision for "${e}" must be a non-negative integer.`);return n}}function
|
|
595
|
-
t.length<=e}function
|
|
596
|
-
if(typeof t!="string")return!1;let n=
|
|
597
|
-
let n=
|
|
598
|
-
"":`(?:\\.\\d{1,${t}})?`}function
|
|
599
|
-
return`^${
|
|
600
|
-
test(t))n=Number(t);else return null;return!Number.isSafeInteger(n)||n<-e||n>e?null:n===0?0:n}var
|
|
601
|
-
has(t))throw new Error(`${e}() received unsafe path segment "${t}".`)}function
|
|
602
|
-
/\[(.+?)\]/g,".$1").replace(/^\.+/,"").replace(/\.+/g,".").replace(/\.$/,"")}function
|
|
603
|
-
let o=n?
|
|
588
|
+
) is above its maxItems (${r.maxItems}).`);r.type==="array"&&$(r.items)&&typeof r.items.type=="string"&&wn({"[]":r.items},
|
|
589
|
+
o)}}var yn="^(?:0|-?[1-9]\\d*)$",oi="\\d{4}",si="0[1-9]|1[0-2]",ii="0[1-9]|[12]\\d|3[01]",ai="[01]\\d|2[0-3]",Ge="[0-5]\\d",
|
|
590
|
+
or=`(?:${ai}):${Ge}`,ci=`(?:Z|[+-](?:${ai}):${Ge})`,di=`(${oi})-(${si})-(${ii})`,ui=`${oi}-(?:${si})-(?:${ii})`,li=`^${ui}\
|
|
591
|
+
$`,Zu=new RegExp(`^${di}$`),Qu=new RegExp(`^${or}(?::${Ge}(?:\\.(\\d+))?)?$`),el=new RegExp(`^${di}T${or}:${Ge}(?:\\.(\\d+\
|
|
592
|
+
))?${ci}$`),tl=new RegExp(yn),rl=[31,28,31,30,31,30,31,31,30,31,30,31];function nl(t){return t%4===0&&(t%100!==0||t%400===
|
|
593
|
+
0)}function ol(t,e){return e===2?nl(t)?29:28:rl[e-1]}function pi(t,e,n){let r=Number(t),o=Number(e),s=Number(n);return o>=
|
|
594
|
+
1&&o<=12&&s>=1&&s<=ol(r,o)}function vt(t,e){let n=t.temporalPrecision;if(n!==void 0){if(!Number.isInteger(n)||n<0)throw new Error(
|
|
595
|
+
`temporalPrecision for "${e}" must be a non-negative integer.`);return n}}function fi(t,e){return t===void 0?!0:e===void 0||
|
|
596
|
+
t.length<=e}function mi(t){if(typeof t!="string")return!1;let e=Zu.exec(t);return e!==null&&pi(e[1],e[2],e[3])}function hi(t,e){
|
|
597
|
+
if(typeof t!="string")return!1;let n=Qu.exec(t);return n!==null&&fi(n[1],e)}function gi(t,e){if(typeof t!="string")return!1;
|
|
598
|
+
let n=el.exec(t);return n===null?!1:pi(n[1],n[2],n[3])&&fi(n[4],e)}function vi(t){return t===void 0?"(?:\\.\\d+)?":t===0?
|
|
599
|
+
"":`(?:\\.\\d{1,${t}})?`}function wi(t,e){let n=vt(t,e);return`^${or}(?::${Ge}${vi(n)})?$`}function yi(t,e){let n=vt(t,e);
|
|
600
|
+
return`^${ui}T${or}:${Ge}${vi(n)}${ci}$`}function In(t,e){let n;if(typeof t=="number")n=t;else if(typeof t=="string"&&tl.
|
|
601
|
+
test(t))n=Number(t);else return null;return!Number.isSafeInteger(n)||n<-e||n>e?null:n===0?0:n}var sl=new Set(["__proto__","prototype","constructor"]);function A(t,e,n){Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0})}function il(t,e){if(sl.
|
|
602
|
+
has(t))throw new Error(`${e}() received unsafe path segment "${t}".`)}function al(t){return typeof t!="string"?t:t.replace(
|
|
603
|
+
/\[(.+?)\]/g,".$1").replace(/^\.+/,"").replace(/\.+/g,".").replace(/\.$/,"")}function Sn(t,e,{normalize:n=!1,allowEmpty:r=!1}={}){
|
|
604
|
+
let o=n?al(t):t;if(typeof o!="string"||o.trim()===""){if(r&&o==="")return[];throw new Error(`${e}() expects a non-empty \
|
|
604
605
|
dotted path string.`)}let s=o.split(".");if(s.some(i=>i===""))throw new Error(`${e}() received an invalid path "${o}".`);
|
|
605
|
-
for(let i of s)
|
|
606
|
-
|
|
607
|
-
return{anyOf:[{type:"integer",minimum:-t,maximum:t},{type:"string",pattern:
|
|
608
|
-
none:()=>({type:
|
|
606
|
+
for(let i of s)il(i,e);return s}var cl="http://json-schema.org/draft-07/schema#",ye="x-json-rest-schema",xn=["object","array","string","number","boolean"],
|
|
607
|
+
bn=Symbol("json-rest-schema.exportContext"),dl=["true","1","yes","y","on"],ul=["false","0","no","n","off"];function Ii(t){
|
|
608
|
+
return{anyOf:[{type:"integer",minimum:-t,maximum:t},{type:"string",pattern:yn}]}}function Oe(t,e){return{[ye]:{[t]:e}}}var ll={
|
|
609
|
+
none:()=>({type:xn}),blob:()=>({type:xn}),serialize:()=>({type:xn}),object:()=>({type:"object"}),array:()=>({type:"array"}),
|
|
609
610
|
file:()=>({type:"string"}),string:()=>({type:"string"}),number:()=>({type:["number","string"]}),integer:()=>({type:["int\
|
|
610
|
-
eger","string"]}),epochMilliseconds:()=>
|
|
611
|
-
type:"string",format:"date-time",pattern:
|
|
612
|
-
fieldName:e})=>({type:"string",pattern:
|
|
613
|
-
let e=new Set([...
|
|
611
|
+
eger","string"]}),epochMilliseconds:()=>Ii(864e13),epochSeconds:()=>Ii(864e10),dateTime:({definition:t,fieldName:e})=>({
|
|
612
|
+
type:"string",format:"date-time",pattern:yi(t,e)}),date:()=>({type:"string",format:"date",pattern:li}),time:({definition:t,
|
|
613
|
+
fieldName:e})=>({type:"string",pattern:wi(t,e)}),boolean:({definition:t})=>{if(t.strictBoolean===!0)return{type:"boolean"};
|
|
614
|
+
let e=new Set([...dl,String(t.stringTrueWhen||"true").trim().toLowerCase()]),n=new Set([...ul,String(t.stringFalseWhen||
|
|
614
615
|
"false").trim().toLowerCase()]);return{anyOf:[{type:"boolean"},{type:"number",enum:[0,1]},{type:"string",enum:[...n,...e]}]}},
|
|
615
|
-
id:()=>({type:["integer","string"],minimum:1,pattern:"^[1-9][0-9]*$"})},
|
|
616
|
+
id:()=>({type:["integer","string"],minimum:1,pattern:"^[1-9][0-9]*$"})},pl={minLength:({definition:t,parameterValue:e})=>t.
|
|
616
617
|
type==="string"?{minLength:e}:null,maxLength:({definition:t,parameterValue:e})=>t.type==="string"?{maxLength:e}:null,min:({
|
|
617
|
-
definition:t,parameterValue:e})=>
|
|
618
|
+
definition:t,parameterValue:e})=>Ve(t)?{minimum:e}:null,max:({definition:t,parameterValue:e})=>Ve(t)?{maximum:e}:null,pattern:({
|
|
618
619
|
definition:t,parameterValue:e})=>t.type==="string"?{pattern:e instanceof RegExp?e.source:e}:null,enum:({parameterValue:t})=>({
|
|
619
620
|
enum:t}),minItems:({definition:t,parameterValue:e})=>t.type==="array"?{minItems:e}:null,maxItems:({definition:t,parameterValue:e})=>t.
|
|
620
621
|
type==="array"?{maxItems:e}:null,notEmpty:({parameterValue:t,definition:e})=>!t||e.type==="array"?null:{minLength:1},uppercase:({
|
|
621
|
-
parameterValue:t})=>t?
|
|
622
|
-
null,length:({parameterValue:t})=>
|
|
623
|
-
null,precision:({parameterValue:t})=>
|
|
624
|
-
parameterValue:t})=>
|
|
625
|
-
defaultTo:()=>null};function
|
|
626
|
-
"object"&&!Array.isArray(r)&&!Array.isArray(o)){
|
|
622
|
+
parameterValue:t})=>t?Oe("transforms",{uppercase:!0}):null,lowercase:({parameterValue:t})=>t?Oe("transforms",{lowercase:!0}):
|
|
623
|
+
null,length:({parameterValue:t})=>Oe("transforms",{length:t}),unsigned:({parameterValue:t})=>t?Oe("metadata",{unsigned:!0}):
|
|
624
|
+
null,precision:({parameterValue:t})=>Oe("metadata",{precision:t}),scale:({parameterValue:t})=>Oe("metadata",{scale:t}),temporalPrecision:({
|
|
625
|
+
parameterValue:t})=>Oe("metadata",{temporalPrecision:t}),strictBoolean:()=>null,required:()=>null,nullable:()=>null,nullOnEmpty:()=>null,
|
|
626
|
+
defaultTo:()=>null};function An(t,e){for(let n of Object.keys(e)){let r=e[n],o=t[n];if(r&&o&&typeof r=="object"&&typeof o==
|
|
627
|
+
"object"&&!Array.isArray(r)&&!Array.isArray(o)){An(o,r);continue}t[n]=r}}function fl(t,e){if(!e||typeof e!="object"||Array.
|
|
627
628
|
isArray(e))throw new Error("JSON Schema export hooks must return an object or null.");for(let n of Object.keys(e)){if(n===
|
|
628
|
-
|
|
629
|
-
t[n]=e[n]}}function
|
|
630
|
-
1?t:{anyOf:r}}function
|
|
631
|
-
let n=t.types[e.type];if(typeof n.toJsonSchema=="function")return n.toJsonSchema;let r=
|
|
632
|
-
`Type '${e.type}' cannot be exported to JSON Schema without a toJsonSchema hook.`);return r}function
|
|
633
|
-
hasOwn(t.validators,e))return null;let r=t.validators[e];if(typeof r.toJsonSchema=="function")return r.toJsonSchema;let o=
|
|
629
|
+
ye&&t[n]&&typeof t[n]=="object"&&typeof e[n]=="object"&&!Array.isArray(t[n])&&!Array.isArray(e[n])){An(t[n],e[n]);continue}
|
|
630
|
+
t[n]=e[n]}}function ml(t,e){let r=[...Array.isArray(t.anyOf)&&Object.keys(t).length===1?t.anyOf:[t],...e];return r.length===
|
|
631
|
+
1?t:{anyOf:r}}function hl(t,e){if(!Object.hasOwn(t.types,e.type))throw new Error(`No casting function for type: ${e.type}`);
|
|
632
|
+
let n=t.types[e.type];if(typeof n.toJsonSchema=="function")return n.toJsonSchema;let r=ll[e.type];if(!r)throw new Error(
|
|
633
|
+
`Type '${e.type}' cannot be exported to JSON Schema without a toJsonSchema hook.`);return r}function gl(t,e,n){if(!Object.
|
|
634
|
+
hasOwn(t.validators,e))return null;let r=t.validators[e];if(typeof r.toJsonSchema=="function")return r.toJsonSchema;let o=pl[e];
|
|
634
635
|
if(o)return o;throw new Error(`Validator '${e}' on field '${n}' cannot be exported to JSON Schema without a toJsonSchema\
|
|
635
|
-
hook.`)}function
|
|
636
|
-
`Unsupported JSON Schema export mode '${t}'. Expected 'create', 'replace', or 'patch'.`)}function
|
|
637
|
-
void 0&&e.operation!==void 0){let n=
|
|
636
|
+
hook.`)}function Si(t){if(t===void 0)return"create";if(["create","replace","patch"].includes(t))return t;throw new Error(
|
|
637
|
+
`Unsupported JSON Schema export mode '${t}'. Expected 'create', 'replace', or 'patch'.`)}function vl(t,e={}){if(e.mode!==
|
|
638
|
+
void 0&&e.operation!==void 0){let n=Si(e.mode);if(n!==e.operation)throw new Error(`Conflicting JSON Schema export option\
|
|
638
639
|
s: mode '${n}' does not match operation '${e.operation}'.`)}if(e.operation!==void 0){if(!Object.hasOwn(t.operations,e.operation))
|
|
639
|
-
throw new Error(`Unknown JSON Schema export operation '${e.operation}'.`);return e.operation}return
|
|
640
|
+
throw new Error(`Unknown JSON Schema export operation '${e.operation}'.`);return e.operation}return Si(e.mode)}function wl(t,e={}){
|
|
640
641
|
if(e.operationName!==void 0&&e.operationDescriptor!==void 0)return{operationName:e.operationName,operation:e.operationDescriptor};
|
|
641
|
-
let n=
|
|
642
|
-
e,
|
|
643
|
-
t[
|
|
644
|
-
"_").replace(/^_+|_+$/g,"")||"operation"}function
|
|
645
|
-
function
|
|
646
|
-
n&&s.operation===r&&s.additionalProperties===o)||null}function
|
|
647
|
-
return t.nextDefinitionId+=1,r}function
|
|
642
|
+
let n=vl(t,e);return{operationName:n,operation:t.operations[n]}}function yl(t={}){let e={...t};return Object.defineProperty(
|
|
643
|
+
e,bn,{value:{definitions:{},nodes:[],nextDefinitionId:1,rootNode:null},enumerable:!1}),e}function ir(t={}){return t[bn]?
|
|
644
|
+
t[bn]:{definitions:{},nodes:[],nextDefinitionId:1,rootNode:null}}function Il(t){return String(t).replace(/[^a-zA-Z0-9]+/g,
|
|
645
|
+
"_").replace(/^_+|_+$/g,"")||"operation"}function Tn(t){return $(t)&&Object.keys(t).length===1&&typeof t.$ref=="string"}
|
|
646
|
+
function sr(t){return Tn(t)?{allOf:[t]}:t}function Sl(t,e,n,r,o){return t.nodes.find(s=>s.schema===e&&s.operationName===
|
|
647
|
+
n&&s.operation===r&&s.additionalProperties===o)||null}function xl(t,e){let n=Il(e),r=`SchemaNode_${t.nextDefinitionId}_${n}`;
|
|
648
|
+
return t.nextDefinitionId+=1,r}function xi(t,e,n,r,o,{root:s=!1}={}){let i=ir(e),a=Sl(i,t,n,r,o);if(a)return s&&(a.pointer=
|
|
648
649
|
"#",i.rootNode=a),a;let c={schema:t,operationName:n,operation:r,additionalProperties:o,status:"new",definitionName:s?null:
|
|
649
|
-
|
|
650
|
-
if(t.status==="built")return{$ref:t.pointer};if(t.status==="building")return{$ref:t.pointer};let n=
|
|
651
|
-
ing",t.pointer!=="#"&&(n.definitions[t.definitionName]={});let r=
|
|
652
|
-
return t.status="built",t.pointer==="#"?r:(n.definitions[t.definitionName]=r,{$ref:t.pointer})}function
|
|
653
|
-
let s=
|
|
654
|
-
referenceBacked:e}}function
|
|
650
|
+
xl(i,n),pointer:s?"#":null};return s?i.rootNode=c:c.pointer=`#/definitions/${c.definitionName}`,i.nodes.push(c),c}function bi(t,e){
|
|
651
|
+
if(t.status==="built")return{$ref:t.pointer};if(t.status==="building")return{$ref:t.pointer};let n=ir(e);t.status="build\
|
|
652
|
+
ing",t.pointer!=="#"&&(n.definitions[t.definitionName]={});let r=bl(t.schema,e,t.operationName,t.operation,t.additionalProperties);
|
|
653
|
+
return t.status="built",t.pointer==="#"?r:(n.definitions[t.definitionName]=r,{$ref:t.pointer})}function En(t,e,n,r,o=!1){
|
|
654
|
+
let s=ir(e),i=xi(t,e,n,r,o);return s.rootNode===i?{$ref:"#"}:bi(i,e)}function wt(t,{referenceBacked:e=!1}={}){return{schema:t,
|
|
655
|
+
referenceBacked:e}}function bl(t,e,n,r,o=!1){let s={},i=[];for(let[c,d]of Object.entries(t.structure))A(s,c,On(t,c,d,e,n,
|
|
655
656
|
r)),r.enforceRequired&&d.required===!0&&i.push(c);let a={type:"object",properties:s,additionalProperties:o};return i.length>
|
|
656
|
-
0&&(a.required=i),a}function
|
|
657
|
-
r,"replace",i.schema.operations.replace,!1)),[
|
|
658
|
-
"schema")?"replace":o,c=a==="replace"?t.operations.replace:s;return
|
|
659
|
-
let i=
|
|
660
|
-
[
|
|
661
|
-
place"?t.operations.replace:s;return
|
|
662
|
-
e,n);if(a.kind==="nested")return
|
|
663
|
-
"opaque")return
|
|
664
|
-
t,e,n,r,o,s)})}let i=
|
|
657
|
+
0&&(a.required=i),a}function Tl(t,e,n,r,o,s){let i=rr(e,n);if(!i)return null;if(i.kind==="schema")return{...sr(En(i.schema,
|
|
658
|
+
r,"replace",i.schema.operations.replace,!1)),[ye]:{castType:"object"}};let a=n.items.type==="object"&&Object.hasOwn(n.items,
|
|
659
|
+
"schema")?"replace":o,c=a==="replace"?t.operations.replace:s;return On(t,`${e}[]`,n.items,r,a,c)}function _l(t,e,n,r,o,s){
|
|
660
|
+
let i=gt(e,n);if(!i)return null;if(i.kind==="schema")return{...sr(En(i.schema,r,"replace",i.schema.operations.replace,!1)),
|
|
661
|
+
[ye]:{castType:"object"}};let a=i.definition.type==="object"&&Object.hasOwn(i.definition,"schema")?"replace":o,c=a==="re\
|
|
662
|
+
place"?t.operations.replace:s;return On(t,`${e}.*`,i.definition,r,a,c)}function Cl(t,e,n,r,o,s){if(n.type==="object"){let a=nr(
|
|
663
|
+
e,n);if(a.kind==="nested")return wt(En(a.schema,r,o,s,a.allowAdditionalProperties===!0),{referenceBacked:!0});if(a.kind===
|
|
664
|
+
"opaque")return wt({type:"object",additionalProperties:!0});if(a.kind==="map")return wt({type:"object",additionalProperties:_l(
|
|
665
|
+
t,e,n,r,o,s)})}let i=hl(t,n)({schema:t,fieldName:e,definition:n,operation:o,mode:o,options:r});if(!i||typeof i!="object"||
|
|
665
666
|
Array.isArray(i))throw new Error(`Type '${n.type}' on field '${e}' returned an invalid JSON Schema fragment.`);if(n.type===
|
|
666
|
-
"array"){let a=
|
|
667
|
-
function
|
|
668
|
-
|
|
669
|
-
continue;let
|
|
670
|
-
c[
|
|
671
|
-
let
|
|
667
|
+
"array"){let a=Tl(t,e,n,r,o,s);if(a)return wt({...i,items:a},{referenceBacked:Tn(i)})}return wt(i,{referenceBacked:Tn(i)})}
|
|
668
|
+
function On(t,e,n,r,o,s){let i={schema:t,fieldName:e,definition:n,operation:o,mode:o,options:r},a=Cl(t,e,n,r,o,s),c=a.referenceBacked?
|
|
669
|
+
sr(a.schema):{...a.schema},d={castType:n.type};for(let l of Object.keys(n)){if(l==="type"||!Object.hasOwn(t.validators,l))
|
|
670
|
+
continue;let g=gl(t,l,e);if(!g)continue;let I=g({...i,parameterName:l,parameterValue:n[l],fieldSchema:{...c}});I&&fl(c,I)}
|
|
671
|
+
c[ye]&&(An(d,c[ye]),delete c[ye]);let u=[];n.nullable===!0&&u.push({type:"null"}),n.nullOnEmpty===!0&&u.push({const:""});
|
|
672
|
+
let f=sr(ml(c,u));if(n.defaultTo!==void 0&&s.applyDefaults)if(typeof n.defaultTo!="function"){let l=t._normalizeDefault(
|
|
672
673
|
n,n.defaultTo,{fieldPath:e,currentObject:{},containerKey:e,objectBeforeCast:{},options:{},settings:t._buildOperationSettings(
|
|
673
|
-
o,s,{})});if(Object.keys(l.errors).length>0){let
|
|
674
|
-
nvalid (${
|
|
675
|
-
e),{operationName:r,operation:o}=
|
|
676
|
-
o,s,{root:!0}),c={$schema:
|
|
677
|
-
|
|
678
|
-
.${String(e)}`}function
|
|
679
|
-
startsWith(n)?t.slice(n.length):null}function
|
|
680
|
-
{...r,field:o})}return n}function
|
|
681
|
-
o=e;for(let s=0;s<r.length;s++){let i=r[s];Object.hasOwn(o,i)||
|
|
682
|
-
return e}function
|
|
683
|
-
function
|
|
674
|
+
o,s,{})});if(Object.keys(l.errors).length>0){let g=Object.values(l.errors)[0];throw new Error(`defaultTo for "${e}" is i\
|
|
675
|
+
nvalid (${g.code}).`)}f.default=l.value}else d.defaults={providedByFunction:!0};return f[ye]=d,f}function Ti(t,e={}){let n=yl(
|
|
676
|
+
e),{operationName:r,operation:o}=wl(t,n),s=n.additionalProperties===void 0?!1:n.additionalProperties,i=ir(n),a=xi(t,n,r,
|
|
677
|
+
o,s,{root:!0}),c={$schema:cl,...bi(a,n)};return Object.keys(i.definitions).length>0&&(c.definitions=i.definitions),c}function _i(t){return t!==null&&(typeof t=="object"||typeof t=="function")&&typeof t.then=="function"}function jn(t){return t instanceof
|
|
678
|
+
Je}function Al(){return{self:!1,children:{}}}function Ci(t){return Object.keys(t.children).length>0}function Re(t,e){return`${t}\
|
|
679
|
+
.${String(e)}`}function ki(t,e){return t===""?String(e):Re(t,e)}function Ai(t,e){if(t===e)return"";let n=`${e}.`;return t.
|
|
680
|
+
startsWith(n)?t.slice(n.length):null}function We(t,e){let n={};for(let r of Object.values(t)){let o=Re(e,r.field);A(n,o,
|
|
681
|
+
{...r,field:o})}return n}function Nn(t){return Sn(t,"validatePath")}function Ei(t){let e={};for(let n of t){let r=Nn(n),
|
|
682
|
+
o=e;for(let s=0;s<r.length;s++){let i=r[s];Object.hasOwn(o,i)||A(o,i,Al()),s===r.length-1&&(o[i].self=!0),o=o[i].children}}
|
|
683
|
+
return e}function El(t,e){let n=t;for(let r of e){if(n==null||typeof n!="object"||!Object.hasOwn(n,r))return;n=n[r]}return n}
|
|
684
|
+
function ar(t){return t===null?!0:Array.isArray(t)||$(t)?Object.keys(t).length>0:t!==void 0}function Oi(t){return[...t].
|
|
684
685
|
sort((e,n)=>{let r=/^[0-9]+$/.test(e),o=/^[0-9]+$/.test(n);return r&&o?Number(e)-Number(n):r?-1:o?1:e.localeCompare(n)})}
|
|
685
|
-
function
|
|
686
|
+
function Ol(t){return/^[0-9]+$/.test(t)}function Rl(t,e=new WeakMap){if(e.has(t))return e.get(t);let n=Object.create(Je.
|
|
686
687
|
prototype);return e.set(t,n),n.structure=null,n.types=t.types,n.validators=t.validators,n.operations=t.operations,n.structure=
|
|
687
|
-
|
|
688
|
-
"object")return t;if(
|
|
688
|
+
dr(cr(t.structure,e)),n._installOperationMethods(),Object.freeze(n)}function cr(t,e=new WeakMap){if(t===null||typeof t!=
|
|
689
|
+
"object")return t;if(jn(t))return Rl(t,e);if(t instanceof Date)return new Date(t.getTime());if(t instanceof RegExp){let r=new RegExp(
|
|
689
690
|
t.source,t.flags);return r.lastIndex=t.lastIndex,r}if(e.has(t))return e.get(t);if(Array.isArray(t)){let r=[];e.set(t,r);
|
|
690
|
-
for(let o of t)r.push(
|
|
691
|
-
o,e));return n}function
|
|
692
|
-
isArray(t))for(let n of t)
|
|
693
|
-
return
|
|
694
|
-
if(!Object.hasOwn(t.structure,r))return null;let s=t.structure[r];if(o.length<1)return s;let i=
|
|
695
|
-
function
|
|
696
|
-
n,r)}if(e?.type==="array"){let o=t._resolveArrayItemsConfig(r,e);if(!o||n.length<1)return null;let[s,...i]=n;if(!
|
|
697
|
-
let a=
|
|
698
|
-
function
|
|
699
|
-
"");r.length>0?n.skipFields=r:delete n.skipFields}if(
|
|
700
|
-
let i=
|
|
691
|
+
for(let o of t)r.push(cr(o,e));return r}if(!$(t))return t;let n={};e.set(t,n);for(let[r,o]of Object.entries(t))A(n,r,cr(
|
|
692
|
+
o,e));return n}function dr(t,e=new WeakSet){if(t===null||typeof t!="object"||e.has(t)||jn(t))return t;if(e.add(t),Array.
|
|
693
|
+
isArray(t))for(let n of t)dr(n,e);else for(let n of Reflect.ownKeys(t))dr(t[n],e);return Object.freeze(t)}function Rn(t){
|
|
694
|
+
return dr(cr(t))}var Pn=new WeakMap;function Mn(t,e,n=""){if(!jn(t)||!Array.isArray(e)||e.length<1)return null;let[r,...o]=e;
|
|
695
|
+
if(!Object.hasOwn(t.structure,r))return null;let s=t.structure[r];if(o.length<1)return s;let i=ki(n,r);return Ni(t,s,o,i)}
|
|
696
|
+
function Ni(t,e,n,r){if(e?.type==="object"){let o=t._resolveObjectFieldMode(r,e);return o.kind!=="nested"?null:Mn(o.schema,
|
|
697
|
+
n,r)}if(e?.type==="array"){let o=t._resolveArrayItemsConfig(r,e);if(!o||n.length<1)return null;let[s,...i]=n;if(!Ol(s))return null;
|
|
698
|
+
let a=Re(r,s);return o.kind==="schema"?i.length<1?null:Mn(o.schema,i,a):i.length<1?o.definition:Ni(t,o.definition,i,a)}return null}
|
|
699
|
+
function Ke(t,e){let n={...t};if(Array.isArray(t.skipFields)){let r=t.skipFields.map(o=>Ai(o,e)).filter(o=>o!==null&&o!==
|
|
700
|
+
"");r.length>0?n.skipFields=r:delete n.skipFields}if($(t.skipParams)){let r={};for(let[o,s]of Object.entries(t.skipParams)){
|
|
701
|
+
let i=Ai(o,e);i===null||i===""||A(r,i,s)}Object.keys(r).length>0?n.skipParams=r:delete n.skipParams}return n}var Pl=Object.
|
|
701
702
|
freeze({create:Object.freeze({targetFields:"schema",enforceRequired:!0,applyDefaults:!0,outputFields:"validated",rejectExplicitUndefined:!0}),
|
|
702
703
|
replace:Object.freeze({targetFields:"schema",enforceRequired:!0,applyDefaults:!0,outputFields:"validated",rejectExplicitUndefined:!0}),
|
|
703
704
|
patch:Object.freeze({targetFields:"input",enforceRequired:!1,applyDefaults:!1,outputFields:"input",rejectExplicitUndefined:!0})});
|
|
704
|
-
function
|
|
705
|
-
", ")}.`)}function
|
|
706
|
-
must define ${n} as a boolean.`)}function
|
|
707
|
-
eration "${t}" must be an object.`);return
|
|
708
|
-
pplyDefaults"),
|
|
705
|
+
function Ri(t,e,n,r){let o=e[n];if(!r.includes(o))throw new Error(`Operation "${t}" must define ${n} as one of: ${r.join(
|
|
706
|
+
", ")}.`)}function kn(t,e,n,r=!0){let o=e[n];if(!(o===void 0&&!r)&&typeof o!="boolean")throw new Error(`Operation "${t}"\
|
|
707
|
+
must define ${n} as a boolean.`)}function kl(t,e){if(typeof e!="object"||e===null||Array.isArray(e))throw new Error(`Op\
|
|
708
|
+
eration "${t}" must be an object.`);return Ri(t,e,"targetFields",["schema","input"]),kn(t,e,"enforceRequired"),kn(t,e,"a\
|
|
709
|
+
pplyDefaults"),Ri(t,e,"outputFields",["validated","input"]),kn(t,e,"rejectExplicitUndefined",!1),Object.freeze({targetFields:e.
|
|
709
710
|
targetFields,enforceRequired:e.enforceRequired,applyDefaults:e.applyDefaults,outputFields:e.outputFields,rejectExplicitUndefined:e.
|
|
710
|
-
rejectExplicitUndefined===void 0?!0:e.rejectExplicitUndefined})}function
|
|
711
|
+
rejectExplicitUndefined===void 0?!0:e.rejectExplicitUndefined})}function Nl(t={}){if(typeof t!="object"||t===null||Array.
|
|
711
712
|
isArray(t))throw new Error("Schema operations must be an object.");let e=Object.create(null);for(let[n,r]of Object.entries(
|
|
712
|
-
|
|
713
|
-
null);for(let[n,r]of Object.entries(t))
|
|
714
|
-
delete e.mode,e}var
|
|
715
|
-
operations=
|
|
713
|
+
Pl))A(e,n,r);for(let[n,r]of Object.entries(t))A(e,n,kl(n,r));return Object.freeze(e)}function Pi(t){let e=Object.create(
|
|
714
|
+
null);for(let[n,r]of Object.entries(t))A(e,n,r);return Object.freeze(e)}function Ml(t){let e={...t};return delete e.operation,
|
|
715
|
+
delete e.mode,e}var Je=class{constructor(e,n,r,o={}){wn(e),this.structure=e,this.types=Pi(n),this.validators=Pi(r),this.
|
|
716
|
+
operations=Nl(o),this._installOperationMethods()}_typeError(e){return this._paramError(e,"TYPE_CAST_FAILED","Value could\
|
|
716
717
|
not be cast to the required type.")}_paramError(e,n,r,o={}){let s=new Error(r);return s.errorObject={field:e,code:n,message:r,
|
|
717
718
|
params:o},s}_paramToBeSkipped(e,n,r){return typeof n!="object"||n===null?!1:!!(Array.isArray(n[r])&&n[r].includes(e))}_fieldToBeSkipped(e,n){
|
|
718
|
-
return Array.isArray(n.skipFields)&&n.skipFields.includes(e)}_mergeErrors(e,n){for(let[r,o]of Object.entries(n))
|
|
719
|
-
let n={};return
|
|
719
|
+
return Array.isArray(n.skipFields)&&n.skipFields.includes(e)}_mergeErrors(e,n){for(let[r,o]of Object.entries(n))A(e,r,o)}_singleErrorMap(e){
|
|
720
|
+
let n={};return A(n,e.field,e),n}_assertSupportedOptions(e={}){if(Object.hasOwn(e,"onlyObjectValues"))throw new Error("U\
|
|
720
721
|
nsupported validation option `onlyObjectValues`. Call `patch()` directly.");if(Object.hasOwn(e,"mode"))throw new Error("\
|
|
721
722
|
Unsupported validation option `mode`. Call `validateWith()` or an operation method directly.");if(Object.hasOwn(e,"opera\
|
|
722
723
|
tion"))throw new Error("Unsupported validation option `operation`. Call `validateWith()` or an operation method directly\
|
|
723
724
|
.")}_buildOperationSettings(e,n,r){return{operationName:e,operation:n,targetFieldNames:n.targetFields==="input"?Object.keys(
|
|
724
725
|
r):Object.keys(this.structure),outputFieldNames:n.outputFields==="input"?Object.keys(r):Object.keys(this.structure),enforceRequired:n.
|
|
725
726
|
enforceRequired,applyDefaults:n.applyDefaults,rejectExplicitUndefined:n.rejectExplicitUndefined,defaultedFields:new Set,
|
|
726
|
-
isFieldPresent:o=>Object.hasOwn(r,o)}}_assertPlainObjectInput(e,n){if(
|
|
727
|
+
isFieldPresent:o=>Object.hasOwn(r,o)}}_assertPlainObjectInput(e,n){if(!$(n))throw new Error(`${e}() expects a plain obje\
|
|
727
728
|
ct input.`)}_resolvePathValidationRequest(e={}){let n=e.operation??e.mode??"patch";if(Object.hasOwn(e,"operation")&&Object.
|
|
728
729
|
hasOwn(e,"mode")&&e.operation!==e.mode)throw new Error("Path validation options `operation` and `mode` must match when b\
|
|
729
730
|
oth are provided.");if(!Object.hasOwn(this.operations,n))throw new Error(`Unknown operation "${n}".`);let r=this.operations[n];
|
|
730
|
-
return{operationName:n,operation:r,validationOptions:
|
|
731
|
+
return{operationName:n,operation:r,validationOptions:Ml(e)}}_buildOperationResult(e,n,r){let o={};for(let s of r.outputFieldNames){
|
|
731
732
|
if(!Object.hasOwn(this.structure,s))continue;let i=r.isFieldPresent(s);(n[s]!==void 0||i&&e[s]===null||r.defaultedFields.
|
|
732
|
-
has(s))&&(!i&&!r.defaultedFields.has(s)||
|
|
733
|
-
return
|
|
733
|
+
has(s))&&(!i&&!r.defaultedFields.has(s)||A(o,s,n[s]))}return o}_resolveObjectFieldMode(e,n){return nr(e,n)}_resolveArrayItemsConfig(e,n){
|
|
734
|
+
return rr(e,n)}_resolveObjectValuesConfig(e,n){return gt(e,n)}_buildArrayItemSettings(e,n){return e.type==="object"&&Object.
|
|
734
735
|
hasOwn(e,"schema")?{...n,operationName:"replace",operation:this.operations.replace}:n}_castValue(e,n,r,o,s,i,a,c){let d=e.
|
|
735
|
-
nullable===!0||a.nullable===!0,
|
|
736
|
-
`No casting function for type: ${e.type}`);let
|
|
736
|
+
nullable===!0||a.nullable===!0,u=e.nullOnEmpty===!0||a.nullOnEmpty===!0;if(!Object.hasOwn(this.types,e.type))throw new Error(
|
|
737
|
+
`No casting function for type: ${e.type}`);let f=this.types[e.type];if(n===null)return d?(A(o,s,null),{errors:{},shouldContinue:!1}):
|
|
737
738
|
{errors:this._singleErrorMap({field:r,code:"NOT_NULLABLE",message:"Field cannot be null",params:{}}),shouldContinue:!1};
|
|
738
|
-
if(n===""&&
|
|
739
|
+
if(n===""&&u)return A(o,s,null),{errors:{},shouldContinue:!1};let l={schema:this,definition:e,value:n,fieldName:r,object:o,
|
|
739
740
|
objectBeforeCast:i,valueBeforeCast:n,options:a,mode:c.operationName,operation:c.operationName,fieldPresent:!0,computedOptions:{
|
|
740
|
-
nullable:d||
|
|
741
|
-
r,
|
|
742
|
-
s,
|
|
741
|
+
nullable:d||u,nullOnEmpty:u},throwTypeError:()=>{throw this._typeError(r)},throwParamError:(g,I,_)=>{throw this._paramError(
|
|
742
|
+
r,g,I,_)}};try{let g=f(l);if(_i(g))throw new Error(`Type handler for "${e.type}" must be synchronous.`);g!==void 0&&(A(o,
|
|
743
|
+
s,g),l.value=g)}catch(g){if(g.errorObject)return{errors:this._singleErrorMap(g.errorObject),shouldContinue:!1};throw g}return{
|
|
743
744
|
errors:{},context:l,shouldContinue:!0}}_runFieldValidators(e,n,r,o,s,i){for(let a of Object.keys(e)){if(a==="type"||this.
|
|
744
745
|
_paramToBeSkipped(a,i.skipParams,n)||!Object.hasOwn(this.validators,a))continue;let c=this.validators[a];try{s.parameterName=
|
|
745
|
-
a,s.parameterValue=e[a];let d=c(s);if(
|
|
746
|
-
(
|
|
746
|
+
a,s.parameterValue=e[a];let d=c(s);if(_i(d))throw new Error(`Validator handler for "${a}" must be synchronous.`);d!==void 0&&
|
|
747
|
+
(A(r,o,d),s.value=d)}catch(d){if(d.errorObject)return this._singleErrorMap(d.errorObject);throw d}}return{}}_normalizeAndValidateValue(e,n,r,o,s,i,a,c){
|
|
747
748
|
let d=this._castValue(e,n,r,o,s,i,a,c);if(Object.keys(d.errors).length>0)return d.errors;if(!d.shouldContinue)return{};let{
|
|
748
|
-
context:
|
|
749
|
-
e,r,o,s,
|
|
750
|
-
let d={...o};return
|
|
749
|
+
context:u}=d,f=this._validateNestedValue(e,r,o,s,a,c);return Object.keys(f).length>0?f:(u.value=o[s],this._runFieldValidators(
|
|
750
|
+
e,r,o,s,u,a))}_normalizeDefault(e,n,{fieldPath:r,currentObject:o,containerKey:s,objectBeforeCast:i,options:a,settings:c}){
|
|
751
|
+
let d={...o};return A(d,s,n),{errors:this._normalizeAndValidateValue(e,n,r,d,s,i,a,c),value:d[s]}}_validateNestedValue(e,n,r,o,s,i){
|
|
751
752
|
if(e.type==="object"){let c=this._resolveObjectFieldMode(n,e);return c.kind==="nested"?this._validateNestedObjectSchema(
|
|
752
753
|
c,n,r,o,s,i):c.kind==="map"?this._validateObjectValues(n,r,o,c.valuesConfig,s,i):{}}if(e.type!=="array")return{};let a=this.
|
|
753
754
|
_resolveArrayItemsConfig(n,e);return a?this._validateArrayItems(n,r,o,a,s,i):{}}_validateNestedObjectSchema(e,n,r,o,s,i){
|
|
754
755
|
let a=r[o],c=e.allowAdditionalProperties?this._extractKnownObjectFields(a,e.schema):a,d=e.schema._validateWithOperation(
|
|
755
|
-
i.operationName,i.operation,c
|
|
756
|
-
a,e.schema,d.validatedObject):d.validatedObject),
|
|
757
|
-
entries(e))Object.hasOwn(n.structure,o)&&
|
|
758
|
-
keys(e)){if(!Object.hasOwn(n.structure,s)){
|
|
759
|
-
r))Object.hasOwn(o,s)||
|
|
760
|
-
keys(a)){let
|
|
761
|
-
_mergeErrors(d,this._singleErrorMap(this._typeError(
|
|
762
|
-
schema._validateWithOperation("replace",o.schema.operations.replace,l
|
|
763
|
-
d,
|
|
764
|
-
definition,i));this._mergeErrors(d,
|
|
765
|
-
c.length;
|
|
766
|
-
this._mergeErrors(d,this._singleErrorMap(this._typeError(
|
|
767
|
-
schema._validateWithOperation("replace",o.schema.operations.replace,c[
|
|
768
|
-
d,
|
|
756
|
+
i.operationName,i.operation,c,Ke(s,n));return A(r,o,e.allowAdditionalProperties?this._mergeKnownAndPassthroughObjectFields(
|
|
757
|
+
a,e.schema,d.validatedObject):d.validatedObject),We(d.errors,n)}_extractKnownObjectFields(e,n){let r={};for(let[o,s]of Object.
|
|
758
|
+
entries(e))Object.hasOwn(n.structure,o)&&A(r,o,s);return r}_mergeKnownAndPassthroughObjectFields(e,n,r){let o={};for(let s of Object.
|
|
759
|
+
keys(e)){if(!Object.hasOwn(n.structure,s)){A(o,s,e[s]);continue}Object.hasOwn(r,s)&&A(o,s,r[s])}for(let[s,i]of Object.entries(
|
|
760
|
+
r))Object.hasOwn(o,s)||A(o,s,i);return o}_validateObjectValues(e,n,r,o,s,i){let a=n[r],c={...a},d={};A(n,r,c);for(let u of Object.
|
|
761
|
+
keys(a)){let f=Re(e,u);if(this._fieldToBeSkipped(f,s))continue;let l=c[u];if(l===void 0){i.rejectExplicitUndefined?this.
|
|
762
|
+
_mergeErrors(d,this._singleErrorMap(this._typeError(f).errorObject)):delete c[u];continue}if(o.kind==="schema"){let I=o.
|
|
763
|
+
schema._validateWithOperation("replace",o.schema.operations.replace,l,Ke(s,f));A(c,u,I.validatedObject),this._mergeErrors(
|
|
764
|
+
d,We(I.errors,f));continue}let g=this._normalizeAndValidateValue(o.definition,l,f,c,u,a,s,this._buildArrayItemSettings(o.
|
|
765
|
+
definition,i));this._mergeErrors(d,g)}return d}_validateArrayItems(e,n,r,o,s,i){let a=n[r],c=a.slice(),d={};A(n,r,c);for(let u=0;u<
|
|
766
|
+
c.length;u++){let f=Re(e,u);if(this._fieldToBeSkipped(f,s))continue;if(!Object.hasOwn(a,u)||c[u]===void 0){i.rejectExplicitUndefined?
|
|
767
|
+
this._mergeErrors(d,this._singleErrorMap(this._typeError(f).errorObject)):delete c[u];continue}if(o.kind==="schema"){let g=o.
|
|
768
|
+
schema._validateWithOperation("replace",o.schema.operations.replace,c[u],Ke(s,f));A(c,u,g.validatedObject),this._mergeErrors(
|
|
769
|
+
d,We(g.errors,f));continue}let l=this._normalizeAndValidateValue(o.definition,c[u],f,c,u,a,s,this._buildArrayItemSettings(
|
|
769
770
|
o.definition,i));this._mergeErrors(d,l)}return d}_validateField(e,n,r,o,s){if(!Object.hasOwn(this.structure,e))return{};
|
|
770
771
|
let i=this.structure[e];if(this._fieldToBeSkipped(e,o))return{};let a=s.isFieldPresent(e),c=n[e],d=c===void 0;return s.enforceRequired&&
|
|
771
772
|
i.required&&(!a||d)&&!this._paramToBeSkipped("required",o.skipParams,e)?this._singleErrorMap({field:e,code:"REQUIRED",message:"\
|
|
772
773
|
Field is required",params:{}}):a?d?s.rejectExplicitUndefined?this._singleErrorMap(this._typeError(e).errorObject):{}:this.
|
|
773
774
|
_normalizeAndValidateValue(i,c,e,r,e,n,o,s):{}}_validateWithOperation(e,n,r,o){this._assertSupportedOptions(o);let s={},
|
|
774
|
-
i={...r},a=this._buildOperationSettings(e,n,r);for(let c of Object.keys(r))Object.hasOwn(this.structure,c)||
|
|
775
|
+
i={...r},a=this._buildOperationSettings(e,n,r);for(let c of Object.keys(r))Object.hasOwn(this.structure,c)||A(s,c,{field:c,
|
|
775
776
|
code:"FIELD_NOT_ALLOWED",message:"Field not allowed",params:{}});for(let c of a.targetFieldNames){let d=this._validateField(
|
|
776
777
|
c,r,i,o,a);this._mergeErrors(s,d)}if(a.applyDefaults){for(let c of Object.keys(this.structure))if(!a.isFieldPresent(c)&&
|
|
777
|
-
this.structure[c].defaultTo!==void 0){let d=this.structure[c],
|
|
778
|
-
|
|
779
|
-
_mergeErrors(s,
|
|
780
|
-
_buildOperationResult(r,i,a),errors:s}}_validateSelectedTree(e,n,r,o,s=""){let i={},a={};for(let c of
|
|
781
|
-
let d=
|
|
782
|
-
c,e[c],n,a,r,o,d);this._mergeErrors(i,
|
|
783
|
-
hasOwn(this.structure,e))return{};let c=this.structure[e],d=n.self===!0,
|
|
784
|
-
let
|
|
785
|
-
a)&&this._mergeErrors(
|
|
786
|
-
c.defaultTo!==void 0){let
|
|
787
|
-
currentObject:o,containerKey:e,objectBeforeCast:r,options:s,settings:i});this._mergeErrors(
|
|
788
|
-
length===0&&
|
|
789
|
-
a).errorObject):{};let
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
r,e);if(c.kind!=="nested")throw new Error(`Schema path "${r}" does not support nested field selection.`);let d=o[s];if(
|
|
794
|
-
d))return{};let
|
|
795
|
-
|
|
778
|
+
this.structure[c].defaultTo!==void 0){let d=this.structure[c],u=typeof d.defaultTo=="function"?d.defaultTo():d.defaultTo,
|
|
779
|
+
f=this._normalizeDefault(d,u,{fieldPath:c,currentObject:i,containerKey:c,objectBeforeCast:r,options:o,settings:a});if(this.
|
|
780
|
+
_mergeErrors(s,f.errors),Object.keys(f.errors).length>0)continue;A(i,c,f.value),a.defaultedFields.add(c)}}return{validatedObject:this.
|
|
781
|
+
_buildOperationResult(r,i,a),errors:s}}_validateSelectedTree(e,n,r,o,s=""){let i={},a={};for(let c of Oi(Object.keys(e))){
|
|
782
|
+
let d=ki(s,c);if(!Object.hasOwn(this.structure,c))throw new Error(`Unknown schema path "${d}".`);let u=this._validateSelectedField(
|
|
783
|
+
c,e[c],n,a,r,o,d);this._mergeErrors(i,u)}return{validatedObject:a,errors:i}}_validateSelectedField(e,n,r,o,s,i,a){if(!Object.
|
|
784
|
+
hasOwn(this.structure,e))return{};let c=this.structure[e],d=n.self===!0,u=Ci(n);if(this._fieldToBeSkipped(a,s))return{};
|
|
785
|
+
let f=Object.hasOwn(r,e),l=r[e],g={};if(!f){if(d&&i.enforceRequired&&c.required&&!this._paramToBeSkipped("required",s.skipParams,
|
|
786
|
+
a)&&this._mergeErrors(g,this._singleErrorMap({field:a,code:"REQUIRED",message:"Field is required",params:{}})),d&&i.applyDefaults&&
|
|
787
|
+
c.defaultTo!==void 0){let N=typeof c.defaultTo=="function"?c.defaultTo():c.defaultTo,z=this._normalizeDefault(c,N,{fieldPath:a,
|
|
788
|
+
currentObject:o,containerKey:e,objectBeforeCast:r,options:s,settings:i});this._mergeErrors(g,z.errors),Object.keys(z.errors).
|
|
789
|
+
length===0&&A(o,e,z.value)}return g}if(l===void 0)return d&&i.rejectExplicitUndefined?this._singleErrorMap(this._typeError(
|
|
790
|
+
a).errorObject):{};let I={[e]:l};if(d){let N=this._normalizeAndValidateValue(c,l,a,I,e,r,s,i);return Object.hasOwn(I,e)&&
|
|
791
|
+
I[e]!==void 0?A(o,e,I[e]):I[e]===null&&A(o,e,null),N}if(!u)return{};let _=this._castValue(c,l,a,I,e,r,s,i);if(Object.keys(
|
|
792
|
+
_.errors).length>0)return _.errors;if(!_.shouldContinue)return{};let P=this._validateSelectedDescendants(c,n.children,a,
|
|
793
|
+
I,e,s,i);return ar(I[e])&&A(o,e,I[e]),P}_validateSelectedDescendants(e,n,r,o,s,i,a){if(e.type==="object"){let c=this._resolveObjectFieldMode(
|
|
794
|
+
r,e);if(c.kind!=="nested")throw new Error(`Schema path "${r}" does not support nested field selection.`);let d=o[s];if(!$(
|
|
795
|
+
d))return{};let u=c.schema._validateSelectedTree(n,d,Ke(i,r),{...a,defaultedFields:new Set});return A(o,s,u.validatedObject),
|
|
796
|
+
We(u.errors,r)}if(e.type==="array"){let c=this._resolveArrayItemsConfig(r,e);if(!c)throw new Error(`Schema path "${r}" d\
|
|
796
797
|
oes not define array items for nested selection.`);return this._validateSelectedArrayItems(r,o,s,c,n,i,a)}throw new Error(
|
|
797
798
|
`Schema path "${r}" does not support nested field selection.`)}_validateSelectedArrayItems(e,n,r,o,s,i,a){let c=[],d=n[r],
|
|
798
|
-
|
|
799
|
-
id because array segments must use numeric indexes.`);let l=Number(
|
|
800
|
-
|
|
801
|
-
if(
|
|
802
|
-
let
|
|
803
|
-
this._mergeErrors(
|
|
804
|
-
operationName:"replace",operation:o.schema.operations.replace,defaultedFields:new Set});
|
|
805
|
-
this._mergeErrors(
|
|
806
|
-
o.definition,
|
|
807
|
-
continue}if(!
|
|
808
|
-
|
|
809
|
-
i,
|
|
799
|
+
u={};A(n,r,c);for(let f of Oi(Object.keys(s))){if(!/^[0-9]+$/.test(f))throw new Error(`Schema path "${Re(e,f)}" is inval\
|
|
800
|
+
id because array segments must use numeric indexes.`);let l=Number(f),g=Re(e,l),I=s[f],_=I.self===!0,P=Ci(I);if(this._fieldToBeSkipped(
|
|
801
|
+
g,i))continue;if(!Object.hasOwn(d,l)){_&&a.rejectExplicitUndefined&&A(u,g,this._typeError(g).errorObject);continue}let N=d[l];
|
|
802
|
+
if(N===void 0){_&&a.rejectExplicitUndefined&&A(u,g,this._typeError(g).errorObject);continue}if(o.kind==="schema"){if(_){
|
|
803
|
+
let R=o.schema._validateWithOperation("replace",o.schema.operations.replace,N,Ke(i,g));ar(R.validatedObject)&&A(c,l,R.validatedObject),
|
|
804
|
+
this._mergeErrors(u,We(R.errors,g));continue}if(!P)continue;let k=o.schema._validateSelectedTree(I.children,N,Ke(i,g),{...a,
|
|
805
|
+
operationName:"replace",operation:o.schema.operations.replace,defaultedFields:new Set});ar(k.validatedObject)&&A(c,l,k.validatedObject),
|
|
806
|
+
this._mergeErrors(u,We(k.errors,g));continue}let z=this._buildArrayItemSettings(o.definition,a),L=[N];if(_){let k=this._normalizeAndValidateValue(
|
|
807
|
+
o.definition,N,g,L,0,d,i,z);Object.hasOwn(L,0)&&L[0]!==void 0?A(c,l,L[0]):L[0]===null&&A(c,l,null),this._mergeErrors(u,k);
|
|
808
|
+
continue}if(!P)continue;let q=this._castValue(o.definition,N,g,L,0,d,i,z);if(Object.keys(q.errors).length>0){this._mergeErrors(
|
|
809
|
+
u,q.errors);continue}if(!q.shouldContinue)continue;let H=this._validateSelectedDescendants(o.definition,I.children,g,L,0,
|
|
810
|
+
i,z);ar(L[0])&&A(c,l,L[0]),this._mergeErrors(u,H)}return u}validateWith(e,n,r={}){if(!Object.hasOwn(this.operations,e))throw new Error(
|
|
810
811
|
`Unknown operation "${e}".`);let o=this.operations[e];return this._assertPlainObjectInput(e,n),this._validateWithOperation(
|
|
811
|
-
e,o,n,r)}validateAt(e,n,r={}){this._assertPlainObjectInput("validateAt",n);let o=
|
|
812
|
-
_resolvePathValidationRequest(r),c=this._validateSelectedTree(
|
|
812
|
+
e,o,n,r)}validateAt(e,n,r={}){this._assertPlainObjectInput("validateAt",n);let o=Nn(e),{operationName:s,operation:i,validationOptions:a}=this.
|
|
813
|
+
_resolvePathValidationRequest(r),c=this._validateSelectedTree(Ei([e]),n,a,this._buildOperationSettings(s,i,n));return{validatedValue:El(
|
|
813
814
|
c.validatedObject,o),errors:c.errors}}validatePaths(e,n,r={}){if(this._assertPlainObjectInput("validatePaths",n),!Array.
|
|
814
815
|
isArray(e)||e.length===0)throw new Error("validatePaths() expects a non-empty array of schema paths.");let{operationName:o,
|
|
815
|
-
operation:s,validationOptions:i}=this._resolvePathValidationRequest(r);return this._validateSelectedTree(
|
|
816
|
+
operation:s,validationOptions:i}=this._resolvePathValidationRequest(r);return this._validateSelectedTree(Ei(e),n,i,this.
|
|
816
817
|
_buildOperationSettings(o,s,n))}_installOperationMethods(){for(let e of Object.keys(this.operations)){if(e in this)throw new Error(
|
|
817
818
|
`Operation name "${e}" is reserved and cannot be used as a schema method.`);this[e]=(n,r={})=>this.validateWith(e,n,r)}}toJsonSchema(e={}){
|
|
818
|
-
return
|
|
819
|
-
if(typeof e!="string"||e.trim()==="")throw new Error("Field path must be a non-empty string.");let n=
|
|
820
|
-
return n===null?null:
|
|
821
|
-
messages===null?Object.freeze({}):
|
|
822
|
-
o)&&this.structure[o][n]&&
|
|
823
|
-
{"":t},"",t)),c=!a;for(;a<s.length;)c=!0,i[a]=
|
|
824
|
-
|
|
825
|
-
"object"||typeof t=="function")&&typeof t.then=="function"}function
|
|
819
|
+
return Ti(this,e)}getFieldDefinitions(){return Pn.has(this)||Pn.set(this,Rn(this.structure)),Pn.get(this)}getFieldDefinition(e){
|
|
820
|
+
if(typeof e!="string"||e.trim()==="")throw new Error("Field path must be a non-empty string.");let n=Mn(this,Nn(e.trim()));
|
|
821
|
+
return n===null?null:Rn(n)}getFieldMessages(e){let n=this.getFieldDefinition(e);return!n||typeof n.messages!="object"||n.
|
|
822
|
+
messages===null?Object.freeze({}):Rn(n.messages)}cleanup(e,n){let r={};for(let o of Object.keys(e))Object.hasOwn(this.structure,
|
|
823
|
+
o)&&this.structure[o][n]&&A(r,o,e[o]);return r}};var{parse:fb,stringify:jl}=JSON,{keys:mb}=Object,Dl=String,zl="string";var Mi="object",Ll=(t,e)=>e;var ji=(t,e,n)=>{let r=Dl(e.push(n)-1);return t.set(n,r),r};var Di=(t,e,n)=>{let r=e&&typeof e===Mi?(u,f)=>u===""||-1<e.indexOf(u)?f:void 0:e||Ll,o=new Map,s=[],i=[],a=+ji(o,s,r.call(
|
|
824
|
+
{"":t},"",t)),c=!a;for(;a<s.length;)c=!0,i[a]=jl(s[a++],d,n);return"["+i.join(",")+"]";function d(u,f){if(c)return c=!c,
|
|
825
|
+
f;let l=r.call(this,u,f);switch(typeof l){case Mi:if(l===null)return l;case zl:return o.get(l)||ji(o,s,l)}return l}};var Fl=new Set(["true","1","yes","y","on"]),ql=new Set(["false","0","no","n","off"]);function $l(t){return t!==null&&(typeof t==
|
|
826
|
+
"object"||typeof t=="function")&&typeof t.then=="function"}function zi(t){if(typeof t=="number")return Number.isFinite(t)?
|
|
826
827
|
t:null;if(typeof t=="bigint"){let e=Number(t);return Number.isSafeInteger(e)?e:null}if(typeof t=="string"){let e=t.trim();
|
|
827
|
-
if(e==="")return null;let n=Number(e);return Number.isFinite(n)?n:null}return null}function
|
|
828
|
+
if(e==="")return null;let n=Number(e);return Number.isFinite(n)?n:null}return null}function Dn(t,e){if(Object.is(t,e))return!0;
|
|
828
829
|
if(t instanceof Date&&e instanceof Date)return t.getTime()===e.getTime();if(t instanceof RegExp&&e instanceof RegExp)return t.
|
|
829
830
|
source===e.source&&t.flags===e.flags;if(Array.isArray(t)||Array.isArray(e)){if(!Array.isArray(t)||!Array.isArray(e)||t.length!==
|
|
830
|
-
e.length)return!1;for(let o=0;o<t.length;o++)if(!
|
|
831
|
+
e.length)return!1;for(let o=0;o<t.length;o++)if(!Dn(t[o],e[o]))return!1;return!0}if(t===null||e===null||typeof t!="objec\
|
|
831
832
|
t"||typeof e!="object"||Object.getPrototypeOf(t)!==Object.getPrototypeOf(e))return!1;let n=Object.keys(t),r=Object.keys(
|
|
832
|
-
e);if(n.length!==r.length)return!1;for(let o of n)if(!Object.hasOwn(e,o)||!
|
|
833
|
+
e);if(n.length!==r.length)return!1;for(let o of n)if(!Object.hasOwn(e,o)||!Dn(t[o],e[o]))return!1;return!0}var Bl={install(t){
|
|
833
834
|
let{addType:e,addValidator:n}=t;e("none",r=>r.value),e("file",r=>{let o=r.value;o==null&&r.throwTypeError();let s=typeof o;
|
|
834
835
|
if(s==="string"||s==="number"||s==="boolean"){let i=o.toString();return r.definition.noTrim?i:i.trim()}r.throwTypeError()}),
|
|
835
836
|
e("string",r=>{let o=r.value;if(o==null)return"";let s=typeof o;if(s==="string"||s==="number"||s==="boolean"){let i=o.toString();
|
|
836
|
-
return r.definition.noTrim?i:i.trim()}r.throwTypeError()}),e("blob",r=>r.value),e("number",r=>{let o=
|
|
837
|
-
null&&r.throwTypeError(),o}),e("integer",r=>{let o=
|
|
838
|
-
o}),e("epochMilliseconds",r=>{let o=
|
|
839
|
-
r.value,864e10);return o===null&&r.throwTypeError(),o}),e("dateTime",r=>{let o=
|
|
840
|
-
value,o)||r.throwTypeError(),r.value}),e("date",r=>(
|
|
841
|
-
r.fieldName);return
|
|
842
|
-
r.value)?[r.value]:r.value),e("object",r=>(
|
|
843
|
-
r.value)}catch{try{return
|
|
837
|
+
return r.definition.noTrim?i:i.trim()}r.throwTypeError()}),e("blob",r=>r.value),e("number",r=>{let o=zi(r.value);return o===
|
|
838
|
+
null&&r.throwTypeError(),o}),e("integer",r=>{let o=zi(r.value);return(o===null||!Number.isInteger(o))&&r.throwTypeError(),
|
|
839
|
+
o}),e("epochMilliseconds",r=>{let o=In(r.value,864e13);return o===null&&r.throwTypeError(),o}),e("epochSeconds",r=>{let o=In(
|
|
840
|
+
r.value,864e10);return o===null&&r.throwTypeError(),o}),e("dateTime",r=>{let o=vt(r.definition,r.fieldName);return gi(r.
|
|
841
|
+
value,o)||r.throwTypeError(),r.value}),e("date",r=>(mi(r.value)||r.throwTypeError(),r.value)),e("time",r=>{let o=vt(r.definition,
|
|
842
|
+
r.fieldName);return hi(r.value,o)||r.throwTypeError(),r.value}),e("array",r=>r.definition.type==="array"&&!Array.isArray(
|
|
843
|
+
r.value)?[r.value]:r.value),e("object",r=>($(r.value)||r.throwTypeError(),r.value)),e("serialize",r=>{try{return JSON.stringify(
|
|
844
|
+
r.value)}catch{try{return Di(r.value)}catch{r.throwTypeError()}}}),e("boolean",r=>{if(typeof r.value=="boolean")return r.
|
|
844
845
|
value;if(typeof r.value=="number"){if(r.value===1)return!0;if(r.value===0)return!1;r.throwTypeError()}if(typeof r.value==
|
|
845
846
|
"bigint"){if(r.value===1n)return!0;if(r.value===0n)return!1;r.throwTypeError()}if(typeof r.value=="string"){let o=String(
|
|
846
847
|
r.definition.stringFalseWhen||"false").trim().toLowerCase(),s=String(r.definition.stringTrueWhen||"true").trim().toLowerCase(),
|
|
847
|
-
i=r.value.trim().toLowerCase(),a=new Set([...
|
|
848
|
+
i=r.value.trim().toLowerCase(),a=new Set([...ql,o]),c=new Set([...Fl,s]);if(a.has(i))return!1;if(c.has(i))return!0}r.throwTypeError()}),
|
|
848
849
|
e("id",r=>{if(typeof r.value=="number"){if(Number.isSafeInteger(r.value)&&r.value>0)return r.value;r.throwTypeError()}if(typeof r.
|
|
849
850
|
value=="bigint"){if(r.value>0n&&r.value<=BigInt(Number.MAX_SAFE_INTEGER))return Number(r.value);r.throwTypeError()}if(typeof r.
|
|
850
851
|
value=="string"){let o=r.value.trim();/^[1-9][0-9]*$/.test(o)||r.throwTypeError();let s=Number(o);return Number.isSafeInteger(
|
|
851
852
|
s)||r.throwTypeError(),s}r.throwTypeError()}),n("minLength",r=>{r.value!==void 0&&r.definition.type==="string"&&r.value.
|
|
852
853
|
toString&&r.value.toString().length<r.parameterValue&&r.throwParamError("MIN_LENGTH",`Length must be at least ${r.parameterValue}\
|
|
853
|
-
characters.`,{min:r.parameterValue,actual:r.value.toString().length})}),n("min",r=>{r.value!==void 0&&
|
|
854
|
+
characters.`,{min:r.parameterValue,actual:r.value.toString().length})}),n("min",r=>{r.value!==void 0&&Ve(r.definition)&&
|
|
854
855
|
typeof r.value=="number"&&r.value<r.parameterValue&&r.throwParamError("MIN_VALUE",`Value must be at least ${r.parameterValue}\
|
|
855
856
|
.`,{min:r.parameterValue,actual:r.value})}),n("maxLength",r=>{r.value!==void 0&&r.definition.type==="string"&&r.value.toString&&
|
|
856
857
|
r.value.toString().length>r.parameterValue&&r.throwParamError("MAX_LENGTH",`Length must be no more than ${r.parameterValue}\
|
|
857
|
-
characters.`,{max:r.parameterValue,actual:r.value.toString().length})}),n("max",r=>{r.value!==void 0&&
|
|
858
|
+
characters.`,{max:r.parameterValue,actual:r.value.toString().length})}),n("max",r=>{r.value!==void 0&&Ve(r.definition)&&
|
|
858
859
|
typeof r.value=="number"&&r.value>r.parameterValue&&r.throwParamError("MAX_VALUE",`Value must be no more than ${r.parameterValue}\
|
|
859
860
|
.`,{max:r.parameterValue,actual:r.value})}),n("enum",r=>{if(!Array.isArray(r.parameterValue))throw new Error(`Enum for ${r.
|
|
860
|
-
fieldName} must be an array.`);r.parameterValue.some(s=>
|
|
861
|
+
fieldName} must be an array.`);r.parameterValue.some(s=>Dn(s,r.value))||r.throwParamError("ENUM_VALUE","Value must match\
|
|
861
862
|
one of the allowed enum values.",{allowed:r.parameterValue})}),n("pattern",r=>{if(r.value===void 0||r.definition.type!==
|
|
862
863
|
"string"||typeof r.value!="string")return;let o=r.parameterValue,s=o instanceof RegExp?new RegExp(o.source,o.flags):typeof o==
|
|
863
864
|
"string"?new RegExp(o):null;if(!s)throw new Error(`Pattern for ${r.fieldName} must be a string or RegExp.`);s.test(r.value)||
|
|
@@ -865,7 +866,7 @@ r.throwParamError("PATTERN","Value does not match the required pattern.",{patter
|
|
|
865
866
|
parameterValue){if(r.definition.type!=="boolean")throw new Error(`strictBoolean can only be used on boolean fields (${r.
|
|
866
867
|
fieldName}).`);typeof r.valueBeforeCast!="boolean"&&r.throwParamError("STRICT_BOOLEAN","Value must be a boolean.")}}),n(
|
|
867
868
|
"validator",r=>{if(typeof r.parameterValue!="function")throw new Error(`Validator for ${r.fieldName} must be a function.`);
|
|
868
|
-
let o=r.parameterValue(r.value,r.object,r);if(
|
|
869
|
+
let o=r.parameterValue(r.value,r.object,r);if($l(o))throw new Error(`Custom validator for "${r.fieldName}" must be synch\
|
|
869
870
|
ronous.`);typeof o=="string"&&r.throwParamError("CUSTOM_VALIDATOR_FAILED",o)}),n("uppercase",r=>{if(typeof r.value=="str\
|
|
870
871
|
ing")return r.value.toUpperCase()}),n("lowercase",r=>{if(typeof r.value=="string")return r.value.toLowerCase()}),n("leng\
|
|
871
872
|
th",r=>{if(typeof r.value=="string")return r.value.substr(0,r.parameterValue);Number.isInteger(Number(r.valueBeforeCast))&&
|
|
@@ -877,74 +878,65 @@ r.throwParamError("MAX_ITEMS",`Must have no more than ${r.parameterValue} items.
|
|
|
877
878
|
n("notEmpty",r=>{r.parameterValue&&typeof r.value=="string"&&r.value===""&&r.throwParamError("NOT_EMPTY","Field cannot b\
|
|
878
879
|
e empty.")}),n("required",()=>{}),n("unsigned",()=>{}),n("precision",()=>{}),n("scale",()=>{}),n("temporalPrecision",r=>{
|
|
879
880
|
if(r.definition.type!=="time"&&r.definition.type!=="dateTime")throw new Error(`temporalPrecision can only be used on tim\
|
|
880
|
-
e or dateTime fields (${r.fieldName}).`)}),n("nullable",()=>{}),n("nullOnEmpty",()=>{}),n("defaultTo",()=>{})}},
|
|
881
|
-
if(typeof n!="function")throw new Error(`Type handler for '${e}' must be a function.`);
|
|
882
|
-
"function")throw new Error(`Validator handler for '${e}' must be a function.`);
|
|
883
|
-
null);for(let[n,r]of Object.entries(t))
|
|
884
|
-
"Plugin must have an install method.");t.install(e)}function
|
|
885
|
-
{value:Object.freeze({getTypes:()=>e,getValidators:()=>n}),enumerable:!1,configurable:!1,writable:!1})}function
|
|
886
|
-
typeof t!="object"&&typeof t!="function")return null;let e
|
|
881
|
+
e or dateTime fields (${r.fieldName}).`)}),n("nullable",()=>{}),n("nullOnEmpty",()=>{}),n("defaultTo",()=>{})}},Li=Bl;var $i=new WeakMap,Bi=new WeakMap,Hi=Symbol.for("json-rest-schema.registry-metadata"),ur=new WeakSet;function Hl(t,e,n){
|
|
882
|
+
if(typeof n!="function")throw new Error(`Type handler for '${e}' must be a function.`);A(t,e,n)}function Vl(t,e,n){if(typeof n!=
|
|
883
|
+
"function")throw new Error(`Validator handler for '${e}' must be a function.`);A(t,e,n)}function lr(t={}){let e=Object.create(
|
|
884
|
+
null);for(let[n,r]of Object.entries(t))A(e,n,r);return e}function Ui(t,e){if(typeof t.install!="function")throw new Error(
|
|
885
|
+
"Plugin must have an install method.");t.install(e)}function Fi(t,e,n){$i.set(t,e),Bi.set(t,n),Object.defineProperty(t,Hi,
|
|
886
|
+
{value:Object.freeze({getTypes:()=>e,getValidators:()=>n}),enumerable:!1,configurable:!1,writable:!1})}function Gl(t){if(!t||
|
|
887
|
+
typeof t!="object"&&typeof t!="function")return null;let e=$i.get(t),n=Bi.get(t);if(e&&n)return{types:e,validators:n};let r=t[Hi];
|
|
887
888
|
return r&&typeof r.getTypes=="function"&&typeof r.getValidators=="function"?{types:r.getTypes(),validators:r.getValidators()}:
|
|
888
889
|
typeof t=="object"&&t.types&&typeof t.types=="object"&&t.validators&&typeof t.validators=="object"&&typeof t.create=="fu\
|
|
889
890
|
nction"&&typeof t.replace=="function"&&typeof t.patch=="function"&&typeof t.toJsonSchema=="function"?{types:t.types,validators:t.
|
|
890
|
-
validators}:null}function
|
|
891
|
-
entries(e)){if(Object.hasOwn(t,r)&&t[r]!==o){if(
|
|
892
|
-
factories with conflicting ${n} "${r}".`)}
|
|
893
|
-
types:
|
|
894
|
-
"Factory sources must be schema instances or schema factories created by json-rest-schema.");
|
|
895
|
-
validators,"validator")}return{types:o,validators:s}}function
|
|
896
|
-
t),o=
|
|
897
|
-
s.addValidator=(i,a)=>{
|
|
898
|
-
let a=
|
|
899
|
-
addType(i,a)},addValidator:(i,a)=>{
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
"
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
`${
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
(
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
"
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
ation.field.minValue"},MAX_VALUE:{messageKey:"max",code:"kernel.validation.field.maxValue"},PATTERN:{messageKey:"pattern",
|
|
940
|
-
code:"kernel.validation.field.pattern"},ENUM_VALUE:{messageKey:"enum",code:"kernel.validation.field.enumValue"},FIELD_NOT_ALLOWED:{
|
|
941
|
-
messageKey:"additionalProperties",code:"kernel.validation.field.notAllowed"},CUSTOM_VALIDATOR_FAILED:{messageKey:"valida\
|
|
942
|
-
tor",code:""},STRICT_BOOLEAN:{messageKey:"default",code:"kernel.validation.field.strictBoolean"},RANGE_EXCEEDED:{messageKey:"\
|
|
943
|
-
default",code:"kernel.validation.field.rangeExceeded"},NOT_EMPTY:{messageKey:"default",code:"kernel.validation.field.not\
|
|
944
|
-
Empty"}}),iT=Object.freeze({code:"kernel.validation.invalid",message:"Invalid value."}),aT=Object.freeze(["create","repl\
|
|
945
|
-
ace","patch","toJsonSchema"]);var ll=Q({cursor:{type:"id",required:!1},limit:{type:"number",required:!1,min:1,unsigned:!0}}),pl=Object.freeze({schema:ll,
|
|
946
|
-
mode:"patch"});var _i=Object.freeze({type:"string",pattern:"^(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d)?$",minLength:5}),fl=Object.freeze(
|
|
947
|
-
{..._i,nullable:!0});var kT=new Map([{keyword:"required",code:"kernel.validation.required"},{keyword:"type",code:"kernel.validation.type"},{keyword:"\
|
|
891
|
+
validators}:null}function Wl(t){return t.length===1&&Array.isArray(t[0])?t[0]:t}function qi(t,e,n){for(let[r,o]of Object.
|
|
892
|
+
entries(e)){if(Object.hasOwn(t,r)&&t[r]!==o){if(ur.has(o))continue;if(!ur.has(t[r]))throw new Error(`Cannot merge schema\
|
|
893
|
+
factories with conflicting ${n} "${r}".`)}A(t,r,o)}}function Kl(t,e,n){let r=Wl(n).filter(Boolean);if(r.length<1)return{
|
|
894
|
+
types:lr(t),validators:lr(e)};let o=Object.create(null),s=Object.create(null);for(let i of r){let a=Gl(i);if(!a)throw new Error(
|
|
895
|
+
"Factory sources must be schema instances or schema factories created by json-rest-schema.");qi(o,a.types,"type"),qi(s,a.
|
|
896
|
+
validators,"validator")}return{types:o,validators:s}}function Vi({types:t={},validators:e={},installCore:n=!0}={}){let r=lr(
|
|
897
|
+
t),o=lr(e),s=(i,a={})=>{let c=new Je(i,r,o,a.operations);return Fi(c,r,o),c};return Fi(s,r,o),s.addType=(i,a)=>{Hl(r,i,a)},
|
|
898
|
+
s.addValidator=(i,a)=>{Vl(o,i,a)},s.use=i=>{Ui(i,{addType:s.addType,addValidator:s.addValidator})},s.createFactory=(...i)=>{
|
|
899
|
+
let a=Kl(r,o,i);return Vi({types:a.types,validators:a.validators,installCore:!1})},n&&Ui(Li,{addType:(i,a)=>{ur.add(a),s.
|
|
900
|
+
addType(i,a)},addValidator:(i,a)=>{ur.add(a),s.addValidator(i,a)}}),s}var oe=Vi({installCore:!0});function Pe(t,e=new WeakSet){if(!t||typeof t!="object"||e.has(t))return t;e.add(t);for(let n of Object.getOwnPropertyNames(
|
|
901
|
+
t))Pe(t[n],e);return Object.freeze(t)}var Jl=new Set(["create","replace","patch"]),Xl=Object.freeze({REQUIRED:{messageKey:"required",code:"kernel.validation.f\
|
|
902
|
+
ield.required"},TYPE_CAST_FAILED:{messageKey:"default",code:"kernel.validation.field.typeCastFailed"},NOT_NULLABLE:{messageKey:"\
|
|
903
|
+
default",code:"kernel.validation.field.notNullable"},MIN_LENGTH:{messageKey:"minLength",code:"kernel.validation.field.mi\
|
|
904
|
+
nLength"},MAX_LENGTH:{messageKey:"maxLength",code:"kernel.validation.field.maxLength"},MIN_ITEMS:{messageKey:"minItems",
|
|
905
|
+
code:"kernel.validation.field.minItems"},MAX_ITEMS:{messageKey:"maxItems",code:"kernel.validation.field.maxItems"},MIN_VALUE:{
|
|
906
|
+
messageKey:"min",code:"kernel.validation.field.minValue"},MAX_VALUE:{messageKey:"max",code:"kernel.validation.field.maxV\
|
|
907
|
+
alue"},PATTERN:{messageKey:"pattern",code:"kernel.validation.field.pattern"},ENUM_VALUE:{messageKey:"enum",code:"kernel.\
|
|
908
|
+
validation.field.enumValue"},FIELD_NOT_ALLOWED:{messageKey:"additionalProperties",code:"kernel.validation.field.notAllow\
|
|
909
|
+
ed"},CUSTOM_VALIDATOR_FAILED:{messageKey:"validator",code:""},STRICT_BOOLEAN:{messageKey:"default",code:"kernel.validati\
|
|
910
|
+
on.field.strictBoolean"},RANGE_EXCEEDED:{messageKey:"default",code:"kernel.validation.field.rangeExceeded"},NOT_EMPTY:{messageKey:"\
|
|
911
|
+
default",code:"kernel.validation.field.notEmpty"}}),Yl=Object.freeze({code:"kernel.validation.invalid",message:"Invalid \
|
|
912
|
+
value."}),Zl=Object.freeze(["create","replace","patch","toJsonSchema"]);function pr(t){return!!t&&typeof t=="object"&&Zl.
|
|
913
|
+
every(e=>typeof t[e]=="function")}function Wi(t=null,{defaultMode:e="create",context:n="schema definition.mode"}={}){let r=K(t),o=w(e).toLowerCase()||"cre\
|
|
914
|
+
ate",s=Object.prototype.hasOwnProperty.call(r,"mode")?w(r.mode).toLowerCase():"";if(!s)return o;if(!Jl.has(s))throw new TypeError(
|
|
915
|
+
`${n} must be one of: create, replace, patch.`);return s}function Ki(t=null,e=""){let n=w(e);if(!n)return{};let r=K(t);return pr(r.schema)?K(r.schema.getFieldMessages(n)):{}}function Ql(t=null,e=""){
|
|
916
|
+
let n=w(e).split(".").filter(Boolean);return n.length<2?{}:(n.pop(),Ki(t,n.join(".")))}function Gi(t,e){let n=e?t[e]:void 0;
|
|
917
|
+
if(typeof n=="string"){let s=w(n);return s?{message:s}:null}if(!x(n))return null;let r=w(n.message);if(!r)return null;let o=w(
|
|
918
|
+
n.code);return o?{message:r,code:o,params:K(n.params)}:{message:r}}function ep(t,e,n=null){let r=w(e?.code).toUpperCase(),
|
|
919
|
+
o=Xl[r]||{},s=K(e?.params),i=Ki(n,t),a=r==="FIELD_NOT_ALLOWED"&&Object.keys(i).length<1?Ql(n,t):i,c=Gi(a,o.messageKey)||
|
|
920
|
+
Gi(a,"default");if(c)return c.code?{message:c.message,code:c.code,params:{...s,...c.params}}:{message:c.message};let d=w(
|
|
921
|
+
e?.message);if(d)return o.code?{message:d,code:o.code,params:s}:{message:d};let u=w(e?.code);return u?{message:u}:{...Yl,
|
|
922
|
+
params:{}}}function zn(t={},e=null){let n=K(t),r={},o={};for(let[s,i]of Object.entries(n)){let a=w(s);if(!a)continue;if(typeof i==
|
|
923
|
+
"string"){r[a]=i;continue}let{message:c,code:d,params:u}=ep(a,i,e);r[a]=c,d&&(o[a]={code:d,params:u})}return{fieldErrors:r,
|
|
924
|
+
fieldErrorCodes:o}}function tp(t){return!!t&&typeof t=="object"&&!Array.isArray(t)&&(Object.prototype.hasOwnProperty.call(t,"schema")||Object.
|
|
925
|
+
prototype.hasOwnProperty.call(t,"mode"))}function Xe(t,{context:e="schema definition",defaultMode:n=""}={}){if(t==null)return null;
|
|
926
|
+
if(!tp(t))throw new TypeError(`${e} must be a schema definition object.`);let r=K(t);if(!Object.prototype.hasOwnProperty.
|
|
927
|
+
call(r,"schema"))throw new TypeError(`${e}.schema is required.`);if(!pr(r.schema))throw new TypeError(`${e}.schema must \
|
|
928
|
+
be a json-rest-schema schema instance.`);let o={schema:r.schema},s=w(n).toLowerCase();return o.mode=Wi(r,{defaultMode:s||
|
|
929
|
+
"patch",context:`${e}.mode`}),Object.freeze(o)}function Ln(t,e,{context:n="schema definition",defaultMode:r=""}={}){let o=Xe(t,{context:n,defaultMode:r});return o?o.schema[o.
|
|
930
|
+
mode](e):null}var rp=oe({cursor:{type:"id",required:!1},limit:{type:"number",required:!1,min:1,unsigned:!0}}),np=Object.freeze({schema:rp,
|
|
931
|
+
mode:"patch"});var Ji=Object.freeze({type:"string",pattern:"^(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d)?$",minLength:5}),op=Object.freeze(
|
|
932
|
+
{...Ji,nullable:!0});var Xi="Schema validation failed.";function Yi({message:t=Xi,fieldErrors:e=null,fieldErrorCodes:n=null,errors:r=null,cause:o,
|
|
933
|
+
statusCode:s=null}={}){let i=new Error(t,o?{cause:o}:void 0);if(t===Xi&&(i.messageCode="kernel.validation.schemaFailed",
|
|
934
|
+
i.messageParams={}),Number.isInteger(s)&&s>=400&&s<=599&&(i.statusCode=s),x(e)){let a=x(n)&&Object.keys(n).length>0?n:null;
|
|
935
|
+
i.fieldErrors=e,a&&(i.fieldErrorCodes=a),i.details={...i.details||{},fieldErrors:e,...a?{fieldErrorCodes:a}:{}}}else r!=
|
|
936
|
+
null&&(i.details={...i.details||{},errors:r});return i}function yt(t,e,{phase:n="input",context:r="schema definition",statusCode:o=null}={}){
|
|
937
|
+
if(t==null)return e;let s=Ln(t,e,{defaultMode:n==="output"?"replace":"patch",context:r}),{fieldErrors:i,fieldErrorCodes:a}=zn(
|
|
938
|
+
s.errors,t);if(Object.keys(i).length>0)throw Yi({fieldErrors:i,fieldErrorCodes:a,statusCode:o});return s.validatedObject??
|
|
939
|
+
e}var oT=new Map([{keyword:"required",code:"kernel.validation.required"},{keyword:"type",code:"kernel.validation.type"},{keyword:"\
|
|
948
940
|
minLength",code:"kernel.validation.minLength"},{keyword:"maxLength",code:"kernel.validation.maxLength"},{keyword:"minimu\
|
|
949
941
|
m",code:"kernel.validation.minimum"},{keyword:"maximum",code:"kernel.validation.maximum"},{keyword:"exclusiveMinimum",code:"\
|
|
950
942
|
kernel.validation.exclusiveMinimum"},{keyword:"exclusiveMaximum",code:"kernel.validation.exclusiveMaximum"},{keyword:"mu\
|
|
@@ -956,62 +948,211 @@ additionalItems",code:"kernel.validation.additionalItems"},{keyword:"uniqueItems
|
|
|
956
948
|
perties"},{keyword:"additionalProperties",code:"kernel.validation.additionalProperties"},{keyword:"propertyNames",code:"\
|
|
957
949
|
kernel.validation.propertyNames"},{keyword:"oneOf",code:"kernel.validation.oneOf"},{keyword:"anyOf",code:"kernel.validat\
|
|
958
950
|
ion.anyOf"},{keyword:"not",code:"kernel.validation.not"},{keyword:"if",code:"kernel.validation.if"}].map(({keyword:t,code:e})=>[
|
|
959
|
-
t,e]));var
|
|
960
|
-
...
|
|
961
|
-
itive integer string."}}}}),mode:"patch"});
|
|
962
|
-
|
|
951
|
+
t,e]));var Zi="^[1-9][0-9]*$",Un=Pe({type:"string",minLength:1,pattern:Zi}),sp=Pe({...Un,nullable:!0}),ip=Pe({schema:oe({recordId:{
|
|
952
|
+
...Un,required:!0,messages:{pattern:{code:"kernel.validation.recordIdInvalid",message:"Record id must be a canonical pos\
|
|
953
|
+
itive integer string."}}}}),mode:"patch"});function Ie(t){let e=Array.isArray(t)?t:[t],n=new Set;for(let r of e){let o=w(r);o&&n.add(o)}return[...n]}function Qi(t=[],e=""){
|
|
954
|
+
let n=w(e);if(!n)return!0;let r=Ie(t);if(r.includes("*")||r.includes(n))return!0;for(let o of r){if(!o.endsWith(".*"))continue;
|
|
955
|
+
let s=o.slice(0,-2);if(s&&n.startsWith(`${s}.`))return!0}return!1}function Fn(t,e,n){if(t==="all"){let r=e.find(o=>!Qi(n,
|
|
956
|
+
o));return r===void 0?null:{permission:r}}return e.some(r=>Qi(n,r))?null:{requiredPermissions:e}}var It=/^[a-z][a-z0-9_.-]*$/u,dp=/^[A-Za-z_$][A-Za-z0-9_$]*$/u;function up(t){return String(t||"").trim().toLowerCase()}
|
|
957
|
+
function $n(t,e){let n=up(t);if(!It.test(n))throw new TypeError(`${e} must match ${It.toString()}.`);return n}function fr(t,e){
|
|
958
|
+
if(t==null)return Object.freeze({});if(!x(t))throw new TypeError(`${e} must be an object mapping local names to capabili\
|
|
959
|
+
ty ids.`);let n={},r=new Set;for(let[o,s]of Object.entries(t)){let i=String(o||"").trim();if(!dp.test(i))throw new TypeError(
|
|
960
|
+
`${e} local name "${i}" must be a JavaScript identifier.`);let a=$n(s,`${e}.${i}`);if(r.has(a))throw new TypeError(`${e}\
|
|
961
|
+
declares capability "${a}" more than once.`);r.add(a),n[i]=a}return Object.freeze(n)}function lp(t,e,n){if(t==null)return Object.
|
|
962
|
+
freeze({});if(!x(t))throw new TypeError(`${n}.hints must be an object mapping required capability ids to what to registe\
|
|
963
|
+
r.`);let r=new Set(Object.values(e)),o={};for(let[s,i]of Object.entries(t)){let a=$n(s,`${n}.hints key`);if(!r.has(a))throw new TypeError(
|
|
964
|
+
`${n}.hints names "${a}", which the provider does not require.`);if(typeof i!="string"||!i.trim())throw new TypeError(`${n}\
|
|
965
|
+
.hints["${a}"] must be the text that says what to register.`);o[a]=i.trim()}return Object.freeze(o)}function pp(t){let e=new Map;
|
|
966
|
+
for(let[n,r]of Object.entries(t))for(let o of Object.keys(r)){if(e.has(o))throw new TypeError(`Provider local name "${o}\
|
|
967
|
+
" is declared by both ${e.get(o)} and ${n}.`);e.set(o,n)}}function fp(t,e,n){for(let r of Object.values(e))for(let[o,s]of Object.
|
|
968
|
+
entries(n))if(Object.values(s).includes(r))throw new TypeError(o==="provides"?`Provider "${t}" cannot late-require capab\
|
|
969
|
+
ility "${r}" that it provides.`:`Provider "${t}" names capability "${r}" under both late and ${o}.`)}function qn(t,e){if(t==
|
|
970
|
+
null)return null;if(typeof t!="function")throw new TypeError(`${e} must be a function when provided.`);return t}function Ye({
|
|
971
|
+
id:t,requires:e={},optional:n={},late:r={},provides:o={},hints:s={},setup:i,boot:a=null,shutdown:c=null}={}){let d=$n(t,
|
|
972
|
+
"Provider id"),u=fr(e,`${d}.requires`),f=fr(n,`${d}.optional`),l=fr(r,`${d}.late`),g=fr(o,`${d}.provides`);pp({requires:u,
|
|
973
|
+
optional:f,late:l,provides:g}),fp(d,l,{provides:g,requires:u,optional:f});let I=qn(i,`${d}.setup`);if(!I)throw new TypeError(
|
|
974
|
+
`${d}.setup is required.`);return Object.freeze({id:d,requires:u,optional:f,late:l,provides:g,hints:lp(s,{...u,...l},d),
|
|
975
|
+
setup:I,boot:qn(a,`${d}.boot`),shutdown:qn(c,`${d}.shutdown`)})}var Bn=new WeakSet;function ea(t,e){return t===null||typeof t!="object"||Bn.has(t)||e.has(t)?!0:Object.isFrozen(t)?(e.add(
|
|
976
|
+
t),Reflect.ownKeys(t).every(n=>{let r=Object.getOwnPropertyDescriptor(t,n);return!Object.hasOwn(r,"value")||ea(r.value,e)})):
|
|
977
|
+
!1}function ta(t){if(t===null||typeof t!="object"||Bn.has(t))return!0;if(!Object.isFrozen(t))return!1;let e=new Set;if(!ea(
|
|
978
|
+
t,e))return!1;for(let n of e)Bn.add(n);return!0}var mp=Object.freeze(["query","command","stream"]),oa=Object.freeze(["none","authenticated","all","any"]),hp=new Set(mp),
|
|
979
|
+
gp=new Set(oa),sa="create",ia=Object.freeze({required:!0,defaultMode:sa,refuseOneOf:!0}),J=class extends Error{constructor(e,n,r={}){
|
|
980
|
+
super(n),this.name="ActionRuntimeError",this.status=Number(e)||500,this.statusCode=this.status,this.code=String(r.code||
|
|
981
|
+
"ACTION_RUNTIME_ERROR"),this.params=r.params&&typeof r.params=="object"?{...r.params}:{},this.details=r.details,this.headers=
|
|
982
|
+
r.headers||{},this.cause=r.cause}};function aa(t,{context:e="domain"}={}){let n=w(t).toLowerCase();if(!n)throw new Error(
|
|
983
|
+
`${e} is required.`);if(!It.test(n))throw new Error(`${e} must match ${It.toString()} (lowercase letters, digits, _, -, \
|
|
984
|
+
.).`);return n}function ra(t,e){let n=Array.isArray(t)?t:[],r=Array.from(new Set(n.map(o=>w(o).toLowerCase()).filter(Boolean)));
|
|
985
|
+
if(r.length<1)throw new Error(`Action definition ${e} must include at least one value.`);return r}function Hn(t){return t&&
|
|
986
|
+
typeof t.getFieldDefinitions=="function"?t.getFieldDefinitions():null}var na=new WeakSet;function Vn(t,e,n=""){for(let[r,
|
|
987
|
+
o]of Object.entries(t))Gn(o,e,n?`${n}.${r}`:r)}function Gn(t,e,n){let r=Hn(t);if(r){Vn(r,e,n);return}if(x(t)){if(Object.
|
|
988
|
+
hasOwn(t,"oneOf"))throw new Error(`Action definition ${e} field "${n}" declares oneOf, which does not restrict its value\
|
|
989
|
+
; list the allowed values with enum.`);Vn(Hn(t.schema)||{},e,n),Object.hasOwn(t,"items")&&Gn(t.items,e,`${n}[]`),Object.
|
|
990
|
+
hasOwn(t,"values")&&Gn(t.values,e,`${n}.*`)}}function Wn(t,e,{required:n=!1,defaultMode:r="",refuseOneOf:o=!1}={}){if(t==
|
|
991
|
+
null){if(!n)return null;throw new Error(`Action definition ${e} is required.`)}if(Array.isArray(t))throw new Error(`Acti\
|
|
992
|
+
on definition ${e} must be a single schema definition.`);if(!x(t))throw new Error(`Action definition ${e} must be a json\
|
|
993
|
+
-rest-schema schema definition.`);let s;try{s=Xe(t,{context:`Action definition ${e}`,defaultMode:r})}catch(i){throw new Error(
|
|
994
|
+
i?.message||`Action definition ${e} is invalid.`)}return o&&!na.has(s.schema)&&(Vn(Hn(s.schema)||{},e),ta(s.schema)&&na.
|
|
995
|
+
add(s.schema)),s}function vp(t,e){if(t==null)return Object.freeze({require:"none",permissions:Object.freeze([]),message:"",
|
|
996
|
+
code:""});if(!x(t))throw new Error(`Action definition "${e}" permission must be an object when provided.`);let n=w(t.require||
|
|
997
|
+
"authenticated").toLowerCase();if(!gp.has(n))throw new Error(`Action definition "${e}" permission.require must be one of\
|
|
998
|
+
: ${oa.join(", ")}.`);return Object.freeze({require:n,permissions:Object.freeze(Ie(t.permissions)),message:w(t.message),
|
|
999
|
+
code:w(t.code)})}function wp(t){if(t==null)return Object.freeze({});if(!x(t))throw new Error("Action definition extensio\
|
|
1000
|
+
ns must be an object when provided.");return Object.freeze({...t})}function yp(t,e){if(t==null)return Object.freeze([]);
|
|
1001
|
+
if(!Array.isArray(t))throw new Error(`Action definition "${e}" events must be an array.`);return Object.freeze(t.map((n,r)=>{
|
|
1002
|
+
if(typeof n!="function")throw new Error(`Action definition "${e}" events[${r}] must be a function.`);return n}))}function Ip(t,{
|
|
1003
|
+
contributorId:e="",contributorDomain:n=""}={}){let r=t&&typeof t=="object"?t:{},o=w(r.id);if(!o)throw new Error("Action \
|
|
1004
|
+
definition id is required.");let s=V(r.version,{fallback:1}),i=aa(r.domain||n,{context:`Action definition "${o}" domain`}),
|
|
1005
|
+
a=w(r.kind||"command").toLowerCase();if(!hp.has(a))throw new Error(`Action definition "${o}" has unsupported kind "${a}"\
|
|
1006
|
+
.`);let c=ra(r.channels,"channels"),d=ra(r.surfaces,"surfaces");if(Object.hasOwn(r,"idempotency"))throw new Error(`Actio\
|
|
1007
|
+
n definition "${o}" declares idempotency. Action definitions no longer declare idempotency.`);if(typeof r.execute!="func\
|
|
1008
|
+
tion")throw new Error(`Action definition "${o}" execute handler is required.`);if(r.checkInput!=null&&typeof r.checkInput!=
|
|
1009
|
+
"function")throw new Error(`Action definition "${o}" checkInput must be a function when provided.`);return Object.freeze(
|
|
1010
|
+
{id:o,version:s,domain:i,kind:a,channels:c,surfaces:d,input:Wn(r.input,"input",ia),output:Wn(r.output,"output",{defaultMode:"\
|
|
1011
|
+
replace"}),permission:vp(r.permission,o),extensions:wp(r.extensions),events:yp(r.events,o),checkInput:r.checkInput??null,
|
|
1012
|
+
execute:r.execute,contributorId:w(e)})}function Sp(t){let e=t&&typeof t=="object"?t:{},n=w(e.contributorId);if(!n)throw new Error(
|
|
1013
|
+
"Action contributor contributorId is required.");let r=aa(e.domain,{context:`Action contributor "${n}" domain`}),s=(Array.
|
|
1014
|
+
isArray(e.actions)?e.actions:[]).map(i=>Ip(i,{contributorId:n,contributorDomain:r}));return Object.freeze({contributorId:n,
|
|
1015
|
+
domain:r,actions:Object.freeze(s)})}function xp(t,e){let n=e.input(t);return n===t.input?t:Object.freeze({...t,input:Wn(
|
|
1016
|
+
n,"input",ia)})}function ca(t,e){let{contributorId:n,domain:r,actions:o}=Sp(t);return Object.freeze({contributorId:n,domain:r,
|
|
1017
|
+
actions:Object.freeze(o.map(s=>Object.freeze({declared:s,definition:xp(s,e)})))})}function Kn(t,e){return`${w(t)}@v${V(e,
|
|
1018
|
+
{fallback:1})}`}function da(t){return t?.requestMeta?.request||null}function ua(t,e){let n=e||da(t);return t?.actor||n?.user||null}function Jn(t,e){
|
|
1019
|
+
return Et(ua(t,e)?.id)}var WT=Object.freeze({schema:oe({}),mode:"replace"});function la(t){let e=t.fieldErrorCodes||t.details?.fieldErrorCodes;return{fieldErrors:t.fieldErrors||t.details?.fieldErrors,
|
|
1020
|
+
...x(e)?{fieldErrorCodes:e}:{}}}function Xn({details:t,cause:e}){return new J(400,"Validation failed.",{code:"ACTION_VAL\
|
|
1021
|
+
IDATION_FAILED",details:t,cause:e})}function fa(t,e){let n=se(e.channel);if(!n||!t.channels.includes(n))throw new J(403,
|
|
1022
|
+
"Forbidden.",{code:"ACTION_CHANNEL_FORBIDDEN",details:{actionId:t.id,channel:n}})}function ma(t,e){let n=se(e.surface),r=t.
|
|
1023
|
+
surfaces;if(!r.includes("*")&&(!n||!r.includes(n)))throw new J(403,"Forbidden.",{code:"ACTION_SURFACE_FORBIDDEN",details:{
|
|
1024
|
+
actionId:t.id,surface:n}})}function ha(t,e){let{permission:n}=t,r=n.require;if(r==="none")return;if(Jn(e)==null)throw new J(
|
|
1025
|
+
401,n.message||"Authentication required.",{code:n.code||"ACTION_AUTHENTICATION_REQUIRED",details:{actionId:t.id}});if(r===
|
|
1026
|
+
"authenticated")return;let s=n.permissions;if(s.length<1)return;let i=Fn(r,s,Ie(e.permissions));if(i)throw new J(403,n.message||
|
|
1027
|
+
"Forbidden.",{code:n.code||"ACTION_PERMISSION_DENIED",details:{actionId:t.id,...i}})}function pa(t){return x(t?.fieldErrors)||
|
|
1028
|
+
x(t?.details?.fieldErrors)}async function ga(t,e){let n;try{n=yt(t.input,e,{phase:"input",context:`Action ${t.id} input`})}catch(r){
|
|
1029
|
+
throw pa(r)?Xn({details:la(r),cause:r}):r?.code==="ACTION_VALIDATION_FAILED"?r:Xn({details:{error:String(r?.message||"In\
|
|
1030
|
+
valid input.")},cause:r})}if(t.checkInput)try{await t.checkInput(n)}catch(r){throw pa(r)?Xn({details:la(r),cause:r}):r}return n}
|
|
1031
|
+
async function va(t,e){if(!t.output)return e;try{return yt(t.output,e,{phase:"output",context:`Action ${t.id} output`})}catch(n){
|
|
1032
|
+
throw new Error("Action output validation failed.",{cause:n})}}var bp=Object.freeze(["requestId","commandId","ip","userAgent"]);function wa(t={}){let e=t&&typeof t=="object"?t:{},n={...e,
|
|
1033
|
+
request:e.request||null};for(let r of bp)n[r]=w(e[r]);return n}function Tp(t){return x(t)?{...t}:null}function _p(t){let e=Tp(t);return e?(e.id==null&&(e.id=null),e):null}function Cp(t){
|
|
1034
|
+
let e=t&&typeof t=="object"?t:{};return{now:e.now instanceof Date?e.now:new Date,timezone:w(e.timezone),locale:w(e.locale)}}
|
|
1035
|
+
var Ap=new Set(["actor","permissions","surface","channel","requestMeta","timeMeta"]);function Ep(t={}){let e={...t};for(let n of Ap)
|
|
1036
|
+
delete e[n];return e}var Op=Symbol("jskit.actions.unloggedExecution");function Yn(t){return!(t&&typeof t=="object"&&t[Op]===!0)}function Rp(t){return se(t)||"internal"}function mr(t={}){let e=t&&
|
|
1037
|
+
typeof t=="object"?t:{},n=Ep(e);return Object.freeze({...n,actor:_p(e.actor),permissions:Ie(e.permissions),surface:se(e.
|
|
1038
|
+
surface),channel:Rp(e.channel),requestMeta:wa(e.requestMeta),timeMeta:Cp(e.timeMeta)})}async function Pp(t,e,n){for(let r of e){let o=await r(n),s=Array.isArray(o)?o:[o];for(let i of s)i!=null&&await t.publish(
|
|
1039
|
+
i)}}function ya(t,{definition:e,context:n,outcome:r,startedAt:o,errorCode:s=null}){Yn(n)&&t.debug({action:e.id,version:e.
|
|
1040
|
+
version,channel:n.channel,surface:n.surface,requestId:n.requestMeta.requestId||null,durationMs:Date.now()-o,outcome:r,errorCode:s},
|
|
1041
|
+
"action.execution")}async function Zn({definition:t,declared:e,input:n,context:r,deps:o,events:s,logger:i,policy:a}){let c=mr(
|
|
1042
|
+
r),d=Date.now();try{fa(t,c),ma(t,c),ha(t,c);let u=await ga(t,n),f=await a.execute(Object.freeze({definition:e,input:u,context:c,
|
|
1043
|
+
run:(g,I)=>t.execute(g,I,o)})),l=await va(t,f);return await Pp(s,t.events,Object.freeze({definition:t,input:u,result:l,context:c})),
|
|
1044
|
+
ya(i,{definition:t,context:c,outcome:"success",startedAt:d}),l}catch(u){throw ya(i,{definition:t,context:c,outcome:"fail\
|
|
1045
|
+
ure",startedAt:d,errorCode:String(u?.code||"ACTION_EXECUTION_FAILED").trim()}),u}}function eo(t,e){let n=new Map;for(let{definition:r}of e.actions){let o=Kn(r.id,r.version),s=t.get(o)??n.get(o);if(s)throw new Error(
|
|
1046
|
+
`Action definition "${o}" is duplicated between contributors "${s.contributorId}" and "${e.contributorId}".`);n.set(o,r)}
|
|
1047
|
+
return n}function kp(t){let e=[],n=new Map,r=new Map,o=new Map;for(let s of t){for(let[i,a]of eo(n,s))n.set(i,a);for(let{
|
|
1048
|
+
definition:i,declared:a}of s.actions)o.set(i,a),e.push(i),r.has(i.id)||r.set(i.id,[]),r.get(i.id).push(i)}for(let s of r.
|
|
1049
|
+
values())s.sort((i,a)=>a.version-i.version);return{definitions:Object.freeze(e),byVersionKey:n,byActionId:r,declaredByDefinition:o}}
|
|
1050
|
+
function Np(t){let e=Number(t);if(!Number.isInteger(e)||e<1)throw new J(400,"Validation failed.",{code:"ACTION_VERSION_I\
|
|
1051
|
+
NVALID",details:{fieldErrors:{version:"version must be an integer >= 1."},fieldErrorCodes:{version:{code:"kernel.action.\
|
|
1052
|
+
versionInvalid",params:{}}}}});return e}function Qn(t,e,n){let r=String(e||"").trim();if(!r)throw new J(400,"Validation \
|
|
1053
|
+
failed.",{code:"ACTION_ID_REQUIRED",details:{fieldErrors:{actionId:"actionId is required."},fieldErrorCodes:{actionId:{code:"\
|
|
1054
|
+
kernel.action.idRequired",params:{}}}}});if(n==null){let a=t.byActionId.get(r)||[];if(a.length<1)throw new J(404,"Not fo\
|
|
1055
|
+
und.",{code:"ACTION_NOT_FOUND",details:{actionId:r}});return a[0]}let o=Np(n),s=Kn(r,o),i=t.byVersionKey.get(s);if(!i)throw new J(
|
|
1056
|
+
404,"Not found.",{code:"ACTION_NOT_FOUND",details:{actionId:r,version:o}});return i}function Ia({contributors:t,events:e,
|
|
1057
|
+
logger:n,policy:r}){let o=kp(t);async function s({actionId:d,version:u,input:f,context:l,deps:g}){let I=Qn(o,d,u);return Zn(
|
|
1058
|
+
{definition:I,declared:o.declaredByDefinition.get(I),input:f,context:l,deps:g,events:e,logger:n,policy:r})}async function i({
|
|
1059
|
+
actionId:d,version:u,input:f,context:l,deps:g}){let I=Qn(o,d,u);if(I.kind!=="stream")throw new J(400,"Validation failed.",
|
|
1060
|
+
{code:"ACTION_STREAM_KIND_REQUIRED",details:{actionId:I.id,version:I.version,kind:I.kind}});return Zn({definition:I,declared:o.
|
|
1061
|
+
declaredByDefinition.get(I),input:f,context:l,deps:g,events:e,logger:n,policy:r})}function a(){return o.definitions.slice()}
|
|
1062
|
+
function c(d,u=null){return Qn(o,d,u)}return Object.freeze({execute:s,executeStream:i,listDefinitions:a,getDefinition:c})}var hr=Object.freeze({input(t){return t.input},execute({input:t,context:e,run:n}){return n(t,e)}});function Mp(t){if(!x(t))throw new TypeError("Event listener must be an object.");let e=String(t.id||"").trim();if(!e)throw new TypeError(
|
|
1063
|
+
"Event listener id is required.");if(typeof t.handle!="function")throw new TypeError(`Event listener "${e}" requires han\
|
|
1064
|
+
dle().`);if(t.matches!=null&&typeof t.matches!="function")throw new TypeError(`Event listener "${e}" matches must be a f\
|
|
1065
|
+
unction when provided.`);return Object.freeze({id:e,handle:t.handle,matches:t.matches??null})}function jp(t){if(!x(t))throw new TypeError(
|
|
1066
|
+
"Published event must be an object.");let e=String(t.type||"").trim();if(!e)throw new TypeError("Published event type is\
|
|
1067
|
+
required.");return Object.freeze({...t,type:e})}function St(){let t=[],e=new Set;function n(i){let a=Mp(i);if(e.has(a.id))
|
|
1068
|
+
throw new Error(`Event listener "${a.id}" is duplicated.`);return e.add(a.id),t.push(a),s}async function r(i){let a=jp(i);
|
|
1069
|
+
for(let c of t)c.matches&&c.matches(a)!==!0||await c.handle(a);return a}function o(){return Object.freeze({listenerIds:Object.
|
|
1070
|
+
freeze(t.map(i=>i.id))})}let s=Object.freeze({register:n,publish:r,diagnostics:o});return s}var Sa=Object.freeze({debug(){},info(){},warn(){},error(){}});function Dp(t){if(!x(t))throw new TypeError("Action catalogue registration must be an action contributor object.");return t}
|
|
1071
|
+
function to({events:t=St(),logger:e=Sa,policy:n=hr}={}){let r=[],o=[],s=new Set,i=new Map,a=null,c=!1;function d(k){if(c)
|
|
1072
|
+
throw new Error("Action catalogue registration is closed after discovery or execution begins.");let R=ca(Dp(k),n);for(let[
|
|
1073
|
+
O,D]of eo(i,R))i.set(O,D);return r.push(R),H}function u({id:k,contribute:R}={}){if(c)throw new Error("Action catalogue r\
|
|
1074
|
+
egistration is closed after discovery or execution begins.");let O=String(k||"").trim();if(!O)throw new TypeError("Actio\
|
|
1075
|
+
n context contributor id is required.");if(typeof R!="function")throw new TypeError(`Action context contributor "${O}" r\
|
|
1076
|
+
equires contribute().`);if(s.has(O))throw new Error(`Action context contributor "${O}" is duplicated.`);return s.add(O),
|
|
1077
|
+
o.push(Object.freeze({id:O,contribute:R})),H}function f(){return c=!0,a??=Ia({contributors:r,events:t,logger:e,policy:n}),
|
|
1078
|
+
a}function l(k,R){let O={...k};for(let[D,W]of Object.entries(x(R)?R:{}))D==="requestMeta"?O.requestMeta={...x(W)?W:{},...x(
|
|
1079
|
+
O.requestMeta)?O.requestMeta:{}}:Object.hasOwn(O,D)||(O[D]=W);return O}async function g({definition:k,input:R,context:O}){
|
|
1080
|
+
let D={...x(O)?O:{}};for(let W of o){let fe=await W.contribute(Object.freeze({actionId:k?.id??null,version:k?.version??null,
|
|
1081
|
+
definition:k,input:Object.freeze({...x(R)?R:{}}),context:Object.freeze({...D})}));D=l(D,fe)}return Object.freeze(D)}function I({
|
|
1082
|
+
actionId:k,version:R,input:O,context:D}){return g({definition:f().getDefinition(k,R),input:O,context:D})}async function _({
|
|
1083
|
+
input:k,context:R}={}){return c=!0,mr(await g({definition:null,input:k,context:R}))}async function P(k,R={}){let O=R&&typeof R==
|
|
1084
|
+
"object"?R:{},D=O.input&&typeof O.input=="object"?O.input:{},W=O.version==null?null:O.version,fe=await I({actionId:O.actionId,
|
|
1085
|
+
version:W,input:D,context:O.context});return f()[k]({actionId:O.actionId,version:W,input:D,context:fe,deps:x(O.deps)?O.deps:
|
|
1086
|
+
{}})}function N(k){return P("execute",k)}function z(k){return P("executeStream",k)}function L(){return f().listDefinitions()}
|
|
1087
|
+
function q(k,R=null){return f().getDefinition(k,R)}let H=Object.freeze({register:d,registerContextContributor:u,execute:N,
|
|
1088
|
+
executeStream:z,contextFor:_,listDefinitions:L,getDefinition:q});return H}var zp=Ye({id:"runtime.actions",requires:{events:"runtime.events",logger:"runtime.logger"},optional:{policy:"runtime.act\
|
|
1089
|
+
ions.policy"},provides:{actions:"runtime.actions"},setup({events:t,logger:e,policy:n}){return{actions:to({events:t,logger:e,
|
|
1090
|
+
policy:n??hr})}}});var xa="public";var Up="/api",ba=`${Up}/bootstrap`;function ro(){let t=[],e=new Set,n=!1;function r({id:a,order:c=0,contribute:d}={}){if(n)throw new Error("Bootstrap regis\
|
|
1091
|
+
tration is closed after the first payload is resolved.");let u=w(a);if(!u)throw new TypeError("Bootstrap contributor id \
|
|
1092
|
+
is required.");if(typeof d!="function")throw new TypeError(`Bootstrap contributor "${u}" requires contribute().`);if(e.has(
|
|
1093
|
+
u))throw new Error(`Bootstrap contributor "${u}" is duplicated.`);return e.add(u),t.push(Object.freeze({id:u,order:Number.
|
|
1094
|
+
isFinite(c)?Number(c):0,contribute:d})),i}async function o(a={}){n=!0;let c={},d=t.map((u,f)=>({entry:u,index:f})).sort(
|
|
1095
|
+
(u,f)=>u.entry.order-f.entry.order||u.index-f.index).map(({entry:u})=>u);for(let u of d){let f=await u.contribute(Object.
|
|
1096
|
+
freeze({...x(a)?a:{},payload:Object.freeze({...c})}));c={...c,...x(f)?f:{}}}return Object.freeze(c)}function s(){return Object.
|
|
1097
|
+
freeze({sealed:n,contributorIds:Object.freeze(t.map(a=>a.id).sort())})}let i=Object.freeze({register:r,resolve:o,diagnostics:s});
|
|
1098
|
+
return i}var Fp=Ye({id:"runtime.bootstrap",requires:{http:"runtime.http"},provides:{bootstrap:"runtime.bootstrap"},setup({http:t}){
|
|
1099
|
+
let e=ro();return t.router.register("GET",ba,{auth:xa,meta:{tags:["bootstrap"],summary:"Resolve app bootstrap payload"}},
|
|
1100
|
+
async(n,r)=>{r.code(200).send(await e.resolve({request:n,reply:r,query:n.query||{}}))}),{bootstrap:e}}});var qp=Ye({id:"runtime.events",provides:{events:"runtime.events"},setup(){return{events:St()}}});var Bp=8,FC=Object.freeze({notOffered:"This assistant does not keep unsaved tool calls out of what it saves, so it is no\
|
|
1101
|
+
t offered here.",discoveryOnly:"Only the discovery tools are offered here, and an unsaved action is never discoverable.",
|
|
1102
|
+
directLimit:`At most ${Bp} actions are offered directly beside action discovery.`});var Ta=20,Hp=32*1024,_a=48*1024,no=Object.freeze({search:"assistant_action_search",contract:"assistant_action_contract",
|
|
1103
|
+
execute:"assistant_action_execute"}),oo=Object.freeze({type:"object",additionalProperties:!0}),Vp=Object.freeze({type:"o\
|
|
963
1104
|
bject",additionalProperties:!1,properties:{query:{type:"string",maxLength:200,description:"Optional literal words or act\
|
|
964
1105
|
ion-id fragments; every word must match. Use short resource or operation terms such as list. Omit query to browse all av\
|
|
965
1106
|
ailable actions."},cursor:{type:"string",maxLength:1e3,description:"Opaque cursor returned by the previous search page."},
|
|
966
|
-
limit:{type:"integer",minimum:1,maximum:
|
|
967
|
-
object",additionalProperties:!1,required:["items","nextCursor","total"],properties:{items:{type:"array",maxItems:
|
|
1107
|
+
limit:{type:"integer",minimum:1,maximum:Ta,description:"Maximum compact matches to return."}}}),Gp=Object.freeze({type:"\
|
|
1108
|
+
object",additionalProperties:!1,required:["items","nextCursor","total"],properties:{items:{type:"array",maxItems:Ta,items:{
|
|
968
1109
|
type:"object",additionalProperties:!1,required:["actionId","version","kind","description"],properties:{actionId:{type:"s\
|
|
969
1110
|
tring"},version:{type:"integer",minimum:1},kind:{type:"string"},description:{type:"string"}}}},nextCursor:{anyOf:[{type:"\
|
|
970
|
-
string"},{type:"null"}]},total:{type:"integer",minimum:0}}}),
|
|
971
|
-
"actionId"],properties:{actionId:{type:"string",minLength:1,maxLength:300},version:{type:"integer",minimum:1}}}),
|
|
1111
|
+
string"},{type:"null"}]},total:{type:"integer",minimum:0}}}),Wp=Object.freeze({type:"object",additionalProperties:!1,required:[
|
|
1112
|
+
"actionId"],properties:{actionId:{type:"string",minLength:1,maxLength:300},version:{type:"integer",minimum:1}}}),Kp=Object.
|
|
972
1113
|
freeze({type:"object",additionalProperties:!1,required:["actionId","version","kind","description","inputSchema","outputS\
|
|
973
1114
|
chema"],properties:{actionId:{type:"string"},version:{type:"integer",minimum:1},kind:{type:"string"},description:{type:"\
|
|
974
|
-
string"},inputSchema:
|
|
975
|
-
"input"],properties:{actionId:{type:"string",minLength:1,maxLength:300},version:{type:"integer",minimum:1},input:
|
|
1115
|
+
string"},inputSchema:oo,outputSchema:oo}}),Jp=Object.freeze({type:"object",additionalProperties:!1,required:["actionId",
|
|
1116
|
+
"input"],properties:{actionId:{type:"string",minLength:1,maxLength:300},version:{type:"integer",minimum:1},input:oo}}),Xp=Object.
|
|
976
1117
|
freeze({type:"object",additionalProperties:!1,required:["actionId","version","result"],properties:{actionId:{type:"strin\
|
|
977
|
-
g"},version:{type:"integer",minimum:1},result:{}}}),
|
|
1118
|
+
g"},version:{type:"integer",minimum:1},result:{}}}),Ca=Object.freeze([Object.freeze({name:no.search,description:"Discove\
|
|
978
1119
|
r application actions available to the current user and surface, including list, search, and query operations for multip\
|
|
979
1120
|
le records. Search before claiming a capability is unavailable. If terminology does not match, use broader terms or omit\
|
|
980
|
-
query to browse. Returns compact paged matches without schemas; follow nextCursor when more discovery is needed.",parameters:
|
|
981
|
-
outputSchema:
|
|
982
|
-
e action before executing it.",parameters:
|
|
983
|
-
vailable action after loading its exact contract in this turn. The action result is returned in result.",parameters:
|
|
984
|
-
attachments:!1,tools:!1,nativeTools:!1});var
|
|
1121
|
+
query to browse. Returns compact paged matches without schemas; follow nextCursor when more discovery is needed.",parameters:Vp,
|
|
1122
|
+
outputSchema:Gp}),Object.freeze({name:no.contract,description:"Load the exact input and output contract for one availabl\
|
|
1123
|
+
e action before executing it.",parameters:Wp,outputSchema:Kp}),Object.freeze({name:no.execute,description:"Execute one a\
|
|
1124
|
+
vailable action after loading its exact contract in this turn. The action result is returned in result.",parameters:Jp,outputSchema:Xp})]);var HC=new URL("./../../../@jskit-ai/assistant-core/src/server/conversation/commandWrapper.js",import.meta.url).href;var TA=new Error("A later Stop or turn superseded this Claude frame.");var nf=Object.freeze({streaming:!1,instructions:!1,configuration:!1,goals:!1,goalBudgets:!1,goalCommands:Object.freeze({}),
|
|
1125
|
+
attachments:!1,tools:!1,nativeTools:!1});var AE=Object.freeze({goals:!0,goalBudgets:!1,goalCommands:Object.freeze({set:Object.freeze({delivery:"message",interruptsTurn:!1}),
|
|
985
1126
|
resume:Object.freeze({delivery:"message",interruptsTurn:!1}),pause:Object.freeze({delivery:"control",interruptsTurn:!0}),
|
|
986
|
-
cancel:Object.freeze({delivery:"message",interruptsTurn:!0})})}),
|
|
987
|
-
1",secretNamespace:n="codex-auth-secret-v1"}={}){function r(d="",
|
|
988
|
-
elper authentication is unavailable. Reconnect Codex and retry.");return l.code=
|
|
989
|
-
|
|
990
|
-
label:
|
|
991
|
-
ex_helper_auth_invalid`,`${
|
|
992
|
-
sha256:${
|
|
993
|
-
"hex")}`}function i(d=""){return
|
|
994
|
-
let
|
|
1127
|
+
cancel:Object.freeze({delivery:"message",interruptsTurn:!0})})}),EE=Object.freeze({});var nO=new URL("./../../../@jskit-ai/assistant-core/src/server/conversation/codexRuntime.js",import.meta.url).href;import{createHash as Na}from"node:crypto";import{open as bf}from"node:fs/promises";import Ma from"node:path";var co=1024*1024,Tf=256*1024,ja=512,_f=128,Cf=16*1024;function uo({errorPrefix:t="",identityNamespace:e="codex-account-v\
|
|
1128
|
+
1",secretNamespace:n="codex-auth-secret-v1"}={}){function r(d="",u="",{messageCode:f}={}){let l=new Error(b(u)||"Codex h\
|
|
1129
|
+
elper authentication is unavailable. Reconnect Codex and retry.");return l.code=b(d)||`${t}codex_helper_auth_unavailable`,
|
|
1130
|
+
b(u)?f&&(l.messageCode=f):l.messageCode="assistant.codex.helperAuthUnavailable",l.messageCode&&(l.messageParams={}),l}function o(d,{
|
|
1131
|
+
label:u="Codex authentication value",maxLength:f=0}={}){if(typeof d!="string"||d.length===0||d.length>f)throw r(`${t}cod\
|
|
1132
|
+
ex_helper_auth_invalid`,`${u} is missing or invalid. Reconnect Codex and retry.`);return d}function s(d="",u=""){return`\
|
|
1133
|
+
sha256:${Na("sha256").update(`${e}\0`,"utf8").update(b(d),"utf8").update("\0","utf8").update(String(u||""),"utf8").digest(
|
|
1134
|
+
"hex")}`}function i(d=""){return Na("sha256").update(`${n}\0`,"utf8").update(String(d||""),"utf8").digest("hex")}async function a(d=""){
|
|
1135
|
+
let u=null;try{u=await bf(d,"r");let f=await u.stat();if(!f.isFile()||f.size>co)throw r(`${t}codex_helper_auth_invalid`,
|
|
995
1136
|
"The selected Codex authentication record is invalid. Reconnect Codex and retry.",{messageCode:"assistant.codex.authReco\
|
|
996
|
-
rdInvalid"});let l=Buffer.alloc(
|
|
997
|
-
break;
|
|
998
|
-
nect Codex and retry.",{messageCode:"assistant.codex.authRecordTooLarge"});let
|
|
999
|
-
f8"));if(!
|
|
1000
|
-
_helper_auth_`)?
|
|
1001
|
-
onnect Codex and retry.",{messageCode:"assistant.codex.authRecordUnreadable"})}finally{await
|
|
1002
|
-
async function c(d={}){let
|
|
1137
|
+
rdInvalid"});let l=Buffer.alloc(co+1),g=0;for(;g<l.length;){let{bytesRead:_}=await u.read(l,g,l.length-g,null);if(_===0)
|
|
1138
|
+
break;g+=_}if(g>co)throw r(`${t}codex_helper_auth_invalid`,"The selected Codex authentication record is too large. Recon\
|
|
1139
|
+
nect Codex and retry.",{messageCode:"assistant.codex.authRecordTooLarge"});let I=JSON.parse(l.subarray(0,g).toString("ut\
|
|
1140
|
+
f8"));if(!x(I))throw new Error("invalid authentication record");return I}catch(f){throw f?.code?.startsWith?.(`${t}codex\
|
|
1141
|
+
_helper_auth_`)?f:r(`${t}codex_helper_auth_unavailable`,"The selected Codex authentication record could not be read. Rec\
|
|
1142
|
+
onnect Codex and retry.",{messageCode:"assistant.codex.authRecordUnreadable"})}finally{await u?.close().catch(()=>null)}}
|
|
1143
|
+
async function c(d={}){let u=b(d.toolHomeSource);if(!u||!Ma.isAbsolute(u))throw r(`${t}codex_helper_auth_unavailable`,"T\
|
|
1003
1144
|
he selected Codex account is unavailable. Reconnect Codex and retry.",{messageCode:"assistant.codex.accountUnavailable"});
|
|
1004
|
-
let
|
|
1005
|
-
{},
|
|
1006
|
-
|
|
1007
|
-
{accessToken:
|
|
1008
|
-
ikey","api_key"].includes(l)){let
|
|
1009
|
-
authMode:"apiKey",identitySignature:s("apiKey",
|
|
1145
|
+
let f=await a(Ma.join(u,".codex","auth.json")),l=b(f.auth_mode).toLowerCase();if(l==="chatgpt"){let g=x(f.tokens)?f.tokens:
|
|
1146
|
+
{},I=o(g.account_id,{label:"Codex account identity",maxLength:ja}),_=o(g.access_token,{label:"Codex access token",maxLength:Tf}),
|
|
1147
|
+
P=g.chatgpt_plan_type??g.plan_type,N=P==null||P===""?"":o(P,{label:"Codex plan type",maxLength:_f});return Object.freeze(
|
|
1148
|
+
{accessToken:_,accountId:I,authMode:"chatgpt",identitySignature:s("chatgpt",I),planType:N,secretSignature:i(_)})}if(["ap\
|
|
1149
|
+
ikey","api_key"].includes(l)){let g=o(f.OPENAI_API_KEY,{label:"Codex API key",maxLength:Cf});return Object.freeze({apiKey:g,
|
|
1150
|
+
authMode:"apiKey",identitySignature:s("apiKey",g),secretSignature:i(g)})}throw r(`${t}codex_helper_auth_invalid`,"The se\
|
|
1010
1151
|
lected Codex authentication mode is unsupported. Reconnect Codex and retry.",{messageCode:"assistant.codex.authModeUnsup\
|
|
1011
|
-
ported"})}return Object.freeze({error:r,identitySignature:s,readRecord:a,readSelected:c})}var
|
|
1152
|
+
ported"})}return Object.freeze({error:r,identitySignature:s,readRecord:a,readSelected:c})}var TO=Object.freeze({label:"Checking the Codex sign-in",operationId:"codex-auth-preflight"});var PO=uo().error;var tR=4*1024*1024;var lP=Object.freeze({goals:!0,goalBudgets:!0,goalCommands:Object.freeze({set:Object.freeze({delivery:"control",interruptsTurn:!1}),
|
|
1012
1153
|
resume:Object.freeze({delivery:"control",interruptsTurn:!1}),pause:Object.freeze({delivery:"control",interruptsTurn:!0}),
|
|
1013
|
-
cancel:Object.freeze({delivery:"control",interruptsTurn:!1})})});var
|
|
1014
|
-
ersation_attachments_not_configured",messageCode:"assistant.conversation.attachmentsNotConfigured"})}});var
|
|
1154
|
+
cancel:Object.freeze({delivery:"control",interruptsTurn:!1})})});var vP=2*1024*1024,wP=32*1024*1024,yP=2*1024*1024;var jk=new URL("./../../../@jskit-ai/assistant-core/src/server/conversation/openCodeProcess.js",import.meta.url).href;var qk=256*1024;var $k=2*1024*1024;var Bk=Ca.map(({name:t,description:e,parameters:n})=>({type:"function",function:{name:t,description:e,parameters:n}}));var y0=Object.freeze({});var P0=Object.freeze([]);var Zf=Object.freeze({resolve(){throw new F(400,"File attachments are not configured for this conversation.",{code:"conv\
|
|
1155
|
+
ersation_attachments_not_configured",messageCode:"assistant.conversation.attachmentsNotConfigured"})}});var F0=Object.freeze([{message:"This conversation exceeds the configured API history limit. Start another conversation o\
|
|
1015
1156
|
r increase the limit.",messageCode:"assistant.conversation.apiHistoryLimit"},{message:"The model reached its output toke\
|
|
1016
1157
|
n limit before completing the answer. Increase maxOutputTokens in the conversation limits.",messageCode:"assistant.conve\
|
|
1017
1158
|
rsation.outputTokenLimit"},{message:"The model stream ended without confirming its application tool calls.",messageCode:"\
|
|
@@ -1030,21 +1171,21 @@ t be saved. Restore storage access and retry saving.",messageCode:"assistant.con
|
|
|
1030
1171
|
Conversation progress could not be saved. Restore access to its storage before continuing.",messageCode:"assistant.conve\
|
|
1031
1172
|
rsation.progressUnsaved"},{message:"The conversation request exceeded its time limit.",messageCode:"assistant.conversati\
|
|
1032
1173
|
on.requestTimedOut"},{message:"Work stopped.",messageCode:"assistant.conversation.workStopped"},{message:"Stopped by use\
|
|
1033
|
-
r.",messageCode:"assistant.conversation.stoppedByUser"}]);var
|
|
1034
|
-
type:"string",maxLength:
|
|
1174
|
+
r.",messageCode:"assistant.conversation.stoppedByUser"}]);var Qe=Object.freeze({text:16e3,toolName:256,arguments:256*1024,toolProgress:280});var CN=oe({kind:{type:"string",enum:["reply","tool"],required:!0},text:{type:"string",maxLength:Qe.text,required:!1},toolName:{
|
|
1175
|
+
type:"string",maxLength:Qe.toolName,required:!1},arguments:{type:"string",maxLength:Qe.arguments,required:!1}}),AN={type:"\
|
|
1035
1176
|
object",additionalProperties:!1,required:["kind","text","toolName","arguments"],properties:{kind:{type:"string",enum:["r\
|
|
1036
|
-
eply","tool"]},text:{type:"string",maxLength:
|
|
1037
|
-
first tool request; empty for subsequent tool requests."},toolName:{type:"string",maxLength:
|
|
1038
|
-
string",maxLength:
|
|
1039
|
-
readInstructions:e=
|
|
1177
|
+
eply","tool"]},text:{type:"string",maxLength:Qe.text,description:"The final reply, or a brief progress sentence for the \
|
|
1178
|
+
first tool request; empty for subsequent tool requests."},toolName:{type:"string",maxLength:Qe.toolName},arguments:{type:"\
|
|
1179
|
+
string",maxLength:Qe.arguments}}};var Aj=Object.freeze({});function cm(){throw new TypeError("Hook delivery requires an instruction resolver.")}function Io({resolveConversation:t,
|
|
1180
|
+
readInstructions:e=cm}){if(typeof t!="function")throw new TypeError("Conversation hook delivery requires a binding resol\
|
|
1040
1181
|
ver.");return async function(r){if(r.scope!=="session")return{kind:"unclaimed"};let o=await t(r);if(!o)return{kind:"uncl\
|
|
1041
1182
|
aimed"};if(o.delivery==="native")return{kind:"delivery",text:""};if(o.delivery!=="hook")throw new TypeError("Unknown con\
|
|
1042
1183
|
versation instruction delivery mode.");let s=await e(o,r);if(typeof s!="string"||!s.trim())throw new TypeError("Managed \
|
|
1043
|
-
conversation instructions are unavailable.");return{kind:"delivery",text:s}}}var
|
|
1184
|
+
conversation instructions are unavailable.");return{kind:"delivery",text:s}}}var Rj=Object.freeze({codex:Object.freeze({requiresWriterExclusion:!1}),claude:Object.freeze({requiresWriterExclusion:!0,
|
|
1044
1185
|
allowsManagedServer:!1,matchesProcess:({executable:t,commandLine:e})=>/(?:^|[\0/])claude(?:\0|$)|@anthropic-ai\/claude-code\//u.
|
|
1045
1186
|
test(`${t||""}\0${e}`)}),opencode:Object.freeze({requiresWriterExclusion:!0,allowsManagedServer:!0,matchesProcess:({executable:t,
|
|
1046
|
-
commandLine:e})=>/(?:^|[\0/])opencode(?:\0|$)/u.test(`${t||""}\0${e}`)})});import{readFile as
|
|
1047
|
-
"managedPreview"]),
|
|
1187
|
+
commandLine:e})=>/(?:^|[\0/])opencode(?:\0|$)/u.test(`${t||""}\0${e}`)})});import{readFile as dm}from"node:fs/promises";import So from"node:path";function wr(t){return String(t||"").trim()}var um=Object.freeze(["main","temporary"]),Ba=Object.freeze(["managedDatabaseRefresh","managedEnvironment","managedGit",
|
|
1188
|
+
"managedPreview"]),Ha=Object.freeze(["managedPages"]),lm=64*1024,cD=Object.freeze(["When user input is necessary, ask no\
|
|
1048
1189
|
more than three concise, high-impact questions at once.","Put multiple questions on separate lines as `[1] Question`, `\
|
|
1049
1190
|
[2] Question`, and so on.","For a small fixed set of useful choices, put `Possible answers:` and a short bullet list dir\
|
|
1050
1191
|
ectly beneath its own question, before the next one; never collect several questions' answers into one trailing list.","\
|
|
@@ -1057,7 +1198,7 @@ Possible answers:
|
|
|
1057
1198
|
[2] Tell the main agent before changes?
|
|
1058
1199
|
Possible answers:
|
|
1059
1200
|
- Yes, tell main first
|
|
1060
|
-
- No, proceed independently`]),
|
|
1201
|
+
- No, proceed independently`]),dD=Object.freeze(["The Vibe64-managed preview is the canonical application server; never \
|
|
1061
1202
|
start a duplicate or replacement server. If it is unavailable, report that blocker. Describe only rendered browser evide\
|
|
1062
1203
|
nce.","When adopting an authenticated app, or when its login blocks Preview inspection, inspect identity support/names w\
|
|
1063
1204
|
ith `vibe64-helper preview status`; prefer `vibe64-helper preview browser identity <configured-name>` to requesting pass\
|
|
@@ -1117,7 +1258,7 @@ waits for cleanup/restoration; retry if cleanup needs attention. Never kill test
|
|
|
1117
1258
|
exit alone does not prove tests stopped. Recheck status before reporting a busy blocker.","If a managed command reports \
|
|
1118
1259
|
kernel task denials or a resource incident, report the blocker with its diagnostic and incident ID and ask the platform \
|
|
1119
1260
|
operator to inspect that evidence before retrying; never raise test timeouts or weaken assertions to work around a proce\
|
|
1120
|
-
ss/thread limit. A generic browser timeout without resource evidence does not establish a platform cause."]),
|
|
1261
|
+
ss/thread limit. A generic browser timeout without resource evidence does not establish a platform cause."]),uD=Object.freeze(
|
|
1121
1262
|
['Pages: `vibe64-helper pages publish <file.html|folder> [--title "Title"]` publishes an HTML page (one file, or a folde\
|
|
1122
1263
|
r with index.html and its own scripts, styles, data and images) that everyone with access to this project can open from \
|
|
1123
1264
|
Vibe64\'s Pages list; `vibe64-helper pages update <page-id> <file.html|folder>` gives a page a new version under the same\
|
|
@@ -1139,7 +1280,7 @@ e data; use --prompt only when gathering it needs judgement.","Before making a p
|
|
|
1139
1280
|
hen a page about the same subject already exists, update it instead of making a new one.","Do not offer pages for quick \
|
|
1140
1281
|
answers, code changes, or documents that belong in the repository. Offer at most once per topic; do not nag.","Everyone \
|
|
1141
1282
|
with access to the project can open a page: never put secrets in one, or anything not every project member should see."]),
|
|
1142
|
-
|
|
1283
|
+
lD=Object.freeze(["Each managed shell command receives current development Env from Vibe64, including declared resource \
|
|
1143
1284
|
bindings; use them in ordinary commands. Do not build environment injection or copy managed credentials into source. Res\
|
|
1144
1285
|
ource provisioning and application migrations remain separate preparation steps.","Use `vibe64-helper env status [develo\
|
|
1145
1286
|
pment|production|all]` to inspect configured key names without revealing values.","Pipe an available value to `vibe64-he\
|
|
@@ -1154,30 +1295,30 @@ xplicit direction, or edit Vibe64 runtime/session storage.","After an Env mutati
|
|
|
1154
1295
|
ey names, never their values, and claim success only when the command succeeded.","Store a secret the application needs \
|
|
1155
1296
|
generated (such as an application key) by generating it with the framework's own generator and piping it to `vibe64-help\
|
|
1156
1297
|
er env set <scope> <KEY> --secret`. Never write it into a generated `.env` file: Vibe64 regenerates that file from Env."]);
|
|
1157
|
-
function
|
|
1298
|
+
function xo(t,e){if(!t||typeof t!="object"||Array.isArray(t))throw new TypeError(`${e} must be an object.`);return t}function bt(t,e,n){
|
|
1158
1299
|
let r=new Set(e),o=Object.keys(t).filter(s=>!r.has(s));if(o.length>0)throw new TypeError(`${n} contains unsupported fiel\
|
|
1159
|
-
ds: ${o.join(", ")}.`)}function
|
|
1300
|
+
ds: ${o.join(", ")}.`)}function pm(t){if(bt(t,["conversationKind","scope","session","hostGuidance"],"Vibe64 session cont\
|
|
1160
1301
|
ext"),t.hostGuidance!==void 0&&(typeof t.hostGuidance!="string"||Buffer.byteLength(t.hostGuidance,"utf8")>1024))throw new TypeError(
|
|
1161
|
-
"Vibe64 host guidance must be bounded text supplied by the host.");if(!
|
|
1162
|
-
"Vibe64 session context has an unknown conversationKind.");let e=
|
|
1163
|
-
...
|
|
1164
|
-
`Vibe64 session capability ${r} must be boolean.`);return[r,e[r]]}));for(let r of
|
|
1302
|
+
"Vibe64 host guidance must be bounded text supplied by the host.");if(!um.includes(t.conversationKind))throw new TypeError(
|
|
1303
|
+
"Vibe64 session context has an unknown conversationKind.");let e=xo(t.session,"Vibe64 session capabilities");bt(e,[...Ba,
|
|
1304
|
+
...Ha],"Vibe64 session capabilities");let n=Object.fromEntries(Ba.map(r=>{if(typeof e[r]!="boolean")throw new TypeError(
|
|
1305
|
+
`Vibe64 session capability ${r} must be boolean.`);return[r,e[r]]}));for(let r of Ha){if(e[r]!==void 0&&typeof e[r]!="bo\
|
|
1165
1306
|
olean")throw new TypeError(`Vibe64 session capability ${r} must be boolean.`);e[r]===!0&&(n[r]=!0)}return{conversationKind:t.
|
|
1166
|
-
conversationKind,scope:"session",...t.hostGuidance?{hostGuidance:t.hostGuidance}:{},session:n}}function
|
|
1167
|
-
pe","stableContext"],"Vibe64 ephemeral context");let e=String(t.stableContext||"").trim();if(!e||e.length>
|
|
1168
|
-
"Vibe64 ephemeral context requires bounded stableContext.");return{scope:"ephemeral",stableContext:e}}function
|
|
1169
|
-
scope==="session")return
|
|
1170
|
-
sion and ephemeral scopes only.")}async function
|
|
1307
|
+
conversationKind,scope:"session",...t.hostGuidance?{hostGuidance:t.hostGuidance}:{},session:n}}function fm(t){bt(t,["sco\
|
|
1308
|
+
pe","stableContext"],"Vibe64 ephemeral context");let e=String(t.stableContext||"").trim();if(!e||e.length>lm)throw new TypeError(
|
|
1309
|
+
"Vibe64 ephemeral context requires bounded stableContext.");return{scope:"ephemeral",stableContext:e}}function mm(t){if(t.
|
|
1310
|
+
scope==="session")return pm(t);if(t.scope==="ephemeral")return fm(t);throw new TypeError("The Vibe64 driver supports ses\
|
|
1311
|
+
sion and ephemeral scopes only.")}async function Va(t={},{readRegistry:e=dm,workdir:n=""}={}){let r=xo(t,"Vibe64 host resolver request");if(bt(r,["data","\
|
|
1171
1312
|
providerSessionId","parentSessionIds","scope"],"Vibe64 host resolver request"),!["session","turn"].includes(r.scope))throw new TypeError(
|
|
1172
|
-
"The Vibe64 host resolver scope must be session or turn.");if(r.scope==="turn")return null;let o=
|
|
1173
|
-
resolver data");
|
|
1313
|
+
"The Vibe64 host resolver scope must be session or turn.");if(r.scope==="turn")return null;let o=xo(r.data,"Vibe64 host \
|
|
1314
|
+
resolver data");bt(o,["registryPath"],"Vibe64 host resolver data");let s=wr(o.registryPath);if(!So.isAbsolute(s))throw new TypeError(
|
|
1174
1315
|
"Vibe64 host resolver data requires an absolute registryPath.");let i=JSON.parse(await e(s,"utf8"));if(!Array.isArray(i?.
|
|
1175
|
-
sessions))throw new TypeError("The conversation ownership registry is invalid.");let a=i.sessions,c=
|
|
1316
|
+
sessions))throw new TypeError("The conversation ownership registry is invalid.");let a=i.sessions,c=wr(r.providerSessionId);
|
|
1176
1317
|
if(r.parentSessionIds!==void 0&&(!Array.isArray(r.parentSessionIds)||r.parentSessionIds.length>32||r.parentSessionIds.some(
|
|
1177
|
-
l=>typeof l!="string"||!l.trim())))throw new TypeError("Invalid native conversation ancestry.");let
|
|
1178
|
-
[]].filter(Boolean).map(l=>a.find(
|
|
1179
|
-
|
|
1180
|
-
t directory.");return
|
|
1181
|
-
tion input exceeds 256 KiB.");var
|
|
1182
|
-
process.stdout.write(await t(
|
|
1183
|
-
native"}:null});process.stdout.write(JSON.stringify(await t(
|
|
1318
|
+
l=>typeof l!="string"||!l.trim())))throw new TypeError("Invalid native conversation ancestry.");let u=[c,...r.parentSessionIds||
|
|
1319
|
+
[]].filter(Boolean).map(l=>a.find(g=>wr(g?.upstreamSessionId)===l)).find(Boolean),f=u?.promptContext;if(!f)return null;if(n&&
|
|
1320
|
+
u.workdir&&So.resolve(n)!==So.resolve(u.workdir))throw new Error("The managed conversation belongs to a different projec\
|
|
1321
|
+
t directory.");return mm(f)}var bo="";for await(let t of process.stdin)if(bo+=t,Buffer.byteLength(bo)>256*1024)throw new Error("Conversation instruc\
|
|
1322
|
+
tion input exceeds 256 KiB.");var Ga=JSON.parse(bo);if(process.argv[2]==="--instructions"){let{vibe64ConversationInstructions:t}=await import("@local/vibe64-genesis/server");
|
|
1323
|
+
process.stdout.write(await t(Ga))}else{let t=Io({resolveConversation:async e=>await Va(e,{workdir:process.cwd()})?{delivery:"\
|
|
1324
|
+
native"}:null});process.stdout.write(JSON.stringify(await t(Ga)))}
|