-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProteinCommandChannel.ts
More file actions
105 lines (91 loc) · 3.15 KB
/
ProteinCommandChannel.ts
File metadata and controls
105 lines (91 loc) · 3.15 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
/**
* Protein command bus — `/commands/*` API via shared HTTPClient (auth, X-Project-ID, retries).
* Complements Rules Engine `AgentCommand` (`/command`) and high-level `AgentProtein` (`/protein/execute`).
*/
import { HTTPClient } from '../client/http-client';
/** Request body for POST /commands/execute */
export interface ProteinCommandExecuteRequest {
command_type: string;
command_name: string;
payload: Record<string, unknown>;
priority?: number;
timeout_ms?: number;
retry_count?: number;
}
export interface ProteinBatchCommandRequest {
commands: ProteinCommandExecuteRequest[];
execute_parallel?: boolean;
fail_fast?: boolean;
}
export class ProteinCommandChannel {
private readonly sessionId: string;
constructor(private readonly http: HTTPClient) {
this.sessionId = `sdk_session_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;
}
private supplementalHeaders(): Record<string, string> {
const h: Record<string, string> = {
'X-Session-ID': this.sessionId,
'X-Request-ID': `req_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`,
};
const tok = this.http.getAuthToken();
if (tok) {
h['X-User-Token'] = tok;
}
return h;
}
async executeCommand<T = unknown>(request: ProteinCommandExecuteRequest): Promise<T> {
const res = await this.http.post<T>('/commands/execute', request, {
headers: this.supplementalHeaders(),
});
return res.data;
}
async executeDNAOperation<T = unknown>(
entityType: string,
operation: string,
data: Record<string, unknown>
): Promise<T> {
const res = await this.http.post<T>(`/commands/dna/${entityType}/${operation}`, data, {
headers: this.supplementalHeaders(),
});
return res.data;
}
async executeBatchCommands<T = unknown>(request: ProteinBatchCommandRequest): Promise<T> {
const res = await this.http.post<T>('/commands/batch', request, {
headers: this.supplementalHeaders(),
});
return res.data;
}
async getEntities<T = unknown>(
entityType: string,
filters?: Record<string, unknown>
): Promise<T> {
const res = await this.http.get<T>(`/commands/entities/${entityType}`, filters, {
headers: this.supplementalHeaders(),
});
return res.data;
}
async createEntity<T = unknown>(entityType: string, data: Record<string, unknown>): Promise<T> {
const res = await this.http.post<T>(`/commands/entities/${entityType}`, data, {
headers: this.supplementalHeaders(),
});
return res.data;
}
async getCommandStatus<T = unknown>(commandUuid: string): Promise<T> {
const res = await this.http.get<T>(`/commands/status/${commandUuid}`, undefined, {
headers: this.supplementalHeaders(),
});
return res.data;
}
async getCommandHistory<T = unknown>(limit = 100, offset = 0): Promise<T> {
const res = await this.http.get<T>('/commands/history', { limit, offset }, {
headers: this.supplementalHeaders(),
});
return res.data;
}
async healthCheck<T = unknown>(): Promise<T> {
const res = await this.http.get<T>('/commands/health', undefined, {
headers: this.supplementalHeaders(),
});
return res.data;
}
}