@vite-hub/workflow 0.7.0 → 0.8.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/README.md +1 -1
- package/dist/{client-CPxPxsl5.js → client-T41cNf3k.js} +10 -21
- package/dist/{config-CwCwuZqv.js → config-G0z9jHLM.js} +5 -5
- package/dist/definition.d.ts +1 -1
- package/dist/{delay-JrpW40UF.js → delay-B4azP18B.js} +3 -3
- package/dist/durability.d.ts +1 -1
- package/dist/{execute-CLmIXnON.js → execute-zu08sWGG.js} +3 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{openworkflow-C65AWQSJ.d.ts → openworkflow-DHuxMJQB.d.ts} +2 -2
- package/dist/{openworkflow-BiwPTYEz.js → openworkflow-zD8luED5.js} +10 -13
- package/dist/{operations-DyaGK9zW.js → operations-C2XbDDDV.js} +3 -3
- package/dist/operations.d.ts +1 -1
- package/dist/operations.js +1 -1
- package/dist/{results-DBp_bmUP.d.ts → results-DqbEUMCH.d.ts} +1 -1
- package/dist/{run-error-8p4BtTMv.js → run-error-zZh1_IBo.js} +5 -21
- package/dist/runtime/cloudflare-concurrency.d.ts +1 -1
- package/dist/runtime/cloudflare-runner.d.ts +1 -1
- package/dist/runtime/cloudflare-runner.js +2 -2
- package/dist/runtime/cloudflare-vite.d.ts +1 -1
- package/dist/runtime/cloudflare-vite.js +1 -1
- package/dist/runtime/execute.d.ts +1 -1
- package/dist/runtime/execute.js +1 -1
- package/dist/runtime/openworkflow-worker.d.ts +2 -2
- package/dist/runtime/openworkflow-worker.js +4 -5
- package/dist/runtime/openworkflow.d.ts +1 -1
- package/dist/runtime/openworkflow.js +1 -1
- package/dist/runtime/state.d.ts +1 -1
- package/dist/runtime/vercel-vite.d.ts +1 -1
- package/dist/runtime/vercel-vite.js +1 -1
- package/dist/{types-CvyOEp0V.d.ts → types-DrhUXMsE.d.ts} +1 -0
- package/dist/{vercel-ADMH2MK8.js → vercel-DRezYOUp.js} +5 -5
- package/dist/vite.d.ts +2 -1
- package/dist/vite.js +425 -104
- package/package.json +3 -3
package/dist/vite.js
CHANGED
|
@@ -3,12 +3,12 @@ import { n as invariantError, t as invariant } from "./invariant-Dj2R1eMr.js";
|
|
|
3
3
|
import { workflowDurabilityUrl } from "./durability.js";
|
|
4
4
|
import { t as internalErrorDiagnostics } from "./error-diagnostics-CsiNo_oI.js";
|
|
5
5
|
import { n as isRecordOrFunction, t as isRecord } from "./object-CAK6UYR5.js";
|
|
6
|
-
import { n as getHostingProvider, r as normalizeHosting, t as normalizeWorkflowOptions } from "./config-
|
|
6
|
+
import { n as getHostingProvider, r as normalizeHosting, t as normalizeWorkflowOptions } from "./config-G0z9jHLM.js";
|
|
7
7
|
import { r as relativeDefinitionFile } from "./inspect-NBCAwsxi.js";
|
|
8
8
|
import { c as getCloudflareWorkflowClassName, l as getLegacyCloudflareWorkflowClassName, n as cloudflareConcurrencyClassName, o as createCloudflareWorkflowBindings, r as cloudflareConcurrencyMigrationTag, t as cloudflareConcurrencyBinding } from "./cloudflare-concurrency-counter-CDHHiMfn.js";
|
|
9
9
|
import { t as workflowErrorDiagnostics } from "./error-diagnostics-35AEmfve.js";
|
|
10
|
-
import { f as toStepPropertyName, i as resolveWorkflowStepOptions } from "./execute-
|
|
11
|
-
import { n as generatedNativeEntryKey, o as vercelNativeRegistryKey, r as generatedNativeRootStepKey, s as workflowStartAtKey } from "./delay-
|
|
10
|
+
import { f as toStepPropertyName, i as resolveWorkflowStepOptions } from "./execute-zu08sWGG.js";
|
|
11
|
+
import { n as generatedNativeEntryKey, o as vercelNativeRegistryKey, r as generatedNativeRootStepKey, s as workflowStartAtKey } from "./delay-B4azP18B.js";
|
|
12
12
|
import { t as defaultOpenWorkflowSqlitePath } from "./openworkflow-defaults-1n0DbLdb.js";
|
|
13
13
|
import { builtinModules, createRequire, isBuiltin } from "node:module";
|
|
14
14
|
import { dirname, normalize, relative, resolve } from "pathe";
|
|
@@ -3264,6 +3264,150 @@ async function copyRuntimePackageFiles(packageDir, targetDir) {
|
|
|
3264
3264
|
await unlessGone(() => copyFile(join(packageDir, path), target));
|
|
3265
3265
|
}
|
|
3266
3266
|
}
|
|
3267
|
+
// ../internal/src/source-files.ts
|
|
3268
|
+
const ignoredDirs = /* @__PURE__ */ new Set([
|
|
3269
|
+
"node_modules",
|
|
3270
|
+
"dist",
|
|
3271
|
+
".output",
|
|
3272
|
+
".nuxt",
|
|
3273
|
+
".vercel",
|
|
3274
|
+
".git",
|
|
3275
|
+
".vitehub"
|
|
3276
|
+
]);
|
|
3277
|
+
const racyWindowNs = 2000000000n;
|
|
3278
|
+
const storeKey = Symbol.for("vite-hub.source-files.v1");
|
|
3279
|
+
function store() {
|
|
3280
|
+
const existing = Reflect.get(globalThis, storeKey);
|
|
3281
|
+
if (isStore(existing)) return existing;
|
|
3282
|
+
const created = {
|
|
3283
|
+
derived: /* @__PURE__ */ new Map(),
|
|
3284
|
+
texts: /* @__PURE__ */ new Map(),
|
|
3285
|
+
trees: /* @__PURE__ */ new Map()
|
|
3286
|
+
};
|
|
3287
|
+
Reflect.set(globalThis, storeKey, created);
|
|
3288
|
+
return created;
|
|
3289
|
+
}
|
|
3290
|
+
function isStore(value) {
|
|
3291
|
+
return typeof value === "object" && value !== null && "texts" in value && "trees" in value && "derived" in value;
|
|
3292
|
+
}
|
|
3293
|
+
function errorCode$1(error) {
|
|
3294
|
+
return typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
|
|
3295
|
+
}
|
|
3296
|
+
function statOrMissing(path) {
|
|
3297
|
+
try {
|
|
3298
|
+
return statSync(path, { bigint: true });
|
|
3299
|
+
} catch (error) {
|
|
3300
|
+
if (errorCode$1(error) === "ENOENT" || errorCode$1(error) === "ENOTDIR") return;
|
|
3301
|
+
throw error;
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3304
|
+
function signature(stats) {
|
|
3305
|
+
return `${stats.ino}:${stats.size}:${stats.mtimeNs}:${stats.ctimeNs}`;
|
|
3306
|
+
}
|
|
3307
|
+
function isSettled(stats) {
|
|
3308
|
+
const changed = stats.mtimeNs > stats.ctimeNs ? stats.mtimeNs : stats.ctimeNs;
|
|
3309
|
+
return BigInt(Date.now()) * 1000000n - changed > racyWindowNs;
|
|
3310
|
+
}
|
|
3311
|
+
function readDirEntries$1(root) {
|
|
3312
|
+
try {
|
|
3313
|
+
return readdirSync(root, { withFileTypes: true });
|
|
3314
|
+
} catch (error) {
|
|
3315
|
+
if (errorCode$1(error) === "ENOENT") return [];
|
|
3316
|
+
throw error;
|
|
3317
|
+
}
|
|
3318
|
+
}
|
|
3319
|
+
function walkTree(root, directories, files, nested = false) {
|
|
3320
|
+
const before = statOrMissing(root);
|
|
3321
|
+
let trusted = before !== void 0 && isSettled(before);
|
|
3322
|
+
if (before) directories.set(root, signature(before));
|
|
3323
|
+
if (nested && existsSync(resolve(root, ".git"))) return trusted;
|
|
3324
|
+
for (const entry of readDirEntries$1(root)) {
|
|
3325
|
+
const path = resolve(root, entry.name);
|
|
3326
|
+
if (entry.isDirectory() && !entry.isSymbolicLink()) {
|
|
3327
|
+
if (entry.name.startsWith(".") || ignoredDirs.has(entry.name)) continue;
|
|
3328
|
+
if (!walkTree(path, directories, files, true)) trusted = false;
|
|
3329
|
+
continue;
|
|
3330
|
+
}
|
|
3331
|
+
if (entry.isFile()) files.push({
|
|
3332
|
+
hidden: entry.name.startsWith("."),
|
|
3333
|
+
name: entry.name,
|
|
3334
|
+
path
|
|
3335
|
+
});
|
|
3336
|
+
}
|
|
3337
|
+
return trusted;
|
|
3338
|
+
}
|
|
3339
|
+
function isCurrent(tree) {
|
|
3340
|
+
for (const [directory, stored] of tree.directories) {
|
|
3341
|
+
const stats = statOrMissing(directory);
|
|
3342
|
+
if (!stats || signature(stats) !== stored) return false;
|
|
3343
|
+
}
|
|
3344
|
+
return true;
|
|
3345
|
+
}
|
|
3346
|
+
function sourceTree(root) {
|
|
3347
|
+
const trees = store().trees;
|
|
3348
|
+
const cached = trees.get(root);
|
|
3349
|
+
if (cached && isCurrent(cached)) return cached;
|
|
3350
|
+
const directories = /* @__PURE__ */ new Map();
|
|
3351
|
+
const files = [];
|
|
3352
|
+
const trusted = walkTree(root, directories, files);
|
|
3353
|
+
files.sort((left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0);
|
|
3354
|
+
const tree = {
|
|
3355
|
+
directories,
|
|
3356
|
+
files
|
|
3357
|
+
};
|
|
3358
|
+
if (trusted) trees.set(root, tree);
|
|
3359
|
+
else trees.delete(root);
|
|
3360
|
+
return tree;
|
|
3361
|
+
}
|
|
3362
|
+
/**
|
|
3363
|
+
* The files below `root` whose name matches `predicate`, sorted by path. The walk skips hidden folders, Git
|
|
3364
|
+
* repositories, and build output folders such as `node_modules`, `dist`, and `.vitehub`. Hidden files need
|
|
3365
|
+
* `includeHidden`. Symbolic links are skipped.
|
|
3366
|
+
*/
|
|
3367
|
+
function listSourceTreeFiles(root, predicate, options = {}) {
|
|
3368
|
+
const files = [];
|
|
3369
|
+
for (const file of sourceTree(resolve(root)).files) {
|
|
3370
|
+
if (file.hidden && !options.includeHidden) continue;
|
|
3371
|
+
if (predicate(file.name)) files.push(file.path);
|
|
3372
|
+
}
|
|
3373
|
+
return files;
|
|
3374
|
+
}
|
|
3375
|
+
/** The UTF-8 text of a source file. A file that did not change since the last read is not read again. */
|
|
3376
|
+
function readSourceText(file) {
|
|
3377
|
+
const path = resolve(file);
|
|
3378
|
+
const texts = store().texts;
|
|
3379
|
+
const stats = statOrMissing(path);
|
|
3380
|
+
if (!stats) return readFileSync(path, "utf8");
|
|
3381
|
+
const current = signature(stats);
|
|
3382
|
+
const cached = texts.get(path);
|
|
3383
|
+
if (cached?.trusted && cached.signature === current) return cached.text;
|
|
3384
|
+
const read = readFileSync(path, "utf8");
|
|
3385
|
+
const text = cached?.text === read ? cached.text : read;
|
|
3386
|
+
texts.set(path, {
|
|
3387
|
+
signature: current,
|
|
3388
|
+
text,
|
|
3389
|
+
trusted: isSettled(stats)
|
|
3390
|
+
});
|
|
3391
|
+
return text;
|
|
3392
|
+
}
|
|
3393
|
+
/**
|
|
3394
|
+
* A value that `compute` derives from the text of a source file, such as its syntax tree. The value is computed again
|
|
3395
|
+
* only when the text changes. `kind` separates the values of different callers for one file. The last two texts of a
|
|
3396
|
+
* file are kept, because some callers read both the file and its transformed code.
|
|
3397
|
+
*/
|
|
3398
|
+
function deriveFromSource(kind, file, source, compute) {
|
|
3399
|
+
const derived = store().derived;
|
|
3400
|
+
const key = `${kind}\0${file}`;
|
|
3401
|
+
const entries = derived.get(key) ?? [];
|
|
3402
|
+
const cached = entries.find((entry) => entry.source === source);
|
|
3403
|
+
if (cached) return cached.value;
|
|
3404
|
+
const value = compute();
|
|
3405
|
+
derived.set(key, [{
|
|
3406
|
+
source,
|
|
3407
|
+
value
|
|
3408
|
+
}, ...entries.slice(0, 1)]);
|
|
3409
|
+
return value;
|
|
3410
|
+
}
|
|
3267
3411
|
// ../internal/src/build/scan-module.ts
|
|
3268
3412
|
/**
|
|
3269
3413
|
* Reads facts from JavaScript and TypeScript modules at build and dev time. The scanner parses each module once with
|
|
@@ -3293,8 +3437,15 @@ function scanModule(source, file = "module.ts") {
|
|
|
3293
3437
|
source
|
|
3294
3438
|
};
|
|
3295
3439
|
}
|
|
3440
|
+
/** `scanModule` with a result that is shared while `source` stays the same for `file`. */
|
|
3441
|
+
function scanModuleText(source, file) {
|
|
3442
|
+
return deriveFromSource("scan-module", file, source, () => scanModule(source, file));
|
|
3443
|
+
}
|
|
3296
3444
|
/** Lists the names that a module exports. A default export reads as `default`. Type-only exports are left out. */
|
|
3297
3445
|
function exportNames(source, file = "module.ts") {
|
|
3446
|
+
return [...deriveFromSource("export-names", file, source, () => readExportNames(source, file))];
|
|
3447
|
+
}
|
|
3448
|
+
function readExportNames(source, file) {
|
|
3298
3449
|
const { module } = parseSync(file, source, {
|
|
3299
3450
|
lang: moduleLanguage(file),
|
|
3300
3451
|
sourceType: "module"
|
|
@@ -3314,6 +3465,15 @@ function unwrapExpression(node) {
|
|
|
3314
3465
|
function argumentExpression(argument) {
|
|
3315
3466
|
return argument === void 0 || argument.type === "SpreadElement" ? void 0 : unwrapExpression(argument);
|
|
3316
3467
|
}
|
|
3468
|
+
/** Calls whose callee is a plain identifier in `names`, such as `defineCollection(...)`, in source order. */
|
|
3469
|
+
function findCalls(module, names) {
|
|
3470
|
+
const wanted = new Set(names);
|
|
3471
|
+
const calls = [];
|
|
3472
|
+
walk(module.program, (node) => {
|
|
3473
|
+
if (node.type === "CallExpression" && node.callee.type === "Identifier" && wanted.has(node.callee.name)) calls.push(node);
|
|
3474
|
+
});
|
|
3475
|
+
return calls.sort((left, right) => left.start - right.start);
|
|
3476
|
+
}
|
|
3317
3477
|
/** The expression of `export default <expression>`, without assertions. Declarations return undefined. */
|
|
3318
3478
|
function defaultExportExpression(module) {
|
|
3319
3479
|
for (const statement of module.program.body) {
|
|
@@ -3535,10 +3695,10 @@ function referencedProviderSourcePaths(contents, publishedSourcesDir) {
|
|
|
3535
3695
|
return [...references].filter((reference) => ![...references].some((parent) => parent !== reference && pathContains$1(parent, reference)));
|
|
3536
3696
|
}
|
|
3537
3697
|
/** Dotenv files (`.env*`, Wrangler `.dev.vars*`), registry credentials, and Wrangler state hold local secrets. */
|
|
3538
|
-
const localSecretFile = /^(?:\.env|\.dev\.vars)(?:\..*)?$|^\.(?:netrc|npmrc|wrangler)$/;
|
|
3698
|
+
const localSecretFile$1 = /^(?:\.env|\.dev\.vars)(?:\..*)?$|^\.(?:netrc|npmrc|wrangler)$/;
|
|
3539
3699
|
/** A retained snapshot and a deployment never receive local secret files, even inside a directory that the code names. */
|
|
3540
3700
|
function isLocalSecretFile(path) {
|
|
3541
|
-
return localSecretFile.test(basename(path));
|
|
3701
|
+
return localSecretFile$1.test(basename(path));
|
|
3542
3702
|
}
|
|
3543
3703
|
/**
|
|
3544
3704
|
* Copies the durable generated sources that deployment files name into deployment artifacts and rewrites their
|
|
@@ -5307,6 +5467,24 @@ function isMissingProjectMarker(error) {
|
|
|
5307
5467
|
const code = error.code;
|
|
5308
5468
|
return code === "ENOENT" || code === "ENOTDIR";
|
|
5309
5469
|
}
|
|
5470
|
+
/** The owner of the generated code that a Vite or Nuxt config writes, from the CLI discovery and Node test markers. */
|
|
5471
|
+
function viteHubGeneratedOwner(config) {
|
|
5472
|
+
if (Reflect.get(config, "vitehubNodeTest") === true) return "node-test";
|
|
5473
|
+
return Reflect.get(config, "vitehubCliDiscovery") === true ? "cli" : "app";
|
|
5474
|
+
}
|
|
5475
|
+
/**
|
|
5476
|
+
* The generated-code folder of an owner, relative to the project root: `.vitehub` for the app, `.vitehub/cli` and
|
|
5477
|
+
* `.vitehub/node-test` for the others. State that the processes share, such as the Email outbox or the Env secret,
|
|
5478
|
+
* stays in `.vitehub`, and so do the declaration files that TypeScript reads, because their contents follow only the
|
|
5479
|
+
* Definitions.
|
|
5480
|
+
*/
|
|
5481
|
+
function viteHubGeneratedCodeDir(owner = "app") {
|
|
5482
|
+
return owner === "app" ? ".vitehub" : `.vitehub/${owner}`;
|
|
5483
|
+
}
|
|
5484
|
+
/** The absolute generated-code folder of an owner. See {@link viteHubGeneratedCodeDir}. */
|
|
5485
|
+
function viteHubGeneratedCodeRoot(projectRoot, owner = "app") {
|
|
5486
|
+
return resolve$1(projectRoot, viteHubGeneratedCodeDir(owner));
|
|
5487
|
+
}
|
|
5310
5488
|
// ../internal/src/build/deployment-output.ts
|
|
5311
5489
|
const providerDeploymentOutputRegistry = globalThis;
|
|
5312
5490
|
const providerDeploymentOutputWrites = providerDeploymentOutputRegistry.__vitehubProviderDeploymentOutputWrites ??= /* @__PURE__ */ new Map();
|
|
@@ -6460,19 +6638,193 @@ function workflowServerEnv(workflow) {
|
|
|
6460
6638
|
};
|
|
6461
6639
|
return Object.fromEntries(Object.entries(fields).filter((entry) => entry[1] !== void 0));
|
|
6462
6640
|
}
|
|
6641
|
+
// ../internal/src/build/colocated-agent-files.ts
|
|
6642
|
+
function flatAgentProjectSourceRoot(handler, serverDir, projectRoot) {
|
|
6643
|
+
if (!serverDir || !projectRoot) return;
|
|
6644
|
+
const path = relative$1(resolve$1(serverDir, "agents"), handler);
|
|
6645
|
+
if (!isAbsolute(path) && path !== ".." && !path.startsWith(`..${sep}`)) return resolve$1(projectRoot);
|
|
6646
|
+
}
|
|
6647
|
+
function resolveColocatedAgentWorkspaceRoot(handler) {
|
|
6648
|
+
const directory = join(dirname$1(handler), "workspace");
|
|
6649
|
+
return existsSync(directory) && statSync(directory).isDirectory() ? directory : void 0;
|
|
6650
|
+
}
|
|
6651
|
+
function resolveDiscoveredAgentSourceRoot(definition) {
|
|
6652
|
+
const colocatedRoot = resolveColocatedAgentWorkspaceRoot(definition.handler);
|
|
6653
|
+
return {
|
|
6654
|
+
sourceRootDir: colocatedRoot ?? definition.sourceRootDir ?? dirname$1(definition.handler),
|
|
6655
|
+
projectSourceRoot: !colocatedRoot && definition.sourceRootDir !== void 0
|
|
6656
|
+
};
|
|
6657
|
+
}
|
|
6658
|
+
const localSourceModule = /^(?:@vite-hub|vite-hub)\/source$/;
|
|
6659
|
+
function stringList(value) {
|
|
6660
|
+
if (typeof value === "string") return [value];
|
|
6661
|
+
if (Array.isArray(value) && value.every((item) => typeof item === "string")) return value;
|
|
6662
|
+
}
|
|
6663
|
+
function literalLocalSource(input, kind) {
|
|
6664
|
+
if (isRecord(input) && !kind && "source" in input) return literalLocalSource(input.source);
|
|
6665
|
+
if (isRecord(input) && ("repo" in input || "url" in input || "server" in input || "content" in input)) return;
|
|
6666
|
+
if (typeof input === "string" && kind === "glob") {
|
|
6667
|
+
const parts = input.replaceAll("\\", "/").replace(/^\.\//, "").split("/").filter(Boolean);
|
|
6668
|
+
const wild = parts.findIndex((part) => /[*?[\]{}()!]/.test(part));
|
|
6669
|
+
return wild === -1 ? {
|
|
6670
|
+
include: ["**/*"],
|
|
6671
|
+
path: parts.join("/") || "."
|
|
6672
|
+
} : {
|
|
6673
|
+
include: [parts.slice(wild).join("/")],
|
|
6674
|
+
path: parts.slice(0, wild).join("/") || "."
|
|
6675
|
+
};
|
|
6676
|
+
}
|
|
6677
|
+
if (typeof input === "string") return { path: input };
|
|
6678
|
+
if (!isRecord(input)) return;
|
|
6679
|
+
const include = stringList(input.include);
|
|
6680
|
+
if (include && kind !== "file") return {
|
|
6681
|
+
dot: input.dot === true,
|
|
6682
|
+
ignore: stringList(input.ignore),
|
|
6683
|
+
include,
|
|
6684
|
+
path: typeof input.cwd === "string" ? input.cwd : "."
|
|
6685
|
+
};
|
|
6686
|
+
if (typeof input.path === "string" && kind !== "glob") return { path: input.path };
|
|
6687
|
+
}
|
|
6688
|
+
function literalLocalSources(handler) {
|
|
6689
|
+
const module = scanModule(readFileSync(handler, "utf8"), handler);
|
|
6690
|
+
const helpers = /* @__PURE__ */ new Map();
|
|
6691
|
+
for (const statement of module.program.body) {
|
|
6692
|
+
if (statement.type !== "ImportDeclaration" || statement.importKind === "type" || !localSourceModule.test(String(statement.source.value))) continue;
|
|
6693
|
+
for (const specifier of statement.specifiers) {
|
|
6694
|
+
if (specifier.type !== "ImportSpecifier" || specifier.importKind === "type") continue;
|
|
6695
|
+
const name = specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
|
|
6696
|
+
if (name === "file" || name === "glob") helpers.set(specifier.local.name, name);
|
|
6697
|
+
}
|
|
6698
|
+
}
|
|
6699
|
+
const sources = [];
|
|
6700
|
+
for (const call of findCalls(module, helpers.keys())) {
|
|
6701
|
+
const argument = argumentExpression(call.arguments[0]);
|
|
6702
|
+
const input = argument ? staticValue(argument) : void 0;
|
|
6703
|
+
const kind = call.callee.type === "Identifier" ? helpers.get(call.callee.name) : void 0;
|
|
6704
|
+
const source = input === dynamic ? void 0 : literalLocalSource(input, kind);
|
|
6705
|
+
if (source) sources.push(source);
|
|
6706
|
+
}
|
|
6707
|
+
walk(module.program, (node) => {
|
|
6708
|
+
if (node.type !== "ObjectExpression") return;
|
|
6709
|
+
const entries = findProperty(node, "sources")?.value;
|
|
6710
|
+
if (entries?.type !== "ObjectExpression") return;
|
|
6711
|
+
for (const entry of objectProperties(entries)) {
|
|
6712
|
+
const input = entry.value ? staticValue(entry.value) : dynamic;
|
|
6713
|
+
const source = input === dynamic ? void 0 : literalLocalSource(input);
|
|
6714
|
+
if (source) sources.push(source);
|
|
6715
|
+
}
|
|
6716
|
+
});
|
|
6717
|
+
return sources;
|
|
6718
|
+
}
|
|
6719
|
+
function contains(root, path) {
|
|
6720
|
+
const nested = relative$1(root, path);
|
|
6721
|
+
return !isAbsolute(nested) && nested !== ".." && !nested.startsWith(`..${sep}`);
|
|
6722
|
+
}
|
|
6723
|
+
/**
|
|
6724
|
+
* The folder that holds the snapshot of a flat Agent's local Sources in a retained sources folder. It sits beside the
|
|
6725
|
+
* numbered source trees and has no dot folder, so globs such as Netlify's `includedFiles` package it.
|
|
6726
|
+
*/
|
|
6727
|
+
function flatAgentSourceSnapshotDir(sourcesDir, handler, projectRoot) {
|
|
6728
|
+
const name = contains(projectRoot, handler) ? relative$1(projectRoot, handler) : basename(handler);
|
|
6729
|
+
return join(sourcesDir, "agent-sources", name.replace(/\.(?:c|m)?[jt]s$/i, ""));
|
|
6730
|
+
}
|
|
6731
|
+
const localSecretFile = /^(?:\.env|\.dev\.vars)(?:\..*)?$/i;
|
|
6732
|
+
function skippedSourceEntry(name) {
|
|
6733
|
+
const lower = name.toLowerCase();
|
|
6734
|
+
return lower === "node_modules" || lower === ".git" || localSecretFile.test(name);
|
|
6735
|
+
}
|
|
6736
|
+
function allowedSnapshotPath(root, path) {
|
|
6737
|
+
return contains(root, path) && !relative$1(root, path).split(sep).some(skippedSourceEntry);
|
|
6738
|
+
}
|
|
6739
|
+
function matchedGlobFiles(folder, source) {
|
|
6740
|
+
const include = source.include.map((pattern) => new Minimatch(pattern.replaceAll("\\", "/"), { dot: source.dot }));
|
|
6741
|
+
const ignore = (source.ignore ?? []).map((pattern) => new Minimatch(pattern.replaceAll("\\", "/"), { dot: true }));
|
|
6742
|
+
const files = [];
|
|
6743
|
+
const visit = (directory) => {
|
|
6744
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
6745
|
+
if (skippedSourceEntry(entry.name)) continue;
|
|
6746
|
+
const path = join(directory, entry.name);
|
|
6747
|
+
if (entry.isDirectory()) visit(path);
|
|
6748
|
+
if (!entry.isFile()) continue;
|
|
6749
|
+
const key = relative$1(folder, path).split(sep).join("/");
|
|
6750
|
+
if (include.some((pattern) => pattern.match(key)) && !ignore.some((pattern) => pattern.match(key))) files.push(path);
|
|
6751
|
+
}
|
|
6752
|
+
};
|
|
6753
|
+
visit(folder);
|
|
6754
|
+
return files;
|
|
6755
|
+
}
|
|
6756
|
+
/**
|
|
6757
|
+
* Copies the local Sources that a flat Agent names with literal `file()` and `glob()` options into `targetDir`, at
|
|
6758
|
+
* their paths under `projectRoot`. A deployment uses this folder as the Agent's Source root, so it ships these files
|
|
6759
|
+
* and not the whole project. A Source with computed options is not copied: it cannot read local files after deploy.
|
|
6760
|
+
*/
|
|
6761
|
+
async function snapshotFlatAgentSources(handler, projectRoot, targetDir) {
|
|
6762
|
+
await mkdir(targetDir, { recursive: true });
|
|
6763
|
+
const root = realpathSync(projectRoot);
|
|
6764
|
+
for (const source of literalLocalSources(handler)) {
|
|
6765
|
+
const from = resolve$1(root, source.path);
|
|
6766
|
+
if (!allowedSnapshotPath(root, from) || !existsSync(from)) continue;
|
|
6767
|
+
const realFrom = realpathSync(from);
|
|
6768
|
+
if (!allowedSnapshotPath(root, realFrom)) continue;
|
|
6769
|
+
const target = resolve$1(targetDir, relative$1(root, from));
|
|
6770
|
+
if (source.include) {
|
|
6771
|
+
if (!statSync(realFrom).isDirectory()) continue;
|
|
6772
|
+
await mkdir(target, { recursive: true });
|
|
6773
|
+
for (const path of matchedGlobFiles(realFrom, {
|
|
6774
|
+
...source,
|
|
6775
|
+
include: source.include
|
|
6776
|
+
})) {
|
|
6777
|
+
const destination = resolve$1(target, relative$1(realFrom, path));
|
|
6778
|
+
await mkdir(dirname$1(destination), { recursive: true });
|
|
6779
|
+
await copyFile(path, destination);
|
|
6780
|
+
}
|
|
6781
|
+
} else if (statSync(realFrom).isFile()) {
|
|
6782
|
+
await mkdir(dirname$1(target), { recursive: true });
|
|
6783
|
+
await copyFile(realFrom, target);
|
|
6784
|
+
}
|
|
6785
|
+
}
|
|
6786
|
+
}
|
|
6787
|
+
function isFolderAgentEntry(file) {
|
|
6788
|
+
if (!/^(?:agent|index)\.(?:c|m)?[jt]s$/i.test(basename(file))) return false;
|
|
6789
|
+
return !(basename(file).toLowerCase().startsWith("agent.") && basename(dirname$1(file)) === "agents" && basename(dirname$1(dirname$1(file))) === "server");
|
|
6790
|
+
}
|
|
6791
|
+
function colocatedAgentFilesRoot(handler, directoryName) {
|
|
6792
|
+
if (!isFolderAgentEntry(handler)) return;
|
|
6793
|
+
const root = join(dirname$1(handler), directoryName);
|
|
6794
|
+
return existsSync(root) ? root : void 0;
|
|
6795
|
+
}
|
|
6796
|
+
function resolveColocatedAgentFilesRoot(handler, directoryName) {
|
|
6797
|
+
const root = colocatedAgentFilesRoot(handler, directoryName);
|
|
6798
|
+
return root && statSync(root).isDirectory() ? root : void 0;
|
|
6799
|
+
}
|
|
6800
|
+
function readColocatedAgentFiles(handler, directoryName) {
|
|
6801
|
+
const root = colocatedAgentFilesRoot(handler, directoryName);
|
|
6802
|
+
if (!root) return;
|
|
6803
|
+
if (!statSync(root).isDirectory()) return;
|
|
6804
|
+
const files = {};
|
|
6805
|
+
const visit = (directory) => {
|
|
6806
|
+
for (const entry of readdirSync(directory, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name))) {
|
|
6807
|
+
const file = join(directory, entry.name);
|
|
6808
|
+
const target = relative$1(root, file).replace(/\\/g, "/");
|
|
6809
|
+
if (entry.isDirectory()) {
|
|
6810
|
+
visit(file);
|
|
6811
|
+
continue;
|
|
6812
|
+
}
|
|
6813
|
+
if (!entry.isFile()) continue;
|
|
6814
|
+
const content = readFileSync(file);
|
|
6815
|
+
files[target] = {
|
|
6816
|
+
content: content.toString("base64"),
|
|
6817
|
+
encoding: "base64"
|
|
6818
|
+
};
|
|
6819
|
+
}
|
|
6820
|
+
};
|
|
6821
|
+
visit(root);
|
|
6822
|
+
return Object.keys(files).length ? files : void 0;
|
|
6823
|
+
}
|
|
6463
6824
|
// ../internal/src/definition-catalog.ts
|
|
6464
6825
|
const sourceFilePattern$2 = /\.(?:c|m)?[jt]sx?$/i;
|
|
6465
6826
|
const declarationFilePattern = /\.d\.(?:c|m)?[jt]sx?$/i;
|
|
6466
6827
|
const testFilePattern = /\.(?:test|spec)\.(?:c|m)?[jt]sx?$/i;
|
|
6467
|
-
const ignoredDirs = /* @__PURE__ */ new Set([
|
|
6468
|
-
"node_modules",
|
|
6469
|
-
"dist",
|
|
6470
|
-
".output",
|
|
6471
|
-
".nuxt",
|
|
6472
|
-
".vercel",
|
|
6473
|
-
".git",
|
|
6474
|
-
".vitehub"
|
|
6475
|
-
]);
|
|
6476
6828
|
function resolveDefinitionScanRoots(rootDir, scanDirs = []) {
|
|
6477
6829
|
return [...new Set([rootDir, ...scanDirs].filter(Boolean))];
|
|
6478
6830
|
}
|
|
@@ -6495,32 +6847,11 @@ function createSuffixDefinitionSource(source, roots, pattern, normalizeName, opt
|
|
|
6495
6847
|
source
|
|
6496
6848
|
};
|
|
6497
6849
|
}
|
|
6498
|
-
function readDirEntries$1(root) {
|
|
6499
|
-
try {
|
|
6500
|
-
return readdirSync(root, { withFileTypes: true });
|
|
6501
|
-
} catch (error) {
|
|
6502
|
-
if (error.code === "ENOENT") return [];
|
|
6503
|
-
throw error;
|
|
6504
|
-
}
|
|
6505
|
-
}
|
|
6506
6850
|
function isGitRepositoryDirectory(directory) {
|
|
6507
6851
|
return existsSync(resolve(directory, ".git"));
|
|
6508
6852
|
}
|
|
6509
6853
|
function listMatchingFiles(root, predicate, options = {}) {
|
|
6510
|
-
|
|
6511
|
-
for (const entry of readDirEntries$1(root)) {
|
|
6512
|
-
const absolute = resolve(root, entry.name);
|
|
6513
|
-
if (entry.isDirectory() && !entry.isSymbolicLink()) {
|
|
6514
|
-
if (isGitRepositoryDirectory(absolute)) continue;
|
|
6515
|
-
if (entry.name.startsWith(".")) continue;
|
|
6516
|
-
if (ignoredDirs.has(entry.name)) continue;
|
|
6517
|
-
files.push(...listMatchingFiles(absolute, predicate, options));
|
|
6518
|
-
continue;
|
|
6519
|
-
}
|
|
6520
|
-
if (entry.name.startsWith(".") && !options.includeHidden) continue;
|
|
6521
|
-
if (entry.isFile() && predicate(entry.name)) files.push(absolute);
|
|
6522
|
-
}
|
|
6523
|
-
return files.sort();
|
|
6854
|
+
return listSourceTreeFiles(root, predicate, options);
|
|
6524
6855
|
}
|
|
6525
6856
|
/** A module that a Definitions folder can hold: JavaScript or TypeScript, and not a declaration, test, or spec file. */
|
|
6526
6857
|
function isDefinitionSourceFile(name) {
|
|
@@ -6694,7 +7025,7 @@ function resolveAgentReExport(file, source, masked) {
|
|
|
6694
7025
|
]) if (existsSync(candidate) && statSync(candidate).isFile()) return candidate;
|
|
6695
7026
|
}
|
|
6696
7027
|
function maskSourceLiterals(source, file) {
|
|
6697
|
-
return maskLiterals(
|
|
7028
|
+
return deriveFromSource("masked-literals", file, source, () => maskLiterals(scanModuleText(source, file)));
|
|
6698
7029
|
}
|
|
6699
7030
|
function isFolderAgentImplementationTarget(file) {
|
|
6700
7031
|
const fileName = normalize(file).split("/").pop();
|
|
@@ -6704,7 +7035,7 @@ function isFolderAgentImplementationTarget(file) {
|
|
|
6704
7035
|
function extractAgentRuntime(file, seen = /* @__PURE__ */ new Set()) {
|
|
6705
7036
|
if (seen.has(file)) return void 0;
|
|
6706
7037
|
seen.add(file);
|
|
6707
|
-
const source =
|
|
7038
|
+
const source = readSourceText(file);
|
|
6708
7039
|
const masked = maskSourceLiterals(source, file);
|
|
6709
7040
|
const start = findAgentObjectStart(source, masked);
|
|
6710
7041
|
if (start === void 0) {
|
|
@@ -6751,7 +7082,7 @@ function extractAgentWorkflowName(file, fallbackName) {
|
|
|
6751
7082
|
if (/^false(?:\s+as\s+const)?$/.test(runtime.masked || "")) return void 0;
|
|
6752
7083
|
const shorthand = /^([A-Za-z_$][\w$]*)$/.exec(runtime.masked || "")?.[1];
|
|
6753
7084
|
if (shorthand) {
|
|
6754
|
-
const source =
|
|
7085
|
+
const source = readSourceText(file);
|
|
6755
7086
|
const masked = maskSourceLiterals(source, file);
|
|
6756
7087
|
const declaration = new RegExp(`\\b(?:const|let|var)\\s+${shorthand}\\s*(?::(?:=>|[^=])*?)?=\\s*`).exec(masked);
|
|
6757
7088
|
if (declaration) {
|
|
@@ -6823,11 +7154,11 @@ function discoverSuffixAgentWorkflowDefinitions(roots) {
|
|
|
6823
7154
|
return workflowDefinition ? [workflowDefinition] : [];
|
|
6824
7155
|
});
|
|
6825
7156
|
}
|
|
6826
|
-
function discoverFlatServerAgentWorkflowDefinitions(scanDirs) {
|
|
7157
|
+
function discoverFlatServerAgentWorkflowDefinitions(scanDirs, projectRoot) {
|
|
6827
7158
|
const folderAgentFiles = scanDirs.flatMap((scanDir) => findFolderAgentFiles(resolve(scanDir, "agents")));
|
|
6828
7159
|
const folderAgentDirs = new Set(folderAgentFiles.map((file) => normalize(resolve(file, ".."))));
|
|
6829
7160
|
const folderAgentTargets = new Set(folderAgentFiles.flatMap((file) => {
|
|
6830
|
-
const source =
|
|
7161
|
+
const source = readSourceText(file);
|
|
6831
7162
|
const target = resolveAgentReExport(file, source, maskSourceLiterals(source, file));
|
|
6832
7163
|
const relativeTarget = target && normalize(relative$1(resolve(file, ".."), target));
|
|
6833
7164
|
return target && relativeTarget && relativeTarget !== ".." && !relativeTarget.startsWith("../") && isFolderAgentImplementationTarget(target) ? [normalize(target)] : [];
|
|
@@ -6854,7 +7185,12 @@ function discoverFlatServerAgentWorkflowDefinitions(scanDirs) {
|
|
|
6854
7185
|
})
|
|
6855
7186
|
})]).flatMap((definition) => {
|
|
6856
7187
|
const workflowDefinition = toAgentWorkflowDefinition(definition.handler, definition.name);
|
|
6857
|
-
|
|
7188
|
+
if (!workflowDefinition) return [];
|
|
7189
|
+
const sourceRootDir = flatAgentProjectSourceRoot(definition.handler, scanDirs[0], projectRoot);
|
|
7190
|
+
return [{
|
|
7191
|
+
...workflowDefinition,
|
|
7192
|
+
...sourceRootDir ? { sourceRootDir } : {}
|
|
7193
|
+
}];
|
|
6858
7194
|
});
|
|
6859
7195
|
}
|
|
6860
7196
|
function discoverConfiguredServerAgentWorkflowDefinitions(scanDirs) {
|
|
@@ -6863,7 +7199,7 @@ function discoverConfiguredServerAgentWorkflowDefinitions(scanDirs) {
|
|
|
6863
7199
|
const agentsDir = resolve(scanDir, "agents");
|
|
6864
7200
|
const files = findFolderAgentFiles(agentsDir);
|
|
6865
7201
|
const targets = new Set(files.flatMap((file) => {
|
|
6866
|
-
const source =
|
|
7202
|
+
const source = readSourceText(file);
|
|
6867
7203
|
const target = resolveAgentReExport(file, source, maskSourceLiterals(source, file));
|
|
6868
7204
|
const relativeTarget = target && normalize(relative$1(resolve(file, ".."), target));
|
|
6869
7205
|
return target && relativeTarget && relativeTarget !== ".." && !relativeTarget.startsWith("../") ? [normalize(target)] : [];
|
|
@@ -6878,8 +7214,8 @@ function discoverConfiguredServerAgentWorkflowDefinitions(scanDirs) {
|
|
|
6878
7214
|
}
|
|
6879
7215
|
return sortDefinitions(definitions);
|
|
6880
7216
|
}
|
|
6881
|
-
function discoverAgentWorkflowDefinitions(roots, serverScanDirs) {
|
|
6882
|
-
return mergeDefinitions("agent workflow", discoverSuffixAgentWorkflowDefinitions(roots), discoverFlatServerAgentWorkflowDefinitions(serverScanDirs), discoverConfiguredServerAgentWorkflowDefinitions(serverScanDirs));
|
|
7217
|
+
function discoverAgentWorkflowDefinitions(roots, serverScanDirs, projectRoot) {
|
|
7218
|
+
return mergeDefinitions("agent workflow", discoverSuffixAgentWorkflowDefinitions(roots), discoverFlatServerAgentWorkflowDefinitions(serverScanDirs, projectRoot), discoverConfiguredServerAgentWorkflowDefinitions(serverScanDirs));
|
|
6883
7219
|
}
|
|
6884
7220
|
function discoverWorkflowFolders(scanDirs, source) {
|
|
6885
7221
|
const definitions = /* @__PURE__ */ new Map();
|
|
@@ -6927,7 +7263,7 @@ function discoverWorkflowDefinitions(options) {
|
|
|
6927
7263
|
handler: file,
|
|
6928
7264
|
name,
|
|
6929
7265
|
source: "vite-suffix"
|
|
6930
|
-
}) })]), discoverFlatServerWorkflowDefinitions(serverScanDirs, "server-workflows"), folderDefinitions, options.mode === "standalone" ? [] : discoverAgentWorkflowDefinitions(roots, serverScanDirs));
|
|
7266
|
+
}) })]), discoverFlatServerWorkflowDefinitions(serverScanDirs, "server-workflows"), folderDefinitions, options.mode === "standalone" ? [] : discoverAgentWorkflowDefinitions(roots, serverScanDirs, options.projectRoot ?? options.rootDir));
|
|
6931
7267
|
}
|
|
6932
7268
|
// src/internal/runtime-type.ts
|
|
6933
7269
|
function isRuntimeRecord(value) {
|
|
@@ -6937,44 +7273,6 @@ function isRuntimeRecord(value) {
|
|
|
6937
7273
|
function getAgentInvocationRecoveryWorkflowName(agentWorkflowName) {
|
|
6938
7274
|
return `vitehub-agent-invocation-recovery-${agentWorkflowName}`;
|
|
6939
7275
|
}
|
|
6940
|
-
// ../internal/src/build/colocated-agent-files.ts
|
|
6941
|
-
function isFolderAgentEntry(file) {
|
|
6942
|
-
if (!/^(?:agent|index)\.(?:c|m)?[jt]s$/i.test(basename(file))) return false;
|
|
6943
|
-
return !(basename(file).toLowerCase().startsWith("agent.") && basename(dirname$1(file)) === "agents" && basename(dirname$1(dirname$1(file))) === "server");
|
|
6944
|
-
}
|
|
6945
|
-
function colocatedAgentFilesRoot(handler, directoryName) {
|
|
6946
|
-
if (!isFolderAgentEntry(handler)) return;
|
|
6947
|
-
const root = join(dirname$1(handler), directoryName);
|
|
6948
|
-
return existsSync(root) ? root : void 0;
|
|
6949
|
-
}
|
|
6950
|
-
function resolveColocatedAgentFilesRoot(handler, directoryName) {
|
|
6951
|
-
const root = colocatedAgentFilesRoot(handler, directoryName);
|
|
6952
|
-
return root && statSync(root).isDirectory() ? root : void 0;
|
|
6953
|
-
}
|
|
6954
|
-
function readColocatedAgentFiles(handler, directoryName) {
|
|
6955
|
-
const root = colocatedAgentFilesRoot(handler, directoryName);
|
|
6956
|
-
if (!root) return;
|
|
6957
|
-
if (!statSync(root).isDirectory()) return;
|
|
6958
|
-
const files = {};
|
|
6959
|
-
const visit = (directory) => {
|
|
6960
|
-
for (const entry of readdirSync(directory, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name))) {
|
|
6961
|
-
const file = join(directory, entry.name);
|
|
6962
|
-
const target = relative$1(root, file).replace(/\\/g, "/");
|
|
6963
|
-
if (entry.isDirectory()) {
|
|
6964
|
-
visit(file);
|
|
6965
|
-
continue;
|
|
6966
|
-
}
|
|
6967
|
-
if (!entry.isFile()) continue;
|
|
6968
|
-
const content = readFileSync(file);
|
|
6969
|
-
files[target] = {
|
|
6970
|
-
content: content.toString("base64"),
|
|
6971
|
-
encoding: "base64"
|
|
6972
|
-
};
|
|
6973
|
-
}
|
|
6974
|
-
};
|
|
6975
|
-
visit(root);
|
|
6976
|
-
return Object.keys(files).length ? files : void 0;
|
|
6977
|
-
}
|
|
6978
7276
|
// ../internal/src/build/esbuild.ts
|
|
6979
7277
|
const viteRawNamespace = "vitehub-vite-raw";
|
|
6980
7278
|
const viteMarkdownTemplateNamespace = "vitehub-markdown-template";
|
|
@@ -8128,10 +8426,6 @@ async function createCloudflareWorkflowNitroConfig(options) {
|
|
|
8128
8426
|
function renderRegistryImport(registryFile, file) {
|
|
8129
8427
|
return `import(${JSON.stringify(pathToFileURL(file).href)})`;
|
|
8130
8428
|
}
|
|
8131
|
-
function resolveAgentWorkspaceSourceRoot(file) {
|
|
8132
|
-
const workspaceDirectory = join(dirname$1(file), "workspace");
|
|
8133
|
-
return existsSync(workspaceDirectory) && statSync(workspaceDirectory).isDirectory() ? workspaceDirectory : dirname$1(file);
|
|
8134
|
-
}
|
|
8135
8429
|
function readAgentInstructions(file, dependencies) {
|
|
8136
8430
|
const instructions = join(dirname$1(file), "instructions.md");
|
|
8137
8431
|
if (!existsSync(instructions) || !statSync(instructions).isFile()) return;
|
|
@@ -8152,13 +8446,14 @@ function readAgentSkills(file) {
|
|
|
8152
8446
|
}));
|
|
8153
8447
|
}
|
|
8154
8448
|
function renderAgentWorkflowRegistryEntry(registryFile, definition, retainedAgentInstructions) {
|
|
8449
|
+
const { sourceRootDir, projectSourceRoot } = resolveDiscoveredAgentSourceRoot(definition);
|
|
8155
8450
|
const instructions = retainedAgentInstructions?.has(definition.handler) ? retainedAgentInstructions.get(definition.handler) : readAgentInstructions(definition.handler);
|
|
8156
8451
|
return [
|
|
8157
8452
|
` [${JSON.stringify(definition.name)}]: Object.assign(async () => {`,
|
|
8158
8453
|
` const cached = registryEntryCache.get(${JSON.stringify(definition.name)})`,
|
|
8159
8454
|
" if (cached) return cached",
|
|
8160
8455
|
` const loaded = await ${renderRegistryImport(registryFile, definition.handler)}`,
|
|
8161
|
-
` const agent = workspaceAgentWithSourceRoot(agentWithColocatedSkills(agentWithColocatedInstructions("default" in loaded ? loaded.default : loaded, ${JSON.stringify(instructions)}), ${JSON.stringify(readAgentSkills(definition.handler))}), ${JSON.stringify(
|
|
8456
|
+
` const agent = workspaceAgentWithSourceRoot(agentWithColocatedSkills(agentWithColocatedInstructions("default" in loaded ? loaded.default : loaded, ${JSON.stringify(instructions)}), ${JSON.stringify(readAgentSkills(definition.handler))}), ${JSON.stringify(sourceRootDir)}, ${JSON.stringify(instructions)}, ${projectSourceRoot})`,
|
|
8162
8457
|
` const entry = { rootStep: false, handler: async (context) => await runAgentWorkflowDefinition(agent, { ...context, payload: { ...context.payload, agentIdentity: context.payload?.agentIdentity || { name: ${JSON.stringify(definition.agentIdentity || definition.name)} } } }, runAgentInline)${definition.source === "agent-workflow-recovery" ? ", internalAgentInvocationRecovery: true" : ""} }`,
|
|
8163
8458
|
` registryEntryCache.set(${JSON.stringify(definition.name)}, entry)`,
|
|
8164
8459
|
" return entry",
|
|
@@ -8440,13 +8735,23 @@ async function writeVercelNativeWorkflowFiles(generatedDir, definitions) {
|
|
|
8440
8735
|
}));
|
|
8441
8736
|
return vercelNativeFiles;
|
|
8442
8737
|
}
|
|
8443
|
-
async function writeProviderEntries(rootDir, workflow, importBases = {}, serverDirs, includeUserAppEntry = true, transformRegistry, definitionRootDir = rootDir, generatedDir = ensureGeneratedDir(rootDir, productName), retainedAgentInstructions, requireVercelNative = false) {
|
|
8738
|
+
async function writeProviderEntries(rootDir, workflow, importBases = {}, serverDirs, includeUserAppEntry = true, transformRegistry, definitionRootDir = rootDir, generatedDir = ensureGeneratedDir(rootDir, productName), retainedAgentInstructions, requireVercelNative = false, projectRoot = definitionRootDir, flatAgentSources) {
|
|
8444
8739
|
await mkdir(generatedDir, { recursive: true });
|
|
8445
8740
|
const registryFile = resolve$1(generatedDir, generatedRegistryFileName);
|
|
8446
|
-
const
|
|
8741
|
+
const discovered = discoverWorkflowDefinitions({
|
|
8742
|
+
projectRoot,
|
|
8447
8743
|
rootDir: definitionRootDir,
|
|
8448
8744
|
serverDirs
|
|
8449
8745
|
});
|
|
8746
|
+
const definitions = flatAgentSources ? await Promise.all(discovered.map(async (definition) => {
|
|
8747
|
+
if (definition.source !== "agent-workflow" || !definition.sourceRootDir || resolveColocatedAgentWorkspaceRoot(definition.handler)) return definition;
|
|
8748
|
+
const sourceRootDir = flatAgentSourceSnapshotDir(flatAgentSources.sourcesDir, definition.handler, projectRoot);
|
|
8749
|
+
await snapshotFlatAgentSources(definition.handler, flatAgentSources.projectRoot, sourceRootDir);
|
|
8750
|
+
return {
|
|
8751
|
+
...definition,
|
|
8752
|
+
sourceRootDir
|
|
8753
|
+
};
|
|
8754
|
+
})) : discovered;
|
|
8450
8755
|
const providerDefinitions = withAgentInvocationRecoveryDefinitions(definitions);
|
|
8451
8756
|
const userAppEntry = includeUserAppEntry ? resolveWorkflowUserAppEntry(definitionRootDir, includeUserAppEntry) : void 0;
|
|
8452
8757
|
const cloudflareWorkflowConfig = resolveWorkflowConfig(workflow, "cloudflare");
|
|
@@ -9001,8 +9306,10 @@ const workflowConsoleSection = {
|
|
|
9001
9306
|
}
|
|
9002
9307
|
};
|
|
9003
9308
|
// src/internal/dev-registry.ts
|
|
9004
|
-
const workflowDevGeneratedDir = ".vitehub/nitro/workflow";
|
|
9005
9309
|
const workflowTestSetupFile = "test-setup.mjs";
|
|
9310
|
+
function workflowDevGeneratedDirectory(projectRoot, owner) {
|
|
9311
|
+
return resolve$1(viteHubGeneratedCodeRoot(projectRoot, owner), "nitro", "workflow");
|
|
9312
|
+
}
|
|
9006
9313
|
const generatedFilesSeparatePerCommand = {
|
|
9007
9314
|
build: {
|
|
9008
9315
|
plugin: "build-plugin.mjs",
|
|
@@ -9106,7 +9413,7 @@ async function writeIfChanged(file, contents) {
|
|
|
9106
9413
|
* not change are not written again.
|
|
9107
9414
|
*/
|
|
9108
9415
|
async function writeWorkflowDevRegistryFiles(options) {
|
|
9109
|
-
const directory =
|
|
9416
|
+
const directory = workflowDevGeneratedDirectory(options.projectRoot, options.owner);
|
|
9110
9417
|
await mkdir(directory, { recursive: true });
|
|
9111
9418
|
const names = generatedFilesSeparatePerCommand[options.dev ? "dev" : "build"];
|
|
9112
9419
|
const registry = resolve$1(directory, names.registry);
|
|
@@ -9212,6 +9519,10 @@ function agentWorkflowRegistryTransform(plugins) {
|
|
|
9212
9519
|
const noExternalAddition = createNoExternalAddition(workflowPackageName);
|
|
9213
9520
|
const workflowBuildAssociation = Symbol("vitehubWorkflowBuildAssociation");
|
|
9214
9521
|
const workflowEnvironmentAssociation = Symbol("vitehubWorkflowEnvironmentAssociation");
|
|
9522
|
+
function workflowProjectRoot(config) {
|
|
9523
|
+
const configured = Reflect.get(config, VITEHUB_PROJECT_ROOT);
|
|
9524
|
+
return resolveViteHubProjectRoot(config.root, { projectRoot: typeof configured === "string" ? configured : void 0 });
|
|
9525
|
+
}
|
|
9215
9526
|
function resolveStringAliases(config) {
|
|
9216
9527
|
return encodeProviderOutputAliases(config.resolve.alias);
|
|
9217
9528
|
}
|
|
@@ -9305,7 +9616,7 @@ function hubWorkflow(workflow, internalOptions = {}) {
|
|
|
9305
9616
|
const build = scheduledBuildConfig(config);
|
|
9306
9617
|
const workflowOptions = build?.workflow ?? workflow;
|
|
9307
9618
|
if (resolveWorkflow(workflowOptions)?.driver !== "vercel") return;
|
|
9308
|
-
const rootDir =
|
|
9619
|
+
const rootDir = workflowProjectRoot(config);
|
|
9309
9620
|
const aliases = await providerImportAliases(config);
|
|
9310
9621
|
const workflowServerDirs = config["__vitehubServerDirs"] ?? build?.serverDirs;
|
|
9311
9622
|
const providerSources = discoverWorkflowProviderSources(config.root, workflowServerDirs);
|
|
@@ -9323,7 +9634,10 @@ function hubWorkflow(workflow, internalOptions = {}) {
|
|
|
9323
9634
|
workflow: internalOptions?.importBase,
|
|
9324
9635
|
workspaceRuntime: internalOptions?.workspaceRuntimeModule,
|
|
9325
9636
|
workspaceDependencies: internalOptions?.workspaceDependencyRuntimeImports
|
|
9326
|
-
}, retainedServerDirs, internalOptions?.includeUserAppEntry, config.plugins.find((plugin) => plugin.vitehub?.agent?.transformWorkflowRegistry)?.vitehub?.agent?.transformWorkflowRegistry, definitionRootDir, artifactDir ? resolve$1(artifactDir, "output") : void 0, retainedAgentInstructions, true)
|
|
9637
|
+
}, retainedServerDirs, internalOptions?.includeUserAppEntry, config.plugins.find((plugin) => plugin.vitehub?.agent?.transformWorkflowRegistry)?.vitehub?.agent?.transformWorkflowRegistry, definitionRootDir, artifactDir ? resolve$1(artifactDir, "output") : void 0, retainedAgentInstructions, true, retainedSources?.resolve(rootDir) ?? rootDir, artifactDir ? {
|
|
9638
|
+
projectRoot: rootDir,
|
|
9639
|
+
sourcesDir: resolve$1(artifactDir, ".vitehub", "workflow", "sources")
|
|
9640
|
+
} : void 0);
|
|
9327
9641
|
assertVercelWorkflowsRunNatively(artifacts.providerDefinitions);
|
|
9328
9642
|
const retainedAliases = retainedSources ? retainProviderOutputAliases(aliases, retainedSources) : aliases;
|
|
9329
9643
|
const native = hasVercelNativeWorkflowEntry(rootDir, artifacts.providerDefinitions, retainedAliases, artifacts.vercelNativeFiles);
|
|
@@ -9389,6 +9703,7 @@ function hubWorkflow(workflow, internalOptions = {}) {
|
|
|
9389
9703
|
console.warn(`[vitehub:workflow] ${report} The dev server runs without Workflows until you fix the Workflow configuration.`);
|
|
9390
9704
|
}
|
|
9391
9705
|
let configPlugins;
|
|
9706
|
+
let generatedOwner = "app";
|
|
9392
9707
|
async function writeDevRegistry(rootDir, workflow, vercel) {
|
|
9393
9708
|
return await writeWorkflowDevRegistryFiles({
|
|
9394
9709
|
agentModules: agentWorkflowModules(configPlugins),
|
|
@@ -9399,6 +9714,7 @@ function hubWorkflow(workflow, internalOptions = {}) {
|
|
|
9399
9714
|
importBase: internalOptions.importBase,
|
|
9400
9715
|
projectRoot: rootDir,
|
|
9401
9716
|
pluginPath: devStartupPlugin,
|
|
9717
|
+
owner: generatedOwner,
|
|
9402
9718
|
vercel,
|
|
9403
9719
|
workflow
|
|
9404
9720
|
});
|
|
@@ -9408,13 +9724,13 @@ function hubWorkflow(workflow, internalOptions = {}) {
|
|
|
9408
9724
|
}
|
|
9409
9725
|
let vercelModuleTransform;
|
|
9410
9726
|
async function prepareVercelNitroRegistry(config) {
|
|
9411
|
-
const rootDir =
|
|
9727
|
+
const rootDir = workflowProjectRoot(config);
|
|
9412
9728
|
const artifacts = await writeProviderEntries(rootDir, workflow, {
|
|
9413
9729
|
agent: agentWorkflowModules(config.plugins),
|
|
9414
9730
|
workflow: internalOptions.importBase,
|
|
9415
9731
|
workspaceRuntime: internalOptions.workspaceRuntimeModule,
|
|
9416
9732
|
workspaceDependencies: internalOptions.workspaceDependencyRuntimeImports
|
|
9417
|
-
}, serverDirs, internalOptions.includeUserAppEntry, config.plugins.find((plugin) => plugin.vitehub?.agent?.transformWorkflowRegistry)?.vitehub?.agent?.transformWorkflowRegistry, config.root, void 0, void 0, true);
|
|
9733
|
+
}, serverDirs, internalOptions.includeUserAppEntry, config.plugins.find((plugin) => plugin.vitehub?.agent?.transformWorkflowRegistry)?.vitehub?.agent?.transformWorkflowRegistry, config.root, void 0, void 0, true, rootDir);
|
|
9418
9734
|
assertVercelWorkflowsRunNatively(artifacts.providerDefinitions);
|
|
9419
9735
|
const native = hasVercelNativeWorkflowEntry(rootDir, artifacts.providerDefinitions, await providerImportAliases(config), artifacts.vercelNativeFiles);
|
|
9420
9736
|
vercelModuleTransform = native ? await createVercelWorkflowModuleTransform(rootDir) : void 0;
|
|
@@ -9437,6 +9753,7 @@ function hubWorkflow(workflow, internalOptions = {}) {
|
|
|
9437
9753
|
const buildConfig = config;
|
|
9438
9754
|
buildConfig.__vitehubWorkflowServerDirs = serverDirs;
|
|
9439
9755
|
startupBuild = env.command === "build";
|
|
9756
|
+
generatedOwner = viteHubGeneratedOwner(config);
|
|
9440
9757
|
configPlugins = config.plugins;
|
|
9441
9758
|
if (startupBuild && internalOptions.hosting) resolveWorkflow(workflow);
|
|
9442
9759
|
devWorkflow = resolveDevWorkflow();
|
|
@@ -9449,7 +9766,7 @@ function hubWorkflow(workflow, internalOptions = {}) {
|
|
|
9449
9766
|
const kit = createNitroServerKit(Reflect.get(config, "nitro"));
|
|
9450
9767
|
kit.addPlugin(plugin, "start");
|
|
9451
9768
|
Reflect.set(config, "nitro", kit.config);
|
|
9452
|
-
if (process.env.VITEST) return { test: { setupFiles: [resolve$1(devRootDir,
|
|
9769
|
+
if (process.env.VITEST) return { test: { setupFiles: [resolve$1(workflowDevGeneratedDirectory(devRootDir, generatedOwner), workflowTestSetupFile)] } };
|
|
9453
9770
|
}
|
|
9454
9771
|
},
|
|
9455
9772
|
configureServer(server) {
|
|
@@ -9460,9 +9777,9 @@ function hubWorkflow(workflow, internalOptions = {}) {
|
|
|
9460
9777
|
server.watcher.add([...watchedDirectories, rootDir]);
|
|
9461
9778
|
const refresh = async (path) => {
|
|
9462
9779
|
const file = path.replace(/\\/g, "/");
|
|
9463
|
-
if (file.
|
|
9780
|
+
if (file.startsWith(`${workflowDevGeneratedDirectory(rootDir, generatedOwner).replace(/\\/g, "/")}/`)) return;
|
|
9464
9781
|
const environment = server.environments.nitro ?? server.environments.ssr;
|
|
9465
|
-
const registryPath = resolve$1(rootDir,
|
|
9782
|
+
const registryPath = resolve$1(workflowDevGeneratedDirectory(rootDir, generatedOwner), "dev-registry.mjs").replace(/\\/g, "/");
|
|
9466
9783
|
const modules = [...environment?.moduleGraph.getModulesByFile(file) ?? []];
|
|
9467
9784
|
const visited = /* @__PURE__ */ new Set();
|
|
9468
9785
|
let registryDependency = false;
|
|
@@ -9480,7 +9797,7 @@ function hubWorkflow(workflow, internalOptions = {}) {
|
|
|
9480
9797
|
if (!(/\.(?:c|m)?[jt]s$/i.test(file) && /(?:\/workflows\/|\.workflow\.|\/agents\/|\.agent\.)/i.test(file)) && !registryDependency) return;
|
|
9481
9798
|
const { changed } = await writeDevRegistry(rootDir, workflowConfig);
|
|
9482
9799
|
await writeWorkflowTypes(rootDir, discoverWorkflowDevDefinitions(rootDir, serverDirs, registersAgentWorkflows(workflowConfig)), internalOptions.importBase);
|
|
9483
|
-
const filesToInvalidate = new Set([...changed, resolve$1(rootDir,
|
|
9800
|
+
const filesToInvalidate = new Set([...changed, resolve$1(workflowDevGeneratedDirectory(rootDir, generatedOwner), "dev-registry.mjs")].map((file) => file.replace(/\\/g, "/")));
|
|
9484
9801
|
let invalidated = false;
|
|
9485
9802
|
for (const changedFile of filesToInvalidate) for (const module of environment?.moduleGraph.getModulesByFile(changedFile) ?? []) {
|
|
9486
9803
|
environment.moduleGraph.invalidateModule(module);
|
|
@@ -9754,7 +10071,7 @@ function hubWorkflow(workflow, internalOptions = {}) {
|
|
|
9754
10071
|
const config = build?.config ?? resolved;
|
|
9755
10072
|
const buildProviderOutput = build?.providerOutput ?? providerOutput;
|
|
9756
10073
|
if (!config || shouldSkipViteProviderBuild(config.command)) return;
|
|
9757
|
-
const rootDir =
|
|
10074
|
+
const rootDir = workflowProjectRoot(config);
|
|
9758
10075
|
const plugins = config.plugins;
|
|
9759
10076
|
const generation = providerOutputGenerations.get(this);
|
|
9760
10077
|
const environment = generation ?? buildEnvironment(this);
|
|
@@ -9773,7 +10090,8 @@ function hubWorkflow(workflow, internalOptions = {}) {
|
|
|
9773
10090
|
const nativeOutputInNitro = Boolean(separateNitroConfig && outputs.vercel);
|
|
9774
10091
|
const nitroServer = nitroOwnsVercelServer(config, workflowOptions) || nativeOutputInNitro;
|
|
9775
10092
|
const cloudflareInNitro = Reflect.get(config, "nitro")?.rollupConfig?.plugins?.some((plugin) => plugin?.name === "vitehub-workflow-cloudflare-exports") ?? false;
|
|
9776
|
-
const
|
|
10093
|
+
const retainsSources = Boolean(outputs.cloudflare || outputs.vercel) && !nitroServer;
|
|
10094
|
+
const retainedSources = !retainsSources ? { resolve: (path) => path } : await retainProviderOutputSources({
|
|
9777
10095
|
aliases: importAliases,
|
|
9778
10096
|
artifactDir: resolve$1(artifactDir, "sources"),
|
|
9779
10097
|
paths: [
|
|
@@ -9797,7 +10115,10 @@ function hubWorkflow(workflow, internalOptions = {}) {
|
|
|
9797
10115
|
workflow: internalOptions?.importBase,
|
|
9798
10116
|
workspaceRuntime: internalOptions?.workspaceRuntimeModule,
|
|
9799
10117
|
workspaceDependencies: internalOptions?.workspaceDependencyRuntimeImports
|
|
9800
|
-
}, retainedServerDirs, internalOptions?.includeUserAppEntry, transformRegistry, retainedDefinitionRoot, resolve$1(artifactDir, "output"), retainedAgentInstructions, Boolean(outputs.vercel && outputs.vercel.driver === "vercel"))
|
|
10118
|
+
}, retainedServerDirs, internalOptions?.includeUserAppEntry, transformRegistry, retainedDefinitionRoot, resolve$1(artifactDir, "output"), retainedAgentInstructions, Boolean(outputs.vercel && outputs.vercel.driver === "vercel"), retainedSources.resolve(rootDir), retainsSources ? {
|
|
10119
|
+
projectRoot: rootDir,
|
|
10120
|
+
sourcesDir: resolve$1(artifactDir, "sources")
|
|
10121
|
+
} : void 0);
|
|
9801
10122
|
stagedArtifactDirs.set(environment, artifactDir);
|
|
9802
10123
|
contributeProviderDeploymentOutput(buildProviderOutput, {
|
|
9803
10124
|
discard: async (failure) => {
|