@controlflow-ai/daemon 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +360 -0
  2. package/bin/console.js +2 -0
  3. package/bin/daemon.js +2 -0
  4. package/bin/pal.js +2 -0
  5. package/bin/server.js +2 -0
  6. package/package.json +31 -0
  7. package/src/agent-runtime.ts +285 -0
  8. package/src/app.ts +745 -0
  9. package/src/args.ts +54 -0
  10. package/src/artifacts.ts +85 -0
  11. package/src/cli.ts +284 -0
  12. package/src/client.ts +310 -0
  13. package/src/coco.ts +52 -0
  14. package/src/codex.ts +41 -0
  15. package/src/coding-agent-runtime.ts +20 -0
  16. package/src/config.ts +106 -0
  17. package/src/console.ts +349 -0
  18. package/src/daemon-client.ts +91 -0
  19. package/src/daemon.ts +580 -0
  20. package/src/db.ts +2830 -0
  21. package/src/failure-message.ts +17 -0
  22. package/src/format.ts +13 -0
  23. package/src/http.ts +55 -0
  24. package/src/lark/agent-runtime.ts +142 -0
  25. package/src/lark/cli.ts +549 -0
  26. package/src/lark/credentials.ts +105 -0
  27. package/src/lark/daemon-integration.ts +108 -0
  28. package/src/lark/dispatcher.ts +374 -0
  29. package/src/lark/event-router.ts +329 -0
  30. package/src/lark/inbound-events.ts +131 -0
  31. package/src/lark/server-integration.ts +445 -0
  32. package/src/lark/setup.ts +326 -0
  33. package/src/lark/ws-daemon.ts +224 -0
  34. package/src/lark-fixture-diagnostics.ts +56 -0
  35. package/src/lark-fixture.ts +277 -0
  36. package/src/local-api.ts +155 -0
  37. package/src/local-auth.ts +45 -0
  38. package/src/migrations/001_initial.ts +61 -0
  39. package/src/migrations/002_daemon_deliveries.ts +52 -0
  40. package/src/migrations/003_sessions_runs.ts +49 -0
  41. package/src/migrations/004_message_idempotency.ts +21 -0
  42. package/src/migrations/005_artifacts.ts +24 -0
  43. package/src/migrations/006_lark_channel_foundation.ts +119 -0
  44. package/src/migrations/007_agents_a0.ts +17 -0
  45. package/src/migrations/008_b0_chat_history.ts +31 -0
  46. package/src/migrations/009_b0_transcript_ingest_seq.ts +35 -0
  47. package/src/migrations/010_b0_transcript_shadow_external_ids.ts +32 -0
  48. package/src/migrations/011_b0_channel_conversation_audit_only.ts +27 -0
  49. package/src/migrations/012_b0_cross_conversation_invariant.ts +45 -0
  50. package/src/migrations/013_b1_0_eng_inbound_raw_events.ts +56 -0
  51. package/src/migrations/014_agents_runtime.ts +10 -0
  52. package/src/migrations/015_agent_runtime_sessions.ts +15 -0
  53. package/src/migrations/016_room_participants.ts +27 -0
  54. package/src/migrations/017_unified_room_delivery.ts +203 -0
  55. package/src/migrations/018_room_display_names.ts +36 -0
  56. package/src/migrations/019_computer_connections.ts +63 -0
  57. package/src/migrations/020_computer_agent_assignments.ts +20 -0
  58. package/src/migrations/021_provider_identity_bindings.ts +32 -0
  59. package/src/migrations.ts +85 -0
  60. package/src/neeko.ts +23 -0
  61. package/src/provider-identity.ts +40 -0
  62. package/src/runtime-registry.ts +41 -0
  63. package/src/server-auth.ts +13 -0
  64. package/src/server.ts +63 -0
  65. package/src/token-file.ts +57 -0
  66. package/src/types.ts +408 -0
  67. package/src/web.ts +565 -0
package/src/types.ts ADDED
@@ -0,0 +1,408 @@
1
+ export type ChatKind = 'group' | 'dm';
2
+ export type MessageType = 'message' | 'system';
3
+ export type RoomProvider = 'web' | 'lark' | 'wechat';
4
+ export type RoomTopicCapability = 'native' | 'unsupported';
5
+ export type AgentRoomSubscriptionMode = 'all' | 'periodic' | 'mentions' | 'muted' | 'off';
6
+ export type PalIdentityKind = 'user' | 'bot' | 'agent' | 'room';
7
+ export type ProviderExternalType = 'user' | 'bot' | 'room';
8
+
9
+ export interface Chat {
10
+ id: string;
11
+ name: string;
12
+ display_name: string | null;
13
+ kind: ChatKind;
14
+ server_id: string;
15
+ provider: RoomProvider;
16
+ dm_type: 'agent_agent' | 'user_agent' | 'user_user' | null;
17
+ capabilities_json: string;
18
+ audit_visibility: 'members' | 'admins';
19
+ created_at: string;
20
+ message_count: number;
21
+ last_message_at: string | null;
22
+ }
23
+
24
+ export type RoomParticipantKind = 'user' | 'bot' | 'agent';
25
+ export type RoomParticipantSource = 'lark_member_api' | 'known_bot' | 'event' | 'local_agent';
26
+
27
+ export interface RoomParticipant {
28
+ id: string;
29
+ room_id: string;
30
+ participant_id: string;
31
+ kind: RoomParticipantKind;
32
+ display_name: string | null;
33
+ source: RoomParticipantSource;
34
+ last_seen_at: string;
35
+ status: 'active' | 'removed';
36
+ joined_at: string;
37
+ delivery_cursor_message_id: number | null;
38
+ created_at: string;
39
+ updated_at: string;
40
+ }
41
+
42
+ export interface Message {
43
+ id: number;
44
+ chat_id: string;
45
+ chat_name: string;
46
+ parent_id: number | null;
47
+ depth: 0 | 1;
48
+ sender: string;
49
+ recipient: string | null;
50
+ content: string;
51
+ type: MessageType;
52
+ created_at: string;
53
+ idempotency_key: string | null;
54
+ channel_id?: string | null;
55
+ provider?: RoomProvider;
56
+ mentions?: string[];
57
+ }
58
+
59
+ export type RunStatus = 'running' | 'completed' | 'failed' | 'killed' | 'restarted';
60
+ export type RunAction = 'kill' | 'restart';
61
+ export type DeliveryStatus = 'pending' | 'claimed' | 'processing_completed' | 'acked' | 'failed' | 'canceled';
62
+
63
+ export interface AgentDefinition {
64
+ id: string;
65
+ agent_key: string;
66
+ display_name: string;
67
+ description: string | null;
68
+ runtime: string | null;
69
+ created_at: string;
70
+ updated_at: string;
71
+ }
72
+
73
+ export interface ComputerAgentAssignment {
74
+ agent: string;
75
+ display_name: string;
76
+ runtime: string | null;
77
+ computer_id: string;
78
+ cwd: string;
79
+ status: 'active' | 'disabled';
80
+ created_at: string;
81
+ updated_at: string;
82
+ }
83
+
84
+ export interface ProvisionedComputer {
85
+ computer: Computer;
86
+ api_key: string;
87
+ command: string;
88
+ }
89
+
90
+ export interface AgentValidationResult {
91
+ ok: boolean;
92
+ diagnostics: Array<{ level: 'error'; code: string; message: string }>;
93
+ }
94
+
95
+ export interface AgentRun {
96
+ id: string;
97
+ message_id: number;
98
+ agent: string;
99
+ status: RunStatus;
100
+ action: RunAction | null;
101
+ attempt: number;
102
+ pid: number | null;
103
+ cwd: string;
104
+ started_at: string;
105
+ updated_at: string;
106
+ ended_at: string | null;
107
+ exit_code: number | null;
108
+ output: string;
109
+ session_id: string | null;
110
+ trigger_message_id: number | null;
111
+ daemon_id: string | null;
112
+ connection_id: string | null;
113
+ computer_id: string | null;
114
+ runtime_provider: string | null;
115
+ runtime_invocation_id: string | null;
116
+ delivery_id: string | null;
117
+ }
118
+
119
+ export interface AgentSession {
120
+ id: string;
121
+ chat_id: string;
122
+ agent: string;
123
+ daemon_id: string;
124
+ computer_id: string | null;
125
+ runtime_provider: string | null;
126
+ cwd: string;
127
+ session_key: string;
128
+ created_at: string;
129
+ updated_at: string;
130
+ last_message_id: number | null;
131
+ runtime_session_id: string | null;
132
+ }
133
+
134
+ export interface DaemonInstance {
135
+ id: string;
136
+ name: string;
137
+ host: string;
138
+ local_url: string;
139
+ server_url: string;
140
+ status: 'online' | 'offline';
141
+ created_at: string;
142
+ last_seen_at: string;
143
+ }
144
+
145
+ export interface Computer {
146
+ id: string;
147
+ name: string;
148
+ status: 'online' | 'offline' | 'revoked';
149
+ active_connection_id: string | null;
150
+ last_seen_at: string | null;
151
+ created_at: string;
152
+ updated_at: string;
153
+ }
154
+
155
+ export interface ComputerConnection {
156
+ id: string;
157
+ computer_id: string;
158
+ epoch: number;
159
+ status: 'active' | 'revoked' | 'closed';
160
+ connected_at: string;
161
+ last_heartbeat_at: string;
162
+ revoked_at: string | null;
163
+ }
164
+
165
+ export interface MessageDelivery {
166
+ id: string;
167
+ message_id: number;
168
+ chat_id: string;
169
+ agent: string;
170
+ status: DeliveryStatus;
171
+ daemon_id: string | null;
172
+ connection_id: string | null;
173
+ claim_token: string | null;
174
+ lease_until: string | null;
175
+ attempts: number;
176
+ idempotency_key: string;
177
+ run_id: string | null;
178
+ last_error: string;
179
+ created_at: string;
180
+ claimed_at: string | null;
181
+ acked_at: string | null;
182
+ failed_at: string | null;
183
+ }
184
+
185
+ export interface Artifact {
186
+ id: string;
187
+ token_hash: string;
188
+ title: string;
189
+ filename: string;
190
+ mime_type: string;
191
+ size_bytes: number;
192
+ content: Uint8Array;
193
+ created_at: string;
194
+ expires_at: string;
195
+ revoked_at: string | null;
196
+ }
197
+
198
+ export interface ArtifactMetadata {
199
+ id: string;
200
+ title: string;
201
+ filename: string;
202
+ mime_type: string;
203
+ size_bytes: number;
204
+ created_at: string;
205
+ expires_at: string;
206
+ revoked_at: string | null;
207
+ }
208
+
209
+ export interface WorkbenchArtifact {
210
+ id: string;
211
+ title: string;
212
+ filename: string;
213
+ mime_type: string;
214
+ size_bytes: number;
215
+ created_at: string;
216
+ }
217
+
218
+ export interface ChannelAccount {
219
+ id: string;
220
+ channel: 'lark';
221
+ name: string;
222
+ app_id: string;
223
+ bot_open_id: string | null;
224
+ agent: string | null;
225
+ provider_account_id: string | null;
226
+ status: 'active' | 'disabled';
227
+ created_at: string;
228
+ updated_at: string;
229
+ }
230
+
231
+ export interface PalIdentity {
232
+ id: string;
233
+ kind: PalIdentityKind;
234
+ display_name: string | null;
235
+ stable_handle: string;
236
+ created_at: string;
237
+ updated_at: string;
238
+ }
239
+
240
+ export interface ProviderIdentityBinding {
241
+ id: string;
242
+ provider: Exclude<RoomProvider, 'web'>;
243
+ provider_account_id: string;
244
+ external_type: ProviderExternalType;
245
+ external_id: string;
246
+ identity_id: string;
247
+ created_at: string;
248
+ updated_at: string;
249
+ }
250
+
251
+ export interface ChannelConversation {
252
+ id: string;
253
+ channel_account_id: string;
254
+ lock_chat_id: string;
255
+ conversation_key: string;
256
+ external_chat_id: string;
257
+ external_root_id: string | null;
258
+ external_thread_id: string | null;
259
+ scope: 'chat' | 'thread' | 'p2p';
260
+ chat_type: 'group' | 'p2p';
261
+ audit_only: 0 | 1;
262
+ created_at: string;
263
+ last_seen_at: string;
264
+ }
265
+
266
+ export interface LockTranscriptMessage {
267
+ id: string;
268
+ lock_message_id: number | null;
269
+ conversation_id: string;
270
+ channel_type: 'lark' | 'internal';
271
+ direction: 'inbound' | 'outbound' | 'internal';
272
+ sender_type: 'user' | 'bot' | 'agent' | 'system';
273
+ sender_id: string;
274
+ recipient_ref: string | null;
275
+ content: string;
276
+ content_type: string;
277
+ source_type: string;
278
+ source_unique_key: string;
279
+ status: 'recorded' | 'superseded' | 'redacted';
280
+ mentions: string[];
281
+ reply_to_transcript_id: string | null;
282
+ quote_root_transcript_id: string | null;
283
+ quote_message_transcript_id: string | null;
284
+ reply_to_external_message_id: string | null;
285
+ quote_root_external_message_id: string | null;
286
+ quote_message_external_message_id: string | null;
287
+ created_at: string;
288
+ recorded_at: string;
289
+ }
290
+
291
+ export interface ChannelOutboxRecord {
292
+ id: string;
293
+ channel_account_id: string;
294
+ channel_conversation_id: string;
295
+ transcript_message_id: string;
296
+ lock_message_id: number | null;
297
+ purpose: string;
298
+ idempotency_key: string;
299
+ created_at: string;
300
+ }
301
+
302
+ export interface ChannelMessageMapping {
303
+ id: string;
304
+ channel_account_id: string;
305
+ channel_conversation_id: string;
306
+ lock_message_id: number | null;
307
+ transcript_message_id: string | null;
308
+ direction: 'inbound' | 'outbound';
309
+ external_message_id: string | null;
310
+ external_chat_id: string;
311
+ external_root_id: string | null;
312
+ external_thread_id: string | null;
313
+ sender_open_id: string | null;
314
+ sender_type: string;
315
+ raw_type: string;
316
+ status: 'mapped' | 'ignored' | 'rejected' | 'sent' | 'failed';
317
+ reason_code: string | null;
318
+ source: 'local_fixture' | 'channel_adapter';
319
+ admitted: 0 | 1;
320
+ raw_payload_redacted_json: string;
321
+ created_at: string;
322
+ }
323
+
324
+ export interface TranscriptReadModel {
325
+ id: string;
326
+ conversation_id: string;
327
+ direction: LockTranscriptMessage['direction'];
328
+ sender_type: LockTranscriptMessage['sender_type'];
329
+ sender_id: string;
330
+ recipient_ref: string | null;
331
+ content: string;
332
+ content_type: string;
333
+ status: LockTranscriptMessage['status'];
334
+ mentions: string[];
335
+ reply_to_transcript_id: string | null;
336
+ quote_root_transcript_id: string | null;
337
+ quote_message_transcript_id: string | null;
338
+ created_at: string;
339
+ recorded_at: string;
340
+ }
341
+
342
+ export interface LockProviderEvidence {
343
+ id: string;
344
+ transcript_message_id: string;
345
+ provider: 'lark';
346
+ provider_message_id: string | null;
347
+ provider_event_id: string | null;
348
+ attempt_id: string | null;
349
+ evidence_type: 'send_attempt' | 'send_result' | 'send_error' | 'receive_event';
350
+ receipt_state: 'pending' | 'delivered' | 'failed' | 'unknown';
351
+ error_code: string | null;
352
+ error_message: string | null;
353
+ raw_payload_redacted_json: string;
354
+ observed_at: string | null;
355
+ created_at: string;
356
+ }
357
+
358
+ export interface ApiResponse<T> {
359
+ ok: boolean;
360
+ data?: T;
361
+ code?: string;
362
+ message?: string;
363
+ }
364
+
365
+
366
+ export interface AgentRoomSubscription {
367
+ id: string;
368
+ agent: string;
369
+ room_id: string;
370
+ channel_id: string | null;
371
+ mode: AgentRoomSubscriptionMode;
372
+ created_at: string;
373
+ updated_at: string;
374
+ }
375
+
376
+ export interface RoomChannel {
377
+ id: string;
378
+ room_id: string;
379
+ kind: 'topic';
380
+ name: string;
381
+ external_ref: string | null;
382
+ created_by: string | null;
383
+ created_at: string;
384
+ }
385
+
386
+ export interface PendingInboundEvent {
387
+ id: string;
388
+ raw_event_id: string;
389
+ provider: Exclude<RoomProvider, 'web'>;
390
+ provider_account_id: string | null;
391
+ reason: string;
392
+ retry_count: number;
393
+ next_retry_at: string | null;
394
+ last_error: string;
395
+ status: 'pending' | 'resolved' | 'dead';
396
+ created_at: string;
397
+ updated_at: string;
398
+ }
399
+
400
+ export interface LarkGroupRoomMapping {
401
+ room_id: string;
402
+ room_name: string;
403
+ display_name: string | null;
404
+ external_chat_id: string;
405
+ app_id: string;
406
+ bot_open_id: string | null;
407
+ agent: string | null;
408
+ }