@@ -105,6 +105,90 @@ CoCalc is organized as a monorepo with key packages:
105
105
5 . ** Authentication** : Each conat request includes account_id and is subject to permission checks at the hub level
106
106
6 . ** Subjects** : Messages are routed using hierarchical subjects like ` hub.account.{uuid}.{service} ` or ` project.{uuid}.{compute_server_id}.{service} `
107
107
108
+ ### Conat Message Patterns
109
+
110
+ CoCalc's Conat messaging system uses hierarchical dot-separated subject patterns for routing messages between distributed services:
111
+
112
+ #### User Account Messages
113
+ ```
114
+ hub.account.{account_id}.{service}
115
+ ```
116
+ - ** account_id** : UUID v4 format (e.g., ` 123e4567-e89b-12d3-a456-426614174000 ` )
117
+ - ** service** : API service name (` api ` , ` projects ` , ` db ` , ` purchases ` , ` jupyter ` , ` sync ` , ` org ` , ` messages ` )
118
+ - ** Examples** :
119
+ - ` hub.account.123e4567-e89b-12d3-a456-426614174000.api ` - Main API calls
120
+ - ` hub.account.123e4567-e89b-12d3-a456-426614174000.projects ` - Project operations
121
+ - ` hub.account.123e4567-e89b-12d3-a456-426614174000.db ` - Database operations
122
+
123
+ #### Project Messages
124
+ ```
125
+ project.{project_id}.{compute_server_id}.{service}.{path}
126
+ ```
127
+ - ** project_id** : UUID v4 format for the project
128
+ - ** compute_server_id** : Numeric ID or ` - ` for default/no specific server
129
+ - ** service** : Service name (` api ` , ` terminal ` , ` sync ` , ` jupyter ` , etc.)
130
+ - ** path** : Base64-encoded file path or ` - ` for no path
131
+ - ** Examples** :
132
+ - ` project.456e7890-e89b-12d3-a456-426614174001.1.api.- ` - Project API (compute server 1)
133
+ - ` project.456e7890-e89b-12d3-a456-426614174001.-.terminal.L2hvbWUvdXNlcg== ` - Terminal service (path: ` /home/user ` )
134
+ - ` project.456e7890-e89b-12d3-a456-426614174001.2.sync.- ` - Sync service (compute server 2)
135
+
136
+ #### Hub Project Messages
137
+ ```
138
+ hub.project.{project_id}.{service}
139
+ ```
140
+ - Used for hub-level project operations
141
+ - ** Examples** :
142
+ - ` hub.project.456e7890-e89b-12d3-a456-426614174001.api ` - Project API calls
143
+ - ` hub.project.456e7890-e89b-12d3-a456-426614174001.sync ` - Project sync operations
144
+
145
+ #### Browser Session Messages
146
+ ```
147
+ {sessionId}.account-{account_id}.{service}
148
+ ```
149
+ - Used for browser-specific sessions
150
+ - ** sessionId** : Unique session identifier
151
+ - ** Examples** : ` {session123}.account-123e4567-e89b-12d3-a456-426614174000.sync `
152
+
153
+ #### Service-Specific Messages
154
+ ```
155
+ {service}.account-{account_id}.api
156
+ {service}.project-{project_id}.api
157
+ ```
158
+ - Used by global services like time, LLM, etc.
159
+ - ** Examples** :
160
+ - ` time.account-123e4567-e89b-12d3-a456-426614174000.api ` - Time service
161
+ - ` llm.project-456e7890-e89b-12d3-a456-426614174001.api ` - LLM service
162
+
163
+ #### Pattern Matching
164
+ - ` * ` - Matches any single segment
165
+ - ` > ` - Matches the rest of the subject (catch-all)
166
+ - Used for subscribing to multiple related subjects
167
+
168
+ #### Key Features
169
+ - ** Automatic Chunking** : Large messages are automatically split and reassembled
170
+ - ** Multiple Encodings** : MsgPack (compact) and JSON supported
171
+ - ** Interest Awareness** : Wait for subscribers before sending messages
172
+ - ** Delivery Confirmation** : Optional confirmation of message receipt
173
+ - ** Authentication** : Per-subject permission checking with account/project IDs
174
+
175
+ #### Usage in Code
176
+ ``` typescript
177
+ // Account message
178
+ const accountSubject = ` hub.account.${accountId }.api ` ;
179
+
180
+ // Project message using helper
181
+ import { projectSubject } from " @cocalc/conat/names" ;
182
+ const projectSub = projectSubject ({
183
+ project_id: projectId ,
184
+ compute_server_id: 1 ,
185
+ service: ' terminal' ,
186
+ path: ' /home/user'
187
+ });
188
+ ```
189
+
190
+ These patterns ensure proper routing, authentication, and isolation between different users and projects in the distributed system. The hierarchical structure allows for efficient pattern matching and scalable message routing across the CoCalc platform.
191
+
108
192
### Key Technologies
109
193
110
194
- ** TypeScript** : Primary language for all new code
0 commit comments