@howone/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,434 @@
1
+ import React, { Component, ReactNode } from 'react';
2
+ import { AxiosResponse, InternalAxiosRequestConfig, AxiosRequestConfig, AxiosInstance } from 'axios';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+
5
+ interface FloatingButtonProps {
6
+ text?: string;
7
+ onClick?: () => void;
8
+ className?: string;
9
+ }
10
+ declare const FloatingButton: React.FC<FloatingButtonProps>;
11
+
12
+ /**
13
+ * 统一认证服务
14
+ *
15
+ * 提供多种认证功能,包括:
16
+ * - Google OAuth 认证
17
+ * - GitHub OAuth 认证
18
+ * - 邮箱验证码认证
19
+ * - Token 验证和管理
20
+ * - 退出登录
21
+ */
22
+ /**
23
+ * 发送验证码请求接口
24
+ */
25
+ interface SendCodeRequest {
26
+ /** 邮箱地址 */
27
+ email: string;
28
+ /** 来源 URL */
29
+ from_url: string;
30
+ /** 应用 ID(可选) */
31
+ app_id?: string;
32
+ /** 应用名称(可选) */
33
+ app_name?: string;
34
+ }
35
+ /**
36
+ * 发送验证码响应接口
37
+ */
38
+ interface SendCodeResponse {
39
+ /** 是否成功 */
40
+ success: boolean;
41
+ /** 消息(可选) */
42
+ message?: string;
43
+ /** 过期时间(秒)(可选) */
44
+ expiresIn?: number;
45
+ /** 状态码(可选,用于处理业务逻辑错误) */
46
+ code?: number;
47
+ /** 数据对象(可选,用于处理业务逻辑错误) */
48
+ data?: {
49
+ success: boolean;
50
+ message?: string;
51
+ code?: number;
52
+ };
53
+ /** 追踪 ID(可选) */
54
+ traceId?: number;
55
+ }
56
+ /**
57
+ * 邮箱登录请求接口
58
+ */
59
+ interface EmailLoginRequest {
60
+ /** 邮箱地址 */
61
+ email: string;
62
+ /** 验证码 */
63
+ code: string;
64
+ /** 来源 URL */
65
+ from_url: string;
66
+ /** 应用 ID(可选) */
67
+ app_id?: string;
68
+ }
69
+ /**
70
+ * 邮箱登录响应接口
71
+ */
72
+ interface EmailLoginResponse {
73
+ /** 是否成功 */
74
+ success: boolean;
75
+ /** JWT token(可选) */
76
+ token?: string;
77
+ /** 用户信息(可选) */
78
+ user?: {
79
+ email: string;
80
+ name?: string;
81
+ };
82
+ /** 重定向 URL(可选) */
83
+ redirect_url?: string;
84
+ /** 消息(可选) */
85
+ message?: string;
86
+ /** 状态码(可选,用于处理业务逻辑错误) */
87
+ code?: number;
88
+ /** 数据对象(可选,用于处理业务逻辑错误) */
89
+ data?: {
90
+ success: boolean;
91
+ message?: string;
92
+ code?: number;
93
+ };
94
+ /** 追踪 ID(可选) */
95
+ traceId?: number;
96
+ }
97
+ declare class UnifiedAuthService {
98
+ private readonly API_BASE_URL;
99
+ /**
100
+ * 初始化 Google 登录流程
101
+ * @returns 包含 token 和用户信息的 Promise
102
+ */
103
+ initiateGoogleLogin(): Promise<{
104
+ token: string;
105
+ user?: any;
106
+ }>;
107
+ /**
108
+ * 打开 OAuth 认证弹窗
109
+ * @param authUrl 认证 URL
110
+ * @returns 包含 token 和用户信息的 Promise
111
+ */
112
+ private openOAuthPopup;
113
+ /**
114
+ * 初始化 GitHub 登录流程
115
+ * @returns 包含 token 和用户信息的 Promise
116
+ */
117
+ initiateGitHubLogin(): Promise<{
118
+ token: string;
119
+ user?: any;
120
+ }>;
121
+ /**
122
+ * 发送邮箱验证码
123
+ * @param email 邮箱地址
124
+ * @param appName 应用名称(可选)
125
+ * @returns 发送结果 Promise
126
+ */
127
+ sendEmailVerificationCode(email: string, appName?: string): Promise<SendCodeResponse>;
128
+ /**
129
+ * 邮箱验证码登录
130
+ * @param email 邮箱地址
131
+ * @param code 验证码
132
+ * @returns 登录结果 Promise
133
+ */
134
+ loginWithEmailCode(email: string, code: string): Promise<EmailLoginResponse>;
135
+ /**
136
+ * 获取验证码状态(调试用)
137
+ * @param email 邮箱地址
138
+ * @returns 验证码状态 Promise
139
+ */
140
+ getCodeStatus(email: string): Promise<any>;
141
+ private generateAppId;
142
+ /**
143
+ * 检查 OAuth 回调
144
+ * 从 URL 参数中获取 token 和错误信息
145
+ * @returns 包含 token、用户信息和错误的对象
146
+ */
147
+ checkOAuthCallback(): {
148
+ success: boolean;
149
+ token?: string;
150
+ error?: string;
151
+ user?: any;
152
+ };
153
+ /**
154
+ * 验证 token 是否有效
155
+ * @param token JWT token
156
+ * @returns 包含有效状态和用户信息的 Promise
157
+ */
158
+ verifyToken(token: string): Promise<{
159
+ valid: boolean;
160
+ user?: any;
161
+ }>;
162
+ /**
163
+ * 从本地存储获取认证数据
164
+ */
165
+ private getSavedAuthData;
166
+ /**
167
+ * 保存认证数据到本地存储
168
+ */
169
+ private saveAuthData;
170
+ /**
171
+ * 退出登录
172
+ * @param token JWT token
173
+ */
174
+ logout(token: string): Promise<void>;
175
+ }
176
+ declare const unifiedAuth: UnifiedAuthService;
177
+ declare const unifiedOAuth: UnifiedAuthService;
178
+ declare function sendEmailVerificationCode(email: string, appName?: string): Promise<SendCodeResponse>;
179
+ declare function loginWithEmailCode(email: string, code: string): Promise<EmailLoginResponse>;
180
+ declare function getCodeStatus(email: string): Promise<any>;
181
+
182
+ /**
183
+ * AI Workflow 服务(精简版,仅支持按 ID 的 path 风格执行)
184
+ *
185
+ * 说明:模板仅需要一种执行接口,形如 POST {baseUrl}/workflow/{workflowId}/execute
186
+ */
187
+ interface AIWorkflowResponse {
188
+ success: boolean;
189
+ output?: Record<string, unknown>;
190
+ error?: string;
191
+ metadata?: Record<string, unknown>;
192
+ }
193
+ interface AIWorkflowClientOptions {
194
+ baseUrl?: string;
195
+ apiKey?: string;
196
+ headers?: Record<string, string>;
197
+ fetchImpl?: typeof fetch;
198
+ }
199
+ declare class AIWorkflowClient {
200
+ private readonly baseUrl;
201
+ private readonly apiKey?;
202
+ private readonly headers;
203
+ private readonly fetchImpl;
204
+ constructor(options?: AIWorkflowClientOptions);
205
+ private buildHeaders;
206
+ private safeJson;
207
+ /**
208
+ * 按 ID 执行工作流:POST {baseUrl}/workflow/{workflowId}/execute
209
+ * body: { input, options }
210
+ */
211
+ executeWorkflow(workflowId: string, input: Record<string, unknown>, options?: Record<string, unknown>): Promise<AIWorkflowResponse>;
212
+ }
213
+ declare function createAIWorkflowClient(options?: AIWorkflowClientOptions): AIWorkflowClient;
214
+ declare const aiWorkflow: AIWorkflowClient;
215
+
216
+ interface RequestInterceptors<T = AxiosResponse> {
217
+ requestInterceptor?: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig;
218
+ requestInterceptorCatch?: (error: any) => any;
219
+ responseInterceptor?: (res: T) => T;
220
+ responseInterceptorCatch?: (error: any) => any;
221
+ }
222
+ interface RequestConfig<T = AxiosResponse> extends AxiosRequestConfig {
223
+ interceptors?: RequestInterceptors<T>;
224
+ showLoading?: boolean;
225
+ }
226
+
227
+ declare class Request {
228
+ instance: AxiosInstance;
229
+ interceptors?: RequestInterceptors;
230
+ abortControllers: Map<string, AbortController>;
231
+ constructor(config: RequestConfig);
232
+ cancelRequest(url: string): void;
233
+ cancelAllRequests(): void;
234
+ request<T = any>(config: RequestConfig<T>): Promise<T>;
235
+ get<T = any>(config: RequestConfig<T>): Promise<T>;
236
+ post<T = any>(config: RequestConfig<T>): Promise<T>;
237
+ delete<T = any>(config: RequestConfig<T>): Promise<T>;
238
+ put<T = any>(config: RequestConfig<T>): Promise<T>;
239
+ patch<T = any>(config: RequestConfig<T>): Promise<T>;
240
+ }
241
+
242
+ interface AxiosAIWorkflowOptions {
243
+ baseUrl?: string;
244
+ basePath?: string;
245
+ apiKey?: string;
246
+ timeout?: number;
247
+ headers?: Record<string, string>;
248
+ requestInstance?: Request;
249
+ /** 'body' (default) or 'path' for /workflow/{id}/execute */
250
+ workflowEndpointStyle?: 'body' | 'path';
251
+ }
252
+ /**
253
+ * Create an AI workflow client backed by the project's Request (axios) wrapper.
254
+ * If `requestInstance` is provided it will be used directly; otherwise a new Request will be created.
255
+ */
256
+ declare function createAIWorkflowClientAxios(options?: AxiosAIWorkflowOptions): {
257
+ executeWorkflow(workflowId: string, input: Record<string, unknown>, opts?: Record<string, unknown>): Promise<AIWorkflowResponse>;
258
+ };
259
+
260
+ type Visibility = 'private' | 'project' | 'public' | 'shared';
261
+ interface Artifact {
262
+ id: string;
263
+ ownerId?: string | null;
264
+ projectId?: string | null;
265
+ visibility: Visibility;
266
+ storageUrl: string;
267
+ thumbnailUrl?: string;
268
+ input?: any;
269
+ output?: any;
270
+ model?: string;
271
+ metadata?: Record<string, any>;
272
+ createdAt?: string;
273
+ likes?: number;
274
+ stats?: {
275
+ views?: number;
276
+ };
277
+ sharedWith?: string[];
278
+ }
279
+ interface ArtifactCreateInput {
280
+ storageUrl: string;
281
+ thumbnailUrl?: string;
282
+ visibility?: Visibility;
283
+ metadata?: Record<string, any>;
284
+ model?: string;
285
+ ownerId?: string;
286
+ projectId?: string;
287
+ }
288
+ interface ArtifactListQuery {
289
+ ownerId?: string;
290
+ projectId?: string;
291
+ visibility?: Visibility;
292
+ limit?: number;
293
+ cursor?: string;
294
+ }
295
+ interface AccessContext {
296
+ userId?: string | null;
297
+ projectId?: string | null;
298
+ tokenScopes?: string[];
299
+ }
300
+ /**
301
+ * Basic client-side permission check for an artifact.
302
+ * Note: final authorization must be enforced on the server. This is a convenience helper.
303
+ */
304
+ declare function canAccessArtifact(a: Artifact, ctx?: AccessContext): boolean;
305
+
306
+ declare function createArtifactsClient(req: Request): {
307
+ create(input: ArtifactCreateInput): Promise<Artifact>;
308
+ list(query?: ArtifactListQuery): Promise<Artifact[]>;
309
+ get(id: string): Promise<Artifact>;
310
+ setVisibility(id: string, visibility: string): Promise<void>;
311
+ delete(id: string): Promise<void>;
312
+ canAccessLocal(a: Artifact, ctx: AccessContext): boolean;
313
+ };
314
+
315
+ declare const request: Request;
316
+ declare const aiRequest: Request;
317
+ declare const workflowRequest: Request;
318
+ /**
319
+ * 简单工厂:返回一个对外友好的 client,封装业务 request 与 AI workflow request。
320
+ * 默认使用上面导出的 `request` 和 `aiRequest`,也可以通过 options 覆盖。
321
+ */
322
+ /**
323
+ * Higher-level factory: createClient
324
+ * - minimal surface compatible with `createClient({ projectId, authRequired })`
325
+ * - returns executeWorkflow, request, aiRequest and a tiny auth helper (set/get token)
326
+ */
327
+ declare function createClient(opts?: {
328
+ projectId?: string;
329
+ authRequired?: boolean;
330
+ baseUrl?: string;
331
+ aiBaseUrl?: string;
332
+ mode?: 'auto' | 'standalone' | 'embedded';
333
+ auth?: {
334
+ mode?: 'none' | 'managed' | 'headless';
335
+ getToken?: () => Promise<string | null>;
336
+ tokenInjection?: {
337
+ allowedOrigins?: string[];
338
+ waitMs?: number;
339
+ };
340
+ };
341
+ requestInstance?: Request;
342
+ aiRequestInstance?: Request;
343
+ }): {
344
+ request: Request;
345
+ aiRequest: Request;
346
+ workflowRequest: Request;
347
+ artifacts: {
348
+ create(input: ArtifactCreateInput): Promise<Artifact>;
349
+ list(query?: ArtifactListQuery): Promise<Artifact[]>;
350
+ get(id: string): Promise<Artifact>;
351
+ setVisibility(id: string, visibility: string): Promise<void>;
352
+ delete(id: string): Promise<void>;
353
+ };
354
+ auth: {
355
+ setToken: (t: string | null) => void;
356
+ getToken: () => string | null;
357
+ isAuthenticated: () => boolean;
358
+ login: (redirect?: string) => void;
359
+ logout: () => void;
360
+ };
361
+ };
362
+
363
+ interface LoginFormProps {
364
+ onLoginSuccess?: () => void;
365
+ appName?: string;
366
+ className?: string;
367
+ }
368
+ declare const LoginForm: React.FC<LoginFormProps>;
369
+
370
+ interface AuthGuardProps {
371
+ children: React.ReactNode;
372
+ fallback?: React.ReactNode;
373
+ redirectTo?: string;
374
+ requireAuth?: boolean;
375
+ roles?: string[];
376
+ permissions?: string[];
377
+ }
378
+ declare const AuthGuard: React.FC<AuthGuardProps>;
379
+
380
+ interface LoadingProps {
381
+ size?: 'sm' | 'md' | 'lg';
382
+ text?: string;
383
+ className?: string;
384
+ fullScreen?: boolean;
385
+ }
386
+ declare const Loading: React.FC<LoadingProps>;
387
+ interface LoadingSpinnerProps {
388
+ size?: 'sm' | 'md' | 'lg';
389
+ className?: string;
390
+ }
391
+ declare const LoadingSpinner: React.FC<LoadingSpinnerProps>;
392
+
393
+ interface ErrorBoundaryState {
394
+ hasError: boolean;
395
+ error?: Error;
396
+ errorInfo?: React.ErrorInfo;
397
+ }
398
+ interface ErrorBoundaryProps {
399
+ children: ReactNode;
400
+ fallback?: React.ComponentType<{
401
+ error?: Error;
402
+ retry?: () => void;
403
+ }>;
404
+ onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
405
+ }
406
+ declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
407
+ constructor(props: ErrorBoundaryProps);
408
+ static getDerivedStateFromError(error: Error): ErrorBoundaryState;
409
+ componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void;
410
+ handleRetry: () => void;
411
+ render(): string | number | boolean | react_jsx_runtime.JSX.Element | Iterable<React.ReactNode> | null | undefined;
412
+ }
413
+ interface ErrorFallbackProps {
414
+ error?: Error;
415
+ retry?: () => void;
416
+ }
417
+ declare const DefaultErrorFallback: React.FC<ErrorFallbackProps>;
418
+
419
+ declare function useIsMobile(): boolean;
420
+
421
+ declare function useLocalStorage<T>(key: string, initialValue: T): readonly [T, (value: T | ((val: T) => T)) => void, () => void];
422
+
423
+ declare function useDebounce<T>(value: T, delay: number): T;
424
+
425
+ /**
426
+ * Early error handler injector
427
+ * This module provides a runtime function to inject the original
428
+ * `error-handler.js` script into the page. The script is executed
429
+ * as soon as it's injected, providing early capture of runtime and
430
+ * Vite overlay errors for the host app.
431
+ */
432
+ declare function injectEarlyErrorHandler(): void;
433
+
434
+ export { type AIWorkflowClientOptions, type AIWorkflowResponse, type AccessContext, type Artifact, type ArtifactCreateInput, type ArtifactListQuery, AuthGuard, type AxiosAIWorkflowOptions, DefaultErrorFallback, type EmailLoginRequest, type EmailLoginResponse, ErrorBoundary, FloatingButton, Loading, LoadingSpinner, LoginForm, type SendCodeRequest, type SendCodeResponse, type Visibility, aiRequest, aiWorkflow, canAccessArtifact, createAIWorkflowClient, createAIWorkflowClientAxios, createArtifactsClient, createClient, getCodeStatus, injectEarlyErrorHandler, loginWithEmailCode, request, sendEmailVerificationCode, unifiedAuth, unifiedOAuth, useDebounce, useIsMobile, useLocalStorage, workflowRequest };