@iqai/adk-cli 0.3.28 → 0.3.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/cli/run.command.d.ts.map +1 -1
- package/dist/cli/run.command.js +23 -5
- package/dist/cli/run.command.js.map +1 -1
- package/dist/http/bootstrap.d.ts.map +1 -1
- package/dist/http/bootstrap.js +5 -0
- package/dist/http/bootstrap.js.map +1 -1
- package/dist/http/filters/index.d.ts +2 -0
- package/dist/http/filters/index.d.ts.map +1 -0
- package/dist/http/filters/index.js +6 -0
- package/dist/http/filters/index.js.map +1 -0
- package/dist/http/filters/pretty-error.filter.d.ts +33 -0
- package/dist/http/filters/pretty-error.filter.d.ts.map +1 -0
- package/dist/http/filters/pretty-error.filter.js +269 -0
- package/dist/http/filters/pretty-error.filter.js.map +1 -0
- package/dist/http/providers/agent-loader/agent-resolver.d.ts +16 -0
- package/dist/http/providers/agent-loader/agent-resolver.d.ts.map +1 -0
- package/dist/http/providers/agent-loader/agent-resolver.js +107 -0
- package/dist/http/providers/agent-loader/agent-resolver.js.map +1 -0
- package/dist/http/providers/agent-loader/cache-utils.d.ts +13 -0
- package/dist/http/providers/agent-loader/cache-utils.d.ts.map +1 -0
- package/dist/http/providers/agent-loader/cache-utils.js +50 -0
- package/dist/http/providers/agent-loader/cache-utils.js.map +1 -0
- package/dist/http/providers/agent-loader/env-utils.d.ts +19 -0
- package/dist/http/providers/agent-loader/env-utils.d.ts.map +1 -0
- package/dist/http/providers/agent-loader/env-utils.js +99 -0
- package/dist/http/providers/agent-loader/env-utils.js.map +1 -0
- package/dist/http/providers/agent-loader/error-handling-utils.d.ts +31 -0
- package/dist/http/providers/agent-loader/error-handling-utils.d.ts.map +1 -0
- package/dist/http/providers/agent-loader/error-handling-utils.js +251 -0
- package/dist/http/providers/agent-loader/error-handling-utils.js.map +1 -0
- package/dist/http/providers/agent-loader/path-plugin.d.ts +1 -1
- package/dist/http/providers/agent-loader/path-plugin.d.ts.map +1 -1
- package/dist/http/providers/agent-loader/path-plugin.js +1 -1
- package/dist/http/providers/agent-loader/path-plugin.js.map +1 -1
- package/dist/http/providers/agent-loader/path-utils.d.ts +20 -0
- package/dist/http/providers/agent-loader/path-utils.d.ts.map +1 -0
- package/dist/http/providers/agent-loader/path-utils.js +84 -0
- package/dist/http/providers/agent-loader/path-utils.js.map +1 -0
- package/dist/http/providers/agent-loader/tsconfig.d.ts +1 -1
- package/dist/http/providers/agent-loader/tsconfig.d.ts.map +1 -1
- package/dist/http/providers/agent-loader/tsconfig.js +1 -1
- package/dist/http/providers/agent-loader/tsconfig.js.map +1 -1
- package/dist/http/providers/agent-loader/type-guards.d.ts +8 -0
- package/dist/http/providers/agent-loader/type-guards.d.ts.map +1 -0
- package/dist/http/providers/agent-loader/type-guards.js +29 -0
- package/dist/http/providers/agent-loader/type-guards.js.map +1 -0
- package/dist/http/providers/agent-loader.service.d.ts +10 -7
- package/dist/http/providers/agent-loader.service.d.ts.map +1 -1
- package/dist/http/providers/agent-loader.service.js +73 -91
- package/dist/http/providers/agent-loader.service.js.map +1 -1
- package/dist/http/providers/agent-manager.service.d.ts +1 -2
- package/dist/http/providers/agent-manager.service.d.ts.map +1 -1
- package/dist/http/providers/agent-manager.service.js +18 -14
- package/dist/http/providers/agent-manager.service.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentResolver = void 0;
|
|
4
|
+
class AgentResolver {
|
|
5
|
+
logger;
|
|
6
|
+
quiet;
|
|
7
|
+
guards;
|
|
8
|
+
constructor(logger, quiet, guards) {
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
this.quiet = quiet;
|
|
11
|
+
this.guards = guards;
|
|
12
|
+
}
|
|
13
|
+
async invokeFunctionSafely(fn) {
|
|
14
|
+
let result = fn();
|
|
15
|
+
if (result && typeof result === "object" && "then" in result) {
|
|
16
|
+
result = await result;
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
async extractBaseAgent(item) {
|
|
21
|
+
if (this.guards.isLikelyAgentInstance(item))
|
|
22
|
+
return item;
|
|
23
|
+
if (this.guards.isAgentBuilder(item))
|
|
24
|
+
return (await item.build()).agent;
|
|
25
|
+
if (this.guards.isBuiltAgent(item))
|
|
26
|
+
return item.agent;
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
async scanModuleExports(mod) {
|
|
30
|
+
for (const [key, value] of Object.entries(mod)) {
|
|
31
|
+
if (key === "default" || this.guards.isPrimitive(value))
|
|
32
|
+
continue;
|
|
33
|
+
const found = await this.extractBaseAgent(value);
|
|
34
|
+
if (found)
|
|
35
|
+
return found;
|
|
36
|
+
if (value && typeof value === "object" && "agent" in value) {
|
|
37
|
+
const inner = await this.extractBaseAgent(value.agent);
|
|
38
|
+
if (inner)
|
|
39
|
+
return inner;
|
|
40
|
+
}
|
|
41
|
+
if (typeof value === "function" && /(agent|build|create)/i.test(key)) {
|
|
42
|
+
try {
|
|
43
|
+
const result = await this.invokeFunctionSafely(value);
|
|
44
|
+
const inner = await this.extractBaseAgent(result);
|
|
45
|
+
if (inner)
|
|
46
|
+
return inner;
|
|
47
|
+
if (result &&
|
|
48
|
+
typeof result === "object" &&
|
|
49
|
+
"agent" in result) {
|
|
50
|
+
const nested = await this.extractBaseAgent(result.agent);
|
|
51
|
+
if (nested)
|
|
52
|
+
return nested;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch { }
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
async tryResolvingDirectCandidate(candidate, mod) {
|
|
61
|
+
if (this.guards.isPrimitive(candidate) || candidate === mod)
|
|
62
|
+
return null;
|
|
63
|
+
const direct = await this.extractBaseAgent(candidate);
|
|
64
|
+
if (direct)
|
|
65
|
+
return direct;
|
|
66
|
+
if (candidate &&
|
|
67
|
+
typeof candidate === "object" &&
|
|
68
|
+
"agent" in candidate)
|
|
69
|
+
return await this.extractBaseAgent(candidate.agent);
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
async tryResolvingFunctionCandidate(fnCandidate) {
|
|
73
|
+
try {
|
|
74
|
+
const result = await this.invokeFunctionSafely(fnCandidate);
|
|
75
|
+
const agent = await this.extractBaseAgent(result);
|
|
76
|
+
if (agent)
|
|
77
|
+
return agent;
|
|
78
|
+
if (result && typeof result === "object" && "agent" in result)
|
|
79
|
+
return await this.extractBaseAgent(result.agent);
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
throw new Error(`Failed executing exported agent function: ${e instanceof Error ? e.message : String(e)}`);
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
async resolveAgentExport(mod) {
|
|
87
|
+
const moduleDefault = mod?.default;
|
|
88
|
+
const candidate = mod?.agent ??
|
|
89
|
+
moduleDefault?.agent ??
|
|
90
|
+
moduleDefault ??
|
|
91
|
+
mod;
|
|
92
|
+
const direct = await this.tryResolvingDirectCandidate(candidate, mod);
|
|
93
|
+
if (direct)
|
|
94
|
+
return direct;
|
|
95
|
+
const scanned = await this.scanModuleExports(mod);
|
|
96
|
+
if (scanned)
|
|
97
|
+
return scanned;
|
|
98
|
+
if (typeof candidate === "function") {
|
|
99
|
+
const fnResult = await this.tryResolvingFunctionCandidate(candidate);
|
|
100
|
+
if (fnResult)
|
|
101
|
+
return fnResult;
|
|
102
|
+
}
|
|
103
|
+
throw new Error("No agent export resolved (expected BaseAgent, AgentBuilder, or BuiltAgent)");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.AgentResolver = AgentResolver;
|
|
107
|
+
//# sourceMappingURL=agent-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-resolver.js","sourceRoot":"","sources":["../../../../src/http/provid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G,MAAM,IAAI,CAAC,6BAA6B,CAAC,SAAS,CAAC,CAAC;YACrE,IAAI,QAAQ;gBAAE,OAAO,QAAQ,CAAC;QAC/B,CAAC;QAED,MAAM,IAAI,KAAK,CACd,4EAA4E,CAC5E,CAAC;IACH,CAAC;CACD;AA3HD,sCA2HC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Logger } from "@nestjs/common";
|
|
2
|
+
export declare const CACHE_DIR = ".adk-cache";
|
|
3
|
+
export declare class CacheUtils {
|
|
4
|
+
private logger;
|
|
5
|
+
private quiet;
|
|
6
|
+
private static activeCacheFiles;
|
|
7
|
+
private static projectRoots;
|
|
8
|
+
constructor(logger: Logger, quiet?: boolean);
|
|
9
|
+
static cleanupAllCacheFiles(logger?: Logger, quiet?: boolean): void;
|
|
10
|
+
trackCacheFile(filePath: string, projectRoot: string): void;
|
|
11
|
+
createTempFilePath(projectRoot: string): string;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=cache-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-utils.d.ts","sourceRoot":"","sources":["../../../../src/http/providers/agent-loader/cache-utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,eAAO,MAAM,SAAS,eAAe,CAAC;AAEtC,qBAAa,UAAU;IAKrB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,KAAK;IALd,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAqB;IACpD,OAAO,CAAC,MAAM,CAAC,YAAY,CAAqB;gBAGvC,MAAM,EAAE,MAAM,EACd,KAAK,UAAQ;IAGtB,MAAM,CAAC,oBAAoB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,UAAQ,GAAG,IAAI;IAuBjE,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;IAK3D,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;CAG/C"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CacheUtils = exports.CACHE_DIR = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
exports.CACHE_DIR = ".adk-cache";
|
|
7
|
+
class CacheUtils {
|
|
8
|
+
logger;
|
|
9
|
+
quiet;
|
|
10
|
+
static activeCacheFiles = new Set();
|
|
11
|
+
static projectRoots = new Set();
|
|
12
|
+
constructor(logger, quiet = false) {
|
|
13
|
+
this.logger = logger;
|
|
14
|
+
this.quiet = quiet;
|
|
15
|
+
}
|
|
16
|
+
static cleanupAllCacheFiles(logger, quiet = false) {
|
|
17
|
+
for (const file of CacheUtils.activeCacheFiles) {
|
|
18
|
+
try {
|
|
19
|
+
if ((0, node_fs_1.existsSync)(file))
|
|
20
|
+
(0, node_fs_1.unlinkSync)(file);
|
|
21
|
+
}
|
|
22
|
+
catch { }
|
|
23
|
+
}
|
|
24
|
+
CacheUtils.activeCacheFiles.clear();
|
|
25
|
+
for (const root of CacheUtils.projectRoots) {
|
|
26
|
+
const cacheDir = (0, node_path_1.join)(root, exports.CACHE_DIR);
|
|
27
|
+
try {
|
|
28
|
+
if ((0, node_fs_1.existsSync)(cacheDir)) {
|
|
29
|
+
(0, node_fs_1.rmSync)(cacheDir, { recursive: true, force: true });
|
|
30
|
+
if (!quiet)
|
|
31
|
+
logger?.log(`Cleaned cache directory: ${cacheDir}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
if (!quiet)
|
|
36
|
+
logger?.warn(`Failed to clean cache directory ${cacheDir}:`, e);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
CacheUtils.projectRoots.clear();
|
|
40
|
+
}
|
|
41
|
+
trackCacheFile(filePath, projectRoot) {
|
|
42
|
+
CacheUtils.activeCacheFiles.add(filePath);
|
|
43
|
+
CacheUtils.projectRoots.add(projectRoot);
|
|
44
|
+
}
|
|
45
|
+
createTempFilePath(projectRoot) {
|
|
46
|
+
return (0, node_path_1.join)(projectRoot, exports.CACHE_DIR, `agent-${Date.now()}.cjs`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.CacheUtils = CacheUtils;
|
|
50
|
+
//# sourceMappingURL=cache-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-utils.js","sourceRoot":"","sources":["../../../../src/http/providers/agent-loader/cache-utils.ts"],"names":[],"mappings":";;;AAAA,qCAAyD;AACzD,yCAAiC;AAGpB,QAAA,SAAS,GAAG,YAAY,CAAC;AAEtC,MAAa,UAAU;IAKb;IACA;IALD,MAAM,CAAC,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;IAC5C,MAAM,CAAC,YAAY,GAAG,IAAI,GAAG,EAAU,CAAC;IAEhD,YACS,MAAc,EACd,QAAQ,KAAK;QADb,WAAM,GAAN,MAAM,CAAQ;QACd,UAAK,GAAL,KAAK,CAAQ;IACnB,CAAC;IAEJ,MAAM,CAAC,oBAAoB,CAAC,MAAe,EAAE,KAAK,GAAG,KAAK;QACzD,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,gBAAgB,EAAE,CAAC;YAChD,IAAI,CAAC;gBACJ,IAAI,IAAA,oBAAU,EAAC,IAAI,CAAC;oBAAE,IAAA,oBAAU,EAAC,IAAI,CAAC,CAAC;YACxC,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;QACX,CAAC;QACD,UAAU,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAEpC,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,YAAY,EAAE,CAAC;YAC5C,MAAM,QAAQ,GAAG,IAAA,gBAAI,EAAC,IAAI,EAAE,iBAAS,CAAC,CAAC;YACvC,IAAI,CAAC;gBACJ,IAAI,IAAA,oBAAU,EAAC,QAAQ,CAAC,EAAE,CAAC;oBAC1B,IAAA,gBAAM,EAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;oBACnD,IAAI,CAAC,KAAK;wBAAE,MAAM,EAAE,GAAG,CAAC,4BAA4B,QAAQ,EAAE,CAAC,CAAC;gBACjE,CAAC;YACF,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACZ,IAAI,CAAC,KAAK;oBACT,MAAM,EAAE,IAAI,CAAC,mCAAmC,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC;YAClE,CAAC;QACF,CAAC;QACD,UAAU,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;IACjC,CAAC;IAED,cAAc,CAAC,QAAgB,EAAE,WAAmB;QACnD,UAAU,CAAC,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC1C,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC1C,CAAC;IAED,kBAAkB,CAAC,WAAmB;QACrC,OAAO,IAAA,gBAAI,EAAC,WAAW,EAAE,iBAAS,EAAE,SAAS,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;;AAvCF,gCAwCC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Logger } from "@nestjs/common";
|
|
2
|
+
export declare class EnvUtils {
|
|
3
|
+
private logger;
|
|
4
|
+
private quiet;
|
|
5
|
+
constructor(logger: Logger, quiet?: boolean);
|
|
6
|
+
/**
|
|
7
|
+
* Find which .env files exist in the project
|
|
8
|
+
*/
|
|
9
|
+
private findExistingEnvFiles;
|
|
10
|
+
/**
|
|
11
|
+
* Generate helpful error message for missing environment variables
|
|
12
|
+
*/
|
|
13
|
+
generateEnvErrorMessage(projectRoot: string, varName?: string, allMissing?: string[]): string;
|
|
14
|
+
/**
|
|
15
|
+
* Load environment variables from prioritized .env files
|
|
16
|
+
*/
|
|
17
|
+
loadEnvironmentVariables(agentFilePath: string): void;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=env-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-utils.d.ts","sourceRoot":"","sources":["../../../../src/http/providers/agent-loader/env-utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,qBAAa,QAAQ;IAEnB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,KAAK;gBADL,MAAM,EAAE,MAAM,EACd,KAAK,UAAQ;IAGtB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAY5B;;OAEG;IACH,uBAAuB,CACtB,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,EAAE,GACnB,MAAM;IAwBT;;OAEG;IACH,wBAAwB,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI;CAmDrD"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnvUtils = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const find_project_root_1 = require("../../../common/find-project-root");
|
|
7
|
+
class EnvUtils {
|
|
8
|
+
logger;
|
|
9
|
+
quiet;
|
|
10
|
+
constructor(logger, quiet = false) {
|
|
11
|
+
this.logger = logger;
|
|
12
|
+
this.quiet = quiet;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Find which .env files exist in the project
|
|
16
|
+
*/
|
|
17
|
+
findExistingEnvFiles(projectRoot) {
|
|
18
|
+
const envFiles = [
|
|
19
|
+
".env.local",
|
|
20
|
+
".env.development.local",
|
|
21
|
+
".env.production.local",
|
|
22
|
+
".env.development",
|
|
23
|
+
".env.production",
|
|
24
|
+
".env",
|
|
25
|
+
];
|
|
26
|
+
return envFiles.filter((file) => (0, node_fs_1.existsSync)((0, node_path_1.join)(projectRoot, file)));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Generate helpful error message for missing environment variables
|
|
30
|
+
*/
|
|
31
|
+
generateEnvErrorMessage(projectRoot, varName, allMissing) {
|
|
32
|
+
const existingEnvFiles = this.findExistingEnvFiles(projectRoot);
|
|
33
|
+
const missingVars = allMissing || (varName ? [varName] : []);
|
|
34
|
+
let message = `\n❌ MISSING ENVIRONMENT VARIABLE${missingVars.length > 1 ? "S" : ""}\n\n`;
|
|
35
|
+
if (missingVars.length > 0) {
|
|
36
|
+
message += `Required: ${missingVars.join(", ")}\n`;
|
|
37
|
+
}
|
|
38
|
+
message += `Project: ${projectRoot}\n\n`;
|
|
39
|
+
if (existingEnvFiles.length > 0) {
|
|
40
|
+
message += `📝 Found: ${existingEnvFiles.join(", ")}\n`;
|
|
41
|
+
message += `💡 Add missing variable${missingVars.length > 1 ? "s" : ""} to one of these files\n\n`;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
message += "💡 Create a .env file with:\n";
|
|
45
|
+
for (const v of missingVars)
|
|
46
|
+
message += ` ${v}=your_value_here\n`;
|
|
47
|
+
message += "\n";
|
|
48
|
+
}
|
|
49
|
+
message += "Tip: Use .env.local (git-ignored) for sensitive values\n";
|
|
50
|
+
return message;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Load environment variables from prioritized .env files
|
|
54
|
+
*/
|
|
55
|
+
loadEnvironmentVariables(agentFilePath) {
|
|
56
|
+
const normalizedAgentPath = (0, node_path_1.normalize)((0, node_path_1.resolve)(agentFilePath));
|
|
57
|
+
const projectRoot = (0, find_project_root_1.findProjectRoot)((0, node_path_1.dirname)(normalizedAgentPath));
|
|
58
|
+
const envFiles = [
|
|
59
|
+
".env.local",
|
|
60
|
+
".env.development.local",
|
|
61
|
+
".env.production.local",
|
|
62
|
+
".env.development",
|
|
63
|
+
".env.production",
|
|
64
|
+
".env",
|
|
65
|
+
];
|
|
66
|
+
let loadedAny = false;
|
|
67
|
+
for (const envFile of envFiles) {
|
|
68
|
+
const envPath = (0, node_path_1.join)(projectRoot, envFile);
|
|
69
|
+
if ((0, node_fs_1.existsSync)(envPath)) {
|
|
70
|
+
try {
|
|
71
|
+
const envContent = (0, node_fs_1.readFileSync)(envPath, "utf8");
|
|
72
|
+
const lines = envContent.split("\n");
|
|
73
|
+
for (const line of lines) {
|
|
74
|
+
const trimmed = line.trim();
|
|
75
|
+
if (trimmed && !trimmed.startsWith("#")) {
|
|
76
|
+
const [key, ...valueParts] = trimmed.split("=");
|
|
77
|
+
if (key && valueParts.length > 0) {
|
|
78
|
+
const value = valueParts.join("=").replace(/^"(.*)"$/, "$1");
|
|
79
|
+
if (!process.env[key.trim()]) {
|
|
80
|
+
process.env[key.trim()] = value.trim();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
loadedAny = true;
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
this.logger.warn(`Warning: Could not load ${envFile} file: ${err instanceof Error ? err.message : String(err)}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!loadedAny && !this.quiet) {
|
|
93
|
+
this.logger.warn(`No .env files found in project root: ${projectRoot}\n` +
|
|
94
|
+
"If your agent requires environment variables, please create a .env file.");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.EnvUtils = EnvUtils;
|
|
99
|
+
//# sourceMappingURL=env-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-utils.js","sourceRoot":"","sources":["../../../../src/http/providers/agent-loader/env-utils.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AACnD,yCAA8D;AAE9D,yEAAoE;AAEpE,MAAa,QAAQ;IAEX;IACA;IAFT,Y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G,CAAC,CAAC;4BAChD,IAAI,GAAG,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gCAClC,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;gCAC7D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;oCAC9B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;gCACxC,CAAC;4BACF,CAAC;wBACF,CAAC;oBACF,CAAC;oBACD,SAAS,GAAG,IAAI,CAAC;gBAClB,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACd,IAAI,CAAC,MAAM,CAAC,IAAI,CACf,2BAA2B,OAAO,UACjC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAChD,EAAE,CACF,CAAC;gBACH,CAAC;YACF,CAAC;QACF,CAAC;QAED,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YAC/B,IAAI,CAAC,MAAM,CAAC,IAAI,CACf,wCAAwC,WAAW,IAAI;gBACtD,0EAA0E,CAC3E,CAAC;QACH,CAAC;IACF,CAAC;CACD;AA1GD,4BA0GC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Logger } from "@nestjs/common";
|
|
2
|
+
export declare class ErrorHandlingUtils {
|
|
3
|
+
private logger;
|
|
4
|
+
constructor(logger: Logger);
|
|
5
|
+
isMissingEnvError(error: unknown): {
|
|
6
|
+
isMissing: boolean;
|
|
7
|
+
varName?: string;
|
|
8
|
+
allMissing?: string[];
|
|
9
|
+
requiredMissing?: string[];
|
|
10
|
+
optionalMissing?: string[];
|
|
11
|
+
hasOnlyOptionalMissing?: boolean;
|
|
12
|
+
};
|
|
13
|
+
handleImportError(error: unknown, outFile: string, projectRoot: string): Promise<Record<string, unknown>>;
|
|
14
|
+
/**
|
|
15
|
+
* Formats Zod or runtime errors into a human-readable string
|
|
16
|
+
*/
|
|
17
|
+
formatUserError(error: unknown): string;
|
|
18
|
+
/**
|
|
19
|
+
* Categorize error for console output with helpful suggestions
|
|
20
|
+
*/
|
|
21
|
+
private categorizeErrorForConsole;
|
|
22
|
+
/**
|
|
23
|
+
* Clean up error messages by removing redundant prefixes
|
|
24
|
+
*/
|
|
25
|
+
private cleanErrorMessage;
|
|
26
|
+
/**
|
|
27
|
+
* Extract module name from error message
|
|
28
|
+
*/
|
|
29
|
+
private extractModuleName;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=error-handling-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handling-utils.d.ts","sourceRoot":"","sources":["../../../../src/http/providers/agent-loader/error-handling-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAIxC,qBAAa,kBAAkB;IAClB,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAElC,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG;QAClC,SAAS,EAAE,OAAO,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;QACtB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;QAC3B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;QAC3B,sBAAsB,CAAC,EAAE,OAAO,CAAC;KACjC;IA0CK,iBAAiB,CACtB,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IA4CnC;;OAEG;IACH,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM;IAsDvC;;OAEG;IACH,OAAO,CAAC,yBAAyB;IA0FjC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAOzB;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAIzB"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ErrorHandlingUtils = void 0;
|
|
37
|
+
const node_url_1 = require("node:url");
|
|
38
|
+
const zod_1 = require("zod");
|
|
39
|
+
const env_utils_1 = require("./env-utils");
|
|
40
|
+
class ErrorHandlingUtils {
|
|
41
|
+
logger;
|
|
42
|
+
constructor(logger) {
|
|
43
|
+
this.logger = logger;
|
|
44
|
+
}
|
|
45
|
+
isMissingEnvError(error) {
|
|
46
|
+
if (error instanceof zod_1.ZodError) {
|
|
47
|
+
const allMissingVars = error.issues
|
|
48
|
+
.filter((issue) => issue.code === "invalid_type" && issue.expected !== "undefined")
|
|
49
|
+
.map((issue) => issue.path?.[0])
|
|
50
|
+
.filter((v) => !!v);
|
|
51
|
+
const requiredMissing = [];
|
|
52
|
+
const optionalMissing = [];
|
|
53
|
+
const optionalPatterns = [
|
|
54
|
+
/^.*_DEBUG$/i,
|
|
55
|
+
/^.*_ENABLED$/i,
|
|
56
|
+
/^PORT$/i,
|
|
57
|
+
/^HOST$/i,
|
|
58
|
+
/^NODE_ENV$/i,
|
|
59
|
+
/^ADK_/i,
|
|
60
|
+
];
|
|
61
|
+
for (const varName of allMissingVars) {
|
|
62
|
+
if (optionalPatterns.some((p) => p.test(varName)))
|
|
63
|
+
optionalMissing.push(varName);
|
|
64
|
+
else
|
|
65
|
+
requiredMissing.push(varName);
|
|
66
|
+
}
|
|
67
|
+
if (allMissingVars.length > 0) {
|
|
68
|
+
return {
|
|
69
|
+
isMissing: true,
|
|
70
|
+
varName: allMissingVars[0],
|
|
71
|
+
allMissing: allMissingVars,
|
|
72
|
+
requiredMissing,
|
|
73
|
+
optionalMissing,
|
|
74
|
+
hasOnlyOptionalMissing: requiredMissing.length === 0 && optionalMissing.length > 0,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return { isMissing: false };
|
|
79
|
+
}
|
|
80
|
+
async handleImportError(error, outFile, projectRoot) {
|
|
81
|
+
const envUtils = new env_utils_1.EnvUtils(this.logger);
|
|
82
|
+
const envCheck = this.isMissingEnvError(error);
|
|
83
|
+
if (envCheck.isMissing) {
|
|
84
|
+
if (envCheck.hasOnlyOptionalMissing) {
|
|
85
|
+
this.logger.warn(`⚠️ Missing optional environment variables: ${envCheck.optionalMissing?.join(", ")}`);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this.logger.error(envUtils.generateEnvErrorMessage(projectRoot, envCheck.varName, envCheck.requiredMissing ?? envCheck.allMissing));
|
|
89
|
+
throw new Error(`Missing required environment variable${envCheck.requiredMissing?.length &&
|
|
90
|
+
envCheck.requiredMissing.length > 1
|
|
91
|
+
? "s"
|
|
92
|
+
: ""}: ${(envCheck.requiredMissing ?? envCheck.allMissing)?.join(", ")}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
return (await Promise.resolve(`${(0, node_url_1.pathToFileURL)(outFile).href}`).then(s => __importStar(require(s))));
|
|
97
|
+
}
|
|
98
|
+
catch (fallbackErr) {
|
|
99
|
+
throw new Error(`Failed to load agent: ${fallbackErr instanceof Error
|
|
100
|
+
? fallbackErr.message
|
|
101
|
+
: String(fallbackErr)}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Formats Zod or runtime errors into a human-readable string
|
|
106
|
+
*/
|
|
107
|
+
formatUserError(error) {
|
|
108
|
+
if (error instanceof zod_1.ZodError) {
|
|
109
|
+
const issues = error.issues.map((i) => {
|
|
110
|
+
const path = i.path?.length ? i.path.join(".") : "(root)";
|
|
111
|
+
return ` • ${path}: ${i.message}`;
|
|
112
|
+
});
|
|
113
|
+
return [
|
|
114
|
+
"",
|
|
115
|
+
"❌ Validation Error",
|
|
116
|
+
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
|
|
117
|
+
"Agent configuration or schema validation failed:",
|
|
118
|
+
"",
|
|
119
|
+
...issues,
|
|
120
|
+
"",
|
|
121
|
+
"💡 Tip: Check your agent's state schema, tools configuration,",
|
|
122
|
+
" or environment variable validation.",
|
|
123
|
+
"",
|
|
124
|
+
].join("\n");
|
|
125
|
+
}
|
|
126
|
+
if (error instanceof Error) {
|
|
127
|
+
const category = this.categorizeErrorForConsole(error);
|
|
128
|
+
const lines = [
|
|
129
|
+
"",
|
|
130
|
+
`❌ ${category.title}`,
|
|
131
|
+
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
|
|
132
|
+
this.cleanErrorMessage(error.message),
|
|
133
|
+
];
|
|
134
|
+
if (category.suggestions.length > 0) {
|
|
135
|
+
lines.push("");
|
|
136
|
+
lines.push(...category.suggestions.map((s) => `💡 ${s}`));
|
|
137
|
+
}
|
|
138
|
+
// Only show stack in debug mode
|
|
139
|
+
if (error.stack && process.env.ADK_DEBUG_NEST === "1") {
|
|
140
|
+
lines.push("");
|
|
141
|
+
lines.push("Stack trace:");
|
|
142
|
+
lines.push(error.stack);
|
|
143
|
+
}
|
|
144
|
+
lines.push("");
|
|
145
|
+
return lines.join("\n");
|
|
146
|
+
}
|
|
147
|
+
return [
|
|
148
|
+
"",
|
|
149
|
+
"❌ Unknown Error",
|
|
150
|
+
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
|
|
151
|
+
String(error),
|
|
152
|
+
"",
|
|
153
|
+
].join("\n");
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Categorize error for console output with helpful suggestions
|
|
157
|
+
*/
|
|
158
|
+
categorizeErrorForConsole(error) {
|
|
159
|
+
const msg = error.message.toLowerCase();
|
|
160
|
+
// Agent loading errors
|
|
161
|
+
if (msg.includes("failed to load agent") ||
|
|
162
|
+
msg.includes("failed to import")) {
|
|
163
|
+
return {
|
|
164
|
+
title: "Agent Loading Error",
|
|
165
|
+
suggestions: [
|
|
166
|
+
"Check your agent.ts file for syntax errors",
|
|
167
|
+
"Ensure all imports are correct",
|
|
168
|
+
"Verify dependencies are installed (npm install)",
|
|
169
|
+
],
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
// Module not found
|
|
173
|
+
if (msg.includes("cannot find module")) {
|
|
174
|
+
const moduleName = this.extractModuleName(error.message);
|
|
175
|
+
return {
|
|
176
|
+
title: "Module Not Found",
|
|
177
|
+
suggestions: moduleName
|
|
178
|
+
? [
|
|
179
|
+
`Install the missing module: npm install ${moduleName}`,
|
|
180
|
+
"Or add it to your package.json dependencies",
|
|
181
|
+
]
|
|
182
|
+
: [
|
|
183
|
+
"Check your imports and package.json",
|
|
184
|
+
"Run: npm install or pnpm install",
|
|
185
|
+
],
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
// Syntax errors
|
|
189
|
+
if (error.name === "SyntaxError") {
|
|
190
|
+
return {
|
|
191
|
+
title: "Syntax Error",
|
|
192
|
+
suggestions: [
|
|
193
|
+
"Review your TypeScript/JavaScript code",
|
|
194
|
+
"Check for missing brackets, quotes, or semicolons",
|
|
195
|
+
],
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
// Type errors
|
|
199
|
+
if (error.name === "TypeError") {
|
|
200
|
+
return {
|
|
201
|
+
title: "Type Error",
|
|
202
|
+
suggestions: [
|
|
203
|
+
"Check for null or undefined values",
|
|
204
|
+
"Verify object properties exist before accessing them",
|
|
205
|
+
],
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
// Agent not found
|
|
209
|
+
if (msg.includes("agent not found")) {
|
|
210
|
+
return {
|
|
211
|
+
title: "Agent Not Found",
|
|
212
|
+
suggestions: [
|
|
213
|
+
"Verify the agent path is correct",
|
|
214
|
+
"Run 'adk list' to see available agents",
|
|
215
|
+
],
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
// Runtime/execution errors
|
|
219
|
+
if (msg.includes("runtime") ||
|
|
220
|
+
msg.includes("execution") ||
|
|
221
|
+
msg.includes("failed executing")) {
|
|
222
|
+
return {
|
|
223
|
+
title: "Agent Runtime Error",
|
|
224
|
+
suggestions: ["Review your agent's code for runtime issues"],
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
// Generic error
|
|
228
|
+
return {
|
|
229
|
+
title: error.name || "Error",
|
|
230
|
+
suggestions: [],
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Clean up error messages by removing redundant prefixes
|
|
235
|
+
*/
|
|
236
|
+
cleanErrorMessage(message) {
|
|
237
|
+
return message
|
|
238
|
+
.replace(/^Error:\s*/i, "")
|
|
239
|
+
.replace(/^Failed to\s+/i, "Failed to ")
|
|
240
|
+
.trim();
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Extract module name from error message
|
|
244
|
+
*/
|
|
245
|
+
extractModuleName(message) {
|
|
246
|
+
const match = message.match(/Cannot find module ['"]([^'"]+)['"]/);
|
|
247
|
+
return match ? match[1] : null;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
exports.ErrorHandlingUtils = ErrorHandlingUtils;
|
|
251
|
+
//# sourceMappingURL=error-handling-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handling-utils.js","sourceRoot":"","sources":["../../../../src/http/providers/agent-loader/error-handling-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyC;AAEzC,6BAAkC;AAClC,2CAAuC;AAEvC,MAAa,kBAAkB;IACV;IAApB,YAAoB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAEtC,iBAAiB,CAAC,KAAc;QAQ/B,IAAI,KAAK,YAAY,cAAQ,EAAE,CAAC;YAC/B,MAAM,cAAc,GAAI,KAAkB,CAAC,MAAM;iBAC/C,MAAM,CACN,CAAC,KAAiB,EAAkD,EAAE,CACrE,KAAK,CAAC,IAAI,KAAK,cAAc,IAAI,KAAK,CAAC,QAAQ,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O;gBACN,KAAK,EAAE,YAAY;gBACnB,WAAW,EAAE;oBACZ,oCAAoC;oBACpC,sDAAsD;iBACtD;aACD,CAAC;QACH,CAAC;QAED,kBAAkB;QAClB,IAAI,GAAG,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC;YACrC,OAAO;gBACN,KAAK,EAAE,iBAAiB;gBACxB,WAAW,EAAE;oBACZ,kCAAkC;oBAClC,wCAAwC;iBACxC;aACD,CAAC;QACH,CAAC;QAED,2BAA2B;QAC3B,IACC,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC;YACvB,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC;YACzB,GAAG,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAC/B,CAAC;YACF,OAAO;gBACN,KAAK,EAAE,qBAAqB;gBAC5B,WAAW,EAAE,CAAC,6CAA6C,CAAC;aAC5D,CAAC;QACH,CAAC;QAED,gBAAgB;QAChB,OAAO;YACN,KAAK,EAAE,KAAK,CAAC,IAAI,IAAI,OAAO;YAC5B,WAAW,EAAE,EAAE;SACf,CAAC;IACH,CAAC;IAED;;OAEG;IACK,iBAAiB,CAAC,OAAe;QACxC,OAAO,OAAO;aACZ,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;aAC1B,OAAO,CAAC,gBAAgB,EAAE,YAAY,CAAC;aACvC,IAAI,EAAE,CAAC;IACV,CAAC;IAED;;OAEG;IACK,iBAAiB,CAAC,OAAe;QACxC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACnE,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAChC,CAAC;CACD;AA3QD,gDA2QC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ESBuildPlugin } from "../agent-loader.types";
|
|
2
1
|
import type { Logger } from "@nestjs/common";
|
|
2
|
+
import type { ESBuildPlugin } from "../agent-loader.types";
|
|
3
3
|
export declare function createPathMappingPlugin(projectRoot: string, opts?: {
|
|
4
4
|
logger?: Logger;
|
|
5
5
|
quiet?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-plugin.d.ts","sourceRoot":"","sources":["../../../../src/http/providers/agent-loader/path-plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"path-plugin.d.ts","sourceRoot":"","sources":["../../../../src/http/providers/agent-loader/path-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAEX,aAAa,EAEb,MAAM,uBAAuB,CAAC;AAI/B,wBAAgB,uBAAuB,CACtC,WAAW,EAAE,MAAM,EACnB,IAAI,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GAC7C,aAAa,CA8Ef"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createPathMappingPlugin = createPathMappingPlugin;
|
|
4
|
-
const tsconfig_1 = require("./tsconfig");
|
|
5
4
|
const node_fs_1 = require("node:fs");
|
|
6
5
|
const node_path_1 = require("node:path");
|
|
6
|
+
const tsconfig_1 = require("./tsconfig");
|
|
7
7
|
const utils_1 = require("./utils");
|
|
8
8
|
function createPathMappingPlugin(projectRoot, opts = {}) {
|
|
9
9
|
const { baseUrl, paths } = (0, tsconfig_1.parseTsConfigPaths)(projectRoot, opts.logger);
|