types.ts 11 KB

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