google-antigravity-ai-provider 0.0.2
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/README.md +35 -0
- package/dist/convert-google-generative-ai-usage.d.ts +11 -0
- package/dist/convert-google-generative-ai-usage.d.ts.map +1 -0
- package/dist/convert-google-generative-ai-usage.js +37 -0
- package/dist/convert-json-schema-to-openapi-schema.d.ts +6 -0
- package/dist/convert-json-schema-to-openapi-schema.d.ts.map +1 -0
- package/dist/convert-json-schema-to-openapi-schema.js +108 -0
- package/dist/convert-to-google-generative-ai-messages.d.ts +7 -0
- package/dist/convert-to-google-generative-ai-messages.d.ts.map +1 -0
- package/dist/convert-to-google-generative-ai-messages.js +186 -0
- package/dist/get-model-path.d.ts +2 -0
- package/dist/get-model-path.d.ts.map +1 -0
- package/dist/get-model-path.js +3 -0
- package/dist/google-antigravity-language-model.d.ts +185 -0
- package/dist/google-antigravity-language-model.d.ts.map +1 -0
- package/dist/google-antigravity-language-model.js +784 -0
- package/dist/google-antigravity-options.d.ts +34 -0
- package/dist/google-antigravity-options.d.ts.map +1 -0
- package/dist/google-antigravity-options.js +128 -0
- package/dist/google-antigravity-provider.d.ts +75 -0
- package/dist/google-antigravity-provider.d.ts.map +1 -0
- package/dist/google-antigravity-provider.js +76 -0
- package/dist/google-error.d.ts +12 -0
- package/dist/google-error.d.ts.map +1 -0
- package/dist/google-error.js +13 -0
- package/dist/google-generative-ai-embedding-model.d.ts +21 -0
- package/dist/google-generative-ai-embedding-model.d.ts.map +1 -0
- package/dist/google-generative-ai-embedding-model.js +90 -0
- package/dist/google-generative-ai-embedding-options.d.ts +8 -0
- package/dist/google-generative-ai-embedding-options.d.ts.map +1 -0
- package/dist/google-generative-ai-embedding-options.js +33 -0
- package/dist/google-generative-ai-image-model.d.ts +31 -0
- package/dist/google-generative-ai-image-model.d.ts.map +1 -0
- package/dist/google-generative-ai-image-model.js +105 -0
- package/dist/google-generative-ai-image-settings.d.ts +8 -0
- package/dist/google-generative-ai-image-settings.d.ts.map +1 -0
- package/dist/google-generative-ai-image-settings.js +1 -0
- package/dist/google-generative-ai-prompt.d.ts +50 -0
- package/dist/google-generative-ai-prompt.d.ts.map +1 -0
- package/dist/google-generative-ai-prompt.js +1 -0
- package/dist/google-prepare-tools.d.ts +23 -0
- package/dist/google-prepare-tools.d.ts.map +1 -0
- package/dist/google-prepare-tools.js +210 -0
- package/dist/google-supported-file-url.d.ts +2 -0
- package/dist/google-supported-file-url.d.ts.map +1 -0
- package/dist/google-supported-file-url.js +13 -0
- package/dist/google-tools.d.ts +76 -0
- package/dist/google-tools.d.ts.map +1 -0
- package/dist/google-tools.js +65 -0
- package/dist/index.d.mts +334 -0
- package/dist/index.d.ts +334 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2017 -0
- package/dist/index.mjs.map +1 -0
- package/dist/internal/index.d.mts +265 -0
- package/dist/internal/index.d.ts +265 -0
- package/dist/internal/index.d.ts.map +1 -0
- package/dist/internal/index.js +2 -0
- package/dist/internal/index.js.map +1 -0
- package/dist/internal/index.mjs +1639 -0
- package/dist/internal/index.mjs.map +1 -0
- package/dist/map-google-generative-ai-finish-reason.d.ts +6 -0
- package/dist/map-google-generative-ai-finish-reason.d.ts.map +1 -0
- package/dist/map-google-generative-ai-finish-reason.js +21 -0
- package/dist/tool/code-execution.d.ts +17 -0
- package/dist/tool/code-execution.d.ts.map +1 -0
- package/dist/tool/code-execution.js +24 -0
- package/dist/tool/enterprise-web-search.d.ts +2 -0
- package/dist/tool/enterprise-web-search.d.ts.map +1 -0
- package/dist/tool/enterprise-web-search.js +7 -0
- package/dist/tool/file-search.d.ts +16 -0
- package/dist/tool/file-search.d.ts.map +1 -0
- package/dist/tool/file-search.js +32 -0
- package/dist/tool/google-maps.d.ts +2 -0
- package/dist/tool/google-maps.d.ts.map +1 -0
- package/dist/tool/google-maps.js +8 -0
- package/dist/tool/google-search.d.ts +14 -0
- package/dist/tool/google-search.d.ts.map +1 -0
- package/dist/tool/google-search.js +14 -0
- package/dist/tool/url-context.d.ts +2 -0
- package/dist/tool/url-context.d.ts.map +1 -0
- package/dist/tool/url-context.js +6 -0
- package/dist/tool/vertex-rag-store.d.ts +16 -0
- package/dist/tool/vertex-rag-store.d.ts.map +1 -0
- package/dist/tool/vertex-rag-store.js +16 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +3 -0
- package/internal.d.ts +1 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# AI SDK - Google Generative AI Provider
|
|
2
|
+
|
|
3
|
+
The **[Google Generative AI provider](https://ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai)** for the [AI SDK](https://ai-sdk.dev/docs) contains language model support for the [Google Generative AI](https://ai.google/discover/generativeai/) APIs.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
The Google Generative AI provider is available in the `@ai-sdk/google` module. You can install it with
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i @ai-sdk/google
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Provider Instance
|
|
14
|
+
|
|
15
|
+
You can import the default provider instance `google` from `@ai-sdk/google`:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { google } from '@ai-sdk/google';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { google } from '@ai-sdk/google';
|
|
25
|
+
import { generateText } from 'ai';
|
|
26
|
+
|
|
27
|
+
const { text } = await generateText({
|
|
28
|
+
model: google('gemini-1.5-pro-latest'),
|
|
29
|
+
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Documentation
|
|
34
|
+
|
|
35
|
+
Please check out the **[Google Generative AI provider documentation](https://ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai)** for more information.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LanguageModelV3Usage } from '@ai-sdk/provider';
|
|
2
|
+
export type GoogleGenerativeAIUsageMetadata = {
|
|
3
|
+
promptTokenCount?: number | null;
|
|
4
|
+
candidatesTokenCount?: number | null;
|
|
5
|
+
totalTokenCount?: number | null;
|
|
6
|
+
cachedContentTokenCount?: number | null;
|
|
7
|
+
thoughtsTokenCount?: number | null;
|
|
8
|
+
trafficType?: string | null;
|
|
9
|
+
};
|
|
10
|
+
export declare function convertGoogleGenerativeAIUsage(usage: GoogleGenerativeAIUsageMetadata | undefined | null): LanguageModelV3Usage;
|
|
11
|
+
//# sourceMappingURL=convert-google-generative-ai-usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-google-generative-ai-usage.d.ts","sourceRoot":"","sources":["../src/convert-google-generative-ai-usage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,MAAM,MAAM,+BAA+B,GAAG;IAC5C,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,+BAA+B,GAAG,SAAS,GAAG,IAAI,GACxD,oBAAoB,CAqCtB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function convertGoogleGenerativeAIUsage(usage) {
|
|
2
|
+
var _a, _b, _c, _d;
|
|
3
|
+
if (usage == null) {
|
|
4
|
+
return {
|
|
5
|
+
inputTokens: {
|
|
6
|
+
total: undefined,
|
|
7
|
+
noCache: undefined,
|
|
8
|
+
cacheRead: undefined,
|
|
9
|
+
cacheWrite: undefined,
|
|
10
|
+
},
|
|
11
|
+
outputTokens: {
|
|
12
|
+
total: undefined,
|
|
13
|
+
text: undefined,
|
|
14
|
+
reasoning: undefined,
|
|
15
|
+
},
|
|
16
|
+
raw: undefined,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const promptTokens = (_a = usage.promptTokenCount) !== null && _a !== void 0 ? _a : 0;
|
|
20
|
+
const candidatesTokens = (_b = usage.candidatesTokenCount) !== null && _b !== void 0 ? _b : 0;
|
|
21
|
+
const cachedContentTokens = (_c = usage.cachedContentTokenCount) !== null && _c !== void 0 ? _c : 0;
|
|
22
|
+
const thoughtsTokens = (_d = usage.thoughtsTokenCount) !== null && _d !== void 0 ? _d : 0;
|
|
23
|
+
return {
|
|
24
|
+
inputTokens: {
|
|
25
|
+
total: promptTokens,
|
|
26
|
+
noCache: promptTokens - cachedContentTokens,
|
|
27
|
+
cacheRead: cachedContentTokens,
|
|
28
|
+
cacheWrite: undefined,
|
|
29
|
+
},
|
|
30
|
+
outputTokens: {
|
|
31
|
+
total: candidatesTokens + thoughtsTokens,
|
|
32
|
+
text: candidatesTokens,
|
|
33
|
+
reasoning: thoughtsTokens,
|
|
34
|
+
},
|
|
35
|
+
raw: usage,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { JSONSchema7Definition } from '@ai-sdk/provider';
|
|
2
|
+
/**
|
|
3
|
+
* Converts JSON Schema 7 to OpenAPI Schema 3.0
|
|
4
|
+
*/
|
|
5
|
+
export declare function convertJSONSchemaToOpenAPISchema(jsonSchema: JSONSchema7Definition | undefined, isRoot?: boolean): unknown;
|
|
6
|
+
//# sourceMappingURL=convert-json-schema-to-openapi-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-json-schema-to-openapi-schema.d.ts","sourceRoot":"","sources":["../src/convert-json-schema-to-openapi-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;GAEG;AACH,wBAAgB,gCAAgC,CAC9C,UAAU,EAAE,qBAAqB,GAAG,SAAS,EAC7C,MAAM,UAAO,GACZ,OAAO,CA0IT"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts JSON Schema 7 to OpenAPI Schema 3.0
|
|
3
|
+
*/
|
|
4
|
+
export function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
5
|
+
// Handle empty object schemas: undefined at root, preserved when nested
|
|
6
|
+
if (jsonSchema == null) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
if (isEmptyObjectSchema(jsonSchema)) {
|
|
10
|
+
if (isRoot) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
if (typeof jsonSchema === 'object' && jsonSchema.description) {
|
|
14
|
+
return { type: 'object', description: jsonSchema.description };
|
|
15
|
+
}
|
|
16
|
+
return { type: 'object' };
|
|
17
|
+
}
|
|
18
|
+
if (typeof jsonSchema === 'boolean') {
|
|
19
|
+
return { type: 'boolean', properties: {} };
|
|
20
|
+
}
|
|
21
|
+
const { type, description, required, properties, items, allOf, anyOf, oneOf, format, const: constValue, minLength, enum: enumValues, } = jsonSchema;
|
|
22
|
+
const result = {};
|
|
23
|
+
if (description)
|
|
24
|
+
result.description = description;
|
|
25
|
+
if (required)
|
|
26
|
+
result.required = required;
|
|
27
|
+
if (format)
|
|
28
|
+
result.format = format;
|
|
29
|
+
if (constValue !== undefined) {
|
|
30
|
+
result.enum = [constValue];
|
|
31
|
+
}
|
|
32
|
+
// Handle type
|
|
33
|
+
if (type) {
|
|
34
|
+
if (Array.isArray(type)) {
|
|
35
|
+
const hasNull = type.includes('null');
|
|
36
|
+
const nonNullTypes = type.filter(t => t !== 'null');
|
|
37
|
+
if (nonNullTypes.length === 0) {
|
|
38
|
+
// Only null type
|
|
39
|
+
result.type = 'null';
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// One or more non-null types: always use anyOf
|
|
43
|
+
result.anyOf = nonNullTypes.map(t => ({ type: t }));
|
|
44
|
+
if (hasNull) {
|
|
45
|
+
result.nullable = true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
result.type = type;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Handle enum
|
|
54
|
+
if (enumValues !== undefined) {
|
|
55
|
+
result.enum = enumValues;
|
|
56
|
+
}
|
|
57
|
+
if (properties != null) {
|
|
58
|
+
result.properties = Object.entries(properties).reduce((acc, [key, value]) => {
|
|
59
|
+
acc[key] = convertJSONSchemaToOpenAPISchema(value, false);
|
|
60
|
+
return acc;
|
|
61
|
+
}, {});
|
|
62
|
+
}
|
|
63
|
+
if (items) {
|
|
64
|
+
result.items = Array.isArray(items)
|
|
65
|
+
? items.map(item => convertJSONSchemaToOpenAPISchema(item, false))
|
|
66
|
+
: convertJSONSchemaToOpenAPISchema(items, false);
|
|
67
|
+
}
|
|
68
|
+
if (allOf) {
|
|
69
|
+
result.allOf = allOf.map(item => convertJSONSchemaToOpenAPISchema(item, false));
|
|
70
|
+
}
|
|
71
|
+
if (anyOf) {
|
|
72
|
+
// Handle cases where anyOf includes a null type
|
|
73
|
+
if (anyOf.some(schema => typeof schema === 'object' && (schema === null || schema === void 0 ? void 0 : schema.type) === 'null')) {
|
|
74
|
+
const nonNullSchemas = anyOf.filter(schema => !(typeof schema === 'object' && (schema === null || schema === void 0 ? void 0 : schema.type) === 'null'));
|
|
75
|
+
if (nonNullSchemas.length === 1) {
|
|
76
|
+
// If there's only one non-null schema, convert it and make it nullable
|
|
77
|
+
const converted = convertJSONSchemaToOpenAPISchema(nonNullSchemas[0], false);
|
|
78
|
+
if (typeof converted === 'object') {
|
|
79
|
+
result.nullable = true;
|
|
80
|
+
Object.assign(result, converted);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
// If there are multiple non-null schemas, keep them in anyOf
|
|
85
|
+
result.anyOf = nonNullSchemas.map(item => convertJSONSchemaToOpenAPISchema(item, false));
|
|
86
|
+
result.nullable = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
result.anyOf = anyOf.map(item => convertJSONSchemaToOpenAPISchema(item, false));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (oneOf) {
|
|
94
|
+
result.oneOf = oneOf.map(item => convertJSONSchemaToOpenAPISchema(item, false));
|
|
95
|
+
}
|
|
96
|
+
if (minLength !== undefined) {
|
|
97
|
+
result.minLength = minLength;
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
function isEmptyObjectSchema(jsonSchema) {
|
|
102
|
+
return (jsonSchema != null &&
|
|
103
|
+
typeof jsonSchema === 'object' &&
|
|
104
|
+
jsonSchema.type === 'object' &&
|
|
105
|
+
(jsonSchema.properties == null ||
|
|
106
|
+
Object.keys(jsonSchema.properties).length === 0) &&
|
|
107
|
+
!jsonSchema.additionalProperties);
|
|
108
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LanguageModelV3Prompt } from '@ai-sdk/provider';
|
|
2
|
+
import { GoogleGenerativeAIPrompt } from './google-generative-ai-prompt';
|
|
3
|
+
export declare function convertToGoogleGenerativeAIMessages(prompt: LanguageModelV3Prompt, options?: {
|
|
4
|
+
isGemmaModel?: boolean;
|
|
5
|
+
providerOptionsName?: string;
|
|
6
|
+
}): GoogleGenerativeAIPrompt;
|
|
7
|
+
//# sourceMappingURL=convert-to-google-generative-ai-messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-to-google-generative-ai-messages.d.ts","sourceRoot":"","sources":["../src/convert-to-google-generative-ai-messages.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EAEtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAGL,wBAAwB,EACzB,MAAM,+BAA+B,CAAC;AAGvC,wBAAgB,mCAAmC,CACjD,MAAM,EAAE,qBAAqB,EAC7B,OAAO,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAC;IAAC,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAAE,GACjE,wBAAwB,CAyN1B"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { UnsupportedFunctionalityError, } from '@ai-sdk/provider';
|
|
2
|
+
import { convertToBase64 } from '@ai-sdk/provider-utils';
|
|
3
|
+
export function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
4
|
+
var _a, _b, _c;
|
|
5
|
+
const systemInstructionParts = [];
|
|
6
|
+
const contents = [];
|
|
7
|
+
let systemMessagesAllowed = true;
|
|
8
|
+
const isGemmaModel = (_a = options === null || options === void 0 ? void 0 : options.isGemmaModel) !== null && _a !== void 0 ? _a : false;
|
|
9
|
+
const providerOptionsName = (_b = options === null || options === void 0 ? void 0 : options.providerOptionsName) !== null && _b !== void 0 ? _b : 'google';
|
|
10
|
+
for (const { role, content } of prompt) {
|
|
11
|
+
switch (role) {
|
|
12
|
+
case 'system': {
|
|
13
|
+
if (!systemMessagesAllowed) {
|
|
14
|
+
throw new UnsupportedFunctionalityError({
|
|
15
|
+
functionality: 'system messages are only supported at the beginning of the conversation',
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
systemInstructionParts.push({ text: content });
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
case 'user': {
|
|
22
|
+
systemMessagesAllowed = false;
|
|
23
|
+
const parts = [];
|
|
24
|
+
for (const part of content) {
|
|
25
|
+
switch (part.type) {
|
|
26
|
+
case 'text': {
|
|
27
|
+
parts.push({ text: part.text });
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
case 'file': {
|
|
31
|
+
// default to image/jpeg for unknown image/* types
|
|
32
|
+
const mediaType = part.mediaType === 'image/*' ? 'image/jpeg' : part.mediaType;
|
|
33
|
+
parts.push(part.data instanceof URL
|
|
34
|
+
? {
|
|
35
|
+
fileData: {
|
|
36
|
+
mimeType: mediaType,
|
|
37
|
+
fileUri: part.data.toString(),
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
: {
|
|
41
|
+
inlineData: {
|
|
42
|
+
mimeType: mediaType,
|
|
43
|
+
data: convertToBase64(part.data),
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
contents.push({ role: 'user', parts });
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case 'assistant': {
|
|
54
|
+
systemMessagesAllowed = false;
|
|
55
|
+
contents.push({
|
|
56
|
+
role: 'model',
|
|
57
|
+
parts: content
|
|
58
|
+
.map(part => {
|
|
59
|
+
var _a;
|
|
60
|
+
const providerOpts = (_a = part.providerOptions) === null || _a === void 0 ? void 0 : _a[providerOptionsName];
|
|
61
|
+
const thoughtSignature = (providerOpts === null || providerOpts === void 0 ? void 0 : providerOpts.thoughtSignature) != null
|
|
62
|
+
? String(providerOpts.thoughtSignature)
|
|
63
|
+
: undefined;
|
|
64
|
+
switch (part.type) {
|
|
65
|
+
case 'text': {
|
|
66
|
+
return part.text.length === 0
|
|
67
|
+
? undefined
|
|
68
|
+
: {
|
|
69
|
+
text: part.text,
|
|
70
|
+
thoughtSignature,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
case 'reasoning': {
|
|
74
|
+
return part.text.length === 0
|
|
75
|
+
? undefined
|
|
76
|
+
: {
|
|
77
|
+
text: part.text,
|
|
78
|
+
thought: true,
|
|
79
|
+
thoughtSignature,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
case 'file': {
|
|
83
|
+
if (part.data instanceof URL) {
|
|
84
|
+
throw new UnsupportedFunctionalityError({
|
|
85
|
+
functionality: 'File data URLs in assistant messages are not supported',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
inlineData: {
|
|
90
|
+
mimeType: part.mediaType,
|
|
91
|
+
data: convertToBase64(part.data),
|
|
92
|
+
},
|
|
93
|
+
thoughtSignature,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
case 'tool-call': {
|
|
97
|
+
return {
|
|
98
|
+
functionCall: {
|
|
99
|
+
name: part.toolName,
|
|
100
|
+
args: part.input,
|
|
101
|
+
},
|
|
102
|
+
thoughtSignature,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
.filter(part => part !== undefined),
|
|
108
|
+
});
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
case 'tool': {
|
|
112
|
+
systemMessagesAllowed = false;
|
|
113
|
+
const parts = [];
|
|
114
|
+
for (const part of content) {
|
|
115
|
+
if (part.type === 'tool-approval-response') {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const output = part.output;
|
|
119
|
+
if (output.type === 'content') {
|
|
120
|
+
for (const contentPart of output.value) {
|
|
121
|
+
switch (contentPart.type) {
|
|
122
|
+
case 'text':
|
|
123
|
+
parts.push({
|
|
124
|
+
functionResponse: {
|
|
125
|
+
name: part.toolName,
|
|
126
|
+
response: {
|
|
127
|
+
name: part.toolName,
|
|
128
|
+
content: contentPart.text,
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
break;
|
|
133
|
+
case 'image-data':
|
|
134
|
+
parts.push({
|
|
135
|
+
inlineData: {
|
|
136
|
+
mimeType: contentPart.mediaType,
|
|
137
|
+
data: contentPart.data,
|
|
138
|
+
},
|
|
139
|
+
}, {
|
|
140
|
+
text: 'Tool executed successfully and returned this image as a response',
|
|
141
|
+
});
|
|
142
|
+
break;
|
|
143
|
+
default:
|
|
144
|
+
parts.push({ text: JSON.stringify(contentPart) });
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
parts.push({
|
|
151
|
+
functionResponse: {
|
|
152
|
+
name: part.toolName,
|
|
153
|
+
response: {
|
|
154
|
+
name: part.toolName,
|
|
155
|
+
content: output.type === 'execution-denied'
|
|
156
|
+
? ((_c = output.reason) !== null && _c !== void 0 ? _c : 'Tool execution denied.')
|
|
157
|
+
: output.value,
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
contents.push({
|
|
164
|
+
role: 'user',
|
|
165
|
+
parts,
|
|
166
|
+
});
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (isGemmaModel &&
|
|
172
|
+
systemInstructionParts.length > 0 &&
|
|
173
|
+
contents.length > 0 &&
|
|
174
|
+
contents[0].role === 'user') {
|
|
175
|
+
const systemText = systemInstructionParts
|
|
176
|
+
.map(part => part.text)
|
|
177
|
+
.join('\n\n');
|
|
178
|
+
contents[0].parts.unshift({ text: systemText + '\n\n' });
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
systemInstruction: systemInstructionParts.length > 0 && !isGemmaModel
|
|
182
|
+
? { parts: systemInstructionParts }
|
|
183
|
+
: undefined,
|
|
184
|
+
contents,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-model-path.d.ts","sourceRoot":"","sources":["../src/get-model-path.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEpD"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult } from '@ai-sdk/provider';
|
|
2
|
+
import { FetchFunction, InferSchema, Resolvable } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { z } from 'zod/v4';
|
|
4
|
+
import { GoogleAntigravityModelId } from './google-antigravity-options';
|
|
5
|
+
type GoogleGenerativeAIConfig = {
|
|
6
|
+
provider: string;
|
|
7
|
+
baseURL: string;
|
|
8
|
+
headers: Resolvable<Record<string, string | undefined>>;
|
|
9
|
+
fetch?: FetchFunction;
|
|
10
|
+
generateId: () => string;
|
|
11
|
+
/**
|
|
12
|
+
* The supported URLs for the model.
|
|
13
|
+
*/
|
|
14
|
+
supportedUrls?: () => LanguageModelV3['supportedUrls'];
|
|
15
|
+
};
|
|
16
|
+
export declare class GoogleAntigravityLanguageModel implements LanguageModelV3 {
|
|
17
|
+
readonly specificationVersion = "v3";
|
|
18
|
+
readonly modelId: GoogleAntigravityModelId;
|
|
19
|
+
private readonly config;
|
|
20
|
+
private readonly generateId;
|
|
21
|
+
constructor(modelId: GoogleAntigravityModelId, config: GoogleGenerativeAIConfig);
|
|
22
|
+
get provider(): string;
|
|
23
|
+
get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
|
|
24
|
+
private get isClaudeModel();
|
|
25
|
+
private getArgs;
|
|
26
|
+
doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
|
|
27
|
+
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
28
|
+
}
|
|
29
|
+
export declare const getGroundingMetadataSchema: () => z.ZodObject<{
|
|
30
|
+
webSearchQueries: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
31
|
+
retrievalQueries: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
32
|
+
searchEntryPoint: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
33
|
+
renderedContent: z.ZodString;
|
|
34
|
+
}, z.core.$strip>>>;
|
|
35
|
+
groundingChunks: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
36
|
+
web: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
37
|
+
uri: z.ZodString;
|
|
38
|
+
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
39
|
+
}, z.core.$strip>>>;
|
|
40
|
+
retrievedContext: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
41
|
+
uri: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
42
|
+
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
43
|
+
text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
44
|
+
fileSearchStore: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
45
|
+
}, z.core.$strip>>>;
|
|
46
|
+
maps: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
47
|
+
uri: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
48
|
+
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
49
|
+
text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
50
|
+
placeId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
51
|
+
}, z.core.$strip>>>;
|
|
52
|
+
}, z.core.$strip>>>>;
|
|
53
|
+
groundingSupports: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
54
|
+
segment: z.ZodObject<{
|
|
55
|
+
startIndex: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
56
|
+
endIndex: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
57
|
+
text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
segment_text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
60
|
+
groundingChunkIndices: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodNumber>>>;
|
|
61
|
+
supportChunkIndices: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodNumber>>>;
|
|
62
|
+
confidenceScores: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodNumber>>>;
|
|
63
|
+
confidenceScore: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodNumber>>>;
|
|
64
|
+
}, z.core.$strip>>>>;
|
|
65
|
+
retrievalMetadata: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodObject<{
|
|
66
|
+
webDynamicRetrievalScore: z.ZodNumber;
|
|
67
|
+
}, z.core.$strip>, z.ZodObject<{}, z.core.$strip>]>>>;
|
|
68
|
+
}, z.core.$strip>;
|
|
69
|
+
export declare const getUrlContextMetadataSchema: () => z.ZodObject<{
|
|
70
|
+
urlMetadata: z.ZodArray<z.ZodObject<{
|
|
71
|
+
retrievedUrl: z.ZodString;
|
|
72
|
+
urlRetrievalStatus: z.ZodString;
|
|
73
|
+
}, z.core.$strip>>;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
declare const responseSchema: import("@ai-sdk/provider-utils").LazySchema<{
|
|
76
|
+
candidates: {
|
|
77
|
+
content?: Record<string, never> | {
|
|
78
|
+
parts?: ({
|
|
79
|
+
functionCall: {
|
|
80
|
+
name: string;
|
|
81
|
+
args: unknown;
|
|
82
|
+
id?: string | null | undefined;
|
|
83
|
+
};
|
|
84
|
+
thoughtSignature?: string | null | undefined;
|
|
85
|
+
} | {
|
|
86
|
+
inlineData: {
|
|
87
|
+
mimeType: string;
|
|
88
|
+
data: string;
|
|
89
|
+
};
|
|
90
|
+
thoughtSignature?: string | null | undefined;
|
|
91
|
+
} | {
|
|
92
|
+
executableCode?: {
|
|
93
|
+
language: string;
|
|
94
|
+
code: string;
|
|
95
|
+
} | null | undefined;
|
|
96
|
+
codeExecutionResult?: {
|
|
97
|
+
outcome: string;
|
|
98
|
+
output: string;
|
|
99
|
+
} | null | undefined;
|
|
100
|
+
text?: string | null | undefined;
|
|
101
|
+
thought?: boolean | null | undefined;
|
|
102
|
+
thoughtSignature?: string | null | undefined;
|
|
103
|
+
})[] | null | undefined;
|
|
104
|
+
} | null | undefined;
|
|
105
|
+
finishReason?: string | null | undefined;
|
|
106
|
+
safetyRatings?: {
|
|
107
|
+
category?: string | null | undefined;
|
|
108
|
+
probability?: string | null | undefined;
|
|
109
|
+
probabilityScore?: number | null | undefined;
|
|
110
|
+
severity?: string | null | undefined;
|
|
111
|
+
severityScore?: number | null | undefined;
|
|
112
|
+
blocked?: boolean | null | undefined;
|
|
113
|
+
}[] | null | undefined;
|
|
114
|
+
groundingMetadata?: {
|
|
115
|
+
webSearchQueries?: string[] | null | undefined;
|
|
116
|
+
retrievalQueries?: string[] | null | undefined;
|
|
117
|
+
searchEntryPoint?: {
|
|
118
|
+
renderedContent: string;
|
|
119
|
+
} | null | undefined;
|
|
120
|
+
groundingChunks?: {
|
|
121
|
+
web?: {
|
|
122
|
+
uri: string;
|
|
123
|
+
title?: string | null | undefined;
|
|
124
|
+
} | null | undefined;
|
|
125
|
+
retrievedContext?: {
|
|
126
|
+
uri?: string | null | undefined;
|
|
127
|
+
title?: string | null | undefined;
|
|
128
|
+
text?: string | null | undefined;
|
|
129
|
+
fileSearchStore?: string | null | undefined;
|
|
130
|
+
} | null | undefined;
|
|
131
|
+
maps?: {
|
|
132
|
+
uri?: string | null | undefined;
|
|
133
|
+
title?: string | null | undefined;
|
|
134
|
+
text?: string | null | undefined;
|
|
135
|
+
placeId?: string | null | undefined;
|
|
136
|
+
} | null | undefined;
|
|
137
|
+
}[] | null | undefined;
|
|
138
|
+
groundingSupports?: {
|
|
139
|
+
segment: {
|
|
140
|
+
startIndex?: number | null | undefined;
|
|
141
|
+
endIndex?: number | null | undefined;
|
|
142
|
+
text?: string | null | undefined;
|
|
143
|
+
};
|
|
144
|
+
segment_text?: string | null | undefined;
|
|
145
|
+
groundingChunkIndices?: number[] | null | undefined;
|
|
146
|
+
supportChunkIndices?: number[] | null | undefined;
|
|
147
|
+
confidenceScores?: number[] | null | undefined;
|
|
148
|
+
confidenceScore?: number[] | null | undefined;
|
|
149
|
+
}[] | null | undefined;
|
|
150
|
+
retrievalMetadata?: Record<string, never> | {
|
|
151
|
+
webDynamicRetrievalScore: number;
|
|
152
|
+
} | null | undefined;
|
|
153
|
+
} | null | undefined;
|
|
154
|
+
urlContextMetadata?: {
|
|
155
|
+
urlMetadata: {
|
|
156
|
+
retrievedUrl: string;
|
|
157
|
+
urlRetrievalStatus: string;
|
|
158
|
+
}[];
|
|
159
|
+
} | null | undefined;
|
|
160
|
+
}[];
|
|
161
|
+
usageMetadata?: {
|
|
162
|
+
cachedContentTokenCount?: number | null | undefined;
|
|
163
|
+
thoughtsTokenCount?: number | null | undefined;
|
|
164
|
+
promptTokenCount?: number | null | undefined;
|
|
165
|
+
candidatesTokenCount?: number | null | undefined;
|
|
166
|
+
totalTokenCount?: number | null | undefined;
|
|
167
|
+
trafficType?: string | null | undefined;
|
|
168
|
+
} | null | undefined;
|
|
169
|
+
promptFeedback?: {
|
|
170
|
+
blockReason?: string | null | undefined;
|
|
171
|
+
safetyRatings?: {
|
|
172
|
+
category?: string | null | undefined;
|
|
173
|
+
probability?: string | null | undefined;
|
|
174
|
+
probabilityScore?: number | null | undefined;
|
|
175
|
+
severity?: string | null | undefined;
|
|
176
|
+
severityScore?: number | null | undefined;
|
|
177
|
+
blocked?: boolean | null | undefined;
|
|
178
|
+
}[] | null | undefined;
|
|
179
|
+
} | null | undefined;
|
|
180
|
+
}>;
|
|
181
|
+
export type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
|
|
182
|
+
export type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
|
|
183
|
+
export type SafetyRatingSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['safetyRatings']>[number];
|
|
184
|
+
export {};
|
|
185
|
+
//# sourceMappingURL=google-antigravity-language-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-antigravity-language-model.d.ts","sourceRoot":"","sources":["../src/google-antigravity-language-model.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,0BAA0B,EAG1B,6BAA6B,EAG7B,2BAA2B,EAG5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAIL,aAAa,EAEb,WAAW,EAKX,UAAU,EAGX,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAS3B,OAAO,EACL,wBAAwB,EAEzB,MAAM,8BAA8B,CAAC;AAKtC,KAAK,wBAAwB,GAAG;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IACxD,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,UAAU,EAAE,MAAM,MAAM,CAAC;IAEzB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,eAAe,CAAC,eAAe,CAAC,CAAC;CACxD,CAAC;AAEF,qBAAa,8BAA+B,YAAW,eAAe;IACpE,QAAQ,CAAC,oBAAoB,QAAQ;IAErC,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAC;IAE3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2B;IAClD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;gBAGxC,OAAO,EAAE,wBAAwB,EACjC,MAAM,EAAE,wBAAwB;IAOlC,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,IAAI,aAAa,qEAEhB;IAED,OAAO,KAAK,aAAa,GAExB;YAEa,OAAO;IA6Hf,UAAU,CACd,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,6BAA6B,CAAC;IAkJnC,QAAQ,CACZ,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,2BAA2B,CAAC;CAgUxC;AA4ID,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsDnC,CAAC;AAmEL,eAAO,MAAM,2BAA2B;;;;;iBAQpC,CAAC;AAEL,QAAA,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqBnB,CAAC;AAKF,MAAM,MAAM,uBAAuB,GAAG,WAAW,CAC/C,WAAW,CAAC,OAAO,cAAc,CAAC,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,mBAAmB,CAAC,CAC9E,CAAC;AAMF,MAAM,MAAM,wBAAwB,GAAG,WAAW,CAChD,WAAW,CAAC,OAAO,cAAc,CAAC,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,oBAAoB,CAAC,CAC/E,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAC1C,WAAW,CAAC,OAAO,cAAc,CAAC,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAC1E,CAAC,MAAM,CAAC,CAAC"}
|