Skip to content

Commit f6e6350

Browse files
wanlin31copybara-github
authored andcommitted
feat: internal change and update the build process
FUTURE_COPYBARA_INTEGRATE_REVIEW=#1090 from googleapis:release-please--branches--main--components--genai bbf62d2 PiperOrigin-RevId: 834454596
1 parent 38cac5b commit f6e6350

File tree

5 files changed

+77
-7
lines changed

5 files changed

+77
-7
lines changed

build_code.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
# Copyright 2025 Google LLC
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# This script is used to remove the copybara:strip_begin and copybara:strip_end
6+
# tags from the google_genai source code.
7+
#
8+
# Usage:
9+
# remove_strip_content.sh [--prod]
10+
#
11+
# Options:
12+
# --prod: Build the prod-internal build. Otherwise, the internal build will
13+
# be built.
14+
#
15+
# This script will:
16+
# 1. Backup the current source code in a temporary directory.
17+
# 2. Remove all lines between the specified tags.
18+
# 3. Restore the original source code from the backup directory.
19+
# 4. Build the prod-internal or internal build.
20+
#
21+
# This script is designed to be run as part of the build process.
22+
23+
set -euxo pipefail
24+
25+
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
26+
TARGET_DIR=${ROOT_DIR}/src
27+
BACKUP_DIR=$(mktemp -d)
28+
PROD_BUILD=false
29+
30+
function cleanup {
31+
if [[ -d "$BACKUP_DIR" ]]; then
32+
echo "Trapped exit: Restoring original source from $BACKUP_DIR..."
33+
rsync -a --delete --exclude "private" "$BACKUP_DIR/" "$TARGET_DIR/"
34+
rm -rf "$BACKUP_DIR"
35+
echo "Source restored."
36+
fi
37+
}
38+
39+
trap cleanup EXIT
40+
41+
if [[ "${1:-}" == "--prod" ]]; then
42+
PROD_BUILD=true
43+
fi
44+
45+
46+
rsync -a --exclude "private" "$TARGET_DIR/" "$BACKUP_DIR"
47+
echo "Starting recursive scrub in: $TARGET_DIR"
48+
49+
find "$TARGET_DIR" -type f -not -path '*/private/*' -print0 | \
50+
while IFS= read -r -d '' file; do
51+
sed -i '/copybara:strip_begin/,/copybara:strip_end/d' "$file"
52+
done
53+
54+
echo "Scrub complete. Ready to generate api-report."
55+
56+
if [[ "${PROD_BUILD:-}" == true ]]; then
57+
echo "Building prod-internal build."
58+
npm run build-prod-internal
59+
else
60+
echo "Building internal build."
61+
npm run build-internal
62+
fi

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
},
3939
"scripts": {
4040
"prepare": "npm run build-prod",
41-
"build": "patch-package && rollup -c && npm-run-all --parallel api-extractor:dev:* && node scripts/ignore_missing_mcp_dep.js",
42-
"build-prod": "patch-package && rollup -c && npm-run-all --parallel api-extractor:prod:* && node scripts/ignore_missing_mcp_dep.js",
41+
"build-internal": "patch-package && rollup -c && npm-run-all --parallel api-extractor:dev:* && node scripts/ignore_missing_mcp_dep.js",
42+
"build-prod-internal": "patch-package && rollup -c && npm-run-all --parallel api-extractor:prod:* && node scripts/ignore_missing_mcp_dep.js",
43+
"build": "./build_code.sh",
44+
"build-prod": "./build_code.sh --prod",
4345
"api-extractor:dev:main": "api-extractor run --local --verbose",
4446
"api-extractor:dev:node": "api-extractor run -c api-extractor.node.json --local --verbose",
4547
"api-extractor:dev:web": "api-extractor run -c api-extractor.web.json --local --verbose",

src/client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export class GoogleGenAI {
125125
private readonly apiKey?: string;
126126
public readonly vertexai: boolean;
127127
private readonly apiVersion?: string;
128+
private readonly httpOptions?: HttpOptions;
128129
readonly models: Models;
129130
readonly live: Live;
130131
readonly batches: Batches;
@@ -145,13 +146,14 @@ export class GoogleGenAI {
145146
this.vertexai = options.vertexai ?? false;
146147
this.apiKey = options.apiKey;
147148
this.apiVersion = options.apiVersion;
149+
this.httpOptions = options.httpOptions;
148150
const auth = new WebAuth(this.apiKey);
149151
this.apiClient = new ApiClient({
150152
auth: auth,
151153
apiVersion: this.apiVersion,
152154
apiKey: this.apiKey,
153155
vertexai: this.vertexai,
154-
httpOptions: options.httpOptions,
156+
httpOptions: this.httpOptions,
155157
userAgentExtra: LANGUAGE_LABEL_PREFIX + 'cross',
156158
uploader: new CrossUploader(),
157159
downloader: new CrossDownloader(),

src/node/node_client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {NodeWebSocketFactory} from '../node/_node_websocket.js';
2222
import {Operations} from '../operations.js';
2323
import {Tokens} from '../tokens.js';
2424
import {Tunings} from '../tunings.js';
25+
import {HttpOptions} from '../types.js';
2526
import {NodeUploader} from './_node_uploader.js';
2627

2728
const LANGUAGE_LABEL_PREFIX = 'gl-node/';
@@ -74,6 +75,7 @@ export class GoogleGenAI {
7475
private readonly project?: string;
7576
private readonly location?: string;
7677
private readonly apiVersion?: string;
78+
private readonly httpOptions?: HttpOptions;
7779
readonly models: Models;
7880
readonly live: Live;
7981
readonly batches: Batches;
@@ -84,7 +86,6 @@ export class GoogleGenAI {
8486
readonly authTokens: Tokens;
8587
readonly tunings: Tunings;
8688
readonly fileSearchStores: FileSearchStores;
87-
8889
constructor(options: GoogleGenAIOptions) {
8990
// Validate explicitly set initializer values.
9091
if ((options.project || options.location) && options.apiKey) {
@@ -158,6 +159,7 @@ export class GoogleGenAI {
158159
}
159160

160161
this.apiVersion = options.apiVersion;
162+
this.httpOptions = options.httpOptions;
161163
const auth = new NodeAuth({
162164
apiKey: this.apiKey,
163165
googleAuthOptions: options.googleAuthOptions,
@@ -169,7 +171,7 @@ export class GoogleGenAI {
169171
apiVersion: this.apiVersion,
170172
apiKey: this.apiKey,
171173
vertexai: this.vertexai,
172-
httpOptions: options.httpOptions,
174+
httpOptions: this.httpOptions,
173175
userAgentExtra: LANGUAGE_LABEL_PREFIX + process.version,
174176
uploader: new NodeUploader(),
175177
downloader: new NodeDownloader(),

src/web/web_client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {Models} from '../models.js';
1717
import {Operations} from '../operations.js';
1818
import {Tokens} from '../tokens.js';
1919
import {Tunings} from '../tunings.js';
20+
import {HttpOptions} from '../types.js';
2021

2122
import {BrowserDownloader} from './_browser_downloader.js';
2223
import {BrowserUploader} from './_browser_uploader.js';
@@ -66,6 +67,7 @@ export class GoogleGenAI {
6667
private readonly apiKey?: string;
6768
public readonly vertexai: boolean;
6869
private readonly apiVersion?: string;
70+
private readonly httpOptions?: HttpOptions;
6971
readonly models: Models;
7072
readonly live: Live;
7173
readonly batches: Batches;
@@ -76,7 +78,6 @@ export class GoogleGenAI {
7678
readonly authTokens: Tokens;
7779
readonly tunings: Tunings;
7880
readonly fileSearchStores: FileSearchStores;
79-
8081
constructor(options: GoogleGenAIOptions) {
8182
if (options.apiKey == null) {
8283
throw new Error('An API Key must be set when running in a browser');
@@ -106,13 +107,14 @@ export class GoogleGenAI {
106107
}
107108

108109
this.apiVersion = options.apiVersion;
110+
this.httpOptions = options.httpOptions;
109111
const auth = new WebAuth(this.apiKey);
110112
this.apiClient = new ApiClient({
111113
auth: auth,
112114
apiVersion: this.apiVersion,
113115
apiKey: this.apiKey,
114116
vertexai: this.vertexai,
115-
httpOptions: options.httpOptions,
117+
httpOptions: this.httpOptions,
116118
userAgentExtra: LANGUAGE_LABEL_PREFIX + 'web',
117119
uploader: new BrowserUploader(),
118120
downloader: new BrowserDownloader(),

0 commit comments

Comments
 (0)