@our-llm/shared 2.0.2 → 3.0.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/package.json CHANGED
@@ -1,17 +1,8 @@
1
1
  {
2
2
  "name": "@our-llm/shared",
3
- "version": "2.0.2",
3
+ "version": "3.0.0",
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
5
26
  }
6
27
 
7
- export interface ImageData {
8
- type: 'image'
9
- value: { url: string }
28
+ // 节点结束事件的 data
29
+ export interface NodeEndData {
30
+ n: string // nodeId
31
+ v?: Record<string, unknown> // variables (业务输出变量)
32
+ m?: SimpleMessage[] // messages (AI 返回的消息,包含图片/视频)
10
33
  }
11
34
 
12
- export type InputData = TextData | ImageData
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
54
+ }
55
+
56
+ // 标题更新事件的 data
57
+ export interface TitleData {
58
+ ti: string // title (LLM 生成的会话标题)
59
+ }
60
+
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,7 @@ export const NodeType = {
25
99
  MESSAGE: 'message',
26
100
  BILLING: 'billing',
27
101
  LOADING: 'loading',
102
+ VIDEO_UNDERSTANDING: 'video_understanding',
28
103
  } as const
29
104
 
30
105
  export type NodeType = (typeof NodeType)[keyof typeof NodeType]
@@ -75,6 +150,8 @@ export interface BrainNodeConfig extends NodeConfig {
75
150
  humanMessageScript?: string // 可选的用户消息脚本,接收 context 参数(包含 variables 和 messages),返回 string[] 用于构造 HumanMessage[]
76
151
  /** 联网搜索配置 */
77
152
  webSearch?: WebSearchConfig
153
+ /** 静默模式:为 true 时不产生 UI 消息,仅将结果存储在 variables 中 */
154
+ silent?: boolean
78
155
  }
79
156
 
80
157
  // 条件判断节点配置
@@ -130,6 +207,13 @@ export interface LoadingNodeConfig extends NodeConfig {
130
207
  message: string // loading 提示语
131
208
  }
132
209
 
210
+ // 视频理解节点配置
211
+ export interface VideoUnderstandingNodeConfig extends NodeConfig {
212
+ type: typeof NodeType.VIDEO_UNDERSTANDING
213
+ systemMessage: string // 系统提示词
214
+ script: string // JS 脚本,从 context 中获取视频 URL,返回 { videoUrl: string }
215
+ }
216
+
133
217
  // 联合类型:所有节点配置
134
218
  export type AnyNodeConfig =
135
219
  | StartNodeConfig
@@ -144,6 +228,7 @@ export type AnyNodeConfig =
144
228
  | MessageNodeConfig
145
229
  | BillingNodeConfig
146
230
  | LoadingNodeConfig
231
+ | VideoUnderstandingNodeConfig
147
232
 
148
233
  // 工作流边配置
149
234
  export interface WorkflowEdge {
@@ -184,12 +269,22 @@ export interface Workflow extends WorkflowConfig {
184
269
  updatedAt: string
185
270
  }
186
271
 
272
+ export interface SimpleMessage {
273
+ type: 'human' | 'ai' | 'system' | 'tool'
274
+ parts: WorkflowMessagePart[]
275
+ id?: string
276
+ }
277
+
187
278
  // 工作流执行输入的消息内容部件类型
188
279
  export type WorkflowMessagePart =
189
- | { type: 'text'; text: string }
190
- | { type: 'image'; url?: string; base64?: string }
191
- | { type: 'file' | 'audio' | 'video'; url?: string }
192
- | { type: 'document'; base64?: string; url?: string; filename: string; mimeType: string }
280
+ | {
281
+ type: 'text'
282
+ text: string
283
+ }
284
+ | { type: 'image'; url: string }
285
+ | { type: 'video'; url: string }
286
+ | { type: 'audio'; url: string }
287
+ | { type: 'document'; url: string; filename: string; mimeType: string }
193
288
 
194
289
  // 工作流执行输入的消息类型(content 为数组,支持多模态内容)
195
290
  export interface WorkflowMessage {
@@ -1,101 +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
- export interface SimpleMessage {
37
- type: 'human' | 'ai' | 'system'
38
- content:
39
- | string
40
- | Array<
41
- | { type: 'text'; text: string }
42
- | { type: 'image_url'; image_url: { url: string } }
43
- >
44
- id?: string
45
- images?: string[]
46
- videos?: string[]
47
- documents?: Array<{ filename: string; url: string }>
48
- }
49
-
50
- export interface LoadingData {
51
- n: string // nodeId
52
- m: string // loading message
53
- }
54
-
55
- // Token 流式事件的 data
56
- export interface TokenData {
57
- n: string // nodeId
58
- c: string // content
59
- r?: 1 // isReasoning (只在 true 时存在,值为 1)
60
- }
61
-
62
- // 完成事件的 data(空对象)
63
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
64
- export interface CompleteData {}
65
-
66
- // 错误事件的 data
67
- export interface ErrorData {
68
- m: string // message
69
- }
70
-
71
- // 标题更新事件的 data
72
- export interface TitleData {
73
- ti: string // title (LLM 生成的会话标题)
74
- }
75
-
76
- // SSE 事件类型
77
- export type SSEEventType = 'ws' | 'ns' | 'ne' | 'tk' | 'ok' | 'err' | 'l' | 'tt'
78
-
79
- // 事件类型映射(后端使用)
80
- export const EventTypeMap = {
81
- workflow_start: 'ws',
82
- node_start: 'ns',
83
- node_end: 'ne',
84
- token: 'tk',
85
- complete: 'ok',
86
- error: 'err',
87
- loading: 'l',
88
- title: 'tt',
89
- } as const
90
-
91
- // 反向映射(前端使用)
92
- export const EventTypeReverse = {
93
- ws: 'workflow_start',
94
- ns: 'node_start',
95
- ne: 'node_end',
96
- tk: 'token',
97
- ok: 'complete',
98
- err: 'error',
99
- l: 'loading',
100
- tt: 'title',
101
- } as const