ai-world-sdk 1.1.2 → 1.1.5

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 CHANGED
@@ -1489,7 +1489,7 @@ for await (const chunk of client.streamDownload({
1489
1489
  | 提供商 | Provider | 模型示例 | 模型类 |
1490
1490
  |--------|----------|----------|--------|
1491
1491
  | OpenAI | `aihubmix` | `gpt-4o-mini`, `gpt-4`, `o1-preview` | `ChatOpenAI` |
1492
- | Google Gemini | `gemini` 或 `aihubmix` | `gemini-2.5-flash-image`, `gemini-1.5-pro` | `ChatGoogleGenerativeAI` |
1492
+ | Google Gemini | `gemini` 或 `aihubmix` | `gemini-2.5-flash-image`, `gemini-3-pro-image-preview` | `ChatGoogleGenerativeAI` |
1493
1493
  | Anthropic Claude | `aihubmix` | `claude-3-sonnet-20240229`, `claude-3-opus-20240229` | `ChatAnthropic` |
1494
1494
  | Doubao | `doubao` 或 `aihubmix` | `doubao-pro-4k`, `doubao-seedream-4-5-251128` | `ChatOpenAI` |
1495
1495
 
@@ -1505,7 +1505,6 @@ for await (const chunk of client.streamDownload({
1505
1505
  - **Google Gemini**:
1506
1506
  - `gemini-2.5-flash-image` (Nano Banana) - **推荐**,快速、高效,1024px 分辨率,支持所有宽高比
1507
1507
  - `gemini-3-pro-image-preview` (Nano Banana Pro) - 专业级,支持 1K/2K/4K 分辨率,支持 Google 搜索、思考模式,最多 14 张参考图片
1508
- - `gemini-2.0-flash-exp-image-generation` (已弃用,建议使用 `gemini-2.5-flash-image`)
1509
1508
 
1510
1509
  **模型选择建议:**
1511
1510
  - **日常使用**: `gemini-2.5-flash-image` - 速度快,成本低
@@ -882,7 +882,7 @@ describe("Langchain SDK Tests", () => {
882
882
  const openai = new index_1.ChatOpenAI({
883
883
  modelName: "gpt-4",
884
884
  temperature: 0.7,
885
- provider: "aihubmix",
885
+ provider: "api2img",
886
886
  });
887
887
  let fullText = "";
888
888
  for await (const chunk of openai.stream([
@@ -891,14 +891,14 @@ describe("Langchain SDK Tests", () => {
891
891
  fullText += extractTextFromChunk(chunk);
892
892
  }
893
893
  expect(fullText.length).toBeGreaterThan(0);
894
- console.log("✅ ChatOpenAI 流式测试成功");
894
+ console.log("✅ ChatOpenAI 流式测试成功 " + fullText);
895
895
  console.log(`完整回复长度: ${fullText.length} 字符`);
896
896
  }, 30000);
897
897
  test("ChatOpenAI - batch 方法", async () => {
898
898
  const openai = new index_1.ChatOpenAI({
899
899
  modelName: "gpt-4",
900
900
  temperature: 0.7,
901
- provider: "aihubmix",
901
+ provider: "api2img",
902
902
  });
903
903
  const responses = await openai.batch([
904
904
  [new index_1.HumanMessage("什么是人工智能?")],
package/dist/base.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * Similar to LangChain.js BaseChatModel
4
4
  */
5
5
  import { BaseMessage, AIMessage, AIMessageChunk } from "./messages";
6
- export type AIModelProvider = "aihubmix" | "api2img" | "doubao" | "gemini";
6
+ import type { AIModelProvider } from "./provider_config";
7
7
  export interface BaseChatModelParams {
8
8
  provider: AIModelProvider;
9
9
  baseUrl?: string;
package/dist/base.js CHANGED
@@ -130,21 +130,72 @@ class BaseChatModel {
130
130
  }
131
131
  const reader = response.body.getReader();
132
132
  const decoder = new TextDecoder();
133
+ let buffer = "";
133
134
  try {
134
135
  while (true) {
135
136
  const { done, value } = await reader.read();
136
137
  if (done)
137
138
  break;
138
- let data = decoder.decode(value, { stream: true });
139
- try {
140
- const parsed = JSON.parse(data);
141
- if (config_1.sdkConfig.getDebug()) {
142
- (0, log_1.debugLog)("📦 Stream Chunk:", parsed);
139
+ buffer += decoder.decode(value, { stream: true });
140
+ // 按行分割处理 SSE 格式数据
141
+ const lines = buffer.split("\n");
142
+ // 保留最后一个可能不完整的行
143
+ buffer = lines.pop() || "";
144
+ for (const line of lines) {
145
+ const trimmedLine = line.trim();
146
+ // 跳过空行
147
+ if (!trimmedLine)
148
+ continue;
149
+ // 检查结束标志
150
+ if (trimmedLine === "data: [DONE]") {
151
+ return;
152
+ }
153
+ // 处理 SSE 格式 "data: {...}"
154
+ if (trimmedLine.startsWith("data: ")) {
155
+ const jsonStr = trimmedLine.slice(6); // 去掉 "data: " 前缀
156
+ try {
157
+ const parsed = JSON.parse(jsonStr);
158
+ if (config_1.sdkConfig.getDebug()) {
159
+ (0, log_1.debugLog)("📦 Stream Chunk:", parsed);
160
+ }
161
+ yield new messages_1.AIMessageChunk(parsed);
162
+ }
163
+ catch (e) {
164
+ if (config_1.sdkConfig.getDebug()) {
165
+ (0, log_1.debugLog)("⚠️ Failed to parse SSE data:", jsonStr, e);
166
+ }
167
+ }
168
+ }
169
+ else {
170
+ // 尝试直接解析(兼容非 SSE 格式)
171
+ try {
172
+ const parsed = JSON.parse(trimmedLine);
173
+ if (config_1.sdkConfig.getDebug()) {
174
+ (0, log_1.debugLog)("📦 Stream Chunk (non-SSE):", parsed);
175
+ }
176
+ yield new messages_1.AIMessageChunk(parsed);
177
+ }
178
+ catch {
179
+ // 忽略无法解析的行
180
+ }
143
181
  }
144
- yield new messages_1.AIMessageChunk(parsed);
145
182
  }
146
- catch {
147
- // 忽略解析错误
183
+ }
184
+ // 处理缓冲区中剩余的数据
185
+ if (buffer.trim()) {
186
+ const trimmedBuffer = buffer.trim();
187
+ if (trimmedBuffer.startsWith("data: ") && trimmedBuffer !== "data: [DONE]") {
188
+ const jsonStr = trimmedBuffer.slice(6);
189
+ try {
190
+ const parsed = JSON.parse(jsonStr);
191
+ if (config_1.sdkConfig.getDebug()) {
192
+ (0, log_1.debugLog)("📦 Stream Chunk (final):", parsed);
193
+ }
194
+ yield new messages_1.AIMessageChunk(parsed);
195
+ }
196
+ catch {
197
+ // 忽略解析错误
198
+ }
148
199
  }
149
200
  }
150
201
  }
package/dist/config.d.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  *
10
10
  * 注意: {VERSION} 占位符会在构建时被替换为实际版本号
11
11
  */
12
- export declare const SDK_SIGNATURE = "AI_WORLD_SDK_V:1.1.2";
12
+ export declare const SDK_SIGNATURE = "AI_WORLD_SDK_V:1.1.5";
13
13
  /**
14
14
  * 版本兼容性错误
15
15
  */
@@ -24,8 +24,8 @@ declare class SDKConfig {
24
24
  private _pluginId;
25
25
  private _versionCompatible;
26
26
  private _versionCheckPromise;
27
- readonly sdkSignature = "AI_WORLD_SDK_V:1.1.2";
28
- readonly sdkVersion = "1.1.2";
27
+ readonly sdkSignature = "AI_WORLD_SDK_V:1.1.5";
28
+ readonly sdkVersion = "1.1.5";
29
29
  constructor();
30
30
  /**
31
31
  * Set global base URL
package/dist/config.js CHANGED
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.sdkConfig = exports.VersionCompatibilityError = exports.SDK_SIGNATURE = void 0;
8
8
  // SDK 版本号(构建时自动从 package.json 更新)
9
9
  // 此版本号会在运行 npm run build 时自动从 package.json 读取并更新
10
- const SDK_VERSION = "1.1.2";
10
+ const SDK_VERSION = "1.1.5";
11
11
  /**
12
12
  * SDK 特征码 - 用于在构建后的 JS 文件中识别 SDK 版本
13
13
  * 格式: AI_WORLD_SDK_V:版本号
@@ -15,7 +15,7 @@ const SDK_VERSION = "1.1.2";
15
15
  *
16
16
  * 注意: {VERSION} 占位符会在构建时被替换为实际版本号
17
17
  */
18
- exports.SDK_SIGNATURE = "AI_WORLD_SDK_V:1.1.2";
18
+ exports.SDK_SIGNATURE = "AI_WORLD_SDK_V:1.1.5";
19
19
  /**
20
20
  * 版本兼容性错误
21
21
  */
@@ -2,7 +2,8 @@
2
2
  * Gemini Image Generation Client
3
3
  * Google Gemini 图像生成客户端
4
4
  */
5
- export type GeminiImageGenerationProvider = "aihubmix" | "api2img" | "gemini";
5
+ import type { AIModelProvider } from "./provider_config";
6
+ export type GeminiImageGenerationProvider = Extract<AIModelProvider, "aihubmix" | "shubiaobiao" | "api2img" | "gemini">;
6
7
  export interface GeminiImageGenerationConfig {
7
8
  provider?: GeminiImageGenerationProvider;
8
9
  baseUrl?: string;
package/dist/index.d.ts CHANGED
@@ -12,7 +12,8 @@ import { OpenAIVideoGenerationClient, type OpenAIVideoGenerationConfig, type Ope
12
12
  import { DownloadClient, type DownloadConfig, type DownloadOptions, type StreamDownloadOptions } from "./download";
13
13
  import { AuthClient, getCurrentUserInfo, type AuthConfig, type UserInfo } from "./auth";
14
14
  export { BaseMessage, HumanMessage, AIMessage, SystemMessage, AIMessageChunk, type MessageContent, type AIMessageChunkData, } from "./messages";
15
- export { BaseChatModel, type BaseChatModelParams, type AIModelProvider, type ToolDefinition, type BindOptions, } from "./base";
15
+ export { BaseChatModel, type BaseChatModelParams, type ToolDefinition, type BindOptions, } from "./base";
16
+ export type { AIModelProvider } from "./provider_config";
16
17
  export { ChatOpenAI } from "./chat_models/openai";
17
18
  export { ChatGoogleGenerativeAI } from "./chat_models/google";
18
19
  export { ChatAnthropic } from "./chat_models/anthropic";
package/dist/index.js CHANGED
@@ -24,6 +24,7 @@ const auth_1 = require("./auth");
24
24
  Object.defineProperty(exports, "AuthClient", { enumerable: true, get: function () { return auth_1.AuthClient; } });
25
25
  Object.defineProperty(exports, "getCurrentUserInfo", { enumerable: true, get: function () { return auth_1.getCurrentUserInfo; } });
26
26
  const config_1 = require("./config");
27
+ const provider_config_1 = require("./provider_config");
27
28
  // Re-export types and classes
28
29
  var messages_1 = require("./messages");
29
30
  Object.defineProperty(exports, "HumanMessage", { enumerable: true, get: function () { return messages_1.HumanMessage; } });
@@ -58,20 +59,18 @@ function createChatModel(model, config) {
58
59
  ...config.headers,
59
60
  },
60
61
  };
61
- switch (config.provider) {
62
- case "doubao":
63
- case "aihubmix":
64
- case "api2img":
65
- return new openai_1.ChatOpenAI({
66
- modelName: model,
67
- ...finalConfig,
68
- });
69
- case "gemini":
70
- return new google_1.ChatGoogleGenerativeAI({
71
- modelName: model,
72
- ...finalConfig,
73
- });
74
- default:
75
- throw new Error(`Unsupported provider: ${config.provider}`);
62
+ const providerConfig = (0, provider_config_1.getProviderConfig)(config.provider);
63
+ if (!providerConfig) {
64
+ throw new Error(`Unsupported provider: ${config.provider}`);
76
65
  }
66
+ if (providerConfig.modelType === "gemini") {
67
+ return new google_1.ChatGoogleGenerativeAI({
68
+ modelName: model,
69
+ ...finalConfig,
70
+ });
71
+ }
72
+ return new openai_1.ChatOpenAI({
73
+ modelName: model,
74
+ ...finalConfig,
75
+ });
77
76
  }
@@ -10,7 +10,7 @@ export interface OpenAIVideoGenerationConfig {
10
10
  export interface OpenAIVideoGenerationRequest {
11
11
  prompt: string;
12
12
  model?: string;
13
- provider?: "aihubmix" | "api2img";
13
+ provider?: "aihubmix" | "shubiaobiao" | "api2img";
14
14
  seconds?: "4" | "8" | "12";
15
15
  size?: "720x1280" | "1280x720" | "1024x1792" | "1792x1024";
16
16
  input_reference?: string;
@@ -107,7 +107,7 @@ export declare class OpenAIVideoGenerationClient {
107
107
  * }
108
108
  * ```
109
109
  */
110
- getTask(taskId: string, provider: "aihubmix" | "api2img"): Promise<OpenAIVideoTaskResponse>;
110
+ getTask(taskId: string, provider: "aihubmix" | "shubiaobiao" | "api2img"): Promise<OpenAIVideoTaskResponse>;
111
111
  /**
112
112
  * 轮询等待任务完成
113
113
  * Poll and wait for task completion
@@ -125,7 +125,7 @@ export declare class OpenAIVideoGenerationClient {
125
125
  * console.log('Video URL:', result.url);
126
126
  * ```
127
127
  */
128
- waitForCompletion(taskId: string, provider?: "aihubmix" | "api2img", options?: {
128
+ waitForCompletion(taskId: string, provider?: "aihubmix" | "shubiaobiao" | "api2img", options?: {
129
129
  maxAttempts?: number;
130
130
  interval?: number;
131
131
  onProgress?: (status: OpenAIVideoTaskResponse) => void;
@@ -184,5 +184,5 @@ export declare class OpenAIVideoGenerationClient {
184
184
  * const thumbnail = await client.downloadVideo('vid_abc123', 'aihubmix', 'thumbnail');
185
185
  * ```
186
186
  */
187
- downloadVideo(taskId: string, provider?: "aihubmix" | "api2img", variant?: "video" | "thumbnail"): Promise<Blob>;
187
+ downloadVideo(taskId: string, provider?: "aihubmix" | "shubiaobiao" | "api2img", variant?: "video" | "thumbnail"): Promise<Blob>;
188
188
  }
@@ -0,0 +1,8 @@
1
+ export type AIModelProvider = "aihubmix" | "api2img" | "doubao" | "gemini" | "shubiaobiao";
2
+ export type ProviderModelType = "openai" | "gemini";
3
+ export interface ProviderConfig {
4
+ provider: AIModelProvider;
5
+ modelType: ProviderModelType;
6
+ }
7
+ export declare const PROVIDER_CONFIGS: Record<AIModelProvider, ProviderConfig>;
8
+ export declare function getProviderConfig(provider: AIModelProvider): ProviderConfig;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PROVIDER_CONFIGS = void 0;
4
+ exports.getProviderConfig = getProviderConfig;
5
+ exports.PROVIDER_CONFIGS = {
6
+ aihubmix: { provider: "aihubmix", modelType: "openai" },
7
+ shubiaobiao: { provider: "shubiaobiao", modelType: "openai" },
8
+ api2img: { provider: "api2img", modelType: "openai" },
9
+ doubao: { provider: "doubao", modelType: "openai" },
10
+ gemini: { provider: "gemini", modelType: "gemini" },
11
+ };
12
+ function getProviderConfig(provider) {
13
+ return exports.PROVIDER_CONFIGS[provider];
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-world-sdk",
3
- "version": "1.1.2",
3
+ "version": "1.1.5",
4
4
  "description": "TypeScript SDK for AI World Platform - Chat Models, Image Generation, and Video Generation",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",