chrome-devtools-frontend 1.0.1603822 → 1.0.1604514
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/front_end/core/host/AidaClient.ts +39 -462
- package/front_end/core/host/AidaClientTypes.ts +470 -0
- package/front_end/core/host/AidaGcaTranslation.ts +225 -122
- package/front_end/core/host/GcaTypes.ts +107 -155
- package/front_end/core/protocol_client/DevToolsCDPConnection.ts +1 -1
- package/front_end/core/sdk/DOMModel.ts +24 -22
- package/front_end/core/sdk/EmulationModel.ts +21 -23
- package/front_end/core/sdk/HeapProfilerModel.ts +4 -7
- package/front_end/core/sdk/NetworkManager.ts +35 -28
- package/front_end/core/sdk/OverlayModel.ts +10 -10
- package/front_end/core/sdk/PreloadingModel.ts +3 -4
- package/front_end/core/sdk/ServiceWorkerManager.ts +2 -3
- package/front_end/core/sdk/SourceMapScopesInfo.ts +93 -63
- package/front_end/entrypoints/formatter_worker/FormatterWorker.ts +1 -3
- package/front_end/entrypoints/heap_snapshot_worker/AllocationProfile.ts +22 -48
- package/front_end/entrypoints/heap_snapshot_worker/HeapSnapshot.ts +1 -1
- package/front_end/generated/InspectorBackendCommands.ts +4 -0
- package/front_end/generated/SupportedCSSProperties.js +68 -2
- package/front_end/generated/protocol-mapping.d.ts +7 -0
- package/front_end/generated/protocol-proxy-api.d.ts +14 -0
- package/front_end/generated/protocol.ts +22 -0
- package/front_end/models/bindings/TempFile.ts +1 -4
- package/front_end/models/extensions/ExtensionAPI.ts +1 -1
- package/front_end/models/heap_snapshot_model/HeapSnapshotModel.ts +34 -47
- package/front_end/models/javascript_metadata/NativeFunctions.js +6 -6
- package/front_end/panels/ai_assistance/AiAssistancePanel.ts +88 -19
- package/front_end/panels/ai_assistance/components/ChatMessage.ts +14 -20
- package/front_end/panels/ai_assistance/components/ChatView.ts +3 -2
- package/front_end/panels/ai_assistance/components/WalkthroughView.ts +35 -7
- package/front_end/panels/elements/ElementsTreeElement.ts +91 -13
- package/front_end/panels/elements/elementsTreeOutline.css +18 -0
- package/front_end/panels/profiler/HeapSnapshotDataGrids.ts +15 -19
- package/front_end/panels/profiler/HeapSnapshotGridNodes.ts +4 -2
- package/front_end/panels/profiler/HeapSnapshotProxy.ts +12 -16
- package/front_end/panels/profiler/HeapSnapshotView.ts +3 -10
- package/front_end/panels/profiler/ProfilesPanel.ts +5 -7
- package/front_end/panels/sensors/SensorsView.ts +0 -2
- package/front_end/panels/timeline/TimelinePanel.ts +1 -3
- package/front_end/panels/timeline/components/LiveMetricsView.ts +35 -63
- package/front_end/panels/timeline/components/liveMetricsView.css +4 -0
- package/front_end/third_party/chromium/README.chromium +1 -1
- package/package.json +1 -1
|
@@ -2,18 +2,19 @@
|
|
|
2
2
|
// Use of this source code is governed by a BSD-style license that can be
|
|
3
3
|
// found in the LICENSE file.
|
|
4
4
|
|
|
5
|
-
import * as AIDA from './
|
|
5
|
+
import * as AIDA from './AidaClientTypes.js';
|
|
6
6
|
import * as GCA from './GcaTypes.js';
|
|
7
7
|
|
|
8
8
|
type AidaRequest = AIDA.DoConversationRequest|AIDA.CompletionRequest|AIDA.GenerateCodeRequest;
|
|
9
9
|
|
|
10
|
-
function createBaseGcaRequest(
|
|
11
|
-
|
|
10
|
+
function createBaseGcaRequest(
|
|
11
|
+
request: AidaRequest, contents: GCA.Content[], experience: string): GCA.GenerateContentRequest {
|
|
12
|
+
const gcaRequest: GCA.GenerateContentRequest = {contents, aicode: {experience}};
|
|
12
13
|
mapCommonAidaRequestFields(request, gcaRequest);
|
|
13
14
|
buildLabels(request, gcaRequest);
|
|
14
15
|
|
|
15
16
|
if ('preamble' in request && request.preamble) {
|
|
16
|
-
gcaRequest.
|
|
17
|
+
gcaRequest.systemInstruction = {
|
|
17
18
|
role: 'user',
|
|
18
19
|
parts: [{text: request.preamble}],
|
|
19
20
|
};
|
|
@@ -23,38 +24,41 @@ function createBaseGcaRequest(request: AidaRequest, contents: GCA.Content[]): GC
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export function aidaDoConversationRequestToGcaRequest(request: AIDA.DoConversationRequest): GCA.GenerateContentRequest {
|
|
26
|
-
|
|
27
|
+
try {
|
|
28
|
+
const contents: GCA.Content[] = [];
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
if (request.historical_contexts) {
|
|
31
|
+
contents.push(...(request.historical_contexts).map(convertAidaContentToGcaContent));
|
|
32
|
+
}
|
|
33
|
+
contents.push(convertAidaContentToGcaContent(request.current_message));
|
|
34
|
+
|
|
35
|
+
const gcaRequest = createBaseGcaRequest(request, contents, 'chat_console_insights');
|
|
36
|
+
|
|
37
|
+
if (request.function_declarations) {
|
|
38
|
+
gcaRequest.tools = [{
|
|
39
|
+
functionDeclarations:
|
|
40
|
+
(request.function_declarations).map(fd => ({
|
|
41
|
+
name: fd.name,
|
|
42
|
+
description: fd.description,
|
|
43
|
+
parameters: convertAidaParamToGcaSchema(fd.parameters),
|
|
44
|
+
})),
|
|
45
|
+
}];
|
|
46
|
+
}
|
|
47
|
+
AIDA.debugLog('Translation succeded:', JSON.stringify(request), JSON.stringify(gcaRequest));
|
|
48
|
+
return gcaRequest;
|
|
49
|
+
} catch (e) {
|
|
50
|
+
AIDA.debugLog('Translation error:', JSON.stringify(request), e);
|
|
51
|
+
throw e;
|
|
43
52
|
}
|
|
44
|
-
|
|
45
|
-
return gcaRequest;
|
|
46
53
|
}
|
|
47
54
|
|
|
48
55
|
function mapCommonAidaRequestFields(aidaRequest: AidaRequest, gcaRequest: GCA.GenerateContentRequest): void {
|
|
49
56
|
if (aidaRequest.options?.model_id) {
|
|
50
57
|
gcaRequest.model = aidaRequest.options.model_id;
|
|
51
58
|
}
|
|
52
|
-
if (aidaRequest.metadata.string_session_id) {
|
|
53
|
-
gcaRequest.session_id = aidaRequest.metadata.string_session_id;
|
|
54
|
-
}
|
|
55
59
|
if (aidaRequest.options?.temperature !== undefined) {
|
|
56
|
-
gcaRequest.
|
|
57
|
-
...gcaRequest.
|
|
60
|
+
gcaRequest.generationConfig = {
|
|
61
|
+
...gcaRequest.generationConfig,
|
|
58
62
|
temperature: aidaRequest.options.temperature,
|
|
59
63
|
};
|
|
60
64
|
}
|
|
@@ -62,24 +66,23 @@ function mapCommonAidaRequestFields(aidaRequest: AidaRequest, gcaRequest: GCA.Ge
|
|
|
62
66
|
|
|
63
67
|
export function gcaResponseToAidaDoConversationResponse(response: GCA.GenerateContentResponse):
|
|
64
68
|
AIDA.DoConversationResponse {
|
|
65
|
-
const candidate = response.candidates[0];
|
|
66
69
|
const functionCalls: AIDA.AidaFunctionCallResponse[] = [];
|
|
67
70
|
|
|
68
|
-
if (
|
|
69
|
-
for (const part of
|
|
70
|
-
if (part.
|
|
71
|
+
if (response.candidates?.[0].content?.parts) {
|
|
72
|
+
for (const part of response.candidates[0].content.parts) {
|
|
73
|
+
if (part.functionCall) {
|
|
71
74
|
functionCalls.push({
|
|
72
|
-
name: part.
|
|
73
|
-
args: part.
|
|
75
|
+
name: part.functionCall.name,
|
|
76
|
+
args: part.functionCall.args || {},
|
|
74
77
|
});
|
|
75
78
|
}
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
return {
|
|
80
|
-
explanation: extractTextFromGcaParts(
|
|
83
|
+
explanation: extractTextFromGcaParts(response.candidates[0].content?.parts),
|
|
81
84
|
metadata: {
|
|
82
|
-
rpcGlobalId: response.
|
|
85
|
+
rpcGlobalId: response.responseId,
|
|
83
86
|
},
|
|
84
87
|
functionCalls: functionCalls.length > 0 ?
|
|
85
88
|
(functionCalls as [AIDA.AidaFunctionCallResponse, ...AIDA.AidaFunctionCallResponse[]]) :
|
|
@@ -96,33 +99,41 @@ function extractTextFromGcaParts(parts: GCA.Part[]|undefined): string {
|
|
|
96
99
|
}
|
|
97
100
|
|
|
98
101
|
export function aidaEventToGcaTelemetryRequest(clientEvent: AIDA.AidaRegisterClientEvent): GCA.SendTelemetryRequest {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
102
|
+
try {
|
|
103
|
+
const feedbackMetrics: GCA.FeedbackMetric[] = [];
|
|
104
|
+
const responseId = String(clientEvent.corresponding_aida_rpc_global_id);
|
|
105
|
+
const eventTime = new Date().toISOString();
|
|
106
|
+
|
|
107
|
+
if (clientEvent.do_conversation_client_event) {
|
|
108
|
+
const feedback = clientEvent.do_conversation_client_event.user_feedback;
|
|
109
|
+
if (feedback.sentiment) {
|
|
110
|
+
let interaction: GCA.InteractionType = GCA.InteractionType.INTERACTION_TYPE_UNSPECIFIED;
|
|
111
|
+
if (feedback.sentiment === AIDA.Rating.POSITIVE) {
|
|
112
|
+
interaction = GCA.InteractionType.THUMBS_UP;
|
|
113
|
+
} else if (feedback.sentiment === AIDA.Rating.NEGATIVE) {
|
|
114
|
+
interaction = GCA.InteractionType.THUMBS_DOWN;
|
|
115
|
+
}
|
|
116
|
+
feedbackMetrics.push({
|
|
117
|
+
eventTime,
|
|
118
|
+
responseId,
|
|
119
|
+
suggestionInteraction: {interaction},
|
|
120
|
+
});
|
|
111
121
|
}
|
|
112
|
-
feedbackMetrics.push({
|
|
113
|
-
event_time: eventTime,
|
|
114
|
-
response_id: responseId,
|
|
115
|
-
suggestion_interaction: {interaction},
|
|
116
|
-
});
|
|
117
122
|
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
feedbackMetrics.push(
|
|
121
|
-
...convertCodeTelemetry(clientEvent.complete_code_client_event, GCA.Method.COMPLETE_CODE, responseId, eventTime));
|
|
122
|
-
feedbackMetrics.push(
|
|
123
|
-
...convertCodeTelemetry(clientEvent.generate_code_client_event, GCA.Method.GENERATE_CODE, responseId, eventTime));
|
|
124
123
|
|
|
125
|
-
|
|
124
|
+
feedbackMetrics.push(...convertCodeTelemetry(
|
|
125
|
+
clientEvent.complete_code_client_event, GCA.Method.COMPLETE_CODE, responseId, eventTime));
|
|
126
|
+
feedbackMetrics.push(...convertCodeTelemetry(
|
|
127
|
+
clientEvent.generate_code_client_event, GCA.Method.GENERATE_CODE, responseId, eventTime));
|
|
128
|
+
const gcaTelemetryRequest: GCA.SendTelemetryRequest = {
|
|
129
|
+
feedbackMetrics,
|
|
130
|
+
};
|
|
131
|
+
AIDA.debugLog('Translation succeeded:', JSON.stringify(clientEvent), JSON.stringify(gcaTelemetryRequest));
|
|
132
|
+
return gcaTelemetryRequest;
|
|
133
|
+
} catch (e) {
|
|
134
|
+
AIDA.debugLog('Translation error:', JSON.stringify(clientEvent), e);
|
|
135
|
+
throw e;
|
|
136
|
+
}
|
|
126
137
|
}
|
|
127
138
|
|
|
128
139
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
@@ -135,23 +146,23 @@ function convertCodeTelemetry(
|
|
|
135
146
|
if ('user_impression' in event && event.user_impression) {
|
|
136
147
|
const impression = event.user_impression;
|
|
137
148
|
return [{
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
149
|
+
eventTime,
|
|
150
|
+
responseId,
|
|
151
|
+
suggestionOffered: {
|
|
141
152
|
method,
|
|
142
153
|
status: GCA.SuggestionStatus.NO_ERROR,
|
|
143
|
-
|
|
154
|
+
responseLatency: `${impression.latency.duration.seconds + impression.latency.duration.nanos / 1e9}s`,
|
|
144
155
|
},
|
|
145
156
|
}];
|
|
146
157
|
}
|
|
147
158
|
if ('user_acceptance' in event && event.user_acceptance) {
|
|
148
159
|
const acceptance = event.user_acceptance;
|
|
149
160
|
return [{
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
161
|
+
eventTime,
|
|
162
|
+
responseId,
|
|
163
|
+
suggestionInteraction: {
|
|
153
164
|
interaction: GCA.InteractionType.ACCEPT,
|
|
154
|
-
|
|
165
|
+
candidateIndex: acceptance.sample.sample_id,
|
|
155
166
|
},
|
|
156
167
|
}];
|
|
157
168
|
}
|
|
@@ -160,33 +171,56 @@ function convertCodeTelemetry(
|
|
|
160
171
|
/* eslint-enable @typescript-eslint/naming-convention */
|
|
161
172
|
|
|
162
173
|
export function aidaCompletionRequestToGcaRequest(request: AIDA.CompletionRequest): GCA.GenerateContentRequest {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
174
|
+
try {
|
|
175
|
+
let additionalFiles: GCA.SourceFile[] =
|
|
176
|
+
(request.additional_files ?? []).map(f => ({
|
|
177
|
+
fileUri: f.path,
|
|
178
|
+
inclusionReason: [AidaReasonToGcaInclusionReason[f.included_reason]],
|
|
179
|
+
}));
|
|
180
|
+
|
|
181
|
+
const inEditorFile: GCA.SourceFile = inFileEditRequestToSourceFile(request);
|
|
182
|
+
if (inEditorFile) {
|
|
183
|
+
additionalFiles = [inEditorFile, ...additionalFiles];
|
|
184
|
+
}
|
|
171
185
|
|
|
172
|
-
|
|
173
|
-
gcaRequest.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
186
|
+
const gcaRequest = createBaseGcaRequest(request, [], 'complete_code');
|
|
187
|
+
gcaRequest.aicode.files = additionalFiles;
|
|
188
|
+
if (request.options?.stop_sequences) {
|
|
189
|
+
gcaRequest.generationConfig = {
|
|
190
|
+
...gcaRequest.generationConfig,
|
|
191
|
+
stopSequences: request.options.stop_sequences,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
AIDA.debugLog('Translation succeeded:', JSON.stringify(request), JSON.stringify(gcaRequest));
|
|
195
|
+
return gcaRequest;
|
|
196
|
+
} catch (e) {
|
|
197
|
+
AIDA.debugLog('Translation error:', JSON.stringify(request), e);
|
|
198
|
+
throw e;
|
|
177
199
|
}
|
|
200
|
+
}
|
|
178
201
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
202
|
+
function inFileEditRequestToSourceFile(request: AIDA.CompletionRequest): GCA.SourceFile {
|
|
203
|
+
const sourceFile: GCA.SourceFile = {
|
|
204
|
+
inclusionReason: [GCA.InclusionReason.ACTIVE],
|
|
205
|
+
fileUri: 'devtools-code-completion',
|
|
206
|
+
segments: [
|
|
207
|
+
{
|
|
208
|
+
content: request.prefix,
|
|
209
|
+
isSelected: false,
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
content: '',
|
|
213
|
+
isSelected: true, // Cursor position
|
|
214
|
+
}
|
|
215
|
+
],
|
|
216
|
+
};
|
|
217
|
+
if (request.suffix) {
|
|
218
|
+
sourceFile.segments?.push({
|
|
219
|
+
content: request.suffix,
|
|
220
|
+
isSelected: false,
|
|
221
|
+
});
|
|
187
222
|
}
|
|
188
|
-
|
|
189
|
-
return gcaRequest;
|
|
223
|
+
return sourceFile;
|
|
190
224
|
}
|
|
191
225
|
|
|
192
226
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
@@ -207,6 +241,9 @@ function buildLabels(request: AidaRequest, gcaRequest: GCA.GenerateContentReques
|
|
|
207
241
|
if ('use_case' in request && request.use_case !== undefined) {
|
|
208
242
|
labels['use_case'] = AIDA.UseCase[request.use_case];
|
|
209
243
|
}
|
|
244
|
+
if (request.metadata.string_session_id) {
|
|
245
|
+
labels['session_id'] = request.metadata.string_session_id;
|
|
246
|
+
}
|
|
210
247
|
const options = request.options as {
|
|
211
248
|
inference_language?: string,
|
|
212
249
|
expect_code_output?: boolean,
|
|
@@ -236,11 +273,18 @@ const AidaReasonToGcaInclusionReason: Record<AIDA.Reason, GCA.InclusionReason> =
|
|
|
236
273
|
};
|
|
237
274
|
|
|
238
275
|
export function gcaResponseToAidaCompletionResponse(response: GCA.GenerateContentResponse): AIDA.CompletionResponse {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
276
|
+
try {
|
|
277
|
+
const {samples, metadata} = gcaResponseToAidaSamplesAndMetadata(response);
|
|
278
|
+
const aidaResponse: AIDA.CompletionResponse = {
|
|
279
|
+
generatedSamples: samples,
|
|
280
|
+
metadata,
|
|
281
|
+
};
|
|
282
|
+
AIDA.debugLog('Translation succeeded:', JSON.stringify(response), JSON.stringify(aidaResponse));
|
|
283
|
+
return aidaResponse;
|
|
284
|
+
} catch (e) {
|
|
285
|
+
AIDA.debugLog('Translation error', JSON.stringify(response), e);
|
|
286
|
+
throw e;
|
|
287
|
+
}
|
|
244
288
|
}
|
|
245
289
|
|
|
246
290
|
function gcaResponseToAidaSamplesAndMetadata(response: GCA.GenerateContentResponse): {
|
|
@@ -248,32 +292,41 @@ function gcaResponseToAidaSamplesAndMetadata(response: GCA.GenerateContentRespon
|
|
|
248
292
|
metadata: AIDA.ResponseMetadata,
|
|
249
293
|
} {
|
|
250
294
|
return {
|
|
251
|
-
samples: response.candidates.map(gcaCandidateToAidaGenerationSample),
|
|
295
|
+
samples: (response.candidates ?? []).map(gcaCandidateToAidaGenerationSample),
|
|
252
296
|
metadata: {
|
|
253
|
-
rpcGlobalId: response.
|
|
297
|
+
rpcGlobalId: response.responseId,
|
|
254
298
|
},
|
|
255
299
|
};
|
|
256
300
|
}
|
|
257
301
|
|
|
258
302
|
export function aidaGenerateCodeRequestToGcaRequest(request: AIDA.GenerateCodeRequest): GCA.GenerateContentRequest {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
303
|
+
try {
|
|
304
|
+
const gcaRequest =
|
|
305
|
+
createBaseGcaRequest(request, [convertAidaContentToGcaContent(request.current_message)], 'generate_code');
|
|
306
|
+
if (request.context_files) {
|
|
307
|
+
gcaRequest.aicode.files = (request.context_files).map(f => ({
|
|
308
|
+
fileUri: f.path,
|
|
309
|
+
programmingLanguage: f.programming_language,
|
|
310
|
+
}));
|
|
311
|
+
}
|
|
312
|
+
AIDA.debugLog('Translation succeeded:', JSON.stringify(request), JSON.stringify(gcaRequest));
|
|
313
|
+
return gcaRequest;
|
|
314
|
+
} catch (e) {
|
|
315
|
+
AIDA.debugLog('Translation error', JSON.stringify(request), e);
|
|
316
|
+
throw e;
|
|
269
317
|
}
|
|
270
|
-
|
|
271
|
-
return gcaRequest;
|
|
272
318
|
}
|
|
273
319
|
|
|
274
320
|
export function gcaResponseToAidaGenerateCodeResponse(response: GCA.GenerateContentResponse):
|
|
275
321
|
AIDA.GenerateCodeResponse {
|
|
276
|
-
|
|
322
|
+
try {
|
|
323
|
+
const aidaResponse: AIDA.GenerateCodeResponse = gcaResponseToAidaSamplesAndMetadata(response);
|
|
324
|
+
AIDA.debugLog('Translation succeeded:', JSON.stringify(response), JSON.stringify(aidaResponse));
|
|
325
|
+
return aidaResponse;
|
|
326
|
+
} catch (e) {
|
|
327
|
+
AIDA.debugLog('translation error', JSON.stringify(response), e);
|
|
328
|
+
throw e;
|
|
329
|
+
}
|
|
277
330
|
}
|
|
278
331
|
|
|
279
332
|
function gcaCandidateToAidaGenerationSample(candidate: GCA.Candidate): AIDA.GenerationSample {
|
|
@@ -282,14 +335,14 @@ function gcaCandidateToAidaGenerationSample(candidate: GCA.Candidate): AIDA.Gene
|
|
|
282
335
|
score: 0,
|
|
283
336
|
sampleId: candidate.index,
|
|
284
337
|
};
|
|
285
|
-
if (candidate.
|
|
338
|
+
if (candidate.citationMetadata) {
|
|
286
339
|
generationSample.attributionMetadata = {
|
|
287
340
|
attributionAction: AIDA.RecitationAction.CITE,
|
|
288
|
-
citations: candidate.
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
341
|
+
citations: (candidate.citationMetadata.citations ?? []).map(c => ({
|
|
342
|
+
startIndex: c.startIndex,
|
|
343
|
+
endIndex: c.endIndex,
|
|
344
|
+
uri: c.uri,
|
|
345
|
+
})),
|
|
293
346
|
};
|
|
294
347
|
}
|
|
295
348
|
return generationSample;
|
|
@@ -305,7 +358,7 @@ function convertAidaContentToGcaContent(content: AIDA.Content): GCA.Content {
|
|
|
305
358
|
}
|
|
306
359
|
return {
|
|
307
360
|
role,
|
|
308
|
-
parts: content.parts.map(convertAidaPartToGcaPart),
|
|
361
|
+
parts: (content.parts ?? []).map(convertAidaPartToGcaPart),
|
|
309
362
|
};
|
|
310
363
|
}
|
|
311
364
|
|
|
@@ -315,7 +368,7 @@ function convertAidaPartToGcaPart(part: AIDA.Part): GCA.Part {
|
|
|
315
368
|
}
|
|
316
369
|
if ('functionCall' in part) {
|
|
317
370
|
return {
|
|
318
|
-
|
|
371
|
+
functionCall: {
|
|
319
372
|
name: part.functionCall.name,
|
|
320
373
|
args: part.functionCall.args,
|
|
321
374
|
},
|
|
@@ -334,7 +387,7 @@ function convertAidaPartToGcaPart(part: AIDA.Part): GCA.Part {
|
|
|
334
387
|
fResponse.error = part.functionResponse.response['error'];
|
|
335
388
|
}
|
|
336
389
|
return {
|
|
337
|
-
|
|
390
|
+
functionResponse: {
|
|
338
391
|
name: part.functionResponse.name,
|
|
339
392
|
response: fResponse,
|
|
340
393
|
},
|
|
@@ -342,8 +395,8 @@ function convertAidaPartToGcaPart(part: AIDA.Part): GCA.Part {
|
|
|
342
395
|
}
|
|
343
396
|
if ('inlineData' in part) {
|
|
344
397
|
return {
|
|
345
|
-
|
|
346
|
-
|
|
398
|
+
inlineData: {
|
|
399
|
+
mimeType: part.inlineData.mimeType,
|
|
347
400
|
data: part.inlineData.data,
|
|
348
401
|
},
|
|
349
402
|
};
|
|
@@ -370,8 +423,58 @@ function convertAidaParamToGcaSchema<T extends string|number|symbol = string>(pa
|
|
|
370
423
|
for (const [key, value] of Object.entries(param.properties)) {
|
|
371
424
|
schema.properties[key] = convertAidaParamToGcaSchema(value as FunctionParam);
|
|
372
425
|
}
|
|
373
|
-
schema.required = param.required.map(r => r.toString());
|
|
426
|
+
schema.required = (param.required ?? []).map(r => r.toString());
|
|
374
427
|
}
|
|
375
428
|
|
|
376
429
|
return schema;
|
|
377
430
|
}
|
|
431
|
+
|
|
432
|
+
export function gcaChunkResponseToAidaChunkResponse(response: GCA.GenerateContentResponse): AIDA.AidaChunkResponse[] {
|
|
433
|
+
try {
|
|
434
|
+
const candidate = response.candidates?.[0];
|
|
435
|
+
const parts = candidate?.content?.parts || [];
|
|
436
|
+
const metadata: AIDA.ResponseMetadata = {
|
|
437
|
+
rpcGlobalId: response.responseId,
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
if (candidate?.citationMetadata?.citations) {
|
|
441
|
+
metadata.attributionMetadata = {
|
|
442
|
+
attributionAction: AIDA.RecitationAction.CITE,
|
|
443
|
+
citations: candidate.citationMetadata.citations.map(c => ({
|
|
444
|
+
startIndex: c.startIndex,
|
|
445
|
+
endIndex: c.endIndex,
|
|
446
|
+
uri: c.uri,
|
|
447
|
+
})),
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
const chunks: AIDA.AidaChunkResponse[] = (parts).map(part => {
|
|
451
|
+
const aidaChunkResponse: AIDA.AidaChunkResponse = {metadata};
|
|
452
|
+
if (part.text) {
|
|
453
|
+
aidaChunkResponse.textChunk = {
|
|
454
|
+
text: extractTextFromGcaParts(parts),
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
if (part.functionCall) {
|
|
458
|
+
aidaChunkResponse.functionCallChunk = {
|
|
459
|
+
functionCall: {
|
|
460
|
+
name: part.functionCall.name,
|
|
461
|
+
args: part.functionCall.args || {},
|
|
462
|
+
},
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
if (part.executableCode) {
|
|
466
|
+
aidaChunkResponse.codeChunk = {
|
|
467
|
+
code: part.executableCode.code,
|
|
468
|
+
inferenceLanguage: part.executableCode.language ? AIDA.AidaInferenceLanguage.PYTHON :
|
|
469
|
+
AIDA.AidaInferenceLanguage.UNKNOWN,
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
return aidaChunkResponse;
|
|
473
|
+
});
|
|
474
|
+
AIDA.debugLog('Translation succeeded:', JSON.stringify(response), JSON.stringify(chunks));
|
|
475
|
+
return chunks;
|
|
476
|
+
} catch (e) {
|
|
477
|
+
AIDA.debugLog('Translation error', JSON.stringify(response), e);
|
|
478
|
+
throw e;
|
|
479
|
+
}
|
|
480
|
+
}
|