types.ts 12 KB

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