experimental-ash 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/docs/internals/hooks.md +13 -16
- package/dist/docs/internals/message-runtime.md +1 -1
- package/dist/docs/public/auth-and-route-protection.md +3 -3
- package/dist/docs/public/typescript-api.md +2 -2
- package/dist/src/channel/types.d.ts +10 -12
- package/dist/src/chunks/{dev-authored-source-watcher-d_35Mp8T.js → dev-authored-source-watcher-B4PaZGUr.js} +1 -1
- package/dist/src/chunks/host-DsW72Q-w.js +65 -0
- package/dist/src/chunks/{paths-YoCQlavu.js → paths-OknjaYR8.js} +24 -24
- package/dist/src/chunks/prewarm-B4YblQ5m.js +6 -0
- package/dist/src/cli/commands/info.js +1 -1
- package/dist/src/cli/run.js +1 -1
- package/dist/src/compiled/.vendor-stamp.json +2 -2
- package/dist/src/compiled/@workflow/core/classify-error.d.ts +4 -3
- package/dist/src/compiled/@workflow/core/encryption.d.ts +7 -1
- package/dist/src/compiled/@workflow/core/index.js +2 -2
- package/dist/src/compiled/@workflow/core/package.json +1 -1
- package/dist/src/compiled/@workflow/core/runtime/constants.d.ts +47 -0
- package/dist/src/compiled/@workflow/core/runtime/replay-budget.d.ts +98 -0
- package/dist/src/compiled/@workflow/core/runtime.js +27 -27
- package/dist/src/compiled/@workflow/core/serialization/types.d.ts +14 -0
- package/dist/src/compiled/@workflow/core/serialization.d.ts +8 -0
- package/dist/src/compiled/@workflow/core/symbols.d.ts +16 -0
- package/dist/src/compiled/@workflow/core/version.d.ts +1 -1
- package/dist/src/compiled/@workflow/core/workflow.js +1 -1
- package/dist/src/compiled/@workflow/errors/error-codes.d.ts +5 -1
- package/dist/src/compiled/@workflow/errors/index.d.ts +15 -1
- package/dist/src/compiled/@workflow/errors/index.js +1 -1
- package/dist/src/compiled/@workflow/errors/package.json +1 -1
- package/dist/src/compiled/_chunks/workflow/{context-errors-zbKocOyk.js → context-errors-Bbvvp-li.js} +2 -2
- package/dist/src/compiled/_chunks/workflow/{dist-0iNBqPYp.js → dist-C7wPwOI9.js} +2 -2
- package/dist/src/compiled/_chunks/workflow/{dist-D774SUM4.js → dist-C_oiE-l7.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/resume-hook-C3VWUPii.js +12 -0
- package/dist/src/compiled/_chunks/workflow/sleep-QTkC1VFe.js +1 -0
- package/dist/src/compiled/_chunks/workflow/{symbols-D-4tVV8x.js → symbols-QezhMuLg.js} +1 -1
- package/dist/src/evals/cli/eval.js +1 -1
- package/dist/src/execution/await-authorization-orchestrator.d.ts +2 -1
- package/dist/src/execution/await-authorization-orchestrator.js +4 -0
- package/dist/src/execution/connection-auth-steps.d.ts +4 -0
- package/dist/src/execution/connection-auth-steps.js +9 -11
- package/dist/src/execution/node-step.d.ts +4 -5
- package/dist/src/execution/subagent-adapter.d.ts +0 -27
- package/dist/src/execution/subagent-adapter.js +2 -66
- package/dist/src/execution/subagent-hitl-proxy.d.ts +2 -2
- package/dist/src/execution/subagent-hitl-proxy.js +2 -2
- package/dist/src/execution/task-mode.d.ts +3 -3
- package/dist/src/execution/task-mode.js +3 -3
- package/dist/src/execution/turn-workflow.d.ts +41 -0
- package/dist/src/execution/turn-workflow.js +96 -0
- package/dist/src/execution/workflow-entry.js +77 -87
- package/dist/src/execution/workflow-errors.d.ts +14 -0
- package/dist/src/execution/workflow-errors.js +54 -0
- package/dist/src/execution/workflow-runtime.d.ts +34 -3
- package/dist/src/execution/workflow-runtime.js +52 -10
- package/dist/src/execution/workflow-steps.d.ts +27 -2
- package/dist/src/execution/workflow-steps.js +31 -26
- package/dist/src/harness/instrumentation-config.js +14 -7
- package/dist/src/harness/messages.d.ts +7 -7
- package/dist/src/harness/messages.js +4 -4
- package/dist/src/harness/runtime-actions.d.ts +4 -4
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/workflow-bundle/workflow-builders.d.ts +1 -1
- package/dist/src/internal/workflow-bundle/workflow-builders.js +20 -8
- package/dist/src/internal/workflow-bundle/workflow-transformer.d.ts +13 -0
- package/dist/src/internal/workflow-bundle/workflow-transformer.js +10 -4
- package/package.json +4 -4
- package/dist/src/chunks/host-tji7W0Nn.js +0 -65
- package/dist/src/chunks/prewarm-6duWvvb5.js +0 -6
- package/dist/src/compiled/_chunks/workflow/resume-hook-CL8Ed91K.js +0 -12
- package/dist/src/compiled/_chunks/workflow/sleep-Dn3i9nxI.js +0 -1
- package/dist/src/execution/continuous-entry.d.ts +0 -59
- package/dist/src/execution/continuous-entry.js +0 -487
- package/dist/src/execution/continuous-runtime.d.ts +0 -17
- package/dist/src/execution/continuous-runtime.js +0 -123
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# experimental-ash
|
|
2
2
|
|
|
3
|
+
## 0.24.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 1a43bef: Remove `result` from `RunHandle`. The workflow runtime's terminal state is observed through the durable event stream's `session.completed` / `session.failed` events. The continuous runtime keeps `result` via a new `ContinuousRunHandle` subtype (in-process resolution; no polling).
|
|
8
|
+
- 5a9f798: Split the durable workflow runtime into a long-lived session driver plus per-turn child workflows. The driver acquires the session's writable once in its workflow body and forwards it to each turn workflow as the second positional `start()` argument; the per-turn child writes directly to the driver's stream, preserving the stable client session stream while preparing turn execution for deployment updates. Requires `@workflow/core` ≥ 5.0.0-beta.6 ([vercel/workflow#2059](https://github.com/vercel/workflow/pull/2059)), which routes child writes to the parent run's stream with a parent-key encrypt-only handshake.
|
|
9
|
+
- 8b2957a: Remove the continuous (in-memory, non-durable) runtime and its supporting
|
|
10
|
+
machinery. The workflow runtime is now the only runtime. Deleted public
|
|
11
|
+
exports: `createContinuousLoopRuntime`, `createContinuousLoopRuntimeFactory`,
|
|
12
|
+
`ContinuousRuntime`, `ContinuousCreateRuntime`, `ContinuousRunHandle`. The
|
|
13
|
+
process-local subagent HITL dispatcher registry
|
|
14
|
+
(`registerContinuousSubagentInputRequestDispatcher` /
|
|
15
|
+
`unregisterContinuousSubagentInputRequestDispatcher`) is also removed —
|
|
16
|
+
subagent `input.requested` events now always forward to the parent via the
|
|
17
|
+
workflow `resumeHook` path.
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 8ca8600: fix(ash): honor `defineInstrumentation` exports when running under Nitro
|
|
22
|
+
|
|
23
|
+
Nitro evaluates the harness's instrumentation-config module twice (once via the generated plugin's `file://` URL, once via the inlined `#harness/*` alias), so a module-local store left the harness reading `undefined` even after the plugin registered a config. The config now lives on `globalThis` under a stable `Symbol.for(...)`, so telemetry actually flows when an `agent/instrumentation.ts` default export is present.
|
|
24
|
+
|
|
3
25
|
## 0.23.0
|
|
4
26
|
|
|
5
27
|
### Minor Changes
|
|
@@ -84,22 +84,19 @@ the workflow path.
|
|
|
84
84
|
|
|
85
85
|
## Dispatch
|
|
86
86
|
|
|
87
|
-
Lifecycle dispatch lives in `src/context/hook-lifecycle.ts`.
|
|
88
|
-
runtime entry
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
`getHarnessEmissionState(session).turnId === ""` so tool-loop
|
|
101
|
-
continuations and runtime-action resumes (which are continuations of
|
|
102
|
-
an existing turn) skip the lifecycle stack.
|
|
87
|
+
Lifecycle dispatch lives in `src/context/hook-lifecycle.ts`. The
|
|
88
|
+
workflow runtime entry point (`execution/workflow-steps.ts`) calls
|
|
89
|
+
`runHookLifecycleStep` once per turn, **inside** the active ALS scope
|
|
90
|
+
so hook code can read and write `ctx.ash` like every other authored
|
|
91
|
+
function. `runHookLifecycleStep` wraps `dispatchHookLifecycle`, lowers
|
|
92
|
+
a `turn-failed` outcome into a parking `StepResult` (`{ next: null }`
|
|
93
|
+
for conversation mode, `{ next: { done: true, output } }` for task
|
|
94
|
+
mode), and otherwise hands off to the supplied harness step callback
|
|
95
|
+
with the (possibly augmented) input.
|
|
96
|
+
|
|
97
|
+
Dispatch is gated on `getHarnessEmissionState(session).turnId === ""`
|
|
98
|
+
so tool-loop continuations and runtime-action resumes (which are
|
|
99
|
+
continuations of an existing turn) skip the lifecycle stack.
|
|
103
100
|
|
|
104
101
|
Stages, in order:
|
|
105
102
|
|
|
@@ -64,4 +64,4 @@ The runtime stores both `auth.current` and `auth.initiator`. Follow-up messages
|
|
|
64
64
|
|
|
65
65
|
The runtime owns stream plumbing; the channel owns delivery policy. The runtime calls `channel.onEvent(event)` for each lifecycle event — the channel may transform it or perform platform side effects. The harness emits events without knowing the transport.
|
|
66
66
|
|
|
67
|
-
Authored stream-event hooks fan out alongside `callAdapterEventHandler` from the same `HarnessEmitFn` composer (`workflow-steps.ts`
|
|
67
|
+
Authored stream-event hooks fan out alongside `callAdapterEventHandler` from the same `HarnessEmitFn` composer (`workflow-steps.ts`). Hook errors propagate through the emit composer and are caught by the existing harness error path, which emits the recoverable `turn.failed` cascade. See [Hooks](./hooks.md).
|
|
@@ -110,9 +110,9 @@ Important behavior:
|
|
|
110
110
|
- follow-up messages update `auth.current` without changing `auth.initiator`
|
|
111
111
|
- unprotected agents expose both as `null`
|
|
112
112
|
|
|
113
|
-
Auth on follow-up messages (`deliver()`) is honored by
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
Auth on follow-up messages (`deliver()`) is honored by the workflow runtime. When a different
|
|
114
|
+
user sends a follow-up to the same session, `session.auth.current` reflects the new caller on
|
|
115
|
+
that turn while `session.auth.initiator` stays the same.
|
|
116
116
|
|
|
117
117
|
## What Ash Does Not Do
|
|
118
118
|
|
|
@@ -62,8 +62,8 @@ Related exported types by subpath:
|
|
|
62
62
|
- `experimental-ash`: `RunMode`
|
|
63
63
|
- `experimental-ash/evals`: eval types
|
|
64
64
|
|
|
65
|
-
Ash also exports lower-level runtime primitives such as `createToolLoopHarness(...)
|
|
66
|
-
|
|
65
|
+
Ash also exports lower-level runtime primitives such as `createToolLoopHarness(...)`
|
|
66
|
+
and `createWorkflowRuntime(...)`.
|
|
67
67
|
|
|
68
68
|
Channel and Slack types exported from `experimental-ash/channels/slack`:
|
|
69
69
|
|
|
@@ -38,9 +38,9 @@ export interface SessionAuthContext {
|
|
|
38
38
|
/**
|
|
39
39
|
* Function provided by the runtime that writes one event to the event stream.
|
|
40
40
|
*
|
|
41
|
-
* Backed by `getWritable()` in the workflow runtime
|
|
42
|
-
*
|
|
43
|
-
*
|
|
41
|
+
* Backed by `getWritable()` in the workflow runtime. Not part of the
|
|
42
|
+
* adapter interface — the runtime always writes events to the stream
|
|
43
|
+
* itself.
|
|
44
44
|
*/
|
|
45
45
|
export type EventEmitFn = (event: HandleMessageStreamEvent) => Promise<void>;
|
|
46
46
|
/**
|
|
@@ -195,7 +195,10 @@ export interface DeliverInput {
|
|
|
195
195
|
readonly payload: DeliverPayload;
|
|
196
196
|
}
|
|
197
197
|
/**
|
|
198
|
-
* Terminal outcome of a runtime
|
|
198
|
+
* Terminal outcome of a runtime run.
|
|
199
|
+
*
|
|
200
|
+
* Terminal state on the workflow runtime is observed through the durable
|
|
201
|
+
* event stream's `session.completed` / `session.failed` events.
|
|
199
202
|
*/
|
|
200
203
|
export type RunResult = {
|
|
201
204
|
readonly status: "completed";
|
|
@@ -207,19 +210,14 @@ export type RunResult = {
|
|
|
207
210
|
* Handle returned immediately by `runtime.run()` before the step loop
|
|
208
211
|
* completes.
|
|
209
212
|
*
|
|
210
|
-
* Carries the identifiers needed for stream endpoints
|
|
211
|
-
* result as a promise.
|
|
213
|
+
* Carries the identifiers needed for stream endpoints.
|
|
212
214
|
*/
|
|
213
215
|
export interface RunHandle {
|
|
214
216
|
readonly continuationToken: string;
|
|
215
217
|
readonly events: ReadableStream<HandleMessageStreamEvent>;
|
|
216
|
-
readonly result: Promise<RunResult>;
|
|
217
218
|
/**
|
|
218
|
-
* Runtime-owned identifier for this session.
|
|
219
|
-
*
|
|
220
|
-
* Used for stream and inspection APIs. Workflow-backed runs expose
|
|
221
|
-
* the workflow run id; continuous runs mint an in-memory session id
|
|
222
|
-
* when the run starts.
|
|
219
|
+
* Runtime-owned identifier for this session. Used for stream and
|
|
220
|
+
* inspection APIs — workflow-backed runs expose the workflow run id.
|
|
223
221
|
*/
|
|
224
222
|
readonly sessionId: string;
|
|
225
223
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as e}from"./paths-YoCQlavu.js";import{t}from"./errors-DsO9xmQL.js";import{i as n}from"./package-DmsQgn4v.js";import{a as r,c as i,i as a,n as o,s,t as c}from"./prewarm-6duWvvb5.js";import{createRequire as l}from"node:module";import*as u from"node:path";import{dirname as d,isAbsolute as f,join as p,relative as m,resolve as h,sep as g}from"node:path";import{lstat as _,open as v,readFile as y,readdir as b,realpath as x,stat as S}from"node:fs/promises";import{existsSync as C,stat as w,unwatchFile as T,watch as E,watchFile as D}from"node:fs";import{EventEmitter as O}from"node:events";import{Readable as k}from"node:stream";import{type as ee}from"node:os";const A={FILE_TYPE:`files`,DIR_TYPE:`directories`,FILE_DIR_TYPE:`files_directories`,EVERYTHING_TYPE:`all`},j={root:`.`,fileFilter:e=>!0,directoryFilter:e=>!0,type:A.FILE_TYPE,lstat:!1,depth:2147483648,alwaysStat:!1,highWaterMark:4096};Object.freeze(j);const te=`READDIRP_RECURSIVE_ERROR`,ne=new Set([`ENOENT`,`EPERM`,`EACCES`,`ELOOP`,te]),re=[A.DIR_TYPE,A.EVERYTHING_TYPE,A.FILE_DIR_TYPE,A.FILE_TYPE],ie=new Set([A.DIR_TYPE,A.EVERYTHING_TYPE,A.FILE_DIR_TYPE]),ae=new Set([A.EVERYTHING_TYPE,A.FILE_DIR_TYPE,A.FILE_TYPE]),oe=e=>ne.has(e.code),se=process.platform===`win32`,M=e=>!0,N=e=>{if(e===void 0)return M;if(typeof e==`function`)return e;if(typeof e==`string`){let t=e.trim();return e=>e.basename===t}if(Array.isArray(e)){let t=e.map(e=>e.trim());return e=>t.some(t=>e.basename===t)}return M};var ce=class extends k{parents;reading;parent;_stat;_maxDepth;_wantsDir;_wantsFile;_wantsEverything;_root;_isDirent;_statsProp;_rdOptions;_fileFilter;_directoryFilter;constructor(e={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:e.highWaterMark});let t={...j,...e},{root:n,type:r}=t;this._fileFilter=N(t.fileFilter),this._directoryFilter=N(t.directoryFilter);let i=t.lstat?_:S;se?this._stat=e=>i(e,{bigint:!0}):this._stat=i,this._maxDepth=t.depth!=null&&Number.isSafeInteger(t.depth)?t.depth:j.depth,this._wantsDir=r?ie.has(r):!1,this._wantsFile=r?ae.has(r):!1,this._wantsEverything=r===A.EVERYTHING_TYPE,this._root=h(n),this._isDirent=!t.alwaysStat,this._statsProp=this._isDirent?`dirent`:`stats`,this._rdOptions={encoding:`utf8`,withFileTypes:this._isDirent},this.parents=[this._exploreDir(n,1)],this.reading=!1,this.parent=void 0}async _read(e){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&e>0;){let t=this.parent,n=t&&t.files;if(n&&n.length>0){let{path:r,depth:i}=t,a=n.splice(0,e).map(e=>this._formatEntry(e,r)),o=await Promise.all(a);for(let t of o){if(!t)continue;if(this.destroyed)return;let n=await this._getEntryType(t);n===`directory`&&this._directoryFilter(t)?(i<=this._maxDepth&&this.parents.push(this._exploreDir(t.fullPath,i+1)),this._wantsDir&&(this.push(t),e--)):(n===`file`||this._includeAsFile(t))&&this._fileFilter(t)&&this._wantsFile&&(this.push(t),e--)}}else{let e=this.parents.pop();if(!e){this.push(null);break}if(this.parent=await e,this.destroyed)return}}}catch(e){this.destroy(e)}finally{this.reading=!1}}}async _exploreDir(e,t){let n;try{n=await b(e,this._rdOptions)}catch(e){this._onError(e)}return{files:n,depth:t,path:e}}async _formatEntry(e,t){let n,r=this._isDirent?e.name:e;try{let i=h(p(t,r));n={path:m(this._root,i),fullPath:i,basename:r},n[this._statsProp]=this._isDirent?e:await this._stat(i)}catch(e){this._onError(e);return}return n}_onError(e){oe(e)&&!this.destroyed?this.emit(`warn`,e):this.destroy(e)}async _getEntryType(e){if(!e&&this._statsProp in e)return``;let t=e[this._statsProp];if(t.isFile())return`file`;if(t.isDirectory())return`directory`;if(t&&t.isSymbolicLink()){let t=e.fullPath;try{let e=await x(t),n=await _(e);if(n.isFile())return`file`;if(n.isDirectory()){let n=e.length;if(t.startsWith(e)&&t.substr(n,1)===g){let n=Error(`Circular symlink detected: "${t}" points to "${e}"`);return n.code=te,this._onError(n)}return`directory`}}catch(e){return this._onError(e),``}}}_includeAsFile(e){let t=e&&e[this._statsProp];return t&&this._wantsEverything&&!t.isDirectory()}};function le(e,t={}){let n=t.entryType||t.type;if(n===`both`&&(n=A.FILE_DIR_TYPE),n&&(t.type=n),!e)throw Error(`readdirp: root argument is required. Usage: readdirp(root, options)`);if(typeof e!=`string`)throw TypeError(`readdirp: root argument must be a string. Usage: readdirp(root, options)`);if(n&&!re.includes(n))throw Error(`readdirp: Invalid type passed. Use one of ${re.join(`, `)}`);return t.root=e,new ce(t)}const P=()=>{},F=process.platform,I=F===`win32`,ue=F===`darwin`,de=F===`linux`,fe=F===`freebsd`,pe=ee()===`OS400`,L={ALL:`all`,READY:`ready`,ADD:`add`,CHANGE:`change`,ADD_DIR:`addDir`,UNLINK:`unlink`,UNLINK_DIR:`unlinkDir`,RAW:`raw`,ERROR:`error`},R=L,me={lstat:_,stat:S},z=`listeners`,B=`errHandlers`,V=`rawEmitters`,he=[z,B,V],ge=new Set(`3dm.3ds.3g2.3gp.7z.a.aac.adp.afdesign.afphoto.afpub.ai.aif.aiff.alz.ape.apk.appimage.ar.arj.asf.au.avi.bak.baml.bh.bin.bk.bmp.btif.bz2.bzip2.cab.caf.cgm.class.cmx.cpio.cr2.cur.dat.dcm.deb.dex.djvu.dll.dmg.dng.doc.docm.docx.dot.dotm.dra.DS_Store.dsk.dts.dtshd.dvb.dwg.dxf.ecelp4800.ecelp7470.ecelp9600.egg.eol.eot.epub.exe.f4v.fbs.fh.fla.flac.flatpak.fli.flv.fpx.fst.fvt.g3.gh.gif.graffle.gz.gzip.h261.h263.h264.icns.ico.ief.img.ipa.iso.jar.jpeg.jpg.jpgv.jpm.jxr.key.ktx.lha.lib.lvp.lz.lzh.lzma.lzo.m3u.m4a.m4v.mar.mdi.mht.mid.midi.mj2.mka.mkv.mmr.mng.mobi.mov.movie.mp3.mp4.mp4a.mpeg.mpg.mpga.mxu.nef.npx.numbers.nupkg.o.odp.ods.odt.oga.ogg.ogv.otf.ott.pages.pbm.pcx.pdb.pdf.pea.pgm.pic.png.pnm.pot.potm.potx.ppa.ppam.ppm.pps.ppsm.ppsx.ppt.pptm.pptx.psd.pya.pyc.pyo.pyv.qt.rar.ras.raw.resources.rgb.rip.rlc.rmf.rmvb.rpm.rtf.rz.s3m.s7z.scpt.sgi.shar.snap.sil.sketch.slk.smv.snk.so.stl.suo.sub.swf.tar.tbz.tbz2.tga.tgz.thmx.tif.tiff.tlz.ttc.ttf.txz.udf.uvh.uvi.uvm.uvp.uvs.uvu.viv.vob.war.wav.wax.wbmp.wdp.weba.webm.webp.whl.wim.wm.wma.wmv.wmx.woff.woff2.wrm.wvx.xbm.xif.xla.xlam.xls.xlsb.xlsm.xlsx.xlt.xltm.xltx.xm.xmind.xpi.xpm.xwd.xz.z.zip.zipx`.split(`.`)),_e=e=>ge.has(u.extname(e).slice(1).toLowerCase()),H=(e,t)=>{e instanceof Set?e.forEach(t):t(e)},U=(e,t,n)=>{let r=e[t];r instanceof Set||(e[t]=r=new Set([r])),r.add(n)},ve=e=>t=>{let n=e[t];n instanceof Set?n.clear():delete e[t]},W=(e,t,n)=>{let r=e[t];r instanceof Set?r.delete(n):r===n&&delete e[t]},ye=e=>e instanceof Set?e.size===0:!e,G=new Map;function be(e,t,n,r,i){let a=(t,r)=>{n(e),i(t,r,{watchedPath:e}),r&&e!==r&&K(u.resolve(e,r),z,u.join(e,r))};try{return E(e,{persistent:t.persistent},a)}catch(e){r(e);return}}const K=(e,t,n,r,i)=>{let a=G.get(e);a&&H(a[t],e=>{e(n,r,i)})},xe=(e,t,n,r)=>{let{listener:i,errHandler:a,rawEmitter:o}=r,s=G.get(t),c;if(!n.persistent)return c=be(e,n,i,a,o),c?c.close.bind(c):void 0;if(s)U(s,z,i),U(s,B,a),U(s,V,o);else{if(c=be(e,n,K.bind(null,t,z),a,K.bind(null,t,V)),!c)return;c.on(R.ERROR,async n=>{let r=K.bind(null,t,B);if(s&&(s.watcherUnusable=!0),I&&n.code===`EPERM`)try{await(await v(e,`r`)).close(),r(n)}catch{}else r(n)}),s={listeners:i,errHandlers:a,rawEmitters:o,watcher:c},G.set(t,s)}return()=>{W(s,z,i),W(s,B,a),W(s,V,o),ye(s.listeners)&&(s.watcher.close(),G.delete(t),he.forEach(ve(s)),s.watcher=void 0,Object.freeze(s))}},q=new Map,Se=(e,t,n,r)=>{let{listener:i,rawEmitter:a}=r,o=q.get(t),s=o&&o.options;return s&&(s.persistent<n.persistent||s.interval>n.interval)&&(T(t),o=void 0),o?(U(o,z,i),U(o,V,a)):(o={listeners:i,rawEmitters:a,options:n,watcher:D(t,n,(n,r)=>{H(o.rawEmitters,e=>{e(R.CHANGE,t,{curr:n,prev:r})});let i=n.mtimeMs;(n.size!==r.size||i>r.mtimeMs||i===0)&&H(o.listeners,t=>t(e,n))})},q.set(t,o)),()=>{W(o,z,i),W(o,V,a),ye(o.listeners)&&(q.delete(t),T(t),o.options=o.watcher=void 0,Object.freeze(o))}};var Ce=class{fsw;_boundHandleError;constructor(e){this.fsw=e,this._boundHandleError=t=>e._handleError(t)}_watchWithNodeFs(e,t){let n=this.fsw.options,r=u.dirname(e),i=u.basename(e);this.fsw._getWatchedDir(r).add(i);let a=u.resolve(e),o={persistent:n.persistent};t||=P;let s;return n.usePolling?(o.interval=n.interval!==n.binaryInterval&&_e(i)?n.binaryInterval:n.interval,s=Se(e,a,o,{listener:t,rawEmitter:this.fsw._emitRaw})):s=xe(e,a,o,{listener:t,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw}),s}_handleFile(e,t,n){if(this.fsw.closed)return;let r=u.dirname(e),i=u.basename(e),a=this.fsw._getWatchedDir(r),o=t;if(a.has(i))return;let s=async(t,n)=>{if(this.fsw._throttle(`watch`,e,5)){if(!n||n.mtimeMs===0)try{let n=await S(e);if(this.fsw.closed)return;let r=n.atimeMs,i=n.mtimeMs;if((!r||r<=i||i!==o.mtimeMs)&&this.fsw._emit(R.CHANGE,e,n),(ue||de||fe)&&o.ino!==n.ino){this.fsw._closeFile(t),o=n;let r=this._watchWithNodeFs(e,s);r&&this.fsw._addPathCloser(t,r)}else o=n}catch{this.fsw._remove(r,i)}else if(a.has(i)){let t=n.atimeMs,r=n.mtimeMs;(!t||t<=r||r!==o.mtimeMs)&&this.fsw._emit(R.CHANGE,e,n),o=n}}},c=this._watchWithNodeFs(e,s);if(!(n&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(e)){if(!this.fsw._throttle(R.ADD,e,0))return;this.fsw._emit(R.ADD,e,t)}return c}async _handleSymlink(e,t,n,r){if(this.fsw.closed)return;let i=e.fullPath,a=this.fsw._getWatchedDir(t);if(!this.fsw.options.followSymlinks){this.fsw._incrReadyCount();let t;try{t=await x(n)}catch{return this.fsw._emitReady(),!0}return this.fsw.closed?void 0:(a.has(r)?this.fsw._symlinkPaths.get(i)!==t&&(this.fsw._symlinkPaths.set(i,t),this.fsw._emit(R.CHANGE,n,e.stats)):(a.add(r),this.fsw._symlinkPaths.set(i,t),this.fsw._emit(R.ADD,n,e.stats)),this.fsw._emitReady(),!0)}if(this.fsw._symlinkPaths.has(i))return!0;this.fsw._symlinkPaths.set(i,!0)}_handleRead(e,t,n,r,i,a,o){e=u.join(e,``);let s=r?`${e}:${r}`:e;if(o=this.fsw._throttle(`readdir`,s,1e3),!o)return;let c=this.fsw._getWatchedDir(n.path),l=new Set,d=this.fsw._readdirp(e,{fileFilter:e=>n.filterPath(e),directoryFilter:e=>n.filterDir(e)});if(d)return d.on(`data`,async o=>{if(this.fsw.closed){d=void 0;return}let s=o.path,f=u.join(e,s);if(l.add(s),!(o.stats.isSymbolicLink()&&await this._handleSymlink(o,e,f,s))){if(this.fsw.closed){d=void 0;return}(s===r||!r&&!c.has(s))&&(this.fsw._incrReadyCount(),f=u.join(i,u.relative(i,f)),this._addToNodeFs(f,t,n,a+1))}}).on(R.ERROR,this._boundHandleError),new Promise((t,s)=>{if(!d)return s();d.once(`end`,()=>{if(this.fsw.closed){d=void 0;return}let s=o?o.clear():!1;t(void 0),c.getChildren().filter(t=>t!==e&&!l.has(t)).forEach(t=>{this.fsw._remove(e,t)}),d=void 0,s&&this._handleRead(e,!1,n,r,i,a,o)})})}async _handleDir(e,t,n,r,i,a,o){let s=this.fsw._getWatchedDir(u.dirname(e)),c=s.has(u.basename(e));!(n&&this.fsw.options.ignoreInitial)&&!i&&!c&&this.fsw._emit(R.ADD_DIR,e,t),s.add(u.basename(e)),this.fsw._getWatchedDir(e);let l,d=this.fsw.options.depth;if((d==null||r<=d)&&!this.fsw._symlinkPaths.has(o)){if(!i&&(await this._handleRead(e,n,a,i,e,r,void 0),this.fsw.closed))return;l=this._watchWithNodeFs(e,(t,n)=>{n&&n.mtimeMs===0||this._handleRead(t,!1,a,i,e,r,void 0)})}return l}async _addToNodeFs(e,t,n,r,i){let a=this.fsw._emitReady;if(this.fsw._isIgnored(e)||this.fsw.closed)return a(),!1;let o=this.fsw._getWatchHelpers(e);n&&(o.filterPath=e=>n.filterPath(e),o.filterDir=e=>n.filterDir(e));try{let n=await me[o.statMethod](o.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(o.watchPath,n))return a(),!1;let s=this.fsw.options.followSymlinks,c;if(n.isDirectory()){let a=u.resolve(e),l=s?await x(e):e;if(this.fsw.closed||(c=await this._handleDir(o.watchPath,n,t,r,i,o,l),this.fsw.closed))return;a!==l&&l!==void 0&&this.fsw._symlinkPaths.set(a,l)}else if(n.isSymbolicLink()){let i=s?await x(e):e;if(this.fsw.closed)return;let a=u.dirname(o.watchPath);if(this.fsw._getWatchedDir(a).add(o.watchPath),this.fsw._emit(R.ADD,o.watchPath,n),c=await this._handleDir(a,n,t,r,e,o,i),this.fsw.closed)return;i!==void 0&&this.fsw._symlinkPaths.set(u.resolve(e),i)}else c=this._handleFile(o.watchPath,n,t);return a(),c&&this.fsw._addPathCloser(e,c),!1}catch(t){if(this.fsw._handleError(t))return a(),e}}};const we=/\\/g,Te=/\/\//g,Ee=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,De=/^\.[/\\]/;function J(e){return Array.isArray(e)?e:[e]}const Y=e=>typeof e==`object`&&!!e&&!(e instanceof RegExp);function Oe(e){return typeof e==`function`?e:typeof e==`string`?t=>e===t:e instanceof RegExp?t=>e.test(t):typeof e==`object`&&e?t=>{if(e.path===t)return!0;if(e.recursive){let n=u.relative(e.path,t);return n?!n.startsWith(`..`)&&!u.isAbsolute(n):!1}return!1}:()=>!1}function ke(e){if(typeof e!=`string`)throw Error(`string expected`);e=u.normalize(e),e=e.replace(/\\/g,`/`);let t=!1;return e.startsWith(`//`)&&(t=!0),e=e.replace(Te,`/`),t&&(e=`/`+e),e}function Ae(e,t,n){let r=ke(t);for(let t=0;t<e.length;t++){let i=e[t];if(i(r,n))return!0}return!1}function je(e,t){if(e==null)throw TypeError(`anymatch: specify first argument`);let n=J(e).map(e=>Oe(e));return t==null?(e,t)=>Ae(n,e,t):Ae(n,t)}const Me=e=>{let t=J(e).flat();if(!t.every(e=>typeof e==`string`))throw TypeError(`Non-string provided as watch path: ${t}`);return t.map(Pe)},Ne=e=>{let t=e.replace(we,`/`),n=!1;return t.startsWith(`//`)&&(n=!0),t=t.replace(Te,`/`),n&&(t=`/`+t),t},Pe=e=>Ne(u.normalize(Ne(e))),Fe=(e=``)=>t=>typeof t==`string`?Pe(u.isAbsolute(t)?t:u.join(e,t)):t,Ie=(e,t)=>u.isAbsolute(e)?e:u.join(t,e),Le=Object.freeze(new Set);var Re=class{path;_removeWatcher;items;constructor(e,t){this.path=e,this._removeWatcher=t,this.items=new Set}add(e){let{items:t}=this;t&&e!==`.`&&e!==`..`&&t.add(e)}async remove(e){let{items:t}=this;if(!t||(t.delete(e),t.size>0))return;let n=this.path;try{await b(n)}catch{this._removeWatcher&&this._removeWatcher(u.dirname(n),u.basename(n))}}has(e){let{items:t}=this;if(t)return t.has(e)}getChildren(){let{items:e}=this;return e?[...e.values()]:[]}dispose(){this.items.clear(),this.path=``,this._removeWatcher=P,this.items=Le,Object.freeze(this)}},ze=class{fsw;path;watchPath;fullWatchPath;dirParts;followSymlinks;statMethod;constructor(e,t,n){this.fsw=n;let r=e;this.path=e=e.replace(De,``),this.watchPath=r,this.fullWatchPath=u.resolve(r),this.dirParts=[],this.dirParts.forEach(e=>{e.length>1&&e.pop()}),this.followSymlinks=t,this.statMethod=t?`stat`:`lstat`}entryPath(e){return u.join(this.watchPath,u.relative(this.watchPath,e.fullPath))}filterPath(e){let{stats:t}=e;if(t&&t.isSymbolicLink())return this.filterDir(e);let n=this.entryPath(e);return this.fsw._isntIgnored(n,t)&&this.fsw._hasReadPermissions(t)}filterDir(e){return this.fsw._isntIgnored(this.entryPath(e),e.stats)}},Be=class extends O{closed;options;_closers;_ignoredPaths;_throttled;_streams;_symlinkPaths;_watched;_pendingWrites;_pendingUnlinks;_readyCount;_emitReady;_closePromise;_userIgnored;_readyEmitted;_emitRaw;_boundRemove;_nodeFsHandler;constructor(e={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;let t=e.awaitWriteFinish,n={stabilityThreshold:2e3,pollInterval:100},r={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...e,ignored:e.ignored?J(e.ignored):J([]),awaitWriteFinish:t===!0?n:typeof t==`object`?{...n,...t}:!1};pe&&(r.usePolling=!0),r.atomic===void 0&&(r.atomic=!r.usePolling);let i=process.env.CHOKIDAR_USEPOLLING;if(i!==void 0){let e=i.toLowerCase();e===`false`||e===`0`?r.usePolling=!1:e===`true`||e===`1`?r.usePolling=!0:r.usePolling=!!e}let a=process.env.CHOKIDAR_INTERVAL;a&&(r.interval=Number.parseInt(a,10));let o=0;this._emitReady=()=>{o++,o>=this._readyCount&&(this._emitReady=P,this._readyEmitted=!0,process.nextTick(()=>this.emit(L.READY)))},this._emitRaw=(...e)=>this.emit(L.RAW,...e),this._boundRemove=this._remove.bind(this),this.options=r,this._nodeFsHandler=new Ce(this),Object.freeze(r)}_addIgnoredPath(e){if(Y(e)){for(let t of this._ignoredPaths)if(Y(t)&&t.path===e.path&&t.recursive===e.recursive)return}this._ignoredPaths.add(e)}_removeIgnoredPath(e){if(this._ignoredPaths.delete(e),typeof e==`string`)for(let t of this._ignoredPaths)Y(t)&&t.path===e&&this._ignoredPaths.delete(t)}add(e,t,n){let{cwd:r}=this.options;this.closed=!1,this._closePromise=void 0;let i=Me(e);return r&&(i=i.map(e=>Ie(e,r))),i.forEach(e=>{this._removeIgnoredPath(e)}),this._userIgnored=void 0,this._readyCount||=0,this._readyCount+=i.length,Promise.all(i.map(async e=>{let r=await this._nodeFsHandler._addToNodeFs(e,!n,void 0,0,t);return r&&this._emitReady(),r})).then(e=>{this.closed||e.forEach(e=>{e&&this.add(u.dirname(e),u.basename(t||e))})}),this}unwatch(e){if(this.closed)return this;let t=Me(e),{cwd:n}=this.options;return t.forEach(e=>{!u.isAbsolute(e)&&!this._closers.has(e)&&(n&&(e=u.join(n,e)),e=u.resolve(e)),this._closePath(e),this._addIgnoredPath(e),this._watched.has(e)&&this._addIgnoredPath({path:e,recursive:!0}),this._userIgnored=void 0}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let e=[];return this._closers.forEach(t=>t.forEach(t=>{let n=t();n instanceof Promise&&e.push(n)})),this._streams.forEach(e=>e.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(e=>e.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=e.length?Promise.all(e).then(()=>void 0):Promise.resolve(),this._closePromise}getWatched(){let e={};return this._watched.forEach((t,n)=>{let r=(this.options.cwd?u.relative(this.options.cwd,n):n)||`.`;e[r]=t.getChildren().sort()}),e}emitWithAll(e,t){this.emit(e,...t),e!==L.ERROR&&this.emit(L.ALL,e,...t)}async _emit(e,t,n){if(this.closed)return;let r=this.options;I&&(t=u.normalize(t)),r.cwd&&(t=u.relative(r.cwd,t));let i=[t];n!=null&&i.push(n);let a=r.awaitWriteFinish,o;if(a&&(o=this._pendingWrites.get(t)))return o.lastChange=new Date,this;if(r.atomic){if(e===L.UNLINK)return this._pendingUnlinks.set(t,[e,...i]),setTimeout(()=>{this._pendingUnlinks.forEach((e,t)=>{this.emit(...e),this.emit(L.ALL,...e),this._pendingUnlinks.delete(t)})},typeof r.atomic==`number`?r.atomic:100),this;e===L.ADD&&this._pendingUnlinks.has(t)&&(e=L.CHANGE,this._pendingUnlinks.delete(t))}if(a&&(e===L.ADD||e===L.CHANGE)&&this._readyEmitted)return this._awaitWriteFinish(t,a.stabilityThreshold,e,(t,n)=>{t?(e=L.ERROR,i[0]=t,this.emitWithAll(e,i)):n&&(i.length>1?i[1]=n:i.push(n),this.emitWithAll(e,i))}),this;if(e===L.CHANGE&&!this._throttle(L.CHANGE,t,50))return this;if(r.alwaysStat&&n===void 0&&(e===L.ADD||e===L.ADD_DIR||e===L.CHANGE)){let e=r.cwd?u.join(r.cwd,t):t,n;try{n=await S(e)}catch{}if(!n||this.closed)return;i.push(n)}return this.emitWithAll(e,i),this}_handleError(e){let t=e&&e.code;return e&&t!==`ENOENT`&&t!==`ENOTDIR`&&(!this.options.ignorePermissionErrors||t!==`EPERM`&&t!==`EACCES`)&&this.emit(L.ERROR,e),e||this.closed}_throttle(e,t,n){this._throttled.has(e)||this._throttled.set(e,new Map);let r=this._throttled.get(e);if(!r)throw Error(`invalid throttle`);let i=r.get(t);if(i)return i.count++,!1;let a,o=()=>{let e=r.get(t),n=e?e.count:0;return r.delete(t),clearTimeout(a),e&&clearTimeout(e.timeoutObject),n};a=setTimeout(o,n);let s={timeoutObject:a,clear:o,count:0};return r.set(t,s),s}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(e,t,n,r){let i=this.options.awaitWriteFinish;if(typeof i!=`object`)return;let a=i.pollInterval,o,s=e;this.options.cwd&&!u.isAbsolute(e)&&(s=u.join(this.options.cwd,e));let c=new Date,l=this._pendingWrites;function d(n){w(s,(i,s)=>{if(i||!l.has(e)){i&&i.code!==`ENOENT`&&r(i);return}let c=Number(new Date);n&&s.size!==n.size&&(l.get(e).lastChange=c),c-l.get(e).lastChange>=t?(l.delete(e),r(void 0,s)):o=setTimeout(d,a,s)})}l.has(e)||(l.set(e,{lastChange:c,cancelWait:()=>(l.delete(e),clearTimeout(o),n)}),o=setTimeout(d,a))}_isIgnored(e,t){if(this.options.atomic&&Ee.test(e))return!0;if(!this._userIgnored){let{cwd:e}=this.options,t=(this.options.ignored||[]).map(Fe(e)),n=[...[...this._ignoredPaths].map(Fe(e)),...t];this._userIgnored=je(n,void 0)}return this._userIgnored(e,t)}_isntIgnored(e,t){return!this._isIgnored(e,t)}_getWatchHelpers(e){return new ze(e,this.options.followSymlinks,this)}_getWatchedDir(e){let t=u.resolve(e);return this._watched.has(t)||this._watched.set(t,new Re(t,this._boundRemove)),this._watched.get(t)}_hasReadPermissions(e){return this.options.ignorePermissionErrors?!0:!!(Number(e.mode)&256)}_remove(e,t,n){let r=u.join(e,t),i=u.resolve(r);if(n??=this._watched.has(r)||this._watched.has(i),!this._throttle(`remove`,r,100))return;!n&&this._watched.size===1&&this.add(e,t,!0),this._getWatchedDir(r).getChildren().forEach(e=>this._remove(r,e));let a=this._getWatchedDir(e),o=a.has(t);a.remove(t),this._symlinkPaths.has(i)&&this._symlinkPaths.delete(i);let s=r;if(this.options.cwd&&(s=u.relative(this.options.cwd,r)),this.options.awaitWriteFinish&&this._pendingWrites.has(s)&&this._pendingWrites.get(s).cancelWait()===L.ADD)return;this._watched.delete(r),this._watched.delete(i);let c=n?L.UNLINK_DIR:L.UNLINK;o&&!this._isIgnored(r)&&this._emit(c,r),this._closePath(r)}_closePath(e){this._closeFile(e);let t=u.dirname(e);this._getWatchedDir(t).remove(u.basename(e))}_closeFile(e){let t=this._closers.get(e);t&&(t.forEach(e=>e()),this._closers.delete(e))}_addPathCloser(e,t){if(!t)return;let n=this._closers.get(e);n||(n=[],this._closers.set(e,n)),n.push(t)}_readdirp(e,t){if(this.closed)return;let n=le(e,{type:L.ALL,alwaysStat:!0,lstat:!0,...t,depth:0});return this._streams.add(n),n.once(`close`,()=>{n=void 0}),n.once(`end`,()=>{n&&=(this._streams.delete(n),void 0)}),n}};function Ve(e,t={}){let n=new Be(t);return n.add(e),n}function He(e,t=!1){let n=e.length,r=0,i=``,a=0,o=16,s=0,c=0,l=0,u=0,d=0;function f(t,n){let i=0,a=0;for(;i<t||!n;){let t=e.charCodeAt(r);if(t>=48&&t<=57)a=a*16+t-48;else if(t>=65&&t<=70)a=a*16+t-65+10;else if(t>=97&&t<=102)a=a*16+t-97+10;else break;r++,i++}return i<t&&(a=-1),a}function p(e){r=e,i=``,a=0,o=16,d=0}function m(){let t=r;if(e.charCodeAt(r)===48)r++;else for(r++;r<e.length&&Q(e.charCodeAt(r));)r++;if(r<e.length&&e.charCodeAt(r)===46)if(r++,r<e.length&&Q(e.charCodeAt(r)))for(r++;r<e.length&&Q(e.charCodeAt(r));)r++;else return d=3,e.substring(t,r);let n=r;if(r<e.length&&(e.charCodeAt(r)===69||e.charCodeAt(r)===101))if(r++,(r<e.length&&e.charCodeAt(r)===43||e.charCodeAt(r)===45)&&r++,r<e.length&&Q(e.charCodeAt(r))){for(r++;r<e.length&&Q(e.charCodeAt(r));)r++;n=r}else d=3;return e.substring(t,n)}function h(){let t=``,i=r;for(;;){if(r>=n){t+=e.substring(i,r),d=2;break}let a=e.charCodeAt(r);if(a===34){t+=e.substring(i,r),r++;break}if(a===92){if(t+=e.substring(i,r),r++,r>=n){d=2;break}switch(e.charCodeAt(r++)){case 34:t+=`"`;break;case 92:t+=`\\`;break;case 47:t+=`/`;break;case 98:t+=`\b`;break;case 102:t+=`\f`;break;case 110:t+=`
|
|
1
|
+
import{s as e}from"./paths-OknjaYR8.js";import{t}from"./errors-DsO9xmQL.js";import{i as n}from"./package-DmsQgn4v.js";import{a as r,c as i,i as a,n as o,s,t as c}from"./prewarm-B4YblQ5m.js";import{createRequire as l}from"node:module";import*as u from"node:path";import{dirname as d,isAbsolute as f,join as p,relative as m,resolve as h,sep as g}from"node:path";import{lstat as _,open as v,readFile as y,readdir as b,realpath as x,stat as S}from"node:fs/promises";import{existsSync as C,stat as w,unwatchFile as T,watch as E,watchFile as D}from"node:fs";import{EventEmitter as O}from"node:events";import{Readable as k}from"node:stream";import{type as ee}from"node:os";const A={FILE_TYPE:`files`,DIR_TYPE:`directories`,FILE_DIR_TYPE:`files_directories`,EVERYTHING_TYPE:`all`},j={root:`.`,fileFilter:e=>!0,directoryFilter:e=>!0,type:A.FILE_TYPE,lstat:!1,depth:2147483648,alwaysStat:!1,highWaterMark:4096};Object.freeze(j);const te=`READDIRP_RECURSIVE_ERROR`,ne=new Set([`ENOENT`,`EPERM`,`EACCES`,`ELOOP`,te]),re=[A.DIR_TYPE,A.EVERYTHING_TYPE,A.FILE_DIR_TYPE,A.FILE_TYPE],ie=new Set([A.DIR_TYPE,A.EVERYTHING_TYPE,A.FILE_DIR_TYPE]),ae=new Set([A.EVERYTHING_TYPE,A.FILE_DIR_TYPE,A.FILE_TYPE]),oe=e=>ne.has(e.code),se=process.platform===`win32`,M=e=>!0,N=e=>{if(e===void 0)return M;if(typeof e==`function`)return e;if(typeof e==`string`){let t=e.trim();return e=>e.basename===t}if(Array.isArray(e)){let t=e.map(e=>e.trim());return e=>t.some(t=>e.basename===t)}return M};var ce=class extends k{parents;reading;parent;_stat;_maxDepth;_wantsDir;_wantsFile;_wantsEverything;_root;_isDirent;_statsProp;_rdOptions;_fileFilter;_directoryFilter;constructor(e={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:e.highWaterMark});let t={...j,...e},{root:n,type:r}=t;this._fileFilter=N(t.fileFilter),this._directoryFilter=N(t.directoryFilter);let i=t.lstat?_:S;se?this._stat=e=>i(e,{bigint:!0}):this._stat=i,this._maxDepth=t.depth!=null&&Number.isSafeInteger(t.depth)?t.depth:j.depth,this._wantsDir=r?ie.has(r):!1,this._wantsFile=r?ae.has(r):!1,this._wantsEverything=r===A.EVERYTHING_TYPE,this._root=h(n),this._isDirent=!t.alwaysStat,this._statsProp=this._isDirent?`dirent`:`stats`,this._rdOptions={encoding:`utf8`,withFileTypes:this._isDirent},this.parents=[this._exploreDir(n,1)],this.reading=!1,this.parent=void 0}async _read(e){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&e>0;){let t=this.parent,n=t&&t.files;if(n&&n.length>0){let{path:r,depth:i}=t,a=n.splice(0,e).map(e=>this._formatEntry(e,r)),o=await Promise.all(a);for(let t of o){if(!t)continue;if(this.destroyed)return;let n=await this._getEntryType(t);n===`directory`&&this._directoryFilter(t)?(i<=this._maxDepth&&this.parents.push(this._exploreDir(t.fullPath,i+1)),this._wantsDir&&(this.push(t),e--)):(n===`file`||this._includeAsFile(t))&&this._fileFilter(t)&&this._wantsFile&&(this.push(t),e--)}}else{let e=this.parents.pop();if(!e){this.push(null);break}if(this.parent=await e,this.destroyed)return}}}catch(e){this.destroy(e)}finally{this.reading=!1}}}async _exploreDir(e,t){let n;try{n=await b(e,this._rdOptions)}catch(e){this._onError(e)}return{files:n,depth:t,path:e}}async _formatEntry(e,t){let n,r=this._isDirent?e.name:e;try{let i=h(p(t,r));n={path:m(this._root,i),fullPath:i,basename:r},n[this._statsProp]=this._isDirent?e:await this._stat(i)}catch(e){this._onError(e);return}return n}_onError(e){oe(e)&&!this.destroyed?this.emit(`warn`,e):this.destroy(e)}async _getEntryType(e){if(!e&&this._statsProp in e)return``;let t=e[this._statsProp];if(t.isFile())return`file`;if(t.isDirectory())return`directory`;if(t&&t.isSymbolicLink()){let t=e.fullPath;try{let e=await x(t),n=await _(e);if(n.isFile())return`file`;if(n.isDirectory()){let n=e.length;if(t.startsWith(e)&&t.substr(n,1)===g){let n=Error(`Circular symlink detected: "${t}" points to "${e}"`);return n.code=te,this._onError(n)}return`directory`}}catch(e){return this._onError(e),``}}}_includeAsFile(e){let t=e&&e[this._statsProp];return t&&this._wantsEverything&&!t.isDirectory()}};function le(e,t={}){let n=t.entryType||t.type;if(n===`both`&&(n=A.FILE_DIR_TYPE),n&&(t.type=n),!e)throw Error(`readdirp: root argument is required. Usage: readdirp(root, options)`);if(typeof e!=`string`)throw TypeError(`readdirp: root argument must be a string. Usage: readdirp(root, options)`);if(n&&!re.includes(n))throw Error(`readdirp: Invalid type passed. Use one of ${re.join(`, `)}`);return t.root=e,new ce(t)}const P=()=>{},F=process.platform,I=F===`win32`,ue=F===`darwin`,de=F===`linux`,fe=F===`freebsd`,pe=ee()===`OS400`,L={ALL:`all`,READY:`ready`,ADD:`add`,CHANGE:`change`,ADD_DIR:`addDir`,UNLINK:`unlink`,UNLINK_DIR:`unlinkDir`,RAW:`raw`,ERROR:`error`},R=L,me={lstat:_,stat:S},z=`listeners`,B=`errHandlers`,V=`rawEmitters`,he=[z,B,V],ge=new Set(`3dm.3ds.3g2.3gp.7z.a.aac.adp.afdesign.afphoto.afpub.ai.aif.aiff.alz.ape.apk.appimage.ar.arj.asf.au.avi.bak.baml.bh.bin.bk.bmp.btif.bz2.bzip2.cab.caf.cgm.class.cmx.cpio.cr2.cur.dat.dcm.deb.dex.djvu.dll.dmg.dng.doc.docm.docx.dot.dotm.dra.DS_Store.dsk.dts.dtshd.dvb.dwg.dxf.ecelp4800.ecelp7470.ecelp9600.egg.eol.eot.epub.exe.f4v.fbs.fh.fla.flac.flatpak.fli.flv.fpx.fst.fvt.g3.gh.gif.graffle.gz.gzip.h261.h263.h264.icns.ico.ief.img.ipa.iso.jar.jpeg.jpg.jpgv.jpm.jxr.key.ktx.lha.lib.lvp.lz.lzh.lzma.lzo.m3u.m4a.m4v.mar.mdi.mht.mid.midi.mj2.mka.mkv.mmr.mng.mobi.mov.movie.mp3.mp4.mp4a.mpeg.mpg.mpga.mxu.nef.npx.numbers.nupkg.o.odp.ods.odt.oga.ogg.ogv.otf.ott.pages.pbm.pcx.pdb.pdf.pea.pgm.pic.png.pnm.pot.potm.potx.ppa.ppam.ppm.pps.ppsm.ppsx.ppt.pptm.pptx.psd.pya.pyc.pyo.pyv.qt.rar.ras.raw.resources.rgb.rip.rlc.rmf.rmvb.rpm.rtf.rz.s3m.s7z.scpt.sgi.shar.snap.sil.sketch.slk.smv.snk.so.stl.suo.sub.swf.tar.tbz.tbz2.tga.tgz.thmx.tif.tiff.tlz.ttc.ttf.txz.udf.uvh.uvi.uvm.uvp.uvs.uvu.viv.vob.war.wav.wax.wbmp.wdp.weba.webm.webp.whl.wim.wm.wma.wmv.wmx.woff.woff2.wrm.wvx.xbm.xif.xla.xlam.xls.xlsb.xlsm.xlsx.xlt.xltm.xltx.xm.xmind.xpi.xpm.xwd.xz.z.zip.zipx`.split(`.`)),_e=e=>ge.has(u.extname(e).slice(1).toLowerCase()),H=(e,t)=>{e instanceof Set?e.forEach(t):t(e)},U=(e,t,n)=>{let r=e[t];r instanceof Set||(e[t]=r=new Set([r])),r.add(n)},ve=e=>t=>{let n=e[t];n instanceof Set?n.clear():delete e[t]},W=(e,t,n)=>{let r=e[t];r instanceof Set?r.delete(n):r===n&&delete e[t]},ye=e=>e instanceof Set?e.size===0:!e,G=new Map;function be(e,t,n,r,i){let a=(t,r)=>{n(e),i(t,r,{watchedPath:e}),r&&e!==r&&K(u.resolve(e,r),z,u.join(e,r))};try{return E(e,{persistent:t.persistent},a)}catch(e){r(e);return}}const K=(e,t,n,r,i)=>{let a=G.get(e);a&&H(a[t],e=>{e(n,r,i)})},xe=(e,t,n,r)=>{let{listener:i,errHandler:a,rawEmitter:o}=r,s=G.get(t),c;if(!n.persistent)return c=be(e,n,i,a,o),c?c.close.bind(c):void 0;if(s)U(s,z,i),U(s,B,a),U(s,V,o);else{if(c=be(e,n,K.bind(null,t,z),a,K.bind(null,t,V)),!c)return;c.on(R.ERROR,async n=>{let r=K.bind(null,t,B);if(s&&(s.watcherUnusable=!0),I&&n.code===`EPERM`)try{await(await v(e,`r`)).close(),r(n)}catch{}else r(n)}),s={listeners:i,errHandlers:a,rawEmitters:o,watcher:c},G.set(t,s)}return()=>{W(s,z,i),W(s,B,a),W(s,V,o),ye(s.listeners)&&(s.watcher.close(),G.delete(t),he.forEach(ve(s)),s.watcher=void 0,Object.freeze(s))}},q=new Map,Se=(e,t,n,r)=>{let{listener:i,rawEmitter:a}=r,o=q.get(t),s=o&&o.options;return s&&(s.persistent<n.persistent||s.interval>n.interval)&&(T(t),o=void 0),o?(U(o,z,i),U(o,V,a)):(o={listeners:i,rawEmitters:a,options:n,watcher:D(t,n,(n,r)=>{H(o.rawEmitters,e=>{e(R.CHANGE,t,{curr:n,prev:r})});let i=n.mtimeMs;(n.size!==r.size||i>r.mtimeMs||i===0)&&H(o.listeners,t=>t(e,n))})},q.set(t,o)),()=>{W(o,z,i),W(o,V,a),ye(o.listeners)&&(q.delete(t),T(t),o.options=o.watcher=void 0,Object.freeze(o))}};var Ce=class{fsw;_boundHandleError;constructor(e){this.fsw=e,this._boundHandleError=t=>e._handleError(t)}_watchWithNodeFs(e,t){let n=this.fsw.options,r=u.dirname(e),i=u.basename(e);this.fsw._getWatchedDir(r).add(i);let a=u.resolve(e),o={persistent:n.persistent};t||=P;let s;return n.usePolling?(o.interval=n.interval!==n.binaryInterval&&_e(i)?n.binaryInterval:n.interval,s=Se(e,a,o,{listener:t,rawEmitter:this.fsw._emitRaw})):s=xe(e,a,o,{listener:t,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw}),s}_handleFile(e,t,n){if(this.fsw.closed)return;let r=u.dirname(e),i=u.basename(e),a=this.fsw._getWatchedDir(r),o=t;if(a.has(i))return;let s=async(t,n)=>{if(this.fsw._throttle(`watch`,e,5)){if(!n||n.mtimeMs===0)try{let n=await S(e);if(this.fsw.closed)return;let r=n.atimeMs,i=n.mtimeMs;if((!r||r<=i||i!==o.mtimeMs)&&this.fsw._emit(R.CHANGE,e,n),(ue||de||fe)&&o.ino!==n.ino){this.fsw._closeFile(t),o=n;let r=this._watchWithNodeFs(e,s);r&&this.fsw._addPathCloser(t,r)}else o=n}catch{this.fsw._remove(r,i)}else if(a.has(i)){let t=n.atimeMs,r=n.mtimeMs;(!t||t<=r||r!==o.mtimeMs)&&this.fsw._emit(R.CHANGE,e,n),o=n}}},c=this._watchWithNodeFs(e,s);if(!(n&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(e)){if(!this.fsw._throttle(R.ADD,e,0))return;this.fsw._emit(R.ADD,e,t)}return c}async _handleSymlink(e,t,n,r){if(this.fsw.closed)return;let i=e.fullPath,a=this.fsw._getWatchedDir(t);if(!this.fsw.options.followSymlinks){this.fsw._incrReadyCount();let t;try{t=await x(n)}catch{return this.fsw._emitReady(),!0}return this.fsw.closed?void 0:(a.has(r)?this.fsw._symlinkPaths.get(i)!==t&&(this.fsw._symlinkPaths.set(i,t),this.fsw._emit(R.CHANGE,n,e.stats)):(a.add(r),this.fsw._symlinkPaths.set(i,t),this.fsw._emit(R.ADD,n,e.stats)),this.fsw._emitReady(),!0)}if(this.fsw._symlinkPaths.has(i))return!0;this.fsw._symlinkPaths.set(i,!0)}_handleRead(e,t,n,r,i,a,o){e=u.join(e,``);let s=r?`${e}:${r}`:e;if(o=this.fsw._throttle(`readdir`,s,1e3),!o)return;let c=this.fsw._getWatchedDir(n.path),l=new Set,d=this.fsw._readdirp(e,{fileFilter:e=>n.filterPath(e),directoryFilter:e=>n.filterDir(e)});if(d)return d.on(`data`,async o=>{if(this.fsw.closed){d=void 0;return}let s=o.path,f=u.join(e,s);if(l.add(s),!(o.stats.isSymbolicLink()&&await this._handleSymlink(o,e,f,s))){if(this.fsw.closed){d=void 0;return}(s===r||!r&&!c.has(s))&&(this.fsw._incrReadyCount(),f=u.join(i,u.relative(i,f)),this._addToNodeFs(f,t,n,a+1))}}).on(R.ERROR,this._boundHandleError),new Promise((t,s)=>{if(!d)return s();d.once(`end`,()=>{if(this.fsw.closed){d=void 0;return}let s=o?o.clear():!1;t(void 0),c.getChildren().filter(t=>t!==e&&!l.has(t)).forEach(t=>{this.fsw._remove(e,t)}),d=void 0,s&&this._handleRead(e,!1,n,r,i,a,o)})})}async _handleDir(e,t,n,r,i,a,o){let s=this.fsw._getWatchedDir(u.dirname(e)),c=s.has(u.basename(e));!(n&&this.fsw.options.ignoreInitial)&&!i&&!c&&this.fsw._emit(R.ADD_DIR,e,t),s.add(u.basename(e)),this.fsw._getWatchedDir(e);let l,d=this.fsw.options.depth;if((d==null||r<=d)&&!this.fsw._symlinkPaths.has(o)){if(!i&&(await this._handleRead(e,n,a,i,e,r,void 0),this.fsw.closed))return;l=this._watchWithNodeFs(e,(t,n)=>{n&&n.mtimeMs===0||this._handleRead(t,!1,a,i,e,r,void 0)})}return l}async _addToNodeFs(e,t,n,r,i){let a=this.fsw._emitReady;if(this.fsw._isIgnored(e)||this.fsw.closed)return a(),!1;let o=this.fsw._getWatchHelpers(e);n&&(o.filterPath=e=>n.filterPath(e),o.filterDir=e=>n.filterDir(e));try{let n=await me[o.statMethod](o.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(o.watchPath,n))return a(),!1;let s=this.fsw.options.followSymlinks,c;if(n.isDirectory()){let a=u.resolve(e),l=s?await x(e):e;if(this.fsw.closed||(c=await this._handleDir(o.watchPath,n,t,r,i,o,l),this.fsw.closed))return;a!==l&&l!==void 0&&this.fsw._symlinkPaths.set(a,l)}else if(n.isSymbolicLink()){let i=s?await x(e):e;if(this.fsw.closed)return;let a=u.dirname(o.watchPath);if(this.fsw._getWatchedDir(a).add(o.watchPath),this.fsw._emit(R.ADD,o.watchPath,n),c=await this._handleDir(a,n,t,r,e,o,i),this.fsw.closed)return;i!==void 0&&this.fsw._symlinkPaths.set(u.resolve(e),i)}else c=this._handleFile(o.watchPath,n,t);return a(),c&&this.fsw._addPathCloser(e,c),!1}catch(t){if(this.fsw._handleError(t))return a(),e}}};const we=/\\/g,Te=/\/\//g,Ee=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,De=/^\.[/\\]/;function J(e){return Array.isArray(e)?e:[e]}const Y=e=>typeof e==`object`&&!!e&&!(e instanceof RegExp);function Oe(e){return typeof e==`function`?e:typeof e==`string`?t=>e===t:e instanceof RegExp?t=>e.test(t):typeof e==`object`&&e?t=>{if(e.path===t)return!0;if(e.recursive){let n=u.relative(e.path,t);return n?!n.startsWith(`..`)&&!u.isAbsolute(n):!1}return!1}:()=>!1}function ke(e){if(typeof e!=`string`)throw Error(`string expected`);e=u.normalize(e),e=e.replace(/\\/g,`/`);let t=!1;return e.startsWith(`//`)&&(t=!0),e=e.replace(Te,`/`),t&&(e=`/`+e),e}function Ae(e,t,n){let r=ke(t);for(let t=0;t<e.length;t++){let i=e[t];if(i(r,n))return!0}return!1}function je(e,t){if(e==null)throw TypeError(`anymatch: specify first argument`);let n=J(e).map(e=>Oe(e));return t==null?(e,t)=>Ae(n,e,t):Ae(n,t)}const Me=e=>{let t=J(e).flat();if(!t.every(e=>typeof e==`string`))throw TypeError(`Non-string provided as watch path: ${t}`);return t.map(Pe)},Ne=e=>{let t=e.replace(we,`/`),n=!1;return t.startsWith(`//`)&&(n=!0),t=t.replace(Te,`/`),n&&(t=`/`+t),t},Pe=e=>Ne(u.normalize(Ne(e))),Fe=(e=``)=>t=>typeof t==`string`?Pe(u.isAbsolute(t)?t:u.join(e,t)):t,Ie=(e,t)=>u.isAbsolute(e)?e:u.join(t,e),Le=Object.freeze(new Set);var Re=class{path;_removeWatcher;items;constructor(e,t){this.path=e,this._removeWatcher=t,this.items=new Set}add(e){let{items:t}=this;t&&e!==`.`&&e!==`..`&&t.add(e)}async remove(e){let{items:t}=this;if(!t||(t.delete(e),t.size>0))return;let n=this.path;try{await b(n)}catch{this._removeWatcher&&this._removeWatcher(u.dirname(n),u.basename(n))}}has(e){let{items:t}=this;if(t)return t.has(e)}getChildren(){let{items:e}=this;return e?[...e.values()]:[]}dispose(){this.items.clear(),this.path=``,this._removeWatcher=P,this.items=Le,Object.freeze(this)}},ze=class{fsw;path;watchPath;fullWatchPath;dirParts;followSymlinks;statMethod;constructor(e,t,n){this.fsw=n;let r=e;this.path=e=e.replace(De,``),this.watchPath=r,this.fullWatchPath=u.resolve(r),this.dirParts=[],this.dirParts.forEach(e=>{e.length>1&&e.pop()}),this.followSymlinks=t,this.statMethod=t?`stat`:`lstat`}entryPath(e){return u.join(this.watchPath,u.relative(this.watchPath,e.fullPath))}filterPath(e){let{stats:t}=e;if(t&&t.isSymbolicLink())return this.filterDir(e);let n=this.entryPath(e);return this.fsw._isntIgnored(n,t)&&this.fsw._hasReadPermissions(t)}filterDir(e){return this.fsw._isntIgnored(this.entryPath(e),e.stats)}},Be=class extends O{closed;options;_closers;_ignoredPaths;_throttled;_streams;_symlinkPaths;_watched;_pendingWrites;_pendingUnlinks;_readyCount;_emitReady;_closePromise;_userIgnored;_readyEmitted;_emitRaw;_boundRemove;_nodeFsHandler;constructor(e={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;let t=e.awaitWriteFinish,n={stabilityThreshold:2e3,pollInterval:100},r={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...e,ignored:e.ignored?J(e.ignored):J([]),awaitWriteFinish:t===!0?n:typeof t==`object`?{...n,...t}:!1};pe&&(r.usePolling=!0),r.atomic===void 0&&(r.atomic=!r.usePolling);let i=process.env.CHOKIDAR_USEPOLLING;if(i!==void 0){let e=i.toLowerCase();e===`false`||e===`0`?r.usePolling=!1:e===`true`||e===`1`?r.usePolling=!0:r.usePolling=!!e}let a=process.env.CHOKIDAR_INTERVAL;a&&(r.interval=Number.parseInt(a,10));let o=0;this._emitReady=()=>{o++,o>=this._readyCount&&(this._emitReady=P,this._readyEmitted=!0,process.nextTick(()=>this.emit(L.READY)))},this._emitRaw=(...e)=>this.emit(L.RAW,...e),this._boundRemove=this._remove.bind(this),this.options=r,this._nodeFsHandler=new Ce(this),Object.freeze(r)}_addIgnoredPath(e){if(Y(e)){for(let t of this._ignoredPaths)if(Y(t)&&t.path===e.path&&t.recursive===e.recursive)return}this._ignoredPaths.add(e)}_removeIgnoredPath(e){if(this._ignoredPaths.delete(e),typeof e==`string`)for(let t of this._ignoredPaths)Y(t)&&t.path===e&&this._ignoredPaths.delete(t)}add(e,t,n){let{cwd:r}=this.options;this.closed=!1,this._closePromise=void 0;let i=Me(e);return r&&(i=i.map(e=>Ie(e,r))),i.forEach(e=>{this._removeIgnoredPath(e)}),this._userIgnored=void 0,this._readyCount||=0,this._readyCount+=i.length,Promise.all(i.map(async e=>{let r=await this._nodeFsHandler._addToNodeFs(e,!n,void 0,0,t);return r&&this._emitReady(),r})).then(e=>{this.closed||e.forEach(e=>{e&&this.add(u.dirname(e),u.basename(t||e))})}),this}unwatch(e){if(this.closed)return this;let t=Me(e),{cwd:n}=this.options;return t.forEach(e=>{!u.isAbsolute(e)&&!this._closers.has(e)&&(n&&(e=u.join(n,e)),e=u.resolve(e)),this._closePath(e),this._addIgnoredPath(e),this._watched.has(e)&&this._addIgnoredPath({path:e,recursive:!0}),this._userIgnored=void 0}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let e=[];return this._closers.forEach(t=>t.forEach(t=>{let n=t();n instanceof Promise&&e.push(n)})),this._streams.forEach(e=>e.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(e=>e.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=e.length?Promise.all(e).then(()=>void 0):Promise.resolve(),this._closePromise}getWatched(){let e={};return this._watched.forEach((t,n)=>{let r=(this.options.cwd?u.relative(this.options.cwd,n):n)||`.`;e[r]=t.getChildren().sort()}),e}emitWithAll(e,t){this.emit(e,...t),e!==L.ERROR&&this.emit(L.ALL,e,...t)}async _emit(e,t,n){if(this.closed)return;let r=this.options;I&&(t=u.normalize(t)),r.cwd&&(t=u.relative(r.cwd,t));let i=[t];n!=null&&i.push(n);let a=r.awaitWriteFinish,o;if(a&&(o=this._pendingWrites.get(t)))return o.lastChange=new Date,this;if(r.atomic){if(e===L.UNLINK)return this._pendingUnlinks.set(t,[e,...i]),setTimeout(()=>{this._pendingUnlinks.forEach((e,t)=>{this.emit(...e),this.emit(L.ALL,...e),this._pendingUnlinks.delete(t)})},typeof r.atomic==`number`?r.atomic:100),this;e===L.ADD&&this._pendingUnlinks.has(t)&&(e=L.CHANGE,this._pendingUnlinks.delete(t))}if(a&&(e===L.ADD||e===L.CHANGE)&&this._readyEmitted)return this._awaitWriteFinish(t,a.stabilityThreshold,e,(t,n)=>{t?(e=L.ERROR,i[0]=t,this.emitWithAll(e,i)):n&&(i.length>1?i[1]=n:i.push(n),this.emitWithAll(e,i))}),this;if(e===L.CHANGE&&!this._throttle(L.CHANGE,t,50))return this;if(r.alwaysStat&&n===void 0&&(e===L.ADD||e===L.ADD_DIR||e===L.CHANGE)){let e=r.cwd?u.join(r.cwd,t):t,n;try{n=await S(e)}catch{}if(!n||this.closed)return;i.push(n)}return this.emitWithAll(e,i),this}_handleError(e){let t=e&&e.code;return e&&t!==`ENOENT`&&t!==`ENOTDIR`&&(!this.options.ignorePermissionErrors||t!==`EPERM`&&t!==`EACCES`)&&this.emit(L.ERROR,e),e||this.closed}_throttle(e,t,n){this._throttled.has(e)||this._throttled.set(e,new Map);let r=this._throttled.get(e);if(!r)throw Error(`invalid throttle`);let i=r.get(t);if(i)return i.count++,!1;let a,o=()=>{let e=r.get(t),n=e?e.count:0;return r.delete(t),clearTimeout(a),e&&clearTimeout(e.timeoutObject),n};a=setTimeout(o,n);let s={timeoutObject:a,clear:o,count:0};return r.set(t,s),s}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(e,t,n,r){let i=this.options.awaitWriteFinish;if(typeof i!=`object`)return;let a=i.pollInterval,o,s=e;this.options.cwd&&!u.isAbsolute(e)&&(s=u.join(this.options.cwd,e));let c=new Date,l=this._pendingWrites;function d(n){w(s,(i,s)=>{if(i||!l.has(e)){i&&i.code!==`ENOENT`&&r(i);return}let c=Number(new Date);n&&s.size!==n.size&&(l.get(e).lastChange=c),c-l.get(e).lastChange>=t?(l.delete(e),r(void 0,s)):o=setTimeout(d,a,s)})}l.has(e)||(l.set(e,{lastChange:c,cancelWait:()=>(l.delete(e),clearTimeout(o),n)}),o=setTimeout(d,a))}_isIgnored(e,t){if(this.options.atomic&&Ee.test(e))return!0;if(!this._userIgnored){let{cwd:e}=this.options,t=(this.options.ignored||[]).map(Fe(e)),n=[...[...this._ignoredPaths].map(Fe(e)),...t];this._userIgnored=je(n,void 0)}return this._userIgnored(e,t)}_isntIgnored(e,t){return!this._isIgnored(e,t)}_getWatchHelpers(e){return new ze(e,this.options.followSymlinks,this)}_getWatchedDir(e){let t=u.resolve(e);return this._watched.has(t)||this._watched.set(t,new Re(t,this._boundRemove)),this._watched.get(t)}_hasReadPermissions(e){return this.options.ignorePermissionErrors?!0:!!(Number(e.mode)&256)}_remove(e,t,n){let r=u.join(e,t),i=u.resolve(r);if(n??=this._watched.has(r)||this._watched.has(i),!this._throttle(`remove`,r,100))return;!n&&this._watched.size===1&&this.add(e,t,!0),this._getWatchedDir(r).getChildren().forEach(e=>this._remove(r,e));let a=this._getWatchedDir(e),o=a.has(t);a.remove(t),this._symlinkPaths.has(i)&&this._symlinkPaths.delete(i);let s=r;if(this.options.cwd&&(s=u.relative(this.options.cwd,r)),this.options.awaitWriteFinish&&this._pendingWrites.has(s)&&this._pendingWrites.get(s).cancelWait()===L.ADD)return;this._watched.delete(r),this._watched.delete(i);let c=n?L.UNLINK_DIR:L.UNLINK;o&&!this._isIgnored(r)&&this._emit(c,r),this._closePath(r)}_closePath(e){this._closeFile(e);let t=u.dirname(e);this._getWatchedDir(t).remove(u.basename(e))}_closeFile(e){let t=this._closers.get(e);t&&(t.forEach(e=>e()),this._closers.delete(e))}_addPathCloser(e,t){if(!t)return;let n=this._closers.get(e);n||(n=[],this._closers.set(e,n)),n.push(t)}_readdirp(e,t){if(this.closed)return;let n=le(e,{type:L.ALL,alwaysStat:!0,lstat:!0,...t,depth:0});return this._streams.add(n),n.once(`close`,()=>{n=void 0}),n.once(`end`,()=>{n&&=(this._streams.delete(n),void 0)}),n}};function Ve(e,t={}){let n=new Be(t);return n.add(e),n}function He(e,t=!1){let n=e.length,r=0,i=``,a=0,o=16,s=0,c=0,l=0,u=0,d=0;function f(t,n){let i=0,a=0;for(;i<t||!n;){let t=e.charCodeAt(r);if(t>=48&&t<=57)a=a*16+t-48;else if(t>=65&&t<=70)a=a*16+t-65+10;else if(t>=97&&t<=102)a=a*16+t-97+10;else break;r++,i++}return i<t&&(a=-1),a}function p(e){r=e,i=``,a=0,o=16,d=0}function m(){let t=r;if(e.charCodeAt(r)===48)r++;else for(r++;r<e.length&&Q(e.charCodeAt(r));)r++;if(r<e.length&&e.charCodeAt(r)===46)if(r++,r<e.length&&Q(e.charCodeAt(r)))for(r++;r<e.length&&Q(e.charCodeAt(r));)r++;else return d=3,e.substring(t,r);let n=r;if(r<e.length&&(e.charCodeAt(r)===69||e.charCodeAt(r)===101))if(r++,(r<e.length&&e.charCodeAt(r)===43||e.charCodeAt(r)===45)&&r++,r<e.length&&Q(e.charCodeAt(r))){for(r++;r<e.length&&Q(e.charCodeAt(r));)r++;n=r}else d=3;return e.substring(t,n)}function h(){let t=``,i=r;for(;;){if(r>=n){t+=e.substring(i,r),d=2;break}let a=e.charCodeAt(r);if(a===34){t+=e.substring(i,r),r++;break}if(a===92){if(t+=e.substring(i,r),r++,r>=n){d=2;break}switch(e.charCodeAt(r++)){case 34:t+=`"`;break;case 92:t+=`\\`;break;case 47:t+=`/`;break;case 98:t+=`\b`;break;case 102:t+=`\f`;break;case 110:t+=`
|
|
2
2
|
`;break;case 114:t+=`\r`;break;case 116:t+=` `;break;case 117:let e=f(4,!0);e>=0?t+=String.fromCharCode(e):d=4;break;default:d=5}i=r;continue}if(a>=0&&a<=31)if(Z(a)){t+=e.substring(i,r),d=2;break}else d=6;r++}return t}function g(){if(i=``,d=0,a=r,c=s,u=l,r>=n)return a=n,o=17;let t=e.charCodeAt(r);if(X(t)){do r++,i+=String.fromCharCode(t),t=e.charCodeAt(r);while(X(t));return o=15}if(Z(t))return r++,i+=String.fromCharCode(t),t===13&&e.charCodeAt(r)===10&&(r++,i+=`
|
|
3
3
|
`),s++,l=r,o=14;switch(t){case 123:return r++,o=1;case 125:return r++,o=2;case 91:return r++,o=3;case 93:return r++,o=4;case 58:return r++,o=6;case 44:return r++,o=5;case 34:return r++,i=h(),o=10;case 47:let c=r-1;if(e.charCodeAt(r+1)===47){for(r+=2;r<n&&!Z(e.charCodeAt(r));)r++;return i=e.substring(c,r),o=12}if(e.charCodeAt(r+1)===42){r+=2;let t=n-1,a=!1;for(;r<t;){let t=e.charCodeAt(r);if(t===42&&e.charCodeAt(r+1)===47){r+=2,a=!0;break}r++,Z(t)&&(t===13&&e.charCodeAt(r)===10&&r++,s++,l=r)}return a||(r++,d=1),i=e.substring(c,r),o=13}return i+=String.fromCharCode(t),r++,o=16;case 45:if(i+=String.fromCharCode(t),r++,r===n||!Q(e.charCodeAt(r)))return o=16;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return i+=m(),o=11;default:for(;r<n&&_(t);)r++,t=e.charCodeAt(r);if(a!==r){switch(i=e.substring(a,r),i){case`true`:return o=8;case`false`:return o=9;case`null`:return o=7}return o=16}return i+=String.fromCharCode(t),r++,o=16}}function _(e){if(X(e)||Z(e))return!1;switch(e){case 125:case 93:case 123:case 91:case 34:case 58:case 44:case 47:return!1}return!0}function v(){let e;do e=g();while(e>=12&&e<=15);return e}return{setPosition:p,getPosition:()=>r,scan:t?v:g,getToken:()=>o,getTokenValue:()=>i,getTokenOffset:()=>a,getTokenLength:()=>r-a,getTokenStartLine:()=>c,getTokenStartCharacter:()=>a-u,getTokenError:()=>d}}function X(e){return e===32||e===9}function Z(e){return e===10||e===13}function Q(e){return e>=48&&e<=57}var Ue;(function(e){e[e.lineFeed=10]=`lineFeed`,e[e.carriageReturn=13]=`carriageReturn`,e[e.space=32]=`space`,e[e._0=48]=`_0`,e[e._1=49]=`_1`,e[e._2=50]=`_2`,e[e._3=51]=`_3`,e[e._4=52]=`_4`,e[e._5=53]=`_5`,e[e._6=54]=`_6`,e[e._7=55]=`_7`,e[e._8=56]=`_8`,e[e._9=57]=`_9`,e[e.a=97]=`a`,e[e.b=98]=`b`,e[e.c=99]=`c`,e[e.d=100]=`d`,e[e.e=101]=`e`,e[e.f=102]=`f`,e[e.g=103]=`g`,e[e.h=104]=`h`,e[e.i=105]=`i`,e[e.j=106]=`j`,e[e.k=107]=`k`,e[e.l=108]=`l`,e[e.m=109]=`m`,e[e.n=110]=`n`,e[e.o=111]=`o`,e[e.p=112]=`p`,e[e.q=113]=`q`,e[e.r=114]=`r`,e[e.s=115]=`s`,e[e.t=116]=`t`,e[e.u=117]=`u`,e[e.v=118]=`v`,e[e.w=119]=`w`,e[e.x=120]=`x`,e[e.y=121]=`y`,e[e.z=122]=`z`,e[e.A=65]=`A`,e[e.B=66]=`B`,e[e.C=67]=`C`,e[e.D=68]=`D`,e[e.E=69]=`E`,e[e.F=70]=`F`,e[e.G=71]=`G`,e[e.H=72]=`H`,e[e.I=73]=`I`,e[e.J=74]=`J`,e[e.K=75]=`K`,e[e.L=76]=`L`,e[e.M=77]=`M`,e[e.N=78]=`N`,e[e.O=79]=`O`,e[e.P=80]=`P`,e[e.Q=81]=`Q`,e[e.R=82]=`R`,e[e.S=83]=`S`,e[e.T=84]=`T`,e[e.U=85]=`U`,e[e.V=86]=`V`,e[e.W=87]=`W`,e[e.X=88]=`X`,e[e.Y=89]=`Y`,e[e.Z=90]=`Z`,e[e.asterisk=42]=`asterisk`,e[e.backslash=92]=`backslash`,e[e.closeBrace=125]=`closeBrace`,e[e.closeBracket=93]=`closeBracket`,e[e.colon=58]=`colon`,e[e.comma=44]=`comma`,e[e.dot=46]=`dot`,e[e.doubleQuote=34]=`doubleQuote`,e[e.minus=45]=`minus`,e[e.openBrace=123]=`openBrace`,e[e.openBracket=91]=`openBracket`,e[e.plus=43]=`plus`,e[e.slash=47]=`slash`,e[e.formFeed=12]=`formFeed`,e[e.tab=9]=`tab`})(Ue||={}),Array(20).fill(0).map((e,t)=>` `.repeat(t)),Array(200).fill(0).map((e,t)=>`
|
|
4
4
|
`+` `.repeat(t)),Array(200).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(200).fill(0).map((e,t)=>`\r
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import{n as e}from"./chunk-8L7ocgPr.js";import{E as t,T as n,i as r,o as i,r as a,w as o}from"./paths-OknjaYR8.js";import{a as s,i as c,n as l,r as u}from"./authored-module-loader-XcFLnl49.js";import{a as d,i as f,n as p,o as ee,r as te,t as m}from"./package-DmsQgn4v.js";import{g as h,m as ne,p as re}from"./types-MZUhN0Zy.js";import{a as ie,c as ae,n as oe,o as se,r as ce,t as le}from"./prewarm-B4YblQ5m.js";import{builtinModules as ue}from"node:module";import{dirname as g,extname as de,isAbsolute as fe,join as _,relative as v,resolve as y,sep as pe}from"node:path";import{cp as b,mkdir as x,readFile as S,readdir as me,realpath as he,rename as C,rm as w,symlink as ge,writeFile as T}from"node:fs/promises";import{randomUUID as _e}from"node:crypto";import{existsSync as ve,readFileSync as ye}from"node:fs";import{fileURLToPath as be}from"node:url";import{Buffer as xe}from"node:buffer";import{build as Se,copyPublicAssets as Ce,createDevServer as we,createNitro as Te,prepare as Ee,prerender as De}from"nitro/builder";const Oe=`ash-cache.json`;async function E(e){let t=await ke(e),n=m().version;t!==null&&t===n||await w(e,{force:!0,recursive:!0})}async function D(e){await x(e,{recursive:!0}),await T(_(e,Oe),`${JSON.stringify({ashVersion:m().version},null,2)}\n`)}async function ke(e){try{let t=JSON.parse(await S(_(e,Oe),`utf8`));return typeof t.ashVersion==`string`?t.ashVersion:null}catch(e){return e instanceof Error&&`code`in e&&e.code,null}}const Ae=new Set([`__builtin_response_array_buffer`,`__builtin_response_json`,`__builtin_response_text`]);async function je(e){if(e.mode===!1)return{code:e.source,workflowManifest:{}};let t=await Me(e.filename,e.source),n=Pe(t);if(n.length===0)return{code:e.source,workflowManifest:{}};let r=e.moduleSpecifier??`./${Ye(e.filename)}`,i=e.stableModuleSpecifier??r,a={},o=[],s=[],c=!1;for(let t of n){if(t.directive===`use step`){let n=Xe(r,t.name);a.steps??={};let i=a.steps[e.filename]??={};if(i[t.name]={stepId:n},e.mode===`workflow`){let e=t.exportPrefix.length>0?`export `:``;o.push({end:t.rangeEnd,start:t.rangeStart,text:`${e}var ${t.name} = globalThis[Symbol.for("WORKFLOW_USE_STEP")](${JSON.stringify(n)});`})}else o.push({end:t.directiveEnd,start:t.directiveStart,text:``}),e.mode===`step`?(c=!0,s.push(`registerStepFunction(${JSON.stringify(n)}, ${t.name});`)):s.push(`${t.name}.stepId = ${JSON.stringify(n)};`);continue}let n=`workflow//${e.stableWorkflowNames?.has(t.name)===!0?i:r}//${t.name}`;a.workflows??={};let l=a.workflows[e.filename]??={};l[t.name]={workflowId:n},e.mode===`workflow`?(o.push({end:t.directiveEnd,start:t.directiveStart,text:``}),s.push(`${t.name}.workflowId = ${JSON.stringify(n)};`),s.push(`globalThis.__private_workflows.set(${JSON.stringify(n)}, ${t.name});`)):(o.push({end:t.directiveEnd,start:t.directiveStart,text:`throw new Error(${JSON.stringify(`You attempted to execute workflow ${t.name} function directly. To start a workflow, use start(${t.name}) from workflow/api`)});`}),s.push(`${t.name}.workflowId = ${JSON.stringify(n)};`))}let l=`/**__internal_workflows${JSON.stringify(a)}*/;`,u=n.some(e=>e.directive===`use workflow`);if(e.mode===`workflow`&&!u)return{code:`${l}\n${Ne(e.source,t,n,r)}`,workflowManifest:a};let d=ze(e.source,o),f=e.mode===`workflow`?await Be(e.filename,d):d;return{code:`${c?`import { registerStepFunction } from "workflow/internal/private";\n${l}\n`:`${l}\n`}${f}${s.length>0?`\n${s.join(`
|
|
2
|
+
`)}\n`:``}`,workflowManifest:a}}async function Me(e,t){let{parseAst:n}=await s();return n(t,{astType:`ts`,lang:Je(e),range:!0,sourceType:`module`},e)}function Ne(e,t,n,r){let i=Ve(e,t),a=n.filter(e=>e.directive===`use step`).map(e=>{let t=e.exportPrefix.length>0?`export `:``,n=Xe(r,e.name);return`${t}var ${e.name} = globalThis[Symbol.for("WORKFLOW_USE_STEP")](${JSON.stringify(n)});`}),o=[...i,...a];return o.length>0?`${o.join(`
|
|
3
|
+
`)}\n`:``}function Pe(e){let t=[];for(let n of e.body??[]){let e=Fe(n);if(e===null)continue;let r=e.fn,i=r.id?.name,a=Le(r.body);if(r.async!==!0||i===void 0||a===void 0)continue;let o=Re(a[0]);o!==null&&t.push({directive:o.value,directiveEnd:o.end,directiveStart:o.start,exportPrefix:e.exported?`export `:``,name:i,rangeEnd:e.end,rangeStart:e.start})}return t}function Fe(e){return e.type===`FunctionDeclaration`?Ie(e,!1,e):e.type!==`ExportNamedDeclaration`||e.declaration?.type!==`FunctionDeclaration`?null:Ie(e.declaration,!0,e)}function Ie(e,t,n){return e.start===void 0||e.end===void 0||n.start===void 0||n.end===void 0?null:{end:n.end,exported:t,fn:e,start:n.start}}function Le(e){return e===void 0||Array.isArray(e)?e:e.body}function Re(e){let t=e?.directive??(e?.type===`ExpressionStatement`&&e.expression?.type===`Literal`?e.expression.value:void 0);return t!==`use workflow`&&t!==`use step`||e?.start===void 0||e.end===void 0?null:{end:e.end,start:e.start,value:t}}function ze(e,t){let n=``,r=0;for(let i of[...t].sort((e,t)=>e.start-t.start))n+=e.slice(r,i.start),n+=i.text,r=i.end;return n+e.slice(r)}async function Be(e,t){let n=await Me(e,t),r=Ge(n),i=[];for(let e of n.body??[]){if(e.type!==`ImportDeclaration`||e.start===void 0||e.end===void 0)continue;let n=We(e);n.length>0&&n.every(e=>!r.has(e))&&i.push({end:qe(t,e.end),start:e.start,text:``})}return i.length>0?ze(t,i):t}function Ve(e,t){let n=[];for(let r of t.body??[])r.type===`ExportNamedDeclaration`&&r.declaration?.type===`VariableDeclaration`&&r.declaration.kind===`const`&&r.start!==void 0&&r.end!==void 0&&(r.declaration.declarations??[]).every(He)&&n.push(e.slice(r.start,r.end).trim());return n}function He(e){return Ue(e.init)}function Ue(e){return e==null?!1:e.type===`Literal`?e.value===null||typeof e.value==`boolean`||typeof e.value==`number`||typeof e.value==`string`:e.type===`TSAsExpression`||e.type===`TSSatisfiesExpression`||e.type===`TSNonNullExpression`||e.type===`TSTypeAssertion`?Ue(e.expression):e.type===`UnaryExpression`&&e.argument?.type===`Literal`?typeof e.argument.value==`number`:!1}function We(e){return e.importKind===`type`?[]:(e.specifiers??[]).filter(e=>e.importKind!==`type`).map(e=>e.local?.name).filter(e=>e!==void 0)}function Ge(e){let t=new Set;return O(e,e=>{e.type===`Identifier`&&typeof e.name==`string`&&t.add(e.name)}),t}function O(e,t){if(!(e.type===`ImportDeclaration`||e.type?.startsWith(`TS`))){t(e);for(let n of Object.values(e))if(Array.isArray(n))for(let e of n)Ke(e)&&O(e,t);else Ke(n)&&O(n,t)}}function Ke(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}function qe(e,t){let n=t;for(;n<e.length&&(e[n]===` `||e[n]===` `);)n+=1;return e[n]===`\r`&&e[n+1]===`
|
|
4
|
+
`?n+2:e[n]===`
|
|
5
|
+
`?n+1:n}function Je(e){return e.endsWith(`.tsx`)?`tsx`:e.endsWith(`.jsx`)?`jsx`:/\.[cm]?ts$/.test(e)?`ts`:`js`}function Ye(e){return e.replace(/\.(?:[cm]?[jt]sx?)$/,``)}function Xe(e,t){return Ae.has(t)?t:`step//${e}//${t}`}const Ze={type:`queue/v2beta`,topic:`__wkf_workflow_*`,consumer:`default`,retryAfterSeconds:5,initialDelaySeconds:0},k=new Map,Qe=new Map;async function A(e,t,n,r,a,o=i){let s=a??process.cwd(),{moduleSpecifier:c,stableModuleSpecifier:l}=tt(r===void 0?fe(e)?e:_(s,e):r,s);return je({filename:e,mode:n,moduleSpecifier:c,source:t,stableModuleSpecifier:l,stableWorkflowNames:o})}function $e(e){return{hasSerde:e.includes(`workflow.serde`)||e.includes(`@serde`)||e.includes(`workflowSerde`)||e.includes(`__workflow_serde`),hasUseStep:/["']use step["']/.test(e),hasUseWorkflow:/["']use workflow["']/.test(e)}}function et(e,t){let n=N(e),r=!n&&at(e,t);if(n||r){let n=j(e);if(n!==null){let i=it(t).has(n.name);if(!(r||i))return{importPath:P(e,t),isPackage:!1};let a=nt(e,n);return a?{importPath:`${n.name}${a}`,isPackage:!0}:ct(e,n)?{importPath:n.name,isPackage:!0}:{importPath:P(e,t),isPackage:!1}}}return{importPath:P(e,t),isPackage:!1}}function tt(e,t){let n=N(e),r=!n&&at(e,t);if(!n&&!r)return{moduleSpecifier:void 0,stableModuleSpecifier:void 0};let i=j(e);if(i===null)return{moduleSpecifier:void 0,stableModuleSpecifier:void 0};let a=nt(e,i),o=a?`${i.name}${a}`:i.name;return{moduleSpecifier:`${o}@${i.version}`,stableModuleSpecifier:o}}function j(e){let t=g(e),n=[];for(;t!==g(t);){let e=k.get(t);if(e!==void 0){for(let t of n)k.set(t,e);return e}n.push(t);let r=_(t,`package.json`);if(ve(r))try{let e=JSON.parse(ye(r,`utf8`));if(typeof e.name==`string`&&typeof e.version==`string`){let r={dir:t,exports:e.exports,main:e.main,module:e.module,name:e.name,version:e.version};k.set(t,r);for(let e of n)k.set(e,r);return r}}catch{}t=g(t)}for(let e of n)k.set(e,null);return null}function nt(e,t){if(t.exports===null||typeof t.exports!=`object`||Array.isArray(t.exports))return``;let n=e.replace(/\\/g,`/`),r=t.dir.replace(/\\/g,`/`),i=n.startsWith(`${r}/`)?`./${n.substring(r.length+1)}`:null;if(i===null)return``;for(let[e,n]of Object.entries(t.exports)){let t=M(n);if(t!==null&&rt(t)===i)return e===`.`?``:e.substring(1)}return``}function M(e){if(typeof e==`string`)return e;if(Array.isArray(e)){for(let t of e){let e=M(t);if(e!==null)return e}return null}if(typeof e==`object`&&e)for(let t of[`workflow`,`default`,`require`,`import`,`node`]){let n=e[t],r=M(n);if(r!==null)return r}return null}function rt(e){return e.startsWith(`./`)?e:`./${e}`}function N(e){return e.split(pe).join(`/`).includes(`/node_modules/`)}function it(e){let t=Qe.get(e);if(t!==void 0)return t;let n=new Set,r=_(e,`package.json`);if(ve(r))try{let e=JSON.parse(ye(r,`utf8`));for(let t of[`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`]){let r=e[t];if(typeof r==`object`&&r&&!Array.isArray(r))for(let e of Object.keys(r))n.add(e)}}catch{}return Qe.set(e,n),n}function at(e,t){if(N(e))return!1;let n=j(e);return n===null||y(n.dir)===y(t)?!1:it(t).has(n.name)}function P(e,t){let n=t.replace(/\\/g,`/`),r=e.replace(/\\/g,`/`),i=r.startsWith(`${n}/`)?r.substring(n.length+1):v(t,e).replace(/\\/g,`/`);return i.startsWith(`.`)||(i=`./${i}`),i}function ot(e){if(typeof e==`string`||Array.isArray(e))return!0;if(typeof e!=`object`||!e)return!1;let t=Object.keys(e);return t.length>0&&t.every(e=>!e.startsWith(`.`))?!0:`.`in e}function st(e){let t=e.replace(/\\/g,`/`);return t.startsWith(`./`)?t.substring(2):t.startsWith(`/`)?t.substring(1):t}function ct(e,t){let n=e.replace(/\\/g,`/`),r=t.dir.replace(/\\/g,`/`);if(!n.startsWith(`${r}/`))return!1;let i=n.substring(r.length+1);if(t.exports!==void 0){let e;if(t.exports!==null&&typeof t.exports==`object`&&`.`in t.exports)e=t.exports[`.`];else if(ot(t.exports))e=t.exports;else return!1;let n=M(e);return n!==null&&st(n)===i}return[t.module,t.main,`index.js`,`index.mjs`,`index.cjs`,`index.ts`,`index.mts`,`index.cts`].flatMap(e=>typeof e==`string`?[st(e)]:[]).includes(i)}const lt=`\0ash-workflow-entry`,ut=new Set([`server-only`,`client-only`,`next/dist/compiled/server-only`,`next/dist/compiled/client-only`]);new Set([...ue,...ue.map(e=>`node:${e}`)]);const dt=new Set([`.ts`,`.tsx`,`.mts`,`.cts`,`.js`,`.jsx`,`.mjs`,`.cjs`]),ft=new Set([`node_modules`,`.git`,`.next`,`.nuxt`,`.output`,`.vercel`,`.workflow-data`,`.workflow-vitest`,`.well-known`,`.svelte-kit`,`.turbo`,`.cache`,`.yarn`,`.pnpm-store`]);async function pt(e){let t=[];async function n(e){let r;try{r=await me(e,{withFileTypes:!0})}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}for(let i of r){if(i.isDirectory()){ft.has(i.name)||await n(_(e,i.name));continue}if(!i.isFile())continue;let r=i.name.match(/\.[^.]+$/)?.[0];r!==void 0&&dt.has(r)&&t.push(_(e,i.name))}}return await n(e),t}function mt(e,t){let{importPath:n,isPackage:r}=et(e,t);return r?`import ${JSON.stringify(n)};`:`import ${JSON.stringify(Ct(t,e))};`}function ht(e){return{name:`ash-workflow-virtual-entry`,resolveId(e){if(e===`\0ash-workflow-entry`)return{id:e}},load(t){if(t===`\0ash-workflow-entry`)return{code:e,moduleSideEffects:!0,moduleType:`js`}}}}function gt(){return{name:`ash-workflow-pseudo-packages`,resolveId(e){if(ut.has(e))return{id:`\0ash-workflow-pseudo-package:${e}`}},load(e){if(e.startsWith(`\0ash-workflow-pseudo-package:`))return{code:``,moduleType:`js`}}}}function _t(e,t={}){return{name:`ash-package-imports`,resolveId(n){let r=n.match(/^#compiled\/(.+)$/)?.[1];if(r!==void 0)return t.workflowCondition===!0&&r===`@workflow/core/index.js`?F([_(e,`src`,`internal`,`workflow-bundle`,`workflow-core-shim.ts`),_(e,`dist`,`src`,`internal`,`workflow-bundle`,`workflow-core-shim.js`)]):F([_(e,`.generated`,`compiled`,r),_(e,`dist`,`src`,`compiled`,r)]);let i=n.match(/^#(.+)\.js$/)?.[1];if(i!==void 0)return F([`.ts`,`.tsx`,`.mts`,`.cts`,`.js`,`.jsx`,`.mjs`,`.cjs`].flatMap(t=>[_(e,`src`,`${i}${t}`),_(e,`dist`,`src`,`${i}${t}`)]))}}}function vt(e){let t=new Set(e.sideEffectFiles?.map(e=>e.replaceAll(`\\`,`/`))??[]);return{name:`ash-workflow-transform`,async load(n){if(!Dt(n))return;let r=await S(n,`utf8`),i=await A(Et(e.workingDir,n),r.replace(/require\(\s*(['"])server-only\1\s*\)/g,`void 0`).replace(/require\(\s*(['"])client-only\1\s*\)/g,`void 0`),e.mode??`workflow`,n,e.projectRoot);return Tt(e.manifest,i.workflowManifest),{code:i.code,map:null,moduleSideEffects:t.has(n.replaceAll(`\\`,`/`))||void 0}}}}async function yt(e){let t=`// biome-ignore-all lint: generated file
|
|
6
|
+
/* eslint-disable */
|
|
7
|
+
import { workflowEntrypoint } from 'workflow/runtime';
|
|
8
|
+
|
|
9
|
+
const workflowCode = \`${(e.code.endsWith(`
|
|
10
|
+
`)?e.code:`${e.code}\n`).replace(/[\\`$]/g,`\\$&`)}\`;
|
|
11
|
+
|
|
12
|
+
export const POST = workflowEntrypoint(workflowCode);`;if(!e.bundleFinalOutput){await wt(e.outfile,t);return}let n=c(await u({cwd:e.workingDir,input:lt,external:e=>e===`@aws-sdk/credential-provider-web-identity`,platform:`node`,plugins:[ht(t)],write:!1,output:{comments:!1,format:e.format,sourcemap:!1}}),`final workflow bundle for "${e.outfile}"`);await wt(e.outfile,n.code)}function bt(e){let t={};for(let[n,r]of Object.entries(e??{})){t[n]={};for(let[e,i]of Object.entries(r))t[n][e]={stepId:i.stepId}}return t}function xt(e){let t={};for(let[n,r]of Object.entries(e??{})){t[n]={};for(let[e,i]of Object.entries(r))t[n][e]={graph:{edges:[],nodes:[]},workflowId:i.workflowId}}return t}function St(e){let t={};for(let[n,r]of Object.entries(e??{})){t[n]={};for(let[e,i]of Object.entries(r))t[n][e]={classId:i.classId}}return t}function Ct(e,t){let n=v(e,t).replaceAll(`\\`,`/`);return n.startsWith(`./`)||n.startsWith(`../`)?n:`./${n}`}function F(e){for(let t of e)if(ve(t))return{id:y(t)}}async function wt(e,t){await x(g(e),{recursive:!0});let n=`${e}.${process.pid}.${Date.now()}.tmp`;await T(n,t),await C(n,e)}function Tt(e,t){e.steps=I(e.steps,t.steps),e.workflows=I(e.workflows,t.workflows),e.classes=I(e.classes,t.classes)}function I(e,t){if(t===void 0)return e;let n={...e};for(let[e,r]of Object.entries(t))n[e]={...n[e],...r};return n}function Et(e,t){let n=t.replaceAll(`\\`,`/`),r=v(e.replaceAll(`\\`,`/`),n).replaceAll(`\\`,`/`);return r.startsWith(`../`)&&(r=r.split(`/`).filter(e=>e!==`..`).join(`/`)),r}function Dt(e){return/\.(?:[cm]?[jt]sx?)$/.test(e)}async function L(e,t){let n=`${e}.tmp-${process.pid}-${Date.now().toString(36)}`;await T(n,t),await Ot(n,e)}async function Ot(e,t){if(process.platform!==`win32`){await C(e,t);return}for(let n=0;n<10;n+=1)try{await C(e,t);return}catch(e){if(!(e instanceof Error&&`code`in e&&(e.code===`EPERM`||e.code===`EACCES`||e.code===`EBUSY`))||n===9)throw e;await new Promise(e=>setTimeout(e,10*(n+1)))}}async function kt(e){let t=[...e.discoveredEntries.discoveredSteps].sort(),n=new Set(t),r=[...e.discoveredEntries.discoveredSerdeFiles].sort().filter(e=>!n.has(e)),i=await jt({projectRoot:e.projectRoot,stepFiles:t,serdeOnlyFiles:r,workingDir:e.workingDir}),a=g(e.outfile),o=[`// Generated by Ash. Do not edit by hand.`,...At({builtinsImportSpecifier:e.builtinsPath===void 0?`workflow/internal/builtins`:R({outfileDirectory:a,preferAbsoluteFileImports:e.preferAbsoluteFileImports??!1,targetPath:e.builtinsPath}),outfileDirectory:a,preferAbsoluteFileImports:e.preferAbsoluteFileImports??!1,serdeOnlyFiles:r,stepFiles:t}),`export const __steps_registered = true;`,``].join(`
|
|
13
|
+
`);return await x(a,{recursive:!0}),await Ft(e.outfile)!==o&&await T(e.outfile,o),i}function At(e){return[e.builtinsImportSpecifier,...e.stepFiles.map(t=>R({outfileDirectory:e.outfileDirectory,preferAbsoluteFileImports:e.preferAbsoluteFileImports,targetPath:t})),...e.serdeOnlyFiles.map(t=>R({outfileDirectory:e.outfileDirectory,preferAbsoluteFileImports:e.preferAbsoluteFileImports,targetPath:t}))].map(e=>`import ${JSON.stringify(e)};`)}function R(e){return e.preferAbsoluteFileImports?o(e.targetPath):Pt(e.outfileDirectory,e.targetPath)}async function jt(e){let t={},n=[...e.stepFiles,...e.serdeOnlyFiles];for(let r of n){let n=await S(r,`utf8`);Mt(t,(await A(Nt(e.workingDir,r),n,`step`,r,e.projectRoot)).workflowManifest)}return t}function Mt(e,t){e.steps=z(e.steps,t.steps),e.workflows=z(e.workflows,t.workflows),e.classes=z(e.classes,t.classes)}function z(e,t){if(t===void 0)return e;let n={...e};for(let[e,r]of Object.entries(t))n[e]={...n[e],...r};return n}function Nt(e,t){let n=t.replaceAll(`\\`,`/`),r=v(e.replaceAll(`\\`,`/`),n).replaceAll(`\\`,`/`);return r.startsWith(`../`)&&(r=r.split(`/`).filter(e=>e!==`..`).join(`/`)),r}function Pt(e,t){let n=v(e,t).replaceAll(`\\`,`/`);return n.startsWith(`.`)?n:`./${n}`}async function Ft(e){try{return await S(e,`utf8`)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return null;throw e}}const It=`index.__ash_service_route_prefix.mjs`,Lt=[`ash/`,`.well-known/workflow/`];function B(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Rt(e){return Lt.some(t=>e.startsWith(t))}function zt(e,t){return e.filter(Bt).map(e=>Ht(e,t))}function Bt(e){if(!B(e)||`handle`in e)return!0;let t=typeof e.src==`string`?e.src:``,n=typeof e.dest==`string`?e.dest:``;return V(t)||V(n)}function V(e){return e.includes(`/ash/v1`)||e.includes(`/.well-known/workflow/`)}function Vt(e){return e.includes(`/ash/v1`)}function Ht(e,t){if(!B(e)||`handle`in e||typeof e.src!=`string`)return e;let n=Vt(e.src)||typeof e.dest==`string`&&Vt(e.dest),r={...e,src:Ut(e.src,t)};return n&&(r.dest=`/ash/__server`),r}function Ut(e,t){if(t===void 0||t===`/`||!V(e)||e.includes(t))return e;let n=t.endsWith(`/`)?t.slice(0,-1):t,r=n.replaceAll(`/`,`\\/`);return e.includes(r)?e:e.startsWith(`^(?:/`)?`^(?:${n}${e.slice(4)}`:e.startsWith(`^/`)?`^${n}${e.slice(1)}`:e.startsWith(`/`)?`${n}${e}`:e}async function Wt(e,t){let n=_(e,`.vc-config.json`),r=_(e,It),i=JSON.parse(await S(n,`utf8`)),a=B(i)?i:{};await T(r,Gt(t)),await T(n,`${JSON.stringify({...a,handler:It},null,2)}\n`)}function Gt(e){return`
|
|
14
|
+
import { Server } from "node:http";
|
|
15
|
+
|
|
16
|
+
const SERVICE_PREFIX = ${JSON.stringify(Kt(e))};
|
|
17
|
+
const PATCH_SYMBOL = Symbol.for("ash.service.route-prefix-strip.patch");
|
|
18
|
+
|
|
19
|
+
function stripServiceRoutePrefix(requestUrl) {
|
|
20
|
+
if (typeof requestUrl !== "string" || requestUrl === "*") {
|
|
21
|
+
return requestUrl;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const queryIndex = requestUrl.indexOf("?");
|
|
25
|
+
const rawPath = queryIndex === -1 ? requestUrl : requestUrl.slice(0, queryIndex);
|
|
26
|
+
const query = queryIndex === -1 ? "" : requestUrl.slice(queryIndex);
|
|
27
|
+
const path = rawPath.startsWith("/") ? rawPath : \`/\${rawPath}\`;
|
|
28
|
+
|
|
29
|
+
if (path === SERVICE_PREFIX) {
|
|
30
|
+
return \`/\${query}\`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (path.startsWith(\`\${SERVICE_PREFIX}/\`)) {
|
|
34
|
+
return path.slice(SERVICE_PREFIX.length) + query;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return path + query;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!globalThis[PATCH_SYMBOL]) {
|
|
41
|
+
globalThis[PATCH_SYMBOL] = true;
|
|
42
|
+
const originalEmit = Server.prototype.emit;
|
|
43
|
+
Server.prototype.emit = function patchedEmit(event, request, ...args) {
|
|
44
|
+
if (event === "request" && request && typeof request.url === "string") {
|
|
45
|
+
request.url = stripServiceRoutePrefix(request.url);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return originalEmit.call(this, event, request, ...args);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const originalModule = await import("./index.mjs");
|
|
53
|
+
const entrypoint = originalModule?.default ?? originalModule;
|
|
54
|
+
|
|
55
|
+
export default entrypoint;
|
|
56
|
+
`.trimStart()}function Kt(e){let t=(e.startsWith(`/`)?e:`/${e}`).replace(/\/+$/,``);return t.length===0?`/`:t}const qt=[`@mongodb-js/zstd`,`node-liblzma`],Jt=[`@chat-adapter/slack`,`chat`];function Yt(e){let t={};return Xt(e)&&Object.assign(t,e),t.NODE_OPTIONS=`--experimental-require-module`,t}function Xt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}async function Zt(e){await w(e,{force:!0,recursive:!0}),await x(e,{recursive:!0})}async function Qt(e){try{return await he(e.sourcePath)}catch{return await he(e.fallbackPath)}}async function $t(e){let t=await Qt({fallbackPath:e.fallbackPath,sourcePath:e.sourcePath});await Zt(e.targetPath),await b(t,e.targetPath,{dereference:!0,recursive:!0})}async function en(e,t={}){let n=_(e,`functions`),r=await tn(n);r!==null&&(t.servicePrefix!==void 0&&await Wt(r,t.servicePrefix),await nn(n,r)),await an(n,n),await on(e,t.servicePrefix)}async function tn(e){let t=_(e,`__server.func`),n=_(e,`ash/__server.func`),r;try{r=await he(t)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return null;throw e}let i=`${n}.ash-staging`;return await x(g(n),{recursive:!0}),await w(i,{force:!0,recursive:!0}),await b(r,i,{dereference:!0,recursive:!0}),await w(n,{force:!0,recursive:!0}),await C(i,n),n}async function nn(e,t,n=e){let r;try{r=await me(e,{withFileTypes:!0})}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}await Promise.all(r.map(async r=>{let i=_(e,r.name),a=H(v(n,i));if(r.isSymbolicLink()){r.name.endsWith(`.func`)&&Rt(a)&&await rn(i,t);return}r.isDirectory()&&!r.name.endsWith(`.func`)&&await nn(i,t,n)}))}async function rn(e,t){await w(e,{force:!0,recursive:!0}),await ge(H(v(g(e),t)),e,`dir`)}async function an(e,t){let n;try{n=await me(t,{withFileTypes:!0})}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}await Promise.all(n.map(async n=>{let r=_(t,n.name),i=H(v(e,r));if(n.name.endsWith(`.func`)){Rt(i)||await w(r,{force:!0,recursive:!0});return}n.isDirectory()&&await an(e,r)}))}async function on(e,t){let n=_(e,`config.json`),r;try{r=JSON.parse(await S(n,`utf8`))}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}!Xt(r)||!Array.isArray(r.routes)||(r.routes=zt(r.routes,t),await T(n,`${JSON.stringify(r,null,2)}\n`))}function H(e){return e.replaceAll(`\\`,`/`)}function sn(e){let t=v(e.fromDirectoryPath,e.toFilePath).replaceAll(`\\`,`/`);return t.startsWith(`.`)?t:`./${t}`}function cn(e){return[`import nitroHandler from ${JSON.stringify(e.delegateImportPath)};`,``,`function invokeNitroHandler(request, context) {`,` if (typeof nitroHandler === "function") {`,` return nitroHandler(request, context);`,` }`,``,` if (nitroHandler !== null && typeof nitroHandler === "object" && "fetch" in nitroHandler) {`,` const fetch = nitroHandler.fetch;`,` if (typeof fetch === "function") {`,` return fetch.call(nitroHandler, request, context);`,` }`,` }`,``,` throw new TypeError("Expected Nitro handler to export a function or an object with fetch(request, context).");`,`}`,``,`const workflowRoutePath = ${JSON.stringify(e.workflowRoutePath)};`,``,`function rewriteRequestToWorkflowRoute(request) {`,` const sourceUrl = new URL(request.url);`,` const routedUrl = new URL(workflowRoutePath, sourceUrl);`,` routedUrl.search = sourceUrl.search;`,` return new Request(routedUrl, request);`,`}`,``,`export default {`,` fetch(request, context) {`,` return invokeNitroHandler(rewriteRequestToWorkflowRoute(request), context);`,` },`,`};`,``].join(`
|
|
57
|
+
`)}async function ln(e){try{let t=JSON.parse(await S(_(e,`.vc-config.json`),`utf8`));if(typeof t.handler==`string`&&t.handler.length>0)return t.handler}catch{}return`index.mjs`}async function un(e){let t=await ln(e.functionDirectoryPath),n=_(e.functionDirectoryPath,t),r=g(n),i=de(t),a=_(r,`__ash_nitro_handler__${i.length>0?i:`.mjs`}`),o=sn({fromDirectoryPath:r,toFilePath:a});await C(n,a),await T(n,cn({delegateImportPath:o,workflowRoutePath:e.workflowRoutePath}))}const dn=new Map;var fn=class{#e;#t;config;#n=new WeakMap;constructor(e){this.config={buildTarget:`standalone`,dirs:[te(`src/execution`)],externalPackages:[...qt,...Jt],projectRoot:e.appRoot,watch:e.watch,workingDir:e.rootDir},this.#e=e.compiledArtifactsBootstrapPath,this.#t=e.outDir}async build(e={}){let t=(dn.get(this.#t)??Promise.resolve()).then(()=>this.#r(e));dn.set(this.#t,t.catch(()=>{})),await t}async#r(e){await E(this.#t);let t=await this.#i();if(t.length===0)throw Error(`Expected the execution workflow source file under "${te(`src/execution`)}".`);let n=await this.findTsConfigPath();await x(this.#t,{recursive:!0});let r=await this.discoverEntries(t,this.#t,n),i=_(this.#t,`workflows.mjs`),{manifest:a}=await this.createWorkflowsBundle({discoveredEntries:r,keepInterimBundleContext:!1,outfile:i,bundleFinalOutput:!1,format:`esm`,inputFiles:t,tsconfigPath:n}),o=_(this.#t,`steps.mjs`),s=await kt({builtinsPath:d(`workflow/internal/builtins`),discoveredEntries:r,outfile:o,preferAbsoluteFileImports:!0,projectRoot:this.config.projectRoot??this.config.workingDir,workingDir:this.config.workingDir}),c=e.nitroStepOutfile;c!==void 0&&c!==o&&await kt({builtinsPath:d(`workflow/internal/builtins`),discoveredEntries:r,outfile:c,preferAbsoluteFileImports:!0,projectRoot:this.config.projectRoot??this.config.workingDir,workingDir:this.config.workingDir}),await pn(i,o),await mn(i),await hn(i);let l=e.nitroWorkflowOutfile;l!==void 0&&l!==i&&(await x(g(l),{recursive:!0}),await Sn(i,l),c!==void 0&&(await pn(l,c),await mn(l),await hn(l))),await this.createManifest({workflowBundlePath:_(this.#t,`workflows.mjs`),manifestDir:this.#t,manifest:{steps:{...s.steps,...a.steps},workflows:{...s.workflows,...a.workflows},classes:{...s.classes,...a.classes}}}),await D(this.#t)}get transformProjectRoot(){return this.config.projectRoot??this.config.workingDir}async findTsConfigPath(){let e=this.config.workingDir;for(;;){for(let t of[`tsconfig.json`,`jsconfig.json`]){let n=_(e,t);try{return await S(n),n}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`ENOENT`))throw e}}let t=g(e);if(t===e)return;e=t}}async getInputFiles(){let e=this.config.dirs.map(e=>y(this.config.workingDir,e));return(await Promise.all(e.map(e=>pt(e)))).flat()}async discoverEntries(e,t,n){let r=this.#n.get(e);if(r!==void 0)return r;let i={discoveredSerdeFiles:[],discoveredSteps:[],discoveredWorkflows:[]};for(let t of e){let e=$e(await S(t,`utf8`));e.hasUseStep&&i.discoveredSteps.push(t),e.hasUseWorkflow&&i.discoveredWorkflows.push(t),e.hasSerde&&i.discoveredSerdeFiles.push(t)}return this.#n.set(e,i),i}async createWorkflowsBundle({bundleFinalOutput:e=!0,discoveredEntries:t,format:n=`cjs`,inputFiles:r,keepInterimBundleContext:i=this.config.watch,outfile:a,tsconfigPath:o}){let s=t??await this.discoverEntries(r,g(a),o),l=[...s.discoveredWorkflows].sort(),d=new Set(l),f=[...s.discoveredSerdeFiles].sort().filter(e=>!d.has(e)),p={},ee=[...l.map(e=>mt(e,this.config.workingDir)),...f.map(e=>mt(e,this.config.workingDir))].join(`
|
|
58
|
+
`);return await yt({bundleFinalOutput:e,code:c(await u({cwd:this.config.workingDir,input:lt,platform:`neutral`,plugins:[ht(ee),gt(),_t(this.config.workingDir,{workflowCondition:!0}),vt({manifest:p,projectRoot:this.transformProjectRoot,sideEffectFiles:[...l,...f],workingDir:this.config.workingDir})],resolve:{conditionNames:[`ash-source`,`workflow`,`node`,`import`,`default`],extensions:[`.ts`,`.tsx`,`.mts`,`.cts`,`.js`,`.jsx`,`.mjs`,`.cjs`],mainFields:[`module`,`main`]},tsconfig:o??!1,write:!1,output:{banner:`globalThis.__private_workflows = new Map();`,codeSplitting:!1,comments:!1,format:`cjs`,sourcemap:`inline`}}),`intermediate workflow bundle for "${a}"`).code,format:n,outfile:a,workingDir:this.config.workingDir}),i?{bundleFinal:async t=>{await yt({bundleFinalOutput:e,code:t,format:n,outfile:a,workingDir:this.config.workingDir})},interimBundleCtx:void 0,manifest:p}:{manifest:p}}async createManifest({manifest:e,manifestDir:t}){let n={version:`1.0.0`,steps:bt(e.steps),workflows:xt(e.workflows),classes:St(e.classes)},r=JSON.stringify(n,null,2);return await x(t,{recursive:!0}),await T(_(t,`manifest.json`),r),r}async buildVercelOutput(e){await this.build();let t=_(this.#t,`vercel-build-output`,`functions`,`.well-known`,`workflow`,`v1`),n=_(t,`flow.func`),r=_(e.outputDir,`functions`,`.well-known`,`workflow`,`v1`),i=_(e.flowNitroOutputDir,`functions`,`__server.func`),a=_(e.flowNitroOutputDir,`functions`,`.well-known`,`workflow`,`v1`,`flow.func`),o=_(r,`flow.func`),s=_(r,`step.func`),c=_(r,`webhook`,`[token].func`);await $t({fallbackPath:i,sourcePath:a,targetPath:n}),await Promise.all([this.#a(n,{experimentalTriggers:Array.from([Ze]),maxDuration:`max`,runtime:e.runtime??null,shouldAddHelpers:!1}),b(_(this.#t,`manifest.json`),_(t,`manifest.json`))]),await un({functionDirectoryPath:n,workflowRoutePath:`/.well-known/workflow/v1/flow`}),await Promise.all([w(o,{force:!0,recursive:!0}),w(s,{force:!0,recursive:!0}),w(c,{force:!0,recursive:!0})]),await x(r,{recursive:!0}),await Promise.all([b(n,o,{recursive:!0}),b(_(t,`manifest.json`),_(r,`manifest.json`))])}async#i(){return[...await this.getInputFiles(),this.#e]}async#a(e,t){let n=_(e,`.vc-config.json`),r=await this.#o(n),i={...r};i.environment=Yt(r.environment),t.runtime!==null&&(i.runtime=t.runtime),t.maxDuration!==void 0&&(i.maxDuration=t.maxDuration),t.shouldAddHelpers!==void 0&&(i.shouldAddHelpers=t.shouldAddHelpers),t.shouldAddSourcemapSupport!==void 0&&(i.shouldAddSourcemapSupport=t.shouldAddSourcemapSupport),t.experimentalTriggers!==void 0&&(i.experimentalTriggers=[...t.experimentalTriggers]),await T(n,`${JSON.stringify(i,null,2)}\n`)}async#o(e){try{let t=JSON.parse(await S(e,`utf8`));if(typeof t==`object`&&t)return t}catch{}return{}}};async function pn(e,t){let n=await U(e);if(n===null||n.includes(`__ashWorkflowStepsRegistered`))return;let r=bn(g(e),t),i=[`import { __steps_registered as __ashWorkflowStepsRegistered } from ${JSON.stringify(r)};`,`void __ashWorkflowStepsRegistered;`,``].join(`
|
|
59
|
+
`),a=n.match(/^import\s.+?;\n/m);if(a===null||a.index===void 0){await L(e,`${i}${n}`);return}let o=a.index+a[0].length;await L(e,`${n.slice(0,o)}${i}${n.slice(o)}`)}async function mn(e){let t=await U(e);if(t===null)return;let n=t;for(let e of[`workflow`,`workflow/api`,`workflow/internal/builtins`,`workflow/internal/private`,`workflow/runtime`]){let t=yn(d(e));n=vn(n,e,t)}n!==t&&await L(e,n)}async function hn(e){let t=await U(e);if(t===null)return;let n=t.indexOf(`const workflowCode = `),r=t.lastIndexOf(`;
|
|
60
|
+
|
|
61
|
+
export const POST = workflowEntrypoint(workflowCode);`);if(n===-1||r===-1||r<=n)return;let i=n+21,a=t.slice(i,r);if(!a.trimStart().startsWith("`"))return;let o=_n(a,e),s=`${t.slice(0,i)}${gn(o)}${t.slice(r)}`;s!==t&&await L(e,s)}function gn(e){let t=xe.from(e,`utf8`).toString(`base64`).match(/.{1,16384}/g)??[``];return`Buffer.from(${JSON.stringify(t)}.join(""), "base64").toString("utf8")`}function _n(e,t){let n=e.trim();if(!n.startsWith("`")||!n.endsWith("`"))throw Error(`Expected generated workflow code literal in "${t}" to be a template.`);let r=n.slice(1,-1),i=``;for(let e=0;e<r.length;e+=1){let t=r[e];if(t!==`\\`){i+=t;continue}let n=r[e+1];if(n===`\\`||n==="`"||n===`$`){i+=n,e+=1;continue}i+=t}return i}function vn(e,t,n){return e.replaceAll(JSON.stringify(t),JSON.stringify(n)).replaceAll(`'${t}'`,JSON.stringify(n))}function yn(e){return o(e)}function bn(e,t){let n=v(e,t).replaceAll(`\\`,`/`);return n.startsWith(`.`)?n:`./${n}`}async function U(e){try{return await S(e,`utf8`)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return null;throw e}}async function xn(e){try{return await S(e)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return null;throw e}}async function Sn(e,t){let n=await S(e),r=await xn(t);r!==null&&r.equals(n)||await L(t,n)}const Cn=`\0ash-pruned-local-sandbox-backend`,wn=/[/\\]bindings[/\\]local\.js$/;function Tn(){return{name:`ash-hosted-sandbox-backend-prune`,load(e){return e===Cn?[`export function createLocalSandboxBackend() {`,` throw new Error("The local sandbox backend is pruned from hosted server bundles.");`,`}`,``].join(`
|
|
62
|
+
`):null},resolveId(e){return wn.test(e)?Cn:null}}}const En=`${h}/runs`,Dn=`${h}/runs/:runId`,On=`${h}/runs/:runId/steps`,kn=`${h}/runs/:runId/events`;function An(e){return e===`all`||e===`app`}function jn(e){return W(e)}function W(e){return e===`all`||e===`flow`}function G(e,n){let r=`#ash-route-handler/${n.method??`ALL`} ${n.route}`,i=t(n.handlerPath);e.options.handlers.push({handler:r,method:n.method,route:n.route}),e.options.virtual[r]=[`import handler from ${i};`,`export default handler;`].join(`
|
|
63
|
+
`)}function K(e){return _(e.options.buildDir,`workflow`)}function Mn(e,t){let n=v(e,t).replaceAll(`\\`,`/`);return n.startsWith(`.`)?n:`./${n}`}async function Nn(e,t){let n=_(K(e),`${t.bundleName}-handler.mjs`),r=g(n),i=Mn(r,t.bundlePath),a=(t.directHandlers??[]).map(e=>{let t=Mn(r,e.bundlePath);return{importSpecifier:t,isOwnBundle:t===i,queuePrefix:e.queuePrefix}});await x(r,{recursive:!0}),await T(n,Pn({bundlePath:i,directHandlers:a,runtimeImportSpecifier:t.runtimeImportSpecifier})),e.options.handlers.push({handler:n,route:t.route})}function Pn(e){let t=[`// Generated by Ash. Do not edit by hand.`,`import { POST } from ${JSON.stringify(e.bundlePath)};`];if(e.directHandlers.length>0&&e.runtimeImportSpecifier!==void 0){let n=0,r=e.directHandlers.map(e=>{if(e.isOwnBundle)return{...e,binding:`POST`};let t=`__ashWorkflowDirectHandler${n}`;return n+=1,{...e,binding:t}});for(let e of r)e.isOwnBundle||t.push(`import { POST as ${e.binding} } from ${JSON.stringify(e.importSpecifier)};`);t.push(`import { getWorld as __ashGetWorkflowWorld } from ${JSON.stringify(e.runtimeImportSpecifier)};`,``,`try {`,` const __ashWorkflowWorld = await __ashGetWorkflowWorld();`,` if (typeof __ashWorkflowWorld?.registerHandler === "function") {`);for(let e of r)t.push(` __ashWorkflowWorld.registerHandler(${JSON.stringify(e.queuePrefix)}, ${e.binding});`);t.push(` }`,`} catch (err) {`,` console.warn("[ash] Failed to register direct workflow queue handlers:", err);`,`}`)}return t.push(``,`export default async ({ req }) => {`,` return await POST(req);`,`};`,``),t.join(`
|
|
64
|
+
`)}function Fn(e,n){let r=`#ash-route${n.route}`,i=t(n.modulePath);e.options.handlers.push({handler:r,method:n.method,route:n.route}),e.options.virtual[r]=[`import { ${n.handlerExport} } from ${i};`,`export default async (event) => ${n.handlerExport}(${n.args}, event.req);`].join(`
|
|
65
|
+
`)}async function In(e,t,n){if(jn(n.surface)){let r=p(),i=new fn({appRoot:t.appRoot,compiledArtifactsBootstrapPath:t.compiledArtifacts.bootstrapPath,outDir:t.workflowBuildDir,rootDir:r,watch:e.options.dev}),a=Promise.resolve(),o=async()=>{await i.build({nitroStepOutfile:W(n.surface)?_(K(e),`steps.mjs`):void 0,nitroWorkflowOutfile:e.options.dev&&W(n.surface)?_(K(e),`workflows.mjs`):void 0})},s=async()=>{let e=a.then(o);a=e.catch(()=>{}),await e},c=!0;await s(),e.hooks.hook(`build:before`,async()=>{if(c){c=!1;return}await s()}),e.options.dev&&e.hooks.hook(`dev:reload`,async()=>{await s()})}let r=ae({appRoot:t.appRoot,dev:e.options.dev});An(n.surface)&&(G(e,{handlerPath:f(`src/internal/nitro/routes/index.ts`),method:`GET`,route:`/`}),G(e,{handlerPath:f(`src/internal/nitro/routes/health.ts`),method:`GET`,route:re}),Fn(e,{args:JSON.stringify({appRoot:r.appRoot}),handlerExport:`handleAgentInfoRequest`,method:`GET`,modulePath:f(`src/internal/nitro/routes/info.ts`),route:ne}),G(e,{handlerPath:f(`src/internal/nitro/routes/workflow-runs.ts`),method:`GET`,route:En}),G(e,{handlerPath:f(`src/internal/nitro/routes/workflow-run.ts`),method:`GET`,route:Dn}),G(e,{handlerPath:f(`src/internal/nitro/routes/workflow-run-steps.ts`),method:`GET`,route:On}),G(e,{handlerPath:f(`src/internal/nitro/routes/workflow-run-events.ts`),method:`GET`,route:kn}),se(e,{artifactsConfig:r,registrations:ie(t)}));let i=K(e),a=W(n.surface)?e.options.dev?_(i,`workflows.mjs`):_(t.workflowBuildDir,`workflows.mjs`):void 0,s=e.options.dev&&a!==void 0?[{bundlePath:a,queuePrefix:`__wkf_workflow_`}]:[],c=s.length>0?o(d(`workflow/runtime`)):void 0;a&&await Nn(e,{bundleName:`workflows`,bundlePath:a,directHandlers:s,route:`/.well-known/workflow/v1/flow`,runtimeImportSpecifier:c}),e.routing.sync()}function Ln(){return`${h}/cron/${_e()}`}function Rn(e){e.options.vercel!==void 0&&(e.options.vercel.cronHandlerRoute=Ln())}function zn(e){return{plugins:[l(),...e]}}function Bn(e){e.hooks.hook(`rollup:before`,(e,t)=>{Array.isArray(t.plugins)&&t.plugins.unshift({name:`ash:nitro-routing-import-specifiers`,transform(e,t){if(t!==`#nitro/virtual/routing`&&t!==`#nitro/virtual/routing-meta`)return null;let r=n(e);return r===e?null:{code:r,map:null}}})})}const Vn=`@alinea/generated.@appsignal/nodejs.@aws-sdk/client-s3.@aws-sdk/s3-presigned-post.@blockfrost/blockfrost-js.@highlight-run/node.@huggingface/transformers.@jpg-store/lucid-cardano.@libsql/client.@mikro-orm/core.@mikro-orm/knex.@node-rs/argon2.@node-rs/bcrypt.@prisma/client.@react-pdf/renderer.@sentry/profiling-node.@sparticuz/chromium.@sparticuz/chromium-min.@statsig/statsig-node-core.@swc/core.@xenova/transformers.@zenstackhq/runtime.argon2.autoprefixer.aws-crt.bcrypt.better-sqlite3.canvas.chromadb-default-embed.config.cpu-features.cypress.dd-trace.eslint.express.firebase-admin.htmlrewriter.import-in-the-middle.isolated-vm.jest.jsdom.keyv.libsql.mdx-bundler.mongodb.mongoose.newrelic.next-mdx-remote.next-seo.node-cron.node-pty.node-web-audio-api.onnxruntime-node.oslo.pg.pino.pino-pretty.pino-roll.playwright.playwright-core.postcss.prettier.prisma.puppeteer.puppeteer-core.ravendb.require-in-the-middle.rimraf.sharp.shiki.sqlite3.thread-stream.ts-morph.ts-node.typescript.vscode-oniguruma.webpack.websocket.zeromq`.split(`.`);function Hn(e){if(e)return{config:{version:3,framework:{version:m().version}}}}const Un=[`workflow`,`workflow/api`,`workflow/errors`,`workflow/internal/builtins`,`workflow/internal/private`,`workflow/runtime`],Wn=Symbol(`ash.workflow-transform-patched`),Gn=[`@napi-rs/keyring`];function Kn(){let e={};for(let t of Un)e[t]=d(t);return e}function qn(e){if(!e&&process.env.VERCEL)return`vercel`}function Jn(e){return e===`all`||e===`app`}function Yn(e){return e===`all`||e===`flow`}function Xn(e){return Yn(e)}function Zn(e,t){return e.options.dev?_(e.options.buildDir,`workflow`,`steps.mjs`):_(t.workflowBuildDir,`steps.mjs`)}function Qn(e){let t=e.compileResult.manifest.config.build;return[...new Set([...Gn,...Vn,...t?.externalDependencies??[]])].filter(e=>e!==ee)}function q(e){return e.replaceAll(`\\`,`/`)}function $n(e){let t=e.indexOf(`?`),n=e.indexOf(`#`),r=t===-1?n:n===-1?t:Math.min(t,n);return r===-1?e:e.slice(0,r)}function J(e){return e.startsWith(`/@fs/`)?e.slice(4):e}function Y(e,t){return t.startsWith(`file://`)?q(J($n(be(t)))):fe(t)?q(J($n(t))):q(J($n(y(e,t))))}function er(e,t){let n=q(e);return n.startsWith(t)||n.includes(`/.ash/workflow-cache/`)}function tr(e){let t=q(e);return process.platform===`win32`?t.toLowerCase():t}function nr(e){let t=/^\s*import\s+(?:.+?\s+from\s+)?["']([^"']+)["'];?\s*$/gm,n=[];for(let r of e.matchAll(t)){let e=r[1];e!==void 0&&n.push(e)}return n}function rr(e,t,n){return t.startsWith(`workflow`)?d(t):t.startsWith(`.`)||t.startsWith(`/`)||t.startsWith(`file://`)?Y(n===void 0?e:g(Y(e,n)),t):null}async function ir(e,t){let n=await S(e,`utf8`),r=new Set;for(let i of nr(n)){let n=rr(t,i,e);n!==null&&r.add(tr(n))}return r}async function ar(e,t){if(e.options.noExternals===!0)return;let n;try{n=await ir(t,e.options.rootDir)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}let r=Array.isArray(e.options.noExternals)?[...e.options.noExternals]:[];e.options.noExternals=[...new Set([...r,...n])]}function or(e,t){let n=q(e).replace(/\/$/,``),r=q(t),i=n.toLowerCase(),a=r.toLowerCase();if(a.startsWith(`${i}/`))return r.slice(n.length+1);if(a===i)return`.`;let o=v(n,r).replaceAll(`\\`,`/`);if(o.startsWith(`../`)&&(o=o.split(`/`).filter(e=>e!==`..`).join(`/`)),o.includes(`:`)||o.startsWith(`/`)){let e=r.split(`/`).pop();return e===void 0||e.length===0?`unknown.ts`:e}return o}function sr(e,t){let n=[t,_(e.options.buildDir,`workflow`)].map(t=>Y(e.options.rootDir,t));e.hooks.hook(`rollup:before`,(t,r)=>{Array.isArray(r.plugins)&&r.plugins.unshift({name:`ash:workflow-module-side-effects`,resolveId(t,r){let i=rr(e.options.rootDir,t,r)??Y(e.options.rootDir,t);return n.some(e=>er(i,e))?{id:i,moduleSideEffects:`no-treeshake`}:null}})})}function cr(e,t){let n=null,r=async()=>(n===null&&(n=await ir(t.stepEntrypointPath,e.options.rootDir)),n);e.hooks.hook(`build:before`,()=>{n=null}),e.options.dev&&e.hooks.hook(`dev:reload`,()=>{n=null}),e.hooks.hook(`rollup:before`,(t,n)=>{Array.isArray(n.plugins)&&n.plugins.unshift({name:`ash:workflow-step-module-side-effects`,async resolveId(t,n){let i=rr(e.options.rootDir,t,n);return i===null||!(await r()).has(tr(i))?null:{id:i,moduleSideEffects:`no-treeshake`}}})})}function lr(e,t){let n=null,r=async()=>(n===null&&(n=await ir(t.stepEntrypointPath,e.options.rootDir)),n);e.hooks.hook(`build:before`,()=>{n=null}),e.options.dev&&e.hooks.hook(`dev:reload`,()=>{n=null}),e.hooks.hook(`rollup:before`,(t,n)=>{Array.isArray(n.plugins)&&n.plugins.unshift({async transform(t,n){let i=await r(),a=Y(e.options.rootDir,n);return i.has(tr(a))?{code:(await A(or(e.options.rootDir,a),t,`step`,a,e.options.rootDir)).code,map:null}:null},name:`ash:workflow-step-transform`})})}function ur(e,t){let n=q(t);e.hooks.hook(`rollup:before`,(e,t)=>{Array.isArray(t.plugins)&&t.plugins.unshift({name:`ash:instrumentation-module-side-effects`,resolveId(e){return q(e)===n?{id:e,moduleSideEffects:`no-treeshake`}:null}})})}function dr(e,t){let n=q(t);e.hooks.hook(`rollup:before`,(e,t)=>{if(Array.isArray(t.plugins))for(let e of t.plugins){if(typeof e!=`object`||!e)continue;let t=e;if(t.name!==`workflow:transform`||t[Wn]===!0||typeof t.transform!=`function`)continue;let r=t.transform;t.transform=function(e,t,...i){return er(t,n)?null:r.call(this,e,t,...i)},t[Wn]=!0}})}async function X(e,t,n={}){let r=n.surface??`all`,i=(!t||n.schedules===!0)&&Jn(r)&&e.scheduleRegistrations.length>0,o=qn(t),s=o===`vercel`?Tn():null,c=s===null?[]:[s],l=zn(c),u=zn(c),d=Qn(e),p=a(e.appRoot,r),ee=e.compiledArtifacts.instrumentationPluginPath===void 0?[e.compiledArtifacts.bootstrapPath]:[e.compiledArtifacts.instrumentationPluginPath,e.compiledArtifacts.bootstrapPath];await E(p);let m=await Te({_cli:{command:t?`dev`:`build`},buildDir:p,dev:t,logLevel:t?1:void 0,output:n.outputDir===void 0?void 0:{dir:n.outputDir},preset:o,plugins:ee,publicAssets:[],scanDirs:Xn(r)?[te(`src/execution`)]:void 0,rolldownConfig:l,rollupConfig:u,rootDir:e.appRoot,serverDir:!1,traceDeps:d,vercel:Hn(o===`vercel`&&Jn(r))},t?{watch:!0}:void 0);if(await D(p),Bn(m),Yn(r)){let t=Kn();for(let[e,n]of Object.entries(t))m.options.alias[e]=n;sr(m,e.workflowBuildDir),dr(m,e.workflowBuildDir)}if(Xn(r)){let t=Zn(m,e);cr(m,{stepEntrypointPath:t}),lr(m,{stepEntrypointPath:t})}if(e.compiledArtifacts.instrumentationSourcePath!==void 0&&ur(m,e.compiledArtifacts.instrumentationSourcePath),t&&Yn(r)){let t=e.workflowBuildDir,n=new Set([q(_(t,`workflows.mjs`))]);m.hooks.hook(`rollup:before`,(e,t)=>{let r=t.external;t.external=(e,...t)=>{if(n.has(q(e)))return!0;if(typeof r==`function`)return r(e,...t)}})}return i&&(Rn(m),ce(m,{artifactsConfig:ae({appRoot:e.appRoot,dev:m.options.dev}),dispatchModulePath:f(`src/internal/nitro/routes/schedule-task.ts`),registrations:e.scheduleRegistrations})),await In(m,e,{surface:r}),Xn(r)&&await ar(m,Zn(m,e)),m}function fr(e){if(typeof e!=`string`||e.length===0)return`unknown`;let t=e.toLowerCase();return t===`slack`||t.includes(`slack`)?`slack`:t===`http`?`http`:t.includes(`webhook`)?`webhook`:`unknown`}function pr(e){let{manifest:t}=e;return{kind:`vercel-ash-agent-summary`,schemaVersion:2,generatorVersion:e.generatorVersion??m().version,agent:{name:t.config.name,description:t.config.description,modelId:t.config.model.id},instructions:t.instructions?gr(t.instructions):null,schedules:t.schedules.map(_r),tools:t.tools.map(vr),skills:t.skills.map(yr),connections:t.connections.map(br),channels:t.channels.filter(hr).map(xr),sandbox:t.sandbox===null?null:{logicalPath:t.sandbox.logicalPath},subagents:t.subagents.map(Sr),diagnostics:{errors:t.diagnosticsSummary.errors,warnings:t.diagnosticsSummary.warnings}}}async function mr(e){let t=pr({generatorVersion:e.generatorVersion,manifest:e.manifest}),n=_(e.appRoot,`.ash/agent-summary.json`);return await x(g(n),{recursive:!0}),await T(n,`${JSON.stringify(t,null,2)}\n`),n}function hr(e){return e.kind===`channel`}function gr(e){return{logicalPath:e.logicalPath,sourceKind:e.sourceKind,markdown:e.markdown}}function _r(e){return{name:e.name,cron:e.cron,logicalPath:e.logicalPath}}function vr(e){return{name:e.name,description:e.description,logicalPath:e.logicalPath}}function yr(e){return{name:e.name,description:e.description,logicalPath:e.logicalPath,sourceKind:e.sourceKind}}function br(e){let t={name:e.connectionName,description:e.description,url:e.url,logicalPath:e.logicalPath,type:`mcp`};return e.vercelConnect===void 0?t:{...t,vercelConnect:{connector:e.vercelConnect.connector}}}function xr(e){let t={name:e.name,method:e.method,urlPath:e.urlPath,type:fr(e.adapterKind),logicalPath:e.logicalPath};return e.adapterKind===void 0?t:{...t,adapterKind:e.adapterKind}}function Sr(e){return{name:e.name,description:e.description,logicalPath:e.logicalPath}}function Cr(){let e=process.env.VERCEL?.trim(),t=process.env.VERCEL_DEPLOYMENT_ID?.trim();return typeof e==`string`&&e.length>0&&typeof t==`string`&&t.length>0}async function wr(e){return Cr()?(await le(e),!0):!1}function Tr(e){return e.replace(/[\\/]+$/,``)}function Er(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Dr(e,t){return typeof t!=`string`||t.trim().length===0?null:y(e,t)}function Or(e){if(!Er(e.config)||!Er(e.config.experimentalServices))return;let t=!1,n;for(let r of Object.values(e.config.experimentalServices)){if(!Er(r))continue;if(r.framework===`nextjs`){t=!0;continue}if(r.framework!==`ash`)continue;let i=Dr(e.configRoot,r.entrypoint),a=typeof r.routePrefix==`string`?r.routePrefix.trim():``;i===e.appRoot&&a.length>0&&a!==`/`&&(n=a)}return t?n:void 0}async function kr(e){let t=e;for(;;){try{let n=_(t,`vercel.json`),r=JSON.parse(await S(n,`utf8`)),i=Or({appRoot:e,configRoot:t,config:r});if(i!==void 0)return i}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`ENOENT`))throw e}let n=g(t);if(n===t)return;t=n}}async function Ar(e){try{return JSON.parse(await S(_(e,`functions`,`__server.func`,`.vc-config.json`),`utf8`)).runtime}catch{return}}async function jr(e){let t=new fn({appRoot:e.appRoot,compiledArtifactsBootstrapPath:e.compiledArtifactsBootstrapPath,outDir:e.workflowBuildDir,rootDir:p(),watch:!1}),n=await Ar(e.outputDir);await t.buildVercelOutput({flowNitroOutputDir:e.flowNitroOutputDir,outputDir:e.outputDir,runtime:n})}async function Mr(e){let t=Tr(e.options.output.dir);return await E(t),await Ee(e),await Ce(e),await De(e),await Se(e),await D(t),t}async function Nr(e,t){let n=await X(e,!1,{outputDir:r(e.appRoot,t),surface:t});try{return await Mr(n)}finally{await n.close()}}async function Pr(e){let t=await oe(e);if(!process.env.VERCEL){let e=await X(t,!1);try{let n=await Mr(e);return await mr({manifest:t.compileResult.manifest,appRoot:t.appRoot}),n}finally{await e.close()}}let n=await X(t,!1,{surface:`app`});try{let e=await Mr(n);await wr({appRoot:t.appRoot,log(e){console.log(e)}});let r=await Nr(t,`flow`);await jr({appRoot:t.appRoot,compiledArtifactsBootstrapPath:t.compiledArtifacts.bootstrapPath,flowNitroOutputDir:r,outputDir:e,workflowBuildDir:t.workflowBuildDir});let i=await kr(t.appRoot);return i!==void 0&&await en(e,{servicePrefix:i}),await mr({manifest:t.compileResult.manifest,appRoot:t.appRoot}),e}finally{await n.close()}}const Z=65535,Q=`WORKFLOW_LOCAL_BASE_URL`,$=`PORT`,Fr=new Set([`[::]`,`::`,`0.0.0.0`]);function Ir(e){let t=new URL(e);return Fr.has(t.hostname)?(t.hostname=`127.0.0.1`,t.toString()):e}function Lr(e){return e instanceof Error&&`code`in e&&e.code===`EADDRINUSE`}function Rr(e){let t=typeof e==`string`?Number(e):e??3e3;if(!Number.isInteger(t)||t<0||t>Z)throw Error(`Invalid development server port "${String(e)}". Expected an integer between 0 and ${Z}.`);return t}function zr(){let e=process.env[$];if(e===void 0||e.trim()===``)return;let t=Number(e);if(!Number.isInteger(t)||t<0||t>Z)throw Error(`Invalid ${$} environment variable "${e}". Expected an integer between 0 and ${Z}.`);return t}function Br(e){let t=Rr(e.port);if(t===0||!e.retryOnAddressInUse)return[t];let n=[];for(let e=0;e<10;e+=1){let r=t+e;if(r>65535)break;n.push(r)}return n}function Vr(e){let t=process.env[Q],n=process.env[$],r=new URL(Ir(e));return process.env[Q]=r.origin,r.port&&(process.env[$]=r.port),()=>{t===void 0?delete process.env[Q]:process.env[Q]=t,n===void 0?delete process.env[$]:process.env[$]=n}}function Hr(e){let t=()=>{};return e.once(`error`,t),()=>{e.off(`error`,t)}}function Ur(e){let t=e.upgrade.bind(e);e.upgrade=async(e,n,r)=>{let i=Hr(n);try{await t(e,n,r)}catch{n.destroyed||n.destroy()}finally{i()}}}async function Wr(e){let t=Br({port:e.port,retryOnAddressInUse:e.retryOnAddressInUse}),n;for(let r of t){let t=e.devServer.listen({hostname:e.host,port:r,silent:!0});try{return await t.ready(),t}catch(r){if(n=r,await t.close().catch(()=>{}),!Lr(r)||!e.retryOnAddressInUse)throw r}}throw Error(`Failed to start Nitro dev server after ${t.length} attempts. Tried ports ${t.join(`, `)}.`,{cause:n})}async function Gr(e,t={}){let n=t.schedules===!0,r=await oe(e);await le({appRoot:r.appRoot,log:e=>console.log(e)});let i=await X(r,!0,{schedules:n}),a=we(i);Ur(a);let o=t.host??i.options.devServer.hostname,s=t.port??zr(),c=s??i.options.devServer.port,l=s===void 0,u;try{let e=await Wr({devServer:a,host:o,port:c,retryOnAddressInUse:l});if(!e.url)throw Error(`Nitro dev server did not expose a URL.`);u=Vr(e.url),await Ee(i),await Se(i);let{startAuthoredSourceWatcher:t}=await import(`./dev-authored-source-watcher-B4PaZGUr.js`),s=await t({nitro:i,preparedHost:r,schedulesEnabled:n}),d=u;if(d===void 0)throw Error(`Workflow local queue environment was not initialized.`);return{async close(){try{await s.close(),await a.close(),await i.close()}finally{d()}},url:Ir(e.url)}}catch(e){throw u?.(),await a.close().catch(()=>{}),await i.close().catch(()=>{}),e}}var Kr=e({buildHost:()=>qr,startHost:()=>Jr});async function qr(e){return await Pr(e)}async function Jr(e,t={}){return await Gr(e,t)}export{Jr as n,Kr as t};
|