@iinm/plain-agent 1.8.0 → 1.8.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iinm/plain-agent",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "A lightweight CLI-based coding agent",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -5,12 +5,26 @@ import { createHash, createHmac } from "node:crypto";
5
5
  * @typedef {{ accessKeyId: string, secretAccessKey: string, sessionToken?: string }} AwsCredentials
6
6
  */
7
7
 
8
+ /** @type {Map<string, { credentials: AwsCredentials, expiration: Date }>} */
9
+ const credentialCache = new Map();
10
+
11
+ const EXPIRATION_MARGIN_MS = 60 * 1000;
12
+
8
13
  /**
9
14
  * Load AWS credentials for the given profile using the AWS CLI.
15
+ * Results are cached and reused until the credentials expire.
10
16
  * @param {string} profile
11
17
  * @returns {Promise<AwsCredentials>}
12
18
  */
13
19
  export async function loadAwsCredentials(profile) {
20
+ const cached = credentialCache.get(profile);
21
+ if (
22
+ cached &&
23
+ Date.now() < cached.expiration.getTime() - EXPIRATION_MARGIN_MS
24
+ ) {
25
+ return cached.credentials;
26
+ }
27
+
14
28
  /** @type {string} */
15
29
  const stdout = await new Promise((resolve, reject) => {
16
30
  execFile(
@@ -37,11 +51,20 @@ export async function loadAwsCredentials(profile) {
37
51
  );
38
52
  }
39
53
  }
40
- return {
54
+ const credentials = {
41
55
  accessKeyId: parsed.AccessKeyId,
42
56
  secretAccessKey: parsed.SecretAccessKey,
43
57
  ...(parsed.SessionToken && { sessionToken: parsed.SessionToken }),
44
58
  };
59
+
60
+ if (parsed.Expiration) {
61
+ const expiration = new Date(parsed.Expiration);
62
+ if (!Number.isNaN(expiration.getTime())) {
63
+ credentialCache.set(profile, { credentials, expiration });
64
+ }
65
+ }
66
+
67
+ return credentials;
45
68
  }
46
69
 
47
70
  /**