wtfai 1.4.0 → 1.4.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/client.d.ts CHANGED
@@ -28,7 +28,7 @@ import { UploadService } from './upload';
28
28
  * })
29
29
  *
30
30
  * // 发送消息
31
- * await session.send({ content: '你好' })
31
+ * await session.send({ parts: [{ type: 'text', text: '你好' }] })
32
32
  * ```
33
33
  */
34
34
  export declare class Wtfai {
package/dist/session.d.ts CHANGED
@@ -40,7 +40,7 @@ export declare class WorkflowSession {
40
40
  /**
41
41
  * 发送消息执行工作流
42
42
  */
43
- send(input: SendInput): Promise<void>;
43
+ send({ parts: inputParts, ...rest }: SendInput): Promise<void>;
44
44
  /**
45
45
  * 解析图片 URL(支持 File 和 URL)
46
46
  */
package/dist/session.js CHANGED
@@ -52,17 +52,17 @@ class WorkflowSession {
52
52
  messages: data.messages
53
53
  });
54
54
  }
55
- async send(input) {
55
+ async send({ parts: inputParts, ...rest }) {
56
56
  if (this.state.isExecuting) throw new Error('工作流正在执行中');
57
57
  this.updateState({
58
58
  isExecuting: true,
59
59
  currentNodeId: void 0
60
60
  });
61
61
  try {
62
- const contentParts = [];
63
- for (const part of input.parts)switch(part.type){
62
+ const parts = [];
63
+ for (const part of inputParts)switch(part.type){
64
64
  case 'text':
65
- contentParts.push({
65
+ parts.push({
66
66
  type: 'text',
67
67
  text: part.text
68
68
  });
@@ -75,7 +75,7 @@ class WorkflowSession {
75
75
  file,
76
76
  url
77
77
  });
78
- contentParts.push({
78
+ parts.push({
79
79
  type: 'image',
80
80
  url: imageUrl
81
81
  });
@@ -84,7 +84,7 @@ class WorkflowSession {
84
84
  case 'document':
85
85
  {
86
86
  const docInfo = await this.resolveDocumentInfo(part);
87
- contentParts.push({
87
+ parts.push({
88
88
  type: 'document',
89
89
  url: docInfo.url,
90
90
  filename: docInfo.filename,
@@ -95,7 +95,7 @@ class WorkflowSession {
95
95
  case 'video':
96
96
  {
97
97
  const videoUrl = await this.resolveVideoUrl(part);
98
- contentParts.push({
98
+ parts.push({
99
99
  type: 'video',
100
100
  url: videoUrl
101
101
  });
@@ -105,38 +105,10 @@ class WorkflowSession {
105
105
  const executionInput = {
106
106
  messages: [
107
107
  {
108
- content: contentParts
108
+ content: parts
109
109
  }
110
110
  ]
111
111
  };
112
- const parts = contentParts.map((part)=>{
113
- switch(part.type){
114
- case 'text':
115
- return {
116
- type: 'text',
117
- text: part.text
118
- };
119
- case 'image':
120
- return {
121
- type: 'image',
122
- url: part.url
123
- };
124
- case 'video':
125
- return {
126
- type: 'video',
127
- url: part.url
128
- };
129
- case 'document':
130
- return {
131
- type: 'document',
132
- filename: part.filename,
133
- url: part.url,
134
- mimeType: part.mimeType
135
- };
136
- default:
137
- throw new Error(`Unknown part type: ${part.type}`);
138
- }
139
- });
140
112
  const userMessage = {
141
113
  type: 'human',
142
114
  parts
@@ -151,7 +123,8 @@ class WorkflowSession {
151
123
  let currentAiMessageIndex = -1;
152
124
  this.abortController = await executeWorkflowSSE(`${this.baseUrl}/workflows/${this.workflowId}/execute`, {
153
125
  input: executionInput,
154
- threadId: this.state.threadId
126
+ threadId: this.state.threadId,
127
+ ...rest
155
128
  }, {
156
129
  onWorkflowStart: (data)=>{
157
130
  this.updateState({
package/dist/types.d.ts CHANGED
@@ -89,9 +89,9 @@ export type ContentPart = {
89
89
  url: string;
90
90
  };
91
91
  /**
92
- * 发送消息的输入
92
+ * 发送消息的输入,支持传入任何扩展字段,会在发送请求时带上
93
93
  */
94
- export interface SendInput {
94
+ export interface SendInput extends Record<string, any> {
95
95
  /** 内容部件数组,按顺序传递给 LLM */
96
96
  parts: ContentPart[];
97
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wtfai",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {