@mast-ai/google-genai 0.3.0 → 0.5.0

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.
@@ -1,3 +1,4 @@
1
+ import type { Tool } from '@google/genai';
1
2
  import type { LlmAdapter, AdapterRequest, AdapterResponse, AdapterStreamChunk } from '@mast-ai/core';
2
3
  /** Token-usage statistics reported by the Gemini API. */
3
4
  export interface UsageMetadata {
@@ -15,12 +16,17 @@ export declare class GoogleGenAIAdapter implements LlmAdapter {
15
16
  private client;
16
17
  private modelName;
17
18
  private onUsageUpdate?;
19
+ private nativeTools?;
18
20
  /**
19
21
  * @param apiKey - Google AI API key.
20
22
  * @param modelName - Gemini model identifier (defaults to `"gemini-3.1-flash-lite-preview"`).
21
23
  * @param onUsageUpdate - Optional callback invoked with token-usage data after each response.
24
+ * @param nativeTools - Optional Gemini built-in tools (e.g. `{ googleSearch: {} }`,
25
+ * `{ codeExecution: {} }`, `{ urlContext: {} }`) that are appended to the tools array on
26
+ * every request alongside any function declarations from the registry.
22
27
  */
23
- constructor(apiKey: string, modelName?: string, onUsageUpdate?: (usage: UsageMetadata) => void);
28
+ constructor(apiKey: string, modelName?: string, onUsageUpdate?: (usage: UsageMetadata) => void, nativeTools?: Tool[]);
29
+ private buildTools;
24
30
  /** {@inheritDoc LlmAdapter.generate} */
25
31
  generate(request: AdapterRequest): Promise<AdapterResponse>;
26
32
  /** {@inheritDoc LlmAdapter.generateStream} */
@@ -11,23 +11,34 @@ export class GoogleGenAIAdapter {
11
11
  client;
12
12
  modelName;
13
13
  onUsageUpdate;
14
+ nativeTools;
14
15
  /**
15
16
  * @param apiKey - Google AI API key.
16
17
  * @param modelName - Gemini model identifier (defaults to `"gemini-3.1-flash-lite-preview"`).
17
18
  * @param onUsageUpdate - Optional callback invoked with token-usage data after each response.
19
+ * @param nativeTools - Optional Gemini built-in tools (e.g. `{ googleSearch: {} }`,
20
+ * `{ codeExecution: {} }`, `{ urlContext: {} }`) that are appended to the tools array on
21
+ * every request alongside any function declarations from the registry.
18
22
  */
19
- constructor(apiKey, modelName = 'gemini-3.1-flash-lite-preview', onUsageUpdate) {
23
+ constructor(apiKey, modelName = 'gemini-3.1-flash-lite-preview', onUsageUpdate, nativeTools) {
20
24
  this.client = new GoogleGenAI({ apiKey });
21
25
  this.modelName = modelName;
22
26
  this.onUsageUpdate = onUsageUpdate;
27
+ this.nativeTools = nativeTools;
28
+ }
29
+ buildTools(request) {
30
+ const functionDeclarations = request.tools.map((t) => this.mapTool(t));
31
+ const allTools = [
32
+ ...(functionDeclarations.length > 0 ? [{ functionDeclarations }] : []),
33
+ ...(this.nativeTools ?? []),
34
+ ];
35
+ return allTools.length > 0 ? allTools : undefined;
23
36
  }
24
37
  /** {@inheritDoc LlmAdapter.generate} */
25
38
  async generate(request) {
26
39
  const contents = this.mapMessages(request.messages);
27
40
  const systemInstruction = this.mapSystemInstruction(request.system);
28
- const tools = request.tools.length > 0
29
- ? [{ functionDeclarations: request.tools.map((t) => this.mapTool(t)) }]
30
- : undefined;
41
+ const tools = this.buildTools(request);
31
42
  const outputSchema = request.outputSchema;
32
43
  const response = await this.client.models.generateContent({
33
44
  model: this.modelName,
@@ -84,9 +95,7 @@ export class GoogleGenAIAdapter {
84
95
  async *generateStream(request) {
85
96
  const contents = this.mapMessages(request.messages);
86
97
  const systemInstruction = this.mapSystemInstruction(request.system);
87
- const tools = request.tools.length > 0
88
- ? [{ functionDeclarations: request.tools.map((t) => this.mapTool(t)) }]
89
- : undefined;
98
+ const tools = this.buildTools(request);
90
99
  const responseStream = await this.client.models.generateContentStream({
91
100
  model: this.modelName,
92
101
  contents,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mast-ai/google-genai",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@google/genai": "^1.50.1",
31
- "@mast-ai/core": "^0.3.0"
31
+ "@mast-ai/core": "^0.5.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "typescript": "~6.0.2",