@use-lattice/litmus 0.121.3

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 (199) hide show
  1. package/LICENSE +19 -0
  2. package/dist/src/accounts-Bt1oJb1Z.cjs +219 -0
  3. package/dist/src/accounts-DjOU8Rm3.js +178 -0
  4. package/dist/src/agentic-utils-D03IiXQc.js +153 -0
  5. package/dist/src/agentic-utils-Dh7xaMQM.cjs +180 -0
  6. package/dist/src/agents-C6BIMlZa.js +231 -0
  7. package/dist/src/agents-DvIpNX1L.cjs +666 -0
  8. package/dist/src/agents-ZP0RP9vV.cjs +231 -0
  9. package/dist/src/agents-maJXdjbR.js +665 -0
  10. package/dist/src/aimlapi-BTbQjG2E.cjs +30 -0
  11. package/dist/src/aimlapi-CwMxqfXP.js +30 -0
  12. package/dist/src/audio-BBUdvsde.cjs +97 -0
  13. package/dist/src/audio-D5DPZ7I-.js +97 -0
  14. package/dist/src/base-BEysXrkq.cjs +222 -0
  15. package/dist/src/base-C451JQfq.js +193 -0
  16. package/dist/src/blobs-BY8MDmpo.js +230 -0
  17. package/dist/src/blobs-BgcNn97m.cjs +256 -0
  18. package/dist/src/cache-BBE_lsTA.cjs +4 -0
  19. package/dist/src/cache-BkrqU5Ba.js +237 -0
  20. package/dist/src/cache-DsCxFlsZ.cjs +297 -0
  21. package/dist/src/chat-CPJWDP6a.cjs +289 -0
  22. package/dist/src/chat-CXX3xzkk.cjs +811 -0
  23. package/dist/src/chat-CcDgZFJ4.js +787 -0
  24. package/dist/src/chat-Dz5ZeGO2.js +289 -0
  25. package/dist/src/chatkit-Dw0mKkML.cjs +1158 -0
  26. package/dist/src/chatkit-swAIVuea.js +1157 -0
  27. package/dist/src/chunk-DEq-mXcV.js +15 -0
  28. package/dist/src/claude-agent-sdk-BXZJtOg6.js +379 -0
  29. package/dist/src/claude-agent-sdk-CkfyjDoG.cjs +383 -0
  30. package/dist/src/cloudflare-ai-BzpJcqUH.js +161 -0
  31. package/dist/src/cloudflare-ai-Cmy_R1y2.cjs +161 -0
  32. package/dist/src/cloudflare-gateway-B9tVQKok.cjs +272 -0
  33. package/dist/src/cloudflare-gateway-DrD3ew3H.js +272 -0
  34. package/dist/src/codex-sdk-Dezj9Nwm.js +1056 -0
  35. package/dist/src/codex-sdk-Dl9D4k5B.cjs +1060 -0
  36. package/dist/src/cometapi-C-9YvCHC.js +54 -0
  37. package/dist/src/cometapi-DHgDKoO2.cjs +54 -0
  38. package/dist/src/completion-B8Ctyxpr.js +120 -0
  39. package/dist/src/completion-Cxrt08sj.cjs +131 -0
  40. package/dist/src/createHash-BwgE13yv.cjs +27 -0
  41. package/dist/src/createHash-DmPQkvBh.js +15 -0
  42. package/dist/src/docker-BiqcTwLv.js +80 -0
  43. package/dist/src/docker-C7tEJnP-.cjs +80 -0
  44. package/dist/src/esm-C62Zofr1.cjs +409 -0
  45. package/dist/src/esm-DMVc93eh.js +379 -0
  46. package/dist/src/evalResult-C3NJPQOo.cjs +301 -0
  47. package/dist/src/evalResult-C7JJAPBb.js +295 -0
  48. package/dist/src/evalResult-DoVTZZWI.cjs +2 -0
  49. package/dist/src/extractor-DnMD3fwt.cjs +391 -0
  50. package/dist/src/extractor-DtlL28vL.js +374 -0
  51. package/dist/src/fetch-BTxakTSg.cjs +1133 -0
  52. package/dist/src/fetch-DQckpUFz.js +928 -0
  53. package/dist/src/fileExtensions-DnqA1y9x.js +85 -0
  54. package/dist/src/fileExtensions-bYh77CN8.cjs +114 -0
  55. package/dist/src/genaiTracer-CyZrmaK0.cjs +268 -0
  56. package/dist/src/genaiTracer-D3fD9dNV.js +256 -0
  57. package/dist/src/graders-BNscxFrU.js +13644 -0
  58. package/dist/src/graders-D2oE9Msq.js +2 -0
  59. package/dist/src/graders-c0Ez_w-9.cjs +2 -0
  60. package/dist/src/graders-d0F2M3e9.cjs +14056 -0
  61. package/dist/src/image-0ZhE0VlR.cjs +280 -0
  62. package/dist/src/image-CWE1pdNv.js +257 -0
  63. package/dist/src/image-D9ZK6hwL.js +163 -0
  64. package/dist/src/image-DKZgZITg.cjs +163 -0
  65. package/dist/src/index.cjs +11366 -0
  66. package/dist/src/index.d.cts +19640 -0
  67. package/dist/src/index.d.ts +19641 -0
  68. package/dist/src/index.js +11306 -0
  69. package/dist/src/invariant-Ddh24eXh.js +25 -0
  70. package/dist/src/invariant-kfQ8Bu82.cjs +30 -0
  71. package/dist/src/knowledgeBase-BgPyGFUd.cjs +122 -0
  72. package/dist/src/knowledgeBase-DyHilYaP.js +122 -0
  73. package/dist/src/litellm-CyMeneHS.js +135 -0
  74. package/dist/src/litellm-DWDF73yF.cjs +135 -0
  75. package/dist/src/logger-C40ZGil9.js +717 -0
  76. package/dist/src/logger-DyfK9PBt.cjs +917 -0
  77. package/dist/src/luma-ray-BAU9X_ep.cjs +315 -0
  78. package/dist/src/luma-ray-nwVseBbv.js +313 -0
  79. package/dist/src/messages-B5ADWTTv.js +245 -0
  80. package/dist/src/messages-BCnZfqrS.cjs +257 -0
  81. package/dist/src/meteor-DLZZ3osF.cjs +134 -0
  82. package/dist/src/meteor-DUiCJRC-.js +134 -0
  83. package/dist/src/modelslab-00cveB8L.cjs +163 -0
  84. package/dist/src/modelslab-D9sCU_L7.js +163 -0
  85. package/dist/src/nova-reel-CTapvqYH.js +276 -0
  86. package/dist/src/nova-reel-DlWuuroF.cjs +278 -0
  87. package/dist/src/nova-sonic-5UPWfeMv.cjs +363 -0
  88. package/dist/src/nova-sonic-BhSwQNym.js +363 -0
  89. package/dist/src/openai-BWrJK9d8.cjs +52 -0
  90. package/dist/src/openai-DumO8WQn.js +47 -0
  91. package/dist/src/openclaw-B8brrjC_.cjs +577 -0
  92. package/dist/src/openclaw-Bkayww9q.js +571 -0
  93. package/dist/src/opencode-sdk-7xjoDNiM.cjs +562 -0
  94. package/dist/src/opencode-sdk-SGwAPxht.js +558 -0
  95. package/dist/src/otlpReceiver-CoAHfAN9.cjs +15 -0
  96. package/dist/src/otlpReceiver-oO3EQwI9.js +14 -0
  97. package/dist/src/providerRegistry-4yjhaEM8.js +45 -0
  98. package/dist/src/providerRegistry-DhV4rJIc.cjs +50 -0
  99. package/dist/src/providers-B5RJVG-7.cjs +33609 -0
  100. package/dist/src/providers-BdmZCLzV.js +33262 -0
  101. package/dist/src/providers-CxtRxn8e.js +2 -0
  102. package/dist/src/providers-DnQLNbx1.cjs +3 -0
  103. package/dist/src/pythonUtils-BD0druiM.cjs +275 -0
  104. package/dist/src/pythonUtils-IBhn5YGR.js +249 -0
  105. package/dist/src/quiverai-BDOwZBsM.cjs +213 -0
  106. package/dist/src/quiverai-D3JTF5lD.js +213 -0
  107. package/dist/src/responses-B2LCDCXZ.js +667 -0
  108. package/dist/src/responses-BvNm4Xv9.cjs +685 -0
  109. package/dist/src/rubyUtils-B0NwnfpY.cjs +245 -0
  110. package/dist/src/rubyUtils-BroxzZ7c.cjs +2 -0
  111. package/dist/src/rubyUtils-hqVw5UvJ.js +222 -0
  112. package/dist/src/sagemaker-Cno2V-Sx.js +689 -0
  113. package/dist/src/sagemaker-fV_KUgs5.cjs +691 -0
  114. package/dist/src/server-BOuAXb06.cjs +238 -0
  115. package/dist/src/server-CtI-EWzm.cjs +2 -0
  116. package/dist/src/server-Cy3DZymt.js +189 -0
  117. package/dist/src/slack-CP8xBePa.js +135 -0
  118. package/dist/src/slack-DSQ1yXVb.cjs +135 -0
  119. package/dist/src/store-BwDDaBjb.cjs +246 -0
  120. package/dist/src/store-DcbLC593.cjs +2 -0
  121. package/dist/src/store-IGpqMIkv.js +240 -0
  122. package/dist/src/tables-3Q2cL7So.cjs +373 -0
  123. package/dist/src/tables-Bi2fjr4W.js +288 -0
  124. package/dist/src/telemetry-Bg2WqF79.js +161 -0
  125. package/dist/src/telemetry-D0x6u5kX.cjs +166 -0
  126. package/dist/src/telemetry-DXNimrI0.cjs +2 -0
  127. package/dist/src/text-B_UCRPp2.js +22 -0
  128. package/dist/src/text-CW1cyrwj.cjs +33 -0
  129. package/dist/src/tokenUsageUtils-NYT-WKS6.js +138 -0
  130. package/dist/src/tokenUsageUtils-bVa1ga6f.cjs +173 -0
  131. package/dist/src/transcription-Cl_W16Pr.js +122 -0
  132. package/dist/src/transcription-yt1EecY8.cjs +124 -0
  133. package/dist/src/transform-BCtGrl_W.cjs +228 -0
  134. package/dist/src/transform-Bv6gG2MJ.cjs +1688 -0
  135. package/dist/src/transform-CY1wbpRy.js +1507 -0
  136. package/dist/src/transform-DU8rUL9P.cjs +2 -0
  137. package/dist/src/transform-yWaShiKr.js +216 -0
  138. package/dist/src/transformersAvailability-BGkzavwb.js +35 -0
  139. package/dist/src/transformersAvailability-DKoRtQLy.cjs +35 -0
  140. package/dist/src/types-5aqHpBwE.cjs +3769 -0
  141. package/dist/src/types-Bn6D9c4U.js +3300 -0
  142. package/dist/src/util-BkKlTkI2.js +293 -0
  143. package/dist/src/util-CTh0bfOm.cjs +1119 -0
  144. package/dist/src/util-D17oBwo7.cjs +328 -0
  145. package/dist/src/util-DsS_-v4p.js +613 -0
  146. package/dist/src/util-DuntT1Ga.js +951 -0
  147. package/dist/src/util-aWjdCYMI.cjs +667 -0
  148. package/dist/src/utils-CisQwpjA.js +94 -0
  149. package/dist/src/utils-yWamDvmz.cjs +123 -0
  150. package/dist/tsconfig.tsbuildinfo +1 -0
  151. package/drizzle/0000_lush_hellion.sql +36 -0
  152. package/drizzle/0001_wide_calypso.sql +3 -0
  153. package/drizzle/0002_tidy_juggernaut.sql +1 -0
  154. package/drizzle/0003_lively_naoko.sql +8 -0
  155. package/drizzle/0004_minor_peter_quill.sql +19 -0
  156. package/drizzle/0005_silky_millenium_guard.sql +2 -0
  157. package/drizzle/0006_harsh_caretaker.sql +42 -0
  158. package/drizzle/0007_cloudy_wong.sql +1 -0
  159. package/drizzle/0008_broad_boomer.sql +2 -0
  160. package/drizzle/0009_strong_marten_broadcloak.sql +19 -0
  161. package/drizzle/0010_needy_bishop.sql +11 -0
  162. package/drizzle/0011_moaning_millenium_guard.sql +1 -0
  163. package/drizzle/0012_late_marten_broadcloak.sql +2 -0
  164. package/drizzle/0013_previous_dormammu.sql +9 -0
  165. package/drizzle/0014_lazy_captain_universe.sql +2 -0
  166. package/drizzle/0015_zippy_wallop.sql +29 -0
  167. package/drizzle/0016_jazzy_zemo.sql +2 -0
  168. package/drizzle/0017_reflective_praxagora.sql +4 -0
  169. package/drizzle/0018_fat_vanisher.sql +22 -0
  170. package/drizzle/0019_new_clint_barton.sql +8 -0
  171. package/drizzle/0020_skinny_maverick.sql +1 -0
  172. package/drizzle/0021_mysterious_madelyne_pryor.sql +13 -0
  173. package/drizzle/0022_sleepy_ultimo.sql +25 -0
  174. package/drizzle/0023_wooden_mandrill.sql +2 -0
  175. package/drizzle/AGENTS.md +68 -0
  176. package/drizzle/CLAUDE.md +1 -0
  177. package/drizzle/meta/0000_snapshot.json +221 -0
  178. package/drizzle/meta/0001_snapshot.json +214 -0
  179. package/drizzle/meta/0002_snapshot.json +221 -0
  180. package/drizzle/meta/0005_snapshot.json +369 -0
  181. package/drizzle/meta/0006_snapshot.json +638 -0
  182. package/drizzle/meta/0007_snapshot.json +640 -0
  183. package/drizzle/meta/0008_snapshot.json +649 -0
  184. package/drizzle/meta/0009_snapshot.json +554 -0
  185. package/drizzle/meta/0010_snapshot.json +619 -0
  186. package/drizzle/meta/0011_snapshot.json +627 -0
  187. package/drizzle/meta/0012_snapshot.json +639 -0
  188. package/drizzle/meta/0013_snapshot.json +717 -0
  189. package/drizzle/meta/0014_snapshot.json +717 -0
  190. package/drizzle/meta/0015_snapshot.json +897 -0
  191. package/drizzle/meta/0016_snapshot.json +1031 -0
  192. package/drizzle/meta/0018_snapshot.json +1210 -0
  193. package/drizzle/meta/0019_snapshot.json +1165 -0
  194. package/drizzle/meta/0020_snapshot.json +1232 -0
  195. package/drizzle/meta/0021_snapshot.json +1311 -0
  196. package/drizzle/meta/0022_snapshot.json +1481 -0
  197. package/drizzle/meta/0023_snapshot.json +1496 -0
  198. package/drizzle/meta/_journal.json +174 -0
  199. package/package.json +240 -0
@@ -0,0 +1,180 @@
1
+ const require_logger = require("./logger-DyfK9PBt.cjs");
2
+ const require_cache = require("./cache-DsCxFlsZ.cjs");
3
+ let fs = require("fs");
4
+ fs = require_logger.__toESM(fs);
5
+ let path = require("path");
6
+ path = require_logger.__toESM(path);
7
+ let dedent = require("dedent");
8
+ dedent = require_logger.__toESM(dedent);
9
+ let crypto = require("crypto");
10
+ crypto = require_logger.__toESM(crypto);
11
+ //#region src/providers/agentic-utils.ts
12
+ /**
13
+ * Shared utilities for agentic providers (Claude Agent SDK, OpenCode SDK, etc.)
14
+ *
15
+ * These utilities handle common functionality needed by coding agent providers:
16
+ * - Working directory fingerprinting for cache key generation
17
+ * - Response caching with fingerprint support
18
+ */
19
+ /**
20
+ * Timeout for working directory fingerprint generation (ms)
21
+ * Prevents hanging on extremely large directories
22
+ */
23
+ const FINGERPRINT_TIMEOUT_MS = 2e3;
24
+ /**
25
+ * Get a fingerprint for a working directory to use as a cache key.
26
+ * Checks directory mtime and descendant file mtimes recursively.
27
+ *
28
+ * This allows for caching prompts that use the same working directory
29
+ * when the files haven't changed.
30
+ *
31
+ * @param workingDir - Absolute path to the working directory
32
+ * @returns SHA-256 hash fingerprint of the directory state
33
+ * @throws Error if fingerprinting times out or directory is inaccessible
34
+ */
35
+ async function getWorkingDirFingerprint(workingDir) {
36
+ const dirMtime = fs.default.statSync(workingDir).mtimeMs;
37
+ const startTime = Date.now();
38
+ const getAllFiles = (dir, files = []) => {
39
+ if (Date.now() - startTime > FINGERPRINT_TIMEOUT_MS) throw new Error("Working directory fingerprint timed out");
40
+ const entries = fs.default.readdirSync(dir, { withFileTypes: true });
41
+ for (const entry of entries) {
42
+ const fullPath = path.default.join(dir, entry.name);
43
+ if (entry.isDirectory()) getAllFiles(fullPath, files);
44
+ else if (entry.isFile()) files.push(fullPath);
45
+ }
46
+ return files;
47
+ };
48
+ const fingerprintData = `dir:${dirMtime};files:${getAllFiles(workingDir).map((file) => {
49
+ const stat = fs.default.statSync(file);
50
+ return `${path.default.relative(workingDir, file)}:${stat.mtimeMs}`;
51
+ }).sort().join(",")}`;
52
+ return crypto.default.createHash("sha256").update(fingerprintData).digest("hex");
53
+ }
54
+ /**
55
+ * Generate a cache key from arbitrary data using SHA-256 hash
56
+ *
57
+ * @param prefix - Cache key prefix (provider identifier)
58
+ * @param data - Data to hash for the cache key
59
+ * @returns Prefixed SHA-256 hash cache key
60
+ */
61
+ function generateCacheKey(prefix, data) {
62
+ const stringified = JSON.stringify(data);
63
+ return `${prefix}:${crypto.default.createHash("sha256").update(stringified).digest("hex")}`;
64
+ }
65
+ /**
66
+ * Initialize cache and check for cached response
67
+ *
68
+ * This handles the common caching pattern used by agentic providers:
69
+ * 1. Check if caching is enabled
70
+ * 2. Generate working directory fingerprint if needed
71
+ * 3. Generate cache key
72
+ * 4. Return cache configuration for use by the provider
73
+ *
74
+ * @param options - Cache options including prefix and working directory
75
+ * @param cacheKeyData - Data to include in the cache key
76
+ * @returns Cache configuration and optional cached response
77
+ */
78
+ async function initializeAgenticCache(options, cacheKeyData) {
79
+ if (!require_cache.isCacheEnabled()) return {
80
+ shouldCache: false,
81
+ shouldReadCache: false,
82
+ shouldWriteCache: false
83
+ };
84
+ if (options.mcp && !options.cacheMcp) return {
85
+ shouldCache: false,
86
+ shouldReadCache: false,
87
+ shouldWriteCache: false
88
+ };
89
+ let workingDirFingerprint = null;
90
+ if (options.workingDir) try {
91
+ workingDirFingerprint = await getWorkingDirFingerprint(options.workingDir);
92
+ } catch (error) {
93
+ require_logger.logger.error(dedent.default`Error getting working directory fingerprint for cache key - ${options.workingDir}: ${String(error)}
94
+
95
+ Caching is disabled.`);
96
+ return {
97
+ shouldCache: false,
98
+ shouldReadCache: false,
99
+ shouldWriteCache: false
100
+ };
101
+ }
102
+ const cache = await require_cache.getCache();
103
+ const cacheKey = generateCacheKey(options.cacheKeyPrefix, {
104
+ ...cacheKeyData,
105
+ workingDirFingerprint,
106
+ ...options.mcp ? { mcp: options.mcp } : {}
107
+ });
108
+ return {
109
+ shouldCache: true,
110
+ shouldReadCache: !options.bustCache,
111
+ shouldWriteCache: true,
112
+ cache,
113
+ cacheKey,
114
+ workingDirFingerprint
115
+ };
116
+ }
117
+ /**
118
+ * Try to get a cached response
119
+ *
120
+ * @param cacheResult - Result from initializeAgenticCache
121
+ * @param debugContext - Context for debug logging (e.g., prompt preview)
122
+ * @returns Cached ProviderResponse if found, undefined otherwise
123
+ */
124
+ async function getCachedResponse(cacheResult, debugContext) {
125
+ if (!cacheResult.shouldReadCache || !cacheResult.cache || !cacheResult.cacheKey) return;
126
+ try {
127
+ const cachedResponse = await cacheResult.cache.get(cacheResult.cacheKey);
128
+ if (cachedResponse) {
129
+ require_logger.logger.debug(`Returning cached response${debugContext ? ` for ${debugContext}` : ""} (cache key: ${cacheResult.cacheKey})`);
130
+ return {
131
+ ...JSON.parse(cachedResponse),
132
+ cached: true
133
+ };
134
+ }
135
+ } catch (error) {
136
+ require_logger.logger.error(`Error getting cached response: ${String(error)}`);
137
+ }
138
+ }
139
+ /**
140
+ * Cache a provider response
141
+ *
142
+ * @param cacheResult - Result from initializeAgenticCache
143
+ * @param response - The ProviderResponse to cache
144
+ * @param debugContext - Context for debug logging
145
+ */
146
+ async function cacheResponse(cacheResult, response, debugContext) {
147
+ if (!cacheResult.shouldWriteCache || !cacheResult.cache || !cacheResult.cacheKey) return;
148
+ try {
149
+ await cacheResult.cache.set(cacheResult.cacheKey, JSON.stringify(response));
150
+ } catch (error) {
151
+ require_logger.logger.error(`Error caching response${debugContext ? ` for ${debugContext}` : ""}: ${String(error)}`);
152
+ }
153
+ }
154
+ //#endregion
155
+ Object.defineProperty(exports, "cacheResponse", {
156
+ enumerable: true,
157
+ get: function() {
158
+ return cacheResponse;
159
+ }
160
+ });
161
+ Object.defineProperty(exports, "generateCacheKey", {
162
+ enumerable: true,
163
+ get: function() {
164
+ return generateCacheKey;
165
+ }
166
+ });
167
+ Object.defineProperty(exports, "getCachedResponse", {
168
+ enumerable: true,
169
+ get: function() {
170
+ return getCachedResponse;
171
+ }
172
+ });
173
+ Object.defineProperty(exports, "initializeAgenticCache", {
174
+ enumerable: true,
175
+ get: function() {
176
+ return initializeAgenticCache;
177
+ }
178
+ });
179
+
180
+ //# sourceMappingURL=agentic-utils-Dh7xaMQM.cjs.map
@@ -0,0 +1,231 @@
1
+ import { b as getEnvInt, r as logger } from "./logger-C40ZGil9.js";
2
+ import { a as isCacheEnabled, i as getCache } from "./cache-BkrqU5Ba.js";
3
+ import { t as telemetry } from "./telemetry-Bg2WqF79.js";
4
+ import { n as createBedrockRequestHandler, r as hasProxyEnv, t as AwsBedrockGenericProvider } from "./base-C451JQfq.js";
5
+ //#region src/providers/bedrock/agents.ts
6
+ /**
7
+ * AWS Bedrock Agents provider for invoking deployed AI agents.
8
+ * Supports all Bedrock Agents features including memory, knowledge bases, action groups,
9
+ * guardrails, and session management.
10
+ *
11
+ * @example Basic usage
12
+ * ```yaml
13
+ * providers:
14
+ * - bedrock-agent:AGENT_ID
15
+ * config:
16
+ * agentAliasId: PROD_ALIAS
17
+ * region: us-east-1
18
+ * ```
19
+ *
20
+ * @example With memory and session
21
+ * ```yaml
22
+ * providers:
23
+ * - bedrock-agent:AGENT_ID
24
+ * config:
25
+ * agentAliasId: PROD_ALIAS
26
+ * sessionId: user-session-123
27
+ * memoryId: LONG_TERM_MEMORY
28
+ * enableTrace: true
29
+ * ```
30
+ *
31
+ * @example With guardrails and inference config
32
+ * ```yaml
33
+ * providers:
34
+ * - bedrock-agent:AGENT_ID
35
+ * config:
36
+ * agentAliasId: PROD_ALIAS
37
+ * guardrailConfiguration:
38
+ * guardrailId: GUARDRAIL_ID
39
+ * guardrailVersion: "1"
40
+ * temperature: 0.7 # Can be specified at root level for convenience
41
+ * topP: 0.9
42
+ * maximumLength: 2048
43
+ * ```
44
+ */
45
+ var AwsBedrockAgentsProvider = class extends AwsBedrockGenericProvider {
46
+ agentRuntimeClient;
47
+ config;
48
+ constructor(agentId, options = {}) {
49
+ super(agentId, options);
50
+ if (!agentId && !options.config?.agentId) throw new Error("Agent ID is required. Provide it in the provider path (bedrock-agent:AGENT_ID) or config.");
51
+ this.config = {
52
+ ...options.config,
53
+ agentId: options.config?.agentId || agentId
54
+ };
55
+ telemetry.record("feature_used", {
56
+ feature: "bedrock-agents",
57
+ provider: "bedrock"
58
+ });
59
+ }
60
+ id() {
61
+ return `bedrock-agent:${this.config.agentId}`;
62
+ }
63
+ toString() {
64
+ return `[AWS Bedrock Agents Provider ${this.config.agentId}]`;
65
+ }
66
+ /**
67
+ * Get or create the Bedrock Agent Runtime client
68
+ */
69
+ async getAgentRuntimeClient() {
70
+ if (!this.agentRuntimeClient) {
71
+ const handler = hasProxyEnv() ? await createBedrockRequestHandler() : void 0;
72
+ try {
73
+ const { BedrockAgentRuntimeClient } = await import("@aws-sdk/client-bedrock-agent-runtime");
74
+ const credentials = await this.getCredentials();
75
+ this.agentRuntimeClient = new BedrockAgentRuntimeClient({
76
+ region: this.getRegion(),
77
+ maxAttempts: getEnvInt("AWS_BEDROCK_MAX_RETRIES", 10),
78
+ retryMode: "adaptive",
79
+ ...handler ? { requestHandler: handler } : {},
80
+ ...credentials ? { credentials } : {}
81
+ });
82
+ } catch (err) {
83
+ logger.error(`Error creating BedrockAgentRuntimeClient: ${err}`);
84
+ throw new Error("The @aws-sdk/client-bedrock-agent-runtime package is required. Please install it: npm install @aws-sdk/client-bedrock-agent-runtime");
85
+ }
86
+ }
87
+ return this.agentRuntimeClient;
88
+ }
89
+ /**
90
+ * Build the session state from configuration
91
+ */
92
+ buildSessionState() {
93
+ if (!this.config.sessionState) return;
94
+ const sessionState = {
95
+ sessionAttributes: this.config.sessionState.sessionAttributes,
96
+ promptSessionAttributes: this.config.sessionState.promptSessionAttributes,
97
+ invocationId: this.config.sessionState.invocationId
98
+ };
99
+ if (this.config.sessionState.returnControlInvocationResults) sessionState.returnControlInvocationResults = this.config.sessionState.returnControlInvocationResults;
100
+ return sessionState;
101
+ }
102
+ /**
103
+ * Build inference configuration from both root-level and nested parameters
104
+ * Root-level parameters take precedence over nested ones for convenience
105
+ */
106
+ buildInferenceConfig() {
107
+ const hasRootConfig = this.config.temperature !== void 0 || this.config.topP !== void 0 || this.config.topK !== void 0 || this.config.maximumLength !== void 0 || this.config.stopSequences !== void 0;
108
+ const hasNestedConfig = this.config.inferenceConfig !== void 0;
109
+ if (!hasRootConfig && !hasNestedConfig) return;
110
+ const inferenceConfig = {};
111
+ if (this.config.inferenceConfig) {
112
+ if (this.config.inferenceConfig.maximumLength !== void 0) inferenceConfig.maximumLength = this.config.inferenceConfig.maximumLength;
113
+ if (this.config.inferenceConfig.stopSequences !== void 0) inferenceConfig.stopSequences = this.config.inferenceConfig.stopSequences;
114
+ if (this.config.inferenceConfig.temperature !== void 0) inferenceConfig.temperature = this.config.inferenceConfig.temperature;
115
+ if (this.config.inferenceConfig.topP !== void 0) inferenceConfig.topP = this.config.inferenceConfig.topP;
116
+ if (this.config.inferenceConfig.topK !== void 0) inferenceConfig.topK = this.config.inferenceConfig.topK;
117
+ }
118
+ if (this.config.temperature !== void 0) inferenceConfig.temperature = this.config.temperature;
119
+ if (this.config.topP !== void 0) inferenceConfig.topP = this.config.topP;
120
+ if (this.config.topK !== void 0) inferenceConfig.topK = this.config.topK;
121
+ if (this.config.maximumLength !== void 0) inferenceConfig.maximumLength = this.config.maximumLength;
122
+ if (this.config.stopSequences !== void 0) inferenceConfig.stopSequences = this.config.stopSequences;
123
+ return inferenceConfig;
124
+ }
125
+ /**
126
+ * Process the streaming response from the agent
127
+ */
128
+ async processResponse(response) {
129
+ let output = "";
130
+ const traces = [];
131
+ if (response.completion) {
132
+ const decoder = new TextDecoder();
133
+ try {
134
+ for await (const event of response.completion) {
135
+ if (event.chunk?.bytes) output += decoder.decode(event.chunk.bytes, { stream: true });
136
+ if (this.config.enableTrace && event.trace) traces.push(event.trace);
137
+ }
138
+ output += decoder.decode();
139
+ } catch (error) {
140
+ logger.error(`Error processing agent response stream: ${error}`);
141
+ throw error;
142
+ }
143
+ }
144
+ return {
145
+ output,
146
+ trace: traces.length > 0 ? traces : void 0,
147
+ sessionId: response.sessionId
148
+ };
149
+ }
150
+ /**
151
+ * Invoke the agent with the given prompt
152
+ */
153
+ async callApi(prompt) {
154
+ if (!this.config.agentAliasId) return { error: "Agent Alias ID is required. Set agentAliasId in the provider config." };
155
+ const client = await this.getAgentRuntimeClient();
156
+ const sessionId = this.config.sessionId || (typeof crypto !== "undefined" && "randomUUID" in crypto ? `session-${crypto.randomUUID()}` : `session-${Date.now()}-${process.hrtime.bigint().toString(36)}`);
157
+ const input = {
158
+ agentId: this.config.agentId,
159
+ agentAliasId: this.config.agentAliasId,
160
+ sessionId,
161
+ inputText: prompt,
162
+ enableTrace: this.config.enableTrace,
163
+ endSession: this.config.endSession,
164
+ sessionState: this.buildSessionState(),
165
+ memoryId: this.config.memoryId,
166
+ ...this.buildInferenceConfig() && { inferenceConfig: this.buildInferenceConfig() },
167
+ ...this.config.guardrailConfiguration && { guardrailConfiguration: this.config.guardrailConfiguration },
168
+ ...this.config.promptOverrideConfiguration && { promptOverrideConfiguration: this.config.promptOverrideConfiguration },
169
+ ...this.config.knowledgeBaseConfigurations && { knowledgeBaseConfigurations: this.config.knowledgeBaseConfigurations },
170
+ ...this.config.actionGroups && { actionGroups: this.config.actionGroups },
171
+ ...this.config.inputDataConfig && { inputDataConfig: this.config.inputDataConfig }
172
+ };
173
+ logger.debug(`Invoking Bedrock agent ${this.config.agentId} with session ${sessionId}`);
174
+ const cache = await getCache();
175
+ const cacheKey = `bedrock-agent:${this.config.agentId}:${JSON.stringify({
176
+ prompt,
177
+ inferenceConfig: this.buildInferenceConfig(),
178
+ knowledgeBaseConfigurations: this.config.knowledgeBaseConfigurations
179
+ })}`;
180
+ if (isCacheEnabled()) {
181
+ const cached = await cache.get(cacheKey);
182
+ if (cached) {
183
+ logger.debug("Returning cached Bedrock Agents response");
184
+ try {
185
+ const parsed = JSON.parse(cached);
186
+ if (parsed && typeof parsed === "object") return {
187
+ ...parsed,
188
+ cached: true
189
+ };
190
+ } catch {
191
+ logger.warn("Failed to parse cached Bedrock Agents response, ignoring cache");
192
+ }
193
+ }
194
+ }
195
+ try {
196
+ const { InvokeAgentCommand } = await import("@aws-sdk/client-bedrock-agent-runtime");
197
+ const response = await client.send(new InvokeAgentCommand(input));
198
+ const { output, trace, sessionId: responseSessionId } = await this.processResponse(response);
199
+ const result = {
200
+ output,
201
+ metadata: {
202
+ ...responseSessionId && { sessionId: responseSessionId },
203
+ ...trace && { trace },
204
+ ...this.config.memoryId && { memoryId: this.config.memoryId },
205
+ ...this.config.guardrailConfiguration && { guardrails: {
206
+ applied: true,
207
+ guardrailId: this.config.guardrailConfiguration.guardrailId,
208
+ guardrailVersion: this.config.guardrailConfiguration.guardrailVersion
209
+ } }
210
+ }
211
+ };
212
+ if (isCacheEnabled()) try {
213
+ await cache.set(cacheKey, JSON.stringify(result));
214
+ } catch (err) {
215
+ logger.error(`Failed to cache response: ${err}`);
216
+ }
217
+ return result;
218
+ } catch (error) {
219
+ logger.error(`Bedrock Agents invocation failed: ${error}`);
220
+ if (error.name === "ResourceNotFoundException") return { error: `Agent or alias not found. Verify agentId: ${this.config.agentId} and agentAliasId: ${this.config.agentAliasId}` };
221
+ else if (error.name === "AccessDeniedException") return { error: "Access denied. Check IAM permissions for bedrock:InvokeAgent" };
222
+ else if (error.name === "ValidationException") return { error: `Invalid configuration: ${error.message}` };
223
+ else if (error.name === "ThrottlingException") return { error: "Rate limit exceeded. Please retry later." };
224
+ return { error: `Failed to invoke agent: ${error.message || String(error)}` };
225
+ }
226
+ }
227
+ };
228
+ //#endregion
229
+ export { AwsBedrockAgentsProvider };
230
+
231
+ //# sourceMappingURL=agents-C6BIMlZa.js.map