types.ts 11 KB

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