@mondaydotcomorg/atp-protocol 0.19.7 → 0.19.9
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.
- package/dist/index.cjs +553 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +533 -6
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +7 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +9 -5
- package/src/types.ts +8 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var atpProvenance = require('@mondaydotcomorg/atp-provenance');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
exports.CallbackType = void 0;
|
|
9
|
+
(function(CallbackType2) {
|
|
10
|
+
CallbackType2["LLM"] = "llm";
|
|
11
|
+
CallbackType2["APPROVAL"] = "approval";
|
|
12
|
+
CallbackType2["EMBEDDING"] = "embedding";
|
|
13
|
+
CallbackType2["TOOL"] = "tool";
|
|
14
|
+
})(exports.CallbackType || (exports.CallbackType = {}));
|
|
15
|
+
exports.ToolOperation = void 0;
|
|
16
|
+
(function(ToolOperation2) {
|
|
17
|
+
ToolOperation2["CALL"] = "call";
|
|
18
|
+
})(exports.ToolOperation || (exports.ToolOperation = {}));
|
|
19
|
+
exports.ToolOperationType = void 0;
|
|
20
|
+
(function(ToolOperationType2) {
|
|
21
|
+
ToolOperationType2["READ"] = "read";
|
|
22
|
+
ToolOperationType2["WRITE"] = "write";
|
|
23
|
+
ToolOperationType2["DESTRUCTIVE"] = "destructive";
|
|
24
|
+
})(exports.ToolOperationType || (exports.ToolOperationType = {}));
|
|
25
|
+
exports.ToolSensitivityLevel = void 0;
|
|
26
|
+
(function(ToolSensitivityLevel2) {
|
|
27
|
+
ToolSensitivityLevel2["PUBLIC"] = "public";
|
|
28
|
+
ToolSensitivityLevel2["INTERNAL"] = "internal";
|
|
29
|
+
ToolSensitivityLevel2["SENSITIVE"] = "sensitive";
|
|
30
|
+
})(exports.ToolSensitivityLevel || (exports.ToolSensitivityLevel = {}));
|
|
31
|
+
exports.ExecutionStatus = void 0;
|
|
32
|
+
(function(ExecutionStatus2) {
|
|
33
|
+
ExecutionStatus2["COMPLETED"] = "completed";
|
|
34
|
+
ExecutionStatus2["FAILED"] = "failed";
|
|
35
|
+
ExecutionStatus2["TIMEOUT"] = "timeout";
|
|
36
|
+
ExecutionStatus2["CANCELLED"] = "cancelled";
|
|
37
|
+
ExecutionStatus2["PAUSED"] = "paused";
|
|
38
|
+
ExecutionStatus2["MEMORY_EXCEEDED"] = "memory_exceeded";
|
|
39
|
+
ExecutionStatus2["LLM_CALLS_EXCEEDED"] = "llm_calls_exceeded";
|
|
40
|
+
ExecutionStatus2["SECURITY_VIOLATION"] = "security_violation";
|
|
41
|
+
ExecutionStatus2["VALIDATION_FAILED"] = "validation_failed";
|
|
42
|
+
ExecutionStatus2["LOOP_DETECTED"] = "loop_detected";
|
|
43
|
+
ExecutionStatus2["RATE_LIMITED"] = "rate_limited";
|
|
44
|
+
ExecutionStatus2["NETWORK_ERROR"] = "network_error";
|
|
45
|
+
ExecutionStatus2["PARSE_ERROR"] = "parse_error";
|
|
46
|
+
})(exports.ExecutionStatus || (exports.ExecutionStatus = {}));
|
|
47
|
+
exports.ExecutionErrorCode = void 0;
|
|
48
|
+
(function(ExecutionErrorCode2) {
|
|
49
|
+
ExecutionErrorCode2["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
50
|
+
ExecutionErrorCode2["EXECUTION_FAILED"] = "EXECUTION_FAILED";
|
|
51
|
+
ExecutionErrorCode2["TIMEOUT_ERROR"] = "TIMEOUT_ERROR";
|
|
52
|
+
ExecutionErrorCode2["MEMORY_LIMIT_EXCEEDED"] = "MEMORY_LIMIT_EXCEEDED";
|
|
53
|
+
ExecutionErrorCode2["LLM_CALL_LIMIT_EXCEEDED"] = "LLM_CALL_LIMIT_EXCEEDED";
|
|
54
|
+
ExecutionErrorCode2["HTTP_CALL_LIMIT_EXCEEDED"] = "HTTP_CALL_LIMIT_EXCEEDED";
|
|
55
|
+
ExecutionErrorCode2["SECURITY_VIOLATION"] = "SECURITY_VIOLATION";
|
|
56
|
+
ExecutionErrorCode2["VALIDATION_FAILED"] = "VALIDATION_FAILED";
|
|
57
|
+
ExecutionErrorCode2["FORBIDDEN_OPERATION"] = "FORBIDDEN_OPERATION";
|
|
58
|
+
ExecutionErrorCode2["PARSE_ERROR"] = "PARSE_ERROR";
|
|
59
|
+
ExecutionErrorCode2["SYNTAX_ERROR"] = "SYNTAX_ERROR";
|
|
60
|
+
ExecutionErrorCode2["TYPE_ERROR"] = "TYPE_ERROR";
|
|
61
|
+
ExecutionErrorCode2["REFERENCE_ERROR"] = "REFERENCE_ERROR";
|
|
62
|
+
ExecutionErrorCode2["INFINITE_LOOP_DETECTED"] = "INFINITE_LOOP_DETECTED";
|
|
63
|
+
ExecutionErrorCode2["LOOP_TIMEOUT"] = "LOOP_TIMEOUT";
|
|
64
|
+
ExecutionErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
65
|
+
ExecutionErrorCode2["HTTP_ERROR"] = "HTTP_ERROR";
|
|
66
|
+
ExecutionErrorCode2["DNS_ERROR"] = "DNS_ERROR";
|
|
67
|
+
ExecutionErrorCode2["RATE_LIMIT_EXCEEDED"] = "RATE_LIMIT_EXCEEDED";
|
|
68
|
+
ExecutionErrorCode2["CONCURRENT_LIMIT_EXCEEDED"] = "CONCURRENT_LIMIT_EXCEEDED";
|
|
69
|
+
})(exports.ExecutionErrorCode || (exports.ExecutionErrorCode = {}));
|
|
70
|
+
|
|
71
|
+
// src/schemas.ts
|
|
72
|
+
var ExecutionConfigSchema = {
|
|
73
|
+
type: "object",
|
|
74
|
+
properties: {
|
|
75
|
+
timeout: {
|
|
76
|
+
type: "number",
|
|
77
|
+
minimum: 1e3,
|
|
78
|
+
maximum: 3e5
|
|
79
|
+
},
|
|
80
|
+
maxMemory: {
|
|
81
|
+
type: "number",
|
|
82
|
+
minimum: 1048576,
|
|
83
|
+
maximum: 536870912
|
|
84
|
+
},
|
|
85
|
+
maxLLMCalls: {
|
|
86
|
+
type: "number",
|
|
87
|
+
minimum: 0,
|
|
88
|
+
maximum: 100
|
|
89
|
+
},
|
|
90
|
+
allowedAPIs: {
|
|
91
|
+
type: "array",
|
|
92
|
+
items: {
|
|
93
|
+
type: "string"
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
allowLLMCalls: {
|
|
97
|
+
type: "boolean"
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
required: [
|
|
101
|
+
"timeout",
|
|
102
|
+
"maxMemory",
|
|
103
|
+
"maxLLMCalls",
|
|
104
|
+
"allowedAPIs",
|
|
105
|
+
"allowLLMCalls"
|
|
106
|
+
]
|
|
107
|
+
};
|
|
108
|
+
var SearchOptionsSchema = {
|
|
109
|
+
type: "object",
|
|
110
|
+
properties: {
|
|
111
|
+
query: {
|
|
112
|
+
type: "string",
|
|
113
|
+
minLength: 1
|
|
114
|
+
},
|
|
115
|
+
apiGroups: {
|
|
116
|
+
type: "array",
|
|
117
|
+
items: {
|
|
118
|
+
type: "string"
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
maxResults: {
|
|
122
|
+
type: "number",
|
|
123
|
+
minimum: 1,
|
|
124
|
+
maximum: 100
|
|
125
|
+
},
|
|
126
|
+
useEmbeddings: {
|
|
127
|
+
type: "boolean"
|
|
128
|
+
},
|
|
129
|
+
embeddingModel: {
|
|
130
|
+
type: "string"
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
required: [
|
|
134
|
+
"query"
|
|
135
|
+
]
|
|
136
|
+
};
|
|
137
|
+
var AgentToolProtocolRequestSchema = {
|
|
138
|
+
type: "object",
|
|
139
|
+
properties: {
|
|
140
|
+
jsonrpc: {
|
|
141
|
+
type: "string",
|
|
142
|
+
enum: [
|
|
143
|
+
"2.0"
|
|
144
|
+
]
|
|
145
|
+
},
|
|
146
|
+
id: {
|
|
147
|
+
type: [
|
|
148
|
+
"string",
|
|
149
|
+
"number"
|
|
150
|
+
]
|
|
151
|
+
},
|
|
152
|
+
method: {
|
|
153
|
+
type: "string"
|
|
154
|
+
},
|
|
155
|
+
params: {
|
|
156
|
+
type: "object"
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
required: [
|
|
160
|
+
"jsonrpc",
|
|
161
|
+
"id",
|
|
162
|
+
"method",
|
|
163
|
+
"params"
|
|
164
|
+
]
|
|
165
|
+
};
|
|
166
|
+
var AgentToolProtocolResponseSchema = {
|
|
167
|
+
type: "object",
|
|
168
|
+
properties: {
|
|
169
|
+
jsonrpc: {
|
|
170
|
+
type: "string",
|
|
171
|
+
enum: [
|
|
172
|
+
"2.0"
|
|
173
|
+
]
|
|
174
|
+
},
|
|
175
|
+
id: {
|
|
176
|
+
type: [
|
|
177
|
+
"string",
|
|
178
|
+
"number"
|
|
179
|
+
]
|
|
180
|
+
},
|
|
181
|
+
result: {},
|
|
182
|
+
error: {
|
|
183
|
+
type: "object",
|
|
184
|
+
properties: {
|
|
185
|
+
code: {
|
|
186
|
+
type: "number"
|
|
187
|
+
},
|
|
188
|
+
message: {
|
|
189
|
+
type: "string"
|
|
190
|
+
},
|
|
191
|
+
data: {}
|
|
192
|
+
},
|
|
193
|
+
required: [
|
|
194
|
+
"code",
|
|
195
|
+
"message"
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
required: [
|
|
200
|
+
"jsonrpc",
|
|
201
|
+
"id"
|
|
202
|
+
]
|
|
203
|
+
};
|
|
204
|
+
var MAX_CODE_SIZE = 1e6;
|
|
205
|
+
var ConfigValidationError = class extends Error {
|
|
206
|
+
static {
|
|
207
|
+
__name(this, "ConfigValidationError");
|
|
208
|
+
}
|
|
209
|
+
field;
|
|
210
|
+
value;
|
|
211
|
+
constructor(message, field, value) {
|
|
212
|
+
super(message);
|
|
213
|
+
this.field = field;
|
|
214
|
+
this.value = value;
|
|
215
|
+
this.name = "ConfigValidationError";
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
var SecurityViolationError = class extends Error {
|
|
219
|
+
static {
|
|
220
|
+
__name(this, "SecurityViolationError");
|
|
221
|
+
}
|
|
222
|
+
violations;
|
|
223
|
+
constructor(message, violations) {
|
|
224
|
+
super(message);
|
|
225
|
+
this.violations = violations;
|
|
226
|
+
this.name = "SecurityViolationError";
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
function sanitizeInput(input, maxLength = MAX_CODE_SIZE) {
|
|
230
|
+
if (typeof input !== "string") {
|
|
231
|
+
return "";
|
|
232
|
+
}
|
|
233
|
+
let sanitized = input.replace(/[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F]/g, "");
|
|
234
|
+
sanitized = sanitized.replace(/[\u200B-\u200D\uFEFF]/g, "");
|
|
235
|
+
sanitized = sanitized.replace(/\n{10,}/g, "\n\n\n");
|
|
236
|
+
if (sanitized.length > maxLength) {
|
|
237
|
+
sanitized = sanitized.substring(0, maxLength);
|
|
238
|
+
}
|
|
239
|
+
return sanitized;
|
|
240
|
+
}
|
|
241
|
+
__name(sanitizeInput, "sanitizeInput");
|
|
242
|
+
function frameCodeExecution(userCode) {
|
|
243
|
+
const cleaned = sanitizeInput(userCode);
|
|
244
|
+
return `
|
|
245
|
+
(async function __user_code_context__() {
|
|
246
|
+
"use strict";
|
|
247
|
+
${cleaned}
|
|
248
|
+
})();
|
|
249
|
+
`.trim();
|
|
250
|
+
}
|
|
251
|
+
__name(frameCodeExecution, "frameCodeExecution");
|
|
252
|
+
var executionConfigSchema = zod.z.object({
|
|
253
|
+
timeout: zod.z.number({
|
|
254
|
+
invalid_type_error: "timeout must be a number"
|
|
255
|
+
}).positive("timeout must be positive").max(3e5, "timeout cannot exceed 300000ms (5 minutes)").optional(),
|
|
256
|
+
maxMemory: zod.z.number({
|
|
257
|
+
invalid_type_error: "maxMemory must be a number"
|
|
258
|
+
}).positive("maxMemory must be positive").max(512 * 1024 * 1024, "maxMemory cannot exceed 512MB").optional(),
|
|
259
|
+
maxLLMCalls: zod.z.number({
|
|
260
|
+
invalid_type_error: "maxLLMCalls must be a number"
|
|
261
|
+
}).nonnegative("maxLLMCalls cannot be negative").max(1e3, "maxLLMCalls cannot exceed 1000").optional(),
|
|
262
|
+
allowedAPIs: zod.z.array(zod.z.string().refine((val) => val.trim().length > 0, {
|
|
263
|
+
message: "allowedAPIs must contain non-empty strings"
|
|
264
|
+
})).optional(),
|
|
265
|
+
allowLLMCalls: zod.z.boolean({
|
|
266
|
+
invalid_type_error: "allowLLMCalls must be a boolean"
|
|
267
|
+
}).optional(),
|
|
268
|
+
progressCallback: zod.z.function().optional(),
|
|
269
|
+
customLLMHandler: zod.z.function().optional(),
|
|
270
|
+
clientServices: zod.z.any().optional(),
|
|
271
|
+
provenanceMode: zod.z.any().optional(),
|
|
272
|
+
securityPolicies: zod.z.array(zod.z.any()).optional(),
|
|
273
|
+
provenanceHints: zod.z.array(zod.z.string()).optional()
|
|
274
|
+
});
|
|
275
|
+
function validateExecutionConfig(config) {
|
|
276
|
+
try {
|
|
277
|
+
executionConfigSchema.parse(config);
|
|
278
|
+
} catch (error) {
|
|
279
|
+
if (error instanceof zod.z.ZodError) {
|
|
280
|
+
const errors = error.errors.map((err) => err.message);
|
|
281
|
+
throw new ConfigValidationError(`Invalid ExecutionConfig: ${errors.join(", ")}`, "ExecutionConfig", config);
|
|
282
|
+
}
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
__name(validateExecutionConfig, "validateExecutionConfig");
|
|
287
|
+
function validateClientId(clientId) {
|
|
288
|
+
if (typeof clientId !== "string") {
|
|
289
|
+
throw new ConfigValidationError("clientId must be a string", "clientId", clientId);
|
|
290
|
+
}
|
|
291
|
+
if (clientId.trim().length === 0) {
|
|
292
|
+
throw new ConfigValidationError("clientId cannot be empty", "clientId", clientId);
|
|
293
|
+
}
|
|
294
|
+
if (clientId.length > 256) {
|
|
295
|
+
throw new ConfigValidationError("clientId cannot exceed 256 characters", "clientId", clientId);
|
|
296
|
+
}
|
|
297
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(clientId)) {
|
|
298
|
+
throw new ConfigValidationError("clientId can only contain alphanumeric characters, dashes, and underscores", "clientId", clientId);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
__name(validateClientId, "validateClientId");
|
|
302
|
+
|
|
303
|
+
// src/auth.ts
|
|
304
|
+
var CredentialResolver = class {
|
|
305
|
+
static {
|
|
306
|
+
__name(this, "CredentialResolver");
|
|
307
|
+
}
|
|
308
|
+
providers = /* @__PURE__ */ new Map();
|
|
309
|
+
/**
|
|
310
|
+
* Registers a runtime credential provider
|
|
311
|
+
*/
|
|
312
|
+
registerProvider(provider) {
|
|
313
|
+
this.providers.set(provider.name, provider);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Resolves auth configuration to credentials
|
|
317
|
+
*/
|
|
318
|
+
async resolve(authConfig) {
|
|
319
|
+
if (authConfig.provider) {
|
|
320
|
+
const provider = this.providers.get(authConfig.provider);
|
|
321
|
+
if (!provider) {
|
|
322
|
+
throw new Error(`Credential provider '${authConfig.provider}' not found`);
|
|
323
|
+
}
|
|
324
|
+
return await provider.resolve();
|
|
325
|
+
}
|
|
326
|
+
switch (authConfig.scheme) {
|
|
327
|
+
case "apiKey":
|
|
328
|
+
return this.resolveAPIKey(authConfig);
|
|
329
|
+
case "bearer":
|
|
330
|
+
return this.resolveBearer(authConfig);
|
|
331
|
+
case "basic":
|
|
332
|
+
return this.resolveBasic(authConfig);
|
|
333
|
+
case "oauth2":
|
|
334
|
+
return this.resolveOAuth2(authConfig);
|
|
335
|
+
case "custom":
|
|
336
|
+
return this.resolveCustom(authConfig);
|
|
337
|
+
case "composite":
|
|
338
|
+
return this.resolveComposite(authConfig);
|
|
339
|
+
default:
|
|
340
|
+
throw new Error(`Unsupported auth scheme: ${authConfig.scheme}`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
resolveAPIKey(config) {
|
|
344
|
+
const value = this.getValue(config);
|
|
345
|
+
if (!value) {
|
|
346
|
+
throw new Error(`API key not provided for '${config.name}'`);
|
|
347
|
+
}
|
|
348
|
+
if (config.in === "header") {
|
|
349
|
+
return {
|
|
350
|
+
headers: {
|
|
351
|
+
[config.name]: value
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
} else {
|
|
355
|
+
return {
|
|
356
|
+
queryParams: {
|
|
357
|
+
[config.name]: value
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
resolveBearer(config) {
|
|
363
|
+
const token = this.getValue(config);
|
|
364
|
+
if (!token) {
|
|
365
|
+
throw new Error("Bearer token not provided");
|
|
366
|
+
}
|
|
367
|
+
return {
|
|
368
|
+
headers: {
|
|
369
|
+
Authorization: `Bearer ${token}`
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
resolveBasic(config) {
|
|
374
|
+
const username = config.usernameEnvVar ? process.env[config.usernameEnvVar] : config.username;
|
|
375
|
+
const password = config.passwordEnvVar ? process.env[config.passwordEnvVar] : this.getValue(config);
|
|
376
|
+
if (!username || !password) {
|
|
377
|
+
throw new Error("Basic auth username and password not provided");
|
|
378
|
+
}
|
|
379
|
+
const credentials = Buffer.from(`${username}:${password}`).toString("base64");
|
|
380
|
+
return {
|
|
381
|
+
headers: {
|
|
382
|
+
Authorization: `Basic ${credentials}`
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
async resolveOAuth2(config) {
|
|
387
|
+
const clientId = config.clientIdEnvVar ? process.env[config.clientIdEnvVar] : config.clientId;
|
|
388
|
+
const clientSecret = config.clientSecretEnvVar ? process.env[config.clientSecretEnvVar] : void 0;
|
|
389
|
+
if (!clientId || !clientSecret) {
|
|
390
|
+
throw new Error("OAuth2 client credentials not provided");
|
|
391
|
+
}
|
|
392
|
+
if (config.flow === "clientCredentials") {
|
|
393
|
+
const token2 = await this.fetchOAuth2Token(config.tokenUrl, clientId, clientSecret, config.scopes);
|
|
394
|
+
return {
|
|
395
|
+
headers: {
|
|
396
|
+
Authorization: `Bearer ${token2}`
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
const token = this.getValue(config);
|
|
401
|
+
if (token) {
|
|
402
|
+
return {
|
|
403
|
+
headers: {
|
|
404
|
+
Authorization: `Bearer ${token}`
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
throw new Error(`OAuth2 flow '${config.flow}' requires manual token setup`);
|
|
409
|
+
}
|
|
410
|
+
resolveCustom(config) {
|
|
411
|
+
const headers = {};
|
|
412
|
+
const queryParams = {};
|
|
413
|
+
Object.assign(headers, config.headers);
|
|
414
|
+
if (config.headerEnvVars) {
|
|
415
|
+
for (const [headerName, envVar] of Object.entries(config.headerEnvVars)) {
|
|
416
|
+
const value = process.env[envVar];
|
|
417
|
+
if (value) {
|
|
418
|
+
headers[headerName] = value;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
if (config.queryParams) {
|
|
423
|
+
Object.assign(queryParams, config.queryParams);
|
|
424
|
+
}
|
|
425
|
+
if (config.queryParamEnvVars) {
|
|
426
|
+
for (const [paramName, envVar] of Object.entries(config.queryParamEnvVars)) {
|
|
427
|
+
const value = process.env[envVar];
|
|
428
|
+
if (value) {
|
|
429
|
+
queryParams[paramName] = value;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return {
|
|
434
|
+
headers: Object.keys(headers).length > 0 ? headers : void 0,
|
|
435
|
+
queryParams: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
resolveComposite(config) {
|
|
439
|
+
const headers = {};
|
|
440
|
+
const queryParams = {};
|
|
441
|
+
for (const [credName, credConfig] of Object.entries(config.credentials)) {
|
|
442
|
+
const value = credConfig.envVar ? process.env[credConfig.envVar] : credConfig.value;
|
|
443
|
+
if (!value) {
|
|
444
|
+
if (credConfig.required !== false) {
|
|
445
|
+
throw new Error(`Required credential '${credName}' not provided`);
|
|
446
|
+
}
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
const injectAs = config.injectAs || "header";
|
|
450
|
+
if ((injectAs === "header" || injectAs === "both") && credConfig.headerName) {
|
|
451
|
+
headers[credConfig.headerName] = value;
|
|
452
|
+
}
|
|
453
|
+
if ((injectAs === "query" || injectAs === "both") && credConfig.queryParamName) {
|
|
454
|
+
queryParams[credConfig.queryParamName] = value;
|
|
455
|
+
}
|
|
456
|
+
if (!credConfig.headerName && !credConfig.queryParamName) {
|
|
457
|
+
if (injectAs === "query" || injectAs === "both") {
|
|
458
|
+
queryParams[credName] = value;
|
|
459
|
+
} else {
|
|
460
|
+
headers[`X-${credName}`] = value;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
headers: Object.keys(headers).length > 0 ? headers : void 0,
|
|
466
|
+
queryParams: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Gets credential value from config (env var or direct value)
|
|
471
|
+
*/
|
|
472
|
+
getValue(config) {
|
|
473
|
+
if (config.envVar) {
|
|
474
|
+
return process.env[config.envVar];
|
|
475
|
+
}
|
|
476
|
+
return config.value;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Fetches OAuth2 token using client credentials flow
|
|
480
|
+
*/
|
|
481
|
+
async fetchOAuth2Token(tokenUrl, clientId, clientSecret, scopes) {
|
|
482
|
+
const params = new URLSearchParams({
|
|
483
|
+
grant_type: "client_credentials",
|
|
484
|
+
client_id: clientId,
|
|
485
|
+
client_secret: clientSecret
|
|
486
|
+
});
|
|
487
|
+
if (scopes && scopes.length > 0) {
|
|
488
|
+
params.append("scope", scopes.join(" "));
|
|
489
|
+
}
|
|
490
|
+
const response = await fetch(tokenUrl, {
|
|
491
|
+
method: "POST",
|
|
492
|
+
headers: {
|
|
493
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
494
|
+
},
|
|
495
|
+
body: params.toString()
|
|
496
|
+
});
|
|
497
|
+
if (!response.ok) {
|
|
498
|
+
throw new Error(`OAuth2 token fetch failed: ${response.statusText}`);
|
|
499
|
+
}
|
|
500
|
+
const data = await response.json();
|
|
501
|
+
return data.access_token;
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
// src/providers.ts
|
|
506
|
+
var MultiAuditSink = class {
|
|
507
|
+
static {
|
|
508
|
+
__name(this, "MultiAuditSink");
|
|
509
|
+
}
|
|
510
|
+
name = "multi";
|
|
511
|
+
sinks;
|
|
512
|
+
constructor(sinks) {
|
|
513
|
+
this.sinks = sinks;
|
|
514
|
+
}
|
|
515
|
+
async write(event) {
|
|
516
|
+
await Promise.all(this.sinks.map((sink) => sink.write(event)));
|
|
517
|
+
}
|
|
518
|
+
async writeBatch(events) {
|
|
519
|
+
await Promise.all(this.sinks.map((sink) => sink.writeBatch(events)));
|
|
520
|
+
}
|
|
521
|
+
async query(filter) {
|
|
522
|
+
for (const sink of this.sinks) {
|
|
523
|
+
if (sink.query) {
|
|
524
|
+
return await sink.query(filter);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
throw new Error("No queryable audit sink available");
|
|
528
|
+
}
|
|
529
|
+
async disconnect() {
|
|
530
|
+
await Promise.all(this.sinks.map((sink) => sink.disconnect ? sink.disconnect() : Promise.resolve()));
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
Object.defineProperty(exports, "ProvenanceMode", {
|
|
535
|
+
enumerable: true,
|
|
536
|
+
get: function () { return atpProvenance.ProvenanceMode; }
|
|
537
|
+
});
|
|
538
|
+
exports.AgentToolProtocolRequestSchema = AgentToolProtocolRequestSchema;
|
|
539
|
+
exports.AgentToolProtocolResponseSchema = AgentToolProtocolResponseSchema;
|
|
540
|
+
exports.ConfigValidationError = ConfigValidationError;
|
|
541
|
+
exports.CredentialResolver = CredentialResolver;
|
|
542
|
+
exports.ExecutionConfigSchema = ExecutionConfigSchema;
|
|
543
|
+
exports.MAX_CODE_SIZE = MAX_CODE_SIZE;
|
|
544
|
+
exports.MultiAuditSink = MultiAuditSink;
|
|
545
|
+
exports.SearchOptionsSchema = SearchOptionsSchema;
|
|
546
|
+
exports.SecurityViolationError = SecurityViolationError;
|
|
547
|
+
exports.executionConfigSchema = executionConfigSchema;
|
|
548
|
+
exports.frameCodeExecution = frameCodeExecution;
|
|
549
|
+
exports.sanitizeInput = sanitizeInput;
|
|
550
|
+
exports.validateClientId = validateClientId;
|
|
551
|
+
exports.validateExecutionConfig = validateExecutionConfig;
|
|
552
|
+
//# sourceMappingURL=index.cjs.map
|
|
553
|
+
//# sourceMappingURL=index.cjs.map
|