blob: e85bd51eadc2a5b753959b4b223e4f274cd931a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { type PartListUnion, type Part } from '@google/genai';
/**
* Represents a request to be sent to the Gemini API.
* For now, it's an alias to PartListUnion as the primary content.
* This can be expanded later to include other request parameters.
*/
export type GeminiCodeRequest = PartListUnion;
export function partListUnionToString(value: PartListUnion): string {
if (typeof value === 'string') {
return value;
}
if (Array.isArray(value)) {
return value.map(partListUnionToString).join('');
}
// Cast to Part, assuming it might contain project-specific fields
const part = value as Part & {
videoMetadata?: unknown;
thought?: string;
codeExecutionResult?: unknown;
executableCode?: unknown;
};
if (part.videoMetadata !== undefined) {
return `[Video Metadata]`;
}
if (part.thought !== undefined) {
return `[Thought: ${part.thought}]`;
}
if (part.codeExecutionResult !== undefined) {
return `[Code Execution Result]`;
}
if (part.executableCode !== undefined) {
return `[Executable Code]`;
}
// Standard Part fields
if (part.fileData !== undefined) {
return `[File Data]`;
}
if (part.functionCall !== undefined) {
return `[Function Call: ${part.functionCall.name}]`;
}
if (part.functionResponse !== undefined) {
return `[Function Response: ${part.functionResponse.name}]`;
}
if (part.inlineData !== undefined) {
return `<${part.inlineData.mimeType}>`;
}
if (part.text !== undefined) {
return part.text;
}
return '';
}
|