wtfai 1.3.2 → 1.4.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.
- package/README.md +10 -5
- package/dist/client.d.ts +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/session.d.ts +4 -0
- package/dist/session.js +46 -2
- package/dist/sse.d.ts +1 -1
- package/dist/types.d.ts +10 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -301,13 +301,18 @@ const url = await client.upload.uploadImage({
|
|
|
301
301
|
消息类型(与后端保持一致)。
|
|
302
302
|
|
|
303
303
|
```typescript
|
|
304
|
+
/** 消息内容部件 */
|
|
305
|
+
type WorkflowMessagePart =
|
|
306
|
+
| { type: 'text'; text: string }
|
|
307
|
+
| { type: 'image'; url: string }
|
|
308
|
+
| { type: 'video'; url: string }
|
|
309
|
+
| { type: 'audio'; url: string }
|
|
310
|
+
| { type: 'document'; filename: string; url: string }
|
|
311
|
+
|
|
304
312
|
interface SimpleMessage {
|
|
305
|
-
type: 'human' | 'ai' | 'system'
|
|
306
|
-
|
|
313
|
+
type: 'human' | 'ai' | 'system' | 'tool'
|
|
314
|
+
parts: WorkflowMessagePart[]
|
|
307
315
|
id?: string
|
|
308
|
-
images?: string[]
|
|
309
|
-
videos?: string[]
|
|
310
|
-
documents?: Array<{ filename: string; url: string }>
|
|
311
316
|
}
|
|
312
317
|
```
|
|
313
318
|
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Workflow, WorkflowListResponse } from '@our-llm/shared/
|
|
1
|
+
import type { Workflow, WorkflowListResponse } from '@our-llm/shared/types';
|
|
2
2
|
import type { ClientConfig, SessionOptions } from './types';
|
|
3
3
|
import { WorkflowSession } from './session';
|
|
4
4
|
import { UploadService } from './upload';
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,5 @@ export default Wtfai;
|
|
|
3
3
|
export { WorkflowSession } from './session';
|
|
4
4
|
export { UploadService } from './upload';
|
|
5
5
|
export type { ClientConfig, SessionOptions, SessionState, SessionEventListeners, SendInput, UploadParams, UploadImageParams, CompressOptions, WorkflowInfo, ContentPart, } from './types';
|
|
6
|
-
export type { SimpleMessage } from '@our-llm/shared/
|
|
7
|
-
export type { Workflow, WorkflowConfig } from '@our-llm/shared/workflow.types';
|
|
6
|
+
export type { SimpleMessage, Workflow, WorkflowConfig, } from '@our-llm/shared/types';
|
|
8
7
|
export { Markdown } from './ui/markdown';
|
package/dist/session.d.ts
CHANGED
package/dist/session.js
CHANGED
|
@@ -69,7 +69,12 @@ class WorkflowSession {
|
|
|
69
69
|
break;
|
|
70
70
|
case 'image':
|
|
71
71
|
{
|
|
72
|
-
const
|
|
72
|
+
const file = 'file' in part ? part.file : void 0;
|
|
73
|
+
const url = 'url' in part ? part.url : void 0;
|
|
74
|
+
const imageUrl = await this.resolveImageUrl({
|
|
75
|
+
file,
|
|
76
|
+
url
|
|
77
|
+
});
|
|
73
78
|
contentParts.push({
|
|
74
79
|
type: 'image',
|
|
75
80
|
url: imageUrl
|
|
@@ -87,6 +92,15 @@ class WorkflowSession {
|
|
|
87
92
|
});
|
|
88
93
|
break;
|
|
89
94
|
}
|
|
95
|
+
case 'video':
|
|
96
|
+
{
|
|
97
|
+
const videoUrl = await this.resolveVideoUrl(part);
|
|
98
|
+
contentParts.push({
|
|
99
|
+
type: 'video',
|
|
100
|
+
url: videoUrl
|
|
101
|
+
});
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
90
104
|
}
|
|
91
105
|
const executionInput = {
|
|
92
106
|
messages: [
|
|
@@ -107,11 +121,17 @@ class WorkflowSession {
|
|
|
107
121
|
type: 'image',
|
|
108
122
|
url: part.url
|
|
109
123
|
};
|
|
124
|
+
case 'video':
|
|
125
|
+
return {
|
|
126
|
+
type: 'video',
|
|
127
|
+
url: part.url
|
|
128
|
+
};
|
|
110
129
|
case 'document':
|
|
111
130
|
return {
|
|
112
131
|
type: 'document',
|
|
113
132
|
filename: part.filename,
|
|
114
|
-
url: part.url
|
|
133
|
+
url: part.url,
|
|
134
|
+
mimeType: part.mimeType
|
|
115
135
|
};
|
|
116
136
|
default:
|
|
117
137
|
throw new Error(`Unknown part type: ${part.type}`);
|
|
@@ -305,6 +325,30 @@ class WorkflowSession {
|
|
|
305
325
|
}
|
|
306
326
|
throw new Error('Document part must have either file or url');
|
|
307
327
|
}
|
|
328
|
+
async resolveVideoUrl(part) {
|
|
329
|
+
if (part.file) return this.uploadService.uploadFile({
|
|
330
|
+
file: part.file,
|
|
331
|
+
resourceType: 'conversation'
|
|
332
|
+
});
|
|
333
|
+
if (part.url) {
|
|
334
|
+
if (part.url.startsWith('blob:')) {
|
|
335
|
+
const response = await fetch(part.url);
|
|
336
|
+
const blob = await response.blob();
|
|
337
|
+
const filename = `video_${Date.now()}.${blob.type.split('/')[1] || 'mp4'}`;
|
|
338
|
+
const file = new File([
|
|
339
|
+
blob
|
|
340
|
+
], filename, {
|
|
341
|
+
type: blob.type
|
|
342
|
+
});
|
|
343
|
+
return this.uploadService.uploadFile({
|
|
344
|
+
file,
|
|
345
|
+
resourceType: 'conversation'
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
return part.url;
|
|
349
|
+
}
|
|
350
|
+
throw new Error('Video part must have either file or url');
|
|
351
|
+
}
|
|
308
352
|
abort() {
|
|
309
353
|
if (this.abortController) {
|
|
310
354
|
this.abortController.abort();
|
package/dist/sse.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WorkflowStartData, NodeStartData, NodeEndData, TokenData, LoadingData, TitleData } from '@our-llm/shared/
|
|
1
|
+
import type { WorkflowStartData, NodeStartData, NodeEndData, TokenData, LoadingData, TitleData } from '@our-llm/shared/types';
|
|
2
2
|
/**
|
|
3
3
|
* SSE 事件回调
|
|
4
4
|
*/
|
package/dist/types.d.ts
CHANGED
|
@@ -79,6 +79,14 @@ export type ContentPart = {
|
|
|
79
79
|
filename: string;
|
|
80
80
|
/** MIME 类型 */
|
|
81
81
|
mimeType: string;
|
|
82
|
+
} | {
|
|
83
|
+
type: 'video';
|
|
84
|
+
/** 视频文件(会自动上传) */
|
|
85
|
+
file: File;
|
|
86
|
+
} | {
|
|
87
|
+
type: 'video';
|
|
88
|
+
/** 视频 URL(支持 blob URL 和普通 URL) */
|
|
89
|
+
url: string;
|
|
82
90
|
};
|
|
83
91
|
/**
|
|
84
92
|
* 发送消息的输入
|
|
@@ -121,7 +129,7 @@ export interface SessionEventListeners {
|
|
|
121
129
|
nodeEnd: (data: {
|
|
122
130
|
nodeId: string;
|
|
123
131
|
variables?: Record<string, unknown>;
|
|
124
|
-
messages?: import('@our-llm/shared/
|
|
132
|
+
messages?: import('@our-llm/shared/types').SimpleMessage[];
|
|
125
133
|
}) => void;
|
|
126
134
|
token: (data: {
|
|
127
135
|
nodeId: string;
|
|
@@ -148,7 +156,7 @@ export interface SessionState {
|
|
|
148
156
|
/** 线程 ID */
|
|
149
157
|
threadId?: string;
|
|
150
158
|
/** 消息列表 */
|
|
151
|
-
messages: import('@our-llm/shared/
|
|
159
|
+
messages: import('@our-llm/shared/types').SimpleMessage[];
|
|
152
160
|
/** 是否正在执行 */
|
|
153
161
|
isExecuting: boolean;
|
|
154
162
|
/** 当前执行节点 ID */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wtfai",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"compressorjs": "^1.2.1",
|
|
39
39
|
"cos-js-sdk-v5": "^1.10.1",
|
|
40
40
|
"uuid": "^13.0.0",
|
|
41
|
-
"@our-llm/shared": "
|
|
41
|
+
"@our-llm/shared": "3.0.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "rslib build",
|