@aigne/gemini 1.74.0-beta → 1.74.0-beta.10

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.
Files changed (38) hide show
  1. package/README.md +4 -4
  2. package/dist/gemini-chat-model.cjs +19 -19
  3. package/dist/gemini-chat-model.d.cts +10 -43
  4. package/dist/gemini-chat-model.d.cts.map +1 -1
  5. package/dist/gemini-chat-model.d.mts +10 -43
  6. package/dist/gemini-chat-model.d.mts.map +1 -1
  7. package/dist/gemini-chat-model.mjs +6 -6
  8. package/dist/gemini-chat-model.mjs.map +1 -1
  9. package/dist/gemini-embedding-model.cjs +65 -0
  10. package/dist/gemini-embedding-model.d.cts +28 -0
  11. package/dist/gemini-embedding-model.d.cts.map +1 -0
  12. package/dist/gemini-embedding-model.d.mts +28 -0
  13. package/dist/gemini-embedding-model.d.mts.map +1 -0
  14. package/dist/gemini-embedding-model.mjs +66 -0
  15. package/dist/gemini-embedding-model.mjs.map +1 -0
  16. package/dist/gemini-image-model.cjs +10 -10
  17. package/dist/gemini-image-model.d.cts +6 -6
  18. package/dist/gemini-image-model.d.cts.map +1 -1
  19. package/dist/gemini-image-model.d.mts +6 -6
  20. package/dist/gemini-image-model.d.mts.map +1 -1
  21. package/dist/gemini-image-model.mjs +2 -2
  22. package/dist/gemini-image-model.mjs.map +1 -1
  23. package/dist/gemini-video-model.cjs +18 -18
  24. package/dist/gemini-video-model.d.cts +53 -53
  25. package/dist/gemini-video-model.d.cts.map +1 -1
  26. package/dist/gemini-video-model.d.mts +53 -53
  27. package/dist/gemini-video-model.d.mts.map +1 -1
  28. package/dist/gemini-video-model.mjs +6 -6
  29. package/dist/gemini-video-model.mjs.map +1 -1
  30. package/dist/index.cjs +2 -0
  31. package/dist/index.d.cts +2 -1
  32. package/dist/index.d.mts +2 -1
  33. package/dist/index.mjs +2 -1
  34. package/dist/utils.cjs +2 -2
  35. package/dist/utils.mjs +1 -1
  36. package/dist/utils.mjs.map +1 -1
  37. package/package.json +3 -6
  38. package/LICENSE.md +0 -93
@@ -1,4 +1,4 @@
1
- import { AgentInvokeOptions, FileUnionContent, VideoModel, VideoModelInput, VideoModelOptions, VideoModelOutput } from "@aigne/core";
1
+ import { FileUnionContent, ModelInvokeOptions, VideoModel, VideoModelInput, VideoModelOptions, VideoModelOutput } from "@aigne/model-base";
2
2
  import { GoogleGenAI } from "@google/genai";
3
3
 
4
4
  //#region src/gemini-video-model.d.ts
@@ -7,47 +7,47 @@ import { GoogleGenAI } from "@google/genai";
7
7
  */
8
8
  interface GeminiVideoModelInput extends VideoModelInput {
9
9
  /**
10
- * Text describing content that should not appear in the video
11
- */
10
+ * Text describing content that should not appear in the video
11
+ */
12
12
  negativePrompt?: string;
13
13
  /**
14
- * Aspect ratio of the video
15
- *
16
- * Veo 3.1: "16:9" (default, 720p and 1080p), "9:16" (720p and 1080p)
17
- * Veo 3: "16:9" (default, 720p and 1080p), "9:16" (720p and 1080p)
18
- */
14
+ * Aspect ratio of the video
15
+ *
16
+ * Veo 3.1: "16:9" (default, 720p and 1080p), "9:16" (720p and 1080p)
17
+ * Veo 3: "16:9" (default, 720p and 1080p), "9:16" (720p and 1080p)
18
+ */
19
19
  aspectRatio?: "16:9" | "9:16";
20
20
  /**
21
- * Resolution of the video
22
- *
23
- * Veo 3.1: "720p" (default), "1080p" (only supports 8 seconds duration)
24
- * Veo 3: "720p" (default), "1080p" (16:9 only)
25
- */
21
+ * Resolution of the video
22
+ *
23
+ * Veo 3.1: "720p" (default), "1080p" (only supports 8 seconds duration)
24
+ * Veo 3: "720p" (default), "1080p" (16:9 only)
25
+ */
26
26
  size?: "720p" | "1080p";
27
27
  /**
28
- * Duration of the generated video in seconds
29
- *
30
- * Veo 3.1: "4", "6", "8"
31
- * Veo 3: "4", "6", "8"
32
- */
28
+ * Duration of the generated video in seconds
29
+ *
30
+ * Veo 3.1: "4", "6", "8"
31
+ * Veo 3: "4", "6", "8"
32
+ */
33
33
  seconds?: "4" | "6" | "8";
34
34
  /**
35
- * Control person generation
36
- *
37
- * For text-to-video and image-to-video:
38
- * - Veo 3.1: "allow_all" for image-to-video, frame interpolation and reference images; only "allow_adult" for text-to-video
39
- * - Veo 3: "allow_all" for image-to-video; only "allow_adult" for text-to-video
40
- * - Veo 2: "allow_all", "allow_adult", "dont_allow"
41
- */
35
+ * Control person generation
36
+ *
37
+ * For text-to-video and image-to-video:
38
+ * - Veo 3.1: "allow_all" for image-to-video, frame interpolation and reference images; only "allow_adult" for text-to-video
39
+ * - Veo 3: "allow_all" for image-to-video; only "allow_adult" for text-to-video
40
+ * - Veo 2: "allow_all", "allow_adult", "dont_allow"
41
+ */
42
42
  personGeneration?: string;
43
43
  /**
44
- * Last frame for video generation (frame interpolation)
45
- */
44
+ * Last frame for video generation (frame interpolation)
45
+ */
46
46
  lastFrame?: FileUnionContent;
47
47
  /**
48
- * Reference images for video generation
49
- * Only supported in Veo 3.1 models
50
- */
48
+ * Reference images for video generation
49
+ * Only supported in Veo 3.1 models
50
+ */
51
51
  referenceImages?: FileUnionContent[];
52
52
  }
53
53
  /**
@@ -59,44 +59,44 @@ interface GeminiVideoModelOutput extends VideoModelOutput {}
59
59
  */
60
60
  interface GeminiVideoModelOptions extends VideoModelOptions<GeminiVideoModelInput, GeminiVideoModelOutput> {
61
61
  /**
62
- * API key for Gemini API
63
- *
64
- * If not provided, will look for GEMINI_API_KEY in environment variables
65
- */
62
+ * API key for Gemini API
63
+ *
64
+ * If not provided, will look for GEMINI_API_KEY in environment variables
65
+ */
66
66
  apiKey?: string;
67
67
  /**
68
- * Base URL for Gemini API
69
- *
70
- * Useful for proxies or alternate endpoints
71
- */
68
+ * Base URL for Gemini API
69
+ *
70
+ * Useful for proxies or alternate endpoints
71
+ */
72
72
  baseURL?: string;
73
73
  /**
74
- * Gemini model to use
75
- *
76
- * Defaults to 'veo-3.1-generate-preview'
77
- */
74
+ * Gemini model to use
75
+ *
76
+ * Defaults to 'veo-3.1-generate-preview'
77
+ */
78
78
  model?: string;
79
79
  /**
80
- * Additional model options to control behavior
81
- */
80
+ * Additional model options to control behavior
81
+ */
82
82
  modelOptions?: Omit<Partial<GeminiVideoModelInput>, "model">;
83
83
  /**
84
- * Client options for Gemini API
85
- */
84
+ * Client options for Gemini API
85
+ */
86
86
  clientOptions?: Record<string, any>;
87
87
  /**
88
- * Polling interval in milliseconds for checking video generation status
89
- *
90
- * Defaults to 10000ms (10 seconds)
91
- */
88
+ * Polling interval in milliseconds for checking video generation status
89
+ *
90
+ * Defaults to 10000ms (10 seconds)
91
+ */
92
92
  pollingInterval?: number;
93
93
  }
94
94
  declare class GeminiVideoModel extends VideoModel<GeminiVideoModelInput, GeminiVideoModelOutput> {
95
95
  options?: GeminiVideoModelOptions | undefined;
96
96
  constructor(options?: GeminiVideoModelOptions | undefined);
97
97
  /**
98
- * @hidden
99
- */
98
+ * @hidden
99
+ */
100
100
  protected _client?: GoogleGenAI;
101
101
  protected apiKeyEnvName: string;
102
102
  get client(): GoogleGenAI;
@@ -110,7 +110,7 @@ declare class GeminiVideoModel extends VideoModel<GeminiVideoModelInput, GeminiV
110
110
  uri?: string;
111
111
  videoBytes?: any;
112
112
  }): Promise<string>;
113
- process(input: GeminiVideoModelInput, options: AgentInvokeOptions): Promise<GeminiVideoModelOutput>;
113
+ process(input: GeminiVideoModelInput, _options: ModelInvokeOptions): Promise<GeminiVideoModelOutput>;
114
114
  }
115
115
  //#endregion
116
116
  export { GeminiVideoModel, GeminiVideoModelInput, GeminiVideoModelOptions, GeminiVideoModelOutput };
@@ -1 +1 @@
1
- {"version":3,"file":"gemini-video-model.d.mts","names":[],"sources":["../src/gemini-video-model.ts"],"mappings":";;;;;AAqBA;;UAAiB,qBAAA,SAA8B,eAAA;EAAA;;AAuD/C;EAvD+C,cAAA;EAAA;;AAuD/C;AAKA;;;EA5D+C,WAAA;EAAA;;AAuD/C;AAKA;;;EA5D+C,IAAA;EAAA;;AAuD/C;AAKA;;;EA5D+C,OAAA;EAAA;;AAuD/C;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EAzBA,eAAA,GAAkB,gBAAA;AAAA;;;;UAMH,sBAAA,SAA+B,gBAAA;AAiEhD;;;AAAA,UA5DiB,uBAAA,SACP,iBAAA,CAAkB,qBAAA,EAAuB,sBAAA;EA2DqB;;;;;EArDtE,MAAA;EA0FgB;;;;;EAnFhB,OAAA;EA0GG;;;;;EAnGH,KAAA;EAuCsE;;;EAlCtE,YAAA,GAAe,IAAA,CAAK,OAAA,CAAQ,qBAAA;EAmCU;;;EA9BtC,aAAA,GAAgB,MAAA;EA6CN;;;;;EAtCV,eAAA;AAAA;AAAA,cAsBW,gBAAA,SAAyB,UAAA,CAAW,qBAAA,EAAuB,sBAAA;EAC1C,OAAA,GAAU,uBAAA;cAAV,OAAA,GAAU,uBAAA;EAoCtB;;;EAAA,UAvBN,OAAA,GAAU,WAAA;EAAA,UAEV,aAAA;EAAA,IAEN,MAAA,CAAA,GAAM,WAAA;EAAA,IAWG,UAAA,CAAA;;;;;MAQT,YAAA,CAAA,GAAY,IAAA,CAAA,OAAA,CAAA,qBAAA;EAIV,cAAA,CACJ,GAAA,UACA,OAAA,UACA,SAAA;IAAa,GAAA;IAAc,UAAA;EAAA,IAC1B,OAAA;EAYY,OAAA,CACb,KAAA,EAAO,qBAAA,EACP,QAAA,EAAU,kBAAA,GACT,OAAA,CAAQ,sBAAA;AAAA"}
@@ -1,8 +1,8 @@
1
1
  import { waitFileSizeStable } from "./utils.mjs";
2
- import { VideoModel, fileUnionContentSchema, videoModelInputSchema } from "@aigne/core";
3
- import { logger } from "@aigne/core/utils/logger";
4
- import { checkArguments } from "@aigne/core/utils/type-utils";
5
- import { nodejs } from "@aigne/utils/nodejs";
2
+ import { VideoModel, fileUnionContentSchema, videoModelInputSchema } from "@aigne/model-base";
3
+ import { logger } from "@aigne/model-base/utils/logger";
4
+ import { nodejs } from "@aigne/model-base/utils/nodejs";
5
+ import { checkArguments } from "@aigne/model-base/utils/type-utils";
6
6
  import { GoogleGenAI } from "@google/genai";
7
7
  import { z } from "zod";
8
8
 
@@ -75,7 +75,7 @@ var GeminiVideoModel = class extends VideoModel {
75
75
  await waitFileSizeStable(localPath);
76
76
  return (await nodejs.fs.readFile(localPath)).toString("base64");
77
77
  }
78
- async process(input, options) {
78
+ async process(input, _options) {
79
79
  const model = input.model ?? input.modelOptions?.model ?? this.credential.model;
80
80
  const mergedInput = {
81
81
  ...this.modelOptions,
@@ -124,7 +124,7 @@ var GeminiVideoModel = class extends VideoModel {
124
124
  if (!operation.response?.generatedVideos?.[0]?.video) throw new Error("Video generation failed: No video generated");
125
125
  const videoFile = operation.response.generatedVideos[0].video;
126
126
  if (!videoFile) throw new Error("Video generation failed: No video file returned");
127
- const dir = nodejs.path.join(nodejs.os.tmpdir(), options?.context?.id || "");
127
+ const dir = nodejs.path.join(nodejs.os.tmpdir(), `gemini-video-${Date.now()}`);
128
128
  await nodejs.fs.mkdir(dir, { recursive: true });
129
129
  const videoId = Date.now().toString();
130
130
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"gemini-video-model.mjs","names":[],"sources":["../src/gemini-video-model.ts"],"sourcesContent":["import type {\n AgentInvokeOptions,\n FileUnionContent,\n VideoModelInput,\n VideoModelOptions,\n VideoModelOutput,\n} from \"@aigne/core\";\nimport { fileUnionContentSchema, VideoModel, videoModelInputSchema } from \"@aigne/core\";\nimport { logger } from \"@aigne/core/utils/logger\";\nimport { checkArguments } from \"@aigne/core/utils/type-utils\";\nimport { nodejs } from \"@aigne/utils/nodejs\";\nimport { type GenerateVideosParameters, GoogleGenAI } from \"@google/genai\";\nimport { type ZodType, z } from \"zod\";\nimport { waitFileSizeStable } from \"./utils.js\";\n\nconst DEFAULT_MODEL = \"veo-3.1-generate-preview\";\nconst DEFAULT_SECONDS = 8;\n\n/**\n * Input options for Gemini Video Model\n */\nexport interface GeminiVideoModelInput extends VideoModelInput {\n /**\n * Text describing content that should not appear in the video\n */\n negativePrompt?: string;\n\n /**\n * Aspect ratio of the video\n *\n * Veo 3.1: \"16:9\" (default, 720p and 1080p), \"9:16\" (720p and 1080p)\n * Veo 3: \"16:9\" (default, 720p and 1080p), \"9:16\" (720p and 1080p)\n */\n aspectRatio?: \"16:9\" | \"9:16\";\n\n /**\n * Resolution of the video\n *\n * Veo 3.1: \"720p\" (default), \"1080p\" (only supports 8 seconds duration)\n * Veo 3: \"720p\" (default), \"1080p\" (16:9 only)\n */\n size?: \"720p\" | \"1080p\";\n\n /**\n * Duration of the generated video in seconds\n *\n * Veo 3.1: \"4\", \"6\", \"8\"\n * Veo 3: \"4\", \"6\", \"8\"\n */\n seconds?: \"4\" | \"6\" | \"8\";\n\n /**\n * Control person generation\n *\n * For text-to-video and image-to-video:\n * - Veo 3.1: \"allow_all\" for image-to-video, frame interpolation and reference images; only \"allow_adult\" for text-to-video\n * - Veo 3: \"allow_all\" for image-to-video; only \"allow_adult\" for text-to-video\n * - Veo 2: \"allow_all\", \"allow_adult\", \"dont_allow\"\n */\n personGeneration?: string;\n\n /**\n * Last frame for video generation (frame interpolation)\n */\n lastFrame?: FileUnionContent;\n\n /**\n * Reference images for video generation\n * Only supported in Veo 3.1 models\n */\n referenceImages?: FileUnionContent[];\n}\n\n/**\n * Output from Gemini Video Model\n */\nexport interface GeminiVideoModelOutput extends VideoModelOutput {}\n\n/**\n * Configuration options for Gemini Video Model\n */\nexport interface GeminiVideoModelOptions\n extends VideoModelOptions<GeminiVideoModelInput, GeminiVideoModelOutput> {\n /**\n * API key for Gemini API\n *\n * If not provided, will look for GEMINI_API_KEY in environment variables\n */\n apiKey?: string;\n\n /**\n * Base URL for Gemini API\n *\n * Useful for proxies or alternate endpoints\n */\n baseURL?: string;\n\n /**\n * Gemini model to use\n *\n * Defaults to 'veo-3.1-generate-preview'\n */\n model?: string;\n\n /**\n * Additional model options to control behavior\n */\n modelOptions?: Omit<Partial<GeminiVideoModelInput>, \"model\">;\n\n /**\n * Client options for Gemini API\n */\n clientOptions?: Record<string, any>;\n\n /**\n * Polling interval in milliseconds for checking video generation status\n *\n * Defaults to 10000ms (10 seconds)\n */\n pollingInterval?: number;\n}\n\nconst geminiVideoModelInputSchema: ZodType<GeminiVideoModelInput> = videoModelInputSchema.extend({\n negativePrompt: z.string().optional(),\n aspectRatio: z.enum([\"16:9\", \"9:16\"]).optional(),\n size: z.enum([\"720p\", \"1080p\"]).optional(),\n seconds: z.enum([\"4\", \"6\", \"8\"]).optional(),\n personGeneration: z.string().optional(),\n lastFrame: fileUnionContentSchema.optional(),\n referenceImages: fileUnionContentSchema.array().optional(),\n});\n\nconst geminiVideoModelOptionsSchema = z.object({\n apiKey: z.string().optional(),\n baseURL: z.string().optional(),\n model: z.string().optional(),\n modelOptions: z.object({}).optional(),\n clientOptions: z.object({}).optional(),\n pollingInterval: z.number().optional(),\n});\n\nexport class GeminiVideoModel extends VideoModel<GeminiVideoModelInput, GeminiVideoModelOutput> {\n constructor(public override options?: GeminiVideoModelOptions) {\n super({\n ...options,\n description: options?.description ?? \"Generate videos using Google Gemini Veo models\",\n inputSchema: geminiVideoModelInputSchema,\n });\n\n if (options) checkArguments(this.name, geminiVideoModelOptionsSchema, options);\n }\n\n /**\n * @hidden\n */\n protected _client?: GoogleGenAI;\n\n protected apiKeyEnvName = \"GEMINI_API_KEY\";\n\n get client() {\n const { apiKey } = this.credential;\n if (!apiKey)\n throw new Error(\n `${this.name} requires an API key. Please provide it via \\`options.apiKey\\`, or set the \\`${this.apiKeyEnvName}\\` environment variable`,\n );\n\n this._client ??= new GoogleGenAI({ apiKey, ...this.options?.clientOptions });\n return this._client;\n }\n\n override get credential() {\n return {\n url: this.options?.baseURL || process.env.GEMINI_BASE_URL,\n apiKey: this.options?.apiKey || process.env[this.apiKeyEnvName],\n model: this.options?.model || DEFAULT_MODEL,\n };\n }\n\n get modelOptions() {\n return this.options?.modelOptions;\n }\n\n async downloadToFile(\n dir: string,\n videoId: string,\n videoFile: { uri?: string; videoBytes?: any },\n ): Promise<string> {\n logger.debug(\"Downloading video content...\");\n const localPath = nodejs.path.join(dir, `${videoId}.mp4`);\n await this.client.files.download({ file: videoFile, downloadPath: localPath });\n logger.debug(`Generated video saved to ${localPath}`);\n\n await waitFileSizeStable(localPath);\n\n const buffer = await nodejs.fs.readFile(localPath);\n return buffer.toString(\"base64\");\n }\n\n override async process(\n input: GeminiVideoModelInput,\n options: AgentInvokeOptions,\n ): Promise<GeminiVideoModelOutput> {\n const model = input.model ?? input.modelOptions?.model ?? this.credential.model;\n const mergedInput = { ...this.modelOptions, ...input };\n\n if (mergedInput.referenceImages && !model.includes(\"veo-3.1\")) {\n throw new Error(\"referenceImages is only supported in Veo 3.1 models\");\n }\n\n const config: GenerateVideosParameters[\"config\"] = {};\n if (mergedInput.negativePrompt) config.negativePrompt = mergedInput.negativePrompt;\n if (mergedInput.aspectRatio) config.aspectRatio = mergedInput.aspectRatio;\n if (mergedInput.size) config.resolution = mergedInput.size;\n if (mergedInput.seconds) config.durationSeconds = parseInt(mergedInput.seconds, 10);\n if (mergedInput.personGeneration) config.personGeneration = mergedInput.personGeneration;\n if (mergedInput.lastFrame) {\n config.lastFrame = await this.transformFileType(\"file\", mergedInput.lastFrame).then(\n (file) => {\n return {\n imageBytes: file.data,\n mimeType: file.mimeType,\n };\n },\n );\n }\n\n if (mergedInput.referenceImages) {\n config.referenceImages = await Promise.all(\n mergedInput.referenceImages.map(async (image) => {\n return await this.transformFileType(\"file\", image).then((file) => {\n return {\n image: {\n imageBytes: file.data,\n mimeType: file.mimeType,\n },\n };\n });\n }),\n );\n }\n\n const params: GenerateVideosParameters = {\n model,\n prompt: mergedInput.prompt,\n config,\n };\n\n if (mergedInput.image) {\n params.image = await this.transformFileType(\"file\", mergedInput.image).then((file) => {\n return {\n imageBytes: file.data,\n mimeType: file.mimeType,\n };\n });\n }\n\n // Start video generation\n let operation = await this.client.models.generateVideos(params);\n logger.debug(\"Video generation started...\");\n\n // Poll operation status until complete\n const pollingInterval = this.options?.pollingInterval ?? 10000;\n while (!operation.done) {\n logger.debug(\"Waiting for video generation to complete...\");\n await new Promise((resolve) => setTimeout(resolve, pollingInterval));\n operation = await this.client.operations.getVideosOperation({ operation });\n }\n\n if (!operation.response?.generatedVideos?.[0]?.video) {\n throw new Error(\"Video generation failed: No video generated\");\n }\n\n // Download the generated video\n const generatedVideo = operation.response.generatedVideos[0];\n const videoFile = generatedVideo.video;\n\n if (!videoFile) {\n throw new Error(\"Video generation failed: No video file returned\");\n }\n\n // Save to temporary directory\n const dir = nodejs.path.join(nodejs.os.tmpdir(), options?.context?.id || \"\");\n await nodejs.fs.mkdir(dir, { recursive: true });\n\n const videoId = Date.now().toString();\n\n return {\n videos: [\n {\n type: \"file\",\n data: await this.downloadToFile(dir, videoId, videoFile),\n mimeType: \"video/mp4\",\n filename: `${videoId}.mp4`,\n },\n ],\n usage: {\n inputTokens: 0,\n outputTokens: 0,\n },\n model,\n seconds: mergedInput.seconds ? parseInt(mergedInput.seconds, 10) : DEFAULT_SECONDS,\n };\n }\n}\n"],"mappings":";;;;;;;;;AAeA,MAAM,gBAAgB;AACtB,MAAM,kBAAkB;AA0GxB,MAAM,8BAA8D,sBAAsB,OAAO;CAC/F,gBAAgB,EAAE,QAAQ,CAAC,UAAU;CACrC,aAAa,EAAE,KAAK,CAAC,QAAQ,OAAO,CAAC,CAAC,UAAU;CAChD,MAAM,EAAE,KAAK,CAAC,QAAQ,QAAQ,CAAC,CAAC,UAAU;CAC1C,SAAS,EAAE,KAAK;EAAC;EAAK;EAAK;EAAI,CAAC,CAAC,UAAU;CAC3C,kBAAkB,EAAE,QAAQ,CAAC,UAAU;CACvC,WAAW,uBAAuB,UAAU;CAC5C,iBAAiB,uBAAuB,OAAO,CAAC,UAAU;CAC3D,CAAC;AAEF,MAAM,gCAAgC,EAAE,OAAO;CAC7C,QAAQ,EAAE,QAAQ,CAAC,UAAU;CAC7B,SAAS,EAAE,QAAQ,CAAC,UAAU;CAC9B,OAAO,EAAE,QAAQ,CAAC,UAAU;CAC5B,cAAc,EAAE,OAAO,EAAE,CAAC,CAAC,UAAU;CACrC,eA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AAC;;AAG5E,MAAI,CAAC,UAAU,UAAU,kBAAkB,IAAI,MAC7C,OAAM,IAAI,MAAM,8CAA8C;EAKhE,MAAM,YADiB,UAAU,SAAS,gBAAgB,GACzB;AAEjC,MAAI,CAAC,UACH,OAAM,IAAI,MAAM,kDAAkD;EAIpE,MAAM,MAAM,OAAO,KAAK,KAAK,OAAO,GAAG,QAAQ,EAAE,SAAS,SAAS,MAAM,GAAG;AAC5E,QAAM,OAAO,GAAG,MAAM,KAAK,EAAE,WAAW,MAAM,CAAC;EAE/C,MAAM,UAAU,KAAK,KAAK,CAAC,UAAU;AAErC,SAAO;GACL,QAAQ,CACN;IACE,MAAM;IACN,MAAM,MAAM,KAAK,eAAe,KAAK,SAAS,UAAU;IACxD,UAAU;IACV,UAAU,GAAG,QAAQ;IACtB,CACF;GACD,OAAO;IACL,aAAa;IACb,cAAc;IACf;GACD;GACA,SAAS,YAAY,UAAU,SAAS,YAAY,SAAS,GAAG,GAAG;GACpE"}
1
+ {"version":3,"file":"gemini-video-model.mjs","names":[],"sources":["../src/gemini-video-model.ts"],"sourcesContent":["import type {\n FileUnionContent,\n ModelInvokeOptions,\n VideoModelInput,\n VideoModelOptions,\n VideoModelOutput,\n} from \"@aigne/model-base\";\nimport { fileUnionContentSchema, VideoModel, videoModelInputSchema } from \"@aigne/model-base\";\nimport { logger } from \"@aigne/model-base/utils/logger\";\nimport { nodejs } from \"@aigne/model-base/utils/nodejs\";\nimport { checkArguments } from \"@aigne/model-base/utils/type-utils\";\nimport { type GenerateVideosParameters, GoogleGenAI } from \"@google/genai\";\nimport { type ZodType, z } from \"zod\";\nimport { waitFileSizeStable } from \"./utils.js\";\n\nconst DEFAULT_MODEL = \"veo-3.1-generate-preview\";\nconst DEFAULT_SECONDS = 8;\n\n/**\n * Input options for Gemini Video Model\n */\nexport interface GeminiVideoModelInput extends VideoModelInput {\n /**\n * Text describing content that should not appear in the video\n */\n negativePrompt?: string;\n\n /**\n * Aspect ratio of the video\n *\n * Veo 3.1: \"16:9\" (default, 720p and 1080p), \"9:16\" (720p and 1080p)\n * Veo 3: \"16:9\" (default, 720p and 1080p), \"9:16\" (720p and 1080p)\n */\n aspectRatio?: \"16:9\" | \"9:16\";\n\n /**\n * Resolution of the video\n *\n * Veo 3.1: \"720p\" (default), \"1080p\" (only supports 8 seconds duration)\n * Veo 3: \"720p\" (default), \"1080p\" (16:9 only)\n */\n size?: \"720p\" | \"1080p\";\n\n /**\n * Duration of the generated video in seconds\n *\n * Veo 3.1: \"4\", \"6\", \"8\"\n * Veo 3: \"4\", \"6\", \"8\"\n */\n seconds?: \"4\" | \"6\" | \"8\";\n\n /**\n * Control person generation\n *\n * For text-to-video and image-to-video:\n * - Veo 3.1: \"allow_all\" for image-to-video, frame interpolation and reference images; only \"allow_adult\" for text-to-video\n * - Veo 3: \"allow_all\" for image-to-video; only \"allow_adult\" for text-to-video\n * - Veo 2: \"allow_all\", \"allow_adult\", \"dont_allow\"\n */\n personGeneration?: string;\n\n /**\n * Last frame for video generation (frame interpolation)\n */\n lastFrame?: FileUnionContent;\n\n /**\n * Reference images for video generation\n * Only supported in Veo 3.1 models\n */\n referenceImages?: FileUnionContent[];\n}\n\n/**\n * Output from Gemini Video Model\n */\nexport interface GeminiVideoModelOutput extends VideoModelOutput {}\n\n/**\n * Configuration options for Gemini Video Model\n */\nexport interface GeminiVideoModelOptions\n extends VideoModelOptions<GeminiVideoModelInput, GeminiVideoModelOutput> {\n /**\n * API key for Gemini API\n *\n * If not provided, will look for GEMINI_API_KEY in environment variables\n */\n apiKey?: string;\n\n /**\n * Base URL for Gemini API\n *\n * Useful for proxies or alternate endpoints\n */\n baseURL?: string;\n\n /**\n * Gemini model to use\n *\n * Defaults to 'veo-3.1-generate-preview'\n */\n model?: string;\n\n /**\n * Additional model options to control behavior\n */\n modelOptions?: Omit<Partial<GeminiVideoModelInput>, \"model\">;\n\n /**\n * Client options for Gemini API\n */\n clientOptions?: Record<string, any>;\n\n /**\n * Polling interval in milliseconds for checking video generation status\n *\n * Defaults to 10000ms (10 seconds)\n */\n pollingInterval?: number;\n}\n\nconst geminiVideoModelInputSchema: ZodType<GeminiVideoModelInput> = videoModelInputSchema.extend({\n negativePrompt: z.string().optional(),\n aspectRatio: z.enum([\"16:9\", \"9:16\"]).optional(),\n size: z.enum([\"720p\", \"1080p\"]).optional(),\n seconds: z.enum([\"4\", \"6\", \"8\"]).optional(),\n personGeneration: z.string().optional(),\n lastFrame: fileUnionContentSchema.optional(),\n referenceImages: fileUnionContentSchema.array().optional(),\n});\n\nconst geminiVideoModelOptionsSchema = z.object({\n apiKey: z.string().optional(),\n baseURL: z.string().optional(),\n model: z.string().optional(),\n modelOptions: z.object({}).optional(),\n clientOptions: z.object({}).optional(),\n pollingInterval: z.number().optional(),\n});\n\nexport class GeminiVideoModel extends VideoModel<GeminiVideoModelInput, GeminiVideoModelOutput> {\n constructor(public override options?: GeminiVideoModelOptions) {\n super({\n ...options,\n description: options?.description ?? \"Generate videos using Google Gemini Veo models\",\n inputSchema: geminiVideoModelInputSchema,\n });\n\n if (options) checkArguments(this.name, geminiVideoModelOptionsSchema, options);\n }\n\n /**\n * @hidden\n */\n protected _client?: GoogleGenAI;\n\n protected apiKeyEnvName = \"GEMINI_API_KEY\";\n\n get client() {\n const { apiKey } = this.credential;\n if (!apiKey)\n throw new Error(\n `${this.name} requires an API key. Please provide it via \\`options.apiKey\\`, or set the \\`${this.apiKeyEnvName}\\` environment variable`,\n );\n\n this._client ??= new GoogleGenAI({ apiKey, ...this.options?.clientOptions });\n return this._client;\n }\n\n override get credential() {\n return {\n url: this.options?.baseURL || process.env.GEMINI_BASE_URL,\n apiKey: this.options?.apiKey || process.env[this.apiKeyEnvName],\n model: this.options?.model || DEFAULT_MODEL,\n };\n }\n\n get modelOptions() {\n return this.options?.modelOptions;\n }\n\n async downloadToFile(\n dir: string,\n videoId: string,\n videoFile: { uri?: string; videoBytes?: any },\n ): Promise<string> {\n logger.debug(\"Downloading video content...\");\n const localPath = nodejs.path.join(dir, `${videoId}.mp4`);\n await this.client.files.download({ file: videoFile, downloadPath: localPath });\n logger.debug(`Generated video saved to ${localPath}`);\n\n await waitFileSizeStable(localPath);\n\n const buffer = await nodejs.fs.readFile(localPath);\n return buffer.toString(\"base64\");\n }\n\n override async process(\n input: GeminiVideoModelInput,\n _options: ModelInvokeOptions,\n ): Promise<GeminiVideoModelOutput> {\n const model = input.model ?? input.modelOptions?.model ?? this.credential.model;\n const mergedInput = { ...this.modelOptions, ...input };\n\n if (mergedInput.referenceImages && !model.includes(\"veo-3.1\")) {\n throw new Error(\"referenceImages is only supported in Veo 3.1 models\");\n }\n\n const config: GenerateVideosParameters[\"config\"] = {};\n if (mergedInput.negativePrompt) config.negativePrompt = mergedInput.negativePrompt;\n if (mergedInput.aspectRatio) config.aspectRatio = mergedInput.aspectRatio;\n if (mergedInput.size) config.resolution = mergedInput.size;\n if (mergedInput.seconds) config.durationSeconds = parseInt(mergedInput.seconds, 10);\n if (mergedInput.personGeneration) config.personGeneration = mergedInput.personGeneration;\n if (mergedInput.lastFrame) {\n config.lastFrame = await this.transformFileType(\"file\", mergedInput.lastFrame).then(\n (file) => {\n return {\n imageBytes: file.data,\n mimeType: file.mimeType,\n };\n },\n );\n }\n\n if (mergedInput.referenceImages) {\n config.referenceImages = await Promise.all(\n mergedInput.referenceImages.map(async (image) => {\n return await this.transformFileType(\"file\", image).then((file) => {\n return {\n image: {\n imageBytes: file.data,\n mimeType: file.mimeType,\n },\n };\n });\n }),\n );\n }\n\n const params: GenerateVideosParameters = {\n model,\n prompt: mergedInput.prompt,\n config,\n };\n\n if (mergedInput.image) {\n params.image = await this.transformFileType(\"file\", mergedInput.image).then((file) => {\n return {\n imageBytes: file.data,\n mimeType: file.mimeType,\n };\n });\n }\n\n // Start video generation\n let operation = await this.client.models.generateVideos(params);\n logger.debug(\"Video generation started...\");\n\n // Poll operation status until complete\n const pollingInterval = this.options?.pollingInterval ?? 10000;\n while (!operation.done) {\n logger.debug(\"Waiting for video generation to complete...\");\n await new Promise((resolve) => setTimeout(resolve, pollingInterval));\n operation = await this.client.operations.getVideosOperation({ operation });\n }\n\n if (!operation.response?.generatedVideos?.[0]?.video) {\n throw new Error(\"Video generation failed: No video generated\");\n }\n\n // Download the generated video\n const generatedVideo = operation.response.generatedVideos[0];\n const videoFile = generatedVideo.video;\n\n if (!videoFile) {\n throw new Error(\"Video generation failed: No video file returned\");\n }\n\n // Save to temporary directory\n const dir = nodejs.path.join(nodejs.os.tmpdir(), `gemini-video-${Date.now()}`);\n await nodejs.fs.mkdir(dir, { recursive: true });\n\n const videoId = Date.now().toString();\n\n return {\n videos: [\n {\n type: \"file\",\n data: await this.downloadToFile(dir, videoId, videoFile),\n mimeType: \"video/mp4\",\n filename: `${videoId}.mp4`,\n },\n ],\n usage: {\n inputTokens: 0,\n outputTokens: 0,\n },\n model,\n seconds: mergedInput.seconds ? parseInt(mergedInput.seconds, 10) : DEFAULT_SECONDS,\n };\n }\n}\n"],"mappings":";;;;;;;;;AAeA,MAAM,gBAAgB;AACtB,MAAM,kBAAkB;AA0GxB,MAAM,8BAA8D,sBAAsB,OAAO;CAC/F,gBAAgB,EAAE,QAAQ,CAAC,UAAU;CACrC,aAAa,EAAE,KAAK,CAAC,QAAQ,OAAO,CAAC,CAAC,UAAU;CAChD,MAAM,EAAE,KAAK,CAAC,QAAQ,QAAQ,CAAC,CAAC,UAAU;CAC1C,SAAS,EAAE,KAAK;EAAC;EAAK;EAAK;EAAI,CAAC,CAAC,UAAU;CAC3C,kBAAkB,EAAE,QAAQ,CAAC,UAAU;CACvC,WAAW,uBAAuB,UAAU;CAC5C,iBAAiB,uBAAuB,OAAO,CAAC,UAAU;CAC3D,CAAC;AAEF,MAAM,gCAAgC,EAAE,OAAO;CAC7C,QAAQ,EAAE,QAAQ,CAAC,UAAU;CAC7B,SAAS,EAAE,QAAQ,CAAC,UAAU;CAC9B,OAAO,EAAE,QAAQ,CAAC,UAAU;CAC5B,cAAc,EAAE,OAAO,EAA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,WAAW,mBAAmB,EAAE,WAAW,CAAC;;AAG5E,MAAI,CAAC,UAAU,UAAU,kBAAkB,IAAI,MAC7C,OAAM,IAAI,MAAM,8CAA8C;EAKhE,MAAM,YADiB,UAAU,SAAS,gBAAgB,GACzB;AAEjC,MAAI,CAAC,UACH,OAAM,IAAI,MAAM,kDAAkD;EAIpE,MAAM,MAAM,OAAO,KAAK,KAAK,OAAO,GAAG,QAAQ,EAAE,gBAAgB,KAAK,KAAK,GAAG;AAC9E,QAAM,OAAO,GAAG,MAAM,KAAK,EAAE,WAAW,MAAM,CAAC;EAE/C,MAAM,UAAU,KAAK,KAAK,CAAC,UAAU;AAErC,SAAO;GACL,QAAQ,CACN;IACE,MAAM;IACN,MAAM,MAAM,KAAK,eAAe,KAAK,SAAS,UAAU;IACxD,UAAU;IACV,UAAU,GAAG,QAAQ;IACtB,CACF;GACD,OAAO;IACL,aAAa;IACb,cAAc;IACf;GACD;GACA,SAAS,YAAY,UAAU,SAAS,YAAY,SAAS,GAAG,GAAG;GACpE"}
package/dist/index.cjs CHANGED
@@ -1,7 +1,9 @@
1
1
  const require_gemini_chat_model = require('./gemini-chat-model.cjs');
2
+ const require_gemini_embedding_model = require('./gemini-embedding-model.cjs');
2
3
  const require_gemini_image_model = require('./gemini-image-model.cjs');
3
4
  const require_gemini_video_model = require('./gemini-video-model.cjs');
4
5
 
5
6
  exports.GeminiChatModel = require_gemini_chat_model.GeminiChatModel;
7
+ exports.GeminiEmbeddingModel = require_gemini_embedding_model.GeminiEmbeddingModel;
6
8
  exports.GeminiImageModel = require_gemini_image_model.GeminiImageModel;
7
9
  exports.GeminiVideoModel = require_gemini_video_model.GeminiVideoModel;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { GeminiChatModel, GeminiChatModelOptions } from "./gemini-chat-model.cjs";
2
+ import { GeminiEmbeddingModel, GeminiEmbeddingModelInput, GeminiEmbeddingModelOptions, GeminiEmbeddingModelOutput } from "./gemini-embedding-model.cjs";
2
3
  import { GeminiImageModel, GeminiImageModelInput, GeminiImageModelOptions, GeminiImageModelOutput } from "./gemini-image-model.cjs";
3
4
  import { GeminiVideoModel, GeminiVideoModelInput, GeminiVideoModelOptions, GeminiVideoModelOutput } from "./gemini-video-model.cjs";
4
- export { GeminiChatModel, GeminiChatModelOptions, GeminiImageModel, GeminiImageModelInput, GeminiImageModelOptions, GeminiImageModelOutput, GeminiVideoModel, GeminiVideoModelInput, GeminiVideoModelOptions, GeminiVideoModelOutput };
5
+ export { GeminiChatModel, GeminiChatModelOptions, GeminiEmbeddingModel, GeminiEmbeddingModelInput, GeminiEmbeddingModelOptions, GeminiEmbeddingModelOutput, GeminiImageModel, GeminiImageModelInput, GeminiImageModelOptions, GeminiImageModelOutput, GeminiVideoModel, GeminiVideoModelInput, GeminiVideoModelOptions, GeminiVideoModelOutput };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { GeminiChatModel, GeminiChatModelOptions } from "./gemini-chat-model.mjs";
2
+ import { GeminiEmbeddingModel, GeminiEmbeddingModelInput, GeminiEmbeddingModelOptions, GeminiEmbeddingModelOutput } from "./gemini-embedding-model.mjs";
2
3
  import { GeminiImageModel, GeminiImageModelInput, GeminiImageModelOptions, GeminiImageModelOutput } from "./gemini-image-model.mjs";
3
4
  import { GeminiVideoModel, GeminiVideoModelInput, GeminiVideoModelOptions, GeminiVideoModelOutput } from "./gemini-video-model.mjs";
4
- export { GeminiChatModel, GeminiChatModelOptions, GeminiImageModel, GeminiImageModelInput, GeminiImageModelOptions, GeminiImageModelOutput, GeminiVideoModel, GeminiVideoModelInput, GeminiVideoModelOptions, GeminiVideoModelOutput };
5
+ export { GeminiChatModel, GeminiChatModelOptions, GeminiEmbeddingModel, GeminiEmbeddingModelInput, GeminiEmbeddingModelOptions, GeminiEmbeddingModelOutput, GeminiImageModel, GeminiImageModelInput, GeminiImageModelOptions, GeminiImageModelOutput, GeminiVideoModel, GeminiVideoModelInput, GeminiVideoModelOptions, GeminiVideoModelOutput };
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { GeminiChatModel } from "./gemini-chat-model.mjs";
2
+ import { GeminiEmbeddingModel } from "./gemini-embedding-model.mjs";
2
3
  import { GeminiImageModel } from "./gemini-image-model.mjs";
3
4
  import { GeminiVideoModel } from "./gemini-video-model.mjs";
4
5
 
5
- export { GeminiChatModel, GeminiImageModel, GeminiVideoModel };
6
+ export { GeminiChatModel, GeminiEmbeddingModel, GeminiImageModel, GeminiVideoModel };
package/dist/utils.cjs CHANGED
@@ -1,4 +1,4 @@
1
- let _aigne_utils_nodejs = require("@aigne/utils/nodejs");
1
+ let _aigne_model_base_utils_nodejs = require("@aigne/model-base/utils/nodejs");
2
2
 
3
3
  //#region src/utils.ts
4
4
  /**
@@ -21,7 +21,7 @@ async function waitFileSizeStable(filePath, options) {
21
21
  while (stableCount < requiredStableCount) {
22
22
  if (Date.now() - startTime > timeout) throw new Error(`Timeout waiting for file to stabilize: ${filePath}`);
23
23
  await new Promise((resolve) => setTimeout(resolve, checkInterval));
24
- const currentSize = (await _aigne_utils_nodejs.nodejs.fs.stat(filePath)).size;
24
+ const currentSize = (await _aigne_model_base_utils_nodejs.nodejs.fs.stat(filePath)).size;
25
25
  if (currentSize === previousSize && currentSize > 0) stableCount++;
26
26
  else {
27
27
  stableCount = 0;
package/dist/utils.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { nodejs } from "@aigne/utils/nodejs";
1
+ import { nodejs } from "@aigne/model-base/utils/nodejs";
2
2
 
3
3
  //#region src/utils.ts
4
4
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import { nodejs } from \"@aigne/utils/nodejs\";\n\n/**\n * Wait for file size to stabilize, ensuring the file download is complete.\n *\n * @param filePath - The path to the file to check\n * @param options - Configuration options\n * @param options.checkInterval - Check interval in milliseconds (default: 500ms)\n * @param options.stableCount - Number of consecutive checks with same size to consider stable (default: 3)\n * @param options.timeout - Timeout in milliseconds (default: 60000ms)\n * @throws Error when timeout is reached\n */\nexport async function waitFileSizeStable(\n filePath: string,\n options?: {\n checkInterval?: number;\n stableCount?: number;\n timeout?: number;\n },\n): Promise<void> {\n const checkInterval = options?.checkInterval ?? 500;\n const requiredStableCount = options?.stableCount ?? 3;\n const timeout = options?.timeout ?? 60000;\n\n const startTime = Date.now();\n let previousSize = 0;\n let stableCount = 0;\n\n while (stableCount < requiredStableCount) {\n if (Date.now() - startTime > timeout) {\n throw new Error(`Timeout waiting for file to stabilize: ${filePath}`);\n }\n\n await new Promise((resolve) => setTimeout(resolve, checkInterval));\n\n const stats = await nodejs.fs.stat(filePath);\n const currentSize = stats.size;\n\n if (currentSize === previousSize && currentSize > 0) {\n stableCount++;\n } else {\n stableCount = 0;\n previousSize = currentSize;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,eAAsB,mBACpB,UACA,SAKe;CACf,MAAM,gBAAgB,SAAS,iBAAiB;CAChD,MAAM,sBAAsB,SAAS,eAAe;CACpD,MAAM,UAAU,SAAS,WAAW;CAEpC,MAAM,YAAY,KAAK,KAAK;CAC5B,IAAI,eAAe;CACnB,IAAI,cAAc;AAElB,QAAO,cAAc,qBAAqB;AACxC,MAAI,KAAK,KAAK,GAAG,YAAY,QAC3B,OAAM,IAAI,MAAM,0CAA0C,WAAW;AAGvE,QAAM,IAAI,SAAS,YAAY,WAAW,SAAS,cAAc,CAAC;EAGlE,MAAM,eADQ,MAAM,OAAO,GAAG,KAAK,SAAS,EAClB;AAE1B,MAAI,gBAAgB,gBAAgB,cAAc,EAChD;OACK;AACL,iBAAc;AACd,kBAAe"}
1
+ {"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import { nodejs } from \"@aigne/model-base/utils/nodejs\";\n\n/**\n * Wait for file size to stabilize, ensuring the file download is complete.\n *\n * @param filePath - The path to the file to check\n * @param options - Configuration options\n * @param options.checkInterval - Check interval in milliseconds (default: 500ms)\n * @param options.stableCount - Number of consecutive checks with same size to consider stable (default: 3)\n * @param options.timeout - Timeout in milliseconds (default: 60000ms)\n * @throws Error when timeout is reached\n */\nexport async function waitFileSizeStable(\n filePath: string,\n options?: {\n checkInterval?: number;\n stableCount?: number;\n timeout?: number;\n },\n): Promise<void> {\n const checkInterval = options?.checkInterval ?? 500;\n const requiredStableCount = options?.stableCount ?? 3;\n const timeout = options?.timeout ?? 60000;\n\n const startTime = Date.now();\n let previousSize = 0;\n let stableCount = 0;\n\n while (stableCount < requiredStableCount) {\n if (Date.now() - startTime > timeout) {\n throw new Error(`Timeout waiting for file to stabilize: ${filePath}`);\n }\n\n await new Promise((resolve) => setTimeout(resolve, checkInterval));\n\n const stats = await nodejs.fs.stat(filePath);\n const currentSize = stats.size;\n\n if (currentSize === previousSize && currentSize > 0) {\n stableCount++;\n } else {\n stableCount = 0;\n previousSize = currentSize;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,eAAsB,mBACpB,UACA,SAKe;CACf,MAAM,gBAAgB,SAAS,iBAAiB;CAChD,MAAM,sBAAsB,SAAS,eAAe;CACpD,MAAM,UAAU,SAAS,WAAW;CAEpC,MAAM,YAAY,KAAK,KAAK;CAC5B,IAAI,eAAe;CACnB,IAAI,cAAc;AAElB,QAAO,cAAc,qBAAqB;AACxC,MAAI,KAAK,KAAK,GAAG,YAAY,QAC3B,OAAM,IAAI,MAAM,0CAA0C,WAAW;AAGvE,QAAM,IAAI,SAAS,YAAY,WAAW,SAAS,cAAc,CAAC;EAGlE,MAAM,eADQ,MAAM,OAAO,GAAG,KAAK,SAAS,EAClB;AAE1B,MAAI,gBAAgB,gBAAgB,cAAc,EAChD;OACK;AACL,iBAAc;AACd,kBAAe"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/gemini",
3
- "version": "1.74.0-beta",
3
+ "version": "1.74.0-beta.10",
4
4
  "description": "AIGNE Gemini SDK for integrating with Google's Gemini AI models",
5
5
  "license": "Elastic-2.0",
6
6
  "publishConfig": {
@@ -38,8 +38,7 @@
38
38
  "yaml": "^2.8.1",
39
39
  "zod": "^3.25.67",
40
40
  "zod-to-json-schema": "^3.24.6",
41
- "@aigne/core": "^1.74.0-beta",
42
- "@aigne/utils": "^1.74.0-beta"
41
+ "@aigne/model-base": "^1.74.0-beta.10"
43
42
  },
44
43
  "devDependencies": {
45
44
  "@types/bun": "^1.3.6",
@@ -47,9 +46,7 @@
47
46
  "rimraf": "^6.1.2",
48
47
  "tsdown": "0.20.0-beta.3",
49
48
  "typescript": "5.9.2",
50
- "@aigne/scripts": "0.0.0",
51
- "@aigne/typescript-config": "0.0.0",
52
- "@aigne/utils": "1.74.0-beta"
49
+ "@aigne/typescript-config": "0.0.0"
53
50
  },
54
51
  "scripts": {
55
52
  "build": "tsdown",
package/LICENSE.md DELETED
@@ -1,93 +0,0 @@
1
- Elastic License 2.0
2
-
3
- URL: https://www.elastic.co/licensing/elastic-license
4
-
5
- ## Acceptance
6
-
7
- By using the software, you agree to all of the terms and conditions below.
8
-
9
- ## Copyright License
10
-
11
- The licensor grants you a non-exclusive, royalty-free, worldwide,
12
- non-sublicensable, non-transferable license to use, copy, distribute, make
13
- available, and prepare derivative works of the software, in each case subject to
14
- the limitations and conditions below.
15
-
16
- ## Limitations
17
-
18
- You may not provide the software to third parties as a hosted or managed
19
- service, where the service provides users with access to any substantial set of
20
- the features or functionality of the software.
21
-
22
- You may not move, change, disable, or circumvent the license key functionality
23
- in the software, and you may not remove or obscure any functionality in the
24
- software that is protected by the license key.
25
-
26
- You may not alter, remove, or obscure any licensing, copyright, or other notices
27
- of the licensor in the software. Any use of the licensor’s trademarks is subject
28
- to applicable law.
29
-
30
- ## Patents
31
-
32
- The licensor grants you a license, under any patent claims the licensor can
33
- license, or becomes able to license, to make, have made, use, sell, offer for
34
- sale, import and have imported the software, in each case subject to the
35
- limitations and conditions in this license. This license does not cover any
36
- patent claims that you cause to be infringed by modifications or additions to
37
- the software. If you or your company make any written claim that the software
38
- infringes or contributes to infringement of any patent, your patent license for
39
- the software granted under these terms ends immediately. If your company makes
40
- such a claim, your patent license ends immediately for work on behalf of your
41
- company.
42
-
43
- ## Notices
44
-
45
- You must ensure that anyone who gets a copy of any part of the software from you
46
- also gets a copy of these terms.
47
-
48
- If you modify the software, you must include in any modified copies of the
49
- software prominent notices stating that you have modified the software.
50
-
51
- ## No Other Rights
52
-
53
- These terms do not imply any licenses other than those expressly granted in
54
- these terms.
55
-
56
- ## Termination
57
-
58
- If you use the software in violation of these terms, such use is not licensed,
59
- and your licenses will automatically terminate. If the licensor provides you
60
- with a notice of your violation, and you cease all violation of this license no
61
- later than 30 days after you receive that notice, your licenses will be
62
- reinstated retroactively. However, if you violate these terms after such
63
- reinstatement, any additional violation of these terms will cause your licenses
64
- to terminate automatically and permanently.
65
-
66
- ## No Liability
67
-
68
- *As far as the law allows, the software comes as is, without any warranty or
69
- condition, and the licensor will not be liable to you for any damages arising
70
- out of these terms or the use or nature of the software, under any kind of
71
- legal claim.*
72
-
73
- ## Definitions
74
-
75
- The **licensor** is the entity offering these terms, and the **software** is the
76
- software the licensor makes available under these terms, including any portion
77
- of it.
78
-
79
- **you** refers to the individual or entity agreeing to these terms.
80
-
81
- **your company** is any legal entity, sole proprietorship, or other kind of
82
- organization that you work for, plus all organizations that have control over,
83
- are under the control of, or are under common control with that
84
- organization. **control** means ownership of substantially all the assets of an
85
- entity, or the power to direct its management and policies by vote, contract, or
86
- otherwise. Control can be direct or indirect.
87
-
88
- **your licenses** are all the licenses granted to you for the software under
89
- these terms.
90
-
91
- **use** means anything you do with the software requiring one of your licenses.
92
-
93
- **trademark** means trademarks, service marks, and similar rights.