@howone/sdk 0.2.21 → 0.3.1
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/index.d.mts +500 -1
- package/dist/index.d.ts +500 -1
- package/dist/index.js +5299 -4253
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5294 -4252
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,139 @@ interface FloatingButtonProps {
|
|
|
11
11
|
}
|
|
12
12
|
declare const FloatingButton: React$1.FC<FloatingButtonProps>;
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* 统一的 SSE 工作流执行模块
|
|
16
|
+
*
|
|
17
|
+
* 集成所有 SSE 相关功能:
|
|
18
|
+
* - 流式执行 (streaming execution)
|
|
19
|
+
* - 事件处理 (event handling)
|
|
20
|
+
* - 完整数据收集 (complete data collection)
|
|
21
|
+
* - 上下文管理 (context management)
|
|
22
|
+
*
|
|
23
|
+
* 提供统一的 API 给 client 使用
|
|
24
|
+
*/
|
|
25
|
+
interface SSEEventPayload {
|
|
26
|
+
type: string;
|
|
27
|
+
data?: Record<string, unknown>;
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
interface NodeExecution {
|
|
31
|
+
nodeName: string;
|
|
32
|
+
content: string;
|
|
33
|
+
timestamp: number;
|
|
34
|
+
}
|
|
35
|
+
interface CostUpdate {
|
|
36
|
+
token: number;
|
|
37
|
+
totalToken: number;
|
|
38
|
+
cost: number;
|
|
39
|
+
totalCost: number;
|
|
40
|
+
timestamp: number;
|
|
41
|
+
}
|
|
42
|
+
interface ExecutionResult {
|
|
43
|
+
success: boolean;
|
|
44
|
+
finalResult: Record<string, unknown> | null;
|
|
45
|
+
nodeExecutions: NodeExecution[];
|
|
46
|
+
costUpdates: CostUpdate[];
|
|
47
|
+
totalDuration: number;
|
|
48
|
+
errors: string[];
|
|
49
|
+
}
|
|
50
|
+
interface SSEExecutionOptions {
|
|
51
|
+
onEvent?: (event: SSEEventPayload) => void;
|
|
52
|
+
onNodeStart?: (nodeName: string, content: string) => void;
|
|
53
|
+
onStreamContent?: (delta: string) => void;
|
|
54
|
+
onCostUpdate?: (cost: CostUpdate) => void;
|
|
55
|
+
onProgress?: (progress: number) => void;
|
|
56
|
+
onLog?: (message: string) => void;
|
|
57
|
+
onStreamChunk?: (chunk: string) => void;
|
|
58
|
+
onError?: (error: Error) => void;
|
|
59
|
+
onComplete?: (result: ExecutionResult) => void;
|
|
60
|
+
signal?: AbortSignal;
|
|
61
|
+
}
|
|
62
|
+
interface SSEWorkflowRequestInit {
|
|
63
|
+
url: string;
|
|
64
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
65
|
+
body?: Record<string, unknown>;
|
|
66
|
+
headers?: Record<string, string>;
|
|
67
|
+
}
|
|
68
|
+
declare function executeSSEWorkflow(request: SSEWorkflowRequestInit, options?: SSEExecutionOptions & {
|
|
69
|
+
authToken?: string;
|
|
70
|
+
}): Promise<ExecutionResult>;
|
|
71
|
+
interface SSERequest {
|
|
72
|
+
(config: {
|
|
73
|
+
workflowId?: string;
|
|
74
|
+
inputs?: Record<string, unknown>;
|
|
75
|
+
url?: string;
|
|
76
|
+
body?: Record<string, unknown>;
|
|
77
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
78
|
+
headers?: Record<string, string>;
|
|
79
|
+
signal?: AbortSignal;
|
|
80
|
+
onEvent?: (event: SSEEventPayload) => void;
|
|
81
|
+
onNodeStart?: (nodeName: string, content: string) => void;
|
|
82
|
+
onStreamContent?: (delta: string) => void;
|
|
83
|
+
onCostUpdate?: (cost: CostUpdate) => void;
|
|
84
|
+
onProgress?: (progress: number) => void;
|
|
85
|
+
onLog?: (message: string) => void;
|
|
86
|
+
onStreamChunk?: (chunk: string) => void;
|
|
87
|
+
onError?: (error: Error) => void;
|
|
88
|
+
onComplete?: (result: ExecutionResult) => void;
|
|
89
|
+
}): Promise<ExecutionResult>;
|
|
90
|
+
}
|
|
91
|
+
declare function createSSERequest(baseUrl: string, projectId?: string, getAuthToken?: () => string | null): SSERequest;
|
|
92
|
+
|
|
93
|
+
type SSEStreamCallbacks = Omit<SSEExecutionOptions, "signal" | "authToken">;
|
|
94
|
+
type SSEStreamConfig = {
|
|
95
|
+
workflowId?: string;
|
|
96
|
+
inputs?: Record<string, unknown>;
|
|
97
|
+
url?: string;
|
|
98
|
+
body?: Record<string, unknown>;
|
|
99
|
+
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
100
|
+
headers?: Record<string, string>;
|
|
101
|
+
signal?: AbortSignal;
|
|
102
|
+
} & SSEStreamCallbacks;
|
|
103
|
+
type SSEWorkflowOptions = Omit<SSEStreamConfig, "workflowId" | "inputs" | "url" | "body">;
|
|
104
|
+
interface SSESession {
|
|
105
|
+
/** Promise for the underlying execution result. */
|
|
106
|
+
result: Promise<ExecutionResult>;
|
|
107
|
+
/** Abort the running SSE request. Safe to call multiple times. */
|
|
108
|
+
cancel: () => void;
|
|
109
|
+
/** The abort signal used for the fetch call. */
|
|
110
|
+
signal: AbortSignal;
|
|
111
|
+
}
|
|
112
|
+
interface SSEClientConfig {
|
|
113
|
+
baseUrl: string;
|
|
114
|
+
projectId?: string;
|
|
115
|
+
getAuthToken?: () => string | null;
|
|
116
|
+
}
|
|
117
|
+
interface SSEClient {
|
|
118
|
+
/**
|
|
119
|
+
* Starts an SSE session (workflowId or url required) and returns controls.
|
|
120
|
+
* The returned session starts immediately.
|
|
121
|
+
*/
|
|
122
|
+
stream(config: SSEStreamConfig): SSESession;
|
|
123
|
+
/**
|
|
124
|
+
* Convenience wrapper over `stream` that resolves once the SSE completes.
|
|
125
|
+
*/
|
|
126
|
+
execute(config: SSEStreamConfig): Promise<ExecutionResult>;
|
|
127
|
+
/**
|
|
128
|
+
* Workflow-specific sugar for `stream`.
|
|
129
|
+
*/
|
|
130
|
+
streamWorkflow(workflowId: string, inputs?: Record<string, unknown>, options?: SSEWorkflowOptions): SSESession;
|
|
131
|
+
/**
|
|
132
|
+
* Workflow-specific sugar for `execute`.
|
|
133
|
+
*/
|
|
134
|
+
executeWorkflow(workflowId: string, inputs?: Record<string, unknown>, options?: SSEWorkflowOptions): Promise<ExecutionResult>;
|
|
135
|
+
/**
|
|
136
|
+
* Returns an async iterable of raw SSE events. Useful for `for await`.
|
|
137
|
+
* Note: the iterable owns the session and ensures cleanup on completion.
|
|
138
|
+
*/
|
|
139
|
+
events(config: SSEStreamConfig): AsyncIterable<SSEEventPayload>;
|
|
140
|
+
/**
|
|
141
|
+
* Workflow-specific sugar for `events`.
|
|
142
|
+
*/
|
|
143
|
+
workflowEvents(workflowId: string, inputs?: Record<string, unknown>, options?: SSEWorkflowOptions): AsyncIterable<SSEEventPayload>;
|
|
144
|
+
}
|
|
145
|
+
declare function createSSEClient(config: SSEClientConfig): SSEClient;
|
|
146
|
+
|
|
14
147
|
/**
|
|
15
148
|
* 发送验证码请求接口
|
|
16
149
|
*/
|
|
@@ -342,6 +475,186 @@ declare function setDefaultProjectId(id: string | null): void;
|
|
|
342
475
|
declare function getDefaultProjectId(): string | null;
|
|
343
476
|
declare function getGlobalEnvironment(): Environment | null;
|
|
344
477
|
|
|
478
|
+
/**
|
|
479
|
+
* Workflow Stream Executor (基于 Server-Sent Events)
|
|
480
|
+
*
|
|
481
|
+
* 用于执行长时间运行的 AI workflow,通过 SSE 实时接收进度更新和结果
|
|
482
|
+
*
|
|
483
|
+
* 支持多种输出模式:
|
|
484
|
+
* 1. 流式输出 (stream) - 逐字/逐块输出,适合 AI 文本生成
|
|
485
|
+
* 2. 进度模式 (progress) - 显示执行进度,适合长时间任务
|
|
486
|
+
* 3. 完整模式 (complete) - 一次性返回结果,适合快速任务
|
|
487
|
+
* 4. 混合模式 (hybrid) - 既有流式内容又有进度,适合复杂场景
|
|
488
|
+
*
|
|
489
|
+
* 适用场景:
|
|
490
|
+
* - Workflow 执行时间 > 5 分钟
|
|
491
|
+
* - 需要实时显示进度或流式输出
|
|
492
|
+
* - 需要简单易用的 API 供 AI 生成代码使用
|
|
493
|
+
*
|
|
494
|
+
* 后端要求:
|
|
495
|
+
* - POST /workflow/{projectId}/{workflowId}/execute (返回 SSE 流)
|
|
496
|
+
* - 发送 JSON 格式的事件: data: {"type": "...", "data": {...}}
|
|
497
|
+
*/
|
|
498
|
+
interface WorkflowStreamEvent {
|
|
499
|
+
type: 'start' | 'progress' | 'stream' | 'log' | 'complete' | 'error';
|
|
500
|
+
data?: any;
|
|
501
|
+
message?: string;
|
|
502
|
+
progress?: number;
|
|
503
|
+
content?: string;
|
|
504
|
+
delta?: string;
|
|
505
|
+
timestamp?: string;
|
|
506
|
+
}
|
|
507
|
+
interface WorkflowStreamOptions {
|
|
508
|
+
onProgress?: (event: WorkflowStreamEvent) => void;
|
|
509
|
+
onStream?: (content: string, delta: string) => void;
|
|
510
|
+
onLog?: (message: string) => void;
|
|
511
|
+
onError?: (error: Error) => void;
|
|
512
|
+
signal?: AbortSignal;
|
|
513
|
+
}
|
|
514
|
+
interface WorkflowStreamResponse {
|
|
515
|
+
success: boolean;
|
|
516
|
+
output?: Record<string, unknown>;
|
|
517
|
+
streamContent?: string;
|
|
518
|
+
error?: string;
|
|
519
|
+
metadata?: Record<string, unknown>;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* 工作流执行器 - 统一的 API 接口
|
|
524
|
+
*
|
|
525
|
+
* 支持两种执行模式:
|
|
526
|
+
* 1. execute - 传统 REST 调用 (快速任务)
|
|
527
|
+
* 2. execute_sse - 流式 SSE 执行 (长时间任务)
|
|
528
|
+
*
|
|
529
|
+
* 设计原则:
|
|
530
|
+
* - AI 可以直接理解并调用
|
|
531
|
+
* - 完整的数据解析和提取
|
|
532
|
+
* - 统一的错误处理
|
|
533
|
+
* - 支持所有事件类型
|
|
534
|
+
*/
|
|
535
|
+
interface ExecutionLogData {
|
|
536
|
+
log_type: 'node_start' | 'cost_update' | 'execution_complete' | 'stream' | 'log' | string;
|
|
537
|
+
workflow_id: string;
|
|
538
|
+
content: string;
|
|
539
|
+
result?: Record<string, unknown>;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* 解析后的工作流执行结果
|
|
543
|
+
*/
|
|
544
|
+
interface ParsedWorkflowResult {
|
|
545
|
+
success: boolean;
|
|
546
|
+
workflowId: string;
|
|
547
|
+
projectId: string;
|
|
548
|
+
executionDuration: number;
|
|
549
|
+
nodeExecutions: Array<{
|
|
550
|
+
nodeName: string;
|
|
551
|
+
content: string;
|
|
552
|
+
timestamp?: number;
|
|
553
|
+
}>;
|
|
554
|
+
costStats: {
|
|
555
|
+
token: number;
|
|
556
|
+
totalToken: number;
|
|
557
|
+
cost: number;
|
|
558
|
+
totalCost: number;
|
|
559
|
+
};
|
|
560
|
+
executionLogs: ExecutionLogData[];
|
|
561
|
+
finalResult?: Record<string, unknown>;
|
|
562
|
+
streamContent?: string;
|
|
563
|
+
metadata?: Record<string, unknown>;
|
|
564
|
+
errors: string[];
|
|
565
|
+
}
|
|
566
|
+
interface WorkflowExecutorOptions {
|
|
567
|
+
onProgress?: (event: {
|
|
568
|
+
type: string;
|
|
569
|
+
progress?: number;
|
|
570
|
+
message?: string;
|
|
571
|
+
data?: any;
|
|
572
|
+
}) => void;
|
|
573
|
+
onNodeStart?: (nodeName: string, content: string) => void;
|
|
574
|
+
onCostUpdate?: (stats: {
|
|
575
|
+
token: number;
|
|
576
|
+
totalToken: number;
|
|
577
|
+
cost: number;
|
|
578
|
+
totalCost: number;
|
|
579
|
+
}) => void;
|
|
580
|
+
onStreamContent?: (delta: string, fullContent: string) => void;
|
|
581
|
+
onLog?: (message: string) => void;
|
|
582
|
+
onComplete?: (result: ParsedWorkflowResult) => void;
|
|
583
|
+
onError?: (error: Error) => void;
|
|
584
|
+
signal?: AbortSignal;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* 工作流执行器类
|
|
588
|
+
*
|
|
589
|
+
* 统一处理 execute 和 execute_sse 两种接口
|
|
590
|
+
* 并完整解析返回的数据
|
|
591
|
+
*/
|
|
592
|
+
declare class WorkflowExecutor {
|
|
593
|
+
private baseUrl;
|
|
594
|
+
private projectId;
|
|
595
|
+
private authToken?;
|
|
596
|
+
constructor(baseUrl: string, projectId: string, authToken?: string);
|
|
597
|
+
/**
|
|
598
|
+
* 执行工作流 (SSE 模式)
|
|
599
|
+
*
|
|
600
|
+
* 适用于长时间运行的工作流,支持流式输出和进度更新
|
|
601
|
+
*
|
|
602
|
+
* @example
|
|
603
|
+
* ```typescript
|
|
604
|
+
* const executor = new WorkflowExecutor(baseUrl, projectId, token);
|
|
605
|
+
*
|
|
606
|
+
* const result = await executor.executeSse(
|
|
607
|
+
* 'workflow-id',
|
|
608
|
+
* { prompt: 'Generate a story' },
|
|
609
|
+
* {
|
|
610
|
+
* onNodeStart: (nodeName) => console.log(`执行节点: ${nodeName}`),
|
|
611
|
+
* onStreamContent: (delta) => process.stdout.write(delta),
|
|
612
|
+
* onCostUpdate: (stats) => console.log(`token: ${stats.totalToken}`),
|
|
613
|
+
* }
|
|
614
|
+
* );
|
|
615
|
+
*
|
|
616
|
+
* console.log('最终结果:', result.finalResult);
|
|
617
|
+
* console.log('总成本:', result.costStats.totalCost);
|
|
618
|
+
* ```
|
|
619
|
+
*/
|
|
620
|
+
executeSse(workflowId: string, inputs: Record<string, unknown>, options?: WorkflowExecutorOptions): Promise<ParsedWorkflowResult>;
|
|
621
|
+
/**
|
|
622
|
+
* 执行工作流 (REST 模式)
|
|
623
|
+
*
|
|
624
|
+
* 适用于快速任务,直接返回结果
|
|
625
|
+
*
|
|
626
|
+
* @example
|
|
627
|
+
* ```typescript
|
|
628
|
+
* const executor = new WorkflowExecutor(baseUrl, projectId, token);
|
|
629
|
+
*
|
|
630
|
+
* const result = await executor.execute(
|
|
631
|
+
* 'workflow-id',
|
|
632
|
+
* { prompt: 'Quick task' }
|
|
633
|
+
* );
|
|
634
|
+
*
|
|
635
|
+
* console.log(result.data);
|
|
636
|
+
* ```
|
|
637
|
+
*/
|
|
638
|
+
execute(workflowId: string, inputs: Record<string, unknown>): Promise<{
|
|
639
|
+
status: number;
|
|
640
|
+
data?: any;
|
|
641
|
+
error?: string;
|
|
642
|
+
}>;
|
|
643
|
+
/**
|
|
644
|
+
* 设置认证 Token
|
|
645
|
+
*/
|
|
646
|
+
setAuthToken(token: string): void;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
type LegacySSERequestFunction = (config: SSEStreamConfig) => Promise<ExecutionResult>;
|
|
650
|
+
type LegacySSERequest = LegacySSERequestFunction & {
|
|
651
|
+
stream: SSEClient["stream"];
|
|
652
|
+
execute: SSEClient["execute"];
|
|
653
|
+
events: SSEClient["events"];
|
|
654
|
+
streamWorkflow: SSEClient["streamWorkflow"];
|
|
655
|
+
executeWorkflow: SSEClient["executeWorkflow"];
|
|
656
|
+
workflowEvents: SSEClient["workflowEvents"];
|
|
657
|
+
};
|
|
345
658
|
/**
|
|
346
659
|
* Higher-level factory: createClient
|
|
347
660
|
* - minimal surface compatible with `createClient({ projectId, authRequired })`
|
|
@@ -350,11 +663,13 @@ declare function getGlobalEnvironment(): Environment | null;
|
|
|
350
663
|
declare function createClient(opts: {
|
|
351
664
|
projectId: string;
|
|
352
665
|
env?: 'local' | 'dev' | 'prod';
|
|
666
|
+
baseUrl?: string;
|
|
353
667
|
authRequired?: boolean;
|
|
354
668
|
mode?: "auto" | "standalone" | "embedded";
|
|
355
669
|
auth?: {
|
|
356
670
|
mode?: "none" | "managed" | "headless";
|
|
357
671
|
getToken?: () => Promise<string | null>;
|
|
672
|
+
tokenCacheMs?: number;
|
|
358
673
|
tokenInjection?: {
|
|
359
674
|
allowedOrigins?: string[];
|
|
360
675
|
waitMs?: number;
|
|
@@ -386,6 +701,152 @@ declare function createClient(opts: {
|
|
|
386
701
|
cancelRequest: (url: string) => void;
|
|
387
702
|
cancelAllRequests: () => void;
|
|
388
703
|
};
|
|
704
|
+
sse: {
|
|
705
|
+
request: {
|
|
706
|
+
request: (config: SSEStreamConfig) => Promise<ExecutionResult>;
|
|
707
|
+
post: (config: SSEStreamConfig) => Promise<ExecutionResult>;
|
|
708
|
+
get: (config: SSEStreamConfig) => Promise<ExecutionResult>;
|
|
709
|
+
put: (config: SSEStreamConfig) => Promise<ExecutionResult>;
|
|
710
|
+
patch: (config: SSEStreamConfig) => Promise<ExecutionResult>;
|
|
711
|
+
delete: (config: SSEStreamConfig) => Promise<ExecutionResult>;
|
|
712
|
+
};
|
|
713
|
+
stream: {
|
|
714
|
+
request: (config: SSEStreamConfig) => SSESession;
|
|
715
|
+
post: (config: SSEStreamConfig) => SSESession;
|
|
716
|
+
get: (config: SSEStreamConfig) => SSESession;
|
|
717
|
+
put: (config: SSEStreamConfig) => SSESession;
|
|
718
|
+
patch: (config: SSEStreamConfig) => SSESession;
|
|
719
|
+
delete: (config: SSEStreamConfig) => SSESession;
|
|
720
|
+
};
|
|
721
|
+
events: {
|
|
722
|
+
request: (config: SSEStreamConfig) => AsyncIterable<SSEEventPayload>;
|
|
723
|
+
post: (config: SSEStreamConfig) => AsyncIterable<SSEEventPayload>;
|
|
724
|
+
get: (config: SSEStreamConfig) => AsyncIterable<SSEEventPayload>;
|
|
725
|
+
put: (config: SSEStreamConfig) => AsyncIterable<SSEEventPayload>;
|
|
726
|
+
patch: (config: SSEStreamConfig) => AsyncIterable<SSEEventPayload>;
|
|
727
|
+
delete: (config: SSEStreamConfig) => AsyncIterable<SSEEventPayload>;
|
|
728
|
+
};
|
|
729
|
+
workflow: {
|
|
730
|
+
execute: (workflowId: string, inputs?: Record<string, unknown>, options?: SSEWorkflowOptions) => Promise<ExecutionResult>;
|
|
731
|
+
stream: (workflowId: string, inputs?: Record<string, unknown>, options?: SSEWorkflowOptions) => SSESession;
|
|
732
|
+
events: (workflowId: string, inputs?: Record<string, unknown>, options?: SSEWorkflowOptions) => AsyncIterable<SSEEventPayload>;
|
|
733
|
+
};
|
|
734
|
+
execute: (config: SSEStreamConfig) => Promise<ExecutionResult>;
|
|
735
|
+
streamWorkflow: (workflowId: string, inputs?: Record<string, unknown>, options?: SSEWorkflowOptions) => SSESession;
|
|
736
|
+
executeWorkflow: (workflowId: string, inputs?: Record<string, unknown>, options?: SSEWorkflowOptions) => Promise<ExecutionResult>;
|
|
737
|
+
workflowEvents: (workflowId: string, inputs?: Record<string, unknown>, options?: SSEWorkflowOptions) => AsyncIterable<SSEEventPayload>;
|
|
738
|
+
};
|
|
739
|
+
/**
|
|
740
|
+
* ✨ 新的简化 SSE API(推荐)
|
|
741
|
+
*
|
|
742
|
+
* projectId 已内部绑定,只需传 workflowId 和 inputs
|
|
743
|
+
*
|
|
744
|
+
* @example
|
|
745
|
+
* ```typescript
|
|
746
|
+
* const result = await client.sse.request.post({
|
|
747
|
+
* workflowId: 'workflow-id',
|
|
748
|
+
* inputs: { prompt: 'Generate story' },
|
|
749
|
+
* onNodeStart: (name) => console.log(`执行: ${name}`),
|
|
750
|
+
* onStreamContent: (delta) => console.log(`内容: ${delta}`),
|
|
751
|
+
* onCostUpdate: (stats) => console.log(`Token: ${stats.totalToken}`)
|
|
752
|
+
* })
|
|
753
|
+
*
|
|
754
|
+
* // 也可以获取流式控制:
|
|
755
|
+
* const session = client.sse.stream.post({ workflowId, inputs: {...} })
|
|
756
|
+
* const events = client.sse.events.post({ workflowId, inputs: {...} })
|
|
757
|
+
* ```
|
|
758
|
+
*/
|
|
759
|
+
sseRequest: LegacySSERequest;
|
|
760
|
+
workflow: {
|
|
761
|
+
request: {
|
|
762
|
+
get: <T = any>(config: RequestConfig<T>) => Promise<T>;
|
|
763
|
+
post: (config: RequestConfig) => Promise<AxiosResponse<any, any>>;
|
|
764
|
+
put: <T = any>(config: RequestConfig<T>) => Promise<T>;
|
|
765
|
+
delete: <T = any>(config: RequestConfig<T>) => Promise<T>;
|
|
766
|
+
request: <T = any>(config: RequestConfig<T>) => Promise<T>;
|
|
767
|
+
cancelRequest: (url: string) => void;
|
|
768
|
+
cancelAllRequests: () => void;
|
|
769
|
+
};
|
|
770
|
+
stream: (workflowId: string, inputs?: Record<string, unknown>, options?: SSEWorkflowOptions) => SSESession;
|
|
771
|
+
execute: (workflowId: string, inputs?: Record<string, unknown>, options?: SSEWorkflowOptions) => Promise<ExecutionResult>;
|
|
772
|
+
events: (workflowId: string, inputs?: Record<string, unknown>, options?: SSEWorkflowOptions) => AsyncIterable<SSEEventPayload>;
|
|
773
|
+
sse: {
|
|
774
|
+
execute: (workflowId: string, inputs?: Record<string, unknown>, options?: SSEWorkflowOptions) => Promise<ExecutionResult>;
|
|
775
|
+
stream: (workflowId: string, inputs?: Record<string, unknown>, options?: SSEWorkflowOptions) => SSESession;
|
|
776
|
+
events: (workflowId: string, inputs?: Record<string, unknown>, options?: SSEWorkflowOptions) => AsyncIterable<SSEEventPayload>;
|
|
777
|
+
};
|
|
778
|
+
executeStream: (workflowId: string, inputs: Record<string, unknown>, streamOptions?: WorkflowStreamOptions) => Promise<WorkflowStreamResponse>;
|
|
779
|
+
executor: (workflowId: string) => {
|
|
780
|
+
executeSse: (inputs: Record<string, unknown>, options?: WorkflowExecutorOptions) => Promise<ParsedWorkflowResult>;
|
|
781
|
+
execute: (inputs: Record<string, unknown>) => Promise<{
|
|
782
|
+
status: number;
|
|
783
|
+
data?: any;
|
|
784
|
+
error?: string;
|
|
785
|
+
}>;
|
|
786
|
+
_executor: WorkflowExecutor;
|
|
787
|
+
};
|
|
788
|
+
};
|
|
789
|
+
/**
|
|
790
|
+
* 执行长时间运行的 workflow (使用 SSE 流式传输)
|
|
791
|
+
*
|
|
792
|
+
* 适用于执行时间 > 5 分钟的 workflow,通过 SSE 实时接收进度更新
|
|
793
|
+
*
|
|
794
|
+
* @example
|
|
795
|
+
* ```typescript
|
|
796
|
+
* const result = await client.executeWorkflowStream(
|
|
797
|
+
* 'workflow-id',
|
|
798
|
+
* { prompt: 'Generate app' },
|
|
799
|
+
* {
|
|
800
|
+
* onProgress: (event) => {
|
|
801
|
+
* console.log('进度:', event.progress, '%')
|
|
802
|
+
* }
|
|
803
|
+
* }
|
|
804
|
+
* )
|
|
805
|
+
* ```
|
|
806
|
+
*/
|
|
807
|
+
executeWorkflowStream: (workflowId: string, inputs: Record<string, unknown>, streamOptions?: WorkflowStreamOptions) => Promise<WorkflowStreamResponse>;
|
|
808
|
+
/**
|
|
809
|
+
* 创建工作流执行器 (推荐方式)
|
|
810
|
+
*
|
|
811
|
+
* 统一支持 execute 和 execute_sse 两种接口
|
|
812
|
+
* 自动完整解析所有事件和数据
|
|
813
|
+
*
|
|
814
|
+
* @example
|
|
815
|
+
* ```typescript
|
|
816
|
+
* // 1. 故事生成工作流 (SSE 流式执行)
|
|
817
|
+
* const executor = client.workflowExecutor('workflow-id');
|
|
818
|
+
*
|
|
819
|
+
* const result = await executor.executeSse(
|
|
820
|
+
* { prompt: 'Generate a story' },
|
|
821
|
+
* {
|
|
822
|
+
* onNodeStart: (nodeName) => console.log(`执行节点: ${nodeName}`),
|
|
823
|
+
* onCostUpdate: (stats) => console.log(`Token: ${stats.totalToken}`),
|
|
824
|
+
* onStreamContent: (delta) => process.stdout.write(delta),
|
|
825
|
+
* onComplete: (result) => {
|
|
826
|
+
* console.log('最终结果:', result.finalResult);
|
|
827
|
+
* console.log('总成本:', result.costStats.totalCost);
|
|
828
|
+
* }
|
|
829
|
+
* }
|
|
830
|
+
* );
|
|
831
|
+
*
|
|
832
|
+
* // 2. 快速任务 (REST 直接调用)
|
|
833
|
+
* const result = await executor.execute({ prompt: 'Quick task' });
|
|
834
|
+
*
|
|
835
|
+
* // 3. 访问完整的执行数据
|
|
836
|
+
* console.log('节点序列:', result.nodeExecutions.map(n => n.nodeName));
|
|
837
|
+
* console.log('流式内容:', result.streamContent);
|
|
838
|
+
* console.log('执行时长:', result.executionDuration, 'ms');
|
|
839
|
+
* ```
|
|
840
|
+
*/
|
|
841
|
+
workflowExecutor: (workflowId: string) => {
|
|
842
|
+
executeSse: (inputs: Record<string, unknown>, options?: WorkflowExecutorOptions) => Promise<ParsedWorkflowResult>;
|
|
843
|
+
execute: (inputs: Record<string, unknown>) => Promise<{
|
|
844
|
+
status: number;
|
|
845
|
+
data?: any;
|
|
846
|
+
error?: string;
|
|
847
|
+
}>;
|
|
848
|
+
_executor: WorkflowExecutor;
|
|
849
|
+
};
|
|
389
850
|
artifacts: {
|
|
390
851
|
create(input: ArtifactCreateInput): Promise<Artifact>;
|
|
391
852
|
list(query?: ArtifactListQuery): Promise<Artifact[]>;
|
|
@@ -631,6 +1092,44 @@ declare function useElementSelector(): UseElementSelectorReturn;
|
|
|
631
1092
|
*/
|
|
632
1093
|
declare function sendElementSelectionToParent(data: ElementSelectionData): void;
|
|
633
1094
|
|
|
1095
|
+
interface UseWorkflowStreamState {
|
|
1096
|
+
loading: boolean;
|
|
1097
|
+
progress: number;
|
|
1098
|
+
streamContent: string;
|
|
1099
|
+
logs: string[];
|
|
1100
|
+
result: WorkflowStreamResponse | null;
|
|
1101
|
+
error: Error | null;
|
|
1102
|
+
}
|
|
1103
|
+
/**
|
|
1104
|
+
* React Hook 用于执行长时间运行的 workflow (基于 SSE)
|
|
1105
|
+
*
|
|
1106
|
+
* 支持多种模式:
|
|
1107
|
+
* 1. 流式输出 - 实时显示 AI 生成的内容
|
|
1108
|
+
* 2. 进度显示 - 显示任务执行进度
|
|
1109
|
+
* 3. 日志输出 - 显示执行日志
|
|
1110
|
+
* 4. 混合模式 - 同时支持以上所有功能
|
|
1111
|
+
*
|
|
1112
|
+
* @example
|
|
1113
|
+
* ```typescript
|
|
1114
|
+
* // 流式输出示例
|
|
1115
|
+
* const { execute, state } = useWorkflowStream()
|
|
1116
|
+
*
|
|
1117
|
+
* await execute('workflow-id', { prompt: 'Write a story' })
|
|
1118
|
+
*
|
|
1119
|
+
* // 显示流式内容
|
|
1120
|
+
* <div>{state.streamContent}</div>
|
|
1121
|
+
*
|
|
1122
|
+
* // 显示进度
|
|
1123
|
+
* <progress value={state.progress} max="100" />
|
|
1124
|
+
* ```
|
|
1125
|
+
*/
|
|
1126
|
+
declare function useWorkflowStream(): {
|
|
1127
|
+
execute: (executeWorkflowStream: (workflowId: string, inputs: Record<string, unknown>, options?: WorkflowStreamOptions) => Promise<WorkflowStreamResponse>, workflowId: string, inputs: Record<string, unknown>) => Promise<WorkflowStreamResponse>;
|
|
1128
|
+
cancel: () => void;
|
|
1129
|
+
reset: () => void;
|
|
1130
|
+
state: UseWorkflowStreamState;
|
|
1131
|
+
};
|
|
1132
|
+
|
|
634
1133
|
/**
|
|
635
1134
|
* 错误处理模块 - 核心类型定义
|
|
636
1135
|
*
|
|
@@ -970,4 +1469,4 @@ declare const elementSelector: {
|
|
|
970
1469
|
isActive: () => boolean;
|
|
971
1470
|
};
|
|
972
1471
|
|
|
973
|
-
export { type AIWorkflowClientOptions, type AIWorkflowResponse, AUTH_TOKEN_KEY, type AccessContext, type Artifact, type ArtifactCreateInput, type ArtifactListQuery, type AxiosAIWorkflowOptions, ClayxButton, ClayxToast, DEFAULT_SELECTOR_CONFIG, DefaultErrorFallback, ERROR_CONFIG, type ElementSelectionData, ElementSelector, ElementSelectorProvider, type EmailLoginRequest, type EmailLoginResponse, type EnhancedErrorConfig, type Environment, ErrorBoundary, ErrorHandler, type ErrorPayload, type ErrorSeverity, type ErrorStats, type ErrorType, FloatingButton, GLOBAL_CONFIG, GlobalToastContainer, HowOneProvider, type HowOneProviderProps, Loading, LoadingSpinner, LoginForm, type MessageType, type SelectorState, type SendCodeRequest, type SendCodeResponse, type SimpleErrorConfig, SimpleErrorHandler, type SourceLocation, ThemeProvider, ThemeToggle, type UseElementSelectorReturn, type UserInteraction, type ViewInfo, type Visibility, aiWorkflow, canAccessArtifact, createAIWorkflowClient, createAIWorkflowClientAxios, createArtifactsClient, createClient, elementSelector, type envs, getCodeStatus, getDefaultProjectId, getEnvironment, getEnvs, getGlobalEnvironment, getToken, howone, iframeNavigation, initIframeNavigation, isTokenValid, loginWithEmailCode, onAuthStateChanged, parseUserFromToken, sendElementSelectionToParent, sendEmailVerificationCode, setDefaultProjectId, setEnvironment, setToken, showLimitUpgradeToast, unifiedAuth, unifiedOAuth, useAuth, useDebounce, useElementSelector, useHowoneContext, useIsMobile, useTheme };
|
|
1472
|
+
export { type AIWorkflowClientOptions, type AIWorkflowResponse, AUTH_TOKEN_KEY, type AccessContext, type Artifact, type ArtifactCreateInput, type ArtifactListQuery, type AxiosAIWorkflowOptions, ClayxButton, ClayxToast, type CostUpdate, DEFAULT_SELECTOR_CONFIG, DefaultErrorFallback, ERROR_CONFIG, type ElementSelectionData, ElementSelector, ElementSelectorProvider, type EmailLoginRequest, type EmailLoginResponse, type EnhancedErrorConfig, type Environment, ErrorBoundary, ErrorHandler, type ErrorPayload, type ErrorSeverity, type ErrorStats, type ErrorType, type ExecutionResult, FloatingButton, GLOBAL_CONFIG, GlobalToastContainer, HowOneProvider, type HowOneProviderProps, Loading, LoadingSpinner, LoginForm, type MessageType, type NodeExecution, type SSEClient, type SSEClientConfig, type SSEEventPayload, type SSEExecutionOptions, type SSERequest, type SSESession, type SSEStreamConfig, type SSEWorkflowOptions, type SSEWorkflowRequestInit, type SelectorState, type SendCodeRequest, type SendCodeResponse, type SimpleErrorConfig, SimpleErrorHandler, type SourceLocation, ThemeProvider, ThemeToggle, type UseElementSelectorReturn, type UseWorkflowStreamState, type UserInteraction, type ViewInfo, type Visibility, aiWorkflow, canAccessArtifact, createAIWorkflowClient, createAIWorkflowClientAxios, createArtifactsClient, createClient, createSSEClient, createSSERequest, elementSelector, type envs, executeSSEWorkflow, getCodeStatus, getDefaultProjectId, getEnvironment, getEnvs, getGlobalEnvironment, getToken, howone, iframeNavigation, initIframeNavigation, isTokenValid, loginWithEmailCode, onAuthStateChanged, parseUserFromToken, sendElementSelectionToParent, sendEmailVerificationCode, setDefaultProjectId, setEnvironment, setToken, showLimitUpgradeToast, unifiedAuth, unifiedOAuth, useAuth, useDebounce, useElementSelector, useHowoneContext, useIsMobile, useTheme, useWorkflowStream };
|