@mondaydotcomorg/atp-protocol 0.17.14

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.
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Provider interfaces for dependency injection
3
+ * These allow users to inject their own implementations for cache, auth, and audit
4
+ */
5
+
6
+ /**
7
+ * Cache provider interface
8
+ * Allows pluggable caching backends (Memory, Redis, FileSystem, etc.)
9
+ */
10
+ export interface CacheProvider {
11
+ /** Provider name for identification */
12
+ name: string;
13
+
14
+ /** Get a value from cache */
15
+ get<T>(key: string): Promise<T | null>;
16
+
17
+ /** Set a value in cache with optional TTL (in seconds) */
18
+ set(key: string, value: unknown, ttl?: number): Promise<void>;
19
+
20
+ /** Delete a value from cache */
21
+ delete(key: string): Promise<void>;
22
+
23
+ /** Check if a key exists in cache */
24
+ has(key: string): Promise<boolean>;
25
+
26
+ /** Clear cache entries matching a pattern (e.g., 'user:*') */
27
+ clear(pattern?: string): Promise<void>;
28
+
29
+ /** Get multiple values at once (optional, for performance) */
30
+ mget?(keys: string[]): Promise<Array<unknown | null>>;
31
+
32
+ /** Set multiple values at once (optional, for performance) */
33
+ mset?(entries: Array<[string, unknown, number?]>): Promise<void>;
34
+
35
+ /** Disconnect/cleanup (optional) */
36
+ disconnect?(): Promise<void>;
37
+ }
38
+
39
+ /**
40
+ * User credential data stored per provider
41
+ */
42
+ export interface UserCredentialData {
43
+ /** Access token */
44
+ token: string;
45
+
46
+ /** OAuth scopes granted (if applicable) */
47
+ scopes?: string[];
48
+
49
+ /** Token expiration timestamp (milliseconds since epoch) */
50
+ expiresAt?: number;
51
+
52
+ /** Refresh token for automatic token refresh */
53
+ refreshToken?: string;
54
+
55
+ /** Additional provider-specific metadata */
56
+ metadata?: Record<string, unknown>;
57
+ }
58
+
59
+ /**
60
+ * Auth provider interface
61
+ * Allows pluggable credential storage (Env vars, AWS Secrets Manager, Vault, etc.)
62
+ */
63
+ export interface AuthProvider {
64
+ /** Provider name for identification */
65
+ name: string;
66
+
67
+ /** Get a credential by key (server-level credentials) */
68
+ getCredential(key: string): Promise<string | null>;
69
+
70
+ /** Set a credential (for OAuth tokens, etc.) */
71
+ setCredential(key: string, value: string, ttl?: number): Promise<void>;
72
+
73
+ /** Delete a credential */
74
+ deleteCredential(key: string): Promise<void>;
75
+
76
+ /** List all credential keys (optional, for admin/debugging) */
77
+ listCredentials?(): Promise<string[]>;
78
+
79
+ /**
80
+ * Get user-scoped credential for a specific provider
81
+ * @param userId - User identifier
82
+ * @param provider - Provider name (e.g., 'github', 'google', 'stripe')
83
+ * @returns User credential data or null if not found
84
+ */
85
+ getUserCredential?(userId: string, provider: string): Promise<UserCredentialData | null>;
86
+
87
+ /**
88
+ * Set user-scoped credential for a specific provider
89
+ * @param userId - User identifier
90
+ * @param provider - Provider name
91
+ * @param data - Credential data including token, scopes, etc.
92
+ */
93
+ setUserCredential?(userId: string, provider: string, data: UserCredentialData): Promise<void>;
94
+
95
+ /**
96
+ * Delete user's credential for a specific provider
97
+ * @param userId - User identifier
98
+ * @param provider - Provider name
99
+ */
100
+ deleteUserCredential?(userId: string, provider: string): Promise<void>;
101
+
102
+ /**
103
+ * List all providers a user has connected
104
+ * @param userId - User identifier
105
+ * @returns Array of provider names
106
+ */
107
+ listUserProviders?(userId: string): Promise<string[]>;
108
+
109
+ /** Disconnect/cleanup (optional) */
110
+ disconnect?(): Promise<void>;
111
+ }
112
+
113
+ /**
114
+ * Audit event structure
115
+ * Comprehensive logging of all operations for security and compliance
116
+ */
117
+ export interface AuditEvent {
118
+ eventId: string;
119
+ timestamp: number;
120
+
121
+ clientId: string;
122
+ userId?: string;
123
+ ipAddress?: string;
124
+ userAgent?: string;
125
+
126
+ eventType: 'execution' | 'tool_call' | 'llm_call' | 'approval' | 'auth' | 'error' | 'client_init';
127
+ action: string;
128
+ resource?: string;
129
+ resourceId?: string;
130
+
131
+ code?: string;
132
+ toolName?: string;
133
+ apiGroup?: string;
134
+ input?: unknown;
135
+ output?: unknown;
136
+ error?: {
137
+ message: string;
138
+ code?: string;
139
+ stack?: string;
140
+ };
141
+
142
+ securityEvents?: string[];
143
+ riskScore?: number;
144
+ annotations?: Record<string, unknown>;
145
+
146
+ duration?: number;
147
+ memoryUsed?: number;
148
+ llmCallsCount?: number;
149
+ httpCallsCount?: number;
150
+
151
+ status: 'success' | 'failed' | 'timeout' | 'cancelled' | 'paused';
152
+
153
+ metadata?: Record<string, unknown>;
154
+ }
155
+
156
+ /**
157
+ * Audit filter for querying events
158
+ */
159
+ export interface AuditFilter {
160
+ clientId?: string;
161
+ userId?: string;
162
+ eventType?: string | string[];
163
+ from?: number;
164
+ to?: number;
165
+ resource?: string;
166
+ status?: string | string[];
167
+ minRiskScore?: number;
168
+ limit?: number;
169
+ offset?: number;
170
+ }
171
+
172
+ /**
173
+ * Audit sink interface
174
+ * Allows pluggable audit destinations (JSONL, PostgreSQL, Elasticsearch, S3, etc.)
175
+ */
176
+ export interface AuditSink {
177
+ /** Sink name for identification */
178
+ name: string;
179
+
180
+ /** Write a single audit event */
181
+ write(event: AuditEvent): Promise<void>;
182
+
183
+ /** Write multiple audit events (for performance) */
184
+ writeBatch(events: AuditEvent[]): Promise<void>;
185
+
186
+ /** Query audit events (optional, for queryable sinks) */
187
+ query?(filter: AuditFilter): Promise<AuditEvent[]>;
188
+
189
+ /** Disconnect/cleanup (optional) */
190
+ disconnect?(): Promise<void>;
191
+ }
192
+
193
+ /**
194
+ * Multi-sink audit wrapper
195
+ * Allows writing to multiple audit sinks simultaneously
196
+ */
197
+ export class MultiAuditSink implements AuditSink {
198
+ name = 'multi';
199
+ private sinks: AuditSink[];
200
+
201
+ constructor(sinks: AuditSink[]) {
202
+ this.sinks = sinks;
203
+ }
204
+
205
+ async write(event: AuditEvent): Promise<void> {
206
+ await Promise.all(this.sinks.map((sink) => sink.write(event)));
207
+ }
208
+
209
+ async writeBatch(events: AuditEvent[]): Promise<void> {
210
+ await Promise.all(this.sinks.map((sink) => sink.writeBatch(events)));
211
+ }
212
+
213
+ async query(filter: AuditFilter): Promise<AuditEvent[]> {
214
+ for (const sink of this.sinks) {
215
+ if (sink.query) {
216
+ return await sink.query(filter);
217
+ }
218
+ }
219
+ throw new Error('No queryable audit sink available');
220
+ }
221
+
222
+ async disconnect(): Promise<void> {
223
+ await Promise.all(
224
+ this.sinks.map((sink) => (sink.disconnect ? sink.disconnect() : Promise.resolve()))
225
+ );
226
+ }
227
+ }
package/src/schemas.ts ADDED
@@ -0,0 +1,55 @@
1
+ import type { JSONSchema } from './types.js';
2
+
3
+ export const ExecutionConfigSchema: JSONSchema = {
4
+ type: 'object',
5
+ properties: {
6
+ timeout: { type: 'number', minimum: 1000, maximum: 300000 },
7
+ maxMemory: { type: 'number', minimum: 1048576, maximum: 536870912 },
8
+ maxLLMCalls: { type: 'number', minimum: 0, maximum: 100 },
9
+ allowedAPIs: { type: 'array', items: { type: 'string' } },
10
+ allowLLMCalls: { type: 'boolean' },
11
+ },
12
+ required: ['timeout', 'maxMemory', 'maxLLMCalls', 'allowedAPIs', 'allowLLMCalls'],
13
+ };
14
+
15
+ export const SearchOptionsSchema: JSONSchema = {
16
+ type: 'object',
17
+ properties: {
18
+ query: { type: 'string', minLength: 1 },
19
+ apiGroups: { type: 'array', items: { type: 'string' } },
20
+ maxResults: { type: 'number', minimum: 1, maximum: 100 },
21
+ useEmbeddings: { type: 'boolean' },
22
+ embeddingModel: { type: 'string' },
23
+ },
24
+ required: ['query'],
25
+ };
26
+
27
+ export const AgentToolProtocolRequestSchema: JSONSchema = {
28
+ type: 'object',
29
+ properties: {
30
+ jsonrpc: { type: 'string', enum: ['2.0'] },
31
+ id: { type: ['string', 'number'] },
32
+ method: { type: 'string' },
33
+ params: { type: 'object' },
34
+ },
35
+ required: ['jsonrpc', 'id', 'method', 'params'],
36
+ };
37
+
38
+ export const AgentToolProtocolResponseSchema: JSONSchema = {
39
+ type: 'object',
40
+ properties: {
41
+ jsonrpc: { type: 'string', enum: ['2.0'] },
42
+ id: { type: ['string', 'number'] },
43
+ result: {},
44
+ error: {
45
+ type: 'object',
46
+ properties: {
47
+ code: { type: 'number' },
48
+ message: { type: 'string' },
49
+ data: {},
50
+ },
51
+ required: ['code', 'message'],
52
+ },
53
+ },
54
+ required: ['jsonrpc', 'id'],
55
+ };