@our-llm/shared 2.1.0 → 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.1.0",
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]
@@ -132,6 +207,13 @@ export interface LoadingNodeConfig extends NodeConfig {
132
207
  message: string // loading 提示语
133
208
  }
134
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
+
135
217
  // 联合类型:所有节点配置
136
218
  export type AnyNodeConfig =
137
219
  | StartNodeConfig
@@ -146,6 +228,7 @@ export type AnyNodeConfig =
146
228
  | MessageNodeConfig
147
229
  | BillingNodeConfig
148
230
  | LoadingNodeConfig
231
+ | VideoUnderstandingNodeConfig
149
232
 
150
233
  // 工作流边配置
151
234
  export interface WorkflowEdge {
@@ -186,15 +269,21 @@ export interface Workflow extends WorkflowConfig {
186
269
  updatedAt: string
187
270
  }
188
271
 
272
+ export interface SimpleMessage {
273
+ type: 'human' | 'ai' | 'system' | 'tool'
274
+ parts: WorkflowMessagePart[]
275
+ id?: string
276
+ }
277
+
189
278
  // 工作流执行输入的消息内容部件类型
190
279
  export type WorkflowMessagePart =
191
280
  | {
192
281
  type: 'text'
193
282
  text: string
194
- document?: { filename: string; url: string } // 表示这条消息是文档解析消息
195
283
  }
196
284
  | { type: 'image'; url: string }
197
- | { type: 'file' | 'audio' | 'video'; url: string }
285
+ | { type: 'video'; url: string }
286
+ | { type: 'audio'; url: string }
198
287
  | { type: 'document'; url: string; filename: string; mimeType: string }
199
288
 
200
289
  // 工作流执行输入的消息类型(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