@vybestack/llxprt-code-core 0.11.0 → 0.12.0-nightly.260910.2aac6841e

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 (417) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/prompt-config/defaults/default-prompts.json +3 -3
  5. package/dist/src/config/agentClientLifecycle.d.ts +4 -3
  6. package/dist/src/config/agentClientLifecycle.js +27 -14
  7. package/dist/src/config/agentClientLifecycle.js.map +1 -1
  8. package/dist/src/config/config.d.ts +2 -5
  9. package/dist/src/config/config.js +10 -23
  10. package/dist/src/config/config.js.map +1 -1
  11. package/dist/src/config/configBase.d.ts +5 -1
  12. package/dist/src/config/configBase.js +27 -6
  13. package/dist/src/config/configBase.js.map +1 -1
  14. package/dist/src/config/configBaseCore.d.ts +26 -8
  15. package/dist/src/config/configBaseCore.js +30 -26
  16. package/dist/src/config/configBaseCore.js.map +1 -1
  17. package/dist/src/config/configMcpRuntime.d.ts +16 -0
  18. package/dist/src/config/configMcpRuntime.js +31 -0
  19. package/dist/src/config/configMcpRuntime.js.map +1 -0
  20. package/dist/src/config/configMediaDefaults.d.ts +10 -0
  21. package/dist/src/config/configMediaDefaults.js +17 -0
  22. package/dist/src/config/configMediaDefaults.js.map +1 -0
  23. package/dist/src/config/configTestHarness.d.ts +4 -0
  24. package/dist/src/config/configTypes.d.ts +4 -54
  25. package/dist/src/config/configTypes.js +6 -82
  26. package/dist/src/config/configTypes.js.map +1 -1
  27. package/dist/src/config/index.d.ts +1 -2
  28. package/dist/src/config/index.js +1 -2
  29. package/dist/src/config/index.js.map +1 -1
  30. package/dist/src/config/models.d.ts +0 -4
  31. package/dist/src/config/models.js +0 -4
  32. package/dist/src/config/models.js.map +1 -1
  33. package/dist/src/config/toolRegistryFactory.d.ts +2 -2
  34. package/dist/src/core/clientContract.d.ts +4 -6
  35. package/dist/src/core/compression/transcriptPathNotice.d.ts +22 -0
  36. package/dist/src/core/compression/transcriptPathNotice.js +29 -0
  37. package/dist/src/core/compression/transcriptPathNotice.js.map +1 -0
  38. package/dist/src/core/contentGenerator.d.ts +2 -5
  39. package/dist/src/core/contentGenerator.js +10 -24
  40. package/dist/src/core/contentGenerator.js.map +1 -1
  41. package/dist/src/core/logger.d.ts +66 -0
  42. package/dist/src/core/logger.js +345 -30
  43. package/dist/src/core/logger.js.map +1 -1
  44. package/dist/src/core/prompts.d.ts +0 -1
  45. package/dist/src/core/prompts.js +5 -79
  46. package/dist/src/core/prompts.js.map +1 -1
  47. package/dist/src/core/turn.d.ts +3 -3
  48. package/dist/src/hooks/hookTranslator.js +5 -4
  49. package/dist/src/hooks/hookTranslator.js.map +1 -1
  50. package/dist/src/index.d.ts +8 -6
  51. package/dist/src/index.js +8 -6
  52. package/dist/src/index.js.map +1 -1
  53. package/dist/src/llm-types/index.d.ts +1 -1
  54. package/dist/src/llm-types/modelEnvelope.d.ts +2 -1
  55. package/dist/src/llm-types/modelEnvelope.js +17 -1
  56. package/dist/src/llm-types/modelEnvelope.js.map +1 -1
  57. package/dist/src/models/schema.d.ts +40 -40
  58. package/dist/src/policy/policies/read-only.toml +0 -5
  59. package/dist/src/prompt-config/TemplateEngine.js +0 -3
  60. package/dist/src/prompt-config/TemplateEngine.js.map +1 -1
  61. package/dist/src/prompt-config/defaults/providers/gemini/core.md +0 -2
  62. package/dist/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/core.md +0 -2
  63. package/dist/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/gemini-2-5-flash/core.md +0 -2
  64. package/dist/src/prompt-config/prompt-loader.d.ts +1 -1
  65. package/dist/src/prompt-config/prompt-loader.js +4 -4
  66. package/dist/src/prompt-config/prompt-loader.js.map +1 -1
  67. package/dist/src/prompt-config/types.d.ts +0 -1
  68. package/dist/src/recording/CheckpointService.d.ts +4 -0
  69. package/dist/src/recording/CheckpointService.js +67 -46
  70. package/dist/src/recording/CheckpointService.js.map +1 -1
  71. package/dist/src/recording/HistoryMutationService.d.ts +1 -1
  72. package/dist/src/recording/HistoryMutationService.js +27 -4
  73. package/dist/src/recording/HistoryMutationService.js.map +1 -1
  74. package/dist/src/recording/RecordingIntegration.d.ts +36 -2
  75. package/dist/src/recording/RecordingIntegration.js +224 -7
  76. package/dist/src/recording/RecordingIntegration.js.map +1 -1
  77. package/dist/src/recording/ReplayEngine.d.ts +8 -10
  78. package/dist/src/recording/ReplayEngine.js +161 -95
  79. package/dist/src/recording/ReplayEngine.js.map +1 -1
  80. package/dist/src/recording/SessionDiscovery.d.ts +4 -2
  81. package/dist/src/recording/SessionDiscovery.js +13 -5
  82. package/dist/src/recording/SessionDiscovery.js.map +1 -1
  83. package/dist/src/recording/SessionRecordingService.d.ts +23 -3
  84. package/dist/src/recording/SessionRecordingService.js +209 -51
  85. package/dist/src/recording/SessionRecordingService.js.map +1 -1
  86. package/dist/src/recording/SessionTransitionService.d.ts +7 -0
  87. package/dist/src/recording/SessionTransitionService.js +66 -13
  88. package/dist/src/recording/SessionTransitionService.js.map +1 -1
  89. package/dist/src/recording/index.d.ts +1 -0
  90. package/dist/src/recording/index.js +1 -0
  91. package/dist/src/recording/index.js.map +1 -1
  92. package/dist/src/recording/janitor/cleanupTypes.d.ts +3 -0
  93. package/dist/src/recording/janitor/cleanupTypes.js.map +1 -1
  94. package/dist/src/recording/janitor/mediaReclamation.d.ts +23 -0
  95. package/dist/src/recording/janitor/mediaReclamation.js +195 -0
  96. package/dist/src/recording/janitor/mediaReclamation.js.map +1 -0
  97. package/dist/src/recording/janitor/sessionJanitor.js +47 -1
  98. package/dist/src/recording/janitor/sessionJanitor.js.map +1 -1
  99. package/dist/src/recording/janitor/sessionScanner.d.ts +12 -9
  100. package/dist/src/recording/janitor/sessionScanner.js +248 -193
  101. package/dist/src/recording/janitor/sessionScanner.js.map +1 -1
  102. package/dist/src/recording/replay-test-helpers.d.ts +10 -1
  103. package/dist/src/recording/replay-test-helpers.js +24 -2
  104. package/dist/src/recording/replay-test-helpers.js.map +1 -1
  105. package/dist/src/recording/replayCheckpointMetadata.d.ts +28 -0
  106. package/dist/src/recording/replayCheckpointMetadata.js +96 -0
  107. package/dist/src/recording/replayCheckpointMetadata.js.map +1 -0
  108. package/dist/src/recording/replayErrorFormatting.d.ts +6 -0
  109. package/dist/src/recording/replayErrorFormatting.js +38 -0
  110. package/dist/src/recording/replayErrorFormatting.js.map +1 -0
  111. package/dist/src/recording/resumeSession.d.ts +3 -0
  112. package/dist/src/recording/resumeSession.js +7 -1
  113. package/dist/src/recording/resumeSession.js.map +1 -1
  114. package/dist/src/recording/semanticMediaPurgeReplayValidation.d.ts +14 -0
  115. package/dist/src/recording/semanticMediaPurgeReplayValidation.js +24 -0
  116. package/dist/src/recording/semanticMediaPurgeReplayValidation.js.map +1 -0
  117. package/dist/src/recording/session-media-package-blobs.d.ts +8 -0
  118. package/dist/src/recording/session-media-package-blobs.js +72 -0
  119. package/dist/src/recording/session-media-package-blobs.js.map +1 -0
  120. package/dist/src/recording/session-media-package-import.d.ts +26 -0
  121. package/dist/src/recording/session-media-package-import.js +124 -0
  122. package/dist/src/recording/session-media-package-import.js.map +1 -0
  123. package/dist/src/recording/session-media-package-state.d.ts +19 -0
  124. package/dist/src/recording/session-media-package-state.js +56 -0
  125. package/dist/src/recording/session-media-package-state.js.map +1 -0
  126. package/dist/src/recording/session-media-package-validation.d.ts +59 -0
  127. package/dist/src/recording/session-media-package-validation.js +286 -0
  128. package/dist/src/recording/session-media-package-validation.js.map +1 -0
  129. package/dist/src/recording/session-media-package-writer.d.ts +18 -0
  130. package/dist/src/recording/session-media-package-writer.js +70 -0
  131. package/dist/src/recording/session-media-package-writer.js.map +1 -0
  132. package/dist/src/recording/session-media-package.d.ts +27 -0
  133. package/dist/src/recording/session-media-package.js +366 -0
  134. package/dist/src/recording/session-media-package.js.map +1 -0
  135. package/dist/src/recording/types.d.ts +34 -2
  136. package/dist/src/recording/types.js.map +1 -1
  137. package/dist/src/runtime/AgentRuntimeContext.d.ts +22 -5
  138. package/dist/src/runtime/AgentRuntimeLoader.d.ts +6 -0
  139. package/dist/src/runtime/AgentRuntimeLoader.js +25 -6
  140. package/dist/src/runtime/AgentRuntimeLoader.js.map +1 -1
  141. package/dist/src/runtime/contracts/PromptEstimation.d.ts +1 -0
  142. package/dist/src/runtime/contracts/PromptEstimation.js.map +1 -1
  143. package/dist/src/runtime/contracts/RuntimeProvider.d.ts +3 -2
  144. package/dist/src/runtime/contracts/RuntimeProviderManager.d.ts +0 -2
  145. package/dist/src/runtime/createAgentRuntimeContext.js +28 -1
  146. package/dist/src/runtime/createAgentRuntimeContext.js.map +1 -1
  147. package/dist/src/runtime/providerRuntimeContext.d.ts +12 -0
  148. package/dist/src/runtime/providerRuntimeContext.js +3 -0
  149. package/dist/src/runtime/providerRuntimeContext.js.map +1 -1
  150. package/dist/src/runtime/runtimeAdapters.js +2 -2
  151. package/dist/src/runtime/runtimeAdapters.js.map +1 -1
  152. package/dist/src/services/history/ContentConverters.d.ts +11 -7
  153. package/dist/src/services/history/ContentConverters.js +11 -7
  154. package/dist/src/services/history/ContentConverters.js.map +1 -1
  155. package/dist/src/services/history/HistoryService.d.ts +18 -180
  156. package/dist/src/services/history/HistoryService.js +53 -523
  157. package/dist/src/services/history/HistoryService.js.map +1 -1
  158. package/dist/src/services/history/HistoryServiceCore.d.ts +278 -0
  159. package/dist/src/services/history/HistoryServiceCore.js +727 -0
  160. package/dist/src/services/history/HistoryServiceCore.js.map +1 -0
  161. package/dist/src/services/history/IContent.d.ts +118 -16
  162. package/dist/src/services/history/IContent.js +284 -4
  163. package/dist/src/services/history/IContent.js.map +1 -1
  164. package/dist/src/services/history/contentSize.js +22 -2
  165. package/dist/src/services/history/contentSize.js.map +1 -1
  166. package/dist/src/services/history/historyChronology.d.ts +7 -0
  167. package/dist/src/services/history/historyChronology.js +35 -3
  168. package/dist/src/services/history/historyChronology.js.map +1 -1
  169. package/dist/src/services/history/historyCloneUtils.d.ts +5 -4
  170. package/dist/src/services/history/historyCloneUtils.js +23 -16
  171. package/dist/src/services/history/historyCloneUtils.js.map +1 -1
  172. package/dist/src/services/history/historyCompressionQueue.d.ts +33 -0
  173. package/dist/src/services/history/historyCompressionQueue.js +81 -0
  174. package/dist/src/services/history/historyCompressionQueue.js.map +1 -0
  175. package/dist/src/services/history/historyEventTypes.d.ts +3 -0
  176. package/dist/src/services/history/historyMutationFailure.d.ts +15 -0
  177. package/dist/src/services/history/historyMutationFailure.js +22 -0
  178. package/dist/src/services/history/historyMutationFailure.js.map +1 -1
  179. package/dist/src/services/history/historyProviderPipeline.d.ts +1 -1
  180. package/dist/src/services/history/historyProviderPipeline.js +15 -5
  181. package/dist/src/services/history/historyProviderPipeline.js.map +1 -1
  182. package/dist/src/services/history/historyTokenEstimation.js +10 -6
  183. package/dist/src/services/history/historyTokenEstimation.js.map +1 -1
  184. package/dist/src/services/history/historyToolNormalization.d.ts +2 -0
  185. package/dist/src/services/history/historyToolNormalization.js +26 -9
  186. package/dist/src/services/history/historyToolNormalization.js.map +1 -1
  187. package/dist/src/services/history/provider-file-binding.d.ts +11 -0
  188. package/dist/src/services/history/provider-file-binding.js +70 -0
  189. package/dist/src/services/history/provider-file-binding.js.map +1 -0
  190. package/dist/src/services/history/semantic-media-purge.d.ts +66 -0
  191. package/dist/src/services/history/semantic-media-purge.js +404 -0
  192. package/dist/src/services/history/semantic-media-purge.js.map +1 -0
  193. package/dist/src/storage/SessionPersistenceService.d.ts +53 -2
  194. package/dist/src/storage/SessionPersistenceService.js +435 -23
  195. package/dist/src/storage/SessionPersistenceService.js.map +1 -1
  196. package/dist/src/storage/history-media-ownership.d.ts +38 -0
  197. package/dist/src/storage/history-media-ownership.js +136 -0
  198. package/dist/src/storage/history-media-ownership.js.map +1 -0
  199. package/dist/src/storage/local-media-store-child.d.ts +6 -0
  200. package/dist/src/storage/local-media-store-child.js +140 -0
  201. package/dist/src/storage/local-media-store-child.js.map +1 -0
  202. package/dist/src/storage/local-media-store-files.d.ts +44 -0
  203. package/dist/src/storage/local-media-store-files.js +460 -0
  204. package/dist/src/storage/local-media-store-files.js.map +1 -0
  205. package/dist/src/storage/local-media-store-lock-recovery.d.ts +15 -0
  206. package/dist/src/storage/local-media-store-lock-recovery.js +112 -0
  207. package/dist/src/storage/local-media-store-lock-recovery.js.map +1 -0
  208. package/dist/src/storage/local-media-store-persistence.d.ts +48 -0
  209. package/dist/src/storage/local-media-store-persistence.js +443 -0
  210. package/dist/src/storage/local-media-store-persistence.js.map +1 -0
  211. package/dist/src/storage/local-media-store-quota.d.ts +6 -0
  212. package/dist/src/storage/local-media-store-quota.js +66 -0
  213. package/dist/src/storage/local-media-store-quota.js.map +1 -0
  214. package/dist/src/storage/local-media-store-reservations.d.ts +55 -0
  215. package/dist/src/storage/local-media-store-reservations.js +377 -0
  216. package/dist/src/storage/local-media-store-reservations.js.map +1 -0
  217. package/dist/src/storage/local-media-store-types.d.ts +110 -0
  218. package/dist/src/storage/local-media-store-types.js +35 -0
  219. package/dist/src/storage/local-media-store-types.js.map +1 -0
  220. package/dist/src/storage/local-media-store-validation.d.ts +34 -0
  221. package/dist/src/storage/local-media-store-validation.js +449 -0
  222. package/dist/src/storage/local-media-store-validation.js.map +1 -0
  223. package/dist/src/storage/local-media-store.d.ts +47 -0
  224. package/dist/src/storage/local-media-store.js +353 -0
  225. package/dist/src/storage/local-media-store.js.map +1 -0
  226. package/dist/src/storage/media-admission-service.d.ts +49 -0
  227. package/dist/src/storage/media-admission-service.js +333 -0
  228. package/dist/src/storage/media-admission-service.js.map +1 -0
  229. package/dist/src/storage/media-lifecycle-metrics.d.ts +75 -0
  230. package/dist/src/storage/media-lifecycle-metrics.js +105 -0
  231. package/dist/src/storage/media-lifecycle-metrics.js.map +1 -0
  232. package/dist/src/storage/media-reference-lifecycle.d.ts +16 -0
  233. package/dist/src/storage/media-reference-lifecycle.js +84 -0
  234. package/dist/src/storage/media-reference-lifecycle.js.map +1 -0
  235. package/dist/src/storage/request-media-resolver.d.ts +67 -0
  236. package/dist/src/storage/request-media-resolver.js +325 -0
  237. package/dist/src/storage/request-media-resolver.js.map +1 -0
  238. package/dist/src/storage/session-media-service-factories.d.ts +19 -0
  239. package/dist/src/storage/session-media-service-factories.js +34 -0
  240. package/dist/src/storage/session-media-service-factories.js.map +1 -0
  241. package/dist/src/storage/session-persistence-helpers.d.ts +10 -0
  242. package/dist/src/storage/session-persistence-helpers.js +46 -0
  243. package/dist/src/storage/session-persistence-helpers.js.map +1 -0
  244. package/dist/src/test-utils/config.d.ts +2 -0
  245. package/dist/src/test-utils/config.js +5 -5
  246. package/dist/src/test-utils/config.js.map +1 -1
  247. package/dist/src/test-utils/runtime.d.ts +2 -0
  248. package/dist/src/test-utils/runtime.js +1 -2
  249. package/dist/src/test-utils/runtime.js.map +1 -1
  250. package/dist/src/tools-adapters/CoreShellToolHostAdapter.js +1 -9
  251. package/dist/src/tools-adapters/CoreShellToolHostAdapter.js.map +1 -1
  252. package/dist/src/tools-adapters/CoreSkillServiceAdapter.d.ts +0 -2
  253. package/dist/src/tools-adapters/CoreSkillServiceAdapter.js +0 -17
  254. package/dist/src/tools-adapters/CoreSkillServiceAdapter.js.map +1 -1
  255. package/dist/src/tools-adapters/CoreToolHostAdapter.d.ts +0 -21
  256. package/dist/src/tools-adapters/CoreToolHostAdapter.js +0 -8
  257. package/dist/src/tools-adapters/CoreToolHostAdapter.js.map +1 -1
  258. package/dist/src/utils/environmentContext.d.ts +8 -9
  259. package/dist/src/utils/environmentContext.js +11 -22
  260. package/dist/src/utils/environmentContext.js.map +1 -1
  261. package/dist/src/utils/errorParsing.d.ts +1 -2
  262. package/dist/src/utils/errorParsing.js +22 -41
  263. package/dist/src/utils/errorParsing.js.map +1 -1
  264. package/dist/src/utils/generateContentResponseUtilities.js +12 -0
  265. package/dist/src/utils/generateContentResponseUtilities.js.map +1 -1
  266. package/dist/src/utils/summarizer.d.ts +1 -2
  267. package/dist/src/utils/summarizer.js +6 -5
  268. package/dist/src/utils/summarizer.js.map +1 -1
  269. package/dist/src/utils/tool-utils.js +7 -1
  270. package/dist/src/utils/tool-utils.js.map +1 -1
  271. package/index.ts +0 -4
  272. package/package.json +38 -30
  273. package/src/config/agentClientLifecycle.ts +53 -22
  274. package/src/config/config.ts +11 -26
  275. package/src/config/configBase.ts +46 -7
  276. package/src/config/configBaseCore.ts +38 -36
  277. package/src/config/configMcpRuntime.ts +46 -0
  278. package/src/config/configMediaDefaults.ts +19 -0
  279. package/src/config/configTypes.ts +13 -53
  280. package/src/config/index.ts +1 -4
  281. package/src/config/models.ts +0 -6
  282. package/src/config/toolRegistryFactory.ts +2 -2
  283. package/src/core/clientContract.ts +4 -6
  284. package/src/core/compression/transcriptPathNotice.ts +31 -0
  285. package/src/core/contentGenerator.ts +15 -39
  286. package/src/core/logger.ts +370 -39
  287. package/src/core/prompts.ts +4 -114
  288. package/src/core/turn.ts +3 -3
  289. package/src/hooks/hookTranslator.ts +6 -4
  290. package/src/index.ts +7 -7
  291. package/src/llm-types/index.ts +5 -0
  292. package/src/llm-types/modelEnvelope.ts +26 -2
  293. package/src/policy/policies/read-only.toml +0 -5
  294. package/src/prompt-config/TemplateEngine.ts +0 -3
  295. package/src/prompt-config/defaults/providers/gemini/core.md +0 -2
  296. package/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/core.md +0 -2
  297. package/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/gemini-2-5-flash/core.md +0 -2
  298. package/src/prompt-config/prompt-loader.ts +7 -8
  299. package/src/prompt-config/types.ts +0 -1
  300. package/src/recording/CheckpointService.ts +110 -45
  301. package/src/recording/HistoryMutationService.ts +28 -3
  302. package/src/recording/RecordingIntegration.ts +258 -11
  303. package/src/recording/ReplayEngine.ts +220 -110
  304. package/src/recording/SessionDiscovery.ts +30 -4
  305. package/src/recording/SessionRecordingService.ts +253 -55
  306. package/src/recording/SessionTransitionService.ts +75 -12
  307. package/src/recording/index.ts +7 -0
  308. package/src/recording/janitor/cleanupTypes.ts +4 -0
  309. package/src/recording/janitor/mediaReclamation.ts +295 -0
  310. package/src/recording/janitor/sessionJanitor.ts +54 -1
  311. package/src/recording/janitor/sessionScanner.ts +319 -227
  312. package/src/recording/replay-test-helpers.ts +33 -2
  313. package/src/recording/replayCheckpointMetadata.ts +115 -0
  314. package/src/recording/replayErrorFormatting.ts +43 -0
  315. package/src/recording/resumeSession.ts +10 -0
  316. package/src/recording/semanticMediaPurgeReplayValidation.ts +35 -0
  317. package/src/recording/session-media-package-blobs.ts +116 -0
  318. package/src/recording/session-media-package-import.ts +189 -0
  319. package/src/recording/session-media-package-state.ts +120 -0
  320. package/src/recording/session-media-package-validation.ts +400 -0
  321. package/src/recording/session-media-package-writer.ts +117 -0
  322. package/src/recording/session-media-package.ts +692 -0
  323. package/src/recording/types.ts +37 -2
  324. package/src/runtime/AgentRuntimeContext.ts +28 -5
  325. package/src/runtime/AgentRuntimeLoader.ts +32 -7
  326. package/src/runtime/contracts/PromptEstimation.ts +1 -0
  327. package/src/runtime/contracts/RuntimeProvider.ts +3 -8
  328. package/src/runtime/contracts/RuntimeProviderManager.ts +0 -2
  329. package/src/runtime/createAgentRuntimeContext.ts +43 -1
  330. package/src/runtime/providerRuntimeContext.ts +22 -0
  331. package/src/runtime/runtimeAdapters.ts +2 -2
  332. package/src/services/history/ContentConverters.ts +11 -7
  333. package/src/services/history/HistoryService.ts +71 -696
  334. package/src/services/history/HistoryServiceCore.ts +1055 -0
  335. package/src/services/history/IContent.ts +460 -20
  336. package/src/services/history/contentSize.ts +22 -2
  337. package/src/services/history/historyChronology.ts +53 -3
  338. package/src/services/history/historyCloneUtils.ts +26 -22
  339. package/src/services/history/historyCompressionQueue.ts +102 -0
  340. package/src/services/history/historyEventTypes.ts +9 -0
  341. package/src/services/history/historyMutationFailure.ts +33 -0
  342. package/src/services/history/historyProviderPipeline.ts +19 -5
  343. package/src/services/history/historyTokenEstimation.ts +9 -5
  344. package/src/services/history/historyToolNormalization.ts +43 -11
  345. package/src/services/history/provider-file-binding.ts +115 -0
  346. package/src/services/history/semantic-media-purge.ts +593 -0
  347. package/src/storage/SessionPersistenceService.ts +667 -30
  348. package/src/storage/history-media-ownership.ts +185 -0
  349. package/src/storage/local-media-store-child.ts +163 -0
  350. package/src/storage/local-media-store-files.ts +643 -0
  351. package/src/storage/local-media-store-lock-recovery.ts +159 -0
  352. package/src/storage/local-media-store-persistence.ts +737 -0
  353. package/src/storage/local-media-store-quota.ts +111 -0
  354. package/src/storage/local-media-store-reservations.ts +485 -0
  355. package/src/storage/local-media-store-types.ts +161 -0
  356. package/src/storage/local-media-store-validation.ts +643 -0
  357. package/src/storage/local-media-store.ts +696 -0
  358. package/src/storage/media-admission-service.ts +512 -0
  359. package/src/storage/media-lifecycle-metrics.ts +228 -0
  360. package/src/storage/media-reference-lifecycle.ts +164 -0
  361. package/src/storage/request-media-resolver.ts +491 -0
  362. package/src/storage/session-media-service-factories.ts +48 -0
  363. package/src/storage/session-persistence-helpers.ts +85 -0
  364. package/src/test-utils/config.ts +7 -5
  365. package/src/test-utils/runtime.ts +3 -2
  366. package/src/tools-adapters/CoreShellToolHostAdapter.ts +1 -11
  367. package/src/tools-adapters/CoreSkillServiceAdapter.ts +0 -23
  368. package/src/tools-adapters/CoreToolHostAdapter.ts +0 -36
  369. package/src/utils/environmentContext.ts +11 -30
  370. package/src/utils/errorParsing.ts +19 -69
  371. package/src/utils/generateContentResponseUtilities.ts +28 -1
  372. package/src/utils/summarizer.ts +8 -10
  373. package/src/utils/tool-utils.ts +7 -1
  374. package/dist/src/code_assist/codeAssist.d.ts +0 -19
  375. package/dist/src/code_assist/codeAssist.js +0 -41
  376. package/dist/src/code_assist/codeAssist.js.map +0 -1
  377. package/dist/src/code_assist/contentGeneratorAdapters.d.ts +0 -49
  378. package/dist/src/code_assist/contentGeneratorAdapters.js +0 -197
  379. package/dist/src/code_assist/contentGeneratorAdapters.js.map +0 -1
  380. package/dist/src/code_assist/converter.d.ts +0 -74
  381. package/dist/src/code_assist/converter.js +0 -158
  382. package/dist/src/code_assist/converter.js.map +0 -1
  383. package/dist/src/code_assist/googleGenAIWrapper.d.ts +0 -27
  384. package/dist/src/code_assist/googleGenAIWrapper.js +0 -46
  385. package/dist/src/code_assist/googleGenAIWrapper.js.map +0 -1
  386. package/dist/src/code_assist/oauth-credential-storage.d.ts +0 -30
  387. package/dist/src/code_assist/oauth-credential-storage.js +0 -135
  388. package/dist/src/code_assist/oauth-credential-storage.js.map +0 -1
  389. package/dist/src/code_assist/server.d.ts +0 -44
  390. package/dist/src/code_assist/server.js +0 -154
  391. package/dist/src/code_assist/server.js.map +0 -1
  392. package/dist/src/code_assist/setup.d.ts +0 -20
  393. package/dist/src/code_assist/setup.js +0 -126
  394. package/dist/src/code_assist/setup.js.map +0 -1
  395. package/dist/src/code_assist/types.d.ts +0 -161
  396. package/dist/src/code_assist/types.js +0 -46
  397. package/dist/src/code_assist/types.js.map +0 -1
  398. package/dist/src/utils/getFolderStructure.d.ts +0 -31
  399. package/dist/src/utils/getFolderStructure.js +0 -240
  400. package/dist/src/utils/getFolderStructure.js.map +0 -1
  401. package/dist/src/utils/installationManager.d.ts +0 -16
  402. package/dist/src/utils/installationManager.js +0 -51
  403. package/dist/src/utils/installationManager.js.map +0 -1
  404. package/dist/src/utils/llm-edit-fixer.d.ts +0 -25
  405. package/dist/src/utils/llm-edit-fixer.js +0 -120
  406. package/dist/src/utils/llm-edit-fixer.js.map +0 -1
  407. package/src/code_assist/codeAssist.ts +0 -59
  408. package/src/code_assist/contentGeneratorAdapters.ts +0 -275
  409. package/src/code_assist/converter.ts +0 -288
  410. package/src/code_assist/googleGenAIWrapper.ts +0 -90
  411. package/src/code_assist/oauth-credential-storage.ts +0 -171
  412. package/src/code_assist/server.ts +0 -263
  413. package/src/code_assist/setup.ts +0 -189
  414. package/src/code_assist/types.ts +0 -201
  415. package/src/utils/getFolderStructure.ts +0 -382
  416. package/src/utils/installationManager.ts +0 -59
  417. package/src/utils/llm-edit-fixer.ts +0 -157
@@ -1,275 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- /**
8
- * Gemini boundary conversion helpers. This file lives inside the code_assist
9
- * enclave, so importing @google/genai is permitted. It converts between the
10
- * neutral llm-types request/response shapes and the Google SDK shapes so that
11
- * the neutral ContentGenerator interface can be implemented without leaking
12
- * Google types to callers.
13
- */
14
-
15
- import {
16
- type GenerateContentParameters,
17
- type GenerateContentConfig,
18
- type CountTokensParameters,
19
- type CountTokensResponse,
20
- type EmbedContentResponse,
21
- type GenerateContentResponse,
22
- type Candidate,
23
- type Part,
24
- type Tool,
25
- type ToolConfig,
26
- type FunctionCallingConfig,
27
- type Content,
28
- FunctionCallingConfigMode,
29
- } from '@google/genai';
30
- import type { ModelGenerationRequest } from '../llm-types/modelRequest.js';
31
- import type {
32
- ToolDeclaration,
33
- ToolChoice,
34
- } from '../llm-types/toolDeclaration.js';
35
- import type { ModelOutput } from '../llm-types/modelEnvelope.js';
36
- import type {
37
- CountTokensRequest,
38
- CountTokensResult,
39
- EmbedContentResult,
40
- } from '../llm-types/tokensAndEmbeddings.js';
41
- import { mapGeminiFinishReason } from '../llm-types/finishReasons.js';
42
- import type { UsageStats, ContentBlock } from '../services/history/IContent.js';
43
- import { ContentConverters } from '../services/history/ContentConverters.js';
44
-
45
- /**
46
- * Convert a neutral ToolChoice into the Gemini ToolConfig shape.
47
- *
48
- * Gemini has no explicit "required" concept — it uses mode ANY to force a call.
49
- * allowedToolNames maps to allowedFunctionNames.
50
- */
51
- function toGeminiToolConfig(choice: ToolChoice): ToolConfig {
52
- let mode: FunctionCallingConfigMode;
53
- if (choice.mode === 'none') {
54
- mode = FunctionCallingConfigMode.NONE;
55
- } else if (choice.mode === 'required') {
56
- mode = FunctionCallingConfigMode.ANY;
57
- } else {
58
- mode = FunctionCallingConfigMode.AUTO;
59
- }
60
- const config: FunctionCallingConfig = { mode };
61
- if (choice.allowedToolNames && choice.allowedToolNames.length > 0) {
62
- config.allowedFunctionNames = choice.allowedToolNames;
63
- }
64
- return { functionCallingConfig: config };
65
- }
66
-
67
- /**
68
- * Convert neutral ToolDeclaration[] to Gemini tools shape.
69
- */
70
- function toGeminiTools(tools: ToolDeclaration[]): Tool[] {
71
- return [
72
- {
73
- functionDeclarations: tools.map((t) => ({
74
- name: t.name,
75
- ...(t.description !== undefined ? { description: t.description } : {}),
76
- parametersJsonSchema: t.parametersJsonSchema,
77
- })),
78
- },
79
- ];
80
- }
81
-
82
- /**
83
- * Convert a neutral ModelGenerationRequest to Google GenerateContentParameters.
84
- *
85
- * Settings are mapped first; modelParams is spread LAST so explicit provider
86
- * extras win over the neutral settings mapping.
87
- */
88
- export function toGenerateContentParameters(
89
- request: ModelGenerationRequest,
90
- ): GenerateContentParameters {
91
- const contents: Content[] = ContentConverters.toGeminiContents(
92
- request.contents,
93
- );
94
-
95
- const config: GenerateContentConfig = {};
96
-
97
- const settings = request.settings;
98
- if (settings) {
99
- if (settings.temperature !== undefined) {
100
- config.temperature = settings.temperature;
101
- }
102
- if (settings.maxOutputTokens !== undefined) {
103
- config.maxOutputTokens = settings.maxOutputTokens;
104
- }
105
- if (settings.topP !== undefined) {
106
- config.topP = settings.topP;
107
- }
108
- if (settings.systemInstruction !== undefined) {
109
- config.systemInstruction = settings.systemInstruction;
110
- }
111
- if (settings.responseJsonSchema !== undefined) {
112
- config.responseJsonSchema = settings.responseJsonSchema;
113
- }
114
- if (settings.toolChoice !== undefined) {
115
- config.toolConfig = toGeminiToolConfig(settings.toolChoice);
116
- }
117
- }
118
-
119
- if (request.tools && request.tools.length > 0) {
120
- config.tools = toGeminiTools(request.tools);
121
- }
122
-
123
- if (request.abortSignal !== undefined) {
124
- config.abortSignal = request.abortSignal;
125
- }
126
-
127
- // modelParams spread LAST so explicit provider params win.
128
- if (request.modelParams) {
129
- Object.assign(config, request.modelParams);
130
- }
131
-
132
- const params: GenerateContentParameters = {
133
- model: request.model ?? '',
134
- contents: contents as never,
135
- config,
136
- };
137
-
138
- return params;
139
- }
140
-
141
- /**
142
- * Convert a Google GenerateContentResponse to a neutral ModelOutput.
143
- */
144
- export function fromGenerateContentResponse(
145
- response: GenerateContentResponse,
146
- ): ModelOutput {
147
- const candidate: Candidate | undefined = response.candidates?.[0];
148
-
149
- let blocks: ContentBlock[] = [];
150
- if (candidate?.content) {
151
- const icontent = ContentConverters.toIContent(candidate.content);
152
- blocks = icontent.blocks;
153
- }
154
-
155
- const output: ModelOutput = {
156
- content: { speaker: 'ai', blocks },
157
- };
158
-
159
- const rawFinishReason = candidate?.finishReason;
160
- if (rawFinishReason !== undefined) {
161
- const finish = mapGeminiFinishReason(String(rawFinishReason));
162
- output.finishReason = finish.finishReason;
163
- output.rawStopReason = finish.rawStopReason;
164
- }
165
-
166
- const usageMeta = response.usageMetadata as
167
- | {
168
- promptTokenCount?: number;
169
- candidatesTokenCount?: number;
170
- totalTokenCount?: number;
171
- cachedContentTokenCount?: number;
172
- thoughtsTokenCount?: number;
173
- }
174
- | undefined;
175
-
176
- if (usageMeta) {
177
- const usage: UsageStats = {
178
- promptTokens: usageMeta.promptTokenCount ?? 0,
179
- completionTokens: usageMeta.candidatesTokenCount ?? 0,
180
- totalTokens: usageMeta.totalTokenCount ?? 0,
181
- };
182
- if (usageMeta.cachedContentTokenCount !== undefined) {
183
- usage.cachedTokens = usageMeta.cachedContentTokenCount;
184
- }
185
- if (usageMeta.thoughtsTokenCount !== undefined) {
186
- usage.reasoningTokens = usageMeta.thoughtsTokenCount;
187
- }
188
- output.usage = usage;
189
- }
190
-
191
- if (response.responseId) {
192
- output.responseId = response.responseId;
193
- }
194
-
195
- const providerMetadata: Record<string, unknown> = {};
196
- if (response.promptFeedback) {
197
- providerMetadata['gemini.promptFeedback'] = response.promptFeedback;
198
- }
199
- if (candidate) {
200
- const candidateObj = candidate as Record<string, unknown>;
201
- if (candidateObj.safetyRatings !== undefined) {
202
- providerMetadata['gemini.safetyRatings'] = candidateObj.safetyRatings;
203
- }
204
- if (candidateObj.groundingMetadata !== undefined) {
205
- providerMetadata['gemini.groundingMetadata'] =
206
- candidateObj.groundingMetadata;
207
- }
208
- }
209
- if (Object.keys(providerMetadata).length > 0) {
210
- output.providerMetadata = providerMetadata;
211
- }
212
-
213
- return output;
214
- }
215
-
216
- /**
217
- * Convert a neutral CountTokensRequest to Google CountTokensParameters.
218
- * model is optional since the neutral type does not carry it.
219
- */
220
- export function toCountTokensParameters(
221
- request: CountTokensRequest,
222
- model?: string,
223
- ): CountTokensParameters {
224
- const contents: Content[] = ContentConverters.toGeminiContents(
225
- request.contents,
226
- );
227
- return {
228
- model: model ?? '',
229
- contents: contents as never,
230
- };
231
- }
232
-
233
- /**
234
- * Convert a Google CountTokensResponse to neutral CountTokensResult.
235
- */
236
- export function fromCountTokensResponse(
237
- response: CountTokensResponse,
238
- ): CountTokensResult {
239
- return {
240
- totalTokens: response.totalTokens ?? 0,
241
- };
242
- }
243
-
244
- /**
245
- * Convert a Google EmbedContentResponse to neutral EmbedContentResult.
246
- */
247
- export function fromEmbedContentResponse(
248
- response: EmbedContentResponse,
249
- ): EmbedContentResult {
250
- const embeddings = (response.embeddings ?? []).map(
251
- (emb: { values?: number[] }) => emb.values ?? [],
252
- );
253
- return { embeddings };
254
- }
255
-
256
- /**
257
- * Stream wrapper: maps each Google response chunk through
258
- * fromGenerateContentResponse to produce neutral ModelStreamChunk values.
259
- */
260
- export async function* mapGeminiStreamToChunks(
261
- stream: AsyncIterable<GenerateContentResponse>,
262
- ): AsyncGenerator<ReturnType<typeof fromGenerateContentResponse>> {
263
- for await (const chunk of stream) {
264
- yield fromGenerateContentResponse(chunk);
265
- }
266
- }
267
-
268
- /**
269
- * Helper to extract the raw parts array from a candidate for testing/diagnostics.
270
- */
271
- export function extractPartsFromCandidate(
272
- candidate: Candidate | undefined,
273
- ): Part[] {
274
- return candidate?.content?.parts ?? [];
275
- }
@@ -1,288 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import type {
8
- CountTokensResponse,
9
- MediaResolution,
10
- GenerateContentResponsePromptFeedback,
11
- GenerateContentResponseUsageMetadata,
12
- } from '@google/genai';
13
- import {
14
- type Content,
15
- type ContentListUnion,
16
- type ContentUnion,
17
- type GenerateContentConfig,
18
- type GenerateContentParameters,
19
- type CountTokensParameters,
20
- GenerateContentResponse,
21
- type GenerationConfigRoutingConfig,
22
- type Candidate,
23
- type ModelSelectionConfig,
24
- type Part,
25
- type SafetySetting,
26
- type PartUnion,
27
- type SpeechConfigUnion,
28
- type ThinkingConfig,
29
- type ToolListUnion,
30
- type ToolConfig,
31
- } from '@google/genai';
32
-
33
- export interface CAGenerateContentRequest {
34
- model: string;
35
- project?: string;
36
- user_prompt_id?: string;
37
- request: VertexGenerateContentRequest;
38
- }
39
-
40
- interface VertexGenerateContentRequest {
41
- contents: Content[];
42
- systemInstruction?: Content;
43
- cachedContent?: string;
44
- tools?: ToolListUnion;
45
- toolConfig?: ToolConfig;
46
- labels?: Record<string, string>;
47
- safetySettings?: SafetySetting[];
48
- generationConfig?: VertexGenerationConfig;
49
- session_id?: string;
50
- }
51
-
52
- interface VertexGenerationConfig {
53
- temperature?: number;
54
- topP?: number;
55
- topK?: number;
56
- candidateCount?: number;
57
- maxOutputTokens?: number;
58
- stopSequences?: string[];
59
- responseLogprobs?: boolean;
60
- logprobs?: number;
61
- presencePenalty?: number;
62
- frequencyPenalty?: number;
63
- seed?: number;
64
- responseMimeType?: string;
65
- responseJsonSchema?: unknown;
66
- responseSchema?: unknown;
67
- routingConfig?: GenerationConfigRoutingConfig;
68
- modelSelectionConfig?: ModelSelectionConfig;
69
- responseModalities?: string[];
70
- mediaResolution?: MediaResolution;
71
- speechConfig?: SpeechConfigUnion;
72
- audioTimestamp?: boolean;
73
- thinkingConfig?: ThinkingConfig;
74
- }
75
-
76
- export interface CaGenerateContentResponse {
77
- response: VertexGenerateContentResponse;
78
- traceId?: string;
79
- }
80
-
81
- interface VertexGenerateContentResponse {
82
- candidates: Candidate[];
83
- automaticFunctionCallingHistory?: Content[];
84
- promptFeedback?: GenerateContentResponsePromptFeedback;
85
- usageMetadata?: GenerateContentResponseUsageMetadata;
86
- modelVersion?: string;
87
- }
88
-
89
- export interface CaCountTokenRequest {
90
- request: VertexCountTokenRequest;
91
- }
92
-
93
- interface VertexCountTokenRequest {
94
- model: string;
95
- contents: Content[];
96
- }
97
-
98
- export interface CaCountTokenResponse {
99
- totalTokens: number;
100
- }
101
-
102
- export function toCountTokenRequest(
103
- req: CountTokensParameters,
104
- ): CaCountTokenRequest {
105
- return {
106
- request: {
107
- model: 'models/' + req.model,
108
- contents: toContents(req.contents),
109
- },
110
- };
111
- }
112
-
113
- export function fromCountTokenResponse(
114
- res: CaCountTokenResponse,
115
- ): CountTokensResponse {
116
- return {
117
- totalTokens: res.totalTokens,
118
- };
119
- }
120
-
121
- export function toGenerateContentRequest(
122
- req: GenerateContentParameters,
123
- userPromptId: string,
124
- project?: string,
125
- _sessionId?: string,
126
- ): CAGenerateContentRequest {
127
- return {
128
- model: req.model,
129
- project,
130
- user_prompt_id: userPromptId,
131
- request: toVertexGenerateContentRequest(req, _sessionId),
132
- };
133
- }
134
-
135
- export function fromGenerateContentResponse(
136
- res: CaGenerateContentResponse,
137
- ): GenerateContentResponse {
138
- const inres = res.response;
139
- const out = new GenerateContentResponse();
140
- out.candidates = inres.candidates;
141
- out.automaticFunctionCallingHistory = inres.automaticFunctionCallingHistory;
142
- out.promptFeedback = inres.promptFeedback;
143
- out.usageMetadata = inres.usageMetadata;
144
- out.modelVersion = inres.modelVersion;
145
- out.responseId = res.traceId;
146
- return out;
147
- }
148
-
149
- function toVertexGenerateContentRequest(
150
- req: GenerateContentParameters,
151
- _sessionId?: string,
152
- ): VertexGenerateContentRequest {
153
- return {
154
- contents: toContents(req.contents),
155
- systemInstruction: maybeToContent(req.config?.systemInstruction),
156
- cachedContent: req.config?.cachedContent,
157
- tools: req.config?.tools,
158
- toolConfig: req.config?.toolConfig,
159
- labels: req.config?.labels,
160
- safetySettings: req.config?.safetySettings,
161
- generationConfig: toVertexGenerationConfig(req.config),
162
- // PRIVACY FIX: session_id removed to prevent transmission to Google servers
163
- // session_id: sessionId,
164
- };
165
- }
166
-
167
- export function toContents(contents: ContentListUnion): Content[] {
168
- if (Array.isArray(contents)) {
169
- // it's a Content[] or a PartsUnion[]
170
- return contents.map(toContent);
171
- }
172
- // it's a Content or a PartsUnion
173
- return [toContent(contents)];
174
- }
175
-
176
- function maybeToContent(content?: ContentUnion): Content | undefined {
177
- if (content == null) {
178
- return undefined;
179
- }
180
- return toContent(content);
181
- }
182
-
183
- function toContent(content: ContentUnion): Content {
184
- if (Array.isArray(content)) {
185
- // it's a PartsUnion[]
186
- return {
187
- role: 'user',
188
- parts: toParts(content),
189
- };
190
- }
191
- if (typeof content === 'string') {
192
- // it's a string
193
- return {
194
- role: 'user',
195
- parts: [{ text: content }],
196
- };
197
- }
198
- if ('parts' in content) {
199
- // it's a Content - process parts to handle thought filtering
200
- return {
201
- ...content,
202
- parts: toParts(content.parts ?? []),
203
- };
204
- }
205
- // it's a Part
206
- return {
207
- role: 'user',
208
- parts: [toPart(content as Part)],
209
- };
210
- }
211
-
212
- function toParts(parts: PartUnion[]): Part[] {
213
- return parts.map(toPart);
214
- }
215
-
216
- function toPart(part: PartUnion): Part {
217
- if (typeof part === 'string') {
218
- // it's a string
219
- return { text: part };
220
- }
221
-
222
- // Handle thought parts for CountToken API compatibility
223
- // The CountToken API expects parts to have certain required "oneof" fields initialized,
224
- // but thought parts don't conform to this schema and cause API failures
225
- if ('thought' in part && Boolean(part.thought)) {
226
- const thoughtText = `[Thought: ${part.thought}]`;
227
-
228
- const newPart = { ...part };
229
- delete (newPart as Record<string, unknown>)['thought'];
230
-
231
- const hasApiContent =
232
- 'functionCall' in newPart ||
233
- 'functionResponse' in newPart ||
234
- 'inlineData' in newPart ||
235
- 'fileData' in newPart;
236
-
237
- if (hasApiContent) {
238
- // It's a functionCall or other non-text part. Just strip the thought.
239
- return newPart;
240
- }
241
-
242
- // If no other valid API content, this must be a text part.
243
- // Combine existing text (if any) with the thought, preserving other properties.
244
- const text = (newPart as { text?: unknown }).text;
245
- const existingText =
246
- text !== undefined && text !== null ? String(text) : '';
247
- const combinedText =
248
- existingText !== '' ? `${existingText}\n${thoughtText}` : thoughtText;
249
-
250
- return {
251
- ...newPart,
252
- text: combinedText,
253
- };
254
- }
255
-
256
- return part;
257
- }
258
-
259
- function toVertexGenerationConfig(
260
- config?: GenerateContentConfig,
261
- ): VertexGenerationConfig | undefined {
262
- if (!config) {
263
- return undefined;
264
- }
265
- return {
266
- temperature: config.temperature,
267
- topP: config.topP,
268
- topK: config.topK,
269
- candidateCount: config.candidateCount,
270
- maxOutputTokens: config.maxOutputTokens,
271
- stopSequences: config.stopSequences,
272
- responseLogprobs: config.responseLogprobs,
273
- logprobs: config.logprobs,
274
- presencePenalty: config.presencePenalty,
275
- frequencyPenalty: config.frequencyPenalty,
276
- seed: config.seed,
277
- responseMimeType: config.responseMimeType,
278
- responseSchema: config.responseSchema,
279
- responseJsonSchema: config.responseJsonSchema,
280
- routingConfig: config.routingConfig,
281
- modelSelectionConfig: config.modelSelectionConfig,
282
- responseModalities: config.responseModalities,
283
- mediaResolution: config.mediaResolution,
284
- speechConfig: config.speechConfig,
285
- audioTimestamp: config.audioTimestamp,
286
- thinkingConfig: config.thinkingConfig,
287
- };
288
- }
@@ -1,90 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- /**
8
- * GoogleGenAIWrapper — implements the NEUTRAL ContentGenerator interface using
9
- * the Google GenAI SDK. Lives in the code_assist enclave so @google/genai
10
- * imports are permitted. Converts neutral requests to Google parameters via
11
- * the boundary adapters and Google responses back to neutral ModelOutput.
12
- */
13
-
14
- import {
15
- type ContentGenerator,
16
- type ContentGeneratorConfig,
17
- } from '../core/contentGenerator.js';
18
- import type { Models, GoogleGenAI } from '@google/genai';
19
- import { GoogleGenAI as GoogleGenAIClass } from '@google/genai';
20
- import type {
21
- ModelGenerationRequest,
22
- ModelOutput,
23
- ModelStreamChunk,
24
- CountTokensRequest,
25
- CountTokensResult,
26
- EmbedContentRequest,
27
- EmbedContentResult,
28
- } from '../llm-types/index.js';
29
- import {
30
- toGenerateContentParameters,
31
- fromGenerateContentResponse,
32
- toCountTokensParameters,
33
- fromCountTokensResponse,
34
- fromEmbedContentResponse,
35
- mapGeminiStreamToChunks,
36
- } from './contentGeneratorAdapters.js';
37
-
38
- /**
39
- * Wrapper around GoogleGenAI models interface to implement the neutral
40
- * ContentGenerator. Converts at the boundary so callers never see Google types.
41
- */
42
- export class GoogleGenAIWrapper implements ContentGenerator {
43
- private models: Models;
44
-
45
- constructor(
46
- config: ContentGeneratorConfig,
47
- httpOptions: { headers: Record<string, string> },
48
- ) {
49
- const googleGenAI: GoogleGenAI = new GoogleGenAIClass({
50
- apiKey: config.apiKey === '' ? undefined : config.apiKey,
51
- vertexai: config.vertexai,
52
- httpOptions,
53
- });
54
- this.models = googleGenAI.models;
55
- }
56
-
57
- async generateContent(
58
- request: ModelGenerationRequest,
59
- _userPromptId: string,
60
- ): Promise<ModelOutput> {
61
- const params = toGenerateContentParameters(request);
62
- const response = await this.models.generateContent(params);
63
- return fromGenerateContentResponse(response);
64
- }
65
-
66
- async generateContentStream(
67
- request: ModelGenerationRequest,
68
- _userPromptId: string,
69
- ): Promise<AsyncGenerator<ModelStreamChunk>> {
70
- const params = toGenerateContentParameters(request);
71
- const stream = await this.models.generateContentStream(params);
72
- return mapGeminiStreamToChunks(stream);
73
- }
74
-
75
- async countTokens(request: CountTokensRequest): Promise<CountTokensResult> {
76
- const params = toCountTokensParameters(request);
77
- const response = await this.models.countTokens(params);
78
- return fromCountTokensResponse(response);
79
- }
80
- async embedContent(
81
- request: EmbedContentRequest,
82
- ): Promise<EmbedContentResult> {
83
- const params = {
84
- model: '',
85
- contents: request.texts,
86
- };
87
- const response = await this.models.embedContent(params);
88
- return fromEmbedContentResponse(response);
89
- }
90
- }