-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtypes.ts
More file actions
197 lines (181 loc) · 7.7 KB
/
Copy pathtypes.ts
File metadata and controls
197 lines (181 loc) · 7.7 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
import type {
BossControlEnvelope,
BossFeatureRegistration,
BossParticipantBinding,
BossPrivatePrincipal,
} from "@dataforxyz/agent-intercom-core/boss";
/**
* Broker-authenticated Boss metadata. It is intentionally absent from
* SessionRegistration so an ordinary client cannot self-assert a run, role,
* or binding epoch.
*/
export interface BossSessionMetadata {
registration: BossFeatureRegistration;
principal: BossPrivatePrincipal;
/** Controller principals have no participant binding; all other roles do. */
binding?: BossParticipantBinding;
}
export interface SessionInfo {
id: string;
name?: string;
cwd: string;
model: string;
pid: number;
startedAt: number;
lastActivity: number;
status?: string;
peerUid?: number;
trustedLocal?: boolean;
origin?: "local" | "remote";
remoteHostId?: string;
parentSessionId?: string;
rootSessionId?: string;
generation?: number;
canDelegate?: boolean;
depth?: number;
maxDepth?: number;
maxChildren?: number;
boss?: BossSessionMetadata;
}
export interface Message {
id: string;
timestamp: number;
replyTo?: string;
expectsReply?: boolean;
content: {
text: string;
attachments?: Attachment[];
};
}
export interface Attachment {
type: "file" | "snippet" | "context";
name: string;
content: string;
language?: string;
}
export type SessionRegistration = Omit<
SessionInfo,
"id" | "peerUid" | "trustedLocal" | "origin" | "remoteHostId" | "parentSessionId" | "rootSessionId" | "generation" | "canDelegate" | "depth" | "maxDepth" | "maxChildren" | "boss"
> & {
/** Ephemeral identity shared only by reconnects from one live runtime. */
runtimeInstanceId?: string;
};
export interface RemoteEnrollmentAccess {
enrollmentToken: string;
}
export interface RemoteSessionAccess {
sessionCredential: string;
sessionId: string;
generation: number;
}
export type RemoteRegistrationAccess = RemoteEnrollmentAccess | RemoteSessionAccess;
export interface RemoteAccessMetadata {
origin: "remote";
remoteHostId: string;
parentSessionId: string;
rootSessionId: string;
generation: number;
canDelegate: boolean;
depth: number;
maxDepth: number;
maxChildren: number;
sessionCredential?: string;
}
export interface RemotePrincipalSummary {
id: string;
name: string;
parentSessionId: string;
rootSessionId: string;
remoteHostId: string;
generation: number;
policy: "remote-tree";
canDelegate: boolean;
depth: number;
maxDepth: number;
maxChildren: number;
state: "active" | "revoked";
expiresAt: number;
createdAt: number;
updatedAt: number;
connected: boolean;
}
export interface RemoteAccessContract {
feature: "remote-access-v1";
policySemanticsVersion: number;
policySemanticsHash: string;
}
export type DeliveryFailureCode =
| "INVALID_MESSAGE"
| "SESSION_NOT_FOUND"
| "AMBIGUOUS_TARGET"
| "SENDER_NOT_FOUND"
| "INVALID_REPLY_TARGET"
| "MUTUAL_ASK"
| "ASK_ALREADY_PENDING"
| "DUPLICATE_MESSAGE_ID"
| "CONFLICTING_MESSAGE_ID"
| "TOO_MANY_PENDING_DELIVERIES"
| "TOO_MANY_PENDING_ASKS"
| "RECIPIENT_DISCONNECTED"
| "SENDER_DISCONNECTED"
| "DELIVERY_TIMEOUT"
| "INVALID_BOSS_CONTROL"
| "BOSS_CONTROL_DENIED";
export type BrokerErrorCode =
| "PROTOCOL_MISMATCH"
| "INVALID_REQUEST"
| "SESSION_ID_IN_USE"
| "ACCESS_DENIED"
| "REMOTE_ACCESS_INCOMPATIBLE"
| "RATE_LIMITED"
| "TOO_MANY_SESSIONS";
export type AskCancellationReason =
| "cancelled"
| "expired"
| "delivery_failed"
| "session_disconnected"
| "authorization_revoked";
export type ClientMessage =
| { type: "health"; requestId: string; stateId?: string }
| { type: "register"; protocol: string; version: number; session: SessionRegistration; sessionId?: string; stateId?: string; access?: RemoteRegistrationAccess }
| { type: "access_control"; requestId: string; adminToken: string; action: "issue_enrollment"; enrollment: { name: string; parentSessionId: string; rootSessionId: string; remoteHostId: string; ttlMs?: number; expiresAt?: number; canDelegate?: boolean; maxDepth?: number; maxChildren?: number } }
| { type: "access_control"; requestId: string; adminToken: string; action: "revoke_subtree"; principalId: string }
| { type: "access_control"; requestId: string; adminToken: string; action: "inspect_tree"; principalId: string }
| { type: "access_control"; requestId: string; adminToken: string; action: "adopt_subtree"; principalId: string; newParentSessionId: string }
| { type: "access_control"; requestId: string; access: RemoteSessionAccess; action: "issue_child_enrollment"; enrollment: { name: string; ttlMs?: number; expiresAt?: number; canDelegate?: boolean; maxDepth?: number; maxChildren?: number } }
| { type: "access_control"; requestId: string; access: RemoteSessionAccess; action: "inspect_tree"; principalId?: string }
| { type: "unregister"; preserveAsks?: boolean }
| { type: "list"; requestId: string }
| { type: "send"; to: string; message: Message }
| { type: "boss_control_send"; to: string; envelope: BossControlEnvelope }
| { type: "boss_control_received"; deliveryId: string }
| { type: "message_received"; deliveryId: string }
| { type: "message_rejected"; deliveryId: string; code: "CONFLICTING_MESSAGE_ID"; reason: string }
| { type: "defer_ask"; requestId: string; messageId: string }
| { type: "cancel_ask"; requestId: string; messageId: string }
| { type: "presence"; name?: string; status?: string; model?: string };
export type BrokerMessage =
| { type: "health_ok"; requestId: string; protocol: string; version: number; endpoint: "local" | "remote"; remoteAccess?: RemoteAccessContract }
| { type: "registered"; sessionId: string; protocol: string; version: number; remoteAccess?: RemoteAccessContract; access?: RemoteAccessMetadata }
| { type: "access_control_result"; requestId: string; action: "issue_enrollment"; enrollmentToken: string; expiresAt: number }
| { type: "access_control_result"; requestId: string; action: "revoke_subtree"; changedPrincipalIds: string[] }
| { type: "access_control_result"; requestId: string; action: "inspect_tree"; principals: RemotePrincipalSummary[] }
| { type: "access_control_result"; requestId: string; action: "adopt_subtree"; principals: RemotePrincipalSummary[] }
| { type: "access_control_result"; requestId: string; action: "issue_child_enrollment"; enrollmentToken: string; expiresAt: number; parentSessionId: string }
| { type: "sessions"; requestId: string; sessions: SessionInfo[] }
| { type: "message"; deliveryId: string; from: SessionInfo; message: Message }
| { type: "boss_control"; deliveryId: string; from: SessionInfo; envelope: BossControlEnvelope }
| { type: "boss_control_accepted"; messageId: string; deliveryId: string }
| { type: "boss_control_delivered"; messageId: string; deliveryId: string }
| { type: "boss_control_failed"; messageId: string; accepted: false; code: DeliveryFailureCode; reason: string }
| { type: "boss_control_failed"; messageId: string; deliveryId: string; accepted: true; code: DeliveryFailureCode; reason: string }
| { type: "presence_update"; session: SessionInfo }
| { type: "session_joined"; session: SessionInfo }
| { type: "session_left"; sessionId: string }
| { type: "error"; code: BrokerErrorCode; error: string }
| { type: "delivery_accepted"; messageId: string; deliveryId: string }
| { type: "delivered"; messageId: string; deliveryId: string }
| { type: "delivery_failed"; messageId: string; accepted: boolean; code: DeliveryFailureCode; reason: string }
| { type: "ask_deferred"; messageId: string; fromSessionId: string }
| { type: "ask_cancelled"; messageId: string; fromSessionId: string; reason: AskCancellationReason }
| { type: "ask_control_result"; requestId: string; action: "defer" | "cancel"; messageId: string; applied: boolean };