wtfai 1.8.9 → 1.8.11
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 +4 -47
- package/dist/client.d.ts +0 -5
- package/dist/client.js +0 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.js +0 -1
- package/dist/session.d.ts +3 -2
- package/dist/session.js +5 -3
- package/dist/types.d.ts +11 -3
- package/dist/upload.d.ts +2 -2
- package/dist/upload.js +6 -6
- package/package.json +2 -2
- package/dist/realtime.d.ts +0 -23
- package/dist/realtime.js +0 -85
package/README.md
CHANGED
|
@@ -600,7 +600,8 @@ canvas.toBlob(async (blob) => {
|
|
|
600
600
|
|
|
601
601
|
// 指定资源类型
|
|
602
602
|
const url = await IframeBridge.uploadFile(file, {
|
|
603
|
-
resourceType: 'conversation' // 'conversation' | 'workflow' | 'knowledge-base'
|
|
603
|
+
resourceType: 'conversation', // 'conversation' | 'workflow' | 'knowledge-base'
|
|
604
|
+
bucketType: 'private' // 'public' | 'private',默认 private
|
|
604
605
|
});
|
|
605
606
|
```
|
|
606
607
|
|
|
@@ -748,52 +749,6 @@ Content-Type: application/json
|
|
|
748
749
|
- 工作流被中断后会触发 `error` 事件,`message` 为传入的 `reason`
|
|
749
750
|
- 如果找不到对应的执行会话,返回 404
|
|
750
751
|
|
|
751
|
-
---
|
|
752
|
-
|
|
753
|
-
---
|
|
754
|
-
|
|
755
|
-
### RealtimeService
|
|
756
|
-
|
|
757
|
-
提供跨端的实时消息总线功能(通过 `client.realtime` 访问)。
|
|
758
|
-
|
|
759
|
-
##### `subscribe(topic: string, onEvent: (event: RealtimeEvent) => void)`
|
|
760
|
-
|
|
761
|
-
订阅实时消息流。适合大屏端监听由其他端发送的指令或通知。
|
|
762
|
-
|
|
763
|
-
- **自动管理**:方法内部会自动计算并附加当前浏览器的设备指纹(deviceId),激活在线状态追踪。
|
|
764
|
-
- **返回值**:返回一个对象,包含 `unsubscribe()` 方法用于断开连接。
|
|
765
|
-
|
|
766
|
-
```typescript
|
|
767
|
-
const sub = await client.realtime.subscribe('class:101', (event) => {
|
|
768
|
-
console.log('收到实时更新:', event.data);
|
|
769
|
-
// event.event 为事件名称,event.data 为业务数据
|
|
770
|
-
});
|
|
771
|
-
|
|
772
|
-
// 当页面销毁或不需要监听时,请务必手动释放:
|
|
773
|
-
// sub.unsubscribe();
|
|
774
|
-
```
|
|
775
|
-
|
|
776
|
-
##### `push(topic: string, event: string, data: any)`
|
|
777
|
-
|
|
778
|
-
推送实时消息。适合手机端(或其他客户端)发送指令。
|
|
779
|
-
|
|
780
|
-
```typescript
|
|
781
|
-
await client.realtime.push('class:101', 'msgA', {
|
|
782
|
-
foo: 'bar'
|
|
783
|
-
});
|
|
784
|
-
```
|
|
785
|
-
|
|
786
|
-
##### `getPresence(topic: string)`
|
|
787
|
-
|
|
788
|
-
获取指定主题下的在线状态详情(如当前有多少个大屏在线)。
|
|
789
|
-
|
|
790
|
-
```typescript
|
|
791
|
-
const { onlineCount, clients } = await client.realtime.getPresence('class:101');
|
|
792
|
-
console.log(`当前在线设备数: ${onlineCount}`);
|
|
793
|
-
```
|
|
794
|
-
|
|
795
|
-
---
|
|
796
|
-
|
|
797
752
|
### UploadService
|
|
798
753
|
|
|
799
754
|
文件上传服务(通过 `client.upload` 访问)。
|
|
@@ -806,6 +761,7 @@ console.log(`当前在线设备数: ${onlineCount}`);
|
|
|
806
761
|
const url = await client.upload.uploadFile({
|
|
807
762
|
file: file,
|
|
808
763
|
resourceType: 'conversation', // 'conversation' | 'workflow' | 'knowledge-base'
|
|
764
|
+
bucketType: 'private', // 'public' | 'private',默认 private
|
|
809
765
|
onProgress: (percent) => {
|
|
810
766
|
console.log(`上传进度: ${percent * 100}%`)
|
|
811
767
|
},
|
|
@@ -820,6 +776,7 @@ const url = await client.upload.uploadFile({
|
|
|
820
776
|
const url = await client.upload.uploadImage({
|
|
821
777
|
file: imageFile,
|
|
822
778
|
resourceType: 'conversation',
|
|
779
|
+
bucketType: 'public',
|
|
823
780
|
onProgress: (percent) => console.log(`${percent * 100}%`),
|
|
824
781
|
compressOptions: { // 可选
|
|
825
782
|
quality: 0.8,
|
package/dist/client.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ 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';
|
|
5
|
-
import { RealtimeService } from './realtime';
|
|
6
5
|
/**
|
|
7
6
|
* Wtfai 客户端
|
|
8
7
|
*
|
|
@@ -34,10 +33,6 @@ export declare class Wtfai {
|
|
|
34
33
|
* 文件上传服务
|
|
35
34
|
*/
|
|
36
35
|
readonly upload: UploadService;
|
|
37
|
-
/**
|
|
38
|
-
* 实时同步服务
|
|
39
|
-
*/
|
|
40
|
-
readonly realtime: RealtimeService;
|
|
41
36
|
private readonly headers;
|
|
42
37
|
constructor(config: ClientConfig);
|
|
43
38
|
/**
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { WorkflowSession } from "./session.js";
|
|
2
2
|
import { UploadService } from "./upload.js";
|
|
3
|
-
import { RealtimeService } from "./realtime.js";
|
|
4
3
|
function _define_property(obj, key, value) {
|
|
5
4
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
6
5
|
value: value,
|
|
@@ -37,7 +36,6 @@ class Wtfai {
|
|
|
37
36
|
_define_property(this, "baseUrl", void 0);
|
|
38
37
|
_define_property(this, "uploadService", void 0);
|
|
39
38
|
_define_property(this, "upload", void 0);
|
|
40
|
-
_define_property(this, "realtime", void 0);
|
|
41
39
|
_define_property(this, "headers", void 0);
|
|
42
40
|
this.baseUrl = (config.baseUrl || 'https://llm-api.ourschool.cc').replace(/\/$/, '');
|
|
43
41
|
const headers = {
|
|
@@ -50,7 +48,6 @@ class Wtfai {
|
|
|
50
48
|
this.headers = headers;
|
|
51
49
|
this.uploadService = new UploadService(this.baseUrl, this.headers);
|
|
52
50
|
this.upload = this.uploadService;
|
|
53
|
-
this.realtime = new RealtimeService(this.baseUrl, this.headers);
|
|
54
51
|
}
|
|
55
52
|
}
|
|
56
53
|
export { Wtfai };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,8 @@ import { Wtfai } from './client';
|
|
|
2
2
|
export default Wtfai;
|
|
3
3
|
export { WorkflowSession } from './session';
|
|
4
4
|
export { UploadService } from './upload';
|
|
5
|
-
export {
|
|
6
|
-
export type {
|
|
7
|
-
export type { SimpleMessage, Workflow, WorkflowConfig, RealtimeEvent, RealtimePresence, RealtimePushDto, DeviceInfoDetail, DeviceInfoListRequest, UpdateDeviceNameRequest, } from '@our-llm/shared/types';
|
|
5
|
+
export type { ClientConfig, SessionOptions, SessionState, SessionEventListeners, SendInput, UploadResourceType, BucketType, UploadParams, UploadImageParams, CompressOptions, WorkflowInfo, ContentPart, ContentAction, } from './types';
|
|
6
|
+
export type { SimpleMessage, Workflow, WorkflowConfig, DeviceInfoDetail, DeviceInfoListRequest, UpdateDeviceNameRequest, } from '@our-llm/shared/types';
|
|
8
7
|
export { Markdown, type MarkdownProps, WorkflowRegistry } from './ui/markdown';
|
|
9
8
|
export type { WorkflowInfoMapping, WorkflowExportConfig } from './ui/context';
|
|
10
9
|
export { exportMessages, createExportedMessagesBlob, createMermaidChartExportAdapter, type ChartImageExport, type ChartExportKind, type ChartExportAdapter, type ChartExportAdapterContext, type MessageExportInput, type MessageExportOptions, type ExportedMessage, type ExportedMessagePayload, } from './export';
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import { Wtfai } from "./client.js";
|
|
|
2
2
|
const src = Wtfai;
|
|
3
3
|
export { WorkflowSession } from "./session.js";
|
|
4
4
|
export { UploadService } from "./upload.js";
|
|
5
|
-
export { RealtimeService } from "./realtime.js";
|
|
6
5
|
export { Markdown, WorkflowRegistry } from "./ui/markdown.js";
|
|
7
6
|
export { createExportedMessagesBlob, createMermaidChartExportAdapter, exportMessages } from "./export.js";
|
|
8
7
|
export default src;
|
package/dist/session.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SimpleMessage, DeviceInfoDetail } from '@our-llm/shared/types';
|
|
2
|
-
import type { SessionOptions, SessionState, SessionEventListeners, SendInput, ListRecordsOptions, ListRecordsResult } from './types';
|
|
2
|
+
import type { SessionOptions, SessionState, SessionEventListeners, SendInput, ListRecordsOptions, ListRecordsResult, UploadResourceType, BucketType } from './types';
|
|
3
3
|
import { UploadService } from './upload';
|
|
4
4
|
/**
|
|
5
5
|
* 工作流会话
|
|
@@ -34,7 +34,8 @@ export declare class WorkflowSession {
|
|
|
34
34
|
base64: string;
|
|
35
35
|
filename: string;
|
|
36
36
|
mimeType: string;
|
|
37
|
-
resourceType?:
|
|
37
|
+
resourceType?: UploadResourceType;
|
|
38
|
+
bucketType?: BucketType;
|
|
38
39
|
}): Promise<string>;
|
|
39
40
|
/**
|
|
40
41
|
* 监听事件
|
package/dist/session.js
CHANGED
|
@@ -29,7 +29,7 @@ class WorkflowSession {
|
|
|
29
29
|
}
|
|
30
30
|
async uploadFileFromIframe(options) {
|
|
31
31
|
this.assertNotDisposed();
|
|
32
|
-
const { base64, filename, mimeType, resourceType = 'conversation' } = options;
|
|
32
|
+
const { base64, filename, mimeType, resourceType = 'conversation', bucketType } = options;
|
|
33
33
|
const byteString = atob(base64);
|
|
34
34
|
const arrayBuffer = new ArrayBuffer(byteString.length);
|
|
35
35
|
const uint8Array = new Uint8Array(arrayBuffer);
|
|
@@ -46,11 +46,13 @@ class WorkflowSession {
|
|
|
46
46
|
});
|
|
47
47
|
if (mimeType.startsWith('image/')) return this.uploadService.uploadImage({
|
|
48
48
|
file,
|
|
49
|
-
resourceType
|
|
49
|
+
resourceType,
|
|
50
|
+
bucketType
|
|
50
51
|
});
|
|
51
52
|
return this.uploadService.uploadFile({
|
|
52
53
|
file,
|
|
53
|
-
resourceType
|
|
54
|
+
resourceType,
|
|
55
|
+
bucketType
|
|
54
56
|
});
|
|
55
57
|
}
|
|
56
58
|
on(event, listener) {
|
package/dist/types.d.ts
CHANGED
|
@@ -18,6 +18,14 @@ export interface SessionOptions {
|
|
|
18
18
|
/** 已有的线程 ID,用于恢复历史会话 */
|
|
19
19
|
threadId?: string;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* 上传资源类型
|
|
23
|
+
*/
|
|
24
|
+
export type UploadResourceType = 'conversation' | 'workflow' | 'knowledge-base';
|
|
25
|
+
/**
|
|
26
|
+
* 存储桶类型
|
|
27
|
+
*/
|
|
28
|
+
export type BucketType = 'public' | 'private';
|
|
21
29
|
/**
|
|
22
30
|
* 上传参数
|
|
23
31
|
*/
|
|
@@ -25,7 +33,9 @@ export interface UploadParams {
|
|
|
25
33
|
/** 要上传的文件 */
|
|
26
34
|
file: File;
|
|
27
35
|
/** 资源类型 */
|
|
28
|
-
resourceType:
|
|
36
|
+
resourceType: UploadResourceType;
|
|
37
|
+
/** 存储桶类型,默认 private */
|
|
38
|
+
bucketType?: BucketType;
|
|
29
39
|
/** 上传进度回调 */
|
|
30
40
|
onProgress?: (percent: number) => void;
|
|
31
41
|
}
|
|
@@ -46,8 +56,6 @@ export interface CompressOptions {
|
|
|
46
56
|
maxWidth?: number;
|
|
47
57
|
/** 最大高度,默认 1920 */
|
|
48
58
|
maxHeight?: number;
|
|
49
|
-
/** 超过此大小(字节)的图片会被转换为 JPEG,默认 1MB */
|
|
50
|
-
convertSize?: number;
|
|
51
59
|
}
|
|
52
60
|
/**
|
|
53
61
|
* 内容部件类型
|
package/dist/upload.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { UploadParams, UploadImageParams } from './types';
|
|
1
|
+
import type { UploadParams, UploadImageParams, BucketType } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* 文件上传服务
|
|
4
4
|
*/
|
|
@@ -38,7 +38,7 @@ export declare class UploadService {
|
|
|
38
38
|
/**
|
|
39
39
|
* 获取文件签名 URL
|
|
40
40
|
*/
|
|
41
|
-
getSignedUrl(key: string,
|
|
41
|
+
getSignedUrl(key: string, bucketType?: BucketType): Promise<{
|
|
42
42
|
url: string;
|
|
43
43
|
}>;
|
|
44
44
|
}
|
package/dist/upload.js
CHANGED
|
@@ -11,13 +11,13 @@ function _define_property(obj, key, value) {
|
|
|
11
11
|
}
|
|
12
12
|
class UploadService {
|
|
13
13
|
compressImage(file, options = {}) {
|
|
14
|
-
const { quality = 0.8, maxWidth = 1920, maxHeight = 1920
|
|
14
|
+
const { quality = 0.8, maxWidth = 1920, maxHeight = 1920 } = options;
|
|
15
15
|
return new Promise((resolve)=>{
|
|
16
16
|
new compressorjs(file, {
|
|
17
17
|
quality,
|
|
18
18
|
maxWidth,
|
|
19
19
|
maxHeight,
|
|
20
|
-
convertSize,
|
|
20
|
+
convertSize: 1 / 0,
|
|
21
21
|
success: (result)=>{
|
|
22
22
|
let filename = file.name;
|
|
23
23
|
if (result.type !== file.type) {
|
|
@@ -131,9 +131,9 @@ class UploadService {
|
|
|
131
131
|
if (err) reject(err);
|
|
132
132
|
else {
|
|
133
133
|
const searchParams = new URLSearchParams({
|
|
134
|
-
key
|
|
135
|
-
...rest
|
|
134
|
+
key
|
|
136
135
|
});
|
|
136
|
+
if (rest.bucketType) searchParams.set('bucketType', rest.bucketType);
|
|
137
137
|
const res = await fetch(`${this.baseUrl}/workflows/signed-url?${searchParams.toString()}`, {
|
|
138
138
|
method: 'GET',
|
|
139
139
|
headers: {
|
|
@@ -157,10 +157,10 @@ class UploadService {
|
|
|
157
157
|
...rest
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
|
-
async getSignedUrl(key,
|
|
160
|
+
async getSignedUrl(key, bucketType = 'private') {
|
|
161
161
|
const searchParams = new URLSearchParams({
|
|
162
162
|
key,
|
|
163
|
-
bucketType
|
|
163
|
+
bucketType
|
|
164
164
|
});
|
|
165
165
|
const res = await fetch(`${this.baseUrl}/workflows/signed-url?${searchParams.toString()}`, {
|
|
166
166
|
method: 'GET',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wtfai",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"jsonrepair": "^3.14.0",
|
|
42
42
|
"mermaid": "^11.12.2",
|
|
43
43
|
"uuid": "^13.0.2",
|
|
44
|
-
"@our-llm/shared": "3.0.
|
|
44
|
+
"@our-llm/shared": "3.0.3"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "rslib build",
|
package/dist/realtime.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { RealtimeEvent, RealtimePresence } from '@our-llm/shared/types';
|
|
2
|
-
export declare class RealtimeService {
|
|
3
|
-
private readonly baseUrl;
|
|
4
|
-
private readonly headers;
|
|
5
|
-
constructor(baseUrl: string, headers: Record<string, string>);
|
|
6
|
-
/**
|
|
7
|
-
* 订阅实时消息流 (适合大屏端)
|
|
8
|
-
* @param topic 主题名称
|
|
9
|
-
* @param onEvent 事件回调
|
|
10
|
-
* @returns 返回一个包含 unsubscribe 方法的对象
|
|
11
|
-
*/
|
|
12
|
-
subscribe(topic: string, onEvent: (event: RealtimeEvent) => void): Promise<{
|
|
13
|
-
unsubscribe: () => void;
|
|
14
|
-
}>;
|
|
15
|
-
/**
|
|
16
|
-
* 推送实时消息 (适合手机端)
|
|
17
|
-
*/
|
|
18
|
-
push(topic: string, event: string, data: any): Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* 获取当前主题的在线状态
|
|
21
|
-
*/
|
|
22
|
-
getPresence(topic: string): Promise<RealtimePresence>;
|
|
23
|
-
}
|
package/dist/realtime.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { fetchEventSource } from "@microsoft/fetch-event-source";
|
|
2
|
-
import { getCachedDeviceId } from "@our-llm/shared/fingerprint";
|
|
3
|
-
function _define_property(obj, key, value) {
|
|
4
|
-
if (key in obj) Object.defineProperty(obj, key, {
|
|
5
|
-
value: value,
|
|
6
|
-
enumerable: true,
|
|
7
|
-
configurable: true,
|
|
8
|
-
writable: true
|
|
9
|
-
});
|
|
10
|
-
else obj[key] = value;
|
|
11
|
-
return obj;
|
|
12
|
-
}
|
|
13
|
-
const REALTIME_RECONNECT_INTERVAL = 1000;
|
|
14
|
-
class RealtimeService {
|
|
15
|
-
async subscribe(topic, onEvent) {
|
|
16
|
-
const deviceId = await getCachedDeviceId();
|
|
17
|
-
const controller = new AbortController();
|
|
18
|
-
const query = `?deviceId=${encodeURIComponent(deviceId)}`;
|
|
19
|
-
const url = `${this.baseUrl}/workflows/realtime/streams/${topic}${query}`;
|
|
20
|
-
fetchEventSource(url, {
|
|
21
|
-
method: 'GET',
|
|
22
|
-
headers: {
|
|
23
|
-
Accept: 'text/event-stream',
|
|
24
|
-
...this.headers
|
|
25
|
-
},
|
|
26
|
-
signal: controller.signal,
|
|
27
|
-
openWhenHidden: true,
|
|
28
|
-
onmessage (msg) {
|
|
29
|
-
if (!msg.data) return;
|
|
30
|
-
if ('message' === msg.event || !msg.event) try {
|
|
31
|
-
const event = JSON.parse(msg.data);
|
|
32
|
-
onEvent(event);
|
|
33
|
-
} catch (e) {
|
|
34
|
-
console.error('[SDK Realtime] Failed to parse message', e);
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
onerror (err) {
|
|
38
|
-
console.error('[SDK Realtime] Connection error', err);
|
|
39
|
-
return REALTIME_RECONNECT_INTERVAL;
|
|
40
|
-
},
|
|
41
|
-
onclose () {
|
|
42
|
-
throw new Error('[SDK Realtime] Connection closed; reconnecting');
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
return {
|
|
46
|
-
unsubscribe: ()=>{
|
|
47
|
-
controller.abort();
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
async push(topic, event, data) {
|
|
52
|
-
const dto = {
|
|
53
|
-
topic,
|
|
54
|
-
event,
|
|
55
|
-
data
|
|
56
|
-
};
|
|
57
|
-
const response = await fetch(`${this.baseUrl}/workflows/realtime/push`, {
|
|
58
|
-
method: 'POST',
|
|
59
|
-
headers: {
|
|
60
|
-
'Content-Type': 'application/json',
|
|
61
|
-
...this.headers
|
|
62
|
-
},
|
|
63
|
-
body: JSON.stringify(dto)
|
|
64
|
-
});
|
|
65
|
-
if (!response.ok) {
|
|
66
|
-
const json = await response.json();
|
|
67
|
-
throw new Error(`${json.message || '推送失败'}`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
async getPresence(topic) {
|
|
71
|
-
const response = await fetch(`${this.baseUrl}/workflows/realtime/presence/${topic}`, {
|
|
72
|
-
method: 'GET',
|
|
73
|
-
headers: this.headers
|
|
74
|
-
});
|
|
75
|
-
if (!response.ok) throw new Error(`获取在线状态失败: ${response.statusText}`);
|
|
76
|
-
return response.json();
|
|
77
|
-
}
|
|
78
|
-
constructor(baseUrl, headers){
|
|
79
|
-
_define_property(this, "baseUrl", void 0);
|
|
80
|
-
_define_property(this, "headers", void 0);
|
|
81
|
-
this.baseUrl = baseUrl;
|
|
82
|
-
this.headers = headers;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
export { RealtimeService };
|