repoburg 1.3.136 → 1.3.138

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 (172) hide show
  1. package/CODEMAP.md +3 -11
  2. package/README.md +4 -4
  3. package/backend/.env +2 -2
  4. package/backend/CODEMAP.md +2 -3
  5. package/backend/dist/src/core-entities/llm-call-log.entity.d.ts +1 -1
  6. package/backend/dist/src/core-entities/llm-call-log.entity.js +3 -3
  7. package/backend/dist/src/core-entities/llm-call-log.entity.js.map +1 -1
  8. package/backend/dist/src/core-entities/session.entity.js +2 -2
  9. package/backend/dist/src/core-entities/session.entity.js.map +1 -1
  10. package/backend/dist/src/core-entities/system-prompt.entity.js +1 -1
  11. package/backend/dist/src/core-entities/system-prompt.entity.js.map +1 -1
  12. package/backend/dist/src/llm-call-logs/dto/llm-call-log.dto.d.ts +1 -1
  13. package/backend/dist/src/llm-call-logs/dto/llm-call-log.dto.js +1 -1
  14. package/backend/dist/src/llm-call-logs/dto/llm-call-log.dto.js.map +1 -1
  15. package/backend/dist/src/llm-call-logs/llm-call-logs.controller.js +1 -1
  16. package/backend/dist/src/llm-orchestration/action-handlers/manage-sub-agents.handler.js +1 -1
  17. package/backend/dist/src/llm-orchestration/action-handlers/overwrite-file.handler.js +1 -0
  18. package/backend/dist/src/llm-orchestration/action-handlers/overwrite-file.handler.js.map +1 -1
  19. package/backend/dist/src/llm-orchestration/action-handlers/quick-edit.handler.js +3 -0
  20. package/backend/dist/src/llm-orchestration/action-handlers/quick-edit.handler.js.map +1 -1
  21. package/backend/dist/src/llm-provider/llm-provider.interface.d.ts +3 -9
  22. package/backend/dist/src/llm-provider/llm-provider.interface.js +2 -9
  23. package/backend/dist/src/llm-provider/llm-provider.interface.js.map +1 -1
  24. package/backend/dist/src/llm-provider/llm-provider.module.js +1 -2
  25. package/backend/dist/src/llm-provider/llm-provider.module.js.map +1 -1
  26. package/backend/dist/src/llm-provider/proxy-llm.provider.d.ts +1 -3
  27. package/backend/dist/src/llm-provider/proxy-llm.provider.js +4 -12
  28. package/backend/dist/src/llm-provider/proxy-llm.provider.js.map +1 -1
  29. package/backend/dist/src/llm-responses/dto/sync-conversation.dto.js +2 -2
  30. package/backend/dist/src/llm-responses/dto/sync-conversation.dto.js.map +1 -1
  31. package/backend/dist/src/sessions/dto/session.dto.d.ts +1 -1
  32. package/backend/dist/src/sessions/dto/session.dto.js +7 -7
  33. package/backend/dist/src/sessions/dto/session.dto.js.map +1 -1
  34. package/backend/dist/src/sessions/sessions.service.js +14 -5
  35. package/backend/dist/src/sessions/sessions.service.js.map +1 -1
  36. package/backend/dist/src/sub-agents/dto/create-sub-agent.dto.js +1 -1
  37. package/backend/dist/src/sub-agents/dto/create-sub-agent.dto.js.map +1 -1
  38. package/backend/dist/src/sub-agents/dto/update-sub-agent.dto.js +1 -1
  39. package/backend/dist/src/sub-agents/dto/update-sub-agent.dto.js.map +1 -1
  40. package/backend/dist/src/sub-agents/sub-agent.entity.js +1 -1
  41. package/backend/dist/src/sub-agents/sub-agent.entity.js.map +1 -1
  42. package/backend/dist/src/system-prompts/dto/system-prompt.dto.js +2 -2
  43. package/backend/dist/src/system-prompts/dto/system-prompt.dto.js.map +1 -1
  44. package/backend/dist/tsconfig.build.tsbuildinfo +1 -1
  45. package/package.json +1 -2
  46. package/backend/dist/packages/gemini-core/examples/simple.d.ts +0 -1
  47. package/backend/dist/packages/gemini-core/examples/simple.js +0 -73
  48. package/backend/dist/packages/gemini-core/examples/simple.js.map +0 -1
  49. package/backend/dist/packages/gemini-core/index.d.ts +0 -3
  50. package/backend/dist/packages/gemini-core/index.js +0 -27
  51. package/backend/dist/packages/gemini-core/index.js.map +0 -1
  52. package/backend/dist/packages/gemini-core/src/code_assist/codeAssist.d.ts +0 -5
  53. package/backend/dist/packages/gemini-core/src/code_assist/codeAssist.js +0 -17
  54. package/backend/dist/packages/gemini-core/src/code_assist/codeAssist.js.map +0 -1
  55. package/backend/dist/packages/gemini-core/src/code_assist/converter.d.ts +0 -69
  56. package/backend/dist/packages/gemini-core/src/code_assist/converter.js +0 -129
  57. package/backend/dist/packages/gemini-core/src/code_assist/converter.js.map +0 -1
  58. package/backend/dist/packages/gemini-core/src/code_assist/oauth-credential-storage.d.ts +0 -8
  59. package/backend/dist/packages/gemini-core/src/code_assist/oauth-credential-storage.js +0 -84
  60. package/backend/dist/packages/gemini-core/src/code_assist/oauth-credential-storage.js.map +0 -1
  61. package/backend/dist/packages/gemini-core/src/code_assist/oauth2.d.ts +0 -12
  62. package/backend/dist/packages/gemini-core/src/code_assist/oauth2.js +0 -371
  63. package/backend/dist/packages/gemini-core/src/code_assist/oauth2.js.map +0 -1
  64. package/backend/dist/packages/gemini-core/src/code_assist/server.d.ts +0 -28
  65. package/backend/dist/packages/gemini-core/src/code_assist/server.js +0 -135
  66. package/backend/dist/packages/gemini-core/src/code_assist/server.js.map +0 -1
  67. package/backend/dist/packages/gemini-core/src/code_assist/setup.d.ts +0 -10
  68. package/backend/dist/packages/gemini-core/src/code_assist/setup.js +0 -94
  69. package/backend/dist/packages/gemini-core/src/code_assist/setup.js.map +0 -1
  70. package/backend/dist/packages/gemini-core/src/code_assist/types.d.ts +0 -106
  71. package/backend/dist/packages/gemini-core/src/code_assist/types.js +0 -28
  72. package/backend/dist/packages/gemini-core/src/code_assist/types.js.map +0 -1
  73. package/backend/dist/packages/gemini-core/src/config/config.d.ts +0 -22
  74. package/backend/dist/packages/gemini-core/src/config/config.js +0 -38
  75. package/backend/dist/packages/gemini-core/src/config/config.js.map +0 -1
  76. package/backend/dist/packages/gemini-core/src/config/models.d.ts +0 -6
  77. package/backend/dist/packages/gemini-core/src/config/models.js +0 -13
  78. package/backend/dist/packages/gemini-core/src/config/models.js.map +0 -1
  79. package/backend/dist/packages/gemini-core/src/config/storage.d.ts +0 -8
  80. package/backend/dist/packages/gemini-core/src/config/storage.js +0 -25
  81. package/backend/dist/packages/gemini-core/src/config/storage.js.map +0 -1
  82. package/backend/dist/packages/gemini-core/src/core/contentGenerator.d.ts +0 -23
  83. package/backend/dist/packages/gemini-core/src/core/contentGenerator.js +0 -63
  84. package/backend/dist/packages/gemini-core/src/core/contentGenerator.js.map +0 -1
  85. package/backend/dist/packages/gemini-core/src/core/geminiChat.d.ts +0 -34
  86. package/backend/dist/packages/gemini-core/src/core/geminiChat.js +0 -247
  87. package/backend/dist/packages/gemini-core/src/core/geminiChat.js.map +0 -1
  88. package/backend/dist/packages/gemini-core/src/core/geminiRequest.d.ts +0 -3
  89. package/backend/dist/packages/gemini-core/src/core/geminiRequest.js +0 -8
  90. package/backend/dist/packages/gemini-core/src/core/geminiRequest.js.map +0 -1
  91. package/backend/dist/packages/gemini-core/src/core/prompts.d.ts +0 -7
  92. package/backend/dist/packages/gemini-core/src/core/prompts.js +0 -69
  93. package/backend/dist/packages/gemini-core/src/core/prompts.js.map +0 -1
  94. package/backend/dist/packages/gemini-core/src/core/tokenLimits.d.ts +0 -5
  95. package/backend/dist/packages/gemini-core/src/core/tokenLimits.js +0 -25
  96. package/backend/dist/packages/gemini-core/src/core/tokenLimits.js.map +0 -1
  97. package/backend/dist/packages/gemini-core/src/index.d.ts +0 -18
  98. package/backend/dist/packages/gemini-core/src/index.js +0 -37
  99. package/backend/dist/packages/gemini-core/src/index.js.map +0 -1
  100. package/backend/dist/packages/gemini-core/src/mcp/token-storage/base-token-storage.d.ts +0 -14
  101. package/backend/dist/packages/gemini-core/src/mcp/token-storage/base-token-storage.js +0 -34
  102. package/backend/dist/packages/gemini-core/src/mcp/token-storage/base-token-storage.js.map +0 -1
  103. package/backend/dist/packages/gemini-core/src/mcp/token-storage/file-token-storage.d.ts +0 -19
  104. package/backend/dist/packages/gemini-core/src/mcp/token-storage/file-token-storage.js +0 -141
  105. package/backend/dist/packages/gemini-core/src/mcp/token-storage/file-token-storage.js.map +0 -1
  106. package/backend/dist/packages/gemini-core/src/mcp/token-storage/hybrid-token-storage.d.ts +0 -18
  107. package/backend/dist/packages/gemini-core/src/mcp/token-storage/hybrid-token-storage.js +0 -74
  108. package/backend/dist/packages/gemini-core/src/mcp/token-storage/hybrid-token-storage.js.map +0 -1
  109. package/backend/dist/packages/gemini-core/src/mcp/token-storage/index.d.ts +0 -6
  110. package/backend/dist/packages/gemini-core/src/mcp/token-storage/index.js +0 -24
  111. package/backend/dist/packages/gemini-core/src/mcp/token-storage/index.js.map +0 -1
  112. package/backend/dist/packages/gemini-core/src/mcp/token-storage/keychain-token-storage.d.ts +0 -26
  113. package/backend/dist/packages/gemini-core/src/mcp/token-storage/keychain-token-storage.js +0 -188
  114. package/backend/dist/packages/gemini-core/src/mcp/token-storage/keychain-token-storage.js.map +0 -1
  115. package/backend/dist/packages/gemini-core/src/mcp/token-storage/types.d.ts +0 -27
  116. package/backend/dist/packages/gemini-core/src/mcp/token-storage/types.js +0 -9
  117. package/backend/dist/packages/gemini-core/src/mcp/token-storage/types.js.map +0 -1
  118. package/backend/dist/packages/gemini-core/src/utils/errors.d.ts +0 -34
  119. package/backend/dist/packages/gemini-core/src/utils/errors.js +0 -103
  120. package/backend/dist/packages/gemini-core/src/utils/errors.js.map +0 -1
  121. package/backend/dist/packages/gemini-core/src/utils/partUtils.d.ts +0 -7
  122. package/backend/dist/packages/gemini-core/src/utils/partUtils.js +0 -108
  123. package/backend/dist/packages/gemini-core/src/utils/partUtils.js.map +0 -1
  124. package/backend/dist/packages/gemini-core/src/utils/quotaErrorDetection.d.ts +0 -16
  125. package/backend/dist/packages/gemini-core/src/utils/quotaErrorDetection.js +0 -60
  126. package/backend/dist/packages/gemini-core/src/utils/quotaErrorDetection.js.map +0 -1
  127. package/backend/dist/packages/gemini-core/src/utils/retry.d.ts +0 -14
  128. package/backend/dist/packages/gemini-core/src/utils/retry.js +0 -154
  129. package/backend/dist/packages/gemini-core/src/utils/retry.js.map +0 -1
  130. package/backend/dist/packages/gemini-core/src/utils/session.d.ts +0 -1
  131. package/backend/dist/packages/gemini-core/src/utils/session.js +0 -6
  132. package/backend/dist/packages/gemini-core/src/utils/session.js.map +0 -1
  133. package/backend/dist/packages/gemini-core/src/utils/userAccountManager.d.ts +0 -10
  134. package/backend/dist/packages/gemini-core/src/utils/userAccountManager.js +0 -106
  135. package/backend/dist/packages/gemini-core/src/utils/userAccountManager.js.map +0 -1
  136. package/backend/dist/src/gemini/gemini-llm.provider.d.ts +0 -12
  137. package/backend/dist/src/gemini/gemini-llm.provider.js +0 -126
  138. package/backend/dist/src/gemini/gemini-llm.provider.js.map +0 -1
  139. package/backend/dist/src/gemini/gemini.module.d.ts +0 -2
  140. package/backend/dist/src/gemini/gemini.module.js +0 -21
  141. package/backend/dist/src/gemini/gemini.module.js.map +0 -1
  142. package/backend/packages/gemini-core/CODEMAP.md +0 -30
  143. package/backend/packages/gemini-core/examples/simple.ts +0 -120
  144. package/backend/packages/gemini-core/index.ts +0 -15
  145. package/backend/packages/gemini-core/src/code_assist/codeAssist.ts +0 -37
  146. package/backend/packages/gemini-core/src/code_assist/converter.ts +0 -250
  147. package/backend/packages/gemini-core/src/code_assist/oauth-credential-storage.ts +0 -129
  148. package/backend/packages/gemini-core/src/code_assist/oauth2.ts +0 -541
  149. package/backend/packages/gemini-core/src/code_assist/server.ts +0 -236
  150. package/backend/packages/gemini-core/src/code_assist/setup.ts +0 -124
  151. package/backend/packages/gemini-core/src/code_assist/types.ts +0 -201
  152. package/backend/packages/gemini-core/src/config/config.ts +0 -75
  153. package/backend/packages/gemini-core/src/config/models.ts +0 -23
  154. package/backend/packages/gemini-core/src/config/storage.ts +0 -30
  155. package/backend/packages/gemini-core/src/core/contentGenerator.ts +0 -136
  156. package/backend/packages/gemini-core/src/core/geminiChat.ts +0 -385
  157. package/backend/packages/gemini-core/src/core/geminiRequest.ts +0 -19
  158. package/backend/packages/gemini-core/src/core/prompts.ts +0 -109
  159. package/backend/packages/gemini-core/src/core/tokenLimits.ts +0 -32
  160. package/backend/packages/gemini-core/src/index.ts +0 -35
  161. package/backend/packages/gemini-core/src/mcp/token-storage/base-token-storage.ts +0 -49
  162. package/backend/packages/gemini-core/src/mcp/token-storage/file-token-storage.ts +0 -184
  163. package/backend/packages/gemini-core/src/mcp/token-storage/hybrid-token-storage.ts +0 -97
  164. package/backend/packages/gemini-core/src/mcp/token-storage/index.ts +0 -14
  165. package/backend/packages/gemini-core/src/mcp/token-storage/keychain-token-storage.ts +0 -251
  166. package/backend/packages/gemini-core/src/mcp/token-storage/types.ts +0 -42
  167. package/backend/packages/gemini-core/src/utils/errors.ts +0 -112
  168. package/backend/packages/gemini-core/src/utils/partUtils.ts +0 -169
  169. package/backend/packages/gemini-core/src/utils/quotaErrorDetection.ts +0 -102
  170. package/backend/packages/gemini-core/src/utils/retry.ts +0 -265
  171. package/backend/packages/gemini-core/src/utils/session.ts +0 -9
  172. package/backend/packages/gemini-core/src/utils/userAccountManager.ts +0 -140
@@ -1,37 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import type { ContentGenerator } from '../core/contentGenerator';
8
- import { AuthType } from '../core/contentGenerator';
9
- import { getOauthClient } from './oauth2';
10
- import { setupUser } from './setup';
11
- import type { HttpOptions } from './server';
12
- import { CodeAssistServer } from './server';
13
- import type { Config } from '../config/config';
14
-
15
- export async function createCodeAssistContentGenerator(
16
- httpOptions: HttpOptions,
17
- authType: AuthType,
18
- config: Config,
19
- sessionId?: string,
20
- ): Promise<ContentGenerator> {
21
- if (
22
- authType === AuthType.LOGIN_WITH_GOOGLE ||
23
- authType === AuthType.CLOUD_SHELL
24
- ) {
25
- const authClient = await getOauthClient(authType, config);
26
- const userData = await setupUser(authClient);
27
- return new CodeAssistServer(
28
- authClient,
29
- userData.projectId,
30
- httpOptions,
31
- sessionId,
32
- userData.userTier,
33
- );
34
- }
35
-
36
- throw new Error(`Unsupported authType: ${authType}`);
37
- }
@@ -1,250 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import type {
8
- Content,
9
- ContentListUnion,
10
- ContentUnion,
11
- GenerateContentConfig,
12
- GenerateContentParameters,
13
- CountTokensParameters,
14
- CountTokensResponse,
15
- GenerationConfigRoutingConfig,
16
- MediaResolution,
17
- Candidate,
18
- ModelSelectionConfig,
19
- GenerateContentResponsePromptFeedback,
20
- GenerateContentResponseUsageMetadata,
21
- Part,
22
- SafetySetting,
23
- PartUnion,
24
- SpeechConfigUnion,
25
- ThinkingConfig,
26
- ToolListUnion,
27
- ToolConfig,
28
- } from '@google/genai';
29
- import { GenerateContentResponse } from '@google/genai';
30
-
31
- export interface CAGenerateContentRequest {
32
- model: string;
33
- project?: string;
34
- user_prompt_id?: string;
35
- request: VertexGenerateContentRequest;
36
- }
37
-
38
- interface VertexGenerateContentRequest {
39
- contents: Content[];
40
- systemInstruction?: Content;
41
- cachedContent?: string;
42
- tools?: ToolListUnion;
43
- toolConfig?: ToolConfig;
44
- labels?: Record<string, string>;
45
- safetySettings?: SafetySetting[];
46
- generationConfig?: VertexGenerationConfig;
47
- session_id?: string;
48
- }
49
-
50
- interface VertexGenerationConfig {
51
- temperature?: number;
52
- topP?: number;
53
- topK?: number;
54
- candidateCount?: number;
55
- maxOutputTokens?: number;
56
- stopSequences?: string[];
57
- responseLogprobs?: boolean;
58
- logprobs?: number;
59
- presencePenalty?: number;
60
- frequencyPenalty?: number;
61
- seed?: number;
62
- responseMimeType?: string;
63
- responseJsonSchema?: unknown;
64
- responseSchema?: unknown;
65
- routingConfig?: GenerationConfigRoutingConfig;
66
- modelSelectionConfig?: ModelSelectionConfig;
67
- responseModalities?: string[];
68
- mediaResolution?: MediaResolution;
69
- speechConfig?: SpeechConfigUnion;
70
- audioTimestamp?: boolean;
71
- thinkingConfig?: ThinkingConfig;
72
- }
73
-
74
- export interface CaGenerateContentResponse {
75
- response: VertexGenerateContentResponse;
76
- }
77
-
78
- interface VertexGenerateContentResponse {
79
- candidates: Candidate[];
80
- automaticFunctionCallingHistory?: Content[];
81
- promptFeedback?: GenerateContentResponsePromptFeedback;
82
- usageMetadata?: GenerateContentResponseUsageMetadata;
83
- modelVersion?: string;
84
- }
85
-
86
- export interface CaCountTokenRequest {
87
- request: VertexCountTokenRequest;
88
- }
89
-
90
- interface VertexCountTokenRequest {
91
- model: string;
92
- contents: Content[];
93
- }
94
-
95
- export interface CaCountTokenResponse {
96
- totalTokens: number;
97
- }
98
-
99
- export function toCountTokenRequest(
100
- req: CountTokensParameters,
101
- ): CaCountTokenRequest {
102
- return {
103
- request: {
104
- model: 'models/' + req.model,
105
- contents: toContents(req.contents),
106
- },
107
- };
108
- }
109
-
110
- export function fromCountTokenResponse(
111
- res: CaCountTokenResponse,
112
- ): CountTokensResponse {
113
- return {
114
- totalTokens: res.totalTokens,
115
- };
116
- }
117
-
118
- export function toGenerateContentRequest(
119
- req: GenerateContentParameters,
120
- userPromptId: string,
121
- project?: string,
122
- sessionId?: string,
123
- ): CAGenerateContentRequest {
124
- return {
125
- model: req.model,
126
- project,
127
- user_prompt_id: userPromptId,
128
- request: toVertexGenerateContentRequest(req, sessionId),
129
- };
130
- }
131
-
132
- export function fromGenerateContentResponse(
133
- res: CaGenerateContentResponse,
134
- ): GenerateContentResponse {
135
- const inres = res.response;
136
- const out = new GenerateContentResponse();
137
- out.candidates = inres.candidates;
138
- out.automaticFunctionCallingHistory = inres.automaticFunctionCallingHistory;
139
- out.promptFeedback = inres.promptFeedback;
140
- out.usageMetadata = inres.usageMetadata;
141
- out.modelVersion = inres.modelVersion;
142
- return out;
143
- }
144
-
145
- function toVertexGenerateContentRequest(
146
- req: GenerateContentParameters,
147
- sessionId?: string,
148
- ): VertexGenerateContentRequest {
149
- return {
150
- contents: toContents(req.contents),
151
- systemInstruction: maybeToContent(req.config?.systemInstruction),
152
- cachedContent: req.config?.cachedContent,
153
- tools: req.config?.tools,
154
- toolConfig: req.config?.toolConfig,
155
- labels: req.config?.labels,
156
- safetySettings: req.config?.safetySettings,
157
- generationConfig: toVertexGenerationConfig(req.config),
158
- session_id: sessionId,
159
- };
160
- }
161
-
162
- export function toContents(contents: ContentListUnion): Content[] {
163
- if (Array.isArray(contents)) {
164
- // it's a Content[] or a PartsUnion[]
165
- return contents.map(toContent);
166
- }
167
- // it's a Content or a PartsUnion
168
- return [toContent(contents)];
169
- }
170
-
171
- function maybeToContent(content?: ContentUnion): Content | undefined {
172
- if (!content) {
173
- return undefined;
174
- }
175
- return toContent(content);
176
- }
177
-
178
- function toContent(content: ContentUnion): Content {
179
- if (Array.isArray(content)) {
180
- // it's a PartsUnion[]
181
- return {
182
- role: 'user',
183
- parts: toParts(content),
184
- };
185
- }
186
- if (typeof content === 'string') {
187
- // it's a string
188
- return {
189
- role: 'user',
190
- parts: [{ text: content }],
191
- };
192
- }
193
- if ('parts' in content) {
194
- // it's a Content - process parts to handle thought filtering
195
- return {
196
- ...content,
197
- parts: content.parts
198
- ? toParts(content.parts.filter((p) => p != null))
199
- : [],
200
- };
201
- }
202
- // it's a Part
203
- return {
204
- role: 'user',
205
- parts: [toPart(content as Part)],
206
- };
207
- }
208
-
209
- export function toParts(parts: PartUnion[]): Part[] {
210
- return parts.map(toPart);
211
- }
212
-
213
- function toPart(part: PartUnion): Part {
214
- if (typeof part === 'string') {
215
- // it's a string
216
- return { text: part };
217
- }
218
- return part;
219
- }
220
-
221
- function toVertexGenerationConfig(
222
- config?: GenerateContentConfig,
223
- ): VertexGenerationConfig | undefined {
224
- if (!config) {
225
- return undefined;
226
- }
227
- return {
228
- temperature: config.temperature,
229
- topP: config.topP,
230
- topK: config.topK,
231
- candidateCount: config.candidateCount,
232
- maxOutputTokens: config.maxOutputTokens,
233
- stopSequences: config.stopSequences,
234
- responseLogprobs: config.responseLogprobs,
235
- logprobs: config.logprobs,
236
- presencePenalty: config.presencePenalty,
237
- frequencyPenalty: config.frequencyPenalty,
238
- seed: config.seed,
239
- responseMimeType: config.responseMimeType,
240
- responseSchema: config.responseSchema,
241
- responseJsonSchema: config.responseJsonSchema,
242
- routingConfig: config.routingConfig,
243
- modelSelectionConfig: config.modelSelectionConfig,
244
- responseModalities: config.responseModalities,
245
- mediaResolution: config.mediaResolution,
246
- speechConfig: config.speechConfig,
247
- audioTimestamp: config.audioTimestamp,
248
- thinkingConfig: config.thinkingConfig,
249
- };
250
- }
@@ -1,129 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import { type Credentials } from 'google-auth-library';
8
- import { HybridTokenStorage } from '../mcp/token-storage/hybrid-token-storage';
9
- import { OAUTH_FILE, GEMINI_DIR, Storage } from '../config/storage';
10
- import type { OAuthCredentials } from '../mcp/token-storage/types';
11
- import * as path from 'node:path';
12
- import * as os from 'node:os';
13
- import { promises as fs } from 'node:fs';
14
-
15
- const KEYCHAIN_SERVICE_NAME = 'gemini-cli-oauth';
16
- const MAIN_ACCOUNT_KEY = 'main-account';
17
-
18
- export class OAuthCredentialStorage {
19
- private static storage: HybridTokenStorage = new HybridTokenStorage(
20
- KEYCHAIN_SERVICE_NAME,
21
- );
22
-
23
- /**
24
- * Load cached OAuth credentials
25
- */
26
- static async loadCredentials(): Promise<Credentials | null> {
27
- try {
28
- const credentials = await this.storage.getCredentials(MAIN_ACCOUNT_KEY);
29
-
30
- if (credentials?.token) {
31
- const { accessToken, refreshToken, expiresAt, tokenType, scope } =
32
- credentials.token;
33
- // Convert from OAuthCredentials format to Google Credentials format
34
- const googleCreds: Credentials = {
35
- access_token: accessToken,
36
- refresh_token: refreshToken || undefined,
37
- token_type: tokenType || undefined,
38
- scope: scope || undefined,
39
- };
40
-
41
- if (expiresAt) {
42
- googleCreds.expiry_date = expiresAt;
43
- }
44
-
45
- return googleCreds;
46
- }
47
-
48
- // Fallback: Try to migrate from old file-based storage
49
- return await this.migrateFromFileStorage();
50
- } catch (error: unknown) {
51
- console.error(error);
52
- throw new Error('Failed to load OAuth credentials');
53
- }
54
- }
55
-
56
- /**
57
- * Save OAuth credentials
58
- */
59
- static async saveCredentials(credentials: Credentials): Promise<void> {
60
- if (!credentials.access_token) {
61
- throw new Error('Attempted to save credentials without an access token.');
62
- }
63
-
64
- // Convert Google Credentials to OAuthCredentials format
65
- const mcpCredentials: OAuthCredentials = {
66
- serverName: MAIN_ACCOUNT_KEY,
67
- token: {
68
- accessToken: credentials.access_token,
69
- refreshToken: credentials.refresh_token || undefined,
70
- tokenType: credentials.token_type || 'Bearer',
71
- scope: credentials.scope || undefined,
72
- expiresAt: credentials.expiry_date || undefined,
73
- },
74
- updatedAt: Date.now(),
75
- };
76
-
77
- await this.storage.setCredentials(mcpCredentials);
78
- }
79
-
80
- /**
81
- * Clear cached OAuth credentials
82
- */
83
- static async clearCredentials(): Promise<void> {
84
- try {
85
- await this.storage.deleteCredentials(MAIN_ACCOUNT_KEY);
86
-
87
- // Also try to remove the old file if it exists
88
- const oldFilePath = Storage.getOAuthCredsPath();
89
- await fs.rm(oldFilePath, { force: true }).catch(() => {});
90
- } catch (error: unknown) {
91
- console.error(error);
92
- throw new Error('Failed to clear OAuth credentials');
93
- }
94
- }
95
-
96
- /**
97
- * Migrate credentials from old file-based storage to keychain
98
- */
99
- private static async migrateFromFileStorage(): Promise<Credentials | null> {
100
- const oldFilePath = Storage.getOAuthCredsPath();
101
-
102
- let credsJson: string;
103
- try {
104
- credsJson = await fs.readFile(oldFilePath, 'utf-8');
105
- } catch (error: unknown) {
106
- if (
107
- typeof error === 'object' &&
108
- error !== null &&
109
- 'code' in error &&
110
- error.code === 'ENOENT'
111
- ) {
112
- // File doesn't exist, so no migration.
113
- return null;
114
- }
115
- // Other read errors should propagate.
116
- throw error;
117
- }
118
-
119
- const credentials = JSON.parse(credsJson) as Credentials;
120
-
121
- // Save to new storage
122
- await this.saveCredentials(credentials);
123
-
124
- // Remove old file after successful migration
125
- await fs.rm(oldFilePath, { force: true }).catch(() => {});
126
-
127
- return credentials;
128
- }
129
- }