workspace.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /** Application-owned identities. Hermes profile/session IDs never identify a chat. */
  2. export interface WorkspaceAgent {
  3. id: string
  4. name: string
  5. avatar: string
  6. instructions: string
  7. /** Explicit account-owner grant; absent on older records means disabled. */
  8. execution?: 'profile' | 'computer'
  9. computer?: 'auto' | 'cloud' | 'vm' | 'local' | 'browser' | 'off'
  10. allowHostEnvironment?: boolean
  11. /** Local VM execution backend; older records retain the isolated Worker. */
  12. vmExecution?: 'worker' | 'profile'
  13. browserProfile?: 'persistent' | 'temporary'
  14. computerEnvironmentId?:string
  15. computerEnvironmentName?:string
  16. canManageTeam?: boolean
  17. teamAuthorizationVersion?: number
  18. temporaryGoalId?:string
  19. helperActivation?:number
  20. helperRunnerId?:string
  21. retiredAt?:number
  22. cleanupState?:'pending'|'complete'
  23. createdByAgentId?: string
  24. createdFromRunId?: string
  25. nodeId: string
  26. profile: string
  27. remoteAgentId?: string
  28. archived: boolean
  29. revision: number
  30. createdAt: number
  31. updatedAt: number
  32. }
  33. export function supportsHostEnvironment(agent: Pick<WorkspaceAgent,'computer'|'execution'>):boolean {
  34. return agent.computer==='vm'||agent.computer==='cloud'||(!agent.computer&&agent.execution==='computer')
  35. }
  36. export function allowsHostEnvironment(agent: Pick<WorkspaceAgent,'computer'|'execution'|'allowHostEnvironment'|'archived'|'remoteAgentId'|'temporaryGoalId'>):boolean {
  37. return agent.allowHostEnvironment===true&&supportsHostEnvironment(agent)&&!agent.archived&&!agent.remoteAgentId&&!agent.temporaryGoalId
  38. }
  39. export interface WorkspaceMemberRole {
  40. name: string
  41. description: string
  42. }
  43. export interface WorkspaceConversation {
  44. id: string
  45. kind: 'direct' | 'group'
  46. name: string
  47. avatar: string
  48. memberIds: string[]
  49. memberRoles?: Record<string, WorkspaceMemberRole>
  50. instructions: string
  51. administratorId: string
  52. mode: 'host' | 'free'
  53. autoReplyIds: string[]
  54. maxReplyRounds: number
  55. archived: boolean
  56. pinned: boolean
  57. readSeq: number
  58. lastSeq: number
  59. lastMessageAt?: number
  60. preview: string
  61. previewAgentId?: string
  62. activeRunId?: string
  63. activeAgentId?: string
  64. activeRunStatus?: WorkspaceRun['status']
  65. activeAgentStates?: Record<string, 'running' | 'waiting' | 'uncertain' | 'queued'>
  66. avatarSignals?: Record<string, { id: string; state: 'success' | 'failure'; at: number }>
  67. queuedMessageCount?: number
  68. unread?: boolean
  69. /** Changes when new attention arrives, so an older read cannot clear it. */
  70. unreadVersion?: number
  71. /** Compatibility signal for older clients: always 0 or 1. */
  72. unreadCount?: number
  73. createdAt: number
  74. updatedAt: number
  75. }
  76. /** Shared by the HTTP lists, snapshots and Web/desktop incremental state. */
  77. export function workspaceConversationTimestamp(value: Pick<WorkspaceConversation, 'lastMessageAt' | 'createdAt'>): number {
  78. return value.lastMessageAt ?? value.createdAt
  79. }
  80. export function compareWorkspaceConversations(a: WorkspaceConversation, b: WorkspaceConversation): number {
  81. return Number(b.pinned) - Number(a.pinned)
  82. || workspaceConversationTimestamp(b) - workspaceConversationTimestamp(a)
  83. || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)
  84. }
  85. export interface WorkspaceTask {
  86. id: string
  87. conversationId: string
  88. title: string
  89. titleSource: 'automatic' | 'user'
  90. messageCount: number
  91. readSeq: number
  92. lastSeq: number
  93. unread?: boolean
  94. unreadVersion?: number
  95. /** Compatibility signal for older clients: always 0 or 1. */
  96. unreadCount: number
  97. activeRunId?: string
  98. activeRunStatus?: WorkspaceRun['status']
  99. lastMessageAt?: number
  100. createdAt: number
  101. updatedAt: number
  102. goal?: import('./agentTasks.js').AgentGoal
  103. }
  104. export function workspaceHasUnread(value: { unread?: boolean; unreadCount?: number; lastSeq: number; readSeq: number }): boolean {
  105. return value.unread ?? (value.unreadCount !== undefined ? value.unreadCount > 0 : value.lastSeq > value.readSeq)
  106. }
  107. export interface WorkspaceFile {
  108. id: string
  109. name: string
  110. mimeType: string
  111. size: number
  112. createdAt: number
  113. sourcePath?: string
  114. conversationId?: string
  115. messageId?: string
  116. profile?: string
  117. sender: 'user' | 'agent'
  118. }
  119. export interface WorkspaceMessage {
  120. revision?: number
  121. execution?:'profile'|'computer'
  122. id: string
  123. conversationId: string
  124. /** User-visible task scope. `taskId` below remains the scheduler turn ID. */
  125. conversationTaskId?: string
  126. seq: number
  127. role: 'user' | 'assistant' | 'system'
  128. taskReference?: { conversationId: string; taskId: string }
  129. agentId?: string
  130. agentName?: string
  131. content: string
  132. reasoning: string
  133. runId?: string
  134. taskId?: string
  135. visible?: boolean
  136. error?: string
  137. status: 'queued' | 'streaming' | 'complete' | 'failed' | 'interrupted' | 'uncertain'
  138. attachments: WorkspaceFile[]
  139. tools: Array<Record<string, unknown>>
  140. createdAt: number
  141. }
  142. export interface WorkspaceMessagePatch {
  143. id: string
  144. conversationId: string
  145. conversationTaskId?: string
  146. baseRevision: number
  147. revision: number
  148. contentAppend: string
  149. reasoningAppend: string
  150. }
  151. export interface WorkspaceRun {
  152. id: string
  153. conversationId: string
  154. conversationTaskId?: string
  155. messageId: string
  156. mentionIds: string[]
  157. activeAgentId?: string
  158. status: 'queued' | 'running' | 'waiting' | 'complete' | 'failed' | 'interrupted' | 'uncertain'
  159. round: number
  160. error?: string
  161. stopRequested?: boolean
  162. assignmentId?: string
  163. /** Structured delivery run; ordinary chat does not carry a goal. */
  164. goalId?: string
  165. targetAgentId?: string
  166. triggerKind?: 'assignment' | 'task_review' | 'task_result'
  167. internalInstruction?: string
  168. authorizationVersion?: number
  169. createdAt: number
  170. updatedAt: number
  171. }
  172. export interface WorkspaceInteraction {
  173. id: string
  174. conversationId: string
  175. conversationTaskId?: string
  176. runId: string
  177. agentId: string
  178. kind: 'approval' | 'clarification'
  179. message: string
  180. choices: string[]
  181. resolved: boolean
  182. }
  183. export interface WorkspaceEvent {
  184. seq: number
  185. type: string
  186. conversationId?: string
  187. data: unknown
  188. }
  189. /** Additional fields are optional while clients can still connect to older servers. */
  190. export interface WorkspaceSendReceipt {
  191. requestId?: string
  192. run: WorkspaceRun
  193. message?: WorkspaceMessage
  194. conversation?: WorkspaceConversation
  195. task?: WorkspaceTask | null
  196. cursor?: number
  197. }
  198. export interface WorkspaceSource {
  199. nodeId: string
  200. profile: string
  201. name: string
  202. }