types.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. export type JsonPrimitive = string | number | boolean | null
  2. export type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue }
  3. export type AuthStatus =
  4. | 'checking'
  5. | 'anonymous'
  6. | 'authenticating'
  7. | 'authenticated'
  8. | 'expired'
  9. | 'error'
  10. export interface CurrentUser {
  11. id: string
  12. username: string
  13. avatar?: string
  14. displayName?: string
  15. email?: string
  16. provider?: string
  17. role?: string
  18. enabled?: boolean
  19. mustChangePassword?: boolean
  20. }
  21. export interface Profile {
  22. name: string
  23. agentName?: string
  24. displayName?: string
  25. description?: string
  26. isDefault: boolean
  27. model?: string
  28. provider?: string
  29. gatewayRunning?: boolean
  30. avatar?: string
  31. agentAvatar?: string
  32. }
  33. export interface ModelOption {
  34. id: string
  35. name: string
  36. provider: string
  37. supportsReasoning?: boolean
  38. reasoningEfforts?: string[]
  39. isDefault?: boolean
  40. }
  41. export interface BootstrapResponse {
  42. status?: string
  43. authRequired: boolean
  44. setupRequired?: boolean
  45. user?: CurrentUser
  46. profiles: Profile[]
  47. csrfToken: string
  48. insecureLan?: boolean
  49. groupUploadsEnabled?: boolean
  50. upstreamReady?: boolean
  51. upstreamError?: string
  52. serverKind?: string
  53. models?: ModelOption[]
  54. }
  55. export interface UploadReference {
  56. id: string
  57. name: string
  58. mimeType: string
  59. size: number
  60. markdown?: string
  61. refText?: string
  62. }
  63. export interface AccountScope {
  64. upstream?: string
  65. userId: string
  66. }
  67. export interface SessionSummary {
  68. id: string
  69. profile?: string
  70. source: string
  71. title: string
  72. preview?: string
  73. model?: string
  74. provider?: string
  75. agent?: string
  76. messageCount: number
  77. toolCallCount: number
  78. inputTokens?: number
  79. outputTokens?: number
  80. startedAt: number
  81. updatedAt: number
  82. endedAt?: number | null
  83. parentSessionId?: string | null
  84. forkPointMessageId?: string | null
  85. workspace?: string | null
  86. archived?: boolean
  87. pinned?: boolean
  88. }
  89. export type ChatRole = 'user' | 'assistant' | 'tool' | 'system'
  90. export type DeliveryStage =
  91. | 'preparing'
  92. | 'attached'
  93. | 'pending'
  94. | 'accepted'
  95. | 'streaming'
  96. | 'settled'
  97. | 'failed'
  98. | 'unknown-receipt'
  99. export interface ChatAttachment {
  100. id: string
  101. name: string
  102. mimeType: string
  103. size: number
  104. path?: string
  105. url?: string
  106. kind?: 'image' | 'pdf' | 'file'
  107. }
  108. export interface ToolCall {
  109. id: string
  110. name: string
  111. status: 'pending' | 'running' | 'completed' | 'failed'
  112. arguments?: JsonValue
  113. result?: JsonValue
  114. preview?: string
  115. error?: string
  116. durationSeconds?: number
  117. }
  118. export interface ChatMessage {
  119. id: string
  120. sessionId: string
  121. profile?: string
  122. role: ChatRole
  123. content: string
  124. reasoning?: string
  125. timestamp: number
  126. sequence?: number
  127. clientMessageId?: string
  128. serverMessageId?: string
  129. stage: DeliveryStage
  130. isStreaming?: boolean
  131. error?: string
  132. attachments?: ChatAttachment[]
  133. toolCalls?: ToolCall[]
  134. toolCallId?: string
  135. toolName?: string
  136. displayKind?: string
  137. displayMetadata?: JsonValue
  138. raw?: JsonValue
  139. }
  140. export interface ChatRoute {
  141. profile: string
  142. sessionId: string
  143. }
  144. export interface ChatUsage {
  145. inputTokens?: number
  146. outputTokens?: number
  147. totalTokens?: number
  148. contextTokens?: number
  149. contextLimit?: number
  150. percentUsed?: number
  151. raw?: JsonValue
  152. }
  153. export interface ApprovalRequest {
  154. id: string
  155. sessionId: string
  156. message?: string
  157. toolName?: string
  158. choices?: string[]
  159. payload: Record<string, JsonValue>
  160. }
  161. export interface ClarificationRequest {
  162. id: string
  163. sessionId: string
  164. question: string
  165. choices?: string[]
  166. payload: Record<string, JsonValue>
  167. }
  168. export type RealtimeConnectionState =
  169. | 'idle'
  170. | 'leasing'
  171. | 'connecting'
  172. | 'connected'
  173. | 'ready'
  174. | 'reconnecting'
  175. | 'disconnected'
  176. | 'failed'
  177. | 'needs-reset'
  178. export interface ChatRouteState {
  179. route: ChatRoute
  180. messages: ChatMessage[]
  181. runtimeSessionId?: string
  182. historySynced: boolean
  183. hasMoreBefore: boolean
  184. loadedMessageCount: number
  185. messageTotal: number
  186. isLoadingHistory: boolean
  187. isStreaming: boolean
  188. isQueued: boolean
  189. fastMode?: boolean
  190. serverFastMode?: boolean
  191. fastModeDirty?: boolean
  192. liveStatus?: string
  193. usage?: ChatUsage
  194. pendingApproval?: ApprovalRequest
  195. pendingClarification?: ClarificationRequest
  196. error?: string
  197. generation: number
  198. }
  199. export interface RpcRequestFrame {
  200. jsonrpc: '2.0'
  201. id: string
  202. method: string
  203. params: Record<string, JsonValue>
  204. }
  205. export interface RpcEventFrame {
  206. jsonrpc?: '2.0'
  207. method: 'event'
  208. params: {
  209. type: string
  210. session_id?: string
  211. profile?: string
  212. payload?: JsonValue
  213. }
  214. }
  215. export interface GroupLimits {
  216. maxAgentsPerRoom: number
  217. maxMessageBytes: number
  218. maxToolStateBytes?: number
  219. maxInteractionPayloadBytes?: number
  220. maxMessagePageSize: number
  221. maxEventBatchSize?: number
  222. maxAgentDepth?: number
  223. maxRoomConcurrency?: number
  224. maxPluginConcurrency?: number
  225. defaultMaxReplyRounds: number
  226. unlimitedReplyRoundsValue: number
  227. maxAgentDisplayNameLength: number
  228. }
  229. export const MIN_SUPPORTED_GROUP_PROTOCOL_VERSION = 2
  230. export const MAX_SUPPORTED_GROUP_PROTOCOL_VERSION = 12
  231. export const SUPPORTED_GROUP_PROTOCOL_VERSION_LABEL = `v${MIN_SUPPORTED_GROUP_PROTOCOL_VERSION}–v${MAX_SUPPORTED_GROUP_PROTOCOL_VERSION}`
  232. export function isSupportedGroupProtocolVersion(value: number): boolean {
  233. return Number.isInteger(value)
  234. && value >= MIN_SUPPORTED_GROUP_PROTOCOL_VERSION
  235. && value <= MAX_SUPPORTED_GROUP_PROTOCOL_VERSION
  236. }
  237. export interface GroupCapabilities {
  238. protocolVersion: number
  239. journalEpoch: string
  240. latestCursor: number
  241. limits: GroupLimits
  242. eventTypes: string[]
  243. features?: string[]
  244. }
  245. export type GroupAgentStatus = 'idle' | 'queued' | 'running' | 'awaiting_input' | 'unknown'
  246. export type GroupMessageStatus = 'queued' | 'streaming' | 'completed' | 'failed' | 'interrupted' | 'unknown'
  247. export interface GroupAgent {
  248. id: string
  249. roomId: string
  250. profile: string
  251. nodeId: string
  252. nodeLabel: string
  253. displayName: string
  254. description: string
  255. storedSessionId?: string | null
  256. lastContextMessageSeq: number
  257. enabled: boolean
  258. replyWithoutMention: boolean
  259. isHost: boolean
  260. model?: string | null
  261. provider?: string | null
  262. reasoningEffort?: string | null
  263. fastMode?: boolean | null
  264. createdAt: number
  265. updatedAt: number
  266. status: GroupAgentStatus
  267. }
  268. export interface GroupNodeProfile {
  269. name: string
  270. displayName: string
  271. model: string
  272. avatar?: string
  273. color?: string
  274. }
  275. export interface GroupNode {
  276. nodeId: string
  277. name: string
  278. serverUrl: string
  279. fingerprint: string
  280. createdAt: number
  281. updatedAt: number
  282. profiles: GroupNodeProfile[]
  283. }
  284. export interface GroupMessage {
  285. seq: number
  286. id: string
  287. roomId: string
  288. topicId?: string | null
  289. senderKind: 'human' | 'agent' | 'system' | 'unknown'
  290. senderId: string
  291. senderName: string
  292. rootMessageId: string
  293. replyToMessageId?: string | null
  294. clientMessageId?: string | null
  295. content: string
  296. reasoning: string
  297. toolState: JsonValue[]
  298. status: GroupMessageStatus
  299. error: string
  300. execution?: {
  301. requestedModel?: string | null
  302. requestedReasoningEffort?: string | null
  303. requestedFastMode?: boolean | null
  304. actualModel?: string | null
  305. actualReasoningEffort?: string | null
  306. actualFastMode?: boolean | null
  307. } | null
  308. createdAt: number
  309. updatedAt: number
  310. }
  311. export interface GroupRun {
  312. id: string
  313. roomId: string
  314. topicId?: string | null
  315. agentId: string
  316. triggerMessageId: string
  317. responseMessageId: string
  318. rootMessageId: string
  319. depth: number
  320. status: 'queued' | 'running' | 'awaiting_input' | 'completed' | 'failed' | 'interrupted' | 'unknown'
  321. runtimeSessionId?: string | null
  322. error: string
  323. replyMode?: 'mentioned' | 'automatic' | null
  324. createdAt: number
  325. updatedAt: number
  326. }
  327. export interface GroupInteraction {
  328. id: string
  329. roomId: string
  330. topicId?: string | null
  331. agentId: string
  332. runId: string
  333. kind: 'approval' | 'clarification' | 'unknown'
  334. payload: JsonValue
  335. status: 'pending' | 'resolved' | 'cancelled' | 'unknown'
  336. createdAt: number
  337. resolvedAt?: number | null
  338. }
  339. export interface GroupRoomSummary {
  340. id: string
  341. name: string
  342. cwd: string
  343. instructions?: string
  344. avatar?: string
  345. avatarMembers?: GroupRoomAvatarMember[]
  346. createdAt: number
  347. updatedAt: number
  348. archived: boolean
  349. agentCount: number
  350. lastMessage?: GroupMessage | null
  351. unreadCount: number
  352. activeRunCount?: number
  353. maxReplyRounds: number
  354. orchestrationMode?: 'free' | 'host'
  355. }
  356. export interface GroupRoomAvatarMember {
  357. profile: string
  358. nodeId: string
  359. displayName: string
  360. }
  361. export interface GroupRoomDetail extends Omit<GroupRoomSummary, 'agentCount' | 'lastMessage' | 'unreadCount'> {
  362. agents: GroupAgent[]
  363. runs: GroupRun[]
  364. pendingInteractions: GroupInteraction[]
  365. latestCursor: number
  366. }
  367. export interface GroupRoomPage {
  368. items: GroupRoomSummary[]
  369. nextCursor?: string | null
  370. }
  371. export interface GroupTopicSummary {
  372. id: string
  373. roomId: string
  374. title: string
  375. preview: string
  376. messageCount: number
  377. unreadCount?: number
  378. latestMessageSeq?: number
  379. createdAt: number
  380. updatedAt: number
  381. archived?: boolean
  382. pinned?: boolean
  383. }
  384. export interface GroupRoomActivity {
  385. roomId: string
  386. activeRunCount: number
  387. unreadCount: number
  388. lastMessage?: GroupMessage | null
  389. }
  390. export interface GroupTopicPage {
  391. items: GroupTopicSummary[]
  392. nextCursor?: string | null
  393. }
  394. export interface GroupMessagePage {
  395. items: GroupMessage[]
  396. }
  397. export type GroupEventType =
  398. | 'room.created'
  399. | 'room.updated'
  400. | 'room.deleted'
  401. | 'room.restored'
  402. | 'agent.created'
  403. | 'agent.updated'
  404. | 'agent.deleted'
  405. | 'agent.status'
  406. | 'message.upsert'
  407. | 'topic.updated'
  408. | 'topic.archived'
  409. | 'topic.restored'
  410. | 'room.activity'
  411. | 'interaction.requested'
  412. | 'interaction.resolved'
  413. | 'run.updated'
  414. | string
  415. export interface GroupSocketEnvelope {
  416. type: 'group.ready' | 'group.event' | 'group.heartbeat' | 'group.reset_required'
  417. epoch?: string
  418. cursor?: number
  419. heartbeatSeconds?: number
  420. roomId?: string
  421. event?: GroupEventType
  422. payload?: JsonValue
  423. reason?: string
  424. }
  425. export interface FileOrigin {
  426. workspaceConversationId?: string
  427. id?: number | string
  428. profile?: string
  429. sessionId?: string
  430. sessionTitle?: string
  431. messageId?: string
  432. authorKind?: 'user' | 'agent' | 'tool'
  433. authorName?: string
  434. observedAt?: number
  435. originalPath?: string
  436. referencePath?: string
  437. }
  438. export type FileKind = 'image' | 'video' | 'audio' | 'document' | 'other'
  439. export interface FileLibraryItem {
  440. id: string
  441. path: string
  442. name: string
  443. extension: string
  444. mimeType: string
  445. size: number
  446. modifiedAt: number
  447. exists: boolean
  448. availability?: 'archived' | 'source' | 'unavailable'
  449. archiveStatus?: string
  450. firstSeenAt?: number
  451. lastSeenAt?: number
  452. messageTimestamp?: number | null
  453. origins: FileOrigin[]
  454. kind: FileKind
  455. previewUrl?: string
  456. downloadUrl?: string
  457. }
  458. export interface FileLibraryPage {
  459. items: FileLibraryItem[]
  460. nextCursor?: string | null
  461. total?: number
  462. }
  463. export type ArtifactKind = 'image' | 'file' | 'link'
  464. export interface ConversationArtifact {
  465. id: string
  466. kind: ArtifactKind
  467. value: string
  468. label: string
  469. sessionId: string
  470. sessionTitle: string
  471. profile?: string
  472. messageId: string
  473. timestamp: number
  474. mimeType?: string
  475. attachment?: ChatAttachment
  476. }
  477. export interface ComposerState {
  478. draft: string
  479. attachments: ChatAttachment[]
  480. quotedMessageId?: string
  481. isComposing: boolean
  482. mode: 'send' | 'queue' | 'steer'
  483. }