@vscode/chat-lib 0.2.1-3 → 0.2.1-30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/dist/src/_internal/extension/byok/node/openAIEndpoint.js +1 -1
  2. package/dist/src/_internal/extension/byok/node/openAIEndpoint.js.map +1 -1
  3. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/copilotCompletion.d.ts +1 -1
  4. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/copilotCompletion.d.ts.map +1 -1
  5. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/copilotCompletion.js +0 -4
  6. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/copilotCompletion.js.map +1 -1
  7. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/ghostText.d.ts +71 -4
  8. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/ghostText.d.ts.map +1 -1
  9. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/ghostText.js +260 -235
  10. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/ghostText.js.map +1 -1
  11. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/last.d.ts +2 -4
  12. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/last.d.ts.map +1 -1
  13. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/last.js +5 -5
  14. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/last.js.map +1 -1
  15. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/streamedCompletionSplitter.d.ts.map +1 -1
  16. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/streamedCompletionSplitter.js +3 -5
  17. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/streamedCompletionSplitter.js.map +1 -1
  18. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/telemetry.d.ts +2 -1
  19. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/telemetry.d.ts.map +1 -1
  20. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/telemetry.js +4 -3
  21. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/ghostText/telemetry.js.map +1 -1
  22. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/networkConfiguration.d.ts +1 -6
  23. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/networkConfiguration.d.ts.map +1 -1
  24. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/networking.d.ts +1 -0
  25. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/networking.d.ts.map +1 -1
  26. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/networking.js +1 -0
  27. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/networking.js.map +1 -1
  28. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/openai/fetch.d.ts +25 -7
  29. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/openai/fetch.d.ts.map +1 -1
  30. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/openai/fetch.js +316 -23
  31. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/openai/fetch.js.map +1 -1
  32. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/openai/openai.d.ts +5 -9
  33. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/openai/openai.d.ts.map +1 -1
  34. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/openai/openai.js +0 -3
  35. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/openai/openai.js.map +1 -1
  36. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/openai/stream.d.ts +3 -27
  37. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/openai/stream.d.ts.map +1 -1
  38. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/openai/stream.js +17 -62
  39. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/openai/stream.js.map +1 -1
  40. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/postInsertion.d.ts +1 -1
  41. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/postInsertion.d.ts.map +1 -1
  42. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/postInsertion.js +0 -4
  43. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/postInsertion.js.map +1 -1
  44. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/completionsPromptFactory/componentsCompletionsPromptFactory.d.ts +2 -1
  45. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/completionsPromptFactory/componentsCompletionsPromptFactory.d.ts.map +1 -1
  46. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/completionsPromptFactory/componentsCompletionsPromptFactory.js +12 -7
  47. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/completionsPromptFactory/componentsCompletionsPromptFactory.js.map +1 -1
  48. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/components/diagnostics.d.ts +10 -0
  49. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/components/diagnostics.d.ts.map +1 -0
  50. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/components/diagnostics.js +92 -0
  51. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/components/diagnostics.js.map +1 -0
  52. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/components/splitContextPrompt.d.ts.map +1 -1
  53. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/components/splitContextPrompt.js +2 -1
  54. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/components/splitContextPrompt.js.map +1 -1
  55. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/contextProviders/contextItemSchemas.d.ts +6 -2
  56. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/contextProviders/contextItemSchemas.d.ts.map +1 -1
  57. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/contextProviders/contextItemSchemas.js +106 -43
  58. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/contextProviders/contextItemSchemas.js.map +1 -1
  59. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/contextProviders/diagnostics.d.ts +5 -0
  60. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/contextProviders/diagnostics.d.ts.map +1 -0
  61. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/contextProviders/diagnostics.js +59 -0
  62. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/prompt/contextProviders/diagnostics.js.map +1 -0
  63. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/suggestions/anomalyDetection.d.ts +1 -1
  64. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/suggestions/anomalyDetection.d.ts.map +1 -1
  65. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/suggestions/anomalyDetection.js.map +1 -1
  66. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/telemetry.d.ts +2 -1
  67. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/telemetry.d.ts.map +1 -1
  68. package/dist/src/_internal/extension/completions-core/vscode-node/lib/src/telemetry.js.map +1 -1
  69. package/dist/src/_internal/extension/completions-core/vscode-node/types/src/contextProviderApiV1.d.ts +10 -2
  70. package/dist/src/_internal/extension/completions-core/vscode-node/types/src/contextProviderApiV1.d.ts.map +1 -1
  71. package/dist/src/_internal/extension/completions-core/vscode-node/types/src/contextProviderApiV1.js +8 -0
  72. package/dist/src/_internal/extension/completions-core/vscode-node/types/src/contextProviderApiV1.js.map +1 -1
  73. package/dist/src/_internal/extension/inlineEdits/node/nextEditCache.d.ts +6 -2
  74. package/dist/src/_internal/extension/inlineEdits/node/nextEditCache.d.ts.map +1 -1
  75. package/dist/src/_internal/extension/inlineEdits/node/nextEditCache.js +5 -5
  76. package/dist/src/_internal/extension/inlineEdits/node/nextEditCache.js.map +1 -1
  77. package/dist/src/_internal/extension/inlineEdits/node/nextEditProvider.d.ts.map +1 -1
  78. package/dist/src/_internal/extension/inlineEdits/node/nextEditProvider.js +10 -7
  79. package/dist/src/_internal/extension/inlineEdits/node/nextEditProvider.js.map +1 -1
  80. package/dist/src/_internal/extension/inlineEdits/node/nextEditResult.d.ts +3 -0
  81. package/dist/src/_internal/extension/inlineEdits/node/nextEditResult.d.ts.map +1 -1
  82. package/dist/src/_internal/extension/inlineEdits/node/nextEditResult.js.map +1 -1
  83. package/dist/src/_internal/extension/prompt/node/chatMLFetcher.d.ts.map +1 -1
  84. package/dist/src/_internal/extension/prompt/node/chatMLFetcher.js +32 -18
  85. package/dist/src/_internal/extension/prompt/node/chatMLFetcher.js.map +1 -1
  86. package/dist/src/_internal/extension/prompt/node/chatMLFetcherTelemetry.d.ts +7 -5
  87. package/dist/src/_internal/extension/prompt/node/chatMLFetcherTelemetry.d.ts.map +1 -1
  88. package/dist/src/_internal/extension/prompt/node/chatMLFetcherTelemetry.js +26 -14
  89. package/dist/src/_internal/extension/prompt/node/chatMLFetcherTelemetry.js.map +1 -1
  90. package/dist/src/_internal/extension/xtab/common/lintErrors.d.ts +2 -0
  91. package/dist/src/_internal/extension/xtab/common/lintErrors.d.ts.map +1 -1
  92. package/dist/src/_internal/extension/xtab/common/lintErrors.js +31 -7
  93. package/dist/src/_internal/extension/xtab/common/lintErrors.js.map +1 -1
  94. package/dist/src/_internal/extension/xtab/common/promptCrafting.d.ts +1 -1
  95. package/dist/src/_internal/extension/xtab/common/promptCrafting.d.ts.map +1 -1
  96. package/dist/src/_internal/extension/xtab/common/promptCrafting.js +18 -10
  97. package/dist/src/_internal/extension/xtab/common/promptCrafting.js.map +1 -1
  98. package/dist/src/_internal/extension/xtab/common/tags.d.ts +1 -0
  99. package/dist/src/_internal/extension/xtab/common/tags.d.ts.map +1 -1
  100. package/dist/src/_internal/extension/xtab/common/tags.js +1 -0
  101. package/dist/src/_internal/extension/xtab/common/tags.js.map +1 -1
  102. package/dist/src/_internal/extension/xtab/node/xtabCustomDiffPatchResponseHandler.d.ts +21 -0
  103. package/dist/src/_internal/extension/xtab/node/xtabCustomDiffPatchResponseHandler.d.ts.map +1 -0
  104. package/dist/src/_internal/extension/xtab/node/xtabCustomDiffPatchResponseHandler.js +97 -0
  105. package/dist/src/_internal/extension/xtab/node/xtabCustomDiffPatchResponseHandler.js.map +1 -0
  106. package/dist/src/_internal/extension/xtab/node/xtabNextCursorPredictor.d.ts.map +1 -1
  107. package/dist/src/_internal/extension/xtab/node/xtabNextCursorPredictor.js +12 -9
  108. package/dist/src/_internal/extension/xtab/node/xtabNextCursorPredictor.js.map +1 -1
  109. package/dist/src/_internal/extension/xtab/node/xtabProvider.d.ts +12 -6
  110. package/dist/src/_internal/extension/xtab/node/xtabProvider.d.ts.map +1 -1
  111. package/dist/src/_internal/extension/xtab/node/xtabProvider.js +46 -16
  112. package/dist/src/_internal/extension/xtab/node/xtabProvider.js.map +1 -1
  113. package/dist/src/_internal/platform/authentication/common/authentication.d.ts +2 -1
  114. package/dist/src/_internal/platform/authentication/common/authentication.d.ts.map +1 -1
  115. package/dist/src/_internal/platform/authentication/common/authentication.js +7 -2
  116. package/dist/src/_internal/platform/authentication/common/authentication.js.map +1 -1
  117. package/dist/src/_internal/platform/authentication/common/copilotToken.d.ts +148 -47
  118. package/dist/src/_internal/platform/authentication/common/copilotToken.d.ts.map +1 -1
  119. package/dist/src/_internal/platform/authentication/common/copilotToken.js +138 -14
  120. package/dist/src/_internal/platform/authentication/common/copilotToken.js.map +1 -1
  121. package/dist/src/_internal/platform/authentication/common/staticGitHubAuthenticationService.js +1 -1
  122. package/dist/src/_internal/platform/authentication/common/staticGitHubAuthenticationService.js.map +1 -1
  123. package/dist/src/_internal/platform/authentication/node/copilotTokenManager.d.ts +10 -0
  124. package/dist/src/_internal/platform/authentication/node/copilotTokenManager.d.ts.map +1 -1
  125. package/dist/src/_internal/platform/authentication/node/copilotTokenManager.js +110 -40
  126. package/dist/src/_internal/platform/authentication/node/copilotTokenManager.js.map +1 -1
  127. package/dist/src/_internal/platform/chat/common/chatMLFetcher.js +1 -1
  128. package/dist/src/_internal/platform/chat/common/chatMLFetcher.js.map +1 -1
  129. package/dist/src/_internal/platform/chat/common/commonTypes.d.ts +5 -1
  130. package/dist/src/_internal/platform/chat/common/commonTypes.d.ts.map +1 -1
  131. package/dist/src/_internal/platform/chat/common/commonTypes.js +5 -1
  132. package/dist/src/_internal/platform/chat/common/commonTypes.js.map +1 -1
  133. package/dist/src/_internal/platform/completions-core/common/openai/copilotAnnotations.d.ts +27 -0
  134. package/dist/src/_internal/platform/completions-core/common/openai/copilotAnnotations.d.ts.map +1 -0
  135. package/dist/src/_internal/platform/completions-core/common/openai/copilotAnnotations.js +35 -0
  136. package/dist/src/_internal/platform/completions-core/common/openai/copilotAnnotations.js.map +1 -0
  137. package/dist/src/_internal/platform/configuration/common/configurationService.d.ts +46 -30
  138. package/dist/src/_internal/platform/configuration/common/configurationService.d.ts.map +1 -1
  139. package/dist/src/_internal/platform/configuration/common/configurationService.js +32 -15
  140. package/dist/src/_internal/platform/configuration/common/configurationService.js.map +1 -1
  141. package/dist/src/_internal/platform/configuration/common/validator.d.ts +2 -0
  142. package/dist/src/_internal/platform/configuration/common/validator.d.ts.map +1 -1
  143. package/dist/src/_internal/platform/configuration/common/validator.js +18 -0
  144. package/dist/src/_internal/platform/configuration/common/validator.js.map +1 -1
  145. package/dist/src/_internal/platform/endpoint/common/chatModelCapabilities.d.ts +1 -0
  146. package/dist/src/_internal/platform/endpoint/common/chatModelCapabilities.d.ts.map +1 -1
  147. package/dist/src/_internal/platform/endpoint/common/chatModelCapabilities.js +27 -20
  148. package/dist/src/_internal/platform/endpoint/common/chatModelCapabilities.js.map +1 -1
  149. package/dist/src/_internal/platform/endpoint/common/endpointTypes.d.ts +1 -0
  150. package/dist/src/_internal/platform/endpoint/common/endpointTypes.d.ts.map +1 -1
  151. package/dist/src/_internal/platform/endpoint/common/endpointTypes.js +1 -0
  152. package/dist/src/_internal/platform/endpoint/common/endpointTypes.js.map +1 -1
  153. package/dist/src/_internal/platform/endpoint/node/chatEndpoint.d.ts +1 -0
  154. package/dist/src/_internal/platform/endpoint/node/chatEndpoint.d.ts.map +1 -1
  155. package/dist/src/_internal/platform/endpoint/node/chatEndpoint.js +49 -10
  156. package/dist/src/_internal/platform/endpoint/node/chatEndpoint.js.map +1 -1
  157. package/dist/src/_internal/platform/endpoint/node/messagesApi.d.ts +18 -5
  158. package/dist/src/_internal/platform/endpoint/node/messagesApi.d.ts.map +1 -1
  159. package/dist/src/_internal/platform/endpoint/node/messagesApi.js +262 -90
  160. package/dist/src/_internal/platform/endpoint/node/messagesApi.js.map +1 -1
  161. package/dist/src/_internal/platform/endpoint/node/responsesApi.d.ts +2 -0
  162. package/dist/src/_internal/platform/endpoint/node/responsesApi.d.ts.map +1 -1
  163. package/dist/src/_internal/platform/endpoint/node/responsesApi.js +23 -5
  164. package/dist/src/_internal/platform/endpoint/node/responsesApi.js.map +1 -1
  165. package/dist/src/_internal/platform/git/common/gitService.d.ts +8 -1
  166. package/dist/src/_internal/platform/git/common/gitService.d.ts.map +1 -1
  167. package/dist/src/_internal/platform/git/common/gitService.js.map +1 -1
  168. package/dist/src/_internal/platform/github/common/githubAPI.d.ts +34 -0
  169. package/dist/src/_internal/platform/github/common/githubAPI.d.ts.map +1 -1
  170. package/dist/src/_internal/platform/github/common/githubAPI.js +94 -0
  171. package/dist/src/_internal/platform/github/common/githubAPI.js.map +1 -1
  172. package/dist/src/_internal/platform/github/common/githubService.d.ts +53 -18
  173. package/dist/src/_internal/platform/github/common/githubService.d.ts.map +1 -1
  174. package/dist/src/_internal/platform/github/common/githubService.js +62 -2
  175. package/dist/src/_internal/platform/github/common/githubService.js.map +1 -1
  176. package/dist/src/_internal/platform/inlineCompletions/common/api.d.ts +5 -1
  177. package/dist/src/_internal/platform/inlineCompletions/common/api.d.ts.map +1 -1
  178. package/dist/src/_internal/platform/inlineEdits/common/dataTypes/languageContext.d.ts +10 -2
  179. package/dist/src/_internal/platform/inlineEdits/common/dataTypes/languageContext.d.ts.map +1 -1
  180. package/dist/src/_internal/platform/inlineEdits/common/dataTypes/languageContext.js +23 -4
  181. package/dist/src/_internal/platform/inlineEdits/common/dataTypes/languageContext.js.map +1 -1
  182. package/dist/src/_internal/platform/inlineEdits/common/dataTypes/nextCursorLinePrediction.d.ts +1 -2
  183. package/dist/src/_internal/platform/inlineEdits/common/dataTypes/nextCursorLinePrediction.d.ts.map +1 -1
  184. package/dist/src/_internal/platform/inlineEdits/common/dataTypes/nextCursorLinePrediction.js +0 -1
  185. package/dist/src/_internal/platform/inlineEdits/common/dataTypes/nextCursorLinePrediction.js.map +1 -1
  186. package/dist/src/_internal/platform/inlineEdits/common/dataTypes/xtabPromptOptions.d.ts +6 -3
  187. package/dist/src/_internal/platform/inlineEdits/common/dataTypes/xtabPromptOptions.d.ts.map +1 -1
  188. package/dist/src/_internal/platform/inlineEdits/common/dataTypes/xtabPromptOptions.js +5 -0
  189. package/dist/src/_internal/platform/inlineEdits/common/dataTypes/xtabPromptOptions.js.map +1 -1
  190. package/dist/src/_internal/platform/inlineEdits/common/inlineEditLogContext.d.ts +1 -0
  191. package/dist/src/_internal/platform/inlineEdits/common/inlineEditLogContext.d.ts.map +1 -1
  192. package/dist/src/_internal/platform/inlineEdits/common/inlineEditLogContext.js +120 -0
  193. package/dist/src/_internal/platform/inlineEdits/common/inlineEditLogContext.js.map +1 -1
  194. package/dist/src/_internal/platform/inlineEdits/common/statelessNextEditProvider.d.ts +7 -5
  195. package/dist/src/_internal/platform/inlineEdits/common/statelessNextEditProvider.d.ts.map +1 -1
  196. package/dist/src/_internal/platform/inlineEdits/common/statelessNextEditProvider.js.map +1 -1
  197. package/dist/src/_internal/platform/inlineEdits/node/inlineEditsModelService.d.ts.map +1 -1
  198. package/dist/src/_internal/platform/inlineEdits/node/inlineEditsModelService.js +5 -0
  199. package/dist/src/_internal/platform/inlineEdits/node/inlineEditsModelService.js.map +1 -1
  200. package/dist/src/_internal/platform/languageServer/common/languageContextService.d.ts +27 -2
  201. package/dist/src/_internal/platform/languageServer/common/languageContextService.d.ts.map +1 -1
  202. package/dist/src/_internal/platform/languageServer/common/languageContextService.js +1 -0
  203. package/dist/src/_internal/platform/languageServer/common/languageContextService.js.map +1 -1
  204. package/dist/src/_internal/platform/log/common/logService.d.ts +12 -0
  205. package/dist/src/_internal/platform/log/common/logService.d.ts.map +1 -1
  206. package/dist/src/_internal/platform/log/common/logService.js +39 -0
  207. package/dist/src/_internal/platform/log/common/logService.js.map +1 -1
  208. package/dist/src/_internal/platform/nesFetch/common/completionsAPI.d.ts +74 -0
  209. package/dist/src/_internal/platform/nesFetch/common/completionsAPI.d.ts.map +1 -0
  210. package/dist/src/_internal/platform/nesFetch/common/completionsAPI.js +23 -0
  211. package/dist/src/_internal/platform/nesFetch/common/completionsAPI.js.map +1 -0
  212. package/dist/src/_internal/platform/nesFetch/common/completionsFetchService.d.ts +72 -0
  213. package/dist/src/_internal/platform/nesFetch/common/completionsFetchService.d.ts.map +1 -0
  214. package/dist/src/_internal/platform/nesFetch/common/completionsFetchService.js +44 -0
  215. package/dist/src/_internal/platform/nesFetch/common/completionsFetchService.js.map +1 -0
  216. package/dist/src/_internal/platform/nesFetch/common/responseStream.d.ts +35 -0
  217. package/dist/src/_internal/platform/nesFetch/common/responseStream.d.ts.map +1 -0
  218. package/dist/src/_internal/platform/nesFetch/common/responseStream.js +162 -0
  219. package/dist/src/_internal/platform/nesFetch/common/responseStream.js.map +1 -0
  220. package/dist/src/_internal/platform/nesFetch/node/completionsFetchServiceImpl.d.ts +29 -0
  221. package/dist/src/_internal/platform/nesFetch/node/completionsFetchServiceImpl.d.ts.map +1 -0
  222. package/dist/src/_internal/platform/nesFetch/node/completionsFetchServiceImpl.js +171 -0
  223. package/dist/src/_internal/platform/nesFetch/node/completionsFetchServiceImpl.js.map +1 -0
  224. package/dist/src/_internal/platform/nesFetch/node/streamTransformer.d.ts +10 -0
  225. package/dist/src/_internal/platform/nesFetch/node/streamTransformer.d.ts.map +1 -0
  226. package/dist/src/_internal/platform/nesFetch/node/streamTransformer.js +86 -0
  227. package/dist/src/_internal/platform/nesFetch/node/streamTransformer.js.map +1 -0
  228. package/dist/src/_internal/platform/networking/common/anthropic.d.ts +167 -0
  229. package/dist/src/_internal/platform/networking/common/anthropic.d.ts.map +1 -0
  230. package/dist/src/_internal/platform/networking/common/anthropic.js +172 -0
  231. package/dist/src/_internal/platform/networking/common/anthropic.js.map +1 -0
  232. package/dist/src/_internal/platform/networking/common/fetch.d.ts +18 -11
  233. package/dist/src/_internal/platform/networking/common/fetch.d.ts.map +1 -1
  234. package/dist/src/_internal/platform/networking/common/fetch.js +5 -5
  235. package/dist/src/_internal/platform/networking/common/fetch.js.map +1 -1
  236. package/dist/src/_internal/platform/networking/common/fetcherService.d.ts +40 -7
  237. package/dist/src/_internal/platform/networking/common/fetcherService.d.ts.map +1 -1
  238. package/dist/src/_internal/platform/networking/common/fetcherService.js +96 -11
  239. package/dist/src/_internal/platform/networking/common/fetcherService.js.map +1 -1
  240. package/dist/src/_internal/platform/networking/common/networking.d.ts +4 -3
  241. package/dist/src/_internal/platform/networking/common/networking.d.ts.map +1 -1
  242. package/dist/src/_internal/platform/networking/common/networking.js.map +1 -1
  243. package/dist/src/_internal/platform/networking/common/openai.d.ts.map +1 -1
  244. package/dist/src/_internal/platform/networking/common/openai.js +13 -1
  245. package/dist/src/_internal/platform/networking/common/openai.js.map +1 -1
  246. package/dist/src/_internal/platform/networking/node/stream.d.ts.map +1 -1
  247. package/dist/src/_internal/platform/networking/node/stream.js +50 -23
  248. package/dist/src/_internal/platform/networking/node/stream.js.map +1 -1
  249. package/dist/src/_internal/platform/requestLogger/node/nullRequestLogger.d.ts +1 -0
  250. package/dist/src/_internal/platform/requestLogger/node/nullRequestLogger.d.ts.map +1 -1
  251. package/dist/src/_internal/platform/requestLogger/node/nullRequestLogger.js +2 -0
  252. package/dist/src/_internal/platform/requestLogger/node/nullRequestLogger.js.map +1 -1
  253. package/dist/src/_internal/platform/requestLogger/node/requestLogger.d.ts +2 -0
  254. package/dist/src/_internal/platform/requestLogger/node/requestLogger.d.ts.map +1 -1
  255. package/dist/src/_internal/platform/requestLogger/node/requestLogger.js.map +1 -1
  256. package/dist/src/_internal/platform/thinking/common/thinkingUtils.d.ts +2 -2
  257. package/dist/src/_internal/platform/thinking/common/thinkingUtils.d.ts.map +1 -1
  258. package/dist/src/_internal/platform/thinking/common/thinkingUtils.js +4 -0
  259. package/dist/src/_internal/platform/thinking/common/thinkingUtils.js.map +1 -1
  260. package/dist/src/_internal/platform/tokenizer/node/tokenizer.d.ts +1 -1
  261. package/dist/src/_internal/platform/tokenizer/node/tokenizer.d.ts.map +1 -1
  262. package/dist/src/_internal/platform/tokenizer/node/tokenizer.js.map +1 -1
  263. package/dist/src/_internal/util/common/test/shims/chatTypes.d.ts +7 -7
  264. package/dist/src/_internal/util/common/test/shims/chatTypes.d.ts.map +1 -1
  265. package/dist/src/_internal/util/common/test/shims/chatTypes.js +11 -11
  266. package/dist/src/_internal/util/common/test/shims/chatTypes.js.map +1 -1
  267. package/dist/src/_internal/util/common/test/shims/vscodeTypesShim.js +3 -3
  268. package/dist/src/_internal/util/common/test/shims/vscodeTypesShim.js.map +1 -1
  269. package/dist/src/_internal/util/common/tracing.d.ts +13 -0
  270. package/dist/src/_internal/util/common/tracing.d.ts.map +1 -1
  271. package/dist/src/_internal/util/common/tracing.js +7 -0
  272. package/dist/src/_internal/util/common/tracing.js.map +1 -1
  273. package/dist/src/_internal/vscodeTypes.d.ts +1 -1
  274. package/dist/src/_internal/vscodeTypes.d.ts.map +1 -1
  275. package/dist/src/_internal/vscodeTypes.js +3 -3
  276. package/dist/src/_internal/vscodeTypes.js.map +1 -1
  277. package/dist/src/main.d.ts.map +1 -1
  278. package/dist/src/main.js +3 -0
  279. package/dist/src/main.js.map +1 -1
  280. package/dist/src/package.json +450 -221
  281. package/package.json +4 -4
@@ -1,11 +1,18 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
+ return function (target, key) { decorator(target, key, paramIndex); }
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ForceMultiLine = exports.ResultType = void 0;
12
+ exports.ForceMultiLine = exports.CompletionsFromNetwork = exports.ResultType = void 0;
4
13
  exports.getGhostText = getGhostText;
5
- /*---------------------------------------------------------------------------------------------
6
- * Copyright (c) Microsoft Corporation. All rights reserved.
7
- * Licensed under the MIT License. See License.txt in the project root for license information.
8
- *--------------------------------------------------------------------------------------------*/
14
+ const configurationService_1 = require("../../../../../../platform/configuration/common/configurationService");
15
+ const nullExperimentationService_1 = require("../../../../../../platform/telemetry/common/nullExperimentationService");
9
16
  const telemetry_1 = require("../../../../../../platform/telemetry/common/telemetry");
10
17
  const crypto_1 = require("../../../../../../util/common/crypto");
11
18
  const uuid_1 = require("../../../../../../util/vs/base/common/uuid");
@@ -54,117 +61,256 @@ var ResultType;
54
61
  // average token length is around 4 characters
55
62
  // the below values have quite a bit of buffer while bringing the limit in significantly from 500
56
63
  const maxSinglelineTokens = 20;
57
- async function genericGetCompletionsFromNetwork(accessor, requestContext, baseTelemetryData, cancellationToken, finishedCb, what, processChoices) {
58
- const featuresService = accessor.get(featuresService_1.ICompletionsFeaturesService);
59
- const fetcherService = accessor.get(fetch_1.ICompletionsOpenAIFetcherService);
60
- const runtimeMode = accessor.get(runtimeMode_1.ICompletionsRuntimeModeService);
61
- const instantiationService = accessor.get(instantiation_1.IInstantiationService);
62
- const logTarget = accessor.get(logger_1.ICompletionsLogTargetService);
63
- const userErrorNotifier = accessor.get(userErrorNotifier_1.ICompletionsUserErrorNotifierService);
64
- ghostTextLogger.debug(logTarget, `Getting ${what} from network`);
65
- // copy the base telemetry data
66
- baseTelemetryData = baseTelemetryData.extendedBy();
67
- // Request one choice for automatic requests, three for invoked (cycling) requests.
68
- const n = requestContext.isCycling ? 3 : 1;
69
- const temperature = (0, openai_1.getTemperatureForSamples)(runtimeMode, n);
70
- const extra = {
71
- language: requestContext.languageId,
72
- next_indent: requestContext.indentation.next ?? 0,
73
- trim_by_indentation: (0, config_1.shouldDoServerTrimming)(requestContext.blockMode),
74
- prompt_tokens: requestContext.prompt.prefixTokens ?? 0,
75
- suffix_tokens: requestContext.prompt.suffixTokens ?? 0,
76
- };
77
- const postOptions = { n, temperature, code_annotations: false };
78
- const modelTerminatesSingleline = featuresService.modelAlwaysTerminatesSingleline(baseTelemetryData);
79
- const simulateSingleline = requestContext.blockMode === config_1.BlockMode.MoreMultiline &&
80
- blockTrimmer_1.BlockTrimmer.isSupported(requestContext.languageId) &&
81
- !modelTerminatesSingleline;
82
- if (!requestContext.multiline && !simulateSingleline) {
83
- // If we are not in multiline mode, we get the server to truncate the results. This does mean that we
84
- // also cache a single line result which will be reused even if we are later in multiline mode. This is
85
- // an acceptable trade-off as the transition should be relatively rare and truncating on the server is
86
- // more efficient.
87
- // Note that this also means we don't need to truncate when creating the GhostAPIChoice object below.
88
- postOptions['stop'] = ['\n'];
89
- }
90
- else if (requestContext.stop) {
91
- postOptions['stop'] = requestContext.stop;
64
+ let CompletionsFromNetwork = class CompletionsFromNetwork {
65
+ constructor(instantiationService, fetcherService, featuresService, runtimeMode, logTarget, completionsCacheService, userErrorNotifier, configurationService, expService) {
66
+ this.instantiationService = instantiationService;
67
+ this.fetcherService = fetcherService;
68
+ this.featuresService = featuresService;
69
+ this.runtimeMode = runtimeMode;
70
+ this.logTarget = logTarget;
71
+ this.completionsCacheService = completionsCacheService;
72
+ this.userErrorNotifier = userErrorNotifier;
73
+ this.configurationService = configurationService;
74
+ this.expService = expService;
92
75
  }
93
- if (requestContext.maxTokens !== undefined) {
94
- postOptions['max_tokens'] = requestContext.maxTokens;
76
+ /** Requests new completion from OpenAI, should be called if and only if the completions for given prompt were not cached before.
77
+ * It returns only first completion, additional completions are added to the caches in the background.
78
+ * Copies from the base telemetry data are used as the basis for each choice's telemetry.
79
+ */
80
+ async getCompletionsFromNetwork(requestContext, baseTelemetryData, cancellationToken, finishedCb) {
81
+ return this.genericGetCompletionsFromNetwork(requestContext, baseTelemetryData, cancellationToken, finishedCb, 'completions', async (requestStart, processingTime, choicesStream) => {
82
+ const choicesIterator = choicesStream[Symbol.asyncIterator]();
83
+ const firstRes = await choicesIterator.next();
84
+ if (firstRes.done) {
85
+ ghostTextLogger.debug(this.logTarget, 'All choices redacted');
86
+ return {
87
+ type: 'empty',
88
+ reason: 'all choices redacted',
89
+ telemetryData: (0, telemetry_3.mkBasicResultTelemetry)(baseTelemetryData),
90
+ };
91
+ }
92
+ if (cancellationToken?.isCancellationRequested) {
93
+ ghostTextLogger.debug(this.logTarget, 'Cancelled after awaiting redactedChoices iterator');
94
+ return {
95
+ type: 'canceled',
96
+ reason: 'after awaiting redactedChoices iterator',
97
+ telemetryData: (0, telemetry_3.mkCanceledResultTelemetry)(baseTelemetryData),
98
+ };
99
+ }
100
+ const firstChoice = firstRes.value;
101
+ if (firstChoice === undefined) {
102
+ // This is probably unreachable given the firstRes.done check above
103
+ ghostTextLogger.debug(this.logTarget, 'Got undefined choice from redactedChoices iterator');
104
+ return {
105
+ type: 'empty',
106
+ reason: 'got undefined choice from redactedChoices iterator',
107
+ telemetryData: (0, telemetry_3.mkBasicResultTelemetry)(baseTelemetryData),
108
+ };
109
+ }
110
+ this.instantiationService.invokeFunction(telemetryPerformance, 'performance', firstChoice, requestStart, processingTime);
111
+ ghostTextLogger.debug(this.logTarget, `Awaited first result, id: ${firstChoice.choiceIndex}`);
112
+ // Adds first result to cache
113
+ const processedFirstChoice = postProcessChoices(firstChoice);
114
+ if (processedFirstChoice) {
115
+ appendToCache(this.completionsCacheService, requestContext, processedFirstChoice);
116
+ ghostTextLogger.debug(this.logTarget, `GhostText first completion (index ${processedFirstChoice?.choiceIndex}): ${JSON.stringify(processedFirstChoice?.completionText)}`);
117
+ }
118
+ //Create promise for each result, don't `await` it (unless in test mode) but handle asynchronously with `.then()`
119
+ const cacheDone = (async () => {
120
+ const apiChoices = processedFirstChoice !== undefined ? [processedFirstChoice] : [];
121
+ for await (const choice of choicesStream) {
122
+ if (choice === undefined) {
123
+ continue;
124
+ }
125
+ ghostTextLogger.debug(this.logTarget, `GhostText later completion (index ${choice?.choiceIndex}): ${JSON.stringify(choice.completionText)}`);
126
+ const processedChoice = postProcessChoices(choice, apiChoices);
127
+ if (!processedChoice) {
128
+ continue;
129
+ }
130
+ apiChoices.push(processedChoice);
131
+ appendToCache(this.completionsCacheService, requestContext, processedChoice);
132
+ }
133
+ })();
134
+ if (this.runtimeMode.isRunningInTest()) {
135
+ await cacheDone;
136
+ }
137
+ if (processedFirstChoice) {
138
+ // Because we ask the server to stop at \n above, we don't need to force single line here
139
+ return {
140
+ type: 'success',
141
+ value: [makeGhostAPIChoice(processedFirstChoice, { forceSingleLine: false }), cacheDone],
142
+ telemetryData: (0, telemetry_3.mkBasicResultTelemetry)(baseTelemetryData),
143
+ telemetryBlob: baseTelemetryData,
144
+ resultType: ResultType.Network,
145
+ };
146
+ }
147
+ else {
148
+ return {
149
+ type: 'empty',
150
+ reason: 'got undefined processedFirstChoice',
151
+ telemetryData: (0, telemetry_3.mkBasicResultTelemetry)(baseTelemetryData),
152
+ };
153
+ }
154
+ });
95
155
  }
96
- const requestStart = Date.now();
97
- // extend telemetry data
98
- const newProperties = {
99
- endpoint: 'completions',
100
- uiKind: fetch_1.CopilotUiKind.GhostText,
101
- temperature: JSON.stringify(temperature),
102
- n: JSON.stringify(n),
103
- stop: JSON.stringify(postOptions['stop']) ?? 'unset',
104
- logit_bias: JSON.stringify(null),
105
- };
106
- Object.assign(baseTelemetryData.properties, newProperties);
107
- try {
108
- const completionParams = {
109
- prompt: requestContext.prompt,
110
- languageId: requestContext.languageId,
111
- repoInfo: requestContext.repoInfo,
112
- ourRequestId: requestContext.ourRequestId,
113
- engineModelId: requestContext.engineModelId,
114
- count: n,
115
- uiKind: fetch_1.CopilotUiKind.GhostText,
116
- postOptions,
117
- headers: requestContext.headers,
118
- extra,
119
- };
120
- const res = await fetcherService.fetchAndStreamCompletions(completionParams, baseTelemetryData, finishedCb, cancellationToken);
121
- if (res.type === 'failed') {
156
+ /** Requests new completion from OpenAI, should be called if and only if we are in the servers-side termination mode, and it's follow-up cycling request
157
+ * It returns all requested completions
158
+ * Copies from the base telemetry data are used as the basis for each choice's telemetry.
159
+ */
160
+ async getAllCompletionsFromNetwork(requestContext, baseTelemetryData, cancellationToken, finishedCb) {
161
+ return this.genericGetCompletionsFromNetwork(requestContext, baseTelemetryData, cancellationToken, finishedCb, 'all completions', async (requestStart, processingTime, choicesStream) => {
162
+ const apiChoices = [];
163
+ for await (const choice of choicesStream) {
164
+ if (cancellationToken?.isCancellationRequested) {
165
+ ghostTextLogger.debug(this.logTarget, 'Cancelled after awaiting choices iterator');
166
+ return {
167
+ type: 'canceled',
168
+ reason: 'after awaiting choices iterator',
169
+ telemetryData: (0, telemetry_3.mkCanceledResultTelemetry)(baseTelemetryData),
170
+ };
171
+ }
172
+ const processedChoice = postProcessChoices(choice, apiChoices);
173
+ if (!processedChoice) {
174
+ continue;
175
+ }
176
+ apiChoices.push(processedChoice);
177
+ }
178
+ //Append results to current completions cache, and network cache
179
+ if (apiChoices.length > 0) {
180
+ for (const choice of apiChoices) {
181
+ appendToCache(this.completionsCacheService, requestContext, choice);
182
+ }
183
+ this.instantiationService.invokeFunction(telemetryPerformance, 'cyclingPerformance', apiChoices[0], requestStart, processingTime);
184
+ }
122
185
  return {
123
- type: 'failed',
124
- reason: res.reason,
186
+ type: 'success',
187
+ value: [apiChoices, Promise.resolve()],
125
188
  telemetryData: (0, telemetry_3.mkBasicResultTelemetry)(baseTelemetryData),
189
+ telemetryBlob: baseTelemetryData,
190
+ resultType: ResultType.Cycling,
126
191
  };
192
+ });
193
+ }
194
+ async genericGetCompletionsFromNetwork(requestContext, baseTelemetryData, cancellationToken, finishedCb, what, processChoices) {
195
+ ghostTextLogger.debug(this.logTarget, `Getting ${what} from network`);
196
+ // copy the base telemetry data
197
+ baseTelemetryData = baseTelemetryData.extendedBy();
198
+ // Request one choice for automatic requests, three for invoked (cycling) requests.
199
+ const n = requestContext.isCycling ? 3 : 1;
200
+ const temperature = (0, openai_1.getTemperatureForSamples)(this.runtimeMode, n);
201
+ const extra = {
202
+ language: requestContext.languageId,
203
+ next_indent: requestContext.indentation.next ?? 0,
204
+ trim_by_indentation: (0, config_1.shouldDoServerTrimming)(requestContext.blockMode),
205
+ prompt_tokens: requestContext.prompt.prefixTokens ?? 0,
206
+ suffix_tokens: requestContext.prompt.suffixTokens ?? 0,
207
+ };
208
+ const postOptions = { n, temperature, code_annotations: false };
209
+ const modelTerminatesSingleline = this.featuresService.modelAlwaysTerminatesSingleline(baseTelemetryData);
210
+ const simulateSingleline = requestContext.blockMode === config_1.BlockMode.MoreMultiline &&
211
+ blockTrimmer_1.BlockTrimmer.isSupported(requestContext.languageId) &&
212
+ !modelTerminatesSingleline;
213
+ if (!requestContext.multiline && !simulateSingleline) {
214
+ // If we are not in multiline mode, we get the server to truncate the results. This does mean that we
215
+ // also cache a single line result which will be reused even if we are later in multiline mode. This is
216
+ // an acceptable trade-off as the transition should be relatively rare and truncating on the server is
217
+ // more efficient.
218
+ // Note that this also means we don't need to truncate when creating the GhostAPIChoice object below.
219
+ postOptions['stop'] = ['\n'];
127
220
  }
128
- if (res.type === 'canceled') {
129
- ghostTextLogger.debug(logTarget, 'Cancelled after awaiting fetchCompletions');
130
- return {
131
- type: 'canceled',
132
- reason: res.reason,
133
- telemetryData: (0, telemetry_3.mkCanceledResultTelemetry)(baseTelemetryData),
134
- };
221
+ else if (requestContext.stop) {
222
+ postOptions['stop'] = requestContext.stop;
135
223
  }
136
- return processChoices(requestStart, res.getProcessingTime(), res.choices);
137
- }
138
- catch (err) {
139
- // If we cancelled a network request, we don't want to log an error
140
- if ((0, networking_1.isAbortError)(err)) {
141
- return {
142
- type: 'canceled',
143
- reason: 'network request aborted',
144
- telemetryData: (0, telemetry_3.mkCanceledResultTelemetry)(baseTelemetryData, {
145
- cancelledNetworkRequest: true,
146
- }),
224
+ if (requestContext.maxTokens !== undefined) {
225
+ postOptions['max_tokens'] = requestContext.maxTokens;
226
+ }
227
+ const requestStart = Date.now();
228
+ // extend telemetry data
229
+ const newProperties = {
230
+ endpoint: 'completions',
231
+ uiKind: fetch_1.CopilotUiKind.GhostText,
232
+ temperature: JSON.stringify(temperature),
233
+ n: JSON.stringify(n),
234
+ stop: JSON.stringify(postOptions['stop']) ?? 'unset',
235
+ logit_bias: JSON.stringify(null),
236
+ };
237
+ Object.assign(baseTelemetryData.properties, newProperties);
238
+ try {
239
+ const completionParams = {
240
+ prompt: requestContext.prompt,
241
+ languageId: requestContext.languageId,
242
+ repoInfo: requestContext.repoInfo,
243
+ ourRequestId: requestContext.ourRequestId,
244
+ engineModelId: requestContext.engineModelId,
245
+ count: n,
246
+ uiKind: fetch_1.CopilotUiKind.GhostText,
247
+ postOptions,
248
+ headers: requestContext.headers,
249
+ extra,
147
250
  };
251
+ const res = this.configurationService.getExperimentBasedConfig(configurationService_1.ConfigKey.TeamInternal.GhostTextUseCompletionsFetchService, this.expService)
252
+ ? await this.fetcherService.fetchAndStreamCompletions2(completionParams, baseTelemetryData, finishedCb, cancellationToken)
253
+ : await this.fetcherService.fetchAndStreamCompletions(completionParams, baseTelemetryData, finishedCb, cancellationToken);
254
+ if (res.type === 'failed') {
255
+ return {
256
+ type: 'failed',
257
+ reason: res.reason,
258
+ telemetryData: (0, telemetry_3.mkBasicResultTelemetry)(baseTelemetryData),
259
+ };
260
+ }
261
+ if (res.type === 'canceled') {
262
+ ghostTextLogger.debug(this.logTarget, 'Cancelled after awaiting fetchCompletions');
263
+ return {
264
+ type: 'canceled',
265
+ reason: res.reason,
266
+ telemetryData: (0, telemetry_3.mkCanceledResultTelemetry)(baseTelemetryData),
267
+ };
268
+ }
269
+ return processChoices(requestStart, res.getProcessingTime(), res.choices);
148
270
  }
149
- else {
150
- instantiationService.invokeFunction(acc => ghostTextLogger.exception(acc, err, `Error on ghost text request`));
151
- userErrorNotifier.notifyUser(err);
152
- if (runtimeMode.shouldFailForDebugPurposes()) {
153
- throw err;
271
+ catch (err) {
272
+ // If we cancelled a network request, we don't want to log an error
273
+ if ((0, networking_1.isAbortError)(err)) {
274
+ return {
275
+ type: 'canceled',
276
+ reason: 'network request aborted',
277
+ telemetryData: (0, telemetry_3.mkCanceledResultTelemetry)(baseTelemetryData, {
278
+ cancelledNetworkRequest: true,
279
+ }),
280
+ };
281
+ }
282
+ else {
283
+ this.instantiationService.invokeFunction(acc => ghostTextLogger.exception(acc, err, `Error on ghost text request`));
284
+ this.userErrorNotifier.notifyUser(err);
285
+ if (this.runtimeMode.shouldFailForDebugPurposes()) {
286
+ throw err;
287
+ }
288
+ // not including err in this result because it'll end up in standard telemetry
289
+ return {
290
+ type: 'failed',
291
+ reason: 'non-abort error on ghost text request',
292
+ telemetryData: (0, telemetry_3.mkBasicResultTelemetry)(baseTelemetryData),
293
+ };
154
294
  }
155
- // not including err in this result because it'll end up in standard telemetry
156
- return {
157
- type: 'failed',
158
- reason: 'non-abort error on ghost text request',
159
- telemetryData: (0, telemetry_3.mkBasicResultTelemetry)(baseTelemetryData),
160
- };
161
295
  }
162
296
  }
163
- }
297
+ };
298
+ exports.CompletionsFromNetwork = CompletionsFromNetwork;
299
+ exports.CompletionsFromNetwork = CompletionsFromNetwork = __decorate([
300
+ __param(0, instantiation_1.IInstantiationService),
301
+ __param(1, fetch_1.ICompletionsOpenAIFetcherService),
302
+ __param(2, featuresService_1.ICompletionsFeaturesService),
303
+ __param(3, runtimeMode_1.ICompletionsRuntimeModeService),
304
+ __param(4, logger_1.ICompletionsLogTargetService),
305
+ __param(5, completionsCache_1.ICompletionsCacheService),
306
+ __param(6, userErrorNotifier_1.ICompletionsUserErrorNotifierService),
307
+ __param(7, configurationService_1.IConfigurationService),
308
+ __param(8, nullExperimentationService_1.IExperimentationService)
309
+ ], CompletionsFromNetwork);
164
310
  /**
165
311
  * Post-proceses a completion choice based on the current request context and existing choices.
166
312
  */
167
- function postProcessChoices(newChoice, requestContext, currentChoices) {
313
+ function postProcessChoices(newChoice, currentChoices) {
168
314
  if (!currentChoices) {
169
315
  currentChoices = [];
170
316
  }
@@ -178,129 +324,6 @@ function postProcessChoices(newChoice, requestContext, currentChoices) {
178
324
  }
179
325
  return newChoice;
180
326
  }
181
- /** Requests new completion from OpenAI, should be called if and only if the completions for given prompt were not cached before.
182
- * It returns only first completion, additional completions are added to the caches in the background.
183
- * Copies from the base telemetry data are used as the basis for each choice's telemetry.
184
- */
185
- async function getCompletionsFromNetwork(accessor, requestContext, baseTelemetryData, cancellationToken, finishedCb) {
186
- const instantiationService = accessor.get(instantiation_1.IInstantiationService);
187
- const logTarget = accessor.get(logger_1.ICompletionsLogTargetService);
188
- const runtimeMode = accessor.get(runtimeMode_1.ICompletionsRuntimeModeService);
189
- return genericGetCompletionsFromNetwork(accessor, requestContext, baseTelemetryData, cancellationToken, finishedCb, 'completions', async (requestStart, processingTime, choicesStream) => {
190
- const choicesIterator = choicesStream[Symbol.asyncIterator]();
191
- const firstRes = await choicesIterator.next();
192
- if (firstRes.done) {
193
- ghostTextLogger.debug(logTarget, 'All choices redacted');
194
- return {
195
- type: 'empty',
196
- reason: 'all choices redacted',
197
- telemetryData: (0, telemetry_3.mkBasicResultTelemetry)(baseTelemetryData),
198
- };
199
- }
200
- if (cancellationToken?.isCancellationRequested) {
201
- ghostTextLogger.debug(logTarget, 'Cancelled after awaiting redactedChoices iterator');
202
- return {
203
- type: 'canceled',
204
- reason: 'after awaiting redactedChoices iterator',
205
- telemetryData: (0, telemetry_3.mkCanceledResultTelemetry)(baseTelemetryData),
206
- };
207
- }
208
- const firstChoice = firstRes.value;
209
- if (firstChoice === undefined) {
210
- // This is probably unreachable given the firstRes.done check above
211
- ghostTextLogger.debug(logTarget, 'Got undefined choice from redactedChoices iterator');
212
- return {
213
- type: 'empty',
214
- reason: 'got undefined choice from redactedChoices iterator',
215
- telemetryData: (0, telemetry_3.mkBasicResultTelemetry)(baseTelemetryData),
216
- };
217
- }
218
- instantiationService.invokeFunction(telemetryPerformance, 'performance', firstChoice, requestStart, processingTime);
219
- ghostTextLogger.debug(logTarget, `Awaited first result, id: ${firstChoice.choiceIndex}`);
220
- // Adds first result to cache
221
- const processedFirstChoice = postProcessChoices(firstChoice, requestContext);
222
- if (processedFirstChoice) {
223
- instantiationService.invokeFunction(appendToCache, requestContext, processedFirstChoice);
224
- ghostTextLogger.debug(logTarget, `GhostText first completion (index ${processedFirstChoice?.choiceIndex}): ${JSON.stringify(processedFirstChoice?.completionText)}`);
225
- }
226
- //Create promise for each result, don't `await` it (unless in test mode) but handle asynchronously with `.then()`
227
- const cacheDone = (async () => {
228
- const apiChoices = processedFirstChoice !== undefined ? [processedFirstChoice] : [];
229
- for await (const choice of choicesStream) {
230
- if (choice === undefined) {
231
- continue;
232
- }
233
- ghostTextLogger.debug(logTarget, `GhostText later completion (index ${choice?.choiceIndex}): ${JSON.stringify(choice.completionText)}`);
234
- const processedChoice = postProcessChoices(choice, requestContext, apiChoices);
235
- if (!processedChoice) {
236
- continue;
237
- }
238
- apiChoices.push(processedChoice);
239
- instantiationService.invokeFunction(appendToCache, requestContext, processedChoice);
240
- }
241
- })();
242
- if (runtimeMode.isRunningInTest()) {
243
- await cacheDone;
244
- }
245
- if (processedFirstChoice) {
246
- // Because we ask the server to stop at \n above, we don't need to force single line here
247
- return {
248
- type: 'success',
249
- value: [makeGhostAPIChoice(processedFirstChoice, { forceSingleLine: false }), cacheDone],
250
- telemetryData: (0, telemetry_3.mkBasicResultTelemetry)(baseTelemetryData),
251
- telemetryBlob: baseTelemetryData,
252
- resultType: ResultType.Network,
253
- };
254
- }
255
- else {
256
- return {
257
- type: 'empty',
258
- reason: 'got undefined processedFirstChoice',
259
- telemetryData: (0, telemetry_3.mkBasicResultTelemetry)(baseTelemetryData),
260
- };
261
- }
262
- });
263
- }
264
- /** Requests new completion from OpenAI, should be called if and only if we are in the servers-side termination mode, and it's follow-up cycling request
265
- * It returns all requested completions
266
- * Copies from the base telemetry data are used as the basis for each choice's telemetry.
267
- */
268
- async function getAllCompletionsFromNetwork(accessor, requestContext, baseTelemetryData, cancellationToken, finishedCb) {
269
- const logTarget = accessor.get(logger_1.ICompletionsLogTargetService);
270
- const instantiationService = accessor.get(instantiation_1.IInstantiationService);
271
- return genericGetCompletionsFromNetwork(accessor, requestContext, baseTelemetryData, cancellationToken, finishedCb, 'all completions', async (requestStart, processingTime, choicesStream) => {
272
- const apiChoices = [];
273
- for await (const choice of choicesStream) {
274
- if (cancellationToken?.isCancellationRequested) {
275
- ghostTextLogger.debug(logTarget, 'Cancelled after awaiting choices iterator');
276
- return {
277
- type: 'canceled',
278
- reason: 'after awaiting choices iterator',
279
- telemetryData: (0, telemetry_3.mkCanceledResultTelemetry)(baseTelemetryData),
280
- };
281
- }
282
- const processedChoice = postProcessChoices(choice, requestContext, apiChoices);
283
- if (!processedChoice) {
284
- continue;
285
- }
286
- apiChoices.push(processedChoice);
287
- }
288
- //Append results to current completions cache, and network cache
289
- if (apiChoices.length > 0) {
290
- for (const choice of apiChoices) {
291
- instantiationService.invokeFunction(appendToCache, requestContext, choice);
292
- }
293
- instantiationService.invokeFunction(telemetryPerformance, 'cyclingPerformance', apiChoices[0], requestStart, processingTime);
294
- }
295
- return {
296
- type: 'success',
297
- value: [apiChoices, Promise.resolve()],
298
- telemetryData: (0, telemetry_3.mkBasicResultTelemetry)(baseTelemetryData),
299
- telemetryBlob: baseTelemetryData,
300
- resultType: ResultType.Cycling,
301
- };
302
- });
303
- }
304
327
  function makeGhostAPIChoice(choice, options) {
305
328
  const ghostChoice = { ...choice };
306
329
  if (options.forceSingleLine) {
@@ -416,12 +439,13 @@ function buildFinishedCallback(accessor, blockMode, document, position, position
416
439
  const lookAhead = positionType === blockTrimmer_1.BlockPositionType.EmptyBlock || positionType === blockTrimmer_1.BlockPositionType.BlockEnd
417
440
  ? featuresService.longLookaheadSize(telemetryData)
418
441
  : featuresService.shortLookaheadSize(telemetryData);
442
+ const completionsCacheService = accessor.get(completionsCache_1.ICompletionsCacheService);
419
443
  const finishedCb = instantiationService.createInstance(streamedCompletionSplitter_1.StreamedCompletionSplitter, prefix, document.detectedLanguageId, false, lookAhead, (extraPrefix, item) => {
420
444
  const cacheContext = {
421
445
  prefix: prefix + extraPrefix,
422
446
  prompt: { ...prompt, prefix: prompt.prefix + extraPrefix },
423
447
  };
424
- instantiationService.invokeFunction(appendToCache, cacheContext, item);
448
+ appendToCache(completionsCacheService, cacheContext, item);
425
449
  }).getFinishedCallback();
426
450
  return {
427
451
  finishedCb,
@@ -446,7 +470,7 @@ function getRemainingDebounceMs(accessor, opts, telemetry) {
446
470
  const elapsed = (0, telemetry_2.now)() - telemetry.issuedTime;
447
471
  return Math.max(0, debounce - elapsed);
448
472
  }
449
- function inlineCompletionRequestCancelled(currentGhostText, requestId, cancellationToken) {
473
+ function isCompletionRequestCancelled(currentGhostText, requestId, cancellationToken) {
450
474
  return cancellationToken?.isCancellationRequested || requestId !== currentGhostText.currentRequestId;
451
475
  }
452
476
  async function getGhostTextWithoutAbortHandling(accessor, completionState, ourRequestId, preIssuedTelemetryDataWithExp, cancellationToken, options) {
@@ -465,7 +489,7 @@ async function getGhostTextWithoutAbortHandling(accessor, completionState, ourRe
465
489
  const logTarget = accessor.get(logger_1.ICompletionsLogTargetService);
466
490
  const currentGhostText = accessor.get(current_1.ICompletionsCurrentGhostText);
467
491
  const statusReporter = accessor.get(progress_1.ICompletionsStatusReporter);
468
- if (inlineCompletionRequestCancelled(currentGhostText, ourRequestId, cancellationToken)) {
492
+ if (isCompletionRequestCancelled(currentGhostText, ourRequestId, cancellationToken)) {
469
493
  return {
470
494
  type: 'abortedBeforeIssued',
471
495
  reason: 'cancelled before extractPrompt',
@@ -540,7 +564,7 @@ async function getGhostTextWithoutAbortHandling(accessor, completionState, ourRe
540
564
  if (debounce > 0) {
541
565
  ghostTextLogger.debug(logTarget, `Debouncing ghost text request for ${debounce}ms`);
542
566
  await (0, async_1.delay)(debounce);
543
- if (inlineCompletionRequestCancelled(currentGhostText, ourRequestId, cancellationToken)) {
567
+ if (isCompletionRequestCancelled(currentGhostText, ourRequestId, cancellationToken)) {
544
568
  return {
545
569
  type: 'abortedBeforeIssued',
546
570
  reason: 'cancelled after debounce',
@@ -594,7 +618,7 @@ async function getGhostTextWithoutAbortHandling(accessor, completionState, ourRe
594
618
  const trimmedChoice = makeGhostAPIChoice(choice[0], { forceSingleLine });
595
619
  choices = [[trimmedChoice], ResultType.Async];
596
620
  }
597
- if (inlineCompletionRequestCancelled(currentGhostText, ourRequestId, cancellationToken)) {
621
+ if (isCompletionRequestCancelled(currentGhostText, ourRequestId, cancellationToken)) {
598
622
  ghostTextLogger.debug(logTarget, 'Cancelled before requesting a new completion');
599
623
  return {
600
624
  type: 'abortedBeforeIssued',
@@ -627,8 +651,9 @@ async function getGhostTextWithoutAbortHandling(accessor, completionState, ourRe
627
651
  }
628
652
  else {
629
653
  // No local choices, go to network
654
+ const completionsFromNetwork = instantiationService.createInstance(CompletionsFromNetwork);
630
655
  if (ghostTextOptions.isCycling) {
631
- const networkChoices = await instantiationService.invokeFunction(getAllCompletionsFromNetwork, requestContext, telemetryData, cancellationToken, ghostTextStrategy.finishedCb);
656
+ const networkChoices = await completionsFromNetwork.getAllCompletionsFromNetwork(requestContext, telemetryData, cancellationToken, ghostTextStrategy.finishedCb);
632
657
  // TODO: if we already had some choices cached from the initial non-cycling request,
633
658
  // and then the cycling request returns no results for some reason, we need to still
634
659
  // return the original choices to the editor to avoid the ghost text disappearing completely.
@@ -663,7 +688,7 @@ async function getGhostTextWithoutAbortHandling(accessor, completionState, ourRe
663
688
  return ghostTextStrategy.finishedCb(text, delta);
664
689
  };
665
690
  const asyncCancellationTokenSource = new src_1.CancellationTokenSource();
666
- const requestPromise = instantiationService.invokeFunction(getCompletionsFromNetwork, requestContext, telemetryData, asyncCancellationTokenSource.token, finishedCb);
691
+ const requestPromise = completionsFromNetwork.getCompletionsFromNetwork(requestContext, telemetryData, asyncCancellationTokenSource.token, finishedCb);
667
692
  void asyncCompletionManager.queueCompletionRequest(ourRequestId, prefix, prompt.prompt, asyncCancellationTokenSource, requestPromise);
668
693
  const c = await asyncCompletionManager.getFirstMatchingRequest(ourRequestId, prefix, prompt.prompt, ghostTextOptions.isSpeculative);
669
694
  if (c === undefined) {
@@ -698,7 +723,7 @@ async function getGhostTextWithoutAbortHandling(accessor, completionState, ourRe
698
723
  if (resultType !== ResultType.TypingAsSuggested && !ghostTextOptions.isCycling && remainingDelay > 0) {
699
724
  ghostTextLogger.debug(logTarget, `Waiting ${remainingDelay}ms before returning completion`);
700
725
  await (0, async_1.delay)(remainingDelay);
701
- if (inlineCompletionRequestCancelled(currentGhostText, ourRequestId, cancellationToken)) {
726
+ if (isCompletionRequestCancelled(currentGhostText, ourRequestId, cancellationToken)) {
702
727
  ghostTextLogger.debug(logTarget, 'Cancelled after completions delay');
703
728
  return {
704
729
  type: 'canceled',
@@ -731,7 +756,7 @@ async function getGhostTextWithoutAbortHandling(accessor, completionState, ourRe
731
756
  // If reading from the cache or async, capture the look back offset used
732
757
  telemetryData.measurements.foundOffset = results?.[0]?.telemetry?.measurements?.foundOffset ?? -1;
733
758
  ghostTextLogger.debug(logTarget, `Produced ${results.length} results from ${(0, telemetry_3.resultTypeToString)(resultType)} at ${telemetryData.measurements.foundOffset} offset`);
734
- if (inlineCompletionRequestCancelled(currentGhostText, ourRequestId, cancellationToken)) {
759
+ if (isCompletionRequestCancelled(currentGhostText, ourRequestId, cancellationToken)) {
735
760
  return {
736
761
  type: 'canceled',
737
762
  reason: 'after post processing completions',
@@ -925,8 +950,8 @@ async function shouldRequestMultiline(accessor, blockMode, document, position, i
925
950
  return { requestMultiline: false };
926
951
  }
927
952
  /** Appends completions to existing entry in cache or creates new entry. */
928
- function appendToCache(accessor, requestContext, choice) {
929
- accessor.get(completionsCache_1.ICompletionsCacheService).append(requestContext.prefix, requestContext.prompt.suffix, choice);
953
+ function appendToCache(competionsCacheService, requestContext, choice) {
954
+ competionsCacheService.append(requestContext.prefix, requestContext.prompt.suffix, choice);
930
955
  }
931
956
  function adjustLeadingWhitespace(index, text, ws) {
932
957
  if (ws.length > 0) {