ai-world-sdk 1.2.7 → 1.3.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/dist/login.js CHANGED
@@ -39,6 +39,7 @@ var __importStar = (this && this.__importStar) || (function () {
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.resolvePluginId = resolvePluginId;
41
41
  exports.validateToken = validateToken;
42
+ exports.ensurePort = ensurePort;
42
43
  exports.readEnvLocal = readEnvLocal;
43
44
  exports.writeEnvLocal = writeEnvLocal;
44
45
  exports.performLogin = performLogin;
@@ -106,8 +107,40 @@ function validateToken(baseUrl, token) {
106
107
  }
107
108
  /**
108
109
  * 强制确保端口可用:如果被占用则 kill 占用进程
110
+ * - Unix: lsof -ti:PORT → kill -9 PID; sleep 0.3
111
+ * - Windows: netstat -ano | findstr :PORT → taskkill /F /PID PID; timeout /t 1 /nobreak >nul
109
112
  */
110
113
  function ensurePort(port) {
114
+ const isWin = process.platform === "win32";
115
+ if (isWin) {
116
+ try {
117
+ const out = (0, child_process_1.execSync)(`netstat -ano | findstr :${port}`, {
118
+ encoding: "utf-8",
119
+ });
120
+ const pids = new Set();
121
+ for (const line of out.split("\n")) {
122
+ const m = line.trim().split(/\s+/);
123
+ const pid = m[m.length - 1];
124
+ if (pid && /^\d+$/.test(pid))
125
+ pids.add(pid);
126
+ }
127
+ for (const pid of pids) {
128
+ try {
129
+ (0, child_process_1.execSync)(`taskkill /F /PID ${pid}`, { stdio: "ignore" });
130
+ }
131
+ catch {
132
+ // pid may have already exited
133
+ }
134
+ }
135
+ if (pids.size > 0) {
136
+ (0, child_process_1.execSync)("timeout /t 1 /nobreak >nul", { stdio: "ignore" });
137
+ }
138
+ }
139
+ catch {
140
+ // findstr returns non-zero when no match — port is free
141
+ }
142
+ return;
143
+ }
111
144
  try {
112
145
  const result = (0, child_process_1.execSync)(`lsof -ti:${port}`, { encoding: "utf-8" }).trim();
113
146
  if (result) {
@@ -120,7 +153,6 @@ function ensurePort(port) {
120
153
  // pid may have already exited
121
154
  }
122
155
  }
123
- // Brief wait for OS to release the port
124
156
  (0, child_process_1.execSync)("sleep 0.3");
125
157
  }
126
158
  }
@@ -7,10 +7,11 @@ export interface OpenAIVideoGenerationConfig {
7
7
  token?: string;
8
8
  headers?: Record<string, string>;
9
9
  }
10
+ export type OpenAIVideoGenerationProvider = "shubiaobiao" | "api2img" | "aiping";
10
11
  export interface OpenAIVideoGenerationRequest {
11
12
  prompt: string;
12
13
  model?: string;
13
- provider?: "shubiaobiao" | "api2img";
14
+ provider?: OpenAIVideoGenerationProvider;
14
15
  seconds?: "4" | "8" | "12";
15
16
  size?: "720x1280" | "1280x720" | "1024x1792" | "1792x1024";
16
17
  input_reference?: string;
@@ -107,7 +108,7 @@ export declare class OpenAIVideoGenerationClient {
107
108
  * }
108
109
  * ```
109
110
  */
110
- getTask(taskId: string, provider: "shubiaobiao" | "api2img"): Promise<OpenAIVideoTaskResponse>;
111
+ getTask(taskId: string, provider: OpenAIVideoGenerationProvider): Promise<OpenAIVideoTaskResponse>;
111
112
  /**
112
113
  * 轮询等待任务完成
113
114
  * Poll and wait for task completion
@@ -125,7 +126,7 @@ export declare class OpenAIVideoGenerationClient {
125
126
  * console.log('Video URL:', result.url);
126
127
  * ```
127
128
  */
128
- waitForCompletion(taskId: string, provider?: "shubiaobiao" | "api2img", options?: {
129
+ waitForCompletion(taskId: string, provider?: OpenAIVideoGenerationProvider, options?: {
129
130
  maxAttempts?: number;
130
131
  interval?: number;
131
132
  onProgress?: (status: OpenAIVideoTaskResponse) => void;
@@ -184,5 +185,5 @@ export declare class OpenAIVideoGenerationClient {
184
185
  * const thumbnail = await client.downloadVideo('vid_abc123', 'api2img', 'thumbnail');
185
186
  * ```
186
187
  */
187
- downloadVideo(taskId: string, provider?: "shubiaobiao" | "api2img", variant?: "video" | "thumbnail"): Promise<Blob>;
188
+ downloadVideo(taskId: string, provider?: OpenAIVideoGenerationProvider, variant?: "video" | "thumbnail"): Promise<Blob>;
188
189
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 模型提供商
3
3
  */
4
- export type AIModelProvider = "api2img" | "aihubmix" | "doubao" | "gemini" | "shubiaobiao" | "anthropic";
4
+ export type AIModelProvider = "api2img" | "aihubmix" | "doubao" | "gemini" | "shubiaobiao" | "anthropic" | "aiping" | "openrouter";
5
5
  /**
6
6
  * 模型端点类型
7
7
  * - openai: OpenAI 兼容 API(/v1/chat/completions 等)
@@ -5,10 +5,12 @@ exports.getProviderConfig = getProviderConfig;
5
5
  exports.PROVIDER_CONFIGS = {
6
6
  shubiaobiao: { provider: "shubiaobiao", modelType: "openai" },
7
7
  api2img: { provider: "api2img", modelType: "openai" },
8
+ aiping: { provider: "aiping", modelType: "openai" },
8
9
  aihubmix: { provider: "aihubmix", modelType: "openai" },
9
10
  doubao: { provider: "doubao", modelType: "openai" },
10
11
  gemini: { provider: "gemini", modelType: "gemini" },
11
12
  anthropic: { provider: "anthropic", modelType: "anthropic" },
13
+ openrouter: { provider: "openrouter", modelType: "openai" },
12
14
  };
13
15
  function getProviderConfig(provider) {
14
16
  return exports.PROVIDER_CONFIGS[provider];
@@ -0,0 +1,102 @@
1
+ /**
2
+ * AI World SDK - VSCode Extension Login
3
+ * 完整 VSCode 扩展登录集成,一步到位初始化
4
+ *
5
+ * 使用方式(最简):
6
+ * import { initAIWorld } from 'ai-world-sdk/vscode';
7
+ * export async function activate(ctx: vscode.ExtensionContext) {
8
+ * const ai = await initAIWorld(ctx);
9
+ * }
10
+ *
11
+ * 导出路径: ai-world-sdk/vscode
12
+ *
13
+ * 存储:token 等信息通过 vscode.SecretStorage 持久化
14
+ * pluginId:默认取扩展 package.json 的 name 字段
15
+ */
16
+ import * as vscode from "vscode";
17
+ import { type AuthenticatedUser } from "./config";
18
+ export interface AIWorldInitOptions {
19
+ /** AI World 后端地址,默认 https://aiworld.local:8000 */
20
+ baseUrl?: string;
21
+ /** 插件 ID,不提供则取扩展 package.json 的 name */
22
+ pluginId?: string;
23
+ /** 是否在初始化时弹窗提示登录,默认 true */
24
+ autoLogin?: boolean;
25
+ /** 登录超时时间(ms),默认 120000 */
26
+ timeout?: number;
27
+ /** 本地回调服务器端口,默认 18000 */
28
+ callbackPort?: number;
29
+ /** 是否开启 debug 模式 */
30
+ debug?: boolean;
31
+ }
32
+ export declare class AIWorldExtension {
33
+ private _context;
34
+ private _baseUrl;
35
+ private _pluginId;
36
+ private _timeout;
37
+ private _callbackPort;
38
+ private _debug;
39
+ private _token;
40
+ private _user;
41
+ private _statusBar;
42
+ private _panel;
43
+ private _disposables;
44
+ private _onDidChangeAuth;
45
+ /** 认证状态变化事件 */
46
+ readonly onDidChangeAuthentication: vscode.Event<boolean>;
47
+ /** @internal 使用 initAIWorld() 创建实例 */
48
+ constructor(context: vscode.ExtensionContext, options?: AIWorldInitOptions);
49
+ get token(): string | undefined;
50
+ get user(): AuthenticatedUser | undefined;
51
+ get pluginId(): string;
52
+ get baseUrl(): string;
53
+ get isAuthenticated(): boolean;
54
+ /**
55
+ * 执行登录:有缓存 token 则验证复用,否则打开浏览器 OAuth
56
+ * 登录成功后自动配置 sdkConfig 并持久化到 SecretStorage
57
+ */
58
+ login(): Promise<string>;
59
+ /** 登出:清除 token、sdkConfig、SecretStorage */
60
+ logout(): Promise<void>;
61
+ /** 显示 / 聚焦登录 Webview 面板 */
62
+ showLoginPanel(): void;
63
+ /** 释放所有资源 */
64
+ dispose(): void;
65
+ private get _secrets();
66
+ private _loadSecrets;
67
+ private _saveSecrets;
68
+ private _clearSecrets;
69
+ private _applySdkConfig;
70
+ /** 初始化流程:读 SecretStorage → 验证 → (可选)弹窗提示登录 → 配置 SDK */
71
+ _bootstrap(autoLogin: boolean): Promise<void>;
72
+ /** 弹出小通知提示用户登录,用户点击"登录"按钮后才打开浏览器 */
73
+ private _promptLogin;
74
+ private _onLoginSuccess;
75
+ private _fetchUserInfo;
76
+ private _registerCommands;
77
+ private _updateStatusBar;
78
+ private _validateAndRefresh;
79
+ private _refreshPanel;
80
+ private _performBrowserLogin;
81
+ _getLoginPanelHtml(): string;
82
+ private _escHtml;
83
+ }
84
+ /**
85
+ * 一步初始化 AI World VSCode 扩展
86
+ *
87
+ * 自动完成:读 SecretStorage → 验证 token → 配置 sdkConfig → 注册命令 → 显示状态栏
88
+ * pluginId 默认取扩展 package.json 的 name 字段
89
+ *
90
+ * @example
91
+ * import { initAIWorld } from 'ai-world-sdk/vscode';
92
+ * export async function activate(ctx: vscode.ExtensionContext) {
93
+ * const ai = await initAIWorld(ctx);
94
+ * // sdkConfig 已自动配置,可直接使用 createProvider 等 SDK 功能
95
+ * }
96
+ */
97
+ export declare function initAIWorld(context: vscode.ExtensionContext, options?: AIWorldInitOptions): Promise<AIWorldExtension>;
98
+ /**
99
+ * 获取已初始化的 AIWorldExtension 实例
100
+ * @throws 如果 initAIWorld 尚未调用
101
+ */
102
+ export declare function getAIWorld(): AIWorldExtension;