-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmodels.ts
More file actions
476 lines (432 loc) · 12.6 KB
/
models.ts
File metadata and controls
476 lines (432 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
/**
* Moltslack Data Models
*
* Core data models for the agent messaging platform.
* Designed with zero-trust security principles.
*/
// ============================================================================
// COMMON TYPES
// ============================================================================
/** ISO 8601 timestamp string */
export type Timestamp = string;
/** UUID v4 identifier */
export type UUID = string;
/** Cryptographic hash (SHA-256) */
export type Hash = string;
/** Base64-encoded signature */
export type Signature = string;
/** Scoped identifier: project:resource or resource */
export type ScopedId = string;
// ============================================================================
// AGENT MODEL
// ============================================================================
export enum AgentStatus {
ACTIVE = 'active',
IDLE = 'idle',
OFFLINE = 'offline',
SUSPENDED = 'suspended',
TERMINATED = 'terminated'
}
export enum AgentType {
HUMAN = 'human',
AI = 'ai',
SYSTEM = 'system',
SERVICE = 'service'
}
export interface AgentCapability {
/** Capability identifier (e.g., 'code_execution', 'web_search') */
id: string;
/** Whether capability is currently enabled */
enabled: boolean;
/** Capability-specific configuration */
config?: Record<string, unknown>;
/** Rate limits for this capability */
rateLimit?: {
maxRequests: number;
windowSeconds: number;
};
}
export interface AgentCredentials {
/** Public key for message verification (PEM format) */
publicKey: string;
/** Token hash for API authentication */
tokenHash: Hash;
/** Token expiration timestamp */
tokenExpiresAt: Timestamp;
/** List of revoked token hashes */
revokedTokens: Hash[];
}
export interface AgentMetadata {
/** Human-readable display name */
displayName: string;
/** Agent description/bio */
description?: string;
/** Avatar URL */
avatarUrl?: string;
/** CLI used to spawn this agent */
cli?: string;
/** Model identifier (e.g., 'claude-opus-4-5-20251101') */
model?: string;
/** Custom key-value metadata */
custom?: Record<string, string>;
}
export interface Agent {
/** Unique agent identifier */
id: UUID;
/** Unique name within project scope */
name: string;
/** Project this agent belongs to */
projectId: UUID;
/** Agent type classification */
type: AgentType;
/** Current operational status */
status: AgentStatus;
/** Agent capabilities */
capabilities: AgentCapability[];
/** Authentication credentials */
credentials: AgentCredentials;
/** Agent metadata */
metadata: AgentMetadata;
/** ID of agent that spawned this one (null for root) */
spawnerId?: UUID;
/** Timestamp when agent was created */
createdAt: Timestamp;
/** Timestamp of last activity */
lastActiveAt: Timestamp;
/** Timestamp when agent was terminated (if applicable) */
terminatedAt?: Timestamp;
}
// ============================================================================
// CHANNEL MODEL
// ============================================================================
export enum ChannelType {
PUBLIC = 'public',
PRIVATE = 'private',
DIRECT = 'direct',
BROADCAST = 'broadcast'
}
export enum ChannelAccessLevel {
READ = 'read',
WRITE = 'write',
ADMIN = 'admin'
}
/** Channel access level string literal type */
export type ChannelAccessLevelValue = 'read' | 'write' | 'admin';
export interface ChannelAccessRule {
/** Principal: agent ID, role name, or '*' for all */
principal: string;
/** Type of principal */
principalType: 'agent' | 'role' | 'all';
/** Access level granted */
level: ChannelAccessLevelValue;
/** Optional expiration */
expiresAt?: Timestamp;
}
export interface ChannelMetadata {
/** Human-readable channel name */
displayName: string;
/** Channel topic/description */
topic?: string;
/** Channel purpose */
purpose?: string;
/** Whether channel is archived */
isArchived: boolean;
/** Whether channel allows external agents (cross-project) */
allowExternal: boolean;
/** Maximum message retention (null = forever) */
retentionDays?: number;
/** Custom key-value metadata */
custom?: Record<string, string>;
}
export interface Channel {
/** Unique channel identifier */
id: UUID;
/** Channel name (e.g., '#general', '#dev-tasks') */
name: string;
/** Project this channel belongs to */
projectId: UUID;
/** Channel type */
type: ChannelType;
/** Access control rules (evaluated in order, first match wins) */
accessRules: ChannelAccessRule[];
/** Default access for agents not matching any rule */
defaultAccess: ChannelAccessLevelValue | null;
/** Channel metadata */
metadata: ChannelMetadata;
/** Agent who created the channel */
createdBy: UUID;
/** Timestamp when channel was created */
createdAt: Timestamp;
/** Timestamp of last message */
lastMessageAt?: Timestamp;
/** Count of members with access */
memberCount: number;
}
// ============================================================================
// MESSAGE MODEL
// ============================================================================
export enum MessageType {
TEXT = 'text',
SYSTEM = 'system',
COMMAND = 'command',
EVENT = 'event',
FILE = 'file',
REACTION = 'reaction',
THREAD_REPLY = 'thread_reply'
}
export enum MessageDeliveryStatus {
PENDING = 'pending',
SENT = 'sent',
DELIVERED = 'delivered',
READ = 'read',
FAILED = 'failed'
}
/** Message delivery status string literal type */
export type MessageDeliveryStatusValue = 'pending' | 'sent' | 'delivered' | 'read' | 'failed';
export interface MessageAttachment {
/** Attachment identifier */
id: UUID;
/** MIME type */
mimeType: string;
/** File name */
filename: string;
/** File size in bytes */
sizeBytes: number;
/** Secure URL to fetch attachment */
url: string;
/** Content hash for integrity verification */
contentHash: Hash;
}
export interface MessageMention {
/** Type of mention */
type: 'agent' | 'channel' | 'all';
/** Referenced ID (agent or channel) */
targetId?: UUID;
/** Position in message content (start index) */
startIndex: number;
/** Length of mention text */
length: number;
}
export interface MessageContent {
/** Plain text content */
text: string;
/** Structured data (for commands, events) */
data?: Record<string, unknown>;
/** Extracted mentions */
mentions: MessageMention[];
/** Attached files */
attachments: MessageAttachment[];
}
export interface Message {
/** Unique message identifier */
id: UUID;
/** Project scope */
projectId: UUID;
/** Target: channel ID, agent ID for DM, or '*' for broadcast */
targetId: string;
/** Type of target */
targetType: 'channel' | 'agent' | 'broadcast';
/** Sending agent ID */
senderId: UUID;
/** Message type classification */
type: MessageType;
/** Message content */
content: MessageContent;
/** Thread parent message ID (null if not a reply) */
threadId?: UUID;
/** Correlation ID for request/response tracking */
correlationId?: UUID;
/** Cryptographic signature of message */
signature: Signature;
/** Delivery status */
deliveryStatus: MessageDeliveryStatusValue;
/** Timestamp when message was sent */
sentAt: Timestamp;
/** Timestamp when message was edited (if applicable) */
editedAt?: Timestamp;
/** Timestamp when message was deleted (soft delete) */
deletedAt?: Timestamp;
}
// ============================================================================
// PERMISSION MODEL
// ============================================================================
export enum PermissionScope {
GLOBAL = 'global',
PROJECT = 'project',
CHANNEL = 'channel',
AGENT = 'agent'
}
export enum PermissionAction {
// Agent permissions
AGENT_SPAWN = 'agent:spawn',
AGENT_RELEASE = 'agent:release',
AGENT_VIEW = 'agent:view',
AGENT_MANAGE = 'agent:manage',
// Channel permissions
CHANNEL_CREATE = 'channel:create',
CHANNEL_DELETE = 'channel:delete',
CHANNEL_READ = 'channel:read',
CHANNEL_WRITE = 'channel:write',
CHANNEL_MANAGE = 'channel:manage',
// Message permissions
MESSAGE_SEND = 'message:send',
MESSAGE_DELETE = 'message:delete',
MESSAGE_EDIT_OWN = 'message:edit_own',
MESSAGE_EDIT_ANY = 'message:edit_any',
// System permissions
SYSTEM_ADMIN = 'system:admin',
SYSTEM_AUDIT = 'system:audit'
}
export interface Permission {
/** Unique permission identifier */
id: UUID;
/** Scope of the permission */
scope: PermissionScope;
/** Resource ID within scope (null for global scope) */
resourceId?: UUID;
/** Allowed actions */
actions: PermissionAction[];
/** Conditions for permission to apply */
conditions?: {
/** Time-based restrictions */
timeWindow?: {
startTime?: string; // HH:MM format
endTime?: string;
daysOfWeek?: number[]; // 0-6, Sunday = 0
};
/** IP/network restrictions */
allowedNetworks?: string[];
/** Rate limiting */
rateLimit?: {
maxRequests: number;
windowSeconds: number;
};
};
}
export interface Role {
/** Unique role identifier */
id: UUID;
/** Role name */
name: string;
/** Project this role belongs to (null for global roles) */
projectId?: UUID;
/** Description of role purpose */
description: string;
/** Permissions granted by this role */
permissions: Permission[];
/** Whether role is a system role (immutable) */
isSystem: boolean;
/** Timestamp when role was created */
createdAt: Timestamp;
}
export interface Token {
/** Token identifier (not the actual token) */
id: UUID;
/** Agent this token belongs to */
agentId: UUID;
/** Token hash (for lookup/validation) */
hash: Hash;
/** Permissions scoped to this token */
permissions: Permission[];
/** Token metadata */
metadata: {
name: string;
description?: string;
createdBy: UUID;
};
/** Token expiration */
expiresAt: Timestamp;
/** Timestamp when token was created */
createdAt: Timestamp;
/** Timestamp when token was last used */
lastUsedAt?: Timestamp;
/** Whether token has been revoked */
isRevoked: boolean;
/** Timestamp when token was revoked */
revokedAt?: Timestamp;
}
// ============================================================================
// PRESENCE MODEL
// ============================================================================
export enum PresenceStatus {
ONLINE = 'online',
IDLE = 'idle',
BUSY = 'busy',
DO_NOT_DISTURB = 'dnd',
OFFLINE = 'offline'
}
/** Presence status string literal type */
export type PresenceStatusValue = 'online' | 'idle' | 'busy' | 'dnd' | 'offline';
export interface PresenceActivity {
/** Type of activity */
type: 'working' | 'waiting' | 'processing' | 'custom';
/** Activity description */
description?: string;
/** Task or thread being worked on */
contextId?: UUID;
/** Started timestamp */
startedAt: Timestamp;
}
export interface Presence {
/** Agent ID */
agentId: UUID;
/** Project ID */
projectId: UUID;
/** Current status */
status: PresenceStatusValue;
/** Manual status message */
statusMessage?: string;
/** Current activity */
activity?: PresenceActivity;
/** Last heartbeat received */
lastHeartbeat: Timestamp;
/** Channels agent is actively monitoring */
activeChannels: UUID[];
/** Whether agent is currently typing */
isTyping: boolean;
/** Channel where agent is typing */
typingInChannel?: UUID;
/** Client connection metadata */
connection: {
/** Connection ID */
connectionId: UUID;
/** Client type */
clientType: 'cli' | 'web' | 'api' | 'bridge';
/** Client version */
clientVersion: string;
/** Connected timestamp */
connectedAt: Timestamp;
/** IP address (for audit) */
ipAddress?: string;
};
}
// ============================================================================
// PROJECT MODEL
// ============================================================================
export interface Project {
/** Unique project identifier */
id: UUID;
/** Project name (used in scoped identifiers) */
name: string;
/** Human-readable display name */
displayName: string;
/** Project description */
description?: string;
/** Project owner agent ID */
ownerId: UUID;
/** Project-wide settings */
settings: {
/** Allow cross-project messaging */
allowBridge: boolean;
/** Default message retention days */
defaultRetentionDays?: number;
/** Require message signing */
requireSignatures: boolean;
/** Maximum agents allowed */
maxAgents: number;
/** Maximum channels allowed */
maxChannels: number;
};
/** Timestamp when project was created */
createdAt: Timestamp;
}