@varo-ui/ai 1.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/dist/index.d.mts +249 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +984 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +52 -0
- package/src/agent-stream.ts +284 -0
- package/src/event-channel.ts +49 -0
- package/src/event-parser.ts +159 -0
- package/src/index.ts +8 -0
- package/src/markdown-view.ts +227 -0
- package/src/markdown.ts +58 -0
- package/src/sse.ts +161 -0
- package/src/text-stream.ts +202 -0
- package/src/type-guards.ts +3 -0
- package/src/types.ts +222 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
export type AgentMessageRole = 'assistant' | 'system' | 'user'
|
|
2
|
+
export type AgentStreamStatus = 'idle' | 'streaming' | 'waiting' | 'completed' | 'failed' | 'cancelled'
|
|
3
|
+
export type AgentPartStatus = 'waiting' | 'running' | 'completed' | 'failed'
|
|
4
|
+
|
|
5
|
+
export interface AgentMessageStartEvent {
|
|
6
|
+
messageId: string
|
|
7
|
+
role: AgentMessageRole
|
|
8
|
+
type: 'message.start'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface AgentTextDeltaEvent {
|
|
12
|
+
delta: string
|
|
13
|
+
messageId: string
|
|
14
|
+
type: 'text.delta'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface AgentMessageEndEvent {
|
|
18
|
+
messageId: string
|
|
19
|
+
type: 'message.end'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface AgentReasoningStartEvent {
|
|
23
|
+
id: string
|
|
24
|
+
title: string
|
|
25
|
+
type: 'reasoning.start'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface AgentReasoningDeltaEvent {
|
|
29
|
+
delta: string
|
|
30
|
+
id: string
|
|
31
|
+
type: 'reasoning.delta'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface AgentReasoningEndEvent {
|
|
35
|
+
durationMs?: number
|
|
36
|
+
id: string
|
|
37
|
+
type: 'reasoning.end'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface AgentToolStartEvent {
|
|
41
|
+
id: string
|
|
42
|
+
input?: unknown
|
|
43
|
+
name: string
|
|
44
|
+
summary?: string
|
|
45
|
+
type: 'tool.start'
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface AgentToolUpdateEvent {
|
|
49
|
+
id: string
|
|
50
|
+
summary?: string
|
|
51
|
+
type: 'tool.update'
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface AgentToolResultEvent {
|
|
55
|
+
id: string
|
|
56
|
+
output?: unknown
|
|
57
|
+
summary?: string
|
|
58
|
+
type: 'tool.result'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface AgentToolErrorEvent {
|
|
62
|
+
error: string
|
|
63
|
+
id: string
|
|
64
|
+
type: 'tool.error'
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface AgentApprovalRequiredEvent {
|
|
68
|
+
choices?: Array<{
|
|
69
|
+
description?: string
|
|
70
|
+
disabled?: boolean
|
|
71
|
+
label: string
|
|
72
|
+
value: string
|
|
73
|
+
}>
|
|
74
|
+
description?: string
|
|
75
|
+
id: string
|
|
76
|
+
title: string
|
|
77
|
+
type: 'approval.required'
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface AgentApprovalResolvedEvent {
|
|
81
|
+
id: string
|
|
82
|
+
type: 'approval.resolved'
|
|
83
|
+
value: string
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface AgentDataEvent {
|
|
87
|
+
name: string
|
|
88
|
+
type: 'data'
|
|
89
|
+
value: unknown
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface AgentErrorEvent {
|
|
93
|
+
code?: string
|
|
94
|
+
message: string
|
|
95
|
+
retryable?: boolean
|
|
96
|
+
type: 'error'
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface AgentDoneEvent {
|
|
100
|
+
type: 'done'
|
|
101
|
+
usage?: {
|
|
102
|
+
inputTokens?: number
|
|
103
|
+
outputTokens?: number
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export type AgentStreamEvent =
|
|
108
|
+
| AgentMessageStartEvent
|
|
109
|
+
| AgentTextDeltaEvent
|
|
110
|
+
| AgentMessageEndEvent
|
|
111
|
+
| AgentReasoningStartEvent
|
|
112
|
+
| AgentReasoningDeltaEvent
|
|
113
|
+
| AgentReasoningEndEvent
|
|
114
|
+
| AgentToolStartEvent
|
|
115
|
+
| AgentToolUpdateEvent
|
|
116
|
+
| AgentToolResultEvent
|
|
117
|
+
| AgentToolErrorEvent
|
|
118
|
+
| AgentApprovalRequiredEvent
|
|
119
|
+
| AgentApprovalResolvedEvent
|
|
120
|
+
| AgentDataEvent
|
|
121
|
+
| AgentErrorEvent
|
|
122
|
+
| AgentDoneEvent
|
|
123
|
+
|
|
124
|
+
export interface AgentStreamMessage {
|
|
125
|
+
final: boolean
|
|
126
|
+
id: string
|
|
127
|
+
role: AgentMessageRole
|
|
128
|
+
source: string
|
|
129
|
+
visible: string
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface AgentReasoningPart {
|
|
133
|
+
content: string
|
|
134
|
+
durationMs?: number
|
|
135
|
+
id: string
|
|
136
|
+
status: AgentPartStatus
|
|
137
|
+
title: string
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface AgentToolPart {
|
|
141
|
+
error?: string
|
|
142
|
+
id: string
|
|
143
|
+
input?: unknown
|
|
144
|
+
name: string
|
|
145
|
+
output?: unknown
|
|
146
|
+
status: AgentPartStatus
|
|
147
|
+
summary?: string
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface AgentApprovalPart {
|
|
151
|
+
choices: AgentApprovalRequiredEvent['choices']
|
|
152
|
+
description?: string
|
|
153
|
+
id: string
|
|
154
|
+
resolvedValue?: string
|
|
155
|
+
status: 'waiting' | 'completed'
|
|
156
|
+
title: string
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface AgentDataPart {
|
|
160
|
+
name: string
|
|
161
|
+
value: unknown
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export interface AgentStreamSnapshot {
|
|
165
|
+
approval?: AgentApprovalPart
|
|
166
|
+
data: AgentDataPart[]
|
|
167
|
+
error?: AgentErrorEvent
|
|
168
|
+
eventCount: number
|
|
169
|
+
message?: AgentStreamMessage
|
|
170
|
+
reasoning: AgentReasoningPart[]
|
|
171
|
+
status: AgentStreamStatus
|
|
172
|
+
tools: AgentToolPart[]
|
|
173
|
+
usage?: AgentDoneEvent['usage']
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface TextStreamSnapshot {
|
|
177
|
+
caughtUp: boolean
|
|
178
|
+
done: boolean
|
|
179
|
+
final: boolean
|
|
180
|
+
paused: boolean
|
|
181
|
+
pendingChars: number
|
|
182
|
+
source: string
|
|
183
|
+
visible: string
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export interface TextStreamOptions {
|
|
187
|
+
catchUpThreshold?: number
|
|
188
|
+
maxCharsPerCommit?: number
|
|
189
|
+
maxCharsPerSecond?: number
|
|
190
|
+
maxCommitFps?: number
|
|
191
|
+
minCharsPerSecond?: number
|
|
192
|
+
targetLatencyMs?: number
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export interface TextStreamController {
|
|
196
|
+
destroy: () => void
|
|
197
|
+
enqueue: (chunk: string) => void
|
|
198
|
+
finish: (options?: { flush?: boolean }) => void
|
|
199
|
+
flush: () => void
|
|
200
|
+
getSnapshot: () => TextStreamSnapshot
|
|
201
|
+
pause: () => void
|
|
202
|
+
reset: (content?: string) => void
|
|
203
|
+
resume: () => void
|
|
204
|
+
subscribe: (listener: () => void) => () => void
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface AgentStreamController {
|
|
208
|
+
cancel: (reason?: string) => void
|
|
209
|
+
connect: (events: AsyncIterable<AgentStreamEvent>) => Promise<AgentStreamSnapshot>
|
|
210
|
+
destroy: () => void
|
|
211
|
+
getSnapshot: () => AgentStreamSnapshot
|
|
212
|
+
push: (event: AgentStreamEvent) => void
|
|
213
|
+
reset: () => void
|
|
214
|
+
subscribe: (listener: () => void) => () => void
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export interface AgentEventChannel {
|
|
218
|
+
end: () => void
|
|
219
|
+
fail: (error: unknown) => void
|
|
220
|
+
push: (event: AgentStreamEvent) => void
|
|
221
|
+
source: AsyncIterable<AgentStreamEvent>
|
|
222
|
+
}
|