@agentuity/cli 0.0.94 → 0.0.96
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/AGENTS.md +54 -0
- package/dist/auth.d.ts +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +8 -5
- package/dist/auth.js.map +1 -1
- package/dist/banner.js +1 -1
- package/dist/banner.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +190 -27
- package/dist/cli.js.map +1 -1
- package/dist/cmd/auth/signup.js +1 -1
- package/dist/cmd/auth/signup.js.map +1 -1
- package/dist/cmd/build/ast.d.ts.map +1 -1
- package/dist/cmd/build/ast.js +7 -0
- package/dist/cmd/build/ast.js.map +1 -1
- package/dist/cmd/build/entry-generator.d.ts +20 -0
- package/dist/cmd/build/entry-generator.d.ts.map +1 -0
- package/dist/cmd/build/entry-generator.js +366 -0
- package/dist/cmd/build/entry-generator.js.map +1 -0
- package/dist/cmd/build/index.d.ts.map +1 -1
- package/dist/cmd/build/index.js +5 -23
- package/dist/cmd/build/index.js.map +1 -1
- package/dist/cmd/build/vite/agent-discovery.d.ts +33 -0
- package/dist/cmd/build/vite/agent-discovery.d.ts.map +1 -0
- package/dist/cmd/build/vite/agent-discovery.js +297 -0
- package/dist/cmd/build/vite/agent-discovery.js.map +1 -0
- package/dist/cmd/build/vite/browser-env-plugin.d.ts +9 -0
- package/dist/cmd/build/vite/browser-env-plugin.d.ts.map +1 -0
- package/dist/cmd/build/vite/browser-env-plugin.js +28 -0
- package/dist/cmd/build/vite/browser-env-plugin.js.map +1 -0
- package/dist/cmd/build/vite/bun-dev-server.d.ts +29 -0
- package/dist/cmd/build/vite/bun-dev-server.d.ts.map +1 -0
- package/dist/cmd/build/vite/bun-dev-server.js +54 -0
- package/dist/cmd/build/vite/bun-dev-server.js.map +1 -0
- package/dist/cmd/build/vite/config-loader.d.ts +23 -0
- package/dist/cmd/build/vite/config-loader.d.ts.map +1 -0
- package/dist/cmd/build/vite/config-loader.js +50 -0
- package/dist/cmd/build/vite/config-loader.js.map +1 -0
- package/dist/cmd/build/vite/index.d.ts +26 -0
- package/dist/cmd/build/vite/index.d.ts.map +1 -0
- package/dist/cmd/build/vite/index.js +127 -0
- package/dist/cmd/build/vite/index.js.map +1 -0
- package/dist/cmd/build/vite/lifecycle-generator.d.ts +11 -0
- package/dist/cmd/build/vite/lifecycle-generator.d.ts.map +1 -0
- package/dist/cmd/build/vite/lifecycle-generator.js +35 -0
- package/dist/cmd/build/vite/lifecycle-generator.js.map +1 -0
- package/dist/cmd/build/vite/metadata-generator.d.ts +32 -0
- package/dist/cmd/build/vite/metadata-generator.d.ts.map +1 -0
- package/dist/cmd/build/vite/metadata-generator.js +489 -0
- package/dist/cmd/build/vite/metadata-generator.js.map +1 -0
- package/dist/cmd/build/vite/patch-plugin.d.ts +21 -0
- package/dist/cmd/build/vite/patch-plugin.d.ts.map +1 -0
- package/dist/cmd/build/vite/patch-plugin.js +70 -0
- package/dist/cmd/build/vite/patch-plugin.js.map +1 -0
- package/dist/cmd/build/vite/registry-generator.d.ts +19 -0
- package/dist/cmd/build/vite/registry-generator.d.ts.map +1 -0
- package/dist/cmd/build/{route-registry.js → vite/registry-generator.js} +126 -48
- package/dist/cmd/build/vite/registry-generator.js.map +1 -0
- package/dist/cmd/build/vite/route-discovery.d.ts +58 -0
- package/dist/cmd/build/vite/route-discovery.d.ts.map +1 -0
- package/dist/cmd/build/vite/route-discovery.js +125 -0
- package/dist/cmd/build/vite/route-discovery.js.map +1 -0
- package/dist/cmd/build/vite/server-bundler.d.ts +16 -0
- package/dist/cmd/build/vite/server-bundler.d.ts.map +1 -0
- package/dist/cmd/build/vite/server-bundler.js +194 -0
- package/dist/cmd/build/vite/server-bundler.js.map +1 -0
- package/dist/cmd/build/vite/vite-asset-server-config.d.ts +19 -0
- package/dist/cmd/build/vite/vite-asset-server-config.d.ts.map +1 -0
- package/dist/cmd/build/vite/vite-asset-server-config.js +105 -0
- package/dist/cmd/build/vite/vite-asset-server-config.js.map +1 -0
- package/dist/cmd/build/vite/vite-asset-server.d.ts +23 -0
- package/dist/cmd/build/vite/vite-asset-server.d.ts.map +1 -0
- package/dist/cmd/build/vite/vite-asset-server.js +40 -0
- package/dist/cmd/build/vite/vite-asset-server.js.map +1 -0
- package/dist/cmd/build/vite/vite-builder.d.ts +44 -0
- package/dist/cmd/build/vite/vite-builder.d.ts.map +1 -0
- package/dist/cmd/build/vite/vite-builder.js +232 -0
- package/dist/cmd/build/vite/vite-builder.js.map +1 -0
- package/dist/cmd/build/vite/workbench-generator.d.ts +10 -0
- package/dist/cmd/build/vite/workbench-generator.d.ts.map +1 -0
- package/dist/cmd/build/vite/workbench-generator.js +135 -0
- package/dist/cmd/build/vite/workbench-generator.js.map +1 -0
- package/dist/cmd/build/vite-bundler.d.ts +23 -0
- package/dist/cmd/build/vite-bundler.d.ts.map +1 -0
- package/dist/cmd/build/vite-bundler.js +79 -0
- package/dist/cmd/build/vite-bundler.js.map +1 -0
- package/dist/cmd/cloud/agent/get.d.ts.map +1 -1
- package/dist/cmd/cloud/agent/get.js +1 -0
- package/dist/cmd/cloud/agent/get.js.map +1 -1
- package/dist/cmd/cloud/agent/list.d.ts.map +1 -1
- package/dist/cmd/cloud/agent/list.js +1 -0
- package/dist/cmd/cloud/agent/list.js.map +1 -1
- package/dist/cmd/cloud/db/get.d.ts.map +1 -1
- package/dist/cmd/cloud/db/get.js +1 -0
- package/dist/cmd/cloud/db/get.js.map +1 -1
- package/dist/cmd/cloud/db/list.d.ts.map +1 -1
- package/dist/cmd/cloud/db/list.js +1 -0
- package/dist/cmd/cloud/db/list.js.map +1 -1
- package/dist/cmd/cloud/deploy.d.ts.map +1 -1
- package/dist/cmd/cloud/deploy.js +152 -128
- package/dist/cmd/cloud/deploy.js.map +1 -1
- package/dist/cmd/cloud/deployment/list.d.ts.map +1 -1
- package/dist/cmd/cloud/deployment/list.js +4 -0
- package/dist/cmd/cloud/deployment/list.js.map +1 -1
- package/dist/cmd/cloud/env/list.d.ts.map +1 -1
- package/dist/cmd/cloud/env/list.js +1 -0
- package/dist/cmd/cloud/env/list.js.map +1 -1
- package/dist/cmd/cloud/keyvalue/get.d.ts.map +1 -1
- package/dist/cmd/cloud/keyvalue/get.js +1 -0
- package/dist/cmd/cloud/keyvalue/get.js.map +1 -1
- package/dist/cmd/cloud/keyvalue/keys.d.ts.map +1 -1
- package/dist/cmd/cloud/keyvalue/keys.js +1 -0
- package/dist/cmd/cloud/keyvalue/keys.js.map +1 -1
- package/dist/cmd/cloud/keyvalue/list-namespaces.d.ts.map +1 -1
- package/dist/cmd/cloud/keyvalue/list-namespaces.js +1 -0
- package/dist/cmd/cloud/keyvalue/list-namespaces.js.map +1 -1
- package/dist/cmd/cloud/keyvalue/stats.d.ts.map +1 -1
- package/dist/cmd/cloud/keyvalue/stats.js +1 -0
- package/dist/cmd/cloud/keyvalue/stats.js.map +1 -1
- package/dist/cmd/cloud/secret/list.d.ts.map +1 -1
- package/dist/cmd/cloud/secret/list.js +1 -0
- package/dist/cmd/cloud/secret/list.js.map +1 -1
- package/dist/cmd/cloud/session/list.d.ts.map +1 -1
- package/dist/cmd/cloud/session/list.js +4 -0
- package/dist/cmd/cloud/session/list.js.map +1 -1
- package/dist/cmd/cloud/storage/get.d.ts.map +1 -1
- package/dist/cmd/cloud/storage/get.js +1 -0
- package/dist/cmd/cloud/storage/get.js.map +1 -1
- package/dist/cmd/cloud/storage/list.d.ts.map +1 -1
- package/dist/cmd/cloud/storage/list.js +3 -0
- package/dist/cmd/cloud/storage/list.js.map +1 -1
- package/dist/cmd/cloud/stream/get.d.ts.map +1 -1
- package/dist/cmd/cloud/stream/get.js +1 -0
- package/dist/cmd/cloud/stream/get.js.map +1 -1
- package/dist/cmd/cloud/stream/list.d.ts.map +1 -1
- package/dist/cmd/cloud/stream/list.js +1 -0
- package/dist/cmd/cloud/stream/list.js.map +1 -1
- package/dist/cmd/cloud/vector/get.d.ts.map +1 -1
- package/dist/cmd/cloud/vector/get.js +1 -0
- package/dist/cmd/cloud/vector/get.js.map +1 -1
- package/dist/cmd/cloud/vector/search.d.ts.map +1 -1
- package/dist/cmd/cloud/vector/search.js +1 -0
- package/dist/cmd/cloud/vector/search.js.map +1 -1
- package/dist/cmd/dev/index.d.ts.map +1 -1
- package/dist/cmd/dev/index.js +291 -751
- package/dist/cmd/dev/index.js.map +1 -1
- package/dist/cmd/dev/sync.d.ts +1 -1
- package/dist/cmd/dev/sync.d.ts.map +1 -1
- package/dist/cmd/dev/sync.js +3 -0
- package/dist/cmd/dev/sync.js.map +1 -1
- package/dist/cmd/profile/show.d.ts.map +1 -1
- package/dist/cmd/profile/show.js +3 -4
- package/dist/cmd/profile/show.js.map +1 -1
- package/dist/cmd/project/create.d.ts.map +1 -1
- package/dist/cmd/project/create.js +3 -4
- package/dist/cmd/project/create.js.map +1 -1
- package/dist/cmd/project/list.d.ts.map +1 -1
- package/dist/cmd/project/list.js +1 -0
- package/dist/cmd/project/list.js.map +1 -1
- package/dist/cmd/project/show.d.ts.map +1 -1
- package/dist/cmd/project/show.js +1 -0
- package/dist/cmd/project/show.js.map +1 -1
- package/dist/cmd/upgrade/index.d.ts.map +1 -1
- package/dist/cmd/upgrade/index.js +5 -3
- package/dist/cmd/upgrade/index.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +29 -11
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/runtime-bootstrap.d.ts +3 -2
- package/dist/runtime-bootstrap.d.ts.map +1 -1
- package/dist/runtime-bootstrap.js +7 -2
- package/dist/runtime-bootstrap.js.map +1 -1
- package/dist/schemas/deploy.d.ts +1 -1
- package/dist/types.d.ts +40 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/bun-version-checker.d.ts +11 -0
- package/dist/utils/bun-version-checker.d.ts.map +1 -0
- package/dist/utils/bun-version-checker.js +56 -0
- package/dist/utils/bun-version-checker.js.map +1 -0
- package/dist/version-check.d.ts.map +1 -1
- package/dist/version-check.js +5 -2
- package/dist/version-check.js.map +1 -1
- package/package.json +10 -3
- package/src/auth.ts +9 -5
- package/src/banner.ts +1 -1
- package/src/cli.ts +228 -29
- package/src/cmd/auth/signup.ts +1 -1
- package/src/cmd/build/ast.ts +7 -0
- package/src/cmd/build/entry-generator.ts +404 -0
- package/src/cmd/build/index.ts +7 -28
- package/src/cmd/build/vite/agent-discovery.ts +467 -0
- package/src/cmd/build/vite/browser-env-plugin.ts +34 -0
- package/src/cmd/build/vite/bun-dev-server.ts +78 -0
- package/src/cmd/build/vite/config-loader.ts +70 -0
- package/src/cmd/build/vite/index.ts +166 -0
- package/src/cmd/build/vite/lifecycle-generator.ts +43 -0
- package/src/cmd/build/vite/metadata-generator.ts +602 -0
- package/src/cmd/build/vite/patch-plugin.ts +88 -0
- package/src/cmd/build/vite/registry-generator.ts +288 -0
- package/src/cmd/build/vite/route-discovery.ts +186 -0
- package/src/cmd/build/vite/server-bundler.ts +258 -0
- package/src/cmd/build/vite/vite-asset-server-config.ts +134 -0
- package/src/cmd/build/vite/vite-asset-server.ts +63 -0
- package/src/cmd/build/vite/vite-builder.ts +284 -0
- package/src/cmd/build/vite/workbench-generator.ts +152 -0
- package/src/cmd/build/vite-bundler.ts +110 -0
- package/src/cmd/cloud/agent/get.ts +2 -0
- package/src/cmd/cloud/agent/list.ts +1 -0
- package/src/cmd/cloud/db/get.ts +1 -0
- package/src/cmd/cloud/db/list.ts +1 -0
- package/src/cmd/cloud/deploy.ts +175 -144
- package/src/cmd/cloud/deployment/list.ts +4 -0
- package/src/cmd/cloud/env/list.ts +1 -0
- package/src/cmd/cloud/keyvalue/get.ts +1 -0
- package/src/cmd/cloud/keyvalue/keys.ts +1 -0
- package/src/cmd/cloud/keyvalue/list-namespaces.ts +1 -0
- package/src/cmd/cloud/keyvalue/stats.ts +2 -0
- package/src/cmd/cloud/secret/list.ts +1 -0
- package/src/cmd/cloud/session/list.ts +4 -0
- package/src/cmd/cloud/storage/get.ts +1 -0
- package/src/cmd/cloud/storage/list.ts +4 -0
- package/src/cmd/cloud/stream/get.ts +1 -0
- package/src/cmd/cloud/stream/list.ts +1 -0
- package/src/cmd/cloud/vector/get.ts +1 -0
- package/src/cmd/cloud/vector/search.ts +1 -0
- package/src/cmd/dev/index.ts +323 -914
- package/src/cmd/dev/sync.ts +5 -1
- package/src/cmd/profile/show.ts +3 -4
- package/src/cmd/project/create.ts +3 -4
- package/src/cmd/project/list.ts +1 -0
- package/src/cmd/project/show.ts +1 -0
- package/src/cmd/upgrade/index.ts +6 -3
- package/src/config.ts +31 -11
- package/src/index.ts +2 -0
- package/src/runtime-bootstrap.ts +8 -2
- package/src/types.ts +48 -1
- package/src/utils/bun-version-checker.ts +70 -0
- package/src/version-check.ts +6 -2
- package/dist/cmd/build/bundler.d.ts +0 -22
- package/dist/cmd/build/bundler.d.ts.map +0 -1
- package/dist/cmd/build/bundler.js +0 -766
- package/dist/cmd/build/bundler.js.map +0 -1
- package/dist/cmd/build/config-loader.d.ts +0 -16
- package/dist/cmd/build/config-loader.d.ts.map +0 -1
- package/dist/cmd/build/config-loader.js +0 -227
- package/dist/cmd/build/config-loader.js.map +0 -1
- package/dist/cmd/build/file.d.ts +0 -2
- package/dist/cmd/build/file.d.ts.map +0 -1
- package/dist/cmd/build/file.js +0 -10
- package/dist/cmd/build/file.js.map +0 -1
- package/dist/cmd/build/fix-duplicate-exports.d.ts +0 -2
- package/dist/cmd/build/fix-duplicate-exports.d.ts.map +0 -1
- package/dist/cmd/build/fix-duplicate-exports.js +0 -170
- package/dist/cmd/build/fix-duplicate-exports.js.map +0 -1
- package/dist/cmd/build/plugin.d.ts +0 -6
- package/dist/cmd/build/plugin.d.ts.map +0 -1
- package/dist/cmd/build/plugin.js +0 -645
- package/dist/cmd/build/plugin.js.map +0 -1
- package/dist/cmd/build/route-discovery.d.ts +0 -54
- package/dist/cmd/build/route-discovery.d.ts.map +0 -1
- package/dist/cmd/build/route-discovery.js +0 -148
- package/dist/cmd/build/route-discovery.js.map +0 -1
- package/dist/cmd/build/route-registry.d.ts +0 -38
- package/dist/cmd/build/route-registry.d.ts.map +0 -1
- package/dist/cmd/build/route-registry.js.map +0 -1
- package/src/cmd/build/bundler.ts +0 -927
- package/src/cmd/build/config-loader.ts +0 -268
- package/src/cmd/build/file.ts +0 -10
- package/src/cmd/build/fix-duplicate-exports.ts +0 -207
- package/src/cmd/build/plugin.ts +0 -782
- package/src/cmd/build/route-discovery.ts +0 -202
- package/src/cmd/build/route-registry.ts +0 -222
|
@@ -1,766 +0,0 @@
|
|
|
1
|
-
import { $, semver } from 'bun';
|
|
2
|
-
import { join, relative, resolve, dirname, basename } from 'node:path';
|
|
3
|
-
import { cpSync, existsSync, mkdirSync, rmSync, readdirSync, readFileSync } from 'node:fs';
|
|
4
|
-
import gitParseUrl from 'git-url-parse';
|
|
5
|
-
import { StructuredError } from '@agentuity/core';
|
|
6
|
-
import * as tui from '../../tui';
|
|
7
|
-
import { pauseStepUI } from '../../steps';
|
|
8
|
-
import AgentuityBundler, { getBuildMetadata } from './plugin';
|
|
9
|
-
import { getFilesRecursively } from './file';
|
|
10
|
-
import { getVersion } from '../../version';
|
|
11
|
-
import { fixDuplicateExportsInDirectory } from './fix-duplicate-exports';
|
|
12
|
-
import { generateWorkbenchMainTsx, generateWorkbenchIndexHtml } from './workbench';
|
|
13
|
-
import { analyzeWorkbench } from './ast';
|
|
14
|
-
import { checkAndUpgradeDependencies } from '../../utils/dependency-checker';
|
|
15
|
-
import { loadBuildConfig, executeBuildConfig, mergeBuildConfig } from './config-loader';
|
|
16
|
-
const minBunVersion = '>=1.3.3';
|
|
17
|
-
async function checkBunVersion() {
|
|
18
|
-
if (semver.satisfies(Bun.version, minBunVersion)) {
|
|
19
|
-
return []; // Version is OK, no output needed
|
|
20
|
-
}
|
|
21
|
-
const message = `Bun is using version ${Bun.version}. This project requires Bun version ${minBunVersion} to build.`;
|
|
22
|
-
if (process.stdin.isTTY && process.stdout.isTTY) {
|
|
23
|
-
// Pause the step UI for interactive prompt
|
|
24
|
-
const resume = pauseStepUI();
|
|
25
|
-
tui.warning(message);
|
|
26
|
-
const ok = await tui.confirm('Would you like to upgrade now?');
|
|
27
|
-
// Small delay to ensure console.log('') in confirm completes
|
|
28
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
29
|
-
resume(); // Resume step UI
|
|
30
|
-
if (ok) {
|
|
31
|
-
await $ `bun upgrade`.quiet();
|
|
32
|
-
const version = (await $ `bun -v`.quiet().text()).trim();
|
|
33
|
-
// Return success message to show in output box
|
|
34
|
-
return [tui.colorSuccess(`Upgraded Bun to ${version}`)];
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
// Failed to upgrade or user declined
|
|
38
|
-
throw new InvalidBunVersion({
|
|
39
|
-
current: Bun.version,
|
|
40
|
-
required: minBunVersion,
|
|
41
|
-
message,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
const AppFileNotFoundError = StructuredError('AppFileNotFoundError');
|
|
45
|
-
const AgentsDirNotFoundError = StructuredError('AgentsDirNotFoundError');
|
|
46
|
-
const BuildFailedError = StructuredError('BuildFailedError')();
|
|
47
|
-
const InvalidBunVersion = StructuredError('InvalidBunVersion')();
|
|
48
|
-
/**
|
|
49
|
-
* Finds the workspace root by walking up the directory tree looking for a package.json with workspaces
|
|
50
|
-
*/
|
|
51
|
-
function findWorkspaceRoot(startDir) {
|
|
52
|
-
let currentDir = startDir;
|
|
53
|
-
while (true) {
|
|
54
|
-
const pkgPath = join(currentDir, 'package.json');
|
|
55
|
-
if (existsSync(pkgPath)) {
|
|
56
|
-
try {
|
|
57
|
-
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
|
58
|
-
if (pkg.workspaces) {
|
|
59
|
-
return currentDir;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
// Ignore parse errors, continue searching
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const parent = resolve(currentDir, '..');
|
|
67
|
-
if (parent === currentDir)
|
|
68
|
-
break; // reached filesystem root
|
|
69
|
-
currentDir = parent;
|
|
70
|
-
}
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Finds a package by searching multiple locations:
|
|
75
|
-
* 1. App-level node_modules
|
|
76
|
-
* 2. Workspace root node_modules
|
|
77
|
-
* 3. Workspace packages directory (for workspace packages)
|
|
78
|
-
*
|
|
79
|
-
* @param rootDir - Root directory of the project
|
|
80
|
-
* @param packageName - Package name (e.g., '@agentuity/workbench')
|
|
81
|
-
* @param logger - Optional logger for debug messages
|
|
82
|
-
* @returns Path to the package directory, or null if not found
|
|
83
|
-
*/
|
|
84
|
-
function findPackagePath(rootDir, packageName, logger) {
|
|
85
|
-
const [scope, name] = packageName.startsWith('@')
|
|
86
|
-
? packageName.slice(1).split('/')
|
|
87
|
-
: [null, packageName];
|
|
88
|
-
// 1. Try app-level node_modules
|
|
89
|
-
const appLevelPath = scope
|
|
90
|
-
? join(rootDir, 'node_modules', `@${scope}`, name)
|
|
91
|
-
: join(rootDir, 'node_modules', name);
|
|
92
|
-
if (existsSync(appLevelPath)) {
|
|
93
|
-
logger?.debug(`Found ${packageName} at app level: ${appLevelPath}`);
|
|
94
|
-
return appLevelPath;
|
|
95
|
-
}
|
|
96
|
-
// 2. Try workspace root node_modules
|
|
97
|
-
const workspaceRoot = findWorkspaceRoot(rootDir);
|
|
98
|
-
if (workspaceRoot) {
|
|
99
|
-
const rootLevelPath = scope
|
|
100
|
-
? join(workspaceRoot, 'node_modules', `@${scope}`, name)
|
|
101
|
-
: join(workspaceRoot, 'node_modules', name);
|
|
102
|
-
if (existsSync(rootLevelPath)) {
|
|
103
|
-
logger?.debug(`Found ${packageName} at workspace root: ${rootLevelPath}`);
|
|
104
|
-
return rootLevelPath;
|
|
105
|
-
}
|
|
106
|
-
// 3. Try workspace packages directory
|
|
107
|
-
const workspacePackagePath = join(workspaceRoot, 'packages', name);
|
|
108
|
-
if (existsSync(workspacePackagePath)) {
|
|
109
|
-
logger?.debug(`Found ${packageName} in workspace packages: ${workspacePackagePath}`);
|
|
110
|
-
return workspacePackagePath;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
const handleBuildFailure = (buildResult) => {
|
|
116
|
-
// Collect all build errors with full details
|
|
117
|
-
const errorMessages = buildResult.logs
|
|
118
|
-
.map((log) => {
|
|
119
|
-
const parts = [log.message];
|
|
120
|
-
if (log.position) {
|
|
121
|
-
parts.push(` at ${log.position.file}:${log.position.line}:${log.position.column}`);
|
|
122
|
-
}
|
|
123
|
-
return parts.join('\n');
|
|
124
|
-
})
|
|
125
|
-
.join('\n');
|
|
126
|
-
throw new BuildFailedError({
|
|
127
|
-
message: errorMessages || 'Build failed with no error messages',
|
|
128
|
-
logs: buildResult.logs,
|
|
129
|
-
});
|
|
130
|
-
};
|
|
131
|
-
export async function bundle({ orgId, projectId, deploymentId, dev = false, rootDir, project, outDir: customOutDir, tag, logsUrl, commitUrl, provider, trigger, event, pullRequestNumber, pullRequestCommentId, pullRequestURL, message, env, region, logger, workbench, }) {
|
|
132
|
-
const output = [];
|
|
133
|
-
const appFile = join(rootDir, 'app.ts');
|
|
134
|
-
if (!existsSync(appFile)) {
|
|
135
|
-
throw new AppFileNotFoundError({
|
|
136
|
-
message: `App file not found at expected location: ${appFile}`,
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
const versionOutput = await checkBunVersion();
|
|
140
|
-
output.push(...versionOutput);
|
|
141
|
-
// Check and upgrade @agentuity/* dependencies if needed
|
|
142
|
-
const upgradeResult = await checkAndUpgradeDependencies(rootDir, logger);
|
|
143
|
-
if (upgradeResult.failed.length > 0 && process.stdin.isTTY) {
|
|
144
|
-
throw new BuildFailedError({
|
|
145
|
-
message: `Failed to upgrade dependencies: ${upgradeResult.failed.join(', ')}`,
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
const outDir = customOutDir ?? join(rootDir, '.agentuity');
|
|
149
|
-
const srcDir = join(rootDir, 'src');
|
|
150
|
-
const appEntrypoints = [];
|
|
151
|
-
for (const folder of ['web', 'agent']) {
|
|
152
|
-
const dir = join(srcDir, folder);
|
|
153
|
-
if (!existsSync(dir)) {
|
|
154
|
-
if (folder === 'agent') {
|
|
155
|
-
throw new AgentsDirNotFoundError({ message: `Expected directory not found: ${dir}` });
|
|
156
|
-
}
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
const files = await getFilesRecursively(dir);
|
|
160
|
-
for (const filename of files) {
|
|
161
|
-
if (/\.[jt]s?$/.test(filename) &&
|
|
162
|
-
!filename.includes('.generated.') &&
|
|
163
|
-
basename(filename) !== 'AGENTS.md') {
|
|
164
|
-
appEntrypoints.push(filename);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
appEntrypoints.push(appFile);
|
|
169
|
-
if (existsSync(outDir)) {
|
|
170
|
-
rmSync(outDir, { recursive: true, force: true });
|
|
171
|
-
}
|
|
172
|
-
// Ensure output directory and subdirectories exist before building
|
|
173
|
-
mkdirSync(outDir, { recursive: true });
|
|
174
|
-
mkdirSync(join(outDir, 'chunk'), { recursive: true });
|
|
175
|
-
mkdirSync(join(outDir, 'asset'), { recursive: true });
|
|
176
|
-
// Pre-create all nested source directories in output
|
|
177
|
-
// This is needed because Bun.build with naming.entry preserves structure
|
|
178
|
-
// but doesn't create nested directories automatically
|
|
179
|
-
for (const entrypoint of appEntrypoints) {
|
|
180
|
-
const relPath = relative(rootDir, dirname(entrypoint));
|
|
181
|
-
const outputSubdir = join(outDir, relPath);
|
|
182
|
-
mkdirSync(outputSubdir, { recursive: true });
|
|
183
|
-
}
|
|
184
|
-
const pkgFile = Bun.file(join(rootDir, 'package.json'));
|
|
185
|
-
const pkgContents = JSON.parse(await pkgFile.text());
|
|
186
|
-
const isProd = !dev;
|
|
187
|
-
const define = {
|
|
188
|
-
'process.env.AGENTUITY_CLOUD_SDK_VERSION': JSON.stringify(getVersion() ?? '1.0.0'),
|
|
189
|
-
'process.env.NODE_ENV': JSON.stringify(isProd ? 'production' : 'development'),
|
|
190
|
-
};
|
|
191
|
-
if (orgId) {
|
|
192
|
-
define['process.env.AGENTUITY_CLOUD_ORG_ID'] = JSON.stringify(orgId);
|
|
193
|
-
}
|
|
194
|
-
if (projectId) {
|
|
195
|
-
define['process.env.AGENTUITY_CLOUD_PROJECT_ID'] = JSON.stringify(projectId);
|
|
196
|
-
}
|
|
197
|
-
if (deploymentId) {
|
|
198
|
-
define['process.env.AGENTUITY_CLOUD_DEPLOYMENT_ID'] = JSON.stringify(deploymentId);
|
|
199
|
-
}
|
|
200
|
-
if (env) {
|
|
201
|
-
for (const [key, value] of env) {
|
|
202
|
-
define[`process.env.${key}`] = JSON.stringify(value);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
// Common externals for native modules (same as legacy CLI)
|
|
206
|
-
const commonExternals = ['bun', 'fsevents', 'chromium-bidi', 'sharp'];
|
|
207
|
-
// Allow projects to specify custom externals via package.json "externals" field
|
|
208
|
-
const customExternals = [];
|
|
209
|
-
if (pkgContents.externals && Array.isArray(pkgContents.externals)) {
|
|
210
|
-
customExternals.push(...pkgContents.externals.filter((e) => typeof e === 'string'));
|
|
211
|
-
}
|
|
212
|
-
const externalPatterns = [...commonExternals, ...customExternals];
|
|
213
|
-
// For production builds: install externals FIRST, then discover full dependency tree
|
|
214
|
-
// This prevents bundling dependencies that will be in node_modules anyway
|
|
215
|
-
let external = externalPatterns;
|
|
216
|
-
if (!dev) {
|
|
217
|
-
logger.debug('Installing externalized packages to discover full dependency tree...');
|
|
218
|
-
// Step 1: Collect packages matching external patterns
|
|
219
|
-
const externalInstalls = [];
|
|
220
|
-
for (const pattern of externalPatterns) {
|
|
221
|
-
if (pattern.endsWith('/*')) {
|
|
222
|
-
const prefix = pattern.slice(0, -2);
|
|
223
|
-
const nmDir = join(rootDir, 'node_modules', prefix);
|
|
224
|
-
if (existsSync(nmDir)) {
|
|
225
|
-
const entries = readdirSync(nmDir);
|
|
226
|
-
for (const entry of entries) {
|
|
227
|
-
const pkgName = `${prefix}/${entry}`;
|
|
228
|
-
if (existsSync(join(rootDir, 'node_modules', pkgName))) {
|
|
229
|
-
externalInstalls.push(pkgName);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
if (existsSync(join(rootDir, 'node_modules', pattern))) {
|
|
236
|
-
externalInstalls.push(pattern);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
// Step 2: Write minimal package.json and install externals
|
|
241
|
-
if (externalInstalls.length > 0) {
|
|
242
|
-
await Bun.write(`${outDir}/package.json`, JSON.stringify({ name: pkgContents.name, version: pkgContents.version }, null, 2));
|
|
243
|
-
logger.debug('Installing %d packages: %s', externalInstalls.length, externalInstalls.join(', '));
|
|
244
|
-
await $ `bun install --no-save --ignore-scripts --target=bun-linux-x64 ${externalInstalls}`
|
|
245
|
-
.cwd(outDir)
|
|
246
|
-
.quiet();
|
|
247
|
-
// Step 3: Scan what actually got installed (includes transitive dependencies)
|
|
248
|
-
const installedNmDir = join(outDir, 'node_modules');
|
|
249
|
-
if (existsSync(installedNmDir)) {
|
|
250
|
-
const allInstalled = [];
|
|
251
|
-
// Recursively find all installed packages
|
|
252
|
-
const scanDir = (dir, prefix = '') => {
|
|
253
|
-
const entries = readdirSync(dir, { withFileTypes: true });
|
|
254
|
-
for (const entry of entries) {
|
|
255
|
-
if (entry.isDirectory()) {
|
|
256
|
-
const pkgName = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
257
|
-
// Check if this is a package (has package.json)
|
|
258
|
-
if (existsSync(join(dir, entry.name, 'package.json'))) {
|
|
259
|
-
allInstalled.push(pkgName);
|
|
260
|
-
}
|
|
261
|
-
// Recurse into scoped packages (@org/package)
|
|
262
|
-
if (entry.name.startsWith('@')) {
|
|
263
|
-
scanDir(join(dir, entry.name), entry.name);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
scanDir(installedNmDir);
|
|
269
|
-
logger.debug('Discovered %d total packages (including dependencies)', allInstalled.length);
|
|
270
|
-
// Step 4: Use ALL installed packages as externals for bundling
|
|
271
|
-
external = allInstalled;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
const tsconfigPath = join(rootDir, 'tsconfig.json');
|
|
276
|
-
const hasTsconfig = existsSync(tsconfigPath);
|
|
277
|
-
// Load user build config (if it exists)
|
|
278
|
-
const buildConfigFunction = await loadBuildConfig(rootDir);
|
|
279
|
-
// Helper to create build context for config function
|
|
280
|
-
const createBuildContext = () => ({
|
|
281
|
-
rootDir,
|
|
282
|
-
dev,
|
|
283
|
-
outDir,
|
|
284
|
-
srcDir,
|
|
285
|
-
orgId,
|
|
286
|
-
projectId,
|
|
287
|
-
region,
|
|
288
|
-
logger,
|
|
289
|
-
});
|
|
290
|
-
await (async () => {
|
|
291
|
-
const baseConfig = {
|
|
292
|
-
entrypoints: appEntrypoints,
|
|
293
|
-
root: rootDir,
|
|
294
|
-
outdir: outDir,
|
|
295
|
-
define,
|
|
296
|
-
sourcemap: dev ? 'inline' : 'external',
|
|
297
|
-
env: 'disable',
|
|
298
|
-
plugins: [AgentuityBundler],
|
|
299
|
-
target: 'bun',
|
|
300
|
-
format: 'esm',
|
|
301
|
-
banner: `// Generated file. DO NOT EDIT`,
|
|
302
|
-
// Disable minify for server bundle (keep code readable for debugging)
|
|
303
|
-
minify: !dev,
|
|
304
|
-
drop: isProd ? ['debugger'] : undefined,
|
|
305
|
-
// Disable splitting - causes module initialization issues with externalized packages
|
|
306
|
-
// The chunk helper functions (__commonJS, __esm, etc.) don't properly handle
|
|
307
|
-
// CommonJS packages in node_modules that require() other modules
|
|
308
|
-
splitting: false,
|
|
309
|
-
conditions: [isProd ? 'production' : 'development', 'bun'],
|
|
310
|
-
external,
|
|
311
|
-
naming: {
|
|
312
|
-
entry: '[dir]/[name].[ext]',
|
|
313
|
-
chunk: 'chunk/[name]-[hash].[ext]',
|
|
314
|
-
asset: 'asset/[name]-[hash].[ext]',
|
|
315
|
-
},
|
|
316
|
-
tsconfig: hasTsconfig ? tsconfigPath : undefined,
|
|
317
|
-
};
|
|
318
|
-
// Apply user config for 'api' phase
|
|
319
|
-
let finalConfig = baseConfig;
|
|
320
|
-
if (buildConfigFunction) {
|
|
321
|
-
const userConfig = await executeBuildConfig(buildConfigFunction, 'api', createBuildContext());
|
|
322
|
-
finalConfig = mergeBuildConfig(baseConfig, userConfig);
|
|
323
|
-
}
|
|
324
|
-
const buildResult = await Bun.build(finalConfig);
|
|
325
|
-
if (!buildResult.success) {
|
|
326
|
-
handleBuildFailure(buildResult);
|
|
327
|
-
}
|
|
328
|
-
})();
|
|
329
|
-
const buildmetadata = getBuildMetadata();
|
|
330
|
-
buildmetadata.assets = [];
|
|
331
|
-
buildmetadata.project = {
|
|
332
|
-
id: projectId ?? '',
|
|
333
|
-
name: pkgContents.name,
|
|
334
|
-
version: pkgContents.version,
|
|
335
|
-
description: pkgContents.description,
|
|
336
|
-
keywords: pkgContents.keywords,
|
|
337
|
-
orgId: orgId ?? '',
|
|
338
|
-
};
|
|
339
|
-
buildmetadata.deployment = {
|
|
340
|
-
...(project?.deployment ?? {}),
|
|
341
|
-
build: {
|
|
342
|
-
bun: Bun.version,
|
|
343
|
-
agentuity: '',
|
|
344
|
-
arch: process.arch,
|
|
345
|
-
platform: process.platform,
|
|
346
|
-
},
|
|
347
|
-
date: new Date().toUTCString(),
|
|
348
|
-
id: deploymentId ?? '',
|
|
349
|
-
};
|
|
350
|
-
if (!dev) {
|
|
351
|
-
// try local first
|
|
352
|
-
const agNMPackage = join(rootDir, 'node_modules', '@agentuity', 'cli', 'package.json');
|
|
353
|
-
if (existsSync(agNMPackage)) {
|
|
354
|
-
try {
|
|
355
|
-
const npmpkg = await Bun.file(agNMPackage).json();
|
|
356
|
-
if (npmpkg.version) {
|
|
357
|
-
buildmetadata.deployment.build.agentuity = npmpkg.version;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
catch {
|
|
361
|
-
// Ignore malformed package.json
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
try {
|
|
366
|
-
// now try the global
|
|
367
|
-
const r = $ `bunx @agentuity/cli version`.quiet().nothrow();
|
|
368
|
-
if (r) {
|
|
369
|
-
const version = await r.text();
|
|
370
|
-
if (version) {
|
|
371
|
-
buildmetadata.deployment.build.agentuity = version.trim();
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
catch {
|
|
376
|
-
// ignore error from bunx
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
// must always set for the template always
|
|
381
|
-
define['process.env.AGENTUITY_PUBLIC_WORKBENCH_PATH'] = JSON.stringify('');
|
|
382
|
-
// Analyze workbench config early to set environment variables for web build
|
|
383
|
-
if (existsSync(appFile)) {
|
|
384
|
-
if (!workbench) {
|
|
385
|
-
const appContent = await Bun.file(appFile).text();
|
|
386
|
-
workbench = analyzeWorkbench(appContent);
|
|
387
|
-
}
|
|
388
|
-
if (workbench.hasWorkbench) {
|
|
389
|
-
// Create workbench config with proper defaults
|
|
390
|
-
const defaultConfig = { route: '/workbench', headers: {} };
|
|
391
|
-
const config = { ...defaultConfig, ...workbench.config };
|
|
392
|
-
// Add to define so process.env.AGENTUITY_PUBLIC_WORKBENCH_PATH gets replaced at build time
|
|
393
|
-
define['process.env.AGENTUITY_PUBLIC_WORKBENCH_PATH'] = JSON.stringify(config.route);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
// web folder is optional
|
|
397
|
-
const webDir = join(srcDir, 'web');
|
|
398
|
-
if (existsSync(webDir)) {
|
|
399
|
-
await (async () => {
|
|
400
|
-
// Find workspace root for monorepo support
|
|
401
|
-
let workspaceRoot = rootDir;
|
|
402
|
-
let currentDir = rootDir;
|
|
403
|
-
while (true) {
|
|
404
|
-
const pkgPath = join(currentDir, 'package.json');
|
|
405
|
-
if (existsSync(pkgPath)) {
|
|
406
|
-
const pkg = JSON.parse(await Bun.file(pkgPath).text());
|
|
407
|
-
if (pkg.workspaces) {
|
|
408
|
-
workspaceRoot = currentDir;
|
|
409
|
-
break;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
const parent = resolve(currentDir, '..');
|
|
413
|
-
if (parent === currentDir)
|
|
414
|
-
break; // reached filesystem root
|
|
415
|
-
currentDir = parent;
|
|
416
|
-
}
|
|
417
|
-
// Make webEntrypoints - just the HTML files themselves
|
|
418
|
-
const webEntrypoints = [...new Bun.Glob('**.html').scanSync(webDir)].map((htmlFile) => resolve(webDir, htmlFile));
|
|
419
|
-
if (webEntrypoints.length) {
|
|
420
|
-
const webOutDir = join(outDir, 'web');
|
|
421
|
-
mkdirSync(webOutDir, { recursive: true });
|
|
422
|
-
mkdirSync(join(webOutDir, 'chunk'), { recursive: true });
|
|
423
|
-
mkdirSync(join(webOutDir, 'asset'), { recursive: true });
|
|
424
|
-
const isLocalRegion = region === 'local' || region === 'l';
|
|
425
|
-
const baseConfig = {
|
|
426
|
-
entrypoints: webEntrypoints,
|
|
427
|
-
root: webDir,
|
|
428
|
-
outdir: webOutDir,
|
|
429
|
-
define,
|
|
430
|
-
sourcemap: dev ? 'inline' : 'linked',
|
|
431
|
-
env: 'AGENTUITY_PUBLIC_*',
|
|
432
|
-
plugins: [AgentuityBundler],
|
|
433
|
-
target: 'browser',
|
|
434
|
-
format: 'esm',
|
|
435
|
-
banner: `// Generated file. DO NOT EDIT`,
|
|
436
|
-
minify: true,
|
|
437
|
-
drop: isProd ? ['debugger'] : undefined,
|
|
438
|
-
splitting: true,
|
|
439
|
-
packages: 'bundle',
|
|
440
|
-
external: workspaceRoot !== rootDir ? [] : undefined,
|
|
441
|
-
// Ensure React is resolved from the consuming app's node_modules
|
|
442
|
-
conditions: ['browser', 'import', 'default'],
|
|
443
|
-
publicPath: isProd && deploymentId && !isLocalRegion
|
|
444
|
-
? `https://static.agentuity.com/${deploymentId}/`
|
|
445
|
-
: undefined,
|
|
446
|
-
naming: {
|
|
447
|
-
entry: '[dir]/[name].[ext]',
|
|
448
|
-
chunk: 'web/chunk/[name]-[hash].[ext]',
|
|
449
|
-
asset: 'web/asset/[name]-[hash].[ext]',
|
|
450
|
-
},
|
|
451
|
-
tsconfig: hasTsconfig ? tsconfigPath : undefined,
|
|
452
|
-
};
|
|
453
|
-
// Apply user config for 'web' phase
|
|
454
|
-
let finalConfig = baseConfig;
|
|
455
|
-
if (buildConfigFunction) {
|
|
456
|
-
const userConfig = await executeBuildConfig(buildConfigFunction, 'web', createBuildContext());
|
|
457
|
-
finalConfig = mergeBuildConfig(baseConfig, userConfig);
|
|
458
|
-
}
|
|
459
|
-
const result = await Bun.build(finalConfig);
|
|
460
|
-
if (result.success) {
|
|
461
|
-
// Fix duplicate exports caused by Bun splitting bug
|
|
462
|
-
// See: https://github.com/oven-sh/bun/issues/5344
|
|
463
|
-
await fixDuplicateExportsInDirectory(join(outDir, 'web'), false);
|
|
464
|
-
if (!dev && buildmetadata?.assets) {
|
|
465
|
-
const assets = buildmetadata.assets;
|
|
466
|
-
result.outputs
|
|
467
|
-
// Filter for deployable assets: sourcemaps (hash '00000000') and content-addressed files
|
|
468
|
-
.filter((x) => x.hash === '00000000' || (x.hash && x.path.includes(x.hash)))
|
|
469
|
-
.forEach((artifact) => {
|
|
470
|
-
const r = relative(join(outDir, 'web'), artifact.path);
|
|
471
|
-
assets.push({
|
|
472
|
-
filename: r,
|
|
473
|
-
kind: artifact.kind,
|
|
474
|
-
contentType: artifact.type,
|
|
475
|
-
size: artifact.size,
|
|
476
|
-
});
|
|
477
|
-
});
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
else {
|
|
481
|
-
handleBuildFailure(result);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
})();
|
|
485
|
-
}
|
|
486
|
-
// Bundle workbench app if detected via setupWorkbench
|
|
487
|
-
if (existsSync(appFile) && workbench && workbench.hasWorkbench) {
|
|
488
|
-
// Create workbench config with proper defaults
|
|
489
|
-
const defaultConfig = { route: '/workbench', headers: {} };
|
|
490
|
-
const config = { ...defaultConfig, ...workbench.config, projectId: projectId };
|
|
491
|
-
try {
|
|
492
|
-
// Generate workbench files on the fly instead of using files from package
|
|
493
|
-
const tempWorkbenchDir = join(outDir, 'temp-workbench');
|
|
494
|
-
mkdirSync(tempWorkbenchDir, { recursive: true });
|
|
495
|
-
// Generate files using templates
|
|
496
|
-
await Bun.write(join(tempWorkbenchDir, 'main.tsx'), generateWorkbenchMainTsx(config));
|
|
497
|
-
// Copy the pre-built standalone.css from workbench package instead of generating it
|
|
498
|
-
// This ensures we use the built version with Tailwind already processed
|
|
499
|
-
const workbenchPackagePath = findPackagePath(rootDir, '@agentuity/workbench', logger);
|
|
500
|
-
const workbenchStylesOut = join(tempWorkbenchDir, 'styles.css');
|
|
501
|
-
if (workbenchPackagePath) {
|
|
502
|
-
const workbenchStylesPath = join(workbenchPackagePath, 'dist', 'standalone.css');
|
|
503
|
-
const workbenchStylesSourcePath = join(workbenchPackagePath, 'src', 'standalone.css');
|
|
504
|
-
if (existsSync(workbenchStylesPath)) {
|
|
505
|
-
cpSync(workbenchStylesPath, workbenchStylesOut);
|
|
506
|
-
logger.debug('Copied workbench dist/standalone.css to temp workbench dir');
|
|
507
|
-
}
|
|
508
|
-
else if (existsSync(workbenchStylesSourcePath)) {
|
|
509
|
-
// Fallback: copy source CSS file (contains Tailwind directives that need processing)
|
|
510
|
-
cpSync(workbenchStylesSourcePath, workbenchStylesOut);
|
|
511
|
-
logger.warn('Workbench dist/standalone.css not found, using source CSS. Ensure @agentuity/workbench is built.');
|
|
512
|
-
}
|
|
513
|
-
else {
|
|
514
|
-
throw new BuildFailedError({
|
|
515
|
-
message: `Workbench styles not found in ${workbenchPackagePath}. Expected either:
|
|
516
|
-
- ${workbenchStylesPath}
|
|
517
|
-
- ${workbenchStylesSourcePath}
|
|
518
|
-
|
|
519
|
-
Make sure @agentuity/workbench is built.`,
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
else {
|
|
524
|
-
throw new BuildFailedError({
|
|
525
|
-
message: `Workbench package not found. Searched in:
|
|
526
|
-
- App-level node_modules
|
|
527
|
-
- Workspace root node_modules
|
|
528
|
-
- Workspace packages directory
|
|
529
|
-
|
|
530
|
-
Make sure @agentuity/workbench is installed or available in the workspace.`,
|
|
531
|
-
});
|
|
532
|
-
}
|
|
533
|
-
const workbenchIndexFile = join(tempWorkbenchDir, 'index.html');
|
|
534
|
-
await Bun.write(workbenchIndexFile, generateWorkbenchIndexHtml());
|
|
535
|
-
// Bundle workbench using generated files
|
|
536
|
-
// Disable splitting to avoid CommonJS/ESM module resolution conflicts
|
|
537
|
-
const workbenchBaseConfig = {
|
|
538
|
-
entrypoints: [workbenchIndexFile],
|
|
539
|
-
outdir: join(outDir, 'workbench'),
|
|
540
|
-
sourcemap: dev ? 'inline' : 'linked',
|
|
541
|
-
target: 'browser',
|
|
542
|
-
format: 'esm',
|
|
543
|
-
banner: `// Generated file. DO NOT EDIT`,
|
|
544
|
-
minify: !dev,
|
|
545
|
-
drop: isProd ? ['debugger'] : undefined,
|
|
546
|
-
splitting: false,
|
|
547
|
-
packages: 'bundle',
|
|
548
|
-
conditions: ['browser', 'import', 'default'],
|
|
549
|
-
naming: {
|
|
550
|
-
entry: '[dir]/[name].[ext]',
|
|
551
|
-
chunk: 'workbench/chunk/[name]-[hash].[ext]',
|
|
552
|
-
asset: 'workbench/asset/[name]-[hash].[ext]',
|
|
553
|
-
},
|
|
554
|
-
};
|
|
555
|
-
// Apply user config for 'workbench' phase
|
|
556
|
-
let finalWorkbenchConfig = workbenchBaseConfig;
|
|
557
|
-
if (buildConfigFunction) {
|
|
558
|
-
const userConfig = await executeBuildConfig(buildConfigFunction, 'workbench', createBuildContext());
|
|
559
|
-
finalWorkbenchConfig = mergeBuildConfig(workbenchBaseConfig, userConfig);
|
|
560
|
-
}
|
|
561
|
-
const workbenchResult = await Bun.build(finalWorkbenchConfig);
|
|
562
|
-
if (workbenchResult.success) {
|
|
563
|
-
logger.debug('Workbench bundled successfully');
|
|
564
|
-
// Clean up temp directory
|
|
565
|
-
rmSync(tempWorkbenchDir, { recursive: true, force: true });
|
|
566
|
-
}
|
|
567
|
-
else {
|
|
568
|
-
logger.error('Workbench bundling failed. Logs:', workbenchResult.logs);
|
|
569
|
-
if (workbenchResult.logs.length === 0) {
|
|
570
|
-
logger.error('No build logs available. Checking generated files...');
|
|
571
|
-
logger.error('Temp dir exists:', await Bun.file(tempWorkbenchDir).exists());
|
|
572
|
-
logger.error('Index file exists:', await Bun.file(workbenchIndexFile).exists());
|
|
573
|
-
logger.error('Main.tsx exists:', await Bun.file(join(tempWorkbenchDir, 'main.tsx')).exists());
|
|
574
|
-
}
|
|
575
|
-
// Clean up temp directory even on failure
|
|
576
|
-
rmSync(tempWorkbenchDir, { recursive: true, force: true });
|
|
577
|
-
logger.fatal('Workbench bundling failed');
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
catch (error) {
|
|
581
|
-
logger.error('Failed to bundle workbench:', error);
|
|
582
|
-
// Collect all error messages
|
|
583
|
-
const errorMessages = [];
|
|
584
|
-
if (error instanceof AggregateError && Array.isArray(error.errors)) {
|
|
585
|
-
for (const err of error.errors) {
|
|
586
|
-
// Extract useful info from Bun's ResolveMessage errors
|
|
587
|
-
if (err && typeof err === 'object') {
|
|
588
|
-
const errObj = err;
|
|
589
|
-
if (typeof errObj.message === 'string') {
|
|
590
|
-
errorMessages.push(` ${errObj.message}`);
|
|
591
|
-
}
|
|
592
|
-
const position = errObj.position;
|
|
593
|
-
if (position?.file && position?.line && position?.column) {
|
|
594
|
-
errorMessages.push(` at ${position.file}:${position.line}:${position.column}`);
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
// Show different tips based on whether we're in a monorepo or published package
|
|
600
|
-
const isMonorepo = await Bun.file(join(rootDir, '../../packages')).exists();
|
|
601
|
-
if (isMonorepo) {
|
|
602
|
-
errorMessages.push('\nTip: Make sure all @agentuity/* packages are built by', 'running "bun run build" from the monorepo root.');
|
|
603
|
-
}
|
|
604
|
-
else {
|
|
605
|
-
errorMessages.push('\nTip: If you see module resolution errors, try running', '"bun install" to ensure all dependencies are installed.');
|
|
606
|
-
}
|
|
607
|
-
// Don't continue if workbench bundling fails
|
|
608
|
-
logger.fatal(errorMessages.join('\n'));
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
if (!dev && buildmetadata) {
|
|
612
|
-
const webPublicDir = join(webDir, 'public');
|
|
613
|
-
if (existsSync(webPublicDir)) {
|
|
614
|
-
const assets = buildmetadata.assets;
|
|
615
|
-
const webOutPublicDir = join(outDir, 'web', 'public');
|
|
616
|
-
cpSync(webPublicDir, webOutPublicDir, { recursive: true });
|
|
617
|
-
[...new Bun.Glob('**.*').scanSync(webOutPublicDir)].forEach((f) => {
|
|
618
|
-
const bf = Bun.file(join(webOutPublicDir, f));
|
|
619
|
-
assets.push({
|
|
620
|
-
filename: join('public', f),
|
|
621
|
-
kind: 'static',
|
|
622
|
-
contentType: bf.type,
|
|
623
|
-
size: bf.size,
|
|
624
|
-
});
|
|
625
|
-
});
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
if (!dev && Bun.which('git') && buildmetadata?.deployment) {
|
|
629
|
-
buildmetadata.deployment.git = {
|
|
630
|
-
commit: process.env.GIT_SHA || process.env.GITHUB_SHA,
|
|
631
|
-
branch: process.env.GITHUB_REF ? process.env.GITHUB_REF.replace('refs/heads/', '') : '',
|
|
632
|
-
repo: process.env.GITHUB_REPOSITORY
|
|
633
|
-
? gitParseUrl(process.env.GITHUB_REPOSITORY).toString('https')
|
|
634
|
-
: '',
|
|
635
|
-
provider: 'git',
|
|
636
|
-
};
|
|
637
|
-
if (process.env.GITHUB_REPOSITORY) {
|
|
638
|
-
buildmetadata.deployment.git.provider = 'github';
|
|
639
|
-
}
|
|
640
|
-
if (process.env.CI && !trigger) {
|
|
641
|
-
buildmetadata.deployment.git.trigger = 'ci';
|
|
642
|
-
}
|
|
643
|
-
// pull out the git information if we have it
|
|
644
|
-
try {
|
|
645
|
-
let gitDir = join(rootDir, '.git');
|
|
646
|
-
let parentDir = dirname(dirname(gitDir));
|
|
647
|
-
while (!existsSync(gitDir) && parentDir !== dirname(parentDir) && gitDir !== '/') {
|
|
648
|
-
gitDir = join(parentDir, '.git');
|
|
649
|
-
parentDir = dirname(parentDir);
|
|
650
|
-
}
|
|
651
|
-
if (existsSync(gitDir)) {
|
|
652
|
-
const tag = $ `git tag -l --points-at HEAD`.nothrow().quiet();
|
|
653
|
-
if (tag) {
|
|
654
|
-
const tags = await tag.text();
|
|
655
|
-
buildmetadata.deployment.git.tags = tags
|
|
656
|
-
.trim()
|
|
657
|
-
.split(/\n/)
|
|
658
|
-
.map((s) => s.trim())
|
|
659
|
-
.filter(Boolean);
|
|
660
|
-
}
|
|
661
|
-
let branch = process.env.GITHUB_HEAD_REF;
|
|
662
|
-
if (!branch) {
|
|
663
|
-
const branchText = $ `git branch --show-current`.nothrow().quiet();
|
|
664
|
-
if (branchText) {
|
|
665
|
-
branch = await branchText.text();
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
if (branch) {
|
|
669
|
-
buildmetadata.deployment.git.branch = branch.trim();
|
|
670
|
-
}
|
|
671
|
-
const commit = $ `git rev-parse HEAD`.nothrow().quiet();
|
|
672
|
-
if (commit) {
|
|
673
|
-
const sha = await commit.text();
|
|
674
|
-
if (sha) {
|
|
675
|
-
buildmetadata.deployment.git.commit = sha.trim();
|
|
676
|
-
const msg = $ `git log --pretty=format:%s -n1 ${buildmetadata.deployment.git.commit}`;
|
|
677
|
-
if (msg) {
|
|
678
|
-
const _msg = await msg.text();
|
|
679
|
-
if (_msg) {
|
|
680
|
-
buildmetadata.deployment.git.message = _msg.trim();
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
const origin = $ `git config --get remote.origin.url`.nothrow().quiet();
|
|
684
|
-
if (origin) {
|
|
685
|
-
const _origin = await origin.text();
|
|
686
|
-
if (_origin) {
|
|
687
|
-
const _url = gitParseUrl(_origin.trim());
|
|
688
|
-
buildmetadata.deployment.git.repo = _url.toString('https');
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
catch {
|
|
696
|
-
// ignore errors
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
// if in gitlab CI, set defaults before user overrides
|
|
700
|
-
if (process.env.GITLAB_CI && buildmetadata?.deployment) {
|
|
701
|
-
buildmetadata.deployment.git ??= {};
|
|
702
|
-
buildmetadata.deployment.git.provider ??= 'gitlab';
|
|
703
|
-
buildmetadata.deployment.git.branch ??= process.env.CI_COMMIT_REF_NAME;
|
|
704
|
-
buildmetadata.deployment.git.commit ??= process.env.CI_COMMIT_SHA;
|
|
705
|
-
buildmetadata.deployment.git.buildUrl ??=
|
|
706
|
-
process.env.CI_JOB_URL ?? process.env.CI_PIPELINE_URL;
|
|
707
|
-
}
|
|
708
|
-
// configure any overrides or any that aren't detected automatically
|
|
709
|
-
if (buildmetadata?.deployment) {
|
|
710
|
-
buildmetadata.deployment.git ??= {};
|
|
711
|
-
// build tags: start with existing discovered tags, add defaults, then merge explicit tags
|
|
712
|
-
const tags = new Set(buildmetadata.deployment.git.tags ?? []);
|
|
713
|
-
tags.add('latest');
|
|
714
|
-
if (buildmetadata.deployment.git.branch) {
|
|
715
|
-
tags.add(buildmetadata.deployment.git.branch);
|
|
716
|
-
}
|
|
717
|
-
if (buildmetadata.deployment.git.commit) {
|
|
718
|
-
tags.add(buildmetadata.deployment.git.commit.substring(0, 7));
|
|
719
|
-
}
|
|
720
|
-
if (tag?.length && !(tag.length === 1 && tag[0] === 'latest')) {
|
|
721
|
-
for (const t of tag) {
|
|
722
|
-
tags.add(t);
|
|
723
|
-
}
|
|
724
|
-
tags.delete('latest'); // if you specify explicit tags we remove latest
|
|
725
|
-
}
|
|
726
|
-
buildmetadata.deployment.git.tags = Array.from(tags);
|
|
727
|
-
if (provider) {
|
|
728
|
-
buildmetadata.deployment.git.provider = provider;
|
|
729
|
-
}
|
|
730
|
-
if (logsUrl) {
|
|
731
|
-
buildmetadata.deployment.git.buildUrl = logsUrl;
|
|
732
|
-
}
|
|
733
|
-
if (commitUrl) {
|
|
734
|
-
buildmetadata.deployment.git.url = commitUrl;
|
|
735
|
-
}
|
|
736
|
-
if (trigger) {
|
|
737
|
-
buildmetadata.deployment.git.trigger = trigger;
|
|
738
|
-
}
|
|
739
|
-
if (event) {
|
|
740
|
-
buildmetadata.deployment.git.event = event;
|
|
741
|
-
}
|
|
742
|
-
if (pullRequestNumber) {
|
|
743
|
-
buildmetadata.deployment.git.pull_request = {
|
|
744
|
-
number: pullRequestNumber,
|
|
745
|
-
url: pullRequestURL,
|
|
746
|
-
commentId: pullRequestCommentId,
|
|
747
|
-
};
|
|
748
|
-
}
|
|
749
|
-
if (message) {
|
|
750
|
-
buildmetadata.deployment.git.message = message;
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
// Write minimal package.json for dev mode (production already wrote it above)
|
|
754
|
-
if (dev) {
|
|
755
|
-
await Bun.write(`${outDir}/package.json`, JSON.stringify({ name: pkgContents.name, version: pkgContents.version }, null, 2));
|
|
756
|
-
}
|
|
757
|
-
await Bun.write(`${outDir}/agentuity.metadata.json`, dev ? JSON.stringify(buildmetadata, null, 2) : JSON.stringify(buildmetadata));
|
|
758
|
-
// Generate route mapping file for runtime route tracking
|
|
759
|
-
const routeMapping = {};
|
|
760
|
-
for (const route of buildmetadata.routes ?? []) {
|
|
761
|
-
routeMapping[`${route.method} ${route.path}`] = route.id;
|
|
762
|
-
}
|
|
763
|
-
await Bun.write(`${outDir}/.routemapping.json`, dev ? JSON.stringify(routeMapping, null, 2) : JSON.stringify(routeMapping));
|
|
764
|
-
return { output };
|
|
765
|
-
}
|
|
766
|
-
//# sourceMappingURL=bundler.js.map
|