types.ts 11 KB

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