@our-llm/shared 2.1.0 → 3.0.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/package.json CHANGED
@@ -1,17 +1,8 @@
1
1
  {
2
2
  "name": "@our-llm/shared",
3
- "version": "2.1.0",
3
+ "version": "3.0.1",
4
4
  "type": "module",
5
5
  "exports": {
6
- "./workflow-events": {
7
- "types": "./workflow-events.ts",
8
- "import": "./workflow-events.ts",
9
- "default": "./workflow-events.ts"
10
- },
11
- "./workflow.types": {
12
- "types": "./workflow.types.ts",
13
- "import": "./workflow.types.ts",
14
- "default": "./workflow.types.ts"
15
- }
6
+ "./types": "./types.ts"
16
7
  }
17
8
  }
@@ -1,15 +1,89 @@
1
- // 数据类型定义
2
- export interface TextData {
3
- type: 'text'
4
- value: string
1
+ /**
2
+ * 工作流 SSE 事件协议
3
+ * 字段名采用缩写形式以减少流量消耗
4
+ *
5
+ * SSE event 字段用于类型判断,data 中不再重复 e 字段
6
+ *
7
+ * 字段映射:
8
+ * - t: threadId (线程ID)
9
+ * - ti: title (会话标题)
10
+ * - n: nodeId (节点ID)
11
+ * - c: content (内容)
12
+ * - r: reasoning (思维过程标记,1=true)
13
+ * - v: variables (业务变量)
14
+ * - m: message (错误消息)
15
+ */
16
+
17
+ // 工作流开始事件的 data
18
+ export interface WorkflowStartData {
19
+ t: string // threadId
20
+ ti?: string // title (会话标题,默认为工作流名称,新对话会有,追问会话就不会再有了)
21
+ }
22
+
23
+ // 节点开始事件的 data
24
+ export interface NodeStartData {
25
+ n: string // nodeId
26
+ }
27
+
28
+ // 节点结束事件的 data
29
+ export interface NodeEndData {
30
+ n: string // nodeId
31
+ v?: Record<string, unknown> // variables (业务输出变量)
32
+ m?: SimpleMessage[] // messages (AI 返回的消息,包含图片/视频)
33
+ }
34
+
35
+ export interface LoadingData {
36
+ n: string // nodeId
37
+ m: string // loading message
38
+ }
39
+
40
+ // Token 流式事件的 data
41
+ export interface TokenData {
42
+ n: string // nodeId
43
+ c: string // content
44
+ r?: 1 // isReasoning (只在 true 时存在,值为 1)
45
+ }
46
+
47
+ // 完成事件的 data(空对象)
48
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
49
+ export interface CompleteData {}
50
+
51
+ // 错误事件的 data
52
+ export interface ErrorData {
53
+ m: string // message
5
54
  }
6
55
 
7
- export interface ImageData {
8
- type: 'image'
9
- value: { url: string }
56
+ // 标题更新事件的 data
57
+ export interface TitleData {
58
+ ti: string // title (LLM 生成的会话标题)
10
59
  }
11
60
 
12
- export type InputData = TextData | ImageData
61
+ // SSE 事件类型
62
+ export type SSEEventType = 'ws' | 'ns' | 'ne' | 'tk' | 'ok' | 'err' | 'l' | 'tt'
63
+
64
+ // 事件类型映射(后端使用)
65
+ export const EventTypeMap = {
66
+ workflow_start: 'ws',
67
+ node_start: 'ns',
68
+ node_end: 'ne',
69
+ token: 'tk',
70
+ complete: 'ok',
71
+ error: 'err',
72
+ loading: 'l',
73
+ title: 'tt',
74
+ } as const
75
+
76
+ // 反向映射(前端使用)
77
+ export const EventTypeReverse = {
78
+ ws: 'workflow_start',
79
+ ns: 'node_start',
80
+ ne: 'node_end',
81
+ tk: 'token',
82
+ ok: 'complete',
83
+ err: 'error',
84
+ l: 'loading',
85
+ tt: 'title',
86
+ } as const
13
87
 
14
88
  // 节点类型常量
15
89
  export const NodeType = {
@@ -25,6 +99,8 @@ export const NodeType = {
25
99
  MESSAGE: 'message',
26
100
  BILLING: 'billing',
27
101
  LOADING: 'loading',
102
+ VIDEO_UNDERSTANDING: 'video_understanding',
103
+ AUDIO_TRANSCRIPTION: 'audio_transcription',
28
104
  } as const
29
105
 
30
106
  export type NodeType = (typeof NodeType)[keyof typeof NodeType]
@@ -132,6 +208,19 @@ export interface LoadingNodeConfig extends NodeConfig {
132
208
  message: string // loading 提示语
133
209
  }
134
210
 
211
+ // 视频理解节点配置
212
+ export interface VideoUnderstandingNodeConfig extends NodeConfig {
213
+ type: typeof NodeType.VIDEO_UNDERSTANDING
214
+ systemMessage: string // 系统提示词
215
+ script: string // JS 脚本,从 context 中获取视频 URL,返回 { videoUrl: string }
216
+ }
217
+
218
+ // 音频转文字节点配置
219
+ export interface AudioTranscriptionNodeConfig extends NodeConfig {
220
+ type: typeof NodeType.AUDIO_TRANSCRIPTION
221
+ script: string // JS代码片段,接收 context 参数(包含 variables、messages 和 audioTranscription 方法),返回对象用于更新 variables
222
+ }
223
+
135
224
  // 联合类型:所有节点配置
136
225
  export type AnyNodeConfig =
137
226
  | StartNodeConfig
@@ -146,6 +235,8 @@ export type AnyNodeConfig =
146
235
  | MessageNodeConfig
147
236
  | BillingNodeConfig
148
237
  | LoadingNodeConfig
238
+ | VideoUnderstandingNodeConfig
239
+ | AudioTranscriptionNodeConfig
149
240
 
150
241
  // 工作流边配置
151
242
  export interface WorkflowEdge {
@@ -186,15 +277,21 @@ export interface Workflow extends WorkflowConfig {
186
277
  updatedAt: string
187
278
  }
188
279
 
280
+ export interface SimpleMessage {
281
+ type: 'human' | 'ai' | 'system' | 'tool'
282
+ parts: WorkflowMessagePart[]
283
+ id?: string
284
+ }
285
+
189
286
  // 工作流执行输入的消息内容部件类型
190
287
  export type WorkflowMessagePart =
191
288
  | {
192
289
  type: 'text'
193
290
  text: string
194
- document?: { filename: string; url: string } // 表示这条消息是文档解析消息
195
291
  }
196
292
  | { type: 'image'; url: string }
197
- | { type: 'file' | 'audio' | 'video'; url: string }
293
+ | { type: 'video'; url: string }
294
+ | { type: 'audio'; url: string }
198
295
  | { type: 'document'; url: string; filename: string; mimeType: string }
199
296
 
200
297
  // 工作流执行输入的消息类型(content 为数组,支持多模态内容)
@@ -1,100 +0,0 @@
1
- /**
2
- * 工作流 SSE 事件协议
3
- * 字段名采用缩写形式以减少流量消耗
4
- *
5
- * SSE event 字段用于类型判断,data 中不再重复 e 字段
6
- *
7
- * 字段映射:
8
- * - t: threadId (线程ID)
9
- * - ti: title (会话标题)
10
- * - n: nodeId (节点ID)
11
- * - c: content (内容)
12
- * - r: reasoning (思维过程标记,1=true)
13
- * - v: variables (业务变量)
14
- * - m: message (错误消息)
15
- */
16
-
17
- // 工作流开始事件的 data
18
- export interface WorkflowStartData {
19
- t: string // threadId
20
- ti?: string // title (会话标题,默认为工作流名称,新对话会有,追问会话就不会再有了)
21
- }
22
-
23
- // 节点开始事件的 data
24
- export interface NodeStartData {
25
- n: string // nodeId
26
- }
27
-
28
- // 节点结束事件的 data
29
- export interface NodeEndData {
30
- n: string // nodeId
31
- v?: Record<string, unknown> // variables (业务输出变量)
32
- m?: SimpleMessage[] // messages (AI 返回的消息,包含图片/视频)
33
- }
34
-
35
- // 简化后的消息格式(与后端 SimpleMessage 保持一致)
36
- // 支持有序的内容部件
37
- export type SimpleMessagePart =
38
- | { type: 'text'; text: string }
39
- | { type: 'image'; url: string }
40
- | { type: 'video'; url: string }
41
- | { type: 'document'; filename: string; url: string }
42
-
43
- export interface SimpleMessage {
44
- type: 'human' | 'ai' | 'system'
45
- parts: SimpleMessagePart[]
46
- id?: string
47
- }
48
-
49
- export interface LoadingData {
50
- n: string // nodeId
51
- m: string // loading message
52
- }
53
-
54
- // Token 流式事件的 data
55
- export interface TokenData {
56
- n: string // nodeId
57
- c: string // content
58
- r?: 1 // isReasoning (只在 true 时存在,值为 1)
59
- }
60
-
61
- // 完成事件的 data(空对象)
62
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
63
- export interface CompleteData {}
64
-
65
- // 错误事件的 data
66
- export interface ErrorData {
67
- m: string // message
68
- }
69
-
70
- // 标题更新事件的 data
71
- export interface TitleData {
72
- ti: string // title (LLM 生成的会话标题)
73
- }
74
-
75
- // SSE 事件类型
76
- export type SSEEventType = 'ws' | 'ns' | 'ne' | 'tk' | 'ok' | 'err' | 'l' | 'tt'
77
-
78
- // 事件类型映射(后端使用)
79
- export const EventTypeMap = {
80
- workflow_start: 'ws',
81
- node_start: 'ns',
82
- node_end: 'ne',
83
- token: 'tk',
84
- complete: 'ok',
85
- error: 'err',
86
- loading: 'l',
87
- title: 'tt',
88
- } as const
89
-
90
- // 反向映射(前端使用)
91
- export const EventTypeReverse = {
92
- ws: 'workflow_start',
93
- ns: 'node_start',
94
- ne: 'node_end',
95
- tk: 'token',
96
- ok: 'complete',
97
- err: 'error',
98
- l: 'loading',
99
- tt: 'title',
100
- } as const