@aws/agentcore 0.3.0-preview.1.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.
Files changed (213) hide show
  1. package/LICENSE +175 -0
  2. package/README.md +147 -0
  3. package/dist/assets/README.md +79 -0
  4. package/dist/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap +2862 -0
  5. package/dist/assets/__tests__/assets.snapshot.test.ts +139 -0
  6. package/dist/assets/agents/AGENTS.md +102 -0
  7. package/dist/assets/cdk/.prettierrc +8 -0
  8. package/dist/assets/cdk/README.md +14 -0
  9. package/dist/assets/cdk/bin/cdk.ts +50 -0
  10. package/dist/assets/cdk/cdk.json +88 -0
  11. package/dist/assets/cdk/gitignore.template +9 -0
  12. package/dist/assets/cdk/jest.config.js +9 -0
  13. package/dist/assets/cdk/lib/cdk-stack.ts +38 -0
  14. package/dist/assets/cdk/npmignore.template +6 -0
  15. package/dist/assets/cdk/package.json +30 -0
  16. package/dist/assets/cdk/test/cdk.test.ts +16 -0
  17. package/dist/assets/cdk/tsconfig.json +28 -0
  18. package/dist/assets/mcp/python/README.md +27 -0
  19. package/dist/assets/mcp/python/pyproject.toml +22 -0
  20. package/dist/assets/mcp/python/server.py +117 -0
  21. package/dist/assets/mcp/python-lambda/README.md +22 -0
  22. package/dist/assets/mcp/python-lambda/handler.py +144 -0
  23. package/dist/assets/mcp/python-lambda/pyproject.toml +15 -0
  24. package/dist/assets/python/autogen/base/README.md +41 -0
  25. package/dist/assets/python/autogen/base/gitignore.template +40 -0
  26. package/dist/assets/python/autogen/base/main.py +52 -0
  27. package/dist/assets/python/autogen/base/mcp_client/client.py +18 -0
  28. package/dist/assets/python/autogen/base/model/load.py +136 -0
  29. package/dist/assets/python/autogen/base/pyproject.toml +35 -0
  30. package/dist/assets/python/crewai/base/README.md +41 -0
  31. package/dist/assets/python/crewai/base/gitignore.template +40 -0
  32. package/dist/assets/python/crewai/base/main.py +55 -0
  33. package/dist/assets/python/crewai/base/model/load.py +133 -0
  34. package/dist/assets/python/crewai/base/pyproject.toml +32 -0
  35. package/dist/assets/python/googleadk/base/README.md +39 -0
  36. package/dist/assets/python/googleadk/base/gitignore.template +40 -0
  37. package/dist/assets/python/googleadk/base/main.py +84 -0
  38. package/dist/assets/python/googleadk/base/mcp_client/client.py +15 -0
  39. package/dist/assets/python/googleadk/base/model/load.py +41 -0
  40. package/dist/assets/python/googleadk/base/pyproject.toml +21 -0
  41. package/dist/assets/python/langchain_langgraph/base/README.md +41 -0
  42. package/dist/assets/python/langchain_langgraph/base/gitignore.template +40 -0
  43. package/dist/assets/python/langchain_langgraph/base/main.py +51 -0
  44. package/dist/assets/python/langchain_langgraph/base/mcp_client/client.py +19 -0
  45. package/dist/assets/python/langchain_langgraph/base/model/load.py +123 -0
  46. package/dist/assets/python/langchain_langgraph/base/pyproject.toml +37 -0
  47. package/dist/assets/python/openaiagents/base/README.md +39 -0
  48. package/dist/assets/python/openaiagents/base/gitignore.template +40 -0
  49. package/dist/assets/python/openaiagents/base/main.py +56 -0
  50. package/dist/assets/python/openaiagents/base/mcp_client/client.py +14 -0
  51. package/dist/assets/python/openaiagents/base/model/load.py +37 -0
  52. package/dist/assets/python/openaiagents/base/pyproject.toml +20 -0
  53. package/dist/assets/python/strands/base/README.md +41 -0
  54. package/dist/assets/python/strands/base/gitignore.template +41 -0
  55. package/dist/assets/python/strands/base/main.py +76 -0
  56. package/dist/assets/python/strands/base/mcp_client/client.py +12 -0
  57. package/dist/assets/python/strands/base/model/load.py +123 -0
  58. package/dist/assets/python/strands/base/pyproject.toml +23 -0
  59. package/dist/assets/python/strands/capabilities/memory/session.py +39 -0
  60. package/dist/assets/typescript/.gitkeep +0 -0
  61. package/dist/cli/index.mjs +985 -0
  62. package/dist/index.d.ts +9 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +27 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/lib/constants.d.ts +25 -0
  67. package/dist/lib/constants.d.ts.map +1 -0
  68. package/dist/lib/constants.js +49 -0
  69. package/dist/lib/constants.js.map +1 -0
  70. package/dist/lib/errors/config.d.ts +49 -0
  71. package/dist/lib/errors/config.d.ts.map +1 -0
  72. package/dist/lib/errors/config.js +167 -0
  73. package/dist/lib/errors/config.js.map +1 -0
  74. package/dist/lib/errors/index.d.ts +2 -0
  75. package/dist/lib/errors/index.d.ts.map +1 -0
  76. package/dist/lib/errors/index.js +18 -0
  77. package/dist/lib/errors/index.js.map +1 -0
  78. package/dist/lib/index.d.ts +7 -0
  79. package/dist/lib/index.d.ts.map +1 -0
  80. package/dist/lib/index.js +39 -0
  81. package/dist/lib/index.js.map +1 -0
  82. package/dist/lib/packaging/errors.d.ts +16 -0
  83. package/dist/lib/packaging/errors.d.ts.map +1 -0
  84. package/dist/lib/packaging/errors.js +36 -0
  85. package/dist/lib/packaging/errors.js.map +1 -0
  86. package/dist/lib/packaging/helpers.d.ts +54 -0
  87. package/dist/lib/packaging/helpers.d.ts.map +1 -0
  88. package/dist/lib/packaging/helpers.js +461 -0
  89. package/dist/lib/packaging/helpers.js.map +1 -0
  90. package/dist/lib/packaging/index.d.ts +36 -0
  91. package/dist/lib/packaging/index.d.ts.map +1 -0
  92. package/dist/lib/packaging/index.js +89 -0
  93. package/dist/lib/packaging/index.js.map +1 -0
  94. package/dist/lib/packaging/node.d.ts +17 -0
  95. package/dist/lib/packaging/node.d.ts.map +1 -0
  96. package/dist/lib/packaging/node.js +108 -0
  97. package/dist/lib/packaging/node.js.map +1 -0
  98. package/dist/lib/packaging/python.d.ts +17 -0
  99. package/dist/lib/packaging/python.d.ts.map +1 -0
  100. package/dist/lib/packaging/python.js +162 -0
  101. package/dist/lib/packaging/python.js.map +1 -0
  102. package/dist/lib/packaging/types/index.d.ts +2 -0
  103. package/dist/lib/packaging/types/index.d.ts.map +1 -0
  104. package/dist/lib/packaging/types/index.js +3 -0
  105. package/dist/lib/packaging/types/index.js.map +1 -0
  106. package/dist/lib/packaging/types/packaging.d.ts +57 -0
  107. package/dist/lib/packaging/types/packaging.d.ts.map +1 -0
  108. package/dist/lib/packaging/types/packaging.js +3 -0
  109. package/dist/lib/packaging/types/packaging.js.map +1 -0
  110. package/dist/lib/packaging/uv.d.ts +7 -0
  111. package/dist/lib/packaging/uv.d.ts.map +1 -0
  112. package/dist/lib/packaging/uv.js +40 -0
  113. package/dist/lib/packaging/uv.js.map +1 -0
  114. package/dist/lib/schemas/io/config-io.d.ts +106 -0
  115. package/dist/lib/schemas/io/config-io.d.ts.map +1 -0
  116. package/dist/lib/schemas/io/config-io.js +293 -0
  117. package/dist/lib/schemas/io/config-io.js.map +1 -0
  118. package/dist/lib/schemas/io/index.d.ts +3 -0
  119. package/dist/lib/schemas/io/index.d.ts.map +1 -0
  120. package/dist/lib/schemas/io/index.js +17 -0
  121. package/dist/lib/schemas/io/index.js.map +1 -0
  122. package/dist/lib/schemas/io/path-resolver.d.ts +112 -0
  123. package/dist/lib/schemas/io/path-resolver.d.ts.map +1 -0
  124. package/dist/lib/schemas/io/path-resolver.js +195 -0
  125. package/dist/lib/schemas/io/path-resolver.js.map +1 -0
  126. package/dist/lib/utils/aws-account.d.ts +7 -0
  127. package/dist/lib/utils/aws-account.d.ts.map +1 -0
  128. package/dist/lib/utils/aws-account.js +24 -0
  129. package/dist/lib/utils/aws-account.js.map +1 -0
  130. package/dist/lib/utils/credentials.d.ts +86 -0
  131. package/dist/lib/utils/credentials.d.ts.map +1 -0
  132. package/dist/lib/utils/credentials.js +153 -0
  133. package/dist/lib/utils/credentials.js.map +1 -0
  134. package/dist/lib/utils/env.d.ts +22 -0
  135. package/dist/lib/utils/env.d.ts.map +1 -0
  136. package/dist/lib/utils/env.js +65 -0
  137. package/dist/lib/utils/env.js.map +1 -0
  138. package/dist/lib/utils/index.d.ts +7 -0
  139. package/dist/lib/utils/index.d.ts.map +1 -0
  140. package/dist/lib/utils/index.js +23 -0
  141. package/dist/lib/utils/index.js.map +1 -0
  142. package/dist/lib/utils/platform.d.ts +63 -0
  143. package/dist/lib/utils/platform.d.ts.map +1 -0
  144. package/dist/lib/utils/platform.js +88 -0
  145. package/dist/lib/utils/platform.js.map +1 -0
  146. package/dist/lib/utils/subprocess.d.ts +29 -0
  147. package/dist/lib/utils/subprocess.d.ts.map +1 -0
  148. package/dist/lib/utils/subprocess.js +94 -0
  149. package/dist/lib/utils/subprocess.js.map +1 -0
  150. package/dist/lib/utils/zod.d.ts +14 -0
  151. package/dist/lib/utils/zod.d.ts.map +1 -0
  152. package/dist/lib/utils/zod.js +32 -0
  153. package/dist/lib/utils/zod.js.map +1 -0
  154. package/dist/schema/constants.d.ts +82 -0
  155. package/dist/schema/constants.d.ts.map +1 -0
  156. package/dist/schema/constants.js +117 -0
  157. package/dist/schema/constants.js.map +1 -0
  158. package/dist/schema/index.d.ts +4 -0
  159. package/dist/schema/index.d.ts.map +1 -0
  160. package/dist/schema/index.js +21 -0
  161. package/dist/schema/index.js.map +1 -0
  162. package/dist/schema/schemas/agent-env.d.ts +75 -0
  163. package/dist/schema/schemas/agent-env.d.ts.map +1 -0
  164. package/dist/schema/schemas/agent-env.js +84 -0
  165. package/dist/schema/schemas/agent-env.js.map +1 -0
  166. package/dist/schema/schemas/agentcore-project.d.ts +88 -0
  167. package/dist/schema/schemas/agentcore-project.d.ts.map +1 -0
  168. package/dist/schema/schemas/agentcore-project.js +83 -0
  169. package/dist/schema/schemas/agentcore-project.js.map +1 -0
  170. package/dist/schema/schemas/aws-targets.d.ts +50 -0
  171. package/dist/schema/schemas/aws-targets.d.ts.map +1 -0
  172. package/dist/schema/schemas/aws-targets.js +49 -0
  173. package/dist/schema/schemas/aws-targets.js.map +1 -0
  174. package/dist/schema/schemas/deployed-state.d.ts +260 -0
  175. package/dist/schema/schemas/deployed-state.d.ts.map +1 -0
  176. package/dist/schema/schemas/deployed-state.js +100 -0
  177. package/dist/schema/schemas/deployed-state.js.map +1 -0
  178. package/dist/schema/schemas/index.d.ts +8 -0
  179. package/dist/schema/schemas/index.d.ts.map +1 -0
  180. package/dist/schema/schemas/index.js +25 -0
  181. package/dist/schema/schemas/index.js.map +1 -0
  182. package/dist/schema/schemas/mcp-defs.d.ts +52 -0
  183. package/dist/schema/schemas/mcp-defs.d.ts.map +1 -0
  184. package/dist/schema/schemas/mcp-defs.js +50 -0
  185. package/dist/schema/schemas/mcp-defs.js.map +1 -0
  186. package/dist/schema/schemas/mcp.d.ts +659 -0
  187. package/dist/schema/schemas/mcp.d.ts.map +1 -0
  188. package/dist/schema/schemas/mcp.js +283 -0
  189. package/dist/schema/schemas/mcp.js.map +1 -0
  190. package/dist/schema/schemas/primitives/index.d.ts +3 -0
  191. package/dist/schema/schemas/primitives/index.d.ts.map +1 -0
  192. package/dist/schema/schemas/primitives/index.js +9 -0
  193. package/dist/schema/schemas/primitives/index.js.map +1 -0
  194. package/dist/schema/schemas/primitives/memory.d.ts +42 -0
  195. package/dist/schema/schemas/primitives/memory.d.ts.map +1 -0
  196. package/dist/schema/schemas/primitives/memory.js +50 -0
  197. package/dist/schema/schemas/primitives/memory.js.map +1 -0
  198. package/dist/schema/schemas/zod-util.d.ts +10 -0
  199. package/dist/schema/schemas/zod-util.d.ts.map +1 -0
  200. package/dist/schema/schemas/zod-util.js +23 -0
  201. package/dist/schema/schemas/zod-util.js.map +1 -0
  202. package/dist/schema/types/index.d.ts +2 -0
  203. package/dist/schema/types/index.d.ts.map +1 -0
  204. package/dist/schema/types/index.js +18 -0
  205. package/dist/schema/types/index.js.map +1 -0
  206. package/dist/schema/types/path.d.ts +27 -0
  207. package/dist/schema/types/path.d.ts.map +1 -0
  208. package/dist/schema/types/path.js +13 -0
  209. package/dist/schema/types/path.js.map +1 -0
  210. package/package.json +111 -0
  211. package/scripts/bump-version.ts +442 -0
  212. package/scripts/check-old-cli.mjs +26 -0
  213. package/scripts/copy-assets.mjs +50 -0
@@ -0,0 +1,293 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigIO = void 0;
4
+ exports.createConfigIO = createConfigIO;
5
+ const schema_1 = require("../../../schema");
6
+ const errors_1 = require("../../errors");
7
+ const utils_1 = require("../../utils");
8
+ const path_resolver_1 = require("./path-resolver");
9
+ const shared_ini_file_loader_1 = require("@smithy/shared-ini-file-loader");
10
+ const fs_1 = require("fs");
11
+ const promises_1 = require("fs/promises");
12
+ const path_1 = require("path");
13
+ /**
14
+ * Manages reading, writing, and validation of AgentCore configuration files
15
+ */
16
+ class ConfigIO {
17
+ pathResolver;
18
+ projectDiscovered;
19
+ /**
20
+ * Create a ConfigIO instance.
21
+ * If no baseDir is provided, automatically discovers the project using findConfigRoot().
22
+ */
23
+ constructor(pathConfig) {
24
+ // Track if baseDir was explicitly provided
25
+ const baseDirProvided = !!pathConfig?.baseDir;
26
+ // Auto-discover config root if no baseDir provided
27
+ if (!baseDirProvided) {
28
+ const discoveredRoot = (0, path_resolver_1.findConfigRoot)();
29
+ if (discoveredRoot) {
30
+ pathConfig = { ...pathConfig, baseDir: discoveredRoot };
31
+ this.projectDiscovered = true;
32
+ }
33
+ else {
34
+ // No project found and no explicit baseDir - mark as not discovered
35
+ this.projectDiscovered = false;
36
+ }
37
+ }
38
+ else {
39
+ // baseDir was explicitly provided (e.g., during project creation)
40
+ this.projectDiscovered = true;
41
+ }
42
+ this.pathResolver = new path_resolver_1.PathResolver(pathConfig);
43
+ }
44
+ /**
45
+ * Check if this ConfigIO is associated with a discovered or explicitly configured project.
46
+ * Returns false if no baseDir was provided and no project was found via auto-discovery.
47
+ */
48
+ hasProject() {
49
+ return this.projectDiscovered;
50
+ }
51
+ /**
52
+ * Get the current path resolver
53
+ */
54
+ getPathResolver() {
55
+ return this.pathResolver;
56
+ }
57
+ /**
58
+ * Update the base directory for config files
59
+ */
60
+ setBaseDir(baseDir) {
61
+ this.pathResolver.setBaseDir(baseDir);
62
+ }
63
+ /**
64
+ * Get the project root directory (parent of agentcore/)
65
+ */
66
+ getProjectRoot() {
67
+ return this.pathResolver.getProjectRoot();
68
+ }
69
+ /**
70
+ * Get the config root directory (the agentcore/ directory)
71
+ */
72
+ getConfigRoot() {
73
+ return this.pathResolver.getBaseDir();
74
+ }
75
+ /**
76
+ * Read and validate the project configuration.
77
+ */
78
+ async readProjectSpec() {
79
+ const filePath = this.pathResolver.getAgentConfigPath();
80
+ return this.readAndValidate(filePath, 'AgentCore Project Config', schema_1.AgentCoreProjectSpecSchema);
81
+ }
82
+ /**
83
+ * Write and validate the project configuration file.
84
+ */
85
+ async writeProjectSpec(data) {
86
+ const filePath = this.pathResolver.getAgentConfigPath();
87
+ await this.validateAndWrite(filePath, 'AgentCore Project Config', schema_1.AgentCoreProjectSpecSchema, data);
88
+ }
89
+ /**
90
+ * Read and validate the AWS configuration file.
91
+ * Applies overrides following AWS SDK precedence:
92
+ * - Account: from current credentials if AWS_PROFILE is set
93
+ * - Region: AWS_REGION > AWS_DEFAULT_REGION > profile config > saved value
94
+ */
95
+ async readAWSDeploymentTargets() {
96
+ const filePath = this.pathResolver.getAWSTargetsConfigPath();
97
+ let targets = await this.readAndValidate(filePath, 'AWS Targets', schema_1.AwsDeploymentTargetsSchema);
98
+ // Override account from credentials if AWS_PROFILE is set
99
+ if (process.env.AWS_PROFILE) {
100
+ const account = await (0, utils_1.detectAwsAccount)();
101
+ if (account) {
102
+ targets = targets.map(t => ({ ...t, account }));
103
+ }
104
+ }
105
+ // Override region from env vars
106
+ const envRegion = process.env.AWS_REGION ?? process.env.AWS_DEFAULT_REGION;
107
+ if (envRegion && schema_1.AgentCoreRegionSchema.safeParse(envRegion).success) {
108
+ return targets.map(t => ({ ...t, region: envRegion }));
109
+ }
110
+ // Check profile config for region
111
+ try {
112
+ const profile = process.env.AWS_PROFILE ?? 'default';
113
+ const config = await (0, shared_ini_file_loader_1.loadSharedConfigFiles)();
114
+ const profileRegion = config.configFile?.[profile]?.region;
115
+ if (profileRegion && schema_1.AgentCoreRegionSchema.safeParse(profileRegion).success) {
116
+ return targets.map(t => ({ ...t, region: profileRegion }));
117
+ }
118
+ }
119
+ catch {
120
+ // Config file not available - use current targets
121
+ }
122
+ return targets;
123
+ }
124
+ /**
125
+ * Write and validate the AWS configuration file
126
+ */
127
+ async writeAWSDeploymentTargets(data) {
128
+ const filePath = this.pathResolver.getAWSTargetsConfigPath();
129
+ await this.validateAndWrite(filePath, 'AWS Targets', schema_1.AwsDeploymentTargetsSchema, data);
130
+ }
131
+ /**
132
+ * Read and validate the deployed state file.
133
+ * Validates that all target keys exist in aws-targets.
134
+ */
135
+ async readDeployedState() {
136
+ const targets = await this.readAWSDeploymentTargets();
137
+ const targetNames = targets.map(t => t.name);
138
+ const schema = (0, schema_1.createValidatedDeployedStateSchema)(targetNames);
139
+ const filePath = this.pathResolver.getStatePath();
140
+ return this.readAndValidate(filePath, 'State', schema);
141
+ }
142
+ /**
143
+ * Write and validate the deployed state file.
144
+ * Validates that all target keys exist in aws-targets.
145
+ */
146
+ async writeDeployedState(data) {
147
+ const targets = await this.readAWSDeploymentTargets();
148
+ const targetNames = targets.map(t => t.name);
149
+ const schema = (0, schema_1.createValidatedDeployedStateSchema)(targetNames);
150
+ const filePath = this.pathResolver.getStatePath();
151
+ await this.validateAndWrite(filePath, 'State', schema, data);
152
+ }
153
+ /**
154
+ * Read and validate the MCP configuration file
155
+ */
156
+ async readMcpSpec() {
157
+ const filePath = this.pathResolver.getMcpConfigPath();
158
+ return this.readAndValidate(filePath, 'MCP Config', schema_1.AgentCoreMcpSpecSchema);
159
+ }
160
+ /**
161
+ * Write and validate the MCP configuration file
162
+ */
163
+ async writeMcpSpec(data) {
164
+ const filePath = this.pathResolver.getMcpConfigPath();
165
+ await this.validateAndWrite(filePath, 'MCP Config', schema_1.AgentCoreMcpSpecSchema, data);
166
+ }
167
+ /**
168
+ * Read and validate the MCP definitions file
169
+ */
170
+ async readMcpDefs() {
171
+ const filePath = this.pathResolver.getMcpDefsPath();
172
+ return this.readAndValidate(filePath, 'MCP Definitions', schema_1.AgentCoreCliMcpDefsSchema);
173
+ }
174
+ /**
175
+ * Write and validate the MCP definitions file
176
+ */
177
+ async writeMcpDefs(data) {
178
+ const filePath = this.pathResolver.getMcpDefsPath();
179
+ await this.validateAndWrite(filePath, 'MCP Definitions', schema_1.AgentCoreCliMcpDefsSchema, data);
180
+ }
181
+ /**
182
+ * Check if the base directory exists
183
+ */
184
+ baseDirExists() {
185
+ return (0, fs_1.existsSync)(this.pathResolver.getBaseDir());
186
+ }
187
+ /**
188
+ * Check if a specific config file exists
189
+ */
190
+ configExists(type) {
191
+ const pathMap = {
192
+ project: this.pathResolver.getAgentConfigPath(),
193
+ awsTargets: this.pathResolver.getAWSTargetsConfigPath(),
194
+ state: this.pathResolver.getStatePath(),
195
+ mcp: this.pathResolver.getMcpConfigPath(),
196
+ mcpDefs: this.pathResolver.getMcpDefsPath(),
197
+ };
198
+ return (0, fs_1.existsSync)(pathMap[type]);
199
+ }
200
+ /**
201
+ * Initialize the base directory and CLI system subdirectory.
202
+ * Requires that a baseDir was explicitly provided or a project was discovered.
203
+ */
204
+ async initializeBaseDir() {
205
+ // Prevent creating directories when no project was configured
206
+ if (!this.projectDiscovered) {
207
+ throw new path_resolver_1.NoProjectError();
208
+ }
209
+ const baseDir = this.pathResolver.getBaseDir();
210
+ const cliSystemDir = this.pathResolver.getCliSystemDir();
211
+ try {
212
+ await (0, promises_1.mkdir)(baseDir, { recursive: true });
213
+ await (0, promises_1.mkdir)(cliSystemDir, { recursive: true });
214
+ }
215
+ catch (err) {
216
+ const normalizedError = err instanceof Error ? err : new Error('Unknown error');
217
+ throw new errors_1.ConfigWriteError(baseDir, normalizedError);
218
+ }
219
+ }
220
+ /**
221
+ * Generic read and validate method
222
+ */
223
+ async readAndValidate(filePath, fileType, schema) {
224
+ // Check if file exists
225
+ if (!(0, fs_1.existsSync)(filePath)) {
226
+ throw new errors_1.ConfigNotFoundError(filePath, fileType);
227
+ }
228
+ // Read file
229
+ let fileContent;
230
+ try {
231
+ fileContent = await (0, promises_1.readFile)(filePath, 'utf-8');
232
+ }
233
+ catch (err) {
234
+ const normalizedError = err instanceof Error ? err : new Error('Unknown error');
235
+ throw new errors_1.ConfigReadError(filePath, normalizedError);
236
+ }
237
+ // Parse JSON
238
+ let parsed;
239
+ try {
240
+ parsed = JSON.parse(fileContent);
241
+ }
242
+ catch (err) {
243
+ const normalizedError = err instanceof Error ? err : new Error('Invalid JSON');
244
+ throw new errors_1.ConfigParseError(filePath, normalizedError);
245
+ }
246
+ // Validate with Zod schema
247
+ const result = schema.safeParse(parsed);
248
+ if (!result.success) {
249
+ throw new errors_1.ConfigValidationError(filePath, fileType, result.error);
250
+ }
251
+ return result.data;
252
+ }
253
+ /**
254
+ * Generic validate and write method
255
+ */
256
+ async validateAndWrite(filePath, fileType, schema, data) {
257
+ // Prevent writing to non-existent projects
258
+ if (!this.projectDiscovered) {
259
+ throw new path_resolver_1.NoProjectError();
260
+ }
261
+ // Validate data with Zod schema
262
+ const result = schema.safeParse(data);
263
+ if (!result.success) {
264
+ throw new errors_1.ConfigValidationError(filePath, fileType, result.error);
265
+ }
266
+ // Ensure directory exists
267
+ const dir = (0, path_1.dirname)(filePath);
268
+ try {
269
+ await (0, promises_1.mkdir)(dir, { recursive: true });
270
+ }
271
+ catch (err) {
272
+ const normalizedError = err instanceof Error ? err : new Error('Unknown error');
273
+ throw new errors_1.ConfigWriteError(filePath, normalizedError);
274
+ }
275
+ // Write file with pretty formatting
276
+ try {
277
+ const jsonContent = JSON.stringify(result.data, null, 2);
278
+ await (0, promises_1.writeFile)(filePath, jsonContent, 'utf-8');
279
+ }
280
+ catch (err) {
281
+ const normalizedError = err instanceof Error ? err : new Error('Unknown error');
282
+ throw new errors_1.ConfigWriteError(filePath, normalizedError);
283
+ }
284
+ }
285
+ }
286
+ exports.ConfigIO = ConfigIO;
287
+ /**
288
+ * Create a new ConfigIO instance
289
+ */
290
+ function createConfigIO(pathConfig) {
291
+ return new ConfigIO(pathConfig);
292
+ }
293
+ //# sourceMappingURL=config-io.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-io.js","sourceRoot":"","sources":["../../../../src/lib/schemas/io/config-io.ts"],"names":[],"mappings":";;;AAgVA,wCAEC;AA3UD,4CAOyB;AACzB,yCAMsB;AACtB,uCAA+C;AAC/C,mDAAgG;AAChG,2EAAuE;AACvE,2BAAgC;AAChC,0CAAyD;AACzD,+BAA+B;AAG/B;;GAEG;AACH,MAAa,QAAQ;IACF,YAAY,CAAe;IAC3B,iBAAiB,CAAU;IAE5C;;;OAGG;IACH,YAAY,UAAgC;QAC1C,2CAA2C;QAC3C,MAAM,eAAe,GAAG,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC;QAE9C,mDAAmD;QACnD,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,MAAM,cAAc,GAAG,IAAA,8BAAc,GAAE,CAAC;YACxC,IAAI,cAAc,EAAE,CAAC;gBACnB,UAAU,GAAG,EAAE,GAAG,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;gBACxD,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,oEAAoE;gBACpE,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC;YACjC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,kEAAkE;YAClE,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAChC,CAAC;QAED,IAAI,CAAC,YAAY,GAAG,IAAI,4BAAY,CAAC,UAAU,CAAC,CAAC;IACnD,CAAC;IAED;;;OAGG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,OAAe;QACxB,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,cAAc,E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IAAI,EAAE,CAAC,CAAC,CAAC;YACzD,MAAM,IAAA,oBAAS,EAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;QAClD,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACtB,MAAM,eAAe,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;YAChF,MAAM,IAAI,yBAAgB,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;CACF;AA1SD,4BA0SC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,UAAgC;IAC7D,OAAO,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { PathResolver, DEFAULT_PATH_CONFIG, findConfigRoot, findProjectRoot, setSessionProjectRoot, getSessionProjectRoot, getWorkingDirectory, requireConfigRoot, NoProjectError, type PathConfig, } from './path-resolver';
2
+ export { ConfigIO, createConfigIO } from './config-io';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/schemas/io/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,iBAAiB,EACjB,cAAc,EACd,KAAK,UAAU,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createConfigIO = exports.ConfigIO = exports.NoProjectError = exports.requireConfigRoot = exports.getWorkingDirectory = exports.getSessionProjectRoot = exports.setSessionProjectRoot = exports.findProjectRoot = exports.findConfigRoot = exports.DEFAULT_PATH_CONFIG = exports.PathResolver = void 0;
4
+ var path_resolver_1 = require("./path-resolver");
5
+ Object.defineProperty(exports, "PathResolver", { enumerable: true, get: function () { return path_resolver_1.PathResolver; } });
6
+ Object.defineProperty(exports, "DEFAULT_PATH_CONFIG", { enumerable: true, get: function () { return path_resolver_1.DEFAULT_PATH_CONFIG; } });
7
+ Object.defineProperty(exports, "findConfigRoot", { enumerable: true, get: function () { return path_resolver_1.findConfigRoot; } });
8
+ Object.defineProperty(exports, "findProjectRoot", { enumerable: true, get: function () { return path_resolver_1.findProjectRoot; } });
9
+ Object.defineProperty(exports, "setSessionProjectRoot", { enumerable: true, get: function () { return path_resolver_1.setSessionProjectRoot; } });
10
+ Object.defineProperty(exports, "getSessionProjectRoot", { enumerable: true, get: function () { return path_resolver_1.getSessionProjectRoot; } });
11
+ Object.defineProperty(exports, "getWorkingDirectory", { enumerable: true, get: function () { return path_resolver_1.getWorkingDirectory; } });
12
+ Object.defineProperty(exports, "requireConfigRoot", { enumerable: true, get: function () { return path_resolver_1.requireConfigRoot; } });
13
+ Object.defineProperty(exports, "NoProjectError", { enumerable: true, get: function () { return path_resolver_1.NoProjectError; } });
14
+ var config_io_1 = require("./config-io");
15
+ Object.defineProperty(exports, "ConfigIO", { enumerable: true, get: function () { return config_io_1.ConfigIO; } });
16
+ Object.defineProperty(exports, "createConfigIO", { enumerable: true, get: function () { return config_io_1.createConfigIO; } });
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/schemas/io/index.ts"],"names":[],"mappings":";;;AAAA,iDAWyB;AAVvB,6GAAA,YAAY,OAAA;AACZ,oHAAA,mBAAmB,OAAA;AACnB,+GAAA,cAAc,OAAA;AACd,gHAAA,eAAe,OAAA;AACf,sHAAA,qBAAqB,OAAA;AACrB,sHAAA,qBAAqB,OAAA;AACrB,oHAAA,mBAAmB,OAAA;AACnB,kHAAA,iBAAiB,OAAA;AACjB,+GAAA,cAAc,OAAA;AAGhB,yCAAuD;AAA9C,qGAAA,QAAQ,OAAA;AAAE,2GAAA,cAAc,OAAA"}
@@ -0,0 +1,112 @@
1
+ export declare const CONFIG_FILES: {
2
+ readonly AGENT_ENV: "agentcore.json";
3
+ readonly AWS_TARGETS: "aws-targets.json";
4
+ readonly DEPLOYED_STATE: "deployed-state.json";
5
+ readonly MCP: "mcp.json";
6
+ readonly MCP_DEFS: "mcp-defs.json";
7
+ };
8
+ /**
9
+ * Error thrown when no AgentCore project is found.
10
+ */
11
+ export declare class NoProjectError extends Error {
12
+ constructor(message?: string);
13
+ }
14
+ /**
15
+ * Get the working directory where the user invoked the CLI.
16
+ *
17
+ * When running via npm/bun scripts (e.g., `npm run cli`), the package manager
18
+ * changes process.cwd() to the package root. INIT_CWD preserves the original
19
+ * directory where the user ran the command.
20
+ *
21
+ * For globally installed CLIs, INIT_CWD is not set, so we fall back to process.cwd().
22
+ */
23
+ export declare function getWorkingDirectory(): string;
24
+ /**
25
+ * Find the config root, throwing NoProjectError if not found.
26
+ * Use this when a project is required to proceed.
27
+ */
28
+ export declare function requireConfigRoot(startDir?: string): string;
29
+ /**
30
+ * Set the project root for the current session.
31
+ * Call this after init creates a new project at cwd/projectName/.
32
+ * Subsequent calls to findConfigRoot() will check this location first.
33
+ */
34
+ export declare function setSessionProjectRoot(projectRoot: string): void;
35
+ /**
36
+ * Get the current session project root, if set.
37
+ */
38
+ export declare function getSessionProjectRoot(): string | null;
39
+ /**
40
+ * Configuration for where AgentCore files are stored
41
+ */
42
+ export interface PathConfig {
43
+ /** Base directory for all AgentCore files */
44
+ baseDir: string;
45
+ }
46
+ /**
47
+ * Walk up the directory tree from startDir looking for an agentcore directory.
48
+ * If a session project was set (via setSessionProjectRoot), checks there first.
49
+ * Returns the path to the agentcore directory if found, or null if not found.
50
+ */
51
+ export declare function findConfigRoot(startDir?: string): string | null;
52
+ /**
53
+ * Get the project root directory (parent of agentcore/).
54
+ * Returns null if no project is found.
55
+ */
56
+ export declare function findProjectRoot(startDir?: string): string | null;
57
+ /**
58
+ * Default configuration uses agentcore/ in current working directory.
59
+ */
60
+ export declare const DEFAULT_PATH_CONFIG: PathConfig;
61
+ /**
62
+ * Utility class for resolving AgentCore file paths
63
+ */
64
+ export declare class PathResolver {
65
+ private config;
66
+ constructor(config?: Partial<PathConfig>);
67
+ /**
68
+ * Get the base directory path (the agentcore/ config directory)
69
+ */
70
+ getBaseDir(): string;
71
+ /**
72
+ * Get the project root directory (parent of agentcore/)
73
+ */
74
+ getProjectRoot(): string;
75
+ /**
76
+ * Get the path to the agent config file (agentcore.json)
77
+ */
78
+ getAgentConfigPath(): string;
79
+ /**
80
+ * Get the path to the AWS targets config file (aws-targets.json)
81
+ */
82
+ getAWSTargetsConfigPath(): string;
83
+ /**
84
+ * Get the path to the CLI system directory (agentcore/.cli/)
85
+ */
86
+ getCliSystemDir(): string;
87
+ /**
88
+ * Get the path to the logs directory (agentcore/.cli/logs/)
89
+ */
90
+ getLogsDir(): string;
91
+ /**
92
+ * Get the path to the invoke logs directory (agentcore/.cli/logs/invoke/)
93
+ */
94
+ getInvokeLogsDir(): string;
95
+ /**
96
+ * Get the path to the deployed state file (agentcore/.cli/deployed-state.json)
97
+ */
98
+ getStatePath(): string;
99
+ /**
100
+ * Get the path to the MCP config file (mcp.json)
101
+ */
102
+ getMcpConfigPath(): string;
103
+ /**
104
+ * Get the path to the MCP definitions file (mcp-defs.json)
105
+ */
106
+ getMcpDefsPath(): string;
107
+ /**
108
+ * Update the base directory
109
+ */
110
+ setBaseDir(baseDir: string): void;
111
+ }
112
+ //# sourceMappingURL=path-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-resolver.d.ts","sourceRoot":"","sources":["../../../../src/lib/schemas/io/path-resolver.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,YAAY;;;;;;CAAgB,CAAC;AAE1C;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,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strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PathResolver = exports.DEFAULT_PATH_CONFIG = exports.NoProjectError = exports.CONFIG_FILES = void 0;
4
+ exports.getWorkingDirectory = getWorkingDirectory;
5
+ exports.requireConfigRoot = requireConfigRoot;
6
+ exports.setSessionProjectRoot = setSessionProjectRoot;
7
+ exports.getSessionProjectRoot = getSessionProjectRoot;
8
+ exports.findConfigRoot = findConfigRoot;
9
+ exports.findProjectRoot = findProjectRoot;
10
+ const constants_1 = require("../../constants");
11
+ const fs_1 = require("fs");
12
+ const path_1 = require("path");
13
+ // Re-export for backward compatibility
14
+ exports.CONFIG_FILES = constants_1.CONFIG_FILES;
15
+ /**
16
+ * Error thrown when no AgentCore project is found.
17
+ */
18
+ class NoProjectError extends Error {
19
+ constructor(message) {
20
+ super(message ?? 'No agentcore project found. Run "agentcore create" first.');
21
+ this.name = 'NoProjectError';
22
+ }
23
+ }
24
+ exports.NoProjectError = NoProjectError;
25
+ /**
26
+ * Get the working directory where the user invoked the CLI.
27
+ *
28
+ * When running via npm/bun scripts (e.g., `npm run cli`), the package manager
29
+ * changes process.cwd() to the package root. INIT_CWD preserves the original
30
+ * directory where the user ran the command.
31
+ *
32
+ * For globally installed CLIs, INIT_CWD is not set, so we fall back to process.cwd().
33
+ */
34
+ function getWorkingDirectory() {
35
+ return process.env.INIT_CWD ?? process.cwd();
36
+ }
37
+ /**
38
+ * Find the config root, throwing NoProjectError if not found.
39
+ * Use this when a project is required to proceed.
40
+ */
41
+ function requireConfigRoot(startDir) {
42
+ const configRoot = findConfigRoot(startDir);
43
+ if (!configRoot) {
44
+ throw new NoProjectError();
45
+ }
46
+ return configRoot;
47
+ }
48
+ /**
49
+ * Session-level project root override.
50
+ * Set this after init creates a project so subsequent discovery finds it.
51
+ */
52
+ let sessionProjectRoot = null;
53
+ /**
54
+ * Set the project root for the current session.
55
+ * Call this after init creates a new project at cwd/projectName/.
56
+ * Subsequent calls to findConfigRoot() will check this location first.
57
+ */
58
+ function setSessionProjectRoot(projectRoot) {
59
+ sessionProjectRoot = projectRoot;
60
+ }
61
+ /**
62
+ * Get the current session project root, if set.
63
+ */
64
+ function getSessionProjectRoot() {
65
+ return sessionProjectRoot;
66
+ }
67
+ /**
68
+ * Check if a directory is a valid AgentCore config directory.
69
+ * A valid config directory contains agentcore.json.
70
+ */
71
+ function isValidConfigDir(configPath) {
72
+ return (0, fs_1.existsSync)((0, path_1.join)(configPath, constants_1.CONFIG_FILES.AGENT_ENV));
73
+ }
74
+ /**
75
+ * Walk up the directory tree from startDir looking for an agentcore directory.
76
+ * If a session project was set (via setSessionProjectRoot), checks there first.
77
+ * Returns the path to the agentcore directory if found, or null if not found.
78
+ */
79
+ function findConfigRoot(startDir = getWorkingDirectory()) {
80
+ // Check session project first (set after init creates a project)
81
+ if (sessionProjectRoot) {
82
+ const sessionConfigPath = (0, path_1.join)(sessionProjectRoot, constants_1.CONFIG_DIR);
83
+ if ((0, fs_1.existsSync)(sessionConfigPath) && isValidConfigDir(sessionConfigPath)) {
84
+ return sessionConfigPath;
85
+ }
86
+ }
87
+ // Fall back to walking up the directory tree
88
+ let currentDir = startDir;
89
+ while (true) {
90
+ const configPath = (0, path_1.join)(currentDir, constants_1.CONFIG_DIR);
91
+ if ((0, fs_1.existsSync)(configPath) && isValidConfigDir(configPath)) {
92
+ return configPath;
93
+ }
94
+ const parentDir = (0, path_1.dirname)(currentDir);
95
+ // Reached filesystem root
96
+ if (parentDir === currentDir) {
97
+ return null;
98
+ }
99
+ currentDir = parentDir;
100
+ }
101
+ }
102
+ /**
103
+ * Get the project root directory (parent of agentcore/).
104
+ * Returns null if no project is found.
105
+ */
106
+ function findProjectRoot(startDir = process.cwd()) {
107
+ const configRoot = findConfigRoot(startDir);
108
+ return configRoot ? (0, path_1.dirname)(configRoot) : null;
109
+ }
110
+ /**
111
+ * Default configuration uses agentcore/ in current working directory.
112
+ */
113
+ exports.DEFAULT_PATH_CONFIG = {
114
+ baseDir: (0, path_1.join)(getWorkingDirectory(), constants_1.CONFIG_DIR),
115
+ };
116
+ /**
117
+ * Utility class for resolving AgentCore file paths
118
+ */
119
+ class PathResolver {
120
+ config;
121
+ constructor(config) {
122
+ this.config = {
123
+ ...exports.DEFAULT_PATH_CONFIG,
124
+ ...config,
125
+ };
126
+ }
127
+ /**
128
+ * Get the base directory path (the agentcore/ config directory)
129
+ */
130
+ getBaseDir() {
131
+ return this.config.baseDir;
132
+ }
133
+ /**
134
+ * Get the project root directory (parent of agentcore/)
135
+ */
136
+ getProjectRoot() {
137
+ return (0, path_1.dirname)(this.config.baseDir);
138
+ }
139
+ /**
140
+ * Get the path to the agent config file (agentcore.json)
141
+ */
142
+ getAgentConfigPath() {
143
+ return (0, path_1.join)(this.config.baseDir, exports.CONFIG_FILES.AGENT_ENV);
144
+ }
145
+ /**
146
+ * Get the path to the AWS targets config file (aws-targets.json)
147
+ */
148
+ getAWSTargetsConfigPath() {
149
+ return (0, path_1.join)(this.config.baseDir, exports.CONFIG_FILES.AWS_TARGETS);
150
+ }
151
+ /**
152
+ * Get the path to the CLI system directory (agentcore/.cli/)
153
+ */
154
+ getCliSystemDir() {
155
+ return (0, path_1.join)(this.config.baseDir, constants_1.CLI_SYSTEM_DIR);
156
+ }
157
+ /**
158
+ * Get the path to the logs directory (agentcore/.cli/logs/)
159
+ */
160
+ getLogsDir() {
161
+ return (0, path_1.join)(this.config.baseDir, constants_1.CLI_SYSTEM_DIR, constants_1.CLI_LOGS_DIR);
162
+ }
163
+ /**
164
+ * Get the path to the invoke logs directory (agentcore/.cli/logs/invoke/)
165
+ */
166
+ getInvokeLogsDir() {
167
+ return (0, path_1.join)(this.config.baseDir, constants_1.CLI_SYSTEM_DIR, constants_1.CLI_LOGS_DIR, 'invoke');
168
+ }
169
+ /**
170
+ * Get the path to the deployed state file (agentcore/.cli/deployed-state.json)
171
+ */
172
+ getStatePath() {
173
+ return (0, path_1.join)(this.config.baseDir, constants_1.CLI_SYSTEM_DIR, exports.CONFIG_FILES.DEPLOYED_STATE);
174
+ }
175
+ /**
176
+ * Get the path to the MCP config file (mcp.json)
177
+ */
178
+ getMcpConfigPath() {
179
+ return (0, path_1.join)(this.config.baseDir, exports.CONFIG_FILES.MCP);
180
+ }
181
+ /**
182
+ * Get the path to the MCP definitions file (mcp-defs.json)
183
+ */
184
+ getMcpDefsPath() {
185
+ return (0, path_1.join)(this.config.baseDir, exports.CONFIG_FILES.MCP_DEFS);
186
+ }
187
+ /**
188
+ * Update the base directory
189
+ */
190
+ setBaseDir(baseDir) {
191
+ this.config.baseDir = baseDir;
192
+ }
193
+ }
194
+ exports.PathResolver = PathResolver;
195
+ //# sourceMappingURL=path-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-resolver.js","sourceRoot":"","sources":["../../../../src/lib/schemas/io/path-resolver.ts"],"names":[],"mappings":";;;AA0BA,kDAEC;AAMD,8CAMC;AAaD,sDAEC;AAKD,sDAEC;AAuBD,wCAyBC;AAMD,0CAGC;AAvHD,+CAA0G;AAC1G,2BAAgC;AAChC,+BAAqC;AAErC,uCAAuC;AAC1B,QAAA,YAAY,GAAG,wBAAa,CAAC;AAE1C;;GAEG;AACH,MAAa,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,IAAI,2DAA2D,CAAC,CAAC;QAC9E,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AALD,wCAKC;AAED;;;;;;;;GAQG;AACH,SAAgB,mBAAmB;IACjC,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;AAC/C,CAAC;AAED;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,QAAiB;IACjD,MAAM,UAAU,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC5C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,cAAc,EAAE,CAAC;IAC7B,CAAC;IACD,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,gBAAgB;QACd,OAAO,IAAA,WAAI,EAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,0BAAc,EAAE,wBAAY,EAAE,QAAQ,CAAC,CAAC;IAC3E,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,IAAA,WAAI,EAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,0BAAc,EAAE,oBAAY,CAAC,cAAc,CAAC,CAAC;IAChF,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,OAAO,IAAA,WAAI,EAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,oBAAY,CAAC,GAAG,CAAC,CAAC;IACrD,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAA,WAAI,EAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,oBAAY,CAAC,QAAQ,CAAC,CAAC;IAC1D,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,OAAe;QACxB,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;IAChC,CAAC;CACF;AAtFD,oCAsFC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Detect AWS account ID from current credentials using STS GetCallerIdentity.
3
+ * This call always succeeds if credentials are valid (cannot be denied by IAM).
4
+ * Returns null if credentials are not available or invalid.
5
+ */
6
+ export declare function detectAwsAccount(): Promise<string | null>;
7
+ //# sourceMappingURL=aws-account.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aws-account.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/aws-account.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAW/D"}